UNPKG

@tanstack/ai-persistence

Version:

Composable state persistence for TanStack AI messages, runs, interrupts, metadata, and locks.

69 lines (68 loc) • 2.84 kB
import { Interrupt, ModelMessage, RunAgentResumeItem, RunStore, StreamChunk, SubagentWireInfo, UIMessage } from '@tanstack/ai'; import { InterruptStore, MessageStore, SessionIndexStore } from './types.js'; /** * The stored transcript of a child agent run of `threadId`, for a UI. It * starts with the task of the first call as a user message. Each message * keeps its card in `metadata.tanstack.subagent`. A nested child * belongs to `threadId` when its parents do. `undefined` for an unknown id * and for a child of another thread. */ export declare function loadChildTranscript(messages: MessageStore, subagentRunId: string, threadId: string): Promise<Array<ModelMessage> | undefined>; /** * Card data for a stored child transcript. It rides on the first message, in * `metadata.tanstack.subagent`, the same shape the wire uses. */ export declare function storedSubagentInfo(messages: ReadonlyArray<ModelMessage>): SubagentWireInfo | undefined; export declare function createSubagentRunRecorder(stores: { messages: MessageStore; runs?: RunStore; interrupts?: InterruptStore; /** When present, each child gets a session index entry. */ sessions?: SessionIndexStore; /** * The tenant of the threads, for the session index. The parent entry is * read from it and each child entry is written in it. Without it, the * default tenant. */ tenantId?: string; /** Minimum milliseconds between writes while a child streams. */ intervalMs?: number; }): { loadChild: (subagentRunId: string, caller: { threadId: string; subagentRunId?: string; }) => Promise<{ parentToolCallId?: string | undefined; pending?: ModelMessage<string | import('@tanstack/ai').ContentPart<unknown, unknown, unknown, unknown, unknown>[] | null>[] | undefined; interruptIds?: string[] | undefined; agent?: string | undefined; messages: ModelMessage<string | import('@tanstack/ai').ContentPart<unknown, unknown, unknown, unknown, unknown>[] | null>[]; } | undefined>; start(input: { threadId: string; runId: string; messages: ReadonlyArray<UIMessage | ModelMessage>; resume?: ReadonlyArray<RunAgentResumeItem>; }): Promise<void>; chunk(input: { threadId: string; runId: string; /** Set when the chat that streams this chunk is a child itself. */ subagentRunId?: string; chunk: StreamChunk; }): Promise<void>; suspend(input: { threadId: string; runId: string; interrupts: ReadonlyArray<Interrupt>; }): Promise<void>; finish(input: { threadId: string; runId: string; }): Promise<void>; abort(input: { threadId: string; runId: string; error?: unknown; }): Promise<void>; };