Add memory management APIs for OpenViking: list, read, write, and delete memories

This commit is contained in:
2026-05-29 16:38:57 +08:00
parent 0ab2a35e16
commit 68b2513043
9 changed files with 578 additions and 3 deletions

View File

@ -68,8 +68,8 @@ class FakeAsyncClient:
self.calls.append(("post", self.api_key, self.headers, path, json, files))
return self.responses.pop(0)
async def get(self, path: str) -> FakeResponse:
self.calls.append(("get", self.api_key, self.headers, path, None))
async def get(self, path: str, params: dict | None = None) -> FakeResponse:
self.calls.append(("get", self.api_key, self.headers, path, params))
return self.responses.pop(0)
async def delete(self, path: str, params: dict | None = None) -> FakeResponse:
@ -573,6 +573,135 @@ def test_openviking_delete_resource_sends_uri_and_recursive_flag():
]
def test_openviking_list_memories_calls_fs_ls_with_recursive_flag():
client = OpenVikingMemorySystemClient(store=FakeStore())
calls = []
responses = [FakeResponse(200, {"status": "ok", "result": {"children": []}})]
client._client = lambda api_key, extra_headers=None, json_content_type=True: FakeAsyncClient( # type: ignore[method-assign]
calls,
responses,
api_key,
extra_headers or {},
)
credential = client.user_credential("tom-key", "tom")
result = asyncio.run(
client.list_memories(
credential,
uri="viking://user/memories",
recursive=True,
)
)
assert result == {"status": "ok", "result": {"children": []}}
assert calls == [
(
"get",
"tom-key",
{},
"/api/v1/fs/ls",
{"uri": "viking://user/memories", "recursive": "true"},
)
]
def test_openviking_read_memory_calls_content_read():
client = OpenVikingMemorySystemClient(store=FakeStore())
calls = []
responses = [FakeResponse(200, {"status": "ok", "result": {"content": "# Python"}})]
client._client = lambda api_key, extra_headers=None, json_content_type=True: FakeAsyncClient( # type: ignore[method-assign]
calls,
responses,
api_key,
extra_headers or {},
)
credential = client.user_credential("tom-key", "tom")
result = asyncio.run(client.read_memory(credential, "viking://user/memories/preferences/python.md"))
assert result == {"status": "ok", "result": {"content": "# Python"}}
assert calls == [
(
"get",
"tom-key",
{},
"/api/v1/content/read",
{"uri": "viking://user/memories/preferences/python.md"},
)
]
def test_openviking_write_memory_posts_content_write_mode_and_wait():
client = OpenVikingMemorySystemClient(store=FakeStore())
calls = []
responses = [FakeResponse(200, {"status": "ok", "result": {"uri": "viking://user/memories/profile.md"}})]
client._client = lambda api_key, extra_headers=None, json_content_type=True: FakeAsyncClient( # type: ignore[method-assign]
calls,
responses,
api_key,
extra_headers or {},
)
credential = client.user_credential("tom-key", "tom")
result = asyncio.run(
client.write_memory(
credential,
uri="viking://user/memories/profile.md",
content="# Profile\n\nLikes Python.",
mode="replace",
wait=True,
)
)
assert result == {"status": "ok", "result": {"uri": "viking://user/memories/profile.md"}}
assert calls == [
(
"post",
"tom-key",
{},
"/api/v1/content/write",
{
"uri": "viking://user/memories/profile.md",
"content": "# Profile\n\nLikes Python.",
"mode": "replace",
"wait": True,
},
None,
)
]
def test_openviking_delete_memory_defaults_non_recursive():
client = OpenVikingMemorySystemClient(store=FakeStore())
calls = []
responses = [FakeResponse(200, {"status": "ok", "result": {"estimated_deleted_count": 1}})]
client._client = lambda api_key, extra_headers=None, json_content_type=True: FakeAsyncClient( # type: ignore[method-assign]
calls,
responses,
api_key,
extra_headers or {},
)
credential = client.user_credential("tom-key", "tom")
result = asyncio.run(
client.delete_memory(
credential,
uri="viking://user/memories/preferences/python.md",
)
)
assert result == {"status": "ok", "result": {"estimated_deleted_count": 1}}
assert calls == [
(
"delete",
"tom-key",
{},
"/api/v1/fs",
{"uri": "viking://user/memories/preferences/python.md", "recursive": "false"},
)
]
def test_everos_assistant_payload_does_not_use_user_id_as_sender():
client = EverOSMemorySystemClient()