@databuddy/sdk 2.3.23 → 2.3.25

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.
@@ -1,5 +1,58 @@
1
- import { LanguageModelV2 } from '@ai-sdk/provider';
1
+ import { LanguageModelV2, LanguageModelV3 } from '@ai-sdk/provider';
2
2
 
3
+ /**
4
+ * Type guards and union types for Vercel AI SDK V2/V3 support
5
+ *
6
+ * Adapted from PostHog's AI SDK implementation:
7
+ * https://github.com/PostHog/posthog-js/tree/main/packages/ai
8
+ */
9
+
10
+ type LanguageModel = LanguageModelV2 | LanguageModelV3;
11
+
12
+ /**
13
+ * Content types for input/output arrays
14
+ */
15
+ type MessageContent = {
16
+ type: "text";
17
+ text: string;
18
+ } | {
19
+ type: "reasoning";
20
+ text: string;
21
+ } | {
22
+ type: "tool-call";
23
+ id: string;
24
+ function: {
25
+ name: string;
26
+ arguments: string;
27
+ };
28
+ } | {
29
+ type: "tool-result";
30
+ toolCallId: string;
31
+ toolName: string;
32
+ output: unknown;
33
+ isError?: boolean;
34
+ } | {
35
+ type: "file";
36
+ file: string;
37
+ mediaType: string;
38
+ } | {
39
+ type: "image";
40
+ image: string;
41
+ mediaType: string;
42
+ } | {
43
+ type: "source";
44
+ sourceType: string;
45
+ id: string;
46
+ url: string;
47
+ title: string;
48
+ };
49
+ /**
50
+ * Message format for input/output
51
+ */
52
+ interface AIMessage {
53
+ role: string;
54
+ content: string | MessageContent[];
55
+ }
3
56
  /**
4
57
  * Token usage from AI model calls
5
58
  */
@@ -8,6 +61,9 @@ interface TokenUsage {
8
61
  outputTokens: number;
9
62
  totalTokens: number;
10
63
  cachedInputTokens?: number;
64
+ cacheCreationInputTokens?: number;
65
+ reasoningTokens?: number;
66
+ webSearchCount?: number;
11
67
  }
12
68
  /**
13
69
  * Cost breakdown from TokenLens
@@ -24,6 +80,7 @@ interface ToolCallInfo {
24
80
  toolCallCount: number;
25
81
  toolResultCount: number;
26
82
  toolCallNames: string[];
83
+ availableTools?: string[];
27
84
  }
28
85
  /**
29
86
  * Error information for failed AI calls
@@ -38,15 +95,20 @@ interface AIError {
38
95
  */
39
96
  interface AICall {
40
97
  timestamp: Date;
98
+ traceId: string;
41
99
  type: "generate" | "stream";
42
100
  model: string;
43
101
  provider: string;
44
102
  finishReason?: string;
103
+ input: AIMessage[];
104
+ output: AIMessage[];
45
105
  usage: TokenUsage;
46
106
  cost: TokenCost;
47
107
  tools: ToolCallInfo;
48
108
  error?: AIError;
49
109
  durationMs: number;
110
+ httpStatus?: number;
111
+ params?: Record<string, unknown>;
50
112
  }
51
113
  /**
52
114
  * Transport function for sending log entries
@@ -81,6 +143,16 @@ interface DatabuddyLLMOptions {
81
143
  * @default true
82
144
  */
83
145
  computeCosts?: boolean;
146
+ /**
147
+ * Privacy mode - when true, input/output content is not captured
148
+ * @default false
149
+ */
150
+ privacyMode?: boolean;
151
+ /**
152
+ * Maximum size for input/output content in bytes
153
+ * @default 1048576 (1MB)
154
+ */
155
+ maxContentSize?: number;
84
156
  /**
85
157
  * Called on successful AI calls
86
158
  */
@@ -99,11 +171,24 @@ interface TrackOptions {
99
171
  * If not provided, uses the transport from DatabuddyLLM instance
100
172
  */
101
173
  transport?: Transport;
174
+ /**
175
+ * Trace ID to link related calls together
176
+ */
177
+ traceId?: string;
178
+ /**
179
+ * Client ID for this specific call (overrides instance-level clientId)
180
+ */
181
+ clientId?: string;
102
182
  /**
103
183
  * Whether to compute costs using TokenLens
104
184
  * @default true
105
185
  */
106
186
  computeCosts?: boolean;
187
+ /**
188
+ * Privacy mode - when true, input/output content is not captured
189
+ * @default false
190
+ */
191
+ privacyMode?: boolean;
107
192
  /**
108
193
  * Called on successful AI calls
109
194
  */
@@ -115,48 +200,40 @@ interface TrackOptions {
115
200
  }
116
201
 
117
202
  /**
118
- * Create a Databuddy LLM tracking instance
203
+ * Create an HTTP transport that sends logs to an API endpoint
119
204
  *
120
205
  * @example
121
206
  * ```ts
122
- * import { databuddyLLM } from "@databuddy/sdk/ai/vercel";
123
- *
124
- * // Use default endpoint (basket.databuddy.cc/llm)
125
- * const { track } = databuddyLLM({
126
- * apiKey: "your-api-key",
127
- * });
128
- *
129
- * // Or override with custom endpoint
130
- * const { track } = databuddyLLM({
131
- * apiUrl: "https://custom.example.com/llm",
132
- * apiKey: "your-api-key",
133
- * });
134
- *
135
- * // Track a model
136
- * const model = track(openai("gpt-4"));
207
+ * import { databuddyLLM, httpTransport } from "@databuddy/sdk/ai/vercel";
137
208
  *
138
- * // Or with custom transport
139
209
  * const { track } = databuddyLLM({
140
- * transport: async (call) => console.log(call),
210
+ * transport: httpTransport("https://api.example.com/ai-logs", "client-id", "api-key"),
141
211
  * });
142
212
  * ```
143
213
  */
144
- declare const databuddyLLM: (options?: DatabuddyLLMOptions) => {
145
- track: (model: LanguageModelV2, trackOptions?: TrackOptions) => LanguageModelV2;
146
- };
214
+ declare const httpTransport: (url: string, clientId?: string, apiKey?: string) => Transport;
215
+
147
216
  /**
148
- * Create an HTTP transport that sends logs to an API endpoint
217
+ * Vercel AI SDK middleware for Databuddy
218
+ *
219
+ * Inspired by and adapted from PostHog's AI SDK implementation:
220
+ * https://github.com/PostHog/posthog-js/tree/main/packages/ai
221
+ */
222
+
223
+ /**
224
+ * Create a Databuddy LLM tracking instance
149
225
  *
150
226
  * @example
151
227
  * ```ts
152
- * import { databuddyLLM, httpTransport } from "@databuddy/sdk/ai/vercel";
228
+ * import { databuddyLLM } from "@databuddy/sdk/ai/vercel";
153
229
  *
154
- * const { track } = databuddyLLM({
155
- * transport: httpTransport("https://api.example.com/ai-logs", "client-id", "api-key"),
156
- * });
230
+ * const { track } = databuddyLLM({ apiKey: "your-api-key" });
231
+ * const model = track(openai("gpt-4"));
157
232
  * ```
158
233
  */
159
- declare const httpTransport: (url: string, clientId?: string, apiKey?: string) => Transport;
234
+ declare const databuddyLLM: (options?: DatabuddyLLMOptions) => {
235
+ track: <T extends LanguageModel>(model: T, trackOptions?: TrackOptions) => T;
236
+ };
160
237
 
161
238
  export { databuddyLLM, httpTransport };
162
239
  export type { AICall, AIError, DatabuddyLLMOptions, TokenCost, TokenUsage, ToolCallInfo, TrackOptions, Transport };
@@ -1,5 +1,58 @@
1
- import { LanguageModelV2 } from '@ai-sdk/provider';
1
+ import { LanguageModelV2, LanguageModelV3 } from '@ai-sdk/provider';
2
2
 
3
+ /**
4
+ * Type guards and union types for Vercel AI SDK V2/V3 support
5
+ *
6
+ * Adapted from PostHog's AI SDK implementation:
7
+ * https://github.com/PostHog/posthog-js/tree/main/packages/ai
8
+ */
9
+
10
+ type LanguageModel = LanguageModelV2 | LanguageModelV3;
11
+
12
+ /**
13
+ * Content types for input/output arrays
14
+ */
15
+ type MessageContent = {
16
+ type: "text";
17
+ text: string;
18
+ } | {
19
+ type: "reasoning";
20
+ text: string;
21
+ } | {
22
+ type: "tool-call";
23
+ id: string;
24
+ function: {
25
+ name: string;
26
+ arguments: string;
27
+ };
28
+ } | {
29
+ type: "tool-result";
30
+ toolCallId: string;
31
+ toolName: string;
32
+ output: unknown;
33
+ isError?: boolean;
34
+ } | {
35
+ type: "file";
36
+ file: string;
37
+ mediaType: string;
38
+ } | {
39
+ type: "image";
40
+ image: string;
41
+ mediaType: string;
42
+ } | {
43
+ type: "source";
44
+ sourceType: string;
45
+ id: string;
46
+ url: string;
47
+ title: string;
48
+ };
49
+ /**
50
+ * Message format for input/output
51
+ */
52
+ interface AIMessage {
53
+ role: string;
54
+ content: string | MessageContent[];
55
+ }
3
56
  /**
4
57
  * Token usage from AI model calls
5
58
  */
@@ -8,6 +61,9 @@ interface TokenUsage {
8
61
  outputTokens: number;
9
62
  totalTokens: number;
10
63
  cachedInputTokens?: number;
64
+ cacheCreationInputTokens?: number;
65
+ reasoningTokens?: number;
66
+ webSearchCount?: number;
11
67
  }
12
68
  /**
13
69
  * Cost breakdown from TokenLens
@@ -24,6 +80,7 @@ interface ToolCallInfo {
24
80
  toolCallCount: number;
25
81
  toolResultCount: number;
26
82
  toolCallNames: string[];
83
+ availableTools?: string[];
27
84
  }
28
85
  /**
29
86
  * Error information for failed AI calls
@@ -38,15 +95,20 @@ interface AIError {
38
95
  */
39
96
  interface AICall {
40
97
  timestamp: Date;
98
+ traceId: string;
41
99
  type: "generate" | "stream";
42
100
  model: string;
43
101
  provider: string;
44
102
  finishReason?: string;
103
+ input: AIMessage[];
104
+ output: AIMessage[];
45
105
  usage: TokenUsage;
46
106
  cost: TokenCost;
47
107
  tools: ToolCallInfo;
48
108
  error?: AIError;
49
109
  durationMs: number;
110
+ httpStatus?: number;
111
+ params?: Record<string, unknown>;
50
112
  }
51
113
  /**
52
114
  * Transport function for sending log entries
@@ -81,6 +143,16 @@ interface DatabuddyLLMOptions {
81
143
  * @default true
82
144
  */
83
145
  computeCosts?: boolean;
146
+ /**
147
+ * Privacy mode - when true, input/output content is not captured
148
+ * @default false
149
+ */
150
+ privacyMode?: boolean;
151
+ /**
152
+ * Maximum size for input/output content in bytes
153
+ * @default 1048576 (1MB)
154
+ */
155
+ maxContentSize?: number;
84
156
  /**
85
157
  * Called on successful AI calls
86
158
  */
@@ -99,11 +171,24 @@ interface TrackOptions {
99
171
  * If not provided, uses the transport from DatabuddyLLM instance
100
172
  */
101
173
  transport?: Transport;
174
+ /**
175
+ * Trace ID to link related calls together
176
+ */
177
+ traceId?: string;
178
+ /**
179
+ * Client ID for this specific call (overrides instance-level clientId)
180
+ */
181
+ clientId?: string;
102
182
  /**
103
183
  * Whether to compute costs using TokenLens
104
184
  * @default true
105
185
  */
106
186
  computeCosts?: boolean;
187
+ /**
188
+ * Privacy mode - when true, input/output content is not captured
189
+ * @default false
190
+ */
191
+ privacyMode?: boolean;
107
192
  /**
108
193
  * Called on successful AI calls
109
194
  */
@@ -115,48 +200,40 @@ interface TrackOptions {
115
200
  }
116
201
 
117
202
  /**
118
- * Create a Databuddy LLM tracking instance
203
+ * Create an HTTP transport that sends logs to an API endpoint
119
204
  *
120
205
  * @example
121
206
  * ```ts
122
- * import { databuddyLLM } from "@databuddy/sdk/ai/vercel";
123
- *
124
- * // Use default endpoint (basket.databuddy.cc/llm)
125
- * const { track } = databuddyLLM({
126
- * apiKey: "your-api-key",
127
- * });
128
- *
129
- * // Or override with custom endpoint
130
- * const { track } = databuddyLLM({
131
- * apiUrl: "https://custom.example.com/llm",
132
- * apiKey: "your-api-key",
133
- * });
134
- *
135
- * // Track a model
136
- * const model = track(openai("gpt-4"));
207
+ * import { databuddyLLM, httpTransport } from "@databuddy/sdk/ai/vercel";
137
208
  *
138
- * // Or with custom transport
139
209
  * const { track } = databuddyLLM({
140
- * transport: async (call) => console.log(call),
210
+ * transport: httpTransport("https://api.example.com/ai-logs", "client-id", "api-key"),
141
211
  * });
142
212
  * ```
143
213
  */
144
- declare const databuddyLLM: (options?: DatabuddyLLMOptions) => {
145
- track: (model: LanguageModelV2, trackOptions?: TrackOptions) => LanguageModelV2;
146
- };
214
+ declare const httpTransport: (url: string, clientId?: string, apiKey?: string) => Transport;
215
+
147
216
  /**
148
- * Create an HTTP transport that sends logs to an API endpoint
217
+ * Vercel AI SDK middleware for Databuddy
218
+ *
219
+ * Inspired by and adapted from PostHog's AI SDK implementation:
220
+ * https://github.com/PostHog/posthog-js/tree/main/packages/ai
221
+ */
222
+
223
+ /**
224
+ * Create a Databuddy LLM tracking instance
149
225
  *
150
226
  * @example
151
227
  * ```ts
152
- * import { databuddyLLM, httpTransport } from "@databuddy/sdk/ai/vercel";
228
+ * import { databuddyLLM } from "@databuddy/sdk/ai/vercel";
153
229
  *
154
- * const { track } = databuddyLLM({
155
- * transport: httpTransport("https://api.example.com/ai-logs", "client-id", "api-key"),
156
- * });
230
+ * const { track } = databuddyLLM({ apiKey: "your-api-key" });
231
+ * const model = track(openai("gpt-4"));
157
232
  * ```
158
233
  */
159
- declare const httpTransport: (url: string, clientId?: string, apiKey?: string) => Transport;
234
+ declare const databuddyLLM: (options?: DatabuddyLLMOptions) => {
235
+ track: <T extends LanguageModel>(model: T, trackOptions?: TrackOptions) => T;
236
+ };
160
237
 
161
238
  export { databuddyLLM, httpTransport };
162
239
  export type { AICall, AIError, DatabuddyLLMOptions, TokenCost, TokenUsage, ToolCallInfo, TrackOptions, Transport };