agentv 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.
@@ -17215,22 +17215,31 @@ async function loadTestById(evalFilePath, repoRoot, evalId) {
17215
17215
  return match;
17216
17216
  }
17217
17217
  var loadEvalCaseById = loadTestById;
17218
+ function parseCommandArray(source) {
17219
+ if (typeof source === "string") {
17220
+ const parts = source.trim().split(/\s+/);
17221
+ return parts.length > 0 && parts[0] !== "" ? parts : void 0;
17222
+ }
17223
+ if (Array.isArray(source)) {
17224
+ const arr = source.filter((s) => typeof s === "string");
17225
+ return arr.length > 0 ? arr : void 0;
17226
+ }
17227
+ return void 0;
17228
+ }
17218
17229
  function parseWorkspaceScriptConfig(raw, evalFileDir) {
17219
17230
  if (!isJsonObject(raw)) return void 0;
17220
17231
  const obj = raw;
17221
17232
  if (obj.script !== void 0 && obj.command === void 0) {
17222
17233
  logWarning5("'script' is deprecated. Use 'command' instead.");
17223
17234
  }
17224
- const commandSource = obj.command ?? obj.script;
17225
- if (!Array.isArray(commandSource) || commandSource.length === 0) return void 0;
17226
- const commandArr = commandSource.filter((s) => typeof s === "string");
17227
- if (commandArr.length === 0) return void 0;
17235
+ const command = parseCommandArray(obj.command ?? obj.script);
17236
+ if (!command) return void 0;
17228
17237
  const timeoutMs = typeof obj.timeout_ms === "number" ? obj.timeout_ms : void 0;
17229
17238
  let cwd = typeof obj.cwd === "string" ? obj.cwd : void 0;
17230
17239
  if (cwd && !path7.isAbsolute(cwd)) {
17231
17240
  cwd = path7.resolve(evalFileDir, cwd);
17232
17241
  }
17233
- const config = { command: commandArr };
17242
+ const config = { command };
17234
17243
  if (timeoutMs !== void 0) {
17235
17244
  return { ...config, timeout_ms: timeoutMs, ...cwd !== void 0 && { cwd } };
17236
17245
  }
@@ -21490,6 +21499,26 @@ ${prompt}` : prompt;
21490
21499
  env[envKey] = this.config.apiKey;
21491
21500
  }
21492
21501
  }
21502
+ if (this.config.subprovider) {
21503
+ const provider = this.config.subprovider.toLowerCase();
21504
+ const PROVIDER_OWN_PREFIXES = {
21505
+ openrouter: ["OPENROUTER_"],
21506
+ anthropic: ["ANTHROPIC_"],
21507
+ openai: ["OPENAI_"],
21508
+ azure: ["AZURE_OPENAI_"],
21509
+ google: ["GEMINI_", "GOOGLE_GENERATIVE_AI_"],
21510
+ gemini: ["GEMINI_", "GOOGLE_GENERATIVE_AI_"],
21511
+ groq: ["GROQ_"],
21512
+ xai: ["XAI_"]
21513
+ };
21514
+ const ownPrefixes = PROVIDER_OWN_PREFIXES[provider] ?? [];
21515
+ const allOtherPrefixes = Object.entries(PROVIDER_OWN_PREFIXES).filter(([key]) => key !== provider).flatMap(([, prefixes]) => prefixes);
21516
+ for (const key of Object.keys(env)) {
21517
+ if (allOtherPrefixes.some((prefix) => key.startsWith(prefix)) && !ownPrefixes.some((prefix) => key.startsWith(prefix))) {
21518
+ delete env[key];
21519
+ }
21520
+ }
21521
+ }
21493
21522
  return env;
21494
21523
  }
21495
21524
  async createWorkspace() {
@@ -21717,6 +21746,10 @@ function summarizePiEvent(event) {
21717
21746
  }
21718
21747
  return `message_update: ${eventType}`;
21719
21748
  }
21749
+ case "tool_execution_start":
21750
+ return `tool_start: ${record.toolName}`;
21751
+ case "tool_execution_end":
21752
+ return `tool_end: ${record.toolName}`;
21720
21753
  default:
21721
21754
  return type;
21722
21755
  }
@@ -21747,25 +21780,89 @@ function parsePiJsonl(output) {
21747
21780
  return parsed;
21748
21781
  }
21749
21782
  function extractMessages(events) {
21783
+ let messages;
21750
21784
  for (let i = events.length - 1; i >= 0; i--) {
21751
21785
  const event = events[i];
21752
21786
  if (!event || typeof event !== "object") continue;
21753
21787
  const record = event;
21754
21788
  if (record.type !== "agent_end") continue;
21755
- const messages = record.messages;
21756
- if (!Array.isArray(messages)) continue;
21757
- return messages.map(convertPiMessage).filter((m) => m !== void 0);
21789
+ const msgs = record.messages;
21790
+ if (!Array.isArray(msgs)) continue;
21791
+ messages = msgs.map(convertPiMessage).filter((m) => m !== void 0);
21792
+ break;
21758
21793
  }
21759
- const output = [];
21794
+ if (!messages) {
21795
+ messages = [];
21796
+ for (const event of events) {
21797
+ if (!event || typeof event !== "object") continue;
21798
+ const record = event;
21799
+ if (record.type === "turn_end") {
21800
+ const converted = convertPiMessage(record.message);
21801
+ if (converted) messages.push(converted);
21802
+ }
21803
+ }
21804
+ }
21805
+ const eventToolCalls = extractToolCallsFromEvents(events);
21806
+ if (eventToolCalls.length > 0) {
21807
+ injectEventToolCalls(messages, eventToolCalls);
21808
+ }
21809
+ return messages;
21810
+ }
21811
+ function extractToolCallsFromEvents(events) {
21812
+ const starts = /* @__PURE__ */ new Map();
21813
+ const results = /* @__PURE__ */ new Map();
21760
21814
  for (const event of events) {
21761
21815
  if (!event || typeof event !== "object") continue;
21762
- const record = event;
21763
- if (record.type === "turn_end") {
21764
- const converted = convertPiMessage(record.message);
21765
- if (converted) output.push(converted);
21816
+ const r = event;
21817
+ const type = r.type;
21818
+ if (type === "tool_execution_start" && typeof r.toolName === "string") {
21819
+ const id = typeof r.toolCallId === "string" ? r.toolCallId : void 0;
21820
+ starts.set(id ?? `anon-${starts.size}`, { tool: r.toolName, input: r.args });
21821
+ } else if (type === "tool_execution_end") {
21822
+ const id = typeof r.toolCallId === "string" ? r.toolCallId : void 0;
21823
+ if (id) results.set(id, r.result);
21824
+ }
21825
+ }
21826
+ const toolCalls = [];
21827
+ for (const [id, { tool: tool2, input }] of starts) {
21828
+ toolCalls.push({
21829
+ tool: tool2,
21830
+ input,
21831
+ id: id.startsWith("anon-") ? void 0 : id,
21832
+ output: results.get(id)
21833
+ });
21834
+ }
21835
+ return toolCalls;
21836
+ }
21837
+ function injectEventToolCalls(messages, eventToolCalls) {
21838
+ const existingIds = /* @__PURE__ */ new Set();
21839
+ const existingTools = /* @__PURE__ */ new Set();
21840
+ for (const msg of messages) {
21841
+ if (!msg.toolCalls) continue;
21842
+ for (const tc of msg.toolCalls) {
21843
+ if (tc.id) existingIds.add(tc.id);
21844
+ existingTools.add(`${tc.tool}:${JSON.stringify(tc.input)}`);
21845
+ }
21846
+ }
21847
+ const missing = eventToolCalls.filter((tc) => {
21848
+ if (tc.id && existingIds.has(tc.id)) return false;
21849
+ if (existingTools.has(`${tc.tool}:${JSON.stringify(tc.input)}`)) return false;
21850
+ return true;
21851
+ });
21852
+ if (missing.length === 0) return;
21853
+ let targetIdx = -1;
21854
+ for (let i = messages.length - 1; i >= 0; i--) {
21855
+ if (messages[i].role === "assistant") {
21856
+ targetIdx = i;
21857
+ break;
21766
21858
  }
21767
21859
  }
21768
- return output;
21860
+ if (targetIdx >= 0) {
21861
+ const target = messages[targetIdx];
21862
+ messages[targetIdx] = { ...target, toolCalls: [...target.toolCalls ?? [], ...missing] };
21863
+ } else {
21864
+ messages.push({ role: "assistant", content: "", toolCalls: missing });
21865
+ }
21769
21866
  }
21770
21867
  function extractTokenUsage(events) {
21771
21868
  for (let i = events.length - 1; i >= 0; i--) {
@@ -21860,15 +21957,13 @@ function extractToolCalls3(content) {
21860
21957
  input: p.input,
21861
21958
  id: typeof p.id === "string" ? p.id : void 0
21862
21959
  });
21863
- }
21864
- if (p.type === "toolCall" && typeof p.name === "string") {
21960
+ } else if ((p.type === "toolCall" || p.type === "tool_call") && typeof p.name === "string") {
21865
21961
  toolCalls.push({
21866
21962
  tool: p.name,
21867
- input: p.arguments,
21963
+ input: p.arguments ?? p.input,
21868
21964
  id: typeof p.id === "string" ? p.id : void 0
21869
21965
  });
21870
- }
21871
- if (p.type === "tool_result" && typeof p.tool_use_id === "string") {
21966
+ } else if (p.type === "tool_result" && typeof p.tool_use_id === "string") {
21872
21967
  const existing = toolCalls.find((tc) => tc.id === p.tool_use_id);
21873
21968
  if (existing) {
21874
21969
  const idx = toolCalls.indexOf(existing);
@@ -31961,4 +32056,4 @@ export {
31961
32056
  OtelStreamingObserver,
31962
32057
  createAgentKernel
31963
32058
  };
31964
- //# sourceMappingURL=chunk-3TBDSUYD.js.map
32059
+ //# sourceMappingURL=chunk-ELQEFMGO.js.map