@raindrop-ai/ai-sdk 0.1.0 → 0.2.0
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/dist/{chunk-ETGFVXYM.mjs → chunk-RBVZVH46.mjs} +114 -24
- package/dist/{index-CUR4qgwL.d.mts → index-BUWOlY-2.d.mts} +57 -8
- package/dist/{index-CUR4qgwL.d.ts → index-BUWOlY-2.d.ts} +57 -8
- package/dist/index.browser.d.mts +57 -8
- package/dist/index.browser.d.ts +57 -8
- package/dist/index.browser.js +114 -24
- package/dist/index.browser.mjs +114 -24
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +114 -24
- 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 +114 -24
- package/dist/index.workers.mjs +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
2
|
|
|
3
|
-
// ../core/dist/chunk-
|
|
3
|
+
// ../core/dist/chunk-QTUH3BHZ.js
|
|
4
4
|
function normalizeFeatureFlags(input) {
|
|
5
5
|
if (Array.isArray(input)) {
|
|
6
6
|
return Object.fromEntries(input.map((name) => [name, "true"]));
|
|
@@ -443,19 +443,52 @@ function projectIdHeaders(projectId) {
|
|
|
443
443
|
var SHUTDOWN_DEADLINE_MS = 1e4;
|
|
444
444
|
var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
445
445
|
function mergePatches(target, source) {
|
|
446
|
-
var _a, _b, _c, _d, _e, _f;
|
|
446
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
447
447
|
const out = { ...target, ...source };
|
|
448
448
|
if (target.properties || source.properties) {
|
|
449
449
|
out.properties = { ...(_a = target.properties) != null ? _a : {}, ...(_b = source.properties) != null ? _b : {} };
|
|
450
450
|
}
|
|
451
|
+
if (target.usage || source.usage) {
|
|
452
|
+
out.usage = { ...(_c = target.usage) != null ? _c : {} };
|
|
453
|
+
if (((_d = source.usage) == null ? void 0 : _d.promptTokens) !== void 0) {
|
|
454
|
+
out.usage.promptTokens = source.usage.promptTokens;
|
|
455
|
+
}
|
|
456
|
+
if (((_e = source.usage) == null ? void 0 : _e.completionTokens) !== void 0) {
|
|
457
|
+
out.usage.completionTokens = source.usage.completionTokens;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (source.error === void 0) {
|
|
461
|
+
out.error = target.error;
|
|
462
|
+
}
|
|
451
463
|
if (target.featureFlags || source.featureFlags) {
|
|
452
|
-
out.featureFlags = { ...(
|
|
464
|
+
out.featureFlags = { ...(_f = target.featureFlags) != null ? _f : {}, ...(_g = source.featureFlags) != null ? _g : {} };
|
|
453
465
|
}
|
|
454
466
|
if (target.attachments || source.attachments) {
|
|
455
|
-
out.attachments = [...(
|
|
467
|
+
out.attachments = [...(_h = target.attachments) != null ? _h : [], ...(_i = source.attachments) != null ? _i : []];
|
|
456
468
|
}
|
|
457
469
|
return out;
|
|
458
470
|
}
|
|
471
|
+
function isErrorLike(value) {
|
|
472
|
+
return value !== null && typeof value === "object";
|
|
473
|
+
}
|
|
474
|
+
function eventTelemetryProperties(patch) {
|
|
475
|
+
var _a, _b;
|
|
476
|
+
const properties = {};
|
|
477
|
+
if (((_a = patch.usage) == null ? void 0 : _a.promptTokens) !== void 0 && Number.isFinite(patch.usage.promptTokens)) {
|
|
478
|
+
properties["ai.usage.prompt_tokens"] = patch.usage.promptTokens;
|
|
479
|
+
}
|
|
480
|
+
if (((_b = patch.usage) == null ? void 0 : _b.completionTokens) !== void 0 && Number.isFinite(patch.usage.completionTokens)) {
|
|
481
|
+
properties["ai.usage.completion_tokens"] = patch.usage.completionTokens;
|
|
482
|
+
}
|
|
483
|
+
if (patch.error !== void 0 && patch.error !== null) {
|
|
484
|
+
const constructorName = patch.error instanceof Error && patch.error.constructor !== Error ? patch.error.constructor.name : void 0;
|
|
485
|
+
const errorType = patch.error instanceof Error ? patch.error.name && patch.error.name !== "Error" ? patch.error.name : constructorName || patch.error.name || "Error" : isErrorLike(patch.error) && typeof patch.error.name === "string" && patch.error.name.length > 0 ? patch.error.name : "Error";
|
|
486
|
+
const errorMessage = patch.error instanceof Error ? patch.error.message : isErrorLike(patch.error) && typeof patch.error.message === "string" ? patch.error.message : String(patch.error);
|
|
487
|
+
properties["error.type"] = errorType;
|
|
488
|
+
properties["error.message"] = errorMessage;
|
|
489
|
+
}
|
|
490
|
+
return properties;
|
|
491
|
+
}
|
|
459
492
|
var EventShipper = class {
|
|
460
493
|
constructor(opts) {
|
|
461
494
|
this.buffers = /* @__PURE__ */ new Map();
|
|
@@ -704,6 +737,11 @@ var EventShipper = class {
|
|
|
704
737
|
return;
|
|
705
738
|
}
|
|
706
739
|
const { wizardSession, ...restProperties } = (_e = accumulated.properties) != null ? _e : {};
|
|
740
|
+
let telemetryProperties = {};
|
|
741
|
+
try {
|
|
742
|
+
telemetryProperties = eventTelemetryProperties(accumulated);
|
|
743
|
+
} catch (e) {
|
|
744
|
+
}
|
|
707
745
|
const convoId = (_f = accumulated.convoId) != null ? _f : sticky.convoId;
|
|
708
746
|
const isPending = (_h = (_g = accumulated.isPending) != null ? _g : sticky.isPending) != null ? _h : true;
|
|
709
747
|
const payload = {
|
|
@@ -713,12 +751,13 @@ var EventShipper = class {
|
|
|
713
751
|
timestamp: (_i = accumulated.timestamp) != null ? _i : (/* @__PURE__ */ new Date()).toISOString(),
|
|
714
752
|
ai_data: {
|
|
715
753
|
input: accumulated.input,
|
|
716
|
-
output: accumulated.output,
|
|
754
|
+
output: accumulated.error !== void 0 && accumulated.error !== null ? void 0 : accumulated.output,
|
|
717
755
|
model: accumulated.model,
|
|
718
756
|
convo_id: convoId
|
|
719
757
|
},
|
|
720
758
|
properties: {
|
|
721
759
|
...restProperties,
|
|
760
|
+
...telemetryProperties,
|
|
722
761
|
...wizardSession ? { "raindrop.wizardSession": wizardSession } : {},
|
|
723
762
|
$context: this.context
|
|
724
763
|
},
|
|
@@ -876,6 +915,13 @@ function redactJsonAttributeValue(key, value) {
|
|
|
876
915
|
if (scrubbedJson === json) return void 0;
|
|
877
916
|
return { stringValue: scrubbedJson };
|
|
878
917
|
}
|
|
918
|
+
function identityAttrs(args) {
|
|
919
|
+
return [
|
|
920
|
+
attrString("ai.telemetry.metadata.raindrop.ai.userId", args.userId),
|
|
921
|
+
attrString("ai.telemetry.metadata.raindrop.convoId", args.convoId),
|
|
922
|
+
attrString("ai.telemetry.metadata.raindrop.eventName", args.eventName)
|
|
923
|
+
];
|
|
924
|
+
}
|
|
879
925
|
function applyOtelSpanAttributeLimit(limit) {
|
|
880
926
|
var _a, _b;
|
|
881
927
|
try {
|
|
@@ -1000,6 +1046,7 @@ var TraceShipper = class {
|
|
|
1000
1046
|
const started = (_a = args.startTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1001
1047
|
const attrs = [
|
|
1002
1048
|
attrString("ai.telemetry.metadata.raindrop.eventId", args.eventId),
|
|
1049
|
+
...identityAttrs(args),
|
|
1003
1050
|
attrString("ai.operationId", args.operationId)
|
|
1004
1051
|
];
|
|
1005
1052
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
@@ -1055,7 +1102,8 @@ var TraceShipper = class {
|
|
|
1055
1102
|
var _a;
|
|
1056
1103
|
const ids = createSpanIds(args.parent);
|
|
1057
1104
|
const attrs = [
|
|
1058
|
-
attrString("ai.telemetry.metadata.raindrop.eventId", args.eventId)
|
|
1105
|
+
attrString("ai.telemetry.metadata.raindrop.eventId", args.eventId),
|
|
1106
|
+
...identityAttrs(args)
|
|
1059
1107
|
];
|
|
1060
1108
|
if ((_a = args.attributes) == null ? void 0 : _a.length) attrs.push(...args.attributes);
|
|
1061
1109
|
const otlp = buildOtlpSpan({
|
|
@@ -2250,7 +2298,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2250
2298
|
};
|
|
2251
2299
|
// ── onStart ─────────────────────────────────────────────────────────────
|
|
2252
2300
|
this.onStart = (event) => {
|
|
2253
|
-
var _a, _b, _c, _d, _e;
|
|
2301
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2254
2302
|
if (event.isEnabled === false) return;
|
|
2255
2303
|
const isEmbed = event.operationId === "ai.embed" || event.operationId === "ai.embedMany";
|
|
2256
2304
|
const recordInputs = event.recordInputs !== false;
|
|
@@ -2260,15 +2308,20 @@ var RaindropTelemetryIntegration = class {
|
|
|
2260
2308
|
const callContextMetadata = getCurrentRaindropCallMetadata();
|
|
2261
2309
|
const metadata = eventMetadata2 != null ? eventMetadata2 : callContextMetadata == null ? void 0 : callContextMetadata.rawMetadata;
|
|
2262
2310
|
const callMeta = this.extractRaindropMetadata(metadata);
|
|
2311
|
+
const identity = {
|
|
2312
|
+
userId: (_b = callMeta.userId) != null ? _b : (_a = this.defaultContext) == null ? void 0 : _a.userId,
|
|
2313
|
+
convoId: (_d = callMeta.convoId) != null ? _d : (_c = this.defaultContext) == null ? void 0 : _c.convoId,
|
|
2314
|
+
eventName: (_f = callMeta.eventName) != null ? _f : (_e = this.defaultContext) == null ? void 0 : _e.eventName
|
|
2315
|
+
};
|
|
2263
2316
|
const inherited = getContextManager().getParentSpanIds();
|
|
2264
2317
|
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;
|
|
2265
2318
|
const explicitEventId = callMeta.eventId && !eventIdGenerated ? callMeta.eventId : void 0;
|
|
2266
|
-
const eventId = (
|
|
2319
|
+
const eventId = (_j = (_i = (_h = explicitEventId != null ? explicitEventId : (_g = this.defaultContext) == null ? void 0 : _g.eventId) != null ? _h : inherited == null ? void 0 : inherited.eventId) != null ? _i : callMeta.eventId) != null ? _j : randomUUID();
|
|
2267
2320
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
2268
2321
|
const { operationName, resourceName } = opName(event.operationId, functionId);
|
|
2269
2322
|
const parentToolContext = !isEmbed && this.subagentWrapping ? getCurrentParentToolContext() : void 0;
|
|
2270
2323
|
const metadataSubagentName = !isEmbed && this.subagentWrapping && parentToolContext === void 0 ? typeof (metadata == null ? void 0 : metadata["eve.subagent.name"]) === "string" ? metadata["eve.subagent.name"] : typeof (metadata == null ? void 0 : metadata["ash.subagent.name"]) === "string" ? metadata["ash.subagent.name"] : void 0 : void 0;
|
|
2271
|
-
const subagentName = (
|
|
2324
|
+
const subagentName = (_k = parentToolContext == null ? void 0 : parentToolContext.toolName) != null ? _k : metadataSubagentName;
|
|
2272
2325
|
let subagentToolCallSpan;
|
|
2273
2326
|
let rootParentOverride;
|
|
2274
2327
|
if (subagentName && this.sendTraces) {
|
|
@@ -2281,6 +2334,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2281
2334
|
name: subagentName,
|
|
2282
2335
|
parent: inheritedParent,
|
|
2283
2336
|
eventId,
|
|
2337
|
+
...identity,
|
|
2284
2338
|
operationId: "ai.toolCall",
|
|
2285
2339
|
attributes: [
|
|
2286
2340
|
attrString("operation.name", "ai.toolCall"),
|
|
@@ -2297,6 +2351,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2297
2351
|
name: "agent.subagent",
|
|
2298
2352
|
parent: subagentParentRef,
|
|
2299
2353
|
eventId,
|
|
2354
|
+
...identity,
|
|
2300
2355
|
operationId: "agent.subagent",
|
|
2301
2356
|
attributes: [
|
|
2302
2357
|
attrString("operation.name", "agent.subagent"),
|
|
@@ -2324,6 +2379,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2324
2379
|
name: event.operationId,
|
|
2325
2380
|
parent: rootParentOverride != null ? rootParentOverride : inheritedParent,
|
|
2326
2381
|
eventId,
|
|
2382
|
+
...identity,
|
|
2327
2383
|
operationId: event.operationId,
|
|
2328
2384
|
attributes: [
|
|
2329
2385
|
attrString("operation.name", operationName),
|
|
@@ -2331,13 +2387,14 @@ var RaindropTelemetryIntegration = class {
|
|
|
2331
2387
|
attrString("ai.telemetry.functionId", functionId),
|
|
2332
2388
|
attrString("ai.model.provider", event.provider),
|
|
2333
2389
|
attrString("ai.model.id", event.modelId),
|
|
2334
|
-
// Filter out
|
|
2335
|
-
//
|
|
2336
|
-
// auto-generated ID would
|
|
2390
|
+
// Filter out identity keys (eventId/userId/convoId/eventName) from
|
|
2391
|
+
// metadata attrs since TraceShipper already stamps them via dedicated
|
|
2392
|
+
// args. Without this, eventMetadata()'s auto-generated ID would
|
|
2393
|
+
// duplicate and override the resolved one.
|
|
2337
2394
|
...attrsFromTelemetryMetadata(
|
|
2338
2395
|
metadata ? Object.fromEntries(
|
|
2339
2396
|
Object.entries(metadata).filter(
|
|
2340
|
-
([k]) => k !== "raindrop.eventId" && k !== "raindrop.internal.eventIdGenerated"
|
|
2397
|
+
([k]) => k !== "raindrop.eventId" && k !== "raindrop.internal.eventIdGenerated" && k !== "raindrop.userId" && k !== "raindrop.convoId" && k !== "raindrop.eventName"
|
|
2341
2398
|
)
|
|
2342
2399
|
) : void 0
|
|
2343
2400
|
),
|
|
@@ -2349,6 +2406,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2349
2406
|
this.callStates.set(event.callId, {
|
|
2350
2407
|
operationId: event.operationId,
|
|
2351
2408
|
eventId,
|
|
2409
|
+
identity,
|
|
2352
2410
|
rootSpan,
|
|
2353
2411
|
rootParent: rootSpan ? this.spanParentRef(rootSpan) : rootParentOverride != null ? rootParentOverride : inheritedParent,
|
|
2354
2412
|
stepSpan: void 0,
|
|
@@ -2400,6 +2458,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2400
2458
|
name: stepOperationId,
|
|
2401
2459
|
parent: state.rootParent,
|
|
2402
2460
|
eventId: state.eventId,
|
|
2461
|
+
...state.identity,
|
|
2403
2462
|
operationId: stepOperationId,
|
|
2404
2463
|
attributes: [
|
|
2405
2464
|
attrString("operation.name", operationName),
|
|
@@ -2533,6 +2592,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2533
2592
|
name: event.operationId,
|
|
2534
2593
|
parent: state.rootParent,
|
|
2535
2594
|
eventId: state.eventId,
|
|
2595
|
+
...state.identity,
|
|
2536
2596
|
operationId: event.operationId,
|
|
2537
2597
|
attributes: [
|
|
2538
2598
|
attrString("operation.name", operationName),
|
|
@@ -2799,6 +2859,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2799
2859
|
name: "ai.toolCall",
|
|
2800
2860
|
parent: state.stepParent,
|
|
2801
2861
|
eventId: state.eventId,
|
|
2862
|
+
...state.identity,
|
|
2802
2863
|
operationId: "ai.toolCall",
|
|
2803
2864
|
attributes: [
|
|
2804
2865
|
attrString("operation.name", operationName),
|
|
@@ -2876,6 +2937,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2876
2937
|
name: "ai.toolCall",
|
|
2877
2938
|
parent: state.stepParent,
|
|
2878
2939
|
eventId: state.eventId,
|
|
2940
|
+
...state.identity,
|
|
2879
2941
|
operationId: "ai.toolCall",
|
|
2880
2942
|
attributes: [
|
|
2881
2943
|
attrString("operation.name", operationName),
|
|
@@ -2979,7 +3041,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2979
3041
|
...callMeta.properties
|
|
2980
3042
|
};
|
|
2981
3043
|
const featureFlags = {
|
|
2982
|
-
...(_g = this.defaultContext) == null ? void 0 : _g.featureFlags,
|
|
3044
|
+
...((_g = this.defaultContext) == null ? void 0 : _g.featureFlags) ? normalizeFeatureFlags(this.defaultContext.featureFlags) : {},
|
|
2983
3045
|
...callMeta.featureFlags
|
|
2984
3046
|
};
|
|
2985
3047
|
const convoId = (_i = callMeta.convoId) != null ? _i : (_h = this.defaultContext) == null ? void 0 : _h.convoId;
|
|
@@ -3530,6 +3592,9 @@ function teeStreamObjectBaseStream(result) {
|
|
|
3530
3592
|
} catch (e) {
|
|
3531
3593
|
}
|
|
3532
3594
|
}
|
|
3595
|
+
function identityFromContext(ctx) {
|
|
3596
|
+
return { userId: ctx.userId, convoId: ctx.convoId, eventName: ctx.eventName };
|
|
3597
|
+
}
|
|
3533
3598
|
function setupOperation(params) {
|
|
3534
3599
|
var _a, _b, _c;
|
|
3535
3600
|
const {
|
|
@@ -3561,6 +3626,7 @@ function setupOperation(params) {
|
|
|
3561
3626
|
name: outerOperationId,
|
|
3562
3627
|
parent: inheritedParent,
|
|
3563
3628
|
eventId,
|
|
3629
|
+
...identityFromContext(mergedCtx),
|
|
3564
3630
|
operationId: outerOperationId,
|
|
3565
3631
|
attributes: [
|
|
3566
3632
|
attrString("operation.name", operationName),
|
|
@@ -3569,9 +3635,6 @@ function setupOperation(params) {
|
|
|
3569
3635
|
attrString("ai.model.provider", modelInfoFromArgs.provider),
|
|
3570
3636
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
3571
3637
|
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
3572
|
-
attrString("ai.telemetry.metadata.raindrop.eventName", mergedCtx.eventName),
|
|
3573
|
-
attrString("ai.telemetry.metadata.raindrop.ai.userId", mergedCtx.userId),
|
|
3574
|
-
attrString("ai.telemetry.metadata.raindrop.convoId", mergedCtx.convoId),
|
|
3575
3638
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
3576
3639
|
...attrsFromHeaders(isRecord(arg) ? arg["headers"] : void 0),
|
|
3577
3640
|
...attrsFromSettings(arg),
|
|
@@ -3661,6 +3724,7 @@ function createFinalize(params) {
|
|
|
3661
3724
|
responseMessages,
|
|
3662
3725
|
rootSpan: setup.rootSpan,
|
|
3663
3726
|
eventId: setup.eventId,
|
|
3727
|
+
...identityFromContext(setup.ctx),
|
|
3664
3728
|
telemetry: setup.telemetry,
|
|
3665
3729
|
toolCalls: setup.toolCalls,
|
|
3666
3730
|
traceShipper,
|
|
@@ -3699,6 +3763,11 @@ function createFinalize(params) {
|
|
|
3699
3763
|
input,
|
|
3700
3764
|
output,
|
|
3701
3765
|
model: finalModel,
|
|
3766
|
+
usage: {
|
|
3767
|
+
promptTokens: usage == null ? void 0 : usage.inputTokens,
|
|
3768
|
+
completionTokens: usage == null ? void 0 : usage.outputTokens
|
|
3769
|
+
},
|
|
3770
|
+
error,
|
|
3702
3771
|
properties: patch.properties,
|
|
3703
3772
|
featureFlags: patch.featureFlags,
|
|
3704
3773
|
attachments: patch.attachments,
|
|
@@ -3733,6 +3802,7 @@ function startToolSpan(toolCall, rootSpan, ctx, startTimeUnixNano) {
|
|
|
3733
3802
|
name: "ai.toolCall",
|
|
3734
3803
|
parent: { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 },
|
|
3735
3804
|
eventId: ctx.eventId,
|
|
3805
|
+
...identityFromContext(ctx),
|
|
3736
3806
|
operationId: "ai.toolCall",
|
|
3737
3807
|
attributes: [
|
|
3738
3808
|
attrString("operation.name", operationName),
|
|
@@ -3770,6 +3840,9 @@ function emitTranscriptToolCallSpans(params) {
|
|
|
3770
3840
|
}
|
|
3771
3841
|
const ctx = {
|
|
3772
3842
|
eventId: params.eventId,
|
|
3843
|
+
userId: params.userId,
|
|
3844
|
+
convoId: params.convoId,
|
|
3845
|
+
eventName: params.eventName,
|
|
3773
3846
|
telemetry: params.telemetry,
|
|
3774
3847
|
traceShipper: params.traceShipper
|
|
3775
3848
|
};
|
|
@@ -4149,6 +4222,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
4149
4222
|
name: outerOperationId,
|
|
4150
4223
|
parent: inheritedParent,
|
|
4151
4224
|
eventId,
|
|
4225
|
+
...identityFromContext(ctx),
|
|
4152
4226
|
operationId: outerOperationId,
|
|
4153
4227
|
attributes: [
|
|
4154
4228
|
attrString("operation.name", operationName),
|
|
@@ -4157,9 +4231,6 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
4157
4231
|
attrString("ai.model.provider", modelInfoFromArgs.provider),
|
|
4158
4232
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
4159
4233
|
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
4160
|
-
attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
|
|
4161
|
-
attrString("ai.telemetry.metadata.raindrop.ai.userId", ctx.userId),
|
|
4162
|
-
attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
|
|
4163
4234
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
4164
4235
|
...attrsFromHeaders(mergedArgs["headers"]),
|
|
4165
4236
|
...attrsFromSettings(mergedArgs),
|
|
@@ -4224,6 +4295,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
4224
4295
|
responseMessages,
|
|
4225
4296
|
rootSpan,
|
|
4226
4297
|
eventId,
|
|
4298
|
+
...identityFromContext(ctx),
|
|
4227
4299
|
telemetry,
|
|
4228
4300
|
toolCalls,
|
|
4229
4301
|
traceShipper: deps.traceShipper,
|
|
@@ -4276,6 +4348,11 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
4276
4348
|
input,
|
|
4277
4349
|
output,
|
|
4278
4350
|
model: finalModel,
|
|
4351
|
+
usage: {
|
|
4352
|
+
promptTokens: usage == null ? void 0 : usage.inputTokens,
|
|
4353
|
+
completionTokens: usage == null ? void 0 : usage.outputTokens
|
|
4354
|
+
},
|
|
4355
|
+
error,
|
|
4279
4356
|
properties: patch.properties,
|
|
4280
4357
|
featureFlags: patch.featureFlags,
|
|
4281
4358
|
attachments: patch.attachments,
|
|
@@ -4359,6 +4436,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
4359
4436
|
name: outerOperationId,
|
|
4360
4437
|
parent: inheritedParent,
|
|
4361
4438
|
eventId,
|
|
4439
|
+
...identityFromContext(ctx),
|
|
4362
4440
|
operationId: outerOperationId,
|
|
4363
4441
|
attributes: [
|
|
4364
4442
|
attrString("operation.name", operationName),
|
|
@@ -4367,9 +4445,6 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
4367
4445
|
attrString("ai.model.provider", modelInfoFromArgs.provider),
|
|
4368
4446
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
4369
4447
|
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
4370
|
-
attrString("ai.telemetry.metadata.raindrop.eventName", ctx.eventName),
|
|
4371
|
-
attrString("ai.telemetry.metadata.raindrop.ai.userId", ctx.userId),
|
|
4372
|
-
attrString("ai.telemetry.metadata.raindrop.convoId", ctx.convoId),
|
|
4373
4448
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
4374
4449
|
...attrsFromHeaders(mergedArgs["headers"]),
|
|
4375
4450
|
...attrsFromSettings(mergedArgs),
|
|
@@ -4434,6 +4509,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
4434
4509
|
responseMessages,
|
|
4435
4510
|
rootSpan,
|
|
4436
4511
|
eventId,
|
|
4512
|
+
...identityFromContext(ctx),
|
|
4437
4513
|
telemetry,
|
|
4438
4514
|
toolCalls,
|
|
4439
4515
|
traceShipper: deps.traceShipper,
|
|
@@ -4486,6 +4562,11 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
4486
4562
|
input,
|
|
4487
4563
|
output,
|
|
4488
4564
|
model: finalModel,
|
|
4565
|
+
usage: {
|
|
4566
|
+
promptTokens: usage == null ? void 0 : usage.inputTokens,
|
|
4567
|
+
completionTokens: usage == null ? void 0 : usage.outputTokens
|
|
4568
|
+
},
|
|
4569
|
+
error,
|
|
4489
4570
|
properties: patch.properties,
|
|
4490
4571
|
featureFlags: patch.featureFlags,
|
|
4491
4572
|
attachments: patch.attachments,
|
|
@@ -4583,6 +4664,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
4583
4664
|
name: "ai.toolCall",
|
|
4584
4665
|
parent,
|
|
4585
4666
|
eventId: ctx.eventId,
|
|
4667
|
+
...identityFromContext(ctx.context),
|
|
4586
4668
|
operationId: "ai.toolCall",
|
|
4587
4669
|
attributes: [
|
|
4588
4670
|
attrString("operation.name", operationName),
|
|
@@ -4943,6 +5025,7 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
4943
5025
|
name: operationId,
|
|
4944
5026
|
parent,
|
|
4945
5027
|
eventId: ctx.eventId,
|
|
5028
|
+
...identityFromContext(ctx.context),
|
|
4946
5029
|
operationId,
|
|
4947
5030
|
attributes: [
|
|
4948
5031
|
attrString("operation.name", operationName),
|
|
@@ -5026,6 +5109,7 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
5026
5109
|
name: operationId,
|
|
5027
5110
|
parent,
|
|
5028
5111
|
eventId: ctx.eventId,
|
|
5112
|
+
...identityFromContext(ctx.context),
|
|
5029
5113
|
operationId,
|
|
5030
5114
|
attributes: [
|
|
5031
5115
|
attrString("operation.name", operationName),
|
|
@@ -5115,7 +5199,7 @@ function extractNestedTokens(usage, key) {
|
|
|
5115
5199
|
// package.json
|
|
5116
5200
|
var package_default = {
|
|
5117
5201
|
name: "@raindrop-ai/ai-sdk",
|
|
5118
|
-
version: "0.
|
|
5202
|
+
version: "0.2.0"};
|
|
5119
5203
|
|
|
5120
5204
|
// src/internal/version.ts
|
|
5121
5205
|
var libraryName = package_default.name;
|
|
@@ -5321,6 +5405,9 @@ function createRaindropAISDK(opts) {
|
|
|
5321
5405
|
const internal = traceShipper.startSpan({
|
|
5322
5406
|
name: args.name,
|
|
5323
5407
|
eventId: args.eventId,
|
|
5408
|
+
userId: args.userId,
|
|
5409
|
+
convoId: args.convoId,
|
|
5410
|
+
eventName: args.eventName,
|
|
5324
5411
|
parent,
|
|
5325
5412
|
operationId: args.operationId,
|
|
5326
5413
|
attributes: attrs
|
|
@@ -5355,6 +5442,9 @@ function createRaindropAISDK(opts) {
|
|
|
5355
5442
|
const internal = traceShipper.startSpan({
|
|
5356
5443
|
name: args.name,
|
|
5357
5444
|
eventId: args.eventId,
|
|
5445
|
+
userId: args.userId,
|
|
5446
|
+
convoId: args.convoId,
|
|
5447
|
+
eventName: args.eventName,
|
|
5358
5448
|
parent,
|
|
5359
5449
|
operationId: args.operationId,
|
|
5360
5450
|
attributes: startAttrs,
|
|
@@ -56,6 +56,10 @@ type IdentifyInput$1 = {
|
|
|
56
56
|
userId: string;
|
|
57
57
|
traits?: Record<string, unknown>;
|
|
58
58
|
};
|
|
59
|
+
type EventUsage = {
|
|
60
|
+
promptTokens?: number;
|
|
61
|
+
completionTokens?: number;
|
|
62
|
+
};
|
|
59
63
|
type Patch = {
|
|
60
64
|
eventName?: string;
|
|
61
65
|
userId?: string;
|
|
@@ -63,6 +67,8 @@ type Patch = {
|
|
|
63
67
|
input?: string;
|
|
64
68
|
output?: string;
|
|
65
69
|
model?: string;
|
|
70
|
+
usage?: EventUsage;
|
|
71
|
+
error?: unknown;
|
|
66
72
|
properties?: Record<string, unknown>;
|
|
67
73
|
featureFlags?: Record<string, string>;
|
|
68
74
|
attachments?: Attachment$1[];
|
|
@@ -161,13 +167,7 @@ declare class EventShipper$1 {
|
|
|
161
167
|
*/
|
|
162
168
|
private requestOpts;
|
|
163
169
|
patch(eventId: string, patch: Patch): Promise<void>;
|
|
164
|
-
finish(eventId: string, patch:
|
|
165
|
-
output?: string;
|
|
166
|
-
model?: string;
|
|
167
|
-
properties?: Record<string, unknown>;
|
|
168
|
-
featureFlags?: Record<string, string>;
|
|
169
|
-
userId?: string;
|
|
170
|
-
}): Promise<void>;
|
|
170
|
+
finish(eventId: string, patch: Pick<Patch, "output" | "model" | "usage" | "error" | "properties" | "featureFlags" | "userId">): Promise<void>;
|
|
171
171
|
flush(): Promise<void>;
|
|
172
172
|
shutdown(): Promise<void>;
|
|
173
173
|
trackSignal(signal: SignalInput): Promise<void>;
|
|
@@ -399,6 +399,9 @@ declare class TraceShipper$1 {
|
|
|
399
399
|
spanIdB64: string;
|
|
400
400
|
};
|
|
401
401
|
eventId: string;
|
|
402
|
+
userId?: string;
|
|
403
|
+
convoId?: string;
|
|
404
|
+
eventName?: string;
|
|
402
405
|
operationId?: string;
|
|
403
406
|
attributes?: Array<OtlpKeyValue | undefined>;
|
|
404
407
|
startTimeUnixNano?: string;
|
|
@@ -417,6 +420,9 @@ declare class TraceShipper$1 {
|
|
|
417
420
|
spanIdB64: string;
|
|
418
421
|
};
|
|
419
422
|
eventId: string;
|
|
423
|
+
userId?: string;
|
|
424
|
+
convoId?: string;
|
|
425
|
+
eventName?: string;
|
|
420
426
|
startTimeUnixNano: string;
|
|
421
427
|
endTimeUnixNano: string;
|
|
422
428
|
attributes?: Array<OtlpKeyValue | undefined>;
|
|
@@ -503,6 +509,37 @@ declare class TraceShipper extends TraceShipper$1 {
|
|
|
503
509
|
constructor(opts: ConstructorParameters<typeof TraceShipper$1>[0]);
|
|
504
510
|
}
|
|
505
511
|
|
|
512
|
+
/**
|
|
513
|
+
* Raindrop telemetry integration for AI SDK v7+
|
|
514
|
+
*
|
|
515
|
+
* Implements the AI SDK's `Telemetry` interface (formerly `TelemetryIntegration`
|
|
516
|
+
* before v7 beta.111) to capture traces and events natively, replacing the
|
|
517
|
+
* Proxy-based wrapping used for v4-v6.
|
|
518
|
+
*
|
|
519
|
+
* Modeled after the upstream OpenTelemetry integration but uses Raindrop's
|
|
520
|
+
* TraceShipper (OTLP/HTTP) + EventShipper instead of the OTel Tracer API.
|
|
521
|
+
*
|
|
522
|
+
* Compatibility: this class targets the latest published v7 build but also
|
|
523
|
+
* exposes the older v7 callback names as aliases so it works on every v7
|
|
524
|
+
* beta/canary released to date:
|
|
525
|
+
* - `onToolCallStart`/`onToolCallFinish` (< beta.111) alongside
|
|
526
|
+
* `onToolExecutionStart`/`onToolExecutionEnd` (>= beta.111).
|
|
527
|
+
* - Current `onToolExecutionEnd` events use the `toolOutput` discriminated
|
|
528
|
+
* union; older builds used top-level `success`/`output`/`error` fields.
|
|
529
|
+
* - `onFinish`/`onEmbedFinish` (< canary.159) alongside `onEnd`/`onEmbedEnd`
|
|
530
|
+
* (>= canary.159, vercel/ai renamed the operation finalizers).
|
|
531
|
+
* - `onAbort` (added as a telemetry-integration callback on the v7 canary
|
|
532
|
+
* line, post-beta.116) finalizes open spans + the pending event when a
|
|
533
|
+
* `streamText` call is cancelled via its `AbortSignal`. Builds that don't
|
|
534
|
+
* dispatch it to integrations simply never call it, so it's a no-op there.
|
|
535
|
+
*
|
|
536
|
+
* Step-end note: we intentionally implement only `onStepFinish` (not the newer
|
|
537
|
+
* `onStepEnd`). The latest canary dispatcher fans every step-end event out to
|
|
538
|
+
* BOTH `onStepEnd` and the deprecated `onStepFinish` on each integration, so
|
|
539
|
+
* implementing both names would double-close the step span. `onStepFinish`
|
|
540
|
+
* alone is dispatched on every published v7 beta/canary to date.
|
|
541
|
+
*/
|
|
542
|
+
|
|
506
543
|
type Listener<T> = (event: T) => PromiseLike<void> | void;
|
|
507
544
|
type ToolExecutionEndEvent = {
|
|
508
545
|
callId: string;
|
|
@@ -576,7 +613,7 @@ type RaindropTelemetryIntegrationOptions = {
|
|
|
576
613
|
eventName?: string;
|
|
577
614
|
convoId?: string;
|
|
578
615
|
properties?: Record<string, unknown>;
|
|
579
|
-
featureFlags?:
|
|
616
|
+
featureFlags?: FeatureFlags;
|
|
580
617
|
};
|
|
581
618
|
};
|
|
582
619
|
declare class RaindropTelemetryIntegration implements TelemetryIntegration {
|
|
@@ -1194,6 +1231,12 @@ type StartSpanArgs = {
|
|
|
1194
1231
|
parent?: TraceSpan;
|
|
1195
1232
|
/** AI SDK operation ID (e.g. "ai.toolCall", "ai.generateText"). Helps classify the span. */
|
|
1196
1233
|
operationId?: string;
|
|
1234
|
+
/** Raindrop user ID this span belongs to. Stamped onto the span so it rides onto nested spans. */
|
|
1235
|
+
userId?: string;
|
|
1236
|
+
/** Raindrop conversation ID this span belongs to. */
|
|
1237
|
+
convoId?: string;
|
|
1238
|
+
/** Raindrop event name this span belongs to. */
|
|
1239
|
+
eventName?: string;
|
|
1197
1240
|
/** Arbitrary string attributes. */
|
|
1198
1241
|
attributes?: Record<string, string>;
|
|
1199
1242
|
};
|
|
@@ -1212,6 +1255,12 @@ type CreateSpanArgs = {
|
|
|
1212
1255
|
parent?: TraceSpan;
|
|
1213
1256
|
/** AI SDK operation ID (e.g. "ai.toolCall"). Helps classify the span. */
|
|
1214
1257
|
operationId?: string;
|
|
1258
|
+
/** Raindrop user ID this span belongs to. Stamped onto the span so it rides onto nested spans. */
|
|
1259
|
+
userId?: string;
|
|
1260
|
+
/** Raindrop conversation ID this span belongs to. */
|
|
1261
|
+
convoId?: string;
|
|
1262
|
+
/** Raindrop event name this span belongs to. */
|
|
1263
|
+
eventName?: string;
|
|
1215
1264
|
/** Input data (will be JSON stringified if object). */
|
|
1216
1265
|
input?: unknown;
|
|
1217
1266
|
/** Output data (will be JSON stringified if object). */
|
|
@@ -56,6 +56,10 @@ type IdentifyInput$1 = {
|
|
|
56
56
|
userId: string;
|
|
57
57
|
traits?: Record<string, unknown>;
|
|
58
58
|
};
|
|
59
|
+
type EventUsage = {
|
|
60
|
+
promptTokens?: number;
|
|
61
|
+
completionTokens?: number;
|
|
62
|
+
};
|
|
59
63
|
type Patch = {
|
|
60
64
|
eventName?: string;
|
|
61
65
|
userId?: string;
|
|
@@ -63,6 +67,8 @@ type Patch = {
|
|
|
63
67
|
input?: string;
|
|
64
68
|
output?: string;
|
|
65
69
|
model?: string;
|
|
70
|
+
usage?: EventUsage;
|
|
71
|
+
error?: unknown;
|
|
66
72
|
properties?: Record<string, unknown>;
|
|
67
73
|
featureFlags?: Record<string, string>;
|
|
68
74
|
attachments?: Attachment$1[];
|
|
@@ -161,13 +167,7 @@ declare class EventShipper$1 {
|
|
|
161
167
|
*/
|
|
162
168
|
private requestOpts;
|
|
163
169
|
patch(eventId: string, patch: Patch): Promise<void>;
|
|
164
|
-
finish(eventId: string, patch:
|
|
165
|
-
output?: string;
|
|
166
|
-
model?: string;
|
|
167
|
-
properties?: Record<string, unknown>;
|
|
168
|
-
featureFlags?: Record<string, string>;
|
|
169
|
-
userId?: string;
|
|
170
|
-
}): Promise<void>;
|
|
170
|
+
finish(eventId: string, patch: Pick<Patch, "output" | "model" | "usage" | "error" | "properties" | "featureFlags" | "userId">): Promise<void>;
|
|
171
171
|
flush(): Promise<void>;
|
|
172
172
|
shutdown(): Promise<void>;
|
|
173
173
|
trackSignal(signal: SignalInput): Promise<void>;
|
|
@@ -399,6 +399,9 @@ declare class TraceShipper$1 {
|
|
|
399
399
|
spanIdB64: string;
|
|
400
400
|
};
|
|
401
401
|
eventId: string;
|
|
402
|
+
userId?: string;
|
|
403
|
+
convoId?: string;
|
|
404
|
+
eventName?: string;
|
|
402
405
|
operationId?: string;
|
|
403
406
|
attributes?: Array<OtlpKeyValue | undefined>;
|
|
404
407
|
startTimeUnixNano?: string;
|
|
@@ -417,6 +420,9 @@ declare class TraceShipper$1 {
|
|
|
417
420
|
spanIdB64: string;
|
|
418
421
|
};
|
|
419
422
|
eventId: string;
|
|
423
|
+
userId?: string;
|
|
424
|
+
convoId?: string;
|
|
425
|
+
eventName?: string;
|
|
420
426
|
startTimeUnixNano: string;
|
|
421
427
|
endTimeUnixNano: string;
|
|
422
428
|
attributes?: Array<OtlpKeyValue | undefined>;
|
|
@@ -503,6 +509,37 @@ declare class TraceShipper extends TraceShipper$1 {
|
|
|
503
509
|
constructor(opts: ConstructorParameters<typeof TraceShipper$1>[0]);
|
|
504
510
|
}
|
|
505
511
|
|
|
512
|
+
/**
|
|
513
|
+
* Raindrop telemetry integration for AI SDK v7+
|
|
514
|
+
*
|
|
515
|
+
* Implements the AI SDK's `Telemetry` interface (formerly `TelemetryIntegration`
|
|
516
|
+
* before v7 beta.111) to capture traces and events natively, replacing the
|
|
517
|
+
* Proxy-based wrapping used for v4-v6.
|
|
518
|
+
*
|
|
519
|
+
* Modeled after the upstream OpenTelemetry integration but uses Raindrop's
|
|
520
|
+
* TraceShipper (OTLP/HTTP) + EventShipper instead of the OTel Tracer API.
|
|
521
|
+
*
|
|
522
|
+
* Compatibility: this class targets the latest published v7 build but also
|
|
523
|
+
* exposes the older v7 callback names as aliases so it works on every v7
|
|
524
|
+
* beta/canary released to date:
|
|
525
|
+
* - `onToolCallStart`/`onToolCallFinish` (< beta.111) alongside
|
|
526
|
+
* `onToolExecutionStart`/`onToolExecutionEnd` (>= beta.111).
|
|
527
|
+
* - Current `onToolExecutionEnd` events use the `toolOutput` discriminated
|
|
528
|
+
* union; older builds used top-level `success`/`output`/`error` fields.
|
|
529
|
+
* - `onFinish`/`onEmbedFinish` (< canary.159) alongside `onEnd`/`onEmbedEnd`
|
|
530
|
+
* (>= canary.159, vercel/ai renamed the operation finalizers).
|
|
531
|
+
* - `onAbort` (added as a telemetry-integration callback on the v7 canary
|
|
532
|
+
* line, post-beta.116) finalizes open spans + the pending event when a
|
|
533
|
+
* `streamText` call is cancelled via its `AbortSignal`. Builds that don't
|
|
534
|
+
* dispatch it to integrations simply never call it, so it's a no-op there.
|
|
535
|
+
*
|
|
536
|
+
* Step-end note: we intentionally implement only `onStepFinish` (not the newer
|
|
537
|
+
* `onStepEnd`). The latest canary dispatcher fans every step-end event out to
|
|
538
|
+
* BOTH `onStepEnd` and the deprecated `onStepFinish` on each integration, so
|
|
539
|
+
* implementing both names would double-close the step span. `onStepFinish`
|
|
540
|
+
* alone is dispatched on every published v7 beta/canary to date.
|
|
541
|
+
*/
|
|
542
|
+
|
|
506
543
|
type Listener<T> = (event: T) => PromiseLike<void> | void;
|
|
507
544
|
type ToolExecutionEndEvent = {
|
|
508
545
|
callId: string;
|
|
@@ -576,7 +613,7 @@ type RaindropTelemetryIntegrationOptions = {
|
|
|
576
613
|
eventName?: string;
|
|
577
614
|
convoId?: string;
|
|
578
615
|
properties?: Record<string, unknown>;
|
|
579
|
-
featureFlags?:
|
|
616
|
+
featureFlags?: FeatureFlags;
|
|
580
617
|
};
|
|
581
618
|
};
|
|
582
619
|
declare class RaindropTelemetryIntegration implements TelemetryIntegration {
|
|
@@ -1194,6 +1231,12 @@ type StartSpanArgs = {
|
|
|
1194
1231
|
parent?: TraceSpan;
|
|
1195
1232
|
/** AI SDK operation ID (e.g. "ai.toolCall", "ai.generateText"). Helps classify the span. */
|
|
1196
1233
|
operationId?: string;
|
|
1234
|
+
/** Raindrop user ID this span belongs to. Stamped onto the span so it rides onto nested spans. */
|
|
1235
|
+
userId?: string;
|
|
1236
|
+
/** Raindrop conversation ID this span belongs to. */
|
|
1237
|
+
convoId?: string;
|
|
1238
|
+
/** Raindrop event name this span belongs to. */
|
|
1239
|
+
eventName?: string;
|
|
1197
1240
|
/** Arbitrary string attributes. */
|
|
1198
1241
|
attributes?: Record<string, string>;
|
|
1199
1242
|
};
|
|
@@ -1212,6 +1255,12 @@ type CreateSpanArgs = {
|
|
|
1212
1255
|
parent?: TraceSpan;
|
|
1213
1256
|
/** AI SDK operation ID (e.g. "ai.toolCall"). Helps classify the span. */
|
|
1214
1257
|
operationId?: string;
|
|
1258
|
+
/** Raindrop user ID this span belongs to. Stamped onto the span so it rides onto nested spans. */
|
|
1259
|
+
userId?: string;
|
|
1260
|
+
/** Raindrop conversation ID this span belongs to. */
|
|
1261
|
+
convoId?: string;
|
|
1262
|
+
/** Raindrop event name this span belongs to. */
|
|
1263
|
+
eventName?: string;
|
|
1215
1264
|
/** Input data (will be JSON stringified if object). */
|
|
1216
1265
|
input?: unknown;
|
|
1217
1266
|
/** Output data (will be JSON stringified if object). */
|