@loxia-labs/loxia-autopilot-one 1.0.1 → 1.0.3
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/README.md +44 -54
- package/bin/cli.js +1 -115
- package/bin/loxia-terminal-v2.js +3 -0
- package/bin/loxia-terminal.js +3 -0
- package/bin/start-with-terminal.js +3 -0
- package/package.json +14 -15
- package/scripts/install-scanners.js +1 -235
- package/src/analyzers/CSSAnalyzer.js +1 -297
- package/src/analyzers/ConfigValidator.js +1 -690
- package/src/analyzers/ESLintAnalyzer.js +1 -320
- package/src/analyzers/JavaScriptAnalyzer.js +1 -261
- package/src/analyzers/PrettierFormatter.js +1 -247
- package/src/analyzers/PythonAnalyzer.js +1 -266
- package/src/analyzers/SecurityAnalyzer.js +1 -729
- package/src/analyzers/TypeScriptAnalyzer.js +1 -247
- package/src/analyzers/codeCloneDetector/analyzer.js +1 -344
- package/src/analyzers/codeCloneDetector/detector.js +1 -203
- package/src/analyzers/codeCloneDetector/index.js +1 -160
- package/src/analyzers/codeCloneDetector/parser.js +1 -199
- package/src/analyzers/codeCloneDetector/reporter.js +1 -148
- package/src/analyzers/codeCloneDetector/scanner.js +1 -59
- package/src/core/agentPool.js +1 -1474
- package/src/core/agentScheduler.js +1 -2147
- package/src/core/contextManager.js +1 -709
- package/src/core/messageProcessor.js +1 -732
- package/src/core/orchestrator.js +1 -548
- package/src/core/stateManager.js +1 -877
- package/src/index.js +1 -631
- package/src/interfaces/cli.js +1 -549
- package/src/interfaces/terminal/__tests__/smoke/advancedFeatures.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/agentControl.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/agents.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/components.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/connection.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/enhancements.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/imports.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/messages.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/tools.test.js +1 -0
- package/src/interfaces/terminal/api/apiClient.js +1 -0
- package/src/interfaces/terminal/api/messageRouter.js +1 -0
- package/src/interfaces/terminal/api/session.js +1 -0
- package/src/interfaces/terminal/api/websocket.js +1 -0
- package/src/interfaces/terminal/components/AgentCreator.js +1 -0
- package/src/interfaces/terminal/components/AgentEditor.js +1 -0
- package/src/interfaces/terminal/components/AgentSwitcher.js +1 -0
- package/src/interfaces/terminal/components/ErrorBoundary.js +1 -0
- package/src/interfaces/terminal/components/ErrorPanel.js +1 -0
- package/src/interfaces/terminal/components/Header.js +1 -0
- package/src/interfaces/terminal/components/HelpPanel.js +1 -0
- package/src/interfaces/terminal/components/InputBox.js +1 -0
- package/src/interfaces/terminal/components/Layout.js +1 -0
- package/src/interfaces/terminal/components/LoadingSpinner.js +1 -0
- package/src/interfaces/terminal/components/MessageList.js +1 -0
- package/src/interfaces/terminal/components/MultilineTextInput.js +1 -0
- package/src/interfaces/terminal/components/SearchPanel.js +1 -0
- package/src/interfaces/terminal/components/SettingsPanel.js +1 -0
- package/src/interfaces/terminal/components/StatusBar.js +1 -0
- package/src/interfaces/terminal/components/TextInput.js +1 -0
- package/src/interfaces/terminal/config/agentEditorConstants.js +1 -0
- package/src/interfaces/terminal/config/constants.js +1 -0
- package/src/interfaces/terminal/index.js +1 -0
- package/src/interfaces/terminal/state/useAgentControl.js +1 -0
- package/src/interfaces/terminal/state/useAgents.js +1 -0
- package/src/interfaces/terminal/state/useConnection.js +1 -0
- package/src/interfaces/terminal/state/useMessages.js +1 -0
- package/src/interfaces/terminal/state/useTools.js +1 -0
- package/src/interfaces/terminal/utils/debugLogger.js +1 -0
- package/src/interfaces/terminal/utils/settingsStorage.js +1 -0
- package/src/interfaces/terminal/utils/theme.js +1 -0
- package/src/interfaces/webServer.js +1 -2162
- package/src/modules/fileExplorer/controller.js +1 -280
- package/src/modules/fileExplorer/index.js +1 -37
- package/src/modules/fileExplorer/middleware.js +1 -92
- package/src/modules/fileExplorer/routes.js +1 -125
- package/src/modules/fileExplorer/types.js +1 -44
- package/src/services/aiService.js +1 -1232
- package/src/services/apiKeyManager.js +1 -164
- package/src/services/benchmarkService.js +1 -366
- package/src/services/budgetService.js +1 -539
- package/src/services/contextInjectionService.js +1 -247
- package/src/services/conversationCompactionService.js +1 -637
- package/src/services/errorHandler.js +1 -810
- package/src/services/fileAttachmentService.js +1 -544
- package/src/services/modelRouterService.js +1 -366
- package/src/services/modelsService.js +1 -322
- package/src/services/qualityInspector.js +1 -796
- package/src/services/tokenCountingService.js +1 -536
- package/src/tools/agentCommunicationTool.js +1 -1344
- package/src/tools/agentDelayTool.js +1 -485
- package/src/tools/asyncToolManager.js +1 -604
- package/src/tools/baseTool.js +1 -800
- package/src/tools/browserTool.js +1 -920
- package/src/tools/cloneDetectionTool.js +1 -621
- package/src/tools/dependencyResolverTool.js +1 -1215
- package/src/tools/fileContentReplaceTool.js +1 -875
- package/src/tools/fileSystemTool.js +1 -1107
- package/src/tools/fileTreeTool.js +1 -853
- package/src/tools/imageTool.js +1 -901
- package/src/tools/importAnalyzerTool.js +1 -1060
- package/src/tools/jobDoneTool.js +1 -248
- package/src/tools/seekTool.js +1 -956
- package/src/tools/staticAnalysisTool.js +1 -1778
- package/src/tools/taskManagerTool.js +1 -2873
- package/src/tools/terminalTool.js +1 -2304
- package/src/tools/webTool.js +1 -1430
- package/src/types/agent.js +1 -519
- package/src/types/contextReference.js +1 -972
- package/src/types/conversation.js +1 -730
- package/src/types/toolCommand.js +1 -747
- package/src/utilities/attachmentValidator.js +1 -292
- package/src/utilities/configManager.js +1 -582
- package/src/utilities/constants.js +1 -722
- package/src/utilities/directoryAccessManager.js +1 -535
- package/src/utilities/fileProcessor.js +1 -307
- package/src/utilities/logger.js +1 -436
- package/src/utilities/tagParser.js +1 -1246
- package/src/utilities/toolConstants.js +1 -317
- package/web-ui/build/index.html +2 -2
- package/web-ui/build/static/{index-Dy2bYbOa.css → index-CClD1090.css} +1 -1
- package/web-ui/build/static/{index-CjkkcnFA.js → index-lCBai6dX.js} +66 -67
|
@@ -1,732 +1 @@
|
|
|
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 { AGENT_MODES, AGENT_MODE_STATES } from '../utilities/constants.js';
|
|
11
|
-
import TagParser from '../utilities/tagParser.js';
|
|
12
|
-
import { TOOL_IDS, COMMAND_FORMATS } from '../utilities/toolConstants.js';
|
|
13
|
-
|
|
14
|
-
class MessageProcessor {
|
|
15
|
-
constructor(config, logger, toolsRegistry, agentPool, contextManager, aiService, modelRouterService = null, modelsService = null) {
|
|
16
|
-
this.config = config;
|
|
17
|
-
this.logger = logger;
|
|
18
|
-
this.toolsRegistry = toolsRegistry;
|
|
19
|
-
this.agentPool = agentPool;
|
|
20
|
-
this.contextManager = contextManager;
|
|
21
|
-
this.aiService = aiService;
|
|
22
|
-
this.modelRouterService = modelRouterService;
|
|
23
|
-
this.modelsService = modelsService;
|
|
24
|
-
|
|
25
|
-
// Active async operations tracking
|
|
26
|
-
this.asyncOperations = new Map();
|
|
27
|
-
|
|
28
|
-
// Tool execution history
|
|
29
|
-
this.executionHistory = new Map();
|
|
30
|
-
|
|
31
|
-
// Operation ID counter
|
|
32
|
-
this.operationCounter = 0;
|
|
33
|
-
|
|
34
|
-
// WebSocket manager for real-time updates
|
|
35
|
-
this.webSocketManager = null;
|
|
36
|
-
|
|
37
|
-
// AgentScheduler reference
|
|
38
|
-
this.scheduler = null;
|
|
39
|
-
|
|
40
|
-
// Orchestrator reference (for backward compatibility)
|
|
41
|
-
this.orchestrator = null;
|
|
42
|
-
|
|
43
|
-
// Initialize TagParser for comprehensive tool command extraction
|
|
44
|
-
this.tagParser = new TagParser();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Set WebSocket manager for real-time UI updates
|
|
49
|
-
* @param {Object} webSocketManager - WebSocket manager instance
|
|
50
|
-
*/
|
|
51
|
-
setWebSocketManager(webSocketManager) {
|
|
52
|
-
this.webSocketManager = webSocketManager;
|
|
53
|
-
this.logger?.info('WebSocket manager set for MessageProcessor', {
|
|
54
|
-
hasManager: !!webSocketManager
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Set AgentScheduler reference
|
|
60
|
-
* @param {AgentScheduler} scheduler - AgentScheduler instance
|
|
61
|
-
*/
|
|
62
|
-
setScheduler(scheduler) {
|
|
63
|
-
this.scheduler = scheduler;
|
|
64
|
-
this.logger?.info('AgentScheduler set for MessageProcessor', {
|
|
65
|
-
hasScheduler: !!scheduler
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Main message processing entry point - NEW ARCHITECTURE
|
|
71
|
-
* Simply queues messages for scheduler processing
|
|
72
|
-
* @param {string} agentId - Target agent ID
|
|
73
|
-
* @param {string} message - Message content
|
|
74
|
-
* @param {Object} context - Message context
|
|
75
|
-
* @returns {Promise<Object>} Queuing result
|
|
76
|
-
*/
|
|
77
|
-
async processMessage(agentId, message, context = {}) {
|
|
78
|
-
const agent = await this.agentPool.getAgent(agentId);
|
|
79
|
-
if (!agent) {
|
|
80
|
-
throw new Error(`Agent not found: ${agentId}`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const messageString = typeof message === 'string' ? message : (message ? JSON.stringify(message) : '');
|
|
84
|
-
this.logger.info(`Queueing message for agent: ${agentId}`, {
|
|
85
|
-
messageLength: messageString.length,
|
|
86
|
-
messageType: typeof message,
|
|
87
|
-
isInterAgentMessage: context.isInterAgentMessage,
|
|
88
|
-
contextMessageType: context.messageType || 'user'
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// Determine message type and queue appropriately
|
|
92
|
-
if (context.isInterAgentMessage) {
|
|
93
|
-
// Inter-agent message
|
|
94
|
-
await this.agentPool.addInterAgentMessage(agentId, {
|
|
95
|
-
content: message,
|
|
96
|
-
sender: context.originalSender,
|
|
97
|
-
senderName: context.senderName,
|
|
98
|
-
subject: context.subject || 'Inter-agent message',
|
|
99
|
-
timestamp: new Date().toISOString(),
|
|
100
|
-
sessionId: context.sessionId,
|
|
101
|
-
requiresReply: context.requiresReply || false
|
|
102
|
-
});
|
|
103
|
-
} else {
|
|
104
|
-
// User message
|
|
105
|
-
await this.agentPool.addUserMessage(agentId, {
|
|
106
|
-
content: message,
|
|
107
|
-
role: 'user',
|
|
108
|
-
timestamp: new Date().toISOString(),
|
|
109
|
-
contextReferences: context.contextReferences || [],
|
|
110
|
-
sessionId: context.sessionId
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Add agent to scheduler if not already active
|
|
115
|
-
if (this.scheduler) {
|
|
116
|
-
await this.scheduler.addAgent(agentId, {
|
|
117
|
-
triggeredBy: context.isInterAgentMessage ? 'inter-agent-message' : 'user-message',
|
|
118
|
-
sessionId: context.sessionId
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
success: true,
|
|
124
|
-
message: 'Message queued for processing',
|
|
125
|
-
agentId: agentId,
|
|
126
|
-
queuedAt: new Date().toISOString()
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Unwrap TagParser format parameters
|
|
132
|
-
* TagParser wraps XML parameters in {value, attributes} objects
|
|
133
|
-
* This method unwraps them to direct values for tool consumption
|
|
134
|
-
* @param {Object} params - Parameters to unwrap
|
|
135
|
-
* @returns {Object} Unwrapped parameters
|
|
136
|
-
*/
|
|
137
|
-
unwrapParameters(params) {
|
|
138
|
-
if (!params || typeof params !== 'object') {
|
|
139
|
-
return params;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const unwrapped = {};
|
|
143
|
-
for (const [key, value] of Object.entries(params)) {
|
|
144
|
-
if (value && typeof value === 'object' && 'value' in value && 'attributes' in value) {
|
|
145
|
-
// TagParser wrapped format: {value: "...", attributes: {}}
|
|
146
|
-
unwrapped[key] = value.value;
|
|
147
|
-
|
|
148
|
-
// Also preserve attributes if tool needs them
|
|
149
|
-
if (value.attributes && Object.keys(value.attributes).length > 0) {
|
|
150
|
-
unwrapped[`${key}_attributes`] = value.attributes;
|
|
151
|
-
}
|
|
152
|
-
} else {
|
|
153
|
-
// Already unwrapped or direct value
|
|
154
|
-
unwrapped[key] = value;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return unwrapped;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Extract tool commands from message content
|
|
163
|
-
* Supports multiple formats: XML, JSON, and simple bracket notation
|
|
164
|
-
* @param {string} message - Message containing tool commands
|
|
165
|
-
* @returns {Promise<Array>} Array of tool commands
|
|
166
|
-
*/
|
|
167
|
-
async extractToolCommands(message) {
|
|
168
|
-
const commands = [];
|
|
169
|
-
|
|
170
|
-
// Use TagParser to extract XML and JSON format commands
|
|
171
|
-
const tagParserCommands = this.tagParser.extractToolCommands(message);
|
|
172
|
-
|
|
173
|
-
// Process TagParser commands and normalize them
|
|
174
|
-
for (const cmd of tagParserCommands) {
|
|
175
|
-
const normalized = this.tagParser.normalizeToolCommand(cmd);
|
|
176
|
-
commands.push({
|
|
177
|
-
toolId: normalized.toolId,
|
|
178
|
-
content: JSON.stringify(normalized.parameters), // Convert parameters to JSON string for tool execution
|
|
179
|
-
parameters: normalized.parameters,
|
|
180
|
-
type: normalized.type,
|
|
181
|
-
isAsync: normalized.parameters?.async === true,
|
|
182
|
-
raw: normalized.rawContent,
|
|
183
|
-
position: cmd.position || {}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Also check for simple bracket notation [tool id="..."] for backward compatibility
|
|
188
|
-
const toolPattern = /\[tool\s+id="([^"]+)"(?:\s+async="(true|false)")?\]([\s\S]*?)\[\/tool\]/gi;
|
|
189
|
-
|
|
190
|
-
console.log('MessageProcessor DEBUG: checking bracket pattern on message length:', message.length);
|
|
191
|
-
|
|
192
|
-
let match;
|
|
193
|
-
while ((match = toolPattern.exec(message)) !== null) {
|
|
194
|
-
const [fullMatch, toolId, isAsync, content] = match;
|
|
195
|
-
|
|
196
|
-
console.log('MessageProcessor DEBUG: bracket pattern matched:', {
|
|
197
|
-
toolId: toolId.trim(),
|
|
198
|
-
contentLength: content.trim().length,
|
|
199
|
-
contentPreview: content.trim().substring(0, 100)
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// Check if this command was already extracted by TagParser
|
|
203
|
-
const alreadyExtracted = commands.some(cmd =>
|
|
204
|
-
cmd.raw === fullMatch || (cmd.position.start === match.index && cmd.position.end === match.index + fullMatch.length)
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
if (!alreadyExtracted) {
|
|
208
|
-
console.log('MessageProcessor DEBUG: adding bracket command (not already extracted by TagParser)');
|
|
209
|
-
|
|
210
|
-
const trimmedContent = content.trim();
|
|
211
|
-
|
|
212
|
-
// Check if the content inside brackets contains XML tags
|
|
213
|
-
const hasXmlTags = /<[^>]+>/g.test(trimmedContent);
|
|
214
|
-
|
|
215
|
-
if (hasXmlTags) {
|
|
216
|
-
console.log('MessageProcessor DEBUG: detected XML content inside brackets, parsing with TagParser');
|
|
217
|
-
|
|
218
|
-
// Decode HTML entities before parsing XML
|
|
219
|
-
const decodedXmlContent = this.tagParser.decodeHtmlEntities(trimmedContent);
|
|
220
|
-
console.log('MessageProcessor DEBUG: HTML decoding changed content:', trimmedContent !== decodedXmlContent);
|
|
221
|
-
|
|
222
|
-
// Parse the XML content using TagParser
|
|
223
|
-
try {
|
|
224
|
-
const xmlParameters = this.tagParser.parseXMLParameters(decodedXmlContent);
|
|
225
|
-
|
|
226
|
-
console.log('MessageProcessor DEBUG: XML parameters extracted:', Object.keys(xmlParameters));
|
|
227
|
-
|
|
228
|
-
// Check if we got valid parameters
|
|
229
|
-
if (!xmlParameters || typeof xmlParameters !== 'object') {
|
|
230
|
-
throw new Error('Invalid XML parameters returned');
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Create a temporary XML command structure for normalization
|
|
234
|
-
const xmlCommand = {
|
|
235
|
-
type: COMMAND_FORMATS.XML,
|
|
236
|
-
toolId: toolId.trim(),
|
|
237
|
-
parameters: xmlParameters,
|
|
238
|
-
rawContent: decodedXmlContent
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// Normalize it to get the actions array
|
|
242
|
-
const normalized = this.tagParser.normalizeToolCommand(xmlCommand);
|
|
243
|
-
|
|
244
|
-
console.log('MessageProcessor DEBUG: normalized XML command:', {
|
|
245
|
-
toolId: normalized.toolId,
|
|
246
|
-
hasActions: !!normalized.parameters.actions,
|
|
247
|
-
actionsLength: normalized.parameters.actions?.length || 0
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
// Add the properly parsed command
|
|
251
|
-
commands.push({
|
|
252
|
-
toolId: normalized.toolId,
|
|
253
|
-
content: JSON.stringify(normalized.parameters),
|
|
254
|
-
parameters: normalized.parameters,
|
|
255
|
-
type: COMMAND_FORMATS.XML, // Mark as XML since we parsed it
|
|
256
|
-
isAsync: isAsync === 'true',
|
|
257
|
-
raw: fullMatch,
|
|
258
|
-
position: {
|
|
259
|
-
start: match.index,
|
|
260
|
-
end: match.index + fullMatch.length
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
} catch (error) {
|
|
265
|
-
console.log('MessageProcessor DEBUG: XML parsing failed:', error.message);
|
|
266
|
-
console.log('MessageProcessor DEBUG: falling back to raw bracket format');
|
|
267
|
-
|
|
268
|
-
// Fall back to treating it as a simple bracket command
|
|
269
|
-
commands.push({
|
|
270
|
-
toolId: toolId.trim(),
|
|
271
|
-
content: trimmedContent,
|
|
272
|
-
type: COMMAND_FORMATS.BRACKET,
|
|
273
|
-
isAsync: isAsync === 'true',
|
|
274
|
-
raw: fullMatch,
|
|
275
|
-
position: {
|
|
276
|
-
start: match.index,
|
|
277
|
-
end: match.index + fullMatch.length
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
} else {
|
|
282
|
-
console.log('MessageProcessor DEBUG: no XML detected, treating as simple bracket command');
|
|
283
|
-
|
|
284
|
-
// Simple bracket command without XML content
|
|
285
|
-
commands.push({
|
|
286
|
-
toolId: toolId.trim(),
|
|
287
|
-
content: trimmedContent,
|
|
288
|
-
type: COMMAND_FORMATS.BRACKET,
|
|
289
|
-
isAsync: isAsync === 'true',
|
|
290
|
-
raw: fullMatch,
|
|
291
|
-
position: {
|
|
292
|
-
start: match.index,
|
|
293
|
-
end: match.index + fullMatch.length
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
} else {
|
|
298
|
-
console.log('MessageProcessor DEBUG: bracket command already extracted by TagParser, skipping');
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Extract agent redirects as well (for inter-agent communication)
|
|
303
|
-
const redirects = this.tagParser.extractAgentRedirects(message);
|
|
304
|
-
for (const redirect of redirects) {
|
|
305
|
-
commands.push({
|
|
306
|
-
toolId: TOOL_IDS.AGENT_COMMUNICATION,
|
|
307
|
-
content: JSON.stringify({
|
|
308
|
-
to: redirect.to,
|
|
309
|
-
message: redirect.content,
|
|
310
|
-
urgent: redirect.urgent,
|
|
311
|
-
requiresResponse: redirect.requiresResponse,
|
|
312
|
-
context: redirect.context
|
|
313
|
-
}),
|
|
314
|
-
type: COMMAND_FORMATS.REDIRECT,
|
|
315
|
-
isAsync: false,
|
|
316
|
-
raw: redirect.rawMatch,
|
|
317
|
-
position: {}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
this.logger.debug(`Extracted ${commands.length} tool commands from message`, {
|
|
322
|
-
formats: commands.map(c => c.type),
|
|
323
|
-
tools: commands.map(c => c.toolId)
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
return commands;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Execute tool commands
|
|
331
|
-
* @param {Array} commands - Array of tool commands
|
|
332
|
-
* @param {Object} context - Execution context
|
|
333
|
-
* @returns {Promise<Array>} Array of execution results
|
|
334
|
-
*/
|
|
335
|
-
async executeTools(commands, context) {
|
|
336
|
-
const results = [];
|
|
337
|
-
|
|
338
|
-
for (const command of commands) {
|
|
339
|
-
try {
|
|
340
|
-
const tool = this.toolsRegistry.getTool(command.toolId);
|
|
341
|
-
|
|
342
|
-
if (!tool) {
|
|
343
|
-
results.push({
|
|
344
|
-
toolId: command.toolId,
|
|
345
|
-
status: 'failed',
|
|
346
|
-
error: `Tool not found: ${command.toolId}`,
|
|
347
|
-
timestamp: new Date().toISOString()
|
|
348
|
-
});
|
|
349
|
-
continue;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
this.logger.info(`Executing tool: ${command.toolId}`, {
|
|
353
|
-
agentId: context.agentId,
|
|
354
|
-
isAsync: command.isAsync
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
let result;
|
|
358
|
-
if (command.isAsync) {
|
|
359
|
-
result = await this.executeAsyncTool(command, tool, context);
|
|
360
|
-
} else {
|
|
361
|
-
// Synchronous tool execution
|
|
362
|
-
// If we have parameters object, use it. Otherwise parse the content.
|
|
363
|
-
let toolInput = command.parameters;
|
|
364
|
-
|
|
365
|
-
if (!toolInput && command.content) {
|
|
366
|
-
// Content is a string, need to parse it using tool's parseParameters method
|
|
367
|
-
if (typeof tool.parseParameters === 'function') {
|
|
368
|
-
try {
|
|
369
|
-
toolInput = tool.parseParameters(command.content);
|
|
370
|
-
this.logger?.debug(`Parsed parameters for tool: ${command.toolId}`, {
|
|
371
|
-
parsedKeys: Object.keys(toolInput)
|
|
372
|
-
});
|
|
373
|
-
} catch (error) {
|
|
374
|
-
this.logger?.warn(`Failed to parse parameters for tool: ${command.toolId}`, {
|
|
375
|
-
error: error.message
|
|
376
|
-
});
|
|
377
|
-
// Fall back to raw content
|
|
378
|
-
toolInput = command.content;
|
|
379
|
-
}
|
|
380
|
-
} else {
|
|
381
|
-
// Tool doesn't have parseParameters, use raw content
|
|
382
|
-
toolInput = command.content;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// CRITICAL FIX: Unwrap TagParser format before tool execution
|
|
387
|
-
// TagParser wraps XML parameters in {value, attributes} objects
|
|
388
|
-
// This unwrapping makes all tools work consistently
|
|
389
|
-
if (toolInput && typeof toolInput === 'object') {
|
|
390
|
-
toolInput = this.unwrapParameters(toolInput);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const toolResult = await tool.execute(toolInput, context);
|
|
394
|
-
result = {
|
|
395
|
-
toolId: command.toolId,
|
|
396
|
-
status: 'completed',
|
|
397
|
-
result: toolResult,
|
|
398
|
-
timestamp: new Date().toISOString()
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
results.push(result);
|
|
403
|
-
|
|
404
|
-
// Store in execution history
|
|
405
|
-
const historyKey = `${context.agentId}-${Date.now()}`;
|
|
406
|
-
this.executionHistory.set(historyKey, {
|
|
407
|
-
...result,
|
|
408
|
-
agentId: context.agentId,
|
|
409
|
-
sessionId: context.sessionId
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
} catch (error) {
|
|
413
|
-
this.logger.error(`Tool execution failed: ${command.toolId}`, {
|
|
414
|
-
error: error.message,
|
|
415
|
-
agentId: context.agentId
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
results.push({
|
|
419
|
-
toolId: command.toolId,
|
|
420
|
-
status: 'failed',
|
|
421
|
-
error: error.message,
|
|
422
|
-
timestamp: new Date().toISOString()
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
return results;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Execute async tool
|
|
432
|
-
* @param {Object} command - Tool command
|
|
433
|
-
* @param {Object} tool - Tool instance
|
|
434
|
-
* @param {Object} context - Execution context
|
|
435
|
-
* @returns {Promise<Object>} Async operation reference
|
|
436
|
-
*/
|
|
437
|
-
async executeAsyncTool(command, tool, context) {
|
|
438
|
-
const operationId = `async-${Date.now()}-${this.operationCounter++}`;
|
|
439
|
-
|
|
440
|
-
// Create async operation entry
|
|
441
|
-
const operation = {
|
|
442
|
-
id: operationId,
|
|
443
|
-
toolId: command.toolId,
|
|
444
|
-
agentId: context.agentId,
|
|
445
|
-
status: 'pending',
|
|
446
|
-
startTime: new Date().toISOString(),
|
|
447
|
-
context: context
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
this.asyncOperations.set(operationId, operation);
|
|
451
|
-
|
|
452
|
-
// Start async execution
|
|
453
|
-
// If we have parameters object, use it. Otherwise parse the content.
|
|
454
|
-
let toolInput = command.parameters;
|
|
455
|
-
|
|
456
|
-
if (!toolInput && command.content) {
|
|
457
|
-
// Content is a string, need to parse it using tool's parseParameters method
|
|
458
|
-
if (typeof tool.parseParameters === 'function') {
|
|
459
|
-
try {
|
|
460
|
-
toolInput = tool.parseParameters(command.content);
|
|
461
|
-
} catch (error) {
|
|
462
|
-
this.logger?.warn(`Failed to parse parameters for async tool: ${command.toolId}`, {
|
|
463
|
-
error: error.message
|
|
464
|
-
});
|
|
465
|
-
// Fall back to raw content
|
|
466
|
-
toolInput = command.content;
|
|
467
|
-
}
|
|
468
|
-
} else {
|
|
469
|
-
// Tool doesn't have parseParameters, use raw content
|
|
470
|
-
toolInput = command.content;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// CRITICAL FIX: Unwrap TagParser format before tool execution
|
|
475
|
-
// TagParser wraps XML parameters in {value, attributes} objects
|
|
476
|
-
// This unwrapping makes all tools work consistently
|
|
477
|
-
if (toolInput && typeof toolInput === 'object') {
|
|
478
|
-
toolInput = this.unwrapParameters(toolInput);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
tool.execute(toolInput, context)
|
|
482
|
-
.then(result => {
|
|
483
|
-
operation.status = 'completed';
|
|
484
|
-
operation.result = result;
|
|
485
|
-
operation.endTime = new Date().toISOString();
|
|
486
|
-
this.notifyAgentOfToolCompletion(operation);
|
|
487
|
-
})
|
|
488
|
-
.catch(error => {
|
|
489
|
-
operation.status = 'failed';
|
|
490
|
-
operation.error = error.message;
|
|
491
|
-
operation.endTime = new Date().toISOString();
|
|
492
|
-
this.notifyAgentOfToolCompletion(operation);
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
// Start monitoring
|
|
496
|
-
this.monitorAsyncOperation(operationId);
|
|
497
|
-
|
|
498
|
-
return {
|
|
499
|
-
toolId: command.toolId,
|
|
500
|
-
status: 'async-pending',
|
|
501
|
-
operationId: operationId,
|
|
502
|
-
message: `Async tool started with operation ID: ${operationId}`,
|
|
503
|
-
timestamp: new Date().toISOString()
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Monitor async operation
|
|
509
|
-
* @param {string} operationId - Operation ID to monitor
|
|
510
|
-
*/
|
|
511
|
-
async monitorAsyncOperation(operationId) {
|
|
512
|
-
const checkInterval = 5000; // 5 seconds
|
|
513
|
-
const maxChecks = 120; // 10 minutes max
|
|
514
|
-
let checks = 0;
|
|
515
|
-
|
|
516
|
-
const monitor = setInterval(() => {
|
|
517
|
-
const operation = this.asyncOperations.get(operationId);
|
|
518
|
-
|
|
519
|
-
if (!operation) {
|
|
520
|
-
clearInterval(monitor);
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
checks++;
|
|
525
|
-
|
|
526
|
-
if (operation.status !== 'pending' || checks >= maxChecks) {
|
|
527
|
-
clearInterval(monitor);
|
|
528
|
-
|
|
529
|
-
if (checks >= maxChecks) {
|
|
530
|
-
operation.status = 'timeout';
|
|
531
|
-
operation.error = 'Operation timed out';
|
|
532
|
-
operation.endTime = new Date().toISOString();
|
|
533
|
-
this.notifyAgentOfToolCompletion(operation);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}, checkInterval);
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* Notify agent of tool completion
|
|
541
|
-
* @param {Object} operation - Completed operation
|
|
542
|
-
*/
|
|
543
|
-
async notifyAgentOfToolCompletion(operation) {
|
|
544
|
-
if (!operation.agentId) return;
|
|
545
|
-
|
|
546
|
-
try {
|
|
547
|
-
// Queue tool result for the agent
|
|
548
|
-
await this.agentPool.addToolResult(operation.agentId, {
|
|
549
|
-
toolId: operation.toolId,
|
|
550
|
-
status: operation.status,
|
|
551
|
-
result: operation.result,
|
|
552
|
-
error: operation.error,
|
|
553
|
-
executionTime: operation.endTime ?
|
|
554
|
-
new Date(operation.endTime) - new Date(operation.startTime) : null,
|
|
555
|
-
timestamp: operation.endTime || new Date().toISOString()
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
// Add agent back to scheduler if needed
|
|
559
|
-
if (this.scheduler) {
|
|
560
|
-
await this.scheduler.addAgent(operation.agentId, {
|
|
561
|
-
triggeredBy: 'tool-completion',
|
|
562
|
-
sessionId: operation.context?.sessionId
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
this.logger.info(`Agent notified of tool completion: ${operation.agentId}`, {
|
|
567
|
-
toolId: operation.toolId,
|
|
568
|
-
status: operation.status
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
} catch (error) {
|
|
572
|
-
this.logger.error(`Failed to notify agent of tool completion`, {
|
|
573
|
-
agentId: operation.agentId,
|
|
574
|
-
toolId: operation.toolId,
|
|
575
|
-
error: error.message
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* Get tool status
|
|
582
|
-
* @param {string} operationId - Operation ID
|
|
583
|
-
* @returns {Promise<Object>} Operation status
|
|
584
|
-
*/
|
|
585
|
-
async getToolStatus(operationId) {
|
|
586
|
-
const operation = this.asyncOperations.get(operationId);
|
|
587
|
-
|
|
588
|
-
if (!operation) {
|
|
589
|
-
return {
|
|
590
|
-
status: 'not-found',
|
|
591
|
-
error: `Operation not found: ${operationId}`
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
return {
|
|
596
|
-
id: operation.id,
|
|
597
|
-
toolId: operation.toolId,
|
|
598
|
-
status: operation.status,
|
|
599
|
-
result: operation.result,
|
|
600
|
-
error: operation.error,
|
|
601
|
-
startTime: operation.startTime,
|
|
602
|
-
endTime: operation.endTime
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* Extract and execute tools from content
|
|
608
|
-
* Called by AgentScheduler after getting AI response
|
|
609
|
-
* @param {string} content - Content containing tool commands
|
|
610
|
-
* @param {string} agentId - Agent ID
|
|
611
|
-
* @param {Object} context - Execution context
|
|
612
|
-
* @returns {Promise<Array>} Tool execution results
|
|
613
|
-
*/
|
|
614
|
-
async extractAndExecuteTools(content, agentId, context) {
|
|
615
|
-
try {
|
|
616
|
-
// Extract tool commands
|
|
617
|
-
const commands = await this.extractToolCommands(content);
|
|
618
|
-
|
|
619
|
-
if (commands.length === 0) {
|
|
620
|
-
return [];
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
// Get agent to include its directoryAccess configuration
|
|
624
|
-
const agent = await this.agentPool.getAgent(agentId);
|
|
625
|
-
|
|
626
|
-
// Execute tools with agent context including sessionId and directoryAccess
|
|
627
|
-
const toolContext = {
|
|
628
|
-
...context,
|
|
629
|
-
agentId,
|
|
630
|
-
sessionId: context.sessionId, // Ensure sessionId is explicitly available for tools
|
|
631
|
-
directoryAccess: agent?.directoryAccess, // Include agent's directory access configuration
|
|
632
|
-
projectDir: agent?.directoryAccess?.workingDirectory || agent?.projectDir || context.projectDir, // Extract project directory from directoryAccess
|
|
633
|
-
agentPool: this.agentPool,
|
|
634
|
-
contextManager: this.contextManager,
|
|
635
|
-
aiService: this.aiService,
|
|
636
|
-
messageProcessor: this,
|
|
637
|
-
orchestrator: this.orchestrator
|
|
638
|
-
};
|
|
639
|
-
|
|
640
|
-
const results = await this.executeTools(commands, toolContext);
|
|
641
|
-
|
|
642
|
-
this.logger.info(`Executed ${results.length} tools for agent: ${agentId}`, {
|
|
643
|
-
tools: results.map(r => ({ toolId: r.toolId, status: r.status }))
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
return results;
|
|
647
|
-
|
|
648
|
-
} catch (error) {
|
|
649
|
-
this.logger.error(`Tool extraction/execution failed for agent: ${agentId}`, {
|
|
650
|
-
error: error.message
|
|
651
|
-
});
|
|
652
|
-
return [];
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
* Stop autonomous execution for an agent
|
|
658
|
-
* Proxy method to AgentScheduler
|
|
659
|
-
* @param {string} agentId - Agent ID to stop
|
|
660
|
-
* @returns {Promise<Object>} Result with agent state
|
|
661
|
-
*/
|
|
662
|
-
async stopAutonomousExecution(agentId) {
|
|
663
|
-
if (!this.scheduler) {
|
|
664
|
-
return {
|
|
665
|
-
success: false,
|
|
666
|
-
error: 'Scheduler not available'
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
return await this.scheduler.stopAgentExecution(agentId);
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* Inject tool results into conversation
|
|
675
|
-
* @param {string} agentId - Agent ID
|
|
676
|
-
* @param {Array} toolResults - Tool execution results
|
|
677
|
-
* @returns {Promise<void>}
|
|
678
|
-
*/
|
|
679
|
-
async injectToolResultsIntoConversation(agentId, toolResults) {
|
|
680
|
-
const agent = await this.agentPool.getAgent(agentId);
|
|
681
|
-
if (!agent) return;
|
|
682
|
-
|
|
683
|
-
for (const result of toolResults) {
|
|
684
|
-
const toolMessage = {
|
|
685
|
-
id: `tool-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
686
|
-
role: 'system',
|
|
687
|
-
content: this.formatToolResultForAgent(result),
|
|
688
|
-
timestamp: new Date().toISOString(),
|
|
689
|
-
type: 'tool-result',
|
|
690
|
-
toolId: result.toolId,
|
|
691
|
-
status: result.status
|
|
692
|
-
};
|
|
693
|
-
|
|
694
|
-
// Add to conversation history
|
|
695
|
-
agent.conversations.full.messages.push(toolMessage);
|
|
696
|
-
|
|
697
|
-
// Also add to current model conversation if exists
|
|
698
|
-
if (agent.currentModel && agent.conversations[agent.currentModel]) {
|
|
699
|
-
agent.conversations[agent.currentModel].messages.push(toolMessage);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// Update last activity
|
|
704
|
-
agent.conversations.full.lastUpdated = new Date().toISOString();
|
|
705
|
-
if (agent.currentModel && agent.conversations[agent.currentModel]) {
|
|
706
|
-
agent.conversations[agent.currentModel].lastUpdated = new Date().toISOString();
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
await this.agentPool.persistAgentState(agentId);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
/**
|
|
713
|
-
* Format tool result for agent consumption
|
|
714
|
-
* @param {Object} result - Tool execution result
|
|
715
|
-
* @returns {string} Formatted result
|
|
716
|
-
*/
|
|
717
|
-
formatToolResultForAgent(result) {
|
|
718
|
-
if (result.status === 'completed') {
|
|
719
|
-
if (typeof result.result === 'object') {
|
|
720
|
-
return `Tool ${result.toolId} completed successfully:\n${JSON.stringify(result.result, null, 2)}`;
|
|
721
|
-
}
|
|
722
|
-
return `Tool ${result.toolId} completed successfully:\n${result.result}`;
|
|
723
|
-
} else if (result.status === 'failed') {
|
|
724
|
-
return `Tool ${result.toolId} failed: ${result.error || 'Unknown error'}`;
|
|
725
|
-
} else if (result.status === 'async-pending') {
|
|
726
|
-
return `Tool ${result.toolId} is running asynchronously (Operation ID: ${result.operationId})`;
|
|
727
|
-
}
|
|
728
|
-
return `Tool ${result.toolId} status: ${result.status}`;
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
export default MessageProcessor;
|
|
1
|
+
const a0_0x2be6d6=a0_0x1cfc;(function(_0x20ec42,_0x1774a7){const _0xeea18c=a0_0x1cfc,_0x4b9d23=_0x20ec42();while(!![]){try{const _0x294aa4=-parseInt(_0xeea18c(0x1c5))/0x1*(-parseInt(_0xeea18c(0x20c))/0x2)+parseInt(_0xeea18c(0x22a))/0x3*(-parseInt(_0xeea18c(0x1bd))/0x4)+parseInt(_0xeea18c(0x1b5))/0x5+-parseInt(_0xeea18c(0x205))/0x6*(parseInt(_0xeea18c(0x203))/0x7)+parseInt(_0xeea18c(0x1d0))/0x8+-parseInt(_0xeea18c(0x217))/0x9*(parseInt(_0xeea18c(0x201))/0xa)+-parseInt(_0xeea18c(0x206))/0xb*(parseInt(_0xeea18c(0x1b4))/0xc);if(_0x294aa4===_0x1774a7)break;else _0x4b9d23['push'](_0x4b9d23['shift']());}catch(_0x46bbf5){_0x4b9d23['push'](_0x4b9d23['shift']());}}}(a0_0x47c6,0x7a068));import{AGENT_MODES,AGENT_MODE_STATES}from'../utilities/constants.js';import a0_0x246f71 from'../utilities/tagParser.js';function a0_0x47c6(){const _0x55b940=['Dg9VBc1Yzxn1Bhq','zw5KvgLTzq','zxHLy3v0zufZEw5Jvg9VBa','mtiYoduXmeT0wLDYBG','CMf3q29UDgvUDa','n1LdAgj4wa','BgvUz3rO','mti2ndGZme55rxzxrG','mtG2nZy5zvrNzezp','ihrVB2WGy29TBwfUzhmGzNjVBsbTzxnZywDL','ChvZAa','y29UDgv4DfjLzMvYzw5Jzxm','zw50CMLLCW','Dg9VBeLK','mJb0tuzvA2C','z2v0qwDLBNq','yxn5BMnpCgvYyxrPB25Z','uxvLDwvPBMCGBwvZC2fNzsbMB3iGywDLBNq6ia','Aw5KzxG','zM9YBwf0vg9VBfjLC3vSDezVCKfNzw50','CgvUzgLUzW','v2vIu29JA2v0ig1HBMfNzxiGC2v0igzVCIbnzxnZywDLuhjVy2vZC29Y','vg9VBca','CgvYC2LZDefNzw50u3rHDgu','CgfYC2vqyxjHBwv0zxjZ','mtH3uwPeA3q','Dw53CMfWugfYyw1LDgvYCW','BM90lwzVDw5K','vg9VBcbUB3qGzM91BMq6ia','ywrKvxnLCK1LC3nHz2u','zxH0CMfJDfrVB2XdB21Tyw5KCW','ywrKqwDLBNq','D2fYBG','C29Tzq','z2v0','DgvZDa','DhLWzq','C2v0u2nOzwr1BgvY','DMfSDwu','x2f0DhjPyNv0zxm','BwvZC2fNzq','C3vIC3rYAw5N','zgvJB2rLshrTBevUDgL0AwvZ','CMvZDwX0','ntf6qMH6sNa','zxHLy3v0Aw9UsgLZDg9YEq','BM9YBwfSAxPLvg9VBenVBw1HBMq','DhjPBq','C2vUzgvYtMfTzq','zMfPBgvK','DgfNugfYC2vY','odrbANHXruS','ndKYotKYmgzcDhbesq','yxr0CMLIDxrLCW','C3rHDhvZ','igLZihj1BM5PBMCGyxn5BMnOCM9UB3vZBhKGke9WzxjHDgLVBIbjrdOG','C3rYAw5NAwz5','B3bLCMf0Aw9Uq291BNrLCG','y3vYCMvUDe1VzgvS','vg9VBcbLEhrYywn0Aw9Ul2v4zwn1DgLVBIbMywLSzwqGzM9YigfNzw50oIa','mJiXmtq4wenUyMHW','CMfUzg9T','twvZC2fNzvbYB2nLC3nVCIberujvrZOGBM8Gwe1migrLDgvJDgvKlcb0CMvHDgLUzYbHCYbZAw1WBguGyNjHy2TLDcbJB21Tyw5K','AxnbC3LUyW','C2v0','z2v0vg9VBfn0yxr1CW','zxHLy3v0zvrVB2XZ','ywLtzxj2AwnL','ndi0odfTz0nfrLG','ywrKvg9VBfjLC3vSDa','sw50zxiTywDLBNqGBwvZC2fNzq','Bw9KzwXZu2vYDMLJzq','C2vZC2LVBKLK','zxHLy3v0zq','BwvZC2fNzvr5Cgu','zgvIDwC','y29UDMvYC2f0Aw9UCW','ywDLBNrqB29S','D2vIu29JA2v0twfUywDLCG','ndGZnda4ohneDMn0zq','CgfYyw1LDgvYCW','Dg9ju09tDhjPBMC','DgLTzw91Da','Dg9VBc1JB21WBgv0Aw9U','C3vIC3rY','C2nOzwr1BgvY','we1m','quDftLrFq09ntvvosunbveLptG','zxjYB3i','qwDLBNqGBM90igzVDw5KoIa','AxnjBNrLCKfNzw50twvZC2fNzq','y29UDgvUDa','B2jQzwn0','BgfZDfvWzgf0zwq','yxn5BMmT','DxnLCI1TzxnZywDL','twvZC2fNzvbYB2nLC3nVCIberujvrZOGyNjHy2TLDcbWyxr0zxjUig1HDgnOzwq6','ywDLBNrjza','ywrKsw50zxjbz2vUDe1LC3nHz2u','BwfW','rMfPBgvKihrVihbHCNnLihbHCMfTzxrLCNmGzM9YihrVB2W6ia','zxHLyW','Bw9UAxrVCKfZEw5Jt3bLCMf0Aw9U','Dg9VBhnszwDPC3rYEq','DxnLCG','zNvSBa','Bg9N','twvZC2fNzvbYB2nLC3nVCIberujvrZOGzgv0zwn0zwqGwe1mignVBNrLBNqGAw5ZAwrLigjYywnRzxrZlcbWyxjZAw5NihDPDgGGvgfNugfYC2vY','Bg9Nz2vY','C2v0v2vIu29JA2v0twfUywDLCG','qxn5BMmGDg9VBcbZDgfYDgvKihDPDgGGB3bLCMf0Aw9UieLeoIa','Dhj1zq','y2f0y2G','zxH0CMfJDefNzw50uMvKAxjLy3rZ','y29TCgXLDgvK','sw52ywXPzcbytuWGCgfYyw1LDgvYCYbYzxr1CM5Lza','zgLYzwn0B3j5qwnJzxnZ','Cg9ZAxrPB24','Aw5MBW','ihrVB2XZigzVCIbHz2vUDdOG','CMf3twf0y2G','B3bLCMf0Aw9Uswq','z2v0vg9VBa','BM90Awz5qwDLBNrpzLrVB2XdB21WBgv0Aw9U','ChjVAMvJDerPCG'];a0_0x47c6=function(){return _0x55b940;};return a0_0x47c6();}import{TOOL_IDS,COMMAND_FORMATS}from'../utilities/toolConstants.js';function a0_0x1cfc(_0x5de29f,_0x43a1c0){_0x5de29f=_0x5de29f-0x1b1;const _0x47c63a=a0_0x47c6();let _0x1cfc27=_0x47c63a[_0x5de29f];if(a0_0x1cfc['wgFzuG']===undefined){var _0x15dfa1=function(_0x4865a9){const _0x5eba88='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x246f71='',_0x3daf06='';for(let _0x12c0c8=0x0,_0x5e203a,_0x11ee03,_0xaa3a78=0x0;_0x11ee03=_0x4865a9['charAt'](_0xaa3a78++);~_0x11ee03&&(_0x5e203a=_0x12c0c8%0x4?_0x5e203a*0x40+_0x11ee03:_0x11ee03,_0x12c0c8++%0x4)?_0x246f71+=String['fromCharCode'](0xff&_0x5e203a>>(-0x2*_0x12c0c8&0x6)):0x0){_0x11ee03=_0x5eba88['indexOf'](_0x11ee03);}for(let _0x586b73=0x0,_0xf5b507=_0x246f71['length'];_0x586b73<_0xf5b507;_0x586b73++){_0x3daf06+='%'+('00'+_0x246f71['charCodeAt'](_0x586b73)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3daf06);};a0_0x1cfc['qZqaLD']=_0x15dfa1,a0_0x1cfc['eQwLsr']={},a0_0x1cfc['wgFzuG']=!![];}const _0x5dc5c6=_0x47c63a[0x0],_0x502e59=_0x5de29f+_0x5dc5c6,_0x30599b=a0_0x1cfc['eQwLsr'][_0x502e59];return!_0x30599b?(_0x1cfc27=a0_0x1cfc['qZqaLD'](_0x1cfc27),a0_0x1cfc['eQwLsr'][_0x502e59]=_0x1cfc27):_0x1cfc27=_0x30599b,_0x1cfc27;}class MessageProcessor{constructor(_0x3daf06,_0x12c0c8,_0x5e203a,_0x11ee03,_0xaa3a78,_0x586b73,_0xf5b507=null,_0x4019d1=null){const _0x33ddc4=a0_0x1cfc;this['config']=_0x3daf06,this[_0x33ddc4(0x1ed)]=_0x12c0c8,this[_0x33ddc4(0x1e8)]=_0x5e203a,this['agentPool']=_0x11ee03,this['contextManager']=_0xaa3a78,this[_0x33ddc4(0x1c4)]=_0x586b73,this['modelRouterService']=_0xf5b507,this[_0x33ddc4(0x1c8)]=_0x4019d1,this['asyncOperations']=new Map(),this['executionHistory']=new Map(),this['operationCounter']=0x0,this[_0x33ddc4(0x1cf)]=null,this[_0x33ddc4(0x1d6)]=null,this['orchestrator']=null,this[_0x33ddc4(0x1b3)]=new a0_0x246f71();}[a0_0x2be6d6(0x1ee)](_0x3dfb7c){const _0x17b9d7=a0_0x2be6d6;this[_0x17b9d7(0x1cf)]=_0x3dfb7c,this['logger']?.['info'](_0x17b9d7(0x213),{'hasManager':!!_0x3dfb7c});}[a0_0x2be6d6(0x223)](_0x2ae944){const _0x2e3612=a0_0x2be6d6;this[_0x2e3612(0x1d6)]=_0x2ae944,this[_0x2e3612(0x1ed)]?.[_0x2e3612(0x1f7)]('AgentScheduler\x20set\x20for\x20MessageProcessor',{'hasScheduler':!!_0x2ae944});}async['processMessage'](_0x116c42,_0x177802,_0x46b782={}){const _0x374069=a0_0x2be6d6,_0x4d302d=await this[_0x374069(0x1ce)][_0x374069(0x20d)](_0x116c42);if(!_0x4d302d)throw new Error(_0x374069(0x1da)+_0x116c42);const _0x1191ea=typeof _0x177802==='string'?_0x177802:_0x177802?JSON['stringify'](_0x177802):'';return this['logger'][_0x374069(0x1f7)](_0x374069(0x20f)+_0x116c42,{'messageLength':_0x1191ea[_0x374069(0x204)],'messageType':typeof _0x177802,'isInterAgentMessage':_0x46b782['isInterAgentMessage'],'contextMessageType':_0x46b782[_0x374069(0x1cb)]||'user'}),_0x46b782['isInterAgentMessage']?await this['agentPool'][_0x374069(0x1e3)](_0x116c42,{'content':_0x177802,'sender':_0x46b782['originalSender'],'senderName':_0x46b782[_0x374069(0x1b1)],'subject':_0x46b782['subject']||_0x374069(0x1c7),'timestamp':new Date()['toISOString'](),'sessionId':_0x46b782['sessionId'],'requiresReply':_0x46b782['requiresReply']||![]}):await this['agentPool'][_0x374069(0x21b)](_0x116c42,{'content':_0x177802,'role':_0x374069(0x1e9),'timestamp':new Date()[_0x374069(0x1d2)](),'contextReferences':_0x46b782[_0x374069(0x209)]||[],'sessionId':_0x46b782[_0x374069(0x1c9)]}),this[_0x374069(0x1d6)]&&await this['scheduler'][_0x374069(0x21d)](_0x116c42,{'triggeredBy':_0x46b782[_0x374069(0x1db)]?'inter-agent-message':_0x374069(0x1e0),'sessionId':_0x46b782['sessionId']}),{'success':!![],'message':'Message\x20queued\x20for\x20processing','agentId':_0x116c42,'queuedAt':new Date()['toISOString']()};}[a0_0x2be6d6(0x218)](_0x451ff5){const _0x1d6a77=a0_0x2be6d6;if(!_0x451ff5||typeof _0x451ff5!==_0x1d6a77(0x1dd))return _0x451ff5;const _0x132f6a={};for(const [_0x5a7190,_0x14f35d]of Object[_0x1d6a77(0x20a)](_0x451ff5)){_0x14f35d&&typeof _0x14f35d==='object'&&'value'in _0x14f35d&&_0x1d6a77(0x1b6)in _0x14f35d?(_0x132f6a[_0x5a7190]=_0x14f35d[_0x1d6a77(0x224)],_0x14f35d['attributes']&&Object['keys'](_0x14f35d['attributes'])['length']>0x0&&(_0x132f6a[_0x5a7190+_0x1d6a77(0x225)]=_0x14f35d[_0x1d6a77(0x1b6)])):_0x132f6a[_0x5a7190]=_0x14f35d;}return _0x132f6a;}async[a0_0x2be6d6(0x21c)](_0x4c8516){const _0xf7fed6=a0_0x2be6d6,_0x1da653=[],_0x51d491=this['tagParser']['extractToolCommands'](_0x4c8516);for(const _0x58b3af of _0x51d491){const _0x5972f0=this[_0xf7fed6(0x1b3)][_0xf7fed6(0x22c)](_0x58b3af);_0x1da653['push']({'toolId':_0x5972f0['toolId'],'content':JSON['stringify'](_0x5972f0[_0xf7fed6(0x1d1)]),'parameters':_0x5972f0[_0xf7fed6(0x1d1)],'type':_0x5972f0[_0xf7fed6(0x222)],'isAsync':_0x5972f0['parameters']?.['async']===!![],'raw':_0x5972f0[_0xf7fed6(0x202)],'position':_0x58b3af[_0xf7fed6(0x1f6)]||{}});}const _0x2b50f2=/\[tool\s+id="([^"]+)"(?:\s+async="(true|false)")?\]([\s\S]*?)\[\/tool\]/gi;console['log']('MessageProcessor\x20DEBUG:\x20checking\x20bracket\x20pattern\x20on\x20message\x20length:',_0x4c8516['length']);let _0x13e1b7;while((_0x13e1b7=_0x2b50f2[_0xf7fed6(0x1e6)](_0x4c8516))!==null){const [_0x38fdab,_0x52b4a9,_0x10a017,_0x121292]=_0x13e1b7;console['log'](_0xf7fed6(0x1e1),{'toolId':_0x52b4a9[_0xf7fed6(0x22d)](),'contentLength':_0x121292[_0xf7fed6(0x22d)]()['length'],'contentPreview':_0x121292[_0xf7fed6(0x22d)]()[_0xf7fed6(0x227)](0x0,0x64)});const _0x131258=_0x1da653[_0xf7fed6(0x21f)](_0x3286fc=>_0x3286fc['raw']===_0x38fdab||_0x3286fc[_0xf7fed6(0x1f6)]['start']===_0x13e1b7[_0xf7fed6(0x210)]&&_0x3286fc[_0xf7fed6(0x1f6)]['end']===_0x13e1b7['index']+_0x38fdab['length']);if(!_0x131258){console[_0xf7fed6(0x1eb)]('MessageProcessor\x20DEBUG:\x20adding\x20bracket\x20command\x20(not\x20already\x20extracted\x20by\x20TagParser)');const _0x125021=_0x121292['trim'](),_0x364fb4=/<[^>]+>/g[_0xf7fed6(0x221)](_0x125021);if(_0x364fb4){console['log'](_0xf7fed6(0x1ec));const _0x83763f=this['tagParser'][_0xf7fed6(0x228)](_0x125021);console[_0xf7fed6(0x1eb)]('MessageProcessor\x20DEBUG:\x20HTML\x20decoding\x20changed\x20content:',_0x125021!==_0x83763f);try{const _0x14e159=this[_0xf7fed6(0x1b3)]['parseXMLParameters'](_0x83763f);console['log']('MessageProcessor\x20DEBUG:\x20XML\x20parameters\x20extracted:',Object['keys'](_0x14e159));if(!_0x14e159||typeof _0x14e159!=='object')throw new Error(_0xf7fed6(0x1f4));const _0x496248={'type':COMMAND_FORMATS['XML'],'toolId':_0x52b4a9['trim'](),'parameters':_0x14e159,'rawContent':_0x83763f},_0x3b6be8=this[_0xf7fed6(0x1b3)]['normalizeToolCommand'](_0x496248);console['log']('MessageProcessor\x20DEBUG:\x20normalized\x20XML\x20command:',{'toolId':_0x3b6be8[_0xf7fed6(0x20b)],'hasActions':!!_0x3b6be8[_0xf7fed6(0x1d1)]['actions'],'actionsLength':_0x3b6be8[_0xf7fed6(0x1d1)]['actions']?.[_0xf7fed6(0x204)]||0x0}),_0x1da653['push']({'toolId':_0x3b6be8['toolId'],'content':JSON[_0xf7fed6(0x1b9)](_0x3b6be8['parameters']),'parameters':_0x3b6be8['parameters'],'type':COMMAND_FORMATS[_0xf7fed6(0x1d7)],'isAsync':_0x10a017==='true','raw':_0x38fdab,'position':{'start':_0x13e1b7['index'],'end':_0x13e1b7[_0xf7fed6(0x210)]+_0x38fdab['length']}});}catch(_0x1d8121){console[_0xf7fed6(0x1eb)]('MessageProcessor\x20DEBUG:\x20XML\x20parsing\x20failed:',_0x1d8121[_0xf7fed6(0x226)]),console[_0xf7fed6(0x1eb)]('MessageProcessor\x20DEBUG:\x20falling\x20back\x20to\x20raw\x20bracket\x20format'),_0x1da653[_0xf7fed6(0x208)]({'toolId':_0x52b4a9[_0xf7fed6(0x22d)](),'content':_0x125021,'type':COMMAND_FORMATS['BRACKET'],'isAsync':_0x10a017==='true','raw':_0x38fdab,'position':{'start':_0x13e1b7['index'],'end':_0x13e1b7[_0xf7fed6(0x210)]+_0x38fdab['length']}});}}else console[_0xf7fed6(0x1eb)](_0xf7fed6(0x1bf)),_0x1da653[_0xf7fed6(0x208)]({'toolId':_0x52b4a9[_0xf7fed6(0x22d)](),'content':_0x125021,'type':COMMAND_FORMATS['BRACKET'],'isAsync':_0x10a017===_0xf7fed6(0x1f0),'raw':_0x38fdab,'position':{'start':_0x13e1b7['index'],'end':_0x13e1b7['index']+_0x38fdab[_0xf7fed6(0x204)]}});}else console[_0xf7fed6(0x1eb)]('MessageProcessor\x20DEBUG:\x20bracket\x20command\x20already\x20extracted\x20by\x20TagParser,\x20skipping');}const _0x58c59a=this[_0xf7fed6(0x1b3)][_0xf7fed6(0x1f2)](_0x4c8516);for(const _0x1ce089 of _0x58c59a){_0x1da653[_0xf7fed6(0x208)]({'toolId':TOOL_IDS[_0xf7fed6(0x1d8)],'content':JSON[_0xf7fed6(0x1b9)]({'to':_0x1ce089['to'],'message':_0x1ce089[_0xf7fed6(0x1dc)],'urgent':_0x1ce089['urgent'],'requiresResponse':_0x1ce089['requiresResponse'],'context':_0x1ce089['context']}),'type':COMMAND_FORMATS['REDIRECT'],'isAsync':![],'raw':_0x1ce089[_0xf7fed6(0x1f9)],'position':{}});}return this['logger']['debug']('Extracted\x20'+_0x1da653['length']+_0xf7fed6(0x207),{'formats':_0x1da653[_0xf7fed6(0x1e4)](_0xb0cdd7=>_0xb0cdd7[_0xf7fed6(0x222)]),'tools':_0x1da653[_0xf7fed6(0x1e4)](_0x154010=>_0x154010['toolId'])}),_0x1da653;}async['executeTools'](_0xfd1569,_0x1a6b11){const _0x5a1fda=a0_0x2be6d6,_0x1d856e=[];for(const _0x25a872 of _0xfd1569){try{const _0x158e68=this[_0x5a1fda(0x1e8)][_0x5a1fda(0x1fb)](_0x25a872[_0x5a1fda(0x20b)]);if(!_0x158e68){_0x1d856e[_0x5a1fda(0x208)]({'toolId':_0x25a872[_0x5a1fda(0x20b)],'status':_0x5a1fda(0x1b2),'error':_0x5a1fda(0x21a)+_0x25a872[_0x5a1fda(0x20b)],'timestamp':new Date()['toISOString']()});continue;}this[_0x5a1fda(0x1ed)]['info']('Executing\x20tool:\x20'+_0x25a872['toolId'],{'agentId':_0x1a6b11[_0x5a1fda(0x1e2)],'isAsync':_0x25a872[_0x5a1fda(0x1c0)]});let _0x17910f;if(_0x25a872['isAsync'])_0x17910f=await this[_0x5a1fda(0x200)](_0x25a872,_0x158e68,_0x1a6b11);else{let _0x5250ab=_0x25a872[_0x5a1fda(0x1d1)];if(!_0x5250ab&&_0x25a872['content']){if(typeof _0x158e68[_0x5a1fda(0x216)]==='function')try{_0x5250ab=_0x158e68[_0x5a1fda(0x216)](_0x25a872[_0x5a1fda(0x1dc)]),this[_0x5a1fda(0x1ed)]?.[_0x5a1fda(0x1cc)]('Parsed\x20parameters\x20for\x20tool:\x20'+_0x25a872[_0x5a1fda(0x20b)],{'parsedKeys':Object['keys'](_0x5250ab)});}catch(_0x1b34e8){this[_0x5a1fda(0x1ed)]?.[_0x5a1fda(0x21e)](_0x5a1fda(0x1e5)+_0x25a872['toolId'],{'error':_0x1b34e8[_0x5a1fda(0x226)]}),_0x5250ab=_0x25a872[_0x5a1fda(0x1dc)];}else _0x5250ab=_0x25a872[_0x5a1fda(0x1dc)];}_0x5250ab&&typeof _0x5250ab==='object'&&(_0x5250ab=this[_0x5a1fda(0x218)](_0x5250ab));const _0x3df526=await _0x158e68['execute'](_0x5250ab,_0x1a6b11);_0x17910f={'toolId':_0x25a872['toolId'],'status':_0x5a1fda(0x1f3),'result':_0x3df526,'timestamp':new Date()['toISOString']()};}_0x1d856e[_0x5a1fda(0x208)](_0x17910f);const _0x277f6e=_0x1a6b11['agentId']+'-'+Date['now']();this[_0x5a1fda(0x22b)][_0x5a1fda(0x1c1)](_0x277f6e,{..._0x17910f,'agentId':_0x1a6b11['agentId'],'sessionId':_0x1a6b11[_0x5a1fda(0x1c9)]});}catch(_0xdcad12){this[_0x5a1fda(0x1ed)]['error']('Tool\x20execution\x20failed:\x20'+_0x25a872[_0x5a1fda(0x20b)],{'error':_0xdcad12['message'],'agentId':_0x1a6b11[_0x5a1fda(0x1e2)]}),_0x1d856e[_0x5a1fda(0x208)]({'toolId':_0x25a872['toolId'],'status':_0x5a1fda(0x1b2),'error':_0xdcad12['message'],'timestamp':new Date()['toISOString']()});}}return _0x1d856e;}async['executeAsyncTool'](_0x27409e,_0x3e8746,_0x4277aa){const _0x5d3af4=a0_0x2be6d6,_0x1c0edf=_0x5d3af4(0x1df)+Date['now']()+'-'+this[_0x5d3af4(0x1ba)]++,_0x59a73f={'id':_0x1c0edf,'toolId':_0x27409e['toolId'],'agentId':_0x4277aa[_0x5d3af4(0x1e2)],'status':_0x5d3af4(0x212),'startTime':new Date()['toISOString'](),'context':_0x4277aa};this[_0x5d3af4(0x20e)]['set'](_0x1c0edf,_0x59a73f);let _0x3a9697=_0x27409e[_0x5d3af4(0x1d1)];if(!_0x3a9697&&_0x27409e[_0x5d3af4(0x1dc)]){if(typeof _0x3e8746[_0x5d3af4(0x216)]==='function')try{_0x3a9697=_0x3e8746['parseParameters'](_0x27409e['content']);}catch(_0x5c4885){this['logger']?.[_0x5d3af4(0x21e)]('Failed\x20to\x20parse\x20parameters\x20for\x20async\x20tool:\x20'+_0x27409e['toolId'],{'error':_0x5c4885[_0x5d3af4(0x226)]}),_0x3a9697=_0x27409e['content'];}else _0x3a9697=_0x27409e['content'];}return _0x3a9697&&typeof _0x3a9697===_0x5d3af4(0x1dd)&&(_0x3a9697=this[_0x5d3af4(0x218)](_0x3a9697)),_0x3e8746[_0x5d3af4(0x1ca)](_0x3a9697,_0x4277aa)['then'](_0x35b90d=>{const _0x54f357=_0x5d3af4;_0x59a73f['status']=_0x54f357(0x1f3),_0x59a73f['result']=_0x35b90d,_0x59a73f['endTime']=new Date()['toISOString'](),this[_0x54f357(0x1fc)](_0x59a73f);})[_0x5d3af4(0x1f1)](_0x4ca298=>{const _0x335326=_0x5d3af4;_0x59a73f['status']='failed',_0x59a73f[_0x335326(0x1d9)]=_0x4ca298[_0x335326(0x226)],_0x59a73f['endTime']=new Date()[_0x335326(0x1d2)](),this[_0x335326(0x1fc)](_0x59a73f);}),this['monitorAsyncOperation'](_0x1c0edf),{'toolId':_0x27409e['toolId'],'status':'async-pending','operationId':_0x1c0edf,'message':_0x5d3af4(0x1ef)+_0x1c0edf,'timestamp':new Date()['toISOString']()};}async[a0_0x2be6d6(0x1e7)](_0x5653d3){const _0x18e3eb=0x1388,_0x33327f=0x78;let _0x1380a6=0x0;const _0xa83b96=setInterval(()=>{const _0x4d37f6=a0_0x1cfc,_0x285c0a=this['asyncOperations'][_0x4d37f6(0x220)](_0x5653d3);if(!_0x285c0a){clearInterval(_0xa83b96);return;}_0x1380a6++,(_0x285c0a['status']!=='pending'||_0x1380a6>=_0x33327f)&&(clearInterval(_0xa83b96),_0x1380a6>=_0x33327f&&(_0x285c0a[_0x4d37f6(0x1b7)]=_0x4d37f6(0x1d3),_0x285c0a[_0x4d37f6(0x1d9)]='Operation\x20timed\x20out',_0x285c0a[_0x4d37f6(0x1ff)]=new Date()[_0x4d37f6(0x1d2)](),this[_0x4d37f6(0x1fc)](_0x285c0a)));},_0x18e3eb);}async['notifyAgentOfToolCompletion'](_0x11e5b7){const _0x6bd08e=a0_0x2be6d6;if(!_0x11e5b7['agentId'])return;try{await this['agentPool'][_0x6bd08e(0x1c6)](_0x11e5b7['agentId'],{'toolId':_0x11e5b7['toolId'],'status':_0x11e5b7[_0x6bd08e(0x1b7)],'result':_0x11e5b7['result'],'error':_0x11e5b7[_0x6bd08e(0x1d9)],'executionTime':_0x11e5b7['endTime']?new Date(_0x11e5b7['endTime'])-new Date(_0x11e5b7['startTime']):null,'timestamp':_0x11e5b7[_0x6bd08e(0x1ff)]||new Date()[_0x6bd08e(0x1d2)]()}),this[_0x6bd08e(0x1d6)]&&await this[_0x6bd08e(0x1d6)]['addAgent'](_0x11e5b7['agentId'],{'triggeredBy':_0x6bd08e(0x1d4),'sessionId':_0x11e5b7['context']?.[_0x6bd08e(0x1c9)]}),this['logger']['info']('Agent\x20notified\x20of\x20tool\x20completion:\x20'+_0x11e5b7['agentId'],{'toolId':_0x11e5b7[_0x6bd08e(0x20b)],'status':_0x11e5b7['status']});}catch(_0x3e3c07){this['logger'][_0x6bd08e(0x1d9)]('Failed\x20to\x20notify\x20agent\x20of\x20tool\x20completion',{'agentId':_0x11e5b7[_0x6bd08e(0x1e2)],'toolId':_0x11e5b7['toolId'],'error':_0x3e3c07[_0x6bd08e(0x226)]});}}async[a0_0x2be6d6(0x1c2)](_0x542a05){const _0x11000a=a0_0x2be6d6,_0x1cca4a=this['asyncOperations']['get'](_0x542a05);if(!_0x1cca4a)return{'status':_0x11000a(0x219),'error':'Operation\x20not\x20found:\x20'+_0x542a05};return{'id':_0x1cca4a['id'],'toolId':_0x1cca4a[_0x11000a(0x20b)],'status':_0x1cca4a['status'],'result':_0x1cca4a['result'],'error':_0x1cca4a[_0x11000a(0x1d9)],'startTime':_0x1cca4a['startTime'],'endTime':_0x1cca4a[_0x11000a(0x1ff)]};}async['extractAndExecuteTools'](_0x385f9d,_0x3e8232,_0x32bb72){const _0x28b139=a0_0x2be6d6;try{const _0x3cafda=await this[_0x28b139(0x21c)](_0x385f9d);if(_0x3cafda['length']===0x0)return[];const _0x297cbf=await this[_0x28b139(0x1ce)]['getAgent'](_0x3e8232),_0x13c079={..._0x32bb72,'agentId':_0x3e8232,'sessionId':_0x32bb72[_0x28b139(0x1c9)],'directoryAccess':_0x297cbf?.['directoryAccess'],'projectDir':_0x297cbf?.[_0x28b139(0x1f5)]?.['workingDirectory']||_0x297cbf?.[_0x28b139(0x1fd)]||_0x32bb72['projectDir'],'agentPool':this[_0x28b139(0x1ce)],'contextManager':this['contextManager'],'aiService':this['aiService'],'messageProcessor':this,'orchestrator':this['orchestrator']},_0x5d0117=await this[_0x28b139(0x1c3)](_0x3cafda,_0x13c079);return this['logger'][_0x28b139(0x1f7)]('Executed\x20'+_0x5d0117['length']+_0x28b139(0x1f8)+_0x3e8232,{'tools':_0x5d0117['map'](_0x4eb33c=>({'toolId':_0x4eb33c[_0x28b139(0x20b)],'status':_0x4eb33c[_0x28b139(0x1b7)]}))}),_0x5d0117;}catch(_0x106bec){return this['logger'][_0x28b139(0x1d9)](_0x28b139(0x1bc)+_0x3e8232,{'error':_0x106bec['message']}),[];}}async['stopAutonomousExecution'](_0x4048a4){if(!this['scheduler'])return{'success':![],'error':'Scheduler\x20not\x20available'};return await this['scheduler']['stopAgentExecution'](_0x4048a4);}async['injectToolResultsIntoConversation'](_0x5bbade,_0x344bba){const _0x1922b0=a0_0x2be6d6,_0x181a97=await this['agentPool'][_0x1922b0(0x20d)](_0x5bbade);if(!_0x181a97)return;for(const _0x46bfb0 of _0x344bba){const _0x4cf3a6={'id':'tool-'+Date['now']()+'-'+Math[_0x1922b0(0x1be)]()['toString'](0x24)[_0x1922b0(0x1d5)](0x2,0x9),'role':'system','content':this[_0x1922b0(0x211)](_0x46bfb0),'timestamp':new Date()['toISOString'](),'type':_0x1922b0(0x1fe),'toolId':_0x46bfb0[_0x1922b0(0x20b)],'status':_0x46bfb0['status']};_0x181a97[_0x1922b0(0x1cd)]['full']['messages']['push'](_0x4cf3a6),_0x181a97[_0x1922b0(0x1bb)]&&_0x181a97['conversations'][_0x181a97[_0x1922b0(0x1bb)]]&&_0x181a97[_0x1922b0(0x1cd)][_0x181a97[_0x1922b0(0x1bb)]]['messages']['push'](_0x4cf3a6);}_0x181a97[_0x1922b0(0x1cd)][_0x1922b0(0x1ea)]['lastUpdated']=new Date()['toISOString'](),_0x181a97['currentModel']&&_0x181a97[_0x1922b0(0x1cd)][_0x181a97['currentModel']]&&(_0x181a97['conversations'][_0x181a97[_0x1922b0(0x1bb)]][_0x1922b0(0x1de)]=new Date()['toISOString']()),await this['agentPool'][_0x1922b0(0x215)](_0x5bbade);}['formatToolResultForAgent'](_0x5ea904){const _0x5d6e43=a0_0x2be6d6;if(_0x5ea904['status']===_0x5d6e43(0x1f3)){if(typeof _0x5ea904['result']==='object')return _0x5d6e43(0x214)+_0x5ea904[_0x5d6e43(0x20b)]+'\x20completed\x20successfully:\x0a'+JSON['stringify'](_0x5ea904['result'],null,0x2);return _0x5d6e43(0x214)+_0x5ea904[_0x5d6e43(0x20b)]+'\x20completed\x20successfully:\x0a'+_0x5ea904[_0x5d6e43(0x229)];}else{if(_0x5ea904[_0x5d6e43(0x1b7)]==='failed')return _0x5d6e43(0x214)+_0x5ea904[_0x5d6e43(0x20b)]+'\x20failed:\x20'+(_0x5ea904[_0x5d6e43(0x1d9)]||'Unknown\x20error');else{if(_0x5ea904['status']==='async-pending')return'Tool\x20'+_0x5ea904['toolId']+_0x5d6e43(0x1b8)+_0x5ea904[_0x5d6e43(0x1fa)]+')';}}return'Tool\x20'+_0x5ea904['toolId']+'\x20status:\x20'+_0x5ea904['status'];}}export default MessageProcessor;
|