@google/adk 1.4.0 → 1.6.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 (213) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +12 -2
  2. package/dist/cjs/a2a/agent_to_a2a.js +18 -3
  3. package/dist/cjs/a2a/auth.js +65 -0
  4. package/dist/cjs/a2a/event_converter_utils.js +47 -18
  5. package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
  6. package/dist/cjs/agents/base_agent.js +39 -0
  7. package/dist/cjs/agents/functions.js +26 -28
  8. package/dist/cjs/agents/llm_agent.js +4 -2
  9. package/dist/cjs/agents/loop_agent.js +15 -3
  10. package/dist/cjs/agents/processors/basic_llm_request_processor.js +3 -2
  11. package/dist/cjs/agents/processors/content_processor_utils.js +2 -1
  12. package/dist/cjs/agents/processors/content_request_processor.js +2 -21
  13. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +3 -1
  14. package/dist/cjs/agents/routed_agent.js +31 -0
  15. package/dist/cjs/agents/run_config.js +3 -2
  16. package/dist/cjs/artifacts/in_memory_artifact_service.js +17 -9
  17. package/dist/cjs/auth/credential_service/in_memory_credential_service.js +14 -3
  18. package/dist/cjs/code_executors/unsafe_local_code_executor.js +23 -12
  19. package/dist/cjs/common.js +35 -0
  20. package/dist/cjs/context/agent_controlled_context_compactor.js +2 -11
  21. package/dist/cjs/context/anchored_context_compactor.js +127 -0
  22. package/dist/cjs/context/compaction_utils.js +64 -0
  23. package/dist/cjs/context/token_based_context_compactor.js +13 -44
  24. package/dist/cjs/events/compacted_event.js +9 -3
  25. package/dist/cjs/events/event.js +28 -0
  26. package/dist/cjs/index.js +7 -0
  27. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  28. package/dist/cjs/memory/in_memory_memory_service.js +13 -2
  29. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +3 -0
  30. package/dist/cjs/plugins/base_plugin.js +4 -2
  31. package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
  32. package/dist/cjs/runner/runner.js +69 -23
  33. package/dist/cjs/sessions/base_session_service.js +8 -3
  34. package/dist/cjs/sessions/in_memory_session_service.js +8 -8
  35. package/dist/cjs/sessions/vertex_ai_session_service.js +22 -10
  36. package/dist/cjs/skills/loader.js +40 -6
  37. package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
  38. package/dist/cjs/tools/example_tool.js +68 -0
  39. package/dist/cjs/tools/get_user_choice_tool.js +53 -0
  40. package/dist/cjs/tools/load_web_page.js +250 -0
  41. package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
  42. package/dist/cjs/tools/mcp/mcp_session_manager.js +35 -21
  43. package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
  44. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  45. package/dist/cjs/tools/request_input_tool.js +54 -0
  46. package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
  47. package/dist/cjs/tools/skill/skill_toolset.js +4 -2
  48. package/dist/cjs/utils/branch_trie.js +41 -0
  49. package/dist/cjs/utils/crypto_shim.js +43 -0
  50. package/dist/cjs/utils/env_aware_utils.js +15 -13
  51. package/dist/cjs/utils/error_utils.js +120 -0
  52. package/dist/cjs/utils/file_utils.js +5 -2
  53. package/dist/cjs/utils/output_schema_utils.js +43 -0
  54. package/dist/cjs/utils/streaming_utils.js +5 -5
  55. package/dist/cjs/utils/vertex_ai_utils.js +3 -0
  56. package/dist/cjs/version.js +1 -1
  57. package/dist/esm/a2a/a2a_remote_agent.js +12 -2
  58. package/dist/esm/a2a/agent_to_a2a.js +18 -3
  59. package/dist/esm/a2a/auth.js +37 -0
  60. package/dist/esm/a2a/event_converter_utils.js +47 -18
  61. package/dist/esm/a2a/metadata_converter_utils.js +1 -1
  62. package/dist/esm/agents/base_agent.js +39 -0
  63. package/dist/esm/agents/functions.js +27 -24
  64. package/dist/esm/agents/llm_agent.js +6 -4
  65. package/dist/esm/agents/loop_agent.js +15 -3
  66. package/dist/esm/agents/processors/basic_llm_request_processor.js +3 -2
  67. package/dist/esm/agents/processors/content_processor_utils.js +2 -1
  68. package/dist/esm/agents/processors/content_request_processor.js +2 -21
  69. package/dist/esm/agents/processors/instructions_llm_request_processor.js +3 -1
  70. package/dist/esm/agents/routed_agent.js +31 -0
  71. package/dist/esm/agents/run_config.js +3 -2
  72. package/dist/esm/artifacts/in_memory_artifact_service.js +17 -9
  73. package/dist/esm/auth/credential_service/in_memory_credential_service.js +14 -3
  74. package/dist/esm/code_executors/unsafe_local_code_executor.js +22 -11
  75. package/dist/esm/common.js +29 -1
  76. package/dist/esm/context/agent_controlled_context_compactor.js +2 -11
  77. package/dist/esm/context/anchored_context_compactor.js +99 -0
  78. package/dist/esm/context/compaction_utils.js +38 -0
  79. package/dist/esm/context/token_based_context_compactor.js +16 -44
  80. package/dist/esm/events/compacted_event.js +7 -2
  81. package/dist/esm/events/event.js +24 -0
  82. package/dist/esm/index.js +8 -1
  83. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  84. package/dist/esm/memory/in_memory_memory_service.js +13 -2
  85. package/dist/esm/memory/vertex_ai_memory_bank_service.js +7 -1
  86. package/dist/esm/plugins/base_plugin.js +4 -2
  87. package/dist/esm/plugins/global_instruction_plugin.js +69 -0
  88. package/dist/esm/runner/runner.js +69 -23
  89. package/dist/esm/sessions/base_session_service.js +8 -3
  90. package/dist/esm/sessions/in_memory_session_service.js +8 -8
  91. package/dist/esm/sessions/vertex_ai_session_service.js +26 -11
  92. package/dist/esm/skills/loader.js +40 -6
  93. package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
  94. package/dist/esm/tools/example_tool.js +42 -0
  95. package/dist/esm/tools/get_user_choice_tool.js +25 -0
  96. package/dist/esm/tools/load_web_page.js +221 -0
  97. package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
  98. package/dist/esm/tools/mcp/mcp_session_manager.js +35 -21
  99. package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
  100. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  101. package/dist/esm/tools/request_input_tool.js +26 -0
  102. package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
  103. package/dist/esm/tools/skill/skill_toolset.js +4 -2
  104. package/dist/esm/utils/branch_trie.js +13 -0
  105. package/dist/esm/utils/crypto_shim.js +15 -0
  106. package/dist/esm/utils/env_aware_utils.js +15 -13
  107. package/dist/esm/utils/error_utils.js +92 -0
  108. package/dist/esm/utils/file_utils.js +5 -2
  109. package/dist/esm/utils/output_schema_utils.js +15 -0
  110. package/dist/esm/utils/streaming_utils.js +1 -1
  111. package/dist/esm/utils/vertex_ai_utils.js +2 -0
  112. package/dist/esm/version.js +1 -1
  113. package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
  114. package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
  115. package/dist/types/a2a/auth.d.ts +30 -0
  116. package/dist/types/a2a/event_converter_utils.d.ts +4 -1
  117. package/dist/types/agents/base_agent.d.ts +29 -1
  118. package/dist/types/agents/functions.d.ts +1 -9
  119. package/dist/types/agents/llm_agent.d.ts +5 -1
  120. package/dist/types/agents/loop_agent.d.ts +2 -2
  121. package/dist/types/agents/routed_agent.d.ts +24 -1
  122. package/dist/types/agents/run_config.d.ts +1 -1
  123. package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +11 -0
  124. package/dist/types/code_executors/unsafe_local_code_executor.d.ts +5 -1
  125. package/dist/types/common.d.ts +11 -2
  126. package/dist/types/context/agent_controlled_context_compactor.d.ts +0 -1
  127. package/dist/types/context/anchored_context_compactor.d.ts +35 -0
  128. package/dist/types/context/compaction_utils.d.ts +23 -0
  129. package/dist/types/context/token_based_context_compactor.d.ts +0 -1
  130. package/dist/types/events/compacted_event.d.ts +10 -0
  131. package/dist/types/events/event.d.ts +13 -0
  132. package/dist/types/index.d.ts +5 -3
  133. package/dist/types/memory/in_memory_memory_service.d.ts +11 -0
  134. package/dist/types/plugins/base_plugin.d.ts +4 -2
  135. package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
  136. package/dist/types/runner/runner.d.ts +1 -1
  137. package/dist/types/sessions/base_session_service.d.ts +8 -0
  138. package/dist/types/sessions/in_memory_session_service.d.ts +9 -0
  139. package/dist/types/sessions/vertex_ai_session_service.d.ts +19 -1
  140. package/dist/types/skills/loader.d.ts +5 -0
  141. package/dist/types/tools/enterprise_web_search_tool.d.ts +26 -0
  142. package/dist/types/tools/example_tool.d.ts +21 -0
  143. package/dist/types/tools/get_user_choice_tool.d.ts +14 -0
  144. package/dist/types/tools/load_web_page.d.ts +33 -0
  145. package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
  146. package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
  147. package/dist/types/tools/request_input_tool.d.ts +15 -0
  148. package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
  149. package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
  150. package/dist/types/utils/branch_trie.d.ts +14 -0
  151. package/dist/types/utils/crypto_shim.d.ts +16 -0
  152. package/dist/types/utils/env_aware_utils.d.ts +23 -0
  153. package/dist/types/utils/error_utils.d.ts +18 -0
  154. package/dist/types/utils/output_schema_utils.d.ts +18 -0
  155. package/dist/types/utils/vertex_ai_utils.d.ts +1 -0
  156. package/dist/types/version.d.ts +1 -1
  157. package/dist/web/a2a/a2a_remote_agent.js +12 -2
  158. package/dist/web/a2a/agent_to_a2a.js +18 -3
  159. package/dist/web/a2a/auth.js +37 -0
  160. package/dist/web/a2a/event_converter_utils.js +47 -18
  161. package/dist/web/a2a/metadata_converter_utils.js +1 -1
  162. package/dist/web/agents/base_agent.js +39 -0
  163. package/dist/web/agents/functions.js +27 -24
  164. package/dist/web/agents/llm_agent.js +6 -4
  165. package/dist/web/agents/loop_agent.js +27 -3
  166. package/dist/web/agents/processors/basic_llm_request_processor.js +3 -2
  167. package/dist/web/agents/processors/content_processor_utils.js +2 -1
  168. package/dist/web/agents/processors/content_request_processor.js +2 -21
  169. package/dist/web/agents/processors/instructions_llm_request_processor.js +3 -1
  170. package/dist/web/agents/routed_agent.js +31 -0
  171. package/dist/web/agents/run_config.js +8 -3
  172. package/dist/web/artifacts/in_memory_artifact_service.js +17 -9
  173. package/dist/web/auth/credential_service/in_memory_credential_service.js +14 -3
  174. package/dist/web/code_executors/unsafe_local_code_executor.js +22 -11
  175. package/dist/web/common.js +29 -1
  176. package/dist/web/context/agent_controlled_context_compactor.js +2 -11
  177. package/dist/web/context/anchored_context_compactor.js +117 -0
  178. package/dist/web/context/compaction_utils.js +38 -0
  179. package/dist/web/context/token_based_context_compactor.js +16 -44
  180. package/dist/web/events/compacted_event.js +7 -2
  181. package/dist/web/events/event.js +24 -0
  182. package/dist/web/index.js +8 -1
  183. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  184. package/dist/web/memory/in_memory_memory_service.js +13 -2
  185. package/dist/web/memory/vertex_ai_memory_bank_service.js +7 -1
  186. package/dist/web/plugins/base_plugin.js +4 -2
  187. package/dist/web/plugins/global_instruction_plugin.js +67 -0
  188. package/dist/web/runner/runner.js +65 -22
  189. package/dist/web/sessions/base_session_service.js +8 -3
  190. package/dist/web/sessions/in_memory_session_service.js +8 -8
  191. package/dist/web/sessions/vertex_ai_session_service.js +24 -11
  192. package/dist/web/skills/loader.js +40 -6
  193. package/dist/web/tools/enterprise_web_search_tool.js +55 -0
  194. package/dist/web/tools/example_tool.js +42 -0
  195. package/dist/web/tools/get_user_choice_tool.js +25 -0
  196. package/dist/web/tools/load_web_page.js +221 -0
  197. package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
  198. package/dist/web/tools/mcp/mcp_session_manager.js +35 -21
  199. package/dist/web/tools/mcp/mcp_toolset.js +63 -0
  200. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  201. package/dist/web/tools/request_input_tool.js +26 -0
  202. package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
  203. package/dist/web/tools/skill/skill_toolset.js +4 -2
  204. package/dist/web/utils/branch_trie.js +13 -0
  205. package/dist/web/utils/crypto_shim.js +15 -0
  206. package/dist/web/utils/env_aware_utils.js +15 -13
  207. package/dist/web/utils/error_utils.js +92 -0
  208. package/dist/web/utils/file_utils.js +5 -2
  209. package/dist/web/utils/output_schema_utils.js +15 -0
  210. package/dist/web/utils/streaming_utils.js +1 -1
  211. package/dist/web/utils/vertex_ai_utils.js +2 -0
  212. package/dist/web/version.js +1 -1
  213. package/package.json +1 -1
@@ -0,0 +1,114 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ import { Type } from "@google/genai";
9
+ import { appendInstructions } from "../../models/llm_request.js";
10
+ import { logger } from "../../utils/logger.js";
11
+ import {
12
+ BaseTool
13
+ } from "../base_tool.js";
14
+ class LoadMcpResourceTool extends BaseTool {
15
+ constructor(mcpToolset) {
16
+ super({
17
+ name: "load_mcp_resource",
18
+ description: `Loads resources from the MCP server.
19
+
20
+ NOTE: Call when you need access to resources.`
21
+ });
22
+ this.mcpToolset = mcpToolset;
23
+ }
24
+ _getDeclaration() {
25
+ return {
26
+ name: this.name,
27
+ description: this.description,
28
+ parameters: {
29
+ type: Type.OBJECT,
30
+ properties: {
31
+ resource_names: {
32
+ type: Type.ARRAY,
33
+ items: {
34
+ type: Type.STRING
35
+ },
36
+ description: "The names of the MCP resources to load."
37
+ }
38
+ }
39
+ }
40
+ };
41
+ }
42
+ async runAsync({ args }) {
43
+ const resourceNames = args["resource_names"] || [];
44
+ return {
45
+ resource_names: resourceNames,
46
+ status: "resource contents temporarily inserted and removed. to access these resources, call load_mcp_resource tool again."
47
+ };
48
+ }
49
+ async processLlmRequest(request) {
50
+ await super.processLlmRequest(request);
51
+ await this.appendResourcesToLlmRequest(request.llmRequest);
52
+ }
53
+ async appendResourcesToLlmRequest(llmRequest) {
54
+ var _a, _b;
55
+ try {
56
+ const availableResourceNames = await this.mcpToolset.listResources();
57
+ if (availableResourceNames.length > 0) {
58
+ appendInstructions(llmRequest, [
59
+ `You have a list of MCP resources:
60
+ ${JSON.stringify(
61
+ availableResourceNames
62
+ )}
63
+
64
+ When the user asks questions about any of the resources, you should call the
65
+ \`load_mcp_resource\` function to load the resource. Always call load_mcp_resource
66
+ before answering questions related to the resources.`
67
+ ]);
68
+ }
69
+ } catch (e) {
70
+ logger.warn(`Failed to list MCP resources: ${e}`);
71
+ }
72
+ const lastContent = llmRequest.contents.at(-1);
73
+ const functionResponse = (_b = (_a = lastContent == null ? void 0 : lastContent.parts) == null ? void 0 : _a[0]) == null ? void 0 : _b.functionResponse;
74
+ if (!functionResponse || functionResponse.name !== this.name) {
75
+ return;
76
+ }
77
+ const response = functionResponse.response || {};
78
+ const requestedResourceNames = response["resource_names"] || [];
79
+ for (const resourceName of requestedResourceNames) {
80
+ try {
81
+ const resourceContents = await this.mcpToolset.readResource(resourceName);
82
+ for (const content of resourceContents) {
83
+ llmRequest.contents.push({
84
+ role: "user",
85
+ parts: [
86
+ { text: `Resource ${resourceName} is:` },
87
+ this.mcpContentToPart(content, resourceName)
88
+ ]
89
+ });
90
+ }
91
+ } catch (e) {
92
+ logger.warn(`Failed to read MCP resource '${resourceName}': ${e}`);
93
+ }
94
+ }
95
+ }
96
+ mcpContentToPart(content, resourceName) {
97
+ var _a;
98
+ if ("text" in content) {
99
+ return { text: content.text };
100
+ }
101
+ if ("blob" in content) {
102
+ return {
103
+ inlineData: {
104
+ data: content.blob,
105
+ mimeType: (_a = content.mimeType) != null ? _a : "application/octet-stream"
106
+ }
107
+ };
108
+ }
109
+ return { text: `[Unknown content type for ${resourceName}]` };
110
+ }
111
+ }
112
+ export {
113
+ LoadMcpResourceTool
114
+ };
@@ -12,6 +12,11 @@ import {
12
12
  import {
13
13
  StreamableHTTPClientTransport
14
14
  } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
15
+ import { formatError } from "../../utils/error_utils.js";
16
+ import { logger } from "../../utils/logger.js";
17
+ function logTransportError(err) {
18
+ logger.error("MCP transport error: " + formatError(err));
19
+ }
15
20
  class MCPSessionManager {
16
21
  constructor(connectionParams) {
17
22
  this.activeSessions = /* @__PURE__ */ new Set();
@@ -20,31 +25,40 @@ class MCPSessionManager {
20
25
  async createSession() {
21
26
  var _a;
22
27
  const client = new Client({ name: "MCPClient", version: "1.0.0" });
23
- switch (this.connectionParams.type) {
24
- case "StdioConnectionParams":
25
- await client.connect(
26
- new StdioClientTransport(this.connectionParams.serverParams)
27
- );
28
- break;
29
- case "StreamableHTTPConnectionParams": {
30
- const options = (_a = this.connectionParams.transportOptions) != null ? _a : {};
31
- if (!options.requestInit && this.connectionParams.header !== void 0) {
32
- options.requestInit = {
33
- headers: this.connectionParams.header
34
- };
28
+ try {
29
+ switch (this.connectionParams.type) {
30
+ case "StdioConnectionParams": {
31
+ const transport = new StdioClientTransport(
32
+ this.connectionParams.serverParams
33
+ );
34
+ transport.onerror = logTransportError;
35
+ await client.connect(transport);
36
+ break;
35
37
  }
36
- await client.connect(
37
- new StreamableHTTPClientTransport(
38
+ case "StreamableHTTPConnectionParams": {
39
+ const options = (_a = this.connectionParams.transportOptions) != null ? _a : {};
40
+ if (!options.requestInit && this.connectionParams.header !== void 0) {
41
+ options.requestInit = {
42
+ headers: this.connectionParams.header
43
+ };
44
+ }
45
+ const transport = new StreamableHTTPClientTransport(
38
46
  new URL(this.connectionParams.url),
39
47
  options
40
- )
41
- );
42
- break;
43
- }
44
- default: {
45
- const _exhaustiveCheck = this.connectionParams;
46
- break;
48
+ );
49
+ transport.onerror = logTransportError;
50
+ await client.connect(transport);
51
+ break;
52
+ }
53
+ default: {
54
+ const _exhaustiveCheck = this.connectionParams;
55
+ break;
56
+ }
47
57
  }
58
+ } catch (err) {
59
+ throw new Error("Failed to create MCP session: " + formatError(err), {
60
+ cause: err
61
+ });
48
62
  }
49
63
  this.activeSessions.add(client);
50
64
  return client;
@@ -48,6 +48,69 @@ class MCPToolset extends BaseToolset {
48
48
  );
49
49
  return tools;
50
50
  }
51
+ /**
52
+ * Lists the names of the resources advertised by the MCP server.
53
+ *
54
+ * @return The resource names available on the server.
55
+ */
56
+ async listResources() {
57
+ const session = await this.mcpSessionManager.createSession();
58
+ try {
59
+ const result = await session.listResources();
60
+ return result.resources.map((resource) => resource.name);
61
+ } finally {
62
+ await this.mcpSessionManager.closeSession(session);
63
+ }
64
+ }
65
+ /**
66
+ * Returns metadata for the resource whose name matches `name`.
67
+ *
68
+ * @param name The advertised name of the resource.
69
+ * @return The matching MCP `Resource`.
70
+ * @throws If no resource with the given name is advertised by the server.
71
+ */
72
+ async getResourceInfo(name) {
73
+ const session = await this.mcpSessionManager.createSession();
74
+ let result;
75
+ try {
76
+ result = await session.listResources();
77
+ } finally {
78
+ await this.mcpSessionManager.closeSession(session);
79
+ }
80
+ const resource = result.resources.find(
81
+ (candidate) => candidate.name === name
82
+ );
83
+ if (!resource) {
84
+ throw new Error(`Resource with name '${name}' not found.`);
85
+ }
86
+ return resource;
87
+ }
88
+ /**
89
+ * Reads the contents of the named resource from the MCP server.
90
+ *
91
+ * The resource name is resolved to a URI via {@link getResourceInfo} before
92
+ * reading. Binary contents are returned base64-encoded, exactly as provided
93
+ * by the server (never decoded and re-encoded).
94
+ *
95
+ * @param name The advertised name of the resource to read.
96
+ * @return The resource contents (text and/or base64-encoded binary).
97
+ * @throws If the resource is unknown or has no URI.
98
+ */
99
+ async readResource(name) {
100
+ const resourceInfo = await this.getResourceInfo(name);
101
+ if (!resourceInfo.uri) {
102
+ throw new Error(`Resource '${name}' has no URI.`);
103
+ }
104
+ const session = await this.mcpSessionManager.createSession();
105
+ try {
106
+ const result = await session.readResource({
107
+ uri: resourceInfo.uri
108
+ });
109
+ return result.contents;
110
+ } finally {
111
+ await this.mcpSessionManager.closeSession(session);
112
+ }
113
+ }
51
114
  async close() {
52
115
  const sessions = this.mcpSessionManager.getActiveSessions();
53
116
  await Promise.allSettled(
@@ -62,19 +62,22 @@ let ToolAuthHandler = class {
62
62
  rawAuthCredential: this.authCredential,
63
63
  credentialKey: this.credentialKey || "default_openapi_key"
64
64
  };
65
- const credential = this.context.getAuthResponse(authConfig);
66
- if (credential) {
67
- const exchanger = new AutoAuthCredentialExchanger();
68
- const result = await exchanger.exchange({
69
- authScheme: this.authScheme,
70
- authCredential: credential
71
- });
65
+ const authResponseCredential = this.context.getAuthResponse(authConfig);
66
+ const credential = authResponseCredential != null ? authResponseCredential : this.authCredential;
67
+ if (!credential) {
68
+ this.context.requestCredential(authConfig);
69
+ return { state: "pending" };
70
+ }
71
+ const exchanger = new AutoAuthCredentialExchanger();
72
+ const result = await exchanger.exchange({
73
+ authScheme: this.authScheme,
74
+ authCredential: credential
75
+ });
76
+ if (authResponseCredential || result.wasExchanged) {
72
77
  const key = store.getCredentialKey(this.authScheme);
73
78
  store.storeCredential(key, result.credential);
74
- return { state: "done", authCredential: result.credential };
75
79
  }
76
- this.context.requestCredential(authConfig);
77
- return { state: "pending" };
80
+ return { state: "done", authCredential: result.credential };
78
81
  }
79
82
  };
80
83
  __decorateClass([
@@ -0,0 +1,26 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ import { z } from "zod";
9
+ import { LongRunningFunctionTool } from "./long_running_tool.js";
10
+ const requestInputTool = new LongRunningFunctionTool({
11
+ name: "adk_request_input",
12
+ description: "Presents a custom message to the user and awaits unstructured or structured input.",
13
+ parameters: z.object({
14
+ message: z.string().describe("The prompt for the user."),
15
+ responseSchema: z.record(z.string(), z.unknown()).optional().describe("Expected schema of the response.")
16
+ }),
17
+ execute: async (input, context) => {
18
+ if (context) {
19
+ context.actions.skipSummarization = true;
20
+ }
21
+ return null;
22
+ }
23
+ });
24
+ export {
25
+ requestInputTool
26
+ };
@@ -21,6 +21,15 @@ import { CodeExecutionLanguage } from "../../code_executors/code_execution_utils
21
21
  import { experimental } from "../../utils/experimental.js";
22
22
  import { materializeFiles } from "../../utils/file_utils.js";
23
23
  import { BaseTool } from "../base_tool.js";
24
+ var RunSkillInlineScriptErrorCode = /* @__PURE__ */ ((RunSkillInlineScriptErrorCode2) => {
25
+ RunSkillInlineScriptErrorCode2["MISSING_SCRIPT_CONTENT"] = "MISSING_SCRIPT_CONTENT";
26
+ RunSkillInlineScriptErrorCode2["MISSING_LANGUAGE"] = "MISSING_LANGUAGE";
27
+ RunSkillInlineScriptErrorCode2["NO_CODE_EXECUTOR"] = "NO_CODE_EXECUTOR";
28
+ RunSkillInlineScriptErrorCode2["EXECUTION_ERROR"] = "EXECUTION_ERROR";
29
+ RunSkillInlineScriptErrorCode2["CONFIRMATION_REJECTED"] = "CONFIRMATION_REJECTED";
30
+ return RunSkillInlineScriptErrorCode2;
31
+ })(RunSkillInlineScriptErrorCode || {});
32
+ const REQUIRE_CONFIRMATION_MESSAGE = "This tool call needs external confirmation before completion.";
24
33
  let RunSkillInlineScriptTool = class extends BaseTool {
25
34
  constructor(toolset) {
26
35
  super({
@@ -70,13 +79,13 @@ let RunSkillInlineScriptTool = class extends BaseTool {
70
79
  if (!inlineScriptContent) {
71
80
  return {
72
81
  error: "Script content is required.",
73
- errorCode: "MISSING_SCRIPT_CONTENT"
82
+ errorCode: "MISSING_SCRIPT_CONTENT" /* MISSING_SCRIPT_CONTENT */
74
83
  };
75
84
  }
76
85
  if (!language) {
77
86
  return {
78
87
  error: "Language is required.",
79
- errorCode: "MISSING_LANGUAGE"
88
+ errorCode: "MISSING_LANGUAGE" /* MISSING_LANGUAGE */
80
89
  };
81
90
  }
82
91
  let codeExecutor = (_a = this.toolset) == null ? void 0 : _a.codeExecutor;
@@ -89,9 +98,17 @@ let RunSkillInlineScriptTool = class extends BaseTool {
89
98
  if (!codeExecutor) {
90
99
  return {
91
100
  error: "No code executor configured.",
92
- errorCode: "NO_CODE_EXECUTOR"
101
+ errorCode: "NO_CODE_EXECUTOR" /* NO_CODE_EXECUTOR */
93
102
  };
94
103
  }
104
+ const confirmationResult = this.enforceConfirmation(
105
+ toolContext,
106
+ inlineScriptContent,
107
+ language
108
+ );
109
+ if (confirmationResult) {
110
+ return confirmationResult;
111
+ }
95
112
  try {
96
113
  const result = await codeExecutor.executeCode({
97
114
  invocationContext: toolContext.invocationContext,
@@ -107,14 +124,46 @@ let RunSkillInlineScriptTool = class extends BaseTool {
107
124
  } catch (e) {
108
125
  return {
109
126
  error: `Failed to execute inline script: ${e.message}`,
110
- errorCode: "EXECUTION_ERROR"
127
+ errorCode: "EXECUTION_ERROR" /* EXECUTION_ERROR */
128
+ };
129
+ }
130
+ }
131
+ /**
132
+ * Enforces a human-in-the-loop confirmation gate before executing an inline
133
+ * script, using the repo's standard tool-confirmation mechanism.
134
+ *
135
+ * - When no confirmation has been provided yet, a confirmation is requested
136
+ * (surfacing the language and script that would run) and an intermediate
137
+ * result is returned so the tool call pauses until the client responds.
138
+ * - When a confirmation exists but was not confirmed, a rejection error is
139
+ * returned and execution is refused.
140
+ * - When the confirmation is confirmed, `undefined` is returned to allow the
141
+ * caller to proceed with execution.
142
+ */
143
+ enforceConfirmation(toolContext, scriptContent, language) {
144
+ const confirmation = toolContext.toolConfirmation;
145
+ if (!confirmation) {
146
+ toolContext.requestConfirmation({
147
+ hint: `Confirmation is required before executing an inline skill script. The agent requested to run the following ${language} script in the code executor. Only approve if you trust its contents:
148
+
149
+ ` + scriptContent,
150
+ payload: { language, scriptContent }
151
+ });
152
+ return { partial: REQUIRE_CONFIRMATION_MESSAGE };
153
+ }
154
+ if (!confirmation.confirmed) {
155
+ return {
156
+ error: "Inline script execution was not confirmed and was rejected.",
157
+ errorCode: "CONFIRMATION_REJECTED" /* CONFIRMATION_REJECTED */
111
158
  };
112
159
  }
160
+ return void 0;
113
161
  }
114
162
  };
115
163
  RunSkillInlineScriptTool = __decorateClass([
116
164
  experimental
117
165
  ], RunSkillInlineScriptTool);
118
166
  export {
167
+ RunSkillInlineScriptErrorCode,
119
168
  RunSkillInlineScriptTool
120
169
  };
@@ -55,9 +55,11 @@ let SkillToolset = class extends BaseToolset {
55
55
  new ListSkillsTool(this),
56
56
  new LoadSkillTool(this),
57
57
  new LoadSkillResourceTool(this),
58
- new RunSkillScriptTool(this),
59
- new RunSkillInlineScriptTool(this)
58
+ new RunSkillScriptTool(this)
60
59
  ];
60
+ if (options.allowInlineScripts) {
61
+ this.tools.push(new RunSkillInlineScriptTool(this));
62
+ }
61
63
  if (this.registry) {
62
64
  this.tools.push(new SearchSkillsTool(this));
63
65
  }
@@ -0,0 +1,13 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ function isSegmentPrefix(currentBranch, targetBranch) {
9
+ return !targetBranch || targetBranch === currentBranch || !!currentBranch && currentBranch.startsWith(`${targetBranch}.`);
10
+ }
11
+ export {
12
+ isSegmentPrefix
13
+ };
@@ -0,0 +1,15 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ function randomUUID() {
9
+ throw new Error(
10
+ "randomUUID: no cryptographically secure source of randomness is available. Neither crypto.randomUUID() nor crypto.getRandomValues() is present in this environment."
11
+ );
12
+ }
13
+ export {
14
+ randomUUID
15
+ };
@@ -5,27 +5,29 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2025 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
+ import { randomUUID as nodeRandomUUID } from "node:crypto";
8
9
  function isBrowser() {
9
10
  return typeof window !== "undefined";
10
11
  }
11
- const UUID_MASK = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
12
12
  function randomUUID() {
13
- var _a;
13
+ var _a, _b;
14
14
  if ((_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) {
15
15
  return globalThis.crypto.randomUUID();
16
16
  }
17
- let uuid = "";
18
- for (let i = 0; i < UUID_MASK.length; i++) {
19
- const randomValue = Math.random() * 16 | 0;
20
- if (UUID_MASK[i] === "x") {
21
- uuid += randomValue.toString(16);
22
- } else if (UUID_MASK[i] === "y") {
23
- uuid += (randomValue & 3 | 8).toString(16);
24
- } else {
25
- uuid += UUID_MASK[i];
26
- }
17
+ if ((_b = globalThis.crypto) == null ? void 0 : _b.getRandomValues) {
18
+ const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
19
+ bytes[6] = bytes[6] & 15 | 64;
20
+ bytes[8] = bytes[8] & 63 | 128;
21
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
22
+ return [
23
+ hex.slice(0, 4),
24
+ hex.slice(4, 6),
25
+ hex.slice(6, 8),
26
+ hex.slice(8, 10),
27
+ hex.slice(10, 16)
28
+ ].map((group) => group.join("")).join("-");
27
29
  }
28
- return uuid;
30
+ return nodeRandomUUID();
29
31
  }
30
32
  function base64Encode(data) {
31
33
  if (isBrowser()) {
@@ -0,0 +1,92 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ const MAX_RESPONSE_BODY_LENGTH = 1e3;
9
+ const TRUNCATION_MARKER = "... [truncated]";
10
+ const UNKNOWN_ERROR = "Unknown error";
11
+ const MIN_HTTP_STATUS = 100;
12
+ const MAX_HTTP_STATUS = 599;
13
+ function asRecord(value) {
14
+ return value !== null && typeof value === "object" ? value : void 0;
15
+ }
16
+ function firstString(...values) {
17
+ for (const value of values) {
18
+ if (typeof value === "string") {
19
+ return value;
20
+ }
21
+ }
22
+ return void 0;
23
+ }
24
+ function truncateBody(body) {
25
+ return body.length > MAX_RESPONSE_BODY_LENGTH ? body.slice(0, MAX_RESPONSE_BODY_LENGTH) + TRUNCATION_MARKER : body;
26
+ }
27
+ function baseMessage(err) {
28
+ if (err instanceof Error) {
29
+ return err.message;
30
+ }
31
+ if (typeof err === "string") {
32
+ return err;
33
+ }
34
+ return String(err);
35
+ }
36
+ function extractHttpDetails(err) {
37
+ var _a, _b;
38
+ const record = asRecord(err);
39
+ if (record === void 0) {
40
+ return void 0;
41
+ }
42
+ const response = asRecord(record["response"]);
43
+ const rawStatus = (_b = (_a = record["status"]) != null ? _a : record["code"]) != null ? _b : response == null ? void 0 : response["status"];
44
+ const status = typeof rawStatus === "number" && rawStatus >= MIN_HTTP_STATUS && rawStatus <= MAX_HTTP_STATUS ? rawStatus : void 0;
45
+ const statusText = firstString(
46
+ record["statusText"],
47
+ response == null ? void 0 : response["statusText"]
48
+ );
49
+ const body = firstString(
50
+ response == null ? void 0 : response["data"],
51
+ response == null ? void 0 : response["body"],
52
+ response == null ? void 0 : response["text"]
53
+ );
54
+ if (status === void 0 && body === void 0) {
55
+ return void 0;
56
+ }
57
+ const head = status === void 0 ? "HTTP error" : `HTTP ${status}${statusText === void 0 ? "" : ` ${statusText}`}`;
58
+ return body === void 0 ? head : `${head}: ${truncateBody(body)}`;
59
+ }
60
+ function formatErrorRecursive(err, seen) {
61
+ var _a;
62
+ if (err === null || err === void 0) {
63
+ return UNKNOWN_ERROR;
64
+ }
65
+ if (typeof err === "object") {
66
+ if (seen.has(err)) {
67
+ return baseMessage(err);
68
+ }
69
+ seen.add(err);
70
+ }
71
+ if (err instanceof AggregateError && err.errors.length > 0) {
72
+ return err.errors.map((sub) => formatErrorRecursive(sub, seen)).join(" | ");
73
+ }
74
+ const http = extractHttpDetails(err);
75
+ const base = baseMessage(err);
76
+ const cause = (_a = asRecord(err)) == null ? void 0 : _a["cause"];
77
+ const causeMessage = cause !== void 0 ? formatErrorRecursive(cause, seen) : void 0;
78
+ let message = base.length > 0 ? base : UNKNOWN_ERROR;
79
+ if (http !== void 0) {
80
+ message = `${message} (${http})`;
81
+ }
82
+ if (causeMessage !== void 0 && http === void 0 && !message.includes(causeMessage)) {
83
+ message = `${message}: ${causeMessage}`;
84
+ }
85
+ return message;
86
+ }
87
+ function formatError(err) {
88
+ return formatErrorRecursive(err, /* @__PURE__ */ new Set());
89
+ }
90
+ export {
91
+ formatError
92
+ };
@@ -7,12 +7,15 @@ const require = topLevelCreateRequire(import.meta.url);
7
7
  */
8
8
  import * as fs from "node:fs/promises";
9
9
  import * as path from "node:path";
10
+ function isInsideDir(resolvedPath, resolvedBaseDir) {
11
+ return resolvedPath === resolvedBaseDir || resolvedPath.startsWith(resolvedBaseDir + path.sep);
12
+ }
10
13
  async function materializeFiles(files, dir = process.cwd()) {
11
14
  const resolvedBaseDir = path.resolve(dir);
12
15
  const createdFiles = [];
13
16
  for (const file of files) {
14
17
  const fullPath = path.resolve(dir, file.name);
15
- if (!fullPath.startsWith(resolvedBaseDir)) {
18
+ if (!isInsideDir(fullPath, resolvedBaseDir)) {
16
19
  throw new Error(
17
20
  `Path traversal detected: ${file.name} resolves outside of ${dir}`
18
21
  );
@@ -34,7 +37,7 @@ async function materializeFiles(files, dir = process.cwd()) {
34
37
  break;
35
38
  }
36
39
  }
37
- if (!finalPath.startsWith(resolvedBaseDir)) {
40
+ if (!isInsideDir(finalPath, resolvedBaseDir)) {
38
41
  throw new Error(
39
42
  `Path traversal detected: ${file.name} resolves outside of ${dir}`
40
43
  );
@@ -0,0 +1,15 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ import { isGemini2OrAbove } from "./model_name.js";
9
+ import { getGoogleLlmVariant, GoogleLLMVariant } from "./variant_utils.js";
10
+ function canUseOutputSchemaWithTools(modelString) {
11
+ return getGoogleLlmVariant() === GoogleLLMVariant.VERTEX_AI && isGemini2OrAbove(modelString);
12
+ }
13
+ export {
14
+ canUseOutputSchemaWithTools
15
+ };
@@ -9,7 +9,7 @@ import {
9
9
  FinishReason
10
10
  } from "@google/genai";
11
11
  import { JSONPath } from "jsonpath-plus";
12
- import { generateClientFunctionCallId } from "../agents/functions.js";
12
+ import { generateClientFunctionCallId } from "../events/event.js";
13
13
  import { FeatureName, isFeatureEnabled } from "../features/feature_registry.js";
14
14
  import { createLlmResponse } from "../models/llm_response.js";
15
15
  const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
@@ -6,6 +6,7 @@ const require = topLevelCreateRequire(import.meta.url);
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
8
  import { getBooleanEnvVar } from "./env_aware_utils.js";
9
+ const EXPRESS_MODE_UNSUPPORTED_MESSAGE = "Vertex AI Express Mode (expressModeApiKey / GOOGLE_API_KEY) is not supported: the @google-cloud/vertexai Agent Engine client cannot send an API key. Provide projectId and location (with Application Default Credentials), or inject a preconfigured client.";
9
10
  function getExpressModeApiKey(project, location, expressModeApiKey) {
10
11
  if ((project || location) && expressModeApiKey) {
11
12
  throw new Error(
@@ -18,5 +19,6 @@ function getExpressModeApiKey(project, location, expressModeApiKey) {
18
19
  return void 0;
19
20
  }
20
21
  export {
22
+ EXPRESS_MODE_UNSUPPORTED_MESSAGE,
21
23
  getExpressModeApiKey
22
24
  };
@@ -5,7 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2025 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
- const version = "1.4.0";
8
+ const version = "1.6.0";
9
9
  export {
10
10
  version
11
11
  };