@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
@@ -27,6 +27,7 @@ __export(model_name_exports, {
27
27
  extractModelName: () => extractModelName,
28
28
  isGemini1Model: () => isGemini1Model,
29
29
  isGemini2OrAbove: () => isGemini2OrAbove,
30
+ isGemini3xFlashLive: () => isGemini3xFlashLive,
30
31
  isGeminiModel: () => isGeminiModel,
31
32
  isGeminiModelIdCheckDisabled: () => isGeminiModelIdCheckDisabled
32
33
  });
@@ -77,6 +78,13 @@ function isGemini2OrAbove(modelString) {
77
78
  const parsedVersion = parseVersion(versionString);
78
79
  return parsedVersion.valid && parsedVersion.major >= 2;
79
80
  }
81
+ function isGemini3xFlashLive(modelString) {
82
+ if (!modelString) {
83
+ return false;
84
+ }
85
+ const modelName = extractModelName(modelString);
86
+ return modelName.startsWith("gemini-3.") && modelName.includes("-flash-live");
87
+ }
80
88
  function isGeminiModelIdCheckDisabled() {
81
89
  return (0, import_env_aware_utils.getBooleanEnvVar)("ADK_DISABLE_GEMINI_MODEL_ID_CHECK");
82
90
  }
@@ -85,6 +93,7 @@ function isGeminiModelIdCheckDisabled() {
85
93
  extractModelName,
86
94
  isGemini1Model,
87
95
  isGemini2OrAbove,
96
+ isGemini3xFlashLive,
88
97
  isGeminiModel,
89
98
  isGeminiModelIdCheckDisabled
90
99
  });
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var partial_copy_exports = {};
26
+ __export(partial_copy_exports, {
27
+ partialCopy: () => partialCopy
28
+ });
29
+ module.exports = __toCommonJS(partial_copy_exports);
30
+ /**
31
+ * @license
32
+ * Copyright 2026 Google LLC
33
+ * SPDX-License-Identifier: Apache-2.0
34
+ */
35
+ function partialCopy(source, targetKeys) {
36
+ const result = {};
37
+ const sourceAsUnknown = source;
38
+ targetKeys.forEach((key) => {
39
+ const keyStr = key;
40
+ if (keyStr in source) {
41
+ result[key] = sourceAsUnknown[keyStr];
42
+ } else {
43
+ result[key] = void 0;
44
+ }
45
+ });
46
+ return result;
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ partialCopy
51
+ });
@@ -24,7 +24,8 @@ var __copyProps = (to, from, except, desc) => {
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var streaming_utils_exports = {};
26
26
  __export(streaming_utils_exports, {
27
- StreamingResponseAggregator: () => StreamingResponseAggregator
27
+ StreamingResponseAggregator: () => StreamingResponseAggregator,
28
+ isEmptyContentPart: () => isEmptyContentPart
28
29
  });
29
30
  module.exports = __toCommonJS(streaming_utils_exports);
30
31
  var import_genai = require("@google/genai");
@@ -37,15 +38,9 @@ var import_llm_response = require("../models/llm_response.js");
37
38
  * Copyright 2026 Google LLC
38
39
  * SPDX-License-Identifier: Apache-2.0
39
40
  */
40
- class StreamingResponseAggregator {
41
- constructor(isProgressiveMode = (0, import_feature_registry.isFeatureEnabled)(
42
- import_feature_registry.FeatureName.PROGRESSIVE_SSE_STREAMING
43
- )) {
44
- this.isProgressiveMode = isProgressiveMode;
45
- // For non-progressive SSE streaming mode
46
- this.text = "";
47
- this.thoughtText = "";
48
- // For progressive SSE streaming mode: accumulate parts in order
41
+ const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
42
+ class ProgressiveStrategy {
43
+ constructor() {
49
44
  this.partsSequence = [];
50
45
  this.currentTextBuffer = "";
51
46
  this.currentFcArgs = {};
@@ -110,10 +105,13 @@ class StreamingResponseAggregator {
110
105
  const pathParts = import_jsonpath_plus.JSONPath.toPathArray(jsonPath).filter(
111
106
  (p) => p !== "$" && p !== "$["
112
107
  );
108
+ if (pathParts.some((part) => UNSAFE_PROPERTY_KEYS.has(String(part)))) {
109
+ return;
110
+ }
113
111
  let current = this.currentFcArgs;
114
112
  for (let i = 0; i < pathParts.length - 1; i++) {
115
113
  const part = pathParts[i];
116
- if (!(part in current)) {
114
+ if (!Object.prototype.hasOwnProperty.call(current, part)) {
117
115
  current[part] = {};
118
116
  }
119
117
  current = current[part];
@@ -172,11 +170,6 @@ class StreamingResponseAggregator {
172
170
  if (!fc) {
173
171
  return;
174
172
  }
175
- if (part.thoughtSignature) {
176
- this.lastThoughtSignature = part.thoughtSignature;
177
- } else if (this.lastThoughtSignature) {
178
- part.thoughtSignature = this.lastThoughtSignature.toString();
179
- }
180
173
  if (fc.partialArgs || fc.willContinue) {
181
174
  if (!fc.id && !this.currentFcId) {
182
175
  fc.id = (0, import_functions.generateClientFunctionCallId)();
@@ -195,63 +188,103 @@ class StreamingResponseAggregator {
195
188
  }
196
189
  }
197
190
  }
198
- async *processResponse(response) {
199
- var _a, _b, _c;
200
- this.response = response;
201
- const llmResponse = (0, import_llm_response.createLlmResponse)(response);
202
- this.usageMetadata = llmResponse.usageMetadata;
203
- if (llmResponse.groundingMetadata) {
204
- this.groundingMetadata = llmResponse.groundingMetadata;
205
- }
206
- if (llmResponse.citationMetadata) {
207
- this.citationMetadata = llmResponse.citationMetadata;
208
- }
209
- if (llmResponse.finishReason) {
210
- this.finishReason = llmResponse.finishReason;
211
- }
191
+ async *processResponse(llmResponse) {
192
+ var _a;
212
193
  if (llmResponse.content && llmResponse.content.parts) {
213
194
  for (const part of llmResponse.content.parts) {
214
- if (part.thoughtSignature) {
215
- this.lastThoughtSignature = part.thoughtSignature;
216
- } else if (part.functionCall && this.lastThoughtSignature) {
217
- part.thoughtSignature = this.lastThoughtSignature.toString();
195
+ if (part.text) {
196
+ const isThought = (_a = part.thought) != null ? _a : false;
197
+ if (this.currentTextBuffer && isThought !== this.currentTextIsThought) {
198
+ this.flushTextBufferToSequence();
199
+ }
200
+ if (!this.currentTextBuffer) {
201
+ this.currentTextIsThought = isThought;
202
+ }
203
+ this.currentTextBuffer += part.text;
204
+ } else if (part.functionCall) {
205
+ this.processFunctionCallPart(part);
206
+ } else {
207
+ this.flushTextBufferToSequence();
208
+ this.partsSequence.push(part);
218
209
  }
219
210
  }
220
211
  }
221
- if (this.isProgressiveMode) {
222
- if (llmResponse.content && llmResponse.content.parts) {
223
- for (const part of llmResponse.content.parts) {
224
- if (part.text) {
225
- const isThought = (_a = part.thought) != null ? _a : false;
226
- if (this.currentTextBuffer && isThought !== this.currentTextIsThought) {
227
- this.flushTextBufferToSequence();
228
- }
229
- if (!this.currentTextBuffer) {
230
- this.currentTextIsThought = isThought;
231
- }
232
- this.currentTextBuffer += part.text;
233
- } else if (part.functionCall) {
234
- this.processFunctionCallPart(part);
212
+ llmResponse.partial = true;
213
+ yield llmResponse;
214
+ }
215
+ close() {
216
+ this.flushTextBufferToSequence();
217
+ this.flushFunctionCallToSequence();
218
+ const finalParts = this.partsSequence;
219
+ if (finalParts.length === 0) {
220
+ return void 0;
221
+ }
222
+ return finalParts;
223
+ }
224
+ }
225
+ class NonProgressiveStrategy {
226
+ constructor() {
227
+ this.text = "";
228
+ this.thoughtText = "";
229
+ }
230
+ async *processResponse(llmResponse) {
231
+ var _a;
232
+ if ((_a = llmResponse.content) == null ? void 0 : _a.parts) {
233
+ const nonTextParts = [];
234
+ let sawTextPart = false;
235
+ for (const part of llmResponse.content.parts) {
236
+ if (typeof part.text === "string") {
237
+ sawTextPart = true;
238
+ if (part.thought) {
239
+ this.thoughtText += part.text;
235
240
  } else {
236
- this.flushTextBufferToSequence();
237
- this.partsSequence.push(part);
241
+ this.text += part.text;
238
242
  }
243
+ continue;
244
+ }
245
+ if (part.functionCall && !part.functionCall.id) {
246
+ part.functionCall.id = (0, import_functions.generateClientFunctionCallId)();
239
247
  }
248
+ nonTextParts.push(part);
240
249
  }
241
- llmResponse.partial = true;
242
- yield llmResponse;
243
- return;
244
- }
245
- if (llmResponse.content && llmResponse.content.parts && typeof ((_b = llmResponse.content.parts[0]) == null ? void 0 : _b.text) === "string") {
246
- const part0 = llmResponse.content.parts[0];
247
- const partText = part0.text || "";
248
- if (part0.thought) {
249
- this.thoughtText += partText;
250
- } else {
251
- this.text += partText;
250
+ if (nonTextParts.length > 0) {
251
+ if (this.thoughtText || this.text) {
252
+ const parts = [];
253
+ if (this.thoughtText) {
254
+ parts.push({ text: this.thoughtText, thought: true });
255
+ }
256
+ if (this.text) {
257
+ parts.push({ text: this.text });
258
+ }
259
+ yield {
260
+ content: {
261
+ role: "model",
262
+ parts
263
+ },
264
+ usageMetadata: llmResponse.usageMetadata,
265
+ partial: false
266
+ };
267
+ this.thoughtText = "";
268
+ this.text = "";
269
+ }
270
+ yield {
271
+ ...llmResponse,
272
+ content: {
273
+ role: llmResponse.content.role,
274
+ parts: nonTextParts
275
+ },
276
+ partial: false
277
+ };
278
+ return;
279
+ }
280
+ if (sawTextPart) {
281
+ llmResponse.partial = true;
252
282
  }
253
- llmResponse.partial = true;
254
- } else if ((this.thoughtText || this.text) && (!llmResponse.content || !llmResponse.content.parts || !((_c = llmResponse.content.parts[0]) == null ? void 0 : _c.inlineData))) {
283
+ }
284
+ yield llmResponse;
285
+ }
286
+ close() {
287
+ if (this.text || this.thoughtText) {
255
288
  const parts = [];
256
289
  if (this.thoughtText) {
257
290
  parts.push({ text: this.thoughtText, thought: true });
@@ -259,75 +292,89 @@ class StreamingResponseAggregator {
259
292
  if (this.text) {
260
293
  parts.push({ text: this.text });
261
294
  }
262
- yield {
263
- content: {
264
- role: "model",
265
- parts
266
- },
267
- usageMetadata: llmResponse.usageMetadata,
268
- partial: false
269
- };
270
- this.thoughtText = "";
271
- this.text = "";
295
+ return parts;
272
296
  }
273
- yield llmResponse;
297
+ return void 0;
274
298
  }
275
- close() {
299
+ }
300
+ class StreamingResponseAggregator {
301
+ constructor(isProgressiveMode = (0, import_feature_registry.isFeatureEnabled)(
302
+ import_feature_registry.FeatureName.PROGRESSIVE_SSE_STREAMING
303
+ )) {
304
+ this.isProgressiveMode = isProgressiveMode;
305
+ this.lastThoughtSignature = {};
306
+ this.strategy = this.isProgressiveMode ? new ProgressiveStrategy() : new NonProgressiveStrategy();
307
+ }
308
+ async *processResponse(response) {
276
309
  var _a, _b;
277
- if (!((_a = this.response) == null ? void 0 : _a.candidates) || this.response.candidates.length === 0) {
310
+ const llmResponse = (0, import_llm_response.createLlmResponse)(response);
311
+ const parts = (_b = (_a = llmResponse.content) == null ? void 0 : _a.parts) != null ? _b : [];
312
+ if (parts.every(isEmptyContentPart) && (llmResponse.finishReason === void 0 || llmResponse.finishReason === import_genai.FinishReason.STOP)) {
313
+ if (llmResponse.usageMetadata) {
314
+ this.usageMetadata = llmResponse.usageMetadata;
315
+ }
316
+ if (llmResponse.groundingMetadata) {
317
+ this.groundingMetadata = llmResponse.groundingMetadata;
318
+ }
319
+ if (llmResponse.citationMetadata) {
320
+ this.citationMetadata = llmResponse.citationMetadata;
321
+ }
322
+ if (llmResponse.finishReason) {
323
+ this.finishReason = llmResponse.finishReason;
324
+ }
278
325
  return;
279
326
  }
280
- if (this.isProgressiveMode) {
281
- this.flushTextBufferToSequence();
282
- this.flushFunctionCallToSequence();
283
- const finalParts = this.partsSequence;
284
- if (finalParts.length === 0) {
285
- return;
286
- }
287
- const candidate = this.response.candidates[0];
288
- const finishReason = (_b = this.finishReason) != null ? _b : candidate.finishReason;
289
- return {
290
- content: {
291
- role: "model",
292
- parts: finalParts
293
- },
294
- groundingMetadata: this.groundingMetadata,
295
- citationMetadata: this.citationMetadata,
296
- errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
297
- errorMessage: finishReason === import_genai.FinishReason.STOP ? void 0 : candidate.finishMessage,
298
- usageMetadata: this.usageMetadata,
299
- finishReason,
300
- partial: false
301
- };
327
+ this.response = response;
328
+ this.usageMetadata = llmResponse.usageMetadata;
329
+ if (llmResponse.groundingMetadata) {
330
+ this.groundingMetadata = llmResponse.groundingMetadata;
302
331
  }
303
- if ((this.text || this.thoughtText) && this.response.candidates && this.response.candidates.length > 0) {
304
- const parts = [];
305
- if (this.thoughtText) {
306
- parts.push({ text: this.thoughtText, thought: true });
307
- }
308
- if (this.text) {
309
- parts.push({ text: this.text });
332
+ if (llmResponse.citationMetadata) {
333
+ this.citationMetadata = llmResponse.citationMetadata;
334
+ }
335
+ if (llmResponse.finishReason) {
336
+ this.finishReason = llmResponse.finishReason;
337
+ }
338
+ if (llmResponse.content && llmResponse.content.parts) {
339
+ for (const part of llmResponse.content.parts) {
340
+ if (part.thoughtSignature) {
341
+ this.lastThoughtSignature.value = part.thoughtSignature;
342
+ } else if (part.functionCall && this.lastThoughtSignature.value) {
343
+ part.thoughtSignature = this.lastThoughtSignature.value.toString();
344
+ }
310
345
  }
311
- const candidate = this.response.candidates[0];
312
- const finishReason = candidate.finishReason;
313
- return {
314
- content: {
315
- role: "model",
316
- parts
317
- },
318
- groundingMetadata: this.groundingMetadata,
319
- citationMetadata: this.citationMetadata,
320
- errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
321
- errorMessage: finishReason === import_genai.FinishReason.STOP ? void 0 : candidate.finishMessage,
322
- usageMetadata: this.usageMetadata,
323
- finishReason,
324
- partial: false
325
- };
326
346
  }
327
- return void 0;
347
+ yield* this.strategy.processResponse(llmResponse);
348
+ }
349
+ close() {
350
+ var _a, _b, _c;
351
+ const finalParts = this.strategy.close();
352
+ const hasMetadata = this.usageMetadata !== void 0 || this.groundingMetadata !== void 0 || this.citationMetadata !== void 0;
353
+ if (!finalParts && !hasMetadata) {
354
+ return void 0;
355
+ }
356
+ const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
357
+ const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
358
+ return {
359
+ content: {
360
+ role: "model",
361
+ parts: finalParts != null ? finalParts : []
362
+ },
363
+ groundingMetadata: this.groundingMetadata,
364
+ citationMetadata: this.citationMetadata,
365
+ errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
366
+ errorMessage: finishReason === import_genai.FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
367
+ usageMetadata: this.usageMetadata,
368
+ finishReason,
369
+ partial: false
370
+ };
328
371
  }
329
372
  }
373
+ function isEmptyContentPart(part) {
374
+ return !part.functionCall && !part.functionResponse && !part.fileData && !part.inlineData && !part.executableCode && !part.codeExecutionResult && (!part.text || part.text === "");
375
+ }
330
376
  // Annotate the CommonJS export names for ESM import in node:
331
377
  0 && (module.exports = {
332
- StreamingResponseAggregator
378
+ StreamingResponseAggregator,
379
+ isEmptyContentPart
333
380
  });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var vertex_ai_utils_exports = {};
26
+ __export(vertex_ai_utils_exports, {
27
+ getExpressModeApiKey: () => getExpressModeApiKey
28
+ });
29
+ module.exports = __toCommonJS(vertex_ai_utils_exports);
30
+ var import_env_aware_utils = require("./env_aware_utils.js");
31
+ /**
32
+ * @license
33
+ * Copyright 2026 Google LLC
34
+ * SPDX-License-Identifier: Apache-2.0
35
+ */
36
+ function getExpressModeApiKey(project, location, expressModeApiKey) {
37
+ if ((project || location) && expressModeApiKey) {
38
+ throw new Error(
39
+ "Cannot specify project or location and expressModeApiKey. Either use project and location, or just the expressModeApiKey."
40
+ );
41
+ }
42
+ if ((0, import_env_aware_utils.getBooleanEnvVar)("GOOGLE_GENAI_USE_VERTEXAI")) {
43
+ return expressModeApiKey || process.env.GOOGLE_API_KEY;
44
+ }
45
+ return void 0;
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ getExpressModeApiKey
50
+ });
@@ -32,7 +32,7 @@ module.exports = __toCommonJS(version_exports);
32
32
  * Copyright 2025 Google LLC
33
33
  * SPDX-License-Identifier: Apache-2.0
34
34
  */
35
- const version = "1.1.0";
35
+ const version = "1.3.0";
36
36
  // Annotate the CommonJS export names for ESM import in node:
37
37
  0 && (module.exports = {
38
38
  version
@@ -99,9 +99,27 @@ class BaseAgent {
99
99
  ctx,
100
100
  this,
101
101
  async function* () {
102
+ var _a2, _b;
103
+ const context2 = this.createInvocationContext(parentContext);
104
+ const beforeAgentCallbackEvent = await this.handleBeforeAgentCallback(context2);
105
+ if (beforeAgentCallbackEvent) {
106
+ yield beforeAgentCallbackEvent;
107
+ }
108
+ if (context2.endInvocation || ((_a2 = parentContext.abortSignal) == null ? void 0 : _a2.aborted)) {
109
+ return;
110
+ }
111
+ for await (const event of this.runLiveImpl(context2)) {
112
+ yield event;
113
+ }
114
+ if (context2.endInvocation || ((_b = parentContext.abortSignal) == null ? void 0 : _b.aborted)) {
115
+ return;
116
+ }
117
+ const afterAgentCallbackEvent = await this.handleAfterAgentCallback(context2);
118
+ if (afterAgentCallbackEvent) {
119
+ yield afterAgentCallbackEvent;
120
+ }
102
121
  }
103
122
  );
104
- throw new Error("Live mode is not implemented yet.");
105
123
  } finally {
106
124
  span.end();
107
125
  }
@@ -159,6 +159,8 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
159
159
  let responseResult;
160
160
  if (typeof functionResult !== "object" || functionResult == null) {
161
161
  responseResult = { result: functionResult };
162
+ } else if (Array.isArray(functionResult)) {
163
+ responseResult = { results: functionResult };
162
164
  } else {
163
165
  responseResult = functionResult;
164
166
  }
@@ -297,6 +299,8 @@ async function handleFunctionCallList({
297
299
  functionResponse = { error: functionResponseError };
298
300
  } else if (typeof functionResponse !== "object" || functionResponse == null) {
299
301
  functionResponse = { result: functionResponse };
302
+ } else if (Array.isArray(functionResponse)) {
303
+ functionResponse = { results: functionResponse };
300
304
  }
301
305
  const functionResponseEvent = createEvent({
302
306
  invocationId: invocationContext.invocationId,
@@ -6,50 +6,98 @@ const require = topLevelCreateRequire(import.meta.url);
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
8
  import { State } from "../sessions/state.js";
9
- async function injectSessionState(template, readonlyContext) {
9
+ const ARTIFACT_PREFIX = "artifact.";
10
+ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
10
11
  const invocationContext = readonlyContext.invocationContext;
11
- async function replaceMatchedKeyWithItsValue(match) {
12
- let key = match[0].replace(/^\{+/, "").replace(/\}+$/, "").trim();
12
+ if (key.startsWith(ARTIFACT_PREFIX)) {
13
+ const fileName = key.substring(ARTIFACT_PREFIX.length);
14
+ if (invocationContext.artifactService === void 0) {
15
+ throw new Error("Artifact service is not initialized.");
16
+ }
17
+ const artifact = await invocationContext.artifactService.loadArtifact({
18
+ appName: invocationContext.session.appName,
19
+ userId: invocationContext.session.userId,
20
+ sessionId: invocationContext.session.id,
21
+ filename: fileName
22
+ });
23
+ if (!artifact) {
24
+ if (isOptional) {
25
+ return "";
26
+ }
27
+ throw new Error(`Artifact ${fileName} not found.`);
28
+ }
29
+ return String(artifact);
30
+ }
31
+ if (!isValidStateName(key)) {
32
+ return rawMatch;
33
+ }
34
+ if (key in invocationContext.session.state) {
35
+ return String(invocationContext.session.state[key]);
36
+ }
37
+ if (isOptional) {
38
+ return "";
39
+ }
40
+ throw new Error(`Context variable not found: \`${key}\`.`);
41
+ }
42
+ async function injectSessionState(template, readonlyContext) {
43
+ const pattern = /\{+[^{}]*}+/g;
44
+ const matches = Array.from(template.matchAll(pattern));
45
+ if (matches.length === 0) {
46
+ return template;
47
+ }
48
+ const parsedMatches = matches.map((match) => {
49
+ const raw = match[0];
50
+ let key = raw.replace(/^\{+/, "").replace(/\}+$/, "").trim();
13
51
  const isOptional = key.endsWith("?");
14
52
  if (isOptional) {
15
53
  key = key.slice(0, -1);
16
54
  }
17
- if (key.startsWith("artifact.")) {
18
- const fileName = key.substring("artifact.".length);
19
- if (invocationContext.artifactService === void 0) {
20
- throw new Error("Artifact service is not initialized.");
55
+ const isValid = key.startsWith(ARTIFACT_PREFIX) || isValidStateName(key);
56
+ return {
57
+ raw,
58
+ key,
59
+ isOptional,
60
+ isValid,
61
+ index: match.index
62
+ };
63
+ });
64
+ const uniqueKeys = /* @__PURE__ */ new Map();
65
+ for (const pm of parsedMatches) {
66
+ if (!pm.isValid) {
67
+ continue;
68
+ }
69
+ const existing = uniqueKeys.get(pm.key);
70
+ if (existing) {
71
+ if (existing.isOptional && !pm.isOptional) {
72
+ existing.isOptional = false;
21
73
  }
22
- const artifact = await invocationContext.artifactService.loadArtifact({
23
- appName: invocationContext.session.appName,
24
- userId: invocationContext.session.userId,
25
- sessionId: invocationContext.session.id,
26
- filename: fileName
74
+ } else {
75
+ uniqueKeys.set(pm.key, {
76
+ key: pm.key,
77
+ isOptional: pm.isOptional,
78
+ raw: pm.raw
27
79
  });
28
- if (!artifact) {
29
- throw new Error(`Artifact ${fileName} not found.`);
30
- }
31
- return String(artifact);
32
- }
33
- if (!isValidStateName(key)) {
34
- return match[0];
35
- }
36
- if (key in invocationContext.session.state) {
37
- return String(invocationContext.session.state[key]);
38
80
  }
39
- if (isOptional) {
40
- return "";
41
- }
42
- throw new Error(`Context variable not found: \`${key}\`.`);
43
81
  }
44
- const pattern = /\{+[^{}]*}+/g;
82
+ const resolutions = /* @__PURE__ */ new Map();
83
+ for (const info of uniqueKeys.values()) {
84
+ resolutions.set(
85
+ info.key,
86
+ resolveKey(info.key, info.isOptional, info.raw, readonlyContext)
87
+ );
88
+ }
89
+ await Promise.all(resolutions.values());
45
90
  const result = [];
46
91
  let lastEnd = 0;
47
- const matches = template.matchAll(pattern);
48
- for (const match of matches) {
49
- result.push(template.slice(lastEnd, match.index));
50
- const replacement = await replaceMatchedKeyWithItsValue(match);
51
- result.push(replacement);
52
- lastEnd = match.index + match[0].length;
92
+ for (const pm of parsedMatches) {
93
+ result.push(template.slice(lastEnd, pm.index));
94
+ if (pm.isValid) {
95
+ const replacement = await resolutions.get(pm.key);
96
+ result.push(replacement);
97
+ } else {
98
+ result.push(pm.raw);
99
+ }
100
+ lastEnd = pm.index + pm.raw.length;
53
101
  }
54
102
  result.push(template.slice(lastEnd));
55
103
  return result.join("");