@posthog/ai 7.13.2 → 7.15.0

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.
Files changed (39) hide show
  1. package/README.md +30 -7
  2. package/dist/anthropic/index.cjs +14 -1
  3. package/dist/anthropic/index.cjs.map +1 -1
  4. package/dist/anthropic/index.mjs +14 -1
  5. package/dist/anthropic/index.mjs.map +1 -1
  6. package/dist/gemini/index.cjs +79 -1
  7. package/dist/gemini/index.cjs.map +1 -1
  8. package/dist/gemini/index.d.ts +2 -1
  9. package/dist/gemini/index.mjs +79 -1
  10. package/dist/gemini/index.mjs.map +1 -1
  11. package/dist/index.cjs +145 -2
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +3 -1
  14. package/dist/index.mjs +145 -2
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/langchain/index.cjs +38 -1
  17. package/dist/langchain/index.cjs.map +1 -1
  18. package/dist/langchain/index.d.ts +1 -0
  19. package/dist/langchain/index.mjs +38 -1
  20. package/dist/langchain/index.mjs.map +1 -1
  21. package/dist/openai/index.cjs +19 -2
  22. package/dist/openai/index.cjs.map +1 -1
  23. package/dist/openai/index.mjs +19 -2
  24. package/dist/openai/index.mjs.map +1 -1
  25. package/dist/openai-agents/index.cjs +655 -0
  26. package/dist/openai-agents/index.cjs.map +1 -0
  27. package/dist/openai-agents/index.d.ts +101 -0
  28. package/dist/openai-agents/index.mjs +652 -0
  29. package/dist/openai-agents/index.mjs.map +1 -0
  30. package/dist/otel/index.cjs +103 -5
  31. package/dist/otel/index.cjs.map +1 -1
  32. package/dist/otel/index.d.ts +66 -5
  33. package/dist/otel/index.mjs +103 -6
  34. package/dist/otel/index.mjs.map +1 -1
  35. package/dist/vercel/index.cjs +20 -1
  36. package/dist/vercel/index.cjs.map +1 -1
  37. package/dist/vercel/index.mjs +20 -1
  38. package/dist/vercel/index.mjs.map +1 -1
  39. package/package.json +23 -4
@@ -23,7 +23,7 @@ function _interopNamespace(e) {
23
23
 
24
24
  var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
25
25
 
26
- var version = "7.13.2";
26
+ var version = "7.15.0";
27
27
 
28
28
  // Type guards for safer type checking
29
29
 
@@ -987,6 +987,12 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
987
987
  eventProperties['$ai_web_search_count'] = additionalTokenData.webSearchCount;
988
988
  }
989
989
 
990
+ // Extract stop reason from generation info
991
+ const stopReason = this._extractStopReason(output);
992
+ if (stopReason) {
993
+ eventProperties['$ai_stop_reason'] = stopReason;
994
+ }
995
+
990
996
  // Handle generations/completions
991
997
  let completions;
992
998
  if (output.generations && Array.isArray(output.generations)) {
@@ -1122,6 +1128,37 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
1122
1128
  // Sanitize the message content to redact base64 images
1123
1129
  return sanitizeLangChain(messageDict);
1124
1130
  }
1131
+ _extractStopReason(output) {
1132
+ if (!output.generations || !Array.isArray(output.generations)) {
1133
+ return undefined;
1134
+ }
1135
+ const lastGeneration = output.generations[output.generations.length - 1];
1136
+ if (!Array.isArray(lastGeneration) || lastGeneration.length === 0) {
1137
+ return undefined;
1138
+ }
1139
+ const gen = lastGeneration[0];
1140
+
1141
+ // Check generationInfo for finish_reason (OpenAI format)
1142
+ if (gen.generationInfo?.finish_reason) {
1143
+ return String(gen.generationInfo.finish_reason);
1144
+ }
1145
+
1146
+ // Check generationInfo for response_metadata.stop_reason (Anthropic format)
1147
+ if (gen.generationInfo?.response_metadata?.stop_reason) {
1148
+ return String(gen.generationInfo.response_metadata.stop_reason);
1149
+ }
1150
+
1151
+ // Check message response_metadata for finish_reason (common LangChain format)
1152
+ if (gen.generationInfo?.response_metadata?.finish_reason) {
1153
+ return String(gen.generationInfo.response_metadata.finish_reason);
1154
+ }
1155
+
1156
+ // Check for stop_reason directly in generationInfo
1157
+ if (gen.generationInfo?.stop_reason) {
1158
+ return String(gen.generationInfo.stop_reason);
1159
+ }
1160
+ return undefined;
1161
+ }
1125
1162
  _parseUsageModel(usage, provider, model) {
1126
1163
  const conversionList = [['promptTokens', 'input'], ['completionTokens', 'output'], ['input_tokens', 'input'], ['output_tokens', 'output'], ['prompt_token_count', 'input'], ['candidates_token_count', 'output'], ['inputTokenCount', 'input'], ['outputTokenCount', 'output'], ['input_token_count', 'input'], ['generated_token_count', 'output']];
1127
1164
  const parsedUsage = conversionList.reduce((acc, [modelKey, typeKey]) => {