@google/adk 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a2a/a2a_remote_agent.js +4 -1
- package/dist/cjs/a2a/agent_card.js +102 -26
- package/dist/cjs/a2a/agent_to_a2a.js +1 -1
- package/dist/cjs/agents/agent_engine_client.js +172 -0
- package/dist/cjs/agents/base_agent.js +20 -4
- package/dist/cjs/agents/functions.js +227 -25
- package/dist/cjs/agents/instructions.js +6 -2
- package/dist/cjs/agents/invocation_context.js +26 -4
- package/dist/cjs/agents/langgraph_agent.js +152 -0
- package/dist/cjs/agents/llm_agent.js +194 -107
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/code_execution_request_processor.js +18 -6
- package/dist/cjs/agents/processors/content_processor_utils.js +38 -10
- package/dist/cjs/agents/processors/content_request_processor.js +34 -2
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/nl_planning_processor.js +12 -3
- package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/cjs/auth/auth_handler.js +37 -5
- package/dist/cjs/auth/auth_schemes.js +9 -0
- package/dist/cjs/cli/cli_eval.js +532 -0
- package/dist/cjs/cli/utils/envs.js +116 -0
- package/dist/cjs/cli/utils/evals.js +137 -0
- package/dist/cjs/cli/utils/logs.js +150 -0
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/cjs/code_executors/code_execution_utils.js +48 -16
- package/dist/cjs/code_executors/code_executor_context.js +6 -2
- package/dist/cjs/code_executors/container_code_executor.js +27 -16
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/cjs/common.js +61 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
- package/dist/cjs/context/token_based_context_compactor.js +2 -1
- package/dist/cjs/errors/input_validation_error.js +3 -2
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/examples/example_util.js +23 -2
- package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
- package/dist/cjs/index.js +104 -1
- package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +16 -8
- package/dist/cjs/models/google_llm.js +13 -16
- package/dist/cjs/models/llm_response.js +9 -1
- package/dist/cjs/models/registry.js +1 -1
- package/dist/cjs/models/routed_llm.js +9 -8
- package/dist/cjs/planners/plan_re_act_planner.js +1 -1
- package/dist/cjs/plugins/base_plugin.js +13 -23
- package/dist/cjs/runner/in_memory_runner.js +6 -11
- package/dist/cjs/runner/runner.js +105 -33
- package/dist/cjs/sessions/base_session_service.js +14 -8
- package/dist/cjs/sessions/database_session_service.js +50 -28
- package/dist/cjs/sessions/db/operations.js +1 -1
- package/dist/cjs/sessions/in_memory_session_service.js +3 -1
- package/dist/cjs/sessions/stale_session_error.js +59 -0
- package/dist/cjs/sessions/state.js +8 -4
- package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
- package/dist/cjs/skills/loader.js +52 -18
- package/dist/cjs/telemetry/setup.js +0 -1
- package/dist/cjs/telemetry/tracing.js +147 -73
- package/dist/cjs/tools/agent_tool.js +44 -0
- package/dist/cjs/tools/apihub_tool/apihub_toolset.js +137 -0
- package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
- package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
- package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +263 -0
- package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +671 -0
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +223 -0
- package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +184 -0
- package/dist/cjs/tools/example_tool.js +10 -0
- package/dist/cjs/tools/function_tool.js +319 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool.js +100 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolset.js +173 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolsets.js +124 -0
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
- package/dist/cjs/tools/google_api_tool/index.js +61 -0
- package/dist/cjs/tools/load_artifacts_tool.js +12 -6
- package/dist/cjs/tools/load_memory_tool.js +12 -10
- package/dist/cjs/tools/mcp/index.js +12 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -14
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +7 -13
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
- package/dist/cjs/tools/toolbox_toolset.js +174 -0
- package/dist/cjs/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/cjs/utils/client_labels.js +19 -2
- package/dist/cjs/utils/env_aware_utils.js +6 -8
- package/dist/cjs/utils/error_utils.js +11 -11
- package/dist/cjs/utils/failover_utils.js +1 -1
- package/dist/cjs/utils/file_extension_utils.js +11 -0
- package/dist/cjs/utils/file_utils.js +2 -24
- package/dist/cjs/utils/gemini_schema_util.js +28 -7
- package/dist/cjs/utils/json_utils.js +49 -0
- package/dist/cjs/utils/live_connection_utils.js +4 -5
- package/dist/cjs/utils/logger_node.js +11 -1
- package/dist/cjs/utils/object_notation_utils.js +6 -3
- package/dist/cjs/utils/output_schema_utils.js +5 -2
- package/dist/cjs/utils/streaming_utils.js +12 -12
- package/dist/cjs/utils/task.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +4 -1
- package/dist/esm/a2a/agent_card.js +103 -27
- package/dist/esm/a2a/agent_to_a2a.js +5 -2
- package/dist/esm/agents/agent_engine_client.js +144 -0
- package/dist/esm/agents/base_agent.js +20 -4
- package/dist/esm/agents/functions.js +226 -25
- package/dist/esm/agents/instructions.js +6 -2
- package/dist/esm/agents/invocation_context.js +24 -4
- package/dist/esm/agents/langgraph_agent.js +123 -0
- package/dist/esm/agents/llm_agent.js +204 -110
- package/dist/esm/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/code_execution_request_processor.js +21 -8
- package/dist/esm/agents/processors/content_processor_utils.js +38 -10
- package/dist/esm/agents/processors/content_request_processor.js +34 -2
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/nl_planning_processor.js +12 -3
- package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/esm/auth/auth_handler.js +37 -5
- package/dist/esm/auth/auth_schemes.js +8 -0
- package/dist/esm/cli/cli_eval.js +510 -0
- package/dist/esm/cli/utils/envs.js +78 -0
- package/dist/esm/cli/utils/evals.js +109 -0
- package/dist/esm/cli/utils/logs.js +111 -0
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/esm/code_executors/code_execution_utils.js +46 -16
- package/dist/esm/code_executors/code_executor_context.js +5 -2
- package/dist/esm/code_executors/container_code_executor.js +27 -16
- package/dist/esm/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/esm/common.js +65 -4
- package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
- package/dist/esm/context/token_based_context_compactor.js +2 -1
- package/dist/esm/errors/input_validation_error.js +3 -2
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/examples/example_util.js +21 -1
- package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
- package/dist/esm/index.js +114 -2
- package/dist/esm/integrations/agent_registry/helpers.js +1 -1
- package/dist/esm/models/gemini_llm_connection.js +16 -8
- package/dist/esm/models/google_llm.js +14 -17
- package/dist/esm/models/llm_response.js +9 -1
- package/dist/esm/models/registry.js +1 -1
- package/dist/esm/models/routed_llm.js +9 -8
- package/dist/esm/planners/plan_re_act_planner.js +1 -1
- package/dist/esm/plugins/base_plugin.js +13 -23
- package/dist/esm/runner/in_memory_runner.js +6 -11
- package/dist/esm/runner/runner.js +105 -33
- package/dist/esm/sessions/base_session_service.js +12 -7
- package/dist/esm/sessions/database_session_service.js +49 -28
- package/dist/esm/sessions/db/operations.js +1 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -1
- package/dist/esm/sessions/stale_session_error.js +31 -0
- package/dist/esm/sessions/state.js +8 -4
- package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
- package/dist/esm/skills/loader.js +51 -17
- package/dist/esm/telemetry/setup.js +1 -2
- package/dist/esm/telemetry/tracing.js +151 -74
- package/dist/esm/tools/agent_tool.js +44 -0
- package/dist/esm/tools/apihub_tool/apihub_toolset.js +101 -0
- package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
- package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
- package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +245 -0
- package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +629 -0
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +219 -0
- package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +158 -0
- package/dist/esm/tools/example_tool.js +13 -1
- package/dist/esm/tools/function_tool.js +316 -0
- package/dist/esm/tools/google_api_tool/google_api_tool.js +73 -0
- package/dist/esm/tools/google_api_tool/google_api_toolset.js +146 -0
- package/dist/esm/tools/google_api_tool/google_api_toolsets.js +94 -0
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
- package/dist/esm/tools/google_api_tool/index.js +31 -0
- package/dist/esm/tools/load_artifacts_tool.js +10 -5
- package/dist/esm/tools/load_memory_tool.js +12 -10
- package/dist/esm/tools/mcp/index.js +6 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -14
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +6 -12
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
- package/dist/esm/tools/toolbox_toolset.js +148 -0
- package/dist/esm/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/esm/utils/client_labels.js +19 -2
- package/dist/esm/utils/env_aware_utils.js +6 -8
- package/dist/esm/utils/error_utils.js +9 -10
- package/dist/esm/utils/failover_utils.js +1 -1
- package/dist/esm/utils/file_extension_utils.js +11 -0
- package/dist/esm/utils/file_utils.js +2 -23
- package/dist/esm/utils/gemini_schema_util.js +27 -7
- package/dist/esm/utils/json_utils.js +21 -0
- package/dist/esm/utils/live_connection_utils.js +4 -5
- package/dist/esm/utils/logger_node.js +11 -1
- package/dist/esm/utils/object_notation_utils.js +4 -2
- package/dist/esm/utils/output_schema_utils.js +5 -2
- package/dist/esm/utils/streaming_utils.js +11 -11
- package/dist/esm/utils/task.js +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
- package/dist/types/a2a/agent_card.d.ts +44 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
- package/dist/types/a2a/index.d.ts +1 -0
- package/dist/types/agents/agent_engine_client.d.ts +37 -0
- package/dist/types/agents/base_agent.d.ts +12 -0
- package/dist/types/agents/functions.d.ts +33 -1
- package/dist/types/agents/invocation_context.d.ts +20 -1
- package/dist/types/agents/langgraph_agent.d.ts +153 -0
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/processors/content_processor_utils.d.ts +4 -2
- package/dist/types/agents/processors/nl_planning_processor.d.ts +2 -1
- package/dist/types/auth/auth_handler.d.ts +28 -1
- package/dist/types/auth/auth_schemes.d.ts +13 -0
- package/dist/types/cli/cli_eval.d.ts +173 -0
- package/dist/types/cli/utils/envs.d.ts +23 -0
- package/dist/types/cli/utils/evals.d.ts +47 -0
- package/dist/types/cli/utils/logs.d.ts +38 -0
- package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
- package/dist/types/code_executors/code_executor_context.d.ts +1 -0
- package/dist/types/code_executors/container_code_executor.d.ts +17 -5
- package/dist/types/common.d.ts +24 -5
- package/dist/types/errors/input_validation_error.d.ts +2 -1
- package/dist/types/events/event.d.ts +4 -0
- package/dist/types/examples/example_util.d.ts +17 -0
- package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
- package/dist/types/index.d.ts +19 -2
- package/dist/types/models/gemini_llm_connection.d.ts +6 -7
- package/dist/types/models/routed_llm.d.ts +1 -1
- package/dist/types/plugins/base_plugin.d.ts +0 -10
- package/dist/types/runner/in_memory_runner.d.ts +2 -1
- package/dist/types/runner/runner.d.ts +34 -0
- package/dist/types/sessions/base_session_service.d.ts +5 -0
- package/dist/types/sessions/database_session_service.d.ts +17 -1
- package/dist/types/sessions/stale_session_error.d.ts +21 -0
- package/dist/types/sessions/state.d.ts +5 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
- package/dist/types/skills/loader.d.ts +3 -2
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +20 -4
- package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +115 -0
- package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
- package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
- package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
- package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +109 -0
- package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +229 -0
- package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
- package/dist/types/tools/application_integration_tool/integration_connector_tool.d.ts +70 -0
- package/dist/types/tools/base_toolset.d.ts +6 -5
- package/dist/types/tools/example_tool.d.ts +10 -0
- package/dist/types/tools/function_tool.d.ts +32 -0
- package/dist/types/tools/google_api_tool/google_api_tool.d.ts +37 -0
- package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +55 -0
- package/dist/types/tools/google_api_tool/google_api_toolsets.d.ts +48 -0
- package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +165 -0
- package/dist/types/tools/google_api_tool/index.d.ts +10 -0
- package/dist/types/tools/load_artifacts_tool.d.ts +14 -1
- package/dist/types/tools/load_memory_tool.d.ts +23 -1
- package/dist/types/tools/mcp/index.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +12 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +8 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +5 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +10 -0
- package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
- package/dist/types/tools/toolbox_toolset.d.ts +159 -0
- package/dist/types/utils/client_labels.d.ts +2 -1
- package/dist/types/utils/env_aware_utils.d.ts +18 -2
- package/dist/types/utils/error_utils.d.ts +7 -0
- package/dist/types/utils/file_utils.d.ts +6 -1
- package/dist/types/utils/gemini_schema_util.d.ts +9 -2
- package/dist/types/utils/json_utils.d.ts +11 -0
- package/dist/types/utils/object_notation_utils.d.ts +7 -0
- package/dist/types/utils/output_schema_utils.d.ts +3 -2
- package/dist/types/utils/simple_zod_to_json.d.ts +1 -2
- package/dist/types/utils/streaming_utils.d.ts +11 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +117 -110
- package/dist/web/index_web.js.map +4 -4
- package/package.json +38 -26
- package/dist/cjs/models/gemini_continuation.js +0 -232
- package/dist/esm/models/gemini_continuation.js +0 -205
- package/dist/types/models/gemini_continuation.d.ts +0 -59
|
@@ -0,0 +1,137 @@
|
|
|
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 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, _e;
|
|
63
|
+
super((_a = options.toolFilter) != null ? _a : []);
|
|
64
|
+
this.name = (_b = options.name) != null ? _b : "";
|
|
65
|
+
this.description = (_c = options.description) != null ? _c : "";
|
|
66
|
+
this.apihubResourceName = options.apihubResourceName;
|
|
67
|
+
this.lazyLoadSpec = (_d = options.lazyLoadSpec) != null ? _d : false;
|
|
68
|
+
this.authScheme = options.authScheme;
|
|
69
|
+
this.authCredential = options.authCredential;
|
|
70
|
+
this.apihubClient = (_e = options.apihubClient) != null ? _e : 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
|
+
async close() {
|
|
90
|
+
if (!this.toolsetPromise) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const toolset = await this.toolsetPromise.catch(() => void 0);
|
|
94
|
+
await (toolset == null ? void 0 : toolset.close());
|
|
95
|
+
}
|
|
96
|
+
loadToolset() {
|
|
97
|
+
if (!this.toolsetPromise) {
|
|
98
|
+
const promise = this.prepareTools();
|
|
99
|
+
this.toolsetPromise = promise;
|
|
100
|
+
promise.catch(() => {
|
|
101
|
+
if (this.toolsetPromise === promise) {
|
|
102
|
+
this.toolsetPromise = void 0;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return this.toolsetPromise;
|
|
107
|
+
}
|
|
108
|
+
async prepareTools() {
|
|
109
|
+
var _a, _b, _c, _d;
|
|
110
|
+
const spec = await this.apihubClient.getSpecContent(
|
|
111
|
+
this.apihubResourceName
|
|
112
|
+
);
|
|
113
|
+
if (!spec.trim()) {
|
|
114
|
+
return void 0;
|
|
115
|
+
}
|
|
116
|
+
const specDict = yaml.load(spec);
|
|
117
|
+
if (!specDict) {
|
|
118
|
+
return void 0;
|
|
119
|
+
}
|
|
120
|
+
this.name || (this.name = (0, import_case_utils.toSnakeCaseName)((_b = (_a = specDict.info) == null ? void 0 : _a.title) != null ? _b : "unnamed"));
|
|
121
|
+
this.description || (this.description = (_d = (_c = specDict.info) == null ? void 0 : _c.description) != null ? _d : "");
|
|
122
|
+
return new import_openapi_toolset.OpenAPIToolset({
|
|
123
|
+
specDict,
|
|
124
|
+
authScheme: this.authScheme,
|
|
125
|
+
authCredential: this.authCredential,
|
|
126
|
+
toolFilter: this.toolFilter
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
__name(APIHubToolset, "APIHubToolset");
|
|
131
|
+
APIHubToolset = __decorateClass([
|
|
132
|
+
import_experimental.experimental
|
|
133
|
+
], APIHubToolset);
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
APIHubToolset
|
|
137
|
+
});
|
|
@@ -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
|
+
});
|