@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.
- package/dist/cjs/agents/functions.js +4 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/common.js +3 -0
- package/dist/cjs/events/event.js +2 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
- package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
- package/dist/cjs/integrations/agent_registry/types.js +50 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
- package/dist/cjs/runner/in_memory_runner.js +10 -5
- package/dist/cjs/runner/runner.js +32 -2
- package/dist/cjs/sessions/database_session_service.js +49 -3
- package/dist/cjs/sessions/in_memory_session_service.js +70 -14
- package/dist/cjs/sessions/registry.js +4 -0
- package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
- package/dist/cjs/tools/agent_tool.js +17 -8
- package/dist/cjs/tools/exit_loop_tool.js +9 -0
- package/dist/cjs/tools/function_tool.js +7 -2
- package/dist/cjs/tools/long_running_tool.js +2 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/cjs/tools/mcp/mcp_tool.js +10 -7
- package/dist/cjs/tools/mcp/mcp_toolset.js +10 -2
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
- package/dist/cjs/utils/file_utils.js +28 -0
- package/dist/cjs/utils/gemini_schema_util.js +18 -0
- package/dist/cjs/utils/partial_copy.js +51 -0
- package/dist/cjs/utils/streaming_utils.js +167 -118
- package/dist/cjs/utils/vertex_ai_utils.js +50 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/functions.js +4 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/esm/code_executors/code_execution_utils.js +1 -1
- package/dist/esm/common.js +2 -0
- package/dist/esm/events/event.js +2 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
- package/dist/esm/integrations/agent_registry/helpers.js +28 -0
- package/dist/esm/integrations/agent_registry/types.js +20 -0
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
- package/dist/esm/runner/in_memory_runner.js +10 -5
- package/dist/esm/runner/runner.js +32 -2
- package/dist/esm/sessions/database_session_service.js +49 -3
- package/dist/esm/sessions/in_memory_session_service.js +70 -14
- package/dist/esm/sessions/registry.js +7 -0
- package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
- package/dist/esm/tools/agent_tool.js +17 -8
- package/dist/esm/tools/exit_loop_tool.js +9 -0
- package/dist/esm/tools/function_tool.js +7 -2
- package/dist/esm/tools/long_running_tool.js +2 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/esm/tools/mcp/mcp_tool.js +10 -7
- package/dist/esm/tools/mcp/mcp_toolset.js +10 -2
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/esm/utils/file_utils.js +26 -0
- package/dist/esm/utils/gemini_schema_util.js +18 -0
- package/dist/esm/utils/partial_copy.js +23 -0
- package/dist/esm/utils/streaming_utils.js +165 -117
- package/dist/esm/utils/vertex_ai_utils.js +22 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
- package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/run_config.d.ts +15 -0
- package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
- package/dist/types/common.d.ts +2 -0
- package/dist/types/events/event_actions.d.ts +24 -6
- package/dist/types/events/structured_events.d.ts +13 -0
- package/dist/types/examples/example_util.d.ts +25 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
- package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
- package/dist/types/integrations/agent_registry/types.d.ts +101 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
- package/dist/types/runner/in_memory_runner.d.ts +28 -1
- package/dist/types/runner/runner.d.ts +47 -0
- package/dist/types/sessions/base_session_service.d.ts +18 -0
- package/dist/types/sessions/database_session_service.d.ts +1 -1
- package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
- package/dist/types/tools/exit_loop_tool.d.ts +9 -0
- package/dist/types/tools/function_tool.d.ts +22 -2
- package/dist/types/tools/long_running_tool.d.ts +11 -1
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
- package/dist/types/utils/file_utils.d.ts +2 -0
- package/dist/types/utils/partial_copy.d.ts +13 -0
- package/dist/types/utils/streaming_utils.d.ts +8 -17
- package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/functions.js +4 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/web/code_executors/code_execution_utils.js +1 -1
- package/dist/web/common.js +2 -0
- package/dist/web/events/event.js +2 -0
- package/dist/web/index.js +11 -0
- package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
- package/dist/web/integrations/agent_registry/helpers.js +28 -0
- package/dist/web/integrations/agent_registry/types.js +20 -0
- package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
- package/dist/web/runner/in_memory_runner.js +10 -5
- package/dist/web/runner/runner.js +32 -2
- package/dist/web/sessions/database_session_service.js +49 -3
- package/dist/web/sessions/in_memory_session_service.js +70 -14
- package/dist/web/sessions/registry.js +7 -0
- package/dist/web/sessions/vertex_ai_session_service.js +414 -0
- package/dist/web/tools/agent_tool.js +17 -8
- package/dist/web/tools/exit_loop_tool.js +9 -0
- package/dist/web/tools/function_tool.js +7 -2
- package/dist/web/tools/long_running_tool.js +2 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/web/tools/mcp/mcp_tool.js +10 -7
- package/dist/web/tools/mcp/mcp_toolset.js +10 -2
- package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/web/utils/file_utils.js +26 -0
- package/dist/web/utils/gemini_schema_util.js +18 -0
- package/dist/web/utils/partial_copy.js +23 -0
- package/dist/web/utils/streaming_utils.js +218 -117
- package/dist/web/utils/vertex_ai_utils.js +22 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -1
|
@@ -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/".concat(this.projectId, "/locations/").concat(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 ".concat(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: ".concat(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 = "".concat(AGENT_REGISTRY_BASE_URL, "/").concat(path);
|
|
80
|
+
} else {
|
|
81
|
+
url = "".concat(AGENT_REGISTRY_BASE_URL, "/").concat(this.basePath, "/").concat(path);
|
|
82
|
+
}
|
|
83
|
+
if (params && Object.keys(params).length > 0) {
|
|
84
|
+
const searchParams = new URLSearchParams(params);
|
|
85
|
+
url += "?".concat(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 ".concat(res.status, ": ").concat(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: ".concat(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: ".concat(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 ".concat(mcpServerName, ": ").concat(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: ".concat(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: ".concat(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
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
/**
|
|
23
|
+
* @license
|
|
24
|
+
* Copyright 2026 Google LLC
|
|
25
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
26
|
+
*/
|
|
27
|
+
import { BaseToolset } from "../../tools/base_toolset.js";
|
|
28
|
+
import {
|
|
29
|
+
MCPSessionManager
|
|
30
|
+
} from "../../tools/mcp/mcp_session_manager.js";
|
|
31
|
+
import { MCPTool } from "../../tools/mcp/mcp_tool.js";
|
|
32
|
+
import { GCP_MCP_SERVER_DESTINATION_ID } from "./types.js";
|
|
33
|
+
class AgentRegistrySingleMCPToolset extends BaseToolset {
|
|
34
|
+
constructor(options) {
|
|
35
|
+
super(options.toolFilter || [], options.prefix);
|
|
36
|
+
this.destinationResourceId = options.destinationResourceId;
|
|
37
|
+
this.connectionParams = options.connectionParams;
|
|
38
|
+
this.headerProvider = options.headerProvider;
|
|
39
|
+
this.authScheme = options.authScheme;
|
|
40
|
+
this.authCredential = options.authCredential;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Connects to the underlying MCP server, retrieves tool definitions, prefixes tool names,
|
|
44
|
+
* and injects destination telemetry metadata.
|
|
45
|
+
*/
|
|
46
|
+
async getTools(context) {
|
|
47
|
+
var _a, _b, _c;
|
|
48
|
+
const headers = {};
|
|
49
|
+
if (this.headerProvider) {
|
|
50
|
+
const providerHeaders = await this.headerProvider(context);
|
|
51
|
+
Object.assign(headers, providerHeaders);
|
|
52
|
+
}
|
|
53
|
+
const connectionParamsCopy = __spreadProps(__spreadValues({}, this.connectionParams), {
|
|
54
|
+
transportOptions: __spreadProps(__spreadValues({}, this.connectionParams.transportOptions), {
|
|
55
|
+
requestInit: __spreadProps(__spreadValues({}, (_a = this.connectionParams.transportOptions) == null ? void 0 : _a.requestInit), {
|
|
56
|
+
headers: __spreadValues(__spreadValues({}, (_c = (_b = this.connectionParams.transportOptions) == null ? void 0 : _b.requestInit) == null ? void 0 : _c.headers), headers)
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
const sessionManager = new MCPSessionManager(connectionParamsCopy);
|
|
61
|
+
const session = await sessionManager.createSession();
|
|
62
|
+
const listResult = await session.listTools();
|
|
63
|
+
const tools = listResult.tools.map((tool) => {
|
|
64
|
+
const prefixedName = this.prefix ? "".concat(this.prefix, "_").concat(tool.name) : tool.name;
|
|
65
|
+
const mcpTool = new MCPTool(
|
|
66
|
+
__spreadProps(__spreadValues({}, tool), { name: prefixedName }),
|
|
67
|
+
sessionManager,
|
|
68
|
+
tool.name
|
|
69
|
+
);
|
|
70
|
+
const toolWithMetadata = mcpTool;
|
|
71
|
+
if (this.destinationResourceId) {
|
|
72
|
+
if (!toolWithMetadata.customMetadata) {
|
|
73
|
+
toolWithMetadata.customMetadata = {};
|
|
74
|
+
}
|
|
75
|
+
toolWithMetadata.customMetadata[GCP_MCP_SERVER_DESTINATION_ID] = this.destinationResourceId;
|
|
76
|
+
}
|
|
77
|
+
return mcpTool;
|
|
78
|
+
});
|
|
79
|
+
const filter = this.toolFilter;
|
|
80
|
+
if (!filter || Array.isArray(filter) && filter.length === 0) {
|
|
81
|
+
return tools;
|
|
82
|
+
}
|
|
83
|
+
return tools.filter((t) => this.isToolSelected(t, context));
|
|
84
|
+
}
|
|
85
|
+
async close() {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
AgentRegistrySingleMCPToolset
|
|
90
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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 isGoogleApi(url) {
|
|
9
|
+
try {
|
|
10
|
+
const parsed = new URL(url);
|
|
11
|
+
return parsed.hostname === "googleapis.com" || parsed.hostname.endsWith(".googleapis.com");
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function cleanName(name) {
|
|
17
|
+
let clean = name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
18
|
+
clean = clean.replace(/_+/g, "_");
|
|
19
|
+
clean = clean.replace(/^_+|_+$/g, "");
|
|
20
|
+
if (clean && !/^[a-zA-Z_]/.test(clean)) {
|
|
21
|
+
clean = "_" + clean;
|
|
22
|
+
}
|
|
23
|
+
return clean;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
cleanName,
|
|
27
|
+
isGoogleApi
|
|
28
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
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 AGENT_REGISTRY_BASE_URL = "https://agentregistry.googleapis.com/v1alpha";
|
|
9
|
+
const GCP_MCP_SERVER_DESTINATION_ID = "gcp.mcp.server.destination.id";
|
|
10
|
+
var ProtocolType = /* @__PURE__ */ ((ProtocolType2) => {
|
|
11
|
+
ProtocolType2["TYPE_UNSPECIFIED"] = "TYPE_UNSPECIFIED";
|
|
12
|
+
ProtocolType2["A2A_AGENT"] = "A2A_AGENT";
|
|
13
|
+
ProtocolType2["CUSTOM"] = "CUSTOM";
|
|
14
|
+
return ProtocolType2;
|
|
15
|
+
})(ProtocolType || {});
|
|
16
|
+
export {
|
|
17
|
+
AGENT_REGISTRY_BASE_URL,
|
|
18
|
+
GCP_MCP_SERVER_DESTINATION_ID,
|
|
19
|
+
ProtocolType
|
|
20
|
+
};
|