@posthog/ai 8.1.11 → 8.2.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 +40 -1
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +40 -1
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +40 -1
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +40 -1
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/index.cjs +37 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +37 -1
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +40 -1
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +40 -1
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/openai/index.cjs +40 -1
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +40 -1
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +42 -1
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.mjs +42 -1
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/otel/index.cjs +60 -0
- package/dist/otel/index.cjs.map +1 -1
- package/dist/otel/index.mjs +60 -0
- package/dist/otel/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +40 -1
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +40 -1
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/openai/index.cjs
CHANGED
|
@@ -534,7 +534,7 @@ function formatOpenAIResponsesInput(input, instructions) {
|
|
|
534
534
|
return messages;
|
|
535
535
|
}
|
|
536
536
|
|
|
537
|
-
var version = "8.
|
|
537
|
+
var version = "8.2.0";
|
|
538
538
|
|
|
539
539
|
const DEFAULT_MAX_DEPTH = 3;
|
|
540
540
|
const MAX_STACK_LINES = 20;
|
|
@@ -587,6 +587,44 @@ function truncateStack(stack) {
|
|
|
587
587
|
return [...lines.slice(0, MAX_STACK_LINES), '... (truncated)'].join('\n');
|
|
588
588
|
}
|
|
589
589
|
|
|
590
|
+
// Warn when a wrapper's base_url points at the PostHog AI Gateway: the gateway
|
|
591
|
+
// emits its own $ai_generation, so each call would be captured (and, for billable
|
|
592
|
+
// products, billed) twice. We only warn — the wrapper's event carries data the
|
|
593
|
+
// gateway never sees (groups, custom properties, trace hierarchy).
|
|
594
|
+
|
|
595
|
+
// Keep in sync with the gateway's deployed hosts (see services/llm-gateway in the
|
|
596
|
+
// main repo). gateway.us.posthog.com is live today; the rest are listed ahead of
|
|
597
|
+
// any traffic moving to them.
|
|
598
|
+
const POSTHOG_AI_GATEWAY_HOSTS = ['gateway.posthog.com', 'gateway.us.posthog.com', 'gateway.eu.posthog.com', 'ai-gateway.us.posthog.com', 'ai-gateway.eu.posthog.com'];
|
|
599
|
+
|
|
600
|
+
// Swap for the dedicated AI Gateway page once it ships.
|
|
601
|
+
const GATEWAY_DOCS_URL = 'https://posthog.com/docs/ai-observability';
|
|
602
|
+
const extractHost = baseURL => {
|
|
603
|
+
try {
|
|
604
|
+
// Tolerate bare hosts that omit a scheme, e.g. "gateway.us.posthog.com/v1".
|
|
605
|
+
const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(baseURL);
|
|
606
|
+
return new URL(hasScheme ? baseURL : `https://${baseURL}`).hostname.toLowerCase();
|
|
607
|
+
} catch {
|
|
608
|
+
return undefined;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
const isPostHogAiGatewayUrl = baseURL => {
|
|
612
|
+
if (!baseURL) {
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
const host = extractHost(baseURL);
|
|
616
|
+
return host !== undefined && POSTHOG_AI_GATEWAY_HOSTS.includes(host);
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
// Warns on every gateway call by design: the misconfiguration is impossible to
|
|
620
|
+
// miss that way, and a doubled bill is worse than noisy logs.
|
|
621
|
+
const warnIfPostHogAiGateway = baseURL => {
|
|
622
|
+
if (!isPostHogAiGatewayUrl(baseURL)) {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
console.warn('[PostHog] The PostHog AI wrapper is pointed at the PostHog AI Gateway. ' + 'Both capture $ai_generation, so every call is double-counted and double-billed. ' + `Use one or the other — see ${GATEWAY_DOCS_URL}.`);
|
|
626
|
+
};
|
|
627
|
+
|
|
590
628
|
/**
|
|
591
629
|
* Options for `captureAiGeneration`. Mirrors the `$ai_generation` event shape
|
|
592
630
|
* directly so that any caller — first-party SDK wrappers and external code
|
|
@@ -610,6 +648,7 @@ const captureAiGeneration = async (client, options) => {
|
|
|
610
648
|
if (!client.capture) {
|
|
611
649
|
return;
|
|
612
650
|
}
|
|
651
|
+
warnIfPostHogAiGateway(options.baseURL);
|
|
613
652
|
const traceId = options.traceId ?? uuid.v4();
|
|
614
653
|
const eventType = options.eventType ?? AIEvent.Generation;
|
|
615
654
|
const privacyMode = options.privacyMode ?? false;
|