@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.
- package/README.md +30 -4
- package/dist/{chunk-AUFHKHNR.mjs → chunk-YP2VKVP7.mjs} +270 -98
- package/dist/{index-sxjvhkYW.d.mts → index-TERu6zvv.d.mts} +88 -12
- package/dist/{index-sxjvhkYW.d.ts → index-TERu6zvv.d.ts} +88 -12
- package/dist/index.browser.d.mts +88 -12
- package/dist/index.browser.d.ts +88 -12
- package/dist/index.browser.js +273 -97
- package/dist/index.browser.mjs +270 -98
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +273 -97
- 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 +273 -97
- package/dist/index.workers.mjs +1 -1
- package/package.json +1 -1
package/dist/index.node.js
CHANGED
|
@@ -4,7 +4,7 @@ var async_hooks = require('async_hooks');
|
|
|
4
4
|
|
|
5
5
|
// src/index.node.ts
|
|
6
6
|
|
|
7
|
-
// ../core/dist/chunk-
|
|
7
|
+
// ../core/dist/chunk-LMIWKHOH.js
|
|
8
8
|
function getCrypto() {
|
|
9
9
|
const c = globalThis.crypto;
|
|
10
10
|
return c;
|
|
@@ -474,29 +474,70 @@ var EventShipper = class {
|
|
|
474
474
|
}
|
|
475
475
|
};
|
|
476
476
|
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
477
|
+
var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
|
|
478
|
+
var DEFAULT_LOCAL_WORKSHOP_URL = "http://localhost:5899/v1/";
|
|
479
|
+
function readEnvVar(name) {
|
|
480
|
+
var _a;
|
|
481
|
+
try {
|
|
482
|
+
const env = (_a = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : _a.env;
|
|
483
|
+
if (env && typeof env[name] === "string" && env[name].length > 0) {
|
|
484
|
+
return env[name];
|
|
485
|
+
}
|
|
486
|
+
} catch (e) {
|
|
487
|
+
}
|
|
488
|
+
return void 0;
|
|
489
|
+
}
|
|
490
|
+
function readWorkshopEnv() {
|
|
491
|
+
const raw = readEnvVar(WORKSHOP_ENV_VAR);
|
|
492
|
+
if (raw === void 0) return void 0;
|
|
493
|
+
const trimmed = raw.trim();
|
|
494
|
+
if (trimmed.length === 0) return void 0;
|
|
495
|
+
if (/^https?:\/\//i.test(trimmed)) return { url: trimmed };
|
|
496
|
+
if (/^(1|true|yes|on)$/i.test(trimmed)) return "enable";
|
|
497
|
+
if (/^(0|false|no|off)$/i.test(trimmed)) return "disable";
|
|
498
|
+
return void 0;
|
|
499
|
+
}
|
|
500
|
+
function isLocalDevHost(hostname) {
|
|
501
|
+
if (!hostname) return false;
|
|
502
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "::1") {
|
|
503
|
+
return true;
|
|
504
|
+
}
|
|
505
|
+
if (hostname.endsWith(".localhost")) return true;
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
function readRuntimeHostname() {
|
|
509
|
+
try {
|
|
510
|
+
const loc = globalThis == null ? void 0 : globalThis.location;
|
|
511
|
+
if (loc && typeof loc.hostname === "string" && loc.hostname.length > 0) {
|
|
512
|
+
return loc.hostname;
|
|
513
|
+
}
|
|
514
|
+
} catch (e) {
|
|
515
|
+
}
|
|
516
|
+
return void 0;
|
|
517
|
+
}
|
|
518
|
+
function shouldAutoEnableLocalWorkshop() {
|
|
519
|
+
if (isLocalDevHost(readRuntimeHostname())) return true;
|
|
520
|
+
if (readEnvVar("NODE_ENV") === "development") return true;
|
|
521
|
+
return false;
|
|
522
|
+
}
|
|
477
523
|
function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
478
524
|
var _a, _b, _c;
|
|
479
|
-
|
|
480
|
-
|
|
525
|
+
if (baseUrl === null) return null;
|
|
526
|
+
if (typeof baseUrl === "string" && baseUrl.length > 0) {
|
|
527
|
+
return (_a = formatEndpoint(baseUrl)) != null ? _a : null;
|
|
528
|
+
}
|
|
529
|
+
const explicitUrlEnv = readEnvVar(LOCAL_DEBUGGER_ENV_VAR);
|
|
530
|
+
if (explicitUrlEnv) return (_b = formatEndpoint(explicitUrlEnv)) != null ? _b : null;
|
|
531
|
+
const workshopEnv = readWorkshopEnv();
|
|
532
|
+
if (workshopEnv === "disable") return null;
|
|
533
|
+
if (workshopEnv === "enable") return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
534
|
+
if (workshopEnv && "url" in workshopEnv) return (_c = formatEndpoint(workshopEnv.url)) != null ? _c : null;
|
|
535
|
+
if (shouldAutoEnableLocalWorkshop()) return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
536
|
+
return null;
|
|
481
537
|
}
|
|
482
538
|
function localDebuggerEnabled(baseUrl) {
|
|
483
539
|
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
484
540
|
}
|
|
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
541
|
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
501
542
|
var _a;
|
|
502
543
|
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
@@ -516,7 +557,7 @@ function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
|
516
557
|
`${baseUrl}live`,
|
|
517
558
|
{
|
|
518
559
|
...event,
|
|
519
|
-
type:
|
|
560
|
+
type: event.type,
|
|
520
561
|
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
521
562
|
},
|
|
522
563
|
{},
|
|
@@ -532,7 +573,7 @@ var TraceShipper = class {
|
|
|
532
573
|
constructor(opts) {
|
|
533
574
|
this.queue = [];
|
|
534
575
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
535
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
|
576
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
536
577
|
this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
|
|
537
578
|
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
538
579
|
this.enabled = opts.enabled !== false;
|
|
@@ -545,12 +586,9 @@ var TraceShipper = class {
|
|
|
545
586
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
546
587
|
this.serviceName = (_g = opts.serviceName) != null ? _g : "raindrop.core";
|
|
547
588
|
this.serviceVersion = (_h = opts.serviceVersion) != null ? _h : "0.0.0";
|
|
548
|
-
|
|
549
|
-
if (
|
|
550
|
-
this.
|
|
551
|
-
if (this.debug) {
|
|
552
|
-
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
553
|
-
}
|
|
589
|
+
this.localDebuggerUrl = (_i = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _i : void 0;
|
|
590
|
+
if (this.debug && this.localDebuggerUrl) {
|
|
591
|
+
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
554
592
|
}
|
|
555
593
|
}
|
|
556
594
|
isDebugEnabled() {
|
|
@@ -837,7 +875,7 @@ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
|
|
|
837
875
|
// package.json
|
|
838
876
|
var package_default = {
|
|
839
877
|
name: "@raindrop-ai/ai-sdk",
|
|
840
|
-
version: "0.0.
|
|
878
|
+
version: "0.0.27"};
|
|
841
879
|
|
|
842
880
|
// src/internal/version.ts
|
|
843
881
|
var libraryName = package_default.name;
|
|
@@ -1477,6 +1515,77 @@ function attrsFromGenAiRequest(options) {
|
|
|
1477
1515
|
];
|
|
1478
1516
|
}
|
|
1479
1517
|
|
|
1518
|
+
// src/internal/call-metadata.ts
|
|
1519
|
+
var SyncFallbackStorage = class {
|
|
1520
|
+
constructor() {
|
|
1521
|
+
this._stack = [];
|
|
1522
|
+
}
|
|
1523
|
+
getStore() {
|
|
1524
|
+
return this._stack[this._stack.length - 1];
|
|
1525
|
+
}
|
|
1526
|
+
run(store, callback) {
|
|
1527
|
+
this._stack.push(store);
|
|
1528
|
+
try {
|
|
1529
|
+
return callback();
|
|
1530
|
+
} finally {
|
|
1531
|
+
this._stack.pop();
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
var _storage = null;
|
|
1536
|
+
function getStorage() {
|
|
1537
|
+
if (_storage) return _storage;
|
|
1538
|
+
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
1539
|
+
_storage = Ctor ? new Ctor() : new SyncFallbackStorage();
|
|
1540
|
+
return _storage;
|
|
1541
|
+
}
|
|
1542
|
+
function _resetRaindropCallMetadataStorage() {
|
|
1543
|
+
_storage = null;
|
|
1544
|
+
}
|
|
1545
|
+
function getCurrentRaindropCallMetadata() {
|
|
1546
|
+
return getStorage().getStore();
|
|
1547
|
+
}
|
|
1548
|
+
function runWithRaindropCallMetadata(metadata, fn) {
|
|
1549
|
+
return getStorage().run(metadata, fn);
|
|
1550
|
+
}
|
|
1551
|
+
function readRaindropCallMetadataFromArgs(args) {
|
|
1552
|
+
var _a;
|
|
1553
|
+
if (args.length === 0) return void 0;
|
|
1554
|
+
const first = args[0];
|
|
1555
|
+
if (!isRecord(first)) return void 0;
|
|
1556
|
+
const topLevel = isRecord(first["metadata"]) ? first["metadata"] : void 0;
|
|
1557
|
+
const stable = isRecord(first["telemetry"]) ? first["telemetry"]["metadata"] : void 0;
|
|
1558
|
+
const stableMetadata = isRecord(stable) ? stable : void 0;
|
|
1559
|
+
const exp = extractExperimentalTelemetry(first);
|
|
1560
|
+
const expMetadata = (exp == null ? void 0 : exp.metadata) && typeof exp.metadata === "object" ? exp.metadata : void 0;
|
|
1561
|
+
const raw = (_a = topLevel != null ? topLevel : stableMetadata) != null ? _a : expMetadata;
|
|
1562
|
+
if (!raw) return void 0;
|
|
1563
|
+
const meta = { rawMetadata: raw };
|
|
1564
|
+
const userId = raw["raindrop.userId"];
|
|
1565
|
+
if (typeof userId === "string" && userId) meta.userId = userId;
|
|
1566
|
+
const eventId = raw["raindrop.eventId"];
|
|
1567
|
+
if (typeof eventId === "string" && eventId) meta.eventId = eventId;
|
|
1568
|
+
const eventIdGenerated = raw["raindrop.internal.eventIdGenerated"];
|
|
1569
|
+
if (eventIdGenerated === true || eventIdGenerated === "true" || eventIdGenerated === "1") {
|
|
1570
|
+
meta.eventIdGenerated = true;
|
|
1571
|
+
}
|
|
1572
|
+
const convoId = raw["raindrop.convoId"];
|
|
1573
|
+
if (typeof convoId === "string" && convoId) meta.convoId = convoId;
|
|
1574
|
+
const eventName = raw["raindrop.eventName"];
|
|
1575
|
+
if (typeof eventName === "string" && eventName) meta.eventName = eventName;
|
|
1576
|
+
const properties = raw["raindrop.properties"];
|
|
1577
|
+
if (typeof properties === "string") {
|
|
1578
|
+
try {
|
|
1579
|
+
const parsed = JSON.parse(properties);
|
|
1580
|
+
if (parsed && typeof parsed === "object") meta.properties = parsed;
|
|
1581
|
+
} catch (e) {
|
|
1582
|
+
}
|
|
1583
|
+
} else if (properties && typeof properties === "object") {
|
|
1584
|
+
meta.properties = properties;
|
|
1585
|
+
}
|
|
1586
|
+
return meta;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1480
1589
|
// src/internal/raindrop-telemetry-integration.ts
|
|
1481
1590
|
var RaindropTelemetryIntegration = class {
|
|
1482
1591
|
constructor(opts) {
|
|
@@ -1484,15 +1593,17 @@ var RaindropTelemetryIntegration = class {
|
|
|
1484
1593
|
// ── onStart ─────────────────────────────────────────────────────────────
|
|
1485
1594
|
this.onStart = (event) => {
|
|
1486
1595
|
var _a, _b, _c, _d;
|
|
1487
|
-
if (event.isEnabled
|
|
1596
|
+
if (event.isEnabled === false) return;
|
|
1488
1597
|
const isEmbed = event.operationId === "ai.embed" || event.operationId === "ai.embedMany";
|
|
1489
1598
|
const recordInputs = event.recordInputs !== false;
|
|
1490
1599
|
const recordOutputs = event.recordOutputs !== false;
|
|
1491
1600
|
const functionId = event.functionId;
|
|
1492
|
-
const
|
|
1601
|
+
const eventMetadata2 = event.metadata;
|
|
1602
|
+
const callContextMetadata = getCurrentRaindropCallMetadata();
|
|
1603
|
+
const metadata = eventMetadata2 != null ? eventMetadata2 : callContextMetadata == null ? void 0 : callContextMetadata.rawMetadata;
|
|
1493
1604
|
const callMeta = this.extractRaindropMetadata(metadata);
|
|
1494
1605
|
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;
|
|
1606
|
+
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
1607
|
const explicitEventId = callMeta.eventId && !eventIdGenerated ? callMeta.eventId : void 0;
|
|
1497
1608
|
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
1609
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
@@ -1618,48 +1729,25 @@ var RaindropTelemetryIntegration = class {
|
|
|
1618
1729
|
state.stepSpan = stepSpan;
|
|
1619
1730
|
state.stepParent = this.spanParentRef(stepSpan);
|
|
1620
1731
|
};
|
|
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 });
|
|
1732
|
+
this.onToolExecutionStart = (event) => this.toolExecutionStart(event);
|
|
1733
|
+
this.onToolExecutionEnd = (event) => this.toolExecutionEnd(event);
|
|
1734
|
+
// Older v7 betas (< beta.111) emit these names. Kept as thin aliases so
|
|
1735
|
+
// applications pinned to those betas continue to work.
|
|
1736
|
+
this.onToolCallStart = (event) => this.toolExecutionStart(event);
|
|
1737
|
+
this.onToolCallFinish = (event) => this.toolExecutionEnd(event);
|
|
1738
|
+
// ── language-model call (v7 beta.111+) ─────────────────────────────────
|
|
1739
|
+
//
|
|
1740
|
+
// `onLanguageModelCallStart` / `onLanguageModelCallEnd` are scoped to the
|
|
1741
|
+
// model invocation only and exclude later client-side tool execution.
|
|
1742
|
+
// Raindrop already spans at the operation + step level, so these are
|
|
1743
|
+
// intentional no-ops — declared so the dispatcher's `mergeCallbacks` sees
|
|
1744
|
+
// them and so we don't accidentally rely on them later.
|
|
1745
|
+
//
|
|
1746
|
+
// Defined as no-ops rather than omitted so adding logic here later is a
|
|
1747
|
+
// strictly additive change.
|
|
1748
|
+
this.onLanguageModelCallStart = (_event) => {
|
|
1647
1749
|
};
|
|
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);
|
|
1750
|
+
this.onLanguageModelCallEnd = (_event) => {
|
|
1663
1751
|
};
|
|
1664
1752
|
// ── onChunk (streaming) ─────────────────────────────────────────────────
|
|
1665
1753
|
this.onChunk = (event) => {
|
|
@@ -1928,6 +2016,53 @@ var RaindropTelemetryIntegration = class {
|
|
|
1928
2016
|
}
|
|
1929
2017
|
return void 0;
|
|
1930
2018
|
}
|
|
2019
|
+
// ── tool execution start / end ──────────────────────────────────────────
|
|
2020
|
+
//
|
|
2021
|
+
// v7 < beta.111 dispatched `onToolCallStart` / `onToolCallFinish`.
|
|
2022
|
+
// v7 >= beta.111 renamed them to `onToolExecutionStart` / `onToolExecutionEnd`
|
|
2023
|
+
// (see https://github.com/vercel/ai/pull/14589). Event shape is identical.
|
|
2024
|
+
// Both names are exposed and forward to a single implementation.
|
|
2025
|
+
toolExecutionStart(event) {
|
|
2026
|
+
const state = this.getState(event.callId);
|
|
2027
|
+
if (!(state == null ? void 0 : state.stepParent)) return;
|
|
2028
|
+
const { toolCall } = event;
|
|
2029
|
+
const { operationName, resourceName } = opName(
|
|
2030
|
+
"ai.toolCall",
|
|
2031
|
+
state.functionId
|
|
2032
|
+
);
|
|
2033
|
+
const inputAttrs = state.recordInputs ? [attrString("ai.toolCall.args", safeJsonWithUint8(toolCall.input))] : [];
|
|
2034
|
+
const toolSpan = this.traceShipper.startSpan({
|
|
2035
|
+
name: "ai.toolCall",
|
|
2036
|
+
parent: state.stepParent,
|
|
2037
|
+
eventId: state.eventId,
|
|
2038
|
+
operationId: "ai.toolCall",
|
|
2039
|
+
attributes: [
|
|
2040
|
+
attrString("operation.name", operationName),
|
|
2041
|
+
attrString("resource.name", resourceName),
|
|
2042
|
+
attrString("ai.telemetry.functionId", state.functionId),
|
|
2043
|
+
attrString("ai.toolCall.name", toolCall.toolName),
|
|
2044
|
+
attrString("ai.toolCall.id", toolCall.toolCallId),
|
|
2045
|
+
...inputAttrs
|
|
2046
|
+
]
|
|
2047
|
+
});
|
|
2048
|
+
state.toolSpans.set(toolCall.toolCallId, toolSpan);
|
|
2049
|
+
this.emitLive(state, "tool_start", toolCall.toolName, { args: toolCall.input });
|
|
2050
|
+
}
|
|
2051
|
+
toolExecutionEnd(event) {
|
|
2052
|
+
const state = this.getState(event.callId);
|
|
2053
|
+
if (!state) return;
|
|
2054
|
+
const toolSpan = state.toolSpans.get(event.toolCall.toolCallId);
|
|
2055
|
+
if (!toolSpan) return;
|
|
2056
|
+
state.toolCallCount += 1;
|
|
2057
|
+
if (event.success) {
|
|
2058
|
+
const outputAttrs = state.recordOutputs ? [attrString("ai.toolCall.result", safeJsonWithUint8(event.output))] : [];
|
|
2059
|
+
this.traceShipper.endSpan(toolSpan, { attributes: outputAttrs });
|
|
2060
|
+
} else {
|
|
2061
|
+
this.traceShipper.endSpan(toolSpan, { error: event.error });
|
|
2062
|
+
}
|
|
2063
|
+
this.emitLive(state, "tool_result", event.toolCall.toolName);
|
|
2064
|
+
state.toolSpans.delete(event.toolCall.toolCallId);
|
|
2065
|
+
}
|
|
1931
2066
|
finishGenerate(event, state) {
|
|
1932
2067
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1933
2068
|
if (state.rootSpan) {
|
|
@@ -2255,7 +2390,16 @@ function detectAISDKVersion(aiSDK) {
|
|
|
2255
2390
|
return "4";
|
|
2256
2391
|
}
|
|
2257
2392
|
function hasStructuredTelemetryEvents(aiSDK) {
|
|
2258
|
-
|
|
2393
|
+
if (!isRecord(aiSDK)) return false;
|
|
2394
|
+
const hasRegister = isFunction(aiSDK["registerTelemetry"]) || isFunction(aiSDK["registerTelemetryIntegration"]);
|
|
2395
|
+
const hasV7Marker = isFunction(aiSDK["experimental_streamLanguageModelCall"]) || isFunction(aiSDK["experimental_streamModelCall"]);
|
|
2396
|
+
return hasRegister && hasV7Marker;
|
|
2397
|
+
}
|
|
2398
|
+
function resolveRegisterTelemetry(aiSDK) {
|
|
2399
|
+
var _a;
|
|
2400
|
+
if (!isRecord(aiSDK)) return void 0;
|
|
2401
|
+
const fn = (_a = aiSDK["registerTelemetry"]) != null ? _a : aiSDK["registerTelemetryIntegration"];
|
|
2402
|
+
return isFunction(fn) ? fn : void 0;
|
|
2259
2403
|
}
|
|
2260
2404
|
function asVercelSchema(jsonSchemaObj) {
|
|
2261
2405
|
const validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
@@ -2896,31 +3040,44 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
2896
3040
|
properties: wrapTimeCtx.properties
|
|
2897
3041
|
}
|
|
2898
3042
|
});
|
|
2899
|
-
const registerFn = aiSDK
|
|
2900
|
-
if (
|
|
3043
|
+
const registerFn = resolveRegisterTelemetry(aiSDK);
|
|
3044
|
+
if (registerFn) {
|
|
2901
3045
|
registerFn(integration);
|
|
2902
3046
|
}
|
|
2903
3047
|
if (debug) {
|
|
2904
|
-
console.log(
|
|
3048
|
+
console.log(
|
|
3049
|
+
"[raindrop-ai/ai-sdk] nativeTelemetry: registered RaindropTelemetryIntegration (Proxy installed for per-call metadata propagation)"
|
|
3050
|
+
);
|
|
2905
3051
|
}
|
|
2906
3052
|
const selfDiagnostics2 = normalizeSelfDiagnosticsConfig(deps.options.selfDiagnostics);
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
3053
|
+
const jsonSchemaFactory = selfDiagnostics2 ? resolveJsonSchemaFactory(aiSDK) : void 0;
|
|
3054
|
+
const metadataAwareOps = /* @__PURE__ */ new Set([
|
|
3055
|
+
"generateText",
|
|
3056
|
+
"streamText",
|
|
3057
|
+
"generateObject",
|
|
3058
|
+
"streamObject",
|
|
3059
|
+
"embed",
|
|
3060
|
+
"embedMany",
|
|
3061
|
+
"rerank"
|
|
3062
|
+
]);
|
|
3063
|
+
const selfDiagnosticsOps = /* @__PURE__ */ new Set(["generateText", "streamText"]);
|
|
3064
|
+
const proxyTarget2 = isModuleNamespace(aiSDK) ? Object.setPrototypeOf({}, aiSDK) : aiSDK;
|
|
3065
|
+
return new Proxy(proxyTarget2, {
|
|
3066
|
+
get(target, prop, receiver) {
|
|
3067
|
+
const original = Reflect.get(target, prop, receiver);
|
|
3068
|
+
if (typeof prop !== "string" || !metadataAwareOps.has(prop) || !isFunction(original)) {
|
|
3069
|
+
return original;
|
|
3070
|
+
}
|
|
3071
|
+
const propName = prop;
|
|
3072
|
+
return (...callArgs) => {
|
|
3073
|
+
var _a2, _b2, _c2;
|
|
3074
|
+
const arg = callArgs[0];
|
|
3075
|
+
const callMetadata = readRaindropCallMetadataFromArgs(callArgs);
|
|
3076
|
+
const callOriginal = () => original.call(aiSDK, ...callArgs);
|
|
3077
|
+
if (selfDiagnostics2 && selfDiagnosticsOps.has(propName) && isRecord(arg)) {
|
|
2921
3078
|
const telemetry = extractExperimentalTelemetry(arg);
|
|
2922
3079
|
const callMeta = (telemetry == null ? void 0 : telemetry.metadata) ? extractRaindropMetadata(telemetry.metadata) : {};
|
|
2923
|
-
const perCallEventIdExplicit = (_a2 =
|
|
3080
|
+
const perCallEventIdExplicit = (_b2 = (_a2 = callMetadata == null ? void 0 : callMetadata.eventId) != null ? _a2 : callMeta.eventId) != null ? _b2 : wrapTimeCtx.eventId;
|
|
2924
3081
|
const perCallEventId = perCallEventIdExplicit != null ? perCallEventIdExplicit : randomUUID();
|
|
2925
3082
|
const perCallEventIdGenerated = !perCallEventIdExplicit;
|
|
2926
3083
|
const perCallCtx = {
|
|
@@ -2957,12 +3114,25 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
2957
3114
|
metadata: mergedMetadata
|
|
2958
3115
|
}
|
|
2959
3116
|
};
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
3117
|
+
const mergedAlsMetadata = {
|
|
3118
|
+
...callMetadata != null ? callMetadata : {},
|
|
3119
|
+
eventId: perCallEventId,
|
|
3120
|
+
eventIdGenerated: perCallEventIdGenerated || (callMetadata == null ? void 0 : callMetadata.eventIdGenerated),
|
|
3121
|
+
rawMetadata: {
|
|
3122
|
+
...(_c2 = callMetadata == null ? void 0 : callMetadata.rawMetadata) != null ? _c2 : {},
|
|
3123
|
+
"raindrop.eventId": perCallEventId,
|
|
3124
|
+
...perCallEventIdGenerated ? { "raindrop.internal.eventIdGenerated": "true" } : {}
|
|
3125
|
+
}
|
|
3126
|
+
};
|
|
3127
|
+
return runWithRaindropCallMetadata(mergedAlsMetadata, callOriginal);
|
|
3128
|
+
}
|
|
3129
|
+
if (callMetadata) {
|
|
3130
|
+
return runWithRaindropCallMetadata(callMetadata, callOriginal);
|
|
3131
|
+
}
|
|
3132
|
+
return callOriginal();
|
|
3133
|
+
};
|
|
3134
|
+
}
|
|
3135
|
+
});
|
|
2966
3136
|
}
|
|
2967
3137
|
const instrumentedOps = /* @__PURE__ */ new Set([
|
|
2968
3138
|
"generateText",
|
|
@@ -4117,6 +4287,7 @@ function createRaindropAISDK(opts) {
|
|
|
4117
4287
|
debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
|
|
4118
4288
|
partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
|
|
4119
4289
|
});
|
|
4290
|
+
const localDebuggerUrl = opts.localWorkshopUrl === false ? null : opts.localWorkshopUrl;
|
|
4120
4291
|
const traceShipper = new TraceShipper2({
|
|
4121
4292
|
writeKey,
|
|
4122
4293
|
endpoint: opts.endpoint,
|
|
@@ -4125,7 +4296,8 @@ function createRaindropAISDK(opts) {
|
|
|
4125
4296
|
debugSpans: ((_f = opts.traces) == null ? void 0 : _f.debugSpans) === true || envDebug,
|
|
4126
4297
|
flushIntervalMs: (_g = opts.traces) == null ? void 0 : _g.flushIntervalMs,
|
|
4127
4298
|
maxBatchSize: (_h = opts.traces) == null ? void 0 : _h.maxBatchSize,
|
|
4128
|
-
maxQueueSize: (_i = opts.traces) == null ? void 0 : _i.maxQueueSize
|
|
4299
|
+
maxQueueSize: (_i = opts.traces) == null ? void 0 : _i.maxQueueSize,
|
|
4300
|
+
localDebuggerUrl
|
|
4129
4301
|
});
|
|
4130
4302
|
return {
|
|
4131
4303
|
wrap(aiSDK, options) {
|
|
@@ -4252,10 +4424,14 @@ function createRaindropAISDK(opts) {
|
|
|
4252
4424
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
|
|
4253
4425
|
|
|
4254
4426
|
exports.RaindropTelemetryIntegration = RaindropTelemetryIntegration;
|
|
4427
|
+
exports._resetRaindropCallMetadataStorage = _resetRaindropCallMetadataStorage;
|
|
4255
4428
|
exports._resetWarnedMissingUserId = _resetWarnedMissingUserId;
|
|
4256
4429
|
exports.createRaindropAISDK = createRaindropAISDK;
|
|
4257
4430
|
exports.currentSpan = currentSpan;
|
|
4258
4431
|
exports.eventMetadata = eventMetadata;
|
|
4259
4432
|
exports.eventMetadataFromChatRequest = eventMetadataFromChatRequest;
|
|
4260
4433
|
exports.getContextManager = getContextManager;
|
|
4434
|
+
exports.getCurrentRaindropCallMetadata = getCurrentRaindropCallMetadata;
|
|
4435
|
+
exports.readRaindropCallMetadataFromArgs = readRaindropCallMetadataFromArgs;
|
|
4436
|
+
exports.runWithRaindropCallMetadata = runWithRaindropCallMetadata;
|
|
4261
4437
|
exports.withCurrent = withCurrent;
|
package/dist/index.node.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-YP2VKVP7.mjs';
|
|
2
2
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
3
|
|
|
4
4
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
|
package/dist/index.workers.d.mts
CHANGED
|
@@ -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
|
|
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>() => {
|
package/dist/index.workers.d.ts
CHANGED
|
@@ -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
|
|
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>() => {
|