@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.browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// ../core/dist/chunk-
|
|
3
|
+
// ../core/dist/chunk-4UCYIEH4.js
|
|
4
4
|
function getCrypto() {
|
|
5
5
|
const c = globalThis.crypto;
|
|
6
6
|
return c;
|
|
@@ -145,6 +145,7 @@ async function postJson(url, body, headers, opts) {
|
|
|
145
145
|
);
|
|
146
146
|
}
|
|
147
147
|
var SpanStatusCode = {
|
|
148
|
+
UNSET: 0,
|
|
148
149
|
ERROR: 2
|
|
149
150
|
};
|
|
150
151
|
function createSpanIds(parent) {
|
|
@@ -465,11 +466,66 @@ var EventShipper = class {
|
|
|
465
466
|
}
|
|
466
467
|
}
|
|
467
468
|
};
|
|
469
|
+
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
470
|
+
function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
471
|
+
var _a, _b, _c;
|
|
472
|
+
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;
|
|
473
|
+
return resolved ? (_c = formatEndpoint(resolved)) != null ? _c : null : null;
|
|
474
|
+
}
|
|
475
|
+
function localDebuggerEnabled(baseUrl) {
|
|
476
|
+
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
477
|
+
}
|
|
478
|
+
function normalizeLocalDebuggerLiveEventType(type) {
|
|
479
|
+
switch (type) {
|
|
480
|
+
case "text-delta":
|
|
481
|
+
return "text_delta";
|
|
482
|
+
case "reasoning":
|
|
483
|
+
case "reasoning-delta":
|
|
484
|
+
return "reasoning_delta";
|
|
485
|
+
case "tool-call":
|
|
486
|
+
return "tool_start";
|
|
487
|
+
case "tool-result":
|
|
488
|
+
return "tool_result";
|
|
489
|
+
default:
|
|
490
|
+
return type;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
494
|
+
var _a;
|
|
495
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
496
|
+
if (!baseUrl) return;
|
|
497
|
+
void postJson(`${baseUrl}traces`, body, {}, {
|
|
498
|
+
maxAttempts: 1,
|
|
499
|
+
debug: (_a = options.debug) != null ? _a : false,
|
|
500
|
+
sdkName: options.sdkName
|
|
501
|
+
}).catch(() => {
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
505
|
+
var _a, _b;
|
|
506
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
507
|
+
if (!baseUrl) return;
|
|
508
|
+
void postJson(
|
|
509
|
+
`${baseUrl}live`,
|
|
510
|
+
{
|
|
511
|
+
...event,
|
|
512
|
+
type: normalizeLocalDebuggerLiveEventType(event.type),
|
|
513
|
+
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
514
|
+
},
|
|
515
|
+
{},
|
|
516
|
+
{
|
|
517
|
+
maxAttempts: 1,
|
|
518
|
+
debug: (_b = options.debug) != null ? _b : false,
|
|
519
|
+
sdkName: options.sdkName
|
|
520
|
+
}
|
|
521
|
+
).catch(() => {
|
|
522
|
+
});
|
|
523
|
+
}
|
|
468
524
|
var TraceShipper = class {
|
|
469
525
|
constructor(opts) {
|
|
470
526
|
this.queue = [];
|
|
471
527
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
472
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
528
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
473
529
|
this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
|
|
474
530
|
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
475
531
|
this.enabled = opts.enabled !== false;
|
|
@@ -482,6 +538,13 @@ var TraceShipper = class {
|
|
|
482
538
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
483
539
|
this.serviceName = (_g = opts.serviceName) != null ? _g : "raindrop.core";
|
|
484
540
|
this.serviceVersion = (_h = opts.serviceVersion) != null ? _h : "0.0.0";
|
|
541
|
+
const localDebugger = typeof process !== "undefined" ? (_i = process.env) == null ? void 0 : _i.RAINDROP_LOCAL_DEBUGGER : void 0;
|
|
542
|
+
if (localDebugger) {
|
|
543
|
+
this.localDebuggerUrl = (_j = resolveLocalDebuggerBaseUrl(localDebugger)) != null ? _j : void 0;
|
|
544
|
+
if (this.debug) {
|
|
545
|
+
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
485
548
|
}
|
|
486
549
|
isDebugEnabled() {
|
|
487
550
|
return this.debug;
|
|
@@ -498,7 +561,25 @@ var TraceShipper = class {
|
|
|
498
561
|
attrString("ai.operationId", args.operationId)
|
|
499
562
|
];
|
|
500
563
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
501
|
-
|
|
564
|
+
const span = { ids, name: args.name, startTimeUnixNano: started, attributes: attrs };
|
|
565
|
+
if (this.localDebuggerUrl) {
|
|
566
|
+
const openSpan = buildOtlpSpan({
|
|
567
|
+
ids: span.ids,
|
|
568
|
+
name: span.name,
|
|
569
|
+
startTimeUnixNano: span.startTimeUnixNano,
|
|
570
|
+
endTimeUnixNano: span.startTimeUnixNano,
|
|
571
|
+
// placeholder — will be updated on endSpan
|
|
572
|
+
attributes: span.attributes,
|
|
573
|
+
status: { code: SpanStatusCode.UNSET }
|
|
574
|
+
});
|
|
575
|
+
const body = buildExportTraceServiceRequest([openSpan], this.serviceName, this.serviceVersion);
|
|
576
|
+
mirrorTraceExportToLocalDebugger(body, {
|
|
577
|
+
baseUrl: this.localDebuggerUrl,
|
|
578
|
+
debug: false,
|
|
579
|
+
sdkName: this.sdkName
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
return span;
|
|
502
583
|
}
|
|
503
584
|
endSpan(span, extra) {
|
|
504
585
|
var _a, _b;
|
|
@@ -521,6 +602,14 @@ var TraceShipper = class {
|
|
|
521
602
|
status
|
|
522
603
|
});
|
|
523
604
|
this.enqueue(otlp);
|
|
605
|
+
if (this.localDebuggerUrl) {
|
|
606
|
+
const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
|
|
607
|
+
mirrorTraceExportToLocalDebugger(body, {
|
|
608
|
+
baseUrl: this.localDebuggerUrl,
|
|
609
|
+
debug: false,
|
|
610
|
+
sdkName: this.sdkName
|
|
611
|
+
});
|
|
612
|
+
}
|
|
524
613
|
}
|
|
525
614
|
createSpan(args) {
|
|
526
615
|
var _a;
|
|
@@ -538,6 +627,14 @@ var TraceShipper = class {
|
|
|
538
627
|
status: args.status
|
|
539
628
|
});
|
|
540
629
|
this.enqueue(otlp);
|
|
630
|
+
if (this.localDebuggerUrl) {
|
|
631
|
+
const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
|
|
632
|
+
mirrorTraceExportToLocalDebugger(body, {
|
|
633
|
+
baseUrl: this.localDebuggerUrl,
|
|
634
|
+
debug: false,
|
|
635
|
+
sdkName: this.sdkName
|
|
636
|
+
});
|
|
637
|
+
}
|
|
541
638
|
}
|
|
542
639
|
enqueue(span) {
|
|
543
640
|
if (!this.enabled) return;
|
|
@@ -732,7 +829,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
|
|
|
732
829
|
// package.json
|
|
733
830
|
var package_default = {
|
|
734
831
|
name: "@raindrop-ai/ai-sdk",
|
|
735
|
-
version: "0.0.
|
|
832
|
+
version: "0.0.21"};
|
|
736
833
|
|
|
737
834
|
// src/internal/version.ts
|
|
738
835
|
var libraryName = package_default.name;
|
|
@@ -1538,6 +1635,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
1538
1635
|
]
|
|
1539
1636
|
});
|
|
1540
1637
|
state.toolSpans.set(toolCall.toolCallId, toolSpan);
|
|
1638
|
+
this.emitLive(state, "tool_start", toolCall.toolName, { args: toolCall.input });
|
|
1541
1639
|
};
|
|
1542
1640
|
// ── onToolCallFinish ────────────────────────────────────────────────────
|
|
1543
1641
|
this.onToolCallFinish = (event) => {
|
|
@@ -1552,11 +1650,12 @@ var RaindropTelemetryIntegration = class {
|
|
|
1552
1650
|
} else {
|
|
1553
1651
|
this.traceShipper.endSpan(toolSpan, { error: event.error });
|
|
1554
1652
|
}
|
|
1653
|
+
this.emitLive(state, "tool_result", event.toolCall.toolName);
|
|
1555
1654
|
state.toolSpans.delete(event.toolCall.toolCallId);
|
|
1556
1655
|
};
|
|
1557
1656
|
// ── onChunk (streaming) ─────────────────────────────────────────────────
|
|
1558
1657
|
this.onChunk = (event) => {
|
|
1559
|
-
var _a, _b, _c;
|
|
1658
|
+
var _a, _b, _c, _d, _e;
|
|
1560
1659
|
const callId = (_b = event.callId) != null ? _b : (_a = event.chunk) == null ? void 0 : _a.callId;
|
|
1561
1660
|
if (!callId) return;
|
|
1562
1661
|
const state = this.getState(callId);
|
|
@@ -1567,6 +1666,12 @@ var RaindropTelemetryIntegration = class {
|
|
|
1567
1666
|
const delta = (_c = chunk.textDelta) != null ? _c : chunk.delta;
|
|
1568
1667
|
if (typeof delta === "string") {
|
|
1569
1668
|
state.accumulatedText += delta;
|
|
1669
|
+
this.emitLive(state, "text_delta", delta);
|
|
1670
|
+
}
|
|
1671
|
+
} else if (chunk.type === "reasoning" || chunk.type === "reasoning-delta") {
|
|
1672
|
+
const text = (_e = (_d = chunk.textDelta) != null ? _d : chunk.text) != null ? _e : chunk.delta;
|
|
1673
|
+
if (typeof text === "string") {
|
|
1674
|
+
this.emitLive(state, "reasoning_delta", text);
|
|
1570
1675
|
}
|
|
1571
1676
|
}
|
|
1572
1677
|
};
|
|
@@ -1754,6 +1859,23 @@ var RaindropTelemetryIntegration = class {
|
|
|
1754
1859
|
spanParentRef(span) {
|
|
1755
1860
|
return { traceIdB64: span.ids.traceIdB64, spanIdB64: span.ids.spanIdB64 };
|
|
1756
1861
|
}
|
|
1862
|
+
emitLive(state, type, content, extra) {
|
|
1863
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1864
|
+
if (!localDebuggerEnabled() || !state.rootSpan) return;
|
|
1865
|
+
const callMeta = this.extractRaindropMetadata(state.metadata);
|
|
1866
|
+
sendLocalDebuggerLiveEvent({
|
|
1867
|
+
traceId: state.rootSpan.ids.traceIdB64,
|
|
1868
|
+
type,
|
|
1869
|
+
content,
|
|
1870
|
+
metadata: {
|
|
1871
|
+
userId: (_b = callMeta.userId) != null ? _b : (_a = this.defaultContext) == null ? void 0 : _a.userId,
|
|
1872
|
+
convoId: (_d = callMeta.convoId) != null ? _d : (_c = this.defaultContext) == null ? void 0 : _c.convoId,
|
|
1873
|
+
eventName: (_f = callMeta.eventName) != null ? _f : (_e = this.defaultContext) == null ? void 0 : _e.eventName,
|
|
1874
|
+
eventId: state.eventId,
|
|
1875
|
+
...extra
|
|
1876
|
+
}
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1757
1879
|
extractRaindropMetadata(metadata) {
|
|
1758
1880
|
if (!metadata) return {};
|
|
1759
1881
|
const result = {};
|
|
@@ -2299,6 +2421,36 @@ function shouldKeepEventPending(params) {
|
|
|
2299
2421
|
if (params.error != null || !params.canKeepEventPending) return false;
|
|
2300
2422
|
return params.finishReason === "tool-calls" || params.finishReason === "tool_calls";
|
|
2301
2423
|
}
|
|
2424
|
+
function normalizePromptAttr(arg) {
|
|
2425
|
+
if (!isRecord(arg)) return arg;
|
|
2426
|
+
const system = arg["system"];
|
|
2427
|
+
const prompt = arg["prompt"];
|
|
2428
|
+
const messages = arg["messages"];
|
|
2429
|
+
if (Array.isArray(messages)) {
|
|
2430
|
+
if (system) {
|
|
2431
|
+
const sysContent = typeof system === "string" ? system : JSON.stringify(system);
|
|
2432
|
+
return [{ role: "system", content: sysContent }, ...messages];
|
|
2433
|
+
}
|
|
2434
|
+
return messages;
|
|
2435
|
+
}
|
|
2436
|
+
if (typeof prompt === "string") {
|
|
2437
|
+
const msgs = [];
|
|
2438
|
+
if (system) {
|
|
2439
|
+
msgs.push({ role: "system", content: typeof system === "string" ? system : JSON.stringify(system) });
|
|
2440
|
+
}
|
|
2441
|
+
msgs.push({ role: "user", content: prompt });
|
|
2442
|
+
return msgs;
|
|
2443
|
+
}
|
|
2444
|
+
return { system, prompt, messages };
|
|
2445
|
+
}
|
|
2446
|
+
function getLocalDebuggerMetadata(ctx) {
|
|
2447
|
+
return {
|
|
2448
|
+
eventId: ctx.eventId,
|
|
2449
|
+
...ctx.eventName ? { eventName: ctx.eventName } : {},
|
|
2450
|
+
...ctx.userId ? { userId: ctx.userId } : {},
|
|
2451
|
+
...ctx.convoId ? { convoId: ctx.convoId } : {}
|
|
2452
|
+
};
|
|
2453
|
+
}
|
|
2302
2454
|
async function safeFinalize(finalize, debug, result, error) {
|
|
2303
2455
|
try {
|
|
2304
2456
|
await finalize(result, error);
|
|
@@ -2371,17 +2523,17 @@ function setupOperation(params) {
|
|
|
2371
2523
|
attrString("ai.telemetry.functionId", telemetry == null ? void 0 : telemetry.functionId),
|
|
2372
2524
|
attrString("ai.model.provider", modelInfoFromArgs.provider),
|
|
2373
2525
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
2526
|
+
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
2527
|
+
attrString("ai.telemetry.metadata.raindrop.eventName", mergedCtx.eventName),
|
|
2528
|
+
attrString("ai.telemetry.metadata.raindrop.userId", mergedCtx.userId),
|
|
2529
|
+
attrString("ai.telemetry.metadata.raindrop.convoId", mergedCtx.convoId),
|
|
2374
2530
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
2375
2531
|
...attrsFromHeaders(isRecord(arg) ? arg["headers"] : void 0),
|
|
2376
2532
|
...attrsFromSettings(arg),
|
|
2377
2533
|
...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [
|
|
2378
2534
|
attrString(
|
|
2379
2535
|
"ai.prompt",
|
|
2380
|
-
safeJsonWithUint8(
|
|
2381
|
-
system: isRecord(arg) ? arg["system"] : void 0,
|
|
2382
|
-
prompt: isRecord(arg) ? arg["prompt"] : void 0,
|
|
2383
|
-
messages: isRecord(arg) ? arg["messages"] : void 0
|
|
2384
|
-
})
|
|
2536
|
+
safeJsonWithUint8(normalizePromptAttr(arg))
|
|
2385
2537
|
)
|
|
2386
2538
|
]
|
|
2387
2539
|
]
|
|
@@ -2390,6 +2542,7 @@ function setupOperation(params) {
|
|
|
2390
2542
|
const operationSelfDiagnostics = isObjectOperation(operation) ? void 0 : selfDiagnostics;
|
|
2391
2543
|
const wrapCtx = {
|
|
2392
2544
|
eventId,
|
|
2545
|
+
context: mergedCtx,
|
|
2393
2546
|
telemetry,
|
|
2394
2547
|
sendTraces,
|
|
2395
2548
|
debug,
|
|
@@ -2764,6 +2917,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
2764
2917
|
const perCallEventIdGenerated = !perCallEventIdExplicit;
|
|
2765
2918
|
const perCallCtx = {
|
|
2766
2919
|
eventId: perCallEventId,
|
|
2920
|
+
context: wrapTimeCtx,
|
|
2767
2921
|
telemetry,
|
|
2768
2922
|
sendTraces: false,
|
|
2769
2923
|
debug,
|
|
@@ -2918,7 +3072,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
2918
3072
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
2919
3073
|
const inherited = await getCurrentParentSpanContext();
|
|
2920
3074
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
2921
|
-
const ctx = { ...mergedCtx};
|
|
3075
|
+
const ctx = { ...mergedCtx, eventId };
|
|
2922
3076
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
2923
3077
|
const outerOperationId = `ai.${operation}`;
|
|
2924
3078
|
const { operationName, resourceName } = opName(outerOperationId, telemetry == null ? void 0 : telemetry.functionId);
|
|
@@ -2934,17 +3088,17 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
2934
3088
|
attrString("ai.telemetry.functionId", telemetry == null ? void 0 : telemetry.functionId),
|
|
2935
3089
|
attrString("ai.model.provider", modelInfoFromArgs.provider),
|
|
2936
3090
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
3091
|
+
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
3092
|
+
attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
|
|
3093
|
+
attrString("ai.telemetry.metadata.raindrop.userId", ctx.userId),
|
|
3094
|
+
attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
|
|
2937
3095
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
2938
3096
|
...attrsFromHeaders(mergedArgs["headers"]),
|
|
2939
3097
|
...attrsFromSettings(mergedArgs),
|
|
2940
3098
|
...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [
|
|
2941
3099
|
attrString(
|
|
2942
3100
|
"ai.prompt",
|
|
2943
|
-
safeJsonWithUint8({
|
|
2944
|
-
system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"],
|
|
2945
|
-
prompt: mergedArgs["prompt"],
|
|
2946
|
-
messages: mergedArgs["messages"]
|
|
2947
|
-
})
|
|
3101
|
+
safeJsonWithUint8(normalizePromptAttr({ system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"], prompt: mergedArgs["prompt"], messages: mergedArgs["messages"] }))
|
|
2948
3102
|
)
|
|
2949
3103
|
]
|
|
2950
3104
|
]
|
|
@@ -2952,6 +3106,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
2952
3106
|
const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
|
|
2953
3107
|
const wrapCtx = {
|
|
2954
3108
|
eventId,
|
|
3109
|
+
context: ctx,
|
|
2955
3110
|
telemetry,
|
|
2956
3111
|
sendTraces,
|
|
2957
3112
|
debug,
|
|
@@ -3125,7 +3280,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
3125
3280
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
3126
3281
|
const inherited = await getCurrentParentSpanContext();
|
|
3127
3282
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
3128
|
-
const ctx = { ...mergedCtx};
|
|
3283
|
+
const ctx = { ...mergedCtx, eventId };
|
|
3129
3284
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
3130
3285
|
const outerOperationId = `ai.${operation}`;
|
|
3131
3286
|
const { operationName, resourceName } = opName(outerOperationId, telemetry == null ? void 0 : telemetry.functionId);
|
|
@@ -3141,17 +3296,17 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
3141
3296
|
attrString("ai.telemetry.functionId", telemetry == null ? void 0 : telemetry.functionId),
|
|
3142
3297
|
attrString("ai.model.provider", modelInfoFromArgs.provider),
|
|
3143
3298
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
3299
|
+
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
3300
|
+
attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
|
|
3301
|
+
attrString("ai.telemetry.metadata.raindrop.userId", ctx.userId),
|
|
3302
|
+
attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
|
|
3144
3303
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
3145
3304
|
...attrsFromHeaders(mergedArgs["headers"]),
|
|
3146
3305
|
...attrsFromSettings(mergedArgs),
|
|
3147
3306
|
...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [
|
|
3148
3307
|
attrString(
|
|
3149
3308
|
"ai.prompt",
|
|
3150
|
-
safeJsonWithUint8({
|
|
3151
|
-
system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"],
|
|
3152
|
-
prompt: mergedArgs["prompt"],
|
|
3153
|
-
messages: mergedArgs["messages"]
|
|
3154
|
-
})
|
|
3309
|
+
safeJsonWithUint8(normalizePromptAttr({ system: (_d = mergedArgs["system"]) != null ? _d : mergedArgs["instructions"], prompt: mergedArgs["prompt"], messages: mergedArgs["messages"] }))
|
|
3155
3310
|
)
|
|
3156
3311
|
]
|
|
3157
3312
|
]
|
|
@@ -3159,6 +3314,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
3159
3314
|
const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
|
|
3160
3315
|
const wrapCtx = {
|
|
3161
3316
|
eventId,
|
|
3317
|
+
context: ctx,
|
|
3162
3318
|
telemetry,
|
|
3163
3319
|
sendTraces,
|
|
3164
3320
|
debug,
|
|
@@ -3382,6 +3538,21 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
3382
3538
|
});
|
|
3383
3539
|
}
|
|
3384
3540
|
};
|
|
3541
|
+
const sendToolLiveEvent = (parent, type, metadata) => {
|
|
3542
|
+
if (!localDebuggerEnabled() || !parent) return;
|
|
3543
|
+
sendLocalDebuggerLiveEvent({
|
|
3544
|
+
traceId: parent.traceIdB64,
|
|
3545
|
+
type,
|
|
3546
|
+
content: name,
|
|
3547
|
+
metadata: {
|
|
3548
|
+
...getLocalDebuggerMetadata({
|
|
3549
|
+
...ctx.context,
|
|
3550
|
+
eventId: ctx.eventId
|
|
3551
|
+
}),
|
|
3552
|
+
...metadata
|
|
3553
|
+
}
|
|
3554
|
+
});
|
|
3555
|
+
};
|
|
3385
3556
|
const createContextSpan = (span) => ({
|
|
3386
3557
|
traceIdB64: span.ids.traceIdB64,
|
|
3387
3558
|
spanIdB64: span.ids.spanIdB64,
|
|
@@ -3397,6 +3568,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
3397
3568
|
const parentCtx = await getCurrentParentSpanContext();
|
|
3398
3569
|
const parent = parentCtx && parentCtx.eventId === ctx.eventId ? { traceIdB64: parentCtx.traceIdB64, spanIdB64: parentCtx.spanIdB64 } : ctx.rootParentForChildren;
|
|
3399
3570
|
const toolSpan = createToolSpan(toolCallId, toolArgs, parent);
|
|
3571
|
+
sendToolLiveEvent(parent, "tool_start", { args: toolArgs });
|
|
3400
3572
|
try {
|
|
3401
3573
|
let lastValue;
|
|
3402
3574
|
const iterator = result[Symbol.asyncIterator]();
|
|
@@ -3412,9 +3584,13 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
3412
3584
|
}
|
|
3413
3585
|
toolCalls.push({ id: toolCallId, name, args: toolArgs, result: lastValue, status: "OK" });
|
|
3414
3586
|
endToolSpan(toolSpan, lastValue);
|
|
3587
|
+
sendToolLiveEvent(parent, "tool_result", { result: lastValue });
|
|
3415
3588
|
} catch (error) {
|
|
3416
3589
|
toolCalls.push({ id: toolCallId, name, args: toolArgs, status: "ERROR" });
|
|
3417
3590
|
endToolSpan(toolSpan, void 0, error);
|
|
3591
|
+
sendToolLiveEvent(parent, "tool_result", {
|
|
3592
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3593
|
+
});
|
|
3418
3594
|
throw error;
|
|
3419
3595
|
}
|
|
3420
3596
|
})();
|
|
@@ -3423,6 +3599,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
3423
3599
|
const parentCtx = await getCurrentParentSpanContext();
|
|
3424
3600
|
const parent = parentCtx && parentCtx.eventId === ctx.eventId ? { traceIdB64: parentCtx.traceIdB64, spanIdB64: parentCtx.spanIdB64 } : ctx.rootParentForChildren;
|
|
3425
3601
|
const toolSpan = createToolSpan(toolCallId, toolArgs, parent);
|
|
3602
|
+
sendToolLiveEvent(parent, "tool_start", { args: toolArgs });
|
|
3426
3603
|
const run = async () => {
|
|
3427
3604
|
try {
|
|
3428
3605
|
const awaitedResult = await result;
|
|
@@ -3434,10 +3611,14 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
3434
3611
|
status: "OK"
|
|
3435
3612
|
});
|
|
3436
3613
|
endToolSpan(toolSpan, awaitedResult);
|
|
3614
|
+
sendToolLiveEvent(parent, "tool_result", { result: awaitedResult });
|
|
3437
3615
|
return awaitedResult;
|
|
3438
3616
|
} catch (error) {
|
|
3439
3617
|
toolCalls.push({ id: toolCallId, name, args: toolArgs, status: "ERROR" });
|
|
3440
3618
|
endToolSpan(toolSpan, void 0, error);
|
|
3619
|
+
sendToolLiveEvent(parent, "tool_result", {
|
|
3620
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3621
|
+
});
|
|
3441
3622
|
throw error;
|
|
3442
3623
|
}
|
|
3443
3624
|
};
|
|
@@ -3477,6 +3658,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
3477
3658
|
const original = Reflect.get(target, prop, receiver);
|
|
3478
3659
|
if (prop === "doGenerate" && isFunction(original)) {
|
|
3479
3660
|
return async (...callArgs) => {
|
|
3661
|
+
var _a, _b;
|
|
3480
3662
|
const options = callArgs[0];
|
|
3481
3663
|
const parentCtx = await getCurrentParentSpanContext();
|
|
3482
3664
|
const parent = parentCtx && parentCtx.eventId === ctx.eventId ? { traceIdB64: parentCtx.traceIdB64, spanIdB64: parentCtx.spanIdB64 } : ctx.rootParentForChildren;
|
|
@@ -3484,6 +3666,22 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
3484
3666
|
try {
|
|
3485
3667
|
const result = await original.apply(target, callArgs);
|
|
3486
3668
|
if (span) endDoGenerateSpan(span, result, modelInfo, ctx);
|
|
3669
|
+
if (localDebuggerEnabled() && ctx.rootParentForChildren && isRecord(result)) {
|
|
3670
|
+
const traceId = ctx.rootParentForChildren.traceIdB64;
|
|
3671
|
+
const liveMeta = getLocalDebuggerMetadata({ ...ctx.context, eventId: ctx.eventId });
|
|
3672
|
+
const content = result["content"];
|
|
3673
|
+
if (Array.isArray(content)) {
|
|
3674
|
+
for (const part of content) {
|
|
3675
|
+
if (isRecord(part)) {
|
|
3676
|
+
if ((part["type"] === "reasoning" || part["type"] === "thinking") && typeof ((_a = part["text"]) != null ? _a : part["thinking"]) === "string") {
|
|
3677
|
+
sendLocalDebuggerLiveEvent({ traceId, type: "reasoning_delta", content: (_b = part["text"]) != null ? _b : part["thinking"], metadata: liveMeta });
|
|
3678
|
+
} else if (part["type"] === "text" && typeof part["text"] === "string") {
|
|
3679
|
+
sendLocalDebuggerLiveEvent({ traceId, type: "text_delta", content: part["text"], metadata: liveMeta });
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3487
3685
|
return result;
|
|
3488
3686
|
} catch (error) {
|
|
3489
3687
|
if (span)
|
|
@@ -3623,6 +3821,23 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
3623
3821
|
}
|
|
3624
3822
|
if ("usage" in value) usage = value["usage"];
|
|
3625
3823
|
if ("providerMetadata" in value) providerMetadata = value["providerMetadata"];
|
|
3824
|
+
if (localDebuggerEnabled() && ctx.rootParentForChildren) {
|
|
3825
|
+
const traceId = ctx.rootParentForChildren.traceIdB64;
|
|
3826
|
+
const liveMeta = getLocalDebuggerMetadata({ ...ctx.context, eventId: ctx.eventId });
|
|
3827
|
+
if (type === "text-delta") {
|
|
3828
|
+
const text = typeof value["delta"] === "string" ? value["delta"] : typeof value["textDelta"] === "string" ? value["textDelta"] : typeof value["text"] === "string" ? value["text"] : void 0;
|
|
3829
|
+
if (typeof text === "string" && text) sendLocalDebuggerLiveEvent({ traceId, type: "text_delta", content: text, metadata: liveMeta });
|
|
3830
|
+
} else if (type === "reasoning" || type === "reasoning-delta") {
|
|
3831
|
+
const text = typeof value["delta"] === "string" ? value["delta"] : typeof value["text"] === "string" ? value["text"] : typeof value["thinking"] === "string" ? value["thinking"] : void 0;
|
|
3832
|
+
if (typeof text === "string" && text) sendLocalDebuggerLiveEvent({ traceId, type: "reasoning_delta", content: text, metadata: liveMeta });
|
|
3833
|
+
} else if (type === "tool-call") {
|
|
3834
|
+
const toolName = typeof value["toolName"] === "string" ? value["toolName"] : "tool";
|
|
3835
|
+
sendLocalDebuggerLiveEvent({ traceId, type: "tool_start", content: toolName, metadata: { ...liveMeta, args: value["args"] } });
|
|
3836
|
+
} else if (type === "tool-result") {
|
|
3837
|
+
const toolName = typeof value["toolName"] === "string" ? value["toolName"] : "tool";
|
|
3838
|
+
sendLocalDebuggerLiveEvent({ traceId, type: "tool_result", content: toolName, metadata: { ...liveMeta, result: value["result"] } });
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3626
3841
|
}
|
|
3627
3842
|
controller.enqueue(value);
|
|
3628
3843
|
} catch (error) {
|