@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
|
@@ -38,11 +38,13 @@ var import_base_tool = require("./base_tool.js");
|
|
|
38
38
|
* SPDX-License-Identifier: Apache-2.0
|
|
39
39
|
*/
|
|
40
40
|
const _LoadMemoryTool = class _LoadMemoryTool extends import_base_tool.BaseTool {
|
|
41
|
-
constructor() {
|
|
41
|
+
constructor(options = {}) {
|
|
42
|
+
var _a;
|
|
42
43
|
super({
|
|
43
44
|
name: "load_memory",
|
|
44
45
|
description: "Loads the memory for the current user.\n\nNOTE: Currently this tool only uses text part from the memory."
|
|
45
46
|
});
|
|
47
|
+
this.textOnlyContent = (_a = options.textOnlyContent) != null ? _a : false;
|
|
46
48
|
}
|
|
47
49
|
_getDeclaration() {
|
|
48
50
|
return {
|
|
@@ -64,12 +66,12 @@ const _LoadMemoryTool = class _LoadMemoryTool extends import_base_tool.BaseTool
|
|
|
64
66
|
args,
|
|
65
67
|
toolContext
|
|
66
68
|
}) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
const query = args["query"];
|
|
70
|
+
if (!toolContext.invocationContext.memoryService) {
|
|
71
|
+
throw new Error("Memory service is not initialized.");
|
|
72
|
+
}
|
|
73
|
+
const searchMemoryResponse = await toolContext.searchMemory(query);
|
|
74
|
+
if (this.textOnlyContent) {
|
|
73
75
|
return {
|
|
74
76
|
memories: searchMemoryResponse.memories.map((m) => {
|
|
75
77
|
var _a, _b;
|
|
@@ -84,10 +86,10 @@ const _LoadMemoryTool = class _LoadMemoryTool extends import_base_tool.BaseTool
|
|
|
84
86
|
};
|
|
85
87
|
})
|
|
86
88
|
};
|
|
87
|
-
} catch (e) {
|
|
88
|
-
console.error("ERROR in LoadMemoryTool runAsync:", e);
|
|
89
|
-
throw e;
|
|
90
89
|
}
|
|
90
|
+
return {
|
|
91
|
+
memories: searchMemoryResponse.memories
|
|
92
|
+
};
|
|
91
93
|
}
|
|
92
94
|
async processLlmRequest(request) {
|
|
93
95
|
await super.processLlmRequest(request);
|
|
@@ -9,6 +9,10 @@ var __defProp = Object.defineProperty;
|
|
|
9
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
12
16
|
var __copyProps = (to, from, except, desc) => {
|
|
13
17
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
18
|
for (let key of __getOwnPropNames(from))
|
|
@@ -20,7 +24,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
24
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
26
|
var mcp_exports = {};
|
|
27
|
+
__export(mcp_exports, {
|
|
28
|
+
genaiSchemaToJsonSchema: () => import_genai_schema_to_json.genaiSchemaToJsonSchema,
|
|
29
|
+
toGeminiSchema: () => import_gemini_schema_util.toGeminiSchema
|
|
30
|
+
});
|
|
23
31
|
module.exports = __toCommonJS(mcp_exports);
|
|
32
|
+
var import_gemini_schema_util = require("../../utils/gemini_schema_util.js");
|
|
33
|
+
var import_genai_schema_to_json = require("../../utils/genai_schema_to_json.js");
|
|
24
34
|
__reExport(mcp_exports, require("./load_mcp_resource_tool.js"), module.exports);
|
|
25
35
|
__reExport(mcp_exports, require("./mcp_session_manager.js"), module.exports);
|
|
26
36
|
__reExport(mcp_exports, require("./mcp_tool.js"), module.exports);
|
|
@@ -32,6 +42,8 @@ __reExport(mcp_exports, require("./mcp_toolset.js"), module.exports);
|
|
|
32
42
|
*/
|
|
33
43
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
44
|
0 && (module.exports = {
|
|
45
|
+
genaiSchemaToJsonSchema,
|
|
46
|
+
toGeminiSchema,
|
|
35
47
|
...require("./load_mcp_resource_tool.js"),
|
|
36
48
|
...require("./mcp_session_manager.js"),
|
|
37
49
|
...require("./mcp_tool.js"),
|
|
@@ -67,6 +67,18 @@ function buildTransportOptions(params) {
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
__name(buildTransportOptions, "buildTransportOptions");
|
|
70
|
+
function buildSseTransportOptions(params) {
|
|
71
|
+
const { transportOptions, header, headers } = params;
|
|
72
|
+
const callerHeaders = (transportOptions == null ? void 0 : transportOptions.requestInit) === void 0 ? header != null ? header : headers : transportOptions.requestInit.headers;
|
|
73
|
+
return {
|
|
74
|
+
...transportOptions,
|
|
75
|
+
requestInit: {
|
|
76
|
+
...transportOptions == null ? void 0 : transportOptions.requestInit,
|
|
77
|
+
headers: (0, import_client_labels.mergeTrackingHeaders)(callerHeaders)
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
__name(buildSseTransportOptions, "buildSseTransportOptions");
|
|
70
82
|
const _MCPSessionManager = class _MCPSessionManager {
|
|
71
83
|
constructor(connectionParams) {
|
|
72
84
|
this.activeSessions = /* @__PURE__ */ new Set();
|
|
@@ -105,6 +117,19 @@ const _MCPSessionManager = class _MCPSessionManager {
|
|
|
105
117
|
await client.connect(transport);
|
|
106
118
|
break;
|
|
107
119
|
}
|
|
120
|
+
case "SseConnectionParams": {
|
|
121
|
+
const { SSEClientTransport } = await (0, import_optional_peer.loadOptionalPeer)(
|
|
122
|
+
MCP_SDK,
|
|
123
|
+
() => Promise.resolve().then(() => __toESM(require("@modelcontextprotocol/sdk/client/sse.js"), 1))
|
|
124
|
+
);
|
|
125
|
+
const transport = new SSEClientTransport(
|
|
126
|
+
new URL(this.connectionParams.url),
|
|
127
|
+
buildSseTransportOptions(this.connectionParams)
|
|
128
|
+
);
|
|
129
|
+
transport.onerror = logTransportError;
|
|
130
|
+
await client.connect(transport);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
108
133
|
default: {
|
|
109
134
|
const _exhaustiveCheck = this.connectionParams;
|
|
110
135
|
break;
|
|
@@ -61,20 +61,7 @@ const _MCPToolset = class _MCPToolset extends import_base_toolset.BaseToolset {
|
|
|
61
61
|
};
|
|
62
62
|
return new import_mcp_tool.MCPTool(toolWithPrefix, this.mcpSessionManager, tool.name);
|
|
63
63
|
});
|
|
64
|
-
|
|
65
|
-
if (!filter || Array.isArray(filter) && filter.length === 0) {
|
|
66
|
-
return tools;
|
|
67
|
-
}
|
|
68
|
-
if (Array.isArray(filter)) {
|
|
69
|
-
return tools.filter((tool) => filter.includes(tool.name));
|
|
70
|
-
}
|
|
71
|
-
if (context) {
|
|
72
|
-
return tools.filter((tool) => filter(tool, context));
|
|
73
|
-
}
|
|
74
|
-
import_logger.logger.warn(
|
|
75
|
-
"MCPToolset: a ToolPredicate toolFilter was provided but getTools() was called without a ReadonlyContext. The filter will not be applied."
|
|
76
|
-
);
|
|
77
|
-
return tools;
|
|
64
|
+
return tools.filter((tool) => this.isToolSelected(tool, context));
|
|
78
65
|
}
|
|
79
66
|
/**
|
|
80
67
|
* Lists the names of the resources advertised by the MCP server.
|
|
@@ -165,12 +165,11 @@ function bearerJwtScheme() {
|
|
|
165
165
|
}
|
|
166
166
|
__name(bearerJwtScheme, "bearerJwtScheme");
|
|
167
167
|
function bearerTokenParam(authScheme, token) {
|
|
168
|
-
var _a;
|
|
169
168
|
const param = {
|
|
170
169
|
originalName: "Authorization",
|
|
171
170
|
paramLocation: "header",
|
|
172
171
|
paramSchema: { type: "string" },
|
|
173
|
-
description:
|
|
172
|
+
description: authScheme.description || "Bearer token",
|
|
174
173
|
name: `${INTERNAL_AUTH_PREFIX}Authorization`,
|
|
175
174
|
required: true
|
|
176
175
|
};
|
package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js
CHANGED
|
@@ -37,14 +37,48 @@ __export(auto_auth_credential_exchanger_exports, {
|
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(auto_auth_credential_exchanger_exports);
|
|
39
39
|
var import_auth_credential = require("../../../../auth/auth_credential.js");
|
|
40
|
+
var import_auth_schemes = require("../../../../auth/auth_schemes.js");
|
|
40
41
|
var import_oauth2_credential_exchanger = require("../../../../auth/oauth2/oauth2_credential_exchanger.js");
|
|
41
42
|
var import_experimental = require("../../../../utils/experimental.js");
|
|
43
|
+
var import_oauth2_exchanger = require("./oauth2_exchanger.js");
|
|
42
44
|
var import_service_account_exchanger = require("./service_account_exchanger.js");
|
|
43
45
|
/**
|
|
44
46
|
* @license
|
|
45
47
|
* Copyright 2026 Google LLC
|
|
46
48
|
* SPDX-License-Identifier: Apache-2.0
|
|
47
49
|
*/
|
|
50
|
+
function isPendingAuthorizationCode(authScheme, authCredential) {
|
|
51
|
+
var _a, _b, _c;
|
|
52
|
+
return !!authScheme && (0, import_oauth2_credential_exchanger.determineGrantType)(authScheme) === import_auth_schemes.OAuthGrantType.AUTHORIZATION_CODE && !((_a = authCredential.oauth2) == null ? void 0 : _a.accessToken) && !((_b = authCredential.oauth2) == null ? void 0 : _b.authCode) && !((_c = authCredential.oauth2) == null ? void 0 : _c.authResponseUri);
|
|
53
|
+
}
|
|
54
|
+
__name(isPendingAuthorizationCode, "isPendingAuthorizationCode");
|
|
55
|
+
function createDefaultOAuth2Exchanger() {
|
|
56
|
+
const tokenFetcher = new import_oauth2_credential_exchanger.OAuth2CredentialExchanger();
|
|
57
|
+
return {
|
|
58
|
+
async exchange(params) {
|
|
59
|
+
const { authScheme, authCredential } = params;
|
|
60
|
+
if (authScheme && authCredential.http) {
|
|
61
|
+
return {
|
|
62
|
+
credential: authCredential,
|
|
63
|
+
wasExchanged: false
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (isPendingAuthorizationCode(authScheme, authCredential)) {
|
|
67
|
+
return {
|
|
68
|
+
credential: authCredential,
|
|
69
|
+
wasExchanged: false
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const { credential, wasExchanged } = await tokenFetcher.exchange(params);
|
|
73
|
+
const bearer = (0, import_oauth2_exchanger.generateAuthToken)(credential);
|
|
74
|
+
return {
|
|
75
|
+
credential: bearer,
|
|
76
|
+
wasExchanged: wasExchanged || bearer !== credential
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
__name(createDefaultOAuth2Exchanger, "createDefaultOAuth2Exchanger");
|
|
48
82
|
let AutoAuthCredentialExchanger = class {
|
|
49
83
|
/**
|
|
50
84
|
* @param customExchangers - Optional exchangers that add to or override the
|
|
@@ -52,14 +86,24 @@ let AutoAuthCredentialExchanger = class {
|
|
|
52
86
|
* exchanger instance to use for that type.
|
|
53
87
|
*/
|
|
54
88
|
constructor(customExchangers) {
|
|
89
|
+
/**
|
|
90
|
+
* The exchanger used for each auth credential type.
|
|
91
|
+
*
|
|
92
|
+
* By default `OAUTH2` and `OPEN_ID_CONNECT` run
|
|
93
|
+
* {@link OAuth2CredentialExchanger} and convert any access token with
|
|
94
|
+
* {@link generateAuthToken}, and `SERVICE_ACCOUNT` maps to a
|
|
95
|
+
* {@link ServiceAccountCredentialExchanger}, with any custom exchangers from
|
|
96
|
+
* the constructor merged over them. The map is live: an entry added or
|
|
97
|
+
* replaced after construction is used by the next {@link exchange} call.
|
|
98
|
+
*/
|
|
55
99
|
this.exchangers = /* @__PURE__ */ new Map();
|
|
56
100
|
this.exchangers.set(
|
|
57
101
|
import_auth_credential.AuthCredentialTypes.OAUTH2,
|
|
58
|
-
|
|
102
|
+
createDefaultOAuth2Exchanger()
|
|
59
103
|
);
|
|
60
104
|
this.exchangers.set(
|
|
61
105
|
import_auth_credential.AuthCredentialTypes.OPEN_ID_CONNECT,
|
|
62
|
-
|
|
106
|
+
createDefaultOAuth2Exchanger()
|
|
63
107
|
);
|
|
64
108
|
this.exchangers.set(
|
|
65
109
|
import_auth_credential.AuthCredentialTypes.SERVICE_ACCOUNT,
|
|
@@ -40,6 +40,7 @@ __export(oauth2_exchanger_exports, {
|
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(oauth2_exchanger_exports);
|
|
42
42
|
var import_auth_credential = require("../../../../auth/auth_credential.js");
|
|
43
|
+
var import_auth_schemes = require("../../../../auth/auth_schemes.js");
|
|
43
44
|
var import_experimental = require("../../../../utils/experimental.js");
|
|
44
45
|
/**
|
|
45
46
|
* @license
|
|
@@ -52,7 +53,7 @@ function checkSchemeCredentialType(authScheme, authCredential) {
|
|
|
52
53
|
"auth_credential is empty. Please create AuthCredential using OAuth2Auth."
|
|
53
54
|
);
|
|
54
55
|
}
|
|
55
|
-
if (authScheme.type !==
|
|
56
|
+
if (authScheme.type !== import_auth_schemes.AuthSchemeType.OPEN_ID_CONNECT && authScheme.type !== import_auth_schemes.AuthSchemeType.OAUTH2) {
|
|
56
57
|
throw new Error(
|
|
57
58
|
`Invalid security scheme, expect AuthSchemeType.openIdConnect or AuthSchemeType.oauth2 auth scheme, but got ${authScheme.type}`
|
|
58
59
|
);
|
|
@@ -80,12 +81,12 @@ function generateAuthToken(authCredential) {
|
|
|
80
81
|
}
|
|
81
82
|
__name(generateAuthToken, "generateAuthToken");
|
|
82
83
|
function exchangeCredential(authScheme, authCredential) {
|
|
83
|
-
var _a
|
|
84
|
+
var _a;
|
|
84
85
|
checkSchemeCredentialType(authScheme, authCredential);
|
|
85
86
|
if (authCredential.http) {
|
|
86
87
|
return authCredential;
|
|
87
88
|
}
|
|
88
|
-
if ((
|
|
89
|
+
if ((_a = authCredential.oauth2) == null ? void 0 : _a.accessToken) {
|
|
89
90
|
return generateAuthToken(authCredential);
|
|
90
91
|
}
|
|
91
92
|
return null;
|
|
@@ -37,6 +37,7 @@ __export(service_account_exchanger_exports, {
|
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(service_account_exchanger_exports);
|
|
39
39
|
var import_google_auth_library = require("google-auth-library");
|
|
40
|
+
var import_node_crypto = require("node:crypto");
|
|
40
41
|
var import_auth_credential = require("../../../../auth/auth_credential.js");
|
|
41
42
|
var import_experimental = require("../../../../utils/experimental.js");
|
|
42
43
|
var import_base_auth_credential_exchanger = require("./base_auth_credential_exchanger.js");
|
|
@@ -47,6 +48,83 @@ var import_base_auth_credential_exchanger = require("./base_auth_credential_exch
|
|
|
47
48
|
*/
|
|
48
49
|
const DEFAULT_SCOPES = ["https://www.googleapis.com/auth/cloud-platform"];
|
|
49
50
|
const MISSING_SERVICE_ACCOUNT_CREDENTIALS = "Service account credentials are missing. Please provide them, or set `useDefaultCredential: true` to use application default credentials in a hosted service like Cloud Run.";
|
|
51
|
+
const GOOGLE_TOKEN_URI = "https://oauth2.googleapis.com/token";
|
|
52
|
+
const JWT_BEARER_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
|
53
|
+
const ASSERTION_LIFETIME_SECONDS = 3600;
|
|
54
|
+
const TOKEN_REQUEST_TIMEOUT_MS = 3e4;
|
|
55
|
+
function hasCustomTokenUri(creds) {
|
|
56
|
+
return !!creds.tokenUri && creds.tokenUri !== GOOGLE_TOKEN_URI;
|
|
57
|
+
}
|
|
58
|
+
__name(hasCustomTokenUri, "hasCustomTokenUri");
|
|
59
|
+
function base64UrlJson(value) {
|
|
60
|
+
return Buffer.from(JSON.stringify(value)).toString("base64url");
|
|
61
|
+
}
|
|
62
|
+
__name(base64UrlJson, "base64UrlJson");
|
|
63
|
+
function signJwtBearerAssertion(creds, scopes, issuedAt) {
|
|
64
|
+
const header = {
|
|
65
|
+
alg: "RS256",
|
|
66
|
+
typ: "JWT",
|
|
67
|
+
...creds.privateKeyId ? { kid: creds.privateKeyId } : {}
|
|
68
|
+
};
|
|
69
|
+
const payload = {
|
|
70
|
+
iss: creds.clientEmail,
|
|
71
|
+
scope: scopes.join(" "),
|
|
72
|
+
aud: GOOGLE_TOKEN_URI,
|
|
73
|
+
iat: issuedAt,
|
|
74
|
+
exp: issuedAt + ASSERTION_LIFETIME_SECONDS
|
|
75
|
+
};
|
|
76
|
+
const signingInput = `${base64UrlJson(header)}.${base64UrlJson(payload)}`;
|
|
77
|
+
const signature = (0, import_node_crypto.createSign)("RSA-SHA256").update(signingInput).sign(creds.privateKey, "base64url");
|
|
78
|
+
return `${signingInput}.${signature}`;
|
|
79
|
+
}
|
|
80
|
+
__name(signJwtBearerAssertion, "signJwtBearerAssertion");
|
|
81
|
+
async function readTokenErrorDetail(response) {
|
|
82
|
+
try {
|
|
83
|
+
const body = await response.json();
|
|
84
|
+
if (typeof body !== "object" || body === null) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
const parts = [];
|
|
88
|
+
if ("error" in body && typeof body.error === "string" && body.error.length > 0) {
|
|
89
|
+
parts.push(body.error);
|
|
90
|
+
}
|
|
91
|
+
if ("error_description" in body && typeof body.error_description === "string" && body.error_description.length > 0) {
|
|
92
|
+
parts.push(body.error_description);
|
|
93
|
+
}
|
|
94
|
+
return parts.length > 0 ? parts.join(": ") : void 0;
|
|
95
|
+
} catch {
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
__name(readTokenErrorDetail, "readTokenErrorDetail");
|
|
100
|
+
async function requestJwtBearerToken(creds, scopes) {
|
|
101
|
+
const assertion = signJwtBearerAssertion(
|
|
102
|
+
creds,
|
|
103
|
+
scopes,
|
|
104
|
+
Math.floor(Date.now() / 1e3)
|
|
105
|
+
);
|
|
106
|
+
const response = await fetch(creds.tokenUri, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
109
|
+
body: new URLSearchParams({
|
|
110
|
+
grant_type: JWT_BEARER_GRANT_TYPE,
|
|
111
|
+
assertion
|
|
112
|
+
}),
|
|
113
|
+
signal: AbortSignal.timeout(TOKEN_REQUEST_TIMEOUT_MS)
|
|
114
|
+
});
|
|
115
|
+
if (!response.ok) {
|
|
116
|
+
const detail = await readTokenErrorDetail(response);
|
|
117
|
+
throw new Error(
|
|
118
|
+
detail ? `Token endpoint responded with HTTP ${response.status}: ${detail}` : `Token endpoint responded with HTTP ${response.status}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
const body = await response.json();
|
|
122
|
+
if (typeof body === "object" && body !== null && "access_token" in body && typeof body.access_token === "string") {
|
|
123
|
+
return body.access_token;
|
|
124
|
+
}
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
__name(requestJwtBearerToken, "requestJwtBearerToken");
|
|
50
128
|
let ServiceAccountCredentialExchanger = class {
|
|
51
129
|
async exchange(params) {
|
|
52
130
|
const { authCredential } = params;
|
|
@@ -87,21 +165,27 @@ let ServiceAccountCredentialExchanger = class {
|
|
|
87
165
|
}
|
|
88
166
|
}
|
|
89
167
|
async exchangeForExplicitCredential(saConfig) {
|
|
168
|
+
var _a;
|
|
90
169
|
const creds = saConfig.serviceAccountCredential;
|
|
91
170
|
if (!creds) {
|
|
92
171
|
throw new import_base_auth_credential_exchanger.AuthCredentialMissingError(MISSING_SERVICE_ACCOUNT_CREDENTIALS);
|
|
93
172
|
}
|
|
94
173
|
try {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
174
|
+
let token;
|
|
175
|
+
if (hasCustomTokenUri(creds)) {
|
|
176
|
+
token = await requestJwtBearerToken(creds, (_a = saConfig.scopes) != null ? _a : []);
|
|
177
|
+
} else {
|
|
178
|
+
const client = new import_google_auth_library.JWT({
|
|
179
|
+
email: creds.clientEmail,
|
|
180
|
+
key: creds.privateKey,
|
|
181
|
+
keyId: creds.privateKeyId,
|
|
182
|
+
projectId: creds.projectId,
|
|
183
|
+
universeDomain: creds.universeDomain,
|
|
184
|
+
scopes: saConfig.scopes
|
|
185
|
+
});
|
|
186
|
+
const tokens = await client.authorize();
|
|
187
|
+
token = tokens.access_token;
|
|
188
|
+
}
|
|
105
189
|
if (!token) {
|
|
106
190
|
throw new Error("Failed to get access token from explicit credentials");
|
|
107
191
|
}
|
|
@@ -54,15 +54,27 @@ const VALID_SCHEMA_TYPES = /* @__PURE__ */ new Set([
|
|
|
54
54
|
"string"
|
|
55
55
|
]);
|
|
56
56
|
let OpenApiSpecParser = class {
|
|
57
|
+
/**
|
|
58
|
+
* @param options.preservePropertyNames Keeps the original parameter and
|
|
59
|
+
* function names instead of converting them to snake_case.
|
|
60
|
+
* @param options.unconstrainedObjectBodyAsParameter Emits a whole-body
|
|
61
|
+
* parameter named `body` when an object request body schema has no
|
|
62
|
+
* properties. Defaults to `false`.
|
|
63
|
+
* @deprecated Retained for backwards compatibility; empty object schemas
|
|
64
|
+
* produce no parameters by default. This option will be removed in a
|
|
65
|
+
* future release.
|
|
66
|
+
*/
|
|
57
67
|
constructor(options = {}) {
|
|
58
|
-
var _a;
|
|
68
|
+
var _a, _b;
|
|
59
69
|
this.preservePropertyNames = (_a = options.preservePropertyNames) != null ? _a : false;
|
|
70
|
+
this.unconstrainedObjectBodyAsParameter = (_b = options.unconstrainedObjectBodyAsParameter) != null ? _b : false;
|
|
60
71
|
}
|
|
61
72
|
parse(openapiSpec) {
|
|
62
73
|
const resolvedSpec = resolveReferences(openapiSpec);
|
|
63
74
|
const sanitizedSpec = sanitizeSchemaTypes(resolvedSpec);
|
|
64
75
|
return collectOperations(sanitizedSpec, {
|
|
65
|
-
preservePropertyNames: this.preservePropertyNames
|
|
76
|
+
preservePropertyNames: this.preservePropertyNames,
|
|
77
|
+
unconstrainedObjectBodyAsParameter: this.unconstrainedObjectBodyAsParameter
|
|
66
78
|
});
|
|
67
79
|
}
|
|
68
80
|
};
|
|
@@ -197,17 +209,18 @@ function resolveServerUrl(server) {
|
|
|
197
209
|
}
|
|
198
210
|
__name(resolveServerUrl, "resolveServerUrl");
|
|
199
211
|
function collectOperations(spec, options = {}) {
|
|
200
|
-
var _a, _b, _c;
|
|
212
|
+
var _a, _b, _c, _d;
|
|
201
213
|
const preservePropertyNames = (_a = options.preservePropertyNames) != null ? _a : false;
|
|
214
|
+
const unconstrainedObjectBodyAsParameter = (_b = options.unconstrainedObjectBodyAsParameter) != null ? _b : false;
|
|
202
215
|
const operations = [];
|
|
203
|
-
const server = (
|
|
216
|
+
const server = (_c = spec.servers) == null ? void 0 : _c[0];
|
|
204
217
|
const baseUrl = server ? resolveServerUrl(server) : "";
|
|
205
218
|
const globalSecurity = spec.security || [];
|
|
206
219
|
let globalSchemeName;
|
|
207
220
|
if (globalSecurity.length > 0) {
|
|
208
221
|
globalSchemeName = Object.keys(globalSecurity[0])[0];
|
|
209
222
|
}
|
|
210
|
-
const authSchemes = ((
|
|
223
|
+
const authSchemes = ((_d = spec.components) == null ? void 0 : _d.securitySchemes) || {};
|
|
211
224
|
for (const [path, pathItem] of Object.entries(spec.paths || {})) {
|
|
212
225
|
if (!pathItem) continue;
|
|
213
226
|
const methods = [
|
|
@@ -230,7 +243,8 @@ function collectOperations(spec, options = {}) {
|
|
|
230
243
|
operation.operationId = (0, import_case_utils.toSnakeCaseName)(`${path}_${method}`);
|
|
231
244
|
}
|
|
232
245
|
const parser = new import_operation_parser.OperationParser(operation, {
|
|
233
|
-
preservePropertyNames
|
|
246
|
+
preservePropertyNames,
|
|
247
|
+
unconstrainedObjectBodyAsParameter
|
|
234
248
|
});
|
|
235
249
|
let authSchemeName;
|
|
236
250
|
if (operation.security && operation.security.length > 0) {
|
|
@@ -52,13 +52,20 @@ let OperationParser = class {
|
|
|
52
52
|
* function names instead of converting them to snake_case.
|
|
53
53
|
* @param options.shouldParse Whether to parse the operation during
|
|
54
54
|
* construction. Defaults to `true`.
|
|
55
|
+
* @param options.unconstrainedObjectBodyAsParameter Emits a whole-body
|
|
56
|
+
* parameter named `body` when an object request body schema has no
|
|
57
|
+
* properties. Defaults to `false`.
|
|
58
|
+
* @deprecated Retained for backwards compatibility; empty object schemas
|
|
59
|
+
* produce no parameters by default. This option will be removed in a
|
|
60
|
+
* future release.
|
|
55
61
|
*/
|
|
56
62
|
constructor(operation, options = {}) {
|
|
57
63
|
this.params = [];
|
|
58
|
-
var _a, _b;
|
|
64
|
+
var _a, _b, _c;
|
|
59
65
|
this.operation = typeof operation === "string" ? JSON.parse(operation) : operation;
|
|
60
66
|
this.preservePropertyNames = (_a = options.preservePropertyNames) != null ? _a : false;
|
|
61
|
-
|
|
67
|
+
this.unconstrainedObjectBodyAsParameter = (_b = options.unconstrainedObjectBodyAsParameter) != null ? _b : false;
|
|
68
|
+
if ((_c = options.shouldParse) != null ? _c : true) {
|
|
62
69
|
this.processOperationParameters();
|
|
63
70
|
this.processRequestBody();
|
|
64
71
|
this.returnValue = this.processReturnValue();
|
|
@@ -78,6 +85,7 @@ let OperationParser = class {
|
|
|
78
85
|
return (0, import_case_utils.renameReservedKeywords)((0, import_case_utils.toSnakeCaseName)(originalName));
|
|
79
86
|
}
|
|
80
87
|
processOperationParameters() {
|
|
88
|
+
var _a;
|
|
81
89
|
const parameters = this.operation.parameters || [];
|
|
82
90
|
for (const param of parameters) {
|
|
83
91
|
if ("name" in param) {
|
|
@@ -88,9 +96,12 @@ let OperationParser = class {
|
|
|
88
96
|
this.params.push({
|
|
89
97
|
originalName,
|
|
90
98
|
paramLocation: location,
|
|
91
|
-
paramSchema:
|
|
99
|
+
paramSchema: {
|
|
100
|
+
...schema,
|
|
101
|
+
description: schema.description || description || void 0
|
|
102
|
+
},
|
|
92
103
|
description,
|
|
93
|
-
required: param.required
|
|
104
|
+
required: (_a = param.required) != null ? _a : false,
|
|
94
105
|
name: this.getParamName(originalName)
|
|
95
106
|
});
|
|
96
107
|
}
|
|
@@ -126,7 +137,7 @@ let OperationParser = class {
|
|
|
126
137
|
});
|
|
127
138
|
}
|
|
128
139
|
}
|
|
129
|
-
} else {
|
|
140
|
+
} else if (this.unconstrainedObjectBodyAsParameter) {
|
|
130
141
|
this.params.push({
|
|
131
142
|
originalName: "",
|
|
132
143
|
paramLocation: "body",
|
|
@@ -147,7 +158,7 @@ let OperationParser = class {
|
|
|
147
158
|
});
|
|
148
159
|
} else {
|
|
149
160
|
this.params.push({
|
|
150
|
-
originalName: "
|
|
161
|
+
originalName: "",
|
|
151
162
|
paramLocation: "body",
|
|
152
163
|
paramSchema: schema,
|
|
153
164
|
description,
|
|
@@ -50,6 +50,16 @@ var import_base_auth_credential_exchanger = require("../auth/credential_exchange
|
|
|
50
50
|
* SPDX-License-Identifier: Apache-2.0
|
|
51
51
|
*/
|
|
52
52
|
const DEFAULT_CREDENTIAL_KEY = "default_openapi_key";
|
|
53
|
+
const INTERACTIVE_CREDENTIAL_TYPES = /* @__PURE__ */ new Set([
|
|
54
|
+
import_auth_credential.AuthCredentialTypes.OAUTH2,
|
|
55
|
+
import_auth_credential.AuthCredentialTypes.OPEN_ID_CONNECT
|
|
56
|
+
]);
|
|
57
|
+
function isMissingInteractiveToken(result) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const { credential, wasExchanged } = result;
|
|
60
|
+
return !wasExchanged && INTERACTIVE_CREDENTIAL_TYPES.has(credential.authType) && !credential.http && !((_a = credential.oauth2) == null ? void 0 : _a.accessToken) && !((_b = credential.oauth2) == null ? void 0 : _b.refreshToken);
|
|
61
|
+
}
|
|
62
|
+
__name(isMissingInteractiveToken, "isMissingInteractiveToken");
|
|
53
63
|
const _ToolContextCredentialStore = class _ToolContextCredentialStore {
|
|
54
64
|
constructor(context) {
|
|
55
65
|
this.context = context;
|
|
@@ -165,7 +175,8 @@ let ToolAuthHandler = class {
|
|
|
165
175
|
};
|
|
166
176
|
}
|
|
167
177
|
/**
|
|
168
|
-
* Exchanges `credential`, or returns `undefined` when the exchange failed
|
|
178
|
+
* Exchanges `credential`, or returns `undefined` when the exchange failed or
|
|
179
|
+
* produced an interactive credential that still holds no token.
|
|
169
180
|
*
|
|
170
181
|
* An exchange failure is transient far more often than it is fatal, so it
|
|
171
182
|
* becomes a `pending` result the client can resume from rather than an
|
|
@@ -175,10 +186,11 @@ let ToolAuthHandler = class {
|
|
|
175
186
|
var _a;
|
|
176
187
|
const exchanger = (_a = this.credentialExchanger) != null ? _a : new import_auto_auth_credential_exchanger.AutoAuthCredentialExchanger();
|
|
177
188
|
try {
|
|
178
|
-
|
|
189
|
+
const result = await exchanger.exchange({
|
|
179
190
|
authScheme: this.authScheme,
|
|
180
191
|
authCredential: credential
|
|
181
192
|
});
|
|
193
|
+
return isMissingInteractiveToken(result) ? void 0 : result;
|
|
182
194
|
} catch (e) {
|
|
183
195
|
import_logger.logger.error(
|
|
184
196
|
`Failed to exchange credential: ${e instanceof Error ? e.message : e}`
|
|
@@ -46,7 +46,7 @@ __export(openapi_toolset_exports, {
|
|
|
46
46
|
OpenAPIToolset: () => OpenAPIToolset
|
|
47
47
|
});
|
|
48
48
|
module.exports = __toCommonJS(openapi_toolset_exports);
|
|
49
|
-
var
|
|
49
|
+
var yaml = __toESM(require("js-yaml"), 1);
|
|
50
50
|
var import_experimental = require("../../utils/experimental.js");
|
|
51
51
|
var import_logger = require("../../utils/logger.js");
|
|
52
52
|
var import_base_toolset = require("../base_toolset.js");
|
|
@@ -64,7 +64,7 @@ let OpenAPIToolset = class extends import_base_toolset.BaseToolset {
|
|
|
64
64
|
let spec = options.specDict;
|
|
65
65
|
if (!spec && options.specStr) {
|
|
66
66
|
if (options.specType === "yaml" || !options.specType && options.specStr.trim().startsWith("---")) {
|
|
67
|
-
spec =
|
|
67
|
+
spec = yaml.load(options.specStr);
|
|
68
68
|
} else if (options.specType === "json" || !options.specType) {
|
|
69
69
|
spec = JSON.parse(options.specStr);
|
|
70
70
|
} else {
|
|
@@ -75,7 +75,8 @@ let OpenAPIToolset = class extends import_base_toolset.BaseToolset {
|
|
|
75
75
|
throw new Error("Either specDict or specStr must be provided.");
|
|
76
76
|
}
|
|
77
77
|
const parser = new import_openapi_spec_parser.OpenApiSpecParser({
|
|
78
|
-
preservePropertyNames: options.preservePropertyNames
|
|
78
|
+
preservePropertyNames: options.preservePropertyNames,
|
|
79
|
+
unconstrainedObjectBodyAsParameter: options.unconstrainedObjectBodyAsParameter
|
|
79
80
|
});
|
|
80
81
|
const parsedOperations = parser.parse(spec);
|
|
81
82
|
for (const op of parsedOperations) {
|
|
@@ -96,7 +97,8 @@ let OpenAPIToolset = class extends import_base_toolset.BaseToolset {
|
|
|
96
97
|
{
|
|
97
98
|
preservePropertyNames: options.preservePropertyNames,
|
|
98
99
|
headerProvider: options.headerProvider,
|
|
99
|
-
credentialKey: options.credentialKey
|
|
100
|
+
credentialKey: options.credentialKey,
|
|
101
|
+
unconstrainedObjectBodyAsParameter: options.unconstrainedObjectBodyAsParameter
|
|
100
102
|
}
|
|
101
103
|
);
|
|
102
104
|
this.tools.push(tool);
|
|
@@ -111,15 +113,7 @@ let OpenAPIToolset = class extends import_base_toolset.BaseToolset {
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
async getTools(context) {
|
|
114
|
-
return this.tools.filter((tool) =>
|
|
115
|
-
if (Array.isArray(this.toolFilter) && this.toolFilter.length > 0) {
|
|
116
|
-
return this.toolFilter.includes(tool.name);
|
|
117
|
-
}
|
|
118
|
-
if (context) {
|
|
119
|
-
return this.isToolSelected(tool, context);
|
|
120
|
-
}
|
|
121
|
-
return true;
|
|
122
|
-
});
|
|
116
|
+
return this.tools.filter((tool) => this.isToolSelected(tool, context));
|
|
123
117
|
}
|
|
124
118
|
getTool(toolName) {
|
|
125
119
|
return this.tools.find((tool) => tool.name === toolName);
|
|
@@ -203,6 +203,22 @@ function encodePathParamValue(name, value) {
|
|
|
203
203
|
return encodeURIComponent(value);
|
|
204
204
|
}
|
|
205
205
|
__name(encodePathParamValue, "encodePathParamValue");
|
|
206
|
+
function serializeQueryValue(value) {
|
|
207
|
+
return typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
|
|
208
|
+
}
|
|
209
|
+
__name(serializeQueryValue, "serializeQueryValue");
|
|
210
|
+
function appendQueryParam(queryParams, name, value) {
|
|
211
|
+
if (!Array.isArray(value)) {
|
|
212
|
+
queryParams.append(name, serializeQueryValue(value));
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
for (const item of value) {
|
|
216
|
+
if (item !== void 0 && item !== null) {
|
|
217
|
+
queryParams.append(name, serializeQueryValue(item));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
__name(appendQueryParam, "appendQueryParam");
|
|
206
222
|
function prepareRequestParams(endpoint, parameters, args) {
|
|
207
223
|
const headers = {};
|
|
208
224
|
const queryParams = new URLSearchParams();
|
|
@@ -223,7 +239,7 @@ function prepareRequestParams(endpoint, parameters, args) {
|
|
|
223
239
|
);
|
|
224
240
|
} else if (location === "query") {
|
|
225
241
|
if (argValue !== void 0 && argValue !== null && argValue !== "") {
|
|
226
|
-
queryParams
|
|
242
|
+
appendQueryParam(queryParams, originalName, argValue);
|
|
227
243
|
}
|
|
228
244
|
} else if (location === "header") {
|
|
229
245
|
headers[originalName] = String(argValue);
|