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
fix(api): complete parts support and simplify error handling (#275)
SeanZ6ea89582b181
diff --git a/openviking/async_client.py b/openviking/async_client.pyindex cfc3920fb..ce69b65c6 100644--- a/openviking/async_client.py+++ b/openviking/async_client.py@@ -123,10 +123,27 @@ class AsyncOpenViking:await self._ensure_initialized()await self._client.delete_session(session_id)- async def add_message(self, session_id: str, role: str, content: str) -> Dict[str, Any]:- """Add a message to a session."""+ async def add_message(+ self,+ session_id: str,+ role: str,+ content: str | None = None,+ parts: list[dict] | None = None,+ ) -> Dict[str, Any]:+ """Add a message to a session.++ Args:+ session_id: Session ID+ role: Message role ("user" or "assistant")+ content: Text content (simple mode)+ parts: Parts array (full Part support: TextPart, ContextPart, ToolPart)++ If both content and parts are provided, parts takes precedence.+ """await self._ensure_initialized()- return await self._client.add_message(session_id=session_id, role=role, content=content)+ return await self._client.add_message(+ session_id=session_id, role=role, content=content, parts=parts+ )async def commit_session(self, session_id: str) -> Dict[str, Any]:"""Commit a session (archive and extract memories)."""diff --git a/openviking/storage/viking_fs.py b/openviking/storage/viking_fs.pyindex b0754a704..28638083e 100644--- a/openviking/storage/viking_fs.py+++ b/openviking/storage/viking_fs.py@@ -768,27 +768,6 @@ class VikingFS:except Exception:return ""- def _convert_agfs_error(self, e: Exception, uri: str) -> Exception:- """Convert AGFSClientError to appropriate Python standard exception.-- This preserves the semantic meaning of errors:- - "No such file or directory" -> FileNotFoundError- - "Permission denied" -> PermissionError- - Connection/timeout errors -> IOError- - Other errors -> IOError with original message- """- error_msg = str(e).lower()- if "no such file" in error_msg or "not found" in error_msg:- return FileNotFoundError(f"File not found: {uri}")- elif "permission denied" in error_msg:- return PermissionError(f"Permission denied: {uri}")- elif "connection refused" in error_msg or "server not running" in error_msg:- return IOError(f"AGFS server unavailable: {e}")- elif "timeout" in error_msg:- return IOError(f"Request timeout: {uri}")- else:- return IOError(f"Failed to access {uri}: {e}")-def _infer_context_type(self, uri: str):"""Infer context_type from URI."""from openviking_cli.retrieve import ContextType@@ -998,14 +977,12 @@ class VikingFS:Raises:FileNotFoundError: If the file does not exist.- PermissionError: If permission denied.- IOError: For other I/O related errors (connection, timeout, etc.)."""path = self._uri_to_path(uri)try:content = self.agfs.read(path)except Exception as e:- raise self._convert_agfs_error(e, uri) from e+ raise FileNotFoundError(f"Failed to read {uri}: {e}")text = self._handle_agfs_content(content)if offset == 0 and limit == -1:return text@@ -1017,18 +994,12 @@ class VikingFS:self,uri: str,) -> bytes:- """Read single binary file.-- Raises:- FileNotFoundError: If the file does not exist.- PermissionError: If permission denied.- IOError: For other I/O related errors (connection, timeout, etc.).- """+ """Read single binary file."""path = self._uri_to_path(uri)try:return self._handle_agfs_read(self.agfs.read(path))except Exception as e:- raise self._convert_agfs_error(e, uri) from e+ raise FileNotFoundError(f"Failed to read {uri}: {e}")async def write_file_bytes(self,@@ -1100,7 +1071,7 @@ class VikingFS:try:entries = self._ls_entries(path)except Exception as e:- raise self._convert_agfs_error(e, uri) from e+ raise FileNotFoundError(f"Failed to list {uri}: {e}")# basic infonow = datetime.now()all_entries = []@@ -1149,7 +1120,7 @@ class VikingFS:all_entries.append(new_entry)return all_entriesexcept Exception as e:- raise self._convert_agfs_error(e, uri) from e+ raise FileNotFoundError(f"Failed to list {uri}: {e}")async def move_file(self,diff --git a/openviking/sync_client.py b/openviking/sync_client.pyindex 936328bb9..c440e9d73 100644--- a/openviking/sync_client.py+++ b/openviking/sync_client.py@@ -48,9 +48,24 @@ class SyncOpenViking:"""Delete a session."""run_async(self._async_client.delete_session(session_id))- def add_message(self, session_id: str, role: str, content: str) -> Dict[str, Any]:- """Add a message to a session."""- return run_async(self._async_client.add_message(session_id, role, content))+ def add_message(+ self,+ session_id: str,+ role: str,+ content: str | None = None,+ parts: list[dict] | None = None,+ ) -> Dict[str, Any]:+ """Add a message to a session.++ Args:+ session_id: Session ID+ role: Message role ("user" or "assistant")+ content: Text content (simple mode)+ parts: Parts array (full Part support: TextPart, ContextPart, ToolPart)++ If both content and parts are provided, parts takes precedence.+ """+ return run_async(self._async_client.add_message(session_id, role, content, parts))def commit_session(self, session_id: str) -> Dict[str, Any]:"""Commit a session (archive and extract memories)."""diff --git a/openviking_cli/client/base.py b/openviking_cli/client/base.pyindex 4141ba681..4520e8691 100644--- a/openviking_cli/client/base.py+++ b/openviking_cli/client/base.py@@ -210,8 +210,23 @@ class BaseClient(ABC):...@abstractmethod- async def add_message(self, session_id: str, role: str, content: str) -> Dict[str, Any]:- """Add a message to a session."""+ async def add_message(+ self,+ session_id: str,+ role: str,+ content: str | None = None,+ parts: list[dict] | None = None,+ ) -> Dict[str, Any]:+ """Add a message to a session.++ Args:+ session_id: Session ID+ role: Message role ("user" or "assistant")+ content: Text content (simple mode)+ parts: Parts array (full Part support: TextPart, ContextPart, ToolPart)++ If both content and parts are provided, parts takes precedence.+ """...# ============= Pack =============diff --git a/openviking_cli/client/sync_http.py b/openviking_cli/client/sync_http.pyindex 40ea2e120..4dfbd3fa8 100644--- a/openviking_cli/client/sync_http.py+++ b/openviking_cli/client/sync_http.py@@ -70,9 +70,24 @@ class SyncHTTPClient:"""Delete a session."""run_async(self._async_client.delete_session(session_id))- def add_message(self, session_id: str, role: str, content: str) -> Dict[str, Any]:- """Add a message to a session."""- return run_async(self._async_client.add_message(session_id, role, content))+ def add_message(+ self,+ session_id: str,+ role: str,+ content: str | None = None,+ parts: list[dict] | None = None,+ ) -> Dict[str, Any]:+ """Add a message to a session.++ Args:+ session_id: Session ID+ role: Message role ("user" or "assistant")+ content: Text content (simple mode)+ parts: Parts array (full Part support: TextPart, ContextPart, ToolPart)++ If both content and parts are provided, parts takes precedence.+ """+ return run_async(self._async_client.add_message(session_id, role, content, parts))def commit_session(self, session_id: str) -> Dict[str, Any]:"""Commit a session (archive and extract memories)."""