@copilotkit/aimock 1.44.0 → 1.45.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +31 -0
- package/README.md +6 -0
- package/dist/agui-types.d.ts.map +1 -1
- package/dist/aimock-cli.cjs +31 -5
- package/dist/aimock-cli.cjs.map +1 -1
- package/dist/aimock-cli.d.cts.map +1 -1
- package/dist/aimock-cli.d.ts.map +1 -1
- package/dist/aimock-cli.js +31 -5
- package/dist/aimock-cli.js.map +1 -1
- package/dist/bedrock-converse.cjs +312 -39
- package/dist/bedrock-converse.cjs.map +1 -1
- package/dist/bedrock-converse.d.cts.map +1 -1
- package/dist/bedrock-converse.d.ts.map +1 -1
- package/dist/bedrock-converse.js +313 -40
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +195 -42
- package/dist/bedrock.cjs.map +1 -1
- package/dist/bedrock.d.cts.map +1 -1
- package/dist/bedrock.d.ts.map +1 -1
- package/dist/bedrock.js +196 -43
- package/dist/bedrock.js.map +1 -1
- package/dist/chaos.cjs +1 -0
- package/dist/chaos.js +1 -1
- package/dist/cli.cjs +152 -5
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +155 -8
- package/dist/cli.js.map +1 -1
- package/dist/cohere.cjs +132 -71
- package/dist/cohere.cjs.map +1 -1
- package/dist/cohere.d.cts.map +1 -1
- package/dist/cohere.d.ts.map +1 -1
- package/dist/cohere.js +133 -72
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.cjs +62 -4
- package/dist/config-loader.cjs.map +1 -1
- package/dist/config-loader.d.cts +37 -4
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/config-loader.d.ts +37 -4
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/config-loader.js +62 -4
- package/dist/config-loader.js.map +1 -1
- package/dist/fakes-plugin.cjs +131 -0
- package/dist/fakes-plugin.cjs.map +1 -0
- package/dist/fakes-plugin.d.cts +23 -0
- package/dist/fakes-plugin.d.cts.map +1 -0
- package/dist/fakes-plugin.d.ts +23 -0
- package/dist/fakes-plugin.d.ts.map +1 -0
- package/dist/fakes-plugin.js +127 -0
- package/dist/fakes-plugin.js.map +1 -0
- package/dist/fixture-loader-services.cjs +1 -1
- package/dist/fixture-loader-services.cjs.map +1 -1
- package/dist/fixture-loader-services.js +1 -1
- package/dist/fixture-loader-services.js.map +1 -1
- package/dist/fixture-loader.cjs +389 -27
- package/dist/fixture-loader.cjs.map +1 -1
- package/dist/fixture-loader.d.cts +47 -3
- package/dist/fixture-loader.d.cts.map +1 -1
- package/dist/fixture-loader.d.ts +47 -3
- package/dist/fixture-loader.d.ts.map +1 -1
- package/dist/fixture-loader.js +384 -29
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini-interactions.cjs +250 -52
- package/dist/gemini-interactions.cjs.map +1 -1
- package/dist/gemini-interactions.d.cts.map +1 -1
- package/dist/gemini-interactions.d.ts.map +1 -1
- package/dist/gemini-interactions.js +251 -53
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +226 -37
- package/dist/gemini.cjs.map +1 -1
- package/dist/gemini.d.cts.map +1 -1
- package/dist/gemini.d.ts.map +1 -1
- package/dist/gemini.js +227 -38
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +881 -7
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +85 -4
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +85 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +839 -8
- package/dist/helpers.js.map +1 -1
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +4 -3
- package/dist/jest.cjs +31 -7
- package/dist/jest.cjs.map +1 -1
- package/dist/jest.d.cts +43 -3
- package/dist/jest.d.cts.map +1 -1
- package/dist/jest.d.ts +43 -3
- package/dist/jest.d.ts.map +1 -1
- package/dist/jest.js +33 -9
- package/dist/jest.js.map +1 -1
- package/dist/journal.cjs +135 -13
- package/dist/journal.cjs.map +1 -1
- package/dist/journal.d.cts +38 -4
- package/dist/journal.d.cts.map +1 -1
- package/dist/journal.d.ts +38 -4
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +135 -13
- package/dist/journal.js.map +1 -1
- package/dist/live-sanitize.cjs +4 -32
- package/dist/live-sanitize.cjs.map +1 -1
- package/dist/live-sanitize.js +4 -32
- package/dist/live-sanitize.js.map +1 -1
- package/dist/llmock.cjs +123 -30
- package/dist/llmock.cjs.map +1 -1
- package/dist/llmock.d.cts +16 -1
- package/dist/llmock.d.cts.map +1 -1
- package/dist/llmock.d.ts +16 -1
- package/dist/llmock.d.ts.map +1 -1
- package/dist/llmock.js +125 -32
- package/dist/llmock.js.map +1 -1
- package/dist/mcp-fakes-mount.cjs +1 -0
- package/dist/mcp-fakes-mount.cjs.map +1 -1
- package/dist/mcp-fakes-mount.js +1 -0
- package/dist/mcp-fakes-mount.js.map +1 -1
- package/dist/mcp-fakes-report.cjs +111 -0
- package/dist/mcp-fakes-report.cjs.map +1 -0
- package/dist/mcp-fakes-report.d.cts +40 -0
- package/dist/mcp-fakes-report.d.cts.map +1 -0
- package/dist/mcp-fakes-report.d.ts +40 -0
- package/dist/mcp-fakes-report.d.ts.map +1 -0
- package/dist/mcp-fakes-report.js +107 -0
- package/dist/mcp-fakes-report.js.map +1 -0
- package/dist/mcp-fakes.cjs +331 -8
- package/dist/mcp-fakes.cjs.map +1 -1
- package/dist/mcp-fakes.d.cts +406 -3
- package/dist/mcp-fakes.d.cts.map +1 -1
- package/dist/mcp-fakes.d.ts +406 -3
- package/dist/mcp-fakes.d.ts.map +1 -1
- package/dist/mcp-fakes.js +331 -8
- package/dist/mcp-fakes.js.map +1 -1
- package/dist/mcp-handler.cjs +209 -16
- package/dist/mcp-handler.cjs.map +1 -1
- package/dist/mcp-handler.d.cts +49 -0
- package/dist/mcp-handler.d.cts.map +1 -0
- package/dist/mcp-handler.d.ts +49 -0
- package/dist/mcp-handler.d.ts.map +1 -0
- package/dist/mcp-handler.js +207 -17
- package/dist/mcp-handler.js.map +1 -1
- package/dist/mcp-mock.cjs +112 -1
- package/dist/mcp-mock.cjs.map +1 -1
- package/dist/mcp-mock.d.cts +33 -2
- package/dist/mcp-mock.d.cts.map +1 -1
- package/dist/mcp-mock.d.ts +33 -2
- package/dist/mcp-mock.d.ts.map +1 -1
- package/dist/mcp-mock.js +112 -1
- package/dist/mcp-mock.js.map +1 -1
- package/dist/mcp-recorder.cjs +1224 -0
- package/dist/mcp-recorder.cjs.map +1 -0
- package/dist/mcp-recorder.d.cts +108 -0
- package/dist/mcp-recorder.d.cts.map +1 -0
- package/dist/mcp-recorder.d.ts +108 -0
- package/dist/mcp-recorder.d.ts.map +1 -0
- package/dist/mcp-recorder.js +1215 -0
- package/dist/mcp-recorder.js.map +1 -0
- package/dist/messages.cjs +362 -56
- package/dist/messages.cjs.map +1 -1
- package/dist/messages.d.cts.map +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +363 -58
- package/dist/messages.js.map +1 -1
- package/dist/misbehavior.cjs +1523 -0
- package/dist/misbehavior.cjs.map +1 -0
- package/dist/misbehavior.d.cts +43 -0
- package/dist/misbehavior.d.cts.map +1 -0
- package/dist/misbehavior.d.ts +43 -0
- package/dist/misbehavior.d.ts.map +1 -0
- package/dist/misbehavior.js +1511 -0
- package/dist/misbehavior.js.map +1 -0
- package/dist/ollama.cjs +310 -112
- package/dist/ollama.cjs.map +1 -1
- package/dist/ollama.d.cts.map +1 -1
- package/dist/ollama.d.ts.map +1 -1
- package/dist/ollama.js +311 -113
- package/dist/ollama.js.map +1 -1
- package/dist/record-sanitize.cjs +231 -0
- package/dist/record-sanitize.cjs.map +1 -0
- package/dist/record-sanitize.js +224 -0
- package/dist/record-sanitize.js.map +1 -0
- package/dist/recorder.cjs +106 -5
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.d.cts +2 -1
- package/dist/recorder.d.cts.map +1 -1
- package/dist/recorder.d.ts +2 -1
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +107 -7
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +667 -171
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts +5 -13
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts +5 -13
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +665 -174
- package/dist/responses.js.map +1 -1
- package/dist/router.cjs +24 -2
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts.map +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +25 -4
- package/dist/router.js.map +1 -1
- package/dist/server.cjs +572 -76
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +574 -78
- package/dist/server.js.map +1 -1
- package/dist/stream-collapse.cjs +236 -34
- package/dist/stream-collapse.cjs.map +1 -1
- package/dist/stream-collapse.d.cts +39 -4
- package/dist/stream-collapse.d.cts.map +1 -1
- package/dist/stream-collapse.d.ts +39 -4
- package/dist/stream-collapse.d.ts.map +1 -1
- package/dist/stream-collapse.js +235 -35
- package/dist/stream-collapse.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +315 -4
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +315 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/validate-cli.cjs +36 -4
- package/dist/validate-cli.cjs.map +1 -1
- package/dist/validate-cli.js +37 -5
- package/dist/validate-cli.js.map +1 -1
- package/dist/vector-types.d.ts.map +1 -1
- package/dist/version.cjs +45 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +44 -0
- package/dist/version.js.map +1 -0
- package/dist/vitest.cjs +66 -10
- package/dist/vitest.cjs.map +1 -1
- package/dist/vitest.d.cts +35 -4
- package/dist/vitest.d.cts.map +1 -1
- package/dist/vitest.d.ts +35 -4
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +67 -11
- package/dist/vitest.js.map +1 -1
- package/dist/watcher.cjs +6 -2
- package/dist/watcher.cjs.map +1 -1
- package/dist/watcher.js +6 -2
- package/dist/watcher.js.map +1 -1
- package/dist/ws-gemini-live.cjs +210 -101
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.d.cts +9 -3
- package/dist/ws-gemini-live.d.cts.map +1 -1
- package/dist/ws-gemini-live.d.ts +9 -3
- package/dist/ws-gemini-live.d.ts.map +1 -1
- package/dist/ws-gemini-live.js +211 -102
- package/dist/ws-gemini-live.js.map +1 -1
- package/dist/ws-realtime.cjs +175 -62
- package/dist/ws-realtime.cjs.map +1 -1
- package/dist/ws-realtime.d.cts +8 -3
- package/dist/ws-realtime.d.cts.map +1 -1
- package/dist/ws-realtime.d.ts +8 -3
- package/dist/ws-realtime.d.ts.map +1 -1
- package/dist/ws-realtime.js +176 -63
- package/dist/ws-realtime.js.map +1 -1
- package/dist/ws-responses.cjs +109 -16
- package/dist/ws-responses.cjs.map +1 -1
- package/dist/ws-responses.d.cts +8 -12
- package/dist/ws-responses.d.cts.map +1 -1
- package/dist/ws-responses.d.ts +8 -12
- package/dist/ws-responses.d.ts.map +1 -1
- package/dist/ws-responses.js +111 -18
- package/dist/ws-responses.js.map +1 -1
- package/package.json +10 -2
- package/skills/write-fixtures/SKILL.md +179 -21
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger } from "./logger.cjs";
|
|
2
|
-
import { FixtureBlock, RecordProviderKey, ToolCall } from "./types.cjs";
|
|
2
|
+
import { CustomToolCall, FixtureBlock, RecordProviderKey, ResponsesFixtureBlock, ToolCall } from "./types.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/stream-collapse.d.ts
|
|
5
5
|
|
|
@@ -71,7 +71,17 @@ interface CollapseResult {
|
|
|
71
71
|
* `response.usage` override shape before persisting.
|
|
72
72
|
*/
|
|
73
73
|
usage?: Record<string, unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Function calls. An OpenAI Responses `function_call` item's `namespace` is
|
|
76
|
+
* kept on its entry (internal {@link collapseOpenAISSEWithResponsesTools} only).
|
|
77
|
+
*/
|
|
74
78
|
toolCalls?: ToolCall[];
|
|
79
|
+
/**
|
|
80
|
+
* OpenAI Responses custom tool calls (`custom_tool_call` items), in output
|
|
81
|
+
* order (internal {@link collapseOpenAISSEWithResponsesTools} only). They are never part of `toolCalls`
|
|
82
|
+
* or `blocks`.
|
|
83
|
+
*/
|
|
84
|
+
customToolCalls?: CustomToolCall[];
|
|
75
85
|
droppedChunks?: number;
|
|
76
86
|
firstDroppedSample?: string;
|
|
77
87
|
truncated?: boolean;
|
|
@@ -100,10 +110,21 @@ interface CollapseResult {
|
|
|
100
110
|
* keeps the legacy `{ content, toolCalls }` shape byte-identical.
|
|
101
111
|
*
|
|
102
112
|
* Each text block coalesces all contiguous content deltas between tool
|
|
103
|
-
* atoms
|
|
104
|
-
*
|
|
113
|
+
* atoms. Each tool block sits in the position where its FIRST delta arrived:
|
|
114
|
+
* a function call becomes a `toolCall` block with the fully-assembled
|
|
115
|
+
* name/arguments/id, and an OpenAI Responses custom call becomes a
|
|
116
|
+
* `customToolCall` block with name/input/id, where `input` is kept verbatim.
|
|
117
|
+
* Custom calls are left out of `blocks` (which, like `toolCalls`, describes
|
|
118
|
+
* function calls and text only); see {@link CollapseResult.responsesBlocks}.
|
|
105
119
|
*/
|
|
106
120
|
blocks?: FixtureBlock[];
|
|
121
|
+
/**
|
|
122
|
+
* OpenAI Responses only: the full ordered output (text, function calls and
|
|
123
|
+
* custom calls) when the stream carried a custom call whose position the
|
|
124
|
+
* `content` + `toolCalls` + `customToolCalls` shape cannot express (it is
|
|
125
|
+
* interleaved with text, or comes before a function call).
|
|
126
|
+
*/
|
|
127
|
+
responsesBlocks?: ResponsesFixtureBlock[];
|
|
107
128
|
}
|
|
108
129
|
/**
|
|
109
130
|
* The opaque `data` of a non-empty Anthropic `redacted_thinking` block, or
|
|
@@ -121,8 +142,16 @@ interface CollapseResult {
|
|
|
121
142
|
* Format:
|
|
122
143
|
* data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"Hello"}}]}\n\n
|
|
123
144
|
* data: [DONE]\n\n
|
|
145
|
+
*
|
|
146
|
+
* Public, with the 1.44.0 result: an OpenAI Responses `namespace` and custom
|
|
147
|
+
* tool calls are dropped. The recorder uses {@link collapseOpenAISSEWithResponsesTools}.
|
|
124
148
|
*/
|
|
125
149
|
declare function collapseOpenAISSE(rawBody: string): CollapseResult;
|
|
150
|
+
/**
|
|
151
|
+
* A collapse result as 1.44.0 returned and recorded it: no `namespace` on a
|
|
152
|
+
* function call or `toolCall` block, and no custom tool calls.
|
|
153
|
+
*/
|
|
154
|
+
|
|
126
155
|
/**
|
|
127
156
|
* Collapse Anthropic Claude Messages SSE stream into a single response.
|
|
128
157
|
*
|
|
@@ -186,9 +215,15 @@ declare function collapseGeminiInteractionsSSE(rawBody: string): CollapseResult;
|
|
|
186
215
|
* Collapse a streaming response body into a non-streaming fixture response.
|
|
187
216
|
* Returns null if the content type is not a known streaming format.
|
|
188
217
|
* Falls back to OpenAI SSE parsing for unrecognized provider keys with text/event-stream.
|
|
218
|
+
*
|
|
219
|
+
* Public, with the 1.44.0 result (see {@link collapseOpenAISSE}). The recorder
|
|
220
|
+
* uses {@link collapseStreamingResponseWithResponsesTools}.
|
|
189
221
|
*/
|
|
190
222
|
declare function collapseStreamingResponse(contentType: string, providerKey: RecordProviderKey, body: string | Buffer, logger?: Logger): CollapseResult | null;
|
|
191
|
-
|
|
223
|
+
/**
|
|
224
|
+
* @internal {@link collapseStreamingResponse} keeping an OpenAI Responses
|
|
225
|
+
* `namespace` and custom tool calls.
|
|
226
|
+
*/
|
|
192
227
|
//#endregion
|
|
193
228
|
export { CollapseResult, MAX_COLLAPSE_STRING_LENGTH, collapseAnthropicSSE, collapseBedrockEventStream, collapseCohereSSE, collapseGeminiInteractionsSSE, collapseGeminiSSE, collapseOllamaNDJSON, collapseOpenAISSE, collapseStreamingResponse, setCollapseStringLimitForTests };
|
|
194
229
|
//# sourceMappingURL=stream-collapse.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-collapse.d.cts","names":[],"sources":["../src/stream-collapse.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream-collapse.d.cts","names":[],"sources":["../src/stream-collapse.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AA+eA;AAsjBA;AAkMA;AAyJA;AAmIA;AA6RA;;;;;AAyTA;AA2LA;;;AAGiB,cA3uEJ,0BA2uEI,EAAA,MAAA;;AAEd,iBAluEa,8BAAA,CAkuEb,KAAA,EAAA,MAAA,GAAA,SAAA,CAAA,EAAA,IAAA;AAAc,UAlrEA,cAAA,CAkrEA;;;;gBA9qED;;;YACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAqCF;;;;;cAKI;;;;;;oBAMM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAoCT;;;;;;;oBAOS;;;;;;;;;;;;;;;;;;;;;;iBAwSJ,iBAAA,mBAAoC;;;;;;;;;;;;;iBAsjBpC,oBAAA,mBAAuC;;;;;;;iBAkMvC,iBAAA,mBAAoC;;;;;;;;;;;;;;;iBAyJpC,oBAAA,mBAAuC;;;;;;;iBAmIvC,iBAAA,mBAAoC;;;;;;;iBA6RpC,0BAAA,UAAoC,SAAS;;;;;;;;;;;;;;;iBAyT7C,6BAAA,mBAAgD;;;;;;;;;iBA2LhD,yBAAA,mCAED,kCACE,iBACN,SACR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger } from "./logger.js";
|
|
2
|
-
import { FixtureBlock, RecordProviderKey, ToolCall } from "./types.js";
|
|
2
|
+
import { CustomToolCall, FixtureBlock, RecordProviderKey, ResponsesFixtureBlock, ToolCall } from "./types.js";
|
|
3
3
|
|
|
4
4
|
//#region src/stream-collapse.d.ts
|
|
5
5
|
|
|
@@ -71,7 +71,17 @@ interface CollapseResult {
|
|
|
71
71
|
* `response.usage` override shape before persisting.
|
|
72
72
|
*/
|
|
73
73
|
usage?: Record<string, unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Function calls. An OpenAI Responses `function_call` item's `namespace` is
|
|
76
|
+
* kept on its entry (internal {@link collapseOpenAISSEWithResponsesTools} only).
|
|
77
|
+
*/
|
|
74
78
|
toolCalls?: ToolCall[];
|
|
79
|
+
/**
|
|
80
|
+
* OpenAI Responses custom tool calls (`custom_tool_call` items), in output
|
|
81
|
+
* order (internal {@link collapseOpenAISSEWithResponsesTools} only). They are never part of `toolCalls`
|
|
82
|
+
* or `blocks`.
|
|
83
|
+
*/
|
|
84
|
+
customToolCalls?: CustomToolCall[];
|
|
75
85
|
droppedChunks?: number;
|
|
76
86
|
firstDroppedSample?: string;
|
|
77
87
|
truncated?: boolean;
|
|
@@ -100,10 +110,21 @@ interface CollapseResult {
|
|
|
100
110
|
* keeps the legacy `{ content, toolCalls }` shape byte-identical.
|
|
101
111
|
*
|
|
102
112
|
* Each text block coalesces all contiguous content deltas between tool
|
|
103
|
-
* atoms
|
|
104
|
-
*
|
|
113
|
+
* atoms. Each tool block sits in the position where its FIRST delta arrived:
|
|
114
|
+
* a function call becomes a `toolCall` block with the fully-assembled
|
|
115
|
+
* name/arguments/id, and an OpenAI Responses custom call becomes a
|
|
116
|
+
* `customToolCall` block with name/input/id, where `input` is kept verbatim.
|
|
117
|
+
* Custom calls are left out of `blocks` (which, like `toolCalls`, describes
|
|
118
|
+
* function calls and text only); see {@link CollapseResult.responsesBlocks}.
|
|
105
119
|
*/
|
|
106
120
|
blocks?: FixtureBlock[];
|
|
121
|
+
/**
|
|
122
|
+
* OpenAI Responses only: the full ordered output (text, function calls and
|
|
123
|
+
* custom calls) when the stream carried a custom call whose position the
|
|
124
|
+
* `content` + `toolCalls` + `customToolCalls` shape cannot express (it is
|
|
125
|
+
* interleaved with text, or comes before a function call).
|
|
126
|
+
*/
|
|
127
|
+
responsesBlocks?: ResponsesFixtureBlock[];
|
|
107
128
|
}
|
|
108
129
|
/**
|
|
109
130
|
* The opaque `data` of a non-empty Anthropic `redacted_thinking` block, or
|
|
@@ -121,8 +142,16 @@ interface CollapseResult {
|
|
|
121
142
|
* Format:
|
|
122
143
|
* data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"Hello"}}]}\n\n
|
|
123
144
|
* data: [DONE]\n\n
|
|
145
|
+
*
|
|
146
|
+
* Public, with the 1.44.0 result: an OpenAI Responses `namespace` and custom
|
|
147
|
+
* tool calls are dropped. The recorder uses {@link collapseOpenAISSEWithResponsesTools}.
|
|
124
148
|
*/
|
|
125
149
|
declare function collapseOpenAISSE(rawBody: string): CollapseResult;
|
|
150
|
+
/**
|
|
151
|
+
* A collapse result as 1.44.0 returned and recorded it: no `namespace` on a
|
|
152
|
+
* function call or `toolCall` block, and no custom tool calls.
|
|
153
|
+
*/
|
|
154
|
+
|
|
126
155
|
/**
|
|
127
156
|
* Collapse Anthropic Claude Messages SSE stream into a single response.
|
|
128
157
|
*
|
|
@@ -186,9 +215,15 @@ declare function collapseGeminiInteractionsSSE(rawBody: string): CollapseResult;
|
|
|
186
215
|
* Collapse a streaming response body into a non-streaming fixture response.
|
|
187
216
|
* Returns null if the content type is not a known streaming format.
|
|
188
217
|
* Falls back to OpenAI SSE parsing for unrecognized provider keys with text/event-stream.
|
|
218
|
+
*
|
|
219
|
+
* Public, with the 1.44.0 result (see {@link collapseOpenAISSE}). The recorder
|
|
220
|
+
* uses {@link collapseStreamingResponseWithResponsesTools}.
|
|
189
221
|
*/
|
|
190
222
|
declare function collapseStreamingResponse(contentType: string, providerKey: RecordProviderKey, body: string | Buffer, logger?: Logger): CollapseResult | null;
|
|
191
|
-
|
|
223
|
+
/**
|
|
224
|
+
* @internal {@link collapseStreamingResponse} keeping an OpenAI Responses
|
|
225
|
+
* `namespace` and custom tool calls.
|
|
226
|
+
*/
|
|
192
227
|
//#endregion
|
|
193
228
|
export { CollapseResult, MAX_COLLAPSE_STRING_LENGTH, collapseAnthropicSSE, collapseBedrockEventStream, collapseCohereSSE, collapseGeminiInteractionsSSE, collapseGeminiSSE, collapseOllamaNDJSON, collapseOpenAISSE, collapseStreamingResponse, setCollapseStringLimitForTests };
|
|
194
229
|
//# sourceMappingURL=stream-collapse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-collapse.d.ts","names":[],"sources":["../src/stream-collapse.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream-collapse.d.ts","names":[],"sources":["../src/stream-collapse.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AA+eA;AAsjBA;AAkMA;AAyJA;AAmIA;AA6RA;;;;;AAyTA;AA2LA;;;AAGiB,cA3uEJ,0BA2uEI,EAAA,MAAA;;AAEd,iBAluEa,8BAAA,CAkuEb,KAAA,EAAA,MAAA,GAAA,SAAA,CAAA,EAAA,IAAA;AAAc,UAlrEA,cAAA,CAkrEA;;;;gBA9qED;;;YACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAqCF;;;;;cAKI;;;;;;oBAMM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAoCT;;;;;;;oBAOS;;;;;;;;;;;;;;;;;;;;;;iBAwSJ,iBAAA,mBAAoC;;;;;;;;;;;;;iBAsjBpC,oBAAA,mBAAuC;;;;;;;iBAkMvC,iBAAA,mBAAoC;;;;;;;;;;;;;;;iBAyJpC,oBAAA,mBAAuC;;;;;;;iBAmIvC,iBAAA,mBAAoC;;;;;;;iBA6RpC,0BAAA,UAAoC,SAAS;;;;;;;;;;;;;;;iBAyT7C,6BAAA,mBAAgD;;;;;;;;;iBA2LhD,yBAAA,mCAED,kCACE,iBACN,SACR"}
|
package/dist/stream-collapse.js
CHANGED
|
@@ -79,6 +79,10 @@ function guardCollapseBody(body) {
|
|
|
79
79
|
function isCollapseInputTruncated(body) {
|
|
80
80
|
return body.length > effectiveCollapseStringLimit();
|
|
81
81
|
}
|
|
82
|
+
/** A Responses `namespace` field when it is a non-empty string, else undefined. */
|
|
83
|
+
function responsesNamespace(item) {
|
|
84
|
+
return typeof item.namespace === "string" && item.namespace !== "" ? item.namespace : void 0;
|
|
85
|
+
}
|
|
82
86
|
/**
|
|
83
87
|
* Normalize a tool call's accumulated `arguments` into valid JSON exactly like
|
|
84
88
|
* the flat-`toolCalls` recorder path: an empty / whitespace-only / missing
|
|
@@ -100,7 +104,40 @@ function toToolCallBlock(ref) {
|
|
|
100
104
|
type: "toolCall",
|
|
101
105
|
name: ref.name,
|
|
102
106
|
arguments: normalizeToolArguments(ref.arguments),
|
|
103
|
-
...ref.id ? { id: ref.id } : {}
|
|
107
|
+
...ref.id ? { id: ref.id } : {},
|
|
108
|
+
...ref.namespace ? { namespace: ref.namespace } : {}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Build a `customToolCall` block from a custom-call accumulator. The `input` is
|
|
113
|
+
* free text: it is kept as is, never normalized to `"{}"`.
|
|
114
|
+
*/
|
|
115
|
+
function toCustomToolCallBlock(ref) {
|
|
116
|
+
return {
|
|
117
|
+
type: "customToolCall",
|
|
118
|
+
name: ref.name,
|
|
119
|
+
input: ref.input,
|
|
120
|
+
...ref.id ? { id: ref.id } : {},
|
|
121
|
+
...ref.namespace ? { namespace: ref.namespace } : {}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** Project a function-call accumulator to a flat fixture tool call. */
|
|
125
|
+
function toFunctionToolCall(ref) {
|
|
126
|
+
return {
|
|
127
|
+
name: ref.name,
|
|
128
|
+
arguments: normalizeToolArguments(ref.arguments),
|
|
129
|
+
...ref.id ? { id: ref.id } : {},
|
|
130
|
+
...ref.namespace ? { namespace: ref.namespace } : {}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** Project a custom-call accumulator to a flat fixture custom tool call. */
|
|
134
|
+
function toCustomToolCall(ref) {
|
|
135
|
+
return {
|
|
136
|
+
type: "custom",
|
|
137
|
+
name: ref.name,
|
|
138
|
+
input: ref.input,
|
|
139
|
+
...ref.id ? { id: ref.id } : {},
|
|
140
|
+
...ref.namespace ? { namespace: ref.namespace } : {}
|
|
104
141
|
};
|
|
105
142
|
}
|
|
106
143
|
/**
|
|
@@ -110,19 +147,31 @@ function toToolCallBlock(ref) {
|
|
|
110
147
|
* `CollapseResult.blocks` unset and the recorder keeps the legacy shape.
|
|
111
148
|
*
|
|
112
149
|
* Interleaved ⇔ (a tool atom appears strictly before the first text atom) OR
|
|
113
|
-
* (a text atom appears after any tool atom).
|
|
150
|
+
* (a text atom appears after any tool atom). Tool atoms are `toolCall` and
|
|
151
|
+
* `customToolCall` atoms. A stream with no tool atoms, or
|
|
114
152
|
* with no text atoms, is never interleaved. Text-first-then-tools is the common
|
|
115
153
|
* legacy case and is explicitly NOT interleaved.
|
|
116
154
|
*
|
|
117
|
-
* CONSISTENCY (#274): each
|
|
118
|
-
* object referenced by its atom
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* arguments
|
|
155
|
+
* CONSISTENCY (#274): each tool block is derived from the SAME accumulator
|
|
156
|
+
* object referenced by its atom. Because the atom `ref` is the very object the
|
|
157
|
+
* flat list is built from, the block and its flat counterpart describe the same
|
|
158
|
+
* call by identity — even when upstream tool-call indices do not match
|
|
159
|
+
* stream-arrival order. A `toolCall` block is normalized identically to the
|
|
160
|
+
* flat `toolCalls` path ({@link toToolCallBlock} / {@link normalizeToolArguments}):
|
|
161
|
+
* empty/missing arguments become `"{}"` in BOTH representations, never `""`. A
|
|
162
|
+
* `customToolCall` block ({@link toCustomToolCallBlock}) keeps `input` verbatim,
|
|
163
|
+
* the same as the flat custom tool call ({@link toCustomToolCall}); it is never
|
|
164
|
+
* normalized to `"{}"`.
|
|
124
165
|
*/
|
|
125
166
|
function buildOrderedBlocks(atoms) {
|
|
167
|
+
return orderedBlocksFrom(atoms.filter((a) => a.kind !== "customToolCall"))?.filter((block) => block.type !== "customToolCall");
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* {@link buildOrderedBlocks} over every atom, custom calls included, for
|
|
171
|
+
* `CollapseResult.responsesBlocks`. With `force`, the blocks are built even
|
|
172
|
+
* when text and tools are not interleaved.
|
|
173
|
+
*/
|
|
174
|
+
function orderedBlocksFrom(atoms, force = false) {
|
|
126
175
|
let firstTextIndex = -1;
|
|
127
176
|
let firstToolIndex = -1;
|
|
128
177
|
let textAfterTool = false;
|
|
@@ -136,8 +185,10 @@ function buildOrderedBlocks(atoms) {
|
|
|
136
185
|
sawTool = true;
|
|
137
186
|
if (firstToolIndex === -1) firstToolIndex = i;
|
|
138
187
|
}
|
|
139
|
-
if (!
|
|
140
|
-
|
|
188
|
+
if (!force) {
|
|
189
|
+
if (!sawTool || !sawText) return void 0;
|
|
190
|
+
if (!(firstToolIndex < firstTextIndex) && !textAfterTool) return void 0;
|
|
191
|
+
}
|
|
141
192
|
const blocks = [];
|
|
142
193
|
let pendingText = "";
|
|
143
194
|
let hasPendingText = false;
|
|
@@ -156,7 +207,7 @@ function buildOrderedBlocks(atoms) {
|
|
|
156
207
|
hasPendingText = true;
|
|
157
208
|
} else {
|
|
158
209
|
flushText();
|
|
159
|
-
blocks.push(toToolCallBlock(a.ref));
|
|
210
|
+
blocks.push(a.kind === "customToolCall" ? toCustomToolCallBlock(a.ref) : toToolCallBlock(a.ref));
|
|
160
211
|
}
|
|
161
212
|
flushText();
|
|
162
213
|
return blocks;
|
|
@@ -233,8 +284,41 @@ function extractSSEData(lines) {
|
|
|
233
284
|
* Format:
|
|
234
285
|
* data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"Hello"}}]}\n\n
|
|
235
286
|
* data: [DONE]\n\n
|
|
287
|
+
*
|
|
288
|
+
* Public, with the 1.44.0 result: an OpenAI Responses `namespace` and custom
|
|
289
|
+
* tool calls are dropped. The recorder uses {@link collapseOpenAISSEWithResponsesTools}.
|
|
236
290
|
*/
|
|
237
291
|
function collapseOpenAISSE(rawBody) {
|
|
292
|
+
return withoutResponsesToolFields(collapseOpenAISSEWithResponsesTools(rawBody));
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* A collapse result as 1.44.0 returned and recorded it: no `namespace` on a
|
|
296
|
+
* function call or `toolCall` block, and no custom tool calls.
|
|
297
|
+
*/
|
|
298
|
+
function withoutResponsesToolFields(collapsed) {
|
|
299
|
+
if (collapsed.customToolCalls === void 0 && collapsed.responsesBlocks === void 0 && !collapsed.toolCalls?.some((tc) => tc.namespace !== void 0) && !collapsed.blocks?.some((block) => block.type !== "text" && block.namespace !== void 0)) return collapsed;
|
|
300
|
+
const result = { ...collapsed };
|
|
301
|
+
delete result.customToolCalls;
|
|
302
|
+
delete result.responsesBlocks;
|
|
303
|
+
if (result.toolCalls) result.toolCalls = result.toolCalls.map((tc) => {
|
|
304
|
+
if (tc.namespace === void 0) return tc;
|
|
305
|
+
const copy = { ...tc };
|
|
306
|
+
delete copy.namespace;
|
|
307
|
+
return copy;
|
|
308
|
+
});
|
|
309
|
+
if (result.blocks) result.blocks = result.blocks.map((block) => {
|
|
310
|
+
if (block.type === "text" || block.namespace === void 0) return block;
|
|
311
|
+
const copy = { ...block };
|
|
312
|
+
delete copy.namespace;
|
|
313
|
+
return copy;
|
|
314
|
+
});
|
|
315
|
+
return result;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* @internal {@link collapseOpenAISSE} keeping an OpenAI Responses `namespace`
|
|
319
|
+
* and custom tool calls, for the recorder with `responsesTools: "extended"`.
|
|
320
|
+
*/
|
|
321
|
+
function collapseOpenAISSEWithResponsesTools(rawBody) {
|
|
238
322
|
const inputTruncated = isCollapseInputTruncated(rawBody);
|
|
239
323
|
const lines = splitSSEEvents(guardCollapseBody(rawBody));
|
|
240
324
|
let content = "";
|
|
@@ -295,14 +379,19 @@ function collapseOpenAISSE(rawBody) {
|
|
|
295
379
|
if (item?.type === "function_call" && typeof parsed.output_index === "number") {
|
|
296
380
|
const entry = toolCallMap.get(parsed.output_index);
|
|
297
381
|
if (entry) {
|
|
298
|
-
if (
|
|
299
|
-
|
|
300
|
-
|
|
382
|
+
if (entry.kind === "function") {
|
|
383
|
+
if (!entry.id && typeof item.call_id === "string") entry.id = item.call_id;
|
|
384
|
+
if (!entry.name && typeof item.name === "string") entry.name = item.name;
|
|
385
|
+
if (!entry.namespace) entry.namespace = responsesNamespace(item);
|
|
386
|
+
if (entry.arguments === "" && typeof item.arguments === "string") entry.arguments = item.arguments;
|
|
387
|
+
}
|
|
301
388
|
} else {
|
|
302
389
|
const created = {
|
|
390
|
+
kind: "function",
|
|
303
391
|
id: typeof item.call_id === "string" ? item.call_id : "",
|
|
304
392
|
name: typeof item.name === "string" ? item.name : "",
|
|
305
|
-
arguments: typeof item.arguments === "string" ? item.arguments : ""
|
|
393
|
+
arguments: typeof item.arguments === "string" ? item.arguments : "",
|
|
394
|
+
namespace: responsesNamespace(item)
|
|
306
395
|
};
|
|
307
396
|
toolCallMap.set(parsed.output_index, created);
|
|
308
397
|
orderAtoms.push({
|
|
@@ -312,15 +401,42 @@ function collapseOpenAISSE(rawBody) {
|
|
|
312
401
|
}
|
|
313
402
|
continue;
|
|
314
403
|
}
|
|
404
|
+
if (item?.type === "custom_tool_call" && typeof parsed.output_index === "number") {
|
|
405
|
+
const entry = toolCallMap.get(parsed.output_index);
|
|
406
|
+
if (entry) {
|
|
407
|
+
if (entry.kind === "custom") {
|
|
408
|
+
if (!entry.id && typeof item.call_id === "string") entry.id = item.call_id;
|
|
409
|
+
if (!entry.name && typeof item.name === "string") entry.name = item.name;
|
|
410
|
+
if (!entry.namespace) entry.namespace = responsesNamespace(item);
|
|
411
|
+
if (entry.input === "" && typeof item.input === "string") entry.input = item.input;
|
|
412
|
+
}
|
|
413
|
+
} else {
|
|
414
|
+
const created = {
|
|
415
|
+
kind: "custom",
|
|
416
|
+
id: typeof item.call_id === "string" ? item.call_id : "",
|
|
417
|
+
name: typeof item.name === "string" ? item.name : "",
|
|
418
|
+
input: typeof item.input === "string" ? item.input : "",
|
|
419
|
+
namespace: responsesNamespace(item)
|
|
420
|
+
};
|
|
421
|
+
toolCallMap.set(parsed.output_index, created);
|
|
422
|
+
orderAtoms.push({
|
|
423
|
+
kind: "customToolCall",
|
|
424
|
+
ref: created
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
315
429
|
}
|
|
316
430
|
if (parsed.type === "response.output_item.added") {
|
|
317
431
|
const item = parsed.item;
|
|
318
432
|
if (item?.type === "function_call" && typeof parsed.output_index === "number") {
|
|
319
433
|
if (!toolCallMap.has(parsed.output_index)) {
|
|
320
434
|
const created = {
|
|
435
|
+
kind: "function",
|
|
321
436
|
id: typeof item.call_id === "string" ? item.call_id : "",
|
|
322
437
|
name: typeof item.name === "string" ? item.name : "",
|
|
323
|
-
arguments: ""
|
|
438
|
+
arguments: "",
|
|
439
|
+
namespace: responsesNamespace(item)
|
|
324
440
|
};
|
|
325
441
|
toolCallMap.set(parsed.output_index, created);
|
|
326
442
|
orderAtoms.push({
|
|
@@ -330,11 +446,66 @@ function collapseOpenAISSE(rawBody) {
|
|
|
330
446
|
}
|
|
331
447
|
continue;
|
|
332
448
|
}
|
|
449
|
+
if (item?.type === "custom_tool_call" && typeof parsed.output_index === "number") {
|
|
450
|
+
if (!toolCallMap.has(parsed.output_index)) {
|
|
451
|
+
const created = {
|
|
452
|
+
kind: "custom",
|
|
453
|
+
id: typeof item.call_id === "string" ? item.call_id : "",
|
|
454
|
+
name: typeof item.name === "string" ? item.name : "",
|
|
455
|
+
input: "",
|
|
456
|
+
namespace: responsesNamespace(item)
|
|
457
|
+
};
|
|
458
|
+
toolCallMap.set(parsed.output_index, created);
|
|
459
|
+
orderAtoms.push({
|
|
460
|
+
kind: "customToolCall",
|
|
461
|
+
ref: created
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
if (parsed.type === "response.custom_tool_call_input.delta" && typeof parsed.delta === "string" && typeof parsed.output_index === "number") {
|
|
468
|
+
let entry = toolCallMap.get(parsed.output_index);
|
|
469
|
+
if (!entry) {
|
|
470
|
+
entry = {
|
|
471
|
+
kind: "custom",
|
|
472
|
+
id: "",
|
|
473
|
+
name: "",
|
|
474
|
+
input: ""
|
|
475
|
+
};
|
|
476
|
+
toolCallMap.set(parsed.output_index, entry);
|
|
477
|
+
orderAtoms.push({
|
|
478
|
+
kind: "customToolCall",
|
|
479
|
+
ref: entry
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
if (entry.kind === "custom") entry.input += parsed.delta;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (parsed.type === "response.custom_tool_call_input.done" && typeof parsed.output_index === "number") {
|
|
486
|
+
const entry = toolCallMap.get(parsed.output_index);
|
|
487
|
+
if (entry) {
|
|
488
|
+
if (entry.kind === "custom" && entry.input === "" && typeof parsed.input === "string") entry.input = parsed.input;
|
|
489
|
+
} else if (typeof parsed.input === "string") {
|
|
490
|
+
const created = {
|
|
491
|
+
kind: "custom",
|
|
492
|
+
id: "",
|
|
493
|
+
name: "",
|
|
494
|
+
input: parsed.input
|
|
495
|
+
};
|
|
496
|
+
toolCallMap.set(parsed.output_index, created);
|
|
497
|
+
orderAtoms.push({
|
|
498
|
+
kind: "customToolCall",
|
|
499
|
+
ref: created
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
continue;
|
|
333
503
|
}
|
|
334
504
|
if (parsed.type === "response.function_call_arguments.delta" && typeof parsed.delta === "string" && typeof parsed.output_index === "number") {
|
|
335
505
|
let entry = toolCallMap.get(parsed.output_index);
|
|
336
506
|
if (!entry) {
|
|
337
507
|
entry = {
|
|
508
|
+
kind: "function",
|
|
338
509
|
id: "",
|
|
339
510
|
name: "",
|
|
340
511
|
arguments: ""
|
|
@@ -345,15 +516,16 @@ function collapseOpenAISSE(rawBody) {
|
|
|
345
516
|
ref: entry
|
|
346
517
|
});
|
|
347
518
|
}
|
|
348
|
-
entry.arguments += parsed.delta;
|
|
519
|
+
if (entry.kind === "function") entry.arguments += parsed.delta;
|
|
349
520
|
continue;
|
|
350
521
|
}
|
|
351
522
|
if (parsed.type === "response.function_call_arguments.done" && typeof parsed.output_index === "number") {
|
|
352
523
|
const entry = toolCallMap.get(parsed.output_index);
|
|
353
524
|
if (entry) {
|
|
354
|
-
if (entry.arguments === "" && typeof parsed.arguments === "string") entry.arguments = parsed.arguments;
|
|
525
|
+
if (entry.kind === "function" && entry.arguments === "" && typeof parsed.arguments === "string") entry.arguments = parsed.arguments;
|
|
355
526
|
} else if (typeof parsed.arguments === "string") {
|
|
356
527
|
const created = {
|
|
528
|
+
kind: "function",
|
|
357
529
|
id: "",
|
|
358
530
|
name: "",
|
|
359
531
|
arguments: parsed.arguments
|
|
@@ -406,6 +578,7 @@ function collapseOpenAISSE(rawBody) {
|
|
|
406
578
|
lastToolCallKey = index;
|
|
407
579
|
if (!toolCallMap.has(index)) {
|
|
408
580
|
const created = {
|
|
581
|
+
kind: "function",
|
|
409
582
|
id: rawId ?? "",
|
|
410
583
|
name: fn?.name ?? "",
|
|
411
584
|
arguments: ""
|
|
@@ -419,11 +592,11 @@ function collapseOpenAISSE(rawBody) {
|
|
|
419
592
|
const entry = toolCallMap.get(index);
|
|
420
593
|
if (fn?.name && typeof fn.name === "string" && !entry.name) entry.name = fn.name;
|
|
421
594
|
if (tc.id && typeof tc.id === "string" && !entry.id) entry.id = tc.id;
|
|
422
|
-
if (fn?.arguments && typeof fn.arguments === "string") entry.arguments += fn.arguments;
|
|
595
|
+
if (entry.kind === "function" && fn?.arguments && typeof fn.arguments === "string") entry.arguments += fn.arguments;
|
|
423
596
|
}
|
|
424
597
|
}
|
|
425
598
|
const harmonyToolCalls = [];
|
|
426
|
-
if (toolCallMap.
|
|
599
|
+
if (!Array.from(toolCallMap.values()).some((tc) => tc.kind === "function") && isHarmonyContent(content)) {
|
|
427
600
|
const parsed = parseHarmonyContent(content);
|
|
428
601
|
if (parsed.failed) {
|
|
429
602
|
harmonyUnparsed = true;
|
|
@@ -434,18 +607,22 @@ function collapseOpenAISSE(rawBody) {
|
|
|
434
607
|
harmonyToolCalls.push(...parsed.toolCalls);
|
|
435
608
|
}
|
|
436
609
|
}
|
|
437
|
-
|
|
610
|
+
const sortedEntries = Array.from(toolCallMap.entries()).sort(([a], [b]) => a - b);
|
|
611
|
+
const customEntries = sortedEntries.flatMap(([, tc]) => tc.kind === "custom" ? [tc] : []);
|
|
612
|
+
const functionEntries = sortedEntries.flatMap(([, tc]) => tc.kind === "function" ? [tc] : []);
|
|
613
|
+
let customFields = {};
|
|
614
|
+
if (customEntries.length > 0) {
|
|
615
|
+
const firstCustomAtom = orderAtoms.findIndex((a) => a.kind === "customToolCall");
|
|
616
|
+
const responsesBlocks = orderedBlocksFrom(orderAtoms, orderAtoms.some((a, i) => a.kind === "toolCall" && i > firstCustomAtom));
|
|
617
|
+
customFields = {
|
|
618
|
+
customToolCalls: responsesBlocks ? orderAtoms.flatMap((a) => a.kind === "customToolCall" ? [toCustomToolCall(a.ref)] : []) : customEntries.map(toCustomToolCall),
|
|
619
|
+
...responsesBlocks ? { responsesBlocks } : {}
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
if (functionEntries.length > 0 || harmonyToolCalls.length > 0) {
|
|
438
623
|
const blocks = buildOrderedBlocks(orderAtoms);
|
|
439
|
-
const orderedToolCalls = orderAtoms.
|
|
440
|
-
|
|
441
|
-
arguments: normalizeToolArguments(a.ref.arguments),
|
|
442
|
-
...a.ref.id ? { id: a.ref.id } : {}
|
|
443
|
-
}));
|
|
444
|
-
const indexSortedToolCalls = Array.from(toolCallMap.entries()).sort(([a], [b]) => a - b).map(([, tc]) => ({
|
|
445
|
-
name: tc.name,
|
|
446
|
-
arguments: normalizeToolArguments(tc.arguments),
|
|
447
|
-
...tc.id ? { id: tc.id } : {}
|
|
448
|
-
}));
|
|
624
|
+
const orderedToolCalls = orderAtoms.flatMap((a) => a.kind === "toolCall" ? [toFunctionToolCall(a.ref)] : []);
|
|
625
|
+
const indexSortedToolCalls = functionEntries.map(toFunctionToolCall);
|
|
449
626
|
return {
|
|
450
627
|
...transcriptSeen ? { transcription: {
|
|
451
628
|
text: transcript,
|
|
@@ -455,6 +632,7 @@ function collapseOpenAISSE(rawBody) {
|
|
|
455
632
|
...blocks ? { blocks } : {},
|
|
456
633
|
...content ? { content } : {},
|
|
457
634
|
toolCalls: [...blocks ? orderedToolCalls : indexSortedToolCalls, ...harmonyToolCalls],
|
|
635
|
+
...customFields,
|
|
458
636
|
...reasoning ? { reasoning } : {},
|
|
459
637
|
...webSearchQueries.length > 0 ? { webSearches: webSearchQueries } : {},
|
|
460
638
|
...usage ? { usage } : {},
|
|
@@ -472,6 +650,7 @@ function collapseOpenAISSE(rawBody) {
|
|
|
472
650
|
...transcriptUsage ? { usage: transcriptUsage } : {}
|
|
473
651
|
} } : {},
|
|
474
652
|
content,
|
|
653
|
+
...customFields,
|
|
475
654
|
...reasoning ? { reasoning } : {},
|
|
476
655
|
...webSearchQueries.length > 0 ? { webSearches: webSearchQueries } : {},
|
|
477
656
|
...usage ? { usage } : {},
|
|
@@ -1010,6 +1189,16 @@ function collapseBedrockEventStream(rawBody) {
|
|
|
1010
1189
|
let parsed;
|
|
1011
1190
|
try {
|
|
1012
1191
|
parsed = JSON.parse(frameStr);
|
|
1192
|
+
if (frame.headers[":event-type"] === "chunk" && parsed !== null && typeof parsed === "object" && Object.hasOwn(parsed, "bytes")) try {
|
|
1193
|
+
const bytes = parsed.bytes;
|
|
1194
|
+
if (typeof bytes !== "string" || bytes.length === 0 || !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(bytes)) throw new TypeError("bytes must be a nonempty base64 string");
|
|
1195
|
+
const event = JSON.parse(Buffer.from(bytes, "base64").toString("utf8"));
|
|
1196
|
+
if (event === null || typeof event !== "object" || Array.isArray(event) || !("type" in event) || typeof event.type !== "string") throw new TypeError("decoded bytes must contain a Claude event object");
|
|
1197
|
+
parsed = event;
|
|
1198
|
+
} catch (err) {
|
|
1199
|
+
const message = err instanceof Error ? err.message : "unknown";
|
|
1200
|
+
throw new TypeError(`Invalid Invoke PayloadPart: ${message}`);
|
|
1201
|
+
}
|
|
1013
1202
|
} catch (err) {
|
|
1014
1203
|
droppedChunks++;
|
|
1015
1204
|
if (droppedChunks === 1) firstDroppedSample = `parse failed (${err instanceof Error ? err.message : "unknown"}): ${surrogateSafeSlice(frameStr, 200)}`;
|
|
@@ -1255,8 +1444,19 @@ function collapseGeminiInteractionsSSE(rawBody) {
|
|
|
1255
1444
|
* Collapse a streaming response body into a non-streaming fixture response.
|
|
1256
1445
|
* Returns null if the content type is not a known streaming format.
|
|
1257
1446
|
* Falls back to OpenAI SSE parsing for unrecognized provider keys with text/event-stream.
|
|
1447
|
+
*
|
|
1448
|
+
* Public, with the 1.44.0 result (see {@link collapseOpenAISSE}). The recorder
|
|
1449
|
+
* uses {@link collapseStreamingResponseWithResponsesTools}.
|
|
1258
1450
|
*/
|
|
1259
1451
|
function collapseStreamingResponse(contentType, providerKey, body, logger) {
|
|
1452
|
+
const collapsed = collapseStreamingResponseWithResponsesTools(contentType, providerKey, body, logger);
|
|
1453
|
+
return collapsed && withoutResponsesToolFields(collapsed);
|
|
1454
|
+
}
|
|
1455
|
+
/**
|
|
1456
|
+
* @internal {@link collapseStreamingResponse} keeping an OpenAI Responses
|
|
1457
|
+
* `namespace` and custom tool calls.
|
|
1458
|
+
*/
|
|
1459
|
+
function collapseStreamingResponseWithResponsesTools(contentType, providerKey, body, logger) {
|
|
1260
1460
|
const ct = contentType.toLowerCase();
|
|
1261
1461
|
if (ct.includes("application/vnd.amazon.eventstream")) return collapseBedrockEventStream(typeof body === "string" ? Buffer.from(body, "binary") : body);
|
|
1262
1462
|
if (ct.includes("application/x-ndjson")) return collapseOllamaNDJSON(typeof body === "string" ? body : body.toString("utf8"));
|
|
@@ -1266,7 +1466,7 @@ function collapseStreamingResponse(contentType, providerKey, body, logger) {
|
|
|
1266
1466
|
case "openai":
|
|
1267
1467
|
case "azure":
|
|
1268
1468
|
case "openrouter":
|
|
1269
|
-
case "byteplus": return
|
|
1469
|
+
case "byteplus": return collapseOpenAISSEWithResponsesTools(str);
|
|
1270
1470
|
case "anthropic": return collapseAnthropicSSE(str);
|
|
1271
1471
|
case "gemini":
|
|
1272
1472
|
case "vertexai": return collapseGeminiSSE(str);
|
|
@@ -1275,12 +1475,12 @@ function collapseStreamingResponse(contentType, providerKey, body, logger) {
|
|
|
1275
1475
|
case "bedrock": return collapseAnthropicSSE(str);
|
|
1276
1476
|
default:
|
|
1277
1477
|
logger?.warn(`[stream-collapse] unknown SSE provider "${providerKey}", falling back to OpenAI SSE format`);
|
|
1278
|
-
return
|
|
1478
|
+
return collapseOpenAISSEWithResponsesTools(str);
|
|
1279
1479
|
}
|
|
1280
1480
|
}
|
|
1281
1481
|
return null;
|
|
1282
1482
|
}
|
|
1283
1483
|
|
|
1284
1484
|
//#endregion
|
|
1285
|
-
export { MAX_COLLAPSE_STRING_LENGTH, capturedRedactedData, collapseAnthropicSSE, collapseBedrockEventStream, collapseCohereSSE, collapseGeminiInteractionsSSE, collapseGeminiSSE, collapseOllamaNDJSON, collapseOpenAISSE, collapseStreamingResponse, setCollapseStringLimitForTests };
|
|
1485
|
+
export { MAX_COLLAPSE_STRING_LENGTH, capturedRedactedData, collapseAnthropicSSE, collapseBedrockEventStream, collapseCohereSSE, collapseGeminiInteractionsSSE, collapseGeminiSSE, collapseOllamaNDJSON, collapseOpenAISSE, collapseStreamingResponse, collapseStreamingResponseWithResponsesTools, setCollapseStringLimitForTests, withoutResponsesToolFields };
|
|
1286
1486
|
//# sourceMappingURL=stream-collapse.js.map
|