@google/adk 2.2.1 → 2.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 (226) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +4 -1
  2. package/dist/cjs/a2a/agent_card.js +102 -26
  3. package/dist/cjs/a2a/agent_to_a2a.js +1 -1
  4. package/dist/cjs/agents/functions.js +199 -25
  5. package/dist/cjs/agents/instructions.js +4 -1
  6. package/dist/cjs/agents/invocation_context.js +26 -4
  7. package/dist/cjs/agents/langgraph_agent.js +152 -0
  8. package/dist/cjs/agents/llm_agent.js +175 -101
  9. package/dist/cjs/agents/processors/code_execution_request_processor.js +10 -6
  10. package/dist/cjs/agents/remote_agent.js +187 -0
  11. package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
  12. package/dist/cjs/auth/auth_handler.js +37 -5
  13. package/dist/cjs/auth/auth_schemes.js +9 -0
  14. package/dist/cjs/cli/cli_eval.js +532 -0
  15. package/dist/cjs/cli/utils/envs.js +116 -0
  16. package/dist/cjs/cli/utils/evals.js +137 -0
  17. package/dist/cjs/cli/utils/logs.js +150 -0
  18. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  19. package/dist/cjs/code_executors/code_execution_utils.js +48 -16
  20. package/dist/cjs/code_executors/code_executor_context.js +6 -2
  21. package/dist/cjs/common.js +72 -0
  22. package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
  23. package/dist/cjs/context/token_based_context_compactor.js +2 -1
  24. package/dist/cjs/events/event.js +4 -2
  25. package/dist/cjs/examples/example_util.js +23 -2
  26. package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
  27. package/dist/cjs/index.js +97 -1
  28. package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
  29. package/dist/cjs/models/gemini_llm_connection.js +16 -8
  30. package/dist/cjs/models/google_llm.js +13 -16
  31. package/dist/cjs/models/llm_response.js +9 -1
  32. package/dist/cjs/models/registry.js +1 -1
  33. package/dist/cjs/models/routed_llm.js +9 -8
  34. package/dist/cjs/planners/plan_re_act_planner.js +1 -1
  35. package/dist/cjs/runner/in_memory_runner.js +6 -11
  36. package/dist/cjs/runner/runner.js +105 -33
  37. package/dist/cjs/sessions/db/operations.js +1 -1
  38. package/dist/cjs/sessions/in_memory_session_service.js +3 -1
  39. package/dist/cjs/sessions/state.js +8 -4
  40. package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
  41. package/dist/cjs/telemetry/tracing.js +97 -66
  42. package/dist/cjs/tools/agent_tool.js +44 -0
  43. package/dist/cjs/tools/apihub_tool/apihub_toolset.js +142 -0
  44. package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
  45. package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
  46. package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
  47. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +185 -0
  48. package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
  49. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +603 -0
  50. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +219 -0
  51. package/dist/cjs/tools/crewai_tool.js +132 -0
  52. package/dist/cjs/tools/example_tool.js +10 -0
  53. package/dist/cjs/tools/function_tool.js +319 -0
  54. package/dist/cjs/tools/google_api_tool/google_api_tool.js +97 -0
  55. package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +226 -0
  56. package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +58 -0
  57. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
  58. package/dist/cjs/tools/google_api_tool/index.js +64 -0
  59. package/dist/cjs/tools/langchain_tool.js +172 -0
  60. package/dist/cjs/tools/mcp/index.js +12 -0
  61. package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
  62. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
  63. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
  64. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
  65. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  66. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
  67. package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
  68. package/dist/cjs/tools/toolbox_tool.js +108 -0
  69. package/dist/cjs/utils/env_aware_utils.js +6 -8
  70. package/dist/cjs/utils/error_utils.js +11 -11
  71. package/dist/cjs/utils/file_extension_utils.js +11 -0
  72. package/dist/cjs/utils/file_utils.js +2 -24
  73. package/dist/cjs/utils/gemini_schema_util.js +4 -1
  74. package/dist/cjs/utils/json_utils.js +49 -0
  75. package/dist/cjs/utils/live_connection_utils.js +4 -5
  76. package/dist/cjs/utils/logger_node.js +7 -1
  77. package/dist/cjs/utils/object_notation_utils.js +6 -3
  78. package/dist/cjs/utils/streaming_utils.js +12 -12
  79. package/dist/cjs/version.js +1 -1
  80. package/dist/esm/a2a/a2a_remote_agent.js +4 -1
  81. package/dist/esm/a2a/agent_card.js +103 -27
  82. package/dist/esm/a2a/agent_to_a2a.js +5 -2
  83. package/dist/esm/agents/functions.js +198 -25
  84. package/dist/esm/agents/instructions.js +4 -1
  85. package/dist/esm/agents/invocation_context.js +24 -4
  86. package/dist/esm/agents/langgraph_agent.js +123 -0
  87. package/dist/esm/agents/llm_agent.js +185 -104
  88. package/dist/esm/agents/processors/code_execution_request_processor.js +13 -8
  89. package/dist/esm/agents/remote_agent.js +164 -0
  90. package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
  91. package/dist/esm/auth/auth_handler.js +37 -5
  92. package/dist/esm/auth/auth_schemes.js +8 -0
  93. package/dist/esm/cli/cli_eval.js +510 -0
  94. package/dist/esm/cli/utils/envs.js +78 -0
  95. package/dist/esm/cli/utils/evals.js +109 -0
  96. package/dist/esm/cli/utils/logs.js +111 -0
  97. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  98. package/dist/esm/code_executors/code_execution_utils.js +46 -16
  99. package/dist/esm/code_executors/code_executor_context.js +5 -2
  100. package/dist/esm/common.js +67 -3
  101. package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
  102. package/dist/esm/context/token_based_context_compactor.js +2 -1
  103. package/dist/esm/events/event.js +4 -2
  104. package/dist/esm/examples/example_util.js +21 -1
  105. package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
  106. package/dist/esm/index.js +99 -1
  107. package/dist/esm/integrations/agent_registry/helpers.js +1 -1
  108. package/dist/esm/models/gemini_llm_connection.js +16 -8
  109. package/dist/esm/models/google_llm.js +14 -17
  110. package/dist/esm/models/llm_response.js +9 -1
  111. package/dist/esm/models/registry.js +1 -1
  112. package/dist/esm/models/routed_llm.js +9 -8
  113. package/dist/esm/planners/plan_re_act_planner.js +1 -1
  114. package/dist/esm/runner/in_memory_runner.js +6 -11
  115. package/dist/esm/runner/runner.js +105 -33
  116. package/dist/esm/sessions/db/operations.js +1 -1
  117. package/dist/esm/sessions/in_memory_session_service.js +3 -1
  118. package/dist/esm/sessions/state.js +8 -4
  119. package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
  120. package/dist/esm/telemetry/tracing.js +97 -66
  121. package/dist/esm/tools/agent_tool.js +44 -0
  122. package/dist/esm/tools/apihub_tool/apihub_toolset.js +106 -0
  123. package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
  124. package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
  125. package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
  126. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +163 -0
  127. package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
  128. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +561 -0
  129. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +215 -0
  130. package/dist/esm/tools/crewai_tool.js +107 -0
  131. package/dist/esm/tools/example_tool.js +13 -1
  132. package/dist/esm/tools/function_tool.js +316 -0
  133. package/dist/esm/tools/google_api_tool/google_api_tool.js +70 -0
  134. package/dist/esm/tools/google_api_tool/google_api_tool_set.js +188 -0
  135. package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +24 -0
  136. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
  137. package/dist/esm/tools/google_api_tool/index.js +33 -0
  138. package/dist/esm/tools/langchain_tool.js +148 -0
  139. package/dist/esm/tools/mcp/index.js +6 -0
  140. package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
  141. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
  142. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
  143. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
  144. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  145. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
  146. package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
  147. package/dist/esm/tools/toolbox_tool.js +80 -0
  148. package/dist/esm/utils/env_aware_utils.js +6 -8
  149. package/dist/esm/utils/error_utils.js +9 -10
  150. package/dist/esm/utils/file_extension_utils.js +11 -0
  151. package/dist/esm/utils/file_utils.js +2 -23
  152. package/dist/esm/utils/gemini_schema_util.js +4 -1
  153. package/dist/esm/utils/json_utils.js +21 -0
  154. package/dist/esm/utils/live_connection_utils.js +4 -5
  155. package/dist/esm/utils/logger_node.js +7 -1
  156. package/dist/esm/utils/object_notation_utils.js +4 -2
  157. package/dist/esm/utils/streaming_utils.js +11 -11
  158. package/dist/esm/version.js +1 -1
  159. package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
  160. package/dist/types/a2a/agent_card.d.ts +44 -1
  161. package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
  162. package/dist/types/a2a/index.d.ts +1 -0
  163. package/dist/types/agents/functions.d.ts +33 -1
  164. package/dist/types/agents/invocation_context.d.ts +20 -1
  165. package/dist/types/agents/langgraph_agent.d.ts +153 -0
  166. package/dist/types/agents/remote_agent.d.ts +68 -0
  167. package/dist/types/auth/auth_handler.d.ts +28 -1
  168. package/dist/types/auth/auth_schemes.d.ts +13 -0
  169. package/dist/types/cli/cli_eval.d.ts +173 -0
  170. package/dist/types/cli/utils/envs.d.ts +23 -0
  171. package/dist/types/cli/utils/evals.d.ts +47 -0
  172. package/dist/types/cli/utils/logs.d.ts +38 -0
  173. package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
  174. package/dist/types/code_executors/code_executor_context.d.ts +1 -0
  175. package/dist/types/common.d.ts +27 -4
  176. package/dist/types/events/event.d.ts +4 -0
  177. package/dist/types/examples/example_util.d.ts +17 -0
  178. package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
  179. package/dist/types/index.d.ts +16 -1
  180. package/dist/types/models/gemini_llm_connection.d.ts +6 -7
  181. package/dist/types/models/routed_llm.d.ts +1 -1
  182. package/dist/types/runner/in_memory_runner.d.ts +2 -1
  183. package/dist/types/runner/runner.d.ts +34 -0
  184. package/dist/types/sessions/state.d.ts +5 -1
  185. package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
  186. package/dist/types/skills/skill.d.ts +1 -1
  187. package/dist/types/telemetry/tracing.d.ts +4 -2
  188. package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +122 -0
  189. package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
  190. package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
  191. package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
  192. package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +86 -0
  193. package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
  194. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +215 -0
  195. package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
  196. package/dist/types/tools/crewai_tool.d.ts +85 -0
  197. package/dist/types/tools/example_tool.d.ts +10 -0
  198. package/dist/types/tools/function_tool.d.ts +32 -0
  199. package/dist/types/tools/google_api_tool/google_api_tool.d.ts +30 -0
  200. package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +78 -0
  201. package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +33 -0
  202. package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +164 -0
  203. package/dist/types/tools/google_api_tool/index.d.ts +11 -0
  204. package/dist/types/tools/langchain_tool.d.ts +103 -0
  205. package/dist/types/tools/mcp/index.d.ts +3 -0
  206. package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
  207. package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
  208. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
  209. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
  210. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
  211. package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
  212. package/dist/types/tools/toolbox_tool.d.ts +73 -0
  213. package/dist/types/utils/env_aware_utils.d.ts +18 -2
  214. package/dist/types/utils/error_utils.d.ts +7 -0
  215. package/dist/types/utils/file_utils.d.ts +6 -1
  216. package/dist/types/utils/gemini_schema_util.d.ts +1 -2
  217. package/dist/types/utils/json_utils.d.ts +11 -0
  218. package/dist/types/utils/object_notation_utils.d.ts +7 -0
  219. package/dist/types/utils/streaming_utils.d.ts +11 -4
  220. package/dist/types/version.d.ts +1 -1
  221. package/dist/web/index_web.js +102 -103
  222. package/dist/web/index_web.js.map +4 -4
  223. package/package.json +8 -3
  224. package/dist/cjs/models/gemini_continuation.js +0 -232
  225. package/dist/esm/models/gemini_continuation.js +0 -205
  226. package/dist/types/models/gemini_continuation.d.ts +0 -59
@@ -17,6 +17,44 @@ import { GoogleLLMVariant } from "../utils/variant_utils.js";
17
17
  import { State } from "../sessions/state.js";
18
18
  import { BaseTool } from "./base_tool.js";
19
19
  import { ForwardingArtifactService } from "./forwarding_artifact_service.js";
20
+ import { parseWithSchema } from "../utils/schema.js";
21
+ import { isZodSchema } from "../utils/simple_zod_to_json.js";
22
+ function excludeNone(value) {
23
+ if (Array.isArray(value)) {
24
+ return value.map((item) => excludeNone(item));
25
+ }
26
+ if (value !== null && typeof value === "object") {
27
+ const result = {};
28
+ for (const [key, val] of Object.entries(value)) {
29
+ if (val !== null && val !== void 0) {
30
+ result[key] = excludeNone(val);
31
+ }
32
+ }
33
+ return result;
34
+ }
35
+ return value;
36
+ }
37
+ __name(excludeNone, "excludeNone");
38
+ function validateAndStripAgentInput(agent, args) {
39
+ var _a2;
40
+ if (typeof args !== "object" || args === null || Array.isArray(args)) {
41
+ throw new Error("AgentTool input args must be a plain object.");
42
+ }
43
+ const schema = isZodSchema(agent.inputSchema) ? agent.inputSchema : (_a2 = agent.inputSchemaSource) != null ? _a2 : agent.inputSchema;
44
+ const validated = parseWithSchema(schema, args);
45
+ return excludeNone(validated);
46
+ }
47
+ __name(validateAndStripAgentInput, "validateAndStripAgentInput");
48
+ function validateAndStripAgentOutput(agent, mergedText) {
49
+ var _a2;
50
+ const parsed = JSON.parse(mergedText);
51
+ const validated = typeof agent.validateOutput === "function" ? agent.validateOutput(parsed) : parseWithSchema(
52
+ isZodSchema(agent.outputSchema) ? agent.outputSchema : (_a2 = agent.outputSchemaSource) != null ? _a2 : agent.outputSchema,
53
+ parsed
54
+ );
55
+ return excludeNone(validated);
56
+ }
57
+ __name(validateAndStripAgentOutput, "validateAndStripAgentOutput");
20
58
  const AGENT_TOOL_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.agentTool");
21
59
  function isAgentTool(obj) {
22
60
  return typeof obj === "object" && obj !== null && AGENT_TOOL_SIGNATURE_SYMBOL in obj && obj[AGENT_TOOL_SIGNATURE_SYMBOL] === true;
@@ -70,6 +108,9 @@ const _AgentTool = class _AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGN
70
108
  }) {
71
109
  var _a2, _b2, _c, _d, _e, _f;
72
110
  const hasInputSchema = isLlmAgent(this.agent) && this.agent.inputSchema;
111
+ if (hasInputSchema && isLlmAgent(this.agent)) {
112
+ args = validateAndStripAgentInput(this.agent, args);
113
+ }
73
114
  const content = {
74
115
  role: "user",
75
116
  parts: [
@@ -124,6 +165,9 @@ const _AgentTool = class _AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGN
124
165
  }
125
166
  const hasOutputSchema = isLlmAgent(this.agent) && this.agent.outputSchema;
126
167
  const mergedText = lastEvent.content.parts.filter((part) => !part.thought).map((part) => part.text).filter((text) => text).join("\n");
168
+ if (hasOutputSchema && isLlmAgent(this.agent)) {
169
+ return validateAndStripAgentOutput(this.agent, mergedText);
170
+ }
127
171
  return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
128
172
  }
129
173
  };
@@ -0,0 +1,106 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __decorateClass = (decorators, target, key, kind) => {
7
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
8
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
9
+ if (decorator = decorators[i])
10
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
11
+ if (kind && result) __defProp(target, key, result);
12
+ return result;
13
+ };
14
+ /**
15
+ * @license
16
+ * Copyright 2026 Google LLC
17
+ * SPDX-License-Identifier: Apache-2.0
18
+ */
19
+ import yaml from "js-yaml";
20
+ import { toSnakeCaseName } from "../../utils/case_utils.js";
21
+ import { experimental } from "../../utils/experimental.js";
22
+ import { BaseToolset } from "../base_toolset.js";
23
+ import { OpenAPIToolset } from "../openapi_tool/openapi_toolset.js";
24
+ import { APIHubClient } from "./clients/apihub_client.js";
25
+ let APIHubToolset = class extends BaseToolset {
26
+ constructor(options) {
27
+ var _a, _b, _c, _d;
28
+ super([]);
29
+ this.name = (_a = options.name) != null ? _a : "";
30
+ this.description = (_b = options.description) != null ? _b : "";
31
+ this.apihubResourceName = options.apihubResourceName;
32
+ this.lazyLoadSpec = (_c = options.lazyLoadSpec) != null ? _c : false;
33
+ this.authScheme = options.authScheme;
34
+ this.authCredential = options.authCredential;
35
+ this.apihubClient = (_d = options.apihubClient) != null ? _d : new APIHubClient({
36
+ accessToken: options.accessToken,
37
+ serviceAccountJson: options.serviceAccountJson
38
+ });
39
+ if (!this.lazyLoadSpec) {
40
+ this.toolsetPromise = this.prepareTools();
41
+ this.toolsetPromise.catch(() => void 0);
42
+ }
43
+ }
44
+ /**
45
+ * Returns one tool per operation in the spec, or an empty array when the
46
+ * spec is empty.
47
+ *
48
+ * @throws When the spec cannot be fetched or is not valid YAML or JSON.
49
+ */
50
+ async getTools(context) {
51
+ const toolset = await this.loadToolset();
52
+ return toolset ? toolset.getTools(context) : [];
53
+ }
54
+ /**
55
+ * Returns the tool with the given name, or `undefined` when the spec
56
+ * produced no such tool.
57
+ *
58
+ * Unlike `OpenAPIToolset.getTool`, the result is a Promise, because the spec
59
+ * may still be loading.
60
+ *
61
+ * @param name The tool name, which is the operation ID in snake_case.
62
+ * @throws When the spec cannot be fetched or is not valid YAML or JSON.
63
+ */
64
+ async getTool(name) {
65
+ const toolset = await this.loadToolset();
66
+ return toolset == null ? void 0 : toolset.getTool(name);
67
+ }
68
+ async close() {
69
+ }
70
+ loadToolset() {
71
+ if (!this.toolsetPromise) {
72
+ const promise = this.prepareTools();
73
+ this.toolsetPromise = promise;
74
+ promise.catch(() => {
75
+ if (this.toolsetPromise === promise) {
76
+ this.toolsetPromise = void 0;
77
+ }
78
+ });
79
+ }
80
+ return this.toolsetPromise;
81
+ }
82
+ async prepareTools() {
83
+ var _a, _b, _c, _d;
84
+ const spec = await this.apihubClient.getSpecContent(
85
+ this.apihubResourceName
86
+ );
87
+ const specDict = yaml.load(spec);
88
+ if (!specDict) {
89
+ return void 0;
90
+ }
91
+ this.name || (this.name = toSnakeCaseName((_b = (_a = specDict.info) == null ? void 0 : _a.title) != null ? _b : "unnamed"));
92
+ this.description || (this.description = (_d = (_c = specDict.info) == null ? void 0 : _c.description) != null ? _d : "");
93
+ return new OpenAPIToolset({
94
+ specDict,
95
+ authScheme: this.authScheme,
96
+ authCredential: this.authCredential
97
+ });
98
+ }
99
+ };
100
+ __name(APIHubToolset, "APIHubToolset");
101
+ APIHubToolset = __decorateClass([
102
+ experimental
103
+ ], APIHubToolset);
104
+ export {
105
+ APIHubToolset
106
+ };
@@ -0,0 +1,244 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ /**
6
+ * @license
7
+ * Copyright 2026 Google LLC
8
+ * SPDX-License-Identifier: Apache-2.0
9
+ */
10
+ import { GoogleAuth } from "google-auth-library";
11
+ import { parseServiceAccountJson } from "./service_account.js";
12
+ const APIHUB_ROOT_URL = "https://apihub.googleapis.com/v1";
13
+ const CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
14
+ const ACCEPT_HEADER = "application/json, text/plain, */*";
15
+ const _APIHubClient = class _APIHubClient {
16
+ constructor(options = {}) {
17
+ if (options.accessToken) {
18
+ this.accessToken = options.accessToken;
19
+ } else if (options.serviceAccountJson) {
20
+ this.serviceAccountJson = options.serviceAccountJson;
21
+ }
22
+ }
23
+ /**
24
+ * Returns the content of the first spec that `path` resolves to.
25
+ *
26
+ * - A path naming an API resolves to the first spec of its first version.
27
+ * - A path naming an API version resolves to the first spec of that version.
28
+ * - A path naming an API spec resolves to that spec.
29
+ *
30
+ * `path` may be a resource name such as
31
+ * `projects/my-project/locations/us-central1/apis/my-api`, or a console URL
32
+ * such as
33
+ * `https://console.cloud.google.com/apigee/api-hub/locations/us-central1/apis/my-api?project=my-project`.
34
+ *
35
+ * @param path The API, API version or API spec to read.
36
+ * @return The decoded spec content, or `''` when the spec is empty.
37
+ * @throws When the path cannot be parsed, when the API has no versions, when
38
+ * the version has no specs, or when a request fails.
39
+ */
40
+ async getSpecContent(path) {
41
+ var _a, _b;
42
+ const names = extractResourceName(path);
43
+ let apiVersionResourceName = names.apiVersionResourceName;
44
+ let apiSpecResourceName = names.apiSpecResourceName;
45
+ if (!apiVersionResourceName) {
46
+ const api = await this.getApi(names.apiResourceName);
47
+ const versions = (_a = api.versions) != null ? _a : [];
48
+ if (versions.length === 0) {
49
+ throw new Error(
50
+ `No versions found in API Hub resource: ${names.apiResourceName}`
51
+ );
52
+ }
53
+ apiVersionResourceName = versions[0];
54
+ }
55
+ if (!apiSpecResourceName) {
56
+ const apiVersion = await this.getApiVersion(apiVersionResourceName);
57
+ const specs = (_b = apiVersion.specs) != null ? _b : [];
58
+ if (specs.length === 0) {
59
+ throw new Error(
60
+ `No specs found in API Hub version: ${apiVersionResourceName}`
61
+ );
62
+ }
63
+ apiSpecResourceName = specs[0];
64
+ }
65
+ if (apiSpecResourceName) {
66
+ return this.fetchSpec(apiSpecResourceName);
67
+ }
68
+ throw new Error(`No API Hub resource found in path: ${path}`);
69
+ }
70
+ /**
71
+ * Lists the APIs registered in a project and location.
72
+ *
73
+ * @param project The Google Cloud project ID.
74
+ * @param location The API Hub location, for example `us-central1`.
75
+ * @return The APIs, or an empty array when there are none.
76
+ */
77
+ async listApis(project, location) {
78
+ var _a;
79
+ const body = await this.get(
80
+ `${APIHUB_ROOT_URL}/projects/${project}/locations/${location}/apis`
81
+ );
82
+ return (_a = body.apis) != null ? _a : [];
83
+ }
84
+ /**
85
+ * Gets an API by resource name.
86
+ *
87
+ * @param apiResourceName `projects/{p}/locations/{l}/apis/{a}`.
88
+ */
89
+ async getApi(apiResourceName) {
90
+ return this.get(`${APIHUB_ROOT_URL}/${apiResourceName}`);
91
+ }
92
+ /**
93
+ * Gets an API version by resource name.
94
+ *
95
+ * @param apiVersionName `projects/{p}/locations/{l}/apis/{a}/versions/{v}`.
96
+ */
97
+ async getApiVersion(apiVersionName) {
98
+ return this.get(`${APIHUB_ROOT_URL}/${apiVersionName}`);
99
+ }
100
+ /** Reads the base64-encoded contents of a spec and decodes them as UTF-8. */
101
+ async fetchSpec(apiSpecResourceName) {
102
+ const body = await this.get(
103
+ `${APIHUB_ROOT_URL}/${apiSpecResourceName}:contents`
104
+ );
105
+ if (!body.contents) {
106
+ return "";
107
+ }
108
+ return Buffer.from(body.contents, "base64").toString("utf-8");
109
+ }
110
+ /** Sends an authenticated GET request and parses the JSON response. */
111
+ async get(url) {
112
+ const response = await fetch(url, {
113
+ headers: {
114
+ accept: ACCEPT_HEADER,
115
+ Authorization: `Bearer ${await this.getAccessToken()}`
116
+ }
117
+ });
118
+ if (!response.ok) {
119
+ throw new Error(
120
+ `API Hub request failed with status ${response.status}: ${url}`
121
+ );
122
+ }
123
+ return await response.json();
124
+ }
125
+ /**
126
+ * Returns the bearer token for the next request.
127
+ *
128
+ * `GoogleAuth` is created once and reused, so that it can cache the token
129
+ * and refresh it when it expires.
130
+ */
131
+ async getAccessToken() {
132
+ var _a;
133
+ if (this.accessToken) {
134
+ return this.accessToken;
135
+ }
136
+ (_a = this.auth) != null ? _a : this.auth = this.createAuth();
137
+ let token;
138
+ try {
139
+ token = await this.auth.getAccessToken();
140
+ } catch (e) {
141
+ throw this.tokenError(e);
142
+ }
143
+ if (!token) {
144
+ throw this.tokenError();
145
+ }
146
+ return token;
147
+ }
148
+ /**
149
+ * Builds the error for a token that could not be obtained.
150
+ *
151
+ * Without a service account, the likely fix is to supply a credential. With
152
+ * one, the key itself was rejected, so the error says so and gives the
153
+ * reason.
154
+ */
155
+ tokenError(cause) {
156
+ if (!this.serviceAccountJson) {
157
+ return new Error(
158
+ "Please provide a service account or an access token to API Hub client.",
159
+ { cause }
160
+ );
161
+ }
162
+ const reason = cause === void 0 ? "no token was returned" : cause instanceof Error ? cause.message : String(cause);
163
+ return new Error(
164
+ `Failed to get an access token for API Hub client from the given service account: ${reason}`,
165
+ { cause }
166
+ );
167
+ }
168
+ createAuth() {
169
+ const scopes = [CLOUD_PLATFORM_SCOPE];
170
+ if (!this.serviceAccountJson) {
171
+ return new GoogleAuth({ scopes });
172
+ }
173
+ return new GoogleAuth({
174
+ credentials: parseServiceAccountJson(this.serviceAccountJson),
175
+ scopes
176
+ });
177
+ }
178
+ };
179
+ __name(_APIHubClient, "APIHubClient");
180
+ let APIHubClient = _APIHubClient;
181
+ function segmentAfter(segments, key) {
182
+ const index = segments.indexOf(key);
183
+ if (index === -1 || index + 1 >= segments.length) {
184
+ return void 0;
185
+ }
186
+ return segments[index + 1];
187
+ }
188
+ __name(segmentAfter, "segmentAfter");
189
+ function splitPathAndQuery(urlOrPath) {
190
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(urlOrPath)) {
191
+ try {
192
+ const url = new URL(urlOrPath);
193
+ return { path: url.pathname, query: url.searchParams };
194
+ } catch {
195
+ }
196
+ }
197
+ const queryStart = urlOrPath.indexOf("?");
198
+ if (queryStart === -1) {
199
+ return { path: urlOrPath, query: new URLSearchParams() };
200
+ }
201
+ return {
202
+ path: urlOrPath.slice(0, queryStart),
203
+ query: new URLSearchParams(urlOrPath.slice(queryStart + 1))
204
+ };
205
+ }
206
+ __name(splitPathAndQuery, "splitPathAndQuery");
207
+ function extractResourceName(urlOrPath) {
208
+ var _a;
209
+ const { path: rawPath, query } = splitPathAndQuery(urlOrPath);
210
+ let path = rawPath;
211
+ if (path.includes("api-hub/")) {
212
+ path = path.split("api-hub")[1];
213
+ }
214
+ const segments = path.split("/").filter((segment) => segment);
215
+ const project = segments.includes("projects") ? segmentAfter(segments, "projects") : (_a = query.get("project")) != null ? _a : void 0;
216
+ if (!project) {
217
+ throw new Error(
218
+ `Project ID not found in URL or path in APIHubClient. Input path is '${urlOrPath}'. Please make sure there is either '/projects/PROJECT_ID' in the path or 'project=PROJECT_ID' query param in the input.`
219
+ );
220
+ }
221
+ const location = segmentAfter(segments, "locations");
222
+ if (!location) {
223
+ throw new Error(
224
+ `Location not found in URL or path in APIHubClient. Input path is '${urlOrPath}'. Please make sure there is either '/location/LOCATION_ID' in the path.`
225
+ );
226
+ }
227
+ const apiId = segmentAfter(segments, "apis");
228
+ if (!apiId) {
229
+ throw new Error(
230
+ `API id not found in URL or path in APIHubClient. Input path is '${urlOrPath}'. Please make sure there is either '/apis/API_ID' in the path.`
231
+ );
232
+ }
233
+ const versionId = segmentAfter(segments, "versions");
234
+ const specId = segmentAfter(segments, "specs");
235
+ const apiResourceName = `projects/${project}/locations/${location}/apis/${apiId}`;
236
+ const apiVersionResourceName = versionId ? `${apiResourceName}/versions/${versionId}` : void 0;
237
+ const apiSpecResourceName = apiVersionResourceName && specId ? `${apiVersionResourceName}/specs/${specId}` : void 0;
238
+ return { apiResourceName, apiVersionResourceName, apiSpecResourceName };
239
+ }
240
+ __name(extractResourceName, "extractResourceName");
241
+ export {
242
+ APIHubClient,
243
+ extractResourceName
244
+ };
@@ -0,0 +1,132 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+ /**
27
+ * @license
28
+ * Copyright 2026 Google LLC
29
+ * SPDX-License-Identifier: Apache-2.0
30
+ */
31
+ import { GoogleAuth, OAuth2Client } from "google-auth-library";
32
+ import { loadOptionalPeer } from "../../../utils/optional_peer.js";
33
+ import { parseServiceAccountJson } from "./service_account.js";
34
+ const CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
35
+ const _SecretManagerClient = class _SecretManagerClient {
36
+ /**
37
+ * @throws `Invalid service account JSON: ...` when `serviceAccountJson`
38
+ * does not parse.
39
+ */
40
+ constructor(options = {}) {
41
+ if (options.serviceAccountJson) {
42
+ this.credentials = parseServiceAccountJson(options.serviceAccountJson);
43
+ } else if (options.authToken) {
44
+ this.authToken = options.authToken;
45
+ }
46
+ }
47
+ /**
48
+ * Returns the payload of a secret version as a UTF-8 string.
49
+ *
50
+ * @param resourceName The secret version, in the form
51
+ * `projects/{project}/secrets/{secret}/versions/{version}`. Use
52
+ * `latest` as the version to read the newest one.
53
+ * @throws When default credentials are needed and cannot be resolved, or
54
+ * when Secret Manager returns an error, such as a missing secret or a
55
+ * denied permission.
56
+ */
57
+ async getSecret(resourceName) {
58
+ var _a;
59
+ const client = await this.getClient();
60
+ const [response] = await client.accessSecretVersion({ name: resourceName });
61
+ const data = (_a = response.payload) == null ? void 0 : _a.data;
62
+ if (data === void 0 || data === null) {
63
+ return "";
64
+ }
65
+ if (typeof data === "string") {
66
+ return data;
67
+ }
68
+ return new TextDecoder("utf-8").decode(data);
69
+ }
70
+ /**
71
+ * Resolves the Secret Manager client, loading the optional peer and the
72
+ * credentials on first use.
73
+ *
74
+ * A created client is kept. A failure is not kept, so the next call tries
75
+ * again, for example once default credentials become available.
76
+ */
77
+ getClient() {
78
+ if (!this.clientPromise) {
79
+ const promise = this.createClient();
80
+ this.clientPromise = promise;
81
+ promise.catch(() => {
82
+ if (this.clientPromise === promise) {
83
+ this.clientPromise = void 0;
84
+ }
85
+ });
86
+ }
87
+ return this.clientPromise;
88
+ }
89
+ async createClient() {
90
+ const { SecretManagerServiceClient } = await loadOptionalPeer(
91
+ {
92
+ packageName: "@google-cloud/secret-manager",
93
+ feature: "SecretManagerClient"
94
+ },
95
+ () => Promise.resolve().then(() => __toESM(require("@google-cloud/secret-manager"), 1))
96
+ );
97
+ if (this.credentials) {
98
+ return new SecretManagerServiceClient({ credentials: this.credentials });
99
+ }
100
+ if (this.authToken) {
101
+ const authClient2 = new OAuth2Client();
102
+ authClient2.setCredentials({ access_token: this.authToken });
103
+ return new SecretManagerServiceClient({
104
+ authClient: toSdkAuthClient(authClient2)
105
+ });
106
+ }
107
+ let authClient;
108
+ try {
109
+ authClient = await new GoogleAuth({
110
+ scopes: [CLOUD_PLATFORM_SCOPE]
111
+ }).getClient();
112
+ } catch (e) {
113
+ const message = e instanceof Error ? e.message : String(e);
114
+ throw new Error(
115
+ `'serviceAccountJson' or 'authToken' are both missing, and error occurred while trying to use default credentials: ${message}`,
116
+ { cause: e }
117
+ );
118
+ }
119
+ return new SecretManagerServiceClient({
120
+ authClient: toSdkAuthClient(authClient)
121
+ });
122
+ }
123
+ };
124
+ __name(_SecretManagerClient, "SecretManagerClient");
125
+ let SecretManagerClient = _SecretManagerClient;
126
+ function toSdkAuthClient(authClient) {
127
+ return authClient;
128
+ }
129
+ __name(toSdkAuthClient, "toSdkAuthClient");
130
+ export {
131
+ SecretManagerClient
132
+ };
@@ -0,0 +1,21 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ /**
6
+ * @license
7
+ * Copyright 2026 Google LLC
8
+ * SPDX-License-Identifier: Apache-2.0
9
+ */
10
+ function parseServiceAccountJson(json) {
11
+ try {
12
+ return JSON.parse(json);
13
+ } catch (e) {
14
+ const message = e instanceof Error ? e.message : String(e);
15
+ throw new Error(`Invalid service account JSON: ${message}`, { cause: e });
16
+ }
17
+ }
18
+ __name(parseServiceAccountJson, "parseServiceAccountJson");
19
+ export {
20
+ parseServiceAccountJson
21
+ };