@posthog/ai 7.18.11 → 7.19.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/dist/anthropic/index.cjs +53 -2
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +53 -2
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +53 -2
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +53 -2
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/index.cjs +55 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +55 -4
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +69 -3
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +69 -3
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/openai/index.cjs +53 -2
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +53 -2
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +1 -1
- package/dist/openai-agents/index.mjs +1 -1
- package/dist/vercel/index.cjs +53 -2
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +53 -2
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/vercel/index.cjs
CHANGED
|
@@ -394,7 +394,58 @@ function sanitizeValues(obj) {
|
|
|
394
394
|
return jsonSafe;
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
var version = "7.
|
|
397
|
+
var version = "7.19.0";
|
|
398
|
+
|
|
399
|
+
const DEFAULT_MAX_DEPTH = 3;
|
|
400
|
+
const MAX_STACK_LINES = 20;
|
|
401
|
+
function serializeError(value, depth = DEFAULT_MAX_DEPTH) {
|
|
402
|
+
if (depth < 0 || value === null || typeof value !== 'object') {
|
|
403
|
+
return value;
|
|
404
|
+
}
|
|
405
|
+
if (value instanceof Error) {
|
|
406
|
+
const out = {
|
|
407
|
+
name: value.name,
|
|
408
|
+
message: value.message,
|
|
409
|
+
stack: truncateStack(value.stack)
|
|
410
|
+
};
|
|
411
|
+
for (const key of Object.keys(value)) {
|
|
412
|
+
out[key] = serializeError(value[key], depth - 1);
|
|
413
|
+
}
|
|
414
|
+
if (value.cause !== undefined) {
|
|
415
|
+
out.cause = serializeError(value.cause, depth - 1);
|
|
416
|
+
}
|
|
417
|
+
return out;
|
|
418
|
+
}
|
|
419
|
+
if (Array.isArray(value)) {
|
|
420
|
+
return value.map(item => serializeError(item, depth - 1));
|
|
421
|
+
}
|
|
422
|
+
return value;
|
|
423
|
+
}
|
|
424
|
+
function stringifyError(error) {
|
|
425
|
+
try {
|
|
426
|
+
return JSON.stringify(sanitizeValues(serializeError(error)));
|
|
427
|
+
} catch {
|
|
428
|
+
if (error instanceof Error) {
|
|
429
|
+
return JSON.stringify({
|
|
430
|
+
name: error.name,
|
|
431
|
+
message: error.message
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
return JSON.stringify({
|
|
435
|
+
message: String(error)
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function truncateStack(stack) {
|
|
440
|
+
if (!stack) {
|
|
441
|
+
return stack;
|
|
442
|
+
}
|
|
443
|
+
const lines = stack.split('\n');
|
|
444
|
+
if (lines.length <= MAX_STACK_LINES) {
|
|
445
|
+
return stack;
|
|
446
|
+
}
|
|
447
|
+
return [...lines.slice(0, MAX_STACK_LINES), '... (truncated)'].join('\n');
|
|
448
|
+
}
|
|
398
449
|
|
|
399
450
|
/**
|
|
400
451
|
* Options for `captureAiGeneration`. Mirrors the `$ai_generation` event shape
|
|
@@ -447,7 +498,7 @@ const captureAiGeneration = async (client, options) => {
|
|
|
447
498
|
}
|
|
448
499
|
errorData = {
|
|
449
500
|
$ai_is_error: true,
|
|
450
|
-
$ai_error:
|
|
501
|
+
$ai_error: stringifyError(options.error),
|
|
451
502
|
$exception_event_id: exceptionId
|
|
452
503
|
};
|
|
453
504
|
}
|