/** * Context API types */ export interface PaginationOptions { /** * ZERO-indexed page number; the first page is 0 (also the server default). * `page: 1` requests the SECOND page — on a result set smaller than * page_size that returns `{ contexts: [], total: N }`, which is easy to * misread as missing data. Omit unless you are actually paging. */ page?: number; page_size?: number; } /** * POST /v1/memories request — semantic search with optional advanced recall. * * @example * ```ts * // Plain search * await client.retrieveMemories({ query: 'billing issues', limit: 10 }); * * // "Everything about Alice", even what text search misses * await client.retrieveMemories({ * query: 'recent activity', * boostContextIds: ['user:alice'], * coverageContextIds: ['user:alice'], * coverageGroupPrefix: 'session:', * sources: ['user', 'verified'], * }); * ``` */ export interface ContextQuery { graph_id?: string; query: string; limit?: number; /** * Where in the ranking to start. Capped at 1000: every channel fetches a * multiple of the window it has to cover, so an unbounded offset is an * unbounded query. * * Exact for the first pages. Past the candidate pool a deeper page searches a * wider pool and a memory can repeat or be skipped, so enumeration wants * `listLocuses` or `locusesForContext`, which page over a stable order. */ offset?: number; context_ids?: string[]; context_types?: Record; /** How many levels to expand (context hierarchy and locus links). Default 1. Use 2 for grandchildren. */ expand_depth?: number; /** ADDITIVE recall (widens): facts linked to these contexts join the * candidate pool alongside search hits — unlike contextIds, which * restricts. Use when the question is about a known entity (e.g. * ["person:alice"]) so its facts surface even if text search misses them. */ boost_context_ids?: string[]; /** COVERAGE recall: like boost, plus a reserved share (~40%) of the result * window spread across the contexts' timeline. For list-everything * questions whose answers are scattered over many sessions. */ coverage_context_ids?: string[]; /** How coverage picks are spread: a context-id prefix from YOUR naming * scheme (e.g. "session:") to round-robin across. Unset = calendar day. */ coverage_group_prefix?: string; /** Filter by provenance sources (e.g. ["user", "assistant"]). */ sources?: string[]; /** * Which channel decides this query: 0 = keyword only, 1 = vector only. * Omit for the server default (0.5), which is exactly the blend that shipped * before this existed. Per query, because a sentence and an exact * module-name lookup want different answers from the same graph. */ semantic_weight?: number; /** Memories rendering: "markdown" (default) | "toon" | "json". */ format?: string; } /** One memory in a `format: "json"` response. */ export interface MemoryItem { locus_id: string; /** Every context this memory is enrolled in — how you tell a card from a body. */ context_ids: string[]; text: string; /** * How well this memory matched the query, 0 to 1. What ranking sorts on, and * a fact about the search rather than about the memory. */ match_score: number; /** How far the engine trusts this memory, 0 to 1. The same whoever asks. */ confidence: number; /** * How long the memory survives decay: `high`, `medium`, `low`, or * `permanent` once promotion has pinned it. Not the kind you wrote — that is * `event_kind`. */ value: string; /** The `event_kind` this memory was written with, when the payload kept one. */ event_kind: string | null; source: string | null; created: number; } /** * POST /v1/memories response. * * The shape follows `format`: markdown and toon render into `memories` and omit * `items`; json returns `items` and omits `memories` entirely. Both fields are * optional here because neither is present in every response — narrow on the * one your `format` asked for. */ export interface ContextResult { /** Present for format "markdown" (default) and "toon". */ memories?: string; /** Present for format "json". */ items?: MemoryItem[]; /** How many came back on this page, not how many matched. */ items_found: number; /** Where this page started. */ offset: number; /** * Whether a further page exists. Not a total: the score floor is applied * after ranking, so counting everything that would pass it means scoring the * whole graph. * * Exact while the match set fits the candidate pool. Past that a deeper page * searches a wider pool and a row can repeat or be skipped — enumeration * wants `listLocuses` or `locusesForContext`, which page over a stable order. */ has_more: boolean; } /** Context metadata */ export interface Context { context_id: string; context_type: string; context_name: string; created_at: number; updated_at: number; reference_count: number; } export interface ContextTypeSummary { context_type: string; count: number; } export interface ContextTypesResponse { context_types: ContextTypeSummary[]; total: number; page: number; page_size: number; } export interface ContextListResponse { contexts: Context[]; total: number; page: number; page_size: number; } export interface ContextSearchOptions { context_type?: string; min_count?: number; /** ZERO-indexed page number; the first page is 0. See {@link PaginationOptions.page}. */ page?: number; page_size?: number; /** Comma-separated extras to fold into the response. Currently "relationships". */ include?: string; /** How to render included relationships: "json" (default), "mindmap", or "toon". */ format?: string; } /** A relationship edge of a matched context (when include=relationships). */ export interface ContextLink { link_type: string; /** "outgoing" (this → other) or "incoming" (other → this). */ direction: string; context_id: string; } export interface ContextSearchResponse { contexts: Context[]; total: number; page: number; page_size: number; /** Present for include=relationships&format=json: links keyed by context_id. */ relationships?: Record; /** Present for format=mindmap or format=toon: relationships as one LLM-ready string. */ relationships_text?: string; } /** Params for getContext */ export interface GetContextParams { graph_id?: string; context_id: string; } /** Batch get context response */ export interface BatchGetContextResponse { contexts: GetContextResponse[]; not_found: string[]; } /** GET /v1/context/{graph_id}?context_id={id} response — latest locus payload and metadata */ export interface GetContextResponse { context_id: string; context: Context; locus_id: string; payload: Record; } /** Options for forgetContext */ export interface ForgetContextOptions { graph_id: string; context_type: string; context_name: string; } /** * DELETE /v1/contexts/{graph_id}/{context_type}/{context_name} response. * Deletes the context within a graph, cascading to its context links and any * locuses left with no other context. Response wrapped in ApiResponse * { success, data }; client unwraps to this. */ export interface ForgetContextResponse { deleted: boolean; context_id: string; /** Locuses deleted because this context was their only context link. */ deleted_locuses: number; /** Locuses kept but unlinked from this context. */ unlinked_locuses: number; /** Context-context links removed. */ context_links_removed: number; /** Whether the context row itself was removed (no other graph references it). */ context_removed: boolean; } /** Valid link types for context relationships */ export type ContextLinkType = "related_to" | "extends" | "reinforces" | "contradicts"; /** Direction filter for relationship queries */ export type RelationshipDirection = "outgoing" | "incoming" | "both"; /** Options for getContextRelationships */ export interface GetContextRelationshipsOptions { graph_id?: string; context_type: string; context_name: string; link_type?: ContextLinkType; direction?: RelationshipDirection; /** ZERO-indexed page number; the first page is 0. See {@link PaginationOptions.page}. */ page?: number; page_size?: number; } /** A single context relationship */ export interface ContextRelationship { context: Context; link_type: string; direction: string; } /** GET /v1/contexts/{graph_id}/{type}/{name}/relationships response */ export interface ContextRelationshipsResponse { relationships: ContextRelationship[]; total: number; page: number; page_size: number; } /** Options for getRelatedMemories convenience method */ export interface GetRelatedMemoriesOptions { graph_id?: string; /** Context type (e.g. "restaurant") */ context_type: string; /** Context name (e.g. "spice_kitchen_rest_001") */ context_name: string; /** Semantic search query over the related memories */ query: string; /** Filter by link type */ link_type?: ContextLinkType; /** Filter by direction */ direction?: RelationshipDirection; /** Include the source context's own memories (default: false) */ include_self?: boolean; /** Max memories to return */ limit?: number; /** How many levels to expand context hierarchy (default 1). Use 2 for grandchildren. */ expand_depth?: number; } /** Response from getRelatedMemories */ export interface GetRelatedMemoriesResponse { /** Formatted memories string from semantic search */ memories: string; /** Number of items found */ items_found: number; /** Context IDs that were searched */ context_ids: string[]; } /** Options for getContextDetails */ export interface GetContextDetailsOptions { graph_id?: string; context_type: string; context_name: string; } /** Locus counts and link stats for one context. */ export interface ContextStats { /** Total number of locuses linked to this context */ total_locuses: number; /** Count of locuses by kind */ by_kind: Record; /** Count of locuses by link type */ by_link_type: Record; outgoing_context_links_count: number; incoming_context_links_count: number; } /** GET /v1/contexts/{graph_id}/{type}/{name} response */ export interface ContextDetailsResponse { context: Context; stats: ContextStats; } /** A context-to-context edge. */ export interface ContextContextLink { from_context_id: string; to_context_id: string; link_type: string; created_at: number; } /** * An edge in a context graph response. * * Not {@link ContextContextLink}: the graph routes render edges as from/to with * no created_at, while ContextContextLink describes the stored row. */ export interface ContextGraphEdge { from: string; to: string; link_type: string; } /** Contexts as nodes, context-context links as edges. */ export interface ContextGraph { nodes: Context[]; edges: ContextGraphEdge[]; } /** Response from getContextGraph / getFullContextGraph */ export interface ContextGraphResponse { graph: ContextGraph; } /** Options for getContextGraph */ export interface GetContextGraphOptions { graph_id?: string; context_type: string; context_name: string; /** Traversal depth from the root context; server default 1, max 3. */ depth?: number; } /** Options for getFullContextGraph */ export interface GetFullContextGraphOptions { graph_id?: string; /** Only include contexts with at least this many locus references. */ min_refs?: number; /** Max contexts returned; server default 500, max 2000. */ limit?: number; } /** Options for linkContexts */ export interface LinkContextsOptions { graph_id?: string; /** Source context id (`type:name`). */ from_context_id: string; /** Target context id (`type:name`). */ to_context_id: string; link_type: ContextLinkType; } /** POST /v1/contexts/{graph_id}/link response */ export interface LinkContextsResponse { message: string; } /** Options for unlinkContexts */ export interface UnlinkContextsOptions { graph_id?: string; /** Source context id (`type:name`). */ from_context_id: string; /** Target context id (`type:name`). */ to_context_id: string; link_type: ContextLinkType; } /** DELETE /v1/contexts/{graph_id}/link response */ export interface UnlinkContextsResponse { from_context_id: string; to_context_id: string; link_type: ContextLinkType; /** False when the edge was already absent; the call still succeeds. */ removed: boolean; links_removed: number; } /** A locus-to-locus edge, as the detail route renders it. */ export interface LocusLink { from: string; to: string; link_type: string; /** True while `to` still names a context id rather than a locus id. */ unresolved: boolean; } /** GET /v1/locus/{graph_id}/{locus_id} response. */ export interface LocusDetailResponse { locus: { locus_id: string; /** Retention tier: `high`, `medium`, `low`, `permanent`. */ value: string; /** The stored envelope, as JSON text: {kind, source, data, context_id}. */ payload: string; source: string | null; created: number; }; links: { outgoing: LocusLink[]; incoming: LocusLink[]; }; /** The only surface exposing decay metadata; confidence matches search. */ metadata: { confidence: number | null; decay_days: number | null; last_accessed: number | null; }; /** Every context this locus is enrolled in. */ contexts: string[]; } /** DELETE /v1/locus/{graph_id}/{locus_id} response. */ export interface DeleteLocusResponse { locus_id: string; /** Edges removed with it, in either direction. */ affected_links: number; }