@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
@@ -38,12 +38,50 @@ var import_variant_utils = require("../utils/variant_utils.js");
38
38
  var import_state = require("../sessions/state.js");
39
39
  var import_base_tool = require("./base_tool.js");
40
40
  var import_forwarding_artifact_service = require("./forwarding_artifact_service.js");
41
+ var import_schema = require("../utils/schema.js");
42
+ var import_simple_zod_to_json = require("../utils/simple_zod_to_json.js");
41
43
  /**
42
44
  * @license
43
45
  * Copyright 2025 Google LLC
44
46
  * SPDX-License-Identifier: Apache-2.0
45
47
  */
46
48
  var _a, _b;
49
+ function excludeNone(value) {
50
+ if (Array.isArray(value)) {
51
+ return value.map((item) => excludeNone(item));
52
+ }
53
+ if (value !== null && typeof value === "object") {
54
+ const result = {};
55
+ for (const [key, val] of Object.entries(value)) {
56
+ if (val !== null && val !== void 0) {
57
+ result[key] = excludeNone(val);
58
+ }
59
+ }
60
+ return result;
61
+ }
62
+ return value;
63
+ }
64
+ __name(excludeNone, "excludeNone");
65
+ function validateAndStripAgentInput(agent, args) {
66
+ var _a2;
67
+ if (typeof args !== "object" || args === null || Array.isArray(args)) {
68
+ throw new Error("AgentTool input args must be a plain object.");
69
+ }
70
+ const schema = (0, import_simple_zod_to_json.isZodSchema)(agent.inputSchema) ? agent.inputSchema : (_a2 = agent.inputSchemaSource) != null ? _a2 : agent.inputSchema;
71
+ const validated = (0, import_schema.parseWithSchema)(schema, args);
72
+ return excludeNone(validated);
73
+ }
74
+ __name(validateAndStripAgentInput, "validateAndStripAgentInput");
75
+ function validateAndStripAgentOutput(agent, mergedText) {
76
+ var _a2;
77
+ const parsed = JSON.parse(mergedText);
78
+ const validated = typeof agent.validateOutput === "function" ? agent.validateOutput(parsed) : (0, import_schema.parseWithSchema)(
79
+ (0, import_simple_zod_to_json.isZodSchema)(agent.outputSchema) ? agent.outputSchema : (_a2 = agent.outputSchemaSource) != null ? _a2 : agent.outputSchema,
80
+ parsed
81
+ );
82
+ return excludeNone(validated);
83
+ }
84
+ __name(validateAndStripAgentOutput, "validateAndStripAgentOutput");
47
85
  const AGENT_TOOL_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.agentTool");
48
86
  function isAgentTool(obj) {
49
87
  return typeof obj === "object" && obj !== null && AGENT_TOOL_SIGNATURE_SYMBOL in obj && obj[AGENT_TOOL_SIGNATURE_SYMBOL] === true;
@@ -97,6 +135,9 @@ const _AgentTool = class _AgentTool extends (_b = import_base_tool.BaseTool, _a
97
135
  }) {
98
136
  var _a2, _b2, _c, _d, _e, _f;
99
137
  const hasInputSchema = (0, import_llm_agent.isLlmAgent)(this.agent) && this.agent.inputSchema;
138
+ if (hasInputSchema && (0, import_llm_agent.isLlmAgent)(this.agent)) {
139
+ args = validateAndStripAgentInput(this.agent, args);
140
+ }
100
141
  const content = {
101
142
  role: "user",
102
143
  parts: [
@@ -151,6 +192,9 @@ const _AgentTool = class _AgentTool extends (_b = import_base_tool.BaseTool, _a
151
192
  }
152
193
  const hasOutputSchema = (0, import_llm_agent.isLlmAgent)(this.agent) && this.agent.outputSchema;
153
194
  const mergedText = lastEvent.content.parts.filter((part) => !part.thought).map((part) => part.text).filter((text) => text).join("\n");
195
+ if (hasOutputSchema && (0, import_llm_agent.isLlmAgent)(this.agent)) {
196
+ return validateAndStripAgentOutput(this.agent, mergedText);
197
+ }
154
198
  return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
155
199
  }
156
200
  };
@@ -0,0 +1,142 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __create = Object.create;
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+ var __decorateClass = (decorators, target, key, kind) => {
37
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
38
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
39
+ if (decorator = decorators[i])
40
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
41
+ if (kind && result) __defProp(target, key, result);
42
+ return result;
43
+ };
44
+ var apihub_toolset_exports = {};
45
+ __export(apihub_toolset_exports, {
46
+ APIHubToolset: () => APIHubToolset
47
+ });
48
+ module.exports = __toCommonJS(apihub_toolset_exports);
49
+ var import_js_yaml = __toESM(require("js-yaml"), 1);
50
+ var import_case_utils = require("../../utils/case_utils.js");
51
+ var import_experimental = require("../../utils/experimental.js");
52
+ var import_base_toolset = require("../base_toolset.js");
53
+ var import_openapi_toolset = require("../openapi_tool/openapi_toolset.js");
54
+ var import_apihub_client = require("./clients/apihub_client.js");
55
+ /**
56
+ * @license
57
+ * Copyright 2026 Google LLC
58
+ * SPDX-License-Identifier: Apache-2.0
59
+ */
60
+ let APIHubToolset = class extends import_base_toolset.BaseToolset {
61
+ constructor(options) {
62
+ var _a, _b, _c, _d;
63
+ super([]);
64
+ this.name = (_a = options.name) != null ? _a : "";
65
+ this.description = (_b = options.description) != null ? _b : "";
66
+ this.apihubResourceName = options.apihubResourceName;
67
+ this.lazyLoadSpec = (_c = options.lazyLoadSpec) != null ? _c : false;
68
+ this.authScheme = options.authScheme;
69
+ this.authCredential = options.authCredential;
70
+ this.apihubClient = (_d = options.apihubClient) != null ? _d : new import_apihub_client.APIHubClient({
71
+ accessToken: options.accessToken,
72
+ serviceAccountJson: options.serviceAccountJson
73
+ });
74
+ if (!this.lazyLoadSpec) {
75
+ this.toolsetPromise = this.prepareTools();
76
+ this.toolsetPromise.catch(() => void 0);
77
+ }
78
+ }
79
+ /**
80
+ * Returns one tool per operation in the spec, or an empty array when the
81
+ * spec is empty.
82
+ *
83
+ * @throws When the spec cannot be fetched or is not valid YAML or JSON.
84
+ */
85
+ async getTools(context) {
86
+ const toolset = await this.loadToolset();
87
+ return toolset ? toolset.getTools(context) : [];
88
+ }
89
+ /**
90
+ * Returns the tool with the given name, or `undefined` when the spec
91
+ * produced no such tool.
92
+ *
93
+ * Unlike `OpenAPIToolset.getTool`, the result is a Promise, because the spec
94
+ * may still be loading.
95
+ *
96
+ * @param name The tool name, which is the operation ID in snake_case.
97
+ * @throws When the spec cannot be fetched or is not valid YAML or JSON.
98
+ */
99
+ async getTool(name) {
100
+ const toolset = await this.loadToolset();
101
+ return toolset == null ? void 0 : toolset.getTool(name);
102
+ }
103
+ async close() {
104
+ }
105
+ loadToolset() {
106
+ if (!this.toolsetPromise) {
107
+ const promise = this.prepareTools();
108
+ this.toolsetPromise = promise;
109
+ promise.catch(() => {
110
+ if (this.toolsetPromise === promise) {
111
+ this.toolsetPromise = void 0;
112
+ }
113
+ });
114
+ }
115
+ return this.toolsetPromise;
116
+ }
117
+ async prepareTools() {
118
+ var _a, _b, _c, _d;
119
+ const spec = await this.apihubClient.getSpecContent(
120
+ this.apihubResourceName
121
+ );
122
+ const specDict = import_js_yaml.default.load(spec);
123
+ if (!specDict) {
124
+ return void 0;
125
+ }
126
+ this.name || (this.name = (0, import_case_utils.toSnakeCaseName)((_b = (_a = specDict.info) == null ? void 0 : _a.title) != null ? _b : "unnamed"));
127
+ this.description || (this.description = (_d = (_c = specDict.info) == null ? void 0 : _c.description) != null ? _d : "");
128
+ return new import_openapi_toolset.OpenAPIToolset({
129
+ specDict,
130
+ authScheme: this.authScheme,
131
+ authCredential: this.authCredential
132
+ });
133
+ }
134
+ };
135
+ __name(APIHubToolset, "APIHubToolset");
136
+ APIHubToolset = __decorateClass([
137
+ import_experimental.experimental
138
+ ], APIHubToolset);
139
+ // Annotate the CommonJS export names for ESM import in node:
140
+ 0 && (module.exports = {
141
+ APIHubToolset
142
+ });
@@ -0,0 +1,272 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var apihub_client_exports = {};
27
+ __export(apihub_client_exports, {
28
+ APIHubClient: () => APIHubClient,
29
+ extractResourceName: () => extractResourceName
30
+ });
31
+ module.exports = __toCommonJS(apihub_client_exports);
32
+ var import_google_auth_library = require("google-auth-library");
33
+ var import_service_account = require("./service_account.js");
34
+ /**
35
+ * @license
36
+ * Copyright 2026 Google LLC
37
+ * SPDX-License-Identifier: Apache-2.0
38
+ */
39
+ const APIHUB_ROOT_URL = "https://apihub.googleapis.com/v1";
40
+ const CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
41
+ const ACCEPT_HEADER = "application/json, text/plain, */*";
42
+ const _APIHubClient = class _APIHubClient {
43
+ constructor(options = {}) {
44
+ if (options.accessToken) {
45
+ this.accessToken = options.accessToken;
46
+ } else if (options.serviceAccountJson) {
47
+ this.serviceAccountJson = options.serviceAccountJson;
48
+ }
49
+ }
50
+ /**
51
+ * Returns the content of the first spec that `path` resolves to.
52
+ *
53
+ * - A path naming an API resolves to the first spec of its first version.
54
+ * - A path naming an API version resolves to the first spec of that version.
55
+ * - A path naming an API spec resolves to that spec.
56
+ *
57
+ * `path` may be a resource name such as
58
+ * `projects/my-project/locations/us-central1/apis/my-api`, or a console URL
59
+ * such as
60
+ * `https://console.cloud.google.com/apigee/api-hub/locations/us-central1/apis/my-api?project=my-project`.
61
+ *
62
+ * @param path The API, API version or API spec to read.
63
+ * @return The decoded spec content, or `''` when the spec is empty.
64
+ * @throws When the path cannot be parsed, when the API has no versions, when
65
+ * the version has no specs, or when a request fails.
66
+ */
67
+ async getSpecContent(path) {
68
+ var _a, _b;
69
+ const names = extractResourceName(path);
70
+ let apiVersionResourceName = names.apiVersionResourceName;
71
+ let apiSpecResourceName = names.apiSpecResourceName;
72
+ if (!apiVersionResourceName) {
73
+ const api = await this.getApi(names.apiResourceName);
74
+ const versions = (_a = api.versions) != null ? _a : [];
75
+ if (versions.length === 0) {
76
+ throw new Error(
77
+ `No versions found in API Hub resource: ${names.apiResourceName}`
78
+ );
79
+ }
80
+ apiVersionResourceName = versions[0];
81
+ }
82
+ if (!apiSpecResourceName) {
83
+ const apiVersion = await this.getApiVersion(apiVersionResourceName);
84
+ const specs = (_b = apiVersion.specs) != null ? _b : [];
85
+ if (specs.length === 0) {
86
+ throw new Error(
87
+ `No specs found in API Hub version: ${apiVersionResourceName}`
88
+ );
89
+ }
90
+ apiSpecResourceName = specs[0];
91
+ }
92
+ if (apiSpecResourceName) {
93
+ return this.fetchSpec(apiSpecResourceName);
94
+ }
95
+ throw new Error(`No API Hub resource found in path: ${path}`);
96
+ }
97
+ /**
98
+ * Lists the APIs registered in a project and location.
99
+ *
100
+ * @param project The Google Cloud project ID.
101
+ * @param location The API Hub location, for example `us-central1`.
102
+ * @return The APIs, or an empty array when there are none.
103
+ */
104
+ async listApis(project, location) {
105
+ var _a;
106
+ const body = await this.get(
107
+ `${APIHUB_ROOT_URL}/projects/${project}/locations/${location}/apis`
108
+ );
109
+ return (_a = body.apis) != null ? _a : [];
110
+ }
111
+ /**
112
+ * Gets an API by resource name.
113
+ *
114
+ * @param apiResourceName `projects/{p}/locations/{l}/apis/{a}`.
115
+ */
116
+ async getApi(apiResourceName) {
117
+ return this.get(`${APIHUB_ROOT_URL}/${apiResourceName}`);
118
+ }
119
+ /**
120
+ * Gets an API version by resource name.
121
+ *
122
+ * @param apiVersionName `projects/{p}/locations/{l}/apis/{a}/versions/{v}`.
123
+ */
124
+ async getApiVersion(apiVersionName) {
125
+ return this.get(`${APIHUB_ROOT_URL}/${apiVersionName}`);
126
+ }
127
+ /** Reads the base64-encoded contents of a spec and decodes them as UTF-8. */
128
+ async fetchSpec(apiSpecResourceName) {
129
+ const body = await this.get(
130
+ `${APIHUB_ROOT_URL}/${apiSpecResourceName}:contents`
131
+ );
132
+ if (!body.contents) {
133
+ return "";
134
+ }
135
+ return Buffer.from(body.contents, "base64").toString("utf-8");
136
+ }
137
+ /** Sends an authenticated GET request and parses the JSON response. */
138
+ async get(url) {
139
+ const response = await fetch(url, {
140
+ headers: {
141
+ accept: ACCEPT_HEADER,
142
+ Authorization: `Bearer ${await this.getAccessToken()}`
143
+ }
144
+ });
145
+ if (!response.ok) {
146
+ throw new Error(
147
+ `API Hub request failed with status ${response.status}: ${url}`
148
+ );
149
+ }
150
+ return await response.json();
151
+ }
152
+ /**
153
+ * Returns the bearer token for the next request.
154
+ *
155
+ * `GoogleAuth` is created once and reused, so that it can cache the token
156
+ * and refresh it when it expires.
157
+ */
158
+ async getAccessToken() {
159
+ var _a;
160
+ if (this.accessToken) {
161
+ return this.accessToken;
162
+ }
163
+ (_a = this.auth) != null ? _a : this.auth = this.createAuth();
164
+ let token;
165
+ try {
166
+ token = await this.auth.getAccessToken();
167
+ } catch (e) {
168
+ throw this.tokenError(e);
169
+ }
170
+ if (!token) {
171
+ throw this.tokenError();
172
+ }
173
+ return token;
174
+ }
175
+ /**
176
+ * Builds the error for a token that could not be obtained.
177
+ *
178
+ * Without a service account, the likely fix is to supply a credential. With
179
+ * one, the key itself was rejected, so the error says so and gives the
180
+ * reason.
181
+ */
182
+ tokenError(cause) {
183
+ if (!this.serviceAccountJson) {
184
+ return new Error(
185
+ "Please provide a service account or an access token to API Hub client.",
186
+ { cause }
187
+ );
188
+ }
189
+ const reason = cause === void 0 ? "no token was returned" : cause instanceof Error ? cause.message : String(cause);
190
+ return new Error(
191
+ `Failed to get an access token for API Hub client from the given service account: ${reason}`,
192
+ { cause }
193
+ );
194
+ }
195
+ createAuth() {
196
+ const scopes = [CLOUD_PLATFORM_SCOPE];
197
+ if (!this.serviceAccountJson) {
198
+ return new import_google_auth_library.GoogleAuth({ scopes });
199
+ }
200
+ return new import_google_auth_library.GoogleAuth({
201
+ credentials: (0, import_service_account.parseServiceAccountJson)(this.serviceAccountJson),
202
+ scopes
203
+ });
204
+ }
205
+ };
206
+ __name(_APIHubClient, "APIHubClient");
207
+ let APIHubClient = _APIHubClient;
208
+ function segmentAfter(segments, key) {
209
+ const index = segments.indexOf(key);
210
+ if (index === -1 || index + 1 >= segments.length) {
211
+ return void 0;
212
+ }
213
+ return segments[index + 1];
214
+ }
215
+ __name(segmentAfter, "segmentAfter");
216
+ function splitPathAndQuery(urlOrPath) {
217
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(urlOrPath)) {
218
+ try {
219
+ const url = new URL(urlOrPath);
220
+ return { path: url.pathname, query: url.searchParams };
221
+ } catch {
222
+ }
223
+ }
224
+ const queryStart = urlOrPath.indexOf("?");
225
+ if (queryStart === -1) {
226
+ return { path: urlOrPath, query: new URLSearchParams() };
227
+ }
228
+ return {
229
+ path: urlOrPath.slice(0, queryStart),
230
+ query: new URLSearchParams(urlOrPath.slice(queryStart + 1))
231
+ };
232
+ }
233
+ __name(splitPathAndQuery, "splitPathAndQuery");
234
+ function extractResourceName(urlOrPath) {
235
+ var _a;
236
+ const { path: rawPath, query } = splitPathAndQuery(urlOrPath);
237
+ let path = rawPath;
238
+ if (path.includes("api-hub/")) {
239
+ path = path.split("api-hub")[1];
240
+ }
241
+ const segments = path.split("/").filter((segment) => segment);
242
+ const project = segments.includes("projects") ? segmentAfter(segments, "projects") : (_a = query.get("project")) != null ? _a : void 0;
243
+ if (!project) {
244
+ throw new Error(
245
+ `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.`
246
+ );
247
+ }
248
+ const location = segmentAfter(segments, "locations");
249
+ if (!location) {
250
+ throw new Error(
251
+ `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.`
252
+ );
253
+ }
254
+ const apiId = segmentAfter(segments, "apis");
255
+ if (!apiId) {
256
+ throw new Error(
257
+ `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.`
258
+ );
259
+ }
260
+ const versionId = segmentAfter(segments, "versions");
261
+ const specId = segmentAfter(segments, "specs");
262
+ const apiResourceName = `projects/${project}/locations/${location}/apis/${apiId}`;
263
+ const apiVersionResourceName = versionId ? `${apiResourceName}/versions/${versionId}` : void 0;
264
+ const apiSpecResourceName = apiVersionResourceName && specId ? `${apiVersionResourceName}/specs/${specId}` : void 0;
265
+ return { apiResourceName, apiVersionResourceName, apiSpecResourceName };
266
+ }
267
+ __name(extractResourceName, "extractResourceName");
268
+ // Annotate the CommonJS export names for ESM import in node:
269
+ 0 && (module.exports = {
270
+ APIHubClient,
271
+ extractResourceName
272
+ });
@@ -0,0 +1,148 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __create = Object.create;
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+ var secret_client_exports = {};
37
+ __export(secret_client_exports, {
38
+ SecretManagerClient: () => SecretManagerClient
39
+ });
40
+ module.exports = __toCommonJS(secret_client_exports);
41
+ var import_google_auth_library = require("google-auth-library");
42
+ var import_optional_peer = require("../../../utils/optional_peer.js");
43
+ var import_service_account = require("./service_account.js");
44
+ /**
45
+ * @license
46
+ * Copyright 2026 Google LLC
47
+ * SPDX-License-Identifier: Apache-2.0
48
+ */
49
+ const CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
50
+ const _SecretManagerClient = class _SecretManagerClient {
51
+ /**
52
+ * @throws `Invalid service account JSON: ...` when `serviceAccountJson`
53
+ * does not parse.
54
+ */
55
+ constructor(options = {}) {
56
+ if (options.serviceAccountJson) {
57
+ this.credentials = (0, import_service_account.parseServiceAccountJson)(options.serviceAccountJson);
58
+ } else if (options.authToken) {
59
+ this.authToken = options.authToken;
60
+ }
61
+ }
62
+ /**
63
+ * Returns the payload of a secret version as a UTF-8 string.
64
+ *
65
+ * @param resourceName The secret version, in the form
66
+ * `projects/{project}/secrets/{secret}/versions/{version}`. Use
67
+ * `latest` as the version to read the newest one.
68
+ * @throws When default credentials are needed and cannot be resolved, or
69
+ * when Secret Manager returns an error, such as a missing secret or a
70
+ * denied permission.
71
+ */
72
+ async getSecret(resourceName) {
73
+ var _a;
74
+ const client = await this.getClient();
75
+ const [response] = await client.accessSecretVersion({ name: resourceName });
76
+ const data = (_a = response.payload) == null ? void 0 : _a.data;
77
+ if (data === void 0 || data === null) {
78
+ return "";
79
+ }
80
+ if (typeof data === "string") {
81
+ return data;
82
+ }
83
+ return new TextDecoder("utf-8").decode(data);
84
+ }
85
+ /**
86
+ * Resolves the Secret Manager client, loading the optional peer and the
87
+ * credentials on first use.
88
+ *
89
+ * A created client is kept. A failure is not kept, so the next call tries
90
+ * again, for example once default credentials become available.
91
+ */
92
+ getClient() {
93
+ if (!this.clientPromise) {
94
+ const promise = this.createClient();
95
+ this.clientPromise = promise;
96
+ promise.catch(() => {
97
+ if (this.clientPromise === promise) {
98
+ this.clientPromise = void 0;
99
+ }
100
+ });
101
+ }
102
+ return this.clientPromise;
103
+ }
104
+ async createClient() {
105
+ const { SecretManagerServiceClient } = await (0, import_optional_peer.loadOptionalPeer)(
106
+ {
107
+ packageName: "@google-cloud/secret-manager",
108
+ feature: "SecretManagerClient"
109
+ },
110
+ () => Promise.resolve().then(() => __toESM(require("@google-cloud/secret-manager"), 1))
111
+ );
112
+ if (this.credentials) {
113
+ return new SecretManagerServiceClient({ credentials: this.credentials });
114
+ }
115
+ if (this.authToken) {
116
+ const authClient2 = new import_google_auth_library.OAuth2Client();
117
+ authClient2.setCredentials({ access_token: this.authToken });
118
+ return new SecretManagerServiceClient({
119
+ authClient: toSdkAuthClient(authClient2)
120
+ });
121
+ }
122
+ let authClient;
123
+ try {
124
+ authClient = await new import_google_auth_library.GoogleAuth({
125
+ scopes: [CLOUD_PLATFORM_SCOPE]
126
+ }).getClient();
127
+ } catch (e) {
128
+ const message = e instanceof Error ? e.message : String(e);
129
+ throw new Error(
130
+ `'serviceAccountJson' or 'authToken' are both missing, and error occurred while trying to use default credentials: ${message}`,
131
+ { cause: e }
132
+ );
133
+ }
134
+ return new SecretManagerServiceClient({
135
+ authClient: toSdkAuthClient(authClient)
136
+ });
137
+ }
138
+ };
139
+ __name(_SecretManagerClient, "SecretManagerClient");
140
+ let SecretManagerClient = _SecretManagerClient;
141
+ function toSdkAuthClient(authClient) {
142
+ return authClient;
143
+ }
144
+ __name(toSdkAuthClient, "toSdkAuthClient");
145
+ // Annotate the CommonJS export names for ESM import in node:
146
+ 0 && (module.exports = {
147
+ SecretManagerClient
148
+ });
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var service_account_exports = {};
27
+ __export(service_account_exports, {
28
+ parseServiceAccountJson: () => parseServiceAccountJson
29
+ });
30
+ module.exports = __toCommonJS(service_account_exports);
31
+ /**
32
+ * @license
33
+ * Copyright 2026 Google LLC
34
+ * SPDX-License-Identifier: Apache-2.0
35
+ */
36
+ function parseServiceAccountJson(json) {
37
+ try {
38
+ return JSON.parse(json);
39
+ } catch (e) {
40
+ const message = e instanceof Error ? e.message : String(e);
41
+ throw new Error(`Invalid service account JSON: ${message}`, { cause: e });
42
+ }
43
+ }
44
+ __name(parseServiceAccountJson, "parseServiceAccountJson");
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ parseServiceAccountJson
48
+ });