@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/langchain/index.mjs
CHANGED
|
@@ -434,7 +434,7 @@ function sanitizeValues(obj) {
|
|
|
434
434
|
}
|
|
435
435
|
//#endregion
|
|
436
436
|
//#region package.json
|
|
437
|
-
var version = "8.22.
|
|
437
|
+
var version = "8.22.4";
|
|
438
438
|
//#endregion
|
|
439
439
|
//#region src/serializeError.ts
|
|
440
440
|
const DEFAULT_MAX_DEPTH = 3;
|
|
@@ -628,6 +628,16 @@ function responsesStopReason(response) {
|
|
|
628
628
|
}
|
|
629
629
|
//#endregion
|
|
630
630
|
//#region src/langchain/callbacks.ts
|
|
631
|
+
const CACHE_INCLUSIVE_PROVIDERS = /* @__PURE__ */ new Set([
|
|
632
|
+
"openai",
|
|
633
|
+
"azure",
|
|
634
|
+
"openrouter"
|
|
635
|
+
]);
|
|
636
|
+
const INPUT_OR_CACHE_TOKEN_KEYS = [
|
|
637
|
+
"$ai_input_tokens",
|
|
638
|
+
"$ai_cache_read_input_tokens",
|
|
639
|
+
"$ai_cache_creation_input_tokens"
|
|
640
|
+
];
|
|
631
641
|
const isLangGraphControlFlow = (error) => error.is_bubble_up === true;
|
|
632
642
|
var LangChainCallbackHandler = class extends BaseCallbackHandler {
|
|
633
643
|
constructor(options) {
|
|
@@ -922,6 +932,8 @@ var LangChainCallbackHandler = class extends BaseCallbackHandler {
|
|
|
922
932
|
eventProperties["$ai_cache_creation_5m_input_tokens"] = additionalTokenData.cacheWrite5mInputTokens;
|
|
923
933
|
eventProperties["$ai_cache_creation_1h_input_tokens"] = additionalTokenData.cacheWrite1hInputTokens;
|
|
924
934
|
}
|
|
935
|
+
const callerReportsTokens = INPUT_OR_CACHE_TOKEN_KEYS.some((key) => Object.prototype.hasOwnProperty.call(this.properties, key));
|
|
936
|
+
if (additionalTokenData.cacheReportingExclusive !== void 0 && !callerReportsTokens) eventProperties["$ai_cache_reporting_exclusive"] = additionalTokenData.cacheReportingExclusive;
|
|
925
937
|
if (additionalTokenData.reasoningTokens) eventProperties["$ai_reasoning_tokens"] = additionalTokenData.reasoningTokens;
|
|
926
938
|
if (additionalTokenData.webSearchCount !== void 0) eventProperties["$ai_web_search_count"] = additionalTokenData.webSearchCount;
|
|
927
939
|
const stopReason = this._extractStopReason(output);
|
|
@@ -1073,6 +1085,8 @@ var LangChainCallbackHandler = class extends BaseCallbackHandler {
|
|
|
1073
1085
|
["completionTokens", "output"],
|
|
1074
1086
|
["input_tokens", "input"],
|
|
1075
1087
|
["output_tokens", "output"],
|
|
1088
|
+
["prompt_tokens", "input"],
|
|
1089
|
+
["completion_tokens", "output"],
|
|
1076
1090
|
["prompt_token_count", "input"],
|
|
1077
1091
|
["candidates_token_count", "output"],
|
|
1078
1092
|
["inputTokenCount", "input"],
|
|
@@ -1127,10 +1141,9 @@ var LangChainCallbackHandler = class extends BaseCallbackHandler {
|
|
|
1127
1141
|
let isAnthropic = false;
|
|
1128
1142
|
if (provider && provider.toLowerCase() === "anthropic") isAnthropic = true;
|
|
1129
1143
|
else if (model && model.toLowerCase().includes("anthropic")) isAnthropic = true;
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1144
|
+
const cacheTokens = (additionalTokenData.cacheReadInputTokens || 0) + (additionalTokenData.cacheWriteInputTokens || 0);
|
|
1145
|
+
if (isAnthropic && inputIncludesCacheTokens && parsedUsage.input && cacheTokens > 0) parsedUsage.input = Math.max(parsedUsage.input - cacheTokens, 0);
|
|
1146
|
+
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;
|
|
1134
1147
|
return [
|
|
1135
1148
|
parsedUsage.input,
|
|
1136
1149
|
parsedUsage.output,
|
|
@@ -1143,8 +1156,10 @@ var LangChainCallbackHandler = class extends BaseCallbackHandler {
|
|
|
1143
1156
|
let normalizedGenerationUsage;
|
|
1144
1157
|
let rawGenerationUsage;
|
|
1145
1158
|
let fallbackGenerationUsage;
|
|
1159
|
+
let generationCount = 0;
|
|
1146
1160
|
for (const generation of response.generations ?? []) for (const genChunk of generation) {
|
|
1147
1161
|
const generationInfo = genChunk.generationInfo ?? {};
|
|
1162
|
+
generationCount++;
|
|
1148
1163
|
const message = "message" in genChunk ? genChunk.message : void 0;
|
|
1149
1164
|
const messageUsage = message && typeof message === "object" && "usage_metadata" in message ? message.usage_metadata : void 0;
|
|
1150
1165
|
normalizedGenerationUsage = firstNonEmptyUsage(normalizedGenerationUsage, messageUsage, generationInfo.usage_metadata);
|
|
@@ -1164,7 +1179,11 @@ var LangChainCallbackHandler = class extends BaseCallbackHandler {
|
|
|
1164
1179
|
if (response.llmOutput != null) for (const key of llmUsageKeys) {
|
|
1165
1180
|
const llmUsage = response.llmOutput[key];
|
|
1166
1181
|
if (!isNonEmptyUsage(llmUsage)) continue;
|
|
1167
|
-
|
|
1182
|
+
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 ? {
|
|
1183
|
+
...llmUsage,
|
|
1184
|
+
input_token_details: normalizedGenerationUsage.input_token_details
|
|
1185
|
+
} : llmUsage;
|
|
1186
|
+
return this._parseUsageModel(usageWithCacheDetails, provider, model, key !== "usage", llmUsage);
|
|
1168
1187
|
}
|
|
1169
1188
|
if (isNonEmptyUsage(normalizedGenerationUsage)) return this._parseUsageModel(normalizedGenerationUsage, provider, model, true, rawGenerationUsage);
|
|
1170
1189
|
if (isNonEmptyUsage(rawGenerationUsage)) return this._parseUsageModel(rawGenerationUsage, provider, model, false, rawGenerationUsage);
|