@google/adk 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/base_agent.js +19 -1
- package/dist/cjs/agents/functions.js +4 -0
- package/dist/cjs/agents/instructions.js +81 -33
- package/dist/cjs/agents/invocation_context.js +0 -1
- package/dist/cjs/agents/llm_agent.js +52 -5
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
- package/dist/cjs/agents/processors/content_request_processor.js +7 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/cjs/auth/auth_preprocessor.js +12 -10
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +7 -7
- package/dist/cjs/common.js +50 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
- package/dist/cjs/context/token_based_context_compactor.js +1 -1
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +122 -0
- package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
- package/dist/cjs/integrations/agent_registry/types.js +50 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
- package/dist/cjs/models/gemini_llm_connection.js +62 -19
- package/dist/cjs/models/google_llm.js +26 -8
- package/dist/cjs/plugins/security_plugin.js +16 -0
- package/dist/cjs/runner/in_memory_runner.js +10 -5
- package/dist/cjs/runner/runner.js +32 -2
- package/dist/cjs/sessions/base_session_service.js +13 -2
- package/dist/cjs/sessions/database_session_service.js +51 -5
- package/dist/cjs/sessions/db/schema.js +45 -10
- package/dist/cjs/sessions/in_memory_session_service.js +72 -15
- package/dist/cjs/sessions/registry.js +4 -0
- package/dist/cjs/sessions/vertex_ai_session_service.js +429 -0
- package/dist/cjs/skills/gcp_skill_registry.js +104 -0
- package/dist/cjs/skills/loader.js +65 -0
- package/dist/cjs/skills/skill_registry.js +27 -0
- package/dist/cjs/tools/agent_tool.js +10 -5
- package/dist/cjs/tools/exit_loop_tool.js +9 -0
- package/dist/cjs/tools/function_tool.js +7 -2
- package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
- package/dist/cjs/tools/long_running_tool.js +2 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/cjs/tools/mcp/mcp_tool.js +10 -6
- package/dist/cjs/tools/mcp/mcp_toolset.js +26 -3
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +127 -0
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +27 -28
- package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
- package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
- package/dist/cjs/tools/skill/skill_toolset.js +40 -5
- package/dist/cjs/tools/vertex_rag_retrieval_tool.js +64 -0
- package/dist/cjs/utils/async_queue.js +88 -0
- package/dist/cjs/utils/case_utils.js +53 -0
- package/dist/cjs/utils/env_aware_utils.js +4 -0
- package/dist/cjs/utils/file_utils.js +28 -0
- package/dist/cjs/utils/gemini_schema_util.js +18 -0
- package/dist/cjs/utils/live_connection_utils.js +284 -0
- package/dist/cjs/utils/model_name.js +9 -0
- package/dist/cjs/utils/partial_copy.js +51 -0
- package/dist/cjs/utils/streaming_utils.js +169 -122
- package/dist/cjs/utils/vertex_ai_utils.js +50 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +19 -1
- package/dist/esm/agents/functions.js +4 -0
- package/dist/esm/agents/instructions.js +81 -33
- package/dist/esm/agents/invocation_context.js +0 -1
- package/dist/esm/agents/llm_agent.js +53 -5
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/esm/agents/processors/content_processor_utils.js +35 -23
- package/dist/esm/agents/processors/content_request_processor.js +7 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/esm/auth/auth_preprocessor.js +12 -10
- package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/esm/code_executors/code_execution_utils.js +1 -1
- package/dist/esm/code_executors/code_executor_context.js +7 -7
- package/dist/esm/common.js +43 -1
- package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
- package/dist/esm/context/token_based_context_compactor.js +1 -1
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/index.js +11 -0
- package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +96 -0
- package/dist/esm/integrations/agent_registry/helpers.js +28 -0
- package/dist/esm/integrations/agent_registry/types.js +20 -0
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
- package/dist/esm/models/gemini_llm_connection.js +62 -19
- package/dist/esm/models/google_llm.js +26 -8
- package/dist/esm/plugins/security_plugin.js +16 -0
- package/dist/esm/runner/in_memory_runner.js +10 -5
- package/dist/esm/runner/runner.js +32 -2
- package/dist/esm/sessions/base_session_service.js +11 -1
- package/dist/esm/sessions/database_session_service.js +51 -5
- package/dist/esm/sessions/db/schema.js +44 -10
- package/dist/esm/sessions/in_memory_session_service.js +74 -16
- package/dist/esm/sessions/registry.js +7 -0
- package/dist/esm/sessions/vertex_ai_session_service.js +405 -0
- package/dist/esm/skills/gcp_skill_registry.js +78 -0
- package/dist/esm/skills/loader.js +64 -0
- package/dist/esm/skills/skill_registry.js +7 -0
- package/dist/esm/tools/agent_tool.js +10 -5
- package/dist/esm/tools/exit_loop_tool.js +9 -0
- package/dist/esm/tools/function_tool.js +7 -2
- package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
- package/dist/esm/tools/long_running_tool.js +2 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/esm/tools/mcp/mcp_tool.js +10 -6
- package/dist/esm/tools/mcp/mcp_toolset.js +26 -3
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +26 -27
- package/dist/esm/tools/skill/load_skill_tool.js +12 -1
- package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/esm/tools/skill/search_skills_tool.js +82 -0
- package/dist/esm/tools/skill/skill_toolset.js +40 -5
- package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
- package/dist/esm/utils/async_queue.js +60 -0
- package/dist/esm/utils/case_utils.js +25 -0
- package/dist/esm/utils/env_aware_utils.js +4 -0
- package/dist/esm/utils/file_utils.js +26 -0
- package/dist/esm/utils/gemini_schema_util.js +18 -0
- package/dist/esm/utils/live_connection_utils.js +256 -0
- package/dist/esm/utils/model_name.js +8 -0
- package/dist/esm/utils/partial_copy.js +23 -0
- package/dist/esm/utils/streaming_utils.js +167 -121
- package/dist/esm/utils/vertex_ai_utils.js +22 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
- package/dist/types/a2a/event_converter_utils.d.ts +14 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
- package/dist/types/a2a/part_converter_utils.d.ts +51 -6
- package/dist/types/agents/invocation_context.d.ts +0 -9
- package/dist/types/agents/llm_agent.d.ts +14 -0
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
- package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +12 -0
- package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +11 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +14 -1
- package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
- package/dist/types/agents/run_config.d.ts +15 -0
- package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
- package/dist/types/common.d.ts +19 -1
- package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
- package/dist/types/events/event_actions.d.ts +25 -8
- package/dist/types/events/structured_events.d.ts +13 -0
- package/dist/types/examples/example_util.d.ts +25 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +62 -0
- package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
- package/dist/types/integrations/agent_registry/types.d.ts +101 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
- package/dist/types/models/base_llm_connection.d.ts +10 -0
- package/dist/types/models/gemini_llm_connection.d.ts +15 -4
- package/dist/types/models/llm_response.d.ts +10 -1
- package/dist/types/plugins/security_plugin.d.ts +30 -0
- package/dist/types/runner/in_memory_runner.d.ts +28 -1
- package/dist/types/runner/runner.d.ts +47 -0
- package/dist/types/sessions/base_session_service.d.ts +22 -0
- package/dist/types/sessions/database_session_service.d.ts +1 -1
- package/dist/types/sessions/db/schema.d.ts +1 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
- package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
- package/dist/types/skills/loader.d.ts +7 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/skills/skill_registry.d.ts +29 -0
- package/dist/types/tools/exit_loop_tool.d.ts +9 -0
- package/dist/types/tools/function_tool.d.ts +22 -2
- package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
- package/dist/types/tools/long_running_tool.d.ts +11 -1
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +2 -1
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
- package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
- package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
- package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
- package/dist/types/utils/async_queue.d.ts +18 -0
- package/dist/types/utils/case_utils.d.ts +12 -0
- package/dist/types/utils/file_utils.d.ts +2 -0
- package/dist/types/utils/live_connection_utils.d.ts +30 -0
- package/dist/types/utils/model_name.d.ts +7 -0
- package/dist/types/utils/partial_copy.d.ts +13 -0
- package/dist/types/utils/streaming_utils.d.ts +7 -17
- package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +31 -1
- package/dist/web/agents/functions.js +4 -0
- package/dist/web/agents/instructions.js +81 -33
- package/dist/web/agents/invocation_context.js +0 -1
- package/dist/web/agents/llm_agent.js +53 -5
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/web/agents/processors/content_processor_utils.js +53 -23
- package/dist/web/agents/processors/content_request_processor.js +7 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/web/auth/auth_preprocessor.js +12 -10
- package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/web/code_executors/code_execution_utils.js +1 -1
- package/dist/web/code_executors/code_executor_context.js +7 -7
- package/dist/web/common.js +43 -1
- package/dist/web/context/summarizers/llm_summarizer.js +11 -0
- package/dist/web/context/token_based_context_compactor.js +1 -1
- package/dist/web/events/event.js +4 -2
- package/dist/web/index.js +11 -0
- package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +109 -0
- package/dist/web/integrations/agent_registry/helpers.js +28 -0
- package/dist/web/integrations/agent_registry/types.js +20 -0
- package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
- package/dist/web/models/gemini_llm_connection.js +75 -19
- package/dist/web/models/google_llm.js +26 -8
- package/dist/web/plugins/security_plugin.js +16 -0
- package/dist/web/runner/in_memory_runner.js +10 -5
- package/dist/web/runner/runner.js +32 -2
- package/dist/web/sessions/base_session_service.js +11 -1
- package/dist/web/sessions/database_session_service.js +51 -5
- package/dist/web/sessions/db/schema.js +44 -10
- package/dist/web/sessions/in_memory_session_service.js +74 -16
- package/dist/web/sessions/registry.js +7 -0
- package/dist/web/sessions/vertex_ai_session_service.js +416 -0
- package/dist/web/skills/gcp_skill_registry.js +78 -0
- package/dist/web/skills/loader.js +64 -0
- package/dist/web/skills/skill_registry.js +7 -0
- package/dist/web/tools/agent_tool.js +10 -5
- package/dist/web/tools/exit_loop_tool.js +9 -0
- package/dist/web/tools/function_tool.js +7 -2
- package/dist/web/tools/google_maps_grounding_tool.js +54 -0
- package/dist/web/tools/long_running_tool.js +2 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/web/tools/mcp/mcp_tool.js +10 -6
- package/dist/web/tools/mcp/mcp_toolset.js +26 -3
- package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
- package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +26 -27
- package/dist/web/tools/skill/load_skill_tool.js +12 -1
- package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/web/tools/skill/search_skills_tool.js +82 -0
- package/dist/web/tools/skill/skill_toolset.js +40 -5
- package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
- package/dist/web/utils/async_queue.js +60 -0
- package/dist/web/utils/case_utils.js +25 -0
- package/dist/web/utils/env_aware_utils.js +4 -0
- package/dist/web/utils/file_utils.js +26 -0
- package/dist/web/utils/gemini_schema_util.js +18 -0
- package/dist/web/utils/live_connection_utils.js +254 -0
- package/dist/web/utils/model_name.js +8 -0
- package/dist/web/utils/partial_copy.js +23 -0
- package/dist/web/utils/streaming_utils.js +221 -122
- package/dist/web/utils/vertex_ai_utils.js +22 -0
- package/dist/web/version.js +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
isGemini1Model,
|
|
10
|
+
isGeminiModel,
|
|
11
|
+
isGeminiModelIdCheckDisabled
|
|
12
|
+
} from "../utils/model_name.js";
|
|
13
|
+
import { BaseTool } from "./base_tool.js";
|
|
14
|
+
function applyGoogleMapsGrounding(llmRequest) {
|
|
15
|
+
if (!llmRequest.model) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const modelCheckDisabled = isGeminiModelIdCheckDisabled();
|
|
19
|
+
llmRequest.config = llmRequest.config || {};
|
|
20
|
+
llmRequest.config.tools = llmRequest.config.tools || [];
|
|
21
|
+
if (isGemini1Model(llmRequest.model)) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"Google Maps grounding tool cannot be used with Gemini 1.x models."
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
if (isGeminiModel(llmRequest.model) || modelCheckDisabled) {
|
|
27
|
+
llmRequest.config.tools.push({
|
|
28
|
+
googleMaps: {}
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
throw new Error(
|
|
33
|
+
"Google maps tool is not supported for model ".concat(llmRequest.model)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
class GoogleMapsGroundingTool extends BaseTool {
|
|
37
|
+
constructor() {
|
|
38
|
+
super({ name: "google_maps", description: "Google Maps Grounding Tool" });
|
|
39
|
+
}
|
|
40
|
+
runAsync() {
|
|
41
|
+
return Promise.resolve();
|
|
42
|
+
}
|
|
43
|
+
async processLlmRequest({
|
|
44
|
+
llmRequest
|
|
45
|
+
}) {
|
|
46
|
+
applyGoogleMapsGrounding(llmRequest);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const GOOGLE_MAPS_GROUNDING = new GoogleMapsGroundingTool();
|
|
50
|
+
export {
|
|
51
|
+
GOOGLE_MAPS_GROUNDING,
|
|
52
|
+
GoogleMapsGroundingTool,
|
|
53
|
+
applyGoogleMapsGrounding
|
|
54
|
+
};
|
|
@@ -37,7 +37,8 @@ class LongRunningFunctionTool extends FunctionTool {
|
|
|
37
37
|
super(__spreadProps(__spreadValues({}, options), { isLongRunning: true }));
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Returns the function declaration with an appended instruction warning the
|
|
41
|
+
* model not to re-invoke the tool while it is still running.
|
|
41
42
|
*/
|
|
42
43
|
_getDeclaration() {
|
|
43
44
|
const declaration = super._getDeclaration();
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
15
15
|
class MCPSessionManager {
|
|
16
16
|
constructor(connectionParams) {
|
|
17
|
+
this.activeSessions = /* @__PURE__ */ new Set();
|
|
17
18
|
this.connectionParams = connectionParams;
|
|
18
19
|
}
|
|
19
20
|
async createSession() {
|
|
@@ -45,8 +46,18 @@ class MCPSessionManager {
|
|
|
45
46
|
break;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
49
|
+
this.activeSessions.add(client);
|
|
48
50
|
return client;
|
|
49
51
|
}
|
|
52
|
+
async closeSession(client) {
|
|
53
|
+
if (this.activeSessions.has(client)) {
|
|
54
|
+
this.activeSessions.delete(client);
|
|
55
|
+
await client.close();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
getActiveSessions() {
|
|
59
|
+
return Array.from(this.activeSessions);
|
|
60
|
+
}
|
|
50
61
|
}
|
|
51
62
|
export {
|
|
52
63
|
MCPSessionManager
|
|
@@ -26,12 +26,16 @@ class MCPTool extends BaseTool {
|
|
|
26
26
|
}
|
|
27
27
|
async runAsync(request) {
|
|
28
28
|
const session = await this.mcpSessionManager.createSession();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
try {
|
|
30
|
+
const callRequest = {};
|
|
31
|
+
callRequest.params = { name: this.originalName, arguments: request.args };
|
|
32
|
+
const result = await session.callTool(callRequest.params, void 0, {
|
|
33
|
+
signal: request.toolContext.abortSignal
|
|
34
|
+
});
|
|
35
|
+
return result;
|
|
36
|
+
} finally {
|
|
37
|
+
await this.mcpSessionManager.closeSession(session);
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
export {
|
|
@@ -33,21 +33,44 @@ class MCPToolset extends BaseToolset {
|
|
|
33
33
|
super(toolFilter, prefix);
|
|
34
34
|
this.mcpSessionManager = new MCPSessionManager(connectionParams);
|
|
35
35
|
}
|
|
36
|
-
async getTools() {
|
|
36
|
+
async getTools(context) {
|
|
37
37
|
const session = await this.mcpSessionManager.createSession();
|
|
38
|
-
|
|
38
|
+
let listResult;
|
|
39
|
+
try {
|
|
40
|
+
listResult = await session.listTools();
|
|
41
|
+
} finally {
|
|
42
|
+
await this.mcpSessionManager.closeSession(session);
|
|
43
|
+
}
|
|
39
44
|
logger.debug("number of tools: ".concat(listResult.tools.length));
|
|
40
45
|
for (const tool of listResult.tools) {
|
|
41
46
|
logger.debug("tool: ".concat(tool.name));
|
|
42
47
|
}
|
|
43
|
-
|
|
48
|
+
const tools = listResult.tools.map((tool) => {
|
|
44
49
|
const toolWithPrefix = __spreadProps(__spreadValues({}, tool), {
|
|
45
50
|
name: this.prefix ? "".concat(this.prefix, "_").concat(tool.name) : tool.name
|
|
46
51
|
});
|
|
47
52
|
return new MCPTool(toolWithPrefix, this.mcpSessionManager, tool.name);
|
|
48
53
|
});
|
|
54
|
+
const filter = this.toolFilter;
|
|
55
|
+
if (!filter || Array.isArray(filter) && filter.length === 0) {
|
|
56
|
+
return tools;
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(filter)) {
|
|
59
|
+
return tools.filter((tool) => filter.includes(tool.name));
|
|
60
|
+
}
|
|
61
|
+
if (context) {
|
|
62
|
+
return tools.filter((tool) => filter(tool, context));
|
|
63
|
+
}
|
|
64
|
+
logger.warn(
|
|
65
|
+
"MCPToolset: a ToolPredicate toolFilter was provided but getTools() was called without a ReadonlyContext. The filter will not be applied."
|
|
66
|
+
);
|
|
67
|
+
return tools;
|
|
49
68
|
}
|
|
50
69
|
async close() {
|
|
70
|
+
const sessions = this.mcpSessionManager.getActiveSessions();
|
|
71
|
+
await Promise.allSettled(
|
|
72
|
+
sessions.map((session) => this.mcpSessionManager.closeSession(session))
|
|
73
|
+
);
|
|
51
74
|
}
|
|
52
75
|
}
|
|
53
76
|
export {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
function applyCredential(url, headers, credential, authScheme) {
|
|
9
|
+
if (!credential) return url;
|
|
10
|
+
if (credential.apiKey) {
|
|
11
|
+
let inLocation;
|
|
12
|
+
let name = "key";
|
|
13
|
+
if (authScheme && authScheme.type === "apiKey") {
|
|
14
|
+
const apiKeyScheme = authScheme;
|
|
15
|
+
inLocation = apiKeyScheme.in;
|
|
16
|
+
name = apiKeyScheme.name;
|
|
17
|
+
}
|
|
18
|
+
if (inLocation === "header") {
|
|
19
|
+
headers[name] = credential.apiKey;
|
|
20
|
+
} else if (inLocation === "query") {
|
|
21
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
22
|
+
url += "".concat(separator).concat(name, "=").concat(encodeURIComponent(credential.apiKey));
|
|
23
|
+
} else {
|
|
24
|
+
headers["Authorization"] = credential.apiKey;
|
|
25
|
+
}
|
|
26
|
+
} else if (credential.http && credential.http.credentials && credential.http.credentials.token) {
|
|
27
|
+
headers["Authorization"] = "Bearer ".concat(credential.http.credentials.token);
|
|
28
|
+
}
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
function createApiKeyScheme(name, inLocation) {
|
|
32
|
+
return {
|
|
33
|
+
type: "apiKey",
|
|
34
|
+
name,
|
|
35
|
+
in: inLocation
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function createBearerScheme() {
|
|
39
|
+
return {
|
|
40
|
+
type: "http",
|
|
41
|
+
scheme: "bearer"
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
applyCredential,
|
|
46
|
+
createApiKeyScheme,
|
|
47
|
+
createBearerScheme
|
|
48
|
+
};
|
package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
6
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
7
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
|
+
if (decorator = decorators[i])
|
|
9
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
10
|
+
if (kind && result) __defProp(target, key, result);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @license
|
|
15
|
+
* Copyright 2026 Google LLC
|
|
16
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
*/
|
|
18
|
+
import {
|
|
19
|
+
AuthCredentialTypes
|
|
20
|
+
} from "../../../../auth/auth_credential.js";
|
|
21
|
+
import { OAuth2CredentialExchanger } from "../../../../auth/oauth2/oauth2_credential_exchanger.js";
|
|
22
|
+
import { experimental } from "../../../../utils/experimental.js";
|
|
23
|
+
import { ServiceAccountCredentialExchanger } from "./service_account_exchanger.js";
|
|
24
|
+
let AutoAuthCredentialExchanger = class {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.exchangers = /* @__PURE__ */ new Map();
|
|
27
|
+
this.exchangers.set(
|
|
28
|
+
AuthCredentialTypes.OAUTH2,
|
|
29
|
+
new OAuth2CredentialExchanger()
|
|
30
|
+
);
|
|
31
|
+
this.exchangers.set(
|
|
32
|
+
AuthCredentialTypes.OPEN_ID_CONNECT,
|
|
33
|
+
new OAuth2CredentialExchanger()
|
|
34
|
+
);
|
|
35
|
+
this.exchangers.set(
|
|
36
|
+
AuthCredentialTypes.SERVICE_ACCOUNT,
|
|
37
|
+
new ServiceAccountCredentialExchanger()
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
async exchange(params) {
|
|
41
|
+
const { authCredential, authScheme } = params;
|
|
42
|
+
const exchanger = this.exchangers.get(authCredential.authType);
|
|
43
|
+
if (!exchanger) {
|
|
44
|
+
return {
|
|
45
|
+
credential: authCredential,
|
|
46
|
+
wasExchanged: false
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return exchanger.exchange({ authScheme, authCredential });
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
__decorateClass([
|
|
53
|
+
experimental
|
|
54
|
+
], AutoAuthCredentialExchanger.prototype, "exchange", 1);
|
|
55
|
+
AutoAuthCredentialExchanger = __decorateClass([
|
|
56
|
+
experimental
|
|
57
|
+
], AutoAuthCredentialExchanger);
|
|
58
|
+
export {
|
|
59
|
+
AutoAuthCredentialExchanger
|
|
60
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
6
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
7
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
|
+
if (decorator = decorators[i])
|
|
9
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
10
|
+
if (kind && result) __defProp(target, key, result);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @license
|
|
15
|
+
* Copyright 2026 Google LLC
|
|
16
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
*/
|
|
18
|
+
import { GoogleAuth, JWT } from "google-auth-library";
|
|
19
|
+
import {
|
|
20
|
+
AuthCredentialTypes
|
|
21
|
+
} from "../../../../auth/auth_credential.js";
|
|
22
|
+
import {
|
|
23
|
+
CredentialExchangeError
|
|
24
|
+
} from "../../../../auth/exchanger/base_credential_exchanger.js";
|
|
25
|
+
import { experimental } from "../../../../utils/experimental.js";
|
|
26
|
+
const DEFAULT_SCOPES = ["https://www.googleapis.com/auth/cloud-platform"];
|
|
27
|
+
let ServiceAccountCredentialExchanger = class {
|
|
28
|
+
async exchange(params) {
|
|
29
|
+
const { authCredential } = params;
|
|
30
|
+
if (authCredential.authType !== AuthCredentialTypes.SERVICE_ACCOUNT || !authCredential.serviceAccount) {
|
|
31
|
+
throw new CredentialExchangeError(
|
|
32
|
+
"Invalid credential type for ServiceAccountCredentialExchanger"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
const saConfig = authCredential.serviceAccount;
|
|
36
|
+
if (saConfig.useDefaultCredential) {
|
|
37
|
+
return this.exchangeForDefaultCredential(saConfig);
|
|
38
|
+
}
|
|
39
|
+
return this.exchangeForExplicitCredential(saConfig);
|
|
40
|
+
}
|
|
41
|
+
async exchangeForDefaultCredential(saConfig) {
|
|
42
|
+
try {
|
|
43
|
+
const auth = new GoogleAuth({
|
|
44
|
+
scopes: saConfig.scopes || DEFAULT_SCOPES
|
|
45
|
+
});
|
|
46
|
+
const client = await auth.getClient();
|
|
47
|
+
const tokenResponse = await client.getAccessToken();
|
|
48
|
+
const token = tokenResponse.token;
|
|
49
|
+
if (!token) {
|
|
50
|
+
throw new Error("Failed to get access token from default credentials");
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
credential: {
|
|
54
|
+
authType: AuthCredentialTypes.HTTP,
|
|
55
|
+
http: {
|
|
56
|
+
scheme: "bearer",
|
|
57
|
+
credentials: { token }
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
wasExchanged: true
|
|
61
|
+
};
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw new CredentialExchangeError(
|
|
64
|
+
"Failed to exchange default service account token: ".concat(error.message)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async exchangeForExplicitCredential(saConfig) {
|
|
69
|
+
const creds = saConfig.serviceAccountCredential;
|
|
70
|
+
if (!creds) {
|
|
71
|
+
throw new CredentialExchangeError(
|
|
72
|
+
"Service account credentials are missing."
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const client = new JWT({
|
|
77
|
+
email: creds.clientEmail,
|
|
78
|
+
key: creds.privateKey,
|
|
79
|
+
scopes: saConfig.scopes
|
|
80
|
+
});
|
|
81
|
+
const tokens = await client.authorize();
|
|
82
|
+
const token = tokens.access_token;
|
|
83
|
+
if (!token) {
|
|
84
|
+
throw new Error("Failed to get access token from explicit credentials");
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
credential: {
|
|
88
|
+
authType: AuthCredentialTypes.HTTP,
|
|
89
|
+
http: {
|
|
90
|
+
scheme: "bearer",
|
|
91
|
+
credentials: { token }
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
wasExchanged: true
|
|
95
|
+
};
|
|
96
|
+
} catch (error) {
|
|
97
|
+
throw new CredentialExchangeError(
|
|
98
|
+
"Failed to exchange explicit service account token: ".concat(error.message)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
__decorateClass([
|
|
104
|
+
experimental
|
|
105
|
+
], ServiceAccountCredentialExchanger.prototype, "exchange", 1);
|
|
106
|
+
ServiceAccountCredentialExchanger = __decorateClass([
|
|
107
|
+
experimental
|
|
108
|
+
], ServiceAccountCredentialExchanger);
|
|
109
|
+
export {
|
|
110
|
+
ServiceAccountCredentialExchanger
|
|
111
|
+
};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
21
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
22
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
23
|
+
if (decorator = decorators[i])
|
|
24
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
25
|
+
if (kind && result) __defProp(target, key, result);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @license
|
|
30
|
+
* Copyright 2026 Google LLC
|
|
31
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
32
|
+
*/
|
|
33
|
+
import { experimental } from "../../../utils/experimental.js";
|
|
34
|
+
import { OperationParser } from "./operation_parser.js";
|
|
35
|
+
const VALID_SCHEMA_TYPES = /* @__PURE__ */ new Set([
|
|
36
|
+
"array",
|
|
37
|
+
"boolean",
|
|
38
|
+
"integer",
|
|
39
|
+
"null",
|
|
40
|
+
"number",
|
|
41
|
+
"object",
|
|
42
|
+
"string"
|
|
43
|
+
]);
|
|
44
|
+
let OpenApiSpecParser = class {
|
|
45
|
+
constructor(options = {}) {
|
|
46
|
+
var _a;
|
|
47
|
+
this.preservePropertyNames = (_a = options.preservePropertyNames) != null ? _a : false;
|
|
48
|
+
}
|
|
49
|
+
parse(openapiSpec) {
|
|
50
|
+
const resolvedSpec = resolveReferences(openapiSpec);
|
|
51
|
+
const sanitizedSpec = sanitizeSchemaTypes(resolvedSpec);
|
|
52
|
+
return collectOperations(sanitizedSpec, {
|
|
53
|
+
preservePropertyNames: this.preservePropertyNames
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
__decorateClass([
|
|
58
|
+
experimental
|
|
59
|
+
], OpenApiSpecParser.prototype, "parse", 1);
|
|
60
|
+
OpenApiSpecParser = __decorateClass([
|
|
61
|
+
experimental
|
|
62
|
+
], OpenApiSpecParser);
|
|
63
|
+
function resolveReferences(spec) {
|
|
64
|
+
const resolvedCache = /* @__PURE__ */ new Map();
|
|
65
|
+
const specCopy = JSON.parse(JSON.stringify(spec));
|
|
66
|
+
const recursiveResolve = (obj, currentDoc, seenRefs = /* @__PURE__ */ new Set()) => {
|
|
67
|
+
if (typeof obj !== "object" || obj === null) {
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(obj)) {
|
|
71
|
+
return obj.map((item) => recursiveResolve(item, currentDoc, seenRefs));
|
|
72
|
+
}
|
|
73
|
+
const objRecord = obj;
|
|
74
|
+
if ("$ref" in objRecord && typeof objRecord["$ref"] === "string") {
|
|
75
|
+
const refString = objRecord["$ref"];
|
|
76
|
+
if (seenRefs.has(refString) && !resolvedCache.has(refString)) {
|
|
77
|
+
const copy = __spreadValues({}, objRecord);
|
|
78
|
+
delete copy["$ref"];
|
|
79
|
+
return copy;
|
|
80
|
+
}
|
|
81
|
+
seenRefs.add(refString);
|
|
82
|
+
if (resolvedCache.has(refString)) {
|
|
83
|
+
return resolvedCache.get(refString);
|
|
84
|
+
}
|
|
85
|
+
let resolvedValue = resolveRef(refString, currentDoc);
|
|
86
|
+
if (resolvedValue !== void 0) {
|
|
87
|
+
resolvedValue = recursiveResolve(resolvedValue, currentDoc, seenRefs);
|
|
88
|
+
resolvedCache.set(refString, resolvedValue);
|
|
89
|
+
return resolvedValue;
|
|
90
|
+
} else {
|
|
91
|
+
return obj;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const newDict = {};
|
|
95
|
+
for (const [key, value] of Object.entries(objRecord)) {
|
|
96
|
+
newDict[key] = recursiveResolve(value, currentDoc, seenRefs);
|
|
97
|
+
}
|
|
98
|
+
return newDict;
|
|
99
|
+
};
|
|
100
|
+
return recursiveResolve(specCopy, specCopy);
|
|
101
|
+
}
|
|
102
|
+
function resolveRef(refString, currentDoc) {
|
|
103
|
+
const parts = refString.split("/");
|
|
104
|
+
if (parts[0] !== "#") {
|
|
105
|
+
throw new Error("External references not supported: ".concat(refString));
|
|
106
|
+
}
|
|
107
|
+
let current = currentDoc;
|
|
108
|
+
for (const part of parts.slice(1)) {
|
|
109
|
+
if (typeof current === "object" && current !== null && part in current) {
|
|
110
|
+
current = current[part];
|
|
111
|
+
} else {
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return current;
|
|
116
|
+
}
|
|
117
|
+
function sanitizeSchemaTypes(openapiSpec) {
|
|
118
|
+
const specCopy = JSON.parse(JSON.stringify(openapiSpec));
|
|
119
|
+
const sanitizeTypeField = (schemaDict) => {
|
|
120
|
+
if (!("type" in schemaDict)) return;
|
|
121
|
+
const typeValue = schemaDict["type"];
|
|
122
|
+
if (typeof typeValue === "string") {
|
|
123
|
+
const normalizedType = typeValue.toLowerCase();
|
|
124
|
+
if (VALID_SCHEMA_TYPES.has(normalizedType)) {
|
|
125
|
+
schemaDict["type"] = normalizedType;
|
|
126
|
+
} else {
|
|
127
|
+
delete schemaDict["type"];
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (Array.isArray(typeValue)) {
|
|
132
|
+
const validTypes = [];
|
|
133
|
+
for (const entry of typeValue) {
|
|
134
|
+
if (typeof entry !== "string") continue;
|
|
135
|
+
const normalizedEntry = entry.toLowerCase();
|
|
136
|
+
if (VALID_SCHEMA_TYPES.has(normalizedEntry) && !validTypes.includes(normalizedEntry)) {
|
|
137
|
+
validTypes.push(normalizedEntry);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (validTypes.length > 0) {
|
|
141
|
+
schemaDict["type"] = validTypes;
|
|
142
|
+
} else {
|
|
143
|
+
delete schemaDict["type"];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const sanitizeRecursive = (obj, inSchema) => {
|
|
148
|
+
if (typeof obj !== "object" || obj === null) {
|
|
149
|
+
return obj;
|
|
150
|
+
}
|
|
151
|
+
if (Array.isArray(obj)) {
|
|
152
|
+
return obj.map((item) => sanitizeRecursive(item, inSchema));
|
|
153
|
+
}
|
|
154
|
+
const objRecord = obj;
|
|
155
|
+
if (inSchema) {
|
|
156
|
+
sanitizeTypeField(objRecord);
|
|
157
|
+
}
|
|
158
|
+
for (const [key, value] of Object.entries(objRecord)) {
|
|
159
|
+
const isSchemaContainer = key === "schema" || key === "schemas";
|
|
160
|
+
objRecord[key] = sanitizeRecursive(value, inSchema || isSchemaContainer);
|
|
161
|
+
}
|
|
162
|
+
return objRecord;
|
|
163
|
+
};
|
|
164
|
+
return sanitizeRecursive(specCopy, false);
|
|
165
|
+
}
|
|
166
|
+
function collectOperations(spec, options = {}) {
|
|
167
|
+
var _a, _b, _c, _d;
|
|
168
|
+
const preservePropertyNames = (_a = options.preservePropertyNames) != null ? _a : false;
|
|
169
|
+
const operations = [];
|
|
170
|
+
const baseUrl = ((_c = (_b = spec.servers) == null ? void 0 : _b[0]) == null ? void 0 : _c.url) || "";
|
|
171
|
+
const globalSecurity = spec.security || [];
|
|
172
|
+
let globalSchemeName;
|
|
173
|
+
if (globalSecurity.length > 0) {
|
|
174
|
+
globalSchemeName = Object.keys(globalSecurity[0])[0];
|
|
175
|
+
}
|
|
176
|
+
const authSchemes = ((_d = spec.components) == null ? void 0 : _d.securitySchemes) || {};
|
|
177
|
+
for (const [path, pathItem] of Object.entries(spec.paths || {})) {
|
|
178
|
+
if (!pathItem) continue;
|
|
179
|
+
const methods = [
|
|
180
|
+
"get",
|
|
181
|
+
"post",
|
|
182
|
+
"put",
|
|
183
|
+
"delete",
|
|
184
|
+
"patch",
|
|
185
|
+
"head",
|
|
186
|
+
"options",
|
|
187
|
+
"trace"
|
|
188
|
+
];
|
|
189
|
+
for (const method of methods) {
|
|
190
|
+
const operation = pathItem[method];
|
|
191
|
+
if (!operation) continue;
|
|
192
|
+
const pathParams = pathItem.parameters || [];
|
|
193
|
+
const opParams = operation.parameters || [];
|
|
194
|
+
operation.parameters = [...opParams, ...pathParams];
|
|
195
|
+
if (!operation.operationId) {
|
|
196
|
+
operation.operationId = "".concat(method, "_").concat(path.replace(/[^a-zA-Z0-9]/g, "_"));
|
|
197
|
+
}
|
|
198
|
+
const parser = new OperationParser(operation, {
|
|
199
|
+
preservePropertyNames
|
|
200
|
+
});
|
|
201
|
+
let authSchemeName;
|
|
202
|
+
if (operation.security && operation.security.length > 0) {
|
|
203
|
+
authSchemeName = Object.keys(operation.security[0])[0];
|
|
204
|
+
}
|
|
205
|
+
authSchemeName = authSchemeName || globalSchemeName;
|
|
206
|
+
const authScheme = authSchemeName ? authSchemes[authSchemeName] : void 0;
|
|
207
|
+
operations.push({
|
|
208
|
+
name: parser.getFunctionName(),
|
|
209
|
+
description: parser.getDescription(),
|
|
210
|
+
endpoint: { baseUrl, path, method },
|
|
211
|
+
operation,
|
|
212
|
+
parameters: parser.getParameters(),
|
|
213
|
+
authScheme
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return operations;
|
|
218
|
+
}
|
|
219
|
+
export {
|
|
220
|
+
OpenApiSpecParser
|
|
221
|
+
};
|