feat(client): client-side caching for conversation list via agent.outbox events
Adds `agent.conversationStore` (read-only view on `conversation` table) to
the :proto Agent interface, plus `agent.renameConversation(id, title?)`
command. Client-side cache in :client is built from a snapshot
(`remote.listFlow(0)` → `local.upsert(...)`) + live updates via
`outbox.agentEvents()` (Created/Deleted/Renamed/Touched).
Changes:
- :journal-api — split `ConversationStore` (read-only: get/list) and
`MutableConversationStore` (CRUD: upsert/delete/rename/touch);
`ConversationStore` gained `listFlow` (cold-flow paging via `list`).
- :outbox-api — `AgentEvent.Touched(date, id, updatedAt)` event so
client cache stays fresh after `send()` (which bumps `updatedAt`).
- :proto.Agent — added `conversationStore: ConversationStore` property,
added `renameConversation(id, title?): Instant?` command, removed
`getConversations(offset, limit)` (now: `conversationStore.list(...)`).
- :server — `GET /conversations` now returns `List<ConversationRecord>`
(lightweight metadata, no handle/image-support flags); `PATCH
/conversations/{id}` uses `agent.renameConversation` and returns
the updated `ConversationRecord`.
- :journal-inmemory — expanded targets to jvm+macos+linux+mingw (matches
:client); moved `InMemoryMutableConversationStore` here from
:storage-inmemory so :client can use it without pulling ios targets.
- :storage-inmemory — depends on :journal-inmemory.
- :storage-ksqlite — pre-staged rename `KsqliteConversationStore` →
`KsqliteMutableConversationStore` to match the new interface split.
- :standalone — `ChatAgent` exposes `conversationStore` as a read-only
view of its `mutableConversationStore`; emits `AgentEvent.Touched`
after each `send()` (after `conversationStore.touch(id, ts)`).
- :client — new `HttpConversationStore` (read-only HTTP impl);
`AgentikAgent` wraps the agent with `wrapWithLocalConversationCache`
so the client sees an in-memory cache (snapshot + outbox events)
instead of direct HTTP. Cache scope + HttpClient + background job
all cancelled in `agent.close()`.
- :client/README — new «Кэш списка бесед» section with the
`listFlow → upsert` / `agentEvents → apply` pattern and a note that
`conversationStore` is read-only (writes only via Agent commands).
All 96 jvmTest tasks green.
This commit is contained in:
+4
-4
@@ -3,7 +3,7 @@ package pw.binom.agentik.storage.ksqlite
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.Instant
|
||||
import pw.binom.agentik.journal.ConversationRecord
|
||||
import pw.binom.agentik.journal.ConversationStore
|
||||
import pw.binom.agentik.journal.MutableConversationStore
|
||||
import pw.binom.db.ksqlite.SQLiteConnection
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
@@ -11,15 +11,15 @@ import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* ksqlite-реализация [ConversationStore]. Схема таблицы `conversation` живёт
|
||||
* ksqlite-реализация [MutableConversationStore]. Схема таблицы `conversation` живёт
|
||||
* в [Schema] (миграция через PRAGMA user_version) — этот класс только
|
||||
* готовит и выполняет SQL, ссылаясь на `Schema.COL_*` / `Schema.TABLE_*`.
|
||||
*/
|
||||
class KsqliteConversationStore(
|
||||
class KsqliteMutableConversationStore(
|
||||
private val connection: SQLiteConnection,
|
||||
private val messageStore: KsqliteMessageStore? = null,
|
||||
private val workingMemoryStore: KsqliteWorkingMemoryStore? = null,
|
||||
) : ConversationStore {
|
||||
) : MutableConversationStore {
|
||||
|
||||
private val mutex = Mutex()
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@ package pw.binom.agentik.storage.ksqlite
|
||||
|
||||
import pw.binom.agentik.context.ContextStore
|
||||
import pw.binom.agentik.journal.MutableJournalStore
|
||||
import pw.binom.agentik.journal.ConversationStore
|
||||
import pw.binom.agentik.journal.MutableConversationStore
|
||||
import pw.binom.agentik.reflection.ReflectionStore
|
||||
import pw.binom.db.ksqlite.SQLiteConnection
|
||||
|
||||
@@ -17,7 +17,7 @@ import pw.binom.db.ksqlite.SQLiteConnection
|
||||
*/
|
||||
class KsqliteStores internal constructor(
|
||||
val connection: SQLiteConnection,
|
||||
val conversations: ConversationStore,
|
||||
val conversations: MutableConversationStore,
|
||||
val messages: MutableJournalStore,
|
||||
val workingMemory: ContextStore,
|
||||
val reflections: ReflectionStore,
|
||||
@@ -51,7 +51,7 @@ class KsqliteStores internal constructor(
|
||||
val working = KsqliteWorkingMemoryStore(conn)
|
||||
return KsqliteStores(
|
||||
connection = conn,
|
||||
conversations = KsqliteConversationStore(conn, messages, working),
|
||||
conversations = KsqliteMutableConversationStore(conn, messages, working),
|
||||
messages = messages,
|
||||
workingMemory = working,
|
||||
reflections = KsqliteReflectionStore(conn),
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import kotlin.test.assertTrue
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Instant
|
||||
|
||||
class KsqliteConversationStoreTest {
|
||||
class KsqliteMutableConversationStoreTest {
|
||||
private lateinit var stores: KsqliteStores
|
||||
|
||||
@BeforeTest
|
||||
+1
-1
@@ -79,7 +79,7 @@ class SchemaMigrationTest {
|
||||
// constructor internal, тест в том же модуле и может его звать.
|
||||
val stores = KsqliteStores(
|
||||
connection = conn,
|
||||
conversations = KsqliteConversationStore(conn),
|
||||
conversations = KsqliteMutableConversationStore(conn),
|
||||
messages = KsqliteMessageStore(conn),
|
||||
workingMemory = KsqliteWorkingMemoryStore(conn),
|
||||
reflections = KsqliteReflectionStore(conn),
|
||||
|
||||
Reference in New Issue
Block a user