raindrop-ai 0.0.64 → 0.0.66
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-BnPIaY-L.d.mts +581 -0
- package/dist/index-BnPIaY-L.d.ts +581 -0
- package/dist/index.d.mts +5 -490
- package/dist/index.d.ts +5 -490
- package/dist/index.js +4 -2
- package/dist/index.mjs +4 -2
- package/dist/tracing/index.d.mts +2 -3
- package/dist/tracing/index.d.ts +2 -3
- package/package.json +4 -2
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
import { Span as Span$1, HrTime, Attributes, SpanKind, SpanContext, SpanStatus, Link, Context } from '@opentelemetry/api';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { Resource } from '@opentelemetry/resources';
|
|
4
|
+
import { SpanProcessorOptions } from '@traceloop/node-server-sdk';
|
|
5
|
+
|
|
6
|
+
type BaseAttachment = {
|
|
7
|
+
attachment_id?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
value: string;
|
|
10
|
+
role: "input" | "output";
|
|
11
|
+
};
|
|
12
|
+
type CodeAttachment = BaseAttachment & {
|
|
13
|
+
type: "code";
|
|
14
|
+
language?: string;
|
|
15
|
+
};
|
|
16
|
+
type OtherAttachment = BaseAttachment & {
|
|
17
|
+
type: "text" | "image" | "iframe";
|
|
18
|
+
};
|
|
19
|
+
type Attachment = CodeAttachment | OtherAttachment;
|
|
20
|
+
/**
|
|
21
|
+
* Interface for tracking events.
|
|
22
|
+
*
|
|
23
|
+
* @param eventId - An optional event ID for the event.
|
|
24
|
+
* @param event - The name of the event.
|
|
25
|
+
* @param properties - An optional record of properties for the event.
|
|
26
|
+
* @param timestamp - An optional timestamp for the event.
|
|
27
|
+
* @param userId - The ID of the user. This is a required field.
|
|
28
|
+
* @param anonymousId - An optional anonymous ID for the user.
|
|
29
|
+
*/
|
|
30
|
+
interface TrackEvent {
|
|
31
|
+
eventId?: string;
|
|
32
|
+
event: string;
|
|
33
|
+
properties?: Record<string, any>;
|
|
34
|
+
timestamp?: string;
|
|
35
|
+
userId: string;
|
|
36
|
+
}
|
|
37
|
+
type BasicSignal = {
|
|
38
|
+
eventId: string;
|
|
39
|
+
name: "thumbs_up" | "thumbs_down" | string;
|
|
40
|
+
sentiment?: "POSITIVE" | "NEGATIVE";
|
|
41
|
+
timestamp?: string;
|
|
42
|
+
properties?: {
|
|
43
|
+
[key: string]: any;
|
|
44
|
+
};
|
|
45
|
+
attachmentId?: string;
|
|
46
|
+
};
|
|
47
|
+
type DefaultSignal = BasicSignal & {
|
|
48
|
+
type?: "default";
|
|
49
|
+
};
|
|
50
|
+
type FeedbackSignal = BasicSignal & {
|
|
51
|
+
type: "feedback";
|
|
52
|
+
comment?: string;
|
|
53
|
+
};
|
|
54
|
+
type EditSignal = BasicSignal & {
|
|
55
|
+
type: "edit";
|
|
56
|
+
after?: string;
|
|
57
|
+
};
|
|
58
|
+
type SignalEvent = DefaultSignal | FeedbackSignal | EditSignal;
|
|
59
|
+
/**
|
|
60
|
+
* Interface for identifying events.
|
|
61
|
+
*
|
|
62
|
+
* @param userId - The ID of the user. This is a required field.
|
|
63
|
+
* @param traits - An optional object of traits for the user.
|
|
64
|
+
* @param anonymousId - An optional anonymous ID for the user.
|
|
65
|
+
* TODO: ensure at least one out of userId or anonymousId is present
|
|
66
|
+
*/
|
|
67
|
+
interface IdentifyEvent {
|
|
68
|
+
userId: string;
|
|
69
|
+
traits?: object;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Type definition for AI tracking events.
|
|
73
|
+
* In addition to the properties of a TrackEvent, an AiTrackEvent may have a 'model' property.
|
|
74
|
+
* It must have at least one of 'input' or 'output' property.
|
|
75
|
+
*
|
|
76
|
+
* @property model - An optional model property for the even
|
|
77
|
+
* @property input - An optional input property for the event, required if output is not provided.
|
|
78
|
+
* @property output - An optional output property for the event, required if input is not provided.
|
|
79
|
+
*/
|
|
80
|
+
type AiTrackEvent = Omit<TrackEvent, "type"> & {
|
|
81
|
+
model?: string;
|
|
82
|
+
convoId?: string;
|
|
83
|
+
attachments?: Attachment[];
|
|
84
|
+
} & ({
|
|
85
|
+
input: string;
|
|
86
|
+
output?: string;
|
|
87
|
+
} | {
|
|
88
|
+
input?: string;
|
|
89
|
+
output: string;
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Type definition for partial AI tracking events used with trackAiPartial.
|
|
93
|
+
* Requires an eventId to correlate partial updates. All other fields are optional.
|
|
94
|
+
*/
|
|
95
|
+
type PartialAiTrackEvent = Partial<AiTrackEvent> & {
|
|
96
|
+
eventId: string;
|
|
97
|
+
isPending?: boolean;
|
|
98
|
+
};
|
|
99
|
+
declare const AttachmentTypeSchema: z.ZodEnum<["code", "text", "image", "iframe"]>;
|
|
100
|
+
type AttachmentType = z.infer<typeof AttachmentTypeSchema>;
|
|
101
|
+
/**
|
|
102
|
+
* Configuration for initializing a trace interaction.
|
|
103
|
+
*
|
|
104
|
+
* This interface defines the context required to create and track an AI
|
|
105
|
+
* interaction through its lifecycle. It includes identifiers for the user
|
|
106
|
+
* and conversation, as well as input/output content and attachments.
|
|
107
|
+
*
|
|
108
|
+
* @property userId - Optional unique identifier for the user
|
|
109
|
+
* @property convoId - Optional unique identifier for the conversation
|
|
110
|
+
* @property eventId - Optional unique identifier for this specific interaction event
|
|
111
|
+
* @property input - Optional input text from the user
|
|
112
|
+
* @property attachments - Optional array of attachments associated with this interaction
|
|
113
|
+
* @property properties - Optional key-value pairs for additional custom metadata
|
|
114
|
+
*/
|
|
115
|
+
interface TraceContext {
|
|
116
|
+
userId?: string;
|
|
117
|
+
convoId?: string;
|
|
118
|
+
eventId?: string;
|
|
119
|
+
input?: string;
|
|
120
|
+
event?: string;
|
|
121
|
+
attachments?: Attachment[];
|
|
122
|
+
properties?: Record<string, string>;
|
|
123
|
+
}
|
|
124
|
+
type BeginInteractionOptions = PartialAiTrackEvent & {
|
|
125
|
+
eventId: string;
|
|
126
|
+
};
|
|
127
|
+
type FinishInteractionOptions = Omit<PartialAiTrackEvent, "eventId"> & {
|
|
128
|
+
output: string;
|
|
129
|
+
eventId?: string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Configuration for a traced workflow.
|
|
133
|
+
*
|
|
134
|
+
* Workflows represent higher-level operations that might contain multiple
|
|
135
|
+
* tasks. They help organize traces into logical units of work.
|
|
136
|
+
*
|
|
137
|
+
* @property name - Name of the workflow for identification in traces
|
|
138
|
+
* @property inputParameters - Optional array of input parameters for the workflow
|
|
139
|
+
* @property properties - Optional key-value pairs for additional metadata
|
|
140
|
+
*/
|
|
141
|
+
interface WorkflowParams {
|
|
142
|
+
name: string;
|
|
143
|
+
inputParameters?: unknown[];
|
|
144
|
+
properties?: Record<string, string>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Configuration for a traced task.
|
|
148
|
+
*
|
|
149
|
+
* Tasks represent individual operations within a workflow, such as an LLM call,
|
|
150
|
+
* a tool invocation, a retrieval operation, or internal processing.
|
|
151
|
+
*
|
|
152
|
+
* @property name - Name of the task for identification in traces
|
|
153
|
+
* @property kind - Category of the task (llm, tool, retrival, or internal)
|
|
154
|
+
* @property properties - Optional key-value pairs for additional metadata
|
|
155
|
+
* @property inputParameters - Optional array of input parameters for the task
|
|
156
|
+
* @property traceContent - Optional flag to control whether content is traced
|
|
157
|
+
* @property suppressTracing - Optional flag to suppress tracing for this task
|
|
158
|
+
*/
|
|
159
|
+
interface SpanParams {
|
|
160
|
+
name: string;
|
|
161
|
+
properties?: Record<string, string>;
|
|
162
|
+
inputParameters?: unknown[];
|
|
163
|
+
traceContent?: boolean;
|
|
164
|
+
suppressTracing?: boolean;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Configuration for a traced tool.
|
|
168
|
+
*
|
|
169
|
+
* Tools represent external utilities or services that are invoked during an AI interaction,
|
|
170
|
+
* such as search engines, calculators, or other specialized functions.
|
|
171
|
+
*
|
|
172
|
+
* @property name - Name of the tool for identification in traces
|
|
173
|
+
* @property version - Optional version number of the tool
|
|
174
|
+
* @property properties - Optional key-value pairs for additional metadata
|
|
175
|
+
* @property inputParameters - Optional record of input parameters for the tool
|
|
176
|
+
* @property traceContent - Optional flag to control whether content is traced
|
|
177
|
+
* @property suppressTracing - Optional flag to suppress tracing for this tool invocation
|
|
178
|
+
*/
|
|
179
|
+
interface ToolParams {
|
|
180
|
+
name: string;
|
|
181
|
+
version?: number;
|
|
182
|
+
properties?: Record<string, string>;
|
|
183
|
+
inputParameters?: Record<string, any>;
|
|
184
|
+
traceContent?: boolean;
|
|
185
|
+
suppressTracing?: boolean;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Represents an active tracing interaction for tracking and analyzing AI interactions.
|
|
189
|
+
*
|
|
190
|
+
* An Interaction is the core entity for tracing and instrumenting AI operations,
|
|
191
|
+
* allowing you to organize your code into workflows and tasks while capturing
|
|
192
|
+
* important metadata and contextual information. Use the methods on this interface
|
|
193
|
+
* to record your AI interaction's lifecycle from input to output, and to add
|
|
194
|
+
* structured context about the operation.
|
|
195
|
+
*
|
|
196
|
+
* Interactions are typically created using the `tracing.begin()` method and ended
|
|
197
|
+
* with the `end()` method. Between these calls, you can add properties, attachments,
|
|
198
|
+
* and nested traced operations.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* // Basic usage pattern
|
|
202
|
+
* const interaction = tracing.begin({
|
|
203
|
+
* userId: "user-123",
|
|
204
|
+
* convoId: "conversation-456"
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* // Set the user's input
|
|
208
|
+
* interaction.setInput("Tell me a joke about AI");
|
|
209
|
+
*
|
|
210
|
+
* // Add context properties
|
|
211
|
+
* interaction.setProperty("intent", "entertainment");
|
|
212
|
+
*
|
|
213
|
+
* // Run a traced workflow
|
|
214
|
+
* const result = await interaction.withWorkflow("joke_generation", async () => {
|
|
215
|
+
* // Run a traced task for the LLM call
|
|
216
|
+
* return await interaction.withTask({
|
|
217
|
+
* name: "llm_completion",
|
|
218
|
+
* kind: "llm"
|
|
219
|
+
* }, async () => {
|
|
220
|
+
* const completion = await openai.chat.completions.create({
|
|
221
|
+
* model: "gpt-4",
|
|
222
|
+
* messages: [{ role: "user", content: "Tell me a joke about AI" }]
|
|
223
|
+
* });
|
|
224
|
+
* return completion.choices[0].message.content;
|
|
225
|
+
* });
|
|
226
|
+
* });
|
|
227
|
+
*
|
|
228
|
+
* // End the interaction with the result
|
|
229
|
+
* interaction.end(result);
|
|
230
|
+
*/
|
|
231
|
+
type Interaction = {
|
|
232
|
+
/**
|
|
233
|
+
* Creates a traced task that executes the provided function.
|
|
234
|
+
*
|
|
235
|
+
* @param params TaskParams object with task configuration
|
|
236
|
+
* @returns A span that can be used to record a task
|
|
237
|
+
*/
|
|
238
|
+
withSpan<T>(params: SpanParams, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): Promise<T>;
|
|
239
|
+
/**
|
|
240
|
+
* Creates a traced tool that executes the provided function.
|
|
241
|
+
*
|
|
242
|
+
* Tools represent external utilities or services that are invoked during an AI interaction.
|
|
243
|
+
* This method wraps a function call with tracing to capture the tool's inputs and outputs.
|
|
244
|
+
*
|
|
245
|
+
* @param params ToolParams object with tool configuration
|
|
246
|
+
* @param fn Function to execute within the tool trace
|
|
247
|
+
* @param thisArg Optional 'this' context for the function
|
|
248
|
+
* @param args Optional arguments to pass to the function
|
|
249
|
+
* @returns A promise that resolves with the tool execution result
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* // Basic tool usage
|
|
253
|
+
* const result = await interaction.withTool(
|
|
254
|
+
* { name: "search_tool" },
|
|
255
|
+
* async () => {
|
|
256
|
+
* // Call to external API or service
|
|
257
|
+
* return "Search results";
|
|
258
|
+
* }
|
|
259
|
+
* );
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* // Basic tool usage
|
|
263
|
+
* const result = await interaction.withTool(
|
|
264
|
+
* {
|
|
265
|
+
* name: "calculator",
|
|
266
|
+
* properties: { operation: "multiply" },
|
|
267
|
+
* inputParameters: { a: 5, b: 10 }
|
|
268
|
+
* },
|
|
269
|
+
* async () => {
|
|
270
|
+
* // Tool implementation
|
|
271
|
+
* return "Result: 50";
|
|
272
|
+
* }
|
|
273
|
+
* );
|
|
274
|
+
*/
|
|
275
|
+
withTool<T>(params: ToolParams, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): Promise<T>;
|
|
276
|
+
/**
|
|
277
|
+
* Creates a task span that can be used to manually record a task.
|
|
278
|
+
*
|
|
279
|
+
* @param params TaskParams object with task configuration
|
|
280
|
+
* @returns A span that can be used to record a task
|
|
281
|
+
*/
|
|
282
|
+
startSpan(params: SpanParams): Span$1;
|
|
283
|
+
/**
|
|
284
|
+
* Sets multiple properties on the interaction context.
|
|
285
|
+
*
|
|
286
|
+
* @param properties Object containing properties to set
|
|
287
|
+
*/
|
|
288
|
+
setProperties(properties: Record<string, string>): void;
|
|
289
|
+
/**
|
|
290
|
+
* Sets a single property on the interaction context.
|
|
291
|
+
*
|
|
292
|
+
* @param key The property key
|
|
293
|
+
* @param value The property value
|
|
294
|
+
*/
|
|
295
|
+
setProperty(key: string, value: string): void;
|
|
296
|
+
/**
|
|
297
|
+
* Adds an attachment to the interaction.
|
|
298
|
+
*
|
|
299
|
+
* @param attachment The attachment to add
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* // Adding various attachment types to an interaction
|
|
303
|
+
*
|
|
304
|
+
* // 1. Text attachment for context
|
|
305
|
+
* interaction.addAttachment([{
|
|
306
|
+
* type: "text",
|
|
307
|
+
* name: "Additional Info",
|
|
308
|
+
* value: "A very long document",
|
|
309
|
+
* role: "input",
|
|
310
|
+
* }]);
|
|
311
|
+
*
|
|
312
|
+
* // 2. Image attachment (output)
|
|
313
|
+
* interaction.addAttachment([{
|
|
314
|
+
* type: "image",
|
|
315
|
+
* value: "https://example.com/image.png",
|
|
316
|
+
* role: "output"
|
|
317
|
+
* }]);
|
|
318
|
+
*
|
|
319
|
+
* // 3. Iframe for embedded content
|
|
320
|
+
* interaction.addAttachment([{
|
|
321
|
+
* type: "iframe",
|
|
322
|
+
* name: "Generated UI",
|
|
323
|
+
* value: "https://newui.generated.com",
|
|
324
|
+
* role: "output",
|
|
325
|
+
* }]);
|
|
326
|
+
*
|
|
327
|
+
* // 4. Code snippet
|
|
328
|
+
* interaction.addAttachment([{
|
|
329
|
+
* type: "code",
|
|
330
|
+
* name: "Generated SQL Query",
|
|
331
|
+
* value: "SELECT * FROM users WHERE os_build = '17.1'",
|
|
332
|
+
* role: "output",
|
|
333
|
+
* language: "sql"
|
|
334
|
+
* }]);
|
|
335
|
+
*
|
|
336
|
+
* // All attachments are included when the interaction ends
|
|
337
|
+
* interaction.end("The weather is sunny and warm.");
|
|
338
|
+
*/
|
|
339
|
+
addAttachments(attachments: Attachment[]): void;
|
|
340
|
+
/**
|
|
341
|
+
* Sets the input for the interaction.
|
|
342
|
+
*
|
|
343
|
+
* @param input The input string
|
|
344
|
+
*/
|
|
345
|
+
setInput(input: string): void;
|
|
346
|
+
/**
|
|
347
|
+
* Ends the interaction and sends analytics data.
|
|
348
|
+
*
|
|
349
|
+
* This method completes the interaction lifecycle by:
|
|
350
|
+
* 1. Setting the trace_id as a property (if available)
|
|
351
|
+
* 2. Sending analytics data including the event ID, conversation ID,
|
|
352
|
+
* user ID, input, output, attachments, and any custom properties
|
|
353
|
+
*
|
|
354
|
+
* @param output The final output string for this interaction
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* // Start and end an interaction
|
|
358
|
+
* const interaction = tracing.begin({
|
|
359
|
+
* userId: "user-123",
|
|
360
|
+
* convoId: "convo-456"
|
|
361
|
+
* });
|
|
362
|
+
*
|
|
363
|
+
* interaction.setInput("What can you help me with today?");
|
|
364
|
+
* // ... process the request ...
|
|
365
|
+
*
|
|
366
|
+
* // End the interaction with the response
|
|
367
|
+
* interaction.end("I can help you with various tasks. Here are some examples...");
|
|
368
|
+
*/
|
|
369
|
+
finish(resultEvent: FinishInteractionOptions): void;
|
|
370
|
+
};
|
|
371
|
+
type Tracer = {
|
|
372
|
+
/**
|
|
373
|
+
* Creates a traced task that executes the provided function.
|
|
374
|
+
*
|
|
375
|
+
* @param params TaskParams object with task configuration
|
|
376
|
+
* @returns A span that can be used to record a task
|
|
377
|
+
*/
|
|
378
|
+
withSpan<T>(params: SpanParams, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): Promise<T>;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* An instrumentation scope consists of the name and optional version
|
|
383
|
+
* used to obtain a tracer or meter from a provider. This metadata is made
|
|
384
|
+
* available on ReadableSpan and MetricRecord for use by the export pipeline.
|
|
385
|
+
*/
|
|
386
|
+
interface InstrumentationScope {
|
|
387
|
+
readonly name: string;
|
|
388
|
+
readonly version?: string;
|
|
389
|
+
readonly schemaUrl?: string;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Represents a timed event.
|
|
394
|
+
* A timed event is an event with a timestamp.
|
|
395
|
+
*/
|
|
396
|
+
interface TimedEvent {
|
|
397
|
+
time: HrTime;
|
|
398
|
+
/** The name of the event. */
|
|
399
|
+
name: string;
|
|
400
|
+
/** The attributes of the event. */
|
|
401
|
+
attributes?: Attributes;
|
|
402
|
+
/** Count of attributes of the event that were dropped due to collection limits */
|
|
403
|
+
droppedAttributesCount?: number;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
interface ReadableSpan {
|
|
407
|
+
readonly name: string;
|
|
408
|
+
readonly kind: SpanKind;
|
|
409
|
+
readonly spanContext: () => SpanContext;
|
|
410
|
+
readonly parentSpanContext?: SpanContext;
|
|
411
|
+
readonly startTime: HrTime;
|
|
412
|
+
readonly endTime: HrTime;
|
|
413
|
+
readonly status: SpanStatus;
|
|
414
|
+
readonly attributes: Attributes;
|
|
415
|
+
readonly links: Link[];
|
|
416
|
+
readonly events: TimedEvent[];
|
|
417
|
+
readonly duration: HrTime;
|
|
418
|
+
readonly ended: boolean;
|
|
419
|
+
readonly resource: Resource;
|
|
420
|
+
readonly instrumentationScope: InstrumentationScope;
|
|
421
|
+
readonly droppedAttributesCount: number;
|
|
422
|
+
readonly droppedEventsCount: number;
|
|
423
|
+
readonly droppedLinksCount: number;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* This type provides the properties of @link{ReadableSpan} at the same time
|
|
428
|
+
* of the Span API
|
|
429
|
+
*/
|
|
430
|
+
type Span = Span$1 & ReadableSpan;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* SpanProcessor is the interface Tracer SDK uses to allow synchronous hooks
|
|
434
|
+
* for when a {@link Span} is started or when a {@link Span} is ended.
|
|
435
|
+
*/
|
|
436
|
+
interface SpanProcessor {
|
|
437
|
+
/**
|
|
438
|
+
* Forces to export all finished spans
|
|
439
|
+
*/
|
|
440
|
+
forceFlush(): Promise<void>;
|
|
441
|
+
/**
|
|
442
|
+
* Called when a {@link Span} is started, if the `span.isRecording()`
|
|
443
|
+
* returns true.
|
|
444
|
+
* @param span the Span that just started.
|
|
445
|
+
*/
|
|
446
|
+
onStart(span: Span, parentContext: Context): void;
|
|
447
|
+
/**
|
|
448
|
+
* Called when a {@link ReadableSpan} is ended, if the `span.isRecording()`
|
|
449
|
+
* returns true.
|
|
450
|
+
* @param span the Span that just ended.
|
|
451
|
+
*/
|
|
452
|
+
onEnd(span: ReadableSpan): void;
|
|
453
|
+
/**
|
|
454
|
+
* Shuts down the processor. Called when SDK is shut down. This is an
|
|
455
|
+
* opportunity for processor to do any cleanup required.
|
|
456
|
+
*/
|
|
457
|
+
shutdown(): Promise<void>;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
interface AnalyticsConfig {
|
|
461
|
+
writeKey: string;
|
|
462
|
+
bufferSize?: number;
|
|
463
|
+
bufferTimeout?: number;
|
|
464
|
+
debugLogs?: boolean;
|
|
465
|
+
endpoint?: string;
|
|
466
|
+
redactPii?: boolean;
|
|
467
|
+
/**
|
|
468
|
+
* false by default. If true, raindrop doesn't initialize OTEL tracing.
|
|
469
|
+
* you can then use the span processor using raindrop.createSpanProcessor()
|
|
470
|
+
*/
|
|
471
|
+
disableTracing?: boolean;
|
|
472
|
+
/**
|
|
473
|
+
* false by default. If true, the SDK will not send any events or initialize tracing.
|
|
474
|
+
* Useful for development/test environments.
|
|
475
|
+
*/
|
|
476
|
+
disabled?: boolean;
|
|
477
|
+
}
|
|
478
|
+
declare const MAX_INGEST_SIZE_BYTES: number;
|
|
479
|
+
declare class Raindrop {
|
|
480
|
+
private writeKey;
|
|
481
|
+
private apiUrl;
|
|
482
|
+
private buffer;
|
|
483
|
+
private bufferSize;
|
|
484
|
+
private bufferTimeout;
|
|
485
|
+
private flushTimer;
|
|
486
|
+
private redactPii;
|
|
487
|
+
private disabled;
|
|
488
|
+
private context;
|
|
489
|
+
private _tracing;
|
|
490
|
+
private partialEventBuffer;
|
|
491
|
+
private partialEventTimeouts;
|
|
492
|
+
private inFlightRequests;
|
|
493
|
+
debugLogs: boolean;
|
|
494
|
+
constructor(config: AnalyticsConfig);
|
|
495
|
+
private formatEndpoint;
|
|
496
|
+
/**
|
|
497
|
+
* Begins a new interaction.
|
|
498
|
+
*
|
|
499
|
+
* @param traceContext - The trace context for the interaction.
|
|
500
|
+
* @returns The interaction object.
|
|
501
|
+
*/
|
|
502
|
+
begin(traceContext: PartialAiTrackEvent & {
|
|
503
|
+
event: string;
|
|
504
|
+
userId: string;
|
|
505
|
+
}): Interaction;
|
|
506
|
+
/**
|
|
507
|
+
* Returns a tracer object that can be used to create spans and tools that aren't tied to any interaction.
|
|
508
|
+
* For chat interaction use-case `begin` should be used.
|
|
509
|
+
* This is meant for batch jobs or other non-interactive use-cases where you only care about tracing and token usage.
|
|
510
|
+
*
|
|
511
|
+
* @param globalProperties - Optional global properties to be associated with all spans and tools.
|
|
512
|
+
* @returns The tracer object.
|
|
513
|
+
*/
|
|
514
|
+
tracer(globalProperties?: Record<string, string>): Tracer;
|
|
515
|
+
createSpanProcessor(processorOptions?: SpanProcessorOptions): SpanProcessor;
|
|
516
|
+
/**
|
|
517
|
+
* Resumes an existing interaction.
|
|
518
|
+
*
|
|
519
|
+
* @param eventId - The ID of the interaction to resume.
|
|
520
|
+
* @returns The interaction object.
|
|
521
|
+
*/
|
|
522
|
+
resumeInteraction(eventId: string): Interaction;
|
|
523
|
+
/**
|
|
524
|
+
* Track AI events. In addiiton to normal event properties, you can provide an "input", "output", or "model" parameter.
|
|
525
|
+
* It takes an AiTrackEvent as input and sends it to the /track-ai endpoint of the raindrop api.
|
|
526
|
+
*
|
|
527
|
+
* @param event - The AiTrackEvent (you must specify at least one of input/output properties)
|
|
528
|
+
* @returns A Promise that resolves when the event has been successfully sent.
|
|
529
|
+
*
|
|
530
|
+
* Example usage:
|
|
531
|
+
* ```typescript
|
|
532
|
+
* raindrop.track_ai({
|
|
533
|
+
* event: "chat", //name of the event
|
|
534
|
+
* model: "claude", //optional
|
|
535
|
+
* input: "what's up?", // input or output is required
|
|
536
|
+
* output: "not much human, how are you?", //input or output is required
|
|
537
|
+
* userId: "cn123456789",
|
|
538
|
+
* });
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
541
|
+
trackAi(event: AiTrackEvent | AiTrackEvent[]): string | Array<string | undefined> | undefined;
|
|
542
|
+
private isEnvWithLocalStorage;
|
|
543
|
+
setUserDetails(event: IdentifyEvent): void;
|
|
544
|
+
trackSignal(signal: SignalEvent | SignalEvent[]): void | void[];
|
|
545
|
+
private getSize;
|
|
546
|
+
private saveToBuffer;
|
|
547
|
+
private flush;
|
|
548
|
+
private sendBatchToApi;
|
|
549
|
+
private getContext;
|
|
550
|
+
private formatZodError;
|
|
551
|
+
/**
|
|
552
|
+
* Deeply merges properties of the source object into the target object.
|
|
553
|
+
* Modifies the target object in place. Handles nested plain objects.
|
|
554
|
+
*/
|
|
555
|
+
private deepMergeObjects;
|
|
556
|
+
/**
|
|
557
|
+
* Internal method for tracking partial AI events. use .begin() to start an interaction instead.
|
|
558
|
+
*
|
|
559
|
+
* @param event - The PartialAiTrackEvent, requires eventId.
|
|
560
|
+
*/
|
|
561
|
+
_trackAiPartial(event: PartialAiTrackEvent): void;
|
|
562
|
+
/**
|
|
563
|
+
* Flushes a single accumulated partial event by its ID.
|
|
564
|
+
* This is called internally by the timeout or by the close method.
|
|
565
|
+
* @param eventId - The ID of the partial event to flush.
|
|
566
|
+
*/
|
|
567
|
+
private flushPartialEvent;
|
|
568
|
+
/**
|
|
569
|
+
* Internal implementation of flushPartialEvent without request tracking.
|
|
570
|
+
* @param eventId - The ID of the partial event to flush.
|
|
571
|
+
*/
|
|
572
|
+
private _flushPartialEventInternal;
|
|
573
|
+
/**
|
|
574
|
+
* Sends a single prepared event object to the 'events/track_partial' endpoint.
|
|
575
|
+
* @param event - The event data conforming to ClientAiTrack schema.
|
|
576
|
+
*/
|
|
577
|
+
private sendPartialEvent;
|
|
578
|
+
close(): Promise<void>;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export { type AiTrackEvent as A, type BeginInteractionOptions as B, type FinishInteractionOptions as F, type Interaction as I, MAX_INGEST_SIZE_BYTES as M, type PartialAiTrackEvent as P, Raindrop as R, type SpanProcessor as S, type Tracer as T, type WorkflowParams as W, type Attachment as a, type AttachmentType as b, type IdentifyEvent as c, type SignalEvent as d, type SpanParams as e, type ToolParams as f, type TraceContext as g };
|