Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
feat(client): support timeout config in ovcli.conf and fix Rust CLI alignment (#308)
Qin Haojie1a408394661a
diff --git a/crates/ov_cli/src/client.rs b/crates/ov_cli/src/client.rsindex abfef95b1..b4687a950 100644--- a/crates/ov_cli/src/client.rs+++ b/crates/ov_cli/src/client.rs@@ -16,13 +16,19 @@ pub struct HttpClient {http: ReqwestClient,base_url: String,api_key: Option<String>,+ agent_id: Option<String>,}impl HttpClient {/// Create a new HTTP client- pub fn new(base_url: impl Into<String>, api_key: Option<String>) -> Self {+ pub fn new(+ base_url: impl Into<String>,+ api_key: Option<String>,+ agent_id: Option<String>,+ timeout_secs: f64,+ ) -> Self {let http = ReqwestClient::builder()- .timeout(std::time::Duration::from_secs(60))+ .timeout(std::time::Duration::from_secs_f64(timeout_secs)).build().expect("Failed to build HTTP client");@@ -30,6 +36,7 @@ impl HttpClient {http,base_url: base_url.into().trim_end_matches('/').to_string(),api_key,+ agent_id,}}@@ -120,6 +127,11 @@ impl HttpClient {headers.insert("X-API-Key", value);}}+ if let Some(agent_id) = &self.agent_id {+ if let Ok(value) = reqwest::header::HeaderValue::from_str(agent_id) {+ headers.insert("X-OpenViking-Agent", value);+ }+ }headers}diff --git a/crates/ov_cli/src/config.rs b/crates/ov_cli/src/config.rsindex 363b39a8a..0c9b847a1 100644--- a/crates/ov_cli/src/config.rs+++ b/crates/ov_cli/src/config.rs@@ -8,7 +8,9 @@ pub struct Config {#[serde(default = "default_url")]pub url: String,pub api_key: Option<String>,- pub user: Option<String>,+ pub agent_id: Option<String>,+ #[serde(default = "default_timeout")]+ pub timeout: f64,#[serde(default = "default_output_format")]pub output: String,}@@ -17,6 +19,10 @@ fn default_url() -> String {"http://localhost:1933".to_string()}+fn default_timeout() -> f64 {+ 60.0+}+fn default_output_format() -> String {"table".to_string()}@@ -26,7 +32,8 @@ impl Default for Config {Self {url: "http://localhost:1933".to_string(),api_key: None,- user: None,+ agent_id: None,+ timeout: 60.0,output: "table".to_string(),}}diff --git a/crates/ov_cli/src/main.rs b/crates/ov_cli/src/main.rsindex 88066d087..74c71d6f2 100644--- a/crates/ov_cli/src/main.rs+++ b/crates/ov_cli/src/main.rs@@ -29,7 +29,12 @@ impl CliContext {}pub fn get_client(&self) -> client::HttpClient {- client::HttpClient::new(&self.config.url, self.config.api_key.clone())+ client::HttpClient::new(+ &self.config.url,+ self.config.api_key.clone(),+ self.config.agent_id.clone(),+ self.config.timeout,+ )}}diff --git a/docs/en/api/01-overview.md b/docs/en/api/01-overview.mdindex 704ef6a90..ae4ddbd44 100644--- a/docs/en/api/01-overview.md+++ b/docs/en/api/01-overview.md@@ -58,6 +58,7 @@ client = ov.SyncHTTPClient(url="http://localhost:1933",api_key="your-key",agent_id="my-agent",+ timeout=120.0,)client.initialize()```@@ -80,6 +81,7 @@ export OPENVIKING_CLI_CONFIG_FILE=/path/to/ovcli.conf|-------|-------------|---------|| `url` | Server address | (required) || `api_key` | API key | `null` (no auth) |+| `timeout` | HTTP request timeout in seconds | `60.0` || `output` | Default output format: `"table"` or `"json"` | `"table"` |See the [Configuration Guide](../guides/01-configuration.md#ovcliconf) for details.diff --git a/docs/zh/api/01-overview.md b/docs/zh/api/01-overview.mdindex b182972af..3b1346098 100644--- a/docs/zh/api/01-overview.md+++ b/docs/zh/api/01-overview.md@@ -58,6 +58,7 @@ client = ov.SyncHTTPClient(url="http://localhost:1933",api_key="your-key",agent_id="my-agent",+ timeout=120.0,)client.initialize()```@@ -81,6 +82,7 @@ export OPENVIKING_CLI_CONFIG_FILE=/path/to/ovcli.conf| `url` | 服务端地址 | (必填) || `api_key` | API Key | `null`(无认证) || `agent_id` | Agent 标识符 | `null` |+| `timeout` | HTTP 请求超时时间(秒) | `60.0` || `output` | 默认输出格式:`"table"` 或 `"json"` | `"table"` |详见 [配置指南](../guides/01-configuration.md#ovcliconf)。diff --git a/examples/cloud/GUIDE.md b/examples/cloud/GUIDE.mdindex 4e8b3e231..a7dd002b7 100644--- a/examples/cloud/GUIDE.md+++ b/examples/cloud/GUIDE.md@@ -317,7 +317,8 @@ import openviking as ovclient = ov.SyncHTTPClient(url="http://localhost:1933",api_key="USER_API_KEY",- agent_id="my-agent"+ agent_id="my-agent",+ timeout=120.0, # HTTP request timeout in seconds (default: 60.0))client.initialize()diff --git a/examples/ovcli.conf.example b/examples/ovcli.conf.exampleindex f461ddbb6..152b4b3a4 100644--- a/examples/ovcli.conf.example+++ b/examples/ovcli.conf.example@@ -2,5 +2,6 @@"url": "http://localhost:1933","api_key": null,"agent_id": null,+ "timeout": 60.0,"output": "table"}diff --git a/examples/server_client/README.md b/examples/server_client/README.mdindex 764b5fc7d..01e476909 100644--- a/examples/server_client/README.md+++ b/examples/server_client/README.md@@ -114,7 +114,7 @@ main()```pythonimport openviking as ov-client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key")+client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key", timeout=120.0)client.initialize()client.add_resource(path="./document.md")@@ -129,7 +129,7 @@ client.close()```pythonimport openviking as ov-client = ov.AsyncHTTPClient(url="http://localhost:1933", api_key="your-key")+client = ov.AsyncHTTPClient(url="http://localhost:1933", api_key="your-key", timeout=120.0)await client.initialize()await client.add_resource(path="./document.md")diff --git a/examples/server_client/client_async.py b/examples/server_client/client_async.pyindex 4982e0541..ea96854db 100644--- a/examples/server_client/client_async.py+++ b/examples/server_client/client_async.py@@ -38,9 +38,12 @@ async def main():parser.add_argument("--url", default="http://localhost:1933", help="Server URL")parser.add_argument("--api-key", default=None, help="API key")parser.add_argument("--agent-id", default=None, help="Agent ID")+ parser.add_argument("--timeout", type=float, default=60.0, help="HTTP timeout in seconds")args = parser.parse_args()- client = ov.AsyncHTTPClient(url=args.url, api_key=args.api_key, agent_id=args.agent_id)+ client = ov.AsyncHTTPClient(+ url=args.url, api_key=args.api_key, agent_id=args.agent_id, timeout=args.timeout+ )try:# ── Connect ──diff --git a/examples/server_client/client_sync.py b/examples/server_client/client_sync.pyindex 89f491e32..797433e09 100644--- a/examples/server_client/client_sync.py+++ b/examples/server_client/client_sync.py@@ -64,9 +64,12 @@ def main():parser.add_argument("--url", default="http://localhost:1933", help="Server URL")parser.add_argument("--api-key", default=None, help="API key")parser.add_argument("--agent-id", default=None, help="Agent ID")+ parser.add_argument("--timeout", type=float, default=60.0, help="HTTP timeout in seconds")args = parser.parse_args()- client = ov.SyncHTTPClient(url=args.url, api_key=args.api_key, agent_id=args.agent_id)+ client = ov.SyncHTTPClient(+ url=args.url, api_key=args.api_key, agent_id=args.agent_id, timeout=args.timeout+ )try:# ── Connect ──diff --git a/openviking_cli/client/http.py b/openviking_cli/client/http.pyindex 4619f7886..5be344024 100644--- a/openviking_cli/client/http.py+++ b/openviking_cli/client/http.py@@ -132,6 +132,7 @@ class AsyncHTTPClient(BaseClient):url: Optional[str] = None,api_key: Optional[str] = None,agent_id: Optional[str] = None,+ timeout: float = 60.0,):"""Initialize AsyncHTTPClient.@@ -139,6 +140,7 @@ class AsyncHTTPClient(BaseClient):url: OpenViking Server URL. If not provided, reads from ovcli.conf.api_key: API key for authentication. If not provided, reads from ovcli.conf.agent_id: Agent identifier. If not provided, reads from ovcli.conf.+ timeout: HTTP request timeout in seconds. Default 60.0."""if url is None:config_path = resolve_config_path(None, OPENVIKING_CLI_CONFIG_ENV, DEFAULT_OVCLI_CONF)@@ -147,6 +149,8 @@ class AsyncHTTPClient(BaseClient):url = cfg.get("url")api_key = api_key or cfg.get("api_key")agent_id = agent_id or cfg.get("agent_id")+ if timeout == 60.0: # only override default with config value+ timeout = cfg.get("timeout", 60.0)if not url:raise ValueError("url is required. Pass it explicitly or configure in "@@ -156,6 +160,7 @@ class AsyncHTTPClient(BaseClient):self._api_key = api_keyself._agent_id = agent_idself._user = UserIdentifier.the_default_user()+ self._timeout = timeoutself._http: Optional[httpx.AsyncClient] = Noneself._observer: Optional[_HTTPObserver] = None@@ -171,7 +176,7 @@ class AsyncHTTPClient(BaseClient):self._http = httpx.AsyncClient(base_url=self._url,headers=headers,- timeout=60.0,+ timeout=self._timeout,)self._observer = _HTTPObserver(self)@@ -321,9 +326,11 @@ class AsyncHTTPClient(BaseClient):async def wait_processed(self, timeout: Optional[float] = None) -> Dict[str, Any]:"""Wait for all processing to complete."""+ http_timeout = timeout if timeout else 600.0response = await self._http.post("/api/v1/system/wait",json={"timeout": timeout},+ timeout=http_timeout,)return self._handle_response(response)diff --git a/openviking_cli/client/sync_http.py b/openviking_cli/client/sync_http.pyindex 4dfbd3fa8..27d2a3050 100644--- a/openviking_cli/client/sync_http.py+++ b/openviking_cli/client/sync_http.py@@ -32,8 +32,11 @@ class SyncHTTPClient:url: Optional[str] = None,api_key: Optional[str] = None,agent_id: Optional[str] = None,+ timeout: float = 60.0,):- self._async_client = AsyncHTTPClient(url=url, api_key=api_key, agent_id=agent_id)+ self._async_client = AsyncHTTPClient(+ url=url, api_key=api_key, agent_id=agent_id, timeout=timeout+ )self._initialized = False# ============= Lifecycle =============