@google/adk 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/base_agent.js +19 -1
- package/dist/cjs/agents/instructions.js +81 -33
- package/dist/cjs/agents/invocation_context.js +0 -1
- package/dist/cjs/agents/llm_agent.js +52 -5
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
- package/dist/cjs/agents/processors/content_request_processor.js +7 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/cjs/auth/auth_preprocessor.js +12 -10
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +7 -7
- package/dist/cjs/common.js +39 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
- package/dist/cjs/context/token_based_context_compactor.js +1 -1
- package/dist/cjs/events/event.js +1 -1
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/cjs/models/gemini_llm_connection.js +62 -19
- package/dist/cjs/models/google_llm.js +26 -8
- package/dist/cjs/plugins/security_plugin.js +16 -0
- package/dist/cjs/sessions/base_session_service.js +13 -2
- package/dist/cjs/sessions/database_session_service.js +2 -2
- package/dist/cjs/sessions/db/schema.js +45 -10
- package/dist/cjs/sessions/in_memory_session_service.js +2 -1
- package/dist/cjs/sessions/vertex_ai_session_service.js +2 -1
- package/dist/cjs/skills/gcp_skill_registry.js +104 -0
- package/dist/cjs/skills/loader.js +65 -0
- package/dist/cjs/skills/skill_registry.js +27 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +127 -0
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
- package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
- package/dist/cjs/tools/skill/skill_toolset.js +40 -5
- package/dist/cjs/utils/async_queue.js +88 -0
- package/dist/cjs/utils/case_utils.js +53 -0
- package/dist/cjs/utils/env_aware_utils.js +4 -0
- package/dist/cjs/utils/live_connection_utils.js +284 -0
- package/dist/cjs/utils/model_name.js +9 -0
- package/dist/cjs/utils/streaming_utils.js +9 -8
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +19 -1
- package/dist/esm/agents/instructions.js +81 -33
- package/dist/esm/agents/invocation_context.js +0 -1
- package/dist/esm/agents/llm_agent.js +53 -5
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/esm/agents/processors/content_processor_utils.js +35 -23
- package/dist/esm/agents/processors/content_request_processor.js +7 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/esm/auth/auth_preprocessor.js +12 -10
- package/dist/esm/auth/oauth2/oauth2_discovery.js +1 -1
- package/dist/esm/code_executors/code_executor_context.js +7 -7
- package/dist/esm/common.js +33 -1
- package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
- package/dist/esm/context/token_based_context_compactor.js +1 -1
- package/dist/esm/events/event.js +1 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/esm/models/gemini_llm_connection.js +62 -19
- package/dist/esm/models/google_llm.js +26 -8
- package/dist/esm/plugins/security_plugin.js +16 -0
- package/dist/esm/sessions/base_session_service.js +11 -1
- package/dist/esm/sessions/database_session_service.js +2 -2
- package/dist/esm/sessions/db/schema.js +44 -10
- package/dist/esm/sessions/in_memory_session_service.js +4 -2
- package/dist/esm/sessions/vertex_ai_session_service.js +4 -2
- package/dist/esm/skills/gcp_skill_registry.js +78 -0
- package/dist/esm/skills/loader.js +64 -0
- package/dist/esm/skills/skill_registry.js +7 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/esm/tools/skill/load_skill_tool.js +12 -1
- package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/esm/tools/skill/search_skills_tool.js +82 -0
- package/dist/esm/tools/skill/skill_toolset.js +40 -5
- package/dist/esm/utils/async_queue.js +60 -0
- package/dist/esm/utils/case_utils.js +25 -0
- package/dist/esm/utils/env_aware_utils.js +4 -0
- package/dist/esm/utils/live_connection_utils.js +256 -0
- package/dist/esm/utils/model_name.js +8 -0
- package/dist/esm/utils/streaming_utils.js +9 -8
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
- package/dist/types/a2a/event_converter_utils.d.ts +14 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
- package/dist/types/a2a/part_converter_utils.d.ts +51 -6
- package/dist/types/agents/invocation_context.d.ts +0 -9
- package/dist/types/agents/llm_agent.d.ts +14 -0
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
- package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
- package/dist/types/common.d.ts +15 -1
- package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
- package/dist/types/events/event_actions.d.ts +1 -2
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
- package/dist/types/models/base_llm_connection.d.ts +10 -0
- package/dist/types/models/gemini_llm_connection.d.ts +15 -4
- package/dist/types/models/llm_response.d.ts +10 -1
- package/dist/types/plugins/security_plugin.d.ts +30 -0
- package/dist/types/sessions/base_session_service.d.ts +4 -0
- package/dist/types/sessions/db/schema.d.ts +1 -0
- package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
- package/dist/types/skills/loader.d.ts +7 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/skills/skill_registry.d.ts +29 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
- package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
- package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
- package/dist/types/utils/async_queue.d.ts +18 -0
- package/dist/types/utils/case_utils.d.ts +12 -0
- package/dist/types/utils/live_connection_utils.d.ts +30 -0
- package/dist/types/utils/model_name.d.ts +7 -0
- package/dist/types/utils/streaming_utils.d.ts +0 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +31 -1
- package/dist/web/agents/instructions.js +81 -33
- package/dist/web/agents/invocation_context.js +0 -1
- package/dist/web/agents/llm_agent.js +53 -5
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/web/agents/processors/content_processor_utils.js +53 -23
- package/dist/web/agents/processors/content_request_processor.js +7 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/web/auth/auth_preprocessor.js +12 -10
- package/dist/web/auth/oauth2/oauth2_discovery.js +1 -1
- package/dist/web/code_executors/code_executor_context.js +7 -7
- package/dist/web/common.js +33 -1
- package/dist/web/context/summarizers/llm_summarizer.js +11 -0
- package/dist/web/context/token_based_context_compactor.js +1 -1
- package/dist/web/events/event.js +1 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/web/models/gemini_llm_connection.js +75 -19
- package/dist/web/models/google_llm.js +26 -8
- package/dist/web/plugins/security_plugin.js +16 -0
- package/dist/web/sessions/base_session_service.js +11 -1
- package/dist/web/sessions/database_session_service.js +2 -2
- package/dist/web/sessions/db/schema.js +44 -10
- package/dist/web/sessions/in_memory_session_service.js +4 -2
- package/dist/web/sessions/vertex_ai_session_service.js +4 -2
- package/dist/web/skills/gcp_skill_registry.js +78 -0
- package/dist/web/skills/loader.js +64 -0
- package/dist/web/skills/skill_registry.js +7 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
- package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/web/tools/skill/load_skill_tool.js +12 -1
- package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/web/tools/skill/search_skills_tool.js +82 -0
- package/dist/web/tools/skill/skill_toolset.js +40 -5
- package/dist/web/utils/async_queue.js +60 -0
- package/dist/web/utils/case_utils.js +25 -0
- package/dist/web/utils/env_aware_utils.js +4 -0
- package/dist/web/utils/live_connection_utils.js +254 -0
- package/dist/web/utils/model_name.js +8 -0
- package/dist/web/utils/streaming_utils.js +9 -8
- package/dist/web/version.js +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,229 @@
|
|
|
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 { experimental } from "../../utils/experimental.js";
|
|
19
|
+
import { BaseTool } from "../base_tool.js";
|
|
20
|
+
import { applyCredential } from "./auth/auth_helpers.js";
|
|
21
|
+
import {
|
|
22
|
+
OperationParser
|
|
23
|
+
} from "./openapi_spec_parser/operation_parser.js";
|
|
24
|
+
import { ToolAuthHandler } from "./openapi_spec_parser/tool_auth_handler.js";
|
|
25
|
+
let RestApiTool = class extends BaseTool {
|
|
26
|
+
constructor(name, description, endpoint, operation, authScheme, authCredential, options = {}) {
|
|
27
|
+
super({ name, description });
|
|
28
|
+
this.endpoint = endpoint;
|
|
29
|
+
this.operation = operation;
|
|
30
|
+
this.authScheme = authScheme;
|
|
31
|
+
this.authCredential = authCredential;
|
|
32
|
+
this.authScheme = authScheme;
|
|
33
|
+
this.authCredential = authCredential;
|
|
34
|
+
this.headerProvider = options.headerProvider;
|
|
35
|
+
this.credentialKey = options.credentialKey;
|
|
36
|
+
this.operationParser = new OperationParser(operation, options);
|
|
37
|
+
}
|
|
38
|
+
configureAuthScheme(authScheme) {
|
|
39
|
+
this.authScheme = authScheme;
|
|
40
|
+
}
|
|
41
|
+
configureAuthCredential(authCredential) {
|
|
42
|
+
this.authCredential = authCredential;
|
|
43
|
+
}
|
|
44
|
+
configureCredentialKey(credentialKey) {
|
|
45
|
+
this.credentialKey = credentialKey;
|
|
46
|
+
}
|
|
47
|
+
_getDeclaration() {
|
|
48
|
+
const schema = this.operationParser.getJsonSchema();
|
|
49
|
+
return {
|
|
50
|
+
name: this.name,
|
|
51
|
+
description: this.description,
|
|
52
|
+
parameters: schema
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async runAsync(request) {
|
|
56
|
+
const context = request.toolContext;
|
|
57
|
+
const args = request.args;
|
|
58
|
+
const authHandler = ToolAuthHandler.fromToolContext(
|
|
59
|
+
context,
|
|
60
|
+
this.authScheme,
|
|
61
|
+
this.authCredential,
|
|
62
|
+
{ credentialKey: this.credentialKey }
|
|
63
|
+
);
|
|
64
|
+
const authResult = await authHandler.prepareAuthCredentials();
|
|
65
|
+
if (authResult.state === "pending") {
|
|
66
|
+
return {
|
|
67
|
+
pending: true,
|
|
68
|
+
message: "Needs your authorization to access your data."
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const credential = authResult.authCredential;
|
|
72
|
+
const method = this.endpoint.method.toUpperCase();
|
|
73
|
+
const {
|
|
74
|
+
url: initialUrl,
|
|
75
|
+
headers,
|
|
76
|
+
body: parsedBody,
|
|
77
|
+
bodyData
|
|
78
|
+
} = prepareRequestParams(
|
|
79
|
+
this.endpoint,
|
|
80
|
+
this.operationParser.getParameters(),
|
|
81
|
+
args
|
|
82
|
+
);
|
|
83
|
+
const body = prepareRequestBody(
|
|
84
|
+
this.operation.requestBody,
|
|
85
|
+
parsedBody,
|
|
86
|
+
bodyData,
|
|
87
|
+
headers
|
|
88
|
+
);
|
|
89
|
+
const url = applyCredential(
|
|
90
|
+
initialUrl,
|
|
91
|
+
headers,
|
|
92
|
+
credential,
|
|
93
|
+
this.authScheme
|
|
94
|
+
);
|
|
95
|
+
if (this.headerProvider) {
|
|
96
|
+
const providerHeaders = this.headerProvider(context);
|
|
97
|
+
Object.assign(headers, providerHeaders);
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const response = await globalThis.fetch(url, {
|
|
101
|
+
method,
|
|
102
|
+
headers,
|
|
103
|
+
// eslint-disable-next-line no-undef
|
|
104
|
+
body
|
|
105
|
+
});
|
|
106
|
+
const contentType = response.headers.get("content-type");
|
|
107
|
+
if (contentType && contentType.includes("application/json")) {
|
|
108
|
+
return await response.json();
|
|
109
|
+
} else {
|
|
110
|
+
return await response.text();
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
return {
|
|
114
|
+
error: "Failed to execute API call: ".concat(error.message)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
__decorateClass([
|
|
120
|
+
experimental
|
|
121
|
+
], RestApiTool.prototype, "configureAuthScheme", 1);
|
|
122
|
+
__decorateClass([
|
|
123
|
+
experimental
|
|
124
|
+
], RestApiTool.prototype, "configureAuthCredential", 1);
|
|
125
|
+
__decorateClass([
|
|
126
|
+
experimental
|
|
127
|
+
], RestApiTool.prototype, "configureCredentialKey", 1);
|
|
128
|
+
__decorateClass([
|
|
129
|
+
experimental
|
|
130
|
+
], RestApiTool.prototype, "_getDeclaration", 1);
|
|
131
|
+
__decorateClass([
|
|
132
|
+
experimental
|
|
133
|
+
], RestApiTool.prototype, "runAsync", 1);
|
|
134
|
+
RestApiTool = __decorateClass([
|
|
135
|
+
experimental
|
|
136
|
+
], RestApiTool);
|
|
137
|
+
function prepareRequestParams(endpoint, parameters, args) {
|
|
138
|
+
const headers = {};
|
|
139
|
+
const queryParams = new URLSearchParams();
|
|
140
|
+
let body = void 0;
|
|
141
|
+
const paramsMap = new Map(parameters.map((p) => [p.name, p]));
|
|
142
|
+
const pathParams = {};
|
|
143
|
+
const bodyData = {};
|
|
144
|
+
for (const [argName, argValue] of Object.entries(args)) {
|
|
145
|
+
const param = paramsMap.get(argName);
|
|
146
|
+
if (!param) continue;
|
|
147
|
+
const originalName = param.originalName;
|
|
148
|
+
const location = param.paramLocation;
|
|
149
|
+
if (location === "path") {
|
|
150
|
+
pathParams[originalName] = String(argValue);
|
|
151
|
+
} else if (location === "query") {
|
|
152
|
+
queryParams.append(originalName, String(argValue));
|
|
153
|
+
} else if (location === "header") {
|
|
154
|
+
headers[originalName] = String(argValue);
|
|
155
|
+
} else if (location === "body") {
|
|
156
|
+
if (originalName === "body" || originalName === "array" || originalName === "") {
|
|
157
|
+
body = argValue;
|
|
158
|
+
} else {
|
|
159
|
+
bodyData[originalName] = argValue;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let url = "".concat(endpoint.baseUrl).concat(endpoint.path);
|
|
164
|
+
for (const [key, value] of Object.entries(pathParams)) {
|
|
165
|
+
url = url.replace("{".concat(key, "}"), value);
|
|
166
|
+
}
|
|
167
|
+
const urlParts = url.split("?");
|
|
168
|
+
if (urlParts.length > 1) {
|
|
169
|
+
const pathQueryParams = new URLSearchParams(urlParts[1]);
|
|
170
|
+
for (const [key, value] of pathQueryParams.entries()) {
|
|
171
|
+
queryParams.append(key, value);
|
|
172
|
+
}
|
|
173
|
+
url = urlParts[0];
|
|
174
|
+
}
|
|
175
|
+
const queryString = queryParams.toString();
|
|
176
|
+
if (queryString) {
|
|
177
|
+
url += "?".concat(queryString);
|
|
178
|
+
}
|
|
179
|
+
return { url, headers, body, bodyData };
|
|
180
|
+
}
|
|
181
|
+
function prepareRequestBody(requestBody, body, bodyData, headers) {
|
|
182
|
+
const finalData = body !== void 0 ? body : Object.keys(bodyData).length > 0 ? bodyData : void 0;
|
|
183
|
+
if (requestBody && "content" in requestBody) {
|
|
184
|
+
const content = requestBody.content;
|
|
185
|
+
for (const [mimeType, _mediaTypeObject] of Object.entries(content)) {
|
|
186
|
+
if (finalData !== void 0) {
|
|
187
|
+
if (mimeType === "application/json" || mimeType.endsWith("+json")) {
|
|
188
|
+
headers["Content-Type"] = mimeType;
|
|
189
|
+
return typeof finalData === "string" ? finalData : JSON.stringify(finalData);
|
|
190
|
+
} else if (mimeType === "application/x-www-form-urlencoded") {
|
|
191
|
+
return new URLSearchParams(finalData);
|
|
192
|
+
} else if (mimeType === "multipart/form-data") {
|
|
193
|
+
const formData = new FormData();
|
|
194
|
+
if (typeof finalData === "object" && finalData !== null) {
|
|
195
|
+
for (const [key, value] of Object.entries(finalData)) {
|
|
196
|
+
formData.append(key, String(value));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return formData;
|
|
200
|
+
} else if (mimeType === "text/plain") {
|
|
201
|
+
headers["Content-Type"] = mimeType;
|
|
202
|
+
return String(finalData);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
} else if (finalData !== void 0) {
|
|
208
|
+
headers["Content-Type"] = "application/json";
|
|
209
|
+
return typeof finalData === "string" ? finalData : JSON.stringify(finalData);
|
|
210
|
+
}
|
|
211
|
+
return void 0;
|
|
212
|
+
}
|
|
213
|
+
function createRestApiTool(parsed, options = {}) {
|
|
214
|
+
return new RestApiTool(
|
|
215
|
+
parsed.name,
|
|
216
|
+
parsed.description,
|
|
217
|
+
parsed.endpoint,
|
|
218
|
+
parsed.operation,
|
|
219
|
+
parsed.authScheme,
|
|
220
|
+
void 0,
|
|
221
|
+
options
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
RestApiTool,
|
|
226
|
+
createRestApiTool,
|
|
227
|
+
prepareRequestBody,
|
|
228
|
+
prepareRequestParams
|
|
229
|
+
};
|
|
@@ -51,7 +51,10 @@ let LoadSkillResourceTool = class extends BaseTool {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
async runAsync({
|
|
54
|
+
async runAsync({
|
|
55
|
+
args,
|
|
56
|
+
toolContext
|
|
57
|
+
}) {
|
|
55
58
|
var _a, _b, _c;
|
|
56
59
|
const skillName = args["skill_name"];
|
|
57
60
|
let resourcePath = args["path"];
|
|
@@ -68,7 +71,18 @@ let LoadSkillResourceTool = class extends BaseTool {
|
|
|
68
71
|
};
|
|
69
72
|
}
|
|
70
73
|
resourcePath = path.posix.normalize(resourcePath);
|
|
71
|
-
|
|
74
|
+
let skill;
|
|
75
|
+
try {
|
|
76
|
+
skill = await this.toolset.getOrFetchSkill(
|
|
77
|
+
skillName,
|
|
78
|
+
toolContext.invocationId
|
|
79
|
+
);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
return {
|
|
82
|
+
error: "Failed to fetch skill '".concat(skillName, "' from registry: ").concat(e.message || e),
|
|
83
|
+
error_code: "REGISTRY_ERROR"
|
|
84
|
+
};
|
|
85
|
+
}
|
|
72
86
|
if (!skill) {
|
|
73
87
|
return {
|
|
74
88
|
error: "Skill '".concat(skillName, "' not found."),
|
|
@@ -131,7 +145,15 @@ let LoadSkillResourceTool = class extends BaseTool {
|
|
|
131
145
|
if (response["status"] === BINARY_FILE_DETECTED_MSG) {
|
|
132
146
|
const skillName = response["skill_name"];
|
|
133
147
|
const resourcePath = response["path"];
|
|
134
|
-
|
|
148
|
+
let skill;
|
|
149
|
+
try {
|
|
150
|
+
skill = await this.toolset.getOrFetchSkill(
|
|
151
|
+
skillName,
|
|
152
|
+
request.toolContext.invocationId
|
|
153
|
+
);
|
|
154
|
+
} catch (_e) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
135
157
|
if (!skill) continue;
|
|
136
158
|
const skillResources = skill.resources || {};
|
|
137
159
|
let content;
|
|
@@ -53,7 +53,18 @@ let LoadSkillTool = class extends BaseTool {
|
|
|
53
53
|
error_code: "MISSING_SKILL_NAME"
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
let skill;
|
|
57
|
+
try {
|
|
58
|
+
skill = await this.toolset.getOrFetchSkill(
|
|
59
|
+
skillName,
|
|
60
|
+
toolContext.invocationId
|
|
61
|
+
);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
return {
|
|
64
|
+
error: "Failed to fetch skill '".concat(skillName, "' from registry: ").concat(e.message || e),
|
|
65
|
+
error_code: "REGISTRY_ERROR"
|
|
66
|
+
};
|
|
67
|
+
}
|
|
57
68
|
if (!skill) {
|
|
58
69
|
return {
|
|
59
70
|
error: "Skill '".concat(skillName, "' not found."),
|
|
@@ -80,7 +80,18 @@ let RunSkillScriptTool = class extends BaseTool {
|
|
|
80
80
|
errorCode: "MISSING_SCRIPT_PATH"
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
let skill;
|
|
84
|
+
try {
|
|
85
|
+
skill = await this.toolset.getOrFetchSkill(
|
|
86
|
+
skillName,
|
|
87
|
+
toolContext.invocationId
|
|
88
|
+
);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
return {
|
|
91
|
+
error: "Failed to fetch skill '".concat(skillName, "' from registry: ").concat(e.message || e),
|
|
92
|
+
errorCode: "REGISTRY_ERROR"
|
|
93
|
+
};
|
|
94
|
+
}
|
|
84
95
|
if (!skill) {
|
|
85
96
|
return {
|
|
86
97
|
error: "Skill '".concat(skillName, "' not found."),
|
|
@@ -0,0 +1,82 @@
|
|
|
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 { Type } from "@google/genai";
|
|
19
|
+
import { experimental } from "../../utils/experimental.js";
|
|
20
|
+
import { logger } from "../../utils/logger.js";
|
|
21
|
+
import { BaseTool } from "../base_tool.js";
|
|
22
|
+
let SearchSkillsTool = class extends BaseTool {
|
|
23
|
+
constructor(toolset) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
if (!toolset.registry) {
|
|
26
|
+
throw new Error("SearchSkillsTool requires a configured skill registry.");
|
|
27
|
+
}
|
|
28
|
+
super({
|
|
29
|
+
name: "search_skills",
|
|
30
|
+
description: ((_b = (_a = toolset.registry).searchToolDescription) == null ? void 0 : _b.call(_a)) || "Searches for relevant skills in the registry based on a semantic or keyword query."
|
|
31
|
+
});
|
|
32
|
+
this.toolset = toolset;
|
|
33
|
+
}
|
|
34
|
+
_getDeclaration() {
|
|
35
|
+
return {
|
|
36
|
+
name: this.name,
|
|
37
|
+
description: this.description,
|
|
38
|
+
parameters: {
|
|
39
|
+
type: Type.OBJECT,
|
|
40
|
+
properties: {
|
|
41
|
+
query: {
|
|
42
|
+
type: Type.STRING,
|
|
43
|
+
description: "Semantic or keyword search query."
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
required: ["query"]
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async runAsync({ args }) {
|
|
51
|
+
const query = args["query"];
|
|
52
|
+
if (!query) {
|
|
53
|
+
return {
|
|
54
|
+
error: "Argument 'query' is required.",
|
|
55
|
+
error_code: "INVALID_ARGUMENTS"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const results = await this.toolset.registry.searchSkills(query);
|
|
60
|
+
return results.filter((r) => {
|
|
61
|
+
if (this.toolset.skills[r.name]) {
|
|
62
|
+
logger.warn(
|
|
63
|
+
"Skill naming conflict: skill '".concat(r.name, "' already exists locally. Registry skill is filtered.")
|
|
64
|
+
);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
});
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return {
|
|
71
|
+
error: "Failed to search skills from registry: ".concat(e.message || e),
|
|
72
|
+
error_code: "REGISTRY_ERROR"
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
SearchSkillsTool = __decorateClass([
|
|
78
|
+
experimental
|
|
79
|
+
], SearchSkillsTool);
|
|
80
|
+
export {
|
|
81
|
+
SearchSkillsTool
|
|
82
|
+
};
|
|
@@ -18,6 +18,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
18
18
|
import { appendInstructions } from "../../models/llm_request.js";
|
|
19
19
|
import { formatSkillsAsXml } from "../../skills/prompt.js";
|
|
20
20
|
import { experimental } from "../../utils/experimental.js";
|
|
21
|
+
import { logger } from "../../utils/logger.js";
|
|
21
22
|
import { BaseTool } from "../base_tool.js";
|
|
22
23
|
import { BaseToolset } from "../base_toolset.js";
|
|
23
24
|
import { ListSkillsTool } from "./list_skills_tool.js";
|
|
@@ -25,14 +26,17 @@ import { LoadSkillResourceTool } from "./load_skill_resource_tool.js";
|
|
|
25
26
|
import { LoadSkillTool } from "./load_skill_tool.js";
|
|
26
27
|
import { RunSkillInlineScriptTool } from "./run_skill_inline_script_tool.js";
|
|
27
28
|
import { RunSkillScriptTool } from "./run_skill_script_tool.js";
|
|
29
|
+
import { SearchSkillsTool } from "./search_skills_tool.js";
|
|
28
30
|
const DEFAULT_SKILL_SYSTEM_INSTRUCTION = "You can use specialized 'skills' to help you with complex tasks. You MUST use the skill tools to interact with these skills.\n\nSkills are folders of instructions and resources that extend your capabilities for specialized tasks. Each skill folder contains:\n- **SKILL.md** (required): The main instruction file with skill metadata and detailed markdown instructions.\n- **references/** (Optional): Additional documentation or examples for skill usage.\n- **assets/** (Optional): Templates, scripts or other resources used by the skill.\n- **scripts/** (Optional): Executable scripts that can be run via bash.\n\nThis is very important:\n\n1. If a skill seems relevant to the current user query, you MUST use the `load_skill` tool with `name=\"<SKILL_NAME>\"` to read its full instructions before proceeding.\n2. Once you have read the instructions, follow them exactly as documented before replying to the user. For example, If the instruction lists multiple steps, please make sure you complete all of them in order.\n3. The `load_skill_resource` tool is for viewing files within a skill's directory (e.g., `references/*`, `assets/*`, `scripts/*`). Do NOT use other tools to access these files.\n4. Use `run_skill_script` to run scripts from a skill's `scripts/` directory. Use `load_skill_resource` to view script content first if needed.\n";
|
|
29
31
|
let SkillToolset = class extends BaseToolset {
|
|
30
32
|
constructor(skills, options = {}) {
|
|
31
33
|
super([], "adk_skill_toolset");
|
|
32
34
|
this.toolCache = /* @__PURE__ */ new Map();
|
|
35
|
+
this.fetchedSkillCache = /* @__PURE__ */ new Map();
|
|
33
36
|
this.skills = Array.isArray(skills) ? Object.fromEntries(skills.map((s) => [s.frontmatter.name, s])) : skills;
|
|
34
37
|
this.codeExecutor = options.codeExecutor;
|
|
35
38
|
this.additionalTools = options.additionalTools || [];
|
|
39
|
+
this.registry = options.registry;
|
|
36
40
|
this.tools = [
|
|
37
41
|
new ListSkillsTool(this),
|
|
38
42
|
new LoadSkillTool(this),
|
|
@@ -40,24 +44,55 @@ let SkillToolset = class extends BaseToolset {
|
|
|
40
44
|
new RunSkillScriptTool(this),
|
|
41
45
|
new RunSkillInlineScriptTool(this)
|
|
42
46
|
];
|
|
47
|
+
if (this.registry) {
|
|
48
|
+
this.tools.push(new SearchSkillsTool(this));
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
async getTools(context) {
|
|
45
52
|
const dynamicTools = await this.resolveAdditionalTools(context);
|
|
46
53
|
return [...this.tools, ...dynamicTools];
|
|
47
54
|
}
|
|
48
55
|
async close() {
|
|
56
|
+
this.fetchedSkillCache.clear();
|
|
49
57
|
}
|
|
50
58
|
getSkill(name) {
|
|
51
59
|
return this.skills[name];
|
|
52
60
|
}
|
|
61
|
+
async getOrFetchSkill(name, invocationId) {
|
|
62
|
+
if (this.skills[name]) {
|
|
63
|
+
return this.skills[name];
|
|
64
|
+
}
|
|
65
|
+
if (!this.registry) {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
const contextKey = invocationId || "default";
|
|
69
|
+
if (!this.fetchedSkillCache.has(contextKey)) {
|
|
70
|
+
this.fetchedSkillCache.set(contextKey, /* @__PURE__ */ new Map());
|
|
71
|
+
}
|
|
72
|
+
const cache = this.fetchedSkillCache.get(contextKey);
|
|
73
|
+
if (cache.has(name)) {
|
|
74
|
+
return cache.get(name);
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const skill = await this.registry.getSkill(name);
|
|
78
|
+
cache.set(name, skill);
|
|
79
|
+
return skill;
|
|
80
|
+
} catch (e) {
|
|
81
|
+
logger.warn("Failed to fetch skill '".concat(name, "' from registry: ").concat(e));
|
|
82
|
+
throw e;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
53
85
|
async processLlmRequest(toolContext, llmRequest) {
|
|
54
86
|
await super.processLlmRequest(toolContext, llmRequest);
|
|
55
87
|
const skills = Object.values(this.skills);
|
|
56
88
|
const skillsXml = formatSkillsAsXml(skills);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
89
|
+
const instructions = [DEFAULT_SKILL_SYSTEM_INSTRUCTION, skillsXml];
|
|
90
|
+
if (this.registry) {
|
|
91
|
+
instructions.push(
|
|
92
|
+
"\nIf the locally available skills are not sufficient to complete your task, you can use the `search_skills` tool to discover additional skills from the registry."
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
appendInstructions(llmRequest, instructions);
|
|
61
96
|
}
|
|
62
97
|
async resolveAdditionalTools(context) {
|
|
63
98
|
if (!context) return [];
|
|
@@ -71,7 +106,7 @@ let SkillToolset = class extends BaseToolset {
|
|
|
71
106
|
}
|
|
72
107
|
const additionalToolNames = /* @__PURE__ */ new Set();
|
|
73
108
|
for (const skillName of activatedSkills) {
|
|
74
|
-
const skill = this.
|
|
109
|
+
const skill = await this.getOrFetchSkill(skillName, context.invocationId);
|
|
75
110
|
if (skill && skill.frontmatter.metadata) {
|
|
76
111
|
const tools = skill.frontmatter.metadata["adk_additional_tools"];
|
|
77
112
|
if (tools) {
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
class AsyncQueue {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.queue = [];
|
|
11
|
+
this.resolvers = [];
|
|
12
|
+
this.closed = false;
|
|
13
|
+
}
|
|
14
|
+
push(value) {
|
|
15
|
+
if (this.closed) return;
|
|
16
|
+
if (this.resolvers.length > 0) {
|
|
17
|
+
const { resolve } = this.resolvers.shift();
|
|
18
|
+
resolve({ value, done: false });
|
|
19
|
+
} else {
|
|
20
|
+
this.queue.push(value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
error(err) {
|
|
24
|
+
this.errorVal = err;
|
|
25
|
+
while (this.resolvers.length > 0) {
|
|
26
|
+
const { reject } = this.resolvers.shift();
|
|
27
|
+
reject(err);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
close() {
|
|
31
|
+
this.closed = true;
|
|
32
|
+
while (this.resolvers.length > 0) {
|
|
33
|
+
const { resolve } = this.resolvers.shift();
|
|
34
|
+
resolve({ value: void 0, done: true });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
[Symbol.asyncIterator]() {
|
|
38
|
+
return {
|
|
39
|
+
next: () => {
|
|
40
|
+
if (this.errorVal) {
|
|
41
|
+
const err = this.errorVal;
|
|
42
|
+
this.errorVal = void 0;
|
|
43
|
+
return Promise.reject(err);
|
|
44
|
+
}
|
|
45
|
+
if (this.queue.length > 0) {
|
|
46
|
+
return Promise.resolve({ value: this.queue.shift(), done: false });
|
|
47
|
+
}
|
|
48
|
+
if (this.closed) {
|
|
49
|
+
return Promise.resolve({ value: void 0, done: true });
|
|
50
|
+
}
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
this.resolvers.push({ resolve, reject });
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
AsyncQueue
|
|
60
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
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 camelCaseKeys(val) {
|
|
9
|
+
if (Array.isArray(val)) {
|
|
10
|
+
return val.map(camelCaseKeys);
|
|
11
|
+
}
|
|
12
|
+
if (val !== null && typeof val === "object" && val.constructor === Object) {
|
|
13
|
+
const obj = val;
|
|
14
|
+
const newObj = {};
|
|
15
|
+
for (const key of Object.keys(obj)) {
|
|
16
|
+
const camelKey = key.replace(/_([a-z])/g, (_, g) => g.toUpperCase());
|
|
17
|
+
newObj[camelKey] = camelCaseKeys(obj[key]);
|
|
18
|
+
}
|
|
19
|
+
return newObj;
|
|
20
|
+
}
|
|
21
|
+
return val;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
camelCaseKeys
|
|
25
|
+
};
|
|
@@ -10,6 +10,10 @@ function isBrowser() {
|
|
|
10
10
|
}
|
|
11
11
|
const UUID_MASK = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
|
12
12
|
function randomUUID() {
|
|
13
|
+
var _a;
|
|
14
|
+
if ((_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) {
|
|
15
|
+
return globalThis.crypto.randomUUID();
|
|
16
|
+
}
|
|
13
17
|
let uuid = "";
|
|
14
18
|
for (let i = 0; i < UUID_MASK.length; i++) {
|
|
15
19
|
const randomValue = Math.random() * 16 | 0;
|