@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 CHANGED
@@ -4676,22 +4676,31 @@ async function loadTestById(evalFilePath, repoRoot, evalId) {
4676
4676
  return match;
4677
4677
  }
4678
4678
  var loadEvalCaseById = loadTestById;
4679
+ function parseCommandArray(source) {
4680
+ if (typeof source === "string") {
4681
+ const parts = source.trim().split(/\s+/);
4682
+ return parts.length > 0 && parts[0] !== "" ? parts : void 0;
4683
+ }
4684
+ if (Array.isArray(source)) {
4685
+ const arr = source.filter((s) => typeof s === "string");
4686
+ return arr.length > 0 ? arr : void 0;
4687
+ }
4688
+ return void 0;
4689
+ }
4679
4690
  function parseWorkspaceScriptConfig(raw, evalFileDir) {
4680
4691
  if (!isJsonObject(raw)) return void 0;
4681
4692
  const obj = raw;
4682
4693
  if (obj.script !== void 0 && obj.command === void 0) {
4683
4694
  logWarning5("'script' is deprecated. Use 'command' instead.");
4684
4695
  }
4685
- const commandSource = obj.command ?? obj.script;
4686
- if (!Array.isArray(commandSource) || commandSource.length === 0) return void 0;
4687
- const commandArr = commandSource.filter((s) => typeof s === "string");
4688
- if (commandArr.length === 0) return void 0;
4696
+ const command = parseCommandArray(obj.command ?? obj.script);
4697
+ if (!command) return void 0;
4689
4698
  const timeoutMs = typeof obj.timeout_ms === "number" ? obj.timeout_ms : void 0;
4690
4699
  let cwd = typeof obj.cwd === "string" ? obj.cwd : void 0;
4691
4700
  if (cwd && !import_node_path8.default.isAbsolute(cwd)) {
4692
4701
  cwd = import_node_path8.default.resolve(evalFileDir, cwd);
4693
4702
  }
4694
- const config = { command: commandArr };
4703
+ const config = { command };
4695
4704
  if (timeoutMs !== void 0) {
4696
4705
  return { ...config, timeout_ms: timeoutMs, ...cwd !== void 0 && { cwd } };
4697
4706
  }
@@ -9180,6 +9189,26 @@ ${prompt}` : prompt;
9180
9189
  env[envKey] = this.config.apiKey;
9181
9190
  }
9182
9191
  }
9192
+ if (this.config.subprovider) {
9193
+ const provider = this.config.subprovider.toLowerCase();
9194
+ const PROVIDER_OWN_PREFIXES = {
9195
+ openrouter: ["OPENROUTER_"],
9196
+ anthropic: ["ANTHROPIC_"],
9197
+ openai: ["OPENAI_"],
9198
+ azure: ["AZURE_OPENAI_"],
9199
+ google: ["GEMINI_", "GOOGLE_GENERATIVE_AI_"],
9200
+ gemini: ["GEMINI_", "GOOGLE_GENERATIVE_AI_"],
9201
+ groq: ["GROQ_"],
9202
+ xai: ["XAI_"]
9203
+ };
9204
+ const ownPrefixes = PROVIDER_OWN_PREFIXES[provider] ?? [];
9205
+ const allOtherPrefixes = Object.entries(PROVIDER_OWN_PREFIXES).filter(([key]) => key !== provider).flatMap(([, prefixes]) => prefixes);
9206
+ for (const key of Object.keys(env)) {
9207
+ if (allOtherPrefixes.some((prefix) => key.startsWith(prefix)) && !ownPrefixes.some((prefix) => key.startsWith(prefix))) {
9208
+ delete env[key];
9209
+ }
9210
+ }
9211
+ }
9183
9212
  return env;
9184
9213
  }
9185
9214
  async createWorkspace() {
@@ -9407,6 +9436,10 @@ function summarizePiEvent(event) {
9407
9436
  }
9408
9437
  return `message_update: ${eventType}`;
9409
9438
  }
9439
+ case "tool_execution_start":
9440
+ return `tool_start: ${record.toolName}`;
9441
+ case "tool_execution_end":
9442
+ return `tool_end: ${record.toolName}`;
9410
9443
  default:
9411
9444
  return type;
9412
9445
  }
@@ -9437,25 +9470,89 @@ function parsePiJsonl(output) {
9437
9470
  return parsed;
9438
9471
  }
9439
9472
  function extractMessages(events) {
9473
+ let messages;
9440
9474
  for (let i = events.length - 1; i >= 0; i--) {
9441
9475
  const event = events[i];
9442
9476
  if (!event || typeof event !== "object") continue;
9443
9477
  const record = event;
9444
9478
  if (record.type !== "agent_end") continue;
9445
- const messages = record.messages;
9446
- if (!Array.isArray(messages)) continue;
9447
- return messages.map(convertPiMessage).filter((m) => m !== void 0);
9479
+ const msgs = record.messages;
9480
+ if (!Array.isArray(msgs)) continue;
9481
+ messages = msgs.map(convertPiMessage).filter((m) => m !== void 0);
9482
+ break;
9483
+ }
9484
+ if (!messages) {
9485
+ messages = [];
9486
+ for (const event of events) {
9487
+ if (!event || typeof event !== "object") continue;
9488
+ const record = event;
9489
+ if (record.type === "turn_end") {
9490
+ const converted = convertPiMessage(record.message);
9491
+ if (converted) messages.push(converted);
9492
+ }
9493
+ }
9494
+ }
9495
+ const eventToolCalls = extractToolCallsFromEvents(events);
9496
+ if (eventToolCalls.length > 0) {
9497
+ injectEventToolCalls(messages, eventToolCalls);
9448
9498
  }
9449
- const output = [];
9499
+ return messages;
9500
+ }
9501
+ function extractToolCallsFromEvents(events) {
9502
+ const starts = /* @__PURE__ */ new Map();
9503
+ const results = /* @__PURE__ */ new Map();
9450
9504
  for (const event of events) {
9451
9505
  if (!event || typeof event !== "object") continue;
9452
- const record = event;
9453
- if (record.type === "turn_end") {
9454
- const converted = convertPiMessage(record.message);
9455
- if (converted) output.push(converted);
9506
+ const r = event;
9507
+ const type = r.type;
9508
+ if (type === "tool_execution_start" && typeof r.toolName === "string") {
9509
+ const id = typeof r.toolCallId === "string" ? r.toolCallId : void 0;
9510
+ starts.set(id ?? `anon-${starts.size}`, { tool: r.toolName, input: r.args });
9511
+ } else if (type === "tool_execution_end") {
9512
+ const id = typeof r.toolCallId === "string" ? r.toolCallId : void 0;
9513
+ if (id) results.set(id, r.result);
9456
9514
  }
9457
9515
  }
9458
- return output;
9516
+ const toolCalls = [];
9517
+ for (const [id, { tool: tool2, input }] of starts) {
9518
+ toolCalls.push({
9519
+ tool: tool2,
9520
+ input,
9521
+ id: id.startsWith("anon-") ? void 0 : id,
9522
+ output: results.get(id)
9523
+ });
9524
+ }
9525
+ return toolCalls;
9526
+ }
9527
+ function injectEventToolCalls(messages, eventToolCalls) {
9528
+ const existingIds = /* @__PURE__ */ new Set();
9529
+ const existingTools = /* @__PURE__ */ new Set();
9530
+ for (const msg of messages) {
9531
+ if (!msg.toolCalls) continue;
9532
+ for (const tc of msg.toolCalls) {
9533
+ if (tc.id) existingIds.add(tc.id);
9534
+ existingTools.add(`${tc.tool}:${JSON.stringify(tc.input)}`);
9535
+ }
9536
+ }
9537
+ const missing = eventToolCalls.filter((tc) => {
9538
+ if (tc.id && existingIds.has(tc.id)) return false;
9539
+ if (existingTools.has(`${tc.tool}:${JSON.stringify(tc.input)}`)) return false;
9540
+ return true;
9541
+ });
9542
+ if (missing.length === 0) return;
9543
+ let targetIdx = -1;
9544
+ for (let i = messages.length - 1; i >= 0; i--) {
9545
+ if (messages[i].role === "assistant") {
9546
+ targetIdx = i;
9547
+ break;
9548
+ }
9549
+ }
9550
+ if (targetIdx >= 0) {
9551
+ const target = messages[targetIdx];
9552
+ messages[targetIdx] = { ...target, toolCalls: [...target.toolCalls ?? [], ...missing] };
9553
+ } else {
9554
+ messages.push({ role: "assistant", content: "", toolCalls: missing });
9555
+ }
9459
9556
  }
9460
9557
  function extractTokenUsage(events) {
9461
9558
  for (let i = events.length - 1; i >= 0; i--) {
@@ -9550,15 +9647,13 @@ function extractToolCalls3(content) {
9550
9647
  input: p.input,
9551
9648
  id: typeof p.id === "string" ? p.id : void 0
9552
9649
  });
9553
- }
9554
- if (p.type === "toolCall" && typeof p.name === "string") {
9650
+ } else if ((p.type === "toolCall" || p.type === "tool_call") && typeof p.name === "string") {
9555
9651
  toolCalls.push({
9556
9652
  tool: p.name,
9557
- input: p.arguments,
9653
+ input: p.arguments ?? p.input,
9558
9654
  id: typeof p.id === "string" ? p.id : void 0
9559
9655
  });
9560
- }
9561
- if (p.type === "tool_result" && typeof p.tool_use_id === "string") {
9656
+ } else if (p.type === "tool_result" && typeof p.tool_use_id === "string") {
9562
9657
  const existing = toolCalls.find((tc) => tc.id === p.tool_use_id);
9563
9658
  if (existing) {
9564
9659
  const idx = toolCalls.indexOf(existing);