raindrop-ai 0.3.0 → 0.3.1
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-5Y3LWBKV.mjs → chunk-4TM4IWHB.mjs} +192 -77
- package/dist/{index-DBdUrUXc.d.mts → index-DuXeVnSq.d.mts} +32 -1
- package/dist/{index-DBdUrUXc.d.ts → index-DuXeVnSq.d.ts} +32 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +224 -74
- package/dist/index.mjs +36 -1
- package/dist/tracing/index.d.mts +6 -16
- package/dist/tracing/index.d.ts +6 -16
- package/dist/tracing/index.js +208 -91
- package/dist/tracing/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -4,7 +4,7 @@ if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
|
|
4
4
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
// ../core/dist/chunk-
|
|
7
|
+
// ../core/dist/chunk-3V4MIA75.js
|
|
8
8
|
function normalizeFeatureFlags(input) {
|
|
9
9
|
if (Array.isArray(input)) {
|
|
10
10
|
return Object.fromEntries(input.map((name) => [name, "true"]));
|
|
@@ -552,6 +552,20 @@ function stringifyBounded(value, limit) {
|
|
|
552
552
|
}
|
|
553
553
|
return json.length <= max ? json : truncateToLimit(json, max);
|
|
554
554
|
}
|
|
555
|
+
function attrString(key, value) {
|
|
556
|
+
if (value === void 0) return void 0;
|
|
557
|
+
return { key, value: { stringValue: value } };
|
|
558
|
+
}
|
|
559
|
+
function attrInt(key, value) {
|
|
560
|
+
if (value === void 0) return void 0;
|
|
561
|
+
if (!Number.isFinite(value)) return void 0;
|
|
562
|
+
return { key, value: { intValue: String(Math.trunc(value)) } };
|
|
563
|
+
}
|
|
564
|
+
function attrDouble(key, value) {
|
|
565
|
+
if (value === void 0) return void 0;
|
|
566
|
+
if (!Number.isFinite(value)) return void 0;
|
|
567
|
+
return { key, value: { doubleValue: value } };
|
|
568
|
+
}
|
|
555
569
|
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
556
570
|
var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
|
|
557
571
|
var DEFAULT_LOCAL_WORKSHOP_URL = "http://localhost:5899/v1/";
|
|
@@ -682,6 +696,7 @@ function projectIdHeaders(projectId) {
|
|
|
682
696
|
var SHUTDOWN_DEADLINE_MS = 1e4;
|
|
683
697
|
var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
684
698
|
var MODEL_USAGE_ATTRIBUTES = {
|
|
699
|
+
usageSource: "raindrop.usage.source",
|
|
685
700
|
providerName: "gen_ai.provider.name",
|
|
686
701
|
requestModel: "gen_ai.request.model",
|
|
687
702
|
responseModel: "gen_ai.response.model",
|
|
@@ -690,6 +705,7 @@ var MODEL_USAGE_ATTRIBUTES = {
|
|
|
690
705
|
reasoningTokens: "gen_ai.usage.reasoning_tokens",
|
|
691
706
|
cacheReadInputTokens: "gen_ai.usage.cache_read_input_tokens",
|
|
692
707
|
cacheWriteInputTokens: "gen_ai.usage.cache_write_input_tokens",
|
|
708
|
+
providerReportedCost: "gen_ai.usage.provider_reported_cost",
|
|
693
709
|
nonCachedInputTokens: "raindrop.usage.input_tokens.non_cached",
|
|
694
710
|
nonReasoningOutputTokens: "raindrop.usage.output_tokens.non_reasoning",
|
|
695
711
|
totalOutputTokens: "raindrop.usage.output_tokens.total",
|
|
@@ -697,6 +713,47 @@ var MODEL_USAGE_ATTRIBUTES = {
|
|
|
697
713
|
cacheReadTokens: "raindrop.usage.input_tokens.cache_read",
|
|
698
714
|
cacheWriteTokens: "raindrop.usage.input_tokens.cache_write"
|
|
699
715
|
};
|
|
716
|
+
var MODEL_PROVIDER_NAMES = [
|
|
717
|
+
["google.vertex.anthropic", "google-vertex"],
|
|
718
|
+
["google.vertex_ai", "google-vertex"],
|
|
719
|
+
["google.vertex", "google-vertex"],
|
|
720
|
+
["gcp.vertex_ai", "google-vertex"],
|
|
721
|
+
["gcp.gemini", "google"],
|
|
722
|
+
["google_vertexai", "google-vertex"],
|
|
723
|
+
["vertex.anthropic", "google-vertex"],
|
|
724
|
+
["amazon-bedrock", "amazon-bedrock"],
|
|
725
|
+
["aws.bedrock", "amazon-bedrock"],
|
|
726
|
+
["bedrock", "amazon-bedrock"],
|
|
727
|
+
["anthropic", "anthropic"],
|
|
728
|
+
["openai", "openai"],
|
|
729
|
+
["google", "google"],
|
|
730
|
+
["az.ai.openai", "azure"],
|
|
731
|
+
["azure", "azure"],
|
|
732
|
+
["openrouter", "openrouter"]
|
|
733
|
+
];
|
|
734
|
+
function canonicalModelProvider(provider) {
|
|
735
|
+
var _a;
|
|
736
|
+
const normalizedProvider = provider.trim().toLowerCase();
|
|
737
|
+
if (normalizedProvider === "gateway") return "vercel";
|
|
738
|
+
const match = MODEL_PROVIDER_NAMES.find(
|
|
739
|
+
([family]) => normalizedProvider === family || normalizedProvider.startsWith(`${family}.`)
|
|
740
|
+
);
|
|
741
|
+
return (_a = match == null ? void 0 : match[1]) != null ? _a : normalizedProvider;
|
|
742
|
+
}
|
|
743
|
+
function tokenCount(value) {
|
|
744
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
745
|
+
}
|
|
746
|
+
function buildRawModelUsageAttributes(usage) {
|
|
747
|
+
const providerReportedCost = typeof usage.providerReportedCost === "number" && Number.isFinite(usage.providerReportedCost) && usage.providerReportedCost >= 0 ? usage.providerReportedCost : void 0;
|
|
748
|
+
return [
|
|
749
|
+
attrInt(MODEL_USAGE_ATTRIBUTES.inputTokens, tokenCount(usage.inputTokens)),
|
|
750
|
+
attrInt(MODEL_USAGE_ATTRIBUTES.outputTokens, tokenCount(usage.outputTokens)),
|
|
751
|
+
attrInt(MODEL_USAGE_ATTRIBUTES.reasoningTokens, tokenCount(usage.reasoningTokens)),
|
|
752
|
+
attrInt(MODEL_USAGE_ATTRIBUTES.cacheReadInputTokens, tokenCount(usage.cacheReadInputTokens)),
|
|
753
|
+
attrInt(MODEL_USAGE_ATTRIBUTES.cacheWriteInputTokens, tokenCount(usage.cacheWriteInputTokens)),
|
|
754
|
+
attrDouble(MODEL_USAGE_ATTRIBUTES.providerReportedCost, providerReportedCost)
|
|
755
|
+
].filter((attribute) => attribute !== void 0);
|
|
756
|
+
}
|
|
700
757
|
var STRING_ALIASES = {
|
|
701
758
|
[MODEL_USAGE_ATTRIBUTES.requestModel]: ["ai.model.id", "ai.model"]
|
|
702
759
|
};
|
|
@@ -1040,7 +1097,7 @@ installTracingSuppressionHook();
|
|
|
1040
1097
|
// package.json
|
|
1041
1098
|
var package_default = {
|
|
1042
1099
|
name: "raindrop-ai",
|
|
1043
|
-
version: "0.3.
|
|
1100
|
+
version: "0.3.1",
|
|
1044
1101
|
main: "dist/index.js",
|
|
1045
1102
|
module: "dist/index.mjs",
|
|
1046
1103
|
types: "dist/index.d.ts",
|
|
@@ -1352,7 +1409,7 @@ function traceloopConfiguredWithoutClaim() {
|
|
|
1352
1409
|
}
|
|
1353
1410
|
|
|
1354
1411
|
// src/tracing/tracer-core.ts
|
|
1355
|
-
import {
|
|
1412
|
+
import { SpanStatusCode as SpanStatusCode5, context as context5, trace as trace5 } from "@opentelemetry/api";
|
|
1356
1413
|
import { OTLPTraceExporter as OTLPHttpTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
1357
1414
|
import { AnthropicInstrumentation } from "@traceloop/instrumentation-anthropic";
|
|
1358
1415
|
import { BedrockInstrumentation } from "@traceloop/instrumentation-bedrock";
|
|
@@ -1636,7 +1693,7 @@ var DirectTraceShipper = class {
|
|
|
1636
1693
|
* so spans still appear as children in the trace tree.
|
|
1637
1694
|
*/
|
|
1638
1695
|
sendSpan(params) {
|
|
1639
|
-
var _a, _b;
|
|
1696
|
+
var _a, _b, _c;
|
|
1640
1697
|
if (!this.enabled) return;
|
|
1641
1698
|
let traceIdB64 = params.traceId;
|
|
1642
1699
|
let parentSpanIdB64 = params.parentSpanId;
|
|
@@ -1680,6 +1737,7 @@ var DirectTraceShipper = class {
|
|
|
1680
1737
|
})) {
|
|
1681
1738
|
attributes.push(attrString2(key, value));
|
|
1682
1739
|
}
|
|
1740
|
+
attributes.push(...(_c = params.otlpAttributes) != null ? _c : []);
|
|
1683
1741
|
let status;
|
|
1684
1742
|
if (params.error) {
|
|
1685
1743
|
status = { code: 2, message: params.error };
|
|
@@ -1831,16 +1889,69 @@ var DirectTraceShipper = class {
|
|
|
1831
1889
|
}
|
|
1832
1890
|
};
|
|
1833
1891
|
|
|
1892
|
+
// src/tracing/exit-flush.ts
|
|
1893
|
+
import * as traceloop from "@traceloop/node-server-sdk";
|
|
1894
|
+
var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
|
|
1895
|
+
function getState2() {
|
|
1896
|
+
const holder = globalThis;
|
|
1897
|
+
let state = holder[STATE_KEY2];
|
|
1898
|
+
if (!state) {
|
|
1899
|
+
state = {
|
|
1900
|
+
clientFlushers: /* @__PURE__ */ new Set(),
|
|
1901
|
+
pipelineFlushNeeded: false,
|
|
1902
|
+
handlerRegistered: false
|
|
1903
|
+
};
|
|
1904
|
+
holder[STATE_KEY2] = state;
|
|
1905
|
+
}
|
|
1906
|
+
return state;
|
|
1907
|
+
}
|
|
1908
|
+
function ensureExitHandler(state) {
|
|
1909
|
+
if (state.handlerRegistered) return;
|
|
1910
|
+
if (typeof process === "undefined" || typeof process.once !== "function") return;
|
|
1911
|
+
state.handlerRegistered = true;
|
|
1912
|
+
process.once("beforeExit", () => {
|
|
1913
|
+
void flushAll();
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
function registerClientFlusher(flush) {
|
|
1917
|
+
const state = getState2();
|
|
1918
|
+
state.clientFlushers.add(flush);
|
|
1919
|
+
ensureExitHandler(state);
|
|
1920
|
+
return () => {
|
|
1921
|
+
state.clientFlushers.delete(flush);
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
function markPipelineForExitFlush() {
|
|
1925
|
+
const state = getState2();
|
|
1926
|
+
state.pipelineFlushNeeded = true;
|
|
1927
|
+
ensureExitHandler(state);
|
|
1928
|
+
}
|
|
1929
|
+
async function flushAll() {
|
|
1930
|
+
const state = getState2();
|
|
1931
|
+
const tasks = [];
|
|
1932
|
+
for (const flush of state.clientFlushers) {
|
|
1933
|
+
tasks.push(Promise.resolve().then(flush).catch(() => {
|
|
1934
|
+
}));
|
|
1935
|
+
}
|
|
1936
|
+
if (state.pipelineFlushNeeded) {
|
|
1937
|
+
tasks.push(
|
|
1938
|
+
Promise.resolve().then(() => traceloop.forceFlush()).catch(() => {
|
|
1939
|
+
})
|
|
1940
|
+
);
|
|
1941
|
+
}
|
|
1942
|
+
await Promise.all(tasks);
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1834
1945
|
// src/tracing/liveInteraction.ts
|
|
1835
1946
|
import {
|
|
1947
|
+
SpanStatusCode as SpanStatusCode3,
|
|
1948
|
+
TraceFlags,
|
|
1836
1949
|
context as context3,
|
|
1837
1950
|
isValidSpanId as isValidSpanId2,
|
|
1838
1951
|
isValidTraceId as isValidTraceId2,
|
|
1839
|
-
SpanStatusCode as SpanStatusCode3,
|
|
1840
|
-
TraceFlags,
|
|
1841
1952
|
trace as trace3
|
|
1842
1953
|
} from "@opentelemetry/api";
|
|
1843
|
-
import * as
|
|
1954
|
+
import * as traceloop2 from "@traceloop/node-server-sdk";
|
|
1844
1955
|
|
|
1845
1956
|
// src/tracing/subagents.ts
|
|
1846
1957
|
import { SpanStatusCode as SpanStatusCode2, context as context2, trace as trace2 } from "@opentelemetry/api";
|
|
@@ -2264,6 +2375,7 @@ var DirectToolSpan = class {
|
|
|
2264
2375
|
};
|
|
2265
2376
|
var LiveInteraction = class {
|
|
2266
2377
|
constructor(context6, traceId, analytics, directShipper, routing) {
|
|
2378
|
+
this.usageEmitted = false;
|
|
2267
2379
|
this.context = context6;
|
|
2268
2380
|
this.analytics = analytics;
|
|
2269
2381
|
this.tracer = trace3.getTracer("traceloop.tracer");
|
|
@@ -2348,10 +2460,7 @@ var LiveInteraction = class {
|
|
|
2348
2460
|
spanId: base64ToHex2(spanIdB64),
|
|
2349
2461
|
traceFlags: TraceFlags.SAMPLED
|
|
2350
2462
|
};
|
|
2351
|
-
const wrappedContext = trace3.setSpan(
|
|
2352
|
-
context3.active(),
|
|
2353
|
-
trace3.wrapSpanContext(spanContext)
|
|
2354
|
-
);
|
|
2463
|
+
const wrappedContext = trace3.setSpan(context3.active(), trace3.wrapSpanContext(spanContext));
|
|
2355
2464
|
const invoke = () => this.routing ? withRoutingContext(this.routing, () => fn.apply(thisArg, args)) : fn.apply(thisArg, args);
|
|
2356
2465
|
try {
|
|
2357
2466
|
const result = await context3.with(wrappedContext, invoke);
|
|
@@ -2402,7 +2511,7 @@ var LiveInteraction = class {
|
|
|
2402
2511
|
}
|
|
2403
2512
|
return fn.apply(thisArg, fnArgs);
|
|
2404
2513
|
};
|
|
2405
|
-
return
|
|
2514
|
+
return traceloop2.withTask(
|
|
2406
2515
|
{
|
|
2407
2516
|
name: taskName,
|
|
2408
2517
|
associationProperties: serializeAssociationProperties(properties),
|
|
@@ -2443,10 +2552,7 @@ var LiveInteraction = class {
|
|
|
2443
2552
|
spanId: base64ToHex2(spanIdB64),
|
|
2444
2553
|
traceFlags: TraceFlags.SAMPLED
|
|
2445
2554
|
};
|
|
2446
|
-
const wrappedContext = trace3.setSpan(
|
|
2447
|
-
context3.active(),
|
|
2448
|
-
trace3.wrapSpanContext(spanContext)
|
|
2449
|
-
);
|
|
2555
|
+
const wrappedContext = trace3.setSpan(context3.active(), trace3.wrapSpanContext(spanContext));
|
|
2450
2556
|
const invoke = () => this.routing ? withRoutingContext(this.routing, () => fn.apply(thisArg, args)) : fn.apply(thisArg, args);
|
|
2451
2557
|
let result;
|
|
2452
2558
|
let error;
|
|
@@ -2556,7 +2662,7 @@ var LiveInteraction = class {
|
|
|
2556
2662
|
throw error;
|
|
2557
2663
|
}
|
|
2558
2664
|
};
|
|
2559
|
-
return
|
|
2665
|
+
return traceloop2.withTool(
|
|
2560
2666
|
{
|
|
2561
2667
|
name: toolName,
|
|
2562
2668
|
associationProperties: serializeAssociationProperties(properties),
|
|
@@ -2859,7 +2965,7 @@ var LiveInteraction = class {
|
|
|
2859
2965
|
span.end();
|
|
2860
2966
|
}
|
|
2861
2967
|
async finish(resultEvent) {
|
|
2862
|
-
var _a, _b, _c, _d;
|
|
2968
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
2863
2969
|
unbindRoutingContext(this.boundContext);
|
|
2864
2970
|
this.boundContext = void 0;
|
|
2865
2971
|
unbindSpanAttributes(this.toolEventsFrame);
|
|
@@ -2867,6 +2973,15 @@ var LiveInteraction = class {
|
|
|
2867
2973
|
if (!this.traceId) {
|
|
2868
2974
|
this.resolveLiveTraceId();
|
|
2869
2975
|
}
|
|
2976
|
+
const eventId = resultEvent.eventId || this.context.eventId;
|
|
2977
|
+
if (!this.usageEmitted) {
|
|
2978
|
+
(_c = this.analytics) == null ? void 0 : _c._recordModelUsage(
|
|
2979
|
+
eventId,
|
|
2980
|
+
(_a = resultEvent.model) != null ? _a : this.context.model,
|
|
2981
|
+
(_b = resultEvent.usage) != null ? _b : this.context.usage
|
|
2982
|
+
);
|
|
2983
|
+
this.usageEmitted = true;
|
|
2984
|
+
}
|
|
2870
2985
|
const spanFlush = (async () => {
|
|
2871
2986
|
var _a2;
|
|
2872
2987
|
try {
|
|
@@ -2874,21 +2989,20 @@ var LiveInteraction = class {
|
|
|
2874
2989
|
} catch (e) {
|
|
2875
2990
|
}
|
|
2876
2991
|
})();
|
|
2877
|
-
if ((
|
|
2992
|
+
if ((_e = (_d = this.analytics) == null ? void 0 : _d._shouldBlockFinishFlush()) != null ? _e : true) {
|
|
2878
2993
|
await spanFlush;
|
|
2879
2994
|
} else {
|
|
2880
2995
|
void spanFlush.catch(() => {
|
|
2881
2996
|
});
|
|
2882
2997
|
}
|
|
2883
|
-
const eventId = resultEvent.eventId || this.context.eventId;
|
|
2884
2998
|
try {
|
|
2885
|
-
await ((
|
|
2999
|
+
await ((_f = this.analytics) == null ? void 0 : _f._drainInFlightPartials(eventId));
|
|
2886
3000
|
} catch (e) {
|
|
2887
3001
|
}
|
|
2888
3002
|
if (this.traceId) {
|
|
2889
3003
|
this.setProperty("trace_id", this.traceId);
|
|
2890
3004
|
}
|
|
2891
|
-
await ((
|
|
3005
|
+
await ((_g = this.analytics) == null ? void 0 : _g._trackAiPartial({
|
|
2892
3006
|
...resultEvent,
|
|
2893
3007
|
eventId,
|
|
2894
3008
|
isPending: false
|
|
@@ -3005,7 +3119,7 @@ var LiveInteraction = class {
|
|
|
3005
3119
|
|
|
3006
3120
|
// src/tracing/liveTracer.ts
|
|
3007
3121
|
import { context as context4, isValidSpanId as isValidSpanId3, SpanStatusCode as SpanStatusCode4, trace as trace4 } from "@opentelemetry/api";
|
|
3008
|
-
import * as
|
|
3122
|
+
import * as traceloop3 from "@traceloop/node-server-sdk";
|
|
3009
3123
|
var LiveTracer = class {
|
|
3010
3124
|
constructor(globalProperties, directShipper, routing) {
|
|
3011
3125
|
this.tracer = trace4.getTracer("traceloop.tracer");
|
|
@@ -3049,7 +3163,7 @@ var LiveTracer = class {
|
|
|
3049
3163
|
}
|
|
3050
3164
|
return fn.apply(thisArg, fnArgs);
|
|
3051
3165
|
};
|
|
3052
|
-
return
|
|
3166
|
+
return traceloop3.withTask(
|
|
3053
3167
|
{
|
|
3054
3168
|
name: taskName,
|
|
3055
3169
|
associationProperties: properties,
|
|
@@ -3161,59 +3275,6 @@ var LiveTracer = class {
|
|
|
3161
3275
|
}
|
|
3162
3276
|
};
|
|
3163
3277
|
|
|
3164
|
-
// src/tracing/exit-flush.ts
|
|
3165
|
-
import * as traceloop3 from "@traceloop/node-server-sdk";
|
|
3166
|
-
var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
|
|
3167
|
-
function getState2() {
|
|
3168
|
-
const holder = globalThis;
|
|
3169
|
-
let state = holder[STATE_KEY2];
|
|
3170
|
-
if (!state) {
|
|
3171
|
-
state = {
|
|
3172
|
-
clientFlushers: /* @__PURE__ */ new Set(),
|
|
3173
|
-
pipelineFlushNeeded: false,
|
|
3174
|
-
handlerRegistered: false
|
|
3175
|
-
};
|
|
3176
|
-
holder[STATE_KEY2] = state;
|
|
3177
|
-
}
|
|
3178
|
-
return state;
|
|
3179
|
-
}
|
|
3180
|
-
function ensureExitHandler(state) {
|
|
3181
|
-
if (state.handlerRegistered) return;
|
|
3182
|
-
if (typeof process === "undefined" || typeof process.once !== "function") return;
|
|
3183
|
-
state.handlerRegistered = true;
|
|
3184
|
-
process.once("beforeExit", () => {
|
|
3185
|
-
void flushAll();
|
|
3186
|
-
});
|
|
3187
|
-
}
|
|
3188
|
-
function registerClientFlusher(flush) {
|
|
3189
|
-
const state = getState2();
|
|
3190
|
-
state.clientFlushers.add(flush);
|
|
3191
|
-
ensureExitHandler(state);
|
|
3192
|
-
return () => {
|
|
3193
|
-
state.clientFlushers.delete(flush);
|
|
3194
|
-
};
|
|
3195
|
-
}
|
|
3196
|
-
function markPipelineForExitFlush() {
|
|
3197
|
-
const state = getState2();
|
|
3198
|
-
state.pipelineFlushNeeded = true;
|
|
3199
|
-
ensureExitHandler(state);
|
|
3200
|
-
}
|
|
3201
|
-
async function flushAll() {
|
|
3202
|
-
const state = getState2();
|
|
3203
|
-
const tasks = [];
|
|
3204
|
-
for (const flush of state.clientFlushers) {
|
|
3205
|
-
tasks.push(Promise.resolve().then(flush).catch(() => {
|
|
3206
|
-
}));
|
|
3207
|
-
}
|
|
3208
|
-
if (state.pipelineFlushNeeded) {
|
|
3209
|
-
tasks.push(
|
|
3210
|
-
Promise.resolve().then(() => traceloop3.forceFlush()).catch(() => {
|
|
3211
|
-
})
|
|
3212
|
-
);
|
|
3213
|
-
}
|
|
3214
|
-
await Promise.all(tasks);
|
|
3215
|
-
}
|
|
3216
|
-
|
|
3217
3278
|
// src/tracing/tracer-core.ts
|
|
3218
3279
|
if (localDebuggerEnabled()) {
|
|
3219
3280
|
if (!process.env.OTEL_EXPORTER_OTLP_PROTOCOL) {
|
|
@@ -3931,6 +3992,59 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
3931
3992
|
...frame ? { frame, frameOwner } : {}
|
|
3932
3993
|
});
|
|
3933
3994
|
};
|
|
3995
|
+
const recordModelUsage = (params) => {
|
|
3996
|
+
try {
|
|
3997
|
+
const attributes = [
|
|
3998
|
+
attrString(MODEL_USAGE_ATTRIBUTES.usageSource, "manual"),
|
|
3999
|
+
attrString(
|
|
4000
|
+
MODEL_USAGE_ATTRIBUTES.providerName,
|
|
4001
|
+
canonicalModelProvider(params.usage.provider)
|
|
4002
|
+
),
|
|
4003
|
+
attrString(MODEL_USAGE_ATTRIBUTES.requestModel, params.model),
|
|
4004
|
+
attrString(MODEL_USAGE_ATTRIBUTES.responseModel, params.model),
|
|
4005
|
+
...buildRawModelUsageAttributes({
|
|
4006
|
+
inputTokens: params.usage.inputTokens,
|
|
4007
|
+
outputTokens: params.usage.outputTokens,
|
|
4008
|
+
cacheReadInputTokens: params.usage.cacheReadTokens,
|
|
4009
|
+
cacheWriteInputTokens: params.usage.cacheWriteTokens,
|
|
4010
|
+
reasoningTokens: params.usage.reasoningTokens,
|
|
4011
|
+
providerReportedCost: params.usage.providerReportedCost
|
|
4012
|
+
})
|
|
4013
|
+
].filter((attribute) => attribute !== void 0);
|
|
4014
|
+
if (directShipper) {
|
|
4015
|
+
const timeMs = Date.now();
|
|
4016
|
+
directShipper.sendSpan({
|
|
4017
|
+
name: "ai.model.usage",
|
|
4018
|
+
spanKind: "llm",
|
|
4019
|
+
properties: { event_id: params.eventId },
|
|
4020
|
+
startTimeMs: timeMs,
|
|
4021
|
+
endTimeMs: timeMs,
|
|
4022
|
+
durationMs: 0,
|
|
4023
|
+
otlpAttributes: attributes
|
|
4024
|
+
});
|
|
4025
|
+
return;
|
|
4026
|
+
}
|
|
4027
|
+
const span = trace5.getTracer("traceloop.tracer").startSpan("ai.model.usage");
|
|
4028
|
+
span.setAttribute("traceloop.span.kind", "llm");
|
|
4029
|
+
span.setAttribute("traceloop.association.properties.event_id", params.eventId);
|
|
4030
|
+
stampSpan(span, projectId, authHint);
|
|
4031
|
+
for (const attribute of attributes) {
|
|
4032
|
+
const value = attribute.value;
|
|
4033
|
+
if (value.stringValue !== void 0) {
|
|
4034
|
+
span.setAttribute(attribute.key, value.stringValue);
|
|
4035
|
+
} else if (value.intValue !== void 0) {
|
|
4036
|
+
const parsed = Number(value.intValue);
|
|
4037
|
+
if (Number.isSafeInteger(parsed)) span.setAttribute(attribute.key, parsed);
|
|
4038
|
+
} else if (value.doubleValue !== void 0) {
|
|
4039
|
+
span.setAttribute(attribute.key, value.doubleValue);
|
|
4040
|
+
} else if (value.boolValue !== void 0) {
|
|
4041
|
+
span.setAttribute(attribute.key, value.boolValue);
|
|
4042
|
+
}
|
|
4043
|
+
}
|
|
4044
|
+
span.end();
|
|
4045
|
+
} catch (e) {
|
|
4046
|
+
}
|
|
4047
|
+
};
|
|
3934
4048
|
return {
|
|
3935
4049
|
/**
|
|
3936
4050
|
* Returns instrumentation instances for your NodeSDK.
|
|
@@ -4042,6 +4156,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
4042
4156
|
begin(traceContext) {
|
|
4043
4157
|
return beginInteraction(traceContext);
|
|
4044
4158
|
},
|
|
4159
|
+
recordModelUsage,
|
|
4045
4160
|
resumeSubagent(carrierOrHeaders, options2 = {}) {
|
|
4046
4161
|
return openSubagentRun(carrierOrHeaders, options2);
|
|
4047
4162
|
},
|
|
@@ -330,11 +330,42 @@ interface IdentifyEvent {
|
|
|
330
330
|
* @property input - An optional input property for the event, required if output is not provided.
|
|
331
331
|
* @property output - An optional output property for the event, required if input is not provided.
|
|
332
332
|
*/
|
|
333
|
+
declare const AiTrackUsageSchema: z.ZodObject<{
|
|
334
|
+
provider: z.ZodString;
|
|
335
|
+
inputTokens: z.ZodNumber;
|
|
336
|
+
outputTokens: z.ZodNumber;
|
|
337
|
+
cacheReadTokens: z.ZodOptional<z.ZodNumber>;
|
|
338
|
+
cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
|
|
339
|
+
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
|
340
|
+
providerReportedCost: z.ZodOptional<z.ZodNumber>;
|
|
341
|
+
}, "strip", z.ZodTypeAny, {
|
|
342
|
+
provider: string;
|
|
343
|
+
inputTokens: number;
|
|
344
|
+
outputTokens: number;
|
|
345
|
+
cacheReadTokens?: number | undefined;
|
|
346
|
+
cacheWriteTokens?: number | undefined;
|
|
347
|
+
reasoningTokens?: number | undefined;
|
|
348
|
+
providerReportedCost?: number | undefined;
|
|
349
|
+
}, {
|
|
350
|
+
provider: string;
|
|
351
|
+
inputTokens: number;
|
|
352
|
+
outputTokens: number;
|
|
353
|
+
cacheReadTokens?: number | undefined;
|
|
354
|
+
cacheWriteTokens?: number | undefined;
|
|
355
|
+
reasoningTokens?: number | undefined;
|
|
356
|
+
providerReportedCost?: number | undefined;
|
|
357
|
+
}>;
|
|
358
|
+
type AiTrackUsage = z.infer<typeof AiTrackUsageSchema>;
|
|
333
359
|
type AiTrackEvent = Omit<TrackEvent, "type"> & {
|
|
334
360
|
model?: string;
|
|
335
361
|
convoId?: string;
|
|
336
362
|
attachments?: Attachment[];
|
|
337
363
|
featureFlags?: RaindropFeatureFlags;
|
|
364
|
+
/**
|
|
365
|
+
* Raw values copied from the provider's usage object. Raindrop derives
|
|
366
|
+
* provider-specific billing pools on the server.
|
|
367
|
+
*/
|
|
368
|
+
usage?: AiTrackUsage;
|
|
338
369
|
} & ({
|
|
339
370
|
input: string;
|
|
340
371
|
output?: string;
|
|
@@ -1454,4 +1485,4 @@ declare class Raindrop {
|
|
|
1454
1485
|
private closeWithinDeadline;
|
|
1455
1486
|
}
|
|
1456
1487
|
|
|
1457
|
-
export { type
|
|
1488
|
+
export { type AiTrackUsage as A, type BeginInteractionOptions as B, type CarrierHeaders as C, type ToolSpan as D, type TraceContext as E, type FinishInteractionOptions as F, type TrackToolParams as G, resolveDisableBatching as H, type Interaction as I, type LocalDebuggerLiveEventInput as L, MAX_INGEST_SIZE_BYTES as M, type PartialAiTrackEvent as P, Raindrop as R, type SubagentResumeOptions as S, type TraceCarrier as T, type WorkflowParams as W, type RaindropSpanProcessor as a, type SubagentRun as b, type Tracer as c, type AiTrackEvent as d, type Attachment as e, type AttachmentType as f, type IdentifyEvent as g, type RaindropFeatureFlagValue as h, type RaindropFeatureFlags as i, type RaindropProperties as j, type RaindropPropertyLeaf as k, type RaindropPropertyValue as l, type SelfDiagnoseOptions as m, type SelfDiagnosticsExecuteContext as n, type SelfDiagnosticsExecuteResult as o, type SelfDiagnosticsSignalDefinition as p, type SelfDiagnosticsSignalDefinitions as q, type SelfDiagnosticsTool as r, type SelfDiagnosticsToolInputSchema as s, type SelfDiagnosticsToolOptions as t, type SignalEvent as u, type SpanParams as v, type SubagentDispatch as w, type SubagentDispatchOptions as x, type SubagentFinishOptions as y, type ToolParams as z };
|
|
@@ -330,11 +330,42 @@ interface IdentifyEvent {
|
|
|
330
330
|
* @property input - An optional input property for the event, required if output is not provided.
|
|
331
331
|
* @property output - An optional output property for the event, required if input is not provided.
|
|
332
332
|
*/
|
|
333
|
+
declare const AiTrackUsageSchema: z.ZodObject<{
|
|
334
|
+
provider: z.ZodString;
|
|
335
|
+
inputTokens: z.ZodNumber;
|
|
336
|
+
outputTokens: z.ZodNumber;
|
|
337
|
+
cacheReadTokens: z.ZodOptional<z.ZodNumber>;
|
|
338
|
+
cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
|
|
339
|
+
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
|
340
|
+
providerReportedCost: z.ZodOptional<z.ZodNumber>;
|
|
341
|
+
}, "strip", z.ZodTypeAny, {
|
|
342
|
+
provider: string;
|
|
343
|
+
inputTokens: number;
|
|
344
|
+
outputTokens: number;
|
|
345
|
+
cacheReadTokens?: number | undefined;
|
|
346
|
+
cacheWriteTokens?: number | undefined;
|
|
347
|
+
reasoningTokens?: number | undefined;
|
|
348
|
+
providerReportedCost?: number | undefined;
|
|
349
|
+
}, {
|
|
350
|
+
provider: string;
|
|
351
|
+
inputTokens: number;
|
|
352
|
+
outputTokens: number;
|
|
353
|
+
cacheReadTokens?: number | undefined;
|
|
354
|
+
cacheWriteTokens?: number | undefined;
|
|
355
|
+
reasoningTokens?: number | undefined;
|
|
356
|
+
providerReportedCost?: number | undefined;
|
|
357
|
+
}>;
|
|
358
|
+
type AiTrackUsage = z.infer<typeof AiTrackUsageSchema>;
|
|
333
359
|
type AiTrackEvent = Omit<TrackEvent, "type"> & {
|
|
334
360
|
model?: string;
|
|
335
361
|
convoId?: string;
|
|
336
362
|
attachments?: Attachment[];
|
|
337
363
|
featureFlags?: RaindropFeatureFlags;
|
|
364
|
+
/**
|
|
365
|
+
* Raw values copied from the provider's usage object. Raindrop derives
|
|
366
|
+
* provider-specific billing pools on the server.
|
|
367
|
+
*/
|
|
368
|
+
usage?: AiTrackUsage;
|
|
338
369
|
} & ({
|
|
339
370
|
input: string;
|
|
340
371
|
output?: string;
|
|
@@ -1454,4 +1485,4 @@ declare class Raindrop {
|
|
|
1454
1485
|
private closeWithinDeadline;
|
|
1455
1486
|
}
|
|
1456
1487
|
|
|
1457
|
-
export { type
|
|
1488
|
+
export { type AiTrackUsage as A, type BeginInteractionOptions as B, type CarrierHeaders as C, type ToolSpan as D, type TraceContext as E, type FinishInteractionOptions as F, type TrackToolParams as G, resolveDisableBatching as H, type Interaction as I, type LocalDebuggerLiveEventInput as L, MAX_INGEST_SIZE_BYTES as M, type PartialAiTrackEvent as P, Raindrop as R, type SubagentResumeOptions as S, type TraceCarrier as T, type WorkflowParams as W, type RaindropSpanProcessor as a, type SubagentRun as b, type Tracer as c, type AiTrackEvent as d, type Attachment as e, type AttachmentType as f, type IdentifyEvent as g, type RaindropFeatureFlagValue as h, type RaindropFeatureFlags as i, type RaindropProperties as j, type RaindropPropertyLeaf as k, type RaindropPropertyValue as l, type SelfDiagnoseOptions as m, type SelfDiagnosticsExecuteContext as n, type SelfDiagnosticsExecuteResult as o, type SelfDiagnosticsSignalDefinition as p, type SelfDiagnosticsSignalDefinitions as q, type SelfDiagnosticsTool as r, type SelfDiagnosticsToolInputSchema as s, type SelfDiagnosticsToolOptions as t, type SignalEvent as u, type SpanParams as v, type SubagentDispatch as w, type SubagentDispatchOptions as x, type SubagentFinishOptions as y, type ToolParams as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@opentelemetry/instrumentation';
|
|
2
|
-
export {
|
|
2
|
+
export { d as AiTrackEvent, A as AiTrackUsage, e as Attachment, f as AttachmentType, B as BeginInteractionOptions, F as FinishInteractionOptions, g as IdentifyEvent, I as Interaction, L as LocalDebuggerLiveEventInput, M as MAX_INGEST_SIZE_BYTES, P as PartialAiTrackEvent, R as Raindrop, h as RaindropFeatureFlagValue, i as RaindropFeatureFlags, j as RaindropProperties, k as RaindropPropertyLeaf, l as RaindropPropertyValue, a as RaindropSpanProcessor, m as SelfDiagnoseOptions, n as SelfDiagnosticsExecuteContext, o as SelfDiagnosticsExecuteResult, p as SelfDiagnosticsSignalDefinition, q as SelfDiagnosticsSignalDefinitions, r as SelfDiagnosticsTool, s as SelfDiagnosticsToolInputSchema, t as SelfDiagnosticsToolOptions, u as SignalEvent, v as SpanParams, w as SubagentDispatch, x as SubagentDispatchOptions, y as SubagentFinishOptions, S as SubagentResumeOptions, b as SubagentRun, z as ToolParams, D as ToolSpan, E as TraceContext, c as Tracer, G as TrackToolParams, W as WorkflowParams, R as default, H as resolveDisableBatching } from './index-DuXeVnSq.mjs';
|
|
3
3
|
import '@traceloop/node-server-sdk';
|
|
4
4
|
import '@opentelemetry/api';
|
|
5
5
|
import 'zod';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@opentelemetry/instrumentation';
|
|
2
|
-
export {
|
|
2
|
+
export { d as AiTrackEvent, A as AiTrackUsage, e as Attachment, f as AttachmentType, B as BeginInteractionOptions, F as FinishInteractionOptions, g as IdentifyEvent, I as Interaction, L as LocalDebuggerLiveEventInput, M as MAX_INGEST_SIZE_BYTES, P as PartialAiTrackEvent, R as Raindrop, h as RaindropFeatureFlagValue, i as RaindropFeatureFlags, j as RaindropProperties, k as RaindropPropertyLeaf, l as RaindropPropertyValue, a as RaindropSpanProcessor, m as SelfDiagnoseOptions, n as SelfDiagnosticsExecuteContext, o as SelfDiagnosticsExecuteResult, p as SelfDiagnosticsSignalDefinition, q as SelfDiagnosticsSignalDefinitions, r as SelfDiagnosticsTool, s as SelfDiagnosticsToolInputSchema, t as SelfDiagnosticsToolOptions, u as SignalEvent, v as SpanParams, w as SubagentDispatch, x as SubagentDispatchOptions, y as SubagentFinishOptions, S as SubagentResumeOptions, b as SubagentRun, z as ToolParams, D as ToolSpan, E as TraceContext, c as Tracer, G as TrackToolParams, W as WorkflowParams, R as default, H as resolveDisableBatching } from './index-DuXeVnSq.js';
|
|
3
3
|
import '@traceloop/node-server-sdk';
|
|
4
4
|
import '@opentelemetry/api';
|
|
5
5
|
import 'zod';
|