@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
|
@@ -9,7 +9,6 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
9
9
|
*/
|
|
10
10
|
var _a;
|
|
11
11
|
import { createPartFromText, Modality } from "@google/genai";
|
|
12
|
-
import { context, trace } from "@opentelemetry/api";
|
|
13
12
|
import { isBaseAgent } from "../agents/base_agent.js";
|
|
14
13
|
import { reservedFunctionCallName } from "../agents/framework_function_calls.js";
|
|
15
14
|
import {
|
|
@@ -39,18 +38,25 @@ import {
|
|
|
39
38
|
withoutInternalMetadata
|
|
40
39
|
} from "../events/internal_metadata.js";
|
|
41
40
|
import { PluginManager } from "../plugins/plugin_manager.js";
|
|
42
|
-
import {
|
|
43
|
-
runAsyncGeneratorWithOtelContext,
|
|
44
|
-
tracer
|
|
45
|
-
} from "../telemetry/tracing.js";
|
|
41
|
+
import { recordInvocation } from "../telemetry/api/instrumentation.js";
|
|
46
42
|
import { isBaseToolset } from "../tools/base_toolset.js";
|
|
43
|
+
import {
|
|
44
|
+
formatError,
|
|
45
|
+
isInvocationCancellation,
|
|
46
|
+
toError
|
|
47
|
+
} from "../utils/error_utils.js";
|
|
47
48
|
import { logger } from "../utils/logger.js";
|
|
48
49
|
import { isGemini2OrAbove } from "../utils/model_name.js";
|
|
49
50
|
import { stringifyWithRedactedInlineData } from "../utils/redact_inline_data.js";
|
|
51
|
+
import { isParallelWorker, isWorkflow } from "../workflow/index.js";
|
|
50
52
|
import {
|
|
51
53
|
asRunnableRoot,
|
|
52
54
|
runNodeAsInvocation
|
|
53
55
|
} from "../workflow/run_node_as_invocation.js";
|
|
56
|
+
const TOOLSET_CLEANUP_TIMEOUT_MS = 1e4;
|
|
57
|
+
const TOOLSET_CLEANUP_TIMEOUT_SYMBOL = /* @__PURE__ */ Symbol(
|
|
58
|
+
"google.adk.runner.toolsetCleanupTimeout"
|
|
59
|
+
);
|
|
54
60
|
const RUNNER_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.runner");
|
|
55
61
|
function isRunner(obj) {
|
|
56
62
|
return typeof obj === "object" && obj !== null && RUNNER_SIGNATURE_SYMBOL in obj && obj[RUNNER_SIGNATURE_SYMBOL] === true;
|
|
@@ -150,59 +156,57 @@ const _Runner = class _Runner {
|
|
|
150
156
|
newMessage.role = "user";
|
|
151
157
|
}
|
|
152
158
|
rejectReservedFunctionCalls(newMessage);
|
|
153
|
-
const
|
|
154
|
-
const ctx = trace.setSpan(context.active(), span);
|
|
159
|
+
const runnerCtx = this;
|
|
155
160
|
try {
|
|
156
|
-
yield*
|
|
157
|
-
|
|
158
|
-
this,
|
|
161
|
+
yield* recordInvocation(
|
|
162
|
+
{ entrypoint: this.agent, sessionId, runConfig },
|
|
159
163
|
async function* () {
|
|
160
|
-
var _a2, _b, _c, _d, _e
|
|
161
|
-
const session = await
|
|
164
|
+
var _a2, _b, _c, _d, _e;
|
|
165
|
+
const session = await runnerCtx.resolveSession(userId, sessionId);
|
|
162
166
|
if ((_a2 = params.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
163
167
|
return;
|
|
164
168
|
}
|
|
165
169
|
if (!session) {
|
|
166
|
-
if (!
|
|
170
|
+
if (!runnerCtx.appName) {
|
|
167
171
|
throw new Error(
|
|
168
172
|
`Session lookup failed: appName must be provided in runner constructor (or via app.name)`
|
|
169
173
|
);
|
|
170
174
|
}
|
|
171
175
|
throw new Error(
|
|
172
|
-
`Session not found: ${sessionId} (appName=${
|
|
176
|
+
`Session not found: ${sessionId} (appName=${runnerCtx.appName}, userId=${userId})`
|
|
173
177
|
);
|
|
174
178
|
}
|
|
175
|
-
if (runConfig.supportCfc && isLlmAgent(
|
|
176
|
-
const modelName =
|
|
179
|
+
if (runConfig.supportCfc && isLlmAgent(runnerCtx.agent)) {
|
|
180
|
+
const modelName = runnerCtx.agent.canonicalModel.model;
|
|
177
181
|
if (!isGemini2OrAbove(modelName)) {
|
|
178
182
|
throw new Error(
|
|
179
|
-
`CFC is not supported for model: ${modelName} in agent: ${
|
|
183
|
+
`CFC is not supported for model: ${modelName} in agent: ${runnerCtx.agent.name}`
|
|
180
184
|
);
|
|
181
185
|
}
|
|
182
|
-
if (!isBuiltInCodeExecutor(
|
|
183
|
-
|
|
186
|
+
if (!isBuiltInCodeExecutor(runnerCtx.agent.codeExecutor)) {
|
|
187
|
+
runnerCtx.agent.codeExecutor = new BuiltInCodeExecutor();
|
|
184
188
|
}
|
|
185
189
|
}
|
|
186
190
|
const invocationContext = new InvocationContext({
|
|
187
|
-
artifactService:
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
artifactService: runnerCtx.artifactService ? isSessionArtifactService(runnerCtx.artifactService) ? runnerCtx.artifactService : new ScopedArtifactService(
|
|
192
|
+
runnerCtx.artifactService,
|
|
193
|
+
runnerCtx.appName,
|
|
190
194
|
userId,
|
|
191
195
|
sessionId
|
|
192
196
|
) : void 0,
|
|
193
|
-
sessionService:
|
|
194
|
-
memoryService:
|
|
195
|
-
credentialService:
|
|
197
|
+
sessionService: runnerCtx.sessionService,
|
|
198
|
+
memoryService: runnerCtx.memoryService,
|
|
199
|
+
credentialService: runnerCtx.credentialService,
|
|
196
200
|
invocationId: newInvocationContextId(),
|
|
197
|
-
agent: isBaseAgent(
|
|
201
|
+
agent: isBaseAgent(runnerCtx.agent) ? runnerCtx.agent : void 0,
|
|
198
202
|
session,
|
|
199
203
|
userContent: newMessage,
|
|
200
204
|
runConfig,
|
|
201
205
|
a2aMetadata: runConfig.a2aMetadata,
|
|
202
|
-
pluginManager:
|
|
206
|
+
pluginManager: runnerCtx.pluginManager,
|
|
203
207
|
abortSignal: params.abortSignal
|
|
204
208
|
});
|
|
205
|
-
const pluginUserMessage = await
|
|
209
|
+
const pluginUserMessage = await runnerCtx.pluginManager.runOnUserMessageCallback({
|
|
206
210
|
userMessage: newMessage,
|
|
207
211
|
invocationContext
|
|
208
212
|
});
|
|
@@ -217,7 +221,7 @@ const _Runner = class _Runner {
|
|
|
217
221
|
throw new Error("No parts in the newMessage.");
|
|
218
222
|
}
|
|
219
223
|
if (runConfig.saveInputBlobsAsArtifacts) {
|
|
220
|
-
newMessage = await
|
|
224
|
+
newMessage = await runnerCtx.saveArtifacts(
|
|
221
225
|
invocationContext.artifactService,
|
|
222
226
|
invocationContext.invocationId,
|
|
223
227
|
newMessage
|
|
@@ -226,7 +230,7 @@ const _Runner = class _Runner {
|
|
|
226
230
|
return;
|
|
227
231
|
}
|
|
228
232
|
}
|
|
229
|
-
await
|
|
233
|
+
await runnerCtx.sessionService.appendEvent({
|
|
230
234
|
session,
|
|
231
235
|
event: createEvent({
|
|
232
236
|
invocationId: invocationContext.invocationId,
|
|
@@ -241,83 +245,137 @@ const _Runner = class _Runner {
|
|
|
241
245
|
return;
|
|
242
246
|
}
|
|
243
247
|
}
|
|
244
|
-
if (isBaseAgent(
|
|
245
|
-
invocationContext.agent =
|
|
248
|
+
if (isBaseAgent(runnerCtx.agent)) {
|
|
249
|
+
invocationContext.agent = runnerCtx.determineAgentForResumption(
|
|
246
250
|
session,
|
|
247
|
-
|
|
251
|
+
runnerCtx.agent
|
|
248
252
|
);
|
|
249
253
|
}
|
|
250
254
|
if (newMessage) {
|
|
251
|
-
|
|
252
|
-
invocationContext
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
if (beforeRunCallbackResponse) {
|
|
258
|
-
const earlyExitEvent = createEvent({
|
|
259
|
-
invocationId: invocationContext.invocationId,
|
|
260
|
-
author: "model",
|
|
261
|
-
content: beforeRunCallbackResponse
|
|
262
|
-
});
|
|
263
|
-
await this.sessionService.appendEvent({
|
|
264
|
-
session,
|
|
265
|
-
event: earlyExitEvent
|
|
266
|
-
});
|
|
267
|
-
if ((_g = params.abortSignal) == null ? void 0 : _g.aborted) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
yield earlyExitEvent;
|
|
271
|
-
} else {
|
|
272
|
-
let abortSealed = false;
|
|
273
|
-
const sealAbortedInvocation = /* @__PURE__ */ __name(() => {
|
|
274
|
-
abortSealed = true;
|
|
275
|
-
return this.synthesizeAbortEvents(invocationContext);
|
|
276
|
-
}, "sealAbortedInvocation");
|
|
277
|
-
try {
|
|
278
|
-
for await (const event of this.runRoot(invocationContext)) {
|
|
279
|
-
if ((_h = params.abortSignal) == null ? void 0 : _h.aborted) {
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
const outputEvent = await this.processAndAppendEvent(
|
|
283
|
-
invocationContext,
|
|
284
|
-
event
|
|
285
|
-
);
|
|
286
|
-
if ((_i = params.abortSignal) == null ? void 0 : _i.aborted) {
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
yield outputEvent;
|
|
290
|
-
}
|
|
291
|
-
if ((_j = params.abortSignal) == null ? void 0 : _j.aborted) {
|
|
292
|
-
for (const abortEvent of await sealAbortedInvocation()) {
|
|
293
|
-
yield abortEvent;
|
|
294
|
-
}
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
} finally {
|
|
298
|
-
if (((_k = params.abortSignal) == null ? void 0 : _k.aborted) && !abortSealed) {
|
|
299
|
-
try {
|
|
300
|
-
await sealAbortedInvocation();
|
|
301
|
-
} catch (e) {
|
|
302
|
-
logger.error(
|
|
303
|
-
`Failed to seal aborted invocation ${invocationContext.invocationId}.`,
|
|
304
|
-
e
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
310
|
-
if ((_l = params.abortSignal) == null ? void 0 : _l.aborted) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
255
|
+
yield* runnerCtx.runWithPluginLifecycle(
|
|
256
|
+
invocationContext,
|
|
257
|
+
() => runnerCtx.runAsyncWithPlugins(invocationContext)
|
|
258
|
+
);
|
|
314
259
|
}
|
|
315
260
|
}
|
|
316
261
|
);
|
|
317
262
|
} finally {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
263
|
+
await this.close();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Closes the runner and cleans up all toolsets reachable from the root agent
|
|
268
|
+
* or workflow.
|
|
269
|
+
*/
|
|
270
|
+
async close() {
|
|
271
|
+
await cleanupToolsets(collectToolsets(this.agent));
|
|
272
|
+
}
|
|
273
|
+
async *runAsyncWithPlugins(invocationContext) {
|
|
274
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
275
|
+
const beforeRunCallbackResponse = await this.pluginManager.runBeforeRunCallback({
|
|
276
|
+
invocationContext
|
|
277
|
+
});
|
|
278
|
+
if ((_a2 = invocationContext.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (beforeRunCallbackResponse) {
|
|
282
|
+
const earlyExitEvent = createEvent({
|
|
283
|
+
invocationId: invocationContext.invocationId,
|
|
284
|
+
author: "model",
|
|
285
|
+
content: beforeRunCallbackResponse
|
|
286
|
+
});
|
|
287
|
+
await this.sessionService.appendEvent({
|
|
288
|
+
session: invocationContext.session,
|
|
289
|
+
event: earlyExitEvent
|
|
290
|
+
});
|
|
291
|
+
if ((_b = invocationContext.abortSignal) == null ? void 0 : _b.aborted) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
yield earlyExitEvent;
|
|
295
|
+
} else {
|
|
296
|
+
let abortSealed = false;
|
|
297
|
+
const sealAbortedInvocation = /* @__PURE__ */ __name(() => {
|
|
298
|
+
abortSealed = true;
|
|
299
|
+
return this.synthesizeAbortEvents(invocationContext);
|
|
300
|
+
}, "sealAbortedInvocation");
|
|
301
|
+
try {
|
|
302
|
+
for await (const event of this.runRoot(invocationContext)) {
|
|
303
|
+
if ((_c = invocationContext.abortSignal) == null ? void 0 : _c.aborted) {
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
const outputEvent = await this.processAndAppendEvent(
|
|
307
|
+
invocationContext,
|
|
308
|
+
event
|
|
309
|
+
);
|
|
310
|
+
if ((_d = invocationContext.abortSignal) == null ? void 0 : _d.aborted) {
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
yield outputEvent;
|
|
314
|
+
}
|
|
315
|
+
if ((_e = invocationContext.abortSignal) == null ? void 0 : _e.aborted) {
|
|
316
|
+
for (const abortEvent of await sealAbortedInvocation()) {
|
|
317
|
+
yield abortEvent;
|
|
318
|
+
}
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
} finally {
|
|
322
|
+
if (((_f = invocationContext.abortSignal) == null ? void 0 : _f.aborted) && !abortSealed) {
|
|
323
|
+
try {
|
|
324
|
+
await sealAbortedInvocation();
|
|
325
|
+
} catch (e) {
|
|
326
|
+
logger.error(
|
|
327
|
+
`Failed to seal aborted invocation ${invocationContext.invocationId}.`,
|
|
328
|
+
e
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/** Finalizes a started run, including when its consumer closes the iterator. */
|
|
336
|
+
async *runWithPluginLifecycle(invocationContext, execute) {
|
|
337
|
+
let failed = false;
|
|
338
|
+
let completed = false;
|
|
339
|
+
try {
|
|
340
|
+
yield* execute();
|
|
341
|
+
completed = true;
|
|
342
|
+
} catch (error) {
|
|
343
|
+
if (!isInvocationCancellation(error, invocationContext.abortSignal)) {
|
|
344
|
+
failed = true;
|
|
345
|
+
await this.notifyRunError(invocationContext, error);
|
|
346
|
+
}
|
|
347
|
+
throw error;
|
|
348
|
+
} finally {
|
|
349
|
+
if (!failed) {
|
|
350
|
+
await this.finishRun(invocationContext, !completed);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
async finishRun(invocationContext, closingEarly) {
|
|
355
|
+
try {
|
|
356
|
+
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
357
|
+
} catch (error) {
|
|
358
|
+
await this.notifyRunError(invocationContext, error);
|
|
359
|
+
if (!closingEarly) {
|
|
360
|
+
throw error;
|
|
361
|
+
}
|
|
362
|
+
logger.error(
|
|
363
|
+
`afterRunCallback failed while closing invocation ${invocationContext.invocationId}.`,
|
|
364
|
+
error
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
async notifyRunError(invocationContext, error) {
|
|
369
|
+
try {
|
|
370
|
+
await this.pluginManager.runOnRunErrorCallback({
|
|
371
|
+
invocationContext,
|
|
372
|
+
error: toError(error)
|
|
373
|
+
});
|
|
374
|
+
} catch (callbackError) {
|
|
375
|
+
logger.error(
|
|
376
|
+
"Run error notification failed; preserving the original error.",
|
|
377
|
+
callbackError
|
|
378
|
+
);
|
|
321
379
|
}
|
|
322
380
|
}
|
|
323
381
|
/**
|
|
@@ -508,6 +566,7 @@ const _Runner = class _Runner {
|
|
|
508
566
|
throw new Error("runLive is only supported for agents.");
|
|
509
567
|
}
|
|
510
568
|
const agent = this.agent;
|
|
569
|
+
const { sessionId } = params;
|
|
511
570
|
const runConfig = createRunConfig(params.runConfig);
|
|
512
571
|
if (!((_a2 = runConfig.responseModalities) == null ? void 0 : _a2.length)) {
|
|
513
572
|
runConfig.responseModalities = [Modality.AUDIO];
|
|
@@ -518,92 +577,92 @@ const _Runner = class _Runner {
|
|
|
518
577
|
}
|
|
519
578
|
(_d = runConfig.inputAudioTranscription) != null ? _d : runConfig.inputAudioTranscription = {};
|
|
520
579
|
}
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
});
|
|
534
|
-
if ((_a3 = params.abortSignal) == null ? void 0 : _a3.aborted) {
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
const invocationContext = new InvocationContext({
|
|
538
|
-
artifactService: this.artifactService ? isSessionArtifactService(this.artifactService) ? this.artifactService : new ScopedArtifactService(
|
|
539
|
-
this.artifactService,
|
|
540
|
-
this.appName,
|
|
541
|
-
params.userId,
|
|
542
|
-
params.sessionId
|
|
543
|
-
) : void 0,
|
|
544
|
-
sessionService: this.sessionService,
|
|
545
|
-
memoryService: this.memoryService,
|
|
546
|
-
credentialService: this.credentialService,
|
|
547
|
-
invocationId: newInvocationContextId(),
|
|
548
|
-
agent,
|
|
549
|
-
session,
|
|
550
|
-
runConfig,
|
|
551
|
-
a2aMetadata: runConfig.a2aMetadata,
|
|
552
|
-
pluginManager: this.pluginManager,
|
|
553
|
-
liveRequestQueue: params.liveRequestQueue,
|
|
554
|
-
abortSignal: params.abortSignal,
|
|
555
|
-
liveSessionResumptionHandle: params.liveSessionResumptionHandle
|
|
556
|
-
});
|
|
557
|
-
invocationContext.agent = this.determineAgentForResumption(
|
|
558
|
-
session,
|
|
559
|
-
agent
|
|
560
|
-
);
|
|
561
|
-
const beforeRunCallbackResponse = await this.pluginManager.runBeforeRunCallback({
|
|
562
|
-
invocationContext
|
|
563
|
-
});
|
|
564
|
-
if ((_b2 = params.abortSignal) == null ? void 0 : _b2.aborted) {
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
if (beforeRunCallbackResponse) {
|
|
568
|
-
const earlyExitEvent = createEvent({
|
|
569
|
-
invocationId: invocationContext.invocationId,
|
|
570
|
-
author: "model",
|
|
571
|
-
content: beforeRunCallbackResponse
|
|
572
|
-
});
|
|
573
|
-
await this.sessionService.appendEvent({
|
|
574
|
-
session,
|
|
575
|
-
event: earlyExitEvent
|
|
576
|
-
});
|
|
577
|
-
yield earlyExitEvent;
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
for await (const event of requireAgent(invocationContext).runLive(
|
|
581
|
-
invocationContext
|
|
582
|
-
)) {
|
|
583
|
-
if ((_c2 = params.abortSignal) == null ? void 0 : _c2.aborted) {
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
const modifiedEvent = await this.pluginManager.runOnEventCallback({
|
|
587
|
-
invocationContext,
|
|
588
|
-
event
|
|
589
|
-
});
|
|
590
|
-
if ((_d2 = params.abortSignal) == null ? void 0 : _d2.aborted) {
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
const eventToProcess = modifiedEvent ? withInternalMetadataOf(event, modifiedEvent) : event;
|
|
594
|
-
if (!eventToProcess.partial && !isLiveModelMediaEventWithInlineData(eventToProcess)) {
|
|
595
|
-
await this.sessionService.appendEvent({
|
|
596
|
-
session,
|
|
597
|
-
event: eventToProcess
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
yield eventToProcess;
|
|
601
|
-
}
|
|
602
|
-
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
580
|
+
const runnerCtx = this;
|
|
581
|
+
yield* recordInvocation(
|
|
582
|
+
{ entrypoint: agent, sessionId, runConfig },
|
|
583
|
+
async function* () {
|
|
584
|
+
var _a3;
|
|
585
|
+
const session = await runnerCtx.sessionService.getOrCreateSession({
|
|
586
|
+
appName: runnerCtx.appName,
|
|
587
|
+
userId: params.userId,
|
|
588
|
+
sessionId: params.sessionId
|
|
589
|
+
});
|
|
590
|
+
if ((_a3 = params.abortSignal) == null ? void 0 : _a3.aborted) {
|
|
591
|
+
return;
|
|
603
592
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
593
|
+
const invocationContext = new InvocationContext({
|
|
594
|
+
artifactService: runnerCtx.artifactService ? isSessionArtifactService(runnerCtx.artifactService) ? runnerCtx.artifactService : new ScopedArtifactService(
|
|
595
|
+
runnerCtx.artifactService,
|
|
596
|
+
runnerCtx.appName,
|
|
597
|
+
params.userId,
|
|
598
|
+
params.sessionId
|
|
599
|
+
) : void 0,
|
|
600
|
+
sessionService: runnerCtx.sessionService,
|
|
601
|
+
memoryService: runnerCtx.memoryService,
|
|
602
|
+
credentialService: runnerCtx.credentialService,
|
|
603
|
+
invocationId: newInvocationContextId(),
|
|
604
|
+
agent,
|
|
605
|
+
session,
|
|
606
|
+
runConfig,
|
|
607
|
+
a2aMetadata: runConfig.a2aMetadata,
|
|
608
|
+
pluginManager: runnerCtx.pluginManager,
|
|
609
|
+
liveRequestQueue: params.liveRequestQueue,
|
|
610
|
+
abortSignal: params.abortSignal,
|
|
611
|
+
liveSessionResumptionHandle: params.liveSessionResumptionHandle
|
|
612
|
+
});
|
|
613
|
+
invocationContext.agent = runnerCtx.determineAgentForResumption(
|
|
614
|
+
session,
|
|
615
|
+
agent
|
|
616
|
+
);
|
|
617
|
+
yield* runnerCtx.runWithPluginLifecycle(
|
|
618
|
+
invocationContext,
|
|
619
|
+
() => runnerCtx.runLiveWithPlugins(invocationContext)
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
async *runLiveWithPlugins(invocationContext) {
|
|
625
|
+
var _a2, _b, _c;
|
|
626
|
+
const beforeRunCallbackResponse = await this.pluginManager.runBeforeRunCallback({
|
|
627
|
+
invocationContext
|
|
628
|
+
});
|
|
629
|
+
if ((_a2 = invocationContext.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
if (beforeRunCallbackResponse) {
|
|
633
|
+
const earlyExitEvent = createEvent({
|
|
634
|
+
invocationId: invocationContext.invocationId,
|
|
635
|
+
author: "model",
|
|
636
|
+
content: beforeRunCallbackResponse
|
|
637
|
+
});
|
|
638
|
+
await this.sessionService.appendEvent({
|
|
639
|
+
session: invocationContext.session,
|
|
640
|
+
event: earlyExitEvent
|
|
641
|
+
});
|
|
642
|
+
yield earlyExitEvent;
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
for await (const event of requireAgent(invocationContext).runLive(
|
|
646
|
+
invocationContext
|
|
647
|
+
)) {
|
|
648
|
+
if ((_b = invocationContext.abortSignal) == null ? void 0 : _b.aborted) {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
const modifiedEvent = await this.pluginManager.runOnEventCallback({
|
|
652
|
+
invocationContext,
|
|
653
|
+
event
|
|
654
|
+
});
|
|
655
|
+
if ((_c = invocationContext.abortSignal) == null ? void 0 : _c.aborted) {
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
const eventToProcess = modifiedEvent ? withInternalMetadataOf(event, modifiedEvent) : event;
|
|
659
|
+
if (!eventToProcess.partial && !isLiveModelMediaEventWithInlineData(eventToProcess)) {
|
|
660
|
+
await this.sessionService.appendEvent({
|
|
661
|
+
session: invocationContext.session,
|
|
662
|
+
event: eventToProcess
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
yield eventToProcess;
|
|
607
666
|
}
|
|
608
667
|
}
|
|
609
668
|
};
|
|
@@ -706,28 +765,87 @@ function findEventByLastFunctionResponseId(events) {
|
|
|
706
765
|
return (_a2 = findMatchingFunctionCall(events)) != null ? _a2 : null;
|
|
707
766
|
}
|
|
708
767
|
__name(findEventByLastFunctionResponseId, "findEventByLastFunctionResponseId");
|
|
709
|
-
function
|
|
710
|
-
const toolsets =
|
|
768
|
+
function collectToolsets(root) {
|
|
769
|
+
const toolsets = /* @__PURE__ */ new Set();
|
|
711
770
|
const visited = /* @__PURE__ */ new Set();
|
|
712
771
|
function traverse(curr) {
|
|
713
|
-
if (visited.has(curr))
|
|
772
|
+
if (visited.has(curr)) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
714
775
|
visited.add(curr);
|
|
715
776
|
if (isLlmAgent(curr)) {
|
|
716
777
|
for (const tool of curr.tools) {
|
|
717
778
|
if (isBaseToolset(tool)) {
|
|
718
|
-
toolsets.
|
|
779
|
+
toolsets.add(tool);
|
|
719
780
|
}
|
|
720
781
|
}
|
|
721
782
|
}
|
|
722
|
-
|
|
723
|
-
|
|
783
|
+
if (isBaseAgent(curr)) {
|
|
784
|
+
for (const sub of curr.subAgents) {
|
|
785
|
+
traverse(sub);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (isWorkflow(curr) && curr.graph) {
|
|
789
|
+
for (const node of curr.graph.nodes) {
|
|
790
|
+
traverse(node);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
if (isParallelWorker(curr)) {
|
|
794
|
+
traverse(curr.inner);
|
|
724
795
|
}
|
|
725
796
|
}
|
|
726
797
|
__name(traverse, "traverse");
|
|
727
|
-
traverse(
|
|
798
|
+
traverse(root);
|
|
728
799
|
return toolsets;
|
|
729
800
|
}
|
|
730
|
-
__name(
|
|
801
|
+
__name(collectToolsets, "collectToolsets");
|
|
802
|
+
function formatToolsetCloseError(err) {
|
|
803
|
+
const formatted = formatError(err);
|
|
804
|
+
if (formatted !== "[object Object]") {
|
|
805
|
+
return formatted;
|
|
806
|
+
}
|
|
807
|
+
try {
|
|
808
|
+
return JSON.stringify(err);
|
|
809
|
+
} catch {
|
|
810
|
+
return formatted;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
__name(formatToolsetCloseError, "formatToolsetCloseError");
|
|
814
|
+
async function cleanupToolsets(toolsets) {
|
|
815
|
+
await Promise.allSettled(
|
|
816
|
+
[...toolsets].map(async (toolset) => {
|
|
817
|
+
var _a2;
|
|
818
|
+
const toolsetName = ((_a2 = toolset.constructor) == null ? void 0 : _a2.name) || "BaseToolset";
|
|
819
|
+
let timeoutId;
|
|
820
|
+
try {
|
|
821
|
+
logger.debug(`Closing toolset: ${toolsetName}`);
|
|
822
|
+
const result = await Promise.race([
|
|
823
|
+
toolset.close().then(() => void 0),
|
|
824
|
+
new Promise((resolve) => {
|
|
825
|
+
timeoutId = setTimeout(
|
|
826
|
+
() => resolve(TOOLSET_CLEANUP_TIMEOUT_SYMBOL),
|
|
827
|
+
TOOLSET_CLEANUP_TIMEOUT_MS
|
|
828
|
+
);
|
|
829
|
+
})
|
|
830
|
+
]);
|
|
831
|
+
if (result === TOOLSET_CLEANUP_TIMEOUT_SYMBOL) {
|
|
832
|
+
logger.warn(`Toolset ${toolsetName} cleanup timed out`);
|
|
833
|
+
} else {
|
|
834
|
+
logger.debug(`Successfully closed toolset: ${toolsetName}`);
|
|
835
|
+
}
|
|
836
|
+
} catch (e) {
|
|
837
|
+
logger.error(
|
|
838
|
+
`Error closing toolset ${toolsetName}: ${formatToolsetCloseError(e)}`
|
|
839
|
+
);
|
|
840
|
+
} finally {
|
|
841
|
+
if (timeoutId !== void 0) {
|
|
842
|
+
clearTimeout(timeoutId);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
})
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
__name(cleanupToolsets, "cleanupToolsets");
|
|
731
849
|
function rejectReservedFunctionCalls(newMessage) {
|
|
732
850
|
const reserved = reservedFunctionCallName(newMessage);
|
|
733
851
|
if (reserved) {
|
|
@@ -41,8 +41,8 @@ const _BaseSessionService = class _BaseSessionService {
|
|
|
41
41
|
if (event.partial) {
|
|
42
42
|
return event;
|
|
43
43
|
}
|
|
44
|
-
event = trimTempDeltaState(event);
|
|
45
44
|
this.updateSessionState({ session, event });
|
|
45
|
+
event = trimTempDeltaState(event);
|
|
46
46
|
upsertSessionEvent(session, event);
|
|
47
47
|
return event;
|
|
48
48
|
}
|
|
@@ -56,9 +56,6 @@ const _BaseSessionService = class _BaseSessionService {
|
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
59
|
-
if (key.startsWith(State.TEMP_PREFIX)) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
59
|
if (!shouldApplyDeltaWrite(session.state, event.actions.stateDelta, key)) {
|
|
63
60
|
continue;
|
|
64
61
|
}
|