@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
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
"use strict";
|
|
8
|
+
var __create = Object.create;
|
|
8
9
|
var __defProp = Object.defineProperty;
|
|
9
10
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
11
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
13
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
14
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
15
|
var __export = (target, all) => {
|
|
@@ -22,6 +24,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
22
24
|
}
|
|
23
25
|
return to;
|
|
24
26
|
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
28
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
32
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
33
|
+
mod
|
|
34
|
+
));
|
|
25
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
36
|
var agent_engine_client_exports = {};
|
|
27
37
|
__export(agent_engine_client_exports, {
|
|
@@ -29,7 +39,8 @@ __export(agent_engine_client_exports, {
|
|
|
29
39
|
AgentExecutionError: () => AgentExecutionError
|
|
30
40
|
});
|
|
31
41
|
module.exports = __toCommonJS(agent_engine_client_exports);
|
|
32
|
-
var
|
|
42
|
+
var import_error_utils = require("../utils/error_utils.js");
|
|
43
|
+
var import_optional_peer = require("../utils/optional_peer.js");
|
|
33
44
|
/**
|
|
34
45
|
* @license
|
|
35
46
|
* Copyright 2026 Google LLC
|
|
@@ -44,21 +55,46 @@ const _AgentExecutionError = class _AgentExecutionError extends Error {
|
|
|
44
55
|
};
|
|
45
56
|
__name(_AgentExecutionError, "AgentExecutionError");
|
|
46
57
|
let AgentExecutionError = _AgentExecutionError;
|
|
47
|
-
|
|
58
|
+
const WIRE_KEY_ALIASES = [
|
|
59
|
+
["userId", "user_id"],
|
|
60
|
+
["sessionId", "session_id"],
|
|
61
|
+
["expireTime", "expire_time"],
|
|
62
|
+
["runConfig", "run_config"],
|
|
63
|
+
["stateDelta", "state_delta"]
|
|
64
|
+
];
|
|
65
|
+
function toWireInput(config) {
|
|
48
66
|
var _a;
|
|
49
|
-
const
|
|
67
|
+
const input = { ...config };
|
|
68
|
+
delete input["classMethod"];
|
|
69
|
+
for (const [camel, snake] of WIRE_KEY_ALIASES) {
|
|
70
|
+
input[snake] = (_a = input[snake]) != null ? _a : input[camel];
|
|
71
|
+
delete input[camel];
|
|
72
|
+
}
|
|
73
|
+
for (const key of Object.keys(input)) {
|
|
74
|
+
if (input[key] === void 0) {
|
|
75
|
+
delete input[key];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return input;
|
|
79
|
+
}
|
|
80
|
+
__name(toWireInput, "toWireInput");
|
|
81
|
+
function buildInputStruct(sdkHelpers, input) {
|
|
82
|
+
var _a;
|
|
83
|
+
const value = sdkHelpers.toValue(input);
|
|
50
84
|
return (_a = value == null ? void 0 : value.structValue) != null ? _a : void 0;
|
|
51
85
|
}
|
|
52
86
|
__name(buildInputStruct, "buildInputStruct");
|
|
53
|
-
function parseOutput(output) {
|
|
54
|
-
return
|
|
87
|
+
function parseOutput(sdkHelpers, output) {
|
|
88
|
+
return sdkHelpers.fromValue(output);
|
|
55
89
|
}
|
|
56
90
|
__name(parseOutput, "parseOutput");
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
91
|
+
const IGNORED_SSE_FIELDS = /* @__PURE__ */ new Set([
|
|
92
|
+
"event",
|
|
93
|
+
"id",
|
|
94
|
+
"retry"
|
|
95
|
+
]);
|
|
96
|
+
const DONE_SENTINEL = "[DONE]";
|
|
97
|
+
function parseFragment(payload) {
|
|
62
98
|
try {
|
|
63
99
|
return JSON.parse(payload);
|
|
64
100
|
} catch (e) {
|
|
@@ -69,7 +105,82 @@ function parseFragment(line) {
|
|
|
69
105
|
}
|
|
70
106
|
}
|
|
71
107
|
__name(parseFragment, "parseFragment");
|
|
108
|
+
function* dispatchEvent(dataLines) {
|
|
109
|
+
if (dataLines.length === 0) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const lines = dataLines.splice(0);
|
|
113
|
+
const payload = lines.join("\n").trim();
|
|
114
|
+
if (payload === "" || payload === DONE_SENTINEL) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
let parsed;
|
|
118
|
+
try {
|
|
119
|
+
parsed = parseFragment(payload);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
if (lines.length === 1) {
|
|
122
|
+
throw e;
|
|
123
|
+
}
|
|
124
|
+
const values = [];
|
|
125
|
+
try {
|
|
126
|
+
for (const line of lines) {
|
|
127
|
+
const trimmed = line.trim();
|
|
128
|
+
if (trimmed !== "" && trimmed !== DONE_SENTINEL) {
|
|
129
|
+
values.push(JSON.parse(trimmed));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
133
|
+
throw e;
|
|
134
|
+
}
|
|
135
|
+
yield* values;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
yield parsed;
|
|
139
|
+
}
|
|
140
|
+
__name(dispatchEvent, "dispatchEvent");
|
|
141
|
+
function* processLine(rawLine, dataLines) {
|
|
142
|
+
const line = (rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine).replace(/^[ \t]+/, "");
|
|
143
|
+
if (line === "") {
|
|
144
|
+
yield* dispatchEvent(dataLines);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (line.startsWith(":")) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const colon = line.indexOf(":");
|
|
151
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
152
|
+
if (IGNORED_SSE_FIELDS.has(field)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (field === "data") {
|
|
156
|
+
if (dataLines.length === 1) {
|
|
157
|
+
const buffered = dataLines[0].trim();
|
|
158
|
+
if (buffered === DONE_SENTINEL) {
|
|
159
|
+
yield* dispatchEvent(dataLines);
|
|
160
|
+
} else if (buffered !== "") {
|
|
161
|
+
try {
|
|
162
|
+
JSON.parse(buffered);
|
|
163
|
+
yield* dispatchEvent(dataLines);
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const value = colon === -1 ? "" : line.slice(colon + 1);
|
|
169
|
+
dataLines.push(value.startsWith(" ") ? value.slice(1) : value);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
yield* dispatchEvent(dataLines);
|
|
173
|
+
const trimmed = line.trim();
|
|
174
|
+
if (trimmed === "" || trimmed === DONE_SENTINEL) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
yield parseFragment(trimmed);
|
|
178
|
+
}
|
|
179
|
+
__name(processLine, "processLine");
|
|
72
180
|
async function* parseStream(stream) {
|
|
181
|
+
var _a;
|
|
182
|
+
const decoder = new TextDecoder("utf-8");
|
|
183
|
+
const dataLines = [];
|
|
73
184
|
let buffer = "";
|
|
74
185
|
for await (const chunk of stream) {
|
|
75
186
|
const chunkData = chunk == null ? void 0 : chunk.data;
|
|
@@ -79,89 +190,205 @@ async function* parseStream(stream) {
|
|
|
79
190
|
}
|
|
80
191
|
continue;
|
|
81
192
|
}
|
|
82
|
-
|
|
83
|
-
buffer += dataStr;
|
|
193
|
+
buffer += chunkData instanceof Uint8Array ? decoder.decode(chunkData, { stream: true }) : String(chunkData);
|
|
84
194
|
const lines = buffer.split("\n");
|
|
85
|
-
buffer = lines.pop()
|
|
195
|
+
buffer = (_a = lines.pop()) != null ? _a : "";
|
|
86
196
|
for (const line of lines) {
|
|
87
|
-
|
|
88
|
-
if (fragment !== void 0) {
|
|
89
|
-
yield fragment;
|
|
90
|
-
}
|
|
197
|
+
yield* processLine(line, dataLines);
|
|
91
198
|
}
|
|
92
199
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
yield
|
|
200
|
+
buffer += decoder.decode();
|
|
201
|
+
for (const line of buffer.split("\n")) {
|
|
202
|
+
yield* processLine(line, dataLines);
|
|
96
203
|
}
|
|
204
|
+
yield* dispatchEvent(dataLines);
|
|
97
205
|
}
|
|
98
206
|
__name(parseStream, "parseStream");
|
|
99
207
|
const _AgentEngineClient = class _AgentEngineClient {
|
|
100
208
|
constructor(config) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
this.reasoningEnginePath = this.client.reasoningEnginePath(
|
|
105
|
-
config.project,
|
|
106
|
-
config.location,
|
|
107
|
-
config.reasoningEngineId
|
|
108
|
-
);
|
|
209
|
+
var _a;
|
|
210
|
+
this.apiEndpoint = (_a = config.apiEndpoint) != null ? _a : config.location === "global" ? "aiplatform.googleapis.com" : `${config.location}-aiplatform.googleapis.com`;
|
|
211
|
+
this.reasoningEnginePath = `projects/${config.project}/locations/${config.location}/reasoningEngines/${config.reasoningEngineId}`;
|
|
109
212
|
}
|
|
110
213
|
/**
|
|
111
214
|
* Creates a remote session.
|
|
112
215
|
*
|
|
113
|
-
*
|
|
216
|
+
* Calls the `async_create_session` class method unless `config.classMethod`
|
|
217
|
+
* names another one.
|
|
218
|
+
*
|
|
219
|
+
* @returns The session payload returned by the Agent Engine. When
|
|
114
220
|
* `config.sessionId` is omitted the engine generates one, and this is the
|
|
115
221
|
* only place the caller can read it back from.
|
|
116
222
|
*/
|
|
117
223
|
async createSession(config) {
|
|
224
|
+
return this.callQueryMethod({
|
|
225
|
+
config,
|
|
226
|
+
defaultClassMethod: "async_create_session",
|
|
227
|
+
errorPrefix: "Failed to create session"
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Reads a remote session.
|
|
232
|
+
*
|
|
233
|
+
* Calls the `async_get_session` class method unless `config.classMethod`
|
|
234
|
+
* names another one.
|
|
235
|
+
*
|
|
236
|
+
* @throws {@link AgentExecutionError} if the user id or the session id is
|
|
237
|
+
* missing, or if the call fails.
|
|
238
|
+
*/
|
|
239
|
+
async getSession(config) {
|
|
240
|
+
var _a, _b;
|
|
241
|
+
const userId = (_a = config.user_id) != null ? _a : config.userId;
|
|
242
|
+
const sessionId = (_b = config.session_id) != null ? _b : config.sessionId;
|
|
243
|
+
if (!userId || !sessionId) {
|
|
244
|
+
throw new AgentExecutionError(
|
|
245
|
+
"Failed to get session: user_id and session_id are required"
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
return this.callQueryMethod({
|
|
249
|
+
config,
|
|
250
|
+
defaultClassMethod: "async_get_session",
|
|
251
|
+
errorPrefix: "Failed to get session"
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Lists the remote sessions of a user.
|
|
256
|
+
*
|
|
257
|
+
* Calls the `async_list_sessions` class method unless `config.classMethod`
|
|
258
|
+
* names another one.
|
|
259
|
+
*/
|
|
260
|
+
async listSessions(config) {
|
|
261
|
+
return this.callQueryMethod({
|
|
262
|
+
config,
|
|
263
|
+
defaultClassMethod: "async_list_sessions",
|
|
264
|
+
errorPrefix: "Failed to list sessions"
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Deletes a remote session.
|
|
269
|
+
*
|
|
270
|
+
* Calls the `async_delete_session` class method unless `config.classMethod`
|
|
271
|
+
* names another one.
|
|
272
|
+
*/
|
|
273
|
+
async deleteSession(config) {
|
|
274
|
+
await this.callQueryMethod({
|
|
275
|
+
config,
|
|
276
|
+
defaultClassMethod: "async_delete_session",
|
|
277
|
+
errorPrefix: "Failed to delete session"
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Sends a query and waits for the whole response.
|
|
282
|
+
*
|
|
283
|
+
* Calls the `query` class method unless `config.classMethod` names another
|
|
284
|
+
* one.
|
|
285
|
+
*/
|
|
286
|
+
async query(config) {
|
|
287
|
+
return this.callQueryMethod({
|
|
288
|
+
config,
|
|
289
|
+
defaultClassMethod: "query",
|
|
290
|
+
errorPrefix: "Failed to execute query"
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Sends a query and yields each streamed response value.
|
|
295
|
+
*
|
|
296
|
+
* Calls the `async_stream_query` class method unless `config.classMethod`
|
|
297
|
+
* names another one. The stream can be server-sent events or
|
|
298
|
+
* newline-delimited JSON.
|
|
299
|
+
*/
|
|
300
|
+
async *streamQuery(config) {
|
|
301
|
+
var _a;
|
|
118
302
|
try {
|
|
119
|
-
const
|
|
303
|
+
const { helpers: sdkHelpers, client } = await this.getClient();
|
|
304
|
+
const stream = client.streamQueryReasoningEngine({
|
|
120
305
|
name: this.reasoningEnginePath,
|
|
121
|
-
classMethod: "
|
|
122
|
-
input: buildInputStruct(config)
|
|
306
|
+
classMethod: (_a = config.classMethod) != null ? _a : "async_stream_query",
|
|
307
|
+
input: buildInputStruct(sdkHelpers, toWireInput(config))
|
|
123
308
|
});
|
|
124
|
-
|
|
309
|
+
yield* parseStream(stream);
|
|
125
310
|
} catch (err) {
|
|
126
|
-
|
|
311
|
+
if (err instanceof AgentExecutionError) {
|
|
312
|
+
throw err;
|
|
313
|
+
}
|
|
127
314
|
throw new AgentExecutionError(
|
|
128
|
-
`Failed to
|
|
315
|
+
`Failed to execute stream query: ${(0, import_error_utils.getErrorMessage)(err)}`,
|
|
129
316
|
err
|
|
130
317
|
);
|
|
131
318
|
}
|
|
132
319
|
}
|
|
133
|
-
|
|
320
|
+
/**
|
|
321
|
+
* Closes the underlying gRPC client.
|
|
322
|
+
*
|
|
323
|
+
* Does nothing if no call has created the client yet, and is safe to call
|
|
324
|
+
* more than once. A later call creates a new client.
|
|
325
|
+
*/
|
|
326
|
+
async close() {
|
|
327
|
+
const pending = this.clientPromise;
|
|
328
|
+
if (!pending) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
this.clientPromise = void 0;
|
|
332
|
+
let loaded;
|
|
134
333
|
try {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
input: buildInputStruct(config)
|
|
139
|
-
});
|
|
140
|
-
return response.output ? parseOutput(response.output) : void 0;
|
|
141
|
-
} catch (err) {
|
|
142
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
143
|
-
throw new AgentExecutionError(`Failed to execute query: ${message}`, err);
|
|
334
|
+
loaded = await pending;
|
|
335
|
+
} catch {
|
|
336
|
+
return;
|
|
144
337
|
}
|
|
338
|
+
await loaded.client.close();
|
|
145
339
|
}
|
|
146
|
-
async
|
|
340
|
+
async callQueryMethod({
|
|
341
|
+
config,
|
|
342
|
+
defaultClassMethod,
|
|
343
|
+
errorPrefix
|
|
344
|
+
}) {
|
|
345
|
+
var _a;
|
|
147
346
|
try {
|
|
148
|
-
const
|
|
347
|
+
const { helpers: sdkHelpers, client } = await this.getClient();
|
|
348
|
+
const [response] = await client.queryReasoningEngine({
|
|
149
349
|
name: this.reasoningEnginePath,
|
|
150
|
-
classMethod:
|
|
151
|
-
input: buildInputStruct(config)
|
|
350
|
+
classMethod: (_a = config.classMethod) != null ? _a : defaultClassMethod,
|
|
351
|
+
input: buildInputStruct(sdkHelpers, toWireInput(config))
|
|
152
352
|
});
|
|
153
|
-
|
|
353
|
+
return response.output ? parseOutput(sdkHelpers, response.output) : void 0;
|
|
154
354
|
} catch (err) {
|
|
155
|
-
if (err instanceof AgentExecutionError) {
|
|
156
|
-
throw err;
|
|
157
|
-
}
|
|
158
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
159
355
|
throw new AgentExecutionError(
|
|
160
|
-
|
|
356
|
+
`${errorPrefix}: ${(0, import_error_utils.getErrorMessage)(err)}`,
|
|
161
357
|
err
|
|
162
358
|
);
|
|
163
359
|
}
|
|
164
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* Resolves the SDK helpers and the gRPC client, loading the optional peer on
|
|
363
|
+
* first use.
|
|
364
|
+
*
|
|
365
|
+
* A created client is kept. A failure is not kept, so the next call tries
|
|
366
|
+
* again, for example once the peer is installed.
|
|
367
|
+
*/
|
|
368
|
+
getClient() {
|
|
369
|
+
if (!this.clientPromise) {
|
|
370
|
+
const promise = this.createClient();
|
|
371
|
+
this.clientPromise = promise;
|
|
372
|
+
promise.catch(() => {
|
|
373
|
+
if (this.clientPromise === promise) {
|
|
374
|
+
this.clientPromise = void 0;
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return this.clientPromise;
|
|
379
|
+
}
|
|
380
|
+
async createClient() {
|
|
381
|
+
const aiplatform = await (0, import_optional_peer.loadOptionalPeer)(
|
|
382
|
+
{ packageName: "@google-cloud/aiplatform", feature: "AgentEngineClient" },
|
|
383
|
+
() => Promise.resolve().then(() => __toESM(require("@google-cloud/aiplatform"), 1))
|
|
384
|
+
);
|
|
385
|
+
return {
|
|
386
|
+
helpers: aiplatform.helpers,
|
|
387
|
+
client: new aiplatform.v1.ReasoningEngineExecutionServiceClient({
|
|
388
|
+
apiEndpoint: this.apiEndpoint
|
|
389
|
+
})
|
|
390
|
+
};
|
|
391
|
+
}
|
|
165
392
|
};
|
|
166
393
|
__name(_AgentEngineClient, "AgentEngineClient");
|
|
167
394
|
let AgentEngineClient = _AgentEngineClient;
|
|
@@ -30,9 +30,10 @@ __export(base_agent_exports, {
|
|
|
30
30
|
isBaseAgent: () => isBaseAgent
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(base_agent_exports);
|
|
33
|
-
var import_api = require("@opentelemetry/api");
|
|
34
33
|
var import_event = require("../events/event.js");
|
|
35
|
-
var
|
|
34
|
+
var import_instrumentation = require("../telemetry/api/instrumentation.js");
|
|
35
|
+
var import_error_utils = require("../utils/error_utils.js");
|
|
36
|
+
var import_logger = require("../utils/logger.js");
|
|
36
37
|
var import_base_node = require("../workflow/base_node.js");
|
|
37
38
|
var import_context = require("./context.js");
|
|
38
39
|
var import_invocation_context = require("./invocation_context.js");
|
|
@@ -122,38 +123,38 @@ const _BaseAgent = class _BaseAgent extends (_b = import_base_node.BaseNode, _a
|
|
|
122
123
|
* @returns An AsyncGenerator that yields the events generated by the agent.
|
|
123
124
|
*/
|
|
124
125
|
async *runAsync(parentContext) {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const context2 = this.createInvocationContext(parentContext);
|
|
134
|
-
const beforeAgentCallbackEvent = await this.handleBeforeAgentCallback(context2);
|
|
126
|
+
const agentCtx = this;
|
|
127
|
+
yield* (0, import_instrumentation.recordAgentInvocation)(
|
|
128
|
+
{ agent: this, invocationContext: parentContext },
|
|
129
|
+
async function* () {
|
|
130
|
+
var _a2, _b2;
|
|
131
|
+
const context = agentCtx.createInvocationContext(parentContext);
|
|
132
|
+
try {
|
|
133
|
+
const beforeAgentCallbackEvent = await agentCtx.handleBeforeAgentCallback(context);
|
|
135
134
|
if (beforeAgentCallbackEvent) {
|
|
136
135
|
yield beforeAgentCallbackEvent;
|
|
137
136
|
}
|
|
138
|
-
if (
|
|
137
|
+
if (context.endInvocation || ((_a2 = parentContext.abortSignal) == null ? void 0 : _a2.aborted)) {
|
|
139
138
|
return;
|
|
140
139
|
}
|
|
141
|
-
|
|
142
|
-
for await (const event of this.runAsyncImpl(context2)) {
|
|
140
|
+
for await (const event of agentCtx.runAsyncImpl(context)) {
|
|
143
141
|
yield event;
|
|
144
142
|
}
|
|
145
|
-
if (
|
|
143
|
+
if (context.endInvocation || ((_b2 = parentContext.abortSignal) == null ? void 0 : _b2.aborted)) {
|
|
146
144
|
return;
|
|
147
145
|
}
|
|
148
|
-
const afterAgentCallbackEvent = await
|
|
146
|
+
const afterAgentCallbackEvent = await agentCtx.handleAfterAgentCallback(context);
|
|
149
147
|
if (afterAgentCallbackEvent) {
|
|
150
148
|
yield afterAgentCallbackEvent;
|
|
151
149
|
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (!(0, import_error_utils.isInvocationCancellation)(error, context.abortSignal)) {
|
|
152
|
+
await agentCtx.handleAgentErrorCallback(context, error);
|
|
153
|
+
}
|
|
154
|
+
throw error;
|
|
152
155
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
span.end();
|
|
156
|
-
}
|
|
156
|
+
}
|
|
157
|
+
);
|
|
157
158
|
}
|
|
158
159
|
/**
|
|
159
160
|
* Runs this agent as a workflow node.
|
|
@@ -188,36 +189,52 @@ const _BaseAgent = class _BaseAgent extends (_b = import_base_node.BaseNode, _a
|
|
|
188
189
|
* @returns An AsyncGenerator that yields the events generated by the agent.
|
|
189
190
|
*/
|
|
190
191
|
async *runLive(parentContext) {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const context2 = this.createInvocationContext(parentContext);
|
|
200
|
-
const beforeAgentCallbackEvent = await this.handleBeforeAgentCallback(context2);
|
|
192
|
+
const agentCtx = this;
|
|
193
|
+
yield* (0, import_instrumentation.recordAgentInvocation)(
|
|
194
|
+
{ agent: this, invocationContext: parentContext },
|
|
195
|
+
async function* () {
|
|
196
|
+
var _a2, _b2;
|
|
197
|
+
const context = agentCtx.createInvocationContext(parentContext);
|
|
198
|
+
try {
|
|
199
|
+
const beforeAgentCallbackEvent = await agentCtx.handleBeforeAgentCallback(context);
|
|
201
200
|
if (beforeAgentCallbackEvent) {
|
|
202
201
|
yield beforeAgentCallbackEvent;
|
|
203
202
|
}
|
|
204
|
-
if (
|
|
203
|
+
if (context.endInvocation || ((_a2 = parentContext.abortSignal) == null ? void 0 : _a2.aborted)) {
|
|
205
204
|
return;
|
|
206
205
|
}
|
|
207
|
-
for await (const event of
|
|
206
|
+
for await (const event of agentCtx.runLiveImpl(context)) {
|
|
208
207
|
yield event;
|
|
209
208
|
}
|
|
210
|
-
if (
|
|
209
|
+
if (context.endInvocation || ((_b2 = parentContext.abortSignal) == null ? void 0 : _b2.aborted)) {
|
|
211
210
|
return;
|
|
212
211
|
}
|
|
213
|
-
const afterAgentCallbackEvent = await
|
|
212
|
+
const afterAgentCallbackEvent = await agentCtx.handleAfterAgentCallback(context);
|
|
214
213
|
if (afterAgentCallbackEvent) {
|
|
215
214
|
yield afterAgentCallbackEvent;
|
|
216
215
|
}
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (!(0, import_error_utils.isInvocationCancellation)(error, context.abortSignal)) {
|
|
218
|
+
await agentCtx.handleAgentErrorCallback(context, error);
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
217
221
|
}
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
/** Reports execution failures without replacing the original thrown value. */
|
|
226
|
+
async handleAgentErrorCallback(invocationContext, error) {
|
|
227
|
+
try {
|
|
228
|
+
await invocationContext.pluginManager.runOnAgentErrorCallback({
|
|
229
|
+
agent: this,
|
|
230
|
+
callbackContext: new import_context.Context({ invocationContext }),
|
|
231
|
+
error: (0, import_error_utils.toError)(error)
|
|
232
|
+
});
|
|
233
|
+
} catch (callbackError) {
|
|
234
|
+
import_logger.logger.error(
|
|
235
|
+
"Agent error notification failed; preserving the original error.",
|
|
236
|
+
callbackError
|
|
218
237
|
);
|
|
219
|
-
} finally {
|
|
220
|
-
span.end();
|
|
221
238
|
}
|
|
222
239
|
}
|
|
223
240
|
/**
|
|
@@ -283,27 +300,40 @@ const _BaseAgent = class _BaseAgent extends (_b = import_base_node.BaseNode, _a
|
|
|
283
300
|
* generated.
|
|
284
301
|
*/
|
|
285
302
|
async handleBeforeAgentCallback(invocationContext) {
|
|
286
|
-
var _a2;
|
|
287
|
-
|
|
303
|
+
var _a2, _b2, _c;
|
|
304
|
+
const hasPlugins = Boolean((_a2 = invocationContext.pluginManager) == null ? void 0 : _a2.hasPlugins);
|
|
305
|
+
if (!hasPlugins && this.canonicalBeforeAgentCallbacks.length === 0) {
|
|
288
306
|
return void 0;
|
|
289
307
|
}
|
|
290
308
|
const callbackContext = new import_context.Context({ invocationContext });
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
309
|
+
let content = hasPlugins ? await invocationContext.pluginManager.runBeforeAgentCallback({
|
|
310
|
+
agent: this,
|
|
311
|
+
callbackContext
|
|
312
|
+
}) : void 0;
|
|
313
|
+
if ((_b2 = invocationContext.abortSignal) == null ? void 0 : _b2.aborted) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (!content) {
|
|
317
|
+
for (const callback of this.canonicalBeforeAgentCallbacks) {
|
|
318
|
+
content = await callback(callbackContext);
|
|
319
|
+
if ((_c = invocationContext.abortSignal) == null ? void 0 : _c.aborted) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (content) {
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
305
325
|
}
|
|
306
326
|
}
|
|
327
|
+
if (content) {
|
|
328
|
+
invocationContext.endInvocation = true;
|
|
329
|
+
return (0, import_event.createEvent)({
|
|
330
|
+
invocationId: invocationContext.invocationId,
|
|
331
|
+
author: this.name,
|
|
332
|
+
branch: invocationContext.branch,
|
|
333
|
+
content,
|
|
334
|
+
actions: callbackContext.eventActions
|
|
335
|
+
});
|
|
336
|
+
}
|
|
307
337
|
if (callbackContext.state.hasDelta()) {
|
|
308
338
|
return (0, import_event.createEvent)({
|
|
309
339
|
invocationId: invocationContext.invocationId,
|
|
@@ -322,26 +352,39 @@ const _BaseAgent = class _BaseAgent extends (_b = import_base_node.BaseNode, _a
|
|
|
322
352
|
* generated.
|
|
323
353
|
*/
|
|
324
354
|
async handleAfterAgentCallback(invocationContext) {
|
|
325
|
-
var _a2;
|
|
326
|
-
|
|
355
|
+
var _a2, _b2, _c;
|
|
356
|
+
const hasPlugins = Boolean((_a2 = invocationContext.pluginManager) == null ? void 0 : _a2.hasPlugins);
|
|
357
|
+
if (!hasPlugins && this.canonicalAfterAgentCallbacks.length === 0) {
|
|
327
358
|
return void 0;
|
|
328
359
|
}
|
|
329
360
|
const callbackContext = new import_context.Context({ invocationContext });
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
361
|
+
let content = hasPlugins ? await invocationContext.pluginManager.runAfterAgentCallback({
|
|
362
|
+
agent: this,
|
|
363
|
+
callbackContext
|
|
364
|
+
}) : void 0;
|
|
365
|
+
if ((_b2 = invocationContext.abortSignal) == null ? void 0 : _b2.aborted) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (!content) {
|
|
369
|
+
for (const callback of this.canonicalAfterAgentCallbacks) {
|
|
370
|
+
content = await callback(callbackContext);
|
|
371
|
+
if ((_c = invocationContext.abortSignal) == null ? void 0 : _c.aborted) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (content) {
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
343
377
|
}
|
|
344
378
|
}
|
|
379
|
+
if (content) {
|
|
380
|
+
return (0, import_event.createEvent)({
|
|
381
|
+
invocationId: invocationContext.invocationId,
|
|
382
|
+
author: this.name,
|
|
383
|
+
branch: invocationContext.branch,
|
|
384
|
+
content,
|
|
385
|
+
actions: callbackContext.eventActions
|
|
386
|
+
});
|
|
387
|
+
}
|
|
345
388
|
if (callbackContext.state.hasDelta()) {
|
|
346
389
|
return (0, import_event.createEvent)({
|
|
347
390
|
invocationId: invocationContext.invocationId,
|