@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
62 lines (61 loc) • 3.23 kB
TypeScript
/**
* Artifact banking (N3) — bank the whole payload, hand back a pointer.
*
* A long-running agent produces outputs that do not fit in a conversation:
* a worker's full report, a build log, a stage's structured result. The wrong
* answer is to truncate one and send the head — the discarded bytes are gone
* and nothing records that they existed. The right answer is to write the
* payload to disk in full and put a bounded preview plus a read-back call in
* the conversation, so the model can pull as much of the rest as it needs,
* whenever it needs it, and compaction can evict the preview without costing
* anything.
*
* Read-back is the tool that already exists: `retrieve_context({ artifactId,
* offset, limit })` paginates any artifact and reports `totalSize` / `hasMore`.
* There is no second read tool and no second storage layer — this module is a
* thin, typed front door onto the instance's artifact store (local temp,
* Redis, or injected), the same store the MCP output normalizer externalizes
* into.
*
* The one thing it adds is that the store no longer has to pre-exist: it is
* created on first use, whether or not `mcp.outputLimits` was ever configured,
* and `retrieve_context` is registered along with it.
*
* @module artifacts/artifactBanking
*/
import type { NeuroLink } from "../neurolink.js";
import type { ArtifactPageRequest, ArtifactStore, BankArtifactOptions, BankedArtifactRef } from "../types/index.js";
/**
* The artifact store for this instance, created on first use.
*
* Lazy creation lives on the host rather than here because both pieces of it
* are private to `NeuroLink`: the store field the `retrieve_context` closure
* reads, and the registration of that tool. Calling it through the host is
* what makes a banked artifact readable by the model, not just by host code.
*/
export declare function ensureArtifactStore(host: NeuroLink): ArtifactStore;
/**
* Write a payload to the artifact store and return a reference to it.
*
* The payload is stored whole. The returned `preview` is a bounded head slice
* for the conversation, and `readBackHint` is the call that fetches the rest.
*
* @param host Instance whose artifact store (and `retrieve_context`) to use.
* @param payload The complete text or JSON payload. Never truncated.
* @param options What this is (`kind` / `label`) and how big a preview to cut.
*/
export declare function bankArtifact(host: NeuroLink, payload: string, options: BankArtifactOptions): Promise<BankedArtifactRef>;
/**
* Read a banked payload back from host code — the programmatic twin of the
* `retrieve_context` tool the model uses.
*
* Returns the FULL payload when `page` is omitted; there is no hidden cap,
* because a host that asks for the artifact is asking for the artifact.
* Returns null when the id is unknown or the file is gone.
*
* With a `page`, a backend that supports range reads moves only the window
* (see `readArtifactWindow`) — the same path `retrieve_context` takes.
*
* @param page Character window. `offset` defaults to 0, `limit` to the rest.
*/
export declare function readArtifact(host: NeuroLink, id: string, page?: ArtifactPageRequest): Promise<string | null>;