@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
54 lines (53 loc) • 2.69 kB
TypeScript
/**
* Agent request attachments, vetted at the HTTP boundary.
*
* `input.images` and `input.files` reach the SDK as strings, and the SDK
* resolves a string itself: an `http(s)` URL is fetched with redirects followed
* and no address check, and anything else is read from the local disk. Both
* are right for a program that names its own files. Neither is right when the
* string came from a caller of a network server, who could name
* `https://169.254.169.254/...`, a redirect to it, or `/etc/passwd`.
*
* So the route resolves every attachment itself and hands the SDK bytes:
* - `data:` URIs pass through, they carry their own content;
* - `https` URLs are downloaded with `safeDownload`: redirects are refused and
* the size is capped. The address is checked and the connection pinned to
* the checked addresses only for a direct download. Behind `HTTPS_PROXY` /
* `ALL_PROXY` the proxy resolves the host, so only the URL text is checked
* (IP literals, single-label and internal host names) and what a
* public-looking name resolves to is the proxy's egress policy;
* - local paths are read only from the operator's `allowedInputRoots`, after
* symlinks are resolved;
* - everything else is refused rather than guessed at, so this classifier
* can never disagree with the SDK's about what a string means.
*
* One request is also bounded as a whole: at most `maxInputAttachments`
* entries, each at most `maxInputBytes`, all together at most
* `maxInputTotalBytes`. The count and every `data:` URI are judged before
* anything is read; the rest are resolved one at a time, each allowed only what
* is left of the shared budget, so a transfer that would overflow it stops
* mid-stream.
*
* The SDK itself is untouched: a program calling `generate()` directly keeps
* reading the paths and URLs it names.
*
* @module server/utils/agentInput
*/
import type { ServerAgentResolvedInput, ServerAgentResolveOptions } from "../../types/index.js";
/** An attachment the server refuses, with the HTTP status that says why. */
export declare class AgentInputError extends Error {
readonly status: number;
readonly code: string;
constructor(message: string, status: number, code: string);
}
/**
* Replace every attachment of an agent request's `input` with vetted content.
*
* @throws {AgentInputError} for the first attachment that is refused, or for a
* request that carries too many attachments or too many bytes.
*/
export declare function resolveAgentInput(input: {
text: string;
images?: string[];
files?: string[];
}, options?: ServerAgentResolveOptions): Promise<ServerAgentResolvedInput>;