raindrop-ai 0.0.26 → 0.0.29
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/{chunk-V425K7I7.mjs → chunk-WBQTVVE5.mjs} +2 -12
- package/dist/{index-6U6ncOea.d.mts → index-BCw4PtuC.d.mts} +7 -212
- package/dist/{index-6U6ncOea.d.ts → index-BCw4PtuC.d.ts} +7 -212
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +33 -42
- package/dist/index.mjs +32 -31
- package/dist/tracing/index.d.mts +3 -2
- package/dist/tracing/index.d.ts +3 -2
- package/dist/tracing/index.js +10 -48
- package/dist/tracing/index.mjs +8 -37
- package/dist/vercel/index.d.mts +1 -1
- package/dist/vercel/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -96,26 +96,16 @@ var NonLiveInteraction = class {
|
|
|
96
96
|
this.context = context;
|
|
97
97
|
this.analytics = analytics;
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
withSpan(_params, fn, thisArg, ...args) {
|
|
100
100
|
try {
|
|
101
101
|
return Promise.resolve(fn.apply(thisArg, args));
|
|
102
102
|
} catch (error) {
|
|
103
103
|
return Promise.reject(error);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
return Promise.resolve(fn.apply(thisArg, args));
|
|
109
|
-
} catch (error) {
|
|
110
|
-
return Promise.reject(error);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
createTask(_params) {
|
|
106
|
+
startSpan(_params) {
|
|
114
107
|
return NO_OP_SPAN;
|
|
115
108
|
}
|
|
116
|
-
withContext(_properties, fn, thisArg, ...args) {
|
|
117
|
-
return fn.apply(thisArg, args);
|
|
118
|
-
}
|
|
119
109
|
setProperties(_properties) {
|
|
120
110
|
var _a;
|
|
121
111
|
(_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
|
|
@@ -83,21 +83,6 @@ type TraceContextOutput = Omit<PartialAiTrackEvent, "eventId"> & {
|
|
|
83
83
|
output: string;
|
|
84
84
|
eventId?: string;
|
|
85
85
|
};
|
|
86
|
-
/**
|
|
87
|
-
* Configuration for a traced workflow.
|
|
88
|
-
*
|
|
89
|
-
* Workflows represent higher-level operations that might contain multiple
|
|
90
|
-
* tasks. They help organize traces into logical units of work.
|
|
91
|
-
*
|
|
92
|
-
* @property name - Name of the workflow for identification in traces
|
|
93
|
-
* @property inputParameters - Optional array of input parameters for the workflow
|
|
94
|
-
* @property properties - Optional key-value pairs for additional metadata
|
|
95
|
-
*/
|
|
96
|
-
interface WorkflowParams {
|
|
97
|
-
name: string;
|
|
98
|
-
inputParameters?: unknown[];
|
|
99
|
-
properties?: Record<string, string>;
|
|
100
|
-
}
|
|
101
86
|
/**
|
|
102
87
|
* Configuration for a traced task.
|
|
103
88
|
*
|
|
@@ -109,9 +94,8 @@ interface WorkflowParams {
|
|
|
109
94
|
* @property properties - Optional key-value pairs for additional metadata
|
|
110
95
|
* @property inputParameters - Optional array of input parameters for the task
|
|
111
96
|
*/
|
|
112
|
-
interface
|
|
97
|
+
interface SpanParams {
|
|
113
98
|
name: string;
|
|
114
|
-
kind: "llm" | "tool" | "retrival" | "internal";
|
|
115
99
|
properties?: Record<string, string>;
|
|
116
100
|
inputParameters?: unknown[];
|
|
117
101
|
}
|
|
@@ -160,209 +144,20 @@ interface TaskParams {
|
|
|
160
144
|
* interaction.end(result);
|
|
161
145
|
*/
|
|
162
146
|
type Interaction = {
|
|
163
|
-
/**
|
|
164
|
-
* Creates a traced workflow that executes the provided function.
|
|
165
|
-
*
|
|
166
|
-
* @template T The return type of the function
|
|
167
|
-
* @param params Either a WorkflowParams object or a string representing the workflow name
|
|
168
|
-
* @param fn The function to execute within the traced workflow
|
|
169
|
-
* @param thisArg Optional. The value to use as `this` when executing the function.
|
|
170
|
-
* Useful when passing methods from classes that require their class instance context.
|
|
171
|
-
* @param args Additional arguments to pass to the function
|
|
172
|
-
* @returns A promise that resolves to the function's return value
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* // Content generation workflow with business context
|
|
176
|
-
* await interaction.withWorkflow({
|
|
177
|
-
* name: "joke_generator_workflow",
|
|
178
|
-
* properties: {
|
|
179
|
-
* content_type: "humor",
|
|
180
|
-
* audience: "developers",
|
|
181
|
-
* distribution_channel: "slack",
|
|
182
|
-
* priority: "normal"
|
|
183
|
-
* }
|
|
184
|
-
* }, async () => {
|
|
185
|
-
* const joke = await createJoke();
|
|
186
|
-
* const translation = await translateToPirate(joke);
|
|
187
|
-
* const signature = await generateSignature(translation);
|
|
188
|
-
* return translation + "\n\n" + signature;
|
|
189
|
-
* });
|
|
190
|
-
*
|
|
191
|
-
* @example
|
|
192
|
-
* // Using thisArg to preserve class context in LLM service
|
|
193
|
-
* class AIServiceClient {
|
|
194
|
-
* private apiKey: string;
|
|
195
|
-
* private chatHistory: Message[];
|
|
196
|
-
*
|
|
197
|
-
* async generateResponse(prompt: string) {
|
|
198
|
-
* // Method that uses this.apiKey and this.chatHistory
|
|
199
|
-
* const completion = await openai.chat.completions.create({
|
|
200
|
-
* model: "gpt-4",
|
|
201
|
-
* messages: [...this.chatHistory, { role: "user", content: prompt }],
|
|
202
|
-
* api_key: this.apiKey
|
|
203
|
-
* });
|
|
204
|
-
* return completion.choices[0].message.content;
|
|
205
|
-
* }
|
|
206
|
-
*
|
|
207
|
-
* async processConversation(prompt: string, conversationId: string) {
|
|
208
|
-
* // Pass this as thisArg to preserve context
|
|
209
|
-
* return await interaction.withWorkflow(
|
|
210
|
-
* {
|
|
211
|
-
* name: "conversation_flow",
|
|
212
|
-
* properties: {
|
|
213
|
-
* request_source: "mobile_app",
|
|
214
|
-
* conversation_stage: "follow_up",
|
|
215
|
-
* user_subscription: "premium",
|
|
216
|
-
* locale: "en-US"
|
|
217
|
-
* }
|
|
218
|
-
* },
|
|
219
|
-
* this.generateResponse,
|
|
220
|
-
* this, // thisArg to access this.apiKey and this.chatHistory
|
|
221
|
-
* prompt
|
|
222
|
-
* );
|
|
223
|
-
* }
|
|
224
|
-
* }
|
|
225
|
-
*/
|
|
226
|
-
withWorkflow<T>(params: WorkflowParams | string, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): Promise<T>;
|
|
227
147
|
/**
|
|
228
148
|
* Creates a traced task that executes the provided function.
|
|
229
149
|
*
|
|
230
|
-
* @
|
|
231
|
-
* @
|
|
232
|
-
* @param fn The function to execute within the traced task
|
|
233
|
-
* @param thisArg Optional. The value to use as `this` when executing the function.
|
|
234
|
-
* Useful when passing methods from classes that require their class instance context.
|
|
235
|
-
* @param args Additional arguments to pass to the function
|
|
236
|
-
* @returns A promise that resolves to the function's return value
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* // LLM task with business metadata
|
|
240
|
-
* await interaction.withTask({
|
|
241
|
-
* name: "joke_creation",
|
|
242
|
-
* kind: "llm",
|
|
243
|
-
* properties: {
|
|
244
|
-
* request_source: "web",
|
|
245
|
-
* feature_flag: "beta_jokes",
|
|
246
|
-
* experiment_group: "creative_boost",
|
|
247
|
-
* user_segment: "developer"
|
|
248
|
-
* }
|
|
249
|
-
* }, async () => {
|
|
250
|
-
* const completion = await openai.chat.completions.create({
|
|
251
|
-
* model: "gpt-3.5-turbo",
|
|
252
|
-
* temperature: 0.7,
|
|
253
|
-
* max_tokens: 2048,
|
|
254
|
-
* messages: [
|
|
255
|
-
* { role: "system", content: "You are a helpful assistant." },
|
|
256
|
-
* { role: "user", content: "I can't log into my account." }
|
|
257
|
-
* ]
|
|
258
|
-
* });
|
|
259
|
-
* return completion.choices[0].message.content;
|
|
260
|
-
* });
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* // Using thisArg with an embedding service
|
|
264
|
-
* class EmbeddingService {
|
|
265
|
-
* private embedModel: string;
|
|
266
|
-
* private dimension: number;
|
|
267
|
-
*
|
|
268
|
-
* async embedText(text: string) {
|
|
269
|
-
* // Uses this.embedModel and this.dimension
|
|
270
|
-
* const embedding = await openai.embeddings.create({
|
|
271
|
-
* model: this.embedModel,
|
|
272
|
-
* input: text
|
|
273
|
-
* });
|
|
274
|
-
* return embedding.data[0].embedding.slice(0, this.dimension);
|
|
275
|
-
* }
|
|
276
|
-
*
|
|
277
|
-
* async getEmbedding(document: string, docId: string) {
|
|
278
|
-
* return interaction.withTask(
|
|
279
|
-
* {
|
|
280
|
-
* name: "text_embedding",
|
|
281
|
-
* kind: "llm",
|
|
282
|
-
* properties: {
|
|
283
|
-
* document_type: "knowledge_base",
|
|
284
|
-
* doc_id: docId,
|
|
285
|
-
* language: "en",
|
|
286
|
-
* content_source: "internal_wiki"
|
|
287
|
-
* }
|
|
288
|
-
* },
|
|
289
|
-
* this.embedText,
|
|
290
|
-
* this, // thisArg preserves access to this.embedModel and this.dimension
|
|
291
|
-
* document // Text to be embedded
|
|
292
|
-
* );
|
|
293
|
-
* }
|
|
294
|
-
* }
|
|
150
|
+
* @param params TaskParams object with task configuration
|
|
151
|
+
* @returns A span that can be used to record a task
|
|
295
152
|
*/
|
|
296
|
-
|
|
153
|
+
withSpan<T>(params: SpanParams, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): Promise<T>;
|
|
297
154
|
/**
|
|
298
155
|
* Creates a task span that can be used to manually record a task.
|
|
299
156
|
*
|
|
300
157
|
* @param params TaskParams object with task configuration
|
|
301
158
|
* @returns A span that can be used to record a task
|
|
302
159
|
*/
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Executes a function with additional context properties.
|
|
306
|
-
*
|
|
307
|
-
* @template T The return type of the function
|
|
308
|
-
* @param properties Object containing context properties to add
|
|
309
|
-
* @param fn The function to execute with additional context
|
|
310
|
-
* @param thisArg Optional. The value to use as `this` when executing the function.
|
|
311
|
-
* Useful when passing methods from classes that require their class instance context.
|
|
312
|
-
* @param args Additional arguments to pass to the function
|
|
313
|
-
* @returns The function's return value or a promise that resolves to it
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* // Adding business context to LLM calls
|
|
317
|
-
* const result = interaction.withContext(
|
|
318
|
-
* {
|
|
319
|
-
* user_intent: "troubleshooting",
|
|
320
|
-
* product_area: "authentication",
|
|
321
|
-
* session_priority: "high",
|
|
322
|
-
* customer_tier: "enterprise"
|
|
323
|
-
* },
|
|
324
|
-
* async () => {
|
|
325
|
-
* const completion = await openai.chat.completions.create({
|
|
326
|
-
* model: "gpt-4",
|
|
327
|
-
* temperature: 0.7,
|
|
328
|
-
* max_tokens: 2048,
|
|
329
|
-
* messages: [
|
|
330
|
-
* { role: "system", content: "You are a helpful assistant." },
|
|
331
|
-
* { role: "user", content: "I can't log into my account." }
|
|
332
|
-
* ]
|
|
333
|
-
* });
|
|
334
|
-
* return completion.choices[0].message.content;
|
|
335
|
-
* }
|
|
336
|
-
* );
|
|
337
|
-
*
|
|
338
|
-
* @example
|
|
339
|
-
* // Using thisArg with semantic search application
|
|
340
|
-
* class SearchService {
|
|
341
|
-
* private vectorDB: VectorDatabase;
|
|
342
|
-
* private queryProcessor: QueryProcessor;
|
|
343
|
-
*
|
|
344
|
-
* async findRelevantDocuments(query: string) {
|
|
345
|
-
* // Uses this.vectorDB and this.queryProcessor
|
|
346
|
-
* const processedQuery = this.queryProcessor.enhance(query);
|
|
347
|
-
* return this.vectorDB.similaritySearch(processedQuery, 5);
|
|
348
|
-
* }
|
|
349
|
-
*
|
|
350
|
-
* async search(userQuery: string, userId: string) {
|
|
351
|
-
* return interaction.withContext(
|
|
352
|
-
* {
|
|
353
|
-
* search_type: "semantic",
|
|
354
|
-
* user_history: "returning_user",
|
|
355
|
-
* search_filter: "documentation",
|
|
356
|
-
* analytics_source: "help_center"
|
|
357
|
-
* },
|
|
358
|
-
* this.findRelevantDocuments,
|
|
359
|
-
* this, // thisArg preserves access to this.vectorDB and this.queryProcessor
|
|
360
|
-
* userQuery // Search query to process
|
|
361
|
-
* );
|
|
362
|
-
* }
|
|
363
|
-
* }
|
|
364
|
-
*/
|
|
365
|
-
withContext<T>(properties: Record<string, string>, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): T | Promise<T>;
|
|
160
|
+
startSpan(params: SpanParams): Span;
|
|
366
161
|
/**
|
|
367
162
|
* Sets multiple properties on the interaction context.
|
|
368
163
|
*
|
|
@@ -495,14 +290,14 @@ declare class Raindrop {
|
|
|
495
290
|
resumeInteraction(eventId: string): Interaction;
|
|
496
291
|
/**
|
|
497
292
|
* Track AI events. In addiiton to normal event properties, you can provide an "input", "output", or "model" parameter.
|
|
498
|
-
* It takes an AiTrackEvent as input and sends it to the /track-ai endpoint of the
|
|
293
|
+
* It takes an AiTrackEvent as input and sends it to the /track-ai endpoint of the raindrop api.
|
|
499
294
|
*
|
|
500
295
|
* @param event - The AiTrackEvent (you must specify at least one of input/output properties)
|
|
501
296
|
* @returns A Promise that resolves when the event has been successfully sent.
|
|
502
297
|
*
|
|
503
298
|
* Example usage:
|
|
504
299
|
* ```typescript
|
|
505
|
-
*
|
|
300
|
+
* raindrop.track_ai({
|
|
506
301
|
* event: "chat", //name of the event
|
|
507
302
|
* model: "claude", //optional
|
|
508
303
|
* input: "what's up?", // input or output is required
|
|
@@ -83,21 +83,6 @@ type TraceContextOutput = Omit<PartialAiTrackEvent, "eventId"> & {
|
|
|
83
83
|
output: string;
|
|
84
84
|
eventId?: string;
|
|
85
85
|
};
|
|
86
|
-
/**
|
|
87
|
-
* Configuration for a traced workflow.
|
|
88
|
-
*
|
|
89
|
-
* Workflows represent higher-level operations that might contain multiple
|
|
90
|
-
* tasks. They help organize traces into logical units of work.
|
|
91
|
-
*
|
|
92
|
-
* @property name - Name of the workflow for identification in traces
|
|
93
|
-
* @property inputParameters - Optional array of input parameters for the workflow
|
|
94
|
-
* @property properties - Optional key-value pairs for additional metadata
|
|
95
|
-
*/
|
|
96
|
-
interface WorkflowParams {
|
|
97
|
-
name: string;
|
|
98
|
-
inputParameters?: unknown[];
|
|
99
|
-
properties?: Record<string, string>;
|
|
100
|
-
}
|
|
101
86
|
/**
|
|
102
87
|
* Configuration for a traced task.
|
|
103
88
|
*
|
|
@@ -109,9 +94,8 @@ interface WorkflowParams {
|
|
|
109
94
|
* @property properties - Optional key-value pairs for additional metadata
|
|
110
95
|
* @property inputParameters - Optional array of input parameters for the task
|
|
111
96
|
*/
|
|
112
|
-
interface
|
|
97
|
+
interface SpanParams {
|
|
113
98
|
name: string;
|
|
114
|
-
kind: "llm" | "tool" | "retrival" | "internal";
|
|
115
99
|
properties?: Record<string, string>;
|
|
116
100
|
inputParameters?: unknown[];
|
|
117
101
|
}
|
|
@@ -160,209 +144,20 @@ interface TaskParams {
|
|
|
160
144
|
* interaction.end(result);
|
|
161
145
|
*/
|
|
162
146
|
type Interaction = {
|
|
163
|
-
/**
|
|
164
|
-
* Creates a traced workflow that executes the provided function.
|
|
165
|
-
*
|
|
166
|
-
* @template T The return type of the function
|
|
167
|
-
* @param params Either a WorkflowParams object or a string representing the workflow name
|
|
168
|
-
* @param fn The function to execute within the traced workflow
|
|
169
|
-
* @param thisArg Optional. The value to use as `this` when executing the function.
|
|
170
|
-
* Useful when passing methods from classes that require their class instance context.
|
|
171
|
-
* @param args Additional arguments to pass to the function
|
|
172
|
-
* @returns A promise that resolves to the function's return value
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* // Content generation workflow with business context
|
|
176
|
-
* await interaction.withWorkflow({
|
|
177
|
-
* name: "joke_generator_workflow",
|
|
178
|
-
* properties: {
|
|
179
|
-
* content_type: "humor",
|
|
180
|
-
* audience: "developers",
|
|
181
|
-
* distribution_channel: "slack",
|
|
182
|
-
* priority: "normal"
|
|
183
|
-
* }
|
|
184
|
-
* }, async () => {
|
|
185
|
-
* const joke = await createJoke();
|
|
186
|
-
* const translation = await translateToPirate(joke);
|
|
187
|
-
* const signature = await generateSignature(translation);
|
|
188
|
-
* return translation + "\n\n" + signature;
|
|
189
|
-
* });
|
|
190
|
-
*
|
|
191
|
-
* @example
|
|
192
|
-
* // Using thisArg to preserve class context in LLM service
|
|
193
|
-
* class AIServiceClient {
|
|
194
|
-
* private apiKey: string;
|
|
195
|
-
* private chatHistory: Message[];
|
|
196
|
-
*
|
|
197
|
-
* async generateResponse(prompt: string) {
|
|
198
|
-
* // Method that uses this.apiKey and this.chatHistory
|
|
199
|
-
* const completion = await openai.chat.completions.create({
|
|
200
|
-
* model: "gpt-4",
|
|
201
|
-
* messages: [...this.chatHistory, { role: "user", content: prompt }],
|
|
202
|
-
* api_key: this.apiKey
|
|
203
|
-
* });
|
|
204
|
-
* return completion.choices[0].message.content;
|
|
205
|
-
* }
|
|
206
|
-
*
|
|
207
|
-
* async processConversation(prompt: string, conversationId: string) {
|
|
208
|
-
* // Pass this as thisArg to preserve context
|
|
209
|
-
* return await interaction.withWorkflow(
|
|
210
|
-
* {
|
|
211
|
-
* name: "conversation_flow",
|
|
212
|
-
* properties: {
|
|
213
|
-
* request_source: "mobile_app",
|
|
214
|
-
* conversation_stage: "follow_up",
|
|
215
|
-
* user_subscription: "premium",
|
|
216
|
-
* locale: "en-US"
|
|
217
|
-
* }
|
|
218
|
-
* },
|
|
219
|
-
* this.generateResponse,
|
|
220
|
-
* this, // thisArg to access this.apiKey and this.chatHistory
|
|
221
|
-
* prompt
|
|
222
|
-
* );
|
|
223
|
-
* }
|
|
224
|
-
* }
|
|
225
|
-
*/
|
|
226
|
-
withWorkflow<T>(params: WorkflowParams | string, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): Promise<T>;
|
|
227
147
|
/**
|
|
228
148
|
* Creates a traced task that executes the provided function.
|
|
229
149
|
*
|
|
230
|
-
* @
|
|
231
|
-
* @
|
|
232
|
-
* @param fn The function to execute within the traced task
|
|
233
|
-
* @param thisArg Optional. The value to use as `this` when executing the function.
|
|
234
|
-
* Useful when passing methods from classes that require their class instance context.
|
|
235
|
-
* @param args Additional arguments to pass to the function
|
|
236
|
-
* @returns A promise that resolves to the function's return value
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* // LLM task with business metadata
|
|
240
|
-
* await interaction.withTask({
|
|
241
|
-
* name: "joke_creation",
|
|
242
|
-
* kind: "llm",
|
|
243
|
-
* properties: {
|
|
244
|
-
* request_source: "web",
|
|
245
|
-
* feature_flag: "beta_jokes",
|
|
246
|
-
* experiment_group: "creative_boost",
|
|
247
|
-
* user_segment: "developer"
|
|
248
|
-
* }
|
|
249
|
-
* }, async () => {
|
|
250
|
-
* const completion = await openai.chat.completions.create({
|
|
251
|
-
* model: "gpt-3.5-turbo",
|
|
252
|
-
* temperature: 0.7,
|
|
253
|
-
* max_tokens: 2048,
|
|
254
|
-
* messages: [
|
|
255
|
-
* { role: "system", content: "You are a helpful assistant." },
|
|
256
|
-
* { role: "user", content: "I can't log into my account." }
|
|
257
|
-
* ]
|
|
258
|
-
* });
|
|
259
|
-
* return completion.choices[0].message.content;
|
|
260
|
-
* });
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* // Using thisArg with an embedding service
|
|
264
|
-
* class EmbeddingService {
|
|
265
|
-
* private embedModel: string;
|
|
266
|
-
* private dimension: number;
|
|
267
|
-
*
|
|
268
|
-
* async embedText(text: string) {
|
|
269
|
-
* // Uses this.embedModel and this.dimension
|
|
270
|
-
* const embedding = await openai.embeddings.create({
|
|
271
|
-
* model: this.embedModel,
|
|
272
|
-
* input: text
|
|
273
|
-
* });
|
|
274
|
-
* return embedding.data[0].embedding.slice(0, this.dimension);
|
|
275
|
-
* }
|
|
276
|
-
*
|
|
277
|
-
* async getEmbedding(document: string, docId: string) {
|
|
278
|
-
* return interaction.withTask(
|
|
279
|
-
* {
|
|
280
|
-
* name: "text_embedding",
|
|
281
|
-
* kind: "llm",
|
|
282
|
-
* properties: {
|
|
283
|
-
* document_type: "knowledge_base",
|
|
284
|
-
* doc_id: docId,
|
|
285
|
-
* language: "en",
|
|
286
|
-
* content_source: "internal_wiki"
|
|
287
|
-
* }
|
|
288
|
-
* },
|
|
289
|
-
* this.embedText,
|
|
290
|
-
* this, // thisArg preserves access to this.embedModel and this.dimension
|
|
291
|
-
* document // Text to be embedded
|
|
292
|
-
* );
|
|
293
|
-
* }
|
|
294
|
-
* }
|
|
150
|
+
* @param params TaskParams object with task configuration
|
|
151
|
+
* @returns A span that can be used to record a task
|
|
295
152
|
*/
|
|
296
|
-
|
|
153
|
+
withSpan<T>(params: SpanParams, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): Promise<T>;
|
|
297
154
|
/**
|
|
298
155
|
* Creates a task span that can be used to manually record a task.
|
|
299
156
|
*
|
|
300
157
|
* @param params TaskParams object with task configuration
|
|
301
158
|
* @returns A span that can be used to record a task
|
|
302
159
|
*/
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Executes a function with additional context properties.
|
|
306
|
-
*
|
|
307
|
-
* @template T The return type of the function
|
|
308
|
-
* @param properties Object containing context properties to add
|
|
309
|
-
* @param fn The function to execute with additional context
|
|
310
|
-
* @param thisArg Optional. The value to use as `this` when executing the function.
|
|
311
|
-
* Useful when passing methods from classes that require their class instance context.
|
|
312
|
-
* @param args Additional arguments to pass to the function
|
|
313
|
-
* @returns The function's return value or a promise that resolves to it
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* // Adding business context to LLM calls
|
|
317
|
-
* const result = interaction.withContext(
|
|
318
|
-
* {
|
|
319
|
-
* user_intent: "troubleshooting",
|
|
320
|
-
* product_area: "authentication",
|
|
321
|
-
* session_priority: "high",
|
|
322
|
-
* customer_tier: "enterprise"
|
|
323
|
-
* },
|
|
324
|
-
* async () => {
|
|
325
|
-
* const completion = await openai.chat.completions.create({
|
|
326
|
-
* model: "gpt-4",
|
|
327
|
-
* temperature: 0.7,
|
|
328
|
-
* max_tokens: 2048,
|
|
329
|
-
* messages: [
|
|
330
|
-
* { role: "system", content: "You are a helpful assistant." },
|
|
331
|
-
* { role: "user", content: "I can't log into my account." }
|
|
332
|
-
* ]
|
|
333
|
-
* });
|
|
334
|
-
* return completion.choices[0].message.content;
|
|
335
|
-
* }
|
|
336
|
-
* );
|
|
337
|
-
*
|
|
338
|
-
* @example
|
|
339
|
-
* // Using thisArg with semantic search application
|
|
340
|
-
* class SearchService {
|
|
341
|
-
* private vectorDB: VectorDatabase;
|
|
342
|
-
* private queryProcessor: QueryProcessor;
|
|
343
|
-
*
|
|
344
|
-
* async findRelevantDocuments(query: string) {
|
|
345
|
-
* // Uses this.vectorDB and this.queryProcessor
|
|
346
|
-
* const processedQuery = this.queryProcessor.enhance(query);
|
|
347
|
-
* return this.vectorDB.similaritySearch(processedQuery, 5);
|
|
348
|
-
* }
|
|
349
|
-
*
|
|
350
|
-
* async search(userQuery: string, userId: string) {
|
|
351
|
-
* return interaction.withContext(
|
|
352
|
-
* {
|
|
353
|
-
* search_type: "semantic",
|
|
354
|
-
* user_history: "returning_user",
|
|
355
|
-
* search_filter: "documentation",
|
|
356
|
-
* analytics_source: "help_center"
|
|
357
|
-
* },
|
|
358
|
-
* this.findRelevantDocuments,
|
|
359
|
-
* this, // thisArg preserves access to this.vectorDB and this.queryProcessor
|
|
360
|
-
* userQuery // Search query to process
|
|
361
|
-
* );
|
|
362
|
-
* }
|
|
363
|
-
* }
|
|
364
|
-
*/
|
|
365
|
-
withContext<T>(properties: Record<string, string>, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): T | Promise<T>;
|
|
160
|
+
startSpan(params: SpanParams): Span;
|
|
366
161
|
/**
|
|
367
162
|
* Sets multiple properties on the interaction context.
|
|
368
163
|
*
|
|
@@ -495,14 +290,14 @@ declare class Raindrop {
|
|
|
495
290
|
resumeInteraction(eventId: string): Interaction;
|
|
496
291
|
/**
|
|
497
292
|
* Track AI events. In addiiton to normal event properties, you can provide an "input", "output", or "model" parameter.
|
|
498
|
-
* It takes an AiTrackEvent as input and sends it to the /track-ai endpoint of the
|
|
293
|
+
* It takes an AiTrackEvent as input and sends it to the /track-ai endpoint of the raindrop api.
|
|
499
294
|
*
|
|
500
295
|
* @param event - The AiTrackEvent (you must specify at least one of input/output properties)
|
|
501
296
|
* @returns A Promise that resolves when the event has been successfully sent.
|
|
502
297
|
*
|
|
503
298
|
* Example usage:
|
|
504
299
|
* ```typescript
|
|
505
|
-
*
|
|
300
|
+
* raindrop.track_ai({
|
|
506
301
|
* event: "chat", //name of the event
|
|
507
302
|
* model: "claude", //optional
|
|
508
303
|
* input: "what's up?", // input or output is required
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -164,7 +164,7 @@ var v4_default = v4;
|
|
|
164
164
|
// package.json
|
|
165
165
|
var package_default = {
|
|
166
166
|
name: "raindrop-ai",
|
|
167
|
-
version: "0.0.
|
|
167
|
+
version: "0.0.29",
|
|
168
168
|
main: "dist/index.js",
|
|
169
169
|
module: "dist/index.mjs",
|
|
170
170
|
types: "dist/index.d.ts",
|
|
@@ -376,26 +376,16 @@ var NonLiveInteraction = class {
|
|
|
376
376
|
this.context = context;
|
|
377
377
|
this.analytics = analytics;
|
|
378
378
|
}
|
|
379
|
-
|
|
379
|
+
withSpan(_params, fn, thisArg, ...args) {
|
|
380
380
|
try {
|
|
381
381
|
return Promise.resolve(fn.apply(thisArg, args));
|
|
382
382
|
} catch (error) {
|
|
383
383
|
return Promise.reject(error);
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
|
-
|
|
387
|
-
try {
|
|
388
|
-
return Promise.resolve(fn.apply(thisArg, args));
|
|
389
|
-
} catch (error) {
|
|
390
|
-
return Promise.reject(error);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
createTask(_params) {
|
|
386
|
+
startSpan(_params) {
|
|
394
387
|
return NO_OP_SPAN;
|
|
395
388
|
}
|
|
396
|
-
withContext(_properties, fn, thisArg, ...args) {
|
|
397
|
-
return fn.apply(thisArg, args);
|
|
398
|
-
}
|
|
399
389
|
setProperties(_properties) {
|
|
400
390
|
var _a;
|
|
401
391
|
(_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
|
|
@@ -493,15 +483,15 @@ var Raindrop = class {
|
|
|
493
483
|
this.isEnvWithLocalStorage = typeof localStorage !== "undefined";
|
|
494
484
|
var _a, _b, _c, _d, _e;
|
|
495
485
|
if (!config.writeKey) {
|
|
496
|
-
throw new Error("A writeKey is required to use
|
|
486
|
+
throw new Error("A writeKey is required to use Raindrop");
|
|
497
487
|
}
|
|
498
488
|
this.writeKey = config.writeKey;
|
|
499
|
-
this.apiUrl = (_a = this.formatEndpoint(config.endpoint)) != null ? _a : `https://
|
|
489
|
+
this.apiUrl = (_a = this.formatEndpoint(config.endpoint)) != null ? _a : `https://api.raindrop.ai/v1/`;
|
|
500
490
|
this.bufferSize = (_b = config.bufferSize) != null ? _b : 50;
|
|
501
491
|
this.bufferTimeout = (_c = config.bufferTimeout) != null ? _c : 1e3;
|
|
502
492
|
this.buffer = new Array();
|
|
503
493
|
if (this.isEnvWithLocalStorage) {
|
|
504
|
-
const storedBuffer = localStorage.getItem("
|
|
494
|
+
const storedBuffer = localStorage.getItem("raindrop_analytics_buffer");
|
|
505
495
|
if (storedBuffer) {
|
|
506
496
|
this.buffer = JSON.parse(storedBuffer);
|
|
507
497
|
this.flush();
|
|
@@ -540,14 +530,14 @@ var Raindrop = class {
|
|
|
540
530
|
}
|
|
541
531
|
/**
|
|
542
532
|
* Track AI events. In addiiton to normal event properties, you can provide an "input", "output", or "model" parameter.
|
|
543
|
-
* It takes an AiTrackEvent as input and sends it to the /track-ai endpoint of the
|
|
533
|
+
* It takes an AiTrackEvent as input and sends it to the /track-ai endpoint of the raindrop api.
|
|
544
534
|
*
|
|
545
535
|
* @param event - The AiTrackEvent (you must specify at least one of input/output properties)
|
|
546
536
|
* @returns A Promise that resolves when the event has been successfully sent.
|
|
547
537
|
*
|
|
548
538
|
* Example usage:
|
|
549
539
|
* ```typescript
|
|
550
|
-
*
|
|
540
|
+
* raindrop.track_ai({
|
|
551
541
|
* event: "chat", //name of the event
|
|
552
542
|
* model: "claude", //optional
|
|
553
543
|
* input: "what's up?", // input or output is required
|
|
@@ -575,7 +565,7 @@ var Raindrop = class {
|
|
|
575
565
|
const parsedAttachments = AttachmentSchema.array().safeParse(attachments != null ? attachments : []);
|
|
576
566
|
if (!parsedAttachments.success) {
|
|
577
567
|
console.warn(
|
|
578
|
-
`[
|
|
568
|
+
`[raindrop] Invalid attachments provided to .track_ai(): ${this.formatZodError(parsedAttachments.error)}`
|
|
579
569
|
);
|
|
580
570
|
return;
|
|
581
571
|
}
|
|
@@ -593,7 +583,7 @@ var Raindrop = class {
|
|
|
593
583
|
});
|
|
594
584
|
if (!parsed.success) {
|
|
595
585
|
console.warn(
|
|
596
|
-
`[
|
|
586
|
+
`[raindrop] Invalid data provided to .track_ai(): ${this.formatZodError(parsed.error)}`
|
|
597
587
|
);
|
|
598
588
|
return;
|
|
599
589
|
}
|
|
@@ -605,7 +595,7 @@ var Raindrop = class {
|
|
|
605
595
|
const size = this.getSize(toSave);
|
|
606
596
|
if (size > MAX_INGEST_SIZE_BYTES) {
|
|
607
597
|
console.warn(
|
|
608
|
-
`[
|
|
598
|
+
`[raindrop] Events larger than ${(MAX_INGEST_SIZE_BYTES / (1024 * 1024)).toFixed(2)} MB may have properties truncated - an event of size ${(size / (1024 * 1024)).toFixed(2)} MB was logged`
|
|
609
599
|
);
|
|
610
600
|
}
|
|
611
601
|
this.saveToBuffer({
|
|
@@ -627,7 +617,7 @@ var Raindrop = class {
|
|
|
627
617
|
});
|
|
628
618
|
if (!parsed.success) {
|
|
629
619
|
console.warn(
|
|
630
|
-
`[
|
|
620
|
+
`[raindrop] Invalid data provided to .setUserDetails(): ${this.formatZodError(parsed.error)}`
|
|
631
621
|
);
|
|
632
622
|
return;
|
|
633
623
|
}
|
|
@@ -652,7 +642,7 @@ var Raindrop = class {
|
|
|
652
642
|
});
|
|
653
643
|
if (!parsed.success) {
|
|
654
644
|
console.warn(
|
|
655
|
-
`[
|
|
645
|
+
`[raindrop] Invalid data provided to .trackSignal(): ${this.formatZodError(parsed.error)}`
|
|
656
646
|
);
|
|
657
647
|
return;
|
|
658
648
|
}
|
|
@@ -677,7 +667,7 @@ var Raindrop = class {
|
|
|
677
667
|
}
|
|
678
668
|
saveToBuffer(event) {
|
|
679
669
|
if (this.isEnvWithLocalStorage) {
|
|
680
|
-
localStorage.setItem("
|
|
670
|
+
localStorage.setItem("raindrop_analytics_buffer", JSON.stringify(this.buffer));
|
|
681
671
|
if (event == null ? void 0 : event.properties) {
|
|
682
672
|
event.properties = { ...event.properties, localStorage: "true" };
|
|
683
673
|
}
|
|
@@ -705,7 +695,7 @@ var Raindrop = class {
|
|
|
705
695
|
const currentBuffer = this.buffer;
|
|
706
696
|
this.buffer = new Array();
|
|
707
697
|
if (this.isEnvWithLocalStorage) {
|
|
708
|
-
localStorage.removeItem("
|
|
698
|
+
localStorage.removeItem("raindrop_analytics_buffer");
|
|
709
699
|
}
|
|
710
700
|
const events = currentBuffer.filter((e) => e.type === "event");
|
|
711
701
|
const aiEvents = currentBuffer.filter((e) => e.type === "ai");
|
|
@@ -733,14 +723,14 @@ var Raindrop = class {
|
|
|
733
723
|
throw new Error(response.statusText);
|
|
734
724
|
}
|
|
735
725
|
if (this.debugLogs) {
|
|
736
|
-
console.log("[
|
|
726
|
+
console.log("[raindrop] Success: " + JSON.stringify(response.status));
|
|
737
727
|
}
|
|
738
728
|
return response;
|
|
739
729
|
} catch (error) {
|
|
740
730
|
if (error.response) {
|
|
741
|
-
console.error("[
|
|
731
|
+
console.error("[raindrop] Error in response: " + error.response.data);
|
|
742
732
|
} else {
|
|
743
|
-
console.error("[
|
|
733
|
+
console.error("[raindrop] Error: " + error.message);
|
|
744
734
|
}
|
|
745
735
|
}
|
|
746
736
|
}
|
|
@@ -789,7 +779,7 @@ var Raindrop = class {
|
|
|
789
779
|
_trackAiPartial(event) {
|
|
790
780
|
const { eventId, isPending, ...rest } = event;
|
|
791
781
|
if (!eventId) {
|
|
792
|
-
console.warn("[
|
|
782
|
+
console.warn("[raindrop] trackAiPartial requires an eventId.");
|
|
793
783
|
return;
|
|
794
784
|
}
|
|
795
785
|
const existingEvent = this.partialEventBuffer.get(eventId) || {};
|
|
@@ -812,14 +802,14 @@ var Raindrop = class {
|
|
|
812
802
|
try {
|
|
813
803
|
await this.flushPartialEvent(eventId);
|
|
814
804
|
} catch (e) {
|
|
815
|
-
console.error(`[
|
|
805
|
+
console.error(`[raindrop] Error during timed flush for partial event ${eventId}:`, e);
|
|
816
806
|
}
|
|
817
807
|
})();
|
|
818
808
|
}, PARTIAL_EVENT_TIMEOUT);
|
|
819
809
|
this.partialEventTimeouts.set(eventId, newTimeout);
|
|
820
810
|
if (this.debugLogs) {
|
|
821
811
|
console.log(
|
|
822
|
-
`[
|
|
812
|
+
`[raindrop] Updated partial event buffer for eventId: ${eventId}. Timeout reset (20s). Event: ${JSON.stringify(mergedEvent)}`
|
|
823
813
|
);
|
|
824
814
|
}
|
|
825
815
|
}
|
|
@@ -840,7 +830,7 @@ var Raindrop = class {
|
|
|
840
830
|
if (!accumulatedEvent) {
|
|
841
831
|
if (this.debugLogs) {
|
|
842
832
|
console.log(
|
|
843
|
-
`[
|
|
833
|
+
`[raindrop] No accumulated event found for eventId: ${eventId} during flush (potentially already flushed or cleared).`
|
|
844
834
|
);
|
|
845
835
|
}
|
|
846
836
|
return;
|
|
@@ -885,7 +875,7 @@ var Raindrop = class {
|
|
|
885
875
|
const parsed = PartialClientAiTrack.partial().safeParse(eventToSend);
|
|
886
876
|
if (!parsed.success) {
|
|
887
877
|
console.warn(
|
|
888
|
-
`[
|
|
878
|
+
`[raindrop] Invalid accumulated data for partial eventId ${eventId}. Event not sent. Errors: ${this.formatZodError(parsed.error)} Data: ${JSON.stringify(eventToSend)}`
|
|
889
879
|
);
|
|
890
880
|
return;
|
|
891
881
|
}
|
|
@@ -896,11 +886,11 @@ var Raindrop = class {
|
|
|
896
886
|
const size = this.getSize(finalData);
|
|
897
887
|
if (size > MAX_INGEST_SIZE_BYTES) {
|
|
898
888
|
console.warn(
|
|
899
|
-
`[
|
|
889
|
+
`[raindrop] Accumulated partial event ${eventId} is larger than ${(MAX_INGEST_SIZE_BYTES / (1024 * 1024)).toFixed(2)} MB and may have properties truncated. Size: ${(size / (1024 * 1024)).toFixed(2)} MB`
|
|
900
890
|
);
|
|
901
891
|
}
|
|
902
892
|
if (this.debugLogs) {
|
|
903
|
-
console.log(`[
|
|
893
|
+
console.log(`[raindrop] Flushing partial event for eventId: ${eventId}`);
|
|
904
894
|
}
|
|
905
895
|
await this.sendPartialEvent(finalData);
|
|
906
896
|
}
|
|
@@ -923,20 +913,20 @@ var Raindrop = class {
|
|
|
923
913
|
if (!response.ok) {
|
|
924
914
|
const errorBody = await response.text();
|
|
925
915
|
console.error(
|
|
926
|
-
`[
|
|
916
|
+
`[raindrop] Error sending partial event ${event.event_id} to ${endpoint}: ${response.status} ${response.statusText}`,
|
|
927
917
|
errorBody
|
|
928
918
|
);
|
|
929
919
|
throw new Error(`HTTP ${response.status} ${response.statusText}`);
|
|
930
920
|
}
|
|
931
921
|
if (this.debugLogs) {
|
|
932
922
|
console.log(
|
|
933
|
-
`[
|
|
923
|
+
`[raindrop] Successfully sent partial event ${event.event_id} to ${endpoint}: ${response.status}`
|
|
934
924
|
);
|
|
935
925
|
}
|
|
936
926
|
return response;
|
|
937
927
|
} catch (error) {
|
|
938
928
|
console.error(
|
|
939
|
-
`[
|
|
929
|
+
`[raindrop] Failed to send partial event ${event.event_id} to ${endpoint}: ${error.message}`
|
|
940
930
|
);
|
|
941
931
|
throw error;
|
|
942
932
|
}
|
|
@@ -944,22 +934,23 @@ var Raindrop = class {
|
|
|
944
934
|
async close() {
|
|
945
935
|
await this.flush();
|
|
946
936
|
if (this.debugLogs) {
|
|
947
|
-
console.log("[
|
|
937
|
+
console.log("[raindrop] Flushing pending partial events before closing...");
|
|
948
938
|
}
|
|
949
939
|
const pendingEventIds = Array.from(this.partialEventTimeouts.keys());
|
|
950
940
|
for (const eventId of pendingEventIds) {
|
|
951
941
|
try {
|
|
952
|
-
if (this.debugLogs)
|
|
942
|
+
if (this.debugLogs)
|
|
943
|
+
console.log(`[raindrop] Flushing partial event ${eventId} during close.`);
|
|
953
944
|
await this.flushPartialEvent(eventId);
|
|
954
945
|
} catch (e) {
|
|
955
|
-
console.error(`[
|
|
946
|
+
console.error(`[raindrop] Error flushing partial event ${eventId} during close:`, e);
|
|
956
947
|
}
|
|
957
948
|
}
|
|
958
949
|
this.partialEventBuffer.clear();
|
|
959
950
|
this.partialEventTimeouts.forEach(clearTimeout);
|
|
960
951
|
this.partialEventTimeouts.clear();
|
|
961
952
|
if (this.debugLogs) {
|
|
962
|
-
console.log("Closing
|
|
953
|
+
console.log("Closing Raindrop Analytics");
|
|
963
954
|
}
|
|
964
955
|
}
|
|
965
956
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
tracing,
|
|
3
3
|
v4_default
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WBQTVVE5.mjs";
|
|
5
5
|
|
|
6
6
|
// ../schemas/src/ingest/index.ts
|
|
7
7
|
import { z } from "zod";
|
|
@@ -84,7 +84,7 @@ var CategorizationRequestSchema = z.object({
|
|
|
84
84
|
// package.json
|
|
85
85
|
var package_default = {
|
|
86
86
|
name: "raindrop-ai",
|
|
87
|
-
version: "0.0.
|
|
87
|
+
version: "0.0.29",
|
|
88
88
|
main: "dist/index.js",
|
|
89
89
|
module: "dist/index.mjs",
|
|
90
90
|
types: "dist/index.d.ts",
|
|
@@ -281,15 +281,15 @@ var Raindrop = class {
|
|
|
281
281
|
this.isEnvWithLocalStorage = typeof localStorage !== "undefined";
|
|
282
282
|
var _a, _b, _c, _d, _e;
|
|
283
283
|
if (!config.writeKey) {
|
|
284
|
-
throw new Error("A writeKey is required to use
|
|
284
|
+
throw new Error("A writeKey is required to use Raindrop");
|
|
285
285
|
}
|
|
286
286
|
this.writeKey = config.writeKey;
|
|
287
|
-
this.apiUrl = (_a = this.formatEndpoint(config.endpoint)) != null ? _a : `https://
|
|
287
|
+
this.apiUrl = (_a = this.formatEndpoint(config.endpoint)) != null ? _a : `https://api.raindrop.ai/v1/`;
|
|
288
288
|
this.bufferSize = (_b = config.bufferSize) != null ? _b : 50;
|
|
289
289
|
this.bufferTimeout = (_c = config.bufferTimeout) != null ? _c : 1e3;
|
|
290
290
|
this.buffer = new Array();
|
|
291
291
|
if (this.isEnvWithLocalStorage) {
|
|
292
|
-
const storedBuffer = localStorage.getItem("
|
|
292
|
+
const storedBuffer = localStorage.getItem("raindrop_analytics_buffer");
|
|
293
293
|
if (storedBuffer) {
|
|
294
294
|
this.buffer = JSON.parse(storedBuffer);
|
|
295
295
|
this.flush();
|
|
@@ -328,14 +328,14 @@ var Raindrop = class {
|
|
|
328
328
|
}
|
|
329
329
|
/**
|
|
330
330
|
* Track AI events. In addiiton to normal event properties, you can provide an "input", "output", or "model" parameter.
|
|
331
|
-
* It takes an AiTrackEvent as input and sends it to the /track-ai endpoint of the
|
|
331
|
+
* It takes an AiTrackEvent as input and sends it to the /track-ai endpoint of the raindrop api.
|
|
332
332
|
*
|
|
333
333
|
* @param event - The AiTrackEvent (you must specify at least one of input/output properties)
|
|
334
334
|
* @returns A Promise that resolves when the event has been successfully sent.
|
|
335
335
|
*
|
|
336
336
|
* Example usage:
|
|
337
337
|
* ```typescript
|
|
338
|
-
*
|
|
338
|
+
* raindrop.track_ai({
|
|
339
339
|
* event: "chat", //name of the event
|
|
340
340
|
* model: "claude", //optional
|
|
341
341
|
* input: "what's up?", // input or output is required
|
|
@@ -363,7 +363,7 @@ var Raindrop = class {
|
|
|
363
363
|
const parsedAttachments = AttachmentSchema.array().safeParse(attachments != null ? attachments : []);
|
|
364
364
|
if (!parsedAttachments.success) {
|
|
365
365
|
console.warn(
|
|
366
|
-
`[
|
|
366
|
+
`[raindrop] Invalid attachments provided to .track_ai(): ${this.formatZodError(parsedAttachments.error)}`
|
|
367
367
|
);
|
|
368
368
|
return;
|
|
369
369
|
}
|
|
@@ -381,7 +381,7 @@ var Raindrop = class {
|
|
|
381
381
|
});
|
|
382
382
|
if (!parsed.success) {
|
|
383
383
|
console.warn(
|
|
384
|
-
`[
|
|
384
|
+
`[raindrop] Invalid data provided to .track_ai(): ${this.formatZodError(parsed.error)}`
|
|
385
385
|
);
|
|
386
386
|
return;
|
|
387
387
|
}
|
|
@@ -393,7 +393,7 @@ var Raindrop = class {
|
|
|
393
393
|
const size = this.getSize(toSave);
|
|
394
394
|
if (size > MAX_INGEST_SIZE_BYTES) {
|
|
395
395
|
console.warn(
|
|
396
|
-
`[
|
|
396
|
+
`[raindrop] Events larger than ${(MAX_INGEST_SIZE_BYTES / (1024 * 1024)).toFixed(2)} MB may have properties truncated - an event of size ${(size / (1024 * 1024)).toFixed(2)} MB was logged`
|
|
397
397
|
);
|
|
398
398
|
}
|
|
399
399
|
this.saveToBuffer({
|
|
@@ -415,7 +415,7 @@ var Raindrop = class {
|
|
|
415
415
|
});
|
|
416
416
|
if (!parsed.success) {
|
|
417
417
|
console.warn(
|
|
418
|
-
`[
|
|
418
|
+
`[raindrop] Invalid data provided to .setUserDetails(): ${this.formatZodError(parsed.error)}`
|
|
419
419
|
);
|
|
420
420
|
return;
|
|
421
421
|
}
|
|
@@ -440,7 +440,7 @@ var Raindrop = class {
|
|
|
440
440
|
});
|
|
441
441
|
if (!parsed.success) {
|
|
442
442
|
console.warn(
|
|
443
|
-
`[
|
|
443
|
+
`[raindrop] Invalid data provided to .trackSignal(): ${this.formatZodError(parsed.error)}`
|
|
444
444
|
);
|
|
445
445
|
return;
|
|
446
446
|
}
|
|
@@ -465,7 +465,7 @@ var Raindrop = class {
|
|
|
465
465
|
}
|
|
466
466
|
saveToBuffer(event) {
|
|
467
467
|
if (this.isEnvWithLocalStorage) {
|
|
468
|
-
localStorage.setItem("
|
|
468
|
+
localStorage.setItem("raindrop_analytics_buffer", JSON.stringify(this.buffer));
|
|
469
469
|
if (event == null ? void 0 : event.properties) {
|
|
470
470
|
event.properties = { ...event.properties, localStorage: "true" };
|
|
471
471
|
}
|
|
@@ -493,7 +493,7 @@ var Raindrop = class {
|
|
|
493
493
|
const currentBuffer = this.buffer;
|
|
494
494
|
this.buffer = new Array();
|
|
495
495
|
if (this.isEnvWithLocalStorage) {
|
|
496
|
-
localStorage.removeItem("
|
|
496
|
+
localStorage.removeItem("raindrop_analytics_buffer");
|
|
497
497
|
}
|
|
498
498
|
const events = currentBuffer.filter((e) => e.type === "event");
|
|
499
499
|
const aiEvents = currentBuffer.filter((e) => e.type === "ai");
|
|
@@ -521,14 +521,14 @@ var Raindrop = class {
|
|
|
521
521
|
throw new Error(response.statusText);
|
|
522
522
|
}
|
|
523
523
|
if (this.debugLogs) {
|
|
524
|
-
console.log("[
|
|
524
|
+
console.log("[raindrop] Success: " + JSON.stringify(response.status));
|
|
525
525
|
}
|
|
526
526
|
return response;
|
|
527
527
|
} catch (error) {
|
|
528
528
|
if (error.response) {
|
|
529
|
-
console.error("[
|
|
529
|
+
console.error("[raindrop] Error in response: " + error.response.data);
|
|
530
530
|
} else {
|
|
531
|
-
console.error("[
|
|
531
|
+
console.error("[raindrop] Error: " + error.message);
|
|
532
532
|
}
|
|
533
533
|
}
|
|
534
534
|
}
|
|
@@ -577,7 +577,7 @@ var Raindrop = class {
|
|
|
577
577
|
_trackAiPartial(event) {
|
|
578
578
|
const { eventId, isPending, ...rest } = event;
|
|
579
579
|
if (!eventId) {
|
|
580
|
-
console.warn("[
|
|
580
|
+
console.warn("[raindrop] trackAiPartial requires an eventId.");
|
|
581
581
|
return;
|
|
582
582
|
}
|
|
583
583
|
const existingEvent = this.partialEventBuffer.get(eventId) || {};
|
|
@@ -600,14 +600,14 @@ var Raindrop = class {
|
|
|
600
600
|
try {
|
|
601
601
|
await this.flushPartialEvent(eventId);
|
|
602
602
|
} catch (e) {
|
|
603
|
-
console.error(`[
|
|
603
|
+
console.error(`[raindrop] Error during timed flush for partial event ${eventId}:`, e);
|
|
604
604
|
}
|
|
605
605
|
})();
|
|
606
606
|
}, PARTIAL_EVENT_TIMEOUT);
|
|
607
607
|
this.partialEventTimeouts.set(eventId, newTimeout);
|
|
608
608
|
if (this.debugLogs) {
|
|
609
609
|
console.log(
|
|
610
|
-
`[
|
|
610
|
+
`[raindrop] Updated partial event buffer for eventId: ${eventId}. Timeout reset (20s). Event: ${JSON.stringify(mergedEvent)}`
|
|
611
611
|
);
|
|
612
612
|
}
|
|
613
613
|
}
|
|
@@ -628,7 +628,7 @@ var Raindrop = class {
|
|
|
628
628
|
if (!accumulatedEvent) {
|
|
629
629
|
if (this.debugLogs) {
|
|
630
630
|
console.log(
|
|
631
|
-
`[
|
|
631
|
+
`[raindrop] No accumulated event found for eventId: ${eventId} during flush (potentially already flushed or cleared).`
|
|
632
632
|
);
|
|
633
633
|
}
|
|
634
634
|
return;
|
|
@@ -673,7 +673,7 @@ var Raindrop = class {
|
|
|
673
673
|
const parsed = PartialClientAiTrack.partial().safeParse(eventToSend);
|
|
674
674
|
if (!parsed.success) {
|
|
675
675
|
console.warn(
|
|
676
|
-
`[
|
|
676
|
+
`[raindrop] Invalid accumulated data for partial eventId ${eventId}. Event not sent. Errors: ${this.formatZodError(parsed.error)} Data: ${JSON.stringify(eventToSend)}`
|
|
677
677
|
);
|
|
678
678
|
return;
|
|
679
679
|
}
|
|
@@ -684,11 +684,11 @@ var Raindrop = class {
|
|
|
684
684
|
const size = this.getSize(finalData);
|
|
685
685
|
if (size > MAX_INGEST_SIZE_BYTES) {
|
|
686
686
|
console.warn(
|
|
687
|
-
`[
|
|
687
|
+
`[raindrop] Accumulated partial event ${eventId} is larger than ${(MAX_INGEST_SIZE_BYTES / (1024 * 1024)).toFixed(2)} MB and may have properties truncated. Size: ${(size / (1024 * 1024)).toFixed(2)} MB`
|
|
688
688
|
);
|
|
689
689
|
}
|
|
690
690
|
if (this.debugLogs) {
|
|
691
|
-
console.log(`[
|
|
691
|
+
console.log(`[raindrop] Flushing partial event for eventId: ${eventId}`);
|
|
692
692
|
}
|
|
693
693
|
await this.sendPartialEvent(finalData);
|
|
694
694
|
}
|
|
@@ -711,20 +711,20 @@ var Raindrop = class {
|
|
|
711
711
|
if (!response.ok) {
|
|
712
712
|
const errorBody = await response.text();
|
|
713
713
|
console.error(
|
|
714
|
-
`[
|
|
714
|
+
`[raindrop] Error sending partial event ${event.event_id} to ${endpoint}: ${response.status} ${response.statusText}`,
|
|
715
715
|
errorBody
|
|
716
716
|
);
|
|
717
717
|
throw new Error(`HTTP ${response.status} ${response.statusText}`);
|
|
718
718
|
}
|
|
719
719
|
if (this.debugLogs) {
|
|
720
720
|
console.log(
|
|
721
|
-
`[
|
|
721
|
+
`[raindrop] Successfully sent partial event ${event.event_id} to ${endpoint}: ${response.status}`
|
|
722
722
|
);
|
|
723
723
|
}
|
|
724
724
|
return response;
|
|
725
725
|
} catch (error) {
|
|
726
726
|
console.error(
|
|
727
|
-
`[
|
|
727
|
+
`[raindrop] Failed to send partial event ${event.event_id} to ${endpoint}: ${error.message}`
|
|
728
728
|
);
|
|
729
729
|
throw error;
|
|
730
730
|
}
|
|
@@ -732,22 +732,23 @@ var Raindrop = class {
|
|
|
732
732
|
async close() {
|
|
733
733
|
await this.flush();
|
|
734
734
|
if (this.debugLogs) {
|
|
735
|
-
console.log("[
|
|
735
|
+
console.log("[raindrop] Flushing pending partial events before closing...");
|
|
736
736
|
}
|
|
737
737
|
const pendingEventIds = Array.from(this.partialEventTimeouts.keys());
|
|
738
738
|
for (const eventId of pendingEventIds) {
|
|
739
739
|
try {
|
|
740
|
-
if (this.debugLogs)
|
|
740
|
+
if (this.debugLogs)
|
|
741
|
+
console.log(`[raindrop] Flushing partial event ${eventId} during close.`);
|
|
741
742
|
await this.flushPartialEvent(eventId);
|
|
742
743
|
} catch (e) {
|
|
743
|
-
console.error(`[
|
|
744
|
+
console.error(`[raindrop] Error flushing partial event ${eventId} during close:`, e);
|
|
744
745
|
}
|
|
745
746
|
}
|
|
746
747
|
this.partialEventBuffer.clear();
|
|
747
748
|
this.partialEventTimeouts.forEach(clearTimeout);
|
|
748
749
|
this.partialEventTimeouts.clear();
|
|
749
750
|
if (this.debugLogs) {
|
|
750
|
-
console.log("Closing
|
|
751
|
+
console.log("Closing Raindrop Analytics");
|
|
751
752
|
}
|
|
752
753
|
}
|
|
753
754
|
};
|
package/dist/tracing/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as traceloop from '@traceloop/node-server-sdk';
|
|
2
|
-
import { R as Raindrop, P as PartialAiTrackEvent, I as Interaction } from '../index-
|
|
2
|
+
import { R as Raindrop, P as PartialAiTrackEvent, I as Interaction } from '../index-BCw4PtuC.mjs';
|
|
3
3
|
import '@dawn/schemas/ingest';
|
|
4
4
|
import '@opentelemetry/api';
|
|
5
5
|
|
|
@@ -8,6 +8,7 @@ declare const tracing: (analytics: Raindrop, apiUrl: string, writeKey: string, o
|
|
|
8
8
|
getActiveInteraction(eventId: string): Interaction;
|
|
9
9
|
close(): void;
|
|
10
10
|
};
|
|
11
|
+
declare function initTracing(): void;
|
|
11
12
|
type Tracing = ReturnType<typeof tracing>;
|
|
12
13
|
|
|
13
|
-
export { type Tracing, tracing };
|
|
14
|
+
export { type Tracing, initTracing, tracing };
|
package/dist/tracing/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as traceloop from '@traceloop/node-server-sdk';
|
|
2
|
-
import { R as Raindrop, P as PartialAiTrackEvent, I as Interaction } from '../index-
|
|
2
|
+
import { R as Raindrop, P as PartialAiTrackEvent, I as Interaction } from '../index-BCw4PtuC.js';
|
|
3
3
|
import '@dawn/schemas/ingest';
|
|
4
4
|
import '@opentelemetry/api';
|
|
5
5
|
|
|
@@ -8,6 +8,7 @@ declare const tracing: (analytics: Raindrop, apiUrl: string, writeKey: string, o
|
|
|
8
8
|
getActiveInteraction(eventId: string): Interaction;
|
|
9
9
|
close(): void;
|
|
10
10
|
};
|
|
11
|
+
declare function initTracing(): void;
|
|
11
12
|
type Tracing = ReturnType<typeof tracing>;
|
|
12
13
|
|
|
13
|
-
export { type Tracing, tracing };
|
|
14
|
+
export { type Tracing, initTracing, tracing };
|
package/dist/tracing/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/tracing/index.ts
|
|
31
31
|
var tracing_exports = {};
|
|
32
32
|
__export(tracing_exports, {
|
|
33
|
+
initTracing: () => initTracing,
|
|
33
34
|
tracing: () => tracing
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(tracing_exports);
|
|
@@ -108,32 +109,12 @@ var LiveInteraction = class {
|
|
|
108
109
|
this.tracer = import_api.trace.getTracer("traceloop.tracer");
|
|
109
110
|
this.traceId = traceId;
|
|
110
111
|
}
|
|
111
|
-
async
|
|
112
|
-
const workflowName = typeof params === "string" ? params : params.name;
|
|
113
|
-
const properties = typeof params === "string" ? getPropertiesFromContext(this.context) : {
|
|
114
|
-
...getPropertiesFromContext(this.context),
|
|
115
|
-
...params.properties || {}
|
|
116
|
-
};
|
|
117
|
-
const inputParameters = typeof params === "string" ? void 0 : params.inputParameters;
|
|
118
|
-
return traceloop.withWorkflow(
|
|
119
|
-
{
|
|
120
|
-
name: workflowName,
|
|
121
|
-
associationProperties: properties,
|
|
122
|
-
inputParameters
|
|
123
|
-
},
|
|
124
|
-
fn,
|
|
125
|
-
thisArg,
|
|
126
|
-
...args
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
async withTask(params, fn, thisArg, ...args) {
|
|
112
|
+
async withSpan(params, fn, thisArg, ...args) {
|
|
130
113
|
const taskName = typeof params === "string" ? params : params.name;
|
|
131
114
|
const properties = typeof params === "string" ? {
|
|
132
|
-
...getPropertiesFromContext(this.context)
|
|
133
|
-
task_kind: "internal"
|
|
115
|
+
...getPropertiesFromContext(this.context)
|
|
134
116
|
} : {
|
|
135
117
|
...getPropertiesFromContext(this.context),
|
|
136
|
-
task_kind: params.kind,
|
|
137
118
|
...params.properties || {}
|
|
138
119
|
};
|
|
139
120
|
const inputParameters = typeof params === "string" ? void 0 : params.inputParameters;
|
|
@@ -148,7 +129,7 @@ var LiveInteraction = class {
|
|
|
148
129
|
...args
|
|
149
130
|
);
|
|
150
131
|
}
|
|
151
|
-
|
|
132
|
+
startSpan(params) {
|
|
152
133
|
const { name, properties = {} } = params;
|
|
153
134
|
const span = this.tracer.startSpan(name);
|
|
154
135
|
span.setAttributes(getPropertiesFromContext(this.context));
|
|
@@ -158,18 +139,6 @@ var LiveInteraction = class {
|
|
|
158
139
|
});
|
|
159
140
|
return span;
|
|
160
141
|
}
|
|
161
|
-
withContext(properties, fn, thisArg, ...args) {
|
|
162
|
-
const newContext = {
|
|
163
|
-
...this.context,
|
|
164
|
-
properties: { ...this.context.properties, ...properties }
|
|
165
|
-
};
|
|
166
|
-
return traceloop.withAssociationProperties(
|
|
167
|
-
getPropertiesFromContext(newContext),
|
|
168
|
-
fn,
|
|
169
|
-
thisArg,
|
|
170
|
-
...args
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
142
|
setProperties(properties) {
|
|
174
143
|
var _a;
|
|
175
144
|
this.context.properties = { ...this.context.properties, ...properties };
|
|
@@ -267,26 +236,16 @@ var NonLiveInteraction = class {
|
|
|
267
236
|
this.context = context2;
|
|
268
237
|
this.analytics = analytics;
|
|
269
238
|
}
|
|
270
|
-
|
|
271
|
-
try {
|
|
272
|
-
return Promise.resolve(fn.apply(thisArg, args));
|
|
273
|
-
} catch (error) {
|
|
274
|
-
return Promise.reject(error);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
withTask(_params, fn, thisArg, ...args) {
|
|
239
|
+
withSpan(_params, fn, thisArg, ...args) {
|
|
278
240
|
try {
|
|
279
241
|
return Promise.resolve(fn.apply(thisArg, args));
|
|
280
242
|
} catch (error) {
|
|
281
243
|
return Promise.reject(error);
|
|
282
244
|
}
|
|
283
245
|
}
|
|
284
|
-
|
|
246
|
+
startSpan(_params) {
|
|
285
247
|
return NO_OP_SPAN;
|
|
286
248
|
}
|
|
287
|
-
withContext(_properties, fn, thisArg, ...args) {
|
|
288
|
-
return fn.apply(thisArg, args);
|
|
289
|
-
}
|
|
290
249
|
setProperties(_properties) {
|
|
291
250
|
var _a;
|
|
292
251
|
(_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
|
|
@@ -398,8 +357,11 @@ var tracing = (analytics, apiUrl, writeKey, options) => {
|
|
|
398
357
|
}
|
|
399
358
|
};
|
|
400
359
|
};
|
|
401
|
-
|
|
360
|
+
function initTracing() {
|
|
361
|
+
_setImplementation(tracing);
|
|
362
|
+
}
|
|
402
363
|
// Annotate the CommonJS export names for ESM import in node:
|
|
403
364
|
0 && (module.exports = {
|
|
365
|
+
initTracing,
|
|
404
366
|
tracing
|
|
405
367
|
});
|
package/dist/tracing/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
NonLiveInteraction,
|
|
3
3
|
_setImplementation,
|
|
4
4
|
v4_default
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-WBQTVVE5.mjs";
|
|
6
6
|
|
|
7
7
|
// src/tracing/index.ts
|
|
8
8
|
import { context, trace as trace2 } from "@opentelemetry/api";
|
|
@@ -31,32 +31,12 @@ var LiveInteraction = class {
|
|
|
31
31
|
this.tracer = trace.getTracer("traceloop.tracer");
|
|
32
32
|
this.traceId = traceId;
|
|
33
33
|
}
|
|
34
|
-
async
|
|
35
|
-
const workflowName = typeof params === "string" ? params : params.name;
|
|
36
|
-
const properties = typeof params === "string" ? getPropertiesFromContext(this.context) : {
|
|
37
|
-
...getPropertiesFromContext(this.context),
|
|
38
|
-
...params.properties || {}
|
|
39
|
-
};
|
|
40
|
-
const inputParameters = typeof params === "string" ? void 0 : params.inputParameters;
|
|
41
|
-
return traceloop.withWorkflow(
|
|
42
|
-
{
|
|
43
|
-
name: workflowName,
|
|
44
|
-
associationProperties: properties,
|
|
45
|
-
inputParameters
|
|
46
|
-
},
|
|
47
|
-
fn,
|
|
48
|
-
thisArg,
|
|
49
|
-
...args
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
async withTask(params, fn, thisArg, ...args) {
|
|
34
|
+
async withSpan(params, fn, thisArg, ...args) {
|
|
53
35
|
const taskName = typeof params === "string" ? params : params.name;
|
|
54
36
|
const properties = typeof params === "string" ? {
|
|
55
|
-
...getPropertiesFromContext(this.context)
|
|
56
|
-
task_kind: "internal"
|
|
37
|
+
...getPropertiesFromContext(this.context)
|
|
57
38
|
} : {
|
|
58
39
|
...getPropertiesFromContext(this.context),
|
|
59
|
-
task_kind: params.kind,
|
|
60
40
|
...params.properties || {}
|
|
61
41
|
};
|
|
62
42
|
const inputParameters = typeof params === "string" ? void 0 : params.inputParameters;
|
|
@@ -71,7 +51,7 @@ var LiveInteraction = class {
|
|
|
71
51
|
...args
|
|
72
52
|
);
|
|
73
53
|
}
|
|
74
|
-
|
|
54
|
+
startSpan(params) {
|
|
75
55
|
const { name, properties = {} } = params;
|
|
76
56
|
const span = this.tracer.startSpan(name);
|
|
77
57
|
span.setAttributes(getPropertiesFromContext(this.context));
|
|
@@ -81,18 +61,6 @@ var LiveInteraction = class {
|
|
|
81
61
|
});
|
|
82
62
|
return span;
|
|
83
63
|
}
|
|
84
|
-
withContext(properties, fn, thisArg, ...args) {
|
|
85
|
-
const newContext = {
|
|
86
|
-
...this.context,
|
|
87
|
-
properties: { ...this.context.properties, ...properties }
|
|
88
|
-
};
|
|
89
|
-
return traceloop.withAssociationProperties(
|
|
90
|
-
getPropertiesFromContext(newContext),
|
|
91
|
-
fn,
|
|
92
|
-
thisArg,
|
|
93
|
-
...args
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
64
|
setProperties(properties) {
|
|
97
65
|
var _a;
|
|
98
66
|
this.context.properties = { ...this.context.properties, ...properties };
|
|
@@ -187,7 +155,10 @@ var tracing = (analytics, apiUrl, writeKey, options) => {
|
|
|
187
155
|
}
|
|
188
156
|
};
|
|
189
157
|
};
|
|
190
|
-
|
|
158
|
+
function initTracing() {
|
|
159
|
+
_setImplementation(tracing);
|
|
160
|
+
}
|
|
191
161
|
export {
|
|
162
|
+
initTracing,
|
|
192
163
|
tracing
|
|
193
164
|
};
|
package/dist/vercel/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LanguageModelV1, streamText, generateText, streamObject } from 'ai';
|
|
2
|
-
import { R as Raindrop, A as AiTrackEvent } from '../index-
|
|
2
|
+
import { R as Raindrop, A as AiTrackEvent } from '../index-BCw4PtuC.mjs';
|
|
3
3
|
import '@dawn/schemas/ingest';
|
|
4
4
|
import '@opentelemetry/api';
|
|
5
5
|
|
package/dist/vercel/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LanguageModelV1, streamText, generateText, streamObject } from 'ai';
|
|
2
|
-
import { R as Raindrop, A as AiTrackEvent } from '../index-
|
|
2
|
+
import { R as Raindrop, A as AiTrackEvent } from '../index-BCw4PtuC.js';
|
|
3
3
|
import '@dawn/schemas/ingest';
|
|
4
4
|
import '@opentelemetry/api';
|
|
5
5
|
|