@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,366 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ModelRouterService - Uses PHI-4 to make intelligent model routing decisions
|
|
3
|
-
*
|
|
4
|
-
* Purpose:
|
|
5
|
-
* - Analyze incoming messages and conversation context
|
|
6
|
-
* - Use PHI-4 to determine optimal model for each message
|
|
7
|
-
* - Provide fallback to previous model on errors
|
|
8
|
-
* - Consider benchmark data and recent message history
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { MODEL_ROUTER_CONFIG, HTTP_STATUS, MODELS } from '../utilities/constants.js';
|
|
12
|
-
|
|
13
|
-
class ModelRouterService {
|
|
14
|
-
constructor(config, logger, benchmarkService, aiService) {
|
|
15
|
-
this.config = config;
|
|
16
|
-
this.logger = logger;
|
|
17
|
-
this.benchmarkService = benchmarkService;
|
|
18
|
-
this.aiService = aiService;
|
|
19
|
-
|
|
20
|
-
this.routerModel = MODEL_ROUTER_CONFIG.ROUTER_MODEL;
|
|
21
|
-
this.contextMessagesCount = MODEL_ROUTER_CONFIG.CONTEXT_MESSAGES_COUNT;
|
|
22
|
-
this.requestTimeout = MODEL_ROUTER_CONFIG.REQUEST_TIMEOUT;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Route message to optimal model using autopilot-model-router analysis
|
|
27
|
-
* @param {Object} message - Current message to route
|
|
28
|
-
* @param {Array} recentMessages - Recent conversation history
|
|
29
|
-
* @param {string} currentModel - Current model being used
|
|
30
|
-
* @param {Array} availableModels - Models available for routing
|
|
31
|
-
* @param {Object} context - Message context with API keys
|
|
32
|
-
* @returns {Promise<string>} Selected model name
|
|
33
|
-
*/
|
|
34
|
-
async routeMessage(message, recentMessages = [], currentModel = '', availableModels = [], context = {}) {
|
|
35
|
-
try {
|
|
36
|
-
this.logger.debug('Starting model routing analysis', {
|
|
37
|
-
messageLength: message.content?.length || 0,
|
|
38
|
-
recentMessagesCount: recentMessages.length,
|
|
39
|
-
currentModel,
|
|
40
|
-
availableModelsCount: availableModels.length
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Build context for autopilot-model-router
|
|
44
|
-
const routingContext = this._buildRoutingContext(
|
|
45
|
-
message,
|
|
46
|
-
recentMessages,
|
|
47
|
-
currentModel,
|
|
48
|
-
availableModels
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
// Get benchmark data
|
|
52
|
-
const benchmarkTable = this.benchmarkService.getBenchmarkTable();
|
|
53
|
-
|
|
54
|
-
// Create routing prompt for autopilot-model-router
|
|
55
|
-
const routingPrompt = this._createRoutingPrompt(routingContext, benchmarkTable);
|
|
56
|
-
|
|
57
|
-
// Send to autopilot-model-router for analysis
|
|
58
|
-
const routingDecision = await this._askForRouting(routingPrompt, context);
|
|
59
|
-
|
|
60
|
-
// Validate and return model selection
|
|
61
|
-
const selectedModel = this._validateModelSelection(routingDecision, availableModels, currentModel);
|
|
62
|
-
|
|
63
|
-
this.logger.info('Model routing completed', {
|
|
64
|
-
selectedModel,
|
|
65
|
-
previousModel: currentModel,
|
|
66
|
-
changed: selectedModel !== currentModel,
|
|
67
|
-
reasoning: routingDecision.reasoning?.substring(0, 100) || 'No reasoning provided'
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// Return full routing result object for AgentScheduler
|
|
71
|
-
return {
|
|
72
|
-
selectedModel,
|
|
73
|
-
previousModel: currentModel,
|
|
74
|
-
changed: selectedModel !== currentModel,
|
|
75
|
-
reasoning: routingDecision.reasoning || 'No reasoning provided'
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
} catch (error) {
|
|
79
|
-
this.logger.error('Model routing failed, falling back to current model', {
|
|
80
|
-
error: error.message,
|
|
81
|
-
currentModel
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Fallback to current model on any error
|
|
85
|
-
const fallbackModel = currentModel || availableModels[0] || MODELS.ANTHROPIC_SONNET;
|
|
86
|
-
return {
|
|
87
|
-
selectedModel: fallbackModel,
|
|
88
|
-
previousModel: currentModel,
|
|
89
|
-
changed: false,
|
|
90
|
-
reasoning: 'Routing failed, using fallback model'
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Build routing context from message and conversation history
|
|
97
|
-
* @private
|
|
98
|
-
*/
|
|
99
|
-
_buildRoutingContext(message, recentMessages, currentModel, availableModels) {
|
|
100
|
-
// Get recent messages (configurable count)
|
|
101
|
-
const contextMessages = recentMessages
|
|
102
|
-
.slice(-this.contextMessagesCount)
|
|
103
|
-
.map(msg => ({
|
|
104
|
-
role: msg.role,
|
|
105
|
-
content: msg.content?.substring(0, 500) || '', // Limit content length
|
|
106
|
-
timestamp: msg.timestamp
|
|
107
|
-
}));
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
currentMessage: {
|
|
111
|
-
content: message.content?.substring(0, 1000) || '', // Limit current message
|
|
112
|
-
role: message.role || 'user',
|
|
113
|
-
hasContextReferences: !!(message.contextReferences?.length),
|
|
114
|
-
contextTypes: message.contextReferences?.map(ref => ref.type) || []
|
|
115
|
-
},
|
|
116
|
-
recentMessages: contextMessages,
|
|
117
|
-
currentModel,
|
|
118
|
-
availableModels: availableModels.map(model => ({
|
|
119
|
-
name: model,
|
|
120
|
-
isCurrentModel: model === currentModel
|
|
121
|
-
})),
|
|
122
|
-
messageCount: recentMessages.length + 1,
|
|
123
|
-
timestamp: new Date().toISOString()
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Create routing prompt for autopilot-model-router
|
|
129
|
-
* @private
|
|
130
|
-
*/
|
|
131
|
-
_createRoutingPrompt(context, benchmarkTable) {
|
|
132
|
-
return `You are a model routing assistant. Your job is to analyze a conversation and select the optimal AI model for the next response.
|
|
133
|
-
|
|
134
|
-
## Current Situation
|
|
135
|
-
- **Current Model**: ${context.currentModel || 'None'}
|
|
136
|
-
- **Message Count**: ${context.messageCount}
|
|
137
|
-
- **Available Models**: ${context.availableModels.map(m => m.name).join(', ')}
|
|
138
|
-
|
|
139
|
-
## Recent Conversation Context
|
|
140
|
-
${this._formatRecentMessages(context.recentMessages)}
|
|
141
|
-
|
|
142
|
-
## Current Message to Route
|
|
143
|
-
**Role**: ${context.currentMessage.role}
|
|
144
|
-
**Content**: ${context.currentMessage.content}
|
|
145
|
-
**Has Context References**: ${context.currentMessage.hasContextReferences}
|
|
146
|
-
${context.currentMessage.contextTypes.length > 0 ? `**Context Types**: ${context.currentMessage.contextTypes.join(', ')}` : ''}
|
|
147
|
-
|
|
148
|
-
## Model Benchmark Data
|
|
149
|
-
${this._formatBenchmarkData(benchmarkTable)}
|
|
150
|
-
|
|
151
|
-
## Routing Decision
|
|
152
|
-
Analyze the current message and conversation context to select the best model. Consider:
|
|
153
|
-
|
|
154
|
-
1. **Task Type**: Infer from conversation content - is this coding, analysis, creative writing, or a quick task?
|
|
155
|
-
2. **Complexity**: Does it require deep reasoning or is it straightforward?
|
|
156
|
-
3. **Context**: Are there code files or technical references?
|
|
157
|
-
4. **Conversation Flow**: What has been discussed recently to understand the overall task?
|
|
158
|
-
5. **Efficiency**: Balance performance with cost/speed needs
|
|
159
|
-
|
|
160
|
-
Respond with JSON only:
|
|
161
|
-
{
|
|
162
|
-
"selectedModel": "model-name",
|
|
163
|
-
"taskType": "coding|analysis|creative|quick-tasks",
|
|
164
|
-
"confidence": 0.85,
|
|
165
|
-
"reasoning": "Brief explanation of why this model was chosen",
|
|
166
|
-
"factors": ["factor1", "factor2", "factor3"]
|
|
167
|
-
}`;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Format recent messages for prompt
|
|
172
|
-
* @private
|
|
173
|
-
*/
|
|
174
|
-
_formatRecentMessages(messages) {
|
|
175
|
-
if (!messages.length) {
|
|
176
|
-
return 'No recent messages available.';
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return messages.map((msg, i) =>
|
|
180
|
-
`${i + 1}. **${msg.role}**: ${msg.content}`
|
|
181
|
-
).join('\n');
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Format benchmark data for prompt
|
|
186
|
-
* @private
|
|
187
|
-
*/
|
|
188
|
-
_formatBenchmarkData(benchmarkTable) {
|
|
189
|
-
const models = benchmarkTable.models || [];
|
|
190
|
-
const tasks = benchmarkTable.tasks || {};
|
|
191
|
-
const summary = benchmarkTable.summary || {};
|
|
192
|
-
|
|
193
|
-
let formatted = '### Model Performance Summary\n';
|
|
194
|
-
|
|
195
|
-
// Task recommendations
|
|
196
|
-
Object.entries(tasks).forEach(([taskType, taskInfo]) => {
|
|
197
|
-
formatted += `**${taskType.toUpperCase()}** (${taskInfo.description}): ${taskInfo.topModels?.join(', ') || 'No data'}\n`;
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
formatted += '\n### Model Details\n';
|
|
201
|
-
|
|
202
|
-
// Model details (limit to available models)
|
|
203
|
-
models.slice(0, 8).forEach(model => {
|
|
204
|
-
formatted += `**${model.name}**: `;
|
|
205
|
-
const taskScores = Object.entries(model.tasks || {})
|
|
206
|
-
.map(([task, info]) => `${task}(${info.score})`)
|
|
207
|
-
.join(', ');
|
|
208
|
-
formatted += `${taskScores} | Strengths: ${model.strengths?.join(', ') || 'N/A'}\n`;
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
return formatted;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Send routing request to autopilot-model-router
|
|
216
|
-
* @private
|
|
217
|
-
*/
|
|
218
|
-
async _askForRouting(prompt, context = {}) {
|
|
219
|
-
try {
|
|
220
|
-
// Use AI service to send request to autopilot-model-router
|
|
221
|
-
const response = await this.aiService.sendMessage(
|
|
222
|
-
this.routerModel,
|
|
223
|
-
prompt,
|
|
224
|
-
{
|
|
225
|
-
agentId: 'model-router',
|
|
226
|
-
systemPrompt: 'You are a model routing expert. Analyze conversations and select optimal AI models. Always respond with valid JSON only.',
|
|
227
|
-
temperature: 0.3, // Low temperature for consistent routing decisions
|
|
228
|
-
maxTokens: 500,
|
|
229
|
-
timeout: this.requestTimeout,
|
|
230
|
-
sessionId: context.sessionId, // CRITICAL: Pass sessionId for API key retrieval
|
|
231
|
-
apiKey: context.apiKey || this.config.apiKey, // Fallback to API key from context if available
|
|
232
|
-
customApiKeys: context.customApiKeys,
|
|
233
|
-
platformProvided: true // autopilot-model-router is a platform model
|
|
234
|
-
}
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
if (!response.content) {
|
|
238
|
-
throw new Error('No response content from autopilot-model-router');
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Parse JSON response
|
|
242
|
-
const routingDecision = this._parseRoutingResponse(response.content);
|
|
243
|
-
|
|
244
|
-
return routingDecision;
|
|
245
|
-
|
|
246
|
-
} catch (error) {
|
|
247
|
-
this.logger.error('autopilot-model-router routing request failed', {
|
|
248
|
-
error: error.message,
|
|
249
|
-
routerModel: this.routerModel
|
|
250
|
-
});
|
|
251
|
-
throw error;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Parse autopilot-model-router routing response
|
|
257
|
-
* @private
|
|
258
|
-
*/
|
|
259
|
-
_parseRoutingResponse(content) {
|
|
260
|
-
try {
|
|
261
|
-
// Try to extract JSON from response
|
|
262
|
-
const jsonMatch = content.match(/\{[\s\S]*\}/);
|
|
263
|
-
if (!jsonMatch) {
|
|
264
|
-
throw new Error('No JSON found in autopilot-model-router response');
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const parsed = JSON.parse(jsonMatch[0]);
|
|
268
|
-
|
|
269
|
-
// Validate required fields
|
|
270
|
-
if (!parsed.selectedModel) {
|
|
271
|
-
throw new Error('Missing selectedModel in autopilot-model-router response');
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return {
|
|
275
|
-
selectedModel: parsed.selectedModel,
|
|
276
|
-
taskType: parsed.taskType || 'unknown',
|
|
277
|
-
confidence: parsed.confidence || 0.5,
|
|
278
|
-
reasoning: parsed.reasoning || 'No reasoning provided',
|
|
279
|
-
factors: parsed.factors || []
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
} catch (error) {
|
|
283
|
-
this.logger.warn('Failed to parse autopilot-model-router routing response', {
|
|
284
|
-
error: error.message,
|
|
285
|
-
content: content.substring(0, 200)
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
// Return default response on parse error
|
|
289
|
-
return {
|
|
290
|
-
selectedModel: null,
|
|
291
|
-
taskType: 'unknown',
|
|
292
|
-
confidence: 0.0,
|
|
293
|
-
reasoning: 'Failed to parse routing response',
|
|
294
|
-
factors: ['parsing-error']
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Validate model selection against available models
|
|
301
|
-
* @private
|
|
302
|
-
*/
|
|
303
|
-
_validateModelSelection(routingDecision, availableModels, currentModel) {
|
|
304
|
-
const { selectedModel } = routingDecision;
|
|
305
|
-
|
|
306
|
-
// If no model selected or parsing failed, use current model
|
|
307
|
-
if (!selectedModel) {
|
|
308
|
-
this.logger.debug('No model selected by router, using current model');
|
|
309
|
-
return currentModel;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// Check if selected model is available
|
|
313
|
-
if (!availableModels.includes(selectedModel)) {
|
|
314
|
-
this.logger.warn('Router selected unavailable model, using current model', {
|
|
315
|
-
selectedModel,
|
|
316
|
-
availableModels
|
|
317
|
-
});
|
|
318
|
-
return currentModel;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Model is valid
|
|
322
|
-
return selectedModel;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Get router service status
|
|
327
|
-
*/
|
|
328
|
-
getStatus() {
|
|
329
|
-
return {
|
|
330
|
-
routerModel: this.routerModel,
|
|
331
|
-
contextMessagesCount: this.contextMessagesCount,
|
|
332
|
-
requestTimeout: this.requestTimeout,
|
|
333
|
-
benchmarkServiceStatus: this.benchmarkService.getStatus(),
|
|
334
|
-
isAvailable: true
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Test router with sample data
|
|
340
|
-
*/
|
|
341
|
-
async testRouter() {
|
|
342
|
-
try {
|
|
343
|
-
const testMessage = {
|
|
344
|
-
content: 'Can you help me debug this JavaScript function?',
|
|
345
|
-
role: 'user'
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
const testResult = await this.routeMessage(
|
|
349
|
-
testMessage,
|
|
350
|
-
[],
|
|
351
|
-
MODELS.ANTHROPIC_SONNET,
|
|
352
|
-
[MODELS.ANTHROPIC_SONNET, MODELS.ANTHROPIC_OPUS, MODELS.GPT_4, MODELS.DEEPSEEK_R1],
|
|
353
|
-
{ apiKey: 'test-key' } // Mock context for testing
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
this.logger.info('Router test completed', { selectedModel: testResult });
|
|
357
|
-
return { success: true, selectedModel: testResult };
|
|
358
|
-
|
|
359
|
-
} catch (error) {
|
|
360
|
-
this.logger.error('Router test failed', { error: error.message });
|
|
361
|
-
return { success: false, error: error.message };
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
export default ModelRouterService;
|
|
1
|
+
const a0_0x1bd400=a0_0x3a76;function a0_0x3a76(_0x39b9db,_0x23bf04){_0x39b9db=_0x39b9db-0x1cf;const _0x434fe5=a0_0x434f();let _0x3a766c=_0x434fe5[_0x39b9db];if(a0_0x3a76['vWQqZg']===undefined){var _0x5834db=function(_0x29b3f7){const _0x32d40e='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x1d3b92='',_0x343f92='';for(let _0x4cc8b4=0x0,_0x274994,_0x519188,_0x34df73=0x0;_0x519188=_0x29b3f7['charAt'](_0x34df73++);~_0x519188&&(_0x274994=_0x4cc8b4%0x4?_0x274994*0x40+_0x519188:_0x519188,_0x4cc8b4++%0x4)?_0x1d3b92+=String['fromCharCode'](0xff&_0x274994>>(-0x2*_0x4cc8b4&0x6)):0x0){_0x519188=_0x32d40e['indexOf'](_0x519188);}for(let _0x3e0f78=0x0,_0x4c5676=_0x1d3b92['length'];_0x3e0f78<_0x4c5676;_0x3e0f78++){_0x343f92+='%'+('00'+_0x1d3b92['charCodeAt'](_0x3e0f78)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x343f92);};a0_0x3a76['AJxcMb']=_0x5834db,a0_0x3a76['PHPVFB']={},a0_0x3a76['vWQqZg']=!![];}const _0x46e012=_0x434fe5[0x0],_0xce016d=_0x39b9db+_0x46e012,_0x4a7a3c=a0_0x3a76['PHPVFB'][_0xce016d];return!_0x4a7a3c?(_0x3a766c=a0_0x3a76['AJxcMb'](_0x3a766c),a0_0x3a76['PHPVFB'][_0xce016d]=_0x3a766c):_0x3a766c=_0x4a7a3c,_0x3a766c;}(function(_0xccb0ed,_0x15f594){const _0xabc868=a0_0x3a76,_0x581f50=_0xccb0ed();while(!![]){try{const _0x1842ce=parseInt(_0xabc868(0x20b))/0x1*(parseInt(_0xabc868(0x1ef))/0x2)+-parseInt(_0xabc868(0x1fc))/0x3*(parseInt(_0xabc868(0x201))/0x4)+-parseInt(_0xabc868(0x1da))/0x5*(parseInt(_0xabc868(0x21d))/0x6)+parseInt(_0xabc868(0x1e3))/0x7*(parseInt(_0xabc868(0x1d2))/0x8)+parseInt(_0xabc868(0x1d7))/0x9*(-parseInt(_0xabc868(0x1f1))/0xa)+parseInt(_0xabc868(0x20d))/0xb+-parseInt(_0xabc868(0x1d6))/0xc;if(_0x1842ce===_0x15f594)break;else _0x581f50['push'](_0x581f50['shift']());}catch(_0x10c0ad){_0x581f50['push'](_0x581f50['shift']());}}}(a0_0x434f,0x7eb62));import{MODEL_ROUTER_CONFIG,HTTP_STATUS,MODELS}from'../utilities/constants.js';class ModelRouterService{constructor(_0x1d3b92,_0x343f92,_0x4cc8b4,_0x274994){const _0x54e201=a0_0x3a76;this['config']=_0x1d3b92,this[_0x54e201(0x1f8)]=_0x343f92,this['benchmarkService']=_0x4cc8b4,this[_0x54e201(0x1e4)]=_0x274994,this['routerModel']=MODEL_ROUTER_CONFIG[_0x54e201(0x1d9)],this['contextMessagesCount']=MODEL_ROUTER_CONFIG['CONTEXT_MESSAGES_COUNT'],this['requestTimeout']=MODEL_ROUTER_CONFIG[_0x54e201(0x1f6)];}async[a0_0x1bd400(0x1f0)](_0x519188,_0x34df73=[],_0x3e0f78='',_0x4c5676=[],_0x21e967={}){const _0x52569b=a0_0x1bd400;try{this[_0x52569b(0x1f8)][_0x52569b(0x1e7)](_0x52569b(0x219),{'messageLength':_0x519188['content']?.['length']||0x0,'recentMessagesCount':_0x34df73['length'],'currentModel':_0x3e0f78,'availableModelsCount':_0x4c5676[_0x52569b(0x220)]});const _0x2bec1c=this['_buildRoutingContext'](_0x519188,_0x34df73,_0x3e0f78,_0x4c5676),_0x3f7469=this[_0x52569b(0x20a)]['getBenchmarkTable'](),_0x77491=this['_createRoutingPrompt'](_0x2bec1c,_0x3f7469),_0x1a7006=await this[_0x52569b(0x1eb)](_0x77491,_0x21e967),_0x54f9fd=this[_0x52569b(0x1ee)](_0x1a7006,_0x4c5676,_0x3e0f78);return this[_0x52569b(0x1f8)][_0x52569b(0x21b)](_0x52569b(0x1ff),{'selectedModel':_0x54f9fd,'previousModel':_0x3e0f78,'changed':_0x54f9fd!==_0x3e0f78,'reasoning':_0x1a7006[_0x52569b(0x1e8)]?.['substring'](0x0,0x64)||'No\x20reasoning\x20provided'}),{'selectedModel':_0x54f9fd,'previousModel':_0x3e0f78,'changed':_0x54f9fd!==_0x3e0f78,'reasoning':_0x1a7006['reasoning']||'No\x20reasoning\x20provided'};}catch(_0x2b7dee){this[_0x52569b(0x1f8)][_0x52569b(0x1db)](_0x52569b(0x1e9),{'error':_0x2b7dee[_0x52569b(0x1f9)],'currentModel':_0x3e0f78});const _0x6cff9a=_0x3e0f78||_0x4c5676[0x0]||MODELS[_0x52569b(0x20e)];return{'selectedModel':_0x6cff9a,'previousModel':_0x3e0f78,'changed':![],'reasoning':_0x52569b(0x221)};}}['_buildRoutingContext'](_0x4a5ebf,_0x22657e,_0x5aa1cb,_0x579552){const _0x96537f=a0_0x1bd400,_0x462650=_0x22657e[_0x96537f(0x217)](-this[_0x96537f(0x213)])['map'](_0x5bbe9c=>({'role':_0x5bbe9c[_0x96537f(0x1f5)],'content':_0x5bbe9c[_0x96537f(0x1f4)]?.[_0x96537f(0x21f)](0x0,0x1f4)||'','timestamp':_0x5bbe9c['timestamp']}));return{'currentMessage':{'content':_0x4a5ebf[_0x96537f(0x1f4)]?.[_0x96537f(0x21f)](0x0,0x3e8)||'','role':_0x4a5ebf[_0x96537f(0x1f5)]||'user','hasContextReferences':!!_0x4a5ebf[_0x96537f(0x1e2)]?.[_0x96537f(0x220)],'contextTypes':_0x4a5ebf[_0x96537f(0x1e2)]?.[_0x96537f(0x1d5)](_0x1704ee=>_0x1704ee[_0x96537f(0x209)])||[]},'recentMessages':_0x462650,'currentModel':_0x5aa1cb,'availableModels':_0x579552[_0x96537f(0x1d5)](_0x1589b3=>({'name':_0x1589b3,'isCurrentModel':_0x1589b3===_0x5aa1cb})),'messageCount':_0x22657e['length']+0x1,'timestamp':new Date()[_0x96537f(0x207)]()};}['_createRoutingPrompt'](_0x4086ac,_0x2d539b){const _0x4be23d=a0_0x1bd400;return'You\x20are\x20a\x20model\x20routing\x20assistant.\x20Your\x20job\x20is\x20to\x20analyze\x20a\x20conversation\x20and\x20select\x20the\x20optimal\x20AI\x20model\x20for\x20the\x20next\x20response.\x0a\x0a##\x20Current\x20Situation\x0a-\x20**Current\x20Model**:\x20'+(_0x4086ac[_0x4be23d(0x1f2)]||'None')+_0x4be23d(0x206)+_0x4086ac['messageCount']+_0x4be23d(0x1df)+_0x4086ac[_0x4be23d(0x21a)]['map'](_0x5f659d=>_0x5f659d[_0x4be23d(0x20f)])[_0x4be23d(0x1e1)](',\x20')+'\x0a\x0a##\x20Recent\x20Conversation\x20Context\x0a'+this['_formatRecentMessages'](_0x4086ac[_0x4be23d(0x20c)])+_0x4be23d(0x211)+_0x4086ac['currentMessage']['role']+'\x0a**Content**:\x20'+_0x4086ac[_0x4be23d(0x1fb)]['content']+_0x4be23d(0x1d8)+_0x4086ac['currentMessage']['hasContextReferences']+'\x0a'+(_0x4086ac[_0x4be23d(0x1fb)][_0x4be23d(0x205)]['length']>0x0?'**Context\x20Types**:\x20'+_0x4086ac[_0x4be23d(0x1fb)]['contextTypes']['join'](',\x20'):'')+_0x4be23d(0x1fa)+this[_0x4be23d(0x218)](_0x2d539b)+_0x4be23d(0x214);}[a0_0x1bd400(0x1fe)](_0x210c16){const _0x8e081=a0_0x1bd400;if(!_0x210c16['length'])return'No\x20recent\x20messages\x20available.';return _0x210c16[_0x8e081(0x1d5)]((_0x1205d0,_0x2c918b)=>_0x2c918b+0x1+_0x8e081(0x212)+_0x1205d0['role']+'**:\x20'+_0x1205d0[_0x8e081(0x1f4)])[_0x8e081(0x1e1)]('\x0a');}['_formatBenchmarkData'](_0x40f4c5){const _0x3684e4=a0_0x1bd400,_0x530fd0=_0x40f4c5[_0x3684e4(0x1d1)]||[],_0x7a42cd=_0x40f4c5['tasks']||{},_0x5273d1=_0x40f4c5['summary']||{};let _0x4854ad='###\x20Model\x20Performance\x20Summary\x0a';return Object['entries'](_0x7a42cd)['forEach'](([_0x1eebbf,_0x7f419f])=>{const _0x3db5bd=_0x3684e4;_0x4854ad+='**'+_0x1eebbf['toUpperCase']()+'**\x20('+_0x7f419f[_0x3db5bd(0x1de)]+_0x3db5bd(0x210)+(_0x7f419f['topModels']?.['join'](',\x20')||'No\x20data')+'\x0a';}),_0x4854ad+='\x0a###\x20Model\x20Details\x0a',_0x530fd0[_0x3684e4(0x217)](0x0,0x8)['forEach'](_0x2f78a9=>{const _0x247593=_0x3684e4;_0x4854ad+='**'+_0x2f78a9['name']+_0x247593(0x1cf);const _0x5f4179=Object['entries'](_0x2f78a9[_0x247593(0x1d3)]||{})[_0x247593(0x1d5)](([_0x282c35,_0x380aee])=>_0x282c35+'('+_0x380aee['score']+')')[_0x247593(0x1e1)](',\x20');_0x4854ad+=_0x5f4179+'\x20|\x20Strengths:\x20'+(_0x2f78a9['strengths']?.[_0x247593(0x1e1)](',\x20')||'N/A')+'\x0a';}),_0x4854ad;}async['_askForRouting'](_0x5dedf0,_0x4af5d3={}){const _0x2c408d=a0_0x1bd400;try{const _0x2146e1=await this[_0x2c408d(0x1e4)]['sendMessage'](this[_0x2c408d(0x204)],_0x5dedf0,{'agentId':'model-router','systemPrompt':_0x2c408d(0x1e0),'temperature':0.3,'maxTokens':0x1f4,'timeout':this['requestTimeout'],'sessionId':_0x4af5d3[_0x2c408d(0x200)],'apiKey':_0x4af5d3['apiKey']||this[_0x2c408d(0x203)][_0x2c408d(0x1e5)],'customApiKeys':_0x4af5d3[_0x2c408d(0x1f3)],'platformProvided':!![]});if(!_0x2146e1['content'])throw new Error('No response content from autopilot-model-router');const _0x2d8509=this[_0x2c408d(0x1d4)](_0x2146e1[_0x2c408d(0x1f4)]);return _0x2d8509;}catch(_0x360c54){this[_0x2c408d(0x1f8)]['error'](_0x2c408d(0x1ed),{'error':_0x360c54['message'],'routerModel':this[_0x2c408d(0x204)]});throw _0x360c54;}}[a0_0x1bd400(0x1d4)](_0x2a3520){const _0x13cfdd=a0_0x1bd400;try{const _0x4f6b88=_0x2a3520[_0x13cfdd(0x1ec)](/\{[\s\S]*\}/);if(!_0x4f6b88)throw new Error('No\x20JSON\x20found\x20in\x20autopilot-model-router\x20response');const _0x4790e6=JSON['parse'](_0x4f6b88[0x0]);if(!_0x4790e6['selectedModel'])throw new Error(_0x13cfdd(0x215));return{'selectedModel':_0x4790e6['selectedModel'],'taskType':_0x4790e6[_0x13cfdd(0x21c)]||_0x13cfdd(0x208),'confidence':_0x4790e6['confidence']||0.5,'reasoning':_0x4790e6['reasoning']||'No\x20reasoning\x20provided','factors':_0x4790e6['factors']||[]};}catch(_0x57dc29){return this['logger']['warn'](_0x13cfdd(0x1ea),{'error':_0x57dc29['message'],'content':_0x2a3520[_0x13cfdd(0x21f)](0x0,0xc8)}),{'selectedModel':null,'taskType':'unknown','confidence':0x0,'reasoning':'Failed\x20to\x20parse\x20routing\x20response','factors':[_0x13cfdd(0x21e)]};}}['_validateModelSelection'](_0x239e76,_0x347336,_0x3b5aa2){const _0x3510e6=a0_0x1bd400,{selectedModel:_0xb31f75}=_0x239e76;if(!_0xb31f75)return this['logger']['debug']('No\x20model\x20selected\x20by\x20router,\x20using\x20current\x20model'),_0x3b5aa2;if(!_0x347336[_0x3510e6(0x1dd)](_0xb31f75))return this['logger']['warn'](_0x3510e6(0x202),{'selectedModel':_0xb31f75,'availableModels':_0x347336}),_0x3b5aa2;return _0xb31f75;}['getStatus'](){const _0x412ae0=a0_0x1bd400;return{'routerModel':this['routerModel'],'contextMessagesCount':this['contextMessagesCount'],'requestTimeout':this[_0x412ae0(0x1d0)],'benchmarkServiceStatus':this['benchmarkService']['getStatus'](),'isAvailable':!![]};}async[a0_0x1bd400(0x1fd)](){const _0x33210a=a0_0x1bd400;try{const _0x5f5aef={'content':'Can\x20you\x20help\x20me\x20debug\x20this\x20JavaScript\x20function?','role':_0x33210a(0x1f7)},_0x287c6c=await this[_0x33210a(0x1f0)](_0x5f5aef,[],MODELS['ANTHROPIC_SONNET'],[MODELS['ANTHROPIC_SONNET'],MODELS[_0x33210a(0x216)],MODELS['GPT_4'],MODELS['DEEPSEEK_R1']],{'apiKey':_0x33210a(0x1e6)});return this[_0x33210a(0x1f8)][_0x33210a(0x21b)]('Router\x20test\x20completed',{'selectedModel':_0x287c6c}),{'success':!![],'selectedModel':_0x287c6c};}catch(_0x2076a6){return this['logger']['error'](_0x33210a(0x1dc),{'error':_0x2076a6['message']}),{'success':![],'error':_0x2076a6['message']};}}}function a0_0x434f(){const _0x1812da=['uM91DgvYihrLC3qGzMfPBgvK','Aw5JBhvKzxm','zgvZy3jPChrPB24','cI0GkIPbDMfPBgfIBguGtw9KzwXZkIO6ia','ww91igfYzsbHig1VzgvSihjVDxrPBMCGzxHWzxj0lIbbBMfSExPLignVBNzLCNnHDgLVBNmGyw5KihnLBgvJDcbVChrPBwfSiefjig1VzgvSCY4GqwX3yxLZihjLC3bVBMqGD2L0Acb2ywXPzcbku09oig9UBhKU','AM9PBG','y29UDgv4DfjLzMvYzw5Jzxm','mtuYnMnYB3rAyW','ywLtzxj2AwnL','yxbPs2v5','DgvZDc1RzxK','zgvIDwC','CMvHC29UAw5N','tw9KzwWGCM91DgLUzYbMywLSzwqSigzHBgXPBMCGyMfJAYb0BYbJDxjYzw50ig1VzgvS','rMfPBgvKihrVihbHCNnLigf1Dg9WAwXVDc1TB2rLBc1YB3v0zxiGCM91DgLUzYbYzxnWB25Zzq','x2fZA0zVCLjVDxrPBMC','Bwf0y2G','yxv0B3bPBg90lw1VzgvSlxjVDxrLCIbYB3v0Aw5NihjLCxvLC3qGzMfPBgvK','x3zHBgLKyxrLtw9KzwXtzwXLy3rPB24','mMfdBhznua','CM91DgvnzxnZywDL','mJm5mhzRB3r6yq','y3vYCMvUDe1VzgvS','y3vZDg9TqxbPs2v5CW','y29UDgvUDa','CM9Szq','uKvrvuvtvf9usu1ft1vu','DxnLCG','Bg9Nz2vY','BwvZC2fNzq','cGOJiYbnB2rLBcbczw5JAg1HCMSGrgf0yqO','y3vYCMvUDe1LC3nHz2u','mZy3mdGZreTruKTT','DgvZDfjVDxrLCG','x2zVCM1HDfjLy2vUDe1LC3nHz2vZ','tw9KzwWGCM91DgLUzYbJB21WBgv0zwq','C2vZC2LVBKLK','ohzqtenNBq','uM91DgvYihnLBgvJDgvKihvUyxzHAwXHyMXLig1VzgvSlcb1C2LUzYbJDxjYzw50ig1VzgvS','y29UzMLN','CM91DgvYtw9KzwW','y29UDgv4Dfr5CgvZ','cI0GkIPnzxnZywDLienVDw50kIO6ia','Dg9ju09tDhjPBMC','Dw5RBM93BG','DhLWzq','yMvUy2HTyxjRu2vYDMLJzq','otq5odqXqvjQCMjK','CMvJzw50twvZC2fNzxm','nZK3mtGXmfPAzvPgqq','qu5usfjpueLdx1nptK5fva','BMfTzq','ktOG','cGOJiYbdDxjYzw50ie1LC3nHz2uGDg8GuM91DgukkIPsB2XLkIO6ia','lIaQkG','y29UDgv4De1LC3nHz2vZq291BNq','cGOJiYbsB3v0Aw5NierLy2LZAw9UcKfUywX5EMuGDgHLign1CNjLBNqGBwvZC2fNzsbHBMqGy29UDMvYC2f0Aw9UignVBNrLEhqGDg8GC2vSzwn0ihrOzsbIzxn0ig1VzgvSlIbdB25ZAwrLCJOkcJeUicOQvgfZAYbuExbLkIO6ieLUzMvYigzYB20Gy29UDMvYC2f0Aw9UignVBNrLBNqGlsbPCYb0AgLZignVzgLUzYWGyw5HBhLZAxmSignYzwf0AxzLihDYAxrPBMCSig9YigeGCxvPy2SGDgfZAZ8kmI4GkIPdB21WBgv4Axr5kIO6ierVzxmGAxqGCMvXDwLYzsbKzwvWihjLyxnVBMLUzYbVCIbPCYbPDcbZDhjHAwDODgzVCNDHCMq/cJmUicOQq29UDgv4DcOQoIbbCMuGDgHLCMuGy29KzsbMAwXLCYbVCIb0zwnOBMLJywWGCMvMzxjLBMnLCZ8knc4GkIPdB252zxjZyxrPB24GrMXVDYOQoIbxAgf0igHHCYbIzwvUigrPC2n1C3nLzcbYzwnLBNrSEsb0BYb1BMrLCNn0yw5KihrOzsbVDMvYywXSihrHC2S/cJuUicOQrwzMAwnPzw5JEsOQoIbcywXHBMnLihbLCMzVCM1HBMnLihDPDgGGy29ZDc9ZCgvLzcbUzwvKCWOkuMvZCg9Uzcb3AxrOiePtt04GB25SEtOkEWOGicjZzwXLy3rLze1VzgvSiJOGiM1VzgvSlw5HBwuIlaOGicj0yxnRvhLWzsi6icjJB2rPBMD8yw5HBhLZAxn8y3jLyxrPDMv8CxvPy2STDgfZA3mIlaOGicjJB25MAwrLBMnLiJOGmc44nsWkicaICMvHC29UAw5NiJOGiKjYAwvMigv4CgXHBMf0Aw9Uig9MihDOEsb0AgLZig1VzgvSihDHCYbJAg9Zzw4IlaOGicjMywn0B3jZiJOGwYjMywn0B3iXiIWGiMzHy3rVCJiIlcaIzMfJDg9YmYjDcN0','twLZC2LUzYbZzwXLy3rLze1VzgvSigLUigf1Dg9WAwXVDc1TB2rLBc1YB3v0zxiGCMvZCg9UC2u','qu5usfjpueLdx09qvvm','C2XPy2u','x2zVCM1HDejLBMnOBwfYA0rHDge','u3rHCNrPBMCGBw9KzwWGCM91DgLUzYbHBMfSExnPCW','yxzHAwXHyMXLtw9KzwXZ','Aw5MBW','DgfZA1r5Cgu','mJK0nLv1A29IBG','CgfYC2LUzY1LCNjVCG','C3vIC3rYAw5N','BgvUz3rO','uM91DgLUzYbMywLSzwqSihvZAw5NigzHBgXIywnRig1VzgvS','kIO6ia','CMvXDwvZDfrPBwvVDxq','Bw9KzwXZ','mZiZnJbPCvrMAwq','DgfZA3m','x3bHCNnLuM91DgLUz1jLC3bVBNnL','BwfW','otu0ndCXnK9JB0nPBW','mtG2nZvbsKrHrLi','cIOQsgfZienVBNrLEhqGuMvMzxjLBMnLCYOQoIa','uK9vvevsx01prevm','nteWnwXcBeXPtG','zxjYB3i'];a0_0x434f=function(){return _0x1812da;};return a0_0x434f();}export default ModelRouterService;
|