@posthog/ai 8.2.1 → 8.2.2

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.
@@ -299,7 +299,7 @@ function addDefaults(params) {
299
299
  };
300
300
  }
301
301
 
302
- var version = "8.2.1";
302
+ var version = "8.2.2";
303
303
 
304
304
  const DEFAULT_MAX_DEPTH = 3;
305
305
  const MAX_STACK_LINES = 20;
@@ -291,7 +291,7 @@ function addDefaults(params) {
291
291
  };
292
292
  }
293
293
 
294
- var version = "8.2.1";
294
+ var version = "8.2.2";
295
295
 
296
296
  const DEFAULT_MAX_DEPTH = 3;
297
297
  const MAX_STACK_LINES = 20;
@@ -384,7 +384,7 @@ function addDefaults(params) {
384
384
  };
385
385
  }
386
386
 
387
- var version = "8.2.1";
387
+ var version = "8.2.2";
388
388
 
389
389
  const DEFAULT_MAX_DEPTH = 3;
390
390
  const MAX_STACK_LINES = 20;
@@ -380,7 +380,7 @@ function addDefaults(params) {
380
380
  };
381
381
  }
382
382
 
383
- var version = "8.2.1";
383
+ var version = "8.2.2";
384
384
 
385
385
  const DEFAULT_MAX_DEPTH = 3;
386
386
  const MAX_STACK_LINES = 20;
package/dist/index.cjs CHANGED
@@ -380,7 +380,7 @@ function sanitizeValues(obj) {
380
380
  return jsonSafe;
381
381
  }
382
382
 
383
- var version = "8.2.1";
383
+ var version = "8.2.2";
384
384
 
385
385
  const DEFAULT_MAX_DEPTH = 3;
386
386
  const MAX_STACK_LINES = 20;
package/dist/index.mjs CHANGED
@@ -378,7 +378,7 @@ function sanitizeValues(obj) {
378
378
  return jsonSafe;
379
379
  }
380
380
 
381
- var version = "8.2.1";
381
+ var version = "8.2.2";
382
382
 
383
383
  const DEFAULT_MAX_DEPTH = 3;
384
384
  const MAX_STACK_LINES = 20;
@@ -217,7 +217,7 @@ function sanitizeValues(obj) {
217
217
  return jsonSafe;
218
218
  }
219
219
 
220
- var version = "8.2.1";
220
+ var version = "8.2.2";
221
221
 
222
222
  const DEFAULT_MAX_DEPTH = 3;
223
223
  const MAX_STACK_LINES = 20;
@@ -215,7 +215,7 @@ function sanitizeValues(obj) {
215
215
  return jsonSafe;
216
216
  }
217
217
 
218
- var version = "8.2.1";
218
+ var version = "8.2.2";
219
219
 
220
220
  const DEFAULT_MAX_DEPTH = 3;
221
221
  const MAX_STACK_LINES = 20;
@@ -534,7 +534,7 @@ function formatOpenAIResponsesInput(input, instructions) {
534
534
  return messages;
535
535
  }
536
536
 
537
- var version = "8.2.1";
537
+ var version = "8.2.2";
538
538
 
539
539
  const DEFAULT_MAX_DEPTH = 3;
540
540
  const MAX_STACK_LINES = 20;
@@ -1359,6 +1359,10 @@ function preserveAPIPromiseHelpers(parentPromise, wrappedPromise) {
1359
1359
  }
1360
1360
  return apiPromise;
1361
1361
  }
1362
+ const TERMINAL_RESPONSE_STATUSES = new Set(['completed', 'failed', 'cancelled', 'incomplete']);
1363
+ function isPendingBackgroundResponse(params, response) {
1364
+ return params.background === true && !response.usage && !!response.status && !TERMINAL_RESPONSE_STATUSES.has(response.status);
1365
+ }
1362
1366
  class PostHogOpenAI extends openai.OpenAI {
1363
1367
  constructor(config) {
1364
1368
  const {
@@ -1784,6 +1788,9 @@ class WrappedResponses extends Responses {
1784
1788
  } else {
1785
1789
  const wrappedPromise = parentPromise.then(async result => {
1786
1790
  if ('output' in result) {
1791
+ if (isPendingBackgroundResponse(openAIParams, result)) {
1792
+ return result;
1793
+ }
1787
1794
  const latency = (Date.now() - startTime) / 1000;
1788
1795
  const availableTools = extractAvailableToolCalls('openai', openAIParams);
1789
1796
  const formattedOutput = formatResponseOpenAI({
@@ -1852,6 +1859,9 @@ class WrappedResponses extends Responses {
1852
1859
  try {
1853
1860
  const parentPromise = super.parse(openAIParams, options);
1854
1861
  const wrappedPromise = parentPromise.then(async result => {
1862
+ if (isPendingBackgroundResponse(openAIParams, result)) {
1863
+ return result;
1864
+ }
1855
1865
  const latency = (Date.now() - startTime) / 1000;
1856
1866
  await captureAiGeneration(this.phClient, {
1857
1867
  ...posthogParams,