@posthog/ai 8.22.2 → 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/README.md +19 -12
- 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/evaluations/index.cjs +1 -1
- package/dist/evaluations/index.cjs.map +1 -1
- package/dist/evaluations/index.d.ts +1 -1
- package/dist/evaluations/index.mjs +1 -1
- package/dist/evaluations/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +4 -1
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +4 -1
- package/dist/gemini/index.mjs.map +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
|
@@ -440,7 +440,7 @@ function sanitizeValues(obj) {
|
|
|
440
440
|
}
|
|
441
441
|
//#endregion
|
|
442
442
|
//#region package.json
|
|
443
|
-
var version = "8.22.
|
|
443
|
+
var version = "8.22.4";
|
|
444
444
|
//#endregion
|
|
445
445
|
//#region src/serializeError.ts
|
|
446
446
|
const DEFAULT_MAX_DEPTH = 3;
|
|
@@ -634,6 +634,16 @@ function responsesStopReason(response) {
|
|
|
634
634
|
}
|
|
635
635
|
//#endregion
|
|
636
636
|
//#region src/langchain/callbacks.ts
|
|
637
|
+
const CACHE_INCLUSIVE_PROVIDERS = /* @__PURE__ */ new Set([
|
|
638
|
+
"openai",
|
|
639
|
+
"azure",
|
|
640
|
+
"openrouter"
|
|
641
|
+
]);
|
|
642
|
+
const INPUT_OR_CACHE_TOKEN_KEYS = [
|
|
643
|
+
"$ai_input_tokens",
|
|
644
|
+
"$ai_cache_read_input_tokens",
|
|
645
|
+
"$ai_cache_creation_input_tokens"
|
|
646
|
+
];
|
|
637
647
|
const isLangGraphControlFlow = (error) => error.is_bubble_up === true;
|
|
638
648
|
var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.BaseCallbackHandler {
|
|
639
649
|
constructor(options) {
|
|
@@ -928,6 +938,8 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
928
938
|
eventProperties["$ai_cache_creation_5m_input_tokens"] = additionalTokenData.cacheWrite5mInputTokens;
|
|
929
939
|
eventProperties["$ai_cache_creation_1h_input_tokens"] = additionalTokenData.cacheWrite1hInputTokens;
|
|
930
940
|
}
|
|
941
|
+
const callerReportsTokens = INPUT_OR_CACHE_TOKEN_KEYS.some((key) => Object.prototype.hasOwnProperty.call(this.properties, key));
|
|
942
|
+
if (additionalTokenData.cacheReportingExclusive !== void 0 && !callerReportsTokens) eventProperties["$ai_cache_reporting_exclusive"] = additionalTokenData.cacheReportingExclusive;
|
|
931
943
|
if (additionalTokenData.reasoningTokens) eventProperties["$ai_reasoning_tokens"] = additionalTokenData.reasoningTokens;
|
|
932
944
|
if (additionalTokenData.webSearchCount !== void 0) eventProperties["$ai_web_search_count"] = additionalTokenData.webSearchCount;
|
|
933
945
|
const stopReason = this._extractStopReason(output);
|
|
@@ -1079,6 +1091,8 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
1079
1091
|
["completionTokens", "output"],
|
|
1080
1092
|
["input_tokens", "input"],
|
|
1081
1093
|
["output_tokens", "output"],
|
|
1094
|
+
["prompt_tokens", "input"],
|
|
1095
|
+
["completion_tokens", "output"],
|
|
1082
1096
|
["prompt_token_count", "input"],
|
|
1083
1097
|
["candidates_token_count", "output"],
|
|
1084
1098
|
["inputTokenCount", "input"],
|
|
@@ -1133,10 +1147,9 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
1133
1147
|
let isAnthropic = false;
|
|
1134
1148
|
if (provider && provider.toLowerCase() === "anthropic") isAnthropic = true;
|
|
1135
1149
|
else if (model && model.toLowerCase().includes("anthropic")) isAnthropic = true;
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
}
|
|
1150
|
+
const cacheTokens = (additionalTokenData.cacheReadInputTokens || 0) + (additionalTokenData.cacheWriteInputTokens || 0);
|
|
1151
|
+
if (isAnthropic && inputIncludesCacheTokens && parsedUsage.input && cacheTokens > 0) parsedUsage.input = Math.max(parsedUsage.input - cacheTokens, 0);
|
|
1152
|
+
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;
|
|
1140
1153
|
return [
|
|
1141
1154
|
parsedUsage.input,
|
|
1142
1155
|
parsedUsage.output,
|
|
@@ -1149,8 +1162,10 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
1149
1162
|
let normalizedGenerationUsage;
|
|
1150
1163
|
let rawGenerationUsage;
|
|
1151
1164
|
let fallbackGenerationUsage;
|
|
1165
|
+
let generationCount = 0;
|
|
1152
1166
|
for (const generation of response.generations ?? []) for (const genChunk of generation) {
|
|
1153
1167
|
const generationInfo = genChunk.generationInfo ?? {};
|
|
1168
|
+
generationCount++;
|
|
1154
1169
|
const message = "message" in genChunk ? genChunk.message : void 0;
|
|
1155
1170
|
const messageUsage = message && typeof message === "object" && "usage_metadata" in message ? message.usage_metadata : void 0;
|
|
1156
1171
|
normalizedGenerationUsage = firstNonEmptyUsage(normalizedGenerationUsage, messageUsage, generationInfo.usage_metadata);
|
|
@@ -1170,7 +1185,11 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
1170
1185
|
if (response.llmOutput != null) for (const key of llmUsageKeys) {
|
|
1171
1186
|
const llmUsage = response.llmOutput[key];
|
|
1172
1187
|
if (!isNonEmptyUsage(llmUsage)) continue;
|
|
1173
|
-
|
|
1188
|
+
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 ? {
|
|
1189
|
+
...llmUsage,
|
|
1190
|
+
input_token_details: normalizedGenerationUsage.input_token_details
|
|
1191
|
+
} : llmUsage;
|
|
1192
|
+
return this._parseUsageModel(usageWithCacheDetails, provider, model, key !== "usage", llmUsage);
|
|
1174
1193
|
}
|
|
1175
1194
|
if (isNonEmptyUsage(normalizedGenerationUsage)) return this._parseUsageModel(normalizedGenerationUsage, provider, model, true, rawGenerationUsage);
|
|
1176
1195
|
if (isNonEmptyUsage(rawGenerationUsage)) return this._parseUsageModel(rawGenerationUsage, provider, model, false, rawGenerationUsage);
|