@posthog/ai 8.16.2 → 8.16.3

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.
@@ -548,7 +548,7 @@ function formatOpenAIResponsesInput(input, instructions) {
548
548
  }
549
549
  //#endregion
550
550
  //#region package.json
551
- var version = "8.16.2";
551
+ var version = "8.16.3";
552
552
  //#endregion
553
553
  //#region src/serializeError.ts
554
554
  const DEFAULT_MAX_DEPTH = 3;
@@ -1303,8 +1303,8 @@ var OpenAIChatStreamAccumulator = class {
1303
1303
  if (Array.isArray(choice?.delta?.tool_calls)) {
1304
1304
  this.firstTokenTime ??= receivedAt;
1305
1305
  for (const toolCall of choice.delta.tool_calls) {
1306
- if (toolCall.index === void 0) continue;
1307
- const current = this.toolCalls.get(toolCall.index) ?? {
1306
+ const key = this.toolCallKey(toolCall);
1307
+ const current = this.toolCalls.get(key) ?? {
1308
1308
  id: "",
1309
1309
  name: "",
1310
1310
  arguments: ""
@@ -1312,7 +1312,8 @@ var OpenAIChatStreamAccumulator = class {
1312
1312
  if (toolCall.id) current.id = toolCall.id;
1313
1313
  if (toolCall.function?.name) current.name = toolCall.function.name;
1314
1314
  if (toolCall.function?.arguments) current.arguments += toolCall.function.arguments;
1315
- this.toolCalls.set(toolCall.index, current);
1315
+ this.toolCalls.set(key, current);
1316
+ this.lastToolCallKey = key;
1316
1317
  }
1317
1318
  }
1318
1319
  if (chunk.usage) this.usage = {
@@ -1325,6 +1326,18 @@ var OpenAIChatStreamAccumulator = class {
1325
1326
  rawUsage: chunk.usage
1326
1327
  };
1327
1328
  }
1329
+ /**
1330
+ * Some OpenAI-compatible providers stream tool calls without an `index`. Match those deltas by a known
1331
+ * `id`; a new `id` or a function name opens a new call, and anything else continues the latest call.
1332
+ */
1333
+ toolCallKey(toolCall) {
1334
+ if (toolCall.index !== void 0) return toolCall.index;
1335
+ if (toolCall.id) {
1336
+ for (const [key, existing] of this.toolCalls) if (existing.id === toolCall.id) return key;
1337
+ }
1338
+ if (toolCall.id || toolCall.function?.name || this.lastToolCallKey === void 0) return `no-index-${this.toolCalls.size}`;
1339
+ return this.lastToolCallKey;
1340
+ }
1328
1341
  result() {
1329
1342
  const content = [];
1330
1343
  if (this.accumulatedContent) content.push({