Skip to content

@pgege/kaboo-runtime


Interface: ThreadStore

Defined in: src/store.ts:39

Pluggable persistence for a thread's full AG-UI event log.

This is the extension point: implement it against your own database to control where conversations live. kaboo-runtime ships InMemoryThreadStore and PostgresThreadStore out of the box.

The store persists events verbatim so ACTIVITY_SNAPSHOT / CUSTOM events survive the round-trip and the full UI can be replayed — with one exception: superseded ACTIVITY_SNAPSHOT events. Each snapshot fully replaces the previous one for its message, so only the latest per message affects a replay, while a long run can emit thousands of them at hundreds of KB each (a single conversation reaching hundreds of MB in practice). Stores prune superseded snapshots on append via pruneSupersededActivitySnapshots; custom stores should do the same.

Methods

appendEvents()

appendEvents(threadId, agentId, events, ownerId?): Promise\<void>

Defined in: src/store.ts:47

Append a completed run's events (in order) to the thread's log.

ownerId records the owning subject on the thread (the runner passes it from accessPolicy.ownerOf). A nullish value must preserve any owner already recorded.

Parameters

threadId

string

agentId

string

events

objectOutputType\<{ rawEvent: ZodOptional\<ZodAny>; timestamp: ZodOptional\<ZodNumber>; type: ZodNativeEnum\<typeof EventType>; }, ZodTypeAny, "passthrough">[]

ownerId?

string | null

Returns

Promise\<void>


clear()

clear(threadId?): Promise\<void>

Defined in: src/store.ts:67

Delete one thread's data, or all threads when threadId is omitted.

Parameters

threadId?

string

Returns

Promise\<void>


listThreads()

listThreads(filter?): Promise\<StoredThread[]>

Defined in: src/store.ts:65

List persisted threads, most recently updated first. With filter.ownerId, only that subject's threads are returned.

Parameters

filter?

ListThreadsFilter

Returns

Promise\<StoredThread[]>


readEvents()

readEvents(threadId): Promise\<objectOutputType\<{ rawEvent: ZodOptional\<ZodAny>; timestamp: ZodOptional\<ZodNumber>; type: ZodNativeEnum\<typeof EventType>; }, ZodTypeAny, "passthrough">[]>

Defined in: src/store.ts:54

Read the thread's full event log, verbatim and in order.

Parameters

threadId

string

Returns

Promise\<objectOutputType\<{ rawEvent: ZodOptional\<ZodAny>; timestamp: ZodOptional\<ZodNumber>; type: ZodNativeEnum\<typeof EventType>; }, ZodTypeAny, "passthrough">[]>


readMessages()

readMessages(threadId): Promise\<({ content: string; encryptedValue?: string; id: string; name?: string; role: "developer"; } | { content: string; encryptedValue?: string; id: string; name?: string; role: "system"; } | { content?: string; encryptedValue?: string; id: string; name?: string; role: "assistant"; toolCalls?: object[]; } | { content: string | ({ text: string; type: "text"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: ... | ...; type: "url"; value: string; }; type: "image"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: ... | ...; type: "url"; value: string; }; type: "audio"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: ... | ...; type: "url"; value: string; }; type: "video"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: ... | ...; type: "url"; value: string; }; type: "document"; } | { data?: string; filename?: string; id?: string; mimeType: string; type: "binary"; url?: string; })[]; encryptedValue?: string; id: string; name?: string; role: "user"; } | { content: string; encryptedValue?: string; error?: string; id: string; role: "tool"; toolCallId: string; } | { activityType: string; content: Record\<string, any>; id: string; role: "activity"; } | { content: string; encryptedValue?: string; id: string; role: "reasoning"; })[]>

Defined in: src/store.ts:60

Read the derived message snapshot for a thread.

Parameters

threadId

string

Returns

Promise\<({ content: string; encryptedValue?: string; id: string; name?: string; role: "developer"; } | { content: string; encryptedValue?: string; id: string; name?: string; role: "system"; } | { content?: string; encryptedValue?: string; id: string; name?: string; role: "assistant"; toolCalls?: object[]; } | { content: string | ({ text: string; type: "text"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: ... | ...; type: "url"; value: string; }; type: "image"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: ... | ...; type: "url"; value: string; }; type: "audio"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: ... | ...; type: "url"; value: string; }; type: "video"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: ... | ...; type: "url"; value: string; }; type: "document"; } | { data?: string; filename?: string; id?: string; mimeType: string; type: "binary"; url?: string; })[]; encryptedValue?: string; id: string; name?: string; role: "user"; } | { content: string; encryptedValue?: string; error?: string; id: string; role: "tool"; toolCallId: string; } | { activityType: string; content: Record\<string, any>; id: string; role: "activity"; } | { content: string; encryptedValue?: string; id: string; role: "reasoning"; })[]>


readState()

readState(threadId): Promise\<Record\<string, unknown> | null>

Defined in: src/store.ts:56

Read the latest agent state (from the last STATE_SNAPSHOT), or null.

Parameters

threadId

string

Returns

Promise\<Record\<string, unknown> | null>


saveMessages()

saveMessages(threadId, messages): Promise\<void>

Defined in: src/store.ts:58

Persist the derived message snapshot for a thread.

Parameters

threadId

string

messages

({ content: string; encryptedValue?: string; id: string; name?: string; role: "developer"; } | { content: string; encryptedValue?: string; id: string; name?: string; role: "system"; } | { content?: string; encryptedValue?: string; id: string; name?: string; role: "assistant"; toolCalls?: object[]; } | { content: string | ({ text: string; type: "text"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: string; type: "url"; value: string; }; type: "image"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: string; type: "url"; value: string; }; type: "audio"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: string; type: "url"; value: string; }; type: "video"; } | { metadata?: unknown; source: { mimeType: string; type: "data"; value: string; } | { mimeType?: string; type: "url"; value: string; }; type: "document"; } | { data?: string; filename?: string; id?: string; mimeType: string; type: "binary"; url?: string; })[]; encryptedValue?: string; id: string; name?: string; role: "user"; } | { content: string; encryptedValue?: string; error?: string; id: string; role: "tool"; toolCallId: string; } | { activityType: string; content: Record\<string, any>; id: string; role: "activity"; } | { content: string; encryptedValue?: string; id: string; role: "reasoning"; })[]

Returns

Promise\<void>