@raindrop-ai/ai-sdk 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -9
- package/dist/{chunk-FD5GVIE2.mjs → chunk-BTNDCDA3.mjs} +237 -22
- package/dist/{index-DGziajf_.d.mts → index-CPArLupC.d.mts} +3 -0
- package/dist/{index-DGziajf_.d.ts → index-CPArLupC.d.ts} +3 -0
- package/dist/index.browser.d.mts +3 -0
- package/dist/index.browser.d.ts +3 -0
- package/dist/index.browser.js +237 -22
- package/dist/index.browser.mjs +237 -22
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +237 -22
- 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 +237 -22
- 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-4UCYIEH4.js
|
|
8
8
|
function getCrypto() {
|
|
9
9
|
const c = globalThis.crypto;
|
|
10
10
|
return c;
|
|
@@ -149,6 +149,7 @@ async function postJson(url, body, headers, opts) {
|
|
|
149
149
|
);
|
|
150
150
|
}
|
|
151
151
|
var SpanStatusCode = {
|
|
152
|
+
UNSET: 0,
|
|
152
153
|
ERROR: 2
|
|
153
154
|
};
|
|
154
155
|
function createSpanIds(parent) {
|
|
@@ -469,11 +470,66 @@ var EventShipper = class {
|
|
|
469
470
|
}
|
|
470
471
|
}
|
|
471
472
|
};
|
|
473
|
+
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
474
|
+
function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
475
|
+
var _a, _b, _c;
|
|
476
|
+
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;
|
|
477
|
+
return resolved ? (_c = formatEndpoint(resolved)) != null ? _c : null : null;
|
|
478
|
+
}
|
|
479
|
+
function localDebuggerEnabled(baseUrl) {
|
|
480
|
+
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
481
|
+
}
|
|
482
|
+
function normalizeLocalDebuggerLiveEventType(type) {
|
|
483
|
+
switch (type) {
|
|
484
|
+
case "text-delta":
|
|
485
|
+
return "text_delta";
|
|
486
|
+
case "reasoning":
|
|
487
|
+
case "reasoning-delta":
|
|
488
|
+
return "reasoning_delta";
|
|
489
|
+
case "tool-call":
|
|
490
|
+
return "tool_start";
|
|
491
|
+
case "tool-result":
|
|
492
|
+
return "tool_result";
|
|
493
|
+
default:
|
|
494
|
+
return type;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
498
|
+
var _a;
|
|
499
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
500
|
+
if (!baseUrl) return;
|
|
501
|
+
void postJson(`${baseUrl}traces`, body, {}, {
|
|
502
|
+
maxAttempts: 1,
|
|
503
|
+
debug: (_a = options.debug) != null ? _a : false,
|
|
504
|
+
sdkName: options.sdkName
|
|
505
|
+
}).catch(() => {
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
509
|
+
var _a, _b;
|
|
510
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
511
|
+
if (!baseUrl) return;
|
|
512
|
+
void postJson(
|
|
513
|
+
`${baseUrl}live`,
|
|
514
|
+
{
|
|
515
|
+
...event,
|
|
516
|
+
type: normalizeLocalDebuggerLiveEventType(event.type),
|
|
517
|
+
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
518
|
+
},
|
|
519
|
+
{},
|
|
520
|
+
{
|
|
521
|
+
maxAttempts: 1,
|
|
522
|
+
debug: (_b = options.debug) != null ? _b : false,
|
|
523
|
+
sdkName: options.sdkName
|
|
524
|
+
}
|
|
525
|
+
).catch(() => {
|
|
526
|
+
});
|
|
527
|
+
}
|
|
472
528
|
var TraceShipper = class {
|
|
473
529
|
constructor(opts) {
|
|
474
530
|
this.queue = [];
|
|
475
531
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
476
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
532
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
477
533
|
this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
|
|
478
534
|
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
479
535
|
this.enabled = opts.enabled !== false;
|
|
@@ -486,6 +542,13 @@ var TraceShipper = class {
|
|
|
486
542
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
487
543
|
this.serviceName = (_g = opts.serviceName) != null ? _g : "raindrop.core";
|
|
488
544
|
this.serviceVersion = (_h = opts.serviceVersion) != null ? _h : "0.0.0";
|
|
545
|
+
const localDebugger = typeof process !== "undefined" ? (_i = process.env) == null ? void 0 : _i.RAINDROP_LOCAL_DEBUGGER : void 0;
|
|
546
|
+
if (localDebugger) {
|
|
547
|
+
this.localDebuggerUrl = (_j = resolveLocalDebuggerBaseUrl(localDebugger)) != null ? _j : void 0;
|
|
548
|
+
if (this.debug) {
|
|
549
|
+
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
489
552
|
}
|
|
490
553
|
isDebugEnabled() {
|
|
491
554
|
return this.debug;
|
|
@@ -502,7 +565,25 @@ var TraceShipper = class {
|
|
|
502
565
|
attrString("ai.operationId", args.operationId)
|
|
503
566
|
];
|
|
504
567
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
505
|
-
|
|
568
|
+
const span = { ids, name: args.name, startTimeUnixNano: started, attributes: attrs };
|
|
569
|
+
if (this.localDebuggerUrl) {
|
|
570
|
+
const openSpan = buildOtlpSpan({
|
|
571
|
+
ids: span.ids,
|
|
572
|
+
name: span.name,
|
|
573
|
+
startTimeUnixNano: span.startTimeUnixNano,
|
|
574
|
+
endTimeUnixNano: span.startTimeUnixNano,
|
|
575
|
+
// placeholder — will be updated on endSpan
|
|
576
|
+
attributes: span.attributes,
|
|
577
|
+
status: { code: SpanStatusCode.UNSET }
|
|
578
|
+
});
|
|
579
|
+
const body = buildExportTraceServiceRequest([openSpan], this.serviceName, this.serviceVersion);
|
|
580
|
+
mirrorTraceExportToLocalDebugger(body, {
|
|
581
|
+
baseUrl: this.localDebuggerUrl,
|
|
582
|
+
debug: false,
|
|
583
|
+
sdkName: this.sdkName
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
return span;
|
|
506
587
|
}
|
|
507
588
|
endSpan(span, extra) {
|
|
508
589
|
var _a, _b;
|
|
@@ -525,6 +606,14 @@ var TraceShipper = class {
|
|
|
525
606
|
status
|
|
526
607
|
});
|
|
527
608
|
this.enqueue(otlp);
|
|
609
|
+
if (this.localDebuggerUrl) {
|
|
610
|
+
const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
|
|
611
|
+
mirrorTraceExportToLocalDebugger(body, {
|
|
612
|
+
baseUrl: this.localDebuggerUrl,
|
|
613
|
+
debug: false,
|
|
614
|
+
sdkName: this.sdkName
|
|
615
|
+
});
|
|
616
|
+
}
|
|
528
617
|
}
|
|
529
618
|
createSpan(args) {
|
|
530
619
|
var _a;
|
|
@@ -542,6 +631,14 @@ var TraceShipper = class {
|
|
|
542
631
|
status: args.status
|
|
543
632
|
});
|
|
544
633
|
this.enqueue(otlp);
|
|
634
|
+
if (this.localDebuggerUrl) {
|
|
635
|
+
const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
|
|
636
|
+
mirrorTraceExportToLocalDebugger(body, {
|
|
637
|
+
baseUrl: this.localDebuggerUrl,
|
|
638
|
+
debug: false,
|
|
639
|
+
sdkName: this.sdkName
|
|
640
|
+
});
|
|
641
|
+
}
|
|
545
642
|
}
|
|
546
643
|
enqueue(span) {
|
|
547
644
|
if (!this.enabled) return;
|
|
@@ -737,7 +834,7 @@ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
|
|
|
737
834
|
// package.json
|
|
738
835
|
var package_default = {
|
|
739
836
|
name: "@raindrop-ai/ai-sdk",
|
|
740
|
-
version: "0.0.
|
|
837
|
+
version: "0.0.21"};
|
|
741
838
|
|
|
742
839
|
// src/internal/version.ts
|
|
743
840
|
var libraryName = package_default.name;
|
|
@@ -1543,6 +1640,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
1543
1640
|
]
|
|
1544
1641
|
});
|
|
1545
1642
|
state.toolSpans.set(toolCall.toolCallId, toolSpan);
|
|
1643
|
+
this.emitLive(state, "tool_start", toolCall.toolName, { args: toolCall.input });
|
|
1546
1644
|
};
|
|
1547
1645
|
// ── onToolCallFinish ────────────────────────────────────────────────────
|
|
1548
1646
|
this.onToolCallFinish = (event) => {
|
|
@@ -1557,11 +1655,12 @@ var RaindropTelemetryIntegration = class {
|
|
|
1557
1655
|
} else {
|
|
1558
1656
|
this.traceShipper.endSpan(toolSpan, { error: event.error });
|
|
1559
1657
|
}
|
|
1658
|
+
this.emitLive(state, "tool_result", event.toolCall.toolName);
|
|
1560
1659
|
state.toolSpans.delete(event.toolCall.toolCallId);
|
|
1561
1660
|
};
|
|
1562
1661
|
// ── onChunk (streaming) ─────────────────────────────────────────────────
|
|
1563
1662
|
this.onChunk = (event) => {
|
|
1564
|
-
var _a, _b, _c;
|
|
1663
|
+
var _a, _b, _c, _d, _e;
|
|
1565
1664
|
const callId = (_b = event.callId) != null ? _b : (_a = event.chunk) == null ? void 0 : _a.callId;
|
|
1566
1665
|
if (!callId) return;
|
|
1567
1666
|
const state = this.getState(callId);
|
|
@@ -1572,6 +1671,12 @@ var RaindropTelemetryIntegration = class {
|
|
|
1572
1671
|
const delta = (_c = chunk.textDelta) != null ? _c : chunk.delta;
|
|
1573
1672
|
if (typeof delta === "string") {
|
|
1574
1673
|
state.accumulatedText += delta;
|
|
1674
|
+
this.emitLive(state, "text_delta", delta);
|
|
1675
|
+
}
|
|
1676
|
+
} else if (chunk.type === "reasoning" || chunk.type === "reasoning-delta") {
|
|
1677
|
+
const text = (_e = (_d = chunk.textDelta) != null ? _d : chunk.text) != null ? _e : chunk.delta;
|
|
1678
|
+
if (typeof text === "string") {
|
|
1679
|
+
this.emitLive(state, "reasoning_delta", text);
|
|
1575
1680
|
}
|
|
1576
1681
|
}
|
|
1577
1682
|
};
|
|
@@ -1759,6 +1864,23 @@ var RaindropTelemetryIntegration = class {
|
|
|
1759
1864
|
spanParentRef(span) {
|
|
1760
1865
|
return { traceIdB64: span.ids.traceIdB64, spanIdB64: span.ids.spanIdB64 };
|
|
1761
1866
|
}
|
|
1867
|
+
emitLive(state, type, content, extra) {
|
|
1868
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1869
|
+
if (!localDebuggerEnabled() || !state.rootSpan) return;
|
|
1870
|
+
const callMeta = this.extractRaindropMetadata(state.metadata);
|
|
1871
|
+
sendLocalDebuggerLiveEvent({
|
|
1872
|
+
traceId: state.rootSpan.ids.traceIdB64,
|
|
1873
|
+
type,
|
|
1874
|
+
content,
|
|
1875
|
+
metadata: {
|
|
1876
|
+
userId: (_b = callMeta.userId) != null ? _b : (_a = this.defaultContext) == null ? void 0 : _a.userId,
|
|
1877
|
+
convoId: (_d = callMeta.convoId) != null ? _d : (_c = this.defaultContext) == null ? void 0 : _c.convoId,
|
|
1878
|
+
eventName: (_f = callMeta.eventName) != null ? _f : (_e = this.defaultContext) == null ? void 0 : _e.eventName,
|
|
1879
|
+
eventId: state.eventId,
|
|
1880
|
+
...extra
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1762
1884
|
extractRaindropMetadata(metadata) {
|
|
1763
1885
|
if (!metadata) return {};
|
|
1764
1886
|
const result = {};
|
|
@@ -2304,6 +2426,36 @@ function shouldKeepEventPending(params) {
|
|
|
2304
2426
|
if (params.error != null || !params.canKeepEventPending) return false;
|
|
2305
2427
|
return params.finishReason === "tool-calls" || params.finishReason === "tool_calls";
|
|
2306
2428
|
}
|
|
2429
|
+
function normalizePromptAttr(arg) {
|
|
2430
|
+
if (!isRecord(arg)) return arg;
|
|
2431
|
+
const system = arg["system"];
|
|
2432
|
+
const prompt = arg["prompt"];
|
|
2433
|
+
const messages = arg["messages"];
|
|
2434
|
+
if (Array.isArray(messages)) {
|
|
2435
|
+
if (system) {
|
|
2436
|
+
const sysContent = typeof system === "string" ? system : JSON.stringify(system);
|
|
2437
|
+
return [{ role: "system", content: sysContent }, ...messages];
|
|
2438
|
+
}
|
|
2439
|
+
return messages;
|
|
2440
|
+
}
|
|
2441
|
+
if (typeof prompt === "string") {
|
|
2442
|
+
const msgs = [];
|
|
2443
|
+
if (system) {
|
|
2444
|
+
msgs.push({ role: "system", content: typeof system === "string" ? system : JSON.stringify(system) });
|
|
2445
|
+
}
|
|
2446
|
+
msgs.push({ role: "user", content: prompt });
|
|
2447
|
+
return msgs;
|
|
2448
|
+
}
|
|
2449
|
+
return { system, prompt, messages };
|
|
2450
|
+
}
|
|
2451
|
+
function getLocalDebuggerMetadata(ctx) {
|
|
2452
|
+
return {
|
|
2453
|
+
eventId: ctx.eventId,
|
|
2454
|
+
...ctx.eventName ? { eventName: ctx.eventName } : {},
|
|
2455
|
+
...ctx.userId ? { userId: ctx.userId } : {},
|
|
2456
|
+
...ctx.convoId ? { convoId: ctx.convoId } : {}
|
|
2457
|
+
};
|
|
2458
|
+
}
|
|
2307
2459
|
async function safeFinalize(finalize, debug, result, error) {
|
|
2308
2460
|
try {
|
|
2309
2461
|
await finalize(result, error);
|
|
@@ -2376,17 +2528,17 @@ function setupOperation(params) {
|
|
|
2376
2528
|
attrString("ai.telemetry.functionId", telemetry == null ? void 0 : telemetry.functionId),
|
|
2377
2529
|
attrString("ai.model.provider", modelInfoFromArgs.provider),
|
|
2378
2530
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
2531
|
+
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
2532
|
+
attrString("ai.telemetry.metadata.raindrop.eventName", mergedCtx.eventName),
|
|
2533
|
+
attrString("ai.telemetry.metadata.raindrop.userId", mergedCtx.userId),
|
|
2534
|
+
attrString("ai.telemetry.metadata.raindrop.convoId", mergedCtx.convoId),
|
|
2379
2535
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
2380
2536
|
...attrsFromHeaders(isRecord(arg) ? arg["headers"] : void 0),
|
|
2381
2537
|
...attrsFromSettings(arg),
|
|
2382
2538
|
...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [
|
|
2383
2539
|
attrString(
|
|
2384
2540
|
"ai.prompt",
|
|
2385
|
-
safeJsonWithUint8(
|
|
2386
|
-
system: isRecord(arg) ? arg["system"] : void 0,
|
|
2387
|
-
prompt: isRecord(arg) ? arg["prompt"] : void 0,
|
|
2388
|
-
messages: isRecord(arg) ? arg["messages"] : void 0
|
|
2389
|
-
})
|
|
2541
|
+
safeJsonWithUint8(normalizePromptAttr(arg))
|
|
2390
2542
|
)
|
|
2391
2543
|
]
|
|
2392
2544
|
]
|
|
@@ -2395,6 +2547,7 @@ function setupOperation(params) {
|
|
|
2395
2547
|
const operationSelfDiagnostics = isObjectOperation(operation) ? void 0 : selfDiagnostics;
|
|
2396
2548
|
const wrapCtx = {
|
|
2397
2549
|
eventId,
|
|
2550
|
+
context: mergedCtx,
|
|
2398
2551
|
telemetry,
|
|
2399
2552
|
sendTraces,
|
|
2400
2553
|
debug,
|
|
@@ -2769,6 +2922,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
2769
2922
|
const perCallEventIdGenerated = !perCallEventIdExplicit;
|
|
2770
2923
|
const perCallCtx = {
|
|
2771
2924
|
eventId: perCallEventId,
|
|
2925
|
+
context: wrapTimeCtx,
|
|
2772
2926
|
telemetry,
|
|
2773
2927
|
sendTraces: false,
|
|
2774
2928
|
debug,
|
|
@@ -2923,7 +3077,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
2923
3077
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
2924
3078
|
const inherited = await getCurrentParentSpanContext();
|
|
2925
3079
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
2926
|
-
const ctx = { ...mergedCtx};
|
|
3080
|
+
const ctx = { ...mergedCtx, eventId };
|
|
2927
3081
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
2928
3082
|
const outerOperationId = `ai.${operation}`;
|
|
2929
3083
|
const { operationName, resourceName } = opName(outerOperationId, telemetry == null ? void 0 : telemetry.functionId);
|
|
@@ -2939,17 +3093,17 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
2939
3093
|
attrString("ai.telemetry.functionId", telemetry == null ? void 0 : telemetry.functionId),
|
|
2940
3094
|
attrString("ai.model.provider", modelInfoFromArgs.provider),
|
|
2941
3095
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
3096
|
+
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
3097
|
+
attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
|
|
3098
|
+
attrString("ai.telemetry.metadata.raindrop.userId", ctx.userId),
|
|
3099
|
+
attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
|
|
2942
3100
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
2943
3101
|
...attrsFromHeaders(mergedArgs["headers"]),
|
|
2944
3102
|
...attrsFromSettings(mergedArgs),
|
|
2945
3103
|
...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [
|
|
2946
3104
|
attrString(
|
|
2947
3105
|
"ai.prompt",
|
|
2948
|
-
safeJsonWithUint8({
|
|
2949
|
-
system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"],
|
|
2950
|
-
prompt: mergedArgs["prompt"],
|
|
2951
|
-
messages: mergedArgs["messages"]
|
|
2952
|
-
})
|
|
3106
|
+
safeJsonWithUint8(normalizePromptAttr({ system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"], prompt: mergedArgs["prompt"], messages: mergedArgs["messages"] }))
|
|
2953
3107
|
)
|
|
2954
3108
|
]
|
|
2955
3109
|
]
|
|
@@ -2957,6 +3111,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
2957
3111
|
const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
|
|
2958
3112
|
const wrapCtx = {
|
|
2959
3113
|
eventId,
|
|
3114
|
+
context: ctx,
|
|
2960
3115
|
telemetry,
|
|
2961
3116
|
sendTraces,
|
|
2962
3117
|
debug,
|
|
@@ -3130,7 +3285,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
3130
3285
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
3131
3286
|
const inherited = await getCurrentParentSpanContext();
|
|
3132
3287
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
3133
|
-
const ctx = { ...mergedCtx};
|
|
3288
|
+
const ctx = { ...mergedCtx, eventId };
|
|
3134
3289
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
3135
3290
|
const outerOperationId = `ai.${operation}`;
|
|
3136
3291
|
const { operationName, resourceName } = opName(outerOperationId, telemetry == null ? void 0 : telemetry.functionId);
|
|
@@ -3146,17 +3301,17 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
3146
3301
|
attrString("ai.telemetry.functionId", telemetry == null ? void 0 : telemetry.functionId),
|
|
3147
3302
|
attrString("ai.model.provider", modelInfoFromArgs.provider),
|
|
3148
3303
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
3304
|
+
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
3305
|
+
attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
|
|
3306
|
+
attrString("ai.telemetry.metadata.raindrop.userId", ctx.userId),
|
|
3307
|
+
attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
|
|
3149
3308
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
3150
3309
|
...attrsFromHeaders(mergedArgs["headers"]),
|
|
3151
3310
|
...attrsFromSettings(mergedArgs),
|
|
3152
3311
|
...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [
|
|
3153
3312
|
attrString(
|
|
3154
3313
|
"ai.prompt",
|
|
3155
|
-
safeJsonWithUint8({
|
|
3156
|
-
system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"],
|
|
3157
|
-
prompt: mergedArgs["prompt"],
|
|
3158
|
-
messages: mergedArgs["messages"]
|
|
3159
|
-
})
|
|
3314
|
+
safeJsonWithUint8(normalizePromptAttr({ system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"], prompt: mergedArgs["prompt"], messages: mergedArgs["messages"] }))
|
|
3160
3315
|
)
|
|
3161
3316
|
]
|
|
3162
3317
|
]
|
|
@@ -3164,6 +3319,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
3164
3319
|
const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
|
|
3165
3320
|
const wrapCtx = {
|
|
3166
3321
|
eventId,
|
|
3322
|
+
context: ctx,
|
|
3167
3323
|
telemetry,
|
|
3168
3324
|
sendTraces,
|
|
3169
3325
|
debug,
|
|
@@ -3387,6 +3543,21 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
3387
3543
|
});
|
|
3388
3544
|
}
|
|
3389
3545
|
};
|
|
3546
|
+
const sendToolLiveEvent = (parent, type, metadata) => {
|
|
3547
|
+
if (!localDebuggerEnabled() || !parent) return;
|
|
3548
|
+
sendLocalDebuggerLiveEvent({
|
|
3549
|
+
traceId: parent.traceIdB64,
|
|
3550
|
+
type,
|
|
3551
|
+
content: name,
|
|
3552
|
+
metadata: {
|
|
3553
|
+
...getLocalDebuggerMetadata({
|
|
3554
|
+
...ctx.context,
|
|
3555
|
+
eventId: ctx.eventId
|
|
3556
|
+
}),
|
|
3557
|
+
...metadata
|
|
3558
|
+
}
|
|
3559
|
+
});
|
|
3560
|
+
};
|
|
3390
3561
|
const createContextSpan = (span) => ({
|
|
3391
3562
|
traceIdB64: span.ids.traceIdB64,
|
|
3392
3563
|
spanIdB64: span.ids.spanIdB64,
|
|
@@ -3402,6 +3573,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
3402
3573
|
const parentCtx = await getCurrentParentSpanContext();
|
|
3403
3574
|
const parent = parentCtx && parentCtx.eventId === ctx.eventId ? { traceIdB64: parentCtx.traceIdB64, spanIdB64: parentCtx.spanIdB64 } : ctx.rootParentForChildren;
|
|
3404
3575
|
const toolSpan = createToolSpan(toolCallId, toolArgs, parent);
|
|
3576
|
+
sendToolLiveEvent(parent, "tool_start", { args: toolArgs });
|
|
3405
3577
|
try {
|
|
3406
3578
|
let lastValue;
|
|
3407
3579
|
const iterator = result[Symbol.asyncIterator]();
|
|
@@ -3417,9 +3589,13 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
3417
3589
|
}
|
|
3418
3590
|
toolCalls.push({ id: toolCallId, name, args: toolArgs, result: lastValue, status: "OK" });
|
|
3419
3591
|
endToolSpan(toolSpan, lastValue);
|
|
3592
|
+
sendToolLiveEvent(parent, "tool_result", { result: lastValue });
|
|
3420
3593
|
} catch (error) {
|
|
3421
3594
|
toolCalls.push({ id: toolCallId, name, args: toolArgs, status: "ERROR" });
|
|
3422
3595
|
endToolSpan(toolSpan, void 0, error);
|
|
3596
|
+
sendToolLiveEvent(parent, "tool_result", {
|
|
3597
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3598
|
+
});
|
|
3423
3599
|
throw error;
|
|
3424
3600
|
}
|
|
3425
3601
|
})();
|
|
@@ -3428,6 +3604,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
3428
3604
|
const parentCtx = await getCurrentParentSpanContext();
|
|
3429
3605
|
const parent = parentCtx && parentCtx.eventId === ctx.eventId ? { traceIdB64: parentCtx.traceIdB64, spanIdB64: parentCtx.spanIdB64 } : ctx.rootParentForChildren;
|
|
3430
3606
|
const toolSpan = createToolSpan(toolCallId, toolArgs, parent);
|
|
3607
|
+
sendToolLiveEvent(parent, "tool_start", { args: toolArgs });
|
|
3431
3608
|
const run = async () => {
|
|
3432
3609
|
try {
|
|
3433
3610
|
const awaitedResult = await result;
|
|
@@ -3439,10 +3616,14 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
3439
3616
|
status: "OK"
|
|
3440
3617
|
});
|
|
3441
3618
|
endToolSpan(toolSpan, awaitedResult);
|
|
3619
|
+
sendToolLiveEvent(parent, "tool_result", { result: awaitedResult });
|
|
3442
3620
|
return awaitedResult;
|
|
3443
3621
|
} catch (error) {
|
|
3444
3622
|
toolCalls.push({ id: toolCallId, name, args: toolArgs, status: "ERROR" });
|
|
3445
3623
|
endToolSpan(toolSpan, void 0, error);
|
|
3624
|
+
sendToolLiveEvent(parent, "tool_result", {
|
|
3625
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3626
|
+
});
|
|
3446
3627
|
throw error;
|
|
3447
3628
|
}
|
|
3448
3629
|
};
|
|
@@ -3482,6 +3663,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
3482
3663
|
const original = Reflect.get(target, prop, receiver);
|
|
3483
3664
|
if (prop === "doGenerate" && isFunction(original)) {
|
|
3484
3665
|
return async (...callArgs) => {
|
|
3666
|
+
var _a, _b;
|
|
3485
3667
|
const options = callArgs[0];
|
|
3486
3668
|
const parentCtx = await getCurrentParentSpanContext();
|
|
3487
3669
|
const parent = parentCtx && parentCtx.eventId === ctx.eventId ? { traceIdB64: parentCtx.traceIdB64, spanIdB64: parentCtx.spanIdB64 } : ctx.rootParentForChildren;
|
|
@@ -3489,6 +3671,22 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
3489
3671
|
try {
|
|
3490
3672
|
const result = await original.apply(target, callArgs);
|
|
3491
3673
|
if (span) endDoGenerateSpan(span, result, modelInfo, ctx);
|
|
3674
|
+
if (localDebuggerEnabled() && ctx.rootParentForChildren && isRecord(result)) {
|
|
3675
|
+
const traceId = ctx.rootParentForChildren.traceIdB64;
|
|
3676
|
+
const liveMeta = getLocalDebuggerMetadata({ ...ctx.context, eventId: ctx.eventId });
|
|
3677
|
+
const content = result["content"];
|
|
3678
|
+
if (Array.isArray(content)) {
|
|
3679
|
+
for (const part of content) {
|
|
3680
|
+
if (isRecord(part)) {
|
|
3681
|
+
if ((part["type"] === "reasoning" || part["type"] === "thinking") && typeof ((_a = part["text"]) != null ? _a : part["thinking"]) === "string") {
|
|
3682
|
+
sendLocalDebuggerLiveEvent({ traceId, type: "reasoning_delta", content: (_b = part["text"]) != null ? _b : part["thinking"], metadata: liveMeta });
|
|
3683
|
+
} else if (part["type"] === "text" && typeof part["text"] === "string") {
|
|
3684
|
+
sendLocalDebuggerLiveEvent({ traceId, type: "text_delta", content: part["text"], metadata: liveMeta });
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3492
3690
|
return result;
|
|
3493
3691
|
} catch (error) {
|
|
3494
3692
|
if (span)
|
|
@@ -3628,6 +3826,23 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
3628
3826
|
}
|
|
3629
3827
|
if ("usage" in value) usage = value["usage"];
|
|
3630
3828
|
if ("providerMetadata" in value) providerMetadata = value["providerMetadata"];
|
|
3829
|
+
if (localDebuggerEnabled() && ctx.rootParentForChildren) {
|
|
3830
|
+
const traceId = ctx.rootParentForChildren.traceIdB64;
|
|
3831
|
+
const liveMeta = getLocalDebuggerMetadata({ ...ctx.context, eventId: ctx.eventId });
|
|
3832
|
+
if (type === "text-delta") {
|
|
3833
|
+
const text = typeof value["delta"] === "string" ? value["delta"] : typeof value["textDelta"] === "string" ? value["textDelta"] : typeof value["text"] === "string" ? value["text"] : void 0;
|
|
3834
|
+
if (typeof text === "string" && text) sendLocalDebuggerLiveEvent({ traceId, type: "text_delta", content: text, metadata: liveMeta });
|
|
3835
|
+
} else if (type === "reasoning" || type === "reasoning-delta") {
|
|
3836
|
+
const text = typeof value["delta"] === "string" ? value["delta"] : typeof value["text"] === "string" ? value["text"] : typeof value["thinking"] === "string" ? value["thinking"] : void 0;
|
|
3837
|
+
if (typeof text === "string" && text) sendLocalDebuggerLiveEvent({ traceId, type: "reasoning_delta", content: text, metadata: liveMeta });
|
|
3838
|
+
} else if (type === "tool-call") {
|
|
3839
|
+
const toolName = typeof value["toolName"] === "string" ? value["toolName"] : "tool";
|
|
3840
|
+
sendLocalDebuggerLiveEvent({ traceId, type: "tool_start", content: toolName, metadata: { ...liveMeta, args: value["args"] } });
|
|
3841
|
+
} else if (type === "tool-result") {
|
|
3842
|
+
const toolName = typeof value["toolName"] === "string" ? value["toolName"] : "tool";
|
|
3843
|
+
sendLocalDebuggerLiveEvent({ traceId, type: "tool_result", content: toolName, metadata: { ...liveMeta, result: value["result"] } });
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3631
3846
|
}
|
|
3632
3847
|
controller.enqueue(value);
|
|
3633
3848
|
} catch (error) {
|
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, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-BTNDCDA3.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, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-
|
|
1
|
+
export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-CPArLupC.mjs';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
|
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, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-
|
|
1
|
+
export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-CPArLupC.js';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
|