@copilotkit/aimock 1.38.0 → 1.40.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 +56 -0
- package/README.md +24 -2
- package/dist/agui-handler.cjs +20 -18
- package/dist/agui-handler.cjs.map +1 -1
- package/dist/agui-handler.d.cts +8 -1
- package/dist/agui-handler.d.cts.map +1 -1
- package/dist/agui-handler.d.ts +8 -1
- package/dist/agui-handler.d.ts.map +1 -1
- package/dist/agui-handler.js +20 -18
- package/dist/agui-handler.js.map +1 -1
- package/dist/agui-stub.d.cts +2 -2
- package/dist/agui-stub.d.ts +2 -2
- package/dist/agui-types.d.cts +84 -3
- package/dist/agui-types.d.cts.map +1 -1
- package/dist/agui-types.d.ts +84 -3
- package/dist/agui-types.d.ts.map +1 -1
- package/dist/aimock-cli.cjs +1 -1
- package/dist/aimock-cli.cjs.map +1 -1
- package/dist/aimock-cli.js +1 -1
- package/dist/aimock-cli.js.map +1 -1
- package/dist/cli.cjs +10 -10
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +10 -10
- package/dist/cli.js.map +1 -1
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/helpers.cjs +8 -4
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +8 -4
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/llmock.cjs +23 -9
- package/dist/llmock.cjs.map +1 -1
- package/dist/llmock.d.cts +22 -0
- package/dist/llmock.d.cts.map +1 -1
- package/dist/llmock.d.ts +22 -0
- package/dist/llmock.d.ts.map +1 -1
- package/dist/llmock.js +25 -11
- package/dist/llmock.js.map +1 -1
- package/dist/openrouter-chat.cjs +41 -0
- package/dist/openrouter-chat.cjs.map +1 -1
- package/dist/openrouter-chat.js +41 -0
- package/dist/openrouter-chat.js.map +1 -1
- package/dist/openrouter-video.cjs.map +1 -1
- package/dist/openrouter-video.js.map +1 -1
- package/dist/recorder.cjs +77 -8
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.d.cts.map +1 -1
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +77 -8
- package/dist/recorder.js.map +1 -1
- package/dist/server.cjs +80 -17
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +6 -1
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts +6 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +80 -18
- package/dist/server.js.map +1 -1
- package/dist/stream-collapse.cjs +97 -6
- package/dist/stream-collapse.cjs.map +1 -1
- package/dist/stream-collapse.d.cts +16 -0
- package/dist/stream-collapse.d.cts.map +1 -1
- package/dist/stream-collapse.d.ts +16 -0
- package/dist/stream-collapse.d.ts.map +1 -1
- package/dist/stream-collapse.js +97 -6
- package/dist/stream-collapse.js.map +1 -1
- package/dist/types.d.cts +22 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +22 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/vector-types.d.ts.map +1 -1
- package/dist/ws-gemini-live.cjs +41 -6
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.js +41 -6
- package/dist/ws-gemini-live.js.map +1 -1
- package/package.json +5 -3
package/dist/stream-collapse.cjs
CHANGED
|
@@ -245,6 +245,7 @@ function collapseOpenAISSE(rawBody) {
|
|
|
245
245
|
let transcriptUsage;
|
|
246
246
|
let reasoning = "";
|
|
247
247
|
const webSearchQueries = [];
|
|
248
|
+
let usage;
|
|
248
249
|
let droppedChunks = 0;
|
|
249
250
|
let firstDroppedSample;
|
|
250
251
|
let harmonyUnparsed = false;
|
|
@@ -252,6 +253,7 @@ function collapseOpenAISSE(rawBody) {
|
|
|
252
253
|
const toolCallMap = /* @__PURE__ */ new Map();
|
|
253
254
|
let nextSyntheticIndex = 1e6;
|
|
254
255
|
const idKeyMap = /* @__PURE__ */ new Map();
|
|
256
|
+
let lastToolCallKey;
|
|
255
257
|
const orderAtoms = [];
|
|
256
258
|
for (const line of lines) {
|
|
257
259
|
const data = extractSSEData(splitSSELines(line));
|
|
@@ -275,7 +277,7 @@ function collapseOpenAISSE(rawBody) {
|
|
|
275
277
|
transcript = parsed.text;
|
|
276
278
|
transcriptSeen = true;
|
|
277
279
|
if (Array.isArray(parsed.languages)) transcriptLanguages = parsed.languages.filter((language) => typeof language === "object" && language !== null && typeof language.code === "string").map((language) => ({ code: language.code }));
|
|
278
|
-
if (parsed.usage && typeof parsed.usage === "object") transcriptUsage = parsed.usage;
|
|
280
|
+
if (parsed.usage && typeof parsed.usage === "object" && !Array.isArray(parsed.usage) && Object.keys(parsed.usage).length > 0) transcriptUsage = parsed.usage;
|
|
279
281
|
continue;
|
|
280
282
|
}
|
|
281
283
|
if (parsed.type === "response.reasoning_summary_text.delta" && typeof parsed.delta === "string") {
|
|
@@ -291,12 +293,90 @@ function collapseOpenAISSE(rawBody) {
|
|
|
291
293
|
continue;
|
|
292
294
|
}
|
|
293
295
|
}
|
|
296
|
+
if (item?.type === "function_call" && typeof parsed.output_index === "number") {
|
|
297
|
+
const entry = toolCallMap.get(parsed.output_index);
|
|
298
|
+
if (entry) {
|
|
299
|
+
if (!entry.id && typeof item.call_id === "string") entry.id = item.call_id;
|
|
300
|
+
if (!entry.name && typeof item.name === "string") entry.name = item.name;
|
|
301
|
+
if (entry.arguments === "" && typeof item.arguments === "string") entry.arguments = item.arguments;
|
|
302
|
+
} else {
|
|
303
|
+
const created = {
|
|
304
|
+
id: typeof item.call_id === "string" ? item.call_id : "",
|
|
305
|
+
name: typeof item.name === "string" ? item.name : "",
|
|
306
|
+
arguments: typeof item.arguments === "string" ? item.arguments : ""
|
|
307
|
+
};
|
|
308
|
+
toolCallMap.set(parsed.output_index, created);
|
|
309
|
+
orderAtoms.push({
|
|
310
|
+
kind: "toolCall",
|
|
311
|
+
ref: created
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (parsed.type === "response.output_item.added") {
|
|
318
|
+
const item = parsed.item;
|
|
319
|
+
if (item?.type === "function_call" && typeof parsed.output_index === "number") {
|
|
320
|
+
if (!toolCallMap.has(parsed.output_index)) {
|
|
321
|
+
const created = {
|
|
322
|
+
id: typeof item.call_id === "string" ? item.call_id : "",
|
|
323
|
+
name: typeof item.name === "string" ? item.name : "",
|
|
324
|
+
arguments: ""
|
|
325
|
+
};
|
|
326
|
+
toolCallMap.set(parsed.output_index, created);
|
|
327
|
+
orderAtoms.push({
|
|
328
|
+
kind: "toolCall",
|
|
329
|
+
ref: created
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (parsed.type === "response.function_call_arguments.delta" && typeof parsed.delta === "string" && typeof parsed.output_index === "number") {
|
|
336
|
+
let entry = toolCallMap.get(parsed.output_index);
|
|
337
|
+
if (!entry) {
|
|
338
|
+
entry = {
|
|
339
|
+
id: "",
|
|
340
|
+
name: "",
|
|
341
|
+
arguments: ""
|
|
342
|
+
};
|
|
343
|
+
toolCallMap.set(parsed.output_index, entry);
|
|
344
|
+
orderAtoms.push({
|
|
345
|
+
kind: "toolCall",
|
|
346
|
+
ref: entry
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
entry.arguments += parsed.delta;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (parsed.type === "response.function_call_arguments.done" && typeof parsed.output_index === "number") {
|
|
353
|
+
const entry = toolCallMap.get(parsed.output_index);
|
|
354
|
+
if (entry) {
|
|
355
|
+
if (entry.arguments === "" && typeof parsed.arguments === "string") entry.arguments = parsed.arguments;
|
|
356
|
+
} else if (typeof parsed.arguments === "string") {
|
|
357
|
+
const created = {
|
|
358
|
+
id: "",
|
|
359
|
+
name: "",
|
|
360
|
+
arguments: parsed.arguments
|
|
361
|
+
};
|
|
362
|
+
toolCallMap.set(parsed.output_index, created);
|
|
363
|
+
orderAtoms.push({
|
|
364
|
+
kind: "toolCall",
|
|
365
|
+
ref: created
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
continue;
|
|
294
369
|
}
|
|
295
370
|
if (parsed.type === "response.output_text.delta" && typeof parsed.delta === "string") {
|
|
296
371
|
content += parsed.delta;
|
|
372
|
+
if (parsed.delta.length > 0) orderAtoms.push({
|
|
373
|
+
kind: "text",
|
|
374
|
+
text: parsed.delta
|
|
375
|
+
});
|
|
297
376
|
continue;
|
|
298
377
|
}
|
|
299
378
|
if (typeof parsed.type === "string" && parsed.type.startsWith("response.")) continue;
|
|
379
|
+
if (parsed.usage && typeof parsed.usage === "object" && !Array.isArray(parsed.usage) && Object.keys(parsed.usage).length > 0) usage = parsed.usage;
|
|
300
380
|
const choices = parsed.choices;
|
|
301
381
|
if (!choices || choices.length === 0) continue;
|
|
302
382
|
const delta = choices[0].delta;
|
|
@@ -322,7 +402,9 @@ function collapseOpenAISSE(rawBody) {
|
|
|
322
402
|
index = nextSyntheticIndex++;
|
|
323
403
|
idKeyMap.set(rawId, index);
|
|
324
404
|
}
|
|
325
|
-
} else index =
|
|
405
|
+
} else if (lastToolCallKey !== void 0) index = lastToolCallKey;
|
|
406
|
+
else index = nextSyntheticIndex++;
|
|
407
|
+
lastToolCallKey = index;
|
|
326
408
|
if (!toolCallMap.has(index)) {
|
|
327
409
|
const created = {
|
|
328
410
|
id: rawId ?? "",
|
|
@@ -376,6 +458,7 @@ function collapseOpenAISSE(rawBody) {
|
|
|
376
458
|
toolCalls: [...blocks ? orderedToolCalls : indexSortedToolCalls, ...harmonyToolCalls],
|
|
377
459
|
...reasoning ? { reasoning } : {},
|
|
378
460
|
...webSearchQueries.length > 0 ? { webSearches: webSearchQueries } : {},
|
|
461
|
+
...usage ? { usage } : {},
|
|
379
462
|
...droppedChunks > 0 ? { droppedChunks } : {},
|
|
380
463
|
...firstDroppedSample ? { firstDroppedSample } : {},
|
|
381
464
|
...harmonyUnparsed ? { harmonyUnparsed: true } : {},
|
|
@@ -392,6 +475,7 @@ function collapseOpenAISSE(rawBody) {
|
|
|
392
475
|
content,
|
|
393
476
|
...reasoning ? { reasoning } : {},
|
|
394
477
|
...webSearchQueries.length > 0 ? { webSearches: webSearchQueries } : {},
|
|
478
|
+
...usage ? { usage } : {},
|
|
395
479
|
...droppedChunks > 0 ? { droppedChunks } : {},
|
|
396
480
|
...firstDroppedSample ? { firstDroppedSample } : {},
|
|
397
481
|
...harmonyUnparsed ? { harmonyUnparsed: true } : {},
|
|
@@ -756,7 +840,6 @@ function collapseCohereSSE(rawBody) {
|
|
|
756
840
|
let index;
|
|
757
841
|
if (typeof parsed.index === "number") index = parsed.index;
|
|
758
842
|
else index = nextSyntheticIndex++;
|
|
759
|
-
lastStartKey = index;
|
|
760
843
|
const toolCalls = (parsed.delta?.message)?.tool_calls;
|
|
761
844
|
if (toolCalls) {
|
|
762
845
|
const fn = toolCalls.function;
|
|
@@ -766,6 +849,7 @@ function collapseCohereSSE(rawBody) {
|
|
|
766
849
|
arguments: ""
|
|
767
850
|
};
|
|
768
851
|
toolCallMap.set(index, created);
|
|
852
|
+
lastStartKey = index;
|
|
769
853
|
orderAtoms.push({
|
|
770
854
|
kind: "toolCall",
|
|
771
855
|
ref: created
|
|
@@ -959,7 +1043,7 @@ function collapseBedrockEventStream(rawBody) {
|
|
|
959
1043
|
const index = parsed.index;
|
|
960
1044
|
const redactedData = capturedRedactedData(block);
|
|
961
1045
|
if (redactedData !== void 0) redactedThinking.push(redactedData);
|
|
962
|
-
if (block?.type === "tool_use"
|
|
1046
|
+
if (block?.type === "tool_use") if (index !== void 0) {
|
|
963
1047
|
const created = {
|
|
964
1048
|
id: block.id ?? "",
|
|
965
1049
|
name: block.name ?? "",
|
|
@@ -970,6 +1054,9 @@ function collapseBedrockEventStream(rawBody) {
|
|
|
970
1054
|
kind: "toolCall",
|
|
971
1055
|
ref: created
|
|
972
1056
|
});
|
|
1057
|
+
} else {
|
|
1058
|
+
droppedChunks++;
|
|
1059
|
+
if (droppedChunks === 1) firstDroppedSample = `tool_use content_block_start with no index — tool call identity lost: ${surrogateSafeSlice(frameStr, 200)}`;
|
|
973
1060
|
}
|
|
974
1061
|
continue;
|
|
975
1062
|
}
|
|
@@ -977,7 +1064,7 @@ function collapseBedrockEventStream(rawBody) {
|
|
|
977
1064
|
const blockStart = parsed.contentBlockStart;
|
|
978
1065
|
const index = parsed.contentBlockIndex ?? blockStart.contentBlockIndex;
|
|
979
1066
|
const start = blockStart.start;
|
|
980
|
-
if (start?.toolUse
|
|
1067
|
+
if (start?.toolUse) if (index !== void 0) {
|
|
981
1068
|
const toolUse = start.toolUse;
|
|
982
1069
|
const created = {
|
|
983
1070
|
id: toolUse.toolUseId ?? "",
|
|
@@ -989,6 +1076,9 @@ function collapseBedrockEventStream(rawBody) {
|
|
|
989
1076
|
kind: "toolCall",
|
|
990
1077
|
ref: created
|
|
991
1078
|
});
|
|
1079
|
+
} else {
|
|
1080
|
+
droppedChunks++;
|
|
1081
|
+
if (droppedChunks === 1) firstDroppedSample = `contentBlockStart toolUse with no index — tool call identity lost: ${surrogateSafeSlice(frameStr, 200)}`;
|
|
992
1082
|
}
|
|
993
1083
|
}
|
|
994
1084
|
if (parsed.contentBlockDelta) {
|
|
@@ -1175,7 +1265,8 @@ function collapseStreamingResponse(contentType, providerKey, body, logger) {
|
|
|
1175
1265
|
const str = typeof body === "string" ? body : body.toString("utf8");
|
|
1176
1266
|
switch (providerKey) {
|
|
1177
1267
|
case "openai":
|
|
1178
|
-
case "azure":
|
|
1268
|
+
case "azure":
|
|
1269
|
+
case "openrouter": return collapseOpenAISSE(str);
|
|
1179
1270
|
case "anthropic": return collapseAnthropicSSE(str);
|
|
1180
1271
|
case "gemini":
|
|
1181
1272
|
case "vertexai": return collapseGeminiSSE(str);
|