agentv 3.3.0 → 3.4.0

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.
@@ -301,7 +301,7 @@ var require_dist = __commonJS({
301
301
  }
302
302
  });
303
303
 
304
- // ../../packages/core/dist/chunk-C4MKEQR5.js
304
+ // ../../packages/core/dist/chunk-JO4HIAEF.js
305
305
  import { constants } from "node:fs";
306
306
  import { access, readFile } from "node:fs/promises";
307
307
  import path from "node:path";
@@ -419,7 +419,7 @@ __export(external_exports2, {
419
419
  void: () => voidType
420
420
  });
421
421
 
422
- // ../../packages/core/dist/chunk-C4MKEQR5.js
422
+ // ../../packages/core/dist/chunk-JO4HIAEF.js
423
423
  var TEST_MESSAGE_ROLE_VALUES = ["system", "user", "assistant", "tool"];
424
424
  var TEST_MESSAGE_ROLES = TEST_MESSAGE_ROLE_VALUES;
425
425
  var TEST_MESSAGE_ROLE_SET = new Set(TEST_MESSAGE_ROLE_VALUES);
@@ -1810,6 +1810,7 @@ var AGENT_PROVIDER_KINDS = [
1810
1810
  "copilot-sdk",
1811
1811
  "copilot-cli",
1812
1812
  "pi-coding-agent",
1813
+ "pi-agent-sdk",
1813
1814
  "claude",
1814
1815
  "claude-cli",
1815
1816
  "claude-sdk",
@@ -20912,6 +20913,29 @@ var MockProvider = class {
20912
20913
  return this.delayMs;
20913
20914
  }
20914
20915
  };
20916
+ function extractPiTextContent(content) {
20917
+ if (typeof content === "string") {
20918
+ return content;
20919
+ }
20920
+ if (!Array.isArray(content)) {
20921
+ return void 0;
20922
+ }
20923
+ const textParts = [];
20924
+ for (const part of content) {
20925
+ if (!part || typeof part !== "object") {
20926
+ continue;
20927
+ }
20928
+ const p = part;
20929
+ if (p.type === "text" && typeof p.text === "string") {
20930
+ textParts.push(p.text);
20931
+ }
20932
+ }
20933
+ return textParts.length > 0 ? textParts.join("\n") : void 0;
20934
+ }
20935
+ function toFiniteNumber(value) {
20936
+ if (typeof value === "number" && Number.isFinite(value)) return value;
20937
+ return void 0;
20938
+ }
20915
20939
  var piAgentModule = null;
20916
20940
  var piAiModule = null;
20917
20941
  async function loadPiModules() {
@@ -20952,7 +20976,8 @@ var PiAgentSdkProvider = class {
20952
20976
  throw new Error("Pi agent SDK request was aborted before execution");
20953
20977
  }
20954
20978
  const { Agent, getModel, getEnvApiKey } = await loadPiModules();
20955
- const startTime = Date.now();
20979
+ const startTimeIso = (/* @__PURE__ */ new Date()).toISOString();
20980
+ const startMs = Date.now();
20956
20981
  const providerName = this.config.provider ?? "anthropic";
20957
20982
  const modelId = this.config.model ?? "claude-sonnet-4-20250514";
20958
20983
  const model = getModel(providerName, modelId);
@@ -20969,16 +20994,73 @@ var PiAgentSdkProvider = class {
20969
20994
  return this.config.apiKey ?? getEnvApiKey(provider) ?? void 0;
20970
20995
  }
20971
20996
  });
20972
- const output = [];
20973
- let finalAssistantContent = "";
20997
+ let tokenUsage;
20998
+ let costUsd;
20999
+ const toolTrackers = /* @__PURE__ */ new Map();
21000
+ const completedToolResults = /* @__PURE__ */ new Map();
20974
21001
  const unsubscribe = agent.subscribe((event) => {
20975
- if (event.type === "message_end") {
20976
- const msg = event.message;
20977
- if (msg.role === "assistant") {
20978
- const content = extractTextContent3(msg.content);
20979
- if (content) {
20980
- finalAssistantContent = content;
21002
+ switch (event.type) {
21003
+ case "message_end": {
21004
+ const msg = event.message;
21005
+ if (msg && typeof msg === "object" && "role" in msg && msg.role === "assistant" && "usage" in msg) {
21006
+ const usage = msg.usage;
21007
+ if (usage && typeof usage === "object") {
21008
+ const u = usage;
21009
+ const input = toFiniteNumber(u.input);
21010
+ const output = toFiniteNumber(u.output);
21011
+ const cached = toFiniteNumber(u.cacheRead);
21012
+ let callDelta;
21013
+ if (input !== void 0 || output !== void 0) {
21014
+ callDelta = {
21015
+ input: input ?? 0,
21016
+ output: output ?? 0,
21017
+ ...cached !== void 0 ? { cached } : {}
21018
+ };
21019
+ tokenUsage = {
21020
+ input: (tokenUsage?.input ?? 0) + callDelta.input,
21021
+ output: (tokenUsage?.output ?? 0) + callDelta.output,
21022
+ ...cached !== void 0 ? { cached: (tokenUsage?.cached ?? 0) + cached } : tokenUsage?.cached !== void 0 ? { cached: tokenUsage.cached } : {}
21023
+ };
21024
+ }
21025
+ const cost = u.cost;
21026
+ if (cost && typeof cost === "object") {
21027
+ const total = toFiniteNumber(cost.total);
21028
+ if (total !== void 0) {
21029
+ costUsd = (costUsd ?? 0) + total;
21030
+ }
21031
+ }
21032
+ request.streamCallbacks?.onLlmCallEnd?.(modelId, callDelta);
21033
+ }
20981
21034
  }
21035
+ break;
21036
+ }
21037
+ case "tool_execution_start": {
21038
+ toolTrackers.set(event.toolCallId, {
21039
+ toolCallId: event.toolCallId,
21040
+ toolName: event.toolName,
21041
+ args: event.args,
21042
+ startMs: Date.now(),
21043
+ startTime: (/* @__PURE__ */ new Date()).toISOString()
21044
+ });
21045
+ request.streamCallbacks?.onToolCallStart?.(event.toolName, event.toolCallId);
21046
+ break;
21047
+ }
21048
+ case "tool_execution_end": {
21049
+ const tracker = toolTrackers.get(event.toolCallId);
21050
+ const durationMs = tracker ? Date.now() - tracker.startMs : 0;
21051
+ completedToolResults.set(event.toolCallId, {
21052
+ output: event.result,
21053
+ durationMs
21054
+ });
21055
+ request.streamCallbacks?.onToolCallEnd?.(
21056
+ event.toolName,
21057
+ tracker?.args,
21058
+ event.result,
21059
+ durationMs,
21060
+ event.toolCallId
21061
+ );
21062
+ toolTrackers.delete(event.toolCallId);
21063
+ break;
20982
21064
  }
20983
21065
  }
20984
21066
  });
@@ -20997,10 +21079,12 @@ var PiAgentSdkProvider = class {
20997
21079
  }
20998
21080
  await agent.waitForIdle();
20999
21081
  const agentMessages = agent.state.messages;
21082
+ const output = [];
21000
21083
  for (const msg of agentMessages) {
21001
- output.push(convertAgentMessage(msg));
21084
+ output.push(convertAgentMessage(msg, toolTrackers, completedToolResults));
21002
21085
  }
21003
- const durationMs = Date.now() - startTime;
21086
+ const endTimeIso = (/* @__PURE__ */ new Date()).toISOString();
21087
+ const durationMs = Date.now() - startMs;
21004
21088
  return {
21005
21089
  raw: {
21006
21090
  messages: agentMessages,
@@ -21009,49 +21093,54 @@ var PiAgentSdkProvider = class {
21009
21093
  provider: this.config.provider
21010
21094
  },
21011
21095
  output,
21012
- durationMs
21096
+ tokenUsage,
21097
+ costUsd,
21098
+ durationMs,
21099
+ startTime: startTimeIso,
21100
+ endTime: endTimeIso
21013
21101
  };
21014
21102
  } finally {
21015
21103
  unsubscribe();
21016
21104
  }
21017
21105
  }
21018
21106
  };
21019
- function extractTextContent3(content) {
21020
- if (typeof content === "string") {
21021
- return content;
21022
- }
21023
- if (!Array.isArray(content)) {
21024
- return void 0;
21025
- }
21026
- const textParts = [];
21027
- for (const part of content) {
21028
- if (!part || typeof part !== "object") {
21029
- continue;
21030
- }
21031
- const p = part;
21032
- if (p.type === "text" && typeof p.text === "string") {
21033
- textParts.push(p.text);
21034
- }
21035
- }
21036
- return textParts.length > 0 ? textParts.join("\n") : void 0;
21037
- }
21038
- function convertAgentMessage(message) {
21107
+ function convertAgentMessage(message, toolTrackers, completedToolResults) {
21039
21108
  if (!message || typeof message !== "object") {
21040
21109
  return { role: "unknown", content: String(message) };
21041
21110
  }
21042
21111
  const msg = message;
21043
21112
  const role = typeof msg.role === "string" ? msg.role : "unknown";
21044
- const content = extractTextContent3(msg.content);
21045
- const toolCalls = extractToolCalls3(msg.content);
21113
+ const content = extractPiTextContent(msg.content);
21114
+ const toolCalls = extractToolCalls3(msg.content, toolTrackers, completedToolResults);
21046
21115
  const startTime = typeof msg.timestamp === "number" ? new Date(msg.timestamp).toISOString() : typeof msg.timestamp === "string" ? msg.timestamp : void 0;
21116
+ let msgTokenUsage;
21117
+ if (msg.usage && typeof msg.usage === "object") {
21118
+ const u = msg.usage;
21119
+ const input = toFiniteNumber(u.input);
21120
+ const output = toFiniteNumber(u.output);
21121
+ if (input !== void 0 || output !== void 0) {
21122
+ msgTokenUsage = {
21123
+ input: input ?? 0,
21124
+ output: output ?? 0,
21125
+ ...toFiniteNumber(u.cacheRead) !== void 0 ? { cached: toFiniteNumber(u.cacheRead) } : {}
21126
+ };
21127
+ }
21128
+ }
21129
+ const metadata = {};
21130
+ if (msg.api) metadata.api = msg.api;
21131
+ if (msg.provider) metadata.provider = msg.provider;
21132
+ if (msg.model) metadata.model = msg.model;
21133
+ if (msg.stopReason) metadata.stopReason = msg.stopReason;
21047
21134
  return {
21048
21135
  role,
21049
21136
  content,
21050
21137
  toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
21051
- startTime
21138
+ startTime,
21139
+ metadata: Object.keys(metadata).length > 0 ? metadata : void 0,
21140
+ tokenUsage: msgTokenUsage
21052
21141
  };
21053
21142
  }
21054
- function extractToolCalls3(content) {
21143
+ function extractToolCalls3(content, toolTrackers, completedToolResults) {
21055
21144
  if (!Array.isArray(content)) {
21056
21145
  return [];
21057
21146
  }
@@ -21062,10 +21151,17 @@ function extractToolCalls3(content) {
21062
21151
  }
21063
21152
  const p = part;
21064
21153
  if (p.type === "toolCall" && typeof p.name === "string") {
21154
+ const id = typeof p.id === "string" ? p.id : void 0;
21155
+ const tracker = id ? toolTrackers.get(id) : void 0;
21156
+ const completed = id ? completedToolResults.get(id) : void 0;
21065
21157
  toolCalls.push({
21066
21158
  tool: p.name,
21067
21159
  input: p.arguments,
21068
- id: typeof p.id === "string" ? p.id : void 0
21160
+ id,
21161
+ output: completed?.output,
21162
+ durationMs: completed?.durationMs,
21163
+ startTime: tracker?.startTime,
21164
+ endTime: tracker?.startTime && completed?.durationMs !== void 0 ? new Date(new Date(tracker.startTime).getTime() + completed.durationMs).toISOString() : void 0
21069
21165
  });
21070
21166
  }
21071
21167
  }
@@ -21597,14 +21693,14 @@ function extractTokenUsage(events) {
21597
21693
  const usage = record.usage;
21598
21694
  if (usage && typeof usage === "object") {
21599
21695
  const u = usage;
21600
- const input = toNumber(u.input_tokens ?? u.inputTokens ?? u.input);
21601
- const output = toNumber(u.output_tokens ?? u.outputTokens ?? u.output);
21696
+ const input = toFiniteNumber(u.input_tokens ?? u.inputTokens ?? u.input);
21697
+ const output = toFiniteNumber(u.output_tokens ?? u.outputTokens ?? u.output);
21602
21698
  if (input !== void 0 || output !== void 0) {
21603
21699
  const result = {
21604
21700
  input: input ?? 0,
21605
21701
  output: output ?? 0
21606
21702
  };
21607
- const cached = toNumber(u.cache_read_input_tokens ?? u.cached ?? u.cachedTokens);
21703
+ const cached = toFiniteNumber(u.cache_read_input_tokens ?? u.cached ?? u.cachedTokens);
21608
21704
  if (cached !== void 0) {
21609
21705
  return { ...result, cached };
21610
21706
  }
@@ -21629,13 +21725,13 @@ function aggregateUsageFromMessages(messages) {
21629
21725
  const usage = m.usage;
21630
21726
  if (!usage || typeof usage !== "object") continue;
21631
21727
  const u = usage;
21632
- const input = toNumber(u.input_tokens ?? u.inputTokens ?? u.input);
21633
- const output = toNumber(u.output_tokens ?? u.outputTokens ?? u.output);
21728
+ const input = toFiniteNumber(u.input_tokens ?? u.inputTokens ?? u.input);
21729
+ const output = toFiniteNumber(u.output_tokens ?? u.outputTokens ?? u.output);
21634
21730
  if (input !== void 0 || output !== void 0) {
21635
21731
  found = true;
21636
21732
  totalInput += input ?? 0;
21637
21733
  totalOutput += output ?? 0;
21638
- const cached = toNumber(u.cache_read_input_tokens ?? u.cached ?? u.cachedTokens);
21734
+ const cached = toFiniteNumber(u.cache_read_input_tokens ?? u.cached ?? u.cachedTokens);
21639
21735
  if (cached !== void 0) {
21640
21736
  totalCached = (totalCached ?? 0) + cached;
21641
21737
  }
@@ -21648,10 +21744,6 @@ function aggregateUsageFromMessages(messages) {
21648
21744
  }
21649
21745
  return result;
21650
21746
  }
21651
- function toNumber(value) {
21652
- if (typeof value === "number" && Number.isFinite(value)) return value;
21653
- return void 0;
21654
- }
21655
21747
  function convertPiMessage(message) {
21656
21748
  if (!message || typeof message !== "object") {
21657
21749
  return void 0;
@@ -21661,7 +21753,7 @@ function convertPiMessage(message) {
21661
21753
  if (typeof role !== "string") {
21662
21754
  return void 0;
21663
21755
  }
21664
- const content = extractTextContent4(msg.content);
21756
+ const content = extractPiTextContent(msg.content);
21665
21757
  const toolCalls = extractToolCalls4(msg.content);
21666
21758
  const startTime = typeof msg.timestamp === "number" ? new Date(msg.timestamp).toISOString() : typeof msg.timestamp === "string" ? msg.timestamp : void 0;
21667
21759
  const metadata = {};
@@ -21678,25 +21770,6 @@ function convertPiMessage(message) {
21678
21770
  metadata: Object.keys(metadata).length > 0 ? metadata : void 0
21679
21771
  };
21680
21772
  }
21681
- function extractTextContent4(content) {
21682
- if (typeof content === "string") {
21683
- return content;
21684
- }
21685
- if (!Array.isArray(content)) {
21686
- return void 0;
21687
- }
21688
- const textParts = [];
21689
- for (const part of content) {
21690
- if (!part || typeof part !== "object") {
21691
- continue;
21692
- }
21693
- const p = part;
21694
- if (p.type === "text" && typeof p.text === "string") {
21695
- textParts.push(p.text);
21696
- }
21697
- }
21698
- return textParts.length > 0 ? textParts.join("\n") : void 0;
21699
- }
21700
21773
  function extractToolCalls4(content) {
21701
21774
  if (!Array.isArray(content)) {
21702
21775
  return [];
@@ -25709,8 +25782,8 @@ var FieldAccuracyEvaluator = class {
25709
25782
  */
25710
25783
  compareNumericTolerance(path46, candidateValue, expectedValue, fieldConfig, weight) {
25711
25784
  const { tolerance = 0, relative = false } = fieldConfig;
25712
- const candidateNum = toNumber2(candidateValue);
25713
- const expectedNum = toNumber2(expectedValue);
25785
+ const candidateNum = toNumber(candidateValue);
25786
+ const expectedNum = toNumber(expectedValue);
25714
25787
  if (candidateNum === null || expectedNum === null) {
25715
25788
  return {
25716
25789
  path: path46,
@@ -25856,7 +25929,7 @@ function resolvePath(obj, path46) {
25856
25929
  }
25857
25930
  return current;
25858
25931
  }
25859
- function toNumber2(value) {
25932
+ function toNumber(value) {
25860
25933
  if (typeof value === "number") {
25861
25934
  return value;
25862
25935
  }
@@ -28744,7 +28817,9 @@ async function runEvaluation(options) {
28744
28817
  testId: evalCase.id,
28745
28818
  status: "failed",
28746
28819
  completedAt: Date.now(),
28747
- error: budgetResult.error
28820
+ error: budgetResult.error,
28821
+ score: budgetResult.score,
28822
+ executionStatus: budgetResult.executionStatus
28748
28823
  });
28749
28824
  }
28750
28825
  if (onResult) {
@@ -28775,7 +28850,9 @@ async function runEvaluation(options) {
28775
28850
  testId: evalCase.id,
28776
28851
  status: "failed",
28777
28852
  completedAt: Date.now(),
28778
- error: haltResult.error
28853
+ error: haltResult.error,
28854
+ score: haltResult.score,
28855
+ executionStatus: haltResult.executionStatus
28779
28856
  });
28780
28857
  }
28781
28858
  if (onResult) {
@@ -28855,7 +28932,9 @@ async function runEvaluation(options) {
28855
28932
  startedAt: 0,
28856
28933
  // Not used for completed status
28857
28934
  completedAt: Date.now(),
28858
- error: result.error
28935
+ error: result.error,
28936
+ score: result.score,
28937
+ executionStatus: result.executionStatus
28859
28938
  });
28860
28939
  }
28861
28940
  if (onResult) {
@@ -29026,7 +29105,9 @@ async function runBatchEvaluation(options) {
29026
29105
  const merged = computed ? mergeExecutionMetrics(computed, {
29027
29106
  tokenUsage: providerResponse.tokenUsage,
29028
29107
  costUsd: providerResponse.costUsd,
29029
- durationMs: providerResponse.durationMs
29108
+ durationMs: providerResponse.durationMs,
29109
+ startTime: providerResponse.startTime,
29110
+ endTime: providerResponse.endTime
29030
29111
  }) : void 0;
29031
29112
  const trace2 = merged?.trace;
29032
29113
  const costUsd = merged?.costUsd;
@@ -29091,7 +29172,9 @@ async function runBatchEvaluation(options) {
29091
29172
  testId: evalCase.id,
29092
29173
  status: "failed",
29093
29174
  completedAt: Date.now(),
29094
- error: error instanceof Error ? error.message : String(error)
29175
+ error: error instanceof Error ? error.message : String(error),
29176
+ score: errorResult.score,
29177
+ executionStatus: errorResult.executionStatus
29095
29178
  });
29096
29179
  }
29097
29180
  continue;
@@ -29107,7 +29190,9 @@ async function runBatchEvaluation(options) {
29107
29190
  status: result.error ? "failed" : "completed",
29108
29191
  startedAt: 0,
29109
29192
  completedAt: Date.now(),
29110
- error: result.error
29193
+ error: result.error,
29194
+ score: result.score,
29195
+ executionStatus: result.executionStatus
29111
29196
  });
29112
29197
  }
29113
29198
  }
@@ -29417,7 +29502,9 @@ async function runEvalCase(options) {
29417
29502
  const merged = computed ? mergeExecutionMetrics(computed, {
29418
29503
  tokenUsage: providerResponse.tokenUsage,
29419
29504
  costUsd: providerResponse.costUsd,
29420
- durationMs: providerResponse.durationMs
29505
+ durationMs: providerResponse.durationMs,
29506
+ startTime: providerResponse.startTime,
29507
+ endTime: providerResponse.endTime
29421
29508
  }) : void 0;
29422
29509
  const trace2 = merged?.trace;
29423
29510
  const costUsd = merged?.costUsd;
@@ -31203,4 +31290,4 @@ export {
31203
31290
  OtelStreamingObserver,
31204
31291
  createAgentKernel
31205
31292
  };
31206
- //# sourceMappingURL=chunk-5M3K2DMV.js.map
31293
+ //# sourceMappingURL=chunk-GOZV2HN2.js.map