@raindrop-ai/ai-sdk 0.0.24 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -4
- package/dist/{chunk-WHP2SVAR.mjs → chunk-76JSTQY3.mjs} +208 -91
- package/dist/{index-sxjvhkYW.d.mts → index-7aDHuHHR.d.mts} +70 -11
- package/dist/{index-sxjvhkYW.d.ts → index-7aDHuHHR.d.ts} +70 -11
- package/dist/index.browser.d.mts +70 -11
- package/dist/index.browser.d.ts +70 -11
- package/dist/index.browser.js +211 -90
- package/dist/index.browser.mjs +208 -91
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +211 -90
- package/dist/index.node.mjs +1 -1
- package/dist/index.workers.d.mts +1 -1
- package/dist/index.workers.d.ts +1 -1
- package/dist/index.workers.js +211 -90
- package/dist/index.workers.mjs +1 -1
- package/package.json +1 -1
package/dist/index.workers.js
CHANGED
|
@@ -4,7 +4,7 @@ var async_hooks = require('async_hooks');
|
|
|
4
4
|
|
|
5
5
|
// src/index.workers.ts
|
|
6
6
|
|
|
7
|
-
// ../core/dist/chunk-
|
|
7
|
+
// ../core/dist/chunk-Y7SM66SW.js
|
|
8
8
|
function getCrypto() {
|
|
9
9
|
const c = globalThis.crypto;
|
|
10
10
|
return c;
|
|
@@ -482,21 +482,6 @@ function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
|
482
482
|
function localDebuggerEnabled(baseUrl) {
|
|
483
483
|
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
484
484
|
}
|
|
485
|
-
function normalizeLocalDebuggerLiveEventType(type) {
|
|
486
|
-
switch (type) {
|
|
487
|
-
case "text-delta":
|
|
488
|
-
return "text_delta";
|
|
489
|
-
case "reasoning":
|
|
490
|
-
case "reasoning-delta":
|
|
491
|
-
return "reasoning_delta";
|
|
492
|
-
case "tool-call":
|
|
493
|
-
return "tool_start";
|
|
494
|
-
case "tool-result":
|
|
495
|
-
return "tool_result";
|
|
496
|
-
default:
|
|
497
|
-
return type;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
485
|
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
501
486
|
var _a;
|
|
502
487
|
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
@@ -516,7 +501,7 @@ function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
|
516
501
|
`${baseUrl}live`,
|
|
517
502
|
{
|
|
518
503
|
...event,
|
|
519
|
-
type:
|
|
504
|
+
type: event.type,
|
|
520
505
|
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
521
506
|
},
|
|
522
507
|
{},
|
|
@@ -837,7 +822,7 @@ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
|
|
|
837
822
|
// package.json
|
|
838
823
|
var package_default = {
|
|
839
824
|
name: "@raindrop-ai/ai-sdk",
|
|
840
|
-
version: "0.0.
|
|
825
|
+
version: "0.0.26"};
|
|
841
826
|
|
|
842
827
|
// src/internal/version.ts
|
|
843
828
|
var libraryName = package_default.name;
|
|
@@ -1477,6 +1462,77 @@ function attrsFromGenAiRequest(options) {
|
|
|
1477
1462
|
];
|
|
1478
1463
|
}
|
|
1479
1464
|
|
|
1465
|
+
// src/internal/call-metadata.ts
|
|
1466
|
+
var SyncFallbackStorage = class {
|
|
1467
|
+
constructor() {
|
|
1468
|
+
this._stack = [];
|
|
1469
|
+
}
|
|
1470
|
+
getStore() {
|
|
1471
|
+
return this._stack[this._stack.length - 1];
|
|
1472
|
+
}
|
|
1473
|
+
run(store, callback) {
|
|
1474
|
+
this._stack.push(store);
|
|
1475
|
+
try {
|
|
1476
|
+
return callback();
|
|
1477
|
+
} finally {
|
|
1478
|
+
this._stack.pop();
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
var _storage = null;
|
|
1483
|
+
function getStorage() {
|
|
1484
|
+
if (_storage) return _storage;
|
|
1485
|
+
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
1486
|
+
_storage = Ctor ? new Ctor() : new SyncFallbackStorage();
|
|
1487
|
+
return _storage;
|
|
1488
|
+
}
|
|
1489
|
+
function _resetRaindropCallMetadataStorage() {
|
|
1490
|
+
_storage = null;
|
|
1491
|
+
}
|
|
1492
|
+
function getCurrentRaindropCallMetadata() {
|
|
1493
|
+
return getStorage().getStore();
|
|
1494
|
+
}
|
|
1495
|
+
function runWithRaindropCallMetadata(metadata, fn) {
|
|
1496
|
+
return getStorage().run(metadata, fn);
|
|
1497
|
+
}
|
|
1498
|
+
function readRaindropCallMetadataFromArgs(args) {
|
|
1499
|
+
var _a;
|
|
1500
|
+
if (args.length === 0) return void 0;
|
|
1501
|
+
const first = args[0];
|
|
1502
|
+
if (!isRecord(first)) return void 0;
|
|
1503
|
+
const topLevel = isRecord(first["metadata"]) ? first["metadata"] : void 0;
|
|
1504
|
+
const stable = isRecord(first["telemetry"]) ? first["telemetry"]["metadata"] : void 0;
|
|
1505
|
+
const stableMetadata = isRecord(stable) ? stable : void 0;
|
|
1506
|
+
const exp = extractExperimentalTelemetry(first);
|
|
1507
|
+
const expMetadata = (exp == null ? void 0 : exp.metadata) && typeof exp.metadata === "object" ? exp.metadata : void 0;
|
|
1508
|
+
const raw = (_a = topLevel != null ? topLevel : stableMetadata) != null ? _a : expMetadata;
|
|
1509
|
+
if (!raw) return void 0;
|
|
1510
|
+
const meta = { rawMetadata: raw };
|
|
1511
|
+
const userId = raw["raindrop.userId"];
|
|
1512
|
+
if (typeof userId === "string" && userId) meta.userId = userId;
|
|
1513
|
+
const eventId = raw["raindrop.eventId"];
|
|
1514
|
+
if (typeof eventId === "string" && eventId) meta.eventId = eventId;
|
|
1515
|
+
const eventIdGenerated = raw["raindrop.internal.eventIdGenerated"];
|
|
1516
|
+
if (eventIdGenerated === true || eventIdGenerated === "true" || eventIdGenerated === "1") {
|
|
1517
|
+
meta.eventIdGenerated = true;
|
|
1518
|
+
}
|
|
1519
|
+
const convoId = raw["raindrop.convoId"];
|
|
1520
|
+
if (typeof convoId === "string" && convoId) meta.convoId = convoId;
|
|
1521
|
+
const eventName = raw["raindrop.eventName"];
|
|
1522
|
+
if (typeof eventName === "string" && eventName) meta.eventName = eventName;
|
|
1523
|
+
const properties = raw["raindrop.properties"];
|
|
1524
|
+
if (typeof properties === "string") {
|
|
1525
|
+
try {
|
|
1526
|
+
const parsed = JSON.parse(properties);
|
|
1527
|
+
if (parsed && typeof parsed === "object") meta.properties = parsed;
|
|
1528
|
+
} catch (e) {
|
|
1529
|
+
}
|
|
1530
|
+
} else if (properties && typeof properties === "object") {
|
|
1531
|
+
meta.properties = properties;
|
|
1532
|
+
}
|
|
1533
|
+
return meta;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1480
1536
|
// src/internal/raindrop-telemetry-integration.ts
|
|
1481
1537
|
var RaindropTelemetryIntegration = class {
|
|
1482
1538
|
constructor(opts) {
|
|
@@ -1484,15 +1540,17 @@ var RaindropTelemetryIntegration = class {
|
|
|
1484
1540
|
// ── onStart ─────────────────────────────────────────────────────────────
|
|
1485
1541
|
this.onStart = (event) => {
|
|
1486
1542
|
var _a, _b, _c, _d;
|
|
1487
|
-
if (event.isEnabled
|
|
1543
|
+
if (event.isEnabled === false) return;
|
|
1488
1544
|
const isEmbed = event.operationId === "ai.embed" || event.operationId === "ai.embedMany";
|
|
1489
1545
|
const recordInputs = event.recordInputs !== false;
|
|
1490
1546
|
const recordOutputs = event.recordOutputs !== false;
|
|
1491
1547
|
const functionId = event.functionId;
|
|
1492
|
-
const
|
|
1548
|
+
const eventMetadata2 = event.metadata;
|
|
1549
|
+
const callContextMetadata = getCurrentRaindropCallMetadata();
|
|
1550
|
+
const metadata = eventMetadata2 != null ? eventMetadata2 : callContextMetadata == null ? void 0 : callContextMetadata.rawMetadata;
|
|
1493
1551
|
const callMeta = this.extractRaindropMetadata(metadata);
|
|
1494
1552
|
const inherited = getContextManager().getParentSpanIds();
|
|
1495
|
-
const eventIdGenerated = (metadata == null ? void 0 : metadata["raindrop.internal.eventIdGenerated"]) === "true" || (metadata == null ? void 0 : metadata["raindrop.internal.eventIdGenerated"]) === true;
|
|
1553
|
+
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;
|
|
1496
1554
|
const explicitEventId = callMeta.eventId && !eventIdGenerated ? callMeta.eventId : void 0;
|
|
1497
1555
|
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();
|
|
1498
1556
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
@@ -1618,48 +1676,25 @@ var RaindropTelemetryIntegration = class {
|
|
|
1618
1676
|
state.stepSpan = stepSpan;
|
|
1619
1677
|
state.stepParent = this.spanParentRef(stepSpan);
|
|
1620
1678
|
};
|
|
1621
|
-
|
|
1622
|
-
this.
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
attrString("resource.name", resourceName),
|
|
1639
|
-
attrString("ai.telemetry.functionId", state.functionId),
|
|
1640
|
-
attrString("ai.toolCall.name", toolCall.toolName),
|
|
1641
|
-
attrString("ai.toolCall.id", toolCall.toolCallId),
|
|
1642
|
-
...inputAttrs
|
|
1643
|
-
]
|
|
1644
|
-
});
|
|
1645
|
-
state.toolSpans.set(toolCall.toolCallId, toolSpan);
|
|
1646
|
-
this.emitLive(state, "tool_start", toolCall.toolName, { args: toolCall.input });
|
|
1679
|
+
this.onToolExecutionStart = (event) => this.toolExecutionStart(event);
|
|
1680
|
+
this.onToolExecutionEnd = (event) => this.toolExecutionEnd(event);
|
|
1681
|
+
// Older v7 betas (< beta.111) emit these names. Kept as thin aliases so
|
|
1682
|
+
// applications pinned to those betas continue to work.
|
|
1683
|
+
this.onToolCallStart = (event) => this.toolExecutionStart(event);
|
|
1684
|
+
this.onToolCallFinish = (event) => this.toolExecutionEnd(event);
|
|
1685
|
+
// ── language-model call (v7 beta.111+) ─────────────────────────────────
|
|
1686
|
+
//
|
|
1687
|
+
// `onLanguageModelCallStart` / `onLanguageModelCallEnd` are scoped to the
|
|
1688
|
+
// model invocation only and exclude later client-side tool execution.
|
|
1689
|
+
// Raindrop already spans at the operation + step level, so these are
|
|
1690
|
+
// intentional no-ops — declared so the dispatcher's `mergeCallbacks` sees
|
|
1691
|
+
// them and so we don't accidentally rely on them later.
|
|
1692
|
+
//
|
|
1693
|
+
// Defined as no-ops rather than omitted so adding logic here later is a
|
|
1694
|
+
// strictly additive change.
|
|
1695
|
+
this.onLanguageModelCallStart = (_event) => {
|
|
1647
1696
|
};
|
|
1648
|
-
|
|
1649
|
-
this.onToolCallFinish = (event) => {
|
|
1650
|
-
const state = this.getState(event.callId);
|
|
1651
|
-
if (!state) return;
|
|
1652
|
-
const toolSpan = state.toolSpans.get(event.toolCall.toolCallId);
|
|
1653
|
-
if (!toolSpan) return;
|
|
1654
|
-
state.toolCallCount += 1;
|
|
1655
|
-
if (event.success) {
|
|
1656
|
-
const outputAttrs = state.recordOutputs ? [attrString("ai.toolCall.result", safeJsonWithUint8(event.output))] : [];
|
|
1657
|
-
this.traceShipper.endSpan(toolSpan, { attributes: outputAttrs });
|
|
1658
|
-
} else {
|
|
1659
|
-
this.traceShipper.endSpan(toolSpan, { error: event.error });
|
|
1660
|
-
}
|
|
1661
|
-
this.emitLive(state, "tool_result", event.toolCall.toolName);
|
|
1662
|
-
state.toolSpans.delete(event.toolCall.toolCallId);
|
|
1697
|
+
this.onLanguageModelCallEnd = (_event) => {
|
|
1663
1698
|
};
|
|
1664
1699
|
// ── onChunk (streaming) ─────────────────────────────────────────────────
|
|
1665
1700
|
this.onChunk = (event) => {
|
|
@@ -1928,6 +1963,53 @@ var RaindropTelemetryIntegration = class {
|
|
|
1928
1963
|
}
|
|
1929
1964
|
return void 0;
|
|
1930
1965
|
}
|
|
1966
|
+
// ── tool execution start / end ──────────────────────────────────────────
|
|
1967
|
+
//
|
|
1968
|
+
// v7 < beta.111 dispatched `onToolCallStart` / `onToolCallFinish`.
|
|
1969
|
+
// v7 >= beta.111 renamed them to `onToolExecutionStart` / `onToolExecutionEnd`
|
|
1970
|
+
// (see https://github.com/vercel/ai/pull/14589). Event shape is identical.
|
|
1971
|
+
// Both names are exposed and forward to a single implementation.
|
|
1972
|
+
toolExecutionStart(event) {
|
|
1973
|
+
const state = this.getState(event.callId);
|
|
1974
|
+
if (!(state == null ? void 0 : state.stepParent)) return;
|
|
1975
|
+
const { toolCall } = event;
|
|
1976
|
+
const { operationName, resourceName } = opName(
|
|
1977
|
+
"ai.toolCall",
|
|
1978
|
+
state.functionId
|
|
1979
|
+
);
|
|
1980
|
+
const inputAttrs = state.recordInputs ? [attrString("ai.toolCall.args", safeJsonWithUint8(toolCall.input))] : [];
|
|
1981
|
+
const toolSpan = this.traceShipper.startSpan({
|
|
1982
|
+
name: "ai.toolCall",
|
|
1983
|
+
parent: state.stepParent,
|
|
1984
|
+
eventId: state.eventId,
|
|
1985
|
+
operationId: "ai.toolCall",
|
|
1986
|
+
attributes: [
|
|
1987
|
+
attrString("operation.name", operationName),
|
|
1988
|
+
attrString("resource.name", resourceName),
|
|
1989
|
+
attrString("ai.telemetry.functionId", state.functionId),
|
|
1990
|
+
attrString("ai.toolCall.name", toolCall.toolName),
|
|
1991
|
+
attrString("ai.toolCall.id", toolCall.toolCallId),
|
|
1992
|
+
...inputAttrs
|
|
1993
|
+
]
|
|
1994
|
+
});
|
|
1995
|
+
state.toolSpans.set(toolCall.toolCallId, toolSpan);
|
|
1996
|
+
this.emitLive(state, "tool_start", toolCall.toolName, { args: toolCall.input });
|
|
1997
|
+
}
|
|
1998
|
+
toolExecutionEnd(event) {
|
|
1999
|
+
const state = this.getState(event.callId);
|
|
2000
|
+
if (!state) return;
|
|
2001
|
+
const toolSpan = state.toolSpans.get(event.toolCall.toolCallId);
|
|
2002
|
+
if (!toolSpan) return;
|
|
2003
|
+
state.toolCallCount += 1;
|
|
2004
|
+
if (event.success) {
|
|
2005
|
+
const outputAttrs = state.recordOutputs ? [attrString("ai.toolCall.result", safeJsonWithUint8(event.output))] : [];
|
|
2006
|
+
this.traceShipper.endSpan(toolSpan, { attributes: outputAttrs });
|
|
2007
|
+
} else {
|
|
2008
|
+
this.traceShipper.endSpan(toolSpan, { error: event.error });
|
|
2009
|
+
}
|
|
2010
|
+
this.emitLive(state, "tool_result", event.toolCall.toolName);
|
|
2011
|
+
state.toolSpans.delete(event.toolCall.toolCallId);
|
|
2012
|
+
}
|
|
1931
2013
|
finishGenerate(event, state) {
|
|
1932
2014
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1933
2015
|
if (state.rootSpan) {
|
|
@@ -2255,7 +2337,16 @@ function detectAISDKVersion(aiSDK) {
|
|
|
2255
2337
|
return "4";
|
|
2256
2338
|
}
|
|
2257
2339
|
function hasStructuredTelemetryEvents(aiSDK) {
|
|
2258
|
-
|
|
2340
|
+
if (!isRecord(aiSDK)) return false;
|
|
2341
|
+
const hasRegister = isFunction(aiSDK["registerTelemetry"]) || isFunction(aiSDK["registerTelemetryIntegration"]);
|
|
2342
|
+
const hasV7Marker = isFunction(aiSDK["experimental_streamLanguageModelCall"]) || isFunction(aiSDK["experimental_streamModelCall"]);
|
|
2343
|
+
return hasRegister && hasV7Marker;
|
|
2344
|
+
}
|
|
2345
|
+
function resolveRegisterTelemetry(aiSDK) {
|
|
2346
|
+
var _a;
|
|
2347
|
+
if (!isRecord(aiSDK)) return void 0;
|
|
2348
|
+
const fn = (_a = aiSDK["registerTelemetry"]) != null ? _a : aiSDK["registerTelemetryIntegration"];
|
|
2349
|
+
return isFunction(fn) ? fn : void 0;
|
|
2259
2350
|
}
|
|
2260
2351
|
function asVercelSchema(jsonSchemaObj) {
|
|
2261
2352
|
const validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
@@ -2533,7 +2624,7 @@ function setupOperation(params) {
|
|
|
2533
2624
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
2534
2625
|
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
2535
2626
|
attrString("ai.telemetry.metadata.raindrop.eventName", mergedCtx.eventName),
|
|
2536
|
-
attrString("ai.telemetry.metadata.raindrop.userId", mergedCtx.userId),
|
|
2627
|
+
attrString("ai.telemetry.metadata.raindrop.ai.userId", mergedCtx.userId),
|
|
2537
2628
|
attrString("ai.telemetry.metadata.raindrop.convoId", mergedCtx.convoId),
|
|
2538
2629
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
2539
2630
|
...attrsFromHeaders(isRecord(arg) ? arg["headers"] : void 0),
|
|
@@ -2896,31 +2987,44 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
2896
2987
|
properties: wrapTimeCtx.properties
|
|
2897
2988
|
}
|
|
2898
2989
|
});
|
|
2899
|
-
const registerFn = aiSDK
|
|
2900
|
-
if (
|
|
2990
|
+
const registerFn = resolveRegisterTelemetry(aiSDK);
|
|
2991
|
+
if (registerFn) {
|
|
2901
2992
|
registerFn(integration);
|
|
2902
2993
|
}
|
|
2903
2994
|
if (debug) {
|
|
2904
|
-
console.log(
|
|
2995
|
+
console.log(
|
|
2996
|
+
"[raindrop-ai/ai-sdk] nativeTelemetry: registered RaindropTelemetryIntegration (Proxy installed for per-call metadata propagation)"
|
|
2997
|
+
);
|
|
2905
2998
|
}
|
|
2906
2999
|
const selfDiagnostics2 = normalizeSelfDiagnosticsConfig(deps.options.selfDiagnostics);
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
3000
|
+
const jsonSchemaFactory = selfDiagnostics2 ? resolveJsonSchemaFactory(aiSDK) : void 0;
|
|
3001
|
+
const metadataAwareOps = /* @__PURE__ */ new Set([
|
|
3002
|
+
"generateText",
|
|
3003
|
+
"streamText",
|
|
3004
|
+
"generateObject",
|
|
3005
|
+
"streamObject",
|
|
3006
|
+
"embed",
|
|
3007
|
+
"embedMany",
|
|
3008
|
+
"rerank"
|
|
3009
|
+
]);
|
|
3010
|
+
const selfDiagnosticsOps = /* @__PURE__ */ new Set(["generateText", "streamText"]);
|
|
3011
|
+
const proxyTarget2 = isModuleNamespace(aiSDK) ? Object.setPrototypeOf({}, aiSDK) : aiSDK;
|
|
3012
|
+
return new Proxy(proxyTarget2, {
|
|
3013
|
+
get(target, prop, receiver) {
|
|
3014
|
+
const original = Reflect.get(target, prop, receiver);
|
|
3015
|
+
if (typeof prop !== "string" || !metadataAwareOps.has(prop) || !isFunction(original)) {
|
|
3016
|
+
return original;
|
|
3017
|
+
}
|
|
3018
|
+
const propName = prop;
|
|
3019
|
+
return (...callArgs) => {
|
|
3020
|
+
var _a2, _b2, _c2;
|
|
3021
|
+
const arg = callArgs[0];
|
|
3022
|
+
const callMetadata = readRaindropCallMetadataFromArgs(callArgs);
|
|
3023
|
+
const callOriginal = () => original.call(aiSDK, ...callArgs);
|
|
3024
|
+
if (selfDiagnostics2 && selfDiagnosticsOps.has(propName) && isRecord(arg)) {
|
|
2921
3025
|
const telemetry = extractExperimentalTelemetry(arg);
|
|
2922
3026
|
const callMeta = (telemetry == null ? void 0 : telemetry.metadata) ? extractRaindropMetadata(telemetry.metadata) : {};
|
|
2923
|
-
const perCallEventIdExplicit = (_a2 =
|
|
3027
|
+
const perCallEventIdExplicit = (_b2 = (_a2 = callMetadata == null ? void 0 : callMetadata.eventId) != null ? _a2 : callMeta.eventId) != null ? _b2 : wrapTimeCtx.eventId;
|
|
2924
3028
|
const perCallEventId = perCallEventIdExplicit != null ? perCallEventIdExplicit : randomUUID();
|
|
2925
3029
|
const perCallEventIdGenerated = !perCallEventIdExplicit;
|
|
2926
3030
|
const perCallCtx = {
|
|
@@ -2957,12 +3061,25 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
2957
3061
|
metadata: mergedMetadata
|
|
2958
3062
|
}
|
|
2959
3063
|
};
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
3064
|
+
const mergedAlsMetadata = {
|
|
3065
|
+
...callMetadata != null ? callMetadata : {},
|
|
3066
|
+
eventId: perCallEventId,
|
|
3067
|
+
eventIdGenerated: perCallEventIdGenerated || (callMetadata == null ? void 0 : callMetadata.eventIdGenerated),
|
|
3068
|
+
rawMetadata: {
|
|
3069
|
+
...(_c2 = callMetadata == null ? void 0 : callMetadata.rawMetadata) != null ? _c2 : {},
|
|
3070
|
+
"raindrop.eventId": perCallEventId,
|
|
3071
|
+
...perCallEventIdGenerated ? { "raindrop.internal.eventIdGenerated": "true" } : {}
|
|
3072
|
+
}
|
|
3073
|
+
};
|
|
3074
|
+
return runWithRaindropCallMetadata(mergedAlsMetadata, callOriginal);
|
|
3075
|
+
}
|
|
3076
|
+
if (callMetadata) {
|
|
3077
|
+
return runWithRaindropCallMetadata(callMetadata, callOriginal);
|
|
3078
|
+
}
|
|
3079
|
+
return callOriginal();
|
|
3080
|
+
};
|
|
3081
|
+
}
|
|
3082
|
+
});
|
|
2966
3083
|
}
|
|
2967
3084
|
const instrumentedOps = /* @__PURE__ */ new Set([
|
|
2968
3085
|
"generateText",
|
|
@@ -3098,7 +3215,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
3098
3215
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
3099
3216
|
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
3100
3217
|
attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
|
|
3101
|
-
attrString("ai.telemetry.metadata.raindrop.userId", ctx.userId),
|
|
3218
|
+
attrString("ai.telemetry.metadata.raindrop.ai.userId", ctx.userId),
|
|
3102
3219
|
attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
|
|
3103
3220
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
3104
3221
|
...attrsFromHeaders(mergedArgs["headers"]),
|
|
@@ -3306,7 +3423,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
3306
3423
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
3307
3424
|
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
3308
3425
|
attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
|
|
3309
|
-
attrString("ai.telemetry.metadata.raindrop.userId", ctx.userId),
|
|
3426
|
+
attrString("ai.telemetry.metadata.raindrop.ai.userId", ctx.userId),
|
|
3310
3427
|
attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
|
|
3311
3428
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
3312
3429
|
...attrsFromHeaders(mergedArgs["headers"]),
|
|
@@ -4254,10 +4371,14 @@ if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
|
|
4254
4371
|
}
|
|
4255
4372
|
|
|
4256
4373
|
exports.RaindropTelemetryIntegration = RaindropTelemetryIntegration;
|
|
4374
|
+
exports._resetRaindropCallMetadataStorage = _resetRaindropCallMetadataStorage;
|
|
4257
4375
|
exports._resetWarnedMissingUserId = _resetWarnedMissingUserId;
|
|
4258
4376
|
exports.createRaindropAISDK = createRaindropAISDK;
|
|
4259
4377
|
exports.currentSpan = currentSpan;
|
|
4260
4378
|
exports.eventMetadata = eventMetadata;
|
|
4261
4379
|
exports.eventMetadataFromChatRequest = eventMetadataFromChatRequest;
|
|
4262
4380
|
exports.getContextManager = getContextManager;
|
|
4381
|
+
exports.getCurrentRaindropCallMetadata = getCurrentRaindropCallMetadata;
|
|
4382
|
+
exports.readRaindropCallMetadataFromArgs = readRaindropCallMetadataFromArgs;
|
|
4383
|
+
exports.runWithRaindropCallMetadata = runWithRaindropCallMetadata;
|
|
4263
4384
|
exports.withCurrent = withCurrent;
|
package/dist/index.workers.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-
|
|
1
|
+
export { RaindropTelemetryIntegration, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentRaindropCallMetadata, readRaindropCallMetadataFromArgs, runWithRaindropCallMetadata, withCurrent } from './chunk-76JSTQY3.mjs';
|
|
2
2
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
3
|
|
|
4
4
|
if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
package/package.json
CHANGED