@agentv/core 3.14.0 → 3.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +114 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +114 -19
- package/dist/index.js.map +1 -1
- package/package.json +2 -5
package/dist/index.js
CHANGED
|
@@ -2955,22 +2955,31 @@ async function loadTestById(evalFilePath, repoRoot, evalId) {
|
|
|
2955
2955
|
return match;
|
|
2956
2956
|
}
|
|
2957
2957
|
var loadEvalCaseById = loadTestById;
|
|
2958
|
+
function parseCommandArray(source) {
|
|
2959
|
+
if (typeof source === "string") {
|
|
2960
|
+
const parts = source.trim().split(/\s+/);
|
|
2961
|
+
return parts.length > 0 && parts[0] !== "" ? parts : void 0;
|
|
2962
|
+
}
|
|
2963
|
+
if (Array.isArray(source)) {
|
|
2964
|
+
const arr = source.filter((s) => typeof s === "string");
|
|
2965
|
+
return arr.length > 0 ? arr : void 0;
|
|
2966
|
+
}
|
|
2967
|
+
return void 0;
|
|
2968
|
+
}
|
|
2958
2969
|
function parseWorkspaceScriptConfig(raw, evalFileDir) {
|
|
2959
2970
|
if (!isJsonObject(raw)) return void 0;
|
|
2960
2971
|
const obj = raw;
|
|
2961
2972
|
if (obj.script !== void 0 && obj.command === void 0) {
|
|
2962
2973
|
logWarning5("'script' is deprecated. Use 'command' instead.");
|
|
2963
2974
|
}
|
|
2964
|
-
const
|
|
2965
|
-
if (!
|
|
2966
|
-
const commandArr = commandSource.filter((s) => typeof s === "string");
|
|
2967
|
-
if (commandArr.length === 0) return void 0;
|
|
2975
|
+
const command = parseCommandArray(obj.command ?? obj.script);
|
|
2976
|
+
if (!command) return void 0;
|
|
2968
2977
|
const timeoutMs = typeof obj.timeout_ms === "number" ? obj.timeout_ms : void 0;
|
|
2969
2978
|
let cwd = typeof obj.cwd === "string" ? obj.cwd : void 0;
|
|
2970
2979
|
if (cwd && !path7.isAbsolute(cwd)) {
|
|
2971
2980
|
cwd = path7.resolve(evalFileDir, cwd);
|
|
2972
2981
|
}
|
|
2973
|
-
const config = { command
|
|
2982
|
+
const config = { command };
|
|
2974
2983
|
if (timeoutMs !== void 0) {
|
|
2975
2984
|
return { ...config, timeout_ms: timeoutMs, ...cwd !== void 0 && { cwd } };
|
|
2976
2985
|
}
|
|
@@ -7340,6 +7349,26 @@ ${prompt}` : prompt;
|
|
|
7340
7349
|
env[envKey] = this.config.apiKey;
|
|
7341
7350
|
}
|
|
7342
7351
|
}
|
|
7352
|
+
if (this.config.subprovider) {
|
|
7353
|
+
const provider = this.config.subprovider.toLowerCase();
|
|
7354
|
+
const PROVIDER_OWN_PREFIXES = {
|
|
7355
|
+
openrouter: ["OPENROUTER_"],
|
|
7356
|
+
anthropic: ["ANTHROPIC_"],
|
|
7357
|
+
openai: ["OPENAI_"],
|
|
7358
|
+
azure: ["AZURE_OPENAI_"],
|
|
7359
|
+
google: ["GEMINI_", "GOOGLE_GENERATIVE_AI_"],
|
|
7360
|
+
gemini: ["GEMINI_", "GOOGLE_GENERATIVE_AI_"],
|
|
7361
|
+
groq: ["GROQ_"],
|
|
7362
|
+
xai: ["XAI_"]
|
|
7363
|
+
};
|
|
7364
|
+
const ownPrefixes = PROVIDER_OWN_PREFIXES[provider] ?? [];
|
|
7365
|
+
const allOtherPrefixes = Object.entries(PROVIDER_OWN_PREFIXES).filter(([key]) => key !== provider).flatMap(([, prefixes]) => prefixes);
|
|
7366
|
+
for (const key of Object.keys(env)) {
|
|
7367
|
+
if (allOtherPrefixes.some((prefix) => key.startsWith(prefix)) && !ownPrefixes.some((prefix) => key.startsWith(prefix))) {
|
|
7368
|
+
delete env[key];
|
|
7369
|
+
}
|
|
7370
|
+
}
|
|
7371
|
+
}
|
|
7343
7372
|
return env;
|
|
7344
7373
|
}
|
|
7345
7374
|
async createWorkspace() {
|
|
@@ -7567,6 +7596,10 @@ function summarizePiEvent(event) {
|
|
|
7567
7596
|
}
|
|
7568
7597
|
return `message_update: ${eventType}`;
|
|
7569
7598
|
}
|
|
7599
|
+
case "tool_execution_start":
|
|
7600
|
+
return `tool_start: ${record.toolName}`;
|
|
7601
|
+
case "tool_execution_end":
|
|
7602
|
+
return `tool_end: ${record.toolName}`;
|
|
7570
7603
|
default:
|
|
7571
7604
|
return type;
|
|
7572
7605
|
}
|
|
@@ -7597,25 +7630,89 @@ function parsePiJsonl(output) {
|
|
|
7597
7630
|
return parsed;
|
|
7598
7631
|
}
|
|
7599
7632
|
function extractMessages(events) {
|
|
7633
|
+
let messages;
|
|
7600
7634
|
for (let i = events.length - 1; i >= 0; i--) {
|
|
7601
7635
|
const event = events[i];
|
|
7602
7636
|
if (!event || typeof event !== "object") continue;
|
|
7603
7637
|
const record = event;
|
|
7604
7638
|
if (record.type !== "agent_end") continue;
|
|
7605
|
-
const
|
|
7606
|
-
if (!Array.isArray(
|
|
7607
|
-
|
|
7639
|
+
const msgs = record.messages;
|
|
7640
|
+
if (!Array.isArray(msgs)) continue;
|
|
7641
|
+
messages = msgs.map(convertPiMessage).filter((m) => m !== void 0);
|
|
7642
|
+
break;
|
|
7643
|
+
}
|
|
7644
|
+
if (!messages) {
|
|
7645
|
+
messages = [];
|
|
7646
|
+
for (const event of events) {
|
|
7647
|
+
if (!event || typeof event !== "object") continue;
|
|
7648
|
+
const record = event;
|
|
7649
|
+
if (record.type === "turn_end") {
|
|
7650
|
+
const converted = convertPiMessage(record.message);
|
|
7651
|
+
if (converted) messages.push(converted);
|
|
7652
|
+
}
|
|
7653
|
+
}
|
|
7654
|
+
}
|
|
7655
|
+
const eventToolCalls = extractToolCallsFromEvents(events);
|
|
7656
|
+
if (eventToolCalls.length > 0) {
|
|
7657
|
+
injectEventToolCalls(messages, eventToolCalls);
|
|
7608
7658
|
}
|
|
7609
|
-
|
|
7659
|
+
return messages;
|
|
7660
|
+
}
|
|
7661
|
+
function extractToolCallsFromEvents(events) {
|
|
7662
|
+
const starts = /* @__PURE__ */ new Map();
|
|
7663
|
+
const results = /* @__PURE__ */ new Map();
|
|
7610
7664
|
for (const event of events) {
|
|
7611
7665
|
if (!event || typeof event !== "object") continue;
|
|
7612
|
-
const
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
|
|
7666
|
+
const r = event;
|
|
7667
|
+
const type = r.type;
|
|
7668
|
+
if (type === "tool_execution_start" && typeof r.toolName === "string") {
|
|
7669
|
+
const id = typeof r.toolCallId === "string" ? r.toolCallId : void 0;
|
|
7670
|
+
starts.set(id ?? `anon-${starts.size}`, { tool: r.toolName, input: r.args });
|
|
7671
|
+
} else if (type === "tool_execution_end") {
|
|
7672
|
+
const id = typeof r.toolCallId === "string" ? r.toolCallId : void 0;
|
|
7673
|
+
if (id) results.set(id, r.result);
|
|
7616
7674
|
}
|
|
7617
7675
|
}
|
|
7618
|
-
|
|
7676
|
+
const toolCalls = [];
|
|
7677
|
+
for (const [id, { tool: tool2, input }] of starts) {
|
|
7678
|
+
toolCalls.push({
|
|
7679
|
+
tool: tool2,
|
|
7680
|
+
input,
|
|
7681
|
+
id: id.startsWith("anon-") ? void 0 : id,
|
|
7682
|
+
output: results.get(id)
|
|
7683
|
+
});
|
|
7684
|
+
}
|
|
7685
|
+
return toolCalls;
|
|
7686
|
+
}
|
|
7687
|
+
function injectEventToolCalls(messages, eventToolCalls) {
|
|
7688
|
+
const existingIds = /* @__PURE__ */ new Set();
|
|
7689
|
+
const existingTools = /* @__PURE__ */ new Set();
|
|
7690
|
+
for (const msg of messages) {
|
|
7691
|
+
if (!msg.toolCalls) continue;
|
|
7692
|
+
for (const tc of msg.toolCalls) {
|
|
7693
|
+
if (tc.id) existingIds.add(tc.id);
|
|
7694
|
+
existingTools.add(`${tc.tool}:${JSON.stringify(tc.input)}`);
|
|
7695
|
+
}
|
|
7696
|
+
}
|
|
7697
|
+
const missing = eventToolCalls.filter((tc) => {
|
|
7698
|
+
if (tc.id && existingIds.has(tc.id)) return false;
|
|
7699
|
+
if (existingTools.has(`${tc.tool}:${JSON.stringify(tc.input)}`)) return false;
|
|
7700
|
+
return true;
|
|
7701
|
+
});
|
|
7702
|
+
if (missing.length === 0) return;
|
|
7703
|
+
let targetIdx = -1;
|
|
7704
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
7705
|
+
if (messages[i].role === "assistant") {
|
|
7706
|
+
targetIdx = i;
|
|
7707
|
+
break;
|
|
7708
|
+
}
|
|
7709
|
+
}
|
|
7710
|
+
if (targetIdx >= 0) {
|
|
7711
|
+
const target = messages[targetIdx];
|
|
7712
|
+
messages[targetIdx] = { ...target, toolCalls: [...target.toolCalls ?? [], ...missing] };
|
|
7713
|
+
} else {
|
|
7714
|
+
messages.push({ role: "assistant", content: "", toolCalls: missing });
|
|
7715
|
+
}
|
|
7619
7716
|
}
|
|
7620
7717
|
function extractTokenUsage(events) {
|
|
7621
7718
|
for (let i = events.length - 1; i >= 0; i--) {
|
|
@@ -7710,15 +7807,13 @@ function extractToolCalls3(content) {
|
|
|
7710
7807
|
input: p.input,
|
|
7711
7808
|
id: typeof p.id === "string" ? p.id : void 0
|
|
7712
7809
|
});
|
|
7713
|
-
}
|
|
7714
|
-
if (p.type === "toolCall" && typeof p.name === "string") {
|
|
7810
|
+
} else if ((p.type === "toolCall" || p.type === "tool_call") && typeof p.name === "string") {
|
|
7715
7811
|
toolCalls.push({
|
|
7716
7812
|
tool: p.name,
|
|
7717
|
-
input: p.arguments,
|
|
7813
|
+
input: p.arguments ?? p.input,
|
|
7718
7814
|
id: typeof p.id === "string" ? p.id : void 0
|
|
7719
7815
|
});
|
|
7720
|
-
}
|
|
7721
|
-
if (p.type === "tool_result" && typeof p.tool_use_id === "string") {
|
|
7816
|
+
} else if (p.type === "tool_result" && typeof p.tool_use_id === "string") {
|
|
7722
7817
|
const existing = toolCalls.find((tc) => tc.id === p.tool_use_id);
|
|
7723
7818
|
if (existing) {
|
|
7724
7819
|
const idx = toolCalls.indexOf(existing);
|