@google/adk 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a2a/a2a_remote_agent.js +4 -1
- package/dist/cjs/a2a/agent_card.js +102 -26
- package/dist/cjs/a2a/agent_to_a2a.js +1 -1
- package/dist/cjs/agents/agent_engine_client.js +172 -0
- package/dist/cjs/agents/base_agent.js +20 -4
- package/dist/cjs/agents/functions.js +227 -25
- package/dist/cjs/agents/instructions.js +6 -2
- package/dist/cjs/agents/invocation_context.js +26 -4
- package/dist/cjs/agents/langgraph_agent.js +152 -0
- package/dist/cjs/agents/llm_agent.js +194 -107
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/code_execution_request_processor.js +18 -6
- package/dist/cjs/agents/processors/content_processor_utils.js +38 -10
- package/dist/cjs/agents/processors/content_request_processor.js +34 -2
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/nl_planning_processor.js +12 -3
- package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/cjs/auth/auth_handler.js +37 -5
- package/dist/cjs/auth/auth_schemes.js +9 -0
- package/dist/cjs/cli/cli_eval.js +532 -0
- package/dist/cjs/cli/utils/envs.js +116 -0
- package/dist/cjs/cli/utils/evals.js +137 -0
- package/dist/cjs/cli/utils/logs.js +150 -0
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/cjs/code_executors/code_execution_utils.js +48 -16
- package/dist/cjs/code_executors/code_executor_context.js +6 -2
- package/dist/cjs/code_executors/container_code_executor.js +27 -16
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/cjs/common.js +61 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
- package/dist/cjs/context/token_based_context_compactor.js +2 -1
- package/dist/cjs/errors/input_validation_error.js +3 -2
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/examples/example_util.js +23 -2
- package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
- package/dist/cjs/index.js +104 -1
- package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +16 -8
- package/dist/cjs/models/google_llm.js +13 -16
- package/dist/cjs/models/llm_response.js +9 -1
- package/dist/cjs/models/registry.js +1 -1
- package/dist/cjs/models/routed_llm.js +9 -8
- package/dist/cjs/planners/plan_re_act_planner.js +1 -1
- package/dist/cjs/plugins/base_plugin.js +13 -23
- package/dist/cjs/runner/in_memory_runner.js +6 -11
- package/dist/cjs/runner/runner.js +105 -33
- package/dist/cjs/sessions/base_session_service.js +14 -8
- package/dist/cjs/sessions/database_session_service.js +50 -28
- package/dist/cjs/sessions/db/operations.js +1 -1
- package/dist/cjs/sessions/in_memory_session_service.js +3 -1
- package/dist/cjs/sessions/stale_session_error.js +59 -0
- package/dist/cjs/sessions/state.js +8 -4
- package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
- package/dist/cjs/skills/loader.js +52 -18
- package/dist/cjs/telemetry/setup.js +0 -1
- package/dist/cjs/telemetry/tracing.js +147 -73
- package/dist/cjs/tools/agent_tool.js +44 -0
- package/dist/cjs/tools/apihub_tool/apihub_toolset.js +137 -0
- package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
- package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
- package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +263 -0
- package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +671 -0
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +223 -0
- package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +184 -0
- package/dist/cjs/tools/example_tool.js +10 -0
- package/dist/cjs/tools/function_tool.js +319 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool.js +100 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolset.js +173 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolsets.js +124 -0
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
- package/dist/cjs/tools/google_api_tool/index.js +61 -0
- package/dist/cjs/tools/load_artifacts_tool.js +12 -6
- package/dist/cjs/tools/load_memory_tool.js +12 -10
- package/dist/cjs/tools/mcp/index.js +12 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -14
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +7 -13
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
- package/dist/cjs/tools/toolbox_toolset.js +174 -0
- package/dist/cjs/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/cjs/utils/client_labels.js +19 -2
- package/dist/cjs/utils/env_aware_utils.js +6 -8
- package/dist/cjs/utils/error_utils.js +11 -11
- package/dist/cjs/utils/failover_utils.js +1 -1
- package/dist/cjs/utils/file_extension_utils.js +11 -0
- package/dist/cjs/utils/file_utils.js +2 -24
- package/dist/cjs/utils/gemini_schema_util.js +28 -7
- package/dist/cjs/utils/json_utils.js +49 -0
- package/dist/cjs/utils/live_connection_utils.js +4 -5
- package/dist/cjs/utils/logger_node.js +11 -1
- package/dist/cjs/utils/object_notation_utils.js +6 -3
- package/dist/cjs/utils/output_schema_utils.js +5 -2
- package/dist/cjs/utils/streaming_utils.js +12 -12
- package/dist/cjs/utils/task.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +4 -1
- package/dist/esm/a2a/agent_card.js +103 -27
- package/dist/esm/a2a/agent_to_a2a.js +5 -2
- package/dist/esm/agents/agent_engine_client.js +144 -0
- package/dist/esm/agents/base_agent.js +20 -4
- package/dist/esm/agents/functions.js +226 -25
- package/dist/esm/agents/instructions.js +6 -2
- package/dist/esm/agents/invocation_context.js +24 -4
- package/dist/esm/agents/langgraph_agent.js +123 -0
- package/dist/esm/agents/llm_agent.js +204 -110
- package/dist/esm/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/code_execution_request_processor.js +21 -8
- package/dist/esm/agents/processors/content_processor_utils.js +38 -10
- package/dist/esm/agents/processors/content_request_processor.js +34 -2
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/nl_planning_processor.js +12 -3
- package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/esm/auth/auth_handler.js +37 -5
- package/dist/esm/auth/auth_schemes.js +8 -0
- package/dist/esm/cli/cli_eval.js +510 -0
- package/dist/esm/cli/utils/envs.js +78 -0
- package/dist/esm/cli/utils/evals.js +109 -0
- package/dist/esm/cli/utils/logs.js +111 -0
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/esm/code_executors/code_execution_utils.js +46 -16
- package/dist/esm/code_executors/code_executor_context.js +5 -2
- package/dist/esm/code_executors/container_code_executor.js +27 -16
- package/dist/esm/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/esm/common.js +65 -4
- package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
- package/dist/esm/context/token_based_context_compactor.js +2 -1
- package/dist/esm/errors/input_validation_error.js +3 -2
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/examples/example_util.js +21 -1
- package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
- package/dist/esm/index.js +114 -2
- package/dist/esm/integrations/agent_registry/helpers.js +1 -1
- package/dist/esm/models/gemini_llm_connection.js +16 -8
- package/dist/esm/models/google_llm.js +14 -17
- package/dist/esm/models/llm_response.js +9 -1
- package/dist/esm/models/registry.js +1 -1
- package/dist/esm/models/routed_llm.js +9 -8
- package/dist/esm/planners/plan_re_act_planner.js +1 -1
- package/dist/esm/plugins/base_plugin.js +13 -23
- package/dist/esm/runner/in_memory_runner.js +6 -11
- package/dist/esm/runner/runner.js +105 -33
- package/dist/esm/sessions/base_session_service.js +12 -7
- package/dist/esm/sessions/database_session_service.js +49 -28
- package/dist/esm/sessions/db/operations.js +1 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -1
- package/dist/esm/sessions/stale_session_error.js +31 -0
- package/dist/esm/sessions/state.js +8 -4
- package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
- package/dist/esm/skills/loader.js +51 -17
- package/dist/esm/telemetry/setup.js +1 -2
- package/dist/esm/telemetry/tracing.js +151 -74
- package/dist/esm/tools/agent_tool.js +44 -0
- package/dist/esm/tools/apihub_tool/apihub_toolset.js +101 -0
- package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
- package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
- package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +245 -0
- package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +629 -0
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +219 -0
- package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +158 -0
- package/dist/esm/tools/example_tool.js +13 -1
- package/dist/esm/tools/function_tool.js +316 -0
- package/dist/esm/tools/google_api_tool/google_api_tool.js +73 -0
- package/dist/esm/tools/google_api_tool/google_api_toolset.js +146 -0
- package/dist/esm/tools/google_api_tool/google_api_toolsets.js +94 -0
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
- package/dist/esm/tools/google_api_tool/index.js +31 -0
- package/dist/esm/tools/load_artifacts_tool.js +10 -5
- package/dist/esm/tools/load_memory_tool.js +12 -10
- package/dist/esm/tools/mcp/index.js +6 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -14
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +6 -12
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
- package/dist/esm/tools/toolbox_toolset.js +148 -0
- package/dist/esm/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/esm/utils/client_labels.js +19 -2
- package/dist/esm/utils/env_aware_utils.js +6 -8
- package/dist/esm/utils/error_utils.js +9 -10
- package/dist/esm/utils/failover_utils.js +1 -1
- package/dist/esm/utils/file_extension_utils.js +11 -0
- package/dist/esm/utils/file_utils.js +2 -23
- package/dist/esm/utils/gemini_schema_util.js +27 -7
- package/dist/esm/utils/json_utils.js +21 -0
- package/dist/esm/utils/live_connection_utils.js +4 -5
- package/dist/esm/utils/logger_node.js +11 -1
- package/dist/esm/utils/object_notation_utils.js +4 -2
- package/dist/esm/utils/output_schema_utils.js +5 -2
- package/dist/esm/utils/streaming_utils.js +11 -11
- package/dist/esm/utils/task.js +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
- package/dist/types/a2a/agent_card.d.ts +44 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
- package/dist/types/a2a/index.d.ts +1 -0
- package/dist/types/agents/agent_engine_client.d.ts +37 -0
- package/dist/types/agents/base_agent.d.ts +12 -0
- package/dist/types/agents/functions.d.ts +33 -1
- package/dist/types/agents/invocation_context.d.ts +20 -1
- package/dist/types/agents/langgraph_agent.d.ts +153 -0
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/processors/content_processor_utils.d.ts +4 -2
- package/dist/types/agents/processors/nl_planning_processor.d.ts +2 -1
- package/dist/types/auth/auth_handler.d.ts +28 -1
- package/dist/types/auth/auth_schemes.d.ts +13 -0
- package/dist/types/cli/cli_eval.d.ts +173 -0
- package/dist/types/cli/utils/envs.d.ts +23 -0
- package/dist/types/cli/utils/evals.d.ts +47 -0
- package/dist/types/cli/utils/logs.d.ts +38 -0
- package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
- package/dist/types/code_executors/code_executor_context.d.ts +1 -0
- package/dist/types/code_executors/container_code_executor.d.ts +17 -5
- package/dist/types/common.d.ts +24 -5
- package/dist/types/errors/input_validation_error.d.ts +2 -1
- package/dist/types/events/event.d.ts +4 -0
- package/dist/types/examples/example_util.d.ts +17 -0
- package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
- package/dist/types/index.d.ts +19 -2
- package/dist/types/models/gemini_llm_connection.d.ts +6 -7
- package/dist/types/models/routed_llm.d.ts +1 -1
- package/dist/types/plugins/base_plugin.d.ts +0 -10
- package/dist/types/runner/in_memory_runner.d.ts +2 -1
- package/dist/types/runner/runner.d.ts +34 -0
- package/dist/types/sessions/base_session_service.d.ts +5 -0
- package/dist/types/sessions/database_session_service.d.ts +17 -1
- package/dist/types/sessions/stale_session_error.d.ts +21 -0
- package/dist/types/sessions/state.d.ts +5 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
- package/dist/types/skills/loader.d.ts +3 -2
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +20 -4
- package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +115 -0
- package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
- package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
- package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
- package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +109 -0
- package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +229 -0
- package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
- package/dist/types/tools/application_integration_tool/integration_connector_tool.d.ts +70 -0
- package/dist/types/tools/base_toolset.d.ts +6 -5
- package/dist/types/tools/example_tool.d.ts +10 -0
- package/dist/types/tools/function_tool.d.ts +32 -0
- package/dist/types/tools/google_api_tool/google_api_tool.d.ts +37 -0
- package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +55 -0
- package/dist/types/tools/google_api_tool/google_api_toolsets.d.ts +48 -0
- package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +165 -0
- package/dist/types/tools/google_api_tool/index.d.ts +10 -0
- package/dist/types/tools/load_artifacts_tool.d.ts +14 -1
- package/dist/types/tools/load_memory_tool.d.ts +23 -1
- package/dist/types/tools/mcp/index.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +12 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +8 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +5 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +10 -0
- package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
- package/dist/types/tools/toolbox_toolset.d.ts +159 -0
- package/dist/types/utils/client_labels.d.ts +2 -1
- package/dist/types/utils/env_aware_utils.d.ts +18 -2
- package/dist/types/utils/error_utils.d.ts +7 -0
- package/dist/types/utils/file_utils.d.ts +6 -1
- package/dist/types/utils/gemini_schema_util.d.ts +9 -2
- package/dist/types/utils/json_utils.d.ts +11 -0
- package/dist/types/utils/object_notation_utils.d.ts +7 -0
- package/dist/types/utils/output_schema_utils.d.ts +3 -2
- package/dist/types/utils/simple_zod_to_json.d.ts +1 -2
- package/dist/types/utils/streaming_utils.d.ts +11 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +117 -110
- package/dist/web/index_web.js.map +4 -4
- package/package.json +38 -26
- package/dist/cjs/models/gemini_continuation.js +0 -232
- package/dist/esm/models/gemini_continuation.js +0 -205
- package/dist/types/models/gemini_continuation.d.ts +0 -59
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
7
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
8
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
9
|
+
if (decorator = decorators[i])
|
|
10
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
11
|
+
if (kind && result) __defProp(target, key, result);
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @license
|
|
16
|
+
* Copyright 2026 Google LLC
|
|
17
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
*/
|
|
19
|
+
import * as fs from "node:fs";
|
|
20
|
+
import { experimental } from "../../utils/experimental.js";
|
|
21
|
+
import { logger } from "../../utils/logger.js";
|
|
22
|
+
const GOOGLE_DISCOVERY_BASE_URL = "https://www.googleapis.com/discovery/v1/apis";
|
|
23
|
+
const GOOGLE_OAUTH2_AUTH_URL = "https://accounts.google.com/o/oauth2/auth";
|
|
24
|
+
const GOOGLE_OAUTH2_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
25
|
+
function normalizeGoogleSchemaRef(ref) {
|
|
26
|
+
if (ref.startsWith("#")) {
|
|
27
|
+
return `#/components/schemas/${ref.slice(1)}`;
|
|
28
|
+
}
|
|
29
|
+
return `#/components/schemas/${ref}`;
|
|
30
|
+
}
|
|
31
|
+
__name(normalizeGoogleSchemaRef, "normalizeGoogleSchemaRef");
|
|
32
|
+
function convertInfo(googleApiSpec, openapiSpec, apiName, apiVersion) {
|
|
33
|
+
var _a, _b, _c, _d;
|
|
34
|
+
openapiSpec.info = {
|
|
35
|
+
title: (_a = googleApiSpec.title) != null ? _a : `${apiName} API`,
|
|
36
|
+
description: (_b = googleApiSpec.description) != null ? _b : "",
|
|
37
|
+
version: (_c = googleApiSpec.version) != null ? _c : apiVersion,
|
|
38
|
+
contact: {},
|
|
39
|
+
termsOfService: (_d = googleApiSpec.documentationLink) != null ? _d : ""
|
|
40
|
+
};
|
|
41
|
+
const docsLink = googleApiSpec.documentationLink;
|
|
42
|
+
if (docsLink) {
|
|
43
|
+
openapiSpec.externalDocs = {
|
|
44
|
+
description: "API Documentation",
|
|
45
|
+
url: docsLink
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
__name(convertInfo, "convertInfo");
|
|
50
|
+
function convertServers(googleApiSpec, openapiSpec, apiName, apiVersion) {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
let baseUrl = `${(_a = googleApiSpec.rootUrl) != null ? _a : ""}${(_b = googleApiSpec.servicePath) != null ? _b : ""}`;
|
|
53
|
+
if (baseUrl.endsWith("/")) {
|
|
54
|
+
baseUrl = baseUrl.slice(0, -1);
|
|
55
|
+
}
|
|
56
|
+
openapiSpec.servers = [
|
|
57
|
+
{
|
|
58
|
+
url: baseUrl,
|
|
59
|
+
description: `${apiName} ${apiVersion} API`
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
__name(convertServers, "convertServers");
|
|
64
|
+
function convertSecuritySchemes(googleApiSpec, openapiSpec) {
|
|
65
|
+
var _a, _b, _c, _d, _e;
|
|
66
|
+
openapiSpec.components = (_a = openapiSpec.components) != null ? _a : {};
|
|
67
|
+
openapiSpec.components.securitySchemes = (_b = openapiSpec.components.securitySchemes) != null ? _b : {};
|
|
68
|
+
const oauth2 = (_c = googleApiSpec.auth) == null ? void 0 : _c.oauth2;
|
|
69
|
+
const hasOauth2 = oauth2 !== void 0 && Object.keys(oauth2).length > 0;
|
|
70
|
+
const formattedScopes = {};
|
|
71
|
+
if (hasOauth2) {
|
|
72
|
+
const scopes = (_d = oauth2.scopes) != null ? _d : {};
|
|
73
|
+
for (const [scope, scopeInfo] of Object.entries(scopes)) {
|
|
74
|
+
formattedScopes[scope] = (_e = scopeInfo.description) != null ? _e : "";
|
|
75
|
+
}
|
|
76
|
+
openapiSpec.components.securitySchemes["oauth2"] = {
|
|
77
|
+
type: "oauth2",
|
|
78
|
+
description: "OAuth 2.0 authentication",
|
|
79
|
+
flows: {
|
|
80
|
+
authorizationCode: {
|
|
81
|
+
authorizationUrl: GOOGLE_OAUTH2_AUTH_URL,
|
|
82
|
+
tokenUrl: GOOGLE_OAUTH2_TOKEN_URL,
|
|
83
|
+
scopes: formattedScopes
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
openapiSpec.components.securitySchemes["apiKey"] = {
|
|
89
|
+
type: "apiKey",
|
|
90
|
+
in: "query",
|
|
91
|
+
name: "key",
|
|
92
|
+
description: "API key for accessing this API"
|
|
93
|
+
};
|
|
94
|
+
openapiSpec.security = [
|
|
95
|
+
hasOauth2 ? { oauth2: Object.keys(formattedScopes) } : {},
|
|
96
|
+
{ apiKey: [] }
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
__name(convertSecuritySchemes, "convertSecuritySchemes");
|
|
100
|
+
function convertSchemaObject(schemaDef) {
|
|
101
|
+
var _a;
|
|
102
|
+
const result = {};
|
|
103
|
+
if (schemaDef.type !== void 0) {
|
|
104
|
+
const gtype = schemaDef.type;
|
|
105
|
+
if (gtype === "object") {
|
|
106
|
+
result["type"] = "object";
|
|
107
|
+
if (schemaDef.properties !== void 0) {
|
|
108
|
+
const properties = {};
|
|
109
|
+
for (const [propName, propDef] of Object.entries(
|
|
110
|
+
schemaDef.properties
|
|
111
|
+
)) {
|
|
112
|
+
properties[propName] = convertSchemaObject(propDef);
|
|
113
|
+
}
|
|
114
|
+
result["properties"] = properties;
|
|
115
|
+
}
|
|
116
|
+
const requiredFields = [];
|
|
117
|
+
for (const [propName, propDef] of Object.entries(
|
|
118
|
+
(_a = schemaDef.properties) != null ? _a : {}
|
|
119
|
+
)) {
|
|
120
|
+
if (propDef.required) {
|
|
121
|
+
requiredFields.push(propName);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (requiredFields.length > 0) {
|
|
125
|
+
result["required"] = requiredFields;
|
|
126
|
+
}
|
|
127
|
+
} else if (gtype === "array") {
|
|
128
|
+
result["type"] = "array";
|
|
129
|
+
if (schemaDef.items !== void 0) {
|
|
130
|
+
result["items"] = convertSchemaObject(schemaDef.items);
|
|
131
|
+
}
|
|
132
|
+
} else if (gtype === "any") {
|
|
133
|
+
result["oneOf"] = [
|
|
134
|
+
{ type: "object" },
|
|
135
|
+
{ type: "array" },
|
|
136
|
+
{ type: "string" },
|
|
137
|
+
{ type: "number" },
|
|
138
|
+
{ type: "boolean" },
|
|
139
|
+
{ type: "null" }
|
|
140
|
+
];
|
|
141
|
+
} else {
|
|
142
|
+
result["type"] = gtype;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (schemaDef.$ref !== void 0) {
|
|
146
|
+
result["$ref"] = normalizeGoogleSchemaRef(schemaDef.$ref);
|
|
147
|
+
}
|
|
148
|
+
if (schemaDef.format !== void 0) {
|
|
149
|
+
result["format"] = schemaDef.format;
|
|
150
|
+
}
|
|
151
|
+
if (schemaDef.enum !== void 0) {
|
|
152
|
+
result["enum"] = schemaDef.enum;
|
|
153
|
+
}
|
|
154
|
+
if (schemaDef.description !== void 0) {
|
|
155
|
+
result["description"] = schemaDef.description;
|
|
156
|
+
}
|
|
157
|
+
if (schemaDef.pattern !== void 0) {
|
|
158
|
+
result["pattern"] = schemaDef.pattern;
|
|
159
|
+
}
|
|
160
|
+
if (schemaDef.default !== void 0) {
|
|
161
|
+
result["default"] = schemaDef.default;
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
__name(convertSchemaObject, "convertSchemaObject");
|
|
166
|
+
function convertSchemas(googleApiSpec, openapiSpec) {
|
|
167
|
+
var _a, _b, _c;
|
|
168
|
+
openapiSpec.components = (_a = openapiSpec.components) != null ? _a : {};
|
|
169
|
+
openapiSpec.components.schemas = (_b = openapiSpec.components.schemas) != null ? _b : {};
|
|
170
|
+
const schemas = (_c = googleApiSpec.schemas) != null ? _c : {};
|
|
171
|
+
for (const [schemaName, schemaDef] of Object.entries(schemas)) {
|
|
172
|
+
openapiSpec.components.schemas[schemaName] = convertSchemaObject(schemaDef);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
__name(convertSchemas, "convertSchemas");
|
|
176
|
+
function extractPathParameters(path) {
|
|
177
|
+
const params = [];
|
|
178
|
+
for (const match of path.matchAll(/\{\+?([^{}]+)\}/g)) {
|
|
179
|
+
params.push(match[1]);
|
|
180
|
+
}
|
|
181
|
+
return params;
|
|
182
|
+
}
|
|
183
|
+
__name(extractPathParameters, "extractPathParameters");
|
|
184
|
+
function convertParameterSchema(paramData) {
|
|
185
|
+
var _a;
|
|
186
|
+
const schema = {
|
|
187
|
+
type: (_a = paramData.type) != null ? _a : "string"
|
|
188
|
+
};
|
|
189
|
+
if (paramData.enum !== void 0) {
|
|
190
|
+
schema["enum"] = paramData.enum;
|
|
191
|
+
}
|
|
192
|
+
if (paramData.format !== void 0) {
|
|
193
|
+
schema["format"] = paramData.format;
|
|
194
|
+
}
|
|
195
|
+
if (paramData.default !== void 0) {
|
|
196
|
+
schema["default"] = paramData.default;
|
|
197
|
+
}
|
|
198
|
+
if (paramData.pattern !== void 0) {
|
|
199
|
+
schema["pattern"] = paramData.pattern;
|
|
200
|
+
}
|
|
201
|
+
return schema;
|
|
202
|
+
}
|
|
203
|
+
__name(convertParameterSchema, "convertParameterSchema");
|
|
204
|
+
function convertOperation(methodData, pathParams) {
|
|
205
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
206
|
+
const parameters = [];
|
|
207
|
+
for (const paramName of pathParams) {
|
|
208
|
+
parameters.push({
|
|
209
|
+
name: paramName,
|
|
210
|
+
in: "path",
|
|
211
|
+
required: true,
|
|
212
|
+
schema: { type: "string" }
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const pathParamSet = new Set(pathParams);
|
|
216
|
+
for (const [paramName, paramData] of Object.entries(
|
|
217
|
+
(_a = methodData.parameters) != null ? _a : {}
|
|
218
|
+
)) {
|
|
219
|
+
if (pathParamSet.has(paramName)) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const location = (_b = paramData.location) != null ? _b : "query";
|
|
223
|
+
parameters.push({
|
|
224
|
+
name: paramName,
|
|
225
|
+
in: location,
|
|
226
|
+
description: (_c = paramData.description) != null ? _c : "",
|
|
227
|
+
required: location === "path" ? true : (_d = paramData.required) != null ? _d : false,
|
|
228
|
+
schema: convertParameterSchema(paramData)
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
const response200 = {
|
|
232
|
+
description: "Successful operation"
|
|
233
|
+
};
|
|
234
|
+
const responseRef = (_e = methodData.response) == null ? void 0 : _e.$ref;
|
|
235
|
+
if (responseRef) {
|
|
236
|
+
response200.content = {
|
|
237
|
+
"application/json": {
|
|
238
|
+
schema: { $ref: normalizeGoogleSchemaRef(responseRef) }
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const operation = {
|
|
243
|
+
operationId: (_f = methodData.id) != null ? _f : "",
|
|
244
|
+
summary: (_g = methodData.description) != null ? _g : "",
|
|
245
|
+
description: (_h = methodData.description) != null ? _h : "",
|
|
246
|
+
parameters,
|
|
247
|
+
responses: {
|
|
248
|
+
"200": response200,
|
|
249
|
+
"400": { description: "Bad request" },
|
|
250
|
+
"401": { description: "Unauthorized" },
|
|
251
|
+
"403": { description: "Forbidden" },
|
|
252
|
+
"404": { description: "Not found" },
|
|
253
|
+
"500": { description: "Server error" }
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
const requestRef = (_i = methodData.request) == null ? void 0 : _i.$ref;
|
|
257
|
+
if (requestRef) {
|
|
258
|
+
operation.requestBody = {
|
|
259
|
+
description: "Request body",
|
|
260
|
+
content: {
|
|
261
|
+
"application/json": {
|
|
262
|
+
schema: { $ref: normalizeGoogleSchemaRef(requestRef) }
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
required: true
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const scopes = (_j = methodData.scopes) != null ? _j : [];
|
|
269
|
+
if (scopes.length > 0) {
|
|
270
|
+
operation.security = [{ oauth2: scopes }];
|
|
271
|
+
}
|
|
272
|
+
return operation;
|
|
273
|
+
}
|
|
274
|
+
__name(convertOperation, "convertOperation");
|
|
275
|
+
function convertMethods(methods, _resourcePath, openapiSpec) {
|
|
276
|
+
var _a, _b, _c;
|
|
277
|
+
for (const methodData of Object.values(methods)) {
|
|
278
|
+
const httpMethod = ((_a = methodData.httpMethod) != null ? _a : "GET").toLowerCase();
|
|
279
|
+
let restPath = ((_c = (_b = methodData.flatPath) != null ? _b : methodData.path) != null ? _c : "/").replace(
|
|
280
|
+
/\{\+([^{}]+)\}/g,
|
|
281
|
+
(_match, paramName) => `{${paramName}}`
|
|
282
|
+
);
|
|
283
|
+
if (!restPath.startsWith("/")) {
|
|
284
|
+
restPath = `/${restPath}`;
|
|
285
|
+
}
|
|
286
|
+
const pathParams = extractPathParameters(restPath);
|
|
287
|
+
if (!openapiSpec.paths[restPath]) {
|
|
288
|
+
openapiSpec.paths[restPath] = {};
|
|
289
|
+
}
|
|
290
|
+
const pathItem = openapiSpec.paths[restPath];
|
|
291
|
+
pathItem[httpMethod] = convertOperation(methodData, pathParams);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
__name(convertMethods, "convertMethods");
|
|
295
|
+
function convertResources(resources, openapiSpec, parentPath = "") {
|
|
296
|
+
var _a;
|
|
297
|
+
for (const [resourceName, resourceData] of Object.entries(resources)) {
|
|
298
|
+
const resourcePath = `${parentPath}/${resourceName}`;
|
|
299
|
+
convertMethods((_a = resourceData.methods) != null ? _a : {}, resourcePath, openapiSpec);
|
|
300
|
+
if (resourceData.resources && Object.keys(resourceData.resources).length > 0) {
|
|
301
|
+
convertResources(resourceData.resources, openapiSpec, resourcePath);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
__name(convertResources, "convertResources");
|
|
306
|
+
let GoogleApiToOpenApiConverter = class {
|
|
307
|
+
constructor(apiName, apiVersion) {
|
|
308
|
+
this.googleApiSpec = null;
|
|
309
|
+
this.apiName = apiName;
|
|
310
|
+
this.apiVersion = apiVersion;
|
|
311
|
+
this.openapiSpec = {
|
|
312
|
+
openapi: "3.0.0",
|
|
313
|
+
info: {},
|
|
314
|
+
servers: [],
|
|
315
|
+
paths: {},
|
|
316
|
+
components: { schemas: {}, securitySchemes: {} }
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
async fetchGoogleApiSpec() {
|
|
320
|
+
try {
|
|
321
|
+
logger.debug(
|
|
322
|
+
`Fetching Google API spec for ${this.apiName} ${this.apiVersion}`
|
|
323
|
+
);
|
|
324
|
+
const url = `${GOOGLE_DISCOVERY_BASE_URL}/${encodeURIComponent(this.apiName)}/${encodeURIComponent(this.apiVersion)}/rest`;
|
|
325
|
+
const response = await globalThis.fetch(url);
|
|
326
|
+
if (response.status >= 400) {
|
|
327
|
+
throw new Error(
|
|
328
|
+
`HTTP Error ${response.status}: Failed to fetch Google API spec for ${this.apiName} ${this.apiVersion}`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
const spec = await response.json();
|
|
332
|
+
if (!spec || typeof spec !== "object" || Object.keys(spec).length === 0) {
|
|
333
|
+
throw new Error("Failed to retrieve API specification");
|
|
334
|
+
}
|
|
335
|
+
this.googleApiSpec = spec;
|
|
336
|
+
logger.debug(`Successfully fetched ${this.apiName} API specification`);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
logger.error(
|
|
339
|
+
`Error fetching API spec: ${error instanceof Error ? error.message : String(error)}`
|
|
340
|
+
);
|
|
341
|
+
throw error;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async convert() {
|
|
345
|
+
var _a, _b, _c;
|
|
346
|
+
if (!this.googleApiSpec) {
|
|
347
|
+
await this.fetchGoogleApiSpec();
|
|
348
|
+
}
|
|
349
|
+
const spec = (_a = this.googleApiSpec) != null ? _a : {};
|
|
350
|
+
convertInfo(spec, this.openapiSpec, this.apiName, this.apiVersion);
|
|
351
|
+
convertServers(spec, this.openapiSpec, this.apiName, this.apiVersion);
|
|
352
|
+
convertSecuritySchemes(spec, this.openapiSpec);
|
|
353
|
+
convertSchemas(spec, this.openapiSpec);
|
|
354
|
+
convertResources((_b = spec.resources) != null ? _b : {}, this.openapiSpec);
|
|
355
|
+
convertMethods((_c = spec.methods) != null ? _c : {}, "/", this.openapiSpec);
|
|
356
|
+
return this.openapiSpec;
|
|
357
|
+
}
|
|
358
|
+
saveOpenapiSpec(outputPath) {
|
|
359
|
+
fs.writeFileSync(
|
|
360
|
+
outputPath,
|
|
361
|
+
JSON.stringify(this.openapiSpec, null, 2),
|
|
362
|
+
"utf-8"
|
|
363
|
+
);
|
|
364
|
+
logger.info(`OpenAPI specification saved to ${outputPath}`);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
__name(GoogleApiToOpenApiConverter, "GoogleApiToOpenApiConverter");
|
|
368
|
+
__decorateClass([
|
|
369
|
+
experimental
|
|
370
|
+
], GoogleApiToOpenApiConverter.prototype, "fetchGoogleApiSpec", 1);
|
|
371
|
+
__decorateClass([
|
|
372
|
+
experimental
|
|
373
|
+
], GoogleApiToOpenApiConverter.prototype, "convert", 1);
|
|
374
|
+
__decorateClass([
|
|
375
|
+
experimental
|
|
376
|
+
], GoogleApiToOpenApiConverter.prototype, "saveOpenapiSpec", 1);
|
|
377
|
+
GoogleApiToOpenApiConverter = __decorateClass([
|
|
378
|
+
experimental
|
|
379
|
+
], GoogleApiToOpenApiConverter);
|
|
380
|
+
export {
|
|
381
|
+
GoogleApiToOpenApiConverter,
|
|
382
|
+
convertInfo,
|
|
383
|
+
convertMethods,
|
|
384
|
+
convertOperation,
|
|
385
|
+
convertParameterSchema,
|
|
386
|
+
convertResources,
|
|
387
|
+
convertSchemaObject,
|
|
388
|
+
convertSchemas,
|
|
389
|
+
convertSecuritySchemes,
|
|
390
|
+
convertServers,
|
|
391
|
+
extractPathParameters,
|
|
392
|
+
normalizeGoogleSchemaRef
|
|
393
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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 { GoogleApiTool, isGoogleApiTool } from "./google_api_tool.js";
|
|
9
|
+
import { GoogleApiToolset, isGoogleApiToolset } from "./google_api_toolset.js";
|
|
10
|
+
import {
|
|
11
|
+
BigQueryToolset,
|
|
12
|
+
CalendarToolset,
|
|
13
|
+
DocsToolset,
|
|
14
|
+
GmailToolset,
|
|
15
|
+
SheetsToolset,
|
|
16
|
+
SlidesToolset,
|
|
17
|
+
YoutubeToolset
|
|
18
|
+
} from "./google_api_toolsets.js";
|
|
19
|
+
export {
|
|
20
|
+
BigQueryToolset,
|
|
21
|
+
CalendarToolset,
|
|
22
|
+
DocsToolset,
|
|
23
|
+
GmailToolset,
|
|
24
|
+
GoogleApiTool,
|
|
25
|
+
GoogleApiToolset,
|
|
26
|
+
SheetsToolset,
|
|
27
|
+
SlidesToolset,
|
|
28
|
+
YoutubeToolset,
|
|
29
|
+
isGoogleApiTool,
|
|
30
|
+
isGoogleApiToolset
|
|
31
|
+
};
|
|
@@ -9,6 +9,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
9
9
|
*/
|
|
10
10
|
import { Type } from "@google/genai";
|
|
11
11
|
import { appendInstructions } from "../models/llm_request.js";
|
|
12
|
+
import { base64Decode } from "../utils/env_aware_utils.js";
|
|
12
13
|
import { logger } from "../utils/logger.js";
|
|
13
14
|
import {
|
|
14
15
|
BaseTool
|
|
@@ -37,6 +38,11 @@ function isInlineMimeTypeSupported(mimeType) {
|
|
|
37
38
|
) || GEMINI_SUPPORTED_INLINE_MIME_TYPES.has(normalized);
|
|
38
39
|
}
|
|
39
40
|
__name(isInlineMimeTypeSupported, "isInlineMimeTypeSupported");
|
|
41
|
+
function base64ByteLength(data) {
|
|
42
|
+
const digits = data.replace(/[=\s]/g, "").length;
|
|
43
|
+
return Math.floor(digits * 3 / 4);
|
|
44
|
+
}
|
|
45
|
+
__name(base64ByteLength, "base64ByteLength");
|
|
40
46
|
function asSafePartForLlm(artifact, artifactName) {
|
|
41
47
|
const inlineData = artifact.inlineData;
|
|
42
48
|
if (!inlineData) {
|
|
@@ -53,15 +59,13 @@ function asSafePartForLlm(artifact, artifactName) {
|
|
|
53
59
|
};
|
|
54
60
|
}
|
|
55
61
|
const isTextLike = mimeType.startsWith("text/") || TEXT_LIKE_MIME_TYPES.has(mimeType);
|
|
56
|
-
const decodedBuffer = Buffer.from(data, "base64");
|
|
57
62
|
if (isTextLike) {
|
|
58
63
|
try {
|
|
59
|
-
|
|
60
|
-
return { text: decoded };
|
|
64
|
+
return { text: base64Decode(data.replace(/-/g, "+").replace(/_/g, "/")) };
|
|
61
65
|
} catch {
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
|
-
const sizeKb =
|
|
68
|
+
const sizeKb = base64ByteLength(data) / 1024;
|
|
65
69
|
return {
|
|
66
70
|
text: `[Binary artifact: ${artifactName}, type: ${mimeType}, size: ${sizeKb.toFixed(1)} KB. Content cannot be displayed inline.]`
|
|
67
71
|
};
|
|
@@ -188,5 +192,6 @@ let LoadArtifactsTool = _LoadArtifactsTool;
|
|
|
188
192
|
const LOAD_ARTIFACTS = new LoadArtifactsTool();
|
|
189
193
|
export {
|
|
190
194
|
LOAD_ARTIFACTS,
|
|
191
|
-
LoadArtifactsTool
|
|
195
|
+
LoadArtifactsTool,
|
|
196
|
+
asSafePartForLlm
|
|
192
197
|
};
|
|
@@ -13,11 +13,13 @@ import {
|
|
|
13
13
|
BaseTool
|
|
14
14
|
} from "./base_tool.js";
|
|
15
15
|
const _LoadMemoryTool = class _LoadMemoryTool extends BaseTool {
|
|
16
|
-
constructor() {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
var _a;
|
|
17
18
|
super({
|
|
18
19
|
name: "load_memory",
|
|
19
20
|
description: "Loads the memory for the current user.\n\nNOTE: Currently this tool only uses text part from the memory."
|
|
20
21
|
});
|
|
22
|
+
this.textOnlyContent = (_a = options.textOnlyContent) != null ? _a : false;
|
|
21
23
|
}
|
|
22
24
|
_getDeclaration() {
|
|
23
25
|
return {
|
|
@@ -39,12 +41,12 @@ const _LoadMemoryTool = class _LoadMemoryTool extends BaseTool {
|
|
|
39
41
|
args,
|
|
40
42
|
toolContext
|
|
41
43
|
}) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const query = args["query"];
|
|
45
|
+
if (!toolContext.invocationContext.memoryService) {
|
|
46
|
+
throw new Error("Memory service is not initialized.");
|
|
47
|
+
}
|
|
48
|
+
const searchMemoryResponse = await toolContext.searchMemory(query);
|
|
49
|
+
if (this.textOnlyContent) {
|
|
48
50
|
return {
|
|
49
51
|
memories: searchMemoryResponse.memories.map((m) => {
|
|
50
52
|
var _a, _b;
|
|
@@ -59,10 +61,10 @@ const _LoadMemoryTool = class _LoadMemoryTool extends BaseTool {
|
|
|
59
61
|
};
|
|
60
62
|
})
|
|
61
63
|
};
|
|
62
|
-
} catch (e) {
|
|
63
|
-
console.error("ERROR in LoadMemoryTool runAsync:", e);
|
|
64
|
-
throw e;
|
|
65
64
|
}
|
|
65
|
+
return {
|
|
66
|
+
memories: searchMemoryResponse.memories
|
|
67
|
+
};
|
|
66
68
|
}
|
|
67
69
|
async processLlmRequest(request) {
|
|
68
70
|
await super.processLlmRequest(request);
|
|
@@ -5,7 +5,13 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2026 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { toGeminiSchema } from "../../utils/gemini_schema_util.js";
|
|
9
|
+
import { genaiSchemaToJsonSchema } from "../../utils/genai_schema_to_json.js";
|
|
8
10
|
export * from "./load_mcp_resource_tool.js";
|
|
9
11
|
export * from "./mcp_session_manager.js";
|
|
10
12
|
export * from "./mcp_tool.js";
|
|
11
13
|
export * from "./mcp_toolset.js";
|
|
14
|
+
export {
|
|
15
|
+
genaiSchemaToJsonSchema,
|
|
16
|
+
toGeminiSchema
|
|
17
|
+
};
|
|
@@ -52,6 +52,18 @@ function buildTransportOptions(params) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
__name(buildTransportOptions, "buildTransportOptions");
|
|
55
|
+
function buildSseTransportOptions(params) {
|
|
56
|
+
const { transportOptions, header, headers } = params;
|
|
57
|
+
const callerHeaders = (transportOptions == null ? void 0 : transportOptions.requestInit) === void 0 ? header != null ? header : headers : transportOptions.requestInit.headers;
|
|
58
|
+
return {
|
|
59
|
+
...transportOptions,
|
|
60
|
+
requestInit: {
|
|
61
|
+
...transportOptions == null ? void 0 : transportOptions.requestInit,
|
|
62
|
+
headers: mergeTrackingHeaders(callerHeaders)
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
__name(buildSseTransportOptions, "buildSseTransportOptions");
|
|
55
67
|
const _MCPSessionManager = class _MCPSessionManager {
|
|
56
68
|
constructor(connectionParams) {
|
|
57
69
|
this.activeSessions = /* @__PURE__ */ new Set();
|
|
@@ -90,6 +102,19 @@ const _MCPSessionManager = class _MCPSessionManager {
|
|
|
90
102
|
await client.connect(transport);
|
|
91
103
|
break;
|
|
92
104
|
}
|
|
105
|
+
case "SseConnectionParams": {
|
|
106
|
+
const { SSEClientTransport } = await loadOptionalPeer(
|
|
107
|
+
MCP_SDK,
|
|
108
|
+
() => Promise.resolve().then(() => __toESM(require("@modelcontextprotocol/sdk/client/sse.js"), 1))
|
|
109
|
+
);
|
|
110
|
+
const transport = new SSEClientTransport(
|
|
111
|
+
new URL(this.connectionParams.url),
|
|
112
|
+
buildSseTransportOptions(this.connectionParams)
|
|
113
|
+
);
|
|
114
|
+
transport.onerror = logTransportError;
|
|
115
|
+
await client.connect(transport);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
93
118
|
default: {
|
|
94
119
|
const _exhaustiveCheck = this.connectionParams;
|
|
95
120
|
break;
|
|
@@ -35,20 +35,7 @@ const _MCPToolset = class _MCPToolset extends BaseToolset {
|
|
|
35
35
|
};
|
|
36
36
|
return new MCPTool(toolWithPrefix, this.mcpSessionManager, tool.name);
|
|
37
37
|
});
|
|
38
|
-
|
|
39
|
-
if (!filter || Array.isArray(filter) && filter.length === 0) {
|
|
40
|
-
return tools;
|
|
41
|
-
}
|
|
42
|
-
if (Array.isArray(filter)) {
|
|
43
|
-
return tools.filter((tool) => filter.includes(tool.name));
|
|
44
|
-
}
|
|
45
|
-
if (context) {
|
|
46
|
-
return tools.filter((tool) => filter(tool, context));
|
|
47
|
-
}
|
|
48
|
-
logger.warn(
|
|
49
|
-
"MCPToolset: a ToolPredicate toolFilter was provided but getTools() was called without a ReadonlyContext. The filter will not be applied."
|
|
50
|
-
);
|
|
51
|
-
return tools;
|
|
38
|
+
return tools.filter((tool) => this.isToolSelected(tool, context));
|
|
52
39
|
}
|
|
53
40
|
/**
|
|
54
41
|
* Lists the names of the resources advertised by the MCP server.
|
|
@@ -131,12 +131,11 @@ function bearerJwtScheme() {
|
|
|
131
131
|
}
|
|
132
132
|
__name(bearerJwtScheme, "bearerJwtScheme");
|
|
133
133
|
function bearerTokenParam(authScheme, token) {
|
|
134
|
-
var _a;
|
|
135
134
|
const param = {
|
|
136
135
|
originalName: "Authorization",
|
|
137
136
|
paramLocation: "header",
|
|
138
137
|
paramSchema: { type: "string" },
|
|
139
|
-
description:
|
|
138
|
+
description: authScheme.description || "Bearer token",
|
|
140
139
|
name: `${INTERNAL_AUTH_PREFIX}Authorization`,
|
|
141
140
|
required: true
|
|
142
141
|
};
|
package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js
CHANGED
|
@@ -19,9 +19,46 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
19
19
|
import {
|
|
20
20
|
AuthCredentialTypes
|
|
21
21
|
} from "../../../../auth/auth_credential.js";
|
|
22
|
-
import {
|
|
22
|
+
import { OAuthGrantType } from "../../../../auth/auth_schemes.js";
|
|
23
|
+
import {
|
|
24
|
+
determineGrantType,
|
|
25
|
+
OAuth2CredentialExchanger
|
|
26
|
+
} from "../../../../auth/oauth2/oauth2_credential_exchanger.js";
|
|
23
27
|
import { experimental } from "../../../../utils/experimental.js";
|
|
28
|
+
import { generateAuthToken } from "./oauth2_exchanger.js";
|
|
24
29
|
import { ServiceAccountCredentialExchanger } from "./service_account_exchanger.js";
|
|
30
|
+
function isPendingAuthorizationCode(authScheme, authCredential) {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
return !!authScheme && determineGrantType(authScheme) === 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);
|
|
33
|
+
}
|
|
34
|
+
__name(isPendingAuthorizationCode, "isPendingAuthorizationCode");
|
|
35
|
+
function createDefaultOAuth2Exchanger() {
|
|
36
|
+
const tokenFetcher = new OAuth2CredentialExchanger();
|
|
37
|
+
return {
|
|
38
|
+
async exchange(params) {
|
|
39
|
+
const { authScheme, authCredential } = params;
|
|
40
|
+
if (authScheme && authCredential.http) {
|
|
41
|
+
return {
|
|
42
|
+
credential: authCredential,
|
|
43
|
+
wasExchanged: false
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (isPendingAuthorizationCode(authScheme, authCredential)) {
|
|
47
|
+
return {
|
|
48
|
+
credential: authCredential,
|
|
49
|
+
wasExchanged: false
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const { credential, wasExchanged } = await tokenFetcher.exchange(params);
|
|
53
|
+
const bearer = generateAuthToken(credential);
|
|
54
|
+
return {
|
|
55
|
+
credential: bearer,
|
|
56
|
+
wasExchanged: wasExchanged || bearer !== credential
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
__name(createDefaultOAuth2Exchanger, "createDefaultOAuth2Exchanger");
|
|
25
62
|
let AutoAuthCredentialExchanger = class {
|
|
26
63
|
/**
|
|
27
64
|
* @param customExchangers - Optional exchangers that add to or override the
|
|
@@ -29,14 +66,24 @@ let AutoAuthCredentialExchanger = class {
|
|
|
29
66
|
* exchanger instance to use for that type.
|
|
30
67
|
*/
|
|
31
68
|
constructor(customExchangers) {
|
|
69
|
+
/**
|
|
70
|
+
* The exchanger used for each auth credential type.
|
|
71
|
+
*
|
|
72
|
+
* By default `OAUTH2` and `OPEN_ID_CONNECT` run
|
|
73
|
+
* {@link OAuth2CredentialExchanger} and convert any access token with
|
|
74
|
+
* {@link generateAuthToken}, and `SERVICE_ACCOUNT` maps to a
|
|
75
|
+
* {@link ServiceAccountCredentialExchanger}, with any custom exchangers from
|
|
76
|
+
* the constructor merged over them. The map is live: an entry added or
|
|
77
|
+
* replaced after construction is used by the next {@link exchange} call.
|
|
78
|
+
*/
|
|
32
79
|
this.exchangers = /* @__PURE__ */ new Map();
|
|
33
80
|
this.exchangers.set(
|
|
34
81
|
AuthCredentialTypes.OAUTH2,
|
|
35
|
-
|
|
82
|
+
createDefaultOAuth2Exchanger()
|
|
36
83
|
);
|
|
37
84
|
this.exchangers.set(
|
|
38
85
|
AuthCredentialTypes.OPEN_ID_CONNECT,
|
|
39
|
-
|
|
86
|
+
createDefaultOAuth2Exchanger()
|
|
40
87
|
);
|
|
41
88
|
this.exchangers.set(
|
|
42
89
|
AuthCredentialTypes.SERVICE_ACCOUNT,
|