@mastra/core
Version:
40 lines (38 loc) • 1.35 kB
JavaScript
;
// src/evals/collect-tool-mocks.ts
function isSubAgentDelegation(toolName) {
return toolName.startsWith("agent-");
}
function extractToolName(label) {
const match = label.match(/^(?:mcp_)?tool:\s*'(.*?)'/);
return match?.[1] ?? label;
}
function collectToolMocks(steps) {
return collectToolMocksInto(steps, []);
}
function collectToolMocksInto(steps, acc) {
if (!steps) return acc;
for (const step of steps) {
const isToolCall = step.stepType === "tool_call" || step.stepType === "mcp_tool_call";
if (isToolCall && step.name) {
const toolName = extractToolName(step.name);
const toolArgs = "toolArgs" in step ? step.toolArgs : void 0;
const toolResult = "toolResult" in step ? step.toolResult : void 0;
acc.push({
toolName,
args: toolArgs ?? {},
output: toolResult,
// Sub-agent delegation args are LLM-authored + runtime-injected; default
// to ignore-args matching so the saved mock matches on replay.
...isSubAgentDelegation(toolName) ? { matchArgs: "ignore" } : {}
});
}
if (!isToolCall && step.children?.length) {
collectToolMocksInto(step.children, acc);
}
}
return acc;
}
exports.collectToolMocks = collectToolMocks;
//# sourceMappingURL=chunk-TLSDQS6O.cjs.map
//# sourceMappingURL=chunk-TLSDQS6O.cjs.map