@google/adk 1.1.0 → 1.3.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 (300) hide show
  1. package/dist/cjs/agents/base_agent.js +19 -1
  2. package/dist/cjs/agents/functions.js +4 -0
  3. package/dist/cjs/agents/instructions.js +81 -33
  4. package/dist/cjs/agents/invocation_context.js +0 -1
  5. package/dist/cjs/agents/llm_agent.js +52 -5
  6. package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  7. package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
  8. package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
  9. package/dist/cjs/agents/processors/content_request_processor.js +7 -0
  10. package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
  11. package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
  12. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
  13. package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  14. package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
  15. package/dist/cjs/auth/auth_preprocessor.js +12 -10
  16. package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
  17. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
  18. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  19. package/dist/cjs/code_executors/code_executor_context.js +7 -7
  20. package/dist/cjs/common.js +50 -0
  21. package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
  22. package/dist/cjs/context/token_based_context_compactor.js +1 -1
  23. package/dist/cjs/events/event.js +4 -2
  24. package/dist/cjs/index.js +14 -0
  25. package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
  26. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +122 -0
  27. package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
  28. package/dist/cjs/integrations/agent_registry/types.js +50 -0
  29. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
  30. package/dist/cjs/models/gemini_llm_connection.js +62 -19
  31. package/dist/cjs/models/google_llm.js +26 -8
  32. package/dist/cjs/plugins/security_plugin.js +16 -0
  33. package/dist/cjs/runner/in_memory_runner.js +10 -5
  34. package/dist/cjs/runner/runner.js +32 -2
  35. package/dist/cjs/sessions/base_session_service.js +13 -2
  36. package/dist/cjs/sessions/database_session_service.js +51 -5
  37. package/dist/cjs/sessions/db/schema.js +45 -10
  38. package/dist/cjs/sessions/in_memory_session_service.js +72 -15
  39. package/dist/cjs/sessions/registry.js +4 -0
  40. package/dist/cjs/sessions/vertex_ai_session_service.js +429 -0
  41. package/dist/cjs/skills/gcp_skill_registry.js +104 -0
  42. package/dist/cjs/skills/loader.js +65 -0
  43. package/dist/cjs/skills/skill_registry.js +27 -0
  44. package/dist/cjs/tools/agent_tool.js +10 -5
  45. package/dist/cjs/tools/exit_loop_tool.js +9 -0
  46. package/dist/cjs/tools/function_tool.js +7 -2
  47. package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
  48. package/dist/cjs/tools/long_running_tool.js +2 -1
  49. package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
  50. package/dist/cjs/tools/mcp/mcp_tool.js +10 -6
  51. package/dist/cjs/tools/mcp/mcp_toolset.js +26 -3
  52. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
  53. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
  54. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
  55. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
  56. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
  57. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +127 -0
  58. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
  59. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
  60. package/dist/cjs/tools/skill/load_skill_resource_tool.js +27 -28
  61. package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
  62. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
  63. package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
  64. package/dist/cjs/tools/skill/skill_toolset.js +40 -5
  65. package/dist/cjs/tools/vertex_rag_retrieval_tool.js +64 -0
  66. package/dist/cjs/utils/async_queue.js +88 -0
  67. package/dist/cjs/utils/case_utils.js +53 -0
  68. package/dist/cjs/utils/env_aware_utils.js +4 -0
  69. package/dist/cjs/utils/file_utils.js +28 -0
  70. package/dist/cjs/utils/gemini_schema_util.js +18 -0
  71. package/dist/cjs/utils/live_connection_utils.js +284 -0
  72. package/dist/cjs/utils/model_name.js +9 -0
  73. package/dist/cjs/utils/partial_copy.js +51 -0
  74. package/dist/cjs/utils/streaming_utils.js +169 -122
  75. package/dist/cjs/utils/vertex_ai_utils.js +50 -0
  76. package/dist/cjs/version.js +1 -1
  77. package/dist/esm/agents/base_agent.js +19 -1
  78. package/dist/esm/agents/functions.js +4 -0
  79. package/dist/esm/agents/instructions.js +81 -33
  80. package/dist/esm/agents/invocation_context.js +0 -1
  81. package/dist/esm/agents/llm_agent.js +53 -5
  82. package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  83. package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
  84. package/dist/esm/agents/processors/content_processor_utils.js +35 -23
  85. package/dist/esm/agents/processors/content_request_processor.js +7 -0
  86. package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
  87. package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
  88. package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
  89. package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  90. package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
  91. package/dist/esm/auth/auth_preprocessor.js +12 -10
  92. package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
  93. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  94. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  95. package/dist/esm/code_executors/code_executor_context.js +7 -7
  96. package/dist/esm/common.js +43 -1
  97. package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
  98. package/dist/esm/context/token_based_context_compactor.js +1 -1
  99. package/dist/esm/events/event.js +4 -2
  100. package/dist/esm/index.js +11 -0
  101. package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
  102. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +96 -0
  103. package/dist/esm/integrations/agent_registry/helpers.js +28 -0
  104. package/dist/esm/integrations/agent_registry/types.js +20 -0
  105. package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
  106. package/dist/esm/models/gemini_llm_connection.js +62 -19
  107. package/dist/esm/models/google_llm.js +26 -8
  108. package/dist/esm/plugins/security_plugin.js +16 -0
  109. package/dist/esm/runner/in_memory_runner.js +10 -5
  110. package/dist/esm/runner/runner.js +32 -2
  111. package/dist/esm/sessions/base_session_service.js +11 -1
  112. package/dist/esm/sessions/database_session_service.js +51 -5
  113. package/dist/esm/sessions/db/schema.js +44 -10
  114. package/dist/esm/sessions/in_memory_session_service.js +74 -16
  115. package/dist/esm/sessions/registry.js +7 -0
  116. package/dist/esm/sessions/vertex_ai_session_service.js +405 -0
  117. package/dist/esm/skills/gcp_skill_registry.js +78 -0
  118. package/dist/esm/skills/loader.js +64 -0
  119. package/dist/esm/skills/skill_registry.js +7 -0
  120. package/dist/esm/tools/agent_tool.js +10 -5
  121. package/dist/esm/tools/exit_loop_tool.js +9 -0
  122. package/dist/esm/tools/function_tool.js +7 -2
  123. package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
  124. package/dist/esm/tools/long_running_tool.js +2 -1
  125. package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
  126. package/dist/esm/tools/mcp/mcp_tool.js +10 -6
  127. package/dist/esm/tools/mcp/mcp_toolset.js +26 -3
  128. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
  129. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  130. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  131. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
  132. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  133. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  134. package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
  135. package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
  136. package/dist/esm/tools/skill/load_skill_resource_tool.js +26 -27
  137. package/dist/esm/tools/skill/load_skill_tool.js +12 -1
  138. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
  139. package/dist/esm/tools/skill/search_skills_tool.js +82 -0
  140. package/dist/esm/tools/skill/skill_toolset.js +40 -5
  141. package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
  142. package/dist/esm/utils/async_queue.js +60 -0
  143. package/dist/esm/utils/case_utils.js +25 -0
  144. package/dist/esm/utils/env_aware_utils.js +4 -0
  145. package/dist/esm/utils/file_utils.js +26 -0
  146. package/dist/esm/utils/gemini_schema_util.js +18 -0
  147. package/dist/esm/utils/live_connection_utils.js +256 -0
  148. package/dist/esm/utils/model_name.js +8 -0
  149. package/dist/esm/utils/partial_copy.js +23 -0
  150. package/dist/esm/utils/streaming_utils.js +167 -121
  151. package/dist/esm/utils/vertex_ai_utils.js +22 -0
  152. package/dist/esm/version.js +1 -1
  153. package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
  154. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
  155. package/dist/types/a2a/event_converter_utils.d.ts +14 -1
  156. package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
  157. package/dist/types/a2a/part_converter_utils.d.ts +51 -6
  158. package/dist/types/agents/invocation_context.d.ts +0 -9
  159. package/dist/types/agents/llm_agent.d.ts +14 -0
  160. package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
  161. package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
  162. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +12 -0
  163. package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
  164. package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
  165. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
  166. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +11 -0
  167. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +14 -1
  168. package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
  169. package/dist/types/agents/run_config.d.ts +15 -0
  170. package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
  171. package/dist/types/common.d.ts +19 -1
  172. package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
  173. package/dist/types/events/event_actions.d.ts +25 -8
  174. package/dist/types/events/structured_events.d.ts +13 -0
  175. package/dist/types/examples/example_util.d.ts +25 -0
  176. package/dist/types/index.d.ts +6 -0
  177. package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
  178. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +62 -0
  179. package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
  180. package/dist/types/integrations/agent_registry/types.d.ts +101 -0
  181. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
  182. package/dist/types/models/base_llm_connection.d.ts +10 -0
  183. package/dist/types/models/gemini_llm_connection.d.ts +15 -4
  184. package/dist/types/models/llm_response.d.ts +10 -1
  185. package/dist/types/plugins/security_plugin.d.ts +30 -0
  186. package/dist/types/runner/in_memory_runner.d.ts +28 -1
  187. package/dist/types/runner/runner.d.ts +47 -0
  188. package/dist/types/sessions/base_session_service.d.ts +22 -0
  189. package/dist/types/sessions/database_session_service.d.ts +1 -1
  190. package/dist/types/sessions/db/schema.d.ts +1 -0
  191. package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
  192. package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
  193. package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
  194. package/dist/types/skills/loader.d.ts +7 -0
  195. package/dist/types/skills/skill.d.ts +1 -1
  196. package/dist/types/skills/skill_registry.d.ts +29 -0
  197. package/dist/types/tools/exit_loop_tool.d.ts +9 -0
  198. package/dist/types/tools/function_tool.d.ts +22 -2
  199. package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
  200. package/dist/types/tools/long_running_tool.d.ts +11 -1
  201. package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
  202. package/dist/types/tools/mcp/mcp_toolset.d.ts +2 -1
  203. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
  204. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
  205. package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
  206. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
  207. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
  208. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
  209. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
  210. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
  211. package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
  212. package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
  213. package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
  214. package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
  215. package/dist/types/utils/async_queue.d.ts +18 -0
  216. package/dist/types/utils/case_utils.d.ts +12 -0
  217. package/dist/types/utils/file_utils.d.ts +2 -0
  218. package/dist/types/utils/live_connection_utils.d.ts +30 -0
  219. package/dist/types/utils/model_name.d.ts +7 -0
  220. package/dist/types/utils/partial_copy.d.ts +13 -0
  221. package/dist/types/utils/streaming_utils.d.ts +7 -17
  222. package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
  223. package/dist/types/version.d.ts +1 -1
  224. package/dist/web/agents/base_agent.js +31 -1
  225. package/dist/web/agents/functions.js +4 -0
  226. package/dist/web/agents/instructions.js +81 -33
  227. package/dist/web/agents/invocation_context.js +0 -1
  228. package/dist/web/agents/llm_agent.js +53 -5
  229. package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  230. package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
  231. package/dist/web/agents/processors/content_processor_utils.js +53 -23
  232. package/dist/web/agents/processors/content_request_processor.js +7 -0
  233. package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
  234. package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
  235. package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
  236. package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  237. package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
  238. package/dist/web/auth/auth_preprocessor.js +12 -10
  239. package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
  240. package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  241. package/dist/web/code_executors/code_execution_utils.js +1 -1
  242. package/dist/web/code_executors/code_executor_context.js +7 -7
  243. package/dist/web/common.js +43 -1
  244. package/dist/web/context/summarizers/llm_summarizer.js +11 -0
  245. package/dist/web/context/token_based_context_compactor.js +1 -1
  246. package/dist/web/events/event.js +4 -2
  247. package/dist/web/index.js +11 -0
  248. package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
  249. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +109 -0
  250. package/dist/web/integrations/agent_registry/helpers.js +28 -0
  251. package/dist/web/integrations/agent_registry/types.js +20 -0
  252. package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
  253. package/dist/web/models/gemini_llm_connection.js +75 -19
  254. package/dist/web/models/google_llm.js +26 -8
  255. package/dist/web/plugins/security_plugin.js +16 -0
  256. package/dist/web/runner/in_memory_runner.js +10 -5
  257. package/dist/web/runner/runner.js +32 -2
  258. package/dist/web/sessions/base_session_service.js +11 -1
  259. package/dist/web/sessions/database_session_service.js +51 -5
  260. package/dist/web/sessions/db/schema.js +44 -10
  261. package/dist/web/sessions/in_memory_session_service.js +74 -16
  262. package/dist/web/sessions/registry.js +7 -0
  263. package/dist/web/sessions/vertex_ai_session_service.js +416 -0
  264. package/dist/web/skills/gcp_skill_registry.js +78 -0
  265. package/dist/web/skills/loader.js +64 -0
  266. package/dist/web/skills/skill_registry.js +7 -0
  267. package/dist/web/tools/agent_tool.js +10 -5
  268. package/dist/web/tools/exit_loop_tool.js +9 -0
  269. package/dist/web/tools/function_tool.js +7 -2
  270. package/dist/web/tools/google_maps_grounding_tool.js +54 -0
  271. package/dist/web/tools/long_running_tool.js +2 -1
  272. package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
  273. package/dist/web/tools/mcp/mcp_tool.js +10 -6
  274. package/dist/web/tools/mcp/mcp_toolset.js +26 -3
  275. package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
  276. package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  277. package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  278. package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
  279. package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  280. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  281. package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
  282. package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
  283. package/dist/web/tools/skill/load_skill_resource_tool.js +26 -27
  284. package/dist/web/tools/skill/load_skill_tool.js +12 -1
  285. package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
  286. package/dist/web/tools/skill/search_skills_tool.js +82 -0
  287. package/dist/web/tools/skill/skill_toolset.js +40 -5
  288. package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
  289. package/dist/web/utils/async_queue.js +60 -0
  290. package/dist/web/utils/case_utils.js +25 -0
  291. package/dist/web/utils/env_aware_utils.js +4 -0
  292. package/dist/web/utils/file_utils.js +26 -0
  293. package/dist/web/utils/gemini_schema_util.js +18 -0
  294. package/dist/web/utils/live_connection_utils.js +254 -0
  295. package/dist/web/utils/model_name.js +8 -0
  296. package/dist/web/utils/partial_copy.js +23 -0
  297. package/dist/web/utils/streaming_utils.js +221 -122
  298. package/dist/web/utils/vertex_ai_utils.js +22 -0
  299. package/dist/web/version.js +1 -1
  300. package/package.json +4 -1
@@ -1,5 +1,24 @@
1
1
  import {createRequire as topLevelCreateRequire} from 'module';
2
2
  const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
3
22
  /**
4
23
  * @license
5
24
  * Copyright 2025 Google LLC
@@ -109,17 +128,19 @@ function convertForeignEvent(event) {
109
128
  text: "[".concat(event.author, "] said: ").concat(part.text)
110
129
  });
111
130
  } else if (part.functionCall) {
112
- const argsText = safeStringify(part.functionCall.args);
113
131
  (_d = content.parts) == null ? void 0 : _d.push({
114
- text: "[".concat(event.author, "] called tool `").concat(part.functionCall.name, "` with parameters: ").concat(argsText)
132
+ text: "[".concat(event.author, "] called tool `").concat(part.functionCall.name, "` with parameters: ").concat(safeStringify(
133
+ part.functionCall.args
134
+ ))
115
135
  });
116
136
  } else if (part.functionResponse) {
117
- const responseText = safeStringify(part.functionResponse.response);
118
137
  (_e = content.parts) == null ? void 0 : _e.push({
119
- text: "[".concat(event.author, "] tool `").concat(part.functionResponse.name, "` returned result: ").concat(responseText)
138
+ text: "[".concat(event.author, "] tool `").concat(part.functionResponse.name, "` returned result: ").concat(safeStringify(
139
+ part.functionResponse.response
140
+ ))
120
141
  });
121
142
  } else {
122
- (_f = content.parts) == null ? void 0 : _f.push(part);
143
+ (_f = content.parts) == null ? void 0 : _f.push(cloneDeep(part));
123
144
  }
124
145
  }
125
146
  return createEvent({
@@ -135,9 +156,11 @@ function mergeFunctionResponseEvents(events) {
135
156
  if (events.length === 0) {
136
157
  throw new Error("Cannot merge an empty list of events.");
137
158
  }
138
- const mergedEvent = createEvent(events[0]);
139
- const partsInMergedEvent = ((_a = mergedEvent.content) == null ? void 0 : _a.parts) || [];
140
- if (partsInMergedEvent.length === 0) {
159
+ const mergedEvent = createEvent(__spreadProps(__spreadValues({}, events[0]), {
160
+ content: events[0].content ? cloneDeep(events[0].content) : void 0
161
+ }));
162
+ const partsInMergedEvent = (_a = mergedEvent.content) == null ? void 0 : _a.parts;
163
+ if (!partsInMergedEvent || partsInMergedEvent.length === 0) {
141
164
  throw new Error("There should be at least one function_response part.");
142
165
  }
143
166
  const partIndicesInMergedEvent = {};
@@ -152,16 +175,17 @@ function mergeFunctionResponseEvents(events) {
152
175
  throw new Error("There should be at least one function_response part.");
153
176
  }
154
177
  for (const part of event.content.parts) {
155
- if (part.functionResponse && part.functionResponse.id) {
156
- const functionCallId = part.functionResponse.id;
178
+ const clonedPart = cloneDeep(part);
179
+ if (clonedPart.functionResponse && clonedPart.functionResponse.id) {
180
+ const functionCallId = clonedPart.functionResponse.id;
157
181
  if (functionCallId in partIndicesInMergedEvent) {
158
- partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
182
+ partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = clonedPart;
159
183
  } else {
160
- partsInMergedEvent.push(part);
184
+ partsInMergedEvent.push(clonedPart);
161
185
  partIndicesInMergedEvent[functionCallId] = partsInMergedEvent.length - 1;
162
186
  }
163
187
  } else {
164
- partsInMergedEvent.push(part);
188
+ partsInMergedEvent.push(clonedPart);
165
189
  }
166
190
  }
167
191
  }
@@ -176,7 +200,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
176
200
  if (!(functionResponses == null ? void 0 : functionResponses.length)) {
177
201
  return events;
178
202
  }
179
- let functionResponsesIds = new Set(
203
+ const functionResponsesIds = new Set(
180
204
  functionResponses.filter((response) => !!response.id).map((response) => response.id)
181
205
  );
182
206
  const secondLatestEvent = events.at(-2);
@@ -190,16 +214,16 @@ function rearrangeEventsForLatestFunctionResponse(events) {
190
214
  }
191
215
  }
192
216
  }
193
- let functionCallEventIdx = -1;
217
+ let match;
194
218
  for (let idx = events.length - 2; idx >= 0; idx--) {
195
219
  const event = events[idx];
196
220
  const functionCalls = getFunctionCalls(event);
197
221
  if (!(functionCalls == null ? void 0 : functionCalls.length)) {
198
222
  continue;
199
223
  }
224
+ let matchedInEvent = false;
200
225
  for (const functionCall of functionCalls) {
201
226
  if (functionCall.id && functionResponsesIds.has(functionCall.id)) {
202
- functionCallEventIdx = idx;
203
227
  const functionCallIds = new Set(
204
228
  functionCalls.map((fc) => fc.id).filter((id) => !!id)
205
229
  );
@@ -213,12 +237,16 @@ function rearrangeEventsForLatestFunctionResponse(events) {
213
237
  ), ", function response") + " ids provided: ".concat(Array.from(functionResponsesIds).join(", "))
214
238
  );
215
239
  }
216
- functionResponsesIds = functionCallIds;
240
+ match = { eventIdx: idx, responseIds: functionCallIds };
241
+ matchedInEvent = true;
217
242
  break;
218
243
  }
219
244
  }
245
+ if (matchedInEvent) {
246
+ break;
247
+ }
220
248
  }
221
- if (functionCallEventIdx === -1) {
249
+ if (!match) {
222
250
  throw new Error(
223
251
  "No function call event found for function responses ids: ".concat(Array.from(
224
252
  functionResponsesIds
@@ -226,17 +254,18 @@ function rearrangeEventsForLatestFunctionResponse(events) {
226
254
  );
227
255
  }
228
256
  const functionResponseEvents = [];
229
- for (let idx = functionCallEventIdx + 1; idx < events.length - 1; idx++) {
257
+ const activeResponses = match.responseIds;
258
+ for (let idx = match.eventIdx + 1; idx < events.length - 1; idx++) {
230
259
  const event = events[idx];
231
260
  const responses = getFunctionResponses(event);
232
261
  if (responses && responses.some(
233
- (response) => response.id && functionResponsesIds.has(response.id)
262
+ (response) => response.id && activeResponses.has(response.id)
234
263
  )) {
235
264
  functionResponseEvents.push(event);
236
265
  }
237
266
  }
238
267
  functionResponseEvents.push(events[events.length - 1]);
239
- const resultEvents = events.slice(0, functionCallEventIdx + 1);
268
+ const resultEvents = events.slice(0, match.eventIdx + 1);
240
269
  resultEvents.push(mergeFunctionResponseEvents(functionResponseEvents));
241
270
  return resultEvents;
242
271
  }
@@ -275,7 +304,7 @@ function rearrangeEventsForAsyncFunctionResponsesInHistory(events) {
275
304
  continue;
276
305
  }
277
306
  if (functionResponseEventsIndices.size === 1) {
278
- const [responseIndex] = [...functionResponseEventsIndices];
307
+ const [responseIndex] = Array.from(functionResponseEventsIndices);
279
308
  resultEvents.push(events[responseIndex]);
280
309
  } else {
281
310
  const indicesArray = Array.from(functionResponseEventsIndices).sort(
@@ -314,5 +343,6 @@ function convertCompactedEvent(event) {
314
343
  }
315
344
  export {
316
345
  getContents,
317
- getCurrentTurnContents
346
+ getCurrentTurnContents,
347
+ mergeFunctionResponseEvents
318
348
  };
@@ -28,6 +28,13 @@ import {
28
28
  getCurrentTurnContents
29
29
  } from "./content_processor_utils.js";
30
30
  class ContentRequestProcessor {
31
+ /**
32
+ * Fills {@link LlmRequest.contents} based on the session event history and
33
+ * agent configuration.
34
+ *
35
+ * @param invocationContext - The current invocation context.
36
+ * @param llmRequest - The request whose contents field will be populated.
37
+ */
31
38
  // eslint-disable-next-line require-yield
32
39
  runAsync(invocationContext, llmRequest) {
33
40
  return __asyncGenerator(this, null, function* () {
@@ -23,9 +23,21 @@ var __asyncGenerator = (__this, __arguments, generator) => {
23
23
  */
24
24
  import { ContextCompactionTrigger } from "../../plugins/base_plugin.js";
25
25
  class ContextCompactorRequestProcessor {
26
+ /**
27
+ * @param compactors - Ordered list of compactors to evaluate; the first one
28
+ * that reports it should compact will perform the compaction.
29
+ */
26
30
  constructor(compactors) {
27
31
  this.compactors = compactors;
28
32
  }
33
+ /**
34
+ * Evaluates compactors in priority order. The first compactor that indicates
35
+ * it should compact will compact the session history, fire plugin hooks, and
36
+ * yield any newly generated events. Iteration stops after one compaction.
37
+ *
38
+ * @param invocationContext - The current invocation context.
39
+ * @param _llmRequest - Unused; present to satisfy the {@link BaseLlmRequestProcessor} interface.
40
+ */
29
41
  runAsync(invocationContext, _llmRequest) {
30
42
  return __asyncGenerator(this, null, function* () {
31
43
  for (const compactor of this.compactors) {
@@ -24,6 +24,13 @@ var __asyncGenerator = (__this, __arguments, generator) => {
24
24
  import { appendInstructions } from "../../models/llm_request.js";
25
25
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
26
26
  class IdentityLlmRequestProcessor extends BaseLlmRequestProcessor {
27
+ /**
28
+ * Appends agent name and description as identity instructions to the system
29
+ * prompt of the request.
30
+ *
31
+ * @param invocationContext - The current invocation context.
32
+ * @param llmRequest - The request object to append instructions to.
33
+ */
27
34
  // eslint-disable-next-line require-yield
28
35
  runAsync(invocationContext, llmRequest) {
29
36
  return __asyncGenerator(this, null, function* () {
@@ -64,6 +64,11 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
64
64
  }
65
65
  appendInstructions(llmRequest, [instructionWithState]);
66
66
  }
67
+ if (agent.outputSchema && agent.tools && agent.tools.length > 0) {
68
+ appendInstructions(llmRequest, [
69
+ 'To output the final result, you must call the "set_model_response" function with the appropriate values. Do not output anything else.'
70
+ ]);
71
+ }
67
72
  });
68
73
  }
69
74
  }
@@ -34,7 +34,15 @@ import { isLlmAgent } from "../llm_agent.js";
34
34
  import { ReadonlyContext } from "../readonly_context.js";
35
35
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
36
36
  class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
37
- /** Handles tool confirmation information to build the LLM request. */
37
+ /**
38
+ * Resumes tool calls that were paused for user confirmation, re-invoking
39
+ * them with the confirmed or denied decision before the next LLM turn.
40
+ *
41
+ * @param invocationContext - The current invocation context, including the
42
+ * session event history used to locate pending confirmation responses.
43
+ * @yields Function response events for tools that have been confirmed and
44
+ * are ready to resume.
45
+ */
38
46
  runAsync(invocationContext) {
39
47
  return __asyncGenerator(this, null, function* () {
40
48
  const agent = invocationContext.agent;
@@ -26,7 +26,13 @@ import { isLlmAgent } from "../llm_agent.js";
26
26
  import { ReadonlyContext } from "../readonly_context.js";
27
27
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
28
28
  class ToolFilterRequestProcessor extends BaseLlmRequestProcessor {
29
- /** Filters the set of tools on the request based on plugins. */
29
+ /**
30
+ * Invokes plugin-based tool filtering and updates {@link LlmRequest.allowedTools}
31
+ * with the reduced tool set if any plugin returns a filtered result.
32
+ *
33
+ * @param invocationContext - The current invocation context.
34
+ * @param llmRequest - The request whose allowed tools may be restricted.
35
+ */
30
36
  // eslint-disable-next-line require-yield
31
37
  runAsync(invocationContext, llmRequest) {
32
38
  return __asyncGenerator(this, null, function* () {
@@ -33,6 +33,7 @@ import {
33
33
  getFunctionResponses
34
34
  } from "../events/event.js";
35
35
  import { State } from "../sessions/state.js";
36
+ import { camelCaseKeys } from "../utils/case_utils.js";
36
37
  import { AuthHandler } from "./auth_handler.js";
37
38
  const TOOLSET_AUTH_CREDENTIAL_ID_PREFIX = "_adk_toolset_auth_";
38
39
  async function storeAuthAndCollectResumeTargets(events, authFcIds, authResponses, state) {
@@ -41,17 +42,15 @@ async function storeAuthAndCollectResumeTargets(events, authFcIds, authResponses
41
42
  const eventFunctionCalls = getFunctionCalls(event);
42
43
  for (const functionCall of eventFunctionCalls) {
43
44
  if (functionCall.id && authFcIds.has(functionCall.id) && functionCall.name === REQUEST_EUC_FUNCTION_CALL_NAME) {
44
- const args = functionCall.args;
45
- if (args && args.authConfig) {
46
- requestedAuthConfigById[functionCall.id] = args.authConfig;
45
+ const args = camelCaseKeys(functionCall.args);
46
+ const authConfig = args == null ? void 0 : args.authConfig;
47
+ if (authConfig) {
48
+ requestedAuthConfigById[functionCall.id] = authConfig;
47
49
  }
48
50
  }
49
51
  }
50
52
  }
51
53
  for (const fcId of authFcIds) {
52
- if (!(fcId in authResponses)) {
53
- continue;
54
- }
55
54
  const authConfig = authResponses[fcId];
56
55
  const requestedAuthConfig = requestedAuthConfigById[fcId];
57
56
  if (requestedAuthConfig && requestedAuthConfig.credentialKey) {
@@ -69,12 +68,15 @@ async function storeAuthAndCollectResumeTargets(events, authFcIds, authResponses
69
68
  const eventFunctionCalls = getFunctionCalls(event);
70
69
  for (const functionCall of eventFunctionCalls) {
71
70
  if (functionCall.id === fcId && functionCall.name === REQUEST_EUC_FUNCTION_CALL_NAME) {
72
- const args = functionCall.args;
73
- if (args && args.functionCallId) {
74
- if (args.functionCallId.startsWith(TOOLSET_AUTH_CREDENTIAL_ID_PREFIX)) {
71
+ const args = camelCaseKeys(
72
+ functionCall.args
73
+ );
74
+ const functionCallId = args == null ? void 0 : args.functionCallId;
75
+ if (functionCallId) {
76
+ if (functionCallId.startsWith(TOOLSET_AUTH_CREDENTIAL_ID_PREFIX)) {
75
77
  continue;
76
78
  }
77
- toolsToResume.add(args.functionCallId);
79
+ toolsToResume.add(functionCallId);
78
80
  }
79
81
  }
80
82
  }
@@ -123,6 +123,18 @@ class OAuth2DiscoveryManager {
123
123
  return void 0;
124
124
  }
125
125
  }
126
+ function normaliseHostname(raw) {
127
+ const stripped = raw.replace(/^\[|\]$/g, "");
128
+ const m = stripped.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
129
+ if (m) {
130
+ const hi = parseInt(m[1], 16);
131
+ const lo = parseInt(m[2], 16);
132
+ return [hi >> 8 & 255, hi & 255, lo >> 8 & 255, lo & 255].join(".");
133
+ }
134
+ const mDot = stripped.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
135
+ if (mDot) return mDot[1];
136
+ return raw;
137
+ }
126
138
  function validateDiscoveryUrl(urlStr) {
127
139
  try {
128
140
  const url = new URL(urlStr);
@@ -130,8 +142,8 @@ function validateDiscoveryUrl(urlStr) {
130
142
  logger.warn("Unsafe protocol for discovery URL: ".concat(url.protocol));
131
143
  return false;
132
144
  }
133
- const host = url.hostname.toLowerCase();
134
- if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
145
+ const host = normaliseHostname(url.hostname.toLowerCase());
146
+ if (host === "localhost" || host === "metadata.google.internal" || host === "metadata.goog" || host.startsWith("127.") || host === "[::1]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
135
147
  logger.warn("Unsafe host for discovery URL: ".concat(host));
136
148
  return false;
137
149
  }
@@ -143,6 +155,18 @@ function validateDiscoveryUrl(urlStr) {
143
155
  return false;
144
156
  }
145
157
  }
158
+ const cgnatMatch = host.match(/^100\.(\d+)\./);
159
+ if (cgnatMatch) {
160
+ const secondOctet = parseInt(cgnatMatch[1], 10);
161
+ if (secondOctet >= 64 && secondOctet <= 127) {
162
+ logger.warn("Unsafe host for discovery URL: ".concat(host));
163
+ return false;
164
+ }
165
+ }
166
+ if (/^\[(f[cd][0-9a-f]{2}|fe[89ab][0-9a-f]):/i.test(url.hostname)) {
167
+ logger.warn("Unsafe host for discovery URL: ".concat(url.hostname));
168
+ return false;
169
+ }
146
170
  return true;
147
171
  } catch (e) {
148
172
  logger.warn("Failed to parse URL for validation ".concat(urlStr, ": ").concat(e));
@@ -0,0 +1,281 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __decorateClass = (decorators, target, key, kind) => {
6
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
7
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
8
+ if (decorator = decorators[i])
9
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10
+ if (kind && result) __defProp(target, key, result);
11
+ return result;
12
+ };
13
+ /**
14
+ * @license
15
+ * Copyright 2026 Google LLC
16
+ * SPDX-License-Identifier: Apache-2.0
17
+ */
18
+ import { Client } from "@google-cloud/vertexai";
19
+ import { Language } from "@google-cloud/vertexai/build/src/genai/types.js";
20
+ import { experimental } from "../utils/experimental.js";
21
+ import { guessMimeType } from "../utils/file_utils.js";
22
+ const SANDBOX_PATTERN = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)\/sandboxEnvironments\/(\d+)$/;
23
+ const ENGINE_PATTERN = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)$/;
24
+ import { logger } from "../utils/logger.js";
25
+ import { BaseCodeExecutor } from "./base_code_executor.js";
26
+ import {
27
+ CodeExecutionLanguage
28
+ } from "./code_execution_utils.js";
29
+ const DEFAULT_MAX_ATTEMPTS = 180;
30
+ const DEFAULT_SANDBOX_TTL = "31536000s";
31
+ const DEFAULT_SANDBOX_DISPLAY_NAME = "default_sandbox";
32
+ const DEFAULT_ENGINE_DISPLAY_NAME = "default_engine";
33
+ function mapLanguage(lang) {
34
+ switch (lang) {
35
+ case CodeExecutionLanguage.PYTHON:
36
+ return Language.LANGUAGE_PYTHON;
37
+ case CodeExecutionLanguage.JAVASCRIPT:
38
+ return Language.LANGUAGE_JAVASCRIPT;
39
+ default:
40
+ throw new Error("Unsupported language for Agent Engine Sandbox: ".concat(lang));
41
+ }
42
+ }
43
+ let AgentEngineSandboxCodeExecutor = class extends BaseCodeExecutor {
44
+ constructor(options = {}) {
45
+ super();
46
+ this.sandboxResourceName = options.sandboxResourceName;
47
+ this.agentEngineResourceName = options.agentEngineResourceName;
48
+ this.projectId = options.projectId || process.env.GOOGLE_CLOUD_PROJECT;
49
+ this.location = options.location || process.env.GOOGLE_CLOUD_LOCATION || "us-central1";
50
+ if (this.sandboxResourceName) {
51
+ const match = this.sandboxResourceName.match(SANDBOX_PATTERN);
52
+ if (match) {
53
+ this.projectId = match[1];
54
+ this.location = match[2];
55
+ } else {
56
+ throw new Error(
57
+ "Invalid sandbox resource name: ".concat(this.sandboxResourceName)
58
+ );
59
+ }
60
+ } else if (this.agentEngineResourceName) {
61
+ const match = this.agentEngineResourceName.match(ENGINE_PATTERN);
62
+ if (match) {
63
+ this.projectId = match[1];
64
+ this.location = match[2];
65
+ } else {
66
+ throw new Error(
67
+ "Invalid agent engine resource name: ".concat(this.agentEngineResourceName)
68
+ );
69
+ }
70
+ }
71
+ if (options.client) {
72
+ this.client = options.client;
73
+ } else {
74
+ if (!this.projectId) {
75
+ throw new Error("Project ID is required.");
76
+ }
77
+ this.client = new Client({
78
+ project: this.projectId,
79
+ location: this.location
80
+ });
81
+ }
82
+ }
83
+ async executeCode(params) {
84
+ var _a;
85
+ const { invocationContext, codeExecutionInput } = params;
86
+ const language = mapLanguage(codeExecutionInput.language);
87
+ const agentEngineName = await this.getOrCreateAgentEngine();
88
+ const sandboxName = await this.getOrCreateSandbox(
89
+ invocationContext,
90
+ agentEngineName,
91
+ language
92
+ );
93
+ const inputs = [
94
+ {
95
+ mimeType: "application/json",
96
+ data: Buffer.from(
97
+ JSON.stringify({ code: codeExecutionInput.code })
98
+ ).toString("base64")
99
+ }
100
+ ];
101
+ if (codeExecutionInput.inputFiles) {
102
+ for (const file of codeExecutionInput.inputFiles) {
103
+ inputs.push({
104
+ mimeType: file.mimeType,
105
+ data: file.content,
106
+ // Assumed to be already base64 encoded based on CodeExecutionInput definition
107
+ metadata: {
108
+ attributes: {
109
+ file_name: Buffer.from(file.name).toString("base64")
110
+ }
111
+ }
112
+ });
113
+ }
114
+ }
115
+ logger.debug("Executing code in sandbox ".concat(sandboxName, "..."));
116
+ const response = await this.client.agentEnginesInternal.sandboxes.executeCodeInternal({
117
+ name: sandboxName,
118
+ inputs
119
+ });
120
+ let stdout = "";
121
+ let stderr = "";
122
+ const outputFiles = [];
123
+ if (response.outputs) {
124
+ for (const output of response.outputs) {
125
+ const attributes = ((_a = output.metadata) == null ? void 0 : _a.attributes) || {};
126
+ const encodedFileName = attributes["file_name"];
127
+ const fileName = encodedFileName ? Buffer.from(encodedFileName, "base64").toString("utf-8") : void 0;
128
+ if (output.mimeType === "application/json" && !fileName) {
129
+ if (output.data) {
130
+ const jsonStr = Buffer.from(output.data, "base64").toString(
131
+ "utf-8"
132
+ );
133
+ try {
134
+ const jsonData = JSON.parse(jsonStr);
135
+ if (jsonData.msg_out !== void 0) {
136
+ stdout = jsonData.msg_out;
137
+ } else {
138
+ stdout = "";
139
+ }
140
+ if (jsonData.msg_err !== void 0) {
141
+ stderr = jsonData.msg_err;
142
+ } else {
143
+ stderr = "";
144
+ }
145
+ } catch (e) {
146
+ logger.warn("Failed to parse JSON output from sandbox", e);
147
+ stdout = jsonStr;
148
+ }
149
+ }
150
+ } else {
151
+ let mimeType = output.mimeType;
152
+ const name = fileName || "output_file";
153
+ if (!mimeType) {
154
+ mimeType = guessMimeType(name);
155
+ }
156
+ outputFiles.push({
157
+ name,
158
+ content: output.data || "",
159
+ mimeType
160
+ });
161
+ }
162
+ }
163
+ }
164
+ return {
165
+ stdout,
166
+ stderr,
167
+ outputFiles
168
+ };
169
+ }
170
+ async getOrCreateAgentEngine() {
171
+ if (this.agentEngineResourceName) {
172
+ return this.agentEngineResourceName;
173
+ }
174
+ if (!this.agentEngineCreationPromise) {
175
+ this.agentEngineCreationPromise = (async () => {
176
+ logger.debug(
177
+ "No Agent Engine resource name provided. Creating a new one..."
178
+ );
179
+ const operation = await this.client.agentEnginesInternal.createInternal(
180
+ {
181
+ config: {
182
+ displayName: DEFAULT_ENGINE_DISPLAY_NAME
183
+ }
184
+ }
185
+ );
186
+ let apiResponse = operation;
187
+ let attempts = 0;
188
+ while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
189
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
190
+ apiResponse = await this.client.agentEnginesInternal.getAgentOperationInternal({
191
+ operationName: operation.name
192
+ });
193
+ attempts++;
194
+ }
195
+ if (!apiResponse.done) {
196
+ throw new Error(
197
+ "Agent Engine creation operation ".concat(operation.name, " did not complete in time.")
198
+ );
199
+ }
200
+ const response = apiResponse.response;
201
+ this.agentEngineResourceName = response.name;
202
+ logger.debug("Created Agent Engine: ".concat(this.agentEngineResourceName));
203
+ return this.agentEngineResourceName;
204
+ })();
205
+ }
206
+ return this.agentEngineCreationPromise;
207
+ }
208
+ async getOrCreateSandbox(invocationContext, agentEngineName, language) {
209
+ var _a, _b;
210
+ if (this.sandboxResourceName) {
211
+ return this.sandboxResourceName;
212
+ }
213
+ const stateKey = "sandbox_name_".concat(language.toLowerCase());
214
+ let sandboxName = (_b = (_a = invocationContext.session) == null ? void 0 : _a.state) == null ? void 0 : _b[stateKey];
215
+ let createNewSandbox = false;
216
+ if (!sandboxName) {
217
+ createNewSandbox = true;
218
+ } else {
219
+ try {
220
+ const sandbox = await this.client.agentEnginesInternal.sandboxes.getInternal({
221
+ name: sandboxName
222
+ });
223
+ if (!sandbox || sandbox.state !== "STATE_RUNNING") {
224
+ createNewSandbox = true;
225
+ }
226
+ } catch (error) {
227
+ logger.debug(
228
+ "Failed to get sandbox ".concat(sandboxName, ", will create a new one"),
229
+ error
230
+ );
231
+ createNewSandbox = true;
232
+ }
233
+ }
234
+ if (createNewSandbox) {
235
+ logger.debug("Creating a new ".concat(language, " code execution sandbox..."));
236
+ const operation = await this.client.agentEnginesInternal.sandboxes.createInternal({
237
+ name: agentEngineName,
238
+ spec: {
239
+ codeExecutionEnvironment: {
240
+ codeLanguage: language
241
+ }
242
+ },
243
+ config: {
244
+ displayName: DEFAULT_SANDBOX_DISPLAY_NAME,
245
+ ttl: DEFAULT_SANDBOX_TTL
246
+ }
247
+ });
248
+ let apiResponse = operation;
249
+ let attempts = 0;
250
+ while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
251
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
252
+ apiResponse = await this.client.agentEnginesInternal.sandboxes.getSandboxOperationInternal(
253
+ {
254
+ operationName: operation.name
255
+ }
256
+ );
257
+ attempts++;
258
+ }
259
+ if (!apiResponse.done) {
260
+ throw new Error(
261
+ "Sandbox creation operation ".concat(operation.name, " did not complete in time.")
262
+ );
263
+ }
264
+ const response = apiResponse.response;
265
+ sandboxName = response.name;
266
+ if (invocationContext.session) {
267
+ if (!invocationContext.session.state) {
268
+ invocationContext.session.state = {};
269
+ }
270
+ invocationContext.session.state[stateKey] = sandboxName;
271
+ }
272
+ }
273
+ return sandboxName;
274
+ }
275
+ };
276
+ AgentEngineSandboxCodeExecutor = __decorateClass([
277
+ experimental
278
+ ], AgentEngineSandboxCodeExecutor);
279
+ export {
280
+ AgentEngineSandboxCodeExecutor
281
+ };
@@ -47,7 +47,7 @@ function extractCodeAndTruncateContent(content, codeBlockDelimiters) {
47
47
  const leadingDelimiterPattern = codeBlockDelimiters.map((d) => d[0]).join("|");
48
48
  const trailingDelimiterPattern = codeBlockDelimiters.map((d) => d[1]).join("|");
49
49
  const match = new RegExp(
50
- "?<prefix>.*?)(".concat(leadingDelimiterPattern, ")(?<codeStr>.*?)(").concat(trailingDelimiterPattern, ")(?<suffix>.*?)$"),
50
+ "(?<prefix>.*?)(".concat(leadingDelimiterPattern, ")(?<codeStr>.*?)(").concat(trailingDelimiterPattern, ")(?<suffix>.*?)$"),
51
51
  "s"
52
52
  ).exec(responseText);
53
53
  const { prefix, codeStr } = (match == null ? void 0 : match.groups) || {};