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