@posthog/ai 8.16.2 → 8.17.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.
@@ -466,7 +466,7 @@ function addDefaults(params) {
466
466
  }
467
467
  //#endregion
468
468
  //#region package.json
469
- var version = "8.16.2";
469
+ var version = "8.17.0";
470
470
  //#endregion
471
471
  //#region src/serializeError.ts
472
472
  const DEFAULT_MAX_DEPTH = 3;
@@ -462,7 +462,7 @@ function addDefaults(params) {
462
462
  }
463
463
  //#endregion
464
464
  //#region package.json
465
- var version = "8.16.2";
465
+ var version = "8.17.0";
466
466
  //#endregion
467
467
  //#region src/serializeError.ts
468
468
  const DEFAULT_MAX_DEPTH = 3;
package/dist/index.cjs CHANGED
@@ -413,7 +413,7 @@ function sanitizeValues(obj) {
413
413
  }
414
414
  //#endregion
415
415
  //#region package.json
416
- var version = "8.16.2";
416
+ var version = "8.17.0";
417
417
  //#endregion
418
418
  //#region src/serializeError.ts
419
419
  const DEFAULT_MAX_DEPTH = 3;
package/dist/index.mjs CHANGED
@@ -412,7 +412,7 @@ function sanitizeValues(obj) {
412
412
  }
413
413
  //#endregion
414
414
  //#region package.json
415
- var version = "8.16.2";
415
+ var version = "8.17.0";
416
416
  //#endregion
417
417
  //#region src/serializeError.ts
418
418
  const DEFAULT_MAX_DEPTH = 3;
@@ -308,7 +308,7 @@ function redactMcpToolCredentials(tools) {
308
308
  }
309
309
  //#endregion
310
310
  //#region package.json
311
- var version = "8.16.2";
311
+ var version = "8.17.0";
312
312
  //#endregion
313
313
  //#region src/serializeError.ts
314
314
  const DEFAULT_MAX_DEPTH = 3;
@@ -307,7 +307,7 @@ function redactMcpToolCredentials(tools) {
307
307
  }
308
308
  //#endregion
309
309
  //#region package.json
310
- var version = "8.16.2";
310
+ var version = "8.17.0";
311
311
  //#endregion
312
312
  //#region src/serializeError.ts
313
313
  const DEFAULT_MAX_DEPTH = 3;
@@ -313,7 +313,7 @@ function redactMcpToolCredentials(tools) {
313
313
  }
314
314
  //#endregion
315
315
  //#region package.json
316
- var version = "8.16.2";
316
+ var version = "8.17.0";
317
317
  //#endregion
318
318
  //#region src/serializeError.ts
319
319
  const DEFAULT_MAX_DEPTH = 3;
@@ -312,7 +312,7 @@ function redactMcpToolCredentials(tools) {
312
312
  }
313
313
  //#endregion
314
314
  //#region package.json
315
- var version = "8.16.2";
315
+ var version = "8.17.0";
316
316
  //#endregion
317
317
  //#region src/serializeError.ts
318
318
  const DEFAULT_MAX_DEPTH = 3;
@@ -552,7 +552,7 @@ function formatOpenAIResponsesInput(input, instructions) {
552
552
  }
553
553
  //#endregion
554
554
  //#region package.json
555
- var version = "8.16.2";
555
+ var version = "8.17.0";
556
556
  //#endregion
557
557
  //#region src/serializeError.ts
558
558
  const DEFAULT_MAX_DEPTH = 3;
@@ -1307,8 +1307,8 @@ var OpenAIChatStreamAccumulator = class {
1307
1307
  if (Array.isArray(choice?.delta?.tool_calls)) {
1308
1308
  this.firstTokenTime ??= receivedAt;
1309
1309
  for (const toolCall of choice.delta.tool_calls) {
1310
- if (toolCall.index === void 0) continue;
1311
- const current = this.toolCalls.get(toolCall.index) ?? {
1310
+ const key = this.toolCallKey(toolCall);
1311
+ const current = this.toolCalls.get(key) ?? {
1312
1312
  id: "",
1313
1313
  name: "",
1314
1314
  arguments: ""
@@ -1316,7 +1316,8 @@ var OpenAIChatStreamAccumulator = class {
1316
1316
  if (toolCall.id) current.id = toolCall.id;
1317
1317
  if (toolCall.function?.name) current.name = toolCall.function.name;
1318
1318
  if (toolCall.function?.arguments) current.arguments += toolCall.function.arguments;
1319
- this.toolCalls.set(toolCall.index, current);
1319
+ this.toolCalls.set(key, current);
1320
+ this.lastToolCallKey = key;
1320
1321
  }
1321
1322
  }
1322
1323
  if (chunk.usage) this.usage = {
@@ -1329,6 +1330,18 @@ var OpenAIChatStreamAccumulator = class {
1329
1330
  rawUsage: chunk.usage
1330
1331
  };
1331
1332
  }
1333
+ /**
1334
+ * Some OpenAI-compatible providers stream tool calls without an `index`. Match those deltas by a known
1335
+ * `id`; a new `id` or a function name opens a new call, and anything else continues the latest call.
1336
+ */
1337
+ toolCallKey(toolCall) {
1338
+ if (toolCall.index !== void 0) return toolCall.index;
1339
+ if (toolCall.id) {
1340
+ for (const [key, existing] of this.toolCalls) if (existing.id === toolCall.id) return key;
1341
+ }
1342
+ if (toolCall.id || toolCall.function?.name || this.lastToolCallKey === void 0) return `no-index-${this.toolCalls.size}`;
1343
+ return this.lastToolCallKey;
1344
+ }
1332
1345
  result() {
1333
1346
  const content = [];
1334
1347
  if (this.accumulatedContent) content.push({