@posthog/ai 8.3.0 → 8.3.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/LICENSE CHANGED
@@ -327,12 +327,12 @@ SOFTWARE.
327
327
 
328
328
  ---
329
329
 
330
- Some files in this codebase contain code from MCPCat/mcpcat-typescript-sdk.
330
+ Some files in this codebase contain code from agentcathq/agentcat-typescript-sdk (formerly MCPCat/mcpcat-typescript-sdk).
331
331
  In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
332
332
 
333
333
  MIT License
334
334
 
335
- Copyright (c) 2025 MCPcat
335
+ Copyright (c) 2025 AgentCat, Inc. (formerly MCPcat)
336
336
 
337
337
  Permission is hereby granted, free of charge, to any person obtaining a copy
338
338
  of this software and associated documentation files (the "Software"), to deal
@@ -299,7 +299,7 @@ function addDefaults(params) {
299
299
  };
300
300
  }
301
301
 
302
- var version = "8.3.0";
302
+ var version = "8.3.1";
303
303
 
304
304
  const DEFAULT_MAX_DEPTH = 3;
305
305
  const MAX_STACK_LINES = 20;
@@ -291,7 +291,7 @@ function addDefaults(params) {
291
291
  };
292
292
  }
293
293
 
294
- var version = "8.3.0";
294
+ var version = "8.3.1";
295
295
 
296
296
  const DEFAULT_MAX_DEPTH = 3;
297
297
  const MAX_STACK_LINES = 20;
@@ -384,7 +384,7 @@ function addDefaults(params) {
384
384
  };
385
385
  }
386
386
 
387
- var version = "8.3.0";
387
+ var version = "8.3.1";
388
388
 
389
389
  const DEFAULT_MAX_DEPTH = 3;
390
390
  const MAX_STACK_LINES = 20;
@@ -380,7 +380,7 @@ function addDefaults(params) {
380
380
  };
381
381
  }
382
382
 
383
- var version = "8.3.0";
383
+ var version = "8.3.1";
384
384
 
385
385
  const DEFAULT_MAX_DEPTH = 3;
386
386
  const MAX_STACK_LINES = 20;
package/dist/index.cjs CHANGED
@@ -380,7 +380,7 @@ function sanitizeValues(obj) {
380
380
  return jsonSafe;
381
381
  }
382
382
 
383
- var version = "8.3.0";
383
+ var version = "8.3.1";
384
384
 
385
385
  const DEFAULT_MAX_DEPTH = 3;
386
386
  const MAX_STACK_LINES = 20;
package/dist/index.d.ts CHANGED
@@ -246,4 +246,5 @@ interface CaptureAiGenerationOptions {
246
246
  */
247
247
  declare const captureAiGeneration: (client: PostHog, options: CaptureAiGenerationOptions) => Promise<void>;
248
248
 
249
- export { AIEvent, type CaptureAiGenerationOptions, type PromptCodeFallbackResult, type PromptRemoteResult, type PromptResult, Prompts, captureAiGeneration, wrapVercelLanguageModel as withTracing };
249
+ export { AIEvent, Prompts, captureAiGeneration, wrapVercelLanguageModel as withTracing };
250
+ export type { CaptureAiGenerationOptions, PromptCodeFallbackResult, PromptRemoteResult, PromptResult };
package/dist/index.mjs CHANGED
@@ -378,7 +378,7 @@ function sanitizeValues(obj) {
378
378
  return jsonSafe;
379
379
  }
380
380
 
381
- var version = "8.3.0";
381
+ var version = "8.3.1";
382
382
 
383
383
  const DEFAULT_MAX_DEPTH = 3;
384
384
  const MAX_STACK_LINES = 20;
@@ -217,7 +217,7 @@ function sanitizeValues(obj) {
217
217
  return jsonSafe;
218
218
  }
219
219
 
220
- var version = "8.3.0";
220
+ var version = "8.3.1";
221
221
 
222
222
  const DEFAULT_MAX_DEPTH = 3;
223
223
  const MAX_STACK_LINES = 20;
@@ -215,7 +215,7 @@ function sanitizeValues(obj) {
215
215
  return jsonSafe;
216
216
  }
217
217
 
218
- var version = "8.3.0";
218
+ var version = "8.3.1";
219
219
 
220
220
  const DEFAULT_MAX_DEPTH = 3;
221
221
  const MAX_STACK_LINES = 20;
@@ -534,7 +534,7 @@ function formatOpenAIResponsesInput(input, instructions) {
534
534
  return messages;
535
535
  }
536
536
 
537
- var version = "8.3.0";
537
+ var version = "8.3.1";
538
538
 
539
539
  const DEFAULT_MAX_DEPTH = 3;
540
540
  const MAX_STACK_LINES = 20;
@@ -644,7 +644,7 @@ const warnIfPostHogAiGateway = baseURL => {
644
644
  * object, it is mutated in place to set `__posthog_previously_captured_error`
645
645
  * so callers can re-throw the original error reference safely.
646
646
  */
647
- const captureAiGeneration = async (client, options) => {
647
+ const captureAiGeneration$1 = async (client, options) => {
648
648
  if (!client.capture) {
649
649
  return;
650
650
  }
@@ -762,6 +762,43 @@ const captureAiGeneration = async (client, options) => {
762
762
  }
763
763
  };
764
764
 
765
+ /**
766
+ * The declared convention only describes the wrapper's own usage numbers, so
767
+ * when the caller passes any of these through posthogProperties the wrapper no
768
+ * longer knows the convention of the reported counts (callers working around
769
+ * the double-billing already pass exclusive ones) and must not declare it.
770
+ * Output/reasoning token overrides don't affect the input/cache relationship,
771
+ * so they don't suppress the declaration. Subset of the input/cache keys in
772
+ * `TOKEN_PROPERTY_KEYS` (../utils.ts) — keep in sync if that taxonomy grows.
773
+ */
774
+ const INPUT_OR_CACHE_TOKEN_KEYS = ['$ai_input_tokens', '$ai_cache_read_input_tokens', '$ai_cache_creation_input_tokens'];
775
+
776
+ /**
777
+ * OpenAI-compatible usage reports `prompt_tokens` INCLUSIVE of cached tokens
778
+ * (`prompt_tokens_details.cached_tokens` is a subset of it), unlike Anthropic's
779
+ * exclusive convention. Ingestion auto-classifies Claude-shaped models as
780
+ * exclusive regardless of provider, so events for Claude served through
781
+ * OpenAI-compatible hosts (e.g. OpenRouter) would get cache reads billed twice.
782
+ * Declaring the convention on every event from this wrapper lets ingestion
783
+ * normalize correctly (see PostHog/posthog#49252); for non-Claude models the
784
+ * flag is a no-op. Callers can still override it via posthogProperties, and
785
+ * when they pass through input or cache token counts themselves the flag stays
786
+ * unset unless they declare it explicitly.
787
+ */
788
+ const captureAiGeneration = (client, options) => {
789
+ const props = options.properties;
790
+ // Own-property check, matching how getTokensSource detects passthrough and
791
+ // how the properties spread actually copies values into the event.
792
+ const callerReportsTokens = props !== undefined && INPUT_OR_CACHE_TOKEN_KEYS.some(key => Object.prototype.hasOwnProperty.call(props, key));
793
+ return captureAiGeneration$1(client, {
794
+ ...options,
795
+ properties: callerReportsTokens ? props : {
796
+ $ai_cache_reporting_exclusive: false,
797
+ ...props
798
+ }
799
+ });
800
+ };
801
+
765
802
  /**
766
803
  * Checks if a ResponseStreamEvent chunk represents the first token/content from the model.
767
804
  * This includes various content types like text, reasoning, audio, and refusals.