@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/vercel/index.mjs
CHANGED
|
@@ -395,7 +395,7 @@ function sanitizeValues(obj) {
|
|
|
395
395
|
return jsonSafe;
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
-
var version = "8.
|
|
398
|
+
var version = "8.2.0";
|
|
399
399
|
|
|
400
400
|
const DEFAULT_MAX_DEPTH = 3;
|
|
401
401
|
const MAX_STACK_LINES = 20;
|
|
@@ -448,6 +448,44 @@ function truncateStack(stack) {
|
|
|
448
448
|
return [...lines.slice(0, MAX_STACK_LINES), '... (truncated)'].join('\n');
|
|
449
449
|
}
|
|
450
450
|
|
|
451
|
+
// Warn when a wrapper's base_url points at the PostHog AI Gateway: the gateway
|
|
452
|
+
// emits its own $ai_generation, so each call would be captured (and, for billable
|
|
453
|
+
// products, billed) twice. We only warn — the wrapper's event carries data the
|
|
454
|
+
// gateway never sees (groups, custom properties, trace hierarchy).
|
|
455
|
+
|
|
456
|
+
// Keep in sync with the gateway's deployed hosts (see services/llm-gateway in the
|
|
457
|
+
// main repo). gateway.us.posthog.com is live today; the rest are listed ahead of
|
|
458
|
+
// any traffic moving to them.
|
|
459
|
+
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'];
|
|
460
|
+
|
|
461
|
+
// Swap for the dedicated AI Gateway page once it ships.
|
|
462
|
+
const GATEWAY_DOCS_URL = 'https://posthog.com/docs/ai-observability';
|
|
463
|
+
const extractHost = baseURL => {
|
|
464
|
+
try {
|
|
465
|
+
// Tolerate bare hosts that omit a scheme, e.g. "gateway.us.posthog.com/v1".
|
|
466
|
+
const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(baseURL);
|
|
467
|
+
return new URL(hasScheme ? baseURL : `https://${baseURL}`).hostname.toLowerCase();
|
|
468
|
+
} catch {
|
|
469
|
+
return undefined;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
const isPostHogAiGatewayUrl = baseURL => {
|
|
473
|
+
if (!baseURL) {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
const host = extractHost(baseURL);
|
|
477
|
+
return host !== undefined && POSTHOG_AI_GATEWAY_HOSTS.includes(host);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
// Warns on every gateway call by design: the misconfiguration is impossible to
|
|
481
|
+
// miss that way, and a doubled bill is worse than noisy logs.
|
|
482
|
+
const warnIfPostHogAiGateway = baseURL => {
|
|
483
|
+
if (!isPostHogAiGatewayUrl(baseURL)) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
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}.`);
|
|
487
|
+
};
|
|
488
|
+
|
|
451
489
|
/**
|
|
452
490
|
* Options for `captureAiGeneration`. Mirrors the `$ai_generation` event shape
|
|
453
491
|
* directly so that any caller — first-party SDK wrappers and external code
|
|
@@ -471,6 +509,7 @@ const captureAiGeneration = async (client, options) => {
|
|
|
471
509
|
if (!client.capture) {
|
|
472
510
|
return;
|
|
473
511
|
}
|
|
512
|
+
warnIfPostHogAiGateway(options.baseURL);
|
|
474
513
|
const traceId = options.traceId ?? v4();
|
|
475
514
|
const eventType = options.eventType ?? AIEvent.Generation;
|
|
476
515
|
const privacyMode = options.privacyMode ?? false;
|