@posthog/ai 6.4.4 → 6.5.1

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/index.mjs CHANGED
@@ -6,7 +6,7 @@ import { wrapLanguageModel } from 'ai';
6
6
  import AnthropicOriginal from '@anthropic-ai/sdk';
7
7
  import { GoogleGenAI } from '@google/genai';
8
8
 
9
- var version = "6.4.4";
9
+ var version = "6.5.1";
10
10
 
11
11
  // Type guards for safer type checking
12
12
  const isString = value => {
@@ -1818,7 +1818,11 @@ const createInstrumentationMiddleware = (phClient, model, options) => {
1818
1818
  const startTime = Date.now();
1819
1819
  const mergedParams = {
1820
1820
  ...options,
1821
- ...mapVercelParams(params)
1821
+ ...mapVercelParams(params),
1822
+ posthogProperties: {
1823
+ ...options.posthogProperties,
1824
+ $ai_framework: 'vercel'
1825
+ }
1822
1826
  };
1823
1827
  const availableTools = extractAvailableToolCalls('vercel', params);
1824
1828
  try {
@@ -1894,7 +1898,11 @@ const createInstrumentationMiddleware = (phClient, model, options) => {
1894
1898
  let usage = {};
1895
1899
  const mergedParams = {
1896
1900
  ...options,
1897
- ...mapVercelParams(params)
1901
+ ...mapVercelParams(params),
1902
+ posthogProperties: {
1903
+ ...options.posthogProperties,
1904
+ $ai_framework: 'vercel'
1905
+ }
1898
1906
  };
1899
1907
  const modelId = options.posthogModelOverride ?? model.modelId;
1900
1908
  const provider = options.posthogProviderOverride ?? extractProvider(model);
@@ -3328,7 +3336,8 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
3328
3336
  $ai_input_state: withPrivacyMode(this.client, this.privacyMode, run.input),
3329
3337
  $ai_latency: latency,
3330
3338
  $ai_span_name: run.name,
3331
- $ai_span_id: runId
3339
+ $ai_span_id: runId,
3340
+ $ai_framework: 'langchain'
3332
3341
  };
3333
3342
  if (parentRunId) {
3334
3343
  eventProperties['$ai_parent_id'] = parentRunId;
@@ -3376,7 +3385,8 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
3376
3385
  $ai_input: withPrivacyMode(this.client, this.privacyMode, run.input),
3377
3386
  $ai_http_status: 200,
3378
3387
  $ai_latency: latency,
3379
- $ai_base_url: run.baseUrl
3388
+ $ai_base_url: run.baseUrl,
3389
+ $ai_framework: 'langchain'
3380
3390
  };
3381
3391
  if (run.tools) {
3382
3392
  eventProperties['$ai_tools'] = run.tools;
@@ -3562,6 +3572,11 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
3562
3572
  } else if (usage.reasoningTokens != null) {
3563
3573
  additionalTokenData.reasoningTokens = usage.reasoningTokens;
3564
3574
  }
3575
+ // In LangChain, input_tokens is the sum of input and cache read tokens.
3576
+ // Our cost calculation expects them to be separate, for Anthropic.
3577
+ if (parsedUsage.input && additionalTokenData.cacheReadInputTokens) {
3578
+ parsedUsage.input = Math.max(parsedUsage.input - additionalTokenData.cacheReadInputTokens, 0);
3579
+ }
3565
3580
  return [parsedUsage.input, parsedUsage.output, additionalTokenData];
3566
3581
  }
3567
3582
  parseUsage(response) {