onbuzz 4.9.13 → 4.10.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/node_modules/glob/README.md +31 -5
- package/node_modules/glob/dist/commonjs/glob.d.ts +8 -0
- package/node_modules/glob/dist/commonjs/glob.d.ts.map +1 -1
- package/node_modules/glob/dist/commonjs/glob.js +2 -1
- package/node_modules/glob/dist/commonjs/glob.js.map +1 -1
- package/node_modules/glob/dist/commonjs/index.min.js +3 -3
- package/node_modules/glob/dist/commonjs/index.min.js.map +4 -4
- package/node_modules/glob/dist/commonjs/pattern.d.ts +3 -0
- package/node_modules/glob/dist/commonjs/pattern.d.ts.map +1 -1
- package/node_modules/glob/dist/commonjs/pattern.js +4 -0
- package/node_modules/glob/dist/commonjs/pattern.js.map +1 -1
- package/node_modules/glob/dist/esm/glob.d.ts +8 -0
- package/node_modules/glob/dist/esm/glob.d.ts.map +1 -1
- package/node_modules/glob/dist/esm/glob.js +2 -1
- package/node_modules/glob/dist/esm/glob.js.map +1 -1
- package/node_modules/glob/dist/esm/index.min.js +3 -3
- package/node_modules/glob/dist/esm/index.min.js.map +4 -4
- package/node_modules/glob/dist/esm/pattern.d.ts +3 -0
- package/node_modules/glob/dist/esm/pattern.d.ts.map +1 -1
- package/node_modules/glob/dist/esm/pattern.js +4 -0
- package/node_modules/glob/dist/esm/pattern.js.map +1 -1
- package/node_modules/{@isaacs → glob/node_modules}/balanced-match/README.md +7 -10
- package/node_modules/{@isaacs → glob/node_modules}/balanced-match/package.json +7 -18
- package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/README.md +3 -6
- package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/index.js +6 -4
- package/node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -0
- package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/index.js +6 -4
- package/node_modules/glob/node_modules/brace-expansion/dist/esm/index.js.map +1 -0
- package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/package.json +11 -7
- package/node_modules/glob/node_modules/minimatch/README.md +76 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.d.ts +4 -2
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.js +309 -55
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/brace-expressions.js +2 -4
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/brace-expressions.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.js +4 -4
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.d.ts +81 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js +232 -134
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.js +8 -8
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/assert-valid-pattern.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/ast.d.ts +4 -2
- package/node_modules/glob/node_modules/minimatch/dist/esm/ast.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/ast.js +309 -55
- package/node_modules/glob/node_modules/minimatch/dist/esm/ast.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/brace-expressions.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/brace-expressions.js +2 -4
- package/node_modules/glob/node_modules/minimatch/dist/esm/brace-expressions.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/escape.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/escape.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/escape.js +4 -4
- package/node_modules/glob/node_modules/minimatch/dist/esm/escape.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/index.d.ts +81 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/index.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/index.js +232 -134
- package/node_modules/glob/node_modules/minimatch/dist/esm/index.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.js +8 -8
- package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/package.json +17 -11
- package/node_modules/glob/package.json +10 -13
- package/node_modules/minipass/LICENSE.md +55 -0
- package/node_modules/minipass/dist/commonjs/index.d.ts +12 -16
- package/node_modules/minipass/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/minipass/dist/commonjs/index.js +13 -3
- package/node_modules/minipass/dist/commonjs/index.js.map +1 -1
- package/node_modules/minipass/dist/esm/index.d.ts +12 -16
- package/node_modules/minipass/dist/esm/index.d.ts.map +1 -1
- package/node_modules/minipass/dist/esm/index.js +3 -1
- package/node_modules/minipass/dist/esm/index.js.map +1 -1
- package/node_modules/minipass/package.json +9 -14
- package/node_modules/path-scurry/node_modules/lru-cache/README.md +96 -10
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel-browser.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel-browser.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.d.ts +1400 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js.map +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.cjs.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.d.ts +109 -32
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +334 -197
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js.map +4 -4
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel-node.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel-node.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.d.ts +1400 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js.map +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel-browser.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel-browser.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.d.ts +1400 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js.map +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.mjs.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.d.ts +109 -32
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.d.ts.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +333 -196
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js.map +4 -4
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel-node.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel-node.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.d.ts +1400 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js.map +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/package.json +71 -18
- package/node_modules/path-scurry/package.json +8 -24
- package/package.json +1 -1
- package/scripts/debug-balance-probe.mjs +35 -35
- package/scripts/push-image.sh +43 -43
- package/scripts/setup-acr.sh +65 -65
- package/scripts/verify-optional-deps.js +96 -1
- package/src/__tests__/composioCliFlags.test.js +239 -239
- package/src/analyzers/CSSAnalyzer.js +298 -297
- package/src/analyzers/ConfigValidator.js +691 -690
- package/src/analyzers/ESLintAnalyzer.js +320 -320
- package/src/analyzers/JavaScriptAnalyzer.js +260 -261
- package/src/analyzers/PrettierFormatter.js +246 -247
- package/src/analyzers/PythonAnalyzer.js +283 -283
- package/src/analyzers/SecurityAnalyzer.js +729 -729
- package/src/analyzers/SparrowAnalyzer.js +341 -341
- package/src/analyzers/TypeScriptAnalyzer.js +247 -247
- package/src/analyzers/__tests__/CSSAnalyzer.test.js +41 -41
- package/src/analyzers/__tests__/ConfigValidator.test.js +362 -362
- package/src/analyzers/__tests__/JavaScriptAnalyzer.test.js +40 -40
- package/src/analyzers/__tests__/PythonAnalyzer.test.js +205 -208
- package/src/analyzers/__tests__/SecurityAnalyzer.test.js +303 -303
- package/src/analyzers/__tests__/TypeScriptAnalyzer.test.js +187 -187
- package/src/analyzers/codeCloneDetector/analyzer.js +344 -344
- package/src/analyzers/codeCloneDetector/detector.js +250 -250
- package/src/analyzers/codeCloneDetector/index.js +194 -192
- package/src/analyzers/codeCloneDetector/parser.js +199 -199
- package/src/core/__tests__/agentPool.test.js +866 -866
- package/src/core/__tests__/agentPoolAutoResume.test.js +209 -209
- package/src/core/__tests__/agentPoolWakeOnMessage.test.js +315 -315
- package/src/core/__tests__/agentScheduler.emptyResponseChatStall.test.js +213 -213
- package/src/core/__tests__/agentScheduler.errorCategorisation.test.js +246 -246
- package/src/core/__tests__/agentScheduler.firstChunkTimeout.test.js +138 -138
- package/src/core/__tests__/agentScheduler.modeTransitions.test.js +233 -233
- package/src/core/__tests__/agentScheduler.nativePromptPick.test.js +319 -319
- package/src/core/__tests__/agentScheduler.taskLifecycleInstruction.test.js +78 -78
- package/src/core/__tests__/agentScheduler.visualizer.test.js +258 -258
- package/src/core/__tests__/flowCheckpointStore.test.js +140 -140
- package/src/core/__tests__/flowEndToEnd.test.js +565 -565
- package/src/core/__tests__/flowFieldMapping.test.js +188 -189
- package/src/core/__tests__/flowLintClientMirror.test.js +96 -98
- package/src/core/__tests__/flowSavePayload.test.js +170 -169
- package/src/core/__tests__/flowTemplates.test.js +311 -311
- package/src/core/__tests__/flowVersionStore.test.js +123 -123
- package/src/core/__tests__/messageProcessor.test.js +669 -669
- package/src/core/__tests__/stateManager.test.js +0 -1
- package/src/core/agentPool.js +2474 -2475
- package/src/core/agentScheduler.js +1 -4
- package/src/core/contextManager.js +708 -708
- package/src/core/flowExecutor.js +1510 -1510
- package/src/core/flowFieldMapping.js +136 -138
- package/src/core/messageProcessor.js +953 -954
- package/src/core/orchestrator.js +593 -595
- package/src/core/stateManager.js +1765 -1752
- package/src/index.js +1221 -1221
- package/src/interfaces/__tests__/archivedAgentDelete.test.js +207 -207
- package/src/interfaces/__tests__/bulkAgentRoute.test.js +361 -361
- package/src/interfaces/__tests__/imageServing.test.js +228 -228
- package/src/interfaces/__tests__/remoteSessionAuth.test.js +308 -308
- package/src/interfaces/__tests__/videoJobsRoutes.test.js +178 -179
- package/src/interfaces/__tests__/webServer.marketplace.test.js +629 -629
- package/src/interfaces/schedulerRoutes.js +50 -50
- package/src/interfaces/terminal/__tests__/smoke/connection.test.js +341 -350
- package/src/interfaces/terminal/__tests__/smoke/enhancements.test.js +156 -156
- package/src/interfaces/terminal/__tests__/smoke/imports.test.js +325 -330
- package/src/interfaces/terminal/__tests__/smoke/tools.test.js +385 -388
- package/src/interfaces/terminal/api/session.js +265 -266
- package/src/interfaces/terminal/api/websocket.js +496 -497
- package/src/interfaces/terminal/components/AgentCreator.js +691 -705
- package/src/interfaces/terminal/components/AgentEditor.js +676 -678
- package/src/interfaces/terminal/components/AgentSwitcher.js +331 -330
- package/src/interfaces/terminal/components/ErrorPanel.js +263 -264
- package/src/interfaces/terminal/components/Header.js +28 -28
- package/src/interfaces/terminal/components/Layout.js +598 -603
- package/src/interfaces/terminal/components/MessageList.js +280 -281
- package/src/interfaces/terminal/components/SettingsPanel.js +410 -415
- package/src/interfaces/terminal/components/StatusBar.js +2 -0
- package/src/interfaces/terminal/index.js +168 -168
- package/src/interfaces/terminal/state/useAgentControl.js +496 -496
- package/src/interfaces/terminal/state/useAgents.js +537 -537
- package/src/interfaces/terminal/state/useMessages.js +629 -630
- package/src/interfaces/terminal/state/useTools.js +554 -554
- package/src/interfaces/terminal/utils/debugLogger.js +44 -44
- package/src/interfaces/terminal/utils/settingsStorage.js +232 -232
- package/src/interfaces/webServer.js +7578 -7579
- package/src/interfaces/webServer.js.bak +7046 -7046
- package/src/modules/fileExplorer/__tests__/zipDownload.test.js +237 -237
- package/src/modules/fileExplorer/controller.js +470 -469
- package/src/modules/fileExplorer/routes.js +285 -286
- package/src/modules/widget/__tests__/isDisabled.test.js +41 -41
- package/src/modules/widget/__tests__/routes.test.js +677 -678
- package/src/modules/widget/__tests__/runtime.test.js +401 -401
- package/src/modules/widget/__tests__/versioning.test.js +309 -309
- package/src/modules/widget/__tests__/webComponentRuntime.test.js +565 -565
- package/src/modules/widget/__tests__/widgetTool.test.js +316 -316
- package/src/modules/widget/routes.js +435 -435
- package/src/modules/widget/runtime/bundle.js +640 -640
- package/src/modules/widget/runtime/webComponentBundle.js +470 -470
- package/src/modules/widget/schema.js +182 -181
- package/src/modules/widget/widgetTool.js +1389 -1389
- package/src/services/__tests__/agentActivityService.test.js +401 -402
- package/src/services/__tests__/benchmarkService.test.js +184 -184
- package/src/services/__tests__/contextInjectionService.test.js +246 -246
- package/src/services/__tests__/conversationQuery.test.js +721 -723
- package/src/services/__tests__/credentialVault.test.js +469 -469
- package/src/services/__tests__/discordService.integration.test.js +638 -639
- package/src/services/__tests__/flowContextService.test.js +590 -590
- package/src/services/__tests__/memoryService.test.js +1 -1
- package/src/services/__tests__/messageSource.test.js +380 -380
- package/src/services/__tests__/modelRouterNaming.test.js +111 -111
- package/src/services/__tests__/projectDetector.test.js +34 -34
- package/src/services/__tests__/promptService.test.js +242 -242
- package/src/services/__tests__/telegramService.test.js +941 -941
- package/src/services/__tests__/tokenCountingService.test.js +48 -48
- package/src/services/agentActivityService.js +419 -420
- package/src/services/aiService.js +2997 -3001
- package/src/services/apiKeyManager.js +359 -359
- package/src/services/benchmarkService.js +196 -196
- package/src/services/codebaseKnowledgeService.js +2 -2
- package/src/services/composioService.js +738 -738
- package/src/services/conversationCompactionService.js +1258 -1257
- package/src/services/credentialVault.js +685 -685
- package/src/services/discordService.js +792 -793
- package/src/services/embeddings/__tests__/azureCustomProvider.test.js +232 -232
- package/src/services/embeddings/__tests__/embeddingService.test.js +417 -417
- package/src/services/embeddings/__tests__/localProvider.test.js +263 -263
- package/src/services/embeddings/autoRecall.js +218 -219
- package/src/services/embeddings/indexers/__tests__/agentIndexer.test.js +232 -232
- package/src/services/embeddings/indexers/__tests__/memoryIndexer.test.js +418 -418
- package/src/services/embeddings/indexers/__tests__/reminisceIndexer.test.js +356 -357
- package/src/services/embeddings/indexers/__tests__/skillsIndexer.test.js +145 -145
- package/src/services/embeddings/indexers/__tests__/taskIndexer.test.js +146 -146
- package/src/services/embeddings/indexers/composioIndexer.js +279 -279
- package/src/services/embeddings/providerInterface.js +206 -206
- package/src/services/embeddings/providers/localProvider.js +11 -7
- package/src/services/embeddings/providers/openaiProvider.js +101 -101
- package/src/services/embeddings/vectorStore/inMemoryJsonStore.js +356 -356
- package/src/services/errorHandler.js +809 -809
- package/src/services/flowContextService.js +586 -586
- package/src/services/grounding/MockAdapter.js +125 -125
- package/src/services/modelRouterService.js +26 -31
- package/src/services/modelsService.js +322 -322
- package/src/services/ollamaService.js +452 -452
- package/src/services/projectDetector.js +403 -404
- package/src/services/promptService.js +418 -418
- package/src/services/qualityInspector.js +795 -795
- package/src/services/scheduleService.js +726 -726
- package/src/services/serviceRegistry.js +386 -386
- package/src/services/telegrafBot.js +174 -174
- package/src/services/telegramService.js +1972 -1972
- package/src/services/visualEditorBridge.js +1033 -1033
- package/src/services/visualEditorServer.js +1769 -1774
- package/src/services/whatsappService.js +667 -668
- package/src/tools/__tests__/agentCommunicationTool.findAgent.test.js +226 -226
- package/src/tools/__tests__/agentCommunicationTool.test.js +3 -3
- package/src/tools/__tests__/agentDelayTool.test.js +342 -342
- package/src/tools/__tests__/baseTool.test.js +3 -3
- package/src/tools/__tests__/codeMapTool.test.js +915 -915
- package/src/tools/__tests__/fileContentReplaceTool.test.js +309 -309
- package/src/tools/__tests__/fileTreeTool.test.js +274 -274
- package/src/tools/__tests__/filesystemTool.test.js +815 -815
- package/src/tools/__tests__/foundryWebSearchTool.test.js +252 -252
- package/src/tools/__tests__/imageTool.validator.test.js +194 -194
- package/src/tools/__tests__/jobDoneTool.test.js +580 -581
- package/src/tools/__tests__/memoryTool.forgetStale.test.js +272 -272
- package/src/tools/__tests__/memoryTool.reminisce.test.js +2 -2
- package/src/tools/__tests__/memoryTool.reminisceSemanticSearch.test.js +301 -301
- package/src/tools/__tests__/memoryTool.semanticSearch.test.js +405 -405
- package/src/tools/__tests__/memoryTool.teamPool.test.js +293 -293
- package/src/tools/__tests__/memoryTool.test.js +1 -1
- package/src/tools/__tests__/seekTool.test.js +282 -282
- package/src/tools/__tests__/skillsTool.search.test.js +164 -164
- package/src/tools/__tests__/skillsTool.test.js +226 -226
- package/src/tools/__tests__/staticAnalysisTool.test.js +509 -509
- package/src/tools/__tests__/taskManagerTool.discipline.test.js +137 -137
- package/src/tools/__tests__/taskManagerTool.search.test.js +143 -143
- package/src/tools/__tests__/taskManagerTool.test.js +866 -866
- package/src/tools/__tests__/terminalTool.test.js +448 -448
- package/src/tools/__tests__/toolShapeForgiveness.test.js +259 -260
- package/src/tools/__tests__/userPromptTool.test.js +297 -297
- package/src/tools/__tests__/videoTool.jobs.test.js +147 -147
- package/src/tools/__tests__/webTool.e2e.test.js +609 -603
- package/src/tools/__tests__/webTool.unit.test.js +195 -195
- package/src/tools/__tests__/webTool.visionModel.test.js +75 -75
- package/src/tools/agentCommunicationTool.js +8 -10
- package/src/tools/agentDelayTool.js +496 -497
- package/src/tools/asyncToolManager.js +602 -603
- package/src/tools/baseTool.js +12 -11
- package/src/tools/cloneDetectionTool.js +576 -581
- package/src/tools/codeMapTool.js +0 -6
- package/src/tools/composioTool.js +617 -617
- package/src/tools/dependencyResolverTool.js +1211 -1212
- package/src/tools/desktop/DesktopTool.js +629 -638
- package/src/tools/desktop/__tests__/DesktopTool.e2e.test.js +306 -306
- package/src/tools/desktop/__tests__/DesktopTool.test.js +507 -507
- package/src/tools/desktop/__tests__/osController.test.js +364 -364
- package/src/tools/desktop/osController.js +491 -491
- package/src/tools/docxTool.js +623 -623
- package/src/tools/excelTool.js +636 -636
- package/src/tools/fileContentReplaceTool.js +5 -7
- package/src/tools/fileSystemTool.js +12 -19
- package/src/tools/fileTreeTool.js +840 -840
- package/src/tools/foundryWebSearchTool.js +273 -273
- package/src/tools/helpTool.js +198 -198
- package/src/tools/imageTool.js +1397 -1397
- package/src/tools/importAnalyzerTool.js +1056 -1056
- package/src/tools/jobDoneTool.js +495 -495
- package/src/tools/memoryTool.js +1 -1
- package/src/tools/office/pres/__tests__/presSystem.test.js +365 -365
- package/src/tools/office/pres/archetypes/agenda.js +61 -61
- package/src/tools/office/pres/archetypes/bentoGrid.js +218 -219
- package/src/tools/office/pres/archetypes/bigStat.js +140 -142
- package/src/tools/office/pres/archetypes/closing.js +70 -70
- package/src/tools/office/pres/archetypes/hero.js +70 -70
- package/src/tools/office/pres/archetypes/productHero.js +93 -94
- package/src/tools/office/pres/archetypes/table.js +73 -74
- package/src/tools/office/pres/backgrounds/orb.js +66 -66
- package/src/tools/office/pres/components.js +422 -423
- package/src/tools/officeTool.js +441 -441
- package/src/tools/pdfTool.js +625 -627
- package/src/tools/platformControlTool.js +1081 -1081
- package/src/tools/seekTool.js +917 -918
- package/src/tools/skillsTool.js +1 -1
- package/src/tools/staticAnalysisTool.js +2143 -2146
- package/src/tools/taskManagerTool.js +3324 -3324
- package/src/tools/terminalTool.js +2615 -2618
- package/src/tools/videoTool.js +1303 -1303
- package/src/tools/visionTool.js +508 -508
- package/src/tools/visualEditorTool.js +1289 -1290
- package/src/tools/webTool.js +3368 -3368
- package/src/tools/whatsappTool.js +464 -464
- package/src/types/__tests__/agent.test.js +499 -499
- package/src/types/__tests__/contextReference.test.js +606 -606
- package/src/types/__tests__/conversation.test.js +555 -555
- package/src/types/__tests__/toolCommand.test.js +584 -584
- package/src/types/contextReference.js +974 -971
- package/src/types/conversation.js +729 -729
- package/src/types/toolCommand.js +746 -746
- package/src/utilities/__tests__/attachmentValidator.test.js +80 -80
- package/src/utilities/__tests__/auditReport.test.js +328 -328
- package/src/utilities/__tests__/directoryAccessManager.test.js +388 -388
- package/src/utilities/__tests__/jsonRepair.test.js +103 -104
- package/src/utilities/__tests__/modeTransitionReasons.test.js +105 -105
- package/src/utilities/__tests__/platformUtils.test.js +80 -87
- package/src/utilities/__tests__/structuredFileValidator.test.js +261 -263
- package/src/utilities/__tests__/toolConstants.test.js +92 -94
- package/src/utilities/__tests__/useIsTouchDevice.detect.test.js +114 -114
- package/src/utilities/__tests__/webUiUtilSync.test.js +117 -117
- package/src/utilities/attachmentValidator.js +284 -288
- package/src/utilities/authCache.js.backup-1779570472481 +121 -121
- package/src/utilities/browserStealth.js +631 -630
- package/src/utilities/configManager.js +616 -617
- package/src/utilities/directoryAccessManager.js +564 -565
- package/src/utilities/fileProcessor.js +308 -307
- package/src/utilities/humanBehavior.js +454 -453
- package/src/utilities/logger.js +479 -479
- package/src/utilities/structuredFileValidator.js +696 -699
- package/src/utilities/tagParser.js +5 -10
- package/src/utilities/userDataDir.js +308 -308
- package/node_modules/@isaacs/brace-expansion/dist/commonjs/index.js.map +0 -1
- package/node_modules/@isaacs/brace-expansion/dist/esm/index.js.map +0 -1
- package/node_modules/minipass/LICENSE +0 -15
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/LICENSE.md +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.d.ts +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.d.ts.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.js +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.js.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/package.json +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.d.ts +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.d.ts.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.js +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.js.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/package.json +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/LICENSE +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/index.d.ts +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/index.d.ts.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/package.json +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/index.d.ts +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/index.d.ts.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/package.json +0 -0
|
@@ -1,955 +1,954 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MessageProcessor - Processes messages from agents, extracts tool commands, executes tools
|
|
3
|
-
*
|
|
4
|
-
* NEW ARCHITECTURE:
|
|
5
|
-
* - Only handles message queuing and tool execution
|
|
6
|
-
* - No scheduling or autonomous loops (handled by AgentScheduler)
|
|
7
|
-
* - Clean separation of concerns
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* @param {string}
|
|
76
|
-
* @param {
|
|
77
|
-
* @
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
let
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
// of the
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* @
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* @
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
console.log('MessageProcessor DEBUG:
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
*
|
|
409
|
-
* @param {
|
|
410
|
-
* @
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
let
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
//
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
//
|
|
465
|
-
//
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
//
|
|
472
|
-
//
|
|
473
|
-
//
|
|
474
|
-
//
|
|
475
|
-
// toolConfig
|
|
476
|
-
//
|
|
477
|
-
//
|
|
478
|
-
//
|
|
479
|
-
//
|
|
480
|
-
//
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
//
|
|
514
|
-
//
|
|
515
|
-
//
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
* @param {Object}
|
|
557
|
-
* @param {Object}
|
|
558
|
-
* @
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
//
|
|
579
|
-
//
|
|
580
|
-
// {
|
|
581
|
-
// {
|
|
582
|
-
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
const
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
//
|
|
605
|
-
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
versions.
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
*
|
|
649
|
-
* @param {Object}
|
|
650
|
-
* @param {Object}
|
|
651
|
-
* @
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
//
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
//
|
|
692
|
-
//
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
operation.
|
|
701
|
-
operation.
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
operation.
|
|
707
|
-
operation.
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
*
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
operation.
|
|
748
|
-
operation.
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
*
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
//
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
*
|
|
800
|
-
* @
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
*
|
|
826
|
-
*
|
|
827
|
-
* @param {string}
|
|
828
|
-
* @param {
|
|
829
|
-
* @
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
//
|
|
852
|
-
//
|
|
853
|
-
//
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
*
|
|
881
|
-
*
|
|
882
|
-
* @
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
*
|
|
898
|
-
* @param {
|
|
899
|
-
* @
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
agent.
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
*
|
|
937
|
-
* @
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1
|
+
/**
|
|
2
|
+
* MessageProcessor - Processes messages from agents, extracts tool commands, executes tools
|
|
3
|
+
*
|
|
4
|
+
* NEW ARCHITECTURE:
|
|
5
|
+
* - Only handles message queuing and tool execution
|
|
6
|
+
* - No scheduling or autonomous loops (handled by AgentScheduler)
|
|
7
|
+
* - Clean separation of concerns
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import TagParser from '../utilities/tagParser.js';
|
|
11
|
+
import { TOOL_IDS, COMMAND_FORMATS } from '../utilities/toolConstants.js';
|
|
12
|
+
import { getVisualEditorBridge } from '../services/visualEditorBridge.js';
|
|
13
|
+
import { VisualEditorTool } from '../tools/visualEditorTool.js';
|
|
14
|
+
import { prependSourceHeader } from '../services/messageSource.js';
|
|
15
|
+
|
|
16
|
+
class MessageProcessor {
|
|
17
|
+
constructor(config, logger, toolsRegistry, agentPool, contextManager, aiService, modelRouterService = null, modelsService = null) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.logger = logger;
|
|
20
|
+
this.toolsRegistry = toolsRegistry;
|
|
21
|
+
this.agentPool = agentPool;
|
|
22
|
+
this.contextManager = contextManager;
|
|
23
|
+
this.aiService = aiService;
|
|
24
|
+
this.modelRouterService = modelRouterService;
|
|
25
|
+
this.modelsService = modelsService;
|
|
26
|
+
|
|
27
|
+
// Active async operations tracking
|
|
28
|
+
this.asyncOperations = new Map();
|
|
29
|
+
|
|
30
|
+
// Tool execution history
|
|
31
|
+
this.executionHistory = new Map();
|
|
32
|
+
|
|
33
|
+
// Operation ID counter
|
|
34
|
+
this.operationCounter = 0;
|
|
35
|
+
|
|
36
|
+
// WebSocket manager for real-time updates
|
|
37
|
+
this.webSocketManager = null;
|
|
38
|
+
|
|
39
|
+
// AgentScheduler reference
|
|
40
|
+
this.scheduler = null;
|
|
41
|
+
|
|
42
|
+
// Orchestrator reference (for backward compatibility)
|
|
43
|
+
this.orchestrator = null;
|
|
44
|
+
|
|
45
|
+
// Initialize TagParser for comprehensive tool command extraction
|
|
46
|
+
this.tagParser = new TagParser();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Set WebSocket manager for real-time UI updates
|
|
51
|
+
* @param {Object} webSocketManager - WebSocket manager instance
|
|
52
|
+
*/
|
|
53
|
+
setWebSocketManager(webSocketManager) {
|
|
54
|
+
this.webSocketManager = webSocketManager;
|
|
55
|
+
this.logger?.info('WebSocket manager set for MessageProcessor', {
|
|
56
|
+
hasManager: !!webSocketManager
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Set AgentScheduler reference
|
|
62
|
+
* @param {AgentScheduler} scheduler - AgentScheduler instance
|
|
63
|
+
*/
|
|
64
|
+
setScheduler(scheduler) {
|
|
65
|
+
this.scheduler = scheduler;
|
|
66
|
+
this.logger?.info('AgentScheduler set for MessageProcessor', {
|
|
67
|
+
hasScheduler: !!scheduler
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Main message processing entry point - NEW ARCHITECTURE
|
|
73
|
+
* Simply queues messages for scheduler processing
|
|
74
|
+
* @param {string} agentId - Target agent ID
|
|
75
|
+
* @param {string} message - Message content
|
|
76
|
+
* @param {Object} context - Message context
|
|
77
|
+
* @returns {Promise<Object>} Queuing result
|
|
78
|
+
*/
|
|
79
|
+
async processMessage(agentId, message, context = {}) {
|
|
80
|
+
const agent = await this.agentPool.getAgent(agentId);
|
|
81
|
+
if (!agent) {
|
|
82
|
+
throw new Error(`Agent not found: ${agentId}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const messageString = typeof message === 'string' ? message : (message ? JSON.stringify(message) : '');
|
|
86
|
+
this.logger.info(`Queueing message for agent: ${agentId}`, {
|
|
87
|
+
messageLength: messageString.length,
|
|
88
|
+
messageType: typeof message,
|
|
89
|
+
isInterAgentMessage: context.isInterAgentMessage,
|
|
90
|
+
contextMessageType: context.messageType || 'user'
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Determine message type and queue appropriately
|
|
94
|
+
if (context.isInterAgentMessage) {
|
|
95
|
+
// Inter-agent message
|
|
96
|
+
await this.agentPool.addInterAgentMessage(agentId, {
|
|
97
|
+
content: message,
|
|
98
|
+
sender: context.originalSender,
|
|
99
|
+
senderName: context.senderName,
|
|
100
|
+
subject: context.subject || 'Inter-agent message',
|
|
101
|
+
timestamp: new Date().toISOString(),
|
|
102
|
+
sessionId: context.sessionId,
|
|
103
|
+
requiresReply: context.requiresReply || false
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
// User message
|
|
107
|
+
// Phase 4: Inject visual context if available
|
|
108
|
+
let enhancedMessage = message;
|
|
109
|
+
let visualContextInjected = false;
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
const bridge = getVisualEditorBridge();
|
|
113
|
+
if (bridge.isEnabled() && bridge.hasInstance(agentId)) {
|
|
114
|
+
const visualContext = bridge.getVisualContext(agentId);
|
|
115
|
+
if (visualContext) {
|
|
116
|
+
enhancedMessage = VisualEditorTool.injectContextIntoMessage(message, visualContext);
|
|
117
|
+
visualContextInjected = true;
|
|
118
|
+
|
|
119
|
+
this.logger.info(`Visual context injected for agent: ${agentId}`, {
|
|
120
|
+
selector: visualContext.selector,
|
|
121
|
+
sourceFile: visualContext.sourceHint?.file
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Clear context after injection (configurable)
|
|
125
|
+
if (this.config.visualEditor?.clearContextAfterInjection !== false) {
|
|
126
|
+
bridge.clearVisualContext(agentId);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} catch (err) {
|
|
131
|
+
// Visual context injection is optional - don't fail the message
|
|
132
|
+
this.logger.warn?.(`Failed to inject visual context: ${err.message}`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Prepend the source attribution header when the message arrived from
|
|
136
|
+
// an external channel (Discord / Telegram). The header is plain text
|
|
137
|
+
// of the form "(Message by alice from Discord > MyGuild > #ops)" and
|
|
138
|
+
// becomes part of the persisted content, so the agent sees it in its
|
|
139
|
+
// LLM context and the operator sees it in the web-UI transcript. The
|
|
140
|
+
// operation is idempotent — re-serialization (state restore, replay)
|
|
141
|
+
// won't double-prefix. Sources of kind web/api/internal produce no
|
|
142
|
+
// header and leave the content untouched. See services/messageSource.js.
|
|
143
|
+
if (context.source) {
|
|
144
|
+
enhancedMessage = prependSourceHeader(enhancedMessage, context.source);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
await this.agentPool.addUserMessage(agentId, {
|
|
148
|
+
content: enhancedMessage,
|
|
149
|
+
role: 'user',
|
|
150
|
+
timestamp: new Date().toISOString(),
|
|
151
|
+
contextReferences: context.contextReferences || [],
|
|
152
|
+
sessionId: context.sessionId,
|
|
153
|
+
visualContextInjected,
|
|
154
|
+
streamingEnabled: context.streamingEnabled !== false, // Pass streaming preference from context
|
|
155
|
+
// Preserve the structured source on the queued message too, so any
|
|
156
|
+
// downstream consumer (logs, analytics, relay) can reason about
|
|
157
|
+
// provenance without re-parsing the inline header.
|
|
158
|
+
source: context.source || null,
|
|
159
|
+
// Flow execution context (if this message is part of a flow)
|
|
160
|
+
isFlowExecution: context.isFlowExecution || false,
|
|
161
|
+
flowRunId: context.flowRunId,
|
|
162
|
+
flowNodeId: context.flowNodeId,
|
|
163
|
+
flowMetadata: context.flowMetadata,
|
|
164
|
+
previousAgentData: context.previousAgentData,
|
|
165
|
+
// v2: typed I/O contract for this node — { inputs, outputs }.
|
|
166
|
+
// Forwarded to the scheduler so the system prompt can advertise
|
|
167
|
+
// the exact named/typed payload the agent must produce.
|
|
168
|
+
nodeContract: context.nodeContract
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Register session with scheduler for API key resolution
|
|
173
|
+
// NOTE: The scheduler uses AgentActivityService to determine which agents
|
|
174
|
+
// should be active based on their message queues - we just register the session here
|
|
175
|
+
if (this.scheduler) {
|
|
176
|
+
await this.scheduler.addAgent(agentId, {
|
|
177
|
+
triggeredBy: context.isInterAgentMessage ? 'inter-agent-message' : 'user-message',
|
|
178
|
+
sessionId: context.sessionId
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
success: true,
|
|
184
|
+
message: 'Message queued for processing',
|
|
185
|
+
agentId: agentId,
|
|
186
|
+
queuedAt: new Date().toISOString()
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Unwrap TagParser format parameters
|
|
192
|
+
* TagParser wraps XML parameters in {value, attributes} objects
|
|
193
|
+
* This method unwraps them to direct values for tool consumption
|
|
194
|
+
* @param {Object} params - Parameters to unwrap
|
|
195
|
+
* @returns {Object} Unwrapped parameters
|
|
196
|
+
*/
|
|
197
|
+
unwrapParameters(params) {
|
|
198
|
+
if (!params || typeof params !== 'object') {
|
|
199
|
+
return params;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Handle arrays - recursively unwrap each element
|
|
203
|
+
if (Array.isArray(params)) {
|
|
204
|
+
return params.map(item => this.unwrapParameters(item));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Check if this is a wrapped value: {value: "...", attributes: {}}
|
|
208
|
+
if ('value' in params && 'attributes' in params && Object.keys(params).length === 2) {
|
|
209
|
+
// This is a wrapped value, return just the value (recursively unwrapped)
|
|
210
|
+
return this.unwrapParameters(params.value);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Regular object - unwrap each property recursively
|
|
214
|
+
const unwrapped = {};
|
|
215
|
+
for (const [key, value] of Object.entries(params)) {
|
|
216
|
+
if (value && typeof value === 'object') {
|
|
217
|
+
if ('value' in value && 'attributes' in value && Object.keys(value).length === 2) {
|
|
218
|
+
// TagParser wrapped format: {value: "...", attributes: {}}
|
|
219
|
+
unwrapped[key] = this.unwrapParameters(value.value);
|
|
220
|
+
|
|
221
|
+
// Also preserve attributes if tool needs them
|
|
222
|
+
if (value.attributes && Object.keys(value.attributes).length > 0) {
|
|
223
|
+
unwrapped[`${key}_attributes`] = value.attributes;
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
// Recursively unwrap nested objects/arrays
|
|
227
|
+
unwrapped[key] = this.unwrapParameters(value);
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
// Primitive value - keep as-is
|
|
231
|
+
unwrapped[key] = value;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return unwrapped;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Extract tool commands from message content
|
|
240
|
+
* Supports multiple formats: XML, JSON, and simple bracket notation
|
|
241
|
+
* @param {string} message - Message containing tool commands
|
|
242
|
+
* @returns {Promise<Array>} Array of tool commands
|
|
243
|
+
*/
|
|
244
|
+
async extractToolCommands(message) {
|
|
245
|
+
const commands = [];
|
|
246
|
+
|
|
247
|
+
// Use TagParser to extract XML and JSON format commands
|
|
248
|
+
const tagParserCommands = this.tagParser.extractToolCommands(message);
|
|
249
|
+
|
|
250
|
+
// Process TagParser commands and normalize them
|
|
251
|
+
for (const cmd of tagParserCommands) {
|
|
252
|
+
const normalized = this.tagParser.normalizeToolCommand(cmd);
|
|
253
|
+
commands.push({
|
|
254
|
+
toolId: normalized.toolId,
|
|
255
|
+
content: JSON.stringify(normalized.parameters), // Convert parameters to JSON string for tool execution
|
|
256
|
+
parameters: normalized.parameters,
|
|
257
|
+
type: normalized.type,
|
|
258
|
+
isAsync: normalized.parameters?.async === true,
|
|
259
|
+
raw: normalized.rawContent,
|
|
260
|
+
position: cmd.position || {}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Also check for simple bracket notation [tool id="..."] for backward compatibility
|
|
265
|
+
const toolPattern = /\[tool\s+id="([^"]+)"(?:\s+async="(true|false)")?\]([\s\S]*?)\[\/tool\]/gi;
|
|
266
|
+
|
|
267
|
+
console.log('MessageProcessor DEBUG: checking bracket pattern on message length:', message.length);
|
|
268
|
+
|
|
269
|
+
let match;
|
|
270
|
+
while ((match = toolPattern.exec(message)) !== null) {
|
|
271
|
+
const [fullMatch, toolId, isAsync, content] = match;
|
|
272
|
+
|
|
273
|
+
console.log('MessageProcessor DEBUG: bracket pattern matched:', {
|
|
274
|
+
toolId: toolId.trim(),
|
|
275
|
+
contentLength: content.trim().length,
|
|
276
|
+
contentPreview: content.trim().substring(0, 100)
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// Check if this command was already extracted by TagParser
|
|
280
|
+
const alreadyExtracted = commands.some(cmd =>
|
|
281
|
+
cmd.raw === fullMatch || (cmd.position.start === match.index && cmd.position.end === match.index + fullMatch.length)
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
if (!alreadyExtracted) {
|
|
285
|
+
console.log('MessageProcessor DEBUG: adding bracket command (not already extracted by TagParser)');
|
|
286
|
+
|
|
287
|
+
const trimmedContent = content.trim();
|
|
288
|
+
|
|
289
|
+
// Check if the content inside brackets contains XML tags
|
|
290
|
+
const hasXmlTags = /<[^>]+>/g.test(trimmedContent);
|
|
291
|
+
|
|
292
|
+
if (hasXmlTags) {
|
|
293
|
+
console.log('MessageProcessor DEBUG: detected XML content inside brackets, parsing with TagParser');
|
|
294
|
+
|
|
295
|
+
// Decode HTML entities before parsing XML
|
|
296
|
+
const decodedXmlContent = this.tagParser.decodeHtmlEntities(trimmedContent);
|
|
297
|
+
console.log('MessageProcessor DEBUG: HTML decoding changed content:', trimmedContent !== decodedXmlContent);
|
|
298
|
+
|
|
299
|
+
// Parse the XML content using TagParser
|
|
300
|
+
try {
|
|
301
|
+
const xmlParameters = this.tagParser.parseXMLParameters(decodedXmlContent);
|
|
302
|
+
|
|
303
|
+
console.log('MessageProcessor DEBUG: XML parameters extracted:', Object.keys(xmlParameters));
|
|
304
|
+
|
|
305
|
+
// Check if we got valid parameters
|
|
306
|
+
if (!xmlParameters || typeof xmlParameters !== 'object') {
|
|
307
|
+
throw new Error('Invalid XML parameters returned');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Create a temporary XML command structure for normalization
|
|
311
|
+
const xmlCommand = {
|
|
312
|
+
type: COMMAND_FORMATS.XML,
|
|
313
|
+
toolId: toolId.trim(),
|
|
314
|
+
parameters: xmlParameters,
|
|
315
|
+
rawContent: decodedXmlContent
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// Normalize it to get the actions array
|
|
319
|
+
const normalized = this.tagParser.normalizeToolCommand(xmlCommand);
|
|
320
|
+
|
|
321
|
+
console.log('MessageProcessor DEBUG: normalized XML command:', {
|
|
322
|
+
toolId: normalized.toolId,
|
|
323
|
+
hasActions: !!normalized.parameters.actions,
|
|
324
|
+
actionsLength: normalized.parameters.actions?.length || 0
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// Add the properly parsed command
|
|
328
|
+
commands.push({
|
|
329
|
+
toolId: normalized.toolId,
|
|
330
|
+
content: JSON.stringify(normalized.parameters),
|
|
331
|
+
parameters: normalized.parameters,
|
|
332
|
+
type: COMMAND_FORMATS.XML, // Mark as XML since we parsed it
|
|
333
|
+
isAsync: isAsync === 'true',
|
|
334
|
+
raw: fullMatch,
|
|
335
|
+
position: {
|
|
336
|
+
start: match.index,
|
|
337
|
+
end: match.index + fullMatch.length
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
} catch (error) {
|
|
342
|
+
console.log('MessageProcessor DEBUG: XML parsing failed:', error.message);
|
|
343
|
+
console.log('MessageProcessor DEBUG: falling back to raw bracket format');
|
|
344
|
+
|
|
345
|
+
// Fall back to treating it as a simple bracket command
|
|
346
|
+
commands.push({
|
|
347
|
+
toolId: toolId.trim(),
|
|
348
|
+
content: trimmedContent,
|
|
349
|
+
type: COMMAND_FORMATS.BRACKET,
|
|
350
|
+
isAsync: isAsync === 'true',
|
|
351
|
+
raw: fullMatch,
|
|
352
|
+
position: {
|
|
353
|
+
start: match.index,
|
|
354
|
+
end: match.index + fullMatch.length
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
console.log('MessageProcessor DEBUG: no XML detected, treating as simple bracket command');
|
|
360
|
+
|
|
361
|
+
// Simple bracket command without XML content
|
|
362
|
+
commands.push({
|
|
363
|
+
toolId: toolId.trim(),
|
|
364
|
+
content: trimmedContent,
|
|
365
|
+
type: COMMAND_FORMATS.BRACKET,
|
|
366
|
+
isAsync: isAsync === 'true',
|
|
367
|
+
raw: fullMatch,
|
|
368
|
+
position: {
|
|
369
|
+
start: match.index,
|
|
370
|
+
end: match.index + fullMatch.length
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
} else {
|
|
375
|
+
console.log('MessageProcessor DEBUG: bracket command already extracted by TagParser, skipping');
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Extract agent redirects as well (for inter-agent communication)
|
|
380
|
+
const redirects = this.tagParser.extractAgentRedirects(message);
|
|
381
|
+
for (const redirect of redirects) {
|
|
382
|
+
commands.push({
|
|
383
|
+
toolId: TOOL_IDS.AGENT_COMMUNICATION,
|
|
384
|
+
content: JSON.stringify({
|
|
385
|
+
to: redirect.to,
|
|
386
|
+
message: redirect.content,
|
|
387
|
+
urgent: redirect.urgent,
|
|
388
|
+
requiresResponse: redirect.requiresResponse,
|
|
389
|
+
context: redirect.context
|
|
390
|
+
}),
|
|
391
|
+
type: COMMAND_FORMATS.REDIRECT,
|
|
392
|
+
isAsync: false,
|
|
393
|
+
raw: redirect.rawMatch,
|
|
394
|
+
position: {}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
this.logger.debug(`Extracted ${commands.length} tool commands from message`, {
|
|
399
|
+
formats: commands.map(c => c.type),
|
|
400
|
+
tools: commands.map(c => c.toolId)
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
return commands;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Execute tool commands
|
|
408
|
+
* @param {Array} commands - Array of tool commands
|
|
409
|
+
* @param {Object} context - Execution context
|
|
410
|
+
* @returns {Promise<Array>} Array of execution results
|
|
411
|
+
*/
|
|
412
|
+
async executeTools(commands, context) {
|
|
413
|
+
const results = [];
|
|
414
|
+
|
|
415
|
+
for (const command of commands) {
|
|
416
|
+
try {
|
|
417
|
+
const tool = this.toolsRegistry.getTool(command.toolId);
|
|
418
|
+
|
|
419
|
+
if (!tool) {
|
|
420
|
+
results.push({
|
|
421
|
+
toolId: command.toolId,
|
|
422
|
+
status: 'failed',
|
|
423
|
+
error: `Tool not found: ${command.toolId}`,
|
|
424
|
+
timestamp: new Date().toISOString()
|
|
425
|
+
});
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
this.logger.info(`Executing tool: ${command.toolId}`, {
|
|
430
|
+
agentId: context.agentId,
|
|
431
|
+
isAsync: command.isAsync
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
let result;
|
|
435
|
+
let toolInput = command.parameters; // Hoisted for artifact tracking access
|
|
436
|
+
if (command.isAsync) {
|
|
437
|
+
result = await this.executeAsyncTool(command, tool, context);
|
|
438
|
+
} else {
|
|
439
|
+
// Synchronous tool execution
|
|
440
|
+
// If we have parameters object, use it. Otherwise parse the content.
|
|
441
|
+
|
|
442
|
+
if (!toolInput && command.content) {
|
|
443
|
+
// Content is a string, need to parse it using tool's parseParameters method
|
|
444
|
+
if (typeof tool.parseParameters === 'function') {
|
|
445
|
+
try {
|
|
446
|
+
toolInput = tool.parseParameters(command.content);
|
|
447
|
+
this.logger?.debug(`Parsed parameters for tool: ${command.toolId}`, {
|
|
448
|
+
parsedKeys: Object.keys(toolInput)
|
|
449
|
+
});
|
|
450
|
+
} catch (error) {
|
|
451
|
+
this.logger?.warn(`Failed to parse parameters for tool: ${command.toolId}`, {
|
|
452
|
+
error: error.message
|
|
453
|
+
});
|
|
454
|
+
// Fall back to raw content
|
|
455
|
+
toolInput = command.content;
|
|
456
|
+
}
|
|
457
|
+
} else {
|
|
458
|
+
// Tool doesn't have parseParameters, use raw content
|
|
459
|
+
toolInput = command.content;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// CRITICAL FIX: Unwrap TagParser format before tool execution
|
|
464
|
+
// TagParser wraps XML parameters in {value, attributes} objects
|
|
465
|
+
// This unwrapping makes all tools work consistently
|
|
466
|
+
if (toolInput && typeof toolInput === 'object') {
|
|
467
|
+
toolInput = this.unwrapParameters(toolInput);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Pass truncation info to tool for partial execution handling.
|
|
471
|
+
// Re-derive projectDir from directoryAccess in case a previous tool
|
|
472
|
+
// (e.g. terminal change-directory) updated the working directory.
|
|
473
|
+
//
|
|
474
|
+
// toolConfig is this tool's slice of the agent's per-tool config
|
|
475
|
+
// (from agent.toolConfig[toolId]) — null when the agent didn't
|
|
476
|
+
// override anything for this tool, in which case the tool uses
|
|
477
|
+
// its global defaults. Tools that want to support per-agent
|
|
478
|
+
// config read `context.toolConfig` and merge it with their own
|
|
479
|
+
// defaults; tools that ignore it get the same behaviour as
|
|
480
|
+
// before.
|
|
481
|
+
const perToolConfig = (context.agentToolConfig && command.toolId)
|
|
482
|
+
? context.agentToolConfig[command.toolId] || null
|
|
483
|
+
: null;
|
|
484
|
+
|
|
485
|
+
const toolContext = {
|
|
486
|
+
...context,
|
|
487
|
+
projectDir: context.directoryAccess?.workingDirectory || context.projectDir,
|
|
488
|
+
toolConfig: perToolConfig,
|
|
489
|
+
wasRepaired: command.wasRepaired || false,
|
|
490
|
+
wasTruncated: command.wasTruncated || false
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
const toolResult = await tool.execute(toolInput, toolContext);
|
|
494
|
+
|
|
495
|
+
// Mark result as partial if input was truncated
|
|
496
|
+
const isPartial = command.wasTruncated || false;
|
|
497
|
+
|
|
498
|
+
result = {
|
|
499
|
+
toolId: command.toolId,
|
|
500
|
+
status: isPartial ? 'partial' : 'completed',
|
|
501
|
+
result: toolResult,
|
|
502
|
+
timestamp: new Date().toISOString(),
|
|
503
|
+
...(isPartial && {
|
|
504
|
+
warning: 'Tool executed with truncated input - AI response exceeded token limit',
|
|
505
|
+
wasTruncated: true
|
|
506
|
+
})
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
results.push(result);
|
|
511
|
+
|
|
512
|
+
// ── Artifact tracking (fire-and-forget) ─────────────────────
|
|
513
|
+
// After successful filesystem writes, persist artifact metadata
|
|
514
|
+
// on the agent object so the UI can display version history.
|
|
515
|
+
// Non-blocking: uses .catch() to avoid disrupting the tool pipeline.
|
|
516
|
+
if (result.status === 'completed' && command.toolId === TOOL_IDS.FILESYSTEM) {
|
|
517
|
+
this._trackArtifacts({ ...command, parameters: toolInput }, result, context)
|
|
518
|
+
.catch(e => this.logger?.warn?.('[Artifacts] tracking failed:', e.message));
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Store in execution history
|
|
522
|
+
const historyKey = `${context.agentId}-${Date.now()}`;
|
|
523
|
+
this.executionHistory.set(historyKey, {
|
|
524
|
+
...result,
|
|
525
|
+
agentId: context.agentId,
|
|
526
|
+
sessionId: context.sessionId
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
} catch (error) {
|
|
530
|
+
this.logger.error(`Tool execution failed: ${command.toolId}`, {
|
|
531
|
+
error: error.message,
|
|
532
|
+
agentId: context.agentId
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
results.push({
|
|
536
|
+
toolId: command.toolId,
|
|
537
|
+
status: 'failed',
|
|
538
|
+
error: error.message,
|
|
539
|
+
timestamp: new Date().toISOString()
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return results;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Track filesystem write/append operations as artifacts on the agent.
|
|
549
|
+
* Persists lightweight metadata (path, size, timestamp) and the content
|
|
550
|
+
* so the UI can show version history without re-parsing message content.
|
|
551
|
+
*
|
|
552
|
+
* The agent.artifacts map is persisted via the normal persistAgentState flow
|
|
553
|
+
* that already runs after tool execution in AgentScheduler.
|
|
554
|
+
*
|
|
555
|
+
* @param {Object} command - Tool command with parameters
|
|
556
|
+
* @param {Object} result - Execution result
|
|
557
|
+
* @param {Object} context - Execution context (agentId, projectDir)
|
|
558
|
+
* @private
|
|
559
|
+
*/
|
|
560
|
+
async _trackArtifacts(command, result, context) {
|
|
561
|
+
try {
|
|
562
|
+
const agent = await this.agentPool?.getAgent?.(context.agentId);
|
|
563
|
+
if (!agent) {
|
|
564
|
+
console.log('[Artifacts] No agent found for', context.agentId);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// Initialize artifacts map if needed: { [filePath]: { versions: [...] } }
|
|
569
|
+
if (!agent.artifacts) agent.artifacts = {};
|
|
570
|
+
|
|
571
|
+
const toolResult = result.result;
|
|
572
|
+
if (!toolResult?.success) {
|
|
573
|
+
console.log('[Artifacts] Tool result not successful:', { success: toolResult?.success, keys: Object.keys(toolResult || {}) });
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// Get the actions from the command parameters
|
|
578
|
+
// The AI may send actions at different levels depending on format:
|
|
579
|
+
// { parameters: { actions: [...] } } — parsed format
|
|
580
|
+
// { actions: [...] } — top-level format (common)
|
|
581
|
+
// { parameters: { type: 'write', ... } } — single action
|
|
582
|
+
const params = command.parameters || {};
|
|
583
|
+
const actions = params.actions || command.actions || (params.type ? [params] : []);
|
|
584
|
+
console.log('[Artifacts] Processing', actions.length, 'actions. Param keys:', Object.keys(params), 'cmd keys:', Object.keys(command));
|
|
585
|
+
const resultActions = toolResult.actions || [toolResult];
|
|
586
|
+
|
|
587
|
+
for (let i = 0; i < actions.length; i++) {
|
|
588
|
+
const action = actions[i];
|
|
589
|
+
const actionResult = resultActions[i] || {};
|
|
590
|
+
const type = action.type || action.action;
|
|
591
|
+
|
|
592
|
+
console.log(`[Artifacts] Action[${i}]:`, { type, filePath: action.filePath || action['file-path'], hasContent: !!action.content, contentLen: action.content?.length, actionKeys: Object.keys(action) });
|
|
593
|
+
|
|
594
|
+
if ((type === 'write' || type === 'append') && actionResult.success !== false) {
|
|
595
|
+
// AI uses various field names: filePath, file-path, outputPath, path
|
|
596
|
+
const rawPath = action.filePath || action['file-path'] || action.outputPath || action.path;
|
|
597
|
+
const content = action.content;
|
|
598
|
+
if (!rawPath || !content) {
|
|
599
|
+
console.log('[Artifacts] Skipped: missing filePath or content', { filePath: !!rawPath, content: !!content, actionKeys: Object.keys(action) });
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// Use the resolved absolute path as key (prevents collisions for same-name files in different dirs)
|
|
604
|
+
// Fall back to raw path if fullPath not available
|
|
605
|
+
const absolutePath = actionResult.fullPath || rawPath;
|
|
606
|
+
const artifactKey = absolutePath.replace(/\\/g, '/');
|
|
607
|
+
|
|
608
|
+
// Relative display path (strip working directory prefix)
|
|
609
|
+
const wd = (context.projectDir || '').replace(/\\/g, '/');
|
|
610
|
+
const displayPath = wd && artifactKey.startsWith(wd + '/')
|
|
611
|
+
? artifactKey.slice(wd.length + 1)
|
|
612
|
+
: artifactKey;
|
|
613
|
+
|
|
614
|
+
const version = {
|
|
615
|
+
id: `v-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
|
616
|
+
content,
|
|
617
|
+
timestamp: result.timestamp || new Date().toISOString(),
|
|
618
|
+
action: type,
|
|
619
|
+
size: Buffer.byteLength(content, 'utf8'),
|
|
620
|
+
fullPath: absolutePath,
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
if (!agent.artifacts[artifactKey]) {
|
|
624
|
+
agent.artifacts[artifactKey] = { displayPath, versions: [] };
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// Deduplicate: skip if content identical to latest
|
|
628
|
+
const versions = agent.artifacts[artifactKey].versions;
|
|
629
|
+
const latest = versions[versions.length - 1];
|
|
630
|
+
if (latest && latest.content === content) continue;
|
|
631
|
+
|
|
632
|
+
versions.push(version);
|
|
633
|
+
console.log('[Artifacts] Tracked:', displayPath, 'v' + versions.length, '(' + version.size + ' bytes)');
|
|
634
|
+
|
|
635
|
+
// Cap at 50 versions per file to keep state reasonable
|
|
636
|
+
if (versions.length > 50) {
|
|
637
|
+
versions.splice(0, versions.length - 50);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
} catch (e) {
|
|
642
|
+
this.logger?.warn?.('Artifact tracking failed (non-fatal):', e.message);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Execute async tool
|
|
648
|
+
* @param {Object} command - Tool command
|
|
649
|
+
* @param {Object} tool - Tool instance
|
|
650
|
+
* @param {Object} context - Execution context
|
|
651
|
+
* @returns {Promise<Object>} Async operation reference
|
|
652
|
+
*/
|
|
653
|
+
async executeAsyncTool(command, tool, context) {
|
|
654
|
+
const operationId = `async-${Date.now()}-${this.operationCounter++}`;
|
|
655
|
+
|
|
656
|
+
// Create async operation entry
|
|
657
|
+
const operation = {
|
|
658
|
+
id: operationId,
|
|
659
|
+
toolId: command.toolId,
|
|
660
|
+
agentId: context.agentId,
|
|
661
|
+
status: 'pending',
|
|
662
|
+
startTime: new Date().toISOString(),
|
|
663
|
+
context: context
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
this.asyncOperations.set(operationId, operation);
|
|
667
|
+
|
|
668
|
+
// Start async execution
|
|
669
|
+
// If we have parameters object, use it. Otherwise parse the content.
|
|
670
|
+
let toolInput = command.parameters;
|
|
671
|
+
|
|
672
|
+
if (!toolInput && command.content) {
|
|
673
|
+
// Content is a string, need to parse it using tool's parseParameters method
|
|
674
|
+
if (typeof tool.parseParameters === 'function') {
|
|
675
|
+
try {
|
|
676
|
+
toolInput = tool.parseParameters(command.content);
|
|
677
|
+
} catch (error) {
|
|
678
|
+
this.logger?.warn(`Failed to parse parameters for async tool: ${command.toolId}`, {
|
|
679
|
+
error: error.message
|
|
680
|
+
});
|
|
681
|
+
// Fall back to raw content
|
|
682
|
+
toolInput = command.content;
|
|
683
|
+
}
|
|
684
|
+
} else {
|
|
685
|
+
// Tool doesn't have parseParameters, use raw content
|
|
686
|
+
toolInput = command.content;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// CRITICAL FIX: Unwrap TagParser format before tool execution
|
|
691
|
+
// TagParser wraps XML parameters in {value, attributes} objects
|
|
692
|
+
// This unwrapping makes all tools work consistently
|
|
693
|
+
if (toolInput && typeof toolInput === 'object') {
|
|
694
|
+
toolInput = this.unwrapParameters(toolInput);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
tool.execute(toolInput, context)
|
|
698
|
+
.then(result => {
|
|
699
|
+
operation.status = 'completed';
|
|
700
|
+
operation.result = result;
|
|
701
|
+
operation.endTime = new Date().toISOString();
|
|
702
|
+
this.notifyAgentOfToolCompletion(operation);
|
|
703
|
+
})
|
|
704
|
+
.catch(error => {
|
|
705
|
+
operation.status = 'failed';
|
|
706
|
+
operation.error = error.message;
|
|
707
|
+
operation.endTime = new Date().toISOString();
|
|
708
|
+
this.notifyAgentOfToolCompletion(operation);
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
// Start monitoring
|
|
712
|
+
this.monitorAsyncOperation(operationId);
|
|
713
|
+
|
|
714
|
+
return {
|
|
715
|
+
toolId: command.toolId,
|
|
716
|
+
status: 'async-pending',
|
|
717
|
+
operationId: operationId,
|
|
718
|
+
message: `Async tool started with operation ID: ${operationId}`,
|
|
719
|
+
timestamp: new Date().toISOString()
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Monitor async operation
|
|
725
|
+
* @param {string} operationId - Operation ID to monitor
|
|
726
|
+
*/
|
|
727
|
+
async monitorAsyncOperation(operationId) {
|
|
728
|
+
const checkInterval = 5000; // 5 seconds
|
|
729
|
+
const maxChecks = 120; // 10 minutes max
|
|
730
|
+
let checks = 0;
|
|
731
|
+
|
|
732
|
+
const monitor = setInterval(() => {
|
|
733
|
+
const operation = this.asyncOperations.get(operationId);
|
|
734
|
+
|
|
735
|
+
if (!operation) {
|
|
736
|
+
clearInterval(monitor);
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
checks++;
|
|
741
|
+
|
|
742
|
+
if (operation.status !== 'pending' || checks >= maxChecks) {
|
|
743
|
+
clearInterval(monitor);
|
|
744
|
+
|
|
745
|
+
if (checks >= maxChecks) {
|
|
746
|
+
operation.status = 'timeout';
|
|
747
|
+
operation.error = 'Operation timed out';
|
|
748
|
+
operation.endTime = new Date().toISOString();
|
|
749
|
+
this.notifyAgentOfToolCompletion(operation);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}, checkInterval);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Notify agent of tool completion
|
|
757
|
+
* @param {Object} operation - Completed operation
|
|
758
|
+
*/
|
|
759
|
+
async notifyAgentOfToolCompletion(operation) {
|
|
760
|
+
if (!operation.agentId) return;
|
|
761
|
+
|
|
762
|
+
try {
|
|
763
|
+
// Queue tool result for the agent
|
|
764
|
+
await this.agentPool.addToolResult(operation.agentId, {
|
|
765
|
+
toolId: operation.toolId,
|
|
766
|
+
status: operation.status,
|
|
767
|
+
result: operation.result,
|
|
768
|
+
error: operation.error,
|
|
769
|
+
executionTime: operation.endTime ?
|
|
770
|
+
new Date(operation.endTime) - new Date(operation.startTime) : null,
|
|
771
|
+
timestamp: operation.endTime || new Date().toISOString()
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
// Ensure session is registered for agent (tool results added to queue
|
|
775
|
+
// will cause agent to become active via AgentActivityService)
|
|
776
|
+
if (this.scheduler) {
|
|
777
|
+
await this.scheduler.addAgent(operation.agentId, {
|
|
778
|
+
triggeredBy: 'tool-completion',
|
|
779
|
+
sessionId: operation.context?.sessionId
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
this.logger.info(`Agent notified of tool completion: ${operation.agentId}`, {
|
|
784
|
+
toolId: operation.toolId,
|
|
785
|
+
status: operation.status
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
} catch (error) {
|
|
789
|
+
this.logger.error(`Failed to notify agent of tool completion`, {
|
|
790
|
+
agentId: operation.agentId,
|
|
791
|
+
toolId: operation.toolId,
|
|
792
|
+
error: error.message
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Get tool status
|
|
799
|
+
* @param {string} operationId - Operation ID
|
|
800
|
+
* @returns {Promise<Object>} Operation status
|
|
801
|
+
*/
|
|
802
|
+
async getToolStatus(operationId) {
|
|
803
|
+
const operation = this.asyncOperations.get(operationId);
|
|
804
|
+
|
|
805
|
+
if (!operation) {
|
|
806
|
+
return {
|
|
807
|
+
status: 'not-found',
|
|
808
|
+
error: `Operation not found: ${operationId}`
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
return {
|
|
813
|
+
id: operation.id,
|
|
814
|
+
toolId: operation.toolId,
|
|
815
|
+
status: operation.status,
|
|
816
|
+
result: operation.result,
|
|
817
|
+
error: operation.error,
|
|
818
|
+
startTime: operation.startTime,
|
|
819
|
+
endTime: operation.endTime
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Extract and execute tools from content
|
|
825
|
+
* Called by AgentScheduler after getting AI response
|
|
826
|
+
* @param {string} content - Content containing tool commands
|
|
827
|
+
* @param {string} agentId - Agent ID
|
|
828
|
+
* @param {Object} context - Execution context
|
|
829
|
+
* @returns {Promise<Array>} Tool execution results
|
|
830
|
+
*/
|
|
831
|
+
async extractAndExecuteTools(content, agentId, context) {
|
|
832
|
+
try {
|
|
833
|
+
// Extract tool commands
|
|
834
|
+
const commands = await this.extractToolCommands(content);
|
|
835
|
+
|
|
836
|
+
if (commands.length === 0) {
|
|
837
|
+
return [];
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
// Get agent to include its directoryAccess configuration
|
|
841
|
+
const agent = await this.agentPool.getAgent(agentId);
|
|
842
|
+
|
|
843
|
+
// Execute tools with agent context including sessionId and directoryAccess
|
|
844
|
+
const toolContext = {
|
|
845
|
+
...context,
|
|
846
|
+
agentId,
|
|
847
|
+
sessionId: context.sessionId, // Ensure sessionId is explicitly available for tools
|
|
848
|
+
directoryAccess: agent?.directoryAccess, // Include agent's directory access configuration
|
|
849
|
+
projectDir: agent?.directoryAccess?.workingDirectory || agent?.projectDir || context.projectDir, // Extract project directory from directoryAccess
|
|
850
|
+
// Per-agent tool configuration — keyed by tool id. Tools can read
|
|
851
|
+
// their own slice via `context.toolConfig` (injected per-tool in
|
|
852
|
+
// executeTools below) or inspect the full map here if they need
|
|
853
|
+
// cross-tool state. See agentPool.js for the schema contract.
|
|
854
|
+
agentToolConfig: (agent && agent.toolConfig) ? agent.toolConfig : {},
|
|
855
|
+
agentPool: this.agentPool,
|
|
856
|
+
contextManager: this.contextManager,
|
|
857
|
+
aiService: this.aiService,
|
|
858
|
+
messageProcessor: this,
|
|
859
|
+
orchestrator: this.orchestrator
|
|
860
|
+
};
|
|
861
|
+
|
|
862
|
+
const results = await this.executeTools(commands, toolContext);
|
|
863
|
+
|
|
864
|
+
this.logger.info(`Executed ${results.length} tools for agent: ${agentId}`, {
|
|
865
|
+
tools: results.map(r => ({ toolId: r.toolId, status: r.status }))
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
return results;
|
|
869
|
+
|
|
870
|
+
} catch (error) {
|
|
871
|
+
this.logger.error(`Tool extraction/execution failed for agent: ${agentId}`, {
|
|
872
|
+
error: error.message
|
|
873
|
+
});
|
|
874
|
+
return [];
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Stop autonomous execution for an agent
|
|
880
|
+
* Proxy method to AgentScheduler
|
|
881
|
+
* @param {string} agentId - Agent ID to stop
|
|
882
|
+
* @returns {Promise<Object>} Result with agent state
|
|
883
|
+
*/
|
|
884
|
+
async stopAutonomousExecution(agentId) {
|
|
885
|
+
if (!this.scheduler) {
|
|
886
|
+
return {
|
|
887
|
+
success: false,
|
|
888
|
+
error: 'Scheduler not available'
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
return await this.scheduler.stopAgentExecution(agentId);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Inject tool results into conversation
|
|
897
|
+
* @param {string} agentId - Agent ID
|
|
898
|
+
* @param {Array} toolResults - Tool execution results
|
|
899
|
+
* @returns {Promise<void>}
|
|
900
|
+
*/
|
|
901
|
+
async injectToolResultsIntoConversation(agentId, toolResults) {
|
|
902
|
+
const agent = await this.agentPool.getAgent(agentId);
|
|
903
|
+
if (!agent) return;
|
|
904
|
+
|
|
905
|
+
for (const result of toolResults) {
|
|
906
|
+
const toolMessage = {
|
|
907
|
+
id: `tool-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
908
|
+
role: 'system',
|
|
909
|
+
content: this.formatToolResultForAgent(result),
|
|
910
|
+
timestamp: new Date().toISOString(),
|
|
911
|
+
type: 'tool-result',
|
|
912
|
+
toolId: result.toolId,
|
|
913
|
+
status: result.status
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
// Add to conversation history
|
|
917
|
+
agent.conversations.full.messages.push(toolMessage);
|
|
918
|
+
|
|
919
|
+
// Also add to current model conversation if exists
|
|
920
|
+
if (agent.currentModel && agent.conversations[agent.currentModel]) {
|
|
921
|
+
agent.conversations[agent.currentModel].messages.push(toolMessage);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// Update last activity
|
|
926
|
+
agent.conversations.full.lastUpdated = new Date().toISOString();
|
|
927
|
+
if (agent.currentModel && agent.conversations[agent.currentModel]) {
|
|
928
|
+
agent.conversations[agent.currentModel].lastUpdated = new Date().toISOString();
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
await this.agentPool.persistAgentState(agentId);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Format tool result for agent consumption
|
|
936
|
+
* @param {Object} result - Tool execution result
|
|
937
|
+
* @returns {string} Formatted result
|
|
938
|
+
*/
|
|
939
|
+
formatToolResultForAgent(result) {
|
|
940
|
+
if (result.status === 'completed') {
|
|
941
|
+
if (typeof result.result === 'object') {
|
|
942
|
+
return `Tool ${result.toolId} completed successfully:\n${JSON.stringify(result.result, null, 2)}`;
|
|
943
|
+
}
|
|
944
|
+
return `Tool ${result.toolId} completed successfully:\n${result.result}`;
|
|
945
|
+
} else if (result.status === 'failed') {
|
|
946
|
+
return `Tool ${result.toolId} failed: ${result.error || 'Unknown error'}`;
|
|
947
|
+
} else if (result.status === 'async-pending') {
|
|
948
|
+
return `Tool ${result.toolId} is running asynchronously (Operation ID: ${result.operationId})`;
|
|
949
|
+
}
|
|
950
|
+
return `Tool ${result.toolId} status: ${result.status}`;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
|
|
955
954
|
export default MessageProcessor;
|