@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.41 kB
TypeScript
/**
* Codex-outbound fallback: request translation, Codex Responses -> ClaudeRequest.
*
* Named to mirror the existing asymmetry: `codexFallback.ts` is the Claude
* engine's fallback _into_ Codex; this file is the Codex engine's fallback
* _out_ to the Anthropic OAuth pool or Vertex-Claude. Owns one thing:
* untrusted inbound Codex Responses JSON -> a typed `ClaudeRequest`. Does not
* own target/model selection, response/stream translation back to Codex wire
* format, tool execution, or dispatch/HTTP.
*
* `parallel_tool_calls` feeds `tool_choice.disable_parallel_tool_use` in
* `mapCodexToolChoiceToClaude`, and tool declarations are flattened through
* `inlineJsonSchema` (dropping `strict` and degrading a circular `$ref` to a
* bare `{type:"object"}`) — the tool-call-fidelity PR's changes to this file.
* A `toolKindByName` map is also returned alongside the translated request,
* so response serialization (which sees only Claude's `name`+`input` on a
* `tool_use` block, no kind discriminator) knows which declared tools were
* `custom` rather than `function`.
*/
import type { ClaudeRequest, ClaudeTextBlock } from "../types/index.js";
import type { CodexNativeInputItem, CodexNativeRequest, CodexNativeToolKind, CodexOutboundFailureInput, CodexOutboundFallbackDecision, CodexTranslationError } from "../types/index.js";
export declare function parseCodexNativeRequest(raw: unknown): {
ok: true;
value: CodexNativeRequest;
} | {
ok: false;
error: CodexTranslationError;
};
export declare function buildSystemBlocksFromDeveloperMessages(items: readonly CodexNativeInputItem[]): ClaudeTextBlock[];
export declare function translateCodexRequestToClaude(request: CodexNativeRequest, target: {
provider: "anthropic" | "vertex";
model: string;
}): {
ok: true;
value: ClaudeRequest;
toolKindByName: ReadonlyMap<string, CodexNativeToolKind>;
} | {
ok: false;
error: CodexTranslationError;
};
/** Caps how many times one request may cross between engines (Codex->Anthropic
* or Anthropic->Codex) in a single turn. A crossing is an engine change, never
* a same-engine account rotation, so this bounds `Codex -> Anthropic ->
* Codex -> ...` cycles without limiting ordinary in-pool retries. */
export declare const MAX_ENGINE_CROSSINGS = 1;
/** Read a transport error code the same way `codexProxyRoutes.ts`'s own
* (unexported) `getCodexTransportErrorCode` does: a direct `.code`, falling
* back to `.cause.code`. Kept here, independently, as a pure utility the
* trigger-policy classifier can be exercised against without importing a
* route-handler module. */
export declare function parseCodexErrorCode(error: unknown): string | undefined;
/**
* Classify one `codexProxyRoutes.ts` `dispatch()` failure into an
* outbound-fallback eligibility decision. A total function over
* `CodexOutboundFailureClass` (exhaustive switch, no `default:`): a missing
* case fails to compile under `noImplicitReturns`, never falls through to a
* silent `undefined`.
*
* `context_preflight` / `token_budget` errors are never modeled here: both
* are self-contained terminal returns inside `dispatch()`'s own outer `try`,
* before any of the four insertion points this classifier serves, so they
* never reach it.
*/
export declare function classifyCodexOutboundFailure(input: CodexOutboundFailureInput): CodexOutboundFallbackDecision;