@databuddy/sdk 2.3.28 → 2.3.30

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,236 +0,0 @@
1
- import { LanguageModelV2, LanguageModelV3 } from '@ai-sdk/provider';
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
- }
56
- /**
57
- * Token usage from AI model calls
58
- */
59
- interface TokenUsage {
60
- inputTokens: number;
61
- outputTokens: number;
62
- totalTokens: number;
63
- cachedInputTokens?: number;
64
- cacheCreationInputTokens?: number;
65
- reasoningTokens?: number;
66
- webSearchCount?: number;
67
- }
68
- /**
69
- * Cost breakdown from TokenLens
70
- */
71
- interface TokenCost {
72
- inputTokenCostUSD?: number;
73
- outputTokenCostUSD?: number;
74
- totalTokenCostUSD?: number;
75
- }
76
- /**
77
- * Tool call information
78
- */
79
- interface ToolCallInfo {
80
- toolCallCount: number;
81
- toolResultCount: number;
82
- toolCallNames: string[];
83
- availableTools?: string[];
84
- }
85
- /**
86
- * Error information for failed AI calls
87
- */
88
- interface AIError {
89
- name: string;
90
- message: string;
91
- stack?: string;
92
- }
93
- /**
94
- * Complete AI call log entry
95
- */
96
- interface AICall {
97
- timestamp: Date;
98
- traceId: string;
99
- type: "generate" | "stream";
100
- model: string;
101
- provider: string;
102
- finishReason?: string;
103
- input: AIMessage[];
104
- output: AIMessage[];
105
- usage: TokenUsage;
106
- cost: TokenCost;
107
- tools: ToolCallInfo;
108
- error?: AIError;
109
- durationMs: number;
110
- httpStatus?: number;
111
- params?: Record<string, unknown>;
112
- }
113
- /**
114
- * Transport function for sending log entries
115
- */
116
- type Transport = (call: AICall) => Promise<void> | void;
117
- /**
118
- * Configuration options for Databuddy LLM tracking
119
- */
120
- interface DatabuddyLLMOptions {
121
- /**
122
- * API endpoint for sending logs (should include /llm path)
123
- * @default process.env.DATABUDDY_API_URL or 'https://basket.databuddy.cc/llm'
124
- */
125
- apiUrl?: string;
126
- /**
127
- * API key for authentication (determines owner - org or user)
128
- * @default process.env.DATABUDDY_API_KEY
129
- */
130
- apiKey?: string;
131
- /**
132
- * Custom transport function to send log entries
133
- * If provided, overrides default HTTP transport
134
- */
135
- transport?: Transport;
136
- /**
137
- * Whether to compute costs using TokenLens
138
- * @default true
139
- */
140
- computeCosts?: boolean;
141
- /**
142
- * Privacy mode - when true, input/output content is not captured
143
- * @default false
144
- */
145
- privacyMode?: boolean;
146
- /**
147
- * Maximum size for input/output content in bytes
148
- * @default 1048576 (1MB)
149
- */
150
- maxContentSize?: number;
151
- /**
152
- * Called on successful AI calls
153
- */
154
- onSuccess?: (call: AICall) => void;
155
- /**
156
- * Called on failed AI calls
157
- */
158
- onError?: (call: AICall) => void;
159
- }
160
- /**
161
- * Configuration options for tracking individual models
162
- */
163
- interface TrackOptions {
164
- /**
165
- * Transport function to send log entries
166
- * If not provided, uses the transport from DatabuddyLLM instance
167
- */
168
- transport?: Transport;
169
- /**
170
- * Trace ID to link related calls together
171
- */
172
- traceId?: string;
173
- /**
174
- * Whether to compute costs using TokenLens
175
- * @default true
176
- */
177
- computeCosts?: boolean;
178
- /**
179
- * Privacy mode - when true, input/output content is not captured
180
- * @default false
181
- */
182
- privacyMode?: boolean;
183
- /**
184
- * Called on successful AI calls
185
- */
186
- onSuccess?: (call: AICall) => void;
187
- /**
188
- * Called on failed AI calls
189
- */
190
- onError?: (call: AICall) => void;
191
- }
192
-
193
- /**
194
- * Create an HTTP transport that sends logs to an API endpoint
195
- *
196
- * @example
197
- * ```ts
198
- * import { databuddyLLM, httpTransport } from "@databuddy/sdk/ai/vercel";
199
- *
200
- * const { track } = databuddyLLM({
201
- * transport: httpTransport("https://api.example.com/ai-logs", "api-key"),
202
- * });
203
- * ```
204
- */
205
- declare const httpTransport: (url: string, apiKey?: string) => Transport;
206
-
207
- /**
208
- * Vercel AI SDK middleware for Databuddy
209
- *
210
- * Inspired by and adapted from PostHog's AI SDK implementation:
211
- * https://github.com/PostHog/posthog-js/tree/main/packages/ai
212
- */
213
-
214
- /**
215
- * Create a Databuddy LLM tracking instance
216
- *
217
- * @example
218
- * ```ts
219
- * import { databuddyLLM } from "@databuddy/sdk/ai/vercel";
220
- *
221
- * const { track } = databuddyLLM({ apiKey: "your-api-key" });
222
- * const model = track(openai("gpt-4"));
223
- * ```
224
- */
225
- declare const databuddyLLM: (options?: DatabuddyLLMOptions) => {
226
- track: <T extends LanguageModel>(model: T, trackOptions?: TrackOptions) => T;
227
- transport: Transport;
228
- };
229
-
230
- /**
231
- * Generate a simple trace ID
232
- */
233
- declare const generateTraceId: () => string;
234
-
235
- export { databuddyLLM, generateTraceId, httpTransport };
236
- export type { AICall, AIError, DatabuddyLLMOptions, TokenCost, TokenUsage, ToolCallInfo, TrackOptions, Transport };
@@ -1,236 +0,0 @@
1
- import { LanguageModelV2, LanguageModelV3 } from '@ai-sdk/provider';
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
- }
56
- /**
57
- * Token usage from AI model calls
58
- */
59
- interface TokenUsage {
60
- inputTokens: number;
61
- outputTokens: number;
62
- totalTokens: number;
63
- cachedInputTokens?: number;
64
- cacheCreationInputTokens?: number;
65
- reasoningTokens?: number;
66
- webSearchCount?: number;
67
- }
68
- /**
69
- * Cost breakdown from TokenLens
70
- */
71
- interface TokenCost {
72
- inputTokenCostUSD?: number;
73
- outputTokenCostUSD?: number;
74
- totalTokenCostUSD?: number;
75
- }
76
- /**
77
- * Tool call information
78
- */
79
- interface ToolCallInfo {
80
- toolCallCount: number;
81
- toolResultCount: number;
82
- toolCallNames: string[];
83
- availableTools?: string[];
84
- }
85
- /**
86
- * Error information for failed AI calls
87
- */
88
- interface AIError {
89
- name: string;
90
- message: string;
91
- stack?: string;
92
- }
93
- /**
94
- * Complete AI call log entry
95
- */
96
- interface AICall {
97
- timestamp: Date;
98
- traceId: string;
99
- type: "generate" | "stream";
100
- model: string;
101
- provider: string;
102
- finishReason?: string;
103
- input: AIMessage[];
104
- output: AIMessage[];
105
- usage: TokenUsage;
106
- cost: TokenCost;
107
- tools: ToolCallInfo;
108
- error?: AIError;
109
- durationMs: number;
110
- httpStatus?: number;
111
- params?: Record<string, unknown>;
112
- }
113
- /**
114
- * Transport function for sending log entries
115
- */
116
- type Transport = (call: AICall) => Promise<void> | void;
117
- /**
118
- * Configuration options for Databuddy LLM tracking
119
- */
120
- interface DatabuddyLLMOptions {
121
- /**
122
- * API endpoint for sending logs (should include /llm path)
123
- * @default process.env.DATABUDDY_API_URL or 'https://basket.databuddy.cc/llm'
124
- */
125
- apiUrl?: string;
126
- /**
127
- * API key for authentication (determines owner - org or user)
128
- * @default process.env.DATABUDDY_API_KEY
129
- */
130
- apiKey?: string;
131
- /**
132
- * Custom transport function to send log entries
133
- * If provided, overrides default HTTP transport
134
- */
135
- transport?: Transport;
136
- /**
137
- * Whether to compute costs using TokenLens
138
- * @default true
139
- */
140
- computeCosts?: boolean;
141
- /**
142
- * Privacy mode - when true, input/output content is not captured
143
- * @default false
144
- */
145
- privacyMode?: boolean;
146
- /**
147
- * Maximum size for input/output content in bytes
148
- * @default 1048576 (1MB)
149
- */
150
- maxContentSize?: number;
151
- /**
152
- * Called on successful AI calls
153
- */
154
- onSuccess?: (call: AICall) => void;
155
- /**
156
- * Called on failed AI calls
157
- */
158
- onError?: (call: AICall) => void;
159
- }
160
- /**
161
- * Configuration options for tracking individual models
162
- */
163
- interface TrackOptions {
164
- /**
165
- * Transport function to send log entries
166
- * If not provided, uses the transport from DatabuddyLLM instance
167
- */
168
- transport?: Transport;
169
- /**
170
- * Trace ID to link related calls together
171
- */
172
- traceId?: string;
173
- /**
174
- * Whether to compute costs using TokenLens
175
- * @default true
176
- */
177
- computeCosts?: boolean;
178
- /**
179
- * Privacy mode - when true, input/output content is not captured
180
- * @default false
181
- */
182
- privacyMode?: boolean;
183
- /**
184
- * Called on successful AI calls
185
- */
186
- onSuccess?: (call: AICall) => void;
187
- /**
188
- * Called on failed AI calls
189
- */
190
- onError?: (call: AICall) => void;
191
- }
192
-
193
- /**
194
- * Create an HTTP transport that sends logs to an API endpoint
195
- *
196
- * @example
197
- * ```ts
198
- * import { databuddyLLM, httpTransport } from "@databuddy/sdk/ai/vercel";
199
- *
200
- * const { track } = databuddyLLM({
201
- * transport: httpTransport("https://api.example.com/ai-logs", "api-key"),
202
- * });
203
- * ```
204
- */
205
- declare const httpTransport: (url: string, apiKey?: string) => Transport;
206
-
207
- /**
208
- * Vercel AI SDK middleware for Databuddy
209
- *
210
- * Inspired by and adapted from PostHog's AI SDK implementation:
211
- * https://github.com/PostHog/posthog-js/tree/main/packages/ai
212
- */
213
-
214
- /**
215
- * Create a Databuddy LLM tracking instance
216
- *
217
- * @example
218
- * ```ts
219
- * import { databuddyLLM } from "@databuddy/sdk/ai/vercel";
220
- *
221
- * const { track } = databuddyLLM({ apiKey: "your-api-key" });
222
- * const model = track(openai("gpt-4"));
223
- * ```
224
- */
225
- declare const databuddyLLM: (options?: DatabuddyLLMOptions) => {
226
- track: <T extends LanguageModel>(model: T, trackOptions?: TrackOptions) => T;
227
- transport: Transport;
228
- };
229
-
230
- /**
231
- * Generate a simple trace ID
232
- */
233
- declare const generateTraceId: () => string;
234
-
235
- export { databuddyLLM, generateTraceId, httpTransport };
236
- export type { AICall, AIError, DatabuddyLLMOptions, TokenCost, TokenUsage, ToolCallInfo, TrackOptions, Transport };