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