From 44b71e784907b9e76dd1bb7aa8ba11a683f6565a Mon Sep 17 00:00:00 2001 From: lda Date: Tue, 1 Sep 2026 01:35:03 +0700 Subject: [PATCH] feat: add Store Protocol (dumb I/O) --- src/agentmsgs/core/store.py | 23 +++++++++++++++++++++++ tests/test_store_protocol.py | 10 ++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/agentmsgs/core/store.py create mode 100644 tests/test_store_protocol.py diff --git a/src/agentmsgs/core/store.py b/src/agentmsgs/core/store.py new file mode 100644 index 0000000..ad8da2f --- /dev/null +++ b/src/agentmsgs/core/store.py @@ -0,0 +1,23 @@ +from __future__ import annotations +from typing import Protocol +import uuid +from .types import Agent, Thread, Message + + +class Store(Protocol): + def get_or_create_agent(self, name: str) -> Agent: ... + def get_agent_by_name(self, name: str) -> Agent | None: ... + def get_agent_by_id(self, id: uuid.UUID) -> Agent | None: ... + def create_agent(self, name: str) -> Agent: ... + def delete_agent(self, id: uuid.UUID) -> None: ... + def list_agents(self) -> list[Agent]: ... + def create_thread(self, participants: set[Agent]) -> Thread: ... + def get_thread(self, id: uuid.UUID) -> Thread | None: ... + def find_threads(self, containing: set[Agent]) -> list[Thread]: ... + def add_participant(self, thread_id: uuid.UUID, agent: Agent) -> Thread: ... + def remove_participant(self, thread_id: uuid.UUID, agent: Agent) -> Thread: ... + def delete_thread(self, id: uuid.UUID) -> None: ... + def append_message(self, thread_id: uuid.UUID, sender: Agent, content: str) -> Message: ... + def list_messages(self, thread_id: uuid.UUID, after_seq: int = 0) -> list[Message]: ... + def get_cursor(self, thread_id: uuid.UUID, agent: Agent) -> int: ... + def set_cursor(self, thread_id: uuid.UUID, agent: Agent, seq: int) -> None: ... diff --git a/tests/test_store_protocol.py b/tests/test_store_protocol.py new file mode 100644 index 0000000..2b94c1e --- /dev/null +++ b/tests/test_store_protocol.py @@ -0,0 +1,10 @@ +from typing import Protocol +from agentmsgs.core.store import Store +import inspect + + +def test_store_is_protocol(): + assert issubclass(Store, Protocol) + # check required methods exist + for m in ["get_or_create_agent","get_agent_by_name","get_agent_by_id","create_agent","delete_agent","list_agents","create_thread","get_thread","find_threads","add_participant","remove_participant","delete_thread","append_message","list_messages","get_cursor","set_cursor"]: + assert hasattr(Store, m), f"missing {m}"