@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
@@ -46,7 +46,6 @@ class InvocationContext {
46
46
  this.endInvocation = params.endInvocation || false;
47
47
  this.transcriptionCache = params.transcriptionCache;
48
48
  this.runConfig = params.runConfig;
49
- this.liveRequestQueue = params.liveRequestQueue;
50
49
  this.activeStreamingTools = params.activeStreamingTools;
51
50
  this.pluginManager = params.pluginManager;
52
51
  this.abortSignal = params.abortSignal;
@@ -7,10 +7,12 @@ const require = topLevelCreateRequire(import.meta.url);
7
7
  */
8
8
  var _a, _b;
9
9
  import { context, trace } from "@opentelemetry/api";
10
+ import { FunctionTool } from "../tools/function_tool.js";
10
11
  import {
11
12
  createEvent,
12
13
  createNewEventId,
13
14
  getFunctionCalls,
15
+ getFunctionResponses,
14
16
  isFinalResponse
15
17
  } from "../events/event.js";
16
18
  import { isBaseLlm } from "../models/base_llm.js";
@@ -32,6 +34,7 @@ import {
32
34
  handleFunctionCallsAsync,
33
35
  populateClientFunctionCallId
34
36
  } from "./functions.js";
37
+ import { AUTH_PREPROCESSOR } from "../auth/auth_preprocessor.js";
35
38
  import { AGENT_TRANSFER_LLM_REQUEST_PROCESSOR } from "./processors/agent_transfer_llm_request_processor.js";
36
39
  import { BASIC_LLM_REQUEST_PROCESSOR } from "./processors/basic_llm_request_processor.js";
37
40
  import { CODE_EXECUTION_REQUEST_PROCESSOR } from "./processors/code_execution_request_processor.js";
@@ -78,6 +81,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
78
81
  this.codeExecutor = config.codeExecutor;
79
82
  this.requestProcessors = (_g = config.requestProcessors) != null ? _g : [
80
83
  BASIC_LLM_REQUEST_PROCESSOR,
84
+ AUTH_PREPROCESSOR,
81
85
  IDENTITY_LLM_REQUEST_PROCESSOR,
82
86
  INSTRUCTIONS_LLM_REQUEST_PROCESSOR,
83
87
  REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
@@ -303,18 +307,26 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
303
307
  event.actions.stateDelta[this.outputKey] = result;
304
308
  }
305
309
  async *runAsyncImpl(context2) {
306
- var _a2;
310
+ var _a2, _b2;
307
311
  while (true) {
308
312
  let lastEvent = void 0;
313
+ let stepHadToolCalls = false;
309
314
  for await (const event of this.runOneStepAsync(context2)) {
310
315
  if ((_a2 = context2.abortSignal) == null ? void 0 : _a2.aborted) {
311
316
  return;
312
317
  }
313
318
  lastEvent = event;
319
+ if (getFunctionCalls(event).length > 0 || getFunctionResponses(event).length > 0) {
320
+ stepHadToolCalls = true;
321
+ }
314
322
  this.maybeSaveOutputToState(event);
315
323
  yield event;
316
324
  }
317
- if (!lastEvent || isFinalResponse(lastEvent)) {
325
+ if (!lastEvent) {
326
+ break;
327
+ }
328
+ const isEmptyMetadataEvent = lastEvent.author === this.name && !lastEvent.partial && (!((_b2 = lastEvent.content) == null ? void 0 : _b2.parts) || lastEvent.content.parts.length === 0);
329
+ if (isFinalResponse(lastEvent) && !(isEmptyMetadataEvent && stepHadToolCalls)) {
318
330
  break;
319
331
  }
320
332
  if (lastEvent.partial) {
@@ -339,6 +351,20 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
339
351
  // --------------------------------------------------------------------------
340
352
  // #START LlmFlow Logic
341
353
  // --------------------------------------------------------------------------
354
+ /**
355
+ * Runs the bidirectional (live) flow for this agent.
356
+ *
357
+ * Establishes a live connection to the model, drains the invocation's
358
+ * `liveRequestQueue` into the connection on a parallel task, and yields
359
+ * events derived from server messages until the queue closes, the model
360
+ * finishes, or an agent transfer occurs.
361
+ *
362
+ * If the live connection drops (network failure, server `goAway`) and a
363
+ * session resumption handle has been observed, the flow transparently
364
+ * reconnects using that handle up to {@link MAX_LIVE_RECONNECT_ATTEMPTS}
365
+ * times. Subsequent reconnects skip `sendHistory` because the server
366
+ * already holds the conversation state associated with the handle.
367
+ */
342
368
  // eslint-disable-next-line require-yield
343
369
  async *runLiveFlow(_invocationContext) {
344
370
  await Promise.resolve();
@@ -362,13 +388,28 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
362
388
  yield event;
363
389
  }
364
390
  }
365
- for (const toolUnion of this.tools) {
391
+ const allTools = [...this.tools];
392
+ if (this.outputSchema && allTools.length > 0) {
393
+ const setModelResponseTool = new FunctionTool({
394
+ name: "set_model_response",
395
+ description: "Call this tool to submit your final response conforming to the output schema. Use this tool only when you have collected all the information and are ready to return the final answer.",
396
+ parameters: this.outputSchema,
397
+ execute: async (args, toolContext) => {
398
+ if (toolContext) {
399
+ toolContext.actions.skipSummarization = true;
400
+ }
401
+ return JSON.stringify(args);
402
+ }
403
+ });
404
+ allTools.push(setModelResponseTool);
405
+ }
406
+ for (const toolUnion of allTools) {
366
407
  const toolContext = new Context({ invocationContext });
367
408
  const tools = (await convertToolUnionToTools(
368
409
  toolUnion,
369
410
  new ReadonlyContext(invocationContext)
370
411
  )).filter((tool) => {
371
- return !llmRequest.allowedTools || llmRequest.allowedTools.includes(tool.name);
412
+ return !llmRequest.allowedTools || llmRequest.allowedTools.includes(tool.name) || tool.name === "set_model_response";
372
413
  });
373
414
  for (const tool of tools) {
374
415
  await tool.processLlmRequest({ toolContext, llmRequest });
@@ -448,7 +489,14 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
448
489
  });
449
490
  if (mergedEvent.content) {
450
491
  const functionCalls = getFunctionCalls(mergedEvent);
451
- if (functionCalls == null ? void 0 : functionCalls.length) {
492
+ const setModelResponseCall = functionCalls.find(
493
+ (call) => call.name === "set_model_response"
494
+ );
495
+ if (setModelResponseCall) {
496
+ const args = setModelResponseCall.args;
497
+ mergedEvent.content.parts = [{ text: JSON.stringify(args) }];
498
+ mergedEvent.actions.skipSummarization = true;
499
+ } else if (functionCalls && functionCalls.length) {
452
500
  populateClientFunctionCallId(mergedEvent);
453
501
  mergedEvent.longRunningToolIds = Array.from(
454
502
  getLongRunningFunctionCalls(functionCalls, llmRequest.toolsDict)
@@ -30,6 +30,13 @@ class AgentTransferLlmRequestProcessor extends BaseLlmRequestProcessor {
30
30
  }
31
31
  });
32
32
  }
33
+ /**
34
+ * Appends transfer instructions and registers the `transfer_to_agent` tool
35
+ * when the agent has reachable transfer targets.
36
+ *
37
+ * @param invocationContext - The current invocation context.
38
+ * @param llmRequest - The request to augment with transfer instructions and the transfer tool.
39
+ */
33
40
  // eslint-disable-next-line require-yield
34
41
  async *runAsync(invocationContext, llmRequest) {
35
42
  if (!isLlmAgent(invocationContext.agent)) {
@@ -9,6 +9,13 @@ import { setOutputSchema } from "../../models/llm_request.js";
9
9
  import { isLlmAgent } from "../llm_agent.js";
10
10
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
11
11
  class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
12
+ /**
13
+ * Populates model name, generation config, output schema, and live connect
14
+ * settings on the request from the agent and run config.
15
+ *
16
+ * @param invocationContext - The current invocation context.
17
+ * @param llmRequest - The request object to populate in place.
18
+ */
12
19
  // eslint-disable-next-line require-yield
13
20
  async *runAsync(invocationContext, llmRequest) {
14
21
  var _a;
@@ -18,7 +25,7 @@ class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
18
25
  }
19
26
  llmRequest.model = agent.canonicalModel.model;
20
27
  llmRequest.config = { ...(_a = agent.generateContentConfig) != null ? _a : {} };
21
- if (agent.outputSchema) {
28
+ if (agent.outputSchema && (!agent.tools || agent.tools.length === 0)) {
22
29
  setOutputSchema(llmRequest, agent.outputSchema);
23
30
  }
24
31
  if (invocationContext.runConfig) {
@@ -109,17 +109,19 @@ function convertForeignEvent(event) {
109
109
  text: `[${event.author}] said: ${part.text}`
110
110
  });
111
111
  } else if (part.functionCall) {
112
- const argsText = safeStringify(part.functionCall.args);
113
112
  (_d = content.parts) == null ? void 0 : _d.push({
114
- text: `[${event.author}] called tool \`${part.functionCall.name}\` with parameters: ${argsText}`
113
+ text: `[${event.author}] called tool \`${part.functionCall.name}\` with parameters: ${safeStringify(
114
+ part.functionCall.args
115
+ )}`
115
116
  });
116
117
  } else if (part.functionResponse) {
117
- const responseText = safeStringify(part.functionResponse.response);
118
118
  (_e = content.parts) == null ? void 0 : _e.push({
119
- text: `[${event.author}] tool \`${part.functionResponse.name}\` returned result: ${responseText}`
119
+ text: `[${event.author}] tool \`${part.functionResponse.name}\` returned result: ${safeStringify(
120
+ part.functionResponse.response
121
+ )}`
120
122
  });
121
123
  } else {
122
- (_f = content.parts) == null ? void 0 : _f.push(part);
124
+ (_f = content.parts) == null ? void 0 : _f.push(cloneDeep(part));
123
125
  }
124
126
  }
125
127
  return createEvent({
@@ -135,9 +137,12 @@ function mergeFunctionResponseEvents(events) {
135
137
  if (events.length === 0) {
136
138
  throw new Error("Cannot merge an empty list of events.");
137
139
  }
138
- const mergedEvent = createEvent(events[0]);
139
- const partsInMergedEvent = ((_a = mergedEvent.content) == null ? void 0 : _a.parts) || [];
140
- if (partsInMergedEvent.length === 0) {
140
+ const mergedEvent = createEvent({
141
+ ...events[0],
142
+ content: events[0].content ? cloneDeep(events[0].content) : void 0
143
+ });
144
+ const partsInMergedEvent = (_a = mergedEvent.content) == null ? void 0 : _a.parts;
145
+ if (!partsInMergedEvent || partsInMergedEvent.length === 0) {
141
146
  throw new Error("There should be at least one function_response part.");
142
147
  }
143
148
  const partIndicesInMergedEvent = {};
@@ -152,16 +157,17 @@ function mergeFunctionResponseEvents(events) {
152
157
  throw new Error("There should be at least one function_response part.");
153
158
  }
154
159
  for (const part of event.content.parts) {
155
- if (part.functionResponse && part.functionResponse.id) {
156
- const functionCallId = part.functionResponse.id;
160
+ const clonedPart = cloneDeep(part);
161
+ if (clonedPart.functionResponse && clonedPart.functionResponse.id) {
162
+ const functionCallId = clonedPart.functionResponse.id;
157
163
  if (functionCallId in partIndicesInMergedEvent) {
158
- partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
164
+ partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = clonedPart;
159
165
  } else {
160
- partsInMergedEvent.push(part);
166
+ partsInMergedEvent.push(clonedPart);
161
167
  partIndicesInMergedEvent[functionCallId] = partsInMergedEvent.length - 1;
162
168
  }
163
169
  } else {
164
- partsInMergedEvent.push(part);
170
+ partsInMergedEvent.push(clonedPart);
165
171
  }
166
172
  }
167
173
  }
@@ -176,7 +182,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
176
182
  if (!(functionResponses == null ? void 0 : functionResponses.length)) {
177
183
  return events;
178
184
  }
179
- let functionResponsesIds = new Set(
185
+ const functionResponsesIds = new Set(
180
186
  functionResponses.filter((response) => !!response.id).map((response) => response.id)
181
187
  );
182
188
  const secondLatestEvent = events.at(-2);
@@ -190,16 +196,16 @@ function rearrangeEventsForLatestFunctionResponse(events) {
190
196
  }
191
197
  }
192
198
  }
193
- let functionCallEventIdx = -1;
199
+ let match;
194
200
  for (let idx = events.length - 2; idx >= 0; idx--) {
195
201
  const event = events[idx];
196
202
  const functionCalls = getFunctionCalls(event);
197
203
  if (!(functionCalls == null ? void 0 : functionCalls.length)) {
198
204
  continue;
199
205
  }
206
+ let matchedInEvent = false;
200
207
  for (const functionCall of functionCalls) {
201
208
  if (functionCall.id && functionResponsesIds.has(functionCall.id)) {
202
- functionCallEventIdx = idx;
203
209
  const functionCallIds = new Set(
204
210
  functionCalls.map((fc) => fc.id).filter((id) => !!id)
205
211
  );
@@ -213,12 +219,16 @@ function rearrangeEventsForLatestFunctionResponse(events) {
213
219
  )}, function response ids provided: ${Array.from(functionResponsesIds).join(", ")}`
214
220
  );
215
221
  }
216
- functionResponsesIds = functionCallIds;
222
+ match = { eventIdx: idx, responseIds: functionCallIds };
223
+ matchedInEvent = true;
217
224
  break;
218
225
  }
219
226
  }
227
+ if (matchedInEvent) {
228
+ break;
229
+ }
220
230
  }
221
- if (functionCallEventIdx === -1) {
231
+ if (!match) {
222
232
  throw new Error(
223
233
  `No function call event found for function responses ids: ${Array.from(
224
234
  functionResponsesIds
@@ -226,17 +236,18 @@ function rearrangeEventsForLatestFunctionResponse(events) {
226
236
  );
227
237
  }
228
238
  const functionResponseEvents = [];
229
- for (let idx = functionCallEventIdx + 1; idx < events.length - 1; idx++) {
239
+ const activeResponses = match.responseIds;
240
+ for (let idx = match.eventIdx + 1; idx < events.length - 1; idx++) {
230
241
  const event = events[idx];
231
242
  const responses = getFunctionResponses(event);
232
243
  if (responses && responses.some(
233
- (response) => response.id && functionResponsesIds.has(response.id)
244
+ (response) => response.id && activeResponses.has(response.id)
234
245
  )) {
235
246
  functionResponseEvents.push(event);
236
247
  }
237
248
  }
238
249
  functionResponseEvents.push(events[events.length - 1]);
239
- const resultEvents = events.slice(0, functionCallEventIdx + 1);
250
+ const resultEvents = events.slice(0, match.eventIdx + 1);
240
251
  resultEvents.push(mergeFunctionResponseEvents(functionResponseEvents));
241
252
  return resultEvents;
242
253
  }
@@ -275,7 +286,7 @@ function rearrangeEventsForAsyncFunctionResponsesInHistory(events) {
275
286
  continue;
276
287
  }
277
288
  if (functionResponseEventsIndices.size === 1) {
278
- const [responseIndex] = [...functionResponseEventsIndices];
289
+ const [responseIndex] = Array.from(functionResponseEventsIndices);
279
290
  resultEvents.push(events[responseIndex]);
280
291
  } else {
281
292
  const indicesArray = Array.from(functionResponseEventsIndices).sort(
@@ -315,5 +326,6 @@ ${event.compactedContent}`
315
326
  }
316
327
  export {
317
328
  getContents,
318
- getCurrentTurnContents
329
+ getCurrentTurnContents,
330
+ mergeFunctionResponseEvents
319
331
  };
@@ -12,6 +12,13 @@ import {
12
12
  getCurrentTurnContents
13
13
  } from "./content_processor_utils.js";
14
14
  class ContentRequestProcessor {
15
+ /**
16
+ * Fills {@link LlmRequest.contents} based on the session event history and
17
+ * agent configuration.
18
+ *
19
+ * @param invocationContext - The current invocation context.
20
+ * @param llmRequest - The request whose contents field will be populated.
21
+ */
15
22
  // eslint-disable-next-line require-yield
16
23
  async *runAsync(invocationContext, llmRequest) {
17
24
  const agent = invocationContext.agent;
@@ -7,9 +7,21 @@ const require = topLevelCreateRequire(import.meta.url);
7
7
  */
8
8
  import { ContextCompactionTrigger } from "../../plugins/base_plugin.js";
9
9
  class ContextCompactorRequestProcessor {
10
+ /**
11
+ * @param compactors - Ordered list of compactors to evaluate; the first one
12
+ * that reports it should compact will perform the compaction.
13
+ */
10
14
  constructor(compactors) {
11
15
  this.compactors = compactors;
12
16
  }
17
+ /**
18
+ * Evaluates compactors in priority order. The first compactor that indicates
19
+ * it should compact will compact the session history, fire plugin hooks, and
20
+ * yield any newly generated events. Iteration stops after one compaction.
21
+ *
22
+ * @param invocationContext - The current invocation context.
23
+ * @param _llmRequest - Unused; present to satisfy the {@link BaseLlmRequestProcessor} interface.
24
+ */
13
25
  async *runAsync(invocationContext, _llmRequest) {
14
26
  for (const compactor of this.compactors) {
15
27
  const shouldCompact = await Promise.resolve(
@@ -8,6 +8,13 @@ const require = topLevelCreateRequire(import.meta.url);
8
8
  import { appendInstructions } from "../../models/llm_request.js";
9
9
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
10
10
  class IdentityLlmRequestProcessor extends BaseLlmRequestProcessor {
11
+ /**
12
+ * Appends agent name and description as identity instructions to the system
13
+ * prompt of the request.
14
+ *
15
+ * @param invocationContext - The current invocation context.
16
+ * @param llmRequest - The request object to append instructions to.
17
+ */
11
18
  // eslint-disable-next-line require-yield
12
19
  async *runAsync(invocationContext, llmRequest) {
13
20
  const agent = invocationContext.agent;
@@ -47,6 +47,11 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
47
47
  }
48
48
  appendInstructions(llmRequest, [instructionWithState]);
49
49
  }
50
+ if (agent.outputSchema && agent.tools && agent.tools.length > 0) {
51
+ appendInstructions(llmRequest, [
52
+ 'To output the final result, you must call the "set_model_response" function with the appropriate values. Do not output anything else.'
53
+ ]);
54
+ }
50
55
  }
51
56
  }
52
57
  const INSTRUCTIONS_LLM_REQUEST_PROCESSOR = new InstructionsLlmRequestProcessor();
@@ -18,7 +18,15 @@ import { isLlmAgent } from "../llm_agent.js";
18
18
  import { ReadonlyContext } from "../readonly_context.js";
19
19
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
20
20
  class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
21
- /** Handles tool confirmation information to build the LLM request. */
21
+ /**
22
+ * Resumes tool calls that were paused for user confirmation, re-invoking
23
+ * them with the confirmed or denied decision before the next LLM turn.
24
+ *
25
+ * @param invocationContext - The current invocation context, including the
26
+ * session event history used to locate pending confirmation responses.
27
+ * @yields Function response events for tools that have been confirmed and
28
+ * are ready to resume.
29
+ */
22
30
  async *runAsync(invocationContext) {
23
31
  const agent = invocationContext.agent;
24
32
  if (!isLlmAgent(agent)) {
@@ -10,7 +10,13 @@ import { isLlmAgent } from "../llm_agent.js";
10
10
  import { ReadonlyContext } from "../readonly_context.js";
11
11
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
12
12
  class ToolFilterRequestProcessor extends BaseLlmRequestProcessor {
13
- /** Filters the set of tools on the request based on plugins. */
13
+ /**
14
+ * Invokes plugin-based tool filtering and updates {@link LlmRequest.allowedTools}
15
+ * with the reduced tool set if any plugin returns a filtered result.
16
+ *
17
+ * @param invocationContext - The current invocation context.
18
+ * @param llmRequest - The request whose allowed tools may be restricted.
19
+ */
14
20
  // eslint-disable-next-line require-yield
15
21
  async *runAsync(invocationContext, llmRequest) {
16
22
  const agent = invocationContext.agent;
@@ -17,6 +17,7 @@ import {
17
17
  getFunctionResponses
18
18
  } from "../events/event.js";
19
19
  import { State } from "../sessions/state.js";
20
+ import { camelCaseKeys } from "../utils/case_utils.js";
20
21
  import { AuthHandler } from "./auth_handler.js";
21
22
  const TOOLSET_AUTH_CREDENTIAL_ID_PREFIX = "_adk_toolset_auth_";
22
23
  async function storeAuthAndCollectResumeTargets(events, authFcIds, authResponses, state) {
@@ -25,17 +26,15 @@ async function storeAuthAndCollectResumeTargets(events, authFcIds, authResponses
25
26
  const eventFunctionCalls = getFunctionCalls(event);
26
27
  for (const functionCall of eventFunctionCalls) {
27
28
  if (functionCall.id && authFcIds.has(functionCall.id) && functionCall.name === REQUEST_EUC_FUNCTION_CALL_NAME) {
28
- const args = functionCall.args;
29
- if (args && args.authConfig) {
30
- requestedAuthConfigById[functionCall.id] = args.authConfig;
29
+ const args = camelCaseKeys(functionCall.args);
30
+ const authConfig = args == null ? void 0 : args.authConfig;
31
+ if (authConfig) {
32
+ requestedAuthConfigById[functionCall.id] = authConfig;
31
33
  }
32
34
  }
33
35
  }
34
36
  }
35
37
  for (const fcId of authFcIds) {
36
- if (!(fcId in authResponses)) {
37
- continue;
38
- }
39
38
  const authConfig = authResponses[fcId];
40
39
  const requestedAuthConfig = requestedAuthConfigById[fcId];
41
40
  if (requestedAuthConfig && requestedAuthConfig.credentialKey) {
@@ -53,12 +52,15 @@ async function storeAuthAndCollectResumeTargets(events, authFcIds, authResponses
53
52
  const eventFunctionCalls = getFunctionCalls(event);
54
53
  for (const functionCall of eventFunctionCalls) {
55
54
  if (functionCall.id === fcId && functionCall.name === REQUEST_EUC_FUNCTION_CALL_NAME) {
56
- const args = functionCall.args;
57
- if (args && args.functionCallId) {
58
- if (args.functionCallId.startsWith(TOOLSET_AUTH_CREDENTIAL_ID_PREFIX)) {
55
+ const args = camelCaseKeys(
56
+ functionCall.args
57
+ );
58
+ const functionCallId = args == null ? void 0 : args.functionCallId;
59
+ if (functionCallId) {
60
+ if (functionCallId.startsWith(TOOLSET_AUTH_CREDENTIAL_ID_PREFIX)) {
59
61
  continue;
60
62
  }
61
- toolsToResume.add(args.functionCallId);
63
+ toolsToResume.add(functionCallId);
62
64
  }
63
65
  }
64
66
  }
@@ -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: ${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: ${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: ${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: ${url.hostname}`);
168
+ return false;
169
+ }
146
170
  return true;
147
171
  } catch (e) {
148
172
  logger.warn(`Failed to parse URL for validation ${urlStr}: ${e}`);