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