@google/adk 2.2.1 → 2.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 (226) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +4 -1
  2. package/dist/cjs/a2a/agent_card.js +102 -26
  3. package/dist/cjs/a2a/agent_to_a2a.js +1 -1
  4. package/dist/cjs/agents/functions.js +199 -25
  5. package/dist/cjs/agents/instructions.js +4 -1
  6. package/dist/cjs/agents/invocation_context.js +26 -4
  7. package/dist/cjs/agents/langgraph_agent.js +152 -0
  8. package/dist/cjs/agents/llm_agent.js +175 -101
  9. package/dist/cjs/agents/processors/code_execution_request_processor.js +10 -6
  10. package/dist/cjs/agents/remote_agent.js +187 -0
  11. package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
  12. package/dist/cjs/auth/auth_handler.js +37 -5
  13. package/dist/cjs/auth/auth_schemes.js +9 -0
  14. package/dist/cjs/cli/cli_eval.js +532 -0
  15. package/dist/cjs/cli/utils/envs.js +116 -0
  16. package/dist/cjs/cli/utils/evals.js +137 -0
  17. package/dist/cjs/cli/utils/logs.js +150 -0
  18. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  19. package/dist/cjs/code_executors/code_execution_utils.js +48 -16
  20. package/dist/cjs/code_executors/code_executor_context.js +6 -2
  21. package/dist/cjs/common.js +72 -0
  22. package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
  23. package/dist/cjs/context/token_based_context_compactor.js +2 -1
  24. package/dist/cjs/events/event.js +4 -2
  25. package/dist/cjs/examples/example_util.js +23 -2
  26. package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
  27. package/dist/cjs/index.js +97 -1
  28. package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
  29. package/dist/cjs/models/gemini_llm_connection.js +16 -8
  30. package/dist/cjs/models/google_llm.js +13 -16
  31. package/dist/cjs/models/llm_response.js +9 -1
  32. package/dist/cjs/models/registry.js +1 -1
  33. package/dist/cjs/models/routed_llm.js +9 -8
  34. package/dist/cjs/planners/plan_re_act_planner.js +1 -1
  35. package/dist/cjs/runner/in_memory_runner.js +6 -11
  36. package/dist/cjs/runner/runner.js +105 -33
  37. package/dist/cjs/sessions/db/operations.js +1 -1
  38. package/dist/cjs/sessions/in_memory_session_service.js +3 -1
  39. package/dist/cjs/sessions/state.js +8 -4
  40. package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
  41. package/dist/cjs/telemetry/tracing.js +97 -66
  42. package/dist/cjs/tools/agent_tool.js +44 -0
  43. package/dist/cjs/tools/apihub_tool/apihub_toolset.js +142 -0
  44. package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
  45. package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
  46. package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
  47. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +185 -0
  48. package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
  49. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +603 -0
  50. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +219 -0
  51. package/dist/cjs/tools/crewai_tool.js +132 -0
  52. package/dist/cjs/tools/example_tool.js +10 -0
  53. package/dist/cjs/tools/function_tool.js +319 -0
  54. package/dist/cjs/tools/google_api_tool/google_api_tool.js +97 -0
  55. package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +226 -0
  56. package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +58 -0
  57. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
  58. package/dist/cjs/tools/google_api_tool/index.js +64 -0
  59. package/dist/cjs/tools/langchain_tool.js +172 -0
  60. package/dist/cjs/tools/mcp/index.js +12 -0
  61. package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
  62. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
  63. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
  64. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
  65. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  66. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
  67. package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
  68. package/dist/cjs/tools/toolbox_tool.js +108 -0
  69. package/dist/cjs/utils/env_aware_utils.js +6 -8
  70. package/dist/cjs/utils/error_utils.js +11 -11
  71. package/dist/cjs/utils/file_extension_utils.js +11 -0
  72. package/dist/cjs/utils/file_utils.js +2 -24
  73. package/dist/cjs/utils/gemini_schema_util.js +4 -1
  74. package/dist/cjs/utils/json_utils.js +49 -0
  75. package/dist/cjs/utils/live_connection_utils.js +4 -5
  76. package/dist/cjs/utils/logger_node.js +7 -1
  77. package/dist/cjs/utils/object_notation_utils.js +6 -3
  78. package/dist/cjs/utils/streaming_utils.js +12 -12
  79. package/dist/cjs/version.js +1 -1
  80. package/dist/esm/a2a/a2a_remote_agent.js +4 -1
  81. package/dist/esm/a2a/agent_card.js +103 -27
  82. package/dist/esm/a2a/agent_to_a2a.js +5 -2
  83. package/dist/esm/agents/functions.js +198 -25
  84. package/dist/esm/agents/instructions.js +4 -1
  85. package/dist/esm/agents/invocation_context.js +24 -4
  86. package/dist/esm/agents/langgraph_agent.js +123 -0
  87. package/dist/esm/agents/llm_agent.js +185 -104
  88. package/dist/esm/agents/processors/code_execution_request_processor.js +13 -8
  89. package/dist/esm/agents/remote_agent.js +164 -0
  90. package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
  91. package/dist/esm/auth/auth_handler.js +37 -5
  92. package/dist/esm/auth/auth_schemes.js +8 -0
  93. package/dist/esm/cli/cli_eval.js +510 -0
  94. package/dist/esm/cli/utils/envs.js +78 -0
  95. package/dist/esm/cli/utils/evals.js +109 -0
  96. package/dist/esm/cli/utils/logs.js +111 -0
  97. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  98. package/dist/esm/code_executors/code_execution_utils.js +46 -16
  99. package/dist/esm/code_executors/code_executor_context.js +5 -2
  100. package/dist/esm/common.js +67 -3
  101. package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
  102. package/dist/esm/context/token_based_context_compactor.js +2 -1
  103. package/dist/esm/events/event.js +4 -2
  104. package/dist/esm/examples/example_util.js +21 -1
  105. package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
  106. package/dist/esm/index.js +99 -1
  107. package/dist/esm/integrations/agent_registry/helpers.js +1 -1
  108. package/dist/esm/models/gemini_llm_connection.js +16 -8
  109. package/dist/esm/models/google_llm.js +14 -17
  110. package/dist/esm/models/llm_response.js +9 -1
  111. package/dist/esm/models/registry.js +1 -1
  112. package/dist/esm/models/routed_llm.js +9 -8
  113. package/dist/esm/planners/plan_re_act_planner.js +1 -1
  114. package/dist/esm/runner/in_memory_runner.js +6 -11
  115. package/dist/esm/runner/runner.js +105 -33
  116. package/dist/esm/sessions/db/operations.js +1 -1
  117. package/dist/esm/sessions/in_memory_session_service.js +3 -1
  118. package/dist/esm/sessions/state.js +8 -4
  119. package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
  120. package/dist/esm/telemetry/tracing.js +97 -66
  121. package/dist/esm/tools/agent_tool.js +44 -0
  122. package/dist/esm/tools/apihub_tool/apihub_toolset.js +106 -0
  123. package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
  124. package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
  125. package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
  126. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +163 -0
  127. package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
  128. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +561 -0
  129. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +215 -0
  130. package/dist/esm/tools/crewai_tool.js +107 -0
  131. package/dist/esm/tools/example_tool.js +13 -1
  132. package/dist/esm/tools/function_tool.js +316 -0
  133. package/dist/esm/tools/google_api_tool/google_api_tool.js +70 -0
  134. package/dist/esm/tools/google_api_tool/google_api_tool_set.js +188 -0
  135. package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +24 -0
  136. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
  137. package/dist/esm/tools/google_api_tool/index.js +33 -0
  138. package/dist/esm/tools/langchain_tool.js +148 -0
  139. package/dist/esm/tools/mcp/index.js +6 -0
  140. package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
  141. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
  142. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
  143. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
  144. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  145. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
  146. package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
  147. package/dist/esm/tools/toolbox_tool.js +80 -0
  148. package/dist/esm/utils/env_aware_utils.js +6 -8
  149. package/dist/esm/utils/error_utils.js +9 -10
  150. package/dist/esm/utils/file_extension_utils.js +11 -0
  151. package/dist/esm/utils/file_utils.js +2 -23
  152. package/dist/esm/utils/gemini_schema_util.js +4 -1
  153. package/dist/esm/utils/json_utils.js +21 -0
  154. package/dist/esm/utils/live_connection_utils.js +4 -5
  155. package/dist/esm/utils/logger_node.js +7 -1
  156. package/dist/esm/utils/object_notation_utils.js +4 -2
  157. package/dist/esm/utils/streaming_utils.js +11 -11
  158. package/dist/esm/version.js +1 -1
  159. package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
  160. package/dist/types/a2a/agent_card.d.ts +44 -1
  161. package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
  162. package/dist/types/a2a/index.d.ts +1 -0
  163. package/dist/types/agents/functions.d.ts +33 -1
  164. package/dist/types/agents/invocation_context.d.ts +20 -1
  165. package/dist/types/agents/langgraph_agent.d.ts +153 -0
  166. package/dist/types/agents/remote_agent.d.ts +68 -0
  167. package/dist/types/auth/auth_handler.d.ts +28 -1
  168. package/dist/types/auth/auth_schemes.d.ts +13 -0
  169. package/dist/types/cli/cli_eval.d.ts +173 -0
  170. package/dist/types/cli/utils/envs.d.ts +23 -0
  171. package/dist/types/cli/utils/evals.d.ts +47 -0
  172. package/dist/types/cli/utils/logs.d.ts +38 -0
  173. package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
  174. package/dist/types/code_executors/code_executor_context.d.ts +1 -0
  175. package/dist/types/common.d.ts +27 -4
  176. package/dist/types/events/event.d.ts +4 -0
  177. package/dist/types/examples/example_util.d.ts +17 -0
  178. package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
  179. package/dist/types/index.d.ts +16 -1
  180. package/dist/types/models/gemini_llm_connection.d.ts +6 -7
  181. package/dist/types/models/routed_llm.d.ts +1 -1
  182. package/dist/types/runner/in_memory_runner.d.ts +2 -1
  183. package/dist/types/runner/runner.d.ts +34 -0
  184. package/dist/types/sessions/state.d.ts +5 -1
  185. package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
  186. package/dist/types/skills/skill.d.ts +1 -1
  187. package/dist/types/telemetry/tracing.d.ts +4 -2
  188. package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +122 -0
  189. package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
  190. package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
  191. package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
  192. package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +86 -0
  193. package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
  194. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +215 -0
  195. package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
  196. package/dist/types/tools/crewai_tool.d.ts +85 -0
  197. package/dist/types/tools/example_tool.d.ts +10 -0
  198. package/dist/types/tools/function_tool.d.ts +32 -0
  199. package/dist/types/tools/google_api_tool/google_api_tool.d.ts +30 -0
  200. package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +78 -0
  201. package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +33 -0
  202. package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +164 -0
  203. package/dist/types/tools/google_api_tool/index.d.ts +11 -0
  204. package/dist/types/tools/langchain_tool.d.ts +103 -0
  205. package/dist/types/tools/mcp/index.d.ts +3 -0
  206. package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
  207. package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
  208. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
  209. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
  210. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
  211. package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
  212. package/dist/types/tools/toolbox_tool.d.ts +73 -0
  213. package/dist/types/utils/env_aware_utils.d.ts +18 -2
  214. package/dist/types/utils/error_utils.d.ts +7 -0
  215. package/dist/types/utils/file_utils.d.ts +6 -1
  216. package/dist/types/utils/gemini_schema_util.d.ts +1 -2
  217. package/dist/types/utils/json_utils.d.ts +11 -0
  218. package/dist/types/utils/object_notation_utils.d.ts +7 -0
  219. package/dist/types/utils/streaming_utils.d.ts +11 -4
  220. package/dist/types/version.d.ts +1 -1
  221. package/dist/web/index_web.js +102 -103
  222. package/dist/web/index_web.js.map +4 -4
  223. package/package.json +8 -3
  224. package/dist/cjs/models/gemini_continuation.js +0 -232
  225. package/dist/esm/models/gemini_continuation.js +0 -205
  226. package/dist/types/models/gemini_continuation.d.ts +0 -59
@@ -63,7 +63,10 @@ const _RemoteA2AAgent = class _RemoteA2AAgent extends import_base_agent.BaseAgen
63
63
  this.client = this.a2aConfig.client;
64
64
  }
65
65
  if (this.a2aConfig.agentCard) {
66
- this.card = await (0, import_agent_card.resolveAgentCard)(this.a2aConfig.agentCard);
66
+ this.card = await (0, import_agent_card.resolveAgentCard)(
67
+ this.a2aConfig.agentCard,
68
+ this.a2aConfig.resolveAgentCardOptions
69
+ );
67
70
  if (!this.client) {
68
71
  const factory = this.a2aConfig.clientFactory || new import_client.ClientFactory();
69
72
  this.client = await factory.createFromAgentCard(this.card);
@@ -59,19 +59,21 @@ var import_workflow = require("../workflow/workflow.js");
59
59
  * Copyright 2026 Google LLC
60
60
  * SPDX-License-Identifier: Apache-2.0
61
61
  */
62
- const WINDOWS_DRIVE_PROTOCOL = /^[a-z]:$/i;
63
- async function resolveAgentCard(agentCard) {
62
+ async function resolveAgentCard(agentCard, options = {}) {
64
63
  if (typeof agentCard === "object") {
65
64
  return agentCard;
66
65
  }
67
- const url = parseCardUrl(agentCard);
68
- if (url && (0, import_ssrf_guard.isHttpUrl)(url)) {
69
- await assertHostAllowed(url);
66
+ const source = agentCard;
67
+ if (source.startsWith("http://") || source.startsWith("https://")) {
68
+ await refuseLinkLocalHost(source);
70
69
  const resolver = new import_client.DefaultAgentCardResolver({
71
- fetchImpl: noRedirectFetch(agentCard)
70
+ fetchImpl: refuseRedirectFetch
72
71
  });
73
- return resolver.resolve(agentCard);
72
+ const card = await resolver.resolve(source);
73
+ validateCardRpcTargets(card, source, options);
74
+ return card;
74
75
  }
76
+ const url = parseCardUrl(source);
75
77
  if (url && url.protocol !== "file:") {
76
78
  throw new Error(
77
79
  `Unsupported agent card URL scheme "${url.protocol}": ${agentCard}. Use http://, https:// or file://, or pass a filesystem path with no scheme.`
@@ -80,6 +82,31 @@ async function resolveAgentCard(agentCard) {
80
82
  return readAgentCardFile(agentCard, url);
81
83
  }
82
84
  __name(resolveAgentCard, "resolveAgentCard");
85
+ const WINDOWS_DRIVE_PROTOCOL = /^[a-z]:$/i;
86
+ async function refuseLinkLocalHost(source) {
87
+ const hostname = (0, import_ssrf_guard.normalizeHost)(new URL(source).hostname);
88
+ if ((0, import_ssrf_guard.isLocalhostHostname)(hostname)) {
89
+ return;
90
+ }
91
+ const addresses = await (0, import_ssrf_guard.resolveHostAddresses)(hostname);
92
+ if (addresses.some((address) => (0, import_ssrf_guard.isLinkLocalAddress)(address))) {
93
+ throw new Error(
94
+ `Refusing to fetch agent card from a link-local address: ${hostname}`
95
+ );
96
+ }
97
+ }
98
+ __name(refuseLinkLocalHost, "refuseLinkLocalHost");
99
+ async function refuseRedirectFetch(url, init) {
100
+ const response = await fetch(url, { ...init, redirect: "manual" });
101
+ if (response.status === 0 || response.status >= 300 && response.status < 400) {
102
+ const location = response.headers.get("location");
103
+ throw new Error(
104
+ `Refusing to follow a redirect from the agent card endpoint (status ${response.status}, location ${location}): ${url}`
105
+ );
106
+ }
107
+ return response;
108
+ }
109
+ __name(refuseRedirectFetch, "refuseRedirectFetch");
83
110
  function parseCardUrl(source) {
84
111
  let url;
85
112
  try {
@@ -102,32 +129,81 @@ async function readAgentCardFile(source, url) {
102
129
  }
103
130
  }
104
131
  __name(readAgentCardFile, "readAgentCardFile");
105
- function noRedirectFetch(source) {
106
- return async (input, init) => {
107
- const response = await fetch(input, { ...init, redirect: "manual" });
108
- if (isRedirect(response.status)) {
132
+ function validateCardRpcTargets(card, source, options) {
133
+ var _a;
134
+ let parsedSource;
135
+ try {
136
+ parsedSource = new URL(source);
137
+ } catch (err) {
138
+ throw new Error(
139
+ `Invalid agent card source URL: ${source}: ${err.message}`
140
+ );
141
+ }
142
+ const rpcUrls = [
143
+ card.url,
144
+ ...((_a = card.additionalInterfaces) != null ? _a : []).map((i) => i.url)
145
+ ];
146
+ for (const rpcUrl of rpcUrls) {
147
+ let parsed;
148
+ try {
149
+ parsed = new URL(rpcUrl);
150
+ } catch (err) {
109
151
  throw new Error(
110
- `Refusing to follow a redirect while fetching the agent card from ${source} (status ${response.status}, location ${response.headers.get("location")}). Configure the final URL instead.`
152
+ `Invalid RPC URL in agent card: ${rpcUrl}: ${err.message}`
111
153
  );
112
154
  }
113
- return response;
114
- };
155
+ if (parsed.protocol !== "https:" && !isLoopbackHost(parsed.hostname)) {
156
+ if (options.allowInsecureRpc === true) {
157
+ import_logger.logger.warn(
158
+ `SECURITY WARNING: accepting a plaintext http RPC URL on a non-loopback host because \`allowInsecureRpc: true\` was set: ${rpcUrl}. This connection can be intercepted or altered by anything on the network path.`
159
+ );
160
+ } else {
161
+ throw new Error(
162
+ `Agent card RPC URL must use https, or http on a loopback host: ${rpcUrl}`
163
+ );
164
+ }
165
+ }
166
+ if (!sameOriginForRpc(parsedSource, parsed)) {
167
+ if (options.allowCrossOriginRpc === true) {
168
+ import_logger.logger.warn(
169
+ `SECURITY WARNING: accepting an agent card RPC URL whose origin differs from the location the card was fetched from because \`allowCrossOriginRpc: true\` was set (fetched from ${source}): ${rpcUrl}.`
170
+ );
171
+ } else {
172
+ throw new Error(
173
+ `Agent card RPC URL must have the same origin as the location the card was fetched from (${source}): ${rpcUrl}`
174
+ );
175
+ }
176
+ }
177
+ }
115
178
  }
116
- __name(noRedirectFetch, "noRedirectFetch");
117
- function isRedirect(status) {
118
- return status === 0 || status >= 300 && status < 400;
179
+ __name(validateCardRpcTargets, "validateCardRpcTargets");
180
+ function sameOriginForRpc(source, rpc) {
181
+ const sourceIsLoopback = isLoopbackHost(source.hostname);
182
+ const rpcIsLoopback = isLoopbackHost(rpc.hostname);
183
+ if (sourceIsLoopback && rpcIsLoopback) {
184
+ return source.protocol === rpc.protocol && effectivePort(source) === effectivePort(rpc);
185
+ }
186
+ return source.origin === rpc.origin;
119
187
  }
120
- __name(isRedirect, "isRedirect");
121
- async function assertHostAllowed(url) {
122
- const host = (0, import_ssrf_guard.normalizeHost)(url.hostname);
123
- const addresses = await (0, import_ssrf_guard.resolveHostAddresses)(host);
124
- if (addresses.some(import_ssrf_guard.isLinkLocalAddress)) {
125
- throw new Error(
126
- `Refusing to fetch agent card from a link-local address: ${host}`
127
- );
188
+ __name(sameOriginForRpc, "sameOriginForRpc");
189
+ function effectivePort(url) {
190
+ if (url.port) {
191
+ return url.port;
192
+ }
193
+ if (url.protocol === "https:") {
194
+ return "443";
128
195
  }
196
+ if (url.protocol === "http:") {
197
+ return "80";
198
+ }
199
+ return url.port;
200
+ }
201
+ __name(effectivePort, "effectivePort");
202
+ function isLoopbackHost(hostname) {
203
+ const bare = hostname.replace(/^\[|\]$/g, "").toLowerCase();
204
+ return bare === "localhost" || bare === "127.0.0.1" || bare === "::1" || bare === "0.0.0.0" || bare === "::" || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(bare);
129
205
  }
130
- __name(assertHostAllowed, "assertHostAllowed");
206
+ __name(isLoopbackHost, "isLoopbackHost");
131
207
  async function getA2AAgentCard(agent, transports) {
132
208
  return {
133
209
  name: agent.name,
@@ -87,7 +87,7 @@ async function toA2a(agent, options = {}) {
87
87
  const protocol = (_c = options.protocol) != null ? _c : "http";
88
88
  const basePath = options.basePath || "";
89
89
  const rpcUrl = `${protocol}://${host}:${port}${basePath}`;
90
- const agentCard = options.agentCard ? await (0, import_agent_card.resolveAgentCard)(options.agentCard) : await (0, import_agent_card.getA2AAgentCard)(agent, [
90
+ const agentCard = options.agentCard ? await (0, import_agent_card.resolveAgentCard)(options.agentCard, options.resolveAgentCardOptions) : await (0, import_agent_card.getA2AAgentCard)(agent, [
91
91
  {
92
92
  url: `${rpcUrl}/jsonrpc`,
93
93
  transport: "JSONRPC"
@@ -39,6 +39,7 @@ __export(functions_exports, {
39
39
  getLongRunningFunctionCalls: () => getLongRunningFunctionCalls,
40
40
  handleFunctionCallList: () => handleFunctionCallList,
41
41
  handleFunctionCallsAsync: () => handleFunctionCallsAsync,
42
+ handleFunctionCallsLive: () => handleFunctionCallsLive,
42
43
  isToolNotFound: () => isToolNotFound,
43
44
  mergeParallelFunctionResponseEvents: () => mergeParallelFunctionResponseEvents,
44
45
  populateClientFunctionCallId: () => import_event2.populateClientFunctionCallId,
@@ -50,7 +51,10 @@ var import_lodash_es = require("lodash-es");
50
51
  var import_event = require("../events/event.js");
51
52
  var import_event_actions = require("../events/event_actions.js");
52
53
  var import_base_tool = require("../tools/base_tool.js");
54
+ var import_function_tool = require("../tools/function_tool.js");
53
55
  var import_logger = require("../utils/logger.js");
56
+ var import_task = require("../utils/task.js");
57
+ var import_active_streaming_tool = require("./active_streaming_tool.js");
54
58
  var import_context = require("./context.js");
55
59
  var import_framework_function_calls = require("./framework_function_calls.js");
56
60
  var import_tracing = require("../telemetry/tracing.js");
@@ -69,6 +73,8 @@ function toolEventAuthor(invocationContext) {
69
73
  __name(toolEventAuthor, "toolEventAuthor");
70
74
  const functionsExportedForTestingOnly = {
71
75
  handleFunctionCallList,
76
+ handleFunctionCallsLive,
77
+ processFunctionLiveHelper,
72
78
  generateAuthEvent,
73
79
  generateRequestConfirmationEvent
74
80
  };
@@ -171,7 +177,8 @@ async function callToolAsync(tool, args, toolContext) {
171
177
  result,
172
178
  toolContext,
173
179
  toolContext.invocationContext
174
- )
180
+ ),
181
+ invocationContext: toolContext.invocationContext
175
182
  });
176
183
  return result;
177
184
  } finally {
@@ -232,6 +239,30 @@ async function handleFunctionCallsAsync({
232
239
  });
233
240
  }
234
241
  __name(handleFunctionCallsAsync, "handleFunctionCallsAsync");
242
+ async function handleFunctionCallsLive({
243
+ invocationContext,
244
+ functionCallEvent,
245
+ toolsDict,
246
+ beforeToolCallbacks,
247
+ afterToolCallbacks,
248
+ filters,
249
+ toolConfirmationDict,
250
+ resumeInputsDict
251
+ }) {
252
+ const functionCalls = (0, import_event.getFunctionCalls)(functionCallEvent);
253
+ return handleFunctionCallList({
254
+ invocationContext,
255
+ functionCalls,
256
+ toolsDict,
257
+ beforeToolCallbacks,
258
+ afterToolCallbacks,
259
+ filters,
260
+ toolConfirmationDict,
261
+ resumeInputsDict,
262
+ isLive: true
263
+ });
264
+ }
265
+ __name(handleFunctionCallsLive, "handleFunctionCallsLive");
235
266
  function normalizeCallbackResponse(response) {
236
267
  if (response == null) {
237
268
  return void 0;
@@ -317,7 +348,8 @@ async function handleFunctionCallList({
317
348
  afterToolCallbacks,
318
349
  filters,
319
350
  toolConfirmationDict,
320
- resumeInputsDict
351
+ resumeInputsDict,
352
+ isLive = false
321
353
  }) {
322
354
  var _a2;
323
355
  const functionResponseEvents = [];
@@ -354,7 +386,6 @@ async function handleFunctionCallList({
354
386
  import_logger.logger.debug(`execute_tool ${tool.name}`);
355
387
  const functionArgs = (_a2 = functionCall.args) != null ? _a2 : {};
356
388
  let functionResponse = null;
357
- let functionResponseError;
358
389
  functionResponse = await invocationContext.pluginManager.runBeforeToolCallback({
359
390
  tool,
360
391
  toolArgs: functionArgs,
@@ -375,7 +406,18 @@ async function handleFunctionCallList({
375
406
  functionResponse = normalizeCallbackResponse(functionResponse);
376
407
  if (functionResponse == null) {
377
408
  try {
378
- functionResponse = await callToolAsync(tool, functionArgs, toolContext);
409
+ const rawFunctionResponse = isLive ? await processFunctionLiveHelper({
410
+ tool,
411
+ toolContext,
412
+ functionCall,
413
+ functionArgs,
414
+ invocationContext
415
+ }) : await callToolAsync(tool, functionArgs, toolContext);
416
+ if (rawFunctionResponse == null && !tool.isLongRunning) {
417
+ functionResponse = { result: rawFunctionResponse };
418
+ } else {
419
+ functionResponse = normalizeCallbackResponse(rawFunctionResponse);
420
+ }
379
421
  } catch (e) {
380
422
  if (e instanceof Error) {
381
423
  const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
@@ -387,18 +429,19 @@ async function handleFunctionCallList({
387
429
  if (onToolErrorResponse != null) {
388
430
  functionResponse = normalizeCallbackResponse(onToolErrorResponse);
389
431
  } else {
390
- functionResponseError = e.message;
432
+ functionResponse = { error: e.message };
391
433
  }
392
434
  } else {
393
- functionResponseError = e;
435
+ functionResponse = { error: e };
394
436
  }
395
437
  }
396
438
  }
439
+ const callbackResult = functionResponse != null ? functionResponse : {};
397
440
  let alteredFunctionResponse = await invocationContext.pluginManager.runAfterToolCallback({
398
441
  tool,
399
442
  toolArgs: functionArgs,
400
443
  toolContext,
401
- result: functionResponse
444
+ result: callbackResult
402
445
  });
403
446
  if (alteredFunctionResponse == null) {
404
447
  for (const callback of afterToolCallbacks) {
@@ -406,7 +449,7 @@ async function handleFunctionCallList({
406
449
  tool,
407
450
  args: functionArgs,
408
451
  context: toolContext,
409
- response: functionResponse
452
+ response: callbackResult
410
453
  });
411
454
  if (alteredFunctionResponse) {
412
455
  break;
@@ -429,13 +472,6 @@ async function handleFunctionCallList({
429
472
  }
430
473
  continue;
431
474
  }
432
- if (functionResponseError) {
433
- functionResponse = { error: functionResponseError };
434
- } else if (functionResponse == null) {
435
- functionResponse = { result: functionResponse };
436
- } else {
437
- functionResponse = normalizeCallbackResponse(functionResponse);
438
- }
439
475
  const functionResponseEvent = (0, import_event.createEvent)({
440
476
  invocationId: invocationContext.invocationId,
441
477
  author: toolEventAuthor(invocationContext),
@@ -449,11 +485,6 @@ async function handleFunctionCallList({
449
485
  actions: toolContext.actions,
450
486
  branch: invocationContext.branch
451
487
  });
452
- import_logger.logger.debug("traceToolCall", {
453
- tool: tool.name,
454
- args: functionArgs,
455
- functionResponseEvent: functionResponseEvent.id
456
- });
457
488
  functionResponseEvents.push(functionResponseEvent);
458
489
  }
459
490
  if (!functionResponseEvents.length) {
@@ -466,13 +497,10 @@ async function handleFunctionCallList({
466
497
  import_tracing.tracer.startActiveSpan("execute_tool (merged)", (span) => {
467
498
  try {
468
499
  import_logger.logger.debug("execute_tool (merged)");
469
- import_logger.logger.debug("traceMergedToolCalls", {
470
- responseEventId: mergedEvent.id,
471
- functionResponseEvent: mergedEvent.id
472
- });
473
500
  (0, import_tracing.traceMergedToolCalls)({
474
501
  responseEventId: mergedEvent.id,
475
- functionResponseEvent: mergedEvent
502
+ functionResponseEvent: mergedEvent,
503
+ invocationContext
476
504
  });
477
505
  } finally {
478
506
  span.end();
@@ -510,6 +538,151 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
510
538
  });
511
539
  }
512
540
  __name(mergeParallelFunctionResponseEvents, "mergeParallelFunctionResponseEvents");
541
+ function isAsyncGeneratorFunction(fn) {
542
+ return typeof fn === "function" && Object.prototype.toString.call(fn) === "[object AsyncGeneratorFunction]";
543
+ }
544
+ __name(isAsyncGeneratorFunction, "isAsyncGeneratorFunction");
545
+ function isStreamingTool(tool) {
546
+ const candidate = tool;
547
+ if (typeof candidate._callLive !== "function") {
548
+ return false;
549
+ }
550
+ if ((0, import_function_tool.isFunctionTool)(tool)) {
551
+ return isAsyncGeneratorFunction(candidate.execute);
552
+ }
553
+ return isAsyncGeneratorFunction(candidate.execute) || isAsyncGeneratorFunction(candidate.func) || isAsyncGeneratorFunction(candidate._callLive);
554
+ }
555
+ __name(isStreamingTool, "isStreamingTool");
556
+ async function* callToolLive({
557
+ tool,
558
+ args,
559
+ toolContext,
560
+ invocationContext
561
+ }) {
562
+ const results = tool._callLive({
563
+ args,
564
+ toolContext,
565
+ invocationContext
566
+ });
567
+ for await (const result of results) {
568
+ yield result;
569
+ }
570
+ }
571
+ __name(callToolLive, "callToolLive");
572
+ async function waitForTaskWithTimeout(task, timeoutMs) {
573
+ let timeoutId;
574
+ const timeoutPromise = new Promise((resolve) => {
575
+ timeoutId = setTimeout(resolve, timeoutMs);
576
+ });
577
+ try {
578
+ await Promise.race([
579
+ task.promise.then(
580
+ () => void 0,
581
+ () => void 0
582
+ ),
583
+ timeoutPromise
584
+ ]);
585
+ } finally {
586
+ if (timeoutId !== void 0) {
587
+ clearTimeout(timeoutId);
588
+ }
589
+ }
590
+ }
591
+ __name(waitForTaskWithTimeout, "waitForTaskWithTimeout");
592
+ const STOP_STREAMING_FUNCTION_NAME = "stop_streaming";
593
+ const STOP_STREAMING_TIMEOUT_MS = 1e3;
594
+ async function processFunctionLiveHelper({
595
+ tool,
596
+ toolContext,
597
+ functionCall,
598
+ functionArgs,
599
+ invocationContext
600
+ }) {
601
+ var _a2, _b2;
602
+ let functionResponse = void 0;
603
+ const targetFunctionName = typeof functionArgs["function_name"] === "string" ? functionArgs["function_name"] : typeof functionArgs["functionName"] === "string" ? functionArgs["functionName"] : void 0;
604
+ if (functionCall.name === STOP_STREAMING_FUNCTION_NAME && targetFunctionName !== void 0) {
605
+ const activeTasks = invocationContext.activeStreamingTools;
606
+ const activeTask = (_a2 = activeTasks == null ? void 0 : activeTasks[targetFunctionName]) == null ? void 0 : _a2.task;
607
+ if (activeTasks && activeTask && !activeTask.done()) {
608
+ activeTask.cancel();
609
+ await waitForTaskWithTimeout(activeTask, STOP_STREAMING_TIMEOUT_MS);
610
+ if (!activeTask.done()) {
611
+ import_logger.logger.warn(`The task for ${targetFunctionName} is not cancelled yet.`);
612
+ functionResponse = {
613
+ status: `The task is not cancelled yet for ${targetFunctionName}.`
614
+ };
615
+ } else {
616
+ activeTasks[targetFunctionName].task = void 0;
617
+ functionResponse = {
618
+ status: `Successfully stopped streaming function ${targetFunctionName}`
619
+ };
620
+ }
621
+ } else {
622
+ functionResponse = {
623
+ status: `No active streaming function named ${targetFunctionName} found`
624
+ };
625
+ }
626
+ } else if (isStreamingTool(tool)) {
627
+ const task = new import_task.Task(async (abortSignal) => {
628
+ var _a3, _b3;
629
+ const generator = callToolLive({
630
+ tool,
631
+ args: functionArgs,
632
+ toolContext,
633
+ invocationContext
634
+ });
635
+ let abortCleanup;
636
+ const abortPromise = new Promise(
637
+ (resolve) => {
638
+ if (abortSignal.aborted) {
639
+ resolve({ value: void 0, done: true });
640
+ return;
641
+ }
642
+ const onAbort = /* @__PURE__ */ __name(() => {
643
+ resolve({ value: void 0, done: true });
644
+ }, "onAbort");
645
+ abortSignal.addEventListener("abort", onAbort, { once: true });
646
+ abortCleanup = /* @__PURE__ */ __name(() => abortSignal.removeEventListener("abort", onAbort), "abortCleanup");
647
+ }
648
+ );
649
+ try {
650
+ while (!abortSignal.aborted) {
651
+ const nextResult = await Promise.race([
652
+ generator.next(),
653
+ abortPromise
654
+ ]);
655
+ if (abortSignal.aborted || nextResult.done) {
656
+ break;
657
+ }
658
+ const result = nextResult.value;
659
+ const updatedContent = (0, import_genai.createUserContent)(
660
+ `Function ${tool.name} returned: ${String(result)}`
661
+ );
662
+ (_a3 = invocationContext.liveRequestQueue) == null ? void 0 : _a3.sendContent(updatedContent);
663
+ }
664
+ } finally {
665
+ abortCleanup == null ? void 0 : abortCleanup();
666
+ if (abortSignal.aborted) {
667
+ void ((_b3 = generator.return) == null ? void 0 : _b3.call(generator, void 0));
668
+ }
669
+ }
670
+ });
671
+ (_b2 = invocationContext.activeStreamingTools) != null ? _b2 : invocationContext.activeStreamingTools = {};
672
+ if (tool.name in invocationContext.activeStreamingTools) {
673
+ invocationContext.activeStreamingTools[tool.name].task = task;
674
+ } else {
675
+ invocationContext.activeStreamingTools[tool.name] = new import_active_streaming_tool.ActiveStreamingTool({ task });
676
+ }
677
+ functionResponse = {
678
+ status: "The function is running asynchronously and the results are pending."
679
+ };
680
+ } else {
681
+ functionResponse = await callToolAsync(tool, functionArgs, toolContext);
682
+ }
683
+ return functionResponse;
684
+ }
685
+ __name(processFunctionLiveHelper, "processFunctionLiveHelper");
513
686
  function findEventByFunctionCallId(events, functionCallId, endIndex = events.length) {
514
687
  for (let i = endIndex - 1; i >= 0; i--) {
515
688
  const event = events[i];
@@ -579,6 +752,7 @@ __name(getConflictingFunctionResponseAuthors, "getConflictingFunctionResponseAut
579
752
  getLongRunningFunctionCalls,
580
753
  handleFunctionCallList,
581
754
  handleFunctionCallsAsync,
755
+ handleFunctionCallsLive,
582
756
  isToolNotFound,
583
757
  mergeParallelFunctionResponseEvents,
584
758
  populateClientFunctionCallId,
@@ -117,7 +117,10 @@ async function injectSessionState(template, readonlyContext) {
117
117
  resolved: resolveSourceNode(match[0], match[1], match[2], scope)
118
118
  })) : [];
119
119
  const pattern = /\{+[^{}]*}+/g;
120
- const matches = Array.from(template.matchAll(pattern));
120
+ const matches = Array.from(template.matchAll(pattern)).filter((match) => {
121
+ const previous = template[match.index - 1];
122
+ return previous !== "$" && previous !== "\\";
123
+ });
121
124
  if (matches.length === 0 && sourceMatches.length === 0) {
122
125
  return template;
123
126
  }
@@ -26,6 +26,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
26
26
  var invocation_context_exports = {};
27
27
  __export(invocation_context_exports, {
28
28
  InvocationContext: () => InvocationContext,
29
+ LlmCallsLimitExceededError: () => LlmCallsLimitExceededError,
30
+ isLlmCallsLimitExceededError: () => isLlmCallsLimitExceededError,
29
31
  newInvocationContextId: () => newInvocationContextId,
30
32
  requireAgent: () => requireAgent
31
33
  });
@@ -36,6 +38,24 @@ var import_env_aware_utils = require("../utils/env_aware_utils.js");
36
38
  * Copyright 2025 Google LLC
37
39
  * SPDX-License-Identifier: Apache-2.0
38
40
  */
41
+ var _a, _b;
42
+ const LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
43
+ "google.adk.llmCallsLimitExceededError"
44
+ );
45
+ const _LlmCallsLimitExceededError = class _LlmCallsLimitExceededError extends (_b = Error, _a = LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL, _b) {
46
+ constructor(message) {
47
+ super(message);
48
+ this[_a] = true;
49
+ this.name = "LlmCallsLimitExceededError";
50
+ Object.setPrototypeOf(this, _LlmCallsLimitExceededError.prototype);
51
+ }
52
+ };
53
+ __name(_LlmCallsLimitExceededError, "LlmCallsLimitExceededError");
54
+ let LlmCallsLimitExceededError = _LlmCallsLimitExceededError;
55
+ function isLlmCallsLimitExceededError(obj) {
56
+ return typeof obj === "object" && obj !== null && LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL in obj && obj[LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL] === true;
57
+ }
58
+ __name(isLlmCallsLimitExceededError, "isLlmCallsLimitExceededError");
39
59
  const _InvocationCostManager = class _InvocationCostManager {
40
60
  constructor() {
41
61
  this.numberOfLlmCalls = 0;
@@ -49,7 +69,7 @@ const _InvocationCostManager = class _InvocationCostManager {
49
69
  incrementAndEnforceLlmCallsLimit(runConfig) {
50
70
  this.numberOfLlmCalls++;
51
71
  if (runConfig && runConfig.maxLlmCalls > 0 && this.numberOfLlmCalls > runConfig.maxLlmCalls) {
52
- throw new Error(
72
+ throw new LlmCallsLimitExceededError(
53
73
  `Max number of llm calls limit of ${runConfig.maxLlmCalls} exceeded`
54
74
  );
55
75
  }
@@ -62,7 +82,7 @@ const _InvocationContext = class _InvocationContext {
62
82
  * @param params The parameters for creating an invocation context.
63
83
  */
64
84
  constructor(params) {
65
- var _a, _b;
85
+ var _a2, _b2;
66
86
  this.artifactService = params.artifactService;
67
87
  this.sessionService = params.sessionService;
68
88
  this.memoryService = params.memoryService;
@@ -79,9 +99,9 @@ const _InvocationContext = class _InvocationContext {
79
99
  this.abortSignal = params.abortSignal;
80
100
  this.workflowInstructionScope = params.workflowInstructionScope;
81
101
  this.isolationScope = params.isolationScope;
82
- this.nodeToolDepth = (_a = params.nodeToolDepth) != null ? _a : 0;
102
+ this.nodeToolDepth = (_a2 = params.nodeToolDepth) != null ? _a2 : 0;
83
103
  this.a2aMetadata = params.a2aMetadata;
84
- this.invocationCostManager = (_b = params.invocationCostManager) != null ? _b : new InvocationCostManager();
104
+ this.invocationCostManager = (_b2 = params.invocationCostManager) != null ? _b2 : new InvocationCostManager();
85
105
  this.liveRequestQueue = params.liveRequestQueue;
86
106
  this.liveSessionResumptionHandle = params.liveSessionResumptionHandle;
87
107
  }
@@ -136,6 +156,8 @@ __name(requireAgent, "requireAgent");
136
156
  // Annotate the CommonJS export names for ESM import in node:
137
157
  0 && (module.exports = {
138
158
  InvocationContext,
159
+ LlmCallsLimitExceededError,
160
+ isLlmCallsLimitExceededError,
139
161
  newInvocationContextId,
140
162
  requireAgent
141
163
  });