import * as ai from 'ai'; import { z } from 'zod'; /** * Budget levels for recall/reflect operations. */ declare const BudgetSchema: z.ZodEnum<{ low: "low"; mid: "mid"; high: "high"; }>; type Budget = z.infer; /** * Fact types for filtering recall results. */ declare const FactTypeSchema: z.ZodEnum<{ world: "world"; experience: "experience"; observation: "observation"; }>; type FactType = z.infer; /** * Recall result item from Hindsight */ interface RecallResult { id: string; text: string; type?: string | null; entities?: string[] | null; context?: string | null; occurred_start?: string | null; occurred_end?: string | null; mentioned_at?: string | null; document_id?: string | null; metadata?: Record | null; chunk_id?: string | null; } /** * Entity state with observations */ interface EntityState { entity_id: string; canonical_name: string; observations: Array<{ text: string; mentioned_at?: string | null; }>; } /** * Chunk data */ interface ChunkData { id: string; text: string; chunk_index: number; truncated?: boolean; } /** * Recall response from Hindsight */ interface RecallResponse { results: RecallResult[]; trace?: Record | null; entities?: Record | null; chunks?: Record | null; } /** * Reflect fact */ interface ReflectFact { id?: string | null; text: string; type?: string | null; context?: string | null; occurred_start?: string | null; occurred_end?: string | null; } /** * Nested based_on structure from Hindsight reflect */ interface ReflectBasedOn { memories?: ReflectFact[]; mental_models?: Array<{ id: string; text: string; context?: string | null; }>; directives?: Array<{ id: string; name: string; content: string; }>; } /** * Reflect response from Hindsight */ interface ReflectResponse { text: string; based_on?: ReflectBasedOn | null; } /** * Retain response from Hindsight */ interface RetainResponse { success: boolean; bank_id: string; items_count: number; async: boolean; } /** * Mental model trigger configuration */ interface MentalModelTrigger { refresh_after_consolidation?: boolean; } /** * Mental model response from Hindsight */ interface MentalModelResponse { id: string; bank_id: string; name: string; content?: string | null; source_query?: string | null; tags?: string[]; created_at?: string | null; updated_at?: string | null; trigger?: MentalModelTrigger | null; } /** * Document response from Hindsight */ interface DocumentResponse { id: string; bank_id: string; original_text: string; content_hash: string | null; created_at: string; updated_at: string; memory_unit_count: number; tags?: string[]; } /** * Hindsight client interface - matches @vectorize-io/hindsight-client */ interface HindsightClient { retain(bankId: string, content: string, options?: { timestamp?: Date | string; context?: string; metadata?: Record; documentId?: string; tags?: string[]; async?: boolean; }): Promise; recall(bankId: string, query: string, options?: { types?: FactType[]; maxTokens?: number; budget?: Budget; trace?: boolean; queryTimestamp?: string; includeEntities?: boolean; maxEntityTokens?: number; includeChunks?: boolean; maxChunkTokens?: number; }): Promise; reflect(bankId: string, query: string, options?: { context?: string; budget?: Budget; maxTokens?: number; }): Promise; getMentalModel(bankId: string, mentalModelId: string): Promise; getDocument(bankId: string, documentId: string): Promise; } interface HindsightToolsOptions { /** Hindsight client instance */ client: HindsightClient; /** Memory bank ID to use for all tool calls (e.g. the user ID) */ bankId: string; /** Options for the retain tool */ retain?: { /** Fire-and-forget retain without waiting for completion (default: false) */ async?: boolean; /** Tags always attached to every retained memory (default: undefined) */ tags?: string[]; /** Metadata always attached to every retained memory (default: undefined) */ metadata?: Record; /** Custom tool description */ description?: string; }; /** Options for the recall tool */ recall?: { /** Restrict results to these fact types: 'world', 'experience', 'observation' (default: undefined = all types) */ types?: FactType[]; /** Maximum tokens to return (default: undefined = API default) */ maxTokens?: number; /** Processing budget controlling latency vs. depth (default: 'mid') */ budget?: Budget; /** Include entity observations in results (default: false) */ includeEntities?: boolean; /** Include raw source chunks in results (default: false) */ includeChunks?: boolean; /** Custom tool description */ description?: string; }; /** Options for the reflect tool */ reflect?: { /** Processing budget controlling latency vs. depth (default: 'mid') */ budget?: Budget; /** Maximum tokens for the response (default: undefined = API default) */ maxTokens?: number; /** Custom tool description */ description?: string; }; /** Options for the getMentalModel tool */ getMentalModel?: { /** Custom tool description */ description?: string; }; /** Options for the getDocument tool */ getDocument?: { /** Custom tool description */ description?: string; }; } /** * Creates AI SDK tools for Hindsight memory operations. * * The bank ID and all infrastructure concerns (budget, tags, async mode, etc.) * are fixed at creation time. The agent only controls semantic inputs: * content, queries, names, and timestamps. * * @example * ```ts * const tools = createHindsightTools({ * client: hindsightClient, * bankId: userId, * recall: { budget: 'high', includeEntities: true }, * retain: { async: true, tags: ['env:prod'] }, * }); * * const result = await generateText({ * model: openai('gpt-4o'), * tools, * messages, * }); * ``` */ declare function createHindsightTools({ client, bankId, retain: retainOpts, recall: recallOpts, reflect: reflectOpts, getMentalModel: getMentalModelOpts, getDocument: getDocumentOpts, }: HindsightToolsOptions): { retain: ai.Tool<{ content: string; documentId?: string | undefined; timestamp?: string | undefined; context?: string | undefined; }, { success: boolean; itemsCount: number; }>; recall: ai.Tool<{ query: string; queryTimestamp?: string | undefined; }, { results: RecallResult[]; entities?: Record | null; }>; reflect: ai.Tool<{ query: string; context?: string | undefined; }, { text: string; basedOn?: ReflectBasedOn | null; }>; getMentalModel: ai.Tool<{ mentalModelId: string; }, { content: string; name: string; updatedAt?: string | null; }>; getDocument: ai.Tool<{ documentId: string; }, { originalText: string; id: string; createdAt: string; updatedAt: string; } | null>; }; type HindsightTools = ReturnType; export { type Budget, BudgetSchema, type ChunkData, type EntityState, type HindsightClient, type HindsightTools, type HindsightToolsOptions, type RecallResponse, type RecallResult, type ReflectFact, type ReflectResponse, type RetainResponse, createHindsightTools };