@posthog/ai 7.18.12 → 7.19.1
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 +4 -4
package/dist/openai/index.mjs
CHANGED
|
@@ -530,7 +530,58 @@ function formatOpenAIResponsesInput(input, instructions) {
|
|
|
530
530
|
return messages;
|
|
531
531
|
}
|
|
532
532
|
|
|
533
|
-
var version = "7.
|
|
533
|
+
var version = "7.19.1";
|
|
534
|
+
|
|
535
|
+
const DEFAULT_MAX_DEPTH = 3;
|
|
536
|
+
const MAX_STACK_LINES = 20;
|
|
537
|
+
function serializeError(value, depth = DEFAULT_MAX_DEPTH) {
|
|
538
|
+
if (depth < 0 || value === null || typeof value !== 'object') {
|
|
539
|
+
return value;
|
|
540
|
+
}
|
|
541
|
+
if (value instanceof Error) {
|
|
542
|
+
const out = {
|
|
543
|
+
name: value.name,
|
|
544
|
+
message: value.message,
|
|
545
|
+
stack: truncateStack(value.stack)
|
|
546
|
+
};
|
|
547
|
+
for (const key of Object.keys(value)) {
|
|
548
|
+
out[key] = serializeError(value[key], depth - 1);
|
|
549
|
+
}
|
|
550
|
+
if (value.cause !== undefined) {
|
|
551
|
+
out.cause = serializeError(value.cause, depth - 1);
|
|
552
|
+
}
|
|
553
|
+
return out;
|
|
554
|
+
}
|
|
555
|
+
if (Array.isArray(value)) {
|
|
556
|
+
return value.map(item => serializeError(item, depth - 1));
|
|
557
|
+
}
|
|
558
|
+
return value;
|
|
559
|
+
}
|
|
560
|
+
function stringifyError(error) {
|
|
561
|
+
try {
|
|
562
|
+
return JSON.stringify(sanitizeValues(serializeError(error)));
|
|
563
|
+
} catch {
|
|
564
|
+
if (error instanceof Error) {
|
|
565
|
+
return JSON.stringify({
|
|
566
|
+
name: error.name,
|
|
567
|
+
message: error.message
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
return JSON.stringify({
|
|
571
|
+
message: String(error)
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
function truncateStack(stack) {
|
|
576
|
+
if (!stack) {
|
|
577
|
+
return stack;
|
|
578
|
+
}
|
|
579
|
+
const lines = stack.split('\n');
|
|
580
|
+
if (lines.length <= MAX_STACK_LINES) {
|
|
581
|
+
return stack;
|
|
582
|
+
}
|
|
583
|
+
return [...lines.slice(0, MAX_STACK_LINES), '... (truncated)'].join('\n');
|
|
584
|
+
}
|
|
534
585
|
|
|
535
586
|
/**
|
|
536
587
|
* Options for `captureAiGeneration`. Mirrors the `$ai_generation` event shape
|
|
@@ -583,7 +634,7 @@ const captureAiGeneration = async (client, options) => {
|
|
|
583
634
|
}
|
|
584
635
|
errorData = {
|
|
585
636
|
$ai_is_error: true,
|
|
586
|
-
$ai_error:
|
|
637
|
+
$ai_error: stringifyError(options.error),
|
|
587
638
|
$exception_event_id: exceptionId
|
|
588
639
|
};
|
|
589
640
|
}
|