/** * Type definitions for the Surreal-Memory REST API. * * Mirrors the server response shapes from `src/surreal_memory/server/`. * Only public-API fields are typed here; internal fields are passed through * as `unknown` so the SDK does not break when the server adds new fields. */ type MemoryType = "fact" | "decision" | "error" | "insight" | "preference" | "workflow" | "instruction" | "concept" | "context" | "todo"; type SynapseType = "CAUSED_BY" | "LEADS_TO" | "CONTRADICTS" | "SIMILAR_TO" | "PART_OF" | "USED_BY" | "DEPENDS_ON" | string; type NeuronType = "entity" | "concept" | "time" | "action" | "intent" | "state"; type LifecycleStage = "full" | "summary" | "essence" | "ghost" | "metadata"; interface Neuron { id: string; type: NeuronType; content: string; content_hash?: number; created_at: string; metadata?: Record; } interface Synapse { id: string; type: SynapseType; source_id: string; target_id: string; weight?: number; created_at: string; } interface Fiber { id: string; content: string; type?: MemoryType; priority?: number; tags?: string[]; stage?: LifecycleStage; created_at: string; updated_at?: string; metadata?: Record; } interface Brain { id: string; name: string; created_at: string; stats?: BrainStats; } interface BrainStats { neurons: number; synapses: number; fibers: number; active_neurons?: number; } interface RememberRequest { content: string; type?: MemoryType; priority?: number; tags?: string[]; ephemeral?: boolean; metadata?: Record; } interface RememberResponse { fiber_id: string; type: MemoryType; saved: true; } interface RecallRequest { query: string; limit?: number; type?: MemoryType; tags?: string[]; min_priority?: number; } interface RecallResult { fiber: Fiber; score: number; activation?: number; } interface RecallResponse { results: RecallResult[]; query: string; brain: string; } interface ContextRequest { limit?: number; since?: string; } interface ContextResponse { fibers: Fiber[]; brain: string; count: number; } interface HealthResponse { status: "ok" | "degraded" | "down"; version: string; storage: string; brain?: string; } interface ApiErrorPayload { detail?: string; error?: string; status?: number; } /** * SurrealMemoryClient — typed REST client for a running Surreal-Memory server. * * @example * ```ts * import { SurrealMemoryClient } from "@acidkill/surreal-memory-client" * * const client = new SurrealMemoryClient({ * baseUrl: "http://localhost:8000", * brain: "myproject", * }) * * const { fiber_id } = await client.remember({ * content: "Fixed auth bug with null check in login.py:42", * type: "fix", * priority: 7, * tags: ["auth"], * }) * * const { results } = await client.recall({ query: "auth bug", limit: 5 }) * ``` */ interface ClientOptions { /** REST server URL, e.g. `http://localhost:8000`. No trailing slash. */ baseUrl: string; /** Default brain name. Can be overridden per-request. Optional. */ brain?: string; /** Optional bearer token sent as `Authorization: Bearer `. */ apiKey?: string; /** Custom `fetch` implementation (defaults to global `fetch`). */ fetch?: typeof fetch; /** Default timeout in ms (defaults to 30000). */ timeoutMs?: number; /** Extra headers attached to every request. */ headers?: Record; } interface RequestOptions { /** Override the brain for this single call. */ brain?: string; /** Override the timeout for this single call. */ timeoutMs?: number; /** AbortSignal for cancellation. */ signal?: AbortSignal; /** Additional headers merged on top of client defaults. */ headers?: Record; } declare class ApiError extends Error { readonly status: number; readonly payload: ApiErrorPayload | undefined; constructor(status: number, message: string, payload?: ApiErrorPayload); } declare class SurrealMemoryClient { private readonly baseUrl; private readonly defaultBrain; private readonly apiKey; private readonly fetchImpl; private readonly defaultTimeoutMs; private readonly defaultHeaders; constructor(options: ClientOptions); remember(req: RememberRequest, options?: RequestOptions): Promise; recall(req: RecallRequest, options?: RequestOptions): Promise; context(req?: ContextRequest, options?: RequestOptions): Promise; getFiber(fiberId: string, options?: RequestOptions): Promise; forget(fiberId: string, options?: RequestOptions): Promise<{ deleted: true; }>; listBrains(options?: RequestOptions): Promise; getBrainStats(options?: RequestOptions): Promise; health(options?: RequestOptions): Promise; private request; private safeReadErrorPayload; private buildQuery; } export { ApiError, type ApiErrorPayload, type Brain, type BrainStats, type ClientOptions, type ContextRequest, type ContextResponse, type Fiber, type HealthResponse, type LifecycleStage, type MemoryType, type Neuron, type NeuronType, type RecallRequest, type RecallResponse, type RecallResult, type RememberRequest, type RememberResponse, type RequestOptions, SurrealMemoryClient, type Synapse, type SynapseType };