braintrust 3.22.0 → 3.23.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/README.md +43 -0
- package/dev/dist/index.d.mts +1 -1
- package/dev/dist/index.d.ts +1 -1
- package/dev/dist/index.js +1354 -652
- package/dev/dist/index.mjs +736 -34
- package/dist/apply-auto-instrumentation.js +222 -186
- package/dist/apply-auto-instrumentation.mjs +37 -1
- package/dist/auto-instrumentations/bundler/esbuild.cjs +53 -1
- package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
- package/dist/auto-instrumentations/bundler/next.cjs +53 -1
- package/dist/auto-instrumentations/bundler/next.mjs +3 -3
- package/dist/auto-instrumentations/bundler/rollup.cjs +53 -1
- package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
- package/dist/auto-instrumentations/bundler/vite.cjs +53 -1
- package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +53 -1
- package/dist/auto-instrumentations/bundler/webpack.cjs +53 -1
- package/dist/auto-instrumentations/bundler/webpack.mjs +3 -3
- package/dist/auto-instrumentations/{chunk-TKRPRPGD.mjs → chunk-EXY7QCJD.mjs} +5 -2
- package/dist/auto-instrumentations/{chunk-T6J4C7LX.mjs → chunk-KIMLYPRW.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-BRQX23KL.mjs → chunk-YXLNSAMJ.mjs} +51 -0
- package/dist/auto-instrumentations/hook.mjs +149 -20
- package/dist/auto-instrumentations/index.cjs +52 -0
- package/dist/auto-instrumentations/index.d.mts +3 -1
- package/dist/auto-instrumentations/index.d.ts +3 -1
- package/dist/auto-instrumentations/index.mjs +3 -1
- package/dist/browser.d.mts +11 -13
- package/dist/browser.d.ts +11 -13
- package/dist/browser.js +1098 -203
- package/dist/browser.mjs +1098 -203
- package/dist/{chunk-KMGUTPB7.mjs → chunk-36IPYKMG.mjs} +20 -1
- package/dist/{chunk-BFGIH2ZJ.js → chunk-CDIKAHDZ.js} +21 -2
- package/dist/{chunk-MWVVR5LR.js → chunk-FZWPFCVE.js} +1506 -820
- package/dist/{chunk-ZG2O3XVF.mjs → chunk-IXL4PMY4.mjs} +719 -33
- package/dist/cli.js +737 -35
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +1098 -203
- package/dist/edge-light.mjs +1098 -203
- package/dist/index.d.mts +11 -13
- package/dist/index.d.ts +11 -13
- package/dist/index.js +786 -593
- package/dist/index.mjs +346 -153
- package/dist/instrumentation/index.d.mts +3 -11
- package/dist/instrumentation/index.d.ts +3 -11
- package/dist/instrumentation/index.js +788 -181
- package/dist/instrumentation/index.mjs +788 -181
- package/dist/vitest-evals-reporter.js +16 -16
- package/dist/vitest-evals-reporter.mjs +2 -2
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +1098 -203
- package/dist/workerd.mjs +1098 -203
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -139,7 +139,7 @@ import {
|
|
|
139
139
|
wrapMastraAgent,
|
|
140
140
|
wrapTraced,
|
|
141
141
|
zodToJsonSchema
|
|
142
|
-
} from "./chunk-
|
|
142
|
+
} from "./chunk-IXL4PMY4.mjs";
|
|
143
143
|
import {
|
|
144
144
|
__export,
|
|
145
145
|
aiSDKChannels,
|
|
@@ -155,6 +155,7 @@ import {
|
|
|
155
155
|
groqChannels,
|
|
156
156
|
huggingFaceChannels,
|
|
157
157
|
isomorph_default,
|
|
158
|
+
langSmithChannels,
|
|
158
159
|
mistralChannels,
|
|
159
160
|
openAIChannels,
|
|
160
161
|
openAICodexChannels,
|
|
@@ -162,7 +163,7 @@ import {
|
|
|
162
163
|
openRouterChannels,
|
|
163
164
|
piCodingAgentChannels,
|
|
164
165
|
strandsAgentSDKChannels
|
|
165
|
-
} from "./chunk-
|
|
166
|
+
} from "./chunk-36IPYKMG.mjs";
|
|
166
167
|
|
|
167
168
|
// src/exports.ts
|
|
168
169
|
var exports_exports = {};
|
|
@@ -321,6 +322,9 @@ __export(exports_exports, {
|
|
|
321
322
|
wrapGoogleGenAI: () => wrapGoogleGenAI,
|
|
322
323
|
wrapGroq: () => wrapGroq,
|
|
323
324
|
wrapHuggingFace: () => wrapHuggingFace,
|
|
325
|
+
wrapLangSmithClient: () => wrapLangSmithClient,
|
|
326
|
+
wrapLangSmithRunTrees: () => wrapLangSmithRunTrees,
|
|
327
|
+
wrapLangSmithTraceable: () => wrapLangSmithTraceable,
|
|
324
328
|
wrapMastraAgent: () => wrapMastraAgent,
|
|
325
329
|
wrapMistral: () => wrapMistral,
|
|
326
330
|
wrapOpenAI: () => wrapOpenAI,
|
|
@@ -1807,9 +1811,6 @@ var EveBridge = class {
|
|
|
1807
1811
|
this.state = state;
|
|
1808
1812
|
}
|
|
1809
1813
|
eventQueuesBySession = /* @__PURE__ */ new Map();
|
|
1810
|
-
sessionsById = new LRUCache({
|
|
1811
|
-
max: MAX_EVE_CACHE_ENTRIES
|
|
1812
|
-
});
|
|
1813
1814
|
completedToolKeys = new LRUCache({
|
|
1814
1815
|
max: MAX_EVE_CACHE_ENTRIES
|
|
1815
1816
|
});
|
|
@@ -1976,7 +1977,7 @@ var EveBridge = class {
|
|
|
1976
1977
|
async handleEvent(event, ctx, hookMetadata) {
|
|
1977
1978
|
switch (event.type) {
|
|
1978
1979
|
case "session.started":
|
|
1979
|
-
|
|
1980
|
+
this.handleSessionStarted(event, ctx, hookMetadata);
|
|
1980
1981
|
return true;
|
|
1981
1982
|
case "turn.started":
|
|
1982
1983
|
await this.handleTurnStarted(event, ctx, hookMetadata);
|
|
@@ -2012,22 +2013,22 @@ var EveBridge = class {
|
|
|
2012
2013
|
this.handleStepFailed(event, ctx);
|
|
2013
2014
|
return true;
|
|
2014
2015
|
case "turn.completed":
|
|
2015
|
-
|
|
2016
|
+
this.handleTurnCompleted(event, ctx);
|
|
2016
2017
|
return true;
|
|
2017
2018
|
case "turn.failed":
|
|
2018
|
-
|
|
2019
|
+
this.handleTurnFailed(event, ctx);
|
|
2019
2020
|
return true;
|
|
2020
2021
|
case "session.failed":
|
|
2021
|
-
|
|
2022
|
+
this.handleSessionFailed(event, ctx);
|
|
2022
2023
|
return true;
|
|
2023
2024
|
case "session.completed":
|
|
2024
|
-
|
|
2025
|
+
this.handleSessionCompleted(event, ctx);
|
|
2025
2026
|
return true;
|
|
2026
2027
|
default:
|
|
2027
2028
|
return false;
|
|
2028
2029
|
}
|
|
2029
2030
|
}
|
|
2030
|
-
|
|
2031
|
+
handleSessionStarted(event, ctx, hookMetadata) {
|
|
2031
2032
|
const sessionId = sessionIdFromContext(ctx);
|
|
2032
2033
|
if (!sessionId) {
|
|
2033
2034
|
return;
|
|
@@ -2043,7 +2044,6 @@ var EveBridge = class {
|
|
|
2043
2044
|
metadata: { ...normalized.metadata, ...metadata }
|
|
2044
2045
|
};
|
|
2045
2046
|
});
|
|
2046
|
-
await this.ensureSession(sessionId, ctx, metadata, eventTime(event));
|
|
2047
2047
|
for (const [key, turn] of this.turnsByKey) {
|
|
2048
2048
|
if (!key.startsWith(`${sessionId}:`)) {
|
|
2049
2049
|
continue;
|
|
@@ -2061,21 +2061,19 @@ var EveBridge = class {
|
|
|
2061
2061
|
if (!sessionId) {
|
|
2062
2062
|
return;
|
|
2063
2063
|
}
|
|
2064
|
-
const session = await this.ensureSession(
|
|
2065
|
-
sessionId,
|
|
2066
|
-
ctx,
|
|
2067
|
-
hookMetadata ?? {},
|
|
2068
|
-
eventTime(event)
|
|
2069
|
-
);
|
|
2070
2064
|
const key = turnKey(sessionId, event.data.turnId);
|
|
2071
|
-
const metadata = {
|
|
2065
|
+
const metadata = {
|
|
2066
|
+
...readEveTraceState(this.state).metadata,
|
|
2067
|
+
...hookMetadata ?? {},
|
|
2068
|
+
"eve.session_id": sessionId
|
|
2069
|
+
};
|
|
2072
2070
|
const existing = this.turnsByKey.get(key);
|
|
2073
2071
|
if (existing) {
|
|
2074
2072
|
existing.metadata = { ...existing.metadata, ...metadata };
|
|
2075
2073
|
existing.span.log({ metadata: existing.metadata });
|
|
2076
2074
|
return;
|
|
2077
2075
|
}
|
|
2078
|
-
const span = await this.startTurnSpan(
|
|
2076
|
+
const span = await this.startTurnSpan(sessionId, event, ctx, metadata);
|
|
2079
2077
|
span.log({ metadata });
|
|
2080
2078
|
this.turnsByKey.set(key, {
|
|
2081
2079
|
key,
|
|
@@ -2113,10 +2111,7 @@ var EveBridge = class {
|
|
|
2113
2111
|
this.markStepEnded(event.data.turnId, event.data.stepIndex);
|
|
2114
2112
|
}
|
|
2115
2113
|
const stepOrdinal = this.stepOrdinal(event);
|
|
2116
|
-
const metadata = {
|
|
2117
|
-
...turn.metadata,
|
|
2118
|
-
...this.sessionsById.get(sessionId)?.metadata ?? {}
|
|
2119
|
-
};
|
|
2114
|
+
const metadata = { ...turn.metadata };
|
|
2120
2115
|
const input = consumeCapturedEveModelInput(
|
|
2121
2116
|
this.state,
|
|
2122
2117
|
sessionId,
|
|
@@ -2211,6 +2206,28 @@ var EveBridge = class {
|
|
|
2211
2206
|
if (!step) {
|
|
2212
2207
|
return;
|
|
2213
2208
|
}
|
|
2209
|
+
const toolCallsById = /* @__PURE__ */ new Map();
|
|
2210
|
+
if (Array.isArray(step.output) && isObject(step.output[0])) {
|
|
2211
|
+
const message = step.output[0]["message"];
|
|
2212
|
+
if (isObject(message) && Array.isArray(message["tool_calls"])) {
|
|
2213
|
+
for (const toolCall of message["tool_calls"]) {
|
|
2214
|
+
if (isObject(toolCall) && typeof toolCall["id"] === "string") {
|
|
2215
|
+
toolCallsById.set(toolCall["id"], toolCall);
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
for (const action of traceActions) {
|
|
2221
|
+
const name = action.kind === "tool-call" ? action.toolName : action.subagentName ?? action.name ?? "agent";
|
|
2222
|
+
toolCallsById.set(action.callId, {
|
|
2223
|
+
function: {
|
|
2224
|
+
arguments: JSON.stringify(action.input),
|
|
2225
|
+
name
|
|
2226
|
+
},
|
|
2227
|
+
id: action.callId,
|
|
2228
|
+
type: "function"
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2214
2231
|
step.output = [
|
|
2215
2232
|
{
|
|
2216
2233
|
finish_reason: "tool_calls",
|
|
@@ -2218,17 +2235,7 @@ var EveBridge = class {
|
|
|
2218
2235
|
message: {
|
|
2219
2236
|
content: null,
|
|
2220
2237
|
role: "assistant",
|
|
2221
|
-
tool_calls:
|
|
2222
|
-
const name = action.kind === "tool-call" ? action.toolName : action.subagentName ?? action.name ?? "agent";
|
|
2223
|
-
return {
|
|
2224
|
-
function: {
|
|
2225
|
-
arguments: JSON.stringify(action.input),
|
|
2226
|
-
name
|
|
2227
|
-
},
|
|
2228
|
-
id: action.callId,
|
|
2229
|
-
type: "function"
|
|
2230
|
-
};
|
|
2231
|
-
})
|
|
2238
|
+
tool_calls: [...toolCallsById.values()]
|
|
2232
2239
|
}
|
|
2233
2240
|
}
|
|
2234
2241
|
];
|
|
@@ -2475,17 +2482,11 @@ var EveBridge = class {
|
|
|
2475
2482
|
)
|
|
2476
2483
|
});
|
|
2477
2484
|
}
|
|
2478
|
-
|
|
2485
|
+
handleSessionFailed(event, ctx) {
|
|
2479
2486
|
const sessionId = event.data.sessionId || sessionIdFromContext(ctx);
|
|
2480
2487
|
if (!sessionId) {
|
|
2481
2488
|
return;
|
|
2482
2489
|
}
|
|
2483
|
-
const session = await this.ensureSession(
|
|
2484
|
-
sessionId,
|
|
2485
|
-
ctx,
|
|
2486
|
-
{},
|
|
2487
|
-
eventTime(event)
|
|
2488
|
-
);
|
|
2489
2490
|
const error = errorFromMessage(
|
|
2490
2491
|
event.data.message,
|
|
2491
2492
|
event.data.code,
|
|
@@ -2502,29 +2503,20 @@ var EveBridge = class {
|
|
|
2502
2503
|
}
|
|
2503
2504
|
for (const [key, tool] of this.toolsByCallKey) {
|
|
2504
2505
|
if (key.startsWith(`${sessionId}:`)) {
|
|
2505
|
-
const
|
|
2506
|
+
const endTime = eventTime(event);
|
|
2506
2507
|
if (!tool.endedByTurn) {
|
|
2507
2508
|
tool.span.log({ metadata: tool.metadata });
|
|
2508
|
-
tool.span.end(
|
|
2509
|
+
tool.span.end(endTime === void 0 ? void 0 : { endTime });
|
|
2509
2510
|
tool.endedByTurn = true;
|
|
2510
2511
|
}
|
|
2511
2512
|
}
|
|
2512
2513
|
}
|
|
2513
|
-
session.span.log({ error });
|
|
2514
|
-
const endTime = eventTime(event);
|
|
2515
|
-
session.span.end(endTime === void 0 ? void 0 : { endTime });
|
|
2516
2514
|
}
|
|
2517
|
-
|
|
2515
|
+
handleSessionCompleted(event, ctx) {
|
|
2518
2516
|
const sessionId = sessionIdFromContext(ctx);
|
|
2519
2517
|
if (!sessionId) {
|
|
2520
2518
|
return;
|
|
2521
2519
|
}
|
|
2522
|
-
const session = await this.ensureSession(
|
|
2523
|
-
sessionId,
|
|
2524
|
-
ctx,
|
|
2525
|
-
{},
|
|
2526
|
-
eventTime(event)
|
|
2527
|
-
);
|
|
2528
2520
|
for (const [key, turn] of this.turnsByKey) {
|
|
2529
2521
|
if (!key.startsWith(`${sessionId}:`)) {
|
|
2530
2522
|
continue;
|
|
@@ -2535,82 +2527,29 @@ var EveBridge = class {
|
|
|
2535
2527
|
}
|
|
2536
2528
|
for (const [key, tool] of this.toolsByCallKey) {
|
|
2537
2529
|
if (key.startsWith(`${sessionId}:`) && !tool.endedByTurn) {
|
|
2538
|
-
const
|
|
2530
|
+
const endTime = eventTime(event);
|
|
2539
2531
|
tool.span.log({ metadata: tool.metadata });
|
|
2540
|
-
tool.span.end(
|
|
2532
|
+
tool.span.end(endTime === void 0 ? void 0 : { endTime });
|
|
2541
2533
|
tool.endedByTurn = true;
|
|
2542
2534
|
}
|
|
2543
2535
|
}
|
|
2544
|
-
session.span.log({ metadata: session.metadata });
|
|
2545
|
-
const endTime = eventTime(event);
|
|
2546
|
-
session.span.end(endTime === void 0 ? void 0 : { endTime });
|
|
2547
|
-
}
|
|
2548
|
-
async ensureSession(sessionId, ctx, metadata, startTime) {
|
|
2549
|
-
metadata = {
|
|
2550
|
-
...readEveTraceState(this.state).metadata,
|
|
2551
|
-
...metadata
|
|
2552
|
-
};
|
|
2553
|
-
const existing = this.sessionsById.get(sessionId);
|
|
2554
|
-
if (existing) {
|
|
2555
|
-
existing.metadata = { ...existing.metadata, ...metadata };
|
|
2556
|
-
existing.span.log({ metadata: existing.metadata });
|
|
2557
|
-
return existing;
|
|
2558
|
-
}
|
|
2559
|
-
const lineage = parentLineageFromContext(ctx);
|
|
2560
|
-
const parentSubagent = lineage ? this.toolsByCallKey.get(toolKey(lineage.sessionId, lineage.callId)) : void 0;
|
|
2561
|
-
const activeParent = currentSpan();
|
|
2562
|
-
const [
|
|
2563
|
-
{ rowId: eventId, spanId },
|
|
2564
|
-
parentSubagentSpanId,
|
|
2565
|
-
fallbackRootSpanId
|
|
2566
|
-
] = await Promise.all([
|
|
2567
|
-
generateEveIds("session", sessionId),
|
|
2568
|
-
lineage ? spanIdForSubagent(lineage.sessionId, lineage.callId) : Promise.resolve(void 0),
|
|
2569
|
-
lineage ? rootSpanIdForSession(lineage.rootSessionId) : rootSpanIdForSession(sessionId)
|
|
2570
|
-
]);
|
|
2571
|
-
const span = await this.startEveSpan({
|
|
2572
|
-
event: {
|
|
2573
|
-
id: eventId,
|
|
2574
|
-
metadata
|
|
2575
|
-
},
|
|
2576
|
-
name: "eve.session",
|
|
2577
|
-
parentSpanIds: lineage && parentSubagentSpanId ? {
|
|
2578
|
-
rootSpanId: parentSubagent?.span.rootSpanId ?? fallbackRootSpanId,
|
|
2579
|
-
spanId: parentSubagentSpanId
|
|
2580
|
-
} : !Object.is(activeParent, NOOP_SPAN) ? {
|
|
2581
|
-
rootSpanId: activeParent.rootSpanId,
|
|
2582
|
-
spanId: activeParent.spanId
|
|
2583
|
-
} : {
|
|
2584
|
-
parentSpanIds: [],
|
|
2585
|
-
rootSpanId: fallbackRootSpanId
|
|
2586
|
-
},
|
|
2587
|
-
spanAttributes: { type: "task" /* TASK */ },
|
|
2588
|
-
spanId,
|
|
2589
|
-
startTime
|
|
2590
|
-
});
|
|
2591
|
-
span.log({ metadata });
|
|
2592
|
-
const session = { metadata, sessionId, span };
|
|
2593
|
-
this.sessionsById.set(sessionId, session);
|
|
2594
|
-
return session;
|
|
2595
2536
|
}
|
|
2596
2537
|
async ensureTurn(event, ctx, hookMetadata) {
|
|
2597
2538
|
const sessionId = sessionIdFromContext(ctx);
|
|
2598
2539
|
if (!sessionId) {
|
|
2599
2540
|
return void 0;
|
|
2600
2541
|
}
|
|
2601
|
-
const session = await this.ensureSession(
|
|
2602
|
-
sessionId,
|
|
2603
|
-
ctx,
|
|
2604
|
-
hookMetadata ?? {},
|
|
2605
|
-
eventTime(event)
|
|
2606
|
-
);
|
|
2607
2542
|
const key = turnKey(sessionId, event.data.turnId);
|
|
2608
2543
|
const existing = this.turnsByKey.get(key);
|
|
2609
2544
|
if (existing) {
|
|
2610
2545
|
return existing;
|
|
2611
2546
|
}
|
|
2612
|
-
const metadata = {
|
|
2613
|
-
|
|
2547
|
+
const metadata = {
|
|
2548
|
+
...readEveTraceState(this.state).metadata,
|
|
2549
|
+
...hookMetadata ?? {},
|
|
2550
|
+
"eve.session_id": sessionId
|
|
2551
|
+
};
|
|
2552
|
+
const span = await this.startTurnSpan(sessionId, event, ctx, metadata);
|
|
2614
2553
|
span.log({ metadata });
|
|
2615
2554
|
const state = {
|
|
2616
2555
|
key,
|
|
@@ -2797,22 +2736,35 @@ var EveBridge = class {
|
|
|
2797
2736
|
this.toolsByCallKey.set(toolKey(sessionId, result.callId), state);
|
|
2798
2737
|
return state;
|
|
2799
2738
|
}
|
|
2800
|
-
async startTurnSpan(
|
|
2801
|
-
const
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2739
|
+
async startTurnSpan(sessionId, event, ctx, metadata) {
|
|
2740
|
+
const session = isObject(ctx) ? ctx["session"] : void 0;
|
|
2741
|
+
const parent = isObject(session) ? session["parent"] : void 0;
|
|
2742
|
+
const parentTurn = isObject(parent) ? parent["turn"] : void 0;
|
|
2743
|
+
const parentLineage = isObject(parent) && typeof parent["callId"] === "string" && typeof parent["sessionId"] === "string" && isObject(parentTurn) && typeof parentTurn["id"] === "string" ? {
|
|
2744
|
+
callId: parent["callId"],
|
|
2745
|
+
sessionId: parent["sessionId"],
|
|
2746
|
+
turnId: parentTurn["id"]
|
|
2747
|
+
} : void 0;
|
|
2748
|
+
const [{ rowId: eventId, spanId }, rootSpanId, parentSpanId] = await Promise.all([
|
|
2749
|
+
generateEveIds("turn", sessionId, event.data.turnId),
|
|
2750
|
+
deterministicEveId(
|
|
2751
|
+
"eve:root",
|
|
2752
|
+
parentLineage?.sessionId ?? sessionId,
|
|
2753
|
+
parentLineage?.turnId ?? event.data.turnId
|
|
2754
|
+
),
|
|
2755
|
+
parentLineage ? deterministicEveId(
|
|
2756
|
+
"eve:subagent",
|
|
2757
|
+
parentLineage.sessionId,
|
|
2758
|
+
parentLineage.callId
|
|
2759
|
+
) : Promise.resolve(void 0)
|
|
2760
|
+
]);
|
|
2806
2761
|
return await this.startEveSpan({
|
|
2807
2762
|
event: {
|
|
2808
2763
|
id: eventId,
|
|
2809
2764
|
metadata
|
|
2810
2765
|
},
|
|
2811
2766
|
name: "eve.turn",
|
|
2812
|
-
parentSpanIds: {
|
|
2813
|
-
rootSpanId: session.span.rootSpanId,
|
|
2814
|
-
spanId: session.span.spanId
|
|
2815
|
-
},
|
|
2767
|
+
parentSpanIds: parentSpanId ? { rootSpanId, spanId: parentSpanId } : { parentSpanIds: [], rootSpanId },
|
|
2816
2768
|
spanAttributes: { type: "task" /* TASK */ },
|
|
2817
2769
|
spanId,
|
|
2818
2770
|
startTime: eventTime(event)
|
|
@@ -2873,7 +2825,6 @@ var EveBridge = class {
|
|
|
2873
2825
|
}
|
|
2874
2826
|
cleanupSession(sessionId) {
|
|
2875
2827
|
const keyPrefix = `${sessionId}:`;
|
|
2876
|
-
this.sessionsById.delete(sessionId);
|
|
2877
2828
|
for (const key of this.turnsByKey.keys()) {
|
|
2878
2829
|
if (key.startsWith(keyPrefix)) {
|
|
2879
2830
|
this.turnsByKey.delete(key);
|
|
@@ -3064,7 +3015,7 @@ function modelMetadataFromRuntime(runtime) {
|
|
|
3064
3015
|
return {};
|
|
3065
3016
|
}
|
|
3066
3017
|
const modelId = runtime["modelId"];
|
|
3067
|
-
return typeof modelId === "string" ? modelMetadataFromModelId(modelId) : {};
|
|
3018
|
+
return typeof modelId === "string" && !modelId.trim().startsWith("dynamic:") ? modelMetadataFromModelId(modelId) : {};
|
|
3068
3019
|
}
|
|
3069
3020
|
function modelMetadataFromModelId(modelId) {
|
|
3070
3021
|
const normalized = modelId.trim();
|
|
@@ -3097,26 +3048,6 @@ function toolMetadataFromTurn(turn) {
|
|
|
3097
3048
|
const { model: _model, provider: _provider, ...metadata } = turn.metadata;
|
|
3098
3049
|
return metadata;
|
|
3099
3050
|
}
|
|
3100
|
-
function parentLineageFromContext(ctx) {
|
|
3101
|
-
if (!isObject(ctx)) {
|
|
3102
|
-
return void 0;
|
|
3103
|
-
}
|
|
3104
|
-
const session = ctx.session;
|
|
3105
|
-
if (!isObject(session)) {
|
|
3106
|
-
return void 0;
|
|
3107
|
-
}
|
|
3108
|
-
const parent = session["parent"];
|
|
3109
|
-
if (!isObject(parent)) {
|
|
3110
|
-
return void 0;
|
|
3111
|
-
}
|
|
3112
|
-
const callId = parent["callId"];
|
|
3113
|
-
const rootSessionId = parent["rootSessionId"];
|
|
3114
|
-
const sessionId = parent["sessionId"];
|
|
3115
|
-
if (typeof callId !== "string" || typeof rootSessionId !== "string" || typeof sessionId !== "string") {
|
|
3116
|
-
return void 0;
|
|
3117
|
-
}
|
|
3118
|
-
return { callId, rootSessionId, sessionId };
|
|
3119
|
-
}
|
|
3120
3051
|
function isToolCallAction(action) {
|
|
3121
3052
|
return isObject(action) && action["kind"] === "tool-call" && typeof action["callId"] === "string" && typeof action["toolName"] === "string" && isObject(action["input"]);
|
|
3122
3053
|
}
|
|
@@ -3172,9 +3103,6 @@ function turnKey(sessionId, turnId) {
|
|
|
3172
3103
|
function toolKey(sessionId, callId) {
|
|
3173
3104
|
return `${sessionId}:${callId}`;
|
|
3174
3105
|
}
|
|
3175
|
-
async function rootSpanIdForSession(sessionId) {
|
|
3176
|
-
return deterministicEveId("eve:root", sessionId);
|
|
3177
|
-
}
|
|
3178
3106
|
async function generateEveIds(kind, ...parts) {
|
|
3179
3107
|
const [rowId, spanId] = await Promise.all([
|
|
3180
3108
|
deterministicEveId(`eve:row:${kind}`, ...parts),
|
|
@@ -3182,9 +3110,6 @@ async function generateEveIds(kind, ...parts) {
|
|
|
3182
3110
|
]);
|
|
3183
3111
|
return { rowId, spanId };
|
|
3184
3112
|
}
|
|
3185
|
-
async function spanIdForSubagent(sessionId, callId) {
|
|
3186
|
-
return deterministicEveId("eve:subagent", sessionId, callId);
|
|
3187
|
-
}
|
|
3188
3113
|
async function deterministicEveId(...parts) {
|
|
3189
3114
|
const data = new TextEncoder().encode(
|
|
3190
3115
|
parts.map((part) => `${part.length}:${part}`).join("\0")
|
|
@@ -5205,6 +5130,271 @@ function wrappedResumeSession(client) {
|
|
|
5205
5130
|
);
|
|
5206
5131
|
}
|
|
5207
5132
|
|
|
5133
|
+
// src/wrappers/langsmith.ts
|
|
5134
|
+
var WRAPPED_CLIENT_CLASS = /* @__PURE__ */ Symbol.for(
|
|
5135
|
+
"braintrust.langsmith.wrapped-client-class"
|
|
5136
|
+
);
|
|
5137
|
+
var WRAPPED_CLIENT_INSTANCE = /* @__PURE__ */ Symbol.for(
|
|
5138
|
+
"braintrust.langsmith.wrapped-client-instance"
|
|
5139
|
+
);
|
|
5140
|
+
var WRAPPED_CLIENT_NAMESPACE = /* @__PURE__ */ Symbol.for(
|
|
5141
|
+
"braintrust.langsmith.wrapped-client-namespace"
|
|
5142
|
+
);
|
|
5143
|
+
var WRAPPED_RUN_TREE_CLASS = /* @__PURE__ */ Symbol.for(
|
|
5144
|
+
"braintrust.langsmith.wrapped-run-tree-class"
|
|
5145
|
+
);
|
|
5146
|
+
var WRAPPED_RUN_TREE_INSTANCE = /* @__PURE__ */ Symbol.for(
|
|
5147
|
+
"braintrust.langsmith.wrapped-run-tree-instance"
|
|
5148
|
+
);
|
|
5149
|
+
var WRAPPED_RUN_TREES_NAMESPACE = /* @__PURE__ */ Symbol.for(
|
|
5150
|
+
"braintrust.langsmith.wrapped-run-trees-namespace"
|
|
5151
|
+
);
|
|
5152
|
+
var WRAPPED_TRACEABLE = /* @__PURE__ */ Symbol.for("braintrust.langsmith.wrapped-traceable");
|
|
5153
|
+
var WRAPPED_TRACEABLE_NAMESPACE = /* @__PURE__ */ Symbol.for(
|
|
5154
|
+
"braintrust.langsmith.wrapped-traceable-namespace"
|
|
5155
|
+
);
|
|
5156
|
+
function wrapLangSmithTraceable(namespace) {
|
|
5157
|
+
return wrapNamespaceExport(
|
|
5158
|
+
namespace,
|
|
5159
|
+
"traceable",
|
|
5160
|
+
WRAPPED_TRACEABLE_NAMESPACE,
|
|
5161
|
+
(value) => wrapTraceable(value)
|
|
5162
|
+
);
|
|
5163
|
+
}
|
|
5164
|
+
function wrapLangSmithRunTrees(namespace) {
|
|
5165
|
+
return wrapNamespaceExport(
|
|
5166
|
+
namespace,
|
|
5167
|
+
"RunTree",
|
|
5168
|
+
WRAPPED_RUN_TREES_NAMESPACE,
|
|
5169
|
+
(value) => wrapRunTreeClass(value)
|
|
5170
|
+
);
|
|
5171
|
+
}
|
|
5172
|
+
function wrapLangSmithClient(namespace) {
|
|
5173
|
+
return wrapNamespaceExport(
|
|
5174
|
+
namespace,
|
|
5175
|
+
"Client",
|
|
5176
|
+
WRAPPED_CLIENT_NAMESPACE,
|
|
5177
|
+
(value) => wrapClientClass(value)
|
|
5178
|
+
);
|
|
5179
|
+
}
|
|
5180
|
+
function wrapNamespaceExport(namespace, exportName, marker, wrap2) {
|
|
5181
|
+
if (!namespace || typeof namespace !== "object") {
|
|
5182
|
+
return namespace;
|
|
5183
|
+
}
|
|
5184
|
+
const candidate = namespace;
|
|
5185
|
+
if (candidate[marker] === true) {
|
|
5186
|
+
return namespace;
|
|
5187
|
+
}
|
|
5188
|
+
if (typeof candidate[exportName] !== "function") {
|
|
5189
|
+
console.warn(
|
|
5190
|
+
`Unsupported LangSmith ${exportName} namespace. Not wrapping.`
|
|
5191
|
+
);
|
|
5192
|
+
return namespace;
|
|
5193
|
+
}
|
|
5194
|
+
const target = isModuleNamespace5(namespace) ? Object.setPrototypeOf({}, namespace) : candidate;
|
|
5195
|
+
const moduleNamespace = target !== candidate;
|
|
5196
|
+
let wrappedExport;
|
|
5197
|
+
return new Proxy(target, {
|
|
5198
|
+
get(target2, prop, receiver) {
|
|
5199
|
+
if (prop === marker) {
|
|
5200
|
+
return true;
|
|
5201
|
+
}
|
|
5202
|
+
const value = Reflect.get(target2, prop, receiver);
|
|
5203
|
+
if (prop !== exportName || typeof value !== "function") {
|
|
5204
|
+
return value;
|
|
5205
|
+
}
|
|
5206
|
+
wrappedExport ??= wrap2(value);
|
|
5207
|
+
return wrappedExport;
|
|
5208
|
+
},
|
|
5209
|
+
getOwnPropertyDescriptor(target2, prop) {
|
|
5210
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target2, prop);
|
|
5211
|
+
if (descriptor || !moduleNamespace) {
|
|
5212
|
+
return descriptor;
|
|
5213
|
+
}
|
|
5214
|
+
const namespaceDescriptor = Reflect.getOwnPropertyDescriptor(
|
|
5215
|
+
candidate,
|
|
5216
|
+
prop
|
|
5217
|
+
);
|
|
5218
|
+
return namespaceDescriptor ? { ...namespaceDescriptor, configurable: true } : void 0;
|
|
5219
|
+
},
|
|
5220
|
+
has(target2, prop) {
|
|
5221
|
+
return Reflect.has(target2, prop) || moduleNamespace && prop in candidate;
|
|
5222
|
+
},
|
|
5223
|
+
ownKeys(target2) {
|
|
5224
|
+
return moduleNamespace ? Reflect.ownKeys(candidate) : Reflect.ownKeys(target2);
|
|
5225
|
+
}
|
|
5226
|
+
});
|
|
5227
|
+
}
|
|
5228
|
+
function isModuleNamespace5(value) {
|
|
5229
|
+
if (!value || typeof value !== "object") {
|
|
5230
|
+
return false;
|
|
5231
|
+
}
|
|
5232
|
+
if (value.constructor?.name === "Module") {
|
|
5233
|
+
return true;
|
|
5234
|
+
}
|
|
5235
|
+
const firstKey = Object.keys(value)[0];
|
|
5236
|
+
if (!firstKey) {
|
|
5237
|
+
return false;
|
|
5238
|
+
}
|
|
5239
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, firstKey);
|
|
5240
|
+
return descriptor ? !descriptor.configurable && !descriptor.writable : false;
|
|
5241
|
+
}
|
|
5242
|
+
function wrapTraceable(traceable2) {
|
|
5243
|
+
if (traceable2[WRAPPED_TRACEABLE]) {
|
|
5244
|
+
return traceable2;
|
|
5245
|
+
}
|
|
5246
|
+
return new Proxy(traceable2, {
|
|
5247
|
+
get(target, prop, receiver) {
|
|
5248
|
+
if (prop === WRAPPED_TRACEABLE) {
|
|
5249
|
+
return true;
|
|
5250
|
+
}
|
|
5251
|
+
return Reflect.get(target, prop, receiver);
|
|
5252
|
+
},
|
|
5253
|
+
apply(target, thisArg, argArray) {
|
|
5254
|
+
const [fn, rawConfig] = argArray;
|
|
5255
|
+
const config = rawConfig && typeof rawConfig === "object" ? rawConfig : void 0;
|
|
5256
|
+
const originalOnEnd = config?.on_end;
|
|
5257
|
+
const wrappedConfig = {
|
|
5258
|
+
...config,
|
|
5259
|
+
on_end(runTree) {
|
|
5260
|
+
publishRunUpdate(runTree);
|
|
5261
|
+
if (originalOnEnd) {
|
|
5262
|
+
Reflect.apply(originalOnEnd, config, [runTree]);
|
|
5263
|
+
}
|
|
5264
|
+
}
|
|
5265
|
+
};
|
|
5266
|
+
return Reflect.apply(target, thisArg, [fn, wrappedConfig]);
|
|
5267
|
+
}
|
|
5268
|
+
});
|
|
5269
|
+
}
|
|
5270
|
+
function wrapRunTreeClass(RunTree) {
|
|
5271
|
+
if (RunTree[WRAPPED_RUN_TREE_CLASS]) {
|
|
5272
|
+
return RunTree;
|
|
5273
|
+
}
|
|
5274
|
+
return new Proxy(RunTree, {
|
|
5275
|
+
get(target, prop, receiver) {
|
|
5276
|
+
if (prop === WRAPPED_RUN_TREE_CLASS) {
|
|
5277
|
+
return true;
|
|
5278
|
+
}
|
|
5279
|
+
const value = Reflect.get(target, prop, receiver);
|
|
5280
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
5281
|
+
},
|
|
5282
|
+
construct(target, args, newTarget) {
|
|
5283
|
+
return wrapRunTreeInstance(Reflect.construct(target, args, newTarget));
|
|
5284
|
+
}
|
|
5285
|
+
});
|
|
5286
|
+
}
|
|
5287
|
+
function wrapRunTreeInstance(runTree) {
|
|
5288
|
+
if (runTree[WRAPPED_RUN_TREE_INSTANCE]) {
|
|
5289
|
+
return runTree;
|
|
5290
|
+
}
|
|
5291
|
+
return new Proxy(runTree, {
|
|
5292
|
+
get(target, prop, receiver) {
|
|
5293
|
+
if (prop === WRAPPED_RUN_TREE_INSTANCE) {
|
|
5294
|
+
return true;
|
|
5295
|
+
}
|
|
5296
|
+
const value = Reflect.get(target, prop, receiver);
|
|
5297
|
+
if (typeof value !== "function") {
|
|
5298
|
+
return value;
|
|
5299
|
+
}
|
|
5300
|
+
let wrapped;
|
|
5301
|
+
if (prop === "createChild") {
|
|
5302
|
+
wrapped = (...args) => wrapRunTreeInstance(Reflect.apply(value, target, args));
|
|
5303
|
+
} else if (prop === "postRun") {
|
|
5304
|
+
const method = value;
|
|
5305
|
+
wrapped = (...args) => langSmithChannels.createRun.tracePromise(
|
|
5306
|
+
() => Reflect.apply(method, target, args),
|
|
5307
|
+
{ arguments: [target] }
|
|
5308
|
+
);
|
|
5309
|
+
} else if (prop === "patchRun") {
|
|
5310
|
+
const method = value;
|
|
5311
|
+
wrapped = (...args) => langSmithChannels.updateRun.tracePromise(
|
|
5312
|
+
() => Reflect.apply(method, target, args),
|
|
5313
|
+
{
|
|
5314
|
+
arguments: [
|
|
5315
|
+
typeof target.id === "string" ? target.id : "",
|
|
5316
|
+
target
|
|
5317
|
+
]
|
|
5318
|
+
}
|
|
5319
|
+
);
|
|
5320
|
+
} else {
|
|
5321
|
+
wrapped = value.bind(target);
|
|
5322
|
+
}
|
|
5323
|
+
return wrapped;
|
|
5324
|
+
}
|
|
5325
|
+
});
|
|
5326
|
+
}
|
|
5327
|
+
function wrapClientClass(Client) {
|
|
5328
|
+
if (Client[WRAPPED_CLIENT_CLASS]) {
|
|
5329
|
+
return Client;
|
|
5330
|
+
}
|
|
5331
|
+
return new Proxy(Client, {
|
|
5332
|
+
get(target, prop, receiver) {
|
|
5333
|
+
if (prop === WRAPPED_CLIENT_CLASS) {
|
|
5334
|
+
return true;
|
|
5335
|
+
}
|
|
5336
|
+
const value = Reflect.get(target, prop, receiver);
|
|
5337
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
5338
|
+
},
|
|
5339
|
+
construct(target, args, newTarget) {
|
|
5340
|
+
return wrapClientInstance(Reflect.construct(target, args, newTarget));
|
|
5341
|
+
}
|
|
5342
|
+
});
|
|
5343
|
+
}
|
|
5344
|
+
function wrapClientInstance(client) {
|
|
5345
|
+
if (client[WRAPPED_CLIENT_INSTANCE]) {
|
|
5346
|
+
return client;
|
|
5347
|
+
}
|
|
5348
|
+
return new Proxy(client, {
|
|
5349
|
+
get(target, prop, receiver) {
|
|
5350
|
+
if (prop === WRAPPED_CLIENT_INSTANCE) {
|
|
5351
|
+
return true;
|
|
5352
|
+
}
|
|
5353
|
+
const value = Reflect.get(target, prop, receiver);
|
|
5354
|
+
if (typeof value !== "function") {
|
|
5355
|
+
return value;
|
|
5356
|
+
}
|
|
5357
|
+
let wrapped;
|
|
5358
|
+
if (prop === "createRun") {
|
|
5359
|
+
const method = value;
|
|
5360
|
+
wrapped = (...args) => langSmithChannels.createRun.tracePromise(
|
|
5361
|
+
() => Reflect.apply(method, target, args),
|
|
5362
|
+
{ arguments: args }
|
|
5363
|
+
);
|
|
5364
|
+
} else if (prop === "updateRun") {
|
|
5365
|
+
const method = value;
|
|
5366
|
+
wrapped = (...args) => langSmithChannels.updateRun.tracePromise(
|
|
5367
|
+
() => Reflect.apply(method, target, args),
|
|
5368
|
+
{ arguments: args }
|
|
5369
|
+
);
|
|
5370
|
+
} else if (prop === "batchIngestRuns") {
|
|
5371
|
+
const method = value;
|
|
5372
|
+
wrapped = (...args) => langSmithChannels.batchIngestRuns.tracePromise(
|
|
5373
|
+
() => Reflect.apply(method, target, args),
|
|
5374
|
+
{ arguments: args }
|
|
5375
|
+
);
|
|
5376
|
+
} else {
|
|
5377
|
+
wrapped = value.bind(target);
|
|
5378
|
+
}
|
|
5379
|
+
return wrapped;
|
|
5380
|
+
}
|
|
5381
|
+
});
|
|
5382
|
+
}
|
|
5383
|
+
function publishRunUpdate(runTree) {
|
|
5384
|
+
if (!runTree || typeof runTree.id !== "string" || !runTree.id) {
|
|
5385
|
+
return;
|
|
5386
|
+
}
|
|
5387
|
+
try {
|
|
5388
|
+
void langSmithChannels.updateRun.tracePromise(() => Promise.resolve(void 0), {
|
|
5389
|
+
arguments: [runTree.id, runTree]
|
|
5390
|
+
}).catch((error) => {
|
|
5391
|
+
debugLogger.error("LangSmith traceable instrumentation failed:", error);
|
|
5392
|
+
});
|
|
5393
|
+
} catch (error) {
|
|
5394
|
+
debugLogger.error("LangSmith traceable instrumentation failed:", error);
|
|
5395
|
+
}
|
|
5396
|
+
}
|
|
5397
|
+
|
|
5208
5398
|
// src/wrappers/vitest/context-manager.ts
|
|
5209
5399
|
var VitestContextManager = class {
|
|
5210
5400
|
/**
|
|
@@ -9617,6 +9807,9 @@ export {
|
|
|
9617
9807
|
wrapGoogleGenAI,
|
|
9618
9808
|
wrapGroq,
|
|
9619
9809
|
wrapHuggingFace,
|
|
9810
|
+
wrapLangSmithClient,
|
|
9811
|
+
wrapLangSmithRunTrees,
|
|
9812
|
+
wrapLangSmithTraceable,
|
|
9620
9813
|
wrapMastraAgent,
|
|
9621
9814
|
wrapMistral,
|
|
9622
9815
|
wrapOpenAI,
|