@loxia-labs/loxia-autopilot-one 1.0.1 → 1.0.4
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 +15 -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,247 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Context Injection Service
|
|
3
|
-
* Builds dynamic context sections from active file attachments
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import FileAttachmentService from './fileAttachmentService.js';
|
|
7
|
-
|
|
8
|
-
class ContextInjectionService {
|
|
9
|
-
constructor(config = {}, logger = null) {
|
|
10
|
-
this.config = config;
|
|
11
|
-
this.logger = logger;
|
|
12
|
-
this.attachmentService = new FileAttachmentService(config, logger);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Initialize service
|
|
17
|
-
* @returns {Promise<void>}
|
|
18
|
-
*/
|
|
19
|
-
async initialize() {
|
|
20
|
-
await this.attachmentService.initialize();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Build dynamic context for an agent
|
|
25
|
-
* @param {string} agentId - Agent ID
|
|
26
|
-
* @returns {Promise<string>} Dynamic context section
|
|
27
|
-
*/
|
|
28
|
-
async buildDynamicContext(agentId) {
|
|
29
|
-
try {
|
|
30
|
-
const activeAttachments = await this.attachmentService.getActiveAttachments(agentId);
|
|
31
|
-
|
|
32
|
-
if (activeAttachments.length === 0) {
|
|
33
|
-
return ''; // No context to inject
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Separate content and reference mode attachments
|
|
37
|
-
const contentFiles = activeAttachments.filter(a => a.mode === 'content');
|
|
38
|
-
const referenceFiles = activeAttachments.filter(a => a.mode === 'reference');
|
|
39
|
-
|
|
40
|
-
let contextSection = '';
|
|
41
|
-
|
|
42
|
-
// Build content files section
|
|
43
|
-
if (contentFiles.length > 0) {
|
|
44
|
-
contextSection += '\n<attached-files>\n';
|
|
45
|
-
|
|
46
|
-
for (const attachment of contentFiles) {
|
|
47
|
-
const content = await this.attachmentService.getAttachmentContent(attachment.fileId);
|
|
48
|
-
if (content) {
|
|
49
|
-
const formattedContent = this.formatContentFile(attachment, content);
|
|
50
|
-
contextSection += formattedContent + '\n';
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
contextSection += '</attached-files>\n';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Build reference files section
|
|
58
|
-
if (referenceFiles.length > 0) {
|
|
59
|
-
contextSection += '\n<file-references>\n';
|
|
60
|
-
|
|
61
|
-
for (const attachment of referenceFiles) {
|
|
62
|
-
const formattedRef = this.formatReferenceFile(attachment);
|
|
63
|
-
contextSection += formattedRef + '\n';
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
contextSection += '</file-references>\n';
|
|
67
|
-
contextSection += '\nNote: Referenced files can be accessed using the filesystem tool if needed.\n';
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return contextSection;
|
|
71
|
-
} catch (error) {
|
|
72
|
-
this.logger?.error('Error building dynamic context', { agentId, error: error.message });
|
|
73
|
-
return ''; // Return empty on error to avoid breaking the conversation
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Format content mode file
|
|
79
|
-
* @param {Object} attachment - Attachment metadata
|
|
80
|
-
* @param {string} content - File content
|
|
81
|
-
* @returns {string} Formatted XML
|
|
82
|
-
*/
|
|
83
|
-
formatContentFile(attachment, content) {
|
|
84
|
-
const { fileName, fileType, size, contentType } = attachment;
|
|
85
|
-
const sizeKB = (size / 1024).toFixed(2);
|
|
86
|
-
|
|
87
|
-
// Format based on content type
|
|
88
|
-
if (contentType === 'text') {
|
|
89
|
-
return this.formatTextFile(attachment, content);
|
|
90
|
-
} else if (contentType === 'image') {
|
|
91
|
-
return this.formatImageFile(attachment, content);
|
|
92
|
-
} else if (contentType === 'pdf') {
|
|
93
|
-
return this.formatPdfFile(attachment, content);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Fallback
|
|
97
|
-
return ` <file name="${this.escapeXml(fileName)}" type="${fileType}" size="${sizeKB}KB" mode="content">\n${this.escapeXml(content)}\n </file>`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Format text file
|
|
102
|
-
* @param {Object} attachment - Attachment metadata
|
|
103
|
-
* @param {string} content - File content
|
|
104
|
-
* @returns {string} Formatted XML
|
|
105
|
-
*/
|
|
106
|
-
formatTextFile(attachment, content) {
|
|
107
|
-
const { fileName, fileType, size } = attachment;
|
|
108
|
-
const sizeKB = (size / 1024).toFixed(2);
|
|
109
|
-
|
|
110
|
-
return ` <file name="${this.escapeXml(fileName)}" type="${fileType}" size="${sizeKB}KB" mode="content">\n${this.escapeXml(content)}\n </file>`;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Format image file
|
|
115
|
-
* @param {Object} attachment - Attachment metadata
|
|
116
|
-
* @param {string} base64Content - Base64 data URI
|
|
117
|
-
* @returns {string} Formatted XML
|
|
118
|
-
*/
|
|
119
|
-
formatImageFile(attachment, base64Content) {
|
|
120
|
-
const { fileName, fileType, size } = attachment;
|
|
121
|
-
const sizeKB = (size / 1024).toFixed(2);
|
|
122
|
-
|
|
123
|
-
return ` <file name="${this.escapeXml(fileName)}" type="${fileType}" size="${sizeKB}KB" mode="content">\n${base64Content}\n </file>`;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Format PDF file
|
|
128
|
-
* @param {Object} attachment - Attachment metadata
|
|
129
|
-
* @param {string} extractedText - Extracted text from PDF
|
|
130
|
-
* @returns {string} Formatted XML
|
|
131
|
-
*/
|
|
132
|
-
formatPdfFile(attachment, extractedText) {
|
|
133
|
-
const { fileName, fileType, size } = attachment;
|
|
134
|
-
const sizeKB = (size / 1024).toFixed(2);
|
|
135
|
-
|
|
136
|
-
return ` <file name="${this.escapeXml(fileName)}" type="${fileType}" size="${sizeKB}KB" mode="content">\n${this.escapeXml(extractedText)}\n </file>`;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Format reference mode file
|
|
141
|
-
* @param {Object} attachment - Attachment metadata
|
|
142
|
-
* @returns {string} Formatted XML
|
|
143
|
-
*/
|
|
144
|
-
formatReferenceFile(attachment) {
|
|
145
|
-
const { fileName, originalPath, size, fileType, lastModified } = attachment;
|
|
146
|
-
const sizeFormatted = this.formatBytes(size);
|
|
147
|
-
const modifiedDate = new Date(lastModified).toISOString().split('T')[0];
|
|
148
|
-
|
|
149
|
-
return ` <file name="${this.escapeXml(fileName)}" path="${this.escapeXml(originalPath)}" size="${sizeFormatted}" type="${fileType}" modified="${modifiedDate}" />`;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Escape XML special characters
|
|
154
|
-
* @param {string} text - Text to escape
|
|
155
|
-
* @returns {string} Escaped text
|
|
156
|
-
*/
|
|
157
|
-
escapeXml(text) {
|
|
158
|
-
if (!text) return '';
|
|
159
|
-
return text
|
|
160
|
-
.replace(/&/g, '&')
|
|
161
|
-
.replace(/</g, '<')
|
|
162
|
-
.replace(/>/g, '>')
|
|
163
|
-
.replace(/"/g, '"')
|
|
164
|
-
.replace(/'/g, ''');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Format bytes to human-readable string
|
|
169
|
-
* @param {number} bytes
|
|
170
|
-
* @returns {string}
|
|
171
|
-
*/
|
|
172
|
-
formatBytes(bytes) {
|
|
173
|
-
if (bytes === 0) return '0 Bytes';
|
|
174
|
-
const k = 1024;
|
|
175
|
-
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
|
176
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
177
|
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + sizes[i];
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Estimate total tokens for active attachments
|
|
182
|
-
* @param {string} agentId - Agent ID
|
|
183
|
-
* @returns {Promise<number>} Total estimated tokens
|
|
184
|
-
*/
|
|
185
|
-
async estimateTotalTokens(agentId) {
|
|
186
|
-
try {
|
|
187
|
-
const activeAttachments = await this.attachmentService.getActiveAttachments(agentId);
|
|
188
|
-
let total = 0;
|
|
189
|
-
|
|
190
|
-
for (const attachment of activeAttachments) {
|
|
191
|
-
if (attachment.mode === 'content') {
|
|
192
|
-
total += attachment.tokenEstimate || 0;
|
|
193
|
-
} else {
|
|
194
|
-
// Reference mode: estimate XML tag overhead
|
|
195
|
-
total += 20; // Approximate tokens for XML tag
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return total;
|
|
200
|
-
} catch (error) {
|
|
201
|
-
this.logger?.error('Error estimating total tokens', { agentId, error: error.message });
|
|
202
|
-
return 0;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Get summary of active attachments
|
|
208
|
-
* @param {string} agentId - Agent ID
|
|
209
|
-
* @returns {Promise<Object>} Summary object
|
|
210
|
-
*/
|
|
211
|
-
async getAttachmentSummary(agentId) {
|
|
212
|
-
try {
|
|
213
|
-
const activeAttachments = await this.attachmentService.getActiveAttachments(agentId);
|
|
214
|
-
|
|
215
|
-
const summary = {
|
|
216
|
-
totalActive: activeAttachments.length,
|
|
217
|
-
contentMode: activeAttachments.filter(a => a.mode === 'content').length,
|
|
218
|
-
referenceMode: activeAttachments.filter(a => a.mode === 'reference').length,
|
|
219
|
-
estimatedTokens: 0,
|
|
220
|
-
files: []
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
for (const attachment of activeAttachments) {
|
|
224
|
-
summary.estimatedTokens += attachment.tokenEstimate || 0;
|
|
225
|
-
summary.files.push({
|
|
226
|
-
fileName: attachment.fileName,
|
|
227
|
-
mode: attachment.mode,
|
|
228
|
-
size: this.formatBytes(attachment.size),
|
|
229
|
-
tokens: attachment.tokenEstimate || 0
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return summary;
|
|
234
|
-
} catch (error) {
|
|
235
|
-
this.logger?.error('Error getting attachment summary', { agentId, error: error.message });
|
|
236
|
-
return {
|
|
237
|
-
totalActive: 0,
|
|
238
|
-
contentMode: 0,
|
|
239
|
-
referenceMode: 0,
|
|
240
|
-
estimatedTokens: 0,
|
|
241
|
-
files: []
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export default ContextInjectionService;
|
|
1
|
+
const a0_0x2ff622=a0_0x1d57;(function(_0x337c1d,_0x334467){const _0x3f1bd4=a0_0x1d57,_0x54340c=_0x337c1d();while(!![]){try{const _0x4a997b=-parseInt(_0x3f1bd4(0xec))/0x1+parseInt(_0x3f1bd4(0xfe))/0x2+parseInt(_0x3f1bd4(0xde))/0x3*(parseInt(_0x3f1bd4(0xf3))/0x4)+-parseInt(_0x3f1bd4(0xe4))/0x5*(-parseInt(_0x3f1bd4(0xf7))/0x6)+-parseInt(_0x3f1bd4(0x108))/0x7+parseInt(_0x3f1bd4(0x10c))/0x8*(parseInt(_0x3f1bd4(0x102))/0x9)+-parseInt(_0x3f1bd4(0xe0))/0xa;if(_0x4a997b===_0x334467)break;else _0x54340c['push'](_0x54340c['shift']());}catch(_0x1dd549){_0x54340c['push'](_0x54340c['shift']());}}}(a0_0x5416,0x2528a));function a0_0x5416(){const _0x5e217c=['cIaGpc9MAwXLpG','BgvUz3rO','nJGWmJjsu2X1Bhu','zMLSDgvY','CMvMzxjLBMnL','jMfTCdS','Bg9Nz2vY','zMXVB3i','nZm5odm3zwzuq21q','zMLSzxm','Aw5PDgLHBgL6zq','zM9YBwf0qNL0zxm','mtm2q0DxugD6','yNvPBgreEw5HBwLJq29UDgv4Da','rxjYB3iGyNvPBgrPBMCGzhLUyw1PyYbJB250zxH0','jMfWB3m7','zM9YBwf0ugrMrMLSzq','pc9MAwXLlxjLzMvYzw5Jzxm+cG','zM9YBwf0sw1Hz2vgAwXL','zM9YBwf0vgv4DezPBgu','m1fnzffRwG','y29UDgvUDa','mZK1ndK2mfLUsffwta','zM9YBwf0uMvMzxjLBMnLrMLSzq','iIaVpG','CMvWBgfJzq','mte3nJGZnwT6vufsrq','rxjYB3iGzxn0Aw1HDgLUzYb0B3rHBcb0B2TLBNm','zxjYB3i','zxnJyxbLwg1S','BwvZC2fNzq','rxjYB3iGz2v0DgLUzYbHDhrHy2HTzw50ihn1Bw1HCNK','Dg9Rzw5fC3rPBwf0zq','CgrM','mJi1mtG0u3v1zLfd','zMLSzu5HBwu','iIbZAxPLpsi','iIbWyxrOpsi','y29UzMLN','C2L6zq','Bw9Kzq','otyWnZy0zuXxzKrx','C3bSAxq','zxn0Aw1HDgvKvg9Rzw5Z','z2v0qwn0AxzLqxr0ywnOBwvUDhm','nNbtEuHLtq','zM9YBwf0q29UDgvUDezPBgu','ica8zMLSzsbUyw1Lpsi','cJXHDhrHy2HLzc1MAwXLCZ4k','yxr0ywnOBwvUDfnLCNzPy2u','ChvZAa','Cg93','ntq5mdu4txHgzMfz','iIb0ExbLpsi'];a0_0x5416=function(){return _0x5e217c;};return a0_0x5416();}import a0_0xef1d6e from'./fileAttachmentService.js';function a0_0x1d57(_0x182bc6,_0x44268a){_0x182bc6=_0x182bc6-0xd9;const _0x5416ba=a0_0x5416();let _0x1d5762=_0x5416ba[_0x182bc6];if(a0_0x1d57['uyGesK']===undefined){var _0x4000fd=function(_0x41cb5c){const _0x54f090='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xef1d6e='',_0x4c5607='';for(let _0x24d79b=0x0,_0x2b7756,_0x16af80,_0x43b997=0x0;_0x16af80=_0x41cb5c['charAt'](_0x43b997++);~_0x16af80&&(_0x2b7756=_0x24d79b%0x4?_0x2b7756*0x40+_0x16af80:_0x16af80,_0x24d79b++%0x4)?_0xef1d6e+=String['fromCharCode'](0xff&_0x2b7756>>(-0x2*_0x24d79b&0x6)):0x0){_0x16af80=_0x54f090['indexOf'](_0x16af80);}for(let _0x1df026=0x0,_0x1e0318=_0xef1d6e['length'];_0x1df026<_0x1e0318;_0x1df026++){_0x4c5607+='%'+('00'+_0xef1d6e['charCodeAt'](_0x1df026)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x4c5607);};a0_0x1d57['JivmxF']=_0x4000fd,a0_0x1d57['PPRGvu']={},a0_0x1d57['uyGesK']=!![];}const _0x441a55=_0x5416ba[0x0],_0x4e19b4=_0x182bc6+_0x441a55,_0x233199=a0_0x1d57['PPRGvu'][_0x4e19b4];return!_0x233199?(_0x1d5762=a0_0x1d57['JivmxF'](_0x1d5762),a0_0x1d57['PPRGvu'][_0x4e19b4]=_0x1d5762):_0x1d5762=_0x233199,_0x1d5762;}class ContextInjectionService{constructor(_0x4c5607={},_0x24d79b=null){const _0x3c22e5=a0_0x1d57;this[_0x3c22e5(0xf0)]=_0x4c5607,this['logger']=_0x24d79b,this[_0x3c22e5(0xfb)]=new a0_0xef1d6e(_0x4c5607,_0x24d79b);}async[a0_0x2ff622(0x10a)](){const _0x388cbd=a0_0x2ff622;await this[_0x388cbd(0xfb)]['initialize']();}async[a0_0x2ff622(0x10d)](_0x2b7756){const _0x5b8b93=a0_0x2ff622;try{const _0x16af80=await this[_0x5b8b93(0xfb)]['getActiveAttachments'](_0x2b7756);if(_0x16af80['length']===0x0)return'';const _0x43b997=_0x16af80['filter'](_0x21584c=>_0x21584c[_0x5b8b93(0xf2)]==='content'),_0x1df026=_0x16af80['filter'](_0x56196e=>_0x56196e[_0x5b8b93(0xf2)]==='reference');let _0x1e0318='';if(_0x43b997['length']>0x0){_0x1e0318+=_0x5b8b93(0xfa);for(const _0x1a5a84 of _0x43b997){const _0x1fcf55=await this[_0x5b8b93(0xfb)]['getAttachmentContent'](_0x1a5a84['fileId']);if(_0x1fcf55){const _0x36b591=this[_0x5b8b93(0xf8)](_0x1a5a84,_0x1fcf55);_0x1e0318+=_0x36b591+'\x0a';}}_0x1e0318+='</attached-files>\x0a';}if(_0x1df026['length']>0x0){_0x1e0318+='\x0a<file-references>\x0a';for(const _0x19500b of _0x1df026){const _0x53950e=this['formatReferenceFile'](_0x19500b);_0x1e0318+=_0x53950e+'\x0a';}_0x1e0318+=_0x5b8b93(0xdb),_0x1e0318+='\x0aNote:\x20Referenced\x20files\x20can\x20be\x20accessed\x20using\x20the\x20filesystem\x20tool\x20if\x20needed.\x0a';}return _0x1e0318;}catch(_0x4e38c0){return this['logger']?.['error'](_0x5b8b93(0x10e),{'agentId':_0x2b7756,'error':_0x4e38c0['message']}),'';}}[a0_0x2ff622(0xf8)](_0x3d0fa3,_0x9f6ba2){const _0x1e7228=a0_0x2ff622,{fileName:_0x17be4c,fileType:_0x539c90,size:_0x1c9820,contentType:_0x2d8878}=_0x3d0fa3,_0x2ffdf7=(_0x1c9820/0x400)['toFixed'](0x2);if(_0x2d8878==='text')return this[_0x1e7228(0xdd)](_0x3d0fa3,_0x9f6ba2);else{if(_0x2d8878==='image')return this['formatImageFile'](_0x3d0fa3,_0x9f6ba2);else{if(_0x2d8878===_0x1e7228(0xeb))return this['formatPdfFile'](_0x3d0fa3,_0x9f6ba2);}}return'\x20\x20<file\x20name=\x22'+this[_0x1e7228(0xe7)](_0x17be4c)+'\x22\x20type=\x22'+_0x539c90+_0x1e7228(0xee)+_0x2ffdf7+'KB\x22\x20mode=\x22content\x22>\x0a'+this['escapeXml'](_0x9f6ba2)+_0x1e7228(0x100);}[a0_0x2ff622(0xdd)](_0x1d7782,_0xb5d6a){const _0x176e75=a0_0x2ff622,{fileName:_0x4acf9e,fileType:_0x195535,size:_0x284f16}=_0x1d7782,_0x25f3d9=(_0x284f16/0x400)['toFixed'](0x2);return'\x20\x20<file\x20name=\x22'+this['escapeXml'](_0x4acf9e)+_0x176e75(0xff)+_0x195535+_0x176e75(0xee)+_0x25f3d9+'KB\x22\x20mode=\x22content\x22>\x0a'+this[_0x176e75(0xe7)](_0xb5d6a)+'\x0a\x20\x20</file>';}[a0_0x2ff622(0xdc)](_0x3f4da3,_0x4731f4){const _0x1960e8=a0_0x2ff622,{fileName:_0x22bc5e,fileType:_0x2f20aa,size:_0x340053}=_0x3f4da3,_0x5c68db=(_0x340053/0x400)['toFixed'](0x2);return _0x1960e8(0xf9)+this['escapeXml'](_0x22bc5e)+_0x1960e8(0xff)+_0x2f20aa+_0x1960e8(0xee)+_0x5c68db+'KB\x22\x20mode=\x22content\x22>\x0a'+_0x4731f4+'\x0a\x20\x20</file>';}[a0_0x2ff622(0xda)](_0x251b9d,_0x2b33ce){const _0x1d78a9=a0_0x2ff622,{fileName:_0x2e753e,fileType:_0x59faba,size:_0x15b62f}=_0x251b9d,_0x4f2c39=(_0x15b62f/0x400)['toFixed'](0x2);return'\x20\x20<file\x20name=\x22'+this['escapeXml'](_0x2e753e)+_0x1d78a9(0xff)+_0x59faba+_0x1d78a9(0xee)+_0x4f2c39+'KB\x22\x20mode=\x22content\x22>\x0a'+this[_0x1d78a9(0xe7)](_0x2b33ce)+'\x0a\x20\x20</file>';}[a0_0x2ff622(0xe1)](_0x4645fc){const _0xf1f230=a0_0x2ff622,{fileName:_0xb69ee0,originalPath:_0x1b0a77,size:_0x515f9d,fileType:_0x19e49f,lastModified:_0x4e245d}=_0x4645fc,_0x5c0ebb=this[_0xf1f230(0x10b)](_0x515f9d),_0x3ba5ab=new Date(_0x4e245d)['toISOString']()[_0xf1f230(0xf4)]('T')[0x0];return _0xf1f230(0xf9)+this['escapeXml'](_0xb69ee0)+_0xf1f230(0xef)+this[_0xf1f230(0xe7)](_0x1b0a77)+_0xf1f230(0xee)+_0x5c0ebb+'\x22\x20type=\x22'+_0x19e49f+'\x22\x20modified=\x22'+_0x3ba5ab+_0xf1f230(0xe2);}['escapeXml'](_0x570db2){const _0x5cec6e=a0_0x2ff622;if(!_0x570db2)return'';return _0x570db2[_0x5cec6e(0xe3)](/&/g,_0x5cec6e(0x105))['replace'](/</g,'<')[_0x5cec6e(0xe3)](/>/g,'>')['replace'](/"/g,'"')[_0x5cec6e(0xe3)](/'/g,_0x5cec6e(0xd9));}['formatBytes'](_0x1cf6dd){const _0x5b6479=a0_0x2ff622;if(_0x1cf6dd===0x0)return'0\x20Bytes';const _0xb2c648=0x400,_0x3e592c=['Bytes','KB','MB','GB'],_0x392561=Math[_0x5b6479(0x107)](Math['log'](_0x1cf6dd)/Math['log'](_0xb2c648));return parseFloat((_0x1cf6dd/Math[_0x5b6479(0xfd)](_0xb2c648,_0x392561))['toFixed'](0x2))+_0x3e592c[_0x392561];}async['estimateTotalTokens'](_0x4a0c08){const _0xdd3e39=a0_0x2ff622;try{const _0x4ecc99=await this['attachmentService'][_0xdd3e39(0xf6)](_0x4a0c08);let _0x174b19=0x0;for(const _0x2ed6b6 of _0x4ecc99){_0x2ed6b6[_0xdd3e39(0xf2)]===_0xdd3e39(0xdf)?_0x174b19+=_0x2ed6b6[_0xdd3e39(0xea)]||0x0:_0x174b19+=0x14;}return _0x174b19;}catch(_0x371191){return this['logger']?.['error'](_0xdd3e39(0xe5),{'agentId':_0x4a0c08,'error':_0x371191['message']}),0x0;}}async['getAttachmentSummary'](_0xefba91){const _0x3aec4b=a0_0x2ff622;try{const _0x4519c7=await this[_0x3aec4b(0xfb)]['getActiveAttachments'](_0xefba91),_0x321c96={'totalActive':_0x4519c7[_0x3aec4b(0x101)],'contentMode':_0x4519c7['filter'](_0x5a2d04=>_0x5a2d04['mode']===_0x3aec4b(0xdf))[_0x3aec4b(0x101)],'referenceMode':_0x4519c7[_0x3aec4b(0x103)](_0x11aca7=>_0x11aca7[_0x3aec4b(0xf2)]===_0x3aec4b(0x104))['length'],'estimatedTokens':0x0,'files':[]};for(const _0x4d9b15 of _0x4519c7){_0x321c96[_0x3aec4b(0xf5)]+=_0x4d9b15['tokenEstimate']||0x0,_0x321c96[_0x3aec4b(0x109)][_0x3aec4b(0xfc)]({'fileName':_0x4d9b15[_0x3aec4b(0xed)],'mode':_0x4d9b15['mode'],'size':this[_0x3aec4b(0x10b)](_0x4d9b15[_0x3aec4b(0xf1)]),'tokens':_0x4d9b15['tokenEstimate']||0x0});}return _0x321c96;}catch(_0x303ea6){return this[_0x3aec4b(0x106)]?.[_0x3aec4b(0xe6)](_0x3aec4b(0xe9),{'agentId':_0xefba91,'error':_0x303ea6[_0x3aec4b(0xe8)]}),{'totalActive':0x0,'contentMode':0x0,'referenceMode':0x0,'estimatedTokens':0x0,'files':[]};}}}export default ContextInjectionService;
|