@posthog/ai 8.22.3 → 8.22.4
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/adk/index.cjs +1 -1
- package/dist/adk/index.mjs +1 -1
- package/dist/anthropic/index.cjs +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/claude-agent-sdk/index.cjs +1 -1
- package/dist/claude-agent-sdk/index.mjs +1 -1
- package/dist/gemini/index.cjs +1 -1
- package/dist/gemini/index.mjs +1 -1
- package/dist/genkit/index.cjs +1 -1
- package/dist/genkit/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/langchain/index.cjs +25 -6
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +25 -6
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/langchain/middleware/index.cjs +25 -6
- package/dist/langchain/middleware/index.cjs.map +1 -1
- package/dist/langchain/middleware/index.mjs +25 -6
- package/dist/langchain/middleware/index.mjs.map +1 -1
- package/dist/openai/index.cjs +1 -1
- package/dist/openai/index.mjs +1 -1
- package/dist/openai-agents/index.cjs +1 -1
- package/dist/openai-agents/index.mjs +1 -1
- package/dist/vercel/index.cjs +1 -1
- package/dist/vercel/index.mjs +1 -1
- package/package.json +2 -2
package/dist/adk/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ let _google_adk = require("@google/adk");
|
|
|
3
3
|
let uuid = require("uuid");
|
|
4
4
|
let _posthog_core = require("@posthog/core");
|
|
5
5
|
//#region package.json
|
|
6
|
-
var version = "8.22.
|
|
6
|
+
var version = "8.22.4";
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/typeGuards.ts
|
|
9
9
|
const isObject = (value) => {
|
package/dist/adk/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { BasePlugin } from "@google/adk";
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { acceptsEventOptions, eventOptionsAsLegacyProperties, toJsonSafeValue, uuidv7 } from "@posthog/core";
|
|
4
4
|
//#region package.json
|
|
5
|
-
var version = "8.22.
|
|
5
|
+
var version = "8.22.4";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/typeGuards.ts
|
|
8
8
|
const isObject = (value) => {
|
package/dist/anthropic/index.cjs
CHANGED
package/dist/anthropic/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ let _anthropic_ai_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
|
|
|
3
3
|
let uuid = require("uuid");
|
|
4
4
|
let _posthog_core = require("@posthog/core");
|
|
5
5
|
//#region package.json
|
|
6
|
-
var version = "8.22.
|
|
6
|
+
var version = "8.22.4";
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/captureAiEvent.ts
|
|
9
9
|
/** @internal */
|
|
@@ -2,7 +2,7 @@ import { SYSTEM_PROMPT_DYNAMIC_BOUNDARY, query as query$1 } from "@anthropic-ai/
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { acceptsEventOptions, eventOptionsAsLegacyProperties, toJsonSafeValue, uuidv7 } from "@posthog/core";
|
|
4
4
|
//#region package.json
|
|
5
|
-
var version = "8.22.
|
|
5
|
+
var version = "8.22.4";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/captureAiEvent.ts
|
|
8
8
|
/** @internal */
|
package/dist/gemini/index.cjs
CHANGED
package/dist/gemini/index.mjs
CHANGED
package/dist/genkit/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
let _posthog_core = require("@posthog/core");
|
|
3
3
|
let uuid = require("uuid");
|
|
4
4
|
//#region package.json
|
|
5
|
-
var version = "8.22.
|
|
5
|
+
var version = "8.22.4";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/captureAiEvent.ts
|
|
8
8
|
/** @internal */
|
package/dist/genkit/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { acceptsEventOptions, eventOptionsAsLegacyProperties, toJsonSafeValue, uuidv7 } from "@posthog/core";
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
//#region package.json
|
|
4
|
-
var version = "8.22.
|
|
4
|
+
var version = "8.22.4";
|
|
5
5
|
//#endregion
|
|
6
6
|
//#region src/captureAiEvent.ts
|
|
7
7
|
/** @internal */
|
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED
package/dist/langchain/index.cjs
CHANGED
|
@@ -435,7 +435,7 @@ function sanitizeValues(obj) {
|
|
|
435
435
|
}
|
|
436
436
|
//#endregion
|
|
437
437
|
//#region package.json
|
|
438
|
-
var version = "8.22.
|
|
438
|
+
var version = "8.22.4";
|
|
439
439
|
//#endregion
|
|
440
440
|
//#region src/serializeError.ts
|
|
441
441
|
const DEFAULT_MAX_DEPTH = 3;
|
|
@@ -629,6 +629,16 @@ function responsesStopReason(response) {
|
|
|
629
629
|
}
|
|
630
630
|
//#endregion
|
|
631
631
|
//#region src/langchain/callbacks.ts
|
|
632
|
+
const CACHE_INCLUSIVE_PROVIDERS = /* @__PURE__ */ new Set([
|
|
633
|
+
"openai",
|
|
634
|
+
"azure",
|
|
635
|
+
"openrouter"
|
|
636
|
+
]);
|
|
637
|
+
const INPUT_OR_CACHE_TOKEN_KEYS = [
|
|
638
|
+
"$ai_input_tokens",
|
|
639
|
+
"$ai_cache_read_input_tokens",
|
|
640
|
+
"$ai_cache_creation_input_tokens"
|
|
641
|
+
];
|
|
632
642
|
const isLangGraphControlFlow = (error) => error.is_bubble_up === true;
|
|
633
643
|
var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.BaseCallbackHandler {
|
|
634
644
|
constructor(options) {
|
|
@@ -923,6 +933,8 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
923
933
|
eventProperties["$ai_cache_creation_5m_input_tokens"] = additionalTokenData.cacheWrite5mInputTokens;
|
|
924
934
|
eventProperties["$ai_cache_creation_1h_input_tokens"] = additionalTokenData.cacheWrite1hInputTokens;
|
|
925
935
|
}
|
|
936
|
+
const callerReportsTokens = INPUT_OR_CACHE_TOKEN_KEYS.some((key) => Object.prototype.hasOwnProperty.call(this.properties, key));
|
|
937
|
+
if (additionalTokenData.cacheReportingExclusive !== void 0 && !callerReportsTokens) eventProperties["$ai_cache_reporting_exclusive"] = additionalTokenData.cacheReportingExclusive;
|
|
926
938
|
if (additionalTokenData.reasoningTokens) eventProperties["$ai_reasoning_tokens"] = additionalTokenData.reasoningTokens;
|
|
927
939
|
if (additionalTokenData.webSearchCount !== void 0) eventProperties["$ai_web_search_count"] = additionalTokenData.webSearchCount;
|
|
928
940
|
const stopReason = this._extractStopReason(output);
|
|
@@ -1074,6 +1086,8 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
1074
1086
|
["completionTokens", "output"],
|
|
1075
1087
|
["input_tokens", "input"],
|
|
1076
1088
|
["output_tokens", "output"],
|
|
1089
|
+
["prompt_tokens", "input"],
|
|
1090
|
+
["completion_tokens", "output"],
|
|
1077
1091
|
["prompt_token_count", "input"],
|
|
1078
1092
|
["candidates_token_count", "output"],
|
|
1079
1093
|
["inputTokenCount", "input"],
|
|
@@ -1128,10 +1142,9 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
1128
1142
|
let isAnthropic = false;
|
|
1129
1143
|
if (provider && provider.toLowerCase() === "anthropic") isAnthropic = true;
|
|
1130
1144
|
else if (model && model.toLowerCase().includes("anthropic")) isAnthropic = true;
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
}
|
|
1145
|
+
const cacheTokens = (additionalTokenData.cacheReadInputTokens || 0) + (additionalTokenData.cacheWriteInputTokens || 0);
|
|
1146
|
+
if (isAnthropic && inputIncludesCacheTokens && parsedUsage.input && cacheTokens > 0) parsedUsage.input = Math.max(parsedUsage.input - cacheTokens, 0);
|
|
1147
|
+
if (!isAnthropic && (usage.prompt_tokens != null || inputIncludesCacheTokens && usage.cache_read_input_tokens == null && usage.cache_creation_input_tokens == null) && cacheTokens > 0 && parsedUsage.input >= cacheTokens && provider && CACHE_INCLUSIVE_PROVIDERS.has(provider.toLowerCase())) additionalTokenData.cacheReportingExclusive = false;
|
|
1135
1148
|
return [
|
|
1136
1149
|
parsedUsage.input,
|
|
1137
1150
|
parsedUsage.output,
|
|
@@ -1144,8 +1157,10 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
1144
1157
|
let normalizedGenerationUsage;
|
|
1145
1158
|
let rawGenerationUsage;
|
|
1146
1159
|
let fallbackGenerationUsage;
|
|
1160
|
+
let generationCount = 0;
|
|
1147
1161
|
for (const generation of response.generations ?? []) for (const genChunk of generation) {
|
|
1148
1162
|
const generationInfo = genChunk.generationInfo ?? {};
|
|
1163
|
+
generationCount++;
|
|
1149
1164
|
const message = "message" in genChunk ? genChunk.message : void 0;
|
|
1150
1165
|
const messageUsage = message && typeof message === "object" && "usage_metadata" in message ? message.usage_metadata : void 0;
|
|
1151
1166
|
normalizedGenerationUsage = firstNonEmptyUsage(normalizedGenerationUsage, messageUsage, generationInfo.usage_metadata);
|
|
@@ -1165,7 +1180,11 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
1165
1180
|
if (response.llmOutput != null) for (const key of llmUsageKeys) {
|
|
1166
1181
|
const llmUsage = response.llmOutput[key];
|
|
1167
1182
|
if (!isNonEmptyUsage(llmUsage)) continue;
|
|
1168
|
-
|
|
1183
|
+
const usageWithCacheDetails = key !== "usage" && generationCount === 1 && llmUsage.input_token_details == null && normalizedGenerationUsage?.input_token_details != null && (llmUsage.promptTokens ?? llmUsage.prompt_tokens ?? llmUsage.input_tokens) === normalizedGenerationUsage.input_tokens ? {
|
|
1184
|
+
...llmUsage,
|
|
1185
|
+
input_token_details: normalizedGenerationUsage.input_token_details
|
|
1186
|
+
} : llmUsage;
|
|
1187
|
+
return this._parseUsageModel(usageWithCacheDetails, provider, model, key !== "usage", llmUsage);
|
|
1169
1188
|
}
|
|
1170
1189
|
if (isNonEmptyUsage(normalizedGenerationUsage)) return this._parseUsageModel(normalizedGenerationUsage, provider, model, true, rawGenerationUsage);
|
|
1171
1190
|
if (isNonEmptyUsage(rawGenerationUsage)) return this._parseUsageModel(rawGenerationUsage, provider, model, false, rawGenerationUsage);
|