Skip to content

@pgege/kaboo-runtime


Class: PostgresThreadStore

Defined in: src/stores/postgres.ts:32

Durable ThreadStore backed by Postgres. Uses its own conversation tables (kaboo_threads, kaboo_thread_events, kaboo_thread_messages), independent of any application schema. pg is an optional peer dependency — install it in the host app to use this store.

Example

import { createKabooRunner, PostgresThreadStore } from "@pgege/kaboo-runtime";

const store = new PostgresThreadStore({ dsn: process.env.DATABASE_URL });
const runner = createKabooRunner(store);

Implements

Constructors

Constructor

new PostgresThreadStore(options): PostgresThreadStore

Defined in: src/stores/postgres.ts:37

Parameters

options

PostgresThreadStoreOptions

Returns

PostgresThreadStore

Methods

appendEvents()

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

Defined in: src/stores/postgres.ts:84

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

Parameters

threadId

string

agentId

string

events

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

Returns

Promise\<void>

Implementation of

ThreadStore.appendEvents


clear()

clear(threadId?): Promise\<void>

Defined in: src/stores/postgres.ts:157

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

Parameters

threadId?

string

Returns

Promise\<void>

Implementation of

ThreadStore.clear


listThreads()

listThreads(): Promise\<StoredThread[]>

Defined in: src/stores/postgres.ts:144

List every persisted thread, most recently updated first.

Returns

Promise\<StoredThread[]>

Implementation of

ThreadStore.listThreads


readEvents()

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

Defined in: src/stores/postgres.ts:112

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">[]>

Implementation of

ThreadStore.readEvents


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/stores/postgres.ts:135

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"; })[]>

Implementation of

ThreadStore.readMessages


readState()

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

Defined in: src/stores/postgres.ts:121

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

Parameters

threadId

string

Returns

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

Implementation of

ThreadStore.readState


saveMessages()

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

Defined in: src/stores/postgres.ts:125

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>

Implementation of

ThreadStore.saveMessages