@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 +2 -2
- package/dist/anthropic/index.cjs +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/gemini/index.cjs +1 -1
- package/dist/gemini/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +1 -1
- package/dist/langchain/index.cjs +1 -1
- package/dist/langchain/index.mjs +1 -1
- package/dist/openai/index.cjs +39 -2
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +39 -2
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +1 -1
- package/dist/openai-agents/index.d.ts +2 -1
- package/dist/openai-agents/index.mjs +1 -1
- package/dist/otel/index.d.ts +2 -1
- package/dist/vercel/index.cjs +1 -1
- package/dist/vercel/index.mjs +1 -1
- package/package.json +5 -5
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
|
package/dist/anthropic/index.cjs
CHANGED
package/dist/anthropic/index.mjs
CHANGED
package/dist/gemini/index.cjs
CHANGED
package/dist/gemini/index.mjs
CHANGED
package/dist/index.cjs
CHANGED
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,
|
|
249
|
+
export { AIEvent, Prompts, captureAiGeneration, wrapVercelLanguageModel as withTracing };
|
|
250
|
+
export type { CaptureAiGenerationOptions, PromptCodeFallbackResult, PromptRemoteResult, PromptResult };
|
package/dist/index.mjs
CHANGED
package/dist/langchain/index.cjs
CHANGED
package/dist/langchain/index.mjs
CHANGED
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.3.
|
|
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.
|