raindrop-ai 0.2.4 → 0.3.0
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/README.md +135 -0
- package/dist/{chunk-XLEPN7ZO.mjs → chunk-5Y3LWBKV.mjs} +1033 -96
- package/dist/index-DBdUrUXc.d.mts +1457 -0
- package/dist/index-DBdUrUXc.d.ts +1457 -0
- package/dist/index.d.mts +5 -1180
- package/dist/index.d.ts +5 -1180
- package/dist/index.js +1111 -116
- package/dist/index.mjs +60 -1
- package/dist/tracing/index.d.mts +3 -1
- package/dist/tracing/index.d.ts +3 -1
- package/dist/tracing/index.js +1037 -101
- package/dist/tracing/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,1180 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
type LocalDebuggerLiveEventType = "text_delta" | "reasoning_delta" | "tool_start" | "tool_result" | "status";
|
|
7
|
-
type LocalDebuggerLiveEventInput$1 = {
|
|
8
|
-
traceId: string;
|
|
9
|
-
spanId?: string;
|
|
10
|
-
type: LocalDebuggerLiveEventType | (string & {});
|
|
11
|
-
content?: string;
|
|
12
|
-
timestamp?: number;
|
|
13
|
-
metadata?: Record<string, unknown>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Run telemetry egress with OpenTelemetry tracing suppressed.
|
|
18
|
-
*
|
|
19
|
-
* Why this exists
|
|
20
|
-
* ---------------
|
|
21
|
-
* Raindrop integrations ship spans/events over HTTP with the global `fetch`
|
|
22
|
-
* (see {@link ../http.ts `postJson`}). When the host app also runs an OTel
|
|
23
|
-
* fetch/undici instrumentation — e.g. `@vercel/otel`'s `registerOTel`, which
|
|
24
|
-
* every Eve agent installs — that instrumentation wraps *our own* telemetry
|
|
25
|
-
* POSTs in a `fetch POST <endpoint>` span. Those spans are then handed to the
|
|
26
|
-
* very exporter that issued the request, so they get shipped right back to
|
|
27
|
-
* Raindrop and Workshop as standalone "runs" (and, because each export issues
|
|
28
|
-
* another fetch, they feed back on themselves). The result is a run list
|
|
29
|
-
* flooded with `fetch POST .../v1/traces`, `.../events/track_partial` and
|
|
30
|
-
* `.../live` entries that drown out the real agent turns — especially with
|
|
31
|
-
* sub-agents, where every sandbox runs its own instrumentation.
|
|
32
|
-
*
|
|
33
|
-
* The OTel-blessed fix is to mark the active context as "tracing suppressed"
|
|
34
|
-
* around the request; instrumentations check `isTracingSuppressed` and return
|
|
35
|
-
* a no-op span instead of recording one. We do this through a hook stashed on
|
|
36
|
-
* `globalThis` by the Node entrypoint ({@link ../index.node.ts}) so that:
|
|
37
|
-
* - `@opentelemetry/api` / `@opentelemetry/core` stay *optional* — core never
|
|
38
|
-
* hard-depends on them, and the hook is simply absent when they (and thus
|
|
39
|
-
* any instrumentation to suppress) are not installed; and
|
|
40
|
-
* - the browser bundle never pulls in `node:module`, mirroring how core
|
|
41
|
-
* injects `AsyncLocalStorage` via `RAINDROP_ASYNC_LOCAL_STORAGE`.
|
|
42
|
-
*
|
|
43
|
-
* When no hook is present the callback runs unchanged, so suppression is a
|
|
44
|
-
* best-effort no-op rather than a hard requirement.
|
|
45
|
-
*/
|
|
46
|
-
/** Hook signature: run `fn` with OTel tracing suppressed, returning its value. */
|
|
47
|
-
type SuppressTracingHook = <T>(fn: () => T) => T;
|
|
48
|
-
declare global {
|
|
49
|
-
var RAINDROP_SUPPRESS_TRACING: SuppressTracingHook | undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type ParentSpanContext = {
|
|
53
|
-
traceIdB64: string;
|
|
54
|
-
spanIdB64: string;
|
|
55
|
-
eventId: string;
|
|
56
|
-
};
|
|
57
|
-
interface ContextSpan {
|
|
58
|
-
readonly traceIdB64: string;
|
|
59
|
-
readonly spanIdB64: string;
|
|
60
|
-
readonly eventId: string;
|
|
61
|
-
log?(data: Record<string, unknown>): void;
|
|
62
|
-
}
|
|
63
|
-
interface AsyncLocalStorageLike<T> {
|
|
64
|
-
getStore(): T | undefined;
|
|
65
|
-
run<R>(store: T, callback: () => R): R;
|
|
66
|
-
enterWith?(store: T): void;
|
|
67
|
-
}
|
|
68
|
-
declare abstract class ContextManager {
|
|
69
|
-
abstract getParentSpanIds(): ParentSpanContext | undefined;
|
|
70
|
-
abstract runInContext<R>(span: ContextSpan, callback: () => R): R;
|
|
71
|
-
abstract getCurrentSpan(): ContextSpan | undefined;
|
|
72
|
-
abstract isReady(): boolean;
|
|
73
|
-
}
|
|
74
|
-
declare global {
|
|
75
|
-
var RAINDROP_CONTEXT_MANAGER: (new () => ContextManager) | undefined;
|
|
76
|
-
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => AsyncLocalStorageLike<T>) | undefined;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Version-agnostic SpanProcessor interface.
|
|
81
|
-
*
|
|
82
|
-
* This interface avoids direct dependency on OTEL's Span and ReadableSpan types
|
|
83
|
-
* which can cause compatibility issues across minor OTEL versions. Using `any`
|
|
84
|
-
* allows the processor to work with any version of OTEL without type conflicts.
|
|
85
|
-
*/
|
|
86
|
-
interface RaindropSpanProcessor {
|
|
87
|
-
forceFlush(): Promise<void>;
|
|
88
|
-
onStart(span: any, parentContext: any): void;
|
|
89
|
-
onEnd(span: any): void;
|
|
90
|
-
shutdown(): Promise<void>;
|
|
91
|
-
}
|
|
92
|
-
type BaseAttachment = {
|
|
93
|
-
attachment_id?: string;
|
|
94
|
-
name?: string;
|
|
95
|
-
value: string;
|
|
96
|
-
role: "input" | "output";
|
|
97
|
-
};
|
|
98
|
-
type CodeAttachment = BaseAttachment & {
|
|
99
|
-
type: "code";
|
|
100
|
-
language?: string;
|
|
101
|
-
};
|
|
102
|
-
type OtherAttachment = BaseAttachment & {
|
|
103
|
-
type: "text" | "image" | "iframe";
|
|
104
|
-
};
|
|
105
|
-
type Attachment = CodeAttachment | OtherAttachment;
|
|
106
|
-
type RaindropFeatureFlagValue = string | number | boolean;
|
|
107
|
-
type RaindropFeatureFlags = string[] | Record<string, RaindropFeatureFlagValue>;
|
|
108
|
-
type RaindropPropertyLeaf = string | boolean | number;
|
|
109
|
-
type RaindropPropertyValue = RaindropPropertyLeaf | RaindropPropertyValue[] | {
|
|
110
|
-
[key: string]: RaindropPropertyValue;
|
|
111
|
-
};
|
|
112
|
-
type RaindropProperties = Record<string, RaindropPropertyValue>;
|
|
113
|
-
/**
|
|
114
|
-
* Interface for tracking events.
|
|
115
|
-
*
|
|
116
|
-
* @param eventId - An optional event ID for the event.
|
|
117
|
-
* @param event - The name of the event.
|
|
118
|
-
* @param properties - An optional record of properties for the event.
|
|
119
|
-
* @param timestamp - An optional timestamp for the event.
|
|
120
|
-
* @param userId - The ID of the user. This is a required field.
|
|
121
|
-
* @param anonymousId - An optional anonymous ID for the user.
|
|
122
|
-
*/
|
|
123
|
-
interface TrackEvent {
|
|
124
|
-
eventId?: string;
|
|
125
|
-
event: string;
|
|
126
|
-
properties?: RaindropProperties;
|
|
127
|
-
featureFlags?: RaindropFeatureFlags;
|
|
128
|
-
timestamp?: string;
|
|
129
|
-
userId: string;
|
|
130
|
-
}
|
|
131
|
-
type BasicSignal = {
|
|
132
|
-
eventId: string;
|
|
133
|
-
name: "thumbs_up" | "thumbs_down" | string;
|
|
134
|
-
sentiment?: "POSITIVE" | "NEGATIVE";
|
|
135
|
-
timestamp?: string;
|
|
136
|
-
properties?: {
|
|
137
|
-
[key: string]: any;
|
|
138
|
-
};
|
|
139
|
-
attachmentId?: string;
|
|
140
|
-
};
|
|
141
|
-
type DefaultSignal = BasicSignal & {
|
|
142
|
-
type?: "default" | "standard";
|
|
143
|
-
};
|
|
144
|
-
type FeedbackSignal = BasicSignal & {
|
|
145
|
-
type: "feedback";
|
|
146
|
-
comment?: string;
|
|
147
|
-
};
|
|
148
|
-
type EditSignal = BasicSignal & {
|
|
149
|
-
type: "edit";
|
|
150
|
-
after?: string;
|
|
151
|
-
};
|
|
152
|
-
type AgentSignal = BasicSignal & {
|
|
153
|
-
type: "agent" | "agent_internal";
|
|
154
|
-
};
|
|
155
|
-
type SignalEvent = DefaultSignal | FeedbackSignal | EditSignal | AgentSignal;
|
|
156
|
-
type SelfDiagnoseOptions = {
|
|
157
|
-
/** The interaction/event ID this diagnostic belongs to. */
|
|
158
|
-
eventId: string;
|
|
159
|
-
/** A human-readable description of the issue. */
|
|
160
|
-
description: string;
|
|
161
|
-
/** Optional category to group the diagnostic under (e.g. "missing_context", "capability_gap"). Defaults to "general". */
|
|
162
|
-
category?: string;
|
|
163
|
-
/** Optional source identifier (e.g. your agent or service name). */
|
|
164
|
-
source?: string;
|
|
165
|
-
/** Signal sentiment. Defaults to "NEGATIVE". */
|
|
166
|
-
sentiment?: "POSITIVE" | "NEGATIVE";
|
|
167
|
-
/** Additional custom properties to attach to the signal. */
|
|
168
|
-
properties?: Record<string, unknown>;
|
|
169
|
-
};
|
|
170
|
-
type SelfDiagnosticsSignalDefinition = {
|
|
171
|
-
description: string;
|
|
172
|
-
sentiment?: "POSITIVE" | "NEGATIVE";
|
|
173
|
-
};
|
|
174
|
-
type SelfDiagnosticsSignalDefinitions = Record<string, SelfDiagnosticsSignalDefinition>;
|
|
175
|
-
type SelfDiagnosticsToolInputSchema = {
|
|
176
|
-
type: "object";
|
|
177
|
-
additionalProperties: false;
|
|
178
|
-
properties: {
|
|
179
|
-
category: {
|
|
180
|
-
type: "string";
|
|
181
|
-
enum: string[];
|
|
182
|
-
description: string;
|
|
183
|
-
};
|
|
184
|
-
detail: {
|
|
185
|
-
type: "string";
|
|
186
|
-
description: string;
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
required: string[];
|
|
190
|
-
};
|
|
191
|
-
type SelfDiagnosticsExecuteContext = {
|
|
192
|
-
eventId?: string;
|
|
193
|
-
interaction?: {
|
|
194
|
-
getEventId(): string | undefined;
|
|
195
|
-
};
|
|
196
|
-
metadata?: Record<string, unknown>;
|
|
197
|
-
properties?: Record<string, unknown>;
|
|
198
|
-
source?: string;
|
|
199
|
-
};
|
|
200
|
-
type SelfDiagnosticsExecuteResult = {
|
|
201
|
-
acknowledged: boolean;
|
|
202
|
-
category: string;
|
|
203
|
-
eventId?: string;
|
|
204
|
-
reason?: "missing_event_id";
|
|
205
|
-
};
|
|
206
|
-
type SelfDiagnosticsToolOptions = {
|
|
207
|
-
eventId?: string;
|
|
208
|
-
getEventId?: () => string | undefined;
|
|
209
|
-
interaction?: {
|
|
210
|
-
getEventId(): string | undefined;
|
|
211
|
-
};
|
|
212
|
-
toolName?: string;
|
|
213
|
-
guidance?: string;
|
|
214
|
-
signals?: SelfDiagnosticsSignalDefinitions;
|
|
215
|
-
source?: string;
|
|
216
|
-
onMissingEventId?: "warn" | "ignore" | "throw";
|
|
217
|
-
};
|
|
218
|
-
type SelfDiagnosticsTool = {
|
|
219
|
-
name: string;
|
|
220
|
-
description: string;
|
|
221
|
-
inputSchema: SelfDiagnosticsToolInputSchema;
|
|
222
|
-
signalKeys: string[];
|
|
223
|
-
execute(input: unknown, context?: SelfDiagnosticsExecuteContext): Promise<SelfDiagnosticsExecuteResult>;
|
|
224
|
-
forVercelAI(): {
|
|
225
|
-
description: string;
|
|
226
|
-
parameters: SelfDiagnosticsToolInputSchema;
|
|
227
|
-
inputSchema: SelfDiagnosticsToolInputSchema;
|
|
228
|
-
execute: (input: unknown, context?: SelfDiagnosticsExecuteContext) => Promise<SelfDiagnosticsExecuteResult>;
|
|
229
|
-
};
|
|
230
|
-
forOpenAI(): {
|
|
231
|
-
type: "function";
|
|
232
|
-
function: {
|
|
233
|
-
name: string;
|
|
234
|
-
description: string;
|
|
235
|
-
parameters: SelfDiagnosticsToolInputSchema;
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
forAnthropic(): {
|
|
239
|
-
name: string;
|
|
240
|
-
description: string;
|
|
241
|
-
input_schema: SelfDiagnosticsToolInputSchema;
|
|
242
|
-
};
|
|
243
|
-
};
|
|
244
|
-
/**
|
|
245
|
-
* Interface for identifying events.
|
|
246
|
-
*
|
|
247
|
-
* @param userId - The ID of the user. This is a required field.
|
|
248
|
-
* @param traits - An optional object of traits for the user.
|
|
249
|
-
* @param anonymousId - An optional anonymous ID for the user.
|
|
250
|
-
* TODO: ensure at least one out of userId or anonymousId is present
|
|
251
|
-
*/
|
|
252
|
-
interface IdentifyEvent {
|
|
253
|
-
userId: string;
|
|
254
|
-
traits?: object;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Type definition for AI tracking events.
|
|
258
|
-
* In addition to the properties of a TrackEvent, an AiTrackEvent may have a 'model' property.
|
|
259
|
-
* It must have at least one of 'input' or 'output' property.
|
|
260
|
-
*
|
|
261
|
-
* @property model - An optional model property for the even
|
|
262
|
-
* @property input - An optional input property for the event, required if output is not provided.
|
|
263
|
-
* @property output - An optional output property for the event, required if input is not provided.
|
|
264
|
-
*/
|
|
265
|
-
type AiTrackEvent = Omit<TrackEvent, "type"> & {
|
|
266
|
-
model?: string;
|
|
267
|
-
convoId?: string;
|
|
268
|
-
attachments?: Attachment[];
|
|
269
|
-
featureFlags?: RaindropFeatureFlags;
|
|
270
|
-
} & ({
|
|
271
|
-
input: string;
|
|
272
|
-
output?: string;
|
|
273
|
-
} | {
|
|
274
|
-
input?: string;
|
|
275
|
-
output: string;
|
|
276
|
-
});
|
|
277
|
-
/**
|
|
278
|
-
* Type definition for partial AI tracking events used with trackAiPartial.
|
|
279
|
-
* Requires an eventId to correlate partial updates. All other fields are optional.
|
|
280
|
-
*/
|
|
281
|
-
type PartialAiTrackEvent = Partial<AiTrackEvent> & {
|
|
282
|
-
eventId: string;
|
|
283
|
-
isPending?: boolean;
|
|
284
|
-
};
|
|
285
|
-
declare const AttachmentTypeSchema: z.ZodEnum<["code", "text", "image", "iframe"]>;
|
|
286
|
-
type AttachmentType = z.infer<typeof AttachmentTypeSchema>;
|
|
287
|
-
/**
|
|
288
|
-
* Configuration for initializing a trace interaction.
|
|
289
|
-
*
|
|
290
|
-
* This interface defines the context required to create and track an AI
|
|
291
|
-
* interaction through its lifecycle. It includes identifiers for the user
|
|
292
|
-
* and conversation, as well as input/output content and attachments.
|
|
293
|
-
*
|
|
294
|
-
* @property userId - Optional unique identifier for the user
|
|
295
|
-
* @property convoId - Optional unique identifier for the conversation
|
|
296
|
-
* @property eventId - Optional unique identifier for this specific interaction event
|
|
297
|
-
* @property input - Optional input text from the user
|
|
298
|
-
* @property attachments - Optional array of attachments associated with this interaction
|
|
299
|
-
* @property properties - Optional key-value pairs for additional custom metadata
|
|
300
|
-
*/
|
|
301
|
-
interface TraceContext {
|
|
302
|
-
userId?: string;
|
|
303
|
-
convoId?: string;
|
|
304
|
-
eventId?: string;
|
|
305
|
-
input?: string;
|
|
306
|
-
event?: string;
|
|
307
|
-
attachments?: Attachment[];
|
|
308
|
-
properties?: Record<string, string>;
|
|
309
|
-
}
|
|
310
|
-
type BeginInteractionOptions = PartialAiTrackEvent & {
|
|
311
|
-
eventId: string;
|
|
312
|
-
};
|
|
313
|
-
type FinishInteractionOptions = Omit<PartialAiTrackEvent, "eventId"> & {
|
|
314
|
-
output: string;
|
|
315
|
-
eventId?: string;
|
|
316
|
-
};
|
|
317
|
-
/**
|
|
318
|
-
* Configuration for a traced workflow.
|
|
319
|
-
*
|
|
320
|
-
* Workflows represent higher-level operations that might contain multiple
|
|
321
|
-
* tasks. They help organize traces into logical units of work.
|
|
322
|
-
*
|
|
323
|
-
* @property name - Name of the workflow for identification in traces
|
|
324
|
-
* @property inputParameters - Optional array of input parameters for the workflow
|
|
325
|
-
* @property properties - Optional key-value pairs for additional metadata
|
|
326
|
-
*/
|
|
327
|
-
interface WorkflowParams {
|
|
328
|
-
name: string;
|
|
329
|
-
inputParameters?: unknown[];
|
|
330
|
-
properties?: Record<string, string>;
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Configuration for a traced task.
|
|
334
|
-
*
|
|
335
|
-
* Tasks represent individual operations within a workflow, such as an LLM call,
|
|
336
|
-
* a tool invocation, a retrieval operation, or internal processing.
|
|
337
|
-
*
|
|
338
|
-
* @property name - Name of the task for identification in traces
|
|
339
|
-
* @property kind - Category of the task (llm, tool, retrival, or internal)
|
|
340
|
-
* @property properties - Optional key-value pairs for additional metadata
|
|
341
|
-
* @property inputParameters - Optional array of input parameters for the task
|
|
342
|
-
* @property traceContent - Optional flag to control whether content is traced
|
|
343
|
-
* @property suppressTracing - Optional flag to suppress tracing for this task
|
|
344
|
-
*/
|
|
345
|
-
interface SpanParams {
|
|
346
|
-
name: string;
|
|
347
|
-
properties?: Record<string, string>;
|
|
348
|
-
inputParameters?: unknown[];
|
|
349
|
-
traceContent?: boolean;
|
|
350
|
-
suppressTracing?: boolean;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Configuration for a traced tool.
|
|
354
|
-
*
|
|
355
|
-
* Tools represent external utilities or services that are invoked during an AI interaction,
|
|
356
|
-
* such as search engines, calculators, or other specialized functions.
|
|
357
|
-
*
|
|
358
|
-
* @property name - Name of the tool for identification in traces
|
|
359
|
-
* @property version - Optional version number of the tool
|
|
360
|
-
* @property properties - Optional key-value pairs for additional metadata
|
|
361
|
-
* @property inputParameters - Optional record of input parameters for the tool
|
|
362
|
-
* @property traceContent - Optional flag to control whether content is traced
|
|
363
|
-
* @property suppressTracing - Optional flag to suppress tracing for this tool invocation
|
|
364
|
-
*/
|
|
365
|
-
interface ToolParams {
|
|
366
|
-
name: string;
|
|
367
|
-
version?: number;
|
|
368
|
-
properties?: Record<string, string>;
|
|
369
|
-
inputParameters?: Record<string, any>;
|
|
370
|
-
traceContent?: boolean;
|
|
371
|
-
suppressTracing?: boolean;
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Parameters for directly logging a tool span without wrapping a function.
|
|
375
|
-
*
|
|
376
|
-
* Use this when you want to record a tool invocation that has already completed,
|
|
377
|
-
* rather than wrapping the tool call with withTool().
|
|
378
|
-
*
|
|
379
|
-
* @property name - Name of the tool for identification in traces
|
|
380
|
-
* @property input - The input provided to the tool (will be JSON stringified if object)
|
|
381
|
-
* @property output - The output returned by the tool (will be JSON stringified if object)
|
|
382
|
-
* @property durationMs - Duration of the tool execution in milliseconds
|
|
383
|
-
* @property startTime - Optional start time of the tool execution
|
|
384
|
-
* @property error - Optional error if the tool failed
|
|
385
|
-
* @property properties - Optional key-value pairs for additional metadata
|
|
386
|
-
* @property traceId - Optional W3C trace ID override for bypassOtelForTools mode
|
|
387
|
-
* @property parentSpanId - Optional W3C parent span ID override for bypassOtelForTools mode
|
|
388
|
-
*/
|
|
389
|
-
interface TrackToolParams {
|
|
390
|
-
name: string;
|
|
391
|
-
input?: unknown;
|
|
392
|
-
output?: unknown;
|
|
393
|
-
durationMs?: number;
|
|
394
|
-
startTime?: Date | number;
|
|
395
|
-
error?: Error | string;
|
|
396
|
-
properties?: Record<string, string>;
|
|
397
|
-
traceId?: string;
|
|
398
|
-
parentSpanId?: string;
|
|
399
|
-
}
|
|
400
|
-
type LocalDebuggerLiveEventInput = Omit<LocalDebuggerLiveEventInput$1, "traceId"> & {
|
|
401
|
-
traceId?: string;
|
|
402
|
-
};
|
|
403
|
-
/**
|
|
404
|
-
* A wrapper around an OpenTelemetry span for tool invocations.
|
|
405
|
-
*
|
|
406
|
-
* Provides a clean API for setting tool input, output, and error status
|
|
407
|
-
* without needing to know the internal traceloop attribute names.
|
|
408
|
-
*
|
|
409
|
-
* @example
|
|
410
|
-
* ```typescript
|
|
411
|
-
* const toolSpan = interaction.startToolSpan({ name: "web_search" });
|
|
412
|
-
* try {
|
|
413
|
-
* const result = await performSearch(query);
|
|
414
|
-
* toolSpan.setOutput(result);
|
|
415
|
-
* } catch (error) {
|
|
416
|
-
* toolSpan.setError(error);
|
|
417
|
-
* } finally {
|
|
418
|
-
* toolSpan.end();
|
|
419
|
-
* }
|
|
420
|
-
* ```
|
|
421
|
-
*/
|
|
422
|
-
interface ToolSpan {
|
|
423
|
-
/**
|
|
424
|
-
* Sets the input for this tool span.
|
|
425
|
-
* @param input The input value (will be JSON stringified if object)
|
|
426
|
-
*/
|
|
427
|
-
setInput(input: unknown): void;
|
|
428
|
-
/**
|
|
429
|
-
* Sets the output for this tool span.
|
|
430
|
-
* @param output The output value (will be JSON stringified if object)
|
|
431
|
-
*/
|
|
432
|
-
setOutput(output: unknown): void;
|
|
433
|
-
/**
|
|
434
|
-
* Marks this tool span as failed with an error.
|
|
435
|
-
* @param error The error that occurred
|
|
436
|
-
*/
|
|
437
|
-
setError(error: Error | string): void;
|
|
438
|
-
/**
|
|
439
|
-
* Ends this tool span. Must be called when the tool execution is complete.
|
|
440
|
-
*/
|
|
441
|
-
end(): void;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Represents an active tracing interaction for tracking and analyzing AI interactions.
|
|
445
|
-
*
|
|
446
|
-
* An Interaction is the core entity for tracing and instrumenting AI operations,
|
|
447
|
-
* allowing you to organize your code into workflows and tasks while capturing
|
|
448
|
-
* important metadata and contextual information. Use the methods on this interface
|
|
449
|
-
* to record your AI interaction's lifecycle from input to output, and to add
|
|
450
|
-
* structured context about the operation.
|
|
451
|
-
*
|
|
452
|
-
* Interactions are typically created using the `tracing.begin()` method and ended
|
|
453
|
-
* with the `end()` method. Between these calls, you can add properties, attachments,
|
|
454
|
-
* and nested traced operations.
|
|
455
|
-
*
|
|
456
|
-
* @example
|
|
457
|
-
* // Basic usage pattern
|
|
458
|
-
* const interaction = tracing.begin({
|
|
459
|
-
* userId: "user-123",
|
|
460
|
-
* convoId: "conversation-456"
|
|
461
|
-
* });
|
|
462
|
-
*
|
|
463
|
-
* // Set the user's input
|
|
464
|
-
* interaction.setInput("Tell me a joke about AI");
|
|
465
|
-
*
|
|
466
|
-
* // Add context properties
|
|
467
|
-
* interaction.setProperty("intent", "entertainment");
|
|
468
|
-
*
|
|
469
|
-
* // Run a traced workflow
|
|
470
|
-
* const result = await interaction.withWorkflow("joke_generation", async () => {
|
|
471
|
-
* // Run a traced task for the LLM call
|
|
472
|
-
* return await interaction.withTask({
|
|
473
|
-
* name: "llm_completion",
|
|
474
|
-
* kind: "llm"
|
|
475
|
-
* }, async () => {
|
|
476
|
-
* const completion = await openai.chat.completions.create({
|
|
477
|
-
* model: "gpt-4",
|
|
478
|
-
* messages: [{ role: "user", content: "Tell me a joke about AI" }]
|
|
479
|
-
* });
|
|
480
|
-
* return completion.choices[0].message.content;
|
|
481
|
-
* });
|
|
482
|
-
* });
|
|
483
|
-
*
|
|
484
|
-
* // End the interaction with the result
|
|
485
|
-
* interaction.end(result);
|
|
486
|
-
*/
|
|
487
|
-
type Interaction = {
|
|
488
|
-
/**
|
|
489
|
-
* Creates a traced task that executes the provided function.
|
|
490
|
-
*
|
|
491
|
-
* @param params TaskParams object with task configuration
|
|
492
|
-
* @returns A span that can be used to record a task
|
|
493
|
-
*/
|
|
494
|
-
withSpan<T>(params: SpanParams, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): Promise<T>;
|
|
495
|
-
/**
|
|
496
|
-
* Creates a traced tool that executes the provided function.
|
|
497
|
-
*
|
|
498
|
-
* Tools represent external utilities or services that are invoked during an AI interaction.
|
|
499
|
-
* This method wraps a function call with tracing to capture the tool's inputs and outputs.
|
|
500
|
-
*
|
|
501
|
-
* @param params ToolParams object with tool configuration
|
|
502
|
-
* @param fn Function to execute within the tool trace
|
|
503
|
-
* @param thisArg Optional 'this' context for the function
|
|
504
|
-
* @param args Optional arguments to pass to the function
|
|
505
|
-
* @returns A promise that resolves with the tool execution result
|
|
506
|
-
*
|
|
507
|
-
* @example
|
|
508
|
-
* // Basic tool usage
|
|
509
|
-
* const result = await interaction.withTool(
|
|
510
|
-
* { name: "search_tool" },
|
|
511
|
-
* async () => {
|
|
512
|
-
* // Call to external API or service
|
|
513
|
-
* return "Search results";
|
|
514
|
-
* }
|
|
515
|
-
* );
|
|
516
|
-
*
|
|
517
|
-
* @example
|
|
518
|
-
* // Basic tool usage
|
|
519
|
-
* const result = await interaction.withTool(
|
|
520
|
-
* {
|
|
521
|
-
* name: "calculator",
|
|
522
|
-
* properties: { operation: "multiply" },
|
|
523
|
-
* inputParameters: { a: 5, b: 10 }
|
|
524
|
-
* },
|
|
525
|
-
* async () => {
|
|
526
|
-
* // Tool implementation
|
|
527
|
-
* return "Result: 50";
|
|
528
|
-
* }
|
|
529
|
-
* );
|
|
530
|
-
*/
|
|
531
|
-
withTool<T>(params: ToolParams, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): Promise<T>;
|
|
532
|
-
/**
|
|
533
|
-
* Creates a task span that can be used to manually record a task.
|
|
534
|
-
*
|
|
535
|
-
* @param params TaskParams object with task configuration
|
|
536
|
-
* @returns A span that can be used to record a task
|
|
537
|
-
*/
|
|
538
|
-
startSpan(params: SpanParams): Span;
|
|
539
|
-
/**
|
|
540
|
-
* Creates a tool span that can be used to manually record a tool invocation.
|
|
541
|
-
*
|
|
542
|
-
* Similar to startSpan but sets the span kind to "tool" instead of "task".
|
|
543
|
-
* Use this when you want manual control over the span lifecycle for tool calls.
|
|
544
|
-
* Returns a ToolSpan wrapper with convenient methods for setting input, output, and errors.
|
|
545
|
-
*
|
|
546
|
-
* @param params ToolParams object with tool configuration
|
|
547
|
-
* @returns A ToolSpan wrapper for recording the tool execution
|
|
548
|
-
*
|
|
549
|
-
* @example
|
|
550
|
-
* ```typescript
|
|
551
|
-
* const interaction = raindrop.begin({ userId: "user-123", event: "agent_run" });
|
|
552
|
-
*
|
|
553
|
-
* // Start a tool span with manual control
|
|
554
|
-
* const toolSpan = interaction.startToolSpan({ name: "web_search" });
|
|
555
|
-
* try {
|
|
556
|
-
* const result = await performSearch(query);
|
|
557
|
-
* toolSpan.setOutput(result);
|
|
558
|
-
* } catch (error) {
|
|
559
|
-
* toolSpan.setError(error);
|
|
560
|
-
* } finally {
|
|
561
|
-
* toolSpan.end();
|
|
562
|
-
* }
|
|
563
|
-
* ```
|
|
564
|
-
*/
|
|
565
|
-
startToolSpan(params: ToolParams): ToolSpan;
|
|
566
|
-
/**
|
|
567
|
-
* Sets multiple properties on the interaction context.
|
|
568
|
-
*
|
|
569
|
-
* @param properties Object containing properties to set
|
|
570
|
-
*/
|
|
571
|
-
setProperties(properties: RaindropProperties): void;
|
|
572
|
-
/**
|
|
573
|
-
* Sets a single property on the interaction context.
|
|
574
|
-
*
|
|
575
|
-
* @param key The property key
|
|
576
|
-
* @param value The property value
|
|
577
|
-
*/
|
|
578
|
-
setProperty(key: string, value: RaindropPropertyValue): void;
|
|
579
|
-
/**
|
|
580
|
-
* Adds an attachment to the interaction.
|
|
581
|
-
*
|
|
582
|
-
* @param attachment The attachment to add
|
|
583
|
-
*
|
|
584
|
-
* @example
|
|
585
|
-
* // Adding various attachment types to an interaction
|
|
586
|
-
*
|
|
587
|
-
* // 1. Text attachment for context
|
|
588
|
-
* interaction.addAttachment([{
|
|
589
|
-
* type: "text",
|
|
590
|
-
* name: "Additional Info",
|
|
591
|
-
* value: "A very long document",
|
|
592
|
-
* role: "input",
|
|
593
|
-
* }]);
|
|
594
|
-
*
|
|
595
|
-
* // 2. Image attachment (output)
|
|
596
|
-
* interaction.addAttachment([{
|
|
597
|
-
* type: "image",
|
|
598
|
-
* value: "https://example.com/image.png",
|
|
599
|
-
* role: "output"
|
|
600
|
-
* }]);
|
|
601
|
-
*
|
|
602
|
-
* // 3. Iframe for embedded content
|
|
603
|
-
* interaction.addAttachment([{
|
|
604
|
-
* type: "iframe",
|
|
605
|
-
* name: "Generated UI",
|
|
606
|
-
* value: "https://newui.generated.com",
|
|
607
|
-
* role: "output",
|
|
608
|
-
* }]);
|
|
609
|
-
*
|
|
610
|
-
* // 4. Code snippet
|
|
611
|
-
* interaction.addAttachment([{
|
|
612
|
-
* type: "code",
|
|
613
|
-
* name: "Generated SQL Query",
|
|
614
|
-
* value: "SELECT * FROM users WHERE os_build = '17.1'",
|
|
615
|
-
* role: "output",
|
|
616
|
-
* language: "sql"
|
|
617
|
-
* }]);
|
|
618
|
-
*
|
|
619
|
-
* // All attachments are included when the interaction ends
|
|
620
|
-
* interaction.end("The weather is sunny and warm.");
|
|
621
|
-
*/
|
|
622
|
-
addAttachments(attachments: Attachment[]): void;
|
|
623
|
-
/**
|
|
624
|
-
* Sets a single feature flag on the interaction.
|
|
625
|
-
* @param name The flag name
|
|
626
|
-
* @param value The flag value (defaults to "true")
|
|
627
|
-
*/
|
|
628
|
-
setFeatureFlag(name: string, value?: RaindropFeatureFlagValue): void;
|
|
629
|
-
/**
|
|
630
|
-
* Sets multiple feature flags on the interaction.
|
|
631
|
-
* Accepts an array of flag names (all set to "true") or an object with explicit values.
|
|
632
|
-
* Merges with any previously set flags.
|
|
633
|
-
* @param flags The feature flags to set
|
|
634
|
-
*/
|
|
635
|
-
setFeatureFlags(flags: RaindropFeatureFlags): void;
|
|
636
|
-
/**
|
|
637
|
-
* Sets the input for the interaction.
|
|
638
|
-
*
|
|
639
|
-
* @param input The input string
|
|
640
|
-
*/
|
|
641
|
-
setInput(input: string): void;
|
|
642
|
-
/**
|
|
643
|
-
* Ends the interaction and sends analytics data.
|
|
644
|
-
*
|
|
645
|
-
* This method completes the interaction lifecycle by:
|
|
646
|
-
* 1. Setting the trace_id as a property (if available)
|
|
647
|
-
* 2. Sending analytics data including the event ID, conversation ID,
|
|
648
|
-
* user ID, input, output, attachments, and any custom properties
|
|
649
|
-
*
|
|
650
|
-
* @param output The final output string for this interaction
|
|
651
|
-
*
|
|
652
|
-
* @example
|
|
653
|
-
* // Start and end an interaction
|
|
654
|
-
* const interaction = tracing.begin({
|
|
655
|
-
* userId: "user-123",
|
|
656
|
-
* convoId: "convo-456"
|
|
657
|
-
* });
|
|
658
|
-
*
|
|
659
|
-
* interaction.setInput("What can you help me with today?");
|
|
660
|
-
* // ... process the request ...
|
|
661
|
-
*
|
|
662
|
-
* // End the interaction with the response
|
|
663
|
-
* interaction.end("I can help you with various tasks. Here are some examples...");
|
|
664
|
-
*/
|
|
665
|
-
finish(resultEvent: FinishInteractionOptions): Promise<void>;
|
|
666
|
-
/**
|
|
667
|
-
* Returns metadata for Vercel AI SDK's experimental_telemetry option.
|
|
668
|
-
*
|
|
669
|
-
* Use this when making Vercel AI SDK calls outside of withSpan() to ensure
|
|
670
|
-
* the interaction's properties (userId, convoId, eventId) are attached to the spans.
|
|
671
|
-
*
|
|
672
|
-
* When using withSpan(), this is handled automatically via context propagation.
|
|
673
|
-
* This method is a fallback for cases where you can't use withSpan().
|
|
674
|
-
*
|
|
675
|
-
* @returns Metadata object with traceloop association properties
|
|
676
|
-
*
|
|
677
|
-
* @example
|
|
678
|
-
* ```typescript
|
|
679
|
-
* const interaction = raindrop.begin({ userId: "user-123", convoId: "convo-456" });
|
|
680
|
-
*
|
|
681
|
-
* // Option 1: Use withSpan (recommended - automatic context propagation)
|
|
682
|
-
* await interaction.withSpan("my-task", async () => {
|
|
683
|
-
* await generateText({ experimental_telemetry: { isEnabled: true }, ... });
|
|
684
|
-
* });
|
|
685
|
-
*
|
|
686
|
-
* // Option 2: Use vercelAiSdkMetadata (fallback when withSpan isn't possible)
|
|
687
|
-
* await generateText({
|
|
688
|
-
* experimental_telemetry: {
|
|
689
|
-
* isEnabled: true,
|
|
690
|
-
* metadata: interaction.vercelAiSdkMetadata(),
|
|
691
|
-
* },
|
|
692
|
-
* ...
|
|
693
|
-
* });
|
|
694
|
-
* ```
|
|
695
|
-
*/
|
|
696
|
-
vercelAiSdkMetadata(): Record<string, string>;
|
|
697
|
-
/**
|
|
698
|
-
* Returns the interaction event ID used for event/signal correlation.
|
|
699
|
-
*/
|
|
700
|
-
getEventId(): string | undefined;
|
|
701
|
-
/**
|
|
702
|
-
* Logs a tool span directly without wrapping a function.
|
|
703
|
-
*
|
|
704
|
-
* Use this when you want to record a tool invocation that has already completed,
|
|
705
|
-
* rather than wrapping the tool call with withTool(). This is useful for:
|
|
706
|
-
* - Recording tool calls from external systems
|
|
707
|
-
* - Logging tools that were executed outside of the tracing context
|
|
708
|
-
* - Retroactively adding tool spans with known input/output/duration
|
|
709
|
-
*
|
|
710
|
-
* @param params TrackToolParams object with tool execution details
|
|
711
|
-
*
|
|
712
|
-
* @example
|
|
713
|
-
* ```typescript
|
|
714
|
-
* const interaction = raindrop.begin({ userId: "user-123", event: "agent_run" });
|
|
715
|
-
*
|
|
716
|
-
* // Record a tool that was already executed
|
|
717
|
-
* interaction.trackTool({
|
|
718
|
-
* name: "web_search",
|
|
719
|
-
* input: { query: "weather in NYC" },
|
|
720
|
-
* output: { results: ["Sunny, 72°F"] },
|
|
721
|
-
* durationMs: 150,
|
|
722
|
-
* });
|
|
723
|
-
*
|
|
724
|
-
* // Record a failed tool
|
|
725
|
-
* interaction.trackTool({
|
|
726
|
-
* name: "database_query",
|
|
727
|
-
* input: { sql: "SELECT * FROM users" },
|
|
728
|
-
* error: new Error("Connection timeout"),
|
|
729
|
-
* durationMs: 5000,
|
|
730
|
-
* });
|
|
731
|
-
*
|
|
732
|
-
* interaction.finish({ output: "Here's the weather..." });
|
|
733
|
-
* ```
|
|
734
|
-
*/
|
|
735
|
-
trackTool(params: TrackToolParams): void;
|
|
736
|
-
/**
|
|
737
|
-
* Emits a live event to the local debugger for this interaction's trace.
|
|
738
|
-
*
|
|
739
|
-
* Use this to surface streaming output or framework-specific progress from
|
|
740
|
-
* integrations that do not use `@raindrop-ai/ai-sdk`.
|
|
741
|
-
*/
|
|
742
|
-
emitLiveEvent(event: LocalDebuggerLiveEventInput): void;
|
|
743
|
-
};
|
|
744
|
-
type Tracer = {
|
|
745
|
-
/**
|
|
746
|
-
* Creates a traced task that executes the provided function.
|
|
747
|
-
*
|
|
748
|
-
* @param params TaskParams object with task configuration
|
|
749
|
-
* @returns A span that can be used to record a task
|
|
750
|
-
*/
|
|
751
|
-
withSpan<T>(params: SpanParams, fn: (...args: any[]) => Promise<T> | T, thisArg?: any, ...args: any[]): Promise<T>;
|
|
752
|
-
/**
|
|
753
|
-
* Logs a tool span directly without wrapping a function.
|
|
754
|
-
*
|
|
755
|
-
* Use this when you want to record a tool invocation that has already completed,
|
|
756
|
-
* rather than wrapping the tool call. This is useful for batch jobs or
|
|
757
|
-
* non-interactive use-cases where you only care about tracing and token usage.
|
|
758
|
-
*
|
|
759
|
-
* @param params TrackToolParams object with tool execution details
|
|
760
|
-
*
|
|
761
|
-
* @example
|
|
762
|
-
* ```typescript
|
|
763
|
-
* const tracer = raindrop.tracer({ job_id: "batch-123" });
|
|
764
|
-
*
|
|
765
|
-
* // Record a tool that was already executed
|
|
766
|
-
* tracer.trackTool({
|
|
767
|
-
* name: "web_search",
|
|
768
|
-
* input: { query: "weather in NYC" },
|
|
769
|
-
* output: { results: ["Sunny, 72°F"] },
|
|
770
|
-
* durationMs: 150,
|
|
771
|
-
* });
|
|
772
|
-
* ```
|
|
773
|
-
*/
|
|
774
|
-
trackTool(params: TrackToolParams): void;
|
|
775
|
-
/**
|
|
776
|
-
* Emits a live event to the local debugger using the current active trace.
|
|
777
|
-
*/
|
|
778
|
-
emitLiveEvent(event: LocalDebuggerLiveEventInput): void;
|
|
779
|
-
};
|
|
780
|
-
|
|
781
|
-
declare global {
|
|
782
|
-
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
|
|
783
|
-
getStore(): T | undefined;
|
|
784
|
-
run<R>(store: T, callback: () => R): R;
|
|
785
|
-
enterWith?(store: T): void;
|
|
786
|
-
}) | undefined;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
interface AnalyticsConfig {
|
|
790
|
-
wizardSession?: string;
|
|
791
|
-
/**
|
|
792
|
-
* Raindrop write key. When omitted (or empty), the SDK runs in local-only mode:
|
|
793
|
-
* cloud requests are skipped and only the Workshop / local-debugger mirror fires
|
|
794
|
-
* (when `localWorkshopUrl` resolves to a URL). Useful for local development where
|
|
795
|
-
* you only want events to land in Workshop without provisioning a write key.
|
|
796
|
-
*/
|
|
797
|
-
writeKey?: string;
|
|
798
|
-
bufferSize?: number;
|
|
799
|
-
bufferTimeout?: number;
|
|
800
|
-
debugLogs?: boolean;
|
|
801
|
-
endpoint?: string;
|
|
802
|
-
redactPii?: boolean;
|
|
803
|
-
/**
|
|
804
|
-
* Per-field character cap applied to ai input/output and serialized
|
|
805
|
-
* tool/span content BEFORE buffering or serialization, so oversized
|
|
806
|
-
* payloads cost the cap — not the payload — on the calling code path
|
|
807
|
-
* (`JSON.stringify` of a multi-MB payload blocks the event loop).
|
|
808
|
-
* Truncated fields end with `...[truncated by raindrop]` and never exceed
|
|
809
|
-
* the cap, marker included. Defaults to 1,000,000 (matching the Python SDK's
|
|
810
|
-
* `max_text_field_chars`).
|
|
811
|
-
*/
|
|
812
|
-
maxTextFieldChars?: number;
|
|
813
|
-
/**
|
|
814
|
-
* Force-enable (or opt out of) Workshop / local-debugger mirroring.
|
|
815
|
-
*
|
|
816
|
-
* - `string` — explicit Workshop URL (e.g. `"http://localhost:5899/v1/"`),
|
|
817
|
-
* wins over env vars and runtime auto-detect.
|
|
818
|
-
* - `false` (or `null`) — explicit opt-out, even on localhost / when
|
|
819
|
-
* `NODE_ENV=development` / when `RAINDROP_WORKSHOP` is set.
|
|
820
|
-
* - `undefined` (default) — fall through to `RAINDROP_LOCAL_DEBUGGER`,
|
|
821
|
-
* `RAINDROP_WORKSHOP`, and runtime auto-detect (localhost-ish hostname
|
|
822
|
-
* OR `NODE_ENV=development` enables the default `:5899` daemon).
|
|
823
|
-
*/
|
|
824
|
-
localWorkshopUrl?: string | false | null;
|
|
825
|
-
/**
|
|
826
|
-
* Optional project slug. When set, every outbound cloud ingest request
|
|
827
|
-
* (event POSTs and the direct trace shipper) carries an
|
|
828
|
-
* `X-Raindrop-Project-Id: <projectId>` header so the backend routes the
|
|
829
|
-
* data to that project. Empty / whitespace-only values are ignored and the
|
|
830
|
-
* backend falls back to the account's default project. Slug format is
|
|
831
|
-
* validated on construction but never throws — invalid values are warned
|
|
832
|
-
* about (when `debugLogs` is true) and sent anyway (the backend returns
|
|
833
|
-
* HTTP 400 if the value is actually unusable). Local Workshop mirror
|
|
834
|
-
* requests deliberately skip this header (project routing is a cloud-only
|
|
835
|
-
* concept), mirroring the `@raindrop-ai/core` convention.
|
|
836
|
-
*/
|
|
837
|
-
projectId?: string;
|
|
838
|
-
/**
|
|
839
|
-
* @deprecated Renamed to `useExternalOtel`. Use that instead.
|
|
840
|
-
* This option will be removed in a future version.
|
|
841
|
-
*/
|
|
842
|
-
disableTracing?: boolean;
|
|
843
|
-
/**
|
|
844
|
-
* Set to true if you have your own OpenTelemetry setup (e.g., Sentry, Datadog).
|
|
845
|
-
*
|
|
846
|
-
* When true:
|
|
847
|
-
* - Raindrop won't create its own NodeSDK (avoids conflicts)
|
|
848
|
-
* - Use `raindrop.createSpanProcessor()` to get a processor for your NodeSDK
|
|
849
|
-
* - Use `raindrop.getInstrumentations()` to get configured LLM instrumentations
|
|
850
|
-
*
|
|
851
|
-
* @example
|
|
852
|
-
* ```ts
|
|
853
|
-
* import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
854
|
-
* import Anthropic from "@anthropic-ai/sdk";
|
|
855
|
-
*
|
|
856
|
-
* const raindrop = new Raindrop({
|
|
857
|
-
* writeKey: "xxx",
|
|
858
|
-
* useExternalOtel: true,
|
|
859
|
-
* instrumentModules: { anthropic: Anthropic },
|
|
860
|
-
* });
|
|
861
|
-
*
|
|
862
|
-
* const sdk = new NodeSDK({
|
|
863
|
-
* spanProcessors: [raindrop.createSpanProcessor(), yourSentryProcessor],
|
|
864
|
-
* instrumentations: raindrop.getInstrumentations(),
|
|
865
|
-
* });
|
|
866
|
-
* sdk.start();
|
|
867
|
-
* ```
|
|
868
|
-
*/
|
|
869
|
-
useExternalOtel?: boolean;
|
|
870
|
-
/**
|
|
871
|
-
* false by default. If true, the SDK will not send any events or initialize tracing.
|
|
872
|
-
* Useful for development/test environments.
|
|
873
|
-
*/
|
|
874
|
-
disabled?: boolean;
|
|
875
|
-
/**
|
|
876
|
-
* Disable span batching for local development.
|
|
877
|
-
* When true, spans are sent immediately instead of being batched.
|
|
878
|
-
* Defaults to true in development (NODE_ENV !== 'production').
|
|
879
|
-
*/
|
|
880
|
-
disableBatching?: boolean;
|
|
881
|
-
/**
|
|
882
|
-
* When true, all `trackTool()`, `withTool()`, and `startToolSpan()` calls bypass the OTEL
|
|
883
|
-
* exporter pipeline and ship spans directly to the Raindrop API via HTTP POST.
|
|
884
|
-
*
|
|
885
|
-
* Spans still read the active OTEL context to inherit traceId
|
|
886
|
-
* and parentSpanId — they still appear as children in the trace tree.
|
|
887
|
-
* Only the shipping mechanism changes.
|
|
888
|
-
*
|
|
889
|
-
* This is useful when OTEL setup is fragile (e.g., conflicting providers,
|
|
890
|
-
* broken exporters) but you still want tool spans to work reliably.
|
|
891
|
-
*
|
|
892
|
-
* @default false
|
|
893
|
-
*/
|
|
894
|
-
bypassOtelForTools?: boolean;
|
|
895
|
-
/**
|
|
896
|
-
* Whether `interaction.finish()` should await the in-flight span/trace flush
|
|
897
|
-
* (i.e. `forceFlush()`, which drains buffered OTLP/tool spans — a `/v1/traces`
|
|
898
|
-
* POST with retries) before resolving. This await was added so a local
|
|
899
|
-
* Workshop daemon doesn't race OTLP ingest; in cloud mode it only adds
|
|
900
|
-
* request latency.
|
|
901
|
-
*
|
|
902
|
-
* Note this gates *only* the span flush. `finish()` always awaits the
|
|
903
|
-
* terminal partial-event POST that records the run, and always orders it
|
|
904
|
-
* after any earlier in-flight POST for the same eventId — to skip the
|
|
905
|
-
* partial POST too, simply don't `await interaction.finish(...)`.
|
|
906
|
-
*
|
|
907
|
-
* - `true` / `undefined` (default) — await the span/trace flush, preserving
|
|
908
|
-
* the historical guaranteed-flush-before-return behavior.
|
|
909
|
-
* - `false` — don't await it; it drains in the background so the caller's
|
|
910
|
-
* request isn't taxed by the round trip + retries. A local Workshop /
|
|
911
|
-
* debugger still forces the await regardless (its read-after-write
|
|
912
|
-
* guarantee depends on it).
|
|
913
|
-
*/
|
|
914
|
-
awaitSpanFlush?: boolean;
|
|
915
|
-
/**
|
|
916
|
-
* Explicitly specify modules to instrument. Optional.
|
|
917
|
-
*
|
|
918
|
-
* Pass the module constructors/namespaces you want to instrument:
|
|
919
|
-
* @example
|
|
920
|
-
* ```ts
|
|
921
|
-
* import OpenAI from "openai";
|
|
922
|
-
* import Anthropic from "@anthropic-ai/sdk";
|
|
923
|
-
*
|
|
924
|
-
* const raindrop = new Raindrop({
|
|
925
|
-
* writeKey: "xxx",
|
|
926
|
-
* instrumentModules: {
|
|
927
|
-
* openAI: OpenAI,
|
|
928
|
-
* anthropic: Anthropic,
|
|
929
|
-
* },
|
|
930
|
-
* });
|
|
931
|
-
* ```
|
|
932
|
-
*/
|
|
933
|
-
instrumentModules?: {
|
|
934
|
-
openAI?: unknown;
|
|
935
|
-
anthropic?: unknown;
|
|
936
|
-
cohere?: unknown;
|
|
937
|
-
bedrock?: unknown;
|
|
938
|
-
google_vertexai?: unknown;
|
|
939
|
-
google_aiplatform?: unknown;
|
|
940
|
-
pinecone?: unknown;
|
|
941
|
-
together?: unknown;
|
|
942
|
-
langchain?: boolean;
|
|
943
|
-
llamaIndex?: unknown;
|
|
944
|
-
chromadb?: unknown;
|
|
945
|
-
qdrant?: unknown;
|
|
946
|
-
mcp?: unknown;
|
|
947
|
-
} & Record<string, unknown>;
|
|
948
|
-
}
|
|
949
|
-
declare const MAX_INGEST_SIZE_BYTES: number;
|
|
950
|
-
/**
|
|
951
|
-
* Resolve the effective `disableBatching` flag that decides whether tracing
|
|
952
|
-
* uses `SimpleSpanProcessor` (immediate export) or `BatchSpanProcessor`.
|
|
953
|
-
*
|
|
954
|
-
* Precedence:
|
|
955
|
-
* 1. An explicit `config.disableBatching` always wins, in both directions.
|
|
956
|
-
* 2. Otherwise, batching is disabled when NOT in production (existing
|
|
957
|
-
* behavior) OR when the local debugger (Workshop) is active — so spans
|
|
958
|
-
* deliver immediately to Workshop even under `NODE_ENV=production`.
|
|
959
|
-
*
|
|
960
|
-
* Production behavior for consumers is unchanged: with no local debugger and
|
|
961
|
-
* no explicit config, this returns `false` (i.e. batching stays on).
|
|
962
|
-
*/
|
|
963
|
-
declare function resolveDisableBatching(explicit: boolean | undefined, signals: {
|
|
964
|
-
isProduction: boolean;
|
|
965
|
-
isLocalDebugger: boolean;
|
|
966
|
-
}): boolean;
|
|
967
|
-
declare class Raindrop {
|
|
968
|
-
private wizardSession;
|
|
969
|
-
private writeKey;
|
|
970
|
-
private apiUrl;
|
|
971
|
-
private buffer;
|
|
972
|
-
private bufferSize;
|
|
973
|
-
private bufferTimeout;
|
|
974
|
-
private flushTimer;
|
|
975
|
-
private redactPii;
|
|
976
|
-
private disabled;
|
|
977
|
-
private context;
|
|
978
|
-
private _tracing;
|
|
979
|
-
private localDebuggerUrlOpt;
|
|
980
|
-
private awaitSpanFlushOpt;
|
|
981
|
-
private partialEventBuffer;
|
|
982
|
-
private partialEventTimeouts;
|
|
983
|
-
private inFlightRequests;
|
|
984
|
-
private inFlightByEvent;
|
|
985
|
-
private maxTextFieldChars;
|
|
986
|
-
private projectId;
|
|
987
|
-
private authHint;
|
|
988
|
-
/**
|
|
989
|
-
* Epoch ms deadline while `close()` is draining; undefined otherwise.
|
|
990
|
-
* Checked before every POST issued during the final flush so a dead or
|
|
991
|
-
* slow network can never wedge process exit.
|
|
992
|
-
*/
|
|
993
|
-
private shutdownDeadlineAt;
|
|
994
|
-
/**
|
|
995
|
-
* Set once `close()` begins and never cleared. Sends issued after the
|
|
996
|
-
* drain window (stragglers, or flush work the deadline abandoned
|
|
997
|
-
* mid-drain) run as a single short attempt instead of regaining the full
|
|
998
|
-
* retry schedule.
|
|
999
|
-
*/
|
|
1000
|
-
private hasShutdown;
|
|
1001
|
-
debugLogs: boolean;
|
|
1002
|
-
constructor(config: AnalyticsConfig);
|
|
1003
|
-
private get localOnly();
|
|
1004
|
-
private formatEndpoint;
|
|
1005
|
-
/**
|
|
1006
|
-
* Begins a new interaction.
|
|
1007
|
-
*
|
|
1008
|
-
* The interaction's routing binding lives until `finish()` (which unbinds it
|
|
1009
|
-
* by identity, so it is removed even if `finish()` runs inside a nested
|
|
1010
|
-
* `withSpan`/`withTool`/`asCurrent` scope or a detached task). One exception:
|
|
1011
|
-
* calling `begin()` INSIDE an `asCurrent(fn)` scope pushes the binding within
|
|
1012
|
-
* that scope, so it dies when the scope exits (matching the Python SDK's
|
|
1013
|
-
* token-reset semantics) — start such interactions outside `asCurrent`, or
|
|
1014
|
-
* keep their work inside the same scope.
|
|
1015
|
-
*
|
|
1016
|
-
* @param traceContext - The trace context for the interaction.
|
|
1017
|
-
* @returns The interaction object.
|
|
1018
|
-
*/
|
|
1019
|
-
begin(traceContext: PartialAiTrackEvent & {
|
|
1020
|
-
event: string;
|
|
1021
|
-
userId: string;
|
|
1022
|
-
}): Interaction;
|
|
1023
|
-
/**
|
|
1024
|
-
* Returns a tracer object that can be used to create spans and tools that aren't tied to any interaction.
|
|
1025
|
-
* For chat interaction use-case `begin` should be used.
|
|
1026
|
-
* This is meant for batch jobs or other non-interactive use-cases where you only care about tracing and token usage.
|
|
1027
|
-
*
|
|
1028
|
-
* @param globalProperties - Optional global properties to be associated with all spans and tools.
|
|
1029
|
-
* @returns The tracer object.
|
|
1030
|
-
*/
|
|
1031
|
-
tracer(globalProperties?: Record<string, string>): Tracer;
|
|
1032
|
-
/**
|
|
1033
|
-
* Scope all spans created inside `fn` (and its awaited continuations) to this
|
|
1034
|
-
* client's project/key, without an interaction. Use it around auto-
|
|
1035
|
-
* instrumented calls (an LLM SDK call, a framework invocation) that aren't
|
|
1036
|
-
* wrapped by `begin()`/`finish()` so their spans route to this client's
|
|
1037
|
-
* project in a multi-client process. The binding lasts exactly the duration
|
|
1038
|
-
* of `fn` — it is removed when `fn` returns or throws.
|
|
1039
|
-
*
|
|
1040
|
-
* @example
|
|
1041
|
-
* ```ts
|
|
1042
|
-
* const answer = await raindrop.asCurrent(() => llm.chat({ ... }));
|
|
1043
|
-
* ```
|
|
1044
|
-
*/
|
|
1045
|
-
asCurrent<T>(fn: () => T): T;
|
|
1046
|
-
createSpanProcessor(processorOptions?: SpanProcessorOptions): RaindropSpanProcessor;
|
|
1047
|
-
/**
|
|
1048
|
-
* Returns configured instrumentation instances based on instrumentModules.
|
|
1049
|
-
* Add these to your NodeSDK when using useExternalOtel: true.
|
|
1050
|
-
*
|
|
1051
|
-
* @example
|
|
1052
|
-
* ```ts
|
|
1053
|
-
* import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
1054
|
-
* import Anthropic from "@anthropic-ai/sdk";
|
|
1055
|
-
*
|
|
1056
|
-
* const raindrop = new Raindrop({
|
|
1057
|
-
* writeKey: "xxx",
|
|
1058
|
-
* useExternalOtel: true,
|
|
1059
|
-
* instrumentModules: { anthropic: Anthropic },
|
|
1060
|
-
* });
|
|
1061
|
-
*
|
|
1062
|
-
* const sdk = new NodeSDK({
|
|
1063
|
-
* spanProcessors: [raindrop.createSpanProcessor()],
|
|
1064
|
-
* instrumentations: raindrop.getInstrumentations(),
|
|
1065
|
-
* });
|
|
1066
|
-
* sdk.start();
|
|
1067
|
-
* ```
|
|
1068
|
-
*/
|
|
1069
|
-
getInstrumentations(): _opentelemetry_instrumentation.Instrumentation<_opentelemetry_instrumentation.InstrumentationConfig>[];
|
|
1070
|
-
/**
|
|
1071
|
-
* Resumes an existing interaction.
|
|
1072
|
-
*
|
|
1073
|
-
* @param eventId - The ID of the interaction to resume.
|
|
1074
|
-
* @returns The interaction object.
|
|
1075
|
-
*/
|
|
1076
|
-
resumeInteraction(eventId: string): Interaction;
|
|
1077
|
-
/**
|
|
1078
|
-
* Creates a framework-agnostic self-diagnostics tool definition.
|
|
1079
|
-
*
|
|
1080
|
-
* Use this when your agent framework does not support automatic tool injection.
|
|
1081
|
-
* The returned object includes adapters for Vercel AI SDK, OpenAI function tools,
|
|
1082
|
-
* and Anthropic tool definitions.
|
|
1083
|
-
*/
|
|
1084
|
-
createSelfDiagnosticsTool(options?: SelfDiagnosticsToolOptions): SelfDiagnosticsTool;
|
|
1085
|
-
/**
|
|
1086
|
-
* Track AI events. In addiiton to normal event properties, you can provide an "input", "output", or "model" parameter.
|
|
1087
|
-
* It takes an AiTrackEvent as input and sends it to the /track-ai endpoint of the raindrop api.
|
|
1088
|
-
*
|
|
1089
|
-
* @param event - The AiTrackEvent (you must specify at least one of input/output properties)
|
|
1090
|
-
* @returns A Promise that resolves when the event has been successfully sent.
|
|
1091
|
-
*
|
|
1092
|
-
* Example usage:
|
|
1093
|
-
* ```typescript
|
|
1094
|
-
* raindrop.track_ai({
|
|
1095
|
-
* event: "chat", //name of the event
|
|
1096
|
-
* model: "claude", //optional
|
|
1097
|
-
* input: "what's up?", // input or output is required
|
|
1098
|
-
* output: "not much human, how are you?", //input or output is required
|
|
1099
|
-
* userId: "cn123456789",
|
|
1100
|
-
* });
|
|
1101
|
-
* ```
|
|
1102
|
-
*/
|
|
1103
|
-
trackAi(event: AiTrackEvent | AiTrackEvent[]): string | Array<string | undefined> | undefined;
|
|
1104
|
-
setUserDetails(event: IdentifyEvent): void;
|
|
1105
|
-
/**
|
|
1106
|
-
* Report a self-diagnostic signal. This is a convenient shorthand for sending
|
|
1107
|
-
* signals that appear in the Self Diagnostics tab of the Raindrop dashboard.
|
|
1108
|
-
*
|
|
1109
|
-
* @param options - The diagnostic details.
|
|
1110
|
-
* @param options.eventId - The interaction/event ID this diagnostic belongs to.
|
|
1111
|
-
* @param options.description - A human-readable description of the issue.
|
|
1112
|
-
* @param options.category - Optional category (e.g. "missing_context"). Defaults to "general".
|
|
1113
|
-
* @param options.source - Optional source identifier. Defaults to "selfDiagnose".
|
|
1114
|
-
* @param options.sentiment - Signal sentiment. Defaults to "NEGATIVE".
|
|
1115
|
-
* @param options.properties - Additional custom properties.
|
|
1116
|
-
*
|
|
1117
|
-
* @example
|
|
1118
|
-
* ```typescript
|
|
1119
|
-
* raindrop.selfDiagnose({
|
|
1120
|
-
* eventId: "evt_123",
|
|
1121
|
-
* description: "User asked for production DB access but no credentials were provided.",
|
|
1122
|
-
* category: "missing_context",
|
|
1123
|
-
* });
|
|
1124
|
-
* ```
|
|
1125
|
-
*/
|
|
1126
|
-
selfDiagnose(options: SelfDiagnoseOptions): void;
|
|
1127
|
-
trackSignal(signal: SignalEvent | SignalEvent[]): void | void[];
|
|
1128
|
-
private getSize;
|
|
1129
|
-
private saveToBuffer;
|
|
1130
|
-
private flush;
|
|
1131
|
-
private mirrorBatchToLocalDebugger;
|
|
1132
|
-
/**
|
|
1133
|
-
* Attempts/timeout budget for one POST, honoring the close() deadline.
|
|
1134
|
-
* Returns `null` when the shutdown budget is exhausted — the caller must
|
|
1135
|
-
* drop the payload instead of issuing a request that could outlive
|
|
1136
|
-
* process exit. Checked fresh on every send so a deadline that expires
|
|
1137
|
-
* mid-drain takes effect immediately.
|
|
1138
|
-
*/
|
|
1139
|
-
private requestBudget;
|
|
1140
|
-
private warnShutdownDrop;
|
|
1141
|
-
private sendBatchToApi;
|
|
1142
|
-
private getContext;
|
|
1143
|
-
private formatZodError;
|
|
1144
|
-
/**
|
|
1145
|
-
* Deeply merges properties of the source object into the target object.
|
|
1146
|
-
* Modifies the target object in place. Handles nested plain objects.
|
|
1147
|
-
*/
|
|
1148
|
-
private deepMergeObjects;
|
|
1149
|
-
/**
|
|
1150
|
-
* Internal method for tracking partial AI events. use .begin() to start an interaction instead.
|
|
1151
|
-
*
|
|
1152
|
-
* @param event - The PartialAiTrackEvent, requires eventId.
|
|
1153
|
-
*/
|
|
1154
|
-
_trackAiPartial(event: PartialAiTrackEvent): Promise<void>;
|
|
1155
|
-
/**
|
|
1156
|
-
* Flushes a single accumulated partial event by its ID.
|
|
1157
|
-
* This is called internally by the timeout or by the close method.
|
|
1158
|
-
* @param eventId - The ID of the partial event to flush.
|
|
1159
|
-
*/
|
|
1160
|
-
private flushPartialEvent;
|
|
1161
|
-
/**
|
|
1162
|
-
* Internal implementation of flushPartialEvent without request tracking.
|
|
1163
|
-
* @param eventId - The ID of the partial event to flush.
|
|
1164
|
-
*/
|
|
1165
|
-
private _flushPartialEventInternal;
|
|
1166
|
-
/**
|
|
1167
|
-
* Sends a single prepared event object to the 'events/track_partial' endpoint.
|
|
1168
|
-
* @param event - The event data conforming to ClientAiTrack schema.
|
|
1169
|
-
*/
|
|
1170
|
-
private sendPartialEvent;
|
|
1171
|
-
/**
|
|
1172
|
-
* Best-effort flush of in-flight OTel spans and pending partial-event POSTs.
|
|
1173
|
-
* Safe to call multiple times; never throws.
|
|
1174
|
-
*/
|
|
1175
|
-
forceFlush(): Promise<void>;
|
|
1176
|
-
close(): Promise<void>;
|
|
1177
|
-
private closeWithinDeadline;
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
export { type AiTrackEvent, type Attachment, type AttachmentType, type BeginInteractionOptions, type FinishInteractionOptions, type IdentifyEvent, type Interaction, type LocalDebuggerLiveEventInput, MAX_INGEST_SIZE_BYTES, type PartialAiTrackEvent, Raindrop, type RaindropFeatureFlagValue, type RaindropFeatureFlags, type RaindropProperties, type RaindropPropertyLeaf, type RaindropPropertyValue, type RaindropSpanProcessor, type SelfDiagnoseOptions, type SelfDiagnosticsExecuteContext, type SelfDiagnosticsExecuteResult, type SelfDiagnosticsSignalDefinition, type SelfDiagnosticsSignalDefinitions, type SelfDiagnosticsTool, type SelfDiagnosticsToolInputSchema, type SelfDiagnosticsToolOptions, type SignalEvent, type SpanParams, type ToolParams, type ToolSpan, type TraceContext, type Tracer, type TrackToolParams, type WorkflowParams, Raindrop as default, resolveDisableBatching };
|
|
1
|
+
import '@opentelemetry/instrumentation';
|
|
2
|
+
export { A as AiTrackEvent, d as Attachment, e as AttachmentType, B as BeginInteractionOptions, F as FinishInteractionOptions, f as IdentifyEvent, I as Interaction, L as LocalDebuggerLiveEventInput, M as MAX_INGEST_SIZE_BYTES, P as PartialAiTrackEvent, R as Raindrop, g as RaindropFeatureFlagValue, h as RaindropFeatureFlags, i as RaindropProperties, j as RaindropPropertyLeaf, k as RaindropPropertyValue, a as RaindropSpanProcessor, l as SelfDiagnoseOptions, m as SelfDiagnosticsExecuteContext, n as SelfDiagnosticsExecuteResult, o as SelfDiagnosticsSignalDefinition, p as SelfDiagnosticsSignalDefinitions, q as SelfDiagnosticsTool, r as SelfDiagnosticsToolInputSchema, s as SelfDiagnosticsToolOptions, t as SignalEvent, u as SpanParams, v as SubagentDispatch, w as SubagentDispatchOptions, x as SubagentFinishOptions, S as SubagentResumeOptions, b as SubagentRun, y as ToolParams, z as ToolSpan, D as TraceContext, c as Tracer, E as TrackToolParams, W as WorkflowParams, R as default, G as resolveDisableBatching } from './index-DBdUrUXc.mjs';
|
|
3
|
+
import '@traceloop/node-server-sdk';
|
|
4
|
+
import '@opentelemetry/api';
|
|
5
|
+
import 'zod';
|