@raindrop-ai/ai-sdk 0.0.32 → 0.0.34

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.
@@ -35,7 +35,6 @@ type SpanIds = {
35
35
  spanIdB64: string;
36
36
  parentSpanIdB64?: string;
37
37
  };
38
-
39
38
  type Attachment$1 = {
40
39
  type: string;
41
40
  role: string;
@@ -84,6 +83,14 @@ type EventShipperOptions = {
84
83
  * Pass `null` to opt out of all mirroring (including auto-detect).
85
84
  */
86
85
  localDebuggerUrl?: string | null;
86
+ /**
87
+ * Per-field character cap applied to event input/output BEFORE buffering
88
+ * or serialization, so oversized payloads cost the cap — not the payload —
89
+ * on the calling code path. Truncated fields end with
90
+ * `...[truncated by raindrop]` and never exceed the cap, marker included.
91
+ * Defaults to 1,000,000 (matching the Python SDK).
92
+ */
93
+ maxTextFieldChars?: number;
87
94
  };
88
95
  declare class EventShipper$1 {
89
96
  private baseUrl;
@@ -99,11 +106,39 @@ declare class EventShipper$1 {
99
106
  private sticky;
100
107
  private timers;
101
108
  private inFlight;
109
+ private maxTextFieldCharsOpt;
110
+ /**
111
+ * Epoch ms deadline while `shutdown()` is draining; undefined otherwise.
112
+ * Checked before every POST issued during the final flush.
113
+ */
114
+ private shutdownDeadlineAt;
115
+ /**
116
+ * Set once `shutdown()` begins and never cleared. Sends issued after the
117
+ * drain window (stragglers, or flush work the deadline abandoned
118
+ * mid-drain) run as a single short attempt instead of regaining the full
119
+ * retry schedule.
120
+ */
121
+ private hasShutdown;
102
122
  /** URL of the local debugger / Workshop daemon, when one is reachable. */
103
123
  private localDebuggerUrl;
104
124
  constructor(opts: EventShipperOptions);
105
125
  isDebugEnabled(): boolean;
106
126
  private authHeaders;
127
+ /**
128
+ * Build the retry/timeout options for one POST, honoring the shutdown
129
+ * deadline. Returns `null` when the shutdown drain window is exhausted —
130
+ * the caller must drop the payload (with a rate-limited warning) instead
131
+ * of issuing a request that could outlive process exit.
132
+ *
133
+ * Checked fresh on EVERY send, so a shutdown that begins while the flush
134
+ * path is mid-drain takes effect immediately: no further retries, and the
135
+ * per-attempt timeout is clamped to the remaining window. After
136
+ * `shutdown()` returns (deadline cleared, `hasShutdown` still set),
137
+ * sends — late callers, or flush work the deadline abandoned mid-drain —
138
+ * run as a single short attempt rather than regaining the full retry
139
+ * schedule.
140
+ */
141
+ private requestOpts;
107
142
  patch(eventId: string, patch: Patch): Promise<void>;
108
143
  finish(eventId: string, patch: {
109
144
  output?: string;
@@ -115,6 +150,7 @@ declare class EventShipper$1 {
115
150
  shutdown(): Promise<void>;
116
151
  trackSignal(signal: SignalInput): Promise<void>;
117
152
  identify(users: IdentifyInput$1 | IdentifyInput$1[]): Promise<void>;
153
+ private warnShutdownDrop;
118
154
  private flushOne;
119
155
  }
120
156
 
@@ -252,6 +288,15 @@ type TraceShipperOptions = {
252
288
  * still want some redaction in that case.
253
289
  */
254
290
  disableDefaultRedaction?: boolean;
291
+ /**
292
+ * Per-attribute character cap applied to every span attribute string value
293
+ * right before the span enters a ship path, so a multi-MB prompt/tool
294
+ * payload can never make the batch `JSON.stringify` (which runs on the
295
+ * event loop) cost seconds. Truncated values end with
296
+ * `...[truncated by raindrop]` and never exceed the cap, marker included.
297
+ * Defaults to 1,000,000 (matching the Python SDK).
298
+ */
299
+ maxTextFieldChars?: number;
255
300
  };
256
301
  declare class TraceShipper$1 {
257
302
  private baseUrl;
@@ -273,7 +318,32 @@ declare class TraceShipper$1 {
273
318
  private localDebuggerUrl;
274
319
  private transformSpanHook;
275
320
  private disableDefaultRedaction;
321
+ private maxTextFieldCharsOpt;
322
+ /**
323
+ * Epoch ms deadline while `shutdown()` is draining; undefined otherwise.
324
+ * Checked before every batch POST issued during the final flush.
325
+ */
326
+ private shutdownDeadlineAt;
327
+ /**
328
+ * Set once `shutdown()` begins and never cleared. Sends issued after the
329
+ * drain window (stragglers, or flush work the deadline abandoned
330
+ * mid-drain) run as a single short attempt instead of regaining the full
331
+ * retry schedule.
332
+ */
333
+ private hasShutdown;
276
334
  constructor(opts: TraceShipperOptions);
335
+ /**
336
+ * Cap every string attribute value on the span. O(#attributes) length
337
+ * checks; only oversized values pay a slice. Runs AFTER the redaction
338
+ * pipeline so the default secret-scrub still sees parseable JSON in
339
+ * `ai.request.providerOptions` / `ai.response.providerMetadata` (capping
340
+ * first could cut a JSON blob mid-way, fail the parse, and ship secrets
341
+ * in the surviving prefix).
342
+ *
343
+ * A stricter `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` env var is honored
344
+ * for span content, matching the Python SDK and the OTel SDK convention.
345
+ */
346
+ private capSpanAttributes;
277
347
  /**
278
348
  * Apply the user `transformSpan` hook (if any) followed by the default
279
349
  * redactor (unless disabled). Returns either the (possibly new) span to
@@ -323,6 +393,8 @@ declare class TraceShipper$1 {
323
393
  }): void;
324
394
  enqueue(span: OtlpSpan): void;
325
395
  flush(): Promise<void>;
396
+ /** See EventShipper.requestOpts — same shutdown-budget semantics. */
397
+ private requestOpts;
326
398
  shutdown(): Promise<void>;
327
399
  }
328
400
 
@@ -365,6 +437,29 @@ declare class TraceShipper extends TraceShipper$1 {
365
437
  }
366
438
 
367
439
  type Listener<T> = (event: T) => PromiseLike<void> | void;
440
+ type ToolExecutionEndEvent = {
441
+ callId: string;
442
+ toolCall: {
443
+ toolCallId: string;
444
+ toolName: string;
445
+ };
446
+ toolOutput: {
447
+ type: "tool-result";
448
+ output: unknown;
449
+ } | {
450
+ type: "tool-error";
451
+ error: unknown;
452
+ };
453
+ } | {
454
+ callId: string;
455
+ toolCall: {
456
+ toolCallId: string;
457
+ toolName: string;
458
+ };
459
+ success: boolean;
460
+ output?: unknown;
461
+ error?: unknown;
462
+ };
368
463
  interface TelemetryIntegration {
369
464
  onStart?: Listener<any>;
370
465
  onStepStart?: Listener<any>;
@@ -381,6 +476,7 @@ interface TelemetryIntegration {
381
476
  onEmbedEnd?: Listener<any>;
382
477
  onFinish?: Listener<any>;
383
478
  onEnd?: Listener<any>;
479
+ onAbort?: Listener<any>;
384
480
  onError?: Listener<any>;
385
481
  executeTool?: <T>(params: {
386
482
  callId: string;
@@ -441,6 +537,10 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
441
537
  */
442
538
  private readonly priorParentContexts;
443
539
  constructor(opts: RaindropTelemetryIntegrationOptions);
540
+ /** Flush any buffered events and trace spans to their destinations. */
541
+ flush: () => Promise<void>;
542
+ /** Flush and stop the background flush timers. */
543
+ shutdown: () => Promise<void>;
444
544
  private getState;
445
545
  private cleanup;
446
546
  private spanParentRef;
@@ -456,9 +556,9 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
456
556
  private toolExecutionStart;
457
557
  private toolExecutionEnd;
458
558
  onToolExecutionStart: (event: any) => void;
459
- onToolExecutionEnd: (event: any) => void;
559
+ onToolExecutionEnd: (event: ToolExecutionEndEvent) => void;
460
560
  onToolCallStart: (event: any) => void;
461
- onToolCallFinish: (event: any) => void;
561
+ onToolCallFinish: (event: ToolExecutionEndEvent) => void;
462
562
  onLanguageModelCallStart: (_event: any) => void;
463
563
  onLanguageModelCallEnd: (_event: any) => void;
464
564
  onChunk: (event: any) => void;
@@ -470,8 +570,15 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
470
570
  onFinish: (event: any) => void;
471
571
  onEnd: (event: any) => void;
472
572
  private finishGenerate;
573
+ /**
574
+ * Patch the Raindrop event for a completed, aborted, or errored text
575
+ * generation so it leaves the `isPending` state. Shared by `onFinish`/`onEnd`,
576
+ * `onAbort`, and `onError`.
577
+ */
578
+ private finalizeGenerateEvent;
473
579
  private finishEmbed;
474
580
  onError: (error: unknown) => void;
581
+ onAbort: (event: any) => void;
475
582
  executeTool: <T>({ callId, toolCallId, execute, }: {
476
583
  callId: string;
477
584
  toolCallId: string;
@@ -484,6 +591,33 @@ type IdentifyInput = {
484
591
  traits?: Record<string, unknown>;
485
592
  };
486
593
 
594
+ declare const TRUNCATION_MARKER = "...[truncated by raindrop]";
595
+ declare const DEFAULT_MAX_TEXT_FIELD_CHARS = 1000000;
596
+ /**
597
+ * Cap a raw text field BEFORE it is buffered or attached to a span.
598
+ *
599
+ * The length check is O(1), so multi-MB strings cost nothing on the caller
600
+ * beyond the slice that keeps the first `limit` chars. Non-string values
601
+ * (including `undefined`) pass through untouched.
602
+ */
603
+ declare function capText(value: string, limit?: number): string;
604
+ declare function capText(value: string | undefined, limit?: number): string | undefined;
605
+ /**
606
+ * JSON-serialize `value` with a hard output budget.
607
+ *
608
+ * Unlike serialize-then-truncate, the cost here is proportional to the
609
+ * limit, not the payload: the value is pruned by `boundedClone` first, so a
610
+ * multi-MB tool result can never burn seconds of CPU on the calling thread
611
+ * (which is typically the host app's event loop). Matching the previous
612
+ * `safeJson` semantics, returns `undefined` when the value cannot be
613
+ * serialized (e.g. BigInt leaves) — and, like any display truncation, a
614
+ * truncated result may not be valid JSON.
615
+ *
616
+ * Small payloads (within the budget) serialize exactly like
617
+ * `JSON.stringify`, except `Uint8Array` values become base64 strings.
618
+ */
619
+ declare function boundedStringify(value: unknown, limit?: number): string | undefined;
620
+
487
621
  type RaindropCallMetadata = {
488
622
  userId?: string;
489
623
  eventId?: string;
@@ -824,6 +958,17 @@ type RaindropAISDKOptions = {
824
958
  partialFlushMs?: number;
825
959
  debug?: boolean;
826
960
  };
961
+ /**
962
+ * Per-field character cap applied to ai input/output text and serialized
963
+ * tool/LLM span payloads BEFORE (or during) serialization, so oversized
964
+ * payloads cost the cap — not the payload — on the calling thread.
965
+ * Truncated values end with `...[truncated by raindrop]` and never exceed
966
+ * the cap. A stricter `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` env var is
967
+ * honored. Applies module-wide: the last `createRaindropAISDK` call that
968
+ * sets this option wins; omitting it leaves the current cap unchanged.
969
+ * Defaults to 1,000,000.
970
+ */
971
+ maxTextFieldChars?: number;
827
972
  };
828
973
  type RaindropAISDKContext = {
829
974
  userId?: string;
@@ -1102,5 +1247,53 @@ type RaindropAISDKClient = {
1102
1247
  shutdown(): Promise<void>;
1103
1248
  };
1104
1249
  declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
1250
+ /**
1251
+ * Options for the {@link raindrop} telemetry-integration factory. A superset of
1252
+ * {@link RaindropAISDKOptions} plus the per-integration `context` defaults and
1253
+ * `subagentWrapping` toggle accepted by `createTelemetryIntegration()`.
1254
+ */
1255
+ type RaindropTelemetryOptions = RaindropAISDKOptions & {
1256
+ /** Default Raindrop context (userId/eventName/convoId/properties) applied to every call. */
1257
+ context?: RaindropTelemetryIntegrationOptions["context"];
1258
+ /**
1259
+ * Wrap sub-agent generations (a `generateText`/`streamText` invoked from
1260
+ * inside a tool's `execute`) in a synthetic tool span so parent and child
1261
+ * spans nest correctly. Enabled by default.
1262
+ */
1263
+ subagentWrapping?: boolean;
1264
+ };
1265
+ /**
1266
+ * One-line factory for the AI SDK v7 `registerTelemetry` DX.
1267
+ *
1268
+ * Returns a {@link RaindropTelemetryIntegration} wired to Raindrop's trace +
1269
+ * event shippers, ready to hand to the AI SDK's `registerTelemetry`. The
1270
+ * `writeKey` defaults to the `RAINDROP_WRITE_KEY` environment variable.
1271
+ *
1272
+ * @example
1273
+ * ```ts
1274
+ * import { generateText, registerTelemetry } from "ai";
1275
+ * import { OpenTelemetry } from "@ai-sdk/otel";
1276
+ * import { raindrop } from "@raindrop-ai/ai-sdk";
1277
+ *
1278
+ * registerTelemetry(new OpenTelemetry(), raindrop());
1279
+ *
1280
+ * await generateText({
1281
+ * model: anthropic("claude-sonnet-4-5"),
1282
+ * prompt: "what is the weather in Tokyo?",
1283
+ * telemetry: { functionId: "weather-agent" },
1284
+ * });
1285
+ * ```
1286
+ *
1287
+ * The returned integration also exposes `flush()` / `shutdown()` for
1288
+ * short-lived scripts that need to drain buffered telemetry before exiting:
1289
+ *
1290
+ * ```ts
1291
+ * const rd = raindrop();
1292
+ * registerTelemetry(rd);
1293
+ * // ...
1294
+ * await rd.flush();
1295
+ * ```
1296
+ */
1297
+ declare function raindrop(options?: RaindropTelemetryOptions): RaindropTelemetryIntegration;
1105
1298
 
1106
- export { redactJsonAttributeValue as $, type AISDKChatRequestLike as A, type BuildEventPatch as B, ContextManager as C, DEFAULT_REDACT_ATTRIBUTE_KEYS as D, type EndSpanArgs as E, type WrappedAISDK as F, _resetRaindropCallMetadataStorage as G, _resetWarnedMissingUserId as H, type IdentifyInput as I, clearParentToolContext as J, createRaindropAISDK as K, currentSpan as L, defaultTransformSpan as M, enterParentToolContext as N, type OtlpAnyValue as O, type ParentToolContext as P, eventMetadata as Q, REDACTED_PLACEHOLDER as R, type SelfDiagnosticsOptions as S, type TraceSpan as T, eventMetadataFromChatRequest as U, getContextManager as V, type WrapAISDKOptions as W, getCurrentParentToolContext as X, getCurrentRaindropCallMetadata as Y, readRaindropCallMetadataFromArgs as Z, _resetParentToolContextStorage as _, type AISDKChatRequestMessageLike as a, redactSecretsInObject as a0, runWithParentToolContext as a1, runWithRaindropCallMetadata as a2, withCurrent as a3, type AISDKMessage as b, type AgentCallMetadata as c, type AgentWithMetadata as d, type Attachment as e, type ContextSpan as f, type CreateSpanArgs as g, DEFAULT_SECRET_KEY_NAMES as h, type EventBuilder as i, type EventMetadataOptions as j, type OtlpSpan as k, type RaindropAISDKClient as l, type RaindropAISDKContext as m, type RaindropAISDKOptions as n, type RaindropCallMetadata as o, RaindropTelemetryIntegration as p, type RaindropTelemetryIntegrationOptions as q, type SelfDiagnosticsSignalDefinition as r, type SelfDiagnosticsSignalDefinitions as s, type SelfDiagnosticsTool as t, type SelfDiagnosticsToolInput as u, type SelfDiagnosticsToolOptions as v, type SelfDiagnosticsToolResult as w, type StartSpanArgs as x, type TransformSpanHook as y, type WrappedAI as z };
1299
+ export { eventMetadataFromChatRequest as $, type AISDKChatRequestLike as A, type BuildEventPatch as B, ContextManager as C, DEFAULT_MAX_TEXT_FIELD_CHARS as D, type EndSpanArgs as E, type TraceSpan as F, type TransformSpanHook as G, type WrappedAI as H, type IdentifyInput as I, type WrappedAISDK as J, _resetRaindropCallMetadataStorage as K, _resetWarnedMissingUserId as L, boundedStringify as M, capText as N, type OtlpAnyValue as O, type ParentToolContext as P, clearParentToolContext as Q, REDACTED_PLACEHOLDER as R, type SelfDiagnosticsOptions as S, TRUNCATION_MARKER as T, createRaindropAISDK as U, currentSpan as V, type WrapAISDKOptions as W, defaultTransformSpan as X, enterParentToolContext as Y, eventMetadata as Z, _resetParentToolContextStorage as _, type AISDKChatRequestMessageLike as a, getContextManager as a0, getCurrentParentToolContext as a1, getCurrentRaindropCallMetadata as a2, raindrop as a3, readRaindropCallMetadataFromArgs as a4, redactJsonAttributeValue as a5, redactSecretsInObject as a6, runWithParentToolContext as a7, runWithRaindropCallMetadata as a8, withCurrent as a9, type AISDKMessage as b, type AgentCallMetadata as c, type AgentWithMetadata as d, type Attachment as e, type ContextSpan as f, type CreateSpanArgs as g, DEFAULT_REDACT_ATTRIBUTE_KEYS as h, DEFAULT_SECRET_KEY_NAMES as i, type EventBuilder as j, type EventMetadataOptions as k, type OtlpSpan as l, type RaindropAISDKClient as m, type RaindropAISDKContext as n, type RaindropAISDKOptions as o, type RaindropCallMetadata as p, RaindropTelemetryIntegration as q, type RaindropTelemetryIntegrationOptions as r, type RaindropTelemetryOptions as s, type SelfDiagnosticsSignalDefinition as t, type SelfDiagnosticsSignalDefinitions as u, type SelfDiagnosticsTool as v, type SelfDiagnosticsToolInput as w, type SelfDiagnosticsToolOptions as x, type SelfDiagnosticsToolResult as y, type StartSpanArgs as z };
@@ -35,7 +35,6 @@ type SpanIds = {
35
35
  spanIdB64: string;
36
36
  parentSpanIdB64?: string;
37
37
  };
38
-
39
38
  type Attachment$1 = {
40
39
  type: string;
41
40
  role: string;
@@ -84,6 +83,14 @@ type EventShipperOptions = {
84
83
  * Pass `null` to opt out of all mirroring (including auto-detect).
85
84
  */
86
85
  localDebuggerUrl?: string | null;
86
+ /**
87
+ * Per-field character cap applied to event input/output BEFORE buffering
88
+ * or serialization, so oversized payloads cost the cap — not the payload —
89
+ * on the calling code path. Truncated fields end with
90
+ * `...[truncated by raindrop]` and never exceed the cap, marker included.
91
+ * Defaults to 1,000,000 (matching the Python SDK).
92
+ */
93
+ maxTextFieldChars?: number;
87
94
  };
88
95
  declare class EventShipper$1 {
89
96
  private baseUrl;
@@ -99,11 +106,39 @@ declare class EventShipper$1 {
99
106
  private sticky;
100
107
  private timers;
101
108
  private inFlight;
109
+ private maxTextFieldCharsOpt;
110
+ /**
111
+ * Epoch ms deadline while `shutdown()` is draining; undefined otherwise.
112
+ * Checked before every POST issued during the final flush.
113
+ */
114
+ private shutdownDeadlineAt;
115
+ /**
116
+ * Set once `shutdown()` begins and never cleared. Sends issued after the
117
+ * drain window (stragglers, or flush work the deadline abandoned
118
+ * mid-drain) run as a single short attempt instead of regaining the full
119
+ * retry schedule.
120
+ */
121
+ private hasShutdown;
102
122
  /** URL of the local debugger / Workshop daemon, when one is reachable. */
103
123
  private localDebuggerUrl;
104
124
  constructor(opts: EventShipperOptions);
105
125
  isDebugEnabled(): boolean;
106
126
  private authHeaders;
127
+ /**
128
+ * Build the retry/timeout options for one POST, honoring the shutdown
129
+ * deadline. Returns `null` when the shutdown drain window is exhausted —
130
+ * the caller must drop the payload (with a rate-limited warning) instead
131
+ * of issuing a request that could outlive process exit.
132
+ *
133
+ * Checked fresh on EVERY send, so a shutdown that begins while the flush
134
+ * path is mid-drain takes effect immediately: no further retries, and the
135
+ * per-attempt timeout is clamped to the remaining window. After
136
+ * `shutdown()` returns (deadline cleared, `hasShutdown` still set),
137
+ * sends — late callers, or flush work the deadline abandoned mid-drain —
138
+ * run as a single short attempt rather than regaining the full retry
139
+ * schedule.
140
+ */
141
+ private requestOpts;
107
142
  patch(eventId: string, patch: Patch): Promise<void>;
108
143
  finish(eventId: string, patch: {
109
144
  output?: string;
@@ -115,6 +150,7 @@ declare class EventShipper$1 {
115
150
  shutdown(): Promise<void>;
116
151
  trackSignal(signal: SignalInput): Promise<void>;
117
152
  identify(users: IdentifyInput$1 | IdentifyInput$1[]): Promise<void>;
153
+ private warnShutdownDrop;
118
154
  private flushOne;
119
155
  }
120
156
 
@@ -252,6 +288,15 @@ type TraceShipperOptions = {
252
288
  * still want some redaction in that case.
253
289
  */
254
290
  disableDefaultRedaction?: boolean;
291
+ /**
292
+ * Per-attribute character cap applied to every span attribute string value
293
+ * right before the span enters a ship path, so a multi-MB prompt/tool
294
+ * payload can never make the batch `JSON.stringify` (which runs on the
295
+ * event loop) cost seconds. Truncated values end with
296
+ * `...[truncated by raindrop]` and never exceed the cap, marker included.
297
+ * Defaults to 1,000,000 (matching the Python SDK).
298
+ */
299
+ maxTextFieldChars?: number;
255
300
  };
256
301
  declare class TraceShipper$1 {
257
302
  private baseUrl;
@@ -273,7 +318,32 @@ declare class TraceShipper$1 {
273
318
  private localDebuggerUrl;
274
319
  private transformSpanHook;
275
320
  private disableDefaultRedaction;
321
+ private maxTextFieldCharsOpt;
322
+ /**
323
+ * Epoch ms deadline while `shutdown()` is draining; undefined otherwise.
324
+ * Checked before every batch POST issued during the final flush.
325
+ */
326
+ private shutdownDeadlineAt;
327
+ /**
328
+ * Set once `shutdown()` begins and never cleared. Sends issued after the
329
+ * drain window (stragglers, or flush work the deadline abandoned
330
+ * mid-drain) run as a single short attempt instead of regaining the full
331
+ * retry schedule.
332
+ */
333
+ private hasShutdown;
276
334
  constructor(opts: TraceShipperOptions);
335
+ /**
336
+ * Cap every string attribute value on the span. O(#attributes) length
337
+ * checks; only oversized values pay a slice. Runs AFTER the redaction
338
+ * pipeline so the default secret-scrub still sees parseable JSON in
339
+ * `ai.request.providerOptions` / `ai.response.providerMetadata` (capping
340
+ * first could cut a JSON blob mid-way, fail the parse, and ship secrets
341
+ * in the surviving prefix).
342
+ *
343
+ * A stricter `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` env var is honored
344
+ * for span content, matching the Python SDK and the OTel SDK convention.
345
+ */
346
+ private capSpanAttributes;
277
347
  /**
278
348
  * Apply the user `transformSpan` hook (if any) followed by the default
279
349
  * redactor (unless disabled). Returns either the (possibly new) span to
@@ -323,6 +393,8 @@ declare class TraceShipper$1 {
323
393
  }): void;
324
394
  enqueue(span: OtlpSpan): void;
325
395
  flush(): Promise<void>;
396
+ /** See EventShipper.requestOpts — same shutdown-budget semantics. */
397
+ private requestOpts;
326
398
  shutdown(): Promise<void>;
327
399
  }
328
400
 
@@ -365,6 +437,29 @@ declare class TraceShipper extends TraceShipper$1 {
365
437
  }
366
438
 
367
439
  type Listener<T> = (event: T) => PromiseLike<void> | void;
440
+ type ToolExecutionEndEvent = {
441
+ callId: string;
442
+ toolCall: {
443
+ toolCallId: string;
444
+ toolName: string;
445
+ };
446
+ toolOutput: {
447
+ type: "tool-result";
448
+ output: unknown;
449
+ } | {
450
+ type: "tool-error";
451
+ error: unknown;
452
+ };
453
+ } | {
454
+ callId: string;
455
+ toolCall: {
456
+ toolCallId: string;
457
+ toolName: string;
458
+ };
459
+ success: boolean;
460
+ output?: unknown;
461
+ error?: unknown;
462
+ };
368
463
  interface TelemetryIntegration {
369
464
  onStart?: Listener<any>;
370
465
  onStepStart?: Listener<any>;
@@ -381,6 +476,7 @@ interface TelemetryIntegration {
381
476
  onEmbedEnd?: Listener<any>;
382
477
  onFinish?: Listener<any>;
383
478
  onEnd?: Listener<any>;
479
+ onAbort?: Listener<any>;
384
480
  onError?: Listener<any>;
385
481
  executeTool?: <T>(params: {
386
482
  callId: string;
@@ -441,6 +537,10 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
441
537
  */
442
538
  private readonly priorParentContexts;
443
539
  constructor(opts: RaindropTelemetryIntegrationOptions);
540
+ /** Flush any buffered events and trace spans to their destinations. */
541
+ flush: () => Promise<void>;
542
+ /** Flush and stop the background flush timers. */
543
+ shutdown: () => Promise<void>;
444
544
  private getState;
445
545
  private cleanup;
446
546
  private spanParentRef;
@@ -456,9 +556,9 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
456
556
  private toolExecutionStart;
457
557
  private toolExecutionEnd;
458
558
  onToolExecutionStart: (event: any) => void;
459
- onToolExecutionEnd: (event: any) => void;
559
+ onToolExecutionEnd: (event: ToolExecutionEndEvent) => void;
460
560
  onToolCallStart: (event: any) => void;
461
- onToolCallFinish: (event: any) => void;
561
+ onToolCallFinish: (event: ToolExecutionEndEvent) => void;
462
562
  onLanguageModelCallStart: (_event: any) => void;
463
563
  onLanguageModelCallEnd: (_event: any) => void;
464
564
  onChunk: (event: any) => void;
@@ -470,8 +570,15 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
470
570
  onFinish: (event: any) => void;
471
571
  onEnd: (event: any) => void;
472
572
  private finishGenerate;
573
+ /**
574
+ * Patch the Raindrop event for a completed, aborted, or errored text
575
+ * generation so it leaves the `isPending` state. Shared by `onFinish`/`onEnd`,
576
+ * `onAbort`, and `onError`.
577
+ */
578
+ private finalizeGenerateEvent;
473
579
  private finishEmbed;
474
580
  onError: (error: unknown) => void;
581
+ onAbort: (event: any) => void;
475
582
  executeTool: <T>({ callId, toolCallId, execute, }: {
476
583
  callId: string;
477
584
  toolCallId: string;
@@ -484,6 +591,33 @@ type IdentifyInput = {
484
591
  traits?: Record<string, unknown>;
485
592
  };
486
593
 
594
+ declare const TRUNCATION_MARKER = "...[truncated by raindrop]";
595
+ declare const DEFAULT_MAX_TEXT_FIELD_CHARS = 1000000;
596
+ /**
597
+ * Cap a raw text field BEFORE it is buffered or attached to a span.
598
+ *
599
+ * The length check is O(1), so multi-MB strings cost nothing on the caller
600
+ * beyond the slice that keeps the first `limit` chars. Non-string values
601
+ * (including `undefined`) pass through untouched.
602
+ */
603
+ declare function capText(value: string, limit?: number): string;
604
+ declare function capText(value: string | undefined, limit?: number): string | undefined;
605
+ /**
606
+ * JSON-serialize `value` with a hard output budget.
607
+ *
608
+ * Unlike serialize-then-truncate, the cost here is proportional to the
609
+ * limit, not the payload: the value is pruned by `boundedClone` first, so a
610
+ * multi-MB tool result can never burn seconds of CPU on the calling thread
611
+ * (which is typically the host app's event loop). Matching the previous
612
+ * `safeJson` semantics, returns `undefined` when the value cannot be
613
+ * serialized (e.g. BigInt leaves) — and, like any display truncation, a
614
+ * truncated result may not be valid JSON.
615
+ *
616
+ * Small payloads (within the budget) serialize exactly like
617
+ * `JSON.stringify`, except `Uint8Array` values become base64 strings.
618
+ */
619
+ declare function boundedStringify(value: unknown, limit?: number): string | undefined;
620
+
487
621
  type RaindropCallMetadata = {
488
622
  userId?: string;
489
623
  eventId?: string;
@@ -824,6 +958,17 @@ type RaindropAISDKOptions = {
824
958
  partialFlushMs?: number;
825
959
  debug?: boolean;
826
960
  };
961
+ /**
962
+ * Per-field character cap applied to ai input/output text and serialized
963
+ * tool/LLM span payloads BEFORE (or during) serialization, so oversized
964
+ * payloads cost the cap — not the payload — on the calling thread.
965
+ * Truncated values end with `...[truncated by raindrop]` and never exceed
966
+ * the cap. A stricter `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` env var is
967
+ * honored. Applies module-wide: the last `createRaindropAISDK` call that
968
+ * sets this option wins; omitting it leaves the current cap unchanged.
969
+ * Defaults to 1,000,000.
970
+ */
971
+ maxTextFieldChars?: number;
827
972
  };
828
973
  type RaindropAISDKContext = {
829
974
  userId?: string;
@@ -1102,5 +1247,53 @@ type RaindropAISDKClient = {
1102
1247
  shutdown(): Promise<void>;
1103
1248
  };
1104
1249
  declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
1250
+ /**
1251
+ * Options for the {@link raindrop} telemetry-integration factory. A superset of
1252
+ * {@link RaindropAISDKOptions} plus the per-integration `context` defaults and
1253
+ * `subagentWrapping` toggle accepted by `createTelemetryIntegration()`.
1254
+ */
1255
+ type RaindropTelemetryOptions = RaindropAISDKOptions & {
1256
+ /** Default Raindrop context (userId/eventName/convoId/properties) applied to every call. */
1257
+ context?: RaindropTelemetryIntegrationOptions["context"];
1258
+ /**
1259
+ * Wrap sub-agent generations (a `generateText`/`streamText` invoked from
1260
+ * inside a tool's `execute`) in a synthetic tool span so parent and child
1261
+ * spans nest correctly. Enabled by default.
1262
+ */
1263
+ subagentWrapping?: boolean;
1264
+ };
1265
+ /**
1266
+ * One-line factory for the AI SDK v7 `registerTelemetry` DX.
1267
+ *
1268
+ * Returns a {@link RaindropTelemetryIntegration} wired to Raindrop's trace +
1269
+ * event shippers, ready to hand to the AI SDK's `registerTelemetry`. The
1270
+ * `writeKey` defaults to the `RAINDROP_WRITE_KEY` environment variable.
1271
+ *
1272
+ * @example
1273
+ * ```ts
1274
+ * import { generateText, registerTelemetry } from "ai";
1275
+ * import { OpenTelemetry } from "@ai-sdk/otel";
1276
+ * import { raindrop } from "@raindrop-ai/ai-sdk";
1277
+ *
1278
+ * registerTelemetry(new OpenTelemetry(), raindrop());
1279
+ *
1280
+ * await generateText({
1281
+ * model: anthropic("claude-sonnet-4-5"),
1282
+ * prompt: "what is the weather in Tokyo?",
1283
+ * telemetry: { functionId: "weather-agent" },
1284
+ * });
1285
+ * ```
1286
+ *
1287
+ * The returned integration also exposes `flush()` / `shutdown()` for
1288
+ * short-lived scripts that need to drain buffered telemetry before exiting:
1289
+ *
1290
+ * ```ts
1291
+ * const rd = raindrop();
1292
+ * registerTelemetry(rd);
1293
+ * // ...
1294
+ * await rd.flush();
1295
+ * ```
1296
+ */
1297
+ declare function raindrop(options?: RaindropTelemetryOptions): RaindropTelemetryIntegration;
1105
1298
 
1106
- export { redactJsonAttributeValue as $, type AISDKChatRequestLike as A, type BuildEventPatch as B, ContextManager as C, DEFAULT_REDACT_ATTRIBUTE_KEYS as D, type EndSpanArgs as E, type WrappedAISDK as F, _resetRaindropCallMetadataStorage as G, _resetWarnedMissingUserId as H, type IdentifyInput as I, clearParentToolContext as J, createRaindropAISDK as K, currentSpan as L, defaultTransformSpan as M, enterParentToolContext as N, type OtlpAnyValue as O, type ParentToolContext as P, eventMetadata as Q, REDACTED_PLACEHOLDER as R, type SelfDiagnosticsOptions as S, type TraceSpan as T, eventMetadataFromChatRequest as U, getContextManager as V, type WrapAISDKOptions as W, getCurrentParentToolContext as X, getCurrentRaindropCallMetadata as Y, readRaindropCallMetadataFromArgs as Z, _resetParentToolContextStorage as _, type AISDKChatRequestMessageLike as a, redactSecretsInObject as a0, runWithParentToolContext as a1, runWithRaindropCallMetadata as a2, withCurrent as a3, type AISDKMessage as b, type AgentCallMetadata as c, type AgentWithMetadata as d, type Attachment as e, type ContextSpan as f, type CreateSpanArgs as g, DEFAULT_SECRET_KEY_NAMES as h, type EventBuilder as i, type EventMetadataOptions as j, type OtlpSpan as k, type RaindropAISDKClient as l, type RaindropAISDKContext as m, type RaindropAISDKOptions as n, type RaindropCallMetadata as o, RaindropTelemetryIntegration as p, type RaindropTelemetryIntegrationOptions as q, type SelfDiagnosticsSignalDefinition as r, type SelfDiagnosticsSignalDefinitions as s, type SelfDiagnosticsTool as t, type SelfDiagnosticsToolInput as u, type SelfDiagnosticsToolOptions as v, type SelfDiagnosticsToolResult as w, type StartSpanArgs as x, type TransformSpanHook as y, type WrappedAI as z };
1299
+ export { eventMetadataFromChatRequest as $, type AISDKChatRequestLike as A, type BuildEventPatch as B, ContextManager as C, DEFAULT_MAX_TEXT_FIELD_CHARS as D, type EndSpanArgs as E, type TraceSpan as F, type TransformSpanHook as G, type WrappedAI as H, type IdentifyInput as I, type WrappedAISDK as J, _resetRaindropCallMetadataStorage as K, _resetWarnedMissingUserId as L, boundedStringify as M, capText as N, type OtlpAnyValue as O, type ParentToolContext as P, clearParentToolContext as Q, REDACTED_PLACEHOLDER as R, type SelfDiagnosticsOptions as S, TRUNCATION_MARKER as T, createRaindropAISDK as U, currentSpan as V, type WrapAISDKOptions as W, defaultTransformSpan as X, enterParentToolContext as Y, eventMetadata as Z, _resetParentToolContextStorage as _, type AISDKChatRequestMessageLike as a, getContextManager as a0, getCurrentParentToolContext as a1, getCurrentRaindropCallMetadata as a2, raindrop as a3, readRaindropCallMetadataFromArgs as a4, redactJsonAttributeValue as a5, redactSecretsInObject as a6, runWithParentToolContext as a7, runWithRaindropCallMetadata as a8, withCurrent as a9, type AISDKMessage as b, type AgentCallMetadata as c, type AgentWithMetadata as d, type Attachment as e, type ContextSpan as f, type CreateSpanArgs as g, DEFAULT_REDACT_ATTRIBUTE_KEYS as h, DEFAULT_SECRET_KEY_NAMES as i, type EventBuilder as j, type EventMetadataOptions as k, type OtlpSpan as l, type RaindropAISDKClient as m, type RaindropAISDKContext as n, type RaindropAISDKOptions as o, type RaindropCallMetadata as p, RaindropTelemetryIntegration as q, type RaindropTelemetryIntegrationOptions as r, type RaindropTelemetryOptions as s, type SelfDiagnosticsSignalDefinition as t, type SelfDiagnosticsSignalDefinitions as u, type SelfDiagnosticsTool as v, type SelfDiagnosticsToolInput as w, type SelfDiagnosticsToolOptions as x, type SelfDiagnosticsToolResult as y, type StartSpanArgs as z };