@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
55 lines (54 loc) • 3.18 kB
TypeScript
/**
* Drives the Anthropic -> Codex response/stream codec against a real upstream
* `Response`. Mirrors `codexFallback.ts`, inverted: named after its own
* upstream, an Anthropic-shape engine, by the same convention `codexFallback.ts`
* is named after Codex.
*
* Scope: translation and the pre-commit/post-commit boundary only. Engine
* selection, OAuth/account selection, retry/cooldown policy and analytics
* recording are owned by sibling modules and are not this module's concern —
* it does not touch `src/lib/server/routes/codexProxyRoutes.ts`.
*
* SSE parsing note: this direction reads Anthropic-shaped SSE bytes, the same
* wire shape `preflightAnthropicStream` already buffers before this module
* ever sees the stream. Rather than duplicating `codexFallback.ts`'s
* carry/searchFrom scanner (built for the differently-shaped native Codex
* event vocabulary), this module reuses `extractSSEEvents` — the incremental
* Anthropic-SSE parser `preflightAnthropicStream` itself is built on — so the
* preflight-buffered chunks and the live remainder are parsed by the exact
* same code path. The carry/searchFrom scanner extraction into a shared
* `sseFrameScanner.ts` remains an explicitly-deferred follow-up either way.
*/
import type { CodexNativeToolKind, CodexResponseEnvelope, CodexResponseStream } from "../types/index.js";
/** A non-2xx reply (either path) or a non-JSON reply (non-streaming path) from
* the Anthropic-shape upstream, raised before any Codex frame is sent. */
export declare class AnthropicFallbackResponseError extends Error {
readonly status: number;
readonly responseBody: string;
constructor(status: number, responseBody: string);
}
/** A pre-commit or post-commit failure while translating the Anthropic SSE
* stream, or a well-formed non-streaming reply this module refuses to
* translate (tool calls over `streamLimits.ts`'s count or size ceiling). */
export declare class AnthropicFallbackStreamError extends Error {
readonly status: number;
readonly code: string;
constructor(status: number, message: string, code: string);
}
/**
* Consume a fully-buffered, non-streaming Anthropic-shape response and
* translate it into one Codex Responses envelope.
*
* No `message_start`/`message_delta` split here: a single JSON object
* carries the whole turn's usage at once (confirmed against this repo's own
* `settleFromResponseUsage`, which reads a non-streaming Anthropic body the
* same way), so the translation delegates straight to `serializeCodexResponse`.
*/
export declare function consumeAnthropicFallbackResponse(response: Response, model: string, toolKindByName?: ReadonlyMap<string, CodexNativeToolKind>): Promise<CodexResponseEnvelope>;
/**
* Translate an Anthropic SSE stream into Codex-shape SSE frames as events
* arrive. The caller owns error framing downstream and must never retry
* after any frame has been emitted (mirrors `codexFallback.ts`'s own
* discipline, `:715-718`).
*/
export declare function createAnthropicFallbackStream(response: Response, model: string, toolKindByName?: ReadonlyMap<string, CodexNativeToolKind>): Promise<CodexResponseStream>;