@google/adk 2.4.0 → 2.5.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 +17 -2
- package/dist/cjs/a2a/a2a_remote_agent_utils.js +8 -4
- package/dist/cjs/a2a/agent_card.js +5 -81
- package/dist/cjs/a2a/agent_to_a2a.js +7 -0
- package/dist/cjs/a2a/event_converter_utils.js +10 -3
- package/dist/cjs/agents/agent_engine_client.js +282 -55
- package/dist/cjs/agents/base_agent.js +111 -68
- package/dist/cjs/agents/functions.js +62 -85
- package/dist/cjs/agents/instructions.js +7 -6
- package/dist/cjs/agents/invocation_context.js +2 -2
- package/dist/cjs/agents/llm_agent.js +105 -95
- package/dist/cjs/agents/processors/content_processor_utils.js +42 -15
- package/dist/cjs/agents/processors/content_request_processor.js +28 -11
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +5 -1
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/nl_planning_processor.js +2 -1
- package/dist/cjs/artifacts/file_artifact_service.js +1 -1
- package/dist/cjs/cli/cli_eval.js +884 -17
- package/dist/cjs/cli/utils/cleanup.js +84 -0
- package/dist/cjs/cli/utils/envs.js +33 -2
- package/dist/cjs/cli/utils/evals.js +75 -8
- package/dist/cjs/cli/utils/logs.js +128 -9
- package/dist/cjs/cli/utils/path_validation.js +83 -0
- package/dist/cjs/code_executors/container_code_executor.js +158 -36
- package/dist/cjs/common.js +50 -12
- package/dist/cjs/context/compaction_utils.js +19 -0
- package/dist/cjs/events/event.js +7 -3
- package/dist/cjs/features/feature_registry.js +5 -0
- package/dist/cjs/index.js +29 -14
- package/dist/cjs/models/google_llm.js +33 -2
- package/dist/cjs/models/interactions_utils.js +3 -0
- package/dist/cjs/plugins/base_plugin.js +45 -21
- package/dist/cjs/plugins/plugin_manager.js +27 -0
- package/dist/cjs/runner/runner.js +306 -189
- package/dist/cjs/sessions/base_session_service.js +1 -4
- package/dist/cjs/sessions/database_session_service.js +191 -19
- package/dist/cjs/sessions/db/operations.js +70 -1
- package/dist/cjs/sessions/db/schema.js +4 -0
- package/dist/cjs/sessions/in_memory_session_service.js +2 -2
- package/dist/cjs/sessions/vertex_ai_session_service.js +11 -3
- package/dist/cjs/skills/loader.js +29 -28
- package/dist/cjs/telemetry/api/instrumentation.js +632 -0
- package/dist/cjs/telemetry/api/internal/common/accumulators.js +169 -0
- package/dist/cjs/telemetry/api/internal/common/attributes.js +131 -0
- package/dist/cjs/telemetry/api/internal/common/config.js +159 -0
- package/dist/cjs/telemetry/api/internal/common/error.js +98 -0
- package/dist/cjs/telemetry/api/internal/common/finish_reason.js +63 -0
- package/dist/cjs/telemetry/api/internal/common/genai_messages.js +217 -0
- package/dist/cjs/telemetry/api/internal/common/http_exchange.js +169 -0
- package/dist/cjs/telemetry/api/internal/common/provider_name.js +87 -0
- package/dist/cjs/telemetry/api/internal/common/redaction.js +148 -0
- package/dist/cjs/telemetry/api/internal/common/serialization.js +58 -0
- package/dist/cjs/telemetry/api/internal/common/token_usage.js +118 -0
- package/dist/cjs/telemetry/api/internal/logs/inference.js +50 -0
- package/dist/cjs/telemetry/api/internal/logs/logger.js +46 -0
- package/dist/cjs/telemetry/api/internal/logs/mcp.js +141 -0
- package/dist/cjs/telemetry/api/internal/metrics/agent.js +128 -0
- package/dist/cjs/telemetry/api/internal/metrics/inference_start_hook.js +56 -0
- package/dist/cjs/telemetry/api/internal/metrics/meters.js +189 -0
- package/dist/cjs/telemetry/api/internal/metrics/tool.js +147 -0
- package/dist/cjs/telemetry/api/internal/metrics/workflow.js +132 -0
- package/dist/cjs/telemetry/api/internal/trace/agent.js +52 -0
- package/dist/cjs/telemetry/api/internal/trace/compaction.js +78 -0
- package/dist/cjs/telemetry/api/internal/trace/inference.js +132 -0
- package/dist/cjs/telemetry/api/internal/trace/live.js +52 -0
- package/dist/cjs/telemetry/api/internal/trace/node.js +73 -0
- package/dist/cjs/telemetry/api/internal/trace/propagation.js +67 -0
- package/dist/cjs/telemetry/api/internal/trace/tool.js +122 -0
- package/dist/cjs/telemetry/api/internal/trace/tracer.js +77 -0
- package/dist/cjs/telemetry/api/internal/trace/workflow.js +77 -0
- package/dist/cjs/telemetry/export/agent_engine.js +90 -0
- package/dist/cjs/telemetry/export/agent_runtime.js +73 -0
- package/dist/cjs/telemetry/export/google_cloud.js +763 -0
- package/dist/cjs/telemetry/export/request_driven_metric_reader.js +303 -0
- package/dist/cjs/telemetry/{setup.js → export/setup.js} +72 -5
- package/dist/cjs/tools/agent_tool.js +9 -1
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +22 -34
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +60 -20
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +26 -10
- package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +14 -23
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/computer_use/base_computer.js +125 -0
- package/dist/cjs/tools/computer_use/computer_use_actions.js +502 -0
- package/dist/cjs/tools/computer_use/computer_use_tool.js +244 -0
- package/dist/cjs/tools/computer_use/computer_use_toolset.js +360 -0
- package/dist/cjs/tools/function_tool.js +15 -5
- package/dist/cjs/tools/google_api_tool/google_api_toolset.js +3 -2
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +3 -1
- package/dist/cjs/tools/load_artifacts_tool.js +15 -5
- package/dist/cjs/tools/load_memory_tool.js +2 -5
- package/dist/cjs/tools/mcp/mcp_session_manager.js +23 -3
- package/dist/cjs/tools/mcp/mcp_tool.js +7 -3
- package/dist/cjs/tools/mcp/mcp_toolset.js +18 -6
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +30 -29
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +45 -14
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +7 -0
- package/dist/cjs/tools/skill/load_skill_tool.js +3 -0
- package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -2
- package/dist/cjs/tools/toolbox_toolset.js +47 -28
- package/dist/cjs/utils/async_queue.js +37 -3
- package/dist/cjs/utils/client_labels.js +9 -11
- package/dist/cjs/utils/env_aware_utils.js +13 -7
- package/dist/cjs/utils/error_utils.js +40 -2
- package/dist/cjs/utils/failover_utils.js +10 -9
- package/dist/cjs/utils/gemini_schema_util.js +125 -12
- package/dist/cjs/utils/id_provider.js +63 -0
- package/dist/cjs/utils/model_name.js +15 -0
- package/dist/cjs/utils/simple_zod_to_json.js +13 -31
- package/dist/cjs/utils/ssrf_guard.js +46 -16
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/index.js +2 -0
- package/dist/cjs/workflow/node_runner.js +24 -80
- package/dist/cjs/workflow/nodes/parallel_worker.js +18 -7
- package/dist/cjs/workflow/run_llm_agent_as_node.js +19 -14
- package/dist/cjs/workflow/utils/retry_utils.js +2 -2
- package/dist/cjs/workflow/workflow.js +12 -12
- package/dist/esm/a2a/a2a_remote_agent.js +23 -3
- package/dist/esm/a2a/a2a_remote_agent_utils.js +8 -4
- package/dist/esm/a2a/agent_card.js +5 -83
- package/dist/esm/a2a/agent_to_a2a.js +7 -0
- package/dist/esm/a2a/event_converter_utils.js +10 -3
- package/dist/esm/agents/agent_engine_client.js +293 -55
- package/dist/esm/agents/base_agent.js +111 -72
- package/dist/esm/agents/functions.js +67 -89
- package/dist/esm/agents/instructions.js +7 -6
- package/dist/esm/agents/invocation_context.js +2 -2
- package/dist/esm/agents/llm_agent.js +111 -100
- package/dist/esm/agents/processors/content_processor_utils.js +42 -15
- package/dist/esm/agents/processors/content_request_processor.js +28 -11
- package/dist/esm/agents/processors/context_compactor_request_processor.js +5 -1
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/nl_planning_processor.js +2 -1
- package/dist/esm/artifacts/file_artifact_service.js +1 -1
- package/dist/esm/cli/cli_eval.js +880 -17
- package/dist/esm/cli/utils/cleanup.js +56 -0
- package/dist/esm/cli/utils/envs.js +33 -2
- package/dist/esm/cli/utils/evals.js +74 -8
- package/dist/esm/cli/utils/logs.js +128 -9
- package/dist/esm/cli/utils/path_validation.js +45 -0
- package/dist/esm/code_executors/container_code_executor.js +158 -36
- package/dist/esm/common.js +49 -6
- package/dist/esm/context/compaction_utils.js +19 -0
- package/dist/esm/events/event.js +7 -3
- package/dist/esm/features/feature_registry.js +5 -0
- package/dist/esm/index.js +27 -15
- package/dist/esm/models/google_llm.js +33 -2
- package/dist/esm/models/interactions_utils.js +3 -0
- package/dist/esm/plugins/base_plugin.js +45 -21
- package/dist/esm/plugins/plugin_manager.js +27 -0
- package/dist/esm/runner/runner.js +310 -192
- package/dist/esm/sessions/base_session_service.js +1 -4
- package/dist/esm/sessions/database_session_service.js +191 -19
- package/dist/esm/sessions/db/operations.js +70 -1
- package/dist/esm/sessions/db/schema.js +4 -0
- package/dist/esm/sessions/in_memory_session_service.js +2 -2
- package/dist/esm/sessions/vertex_ai_session_service.js +11 -3
- package/dist/esm/skills/loader.js +29 -28
- package/dist/esm/telemetry/api/instrumentation.js +655 -0
- package/dist/esm/telemetry/api/internal/common/accumulators.js +139 -0
- package/dist/esm/telemetry/api/internal/common/attributes.js +94 -0
- package/dist/esm/telemetry/api/internal/common/config.js +128 -0
- package/dist/esm/telemetry/api/internal/common/error.js +69 -0
- package/dist/esm/telemetry/api/internal/common/finish_reason.js +35 -0
- package/dist/esm/telemetry/api/internal/common/genai_messages.js +188 -0
- package/dist/esm/telemetry/api/internal/common/http_exchange.js +142 -0
- package/dist/esm/telemetry/api/internal/common/provider_name.js +59 -0
- package/dist/esm/telemetry/api/internal/common/redaction.js +121 -0
- package/dist/esm/telemetry/api/internal/common/serialization.js +30 -0
- package/dist/esm/telemetry/api/internal/common/token_usage.js +85 -0
- package/dist/esm/telemetry/api/internal/logs/inference.js +23 -0
- package/dist/esm/telemetry/api/internal/logs/logger.js +19 -0
- package/dist/esm/telemetry/api/internal/logs/mcp.js +113 -0
- package/dist/esm/telemetry/api/internal/metrics/agent.js +107 -0
- package/dist/esm/telemetry/api/internal/metrics/inference_start_hook.js +29 -0
- package/dist/esm/telemetry/api/internal/metrics/meters.js +165 -0
- package/dist/esm/telemetry/api/internal/metrics/tool.js +119 -0
- package/dist/esm/telemetry/api/internal/metrics/workflow.js +112 -0
- package/dist/esm/telemetry/api/internal/trace/agent.js +25 -0
- package/dist/esm/telemetry/api/internal/trace/compaction.js +50 -0
- package/dist/esm/telemetry/api/internal/trace/inference.js +107 -0
- package/dist/esm/telemetry/api/internal/trace/live.js +28 -0
- package/dist/esm/telemetry/api/internal/trace/node.js +44 -0
- package/dist/esm/telemetry/api/internal/trace/propagation.js +39 -0
- package/dist/esm/telemetry/api/internal/trace/tool.js +96 -0
- package/dist/esm/telemetry/api/internal/trace/tracer.js +52 -0
- package/dist/esm/telemetry/api/internal/trace/workflow.js +54 -0
- package/dist/esm/telemetry/export/agent_engine.js +67 -0
- package/dist/esm/telemetry/export/agent_runtime.js +46 -0
- package/dist/esm/telemetry/export/google_cloud.js +733 -0
- package/dist/esm/telemetry/export/request_driven_metric_reader.js +276 -0
- package/dist/esm/telemetry/export/setup.js +160 -0
- package/dist/esm/tools/agent_tool.js +9 -1
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +23 -35
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +64 -21
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +26 -10
- package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +14 -23
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/computer_use/base_computer.js +99 -0
- package/dist/esm/tools/computer_use/computer_use_actions.js +477 -0
- package/dist/esm/tools/computer_use/computer_use_tool.js +217 -0
- package/dist/esm/tools/computer_use/computer_use_toolset.js +344 -0
- package/dist/esm/tools/function_tool.js +15 -5
- package/dist/esm/tools/google_api_tool/google_api_toolset.js +3 -2
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +3 -1
- package/dist/esm/tools/load_artifacts_tool.js +15 -5
- package/dist/esm/tools/load_memory_tool.js +2 -5
- package/dist/esm/tools/mcp/mcp_session_manager.js +23 -3
- package/dist/esm/tools/mcp/mcp_tool.js +7 -3
- package/dist/esm/tools/mcp/mcp_toolset.js +18 -6
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +27 -26
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +45 -14
- package/dist/esm/tools/skill/load_skill_resource_tool.js +7 -0
- package/dist/esm/tools/skill/load_skill_tool.js +3 -0
- package/dist/esm/tools/skill/run_skill_script_tool.js +12 -2
- package/dist/esm/tools/toolbox_toolset.js +47 -28
- package/dist/esm/utils/async_queue.js +37 -3
- package/dist/esm/utils/client_labels.js +9 -11
- package/dist/esm/utils/env_aware_utils.js +12 -7
- package/dist/esm/utils/error_utils.js +37 -1
- package/dist/esm/utils/failover_utils.js +10 -9
- package/dist/esm/utils/gemini_schema_util.js +124 -11
- package/dist/esm/utils/id_provider.js +33 -0
- package/dist/esm/utils/model_name.js +14 -0
- package/dist/esm/utils/simple_zod_to_json.js +13 -31
- package/dist/esm/utils/ssrf_guard.js +55 -15
- package/dist/esm/version.js +1 -1
- package/dist/esm/workflow/index.js +2 -1
- package/dist/esm/workflow/node_runner.js +26 -80
- package/dist/esm/workflow/nodes/parallel_worker.js +16 -6
- package/dist/esm/workflow/run_llm_agent_as_node.js +19 -14
- package/dist/esm/workflow/utils/retry_utils.js +2 -2
- package/dist/esm/workflow/workflow.js +12 -12
- package/dist/types/a2a/a2a_remote_agent.d.ts +6 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +3 -2
- package/dist/types/agents/agent_engine_client.d.ts +121 -3
- package/dist/types/agents/base_agent.d.ts +2 -0
- package/dist/types/agents/processors/content_processor_utils.d.ts +9 -9
- package/dist/types/agents/run_config.d.ts +14 -0
- package/dist/types/cli/cli_eval.d.ts +172 -9
- package/dist/types/cli/utils/cleanup.d.ts +18 -0
- package/dist/types/cli/utils/envs.d.ts +13 -3
- package/dist/types/cli/utils/evals.d.ts +64 -1
- package/dist/types/cli/utils/logs.d.ts +19 -2
- package/dist/types/cli/utils/path_validation.d.ts +30 -0
- package/dist/types/code_executors/container_code_executor.d.ts +49 -8
- package/dist/types/common.d.ts +16 -9
- package/dist/types/context/compaction_utils.d.ts +13 -1
- package/dist/types/events/event.d.ts +3 -0
- package/dist/types/features/feature_registry.d.ts +1 -0
- package/dist/types/index.d.ts +9 -6
- package/dist/types/plugins/base_plugin.d.ts +50 -21
- package/dist/types/plugins/plugin_manager.d.ts +13 -0
- package/dist/types/runner/runner.d.ts +11 -0
- package/dist/types/sessions/base_session_service.d.ts +0 -2
- package/dist/types/sessions/db/operations.d.ts +2 -1
- package/dist/types/sessions/db/schema.d.ts +5 -3
- package/dist/types/telemetry/api/instrumentation.d.ts +259 -0
- package/dist/types/telemetry/api/internal/common/accumulators.d.ts +91 -0
- package/dist/types/telemetry/api/internal/common/attributes.d.ts +90 -0
- package/dist/types/telemetry/api/internal/common/config.d.ts +61 -0
- package/dist/types/telemetry/api/internal/common/error.d.ts +29 -0
- package/dist/types/telemetry/api/internal/common/finish_reason.d.ts +18 -0
- package/dist/types/telemetry/api/internal/common/genai_messages.d.ts +26 -0
- package/dist/types/telemetry/api/internal/common/http_exchange.d.ts +50 -0
- package/dist/types/telemetry/api/internal/common/provider_name.d.ts +16 -0
- package/dist/types/telemetry/api/internal/common/redaction.d.ts +14 -0
- package/dist/types/telemetry/api/internal/common/serialization.d.ts +18 -0
- package/dist/types/telemetry/api/internal/common/token_usage.d.ts +47 -0
- package/dist/types/telemetry/api/internal/logs/inference.d.ts +15 -0
- package/dist/types/telemetry/api/internal/logs/logger.d.ts +13 -0
- package/dist/types/telemetry/api/internal/logs/mcp.d.ts +31 -0
- package/dist/types/telemetry/api/internal/metrics/agent.d.ts +28 -0
- package/dist/types/telemetry/api/internal/metrics/inference_start_hook.d.ts +12 -0
- package/dist/types/telemetry/api/internal/metrics/meters.d.ts +57 -0
- package/dist/types/telemetry/api/internal/metrics/tool.d.ts +44 -0
- package/dist/types/telemetry/api/internal/metrics/workflow.d.ts +32 -0
- package/dist/types/telemetry/api/internal/trace/agent.d.ts +14 -0
- package/dist/types/telemetry/api/internal/trace/compaction.d.ts +20 -0
- package/dist/types/telemetry/api/internal/trace/inference.d.ts +31 -0
- package/dist/types/telemetry/api/internal/trace/live.d.ts +21 -0
- package/dist/types/telemetry/api/internal/trace/node.d.ts +22 -0
- package/dist/types/telemetry/api/internal/trace/propagation.d.ts +22 -0
- package/dist/types/telemetry/api/internal/trace/tool.d.ts +57 -0
- package/dist/types/telemetry/api/internal/trace/tracer.d.ts +31 -0
- package/dist/types/telemetry/api/internal/trace/workflow.d.ts +21 -0
- package/dist/types/telemetry/export/agent_engine.d.ts +23 -0
- package/dist/types/telemetry/export/agent_runtime.d.ts +40 -0
- package/dist/types/telemetry/export/google_cloud.d.ts +189 -0
- package/dist/types/telemetry/export/request_driven_metric_reader.d.ts +144 -0
- package/dist/types/telemetry/{setup.d.ts → export/setup.d.ts} +3 -0
- package/dist/types/tools/agent_tool.d.ts +1 -1
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +13 -4
- package/dist/types/tools/base_toolset.d.ts +1 -1
- package/dist/types/tools/computer_use/base_computer.d.ts +281 -0
- package/dist/types/tools/computer_use/computer_use_actions.d.ts +53 -0
- package/dist/types/tools/computer_use/computer_use_tool.d.ts +108 -0
- package/dist/types/tools/computer_use/computer_use_toolset.d.ts +132 -0
- package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +2 -0
- package/dist/types/tools/load_artifacts_tool.d.ts +5 -1
- package/dist/types/tools/load_memory_tool.d.ts +13 -7
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +16 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +8 -8
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +7 -3
- package/dist/types/tools/toolbox_toolset.d.ts +15 -20
- package/dist/types/utils/async_queue.d.ts +14 -0
- package/dist/types/utils/env_aware_utils.d.ts +11 -0
- package/dist/types/utils/error_utils.d.ts +4 -0
- package/dist/types/utils/gemini_schema_util.d.ts +27 -6
- package/dist/types/utils/id_provider.d.ts +43 -0
- package/dist/types/utils/model_name.d.ts +8 -0
- package/dist/types/utils/ssrf_guard.d.ts +2 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/workflow/index.d.ts +1 -1
- package/dist/types/workflow/nodes/parallel_worker.d.ts +8 -1
- package/dist/web/index_web.js +86 -88
- package/dist/web/index_web.js.map +4 -4
- package/package.json +13 -15
- package/dist/cjs/telemetry/google_cloud.js +0 -116
- package/dist/cjs/telemetry/tracing.js +0 -393
- package/dist/esm/telemetry/google_cloud.js +0 -99
- package/dist/esm/telemetry/setup.js +0 -88
- package/dist/esm/telemetry/tracing.js +0 -361
- package/dist/types/telemetry/google_cloud.d.ts +0 -9
- package/dist/types/telemetry/tracing.d.ts +0 -143
|
@@ -0,0 +1,344 @@
|
|
|
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
|
+
var _a, _b;
|
|
20
|
+
import { Environment } from "@google/genai";
|
|
21
|
+
import { experimental } from "../../utils/experimental.js";
|
|
22
|
+
import { logger } from "../../utils/logger.js";
|
|
23
|
+
import { getGeminiMajorVersion } from "../../utils/model_name.js";
|
|
24
|
+
import { BaseToolset } from "../base_toolset.js";
|
|
25
|
+
import {
|
|
26
|
+
checkComputerUseEnabled,
|
|
27
|
+
ComputerEnvironment
|
|
28
|
+
} from "./base_computer.js";
|
|
29
|
+
import {
|
|
30
|
+
createComputerActions,
|
|
31
|
+
LEGACY_ACTION_NAMES,
|
|
32
|
+
OPTIONAL_KEY_ACTIONS,
|
|
33
|
+
OPTIONAL_MOUSE_ACTIONS,
|
|
34
|
+
unimplementedOptionalActions
|
|
35
|
+
} from "./computer_use_actions.js";
|
|
36
|
+
import {
|
|
37
|
+
ComputerUseTool,
|
|
38
|
+
isComputerUseTool
|
|
39
|
+
} from "./computer_use_tool.js";
|
|
40
|
+
const DIRECT_EXCLUSION_MAP = Object.freeze({
|
|
41
|
+
// Legacy -> modern.
|
|
42
|
+
click_at: ["click"],
|
|
43
|
+
hover_at: ["move"],
|
|
44
|
+
type_text_at: ["type"],
|
|
45
|
+
type_text: ["type"],
|
|
46
|
+
scroll_at: ["scroll"],
|
|
47
|
+
// Whole-page scroll has no modern counterpart.
|
|
48
|
+
scroll_document: [],
|
|
49
|
+
current_state: ["take_screenshot"],
|
|
50
|
+
key_combination: ["press_key", "hotkey"],
|
|
51
|
+
wait_5_seconds: ["wait"],
|
|
52
|
+
// Modern -> legacy.
|
|
53
|
+
click: ["click_at"],
|
|
54
|
+
move: ["hover_at"],
|
|
55
|
+
type: ["type_text_at"],
|
|
56
|
+
// Does not drop scroll_document.
|
|
57
|
+
scroll: ["scroll_at"],
|
|
58
|
+
take_screenshot: ["current_state"],
|
|
59
|
+
// key_combination is dropped only when both of these are excluded.
|
|
60
|
+
press_key: [],
|
|
61
|
+
hotkey: [],
|
|
62
|
+
wait: ["wait_5_seconds"]
|
|
63
|
+
});
|
|
64
|
+
const LEGACY_EXCLUSION_NAMES = /* @__PURE__ */ new Set([
|
|
65
|
+
"click_at",
|
|
66
|
+
"hover_at",
|
|
67
|
+
"type_text_at",
|
|
68
|
+
"type_text",
|
|
69
|
+
"scroll_at",
|
|
70
|
+
"scroll_document",
|
|
71
|
+
"current_state",
|
|
72
|
+
"key_combination",
|
|
73
|
+
"wait_5_seconds"
|
|
74
|
+
]);
|
|
75
|
+
const MODERN_EXCLUSION_NAMES = /* @__PURE__ */ new Set([
|
|
76
|
+
"click",
|
|
77
|
+
"move",
|
|
78
|
+
"type",
|
|
79
|
+
"scroll",
|
|
80
|
+
"take_screenshot",
|
|
81
|
+
"press_key",
|
|
82
|
+
"hotkey",
|
|
83
|
+
"wait",
|
|
84
|
+
...OPTIONAL_MOUSE_ACTIONS,
|
|
85
|
+
...OPTIONAL_KEY_ACTIONS
|
|
86
|
+
]);
|
|
87
|
+
const TYPING_ACTIONS = ["type", "type_text_at", "type_text"];
|
|
88
|
+
const computerQueues = /* @__PURE__ */ new WeakMap();
|
|
89
|
+
function expandLocalExclusions(excludedNames) {
|
|
90
|
+
var _a2;
|
|
91
|
+
const expanded = new Set(excludedNames);
|
|
92
|
+
for (const name of excludedNames) {
|
|
93
|
+
for (const counterpart of (_a2 = DIRECT_EXCLUSION_MAP[name]) != null ? _a2 : []) {
|
|
94
|
+
expanded.add(counterpart);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (TYPING_ACTIONS.some((name) => expanded.has(name))) {
|
|
98
|
+
TYPING_ACTIONS.forEach((name) => expanded.add(name));
|
|
99
|
+
}
|
|
100
|
+
if (expanded.has("press_key") && expanded.has("hotkey")) {
|
|
101
|
+
expanded.add("key_combination");
|
|
102
|
+
}
|
|
103
|
+
return expanded;
|
|
104
|
+
}
|
|
105
|
+
__name(expandLocalExclusions, "expandLocalExclusions");
|
|
106
|
+
function resolveExcludedPredefinedFunctions({
|
|
107
|
+
excludedNames,
|
|
108
|
+
model,
|
|
109
|
+
unimplementedActions
|
|
110
|
+
}) {
|
|
111
|
+
var _a2;
|
|
112
|
+
const major = getGeminiMajorVersion(model);
|
|
113
|
+
if (major !== void 0 && major < 3) {
|
|
114
|
+
if (excludedNames === void 0) {
|
|
115
|
+
return void 0;
|
|
116
|
+
}
|
|
117
|
+
const bothModernKeys = excludedNames.includes("press_key") && excludedNames.includes("hotkey");
|
|
118
|
+
const resolved2 = [];
|
|
119
|
+
for (const name of excludedNames) {
|
|
120
|
+
if (name === "press_key" || name === "hotkey") {
|
|
121
|
+
if (bothModernKeys) {
|
|
122
|
+
resolved2.push("key_combination");
|
|
123
|
+
}
|
|
124
|
+
} else if (name === "type_text") {
|
|
125
|
+
resolved2.push("type_text_at");
|
|
126
|
+
} else if (MODERN_EXCLUSION_NAMES.has(name)) {
|
|
127
|
+
resolved2.push(...(_a2 = DIRECT_EXCLUSION_MAP[name]) != null ? _a2 : []);
|
|
128
|
+
} else {
|
|
129
|
+
resolved2.push(name);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return [...new Set(resolved2)];
|
|
133
|
+
}
|
|
134
|
+
const resolved = [];
|
|
135
|
+
for (const name of excludedNames != null ? excludedNames : []) {
|
|
136
|
+
if (LEGACY_EXCLUSION_NAMES.has(name)) {
|
|
137
|
+
resolved.push(...DIRECT_EXCLUSION_MAP[name]);
|
|
138
|
+
} else {
|
|
139
|
+
resolved.push(name);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (major !== void 0 && major >= 3) {
|
|
143
|
+
resolved.push(...unimplementedActions);
|
|
144
|
+
}
|
|
145
|
+
const deduped = [...new Set(resolved)];
|
|
146
|
+
if (deduped.length === 0 && excludedNames === void 0) {
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
return deduped;
|
|
150
|
+
}
|
|
151
|
+
__name(resolveExcludedPredefinedFunctions, "resolveExcludedPredefinedFunctions");
|
|
152
|
+
async function runExclusive(computer, action) {
|
|
153
|
+
var _a2;
|
|
154
|
+
const previous = (_a2 = computerQueues.get(computer)) != null ? _a2 : Promise.resolve();
|
|
155
|
+
const result = previous.then(action);
|
|
156
|
+
computerQueues.set(
|
|
157
|
+
computer,
|
|
158
|
+
result.then(
|
|
159
|
+
() => void 0,
|
|
160
|
+
() => void 0
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
__name(runExclusive, "runExclusive");
|
|
166
|
+
function toGenaiEnvironment(environment) {
|
|
167
|
+
switch (environment) {
|
|
168
|
+
case ComputerEnvironment.ENVIRONMENT_UNSPECIFIED:
|
|
169
|
+
return Environment.ENVIRONMENT_UNSPECIFIED;
|
|
170
|
+
case ComputerEnvironment.ENVIRONMENT_BROWSER:
|
|
171
|
+
return Environment.ENVIRONMENT_BROWSER;
|
|
172
|
+
default: {
|
|
173
|
+
const exhaustive = environment;
|
|
174
|
+
throw new Error(`Unknown computer environment: ${exhaustive}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
__name(toGenaiEnvironment, "toGenaiEnvironment");
|
|
179
|
+
function isComputerUseConfig(tool) {
|
|
180
|
+
return "computerUse" in tool && tool.computerUse !== void 0;
|
|
181
|
+
}
|
|
182
|
+
__name(isComputerUseConfig, "isComputerUseConfig");
|
|
183
|
+
async function adaptComputerUseTool({
|
|
184
|
+
methodName,
|
|
185
|
+
adapter,
|
|
186
|
+
llmRequest
|
|
187
|
+
}) {
|
|
188
|
+
if (!LEGACY_ACTION_NAMES.includes(methodName)) {
|
|
189
|
+
logger.warn(`Method ${methodName} is not a valid BaseComputer method`);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const original = Object.hasOwn(llmRequest.toolsDict, methodName) ? llmRequest.toolsDict[methodName] : void 0;
|
|
193
|
+
if (!isComputerUseTool(original)) {
|
|
194
|
+
logger.warn(`Method ${methodName} not found in toolsDict`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const adapted = await adapter(original.func);
|
|
198
|
+
llmRequest.toolsDict[adapted.name] = new ComputerUseTool({
|
|
199
|
+
...adapted,
|
|
200
|
+
screenSize: original.screenSize,
|
|
201
|
+
virtualScreenSize: original.virtualScreenSize
|
|
202
|
+
});
|
|
203
|
+
if (adapted.name !== methodName) {
|
|
204
|
+
delete llmRequest.toolsDict[methodName];
|
|
205
|
+
}
|
|
206
|
+
logger.debug(`Adapted tool ${methodName} to ${adapted.name}`);
|
|
207
|
+
}
|
|
208
|
+
__name(adaptComputerUseTool, "adaptComputerUseTool");
|
|
209
|
+
const COMPUTER_USE_TOOLSET_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
|
|
210
|
+
"google.adk.computerUseToolset"
|
|
211
|
+
);
|
|
212
|
+
function isComputerUseToolset(obj) {
|
|
213
|
+
return typeof obj === "object" && obj !== null && COMPUTER_USE_TOOLSET_SIGNATURE_SYMBOL in obj && obj[COMPUTER_USE_TOOLSET_SIGNATURE_SYMBOL] === true;
|
|
214
|
+
}
|
|
215
|
+
__name(isComputerUseToolset, "isComputerUseToolset");
|
|
216
|
+
let ComputerUseToolset = class extends (_b = BaseToolset, _a = COMPUTER_USE_TOOLSET_SIGNATURE_SYMBOL, _b) {
|
|
217
|
+
/**
|
|
218
|
+
* @param options The computer and its configuration.
|
|
219
|
+
*/
|
|
220
|
+
constructor(options) {
|
|
221
|
+
var _a2;
|
|
222
|
+
checkComputerUseEnabled();
|
|
223
|
+
super([]);
|
|
224
|
+
/** A unique symbol to identify ADK computer use toolset class. */
|
|
225
|
+
this[_a] = true;
|
|
226
|
+
this.closed = false;
|
|
227
|
+
this.computer = options.computer;
|
|
228
|
+
this.excludedPredefinedFunctions = options.excludedPredefinedFunctions;
|
|
229
|
+
this.allowPrivateNetworkAccess = (_a2 = options.allowPrivateNetworkAccess) != null ? _a2 : false;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Returns a tool for every action the computer supports, except the
|
|
233
|
+
* excluded ones. The computer is initialized on the first call, and the
|
|
234
|
+
* tools are cached until {@link close}.
|
|
235
|
+
*/
|
|
236
|
+
async getTools() {
|
|
237
|
+
var _a2;
|
|
238
|
+
(_a2 = this.loadingTools) != null ? _a2 : this.loadingTools = this.loadTools();
|
|
239
|
+
try {
|
|
240
|
+
return await this.loadingTools;
|
|
241
|
+
} catch (error) {
|
|
242
|
+
this.loadingTools = void 0;
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Closes the computer and drops the cached tools. The next call to
|
|
248
|
+
* {@link getTools} initializes the computer again.
|
|
249
|
+
*/
|
|
250
|
+
async close() {
|
|
251
|
+
if (!this.closed) {
|
|
252
|
+
await this.computer.close();
|
|
253
|
+
this.closed = true;
|
|
254
|
+
}
|
|
255
|
+
this.initializing = void 0;
|
|
256
|
+
this.loadingTools = void 0;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Registers the computer use tools in the request and adds the computer use
|
|
260
|
+
* configuration, unless the request already has one.
|
|
261
|
+
*
|
|
262
|
+
* @param _toolContext The context of the tool.
|
|
263
|
+
* @param llmRequest The outgoing request.
|
|
264
|
+
*/
|
|
265
|
+
async processLlmRequest(_toolContext, llmRequest) {
|
|
266
|
+
var _a2, _b2, _c;
|
|
267
|
+
for (const tool of await this.getTools()) {
|
|
268
|
+
llmRequest.toolsDict[tool.name] = tool;
|
|
269
|
+
}
|
|
270
|
+
(_a2 = llmRequest.config) != null ? _a2 : llmRequest.config = {};
|
|
271
|
+
(_c = (_b2 = llmRequest.config).tools) != null ? _c : _b2.tools = [];
|
|
272
|
+
if (llmRequest.config.tools.some(isComputerUseConfig)) {
|
|
273
|
+
logger.debug("Computer use already configured in LLM request");
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const environment = toGenaiEnvironment(await this.computer.environment());
|
|
277
|
+
const excludedPredefinedFunctions = resolveExcludedPredefinedFunctions({
|
|
278
|
+
excludedNames: this.excludedPredefinedFunctions,
|
|
279
|
+
model: llmRequest.model,
|
|
280
|
+
unimplementedActions: unimplementedOptionalActions(this.computer)
|
|
281
|
+
});
|
|
282
|
+
llmRequest.config.tools.push({
|
|
283
|
+
computerUse: excludedPredefinedFunctions === void 0 ? { environment } : { environment, excludedPredefinedFunctions }
|
|
284
|
+
});
|
|
285
|
+
logger.debug(
|
|
286
|
+
`Added computer use tool with environment: ${environment}, excluded functions: ${excludedPredefinedFunctions}`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
ensureInitialized() {
|
|
290
|
+
var _a2;
|
|
291
|
+
(_a2 = this.initializing) != null ? _a2 : this.initializing = this.computer.initialize().then(
|
|
292
|
+
() => {
|
|
293
|
+
this.closed = false;
|
|
294
|
+
},
|
|
295
|
+
(error) => {
|
|
296
|
+
this.initializing = void 0;
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
return this.initializing;
|
|
301
|
+
}
|
|
302
|
+
async loadTools() {
|
|
303
|
+
var _a2;
|
|
304
|
+
await this.ensureInitialized();
|
|
305
|
+
const screenSize = await this.computer.screenSize();
|
|
306
|
+
const excluded = expandLocalExclusions(
|
|
307
|
+
(_a2 = this.excludedPredefinedFunctions) != null ? _a2 : []
|
|
308
|
+
);
|
|
309
|
+
return createComputerActions({
|
|
310
|
+
computer: this.computer,
|
|
311
|
+
allowPrivateNetworkAccess: this.allowPrivateNetworkAccess
|
|
312
|
+
}).filter((action) => !excluded.has(action.name)).map(
|
|
313
|
+
(action) => new ComputerUseTool({
|
|
314
|
+
name: action.name,
|
|
315
|
+
description: action.description,
|
|
316
|
+
parameters: action.parameters,
|
|
317
|
+
execute: this.bindToComputer(action),
|
|
318
|
+
screenSize
|
|
319
|
+
})
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Wraps an action so it runs exclusively on the computer, after the
|
|
324
|
+
* computer has prepared for the calling session.
|
|
325
|
+
*/
|
|
326
|
+
bindToComputer(action) {
|
|
327
|
+
const computer = this.computer;
|
|
328
|
+
return (args, toolContext) => runExclusive(computer, async () => {
|
|
329
|
+
if (toolContext) {
|
|
330
|
+
await computer.prepare(toolContext);
|
|
331
|
+
}
|
|
332
|
+
return action.execute(args);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
__name(ComputerUseToolset, "ComputerUseToolset");
|
|
337
|
+
ComputerUseToolset = __decorateClass([
|
|
338
|
+
experimental
|
|
339
|
+
], ComputerUseToolset);
|
|
340
|
+
export {
|
|
341
|
+
ComputerUseToolset,
|
|
342
|
+
adaptComputerUseTool,
|
|
343
|
+
isComputerUseToolset
|
|
344
|
+
};
|
|
@@ -29,9 +29,10 @@ function toResponseSchema(response) {
|
|
|
29
29
|
return zodObjectToSchema(response);
|
|
30
30
|
}
|
|
31
31
|
if (typeof response === "object" && response !== null && "safeParse" in response && typeof response.safeParse === "function") {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const jsonSchema = toJsonSchema(response);
|
|
33
|
+
return (_a2 = toGeminiSchema(jsonSchema)) != null ? _a2 : {
|
|
34
|
+
type: Type.TYPE_UNSPECIFIED
|
|
35
|
+
};
|
|
35
36
|
}
|
|
36
37
|
return response;
|
|
37
38
|
}
|
|
@@ -251,6 +252,11 @@ function annotateNullableFields(schema) {
|
|
|
251
252
|
if (!isPlainRecord(propertySchema)) {
|
|
252
253
|
continue;
|
|
253
254
|
}
|
|
255
|
+
const propType = propertySchema["type"];
|
|
256
|
+
if (propType === null || propType === "null" || propType === Type.NULL) {
|
|
257
|
+
propertySchema["type"] = Type.OBJECT;
|
|
258
|
+
propertySchema["nullable"] = true;
|
|
259
|
+
}
|
|
254
260
|
const anyOf = propertySchema["anyOf"];
|
|
255
261
|
if (!Array.isArray(anyOf)) {
|
|
256
262
|
continue;
|
|
@@ -353,8 +359,12 @@ function processParameterSchema(vertexai, schema) {
|
|
|
353
359
|
__name(processParameterSchema, "processParameterSchema");
|
|
354
360
|
function mapPropertySchemaType(propertySchema) {
|
|
355
361
|
var _a2, _b2;
|
|
356
|
-
|
|
357
|
-
|
|
362
|
+
const rawType = propertySchema["type"];
|
|
363
|
+
if (rawType === null || rawType === "null" || rawType === Type.NULL) {
|
|
364
|
+
propertySchema["type"] = Type.OBJECT;
|
|
365
|
+
propertySchema["nullable"] = true;
|
|
366
|
+
} else if (typeof rawType === "string") {
|
|
367
|
+
propertySchema["type"] = (_a2 = SCHEMA_TYPE_MAP[rawType]) != null ? _a2 : Type.TYPE_UNSPECIFIED;
|
|
358
368
|
if (propertySchema["type"] === Type.ARRAY && isPlainRecord(propertySchema["items"])) {
|
|
359
369
|
mapPropertySchemaType(propertySchema["items"]);
|
|
360
370
|
}
|
|
@@ -45,6 +45,7 @@ let GoogleApiToolset = class extends (_b = BaseToolset, _a = GOOGLE_API_TOOLSET_
|
|
|
45
45
|
this.apiVersion = options.apiVersion;
|
|
46
46
|
this.clientId = options.clientId;
|
|
47
47
|
this.clientSecret = options.clientSecret;
|
|
48
|
+
this.scopes = options.scopes ? [...options.scopes] : void 0;
|
|
48
49
|
}
|
|
49
50
|
async loadToolsetWithOidcAuth() {
|
|
50
51
|
var _a2, _b2, _c, _d, _e;
|
|
@@ -60,7 +61,7 @@ let GoogleApiToolset = class extends (_b = BaseToolset, _a = GOOGLE_API_TOOLSET_
|
|
|
60
61
|
const oauth2Scheme = (_b2 = (_a2 = specDict.components) == null ? void 0 : _a2.securitySchemes) == null ? void 0 : _b2["oauth2"];
|
|
61
62
|
const scopesMap = (_e = (_d = (_c = oauth2Scheme == null ? void 0 : oauth2Scheme.flows) == null ? void 0 : _c.authorizationCode) == null ? void 0 : _d.scopes) != null ? _e : {};
|
|
62
63
|
const firstScope = Object.keys(scopesMap)[0];
|
|
63
|
-
const scopes = firstScope ? [firstScope] : void 0;
|
|
64
|
+
const scopes = this.scopes !== void 0 ? [...this.scopes] : firstScope ? [firstScope] : void 0;
|
|
64
65
|
const authScheme = {
|
|
65
66
|
type: "openIdConnect",
|
|
66
67
|
openIdConnectUrl: "",
|
|
@@ -83,7 +84,7 @@ let GoogleApiToolset = class extends (_b = BaseToolset, _a = GOOGLE_API_TOOLSET_
|
|
|
83
84
|
}
|
|
84
85
|
async ensureToolsLoaded() {
|
|
85
86
|
var _a2;
|
|
86
|
-
if (this.openapiToolset
|
|
87
|
+
if (this.openapiToolset) {
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
90
|
(_a2 = this.loadingPromise) != null ? _a2 : this.loadingPromise = (async () => {
|
|
@@ -205,11 +205,13 @@ function convertOperation(methodData, pathParams) {
|
|
|
205
205
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
206
206
|
const parameters = [];
|
|
207
207
|
for (const paramName of pathParams) {
|
|
208
|
+
const paramData = methodData.parameters && Object.hasOwn(methodData.parameters, paramName) ? methodData.parameters[paramName] : void 0;
|
|
208
209
|
parameters.push({
|
|
209
210
|
name: paramName,
|
|
210
211
|
in: "path",
|
|
212
|
+
...(paramData == null ? void 0 : paramData.description) !== void 0 ? { description: paramData.description } : {},
|
|
211
213
|
required: true,
|
|
212
|
-
schema: { type: "string" }
|
|
214
|
+
schema: paramData ? convertParameterSchema(paramData) : { type: "string" }
|
|
213
215
|
});
|
|
214
216
|
}
|
|
215
217
|
const pathParamSet = new Set(pathParams);
|
|
@@ -25,7 +25,7 @@ function normalizeMimeType(mimeType) {
|
|
|
25
25
|
if (!mimeType) {
|
|
26
26
|
return void 0;
|
|
27
27
|
}
|
|
28
|
-
return mimeType.split(";")[0].trim();
|
|
28
|
+
return mimeType.split(";")[0].trim().toLowerCase();
|
|
29
29
|
}
|
|
30
30
|
__name(normalizeMimeType, "normalizeMimeType");
|
|
31
31
|
function isInlineMimeTypeSupported(mimeType) {
|
|
@@ -43,23 +43,33 @@ function base64ByteLength(data) {
|
|
|
43
43
|
return Math.floor(digits * 3 / 4);
|
|
44
44
|
}
|
|
45
45
|
__name(base64ByteLength, "base64ByteLength");
|
|
46
|
-
function asSafePartForLlm(artifact, artifactName) {
|
|
46
|
+
function asSafePartForLlm(artifact, artifactName, options) {
|
|
47
|
+
if ((options == null ? void 0 : options.inlineMediaAsPlaceholder) && !artifact.inlineData && artifact.fileData) {
|
|
48
|
+
const fileUri = artifact.fileData.fileUri || "unknown";
|
|
49
|
+
const mimeType2 = normalizeMimeType(artifact.fileData.mimeType) || "application/octet-stream";
|
|
50
|
+
return {
|
|
51
|
+
text: `[Artifact: ${artifactName}, uri: ${fileUri}, type: ${mimeType2}.]`
|
|
52
|
+
};
|
|
53
|
+
}
|
|
47
54
|
const inlineData = artifact.inlineData;
|
|
48
55
|
if (!inlineData) {
|
|
49
56
|
return artifact;
|
|
50
57
|
}
|
|
51
|
-
if (isInlineMimeTypeSupported(inlineData.mimeType)) {
|
|
58
|
+
if (!(options == null ? void 0 : options.inlineMediaAsPlaceholder) && isInlineMimeTypeSupported(inlineData.mimeType)) {
|
|
52
59
|
return artifact;
|
|
53
60
|
}
|
|
54
61
|
const mimeType = normalizeMimeType(inlineData.mimeType) || "application/octet-stream";
|
|
62
|
+
const isTextLike = mimeType.startsWith("text/") || TEXT_LIKE_MIME_TYPES.has(mimeType);
|
|
55
63
|
const data = inlineData.data;
|
|
56
|
-
if (!data) {
|
|
64
|
+
if (data === void 0 || data === null || !isTextLike && data === "") {
|
|
57
65
|
return {
|
|
58
66
|
text: `[Artifact: ${artifactName}, type: ${mimeType}. No inline data was provided.]`
|
|
59
67
|
};
|
|
60
68
|
}
|
|
61
|
-
const isTextLike = mimeType.startsWith("text/") || TEXT_LIKE_MIME_TYPES.has(mimeType);
|
|
62
69
|
if (isTextLike) {
|
|
70
|
+
if (data === "") {
|
|
71
|
+
return { text: "" };
|
|
72
|
+
}
|
|
63
73
|
try {
|
|
64
74
|
return { text: base64Decode(data.replace(/-/g, "+").replace(/_/g, "/")) };
|
|
65
75
|
} catch {
|
|
@@ -17,7 +17,7 @@ const _LoadMemoryTool = class _LoadMemoryTool extends BaseTool {
|
|
|
17
17
|
var _a;
|
|
18
18
|
super({
|
|
19
19
|
name: "load_memory",
|
|
20
|
-
description: "Loads the memory for the current user
|
|
20
|
+
description: "Loads the memory for the current user."
|
|
21
21
|
});
|
|
22
22
|
this.textOnlyContent = (_a = options.textOnlyContent) != null ? _a : false;
|
|
23
23
|
}
|
|
@@ -37,10 +37,7 @@ const _LoadMemoryTool = class _LoadMemoryTool extends BaseTool {
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
async runAsync({
|
|
41
|
-
args,
|
|
42
|
-
toolContext
|
|
43
|
-
}) {
|
|
40
|
+
async runAsync({ args, toolContext }) {
|
|
44
41
|
const query = args["query"];
|
|
45
42
|
if (!toolContext.invocationContext.memoryService) {
|
|
46
43
|
throw new Error("Memory service is not initialized.");
|
|
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
* Copyright 2025 Google LLC
|
|
29
29
|
* SPDX-License-Identifier: Apache-2.0
|
|
30
30
|
*/
|
|
31
|
+
import { instrumentMcpFetch } from "../../telemetry/api/instrumentation.js";
|
|
31
32
|
import { mergeTrackingHeaders } from "../../utils/client_labels.js";
|
|
32
33
|
import { formatError } from "../../utils/error_utils.js";
|
|
33
34
|
import { logger } from "../../utils/logger.js";
|
|
@@ -48,7 +49,8 @@ function buildTransportOptions(params) {
|
|
|
48
49
|
requestInit: {
|
|
49
50
|
...transportOptions == null ? void 0 : transportOptions.requestInit,
|
|
50
51
|
headers: mergeTrackingHeaders(callerHeaders)
|
|
51
|
-
}
|
|
52
|
+
},
|
|
53
|
+
fetch: instrumentMcpFetch(transportOptions == null ? void 0 : transportOptions.fetch)
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
56
|
__name(buildTransportOptions, "buildTransportOptions");
|
|
@@ -60,7 +62,8 @@ function buildSseTransportOptions(params) {
|
|
|
60
62
|
requestInit: {
|
|
61
63
|
...transportOptions == null ? void 0 : transportOptions.requestInit,
|
|
62
64
|
headers: mergeTrackingHeaders(callerHeaders)
|
|
63
|
-
}
|
|
65
|
+
},
|
|
66
|
+
fetch: instrumentMcpFetch(transportOptions == null ? void 0 : transportOptions.fetch)
|
|
64
67
|
};
|
|
65
68
|
}
|
|
66
69
|
__name(buildSseTransportOptions, "buildSseTransportOptions");
|
|
@@ -69,6 +72,23 @@ const _MCPSessionManager = class _MCPSessionManager {
|
|
|
69
72
|
this.activeSessions = /* @__PURE__ */ new Set();
|
|
70
73
|
this.connectionParams = connectionParams;
|
|
71
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Builds per-request options for MCP client operations.
|
|
77
|
+
*
|
|
78
|
+
* For a stdio connection with a configured `timeout`, the timeout is
|
|
79
|
+
* converted from seconds to milliseconds. Otherwise the MCP SDK applies its
|
|
80
|
+
* own default request timeout.
|
|
81
|
+
*
|
|
82
|
+
* @param signal Optional abort signal to attach to the request.
|
|
83
|
+
* @return The request options for the MCP SDK client.
|
|
84
|
+
*/
|
|
85
|
+
getRequestOptions(signal) {
|
|
86
|
+
const options = signal !== void 0 ? { signal } : {};
|
|
87
|
+
if (this.connectionParams.type === "StdioConnectionParams" && this.connectionParams.timeout !== void 0) {
|
|
88
|
+
options.timeout = this.connectionParams.timeout * 1e3;
|
|
89
|
+
}
|
|
90
|
+
return options;
|
|
91
|
+
}
|
|
72
92
|
async createSession() {
|
|
73
93
|
const { Client } = await loadOptionalPeer(
|
|
74
94
|
MCP_SDK,
|
|
@@ -86,7 +106,7 @@ const _MCPSessionManager = class _MCPSessionManager {
|
|
|
86
106
|
this.connectionParams.serverParams
|
|
87
107
|
);
|
|
88
108
|
transport.onerror = logTransportError;
|
|
89
|
-
await client.connect(transport);
|
|
109
|
+
await client.connect(transport, this.getRequestOptions());
|
|
90
110
|
break;
|
|
91
111
|
}
|
|
92
112
|
case "StreamableHTTPConnectionParams": {
|
|
@@ -31,9 +31,13 @@ const _MCPTool = class _MCPTool extends BaseTool {
|
|
|
31
31
|
try {
|
|
32
32
|
const callRequest = {};
|
|
33
33
|
callRequest.params = { name: this.originalName, arguments: request.args };
|
|
34
|
-
const result = await session.callTool(
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const result = await session.callTool(
|
|
35
|
+
callRequest.params,
|
|
36
|
+
void 0,
|
|
37
|
+
this.mcpSessionManager.getRequestOptions(
|
|
38
|
+
request.toolContext.abortSignal
|
|
39
|
+
)
|
|
40
|
+
);
|
|
37
41
|
return result;
|
|
38
42
|
} finally {
|
|
39
43
|
await this.mcpSessionManager.closeSession(session);
|
|
@@ -20,7 +20,10 @@ const _MCPToolset = class _MCPToolset extends BaseToolset {
|
|
|
20
20
|
const session = await this.mcpSessionManager.createSession();
|
|
21
21
|
let listResult;
|
|
22
22
|
try {
|
|
23
|
-
listResult = await session.listTools(
|
|
23
|
+
listResult = await session.listTools(
|
|
24
|
+
void 0,
|
|
25
|
+
this.mcpSessionManager.getRequestOptions()
|
|
26
|
+
);
|
|
24
27
|
} finally {
|
|
25
28
|
await this.mcpSessionManager.closeSession(session);
|
|
26
29
|
}
|
|
@@ -45,7 +48,10 @@ const _MCPToolset = class _MCPToolset extends BaseToolset {
|
|
|
45
48
|
async listResources() {
|
|
46
49
|
const session = await this.mcpSessionManager.createSession();
|
|
47
50
|
try {
|
|
48
|
-
const result = await session.listResources(
|
|
51
|
+
const result = await session.listResources(
|
|
52
|
+
void 0,
|
|
53
|
+
this.mcpSessionManager.getRequestOptions()
|
|
54
|
+
);
|
|
49
55
|
return result.resources.map((resource) => resource.name);
|
|
50
56
|
} finally {
|
|
51
57
|
await this.mcpSessionManager.closeSession(session);
|
|
@@ -62,7 +68,10 @@ const _MCPToolset = class _MCPToolset extends BaseToolset {
|
|
|
62
68
|
const session = await this.mcpSessionManager.createSession();
|
|
63
69
|
let result;
|
|
64
70
|
try {
|
|
65
|
-
result = await session.listResources(
|
|
71
|
+
result = await session.listResources(
|
|
72
|
+
void 0,
|
|
73
|
+
this.mcpSessionManager.getRequestOptions()
|
|
74
|
+
);
|
|
66
75
|
} finally {
|
|
67
76
|
await this.mcpSessionManager.closeSession(session);
|
|
68
77
|
}
|
|
@@ -92,9 +101,12 @@ const _MCPToolset = class _MCPToolset extends BaseToolset {
|
|
|
92
101
|
}
|
|
93
102
|
const session = await this.mcpSessionManager.createSession();
|
|
94
103
|
try {
|
|
95
|
-
const result = await session.readResource(
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
const result = await session.readResource(
|
|
105
|
+
{
|
|
106
|
+
uri: resourceInfo.uri
|
|
107
|
+
},
|
|
108
|
+
this.mcpSessionManager.getRequestOptions()
|
|
109
|
+
);
|
|
98
110
|
return result.contents;
|
|
99
111
|
} finally {
|
|
100
112
|
await this.mcpSessionManager.closeSession(session);
|