Skip to content

@pgege/kaboo-runtime


Class: PostgresThreadStore

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

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:54

Parameters

options

PostgresThreadStoreOptions

Returns

PostgresThreadStore

Methods

appendEvents()

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

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

Append 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

BaseEvent[]

ownerId?

string | null

Returns

Promise\<void>

Implementation of

ThreadStore.appendEvents


clear()

clear(threadId?): Promise\<void>

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

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

Parameters

threadId?

string

Returns

Promise\<void>

Implementation of

ThreadStore.clear


compactRun()

compactRun(threadId, runId): Promise\<void>

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

Replace a finished run's events with compactRunEvents of them, in place: events appended after the run keep their position. A run that has not finished, or is not in the log, is left alone.

Parameters

threadId

string

runId

string

Returns

Promise\<void>

Implementation of

ThreadStore.compactRun


listThreads()

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

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

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

Parameters

filter?

ListThreadsFilter

Returns

Promise\<StoredThread[]>

Implementation of

ThreadStore.listThreads


readEvents()

readEvents(threadId): Promise\<BaseEvent[]>

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

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

Parameters

threadId

string

Returns

Promise\<BaseEvent[]>

Implementation of

ThreadStore.readEvents


readMessages()

readMessages(threadId): Promise\<Message[]>

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

Read the derived message snapshot for a thread.

Parameters

threadId

string

Returns

Promise\<Message[]>

Implementation of

ThreadStore.readMessages


readState()

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

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

Read the latest agent state (see deriveState), 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:217

Persist the derived message snapshot for a thread.

Parameters

threadId

string

messages

Message[]

Returns

Promise\<void>

Implementation of

ThreadStore.saveMessages