@softactivate/adk 1.1.0 → 1.2.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 (141) hide show
  1. package/dist/cjs/agents/functions.js +4 -0
  2. package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
  3. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
  4. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  5. package/dist/cjs/common.js +3 -0
  6. package/dist/cjs/events/event.js +2 -0
  7. package/dist/cjs/index.js +14 -0
  8. package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
  9. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
  10. package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
  11. package/dist/cjs/integrations/agent_registry/types.js +50 -0
  12. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
  13. package/dist/cjs/runner/in_memory_runner.js +10 -5
  14. package/dist/cjs/runner/runner.js +32 -2
  15. package/dist/cjs/sessions/database_session_service.js +49 -3
  16. package/dist/cjs/sessions/in_memory_session_service.js +70 -14
  17. package/dist/cjs/sessions/registry.js +4 -0
  18. package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
  19. package/dist/cjs/tools/agent_tool.js +17 -8
  20. package/dist/cjs/tools/exit_loop_tool.js +9 -0
  21. package/dist/cjs/tools/function_tool.js +7 -2
  22. package/dist/cjs/tools/long_running_tool.js +2 -1
  23. package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
  24. package/dist/cjs/tools/mcp/mcp_tool.js +10 -7
  25. package/dist/cjs/tools/mcp/mcp_toolset.js +10 -2
  26. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
  27. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
  28. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
  29. package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
  30. package/dist/cjs/utils/file_utils.js +28 -0
  31. package/dist/cjs/utils/gemini_schema_util.js +18 -0
  32. package/dist/cjs/utils/partial_copy.js +51 -0
  33. package/dist/cjs/utils/streaming_utils.js +167 -118
  34. package/dist/cjs/utils/vertex_ai_utils.js +50 -0
  35. package/dist/cjs/version.js +1 -1
  36. package/dist/esm/agents/functions.js +4 -0
  37. package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
  38. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  39. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  40. package/dist/esm/common.js +2 -0
  41. package/dist/esm/events/event.js +2 -0
  42. package/dist/esm/index.js +11 -0
  43. package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
  44. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
  45. package/dist/esm/integrations/agent_registry/helpers.js +28 -0
  46. package/dist/esm/integrations/agent_registry/types.js +20 -0
  47. package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
  48. package/dist/esm/runner/in_memory_runner.js +10 -5
  49. package/dist/esm/runner/runner.js +32 -2
  50. package/dist/esm/sessions/database_session_service.js +49 -3
  51. package/dist/esm/sessions/in_memory_session_service.js +70 -14
  52. package/dist/esm/sessions/registry.js +7 -0
  53. package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
  54. package/dist/esm/tools/agent_tool.js +17 -8
  55. package/dist/esm/tools/exit_loop_tool.js +9 -0
  56. package/dist/esm/tools/function_tool.js +7 -2
  57. package/dist/esm/tools/long_running_tool.js +2 -1
  58. package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
  59. package/dist/esm/tools/mcp/mcp_tool.js +10 -7
  60. package/dist/esm/tools/mcp/mcp_toolset.js +10 -2
  61. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
  62. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  63. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  64. package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
  65. package/dist/esm/utils/file_utils.js +26 -0
  66. package/dist/esm/utils/gemini_schema_util.js +18 -0
  67. package/dist/esm/utils/partial_copy.js +23 -0
  68. package/dist/esm/utils/streaming_utils.js +165 -117
  69. package/dist/esm/utils/vertex_ai_utils.js +22 -0
  70. package/dist/esm/version.js +1 -1
  71. package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
  72. package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
  73. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
  74. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
  75. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
  76. package/dist/types/agents/run_config.d.ts +15 -0
  77. package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
  78. package/dist/types/common.d.ts +2 -0
  79. package/dist/types/events/event_actions.d.ts +24 -6
  80. package/dist/types/events/structured_events.d.ts +13 -0
  81. package/dist/types/examples/example_util.d.ts +25 -0
  82. package/dist/types/index.d.ts +6 -0
  83. package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
  84. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
  85. package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
  86. package/dist/types/integrations/agent_registry/types.d.ts +101 -0
  87. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
  88. package/dist/types/runner/in_memory_runner.d.ts +28 -1
  89. package/dist/types/runner/runner.d.ts +47 -0
  90. package/dist/types/sessions/base_session_service.d.ts +18 -0
  91. package/dist/types/sessions/database_session_service.d.ts +1 -1
  92. package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
  93. package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
  94. package/dist/types/tools/exit_loop_tool.d.ts +9 -0
  95. package/dist/types/tools/function_tool.d.ts +22 -2
  96. package/dist/types/tools/long_running_tool.d.ts +11 -1
  97. package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
  98. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
  99. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
  100. package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
  101. package/dist/types/utils/file_utils.d.ts +2 -0
  102. package/dist/types/utils/partial_copy.d.ts +13 -0
  103. package/dist/types/utils/streaming_utils.d.ts +8 -17
  104. package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
  105. package/dist/types/version.d.ts +1 -1
  106. package/dist/web/agents/functions.js +4 -0
  107. package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
  108. package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  109. package/dist/web/code_executors/code_execution_utils.js +1 -1
  110. package/dist/web/common.js +2 -0
  111. package/dist/web/events/event.js +2 -0
  112. package/dist/web/index.js +11 -0
  113. package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
  114. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
  115. package/dist/web/integrations/agent_registry/helpers.js +28 -0
  116. package/dist/web/integrations/agent_registry/types.js +20 -0
  117. package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
  118. package/dist/web/runner/in_memory_runner.js +10 -5
  119. package/dist/web/runner/runner.js +32 -2
  120. package/dist/web/sessions/database_session_service.js +49 -3
  121. package/dist/web/sessions/in_memory_session_service.js +70 -14
  122. package/dist/web/sessions/registry.js +7 -0
  123. package/dist/web/sessions/vertex_ai_session_service.js +414 -0
  124. package/dist/web/tools/agent_tool.js +17 -8
  125. package/dist/web/tools/exit_loop_tool.js +9 -0
  126. package/dist/web/tools/function_tool.js +7 -2
  127. package/dist/web/tools/long_running_tool.js +2 -1
  128. package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
  129. package/dist/web/tools/mcp/mcp_tool.js +10 -7
  130. package/dist/web/tools/mcp/mcp_toolset.js +10 -2
  131. package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
  132. package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  133. package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  134. package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
  135. package/dist/web/utils/file_utils.js +26 -0
  136. package/dist/web/utils/gemini_schema_util.js +18 -0
  137. package/dist/web/utils/partial_copy.js +23 -0
  138. package/dist/web/utils/streaming_utils.js +218 -117
  139. package/dist/web/utils/vertex_ai_utils.js +22 -0
  140. package/dist/web/version.js +1 -1
  141. package/package.json +2 -1
@@ -0,0 +1,281 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __decorateClass = (decorators, target, key, kind) => {
6
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
7
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
8
+ if (decorator = decorators[i])
9
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10
+ if (kind && result) __defProp(target, key, result);
11
+ return result;
12
+ };
13
+ /**
14
+ * @license
15
+ * Copyright 2026 Google LLC
16
+ * SPDX-License-Identifier: Apache-2.0
17
+ */
18
+ import { Client } from "@google-cloud/vertexai";
19
+ import { Language } from "@google-cloud/vertexai/build/src/genai/types.js";
20
+ import { experimental } from "../utils/experimental.js";
21
+ import { guessMimeType } from "../utils/file_utils.js";
22
+ const SANDBOX_PATTERN = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)\/sandboxEnvironments\/(\d+)$/;
23
+ const ENGINE_PATTERN = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)$/;
24
+ import { logger } from "../utils/logger.js";
25
+ import { BaseCodeExecutor } from "./base_code_executor.js";
26
+ import {
27
+ CodeExecutionLanguage
28
+ } from "./code_execution_utils.js";
29
+ const DEFAULT_MAX_ATTEMPTS = 180;
30
+ const DEFAULT_SANDBOX_TTL = "31536000s";
31
+ const DEFAULT_SANDBOX_DISPLAY_NAME = "default_sandbox";
32
+ const DEFAULT_ENGINE_DISPLAY_NAME = "default_engine";
33
+ function mapLanguage(lang) {
34
+ switch (lang) {
35
+ case CodeExecutionLanguage.PYTHON:
36
+ return Language.LANGUAGE_PYTHON;
37
+ case CodeExecutionLanguage.JAVASCRIPT:
38
+ return Language.LANGUAGE_JAVASCRIPT;
39
+ default:
40
+ throw new Error(`Unsupported language for Agent Engine Sandbox: ${lang}`);
41
+ }
42
+ }
43
+ let AgentEngineSandboxCodeExecutor = class extends BaseCodeExecutor {
44
+ constructor(options = {}) {
45
+ super();
46
+ this.sandboxResourceName = options.sandboxResourceName;
47
+ this.agentEngineResourceName = options.agentEngineResourceName;
48
+ this.projectId = options.projectId || process.env.GOOGLE_CLOUD_PROJECT;
49
+ this.location = options.location || process.env.GOOGLE_CLOUD_LOCATION || "us-central1";
50
+ if (this.sandboxResourceName) {
51
+ const match = this.sandboxResourceName.match(SANDBOX_PATTERN);
52
+ if (match) {
53
+ this.projectId = match[1];
54
+ this.location = match[2];
55
+ } else {
56
+ throw new Error(
57
+ `Invalid sandbox resource name: ${this.sandboxResourceName}`
58
+ );
59
+ }
60
+ } else if (this.agentEngineResourceName) {
61
+ const match = this.agentEngineResourceName.match(ENGINE_PATTERN);
62
+ if (match) {
63
+ this.projectId = match[1];
64
+ this.location = match[2];
65
+ } else {
66
+ throw new Error(
67
+ `Invalid agent engine resource name: ${this.agentEngineResourceName}`
68
+ );
69
+ }
70
+ }
71
+ if (options.client) {
72
+ this.client = options.client;
73
+ } else {
74
+ if (!this.projectId) {
75
+ throw new Error("Project ID is required.");
76
+ }
77
+ this.client = new Client({
78
+ project: this.projectId,
79
+ location: this.location
80
+ });
81
+ }
82
+ }
83
+ async executeCode(params) {
84
+ var _a;
85
+ const { invocationContext, codeExecutionInput } = params;
86
+ const language = mapLanguage(codeExecutionInput.language);
87
+ const agentEngineName = await this.getOrCreateAgentEngine();
88
+ const sandboxName = await this.getOrCreateSandbox(
89
+ invocationContext,
90
+ agentEngineName,
91
+ language
92
+ );
93
+ const inputs = [
94
+ {
95
+ mimeType: "application/json",
96
+ data: Buffer.from(
97
+ JSON.stringify({ code: codeExecutionInput.code })
98
+ ).toString("base64")
99
+ }
100
+ ];
101
+ if (codeExecutionInput.inputFiles) {
102
+ for (const file of codeExecutionInput.inputFiles) {
103
+ inputs.push({
104
+ mimeType: file.mimeType,
105
+ data: file.content,
106
+ // Assumed to be already base64 encoded based on CodeExecutionInput definition
107
+ metadata: {
108
+ attributes: {
109
+ file_name: Buffer.from(file.name).toString("base64")
110
+ }
111
+ }
112
+ });
113
+ }
114
+ }
115
+ logger.debug(`Executing code in sandbox ${sandboxName}...`);
116
+ const response = await this.client.agentEnginesInternal.sandboxes.executeCodeInternal({
117
+ name: sandboxName,
118
+ inputs
119
+ });
120
+ let stdout = "";
121
+ let stderr = "";
122
+ const outputFiles = [];
123
+ if (response.outputs) {
124
+ for (const output of response.outputs) {
125
+ const attributes = ((_a = output.metadata) == null ? void 0 : _a.attributes) || {};
126
+ const encodedFileName = attributes["file_name"];
127
+ const fileName = encodedFileName ? Buffer.from(encodedFileName, "base64").toString("utf-8") : void 0;
128
+ if (output.mimeType === "application/json" && !fileName) {
129
+ if (output.data) {
130
+ const jsonStr = Buffer.from(output.data, "base64").toString(
131
+ "utf-8"
132
+ );
133
+ try {
134
+ const jsonData = JSON.parse(jsonStr);
135
+ if (jsonData.msg_out !== void 0) {
136
+ stdout = jsonData.msg_out;
137
+ } else {
138
+ stdout = "";
139
+ }
140
+ if (jsonData.msg_err !== void 0) {
141
+ stderr = jsonData.msg_err;
142
+ } else {
143
+ stderr = "";
144
+ }
145
+ } catch (e) {
146
+ logger.warn("Failed to parse JSON output from sandbox", e);
147
+ stdout = jsonStr;
148
+ }
149
+ }
150
+ } else {
151
+ let mimeType = output.mimeType;
152
+ const name = fileName || "output_file";
153
+ if (!mimeType) {
154
+ mimeType = guessMimeType(name);
155
+ }
156
+ outputFiles.push({
157
+ name,
158
+ content: output.data || "",
159
+ mimeType
160
+ });
161
+ }
162
+ }
163
+ }
164
+ return {
165
+ stdout,
166
+ stderr,
167
+ outputFiles
168
+ };
169
+ }
170
+ async getOrCreateAgentEngine() {
171
+ if (this.agentEngineResourceName) {
172
+ return this.agentEngineResourceName;
173
+ }
174
+ if (!this.agentEngineCreationPromise) {
175
+ this.agentEngineCreationPromise = (async () => {
176
+ logger.debug(
177
+ "No Agent Engine resource name provided. Creating a new one..."
178
+ );
179
+ const operation = await this.client.agentEnginesInternal.createInternal(
180
+ {
181
+ config: {
182
+ displayName: DEFAULT_ENGINE_DISPLAY_NAME
183
+ }
184
+ }
185
+ );
186
+ let apiResponse = operation;
187
+ let attempts = 0;
188
+ while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
189
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
190
+ apiResponse = await this.client.agentEnginesInternal.getAgentOperationInternal({
191
+ operationName: operation.name
192
+ });
193
+ attempts++;
194
+ }
195
+ if (!apiResponse.done) {
196
+ throw new Error(
197
+ `Agent Engine creation operation ${operation.name} did not complete in time.`
198
+ );
199
+ }
200
+ const response = apiResponse.response;
201
+ this.agentEngineResourceName = response.name;
202
+ logger.debug(`Created Agent Engine: ${this.agentEngineResourceName}`);
203
+ return this.agentEngineResourceName;
204
+ })();
205
+ }
206
+ return this.agentEngineCreationPromise;
207
+ }
208
+ async getOrCreateSandbox(invocationContext, agentEngineName, language) {
209
+ var _a, _b;
210
+ if (this.sandboxResourceName) {
211
+ return this.sandboxResourceName;
212
+ }
213
+ const stateKey = `sandbox_name_${language.toLowerCase()}`;
214
+ let sandboxName = (_b = (_a = invocationContext.session) == null ? void 0 : _a.state) == null ? void 0 : _b[stateKey];
215
+ let createNewSandbox = false;
216
+ if (!sandboxName) {
217
+ createNewSandbox = true;
218
+ } else {
219
+ try {
220
+ const sandbox = await this.client.agentEnginesInternal.sandboxes.getInternal({
221
+ name: sandboxName
222
+ });
223
+ if (!sandbox || sandbox.state !== "STATE_RUNNING") {
224
+ createNewSandbox = true;
225
+ }
226
+ } catch (error) {
227
+ logger.debug(
228
+ `Failed to get sandbox ${sandboxName}, will create a new one`,
229
+ error
230
+ );
231
+ createNewSandbox = true;
232
+ }
233
+ }
234
+ if (createNewSandbox) {
235
+ logger.debug(`Creating a new ${language} code execution sandbox...`);
236
+ const operation = await this.client.agentEnginesInternal.sandboxes.createInternal({
237
+ name: agentEngineName,
238
+ spec: {
239
+ codeExecutionEnvironment: {
240
+ codeLanguage: language
241
+ }
242
+ },
243
+ config: {
244
+ displayName: DEFAULT_SANDBOX_DISPLAY_NAME,
245
+ ttl: DEFAULT_SANDBOX_TTL
246
+ }
247
+ });
248
+ let apiResponse = operation;
249
+ let attempts = 0;
250
+ while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
251
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
252
+ apiResponse = await this.client.agentEnginesInternal.sandboxes.getSandboxOperationInternal(
253
+ {
254
+ operationName: operation.name
255
+ }
256
+ );
257
+ attempts++;
258
+ }
259
+ if (!apiResponse.done) {
260
+ throw new Error(
261
+ `Sandbox creation operation ${operation.name} did not complete in time.`
262
+ );
263
+ }
264
+ const response = apiResponse.response;
265
+ sandboxName = response.name;
266
+ if (invocationContext.session) {
267
+ if (!invocationContext.session.state) {
268
+ invocationContext.session.state = {};
269
+ }
270
+ invocationContext.session.state[stateKey] = sandboxName;
271
+ }
272
+ }
273
+ return sandboxName;
274
+ }
275
+ };
276
+ AgentEngineSandboxCodeExecutor = __decorateClass([
277
+ experimental
278
+ ], AgentEngineSandboxCodeExecutor);
279
+ export {
280
+ AgentEngineSandboxCodeExecutor
281
+ };
@@ -47,7 +47,7 @@ function extractCodeAndTruncateContent(content, codeBlockDelimiters) {
47
47
  const leadingDelimiterPattern = codeBlockDelimiters.map((d) => d[0]).join("|");
48
48
  const trailingDelimiterPattern = codeBlockDelimiters.map((d) => d[1]).join("|");
49
49
  const match = new RegExp(
50
- `?<prefix>.*?)(${leadingDelimiterPattern})(?<codeStr>.*?)(${trailingDelimiterPattern})(?<suffix>.*?)$`,
50
+ `(?<prefix>.*?)(${leadingDelimiterPattern})(?<codeStr>.*?)(${trailingDelimiterPattern})(?<suffix>.*?)$`,
51
51
  "s"
52
52
  ).exec(responseText);
53
53
  const { prefix, codeStr } = (match == null ? void 0 : match.groups) || {};
@@ -64,6 +64,7 @@ import {
64
64
  isBaseExampleProvider
65
65
  } from "./examples/base_example_provider.js";
66
66
  import { InMemoryMemoryService } from "./memory/in_memory_memory_service.js";
67
+ import { VertexAiMemoryBankService } from "./memory/vertex_ai_memory_bank_service.js";
67
68
  import { ApigeeLlm } from "./models/apigee_llm.js";
68
69
  import { BaseLlm, isBaseLlm } from "./models/base_llm.js";
69
70
  import { Gemini, geminiInitParams } from "./models/google_llm.js";
@@ -208,6 +209,7 @@ export {
208
209
  TruncatingContextCompactor,
209
210
  URL_CONTEXT,
210
211
  UrlContextTool,
212
+ VertexAiMemoryBankService,
211
213
  VertexAiSearchTool,
212
214
  VertexRagRetrievalTool,
213
215
  createEvent,
@@ -79,6 +79,7 @@ const PRESERVE_KEYS_CAMEL_CASE = [
79
79
  "actions.requestedAuthConfigs",
80
80
  "actions.requestedToolConfirmations",
81
81
  "actions.customMetadata",
82
+ "customMetadata",
82
83
  "content.parts.functionCall.args",
83
84
  "content.parts.functionResponse.response"
84
85
  ];
@@ -88,6 +89,7 @@ const PRESERVE_KEYS_SNAKE_CASE = [
88
89
  "actions.requested_auth_configs",
89
90
  "actions.requested_tool_confirmations",
90
91
  "actions.custom_metadata",
92
+ "custom_metadata",
91
93
  "content.parts.function_call.args",
92
94
  "content.parts.function_response.response"
93
95
  ];
package/dist/esm/index.js CHANGED
@@ -9,15 +9,21 @@ import { AGENT_CARD_PATH, RemoteA2AAgent } from "./a2a/a2a_remote_agent.js";
9
9
  import { getA2AAgentCard } from "./a2a/agent_card.js";
10
10
  import { A2AAgentExecutor } from "./a2a/agent_executor.js";
11
11
  import { toA2a } from "./a2a/agent_to_a2a.js";
12
+ import { InvocationContext } from "./agents/invocation_context.js";
12
13
  import { FileArtifactService } from "./artifacts/file_artifact_service.js";
13
14
  import { GcsArtifactService } from "./artifacts/gcs_artifact_service.js";
14
15
  import { getArtifactServiceFromUri } from "./artifacts/registry.js";
16
+ import {
17
+ AgentEngineSandboxCodeExecutor
18
+ } from "./code_executors/agent_engine_sandbox_code_executor.js";
19
+ import { CodeExecutionLanguage } from "./code_executors/code_execution_utils.js";
15
20
  import {
16
21
  UnsafeLocalCodeExecutor
17
22
  } from "./code_executors/unsafe_local_code_executor.js";
18
23
  export * from "./common.js";
19
24
  import { DatabaseSessionService } from "./sessions/database_session_service.js";
20
25
  import { getSessionServiceFromUri } from "./sessions/registry.js";
26
+ import { VertexAiSessionService } from "./sessions/vertex_ai_session_service.js";
21
27
  import {
22
28
  loadAllSkillsInDir,
23
29
  loadSkillFromDir,
@@ -25,6 +31,7 @@ import {
25
31
  } from "./skills/loader.js";
26
32
  import { RunSkillInlineScriptTool } from "./tools/skill/run_skill_inline_script_tool.js";
27
33
  import { RunSkillScriptTool } from "./tools/skill/run_skill_script_tool.js";
34
+ export * from "./integrations/agent_registry/agent_registry.js";
28
35
  export * from "./telemetry/google_cloud.js";
29
36
  export * from "./telemetry/setup.js";
30
37
  export * from "./tools/mcp/mcp_session_manager.js";
@@ -33,13 +40,17 @@ export * from "./tools/mcp/mcp_toolset.js";
33
40
  export {
34
41
  A2AAgentExecutor,
35
42
  AGENT_CARD_PATH,
43
+ AgentEngineSandboxCodeExecutor,
44
+ CodeExecutionLanguage,
36
45
  DatabaseSessionService,
37
46
  FileArtifactService,
38
47
  GcsArtifactService,
48
+ InvocationContext,
39
49
  RemoteA2AAgent,
40
50
  RunSkillInlineScriptTool,
41
51
  RunSkillScriptTool,
42
52
  UnsafeLocalCodeExecutor,
53
+ VertexAiSessionService,
43
54
  getA2AAgentCard,
44
55
  getArtifactServiceFromUri,
45
56
  getSessionServiceFromUri,
@@ -0,0 +1,333 @@
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 { GoogleAuth } from "google-auth-library";
9
+ import { RemoteA2AAgent } from "../../a2a/a2a_remote_agent.js";
10
+ import { logger } from "../../utils/logger.js";
11
+ import { AgentRegistrySingleMCPToolset } from "./agent_registry_mcp_toolset.js";
12
+ import { cleanName, isGoogleApi } from "./helpers.js";
13
+ import {
14
+ AGENT_REGISTRY_BASE_URL,
15
+ ProtocolType
16
+ } from "./types.js";
17
+ export * from "./agent_registry_mcp_toolset.js";
18
+ export * from "./helpers.js";
19
+ export * from "./types.js";
20
+ const TRANSPORT_MAPPING = {
21
+ "HTTP_JSON": "HTTP+JSON",
22
+ "JSONRPC": "JSONRPC",
23
+ "GRPC": "GRPC"
24
+ };
25
+ class AgentRegistry {
26
+ constructor(options) {
27
+ if (!options.projectId || !options.location) {
28
+ throw new Error("project_id and location must be provided");
29
+ }
30
+ this.projectId = options.projectId;
31
+ this.location = options.location;
32
+ this.basePath = `projects/${this.projectId}/locations/${this.location}`;
33
+ this.headerProvider = options.headerProvider;
34
+ this.auth = new GoogleAuth({
35
+ scopes: ["https://www.googleapis.com/auth/cloud-platform"]
36
+ });
37
+ }
38
+ /**
39
+ * Resolves default Google Cloud credentials and returns standard headers.
40
+ * Automatically caches, fetches, and handles refreshing expired OAuth tokens.
41
+ * Injects the billing/quota project identifier `x-goog-user-project` if present.
42
+ */
43
+ async getAuthHeaders() {
44
+ try {
45
+ const client = await this.auth.getClient();
46
+ const headers = await client.getRequestHeaders(
47
+ "https://agentregistry.googleapis.com"
48
+ );
49
+ const authHeaders = {};
50
+ const rawHeaders = headers;
51
+ const authKey = Object.keys(rawHeaders).find(
52
+ (k) => k.toLowerCase() === "authorization"
53
+ );
54
+ let token = authKey ? rawHeaders[authKey] : void 0;
55
+ if (!token && client.credentials && client.credentials.access_token) {
56
+ token = `Bearer ${client.credentials.access_token}`;
57
+ }
58
+ if (token) {
59
+ authHeaders["Authorization"] = token;
60
+ }
61
+ authHeaders["Content-Type"] = "application/json";
62
+ const quotaProjectId = client.quotaProjectId || this.auth.quotaProjectId;
63
+ if (quotaProjectId) {
64
+ authHeaders["x-goog-user-project"] = quotaProjectId;
65
+ }
66
+ return authHeaders;
67
+ } catch (err) {
68
+ const msg = err instanceof Error ? err.message : String(err);
69
+ throw new Error(`Failed to refresh Google Cloud credentials: ${msg}`);
70
+ }
71
+ }
72
+ /**
73
+ * Helper function to execute HTTP GET requests against the Agent Registry API.
74
+ * Handles path resolution, search query params compilation, and auth headers fetching.
75
+ */
76
+ async makeRequest(path, params) {
77
+ let url;
78
+ if (path.startsWith("projects/")) {
79
+ url = `${AGENT_REGISTRY_BASE_URL}/${path}`;
80
+ } else {
81
+ url = `${AGENT_REGISTRY_BASE_URL}/${this.basePath}/${path}`;
82
+ }
83
+ if (params && Object.keys(params).length > 0) {
84
+ const searchParams = new URLSearchParams(params);
85
+ url += `?${searchParams.toString()}`;
86
+ }
87
+ try {
88
+ const headers = await this.getAuthHeaders();
89
+ const res = await fetch(url, {
90
+ method: "GET",
91
+ headers
92
+ });
93
+ if (!res.ok) {
94
+ const text = await res.text();
95
+ throw new Error(
96
+ `API request failed with status ${res.status}: ${text}`
97
+ );
98
+ }
99
+ return await res.json();
100
+ } catch (err) {
101
+ const msg = err instanceof Error ? err.message : String(err);
102
+ if (msg.includes("API request failed")) {
103
+ throw err;
104
+ }
105
+ throw new Error(`API request failed: ${msg}`);
106
+ }
107
+ }
108
+ /**
109
+ * Parses connection interfaces list from registry metadata and returns the first match
110
+ * corresponding to requested protocol types and binding options.
111
+ */
112
+ getConnectionUri(resourceDetails, filters) {
113
+ const protocols = [];
114
+ if (resourceDetails.protocols) {
115
+ protocols.push(...resourceDetails.protocols);
116
+ }
117
+ if (resourceDetails.interfaces) {
118
+ protocols.push({ interfaces: resourceDetails.interfaces });
119
+ }
120
+ for (const p of protocols) {
121
+ if ((filters == null ? void 0 : filters.protocolType) && p.type !== filters.protocolType) {
122
+ continue;
123
+ }
124
+ const protocolVersion = p.protocolVersion;
125
+ const interfaces = p.interfaces || [];
126
+ for (const i of interfaces) {
127
+ const mappedBinding = i.protocolBinding ? TRANSPORT_MAPPING[i.protocolBinding] : void 0;
128
+ if ((filters == null ? void 0 : filters.protocolBinding) && mappedBinding !== filters.protocolBinding) {
129
+ continue;
130
+ }
131
+ if (i.url) {
132
+ return { url: i.url, protocolVersion, protocolBinding: mappedBinding };
133
+ }
134
+ }
135
+ }
136
+ return {};
137
+ }
138
+ // --- MCP Server Methods ---
139
+ async listMcpServers(options) {
140
+ const params = {};
141
+ if (options == null ? void 0 : options.filterStr) {
142
+ params["filter"] = options.filterStr;
143
+ }
144
+ if (options == null ? void 0 : options.pageSize) {
145
+ params["pageSize"] = String(options.pageSize);
146
+ }
147
+ if (options == null ? void 0 : options.pageToken) {
148
+ params["pageToken"] = options.pageToken;
149
+ }
150
+ return this.makeRequest("mcpServers", params);
151
+ }
152
+ async getMcpServer(name) {
153
+ return this.makeRequest(name);
154
+ }
155
+ async getMcpToolset(mcpServerName, options) {
156
+ var _a, _b;
157
+ const serverDetails = await this.getMcpServer(mcpServerName);
158
+ const name = cleanName(serverDetails.displayName || mcpServerName);
159
+ const mcpServerId = serverDetails.mcpServerId;
160
+ let endpointUri = this.getConnectionUri(serverDetails, {
161
+ protocolBinding: "JSONRPC"
162
+ }).url;
163
+ if (!endpointUri) {
164
+ endpointUri = this.getConnectionUri(serverDetails, {
165
+ protocolBinding: "HTTP+JSON"
166
+ }).url;
167
+ }
168
+ if (!endpointUri) {
169
+ throw new Error(
170
+ `MCP Server endpoint URI not found for: ${mcpServerName}`
171
+ );
172
+ }
173
+ let authScheme = options == null ? void 0 : options.authScheme;
174
+ if (mcpServerId && !authScheme) {
175
+ try {
176
+ const bindingsData = await this.makeRequest("bindings");
177
+ const bindings = bindingsData.bindings || [];
178
+ for (const b of bindings) {
179
+ const targetId = ((_a = b.target) == null ? void 0 : _a.identifier) || "";
180
+ if (targetId.endsWith(mcpServerId)) {
181
+ const authProvider = (_b = b.authProviderBinding) == null ? void 0 : _b.authProvider;
182
+ if (authProvider) {
183
+ authScheme = {
184
+ type: "gcpAuthProviderScheme",
185
+ name: authProvider,
186
+ continueUri: options == null ? void 0 : options.continueUri
187
+ };
188
+ break;
189
+ }
190
+ }
191
+ }
192
+ } catch (err) {
193
+ const msg = err instanceof Error ? err.message : String(err);
194
+ logger.warn(
195
+ `Failed to fetch bindings for MCP Server ${mcpServerName}: ${msg}`
196
+ );
197
+ }
198
+ }
199
+ const connectionParams = {
200
+ type: "StreamableHTTPConnectionParams",
201
+ url: endpointUri
202
+ };
203
+ const combinedHeaderProvider = async (context) => {
204
+ const headers = {};
205
+ if (!authScheme && !(options == null ? void 0 : options.authCredential) && isGoogleApi(endpointUri)) {
206
+ Object.assign(headers, await this.getAuthHeaders());
207
+ }
208
+ if (this.headerProvider && context) {
209
+ Object.assign(headers, this.headerProvider(context));
210
+ }
211
+ return headers;
212
+ };
213
+ return new AgentRegistrySingleMCPToolset({
214
+ destinationResourceId: mcpServerId,
215
+ connectionParams,
216
+ prefix: name,
217
+ headerProvider: combinedHeaderProvider,
218
+ authScheme,
219
+ authCredential: options == null ? void 0 : options.authCredential
220
+ });
221
+ }
222
+ // --- Endpoint Methods ---
223
+ async listEndpoints(options) {
224
+ const params = {};
225
+ if (options == null ? void 0 : options.filterStr) {
226
+ params["filter"] = options.filterStr;
227
+ }
228
+ if (options == null ? void 0 : options.pageSize) {
229
+ params["pageSize"] = String(options.pageSize);
230
+ }
231
+ if (options == null ? void 0 : options.pageToken) {
232
+ params["pageToken"] = options.pageToken;
233
+ }
234
+ return this.makeRequest("endpoints", params);
235
+ }
236
+ async getEndpoint(name) {
237
+ return this.makeRequest(name);
238
+ }
239
+ async getModelName(endpointName) {
240
+ const endpointDetails = await this.getEndpoint(endpointName);
241
+ const { url } = this.getConnectionUri(endpointDetails);
242
+ if (!url) {
243
+ throw new Error(`Connection URI not found for endpoint: ${endpointName}`);
244
+ }
245
+ const uri = url.replace(/:\w+$/, "");
246
+ if (uri.startsWith("projects/")) {
247
+ return uri;
248
+ }
249
+ const match = uri.match(/(projects\/.+)/);
250
+ if (match) {
251
+ return match[1];
252
+ }
253
+ return uri;
254
+ }
255
+ // --- Agent Methods ---
256
+ async listAgents(options) {
257
+ const params = {};
258
+ if (options == null ? void 0 : options.filterStr) {
259
+ params["filter"] = options.filterStr;
260
+ }
261
+ if (options == null ? void 0 : options.pageSize) {
262
+ params["pageSize"] = String(options.pageSize);
263
+ }
264
+ if (options == null ? void 0 : options.pageToken) {
265
+ params["pageToken"] = options.pageToken;
266
+ }
267
+ return this.makeRequest("agents", params);
268
+ }
269
+ async getAgentInfo(name) {
270
+ return this.makeRequest(name);
271
+ }
272
+ async getRemoteA2AAgent(agentName, options) {
273
+ const agentInfo = await this.getAgentInfo(agentName);
274
+ const card = agentInfo.card || {};
275
+ const cardContent = card.content;
276
+ if (card.type === "A2A_AGENT_CARD" && cardContent) {
277
+ const agentCard2 = cardContent;
278
+ const name2 = cleanName(agentCard2.name);
279
+ return new RemoteA2AAgent({
280
+ name: name2,
281
+ agentCard: agentCard2,
282
+ description: agentCard2.description,
283
+ client: options == null ? void 0 : options.client,
284
+ clientFactory: options == null ? void 0 : options.clientFactory
285
+ });
286
+ }
287
+ const name = cleanName(agentInfo.displayName || agentName);
288
+ const description = agentInfo.description || "";
289
+ const version = agentInfo.version || "";
290
+ const { url, protocolVersion, protocolBinding } = this.getConnectionUri(
291
+ agentInfo,
292
+ {
293
+ protocolType: ProtocolType.A2A_AGENT
294
+ }
295
+ );
296
+ if (!url) {
297
+ throw new Error(`A2A connection URI not found for Agent: ${agentName}`);
298
+ }
299
+ const skills = (agentInfo.skills || []).map(
300
+ (s) => ({
301
+ id: s.id,
302
+ name: s.name,
303
+ description: s.description || "",
304
+ tags: s.tags || [],
305
+ examples: s.examples || []
306
+ })
307
+ );
308
+ const agentCard = {
309
+ name,
310
+ description,
311
+ version,
312
+ preferredTransport: protocolBinding || "HTTP+JSON",
313
+ protocolVersion: protocolVersion || "0.3.0",
314
+ url,
315
+ skills,
316
+ capabilities: {
317
+ streaming: false
318
+ },
319
+ defaultInputModes: ["text"],
320
+ defaultOutputModes: ["text"]
321
+ };
322
+ return new RemoteA2AAgent({
323
+ name,
324
+ agentCard,
325
+ description,
326
+ client: options == null ? void 0 : options.client,
327
+ clientFactory: options == null ? void 0 : options.clientFactory
328
+ });
329
+ }
330
+ }
331
+ export {
332
+ AgentRegistry
333
+ };