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/browser.js
CHANGED
|
@@ -1928,7 +1928,8 @@ var SpanType = _v3.z.union([
|
|
|
1928
1928
|
"automation",
|
|
1929
1929
|
"facet",
|
|
1930
1930
|
"preprocessor",
|
|
1931
|
-
"classifier"
|
|
1931
|
+
"classifier",
|
|
1932
|
+
"review"
|
|
1932
1933
|
]),
|
|
1933
1934
|
_v3.z.null()
|
|
1934
1935
|
]);
|
|
@@ -12695,14 +12696,17 @@ function parseToolName(rawToolName) {
|
|
|
12695
12696
|
rawToolName
|
|
12696
12697
|
};
|
|
12697
12698
|
}
|
|
12698
|
-
function createToolTracingHooks(
|
|
12699
|
+
function createToolTracingHooks(resolveParentSpan, activeToolSpans, mcpServers, subAgentSpans, endedSubAgentSpans) {
|
|
12699
12700
|
const preToolUse = async (input, toolUseID) => {
|
|
12700
12701
|
if (input.hook_event_name !== "PreToolUse" || !toolUseID) {
|
|
12701
12702
|
return {};
|
|
12702
12703
|
}
|
|
12704
|
+
if (input.tool_name === "Task") {
|
|
12705
|
+
return {};
|
|
12706
|
+
}
|
|
12703
12707
|
const parsed = parseToolName(input.tool_name);
|
|
12704
12708
|
const mcpMetadata = getMcpServerMetadata(parsed.mcpServer, mcpServers);
|
|
12705
|
-
const parentExport = await
|
|
12709
|
+
const parentExport = await resolveParentSpan(toolUseID);
|
|
12706
12710
|
const toolSpan = startSpan({
|
|
12707
12711
|
name: parsed.displayName,
|
|
12708
12712
|
spanAttributes: { type: "tool" /* TOOL */ },
|
|
@@ -12730,6 +12734,30 @@ function createToolTracingHooks(parentSpanExportPromise, activeToolSpans, mcpSer
|
|
|
12730
12734
|
if (input.hook_event_name !== "PostToolUse" || !toolUseID) {
|
|
12731
12735
|
return {};
|
|
12732
12736
|
}
|
|
12737
|
+
const subAgentSpan = subAgentSpans.get(toolUseID);
|
|
12738
|
+
if (subAgentSpan) {
|
|
12739
|
+
try {
|
|
12740
|
+
const response = input.tool_response;
|
|
12741
|
+
const metadata = {};
|
|
12742
|
+
if (_optionalChain([response, 'optionalAccess', _267 => _267.status])) {
|
|
12743
|
+
metadata["claude_agent_sdk.status"] = response.status;
|
|
12744
|
+
}
|
|
12745
|
+
if (_optionalChain([response, 'optionalAccess', _268 => _268.totalDurationMs])) {
|
|
12746
|
+
metadata["claude_agent_sdk.duration_ms"] = response.totalDurationMs;
|
|
12747
|
+
}
|
|
12748
|
+
if (_optionalChain([response, 'optionalAccess', _269 => _269.totalToolUseCount]) !== void 0) {
|
|
12749
|
+
metadata["claude_agent_sdk.tool_use_count"] = response.totalToolUseCount;
|
|
12750
|
+
}
|
|
12751
|
+
subAgentSpan.log({
|
|
12752
|
+
output: _optionalChain([response, 'optionalAccess', _270 => _270.content]),
|
|
12753
|
+
metadata
|
|
12754
|
+
});
|
|
12755
|
+
} finally {
|
|
12756
|
+
subAgentSpan.end();
|
|
12757
|
+
endedSubAgentSpans.add(toolUseID);
|
|
12758
|
+
}
|
|
12759
|
+
return {};
|
|
12760
|
+
}
|
|
12733
12761
|
const toolSpan = activeToolSpans.get(toolUseID);
|
|
12734
12762
|
if (!toolSpan) {
|
|
12735
12763
|
return {};
|
|
@@ -12746,6 +12774,16 @@ function createToolTracingHooks(parentSpanExportPromise, activeToolSpans, mcpSer
|
|
|
12746
12774
|
if (input.hook_event_name !== "PostToolUseFailure" || !toolUseID) {
|
|
12747
12775
|
return {};
|
|
12748
12776
|
}
|
|
12777
|
+
const subAgentSpan = subAgentSpans.get(toolUseID);
|
|
12778
|
+
if (subAgentSpan) {
|
|
12779
|
+
try {
|
|
12780
|
+
subAgentSpan.log({ error: input.error });
|
|
12781
|
+
} finally {
|
|
12782
|
+
subAgentSpan.end();
|
|
12783
|
+
endedSubAgentSpans.add(toolUseID);
|
|
12784
|
+
}
|
|
12785
|
+
return {};
|
|
12786
|
+
}
|
|
12749
12787
|
const toolSpan = activeToolSpans.get(toolUseID);
|
|
12750
12788
|
if (!toolSpan) {
|
|
12751
12789
|
return {};
|
|
@@ -12770,12 +12808,14 @@ function createToolTracingHooks(parentSpanExportPromise, activeToolSpans, mcpSer
|
|
|
12770
12808
|
};
|
|
12771
12809
|
return { preToolUse, postToolUse, postToolUseFailure };
|
|
12772
12810
|
}
|
|
12773
|
-
function injectTracingHooks(options,
|
|
12811
|
+
function injectTracingHooks(options, resolveParentSpan, activeToolSpans, subAgentSpans, endedSubAgentSpans) {
|
|
12774
12812
|
const mcpServers = options.mcpServers;
|
|
12775
12813
|
const { preToolUse, postToolUse, postToolUseFailure } = createToolTracingHooks(
|
|
12776
|
-
|
|
12814
|
+
resolveParentSpan,
|
|
12777
12815
|
activeToolSpans,
|
|
12778
|
-
mcpServers
|
|
12816
|
+
mcpServers,
|
|
12817
|
+
subAgentSpans,
|
|
12818
|
+
endedSubAgentSpans
|
|
12779
12819
|
);
|
|
12780
12820
|
const existingHooks = _nullishCoalesce(options.hooks, () => ( {}));
|
|
12781
12821
|
return {
|
|
@@ -12821,18 +12861,45 @@ function filterSerializableOptions(options) {
|
|
|
12821
12861
|
}
|
|
12822
12862
|
return filtered;
|
|
12823
12863
|
}
|
|
12864
|
+
function isAsyncIterable(value) {
|
|
12865
|
+
return value !== null && value !== void 0 && typeof value[Symbol.asyncIterator] === "function";
|
|
12866
|
+
}
|
|
12824
12867
|
function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
12825
12868
|
const proxy = new Proxy(queryFn, {
|
|
12826
12869
|
apply(target, thisArg, argArray) {
|
|
12827
12870
|
const params = _nullishCoalesce(argArray[0], () => ( {}));
|
|
12828
12871
|
const { prompt, options = {} } = params;
|
|
12872
|
+
const promptIsAsyncIterable = isAsyncIterable(prompt);
|
|
12873
|
+
let capturedPromptMessages;
|
|
12874
|
+
let promptForQuery = prompt;
|
|
12875
|
+
let promptStarted = false;
|
|
12876
|
+
let resolvePromptDone;
|
|
12877
|
+
const promptDone = new Promise((resolve) => {
|
|
12878
|
+
resolvePromptDone = resolve;
|
|
12879
|
+
});
|
|
12880
|
+
if (promptIsAsyncIterable) {
|
|
12881
|
+
capturedPromptMessages = [];
|
|
12882
|
+
const originalPrompt = prompt;
|
|
12883
|
+
const capturingPrompt = (async function* () {
|
|
12884
|
+
promptStarted = true;
|
|
12885
|
+
try {
|
|
12886
|
+
for await (const msg of originalPrompt) {
|
|
12887
|
+
capturedPromptMessages.push(msg);
|
|
12888
|
+
yield msg;
|
|
12889
|
+
}
|
|
12890
|
+
} finally {
|
|
12891
|
+
_optionalChain([resolvePromptDone, 'optionalCall', _271 => _271()]);
|
|
12892
|
+
}
|
|
12893
|
+
})();
|
|
12894
|
+
promptForQuery = capturingPrompt;
|
|
12895
|
+
}
|
|
12829
12896
|
const span = startSpan({
|
|
12830
12897
|
name: "Claude Agent",
|
|
12831
12898
|
spanAttributes: {
|
|
12832
12899
|
type: "task" /* TASK */
|
|
12833
12900
|
},
|
|
12834
12901
|
event: {
|
|
12835
|
-
input: typeof prompt === "string" ? prompt :
|
|
12902
|
+
input: typeof prompt === "string" ? prompt : promptIsAsyncIterable ? void 0 : prompt !== void 0 ? String(prompt) : void 0,
|
|
12836
12903
|
metadata: filterSerializableOptions(options)
|
|
12837
12904
|
}
|
|
12838
12905
|
});
|
|
@@ -12843,19 +12910,28 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
12843
12910
|
let currentMessageStartTime = getCurrentUnixTimestamp();
|
|
12844
12911
|
const currentMessages = [];
|
|
12845
12912
|
const createLLMSpan = async () => {
|
|
12913
|
+
const parentToolUseId = _nullishCoalesce(_optionalChain([currentMessages, 'access', _272 => _272[0], 'optionalAccess', _273 => _273.parent_tool_use_id]), () => ( null));
|
|
12914
|
+
let parentSpanExport;
|
|
12915
|
+
if (parentToolUseId) {
|
|
12916
|
+
const subAgentSpan = subAgentSpans.get(parentToolUseId);
|
|
12917
|
+
parentSpanExport = subAgentSpan ? await subAgentSpan.export() : await span.export();
|
|
12918
|
+
} else {
|
|
12919
|
+
parentSpanExport = await span.export();
|
|
12920
|
+
}
|
|
12846
12921
|
const finalMessageContent = await _createLLMSpanForMessages(
|
|
12847
12922
|
currentMessages,
|
|
12848
12923
|
prompt,
|
|
12849
12924
|
finalResults,
|
|
12850
12925
|
options,
|
|
12851
12926
|
currentMessageStartTime,
|
|
12852
|
-
|
|
12927
|
+
capturedPromptMessages,
|
|
12928
|
+
parentSpanExport
|
|
12853
12929
|
);
|
|
12854
12930
|
if (finalMessageContent) {
|
|
12855
12931
|
finalResults.push(finalMessageContent);
|
|
12856
12932
|
}
|
|
12857
12933
|
const lastMessage = currentMessages[currentMessages.length - 1];
|
|
12858
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
12934
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _274 => _274.message, 'optionalAccess', _275 => _275.usage])) {
|
|
12859
12935
|
const outputTokens = getNumberProperty2(lastMessage.message.usage, "output_tokens") || 0;
|
|
12860
12936
|
accumulatedOutputTokens += outputTokens;
|
|
12861
12937
|
}
|
|
@@ -12863,12 +12939,34 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
12863
12939
|
};
|
|
12864
12940
|
const invocationTarget = thisArg === proxy || thisArg === void 0 ? _nullishCoalesce(defaultThis, () => ( thisArg)) : thisArg;
|
|
12865
12941
|
const activeToolSpans = /* @__PURE__ */ new Map();
|
|
12942
|
+
const subAgentSpans = /* @__PURE__ */ new Map();
|
|
12943
|
+
const endedSubAgentSpans = /* @__PURE__ */ new Set();
|
|
12944
|
+
const toolUseToParent = /* @__PURE__ */ new Map();
|
|
12945
|
+
const pendingSubAgentNames = /* @__PURE__ */ new Map();
|
|
12946
|
+
const resolveParentSpan = async (toolUseID) => {
|
|
12947
|
+
const parentToolUseId = toolUseToParent.get(toolUseID);
|
|
12948
|
+
if (parentToolUseId) {
|
|
12949
|
+
const subAgentSpan = subAgentSpans.get(parentToolUseId);
|
|
12950
|
+
if (subAgentSpan) {
|
|
12951
|
+
return subAgentSpan.export();
|
|
12952
|
+
}
|
|
12953
|
+
}
|
|
12954
|
+
return span.export();
|
|
12955
|
+
};
|
|
12866
12956
|
const optionsWithHooks = injectTracingHooks(
|
|
12867
12957
|
options,
|
|
12868
|
-
|
|
12869
|
-
activeToolSpans
|
|
12958
|
+
resolveParentSpan,
|
|
12959
|
+
activeToolSpans,
|
|
12960
|
+
subAgentSpans,
|
|
12961
|
+
endedSubAgentSpans
|
|
12870
12962
|
);
|
|
12871
|
-
const modifiedArgArray = [
|
|
12963
|
+
const modifiedArgArray = [
|
|
12964
|
+
{
|
|
12965
|
+
...params,
|
|
12966
|
+
...promptForQuery !== void 0 ? { prompt: promptForQuery } : {},
|
|
12967
|
+
options: optionsWithHooks
|
|
12968
|
+
}
|
|
12969
|
+
];
|
|
12872
12970
|
const originalGenerator = withCurrent(
|
|
12873
12971
|
span,
|
|
12874
12972
|
() => Reflect.apply(target, invocationTarget, modifiedArgArray)
|
|
@@ -12877,20 +12975,55 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
12877
12975
|
try {
|
|
12878
12976
|
for await (const message of originalGenerator) {
|
|
12879
12977
|
const currentTime = getCurrentUnixTimestamp();
|
|
12880
|
-
|
|
12978
|
+
if (message.type === "assistant" && Array.isArray(_optionalChain([message, 'access', _276 => _276.message, 'optionalAccess', _277 => _277.content]))) {
|
|
12979
|
+
const parentToolUseId = _nullishCoalesce(message.parent_tool_use_id, () => ( null));
|
|
12980
|
+
for (const block of message.message.content) {
|
|
12981
|
+
if (block.type === "tool_use" && block.id) {
|
|
12982
|
+
toolUseToParent.set(block.id, parentToolUseId);
|
|
12983
|
+
if (block.name === "Task" && _optionalChain([block, 'access', _278 => _278.input, 'optionalAccess', _279 => _279.subagent_type])) {
|
|
12984
|
+
pendingSubAgentNames.set(
|
|
12985
|
+
block.id,
|
|
12986
|
+
block.input.subagent_type
|
|
12987
|
+
);
|
|
12988
|
+
}
|
|
12989
|
+
}
|
|
12990
|
+
}
|
|
12991
|
+
}
|
|
12992
|
+
if ("parent_tool_use_id" in message) {
|
|
12993
|
+
const parentToolUseId = message.parent_tool_use_id;
|
|
12994
|
+
if (parentToolUseId && !subAgentSpans.has(parentToolUseId)) {
|
|
12995
|
+
const agentName = pendingSubAgentNames.get(parentToolUseId);
|
|
12996
|
+
const spanName = agentName ? `Agent: ${agentName}` : "Agent: sub-agent";
|
|
12997
|
+
const parentExport = await span.export();
|
|
12998
|
+
const subAgentSpan = startSpan({
|
|
12999
|
+
name: spanName,
|
|
13000
|
+
spanAttributes: { type: "task" /* TASK */ },
|
|
13001
|
+
event: {
|
|
13002
|
+
metadata: {
|
|
13003
|
+
...agentName && {
|
|
13004
|
+
"claude_agent_sdk.agent_type": agentName
|
|
13005
|
+
}
|
|
13006
|
+
}
|
|
13007
|
+
},
|
|
13008
|
+
parent: parentExport
|
|
13009
|
+
});
|
|
13010
|
+
subAgentSpans.set(parentToolUseId, subAgentSpan);
|
|
13011
|
+
}
|
|
13012
|
+
}
|
|
13013
|
+
const messageId = _optionalChain([message, 'access', _280 => _280.message, 'optionalAccess', _281 => _281.id]);
|
|
12881
13014
|
if (messageId && messageId !== currentMessageId) {
|
|
12882
13015
|
await createLLMSpan();
|
|
12883
13016
|
currentMessageId = messageId;
|
|
12884
13017
|
currentMessageStartTime = currentTime;
|
|
12885
13018
|
}
|
|
12886
|
-
if (message.type === "assistant" && _optionalChain([message, 'access',
|
|
13019
|
+
if (message.type === "assistant" && _optionalChain([message, 'access', _282 => _282.message, 'optionalAccess', _283 => _283.usage])) {
|
|
12887
13020
|
currentMessages.push(message);
|
|
12888
13021
|
}
|
|
12889
13022
|
if (message.type === "result" && message.usage) {
|
|
12890
13023
|
finalUsageMetrics = _extractUsageFromMessage(message);
|
|
12891
13024
|
if (currentMessages.length > 0 && finalUsageMetrics.completion_tokens !== void 0) {
|
|
12892
13025
|
const lastMessage = currentMessages[currentMessages.length - 1];
|
|
12893
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
13026
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _284 => _284.message, 'optionalAccess', _285 => _285.usage])) {
|
|
12894
13027
|
const adjustedTokens = finalUsageMetrics.completion_tokens - accumulatedOutputTokens;
|
|
12895
13028
|
if (adjustedTokens >= 0) {
|
|
12896
13029
|
lastMessage.message.usage.output_tokens = adjustedTokens;
|
|
@@ -12922,6 +13055,22 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
12922
13055
|
});
|
|
12923
13056
|
throw error;
|
|
12924
13057
|
} finally {
|
|
13058
|
+
for (const [id, subSpan] of subAgentSpans) {
|
|
13059
|
+
if (!endedSubAgentSpans.has(id)) {
|
|
13060
|
+
subSpan.end();
|
|
13061
|
+
}
|
|
13062
|
+
}
|
|
13063
|
+
subAgentSpans.clear();
|
|
13064
|
+
if (capturedPromptMessages) {
|
|
13065
|
+
if (promptStarted) {
|
|
13066
|
+
await promptDone;
|
|
13067
|
+
}
|
|
13068
|
+
if (capturedPromptMessages.length > 0) {
|
|
13069
|
+
span.log({
|
|
13070
|
+
input: _formatCapturedMessages(capturedPromptMessages)
|
|
13071
|
+
});
|
|
13072
|
+
}
|
|
13073
|
+
}
|
|
12925
13074
|
span.end();
|
|
12926
13075
|
}
|
|
12927
13076
|
})();
|
|
@@ -12949,19 +13098,30 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
12949
13098
|
});
|
|
12950
13099
|
return proxy;
|
|
12951
13100
|
}
|
|
12952
|
-
function _buildLLMInput(prompt, conversationHistory) {
|
|
12953
|
-
const
|
|
12954
|
-
|
|
12955
|
-
|
|
12956
|
-
|
|
12957
|
-
|
|
13101
|
+
function _buildLLMInput(prompt, conversationHistory, capturedPromptMessages) {
|
|
13102
|
+
const promptMessages = [];
|
|
13103
|
+
if (typeof prompt === "string") {
|
|
13104
|
+
promptMessages.push({ content: prompt, role: "user" });
|
|
13105
|
+
} else if (capturedPromptMessages && capturedPromptMessages.length > 0) {
|
|
13106
|
+
for (const msg of capturedPromptMessages) {
|
|
13107
|
+
const role = _optionalChain([msg, 'access', _286 => _286.message, 'optionalAccess', _287 => _287.role]);
|
|
13108
|
+
const content = _optionalChain([msg, 'access', _288 => _288.message, 'optionalAccess', _289 => _289.content]);
|
|
13109
|
+
if (role && content !== void 0) {
|
|
13110
|
+
promptMessages.push({ content, role });
|
|
13111
|
+
}
|
|
13112
|
+
}
|
|
13113
|
+
}
|
|
13114
|
+
const inputParts = [...promptMessages, ...conversationHistory];
|
|
12958
13115
|
return inputParts.length > 0 ? inputParts : void 0;
|
|
12959
13116
|
}
|
|
13117
|
+
function _formatCapturedMessages(messages) {
|
|
13118
|
+
return messages.length > 0 ? messages : [];
|
|
13119
|
+
}
|
|
12960
13120
|
function _extractUsageFromMessage(message) {
|
|
12961
13121
|
const metrics = {};
|
|
12962
13122
|
let usage;
|
|
12963
13123
|
if (message.type === "assistant") {
|
|
12964
|
-
usage = _optionalChain([message, 'access',
|
|
13124
|
+
usage = _optionalChain([message, 'access', _290 => _290.message, 'optionalAccess', _291 => _291.usage]);
|
|
12965
13125
|
} else if (message.type === "result") {
|
|
12966
13126
|
usage = message.usage;
|
|
12967
13127
|
}
|
|
@@ -12990,17 +13150,21 @@ function _extractUsageFromMessage(message) {
|
|
|
12990
13150
|
}
|
|
12991
13151
|
return metrics;
|
|
12992
13152
|
}
|
|
12993
|
-
async function _createLLMSpanForMessages(messages, prompt, conversationHistory, options, startTime, parentSpan) {
|
|
13153
|
+
async function _createLLMSpanForMessages(messages, prompt, conversationHistory, options, startTime, capturedPromptMessages, parentSpan) {
|
|
12994
13154
|
if (messages.length === 0) return void 0;
|
|
12995
13155
|
const lastMessage = messages[messages.length - 1];
|
|
12996
|
-
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access',
|
|
13156
|
+
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access', _292 => _292.message, 'optionalAccess', _293 => _293.usage])) {
|
|
12997
13157
|
return void 0;
|
|
12998
13158
|
}
|
|
12999
13159
|
const model = lastMessage.message.model || options.model;
|
|
13000
13160
|
const usage = _extractUsageFromMessage(lastMessage);
|
|
13001
|
-
const input = _buildLLMInput(
|
|
13161
|
+
const input = _buildLLMInput(
|
|
13162
|
+
prompt,
|
|
13163
|
+
conversationHistory,
|
|
13164
|
+
capturedPromptMessages
|
|
13165
|
+
);
|
|
13002
13166
|
const outputs = messages.map(
|
|
13003
|
-
(m) => _optionalChain([m, 'access',
|
|
13167
|
+
(m) => _optionalChain([m, 'access', _294 => _294.message, 'optionalAccess', _295 => _295.content]) && _optionalChain([m, 'access', _296 => _296.message, 'optionalAccess', _297 => _297.role]) ? { content: m.message.content, role: m.message.role } : void 0
|
|
13004
13168
|
).filter((c) => c !== void 0);
|
|
13005
13169
|
await traced(
|
|
13006
13170
|
(llmSpan) => {
|
|
@@ -13020,7 +13184,7 @@ async function _createLLMSpanForMessages(messages, prompt, conversationHistory,
|
|
|
13020
13184
|
parent: parentSpan
|
|
13021
13185
|
}
|
|
13022
13186
|
);
|
|
13023
|
-
return _optionalChain([lastMessage, 'access',
|
|
13187
|
+
return _optionalChain([lastMessage, 'access', _298 => _298.message, 'optionalAccess', _299 => _299.content]) && _optionalChain([lastMessage, 'access', _300 => _300.message, 'optionalAccess', _301 => _301.role]) ? { content: lastMessage.message.content, role: lastMessage.message.role } : void 0;
|
|
13024
13188
|
}
|
|
13025
13189
|
function wrapClaudeAgentSDK(sdk) {
|
|
13026
13190
|
const cache = /* @__PURE__ */ new Map();
|
|
@@ -13294,7 +13458,7 @@ function serializePart(part) {
|
|
|
13294
13458
|
return part;
|
|
13295
13459
|
}
|
|
13296
13460
|
function serializeTools(params) {
|
|
13297
|
-
if (!_optionalChain([params, 'access',
|
|
13461
|
+
if (!_optionalChain([params, 'access', _302 => _302.config, 'optionalAccess', _303 => _303.tools])) {
|
|
13298
13462
|
return null;
|
|
13299
13463
|
}
|
|
13300
13464
|
try {
|
|
@@ -13377,7 +13541,7 @@ function aggregateGenerateContentChunks(chunks, start, firstTokenTime) {
|
|
|
13377
13541
|
}
|
|
13378
13542
|
if (chunk.candidates && Array.isArray(chunk.candidates)) {
|
|
13379
13543
|
for (const candidate of chunk.candidates) {
|
|
13380
|
-
if (_optionalChain([candidate, 'access',
|
|
13544
|
+
if (_optionalChain([candidate, 'access', _304 => _304.content, 'optionalAccess', _305 => _305.parts])) {
|
|
13381
13545
|
for (const part of candidate.content.parts) {
|
|
13382
13546
|
if (part.text !== void 0) {
|
|
13383
13547
|
if (part.thought) {
|
|
@@ -13408,7 +13572,7 @@ function aggregateGenerateContentChunks(chunks, start, firstTokenTime) {
|
|
|
13408
13572
|
parts.push({ text });
|
|
13409
13573
|
}
|
|
13410
13574
|
parts.push(...otherParts);
|
|
13411
|
-
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess',
|
|
13575
|
+
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess', _306 => _306.candidates])) {
|
|
13412
13576
|
const candidates = [];
|
|
13413
13577
|
for (const candidate of lastResponse.candidates) {
|
|
13414
13578
|
const candidateDict = {
|
|
@@ -13755,7 +13919,7 @@ function unescapePath(path) {
|
|
|
13755
13919
|
}
|
|
13756
13920
|
var graph_framework_default = { createGraph };
|
|
13757
13921
|
|
|
13758
|
-
// ../node_modules
|
|
13922
|
+
// ../node_modules/async/dist/async.mjs
|
|
13759
13923
|
function initialParams(fn) {
|
|
13760
13924
|
return function(...args) {
|
|
13761
13925
|
var callback = args.pop();
|
|
@@ -13826,7 +13990,7 @@ function isAsync(fn) {
|
|
|
13826
13990
|
function isAsyncGenerator2(fn) {
|
|
13827
13991
|
return fn[Symbol.toStringTag] === "AsyncGenerator";
|
|
13828
13992
|
}
|
|
13829
|
-
function
|
|
13993
|
+
function isAsyncIterable2(obj) {
|
|
13830
13994
|
return typeof obj[Symbol.asyncIterator] === "function";
|
|
13831
13995
|
}
|
|
13832
13996
|
function wrapAsync(asyncFn) {
|
|
@@ -13880,7 +14044,6 @@ function isArrayLike(value) {
|
|
|
13880
14044
|
return value && typeof value.length === "number" && value.length >= 0 && value.length % 1 === 0;
|
|
13881
14045
|
}
|
|
13882
14046
|
var breakLoop = {};
|
|
13883
|
-
var breakLoop$1 = breakLoop;
|
|
13884
14047
|
function once(fn) {
|
|
13885
14048
|
function wrapper(...args) {
|
|
13886
14049
|
if (fn === null) return;
|
|
@@ -13972,7 +14135,7 @@ function asyncEachOfLimit(generator, limit, iteratee, callback) {
|
|
|
13972
14135
|
canceled = true;
|
|
13973
14136
|
return;
|
|
13974
14137
|
}
|
|
13975
|
-
if (result === breakLoop
|
|
14138
|
+
if (result === breakLoop || done && running <= 0) {
|
|
13976
14139
|
done = true;
|
|
13977
14140
|
return callback(null);
|
|
13978
14141
|
}
|
|
@@ -13998,7 +14161,7 @@ var eachOfLimit$2 = (limit) => {
|
|
|
13998
14161
|
if (isAsyncGenerator2(obj)) {
|
|
13999
14162
|
return asyncEachOfLimit(obj, limit, iteratee, callback);
|
|
14000
14163
|
}
|
|
14001
|
-
if (
|
|
14164
|
+
if (isAsyncIterable2(obj)) {
|
|
14002
14165
|
return asyncEachOfLimit(obj[Symbol.asyncIterator](), limit, iteratee, callback);
|
|
14003
14166
|
}
|
|
14004
14167
|
var nextElem = createIterator(obj);
|
|
@@ -14015,7 +14178,7 @@ var eachOfLimit$2 = (limit) => {
|
|
|
14015
14178
|
} else if (err === false) {
|
|
14016
14179
|
done = true;
|
|
14017
14180
|
canceled = true;
|
|
14018
|
-
} else if (value === breakLoop
|
|
14181
|
+
} else if (value === breakLoop || done && running <= 0) {
|
|
14019
14182
|
done = true;
|
|
14020
14183
|
return callback(null);
|
|
14021
14184
|
} else if (!looping) {
|
|
@@ -14058,7 +14221,7 @@ function eachOfArrayLike(coll, iteratee, callback) {
|
|
|
14058
14221
|
if (canceled === true) return;
|
|
14059
14222
|
if (err) {
|
|
14060
14223
|
callback(err);
|
|
14061
|
-
} else if (++completed === length || value === breakLoop
|
|
14224
|
+
} else if (++completed === length || value === breakLoop) {
|
|
14062
14225
|
callback(null);
|
|
14063
14226
|
}
|
|
14064
14227
|
}
|
|
@@ -14454,7 +14617,7 @@ function _createTester(check, getResult) {
|
|
|
14454
14617
|
if (check(result) && !testResult) {
|
|
14455
14618
|
testPassed = true;
|
|
14456
14619
|
testResult = getResult(true, value);
|
|
14457
|
-
return callback(null, breakLoop
|
|
14620
|
+
return callback(null, breakLoop);
|
|
14458
14621
|
}
|
|
14459
14622
|
callback();
|
|
14460
14623
|
});
|
|
@@ -14866,7 +15029,7 @@ var CachedSpanFetcher = (_class18 = class {
|
|
|
14866
15029
|
spanType
|
|
14867
15030
|
);
|
|
14868
15031
|
const rows = await fetcher.fetchedData();
|
|
14869
|
-
return rows.filter((row) => _optionalChain([row, 'access',
|
|
15032
|
+
return rows.filter((row) => _optionalChain([row, 'access', _307 => _307.span_attributes, 'optionalAccess', _308 => _308.purpose]) !== "scorer").map((row) => ({
|
|
14870
15033
|
input: row.input,
|
|
14871
15034
|
output: row.output,
|
|
14872
15035
|
metadata: row.metadata,
|
|
@@ -14900,7 +15063,7 @@ var CachedSpanFetcher = (_class18 = class {
|
|
|
14900
15063
|
async fetchSpans(spanType) {
|
|
14901
15064
|
const spans = await this.fetchFn(spanType);
|
|
14902
15065
|
for (const span of spans) {
|
|
14903
|
-
const type = _nullishCoalesce(_optionalChain([span, 'access',
|
|
15066
|
+
const type = _nullishCoalesce(_optionalChain([span, 'access', _309 => _309.span_attributes, 'optionalAccess', _310 => _310.type]), () => ( ""));
|
|
14904
15067
|
const existing = _nullishCoalesce(this.spanCache.get(type), () => ( []));
|
|
14905
15068
|
existing.push(span);
|
|
14906
15069
|
this.spanCache.set(type, existing);
|
|
@@ -14980,11 +15143,11 @@ var LocalTrace = (_class19 = class {
|
|
|
14980
15143
|
const cachedSpans = this.state.spanCache.getByRootSpanId(this.rootSpanId);
|
|
14981
15144
|
if (cachedSpans && cachedSpans.length > 0) {
|
|
14982
15145
|
let spans = cachedSpans.filter(
|
|
14983
|
-
(span) => _optionalChain([span, 'access',
|
|
15146
|
+
(span) => _optionalChain([span, 'access', _311 => _311.span_attributes, 'optionalAccess', _312 => _312.purpose]) !== "scorer"
|
|
14984
15147
|
);
|
|
14985
15148
|
if (spanType && spanType.length > 0) {
|
|
14986
15149
|
spans = spans.filter(
|
|
14987
|
-
(span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access',
|
|
15150
|
+
(span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access', _313 => _313.span_attributes, 'optionalAccess', _314 => _314.type]), () => ( "")))
|
|
14988
15151
|
);
|
|
14989
15152
|
}
|
|
14990
15153
|
return spans.map((span) => ({
|
|
@@ -15003,7 +15166,7 @@ var LocalTrace = (_class19 = class {
|
|
|
15003
15166
|
* Calls the API with the project_default preprocessor (which falls back to "thread").
|
|
15004
15167
|
*/
|
|
15005
15168
|
async getThread(options) {
|
|
15006
|
-
const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
15169
|
+
const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _315 => _315.preprocessor]), () => ( "project_default"));
|
|
15007
15170
|
if (!this.threadCache.has(cacheKey)) {
|
|
15008
15171
|
const promise = this.fetchThread(options);
|
|
15009
15172
|
this.threadCache.set(cacheKey, promise);
|
|
@@ -15014,7 +15177,7 @@ var LocalTrace = (_class19 = class {
|
|
|
15014
15177
|
await this.ensureSpansReady();
|
|
15015
15178
|
await this.state.login({});
|
|
15016
15179
|
const result = await invoke({
|
|
15017
|
-
globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
15180
|
+
globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _316 => _316.preprocessor]), () => ( "project_default")),
|
|
15018
15181
|
functionType: "preprocessor",
|
|
15019
15182
|
input: {
|
|
15020
15183
|
trace_ref: {
|
|
@@ -15173,10 +15336,10 @@ function validateParametersWithJsonSchema(parameters, schema) {
|
|
|
15173
15336
|
const ajv = new (0, _ajv2.default)({ coerceTypes: true, useDefaults: true, strict: false });
|
|
15174
15337
|
const validate = ajv.compile(schema);
|
|
15175
15338
|
if (!validate(parameters)) {
|
|
15176
|
-
const errorMessages = _optionalChain([validate, 'access',
|
|
15339
|
+
const errorMessages = _optionalChain([validate, 'access', _317 => _317.errors, 'optionalAccess', _318 => _318.map, 'call', _319 => _319((err) => {
|
|
15177
15340
|
const path = err.instancePath || "root";
|
|
15178
15341
|
return `${path}: ${err.message}`;
|
|
15179
|
-
}), 'access',
|
|
15342
|
+
}), 'access', _320 => _320.join, 'call', _321 => _321(", ")]);
|
|
15180
15343
|
throw Error(`Invalid parameters: ${errorMessages}`);
|
|
15181
15344
|
}
|
|
15182
15345
|
return parameters;
|
|
@@ -15232,7 +15395,7 @@ function callEvaluatorData(data) {
|
|
|
15232
15395
|
baseExperiment
|
|
15233
15396
|
};
|
|
15234
15397
|
}
|
|
15235
|
-
function
|
|
15398
|
+
function isAsyncIterable3(value) {
|
|
15236
15399
|
return typeof value === "object" && value !== null && typeof value[Symbol.asyncIterator] === "function";
|
|
15237
15400
|
}
|
|
15238
15401
|
function isIterable(value) {
|
|
@@ -15417,7 +15580,7 @@ var defaultErrorScoreHandler = ({
|
|
|
15417
15580
|
};
|
|
15418
15581
|
async function runEvaluatorInternal(experiment, evaluator, progressReporter, filters, stream, parameters, collectResults, enableCache) {
|
|
15419
15582
|
if (enableCache) {
|
|
15420
|
-
_optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess',
|
|
15583
|
+
_optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _322 => _322.spanCache, 'optionalAccess', _323 => _323.start, 'call', _324 => _324()]);
|
|
15421
15584
|
}
|
|
15422
15585
|
try {
|
|
15423
15586
|
if (typeof evaluator.data === "string") {
|
|
@@ -15453,7 +15616,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15453
15616
|
}
|
|
15454
15617
|
const resolvedDataResult = dataResult instanceof Promise ? await dataResult : dataResult;
|
|
15455
15618
|
const dataIterable = (() => {
|
|
15456
|
-
if (
|
|
15619
|
+
if (isAsyncIterable3(resolvedDataResult)) {
|
|
15457
15620
|
return resolvedDataResult;
|
|
15458
15621
|
}
|
|
15459
15622
|
if (Array.isArray(resolvedDataResult) || isIterable(resolvedDataResult)) {
|
|
@@ -15528,7 +15691,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15528
15691
|
objectType: parentComponents ? spanObjectTypeV3ToTypedString(
|
|
15529
15692
|
parentComponents.data.object_type
|
|
15530
15693
|
) : "experiment",
|
|
15531
|
-
objectId: await _asyncNullishCoalesce(await _asyncOptionalChain([parentComponents, 'optionalAccess', async
|
|
15694
|
+
objectId: await _asyncNullishCoalesce(await _asyncOptionalChain([parentComponents, 'optionalAccess', async _325 => _325.data, 'access', async _326 => _326.object_id]), async () => ( (experimentIdPromise ? await _asyncNullishCoalesce(await experimentIdPromise, async () => ( "")) : ""))),
|
|
15532
15695
|
rootSpanId: rootSpan.rootSpanId,
|
|
15533
15696
|
ensureSpansFlushed,
|
|
15534
15697
|
state
|
|
@@ -15554,10 +15717,10 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15554
15717
|
span,
|
|
15555
15718
|
parameters: _nullishCoalesce(parameters, () => ( {})),
|
|
15556
15719
|
reportProgress: (event) => {
|
|
15557
|
-
_optionalChain([stream, 'optionalCall',
|
|
15720
|
+
_optionalChain([stream, 'optionalCall', _327 => _327({
|
|
15558
15721
|
...event,
|
|
15559
15722
|
id: rootSpan.id,
|
|
15560
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
15723
|
+
origin: _optionalChain([baseEvent, 'access', _328 => _328.event, 'optionalAccess', _329 => _329.origin]),
|
|
15561
15724
|
name: evaluator.evalName,
|
|
15562
15725
|
object_type: "task"
|
|
15563
15726
|
})]);
|
|
@@ -15721,7 +15884,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15721
15884
|
metadata,
|
|
15722
15885
|
scores: mergedScores,
|
|
15723
15886
|
error,
|
|
15724
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
15887
|
+
origin: _optionalChain([baseEvent, 'access', _330 => _330.event, 'optionalAccess', _331 => _331.origin])
|
|
15725
15888
|
});
|
|
15726
15889
|
}
|
|
15727
15890
|
};
|
|
@@ -15754,7 +15917,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15754
15917
|
break;
|
|
15755
15918
|
}
|
|
15756
15919
|
scheduledTrials++;
|
|
15757
|
-
_optionalChain([progressReporter, 'access',
|
|
15920
|
+
_optionalChain([progressReporter, 'access', _332 => _332.setTotal, 'optionalCall', _333 => _333(evaluator.evalName, scheduledTrials)]);
|
|
15758
15921
|
q.push({ datum, trialIndex });
|
|
15759
15922
|
}
|
|
15760
15923
|
}
|
|
@@ -15829,9 +15992,9 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
15829
15992
|
);
|
|
15830
15993
|
} finally {
|
|
15831
15994
|
if (enableCache) {
|
|
15832
|
-
const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess',
|
|
15833
|
-
_optionalChain([spanCache, 'optionalAccess',
|
|
15834
|
-
_optionalChain([spanCache, 'optionalAccess',
|
|
15995
|
+
const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _334 => _334.spanCache]);
|
|
15996
|
+
_optionalChain([spanCache, 'optionalAccess', _335 => _335.dispose, 'call', _336 => _336()]);
|
|
15997
|
+
_optionalChain([spanCache, 'optionalAccess', _337 => _337.stop, 'call', _338 => _338()]);
|
|
15835
15998
|
}
|
|
15836
15999
|
}
|
|
15837
16000
|
}
|