@loxia-labs/loxia-autopilot-one 1.0.1
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/LICENSE +267 -0
- package/README.md +509 -0
- package/bin/cli.js +117 -0
- package/package.json +94 -0
- package/scripts/install-scanners.js +236 -0
- package/src/analyzers/CSSAnalyzer.js +297 -0
- package/src/analyzers/ConfigValidator.js +690 -0
- package/src/analyzers/ESLintAnalyzer.js +320 -0
- package/src/analyzers/JavaScriptAnalyzer.js +261 -0
- package/src/analyzers/PrettierFormatter.js +247 -0
- package/src/analyzers/PythonAnalyzer.js +266 -0
- package/src/analyzers/SecurityAnalyzer.js +729 -0
- package/src/analyzers/TypeScriptAnalyzer.js +247 -0
- package/src/analyzers/codeCloneDetector/analyzer.js +344 -0
- package/src/analyzers/codeCloneDetector/detector.js +203 -0
- package/src/analyzers/codeCloneDetector/index.js +160 -0
- package/src/analyzers/codeCloneDetector/parser.js +199 -0
- package/src/analyzers/codeCloneDetector/reporter.js +148 -0
- package/src/analyzers/codeCloneDetector/scanner.js +59 -0
- package/src/core/agentPool.js +1474 -0
- package/src/core/agentScheduler.js +2147 -0
- package/src/core/contextManager.js +709 -0
- package/src/core/messageProcessor.js +732 -0
- package/src/core/orchestrator.js +548 -0
- package/src/core/stateManager.js +877 -0
- package/src/index.js +631 -0
- package/src/interfaces/cli.js +549 -0
- package/src/interfaces/webServer.js +2162 -0
- package/src/modules/fileExplorer/controller.js +280 -0
- package/src/modules/fileExplorer/index.js +37 -0
- package/src/modules/fileExplorer/middleware.js +92 -0
- package/src/modules/fileExplorer/routes.js +125 -0
- package/src/modules/fileExplorer/types.js +44 -0
- package/src/services/aiService.js +1232 -0
- package/src/services/apiKeyManager.js +164 -0
- package/src/services/benchmarkService.js +366 -0
- package/src/services/budgetService.js +539 -0
- package/src/services/contextInjectionService.js +247 -0
- package/src/services/conversationCompactionService.js +637 -0
- package/src/services/errorHandler.js +810 -0
- package/src/services/fileAttachmentService.js +544 -0
- package/src/services/modelRouterService.js +366 -0
- package/src/services/modelsService.js +322 -0
- package/src/services/qualityInspector.js +796 -0
- package/src/services/tokenCountingService.js +536 -0
- package/src/tools/agentCommunicationTool.js +1344 -0
- package/src/tools/agentDelayTool.js +485 -0
- package/src/tools/asyncToolManager.js +604 -0
- package/src/tools/baseTool.js +800 -0
- package/src/tools/browserTool.js +920 -0
- package/src/tools/cloneDetectionTool.js +621 -0
- package/src/tools/dependencyResolverTool.js +1215 -0
- package/src/tools/fileContentReplaceTool.js +875 -0
- package/src/tools/fileSystemTool.js +1107 -0
- package/src/tools/fileTreeTool.js +853 -0
- package/src/tools/imageTool.js +901 -0
- package/src/tools/importAnalyzerTool.js +1060 -0
- package/src/tools/jobDoneTool.js +248 -0
- package/src/tools/seekTool.js +956 -0
- package/src/tools/staticAnalysisTool.js +1778 -0
- package/src/tools/taskManagerTool.js +2873 -0
- package/src/tools/terminalTool.js +2304 -0
- package/src/tools/webTool.js +1430 -0
- package/src/types/agent.js +519 -0
- package/src/types/contextReference.js +972 -0
- package/src/types/conversation.js +730 -0
- package/src/types/toolCommand.js +747 -0
- package/src/utilities/attachmentValidator.js +292 -0
- package/src/utilities/configManager.js +582 -0
- package/src/utilities/constants.js +722 -0
- package/src/utilities/directoryAccessManager.js +535 -0
- package/src/utilities/fileProcessor.js +307 -0
- package/src/utilities/logger.js +436 -0
- package/src/utilities/tagParser.js +1246 -0
- package/src/utilities/toolConstants.js +317 -0
- package/web-ui/build/index.html +15 -0
- package/web-ui/build/logo.png +0 -0
- package/web-ui/build/logo2.png +0 -0
- package/web-ui/build/static/index-CjkkcnFA.js +344 -0
- package/web-ui/build/static/index-Dy2bYbOa.css +1 -0
|
@@ -0,0 +1,901 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file tools/imageTool.js
|
|
3
|
+
* @description Tool for generating images using AI models (Flux, DALL-E, etc.)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import os from 'os';
|
|
8
|
+
import { promises as fs } from 'fs';
|
|
9
|
+
import { BaseTool } from './baseTool.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Configuration constants for image generation
|
|
13
|
+
*/
|
|
14
|
+
const IMAGE_CONFIG = {
|
|
15
|
+
DEFAULT_MODEL: 'azure-openai-dalle3',
|
|
16
|
+
DEFAULT_SIZE: '1024x1024',
|
|
17
|
+
DEFAULT_QUALITY: 'standard',
|
|
18
|
+
VALID_SIZES: ['256x256', '512x512', '1024x1024', '1024x1792', '1792x1024'],
|
|
19
|
+
VALID_FORMATS: ['png', 'jpg', 'jpeg', 'webp'],
|
|
20
|
+
MAX_CONCURRENT: 3,
|
|
21
|
+
QUEUE_LIMIT: 10,
|
|
22
|
+
TEMP_CLEANUP_MS: 3600000, // 1 hour
|
|
23
|
+
MAX_PROMPT_LENGTH: 4000,
|
|
24
|
+
DOWNLOAD_TIMEOUT: 60000 // 60 seconds
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* ImageTool - Generate images using AI models
|
|
29
|
+
* Supports queueing, async processing, and both temp/project directory storage
|
|
30
|
+
*/
|
|
31
|
+
export class ImageTool extends BaseTool {
|
|
32
|
+
constructor(config = {}, logger = null) {
|
|
33
|
+
super(config, logger);
|
|
34
|
+
|
|
35
|
+
// Override tool ID
|
|
36
|
+
this.id = 'image-gen';
|
|
37
|
+
|
|
38
|
+
// Job queue and tracking
|
|
39
|
+
this.queue = [];
|
|
40
|
+
this.currentJob = null;
|
|
41
|
+
this.completedJobs = new Map();
|
|
42
|
+
this.isProcessing = false;
|
|
43
|
+
|
|
44
|
+
// AIService will be injected later
|
|
45
|
+
this.aiService = null;
|
|
46
|
+
|
|
47
|
+
// AgentPool will be injected later (for saving to conversation history)
|
|
48
|
+
this.agentPool = null;
|
|
49
|
+
|
|
50
|
+
// Temp directory for images
|
|
51
|
+
this.tempDir = path.join(os.tmpdir(), 'loxia-images');
|
|
52
|
+
|
|
53
|
+
// Cleanup timers
|
|
54
|
+
this.cleanupTimers = new Map();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Set AI service for image generation
|
|
59
|
+
* @param {AIService} aiService - AI service instance
|
|
60
|
+
*/
|
|
61
|
+
setAIService(aiService) {
|
|
62
|
+
this.aiService = aiService;
|
|
63
|
+
this.logger?.info('AI Service set for ImageTool');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Set Agent Pool for saving results to conversation history
|
|
68
|
+
* @param {AgentPool} agentPool - AgentPool instance
|
|
69
|
+
*/
|
|
70
|
+
setAgentPool(agentPool) {
|
|
71
|
+
this.agentPool = agentPool;
|
|
72
|
+
this.logger?.info('AgentPool set for ImageTool');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get tool description for agent system prompt
|
|
77
|
+
* @returns {string} Formatted tool description
|
|
78
|
+
*/
|
|
79
|
+
getDescription() {
|
|
80
|
+
return `Tool: Image Generator - Generate images using AI models
|
|
81
|
+
|
|
82
|
+
**Purpose:** Generate images from text descriptions using DALL-E 3 via Azure OpenAI. Images are saved to files and displayed in the chat.
|
|
83
|
+
|
|
84
|
+
**CRITICAL: Automatic Execution**
|
|
85
|
+
- ANY \`\`\`json block with "toolId": "image-gen" will be EXECUTED IMMEDIATELY
|
|
86
|
+
- ANY <image-gen> XML tag will be EXECUTED IMMEDIATELY
|
|
87
|
+
- DO NOT show examples or ask permission - just output the command when you want to generate an image
|
|
88
|
+
- If generation fails, output a NEW command with corrections - do NOT explain or show examples
|
|
89
|
+
|
|
90
|
+
**Invocation Syntax:**
|
|
91
|
+
|
|
92
|
+
XML Format (PREFERRED):
|
|
93
|
+
<image-gen>
|
|
94
|
+
<prompt>Detailed description of the image</prompt>
|
|
95
|
+
<output-path>images/filename.png</output-path>
|
|
96
|
+
<model>azure-openai-dalle3</model>
|
|
97
|
+
<size>1024x1024</size>
|
|
98
|
+
</image-gen>
|
|
99
|
+
|
|
100
|
+
JSON Format (also works):
|
|
101
|
+
\`\`\`json
|
|
102
|
+
{
|
|
103
|
+
"toolId": "image-gen",
|
|
104
|
+
"parameters": {
|
|
105
|
+
"prompt": "Detailed description",
|
|
106
|
+
"outputPath": "images/filename.png",
|
|
107
|
+
"model": "azure-openai-dalle3",
|
|
108
|
+
"size": "1024x1024"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
\`\`\`
|
|
112
|
+
|
|
113
|
+
**Parameters:**
|
|
114
|
+
- **prompt** (string, required): Detailed description of the image to generate
|
|
115
|
+
- **outputPath** (string, optional): Relative path for saving the image
|
|
116
|
+
- If specified: Saves to project directory at this path (permanent)
|
|
117
|
+
- If omitted: Saves to temp directory (auto-deleted after 1 hour)
|
|
118
|
+
- **model** (string, optional): AI model to use. Default: "azure-openai-dalle3"
|
|
119
|
+
- **size** (string, optional): Image size. Options: 256x256, 512x512, 1024x1024, 1024x1792, 1792x1024. Default: "1024x1024"
|
|
120
|
+
- **quality** (string, optional): Image quality. Options: standard, hd. Default: "standard"
|
|
121
|
+
|
|
122
|
+
**Storage Behavior:**
|
|
123
|
+
- With outputPath: Saved to project directory (permanent)
|
|
124
|
+
- Without outputPath: Saved to temp directory, auto-deleted after 1 hour
|
|
125
|
+
|
|
126
|
+
**Usage Instructions:**
|
|
127
|
+
1. When user requests an image, output the <image-gen> tag IMMEDIATELY
|
|
128
|
+
2. DO NOT ask for permission or show examples first
|
|
129
|
+
3. DO NOT explain the format - just use it
|
|
130
|
+
4. If it fails, retry with a corrected command (no explanations)
|
|
131
|
+
5. Only generate ONE image at a time (no batch mode needed)
|
|
132
|
+
|
|
133
|
+
**Correct Usage Pattern:**
|
|
134
|
+
|
|
135
|
+
User: "create a sunset image"
|
|
136
|
+
You: <image-gen>
|
|
137
|
+
<prompt>A beautiful sunset over the ocean with vibrant orange and pink colors reflecting on calm waters</prompt>
|
|
138
|
+
<output-path>images/sunset.png</output-path>
|
|
139
|
+
</image-gen>
|
|
140
|
+
|
|
141
|
+
**WRONG Usage Pattern (DO NOT DO THIS):**
|
|
142
|
+
|
|
143
|
+
User: "create a sunset image"
|
|
144
|
+
You: "I'll generate that image for you. Here's the command:
|
|
145
|
+
\`\`\`xml
|
|
146
|
+
<image-gen>...</image-gen>
|
|
147
|
+
\`\`\`
|
|
148
|
+
Do you want me to proceed?"
|
|
149
|
+
← This is WRONG because the command already executed when you showed it!
|
|
150
|
+
|
|
151
|
+
**Required Parameters:**
|
|
152
|
+
- prompt: Detailed, descriptive text (be creative and specific)
|
|
153
|
+
- model: Always use "azure-openai-dalle3"
|
|
154
|
+
- size: Use "1024x1024" for square, "1024x1792" for portrait, "1792x1024" for landscape
|
|
155
|
+
|
|
156
|
+
**Optional Parameters:**
|
|
157
|
+
- output-path: Relative path like "images/filename.png" (omit for temp file)
|
|
158
|
+
- quality: "standard" or "hd" (default: standard)
|
|
159
|
+
|
|
160
|
+
**Important Notes:**
|
|
161
|
+
- Images take 15-30 seconds to generate
|
|
162
|
+
- You'll get immediate confirmation with a job ID
|
|
163
|
+
- The image appears automatically when complete
|
|
164
|
+
- Be descriptive in prompts for better results
|
|
165
|
+
- Maximum ${IMAGE_CONFIG.QUEUE_LIMIT} images in queue at once`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Parse image generation parameters
|
|
170
|
+
* @param {string|Object} content - Raw content or parsed object
|
|
171
|
+
* @returns {Object} Parsed parameters
|
|
172
|
+
*/
|
|
173
|
+
parseParameters(content) {
|
|
174
|
+
// Handle JSON format
|
|
175
|
+
if (typeof content === 'object' && content !== null) {
|
|
176
|
+
return this._parseJSONParams(content);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Handle string format
|
|
180
|
+
if (typeof content === 'string') {
|
|
181
|
+
const trimmed = content.trim();
|
|
182
|
+
|
|
183
|
+
// Try to parse as JSON first
|
|
184
|
+
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
185
|
+
try {
|
|
186
|
+
const parsed = JSON.parse(trimmed);
|
|
187
|
+
return this._parseJSONParams(parsed);
|
|
188
|
+
} catch (err) {
|
|
189
|
+
// Not valid JSON, fall through to XML parsing
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Parse as XML
|
|
194
|
+
return this._parseXMLParams(content);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
throw new Error('Invalid parameter format');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Parse JSON parameters
|
|
202
|
+
* @private
|
|
203
|
+
*/
|
|
204
|
+
_parseJSONParams(obj) {
|
|
205
|
+
// Handle parameters wrapper (when called via toolId/parameters structure)
|
|
206
|
+
if (obj.parameters) {
|
|
207
|
+
obj = obj.parameters;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Check for batch mode
|
|
211
|
+
if (obj.batch && Array.isArray(obj.batch)) {
|
|
212
|
+
return {
|
|
213
|
+
batch: true,
|
|
214
|
+
images: obj.batch.map(img => this._parseImageParams(img))
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
batch: false,
|
|
220
|
+
images: [this._parseImageParams(obj)]
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Parse XML parameters
|
|
226
|
+
* @private
|
|
227
|
+
*/
|
|
228
|
+
_parseXMLParams(content) {
|
|
229
|
+
const params = { batch: false, images: [] };
|
|
230
|
+
|
|
231
|
+
// Check for batch mode
|
|
232
|
+
const batchMatch = /<batch>([\s\S]*?)<\/batch>/i.exec(content);
|
|
233
|
+
|
|
234
|
+
if (batchMatch) {
|
|
235
|
+
params.batch = true;
|
|
236
|
+
const batchContent = batchMatch[1];
|
|
237
|
+
|
|
238
|
+
// Extract individual <image> blocks
|
|
239
|
+
const imageRegex = /<image>([\s\S]*?)<\/image>/gi;
|
|
240
|
+
let match;
|
|
241
|
+
|
|
242
|
+
while ((match = imageRegex.exec(batchContent)) !== null) {
|
|
243
|
+
params.images.push(this._parseXMLImage(match[1]));
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
// Single image mode
|
|
247
|
+
params.images.push(this._parseXMLImage(content));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (params.images.length === 0) {
|
|
251
|
+
throw new Error('No valid image parameters found');
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return params;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Parse single image parameters from object
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
_parseImageParams(obj) {
|
|
262
|
+
const outputPath = obj.outputPath || obj['output-path'] || null;
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
prompt: obj.prompt || '',
|
|
266
|
+
outputPath: outputPath,
|
|
267
|
+
saveToProject: outputPath !== null, // If path specified, save to project
|
|
268
|
+
model: obj.model || IMAGE_CONFIG.DEFAULT_MODEL,
|
|
269
|
+
size: obj.size || IMAGE_CONFIG.DEFAULT_SIZE,
|
|
270
|
+
quality: obj.quality || IMAGE_CONFIG.DEFAULT_QUALITY
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Parse single image parameters from XML string
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
_parseXMLImage(xmlContent) {
|
|
279
|
+
const extractTag = (tag) => {
|
|
280
|
+
const regex = new RegExp(`<${tag}>([\\s\\S]*?)<\\/${tag}>`, 'i');
|
|
281
|
+
const match = regex.exec(xmlContent);
|
|
282
|
+
return match ? match[1].trim() : null;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const outputPath = extractTag('output-path') || null;
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
prompt: extractTag('prompt') || '',
|
|
289
|
+
outputPath: outputPath,
|
|
290
|
+
saveToProject: outputPath !== null, // If path specified, save to project
|
|
291
|
+
model: extractTag('model') || IMAGE_CONFIG.DEFAULT_MODEL,
|
|
292
|
+
size: extractTag('size') || IMAGE_CONFIG.DEFAULT_SIZE,
|
|
293
|
+
quality: extractTag('quality') || IMAGE_CONFIG.DEFAULT_QUALITY
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Execute image generation
|
|
299
|
+
* @param {Object|string} params - Parsed parameters object OR raw XML/JSON string
|
|
300
|
+
* @param {Object} context - Execution context
|
|
301
|
+
* @returns {Promise<Object>} Execution result
|
|
302
|
+
*/
|
|
303
|
+
async execute(params, context = {}) {
|
|
304
|
+
try {
|
|
305
|
+
const { agentId, projectDir, directoryAccess, sessionId } = context;
|
|
306
|
+
|
|
307
|
+
// Auto-detect and parse string inputs (from TagParser)
|
|
308
|
+
if (typeof params === 'string') {
|
|
309
|
+
this.logger?.info('ImageTool: Auto-parsing string parameters');
|
|
310
|
+
params = this.parseParameters(params);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Validate parameters
|
|
314
|
+
this._validateParameters(params);
|
|
315
|
+
|
|
316
|
+
// Queue images
|
|
317
|
+
const jobIds = [];
|
|
318
|
+
|
|
319
|
+
for (const imageParams of params.images) {
|
|
320
|
+
// Create job
|
|
321
|
+
const jobId = this._generateJobId();
|
|
322
|
+
|
|
323
|
+
const job = {
|
|
324
|
+
jobId,
|
|
325
|
+
agentId,
|
|
326
|
+
sessionId,
|
|
327
|
+
prompt: imageParams.prompt,
|
|
328
|
+
outputPath: imageParams.outputPath,
|
|
329
|
+
saveToProject: imageParams.saveToProject,
|
|
330
|
+
model: imageParams.model,
|
|
331
|
+
size: imageParams.size,
|
|
332
|
+
quality: imageParams.quality,
|
|
333
|
+
projectDir: projectDir || process.cwd(),
|
|
334
|
+
directoryAccess,
|
|
335
|
+
status: 'queued',
|
|
336
|
+
createdAt: new Date().toISOString()
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// Check queue limit
|
|
340
|
+
if (this.queue.length >= IMAGE_CONFIG.QUEUE_LIMIT) {
|
|
341
|
+
return {
|
|
342
|
+
success: false,
|
|
343
|
+
error: `Queue limit reached (${IMAGE_CONFIG.QUEUE_LIMIT} images). Please wait for current jobs to complete.`,
|
|
344
|
+
queueLength: this.queue.length
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
this.queue.push(job);
|
|
349
|
+
jobIds.push(jobId);
|
|
350
|
+
|
|
351
|
+
this.logger?.info(`Image generation job queued: ${jobId}`, {
|
|
352
|
+
prompt: imageParams.prompt.substring(0, 50) + '...',
|
|
353
|
+
queuePosition: this.queue.length
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Start processing if not already running
|
|
358
|
+
if (!this.isProcessing) {
|
|
359
|
+
this._processQueue().catch(err => {
|
|
360
|
+
this.logger?.error('Queue processing error:', err);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Return immediate response
|
|
365
|
+
return {
|
|
366
|
+
success: true,
|
|
367
|
+
jobIds,
|
|
368
|
+
queueLength: this.queue.length,
|
|
369
|
+
message: params.batch
|
|
370
|
+
? `${jobIds.length} images queued for generation`
|
|
371
|
+
: 'Image queued for generation',
|
|
372
|
+
estimatedWaitTime: this._estimateWaitTime()
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
} catch (error) {
|
|
376
|
+
this.logger?.error('Image generation error:', error);
|
|
377
|
+
return {
|
|
378
|
+
success: false,
|
|
379
|
+
error: error.message
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Validate parameters
|
|
386
|
+
* @private
|
|
387
|
+
*/
|
|
388
|
+
_validateParameters(params) {
|
|
389
|
+
if (!params.images || params.images.length === 0) {
|
|
390
|
+
throw new Error('No images specified');
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
for (const img of params.images) {
|
|
394
|
+
if (!img.prompt || img.prompt.trim().length === 0) {
|
|
395
|
+
throw new Error('Image prompt is required');
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (img.prompt.length > IMAGE_CONFIG.MAX_PROMPT_LENGTH) {
|
|
399
|
+
throw new Error(`Prompt too long (max ${IMAGE_CONFIG.MAX_PROMPT_LENGTH} characters)`);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (img.size && !IMAGE_CONFIG.VALID_SIZES.includes(img.size)) {
|
|
403
|
+
throw new Error(`Invalid size: ${img.size}. Valid sizes: ${IMAGE_CONFIG.VALID_SIZES.join(', ')}`);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (img.outputPath) {
|
|
407
|
+
const ext = path.extname(img.outputPath).toLowerCase().replace('.', '');
|
|
408
|
+
if (ext && !IMAGE_CONFIG.VALID_FORMATS.includes(ext)) {
|
|
409
|
+
throw new Error(`Invalid format: ${ext}. Valid formats: ${IMAGE_CONFIG.VALID_FORMATS.join(', ')}`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Process the image generation queue
|
|
417
|
+
* @private
|
|
418
|
+
*/
|
|
419
|
+
async _processQueue() {
|
|
420
|
+
if (this.isProcessing) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
this.isProcessing = true;
|
|
425
|
+
|
|
426
|
+
while (this.queue.length > 0) {
|
|
427
|
+
const job = this.queue.shift();
|
|
428
|
+
this.currentJob = job;
|
|
429
|
+
|
|
430
|
+
this.logger?.info(`Processing image generation job: ${job.jobId}`);
|
|
431
|
+
|
|
432
|
+
try {
|
|
433
|
+
job.status = 'processing';
|
|
434
|
+
|
|
435
|
+
// Generate the image
|
|
436
|
+
const result = await this._generateImage(job);
|
|
437
|
+
|
|
438
|
+
job.status = 'completed';
|
|
439
|
+
job.result = result;
|
|
440
|
+
job.completedAt = new Date().toISOString();
|
|
441
|
+
|
|
442
|
+
// Store completed job
|
|
443
|
+
this.completedJobs.set(job.jobId, job);
|
|
444
|
+
|
|
445
|
+
// Broadcast result via WebSocket
|
|
446
|
+
if (global.loxiaWebServer && job.sessionId) {
|
|
447
|
+
// Determine which URL to use: local saved file or temporary AI URL
|
|
448
|
+
let imageUrl;
|
|
449
|
+
let isTemporary = false;
|
|
450
|
+
|
|
451
|
+
if (result.savedToDisk && result.resolvedOutputPath) {
|
|
452
|
+
// Image was saved successfully - use our server endpoint
|
|
453
|
+
imageUrl = this._convertToWebUrl(result.resolvedOutputPath, job.sessionId);
|
|
454
|
+
} else if (result.temporaryUrl) {
|
|
455
|
+
// Download failed - use temporary AI-generated URL (expires in ~1 hour)
|
|
456
|
+
imageUrl = result.temporaryUrl;
|
|
457
|
+
isTemporary = true;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
global.loxiaWebServer.broadcastToSession(job.sessionId, {
|
|
461
|
+
type: 'imageGenerated',
|
|
462
|
+
agentId: job.agentId,
|
|
463
|
+
jobId: job.jobId,
|
|
464
|
+
imageUrl,
|
|
465
|
+
localPath: result.resolvedOutputPath,
|
|
466
|
+
prompt: job.prompt,
|
|
467
|
+
success: true,
|
|
468
|
+
isTemporary, // Indicates if URL will expire
|
|
469
|
+
savedToDisk: result.savedToDisk,
|
|
470
|
+
downloadError: result.downloadError, // Include error if save failed
|
|
471
|
+
timestamp: job.completedAt
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
this.logger?.info('Image generation broadcast sent', {
|
|
475
|
+
jobId: job.jobId,
|
|
476
|
+
imageUrl,
|
|
477
|
+
localPath: result.resolvedOutputPath,
|
|
478
|
+
savedToDisk: result.savedToDisk,
|
|
479
|
+
isTemporary
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
// Save image result to conversation history for persistence
|
|
483
|
+
if (this.agentPool && job.agentId) {
|
|
484
|
+
try {
|
|
485
|
+
const agent = await this.agentPool.getAgent(job.agentId);
|
|
486
|
+
if (agent) {
|
|
487
|
+
// Build message content with warnings if applicable
|
|
488
|
+
let content = `Image generated: ${job.prompt}`;
|
|
489
|
+
|
|
490
|
+
if (isTemporary) {
|
|
491
|
+
content += '\n\n⚠️ **Warning:** Image is using a temporary URL (expires in ~1 hour). Failed to save to disk.';
|
|
492
|
+
if (result.downloadError) {
|
|
493
|
+
content += `\n**Error:** ${result.downloadError}`;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Create image message for conversation history
|
|
498
|
+
const imageMessage = {
|
|
499
|
+
id: `img-result-${job.jobId}`,
|
|
500
|
+
role: 'assistant',
|
|
501
|
+
content,
|
|
502
|
+
timestamp: job.completedAt,
|
|
503
|
+
imageUrl, // CRITICAL: Include imageUrl so it persists across page refreshes
|
|
504
|
+
type: 'image-result',
|
|
505
|
+
toolId: 'image-gen',
|
|
506
|
+
status: 'completed',
|
|
507
|
+
isTemporary: isTemporary || false,
|
|
508
|
+
savedToDisk: result.savedToDisk !== false
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// Add to full conversation
|
|
512
|
+
agent.conversations.full.messages.push(imageMessage);
|
|
513
|
+
agent.conversations.full.lastUpdated = job.completedAt;
|
|
514
|
+
|
|
515
|
+
// Add to current model conversation if exists
|
|
516
|
+
if (agent.currentModel && agent.conversations[agent.currentModel]) {
|
|
517
|
+
agent.conversations[agent.currentModel].messages.push(imageMessage);
|
|
518
|
+
agent.conversations[agent.currentModel].lastUpdated = job.completedAt;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Update agent activity
|
|
522
|
+
agent.lastActivity = job.completedAt;
|
|
523
|
+
|
|
524
|
+
// Persist agent state to save conversation history
|
|
525
|
+
await this.agentPool.persistAgentState(job.agentId);
|
|
526
|
+
|
|
527
|
+
this.logger?.info('Image result saved to conversation history', {
|
|
528
|
+
agentId: job.agentId,
|
|
529
|
+
jobId: job.jobId,
|
|
530
|
+
messageId: imageMessage.id
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
} catch (error) {
|
|
534
|
+
this.logger?.error('Failed to save image result to conversation history', {
|
|
535
|
+
error: error.message,
|
|
536
|
+
agentId: job.agentId,
|
|
537
|
+
jobId: job.jobId
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
this.logger?.info(`Image generation completed: ${job.jobId}`, {
|
|
544
|
+
outputPath: result.resolvedOutputPath
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
} catch (error) {
|
|
548
|
+
this.logger?.error(`Image generation failed: ${job.jobId}`, error);
|
|
549
|
+
|
|
550
|
+
job.status = 'failed';
|
|
551
|
+
job.error = error.message;
|
|
552
|
+
job.completedAt = new Date().toISOString();
|
|
553
|
+
|
|
554
|
+
this.completedJobs.set(job.jobId, job);
|
|
555
|
+
|
|
556
|
+
// Broadcast error to specific session
|
|
557
|
+
if (global.loxiaWebServer && job.sessionId) {
|
|
558
|
+
global.loxiaWebServer.broadcastToSession(job.sessionId, {
|
|
559
|
+
type: 'imageGenerated',
|
|
560
|
+
jobId: job.jobId,
|
|
561
|
+
agentId: job.agentId,
|
|
562
|
+
prompt: job.prompt,
|
|
563
|
+
success: false,
|
|
564
|
+
error: error.message,
|
|
565
|
+
timestamp: job.completedAt
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
this.logger?.info('Image generation error broadcast sent', {
|
|
569
|
+
jobId: job.jobId,
|
|
570
|
+
sessionId: job.sessionId,
|
|
571
|
+
error: error.message
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// Save error message to conversation history
|
|
576
|
+
if (this.agentPool && job.agentId) {
|
|
577
|
+
try {
|
|
578
|
+
const agent = await this.agentPool.getAgent(job.agentId);
|
|
579
|
+
if (agent) {
|
|
580
|
+
// Create error message for conversation history
|
|
581
|
+
const errorMessage = {
|
|
582
|
+
id: `img-error-${job.jobId}`,
|
|
583
|
+
role: 'system',
|
|
584
|
+
content: `❌ Image generation failed: ${error.message}\n\n**Prompt:** ${job.prompt}`,
|
|
585
|
+
timestamp: job.completedAt,
|
|
586
|
+
type: 'error',
|
|
587
|
+
toolId: 'image-gen',
|
|
588
|
+
status: 'failed',
|
|
589
|
+
jobId: job.jobId
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// Add to full conversation
|
|
593
|
+
agent.conversations.full.messages.push(errorMessage);
|
|
594
|
+
agent.conversations.full.lastUpdated = job.completedAt;
|
|
595
|
+
|
|
596
|
+
// Add to current model conversation if exists
|
|
597
|
+
if (agent.currentModel && agent.conversations[agent.currentModel]) {
|
|
598
|
+
agent.conversations[agent.currentModel].messages.push(errorMessage);
|
|
599
|
+
agent.conversations[agent.currentModel].lastUpdated = job.completedAt;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// Update agent activity
|
|
603
|
+
agent.lastActivity = job.completedAt;
|
|
604
|
+
|
|
605
|
+
// Persist agent state to save conversation history
|
|
606
|
+
await this.agentPool.persistAgentState(job.agentId);
|
|
607
|
+
|
|
608
|
+
this.logger?.info('Image error saved to conversation history', {
|
|
609
|
+
agentId: job.agentId,
|
|
610
|
+
jobId: job.jobId,
|
|
611
|
+
error: error.message
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
} catch (historyError) {
|
|
615
|
+
this.logger?.error('Failed to save image error to conversation history', {
|
|
616
|
+
error: historyError.message,
|
|
617
|
+
agentId: job.agentId,
|
|
618
|
+
jobId: job.jobId
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
this.isProcessing = false;
|
|
626
|
+
this.currentJob = null;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Generate a single image
|
|
631
|
+
* @private
|
|
632
|
+
*/
|
|
633
|
+
async _generateImage(job) {
|
|
634
|
+
// Check if AI service is available
|
|
635
|
+
if (!this.aiService) {
|
|
636
|
+
throw new Error('AI service not available. Image generation requires AI service.');
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// Resolve output path
|
|
640
|
+
const resolvedOutputPath = await this._resolveOutputPath(job);
|
|
641
|
+
|
|
642
|
+
// Ensure directory exists
|
|
643
|
+
const outputDir = path.dirname(resolvedOutputPath);
|
|
644
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
645
|
+
|
|
646
|
+
this.logger?.info(`Generating image with ${job.model}`, {
|
|
647
|
+
size: job.size,
|
|
648
|
+
quality: job.quality
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
// Call AI service to generate image
|
|
652
|
+
const options = {
|
|
653
|
+
model: job.model,
|
|
654
|
+
size: job.size,
|
|
655
|
+
quality: job.quality,
|
|
656
|
+
responseFormat: 'url', // Get URL to download
|
|
657
|
+
sessionId: job.sessionId // CRITICAL: Pass sessionId for API key retrieval
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
const aiResult = await this.aiService.generateImage(job.prompt, options);
|
|
661
|
+
|
|
662
|
+
// AIService returns: { url, b64_json, model, requestId, revisedPrompt }
|
|
663
|
+
// Handle both 'url' and 'imageUrl' response formats
|
|
664
|
+
const imageUrl = aiResult?.url || aiResult?.imageUrl;
|
|
665
|
+
|
|
666
|
+
if (!imageUrl) {
|
|
667
|
+
throw new Error('No image URL received from AI service');
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
this.logger?.info(`Image URL received: ${imageUrl.substring(0, 50)}...`);
|
|
671
|
+
|
|
672
|
+
// Try to download and save image
|
|
673
|
+
let savedToDisk = false;
|
|
674
|
+
let downloadError = null;
|
|
675
|
+
|
|
676
|
+
try {
|
|
677
|
+
await this._downloadImage(imageUrl, resolvedOutputPath);
|
|
678
|
+
savedToDisk = true;
|
|
679
|
+
|
|
680
|
+
// Schedule cleanup if temp file
|
|
681
|
+
if (!job.saveToProject) {
|
|
682
|
+
this._scheduleCleanup(resolvedOutputPath, job.jobId);
|
|
683
|
+
}
|
|
684
|
+
} catch (error) {
|
|
685
|
+
// Download failed, but we still have the temporary URL
|
|
686
|
+
downloadError = error.message;
|
|
687
|
+
this.logger?.warn(`Failed to save image to disk, will use temporary URL: ${error.message}`);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
return {
|
|
691
|
+
jobId: job.jobId,
|
|
692
|
+
prompt: job.prompt,
|
|
693
|
+
outputPath: job.outputPath,
|
|
694
|
+
resolvedOutputPath: savedToDisk ? resolvedOutputPath : null,
|
|
695
|
+
temporaryUrl: imageUrl, // AI-generated URL (valid for ~1 hour)
|
|
696
|
+
savedToDisk,
|
|
697
|
+
downloadError,
|
|
698
|
+
success: true, // Image was generated successfully
|
|
699
|
+
model: aiResult.model || job.model,
|
|
700
|
+
size: job.size,
|
|
701
|
+
usage: aiResult.usage
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Resolve output path (temp or project directory)
|
|
707
|
+
* @private
|
|
708
|
+
*/
|
|
709
|
+
async _resolveOutputPath(job) {
|
|
710
|
+
if (job.saveToProject) {
|
|
711
|
+
// Save to project directory
|
|
712
|
+
const projectDir = job.projectDir || process.cwd();
|
|
713
|
+
|
|
714
|
+
let outputPath = job.outputPath;
|
|
715
|
+
if (!outputPath) {
|
|
716
|
+
// Auto-generate filename
|
|
717
|
+
const timestamp = Date.now();
|
|
718
|
+
outputPath = `images/generated-${timestamp}.png`;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
const resolvedPath = path.isAbsolute(outputPath)
|
|
722
|
+
? path.normalize(outputPath)
|
|
723
|
+
: path.normalize(path.join(projectDir, outputPath));
|
|
724
|
+
|
|
725
|
+
// Security: Check for path traversal
|
|
726
|
+
if (!resolvedPath.startsWith(path.normalize(projectDir))) {
|
|
727
|
+
throw new Error('Path traversal detected');
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Check directory access if provided
|
|
731
|
+
if (job.directoryAccess) {
|
|
732
|
+
// Simple check - file must be within allowed directories
|
|
733
|
+
// Full implementation would use DirectoryAccessManager
|
|
734
|
+
const relativePath = path.relative(projectDir, resolvedPath);
|
|
735
|
+
if (relativePath.startsWith('..')) {
|
|
736
|
+
throw new Error('Access denied: path outside project directory');
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
return resolvedPath;
|
|
741
|
+
} else {
|
|
742
|
+
// Save to temp directory
|
|
743
|
+
await fs.mkdir(this.tempDir, { recursive: true });
|
|
744
|
+
|
|
745
|
+
let filename = job.outputPath
|
|
746
|
+
? path.basename(job.outputPath)
|
|
747
|
+
: `generated-${job.jobId}.png`;
|
|
748
|
+
|
|
749
|
+
return path.join(this.tempDir, filename);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Download image from URL
|
|
755
|
+
* @private
|
|
756
|
+
*/
|
|
757
|
+
async _downloadImage(imageUrl, outputPath) {
|
|
758
|
+
try {
|
|
759
|
+
const response = await fetch(imageUrl, {
|
|
760
|
+
signal: AbortSignal.timeout(IMAGE_CONFIG.DOWNLOAD_TIMEOUT)
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
if (!response.ok) {
|
|
764
|
+
throw new Error(`Failed to download image: HTTP ${response.status}`);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
768
|
+
await fs.writeFile(outputPath, buffer);
|
|
769
|
+
|
|
770
|
+
this.logger?.info(`Image saved to: ${outputPath}`);
|
|
771
|
+
|
|
772
|
+
} catch (error) {
|
|
773
|
+
if (error.name === 'TimeoutError') {
|
|
774
|
+
throw new Error('Image download timeout');
|
|
775
|
+
} else if (error.name === 'TypeError') {
|
|
776
|
+
throw new Error(`Network error: ${error.message}`);
|
|
777
|
+
} else {
|
|
778
|
+
throw new Error(`Download failed: ${error.message}`);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Schedule cleanup of temp file
|
|
785
|
+
* @private
|
|
786
|
+
*/
|
|
787
|
+
_scheduleCleanup(filePath, jobId) {
|
|
788
|
+
const timer = setTimeout(async () => {
|
|
789
|
+
try {
|
|
790
|
+
await fs.unlink(filePath);
|
|
791
|
+
this.logger?.debug(`Cleaned up temp image: ${filePath}`);
|
|
792
|
+
this.cleanupTimers.delete(jobId);
|
|
793
|
+
} catch (error) {
|
|
794
|
+
// File might already be deleted, ignore
|
|
795
|
+
}
|
|
796
|
+
}, IMAGE_CONFIG.TEMP_CLEANUP_MS);
|
|
797
|
+
|
|
798
|
+
this.cleanupTimers.set(jobId, timer);
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Convert local file path to web-accessible URL
|
|
803
|
+
* @private
|
|
804
|
+
*/
|
|
805
|
+
_convertToWebUrl(localPath, sessionId) {
|
|
806
|
+
// Extract just the filename from the path
|
|
807
|
+
const filename = path.basename(localPath);
|
|
808
|
+
|
|
809
|
+
// Construct web URL using the image serving endpoint
|
|
810
|
+
// Assumes web server runs on port 8080 (can be made configurable)
|
|
811
|
+
const port = global.loxiaWebServer?.port || 8080;
|
|
812
|
+
let host = global.loxiaWebServer?.host || 'localhost';
|
|
813
|
+
|
|
814
|
+
// Convert 0.0.0.0 (server binding address) to localhost (browser-accessible)
|
|
815
|
+
// Browsers cannot connect to 0.0.0.0, even though servers can bind to it
|
|
816
|
+
if (host === '0.0.0.0') {
|
|
817
|
+
host = 'localhost';
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
return `http://${host}:${port}/api/images/${sessionId}/${filename}`;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Estimate wait time based on queue
|
|
825
|
+
* @private
|
|
826
|
+
*/
|
|
827
|
+
_estimateWaitTime() {
|
|
828
|
+
const avgGenerationTime = 30; // seconds
|
|
829
|
+
const queuePosition = this.queue.length;
|
|
830
|
+
|
|
831
|
+
if (queuePosition === 0) {
|
|
832
|
+
return '~30 seconds';
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
const estimatedSeconds = queuePosition * avgGenerationTime;
|
|
836
|
+
const minutes = Math.floor(estimatedSeconds / 60);
|
|
837
|
+
const seconds = estimatedSeconds % 60;
|
|
838
|
+
|
|
839
|
+
if (minutes > 0) {
|
|
840
|
+
return `~${minutes}m ${seconds}s`;
|
|
841
|
+
}
|
|
842
|
+
return `~${seconds}s`;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* Generate unique job ID
|
|
847
|
+
* @private
|
|
848
|
+
*/
|
|
849
|
+
_generateJobId() {
|
|
850
|
+
return `img-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* Get job status
|
|
855
|
+
* @param {string} jobId - Job ID
|
|
856
|
+
* @returns {Object} Job status
|
|
857
|
+
*/
|
|
858
|
+
getJobStatus(jobId) {
|
|
859
|
+
// Check completed jobs
|
|
860
|
+
if (this.completedJobs.has(jobId)) {
|
|
861
|
+
return this.completedJobs.get(jobId);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// Check current job
|
|
865
|
+
if (this.currentJob && this.currentJob.jobId === jobId) {
|
|
866
|
+
return this.currentJob;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// Check queue
|
|
870
|
+
const queuedJob = this.queue.find(job => job.jobId === jobId);
|
|
871
|
+
if (queuedJob) {
|
|
872
|
+
return queuedJob;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
return {
|
|
876
|
+
jobId,
|
|
877
|
+
status: 'not_found'
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Cleanup on shutdown
|
|
883
|
+
*/
|
|
884
|
+
async cleanup() {
|
|
885
|
+
this.logger?.info('Shutting down ImageTool');
|
|
886
|
+
|
|
887
|
+
// Clear all cleanup timers
|
|
888
|
+
for (const timer of this.cleanupTimers.values()) {
|
|
889
|
+
clearTimeout(timer);
|
|
890
|
+
}
|
|
891
|
+
this.cleanupTimers.clear();
|
|
892
|
+
|
|
893
|
+
// Mark queued jobs as cancelled
|
|
894
|
+
for (const job of this.queue) {
|
|
895
|
+
job.status = 'cancelled';
|
|
896
|
+
}
|
|
897
|
+
this.queue = [];
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
export default ImageTool;
|