@copilotkit/aimock 1.39.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.
Files changed (50) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +30 -0
  4. package/README.md +1 -0
  5. package/dist/agui-handler.d.cts.map +1 -1
  6. package/dist/agui-stub.d.cts +2 -2
  7. package/dist/agui-stub.d.ts +2 -2
  8. package/dist/agui-types.d.cts +66 -3
  9. package/dist/agui-types.d.cts.map +1 -1
  10. package/dist/agui-types.d.ts +66 -3
  11. package/dist/agui-types.d.ts.map +1 -1
  12. package/dist/config-loader.d.cts.map +1 -1
  13. package/dist/config-loader.d.ts.map +1 -1
  14. package/dist/helpers.cjs +8 -4
  15. package/dist/helpers.cjs.map +1 -1
  16. package/dist/helpers.d.cts.map +1 -1
  17. package/dist/helpers.d.ts.map +1 -1
  18. package/dist/helpers.js +8 -4
  19. package/dist/helpers.js.map +1 -1
  20. package/dist/index.d.cts +2 -2
  21. package/dist/index.d.ts +2 -2
  22. package/dist/openrouter-chat.cjs +41 -0
  23. package/dist/openrouter-chat.cjs.map +1 -1
  24. package/dist/openrouter-chat.js +41 -0
  25. package/dist/openrouter-chat.js.map +1 -1
  26. package/dist/recorder.cjs +77 -8
  27. package/dist/recorder.cjs.map +1 -1
  28. package/dist/recorder.d.cts.map +1 -1
  29. package/dist/recorder.d.ts.map +1 -1
  30. package/dist/recorder.js +77 -8
  31. package/dist/recorder.js.map +1 -1
  32. package/dist/server.cjs +46 -0
  33. package/dist/server.cjs.map +1 -1
  34. package/dist/server.d.cts.map +1 -1
  35. package/dist/server.d.ts.map +1 -1
  36. package/dist/server.js +46 -0
  37. package/dist/server.js.map +1 -1
  38. package/dist/stream-collapse.cjs +20 -6
  39. package/dist/stream-collapse.cjs.map +1 -1
  40. package/dist/stream-collapse.d.cts +16 -0
  41. package/dist/stream-collapse.d.cts.map +1 -1
  42. package/dist/stream-collapse.d.ts +16 -0
  43. package/dist/stream-collapse.d.ts.map +1 -1
  44. package/dist/stream-collapse.js +20 -6
  45. package/dist/stream-collapse.js.map +1 -1
  46. package/dist/types.d.cts +22 -3
  47. package/dist/types.d.cts.map +1 -1
  48. package/dist/types.d.ts +22 -3
  49. package/dist/types.d.ts.map +1 -1
  50. package/package.json +3 -2
@@ -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") {
@@ -374,6 +376,7 @@ function collapseOpenAISSE(rawBody) {
374
376
  continue;
375
377
  }
376
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;
377
380
  const choices = parsed.choices;
378
381
  if (!choices || choices.length === 0) continue;
379
382
  const delta = choices[0].delta;
@@ -399,7 +402,9 @@ function collapseOpenAISSE(rawBody) {
399
402
  index = nextSyntheticIndex++;
400
403
  idKeyMap.set(rawId, index);
401
404
  }
402
- } else index = nextSyntheticIndex++;
405
+ } else if (lastToolCallKey !== void 0) index = lastToolCallKey;
406
+ else index = nextSyntheticIndex++;
407
+ lastToolCallKey = index;
403
408
  if (!toolCallMap.has(index)) {
404
409
  const created = {
405
410
  id: rawId ?? "",
@@ -453,6 +458,7 @@ function collapseOpenAISSE(rawBody) {
453
458
  toolCalls: [...blocks ? orderedToolCalls : indexSortedToolCalls, ...harmonyToolCalls],
454
459
  ...reasoning ? { reasoning } : {},
455
460
  ...webSearchQueries.length > 0 ? { webSearches: webSearchQueries } : {},
461
+ ...usage ? { usage } : {},
456
462
  ...droppedChunks > 0 ? { droppedChunks } : {},
457
463
  ...firstDroppedSample ? { firstDroppedSample } : {},
458
464
  ...harmonyUnparsed ? { harmonyUnparsed: true } : {},
@@ -469,6 +475,7 @@ function collapseOpenAISSE(rawBody) {
469
475
  content,
470
476
  ...reasoning ? { reasoning } : {},
471
477
  ...webSearchQueries.length > 0 ? { webSearches: webSearchQueries } : {},
478
+ ...usage ? { usage } : {},
472
479
  ...droppedChunks > 0 ? { droppedChunks } : {},
473
480
  ...firstDroppedSample ? { firstDroppedSample } : {},
474
481
  ...harmonyUnparsed ? { harmonyUnparsed: true } : {},
@@ -833,7 +840,6 @@ function collapseCohereSSE(rawBody) {
833
840
  let index;
834
841
  if (typeof parsed.index === "number") index = parsed.index;
835
842
  else index = nextSyntheticIndex++;
836
- lastStartKey = index;
837
843
  const toolCalls = (parsed.delta?.message)?.tool_calls;
838
844
  if (toolCalls) {
839
845
  const fn = toolCalls.function;
@@ -843,6 +849,7 @@ function collapseCohereSSE(rawBody) {
843
849
  arguments: ""
844
850
  };
845
851
  toolCallMap.set(index, created);
852
+ lastStartKey = index;
846
853
  orderAtoms.push({
847
854
  kind: "toolCall",
848
855
  ref: created
@@ -1036,7 +1043,7 @@ function collapseBedrockEventStream(rawBody) {
1036
1043
  const index = parsed.index;
1037
1044
  const redactedData = capturedRedactedData(block);
1038
1045
  if (redactedData !== void 0) redactedThinking.push(redactedData);
1039
- if (block?.type === "tool_use" && index !== void 0) {
1046
+ if (block?.type === "tool_use") if (index !== void 0) {
1040
1047
  const created = {
1041
1048
  id: block.id ?? "",
1042
1049
  name: block.name ?? "",
@@ -1047,6 +1054,9 @@ function collapseBedrockEventStream(rawBody) {
1047
1054
  kind: "toolCall",
1048
1055
  ref: created
1049
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)}`;
1050
1060
  }
1051
1061
  continue;
1052
1062
  }
@@ -1054,7 +1064,7 @@ function collapseBedrockEventStream(rawBody) {
1054
1064
  const blockStart = parsed.contentBlockStart;
1055
1065
  const index = parsed.contentBlockIndex ?? blockStart.contentBlockIndex;
1056
1066
  const start = blockStart.start;
1057
- if (start?.toolUse && index !== void 0) {
1067
+ if (start?.toolUse) if (index !== void 0) {
1058
1068
  const toolUse = start.toolUse;
1059
1069
  const created = {
1060
1070
  id: toolUse.toolUseId ?? "",
@@ -1066,6 +1076,9 @@ function collapseBedrockEventStream(rawBody) {
1066
1076
  kind: "toolCall",
1067
1077
  ref: created
1068
1078
  });
1079
+ } else {
1080
+ droppedChunks++;
1081
+ if (droppedChunks === 1) firstDroppedSample = `contentBlockStart toolUse with no index — tool call identity lost: ${surrogateSafeSlice(frameStr, 200)}`;
1069
1082
  }
1070
1083
  }
1071
1084
  if (parsed.contentBlockDelta) {
@@ -1252,7 +1265,8 @@ function collapseStreamingResponse(contentType, providerKey, body, logger) {
1252
1265
  const str = typeof body === "string" ? body : body.toString("utf8");
1253
1266
  switch (providerKey) {
1254
1267
  case "openai":
1255
- case "azure": return collapseOpenAISSE(str);
1268
+ case "azure":
1269
+ case "openrouter": return collapseOpenAISSE(str);
1256
1270
  case "anthropic": return collapseAnthropicSSE(str);
1257
1271
  case "gemini":
1258
1272
  case "vertexai": return collapseGeminiSSE(str);