@raindrop-ai/ai-sdk 0.0.25 → 0.0.27

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-4UCYIEH4.js
1
+ // ../core/dist/chunk-LMIWKHOH.js
2
2
  function getCrypto() {
3
3
  const c = globalThis.crypto;
4
4
  return c;
@@ -468,29 +468,70 @@ var EventShipper = class {
468
468
  }
469
469
  };
470
470
  var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
471
+ var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
472
+ var DEFAULT_LOCAL_WORKSHOP_URL = "http://localhost:5899/v1/";
473
+ function readEnvVar(name) {
474
+ var _a;
475
+ try {
476
+ const env = (_a = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : _a.env;
477
+ if (env && typeof env[name] === "string" && env[name].length > 0) {
478
+ return env[name];
479
+ }
480
+ } catch (e) {
481
+ }
482
+ return void 0;
483
+ }
484
+ function readWorkshopEnv() {
485
+ const raw = readEnvVar(WORKSHOP_ENV_VAR);
486
+ if (raw === void 0) return void 0;
487
+ const trimmed = raw.trim();
488
+ if (trimmed.length === 0) return void 0;
489
+ if (/^https?:\/\//i.test(trimmed)) return { url: trimmed };
490
+ if (/^(1|true|yes|on)$/i.test(trimmed)) return "enable";
491
+ if (/^(0|false|no|off)$/i.test(trimmed)) return "disable";
492
+ return void 0;
493
+ }
494
+ function isLocalDevHost(hostname) {
495
+ if (!hostname) return false;
496
+ if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "::1") {
497
+ return true;
498
+ }
499
+ if (hostname.endsWith(".localhost")) return true;
500
+ return false;
501
+ }
502
+ function readRuntimeHostname() {
503
+ try {
504
+ const loc = globalThis == null ? void 0 : globalThis.location;
505
+ if (loc && typeof loc.hostname === "string" && loc.hostname.length > 0) {
506
+ return loc.hostname;
507
+ }
508
+ } catch (e) {
509
+ }
510
+ return void 0;
511
+ }
512
+ function shouldAutoEnableLocalWorkshop() {
513
+ if (isLocalDevHost(readRuntimeHostname())) return true;
514
+ if (readEnvVar("NODE_ENV") === "development") return true;
515
+ return false;
516
+ }
471
517
  function resolveLocalDebuggerBaseUrl(baseUrl) {
472
518
  var _a, _b, _c;
473
- 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;
474
- return resolved ? (_c = formatEndpoint(resolved)) != null ? _c : null : null;
519
+ if (baseUrl === null) return null;
520
+ if (typeof baseUrl === "string" && baseUrl.length > 0) {
521
+ return (_a = formatEndpoint(baseUrl)) != null ? _a : null;
522
+ }
523
+ const explicitUrlEnv = readEnvVar(LOCAL_DEBUGGER_ENV_VAR);
524
+ if (explicitUrlEnv) return (_b = formatEndpoint(explicitUrlEnv)) != null ? _b : null;
525
+ const workshopEnv = readWorkshopEnv();
526
+ if (workshopEnv === "disable") return null;
527
+ if (workshopEnv === "enable") return DEFAULT_LOCAL_WORKSHOP_URL;
528
+ if (workshopEnv && "url" in workshopEnv) return (_c = formatEndpoint(workshopEnv.url)) != null ? _c : null;
529
+ if (shouldAutoEnableLocalWorkshop()) return DEFAULT_LOCAL_WORKSHOP_URL;
530
+ return null;
475
531
  }
476
532
  function localDebuggerEnabled(baseUrl) {
477
533
  return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
478
534
  }
479
- function normalizeLocalDebuggerLiveEventType(type) {
480
- switch (type) {
481
- case "text-delta":
482
- return "text_delta";
483
- case "reasoning":
484
- case "reasoning-delta":
485
- return "reasoning_delta";
486
- case "tool-call":
487
- return "tool_start";
488
- case "tool-result":
489
- return "tool_result";
490
- default:
491
- return type;
492
- }
493
- }
494
535
  function mirrorTraceExportToLocalDebugger(body, options = {}) {
495
536
  var _a;
496
537
  const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
@@ -510,7 +551,7 @@ function sendLocalDebuggerLiveEvent(event, options = {}) {
510
551
  `${baseUrl}live`,
511
552
  {
512
553
  ...event,
513
- type: normalizeLocalDebuggerLiveEventType(event.type),
554
+ type: event.type,
514
555
  timestamp: (_a = event.timestamp) != null ? _a : Date.now()
515
556
  },
516
557
  {},
@@ -526,7 +567,7 @@ var TraceShipper = class {
526
567
  constructor(opts) {
527
568
  this.queue = [];
528
569
  this.inFlight = /* @__PURE__ */ new Set();
529
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
570
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
530
571
  this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
531
572
  this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
532
573
  this.enabled = opts.enabled !== false;
@@ -539,12 +580,9 @@ var TraceShipper = class {
539
580
  this.prefix = `[raindrop-ai/${this.sdkName}]`;
540
581
  this.serviceName = (_g = opts.serviceName) != null ? _g : "raindrop.core";
541
582
  this.serviceVersion = (_h = opts.serviceVersion) != null ? _h : "0.0.0";
542
- const localDebugger = typeof process !== "undefined" ? (_i = process.env) == null ? void 0 : _i.RAINDROP_LOCAL_DEBUGGER : void 0;
543
- if (localDebugger) {
544
- this.localDebuggerUrl = (_j = resolveLocalDebuggerBaseUrl(localDebugger)) != null ? _j : void 0;
545
- if (this.debug) {
546
- console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
547
- }
583
+ this.localDebuggerUrl = (_i = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _i : void 0;
584
+ if (this.debug && this.localDebuggerUrl) {
585
+ console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
548
586
  }
549
587
  }
550
588
  isDebugEnabled() {
@@ -830,7 +868,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
830
868
  // package.json
831
869
  var package_default = {
832
870
  name: "@raindrop-ai/ai-sdk",
833
- version: "0.0.25"};
871
+ version: "0.0.27"};
834
872
 
835
873
  // src/internal/version.ts
836
874
  var libraryName = package_default.name;
@@ -1470,6 +1508,77 @@ function attrsFromGenAiRequest(options) {
1470
1508
  ];
1471
1509
  }
1472
1510
 
1511
+ // src/internal/call-metadata.ts
1512
+ var SyncFallbackStorage = class {
1513
+ constructor() {
1514
+ this._stack = [];
1515
+ }
1516
+ getStore() {
1517
+ return this._stack[this._stack.length - 1];
1518
+ }
1519
+ run(store, callback) {
1520
+ this._stack.push(store);
1521
+ try {
1522
+ return callback();
1523
+ } finally {
1524
+ this._stack.pop();
1525
+ }
1526
+ }
1527
+ };
1528
+ var _storage = null;
1529
+ function getStorage() {
1530
+ if (_storage) return _storage;
1531
+ const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
1532
+ _storage = Ctor ? new Ctor() : new SyncFallbackStorage();
1533
+ return _storage;
1534
+ }
1535
+ function _resetRaindropCallMetadataStorage() {
1536
+ _storage = null;
1537
+ }
1538
+ function getCurrentRaindropCallMetadata() {
1539
+ return getStorage().getStore();
1540
+ }
1541
+ function runWithRaindropCallMetadata(metadata, fn) {
1542
+ return getStorage().run(metadata, fn);
1543
+ }
1544
+ function readRaindropCallMetadataFromArgs(args) {
1545
+ var _a;
1546
+ if (args.length === 0) return void 0;
1547
+ const first = args[0];
1548
+ if (!isRecord(first)) return void 0;
1549
+ const topLevel = isRecord(first["metadata"]) ? first["metadata"] : void 0;
1550
+ const stable = isRecord(first["telemetry"]) ? first["telemetry"]["metadata"] : void 0;
1551
+ const stableMetadata = isRecord(stable) ? stable : void 0;
1552
+ const exp = extractExperimentalTelemetry(first);
1553
+ const expMetadata = (exp == null ? void 0 : exp.metadata) && typeof exp.metadata === "object" ? exp.metadata : void 0;
1554
+ const raw = (_a = topLevel != null ? topLevel : stableMetadata) != null ? _a : expMetadata;
1555
+ if (!raw) return void 0;
1556
+ const meta = { rawMetadata: raw };
1557
+ const userId = raw["raindrop.userId"];
1558
+ if (typeof userId === "string" && userId) meta.userId = userId;
1559
+ const eventId = raw["raindrop.eventId"];
1560
+ if (typeof eventId === "string" && eventId) meta.eventId = eventId;
1561
+ const eventIdGenerated = raw["raindrop.internal.eventIdGenerated"];
1562
+ if (eventIdGenerated === true || eventIdGenerated === "true" || eventIdGenerated === "1") {
1563
+ meta.eventIdGenerated = true;
1564
+ }
1565
+ const convoId = raw["raindrop.convoId"];
1566
+ if (typeof convoId === "string" && convoId) meta.convoId = convoId;
1567
+ const eventName = raw["raindrop.eventName"];
1568
+ if (typeof eventName === "string" && eventName) meta.eventName = eventName;
1569
+ const properties = raw["raindrop.properties"];
1570
+ if (typeof properties === "string") {
1571
+ try {
1572
+ const parsed = JSON.parse(properties);
1573
+ if (parsed && typeof parsed === "object") meta.properties = parsed;
1574
+ } catch (e) {
1575
+ }
1576
+ } else if (properties && typeof properties === "object") {
1577
+ meta.properties = properties;
1578
+ }
1579
+ return meta;
1580
+ }
1581
+
1473
1582
  // src/internal/raindrop-telemetry-integration.ts
1474
1583
  var RaindropTelemetryIntegration = class {
1475
1584
  constructor(opts) {
@@ -1477,15 +1586,17 @@ var RaindropTelemetryIntegration = class {
1477
1586
  // ── onStart ─────────────────────────────────────────────────────────────
1478
1587
  this.onStart = (event) => {
1479
1588
  var _a, _b, _c, _d;
1480
- if (event.isEnabled !== true) return;
1589
+ if (event.isEnabled === false) return;
1481
1590
  const isEmbed = event.operationId === "ai.embed" || event.operationId === "ai.embedMany";
1482
1591
  const recordInputs = event.recordInputs !== false;
1483
1592
  const recordOutputs = event.recordOutputs !== false;
1484
1593
  const functionId = event.functionId;
1485
- const metadata = event.metadata;
1594
+ const eventMetadata2 = event.metadata;
1595
+ const callContextMetadata = getCurrentRaindropCallMetadata();
1596
+ const metadata = eventMetadata2 != null ? eventMetadata2 : callContextMetadata == null ? void 0 : callContextMetadata.rawMetadata;
1486
1597
  const callMeta = this.extractRaindropMetadata(metadata);
1487
1598
  const inherited = getContextManager().getParentSpanIds();
1488
- const eventIdGenerated = (metadata == null ? void 0 : metadata["raindrop.internal.eventIdGenerated"]) === "true" || (metadata == null ? void 0 : metadata["raindrop.internal.eventIdGenerated"]) === true;
1599
+ 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;
1489
1600
  const explicitEventId = callMeta.eventId && !eventIdGenerated ? callMeta.eventId : void 0;
1490
1601
  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();
1491
1602
  const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
@@ -1611,48 +1722,25 @@ var RaindropTelemetryIntegration = class {
1611
1722
  state.stepSpan = stepSpan;
1612
1723
  state.stepParent = this.spanParentRef(stepSpan);
1613
1724
  };
1614
- // ── onToolCallStart ─────────────────────────────────────────────────────
1615
- this.onToolCallStart = (event) => {
1616
- const state = this.getState(event.callId);
1617
- if (!(state == null ? void 0 : state.stepParent)) return;
1618
- const { toolCall } = event;
1619
- const { operationName, resourceName } = opName(
1620
- "ai.toolCall",
1621
- state.functionId
1622
- );
1623
- const inputAttrs = state.recordInputs ? [attrString("ai.toolCall.args", safeJsonWithUint8(toolCall.input))] : [];
1624
- const toolSpan = this.traceShipper.startSpan({
1625
- name: "ai.toolCall",
1626
- parent: state.stepParent,
1627
- eventId: state.eventId,
1628
- operationId: "ai.toolCall",
1629
- attributes: [
1630
- attrString("operation.name", operationName),
1631
- attrString("resource.name", resourceName),
1632
- attrString("ai.telemetry.functionId", state.functionId),
1633
- attrString("ai.toolCall.name", toolCall.toolName),
1634
- attrString("ai.toolCall.id", toolCall.toolCallId),
1635
- ...inputAttrs
1636
- ]
1637
- });
1638
- state.toolSpans.set(toolCall.toolCallId, toolSpan);
1639
- this.emitLive(state, "tool_start", toolCall.toolName, { args: toolCall.input });
1725
+ this.onToolExecutionStart = (event) => this.toolExecutionStart(event);
1726
+ this.onToolExecutionEnd = (event) => this.toolExecutionEnd(event);
1727
+ // Older v7 betas (< beta.111) emit these names. Kept as thin aliases so
1728
+ // applications pinned to those betas continue to work.
1729
+ this.onToolCallStart = (event) => this.toolExecutionStart(event);
1730
+ this.onToolCallFinish = (event) => this.toolExecutionEnd(event);
1731
+ // ── language-model call (v7 beta.111+) ─────────────────────────────────
1732
+ //
1733
+ // `onLanguageModelCallStart` / `onLanguageModelCallEnd` are scoped to the
1734
+ // model invocation only and exclude later client-side tool execution.
1735
+ // Raindrop already spans at the operation + step level, so these are
1736
+ // intentional no-ops — declared so the dispatcher's `mergeCallbacks` sees
1737
+ // them and so we don't accidentally rely on them later.
1738
+ //
1739
+ // Defined as no-ops rather than omitted so adding logic here later is a
1740
+ // strictly additive change.
1741
+ this.onLanguageModelCallStart = (_event) => {
1640
1742
  };
1641
- // ── onToolCallFinish ────────────────────────────────────────────────────
1642
- this.onToolCallFinish = (event) => {
1643
- const state = this.getState(event.callId);
1644
- if (!state) return;
1645
- const toolSpan = state.toolSpans.get(event.toolCall.toolCallId);
1646
- if (!toolSpan) return;
1647
- state.toolCallCount += 1;
1648
- if (event.success) {
1649
- const outputAttrs = state.recordOutputs ? [attrString("ai.toolCall.result", safeJsonWithUint8(event.output))] : [];
1650
- this.traceShipper.endSpan(toolSpan, { attributes: outputAttrs });
1651
- } else {
1652
- this.traceShipper.endSpan(toolSpan, { error: event.error });
1653
- }
1654
- this.emitLive(state, "tool_result", event.toolCall.toolName);
1655
- state.toolSpans.delete(event.toolCall.toolCallId);
1743
+ this.onLanguageModelCallEnd = (_event) => {
1656
1744
  };
1657
1745
  // ── onChunk (streaming) ─────────────────────────────────────────────────
1658
1746
  this.onChunk = (event) => {
@@ -1921,6 +2009,53 @@ var RaindropTelemetryIntegration = class {
1921
2009
  }
1922
2010
  return void 0;
1923
2011
  }
2012
+ // ── tool execution start / end ──────────────────────────────────────────
2013
+ //
2014
+ // v7 < beta.111 dispatched `onToolCallStart` / `onToolCallFinish`.
2015
+ // v7 >= beta.111 renamed them to `onToolExecutionStart` / `onToolExecutionEnd`
2016
+ // (see https://github.com/vercel/ai/pull/14589). Event shape is identical.
2017
+ // Both names are exposed and forward to a single implementation.
2018
+ toolExecutionStart(event) {
2019
+ const state = this.getState(event.callId);
2020
+ if (!(state == null ? void 0 : state.stepParent)) return;
2021
+ const { toolCall } = event;
2022
+ const { operationName, resourceName } = opName(
2023
+ "ai.toolCall",
2024
+ state.functionId
2025
+ );
2026
+ const inputAttrs = state.recordInputs ? [attrString("ai.toolCall.args", safeJsonWithUint8(toolCall.input))] : [];
2027
+ const toolSpan = this.traceShipper.startSpan({
2028
+ name: "ai.toolCall",
2029
+ parent: state.stepParent,
2030
+ eventId: state.eventId,
2031
+ operationId: "ai.toolCall",
2032
+ attributes: [
2033
+ attrString("operation.name", operationName),
2034
+ attrString("resource.name", resourceName),
2035
+ attrString("ai.telemetry.functionId", state.functionId),
2036
+ attrString("ai.toolCall.name", toolCall.toolName),
2037
+ attrString("ai.toolCall.id", toolCall.toolCallId),
2038
+ ...inputAttrs
2039
+ ]
2040
+ });
2041
+ state.toolSpans.set(toolCall.toolCallId, toolSpan);
2042
+ this.emitLive(state, "tool_start", toolCall.toolName, { args: toolCall.input });
2043
+ }
2044
+ toolExecutionEnd(event) {
2045
+ const state = this.getState(event.callId);
2046
+ if (!state) return;
2047
+ const toolSpan = state.toolSpans.get(event.toolCall.toolCallId);
2048
+ if (!toolSpan) return;
2049
+ state.toolCallCount += 1;
2050
+ if (event.success) {
2051
+ const outputAttrs = state.recordOutputs ? [attrString("ai.toolCall.result", safeJsonWithUint8(event.output))] : [];
2052
+ this.traceShipper.endSpan(toolSpan, { attributes: outputAttrs });
2053
+ } else {
2054
+ this.traceShipper.endSpan(toolSpan, { error: event.error });
2055
+ }
2056
+ this.emitLive(state, "tool_result", event.toolCall.toolName);
2057
+ state.toolSpans.delete(event.toolCall.toolCallId);
2058
+ }
1924
2059
  finishGenerate(event, state) {
1925
2060
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1926
2061
  if (state.rootSpan) {
@@ -2248,7 +2383,16 @@ function detectAISDKVersion(aiSDK) {
2248
2383
  return "4";
2249
2384
  }
2250
2385
  function hasStructuredTelemetryEvents(aiSDK) {
2251
- return isRecord(aiSDK) && isFunction(aiSDK["registerTelemetryIntegration"]) && isFunction(aiSDK["experimental_streamModelCall"]);
2386
+ if (!isRecord(aiSDK)) return false;
2387
+ const hasRegister = isFunction(aiSDK["registerTelemetry"]) || isFunction(aiSDK["registerTelemetryIntegration"]);
2388
+ const hasV7Marker = isFunction(aiSDK["experimental_streamLanguageModelCall"]) || isFunction(aiSDK["experimental_streamModelCall"]);
2389
+ return hasRegister && hasV7Marker;
2390
+ }
2391
+ function resolveRegisterTelemetry(aiSDK) {
2392
+ var _a;
2393
+ if (!isRecord(aiSDK)) return void 0;
2394
+ const fn = (_a = aiSDK["registerTelemetry"]) != null ? _a : aiSDK["registerTelemetryIntegration"];
2395
+ return isFunction(fn) ? fn : void 0;
2252
2396
  }
2253
2397
  function asVercelSchema(jsonSchemaObj) {
2254
2398
  const validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
@@ -2889,31 +3033,44 @@ function wrapAISDK(aiSDK, deps) {
2889
3033
  properties: wrapTimeCtx.properties
2890
3034
  }
2891
3035
  });
2892
- const registerFn = aiSDK["registerTelemetryIntegration"];
2893
- if (isFunction(registerFn)) {
3036
+ const registerFn = resolveRegisterTelemetry(aiSDK);
3037
+ if (registerFn) {
2894
3038
  registerFn(integration);
2895
3039
  }
2896
3040
  if (debug) {
2897
- console.log("[raindrop-ai/ai-sdk] nativeTelemetry: registered RaindropTelemetryIntegration (no Proxy)");
3041
+ console.log(
3042
+ "[raindrop-ai/ai-sdk] nativeTelemetry: registered RaindropTelemetryIntegration (Proxy installed for per-call metadata propagation)"
3043
+ );
2898
3044
  }
2899
3045
  const selfDiagnostics2 = normalizeSelfDiagnosticsConfig(deps.options.selfDiagnostics);
2900
- if (selfDiagnostics2) {
2901
- const textOps = /* @__PURE__ */ new Set(["generateText", "streamText"]);
2902
- const jsonSchemaFactory = resolveJsonSchemaFactory(aiSDK);
2903
- const proxyTarget2 = isModuleNamespace(aiSDK) ? Object.setPrototypeOf({}, aiSDK) : aiSDK;
2904
- return new Proxy(proxyTarget2, {
2905
- get(target, prop, receiver) {
2906
- const original = Reflect.get(target, prop, receiver);
2907
- if (typeof prop !== "string" || !textOps.has(prop) || !isFunction(original)) {
2908
- return original;
2909
- }
2910
- return (...callArgs) => {
2911
- var _a2;
2912
- const arg = callArgs[0];
2913
- if (!isRecord(arg)) return original.call(aiSDK, ...callArgs);
3046
+ const jsonSchemaFactory = selfDiagnostics2 ? resolveJsonSchemaFactory(aiSDK) : void 0;
3047
+ const metadataAwareOps = /* @__PURE__ */ new Set([
3048
+ "generateText",
3049
+ "streamText",
3050
+ "generateObject",
3051
+ "streamObject",
3052
+ "embed",
3053
+ "embedMany",
3054
+ "rerank"
3055
+ ]);
3056
+ const selfDiagnosticsOps = /* @__PURE__ */ new Set(["generateText", "streamText"]);
3057
+ const proxyTarget2 = isModuleNamespace(aiSDK) ? Object.setPrototypeOf({}, aiSDK) : aiSDK;
3058
+ return new Proxy(proxyTarget2, {
3059
+ get(target, prop, receiver) {
3060
+ const original = Reflect.get(target, prop, receiver);
3061
+ if (typeof prop !== "string" || !metadataAwareOps.has(prop) || !isFunction(original)) {
3062
+ return original;
3063
+ }
3064
+ const propName = prop;
3065
+ return (...callArgs) => {
3066
+ var _a2, _b2, _c2;
3067
+ const arg = callArgs[0];
3068
+ const callMetadata = readRaindropCallMetadataFromArgs(callArgs);
3069
+ const callOriginal = () => original.call(aiSDK, ...callArgs);
3070
+ if (selfDiagnostics2 && selfDiagnosticsOps.has(propName) && isRecord(arg)) {
2914
3071
  const telemetry = extractExperimentalTelemetry(arg);
2915
3072
  const callMeta = (telemetry == null ? void 0 : telemetry.metadata) ? extractRaindropMetadata(telemetry.metadata) : {};
2916
- const perCallEventIdExplicit = (_a2 = callMeta.eventId) != null ? _a2 : wrapTimeCtx.eventId;
3073
+ const perCallEventIdExplicit = (_b2 = (_a2 = callMetadata == null ? void 0 : callMetadata.eventId) != null ? _a2 : callMeta.eventId) != null ? _b2 : wrapTimeCtx.eventId;
2917
3074
  const perCallEventId = perCallEventIdExplicit != null ? perCallEventIdExplicit : randomUUID();
2918
3075
  const perCallEventIdGenerated = !perCallEventIdExplicit;
2919
3076
  const perCallCtx = {
@@ -2950,12 +3107,25 @@ function wrapAISDK(aiSDK, deps) {
2950
3107
  metadata: mergedMetadata
2951
3108
  }
2952
3109
  };
2953
- return original.call(aiSDK, ...callArgs);
2954
- };
2955
- }
2956
- });
2957
- }
2958
- return aiSDK;
3110
+ const mergedAlsMetadata = {
3111
+ ...callMetadata != null ? callMetadata : {},
3112
+ eventId: perCallEventId,
3113
+ eventIdGenerated: perCallEventIdGenerated || (callMetadata == null ? void 0 : callMetadata.eventIdGenerated),
3114
+ rawMetadata: {
3115
+ ...(_c2 = callMetadata == null ? void 0 : callMetadata.rawMetadata) != null ? _c2 : {},
3116
+ "raindrop.eventId": perCallEventId,
3117
+ ...perCallEventIdGenerated ? { "raindrop.internal.eventIdGenerated": "true" } : {}
3118
+ }
3119
+ };
3120
+ return runWithRaindropCallMetadata(mergedAlsMetadata, callOriginal);
3121
+ }
3122
+ if (callMetadata) {
3123
+ return runWithRaindropCallMetadata(callMetadata, callOriginal);
3124
+ }
3125
+ return callOriginal();
3126
+ };
3127
+ }
3128
+ });
2959
3129
  }
2960
3130
  const instrumentedOps = /* @__PURE__ */ new Set([
2961
3131
  "generateText",
@@ -4110,6 +4280,7 @@ function createRaindropAISDK(opts) {
4110
4280
  debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
4111
4281
  partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
4112
4282
  });
4283
+ const localDebuggerUrl = opts.localWorkshopUrl === false ? null : opts.localWorkshopUrl;
4113
4284
  const traceShipper = new TraceShipper2({
4114
4285
  writeKey,
4115
4286
  endpoint: opts.endpoint,
@@ -4118,7 +4289,8 @@ function createRaindropAISDK(opts) {
4118
4289
  debugSpans: ((_f = opts.traces) == null ? void 0 : _f.debugSpans) === true || envDebug,
4119
4290
  flushIntervalMs: (_g = opts.traces) == null ? void 0 : _g.flushIntervalMs,
4120
4291
  maxBatchSize: (_h = opts.traces) == null ? void 0 : _h.maxBatchSize,
4121
- maxQueueSize: (_i = opts.traces) == null ? void 0 : _i.maxQueueSize
4292
+ maxQueueSize: (_i = opts.traces) == null ? void 0 : _i.maxQueueSize,
4293
+ localDebuggerUrl
4122
4294
  });
4123
4295
  return {
4124
4296
  wrap(aiSDK, options) {
@@ -4241,4 +4413,4 @@ function createRaindropAISDK(opts) {
4241
4413
  };
4242
4414
  }
4243
4415
 
4244
- export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent };
4416
+ export { RaindropTelemetryIntegration, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentRaindropCallMetadata, readRaindropCallMetadataFromArgs, runWithRaindropCallMetadata, withCurrent };
@@ -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, g as CreateSpanArgs, E as EndSpanArgs, h as EventBuilder, i as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, j as RaindropAISDKContext, k as RaindropAISDKOptions, l as RaindropTelemetryIntegration, m as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, n as SelfDiagnosticsSignalDefinition, o as SelfDiagnosticsSignalDefinitions, p as StartSpanArgs, T as TraceSpan, W as WrapAISDKOptions, q as WrappedAI, r as WrappedAISDK, _ as _resetWarnedMissingUserId, s as createRaindropAISDK, t as currentSpan, u as eventMetadata, v as eventMetadataFromChatRequest, w as getContextManager, x as withCurrent } from './index-sxjvhkYW.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, g as CreateSpanArgs, E as EndSpanArgs, h as EventBuilder, i as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, j as RaindropAISDKContext, k as RaindropAISDKOptions, l as RaindropCallMetadata, m as RaindropTelemetryIntegration, n as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, o as SelfDiagnosticsSignalDefinition, p as SelfDiagnosticsSignalDefinitions, q as StartSpanArgs, T as TraceSpan, W as WrapAISDKOptions, r as WrappedAI, s as WrappedAISDK, _ as _resetRaindropCallMetadataStorage, t as _resetWarnedMissingUserId, u as createRaindropAISDK, v as currentSpan, w as eventMetadata, x as eventMetadataFromChatRequest, y as getContextManager, z as getCurrentRaindropCallMetadata, D as readRaindropCallMetadataFromArgs, F as runWithRaindropCallMetadata, G as withCurrent } from './index-TERu6zvv.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, g as CreateSpanArgs, E as EndSpanArgs, h as EventBuilder, i as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, j as RaindropAISDKContext, k as RaindropAISDKOptions, l as RaindropTelemetryIntegration, m as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, n as SelfDiagnosticsSignalDefinition, o as SelfDiagnosticsSignalDefinitions, p as StartSpanArgs, T as TraceSpan, W as WrapAISDKOptions, q as WrappedAI, r as WrappedAISDK, _ as _resetWarnedMissingUserId, s as createRaindropAISDK, t as currentSpan, u as eventMetadata, v as eventMetadataFromChatRequest, w as getContextManager, x as withCurrent } from './index-sxjvhkYW.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, g as CreateSpanArgs, E as EndSpanArgs, h as EventBuilder, i as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, j as RaindropAISDKContext, k as RaindropAISDKOptions, l as RaindropCallMetadata, m as RaindropTelemetryIntegration, n as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, o as SelfDiagnosticsSignalDefinition, p as SelfDiagnosticsSignalDefinitions, q as StartSpanArgs, T as TraceSpan, W as WrapAISDKOptions, r as WrappedAI, s as WrappedAISDK, _ as _resetRaindropCallMetadataStorage, t as _resetWarnedMissingUserId, u as createRaindropAISDK, v as currentSpan, w as eventMetadata, x as eventMetadataFromChatRequest, y as getContextManager, z as getCurrentRaindropCallMetadata, D as readRaindropCallMetadataFromArgs, F as runWithRaindropCallMetadata, G as withCurrent } from './index-TERu6zvv.js';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {