braintrust 2.2.1-rc.0 → 2.2.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/dev/dist/index.d.mts +1 -1
- package/dev/dist/index.d.ts +1 -1
- package/dev/dist/index.js +7 -7
- package/dev/dist/index.mjs +13 -13
- package/dist/browser.d.mts +239 -239
- package/dist/browser.d.ts +239 -239
- package/dist/browser.js +220 -57
- package/dist/browser.mjs +192 -29
- package/dist/cli.js +1214 -718
- package/dist/index.d.mts +239 -239
- package/dist/index.d.ts +239 -239
- package/dist/index.js +220 -57
- package/dist/index.mjs +198 -35
- package/package.json +23 -23
- package/util/dist/index.d.mts +3 -2
- package/util/dist/index.d.ts +3 -2
- package/util/dist/index.js +3 -1
- package/util/dist/index.mjs +3 -1
- package/LICENSE +0 -201
- package/dist/eval-runner.js +0 -12680
package/dist/index.js
CHANGED
|
@@ -2150,7 +2150,8 @@ var SpanType = _v3.z.union([
|
|
|
2150
2150
|
"automation",
|
|
2151
2151
|
"facet",
|
|
2152
2152
|
"preprocessor",
|
|
2153
|
-
"classifier"
|
|
2153
|
+
"classifier",
|
|
2154
|
+
"review"
|
|
2154
2155
|
]),
|
|
2155
2156
|
_v3.z.null()
|
|
2156
2157
|
]);
|
|
@@ -12922,14 +12923,17 @@ function parseToolName(rawToolName) {
|
|
|
12922
12923
|
rawToolName
|
|
12923
12924
|
};
|
|
12924
12925
|
}
|
|
12925
|
-
function createToolTracingHooks(
|
|
12926
|
+
function createToolTracingHooks(resolveParentSpan, activeToolSpans, mcpServers, subAgentSpans, endedSubAgentSpans) {
|
|
12926
12927
|
const preToolUse = async (input, toolUseID) => {
|
|
12927
12928
|
if (input.hook_event_name !== "PreToolUse" || !toolUseID) {
|
|
12928
12929
|
return {};
|
|
12929
12930
|
}
|
|
12931
|
+
if (input.tool_name === "Task") {
|
|
12932
|
+
return {};
|
|
12933
|
+
}
|
|
12930
12934
|
const parsed = parseToolName(input.tool_name);
|
|
12931
12935
|
const mcpMetadata = getMcpServerMetadata(parsed.mcpServer, mcpServers);
|
|
12932
|
-
const parentExport = await
|
|
12936
|
+
const parentExport = await resolveParentSpan(toolUseID);
|
|
12933
12937
|
const toolSpan = startSpan({
|
|
12934
12938
|
name: parsed.displayName,
|
|
12935
12939
|
spanAttributes: { type: "tool" /* TOOL */ },
|
|
@@ -12957,6 +12961,30 @@ function createToolTracingHooks(parentSpanExportPromise, activeToolSpans, mcpSer
|
|
|
12957
12961
|
if (input.hook_event_name !== "PostToolUse" || !toolUseID) {
|
|
12958
12962
|
return {};
|
|
12959
12963
|
}
|
|
12964
|
+
const subAgentSpan = subAgentSpans.get(toolUseID);
|
|
12965
|
+
if (subAgentSpan) {
|
|
12966
|
+
try {
|
|
12967
|
+
const response = input.tool_response;
|
|
12968
|
+
const metadata = {};
|
|
12969
|
+
if (_optionalChain([response, 'optionalAccess', _276 => _276.status])) {
|
|
12970
|
+
metadata["claude_agent_sdk.status"] = response.status;
|
|
12971
|
+
}
|
|
12972
|
+
if (_optionalChain([response, 'optionalAccess', _277 => _277.totalDurationMs])) {
|
|
12973
|
+
metadata["claude_agent_sdk.duration_ms"] = response.totalDurationMs;
|
|
12974
|
+
}
|
|
12975
|
+
if (_optionalChain([response, 'optionalAccess', _278 => _278.totalToolUseCount]) !== void 0) {
|
|
12976
|
+
metadata["claude_agent_sdk.tool_use_count"] = response.totalToolUseCount;
|
|
12977
|
+
}
|
|
12978
|
+
subAgentSpan.log({
|
|
12979
|
+
output: _optionalChain([response, 'optionalAccess', _279 => _279.content]),
|
|
12980
|
+
metadata
|
|
12981
|
+
});
|
|
12982
|
+
} finally {
|
|
12983
|
+
subAgentSpan.end();
|
|
12984
|
+
endedSubAgentSpans.add(toolUseID);
|
|
12985
|
+
}
|
|
12986
|
+
return {};
|
|
12987
|
+
}
|
|
12960
12988
|
const toolSpan = activeToolSpans.get(toolUseID);
|
|
12961
12989
|
if (!toolSpan) {
|
|
12962
12990
|
return {};
|
|
@@ -12973,6 +13001,16 @@ function createToolTracingHooks(parentSpanExportPromise, activeToolSpans, mcpSer
|
|
|
12973
13001
|
if (input.hook_event_name !== "PostToolUseFailure" || !toolUseID) {
|
|
12974
13002
|
return {};
|
|
12975
13003
|
}
|
|
13004
|
+
const subAgentSpan = subAgentSpans.get(toolUseID);
|
|
13005
|
+
if (subAgentSpan) {
|
|
13006
|
+
try {
|
|
13007
|
+
subAgentSpan.log({ error: input.error });
|
|
13008
|
+
} finally {
|
|
13009
|
+
subAgentSpan.end();
|
|
13010
|
+
endedSubAgentSpans.add(toolUseID);
|
|
13011
|
+
}
|
|
13012
|
+
return {};
|
|
13013
|
+
}
|
|
12976
13014
|
const toolSpan = activeToolSpans.get(toolUseID);
|
|
12977
13015
|
if (!toolSpan) {
|
|
12978
13016
|
return {};
|
|
@@ -12997,12 +13035,14 @@ function createToolTracingHooks(parentSpanExportPromise, activeToolSpans, mcpSer
|
|
|
12997
13035
|
};
|
|
12998
13036
|
return { preToolUse, postToolUse, postToolUseFailure };
|
|
12999
13037
|
}
|
|
13000
|
-
function injectTracingHooks(options,
|
|
13038
|
+
function injectTracingHooks(options, resolveParentSpan, activeToolSpans, subAgentSpans, endedSubAgentSpans) {
|
|
13001
13039
|
const mcpServers = options.mcpServers;
|
|
13002
13040
|
const { preToolUse, postToolUse, postToolUseFailure } = createToolTracingHooks(
|
|
13003
|
-
|
|
13041
|
+
resolveParentSpan,
|
|
13004
13042
|
activeToolSpans,
|
|
13005
|
-
mcpServers
|
|
13043
|
+
mcpServers,
|
|
13044
|
+
subAgentSpans,
|
|
13045
|
+
endedSubAgentSpans
|
|
13006
13046
|
);
|
|
13007
13047
|
const existingHooks = _nullishCoalesce(options.hooks, () => ( {}));
|
|
13008
13048
|
return {
|
|
@@ -13048,18 +13088,45 @@ function filterSerializableOptions(options) {
|
|
|
13048
13088
|
}
|
|
13049
13089
|
return filtered;
|
|
13050
13090
|
}
|
|
13091
|
+
function isAsyncIterable(value) {
|
|
13092
|
+
return value !== null && value !== void 0 && typeof value[Symbol.asyncIterator] === "function";
|
|
13093
|
+
}
|
|
13051
13094
|
function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
13052
13095
|
const proxy = new Proxy(queryFn, {
|
|
13053
13096
|
apply(target, thisArg, argArray) {
|
|
13054
13097
|
const params = _nullishCoalesce(argArray[0], () => ( {}));
|
|
13055
13098
|
const { prompt, options = {} } = params;
|
|
13099
|
+
const promptIsAsyncIterable = isAsyncIterable(prompt);
|
|
13100
|
+
let capturedPromptMessages;
|
|
13101
|
+
let promptForQuery = prompt;
|
|
13102
|
+
let promptStarted = false;
|
|
13103
|
+
let resolvePromptDone;
|
|
13104
|
+
const promptDone = new Promise((resolve) => {
|
|
13105
|
+
resolvePromptDone = resolve;
|
|
13106
|
+
});
|
|
13107
|
+
if (promptIsAsyncIterable) {
|
|
13108
|
+
capturedPromptMessages = [];
|
|
13109
|
+
const originalPrompt = prompt;
|
|
13110
|
+
const capturingPrompt = (async function* () {
|
|
13111
|
+
promptStarted = true;
|
|
13112
|
+
try {
|
|
13113
|
+
for await (const msg of originalPrompt) {
|
|
13114
|
+
capturedPromptMessages.push(msg);
|
|
13115
|
+
yield msg;
|
|
13116
|
+
}
|
|
13117
|
+
} finally {
|
|
13118
|
+
_optionalChain([resolvePromptDone, 'optionalCall', _280 => _280()]);
|
|
13119
|
+
}
|
|
13120
|
+
})();
|
|
13121
|
+
promptForQuery = capturingPrompt;
|
|
13122
|
+
}
|
|
13056
13123
|
const span = startSpan({
|
|
13057
13124
|
name: "Claude Agent",
|
|
13058
13125
|
spanAttributes: {
|
|
13059
13126
|
type: "task" /* TASK */
|
|
13060
13127
|
},
|
|
13061
13128
|
event: {
|
|
13062
|
-
input: typeof prompt === "string" ? prompt :
|
|
13129
|
+
input: typeof prompt === "string" ? prompt : promptIsAsyncIterable ? void 0 : prompt !== void 0 ? String(prompt) : void 0,
|
|
13063
13130
|
metadata: filterSerializableOptions(options)
|
|
13064
13131
|
}
|
|
13065
13132
|
});
|
|
@@ -13070,19 +13137,28 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
13070
13137
|
let currentMessageStartTime = getCurrentUnixTimestamp();
|
|
13071
13138
|
const currentMessages = [];
|
|
13072
13139
|
const createLLMSpan = async () => {
|
|
13140
|
+
const parentToolUseId = _nullishCoalesce(_optionalChain([currentMessages, 'access', _281 => _281[0], 'optionalAccess', _282 => _282.parent_tool_use_id]), () => ( null));
|
|
13141
|
+
let parentSpanExport;
|
|
13142
|
+
if (parentToolUseId) {
|
|
13143
|
+
const subAgentSpan = subAgentSpans.get(parentToolUseId);
|
|
13144
|
+
parentSpanExport = subAgentSpan ? await subAgentSpan.export() : await span.export();
|
|
13145
|
+
} else {
|
|
13146
|
+
parentSpanExport = await span.export();
|
|
13147
|
+
}
|
|
13073
13148
|
const finalMessageContent = await _createLLMSpanForMessages(
|
|
13074
13149
|
currentMessages,
|
|
13075
13150
|
prompt,
|
|
13076
13151
|
finalResults,
|
|
13077
13152
|
options,
|
|
13078
13153
|
currentMessageStartTime,
|
|
13079
|
-
|
|
13154
|
+
capturedPromptMessages,
|
|
13155
|
+
parentSpanExport
|
|
13080
13156
|
);
|
|
13081
13157
|
if (finalMessageContent) {
|
|
13082
13158
|
finalResults.push(finalMessageContent);
|
|
13083
13159
|
}
|
|
13084
13160
|
const lastMessage = currentMessages[currentMessages.length - 1];
|
|
13085
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
13161
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _283 => _283.message, 'optionalAccess', _284 => _284.usage])) {
|
|
13086
13162
|
const outputTokens = getNumberProperty2(lastMessage.message.usage, "output_tokens") || 0;
|
|
13087
13163
|
accumulatedOutputTokens += outputTokens;
|
|
13088
13164
|
}
|
|
@@ -13090,12 +13166,34 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
13090
13166
|
};
|
|
13091
13167
|
const invocationTarget = thisArg === proxy || thisArg === void 0 ? _nullishCoalesce(defaultThis, () => ( thisArg)) : thisArg;
|
|
13092
13168
|
const activeToolSpans = /* @__PURE__ */ new Map();
|
|
13169
|
+
const subAgentSpans = /* @__PURE__ */ new Map();
|
|
13170
|
+
const endedSubAgentSpans = /* @__PURE__ */ new Set();
|
|
13171
|
+
const toolUseToParent = /* @__PURE__ */ new Map();
|
|
13172
|
+
const pendingSubAgentNames = /* @__PURE__ */ new Map();
|
|
13173
|
+
const resolveParentSpan = async (toolUseID) => {
|
|
13174
|
+
const parentToolUseId = toolUseToParent.get(toolUseID);
|
|
13175
|
+
if (parentToolUseId) {
|
|
13176
|
+
const subAgentSpan = subAgentSpans.get(parentToolUseId);
|
|
13177
|
+
if (subAgentSpan) {
|
|
13178
|
+
return subAgentSpan.export();
|
|
13179
|
+
}
|
|
13180
|
+
}
|
|
13181
|
+
return span.export();
|
|
13182
|
+
};
|
|
13093
13183
|
const optionsWithHooks = injectTracingHooks(
|
|
13094
13184
|
options,
|
|
13095
|
-
|
|
13096
|
-
activeToolSpans
|
|
13185
|
+
resolveParentSpan,
|
|
13186
|
+
activeToolSpans,
|
|
13187
|
+
subAgentSpans,
|
|
13188
|
+
endedSubAgentSpans
|
|
13097
13189
|
);
|
|
13098
|
-
const modifiedArgArray = [
|
|
13190
|
+
const modifiedArgArray = [
|
|
13191
|
+
{
|
|
13192
|
+
...params,
|
|
13193
|
+
...promptForQuery !== void 0 ? { prompt: promptForQuery } : {},
|
|
13194
|
+
options: optionsWithHooks
|
|
13195
|
+
}
|
|
13196
|
+
];
|
|
13099
13197
|
const originalGenerator = withCurrent(
|
|
13100
13198
|
span,
|
|
13101
13199
|
() => Reflect.apply(target, invocationTarget, modifiedArgArray)
|
|
@@ -13104,20 +13202,55 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
13104
13202
|
try {
|
|
13105
13203
|
for await (const message of originalGenerator) {
|
|
13106
13204
|
const currentTime = getCurrentUnixTimestamp();
|
|
13107
|
-
|
|
13205
|
+
if (message.type === "assistant" && Array.isArray(_optionalChain([message, 'access', _285 => _285.message, 'optionalAccess', _286 => _286.content]))) {
|
|
13206
|
+
const parentToolUseId = _nullishCoalesce(message.parent_tool_use_id, () => ( null));
|
|
13207
|
+
for (const block of message.message.content) {
|
|
13208
|
+
if (block.type === "tool_use" && block.id) {
|
|
13209
|
+
toolUseToParent.set(block.id, parentToolUseId);
|
|
13210
|
+
if (block.name === "Task" && _optionalChain([block, 'access', _287 => _287.input, 'optionalAccess', _288 => _288.subagent_type])) {
|
|
13211
|
+
pendingSubAgentNames.set(
|
|
13212
|
+
block.id,
|
|
13213
|
+
block.input.subagent_type
|
|
13214
|
+
);
|
|
13215
|
+
}
|
|
13216
|
+
}
|
|
13217
|
+
}
|
|
13218
|
+
}
|
|
13219
|
+
if ("parent_tool_use_id" in message) {
|
|
13220
|
+
const parentToolUseId = message.parent_tool_use_id;
|
|
13221
|
+
if (parentToolUseId && !subAgentSpans.has(parentToolUseId)) {
|
|
13222
|
+
const agentName = pendingSubAgentNames.get(parentToolUseId);
|
|
13223
|
+
const spanName = agentName ? `Agent: ${agentName}` : "Agent: sub-agent";
|
|
13224
|
+
const parentExport = await span.export();
|
|
13225
|
+
const subAgentSpan = startSpan({
|
|
13226
|
+
name: spanName,
|
|
13227
|
+
spanAttributes: { type: "task" /* TASK */ },
|
|
13228
|
+
event: {
|
|
13229
|
+
metadata: {
|
|
13230
|
+
...agentName && {
|
|
13231
|
+
"claude_agent_sdk.agent_type": agentName
|
|
13232
|
+
}
|
|
13233
|
+
}
|
|
13234
|
+
},
|
|
13235
|
+
parent: parentExport
|
|
13236
|
+
});
|
|
13237
|
+
subAgentSpans.set(parentToolUseId, subAgentSpan);
|
|
13238
|
+
}
|
|
13239
|
+
}
|
|
13240
|
+
const messageId = _optionalChain([message, 'access', _289 => _289.message, 'optionalAccess', _290 => _290.id]);
|
|
13108
13241
|
if (messageId && messageId !== currentMessageId) {
|
|
13109
13242
|
await createLLMSpan();
|
|
13110
13243
|
currentMessageId = messageId;
|
|
13111
13244
|
currentMessageStartTime = currentTime;
|
|
13112
13245
|
}
|
|
13113
|
-
if (message.type === "assistant" && _optionalChain([message, 'access',
|
|
13246
|
+
if (message.type === "assistant" && _optionalChain([message, 'access', _291 => _291.message, 'optionalAccess', _292 => _292.usage])) {
|
|
13114
13247
|
currentMessages.push(message);
|
|
13115
13248
|
}
|
|
13116
13249
|
if (message.type === "result" && message.usage) {
|
|
13117
13250
|
finalUsageMetrics = _extractUsageFromMessage(message);
|
|
13118
13251
|
if (currentMessages.length > 0 && finalUsageMetrics.completion_tokens !== void 0) {
|
|
13119
13252
|
const lastMessage = currentMessages[currentMessages.length - 1];
|
|
13120
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
13253
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _293 => _293.message, 'optionalAccess', _294 => _294.usage])) {
|
|
13121
13254
|
const adjustedTokens = finalUsageMetrics.completion_tokens - accumulatedOutputTokens;
|
|
13122
13255
|
if (adjustedTokens >= 0) {
|
|
13123
13256
|
lastMessage.message.usage.output_tokens = adjustedTokens;
|
|
@@ -13149,6 +13282,22 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
13149
13282
|
});
|
|
13150
13283
|
throw error;
|
|
13151
13284
|
} finally {
|
|
13285
|
+
for (const [id, subSpan] of subAgentSpans) {
|
|
13286
|
+
if (!endedSubAgentSpans.has(id)) {
|
|
13287
|
+
subSpan.end();
|
|
13288
|
+
}
|
|
13289
|
+
}
|
|
13290
|
+
subAgentSpans.clear();
|
|
13291
|
+
if (capturedPromptMessages) {
|
|
13292
|
+
if (promptStarted) {
|
|
13293
|
+
await promptDone;
|
|
13294
|
+
}
|
|
13295
|
+
if (capturedPromptMessages.length > 0) {
|
|
13296
|
+
span.log({
|
|
13297
|
+
input: _formatCapturedMessages(capturedPromptMessages)
|
|
13298
|
+
});
|
|
13299
|
+
}
|
|
13300
|
+
}
|
|
13152
13301
|
span.end();
|
|
13153
13302
|
}
|
|
13154
13303
|
})();
|
|
@@ -13176,19 +13325,30 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
13176
13325
|
});
|
|
13177
13326
|
return proxy;
|
|
13178
13327
|
}
|
|
13179
|
-
function _buildLLMInput(prompt, conversationHistory) {
|
|
13180
|
-
const
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13328
|
+
function _buildLLMInput(prompt, conversationHistory, capturedPromptMessages) {
|
|
13329
|
+
const promptMessages = [];
|
|
13330
|
+
if (typeof prompt === "string") {
|
|
13331
|
+
promptMessages.push({ content: prompt, role: "user" });
|
|
13332
|
+
} else if (capturedPromptMessages && capturedPromptMessages.length > 0) {
|
|
13333
|
+
for (const msg of capturedPromptMessages) {
|
|
13334
|
+
const role = _optionalChain([msg, 'access', _295 => _295.message, 'optionalAccess', _296 => _296.role]);
|
|
13335
|
+
const content = _optionalChain([msg, 'access', _297 => _297.message, 'optionalAccess', _298 => _298.content]);
|
|
13336
|
+
if (role && content !== void 0) {
|
|
13337
|
+
promptMessages.push({ content, role });
|
|
13338
|
+
}
|
|
13339
|
+
}
|
|
13340
|
+
}
|
|
13341
|
+
const inputParts = [...promptMessages, ...conversationHistory];
|
|
13185
13342
|
return inputParts.length > 0 ? inputParts : void 0;
|
|
13186
13343
|
}
|
|
13344
|
+
function _formatCapturedMessages(messages) {
|
|
13345
|
+
return messages.length > 0 ? messages : [];
|
|
13346
|
+
}
|
|
13187
13347
|
function _extractUsageFromMessage(message) {
|
|
13188
13348
|
const metrics = {};
|
|
13189
13349
|
let usage;
|
|
13190
13350
|
if (message.type === "assistant") {
|
|
13191
|
-
usage = _optionalChain([message, 'access',
|
|
13351
|
+
usage = _optionalChain([message, 'access', _299 => _299.message, 'optionalAccess', _300 => _300.usage]);
|
|
13192
13352
|
} else if (message.type === "result") {
|
|
13193
13353
|
usage = message.usage;
|
|
13194
13354
|
}
|
|
@@ -13217,17 +13377,21 @@ function _extractUsageFromMessage(message) {
|
|
|
13217
13377
|
}
|
|
13218
13378
|
return metrics;
|
|
13219
13379
|
}
|
|
13220
|
-
async function _createLLMSpanForMessages(messages, prompt, conversationHistory, options, startTime, parentSpan) {
|
|
13380
|
+
async function _createLLMSpanForMessages(messages, prompt, conversationHistory, options, startTime, capturedPromptMessages, parentSpan) {
|
|
13221
13381
|
if (messages.length === 0) return void 0;
|
|
13222
13382
|
const lastMessage = messages[messages.length - 1];
|
|
13223
|
-
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access',
|
|
13383
|
+
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access', _301 => _301.message, 'optionalAccess', _302 => _302.usage])) {
|
|
13224
13384
|
return void 0;
|
|
13225
13385
|
}
|
|
13226
13386
|
const model = lastMessage.message.model || options.model;
|
|
13227
13387
|
const usage = _extractUsageFromMessage(lastMessage);
|
|
13228
|
-
const input = _buildLLMInput(
|
|
13388
|
+
const input = _buildLLMInput(
|
|
13389
|
+
prompt,
|
|
13390
|
+
conversationHistory,
|
|
13391
|
+
capturedPromptMessages
|
|
13392
|
+
);
|
|
13229
13393
|
const outputs = messages.map(
|
|
13230
|
-
(m) => _optionalChain([m, 'access',
|
|
13394
|
+
(m) => _optionalChain([m, 'access', _303 => _303.message, 'optionalAccess', _304 => _304.content]) && _optionalChain([m, 'access', _305 => _305.message, 'optionalAccess', _306 => _306.role]) ? { content: m.message.content, role: m.message.role } : void 0
|
|
13231
13395
|
).filter((c) => c !== void 0);
|
|
13232
13396
|
await traced(
|
|
13233
13397
|
(llmSpan) => {
|
|
@@ -13247,7 +13411,7 @@ async function _createLLMSpanForMessages(messages, prompt, conversationHistory,
|
|
|
13247
13411
|
parent: parentSpan
|
|
13248
13412
|
}
|
|
13249
13413
|
);
|
|
13250
|
-
return _optionalChain([lastMessage, 'access',
|
|
13414
|
+
return _optionalChain([lastMessage, 'access', _307 => _307.message, 'optionalAccess', _308 => _308.content]) && _optionalChain([lastMessage, 'access', _309 => _309.message, 'optionalAccess', _310 => _310.role]) ? { content: lastMessage.message.content, role: lastMessage.message.role } : void 0;
|
|
13251
13415
|
}
|
|
13252
13416
|
function wrapClaudeAgentSDK(sdk) {
|
|
13253
13417
|
const cache = /* @__PURE__ */ new Map();
|
|
@@ -13521,7 +13685,7 @@ function serializePart(part) {
|
|
|
13521
13685
|
return part;
|
|
13522
13686
|
}
|
|
13523
13687
|
function serializeTools(params) {
|
|
13524
|
-
if (!_optionalChain([params, 'access',
|
|
13688
|
+
if (!_optionalChain([params, 'access', _311 => _311.config, 'optionalAccess', _312 => _312.tools])) {
|
|
13525
13689
|
return null;
|
|
13526
13690
|
}
|
|
13527
13691
|
try {
|
|
@@ -13604,7 +13768,7 @@ function aggregateGenerateContentChunks(chunks, start, firstTokenTime) {
|
|
|
13604
13768
|
}
|
|
13605
13769
|
if (chunk.candidates && Array.isArray(chunk.candidates)) {
|
|
13606
13770
|
for (const candidate of chunk.candidates) {
|
|
13607
|
-
if (_optionalChain([candidate, 'access',
|
|
13771
|
+
if (_optionalChain([candidate, 'access', _313 => _313.content, 'optionalAccess', _314 => _314.parts])) {
|
|
13608
13772
|
for (const part of candidate.content.parts) {
|
|
13609
13773
|
if (part.text !== void 0) {
|
|
13610
13774
|
if (part.thought) {
|
|
@@ -13635,7 +13799,7 @@ function aggregateGenerateContentChunks(chunks, start, firstTokenTime) {
|
|
|
13635
13799
|
parts.push({ text });
|
|
13636
13800
|
}
|
|
13637
13801
|
parts.push(...otherParts);
|
|
13638
|
-
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess',
|
|
13802
|
+
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess', _315 => _315.candidates])) {
|
|
13639
13803
|
const candidates = [];
|
|
13640
13804
|
for (const candidate of lastResponse.candidates) {
|
|
13641
13805
|
const candidateDict = {
|
|
@@ -13982,7 +14146,7 @@ function unescapePath(path2) {
|
|
|
13982
14146
|
}
|
|
13983
14147
|
var graph_framework_default = { createGraph };
|
|
13984
14148
|
|
|
13985
|
-
// ../node_modules
|
|
14149
|
+
// ../node_modules/async/dist/async.mjs
|
|
13986
14150
|
function initialParams(fn) {
|
|
13987
14151
|
return function(...args) {
|
|
13988
14152
|
var callback = args.pop();
|
|
@@ -14053,7 +14217,7 @@ function isAsync(fn) {
|
|
|
14053
14217
|
function isAsyncGenerator2(fn) {
|
|
14054
14218
|
return fn[Symbol.toStringTag] === "AsyncGenerator";
|
|
14055
14219
|
}
|
|
14056
|
-
function
|
|
14220
|
+
function isAsyncIterable2(obj) {
|
|
14057
14221
|
return typeof obj[Symbol.asyncIterator] === "function";
|
|
14058
14222
|
}
|
|
14059
14223
|
function wrapAsync(asyncFn) {
|
|
@@ -14107,7 +14271,6 @@ function isArrayLike(value) {
|
|
|
14107
14271
|
return value && typeof value.length === "number" && value.length >= 0 && value.length % 1 === 0;
|
|
14108
14272
|
}
|
|
14109
14273
|
var breakLoop = {};
|
|
14110
|
-
var breakLoop$1 = breakLoop;
|
|
14111
14274
|
function once(fn) {
|
|
14112
14275
|
function wrapper(...args) {
|
|
14113
14276
|
if (fn === null) return;
|
|
@@ -14199,7 +14362,7 @@ function asyncEachOfLimit(generator, limit, iteratee, callback) {
|
|
|
14199
14362
|
canceled = true;
|
|
14200
14363
|
return;
|
|
14201
14364
|
}
|
|
14202
|
-
if (result === breakLoop
|
|
14365
|
+
if (result === breakLoop || done && running <= 0) {
|
|
14203
14366
|
done = true;
|
|
14204
14367
|
return callback(null);
|
|
14205
14368
|
}
|
|
@@ -14225,7 +14388,7 @@ var eachOfLimit$2 = (limit) => {
|
|
|
14225
14388
|
if (isAsyncGenerator2(obj)) {
|
|
14226
14389
|
return asyncEachOfLimit(obj, limit, iteratee, callback);
|
|
14227
14390
|
}
|
|
14228
|
-
if (
|
|
14391
|
+
if (isAsyncIterable2(obj)) {
|
|
14229
14392
|
return asyncEachOfLimit(obj[Symbol.asyncIterator](), limit, iteratee, callback);
|
|
14230
14393
|
}
|
|
14231
14394
|
var nextElem = createIterator(obj);
|
|
@@ -14242,7 +14405,7 @@ var eachOfLimit$2 = (limit) => {
|
|
|
14242
14405
|
} else if (err === false) {
|
|
14243
14406
|
done = true;
|
|
14244
14407
|
canceled = true;
|
|
14245
|
-
} else if (value === breakLoop
|
|
14408
|
+
} else if (value === breakLoop || done && running <= 0) {
|
|
14246
14409
|
done = true;
|
|
14247
14410
|
return callback(null);
|
|
14248
14411
|
} else if (!looping) {
|
|
@@ -14285,7 +14448,7 @@ function eachOfArrayLike(coll, iteratee, callback) {
|
|
|
14285
14448
|
if (canceled === true) return;
|
|
14286
14449
|
if (err) {
|
|
14287
14450
|
callback(err);
|
|
14288
|
-
} else if (++completed === length || value === breakLoop
|
|
14451
|
+
} else if (++completed === length || value === breakLoop) {
|
|
14289
14452
|
callback(null);
|
|
14290
14453
|
}
|
|
14291
14454
|
}
|
|
@@ -14681,7 +14844,7 @@ function _createTester(check, getResult) {
|
|
|
14681
14844
|
if (check(result) && !testResult) {
|
|
14682
14845
|
testPassed = true;
|
|
14683
14846
|
testResult = getResult(true, value);
|
|
14684
|
-
return callback(null, breakLoop
|
|
14847
|
+
return callback(null, breakLoop);
|
|
14685
14848
|
}
|
|
14686
14849
|
callback();
|
|
14687
14850
|
});
|
|
@@ -15093,7 +15256,7 @@ var CachedSpanFetcher = (_class18 = class {
|
|
|
15093
15256
|
spanType
|
|
15094
15257
|
);
|
|
15095
15258
|
const rows = await fetcher.fetchedData();
|
|
15096
|
-
return rows.filter((row) => _optionalChain([row, 'access',
|
|
15259
|
+
return rows.filter((row) => _optionalChain([row, 'access', _316 => _316.span_attributes, 'optionalAccess', _317 => _317.purpose]) !== "scorer").map((row) => ({
|
|
15097
15260
|
input: row.input,
|
|
15098
15261
|
output: row.output,
|
|
15099
15262
|
metadata: row.metadata,
|
|
@@ -15127,7 +15290,7 @@ var CachedSpanFetcher = (_class18 = class {
|
|
|
15127
15290
|
async fetchSpans(spanType) {
|
|
15128
15291
|
const spans = await this.fetchFn(spanType);
|
|
15129
15292
|
for (const span of spans) {
|
|
15130
|
-
const type = _nullishCoalesce(_optionalChain([span, 'access',
|
|
15293
|
+
const type = _nullishCoalesce(_optionalChain([span, 'access', _318 => _318.span_attributes, 'optionalAccess', _319 => _319.type]), () => ( ""));
|
|
15131
15294
|
const existing = _nullishCoalesce(this.spanCache.get(type), () => ( []));
|
|
15132
15295
|
existing.push(span);
|
|
15133
15296
|
this.spanCache.set(type, existing);
|
|
@@ -15207,11 +15370,11 @@ var LocalTrace = (_class19 = class {
|
|
|
15207
15370
|
const cachedSpans = this.state.spanCache.getByRootSpanId(this.rootSpanId);
|
|
15208
15371
|
if (cachedSpans && cachedSpans.length > 0) {
|
|
15209
15372
|
let spans = cachedSpans.filter(
|
|
15210
|
-
(span) => _optionalChain([span, 'access',
|
|
15373
|
+
(span) => _optionalChain([span, 'access', _320 => _320.span_attributes, 'optionalAccess', _321 => _321.purpose]) !== "scorer"
|
|
15211
15374
|
);
|
|
15212
15375
|
if (spanType && spanType.length > 0) {
|
|
15213
15376
|
spans = spans.filter(
|
|
15214
|
-
(span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access',
|
|
15377
|
+
(span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access', _322 => _322.span_attributes, 'optionalAccess', _323 => _323.type]), () => ( "")))
|
|
15215
15378
|
);
|
|
15216
15379
|
}
|
|
15217
15380
|
return spans.map((span) => ({
|
|
@@ -15230,7 +15393,7 @@ var LocalTrace = (_class19 = class {
|
|
|
15230
15393
|
* Calls the API with the project_default preprocessor (which falls back to "thread").
|
|
15231
15394
|
*/
|
|
15232
15395
|
async getThread(options) {
|
|
15233
|
-
const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
15396
|
+
const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _324 => _324.preprocessor]), () => ( "project_default"));
|
|
15234
15397
|
if (!this.threadCache.has(cacheKey)) {
|
|
15235
15398
|
const promise = this.fetchThread(options);
|
|
15236
15399
|
this.threadCache.set(cacheKey, promise);
|
|
@@ -15241,7 +15404,7 @@ var LocalTrace = (_class19 = class {
|
|
|
15241
15404
|
await this.ensureSpansReady();
|
|
15242
15405
|
await this.state.login({});
|
|
15243
15406
|
const result = await invoke({
|
|
15244
|
-
globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
15407
|
+
globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _325 => _325.preprocessor]), () => ( "project_default")),
|
|
15245
15408
|
functionType: "preprocessor",
|
|
15246
15409
|
input: {
|
|
15247
15410
|
trace_ref: {
|
|
@@ -15400,10 +15563,10 @@ function validateParametersWithJsonSchema(parameters, schema) {
|
|
|
15400
15563
|
const ajv = new (0, _ajv2.default)({ coerceTypes: true, useDefaults: true, strict: false });
|
|
15401
15564
|
const validate = ajv.compile(schema);
|
|
15402
15565
|
if (!validate(parameters)) {
|
|
15403
|
-
const errorMessages = _optionalChain([validate, 'access',
|
|
15566
|
+
const errorMessages = _optionalChain([validate, 'access', _326 => _326.errors, 'optionalAccess', _327 => _327.map, 'call', _328 => _328((err) => {
|
|
15404
15567
|
const path2 = err.instancePath || "root";
|
|
15405
15568
|
return `${path2}: ${err.message}`;
|
|
15406
|
-
}), 'access',
|
|
15569
|
+
}), 'access', _329 => _329.join, 'call', _330 => _330(", ")]);
|
|
15407
15570
|
throw Error(`Invalid parameters: ${errorMessages}`);
|
|
15408
15571
|
}
|
|
15409
15572
|
return parameters;
|
|
@@ -15459,7 +15622,7 @@ function callEvaluatorData(data) {
|
|
|
15459
15622
|
baseExperiment
|
|
15460
15623
|
};
|
|
15461
15624
|
}
|
|
15462
|
-
function
|
|
15625
|
+
function isAsyncIterable3(value) {
|
|
15463
15626
|
return typeof value === "object" && value !== null && typeof value[Symbol.asyncIterator] === "function";
|
|
15464
15627
|
}
|
|
15465
15628
|
function isIterable(value) {
|
|
@@ -15644,7 +15807,7 @@ var defaultErrorScoreHandler = ({
|
|
|
15644
15807
|
};
|
|
15645
15808
|
async function runEvaluatorInternal(experiment, evaluator, progressReporter, filters, stream, parameters, collectResults, enableCache) {
|
|
15646
15809
|
if (enableCache) {
|
|
15647
|
-
_optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess',
|
|
15810
|
+
_optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _331 => _331.spanCache, 'optionalAccess', _332 => _332.start, 'call', _333 => _333()]);
|
|
15648
15811
|
}
|
|
15649
15812
|
try {
|
|
15650
15813
|
if (typeof evaluator.data === "string") {
|
|
@@ -15680,7 +15843,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15680
15843
|
}
|
|
15681
15844
|
const resolvedDataResult = dataResult instanceof Promise ? await dataResult : dataResult;
|
|
15682
15845
|
const dataIterable = (() => {
|
|
15683
|
-
if (
|
|
15846
|
+
if (isAsyncIterable3(resolvedDataResult)) {
|
|
15684
15847
|
return resolvedDataResult;
|
|
15685
15848
|
}
|
|
15686
15849
|
if (Array.isArray(resolvedDataResult) || isIterable(resolvedDataResult)) {
|
|
@@ -15755,7 +15918,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15755
15918
|
objectType: parentComponents ? spanObjectTypeV3ToTypedString(
|
|
15756
15919
|
parentComponents.data.object_type
|
|
15757
15920
|
) : "experiment",
|
|
15758
|
-
objectId: await _asyncNullishCoalesce(await _asyncOptionalChain([parentComponents, 'optionalAccess', async
|
|
15921
|
+
objectId: await _asyncNullishCoalesce(await _asyncOptionalChain([parentComponents, 'optionalAccess', async _334 => _334.data, 'access', async _335 => _335.object_id]), async () => ( (experimentIdPromise ? await _asyncNullishCoalesce(await experimentIdPromise, async () => ( "")) : ""))),
|
|
15759
15922
|
rootSpanId: rootSpan.rootSpanId,
|
|
15760
15923
|
ensureSpansFlushed,
|
|
15761
15924
|
state
|
|
@@ -15781,10 +15944,10 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15781
15944
|
span,
|
|
15782
15945
|
parameters: _nullishCoalesce(parameters, () => ( {})),
|
|
15783
15946
|
reportProgress: (event) => {
|
|
15784
|
-
_optionalChain([stream, 'optionalCall',
|
|
15947
|
+
_optionalChain([stream, 'optionalCall', _336 => _336({
|
|
15785
15948
|
...event,
|
|
15786
15949
|
id: rootSpan.id,
|
|
15787
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
15950
|
+
origin: _optionalChain([baseEvent, 'access', _337 => _337.event, 'optionalAccess', _338 => _338.origin]),
|
|
15788
15951
|
name: evaluator.evalName,
|
|
15789
15952
|
object_type: "task"
|
|
15790
15953
|
})]);
|
|
@@ -15948,7 +16111,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15948
16111
|
metadata,
|
|
15949
16112
|
scores: mergedScores,
|
|
15950
16113
|
error,
|
|
15951
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
16114
|
+
origin: _optionalChain([baseEvent, 'access', _339 => _339.event, 'optionalAccess', _340 => _340.origin])
|
|
15952
16115
|
});
|
|
15953
16116
|
}
|
|
15954
16117
|
};
|
|
@@ -15981,7 +16144,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15981
16144
|
break;
|
|
15982
16145
|
}
|
|
15983
16146
|
scheduledTrials++;
|
|
15984
|
-
_optionalChain([progressReporter, 'access',
|
|
16147
|
+
_optionalChain([progressReporter, 'access', _341 => _341.setTotal, 'optionalCall', _342 => _342(evaluator.evalName, scheduledTrials)]);
|
|
15985
16148
|
q.push({ datum, trialIndex });
|
|
15986
16149
|
}
|
|
15987
16150
|
}
|
|
@@ -16056,9 +16219,9 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
16056
16219
|
);
|
|
16057
16220
|
} finally {
|
|
16058
16221
|
if (enableCache) {
|
|
16059
|
-
const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess',
|
|
16060
|
-
_optionalChain([spanCache, 'optionalAccess',
|
|
16061
|
-
_optionalChain([spanCache, 'optionalAccess',
|
|
16222
|
+
const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _343 => _343.spanCache]);
|
|
16223
|
+
_optionalChain([spanCache, 'optionalAccess', _344 => _344.dispose, 'call', _345 => _345()]);
|
|
16224
|
+
_optionalChain([spanCache, 'optionalAccess', _346 => _346.stop, 'call', _347 => _347()]);
|
|
16062
16225
|
}
|
|
16063
16226
|
}
|
|
16064
16227
|
}
|