@juspay/neurolink 12.36.1 → 12.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -3
- package/dist/browser/neurolink.min.js +1 -1
- package/dist/proxy/argumentParsing.d.ts +12 -0
- package/dist/proxy/argumentParsing.js +23 -0
- package/dist/proxy/codexOutboundFallback.d.ts +10 -6
- package/dist/proxy/codexOutboundFallback.js +163 -43
- package/dist/proxy/codexResponsesFormat.d.ts +125 -0
- package/dist/proxy/codexResponsesFormat.js +591 -0
- package/dist/proxy/codexToAnthropicFallback.d.ts +54 -0
- package/dist/proxy/codexToAnthropicFallback.js +408 -0
- package/dist/proxy/proxyTracer.d.ts +21 -0
- package/dist/proxy/proxyTracer.js +45 -0
- package/dist/proxy/streamLimits.d.ts +16 -0
- package/dist/proxy/streamLimits.js +16 -0
- package/dist/types/codex.d.ts +113 -1
- package/dist/types/proxy.d.ts +12 -1
- package/docs-site/static/search-index.json +7 -7
- package/package.json +1 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire-format translation: Anthropic `ClaudeResponse` shape -> the Codex
|
|
3
|
+
* Responses shape a native Codex client expects.
|
|
4
|
+
*
|
|
5
|
+
* Pure wire-format only — no account selection, retry policy, or transport.
|
|
6
|
+
* Mirrors `claudeFormat.ts`'s role for the opposite direction: that module
|
|
7
|
+
* serializes NeuroLink's internal result into Claude SSE, this one serializes
|
|
8
|
+
* an already-Claude-shaped result into Codex SSE (or one JSON envelope).
|
|
9
|
+
*/
|
|
10
|
+
import type { ClaudeContentBlock, ClaudeResponse, ClaudeUsage, CodexNativeToolKind, CodexResponseEnvelope, CodexResponseItem, CodexResponseUsage } from "../types/index.js";
|
|
11
|
+
/** Same idiom as `generateToolUseId` (`claudeFormat.ts`), Codex's own prefix. */
|
|
12
|
+
export declare function generateCodexResponseId(): string;
|
|
13
|
+
/** Item ids are prefixed by kind so a client can tell message/tool items apart at a glance. */
|
|
14
|
+
export declare function generateCodexItemId(kind: "message" | "function_call" | "custom_tool_call"): string;
|
|
15
|
+
/**
|
|
16
|
+
* Reuse the Anthropic `tool_use.id` (`toolu_...`) verbatim as the Codex `call_id`.
|
|
17
|
+
* No id-mapping table exists anywhere in this codebase's translation modules, and
|
|
18
|
+
* nothing on the way in validates `call_id` format — see the design doc's §5 for
|
|
19
|
+
* the full reasoning and its one unresolved edge (a real, non-fallback Codex
|
|
20
|
+
* backend rejecting a non-`call_`-prefixed id on a later turn).
|
|
21
|
+
*/
|
|
22
|
+
export declare function codexCallIdFromToolUseId(toolUseId: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Absent cache fields are omitted rather than zeroed (never conflate "not
|
|
25
|
+
* observed" with "observed as zero" — the field's own doc comment on
|
|
26
|
+
* `CodexResponseUsage` states this contract).
|
|
27
|
+
*/
|
|
28
|
+
export declare function synthesizeCodexUsage(usage: ClaudeUsage): CodexResponseUsage;
|
|
29
|
+
/**
|
|
30
|
+
* Shared by the streaming serializer's non-failure item close and the
|
|
31
|
+
* non-streaming path (`serializeCodexResponse`), so item shape is defined
|
|
32
|
+
* once. Always produces a "completed" item — the streaming failure path
|
|
33
|
+
* (an item closed "incomplete" mid-turn) builds its item directly, since it
|
|
34
|
+
* must preserve the raw accumulated text/argument bytes rather than a value
|
|
35
|
+
* reconstructed through this function.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildCodexResponseItem(block: ClaudeContentBlock, itemId: string, toolKindByName?: ReadonlyMap<string, CodexNativeToolKind>): CodexResponseItem | null;
|
|
38
|
+
/** Non-streaming path: `§7` of the design — the document root IS a `CodexResponseEnvelope`. */
|
|
39
|
+
export declare function serializeCodexResponse(result: ClaudeResponse, requestModel: string, toolKindByName?: ReadonlyMap<string, CodexNativeToolKind>): CodexResponseEnvelope;
|
|
40
|
+
/**
|
|
41
|
+
* Push-based streaming serializer. A genuinely incremental tool-call-argument
|
|
42
|
+
* path (`openToolCall`/`pushToolCallArgsDelta`/`closeToolCall`) forwards each
|
|
43
|
+
* raw `input_json_delta` chunk as it arrives rather than buffering the whole
|
|
44
|
+
* call before emitting anything — `partial_json` is not individually valid
|
|
45
|
+
* JSON, so a serializer that validated per-chunk could not do this.
|
|
46
|
+
*/
|
|
47
|
+
export declare class CodexResponsesStreamSerializer {
|
|
48
|
+
private readonly model;
|
|
49
|
+
private readonly toolKindByName;
|
|
50
|
+
private state;
|
|
51
|
+
private readonly responseId;
|
|
52
|
+
private outputIndex;
|
|
53
|
+
private openKind;
|
|
54
|
+
private openItemId;
|
|
55
|
+
private textAccum;
|
|
56
|
+
private argsAccum;
|
|
57
|
+
private toolCallId;
|
|
58
|
+
private toolName;
|
|
59
|
+
private readonly closedItems;
|
|
60
|
+
private terminalEnvelope;
|
|
61
|
+
constructor(model: string, toolKindByName?: ReadonlyMap<string, CodexNativeToolKind>);
|
|
62
|
+
start(): Generator<string>;
|
|
63
|
+
pushDelta(text: string): Generator<string>;
|
|
64
|
+
/** Opens the tool-call item header at content_block_start, before any argument text
|
|
65
|
+
* is known — mirrors what content_block_start already gives us (id, name). A tool
|
|
66
|
+
* the request declared `custom` opens as a `custom_tool_call` item. */
|
|
67
|
+
openToolCall(toolUseId: string, name: string): Generator<string>;
|
|
68
|
+
/** Forwards one raw partial_json fragment as-is — no JSON.parse here, because a lone
|
|
69
|
+
* fragment is not required to be valid JSON on its own. A custom call's fragments
|
|
70
|
+
* are the `{"input":"..."}` wrapper, not client text, so they are only buffered;
|
|
71
|
+
* `closeToolCall` emits the unwrapped input once the whole wrapper is known. */
|
|
72
|
+
pushToolCallArgsDelta(rawChunk: string): Generator<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Public close for a tool-use block at `content_block_stop`. A no-op when no
|
|
75
|
+
* tool-call item is open, so a driver can call it unconditionally.
|
|
76
|
+
* Validates the accumulated arguments once, here — the one place validity
|
|
77
|
+
* is required. Throws on malformed JSON; the caller must catch and route to
|
|
78
|
+
* `emitFailure` (never swallowed, never retried after this point).
|
|
79
|
+
*/
|
|
80
|
+
closeToolCall(): Generator<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Public close for a text block at `content_block_stop`, mirroring
|
|
83
|
+
* `closeToolCall`'s role for the message item. A no-op when no message item
|
|
84
|
+
* is open, so a driver can call it unconditionally alongside `closeToolCall`
|
|
85
|
+
* without first inspecting which kind is currently open.
|
|
86
|
+
*/
|
|
87
|
+
closeTextBlock(): Generator<string>;
|
|
88
|
+
finish(stopReason: string | null, usage: ClaudeUsage): Generator<string, CodexResponseEnvelope>;
|
|
89
|
+
/**
|
|
90
|
+
* Post-commit terminal path. Closes any open item as "incomplete" — now
|
|
91
|
+
* representable via `CodexResponseItemStatus` — then emits a single
|
|
92
|
+
* `response.failed`. Idempotent: a second call after this one already ran
|
|
93
|
+
* returns the same envelope without emitting further frames, so a driver
|
|
94
|
+
* that reaches it defensively from more than one place never double-emits.
|
|
95
|
+
*/
|
|
96
|
+
emitFailure(_status: number, message: string, code?: string): Generator<string, CodexResponseEnvelope>;
|
|
97
|
+
private assertNotTerminal;
|
|
98
|
+
/**
|
|
99
|
+
* The custom-kind close: nothing was streamed live, so one input delta
|
|
100
|
+
* carries the whole unwrapped input, then its done event. Lenient where the
|
|
101
|
+
* function path throws: the wrapper is Claude's own output for the
|
|
102
|
+
* single-field schema `mapCodexCustomToolToClaude` declared, so a parse
|
|
103
|
+
* failure is an internal bug, and the raw accumulated text is emitted rather
|
|
104
|
+
* than failing the turn over it.
|
|
105
|
+
*/
|
|
106
|
+
private closeCustomToolCall;
|
|
107
|
+
private openMessage;
|
|
108
|
+
/** Closes whichever item is currently open, as "incomplete" when `failed`. */
|
|
109
|
+
private closeOpenItem;
|
|
110
|
+
/**
|
|
111
|
+
* The failure-close counterpart to `closeToolCall`. Arguments are carried
|
|
112
|
+
* verbatim from `argsAccum` and never re-validated — `JSON.parse` is not
|
|
113
|
+
* called on the failure path, and no `function_call_arguments.done` is
|
|
114
|
+
* emitted, since the arguments never reached a validated, complete state.
|
|
115
|
+
*/
|
|
116
|
+
private closeFailedFunctionCall;
|
|
117
|
+
/**
|
|
118
|
+
* The failure close for a custom call. Its accumulated bytes are Anthropic's
|
|
119
|
+
* JSON wrapper, not the client's grammar text, so `input` is the unwrapped
|
|
120
|
+
* string when the wrapper already parses and "" otherwise — an incomplete
|
|
121
|
+
* item is never executed. No input done event, as on the function path.
|
|
122
|
+
*/
|
|
123
|
+
private closeFailedCustomToolCall;
|
|
124
|
+
private closeMessageItem;
|
|
125
|
+
}
|