/** * Minimal fetch-based client for the Hindsight HTTP API. * * Replaces the `@vectorize-io/hindsight-client` SDK with hand-rolled fetch * calls so we depend on nothing more than the API endpoints we actually use: * `retain`, `retainBatch`, `recall`, `reflect`, bank + document management, * and bulk listing. Centralising construction here keeps a single seam for * tests to spy on. */ import type { HindsightConfig } from "./config"; export type Budget = "low" | "mid" | "high" | string; export type TagsMatch = "any" | "all" | "any_strict" | "all_strict"; export type UpdateMode = "replace" | "append"; export type ConsolidationState = "failed" | "pending" | "done"; export interface HindsightApiOptions { baseUrl: string; apiKey?: string; userAgent?: string; } export interface RecallResult { id?: string; text: string; type?: string | null; mentioned_at?: string | null; [key: string]: unknown; } export interface RecallResponse { results: RecallResult[]; [key: string]: unknown; } export interface ReflectResponse { text?: string; [key: string]: unknown; } export interface RetainResponse { [key: string]: unknown; } export interface BankProfileResponse { [key: string]: unknown; } export interface ListMemoriesResponse { [key: string]: unknown; } export interface DocumentResponse { [key: string]: unknown; } export interface ListDocumentsResponse { [key: string]: unknown; } /** Mirrors the shape accepted by `POST /v1/default/banks/{bank_id}/memories`. */ export interface MemoryItemInput { content: string; timestamp?: Date | string; context?: string; metadata?: Record; documentId?: string; tags?: string[]; /** Scoping policy for observations derived from this item. */ observationScopes?: "per_tag" | "combined" | "all_combinations" | string[][]; /** Per-item extraction strategy override. */ strategy?: string; updateMode?: UpdateMode; } export interface RetainOptions { timestamp?: Date | string; context?: string; metadata?: Record; documentId?: string; async?: boolean; tags?: string[]; updateMode?: UpdateMode; } export interface RetainBatchOptions { /** Document id applied to every item that doesn't carry its own. */ documentId?: string; /** Tags attached to the resulting document(s), not individual items. */ documentTags?: string[]; async?: boolean; } export interface RecallOptions { types?: string[]; maxTokens?: number; budget?: Budget; tags?: string[]; tagsMatch?: TagsMatch; } export interface ReflectOptions { context?: string; budget?: Budget; tags?: string[]; tagsMatch?: TagsMatch; } export interface CreateBankOptions { reflectMission?: string; retainMission?: string; } export interface ListMemoriesOptions { limit?: number; offset?: number; type?: string; q?: string; consolidationState?: ConsolidationState; } export interface ListDocumentsOptions { limit?: number; offset?: number; } export interface UpdateDocumentOptions { tags?: string[]; } export type MentalModelDetail = "metadata" | "content" | "full"; export type MentalModelMode = "full" | "delta"; export interface MentalModelTrigger { mode?: MentalModelMode; refresh_after_consolidation?: boolean; } /** Shape returned by list/get on the mental-models endpoint. Fields are populated by `detail`. */ export interface MentalModelSummary { id: string; bank_id: string; name: string; tags?: string[]; last_refreshed_at?: string | null; created_at?: string | null; source_query?: string; content?: string; max_tokens?: number; trigger?: MentalModelTrigger; [key: string]: unknown; } export interface MentalModelListResponse { items: MentalModelSummary[]; [key: string]: unknown; } export interface MentalModelHistoryEntry { previous_content: string | null; changed_at: string; [key: string]: unknown; } export interface CreateMentalModelOptions { id?: string; tags?: string[]; maxTokens?: number; trigger?: MentalModelTrigger; } export interface CreateMentalModelResponse { operation_id?: string; [key: string]: unknown; } export interface RefreshMentalModelResponse { operation_id?: string; [key: string]: unknown; } export interface ListMentalModelsOptions { detail?: MentalModelDetail; } export interface GetMentalModelOptions { detail?: MentalModelDetail; } export declare class HindsightError extends Error { statusCode?: number; details?: unknown; constructor(message: string, statusCode?: number, details?: unknown); } export declare class HindsightApi { #private; constructor(options: HindsightApiOptions); retain(bankId: string, content: string, options?: RetainOptions): Promise; /** * Retain multiple memories in a single request. Mirrors the official * client's `retainBatch` — items hit `POST /memories` together so the * server can dedupe and consolidate as a batch instead of N round-trips. * * Per-item `documentId` wins; `options.documentId` only fills the gaps. */ retainBatch(bankId: string, items: MemoryItemInput[], options?: RetainBatchOptions): Promise; recall(bankId: string, query: string, options?: RecallOptions): Promise; reflect(bankId: string, query: string, options?: ReflectOptions): Promise; createBank(bankId: string, options?: CreateBankOptions): Promise; /** * Bulk-list memory units in a bank with optional filters and pagination. * Endpoint: `GET /v1/default/banks/{bank_id}/memories/list`. */ listMemories(bankId: string, options?: ListMemoriesOptions): Promise; /** Bulk-list documents in a bank. */ listDocuments(bankId: string, options?: ListDocumentsOptions): Promise; /** Fetch a document. Returns `null` on 404 instead of throwing. */ getDocument(bankId: string, documentId: string): Promise; /** Update a document's mutable fields (currently just tags). */ updateDocument(bankId: string, documentId: string, options: UpdateDocumentOptions): Promise; /** * Delete a document and every memory derived from it. Returns `true` on * success, `false` if the document was already gone (404). */ deleteDocument(bankId: string, documentId: string): Promise; /** * List mental models in a bank. Default `detail=content` includes the * generated `content` text but excludes the heavyweight `reflect_response` * provenance chain (which can exceed 200KB). Use `detail=metadata` for * inventory and `detail=full` only for debug surfaces. */ listMentalModels(bankId: string, options?: ListMentalModelsOptions): Promise; /** Fetch a single mental model. Returns `null` on 404. */ getMentalModel(bankId: string, mentalModelId: string, options?: GetMentalModelOptions): Promise; /** * Create a mental model. Asynchronous on the server: returns an * `operation_id`; the model's `content` populates after the background * reflect completes. */ createMentalModel(bankId: string, name: string, sourceQuery: string, options?: CreateMentalModelOptions): Promise; /** Trigger an out-of-band refresh of a mental model. Returns the operation handle. */ refreshMentalModel(bankId: string, mentalModelId: string): Promise; /** Delete a mental model. Returns `true` on success, `false` if it was already gone (404). */ deleteMentalModel(bankId: string, mentalModelId: string): Promise; /** * Fetch the change history of a mental model. Each entry captures the * content snapshot BEFORE that change; the current content is read via * `getMentalModel`. Most-recent first. */ getMentalModelHistory(bankId: string, mentalModelId: string): Promise; } export declare function createHindsightClient(config: HindsightConfig & { hindsightApiUrl: string; }): HindsightApi;