raindrop-ai 0.0.91 → 0.0.92-otelv2
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-4KBZONJV.mjs → chunk-PURTSYKG.mjs} +96 -66
- package/dist/index.js +88 -64
- package/dist/index.mjs +1 -1
- package/dist/tracing/index.js +88 -64
- package/dist/tracing/index.mjs +1 -1
- package/package.json +7 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../core/dist/chunk-
|
|
1
|
+
// ../core/dist/chunk-Y7SM66SW.js
|
|
2
2
|
function wait(ms) {
|
|
3
3
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
4
|
}
|
|
@@ -97,21 +97,6 @@ function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
|
97
97
|
function localDebuggerEnabled(baseUrl) {
|
|
98
98
|
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
99
99
|
}
|
|
100
|
-
function normalizeLocalDebuggerLiveEventType(type) {
|
|
101
|
-
switch (type) {
|
|
102
|
-
case "text-delta":
|
|
103
|
-
return "text_delta";
|
|
104
|
-
case "reasoning":
|
|
105
|
-
case "reasoning-delta":
|
|
106
|
-
return "reasoning_delta";
|
|
107
|
-
case "tool-call":
|
|
108
|
-
return "tool_start";
|
|
109
|
-
case "tool-result":
|
|
110
|
-
return "tool_result";
|
|
111
|
-
default:
|
|
112
|
-
return type;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
100
|
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
116
101
|
var _a;
|
|
117
102
|
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
@@ -143,7 +128,7 @@ function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
|
143
128
|
`${baseUrl}live`,
|
|
144
129
|
{
|
|
145
130
|
...event,
|
|
146
|
-
type:
|
|
131
|
+
type: event.type,
|
|
147
132
|
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
148
133
|
},
|
|
149
134
|
{},
|
|
@@ -163,7 +148,7 @@ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
|
|
|
163
148
|
// package.json
|
|
164
149
|
var package_default = {
|
|
165
150
|
name: "raindrop-ai",
|
|
166
|
-
version: "0.0.
|
|
151
|
+
version: "0.0.92",
|
|
167
152
|
main: "dist/index.js",
|
|
168
153
|
module: "dist/index.mjs",
|
|
169
154
|
types: "dist/index.d.ts",
|
|
@@ -682,7 +667,13 @@ var DirectTraceShipper = class {
|
|
|
682
667
|
};
|
|
683
668
|
|
|
684
669
|
// src/tracing/liveInteraction.ts
|
|
685
|
-
import {
|
|
670
|
+
import {
|
|
671
|
+
context as context2,
|
|
672
|
+
isValidSpanId,
|
|
673
|
+
SpanStatusCode as SpanStatusCode2,
|
|
674
|
+
TraceFlags,
|
|
675
|
+
trace as trace2
|
|
676
|
+
} from "@opentelemetry/api";
|
|
686
677
|
import * as traceloop from "@traceloop/node-server-sdk";
|
|
687
678
|
function getPropertiesFromContext(context5) {
|
|
688
679
|
const properties = {
|
|
@@ -732,6 +723,10 @@ var LiveToolSpan = class {
|
|
|
732
723
|
this.name = params.name;
|
|
733
724
|
this.emitLiveEvent = params.emitLiveEvent;
|
|
734
725
|
}
|
|
726
|
+
spanIdHex() {
|
|
727
|
+
const ctx = this.span.spanContext();
|
|
728
|
+
return isValidSpanId(ctx.spanId) ? ctx.spanId : void 0;
|
|
729
|
+
}
|
|
735
730
|
setInput(input) {
|
|
736
731
|
this.span.setAttribute("traceloop.entity.input", serializeSpanValue(input));
|
|
737
732
|
}
|
|
@@ -754,6 +749,7 @@ var LiveToolSpan = class {
|
|
|
754
749
|
(_a = this.emitLiveEvent) == null ? void 0 : _a.call(this, {
|
|
755
750
|
type: "tool_result",
|
|
756
751
|
content: this.name,
|
|
752
|
+
spanId: this.spanIdHex(),
|
|
757
753
|
metadata: {
|
|
758
754
|
...this.output !== void 0 ? { result: this.output } : {},
|
|
759
755
|
...this.errorMessage ? { error: this.errorMessage } : {}
|
|
@@ -768,6 +764,7 @@ var DirectToolSpan = class {
|
|
|
768
764
|
this.properties = params.properties;
|
|
769
765
|
this.directShipper = params.directShipper;
|
|
770
766
|
this.traceId = params.traceId;
|
|
767
|
+
this.spanId = params.spanId;
|
|
771
768
|
this.parentSpanId = params.parentSpanId;
|
|
772
769
|
this.startTimeMs = Date.now();
|
|
773
770
|
this.input = params.input !== void 0 ? serializeSpanValue(params.input) : void 0;
|
|
@@ -792,6 +789,7 @@ var DirectToolSpan = class {
|
|
|
792
789
|
const endTimeMs = Date.now();
|
|
793
790
|
this.directShipper.sendToolSpan({
|
|
794
791
|
name: this.name,
|
|
792
|
+
spanId: this.spanId,
|
|
795
793
|
input: this.input,
|
|
796
794
|
output: this.output,
|
|
797
795
|
durationMs: endTimeMs - this.startTimeMs,
|
|
@@ -804,6 +802,7 @@ var DirectToolSpan = class {
|
|
|
804
802
|
});
|
|
805
803
|
(_a = this.emitLiveEvent) == null ? void 0 : _a.call(this, {
|
|
806
804
|
traceId: this.traceId,
|
|
805
|
+
spanId: this.spanId,
|
|
807
806
|
type: "tool_result",
|
|
808
807
|
content: this.name,
|
|
809
808
|
timestamp: endTimeMs,
|
|
@@ -957,17 +956,18 @@ var LiveInteraction = class {
|
|
|
957
956
|
}
|
|
958
957
|
if (this.directShipper) {
|
|
959
958
|
const activeContext = getActiveTraceContext();
|
|
959
|
+
const traceIdB64 = this.ensureTraceId(activeContext.traceIdB64);
|
|
960
|
+
const { parentSpanIdB64 } = activeContext;
|
|
961
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
962
|
+
const startTimeMs = Date.now();
|
|
960
963
|
this.emitLiveEvent({
|
|
961
|
-
traceId:
|
|
964
|
+
traceId: traceIdB64,
|
|
965
|
+
spanId: spanIdB64,
|
|
962
966
|
type: "tool_start",
|
|
963
967
|
content: toolName,
|
|
964
|
-
timestamp:
|
|
968
|
+
timestamp: startTimeMs,
|
|
965
969
|
metadata: params.inputParameters ? { args: params.inputParameters } : void 0
|
|
966
970
|
});
|
|
967
|
-
const traceIdB64 = this.ensureTraceId(activeContext.traceIdB64);
|
|
968
|
-
const { parentSpanIdB64 } = activeContext;
|
|
969
|
-
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
970
|
-
const startTimeMs = Date.now();
|
|
971
971
|
const spanContext = {
|
|
972
972
|
traceId: base64ToHex(traceIdB64),
|
|
973
973
|
spanId: base64ToHex(spanIdB64),
|
|
@@ -1001,6 +1001,7 @@ var LiveInteraction = class {
|
|
|
1001
1001
|
});
|
|
1002
1002
|
this.emitLiveEvent({
|
|
1003
1003
|
traceId: traceIdB64,
|
|
1004
|
+
spanId: spanIdB64,
|
|
1004
1005
|
type: "tool_result",
|
|
1005
1006
|
content: toolName,
|
|
1006
1007
|
timestamp: endTimeMs2,
|
|
@@ -1030,6 +1031,7 @@ var LiveInteraction = class {
|
|
|
1030
1031
|
});
|
|
1031
1032
|
this.emitLiveEvent({
|
|
1032
1033
|
traceId: traceIdB64,
|
|
1034
|
+
spanId: spanIdB64,
|
|
1033
1035
|
type: "tool_result",
|
|
1034
1036
|
content: toolName,
|
|
1035
1037
|
timestamp: endTimeMs,
|
|
@@ -1040,49 +1042,59 @@ var LiveInteraction = class {
|
|
|
1040
1042
|
});
|
|
1041
1043
|
return result;
|
|
1042
1044
|
}
|
|
1043
|
-
this.emitLiveEvent({
|
|
1044
|
-
type: "tool_start",
|
|
1045
|
-
content: toolName,
|
|
1046
|
-
timestamp: Date.now(),
|
|
1047
|
-
metadata: params.inputParameters ? { args: params.inputParameters } : void 0
|
|
1048
|
-
});
|
|
1049
1045
|
const inputParams = params.inputParameters ? [params.inputParameters] : void 0;
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
suppressTracing: params.suppressTracing
|
|
1059
|
-
},
|
|
1060
|
-
fn,
|
|
1061
|
-
thisArg,
|
|
1062
|
-
...args
|
|
1063
|
-
);
|
|
1064
|
-
this.emitLiveEvent({
|
|
1065
|
-
type: "tool_result",
|
|
1066
|
-
content: toolName,
|
|
1067
|
-
timestamp: Date.now(),
|
|
1068
|
-
metadata: {
|
|
1069
|
-
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
1070
|
-
...result !== void 0 ? { result } : {}
|
|
1071
|
-
}
|
|
1072
|
-
});
|
|
1073
|
-
return result;
|
|
1074
|
-
} catch (error) {
|
|
1075
|
-
this.emitLiveEvent({
|
|
1076
|
-
type: "tool_result",
|
|
1046
|
+
const emitLive = (event) => this.emitLiveEvent(event);
|
|
1047
|
+
const wrapped = async (...wrappedArgs) => {
|
|
1048
|
+
const activeSpan = trace2.getSpan(context2.active());
|
|
1049
|
+
const ctx = activeSpan == null ? void 0 : activeSpan.spanContext();
|
|
1050
|
+
const liveSpanId = ctx && isValidSpanId(ctx.spanId) ? ctx.spanId : void 0;
|
|
1051
|
+
emitLive({
|
|
1052
|
+
type: "tool_start",
|
|
1053
|
+
spanId: liveSpanId,
|
|
1077
1054
|
content: toolName,
|
|
1078
1055
|
timestamp: Date.now(),
|
|
1079
|
-
metadata: {
|
|
1080
|
-
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
1081
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1082
|
-
}
|
|
1056
|
+
metadata: params.inputParameters ? { args: params.inputParameters } : void 0
|
|
1083
1057
|
});
|
|
1084
|
-
|
|
1085
|
-
|
|
1058
|
+
try {
|
|
1059
|
+
const r = await fn.apply(thisArg, wrappedArgs);
|
|
1060
|
+
emitLive({
|
|
1061
|
+
type: "tool_result",
|
|
1062
|
+
spanId: liveSpanId,
|
|
1063
|
+
content: toolName,
|
|
1064
|
+
timestamp: Date.now(),
|
|
1065
|
+
metadata: {
|
|
1066
|
+
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
1067
|
+
...r !== void 0 ? { result: r } : {}
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
return r;
|
|
1071
|
+
} catch (error) {
|
|
1072
|
+
emitLive({
|
|
1073
|
+
type: "tool_result",
|
|
1074
|
+
spanId: liveSpanId,
|
|
1075
|
+
content: toolName,
|
|
1076
|
+
timestamp: Date.now(),
|
|
1077
|
+
metadata: {
|
|
1078
|
+
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
1079
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
throw error;
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
return traceloop.withTool(
|
|
1086
|
+
{
|
|
1087
|
+
name: toolName,
|
|
1088
|
+
associationProperties: serializeAssociationProperties(properties),
|
|
1089
|
+
inputParameters: inputParams,
|
|
1090
|
+
version: params.version,
|
|
1091
|
+
traceContent: params.traceContent,
|
|
1092
|
+
suppressTracing: params.suppressTracing
|
|
1093
|
+
},
|
|
1094
|
+
wrapped,
|
|
1095
|
+
void 0,
|
|
1096
|
+
...args
|
|
1097
|
+
);
|
|
1086
1098
|
}
|
|
1087
1099
|
startSpan(params) {
|
|
1088
1100
|
const { name, properties = {} } = params;
|
|
@@ -1105,11 +1117,13 @@ var LiveInteraction = class {
|
|
|
1105
1117
|
const activeTraceContext = getActiveTraceContext();
|
|
1106
1118
|
const traceIdB64 = this.ensureTraceId(activeTraceContext.traceIdB64);
|
|
1107
1119
|
const { parentSpanIdB64 } = activeTraceContext;
|
|
1120
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
1108
1121
|
if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
|
|
1109
1122
|
console.log(`[raindrop] startToolSpan (direct): started tool span "${name}"`);
|
|
1110
1123
|
}
|
|
1111
1124
|
this.emitLiveEvent({
|
|
1112
1125
|
traceId: traceIdB64,
|
|
1126
|
+
spanId: spanIdB64,
|
|
1113
1127
|
type: "tool_start",
|
|
1114
1128
|
content: name,
|
|
1115
1129
|
timestamp: Date.now(),
|
|
@@ -1120,6 +1134,7 @@ var LiveInteraction = class {
|
|
|
1120
1134
|
properties: mergedProperties,
|
|
1121
1135
|
directShipper: this.directShipper,
|
|
1122
1136
|
traceId: traceIdB64,
|
|
1137
|
+
spanId: spanIdB64,
|
|
1123
1138
|
parentSpanId: parentSpanIdB64,
|
|
1124
1139
|
input: inputParameters,
|
|
1125
1140
|
emitLiveEvent: (event) => this.emitLiveEvent(event)
|
|
@@ -1135,8 +1150,11 @@ var LiveInteraction = class {
|
|
|
1135
1150
|
if ((_b = this.analytics) == null ? void 0 : _b.debugLogs) {
|
|
1136
1151
|
console.log(`[raindrop] startToolSpan: started tool span "${name}"`);
|
|
1137
1152
|
}
|
|
1153
|
+
const startSpanCtx = span.spanContext();
|
|
1154
|
+
const startSpanIdHex = isValidSpanId(startSpanCtx.spanId) ? startSpanCtx.spanId : void 0;
|
|
1138
1155
|
this.emitLiveEvent({
|
|
1139
1156
|
type: "tool_start",
|
|
1157
|
+
spanId: startSpanIdHex,
|
|
1140
1158
|
content: name,
|
|
1141
1159
|
timestamp: Date.now(),
|
|
1142
1160
|
metadata: inputParameters !== void 0 ? { args: inputParameters } : void 0
|
|
@@ -1226,10 +1244,12 @@ var LiveInteraction = class {
|
|
|
1226
1244
|
const activeContext = getActiveTraceContext();
|
|
1227
1245
|
const traceIdB64 = this.ensureTraceId(activeContext.traceIdB64);
|
|
1228
1246
|
const { parentSpanIdB64 } = activeContext;
|
|
1247
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
1229
1248
|
const inputStr = input !== void 0 ? typeof input === "string" ? input : JSON.stringify(input) : void 0;
|
|
1230
1249
|
const outputStr = output !== void 0 ? typeof output === "string" ? output : JSON.stringify(output) : void 0;
|
|
1231
1250
|
this.directShipper.sendToolSpan({
|
|
1232
1251
|
name,
|
|
1252
|
+
spanId: spanIdB64,
|
|
1233
1253
|
input: inputStr,
|
|
1234
1254
|
output: outputStr,
|
|
1235
1255
|
durationMs,
|
|
@@ -1253,6 +1273,7 @@ var LiveInteraction = class {
|
|
|
1253
1273
|
}
|
|
1254
1274
|
this.emitLiveEvent({
|
|
1255
1275
|
traceId: traceIdB64,
|
|
1276
|
+
spanId: spanIdB64,
|
|
1256
1277
|
type: "tool_result",
|
|
1257
1278
|
content: name,
|
|
1258
1279
|
timestamp: endTimeMs,
|
|
@@ -1298,8 +1319,11 @@ var LiveInteraction = class {
|
|
|
1298
1319
|
error: error ? String(error) : void 0
|
|
1299
1320
|
});
|
|
1300
1321
|
}
|
|
1322
|
+
const trackToolCtx = span.spanContext();
|
|
1323
|
+
const trackToolSpanIdHex = isValidSpanId(trackToolCtx.spanId) ? trackToolCtx.spanId : void 0;
|
|
1301
1324
|
this.emitLiveEvent({
|
|
1302
1325
|
type: "tool_result",
|
|
1326
|
+
spanId: trackToolSpanIdHex,
|
|
1303
1327
|
content: name,
|
|
1304
1328
|
timestamp: endTimeMs,
|
|
1305
1329
|
metadata: {
|
|
@@ -1312,7 +1336,7 @@ var LiveInteraction = class {
|
|
|
1312
1336
|
};
|
|
1313
1337
|
|
|
1314
1338
|
// src/tracing/liveTracer.ts
|
|
1315
|
-
import { context as context3, SpanStatusCode as SpanStatusCode3, trace as trace3 } from "@opentelemetry/api";
|
|
1339
|
+
import { context as context3, isValidSpanId as isValidSpanId2, SpanStatusCode as SpanStatusCode3, trace as trace3 } from "@opentelemetry/api";
|
|
1316
1340
|
import * as traceloop2 from "@traceloop/node-server-sdk";
|
|
1317
1341
|
var LiveTracer = class {
|
|
1318
1342
|
constructor(globalProperties, directShipper) {
|
|
@@ -1361,10 +1385,12 @@ var LiveTracer = class {
|
|
|
1361
1385
|
const endTimeMs = startTimeMs + (durationMs != null ? durationMs : 0);
|
|
1362
1386
|
if (this.directShipper) {
|
|
1363
1387
|
const { traceIdB64, parentSpanIdB64 } = getActiveTraceContext();
|
|
1388
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
1364
1389
|
const inputStr = input !== void 0 ? typeof input === "string" ? input : JSON.stringify(input) : void 0;
|
|
1365
1390
|
const outputStr = output !== void 0 ? typeof output === "string" ? output : JSON.stringify(output) : void 0;
|
|
1366
1391
|
this.directShipper.sendToolSpan({
|
|
1367
1392
|
name,
|
|
1393
|
+
spanId: spanIdB64,
|
|
1368
1394
|
input: inputStr,
|
|
1369
1395
|
output: outputStr,
|
|
1370
1396
|
durationMs,
|
|
@@ -1381,6 +1407,7 @@ var LiveTracer = class {
|
|
|
1381
1407
|
if (traceIdB64) {
|
|
1382
1408
|
this.emitLiveEvent({
|
|
1383
1409
|
traceId: traceIdB64,
|
|
1410
|
+
spanId: spanIdB64,
|
|
1384
1411
|
type: "tool_result",
|
|
1385
1412
|
content: name,
|
|
1386
1413
|
timestamp: endTimeMs,
|
|
@@ -1422,10 +1449,13 @@ var LiveTracer = class {
|
|
|
1422
1449
|
span.setStatus({ code: SpanStatusCode3.OK });
|
|
1423
1450
|
}
|
|
1424
1451
|
span.end(endTimeMs);
|
|
1425
|
-
const
|
|
1452
|
+
const ctx = span.spanContext();
|
|
1453
|
+
const traceId = ctx.traceId || ((_a = trace3.getSpan(context3.active())) == null ? void 0 : _a.spanContext().traceId);
|
|
1454
|
+
const spanIdHex = isValidSpanId2(ctx.spanId) ? ctx.spanId : void 0;
|
|
1426
1455
|
if (traceId) {
|
|
1427
1456
|
this.emitLiveEvent({
|
|
1428
1457
|
traceId,
|
|
1458
|
+
spanId: spanIdHex,
|
|
1429
1459
|
type: "tool_result",
|
|
1430
1460
|
content: name,
|
|
1431
1461
|
timestamp: endTimeMs,
|
package/dist/index.js
CHANGED
|
@@ -5771,7 +5771,7 @@ __export(index_exports, {
|
|
|
5771
5771
|
});
|
|
5772
5772
|
module.exports = __toCommonJS(index_exports);
|
|
5773
5773
|
|
|
5774
|
-
// ../core/dist/chunk-
|
|
5774
|
+
// ../core/dist/chunk-Y7SM66SW.js
|
|
5775
5775
|
function wait(ms) {
|
|
5776
5776
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5777
5777
|
}
|
|
@@ -5870,21 +5870,6 @@ function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
|
5870
5870
|
function localDebuggerEnabled(baseUrl) {
|
|
5871
5871
|
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
5872
5872
|
}
|
|
5873
|
-
function normalizeLocalDebuggerLiveEventType(type) {
|
|
5874
|
-
switch (type) {
|
|
5875
|
-
case "text-delta":
|
|
5876
|
-
return "text_delta";
|
|
5877
|
-
case "reasoning":
|
|
5878
|
-
case "reasoning-delta":
|
|
5879
|
-
return "reasoning_delta";
|
|
5880
|
-
case "tool-call":
|
|
5881
|
-
return "tool_start";
|
|
5882
|
-
case "tool-result":
|
|
5883
|
-
return "tool_result";
|
|
5884
|
-
default:
|
|
5885
|
-
return type;
|
|
5886
|
-
}
|
|
5887
|
-
}
|
|
5888
5873
|
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
5889
5874
|
var _a;
|
|
5890
5875
|
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
@@ -5916,7 +5901,7 @@ function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
|
5916
5901
|
`${baseUrl}live`,
|
|
5917
5902
|
{
|
|
5918
5903
|
...event,
|
|
5919
|
-
type:
|
|
5904
|
+
type: event.type,
|
|
5920
5905
|
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
5921
5906
|
},
|
|
5922
5907
|
{},
|
|
@@ -10041,7 +10026,7 @@ var SignalEventSchema = external_exports.object({
|
|
|
10041
10026
|
// package.json
|
|
10042
10027
|
var package_default = {
|
|
10043
10028
|
name: "raindrop-ai",
|
|
10044
|
-
version: "0.0.
|
|
10029
|
+
version: "0.0.92",
|
|
10045
10030
|
main: "dist/index.js",
|
|
10046
10031
|
module: "dist/index.mjs",
|
|
10047
10032
|
types: "dist/index.d.ts",
|
|
@@ -10696,6 +10681,10 @@ var LiveToolSpan = class {
|
|
|
10696
10681
|
this.name = params.name;
|
|
10697
10682
|
this.emitLiveEvent = params.emitLiveEvent;
|
|
10698
10683
|
}
|
|
10684
|
+
spanIdHex() {
|
|
10685
|
+
const ctx = this.span.spanContext();
|
|
10686
|
+
return (0, import_api2.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
|
|
10687
|
+
}
|
|
10699
10688
|
setInput(input) {
|
|
10700
10689
|
this.span.setAttribute("traceloop.entity.input", serializeSpanValue(input));
|
|
10701
10690
|
}
|
|
@@ -10718,6 +10707,7 @@ var LiveToolSpan = class {
|
|
|
10718
10707
|
(_a = this.emitLiveEvent) == null ? void 0 : _a.call(this, {
|
|
10719
10708
|
type: "tool_result",
|
|
10720
10709
|
content: this.name,
|
|
10710
|
+
spanId: this.spanIdHex(),
|
|
10721
10711
|
metadata: {
|
|
10722
10712
|
...this.output !== void 0 ? { result: this.output } : {},
|
|
10723
10713
|
...this.errorMessage ? { error: this.errorMessage } : {}
|
|
@@ -10732,6 +10722,7 @@ var DirectToolSpan = class {
|
|
|
10732
10722
|
this.properties = params.properties;
|
|
10733
10723
|
this.directShipper = params.directShipper;
|
|
10734
10724
|
this.traceId = params.traceId;
|
|
10725
|
+
this.spanId = params.spanId;
|
|
10735
10726
|
this.parentSpanId = params.parentSpanId;
|
|
10736
10727
|
this.startTimeMs = Date.now();
|
|
10737
10728
|
this.input = params.input !== void 0 ? serializeSpanValue(params.input) : void 0;
|
|
@@ -10756,6 +10747,7 @@ var DirectToolSpan = class {
|
|
|
10756
10747
|
const endTimeMs = Date.now();
|
|
10757
10748
|
this.directShipper.sendToolSpan({
|
|
10758
10749
|
name: this.name,
|
|
10750
|
+
spanId: this.spanId,
|
|
10759
10751
|
input: this.input,
|
|
10760
10752
|
output: this.output,
|
|
10761
10753
|
durationMs: endTimeMs - this.startTimeMs,
|
|
@@ -10768,6 +10760,7 @@ var DirectToolSpan = class {
|
|
|
10768
10760
|
});
|
|
10769
10761
|
(_a = this.emitLiveEvent) == null ? void 0 : _a.call(this, {
|
|
10770
10762
|
traceId: this.traceId,
|
|
10763
|
+
spanId: this.spanId,
|
|
10771
10764
|
type: "tool_result",
|
|
10772
10765
|
content: this.name,
|
|
10773
10766
|
timestamp: endTimeMs,
|
|
@@ -10921,17 +10914,18 @@ var LiveInteraction = class {
|
|
|
10921
10914
|
}
|
|
10922
10915
|
if (this.directShipper) {
|
|
10923
10916
|
const activeContext = getActiveTraceContext();
|
|
10917
|
+
const traceIdB64 = this.ensureTraceId(activeContext.traceIdB64);
|
|
10918
|
+
const { parentSpanIdB64 } = activeContext;
|
|
10919
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
10920
|
+
const startTimeMs = Date.now();
|
|
10924
10921
|
this.emitLiveEvent({
|
|
10925
|
-
traceId:
|
|
10922
|
+
traceId: traceIdB64,
|
|
10923
|
+
spanId: spanIdB64,
|
|
10926
10924
|
type: "tool_start",
|
|
10927
10925
|
content: toolName,
|
|
10928
|
-
timestamp:
|
|
10926
|
+
timestamp: startTimeMs,
|
|
10929
10927
|
metadata: params.inputParameters ? { args: params.inputParameters } : void 0
|
|
10930
10928
|
});
|
|
10931
|
-
const traceIdB64 = this.ensureTraceId(activeContext.traceIdB64);
|
|
10932
|
-
const { parentSpanIdB64 } = activeContext;
|
|
10933
|
-
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
10934
|
-
const startTimeMs = Date.now();
|
|
10935
10929
|
const spanContext = {
|
|
10936
10930
|
traceId: base64ToHex(traceIdB64),
|
|
10937
10931
|
spanId: base64ToHex(spanIdB64),
|
|
@@ -10965,6 +10959,7 @@ var LiveInteraction = class {
|
|
|
10965
10959
|
});
|
|
10966
10960
|
this.emitLiveEvent({
|
|
10967
10961
|
traceId: traceIdB64,
|
|
10962
|
+
spanId: spanIdB64,
|
|
10968
10963
|
type: "tool_result",
|
|
10969
10964
|
content: toolName,
|
|
10970
10965
|
timestamp: endTimeMs2,
|
|
@@ -10994,6 +10989,7 @@ var LiveInteraction = class {
|
|
|
10994
10989
|
});
|
|
10995
10990
|
this.emitLiveEvent({
|
|
10996
10991
|
traceId: traceIdB64,
|
|
10992
|
+
spanId: spanIdB64,
|
|
10997
10993
|
type: "tool_result",
|
|
10998
10994
|
content: toolName,
|
|
10999
10995
|
timestamp: endTimeMs,
|
|
@@ -11004,49 +11000,59 @@ var LiveInteraction = class {
|
|
|
11004
11000
|
});
|
|
11005
11001
|
return result;
|
|
11006
11002
|
}
|
|
11007
|
-
this.emitLiveEvent({
|
|
11008
|
-
type: "tool_start",
|
|
11009
|
-
content: toolName,
|
|
11010
|
-
timestamp: Date.now(),
|
|
11011
|
-
metadata: params.inputParameters ? { args: params.inputParameters } : void 0
|
|
11012
|
-
});
|
|
11013
11003
|
const inputParams = params.inputParameters ? [params.inputParameters] : void 0;
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
suppressTracing: params.suppressTracing
|
|
11023
|
-
},
|
|
11024
|
-
fn,
|
|
11025
|
-
thisArg,
|
|
11026
|
-
...args
|
|
11027
|
-
);
|
|
11028
|
-
this.emitLiveEvent({
|
|
11029
|
-
type: "tool_result",
|
|
11030
|
-
content: toolName,
|
|
11031
|
-
timestamp: Date.now(),
|
|
11032
|
-
metadata: {
|
|
11033
|
-
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
11034
|
-
...result !== void 0 ? { result } : {}
|
|
11035
|
-
}
|
|
11036
|
-
});
|
|
11037
|
-
return result;
|
|
11038
|
-
} catch (error) {
|
|
11039
|
-
this.emitLiveEvent({
|
|
11040
|
-
type: "tool_result",
|
|
11004
|
+
const emitLive = (event) => this.emitLiveEvent(event);
|
|
11005
|
+
const wrapped = async (...wrappedArgs) => {
|
|
11006
|
+
const activeSpan = import_api2.trace.getSpan(import_api2.context.active());
|
|
11007
|
+
const ctx = activeSpan == null ? void 0 : activeSpan.spanContext();
|
|
11008
|
+
const liveSpanId = ctx && (0, import_api2.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
|
|
11009
|
+
emitLive({
|
|
11010
|
+
type: "tool_start",
|
|
11011
|
+
spanId: liveSpanId,
|
|
11041
11012
|
content: toolName,
|
|
11042
11013
|
timestamp: Date.now(),
|
|
11043
|
-
metadata: {
|
|
11044
|
-
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
11045
|
-
error: error instanceof Error ? error.message : String(error)
|
|
11046
|
-
}
|
|
11014
|
+
metadata: params.inputParameters ? { args: params.inputParameters } : void 0
|
|
11047
11015
|
});
|
|
11048
|
-
|
|
11049
|
-
|
|
11016
|
+
try {
|
|
11017
|
+
const r = await fn.apply(thisArg, wrappedArgs);
|
|
11018
|
+
emitLive({
|
|
11019
|
+
type: "tool_result",
|
|
11020
|
+
spanId: liveSpanId,
|
|
11021
|
+
content: toolName,
|
|
11022
|
+
timestamp: Date.now(),
|
|
11023
|
+
metadata: {
|
|
11024
|
+
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
11025
|
+
...r !== void 0 ? { result: r } : {}
|
|
11026
|
+
}
|
|
11027
|
+
});
|
|
11028
|
+
return r;
|
|
11029
|
+
} catch (error) {
|
|
11030
|
+
emitLive({
|
|
11031
|
+
type: "tool_result",
|
|
11032
|
+
spanId: liveSpanId,
|
|
11033
|
+
content: toolName,
|
|
11034
|
+
timestamp: Date.now(),
|
|
11035
|
+
metadata: {
|
|
11036
|
+
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
11037
|
+
error: error instanceof Error ? error.message : String(error)
|
|
11038
|
+
}
|
|
11039
|
+
});
|
|
11040
|
+
throw error;
|
|
11041
|
+
}
|
|
11042
|
+
};
|
|
11043
|
+
return traceloop.withTool(
|
|
11044
|
+
{
|
|
11045
|
+
name: toolName,
|
|
11046
|
+
associationProperties: serializeAssociationProperties(properties),
|
|
11047
|
+
inputParameters: inputParams,
|
|
11048
|
+
version: params.version,
|
|
11049
|
+
traceContent: params.traceContent,
|
|
11050
|
+
suppressTracing: params.suppressTracing
|
|
11051
|
+
},
|
|
11052
|
+
wrapped,
|
|
11053
|
+
void 0,
|
|
11054
|
+
...args
|
|
11055
|
+
);
|
|
11050
11056
|
}
|
|
11051
11057
|
startSpan(params) {
|
|
11052
11058
|
const { name, properties = {} } = params;
|
|
@@ -11069,11 +11075,13 @@ var LiveInteraction = class {
|
|
|
11069
11075
|
const activeTraceContext = getActiveTraceContext();
|
|
11070
11076
|
const traceIdB64 = this.ensureTraceId(activeTraceContext.traceIdB64);
|
|
11071
11077
|
const { parentSpanIdB64 } = activeTraceContext;
|
|
11078
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
11072
11079
|
if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
|
|
11073
11080
|
console.log(`[raindrop] startToolSpan (direct): started tool span "${name}"`);
|
|
11074
11081
|
}
|
|
11075
11082
|
this.emitLiveEvent({
|
|
11076
11083
|
traceId: traceIdB64,
|
|
11084
|
+
spanId: spanIdB64,
|
|
11077
11085
|
type: "tool_start",
|
|
11078
11086
|
content: name,
|
|
11079
11087
|
timestamp: Date.now(),
|
|
@@ -11084,6 +11092,7 @@ var LiveInteraction = class {
|
|
|
11084
11092
|
properties: mergedProperties,
|
|
11085
11093
|
directShipper: this.directShipper,
|
|
11086
11094
|
traceId: traceIdB64,
|
|
11095
|
+
spanId: spanIdB64,
|
|
11087
11096
|
parentSpanId: parentSpanIdB64,
|
|
11088
11097
|
input: inputParameters,
|
|
11089
11098
|
emitLiveEvent: (event) => this.emitLiveEvent(event)
|
|
@@ -11099,8 +11108,11 @@ var LiveInteraction = class {
|
|
|
11099
11108
|
if ((_b = this.analytics) == null ? void 0 : _b.debugLogs) {
|
|
11100
11109
|
console.log(`[raindrop] startToolSpan: started tool span "${name}"`);
|
|
11101
11110
|
}
|
|
11111
|
+
const startSpanCtx = span.spanContext();
|
|
11112
|
+
const startSpanIdHex = (0, import_api2.isValidSpanId)(startSpanCtx.spanId) ? startSpanCtx.spanId : void 0;
|
|
11102
11113
|
this.emitLiveEvent({
|
|
11103
11114
|
type: "tool_start",
|
|
11115
|
+
spanId: startSpanIdHex,
|
|
11104
11116
|
content: name,
|
|
11105
11117
|
timestamp: Date.now(),
|
|
11106
11118
|
metadata: inputParameters !== void 0 ? { args: inputParameters } : void 0
|
|
@@ -11190,10 +11202,12 @@ var LiveInteraction = class {
|
|
|
11190
11202
|
const activeContext = getActiveTraceContext();
|
|
11191
11203
|
const traceIdB64 = this.ensureTraceId(activeContext.traceIdB64);
|
|
11192
11204
|
const { parentSpanIdB64 } = activeContext;
|
|
11205
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
11193
11206
|
const inputStr = input !== void 0 ? typeof input === "string" ? input : JSON.stringify(input) : void 0;
|
|
11194
11207
|
const outputStr = output !== void 0 ? typeof output === "string" ? output : JSON.stringify(output) : void 0;
|
|
11195
11208
|
this.directShipper.sendToolSpan({
|
|
11196
11209
|
name,
|
|
11210
|
+
spanId: spanIdB64,
|
|
11197
11211
|
input: inputStr,
|
|
11198
11212
|
output: outputStr,
|
|
11199
11213
|
durationMs,
|
|
@@ -11217,6 +11231,7 @@ var LiveInteraction = class {
|
|
|
11217
11231
|
}
|
|
11218
11232
|
this.emitLiveEvent({
|
|
11219
11233
|
traceId: traceIdB64,
|
|
11234
|
+
spanId: spanIdB64,
|
|
11220
11235
|
type: "tool_result",
|
|
11221
11236
|
content: name,
|
|
11222
11237
|
timestamp: endTimeMs,
|
|
@@ -11262,8 +11277,11 @@ var LiveInteraction = class {
|
|
|
11262
11277
|
error: error ? String(error) : void 0
|
|
11263
11278
|
});
|
|
11264
11279
|
}
|
|
11280
|
+
const trackToolCtx = span.spanContext();
|
|
11281
|
+
const trackToolSpanIdHex = (0, import_api2.isValidSpanId)(trackToolCtx.spanId) ? trackToolCtx.spanId : void 0;
|
|
11265
11282
|
this.emitLiveEvent({
|
|
11266
11283
|
type: "tool_result",
|
|
11284
|
+
spanId: trackToolSpanIdHex,
|
|
11267
11285
|
content: name,
|
|
11268
11286
|
timestamp: endTimeMs,
|
|
11269
11287
|
metadata: {
|
|
@@ -11325,10 +11343,12 @@ var LiveTracer = class {
|
|
|
11325
11343
|
const endTimeMs = startTimeMs + (durationMs != null ? durationMs : 0);
|
|
11326
11344
|
if (this.directShipper) {
|
|
11327
11345
|
const { traceIdB64, parentSpanIdB64 } = getActiveTraceContext();
|
|
11346
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
11328
11347
|
const inputStr = input !== void 0 ? typeof input === "string" ? input : JSON.stringify(input) : void 0;
|
|
11329
11348
|
const outputStr = output !== void 0 ? typeof output === "string" ? output : JSON.stringify(output) : void 0;
|
|
11330
11349
|
this.directShipper.sendToolSpan({
|
|
11331
11350
|
name,
|
|
11351
|
+
spanId: spanIdB64,
|
|
11332
11352
|
input: inputStr,
|
|
11333
11353
|
output: outputStr,
|
|
11334
11354
|
durationMs,
|
|
@@ -11345,6 +11365,7 @@ var LiveTracer = class {
|
|
|
11345
11365
|
if (traceIdB64) {
|
|
11346
11366
|
this.emitLiveEvent({
|
|
11347
11367
|
traceId: traceIdB64,
|
|
11368
|
+
spanId: spanIdB64,
|
|
11348
11369
|
type: "tool_result",
|
|
11349
11370
|
content: name,
|
|
11350
11371
|
timestamp: endTimeMs,
|
|
@@ -11386,10 +11407,13 @@ var LiveTracer = class {
|
|
|
11386
11407
|
span.setStatus({ code: import_api3.SpanStatusCode.OK });
|
|
11387
11408
|
}
|
|
11388
11409
|
span.end(endTimeMs);
|
|
11389
|
-
const
|
|
11410
|
+
const ctx = span.spanContext();
|
|
11411
|
+
const traceId = ctx.traceId || ((_a = import_api3.trace.getSpan(import_api3.context.active())) == null ? void 0 : _a.spanContext().traceId);
|
|
11412
|
+
const spanIdHex = (0, import_api3.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
|
|
11390
11413
|
if (traceId) {
|
|
11391
11414
|
this.emitLiveEvent({
|
|
11392
11415
|
traceId,
|
|
11416
|
+
spanId: spanIdHex,
|
|
11393
11417
|
type: "tool_result",
|
|
11394
11418
|
content: name,
|
|
11395
11419
|
timestamp: endTimeMs,
|
package/dist/index.mjs
CHANGED
package/dist/tracing/index.js
CHANGED
|
@@ -50,7 +50,7 @@ var import_instrumentation_vertexai = require("@traceloop/instrumentation-vertex
|
|
|
50
50
|
var traceloop3 = __toESM(require("@traceloop/node-server-sdk"));
|
|
51
51
|
var import_weakref = require("weakref");
|
|
52
52
|
|
|
53
|
-
// ../core/dist/chunk-
|
|
53
|
+
// ../core/dist/chunk-Y7SM66SW.js
|
|
54
54
|
function wait(ms) {
|
|
55
55
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
56
56
|
}
|
|
@@ -149,21 +149,6 @@ function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
|
149
149
|
function localDebuggerEnabled(baseUrl) {
|
|
150
150
|
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
151
151
|
}
|
|
152
|
-
function normalizeLocalDebuggerLiveEventType(type) {
|
|
153
|
-
switch (type) {
|
|
154
|
-
case "text-delta":
|
|
155
|
-
return "text_delta";
|
|
156
|
-
case "reasoning":
|
|
157
|
-
case "reasoning-delta":
|
|
158
|
-
return "reasoning_delta";
|
|
159
|
-
case "tool-call":
|
|
160
|
-
return "tool_start";
|
|
161
|
-
case "tool-result":
|
|
162
|
-
return "tool_result";
|
|
163
|
-
default:
|
|
164
|
-
return type;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
152
|
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
168
153
|
var _a;
|
|
169
154
|
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
@@ -183,7 +168,7 @@ function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
|
183
168
|
`${baseUrl}live`,
|
|
184
169
|
{
|
|
185
170
|
...event,
|
|
186
|
-
type:
|
|
171
|
+
type: event.type,
|
|
187
172
|
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
188
173
|
},
|
|
189
174
|
{},
|
|
@@ -351,7 +336,7 @@ function base64ToHex(base64) {
|
|
|
351
336
|
// package.json
|
|
352
337
|
var package_default = {
|
|
353
338
|
name: "raindrop-ai",
|
|
354
|
-
version: "0.0.
|
|
339
|
+
version: "0.0.92",
|
|
355
340
|
main: "dist/index.js",
|
|
356
341
|
module: "dist/index.mjs",
|
|
357
342
|
types: "dist/index.d.ts",
|
|
@@ -754,6 +739,10 @@ var LiveToolSpan = class {
|
|
|
754
739
|
this.name = params.name;
|
|
755
740
|
this.emitLiveEvent = params.emitLiveEvent;
|
|
756
741
|
}
|
|
742
|
+
spanIdHex() {
|
|
743
|
+
const ctx = this.span.spanContext();
|
|
744
|
+
return (0, import_api2.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
|
|
745
|
+
}
|
|
757
746
|
setInput(input) {
|
|
758
747
|
this.span.setAttribute("traceloop.entity.input", serializeSpanValue(input));
|
|
759
748
|
}
|
|
@@ -776,6 +765,7 @@ var LiveToolSpan = class {
|
|
|
776
765
|
(_a = this.emitLiveEvent) == null ? void 0 : _a.call(this, {
|
|
777
766
|
type: "tool_result",
|
|
778
767
|
content: this.name,
|
|
768
|
+
spanId: this.spanIdHex(),
|
|
779
769
|
metadata: {
|
|
780
770
|
...this.output !== void 0 ? { result: this.output } : {},
|
|
781
771
|
...this.errorMessage ? { error: this.errorMessage } : {}
|
|
@@ -790,6 +780,7 @@ var DirectToolSpan = class {
|
|
|
790
780
|
this.properties = params.properties;
|
|
791
781
|
this.directShipper = params.directShipper;
|
|
792
782
|
this.traceId = params.traceId;
|
|
783
|
+
this.spanId = params.spanId;
|
|
793
784
|
this.parentSpanId = params.parentSpanId;
|
|
794
785
|
this.startTimeMs = Date.now();
|
|
795
786
|
this.input = params.input !== void 0 ? serializeSpanValue(params.input) : void 0;
|
|
@@ -814,6 +805,7 @@ var DirectToolSpan = class {
|
|
|
814
805
|
const endTimeMs = Date.now();
|
|
815
806
|
this.directShipper.sendToolSpan({
|
|
816
807
|
name: this.name,
|
|
808
|
+
spanId: this.spanId,
|
|
817
809
|
input: this.input,
|
|
818
810
|
output: this.output,
|
|
819
811
|
durationMs: endTimeMs - this.startTimeMs,
|
|
@@ -826,6 +818,7 @@ var DirectToolSpan = class {
|
|
|
826
818
|
});
|
|
827
819
|
(_a = this.emitLiveEvent) == null ? void 0 : _a.call(this, {
|
|
828
820
|
traceId: this.traceId,
|
|
821
|
+
spanId: this.spanId,
|
|
829
822
|
type: "tool_result",
|
|
830
823
|
content: this.name,
|
|
831
824
|
timestamp: endTimeMs,
|
|
@@ -979,17 +972,18 @@ var LiveInteraction = class {
|
|
|
979
972
|
}
|
|
980
973
|
if (this.directShipper) {
|
|
981
974
|
const activeContext = getActiveTraceContext();
|
|
975
|
+
const traceIdB64 = this.ensureTraceId(activeContext.traceIdB64);
|
|
976
|
+
const { parentSpanIdB64 } = activeContext;
|
|
977
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
978
|
+
const startTimeMs = Date.now();
|
|
982
979
|
this.emitLiveEvent({
|
|
983
|
-
traceId:
|
|
980
|
+
traceId: traceIdB64,
|
|
981
|
+
spanId: spanIdB64,
|
|
984
982
|
type: "tool_start",
|
|
985
983
|
content: toolName,
|
|
986
|
-
timestamp:
|
|
984
|
+
timestamp: startTimeMs,
|
|
987
985
|
metadata: params.inputParameters ? { args: params.inputParameters } : void 0
|
|
988
986
|
});
|
|
989
|
-
const traceIdB64 = this.ensureTraceId(activeContext.traceIdB64);
|
|
990
|
-
const { parentSpanIdB64 } = activeContext;
|
|
991
|
-
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
992
|
-
const startTimeMs = Date.now();
|
|
993
987
|
const spanContext = {
|
|
994
988
|
traceId: base64ToHex(traceIdB64),
|
|
995
989
|
spanId: base64ToHex(spanIdB64),
|
|
@@ -1023,6 +1017,7 @@ var LiveInteraction = class {
|
|
|
1023
1017
|
});
|
|
1024
1018
|
this.emitLiveEvent({
|
|
1025
1019
|
traceId: traceIdB64,
|
|
1020
|
+
spanId: spanIdB64,
|
|
1026
1021
|
type: "tool_result",
|
|
1027
1022
|
content: toolName,
|
|
1028
1023
|
timestamp: endTimeMs2,
|
|
@@ -1052,6 +1047,7 @@ var LiveInteraction = class {
|
|
|
1052
1047
|
});
|
|
1053
1048
|
this.emitLiveEvent({
|
|
1054
1049
|
traceId: traceIdB64,
|
|
1050
|
+
spanId: spanIdB64,
|
|
1055
1051
|
type: "tool_result",
|
|
1056
1052
|
content: toolName,
|
|
1057
1053
|
timestamp: endTimeMs,
|
|
@@ -1062,49 +1058,59 @@ var LiveInteraction = class {
|
|
|
1062
1058
|
});
|
|
1063
1059
|
return result;
|
|
1064
1060
|
}
|
|
1065
|
-
this.emitLiveEvent({
|
|
1066
|
-
type: "tool_start",
|
|
1067
|
-
content: toolName,
|
|
1068
|
-
timestamp: Date.now(),
|
|
1069
|
-
metadata: params.inputParameters ? { args: params.inputParameters } : void 0
|
|
1070
|
-
});
|
|
1071
1061
|
const inputParams = params.inputParameters ? [params.inputParameters] : void 0;
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
suppressTracing: params.suppressTracing
|
|
1081
|
-
},
|
|
1082
|
-
fn,
|
|
1083
|
-
thisArg,
|
|
1084
|
-
...args
|
|
1085
|
-
);
|
|
1086
|
-
this.emitLiveEvent({
|
|
1087
|
-
type: "tool_result",
|
|
1088
|
-
content: toolName,
|
|
1089
|
-
timestamp: Date.now(),
|
|
1090
|
-
metadata: {
|
|
1091
|
-
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
1092
|
-
...result !== void 0 ? { result } : {}
|
|
1093
|
-
}
|
|
1094
|
-
});
|
|
1095
|
-
return result;
|
|
1096
|
-
} catch (error) {
|
|
1097
|
-
this.emitLiveEvent({
|
|
1098
|
-
type: "tool_result",
|
|
1062
|
+
const emitLive = (event) => this.emitLiveEvent(event);
|
|
1063
|
+
const wrapped = async (...wrappedArgs) => {
|
|
1064
|
+
const activeSpan = import_api2.trace.getSpan(import_api2.context.active());
|
|
1065
|
+
const ctx = activeSpan == null ? void 0 : activeSpan.spanContext();
|
|
1066
|
+
const liveSpanId = ctx && (0, import_api2.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
|
|
1067
|
+
emitLive({
|
|
1068
|
+
type: "tool_start",
|
|
1069
|
+
spanId: liveSpanId,
|
|
1099
1070
|
content: toolName,
|
|
1100
1071
|
timestamp: Date.now(),
|
|
1101
|
-
metadata: {
|
|
1102
|
-
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
1103
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1104
|
-
}
|
|
1072
|
+
metadata: params.inputParameters ? { args: params.inputParameters } : void 0
|
|
1105
1073
|
});
|
|
1106
|
-
|
|
1107
|
-
|
|
1074
|
+
try {
|
|
1075
|
+
const r = await fn.apply(thisArg, wrappedArgs);
|
|
1076
|
+
emitLive({
|
|
1077
|
+
type: "tool_result",
|
|
1078
|
+
spanId: liveSpanId,
|
|
1079
|
+
content: toolName,
|
|
1080
|
+
timestamp: Date.now(),
|
|
1081
|
+
metadata: {
|
|
1082
|
+
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
1083
|
+
...r !== void 0 ? { result: r } : {}
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
return r;
|
|
1087
|
+
} catch (error) {
|
|
1088
|
+
emitLive({
|
|
1089
|
+
type: "tool_result",
|
|
1090
|
+
spanId: liveSpanId,
|
|
1091
|
+
content: toolName,
|
|
1092
|
+
timestamp: Date.now(),
|
|
1093
|
+
metadata: {
|
|
1094
|
+
...params.inputParameters ? { args: params.inputParameters } : {},
|
|
1095
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
throw error;
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
return traceloop.withTool(
|
|
1102
|
+
{
|
|
1103
|
+
name: toolName,
|
|
1104
|
+
associationProperties: serializeAssociationProperties(properties),
|
|
1105
|
+
inputParameters: inputParams,
|
|
1106
|
+
version: params.version,
|
|
1107
|
+
traceContent: params.traceContent,
|
|
1108
|
+
suppressTracing: params.suppressTracing
|
|
1109
|
+
},
|
|
1110
|
+
wrapped,
|
|
1111
|
+
void 0,
|
|
1112
|
+
...args
|
|
1113
|
+
);
|
|
1108
1114
|
}
|
|
1109
1115
|
startSpan(params) {
|
|
1110
1116
|
const { name, properties = {} } = params;
|
|
@@ -1127,11 +1133,13 @@ var LiveInteraction = class {
|
|
|
1127
1133
|
const activeTraceContext = getActiveTraceContext();
|
|
1128
1134
|
const traceIdB64 = this.ensureTraceId(activeTraceContext.traceIdB64);
|
|
1129
1135
|
const { parentSpanIdB64 } = activeTraceContext;
|
|
1136
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
1130
1137
|
if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
|
|
1131
1138
|
console.log(`[raindrop] startToolSpan (direct): started tool span "${name}"`);
|
|
1132
1139
|
}
|
|
1133
1140
|
this.emitLiveEvent({
|
|
1134
1141
|
traceId: traceIdB64,
|
|
1142
|
+
spanId: spanIdB64,
|
|
1135
1143
|
type: "tool_start",
|
|
1136
1144
|
content: name,
|
|
1137
1145
|
timestamp: Date.now(),
|
|
@@ -1142,6 +1150,7 @@ var LiveInteraction = class {
|
|
|
1142
1150
|
properties: mergedProperties,
|
|
1143
1151
|
directShipper: this.directShipper,
|
|
1144
1152
|
traceId: traceIdB64,
|
|
1153
|
+
spanId: spanIdB64,
|
|
1145
1154
|
parentSpanId: parentSpanIdB64,
|
|
1146
1155
|
input: inputParameters,
|
|
1147
1156
|
emitLiveEvent: (event) => this.emitLiveEvent(event)
|
|
@@ -1157,8 +1166,11 @@ var LiveInteraction = class {
|
|
|
1157
1166
|
if ((_b = this.analytics) == null ? void 0 : _b.debugLogs) {
|
|
1158
1167
|
console.log(`[raindrop] startToolSpan: started tool span "${name}"`);
|
|
1159
1168
|
}
|
|
1169
|
+
const startSpanCtx = span.spanContext();
|
|
1170
|
+
const startSpanIdHex = (0, import_api2.isValidSpanId)(startSpanCtx.spanId) ? startSpanCtx.spanId : void 0;
|
|
1160
1171
|
this.emitLiveEvent({
|
|
1161
1172
|
type: "tool_start",
|
|
1173
|
+
spanId: startSpanIdHex,
|
|
1162
1174
|
content: name,
|
|
1163
1175
|
timestamp: Date.now(),
|
|
1164
1176
|
metadata: inputParameters !== void 0 ? { args: inputParameters } : void 0
|
|
@@ -1248,10 +1260,12 @@ var LiveInteraction = class {
|
|
|
1248
1260
|
const activeContext = getActiveTraceContext();
|
|
1249
1261
|
const traceIdB64 = this.ensureTraceId(activeContext.traceIdB64);
|
|
1250
1262
|
const { parentSpanIdB64 } = activeContext;
|
|
1263
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
1251
1264
|
const inputStr = input !== void 0 ? typeof input === "string" ? input : JSON.stringify(input) : void 0;
|
|
1252
1265
|
const outputStr = output !== void 0 ? typeof output === "string" ? output : JSON.stringify(output) : void 0;
|
|
1253
1266
|
this.directShipper.sendToolSpan({
|
|
1254
1267
|
name,
|
|
1268
|
+
spanId: spanIdB64,
|
|
1255
1269
|
input: inputStr,
|
|
1256
1270
|
output: outputStr,
|
|
1257
1271
|
durationMs,
|
|
@@ -1275,6 +1289,7 @@ var LiveInteraction = class {
|
|
|
1275
1289
|
}
|
|
1276
1290
|
this.emitLiveEvent({
|
|
1277
1291
|
traceId: traceIdB64,
|
|
1292
|
+
spanId: spanIdB64,
|
|
1278
1293
|
type: "tool_result",
|
|
1279
1294
|
content: name,
|
|
1280
1295
|
timestamp: endTimeMs,
|
|
@@ -1320,8 +1335,11 @@ var LiveInteraction = class {
|
|
|
1320
1335
|
error: error ? String(error) : void 0
|
|
1321
1336
|
});
|
|
1322
1337
|
}
|
|
1338
|
+
const trackToolCtx = span.spanContext();
|
|
1339
|
+
const trackToolSpanIdHex = (0, import_api2.isValidSpanId)(trackToolCtx.spanId) ? trackToolCtx.spanId : void 0;
|
|
1323
1340
|
this.emitLiveEvent({
|
|
1324
1341
|
type: "tool_result",
|
|
1342
|
+
spanId: trackToolSpanIdHex,
|
|
1325
1343
|
content: name,
|
|
1326
1344
|
timestamp: endTimeMs,
|
|
1327
1345
|
metadata: {
|
|
@@ -1383,10 +1401,12 @@ var LiveTracer = class {
|
|
|
1383
1401
|
const endTimeMs = startTimeMs + (durationMs != null ? durationMs : 0);
|
|
1384
1402
|
if (this.directShipper) {
|
|
1385
1403
|
const { traceIdB64, parentSpanIdB64 } = getActiveTraceContext();
|
|
1404
|
+
const spanIdB64 = base64Encode2(randomBytes2(8));
|
|
1386
1405
|
const inputStr = input !== void 0 ? typeof input === "string" ? input : JSON.stringify(input) : void 0;
|
|
1387
1406
|
const outputStr = output !== void 0 ? typeof output === "string" ? output : JSON.stringify(output) : void 0;
|
|
1388
1407
|
this.directShipper.sendToolSpan({
|
|
1389
1408
|
name,
|
|
1409
|
+
spanId: spanIdB64,
|
|
1390
1410
|
input: inputStr,
|
|
1391
1411
|
output: outputStr,
|
|
1392
1412
|
durationMs,
|
|
@@ -1403,6 +1423,7 @@ var LiveTracer = class {
|
|
|
1403
1423
|
if (traceIdB64) {
|
|
1404
1424
|
this.emitLiveEvent({
|
|
1405
1425
|
traceId: traceIdB64,
|
|
1426
|
+
spanId: spanIdB64,
|
|
1406
1427
|
type: "tool_result",
|
|
1407
1428
|
content: name,
|
|
1408
1429
|
timestamp: endTimeMs,
|
|
@@ -1444,10 +1465,13 @@ var LiveTracer = class {
|
|
|
1444
1465
|
span.setStatus({ code: import_api3.SpanStatusCode.OK });
|
|
1445
1466
|
}
|
|
1446
1467
|
span.end(endTimeMs);
|
|
1447
|
-
const
|
|
1468
|
+
const ctx = span.spanContext();
|
|
1469
|
+
const traceId = ctx.traceId || ((_a = import_api3.trace.getSpan(import_api3.context.active())) == null ? void 0 : _a.spanContext().traceId);
|
|
1470
|
+
const spanIdHex = (0, import_api3.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
|
|
1448
1471
|
if (traceId) {
|
|
1449
1472
|
this.emitLiveEvent({
|
|
1450
1473
|
traceId,
|
|
1474
|
+
spanId: spanIdHex,
|
|
1451
1475
|
type: "tool_result",
|
|
1452
1476
|
content: name,
|
|
1453
1477
|
timestamp: endTimeMs,
|
package/dist/tracing/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "raindrop-ai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.92-otelv2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,23 +37,22 @@
|
|
|
37
37
|
"dist/**"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"ai": "^6.0.0",
|
|
41
40
|
"@opentelemetry/resources": "^2.0.1",
|
|
42
41
|
"@types/node": "^20.11.17",
|
|
42
|
+
"ai": "^6.0.0",
|
|
43
43
|
"msw": "^2.12.8",
|
|
44
44
|
"tsup": "^8.4.0",
|
|
45
45
|
"tsx": "^4.20.3",
|
|
46
46
|
"typescript": "^5.3.3",
|
|
47
47
|
"vite": "^7.3.2",
|
|
48
48
|
"vitest": "^4.0.10",
|
|
49
|
-
"@raindrop-ai/core": "0.0.1",
|
|
50
49
|
"@raindrop-ai/redact-pii": "0.1.2",
|
|
50
|
+
"@raindrop-ai/core": "0.0.1",
|
|
51
51
|
"@raindrop-ai/schemas": "0.0.1"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@opentelemetry/api": "^1.9.0",
|
|
55
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.
|
|
56
|
-
"@traceloop/node-server-sdk": "0.19.0-otel-v1",
|
|
55
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
|
|
57
56
|
"weakref": "^0.2.1",
|
|
58
57
|
"zod": "^3.23.8"
|
|
59
58
|
},
|
|
@@ -96,6 +95,9 @@
|
|
|
96
95
|
},
|
|
97
96
|
"clean": true
|
|
98
97
|
},
|
|
98
|
+
"optionalDependencies": {
|
|
99
|
+
"@traceloop/node-server-sdk": "0.22.2"
|
|
100
|
+
},
|
|
99
101
|
"scripts": {
|
|
100
102
|
"build": "tsup",
|
|
101
103
|
"dev": "tsup --watch",
|