@google/adk 2.1.0 → 2.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/a2a/agent_card.js +8 -0
- package/dist/cjs/a2a/agent_executor.js +8 -3
- package/dist/cjs/agents/llm_agent.js +15 -1
- package/dist/cjs/agents/processors/content_processor_utils.js +10 -2
- package/dist/cjs/agents/processors/nl_planning_processor.js +114 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +13 -7
- package/dist/cjs/auth/auth_credential.js +12 -2
- package/dist/cjs/code_executors/code_execution_utils.js +3 -3
- package/dist/cjs/common.js +45 -0
- package/dist/cjs/examples/example.js +92 -0
- package/dist/cjs/examples/example_util.js +28 -4
- package/dist/cjs/examples/index.js +39 -0
- package/dist/cjs/examples/vertex_ai_example_store.js +39 -0
- package/dist/cjs/index.js +46 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +17 -5
- package/dist/cjs/models/base_llm.js +1 -6
- package/dist/cjs/models/chrome_prompt_llm.js +16 -2
- package/dist/cjs/models/chrome_prompt_utils.js +54 -2
- package/dist/cjs/models/gemini_llm_connection.js +5 -4
- package/dist/cjs/planners/base_planner.js +56 -0
- package/dist/cjs/planners/built_in_planner.js +85 -0
- package/dist/cjs/planners/plan_re_act_planner.js +172 -0
- package/dist/cjs/plugins/base_plugin.js +46 -61
- package/dist/cjs/tools/example_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +14 -8
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +281 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +70 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +120 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -10
- package/dist/cjs/tools/openapi_tool/common/common.js +139 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +73 -13
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -34
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +14 -2
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +90 -28
- package/dist/cjs/tools/skill/skill_toolset.js +2 -0
- package/dist/cjs/tools/tool_context.js +41 -0
- package/dist/cjs/tools/webmcp/index.js +37 -0
- package/dist/cjs/tools/webmcp/webmcp_tool.js +156 -0
- package/dist/cjs/tools/webmcp/webmcp_toolset.js +116 -0
- package/dist/cjs/tools/webmcp/webmcp_types.js +50 -0
- package/dist/cjs/utils/case_utils.js +52 -2
- package/dist/cjs/utils/client_labels.js +67 -0
- package/dist/cjs/utils/gemini_schema_util.js +103 -3
- package/dist/cjs/utils/hash_utils.js +73 -0
- package/dist/cjs/utils/live_connection_utils.js +10 -9
- package/dist/cjs/utils/model_name.js +17 -2
- package/dist/cjs/utils/simple_zod_to_json.js +5 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/agent_card.js +8 -0
- package/dist/esm/a2a/agent_executor.js +8 -3
- package/dist/esm/agents/llm_agent.js +18 -1
- package/dist/esm/agents/processors/content_processor_utils.js +10 -2
- package/dist/esm/agents/processors/nl_planning_processor.js +87 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +13 -7
- package/dist/esm/auth/auth_credential.js +11 -1
- package/dist/esm/code_executors/code_execution_utils.js +3 -3
- package/dist/esm/common.js +38 -2
- package/dist/esm/examples/example.js +85 -0
- package/dist/esm/examples/example_util.js +25 -3
- package/dist/esm/examples/index.js +11 -0
- package/dist/esm/examples/vertex_ai_example_store.js +11 -0
- package/dist/esm/index.js +51 -1
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +17 -5
- package/dist/esm/models/base_llm.js +2 -7
- package/dist/esm/models/chrome_prompt_llm.js +20 -3
- package/dist/esm/models/chrome_prompt_utils.js +51 -2
- package/dist/esm/models/gemini_llm_connection.js +6 -5
- package/dist/esm/planners/base_planner.js +28 -0
- package/dist/esm/planners/built_in_planner.js +57 -0
- package/dist/esm/planners/plan_re_act_planner.js +145 -0
- package/dist/esm/plugins/base_plugin.js +46 -61
- package/dist/esm/tools/example_tool.js +1 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +14 -8
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +272 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +43 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +93 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -12
- package/dist/esm/tools/openapi_tool/common/common.js +112 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +80 -13
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -33
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +14 -2
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +89 -28
- package/dist/esm/tools/skill/skill_toolset.js +2 -0
- package/dist/esm/tools/tool_context.js +15 -0
- package/dist/esm/tools/webmcp/index.js +10 -0
- package/dist/esm/tools/webmcp/webmcp_tool.js +131 -0
- package/dist/esm/tools/webmcp/webmcp_toolset.js +89 -0
- package/dist/esm/tools/webmcp/webmcp_types.js +22 -0
- package/dist/esm/utils/case_utils.js +49 -1
- package/dist/esm/utils/client_labels.js +65 -0
- package/dist/esm/utils/gemini_schema_util.js +102 -3
- package/dist/esm/utils/hash_utils.js +45 -0
- package/dist/esm/utils/live_connection_utils.js +11 -10
- package/dist/esm/utils/model_name.js +15 -2
- package/dist/esm/utils/simple_zod_to_json.js +5 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/llm_agent.d.ts +12 -1
- package/dist/types/agents/processors/nl_planning_processor.d.ts +30 -0
- package/dist/types/auth/auth_credential.d.ts +9 -0
- package/dist/types/common.d.ts +16 -4
- package/dist/types/examples/base_example_provider.d.ts +2 -2
- package/dist/types/examples/example.d.ts +75 -0
- package/dist/types/examples/example_util.d.ts +13 -2
- package/dist/types/examples/index.d.ts +18 -0
- package/dist/types/examples/vertex_ai_example_store.d.ts +7 -0
- package/dist/types/index.d.ts +12 -3
- package/dist/types/memory/memory_entry.d.ts +15 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +9 -0
- package/dist/types/models/chrome_prompt_utils.d.ts +29 -0
- package/dist/types/planners/base_planner.d.ts +50 -0
- package/dist/types/planners/built_in_planner.d.ts +53 -0
- package/dist/types/planners/plan_re_act_planner.d.ts +21 -0
- package/dist/types/plugins/base_plugin.d.ts +52 -52
- package/dist/types/skills/skill_registry.d.ts +8 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +110 -1
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +32 -2
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.d.ts +35 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.d.ts +54 -0
- package/dist/types/tools/openapi_tool/common/common.d.ts +60 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +7 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +56 -2
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +73 -5
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +11 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +42 -8
- package/dist/types/tools/tool_context.d.ts +19 -0
- package/dist/types/tools/webmcp/index.d.ts +12 -0
- package/dist/types/tools/webmcp/webmcp_tool.d.ts +47 -0
- package/dist/types/tools/webmcp/webmcp_toolset.d.ts +67 -0
- package/dist/types/tools/webmcp/webmcp_types.d.ts +69 -0
- package/dist/types/utils/case_utils.d.ts +36 -0
- package/dist/types/utils/client_labels.d.ts +33 -0
- package/dist/types/utils/gemini_schema_util.d.ts +13 -0
- package/dist/types/utils/hash_utils.d.ts +25 -0
- package/dist/types/utils/logger.d.ts +10 -2
- package/dist/types/utils/model_name.d.ts +30 -2
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +112 -79
- package/dist/web/index_web.js.map +4 -4
- package/package.json +8 -2
|
@@ -35,11 +35,13 @@ var rest_api_tool_exports = {};
|
|
|
35
35
|
__export(rest_api_tool_exports, {
|
|
36
36
|
RestApiTool: () => RestApiTool,
|
|
37
37
|
createRestApiTool: () => createRestApiTool,
|
|
38
|
+
createRestApiToolFromJson: () => createRestApiToolFromJson,
|
|
38
39
|
prepareRequestBody: () => prepareRequestBody,
|
|
39
40
|
prepareRequestParams: () => prepareRequestParams
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(rest_api_tool_exports);
|
|
42
43
|
var import_experimental = require("../../utils/experimental.js");
|
|
44
|
+
var import_gemini_schema_util = require("../../utils/gemini_schema_util.js");
|
|
43
45
|
var import_base_tool = require("../base_tool.js");
|
|
44
46
|
var import_auth_helpers = require("./auth/auth_helpers.js");
|
|
45
47
|
var import_operation_parser = require("./openapi_spec_parser/operation_parser.js");
|
|
@@ -49,9 +51,30 @@ var import_tool_auth_handler = require("./openapi_spec_parser/tool_auth_handler.
|
|
|
49
51
|
* Copyright 2026 Google LLC
|
|
50
52
|
* SPDX-License-Identifier: Apache-2.0
|
|
51
53
|
*/
|
|
54
|
+
const MAX_TOOL_NAME_LENGTH = 60;
|
|
55
|
+
const SECURITY_SCHEME_TYPES = [
|
|
56
|
+
"apiKey",
|
|
57
|
+
"http",
|
|
58
|
+
"oauth2",
|
|
59
|
+
"openIdConnect"
|
|
60
|
+
];
|
|
61
|
+
function readSchemeType(value) {
|
|
62
|
+
return typeof value === "object" && value !== null && "type" in value ? value.type : void 0;
|
|
63
|
+
}
|
|
64
|
+
__name(readSchemeType, "readSchemeType");
|
|
65
|
+
function isSecurityScheme(value) {
|
|
66
|
+
const type = readSchemeType(value);
|
|
67
|
+
return typeof type === "string" && SECURITY_SCHEME_TYPES.includes(type);
|
|
68
|
+
}
|
|
69
|
+
__name(isSecurityScheme, "isSecurityScheme");
|
|
70
|
+
function serializeCookieHeader(cookies) {
|
|
71
|
+
return Object.entries(cookies).map(([name, value]) => `${name}=${encodeURIComponent(value)}`).join("; ");
|
|
72
|
+
}
|
|
73
|
+
__name(serializeCookieHeader, "serializeCookieHeader");
|
|
52
74
|
let RestApiTool = class extends import_base_tool.BaseTool {
|
|
53
75
|
constructor(name, description, endpoint, operation, authScheme, authCredential, options = {}) {
|
|
54
|
-
|
|
76
|
+
var _a;
|
|
77
|
+
super({ name: name.slice(0, MAX_TOOL_NAME_LENGTH), description });
|
|
55
78
|
this.endpoint = endpoint;
|
|
56
79
|
this.operation = operation;
|
|
57
80
|
this.authScheme = authScheme;
|
|
@@ -60,7 +83,7 @@ let RestApiTool = class extends import_base_tool.BaseTool {
|
|
|
60
83
|
this.authCredential = authCredential;
|
|
61
84
|
this.headerProvider = options.headerProvider;
|
|
62
85
|
this.credentialKey = options.credentialKey;
|
|
63
|
-
this.operationParser = new import_operation_parser.OperationParser(operation, options);
|
|
86
|
+
this.operationParser = (_a = options.operationParser) != null ? _a : new import_operation_parser.OperationParser(operation, options);
|
|
64
87
|
}
|
|
65
88
|
configureAuthScheme(authScheme) {
|
|
66
89
|
this.authScheme = authScheme;
|
|
@@ -72,14 +95,16 @@ let RestApiTool = class extends import_base_tool.BaseTool {
|
|
|
72
95
|
this.credentialKey = credentialKey;
|
|
73
96
|
}
|
|
74
97
|
_getDeclaration() {
|
|
75
|
-
const schema = this.operationParser.getJsonSchema();
|
|
76
98
|
return {
|
|
77
99
|
name: this.name,
|
|
78
100
|
description: this.description,
|
|
79
|
-
parameters:
|
|
101
|
+
parameters: (0, import_gemini_schema_util.openApiSchemaToGeminiSchema)(
|
|
102
|
+
this.operationParser.getJsonSchema()
|
|
103
|
+
)
|
|
80
104
|
};
|
|
81
105
|
}
|
|
82
106
|
async runAsync(request) {
|
|
107
|
+
var _a;
|
|
83
108
|
const context = request.toolContext;
|
|
84
109
|
const args = request.args;
|
|
85
110
|
const authHandler = import_tool_auth_handler.ToolAuthHandler.fromToolContext(
|
|
@@ -101,7 +126,8 @@ let RestApiTool = class extends import_base_tool.BaseTool {
|
|
|
101
126
|
url: initialUrl,
|
|
102
127
|
headers,
|
|
103
128
|
body: parsedBody,
|
|
104
|
-
bodyData
|
|
129
|
+
bodyData,
|
|
130
|
+
cookies
|
|
105
131
|
} = prepareRequestParams(
|
|
106
132
|
this.endpoint,
|
|
107
133
|
this.operationParser.getParameters(),
|
|
@@ -117,30 +143,36 @@ let RestApiTool = class extends import_base_tool.BaseTool {
|
|
|
117
143
|
initialUrl,
|
|
118
144
|
headers,
|
|
119
145
|
credential,
|
|
120
|
-
this.authScheme
|
|
146
|
+
(_a = authResult.authScheme) != null ? _a : this.authScheme
|
|
121
147
|
);
|
|
122
148
|
if (this.headerProvider) {
|
|
123
149
|
const providerHeaders = this.headerProvider(context);
|
|
124
150
|
Object.assign(headers, providerHeaders);
|
|
125
151
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
152
|
+
const hasCookieHeader = Object.keys(headers).some(
|
|
153
|
+
(header) => header.toLowerCase() === "cookie"
|
|
154
|
+
);
|
|
155
|
+
if (Object.keys(cookies).length > 0 && !hasCookieHeader) {
|
|
156
|
+
headers["Cookie"] = serializeCookieHeader(cookies);
|
|
157
|
+
}
|
|
158
|
+
const response = await globalThis.fetch(url, {
|
|
159
|
+
method,
|
|
160
|
+
headers,
|
|
161
|
+
// eslint-disable-next-line no-undef
|
|
162
|
+
body
|
|
163
|
+
});
|
|
164
|
+
if (response.status >= 400) {
|
|
165
|
+
const errorDetails = await response.text();
|
|
140
166
|
return {
|
|
141
|
-
error: `
|
|
167
|
+
error: `Tool ${this.name} execution failed. Analyze this execution error and your inputs. Retry with adjustments if applicable. But make sure don't retry more than 3 times. Execution Error: ${errorDetails}`
|
|
142
168
|
};
|
|
143
169
|
}
|
|
170
|
+
const text = await response.text();
|
|
171
|
+
try {
|
|
172
|
+
return JSON.parse(text);
|
|
173
|
+
} catch {
|
|
174
|
+
return { text };
|
|
175
|
+
}
|
|
144
176
|
}
|
|
145
177
|
};
|
|
146
178
|
__name(RestApiTool, "RestApiTool");
|
|
@@ -174,6 +206,7 @@ __name(encodePathParamValue, "encodePathParamValue");
|
|
|
174
206
|
function prepareRequestParams(endpoint, parameters, args) {
|
|
175
207
|
const headers = {};
|
|
176
208
|
const queryParams = new URLSearchParams();
|
|
209
|
+
const cookies = {};
|
|
177
210
|
let body = void 0;
|
|
178
211
|
const paramsMap = new Map(parameters.map((p) => [p.name, p]));
|
|
179
212
|
const pathParams = {};
|
|
@@ -189,9 +222,13 @@ function prepareRequestParams(endpoint, parameters, args) {
|
|
|
189
222
|
String(argValue)
|
|
190
223
|
);
|
|
191
224
|
} else if (location === "query") {
|
|
192
|
-
|
|
225
|
+
if (argValue !== void 0 && argValue !== null && argValue !== "") {
|
|
226
|
+
queryParams.append(originalName, String(argValue));
|
|
227
|
+
}
|
|
193
228
|
} else if (location === "header") {
|
|
194
229
|
headers[originalName] = String(argValue);
|
|
230
|
+
} else if (location === "cookie") {
|
|
231
|
+
cookies[originalName] = String(argValue);
|
|
195
232
|
} else if (location === "body") {
|
|
196
233
|
if (originalName === "body" || originalName === "array" || originalName === "") {
|
|
197
234
|
body = argValue;
|
|
@@ -204,7 +241,8 @@ function prepareRequestParams(endpoint, parameters, args) {
|
|
|
204
241
|
/\{([^{}]+)\}/g,
|
|
205
242
|
(placeholder, name) => Object.hasOwn(pathParams, name) ? pathParams[name] : placeholder
|
|
206
243
|
);
|
|
207
|
-
|
|
244
|
+
const baseUrl = endpoint.baseUrl.endsWith("/") ? endpoint.baseUrl.slice(0, -1) : endpoint.baseUrl;
|
|
245
|
+
let url = `${baseUrl}${resolvedPath}`;
|
|
208
246
|
const urlParts = url.split("?");
|
|
209
247
|
if (urlParts.length > 1) {
|
|
210
248
|
const pathQueryParams = new URLSearchParams(urlParts[1]);
|
|
@@ -217,9 +255,13 @@ function prepareRequestParams(endpoint, parameters, args) {
|
|
|
217
255
|
if (queryString) {
|
|
218
256
|
url += `?${queryString}`;
|
|
219
257
|
}
|
|
220
|
-
return { url, headers, body, bodyData };
|
|
258
|
+
return { url, headers, body, bodyData, cookies };
|
|
221
259
|
}
|
|
222
260
|
__name(prepareRequestParams, "prepareRequestParams");
|
|
261
|
+
function isRawBody(value) {
|
|
262
|
+
return typeof value === "string" || ArrayBuffer.isView(value) || value instanceof ArrayBuffer || value instanceof Blob;
|
|
263
|
+
}
|
|
264
|
+
__name(isRawBody, "isRawBody");
|
|
223
265
|
function prepareRequestBody(requestBody, body, bodyData, headers) {
|
|
224
266
|
const finalData = body !== void 0 ? body : Object.keys(bodyData).length > 0 ? bodyData : void 0;
|
|
225
267
|
if (requestBody && "content" in requestBody) {
|
|
@@ -239,6 +281,9 @@ function prepareRequestBody(requestBody, body, bodyData, headers) {
|
|
|
239
281
|
}
|
|
240
282
|
}
|
|
241
283
|
return formData;
|
|
284
|
+
} else if (mimeType === "application/octet-stream") {
|
|
285
|
+
headers["Content-Type"] = mimeType;
|
|
286
|
+
return isRawBody(finalData) ? finalData : String(finalData);
|
|
242
287
|
} else if (mimeType === "text/plain") {
|
|
243
288
|
headers["Content-Type"] = mimeType;
|
|
244
289
|
return String(finalData);
|
|
@@ -252,21 +297,38 @@ function prepareRequestBody(requestBody, body, bodyData, headers) {
|
|
|
252
297
|
}
|
|
253
298
|
__name(prepareRequestBody, "prepareRequestBody");
|
|
254
299
|
function createRestApiTool(parsed, options = {}) {
|
|
300
|
+
var _a, _b;
|
|
301
|
+
const operationParser = parsed.parameters ? import_operation_parser.OperationParser.load(
|
|
302
|
+
parsed.operation,
|
|
303
|
+
parsed.parameters,
|
|
304
|
+
parsed.returnValue
|
|
305
|
+
) : new import_operation_parser.OperationParser(parsed.operation, options);
|
|
255
306
|
return new RestApiTool(
|
|
256
|
-
parsed.name,
|
|
257
|
-
parsed.description,
|
|
307
|
+
(_a = parsed.name) != null ? _a : operationParser.getFunctionName(),
|
|
308
|
+
(_b = parsed.description) != null ? _b : operationParser.getDescription(),
|
|
258
309
|
parsed.endpoint,
|
|
259
310
|
parsed.operation,
|
|
260
311
|
parsed.authScheme,
|
|
261
|
-
|
|
262
|
-
options
|
|
312
|
+
parsed.authCredential,
|
|
313
|
+
{ ...options, operationParser }
|
|
263
314
|
);
|
|
264
315
|
}
|
|
265
316
|
__name(createRestApiTool, "createRestApiTool");
|
|
317
|
+
function createRestApiToolFromJson(parsedOperationJson) {
|
|
318
|
+
const parsed = JSON.parse(parsedOperationJson);
|
|
319
|
+
if (parsed.authScheme && !isSecurityScheme(parsed.authScheme)) {
|
|
320
|
+
throw new Error(
|
|
321
|
+
`Unsupported security scheme type: ${JSON.stringify(readSchemeType(parsed.authScheme))}. Expected one of: ${SECURITY_SCHEME_TYPES.join(", ")}.`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
return createRestApiTool(parsed);
|
|
325
|
+
}
|
|
326
|
+
__name(createRestApiToolFromJson, "createRestApiToolFromJson");
|
|
266
327
|
// Annotate the CommonJS export names for ESM import in node:
|
|
267
328
|
0 && (module.exports = {
|
|
268
329
|
RestApiTool,
|
|
269
330
|
createRestApiTool,
|
|
331
|
+
createRestApiToolFromJson,
|
|
270
332
|
prepareRequestBody,
|
|
271
333
|
prepareRequestParams
|
|
272
334
|
});
|
|
@@ -109,7 +109,9 @@ let SkillToolset = class extends import_base_toolset.BaseToolset {
|
|
|
109
109
|
return [...this.tools, ...dynamicTools];
|
|
110
110
|
}
|
|
111
111
|
async close() {
|
|
112
|
+
var _a, _b;
|
|
112
113
|
this.fetchedSkillCache.clear();
|
|
114
|
+
await ((_b = (_a = this.registry) == null ? void 0 : _a.close) == null ? void 0 : _b.call(_a));
|
|
113
115
|
}
|
|
114
116
|
getSkill(name) {
|
|
115
117
|
return this.skills[name];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var tool_context_exports = {};
|
|
26
|
+
__export(tool_context_exports, {
|
|
27
|
+
CallbackContext: () => import_context.Context,
|
|
28
|
+
ToolContext: () => import_context.Context
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(tool_context_exports);
|
|
31
|
+
var import_context = require("../agents/context.js");
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2026 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
CallbackContext,
|
|
40
|
+
ToolContext
|
|
41
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var webmcp_exports = {};
|
|
23
|
+
module.exports = __toCommonJS(webmcp_exports);
|
|
24
|
+
__reExport(webmcp_exports, require("./webmcp_tool.js"), module.exports);
|
|
25
|
+
__reExport(webmcp_exports, require("./webmcp_toolset.js"), module.exports);
|
|
26
|
+
__reExport(webmcp_exports, require("./webmcp_types.js"), module.exports);
|
|
27
|
+
/**
|
|
28
|
+
* @license
|
|
29
|
+
* Copyright 2026 Google LLC
|
|
30
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
31
|
+
*/
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
...require("./webmcp_tool.js"),
|
|
35
|
+
...require("./webmcp_toolset.js"),
|
|
36
|
+
...require("./webmcp_types.js")
|
|
37
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var webmcp_tool_exports = {};
|
|
27
|
+
__export(webmcp_tool_exports, {
|
|
28
|
+
WebMCPTool: () => WebMCPTool
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(webmcp_tool_exports);
|
|
31
|
+
var import_genai = require("@google/genai");
|
|
32
|
+
var import_gemini_schema_util = require("../../utils/gemini_schema_util.js");
|
|
33
|
+
var import_logger = require("../../utils/logger.js");
|
|
34
|
+
var import_base_tool = require("../base_tool.js");
|
|
35
|
+
var import_webmcp_types = require("./webmcp_types.js");
|
|
36
|
+
/**
|
|
37
|
+
* @license
|
|
38
|
+
* Copyright 2026 Google LLC
|
|
39
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
40
|
+
*/
|
|
41
|
+
const argEncodingByContext = /* @__PURE__ */ new WeakMap();
|
|
42
|
+
function isArgParseFailure(value) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
let text = "";
|
|
45
|
+
if (typeof value === "string") {
|
|
46
|
+
text = value;
|
|
47
|
+
} else if (value && typeof value === "object") {
|
|
48
|
+
const candidate = value;
|
|
49
|
+
text = String((_b = (_a = candidate.error) != null ? _a : candidate.message) != null ? _b : "");
|
|
50
|
+
}
|
|
51
|
+
return /failed to parse input arguments|could not parse .*arguments/i.test(
|
|
52
|
+
text
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
__name(isArgParseFailure, "isArgParseFailure");
|
|
56
|
+
const _WebMCPTool = class _WebMCPTool extends import_base_tool.BaseTool {
|
|
57
|
+
constructor(params) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
super({
|
|
60
|
+
name: (_a = params.name) != null ? _a : params.tool.name,
|
|
61
|
+
description: (_b = params.tool.description) != null ? _b : ""
|
|
62
|
+
});
|
|
63
|
+
this.webmcpTool = params.tool;
|
|
64
|
+
this.doc = params.document;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The tool's JSON Schema as an object.
|
|
68
|
+
*
|
|
69
|
+
* `inputSchema` is specified as an object, but a browser handing back a JSON
|
|
70
|
+
* string would otherwise convert to a parameterless declaration, leaving the
|
|
71
|
+
* model no argument names to fill in — it then calls the tool with `{}`.
|
|
72
|
+
*/
|
|
73
|
+
resolveInputSchema() {
|
|
74
|
+
const raw = this.webmcpTool.inputSchema;
|
|
75
|
+
if (raw == null) return void 0;
|
|
76
|
+
if (typeof raw === "string") {
|
|
77
|
+
try {
|
|
78
|
+
const parsed = JSON.parse(raw);
|
|
79
|
+
return typeof parsed === "object" && parsed !== null ? parsed : void 0;
|
|
80
|
+
} catch {
|
|
81
|
+
import_logger.logger.warn(
|
|
82
|
+
`WebMCP tool '${this.webmcpTool.name}' has an inputSchema string that is not valid JSON; exposing it with no parameters.`
|
|
83
|
+
);
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (typeof raw === "object") return raw;
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
_getDeclaration() {
|
|
91
|
+
var _a;
|
|
92
|
+
const schema = this.resolveInputSchema();
|
|
93
|
+
const parameters = schema ? (_a = (0, import_gemini_schema_util.toGeminiSchema)(schema)) != null ? _a : { type: import_genai.Type.OBJECT, properties: {} } : { type: import_genai.Type.OBJECT, properties: {} };
|
|
94
|
+
if (schema && !parameters.properties) {
|
|
95
|
+
import_logger.logger.warn(
|
|
96
|
+
`WebMCP tool '${this.webmcpTool.name}' declared an inputSchema that produced no parameters; the model will be unable to pass arguments.`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
name: this.name,
|
|
101
|
+
description: this.description,
|
|
102
|
+
parameters
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async checkRequireConfirmation() {
|
|
106
|
+
var _a;
|
|
107
|
+
return !!((_a = this.webmcpTool.annotations) == null ? void 0 : _a.consequentialHint);
|
|
108
|
+
}
|
|
109
|
+
async runAsync(request) {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
const modelContext = (0, import_webmcp_types.getModelContext)(this.doc);
|
|
112
|
+
if (!modelContext) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
"document.modelContext is unavailable, so WebMCP tools cannot be executed. WebMCP requires a browser with the API enabled."
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
const args = (_a = request.args) != null ? _a : {};
|
|
118
|
+
const signal = (_b = request.toolContext) == null ? void 0 : _b.abortSignal;
|
|
119
|
+
const options = signal ? { signal } : void 0;
|
|
120
|
+
const invoke = /* @__PURE__ */ __name((encoding) => modelContext.executeTool(
|
|
121
|
+
this.webmcpTool,
|
|
122
|
+
encoding === "json-string" ? JSON.stringify(args) : args,
|
|
123
|
+
options
|
|
124
|
+
), "invoke");
|
|
125
|
+
const known = argEncodingByContext.get(modelContext);
|
|
126
|
+
if (known) {
|
|
127
|
+
return await invoke(known);
|
|
128
|
+
}
|
|
129
|
+
let firstResult;
|
|
130
|
+
try {
|
|
131
|
+
firstResult = await invoke("object");
|
|
132
|
+
if (!isArgParseFailure(firstResult)) {
|
|
133
|
+
argEncodingByContext.set(modelContext, "object");
|
|
134
|
+
return firstResult;
|
|
135
|
+
}
|
|
136
|
+
} catch (err) {
|
|
137
|
+
if (!isArgParseFailure(err)) throw err;
|
|
138
|
+
firstResult = err;
|
|
139
|
+
}
|
|
140
|
+
const retried = await invoke("json-string");
|
|
141
|
+
if (isArgParseFailure(retried)) {
|
|
142
|
+
return firstResult;
|
|
143
|
+
}
|
|
144
|
+
argEncodingByContext.set(modelContext, "json-string");
|
|
145
|
+
import_logger.logger.debug(
|
|
146
|
+
"This browser expects JSON-string WebMCP tool arguments; using that encoding."
|
|
147
|
+
);
|
|
148
|
+
return retried;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
__name(_WebMCPTool, "WebMCPTool");
|
|
152
|
+
let WebMCPTool = _WebMCPTool;
|
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
+
0 && (module.exports = {
|
|
155
|
+
WebMCPTool
|
|
156
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var webmcp_toolset_exports = {};
|
|
27
|
+
__export(webmcp_toolset_exports, {
|
|
28
|
+
WebMCPToolset: () => WebMCPToolset
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(webmcp_toolset_exports);
|
|
31
|
+
var import_logger = require("../../utils/logger.js");
|
|
32
|
+
var import_base_toolset = require("../base_toolset.js");
|
|
33
|
+
var import_webmcp_tool = require("./webmcp_tool.js");
|
|
34
|
+
var import_webmcp_types = require("./webmcp_types.js");
|
|
35
|
+
/**
|
|
36
|
+
* @license
|
|
37
|
+
* Copyright 2026 Google LLC
|
|
38
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
39
|
+
*/
|
|
40
|
+
const _WebMCPToolset = class _WebMCPToolset extends import_base_toolset.BaseToolset {
|
|
41
|
+
constructor(options = {}) {
|
|
42
|
+
var _a;
|
|
43
|
+
super((_a = options.toolFilter) != null ? _a : [], options.prefix);
|
|
44
|
+
this.changeListeners = /* @__PURE__ */ new Set();
|
|
45
|
+
this.doc = options.document;
|
|
46
|
+
this.fromOrigins = options.fromOrigins;
|
|
47
|
+
}
|
|
48
|
+
/** Whether this document exposes WebMCP. */
|
|
49
|
+
isSupported() {
|
|
50
|
+
return !!(0, import_webmcp_types.getModelContext)(this.doc);
|
|
51
|
+
}
|
|
52
|
+
async getTools(context) {
|
|
53
|
+
const modelContext = (0, import_webmcp_types.getModelContext)(this.doc);
|
|
54
|
+
if (!modelContext) {
|
|
55
|
+
import_logger.logger.debug(
|
|
56
|
+
"document.modelContext is unavailable; WebMCPToolset is exposing no tools."
|
|
57
|
+
);
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
const registered = await modelContext.getTools(
|
|
61
|
+
this.fromOrigins ? { fromOrigins: this.fromOrigins } : void 0
|
|
62
|
+
);
|
|
63
|
+
const tools = registered.map(
|
|
64
|
+
(tool) => new import_webmcp_tool.WebMCPTool({
|
|
65
|
+
tool,
|
|
66
|
+
name: this.prefix ? `${this.prefix}_${tool.name}` : tool.name,
|
|
67
|
+
document: this.doc
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
const filter = this.toolFilter;
|
|
71
|
+
if (!filter || Array.isArray(filter) && filter.length === 0) {
|
|
72
|
+
return tools;
|
|
73
|
+
}
|
|
74
|
+
if (Array.isArray(filter)) {
|
|
75
|
+
return tools.filter((tool) => filter.includes(tool.name));
|
|
76
|
+
}
|
|
77
|
+
if (context) {
|
|
78
|
+
return tools.filter((tool) => filter(tool, context));
|
|
79
|
+
}
|
|
80
|
+
import_logger.logger.warn(
|
|
81
|
+
"WebMCPToolset: a ToolPredicate toolFilter was provided but getTools() was called without a ReadonlyContext. The filter will not be applied."
|
|
82
|
+
);
|
|
83
|
+
return tools;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Subscribes to the WebMCP `toolchange` event, which fires when the page
|
|
87
|
+
* registers or removes tools. Returns an unsubscribe function.
|
|
88
|
+
*/
|
|
89
|
+
onToolChange(listener) {
|
|
90
|
+
const modelContext = (0, import_webmcp_types.getModelContext)(this.doc);
|
|
91
|
+
if (!modelContext) return () => {
|
|
92
|
+
};
|
|
93
|
+
const handler = /* @__PURE__ */ __name(() => listener(), "handler");
|
|
94
|
+
this.changeListeners.add(handler);
|
|
95
|
+
modelContext.addEventListener("toolchange", handler);
|
|
96
|
+
return () => {
|
|
97
|
+
modelContext.removeEventListener("toolchange", handler);
|
|
98
|
+
this.changeListeners.delete(handler);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async close() {
|
|
102
|
+
const modelContext = (0, import_webmcp_types.getModelContext)(this.doc);
|
|
103
|
+
if (modelContext) {
|
|
104
|
+
for (const handler of this.changeListeners) {
|
|
105
|
+
modelContext.removeEventListener("toolchange", handler);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
this.changeListeners.clear();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
__name(_WebMCPToolset, "WebMCPToolset");
|
|
112
|
+
let WebMCPToolset = _WebMCPToolset;
|
|
113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
114
|
+
0 && (module.exports = {
|
|
115
|
+
WebMCPToolset
|
|
116
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var webmcp_types_exports = {};
|
|
27
|
+
__export(webmcp_types_exports, {
|
|
28
|
+
getModelContext: () => getModelContext,
|
|
29
|
+
isWebMCPSupported: () => isWebMCPSupported
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(webmcp_types_exports);
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2026 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
function getModelContext(doc) {
|
|
38
|
+
const target = doc != null ? doc : globalThis.document;
|
|
39
|
+
return target == null ? void 0 : target.modelContext;
|
|
40
|
+
}
|
|
41
|
+
__name(getModelContext, "getModelContext");
|
|
42
|
+
function isWebMCPSupported(doc) {
|
|
43
|
+
return !!getModelContext(doc);
|
|
44
|
+
}
|
|
45
|
+
__name(isWebMCPSupported, "isWebMCPSupported");
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
getModelContext,
|
|
49
|
+
isWebMCPSupported
|
|
50
|
+
});
|