@google/adk 2.4.0 → 2.5.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.
Files changed (326) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +17 -2
  2. package/dist/cjs/a2a/a2a_remote_agent_utils.js +8 -4
  3. package/dist/cjs/a2a/agent_card.js +5 -81
  4. package/dist/cjs/a2a/agent_to_a2a.js +7 -0
  5. package/dist/cjs/a2a/event_converter_utils.js +10 -3
  6. package/dist/cjs/agents/agent_engine_client.js +282 -55
  7. package/dist/cjs/agents/base_agent.js +111 -68
  8. package/dist/cjs/agents/functions.js +62 -85
  9. package/dist/cjs/agents/instructions.js +7 -6
  10. package/dist/cjs/agents/invocation_context.js +2 -2
  11. package/dist/cjs/agents/llm_agent.js +105 -95
  12. package/dist/cjs/agents/processors/content_processor_utils.js +42 -15
  13. package/dist/cjs/agents/processors/content_request_processor.js +28 -11
  14. package/dist/cjs/agents/processors/context_compactor_request_processor.js +5 -1
  15. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
  16. package/dist/cjs/agents/processors/nl_planning_processor.js +2 -1
  17. package/dist/cjs/artifacts/file_artifact_service.js +1 -1
  18. package/dist/cjs/cli/cli_eval.js +884 -17
  19. package/dist/cjs/cli/utils/cleanup.js +84 -0
  20. package/dist/cjs/cli/utils/envs.js +33 -2
  21. package/dist/cjs/cli/utils/evals.js +75 -8
  22. package/dist/cjs/cli/utils/logs.js +128 -9
  23. package/dist/cjs/cli/utils/path_validation.js +83 -0
  24. package/dist/cjs/code_executors/container_code_executor.js +158 -36
  25. package/dist/cjs/common.js +50 -12
  26. package/dist/cjs/context/compaction_utils.js +19 -0
  27. package/dist/cjs/events/event.js +7 -3
  28. package/dist/cjs/features/feature_registry.js +5 -0
  29. package/dist/cjs/index.js +29 -14
  30. package/dist/cjs/models/google_llm.js +33 -2
  31. package/dist/cjs/models/interactions_utils.js +3 -0
  32. package/dist/cjs/plugins/base_plugin.js +45 -21
  33. package/dist/cjs/plugins/plugin_manager.js +27 -0
  34. package/dist/cjs/runner/runner.js +306 -189
  35. package/dist/cjs/sessions/base_session_service.js +1 -4
  36. package/dist/cjs/sessions/database_session_service.js +191 -19
  37. package/dist/cjs/sessions/db/operations.js +70 -1
  38. package/dist/cjs/sessions/db/schema.js +4 -0
  39. package/dist/cjs/sessions/in_memory_session_service.js +2 -2
  40. package/dist/cjs/sessions/vertex_ai_session_service.js +11 -3
  41. package/dist/cjs/skills/loader.js +29 -28
  42. package/dist/cjs/telemetry/api/instrumentation.js +632 -0
  43. package/dist/cjs/telemetry/api/internal/common/accumulators.js +169 -0
  44. package/dist/cjs/telemetry/api/internal/common/attributes.js +131 -0
  45. package/dist/cjs/telemetry/api/internal/common/config.js +159 -0
  46. package/dist/cjs/telemetry/api/internal/common/error.js +98 -0
  47. package/dist/cjs/telemetry/api/internal/common/finish_reason.js +63 -0
  48. package/dist/cjs/telemetry/api/internal/common/genai_messages.js +217 -0
  49. package/dist/cjs/telemetry/api/internal/common/http_exchange.js +169 -0
  50. package/dist/cjs/telemetry/api/internal/common/provider_name.js +87 -0
  51. package/dist/cjs/telemetry/api/internal/common/redaction.js +148 -0
  52. package/dist/cjs/telemetry/api/internal/common/serialization.js +58 -0
  53. package/dist/cjs/telemetry/api/internal/common/token_usage.js +118 -0
  54. package/dist/cjs/telemetry/api/internal/logs/inference.js +50 -0
  55. package/dist/cjs/telemetry/api/internal/logs/logger.js +46 -0
  56. package/dist/cjs/telemetry/api/internal/logs/mcp.js +141 -0
  57. package/dist/cjs/telemetry/api/internal/metrics/agent.js +128 -0
  58. package/dist/cjs/telemetry/api/internal/metrics/inference_start_hook.js +56 -0
  59. package/dist/cjs/telemetry/api/internal/metrics/meters.js +189 -0
  60. package/dist/cjs/telemetry/api/internal/metrics/tool.js +147 -0
  61. package/dist/cjs/telemetry/api/internal/metrics/workflow.js +132 -0
  62. package/dist/cjs/telemetry/api/internal/trace/agent.js +52 -0
  63. package/dist/cjs/telemetry/api/internal/trace/compaction.js +78 -0
  64. package/dist/cjs/telemetry/api/internal/trace/inference.js +132 -0
  65. package/dist/cjs/telemetry/api/internal/trace/live.js +52 -0
  66. package/dist/cjs/telemetry/api/internal/trace/node.js +73 -0
  67. package/dist/cjs/telemetry/api/internal/trace/propagation.js +67 -0
  68. package/dist/cjs/telemetry/api/internal/trace/tool.js +122 -0
  69. package/dist/cjs/telemetry/api/internal/trace/tracer.js +77 -0
  70. package/dist/cjs/telemetry/api/internal/trace/workflow.js +77 -0
  71. package/dist/cjs/telemetry/export/agent_engine.js +90 -0
  72. package/dist/cjs/telemetry/export/agent_runtime.js +73 -0
  73. package/dist/cjs/telemetry/export/google_cloud.js +763 -0
  74. package/dist/cjs/telemetry/export/request_driven_metric_reader.js +303 -0
  75. package/dist/cjs/telemetry/{setup.js → export/setup.js} +72 -5
  76. package/dist/cjs/tools/agent_tool.js +9 -1
  77. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +22 -34
  78. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +60 -20
  79. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +26 -10
  80. package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +14 -23
  81. package/dist/cjs/tools/base_toolset.js +1 -1
  82. package/dist/cjs/tools/computer_use/base_computer.js +125 -0
  83. package/dist/cjs/tools/computer_use/computer_use_actions.js +502 -0
  84. package/dist/cjs/tools/computer_use/computer_use_tool.js +244 -0
  85. package/dist/cjs/tools/computer_use/computer_use_toolset.js +360 -0
  86. package/dist/cjs/tools/function_tool.js +15 -5
  87. package/dist/cjs/tools/google_api_tool/google_api_toolset.js +3 -2
  88. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +3 -1
  89. package/dist/cjs/tools/load_artifacts_tool.js +15 -5
  90. package/dist/cjs/tools/load_memory_tool.js +2 -5
  91. package/dist/cjs/tools/mcp/mcp_session_manager.js +23 -3
  92. package/dist/cjs/tools/mcp/mcp_tool.js +7 -3
  93. package/dist/cjs/tools/mcp/mcp_toolset.js +18 -6
  94. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +30 -29
  95. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
  96. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +45 -14
  97. package/dist/cjs/tools/skill/load_skill_resource_tool.js +7 -0
  98. package/dist/cjs/tools/skill/load_skill_tool.js +3 -0
  99. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -2
  100. package/dist/cjs/tools/toolbox_toolset.js +47 -28
  101. package/dist/cjs/utils/async_queue.js +37 -3
  102. package/dist/cjs/utils/client_labels.js +9 -11
  103. package/dist/cjs/utils/env_aware_utils.js +13 -7
  104. package/dist/cjs/utils/error_utils.js +40 -2
  105. package/dist/cjs/utils/failover_utils.js +10 -9
  106. package/dist/cjs/utils/gemini_schema_util.js +125 -12
  107. package/dist/cjs/utils/id_provider.js +63 -0
  108. package/dist/cjs/utils/model_name.js +15 -0
  109. package/dist/cjs/utils/simple_zod_to_json.js +13 -31
  110. package/dist/cjs/utils/ssrf_guard.js +46 -16
  111. package/dist/cjs/version.js +1 -1
  112. package/dist/cjs/workflow/index.js +2 -0
  113. package/dist/cjs/workflow/node_runner.js +24 -80
  114. package/dist/cjs/workflow/nodes/parallel_worker.js +18 -7
  115. package/dist/cjs/workflow/run_llm_agent_as_node.js +19 -14
  116. package/dist/cjs/workflow/utils/retry_utils.js +2 -2
  117. package/dist/cjs/workflow/workflow.js +12 -12
  118. package/dist/esm/a2a/a2a_remote_agent.js +23 -3
  119. package/dist/esm/a2a/a2a_remote_agent_utils.js +8 -4
  120. package/dist/esm/a2a/agent_card.js +5 -83
  121. package/dist/esm/a2a/agent_to_a2a.js +7 -0
  122. package/dist/esm/a2a/event_converter_utils.js +10 -3
  123. package/dist/esm/agents/agent_engine_client.js +293 -55
  124. package/dist/esm/agents/base_agent.js +111 -72
  125. package/dist/esm/agents/functions.js +67 -89
  126. package/dist/esm/agents/instructions.js +7 -6
  127. package/dist/esm/agents/invocation_context.js +2 -2
  128. package/dist/esm/agents/llm_agent.js +111 -100
  129. package/dist/esm/agents/processors/content_processor_utils.js +42 -15
  130. package/dist/esm/agents/processors/content_request_processor.js +28 -11
  131. package/dist/esm/agents/processors/context_compactor_request_processor.js +5 -1
  132. package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
  133. package/dist/esm/agents/processors/nl_planning_processor.js +2 -1
  134. package/dist/esm/artifacts/file_artifact_service.js +1 -1
  135. package/dist/esm/cli/cli_eval.js +880 -17
  136. package/dist/esm/cli/utils/cleanup.js +56 -0
  137. package/dist/esm/cli/utils/envs.js +33 -2
  138. package/dist/esm/cli/utils/evals.js +74 -8
  139. package/dist/esm/cli/utils/logs.js +128 -9
  140. package/dist/esm/cli/utils/path_validation.js +45 -0
  141. package/dist/esm/code_executors/container_code_executor.js +158 -36
  142. package/dist/esm/common.js +49 -6
  143. package/dist/esm/context/compaction_utils.js +19 -0
  144. package/dist/esm/events/event.js +7 -3
  145. package/dist/esm/features/feature_registry.js +5 -0
  146. package/dist/esm/index.js +27 -15
  147. package/dist/esm/models/google_llm.js +33 -2
  148. package/dist/esm/models/interactions_utils.js +3 -0
  149. package/dist/esm/plugins/base_plugin.js +45 -21
  150. package/dist/esm/plugins/plugin_manager.js +27 -0
  151. package/dist/esm/runner/runner.js +310 -192
  152. package/dist/esm/sessions/base_session_service.js +1 -4
  153. package/dist/esm/sessions/database_session_service.js +191 -19
  154. package/dist/esm/sessions/db/operations.js +70 -1
  155. package/dist/esm/sessions/db/schema.js +4 -0
  156. package/dist/esm/sessions/in_memory_session_service.js +2 -2
  157. package/dist/esm/sessions/vertex_ai_session_service.js +11 -3
  158. package/dist/esm/skills/loader.js +29 -28
  159. package/dist/esm/telemetry/api/instrumentation.js +655 -0
  160. package/dist/esm/telemetry/api/internal/common/accumulators.js +139 -0
  161. package/dist/esm/telemetry/api/internal/common/attributes.js +94 -0
  162. package/dist/esm/telemetry/api/internal/common/config.js +128 -0
  163. package/dist/esm/telemetry/api/internal/common/error.js +69 -0
  164. package/dist/esm/telemetry/api/internal/common/finish_reason.js +35 -0
  165. package/dist/esm/telemetry/api/internal/common/genai_messages.js +188 -0
  166. package/dist/esm/telemetry/api/internal/common/http_exchange.js +142 -0
  167. package/dist/esm/telemetry/api/internal/common/provider_name.js +59 -0
  168. package/dist/esm/telemetry/api/internal/common/redaction.js +121 -0
  169. package/dist/esm/telemetry/api/internal/common/serialization.js +30 -0
  170. package/dist/esm/telemetry/api/internal/common/token_usage.js +85 -0
  171. package/dist/esm/telemetry/api/internal/logs/inference.js +23 -0
  172. package/dist/esm/telemetry/api/internal/logs/logger.js +19 -0
  173. package/dist/esm/telemetry/api/internal/logs/mcp.js +113 -0
  174. package/dist/esm/telemetry/api/internal/metrics/agent.js +107 -0
  175. package/dist/esm/telemetry/api/internal/metrics/inference_start_hook.js +29 -0
  176. package/dist/esm/telemetry/api/internal/metrics/meters.js +165 -0
  177. package/dist/esm/telemetry/api/internal/metrics/tool.js +119 -0
  178. package/dist/esm/telemetry/api/internal/metrics/workflow.js +112 -0
  179. package/dist/esm/telemetry/api/internal/trace/agent.js +25 -0
  180. package/dist/esm/telemetry/api/internal/trace/compaction.js +50 -0
  181. package/dist/esm/telemetry/api/internal/trace/inference.js +107 -0
  182. package/dist/esm/telemetry/api/internal/trace/live.js +28 -0
  183. package/dist/esm/telemetry/api/internal/trace/node.js +44 -0
  184. package/dist/esm/telemetry/api/internal/trace/propagation.js +39 -0
  185. package/dist/esm/telemetry/api/internal/trace/tool.js +96 -0
  186. package/dist/esm/telemetry/api/internal/trace/tracer.js +52 -0
  187. package/dist/esm/telemetry/api/internal/trace/workflow.js +54 -0
  188. package/dist/esm/telemetry/export/agent_engine.js +67 -0
  189. package/dist/esm/telemetry/export/agent_runtime.js +46 -0
  190. package/dist/esm/telemetry/export/google_cloud.js +733 -0
  191. package/dist/esm/telemetry/export/request_driven_metric_reader.js +276 -0
  192. package/dist/esm/telemetry/export/setup.js +160 -0
  193. package/dist/esm/tools/agent_tool.js +9 -1
  194. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +23 -35
  195. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +64 -21
  196. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +26 -10
  197. package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +14 -23
  198. package/dist/esm/tools/base_toolset.js +1 -1
  199. package/dist/esm/tools/computer_use/base_computer.js +99 -0
  200. package/dist/esm/tools/computer_use/computer_use_actions.js +477 -0
  201. package/dist/esm/tools/computer_use/computer_use_tool.js +217 -0
  202. package/dist/esm/tools/computer_use/computer_use_toolset.js +344 -0
  203. package/dist/esm/tools/function_tool.js +15 -5
  204. package/dist/esm/tools/google_api_tool/google_api_toolset.js +3 -2
  205. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +3 -1
  206. package/dist/esm/tools/load_artifacts_tool.js +15 -5
  207. package/dist/esm/tools/load_memory_tool.js +2 -5
  208. package/dist/esm/tools/mcp/mcp_session_manager.js +23 -3
  209. package/dist/esm/tools/mcp/mcp_tool.js +7 -3
  210. package/dist/esm/tools/mcp/mcp_toolset.js +18 -6
  211. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +27 -26
  212. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
  213. package/dist/esm/tools/openapi_tool/rest_api_tool.js +45 -14
  214. package/dist/esm/tools/skill/load_skill_resource_tool.js +7 -0
  215. package/dist/esm/tools/skill/load_skill_tool.js +3 -0
  216. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -2
  217. package/dist/esm/tools/toolbox_toolset.js +47 -28
  218. package/dist/esm/utils/async_queue.js +37 -3
  219. package/dist/esm/utils/client_labels.js +9 -11
  220. package/dist/esm/utils/env_aware_utils.js +12 -7
  221. package/dist/esm/utils/error_utils.js +37 -1
  222. package/dist/esm/utils/failover_utils.js +10 -9
  223. package/dist/esm/utils/gemini_schema_util.js +124 -11
  224. package/dist/esm/utils/id_provider.js +33 -0
  225. package/dist/esm/utils/model_name.js +14 -0
  226. package/dist/esm/utils/simple_zod_to_json.js +13 -31
  227. package/dist/esm/utils/ssrf_guard.js +55 -15
  228. package/dist/esm/version.js +1 -1
  229. package/dist/esm/workflow/index.js +2 -1
  230. package/dist/esm/workflow/node_runner.js +26 -80
  231. package/dist/esm/workflow/nodes/parallel_worker.js +16 -6
  232. package/dist/esm/workflow/run_llm_agent_as_node.js +19 -14
  233. package/dist/esm/workflow/utils/retry_utils.js +2 -2
  234. package/dist/esm/workflow/workflow.js +12 -12
  235. package/dist/types/a2a/a2a_remote_agent.d.ts +6 -0
  236. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +3 -2
  237. package/dist/types/agents/agent_engine_client.d.ts +121 -3
  238. package/dist/types/agents/base_agent.d.ts +2 -0
  239. package/dist/types/agents/processors/content_processor_utils.d.ts +9 -9
  240. package/dist/types/agents/run_config.d.ts +14 -0
  241. package/dist/types/cli/cli_eval.d.ts +172 -9
  242. package/dist/types/cli/utils/cleanup.d.ts +18 -0
  243. package/dist/types/cli/utils/envs.d.ts +13 -3
  244. package/dist/types/cli/utils/evals.d.ts +64 -1
  245. package/dist/types/cli/utils/logs.d.ts +19 -2
  246. package/dist/types/cli/utils/path_validation.d.ts +30 -0
  247. package/dist/types/code_executors/container_code_executor.d.ts +49 -8
  248. package/dist/types/common.d.ts +16 -9
  249. package/dist/types/context/compaction_utils.d.ts +13 -1
  250. package/dist/types/events/event.d.ts +3 -0
  251. package/dist/types/features/feature_registry.d.ts +1 -0
  252. package/dist/types/index.d.ts +9 -6
  253. package/dist/types/plugins/base_plugin.d.ts +50 -21
  254. package/dist/types/plugins/plugin_manager.d.ts +13 -0
  255. package/dist/types/runner/runner.d.ts +11 -0
  256. package/dist/types/sessions/base_session_service.d.ts +0 -2
  257. package/dist/types/sessions/db/operations.d.ts +2 -1
  258. package/dist/types/sessions/db/schema.d.ts +5 -3
  259. package/dist/types/telemetry/api/instrumentation.d.ts +259 -0
  260. package/dist/types/telemetry/api/internal/common/accumulators.d.ts +91 -0
  261. package/dist/types/telemetry/api/internal/common/attributes.d.ts +90 -0
  262. package/dist/types/telemetry/api/internal/common/config.d.ts +61 -0
  263. package/dist/types/telemetry/api/internal/common/error.d.ts +29 -0
  264. package/dist/types/telemetry/api/internal/common/finish_reason.d.ts +18 -0
  265. package/dist/types/telemetry/api/internal/common/genai_messages.d.ts +26 -0
  266. package/dist/types/telemetry/api/internal/common/http_exchange.d.ts +50 -0
  267. package/dist/types/telemetry/api/internal/common/provider_name.d.ts +16 -0
  268. package/dist/types/telemetry/api/internal/common/redaction.d.ts +14 -0
  269. package/dist/types/telemetry/api/internal/common/serialization.d.ts +18 -0
  270. package/dist/types/telemetry/api/internal/common/token_usage.d.ts +47 -0
  271. package/dist/types/telemetry/api/internal/logs/inference.d.ts +15 -0
  272. package/dist/types/telemetry/api/internal/logs/logger.d.ts +13 -0
  273. package/dist/types/telemetry/api/internal/logs/mcp.d.ts +31 -0
  274. package/dist/types/telemetry/api/internal/metrics/agent.d.ts +28 -0
  275. package/dist/types/telemetry/api/internal/metrics/inference_start_hook.d.ts +12 -0
  276. package/dist/types/telemetry/api/internal/metrics/meters.d.ts +57 -0
  277. package/dist/types/telemetry/api/internal/metrics/tool.d.ts +44 -0
  278. package/dist/types/telemetry/api/internal/metrics/workflow.d.ts +32 -0
  279. package/dist/types/telemetry/api/internal/trace/agent.d.ts +14 -0
  280. package/dist/types/telemetry/api/internal/trace/compaction.d.ts +20 -0
  281. package/dist/types/telemetry/api/internal/trace/inference.d.ts +31 -0
  282. package/dist/types/telemetry/api/internal/trace/live.d.ts +21 -0
  283. package/dist/types/telemetry/api/internal/trace/node.d.ts +22 -0
  284. package/dist/types/telemetry/api/internal/trace/propagation.d.ts +22 -0
  285. package/dist/types/telemetry/api/internal/trace/tool.d.ts +57 -0
  286. package/dist/types/telemetry/api/internal/trace/tracer.d.ts +31 -0
  287. package/dist/types/telemetry/api/internal/trace/workflow.d.ts +21 -0
  288. package/dist/types/telemetry/export/agent_engine.d.ts +23 -0
  289. package/dist/types/telemetry/export/agent_runtime.d.ts +40 -0
  290. package/dist/types/telemetry/export/google_cloud.d.ts +189 -0
  291. package/dist/types/telemetry/export/request_driven_metric_reader.d.ts +144 -0
  292. package/dist/types/telemetry/{setup.d.ts → export/setup.d.ts} +3 -0
  293. package/dist/types/tools/agent_tool.d.ts +1 -1
  294. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +13 -4
  295. package/dist/types/tools/base_toolset.d.ts +1 -1
  296. package/dist/types/tools/computer_use/base_computer.d.ts +281 -0
  297. package/dist/types/tools/computer_use/computer_use_actions.d.ts +53 -0
  298. package/dist/types/tools/computer_use/computer_use_tool.d.ts +108 -0
  299. package/dist/types/tools/computer_use/computer_use_toolset.d.ts +132 -0
  300. package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +2 -0
  301. package/dist/types/tools/load_artifacts_tool.d.ts +5 -1
  302. package/dist/types/tools/load_memory_tool.d.ts +13 -7
  303. package/dist/types/tools/mcp/mcp_session_manager.d.ts +16 -0
  304. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +8 -8
  305. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +7 -3
  306. package/dist/types/tools/toolbox_toolset.d.ts +15 -20
  307. package/dist/types/utils/async_queue.d.ts +14 -0
  308. package/dist/types/utils/env_aware_utils.d.ts +11 -0
  309. package/dist/types/utils/error_utils.d.ts +4 -0
  310. package/dist/types/utils/gemini_schema_util.d.ts +27 -6
  311. package/dist/types/utils/id_provider.d.ts +43 -0
  312. package/dist/types/utils/model_name.d.ts +8 -0
  313. package/dist/types/utils/ssrf_guard.d.ts +2 -0
  314. package/dist/types/version.d.ts +1 -1
  315. package/dist/types/workflow/index.d.ts +1 -1
  316. package/dist/types/workflow/nodes/parallel_worker.d.ts +8 -1
  317. package/dist/web/index_web.js +86 -88
  318. package/dist/web/index_web.js.map +4 -4
  319. package/package.json +13 -15
  320. package/dist/cjs/telemetry/google_cloud.js +0 -116
  321. package/dist/cjs/telemetry/tracing.js +0 -393
  322. package/dist/esm/telemetry/google_cloud.js +0 -99
  323. package/dist/esm/telemetry/setup.js +0 -88
  324. package/dist/esm/telemetry/tracing.js +0 -361
  325. package/dist/types/telemetry/google_cloud.d.ts +0 -9
  326. package/dist/types/telemetry/tracing.d.ts +0 -143
@@ -38,13 +38,20 @@ __export(cli_eval_exports, {
38
38
  DEFAULT_CRITERIA: () => DEFAULT_CRITERIA,
39
39
  EVAL_SESSION_ID_PREFIX: () => EVAL_SESSION_ID_PREFIX,
40
40
  EvalStatus: () => EvalStatus,
41
+ LocalEvalSetResultsManager: () => LocalEvalSetResultsManager,
42
+ LocalEvalSetsManager: () => LocalEvalSetsManager,
41
43
  MISSING_EVAL_DEPENDENCIES_MESSAGE: () => MISSING_EVAL_DEPENDENCIES_MESSAGE,
42
44
  RESPONSE_EVALUATION_SCORE_KEY: () => RESPONSE_EVALUATION_SCORE_KEY,
43
45
  RESPONSE_MATCH_SCORE_KEY: () => RESPONSE_MATCH_SCORE_KEY,
44
46
  TOOL_TRAJECTORY_SCORE_KEY: () => TOOL_TRAJECTORY_SCORE_KEY,
47
+ convertEvalSetToSchema: () => convertEvalSetToSchema,
48
+ createEvalSetResult: () => createEvalSetResult,
45
49
  getEvaluationCriteriaOrDefault: () => getEvaluationCriteriaOrDefault,
46
50
  getRootAgent: () => getRootAgent,
51
+ loadEvalSetFromFile: () => loadEvalSetFromFile,
52
+ normalizeEvalCase: () => normalizeEvalCase,
47
53
  parseAndGetEvalsToRun: () => parseAndGetEvalsToRun,
54
+ parseEvalSetResultJson: () => parseEvalSetResultJson,
48
55
  runEvals: () => runEvals,
49
56
  tryGetResetFunc: () => tryGetResetFunc
50
57
  });
@@ -56,10 +63,14 @@ var import_node_url = require("node:url");
56
63
  var import_base_agent = require("../agents/base_agent.js");
57
64
  var import_llm_agent = require("../agents/llm_agent.js");
58
65
  var import_in_memory_artifact_service = require("../artifacts/in_memory_artifact_service.js");
66
+ var import_input_validation_error = require("../errors/input_validation_error.js");
67
+ var import_not_found_error = require("../errors/not_found_error.js");
68
+ var import_internal_metadata = require("../events/internal_metadata.js");
59
69
  var import_runner = require("../runner/runner.js");
60
70
  var import_in_memory_session_service = require("../sessions/in_memory_session_service.js");
61
71
  var import_logger = require("../utils/logger.js");
62
72
  var import_evals = require("./utils/evals.js");
73
+ var import_path_validation = require("./utils/path_validation.js");
63
74
  /**
64
75
  * @license
65
76
  * Copyright 2026 Google LLC
@@ -145,8 +156,9 @@ function parseAndGetEvalsToRun(evalSetFilePaths) {
145
156
  for (const inputEvalSet of evalSetFilePaths) {
146
157
  let evalSetFile;
147
158
  let evals = [];
148
- if (inputEvalSet.includes(":")) {
149
- const colonIndex = inputEvalSet.indexOf(":");
159
+ const hasDrivePrefix = /^[A-Za-z]:[\\/]/.test(inputEvalSet);
160
+ const colonIndex = inputEvalSet.indexOf(":", hasDrivePrefix ? 3 : 0);
161
+ if (colonIndex !== -1) {
150
162
  evalSetFile = inputEvalSet.slice(0, colonIndex);
151
163
  evals = inputEvalSet.slice(colonIndex + 1).split(",").filter((s) => s.length > 0);
152
164
  } else {
@@ -293,6 +305,23 @@ function evaluateSingleMetric(metric, actualInvocations, expectedInvocations) {
293
305
  };
294
306
  }
295
307
  __name(evaluateSingleMetric, "evaluateSingleMetric");
308
+ const MOCK_TOOL_OUTPUT_RESPONSE_KEY = "result";
309
+ const declaredToolResponses = /* @__PURE__ */ new WeakMap();
310
+ function getMockToolResponse(toolUse) {
311
+ const declared = declaredToolResponses.get(toolUse);
312
+ if (declared !== void 0) {
313
+ return declared;
314
+ }
315
+ if (toolUse.mock_tool_output !== void 0) {
316
+ return { [MOCK_TOOL_OUTPUT_RESPONSE_KEY]: toolUse.mock_tool_output };
317
+ }
318
+ return void 0;
319
+ }
320
+ __name(getMockToolResponse, "getMockToolResponse");
321
+ function isEvalEntry(evalCase) {
322
+ return "data" in evalCase && Array.isArray(evalCase.data);
323
+ }
324
+ __name(isEvalEntry, "isEvalEntry");
296
325
  function installMockToolOutputCallbacks(agent, interceptor, savedCallbacks) {
297
326
  if ((0, import_llm_agent.isLlmAgent)(agent) && !savedCallbacks.has(agent)) {
298
327
  savedCallbacks.set(agent, agent.beforeToolCallback);
@@ -305,7 +334,7 @@ function installMockToolOutputCallbacks(agent, interceptor, savedCallbacks) {
305
334
  }
306
335
  __name(installMockToolOutputCallbacks, "installMockToolOutputCallbacks");
307
336
  async function generateActualInvocations(rootAgent, evalCase, resetFunc, sessionService, artifactService) {
308
- var _a, _b, _c, _d, _e, _f, _g;
337
+ var _a, _b, _c, _d, _e, _f, _g, _h;
309
338
  if (resetFunc) {
310
339
  await resetFunc();
311
340
  }
@@ -327,8 +356,13 @@ async function generateActualInvocations(rootAgent, evalCase, resetFunc, session
327
356
  const pendingMockToolUses = [];
328
357
  for (const turn of evalCase.data) {
329
358
  for (const expectedTool of (_g = turn.expected_tool_use) != null ? _g : []) {
330
- if (expectedTool.mock_tool_output !== void 0) {
331
- pendingMockToolUses.push({ ...expectedTool });
359
+ const response = getMockToolResponse(expectedTool);
360
+ if (response !== void 0) {
361
+ pendingMockToolUses.push({
362
+ toolName: expectedTool.tool_name,
363
+ toolInput: (_h = expectedTool.tool_input) != null ? _h : {},
364
+ response
365
+ });
332
366
  }
333
367
  }
334
368
  }
@@ -336,14 +370,11 @@ async function generateActualInvocations(rootAgent, evalCase, resetFunc, session
336
370
  if (pendingMockToolUses.length > 0) {
337
371
  const interceptor = /* @__PURE__ */ __name(({ tool, args }) => {
338
372
  const idx = pendingMockToolUses.findIndex(
339
- (expected) => {
340
- var _a2;
341
- return expected.mock_tool_output !== void 0 && tool.name === expected.tool_name && deepEqual(args, (_a2 = expected.tool_input) != null ? _a2 : {});
342
- }
373
+ (expected) => tool.name === expected.toolName && deepEqual(args, expected.toolInput)
343
374
  );
344
375
  if (idx !== -1) {
345
376
  const [matched] = pendingMockToolUses.splice(idx, 1);
346
- return { result: matched.mock_tool_output };
377
+ return matched.response;
347
378
  }
348
379
  return void 0;
349
380
  }, "interceptor");
@@ -387,27 +418,97 @@ async function generateActualInvocations(rootAgent, evalCase, resetFunc, session
387
418
  reference: ""
388
419
  });
389
420
  }
390
- return { actualInvocations, sessionId, userId };
421
+ return { actualInvocations, sessionId, userId, recordedSession };
391
422
  }
392
423
  __name(generateActualInvocations, "generateActualInvocations");
424
+ function evalCaseToEvalEntry(evalCase) {
425
+ if (isEvalEntry(evalCase)) {
426
+ return evalCase;
427
+ }
428
+ const structured = evalCase;
429
+ const data = structured.conversation.map((invocation) => {
430
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
431
+ const query = (_c = (_b = (_a = invocation.userContent) == null ? void 0 : _a.parts) == null ? void 0 : _b.map((p) => {
432
+ var _a2;
433
+ return (_a2 = p.text) != null ? _a2 : "";
434
+ }).join("")) != null ? _c : "";
435
+ const reference = (_f = (_e = (_d = invocation.finalResponse) == null ? void 0 : _d.parts) == null ? void 0 : _e.map((p) => {
436
+ var _a2;
437
+ return (_a2 = p.text) != null ? _a2 : "";
438
+ }).join("")) != null ? _f : "";
439
+ const toolResponsesById = /* @__PURE__ */ new Map();
440
+ for (const toolResponse of (_h = (_g = invocation.intermediateData) == null ? void 0 : _g.toolResponses) != null ? _h : []) {
441
+ if (toolResponse.id) {
442
+ toolResponsesById.set(toolResponse.id, toolResponse);
443
+ }
444
+ }
445
+ const expected_tool_use = ((_j = (_i = invocation.intermediateData) == null ? void 0 : _i.toolUses) != null ? _j : []).map((fc) => {
446
+ var _a2, _b2;
447
+ const toolUse = {
448
+ tool_name: (_a2 = fc.name) != null ? _a2 : "",
449
+ tool_input: (_b2 = fc.args) != null ? _b2 : {}
450
+ };
451
+ const toolResponse = fc.id ? toolResponsesById.get(fc.id) : void 0;
452
+ if ((toolResponse == null ? void 0 : toolResponse.response) !== void 0) {
453
+ declaredToolResponses.set(toolUse, toolResponse.response);
454
+ }
455
+ return toolUse;
456
+ });
457
+ const expected_intermediate_agent_responses = ((_l = (_k = invocation.intermediateData) == null ? void 0 : _k.intermediateResponses) != null ? _l : []).map(
458
+ ([author, parts]) => [author, parts]
459
+ );
460
+ return {
461
+ query,
462
+ expected_tool_use,
463
+ expected_intermediate_agent_responses,
464
+ reference
465
+ };
466
+ });
467
+ const sessionInput = structured.sessionInput;
468
+ return {
469
+ name: structured.evalId,
470
+ data,
471
+ ...sessionInput ? {
472
+ initial_session: {
473
+ ...sessionInput.appName ? { app_name: sessionInput.appName } : {},
474
+ ...sessionInput.userId ? { user_id: sessionInput.userId } : {},
475
+ state: sessionInput.state
476
+ }
477
+ } : {}
478
+ };
479
+ }
480
+ __name(evalCaseToEvalEntry, "evalCaseToEvalEntry");
393
481
  function resolveEvalCasesForSet(evalSetId, entries) {
394
482
  if (entries.length > 0 && typeof entries[0] === "string") {
395
483
  const filterNames = entries;
396
- const fileData = JSON.parse(
484
+ const rawFileData = JSON.parse(
397
485
  fs.readFileSync(evalSetId, "utf-8")
398
486
  );
399
- return fileData.filter((e) => filterNames.includes(e.name));
487
+ if (Array.isArray(rawFileData)) {
488
+ return rawFileData.filter(
489
+ (e) => filterNames.includes(e.name)
490
+ );
491
+ }
492
+ const loadedSet = loadEvalSetFromFile(evalSetId, evalSetId);
493
+ return loadedSet.evalCases.filter((e) => filterNames.includes(e.evalId)).map(evalCaseToEvalEntry);
400
494
  }
401
495
  if (entries.length === 0 && fs.existsSync(evalSetId) && fs.statSync(evalSetId).isFile()) {
402
- return JSON.parse(fs.readFileSync(evalSetId, "utf-8"));
496
+ const rawFileData = JSON.parse(
497
+ fs.readFileSync(evalSetId, "utf-8")
498
+ );
499
+ if (Array.isArray(rawFileData)) {
500
+ return rawFileData;
501
+ }
502
+ const loadedSet = loadEvalSetFromFile(evalSetId, evalSetId);
503
+ return loadedSet.evalCases.map(evalCaseToEvalEntry);
403
504
  }
404
- return entries;
505
+ return entries.map(evalCaseToEvalEntry);
405
506
  }
406
507
  __name(resolveEvalCasesForSet, "resolveEvalCasesForSet");
407
508
  function printCaseDetailedResults(result) {
408
509
  var _a;
409
510
  import_logger.logger.info(
410
- `Eval result for ${result.eval_set_file}:${result.eval_id}: ${EvalStatus[result.final_eval_status]}`
511
+ `Eval result for ${result.eval_set_id}:${result.eval_id}: ${EvalStatus[result.final_eval_status]}`
411
512
  );
412
513
  for (const metricResult of result.overall_eval_metric_results) {
413
514
  import_logger.logger.info(
@@ -456,7 +557,7 @@ async function* runEvals(optionsOrMap, rootAgentArg, resetFuncArg, evalMetricsAr
456
557
  const evalCases = resolveEvalCasesForSet(evalSetId, rawEntries);
457
558
  for (const evalCase of evalCases) {
458
559
  const evalName = evalCase.name;
459
- const { actualInvocations, sessionId, userId } = await generateActualInvocations(
560
+ const { actualInvocations, sessionId, userId, recordedSession } = await generateActualInvocations(
460
561
  rootAgent,
461
562
  evalCase,
462
563
  resetFunc,
@@ -499,12 +600,14 @@ async function* runEvals(optionsOrMap, rootAgentArg, resetFuncArg, evalMetricsAr
499
600
  }
500
601
  const result = {
501
602
  eval_set_file: evalSetId,
603
+ eval_set_id: evalSetId,
502
604
  eval_id: evalName,
503
605
  final_eval_status: finalEvalStatus,
504
606
  eval_metric_results: evalMetricResultsPairs,
505
607
  overall_eval_metric_results: overallEvalMetricResults,
506
608
  eval_metric_result_per_invocation: perInvocationMap,
507
609
  session_id: sessionId,
610
+ session_details: recordedSession && (0, import_internal_metadata.publicSession)(recordedSession),
508
611
  user_id: userId
509
612
  };
510
613
  if (printDetailedResults) {
@@ -515,18 +618,782 @@ async function* runEvals(optionsOrMap, rootAgentArg, resetFuncArg, evalMetricsAr
515
618
  }
516
619
  }
517
620
  __name(runEvals, "runEvals");
621
+ const ADK_EVAL_HISTORY_DIR = ".adk/eval_history";
622
+ const EVAL_SET_RESULT_FILE_EXTENSION = ".evalset_result.json";
623
+ function sanitizeEvalSetResultName(evalSetResultName) {
624
+ return evalSetResultName.replace(/\//g, "_");
625
+ }
626
+ __name(sanitizeEvalSetResultName, "sanitizeEvalSetResultName");
627
+ function toRunEvalResult(caseResult, fallbackEvalSetId) {
628
+ const record = caseResult;
629
+ const evalSetFile = typeof record.evalSetFile === "string" ? record.evalSetFile : typeof record.eval_set_file === "string" ? record.eval_set_file : void 0;
630
+ const evalSetId = typeof record.evalSetId === "string" ? record.evalSetId : typeof record.eval_set_id === "string" ? record.eval_set_id : fallbackEvalSetId != null ? fallbackEvalSetId : "";
631
+ const evalId = typeof record.evalId === "string" ? record.evalId : typeof record.eval_id === "string" ? record.eval_id : "";
632
+ const finalEvalStatus = typeof record.finalEvalStatus === "number" ? record.finalEvalStatus : typeof record.final_eval_status === "number" ? record.final_eval_status : 3 /* NOT_EVALUATED */;
633
+ const evalMetricResults = Array.isArray(record.evalMetricResults) ? record.evalMetricResults : Array.isArray(record.eval_metric_results) ? record.eval_metric_results : void 0;
634
+ const overallEvalMetricResults = Array.isArray(
635
+ record.overallEvalMetricResults
636
+ ) ? record.overallEvalMetricResults : Array.isArray(record.overall_eval_metric_results) ? record.overall_eval_metric_results : [];
637
+ const evalMetricResultPerInvocation = Array.isArray(
638
+ record.evalMetricResultPerInvocation
639
+ ) ? record.evalMetricResultPerInvocation : Array.isArray(record.eval_metric_result_per_invocation) ? record.eval_metric_result_per_invocation : [];
640
+ const sessionId = typeof record.sessionId === "string" ? record.sessionId : typeof record.session_id === "string" ? record.session_id : "";
641
+ const rawSessionDetails = record.sessionDetails !== void 0 && record.sessionDetails !== null ? record.sessionDetails : record.session_details !== void 0 && record.session_details !== null ? record.session_details : void 0;
642
+ const sessionDetails = rawSessionDetails && (0, import_internal_metadata.publicSession)(rawSessionDetails);
643
+ const userId = typeof record.userId === "string" ? record.userId : typeof record.user_id === "string" ? record.user_id : void 0;
644
+ return {
645
+ ...evalSetFile !== void 0 ? { evalSetFile } : {},
646
+ evalSetId,
647
+ evalId,
648
+ finalEvalStatus,
649
+ ...evalMetricResults !== void 0 ? { evalMetricResults } : {},
650
+ overallEvalMetricResults,
651
+ evalMetricResultPerInvocation,
652
+ sessionId,
653
+ ...sessionDetails !== void 0 ? { sessionDetails } : {},
654
+ ...userId !== void 0 ? { userId } : {}
655
+ };
656
+ }
657
+ __name(toRunEvalResult, "toRunEvalResult");
658
+ function createEvalSetResult({
659
+ appName,
660
+ evalSetId,
661
+ evalCaseResults,
662
+ creationTimestamp = (performance.timeOrigin + performance.now()) / 1e3
663
+ }) {
664
+ const evalSetResultId = `${appName}_${evalSetId}_${creationTimestamp}`;
665
+ const evalSetResultName = sanitizeEvalSetResultName(evalSetResultId);
666
+ return {
667
+ evalSetResultId,
668
+ evalSetResultName,
669
+ evalSetId,
670
+ evalCaseResults: evalCaseResults.map(
671
+ (caseResult) => toRunEvalResult(caseResult, evalSetId)
672
+ ),
673
+ creationTimestamp
674
+ };
675
+ }
676
+ __name(createEvalSetResult, "createEvalSetResult");
677
+ function parseEvalSetResultJson(evalSetResultJson) {
678
+ var _a, _b;
679
+ const decoded = JSON.parse(evalSetResultJson);
680
+ const target = typeof decoded === "string" ? JSON.parse(decoded) : decoded;
681
+ if (typeof target !== "object" || target === null || Array.isArray(target)) {
682
+ throw new Error("Invalid EvalSetResult JSON: expected an object.");
683
+ }
684
+ const record = target;
685
+ const evalSetResultId = typeof record.evalSetResultId === "string" ? record.evalSetResultId : typeof record.eval_set_result_id === "string" ? record.eval_set_result_id : void 0;
686
+ const evalSetId = typeof record.evalSetId === "string" ? record.evalSetId : typeof record.eval_set_id === "string" ? record.eval_set_id : void 0;
687
+ if (!evalSetResultId || !evalSetId) {
688
+ throw new Error(
689
+ "Invalid EvalSetResult JSON: missing evalSetResultId or evalSetId."
690
+ );
691
+ }
692
+ const evalSetResultName = typeof record.evalSetResultName === "string" ? record.evalSetResultName : typeof record.eval_set_result_name === "string" ? record.eval_set_result_name : sanitizeEvalSetResultName(evalSetResultId);
693
+ const rawCases = (_b = (_a = record.evalCaseResults) != null ? _a : record.eval_case_results) != null ? _b : [];
694
+ if (!Array.isArray(rawCases)) {
695
+ throw new Error(
696
+ "Invalid EvalSetResult JSON: evalCaseResults must be an array."
697
+ );
698
+ }
699
+ const evalCaseResults = rawCases.map((rawCase) => {
700
+ if (typeof rawCase !== "object" || rawCase === null || Array.isArray(rawCase)) {
701
+ throw new Error(
702
+ "Invalid EvalSetResult JSON: each evalCaseResult must be an object."
703
+ );
704
+ }
705
+ return toRunEvalResult(rawCase, evalSetId);
706
+ });
707
+ const creationTimestamp = typeof record.creationTimestamp === "number" ? record.creationTimestamp : typeof record.creation_timestamp === "number" ? record.creation_timestamp : 0;
708
+ return {
709
+ evalSetResultId,
710
+ evalSetResultName,
711
+ evalSetId,
712
+ evalCaseResults,
713
+ creationTimestamp
714
+ };
715
+ }
716
+ __name(parseEvalSetResultJson, "parseEvalSetResultJson");
717
+ const _LocalEvalSetResultsManager = class _LocalEvalSetResultsManager {
718
+ constructor(agentsDir) {
719
+ this.agentsDir = agentsDir;
720
+ }
721
+ /**
722
+ * Creates and saves a new {@link EvalSetResult} for `evalCaseResults`.
723
+ */
724
+ saveEvalSetResult({
725
+ appName,
726
+ evalSetId,
727
+ evalCaseResults
728
+ }) {
729
+ (0, import_path_validation.validatePathSegment)(appName, "appName");
730
+ (0, import_path_validation.validatePathSegment)(evalSetId, "evalSetId");
731
+ const evalSetResult = createEvalSetResult({
732
+ appName,
733
+ evalSetId,
734
+ evalCaseResults
735
+ });
736
+ const appEvalHistoryDir = this.getEvalHistoryDir(appName);
737
+ if (!fs.existsSync(appEvalHistoryDir)) {
738
+ fs.mkdirSync(appEvalHistoryDir, { recursive: true });
739
+ }
740
+ const evalSetResultFilePath = path.join(
741
+ appEvalHistoryDir,
742
+ `${evalSetResult.evalSetResultName}${EVAL_SET_RESULT_FILE_EXTENSION}`
743
+ );
744
+ import_logger.logger.info(`Writing eval result to file: ${evalSetResultFilePath}`);
745
+ fs.writeFileSync(
746
+ evalSetResultFilePath,
747
+ JSON.stringify(evalSetResult, null, 2),
748
+ "utf-8"
749
+ );
750
+ return evalSetResult;
751
+ }
752
+ /**
753
+ * Loads an {@link EvalSetResult} by `appName` and `evalSetResultId`.
754
+ *
755
+ * @throws {NotFoundError} If the result file does not exist.
756
+ */
757
+ getEvalSetResult(appName, evalSetResultId) {
758
+ const appEvalHistoryDir = this.getEvalHistoryDir(appName);
759
+ (0, import_path_validation.validatePathSegment)(evalSetResultId, "evalSetResultId");
760
+ const filePath = path.resolve(
761
+ appEvalHistoryDir,
762
+ `${evalSetResultId}${EVAL_SET_RESULT_FILE_EXTENSION}`
763
+ );
764
+ if (!(0, import_path_validation.isStrictlyInside)(appEvalHistoryDir, filePath)) {
765
+ throw new import_input_validation_error.InputValidationError(
766
+ `evalSetResultId '${evalSetResultId}' resolves outside the eval history directory.`
767
+ );
768
+ }
769
+ if (!fs.existsSync(filePath)) {
770
+ throw new import_not_found_error.NotFoundError(
771
+ `Eval set result \`${evalSetResultId}\` not found.`
772
+ );
773
+ }
774
+ const content = fs.readFileSync(filePath, "utf-8");
775
+ return parseEvalSetResultJson(content);
776
+ }
777
+ /**
778
+ * Lists all saved eval set result IDs for `appName`.
779
+ */
780
+ listEvalSetResults(appName) {
781
+ const appEvalHistoryDir = this.getEvalHistoryDir(appName);
782
+ if (!fs.existsSync(appEvalHistoryDir)) {
783
+ return [];
784
+ }
785
+ return fs.readdirSync(appEvalHistoryDir).filter((file) => file.endsWith(EVAL_SET_RESULT_FILE_EXTENSION)).map((file) => file.slice(0, -EVAL_SET_RESULT_FILE_EXTENSION.length));
786
+ }
787
+ getEvalHistoryDir(appName) {
788
+ (0, import_path_validation.validatePathSegment)(appName, "appName");
789
+ const baseDir = path.resolve(this.agentsDir);
790
+ const appDir = path.resolve(baseDir, appName);
791
+ if (!(0, import_path_validation.isStrictlyInside)(baseDir, appDir)) {
792
+ throw new import_input_validation_error.InputValidationError(
793
+ `appName '${appName}' resolves outside agentsDir.`
794
+ );
795
+ }
796
+ return path.join(appDir, ADK_EVAL_HISTORY_DIR);
797
+ }
798
+ };
799
+ __name(_LocalEvalSetResultsManager, "LocalEvalSetResultsManager");
800
+ let LocalEvalSetResultsManager = _LocalEvalSetResultsManager;
801
+ const EVAL_SET_FILE_EXTENSION = ".evalset.json";
802
+ const VALID_EVAL_ID_PATTERN = /^[a-zA-Z0-9_]+$/;
803
+ function validateEvalId(idName, idValue) {
804
+ if (!VALID_EVAL_ID_PATTERN.test(idValue)) {
805
+ const formattedName = idName.length > 0 ? idName[0].toUpperCase() + idName.slice(1) : idName;
806
+ throw new import_input_validation_error.InputValidationError(
807
+ `Invalid ${idName}. ${formattedName} should have the \`${VALID_EVAL_ID_PATTERN.source}\` format`
808
+ );
809
+ }
810
+ }
811
+ __name(validateEvalId, "validateEvalId");
812
+ function readCreationTimestamp(record) {
813
+ if (typeof record.creationTimestamp === "number") {
814
+ return record.creationTimestamp;
815
+ }
816
+ if (typeof record.creation_timestamp === "number") {
817
+ return record.creation_timestamp;
818
+ }
819
+ return void 0;
820
+ }
821
+ __name(readCreationTimestamp, "readCreationTimestamp");
822
+ function normalizeContent(raw, defaultRole) {
823
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
824
+ throw new import_input_validation_error.InputValidationError("Invalid Content: expected an object.");
825
+ }
826
+ const record = raw;
827
+ if (record.parts !== void 0 && !Array.isArray(record.parts)) {
828
+ throw new import_input_validation_error.InputValidationError(
829
+ "Invalid Content: parts must be an array when provided."
830
+ );
831
+ }
832
+ const parts = Array.isArray(record.parts) ? record.parts : [];
833
+ const role = typeof record.role === "string" ? record.role : defaultRole !== void 0 ? defaultRole : void 0;
834
+ return {
835
+ parts,
836
+ ...role !== void 0 ? { role } : {}
837
+ };
838
+ }
839
+ __name(normalizeContent, "normalizeContent");
840
+ function normalizeIntermediateData(raw) {
841
+ var _a, _b, _c, _d, _e, _f;
842
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
843
+ throw new import_input_validation_error.InputValidationError(
844
+ "Invalid EvalIntermediateData: expected an object."
845
+ );
846
+ }
847
+ const record = raw;
848
+ const rawToolUses = (_b = (_a = record.toolUses) != null ? _a : record.tool_uses) != null ? _b : [];
849
+ if (!Array.isArray(rawToolUses)) {
850
+ throw new import_input_validation_error.InputValidationError(
851
+ "Invalid EvalIntermediateData: toolUses must be an array."
852
+ );
853
+ }
854
+ const toolUses = rawToolUses.map((tu) => {
855
+ if (typeof tu !== "object" || tu === null || Array.isArray(tu)) {
856
+ throw new import_input_validation_error.InputValidationError(
857
+ "Invalid FunctionCall in toolUses: expected an object."
858
+ );
859
+ }
860
+ const fc = tu;
861
+ if (fc.name !== void 0 && typeof fc.name !== "string") {
862
+ throw new import_input_validation_error.InputValidationError(
863
+ "Invalid FunctionCall: name must be a string."
864
+ );
865
+ }
866
+ if (fc.args !== void 0 && (typeof fc.args !== "object" || fc.args === null || Array.isArray(fc.args))) {
867
+ throw new import_input_validation_error.InputValidationError(
868
+ "Invalid FunctionCall: args must be an object."
869
+ );
870
+ }
871
+ return {
872
+ ...typeof fc.id === "string" ? { id: fc.id } : {},
873
+ ...typeof fc.name === "string" ? { name: fc.name } : {},
874
+ ...fc.args !== void 0 ? { args: fc.args } : {}
875
+ };
876
+ });
877
+ const rawToolResponses = (_d = (_c = record.toolResponses) != null ? _c : record.tool_responses) != null ? _d : [];
878
+ if (!Array.isArray(rawToolResponses)) {
879
+ throw new import_input_validation_error.InputValidationError(
880
+ "Invalid EvalIntermediateData: toolResponses must be an array."
881
+ );
882
+ }
883
+ const toolResponses = rawToolResponses.map((tr) => {
884
+ if (typeof tr !== "object" || tr === null || Array.isArray(tr)) {
885
+ throw new import_input_validation_error.InputValidationError(
886
+ "Invalid FunctionResponse in toolResponses: expected an object."
887
+ );
888
+ }
889
+ const fr = tr;
890
+ if (fr.id !== void 0 && typeof fr.id !== "string") {
891
+ throw new import_input_validation_error.InputValidationError(
892
+ "Invalid FunctionResponse: id must be a string."
893
+ );
894
+ }
895
+ if (fr.name !== void 0 && typeof fr.name !== "string") {
896
+ throw new import_input_validation_error.InputValidationError(
897
+ "Invalid FunctionResponse: name must be a string."
898
+ );
899
+ }
900
+ if (fr.response !== void 0 && (typeof fr.response !== "object" || fr.response === null || Array.isArray(fr.response))) {
901
+ throw new import_input_validation_error.InputValidationError(
902
+ "Invalid FunctionResponse: response must be an object."
903
+ );
904
+ }
905
+ return {
906
+ ...typeof fr.id === "string" ? { id: fr.id } : {},
907
+ ...typeof fr.name === "string" ? { name: fr.name } : {},
908
+ ...fr.response !== void 0 ? { response: fr.response } : {}
909
+ };
910
+ });
911
+ const rawIntermediate = (_f = (_e = record.intermediateResponses) != null ? _e : record.intermediate_responses) != null ? _f : [];
912
+ if (!Array.isArray(rawIntermediate)) {
913
+ throw new import_input_validation_error.InputValidationError(
914
+ "Invalid EvalIntermediateData: intermediateResponses must be an array."
915
+ );
916
+ }
917
+ const intermediateResponses = rawIntermediate.map((entry) => {
918
+ if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string" || !Array.isArray(entry[1])) {
919
+ throw new import_input_validation_error.InputValidationError(
920
+ "Invalid intermediateResponses entry: expected [author, Part[]]."
921
+ );
922
+ }
923
+ return [entry[0], entry[1]];
924
+ });
925
+ return {
926
+ toolUses,
927
+ ...toolResponses.length > 0 ? { toolResponses } : {},
928
+ intermediateResponses
929
+ };
930
+ }
931
+ __name(normalizeIntermediateData, "normalizeIntermediateData");
932
+ function normalizeInvocation(raw) {
933
+ var _a, _b, _c;
934
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
935
+ throw new import_input_validation_error.InputValidationError(
936
+ "Invalid EvalInvocation: expected an object."
937
+ );
938
+ }
939
+ const record = raw;
940
+ const rawUserContent = (_a = record.userContent) != null ? _a : record.user_content;
941
+ if (rawUserContent === void 0) {
942
+ throw new import_input_validation_error.InputValidationError(
943
+ "Invalid EvalInvocation: userContent is required."
944
+ );
945
+ }
946
+ const userContent = normalizeContent(rawUserContent);
947
+ const rawFinalResponse = (_b = record.finalResponse) != null ? _b : record.final_response;
948
+ const finalResponse = rawFinalResponse !== void 0 && rawFinalResponse !== null ? normalizeContent(rawFinalResponse) : void 0;
949
+ const rawIntermediateData = (_c = record.intermediateData) != null ? _c : record.intermediate_data;
950
+ const intermediateData = rawIntermediateData !== void 0 && rawIntermediateData !== null ? normalizeIntermediateData(rawIntermediateData) : void 0;
951
+ const invocationId = typeof record.invocationId === "string" ? record.invocationId : typeof record.invocation_id === "string" ? record.invocation_id : void 0;
952
+ const creationTimestamp = readCreationTimestamp(record);
953
+ return {
954
+ ...invocationId !== void 0 ? { invocationId } : {},
955
+ userContent,
956
+ ...finalResponse !== void 0 ? { finalResponse } : {},
957
+ ...intermediateData !== void 0 ? { intermediateData } : {},
958
+ ...creationTimestamp !== void 0 ? { creationTimestamp } : {}
959
+ };
960
+ }
961
+ __name(normalizeInvocation, "normalizeInvocation");
962
+ function normalizeSessionInput(raw) {
963
+ var _a, _b, _c, _d, _e;
964
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
965
+ throw new import_input_validation_error.InputValidationError(
966
+ "Invalid EvalSessionInput: expected an object."
967
+ );
968
+ }
969
+ const record = raw;
970
+ const rawAppName = (_b = (_a = record.appName) != null ? _a : record.app_name) != null ? _b : "";
971
+ const rawUserId = (_d = (_c = record.userId) != null ? _c : record.user_id) != null ? _d : "";
972
+ const rawState = (_e = record.state) != null ? _e : {};
973
+ if (typeof rawAppName !== "string") {
974
+ throw new import_input_validation_error.InputValidationError(
975
+ "Invalid EvalSessionInput: appName must be a string."
976
+ );
977
+ }
978
+ if (typeof rawUserId !== "string") {
979
+ throw new import_input_validation_error.InputValidationError(
980
+ "Invalid EvalSessionInput: userId must be a string."
981
+ );
982
+ }
983
+ if (typeof rawState !== "object" || rawState === null || Array.isArray(rawState)) {
984
+ throw new import_input_validation_error.InputValidationError(
985
+ "Invalid EvalSessionInput: state must be an object."
986
+ );
987
+ }
988
+ return {
989
+ appName: rawAppName,
990
+ userId: rawUserId,
991
+ state: rawState
992
+ };
993
+ }
994
+ __name(normalizeSessionInput, "normalizeSessionInput");
995
+ function normalizeEvalCase(raw) {
996
+ var _a, _b;
997
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
998
+ throw new import_input_validation_error.InputValidationError("Invalid EvalCase: expected an object.");
999
+ }
1000
+ const record = raw;
1001
+ const rawEvalId = (_a = record.evalId) != null ? _a : record.eval_id;
1002
+ if (typeof rawEvalId !== "string") {
1003
+ throw new import_input_validation_error.InputValidationError(
1004
+ "Invalid EvalCase: evalId must be a string."
1005
+ );
1006
+ }
1007
+ if (!Array.isArray(record.conversation)) {
1008
+ throw new import_input_validation_error.InputValidationError(
1009
+ "Invalid EvalCase: conversation must be an array."
1010
+ );
1011
+ }
1012
+ const conversation = record.conversation.map(normalizeInvocation);
1013
+ const rawSessionInput = (_b = record.sessionInput) != null ? _b : record.session_input;
1014
+ const sessionInput = rawSessionInput !== void 0 && rawSessionInput !== null ? normalizeSessionInput(rawSessionInput) : void 0;
1015
+ const creationTimestamp = readCreationTimestamp(record);
1016
+ return {
1017
+ evalId: rawEvalId,
1018
+ conversation,
1019
+ ...sessionInput !== void 0 ? { sessionInput } : {},
1020
+ ...creationTimestamp !== void 0 ? { creationTimestamp } : {}
1021
+ };
1022
+ }
1023
+ __name(normalizeEvalCase, "normalizeEvalCase");
1024
+ function convertLegacyInvocationToSchema(rawInvocation) {
1025
+ var _a, _b, _c;
1026
+ if (typeof rawInvocation !== "object" || rawInvocation === null || Array.isArray(rawInvocation)) {
1027
+ throw new import_input_validation_error.InputValidationError(
1028
+ "Invalid legacy invocation: expected an object."
1029
+ );
1030
+ }
1031
+ const record = rawInvocation;
1032
+ if (typeof record.query !== "string") {
1033
+ throw new import_input_validation_error.InputValidationError(
1034
+ "Invalid legacy invocation: query must be a string."
1035
+ );
1036
+ }
1037
+ const query = record.query;
1038
+ const rawReference = (_a = record.reference) != null ? _a : "";
1039
+ if (typeof rawReference !== "string") {
1040
+ throw new import_input_validation_error.InputValidationError(
1041
+ "Invalid legacy invocation: reference must be a string."
1042
+ );
1043
+ }
1044
+ const rawExpectedToolUse = (_b = record.expected_tool_use) != null ? _b : [];
1045
+ if (!Array.isArray(rawExpectedToolUse)) {
1046
+ throw new import_input_validation_error.InputValidationError(
1047
+ "Invalid legacy invocation: expected_tool_use must be an array."
1048
+ );
1049
+ }
1050
+ const toolResponses = [];
1051
+ const toolUses = rawExpectedToolUse.map((oldToolUse) => {
1052
+ var _a2;
1053
+ if (typeof oldToolUse !== "object" || oldToolUse === null || Array.isArray(oldToolUse)) {
1054
+ throw new import_input_validation_error.InputValidationError(
1055
+ "Invalid legacy tool_use entry: expected an object."
1056
+ );
1057
+ }
1058
+ const tu = oldToolUse;
1059
+ if (typeof tu.tool_name !== "string") {
1060
+ throw new import_input_validation_error.InputValidationError(
1061
+ "Invalid legacy tool_use: tool_name must be a string."
1062
+ );
1063
+ }
1064
+ if (tu.tool_input !== void 0 && (typeof tu.tool_input !== "object" || tu.tool_input === null || Array.isArray(tu.tool_input))) {
1065
+ throw new import_input_validation_error.InputValidationError(
1066
+ "Invalid legacy tool_use: tool_input must be an object."
1067
+ );
1068
+ }
1069
+ const toolUse = {
1070
+ name: tu.tool_name,
1071
+ args: (_a2 = tu.tool_input) != null ? _a2 : {}
1072
+ };
1073
+ if (tu.mock_tool_output !== void 0) {
1074
+ toolUse.id = (0, import_node_crypto.randomUUID)();
1075
+ toolResponses.push({
1076
+ id: toolUse.id,
1077
+ name: tu.tool_name,
1078
+ response: { [MOCK_TOOL_OUTPUT_RESPONSE_KEY]: tu.mock_tool_output }
1079
+ });
1080
+ }
1081
+ return toolUse;
1082
+ });
1083
+ const rawExpectedIntermediate = (_c = record.expected_intermediate_agent_responses) != null ? _c : [];
1084
+ if (!Array.isArray(rawExpectedIntermediate)) {
1085
+ throw new import_input_validation_error.InputValidationError(
1086
+ "Invalid legacy invocation: expected_intermediate_agent_responses must be an array."
1087
+ );
1088
+ }
1089
+ const intermediateResponses = rawExpectedIntermediate.map((oldIntermediate) => {
1090
+ if (Array.isArray(oldIntermediate)) {
1091
+ if (oldIntermediate.length !== 2 || typeof oldIntermediate[0] !== "string" || !Array.isArray(oldIntermediate[1])) {
1092
+ throw new import_input_validation_error.InputValidationError(
1093
+ "Invalid legacy intermediate response tuple: expected [author, Part[]]."
1094
+ );
1095
+ }
1096
+ return [oldIntermediate[0], oldIntermediate[1]];
1097
+ }
1098
+ if (typeof oldIntermediate === "object" && oldIntermediate !== null) {
1099
+ const ir = oldIntermediate;
1100
+ if (typeof ir.author !== "string" || typeof ir.text !== "string") {
1101
+ throw new import_input_validation_error.InputValidationError(
1102
+ "Invalid legacy intermediate response: author and text must be strings."
1103
+ );
1104
+ }
1105
+ return [ir.author, [{ text: ir.text }]];
1106
+ }
1107
+ throw new import_input_validation_error.InputValidationError(
1108
+ "Invalid legacy intermediate response: expected an object or tuple."
1109
+ );
1110
+ });
1111
+ return {
1112
+ invocationId: (0, import_node_crypto.randomUUID)(),
1113
+ userContent: {
1114
+ parts: [{ text: query }],
1115
+ role: "user"
1116
+ },
1117
+ finalResponse: {
1118
+ parts: [{ text: rawReference }],
1119
+ role: "model"
1120
+ },
1121
+ intermediateData: {
1122
+ toolUses,
1123
+ ...toolResponses.length > 0 ? { toolResponses } : {},
1124
+ intermediateResponses
1125
+ },
1126
+ creationTimestamp: Date.now() / 1e3
1127
+ };
1128
+ }
1129
+ __name(convertLegacyInvocationToSchema, "convertLegacyInvocationToSchema");
1130
+ function convertEvalSetToSchema(evalSetId, evalSetInJsonFormat) {
1131
+ if (!Array.isArray(evalSetInJsonFormat)) {
1132
+ throw new import_input_validation_error.InputValidationError(
1133
+ "Invalid legacy eval set JSON: expected an array of eval entries."
1134
+ );
1135
+ }
1136
+ const evalCases = [];
1137
+ for (const rawEvalCase of evalSetInJsonFormat) {
1138
+ if (typeof rawEvalCase !== "object" || rawEvalCase === null || Array.isArray(rawEvalCase)) {
1139
+ throw new import_input_validation_error.InputValidationError(
1140
+ "Invalid legacy eval case: expected an object."
1141
+ );
1142
+ }
1143
+ const oldEvalCase = rawEvalCase;
1144
+ if (typeof oldEvalCase.name !== "string") {
1145
+ throw new import_input_validation_error.InputValidationError(
1146
+ "Invalid legacy eval case: name must be a string."
1147
+ );
1148
+ }
1149
+ if (!Array.isArray(oldEvalCase.data)) {
1150
+ throw new import_input_validation_error.InputValidationError(
1151
+ "Invalid legacy eval case: data must be an array."
1152
+ );
1153
+ }
1154
+ const newInvocations = oldEvalCase.data.map(
1155
+ convertLegacyInvocationToSchema
1156
+ );
1157
+ let sessionInput;
1158
+ if (oldEvalCase.initial_session !== void 0 && oldEvalCase.initial_session !== null) {
1159
+ if (typeof oldEvalCase.initial_session !== "object" || Array.isArray(oldEvalCase.initial_session)) {
1160
+ throw new import_input_validation_error.InputValidationError(
1161
+ "Invalid legacy eval case: initial_session must be an object."
1162
+ );
1163
+ }
1164
+ const initSess = oldEvalCase.initial_session;
1165
+ if (Object.keys(initSess).length > 0) {
1166
+ sessionInput = normalizeSessionInput(initSess);
1167
+ }
1168
+ }
1169
+ evalCases.push({
1170
+ evalId: oldEvalCase.name,
1171
+ conversation: newInvocations,
1172
+ ...sessionInput !== void 0 ? { sessionInput } : {},
1173
+ creationTimestamp: Date.now() / 1e3
1174
+ });
1175
+ }
1176
+ return {
1177
+ evalSetId,
1178
+ name: evalSetId,
1179
+ creationTimestamp: Date.now() / 1e3,
1180
+ evalCases
1181
+ };
1182
+ }
1183
+ __name(convertEvalSetToSchema, "convertEvalSetToSchema");
1184
+ function parseEvalSetObject(raw) {
1185
+ var _a, _b;
1186
+ const rawEvalSetId = (_a = raw.evalSetId) != null ? _a : raw.eval_set_id;
1187
+ const rawEvalCases = (_b = raw.evalCases) != null ? _b : raw.eval_cases;
1188
+ if (typeof rawEvalSetId !== "string" || !Array.isArray(rawEvalCases)) {
1189
+ throw new import_input_validation_error.InputValidationError(
1190
+ "Invalid EvalSet JSON: missing evalSetId or evalCases."
1191
+ );
1192
+ }
1193
+ const name = typeof raw.name === "string" ? raw.name : void 0;
1194
+ const description = typeof raw.description === "string" ? raw.description : void 0;
1195
+ const creationTimestamp = readCreationTimestamp(raw);
1196
+ return {
1197
+ evalSetId: rawEvalSetId,
1198
+ ...name !== void 0 ? { name } : {},
1199
+ ...description !== void 0 ? { description } : {},
1200
+ evalCases: rawEvalCases.map(normalizeEvalCase),
1201
+ ...creationTimestamp !== void 0 ? { creationTimestamp } : {}
1202
+ };
1203
+ }
1204
+ __name(parseEvalSetObject, "parseEvalSetObject");
1205
+ function loadEvalSetFromFile(evalSetFilePath, evalSetId) {
1206
+ const content = fs.readFileSync(evalSetFilePath, "utf-8");
1207
+ const parsed = JSON.parse(content);
1208
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) && ("evalSetId" in parsed || "eval_set_id" in parsed || "evalCases" in parsed || "eval_cases" in parsed)) {
1209
+ return parseEvalSetObject(parsed);
1210
+ }
1211
+ return convertEvalSetToSchema(evalSetId, parsed);
1212
+ }
1213
+ __name(loadEvalSetFromFile, "loadEvalSetFromFile");
1214
+ const _LocalEvalSetsManager = class _LocalEvalSetsManager {
1215
+ constructor(agentsDir) {
1216
+ this.agentsDir = agentsDir;
1217
+ }
1218
+ /**
1219
+ * Loads an {@link EvalSet} identified by `appName` and `evalSetId`, or
1220
+ * returns `undefined` if the file does not exist.
1221
+ */
1222
+ getEvalSet(appName, evalSetId) {
1223
+ const evalSetFilePath = this.getEvalSetFilePath(appName, evalSetId);
1224
+ if (!fs.existsSync(evalSetFilePath)) {
1225
+ return void 0;
1226
+ }
1227
+ return loadEvalSetFromFile(evalSetFilePath, evalSetId);
1228
+ }
1229
+ /**
1230
+ * Creates an empty {@link EvalSet} file for `appName` and `evalSetId`.
1231
+ *
1232
+ * @throws {InputValidationError} If `evalSetId` is invalid or the eval set
1233
+ * already exists.
1234
+ */
1235
+ createEvalSet(appName, evalSetId) {
1236
+ validateEvalId("eval set ID", evalSetId);
1237
+ const newEvalSetPath = this.getEvalSetFilePath(appName, evalSetId);
1238
+ if (fs.existsSync(newEvalSetPath)) {
1239
+ throw new import_input_validation_error.InputValidationError(
1240
+ `EvalSet ${evalSetId} already exists for app ${appName}.`
1241
+ );
1242
+ }
1243
+ import_logger.logger.info(`Creating eval set file \`${newEvalSetPath}\``);
1244
+ const newEvalSet = {
1245
+ evalSetId,
1246
+ name: evalSetId,
1247
+ evalCases: [],
1248
+ creationTimestamp: Date.now() / 1e3
1249
+ };
1250
+ this.writeEvalSet(newEvalSetPath, newEvalSet);
1251
+ return newEvalSet;
1252
+ }
1253
+ /**
1254
+ * Lists all eval set IDs stored under `appName`, sorted alphabetically.
1255
+ */
1256
+ listEvalSets(appName) {
1257
+ (0, import_path_validation.validatePathSegment)(appName, "appName");
1258
+ const baseDir = path.resolve(this.agentsDir);
1259
+ const appDir = path.resolve(baseDir, appName);
1260
+ if (!(0, import_path_validation.isStrictlyInside)(baseDir, appDir)) {
1261
+ throw new import_input_validation_error.InputValidationError(`Invalid appName '${appName}'.`);
1262
+ }
1263
+ if (!fs.existsSync(appDir)) {
1264
+ return [];
1265
+ }
1266
+ const evalSets = [];
1267
+ for (const file of fs.readdirSync(appDir)) {
1268
+ if (file.endsWith(EVAL_SET_FILE_EXTENSION)) {
1269
+ evalSets.push(file.slice(0, -EVAL_SET_FILE_EXTENSION.length));
1270
+ }
1271
+ }
1272
+ return evalSets.sort();
1273
+ }
1274
+ /**
1275
+ * Adds `evalCase` to the {@link EvalSet} identified by `appName` and
1276
+ * `evalSetId`.
1277
+ *
1278
+ * @throws {NotFoundError} If the eval set does not exist.
1279
+ * @throws {InputValidationError} If `evalCase.evalId` is invalid or already exists.
1280
+ */
1281
+ addEvalCase(appName, evalSetId, evalCase) {
1282
+ const normalizedCase = normalizeEvalCase(evalCase);
1283
+ const evalCaseId = normalizedCase.evalId;
1284
+ validateEvalId("Eval Case ID", evalCaseId);
1285
+ const evalSet = this.getEvalSet(appName, evalSetId);
1286
+ if (!evalSet) {
1287
+ throw new import_not_found_error.NotFoundError(`Eval set \`${evalSetId}\` not found.`);
1288
+ }
1289
+ if (evalSet.evalCases.some((x) => x.evalId === evalCaseId)) {
1290
+ throw new import_input_validation_error.InputValidationError(
1291
+ `Eval id \`${evalCaseId}\` already exists in \`${evalSetId}\` eval set.`
1292
+ );
1293
+ }
1294
+ evalSet.evalCases.push(normalizedCase);
1295
+ const evalSetFilePath = this.getEvalSetFilePath(appName, evalSetId);
1296
+ this.writeEvalSet(evalSetFilePath, evalSet);
1297
+ }
1298
+ /**
1299
+ * Returns a single {@link EvalCase} by `appName`, `evalSetId`, and
1300
+ * `evalCaseId`, or `undefined` if not found.
1301
+ */
1302
+ getEvalCase(appName, evalSetId, evalCaseId) {
1303
+ const evalSet = this.getEvalSet(appName, evalSetId);
1304
+ if (!evalSet) {
1305
+ return void 0;
1306
+ }
1307
+ return evalSet.evalCases.find((c) => c.evalId === evalCaseId);
1308
+ }
1309
+ /**
1310
+ * Updates an existing {@link EvalCase} in the {@link EvalSet} identified by
1311
+ * `appName` and `evalSetId`.
1312
+ *
1313
+ * @throws {NotFoundError} If the eval set or eval case is not found.
1314
+ */
1315
+ updateEvalCase(appName, evalSetId, updatedEvalCase) {
1316
+ const normalizedCase = normalizeEvalCase(updatedEvalCase);
1317
+ const evalCaseId = normalizedCase.evalId;
1318
+ const evalSet = this.getEvalSet(appName, evalSetId);
1319
+ if (!evalSet || !evalSet.evalCases.some((c) => c.evalId === evalCaseId)) {
1320
+ throw new import_not_found_error.NotFoundError(
1321
+ `Eval Set \`${evalSetId}\` or Eval id \`${evalCaseId}\` not found.`
1322
+ );
1323
+ }
1324
+ evalSet.evalCases = evalSet.evalCases.filter(
1325
+ (c) => c.evalId !== evalCaseId
1326
+ );
1327
+ evalSet.evalCases.push(normalizedCase);
1328
+ const evalSetFilePath = this.getEvalSetFilePath(appName, evalSetId);
1329
+ this.writeEvalSet(evalSetFilePath, evalSet);
1330
+ }
1331
+ /**
1332
+ * Deletes an {@link EvalCase} identified by `appName`, `evalSetId`, and
1333
+ * `evalCaseId`.
1334
+ *
1335
+ * @throws {NotFoundError} If the eval set or eval case to delete is not found.
1336
+ */
1337
+ deleteEvalCase(appName, evalSetId, evalCaseId) {
1338
+ const evalSet = this.getEvalSet(appName, evalSetId);
1339
+ if (!evalSet || !evalSet.evalCases.some((c) => c.evalId === evalCaseId)) {
1340
+ throw new import_not_found_error.NotFoundError(
1341
+ `Eval Set \`${evalSetId}\` or Eval id \`${evalCaseId}\` not found.`
1342
+ );
1343
+ }
1344
+ import_logger.logger.info(
1345
+ `EvalCase \`${evalCaseId}\` was found in the eval set. It will be removed permanently.`
1346
+ );
1347
+ evalSet.evalCases = evalSet.evalCases.filter(
1348
+ (c) => c.evalId !== evalCaseId
1349
+ );
1350
+ const evalSetFilePath = this.getEvalSetFilePath(appName, evalSetId);
1351
+ this.writeEvalSet(evalSetFilePath, evalSet);
1352
+ }
1353
+ getEvalSetFilePath(appName, evalSetId) {
1354
+ (0, import_path_validation.validatePathSegment)(appName, "appName");
1355
+ (0, import_path_validation.validatePathSegment)(evalSetId, "evalSetId");
1356
+ validateEvalId("eval set ID", evalSetId);
1357
+ const baseDir = path.resolve(this.agentsDir);
1358
+ const appDir = path.resolve(baseDir, appName);
1359
+ if (!(0, import_path_validation.isStrictlyInside)(baseDir, appDir)) {
1360
+ throw new import_input_validation_error.InputValidationError(`Invalid appName '${appName}'.`);
1361
+ }
1362
+ const filePath = path.resolve(
1363
+ appDir,
1364
+ `${evalSetId}${EVAL_SET_FILE_EXTENSION}`
1365
+ );
1366
+ if (!(0, import_path_validation.isStrictlyInside)(appDir, filePath)) {
1367
+ throw new import_input_validation_error.InputValidationError(`Invalid evalSetId '${evalSetId}'.`);
1368
+ }
1369
+ return filePath;
1370
+ }
1371
+ writeEvalSet(evalSetPath, evalSet) {
1372
+ fs.mkdirSync(path.dirname(evalSetPath), { recursive: true });
1373
+ fs.writeFileSync(evalSetPath, JSON.stringify(evalSet, null, 2), "utf-8");
1374
+ }
1375
+ };
1376
+ __name(_LocalEvalSetsManager, "LocalEvalSetsManager");
1377
+ let LocalEvalSetsManager = _LocalEvalSetsManager;
518
1378
  // Annotate the CommonJS export names for ESM import in node:
519
1379
  0 && (module.exports = {
520
1380
  DEFAULT_CRITERIA,
521
1381
  EVAL_SESSION_ID_PREFIX,
522
1382
  EvalStatus,
1383
+ LocalEvalSetResultsManager,
1384
+ LocalEvalSetsManager,
523
1385
  MISSING_EVAL_DEPENDENCIES_MESSAGE,
524
1386
  RESPONSE_EVALUATION_SCORE_KEY,
525
1387
  RESPONSE_MATCH_SCORE_KEY,
526
1388
  TOOL_TRAJECTORY_SCORE_KEY,
1389
+ convertEvalSetToSchema,
1390
+ createEvalSetResult,
527
1391
  getEvaluationCriteriaOrDefault,
528
1392
  getRootAgent,
1393
+ loadEvalSetFromFile,
1394
+ normalizeEvalCase,
529
1395
  parseAndGetEvalsToRun,
1396
+ parseEvalSetResultJson,
530
1397
  runEvals,
531
1398
  tryGetResetFunc
532
1399
  });