@google/adk 2.2.1 → 2.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.
Files changed (298) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +4 -1
  2. package/dist/cjs/a2a/agent_card.js +102 -26
  3. package/dist/cjs/a2a/agent_to_a2a.js +1 -1
  4. package/dist/cjs/agents/agent_engine_client.js +172 -0
  5. package/dist/cjs/agents/base_agent.js +20 -4
  6. package/dist/cjs/agents/functions.js +227 -25
  7. package/dist/cjs/agents/instructions.js +6 -2
  8. package/dist/cjs/agents/invocation_context.js +26 -4
  9. package/dist/cjs/agents/langgraph_agent.js +152 -0
  10. package/dist/cjs/agents/llm_agent.js +194 -107
  11. package/dist/cjs/agents/processors/basic_llm_request_processor.js +1 -1
  12. package/dist/cjs/agents/processors/code_execution_request_processor.js +18 -6
  13. package/dist/cjs/agents/processors/content_processor_utils.js +38 -10
  14. package/dist/cjs/agents/processors/content_request_processor.js +34 -2
  15. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
  16. package/dist/cjs/agents/processors/nl_planning_processor.js +12 -3
  17. package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
  18. package/dist/cjs/auth/auth_handler.js +37 -5
  19. package/dist/cjs/auth/auth_schemes.js +9 -0
  20. package/dist/cjs/cli/cli_eval.js +532 -0
  21. package/dist/cjs/cli/utils/envs.js +116 -0
  22. package/dist/cjs/cli/utils/evals.js +137 -0
  23. package/dist/cjs/cli/utils/logs.js +150 -0
  24. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  25. package/dist/cjs/code_executors/code_execution_utils.js +48 -16
  26. package/dist/cjs/code_executors/code_executor_context.js +6 -2
  27. package/dist/cjs/code_executors/container_code_executor.js +27 -16
  28. package/dist/cjs/code_executors/unsafe_local_code_executor.js +6 -1
  29. package/dist/cjs/common.js +61 -0
  30. package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
  31. package/dist/cjs/context/token_based_context_compactor.js +2 -1
  32. package/dist/cjs/errors/input_validation_error.js +3 -2
  33. package/dist/cjs/events/event.js +4 -2
  34. package/dist/cjs/examples/example_util.js +23 -2
  35. package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
  36. package/dist/cjs/index.js +104 -1
  37. package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
  38. package/dist/cjs/models/gemini_llm_connection.js +16 -8
  39. package/dist/cjs/models/google_llm.js +13 -16
  40. package/dist/cjs/models/llm_response.js +9 -1
  41. package/dist/cjs/models/registry.js +1 -1
  42. package/dist/cjs/models/routed_llm.js +9 -8
  43. package/dist/cjs/planners/plan_re_act_planner.js +1 -1
  44. package/dist/cjs/plugins/base_plugin.js +13 -23
  45. package/dist/cjs/runner/in_memory_runner.js +6 -11
  46. package/dist/cjs/runner/runner.js +105 -33
  47. package/dist/cjs/sessions/base_session_service.js +14 -8
  48. package/dist/cjs/sessions/database_session_service.js +50 -28
  49. package/dist/cjs/sessions/db/operations.js +1 -1
  50. package/dist/cjs/sessions/in_memory_session_service.js +3 -1
  51. package/dist/cjs/sessions/stale_session_error.js +59 -0
  52. package/dist/cjs/sessions/state.js +8 -4
  53. package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
  54. package/dist/cjs/skills/loader.js +52 -18
  55. package/dist/cjs/telemetry/setup.js +0 -1
  56. package/dist/cjs/telemetry/tracing.js +147 -73
  57. package/dist/cjs/tools/agent_tool.js +44 -0
  58. package/dist/cjs/tools/apihub_tool/apihub_toolset.js +137 -0
  59. package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
  60. package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
  61. package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
  62. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +263 -0
  63. package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
  64. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +671 -0
  65. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +223 -0
  66. package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +184 -0
  67. package/dist/cjs/tools/example_tool.js +10 -0
  68. package/dist/cjs/tools/function_tool.js +319 -0
  69. package/dist/cjs/tools/google_api_tool/google_api_tool.js +100 -0
  70. package/dist/cjs/tools/google_api_tool/google_api_toolset.js +173 -0
  71. package/dist/cjs/tools/google_api_tool/google_api_toolsets.js +124 -0
  72. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
  73. package/dist/cjs/tools/google_api_tool/index.js +61 -0
  74. package/dist/cjs/tools/load_artifacts_tool.js +12 -6
  75. package/dist/cjs/tools/load_memory_tool.js +12 -10
  76. package/dist/cjs/tools/mcp/index.js +12 -0
  77. package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
  78. package/dist/cjs/tools/mcp/mcp_toolset.js +1 -14
  79. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
  80. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
  81. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
  82. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  83. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
  84. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
  85. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
  86. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +7 -13
  87. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +17 -1
  88. package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
  89. package/dist/cjs/tools/toolbox_toolset.js +174 -0
  90. package/dist/cjs/tools/webmcp/webmcp_toolset.js +1 -14
  91. package/dist/cjs/utils/client_labels.js +19 -2
  92. package/dist/cjs/utils/env_aware_utils.js +6 -8
  93. package/dist/cjs/utils/error_utils.js +11 -11
  94. package/dist/cjs/utils/failover_utils.js +1 -1
  95. package/dist/cjs/utils/file_extension_utils.js +11 -0
  96. package/dist/cjs/utils/file_utils.js +2 -24
  97. package/dist/cjs/utils/gemini_schema_util.js +28 -7
  98. package/dist/cjs/utils/json_utils.js +49 -0
  99. package/dist/cjs/utils/live_connection_utils.js +4 -5
  100. package/dist/cjs/utils/logger_node.js +11 -1
  101. package/dist/cjs/utils/object_notation_utils.js +6 -3
  102. package/dist/cjs/utils/output_schema_utils.js +5 -2
  103. package/dist/cjs/utils/streaming_utils.js +12 -12
  104. package/dist/cjs/utils/task.js +1 -1
  105. package/dist/cjs/version.js +1 -1
  106. package/dist/esm/a2a/a2a_remote_agent.js +4 -1
  107. package/dist/esm/a2a/agent_card.js +103 -27
  108. package/dist/esm/a2a/agent_to_a2a.js +5 -2
  109. package/dist/esm/agents/agent_engine_client.js +144 -0
  110. package/dist/esm/agents/base_agent.js +20 -4
  111. package/dist/esm/agents/functions.js +226 -25
  112. package/dist/esm/agents/instructions.js +6 -2
  113. package/dist/esm/agents/invocation_context.js +24 -4
  114. package/dist/esm/agents/langgraph_agent.js +123 -0
  115. package/dist/esm/agents/llm_agent.js +204 -110
  116. package/dist/esm/agents/processors/basic_llm_request_processor.js +1 -1
  117. package/dist/esm/agents/processors/code_execution_request_processor.js +21 -8
  118. package/dist/esm/agents/processors/content_processor_utils.js +38 -10
  119. package/dist/esm/agents/processors/content_request_processor.js +34 -2
  120. package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
  121. package/dist/esm/agents/processors/nl_planning_processor.js +12 -3
  122. package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
  123. package/dist/esm/auth/auth_handler.js +37 -5
  124. package/dist/esm/auth/auth_schemes.js +8 -0
  125. package/dist/esm/cli/cli_eval.js +510 -0
  126. package/dist/esm/cli/utils/envs.js +78 -0
  127. package/dist/esm/cli/utils/evals.js +109 -0
  128. package/dist/esm/cli/utils/logs.js +111 -0
  129. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  130. package/dist/esm/code_executors/code_execution_utils.js +46 -16
  131. package/dist/esm/code_executors/code_executor_context.js +5 -2
  132. package/dist/esm/code_executors/container_code_executor.js +27 -16
  133. package/dist/esm/code_executors/unsafe_local_code_executor.js +6 -1
  134. package/dist/esm/common.js +65 -4
  135. package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
  136. package/dist/esm/context/token_based_context_compactor.js +2 -1
  137. package/dist/esm/errors/input_validation_error.js +3 -2
  138. package/dist/esm/events/event.js +4 -2
  139. package/dist/esm/examples/example_util.js +21 -1
  140. package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
  141. package/dist/esm/index.js +114 -2
  142. package/dist/esm/integrations/agent_registry/helpers.js +1 -1
  143. package/dist/esm/models/gemini_llm_connection.js +16 -8
  144. package/dist/esm/models/google_llm.js +14 -17
  145. package/dist/esm/models/llm_response.js +9 -1
  146. package/dist/esm/models/registry.js +1 -1
  147. package/dist/esm/models/routed_llm.js +9 -8
  148. package/dist/esm/planners/plan_re_act_planner.js +1 -1
  149. package/dist/esm/plugins/base_plugin.js +13 -23
  150. package/dist/esm/runner/in_memory_runner.js +6 -11
  151. package/dist/esm/runner/runner.js +105 -33
  152. package/dist/esm/sessions/base_session_service.js +12 -7
  153. package/dist/esm/sessions/database_session_service.js +49 -28
  154. package/dist/esm/sessions/db/operations.js +1 -1
  155. package/dist/esm/sessions/in_memory_session_service.js +3 -1
  156. package/dist/esm/sessions/stale_session_error.js +31 -0
  157. package/dist/esm/sessions/state.js +8 -4
  158. package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
  159. package/dist/esm/skills/loader.js +51 -17
  160. package/dist/esm/telemetry/setup.js +1 -2
  161. package/dist/esm/telemetry/tracing.js +151 -74
  162. package/dist/esm/tools/agent_tool.js +44 -0
  163. package/dist/esm/tools/apihub_tool/apihub_toolset.js +101 -0
  164. package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
  165. package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
  166. package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
  167. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +245 -0
  168. package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
  169. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +629 -0
  170. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +219 -0
  171. package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +158 -0
  172. package/dist/esm/tools/example_tool.js +13 -1
  173. package/dist/esm/tools/function_tool.js +316 -0
  174. package/dist/esm/tools/google_api_tool/google_api_tool.js +73 -0
  175. package/dist/esm/tools/google_api_tool/google_api_toolset.js +146 -0
  176. package/dist/esm/tools/google_api_tool/google_api_toolsets.js +94 -0
  177. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
  178. package/dist/esm/tools/google_api_tool/index.js +31 -0
  179. package/dist/esm/tools/load_artifacts_tool.js +10 -5
  180. package/dist/esm/tools/load_memory_tool.js +12 -10
  181. package/dist/esm/tools/mcp/index.js +6 -0
  182. package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
  183. package/dist/esm/tools/mcp/mcp_toolset.js +1 -14
  184. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
  185. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
  186. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
  187. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  188. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
  189. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
  190. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
  191. package/dist/esm/tools/openapi_tool/openapi_toolset.js +6 -12
  192. package/dist/esm/tools/openapi_tool/rest_api_tool.js +17 -1
  193. package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
  194. package/dist/esm/tools/toolbox_toolset.js +148 -0
  195. package/dist/esm/tools/webmcp/webmcp_toolset.js +1 -14
  196. package/dist/esm/utils/client_labels.js +19 -2
  197. package/dist/esm/utils/env_aware_utils.js +6 -8
  198. package/dist/esm/utils/error_utils.js +9 -10
  199. package/dist/esm/utils/failover_utils.js +1 -1
  200. package/dist/esm/utils/file_extension_utils.js +11 -0
  201. package/dist/esm/utils/file_utils.js +2 -23
  202. package/dist/esm/utils/gemini_schema_util.js +27 -7
  203. package/dist/esm/utils/json_utils.js +21 -0
  204. package/dist/esm/utils/live_connection_utils.js +4 -5
  205. package/dist/esm/utils/logger_node.js +11 -1
  206. package/dist/esm/utils/object_notation_utils.js +4 -2
  207. package/dist/esm/utils/output_schema_utils.js +5 -2
  208. package/dist/esm/utils/streaming_utils.js +11 -11
  209. package/dist/esm/utils/task.js +1 -1
  210. package/dist/esm/version.js +1 -1
  211. package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
  212. package/dist/types/a2a/agent_card.d.ts +44 -1
  213. package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
  214. package/dist/types/a2a/index.d.ts +1 -0
  215. package/dist/types/agents/agent_engine_client.d.ts +37 -0
  216. package/dist/types/agents/base_agent.d.ts +12 -0
  217. package/dist/types/agents/functions.d.ts +33 -1
  218. package/dist/types/agents/invocation_context.d.ts +20 -1
  219. package/dist/types/agents/langgraph_agent.d.ts +153 -0
  220. package/dist/types/agents/llm_agent.d.ts +5 -1
  221. package/dist/types/agents/processors/content_processor_utils.d.ts +4 -2
  222. package/dist/types/agents/processors/nl_planning_processor.d.ts +2 -1
  223. package/dist/types/auth/auth_handler.d.ts +28 -1
  224. package/dist/types/auth/auth_schemes.d.ts +13 -0
  225. package/dist/types/cli/cli_eval.d.ts +173 -0
  226. package/dist/types/cli/utils/envs.d.ts +23 -0
  227. package/dist/types/cli/utils/evals.d.ts +47 -0
  228. package/dist/types/cli/utils/logs.d.ts +38 -0
  229. package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
  230. package/dist/types/code_executors/code_executor_context.d.ts +1 -0
  231. package/dist/types/code_executors/container_code_executor.d.ts +17 -5
  232. package/dist/types/common.d.ts +24 -5
  233. package/dist/types/errors/input_validation_error.d.ts +2 -1
  234. package/dist/types/events/event.d.ts +4 -0
  235. package/dist/types/examples/example_util.d.ts +17 -0
  236. package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
  237. package/dist/types/index.d.ts +19 -2
  238. package/dist/types/models/gemini_llm_connection.d.ts +6 -7
  239. package/dist/types/models/routed_llm.d.ts +1 -1
  240. package/dist/types/plugins/base_plugin.d.ts +0 -10
  241. package/dist/types/runner/in_memory_runner.d.ts +2 -1
  242. package/dist/types/runner/runner.d.ts +34 -0
  243. package/dist/types/sessions/base_session_service.d.ts +5 -0
  244. package/dist/types/sessions/database_session_service.d.ts +17 -1
  245. package/dist/types/sessions/stale_session_error.d.ts +21 -0
  246. package/dist/types/sessions/state.d.ts +5 -1
  247. package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
  248. package/dist/types/skills/loader.d.ts +3 -2
  249. package/dist/types/skills/skill.d.ts +1 -1
  250. package/dist/types/telemetry/tracing.d.ts +20 -4
  251. package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +115 -0
  252. package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
  253. package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
  254. package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
  255. package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +109 -0
  256. package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
  257. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +229 -0
  258. package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
  259. package/dist/types/tools/application_integration_tool/integration_connector_tool.d.ts +70 -0
  260. package/dist/types/tools/base_toolset.d.ts +6 -5
  261. package/dist/types/tools/example_tool.d.ts +10 -0
  262. package/dist/types/tools/function_tool.d.ts +32 -0
  263. package/dist/types/tools/google_api_tool/google_api_tool.d.ts +37 -0
  264. package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +55 -0
  265. package/dist/types/tools/google_api_tool/google_api_toolsets.d.ts +48 -0
  266. package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +165 -0
  267. package/dist/types/tools/google_api_tool/index.d.ts +10 -0
  268. package/dist/types/tools/load_artifacts_tool.d.ts +14 -1
  269. package/dist/types/tools/load_memory_tool.d.ts +23 -1
  270. package/dist/types/tools/mcp/index.d.ts +3 -0
  271. package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
  272. package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
  273. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
  274. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
  275. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +12 -0
  276. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +8 -0
  277. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
  278. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +5 -0
  279. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +10 -0
  280. package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
  281. package/dist/types/tools/toolbox_toolset.d.ts +159 -0
  282. package/dist/types/utils/client_labels.d.ts +2 -1
  283. package/dist/types/utils/env_aware_utils.d.ts +18 -2
  284. package/dist/types/utils/error_utils.d.ts +7 -0
  285. package/dist/types/utils/file_utils.d.ts +6 -1
  286. package/dist/types/utils/gemini_schema_util.d.ts +9 -2
  287. package/dist/types/utils/json_utils.d.ts +11 -0
  288. package/dist/types/utils/object_notation_utils.d.ts +7 -0
  289. package/dist/types/utils/output_schema_utils.d.ts +3 -2
  290. package/dist/types/utils/simple_zod_to_json.d.ts +1 -2
  291. package/dist/types/utils/streaming_utils.d.ts +11 -4
  292. package/dist/types/version.d.ts +1 -1
  293. package/dist/web/index_web.js +117 -110
  294. package/dist/web/index_web.js.map +4 -4
  295. package/package.json +38 -26
  296. package/dist/cjs/models/gemini_continuation.js +0 -232
  297. package/dist/esm/models/gemini_continuation.js +0 -205
  298. package/dist/types/models/gemini_continuation.d.ts +0 -59
@@ -43,10 +43,12 @@ __export(loader_exports, {
43
43
  });
44
44
  module.exports = __toCommonJS(loader_exports);
45
45
  var import_adm_zip = __toESM(require("adm-zip"), 1);
46
- var import_js_yaml = __toESM(require("js-yaml"), 1);
46
+ var yaml = __toESM(require("js-yaml"), 1);
47
47
  var import_node_buffer = require("node:buffer");
48
48
  var fs = __toESM(require("node:fs/promises"), 1);
49
49
  var path = __toESM(require("node:path"), 1);
50
+ var import_input_validation_error = require("../errors/input_validation_error.js");
51
+ var import_not_found_error = require("../errors/not_found_error.js");
50
52
  var import_logger = require("../utils/logger.js");
51
53
  var import_skill = require("./skill.js");
52
54
  /**
@@ -126,24 +128,37 @@ async function loadDir(directoryPath) {
126
128
  return files;
127
129
  }
128
130
  __name(loadDir, "loadDir");
131
+ const FRONTMATTER_BOM = "\uFEFF";
132
+ const FRONTMATTER_PATTERN = /^---[ \t]*\r?\n(?:([\s\S]*?)\r?\n)??---[ \t]*(?:\r?\n|$)/;
129
133
  function parseFrontmatterYaml(content) {
130
- if (!content.startsWith("---")) {
131
- throw new Error("SKILL.md must start with YAML frontmatter (---)");
134
+ var _a;
135
+ const text = content.startsWith(FRONTMATTER_BOM) ? content.slice(FRONTMATTER_BOM.length) : content;
136
+ if (!text.startsWith("---")) {
137
+ throw new import_input_validation_error.InputValidationError(
138
+ "SKILL.md must start with YAML frontmatter (---)"
139
+ );
132
140
  }
133
- const parts = content.split("---");
134
- if (parts.length < 3) {
135
- throw new Error("SKILL.md frontmatter not properly closed with ---");
141
+ const match = FRONTMATTER_PATTERN.exec(text);
142
+ if (!match) {
143
+ throw new import_input_validation_error.InputValidationError(
144
+ "SKILL.md frontmatter not properly closed with ---"
145
+ );
136
146
  }
137
- const frontmatterStr = parts[1];
138
- const body = parts.filter((_, i) => i >= 2).join("---").trim();
147
+ const frontmatterStr = (_a = match[1]) != null ? _a : "";
148
+ const body = text.slice(match[0].length).trim();
139
149
  try {
140
- const parsed = import_js_yaml.default.load(frontmatterStr);
150
+ const parsed = yaml.load(frontmatterStr);
141
151
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
142
- throw new Error("SKILL.md frontmatter must be a YAML mapping");
152
+ throw new import_input_validation_error.InputValidationError(
153
+ "SKILL.md frontmatter must be a YAML mapping"
154
+ );
143
155
  }
144
156
  return { raw: parsed, body };
145
157
  } catch (e) {
146
- throw new Error(`Invalid YAML in frontmatter: ${e.message}`);
158
+ throw new import_input_validation_error.InputValidationError(
159
+ `Invalid YAML in frontmatter: ${e.message}`,
160
+ { cause: e }
161
+ );
147
162
  }
148
163
  }
149
164
  __name(parseFrontmatterYaml, "parseFrontmatterYaml");
@@ -151,7 +166,10 @@ function validateFrontmatter(raw) {
151
166
  try {
152
167
  return import_skill.FrontmatterSchema.parse(raw);
153
168
  } catch (e) {
154
- throw new Error(`Invalid YAML in frontmatter: ${e.message}`);
169
+ throw new import_input_validation_error.InputValidationError(
170
+ `Invalid YAML in frontmatter: ${e.message}`,
171
+ { cause: e }
172
+ );
155
173
  }
156
174
  }
157
175
  __name(validateFrontmatter, "validateFrontmatter");
@@ -198,6 +216,18 @@ __name(loadSkillFromDir, "loadSkillFromDir");
198
216
  async function validateSkillDir(skillDir) {
199
217
  const problems = [];
200
218
  const resolvedDir = path.resolve(skillDir);
219
+ try {
220
+ const stats = await fs.stat(resolvedDir);
221
+ if (!stats.isDirectory()) {
222
+ return [`'${resolvedDir}' is not a directory.`];
223
+ }
224
+ } catch (e) {
225
+ const code = e.code;
226
+ if (code === "ENOENT" || code === "ENOTDIR") {
227
+ return [`Directory '${resolvedDir}' does not exist.`];
228
+ }
229
+ return [`Failed to access '${resolvedDir}': ${e.message}`];
230
+ }
201
231
  let skill;
202
232
  try {
203
233
  skill = await loadSkillFile(resolvedDir);
@@ -247,7 +277,7 @@ async function loadSkillFile(skillDir) {
247
277
  );
248
278
  }
249
279
  if (!skillMdPath) {
250
- throw new Error(
280
+ throw new import_not_found_error.NotFoundError(
251
281
  `SKILL.md (or any case variation like skill.md) not found in '${skillDir}'.`
252
282
  );
253
283
  }
@@ -255,7 +285,7 @@ async function loadSkillFile(skillDir) {
255
285
  const frontmatter = import_skill.FrontmatterSchema.parse(parsed);
256
286
  const dirName = path.basename(resolvedDir);
257
287
  if (dirName !== frontmatter.name) {
258
- throw new Error(
288
+ throw new import_input_validation_error.InputValidationError(
259
289
  `Skill name '${frontmatter.name}' does not match directory name '${dirName}'.`
260
290
  );
261
291
  }
@@ -317,7 +347,9 @@ function loadSkillFromZipBuffer(zipBuffer) {
317
347
  const entries = zip.getEntries();
318
348
  for (const entry of entries) {
319
349
  if (isDangerousZipEntryName(entry.entryName)) {
320
- throw new Error(`Dangerous zip entry ignored: ${entry.entryName}`);
350
+ throw new import_input_validation_error.InputValidationError(
351
+ `Dangerous zip entry ignored: ${entry.entryName}`
352
+ );
321
353
  }
322
354
  }
323
355
  let skillMdContent = "";
@@ -329,15 +361,17 @@ function loadSkillFromZipBuffer(zipBuffer) {
329
361
  }
330
362
  }
331
363
  if (!skillMdContent) {
332
- throw new Error("SKILL.md not found in zipped filesystem.");
364
+ throw new import_not_found_error.NotFoundError("SKILL.md not found in zipped filesystem.");
333
365
  }
334
366
  const { raw, body } = parseFrontmatterYaml(skillMdContent);
335
367
  const skillName = raw["name"];
336
368
  if (!skillName) {
337
- throw new Error("SKILL.md frontmatter must contain 'name'");
369
+ throw new import_input_validation_error.InputValidationError("SKILL.md frontmatter must contain 'name'");
338
370
  }
339
371
  if (typeof skillName !== "string" || !isBareSkillName(skillName)) {
340
- throw new Error(`Invalid skill name in SKILL.md: ${String(skillName)}`);
372
+ throw new import_input_validation_error.InputValidationError(
373
+ `Invalid skill name in SKILL.md: ${String(skillName)}`
374
+ );
341
375
  }
342
376
  const frontmatter = validateFrontmatter(raw);
343
377
  const references = {};
@@ -59,7 +59,6 @@ function maybeSetOtelProviders(otelHooksToSetup = [], otelResource) {
59
59
  spanProcessors
60
60
  });
61
61
  tracerProvider.register();
62
- import_api.trace.setGlobalTracerProvider(tracerProvider);
63
62
  }
64
63
  if (metricReaders.length > 0) {
65
64
  const meterProvider = new import_sdk_metrics.MeterProvider({
@@ -25,6 +25,7 @@ var __copyProps = (to, from, except, desc) => {
25
25
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
26
  var tracing_exports = {};
27
27
  __export(tracing_exports, {
28
+ resolveErrorType: () => resolveErrorType,
28
29
  runAsyncGeneratorWithOtelContext: () => runAsyncGeneratorWithOtelContext,
29
30
  traceAgentInvocation: () => traceAgentInvocation,
30
31
  traceCallLlm: () => traceCallLlm,
@@ -36,6 +37,7 @@ __export(tracing_exports, {
36
37
  tracer: () => tracer
37
38
  });
38
39
  module.exports = __toCommonJS(tracing_exports);
40
+ var import_genai = require("@google/genai");
39
41
  var import_api = require("@opentelemetry/api");
40
42
  var import_version = require("../version.js");
41
43
  /**
@@ -43,21 +45,46 @@ var import_version = require("../version.js");
43
45
  * Copyright 2025 Google LLC
44
46
  * SPDX-License-Identifier: Apache-2.0
45
47
  */
46
- const GEN_AI_AGENT_DESCRIPTION = "gen_ai.agent.description";
47
- const GEN_AI_AGENT_NAME = "gen_ai.agent.name";
48
- const GEN_AI_CONVERSATION_ID = "gen_ai.conversation.id";
49
- const GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
50
- const GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
51
- const GEN_AI_TOOL_DESCRIPTION = "gen_ai.tool.description";
52
- const GEN_AI_TOOL_NAME = "gen_ai.tool.name";
53
- const GEN_AI_TOOL_TYPE = "gen_ai.tool.type";
54
- const ADK_WORKFLOW_NAME = "adk.workflow.name";
55
- const ADK_NODE_PATH = "adk.node.path";
56
- const ADK_NODE_RUN_ID = "adk.node.run_id";
57
- const ADK_NODE_ATTEMPT = "adk.node.attempt";
58
- const ADK_NODE_STATUS = "adk.node.status";
59
- const ADK_NODE_INTERRUPT_COUNT = "adk.node.interrupt_count";
60
- const tracer = import_api.trace.getTracer("gcp.vertex.agent", import_version.version);
48
+ var GenAiAttr = /* @__PURE__ */ ((GenAiAttr2) => {
49
+ GenAiAttr2["AGENT_DESCRIPTION"] = "gen_ai.agent.description";
50
+ GenAiAttr2["AGENT_NAME"] = "gen_ai.agent.name";
51
+ GenAiAttr2["CONVERSATION_ID"] = "gen_ai.conversation.id";
52
+ GenAiAttr2["OPERATION_NAME"] = "gen_ai.operation.name";
53
+ GenAiAttr2["SYSTEM"] = "gen_ai.system";
54
+ GenAiAttr2["TOOL_CALL_ID"] = "gen_ai.tool.call.id";
55
+ GenAiAttr2["TOOL_DESCRIPTION"] = "gen_ai.tool.description";
56
+ GenAiAttr2["TOOL_NAME"] = "gen_ai.tool.name";
57
+ GenAiAttr2["TOOL_TYPE"] = "gen_ai.tool.type";
58
+ GenAiAttr2["REQUEST_MODEL"] = "gen_ai.request.model";
59
+ GenAiAttr2["REQUEST_TOP_P"] = "gen_ai.request.top_p";
60
+ GenAiAttr2["REQUEST_MAX_TOKENS"] = "gen_ai.request.max_tokens";
61
+ GenAiAttr2["USAGE_INPUT_TOKENS"] = "gen_ai.usage.input_tokens";
62
+ GenAiAttr2["USAGE_OUTPUT_TOKENS"] = "gen_ai.usage.output_tokens";
63
+ GenAiAttr2["RESPONSE_FINISH_REASONS"] = "gen_ai.response.finish_reasons";
64
+ return GenAiAttr2;
65
+ })(GenAiAttr || {});
66
+ var AdkAttr = /* @__PURE__ */ ((AdkAttr2) => {
67
+ AdkAttr2["WORKFLOW_NAME"] = "adk.workflow.name";
68
+ AdkAttr2["NODE_PATH"] = "adk.node.path";
69
+ AdkAttr2["NODE_RUN_ID"] = "adk.node.run_id";
70
+ AdkAttr2["NODE_ATTEMPT"] = "adk.node.attempt";
71
+ AdkAttr2["NODE_STATUS"] = "adk.node.status";
72
+ AdkAttr2["NODE_INTERRUPT_COUNT"] = "adk.node.interrupt_count";
73
+ return AdkAttr2;
74
+ })(AdkAttr || {});
75
+ var GcpAttr = /* @__PURE__ */ ((GcpAttr2) => {
76
+ GcpAttr2["INVOCATION_ID"] = "gcp.vertex.agent.invocation_id";
77
+ GcpAttr2["SESSION_ID"] = "gcp.vertex.agent.session_id";
78
+ GcpAttr2["EVENT_ID"] = "gcp.vertex.agent.event_id";
79
+ GcpAttr2["LLM_REQUEST"] = "gcp.vertex.agent.llm_request";
80
+ GcpAttr2["LLM_RESPONSE"] = "gcp.vertex.agent.llm_response";
81
+ GcpAttr2["TOOL_CALL_ARGS"] = "gcp.vertex.agent.tool_call_args";
82
+ GcpAttr2["TOOL_RESPONSE"] = "gcp.vertex.agent.tool_response";
83
+ GcpAttr2["DATA"] = "gcp.vertex.agent.data";
84
+ return GcpAttr2;
85
+ })(GcpAttr || {});
86
+ const GEN_AI_SYSTEM_VALUE = "gcp.vertex.agent";
87
+ const tracer = import_api.trace.getTracer(GEN_AI_SYSTEM_VALUE, import_version.version);
61
88
  function safeJsonSerialize(obj) {
62
89
  try {
63
90
  return JSON.stringify(obj);
@@ -73,11 +100,11 @@ function traceAgentInvocation({
73
100
  const span = import_api.trace.getActiveSpan();
74
101
  if (!span) return;
75
102
  span.setAttributes({
76
- [GEN_AI_OPERATION_NAME]: "invoke_agent",
103
+ ["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_agent",
77
104
  // Conditionally Required
78
- [GEN_AI_AGENT_DESCRIPTION]: agent.description,
79
- [GEN_AI_AGENT_NAME]: agent.name,
80
- [GEN_AI_CONVERSATION_ID]: invocationContext.session.id
105
+ ["gen_ai.agent.description" /* AGENT_DESCRIPTION */]: agent.description,
106
+ ["gen_ai.agent.name" /* AGENT_NAME */]: agent.name,
107
+ ["gen_ai.conversation.id" /* CONVERSATION_ID */]: invocationContext.session.id
81
108
  });
82
109
  }
83
110
  __name(traceAgentInvocation, "traceAgentInvocation");
@@ -89,10 +116,10 @@ function traceWorkflowInvocation({
89
116
  const span = import_api.trace.getActiveSpan();
90
117
  if (!span) return;
91
118
  span.setAttributes({
92
- [GEN_AI_OPERATION_NAME]: "invoke_workflow",
93
- [GEN_AI_CONVERSATION_ID]: sessionId,
94
- [ADK_WORKFLOW_NAME]: workflowName,
95
- [ADK_NODE_PATH]: nodePath
119
+ ["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_workflow",
120
+ ["gen_ai.conversation.id" /* CONVERSATION_ID */]: sessionId,
121
+ ["adk.workflow.name" /* WORKFLOW_NAME */]: workflowName,
122
+ ["adk.node.path" /* NODE_PATH */]: nodePath
96
123
  });
97
124
  }
98
125
  __name(traceWorkflowInvocation, "traceWorkflowInvocation");
@@ -106,40 +133,83 @@ function traceNodeExecution({
106
133
  const span = import_api.trace.getActiveSpan();
107
134
  if (!span) return;
108
135
  span.setAttributes({
109
- [GEN_AI_OPERATION_NAME]: "execute_node",
110
- [ADK_NODE_PATH]: nodePath,
111
- [ADK_NODE_RUN_ID]: runId,
112
- [ADK_NODE_ATTEMPT]: attempt,
113
- [ADK_NODE_STATUS]: status,
114
- [ADK_NODE_INTERRUPT_COUNT]: interruptCount
136
+ ["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_node",
137
+ ["adk.node.path" /* NODE_PATH */]: nodePath,
138
+ ["adk.node.run_id" /* NODE_RUN_ID */]: runId,
139
+ ["adk.node.attempt" /* NODE_ATTEMPT */]: attempt,
140
+ ["adk.node.status" /* NODE_STATUS */]: status,
141
+ ["adk.node.interrupt_count" /* NODE_INTERRUPT_COUNT */]: interruptCount
115
142
  });
116
143
  }
117
144
  __name(traceNodeExecution, "traceNodeExecution");
118
- function traceToolCall({
119
- tool,
120
- args,
121
- functionResponseEvent
122
- }) {
145
+ function resolveErrorType(error) {
123
146
  var _a, _b;
124
- const span = import_api.trace.getActiveSpan();
147
+ if (error !== null && (typeof error === "object" || typeof error === "function")) {
148
+ try {
149
+ const errorObject = error;
150
+ const customErrorType = (_a = errorObject.errorType) != null ? _a : errorObject.error_type;
151
+ if (typeof customErrorType === "string" || typeof customErrorType === "number") {
152
+ return String(customErrorType);
153
+ }
154
+ if (error instanceof import_genai.ApiError) {
155
+ return String(error.status);
156
+ }
157
+ const constructorName = (_b = errorObject.constructor) == null ? void 0 : _b.name;
158
+ if (typeof constructorName === "string" && constructorName.length > 0) {
159
+ return constructorName;
160
+ }
161
+ } catch {
162
+ }
163
+ }
164
+ return typeof error;
165
+ }
166
+ __name(resolveErrorType, "resolveErrorType");
167
+ function traceToolCall(params) {
168
+ var _a, _b, _c;
169
+ const {
170
+ tool,
171
+ args,
172
+ functionResponseEvent,
173
+ invocationContext,
174
+ error,
175
+ errorType
176
+ } = params;
177
+ const span = (_a = params.span) != null ? _a : import_api.trace.getActiveSpan();
125
178
  if (!span) return;
179
+ const hasError = Object.hasOwn(params, "error");
180
+ const failureType = hasError ? resolveErrorType(error) : errorType;
181
+ if (hasError) {
182
+ let exception;
183
+ try {
184
+ exception = error instanceof Error ? error : resolveErrorType(error);
185
+ } catch {
186
+ exception = resolveErrorType(error);
187
+ }
188
+ span.recordException(exception);
189
+ }
190
+ if (failureType !== void 0) {
191
+ span.setAttribute("error.type", failureType);
192
+ span.setStatus({ code: import_api.SpanStatusCode.ERROR, message: failureType });
193
+ }
126
194
  span.setAttributes({
127
- [GEN_AI_OPERATION_NAME]: "execute_tool",
128
- [GEN_AI_TOOL_DESCRIPTION]: tool.description || "",
129
- [GEN_AI_TOOL_NAME]: tool.name,
195
+ ["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
196
+ ["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
197
+ ["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: tool.description || "",
198
+ ["gen_ai.tool.name" /* TOOL_NAME */]: tool.name,
130
199
  // e.g. FunctionTool
131
- [GEN_AI_TOOL_TYPE]: tool.constructor.name,
200
+ ["gen_ai.tool.type" /* TOOL_TYPE */]: tool.constructor.name,
201
+ ["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
132
202
  // Setting empty llm request and response (as UI expect these) while not
133
203
  // applicable for tool_response.
134
- "gcp.vertex.agent.llm_request": "{}",
135
- "gcp.vertex.agent.llm_response": "{}",
136
- "gcp.vertex.agent.tool_call_args": shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
204
+ ["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
205
+ ["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}",
206
+ ["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
137
207
  });
138
208
  let toolCallId = "<not specified>";
139
209
  let toolResponse = "<not specified>";
140
- if ((_a = functionResponseEvent.content) == null ? void 0 : _a.parts) {
210
+ if ((_b = functionResponseEvent == null ? void 0 : functionResponseEvent.content) == null ? void 0 : _b.parts) {
141
211
  const responseParts = functionResponseEvent.content.parts;
142
- const functionResponse = (_b = responseParts[0]) == null ? void 0 : _b.functionResponse;
212
+ const functionResponse = (_c = responseParts[0]) == null ? void 0 : _c.functionResponse;
143
213
  if (functionResponse == null ? void 0 : functionResponse.id) {
144
214
  toolCallId = functionResponse.id;
145
215
  }
@@ -151,32 +221,35 @@ function traceToolCall({
151
221
  toolResponse = { result: toolResponse };
152
222
  }
153
223
  span.setAttributes({
154
- [GEN_AI_TOOL_CALL_ID]: toolCallId,
155
- "gcp.vertex.agent.event_id": functionResponseEvent.id,
156
- "gcp.vertex.agent.tool_response": shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
224
+ ["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: toolCallId,
225
+ ...functionResponseEvent ? { ["gcp.vertex.agent.event_id" /* EVENT_ID */]: functionResponseEvent.id } : {},
226
+ ["gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
157
227
  });
158
228
  }
159
229
  __name(traceToolCall, "traceToolCall");
160
230
  function traceMergedToolCalls({
161
231
  responseEventId,
162
- functionResponseEvent
232
+ functionResponseEvent,
233
+ invocationContext
163
234
  }) {
164
235
  const span = import_api.trace.getActiveSpan();
165
236
  if (!span) return;
166
237
  span.setAttributes({
167
- [GEN_AI_OPERATION_NAME]: "execute_tool",
168
- [GEN_AI_TOOL_NAME]: "(merged tools)",
169
- [GEN_AI_TOOL_DESCRIPTION]: "(merged tools)",
170
- [GEN_AI_TOOL_CALL_ID]: responseEventId,
171
- "gcp.vertex.agent.tool_call_args": "N/A",
172
- "gcp.vertex.agent.event_id": responseEventId,
238
+ ["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
239
+ ["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
240
+ ["gen_ai.tool.name" /* TOOL_NAME */]: "(merged tools)",
241
+ ["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: "(merged tools)",
242
+ ["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: responseEventId,
243
+ ["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
244
+ ["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: "N/A",
245
+ ["gcp.vertex.agent.event_id" /* EVENT_ID */]: responseEventId,
173
246
  // Setting empty llm request and response (as UI expect these) while not
174
247
  // applicable for tool_response.
175
- "gcp.vertex.agent.llm_request": "{}",
176
- "gcp.vertex.agent.llm_response": "{}"
248
+ ["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
249
+ ["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}"
177
250
  });
178
251
  span.setAttribute(
179
- "gcp.vertex.agent.tool_response",
252
+ "gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */,
180
253
  shouldAddRequestResponseToSpans() ? safeJsonSerialize(functionResponseEvent) : "{}"
181
254
  );
182
255
  }
@@ -191,43 +264,43 @@ function traceCallLlm({
191
264
  const span = import_api.trace.getActiveSpan();
192
265
  if (!span) return;
193
266
  span.setAttributes({
194
- "gen_ai.system": "gcp.vertex.agent",
195
- "gen_ai.request.model": llmRequest.model,
196
- ...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { [GEN_AI_AGENT_NAME]: invocationContext.agent.name } : {},
197
- "gcp.vertex.agent.invocation_id": invocationContext.invocationId,
198
- "gcp.vertex.agent.session_id": invocationContext.session.id,
199
- "gcp.vertex.agent.event_id": eventId,
267
+ ["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
268
+ ["gen_ai.request.model" /* REQUEST_MODEL */]: llmRequest.model,
269
+ ...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { ["gen_ai.agent.name" /* AGENT_NAME */]: invocationContext.agent.name } : {},
270
+ ["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
271
+ ["gcp.vertex.agent.session_id" /* SESSION_ID */]: invocationContext.session.id,
272
+ ["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId,
200
273
  // Consider removing once GenAI SDK provides a way to record this info.
201
- "gcp.vertex.agent.llm_request": shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
274
+ ["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
202
275
  });
203
276
  if ((_b = llmRequest.config) == null ? void 0 : _b.topP) {
204
- span.setAttribute("gen_ai.request.top_p", llmRequest.config.topP);
277
+ span.setAttribute("gen_ai.request.top_p" /* REQUEST_TOP_P */, llmRequest.config.topP);
205
278
  }
206
279
  if (((_c = llmRequest.config) == null ? void 0 : _c.maxOutputTokens) !== void 0) {
207
280
  span.setAttribute(
208
- "gen_ai.request.max_tokens",
281
+ "gen_ai.request.max_tokens" /* REQUEST_MAX_TOKENS */,
209
282
  llmRequest.config.maxOutputTokens
210
283
  );
211
284
  }
212
285
  span.setAttribute(
213
- "gcp.vertex.agent.llm_response",
286
+ "gcp.vertex.agent.llm_response" /* LLM_RESPONSE */,
214
287
  shouldAddRequestResponseToSpans() ? safeJsonSerialize(llmResponse) : "{}"
215
288
  );
216
289
  if (llmResponse.usageMetadata) {
217
290
  span.setAttribute(
218
- "gen_ai.usage.input_tokens",
291
+ "gen_ai.usage.input_tokens" /* USAGE_INPUT_TOKENS */,
219
292
  llmResponse.usageMetadata.promptTokenCount || 0
220
293
  );
221
294
  }
222
295
  if ((_d = llmResponse.usageMetadata) == null ? void 0 : _d.candidatesTokenCount) {
223
296
  span.setAttribute(
224
- "gen_ai.usage.output_tokens",
297
+ "gen_ai.usage.output_tokens" /* USAGE_OUTPUT_TOKENS */,
225
298
  llmResponse.usageMetadata.candidatesTokenCount
226
299
  );
227
300
  }
228
301
  if (llmResponse.finishReason) {
229
302
  const finishReasonValue = typeof llmResponse.finishReason === "string" ? llmResponse.finishReason.toLowerCase() : String(llmResponse.finishReason).toLowerCase();
230
- span.setAttribute("gen_ai.response.finish_reasons", [finishReasonValue]);
303
+ span.setAttribute("gen_ai.response.finish_reasons" /* RESPONSE_FINISH_REASONS */, [finishReasonValue]);
231
304
  }
232
305
  }
233
306
  __name(traceCallLlm, "traceCallLlm");
@@ -239,11 +312,11 @@ function traceSendData({
239
312
  const span = import_api.trace.getActiveSpan();
240
313
  if (!span) return;
241
314
  span.setAttributes({
242
- "gcp.vertex.agent.invocation_id": invocationContext.invocationId,
243
- "gcp.vertex.agent.event_id": eventId
315
+ ["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
316
+ ["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId
244
317
  });
245
318
  span.setAttribute(
246
- "gcp.vertex.agent.data",
319
+ "gcp.vertex.agent.data" /* DATA */,
247
320
  shouldAddRequestResponseToSpans() ? safeJsonSerialize(data) : "{}"
248
321
  );
249
322
  }
@@ -307,6 +380,7 @@ function shouldAddRequestResponseToSpans() {
307
380
  __name(shouldAddRequestResponseToSpans, "shouldAddRequestResponseToSpans");
308
381
  // Annotate the CommonJS export names for ESM import in node:
309
382
  0 && (module.exports = {
383
+ resolveErrorType,
310
384
  runAsyncGeneratorWithOtelContext,
311
385
  traceAgentInvocation,
312
386
  traceCallLlm,
@@ -38,12 +38,50 @@ var import_variant_utils = require("../utils/variant_utils.js");
38
38
  var import_state = require("../sessions/state.js");
39
39
  var import_base_tool = require("./base_tool.js");
40
40
  var import_forwarding_artifact_service = require("./forwarding_artifact_service.js");
41
+ var import_schema = require("../utils/schema.js");
42
+ var import_simple_zod_to_json = require("../utils/simple_zod_to_json.js");
41
43
  /**
42
44
  * @license
43
45
  * Copyright 2025 Google LLC
44
46
  * SPDX-License-Identifier: Apache-2.0
45
47
  */
46
48
  var _a, _b;
49
+ function excludeNone(value) {
50
+ if (Array.isArray(value)) {
51
+ return value.map((item) => excludeNone(item));
52
+ }
53
+ if (value !== null && typeof value === "object") {
54
+ const result = {};
55
+ for (const [key, val] of Object.entries(value)) {
56
+ if (val !== null && val !== void 0) {
57
+ result[key] = excludeNone(val);
58
+ }
59
+ }
60
+ return result;
61
+ }
62
+ return value;
63
+ }
64
+ __name(excludeNone, "excludeNone");
65
+ function validateAndStripAgentInput(agent, args) {
66
+ var _a2;
67
+ if (typeof args !== "object" || args === null || Array.isArray(args)) {
68
+ throw new Error("AgentTool input args must be a plain object.");
69
+ }
70
+ const schema = (0, import_simple_zod_to_json.isZodSchema)(agent.inputSchema) ? agent.inputSchema : (_a2 = agent.inputSchemaSource) != null ? _a2 : agent.inputSchema;
71
+ const validated = (0, import_schema.parseWithSchema)(schema, args);
72
+ return excludeNone(validated);
73
+ }
74
+ __name(validateAndStripAgentInput, "validateAndStripAgentInput");
75
+ function validateAndStripAgentOutput(agent, mergedText) {
76
+ var _a2;
77
+ const parsed = JSON.parse(mergedText);
78
+ const validated = typeof agent.validateOutput === "function" ? agent.validateOutput(parsed) : (0, import_schema.parseWithSchema)(
79
+ (0, import_simple_zod_to_json.isZodSchema)(agent.outputSchema) ? agent.outputSchema : (_a2 = agent.outputSchemaSource) != null ? _a2 : agent.outputSchema,
80
+ parsed
81
+ );
82
+ return excludeNone(validated);
83
+ }
84
+ __name(validateAndStripAgentOutput, "validateAndStripAgentOutput");
47
85
  const AGENT_TOOL_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.agentTool");
48
86
  function isAgentTool(obj) {
49
87
  return typeof obj === "object" && obj !== null && AGENT_TOOL_SIGNATURE_SYMBOL in obj && obj[AGENT_TOOL_SIGNATURE_SYMBOL] === true;
@@ -97,6 +135,9 @@ const _AgentTool = class _AgentTool extends (_b = import_base_tool.BaseTool, _a
97
135
  }) {
98
136
  var _a2, _b2, _c, _d, _e, _f;
99
137
  const hasInputSchema = (0, import_llm_agent.isLlmAgent)(this.agent) && this.agent.inputSchema;
138
+ if (hasInputSchema && (0, import_llm_agent.isLlmAgent)(this.agent)) {
139
+ args = validateAndStripAgentInput(this.agent, args);
140
+ }
100
141
  const content = {
101
142
  role: "user",
102
143
  parts: [
@@ -151,6 +192,9 @@ const _AgentTool = class _AgentTool extends (_b = import_base_tool.BaseTool, _a
151
192
  }
152
193
  const hasOutputSchema = (0, import_llm_agent.isLlmAgent)(this.agent) && this.agent.outputSchema;
153
194
  const mergedText = lastEvent.content.parts.filter((part) => !part.thought).map((part) => part.text).filter((text) => text).join("\n");
195
+ if (hasOutputSchema && (0, import_llm_agent.isLlmAgent)(this.agent)) {
196
+ return validateAndStripAgentOutput(this.agent, mergedText);
197
+ }
154
198
  return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
155
199
  }
156
200
  };