@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.
Files changed (190) hide show
  1. package/dist/cjs/agents/base_agent.js +19 -1
  2. package/dist/cjs/agents/instructions.js +81 -33
  3. package/dist/cjs/agents/invocation_context.js +0 -1
  4. package/dist/cjs/agents/llm_agent.js +52 -5
  5. package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  6. package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
  7. package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
  8. package/dist/cjs/agents/processors/content_request_processor.js +7 -0
  9. package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
  10. package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
  11. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
  12. package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  13. package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
  14. package/dist/cjs/auth/auth_preprocessor.js +12 -10
  15. package/dist/cjs/auth/oauth2/oauth2_discovery.js +1 -1
  16. package/dist/cjs/code_executors/code_executor_context.js +7 -7
  17. package/dist/cjs/common.js +39 -0
  18. package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
  19. package/dist/cjs/context/token_based_context_compactor.js +1 -1
  20. package/dist/cjs/events/event.js +1 -1
  21. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  22. package/dist/cjs/models/gemini_llm_connection.js +62 -19
  23. package/dist/cjs/models/google_llm.js +26 -8
  24. package/dist/cjs/plugins/security_plugin.js +16 -0
  25. package/dist/cjs/sessions/base_session_service.js +13 -2
  26. package/dist/cjs/sessions/database_session_service.js +2 -2
  27. package/dist/cjs/sessions/db/schema.js +45 -10
  28. package/dist/cjs/sessions/in_memory_session_service.js +2 -1
  29. package/dist/cjs/sessions/vertex_ai_session_service.js +2 -1
  30. package/dist/cjs/skills/gcp_skill_registry.js +104 -0
  31. package/dist/cjs/skills/loader.js +65 -0
  32. package/dist/cjs/skills/skill_registry.js +27 -0
  33. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
  34. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
  35. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +127 -0
  36. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
  37. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
  38. package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
  39. package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
  40. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
  41. package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
  42. package/dist/cjs/tools/skill/skill_toolset.js +40 -5
  43. package/dist/cjs/utils/async_queue.js +88 -0
  44. package/dist/cjs/utils/case_utils.js +53 -0
  45. package/dist/cjs/utils/env_aware_utils.js +4 -0
  46. package/dist/cjs/utils/live_connection_utils.js +284 -0
  47. package/dist/cjs/utils/model_name.js +9 -0
  48. package/dist/cjs/utils/streaming_utils.js +9 -8
  49. package/dist/cjs/version.js +1 -1
  50. package/dist/esm/agents/base_agent.js +19 -1
  51. package/dist/esm/agents/instructions.js +81 -33
  52. package/dist/esm/agents/invocation_context.js +0 -1
  53. package/dist/esm/agents/llm_agent.js +53 -5
  54. package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  55. package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
  56. package/dist/esm/agents/processors/content_processor_utils.js +35 -23
  57. package/dist/esm/agents/processors/content_request_processor.js +7 -0
  58. package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
  59. package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
  60. package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
  61. package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  62. package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
  63. package/dist/esm/auth/auth_preprocessor.js +12 -10
  64. package/dist/esm/auth/oauth2/oauth2_discovery.js +1 -1
  65. package/dist/esm/code_executors/code_executor_context.js +7 -7
  66. package/dist/esm/common.js +33 -1
  67. package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
  68. package/dist/esm/context/token_based_context_compactor.js +1 -1
  69. package/dist/esm/events/event.js +1 -1
  70. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  71. package/dist/esm/models/gemini_llm_connection.js +62 -19
  72. package/dist/esm/models/google_llm.js +26 -8
  73. package/dist/esm/plugins/security_plugin.js +16 -0
  74. package/dist/esm/sessions/base_session_service.js +11 -1
  75. package/dist/esm/sessions/database_session_service.js +2 -2
  76. package/dist/esm/sessions/db/schema.js +44 -10
  77. package/dist/esm/sessions/in_memory_session_service.js +4 -2
  78. package/dist/esm/sessions/vertex_ai_session_service.js +4 -2
  79. package/dist/esm/skills/gcp_skill_registry.js +78 -0
  80. package/dist/esm/skills/loader.js +64 -0
  81. package/dist/esm/skills/skill_registry.js +7 -0
  82. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
  83. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  84. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  85. package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
  86. package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
  87. package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
  88. package/dist/esm/tools/skill/load_skill_tool.js +12 -1
  89. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
  90. package/dist/esm/tools/skill/search_skills_tool.js +82 -0
  91. package/dist/esm/tools/skill/skill_toolset.js +40 -5
  92. package/dist/esm/utils/async_queue.js +60 -0
  93. package/dist/esm/utils/case_utils.js +25 -0
  94. package/dist/esm/utils/env_aware_utils.js +4 -0
  95. package/dist/esm/utils/live_connection_utils.js +256 -0
  96. package/dist/esm/utils/model_name.js +8 -0
  97. package/dist/esm/utils/streaming_utils.js +9 -8
  98. package/dist/esm/version.js +1 -1
  99. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
  100. package/dist/types/a2a/event_converter_utils.d.ts +14 -1
  101. package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
  102. package/dist/types/a2a/part_converter_utils.d.ts +51 -6
  103. package/dist/types/agents/invocation_context.d.ts +0 -9
  104. package/dist/types/agents/llm_agent.d.ts +14 -0
  105. package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
  106. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
  107. package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
  108. package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
  109. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
  110. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
  111. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
  112. package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
  113. package/dist/types/common.d.ts +15 -1
  114. package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
  115. package/dist/types/events/event_actions.d.ts +1 -2
  116. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
  117. package/dist/types/models/base_llm_connection.d.ts +10 -0
  118. package/dist/types/models/gemini_llm_connection.d.ts +15 -4
  119. package/dist/types/models/llm_response.d.ts +10 -1
  120. package/dist/types/plugins/security_plugin.d.ts +30 -0
  121. package/dist/types/sessions/base_session_service.d.ts +4 -0
  122. package/dist/types/sessions/db/schema.d.ts +1 -0
  123. package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
  124. package/dist/types/skills/loader.d.ts +7 -0
  125. package/dist/types/skills/skill.d.ts +1 -1
  126. package/dist/types/skills/skill_registry.d.ts +29 -0
  127. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
  128. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
  129. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
  130. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
  131. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
  132. package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
  133. package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
  134. package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
  135. package/dist/types/utils/async_queue.d.ts +18 -0
  136. package/dist/types/utils/case_utils.d.ts +12 -0
  137. package/dist/types/utils/live_connection_utils.d.ts +30 -0
  138. package/dist/types/utils/model_name.d.ts +7 -0
  139. package/dist/types/utils/streaming_utils.d.ts +0 -1
  140. package/dist/types/version.d.ts +1 -1
  141. package/dist/web/agents/base_agent.js +31 -1
  142. package/dist/web/agents/instructions.js +81 -33
  143. package/dist/web/agents/invocation_context.js +0 -1
  144. package/dist/web/agents/llm_agent.js +53 -5
  145. package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  146. package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
  147. package/dist/web/agents/processors/content_processor_utils.js +53 -23
  148. package/dist/web/agents/processors/content_request_processor.js +7 -0
  149. package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
  150. package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
  151. package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
  152. package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  153. package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
  154. package/dist/web/auth/auth_preprocessor.js +12 -10
  155. package/dist/web/auth/oauth2/oauth2_discovery.js +1 -1
  156. package/dist/web/code_executors/code_executor_context.js +7 -7
  157. package/dist/web/common.js +33 -1
  158. package/dist/web/context/summarizers/llm_summarizer.js +11 -0
  159. package/dist/web/context/token_based_context_compactor.js +1 -1
  160. package/dist/web/events/event.js +1 -1
  161. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  162. package/dist/web/models/gemini_llm_connection.js +75 -19
  163. package/dist/web/models/google_llm.js +26 -8
  164. package/dist/web/plugins/security_plugin.js +16 -0
  165. package/dist/web/sessions/base_session_service.js +11 -1
  166. package/dist/web/sessions/database_session_service.js +2 -2
  167. package/dist/web/sessions/db/schema.js +44 -10
  168. package/dist/web/sessions/in_memory_session_service.js +4 -2
  169. package/dist/web/sessions/vertex_ai_session_service.js +4 -2
  170. package/dist/web/skills/gcp_skill_registry.js +78 -0
  171. package/dist/web/skills/loader.js +64 -0
  172. package/dist/web/skills/skill_registry.js +7 -0
  173. package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
  174. package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  175. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  176. package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
  177. package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
  178. package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
  179. package/dist/web/tools/skill/load_skill_tool.js +12 -1
  180. package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
  181. package/dist/web/tools/skill/search_skills_tool.js +82 -0
  182. package/dist/web/tools/skill/skill_toolset.js +40 -5
  183. package/dist/web/utils/async_queue.js +60 -0
  184. package/dist/web/utils/case_utils.js +25 -0
  185. package/dist/web/utils/env_aware_utils.js +4 -0
  186. package/dist/web/utils/live_connection_utils.js +254 -0
  187. package/dist/web/utils/model_name.js +8 -0
  188. package/dist/web/utils/streaming_utils.js +9 -8
  189. package/dist/web/version.js +1 -1
  190. 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: ${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 = `${endpoint.baseUrl}${endpoint.path}`;
164
+ for (const [key, value] of Object.entries(pathParams)) {
165
+ url = url.replace(`{${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 += `?${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({ args }) {
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
- const skill = this.toolset.getSkill(skillName);
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 '${skillName}' from registry: ${e.message || e}`,
83
+ error_code: "REGISTRY_ERROR"
84
+ };
85
+ }
72
86
  if (!skill) {
73
87
  return {
74
88
  error: `Skill '${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
- const skill = this.toolset.getSkill(skillName);
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
- const skill = this.toolset.getSkill(skillName);
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 '${skillName}' from registry: ${e.message || e}`,
65
+ error_code: "REGISTRY_ERROR"
66
+ };
67
+ }
57
68
  if (!skill) {
58
69
  return {
59
70
  error: `Skill '${skillName}' not found.`,
@@ -80,7 +80,18 @@ let RunSkillScriptTool = class extends BaseTool {
80
80
  errorCode: "MISSING_SCRIPT_PATH"
81
81
  };
82
82
  }
83
- const skill = this.toolset.getSkill(skillName);
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 '${skillName}' from registry: ${e.message || e}`,
92
+ errorCode: "REGISTRY_ERROR"
93
+ };
94
+ }
84
95
  if (!skill) {
85
96
  return {
86
97
  error: `Skill '${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 '${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: ${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,6 +26,7 @@ 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.
29
31
 
30
32
  Skills are folders of instructions and resources that extend your capabilities for specialized tasks. Each skill folder contains:
@@ -44,9 +46,11 @@ let SkillToolset = class extends BaseToolset {
44
46
  constructor(skills, options = {}) {
45
47
  super([], "adk_skill_toolset");
46
48
  this.toolCache = /* @__PURE__ */ new Map();
49
+ this.fetchedSkillCache = /* @__PURE__ */ new Map();
47
50
  this.skills = Array.isArray(skills) ? Object.fromEntries(skills.map((s) => [s.frontmatter.name, s])) : skills;
48
51
  this.codeExecutor = options.codeExecutor;
49
52
  this.additionalTools = options.additionalTools || [];
53
+ this.registry = options.registry;
50
54
  this.tools = [
51
55
  new ListSkillsTool(this),
52
56
  new LoadSkillTool(this),
@@ -54,24 +58,55 @@ let SkillToolset = class extends BaseToolset {
54
58
  new RunSkillScriptTool(this),
55
59
  new RunSkillInlineScriptTool(this)
56
60
  ];
61
+ if (this.registry) {
62
+ this.tools.push(new SearchSkillsTool(this));
63
+ }
57
64
  }
58
65
  async getTools(context) {
59
66
  const dynamicTools = await this.resolveAdditionalTools(context);
60
67
  return [...this.tools, ...dynamicTools];
61
68
  }
62
69
  async close() {
70
+ this.fetchedSkillCache.clear();
63
71
  }
64
72
  getSkill(name) {
65
73
  return this.skills[name];
66
74
  }
75
+ async getOrFetchSkill(name, invocationId) {
76
+ if (this.skills[name]) {
77
+ return this.skills[name];
78
+ }
79
+ if (!this.registry) {
80
+ return void 0;
81
+ }
82
+ const contextKey = invocationId || "default";
83
+ if (!this.fetchedSkillCache.has(contextKey)) {
84
+ this.fetchedSkillCache.set(contextKey, /* @__PURE__ */ new Map());
85
+ }
86
+ const cache = this.fetchedSkillCache.get(contextKey);
87
+ if (cache.has(name)) {
88
+ return cache.get(name);
89
+ }
90
+ try {
91
+ const skill = await this.registry.getSkill(name);
92
+ cache.set(name, skill);
93
+ return skill;
94
+ } catch (e) {
95
+ logger.warn(`Failed to fetch skill '${name}' from registry: ${e}`);
96
+ throw e;
97
+ }
98
+ }
67
99
  async processLlmRequest(toolContext, llmRequest) {
68
100
  await super.processLlmRequest(toolContext, llmRequest);
69
101
  const skills = Object.values(this.skills);
70
102
  const skillsXml = formatSkillsAsXml(skills);
71
- appendInstructions(llmRequest, [
72
- DEFAULT_SKILL_SYSTEM_INSTRUCTION,
73
- skillsXml
74
- ]);
103
+ const instructions = [DEFAULT_SKILL_SYSTEM_INSTRUCTION, skillsXml];
104
+ if (this.registry) {
105
+ instructions.push(
106
+ "\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."
107
+ );
108
+ }
109
+ appendInstructions(llmRequest, instructions);
75
110
  }
76
111
  async resolveAdditionalTools(context) {
77
112
  if (!context) return [];
@@ -85,7 +120,7 @@ let SkillToolset = class extends BaseToolset {
85
120
  }
86
121
  const additionalToolNames = /* @__PURE__ */ new Set();
87
122
  for (const skillName of activatedSkills) {
88
- const skill = this.skills[skillName];
123
+ const skill = await this.getOrFetchSkill(skillName, context.invocationId);
89
124
  if (skill && skill.frontmatter.metadata) {
90
125
  const tools = skill.frontmatter.metadata["adk_additional_tools"];
91
126
  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;