@posthog/ai 6.3.3 → 6.4.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.d.ts CHANGED
@@ -2,9 +2,9 @@ import OpenAIOrignal, { OpenAI, APIPromise, ClientOptions as ClientOptions$1, Az
2
2
  import { PostHog } from 'posthog-node';
3
3
  import { Stream } from 'openai/streaming';
4
4
  import { ParsedResponse } from 'openai/resources/responses/responses';
5
+ import { ResponseCreateParamsWithTools, ExtractParsedContentFromParams } from 'openai/lib/ResponsesParser';
5
6
  import { LanguageModelV2 } from '@ai-sdk/provider';
6
- import AnthropicOriginal from '@anthropic-ai/sdk';
7
- import { RequestOptions as RequestOptions$2, APIPromise as APIPromise$1 } from '@anthropic-ai/sdk/core';
7
+ import AnthropicOriginal, { APIPromise as APIPromise$1 } from '@anthropic-ai/sdk';
8
8
  import { Stream as Stream$1 } from '@anthropic-ai/sdk/streaming';
9
9
  import { GoogleGenAI, GenerateContentParameters, GenerateContentResponse } from '@google/genai';
10
10
  import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
@@ -54,7 +54,7 @@ interface MonitoringOpenAIConfig$1 extends ClientOptions$1 {
54
54
  posthog: PostHog;
55
55
  baseURL?: string;
56
56
  }
57
- type RequestOptions$1 = Record<string, any>;
57
+ type RequestOptions$2 = Record<string, any>;
58
58
  declare class PostHogOpenAI extends OpenAI {
59
59
  private readonly phClient;
60
60
  chat: WrappedChat$1;
@@ -70,24 +70,24 @@ declare class WrappedCompletions$1 extends Completions {
70
70
  private readonly phClient;
71
71
  private readonly baseURL;
72
72
  constructor(client: OpenAI, phClient: PostHog);
73
- create(body: ChatCompletionCreateParamsNonStreaming$1 & MonitoringParams, options?: RequestOptions$1): APIPromise<ChatCompletion$1>;
74
- create(body: ChatCompletionCreateParamsStreaming$1 & MonitoringParams, options?: RequestOptions$1): APIPromise<Stream<ChatCompletionChunk$1>>;
75
- create(body: ChatCompletionCreateParamsBase$1 & MonitoringParams, options?: RequestOptions$1): APIPromise<ChatCompletion$1 | Stream<ChatCompletionChunk$1>>;
73
+ create(body: ChatCompletionCreateParamsNonStreaming$1 & MonitoringParams, options?: RequestOptions$2): APIPromise<ChatCompletion$1>;
74
+ create(body: ChatCompletionCreateParamsStreaming$1 & MonitoringParams, options?: RequestOptions$2): APIPromise<Stream<ChatCompletionChunk$1>>;
75
+ create(body: ChatCompletionCreateParamsBase$1 & MonitoringParams, options?: RequestOptions$2): APIPromise<ChatCompletion$1 | Stream<ChatCompletionChunk$1>>;
76
76
  }
77
77
  declare class WrappedResponses extends Responses {
78
78
  private readonly phClient;
79
79
  private readonly baseURL;
80
80
  constructor(client: OpenAI, phClient: PostHog);
81
- create(body: ResponsesCreateParamsNonStreaming & MonitoringParams, options?: RequestOptions$1): APIPromise<OpenAI.Responses.Response>;
82
- create(body: ResponsesCreateParamsStreaming & MonitoringParams, options?: RequestOptions$1): APIPromise<Stream<OpenAI.Responses.ResponseStreamEvent>>;
83
- create(body: ResponsesCreateParamsBase & MonitoringParams, options?: RequestOptions$1): APIPromise<OpenAI.Responses.Response | Stream<OpenAI.Responses.ResponseStreamEvent>>;
84
- parse<Params extends ResponsesCreateParamsBase, ParsedT = any>(body: Params & MonitoringParams, options?: RequestOptions$1): APIPromise<ParsedResponse<ParsedT>>;
81
+ create(body: ResponsesCreateParamsNonStreaming & MonitoringParams, options?: RequestOptions$2): APIPromise<OpenAI.Responses.Response>;
82
+ create(body: ResponsesCreateParamsStreaming & MonitoringParams, options?: RequestOptions$2): APIPromise<Stream<OpenAI.Responses.ResponseStreamEvent>>;
83
+ create(body: ResponsesCreateParamsBase & MonitoringParams, options?: RequestOptions$2): APIPromise<OpenAI.Responses.Response | Stream<OpenAI.Responses.ResponseStreamEvent>>;
84
+ parse<Params extends ResponseCreateParamsWithTools, ParsedT = ExtractParsedContentFromParams<Params>>(body: Params & MonitoringParams, options?: RequestOptions$2): APIPromise<ParsedResponse<ParsedT>>;
85
85
  }
86
86
  declare class WrappedEmbeddings$1 extends Embeddings {
87
87
  private readonly phClient;
88
88
  private readonly baseURL;
89
89
  constructor(client: OpenAI, phClient: PostHog);
90
- create(body: EmbeddingCreateParams$1 & MonitoringParams, options?: RequestOptions$1): APIPromise<CreateEmbeddingResponse$1>;
90
+ create(body: EmbeddingCreateParams$1 & MonitoringParams, options?: RequestOptions$2): APIPromise<CreateEmbeddingResponse$1>;
91
91
  }
92
92
 
93
93
  type ChatCompletion = OpenAIOrignal.ChatCompletion;
@@ -102,7 +102,7 @@ interface MonitoringOpenAIConfig {
102
102
  posthog: PostHog;
103
103
  baseURL?: string;
104
104
  }
105
- type RequestOptions = Record<string, any>;
105
+ type RequestOptions$1 = Record<string, any>;
106
106
  declare class PostHogAzureOpenAI extends AzureOpenAI {
107
107
  private readonly phClient;
108
108
  chat: WrappedChat;
@@ -117,15 +117,15 @@ declare class WrappedCompletions extends AzureOpenAI.Chat.Completions {
117
117
  private readonly phClient;
118
118
  private readonly baseURL;
119
119
  constructor(client: AzureOpenAI, phClient: PostHog);
120
- create(body: ChatCompletionCreateParamsNonStreaming & MonitoringParams, options?: RequestOptions): APIPromise<ChatCompletion>;
121
- create(body: ChatCompletionCreateParamsStreaming & MonitoringParams, options?: RequestOptions): APIPromise<Stream<ChatCompletionChunk>>;
122
- create(body: ChatCompletionCreateParamsBase & MonitoringParams, options?: RequestOptions): APIPromise<ChatCompletion | Stream<ChatCompletionChunk>>;
120
+ create(body: ChatCompletionCreateParamsNonStreaming & MonitoringParams, options?: RequestOptions$1): APIPromise<ChatCompletion>;
121
+ create(body: ChatCompletionCreateParamsStreaming & MonitoringParams, options?: RequestOptions$1): APIPromise<Stream<ChatCompletionChunk>>;
122
+ create(body: ChatCompletionCreateParamsBase & MonitoringParams, options?: RequestOptions$1): APIPromise<ChatCompletion | Stream<ChatCompletionChunk>>;
123
123
  }
124
124
  declare class WrappedEmbeddings extends AzureOpenAI.Embeddings {
125
125
  private readonly phClient;
126
126
  private readonly baseURL;
127
127
  constructor(client: AzureOpenAI, phClient: PostHog);
128
- create(body: EmbeddingCreateParams & MonitoringParams, options?: RequestOptions): APIPromise<CreateEmbeddingResponse>;
128
+ create(body: EmbeddingCreateParams & MonitoringParams, options?: RequestOptions$1): APIPromise<CreateEmbeddingResponse>;
129
129
  }
130
130
 
131
131
  interface ClientOptions {
@@ -146,6 +146,7 @@ type MessageCreateParamsStreaming = AnthropicOriginal.Messages.MessageCreatePara
146
146
  type Message = AnthropicOriginal.Messages.Message;
147
147
  type RawMessageStreamEvent = AnthropicOriginal.Messages.RawMessageStreamEvent;
148
148
  type MessageCreateParamsBase = AnthropicOriginal.Messages.MessageCreateParams;
149
+ type RequestOptions = AnthropicOriginal.RequestOptions;
149
150
 
150
151
  interface MonitoringAnthropicConfig {
151
152
  apiKey: string;
@@ -161,9 +162,9 @@ declare class WrappedMessages extends AnthropicOriginal.Messages {
161
162
  private readonly phClient;
162
163
  private readonly baseURL;
163
164
  constructor(parentClient: PostHogAnthropic, phClient: PostHog);
164
- create(body: MessageCreateParamsNonStreaming, options?: RequestOptions$2): APIPromise$1<Message>;
165
- create(body: MessageCreateParamsStreaming & MonitoringParams, options?: RequestOptions$2): APIPromise$1<Stream$1<RawMessageStreamEvent>>;
166
- create(body: MessageCreateParamsBase & MonitoringParams, options?: RequestOptions$2): APIPromise$1<Stream$1<RawMessageStreamEvent> | Message>;
165
+ create(body: MessageCreateParamsNonStreaming, options?: RequestOptions): APIPromise$1<Message>;
166
+ create(body: MessageCreateParamsStreaming & MonitoringParams, options?: RequestOptions): APIPromise$1<Stream$1<RawMessageStreamEvent>>;
167
+ create(body: MessageCreateParamsBase & MonitoringParams, options?: RequestOptions): APIPromise$1<Stream$1<RawMessageStreamEvent> | Message>;
167
168
  }
168
169
 
169
170
  interface MonitoringGeminiConfig {
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.3.3";
9
+ var version = "6.4.1";
10
10
 
11
11
  // limit large outputs by truncating to 200kb (approx 200k bytes)
12
12
  const MAX_OUTPUT_SIZE = 200000;
@@ -822,7 +822,7 @@ let WrappedCompletions$1 = class WrappedCompletions extends Completions {
822
822
  await sendEventToPosthog({
823
823
  client: this.phClient,
824
824
  ...posthogParams,
825
- model: openAIParams.model,
825
+ model: String(openAIParams.model ?? ''),
826
826
  provider: 'openai',
827
827
  input: sanitizeOpenAI(openAIParams.messages),
828
828
  output: [],
@@ -959,8 +959,7 @@ let WrappedResponses$1 = class WrappedResponses extends Responses {
959
959
  await sendEventToPosthog({
960
960
  client: this.phClient,
961
961
  ...posthogParams,
962
- //@ts-expect-error
963
- model: openAIParams.model,
962
+ model: String(openAIParams.model ?? ''),
964
963
  provider: 'openai',
965
964
  input: sanitizeOpenAIResponse(openAIParams.input),
966
965
  output: [],
@@ -986,7 +985,6 @@ let WrappedResponses$1 = class WrappedResponses extends Responses {
986
985
  posthogParams
987
986
  } = extractPosthogParams(body);
988
987
  const startTime = Date.now();
989
- // Create a temporary instance that bypasses our wrapped create method
990
988
  const originalCreate = super.create.bind(this);
991
989
  const originalSelf = this;
992
990
  const tempCreate = originalSelf.create;
@@ -998,8 +996,7 @@ let WrappedResponses$1 = class WrappedResponses extends Responses {
998
996
  await sendEventToPosthog({
999
997
  client: this.phClient,
1000
998
  ...posthogParams,
1001
- //@ts-expect-error
1002
- model: openAIParams.model,
999
+ model: String(openAIParams.model ?? ''),
1003
1000
  provider: 'openai',
1004
1001
  input: sanitizeOpenAIResponse(openAIParams.input),
1005
1002
  output: result.output,
@@ -1020,8 +1017,7 @@ let WrappedResponses$1 = class WrappedResponses extends Responses {
1020
1017
  await sendEventToPosthog({
1021
1018
  client: this.phClient,
1022
1019
  ...posthogParams,
1023
- //@ts-expect-error
1024
- model: openAIParams.model,
1020
+ model: String(openAIParams.model ?? ''),
1025
1021
  provider: 'openai',
1026
1022
  input: sanitizeOpenAIResponse(openAIParams.input),
1027
1023
  output: [],
@@ -1463,8 +1459,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
1463
1459
  await sendEventToPosthog({
1464
1460
  client: this.phClient,
1465
1461
  ...posthogParams,
1466
- //@ts-expect-error
1467
- model: openAIParams.model,
1462
+ model: String(openAIParams.model ?? ''),
1468
1463
  provider: 'azure',
1469
1464
  input: openAIParams.input,
1470
1465
  output: result.output,
@@ -1484,8 +1479,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
1484
1479
  await sendEventToPosthog({
1485
1480
  client: this.phClient,
1486
1481
  ...posthogParams,
1487
- //@ts-expect-error
1488
- model: openAIParams.model,
1482
+ model: String(openAIParams.model ?? ''),
1489
1483
  provider: 'azure',
1490
1484
  input: openAIParams.input,
1491
1485
  output: [],