import { type DB } from '../db/client.js'; import type { AgentMessage } from './types.js'; export type MemoryField = 'id' | 'turnId' | 'whatsapp' | 'stepIndex' | 'role' | 'content' | 'toolCallsJson' | 'toolCallId' | 'toolName' | 'tenantId' | 'createdAt'; export declare const DEFAULT_MEMORY_COLUMNS: Readonly>; export interface ConversationMemoryOptions { db: D1Database | DB; /** Physical table name. Default `'agent_turns'`. */ tableName?: string; columnMap?: Partial>; omitColumns?: ReadonlyArray; allowedExtraColumns?: ReadonlyArray; /** * Multi-tenant scoping. When set, every append writes this value and * every load restricts to it. Null / undefined = no scoping. */ tenantId?: string | null; } export interface AppendRowInput { turnId: string; whatsapp: string; stepIndex: number; message: AgentMessage; extraColumns?: Record; } export interface LoadWindowOptions { /** Max messages to load. Default 20. */ limit?: number; /** * Optional per-load tenant override — usually unnecessary since the * store is constructed with a tenantId, but useful when one instance * serves multiple tenants. */ tenantId?: string | null; } export declare class ConversationMemory { readonly db: DB; readonly tableName: string; readonly columns: Readonly>; readonly omitColumns: ReadonlySet; readonly allowedExtraColumns: ReadonlySet; readonly tenantId: string | null; constructor({ db, tableName, columnMap, omitColumns, allowedExtraColumns, tenantId, }: ConversationMemoryOptions); /** * Append a single row. The loop typically calls this once per message * as it processes each step, so partial failures leave a * self-consistent trail up to the failure point. */ append(input: AppendRowInput): Promise; /** * Load the most recent N messages for a user, in chronological order * (oldest first) so callers can append to a system prompt without * reversing. * * The window may split a turn — e.g. return a tool result whose * assistant parent is beyond `limit`. That's fine for the LLM (it * ignores dangling tool rows that predate its context), but callers * that need strict turn-atomicity should size `limit` generously. */ loadWindow(whatsapp: string, opts?: LoadWindowOptions): Promise; /** * Load every row of a single turn, in step order. Useful for * post-hoc debugging (dashboards, tracer replays). */ loadTurn(turnId: string): Promise; private rowToMessage; } //# sourceMappingURL=conversation_memory.d.ts.map