import { ClientCore } from "./core"; import type { ApproveFindingOptions, BatchEventItem, BatchGetContextResponse, BatchResolveRequest, BatchResolveResponse, BatchStoreEventResponse, ContextDetailsResponse, ContextGraphResponse, ContextListResponse, ContextQuery, ContextRelationshipsResponse, ContextResult, ContextSearchOptions, ContextSearchResponse, ContextTypesResponse, CreateEventApiRequest, CreateGraphResponse, DeepRecallQuery, DeepRecallResult, DeleteLocusResponse, FindingActionResponse, FindingsResponse, ForgetContextOptions, ForgetContextResponse, GetContextDetailsOptions, GetContextGraphOptions, GetContextParams, GetContextRelationshipsOptions, GetContextResponse, GetFullContextGraphOptions, GetRelatedMemoriesOptions, GetRelatedMemoriesResponse, GetUnresolvedLinksResponse, GetUnresolvedOverviewResponse, GraphListResponse, LinkContextsOptions, LinkContextsResponse, LocusDetailResponse, ObserveRequest, ObserveResponse, PaginationOptions, ResolveRequest, ResolveResponse, StoreEventResponse, TransactionOperation, TransactionResponse, UnlinkContextsOptions, UnlinkContextsResponse } from "./types"; /** * LocusGraphClient — SDK for the LocusGraph memory API. * * Authenticates with an agent bearer secret and talks directly to a region * server. The transport/auth/helpers live in {@link ClientCore}; the endpoint * logic lives in `./methods/*`. This class is a thin, documented facade that * delegates to them, so the public API stays flat (`client.searchContexts(...)`). * * @example * ```ts * const client = new LocusGraphClient({ * serverUrl: 'https://api.locusgraph.com', * agentSecret: process.env.LOCUSGRAPH_AGENT_SECRET, * graphId: 'my-graph', * }); * await client.storeEvent({ graph_id: 'my-graph', event_kind: 'fact', payload: { data: 'hi' } }); * const { memories } = await client.retrieveMemories({ query: 'what did I store?' }); * ``` */ export declare class LocusGraphClient extends ClientCore { /** * Create a new graph (POST /v1/graphs). * * Requires an **unscoped** agent secret — a token scoped to a single graph * can't create graphs and the server rejects it with 403. * * @param name Human-readable graph name. * @param description Optional description. * @returns The new graph's `graph_id`, `owner_agent_id`, and `created_at`. * @example * ```ts * const g = await client.createGraph('research-notes', 'Papers and findings'); * ``` */ createGraph(name: string, description?: string): Promise; /** * List graphs the authenticated agent has access to (GET /v1/graphs). * * A graph-scoped secret only ever lists its one graph. * * @param options Pagination (`page`, `page_size`). */ listGraphs(options?: PaginationOptions): Promise; /** * Store a memory in LocusGraph (POST /v1/events). * * `payload` is arbitrary JSON. Stamp a `source` (provenance) — it sets the * memory's base confidence and decides who wins when memories conflict. Attach * relationship links (`extends` / `related_to` / `reinforces` / `contradicts`) * to connect it to other contexts. * * @param request The event: `graph_id`, `event_kind`, optional `source`, * `context_id`, link arrays, and the `payload`. * @returns The memory's id, what the write did to the context * (`created` | `replaced` | `unchanged` | `filtered`), and its confidence. * @example * ```ts * await client.storeEvent({ * graph_id: 'my-graph', * event_kind: 'fact', * source: 'user', * context_id: 'preference:dark_mode', * payload: { data: 'prefers dark mode' }, * }); * ``` */ storeEvent(request: CreateEventApiRequest): Promise; /** * Store many events in ONE request (POST /v1/events/batch). * * One round-trip and one permission check for the whole batch. Events are * processed **in order** (so `extends` parents can precede their children); a * per-item failure is reported in `results` and doesn't abort the batch. Max * 1000 events. * * @param items The events (each without `graph_id`). * @param graphId Graph to store into; falls back to the client's default. * @returns `{ stored, filtered, failed, results }` (results in request order). * @example * ```ts * await client.storeEventsBatch([ * { event_kind: 'fact', context_id: 'service:auth', payload: { data: 'Auth API' } }, * { event_kind: 'fact', context_id: 'endpoint:login', extends: ['service:auth'], payload: { data: '/login' } }, * ], 'my-graph'); * ``` */ storeEventsBatch(items: BatchEventItem[], graphId?: string): Promise; /** * Search memories by semantic similarity (POST /v1/memories). * * Beyond a plain `query`, supports advanced recall: `boostContextIds` * (additively widen around a known entity), `coverageContextIds` + * `coverageGroupPrefix` (spread results across a timeline), `contextIds` * (restrict), `sources` (provenance filter), and `format` (`markdown` | * `toon` | `json`). * * @param query The query and recall options; `graphId` falls back to the default. * @returns `{ memories, items_found }` — `memories` is the rendered string. * @example * ```ts * await client.retrieveMemories({ * query: 'recent activity', * boostContextIds: ['user:alice'], * sources: ['user', 'verified'], * limit: 10, * }); * ``` */ retrieveMemories(query: ContextQuery): Promise; /** * Agentic deep recall (POST /v1/memories/deep-recall). * * A walker agent explores the context graph (up to 3 hops, choosing * branches), then retrieves with aimed queries and returns a synthesized * answer plus cited evidence. Prefer this over `retrieveMemories` when the * question likely spans linked contexts (multi-hop, "what do we know about * X and what did we decide"). `coverage: 'partial'` means the walk was cut * short — consider one re-call passing the interesting `contexts` from the * facts as `contextIds`. * * @param query `question` (one focused thing), optional `contextIds` to * start the walk from; `graphId` falls back to the default. * @returns `{ summary, facts, contexts_walked, coverage, rounds_used, fallback, usage }`. * @example * ```ts * const { summary, facts } = await client.deepRecall({ * question: 'What did we decide about churn, and why?', * contextIds: ['session:retention_research'], * }); * ``` */ deepRecall(query: DeepRecallQuery): Promise; /** * Observe a raw moment into the awareness log (POST /v1/awareness/observe). * * Fire-and-forget by design: the server appends the payload verbatim and * replies 202 — a background judge later distills it into findings and * routes each one. In shadow mode nothing reaches the graph without a human * approval, so observe liberally and let the judge do the filtering. * `source: 'derived'` is rejected (the engine's own output never loops back * in). Payloads over 64 KB are rejected — whole documents belong to ingest. * * @param request `source`, `payload` (string or JSON object), optional * `stream` and `observedAt`; `graphId` falls back to the default. * @returns `{ observed, observation_id }`. * @example * ```ts * await client.observe({ * source: 'user', * payload: 'Parking spot is level 3, row F', * }); * ``` */ observe(request: ObserveRequest): Promise; /** * List ALL judged findings, newest first * (GET /v1/awareness/findings/{graph_id}): would_promote, pending, dropped, * resolved. This is the shadow measurement read — the response's `usage` * block carries the judge's summed LLM spend for the graph. */ awarenessFindings(graphId?: string): Promise; /** * List pending findings awaiting review, oldest first, each with a verbatim * observation excerpt (GET /v1/awareness/inbox/{graph_id}). */ awarenessInbox(graphId?: string): Promise; /** * Approve a pending finding into the graph * (POST /v1/awareness/inbox/{finding_id}/approve). * * The write goes through the normal admission path, stamped with the * ORIGINAL observation's source. Pass `statement` to edit before approving * (counted separately as `edited_promoted` by the shadow metrics). * * @returns `{ id, status }` — `promoted` or `edited_promoted`. */ approveFinding(findingId: string, options?: ApproveFindingOptions): Promise; /** * Reject a pending finding (POST /v1/awareness/inbox/{finding_id}/reject). * Closes the draft; the raw observation stays retained and searchable. */ rejectFinding(findingId: string): Promise; /** * List context types in a graph with their counts (GET /v1/contexts/{graph_id}). * @param graphId Graph; falls back to the default. @param options Pagination. */ listContextTypes(graphId?: string, options?: PaginationOptions): Promise; /** * List all contexts of a given type (GET /v1/contexts/{graph_id}?type=...). * @param contextType e.g. `'preference'`. @param graphId Graph. @param options Pagination. */ listContextsByType(contextType: string, graphId?: string, options?: PaginationOptions): Promise; /** * Search contexts by name (GET /v1/contexts/{graph_id}?q=...). * * Keyword/substring match on the context name. Pass * `options.include = 'relationships'` to fold in how matched contexts connect, * and `options.format` to choose the shape: `'json'` populates * `response.relationships` (a map), `'mindmap'` / `'toon'` populate * `response.relationships_text` (one LLM-ready string). * * @param query Search term. * @param graphId Graph; falls back to the default. * @param options `context_type`, `min_count`, pagination, `include`, `format`. * @example * ```ts * const res = await client.searchContexts('dark', undefined, { * include: 'relationships', format: 'mindmap', * }); * console.log(res.relationships_text); * ``` */ searchContexts(query: string, graphId?: string, options?: ContextSearchOptions): Promise; /** * Get a context by exact name across all types * (GET /v1/context/{graph_id}?context_name=...). * @throws if not found (404). */ getContextByName(contextName: string, graphId?: string): Promise; /** * Get a context's relationship edges * (GET /v1/contexts/{graph_id}/{type}/{name}/relationships). * * @param options `contextType`, `contextName`, and optional `linkType` * (`related_to` | `extends` | `reinforces` | `contradicts`) and `direction` * (`outgoing` | `incoming` | `both`). */ getContextRelationships(options: GetContextRelationshipsOptions): Promise; /** * Get memories from related contexts in one call: traverse the relationships, * collect the connected context ids, then semantic-search across them. * * @param options Traversal (`contextType`, `contextName`, `linkType`, * `direction`, `includeSelf`) plus the `query` to search the related memories. * @returns `{ memories, items_found, context_ids }`. * @example * ```ts * await client.getRelatedMemories({ * contextType: 'service', contextName: 'auth', * linkType: 'extends', direction: 'incoming', * query: 'error rates', * }); * ``` */ getRelatedMemories(options: GetRelatedMemoriesOptions): Promise; /** * Get a single context by `context_id`, with its latest locus payload * (GET /v1/context/{graph_id}?context_id=...). * @throws if not found in the graph (404). */ getContext(params: GetContextParams): Promise; /** * Get multiple contexts by id in one request (POST /v1/context/{graph_id}/batch). * @returns Found contexts plus a `not_found` list. */ batchGetContext(contextIds: string[], graphId?: string): Promise; /** * Get a context's metadata and stats by type and name * (GET /v1/contexts/{graph_id}/{type}/{name}): locus counts by kind and * link type, plus incoming/outgoing context-link counts. * @throws if the context doesn't exist in the graph (404). */ getContextDetails(options: GetContextDetailsOptions): Promise; /** * Get the relationship graph around one context * (GET /v1/contexts/{graph_id}/{type}/{name}/graph). Nodes are contexts, * edges are context-context links; `depth` bounds the traversal (1-3, * default 1). * @throws if the root context doesn't exist in the graph (404). */ getContextGraph(options: GetContextGraphOptions): Promise; /** * Get the whole graph's context network (GET /v1/contexts/{graph_id}/graph). * Filter with `min_refs` (drop rarely-referenced contexts) and `limit` * (default 500, max 2000) to keep the map legible. */ getFullContextGraph(options?: GetFullContextGraphOptions): Promise; /** * Link two contexts (POST /v1/contexts/{graph_id}/link). Both contexts must * already exist in the graph. Requires write permission. * * @param options `fromContextId` / `toContextId` (`type:name` ids) and * `linkType` (`related_to` | `extends` | `reinforces` | `contradicts`). */ linkContexts(options: LinkContextsOptions): Promise; /** * Remove one typed edge between two contexts * (DELETE /v1/contexts/{graph_id}/link). Links are additive on re-store, so * this is the only way to repair a wrong edge without deleting the context. * * @param options `fromContextId` / `toContextId` (`type:name` ids) and * `linkType` (`related_to` | `extends` | `reinforces` | `contradicts`). */ unlinkContexts(options: UnlinkContextsOptions): Promise; /** * Apply mixed store / delete / unlink operations as ONE transaction * (POST /v1/graphs/{graph_id}/transaction). All of it lands or none of it * does — use it where a multi-step edit must not half-apply, such as merging * two contexts. `storeEventsBatch` remains the bulk path. * * @param operations each `{op: 'store' | 'delete' | 'unlink', ...}`; `op` * defaults to `store`. Roughly a dozen events per call. */ transaction(operations: TransactionOperation[], graphId?: string): Promise; /** * Get one memory with its links, metadata and contexts * (GET /v1/locus/{graph_id}/{locus_id}). * * The only route exposing decay metadata, both link directions with their * unresolved flags, and the context enrolments — what an audit reads. */ getLocus(locusId: string, graphId?: string): Promise; /** * Delete one memory and every edge touching it * (DELETE /v1/locus/{graph_id}/{locus_id}). * * This is how a reinforces or contradicts edge comes back off its target. * `unlinkContexts` will not do it — that is the context-to-context graph. */ deleteLocus(locusId: string, graphId?: string): Promise; /** * Forget (delete) a context by type and name * (DELETE /v1/contexts/{graph_id}/{type}/{name}). * * Cascades: removes the context's links, unlinks its loci, and deletes any * locus left with no other context. Requires write permission. * * @returns A report of what was removed (`deleted_locuses`, `unlinked_locuses`, * `context_links_removed`, `context_removed`). */ forgetContext(options: ForgetContextOptions): Promise; /** * Resolve a `context_id` to a `locus_id` (POST /v1/resolve/{graph_id}), * reconciling links that referenced the context before it had a locus. */ resolve(request: ResolveRequest): Promise; /** Resolve many context→locus pairs in one request (POST /v1/resolve/{graph_id}/batch). */ batchResolve(request: BatchResolveRequest): Promise; /** * Graph-wide overview of unresolved links * (GET /v1/resolve/{graph_id}/unresolved) — how many, and for which contexts. */ getUnresolvedOverview(graphId?: string): Promise; /** The unresolved links pointing at one context (GET /v1/resolve/{graph_id}/unresolved/{context_id}). */ getUnresolvedLinks(contextId: string, graphId?: string): Promise; }