@raindrop-ai/ai-sdk 0.0.32 → 0.0.33

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 CHANGED
@@ -115,9 +115,50 @@ raindrop.traces.endSpan(agentTurn);
115
115
  await raindrop.flush();
116
116
  ```
117
117
 
118
- ### AI SDK v7+ native telemetry (opt-in)
118
+ ### AI SDK v7 quick start: `registerTelemetry(raindrop())`
119
119
 
120
- On AI SDK v7+, you can use the native `Telemetry` callback interface (formerly `TelemetryIntegration` before beta.111) instead of Proxy wrapping. This avoids Proxy overhead and works with all AI SDK entry points (including `ToolLoopAgent`).
120
+ On AI SDK v7, the simplest setup is the `raindrop()` factory, which returns a
121
+ ready-to-register telemetry integration. The `writeKey` defaults to the
122
+ `RAINDROP_WRITE_KEY` environment variable.
123
+
124
+ ```ts
125
+ import { generateText, registerTelemetry } from "ai";
126
+ import { OpenTelemetry } from "@ai-sdk/otel";
127
+ import { raindrop } from "@raindrop-ai/ai-sdk";
128
+
129
+ registerTelemetry(new OpenTelemetry(), raindrop());
130
+
131
+ const result = await generateText({
132
+ model: anthropic("claude-sonnet-4-5"),
133
+ prompt: "what is the weather in Tokyo?",
134
+ telemetry: { functionId: "weather-agent" }, // no `isEnabled` needed in v7
135
+ });
136
+ ```
137
+
138
+ `raindrop()` is self-contained — `@ai-sdk/otel` is optional; you can register
139
+ Raindrop on its own with `registerTelemetry(raindrop())`. Pass `context` and
140
+ `subagentWrapping` to customise behaviour, e.g. `raindrop({ context: { userId: "user_123" } })`.
141
+
142
+ For short-lived scripts that exit before the background flush timer fires, keep
143
+ the reference and drain it before exiting:
144
+
145
+ ```ts
146
+ const rd = raindrop();
147
+ registerTelemetry(rd);
148
+ // ... run your generations ...
149
+ await rd.flush(); // or rd.shutdown()
150
+ ```
151
+
152
+ Sub-agents (a `generateText`/`streamText` invoked from inside a tool's
153
+ `execute`) nest automatically: the inner generation's spans are parented under
154
+ the tool span so parent and child spans stay correctly nested.
155
+
156
+ ### AI SDK v7+ native telemetry (advanced)
157
+
158
+ For finer control you can build the integration from a `createRaindropAISDK`
159
+ client instead. The native `Telemetry` callback interface (formerly
160
+ `TelemetryIntegration` before beta.111) avoids Proxy overhead and works with all
161
+ AI SDK entry points (including `ToolLoopAgent`).
121
162
 
122
163
  ```ts
123
164
  // Option A: wrap() with nativeTelemetry flag
@@ -251,7 +292,7 @@ This package is tested against multiple Vercel AI SDK versions:
251
292
  | v4.x | ✅ Supported | Proxy |
252
293
  | v5.x | ✅ Supported | Proxy |
253
294
  | v6.x | ✅ Supported | Proxy |
254
- | v7.x (beta) | ✅ Supported | Proxy (default) or native `Telemetry` (opt-in, formerly `TelemetryIntegration` pre-beta.111). Verified against beta.116. |
295
+ | v7.x (beta/canary) | ✅ Supported | Proxy (default) or native `Telemetry` (opt-in, formerly `TelemetryIntegration` pre-beta.111). Verified against beta.116 and canary.171. |
255
296
 
256
297
  ### Version Differences Handled
257
298
 
@@ -1781,6 +1781,25 @@ var RaindropTelemetryIntegration = class {
1781
1781
  * (the `event.callId` can be the same for parallel sibling tools).
1782
1782
  */
1783
1783
  this.priorParentContexts = /* @__PURE__ */ new Map();
1784
+ // ── lifecycle ─────────────────────────────────────────────────────────────
1785
+ //
1786
+ // The shippers buffer spans/events and flush on a timer, so a short-lived
1787
+ // script (e.g. a single `generateText` then `process.exit`) can exit before
1788
+ // anything ships. Expose `flush`/`shutdown` on the integration itself so the
1789
+ // value returned by `raindrop()` is self-sufficient — callers can keep the
1790
+ // reference they pass to `registerTelemetry` and `await rd.flush()` before
1791
+ // exiting, without also constructing a separate client.
1792
+ /** Flush any buffered events and trace spans to their destinations. */
1793
+ this.flush = async () => {
1794
+ await Promise.all([this.eventShipper.flush(), this.traceShipper.flush()]);
1795
+ };
1796
+ /** Flush and stop the background flush timers. */
1797
+ this.shutdown = async () => {
1798
+ await Promise.all([
1799
+ this.eventShipper.shutdown(),
1800
+ this.traceShipper.shutdown()
1801
+ ]);
1802
+ };
1784
1803
  // ── onStart ─────────────────────────────────────────────────────────────
1785
1804
  this.onStart = (event) => {
1786
1805
  var _a, _b, _c, _d, _e;
@@ -2174,8 +2193,56 @@ var RaindropTelemetryIntegration = class {
2174
2193
  if (state.subagentToolCallSpan) {
2175
2194
  this.traceShipper.endSpan(state.subagentToolCallSpan, { error: actualError });
2176
2195
  }
2196
+ const isEmbed = state.operationId === "ai.embed" || state.operationId === "ai.embedMany";
2197
+ if (!isEmbed) {
2198
+ this.finalizeGenerateEvent(state, state.accumulatedText || void 0, void 0);
2199
+ }
2177
2200
  this.cleanup(event.callId);
2178
2201
  };
2202
+ // ── onAbort ─────────────────────────────────────────────────────────────
2203
+ //
2204
+ // Dispatched by the v7 canary line (post-beta.116) when a `streamText` call
2205
+ // is cancelled via its `AbortSignal`. On abort the SDK fires neither `onEnd`
2206
+ // nor `onError`, so without this every open span would leak and the event
2207
+ // would hang forever in its `isPending` state. We close every open span with
2208
+ // an `ai.response.aborted` marker (no error status — an abort is not a model
2209
+ // failure) and flush the partial event.
2210
+ this.onAbort = (event) => {
2211
+ const callId = event == null ? void 0 : event.callId;
2212
+ if (!callId) return;
2213
+ const state = this.getState(callId);
2214
+ if (!state) return;
2215
+ const abortedAttr = attrString("ai.response.aborted", "true");
2216
+ if (state.stepSpan) {
2217
+ this.traceShipper.endSpan(state.stepSpan, { attributes: [abortedAttr] });
2218
+ state.stepSpan = void 0;
2219
+ state.stepParent = void 0;
2220
+ }
2221
+ for (const embedSpan of state.embedSpans.values()) {
2222
+ this.traceShipper.endSpan(embedSpan, { attributes: [abortedAttr] });
2223
+ }
2224
+ state.embedSpans.clear();
2225
+ for (const toolCallId of state.parentContextToolCallIds) {
2226
+ this.priorParentContexts.delete(toolCallId);
2227
+ }
2228
+ state.parentContextToolCallIds.clear();
2229
+ for (const toolSpan of state.toolSpans.values()) {
2230
+ this.traceShipper.endSpan(toolSpan, { attributes: [abortedAttr] });
2231
+ }
2232
+ state.toolSpans.clear();
2233
+ if (state.rootSpan) {
2234
+ this.traceShipper.endSpan(state.rootSpan, {
2235
+ attributes: [abortedAttr, attrInt("ai.toolCall.count", state.toolCallCount)]
2236
+ });
2237
+ }
2238
+ if (state.subagentToolCallSpan) {
2239
+ this.traceShipper.endSpan(state.subagentToolCallSpan, {
2240
+ attributes: [abortedAttr]
2241
+ });
2242
+ }
2243
+ this.finalizeGenerateEvent(state, state.accumulatedText || void 0, void 0);
2244
+ this.cleanup(callId);
2245
+ };
2179
2246
  // ── executeTool ─────────────────────────────────────────────────────────
2180
2247
  this.executeTool = async ({
2181
2248
  callId,
@@ -2333,11 +2400,12 @@ var RaindropTelemetryIntegration = class {
2333
2400
  const toolSpan = state.toolSpans.get(event.toolCall.toolCallId);
2334
2401
  if (!toolSpan) return;
2335
2402
  state.toolCallCount += 1;
2336
- if (event.success) {
2337
- const outputAttrs = state.recordOutputs ? [attrString("ai.toolCall.result", safeJsonWithUint8(event.output))] : [];
2403
+ const outcome = "toolOutput" in event ? event.toolOutput.type === "tool-result" ? { success: true, output: event.toolOutput.output } : { success: false, error: event.toolOutput.error } : event.success ? { success: true, output: event.output } : { success: false, error: event.error };
2404
+ if (outcome.success) {
2405
+ const outputAttrs = state.recordOutputs ? [attrString("ai.toolCall.result", safeJsonWithUint8(outcome.output))] : [];
2338
2406
  this.traceShipper.endSpan(toolSpan, { attributes: outputAttrs });
2339
2407
  } else {
2340
- this.traceShipper.endSpan(toolSpan, { error: event.error });
2408
+ this.traceShipper.endSpan(toolSpan, { error: outcome.error });
2341
2409
  }
2342
2410
  this.emitLive(state, "tool_result", event.toolCall.toolName);
2343
2411
  state.toolSpans.delete(event.toolCall.toolCallId);
@@ -2411,7 +2479,7 @@ var RaindropTelemetryIntegration = class {
2411
2479
  }
2412
2480
  }
2413
2481
  finishGenerate(event, state) {
2414
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
2482
+ var _a, _b, _c, _d, _e, _f;
2415
2483
  if (state.rootSpan) {
2416
2484
  const outputAttrs = [];
2417
2485
  if (state.recordOutputs) {
@@ -2459,38 +2527,47 @@ var RaindropTelemetryIntegration = class {
2459
2527
  );
2460
2528
  this.traceShipper.endSpan(state.rootSpan, { attributes: outputAttrs });
2461
2529
  }
2530
+ this.finalizeGenerateEvent(
2531
+ state,
2532
+ (_e = event.text) != null ? _e : state.accumulatedText || void 0,
2533
+ (_f = event.response) == null ? void 0 : _f.modelId
2534
+ );
2535
+ }
2536
+ /**
2537
+ * Patch the Raindrop event for a completed, aborted, or errored text
2538
+ * generation so it leaves the `isPending` state. Shared by `onFinish`/`onEnd`,
2539
+ * `onAbort`, and `onError`.
2540
+ */
2541
+ finalizeGenerateEvent(state, output, model) {
2542
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2462
2543
  const suppressSubagentEvent = state.subagentName !== void 0 && state.subagentToolCallSpan !== void 0;
2463
- if (this.sendEvents && !suppressSubagentEvent) {
2464
- const callMeta = this.extractRaindropMetadata(state.metadata);
2465
- const userId = (_f = callMeta.userId) != null ? _f : (_e = this.defaultContext) == null ? void 0 : _e.userId;
2466
- if (userId) {
2467
- const eventName = (_i = (_h = callMeta.eventName) != null ? _h : (_g = this.defaultContext) == null ? void 0 : _g.eventName) != null ? _i : state.operationId;
2468
- const output = (_j = event.text) != null ? _j : state.accumulatedText || void 0;
2469
- const input = state.inputText;
2470
- const model = (_k = event.response) == null ? void 0 : _k.modelId;
2471
- const properties = {
2472
- ...(_l = this.defaultContext) == null ? void 0 : _l.properties,
2473
- ...callMeta.properties
2474
- };
2475
- const convoId = (_n = callMeta.convoId) != null ? _n : (_m = this.defaultContext) == null ? void 0 : _m.convoId;
2476
- void this.eventShipper.patch(state.eventId, {
2477
- eventName,
2478
- userId,
2479
- convoId,
2480
- input,
2481
- output,
2482
- model,
2483
- properties: Object.keys(properties).length > 0 ? properties : void 0,
2484
- isPending: false
2485
- }).catch((err) => {
2486
- if (this.debug) {
2487
- console.warn(
2488
- `[raindrop-ai/ai-sdk] event patch failed: ${err instanceof Error ? err.message : err}`
2489
- );
2490
- }
2491
- });
2544
+ if (!this.sendEvents || suppressSubagentEvent) return;
2545
+ const callMeta = this.extractRaindropMetadata(state.metadata);
2546
+ const userId = (_b = callMeta.userId) != null ? _b : (_a = this.defaultContext) == null ? void 0 : _a.userId;
2547
+ if (!userId) return;
2548
+ const eventName = (_e = (_d = callMeta.eventName) != null ? _d : (_c = this.defaultContext) == null ? void 0 : _c.eventName) != null ? _e : state.operationId;
2549
+ const input = state.inputText;
2550
+ const properties = {
2551
+ ...(_f = this.defaultContext) == null ? void 0 : _f.properties,
2552
+ ...callMeta.properties
2553
+ };
2554
+ const convoId = (_h = callMeta.convoId) != null ? _h : (_g = this.defaultContext) == null ? void 0 : _g.convoId;
2555
+ void this.eventShipper.patch(state.eventId, {
2556
+ eventName,
2557
+ userId,
2558
+ convoId,
2559
+ input,
2560
+ output,
2561
+ model,
2562
+ properties: Object.keys(properties).length > 0 ? properties : void 0,
2563
+ isPending: false
2564
+ }).catch((err) => {
2565
+ if (this.debug) {
2566
+ console.warn(
2567
+ `[raindrop-ai/ai-sdk] event patch failed: ${err instanceof Error ? err.message : err}`
2568
+ );
2492
2569
  }
2493
- }
2570
+ });
2494
2571
  }
2495
2572
  finishEmbed(event, state) {
2496
2573
  var _a;
@@ -4575,7 +4652,7 @@ function extractNestedTokens(usage, key) {
4575
4652
  // package.json
4576
4653
  var package_default = {
4577
4654
  name: "@raindrop-ai/ai-sdk",
4578
- version: "0.0.32"};
4655
+ version: "0.0.33"};
4579
4656
 
4580
4657
  // src/internal/version.ts
4581
4658
  var libraryName = package_default.name;
@@ -4845,5 +4922,12 @@ function createRaindropAISDK(opts) {
4845
4922
  }
4846
4923
  };
4847
4924
  }
4925
+ function raindrop(options = {}) {
4926
+ var _a;
4927
+ const { context, subagentWrapping, writeKey, ...rest } = options;
4928
+ const resolvedWriteKey = writeKey != null ? writeKey : typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a.RAINDROP_WRITE_KEY : void 0;
4929
+ const client = createRaindropAISDK({ ...rest, writeKey: resolvedWriteKey });
4930
+ return client.createTelemetryIntegration({ context, subagentWrapping });
4931
+ }
4848
4932
 
4849
- export { DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithParentToolContext, runWithRaindropCallMetadata, withCurrent };
4933
+ export { DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, raindrop, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithParentToolContext, runWithRaindropCallMetadata, withCurrent };
@@ -365,6 +365,29 @@ declare class TraceShipper extends TraceShipper$1 {
365
365
  }
366
366
 
367
367
  type Listener<T> = (event: T) => PromiseLike<void> | void;
368
+ type ToolExecutionEndEvent = {
369
+ callId: string;
370
+ toolCall: {
371
+ toolCallId: string;
372
+ toolName: string;
373
+ };
374
+ toolOutput: {
375
+ type: "tool-result";
376
+ output: unknown;
377
+ } | {
378
+ type: "tool-error";
379
+ error: unknown;
380
+ };
381
+ } | {
382
+ callId: string;
383
+ toolCall: {
384
+ toolCallId: string;
385
+ toolName: string;
386
+ };
387
+ success: boolean;
388
+ output?: unknown;
389
+ error?: unknown;
390
+ };
368
391
  interface TelemetryIntegration {
369
392
  onStart?: Listener<any>;
370
393
  onStepStart?: Listener<any>;
@@ -381,6 +404,7 @@ interface TelemetryIntegration {
381
404
  onEmbedEnd?: Listener<any>;
382
405
  onFinish?: Listener<any>;
383
406
  onEnd?: Listener<any>;
407
+ onAbort?: Listener<any>;
384
408
  onError?: Listener<any>;
385
409
  executeTool?: <T>(params: {
386
410
  callId: string;
@@ -441,6 +465,10 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
441
465
  */
442
466
  private readonly priorParentContexts;
443
467
  constructor(opts: RaindropTelemetryIntegrationOptions);
468
+ /** Flush any buffered events and trace spans to their destinations. */
469
+ flush: () => Promise<void>;
470
+ /** Flush and stop the background flush timers. */
471
+ shutdown: () => Promise<void>;
444
472
  private getState;
445
473
  private cleanup;
446
474
  private spanParentRef;
@@ -456,9 +484,9 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
456
484
  private toolExecutionStart;
457
485
  private toolExecutionEnd;
458
486
  onToolExecutionStart: (event: any) => void;
459
- onToolExecutionEnd: (event: any) => void;
487
+ onToolExecutionEnd: (event: ToolExecutionEndEvent) => void;
460
488
  onToolCallStart: (event: any) => void;
461
- onToolCallFinish: (event: any) => void;
489
+ onToolCallFinish: (event: ToolExecutionEndEvent) => void;
462
490
  onLanguageModelCallStart: (_event: any) => void;
463
491
  onLanguageModelCallEnd: (_event: any) => void;
464
492
  onChunk: (event: any) => void;
@@ -470,8 +498,15 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
470
498
  onFinish: (event: any) => void;
471
499
  onEnd: (event: any) => void;
472
500
  private finishGenerate;
501
+ /**
502
+ * Patch the Raindrop event for a completed, aborted, or errored text
503
+ * generation so it leaves the `isPending` state. Shared by `onFinish`/`onEnd`,
504
+ * `onAbort`, and `onError`.
505
+ */
506
+ private finalizeGenerateEvent;
473
507
  private finishEmbed;
474
508
  onError: (error: unknown) => void;
509
+ onAbort: (event: any) => void;
475
510
  executeTool: <T>({ callId, toolCallId, execute, }: {
476
511
  callId: string;
477
512
  toolCallId: string;
@@ -1102,5 +1137,53 @@ type RaindropAISDKClient = {
1102
1137
  shutdown(): Promise<void>;
1103
1138
  };
1104
1139
  declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
1140
+ /**
1141
+ * Options for the {@link raindrop} telemetry-integration factory. A superset of
1142
+ * {@link RaindropAISDKOptions} plus the per-integration `context` defaults and
1143
+ * `subagentWrapping` toggle accepted by `createTelemetryIntegration()`.
1144
+ */
1145
+ type RaindropTelemetryOptions = RaindropAISDKOptions & {
1146
+ /** Default Raindrop context (userId/eventName/convoId/properties) applied to every call. */
1147
+ context?: RaindropTelemetryIntegrationOptions["context"];
1148
+ /**
1149
+ * Wrap sub-agent generations (a `generateText`/`streamText` invoked from
1150
+ * inside a tool's `execute`) in a synthetic tool span so parent and child
1151
+ * spans nest correctly. Enabled by default.
1152
+ */
1153
+ subagentWrapping?: boolean;
1154
+ };
1155
+ /**
1156
+ * One-line factory for the AI SDK v7 `registerTelemetry` DX.
1157
+ *
1158
+ * Returns a {@link RaindropTelemetryIntegration} wired to Raindrop's trace +
1159
+ * event shippers, ready to hand to the AI SDK's `registerTelemetry`. The
1160
+ * `writeKey` defaults to the `RAINDROP_WRITE_KEY` environment variable.
1161
+ *
1162
+ * @example
1163
+ * ```ts
1164
+ * import { generateText, registerTelemetry } from "ai";
1165
+ * import { OpenTelemetry } from "@ai-sdk/otel";
1166
+ * import { raindrop } from "@raindrop-ai/ai-sdk";
1167
+ *
1168
+ * registerTelemetry(new OpenTelemetry(), raindrop());
1169
+ *
1170
+ * await generateText({
1171
+ * model: anthropic("claude-sonnet-4-5"),
1172
+ * prompt: "what is the weather in Tokyo?",
1173
+ * telemetry: { functionId: "weather-agent" },
1174
+ * });
1175
+ * ```
1176
+ *
1177
+ * The returned integration also exposes `flush()` / `shutdown()` for
1178
+ * short-lived scripts that need to drain buffered telemetry before exiting:
1179
+ *
1180
+ * ```ts
1181
+ * const rd = raindrop();
1182
+ * registerTelemetry(rd);
1183
+ * // ...
1184
+ * await rd.flush();
1185
+ * ```
1186
+ */
1187
+ declare function raindrop(options?: RaindropTelemetryOptions): RaindropTelemetryIntegration;
1105
1188
 
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 };
1189
+ export { raindrop as $, type AISDKChatRequestLike as A, type BuildEventPatch as B, ContextManager as C, DEFAULT_REDACT_ATTRIBUTE_KEYS as D, type EndSpanArgs as E, type WrappedAI as F, type WrappedAISDK as G, _resetRaindropCallMetadataStorage as H, type IdentifyInput as I, _resetWarnedMissingUserId as J, clearParentToolContext as K, createRaindropAISDK as L, currentSpan as M, defaultTransformSpan as N, type OtlpAnyValue as O, type ParentToolContext as P, enterParentToolContext as Q, REDACTED_PLACEHOLDER as R, type SelfDiagnosticsOptions as S, type TraceSpan as T, eventMetadata as U, eventMetadataFromChatRequest as V, type WrapAISDKOptions as W, getContextManager as X, getCurrentParentToolContext as Y, getCurrentRaindropCallMetadata as Z, _resetParentToolContextStorage as _, type AISDKChatRequestMessageLike as a, readRaindropCallMetadataFromArgs as a0, redactJsonAttributeValue as a1, redactSecretsInObject as a2, runWithParentToolContext as a3, runWithRaindropCallMetadata as a4, withCurrent as a5, 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 RaindropTelemetryOptions as r, type SelfDiagnosticsSignalDefinition as s, type SelfDiagnosticsSignalDefinitions as t, type SelfDiagnosticsTool as u, type SelfDiagnosticsToolInput as v, type SelfDiagnosticsToolOptions as w, type SelfDiagnosticsToolResult as x, type StartSpanArgs as y, type TransformSpanHook as z };
@@ -365,6 +365,29 @@ declare class TraceShipper extends TraceShipper$1 {
365
365
  }
366
366
 
367
367
  type Listener<T> = (event: T) => PromiseLike<void> | void;
368
+ type ToolExecutionEndEvent = {
369
+ callId: string;
370
+ toolCall: {
371
+ toolCallId: string;
372
+ toolName: string;
373
+ };
374
+ toolOutput: {
375
+ type: "tool-result";
376
+ output: unknown;
377
+ } | {
378
+ type: "tool-error";
379
+ error: unknown;
380
+ };
381
+ } | {
382
+ callId: string;
383
+ toolCall: {
384
+ toolCallId: string;
385
+ toolName: string;
386
+ };
387
+ success: boolean;
388
+ output?: unknown;
389
+ error?: unknown;
390
+ };
368
391
  interface TelemetryIntegration {
369
392
  onStart?: Listener<any>;
370
393
  onStepStart?: Listener<any>;
@@ -381,6 +404,7 @@ interface TelemetryIntegration {
381
404
  onEmbedEnd?: Listener<any>;
382
405
  onFinish?: Listener<any>;
383
406
  onEnd?: Listener<any>;
407
+ onAbort?: Listener<any>;
384
408
  onError?: Listener<any>;
385
409
  executeTool?: <T>(params: {
386
410
  callId: string;
@@ -441,6 +465,10 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
441
465
  */
442
466
  private readonly priorParentContexts;
443
467
  constructor(opts: RaindropTelemetryIntegrationOptions);
468
+ /** Flush any buffered events and trace spans to their destinations. */
469
+ flush: () => Promise<void>;
470
+ /** Flush and stop the background flush timers. */
471
+ shutdown: () => Promise<void>;
444
472
  private getState;
445
473
  private cleanup;
446
474
  private spanParentRef;
@@ -456,9 +484,9 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
456
484
  private toolExecutionStart;
457
485
  private toolExecutionEnd;
458
486
  onToolExecutionStart: (event: any) => void;
459
- onToolExecutionEnd: (event: any) => void;
487
+ onToolExecutionEnd: (event: ToolExecutionEndEvent) => void;
460
488
  onToolCallStart: (event: any) => void;
461
- onToolCallFinish: (event: any) => void;
489
+ onToolCallFinish: (event: ToolExecutionEndEvent) => void;
462
490
  onLanguageModelCallStart: (_event: any) => void;
463
491
  onLanguageModelCallEnd: (_event: any) => void;
464
492
  onChunk: (event: any) => void;
@@ -470,8 +498,15 @@ declare class RaindropTelemetryIntegration implements TelemetryIntegration {
470
498
  onFinish: (event: any) => void;
471
499
  onEnd: (event: any) => void;
472
500
  private finishGenerate;
501
+ /**
502
+ * Patch the Raindrop event for a completed, aborted, or errored text
503
+ * generation so it leaves the `isPending` state. Shared by `onFinish`/`onEnd`,
504
+ * `onAbort`, and `onError`.
505
+ */
506
+ private finalizeGenerateEvent;
473
507
  private finishEmbed;
474
508
  onError: (error: unknown) => void;
509
+ onAbort: (event: any) => void;
475
510
  executeTool: <T>({ callId, toolCallId, execute, }: {
476
511
  callId: string;
477
512
  toolCallId: string;
@@ -1102,5 +1137,53 @@ type RaindropAISDKClient = {
1102
1137
  shutdown(): Promise<void>;
1103
1138
  };
1104
1139
  declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
1140
+ /**
1141
+ * Options for the {@link raindrop} telemetry-integration factory. A superset of
1142
+ * {@link RaindropAISDKOptions} plus the per-integration `context` defaults and
1143
+ * `subagentWrapping` toggle accepted by `createTelemetryIntegration()`.
1144
+ */
1145
+ type RaindropTelemetryOptions = RaindropAISDKOptions & {
1146
+ /** Default Raindrop context (userId/eventName/convoId/properties) applied to every call. */
1147
+ context?: RaindropTelemetryIntegrationOptions["context"];
1148
+ /**
1149
+ * Wrap sub-agent generations (a `generateText`/`streamText` invoked from
1150
+ * inside a tool's `execute`) in a synthetic tool span so parent and child
1151
+ * spans nest correctly. Enabled by default.
1152
+ */
1153
+ subagentWrapping?: boolean;
1154
+ };
1155
+ /**
1156
+ * One-line factory for the AI SDK v7 `registerTelemetry` DX.
1157
+ *
1158
+ * Returns a {@link RaindropTelemetryIntegration} wired to Raindrop's trace +
1159
+ * event shippers, ready to hand to the AI SDK's `registerTelemetry`. The
1160
+ * `writeKey` defaults to the `RAINDROP_WRITE_KEY` environment variable.
1161
+ *
1162
+ * @example
1163
+ * ```ts
1164
+ * import { generateText, registerTelemetry } from "ai";
1165
+ * import { OpenTelemetry } from "@ai-sdk/otel";
1166
+ * import { raindrop } from "@raindrop-ai/ai-sdk";
1167
+ *
1168
+ * registerTelemetry(new OpenTelemetry(), raindrop());
1169
+ *
1170
+ * await generateText({
1171
+ * model: anthropic("claude-sonnet-4-5"),
1172
+ * prompt: "what is the weather in Tokyo?",
1173
+ * telemetry: { functionId: "weather-agent" },
1174
+ * });
1175
+ * ```
1176
+ *
1177
+ * The returned integration also exposes `flush()` / `shutdown()` for
1178
+ * short-lived scripts that need to drain buffered telemetry before exiting:
1179
+ *
1180
+ * ```ts
1181
+ * const rd = raindrop();
1182
+ * registerTelemetry(rd);
1183
+ * // ...
1184
+ * await rd.flush();
1185
+ * ```
1186
+ */
1187
+ declare function raindrop(options?: RaindropTelemetryOptions): RaindropTelemetryIntegration;
1105
1188
 
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 };
1189
+ export { raindrop as $, type AISDKChatRequestLike as A, type BuildEventPatch as B, ContextManager as C, DEFAULT_REDACT_ATTRIBUTE_KEYS as D, type EndSpanArgs as E, type WrappedAI as F, type WrappedAISDK as G, _resetRaindropCallMetadataStorage as H, type IdentifyInput as I, _resetWarnedMissingUserId as J, clearParentToolContext as K, createRaindropAISDK as L, currentSpan as M, defaultTransformSpan as N, type OtlpAnyValue as O, type ParentToolContext as P, enterParentToolContext as Q, REDACTED_PLACEHOLDER as R, type SelfDiagnosticsOptions as S, type TraceSpan as T, eventMetadata as U, eventMetadataFromChatRequest as V, type WrapAISDKOptions as W, getContextManager as X, getCurrentParentToolContext as Y, getCurrentRaindropCallMetadata as Z, _resetParentToolContextStorage as _, type AISDKChatRequestMessageLike as a, readRaindropCallMetadataFromArgs as a0, redactJsonAttributeValue as a1, redactSecretsInObject as a2, runWithParentToolContext as a3, runWithRaindropCallMetadata as a4, withCurrent as a5, 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 RaindropTelemetryOptions as r, type SelfDiagnosticsSignalDefinition as s, type SelfDiagnosticsSignalDefinitions as t, type SelfDiagnosticsTool as u, type SelfDiagnosticsToolInput as v, type SelfDiagnosticsToolOptions as w, type SelfDiagnosticsToolResult as x, type StartSpanArgs as y, type TransformSpanHook as z };