@raindrop-ai/ai-sdk 0.1.0 → 0.2.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.
@@ -56,6 +56,10 @@ type IdentifyInput$1 = {
56
56
  userId: string;
57
57
  traits?: Record<string, unknown>;
58
58
  };
59
+ type EventUsage = {
60
+ promptTokens?: number;
61
+ completionTokens?: number;
62
+ };
59
63
  type Patch = {
60
64
  eventName?: string;
61
65
  userId?: string;
@@ -63,6 +67,8 @@ type Patch = {
63
67
  input?: string;
64
68
  output?: string;
65
69
  model?: string;
70
+ usage?: EventUsage;
71
+ error?: unknown;
66
72
  properties?: Record<string, unknown>;
67
73
  featureFlags?: Record<string, string>;
68
74
  attachments?: Attachment$1[];
@@ -161,13 +167,7 @@ declare class EventShipper$1 {
161
167
  */
162
168
  private requestOpts;
163
169
  patch(eventId: string, patch: Patch): Promise<void>;
164
- finish(eventId: string, patch: {
165
- output?: string;
166
- model?: string;
167
- properties?: Record<string, unknown>;
168
- featureFlags?: Record<string, string>;
169
- userId?: string;
170
- }): Promise<void>;
170
+ finish(eventId: string, patch: Pick<Patch, "output" | "model" | "usage" | "error" | "properties" | "featureFlags" | "userId">): Promise<void>;
171
171
  flush(): Promise<void>;
172
172
  shutdown(): Promise<void>;
173
173
  trackSignal(signal: SignalInput): Promise<void>;
@@ -399,6 +399,9 @@ declare class TraceShipper$1 {
399
399
  spanIdB64: string;
400
400
  };
401
401
  eventId: string;
402
+ userId?: string;
403
+ convoId?: string;
404
+ eventName?: string;
402
405
  operationId?: string;
403
406
  attributes?: Array<OtlpKeyValue | undefined>;
404
407
  startTimeUnixNano?: string;
@@ -417,6 +420,9 @@ declare class TraceShipper$1 {
417
420
  spanIdB64: string;
418
421
  };
419
422
  eventId: string;
423
+ userId?: string;
424
+ convoId?: string;
425
+ eventName?: string;
420
426
  startTimeUnixNano: string;
421
427
  endTimeUnixNano: string;
422
428
  attributes?: Array<OtlpKeyValue | undefined>;
@@ -503,6 +509,37 @@ declare class TraceShipper extends TraceShipper$1 {
503
509
  constructor(opts: ConstructorParameters<typeof TraceShipper$1>[0]);
504
510
  }
505
511
 
512
+ /**
513
+ * Raindrop telemetry integration for AI SDK v7+
514
+ *
515
+ * Implements the AI SDK's `Telemetry` interface (formerly `TelemetryIntegration`
516
+ * before v7 beta.111) to capture traces and events natively, replacing the
517
+ * Proxy-based wrapping used for v4-v6.
518
+ *
519
+ * Modeled after the upstream OpenTelemetry integration but uses Raindrop's
520
+ * TraceShipper (OTLP/HTTP) + EventShipper instead of the OTel Tracer API.
521
+ *
522
+ * Compatibility: this class targets the latest published v7 build but also
523
+ * exposes the older v7 callback names as aliases so it works on every v7
524
+ * beta/canary released to date:
525
+ * - `onToolCallStart`/`onToolCallFinish` (< beta.111) alongside
526
+ * `onToolExecutionStart`/`onToolExecutionEnd` (>= beta.111).
527
+ * - Current `onToolExecutionEnd` events use the `toolOutput` discriminated
528
+ * union; older builds used top-level `success`/`output`/`error` fields.
529
+ * - `onFinish`/`onEmbedFinish` (< canary.159) alongside `onEnd`/`onEmbedEnd`
530
+ * (>= canary.159, vercel/ai renamed the operation finalizers).
531
+ * - `onAbort` (added as a telemetry-integration callback on the v7 canary
532
+ * line, post-beta.116) finalizes open spans + the pending event when a
533
+ * `streamText` call is cancelled via its `AbortSignal`. Builds that don't
534
+ * dispatch it to integrations simply never call it, so it's a no-op there.
535
+ *
536
+ * Step-end note: we intentionally implement only `onStepFinish` (not the newer
537
+ * `onStepEnd`). The latest canary dispatcher fans every step-end event out to
538
+ * BOTH `onStepEnd` and the deprecated `onStepFinish` on each integration, so
539
+ * implementing both names would double-close the step span. `onStepFinish`
540
+ * alone is dispatched on every published v7 beta/canary to date.
541
+ */
542
+
506
543
  type Listener<T> = (event: T) => PromiseLike<void> | void;
507
544
  type ToolExecutionEndEvent = {
508
545
  callId: string;
@@ -576,7 +613,7 @@ type RaindropTelemetryIntegrationOptions = {
576
613
  eventName?: string;
577
614
  convoId?: string;
578
615
  properties?: Record<string, unknown>;
579
- featureFlags?: Record<string, string>;
616
+ featureFlags?: FeatureFlags;
580
617
  };
581
618
  };
582
619
  declare class RaindropTelemetryIntegration implements TelemetryIntegration {
@@ -1194,6 +1231,12 @@ type StartSpanArgs = {
1194
1231
  parent?: TraceSpan;
1195
1232
  /** AI SDK operation ID (e.g. "ai.toolCall", "ai.generateText"). Helps classify the span. */
1196
1233
  operationId?: string;
1234
+ /** Raindrop user ID this span belongs to. Stamped onto the span so it rides onto nested spans. */
1235
+ userId?: string;
1236
+ /** Raindrop conversation ID this span belongs to. */
1237
+ convoId?: string;
1238
+ /** Raindrop event name this span belongs to. */
1239
+ eventName?: string;
1197
1240
  /** Arbitrary string attributes. */
1198
1241
  attributes?: Record<string, string>;
1199
1242
  };
@@ -1212,6 +1255,12 @@ type CreateSpanArgs = {
1212
1255
  parent?: TraceSpan;
1213
1256
  /** AI SDK operation ID (e.g. "ai.toolCall"). Helps classify the span. */
1214
1257
  operationId?: string;
1258
+ /** Raindrop user ID this span belongs to. Stamped onto the span so it rides onto nested spans. */
1259
+ userId?: string;
1260
+ /** Raindrop conversation ID this span belongs to. */
1261
+ convoId?: string;
1262
+ /** Raindrop event name this span belongs to. */
1263
+ eventName?: string;
1215
1264
  /** Input data (will be JSON stringified if object). */
1216
1265
  input?: unknown;
1217
1266
  /** Output data (will be JSON stringified if object). */
@@ -56,6 +56,10 @@ type IdentifyInput$1 = {
56
56
  userId: string;
57
57
  traits?: Record<string, unknown>;
58
58
  };
59
+ type EventUsage = {
60
+ promptTokens?: number;
61
+ completionTokens?: number;
62
+ };
59
63
  type Patch = {
60
64
  eventName?: string;
61
65
  userId?: string;
@@ -63,6 +67,8 @@ type Patch = {
63
67
  input?: string;
64
68
  output?: string;
65
69
  model?: string;
70
+ usage?: EventUsage;
71
+ error?: unknown;
66
72
  properties?: Record<string, unknown>;
67
73
  featureFlags?: Record<string, string>;
68
74
  attachments?: Attachment$1[];
@@ -161,13 +167,7 @@ declare class EventShipper$1 {
161
167
  */
162
168
  private requestOpts;
163
169
  patch(eventId: string, patch: Patch): Promise<void>;
164
- finish(eventId: string, patch: {
165
- output?: string;
166
- model?: string;
167
- properties?: Record<string, unknown>;
168
- featureFlags?: Record<string, string>;
169
- userId?: string;
170
- }): Promise<void>;
170
+ finish(eventId: string, patch: Pick<Patch, "output" | "model" | "usage" | "error" | "properties" | "featureFlags" | "userId">): Promise<void>;
171
171
  flush(): Promise<void>;
172
172
  shutdown(): Promise<void>;
173
173
  trackSignal(signal: SignalInput): Promise<void>;
@@ -399,6 +399,9 @@ declare class TraceShipper$1 {
399
399
  spanIdB64: string;
400
400
  };
401
401
  eventId: string;
402
+ userId?: string;
403
+ convoId?: string;
404
+ eventName?: string;
402
405
  operationId?: string;
403
406
  attributes?: Array<OtlpKeyValue | undefined>;
404
407
  startTimeUnixNano?: string;
@@ -417,6 +420,9 @@ declare class TraceShipper$1 {
417
420
  spanIdB64: string;
418
421
  };
419
422
  eventId: string;
423
+ userId?: string;
424
+ convoId?: string;
425
+ eventName?: string;
420
426
  startTimeUnixNano: string;
421
427
  endTimeUnixNano: string;
422
428
  attributes?: Array<OtlpKeyValue | undefined>;
@@ -503,6 +509,37 @@ declare class TraceShipper extends TraceShipper$1 {
503
509
  constructor(opts: ConstructorParameters<typeof TraceShipper$1>[0]);
504
510
  }
505
511
 
512
+ /**
513
+ * Raindrop telemetry integration for AI SDK v7+
514
+ *
515
+ * Implements the AI SDK's `Telemetry` interface (formerly `TelemetryIntegration`
516
+ * before v7 beta.111) to capture traces and events natively, replacing the
517
+ * Proxy-based wrapping used for v4-v6.
518
+ *
519
+ * Modeled after the upstream OpenTelemetry integration but uses Raindrop's
520
+ * TraceShipper (OTLP/HTTP) + EventShipper instead of the OTel Tracer API.
521
+ *
522
+ * Compatibility: this class targets the latest published v7 build but also
523
+ * exposes the older v7 callback names as aliases so it works on every v7
524
+ * beta/canary released to date:
525
+ * - `onToolCallStart`/`onToolCallFinish` (< beta.111) alongside
526
+ * `onToolExecutionStart`/`onToolExecutionEnd` (>= beta.111).
527
+ * - Current `onToolExecutionEnd` events use the `toolOutput` discriminated
528
+ * union; older builds used top-level `success`/`output`/`error` fields.
529
+ * - `onFinish`/`onEmbedFinish` (< canary.159) alongside `onEnd`/`onEmbedEnd`
530
+ * (>= canary.159, vercel/ai renamed the operation finalizers).
531
+ * - `onAbort` (added as a telemetry-integration callback on the v7 canary
532
+ * line, post-beta.116) finalizes open spans + the pending event when a
533
+ * `streamText` call is cancelled via its `AbortSignal`. Builds that don't
534
+ * dispatch it to integrations simply never call it, so it's a no-op there.
535
+ *
536
+ * Step-end note: we intentionally implement only `onStepFinish` (not the newer
537
+ * `onStepEnd`). The latest canary dispatcher fans every step-end event out to
538
+ * BOTH `onStepEnd` and the deprecated `onStepFinish` on each integration, so
539
+ * implementing both names would double-close the step span. `onStepFinish`
540
+ * alone is dispatched on every published v7 beta/canary to date.
541
+ */
542
+
506
543
  type Listener<T> = (event: T) => PromiseLike<void> | void;
507
544
  type ToolExecutionEndEvent = {
508
545
  callId: string;
@@ -576,7 +613,7 @@ type RaindropTelemetryIntegrationOptions = {
576
613
  eventName?: string;
577
614
  convoId?: string;
578
615
  properties?: Record<string, unknown>;
579
- featureFlags?: Record<string, string>;
616
+ featureFlags?: FeatureFlags;
580
617
  };
581
618
  };
582
619
  declare class RaindropTelemetryIntegration implements TelemetryIntegration {
@@ -1194,6 +1231,12 @@ type StartSpanArgs = {
1194
1231
  parent?: TraceSpan;
1195
1232
  /** AI SDK operation ID (e.g. "ai.toolCall", "ai.generateText"). Helps classify the span. */
1196
1233
  operationId?: string;
1234
+ /** Raindrop user ID this span belongs to. Stamped onto the span so it rides onto nested spans. */
1235
+ userId?: string;
1236
+ /** Raindrop conversation ID this span belongs to. */
1237
+ convoId?: string;
1238
+ /** Raindrop event name this span belongs to. */
1239
+ eventName?: string;
1197
1240
  /** Arbitrary string attributes. */
1198
1241
  attributes?: Record<string, string>;
1199
1242
  };
@@ -1212,6 +1255,12 @@ type CreateSpanArgs = {
1212
1255
  parent?: TraceSpan;
1213
1256
  /** AI SDK operation ID (e.g. "ai.toolCall"). Helps classify the span. */
1214
1257
  operationId?: string;
1258
+ /** Raindrop user ID this span belongs to. Stamped onto the span so it rides onto nested spans. */
1259
+ userId?: string;
1260
+ /** Raindrop conversation ID this span belongs to. */
1261
+ convoId?: string;
1262
+ /** Raindrop event name this span belongs to. */
1263
+ eventName?: string;
1215
1264
  /** Input data (will be JSON stringified if object). */
1216
1265
  input?: unknown;
1217
1266
  /** Output data (will be JSON stringified if object). */
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // ../core/dist/chunk-Y5LUB7OE.js
3
+ // ../core/dist/chunk-QTUH3BHZ.js
4
4
  function normalizeFeatureFlags(input) {
5
5
  if (Array.isArray(input)) {
6
6
  return Object.fromEntries(input.map((name) => [name, "true"]));
@@ -443,19 +443,52 @@ function projectIdHeaders(projectId) {
443
443
  var SHUTDOWN_DEADLINE_MS = 1e4;
444
444
  var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
445
445
  function mergePatches(target, source) {
446
- var _a, _b, _c, _d, _e, _f;
446
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
447
447
  const out = { ...target, ...source };
448
448
  if (target.properties || source.properties) {
449
449
  out.properties = { ...(_a = target.properties) != null ? _a : {}, ...(_b = source.properties) != null ? _b : {} };
450
450
  }
451
+ if (target.usage || source.usage) {
452
+ out.usage = { ...(_c = target.usage) != null ? _c : {} };
453
+ if (((_d = source.usage) == null ? void 0 : _d.promptTokens) !== void 0) {
454
+ out.usage.promptTokens = source.usage.promptTokens;
455
+ }
456
+ if (((_e = source.usage) == null ? void 0 : _e.completionTokens) !== void 0) {
457
+ out.usage.completionTokens = source.usage.completionTokens;
458
+ }
459
+ }
460
+ if (source.error === void 0) {
461
+ out.error = target.error;
462
+ }
451
463
  if (target.featureFlags || source.featureFlags) {
452
- out.featureFlags = { ...(_c = target.featureFlags) != null ? _c : {}, ...(_d = source.featureFlags) != null ? _d : {} };
464
+ out.featureFlags = { ...(_f = target.featureFlags) != null ? _f : {}, ...(_g = source.featureFlags) != null ? _g : {} };
453
465
  }
454
466
  if (target.attachments || source.attachments) {
455
- out.attachments = [...(_e = target.attachments) != null ? _e : [], ...(_f = source.attachments) != null ? _f : []];
467
+ out.attachments = [...(_h = target.attachments) != null ? _h : [], ...(_i = source.attachments) != null ? _i : []];
456
468
  }
457
469
  return out;
458
470
  }
471
+ function isErrorLike(value) {
472
+ return value !== null && typeof value === "object";
473
+ }
474
+ function eventTelemetryProperties(patch) {
475
+ var _a, _b;
476
+ const properties = {};
477
+ if (((_a = patch.usage) == null ? void 0 : _a.promptTokens) !== void 0 && Number.isFinite(patch.usage.promptTokens)) {
478
+ properties["ai.usage.prompt_tokens"] = patch.usage.promptTokens;
479
+ }
480
+ if (((_b = patch.usage) == null ? void 0 : _b.completionTokens) !== void 0 && Number.isFinite(patch.usage.completionTokens)) {
481
+ properties["ai.usage.completion_tokens"] = patch.usage.completionTokens;
482
+ }
483
+ if (patch.error !== void 0 && patch.error !== null) {
484
+ const constructorName = patch.error instanceof Error && patch.error.constructor !== Error ? patch.error.constructor.name : void 0;
485
+ const errorType = patch.error instanceof Error ? patch.error.name && patch.error.name !== "Error" ? patch.error.name : constructorName || patch.error.name || "Error" : isErrorLike(patch.error) && typeof patch.error.name === "string" && patch.error.name.length > 0 ? patch.error.name : "Error";
486
+ const errorMessage = patch.error instanceof Error ? patch.error.message : isErrorLike(patch.error) && typeof patch.error.message === "string" ? patch.error.message : String(patch.error);
487
+ properties["error.type"] = errorType;
488
+ properties["error.message"] = errorMessage;
489
+ }
490
+ return properties;
491
+ }
459
492
  var EventShipper = class {
460
493
  constructor(opts) {
461
494
  this.buffers = /* @__PURE__ */ new Map();
@@ -704,6 +737,11 @@ var EventShipper = class {
704
737
  return;
705
738
  }
706
739
  const { wizardSession, ...restProperties } = (_e = accumulated.properties) != null ? _e : {};
740
+ let telemetryProperties = {};
741
+ try {
742
+ telemetryProperties = eventTelemetryProperties(accumulated);
743
+ } catch (e) {
744
+ }
707
745
  const convoId = (_f = accumulated.convoId) != null ? _f : sticky.convoId;
708
746
  const isPending = (_h = (_g = accumulated.isPending) != null ? _g : sticky.isPending) != null ? _h : true;
709
747
  const payload = {
@@ -713,12 +751,13 @@ var EventShipper = class {
713
751
  timestamp: (_i = accumulated.timestamp) != null ? _i : (/* @__PURE__ */ new Date()).toISOString(),
714
752
  ai_data: {
715
753
  input: accumulated.input,
716
- output: accumulated.output,
754
+ output: accumulated.error !== void 0 && accumulated.error !== null ? void 0 : accumulated.output,
717
755
  model: accumulated.model,
718
756
  convo_id: convoId
719
757
  },
720
758
  properties: {
721
759
  ...restProperties,
760
+ ...telemetryProperties,
722
761
  ...wizardSession ? { "raindrop.wizardSession": wizardSession } : {},
723
762
  $context: this.context
724
763
  },
@@ -876,6 +915,13 @@ function redactJsonAttributeValue(key, value) {
876
915
  if (scrubbedJson === json) return void 0;
877
916
  return { stringValue: scrubbedJson };
878
917
  }
918
+ function identityAttrs(args) {
919
+ return [
920
+ attrString("ai.telemetry.metadata.raindrop.ai.userId", args.userId),
921
+ attrString("ai.telemetry.metadata.raindrop.convoId", args.convoId),
922
+ attrString("ai.telemetry.metadata.raindrop.eventName", args.eventName)
923
+ ];
924
+ }
879
925
  function applyOtelSpanAttributeLimit(limit) {
880
926
  var _a, _b;
881
927
  try {
@@ -1000,6 +1046,7 @@ var TraceShipper = class {
1000
1046
  const started = (_a = args.startTimeUnixNano) != null ? _a : nowUnixNanoString();
1001
1047
  const attrs = [
1002
1048
  attrString("ai.telemetry.metadata.raindrop.eventId", args.eventId),
1049
+ ...identityAttrs(args),
1003
1050
  attrString("ai.operationId", args.operationId)
1004
1051
  ];
1005
1052
  if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
@@ -1055,7 +1102,8 @@ var TraceShipper = class {
1055
1102
  var _a;
1056
1103
  const ids = createSpanIds(args.parent);
1057
1104
  const attrs = [
1058
- attrString("ai.telemetry.metadata.raindrop.eventId", args.eventId)
1105
+ attrString("ai.telemetry.metadata.raindrop.eventId", args.eventId),
1106
+ ...identityAttrs(args)
1059
1107
  ];
1060
1108
  if ((_a = args.attributes) == null ? void 0 : _a.length) attrs.push(...args.attributes);
1061
1109
  const otlp = buildOtlpSpan({
@@ -1311,7 +1359,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
1311
1359
  // package.json
1312
1360
  var package_default = {
1313
1361
  name: "@raindrop-ai/ai-sdk",
1314
- version: "0.1.0"};
1362
+ version: "0.2.0"};
1315
1363
 
1316
1364
  // src/internal/version.ts
1317
1365
  var libraryName = package_default.name;
@@ -2246,7 +2294,7 @@ var RaindropTelemetryIntegration = class {
2246
2294
  };
2247
2295
  // ── onStart ─────────────────────────────────────────────────────────────
2248
2296
  this.onStart = (event) => {
2249
- var _a, _b, _c, _d, _e;
2297
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2250
2298
  if (event.isEnabled === false) return;
2251
2299
  const isEmbed = event.operationId === "ai.embed" || event.operationId === "ai.embedMany";
2252
2300
  const recordInputs = event.recordInputs !== false;
@@ -2256,15 +2304,20 @@ var RaindropTelemetryIntegration = class {
2256
2304
  const callContextMetadata = getCurrentRaindropCallMetadata();
2257
2305
  const metadata = eventMetadata2 != null ? eventMetadata2 : callContextMetadata == null ? void 0 : callContextMetadata.rawMetadata;
2258
2306
  const callMeta = this.extractRaindropMetadata(metadata);
2307
+ const identity = {
2308
+ userId: (_b = callMeta.userId) != null ? _b : (_a = this.defaultContext) == null ? void 0 : _a.userId,
2309
+ convoId: (_d = callMeta.convoId) != null ? _d : (_c = this.defaultContext) == null ? void 0 : _c.convoId,
2310
+ eventName: (_f = callMeta.eventName) != null ? _f : (_e = this.defaultContext) == null ? void 0 : _e.eventName
2311
+ };
2259
2312
  const inherited = getContextManager().getParentSpanIds();
2260
2313
  const eventIdGenerated = (metadata == null ? void 0 : metadata["raindrop.internal.eventIdGenerated"]) === "true" || (metadata == null ? void 0 : metadata["raindrop.internal.eventIdGenerated"]) === true || (callContextMetadata == null ? void 0 : callContextMetadata.eventIdGenerated) === true;
2261
2314
  const explicitEventId = callMeta.eventId && !eventIdGenerated ? callMeta.eventId : void 0;
2262
- const eventId = (_d = (_c = (_b = explicitEventId != null ? explicitEventId : (_a = this.defaultContext) == null ? void 0 : _a.eventId) != null ? _b : inherited == null ? void 0 : inherited.eventId) != null ? _c : callMeta.eventId) != null ? _d : randomUUID();
2315
+ const eventId = (_j = (_i = (_h = explicitEventId != null ? explicitEventId : (_g = this.defaultContext) == null ? void 0 : _g.eventId) != null ? _h : inherited == null ? void 0 : inherited.eventId) != null ? _i : callMeta.eventId) != null ? _j : randomUUID();
2263
2316
  const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
2264
2317
  const { operationName, resourceName } = opName(event.operationId, functionId);
2265
2318
  const parentToolContext = !isEmbed && this.subagentWrapping ? getCurrentParentToolContext() : void 0;
2266
2319
  const metadataSubagentName = !isEmbed && this.subagentWrapping && parentToolContext === void 0 ? typeof (metadata == null ? void 0 : metadata["eve.subagent.name"]) === "string" ? metadata["eve.subagent.name"] : typeof (metadata == null ? void 0 : metadata["ash.subagent.name"]) === "string" ? metadata["ash.subagent.name"] : void 0 : void 0;
2267
- const subagentName = (_e = parentToolContext == null ? void 0 : parentToolContext.toolName) != null ? _e : metadataSubagentName;
2320
+ const subagentName = (_k = parentToolContext == null ? void 0 : parentToolContext.toolName) != null ? _k : metadataSubagentName;
2268
2321
  let subagentToolCallSpan;
2269
2322
  let rootParentOverride;
2270
2323
  if (subagentName && this.sendTraces) {
@@ -2277,6 +2330,7 @@ var RaindropTelemetryIntegration = class {
2277
2330
  name: subagentName,
2278
2331
  parent: inheritedParent,
2279
2332
  eventId,
2333
+ ...identity,
2280
2334
  operationId: "ai.toolCall",
2281
2335
  attributes: [
2282
2336
  attrString("operation.name", "ai.toolCall"),
@@ -2293,6 +2347,7 @@ var RaindropTelemetryIntegration = class {
2293
2347
  name: "agent.subagent",
2294
2348
  parent: subagentParentRef,
2295
2349
  eventId,
2350
+ ...identity,
2296
2351
  operationId: "agent.subagent",
2297
2352
  attributes: [
2298
2353
  attrString("operation.name", "agent.subagent"),
@@ -2320,6 +2375,7 @@ var RaindropTelemetryIntegration = class {
2320
2375
  name: event.operationId,
2321
2376
  parent: rootParentOverride != null ? rootParentOverride : inheritedParent,
2322
2377
  eventId,
2378
+ ...identity,
2323
2379
  operationId: event.operationId,
2324
2380
  attributes: [
2325
2381
  attrString("operation.name", operationName),
@@ -2327,13 +2383,14 @@ var RaindropTelemetryIntegration = class {
2327
2383
  attrString("ai.telemetry.functionId", functionId),
2328
2384
  attrString("ai.model.provider", event.provider),
2329
2385
  attrString("ai.model.id", event.modelId),
2330
- // Filter out raindrop.eventId from metadata attrs since TraceShipper
2331
- // already sets it via the eventId arg. Without this, eventMetadata()'s
2332
- // auto-generated ID would duplicate and override the resolved one.
2386
+ // Filter out identity keys (eventId/userId/convoId/eventName) from
2387
+ // metadata attrs since TraceShipper already stamps them via dedicated
2388
+ // args. Without this, eventMetadata()'s auto-generated ID would
2389
+ // duplicate and override the resolved one.
2333
2390
  ...attrsFromTelemetryMetadata(
2334
2391
  metadata ? Object.fromEntries(
2335
2392
  Object.entries(metadata).filter(
2336
- ([k]) => k !== "raindrop.eventId" && k !== "raindrop.internal.eventIdGenerated"
2393
+ ([k]) => k !== "raindrop.eventId" && k !== "raindrop.internal.eventIdGenerated" && k !== "raindrop.userId" && k !== "raindrop.convoId" && k !== "raindrop.eventName"
2337
2394
  )
2338
2395
  ) : void 0
2339
2396
  ),
@@ -2345,6 +2402,7 @@ var RaindropTelemetryIntegration = class {
2345
2402
  this.callStates.set(event.callId, {
2346
2403
  operationId: event.operationId,
2347
2404
  eventId,
2405
+ identity,
2348
2406
  rootSpan,
2349
2407
  rootParent: rootSpan ? this.spanParentRef(rootSpan) : rootParentOverride != null ? rootParentOverride : inheritedParent,
2350
2408
  stepSpan: void 0,
@@ -2396,6 +2454,7 @@ var RaindropTelemetryIntegration = class {
2396
2454
  name: stepOperationId,
2397
2455
  parent: state.rootParent,
2398
2456
  eventId: state.eventId,
2457
+ ...state.identity,
2399
2458
  operationId: stepOperationId,
2400
2459
  attributes: [
2401
2460
  attrString("operation.name", operationName),
@@ -2529,6 +2588,7 @@ var RaindropTelemetryIntegration = class {
2529
2588
  name: event.operationId,
2530
2589
  parent: state.rootParent,
2531
2590
  eventId: state.eventId,
2591
+ ...state.identity,
2532
2592
  operationId: event.operationId,
2533
2593
  attributes: [
2534
2594
  attrString("operation.name", operationName),
@@ -2795,6 +2855,7 @@ var RaindropTelemetryIntegration = class {
2795
2855
  name: "ai.toolCall",
2796
2856
  parent: state.stepParent,
2797
2857
  eventId: state.eventId,
2858
+ ...state.identity,
2798
2859
  operationId: "ai.toolCall",
2799
2860
  attributes: [
2800
2861
  attrString("operation.name", operationName),
@@ -2872,6 +2933,7 @@ var RaindropTelemetryIntegration = class {
2872
2933
  name: "ai.toolCall",
2873
2934
  parent: state.stepParent,
2874
2935
  eventId: state.eventId,
2936
+ ...state.identity,
2875
2937
  operationId: "ai.toolCall",
2876
2938
  attributes: [
2877
2939
  attrString("operation.name", operationName),
@@ -2975,7 +3037,7 @@ var RaindropTelemetryIntegration = class {
2975
3037
  ...callMeta.properties
2976
3038
  };
2977
3039
  const featureFlags = {
2978
- ...(_g = this.defaultContext) == null ? void 0 : _g.featureFlags,
3040
+ ...((_g = this.defaultContext) == null ? void 0 : _g.featureFlags) ? normalizeFeatureFlags(this.defaultContext.featureFlags) : {},
2979
3041
  ...callMeta.featureFlags
2980
3042
  };
2981
3043
  const convoId = (_i = callMeta.convoId) != null ? _i : (_h = this.defaultContext) == null ? void 0 : _h.convoId;
@@ -3539,6 +3601,9 @@ function teeStreamObjectBaseStream(result) {
3539
3601
  } catch (e) {
3540
3602
  }
3541
3603
  }
3604
+ function identityFromContext(ctx) {
3605
+ return { userId: ctx.userId, convoId: ctx.convoId, eventName: ctx.eventName };
3606
+ }
3542
3607
  function setupOperation(params) {
3543
3608
  var _a, _b, _c;
3544
3609
  const {
@@ -3570,6 +3635,7 @@ function setupOperation(params) {
3570
3635
  name: outerOperationId,
3571
3636
  parent: inheritedParent,
3572
3637
  eventId,
3638
+ ...identityFromContext(mergedCtx),
3573
3639
  operationId: outerOperationId,
3574
3640
  attributes: [
3575
3641
  attrString("operation.name", operationName),
@@ -3578,9 +3644,6 @@ function setupOperation(params) {
3578
3644
  attrString("ai.model.provider", modelInfoFromArgs.provider),
3579
3645
  attrString("ai.model.id", modelInfoFromArgs.modelId),
3580
3646
  attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
3581
- attrString("ai.telemetry.metadata.raindrop.eventName", mergedCtx.eventName),
3582
- attrString("ai.telemetry.metadata.raindrop.ai.userId", mergedCtx.userId),
3583
- attrString("ai.telemetry.metadata.raindrop.convoId", mergedCtx.convoId),
3584
3647
  ...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
3585
3648
  ...attrsFromHeaders(isRecord(arg) ? arg["headers"] : void 0),
3586
3649
  ...attrsFromSettings(arg),
@@ -3670,6 +3733,7 @@ function createFinalize(params) {
3670
3733
  responseMessages,
3671
3734
  rootSpan: setup.rootSpan,
3672
3735
  eventId: setup.eventId,
3736
+ ...identityFromContext(setup.ctx),
3673
3737
  telemetry: setup.telemetry,
3674
3738
  toolCalls: setup.toolCalls,
3675
3739
  traceShipper,
@@ -3708,6 +3772,11 @@ function createFinalize(params) {
3708
3772
  input,
3709
3773
  output,
3710
3774
  model: finalModel,
3775
+ usage: {
3776
+ promptTokens: usage == null ? void 0 : usage.inputTokens,
3777
+ completionTokens: usage == null ? void 0 : usage.outputTokens
3778
+ },
3779
+ error,
3711
3780
  properties: patch.properties,
3712
3781
  featureFlags: patch.featureFlags,
3713
3782
  attachments: patch.attachments,
@@ -3742,6 +3811,7 @@ function startToolSpan(toolCall, rootSpan, ctx, startTimeUnixNano) {
3742
3811
  name: "ai.toolCall",
3743
3812
  parent: { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 },
3744
3813
  eventId: ctx.eventId,
3814
+ ...identityFromContext(ctx),
3745
3815
  operationId: "ai.toolCall",
3746
3816
  attributes: [
3747
3817
  attrString("operation.name", operationName),
@@ -3779,6 +3849,9 @@ function emitTranscriptToolCallSpans(params) {
3779
3849
  }
3780
3850
  const ctx = {
3781
3851
  eventId: params.eventId,
3852
+ userId: params.userId,
3853
+ convoId: params.convoId,
3854
+ eventName: params.eventName,
3782
3855
  telemetry: params.telemetry,
3783
3856
  traceShipper: params.traceShipper
3784
3857
  };
@@ -4158,6 +4231,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
4158
4231
  name: outerOperationId,
4159
4232
  parent: inheritedParent,
4160
4233
  eventId,
4234
+ ...identityFromContext(ctx),
4161
4235
  operationId: outerOperationId,
4162
4236
  attributes: [
4163
4237
  attrString("operation.name", operationName),
@@ -4166,9 +4240,6 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
4166
4240
  attrString("ai.model.provider", modelInfoFromArgs.provider),
4167
4241
  attrString("ai.model.id", modelInfoFromArgs.modelId),
4168
4242
  attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
4169
- attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
4170
- attrString("ai.telemetry.metadata.raindrop.ai.userId", ctx.userId),
4171
- attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
4172
4243
  ...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
4173
4244
  ...attrsFromHeaders(mergedArgs["headers"]),
4174
4245
  ...attrsFromSettings(mergedArgs),
@@ -4233,6 +4304,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
4233
4304
  responseMessages,
4234
4305
  rootSpan,
4235
4306
  eventId,
4307
+ ...identityFromContext(ctx),
4236
4308
  telemetry,
4237
4309
  toolCalls,
4238
4310
  traceShipper: deps.traceShipper,
@@ -4285,6 +4357,11 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
4285
4357
  input,
4286
4358
  output,
4287
4359
  model: finalModel,
4360
+ usage: {
4361
+ promptTokens: usage == null ? void 0 : usage.inputTokens,
4362
+ completionTokens: usage == null ? void 0 : usage.outputTokens
4363
+ },
4364
+ error,
4288
4365
  properties: patch.properties,
4289
4366
  featureFlags: patch.featureFlags,
4290
4367
  attachments: patch.attachments,
@@ -4368,6 +4445,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
4368
4445
  name: outerOperationId,
4369
4446
  parent: inheritedParent,
4370
4447
  eventId,
4448
+ ...identityFromContext(ctx),
4371
4449
  operationId: outerOperationId,
4372
4450
  attributes: [
4373
4451
  attrString("operation.name", operationName),
@@ -4376,9 +4454,6 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
4376
4454
  attrString("ai.model.provider", modelInfoFromArgs.provider),
4377
4455
  attrString("ai.model.id", modelInfoFromArgs.modelId),
4378
4456
  attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
4379
- attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
4380
- attrString("ai.telemetry.metadata.raindrop.ai.userId", ctx.userId),
4381
- attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
4382
4457
  ...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
4383
4458
  ...attrsFromHeaders(mergedArgs["headers"]),
4384
4459
  ...attrsFromSettings(mergedArgs),
@@ -4443,6 +4518,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
4443
4518
  responseMessages,
4444
4519
  rootSpan,
4445
4520
  eventId,
4521
+ ...identityFromContext(ctx),
4446
4522
  telemetry,
4447
4523
  toolCalls,
4448
4524
  traceShipper: deps.traceShipper,
@@ -4495,6 +4571,11 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
4495
4571
  input,
4496
4572
  output,
4497
4573
  model: finalModel,
4574
+ usage: {
4575
+ promptTokens: usage == null ? void 0 : usage.inputTokens,
4576
+ completionTokens: usage == null ? void 0 : usage.outputTokens
4577
+ },
4578
+ error,
4498
4579
  properties: patch.properties,
4499
4580
  featureFlags: patch.featureFlags,
4500
4581
  attachments: patch.attachments,
@@ -4592,6 +4673,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
4592
4673
  name: "ai.toolCall",
4593
4674
  parent,
4594
4675
  eventId: ctx.eventId,
4676
+ ...identityFromContext(ctx.context),
4595
4677
  operationId: "ai.toolCall",
4596
4678
  attributes: [
4597
4679
  attrString("operation.name", operationName),
@@ -4952,6 +5034,7 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
4952
5034
  name: operationId,
4953
5035
  parent,
4954
5036
  eventId: ctx.eventId,
5037
+ ...identityFromContext(ctx.context),
4955
5038
  operationId,
4956
5039
  attributes: [
4957
5040
  attrString("operation.name", operationName),
@@ -5035,6 +5118,7 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
5035
5118
  name: operationId,
5036
5119
  parent,
5037
5120
  eventId: ctx.eventId,
5121
+ ...identityFromContext(ctx.context),
5038
5122
  operationId,
5039
5123
  attributes: [
5040
5124
  attrString("operation.name", operationName),
@@ -5295,6 +5379,9 @@ function createRaindropAISDK(opts) {
5295
5379
  const internal = traceShipper.startSpan({
5296
5380
  name: args.name,
5297
5381
  eventId: args.eventId,
5382
+ userId: args.userId,
5383
+ convoId: args.convoId,
5384
+ eventName: args.eventName,
5298
5385
  parent,
5299
5386
  operationId: args.operationId,
5300
5387
  attributes: attrs
@@ -5329,6 +5416,9 @@ function createRaindropAISDK(opts) {
5329
5416
  const internal = traceShipper.startSpan({
5330
5417
  name: args.name,
5331
5418
  eventId: args.eventId,
5419
+ userId: args.userId,
5420
+ convoId: args.convoId,
5421
+ eventName: args.eventName,
5332
5422
  parent,
5333
5423
  operationId: args.operationId,
5334
5424
  attributes: startAttrs,