@raindrop-ai/ai-sdk 0.0.20 → 0.0.21

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.
@@ -1,4 +1,4 @@
1
- // ../core/dist/chunk-H6VSZSLN.js
1
+ // ../core/dist/chunk-4UCYIEH4.js
2
2
  function getCrypto() {
3
3
  const c = globalThis.crypto;
4
4
  return c;
@@ -143,6 +143,7 @@ async function postJson(url, body, headers, opts) {
143
143
  );
144
144
  }
145
145
  var SpanStatusCode = {
146
+ UNSET: 0,
146
147
  ERROR: 2
147
148
  };
148
149
  function createSpanIds(parent) {
@@ -463,11 +464,66 @@ var EventShipper = class {
463
464
  }
464
465
  }
465
466
  };
467
+ var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
468
+ function resolveLocalDebuggerBaseUrl(baseUrl) {
469
+ var _a, _b, _c;
470
+ const resolved = (_b = baseUrl != null ? baseUrl : typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a[LOCAL_DEBUGGER_ENV_VAR] : void 0) != null ? _b : null;
471
+ return resolved ? (_c = formatEndpoint(resolved)) != null ? _c : null : null;
472
+ }
473
+ function localDebuggerEnabled(baseUrl) {
474
+ return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
475
+ }
476
+ function normalizeLocalDebuggerLiveEventType(type) {
477
+ switch (type) {
478
+ case "text-delta":
479
+ return "text_delta";
480
+ case "reasoning":
481
+ case "reasoning-delta":
482
+ return "reasoning_delta";
483
+ case "tool-call":
484
+ return "tool_start";
485
+ case "tool-result":
486
+ return "tool_result";
487
+ default:
488
+ return type;
489
+ }
490
+ }
491
+ function mirrorTraceExportToLocalDebugger(body, options = {}) {
492
+ var _a;
493
+ const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
494
+ if (!baseUrl) return;
495
+ void postJson(`${baseUrl}traces`, body, {}, {
496
+ maxAttempts: 1,
497
+ debug: (_a = options.debug) != null ? _a : false,
498
+ sdkName: options.sdkName
499
+ }).catch(() => {
500
+ });
501
+ }
502
+ function sendLocalDebuggerLiveEvent(event, options = {}) {
503
+ var _a, _b;
504
+ const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
505
+ if (!baseUrl) return;
506
+ void postJson(
507
+ `${baseUrl}live`,
508
+ {
509
+ ...event,
510
+ type: normalizeLocalDebuggerLiveEventType(event.type),
511
+ timestamp: (_a = event.timestamp) != null ? _a : Date.now()
512
+ },
513
+ {},
514
+ {
515
+ maxAttempts: 1,
516
+ debug: (_b = options.debug) != null ? _b : false,
517
+ sdkName: options.sdkName
518
+ }
519
+ ).catch(() => {
520
+ });
521
+ }
466
522
  var TraceShipper = class {
467
523
  constructor(opts) {
468
524
  this.queue = [];
469
525
  this.inFlight = /* @__PURE__ */ new Set();
470
- var _a, _b, _c, _d, _e, _f, _g, _h;
526
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
471
527
  this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
472
528
  this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
473
529
  this.enabled = opts.enabled !== false;
@@ -480,6 +536,13 @@ var TraceShipper = class {
480
536
  this.prefix = `[raindrop-ai/${this.sdkName}]`;
481
537
  this.serviceName = (_g = opts.serviceName) != null ? _g : "raindrop.core";
482
538
  this.serviceVersion = (_h = opts.serviceVersion) != null ? _h : "0.0.0";
539
+ const localDebugger = typeof process !== "undefined" ? (_i = process.env) == null ? void 0 : _i.RAINDROP_LOCAL_DEBUGGER : void 0;
540
+ if (localDebugger) {
541
+ this.localDebuggerUrl = (_j = resolveLocalDebuggerBaseUrl(localDebugger)) != null ? _j : void 0;
542
+ if (this.debug) {
543
+ console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
544
+ }
545
+ }
483
546
  }
484
547
  isDebugEnabled() {
485
548
  return this.debug;
@@ -496,7 +559,25 @@ var TraceShipper = class {
496
559
  attrString("ai.operationId", args.operationId)
497
560
  ];
498
561
  if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
499
- return { ids, name: args.name, startTimeUnixNano: started, attributes: attrs };
562
+ const span = { ids, name: args.name, startTimeUnixNano: started, attributes: attrs };
563
+ if (this.localDebuggerUrl) {
564
+ const openSpan = buildOtlpSpan({
565
+ ids: span.ids,
566
+ name: span.name,
567
+ startTimeUnixNano: span.startTimeUnixNano,
568
+ endTimeUnixNano: span.startTimeUnixNano,
569
+ // placeholder — will be updated on endSpan
570
+ attributes: span.attributes,
571
+ status: { code: SpanStatusCode.UNSET }
572
+ });
573
+ const body = buildExportTraceServiceRequest([openSpan], this.serviceName, this.serviceVersion);
574
+ mirrorTraceExportToLocalDebugger(body, {
575
+ baseUrl: this.localDebuggerUrl,
576
+ debug: false,
577
+ sdkName: this.sdkName
578
+ });
579
+ }
580
+ return span;
500
581
  }
501
582
  endSpan(span, extra) {
502
583
  var _a, _b;
@@ -519,6 +600,14 @@ var TraceShipper = class {
519
600
  status
520
601
  });
521
602
  this.enqueue(otlp);
603
+ if (this.localDebuggerUrl) {
604
+ const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
605
+ mirrorTraceExportToLocalDebugger(body, {
606
+ baseUrl: this.localDebuggerUrl,
607
+ debug: false,
608
+ sdkName: this.sdkName
609
+ });
610
+ }
522
611
  }
523
612
  createSpan(args) {
524
613
  var _a;
@@ -536,6 +625,14 @@ var TraceShipper = class {
536
625
  status: args.status
537
626
  });
538
627
  this.enqueue(otlp);
628
+ if (this.localDebuggerUrl) {
629
+ const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
630
+ mirrorTraceExportToLocalDebugger(body, {
631
+ baseUrl: this.localDebuggerUrl,
632
+ debug: false,
633
+ sdkName: this.sdkName
634
+ });
635
+ }
539
636
  }
540
637
  enqueue(span) {
541
638
  if (!this.enabled) return;
@@ -730,7 +827,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
730
827
  // package.json
731
828
  var package_default = {
732
829
  name: "@raindrop-ai/ai-sdk",
733
- version: "0.0.20"};
830
+ version: "0.0.21"};
734
831
 
735
832
  // src/internal/version.ts
736
833
  var libraryName = package_default.name;
@@ -1536,6 +1633,7 @@ var RaindropTelemetryIntegration = class {
1536
1633
  ]
1537
1634
  });
1538
1635
  state.toolSpans.set(toolCall.toolCallId, toolSpan);
1636
+ this.emitLive(state, "tool_start", toolCall.toolName, { args: toolCall.input });
1539
1637
  };
1540
1638
  // ── onToolCallFinish ────────────────────────────────────────────────────
1541
1639
  this.onToolCallFinish = (event) => {
@@ -1550,11 +1648,12 @@ var RaindropTelemetryIntegration = class {
1550
1648
  } else {
1551
1649
  this.traceShipper.endSpan(toolSpan, { error: event.error });
1552
1650
  }
1651
+ this.emitLive(state, "tool_result", event.toolCall.toolName);
1553
1652
  state.toolSpans.delete(event.toolCall.toolCallId);
1554
1653
  };
1555
1654
  // ── onChunk (streaming) ─────────────────────────────────────────────────
1556
1655
  this.onChunk = (event) => {
1557
- var _a, _b, _c;
1656
+ var _a, _b, _c, _d, _e;
1558
1657
  const callId = (_b = event.callId) != null ? _b : (_a = event.chunk) == null ? void 0 : _a.callId;
1559
1658
  if (!callId) return;
1560
1659
  const state = this.getState(callId);
@@ -1565,6 +1664,12 @@ var RaindropTelemetryIntegration = class {
1565
1664
  const delta = (_c = chunk.textDelta) != null ? _c : chunk.delta;
1566
1665
  if (typeof delta === "string") {
1567
1666
  state.accumulatedText += delta;
1667
+ this.emitLive(state, "text_delta", delta);
1668
+ }
1669
+ } else if (chunk.type === "reasoning" || chunk.type === "reasoning-delta") {
1670
+ const text = (_e = (_d = chunk.textDelta) != null ? _d : chunk.text) != null ? _e : chunk.delta;
1671
+ if (typeof text === "string") {
1672
+ this.emitLive(state, "reasoning_delta", text);
1568
1673
  }
1569
1674
  }
1570
1675
  };
@@ -1752,6 +1857,23 @@ var RaindropTelemetryIntegration = class {
1752
1857
  spanParentRef(span) {
1753
1858
  return { traceIdB64: span.ids.traceIdB64, spanIdB64: span.ids.spanIdB64 };
1754
1859
  }
1860
+ emitLive(state, type, content, extra) {
1861
+ var _a, _b, _c, _d, _e, _f;
1862
+ if (!localDebuggerEnabled() || !state.rootSpan) return;
1863
+ const callMeta = this.extractRaindropMetadata(state.metadata);
1864
+ sendLocalDebuggerLiveEvent({
1865
+ traceId: state.rootSpan.ids.traceIdB64,
1866
+ type,
1867
+ content,
1868
+ metadata: {
1869
+ userId: (_b = callMeta.userId) != null ? _b : (_a = this.defaultContext) == null ? void 0 : _a.userId,
1870
+ convoId: (_d = callMeta.convoId) != null ? _d : (_c = this.defaultContext) == null ? void 0 : _c.convoId,
1871
+ eventName: (_f = callMeta.eventName) != null ? _f : (_e = this.defaultContext) == null ? void 0 : _e.eventName,
1872
+ eventId: state.eventId,
1873
+ ...extra
1874
+ }
1875
+ });
1876
+ }
1755
1877
  extractRaindropMetadata(metadata) {
1756
1878
  if (!metadata) return {};
1757
1879
  const result = {};
@@ -2297,6 +2419,36 @@ function shouldKeepEventPending(params) {
2297
2419
  if (params.error != null || !params.canKeepEventPending) return false;
2298
2420
  return params.finishReason === "tool-calls" || params.finishReason === "tool_calls";
2299
2421
  }
2422
+ function normalizePromptAttr(arg) {
2423
+ if (!isRecord(arg)) return arg;
2424
+ const system = arg["system"];
2425
+ const prompt = arg["prompt"];
2426
+ const messages = arg["messages"];
2427
+ if (Array.isArray(messages)) {
2428
+ if (system) {
2429
+ const sysContent = typeof system === "string" ? system : JSON.stringify(system);
2430
+ return [{ role: "system", content: sysContent }, ...messages];
2431
+ }
2432
+ return messages;
2433
+ }
2434
+ if (typeof prompt === "string") {
2435
+ const msgs = [];
2436
+ if (system) {
2437
+ msgs.push({ role: "system", content: typeof system === "string" ? system : JSON.stringify(system) });
2438
+ }
2439
+ msgs.push({ role: "user", content: prompt });
2440
+ return msgs;
2441
+ }
2442
+ return { system, prompt, messages };
2443
+ }
2444
+ function getLocalDebuggerMetadata(ctx) {
2445
+ return {
2446
+ eventId: ctx.eventId,
2447
+ ...ctx.eventName ? { eventName: ctx.eventName } : {},
2448
+ ...ctx.userId ? { userId: ctx.userId } : {},
2449
+ ...ctx.convoId ? { convoId: ctx.convoId } : {}
2450
+ };
2451
+ }
2300
2452
  async function safeFinalize(finalize, debug, result, error) {
2301
2453
  try {
2302
2454
  await finalize(result, error);
@@ -2369,17 +2521,17 @@ function setupOperation(params) {
2369
2521
  attrString("ai.telemetry.functionId", telemetry == null ? void 0 : telemetry.functionId),
2370
2522
  attrString("ai.model.provider", modelInfoFromArgs.provider),
2371
2523
  attrString("ai.model.id", modelInfoFromArgs.modelId),
2524
+ attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
2525
+ attrString("ai.telemetry.metadata.raindrop.eventName", mergedCtx.eventName),
2526
+ attrString("ai.telemetry.metadata.raindrop.userId", mergedCtx.userId),
2527
+ attrString("ai.telemetry.metadata.raindrop.convoId", mergedCtx.convoId),
2372
2528
  ...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
2373
2529
  ...attrsFromHeaders(isRecord(arg) ? arg["headers"] : void 0),
2374
2530
  ...attrsFromSettings(arg),
2375
2531
  ...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [
2376
2532
  attrString(
2377
2533
  "ai.prompt",
2378
- safeJsonWithUint8({
2379
- system: isRecord(arg) ? arg["system"] : void 0,
2380
- prompt: isRecord(arg) ? arg["prompt"] : void 0,
2381
- messages: isRecord(arg) ? arg["messages"] : void 0
2382
- })
2534
+ safeJsonWithUint8(normalizePromptAttr(arg))
2383
2535
  )
2384
2536
  ]
2385
2537
  ]
@@ -2388,6 +2540,7 @@ function setupOperation(params) {
2388
2540
  const operationSelfDiagnostics = isObjectOperation(operation) ? void 0 : selfDiagnostics;
2389
2541
  const wrapCtx = {
2390
2542
  eventId,
2543
+ context: mergedCtx,
2391
2544
  telemetry,
2392
2545
  sendTraces,
2393
2546
  debug,
@@ -2762,6 +2915,7 @@ function wrapAISDK(aiSDK, deps) {
2762
2915
  const perCallEventIdGenerated = !perCallEventIdExplicit;
2763
2916
  const perCallCtx = {
2764
2917
  eventId: perCallEventId,
2918
+ context: wrapTimeCtx,
2765
2919
  telemetry,
2766
2920
  sendTraces: false,
2767
2921
  debug,
@@ -2916,7 +3070,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
2916
3070
  if (!mergedCtx.userId) warnMissingUserIdOnce();
2917
3071
  const inherited = await getCurrentParentSpanContext();
2918
3072
  const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
2919
- const ctx = { ...mergedCtx};
3073
+ const ctx = { ...mergedCtx, eventId };
2920
3074
  const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
2921
3075
  const outerOperationId = `ai.${operation}`;
2922
3076
  const { operationName, resourceName } = opName(outerOperationId, telemetry == null ? void 0 : telemetry.functionId);
@@ -2932,17 +3086,17 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
2932
3086
  attrString("ai.telemetry.functionId", telemetry == null ? void 0 : telemetry.functionId),
2933
3087
  attrString("ai.model.provider", modelInfoFromArgs.provider),
2934
3088
  attrString("ai.model.id", modelInfoFromArgs.modelId),
3089
+ attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
3090
+ attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
3091
+ attrString("ai.telemetry.metadata.raindrop.userId", ctx.userId),
3092
+ attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
2935
3093
  ...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
2936
3094
  ...attrsFromHeaders(mergedArgs["headers"]),
2937
3095
  ...attrsFromSettings(mergedArgs),
2938
3096
  ...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [
2939
3097
  attrString(
2940
3098
  "ai.prompt",
2941
- safeJsonWithUint8({
2942
- system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"],
2943
- prompt: mergedArgs["prompt"],
2944
- messages: mergedArgs["messages"]
2945
- })
3099
+ safeJsonWithUint8(normalizePromptAttr({ system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"], prompt: mergedArgs["prompt"], messages: mergedArgs["messages"] }))
2946
3100
  )
2947
3101
  ]
2948
3102
  ]
@@ -2950,6 +3104,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
2950
3104
  const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
2951
3105
  const wrapCtx = {
2952
3106
  eventId,
3107
+ context: ctx,
2953
3108
  telemetry,
2954
3109
  sendTraces,
2955
3110
  debug,
@@ -3123,7 +3278,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
3123
3278
  if (!mergedCtx.userId) warnMissingUserIdOnce();
3124
3279
  const inherited = await getCurrentParentSpanContext();
3125
3280
  const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
3126
- const ctx = { ...mergedCtx};
3281
+ const ctx = { ...mergedCtx, eventId };
3127
3282
  const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
3128
3283
  const outerOperationId = `ai.${operation}`;
3129
3284
  const { operationName, resourceName } = opName(outerOperationId, telemetry == null ? void 0 : telemetry.functionId);
@@ -3139,17 +3294,17 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
3139
3294
  attrString("ai.telemetry.functionId", telemetry == null ? void 0 : telemetry.functionId),
3140
3295
  attrString("ai.model.provider", modelInfoFromArgs.provider),
3141
3296
  attrString("ai.model.id", modelInfoFromArgs.modelId),
3297
+ attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
3298
+ attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
3299
+ attrString("ai.telemetry.metadata.raindrop.userId", ctx.userId),
3300
+ attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
3142
3301
  ...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
3143
3302
  ...attrsFromHeaders(mergedArgs["headers"]),
3144
3303
  ...attrsFromSettings(mergedArgs),
3145
3304
  ...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [
3146
3305
  attrString(
3147
3306
  "ai.prompt",
3148
- safeJsonWithUint8({
3149
- system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"],
3150
- prompt: mergedArgs["prompt"],
3151
- messages: mergedArgs["messages"]
3152
- })
3307
+ safeJsonWithUint8(normalizePromptAttr({ system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"], prompt: mergedArgs["prompt"], messages: mergedArgs["messages"] }))
3153
3308
  )
3154
3309
  ]
3155
3310
  ]
@@ -3157,6 +3312,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
3157
3312
  const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
3158
3313
  const wrapCtx = {
3159
3314
  eventId,
3315
+ context: ctx,
3160
3316
  telemetry,
3161
3317
  sendTraces,
3162
3318
  debug,
@@ -3380,6 +3536,21 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
3380
3536
  });
3381
3537
  }
3382
3538
  };
3539
+ const sendToolLiveEvent = (parent, type, metadata) => {
3540
+ if (!localDebuggerEnabled() || !parent) return;
3541
+ sendLocalDebuggerLiveEvent({
3542
+ traceId: parent.traceIdB64,
3543
+ type,
3544
+ content: name,
3545
+ metadata: {
3546
+ ...getLocalDebuggerMetadata({
3547
+ ...ctx.context,
3548
+ eventId: ctx.eventId
3549
+ }),
3550
+ ...metadata
3551
+ }
3552
+ });
3553
+ };
3383
3554
  const createContextSpan = (span) => ({
3384
3555
  traceIdB64: span.ids.traceIdB64,
3385
3556
  spanIdB64: span.ids.spanIdB64,
@@ -3395,6 +3566,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
3395
3566
  const parentCtx = await getCurrentParentSpanContext();
3396
3567
  const parent = parentCtx && parentCtx.eventId === ctx.eventId ? { traceIdB64: parentCtx.traceIdB64, spanIdB64: parentCtx.spanIdB64 } : ctx.rootParentForChildren;
3397
3568
  const toolSpan = createToolSpan(toolCallId, toolArgs, parent);
3569
+ sendToolLiveEvent(parent, "tool_start", { args: toolArgs });
3398
3570
  try {
3399
3571
  let lastValue;
3400
3572
  const iterator = result[Symbol.asyncIterator]();
@@ -3410,9 +3582,13 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
3410
3582
  }
3411
3583
  toolCalls.push({ id: toolCallId, name, args: toolArgs, result: lastValue, status: "OK" });
3412
3584
  endToolSpan(toolSpan, lastValue);
3585
+ sendToolLiveEvent(parent, "tool_result", { result: lastValue });
3413
3586
  } catch (error) {
3414
3587
  toolCalls.push({ id: toolCallId, name, args: toolArgs, status: "ERROR" });
3415
3588
  endToolSpan(toolSpan, void 0, error);
3589
+ sendToolLiveEvent(parent, "tool_result", {
3590
+ error: error instanceof Error ? error.message : String(error)
3591
+ });
3416
3592
  throw error;
3417
3593
  }
3418
3594
  })();
@@ -3421,6 +3597,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
3421
3597
  const parentCtx = await getCurrentParentSpanContext();
3422
3598
  const parent = parentCtx && parentCtx.eventId === ctx.eventId ? { traceIdB64: parentCtx.traceIdB64, spanIdB64: parentCtx.spanIdB64 } : ctx.rootParentForChildren;
3423
3599
  const toolSpan = createToolSpan(toolCallId, toolArgs, parent);
3600
+ sendToolLiveEvent(parent, "tool_start", { args: toolArgs });
3424
3601
  const run = async () => {
3425
3602
  try {
3426
3603
  const awaitedResult = await result;
@@ -3432,10 +3609,14 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
3432
3609
  status: "OK"
3433
3610
  });
3434
3611
  endToolSpan(toolSpan, awaitedResult);
3612
+ sendToolLiveEvent(parent, "tool_result", { result: awaitedResult });
3435
3613
  return awaitedResult;
3436
3614
  } catch (error) {
3437
3615
  toolCalls.push({ id: toolCallId, name, args: toolArgs, status: "ERROR" });
3438
3616
  endToolSpan(toolSpan, void 0, error);
3617
+ sendToolLiveEvent(parent, "tool_result", {
3618
+ error: error instanceof Error ? error.message : String(error)
3619
+ });
3439
3620
  throw error;
3440
3621
  }
3441
3622
  };
@@ -3475,6 +3656,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
3475
3656
  const original = Reflect.get(target, prop, receiver);
3476
3657
  if (prop === "doGenerate" && isFunction(original)) {
3477
3658
  return async (...callArgs) => {
3659
+ var _a, _b;
3478
3660
  const options = callArgs[0];
3479
3661
  const parentCtx = await getCurrentParentSpanContext();
3480
3662
  const parent = parentCtx && parentCtx.eventId === ctx.eventId ? { traceIdB64: parentCtx.traceIdB64, spanIdB64: parentCtx.spanIdB64 } : ctx.rootParentForChildren;
@@ -3482,6 +3664,22 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
3482
3664
  try {
3483
3665
  const result = await original.apply(target, callArgs);
3484
3666
  if (span) endDoGenerateSpan(span, result, modelInfo, ctx);
3667
+ if (localDebuggerEnabled() && ctx.rootParentForChildren && isRecord(result)) {
3668
+ const traceId = ctx.rootParentForChildren.traceIdB64;
3669
+ const liveMeta = getLocalDebuggerMetadata({ ...ctx.context, eventId: ctx.eventId });
3670
+ const content = result["content"];
3671
+ if (Array.isArray(content)) {
3672
+ for (const part of content) {
3673
+ if (isRecord(part)) {
3674
+ if ((part["type"] === "reasoning" || part["type"] === "thinking") && typeof ((_a = part["text"]) != null ? _a : part["thinking"]) === "string") {
3675
+ sendLocalDebuggerLiveEvent({ traceId, type: "reasoning_delta", content: (_b = part["text"]) != null ? _b : part["thinking"], metadata: liveMeta });
3676
+ } else if (part["type"] === "text" && typeof part["text"] === "string") {
3677
+ sendLocalDebuggerLiveEvent({ traceId, type: "text_delta", content: part["text"], metadata: liveMeta });
3678
+ }
3679
+ }
3680
+ }
3681
+ }
3682
+ }
3485
3683
  return result;
3486
3684
  } catch (error) {
3487
3685
  if (span)
@@ -3621,6 +3819,23 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
3621
3819
  }
3622
3820
  if ("usage" in value) usage = value["usage"];
3623
3821
  if ("providerMetadata" in value) providerMetadata = value["providerMetadata"];
3822
+ if (localDebuggerEnabled() && ctx.rootParentForChildren) {
3823
+ const traceId = ctx.rootParentForChildren.traceIdB64;
3824
+ const liveMeta = getLocalDebuggerMetadata({ ...ctx.context, eventId: ctx.eventId });
3825
+ if (type === "text-delta") {
3826
+ const text = typeof value["delta"] === "string" ? value["delta"] : typeof value["textDelta"] === "string" ? value["textDelta"] : typeof value["text"] === "string" ? value["text"] : void 0;
3827
+ if (typeof text === "string" && text) sendLocalDebuggerLiveEvent({ traceId, type: "text_delta", content: text, metadata: liveMeta });
3828
+ } else if (type === "reasoning" || type === "reasoning-delta") {
3829
+ const text = typeof value["delta"] === "string" ? value["delta"] : typeof value["text"] === "string" ? value["text"] : typeof value["thinking"] === "string" ? value["thinking"] : void 0;
3830
+ if (typeof text === "string" && text) sendLocalDebuggerLiveEvent({ traceId, type: "reasoning_delta", content: text, metadata: liveMeta });
3831
+ } else if (type === "tool-call") {
3832
+ const toolName = typeof value["toolName"] === "string" ? value["toolName"] : "tool";
3833
+ sendLocalDebuggerLiveEvent({ traceId, type: "tool_start", content: toolName, metadata: { ...liveMeta, args: value["args"] } });
3834
+ } else if (type === "tool-result") {
3835
+ const toolName = typeof value["toolName"] === "string" ? value["toolName"] : "tool";
3836
+ sendLocalDebuggerLiveEvent({ traceId, type: "tool_result", content: toolName, metadata: { ...liveMeta, result: value["result"] } });
3837
+ }
3838
+ }
3624
3839
  }
3625
3840
  controller.enqueue(value);
3626
3841
  } catch (error) {
@@ -1,4 +1,4 @@
1
- export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-DGziajf_.mjs';
1
+ export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-CPArLupC.mjs';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -1,4 +1,4 @@
1
- export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-DGziajf_.js';
1
+ export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-CPArLupC.js';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {