UNPKG

@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

65 lines (64 loc) • 3.44 kB
import type { ClaudeCacheBreakpointOptions, ClaudeRequest, VertexAnthropicCacheInput, VertexAnthropicCacheOutput, VertexAnthropicMessage } from "../types/index.js"; /** Anthropic allows at most four `cache_control` breakpoints per request. */ export declare const ANTHROPIC_MAX_CACHE_BREAKPOINTS = 4; /** * Annotate a native Vertex+Claude request with prompt-cache breakpoints. * * Budget allocation (max 4 markers): * 1. The stable prefix — the last system block when a system prompt is * present (this single marker caches `tools + system`, since system * renders after tools); otherwise the last tool definition. * 2-4. A rolling breakpoint on the last few messages, so the * growing-but-now-stable conversation history is cached and only the * newest turn is billed as fresh input. * * Pure: the inputs are cloned, never mutated. */ export declare function applyVertexAnthropicCacheBreakpoints(input: VertexAnthropicCacheInput): VertexAnthropicCacheOutput; /** * Count the `cache_control` markers already present on a request. The direct * Anthropic path arrives with markers the upstream layers placed — * MessageBuilder tags the system prompt, the client tags the last tool * definition, and message content blocks may carry their own. Anthropic * rejects requests with more than four markers, so any additional history * breakpoints must fit in the remaining budget. */ export declare function countAnthropicCacheMarkers(input: { system?: string | ReadonlyArray<{ cache_control?: unknown; }> | undefined; tools?: ReadonlyArray<{ cache_control?: unknown; }> | undefined; messages: ReadonlyArray<VertexAnthropicMessage>; }): number; /** * Rolling history breakpoints for request paths whose stable-prefix markers * are managed upstream (direct Anthropic: system via MessageBuilder, last * tool via the provider client). Marks the last content block of up to `budget` * tail messages; a tail block that already carries a marker is left as-is * without consuming budget (it already serves as that breakpoint). Pure — * the input array is cloned, never mutated. */ export declare function applyAnthropicHistoryCacheBreakpoints(input: ReadonlyArray<VertexAnthropicMessage>, budget: number): VertexAnthropicMessage[]; /** * Breakpoint placement for a Claude Messages request the proxy built itself, * rather than one a client authored. * * A request translated from another wire format arrives with no markers at * all, because the format it came from has no way to express one: OpenAI-shaped * callers rely on automatic prefix caching, which Anthropic does not do. A * faithful translation is therefore cached at 0% on every turn, and a caller * that fell back here from an exhausted pool burns the replacement quota faster * than the one it was spared. * * Placement follows Anthropic's `tools → system → messages` rendering: one * marker on the last system block covers tools *and* system in a single * breakpoint, and the rest roll along the tail of the history so a growing * conversation keeps its settled prefix cached. Markers the caller supplied are * counted first and never displaced — this only spends what is left of the * four. * * Pure: inputs are cloned, never mutated. */ export declare function applyClaudeRequestCacheBreakpoints(request: ClaudeRequest, options?: ClaudeCacheBreakpointOptions): ClaudeRequest;