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