@ai-setting/roy-agent-core 1.3.9 → 1.3.11
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/config/index.js +1647 -0
- package/dist/index.js +12579 -89691
- package/package.json +19 -56
- package/src/config/config-component.test.ts +0 -627
- package/src/config/config-component.ts +0 -906
- package/src/config/config-parser.test.ts +0 -319
- package/src/config/config-parser.ts +0 -203
- package/src/config/decentralized-config.test.ts +0 -740
- package/src/config/env-key.ts +0 -210
- package/src/config/env-source.test.ts +0 -252
- package/src/config/env-source.ts +0 -301
- package/src/config/file-source.test.ts +0 -357
- package/src/config/file-source.ts +0 -421
- package/src/config/index.ts +0 -24
- package/src/config/protocol-resolver.test.ts +0 -217
- package/src/config/protocol-resolver.ts +0 -228
- package/src/env/agent/agent-component.abort.test.ts +0 -511
- package/src/env/agent/agent-component.record-session.test.ts +0 -349
- package/src/env/agent/agent-component.test.ts +0 -1389
- package/src/env/agent/agent-component.tool-error.test.ts +0 -327
- package/src/env/agent/agent-component.ts +0 -1711
- package/src/env/agent/agent-config-registration.test.ts +0 -226
- package/src/env/agent/agent-config-registration.ts +0 -46
- package/src/env/agent/agent-reminder-plugin.integration.test.ts +0 -243
- package/src/env/agent/index.ts +0 -10
- package/src/env/agent/summary-agent.parse-hint.test.ts +0 -360
- package/src/env/agent/summary-agent.ts +0 -508
- package/src/env/agent/types.ts +0 -536
- package/src/env/commands/commands-component.test.ts +0 -364
- package/src/env/commands/commands-component.ts +0 -604
- package/src/env/commands/commands-config-registration.test.ts +0 -198
- package/src/env/commands/commands-config-registration.ts +0 -38
- package/src/env/commands/index.ts +0 -21
- package/src/env/commands/parser.test.ts +0 -203
- package/src/env/commands/parser.ts +0 -115
- package/src/env/commands/types.ts +0 -184
- package/src/env/commands-prompt-integration.test.ts +0 -243
- package/src/env/component-env.test.ts +0 -119
- package/src/env/component.ts +0 -335
- package/src/env/constants.test.ts +0 -72
- package/src/env/constants.ts +0 -123
- package/src/env/debug/debug-component.test.ts +0 -114
- package/src/env/debug/debug-component.ts +0 -547
- package/src/env/debug/formatters/index.ts +0 -9
- package/src/env/debug/formatters/repl-formatter.test.ts +0 -139
- package/src/env/debug/formatters/repl-formatter.ts +0 -358
- package/src/env/debug/formatters/trace-formatter.test.ts +0 -119
- package/src/env/debug/formatters/trace-formatter.ts +0 -191
- package/src/env/debug/formatters/tree-formatter.test.ts +0 -107
- package/src/env/debug/formatters/tree-formatter.ts +0 -325
- package/src/env/debug/index.ts +0 -38
- package/src/env/debug/parser/regex-parser.test.ts +0 -201
- package/src/env/debug/parser/regex-parser.ts +0 -196
- package/src/env/debug/parser/span-builder.test.ts +0 -241
- package/src/env/debug/parser/span-builder.ts +0 -386
- package/src/env/debug/reader/log-reader.test.ts +0 -170
- package/src/env/debug/reader/log-reader.ts +0 -186
- package/src/env/debug/reader/span-db-reader.test.ts +0 -118
- package/src/env/debug/reader/span-db-reader.ts +0 -201
- package/src/env/debug/types.test.ts +0 -187
- package/src/env/debug/types.ts +0 -171
- package/src/env/environment-init.test.ts +0 -183
- package/src/env/environment-lifecycle.test.ts +0 -516
- package/src/env/environment-service.test.ts +0 -332
- package/src/env/environment.handle-query.test.ts +0 -96
- package/src/env/environment.test.ts +0 -232
- package/src/env/environment.ts +0 -708
- package/src/env/errors.test.ts +0 -165
- package/src/env/errors.ts +0 -157
- package/src/env/event-source/event-source-agent-handler.test.ts +0 -193
- package/src/env/event-source/event-source-agent-handler.ts +0 -111
- package/src/env/event-source/event-source-component.process-cleanup.test.ts +0 -236
- package/src/env/event-source/event-source-component.stop.test.ts +0 -346
- package/src/env/event-source/event-source-component.test.ts +0 -1207
- package/src/env/event-source/event-source-component.ts +0 -1379
- package/src/env/event-source/event-source-config-registration.test.ts +0 -242
- package/src/env/event-source/event-source-config-registration.ts +0 -37
- package/src/env/event-source/event-source-integration.test.ts +0 -320
- package/src/env/event-source/event-source-platform.test.ts +0 -630
- package/src/env/event-source/types.ts +0 -298
- package/src/env/hook/global-hook-manager.ts +0 -162
- package/src/env/hook/hook-manager.test.ts +0 -374
- package/src/env/hook/hook-manager.ts +0 -309
- package/src/env/hook/index.ts +0 -38
- package/src/env/hook/types.ts +0 -138
- package/src/env/index.ts +0 -144
- package/src/env/interface.ts +0 -203
- package/src/env/llm/hooks.test.ts +0 -293
- package/src/env/llm/hooks.ts +0 -316
- package/src/env/llm/index.ts +0 -61
- package/src/env/llm/invoke-threshold-check.test.ts +0 -88
- package/src/env/llm/invoke-timeout.test.ts +0 -54
- package/src/env/llm/invoke.test.ts +0 -71
- package/src/env/llm/invoke.ts +0 -1039
- package/src/env/llm/llm-config.test.ts +0 -523
- package/src/env/llm/llm.test.ts +0 -233
- package/src/env/llm/llm.ts +0 -568
- package/src/env/llm/provider.test.ts +0 -182
- package/src/env/llm/provider.ts +0 -108
- package/src/env/llm/transform.test.ts +0 -251
- package/src/env/llm/transform.ts +0 -286
- package/src/env/llm/types.test.ts +0 -580
- package/src/env/llm/types.ts +0 -424
- package/src/env/log-trace/decorator-otel.test.ts +0 -182
- package/src/env/log-trace/decorator.ts +0 -230
- package/src/env/log-trace/index.ts +0 -79
- package/src/env/log-trace/log-trace-component.test.ts +0 -242
- package/src/env/log-trace/log-trace-component.ts +0 -497
- package/src/env/log-trace/log-trace-config-registration.test.ts +0 -348
- package/src/env/log-trace/log-trace-config-registration.ts +0 -45
- package/src/env/log-trace/logger.test.ts +0 -149
- package/src/env/log-trace/logger.ts +0 -522
- package/src/env/log-trace/opentelemetry/cli-propagation.test.ts +0 -147
- package/src/env/log-trace/opentelemetry/cli-propagation.ts +0 -194
- package/src/env/log-trace/opentelemetry/integration.test.ts +0 -668
- package/src/env/log-trace/opentelemetry/mod.ts +0 -25
- package/src/env/log-trace/opentelemetry/propagation-env.test.ts +0 -181
- package/src/env/log-trace/opentelemetry/propagation-env.ts +0 -136
- package/src/env/log-trace/opentelemetry/propagation.test.ts +0 -259
- package/src/env/log-trace/opentelemetry/propagation.ts +0 -215
- package/src/env/log-trace/opentelemetry/tracer-provider-context.test.ts +0 -166
- package/src/env/log-trace/opentelemetry/tracer-provider.test.ts +0 -379
- package/src/env/log-trace/opentelemetry/tracer-provider.ts +0 -612
- package/src/env/log-trace/span-storage.test.ts +0 -145
- package/src/env/log-trace/span-storage.ts +0 -230
- package/src/env/log-trace/trace-context.test.ts +0 -187
- package/src/env/log-trace/trace-context.ts +0 -162
- package/src/env/log-trace/types.test.ts +0 -63
- package/src/env/log-trace/types.ts +0 -172
- package/src/env/mcp/README.md +0 -244
- package/src/env/mcp/__integration__/mcp-component.integration.test.ts +0 -373
- package/src/env/mcp/config.test.ts +0 -74
- package/src/env/mcp/config.ts +0 -116
- package/src/env/mcp/index.ts +0 -41
- package/src/env/mcp/loader.test.ts +0 -161
- package/src/env/mcp/loader.ts +0 -209
- package/src/env/mcp/mcp-component.test.ts +0 -111
- package/src/env/mcp/mcp-component.ts +0 -358
- package/src/env/mcp/mcp-config-registration.test.ts +0 -304
- package/src/env/mcp/mcp-config-registration.ts +0 -50
- package/src/env/mcp/scanner.test.ts +0 -170
- package/src/env/mcp/scanner.ts +0 -246
- package/src/env/mcp/tool/adapter.test.ts +0 -520
- package/src/env/mcp/tool/adapter.ts +0 -521
- package/src/env/mcp/tool/index.ts +0 -5
- package/src/env/mcp/types.test.ts +0 -171
- package/src/env/mcp/types.ts +0 -79
- package/src/env/memory/README.md +0 -177
- package/src/env/memory/built-in/index.ts +0 -59
- package/src/env/memory/built-in/recall-memory.ts +0 -103
- package/src/env/memory/built-in/record-memory.ts +0 -148
- package/src/env/memory/index.ts +0 -20
- package/src/env/memory/memory-component.test.ts +0 -239
- package/src/env/memory/memory-component.ts +0 -503
- package/src/env/memory/memory-config-registration.test.ts +0 -67
- package/src/env/memory/memory-config-registration.ts +0 -48
- package/src/env/memory/memory-config.ts +0 -45
- package/src/env/memory/memory-file.test.ts +0 -268
- package/src/env/memory/plugin/index.ts +0 -48
- package/src/env/memory/plugin/memory-agent.test.ts +0 -249
- package/src/env/memory/plugin/memory-agent.ts +0 -365
- package/src/env/memory/plugin/memory-manager.ts +0 -198
- package/src/env/memory/plugin/memory-plugin-agent.test.ts +0 -145
- package/src/env/memory/plugin/memory-plugin.ts +0 -210
- package/src/env/memory/plugin/plugin-simplified.test.ts +0 -51
- package/src/env/memory/plugin/recall-memory.test.ts +0 -106
- package/src/env/memory/plugin/recall-memory.ts +0 -53
- package/src/env/memory/plugin/types.ts +0 -101
- package/src/env/memory/tools/memory-agent-tools.ts +0 -228
- package/src/env/memory/types.ts +0 -85
- package/src/env/paths.ts +0 -118
- package/src/env/prompt/index.ts +0 -18
- package/src/env/prompt/memory-prompts.test.ts +0 -91
- package/src/env/prompt/prompt-component.test.ts +0 -491
- package/src/env/prompt/prompt-component.ts +0 -619
- package/src/env/prompt/prompt-config-registration.test.ts +0 -213
- package/src/env/prompt/prompt-config-registration.ts +0 -39
- package/src/env/prompt/prompts-index.ts +0 -504
- package/src/env/prompt/renderer.ts +0 -67
- package/src/env/prompt/types.ts +0 -136
- package/src/env/session/hooks.ts +0 -18
- package/src/env/session/index.ts +0 -37
- package/src/env/session/search-query-parser.test.ts +0 -425
- package/src/env/session/search-query-parser.ts +0 -171
- package/src/env/session/session-checkpoint.test.ts +0 -523
- package/src/env/session/session-component.extract-recent-messages.test.ts +0 -209
- package/src/env/session/session-component.test.ts +0 -132
- package/src/env/session/session-component.ts +0 -1249
- package/src/env/session/session-config-registration.test.ts +0 -138
- package/src/env/session/session-config-registration.ts +0 -52
- package/src/env/session/session-message-converter.test.ts +0 -763
- package/src/env/session/session-message-converter.ts +0 -415
- package/src/env/session/session-message-e2e.test.ts +0 -448
- package/src/env/session/session-search.test.ts +0 -391
- package/src/env/session/session-store.test.ts +0 -362
- package/src/env/session/session-store.ts +0 -141
- package/src/env/session/storage/index.ts +0 -6
- package/src/env/session/storage/memory.ts +0 -502
- package/src/env/session/storage/sqlite.ts +0 -794
- package/src/env/session/types.ts +0 -742
- package/src/env/skill/config.ts +0 -39
- package/src/env/skill/index.ts +0 -6
- package/src/env/skill/parser.test.ts +0 -116
- package/src/env/skill/parser.ts +0 -77
- package/src/env/skill/scanner.test.ts +0 -211
- package/src/env/skill/scanner.ts +0 -119
- package/src/env/skill/skill-component.test.ts +0 -234
- package/src/env/skill/skill-component.ts +0 -352
- package/src/env/skill/skill-config-registration.test.ts +0 -60
- package/src/env/skill/skill-config-registration.ts +0 -43
- package/src/env/skill/tool/index.ts +0 -1
- package/src/env/skill/tool/skill-tool.test.ts +0 -100
- package/src/env/skill/tool/skill-tool.ts +0 -72
- package/src/env/skill/types.ts +0 -64
- package/src/env/task/delegate/delegate-tool.test.ts +0 -498
- package/src/env/task/delegate/delegate-tool.ts +0 -1014
- package/src/env/task/delegate/index.ts +0 -18
- package/src/env/task/delegate/stop-tool.test.ts +0 -140
- package/src/env/task/delegate/stop-tool.ts +0 -119
- package/src/env/task/delegate/task-events.test.ts +0 -178
- package/src/env/task/delegate/task-events.ts +0 -143
- package/src/env/task/hooks/contexts.test.ts +0 -92
- package/src/env/task/hooks/contexts.ts +0 -192
- package/src/env/task/hooks/index.ts +0 -23
- package/src/env/task/hooks/task-hook-points.test.ts +0 -32
- package/src/env/task/hooks/task-hook-points.ts +0 -54
- package/src/env/task/index.ts +0 -7
- package/src/env/task/plugins/index.ts +0 -13
- package/src/env/task/plugins/task-plugin.test.ts +0 -74
- package/src/env/task/plugins/task-plugin.ts +0 -89
- package/src/env/task/plugins/task-tag-plugin.test.ts +0 -377
- package/src/env/task/plugins/task-tag-plugin.ts +0 -319
- package/src/env/task/plugins/task-workflow-extractor.integration.test.ts +0 -226
- package/src/env/task/plugins/workflow-extractor-agent.test.ts +0 -107
- package/src/env/task/plugins/workflow-extractor-agent.ts +0 -225
- package/src/env/task/storage/index.ts +0 -6
- package/src/env/task/storage/sqlite-task-store.test.ts +0 -283
- package/src/env/task/storage/sqlite-task-store.ts +0 -903
- package/src/env/task/storage/task-search.test.ts +0 -291
- package/src/env/task/tag-service.test.ts +0 -198
- package/src/env/task/tag-service.ts +0 -264
- package/src/env/task/task-component.test.ts +0 -193
- package/src/env/task/task-component.ts +0 -658
- package/src/env/task/task-config-registration.test.ts +0 -57
- package/src/env/task/task-config-registration.ts +0 -37
- package/src/env/task/task-types.test.ts +0 -137
- package/src/env/task/tools/complete-tool.ts +0 -44
- package/src/env/task/tools/create-tool.ts +0 -49
- package/src/env/task/tools/delete-tool.ts +0 -43
- package/src/env/task/tools/get-tool.ts +0 -59
- package/src/env/task/tools/index.ts +0 -10
- package/src/env/task/tools/list-tool.ts +0 -40
- package/src/env/task/tools/operation/create-tool.ts +0 -48
- package/src/env/task/tools/operation/delete-tool.ts +0 -43
- package/src/env/task/tools/operation/get-tool.ts +0 -43
- package/src/env/task/tools/operation/index.ts +0 -9
- package/src/env/task/tools/operation/list-tool.ts +0 -40
- package/src/env/task/tools/operation/operation-tools.test.ts +0 -274
- package/src/env/task/tools/operation/operation-types.ts +0 -75
- package/src/env/task/tools/operation/update-tool.ts +0 -47
- package/src/env/task/tools/task-tools.test.ts +0 -203
- package/src/env/task/tools/task-types.test.ts +0 -75
- package/src/env/task/tools/task-types.ts +0 -68
- package/src/env/task/tools/update-tool.ts +0 -70
- package/src/env/task/types.ts +0 -160
- package/src/env/tool/built-in/bash.ts +0 -201
- package/src/env/tool/built-in/echo.ts +0 -29
- package/src/env/tool/built-in/edit-file.test.ts +0 -136
- package/src/env/tool/built-in/edit-file.ts +0 -92
- package/src/env/tool/built-in/glob.test.ts +0 -94
- package/src/env/tool/built-in/glob.ts +0 -65
- package/src/env/tool/built-in/grep.test.ts +0 -122
- package/src/env/tool/built-in/grep.ts +0 -108
- package/src/env/tool/built-in/index.ts +0 -44
- package/src/env/tool/built-in/read-file.test.ts +0 -84
- package/src/env/tool/built-in/read-file.ts +0 -75
- package/src/env/tool/built-in/write-file.test.ts +0 -119
- package/src/env/tool/built-in/write-file.ts +0 -68
- package/src/env/tool/index.ts +0 -24
- package/src/env/tool/registry.test.ts +0 -257
- package/src/env/tool/registry.ts +0 -167
- package/src/env/tool/tool-component.test.ts +0 -559
- package/src/env/tool/tool-component.ts +0 -563
- package/src/env/tool/tool-config-registration.test.ts +0 -249
- package/src/env/tool/tool-config-registration.ts +0 -46
- package/src/env/tool/types.ts +0 -267
- package/src/env/tool/validator.test.ts +0 -143
- package/src/env/tool/validator.ts +0 -44
- package/src/env/types.ts +0 -180
- package/src/env/workflow/ask-user-tool-registration.test.ts +0 -216
- package/src/env/workflow/complex-workflow.integration.test.ts +0 -1900
- package/src/env/workflow/decorators/decorator-node.ts +0 -229
- package/src/env/workflow/decorators/decorator.test.ts +0 -196
- package/src/env/workflow/decorators/edge.ts +0 -82
- package/src/env/workflow/decorators/index.ts +0 -31
- package/src/env/workflow/decorators/node-as.ts +0 -98
- package/src/env/workflow/decorators/workflow.ts +0 -54
- package/src/env/workflow/engine/dag-manager.test.ts +0 -570
- package/src/env/workflow/engine/dag-manager.ts +0 -594
- package/src/env/workflow/engine/engine.ts +0 -1422
- package/src/env/workflow/engine/event-bus.test.ts +0 -359
- package/src/env/workflow/engine/event-bus.ts +0 -156
- package/src/env/workflow/engine/executor-agent-session.test.ts +0 -84
- package/src/env/workflow/engine/executor.test.ts +0 -619
- package/src/env/workflow/engine/executor.ts +0 -593
- package/src/env/workflow/engine/index.ts +0 -24
- package/src/env/workflow/engine/node-registry.test.ts +0 -560
- package/src/env/workflow/engine/node-registry.ts +0 -289
- package/src/env/workflow/engine/resume-removed.test.ts +0 -22
- package/src/env/workflow/engine/scheduler.test.ts +0 -715
- package/src/env/workflow/engine/scheduler.ts +0 -318
- package/src/env/workflow/engine/workflow-engine.test.ts +0 -815
- package/src/env/workflow/extractor/workflow-converter.ts +0 -306
- package/src/env/workflow/fixtures.ts +0 -380
- package/src/env/workflow/index.ts +0 -38
- package/src/env/workflow/integration/run-resume-unified.test.ts +0 -186
- package/src/env/workflow/integration/service-integration.test.ts +0 -267
- package/src/env/workflow/metadata/keys.ts +0 -12
- package/src/env/workflow/nodes/agent-component-adapter.test.ts +0 -318
- package/src/env/workflow/nodes/agent-component-adapter.ts +0 -448
- package/src/env/workflow/nodes/agent-node.test.ts +0 -371
- package/src/env/workflow/nodes/agent-node.ts +0 -598
- package/src/env/workflow/nodes/ask-user-node.ts +0 -113
- package/src/env/workflow/nodes/condition-node.ts +0 -200
- package/src/env/workflow/nodes/index.ts +0 -9
- package/src/env/workflow/nodes/merge-node.ts +0 -141
- package/src/env/workflow/nodes/skill-node.test.ts +0 -253
- package/src/env/workflow/nodes/skill-node.ts +0 -393
- package/src/env/workflow/nodes/tool-node.test.ts +0 -251
- package/src/env/workflow/nodes/tool-node.ts +0 -493
- package/src/env/workflow/nodes/workflow-llm-history.test.ts +0 -455
- package/src/env/workflow/nodes/workflow-node.test.ts +0 -315
- package/src/env/workflow/nodes/workflow-node.ts +0 -311
- package/src/env/workflow/service/index.ts +0 -27
- package/src/env/workflow/service/registry.test.ts +0 -133
- package/src/env/workflow/service/registry.ts +0 -71
- package/src/env/workflow/service/workflow-service.test.ts +0 -310
- package/src/env/workflow/service/workflow-service.ts +0 -393
- package/src/env/workflow/storage/index.ts +0 -28
- package/src/env/workflow/storage/mock-repositories.ts +0 -385
- package/src/env/workflow/storage/sqlite.test.ts +0 -179
- package/src/env/workflow/storage/sqlite.ts +0 -163
- package/src/env/workflow/storage/workflow-repo.test.ts +0 -780
- package/src/env/workflow/storage/workflow-repo.ts +0 -342
- package/src/env/workflow/tools/ask-user-tool.ts +0 -82
- package/src/env/workflow/tools/index.ts +0 -26
- package/src/env/workflow/tools/run-workflow.test.ts +0 -352
- package/src/env/workflow/tools/run-workflow.ts +0 -214
- package/src/env/workflow/types/context.ts +0 -18
- package/src/env/workflow/types/decorators-types.ts +0 -198
- package/src/env/workflow/types/event.test.ts +0 -515
- package/src/env/workflow/types/event.ts +0 -193
- package/src/env/workflow/types/index.ts +0 -49
- package/src/env/workflow/types/run.test.ts +0 -437
- package/src/env/workflow/types/run.ts +0 -173
- package/src/env/workflow/types/workflow-hil.ts +0 -114
- package/src/env/workflow/types/workflow-message.test.ts +0 -138
- package/src/env/workflow/types/workflow-message.ts +0 -196
- package/src/env/workflow/types/workflow-session.test.ts +0 -95
- package/src/env/workflow/types/workflow-session.ts +0 -59
- package/src/env/workflow/types/workflow.test.ts +0 -495
- package/src/env/workflow/types/workflow.ts +0 -195
- package/src/env/workflow/types_compat.ts +0 -51
- package/src/env/workflow/utils/create-workflow.ts +0 -47
- package/src/env/workflow/utils/execution-state.ts +0 -245
- package/src/env/workflow/utils/index.ts +0 -18
- package/src/env/workflow/utils/node-registry-helper.ts +0 -58
- package/src/env/workflow/utils/recovery-validator.test.ts +0 -460
- package/src/env/workflow/utils/recovery-validator.ts +0 -377
- package/src/env/workflow/utils/session-parser.test.ts +0 -111
- package/src/env/workflow/utils/session-parser.ts +0 -94
- package/src/env/workflow/utils/session-recovery.test.ts +0 -334
- package/src/env/workflow/utils/session-recovery.ts +0 -188
- package/src/env/workflow/utils/template-resolver.test.ts +0 -258
- package/src/env/workflow/utils/template-resolver.ts +0 -436
- package/src/env/workflow/utils/validation-rules.ts +0 -149
- package/src/env/workflow/workflow-component.ts +0 -544
- package/src/index.ts +0 -422
- package/src/utils/id.ts +0 -21
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview TDD Tests for Tool Error Handling in AgentComponent
|
|
3
|
-
*
|
|
4
|
-
* Feature: Tool execution error should be stored as tool result
|
|
5
|
-
*
|
|
6
|
-
* Problem:
|
|
7
|
-
* When a tool throws an exception during execution, the tool call is already
|
|
8
|
-
* added to messages (via pushMessage), but the tool result is NOT added because:
|
|
9
|
-
* 1. executeTool() throws the error
|
|
10
|
-
* 2. The catch block in the ReAct loop catches the error
|
|
11
|
-
* 3. Tool result pushMessage() is never reached
|
|
12
|
-
*
|
|
13
|
-
* This breaks AI SDK v6's requirement for 1:1 tool-call to tool-result mapping.
|
|
14
|
-
*
|
|
15
|
-
* Solution:
|
|
16
|
-
* Modify the error handling to always add tool result (with error content) even
|
|
17
|
-
* when tool execution throws an exception. This makes the behavior uniform
|
|
18
|
-
* regardless of whether the tool succeeds, returns an error, or throws an exception.
|
|
19
|
-
*
|
|
20
|
-
* For ask_user special case: the exception is stored as tool result (unlike other
|
|
21
|
-
* exceptions which are swallowed), allowing resume flow to replace it with actual
|
|
22
|
-
* user response.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
26
|
-
import { AgentComponent } from "./agent-component";
|
|
27
|
-
import type { Environment } from "../interface";
|
|
28
|
-
import { ConfigComponent } from "../../config/config-component";
|
|
29
|
-
import { AskUserError } from "../workflow/types/workflow-hil";
|
|
30
|
-
import { z } from "zod";
|
|
31
|
-
|
|
32
|
-
// ============================================================================
|
|
33
|
-
// Mock Environment Factory
|
|
34
|
-
// ============================================================================
|
|
35
|
-
|
|
36
|
-
function createMockEnvironment(mockComponents: Record<string, any> = {}): Environment {
|
|
37
|
-
return {
|
|
38
|
-
name: "test-env",
|
|
39
|
-
version: "1.0.0",
|
|
40
|
-
getConfig: vi.fn(() => ({ name: "test-env", version: "1.0.0", enabled: true })),
|
|
41
|
-
registerComponent: vi.fn(),
|
|
42
|
-
unregisterComponent: vi.fn(),
|
|
43
|
-
getComponent: vi.fn((name: string) => {
|
|
44
|
-
return mockComponents[name];
|
|
45
|
-
}),
|
|
46
|
-
listComponents: vi.fn(() => Object.keys(mockComponents)),
|
|
47
|
-
handle_query: vi.fn(),
|
|
48
|
-
handle_action: vi.fn(),
|
|
49
|
-
subscribe: vi.fn(() => () => {}),
|
|
50
|
-
subscribeTo: vi.fn(() => () => {}),
|
|
51
|
-
subscribeAll: vi.fn(() => () => {}),
|
|
52
|
-
pushEnvEvent: vi.fn(),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ============================================================================
|
|
57
|
-
// Test Suite: Tool Error Handling
|
|
58
|
-
// ============================================================================
|
|
59
|
-
|
|
60
|
-
describe("AgentComponent Tool Error Handling (TDD)", () => {
|
|
61
|
-
let agentComponent: AgentComponent;
|
|
62
|
-
let mockEnv: Environment;
|
|
63
|
-
let configComponent: ConfigComponent;
|
|
64
|
-
let mockSessionComponent: any;
|
|
65
|
-
|
|
66
|
-
beforeEach(async () => {
|
|
67
|
-
vi.clearAllMocks();
|
|
68
|
-
|
|
69
|
-
configComponent = new ConfigComponent();
|
|
70
|
-
|
|
71
|
-
// Create mock session component to capture stored messages
|
|
72
|
-
mockSessionComponent = {
|
|
73
|
-
name: "session",
|
|
74
|
-
create: vi.fn(async () => ({ id: "test-session", title: "Test" })),
|
|
75
|
-
get: vi.fn(async () => ({ id: "test-session" })),
|
|
76
|
-
addMessage: vi.fn(async () => "msg_id"),
|
|
77
|
-
getMessages: vi.fn(async () => []),
|
|
78
|
-
getContext: vi.fn(async () => ({
|
|
79
|
-
session: { id: "test-session" },
|
|
80
|
-
messages: [],
|
|
81
|
-
})),
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
mockEnv = createMockEnvironment({
|
|
85
|
-
config: configComponent,
|
|
86
|
-
session: mockSessionComponent,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
agentComponent = new AgentComponent();
|
|
90
|
-
await agentComponent.init({
|
|
91
|
-
name: "agent",
|
|
92
|
-
version: "1.0.0",
|
|
93
|
-
enabled: true,
|
|
94
|
-
env: mockEnv,
|
|
95
|
-
options: { configComponent }
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
afterEach(() => {
|
|
100
|
-
vi.restoreAllMocks();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// ===========================================================================
|
|
104
|
-
// RED Phase: Write failing tests first
|
|
105
|
-
// ===========================================================================
|
|
106
|
-
|
|
107
|
-
describe("RED: AskUserError should be stored as tool result", () => {
|
|
108
|
-
it("should store AskUserError as tool result for ask_user tool", async () => {
|
|
109
|
-
// Setup agent
|
|
110
|
-
agentComponent.registerAgent("test-agent", {
|
|
111
|
-
type: "primary",
|
|
112
|
-
systemPrompt: "You are a helpful assistant.",
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// Mock LLM that returns ask_user tool call
|
|
116
|
-
const mockLLMComponent = {
|
|
117
|
-
invoke: vi.fn(() => Promise.resolve({
|
|
118
|
-
output: {
|
|
119
|
-
content: "",
|
|
120
|
-
toolCalls: [{
|
|
121
|
-
id: "call_1",
|
|
122
|
-
function: { name: "ask_user", arguments: JSON.stringify({ query: "Continue?" }) }
|
|
123
|
-
}]
|
|
124
|
-
}
|
|
125
|
-
}))
|
|
126
|
-
};
|
|
127
|
-
(mockEnv.getComponent as any).mockImplementation((name: string) => {
|
|
128
|
-
if (name === "llm") return mockLLMComponent;
|
|
129
|
-
if (name === "session") return mockSessionComponent;
|
|
130
|
-
return undefined;
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// Mock ask_user tool that throws AskUserError
|
|
134
|
-
const mockAskUserTool: any = {
|
|
135
|
-
name: "ask_user",
|
|
136
|
-
description: "Ask user for input",
|
|
137
|
-
parameters: z.object({
|
|
138
|
-
query: z.string(),
|
|
139
|
-
}),
|
|
140
|
-
execute: vi.fn(async () => {
|
|
141
|
-
throw new AskUserError(
|
|
142
|
-
"run_123",
|
|
143
|
-
"test-session",
|
|
144
|
-
"node_1",
|
|
145
|
-
"agent",
|
|
146
|
-
"Continue?"
|
|
147
|
-
);
|
|
148
|
-
}),
|
|
149
|
-
};
|
|
150
|
-
agentComponent.setDefaultTools([mockAskUserTool]);
|
|
151
|
-
|
|
152
|
-
// Execute agent
|
|
153
|
-
const result = await agentComponent.run("test-agent", "Test ask_user", {
|
|
154
|
-
sessionId: "test-session",
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// Verify: result should contain __ASK_USER_ERROR__ marker
|
|
158
|
-
expect(result.error).toBeDefined();
|
|
159
|
-
expect(result.error).toContain("__ASK_USER_ERROR__");
|
|
160
|
-
|
|
161
|
-
// Verify: session should have tool result with error content
|
|
162
|
-
const storedMessages = mockSessionComponent.addMessage.mock.calls;
|
|
163
|
-
const toolMessages = storedMessages.filter((call: any[]) =>
|
|
164
|
-
call[1]?.role === "tool"
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
// For ask_user, tool result should be stored with error info
|
|
168
|
-
expect(toolMessages.length).toBeGreaterThan(0);
|
|
169
|
-
|
|
170
|
-
const toolMessage = toolMessages[0][1];
|
|
171
|
-
// Content might be empty, check parts for output
|
|
172
|
-
const hasParts = toolMessage.parts && toolMessage.parts.length > 0;
|
|
173
|
-
const hasOutput = hasParts && toolMessage.parts[0]?.output;
|
|
174
|
-
|
|
175
|
-
// Either content or parts output should contain the query
|
|
176
|
-
const toolContent = typeof toolMessage.content === "string"
|
|
177
|
-
? toolMessage.content
|
|
178
|
-
: "";
|
|
179
|
-
const partsOutput = hasOutput ? JSON.stringify(toolMessage.parts[0].output) : "";
|
|
180
|
-
|
|
181
|
-
// Should contain error info from AskUserError (query in output)
|
|
182
|
-
expect(toolContent + partsOutput).toContain("Continue?");
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
describe("RED: Resume flow should replace tool result", () => {
|
|
187
|
-
it("should allow replacing tool result with user response on resume", async () => {
|
|
188
|
-
// This test verifies the resume flow design
|
|
189
|
-
// When resuming, the stored tool result (with error) should be
|
|
190
|
-
// replaced with the actual user response
|
|
191
|
-
|
|
192
|
-
const agentSessionId = "agent_session_123";
|
|
193
|
-
|
|
194
|
-
// Simulate stored messages after initial run (with tool error stored)
|
|
195
|
-
const storedToolResult = {
|
|
196
|
-
role: "tool" as const,
|
|
197
|
-
content: JSON.stringify({ error: "AskUserError: Continue?" }),
|
|
198
|
-
metadata: {
|
|
199
|
-
toolCallId: "call_1",
|
|
200
|
-
toolName: "ask_user",
|
|
201
|
-
isAskUserError: true,
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
// Simulate resume - user response should replace tool result
|
|
206
|
-
const userResponse = "yes, continue";
|
|
207
|
-
|
|
208
|
-
// Resume would call addMessage to add user response
|
|
209
|
-
// The key insight: on resume, we need to either:
|
|
210
|
-
// 1. Replace the existing tool result message, or
|
|
211
|
-
// 2. Add user response as a new message and skip the error tool result
|
|
212
|
-
|
|
213
|
-
// For now, verify the session can store both
|
|
214
|
-
mockSessionComponent.addMessage(agentSessionId, {
|
|
215
|
-
role: "user",
|
|
216
|
-
content: userResponse,
|
|
217
|
-
metadata: { type: "user_response" },
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// Verify user response was stored
|
|
221
|
-
expect(mockSessionComponent.addMessage).toHaveBeenCalledWith(
|
|
222
|
-
agentSessionId,
|
|
223
|
-
expect.objectContaining({
|
|
224
|
-
role: "user",
|
|
225
|
-
content: userResponse,
|
|
226
|
-
})
|
|
227
|
-
);
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
describe("RED: Normal tool error should also be stored", () => {
|
|
232
|
-
it("should store normal tool error as tool result", async () => {
|
|
233
|
-
// Setup agent
|
|
234
|
-
agentComponent.registerAgent("test-agent", {
|
|
235
|
-
type: "primary",
|
|
236
|
-
systemPrompt: "You are a helpful assistant.",
|
|
237
|
-
maxIterations: 1, // Limit iterations to avoid infinite loop
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
// Mock LLM that returns a tool call
|
|
241
|
-
const mockLLMComponent = {
|
|
242
|
-
invoke: vi.fn(() => Promise.resolve({
|
|
243
|
-
output: {
|
|
244
|
-
content: "",
|
|
245
|
-
toolCalls: [{
|
|
246
|
-
id: "call_1",
|
|
247
|
-
function: { name: "error_tool", arguments: "{}" }
|
|
248
|
-
}]
|
|
249
|
-
}
|
|
250
|
-
}))
|
|
251
|
-
};
|
|
252
|
-
(mockEnv.getComponent as any).mockImplementation((name: string) => {
|
|
253
|
-
if (name === "llm") return mockLLMComponent;
|
|
254
|
-
if (name === "session") return mockSessionComponent;
|
|
255
|
-
return undefined;
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
// Mock tool that returns error result (not throws)
|
|
259
|
-
const mockTool: any = {
|
|
260
|
-
name: "error_tool",
|
|
261
|
-
description: "A tool that returns error",
|
|
262
|
-
parameters: z.object({}),
|
|
263
|
-
execute: vi.fn(async () => {
|
|
264
|
-
return { success: false, output: "", error: "Tool execution failed!" };
|
|
265
|
-
}),
|
|
266
|
-
};
|
|
267
|
-
agentComponent.setDefaultTools([mockTool]);
|
|
268
|
-
|
|
269
|
-
// Execute agent
|
|
270
|
-
const result = await agentComponent.run("test-agent", "Test tool error", {
|
|
271
|
-
sessionId: "test-session",
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
// Verify: session should have BOTH tool call and tool result
|
|
275
|
-
expect(mockSessionComponent.addMessage).toHaveBeenCalled();
|
|
276
|
-
const storedMessages = mockSessionComponent.addMessage.mock.calls;
|
|
277
|
-
|
|
278
|
-
// Find tool result message
|
|
279
|
-
const toolMessages = storedMessages.filter((call: any[]) =>
|
|
280
|
-
call[1]?.role === "tool"
|
|
281
|
-
);
|
|
282
|
-
expect(toolMessages.length).toBeGreaterThan(0);
|
|
283
|
-
|
|
284
|
-
// The tool result should contain the error message
|
|
285
|
-
const toolMessage = toolMessages[0][1];
|
|
286
|
-
const hasParts = toolMessage.parts && toolMessage.parts.length > 0;
|
|
287
|
-
const hasOutput = hasParts && toolMessage.parts[0]?.output;
|
|
288
|
-
|
|
289
|
-
const toolContent = typeof toolMessage.content === "string"
|
|
290
|
-
? toolMessage.content
|
|
291
|
-
: "";
|
|
292
|
-
const partsOutput = hasOutput ? JSON.stringify(toolMessage.parts[0].output) : "";
|
|
293
|
-
|
|
294
|
-
expect(toolContent + partsOutput).toContain("Tool execution failed");
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
// ===========================================================================
|
|
299
|
-
// Helper: Run agent with mocked LLM
|
|
300
|
-
// ===========================================================================
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Helper function to run agent with custom LLM mock
|
|
304
|
-
*/
|
|
305
|
-
async function runAgentWithLLMMock(
|
|
306
|
-
agentName: string,
|
|
307
|
-
llmResponse: any,
|
|
308
|
-
tools: any[],
|
|
309
|
-
sessionId?: string
|
|
310
|
-
) {
|
|
311
|
-
const mockLLMComponent = {
|
|
312
|
-
invoke: vi.fn(() => Promise.resolve(llmResponse)),
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
(mockEnv.getComponent as any).mockImplementation((name: string) => {
|
|
316
|
-
if (name === "llm") return mockLLMComponent;
|
|
317
|
-
if (name === "session") return mockSessionComponent;
|
|
318
|
-
return undefined;
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
agentComponent.setDefaultTools(tools);
|
|
322
|
-
|
|
323
|
-
return agentComponent.run(agentName, "Test query", {
|
|
324
|
-
sessionId: sessionId || "test-session",
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
});
|