intention-coding 0.5.2 → 0.5.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/dist/index.cjs +1194 -546
- package/dist/services/image-analysis/analyzer.d.ts +4 -18
- package/dist/services/image-analysis/analyzer.d.ts.map +1 -1
- package/dist/services/image-analysis/index.d.ts +2 -2
- package/dist/services/image-analysis/index.d.ts.map +1 -1
- package/dist/services/image-analysis/types.d.ts +1 -148
- package/dist/services/image-analysis/types.d.ts.map +1 -1
- package/dist/services/image-converter/index.d.ts +2 -2
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/project-template/index.d.ts +2 -2
- package/dist/services/requirement/index.d.ts +75 -0
- package/dist/services/requirement/index.d.ts.map +1 -0
- package/dist/services/requirement-analyzer/index.d.ts +4 -4
- package/dist/utils/dify.d.ts +24 -2
- package/dist/utils/dify.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/services/code-generator/index.d.ts +0 -50
- package/dist/services/code-generator/index.d.ts.map +0 -1
- package/dist/services/code-generator/stages/execution-stage.d.ts +0 -96
- package/dist/services/code-generator/stages/execution-stage.d.ts.map +0 -1
- package/dist/services/code-generator/stages/ideation-stage.d.ts +0 -34
- package/dist/services/code-generator/stages/ideation-stage.d.ts.map +0 -1
- package/dist/services/code-generator/stages/optimization-stage.d.ts +0 -47
- package/dist/services/code-generator/stages/optimization-stage.d.ts.map +0 -1
- package/dist/services/code-generator/stages/planning-stage.d.ts +0 -34
- package/dist/services/code-generator/stages/planning-stage.d.ts.map +0 -1
- package/dist/services/code-generator/stages/research-stage.d.ts +0 -36
- package/dist/services/code-generator/stages/research-stage.d.ts.map +0 -1
- package/dist/services/code-generator/stages/review-stage.d.ts +0 -34
- package/dist/services/code-generator/stages/review-stage.d.ts.map +0 -1
- package/dist/services/code-generator/types.d.ts +0 -233
- package/dist/services/code-generator/types.d.ts.map +0 -1
- package/dist/services/code-generator/utils/instruction-executor.d.ts +0 -70
- package/dist/services/code-generator/utils/instruction-executor.d.ts.map +0 -1
- package/dist/services/code-generator/workflow-manager.d.ts +0 -47
- package/dist/services/code-generator/workflow-manager.d.ts.map +0 -1
- package/dist/services/requirement-handler/core/agents/align-agent.d.ts +0 -31
- package/dist/services/requirement-handler/core/agents/align-agent.d.ts.map +0 -1
- package/dist/services/requirement-handler/core/agents/approve-agent.d.ts +0 -33
- package/dist/services/requirement-handler/core/agents/approve-agent.d.ts.map +0 -1
- package/dist/services/requirement-handler/core/agents/architect-agent.d.ts +0 -29
- package/dist/services/requirement-handler/core/agents/architect-agent.d.ts.map +0 -1
- package/dist/services/requirement-handler/core/agents/assess-agent.d.ts +0 -53
- package/dist/services/requirement-handler/core/agents/assess-agent.d.ts.map +0 -1
- package/dist/services/requirement-handler/core/agents/atomize-agent.d.ts +0 -33
- package/dist/services/requirement-handler/core/agents/atomize-agent.d.ts.map +0 -1
- package/dist/services/requirement-handler/core/agents/automate-agent.d.ts +0 -43
- package/dist/services/requirement-handler/core/agents/automate-agent.d.ts.map +0 -1
- package/dist/services/requirement-handler/core/requirement-handler-service.d.ts +0 -35
- package/dist/services/requirement-handler/core/requirement-handler-service.d.ts.map +0 -1
- package/dist/services/requirement-handler/core/types.d.ts +0 -143
- package/dist/services/requirement-handler/core/types.d.ts.map +0 -1
- package/dist/services/requirement-handler/index.d.ts +0 -87
- package/dist/services/requirement-handler/index.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -66,7 +66,7 @@ var __webpack_exports__ = {};
|
|
|
66
66
|
try {
|
|
67
67
|
if (process.env.LOG_DIR) logDir = process.env.LOG_DIR;
|
|
68
68
|
else {
|
|
69
|
-
const storageDir =
|
|
69
|
+
const storageDir = config_getStorageDir();
|
|
70
70
|
logDir = storageDir ? storageDir + '/logs' : './.aico/logs';
|
|
71
71
|
}
|
|
72
72
|
} catch (error) {
|
|
@@ -130,7 +130,7 @@ var __webpack_exports__ = {};
|
|
|
130
130
|
format: fileFormat,
|
|
131
131
|
level: 'info'
|
|
132
132
|
}));
|
|
133
|
-
const
|
|
133
|
+
const logger_logger = external_winston_default().createLogger({
|
|
134
134
|
level: 'debug',
|
|
135
135
|
levels,
|
|
136
136
|
format: external_winston_default().format.combine(external_winston_default().format.errors({
|
|
@@ -159,8 +159,8 @@ var __webpack_exports__ = {};
|
|
|
159
159
|
] : []
|
|
160
160
|
});
|
|
161
161
|
process.on('SIGINT', ()=>{
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
logger_logger.end(()=>{
|
|
163
|
+
logger_logger.info("\u65E5\u5FD7\u5DF2\u5173\u95ED");
|
|
164
164
|
process.exit(0);
|
|
165
165
|
});
|
|
166
166
|
});
|
|
@@ -243,7 +243,7 @@ var __webpack_exports__ = {};
|
|
|
243
243
|
const contextManager = new ContextManager();
|
|
244
244
|
const detectProjectRoot = (enableLogging = false)=>{
|
|
245
245
|
if (process.env.MCP_STORAGE_DIR) {
|
|
246
|
-
if (enableLogging)
|
|
246
|
+
if (enableLogging) logger_logger.info(`\u{4F7F}\u{7528}\u{73AF}\u{5883}\u{53D8}\u{91CF} MCP_STORAGE_DIR: ${process.env.MCP_STORAGE_DIR}`);
|
|
247
247
|
return process.env.MCP_STORAGE_DIR;
|
|
248
248
|
}
|
|
249
249
|
let currentDir = process.cwd();
|
|
@@ -254,12 +254,12 @@ var __webpack_exports__ = {};
|
|
|
254
254
|
'pyproject.toml',
|
|
255
255
|
'go.mod'
|
|
256
256
|
];
|
|
257
|
-
if (enableLogging)
|
|
257
|
+
if (enableLogging) logger_logger.info(`\u{5F00}\u{59CB}\u{4ECE}\u{5F53}\u{524D}\u{76EE}\u{5F55}\u{68C0}\u{6D4B}\u{9879}\u{76EE}\u{6839}\u{76EE}\u{5F55}: ${currentDir}`);
|
|
258
258
|
while('/' !== currentDir){
|
|
259
259
|
for (const marker of markers){
|
|
260
260
|
const markerPath = (0, external_path_namespaceObject.resolve)(currentDir, marker);
|
|
261
261
|
if (external_fs_namespaceObject.existsSync(markerPath)) {
|
|
262
|
-
if (enableLogging)
|
|
262
|
+
if (enableLogging) logger_logger.info(`\u{627E}\u{5230}\u{9879}\u{76EE}\u{6807}\u{8BB0}\u{6587}\u{4EF6} ${marker} \u{5728}: ${currentDir}`);
|
|
263
263
|
return currentDir;
|
|
264
264
|
}
|
|
265
265
|
}
|
|
@@ -267,7 +267,7 @@ var __webpack_exports__ = {};
|
|
|
267
267
|
if (parentDir === currentDir) break;
|
|
268
268
|
currentDir = parentDir;
|
|
269
269
|
}
|
|
270
|
-
if (enableLogging)
|
|
270
|
+
if (enableLogging) logger_logger.warn(`\u{672A}\u{627E}\u{5230}\u{9879}\u{76EE}\u{6807}\u{8BB0}\u{6587}\u{4EF6}\u{FF0C}\u{4F7F}\u{7528}\u{5F53}\u{524D}\u{5DE5}\u{4F5C}\u{76EE}\u{5F55}: ${process.cwd()}`);
|
|
271
271
|
return process.cwd();
|
|
272
272
|
};
|
|
273
273
|
let _PROJECT_ROOT = null;
|
|
@@ -289,9 +289,9 @@ var __webpack_exports__ = {};
|
|
|
289
289
|
_PROJECT_ROOT = detectedRoot;
|
|
290
290
|
if (!process.env.MCP_STORAGE_DIR) process.env.MCP_STORAGE_DIR = detectedRoot;
|
|
291
291
|
contextManager.setCachedData("project_root", detectedRoot);
|
|
292
|
-
|
|
292
|
+
logger_logger.info(`\u{9879}\u{76EE}\u{6839}\u{76EE}\u{5F55}\u{5DF2}\u{8BBE}\u{7F6E}\u{4E3A}: ${detectedRoot}`);
|
|
293
293
|
};
|
|
294
|
-
const
|
|
294
|
+
const config_getStorageDir = ()=>{
|
|
295
295
|
try {
|
|
296
296
|
const cachedRoot = contextManager.getCachedData("project_root");
|
|
297
297
|
if (cachedRoot && 'string' == typeof cachedRoot) return cachedRoot + "/.aico";
|
|
@@ -317,7 +317,7 @@ var __webpack_exports__ = {};
|
|
|
317
317
|
const external_html_to_md_namespaceObject = require("html-to-md");
|
|
318
318
|
var external_html_to_md_default = /*#__PURE__*/ __webpack_require__.n(external_html_to_md_namespaceObject);
|
|
319
319
|
const external_os_namespaceObject = require("os");
|
|
320
|
-
const
|
|
320
|
+
const common_sanitizeFileName = (input)=>input.replace(/[\\/:*?"<>|\n\r#%&]/g, '').trim().replace(/\s+/g, '_').replace(/_+/g, '_').replace(/^_+|_+$/g, '');
|
|
321
321
|
function normalizePath(filePath) {
|
|
322
322
|
if (!filePath || 'string' != typeof filePath) throw new Error("\u6587\u4EF6\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A");
|
|
323
323
|
filePath = filePath.trim().replace(/^["']|["']$/g, '');
|
|
@@ -329,14 +329,14 @@ var __webpack_exports__ = {};
|
|
|
329
329
|
const resolved = external_path_default().resolve(normalized);
|
|
330
330
|
return resolved;
|
|
331
331
|
}
|
|
332
|
-
async function
|
|
332
|
+
async function common_validateAndResolvePath(filePath) {
|
|
333
333
|
if (!filePath) throw new Error("\u6587\u4EF6\u8DEF\u5F84\u53C2\u6570\u7F3A\u5931\uFF0C\u8BF7\u63D0\u4F9B filePath \u53C2\u6570");
|
|
334
334
|
const resolved = normalizePath(filePath);
|
|
335
335
|
try {
|
|
336
336
|
await external_fs_namespaceObject.promises.access(resolved, external_fs_namespaceObject.constants.R_OK);
|
|
337
337
|
} catch (error) {
|
|
338
338
|
const osInfo = `[${process.platform}]`;
|
|
339
|
-
|
|
339
|
+
logger_logger.warn(`\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}\u{6216}\u{4E0D}\u{53EF}\u{8BFB} ${osInfo}: ${resolved}`, error);
|
|
340
340
|
throw new Error(`\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}\u{6216}\u{4E0D}\u{53EF}\u{8BFB} ${osInfo}: ${resolved}`);
|
|
341
341
|
}
|
|
342
342
|
return resolved;
|
|
@@ -3968,9 +3968,9 @@ var __webpack_exports__ = {};
|
|
|
3968
3968
|
const { filePath } = args;
|
|
3969
3969
|
if (!filePath) throw new Error("\u6587\u4EF6\u8DEF\u5F84\u53C2\u6570\u7F3A\u5931\uFF0C\u8BF7\u63D0\u4F9B filePath \u53C2\u6570");
|
|
3970
3970
|
try {
|
|
3971
|
-
const resolvedPath = await
|
|
3971
|
+
const resolvedPath = await common_validateAndResolvePath(filePath);
|
|
3972
3972
|
const buffer = await promises_namespaceObject.readFile(resolvedPath);
|
|
3973
|
-
const mdDir = external_path_default().join(
|
|
3973
|
+
const mdDir = external_path_default().join(config_getStorageDir(), 'md');
|
|
3974
3974
|
const baseName = external_path_default().basename(filePath, '.docx');
|
|
3975
3975
|
const outputDir = external_path_default().join(mdDir, baseName);
|
|
3976
3976
|
const imgsDir = external_path_default().join(outputDir, 'imgs');
|
|
@@ -3980,7 +3980,7 @@ var __webpack_exports__ = {};
|
|
|
3980
3980
|
await promises_namespaceObject.mkdir(imgsDir, {
|
|
3981
3981
|
recursive: true
|
|
3982
3982
|
});
|
|
3983
|
-
|
|
3983
|
+
logger_logger.info("\u5F00\u59CB\u8F6C\u6362Word\u6587\u6863", {
|
|
3984
3984
|
file: filePath,
|
|
3985
3985
|
outputDir,
|
|
3986
3986
|
imgsDir
|
|
@@ -4006,7 +4006,7 @@ var __webpack_exports__ = {};
|
|
|
4006
4006
|
await promises_namespaceObject.writeFile(imagePath, imageBuffer);
|
|
4007
4007
|
htmlContent = htmlContent.replace(img.fullMatch, `<img src="./imgs/${imageFileName}" />`);
|
|
4008
4008
|
} catch (err) {
|
|
4009
|
-
|
|
4009
|
+
logger_logger.error("\u56FE\u7247\u5904\u7406\u5931\u8D25", {
|
|
4010
4010
|
error: err instanceof Error ? err.message : String(err),
|
|
4011
4011
|
imageNumber: i + 1
|
|
4012
4012
|
});
|
|
@@ -4017,7 +4017,7 @@ var __webpack_exports__ = {};
|
|
|
4017
4017
|
value: htmlContent,
|
|
4018
4018
|
messages: basicResult.messages
|
|
4019
4019
|
};
|
|
4020
|
-
if (htmlResult.messages && htmlResult.messages.length > 0)
|
|
4020
|
+
if (htmlResult.messages && htmlResult.messages.length > 0) logger_logger.warn("Word\u8F6C\u6362\u8B66\u544A", {
|
|
4021
4021
|
file: filePath,
|
|
4022
4022
|
warnings: htmlResult.messages
|
|
4023
4023
|
});
|
|
@@ -4042,7 +4042,7 @@ var __webpack_exports__ = {};
|
|
|
4042
4042
|
};
|
|
4043
4043
|
} catch (error) {
|
|
4044
4044
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
4045
|
-
|
|
4045
|
+
logger_logger.error(`Word\u{8F6C}\u{6362}\u{5931}\u{8D25}: ${errorMsg}`, {
|
|
4046
4046
|
tool: "word2md",
|
|
4047
4047
|
filePath
|
|
4048
4048
|
});
|
|
@@ -4094,17 +4094,17 @@ var __webpack_exports__ = {};
|
|
|
4094
4094
|
const { preserve_formatting = true, extract_metadata = true } = options;
|
|
4095
4095
|
try {
|
|
4096
4096
|
initializeProjectRoot();
|
|
4097
|
-
const resolvedPath = await
|
|
4097
|
+
const resolvedPath = await common_validateAndResolvePath(file_path);
|
|
4098
4098
|
if (!file_path.toLowerCase().endsWith('.pdf')) throw new Error("\u6587\u4EF6\u5FC5\u987B\u662FPDF\u683C\u5F0F\uFF08.pdf\u6269\u5C55\u540D\uFF09");
|
|
4099
|
-
|
|
4099
|
+
logger_logger.info("\u5F00\u59CB\u8BFB\u53D6PDF\u6587\u4EF6", {
|
|
4100
4100
|
file: file_path
|
|
4101
4101
|
});
|
|
4102
4102
|
const dataBuffer = await promises_namespaceObject.readFile(resolvedPath);
|
|
4103
|
-
|
|
4103
|
+
logger_logger.info("\u5F00\u59CB\u89E3\u6790PDF\u5185\u5BB9");
|
|
4104
4104
|
const pdfParse = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "pdf-parse/lib/pdf-parse.js"));
|
|
4105
4105
|
const pdfData = await pdfParse.default(dataBuffer);
|
|
4106
|
-
const mdDir = external_path_default().join(
|
|
4107
|
-
const baseName =
|
|
4106
|
+
const mdDir = external_path_default().join(config_getStorageDir(), 'md');
|
|
4107
|
+
const baseName = common_sanitizeFileName(external_path_default().basename(file_path, '.pdf'));
|
|
4108
4108
|
const outputDir = external_path_default().join(mdDir, baseName);
|
|
4109
4109
|
await promises_namespaceObject.mkdir(outputDir, {
|
|
4110
4110
|
recursive: true
|
|
@@ -4133,7 +4133,7 @@ var __webpack_exports__ = {};
|
|
|
4133
4133
|
markdownLength: markdownContent.length,
|
|
4134
4134
|
outputFile: external_path_default().resolve(fullMdPath)
|
|
4135
4135
|
};
|
|
4136
|
-
|
|
4136
|
+
logger_logger.info("PDF\u8F6C\u6362\u5B8C\u6210", stats);
|
|
4137
4137
|
return {
|
|
4138
4138
|
content: [
|
|
4139
4139
|
{
|
|
@@ -4160,7 +4160,7 @@ var __webpack_exports__ = {};
|
|
|
4160
4160
|
};
|
|
4161
4161
|
} catch (error) {
|
|
4162
4162
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
4163
|
-
|
|
4163
|
+
logger_logger.error(`PDF\u{8F6C}\u{6362}\u{5931}\u{8D25}: ${errorMsg}`, {
|
|
4164
4164
|
tool: "pdf2md",
|
|
4165
4165
|
file_path,
|
|
4166
4166
|
error: errorMsg
|
|
@@ -4181,188 +4181,7 @@ var __webpack_exports__ = {};
|
|
|
4181
4181
|
}
|
|
4182
4182
|
}
|
|
4183
4183
|
};
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
\u{8BF7}\u{6309}\u{4EE5}\u{4E0B}\u{6B65}\u{9AA4}\u{8FDB}\u{884C}\u{5206}\u{6790}\u{FF1A}
|
|
4187
|
-
|
|
4188
|
-
## 1. \u{4EE3}\u{7801}\u{5E93}\u{5206}\u{6790}
|
|
4189
|
-
\u{5206}\u{6790}\u{5F53}\u{524D}\u{4EE3}\u{7801}\u{5E93}\u{FF0C}\u{603B}\u{7ED3}\u{FF1A}
|
|
4190
|
-
- \u{4E3B}\u{8981}\u{529F}\u{80FD}\u{6A21}\u{5757}\u{53CA}\u{5176}\u{5B9E}\u{73B0}
|
|
4191
|
-
- \u{5173}\u{952E}\u{4E1A}\u{52A1}\u{903B}\u{8F91}\u{6D41}\u{7A0B}
|
|
4192
|
-
- \u{91CD}\u{8981}\u{6570}\u{636E}\u{7ED3}\u{6784}
|
|
4193
|
-
- \u{6838}\u{5FC3}\u{7B97}\u{6CD5}\u{5B9E}\u{73B0}
|
|
4194
|
-
|
|
4195
|
-
## 2. \u{63A5}\u{53E3}\u{4E0E}\u{9700}\u{6C42}\u{5BF9}\u{5E94}\u{5173}\u{7CFB}\u{8868}
|
|
4196
|
-
\u{6839}\u{636E}\u{4EE3}\u{7801}\u{53D8}\u{66F4}\u{FF0C}\u{751F}\u{6210}\u{63A5}\u{53E3}\u{4E0E}\u{9700}\u{6C42}\u{5BF9}\u{5E94}\u{5173}\u{7CFB}\u{8868}\u{FF1A}
|
|
4197
|
-
|
|
4198
|
-
| \u{9700}\u{6C42}\u{529F}\u{80FD} | \u{5B9E}\u{73B0}\u{63A5}\u{53E3} | \u{8BF7}\u{6C42}\u{65B9}\u{5F0F} | URL | \u{53D8}\u{66F4}\u{72B6}\u{6001} |
|
|
4199
|
-
|---------|---------|---------|-----|----------|
|
|
4200
|
-
| [\u{9700}\u{6C42}\u{529F}\u{80FD}\u{63CF}\u{8FF0}] | [Controller.method] | [GET/POST/PUT/DELETE] | [/api/path] | [\u{65B0}\u{589E}/\u{4FEE}\u{6539}/\u{5220}\u{9664}] |
|
|
4201
|
-
|
|
4202
|
-
## 3. \u{6838}\u{5FC3}\u{903B}\u{8F91}\u{65B9}\u{6CD5}\u{8868}
|
|
4203
|
-
\u{5206}\u{6790}\u{6838}\u{5FC3}\u{4E1A}\u{52A1}\u{903B}\u{8F91}\u{65B9}\u{6CD5}\u{FF1A}
|
|
4204
|
-
|
|
4205
|
-
| \u{65B9}\u{6CD5}\u{540D}\u{79F0} | \u{6240}\u{5C5E}\u{7C7B} | \u{529F}\u{80FD}\u{8BF4}\u{660E} | \u{53D8}\u{66F4}\u{72B6}\u{6001} |
|
|
4206
|
-
|---------|-------|---------|----------|
|
|
4207
|
-
| [methodName] | [ClassName] | [\u{529F}\u{80FD}\u{63CF}\u{8FF0}] | [\u{65B0}\u{589E}/\u{4FEE}\u{6539}/\u{5220}\u{9664}] |
|
|
4208
|
-
|
|
4209
|
-
## 4. \u{524D}\u{7AEF}\u{9875}\u{9762}\u{4E0E}\u{63A5}\u{53E3}\u{5BF9}\u{5E94}\u{5173}\u{7CFB}\u{8868}
|
|
4210
|
-
\u{5206}\u{6790}\u{524D}\u{7AEF}\u{9875}\u{9762}\u{53D8}\u{66F4}\u{FF1A}
|
|
4211
|
-
|
|
4212
|
-
| \u{9875}\u{9762}\u{540D}\u{79F0} | \u{8C03}\u{7528}\u{63A5}\u{53E3} | \u{7EC4}\u{4EF6}\u{540D}\u{79F0} | \u{8DEF}\u{7531}\u{8DEF}\u{5F84} | \u{53D8}\u{66F4}\u{72B6}\u{6001} |
|
|
4213
|
-
|---------|---------|---------|---------|----------|
|
|
4214
|
-
| [\u{9875}\u{9762}\u{540D}\u{79F0}] | [Controller.method] | [ComponentName] | [/path] | [\u{65B0}\u{589E}/\u{4FEE}\u{6539}/\u{5220}\u{9664}] |
|
|
4215
|
-
|
|
4216
|
-
## 5. \u{524D}\u{7AEF}\u{6838}\u{5FC3}\u{7EC4}\u{4EF6}\u{8868}
|
|
4217
|
-
\u{5206}\u{6790}\u{524D}\u{7AEF}\u{7EC4}\u{4EF6}\u{53D8}\u{66F4}\u{FF1A}
|
|
4218
|
-
|
|
4219
|
-
| \u{7EC4}\u{4EF6}\u{540D}\u{79F0} | \u{6240}\u{5C5E}\u{9875}\u{9762} | \u{529F}\u{80FD}\u{8BF4}\u{660E} | \u{53D8}\u{66F4}\u{72B6}\u{6001} |
|
|
4220
|
-
|---------|---------|---------|----------|
|
|
4221
|
-
| [ComponentName] | [PageName] | [\u{529F}\u{80FD}\u{63CF}\u{8FF0}] | [\u{65B0}\u{589E}/\u{4FEE}\u{6539}/\u{5220}\u{9664}] |
|
|
4222
|
-
|
|
4223
|
-
## 6. \u{9700}\u{6C42}\u{5B8C}\u{6574}\u{6027}\u{68C0}\u{67E5}
|
|
4224
|
-
\u{5BF9}\u{6BD4}\u{539F}\u{59CB}\u{9700}\u{6C42}\u{FF0C}\u{68C0}\u{67E5}\u{FF1A}
|
|
4225
|
-
- \u{2705} \u{5DF2}\u{5B8C}\u{6210}\u{7684}\u{529F}\u{80FD}
|
|
4226
|
-
- \u{26A0}\u{FE0F} \u{90E8}\u{5206}\u{5B8C}\u{6210}\u{7684}\u{529F}\u{80FD}
|
|
4227
|
-
- \u{274C} \u{672A}\u{5B9E}\u{73B0}\u{7684}\u{529F}\u{80FD}
|
|
4228
|
-
- \u{1F504} \u{9700}\u{8981}\u{8FDB}\u{4E00}\u{6B65}\u{5B8C}\u{5584}\u{7684}\u{529F}\u{80FD}
|
|
4229
|
-
|
|
4230
|
-
## 7. \u{5EFA}\u{8BAE}\u{4E0E}\u{603B}\u{7ED3}
|
|
4231
|
-
- \u{5B9E}\u{73B0}\u{8D28}\u{91CF}\u{8BC4}\u{4F30}
|
|
4232
|
-
- \u{6F5C}\u{5728}\u{95EE}\u{9898}\u{8BC6}\u{522B}
|
|
4233
|
-
- \u{540E}\u{7EED}\u{5F00}\u{53D1}\u{5EFA}\u{8BAE}
|
|
4234
|
-
- \u{6D4B}\u{8BD5}\u{5EFA}\u{8BAE}
|
|
4235
|
-
|
|
4236
|
-
\u{8BF7}\u{786E}\u{4FDD}\u{6240}\u{6709}\u{8868}\u{683C}\u{4E0A}\u{4E0B}\u{5BF9}\u{9F50}\u{FF0C}\u{5185}\u{5BB9}\u{8BE6}\u{5B9E}\u{51C6}\u{786E}\u{3002}`;
|
|
4237
|
-
objectType({
|
|
4238
|
-
baseBranch: stringType().default('main').describe("\u57FA\u51C6\u5206\u652F\u540D\u79F0\uFF0C\u7528\u4E8E\u5BF9\u6BD4\u53D8\u66F4"),
|
|
4239
|
-
requirementFile: stringType().optional().describe("\u9700\u6C42\u6587\u6863\u6587\u4EF6\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09"),
|
|
4240
|
-
includeUncommitted: booleanType().default(true).describe("\u662F\u5426\u5305\u542B\u672A\u63D0\u4EA4\u7684\u53D8\u66F4"),
|
|
4241
|
-
outputFormat: enumType([
|
|
4242
|
-
'markdown',
|
|
4243
|
-
'json'
|
|
4244
|
-
]).default('markdown').describe("\u8F93\u51FA\u683C\u5F0F")
|
|
4245
|
-
});
|
|
4246
|
-
const changeSummarizer = {
|
|
4247
|
-
name: "\u4EE3\u7801\u53D8\u66F4\u5206\u6790\u667A\u80FD\u4F53",
|
|
4248
|
-
description: "\u5206\u6790\u4EE3\u7801\u5E76\u4E0E\u9700\u6C42\u8FDB\u884C\u5BF9\u6BD4\uFF0C\u786E\u4FDD\u5B9E\u73B0\u5B8C\u6574\u6027",
|
|
4249
|
-
inputSchema: {
|
|
4250
|
-
baseBranch: stringType().default('main').describe("\u57FA\u51C6\u5206\u652F\u540D\u79F0\uFF0C\u7528\u4E8E\u5BF9\u6BD4\u53D8\u66F4"),
|
|
4251
|
-
requirementFile: stringType().optional().describe("\u9700\u6C42\u6587\u6863\u6587\u4EF6\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09"),
|
|
4252
|
-
includeUncommitted: booleanType().default(true).describe("\u662F\u5426\u5305\u542B\u672A\u63D0\u4EA4\u7684\u53D8\u66F4"),
|
|
4253
|
-
outputFormat: enumType([
|
|
4254
|
-
'markdown',
|
|
4255
|
-
'json'
|
|
4256
|
-
]).default('markdown').describe("\u8F93\u51FA\u683C\u5F0F")
|
|
4257
|
-
},
|
|
4258
|
-
handler: async (args)=>{
|
|
4259
|
-
try {
|
|
4260
|
-
initializeProjectRoot();
|
|
4261
|
-
console.log('[CHANGE-SUMMARIZER DEBUG] args:', JSON.stringify(args, null, 2));
|
|
4262
|
-
console.log('[CHANGE-SUMMARIZER DEBUG] args.baseBranch:', args.baseBranch);
|
|
4263
|
-
console.log('[CHANGE-SUMMARIZER DEBUG] args.outputFormat:', args.outputFormat);
|
|
4264
|
-
logger.info({
|
|
4265
|
-
module: 'change-summarizer',
|
|
4266
|
-
message: 'Starting code analysis',
|
|
4267
|
-
args
|
|
4268
|
-
});
|
|
4269
|
-
let requirementContent = '';
|
|
4270
|
-
if (args.requirementFile && external_fs_default().existsSync(args.requirementFile)) requirementContent = external_fs_default().readFileSync(args.requirementFile, 'utf-8');
|
|
4271
|
-
const analysisPrompt = buildAnalysisPrompt(requirementContent);
|
|
4272
|
-
const outputPath = await saveAnalysisResult(analysisPrompt, args.outputFormat);
|
|
4273
|
-
logger.info({
|
|
4274
|
-
module: 'change-summarizer',
|
|
4275
|
-
message: 'Code analysis completed',
|
|
4276
|
-
outputPath
|
|
4277
|
-
});
|
|
4278
|
-
return {
|
|
4279
|
-
content: [
|
|
4280
|
-
{
|
|
4281
|
-
type: "text",
|
|
4282
|
-
text: JSON.stringify({
|
|
4283
|
-
success: true,
|
|
4284
|
-
message: "\u4EE3\u7801\u53D8\u66F4\u5206\u6790\u667A\u80FD\u4F53\u6D4B\u8BD5\u6210\u529F",
|
|
4285
|
-
data: {
|
|
4286
|
-
baseBranch: args.baseBranch || 'main',
|
|
4287
|
-
outputFormat: args.outputFormat || 'markdown'
|
|
4288
|
-
}
|
|
4289
|
-
})
|
|
4290
|
-
}
|
|
4291
|
-
]
|
|
4292
|
-
};
|
|
4293
|
-
} catch (error) {
|
|
4294
|
-
logger.error({
|
|
4295
|
-
module: 'change-summarizer',
|
|
4296
|
-
message: 'Code analysis failed',
|
|
4297
|
-
error: error instanceof Error ? error.message : String(error)
|
|
4298
|
-
});
|
|
4299
|
-
return {
|
|
4300
|
-
content: [
|
|
4301
|
-
{
|
|
4302
|
-
type: "text",
|
|
4303
|
-
text: JSON.stringify({
|
|
4304
|
-
success: false,
|
|
4305
|
-
message: `\u{4EE3}\u{7801}\u{53D8}\u{66F4}\u{5206}\u{6790}\u{667A}\u{80FD}\u{4F53}\u{6267}\u{884C}\u{5931}\u{8D25}: ${error instanceof Error ? error.message : String(error)}`,
|
|
4306
|
-
data: null
|
|
4307
|
-
})
|
|
4308
|
-
}
|
|
4309
|
-
],
|
|
4310
|
-
isError: true
|
|
4311
|
-
};
|
|
4312
|
-
}
|
|
4313
|
-
}
|
|
4314
|
-
};
|
|
4315
|
-
changeSummarizer.handler = changeSummarizer.handler;
|
|
4316
|
-
function buildAnalysisPrompt(requirementContent) {
|
|
4317
|
-
const changesSection = `
|
|
4318
|
-
## \u{4EE3}\u{7801}\u{4E0A}\u{4E0B}\u{6587}\u{5206}\u{6790}
|
|
4319
|
-
|
|
4320
|
-
\u{8BF7}\u{57FA}\u{4E8E}\u{4EE5}\u{4E0B}\u{5185}\u{5BB9}\u{8FDB}\u{884C}\u{5206}\u{6790}\u{FF1A}
|
|
4321
|
-
- \u{5F53}\u{524D}\u{4EE3}\u{7801}\u{5E93}\u{7684}\u{6574}\u{4F53}\u{7ED3}\u{6784}
|
|
4322
|
-
- \u{4E3B}\u{8981}\u{529F}\u{80FD}\u{6A21}\u{5757}\u{7684}\u{5B9E}\u{73B0}
|
|
4323
|
-
- \u{5173}\u{952E}\u{4E1A}\u{52A1}\u{903B}\u{8F91}
|
|
4324
|
-
- \u{63A5}\u{53E3}\u{5B9A}\u{4E49}\u{4E0E}\u{5B9E}\u{73B0}
|
|
4325
|
-
- \u{524D}\u{7AEF}\u{7EC4}\u{4EF6}\u{4E0E}\u{9875}\u{9762}
|
|
4326
|
-
`;
|
|
4327
|
-
const requirementSection = requirementContent ? `
|
|
4328
|
-
## \u{9700}\u{6C42}\u{6587}\u{6863}\u{5185}\u{5BB9}
|
|
4329
|
-
${requirementContent}
|
|
4330
|
-
` : `
|
|
4331
|
-
## \u{9700}\u{6C42}\u{6587}\u{6863}
|
|
4332
|
-
\u{672A}\u{63D0}\u{4F9B}\u{9700}\u{6C42}\u{6587}\u{6863}\u{FF0C}\u{8BF7}\u{57FA}\u{4E8E}\u{4EE3}\u{7801}\u{53D8}\u{66F4}\u{8FDB}\u{884C}\u{5206}\u{6790}\u{3002}
|
|
4333
|
-
`;
|
|
4334
|
-
return `
|
|
4335
|
-
${changeAnalysisPrompt}
|
|
4336
|
-
|
|
4337
|
-
${changesSection}
|
|
4338
|
-
|
|
4339
|
-
${requirementSection}
|
|
4340
|
-
|
|
4341
|
-
\u{8BF7}\u{57FA}\u{4E8E}\u{4EE5}\u{4E0A}\u{4FE1}\u{606F}\u{8FDB}\u{884C}\u{8BE6}\u{7EC6}\u{5206}\u{6790}\u{3002}
|
|
4342
|
-
`;
|
|
4343
|
-
}
|
|
4344
|
-
async function saveAnalysisResult(prompt, format) {
|
|
4345
|
-
const storageDir = getStorageDir();
|
|
4346
|
-
if (!storageDir || 'string' != typeof storageDir) throw new Error("\u5B58\u50A8\u76EE\u5F55\u914D\u7F6E\u9519\u8BEF\uFF0C\u65E0\u6CD5\u4FDD\u5B58\u5206\u6790\u7ED3\u679C");
|
|
4347
|
-
const outputDir = external_path_default().join(storageDir, 'change-analysis');
|
|
4348
|
-
if (!external_fs_default().existsSync(outputDir)) external_fs_default().mkdirSync(outputDir, {
|
|
4349
|
-
recursive: true
|
|
4350
|
-
});
|
|
4351
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
4352
|
-
const filename = `change-analysis-${timestamp}.${'json' === format ? 'json' : 'md'}`;
|
|
4353
|
-
const outputPath = external_path_default().join(outputDir, filename);
|
|
4354
|
-
if ('json' === format) {
|
|
4355
|
-
const jsonData = {
|
|
4356
|
-
timestamp: new Date().toISOString(),
|
|
4357
|
-
prompt,
|
|
4358
|
-
type: 'change-analysis'
|
|
4359
|
-
};
|
|
4360
|
-
external_fs_default().writeFileSync(outputPath, JSON.stringify(jsonData, null, 2), 'utf-8');
|
|
4361
|
-
} else external_fs_default().writeFileSync(outputPath, prompt, 'utf-8');
|
|
4362
|
-
return outputPath;
|
|
4363
|
-
}
|
|
4364
|
-
const external_sharp_namespaceObject = require("sharp");
|
|
4365
|
-
var external_sharp_default = /*#__PURE__*/ __webpack_require__.n(external_sharp_namespaceObject);
|
|
4184
|
+
require("aico-pack");
|
|
4366
4185
|
class OpenAIService {
|
|
4367
4186
|
qwenConfig = {
|
|
4368
4187
|
apiKey: 'sk-95b0bc60b7464bbbafd64edc2f5bab14',
|
|
@@ -4683,25 +4502,462 @@ ${requirementSection}
|
|
|
4683
4502
|
}
|
|
4684
4503
|
}
|
|
4685
4504
|
}
|
|
4686
|
-
const
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4505
|
+
const openai_openAIService = new OpenAIService();
|
|
4506
|
+
objectType({
|
|
4507
|
+
input_type: enumType([
|
|
4508
|
+
"text",
|
|
4509
|
+
"md_file"
|
|
4510
|
+
]).describe("\u8F93\u5165\u7C7B\u578B\uFF1A\u76F4\u63A5\u6587\u672C\u8F93\u5165\u6216\u5F15\u7528\u5DF2\u751F\u6210\u7684MD\u6587\u4EF6"),
|
|
4511
|
+
content: stringType().optional().describe("\u5F53input_type\u4E3Atext\u65F6\uFF0C\u76F4\u63A5\u8F93\u5165\u7684\u9700\u6C42\u5185\u5BB9"),
|
|
4512
|
+
md_file_path: stringType().optional().describe("\u5F53input_type\u4E3Amd_file\u65F6\uFF0C\u8981\u5206\u6790\u7684MD\u6587\u4EF6\u8DEF\u5F84"),
|
|
4513
|
+
feature_name: stringType().describe("\u529F\u80FD\u540D\u79F0\uFF0C\u7528\u4E8E\u751F\u6210\u8F93\u51FA\u6587\u4EF6\u540D"),
|
|
4514
|
+
custom_prompt: stringType().optional().describe("\u81EA\u5B9A\u4E49\u63D0\u793A\u8BCD\uFF0C\u7528\u4E8E\u6307\u5BFCAI\u751F\u6210\u7279\u5B9A\u98CE\u683C\u7684\u9700\u6C42\u6587\u6863"),
|
|
4515
|
+
analysis_depth: enumType([
|
|
4516
|
+
"basic",
|
|
4517
|
+
"detailed",
|
|
4518
|
+
"comprehensive"
|
|
4519
|
+
]).default("detailed").describe("\u5206\u6790\u6DF1\u5EA6\uFF1A\u57FA\u7840\u3001\u8BE6\u7EC6\u3001\u7EFC\u5408"),
|
|
4520
|
+
use_streaming: booleanType().default(false).describe("\u662F\u5426\u4F7F\u7528\u6D41\u5F0F\u5904\u7406\uFF08\u9002\u7528\u4E8E\u5927\u6587\u4EF6\uFF09"),
|
|
4521
|
+
chunk_size: numberType().min(10).max(1000).default(100).describe("\u5206\u5757\u5927\u5C0F\uFF08\u4EC5\u5728use_streaming\u4E3Atrue\u65F6\u6709\u6548\uFF09")
|
|
4522
|
+
}).refine((data)=>{
|
|
4523
|
+
if ("text" === data.input_type) return data.content && data.content.trim().length > 0;
|
|
4524
|
+
if ("md_file" === data.input_type) return data.md_file_path && data.md_file_path.trim().length > 0;
|
|
4525
|
+
return false;
|
|
4526
|
+
}, {
|
|
4527
|
+
message: "\u5F53input_type\u4E3Atext\u65F6content\u5FC5\u586B\uFF0C\u5F53input_type\u4E3Amd_file\u65F6md_file_path\u5FC5\u586B"
|
|
4528
|
+
});
|
|
4529
|
+
const requirementAnalyzerTool = {
|
|
4530
|
+
name: "\u9700\u6C42\u62A5\u544A\u751F\u6210\u667A\u80FD\u4F53",
|
|
4531
|
+
description: "\u667A\u80FD\u5206\u6790\u9700\u6C42\u5E76\u751F\u6210\u7EDF\u4E00\u7684\u6280\u672F\u6587\u6863\uFF0C\u652F\u6301\u9879\u76EE\u60C5\u51B5\u611F\u77E5\u548C\u7CBE\u786E\u6A21\u677F\u5339\u914D",
|
|
4532
|
+
inputSchema: {
|
|
4533
|
+
input_type: enumType([
|
|
4534
|
+
"text",
|
|
4535
|
+
"md_file"
|
|
4536
|
+
]).describe("\u8F93\u5165\u7C7B\u578B\uFF1A\u76F4\u63A5\u6587\u672C\u8F93\u5165\u6216\u5F15\u7528\u5DF2\u751F\u6210\u7684MD\u6587\u4EF6"),
|
|
4537
|
+
content: stringType().optional().describe("\u5F53input_type\u4E3Atext\u65F6\uFF0C\u76F4\u63A5\u8F93\u5165\u7684\u9700\u6C42\u5185\u5BB9"),
|
|
4538
|
+
md_file_path: stringType().optional().describe("\u5F53input_type\u4E3Amd_file\u65F6\uFF0C\u8981\u5206\u6790\u7684MD\u6587\u4EF6\u8DEF\u5F84"),
|
|
4539
|
+
feature_name: stringType().describe("\u529F\u80FD\u540D\u79F0\uFF0C\u7528\u4E8E\u751F\u6210\u8F93\u51FA\u6587\u4EF6\u540D"),
|
|
4540
|
+
custom_prompt: stringType().optional().describe("\u81EA\u5B9A\u4E49\u63D0\u793A\u8BCD\uFF0C\u7528\u4E8E\u6307\u5BFCAI\u751F\u6210\u7279\u5B9A\u98CE\u683C\u7684\u9700\u6C42\u6587\u6863"),
|
|
4541
|
+
analysis_depth: enumType([
|
|
4542
|
+
"basic",
|
|
4543
|
+
"detailed",
|
|
4544
|
+
"comprehensive"
|
|
4545
|
+
]).default("detailed").describe("\u5206\u6790\u6DF1\u5EA6\uFF1A\u57FA\u7840\u3001\u8BE6\u7EC6\u3001\u7EFC\u5408"),
|
|
4546
|
+
use_streaming: booleanType().default(false).describe("\u662F\u5426\u4F7F\u7528\u6D41\u5F0F\u5904\u7406\uFF08\u9002\u7528\u4E8E\u5927\u6587\u4EF6\uFF09"),
|
|
4547
|
+
chunk_size: numberType().min(10).max(1000).default(100).describe("\u5206\u5757\u5927\u5C0F\uFF08\u4EC5\u5728use_streaming\u4E3Atrue\u65F6\u6709\u6548\uFF09")
|
|
4548
|
+
},
|
|
4549
|
+
handler: async (args)=>{
|
|
4550
|
+
try {
|
|
4551
|
+
return {
|
|
4552
|
+
content: [
|
|
4553
|
+
{
|
|
4554
|
+
type: "text",
|
|
4555
|
+
text: JSON.stringify({
|
|
4556
|
+
success: true,
|
|
4557
|
+
message: "\u9700\u6C42\u5206\u6790\u667A\u80FD\u4F53\u6D4B\u8BD5\u6210\u529F",
|
|
4558
|
+
data: {
|
|
4559
|
+
input_type: args.input_type,
|
|
4560
|
+
feature_name: args.feature_name
|
|
4561
|
+
}
|
|
4562
|
+
})
|
|
4563
|
+
}
|
|
4564
|
+
]
|
|
4565
|
+
};
|
|
4566
|
+
} catch (error) {
|
|
4567
|
+
return {
|
|
4568
|
+
content: [
|
|
4569
|
+
{
|
|
4570
|
+
type: "text",
|
|
4571
|
+
text: JSON.stringify({
|
|
4572
|
+
success: false,
|
|
4573
|
+
message: `\u{9700}\u{6C42}\u{5206}\u{6790}\u{667A}\u{80FD}\u{4F53}\u{6267}\u{884C}\u{5931}\u{8D25}: ${error.message}`,
|
|
4574
|
+
data: null
|
|
4575
|
+
})
|
|
4576
|
+
}
|
|
4577
|
+
],
|
|
4578
|
+
isError: true
|
|
4579
|
+
};
|
|
4580
|
+
}
|
|
4581
|
+
}
|
|
4582
|
+
};
|
|
4583
|
+
const changeAnalysisPrompt = `\u{8BF7}\u{5206}\u{6790}\u{5F53}\u{524D}\u{4EE3}\u{7801}\u{5E93}\u{FF0C}\u{5E76}\u{4E0E}\u{9700}\u{6C42}\u{8FDB}\u{884C}\u{5BF9}\u{6BD4}\u{FF0C}\u{786E}\u{4FDD}\u{5B9E}\u{73B0}\u{7684}\u{5B8C}\u{6574}\u{6027}\u{3002}
|
|
4584
|
+
|
|
4585
|
+
\u{8BF7}\u{6309}\u{4EE5}\u{4E0B}\u{6B65}\u{9AA4}\u{8FDB}\u{884C}\u{5206}\u{6790}\u{FF1A}
|
|
4586
|
+
|
|
4587
|
+
## 1. \u{4EE3}\u{7801}\u{5E93}\u{5206}\u{6790}
|
|
4588
|
+
\u{5206}\u{6790}\u{5F53}\u{524D}\u{4EE3}\u{7801}\u{5E93}\u{FF0C}\u{603B}\u{7ED3}\u{FF1A}
|
|
4589
|
+
- \u{4E3B}\u{8981}\u{529F}\u{80FD}\u{6A21}\u{5757}\u{53CA}\u{5176}\u{5B9E}\u{73B0}
|
|
4590
|
+
- \u{5173}\u{952E}\u{4E1A}\u{52A1}\u{903B}\u{8F91}\u{6D41}\u{7A0B}
|
|
4591
|
+
- \u{91CD}\u{8981}\u{6570}\u{636E}\u{7ED3}\u{6784}
|
|
4592
|
+
- \u{6838}\u{5FC3}\u{7B97}\u{6CD5}\u{5B9E}\u{73B0}
|
|
4593
|
+
|
|
4594
|
+
## 2. \u{63A5}\u{53E3}\u{4E0E}\u{9700}\u{6C42}\u{5BF9}\u{5E94}\u{5173}\u{7CFB}\u{8868}
|
|
4595
|
+
\u{6839}\u{636E}\u{4EE3}\u{7801}\u{53D8}\u{66F4}\u{FF0C}\u{751F}\u{6210}\u{63A5}\u{53E3}\u{4E0E}\u{9700}\u{6C42}\u{5BF9}\u{5E94}\u{5173}\u{7CFB}\u{8868}\u{FF1A}
|
|
4596
|
+
|
|
4597
|
+
| \u{9700}\u{6C42}\u{529F}\u{80FD} | \u{5B9E}\u{73B0}\u{63A5}\u{53E3} | \u{8BF7}\u{6C42}\u{65B9}\u{5F0F} | URL | \u{53D8}\u{66F4}\u{72B6}\u{6001} |
|
|
4598
|
+
|---------|---------|---------|-----|----------|
|
|
4599
|
+
| [\u{9700}\u{6C42}\u{529F}\u{80FD}\u{63CF}\u{8FF0}] | [Controller.method] | [GET/POST/PUT/DELETE] | [/api/path] | [\u{65B0}\u{589E}/\u{4FEE}\u{6539}/\u{5220}\u{9664}] |
|
|
4600
|
+
|
|
4601
|
+
## 3. \u{6838}\u{5FC3}\u{903B}\u{8F91}\u{65B9}\u{6CD5}\u{8868}
|
|
4602
|
+
\u{5206}\u{6790}\u{6838}\u{5FC3}\u{4E1A}\u{52A1}\u{903B}\u{8F91}\u{65B9}\u{6CD5}\u{FF1A}
|
|
4603
|
+
|
|
4604
|
+
| \u{65B9}\u{6CD5}\u{540D}\u{79F0} | \u{6240}\u{5C5E}\u{7C7B} | \u{529F}\u{80FD}\u{8BF4}\u{660E} | \u{53D8}\u{66F4}\u{72B6}\u{6001} |
|
|
4605
|
+
|---------|-------|---------|----------|
|
|
4606
|
+
| [methodName] | [ClassName] | [\u{529F}\u{80FD}\u{63CF}\u{8FF0}] | [\u{65B0}\u{589E}/\u{4FEE}\u{6539}/\u{5220}\u{9664}] |
|
|
4607
|
+
|
|
4608
|
+
## 4. \u{524D}\u{7AEF}\u{9875}\u{9762}\u{4E0E}\u{63A5}\u{53E3}\u{5BF9}\u{5E94}\u{5173}\u{7CFB}\u{8868}
|
|
4609
|
+
\u{5206}\u{6790}\u{524D}\u{7AEF}\u{9875}\u{9762}\u{53D8}\u{66F4}\u{FF1A}
|
|
4610
|
+
|
|
4611
|
+
| \u{9875}\u{9762}\u{540D}\u{79F0} | \u{8C03}\u{7528}\u{63A5}\u{53E3} | \u{7EC4}\u{4EF6}\u{540D}\u{79F0} | \u{8DEF}\u{7531}\u{8DEF}\u{5F84} | \u{53D8}\u{66F4}\u{72B6}\u{6001} |
|
|
4612
|
+
|---------|---------|---------|---------|----------|
|
|
4613
|
+
| [\u{9875}\u{9762}\u{540D}\u{79F0}] | [Controller.method] | [ComponentName] | [/path] | [\u{65B0}\u{589E}/\u{4FEE}\u{6539}/\u{5220}\u{9664}] |
|
|
4614
|
+
|
|
4615
|
+
## 5. \u{524D}\u{7AEF}\u{6838}\u{5FC3}\u{7EC4}\u{4EF6}\u{8868}
|
|
4616
|
+
\u{5206}\u{6790}\u{524D}\u{7AEF}\u{7EC4}\u{4EF6}\u{53D8}\u{66F4}\u{FF1A}
|
|
4617
|
+
|
|
4618
|
+
| \u{7EC4}\u{4EF6}\u{540D}\u{79F0} | \u{6240}\u{5C5E}\u{9875}\u{9762} | \u{529F}\u{80FD}\u{8BF4}\u{660E} | \u{53D8}\u{66F4}\u{72B6}\u{6001} |
|
|
4619
|
+
|---------|---------|---------|----------|
|
|
4620
|
+
| [ComponentName] | [PageName] | [\u{529F}\u{80FD}\u{63CF}\u{8FF0}] | [\u{65B0}\u{589E}/\u{4FEE}\u{6539}/\u{5220}\u{9664}] |
|
|
4621
|
+
|
|
4622
|
+
## 6. \u{9700}\u{6C42}\u{5B8C}\u{6574}\u{6027}\u{68C0}\u{67E5}
|
|
4623
|
+
\u{5BF9}\u{6BD4}\u{539F}\u{59CB}\u{9700}\u{6C42}\u{FF0C}\u{68C0}\u{67E5}\u{FF1A}
|
|
4624
|
+
- \u{2705} \u{5DF2}\u{5B8C}\u{6210}\u{7684}\u{529F}\u{80FD}
|
|
4625
|
+
- \u{26A0}\u{FE0F} \u{90E8}\u{5206}\u{5B8C}\u{6210}\u{7684}\u{529F}\u{80FD}
|
|
4626
|
+
- \u{274C} \u{672A}\u{5B9E}\u{73B0}\u{7684}\u{529F}\u{80FD}
|
|
4627
|
+
- \u{1F504} \u{9700}\u{8981}\u{8FDB}\u{4E00}\u{6B65}\u{5B8C}\u{5584}\u{7684}\u{529F}\u{80FD}
|
|
4628
|
+
|
|
4629
|
+
## 7. \u{5EFA}\u{8BAE}\u{4E0E}\u{603B}\u{7ED3}
|
|
4630
|
+
- \u{5B9E}\u{73B0}\u{8D28}\u{91CF}\u{8BC4}\u{4F30}
|
|
4631
|
+
- \u{6F5C}\u{5728}\u{95EE}\u{9898}\u{8BC6}\u{522B}
|
|
4632
|
+
- \u{540E}\u{7EED}\u{5F00}\u{53D1}\u{5EFA}\u{8BAE}
|
|
4633
|
+
- \u{6D4B}\u{8BD5}\u{5EFA}\u{8BAE}
|
|
4634
|
+
|
|
4635
|
+
\u{8BF7}\u{786E}\u{4FDD}\u{6240}\u{6709}\u{8868}\u{683C}\u{4E0A}\u{4E0B}\u{5BF9}\u{9F50}\u{FF0C}\u{5185}\u{5BB9}\u{8BE6}\u{5B9E}\u{51C6}\u{786E}\u{3002}`;
|
|
4636
|
+
objectType({
|
|
4637
|
+
baseBranch: stringType().default('main').describe("\u57FA\u51C6\u5206\u652F\u540D\u79F0\uFF0C\u7528\u4E8E\u5BF9\u6BD4\u53D8\u66F4"),
|
|
4638
|
+
requirementFile: stringType().optional().describe("\u9700\u6C42\u6587\u6863\u6587\u4EF6\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09"),
|
|
4639
|
+
includeUncommitted: booleanType().default(true).describe("\u662F\u5426\u5305\u542B\u672A\u63D0\u4EA4\u7684\u53D8\u66F4"),
|
|
4640
|
+
outputFormat: enumType([
|
|
4641
|
+
'markdown',
|
|
4642
|
+
'json'
|
|
4643
|
+
]).default('markdown').describe("\u8F93\u51FA\u683C\u5F0F")
|
|
4644
|
+
});
|
|
4645
|
+
const changeSummarizer = {
|
|
4646
|
+
name: "\u4EE3\u7801\u53D8\u66F4\u5206\u6790\u667A\u80FD\u4F53",
|
|
4647
|
+
description: "\u5206\u6790\u4EE3\u7801\u5E76\u4E0E\u9700\u6C42\u8FDB\u884C\u5BF9\u6BD4\uFF0C\u786E\u4FDD\u5B9E\u73B0\u5B8C\u6574\u6027",
|
|
4648
|
+
inputSchema: {
|
|
4649
|
+
baseBranch: stringType().default('main').describe("\u57FA\u51C6\u5206\u652F\u540D\u79F0\uFF0C\u7528\u4E8E\u5BF9\u6BD4\u53D8\u66F4"),
|
|
4650
|
+
requirementFile: stringType().optional().describe("\u9700\u6C42\u6587\u6863\u6587\u4EF6\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09"),
|
|
4651
|
+
includeUncommitted: booleanType().default(true).describe("\u662F\u5426\u5305\u542B\u672A\u63D0\u4EA4\u7684\u53D8\u66F4"),
|
|
4652
|
+
outputFormat: enumType([
|
|
4653
|
+
'markdown',
|
|
4654
|
+
'json'
|
|
4655
|
+
]).default('markdown').describe("\u8F93\u51FA\u683C\u5F0F")
|
|
4656
|
+
},
|
|
4657
|
+
handler: async (args)=>{
|
|
4658
|
+
try {
|
|
4659
|
+
initializeProjectRoot();
|
|
4660
|
+
console.log('[CHANGE-SUMMARIZER DEBUG] args:', JSON.stringify(args, null, 2));
|
|
4661
|
+
console.log('[CHANGE-SUMMARIZER DEBUG] args.baseBranch:', args.baseBranch);
|
|
4662
|
+
console.log('[CHANGE-SUMMARIZER DEBUG] args.outputFormat:', args.outputFormat);
|
|
4663
|
+
logger_logger.info({
|
|
4664
|
+
module: 'change-summarizer',
|
|
4665
|
+
message: 'Starting code analysis',
|
|
4666
|
+
args
|
|
4667
|
+
});
|
|
4668
|
+
let requirementContent = '';
|
|
4669
|
+
if (args.requirementFile && external_fs_default().existsSync(args.requirementFile)) requirementContent = external_fs_default().readFileSync(args.requirementFile, 'utf-8');
|
|
4670
|
+
const analysisPrompt = buildAnalysisPrompt(requirementContent);
|
|
4671
|
+
const outputPath = await saveAnalysisResult(analysisPrompt, args.outputFormat);
|
|
4672
|
+
logger_logger.info({
|
|
4673
|
+
module: 'change-summarizer',
|
|
4674
|
+
message: 'Code analysis completed',
|
|
4675
|
+
outputPath
|
|
4676
|
+
});
|
|
4677
|
+
return {
|
|
4678
|
+
content: [
|
|
4679
|
+
{
|
|
4680
|
+
type: "text",
|
|
4681
|
+
text: JSON.stringify({
|
|
4682
|
+
success: true,
|
|
4683
|
+
message: "\u4EE3\u7801\u53D8\u66F4\u5206\u6790\u667A\u80FD\u4F53\u6D4B\u8BD5\u6210\u529F",
|
|
4684
|
+
data: {
|
|
4685
|
+
baseBranch: args.baseBranch || 'main',
|
|
4686
|
+
outputFormat: args.outputFormat || 'markdown'
|
|
4687
|
+
}
|
|
4688
|
+
})
|
|
4689
|
+
}
|
|
4690
|
+
]
|
|
4691
|
+
};
|
|
4692
|
+
} catch (error) {
|
|
4693
|
+
logger_logger.error({
|
|
4694
|
+
module: 'change-summarizer',
|
|
4695
|
+
message: 'Code analysis failed',
|
|
4696
|
+
error: error instanceof Error ? error.message : String(error)
|
|
4697
|
+
});
|
|
4698
|
+
return {
|
|
4699
|
+
content: [
|
|
4700
|
+
{
|
|
4701
|
+
type: "text",
|
|
4702
|
+
text: JSON.stringify({
|
|
4703
|
+
success: false,
|
|
4704
|
+
message: `\u{4EE3}\u{7801}\u{53D8}\u{66F4}\u{5206}\u{6790}\u{667A}\u{80FD}\u{4F53}\u{6267}\u{884C}\u{5931}\u{8D25}: ${error instanceof Error ? error.message : String(error)}`,
|
|
4705
|
+
data: null
|
|
4706
|
+
})
|
|
4707
|
+
}
|
|
4708
|
+
],
|
|
4709
|
+
isError: true
|
|
4710
|
+
};
|
|
4711
|
+
}
|
|
4712
|
+
}
|
|
4713
|
+
};
|
|
4714
|
+
changeSummarizer.handler = changeSummarizer.handler;
|
|
4715
|
+
function buildAnalysisPrompt(requirementContent) {
|
|
4716
|
+
const changesSection = `
|
|
4717
|
+
## \u{4EE3}\u{7801}\u{4E0A}\u{4E0B}\u{6587}\u{5206}\u{6790}
|
|
4718
|
+
|
|
4719
|
+
\u{8BF7}\u{57FA}\u{4E8E}\u{4EE5}\u{4E0B}\u{5185}\u{5BB9}\u{8FDB}\u{884C}\u{5206}\u{6790}\u{FF1A}
|
|
4720
|
+
- \u{5F53}\u{524D}\u{4EE3}\u{7801}\u{5E93}\u{7684}\u{6574}\u{4F53}\u{7ED3}\u{6784}
|
|
4721
|
+
- \u{4E3B}\u{8981}\u{529F}\u{80FD}\u{6A21}\u{5757}\u{7684}\u{5B9E}\u{73B0}
|
|
4722
|
+
- \u{5173}\u{952E}\u{4E1A}\u{52A1}\u{903B}\u{8F91}
|
|
4723
|
+
- \u{63A5}\u{53E3}\u{5B9A}\u{4E49}\u{4E0E}\u{5B9E}\u{73B0}
|
|
4724
|
+
- \u{524D}\u{7AEF}\u{7EC4}\u{4EF6}\u{4E0E}\u{9875}\u{9762}
|
|
4725
|
+
`;
|
|
4726
|
+
const requirementSection = requirementContent ? `
|
|
4727
|
+
## \u{9700}\u{6C42}\u{6587}\u{6863}\u{5185}\u{5BB9}
|
|
4728
|
+
${requirementContent}
|
|
4729
|
+
` : `
|
|
4730
|
+
## \u{9700}\u{6C42}\u{6587}\u{6863}
|
|
4731
|
+
\u{672A}\u{63D0}\u{4F9B}\u{9700}\u{6C42}\u{6587}\u{6863}\u{FF0C}\u{8BF7}\u{57FA}\u{4E8E}\u{4EE3}\u{7801}\u{53D8}\u{66F4}\u{8FDB}\u{884C}\u{5206}\u{6790}\u{3002}
|
|
4732
|
+
`;
|
|
4733
|
+
return `
|
|
4734
|
+
${changeAnalysisPrompt}
|
|
4735
|
+
|
|
4736
|
+
${changesSection}
|
|
4737
|
+
|
|
4738
|
+
${requirementSection}
|
|
4739
|
+
|
|
4740
|
+
\u{8BF7}\u{57FA}\u{4E8E}\u{4EE5}\u{4E0A}\u{4FE1}\u{606F}\u{8FDB}\u{884C}\u{8BE6}\u{7EC6}\u{5206}\u{6790}\u{3002}
|
|
4741
|
+
`;
|
|
4742
|
+
}
|
|
4743
|
+
async function saveAnalysisResult(prompt, format) {
|
|
4744
|
+
const storageDir = config_getStorageDir();
|
|
4745
|
+
if (!storageDir || 'string' != typeof storageDir) throw new Error("\u5B58\u50A8\u76EE\u5F55\u914D\u7F6E\u9519\u8BEF\uFF0C\u65E0\u6CD5\u4FDD\u5B58\u5206\u6790\u7ED3\u679C");
|
|
4746
|
+
const outputDir = external_path_default().join(storageDir, 'change-analysis');
|
|
4747
|
+
if (!external_fs_default().existsSync(outputDir)) external_fs_default().mkdirSync(outputDir, {
|
|
4748
|
+
recursive: true
|
|
4749
|
+
});
|
|
4750
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
4751
|
+
const filename = `change-analysis-${timestamp}.${'json' === format ? 'json' : 'md'}`;
|
|
4752
|
+
const outputPath = external_path_default().join(outputDir, filename);
|
|
4753
|
+
if ('json' === format) {
|
|
4754
|
+
const jsonData = {
|
|
4755
|
+
timestamp: new Date().toISOString(),
|
|
4756
|
+
prompt,
|
|
4757
|
+
type: 'change-analysis'
|
|
4758
|
+
};
|
|
4759
|
+
external_fs_default().writeFileSync(outputPath, JSON.stringify(jsonData, null, 2), 'utf-8');
|
|
4760
|
+
} else external_fs_default().writeFileSync(outputPath, prompt, 'utf-8');
|
|
4761
|
+
return outputPath;
|
|
4762
|
+
}
|
|
4763
|
+
const external_sharp_namespaceObject = require("sharp");
|
|
4764
|
+
var external_sharp_default = /*#__PURE__*/ __webpack_require__.n(external_sharp_namespaceObject);
|
|
4765
|
+
async function invokeFlow(params, streamCb) {
|
|
4766
|
+
const { appid = 'app-ESTcrkOPOmkxdrO0120mE4s1', data, timeout = 1800000 } = params;
|
|
4767
|
+
const controller = new AbortController();
|
|
4768
|
+
const signal = controller.signal;
|
|
4769
|
+
if ('undefined' == typeof ReadableStream) throw new Error('ReadableStream is not supported in this environment');
|
|
4770
|
+
const fetchData = async (retryCount = 0)=>{
|
|
4771
|
+
try {
|
|
4772
|
+
const fetchOptions = {
|
|
4773
|
+
method: 'POST',
|
|
4774
|
+
headers: {
|
|
4775
|
+
Authorization: `Bearer ${appid}`,
|
|
4776
|
+
'Content-Type': 'application/json'
|
|
4777
|
+
},
|
|
4778
|
+
body: JSON.stringify({
|
|
4779
|
+
inputs: data,
|
|
4780
|
+
response_mode: 'streaming',
|
|
4781
|
+
user: "aico-mcp"
|
|
4782
|
+
}),
|
|
4783
|
+
signal
|
|
4784
|
+
};
|
|
4785
|
+
const res = await fetch('http://11.0.166.20:9199/v1/workflows/run', fetchOptions);
|
|
4786
|
+
if (!res.ok) {
|
|
4787
|
+
if (retryCount < 3) {
|
|
4788
|
+
await new Promise((resolve)=>setTimeout(resolve, 1000));
|
|
4789
|
+
return fetchData(retryCount + 1);
|
|
4790
|
+
}
|
|
4791
|
+
const errorResponse = await res.text();
|
|
4792
|
+
throw new Error(`\u{7F51}\u{7EDC}\u{54CD}\u{5E94}\u{5F02}\u{5E38}: ${res.status} ${res.statusText} - ${errorResponse}`);
|
|
4793
|
+
}
|
|
4794
|
+
if (res.ok) if (res.body) {
|
|
4795
|
+
const reader = res.body.getReader();
|
|
4796
|
+
const decoder = new TextDecoder('utf-8');
|
|
4797
|
+
if (streamCb) return void new ReadableStream({
|
|
4798
|
+
start (controller) {
|
|
4799
|
+
let buffer = '';
|
|
4800
|
+
function push() {
|
|
4801
|
+
reader.read().then(({ done, value })=>{
|
|
4802
|
+
if (done) {
|
|
4803
|
+
const lines = buffer.split('\n');
|
|
4804
|
+
for (const line of lines)handleLine(line, controller);
|
|
4805
|
+
if (streamCb) streamCb({
|
|
4806
|
+
isEnd: true
|
|
4807
|
+
});
|
|
4808
|
+
controller.close();
|
|
4809
|
+
return;
|
|
4810
|
+
}
|
|
4811
|
+
const chunkText = decoder.decode(value, {
|
|
4812
|
+
stream: true
|
|
4813
|
+
});
|
|
4814
|
+
buffer += chunkText;
|
|
4815
|
+
const lines = buffer.split('\n');
|
|
4816
|
+
for(let i = 0; i < lines.length - 1; i++)handleLine(lines[i], controller);
|
|
4817
|
+
buffer = lines[lines.length - 1];
|
|
4818
|
+
push();
|
|
4819
|
+
});
|
|
4820
|
+
}
|
|
4821
|
+
function handleLine(line, controller) {
|
|
4822
|
+
line = line.trim();
|
|
4823
|
+
if (line.startsWith('data:')) {
|
|
4824
|
+
const dataStr = line.slice(5).trim();
|
|
4825
|
+
if ('' === dataStr) return;
|
|
4826
|
+
try {
|
|
4827
|
+
const jsonData = JSON.parse(dataStr);
|
|
4828
|
+
if (jsonData.data?.text) {
|
|
4829
|
+
const wrappedData = {
|
|
4830
|
+
content: jsonData.data.text.toString(),
|
|
4831
|
+
controller
|
|
4832
|
+
};
|
|
4833
|
+
if (streamCb) streamCb(wrappedData);
|
|
4834
|
+
}
|
|
4835
|
+
} catch (e) {
|
|
4836
|
+
console.error("\u89E3\u6790JSON\u5931\u8D25:", e);
|
|
4837
|
+
}
|
|
4838
|
+
}
|
|
4839
|
+
}
|
|
4840
|
+
push();
|
|
4841
|
+
}
|
|
4842
|
+
});
|
|
4843
|
+
{
|
|
4844
|
+
let buffer = '';
|
|
4845
|
+
let accumulatedText = '';
|
|
4846
|
+
let isResponseEnded = false;
|
|
4847
|
+
const readAll = async ()=>{
|
|
4848
|
+
const { done, value } = await reader.read();
|
|
4849
|
+
if (done) {
|
|
4850
|
+
if (!isResponseEnded) throw new Error("\u54CD\u5E94\u63D0\u524D\u7ED3\u675F");
|
|
4851
|
+
return accumulatedText;
|
|
4852
|
+
}
|
|
4853
|
+
const chunkText = decoder.decode(value, {
|
|
4854
|
+
stream: true
|
|
4855
|
+
});
|
|
4856
|
+
buffer += chunkText;
|
|
4857
|
+
const lines = buffer.split('\n');
|
|
4858
|
+
for(let i = 0; i < lines.length - 1; i++){
|
|
4859
|
+
const line = lines[i].trim();
|
|
4860
|
+
if (!line.startsWith('data:')) continue;
|
|
4861
|
+
const dataStr = line.slice(5).trim();
|
|
4862
|
+
if ('' !== dataStr) try {
|
|
4863
|
+
const jsonData = JSON.parse(dataStr);
|
|
4864
|
+
switch(jsonData.event){
|
|
4865
|
+
case 'message':
|
|
4866
|
+
case 'agent_message':
|
|
4867
|
+
case 'text_chunk':
|
|
4868
|
+
{
|
|
4869
|
+
const content = 'text_chunk' === jsonData.event ? jsonData.data.text : jsonData.answer;
|
|
4870
|
+
accumulatedText += content;
|
|
4871
|
+
break;
|
|
4872
|
+
}
|
|
4873
|
+
case 'workflow_finished':
|
|
4874
|
+
accumulatedText = jsonData.data;
|
|
4875
|
+
isResponseEnded = true;
|
|
4876
|
+
break;
|
|
4877
|
+
case 'message_end':
|
|
4878
|
+
isResponseEnded = true;
|
|
4879
|
+
break;
|
|
4880
|
+
case 'error':
|
|
4881
|
+
throw new Error(`\u{670D}\u{52A1}\u{5668}\u{9519}\u{8BEF}: ${jsonData.code}, ${jsonData.message}`);
|
|
4882
|
+
default:
|
|
4883
|
+
break;
|
|
4884
|
+
}
|
|
4885
|
+
} catch (e) {
|
|
4886
|
+
throw new Error("\u89E3\u6790JSON\u5931\u8D25: " + e.message);
|
|
4887
|
+
}
|
|
4888
|
+
}
|
|
4889
|
+
buffer = lines[lines.length - 1];
|
|
4890
|
+
return readAll();
|
|
4891
|
+
};
|
|
4892
|
+
return readAll();
|
|
4893
|
+
}
|
|
4894
|
+
} else throw new Error("\u54CD\u5E94\u4F53\u4E3A\u7A7A");
|
|
4895
|
+
{
|
|
4896
|
+
const errorResponse = await res.text();
|
|
4897
|
+
throw new Error(`\u{7F51}\u{7EDC}\u{54CD}\u{5E94}\u{5F02}\u{5E38}: ${res.status} ${res.statusText} - ${errorResponse}`);
|
|
4898
|
+
}
|
|
4899
|
+
} catch (error) {
|
|
4900
|
+
if ('AbortError' === error.name) throw new Error("\u8BF7\u6C42\u5DF2\u88AB\u4E2D\u6B62\uFF0C\u8D85\u65F6");
|
|
4901
|
+
throw error;
|
|
4902
|
+
}
|
|
4903
|
+
};
|
|
4904
|
+
try {
|
|
4905
|
+
const result = await Promise.race([
|
|
4906
|
+
fetchData(),
|
|
4907
|
+
new Promise((_, reject)=>{
|
|
4908
|
+
setTimeout(()=>{
|
|
4909
|
+
controller.abort();
|
|
4910
|
+
reject(new Error("\u8BF7\u6C42\u8D85\u65F6"));
|
|
4911
|
+
}, timeout);
|
|
4912
|
+
})
|
|
4913
|
+
]);
|
|
4914
|
+
if (streamCb) return;
|
|
4915
|
+
return result;
|
|
4916
|
+
} catch (error) {
|
|
4917
|
+
controller.abort();
|
|
4918
|
+
throw error;
|
|
4919
|
+
}
|
|
4920
|
+
}
|
|
4921
|
+
async function uploadFile(params) {
|
|
4922
|
+
const { appid, filePath, user = 'aico-mcp' } = params;
|
|
4923
|
+
try {
|
|
4924
|
+
const fileBuffer = await external_fs_default().promises.readFile(filePath);
|
|
4925
|
+
const fileName = external_path_default().basename(filePath);
|
|
4926
|
+
const fileExtension = external_path_default().extname(filePath).toLowerCase().slice(1);
|
|
4927
|
+
const mimeTypes = {
|
|
4928
|
+
png: 'image/png',
|
|
4929
|
+
jpeg: 'image/jpeg',
|
|
4930
|
+
jpg: 'image/jpeg',
|
|
4931
|
+
webp: 'image/webp',
|
|
4932
|
+
gif: 'image/gif'
|
|
4933
|
+
};
|
|
4934
|
+
const mimeType = mimeTypes[fileExtension] || 'application/octet-stream';
|
|
4935
|
+
const formData = new FormData();
|
|
4936
|
+
formData.append('file', new Blob([
|
|
4937
|
+
fileBuffer.buffer
|
|
4938
|
+
], {
|
|
4939
|
+
type: mimeType
|
|
4940
|
+
}), fileName);
|
|
4941
|
+
formData.append('user', user);
|
|
4942
|
+
const response = await fetch('http://11.0.166.20:9199/v1/files/upload', {
|
|
4943
|
+
method: 'POST',
|
|
4944
|
+
headers: {
|
|
4945
|
+
Authorization: `Bearer ${appid}`
|
|
4946
|
+
},
|
|
4947
|
+
body: formData
|
|
4948
|
+
});
|
|
4949
|
+
if (!response.ok) {
|
|
4950
|
+
const errorText = await response.text();
|
|
4951
|
+
throw new Error(`\u{6587}\u{4EF6}\u{4E0A}\u{4F20}\u{5931}\u{8D25}: ${response.status} ${response.statusText} - ${errorText}`);
|
|
4952
|
+
}
|
|
4953
|
+
const result = await response.json();
|
|
4954
|
+
if (!result.id || !result.name) throw new Error("\u65E0\u6548\u7684\u6587\u4EF6\u4E0A\u4F20\u54CD\u5E94\u683C\u5F0F");
|
|
4955
|
+
return result;
|
|
4956
|
+
} catch (error) {
|
|
4957
|
+
if (error instanceof Error) throw new Error(`\u{6587}\u{4EF6}\u{4E0A}\u{4F20}\u{5931}\u{8D25}: ${error.message}`);
|
|
4958
|
+
throw new Error("\u6587\u4EF6\u4E0A\u4F20\u5931\u8D25: \u672A\u77E5\u9519\u8BEF");
|
|
4959
|
+
}
|
|
4960
|
+
}
|
|
4705
4961
|
class ImageAnalysisError extends Error {
|
|
4706
4962
|
code;
|
|
4707
4963
|
context;
|
|
@@ -4717,7 +4973,6 @@ ${requirementSection}
|
|
|
4717
4973
|
AnalysisErrorCodes["IMAGE_CORRUPTED"] = "IMAGE_CORRUPTED";
|
|
4718
4974
|
AnalysisErrorCodes["ANALYSIS_FAILED"] = "ANALYSIS_FAILED";
|
|
4719
4975
|
AnalysisErrorCodes["AI_SERVICE_ERROR"] = "AI_SERVICE_ERROR";
|
|
4720
|
-
AnalysisErrorCodes["INVALID_ANALYSIS_TYPE"] = "INVALID_ANALYSIS_TYPE";
|
|
4721
4976
|
return AnalysisErrorCodes;
|
|
4722
4977
|
}({});
|
|
4723
4978
|
const SUPPORTED_IMAGE_FORMATS = [
|
|
@@ -4734,7 +4989,7 @@ ${requirementSection}
|
|
|
4734
4989
|
async analyzeImage(imagePath, context) {
|
|
4735
4990
|
const startTime = Date.now();
|
|
4736
4991
|
try {
|
|
4737
|
-
|
|
4992
|
+
logger_logger.info("\u5F00\u59CB\u56FE\u7247\u5185\u5BB9\u5206\u6790", {
|
|
4738
4993
|
imagePath: imagePath
|
|
4739
4994
|
});
|
|
4740
4995
|
await this.validateParams(imagePath);
|
|
@@ -4748,20 +5003,16 @@ ${requirementSection}
|
|
|
4748
5003
|
});
|
|
4749
5004
|
const result = {
|
|
4750
5005
|
basic_info: basicInfo,
|
|
4751
|
-
analysis_type: types_AnalysisType.GENERAL,
|
|
4752
|
-
detail_level: types_DetailLevel.DETAILED,
|
|
4753
5006
|
content: analysisContent,
|
|
4754
|
-
processing_time_ms: processingTime
|
|
4755
|
-
confidence_score: this.calculateConfidenceScore(analysisContent)
|
|
5007
|
+
processing_time_ms: processingTime
|
|
4756
5008
|
};
|
|
4757
|
-
|
|
5009
|
+
logger_logger.info("\u56FE\u7247\u5185\u5BB9\u5206\u6790\u5B8C\u6210", {
|
|
4758
5010
|
imagePath: imagePath,
|
|
4759
|
-
processingTimeMs: processingTime
|
|
4760
|
-
confidenceScore: result.confidence_score
|
|
5011
|
+
processingTimeMs: processingTime
|
|
4761
5012
|
});
|
|
4762
5013
|
return result;
|
|
4763
5014
|
} catch (error) {
|
|
4764
|
-
|
|
5015
|
+
logger_logger.error("\u56FE\u7247\u5185\u5BB9\u5206\u6790\u5931\u8D25", {
|
|
4765
5016
|
error,
|
|
4766
5017
|
params: {
|
|
4767
5018
|
image_path: imagePath
|
|
@@ -4774,7 +5025,7 @@ ${requirementSection}
|
|
|
4774
5025
|
try {
|
|
4775
5026
|
const imageBase64 = await this.imageToBase64(imagePath);
|
|
4776
5027
|
const prompt = this.buildAnalysisPrompt(imagePath, basicInfo, context);
|
|
4777
|
-
const aiResponse = await
|
|
5028
|
+
const aiResponse = await openai_openAIService.analyzeImage({
|
|
4778
5029
|
image_base64: imageBase64,
|
|
4779
5030
|
prompt: prompt,
|
|
4780
5031
|
system_prompt: "\u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684\u56FE\u7247\u5206\u6790\u4E13\u5BB6\uFF0C\u8BF7\u4E25\u683C\u57FA\u4E8E\u4EFB\u52A1\u6307\u4EE4\u5206\u6790\u56FE\u7247\u5185\u5BB9\uFF0C\u4E0D\u504F\u79BB\u4EFB\u52A1\u8303\u56F4\uFF0C\u4E0D\u6DFB\u52A0\u65E0\u5173\u4FE1\u606F\u3002"
|
|
@@ -4782,15 +5033,26 @@ ${requirementSection}
|
|
|
4782
5033
|
const analysisContent = this.parseAIResponse(aiResponse);
|
|
4783
5034
|
return analysisContent;
|
|
4784
5035
|
} catch (error) {
|
|
4785
|
-
|
|
5036
|
+
logger_logger.warn("\u4E3BAI\u5206\u6790\u5931\u8D25\uFF0C\u5C1D\u8BD5Dify\u515C\u5E95\u5206\u6790", {
|
|
4786
5037
|
error,
|
|
4787
5038
|
params: {
|
|
4788
5039
|
image_path: imagePath
|
|
4789
5040
|
}
|
|
4790
5041
|
});
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
})
|
|
5042
|
+
try {
|
|
5043
|
+
return await this.fallbackToDifyAnalysis(imagePath, context);
|
|
5044
|
+
} catch (fallbackError) {
|
|
5045
|
+
logger_logger.error("Dify\u515C\u5E95\u5206\u6790\u4E5F\u5931\u8D25", {
|
|
5046
|
+
error: fallbackError,
|
|
5047
|
+
params: {
|
|
5048
|
+
image_path: imagePath
|
|
5049
|
+
}
|
|
5050
|
+
});
|
|
5051
|
+
throw new ImageAnalysisError("\u8BC6\u522B\u56FE\u7247\u5931\u8D25", types_AnalysisErrorCodes.ANALYSIS_FAILED, {
|
|
5052
|
+
originalError: error,
|
|
5053
|
+
fallbackError
|
|
5054
|
+
});
|
|
5055
|
+
}
|
|
4794
5056
|
}
|
|
4795
5057
|
}
|
|
4796
5058
|
buildAnalysisPrompt(imagePath, basicInfo, context) {
|
|
@@ -4804,48 +5066,18 @@ ${requirementSection}
|
|
|
4804
5066
|
const contextPrompt = context ? `
|
|
4805
5067
|
|
|
4806
5068
|
## \u{5206}\u{6790}\u{6307}\u{4EE4}
|
|
4807
|
-
${context}
|
|
4808
|
-
|
|
4809
|
-
\u{8BF7}\u{4E25}\u{683C}\u{6839}\u{636E}\u{4EE5}\u{4E0A}\u{6307}\u{4EE4}\u{8FDB}\u{884C}\u{56FE}\u{7247}\u{5206}\u{6790}\u{FF0C}\u{4E0D}\u{504F}\u{79BB}\u{4EFB}\u{52A1}\u{8303}\u{56F4}\u{FF0C}\u{4E0D}\u{6DFB}\u{52A0}\u{65E0}\u{5173}\u{4FE1}\u{606F}\u{3002}` : '';
|
|
4810
|
-
const strictPrompt = `
|
|
4811
|
-
|
|
4812
|
-
## \u{5206}\u{6790}\u{8981}\u{6C42}
|
|
4813
|
-
\u{4F60}\u{5FC5}\u{987B}\u{4E25}\u{683C}\u{6839}\u{636E}\u{4EFB}\u{52A1}\u{6307}\u{4EE4}\u{5206}\u{6790}\u{56FE}\u{7247}\u{5185}\u{5BB9}\u{FF0C}\u{4E0D}\u{504F}\u{79BB}\u{7528}\u{6237}\u{8981}\u{6C42}\u{7684}\u{8303}\u{56F4}\u{FF0C}\u{4E0D}\u{6DFB}\u{52A0}\u{65E0}\u{5173}\u{4FE1}\u{606F}\u{3002}\u{786E}\u{4FDD}\u{5206}\u{6790}\u{7ED3}\u{679C}\u{6E05}\u{6670}\u{51C6}\u{786E}\u{FF0C}\u{53EA}\u{5305}\u{542B}\u{4E0E}\u{4EFB}\u{52A1}\u{76F8}\u{5173}\u{7684}\u{4FE1}\u{606F}\u{3002}`;
|
|
4814
|
-
return `${basePrompt}${contextPrompt}${strictPrompt}`.trim();
|
|
5069
|
+
${context}` : '';
|
|
5070
|
+
return `${basePrompt}${contextPrompt}`.trim();
|
|
4815
5071
|
}
|
|
4816
5072
|
parseAIResponse(aiResponse) {
|
|
4817
5073
|
if (!aiResponse || 'string' != typeof aiResponse) throw new ImageAnalysisError("AI\u670D\u52A1\u8FD4\u56DE\u65E0\u6548\u54CD\u5E94", types_AnalysisErrorCodes.AI_SERVICE_ERROR, {
|
|
4818
5074
|
aiResponse
|
|
4819
5075
|
});
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
});
|
|
4824
|
-
const cleanedResponse = this.cleanAIResponse(aiResponse);
|
|
4825
|
-
const content = {
|
|
4826
|
-
summary: cleanedResponse,
|
|
4827
|
-
details: {
|
|
4828
|
-
raw_response: aiResponse
|
|
4829
|
-
},
|
|
5076
|
+
return {
|
|
5077
|
+
summary: aiResponse.trim(),
|
|
5078
|
+
details: {},
|
|
4830
5079
|
tags: []
|
|
4831
5080
|
};
|
|
4832
|
-
logger.debug("\u5185\u5BB9\u89E3\u6790\u7ED3\u679C", {
|
|
4833
|
-
summaryLength: content.summary.length
|
|
4834
|
-
});
|
|
4835
|
-
return content;
|
|
4836
|
-
}
|
|
4837
|
-
cleanAIResponse(response) {
|
|
4838
|
-
let cleaned = response.trim();
|
|
4839
|
-
const patternsToRemove = [
|
|
4840
|
-
/^(?:好的|明白了|根据您的要求|根据分析|根据图片内容)[,,::]\s*/i,
|
|
4841
|
-
/(?:以下是|下面是对|分析结果如下|内容如下)[::]\s*/i,
|
|
4842
|
-
/\n(?:总结|结论|综上所述)[::]\s*/i
|
|
4843
|
-
];
|
|
4844
|
-
patternsToRemove.forEach((pattern)=>{
|
|
4845
|
-
cleaned = cleaned.replace(pattern, '');
|
|
4846
|
-
});
|
|
4847
|
-
cleaned = cleaned.replace(/\n{3,}/g, '\n\n').trim();
|
|
4848
|
-
return cleaned;
|
|
4849
5081
|
}
|
|
4850
5082
|
async getImageBasicInfo(imagePath) {
|
|
4851
5083
|
try {
|
|
@@ -4858,9 +5090,7 @@ ${context}
|
|
|
4858
5090
|
width: metadata.width || 0,
|
|
4859
5091
|
height: metadata.height || 0
|
|
4860
5092
|
},
|
|
4861
|
-
file_size: stats.size
|
|
4862
|
-
color_space: metadata.space,
|
|
4863
|
-
has_alpha: metadata.hasAlpha
|
|
5093
|
+
file_size: stats.size
|
|
4864
5094
|
};
|
|
4865
5095
|
} catch (error) {
|
|
4866
5096
|
throw new ImageAnalysisError(`\u{65E0}\u{6CD5}\u{8BFB}\u{53D6}\u{56FE}\u{7247}\u{4FE1}\u{606F}: ${imagePath}`, types_AnalysisErrorCodes.IMAGE_CORRUPTED, {
|
|
@@ -4903,145 +5133,16 @@ ${context}
|
|
|
4903
5133
|
async validateParams(imagePath) {
|
|
4904
5134
|
try {
|
|
4905
5135
|
await promises_namespaceObject.access(imagePath);
|
|
4906
|
-
} catch {
|
|
4907
|
-
throw new ImageAnalysisError(`\u{56FE}\u{7247}\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}: ${imagePath}`, types_AnalysisErrorCodes.FILE_NOT_FOUND, {
|
|
4908
|
-
imagePath: imagePath
|
|
4909
|
-
});
|
|
4910
|
-
}
|
|
4911
|
-
const ext = external_path_namespaceObject.extname(imagePath).slice(1).toLowerCase();
|
|
4912
|
-
if (!SUPPORTED_IMAGE_FORMATS.includes(ext)) throw new ImageAnalysisError(`\u{4E0D}\u{652F}\u{6301}\u{7684}\u{56FE}\u{7247}\u{683C}\u{5F0F}: ${ext}`, types_AnalysisErrorCodes.UNSUPPORTED_FORMAT, {
|
|
4913
|
-
format: ext,
|
|
4914
|
-
supportedFormats: SUPPORTED_IMAGE_FORMATS
|
|
4915
|
-
});
|
|
4916
|
-
}
|
|
4917
|
-
calculateConfidenceScore(content) {
|
|
4918
|
-
let score = 0.5;
|
|
4919
|
-
if (content.summary.length > 100) score += 0.2;
|
|
4920
|
-
if (content.tags && content.tags.length > 0) score += 0.1;
|
|
4921
|
-
if (content.objects && content.objects.length > 0) score += 0.1;
|
|
4922
|
-
if (content.text_content && content.text_content.length > 0) score += 0.1;
|
|
4923
|
-
return Math.min(score, 1.0);
|
|
4924
|
-
}
|
|
4925
|
-
extractValue(text, pattern) {
|
|
4926
|
-
const match = text.match(pattern);
|
|
4927
|
-
return match ? match[1].trim() : null;
|
|
4928
|
-
}
|
|
4929
|
-
extractBoolean(text, pattern) {
|
|
4930
|
-
return pattern.test(text);
|
|
4931
|
-
}
|
|
4932
|
-
extractList(text, pattern) {
|
|
4933
|
-
const match = text.match(pattern);
|
|
4934
|
-
if (match) return match[1].split(/[,,、]/).map((item)=>item.trim()).filter(Boolean);
|
|
4935
|
-
return [];
|
|
4936
|
-
}
|
|
4937
|
-
extractUIComponents(text) {
|
|
4938
|
-
const components = [];
|
|
4939
|
-
const componentPatterns = [
|
|
4940
|
-
/按钮|button/gi,
|
|
4941
|
-
/输入框|input|文本框/gi,
|
|
4942
|
-
/导航|navigation|nav/gi,
|
|
4943
|
-
/卡片|card/gi,
|
|
4944
|
-
/列表|list/gi,
|
|
4945
|
-
/表格|table/gi
|
|
4946
|
-
];
|
|
4947
|
-
componentPatterns.forEach((pattern, index)=>{
|
|
4948
|
-
const matches = text.match(pattern);
|
|
4949
|
-
if (matches) components.push({
|
|
4950
|
-
type: [
|
|
4951
|
-
'button',
|
|
4952
|
-
'input',
|
|
4953
|
-
'navigation',
|
|
4954
|
-
'card',
|
|
4955
|
-
'list',
|
|
4956
|
-
'table'
|
|
4957
|
-
][index],
|
|
4958
|
-
name: matches[0],
|
|
4959
|
-
position: {
|
|
4960
|
-
x: 0,
|
|
4961
|
-
y: 0,
|
|
4962
|
-
width: 0,
|
|
4963
|
-
height: 0
|
|
4964
|
-
},
|
|
4965
|
-
properties: {}
|
|
4966
|
-
});
|
|
4967
|
-
});
|
|
4968
|
-
return components;
|
|
4969
|
-
}
|
|
4970
|
-
extractColorScheme(text) {
|
|
4971
|
-
return {
|
|
4972
|
-
primary_colors: this.extractList(text, /主色调[::]\s*([^\n]+)/i),
|
|
4973
|
-
secondary_colors: this.extractList(text, /辅助色[::]\s*([^\n]+)/i),
|
|
4974
|
-
background_colors: this.extractList(text, /背景色[::]\s*([^\n]+)/i)
|
|
4975
|
-
};
|
|
4976
|
-
}
|
|
4977
|
-
extractTypography(text) {
|
|
4978
|
-
return {
|
|
4979
|
-
fonts: this.extractList(text, /字体[::]\s*([^\n]+)/i),
|
|
4980
|
-
text_hierarchy: this.extractList(text, /文字层次[::]\s*([^\n]+)/i)
|
|
4981
|
-
};
|
|
4982
|
-
}
|
|
4983
|
-
extractNavigation(text) {
|
|
4984
|
-
return {
|
|
4985
|
-
type: this.extractValue(text, /导航类型[::]\s*([^\n]+)/i) || "\u672A\u8BC6\u522B",
|
|
4986
|
-
elements: this.extractList(text, /导航元素[::]\s*([^\n]+)/i)
|
|
4987
|
-
};
|
|
4988
|
-
}
|
|
4989
|
-
extractFunctionalRequirements(text) {
|
|
4990
|
-
const requirements = [];
|
|
4991
|
-
const funcReqPattern = /功能需求[::][\s\S]*?(?=非功能需求|用户故事|$)/i;
|
|
4992
|
-
const match = text.match(funcReqPattern);
|
|
4993
|
-
if (match) {
|
|
4994
|
-
const reqText = match[0];
|
|
4995
|
-
const reqItems = reqText.split(/\d+\./).filter((item)=>item.trim());
|
|
4996
|
-
reqItems.forEach((item, index)=>{
|
|
4997
|
-
if (item.trim()) requirements.push({
|
|
4998
|
-
id: `FR-${index + 1}`,
|
|
4999
|
-
title: item.split('\n')[0].trim(),
|
|
5000
|
-
description: item.trim(),
|
|
5001
|
-
priority: 'medium',
|
|
5002
|
-
category: "\u529F\u80FD\u9700\u6C42",
|
|
5003
|
-
acceptance_criteria: []
|
|
5004
|
-
});
|
|
5136
|
+
} catch {
|
|
5137
|
+
throw new ImageAnalysisError(`\u{56FE}\u{7247}\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}: ${imagePath}`, types_AnalysisErrorCodes.FILE_NOT_FOUND, {
|
|
5138
|
+
imagePath: imagePath
|
|
5005
5139
|
});
|
|
5006
5140
|
}
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
const nfrTypes = [
|
|
5012
|
-
"\u6027\u80FD",
|
|
5013
|
-
"\u5B89\u5168",
|
|
5014
|
-
"\u53EF\u7528\u6027",
|
|
5015
|
-
"\u53EF\u7EF4\u62A4\u6027",
|
|
5016
|
-
"\u53EF\u6269\u5C55\u6027"
|
|
5017
|
-
];
|
|
5018
|
-
nfrTypes.forEach((type)=>{
|
|
5019
|
-
const pattern = new RegExp(`${type}[\u{FF1A}:]\\s*([^\\n]+)`, 'i');
|
|
5020
|
-
const match = text.match(pattern);
|
|
5021
|
-
if (match) requirements.push({
|
|
5022
|
-
type: type,
|
|
5023
|
-
description: match[1].trim(),
|
|
5024
|
-
metric: '',
|
|
5025
|
-
target_value: ''
|
|
5026
|
-
});
|
|
5027
|
-
});
|
|
5028
|
-
return requirements;
|
|
5029
|
-
}
|
|
5030
|
-
extractUserStories(text) {
|
|
5031
|
-
const stories = [];
|
|
5032
|
-
const storyPattern = /作为.*?我希望.*?以便.*?/g;
|
|
5033
|
-
const matches = text.match(storyPattern);
|
|
5034
|
-
if (matches) matches.forEach((story, index)=>{
|
|
5035
|
-
const parts = story.split(/我希望|以便/);
|
|
5036
|
-
if (parts.length >= 3) stories.push({
|
|
5037
|
-
as_a: parts[0].replace("\u4F5C\u4E3A", '').trim(),
|
|
5038
|
-
i_want: parts[1].trim(),
|
|
5039
|
-
so_that: parts[2].trim(),
|
|
5040
|
-
acceptance_criteria: [],
|
|
5041
|
-
priority: 'medium'
|
|
5042
|
-
});
|
|
5141
|
+
const ext = external_path_namespaceObject.extname(imagePath).slice(1).toLowerCase();
|
|
5142
|
+
if (!SUPPORTED_IMAGE_FORMATS.includes(ext)) throw new ImageAnalysisError(`\u{4E0D}\u{652F}\u{6301}\u{7684}\u{56FE}\u{7247}\u{683C}\u{5F0F}: ${ext}`, types_AnalysisErrorCodes.UNSUPPORTED_FORMAT, {
|
|
5143
|
+
format: ext,
|
|
5144
|
+
supportedFormats: SUPPORTED_IMAGE_FORMATS
|
|
5043
5145
|
});
|
|
5044
|
-
return stories;
|
|
5045
5146
|
}
|
|
5046
5147
|
formatFileSize(bytes) {
|
|
5047
5148
|
if (0 === bytes) return '0 B';
|
|
@@ -5055,6 +5156,58 @@ ${context}
|
|
|
5055
5156
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
5056
5157
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
|
5057
5158
|
}
|
|
5159
|
+
async fallbackToDifyAnalysis(imagePath, context) {
|
|
5160
|
+
logger_logger.info("\u5F00\u59CBDify\u515C\u5E95\u56FE\u7247\u5206\u6790", {
|
|
5161
|
+
imagePath: imagePath,
|
|
5162
|
+
context: context
|
|
5163
|
+
});
|
|
5164
|
+
try {
|
|
5165
|
+
const uploadResult = await uploadFile({
|
|
5166
|
+
appid: 'app-AvlLh0nfN4l9oz1MSW4sEAQ6',
|
|
5167
|
+
filePath: imagePath,
|
|
5168
|
+
user: 'aico-mcp'
|
|
5169
|
+
});
|
|
5170
|
+
logger_logger.info("\u6587\u4EF6\u4E0A\u4F20\u6210\u529F\uFF0C\u6587\u4EF6ID:", uploadResult.id);
|
|
5171
|
+
const workflowData = {
|
|
5172
|
+
imagePath: {
|
|
5173
|
+
type: 'image',
|
|
5174
|
+
transfer_method: 'local_file',
|
|
5175
|
+
upload_file_id: uploadResult.id
|
|
5176
|
+
},
|
|
5177
|
+
context: context || "\u8BF7\u5206\u6790\u8FD9\u5F20\u56FE\u7247\u7684\u5185\u5BB9"
|
|
5178
|
+
};
|
|
5179
|
+
const workflowResponse = await invokeFlow({
|
|
5180
|
+
appid: 'app-AvlLh0nfN4l9oz1MSW4sEAQ6',
|
|
5181
|
+
data: workflowData
|
|
5182
|
+
});
|
|
5183
|
+
logger_logger.info("Dify\u5DE5\u4F5C\u6D41\u8C03\u7528\u6210\u529F", {
|
|
5184
|
+
response: workflowResponse
|
|
5185
|
+
});
|
|
5186
|
+
let summary = "\u5206\u6790\u5B8C\u6210";
|
|
5187
|
+
if ('string' == typeof workflowResponse) summary = workflowResponse;
|
|
5188
|
+
else if (workflowResponse?.data?.text) summary = workflowResponse.data.text;
|
|
5189
|
+
else if (workflowResponse?.answer) summary = workflowResponse.answer;
|
|
5190
|
+
else if (workflowResponse?.outputs?.text) summary = workflowResponse.outputs.text;
|
|
5191
|
+
else if (workflowResponse?.status === 'failed') throw new Error(`Dify\u{5DE5}\u{4F5C}\u{6D41}\u{6267}\u{884C}\u{5931}\u{8D25}: ${workflowResponse.error || "\u672A\u77E5\u9519\u8BEF"}`);
|
|
5192
|
+
return {
|
|
5193
|
+
summary: summary,
|
|
5194
|
+
details: {
|
|
5195
|
+
dify_response: workflowResponse,
|
|
5196
|
+
fallback_used: true
|
|
5197
|
+
},
|
|
5198
|
+
tags: [
|
|
5199
|
+
'dify-fallback'
|
|
5200
|
+
]
|
|
5201
|
+
};
|
|
5202
|
+
} catch (error) {
|
|
5203
|
+
logger_logger.error("Dify\u670D\u52A1\u8C03\u7528\u5931\u8D25", {
|
|
5204
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5205
|
+
imagePath: imagePath,
|
|
5206
|
+
context: context
|
|
5207
|
+
});
|
|
5208
|
+
throw new ImageAnalysisError(`\u{56FE}\u{7247}\u{5206}\u{6790}\u{670D}\u{52A1}\u{8C03}\u{7528}\u{5931}\u{8D25}: ${error instanceof Error ? error.message : String(error)}`, types_AnalysisErrorCodes.AI_SERVICE_ERROR);
|
|
5209
|
+
}
|
|
5210
|
+
}
|
|
5058
5211
|
}
|
|
5059
5212
|
const ImageAnalysisParamsSchema = objectType({
|
|
5060
5213
|
image_path: stringType().min(1).describe("\u56FE\u7247\u6587\u4EF6\u8DEF\u5F84"),
|
|
@@ -5070,7 +5223,7 @@ ${context}
|
|
|
5070
5223
|
handler: async (args)=>{
|
|
5071
5224
|
const analyzer = new ImageAnalyzer();
|
|
5072
5225
|
try {
|
|
5073
|
-
|
|
5226
|
+
logger_logger.info("\u56FE\u7247\u5185\u5BB9\u7406\u89E3\u667A\u80FD\u4F53\u5F00\u59CB\u6267\u884C", {
|
|
5074
5227
|
imagePath: args.image_path
|
|
5075
5228
|
});
|
|
5076
5229
|
const validatedArgs = ImageAnalysisParamsSchema.parse(args);
|
|
@@ -5088,14 +5241,12 @@ ${context}
|
|
|
5088
5241
|
- \u{5904}\u{7406}\u{65F6}\u{95F4}\u{FF1A}${result.processing_time_ms}ms
|
|
5089
5242
|
|
|
5090
5243
|
\u{56FE}\u{7247}\u{63CF}\u{8FF0}\u{FF1A}
|
|
5091
|
-
${result.content.summary}
|
|
5092
|
-
|
|
5093
|
-
${result.content.tags && result.content.tags.length > 0 ? `\u{5173}\u{952E}\u{6807}\u{7B7E}\u{FF1A}${result.content.tags.map((tag)=>`\`${tag}\``).join(' ')}` : ''}`
|
|
5244
|
+
${result.content.summary}`
|
|
5094
5245
|
}
|
|
5095
5246
|
]
|
|
5096
5247
|
};
|
|
5097
5248
|
} catch (error) {
|
|
5098
|
-
|
|
5249
|
+
logger_logger.error("\u56FE\u7247\u5185\u5BB9\u7406\u89E3\u667A\u80FD\u4F53\u6267\u884C\u5931\u8D25", {
|
|
5099
5250
|
error,
|
|
5100
5251
|
args
|
|
5101
5252
|
});
|
|
@@ -5126,51 +5277,16 @@ ${result.content.tags && result.content.tags.length > 0 ? `\u{5173}\u{952E}\u{68
|
|
|
5126
5277
|
[types_AnalysisErrorCodes.UNSUPPORTED_FORMAT]: "\u4E0D\u652F\u6301\u7684\u56FE\u7247\u683C\u5F0F",
|
|
5127
5278
|
[types_AnalysisErrorCodes.FILE_NOT_FOUND]: "\u56FE\u7247\u6587\u4EF6\u672A\u627E\u5230",
|
|
5128
5279
|
[types_AnalysisErrorCodes.IMAGE_CORRUPTED]: "\u56FE\u7247\u6587\u4EF6\u635F\u574F",
|
|
5129
|
-
[types_AnalysisErrorCodes.ANALYSIS_FAILED]: "\
|
|
5130
|
-
[types_AnalysisErrorCodes.AI_SERVICE_ERROR]: "AI\u670D\u52A1\u9519\u8BEF"
|
|
5131
|
-
[types_AnalysisErrorCodes.INVALID_ANALYSIS_TYPE]: "\u65E0\u6548\u7684\u5206\u6790\u7C7B\u578B"
|
|
5280
|
+
[types_AnalysisErrorCodes.ANALYSIS_FAILED]: "\u56FE\u7247\u8BC6\u522B\u5931\u8D25",
|
|
5281
|
+
[types_AnalysisErrorCodes.AI_SERVICE_ERROR]: "AI\u670D\u52A1\u9519\u8BEF"
|
|
5132
5282
|
};
|
|
5133
5283
|
const errorTitle = errorMessages[error.code] || "\u5206\u6790\u9519\u8BEF";
|
|
5134
|
-
return
|
|
5135
|
-
# \u{274C} ${errorTitle}
|
|
5136
|
-
|
|
5137
|
-
## \u{9519}\u{8BEF}\u{4FE1}\u{606F}
|
|
5138
|
-
${error.message}
|
|
5139
|
-
|
|
5140
|
-
## \u{9519}\u{8BEF}\u{4EE3}\u{7801}
|
|
5141
|
-
${error.code}
|
|
5142
|
-
|
|
5143
|
-
## \u{89E3}\u{51B3}\u{5EFA}\u{8BAE}
|
|
5144
|
-
${getErrorSuggestion(error.code)}
|
|
5145
|
-
|
|
5146
|
-
## \u{652F}\u{6301}\u{7684}\u{529F}\u{80FD}
|
|
5147
|
-
- **\u{56FE}\u{7247}\u{683C}\u{5F0F}**: ${SUPPORTED_IMAGE_FORMATS.join(", ")}
|
|
5148
|
-
- **\u{5206}\u{6790}\u{7C7B}\u{578B}**: \u{901A}\u{7528}\u{3001}\u{7269}\u{4F53}\u{8BC6}\u{522B}\u{3001}\u{6587}\u{5B57}\u{8BC6}\u{522B}\u{3001}\u{573A}\u{666F}\u{5206}\u{6790}\u{3001}\u{4EBA}\u{7269}\u{5206}\u{6790}\u{3001}\u{6280}\u{672F}\u{5206}\u{6790}\u{3001}UI\u{8BBE}\u{8BA1}\u{7A3F}\u{3001}\u{9700}\u{6C42}\u{8BC6}\u{522B}\u{3001}\u{81EA}\u{5B9A}\u{4E49}
|
|
5149
|
-
- **\u{8BE6}\u{7EC6}\u{7A0B}\u{5EA6}**: \u{7B80}\u{8981}\u{3001}\u{8BE6}\u{7EC6}\u{3001}\u{5168}\u{9762}
|
|
5150
|
-
|
|
5151
|
-
## \u{9519}\u{8BEF}\u{8BE6}\u{60C5}
|
|
5152
|
-
- **\u{65F6}\u{95F4}**: ${new Date().toISOString()}
|
|
5153
|
-
- **\u{4E0A}\u{4E0B}\u{6587}**: ${error.context ? JSON.stringify(error.context, null, 2) : "\u65E0"}
|
|
5154
|
-
|
|
5155
|
-
\u{8BF7}\u{6839}\u{636E}\u{4E0A}\u{8FF0}\u{4FE1}\u{606F}\u{8C03}\u{6574}\u{53C2}\u{6570}\u{540E}\u{91CD}\u{8BD5}\u{3002}
|
|
5156
|
-
`.trim();
|
|
5284
|
+
return `\u{274C} ${errorTitle}\n\n${error.message}`;
|
|
5157
5285
|
}
|
|
5158
5286
|
function formatUnknownErrorResponse(error) {
|
|
5159
|
-
return
|
|
5160
|
-
# \u{274C} \u{7CFB}\u{7EDF}\u{9519}\u{8BEF}
|
|
5161
|
-
|
|
5162
|
-
\u{56FE}\u{7247}\u{5185}\u{5BB9}\u{5206}\u{6790}\u{8FC7}\u{7A0B}\u{4E2D}\u{53D1}\u{751F}\u{672A}\u{77E5}\u{9519}\u{8BEF}\u{FF0C}\u{8BF7}\u{7A0D}\u{540E}\u{91CD}\u{8BD5}\u{6216}\u{8054}\u{7CFB}\u{6280}\u{672F}\u{652F}\u{6301}\u{3002}
|
|
5287
|
+
return `\u{274C} \u{7CFB}\u{7EDF}\u{9519}\u{8BEF}
|
|
5163
5288
|
|
|
5164
|
-
|
|
5165
|
-
**\u{65F6}\u{95F4}**: ${new Date().toISOString()}
|
|
5166
|
-
|
|
5167
|
-
## \u{5EFA}\u{8BAE}
|
|
5168
|
-
1. \u{68C0}\u{67E5}\u{56FE}\u{7247}\u{6587}\u{4EF6}\u{662F}\u{5426}\u{5B58}\u{5728}\u{4E14}\u{53EF}\u{8BFB}
|
|
5169
|
-
2. \u{786E}\u{8BA4}\u{56FE}\u{7247}\u{683C}\u{5F0F}\u{662F}\u{5426}\u{652F}\u{6301}
|
|
5170
|
-
3. \u{9A8C}\u{8BC1}\u{56FE}\u{7247}\u{6587}\u{4EF6}\u{662F}\u{5426}\u{635F}\u{574F}
|
|
5171
|
-
4. \u{68C0}\u{67E5}\u{7F51}\u{7EDC}\u{8FDE}\u{63A5}\u{662F}\u{5426}\u{6B63}\u{5E38}
|
|
5172
|
-
5. \u{5982}\u{95EE}\u{9898}\u{6301}\u{7EED}\u{FF0C}\u{8BF7}\u{8054}\u{7CFB}\u{6280}\u{672F}\u{652F}\u{6301}
|
|
5173
|
-
`.trim();
|
|
5289
|
+
${error?.message || "\u672A\u77E5\u9519\u8BEF"}`;
|
|
5174
5290
|
}
|
|
5175
5291
|
function formatFileSize(bytes) {
|
|
5176
5292
|
if (0 === bytes) return "0 B";
|
|
@@ -5184,18 +5300,6 @@ ${getErrorSuggestion(error.code)}
|
|
|
5184
5300
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
5185
5301
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
|
5186
5302
|
}
|
|
5187
|
-
function getErrorSuggestion(errorCode) {
|
|
5188
|
-
const suggestions = {
|
|
5189
|
-
[types_AnalysisErrorCodes.INVALID_IMAGE_PATH]: "\u8BF7\u68C0\u67E5\u56FE\u7247\u8DEF\u5F84\u662F\u5426\u6B63\u786E",
|
|
5190
|
-
[types_AnalysisErrorCodes.UNSUPPORTED_FORMAT]: "\u8BF7\u4F7F\u7528\u652F\u6301\u7684\u56FE\u7247\u683C\u5F0F\uFF08jpg, png, gif\u7B49\uFF09",
|
|
5191
|
-
[types_AnalysisErrorCodes.FILE_NOT_FOUND]: "\u8BF7\u786E\u8BA4\u56FE\u7247\u6587\u4EF6\u5B58\u5728\u4E14\u8DEF\u5F84\u6B63\u786E",
|
|
5192
|
-
[types_AnalysisErrorCodes.IMAGE_CORRUPTED]: "\u8BF7\u68C0\u67E5\u56FE\u7247\u6587\u4EF6\u662F\u5426\u5B8C\u6574\u4E14\u672A\u635F\u574F",
|
|
5193
|
-
[types_AnalysisErrorCodes.ANALYSIS_FAILED]: "\u8BF7\u91CD\u8BD5\u6216\u4F7F\u7528\u4E0D\u540C\u7684\u5206\u6790\u7C7B\u578B",
|
|
5194
|
-
[types_AnalysisErrorCodes.AI_SERVICE_ERROR]: "\u8BF7\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5\u6216\u7A0D\u540E\u91CD\u8BD5",
|
|
5195
|
-
[types_AnalysisErrorCodes.INVALID_ANALYSIS_TYPE]: "\u8BF7\u4F7F\u7528\u6709\u6548\u7684\u5206\u6790\u7C7B\u578B"
|
|
5196
|
-
};
|
|
5197
|
-
return suggestions[errorCode] || "\u8BF7\u68C0\u67E5\u8F93\u5165\u53C2\u6570\u5E76\u91CD\u8BD5";
|
|
5198
|
-
}
|
|
5199
5303
|
class ImageConversionError extends Error {
|
|
5200
5304
|
code;
|
|
5201
5305
|
context;
|
|
@@ -5244,7 +5348,7 @@ ${getErrorSuggestion(error.code)}
|
|
|
5244
5348
|
const inputPaths = Array.isArray(params.input_paths) ? params.input_paths : [
|
|
5245
5349
|
params.input_paths
|
|
5246
5350
|
];
|
|
5247
|
-
|
|
5351
|
+
logger_logger.info("\u5F00\u59CB\u56FE\u7247\u8F6C\u6362", {
|
|
5248
5352
|
inputCount: inputPaths.length,
|
|
5249
5353
|
outputFormat: params.output_format,
|
|
5250
5354
|
isBatch: inputPaths.length > 1
|
|
@@ -5262,7 +5366,7 @@ ${getErrorSuggestion(error.code)}
|
|
|
5262
5366
|
processing_time_ms: processingTime
|
|
5263
5367
|
}
|
|
5264
5368
|
};
|
|
5265
|
-
|
|
5369
|
+
logger_logger.info("\u56FE\u7247\u8F6C\u6362\u5B8C\u6210", {
|
|
5266
5370
|
total: results.length,
|
|
5267
5371
|
successful,
|
|
5268
5372
|
failed,
|
|
@@ -5270,7 +5374,7 @@ ${getErrorSuggestion(error.code)}
|
|
|
5270
5374
|
});
|
|
5271
5375
|
return batchResult;
|
|
5272
5376
|
} catch (error) {
|
|
5273
|
-
|
|
5377
|
+
logger_logger.error("\u56FE\u7247\u8F6C\u6362\u5931\u8D25", {
|
|
5274
5378
|
error,
|
|
5275
5379
|
params
|
|
5276
5380
|
});
|
|
@@ -5284,14 +5388,14 @@ ${getErrorSuggestion(error.code)}
|
|
|
5284
5388
|
await this.ensureOutputDirectory(outputPath);
|
|
5285
5389
|
const metadata = await this.getImageMetadata(inputPath);
|
|
5286
5390
|
const result = await this.performConversion(inputPath, outputPath, params, metadata);
|
|
5287
|
-
|
|
5391
|
+
logger_logger.info("\u5355\u5F20\u56FE\u7247\u8F6C\u6362\u6210\u529F", {
|
|
5288
5392
|
inputPath,
|
|
5289
5393
|
outputPath,
|
|
5290
5394
|
format: params.output_format
|
|
5291
5395
|
});
|
|
5292
5396
|
return result;
|
|
5293
5397
|
} catch (error) {
|
|
5294
|
-
|
|
5398
|
+
logger_logger.error("\u5355\u5F20\u56FE\u7247\u8F6C\u6362\u5931\u8D25", {
|
|
5295
5399
|
error,
|
|
5296
5400
|
inputPath
|
|
5297
5401
|
});
|
|
@@ -5488,7 +5592,7 @@ ${getErrorSuggestion(error.code)}
|
|
|
5488
5592
|
initializeProjectRoot();
|
|
5489
5593
|
const converter = new ImageConverter();
|
|
5490
5594
|
try {
|
|
5491
|
-
|
|
5595
|
+
logger_logger.info("\u56FE\u7247\u683C\u5F0F\u8F6C\u6362\u667A\u80FD\u4F53\u5F00\u59CB\u6267\u884C", {
|
|
5492
5596
|
inputPaths: args.input_paths,
|
|
5493
5597
|
outputFormat: args.output_format,
|
|
5494
5598
|
isBatch: Array.isArray(args.input_paths)
|
|
@@ -5513,7 +5617,7 @@ ${getErrorSuggestion(error.code)}
|
|
|
5513
5617
|
]
|
|
5514
5618
|
};
|
|
5515
5619
|
} catch (error) {
|
|
5516
|
-
|
|
5620
|
+
logger_logger.error("\u56FE\u7247\u683C\u5F0F\u8F6C\u6362\u667A\u80FD\u4F53\u6267\u884C\u5931\u8D25", {
|
|
5517
5621
|
error,
|
|
5518
5622
|
args
|
|
5519
5623
|
});
|
|
@@ -5624,7 +5728,7 @@ ${error.message}
|
|
|
5624
5728
|
${error.code}
|
|
5625
5729
|
|
|
5626
5730
|
## \u{89E3}\u{51B3}\u{5EFA}\u{8BAE}
|
|
5627
|
-
${
|
|
5731
|
+
${getErrorSuggestion(error.code)}
|
|
5628
5732
|
|
|
5629
5733
|
## \u{652F}\u{6301}\u{7684}\u{683C}\u{5F0F}
|
|
5630
5734
|
- **\u{8F93}\u{5165}\u{683C}\u{5F0F}**: ${SUPPORTED_INPUT_FORMATS.join(", ")}
|
|
@@ -5668,7 +5772,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5668
5772
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
5669
5773
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
|
5670
5774
|
}
|
|
5671
|
-
function
|
|
5775
|
+
function getErrorSuggestion(errorCode) {
|
|
5672
5776
|
const suggestions = {
|
|
5673
5777
|
[types_ConversionErrorCodes.INVALID_INPUT_PATH]: "\u8BF7\u68C0\u67E5\u8F93\u5165\u8DEF\u5F84\u662F\u5426\u6B63\u786E",
|
|
5674
5778
|
[types_ConversionErrorCodes.UNSUPPORTED_FORMAT]: "\u8BF7\u4F7F\u7528\u652F\u6301\u7684\u56FE\u7247\u683C\u5F0F",
|
|
@@ -5763,7 +5867,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5763
5867
|
});
|
|
5764
5868
|
class ImagePreprocessor {
|
|
5765
5869
|
async validateImage(imagePath) {
|
|
5766
|
-
|
|
5870
|
+
logger_logger.info("ImagePreprocessor: \u5F00\u59CB\u9A8C\u8BC1\u56FE\u7247", imagePath);
|
|
5767
5871
|
const result = {
|
|
5768
5872
|
isValid: false,
|
|
5769
5873
|
fileExists: false,
|
|
@@ -5775,7 +5879,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5775
5879
|
result.formatSupported = types_SUPPORTED_IMAGE_FORMATS.includes(fileExtension);
|
|
5776
5880
|
if (!result.formatSupported) {
|
|
5777
5881
|
result.errorMessage = `\u{4E0D}\u{652F}\u{6301}\u{7684}\u{56FE}\u{7247}\u{683C}\u{5F0F}: ${fileExtension}`;
|
|
5778
|
-
|
|
5882
|
+
logger_logger.warn("\u4E0D\u652F\u6301\u7684\u56FE\u7247\u683C\u5F0F", {
|
|
5779
5883
|
imagePath,
|
|
5780
5884
|
format: fileExtension
|
|
5781
5885
|
});
|
|
@@ -5784,12 +5888,12 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5784
5888
|
try {
|
|
5785
5889
|
await external_node_fs_promises_namespaceObject.access(imagePath, external_node_fs_namespaceObject.constants.R_OK);
|
|
5786
5890
|
result.readable = true;
|
|
5787
|
-
|
|
5891
|
+
logger_logger.debug("\u56FE\u7247\u6587\u4EF6\u53EF\u8BFB", {
|
|
5788
5892
|
imagePath
|
|
5789
5893
|
});
|
|
5790
5894
|
} catch (error) {
|
|
5791
5895
|
result.errorMessage = "\u56FE\u7247\u6587\u4EF6\u65E0\u6CD5\u8BFB\u53D6\uFF0C\u8BF7\u68C0\u67E5\u6587\u4EF6\u6743\u9650";
|
|
5792
|
-
|
|
5896
|
+
logger_logger.warn("\u56FE\u7247\u6587\u4EF6\u65E0\u6CD5\u8BFB\u53D6", {
|
|
5793
5897
|
imagePath
|
|
5794
5898
|
});
|
|
5795
5899
|
return result;
|
|
@@ -5798,32 +5902,32 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5798
5902
|
const metadata = await external_sharp_default()(imagePath).metadata();
|
|
5799
5903
|
if (!metadata.width || !metadata.height) {
|
|
5800
5904
|
result.errorMessage = "\u65E0\u6CD5\u83B7\u53D6\u56FE\u7247\u5C3A\u5BF8\u4FE1\u606F\uFF0C\u53EF\u80FD\u6587\u4EF6\u5DF2\u635F\u574F";
|
|
5801
|
-
|
|
5905
|
+
logger_logger.warn("\u65E0\u6CD5\u83B7\u53D6\u56FE\u7247\u5C3A\u5BF8", {
|
|
5802
5906
|
imagePath
|
|
5803
5907
|
});
|
|
5804
5908
|
return result;
|
|
5805
5909
|
}
|
|
5806
|
-
|
|
5910
|
+
logger_logger.debug("\u56FE\u7247\u5143\u6570\u636E\u83B7\u53D6\u6210\u529F", {
|
|
5807
5911
|
imagePath,
|
|
5808
5912
|
width: metadata.width,
|
|
5809
5913
|
height: metadata.height
|
|
5810
5914
|
});
|
|
5811
5915
|
} catch (error) {
|
|
5812
5916
|
result.errorMessage = "\u56FE\u7247\u6587\u4EF6\u683C\u5F0F\u9519\u8BEF\u6216\u5DF2\u635F\u574F";
|
|
5813
|
-
|
|
5917
|
+
logger_logger.warn("\u56FE\u7247\u6587\u4EF6\u635F\u574F", {
|
|
5814
5918
|
imagePath,
|
|
5815
5919
|
error: error instanceof Error ? error.message : error
|
|
5816
5920
|
});
|
|
5817
5921
|
return result;
|
|
5818
5922
|
}
|
|
5819
5923
|
result.isValid = true;
|
|
5820
|
-
|
|
5924
|
+
logger_logger.info("\u56FE\u7247\u9A8C\u8BC1\u6210\u529F", {
|
|
5821
5925
|
imagePath
|
|
5822
5926
|
});
|
|
5823
5927
|
return result;
|
|
5824
5928
|
} catch (error) {
|
|
5825
5929
|
result.errorMessage = `\u{56FE}\u{7247}\u{9A8C}\u{8BC1}\u{8FC7}\u{7A0B}\u{4E2D}\u{53D1}\u{751F}\u{9519}\u{8BEF}: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`;
|
|
5826
|
-
|
|
5930
|
+
logger_logger.error("\u56FE\u7247\u9A8C\u8BC1\u5931\u8D25", {
|
|
5827
5931
|
imagePath,
|
|
5828
5932
|
error
|
|
5829
5933
|
});
|
|
@@ -5831,7 +5935,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5831
5935
|
}
|
|
5832
5936
|
}
|
|
5833
5937
|
async getImageInfo(imagePath) {
|
|
5834
|
-
|
|
5938
|
+
logger_logger.info("ImagePreprocessor: \u5F00\u59CB\u83B7\u53D6\u56FE\u7247\u4FE1\u606F", imagePath);
|
|
5835
5939
|
try {
|
|
5836
5940
|
const stats = await external_node_fs_promises_namespaceObject.stat(imagePath);
|
|
5837
5941
|
const fileName = external_node_path_namespaceObject.basename(imagePath);
|
|
@@ -5867,7 +5971,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5867
5971
|
fileName,
|
|
5868
5972
|
createdAt: stats.birthtime
|
|
5869
5973
|
};
|
|
5870
|
-
|
|
5974
|
+
logger_logger.info("\u56FE\u7247\u4FE1\u606F\u83B7\u53D6\u6210\u529F", {
|
|
5871
5975
|
imagePath,
|
|
5872
5976
|
width,
|
|
5873
5977
|
height,
|
|
@@ -5878,7 +5982,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5878
5982
|
return imageInfo;
|
|
5879
5983
|
} catch (error) {
|
|
5880
5984
|
if (error instanceof ImageRecognitionError) throw error;
|
|
5881
|
-
|
|
5985
|
+
logger_logger.error("\u83B7\u53D6\u56FE\u7247\u4FE1\u606F\u5931\u8D25", {
|
|
5882
5986
|
imagePath,
|
|
5883
5987
|
error
|
|
5884
5988
|
});
|
|
@@ -5893,7 +5997,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5893
5997
|
const heightCondition = height >= LONG_IMAGE_THRESHOLDS.MIN_HEIGHT;
|
|
5894
5998
|
const aspectRatioCondition = aspectRatio <= 1 / LONG_IMAGE_THRESHOLDS.MIN_ASPECT_RATIO;
|
|
5895
5999
|
const isLong = heightCondition && aspectRatioCondition;
|
|
5896
|
-
|
|
6000
|
+
logger_logger.debug("\u957F\u56FE\u68C0\u6D4B\u7ED3\u679C", {
|
|
5897
6001
|
width,
|
|
5898
6002
|
height,
|
|
5899
6003
|
aspectRatio: aspectRatio.toFixed(2),
|
|
@@ -5904,7 +6008,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5904
6008
|
return isLong;
|
|
5905
6009
|
}
|
|
5906
6010
|
async assessImageQuality(imagePath) {
|
|
5907
|
-
|
|
6011
|
+
logger_logger.info("ImagePreprocessor: \u5F00\u59CB\u8BC4\u4F30\u56FE\u7247\u8D28\u91CF", {
|
|
5908
6012
|
imagePath
|
|
5909
6013
|
});
|
|
5910
6014
|
try {
|
|
@@ -5946,7 +6050,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5946
6050
|
clarity: clarityScore,
|
|
5947
6051
|
recommendation
|
|
5948
6052
|
};
|
|
5949
|
-
|
|
6053
|
+
logger_logger.info("\u56FE\u7247\u8D28\u91CF\u8BC4\u4F30\u5B8C\u6210", {
|
|
5950
6054
|
imagePath,
|
|
5951
6055
|
totalScore: totalScore.toFixed(3),
|
|
5952
6056
|
resolutionScore: resolutionScore.toFixed(3),
|
|
@@ -5957,7 +6061,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5957
6061
|
return assessment;
|
|
5958
6062
|
} catch (error) {
|
|
5959
6063
|
if (error instanceof ImageRecognitionError) throw error;
|
|
5960
|
-
|
|
6064
|
+
logger_logger.error("\u56FE\u7247\u8D28\u91CF\u8BC4\u4F30\u5931\u8D25", {
|
|
5961
6065
|
imagePath,
|
|
5962
6066
|
error
|
|
5963
6067
|
});
|
|
@@ -5973,7 +6077,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5973
6077
|
}
|
|
5974
6078
|
class ConfigCalculator {
|
|
5975
6079
|
async calculateSegmentConfig(imageInfo, qualityAssessment, maxSegments = LONG_IMAGE_THRESHOLDS.MAX_SEGMENTS) {
|
|
5976
|
-
|
|
6080
|
+
logger_logger.info("ConfigCalculator: \u5F00\u59CB\u8BA1\u7B97\u5206\u6BB5\u914D\u7F6E", {
|
|
5977
6081
|
width: imageInfo.width,
|
|
5978
6082
|
height: imageInfo.height,
|
|
5979
6083
|
isLongImage: imageInfo.isLongImage
|
|
@@ -5989,7 +6093,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
5989
6093
|
],
|
|
5990
6094
|
estimatedTime: this.estimateSegmentProcessingTime(1, imageInfo.size)
|
|
5991
6095
|
};
|
|
5992
|
-
|
|
6096
|
+
logger_logger.info("\u975E\u957F\u56FE\uFF0C\u4F7F\u7528\u5355\u6BB5\u914D\u7F6E", config);
|
|
5993
6097
|
return config;
|
|
5994
6098
|
}
|
|
5995
6099
|
const segmentHeight = this.calculateOptimalSegmentHeight(imageInfo, qualityAssessment);
|
|
@@ -6008,13 +6112,13 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6008
6112
|
processingOrder,
|
|
6009
6113
|
estimatedTime
|
|
6010
6114
|
};
|
|
6011
|
-
|
|
6115
|
+
logger_logger.info("\u5206\u6BB5\u914D\u7F6E\u8BA1\u7B97\u5B8C\u6210", {
|
|
6012
6116
|
...config,
|
|
6013
6117
|
estimatedTimeMinutes: (estimatedTime / 60000).toFixed(1)
|
|
6014
6118
|
});
|
|
6015
6119
|
return config;
|
|
6016
6120
|
} catch (error) {
|
|
6017
|
-
|
|
6121
|
+
logger_logger.error("\u5206\u6BB5\u914D\u7F6E\u8BA1\u7B97\u5931\u8D25", {
|
|
6018
6122
|
error,
|
|
6019
6123
|
imageInfo
|
|
6020
6124
|
});
|
|
@@ -6044,7 +6148,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6044
6148
|
return Math.max(overlapHeight, LONG_IMAGE_THRESHOLDS.MIN_OVERLAP);
|
|
6045
6149
|
}
|
|
6046
6150
|
calculateConcurrencyConfig(imageSize, segmentCount = 1) {
|
|
6047
|
-
|
|
6151
|
+
logger_logger.info("ConfigCalculator: \u5F00\u59CB\u8BA1\u7B97\u5E76\u53D1\u914D\u7F6E", {
|
|
6048
6152
|
imageSize: `${(imageSize / 1024 / 1024).toFixed(2)}MB`,
|
|
6049
6153
|
segmentCount
|
|
6050
6154
|
});
|
|
@@ -6066,7 +6170,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6066
6170
|
delayBetweenBatches,
|
|
6067
6171
|
memoryLimit: PERFORMANCE_LIMITS.MAX_MEMORY_MB
|
|
6068
6172
|
};
|
|
6069
|
-
|
|
6173
|
+
logger_logger.info("\u5E76\u53D1\u914D\u7F6E\u8BA1\u7B97\u5B8C\u6210", {
|
|
6070
6174
|
...config,
|
|
6071
6175
|
systemInfo: {
|
|
6072
6176
|
totalMemoryGB: (totalMemoryMB / 1024).toFixed(1),
|
|
@@ -6078,7 +6182,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6078
6182
|
});
|
|
6079
6183
|
return config;
|
|
6080
6184
|
} catch (error) {
|
|
6081
|
-
|
|
6185
|
+
logger_logger.error("\u5E76\u53D1\u914D\u7F6E\u8BA1\u7B97\u5931\u8D25", {
|
|
6082
6186
|
error,
|
|
6083
6187
|
imageSize,
|
|
6084
6188
|
segmentCount
|
|
@@ -6095,7 +6199,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6095
6199
|
return this.estimateSegmentProcessingTime(segmentCount, imageSize);
|
|
6096
6200
|
}
|
|
6097
6201
|
estimateSegmentProcessingTime(segmentCount, imageSize) {
|
|
6098
|
-
|
|
6202
|
+
logger_logger.info("ConfigCalculator: \u5F00\u59CB\u9884\u4F30\u5904\u7406\u65F6\u95F4", {
|
|
6099
6203
|
segmentCount,
|
|
6100
6204
|
imageSize
|
|
6101
6205
|
});
|
|
@@ -6113,7 +6217,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6113
6217
|
const startupOverhead = 2000;
|
|
6114
6218
|
const finalizationOverhead = 1000;
|
|
6115
6219
|
const estimatedTime = totalTime + startupOverhead + finalizationOverhead;
|
|
6116
|
-
|
|
6220
|
+
logger_logger.info("\u5904\u7406\u65F6\u95F4\u9884\u4F30\u5B8C\u6210", {
|
|
6117
6221
|
segmentCount,
|
|
6118
6222
|
baseTimePerSegment,
|
|
6119
6223
|
concurrencyEfficiency,
|
|
@@ -6122,7 +6226,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6122
6226
|
});
|
|
6123
6227
|
return estimatedTime;
|
|
6124
6228
|
} catch (error) {
|
|
6125
|
-
|
|
6229
|
+
logger_logger.error("\u5904\u7406\u65F6\u95F4\u9884\u4F30\u5931\u8D25", {
|
|
6126
6230
|
error,
|
|
6127
6231
|
segmentCount,
|
|
6128
6232
|
imageSize
|
|
@@ -6133,7 +6237,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6133
6237
|
}
|
|
6134
6238
|
class analyzer_ImageAnalyzer {
|
|
6135
6239
|
async analyzeLongImage(imagePath, imageInfo, segmentConfig, concurrencyConfig, apiPreference = 'auto') {
|
|
6136
|
-
|
|
6240
|
+
logger_logger.info("ImageAnalyzer: \u5F00\u59CB\u5206\u6790\u957F\u56FE", {
|
|
6137
6241
|
imagePath,
|
|
6138
6242
|
totalSegments: segmentConfig.totalSegments,
|
|
6139
6243
|
maxConcurrency: concurrencyConfig.maxConcurrency
|
|
@@ -6167,7 +6271,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6167
6271
|
outputPath: '',
|
|
6168
6272
|
success: 0 === summary.failedSegments
|
|
6169
6273
|
};
|
|
6170
|
-
|
|
6274
|
+
logger_logger.info("\u957F\u56FE\u5206\u6790\u5B8C\u6210", {
|
|
6171
6275
|
imagePath,
|
|
6172
6276
|
totalSegments: summary.totalSegments,
|
|
6173
6277
|
successfulSegments: summary.successfulSegments,
|
|
@@ -6176,7 +6280,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6176
6280
|
});
|
|
6177
6281
|
return result;
|
|
6178
6282
|
} catch (error) {
|
|
6179
|
-
|
|
6283
|
+
logger_logger.error("\u957F\u56FE\u5206\u6790\u5931\u8D25", {
|
|
6180
6284
|
imagePath,
|
|
6181
6285
|
error
|
|
6182
6286
|
});
|
|
@@ -6192,7 +6296,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6192
6296
|
const segments = await this.generateSegments(imagePath, imageInfo, segmentConfig);
|
|
6193
6297
|
for(let i = 0; i < segments.length; i += batchSize){
|
|
6194
6298
|
const batch = segments.slice(i, i + batchSize);
|
|
6195
|
-
|
|
6299
|
+
logger_logger.info(`\u{5904}\u{7406}\u{6279}\u{6B21} ${Math.floor(i / batchSize) + 1}/${Math.ceil(segments.length / batchSize)}`, {
|
|
6196
6300
|
batchSize: batch.length,
|
|
6197
6301
|
startIndex: i
|
|
6198
6302
|
});
|
|
@@ -6200,7 +6304,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6200
6304
|
try {
|
|
6201
6305
|
return await this.analyzeSegment(buffer, info, apiPreference);
|
|
6202
6306
|
} catch (error) {
|
|
6203
|
-
|
|
6307
|
+
logger_logger.error(`\u{6BB5}\u{843D} ${info.index} \u{5206}\u{6790}\u{5931}\u{8D25}`, {
|
|
6204
6308
|
error
|
|
6205
6309
|
});
|
|
6206
6310
|
return {
|
|
@@ -6222,7 +6326,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6222
6326
|
}
|
|
6223
6327
|
async analyzeSegment(imageBuffer, segmentInfo, apiPreference = 'auto') {
|
|
6224
6328
|
const startTime = Date.now();
|
|
6225
|
-
|
|
6329
|
+
logger_logger.info("ImageAnalyzer: \u5F00\u59CB\u5206\u6790\u56FE\u7247\u6BB5\u843D", {
|
|
6226
6330
|
segmentIndex: segmentInfo.index,
|
|
6227
6331
|
totalSegments: segmentInfo.totalSegments,
|
|
6228
6332
|
isFirstSegment: segmentInfo.isFirstSegment,
|
|
@@ -6237,7 +6341,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6237
6341
|
try {
|
|
6238
6342
|
if ('glm-4v' === apiPreference || 'auto' === apiPreference) {
|
|
6239
6343
|
apiUsed = 'glm-4v-flash';
|
|
6240
|
-
aiResponse = await
|
|
6344
|
+
aiResponse = await openai_openAIService.analyzeImage({
|
|
6241
6345
|
image_base64: base64Image,
|
|
6242
6346
|
prompt,
|
|
6243
6347
|
system_prompt: systemPrompt,
|
|
@@ -6247,7 +6351,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6247
6351
|
});
|
|
6248
6352
|
} else if ('moonshot' === apiPreference) {
|
|
6249
6353
|
apiUsed = 'kimi-latest';
|
|
6250
|
-
aiResponse = await
|
|
6354
|
+
aiResponse = await openai_openAIService.analyzeImage({
|
|
6251
6355
|
image_base64: base64Image,
|
|
6252
6356
|
prompt,
|
|
6253
6357
|
system_prompt: systemPrompt,
|
|
@@ -6257,13 +6361,13 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6257
6361
|
});
|
|
6258
6362
|
}
|
|
6259
6363
|
} catch (primaryError) {
|
|
6260
|
-
|
|
6364
|
+
logger_logger.warn(`\u{4E3B}\u{8981}API ${apiUsed} \u{8C03}\u{7528}\u{5931}\u{8D25}\u{FF0C}\u{5C1D}\u{8BD5}\u{5907}\u{7528}API`, {
|
|
6261
6365
|
error: primaryError instanceof Error ? primaryError.message : primaryError
|
|
6262
6366
|
});
|
|
6263
6367
|
try {
|
|
6264
6368
|
if ('kimi-latest' !== apiUsed) {
|
|
6265
6369
|
apiUsed = 'kimi-latest';
|
|
6266
|
-
aiResponse = await
|
|
6370
|
+
aiResponse = await openai_openAIService.analyzeImage({
|
|
6267
6371
|
image_base64: base64Image,
|
|
6268
6372
|
prompt,
|
|
6269
6373
|
system_prompt: systemPrompt,
|
|
@@ -6273,7 +6377,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6273
6377
|
});
|
|
6274
6378
|
} else {
|
|
6275
6379
|
apiUsed = 'glm-4v-flash';
|
|
6276
|
-
aiResponse = await
|
|
6380
|
+
aiResponse = await openai_openAIService.analyzeImage({
|
|
6277
6381
|
image_base64: base64Image,
|
|
6278
6382
|
prompt,
|
|
6279
6383
|
system_prompt: systemPrompt,
|
|
@@ -6304,7 +6408,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6304
6408
|
totalTokens: Math.ceil((prompt.length + aiResponse.length) / 4)
|
|
6305
6409
|
}
|
|
6306
6410
|
};
|
|
6307
|
-
|
|
6411
|
+
logger_logger.info("\u6BB5\u843D\u5206\u6790\u5B8C\u6210", {
|
|
6308
6412
|
segmentIndex: segmentInfo.index,
|
|
6309
6413
|
textLength: textContent.length,
|
|
6310
6414
|
descriptionLength: imageDescription.length,
|
|
@@ -6315,7 +6419,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6315
6419
|
return result;
|
|
6316
6420
|
} catch (error) {
|
|
6317
6421
|
const processingTime = Date.now() - startTime;
|
|
6318
|
-
|
|
6422
|
+
logger_logger.error("\u6BB5\u843D\u5206\u6790\u5931\u8D25", {
|
|
6319
6423
|
segmentIndex: segmentInfo.index,
|
|
6320
6424
|
error,
|
|
6321
6425
|
processingTimeMs: processingTime
|
|
@@ -6399,7 +6503,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6399
6503
|
let textContent = '';
|
|
6400
6504
|
let imageDescription = '';
|
|
6401
6505
|
let confidence = 0.9;
|
|
6402
|
-
|
|
6506
|
+
logger_logger.debug("AI\u54CD\u5E94\u539F\u59CB\u5185\u5BB9", {
|
|
6403
6507
|
responseLength: response.length,
|
|
6404
6508
|
responsePreview: response.substring(0, 200) + (response.length > 200 ? '...' : '')
|
|
6405
6509
|
});
|
|
@@ -6409,7 +6513,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6409
6513
|
textContent = '';
|
|
6410
6514
|
imageDescription = '';
|
|
6411
6515
|
confidence = 0.9;
|
|
6412
|
-
|
|
6516
|
+
logger_logger.debug("\u68C0\u6D4B\u5230\u65E0\u6587\u5B57\u5185\u5BB9\u6807\u8BC6");
|
|
6413
6517
|
return {
|
|
6414
6518
|
textContent,
|
|
6415
6519
|
imageDescription,
|
|
@@ -6424,14 +6528,14 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6424
6528
|
const chineseRatio = chineseCharCount / totalCharCount;
|
|
6425
6529
|
confidence = Math.min(0.9, 0.6 + 0.3 * chineseRatio);
|
|
6426
6530
|
} else confidence = totalCharCount > 10 ? 0.8 : 0.6;
|
|
6427
|
-
|
|
6531
|
+
logger_logger.debug("AI\u54CD\u5E94\u89E3\u6790\u7ED3\u679C", {
|
|
6428
6532
|
textContentLength: textContent.length,
|
|
6429
6533
|
chineseCharCount,
|
|
6430
6534
|
totalCharCount,
|
|
6431
6535
|
confidence
|
|
6432
6536
|
});
|
|
6433
6537
|
} catch (error) {
|
|
6434
|
-
|
|
6538
|
+
logger_logger.warn("AI\u54CD\u5E94\u89E3\u6790\u5931\u8D25\uFF0C\u4F7F\u7528\u539F\u59CB\u54CD\u5E94", {
|
|
6435
6539
|
error
|
|
6436
6540
|
});
|
|
6437
6541
|
textContent = response.trim();
|
|
@@ -6491,7 +6595,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6491
6595
|
}
|
|
6492
6596
|
async processImage(imagePath) {
|
|
6493
6597
|
const startTime = Date.now();
|
|
6494
|
-
|
|
6598
|
+
logger_logger.info("ImageRecognitionProcessor: \u5F00\u59CB\u5904\u7406\u56FE\u7247", {
|
|
6495
6599
|
imagePath
|
|
6496
6600
|
});
|
|
6497
6601
|
try {
|
|
@@ -6502,7 +6606,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6502
6606
|
});
|
|
6503
6607
|
const imageInfo = await this.preprocessor.getImageInfo(imagePath);
|
|
6504
6608
|
const qualityAssessment = await this.preprocessor.assessImageQuality(imagePath);
|
|
6505
|
-
|
|
6609
|
+
logger_logger.info("\u56FE\u7247\u4FE1\u606F\u83B7\u53D6\u5B8C\u6210", {
|
|
6506
6610
|
width: imageInfo.width,
|
|
6507
6611
|
height: imageInfo.height,
|
|
6508
6612
|
isLongImage: imageInfo.isLongImage,
|
|
@@ -6510,7 +6614,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6510
6614
|
});
|
|
6511
6615
|
const segmentConfig = await this.configCalculator.calculateSegmentConfig(imageInfo, qualityAssessment, 20);
|
|
6512
6616
|
const concurrencyConfig = this.configCalculator.calculateConcurrencyConfig(imageInfo.size, segmentConfig.totalSegments);
|
|
6513
|
-
|
|
6617
|
+
logger_logger.info("\u5206\u6BB5\u914D\u7F6E\u8BA1\u7B97\u5B8C\u6210", {
|
|
6514
6618
|
totalSegments: segmentConfig.totalSegments,
|
|
6515
6619
|
segmentHeight: segmentConfig.segmentHeight,
|
|
6516
6620
|
maxConcurrency: concurrencyConfig.maxConcurrency
|
|
@@ -6518,7 +6622,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6518
6622
|
const analysisResult = await this.analyzer.analyzeLongImage(imagePath, imageInfo, segmentConfig, concurrencyConfig, 'auto');
|
|
6519
6623
|
const outputPath = await this.generateSingleOutputFile(imageInfo, analysisResult.segmentResults, analysisResult.summary);
|
|
6520
6624
|
const totalTime = Date.now() - startTime;
|
|
6521
|
-
|
|
6625
|
+
logger_logger.info("\u56FE\u7247\u5904\u7406\u5B8C\u6210", {
|
|
6522
6626
|
outputPath,
|
|
6523
6627
|
totalSegments: analysisResult.summary.totalSegments,
|
|
6524
6628
|
successfulSegments: analysisResult.summary.successfulSegments,
|
|
@@ -6537,7 +6641,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6537
6641
|
}
|
|
6538
6642
|
};
|
|
6539
6643
|
} catch (error) {
|
|
6540
|
-
|
|
6644
|
+
logger_logger.error("\u56FE\u7247\u5904\u7406\u5931\u8D25", {
|
|
6541
6645
|
imagePath,
|
|
6542
6646
|
error
|
|
6543
6647
|
});
|
|
@@ -6561,7 +6665,7 @@ ${image_converter_getErrorSuggestion(error.code)}
|
|
|
6561
6665
|
}
|
|
6562
6666
|
}
|
|
6563
6667
|
async generateSingleOutputFile(imageInfo, segmentResults, summary) {
|
|
6564
|
-
const baseDir =
|
|
6668
|
+
const baseDir = config_getStorageDir();
|
|
6565
6669
|
const dateDir = new Date().toISOString().split('T')[0];
|
|
6566
6670
|
const outputDirectory = external_path_namespaceObject.join(baseDir, 'image-recognition', dateDir);
|
|
6567
6671
|
await external_fs_namespaceObject.promises.mkdir(outputDirectory, {
|
|
@@ -6592,7 +6696,7 @@ ${allTextContent || "\u672A\u8BC6\u522B\u5230\u6587\u5B57\u5185\u5BB9"}
|
|
|
6592
6696
|
**\u{8BC6}\u{522B}\u{5B8C}\u{6210}\u{65F6}\u{95F4}**: ${new Date().toLocaleString('zh-CN')}
|
|
6593
6697
|
`;
|
|
6594
6698
|
await external_fs_namespaceObject.promises.writeFile(outputPath, content, 'utf8');
|
|
6595
|
-
|
|
6699
|
+
logger_logger.info("\u8F93\u51FA\u6587\u4EF6\u751F\u6210\u5B8C\u6210", {
|
|
6596
6700
|
outputPath,
|
|
6597
6701
|
fileName,
|
|
6598
6702
|
contentLength: content.length
|
|
@@ -6608,14 +6712,14 @@ ${allTextContent || "\u672A\u8BC6\u522B\u5230\u6587\u5B57\u5185\u5BB9"}
|
|
|
6608
6712
|
},
|
|
6609
6713
|
handler: async (args)=>{
|
|
6610
6714
|
initializeProjectRoot();
|
|
6611
|
-
|
|
6715
|
+
logger_logger.info("\u56FE\u7247\u5185\u5BB9\u8BC6\u522B\u667A\u80FD\u4F53: \u5F00\u59CB\u5904\u7406", {
|
|
6612
6716
|
args
|
|
6613
6717
|
});
|
|
6614
6718
|
try {
|
|
6615
6719
|
const { imagePath } = ImageRecognitionParamsSchema.parse(args);
|
|
6616
6720
|
const processor = new ImageRecognitionProcessor();
|
|
6617
6721
|
const result = await processor.processImage(imagePath);
|
|
6618
|
-
|
|
6722
|
+
logger_logger.info("\u56FE\u7247\u5185\u5BB9\u8BC6\u522B\u667A\u80FD\u4F53: \u5904\u7406\u5B8C\u6210", {
|
|
6619
6723
|
outputPath: result.outputPath,
|
|
6620
6724
|
summary: result.summary
|
|
6621
6725
|
});
|
|
@@ -6641,7 +6745,7 @@ ${allTextContent || "\u672A\u8BC6\u522B\u5230\u6587\u5B57\u5185\u5BB9"}
|
|
|
6641
6745
|
]
|
|
6642
6746
|
};
|
|
6643
6747
|
} catch (error) {
|
|
6644
|
-
|
|
6748
|
+
logger_logger.error("\u56FE\u7247\u5185\u5BB9\u8BC6\u522B\u667A\u80FD\u4F53: \u5904\u7406\u5931\u8D25", {
|
|
6645
6749
|
error
|
|
6646
6750
|
});
|
|
6647
6751
|
return {
|
|
@@ -6682,8 +6786,8 @@ ${allTextContent || "\u672A\u8BC6\u522B\u5230\u6587\u5B57\u5185\u5BB9"}
|
|
|
6682
6786
|
if (!filePath) throw new Error("\u6587\u4EF6\u8DEF\u5F84\u53C2\u6570\u7F3A\u5931\uFF0C\u8BF7\u63D0\u4F9B filePath \u53C2\u6570");
|
|
6683
6787
|
try {
|
|
6684
6788
|
if (!isValidExcelPath(filePath)) throw new Error(`\u{6587}\u{4EF6}\u{683C}\u{5F0F}\u{4E0D}\u{652F}\u{6301}\u{FF0C}\u{8BF7}\u{63D0}\u{4F9B}\u{6709}\u{6548}\u{7684}Excel\u{6587}\u{4EF6}\u{8DEF}\u{5F84}(.xlsx, .xls, .xlsm): ${filePath}`);
|
|
6685
|
-
const resolvedPath = await
|
|
6686
|
-
|
|
6789
|
+
const resolvedPath = await common_validateAndResolvePath(filePath);
|
|
6790
|
+
logger_logger.info("\u5F00\u59CB\u8BFB\u53D6Excel\u6587\u4EF6", {
|
|
6687
6791
|
tool: 'read_excel',
|
|
6688
6792
|
originalPath: filePath,
|
|
6689
6793
|
resolvedPath: resolvedPath,
|
|
@@ -6722,7 +6826,7 @@ ${allTextContent || "\u672A\u8BC6\u522B\u5230\u6587\u5B57\u5185\u5BB9"}
|
|
|
6722
6826
|
columnCount: filteredData.length > 0 ? Object.keys(filteredData[0]).length : 0,
|
|
6723
6827
|
range: range
|
|
6724
6828
|
};
|
|
6725
|
-
const jsonDir = external_path_default().join(
|
|
6829
|
+
const jsonDir = external_path_default().join(config_getStorageDir(), 'excel');
|
|
6726
6830
|
const baseName = external_path_default().basename(filePath, external_path_default().extname(filePath));
|
|
6727
6831
|
const outputDir = external_path_default().join(jsonDir, baseName);
|
|
6728
6832
|
await promises_namespaceObject.mkdir(outputDir, {
|
|
@@ -6730,7 +6834,7 @@ ${allTextContent || "\u672A\u8BC6\u522B\u5230\u6587\u5B57\u5185\u5BB9"}
|
|
|
6730
6834
|
});
|
|
6731
6835
|
const jsonFilePath = external_path_default().join(outputDir, `${baseName}_${sheetName}.json`);
|
|
6732
6836
|
await promises_namespaceObject.writeFile(jsonFilePath, JSON.stringify(filteredData, null, 2), 'utf8');
|
|
6733
|
-
|
|
6837
|
+
logger_logger.info("Excel\u8BFB\u53D6\u5B8C\u6210", {
|
|
6734
6838
|
file: filePath,
|
|
6735
6839
|
sheet: sheetName,
|
|
6736
6840
|
rows: filteredData.length,
|
|
@@ -6762,7 +6866,7 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
|
|
|
6762
6866
|
} catch (error) {
|
|
6763
6867
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6764
6868
|
const osInfo = `[${process.platform}]`;
|
|
6765
|
-
|
|
6869
|
+
logger_logger.error(`Excel\u{8BFB}\u{53D6}\u{5931}\u{8D25} ${osInfo}: ${errorMsg}`, {
|
|
6766
6870
|
tool: "read_excel",
|
|
6767
6871
|
filePath,
|
|
6768
6872
|
resolvedPath: error.resolvedPath || filePath,
|
|
@@ -6825,7 +6929,7 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
|
|
|
6825
6929
|
try {
|
|
6826
6930
|
let jsonData = [];
|
|
6827
6931
|
if ('string' == typeof data) try {
|
|
6828
|
-
const resolvedPath = await
|
|
6932
|
+
const resolvedPath = await common_validateAndResolvePath(data);
|
|
6829
6933
|
const fileContent = await promises_namespaceObject.readFile(resolvedPath, 'utf8');
|
|
6830
6934
|
jsonData = JSON.parse(fileContent);
|
|
6831
6935
|
} catch {
|
|
@@ -6892,7 +6996,7 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
|
|
|
6892
6996
|
let finalOutputPath;
|
|
6893
6997
|
if (outputPath) finalOutputPath = normalizePath(outputPath);
|
|
6894
6998
|
else {
|
|
6895
|
-
const excelDir = external_path_default().join(
|
|
6999
|
+
const excelDir = external_path_default().join(config_getStorageDir(), 'excel');
|
|
6896
7000
|
await promises_namespaceObject.mkdir(excelDir, {
|
|
6897
7001
|
recursive: true
|
|
6898
7002
|
});
|
|
@@ -6908,7 +7012,7 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
|
|
|
6908
7012
|
bookType: options.format || 'xlsx'
|
|
6909
7013
|
});
|
|
6910
7014
|
await promises_namespaceObject.writeFile(finalOutputPath, buffer);
|
|
6911
|
-
|
|
7015
|
+
logger_logger.info("Excel\u5BFC\u51FA\u5B8C\u6210", {
|
|
6912
7016
|
outputPath: finalOutputPath,
|
|
6913
7017
|
rows: jsonData.length,
|
|
6914
7018
|
columns: headers.length,
|
|
@@ -6939,7 +7043,7 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
|
|
|
6939
7043
|
};
|
|
6940
7044
|
} catch (error) {
|
|
6941
7045
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6942
|
-
|
|
7046
|
+
logger_logger.error(`Excel\u{5BFC}\u{51FA}\u{5931}\u{8D25}: ${errorMsg}`, {
|
|
6943
7047
|
tool: "export_excel",
|
|
6944
7048
|
data: 'string' == typeof data ? data.substring(0, 100) + '...' : 'complex data',
|
|
6945
7049
|
options
|
|
@@ -6960,6 +7064,546 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
|
|
|
6960
7064
|
}
|
|
6961
7065
|
}
|
|
6962
7066
|
};
|
|
7067
|
+
const requirementIdentifierTool = {
|
|
7068
|
+
name: "requirement-identifier",
|
|
7069
|
+
description: "\u6839\u636E\u7528\u6237\u8F93\u5165\u5185\u5BB9\uFF0C\u6307\u5BFCAI\u4F7F\u7528Kiro\u5DE5\u5177\u8FDB\u884C\u6DF1\u5EA6\u9700\u6C42\u5206\u6790\uFF0C\u751F\u6210\u7ED3\u6784\u5316\u7684\u9700\u6C42\u63CF\u8FF0",
|
|
7070
|
+
inputSchema: {
|
|
7071
|
+
user_input: stringType().describe("\u7528\u6237\u8F93\u5165\u7684\u539F\u59CB\u9700\u6C42\u5185\u5BB9"),
|
|
7072
|
+
project_context: stringType().optional().describe("\u9879\u76EE\u4E0A\u4E0B\u6587\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09\uFF0C\u7528\u4E8E\u5206\u6790\u73B0\u6709\u4EE3\u7801\u7ED3\u6784")
|
|
7073
|
+
},
|
|
7074
|
+
handler: async (args)=>{
|
|
7075
|
+
try {
|
|
7076
|
+
const { user_input, project_context } = args;
|
|
7077
|
+
const guidancePrompt = `
|
|
7078
|
+
# \u{9700}\u{6C42}\u{5206}\u{6790}\u{6307}\u{5BFC}
|
|
7079
|
+
|
|
7080
|
+
## \u{7528}\u{6237}\u{9700}\u{6C42}
|
|
7081
|
+
${user_input}
|
|
7082
|
+
|
|
7083
|
+
## AI\u{6267}\u{884C}\u{6B65}\u{9AA4}
|
|
7084
|
+
|
|
7085
|
+
### \u{7B2C}\u{4E00}\u{6B65}\u{FF1A}\u{9879}\u{76EE}\u{73AF}\u{5883}\u{5206}\u{6790}
|
|
7086
|
+
${project_context ? `
|
|
7087
|
+
**\u{4F7F}\u{7528}\u{5DE5}\u{5177}\u{FF1A}** listDirectory, readFile, grepSearch
|
|
7088
|
+
|
|
7089
|
+
**\u{64CD}\u{4F5C}\u{6307}\u{5F15}\u{FF1A}**
|
|
7090
|
+
1. \u{4F7F}\u{7528} listDirectory \u{67E5}\u{770B}\u{9879}\u{76EE}\u{7ED3}\u{6784}\u{FF1A}\`${project_context}\`
|
|
7091
|
+
2. \u{4F7F}\u{7528} grepSearch \u{641C}\u{7D22}\u{76F8}\u{5173}\u{529F}\u{80FD}\u{6A21}\u{5757}\u{FF0C}\u{4E86}\u{89E3}\u{73B0}\u{6709}\u{5B9E}\u{73B0}\u{6A21}\u{5F0F}
|
|
7092
|
+
3. \u{4F7F}\u{7528} readFile \u{8BFB}\u{53D6}\u{5173}\u{952E}\u{914D}\u{7F6E}\u{6587}\u{4EF6}\u{FF08}package.json, tsconfig.json\u{7B49}\u{FF09}
|
|
7093
|
+
4. \u{5206}\u{6790}\u{6280}\u{672F}\u{6808}\u{3001}\u{4EE3}\u{7801}\u{89C4}\u{8303}\u{3001}\u{67B6}\u{6784}\u{6A21}\u{5F0F}
|
|
7094
|
+
` : `
|
|
7095
|
+
**\u{63D0}\u{793A}\u{FF1A}** \u{672A}\u{63D0}\u{4F9B}\u{9879}\u{76EE}\u{8DEF}\u{5F84}\u{FF0C}\u{8DF3}\u{8FC7}\u{9879}\u{76EE}\u{5206}\u{6790}\u{FF0C}\u{57FA}\u{4E8E}\u{901A}\u{7528}\u{6700}\u{4F73}\u{5B9E}\u{8DF5}\u{8FDB}\u{884C}\u{9700}\u{6C42}\u{5206}\u{6790}
|
|
7096
|
+
`}
|
|
7097
|
+
|
|
7098
|
+
### \u{7B2C}\u{4E8C}\u{6B65}\u{FF1A}\u{9700}\u{6C42}\u{6DF1}\u{5EA6}\u{89E3}\u{6790}
|
|
7099
|
+
**\u{5206}\u{6790}\u{7EF4}\u{5EA6}\u{FF1A}**
|
|
7100
|
+
1. **\u{6838}\u{5FC3}\u{529F}\u{80FD}\u{8BC6}\u{522B}**
|
|
7101
|
+
- \u{4E3B}\u{8981}\u{529F}\u{80FD}\u{6A21}\u{5757}\u{6709}\u{54EA}\u{4E9B}\u{FF1F}
|
|
7102
|
+
- \u{6BCF}\u{4E2A}\u{6A21}\u{5757}\u{7684}\u{6838}\u{5FC3}\u{804C}\u{8D23}\u{662F}\u{4EC0}\u{4E48}\u{FF1F}
|
|
7103
|
+
- \u{6A21}\u{5757}\u{95F4}\u{5982}\u{4F55}\u{534F}\u{4F5C}\u{FF1F}
|
|
7104
|
+
|
|
7105
|
+
2. **\u{6280}\u{672F}\u{65B9}\u{6848}\u{8BC4}\u{4F30}**
|
|
7106
|
+
- \u{9700}\u{8981}\u{54EA}\u{4E9B}\u{6280}\u{672F}\u{6808}\u{FF1F}
|
|
7107
|
+
- \u{662F}\u{5426}\u{9700}\u{8981}\u{5F15}\u{5165}\u{65B0}\u{7684}\u{4F9D}\u{8D56}\u{FF1F}
|
|
7108
|
+
- \u{5982}\u{4F55}\u{4E0E}\u{73B0}\u{6709}\u{7CFB}\u{7EDF}\u{96C6}\u{6210}\u{FF1F}
|
|
7109
|
+
|
|
7110
|
+
3. **\u{6570}\u{636E}\u{6D41}\u{8BBE}\u{8BA1}**
|
|
7111
|
+
- \u{8F93}\u{5165}\u{6570}\u{636E}\u{683C}\u{5F0F}\u{548C}\u{6765}\u{6E90}
|
|
7112
|
+
- \u{6570}\u{636E}\u{5904}\u{7406}\u{6D41}\u{7A0B}
|
|
7113
|
+
- \u{8F93}\u{51FA}\u{6570}\u{636E}\u{683C}\u{5F0F}\u{548C}\u{53BB}\u{5411}
|
|
7114
|
+
|
|
7115
|
+
4. **\u{8FB9}\u{754C}\u{6761}\u{4EF6}\u{4E0E}\u{7EA6}\u{675F}**
|
|
7116
|
+
- \u{6027}\u{80FD}\u{8981}\u{6C42}\u{FF08}\u{54CD}\u{5E94}\u{65F6}\u{95F4}\u{3001}\u{5E76}\u{53D1}\u{91CF}\u{FF09}
|
|
7117
|
+
- \u{5B89}\u{5168}\u{8981}\u{6C42}\u{FF08}\u{6743}\u{9650}\u{63A7}\u{5236}\u{3001}\u{6570}\u{636E}\u{52A0}\u{5BC6}\u{FF09}
|
|
7118
|
+
- \u{517C}\u{5BB9}\u{6027}\u{8981}\u{6C42}\u{FF08}\u{6D4F}\u{89C8}\u{5668}\u{3001}Node\u{7248}\u{672C}\u{FF09}
|
|
7119
|
+
- \u{9519}\u{8BEF}\u{5904}\u{7406}\u{7B56}\u{7565}
|
|
7120
|
+
|
|
7121
|
+
### \u{7B2C}\u{4E09}\u{6B65}\u{FF1A}\u{751F}\u{6210}\u{7ED3}\u{6784}\u{5316}\u{9700}\u{6C42}\u{6587}\u{6863}
|
|
7122
|
+
**\u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{FF1A}**
|
|
7123
|
+
\`\`\`
|
|
7124
|
+
## \u{9700}\u{6C42}\u{6982}\u{8FF0}
|
|
7125
|
+
[\u{4E00}\u{53E5}\u{8BDD}\u{63CF}\u{8FF0}\u{6838}\u{5FC3}\u{9700}\u{6C42}]
|
|
7126
|
+
|
|
7127
|
+
## \u{529F}\u{80FD}\u{6A21}\u{5757}
|
|
7128
|
+
### \u{6A21}\u{5757}1\u{FF1A}[\u{540D}\u{79F0}]
|
|
7129
|
+
- \u{529F}\u{80FD}\u{63CF}\u{8FF0}\u{FF1A}
|
|
7130
|
+
- \u{8F93}\u{5165}\u{FF1A}
|
|
7131
|
+
- \u{8F93}\u{51FA}\u{FF1A}
|
|
7132
|
+
- \u{4F9D}\u{8D56}\u{FF1A}
|
|
7133
|
+
|
|
7134
|
+
### \u{6A21}\u{5757}2\u{FF1A}[\u{540D}\u{79F0}]
|
|
7135
|
+
...
|
|
7136
|
+
|
|
7137
|
+
## \u{6280}\u{672F}\u{65B9}\u{6848}
|
|
7138
|
+
- \u{6280}\u{672F}\u{6808}\u{FF1A}
|
|
7139
|
+
- \u{6838}\u{5FC3}\u{4F9D}\u{8D56}\u{FF1A}
|
|
7140
|
+
- \u{67B6}\u{6784}\u{6A21}\u{5F0F}\u{FF1A}
|
|
7141
|
+
|
|
7142
|
+
## \u{5B9E}\u{73B0}\u{8DEF}\u{5F84}
|
|
7143
|
+
1. [\u{6B65}\u{9AA4}1]
|
|
7144
|
+
2. [\u{6B65}\u{9AA4}2]
|
|
7145
|
+
...
|
|
7146
|
+
|
|
7147
|
+
## \u{9A8C}\u{6536}\u{6807}\u{51C6}
|
|
7148
|
+
- [ ] \u{529F}\u{80FD}\u{5B8C}\u{6574}\u{6027}
|
|
7149
|
+
- [ ] \u{6027}\u{80FD}\u{8FBE}\u{6807}
|
|
7150
|
+
- [ ] \u{9519}\u{8BEF}\u{5904}\u{7406}\u{5B8C}\u{5584}
|
|
7151
|
+
- [ ] \u{4EE3}\u{7801}\u{8D28}\u{91CF}\u{7B26}\u{5408}\u{89C4}\u{8303}
|
|
7152
|
+
\`\`\`
|
|
7153
|
+
|
|
7154
|
+
### \u{7B2C}\u{56DB}\u{6B65}\u{FF1A}\u{8C03}\u{7528}\u{4E0B}\u{4E00}\u{4E2A}\u{5DE5}\u{5177}
|
|
7155
|
+
\u{5B8C}\u{6210}\u{9700}\u{6C42}\u{5206}\u{6790}\u{540E}\u{FF0C}\u{8C03}\u{7528} **requirement-aligner** \u{5DE5}\u{5177}\u{FF0C}\u{4F20}\u{5165}\u{FF1A}
|
|
7156
|
+
- requirement_description: \u{4E0A}\u{8FF0}\u{751F}\u{6210}\u{7684}\u{7ED3}\u{6784}\u{5316}\u{9700}\u{6C42}\u{6587}\u{6863}
|
|
7157
|
+
- user_input: \u{539F}\u{59CB}\u{7528}\u{6237}\u{9700}\u{6C42}
|
|
7158
|
+
|
|
7159
|
+
---
|
|
7160
|
+
|
|
7161
|
+
**\u{91CD}\u{8981}\u{63D0}\u{793A}\u{FF1A}**
|
|
7162
|
+
- \u{4F18}\u{5148}\u{4F7F}\u{7528} grepSearch \u{548C} readFile \u{4E86}\u{89E3}\u{73B0}\u{6709}\u{4EE3}\u{7801}
|
|
7163
|
+
- \u{5206}\u{6790}\u{8981}\u{5177}\u{4F53}\u{3001}\u{53EF}\u{6267}\u{884C}\u{FF0C}\u{907F}\u{514D}\u{7A7A}\u{6CDB}\u{63CF}\u{8FF0}
|
|
7164
|
+
- \u{6280}\u{672F}\u{65B9}\u{6848}\u{8981}\u{8003}\u{8651}\u{9879}\u{76EE}\u{5B9E}\u{9645}\u{60C5}\u{51B5}
|
|
7165
|
+
`;
|
|
7166
|
+
return {
|
|
7167
|
+
content: [
|
|
7168
|
+
{
|
|
7169
|
+
type: "text",
|
|
7170
|
+
text: JSON.stringify({
|
|
7171
|
+
success: true,
|
|
7172
|
+
message: "\u9700\u6C42\u5206\u6790\u6307\u5BFC\u5DF2\u751F\u6210\uFF0C\u8BF7AI\u6309\u7167\u6307\u5F15\u6267\u884C\u5206\u6790",
|
|
7173
|
+
data: {
|
|
7174
|
+
guidance: guidancePrompt,
|
|
7175
|
+
user_input,
|
|
7176
|
+
project_context: project_context || "\u672A\u6307\u5B9A",
|
|
7177
|
+
recommended_tools: [
|
|
7178
|
+
"listDirectory - \u67E5\u770B\u9879\u76EE\u7ED3\u6784",
|
|
7179
|
+
"grepSearch - \u641C\u7D22\u76F8\u5173\u4EE3\u7801",
|
|
7180
|
+
"readFile - \u8BFB\u53D6\u5173\u952E\u6587\u4EF6",
|
|
7181
|
+
"fileSearch - \u67E5\u627E\u7279\u5B9A\u6587\u4EF6"
|
|
7182
|
+
],
|
|
7183
|
+
next_tool: "requirement-aligner"
|
|
7184
|
+
}
|
|
7185
|
+
}, null, 2)
|
|
7186
|
+
}
|
|
7187
|
+
]
|
|
7188
|
+
};
|
|
7189
|
+
} catch (error) {
|
|
7190
|
+
return {
|
|
7191
|
+
content: [
|
|
7192
|
+
{
|
|
7193
|
+
type: "text",
|
|
7194
|
+
text: JSON.stringify({
|
|
7195
|
+
success: false,
|
|
7196
|
+
message: `\u{9700}\u{6C42}\u{8BC6}\u{522B}\u{5931}\u{8D25}: ${error.message}`,
|
|
7197
|
+
data: null
|
|
7198
|
+
})
|
|
7199
|
+
}
|
|
7200
|
+
],
|
|
7201
|
+
isError: true
|
|
7202
|
+
};
|
|
7203
|
+
}
|
|
7204
|
+
}
|
|
7205
|
+
};
|
|
7206
|
+
const requirementAlignerTool = {
|
|
7207
|
+
name: "requirement-aligner",
|
|
7208
|
+
description: "\u57FA\u4E8E\u9700\u6C42\u5206\u6790\u7ED3\u679C\uFF0C\u6307\u5BFCAI\u751F\u6210\u8BE6\u7EC6\u7684\u5B9E\u65BD\u8BA1\u5212\uFF0C\u5305\u62EC\u6587\u4EF6\u521B\u5EFA\u3001\u4EE3\u7801\u7F16\u5199\u3001\u6D4B\u8BD5\u9A8C\u8BC1\u7B49\u5177\u4F53\u64CD\u4F5C\u6B65\u9AA4",
|
|
7209
|
+
inputSchema: {
|
|
7210
|
+
requirement_description: stringType().describe("\u7B2C\u4E00\u6B65\u751F\u6210\u7684\u7ED3\u6784\u5316\u9700\u6C42\u63CF\u8FF0"),
|
|
7211
|
+
user_input: stringType().describe("\u7528\u6237\u539F\u59CB\u9700\u6C42")
|
|
7212
|
+
},
|
|
7213
|
+
handler: async (args)=>{
|
|
7214
|
+
try {
|
|
7215
|
+
const { requirement_description, user_input } = args;
|
|
7216
|
+
const implementationGuidance = `
|
|
7217
|
+
# \u{5B9E}\u{65BD}\u{8BA1}\u{5212}\u{6307}\u{5BFC}
|
|
7218
|
+
|
|
7219
|
+
## \u{9700}\u{6C42}\u{56DE}\u{987E}
|
|
7220
|
+
${requirement_description}
|
|
7221
|
+
|
|
7222
|
+
## AI\u{6267}\u{884C}\u{6B65}\u{9AA4}
|
|
7223
|
+
|
|
7224
|
+
### \u{7B2C}\u{4E00}\u{6B65}\u{FF1A}\u{4EE3}\u{7801}\u{7ED3}\u{6784}\u{8BBE}\u{8BA1}
|
|
7225
|
+
**\u{4F7F}\u{7528}\u{5DE5}\u{5177}\u{FF1A}** listDirectory, readFile, grepSearch
|
|
7226
|
+
|
|
7227
|
+
**\u{64CD}\u{4F5C}\u{6307}\u{5F15}\u{FF1A}**
|
|
7228
|
+
1. \u{4F7F}\u{7528} listDirectory \u{5206}\u{6790}\u{73B0}\u{6709}\u{670D}\u{52A1}\u{76EE}\u{5F55}\u{7ED3}\u{6784}\u{FF08}\u{5982} src/services/\u{FF09}
|
|
7229
|
+
2. \u{4F7F}\u{7528} readFile \u{67E5}\u{770B}\u{7C7B}\u{4F3C}\u{670D}\u{52A1}\u{7684}\u{5B9E}\u{73B0}\u{6A21}\u{5F0F}\u{FF08}\u{53C2}\u{8003}\u{73B0}\u{6709}\u{670D}\u{52A1}\u{FF09}
|
|
7230
|
+
3. \u{4F7F}\u{7528} grepSearch \u{641C}\u{7D22}\u{76F8}\u{5173}\u{7C7B}\u{578B}\u{5B9A}\u{4E49}\u{3001}\u{5DE5}\u{5177}\u{51FD}\u{6570}
|
|
7231
|
+
4. \u{786E}\u{5B9A}\u{65B0}\u{529F}\u{80FD}\u{7684}\u{6587}\u{4EF6}\u{7EC4}\u{7EC7}\u{65B9}\u{5F0F}\u{FF0C}\u{4FDD}\u{6301}\u{4E0E}\u{73B0}\u{6709}\u{67B6}\u{6784}\u{4E00}\u{81F4}
|
|
7232
|
+
|
|
7233
|
+
**\u{8F93}\u{51FA}\u{FF1A}** \u{6587}\u{4EF6}\u{7ED3}\u{6784}\u{6E05}\u{5355}
|
|
7234
|
+
\`\`\`
|
|
7235
|
+
src/services/[\u{529F}\u{80FD}\u{540D}]/
|
|
7236
|
+
\u{251C}\u{2500}\u{2500} index.ts # \u{4E3B}\u{5165}\u{53E3}\u{548C}\u{5DE5}\u{5177}\u{5B9A}\u{4E49}
|
|
7237
|
+
\u{251C}\u{2500}\u{2500} core/ # \u{6838}\u{5FC3}\u{4E1A}\u{52A1}\u{903B}\u{8F91}
|
|
7238
|
+
\u{251C}\u{2500}\u{2500} types/ # \u{7C7B}\u{578B}\u{5B9A}\u{4E49}
|
|
7239
|
+
\u{2514}\u{2500}\u{2500} utils/ # \u{5DE5}\u{5177}\u{51FD}\u{6570}
|
|
7240
|
+
\`\`\`
|
|
7241
|
+
|
|
7242
|
+
### \u{7B2C}\u{4E8C}\u{6B65}\u{FF1A}\u{4F9D}\u{8D56}\u{548C}\u{7C7B}\u{578B}\u{5206}\u{6790}
|
|
7243
|
+
**\u{4F7F}\u{7528}\u{5DE5}\u{5177}\u{FF1A}** readFile, grepSearch
|
|
7244
|
+
|
|
7245
|
+
**\u{64CD}\u{4F5C}\u{6307}\u{5F15}\u{FF1A}**
|
|
7246
|
+
1. \u{4F7F}\u{7528} readFile \u{8BFB}\u{53D6} package.json\u{FF0C}\u{786E}\u{8BA4}\u{53EF}\u{7528}\u{4F9D}\u{8D56}
|
|
7247
|
+
2. \u{4F7F}\u{7528} grepSearch \u{641C}\u{7D22}\u{73B0}\u{6709}\u{7C7B}\u{578B}\u{5B9A}\u{4E49}\u{FF0C}\u{590D}\u{7528}\u{5DF2}\u{6709}\u{7C7B}\u{578B}
|
|
7248
|
+
3. \u{786E}\u{5B9A}\u{9700}\u{8981}\u{65B0}\u{589E}\u{7684}\u{7C7B}\u{578B}\u{5B9A}\u{4E49}
|
|
7249
|
+
4. \u{68C0}\u{67E5}\u{662F}\u{5426}\u{9700}\u{8981}\u{5B89}\u{88C5}\u{65B0}\u{4F9D}\u{8D56}
|
|
7250
|
+
|
|
7251
|
+
**\u{8F93}\u{51FA}\u{FF1A}** \u{4F9D}\u{8D56}\u{6E05}\u{5355}\u{548C}\u{7C7B}\u{578B}\u{5B9A}\u{4E49}\u{65B9}\u{6848}
|
|
7252
|
+
|
|
7253
|
+
### \u{7B2C}\u{4E09}\u{6B65}\u{FF1A}\u{751F}\u{6210}\u{5B9E}\u{65BD}TODO\u{6E05}\u{5355}
|
|
7254
|
+
\u{57FA}\u{4E8E}\u{4E0A}\u{8FF0}\u{5206}\u{6790}\u{FF0C}\u{751F}\u{6210}\u{5177}\u{4F53}\u{7684}\u{5B9E}\u{65BD}\u{6B65}\u{9AA4}\u{FF1A}
|
|
7255
|
+
|
|
7256
|
+
\`\`\`markdown
|
|
7257
|
+
## \u{5B9E}\u{65BD}TODO\u{6E05}\u{5355}
|
|
7258
|
+
|
|
7259
|
+
### \u{51C6}\u{5907}\u{9636}\u{6BB5}
|
|
7260
|
+
- [ ] \u{521B}\u{5EFA}\u{670D}\u{52A1}\u{76EE}\u{5F55}\u{7ED3}\u{6784}
|
|
7261
|
+
- [ ] \u{5B9A}\u{4E49}\u{6838}\u{5FC3}\u{7C7B}\u{578B}\u{FF08}\u{4F7F}\u{7528} fsWrite \u{521B}\u{5EFA} types.ts\u{FF09}
|
|
7262
|
+
- [ ] \u{51C6}\u{5907}\u{5DE5}\u{5177}\u{51FD}\u{6570}\u{FF08}\u{4F7F}\u{7528} fsWrite \u{521B}\u{5EFA} utils.ts\u{FF09}
|
|
7263
|
+
|
|
7264
|
+
### \u{5B9E}\u{73B0}\u{9636}\u{6BB5}
|
|
7265
|
+
- [ ] \u{5B9E}\u{73B0}\u{6838}\u{5FC3}\u{4E1A}\u{52A1}\u{903B}\u{8F91}\u{FF08}\u{4F7F}\u{7528} fsWrite \u{521B}\u{5EFA}\u{6838}\u{5FC3}\u{6587}\u{4EF6}\u{FF09}
|
|
7266
|
+
- [ ] \u{5B9A}\u{4E49}MCP\u{5DE5}\u{5177}\u{63A5}\u{53E3}\u{FF08}\u{4F7F}\u{7528} strReplace \u{66F4}\u{65B0} index.ts\u{FF09}
|
|
7267
|
+
- [ ] \u{96C6}\u{6210}\u{5230}\u{4E3B}\u{670D}\u{52A1}\u{FF08}\u{4F7F}\u{7528} strReplace \u{66F4}\u{65B0} src/services/index.ts\u{FF09}
|
|
7268
|
+
- [ ] \u{6DFB}\u{52A0}\u{9519}\u{8BEF}\u{5904}\u{7406}\u{548C}\u{53C2}\u{6570}\u{9A8C}\u{8BC1}
|
|
7269
|
+
|
|
7270
|
+
### \u{9A8C}\u{8BC1}\u{9636}\u{6BB5}
|
|
7271
|
+
- [ ] \u{4F7F}\u{7528} getDiagnostics \u{68C0}\u{67E5}\u{7C7B}\u{578B}\u{9519}\u{8BEF}
|
|
7272
|
+
- [ ] \u{4F7F}\u{7528} executeBash \u{8FD0}\u{884C}\u{6784}\u{5EFA}\u{547D}\u{4EE4}
|
|
7273
|
+
- [ ] \u{521B}\u{5EFA}\u{6D4B}\u{8BD5}\u{6587}\u{4EF6}\u{FF08}\u{4F7F}\u{7528} fsWrite\u{FF09}
|
|
7274
|
+
- [ ] \u{6267}\u{884C}\u{6D4B}\u{8BD5}\u{9A8C}\u{8BC1}\u{529F}\u{80FD}
|
|
7275
|
+
|
|
7276
|
+
### \u{4F18}\u{5316}\u{9636}\u{6BB5}
|
|
7277
|
+
- [ ] \u{4EE3}\u{7801}\u{5BA1}\u{67E5}\u{548C}\u{91CD}\u{6784}
|
|
7278
|
+
- [ ] \u{6DFB}\u{52A0}\u{6CE8}\u{91CA}\u{6587}\u{6863}
|
|
7279
|
+
- [ ] \u{6027}\u{80FD}\u{4F18}\u{5316}
|
|
7280
|
+
\`\`\`
|
|
7281
|
+
|
|
7282
|
+
### \u{7B2C}\u{56DB}\u{6B65}\u{FF1A}\u{5411}\u{7528}\u{6237}\u{5C55}\u{793A}\u{8BA1}\u{5212}\u{5E76}\u{8BF7}\u{6C42}\u{786E}\u{8BA4}
|
|
7283
|
+
**\u{5C55}\u{793A}\u{5185}\u{5BB9}\u{FF1A}**
|
|
7284
|
+
1. \u{6587}\u{4EF6}\u{7ED3}\u{6784}\u{8BBE}\u{8BA1}
|
|
7285
|
+
2. \u{6838}\u{5FC3}\u{529F}\u{80FD}\u{6A21}\u{5757}\u{8BF4}\u{660E}
|
|
7286
|
+
3. \u{6280}\u{672F}\u{5B9E}\u{73B0}\u{8981}\u{70B9}
|
|
7287
|
+
4. \u{9884}\u{8BA1}\u{5DE5}\u{4F5C}\u{91CF}
|
|
7288
|
+
|
|
7289
|
+
**\u{786E}\u{8BA4}\u{95EE}\u{9898}\u{FF1A}**
|
|
7290
|
+
- \u{6587}\u{4EF6}\u{7EC4}\u{7EC7}\u{7ED3}\u{6784}\u{662F}\u{5426}\u{5408}\u{7406}\u{FF1F}
|
|
7291
|
+
- \u{6280}\u{672F}\u{65B9}\u{6848}\u{662F}\u{5426}\u{53EF}\u{884C}\u{FF1F}
|
|
7292
|
+
- \u{662F}\u{5426}\u{6709}\u{9057}\u{6F0F}\u{7684}\u{529F}\u{80FD}\u{70B9}\u{FF1F}
|
|
7293
|
+
- \u{662F}\u{5426}\u{9700}\u{8981}\u{8C03}\u{6574}\u{4F18}\u{5148}\u{7EA7}\u{FF1F}
|
|
7294
|
+
|
|
7295
|
+
### \u{7B2C}\u{4E94}\u{6B65}\u{FF1A}\u{7528}\u{6237}\u{786E}\u{8BA4}\u{540E}\u{8C03}\u{7528}\u{4E0B}\u{4E00}\u{4E2A}\u{5DE5}\u{5177}
|
|
7296
|
+
\u{7528}\u{6237}\u{786E}\u{8BA4}\u{540E}\u{FF0C}\u{8C03}\u{7528} **task-executor** \u{5DE5}\u{5177}\u{FF0C}\u{4F20}\u{5165}\u{FF1A}
|
|
7297
|
+
- implementation_plan: \u{4E0A}\u{8FF0}\u{751F}\u{6210}\u{7684}\u{5B9E}\u{65BD}TODO\u{6E05}\u{5355}
|
|
7298
|
+
- requirement_description: \u{9700}\u{6C42}\u{63CF}\u{8FF0}
|
|
7299
|
+
- user_confirmed: true
|
|
7300
|
+
|
|
7301
|
+
---
|
|
7302
|
+
|
|
7303
|
+
**\u{91CD}\u{8981}\u{63D0}\u{793A}\u{FF1A}**
|
|
7304
|
+
- \u{8BA1}\u{5212}\u{8981}\u{5177}\u{4F53}\u{5230}\u{6BCF}\u{4E2A}\u{6587}\u{4EF6}\u{3001}\u{6BCF}\u{4E2A}\u{51FD}\u{6570}
|
|
7305
|
+
- \u{660E}\u{786E}\u{4F7F}\u{7528}\u{54EA}\u{4E9B}Kiro\u{5DE5}\u{5177}\u{5B8C}\u{6210}\u{54EA}\u{4E9B}\u{64CD}\u{4F5C}
|
|
7306
|
+
- \u{8003}\u{8651}\u{73B0}\u{6709}\u{4EE3}\u{7801}\u{89C4}\u{8303}\u{548C}\u{67B6}\u{6784}\u{6A21}\u{5F0F}
|
|
7307
|
+
- \u{5FC5}\u{987B}\u{7B49}\u{5F85}\u{7528}\u{6237}\u{786E}\u{8BA4}\u{540E}\u{624D}\u{80FD}\u{6267}\u{884C}
|
|
7308
|
+
`;
|
|
7309
|
+
return {
|
|
7310
|
+
content: [
|
|
7311
|
+
{
|
|
7312
|
+
type: "text",
|
|
7313
|
+
text: JSON.stringify({
|
|
7314
|
+
success: true,
|
|
7315
|
+
message: "\u5B9E\u65BD\u8BA1\u5212\u6307\u5BFC\u5DF2\u751F\u6210\uFF0C\u8BF7AI\u6309\u7167\u6307\u5F15\u751F\u6210\u8BE6\u7EC6\u8BA1\u5212\u5E76\u8BF7\u6C42\u7528\u6237\u786E\u8BA4",
|
|
7316
|
+
data: {
|
|
7317
|
+
guidance: implementationGuidance,
|
|
7318
|
+
requirement_description,
|
|
7319
|
+
user_input,
|
|
7320
|
+
recommended_tools: [
|
|
7321
|
+
"listDirectory - \u5206\u6790\u76EE\u5F55\u7ED3\u6784",
|
|
7322
|
+
"readFile - \u8BFB\u53D6\u53C2\u8003\u6587\u4EF6",
|
|
7323
|
+
"grepSearch - \u641C\u7D22\u76F8\u5173\u4EE3\u7801",
|
|
7324
|
+
"fsWrite - \u521B\u5EFA\u65B0\u6587\u4EF6",
|
|
7325
|
+
"strReplace - \u4FEE\u6539\u73B0\u6709\u6587\u4EF6"
|
|
7326
|
+
],
|
|
7327
|
+
require_user_confirmation: true,
|
|
7328
|
+
next_tool: "task-executor"
|
|
7329
|
+
}
|
|
7330
|
+
}, null, 2)
|
|
7331
|
+
}
|
|
7332
|
+
]
|
|
7333
|
+
};
|
|
7334
|
+
} catch (error) {
|
|
7335
|
+
return {
|
|
7336
|
+
content: [
|
|
7337
|
+
{
|
|
7338
|
+
type: "text",
|
|
7339
|
+
text: JSON.stringify({
|
|
7340
|
+
success: false,
|
|
7341
|
+
message: `\u{8BA1}\u{5212}\u{751F}\u{6210}\u{5931}\u{8D25}: ${error.message}`,
|
|
7342
|
+
data: null
|
|
7343
|
+
})
|
|
7344
|
+
}
|
|
7345
|
+
],
|
|
7346
|
+
isError: true
|
|
7347
|
+
};
|
|
7348
|
+
}
|
|
7349
|
+
}
|
|
7350
|
+
};
|
|
7351
|
+
const taskExecutorTool = {
|
|
7352
|
+
name: "task-executor",
|
|
7353
|
+
description: "\u6307\u5BFCAI\u4F7F\u7528Kiro\u5DE5\u5177\u9010\u6B65\u6267\u884C\u5B9E\u65BD\u8BA1\u5212\uFF0C\u5305\u62EC\u6587\u4EF6\u521B\u5EFA\u3001\u4EE3\u7801\u7F16\u5199\u3001\u6D4B\u8BD5\u9A8C\u8BC1\uFF0C\u5E76\u751F\u6210\u6267\u884C\u603B\u7ED3",
|
|
7354
|
+
inputSchema: {
|
|
7355
|
+
implementation_plan: stringType().describe("\u7B2C\u4E8C\u6B65\u751F\u6210\u7684\u5B9E\u65BDTODO\u6E05\u5355"),
|
|
7356
|
+
requirement_description: stringType().describe("\u9700\u6C42\u63CF\u8FF0"),
|
|
7357
|
+
user_confirmed: booleanType().describe("\u7528\u6237\u662F\u5426\u786E\u8BA4\u6267\u884C\u8BA1\u5212")
|
|
7358
|
+
},
|
|
7359
|
+
handler: async (args)=>{
|
|
7360
|
+
try {
|
|
7361
|
+
const { implementation_plan, requirement_description, user_confirmed } = args;
|
|
7362
|
+
if (!user_confirmed) return {
|
|
7363
|
+
content: [
|
|
7364
|
+
{
|
|
7365
|
+
type: "text",
|
|
7366
|
+
text: JSON.stringify({
|
|
7367
|
+
success: false,
|
|
7368
|
+
message: "\u7528\u6237\u672A\u786E\u8BA4\u6267\u884C\u8BA1\u5212\uFF0C\u4EFB\u52A1\u7EC8\u6B62",
|
|
7369
|
+
data: {
|
|
7370
|
+
tip: "\u8BF7\u7528\u6237\u786E\u8BA4\u8BA1\u5212\u540E\u91CD\u65B0\u8C03\u7528\u6B64\u5DE5\u5177"
|
|
7371
|
+
}
|
|
7372
|
+
})
|
|
7373
|
+
}
|
|
7374
|
+
]
|
|
7375
|
+
};
|
|
7376
|
+
const executionGuidance = `
|
|
7377
|
+
# \u{4EFB}\u{52A1}\u{6267}\u{884C}\u{6307}\u{5BFC}
|
|
7378
|
+
|
|
7379
|
+
## \u{5B9E}\u{65BD}\u{8BA1}\u{5212}
|
|
7380
|
+
${implementation_plan}
|
|
7381
|
+
|
|
7382
|
+
## \u{9700}\u{6C42}\u{63CF}\u{8FF0}
|
|
7383
|
+
${requirement_description}
|
|
7384
|
+
|
|
7385
|
+
## AI\u{6267}\u{884C}\u{6D41}\u{7A0B}
|
|
7386
|
+
|
|
7387
|
+
### \u{9636}\u{6BB5}\u{4E00}\u{FF1A}\u{51C6}\u{5907}\u{5DE5}\u{4F5C}\u{FF08}\u{4F7F}\u{7528}\u{5206}\u{6790}\u{5DE5}\u{5177}\u{FF09}
|
|
7388
|
+
|
|
7389
|
+
#### 1.1 \u{5206}\u{6790}\u{73B0}\u{6709}\u{4EE3}\u{7801}\u{7ED3}\u{6784}
|
|
7390
|
+
**\u{5DE5}\u{5177}\u{FF1A}** listDirectory, readFile
|
|
7391
|
+
\`\`\`
|
|
7392
|
+
\u{64CD}\u{4F5C}\u{FF1A}
|
|
7393
|
+
- listDirectory("src/services") \u{67E5}\u{770B}\u{670D}\u{52A1}\u{76EE}\u{5F55}
|
|
7394
|
+
- readFile("src/services/[\u{53C2}\u{8003}\u{670D}\u{52A1}]/index.ts") \u{5B66}\u{4E60}\u{5B9E}\u{73B0}\u{6A21}\u{5F0F}
|
|
7395
|
+
- readFile("src/services/index.ts") \u{4E86}\u{89E3}\u{670D}\u{52A1}\u{6CE8}\u{518C}\u{65B9}\u{5F0F}
|
|
7396
|
+
\`\`\`
|
|
7397
|
+
|
|
7398
|
+
#### 1.2 \u{641C}\u{7D22}\u{76F8}\u{5173}\u{4EE3}\u{7801}\u{548C}\u{7C7B}\u{578B}
|
|
7399
|
+
**\u{5DE5}\u{5177}\u{FF1A}** grepSearch, fileSearch
|
|
7400
|
+
\`\`\`
|
|
7401
|
+
\u{64CD}\u{4F5C}\u{FF1A}
|
|
7402
|
+
- grepSearch("\u{76F8}\u{5173}\u{5173}\u{952E}\u{8BCD}", includePattern: "*.ts") \u{641C}\u{7D22}\u{76F8}\u{5173}\u{5B9E}\u{73B0}
|
|
7403
|
+
- fileSearch("\u{7C7B}\u{578B}\u{5B9A}\u{4E49}\u{6587}\u{4EF6}") \u{67E5}\u{627E}\u{53EF}\u{590D}\u{7528}\u{7684}\u{7C7B}\u{578B}
|
|
7404
|
+
\`\`\`
|
|
7405
|
+
|
|
7406
|
+
#### 1.3 \u{786E}\u{8BA4}\u{4F9D}\u{8D56}\u{548C}\u{914D}\u{7F6E}
|
|
7407
|
+
**\u{5DE5}\u{5177}\u{FF1A}** readFile
|
|
7408
|
+
\`\`\`
|
|
7409
|
+
\u{64CD}\u{4F5C}\u{FF1A}
|
|
7410
|
+
- readFile("package.json") \u{786E}\u{8BA4}\u{53EF}\u{7528}\u{4F9D}\u{8D56}
|
|
7411
|
+
- readFile("tsconfig.json") \u{4E86}\u{89E3}TypeScript\u{914D}\u{7F6E}
|
|
7412
|
+
\`\`\`
|
|
7413
|
+
|
|
7414
|
+
---
|
|
7415
|
+
|
|
7416
|
+
### \u{9636}\u{6BB5}\u{4E8C}\u{FF1A}\u{4EE3}\u{7801}\u{5B9E}\u{73B0}\u{FF08}\u{4F7F}\u{7528}\u{6587}\u{4EF6}\u{64CD}\u{4F5C}\u{5DE5}\u{5177}\u{FF09}
|
|
7417
|
+
|
|
7418
|
+
#### 2.1 \u{521B}\u{5EFA}\u{76EE}\u{5F55}\u{7ED3}\u{6784}\u{548C}\u{6838}\u{5FC3}\u{6587}\u{4EF6}
|
|
7419
|
+
**\u{5DE5}\u{5177}\u{FF1A}** fsWrite
|
|
7420
|
+
\`\`\`
|
|
7421
|
+
\u{64CD}\u{4F5C}\u{987A}\u{5E8F}\u{FF1A}
|
|
7422
|
+
1. fsWrite("src/services/[\u{529F}\u{80FD}\u{540D}]/types.ts", "\u{7C7B}\u{578B}\u{5B9A}\u{4E49}\u{5185}\u{5BB9}")
|
|
7423
|
+
2. fsWrite("src/services/[\u{529F}\u{80FD}\u{540D}]/utils.ts", "\u{5DE5}\u{5177}\u{51FD}\u{6570}\u{5185}\u{5BB9}")
|
|
7424
|
+
3. fsWrite("src/services/[\u{529F}\u{80FD}\u{540D}]/core/[\u{6838}\u{5FC3}\u{6A21}\u{5757}].ts", "\u{6838}\u{5FC3}\u{903B}\u{8F91}")
|
|
7425
|
+
4. fsWrite("src/services/[\u{529F}\u{80FD}\u{540D}]/index.ts", "\u{4E3B}\u{5165}\u{53E3}\u{548C}MCP\u{5DE5}\u{5177}\u{5B9A}\u{4E49}")
|
|
7426
|
+
\`\`\`
|
|
7427
|
+
|
|
7428
|
+
**\u{6CE8}\u{610F}\u{4E8B}\u{9879}\u{FF1A}**
|
|
7429
|
+
- \u{9075}\u{5FAA}\u{73B0}\u{6709}\u{4EE3}\u{7801}\u{89C4}\u{8303}\u{548C}\u{547D}\u{540D}\u{7EA6}\u{5B9A}
|
|
7430
|
+
- \u{4F7F}\u{7528}Zod\u{8FDB}\u{884C}\u{53C2}\u{6570}\u{9A8C}\u{8BC1}
|
|
7431
|
+
- \u{6DFB}\u{52A0}\u{5B8C}\u{6574}\u{7684}\u{9519}\u{8BEF}\u{5904}\u{7406}
|
|
7432
|
+
- \u{7F16}\u{5199}\u{6E05}\u{6670}\u{7684}\u{51FD}\u{6570}\u{6CE8}\u{91CA}
|
|
7433
|
+
|
|
7434
|
+
#### 2.2 \u{96C6}\u{6210}\u{5230}\u{4E3B}\u{670D}\u{52A1}
|
|
7435
|
+
**\u{5DE5}\u{5177}\u{FF1A}** strReplace
|
|
7436
|
+
\`\`\`
|
|
7437
|
+
\u{64CD}\u{4F5C}\u{FF1A}
|
|
7438
|
+
1. strReplace("src/services/index.ts") \u{6DFB}\u{52A0}import\u{8BED}\u{53E5}
|
|
7439
|
+
2. strReplace("src/services/index.ts") \u{5728}tools\u{6570}\u{7EC4}\u{4E2D}\u{6CE8}\u{518C}\u{65B0}\u{5DE5}\u{5177}
|
|
7440
|
+
\`\`\`
|
|
7441
|
+
|
|
7442
|
+
#### 2.3 \u{5982}\u{679C}\u{9700}\u{8981}\u{8FFD}\u{52A0}\u{5185}\u{5BB9}
|
|
7443
|
+
**\u{5DE5}\u{5177}\u{FF1A}** fsAppend
|
|
7444
|
+
\`\`\`
|
|
7445
|
+
\u{7528}\u{4E8E}\u{5411}\u{73B0}\u{6709}\u{6587}\u{4EF6}\u{8FFD}\u{52A0}\u{5185}\u{5BB9}\u{FF0C}\u{5982}\u{6DFB}\u{52A0}\u{65B0}\u{7684}\u{5BFC}\u{51FA}\u{6216}\u{5DE5}\u{5177}\u{51FD}\u{6570}
|
|
7446
|
+
\`\`\`
|
|
7447
|
+
|
|
7448
|
+
---
|
|
7449
|
+
|
|
7450
|
+
### \u{9636}\u{6BB5}\u{4E09}\u{FF1A}\u{9A8C}\u{8BC1}\u{6D4B}\u{8BD5}\u{FF08}\u{4F7F}\u{7528}\u{8BCA}\u{65AD}\u{548C}\u{6267}\u{884C}\u{5DE5}\u{5177}\u{FF09}
|
|
7451
|
+
|
|
7452
|
+
#### 3.1 \u{7C7B}\u{578B}\u{68C0}\u{67E5}
|
|
7453
|
+
**\u{5DE5}\u{5177}\u{FF1A}** getDiagnostics
|
|
7454
|
+
\`\`\`
|
|
7455
|
+
\u{64CD}\u{4F5C}\u{FF1A}
|
|
7456
|
+
- getDiagnostics(["src/services/[\u{529F}\u{80FD}\u{540D}]/index.ts", "src/services/index.ts"])
|
|
7457
|
+
- \u{68C0}\u{67E5}\u{5E76}\u{4FEE}\u{590D}\u{6240}\u{6709}\u{7C7B}\u{578B}\u{9519}\u{8BEF}
|
|
7458
|
+
\`\`\`
|
|
7459
|
+
|
|
7460
|
+
#### 3.2 \u{6784}\u{5EFA}\u{9A8C}\u{8BC1}
|
|
7461
|
+
**\u{5DE5}\u{5177}\u{FF1A}** executeBash
|
|
7462
|
+
\`\`\`
|
|
7463
|
+
\u{64CD}\u{4F5C}\u{FF1A}
|
|
7464
|
+
- executeBash("npm run build") \u{6267}\u{884C}\u{6784}\u{5EFA}
|
|
7465
|
+
- \u{68C0}\u{67E5}\u{6784}\u{5EFA}\u{8F93}\u{51FA}\u{FF0C}\u{786E}\u{4FDD}\u{65E0}\u{9519}\u{8BEF}
|
|
7466
|
+
\`\`\`
|
|
7467
|
+
|
|
7468
|
+
#### 3.3 \u{521B}\u{5EFA}\u{6D4B}\u{8BD5}\u{6587}\u{4EF6}
|
|
7469
|
+
**\u{5DE5}\u{5177}\u{FF1A}** fsWrite
|
|
7470
|
+
\`\`\`
|
|
7471
|
+
\u{64CD}\u{4F5C}\u{FF1A}
|
|
7472
|
+
- fsWrite("test/test-[\u{529F}\u{80FD}\u{540D}]-mcp-call.cjs", "\u{6D4B}\u{8BD5}\u{4EE3}\u{7801}")
|
|
7473
|
+
- \u{53C2}\u{8003}\u{73B0}\u{6709}\u{6D4B}\u{8BD5}\u{6587}\u{4EF6}\u{7684}\u{7ED3}\u{6784}\u{548C}\u{6A21}\u{5F0F}
|
|
7474
|
+
\`\`\`
|
|
7475
|
+
|
|
7476
|
+
#### 3.4 \u{6267}\u{884C}\u{529F}\u{80FD}\u{6D4B}\u{8BD5}
|
|
7477
|
+
**\u{5DE5}\u{5177}\u{FF1A}** executeBash
|
|
7478
|
+
\`\`\`
|
|
7479
|
+
\u{64CD}\u{4F5C}\u{FF1A}
|
|
7480
|
+
- executeBash("node test/test-[\u{529F}\u{80FD}\u{540D}]-mcp-call.cjs")
|
|
7481
|
+
- \u{9A8C}\u{8BC1}\u{6240}\u{6709}\u{529F}\u{80FD}\u{6B63}\u{5E38}\u{5DE5}\u{4F5C}
|
|
7482
|
+
- \u{5982}\u{6709}\u{9519}\u{8BEF}\u{FF0C}\u{4F7F}\u{7528} strReplace \u{4FEE}\u{590D}\u{4EE3}\u{7801}
|
|
7483
|
+
\`\`\`
|
|
7484
|
+
|
|
7485
|
+
---
|
|
7486
|
+
|
|
7487
|
+
### \u{9636}\u{6BB5}\u{56DB}\u{FF1A}\u{4F18}\u{5316}\u{5B8C}\u{5584}\u{FF08}\u{8FED}\u{4EE3}\u{6539}\u{8FDB}\u{FF09}
|
|
7488
|
+
|
|
7489
|
+
#### 4.1 \u{4EE3}\u{7801}\u{5BA1}\u{67E5}
|
|
7490
|
+
**\u{68C0}\u{67E5}\u{9879}\u{FF1A}**
|
|
7491
|
+
- [ ] \u{4EE3}\u{7801}\u{7B26}\u{5408}\u{9879}\u{76EE}\u{89C4}\u{8303}
|
|
7492
|
+
- [ ] \u{9519}\u{8BEF}\u{5904}\u{7406}\u{5B8C}\u{5584}
|
|
7493
|
+
- [ ] \u{7C7B}\u{578B}\u{5B9A}\u{4E49}\u{6E05}\u{6670}
|
|
7494
|
+
- [ ] \u{6CE8}\u{91CA}\u{6587}\u{6863}\u{5B8C}\u{6574}
|
|
7495
|
+
- [ ] \u{65E0}\u{5197}\u{4F59}\u{4EE3}\u{7801}
|
|
7496
|
+
|
|
7497
|
+
#### 4.2 \u{6027}\u{80FD}\u{4F18}\u{5316}
|
|
7498
|
+
**\u{8003}\u{8651}\u{70B9}\u{FF1A}**
|
|
7499
|
+
- \u{5F02}\u{6B65}\u{64CD}\u{4F5C}\u{662F}\u{5426}\u{5408}\u{7406}
|
|
7500
|
+
- \u{662F}\u{5426}\u{6709}\u{4E0D}\u{5FC5}\u{8981}\u{7684}\u{6587}\u{4EF6}\u{8BFB}\u{53D6}
|
|
7501
|
+
- \u{9519}\u{8BEF}\u{5904}\u{7406}\u{662F}\u{5426}\u{9AD8}\u{6548}
|
|
7502
|
+
|
|
7503
|
+
#### 4.3 \u{6700}\u{7EC8}\u{9A8C}\u{8BC1}
|
|
7504
|
+
**\u{5DE5}\u{5177}\u{FF1A}** getDiagnostics, executeBash
|
|
7505
|
+
\`\`\`
|
|
7506
|
+
\u{64CD}\u{4F5C}\u{FF1A}
|
|
7507
|
+
- \u{518D}\u{6B21}\u{8FD0}\u{884C} getDiagnostics \u{786E}\u{4FDD}\u{65E0}\u{8B66}\u{544A}
|
|
7508
|
+
- \u{518D}\u{6B21}\u{8FD0}\u{884C}\u{6D4B}\u{8BD5}\u{786E}\u{4FDD}\u{529F}\u{80FD}\u{5B8C}\u{6574}
|
|
7509
|
+
- \u{6267}\u{884C} npm run build \u{786E}\u{4FDD}\u{6784}\u{5EFA}\u{6210}\u{529F}
|
|
7510
|
+
\`\`\`
|
|
7511
|
+
|
|
7512
|
+
---
|
|
7513
|
+
|
|
7514
|
+
### \u{9636}\u{6BB5}\u{4E94}\u{FF1A}\u{751F}\u{6210}\u{603B}\u{7ED3}\u{62A5}\u{544A}
|
|
7515
|
+
|
|
7516
|
+
\u{5B8C}\u{6210}\u{6240}\u{6709}\u{4EFB}\u{52A1}\u{540E}\u{FF0C}\u{751F}\u{6210}\u{7B80}\u{6D01}\u{7684}\u{603B}\u{7ED3}\u{62A5}\u{544A}\u{FF1A}
|
|
7517
|
+
|
|
7518
|
+
\`\`\`markdown
|
|
7519
|
+
## \u{6267}\u{884C}\u{603B}\u{7ED3}
|
|
7520
|
+
|
|
7521
|
+
### \u{5B8C}\u{6210}\u{5185}\u{5BB9}
|
|
7522
|
+
- \u{521B}\u{5EFA}\u{7684}\u{6587}\u{4EF6}\u{5217}\u{8868}
|
|
7523
|
+
- \u{5B9E}\u{73B0}\u{7684}\u{6838}\u{5FC3}\u{529F}\u{80FD}
|
|
7524
|
+
- \u{96C6}\u{6210}\u{7684}\u{670D}\u{52A1}
|
|
7525
|
+
|
|
7526
|
+
### \u{6280}\u{672F}\u{8981}\u{70B9}
|
|
7527
|
+
- \u{4F7F}\u{7528}\u{7684}\u{5173}\u{952E}\u{6280}\u{672F}
|
|
7528
|
+
- \u{89E3}\u{51B3}\u{7684}\u{4E3B}\u{8981}\u{95EE}\u{9898}
|
|
7529
|
+
|
|
7530
|
+
### \u{9A8C}\u{8BC1}\u{7ED3}\u{679C}
|
|
7531
|
+
- \u{7C7B}\u{578B}\u{68C0}\u{67E5}\u{FF1A}\u{901A}\u{8FC7}/\u{5931}\u{8D25}
|
|
7532
|
+
- \u{6784}\u{5EFA}\u{6D4B}\u{8BD5}\u{FF1A}\u{901A}\u{8FC7}/\u{5931}\u{8D25}
|
|
7533
|
+
- \u{529F}\u{80FD}\u{6D4B}\u{8BD5}\u{FF1A}\u{901A}\u{8FC7}/\u{5931}\u{8D25}
|
|
7534
|
+
|
|
7535
|
+
### \u{540E}\u{7EED}\u{5EFA}\u{8BAE}
|
|
7536
|
+
- \u{53EF}\u{4F18}\u{5316}\u{7684}\u{70B9}
|
|
7537
|
+
- \u{53EF}\u{6269}\u{5C55}\u{7684}\u{65B9}\u{5411}
|
|
7538
|
+
\`\`\`
|
|
7539
|
+
|
|
7540
|
+
---
|
|
7541
|
+
|
|
7542
|
+
## \u{6267}\u{884C}\u{539F}\u{5219}
|
|
7543
|
+
|
|
7544
|
+
1. **\u{6E10}\u{8FDB}\u{5F0F}\u{5B9E}\u{73B0}**\u{FF1A}\u{5148}\u{5B9E}\u{73B0}\u{6838}\u{5FC3}\u{529F}\u{80FD}\u{FF0C}\u{518D}\u{5B8C}\u{5584}\u{7EC6}\u{8282}
|
|
7545
|
+
2. **\u{6301}\u{7EED}\u{9A8C}\u{8BC1}**\u{FF1A}\u{6BCF}\u{5B8C}\u{6210}\u{4E00}\u{4E2A}\u{6A21}\u{5757}\u{7ACB}\u{5373}\u{4F7F}\u{7528} getDiagnostics \u{68C0}\u{67E5}
|
|
7546
|
+
3. **\u{53C2}\u{8003}\u{73B0}\u{6709}\u{4EE3}\u{7801}**\u{FF1A}\u{4FDD}\u{6301}\u{4E0E}\u{9879}\u{76EE}\u{98CE}\u{683C}\u{4E00}\u{81F4}
|
|
7547
|
+
4. **\u{9519}\u{8BEF}\u{5904}\u{7406}\u{4F18}\u{5148}**\u{FF1A}\u{786E}\u{4FDD}\u{6240}\u{6709}\u{5F02}\u{5E38}\u{60C5}\u{51B5}\u{90FD}\u{6709}\u{5904}\u{7406}
|
|
7548
|
+
5. **\u{6D4B}\u{8BD5}\u{9A71}\u{52A8}**\u{FF1A}\u{8FB9}\u{5F00}\u{53D1}\u{8FB9}\u{6D4B}\u{8BD5}\u{FF0C}\u{53CA}\u{65F6}\u{53D1}\u{73B0}\u{95EE}\u{9898}
|
|
7549
|
+
|
|
7550
|
+
## \u{5DE5}\u{5177}\u{4F7F}\u{7528}\u{4F18}\u{5148}\u{7EA7}
|
|
7551
|
+
|
|
7552
|
+
1. **\u{5206}\u{6790}\u{9636}\u{6BB5}**\u{FF1A}listDirectory \u{2192} readFile \u{2192} grepSearch
|
|
7553
|
+
2. **\u{5B9E}\u{73B0}\u{9636}\u{6BB5}**\u{FF1A}fsWrite \u{2192} strReplace \u{2192} fsAppend
|
|
7554
|
+
3. **\u{9A8C}\u{8BC1}\u{9636}\u{6BB5}**\u{FF1A}getDiagnostics \u{2192} executeBash
|
|
7555
|
+
4. **\u{4FEE}\u{590D}\u{9636}\u{6BB5}**\u{FF1A}strReplace \u{2192} getDiagnostics\u{FF08}\u{5FAA}\u{73AF}\u{76F4}\u{5230}\u{65E0}\u{9519}\u{8BEF}\u{FF09}
|
|
7556
|
+
|
|
7557
|
+
---
|
|
7558
|
+
|
|
7559
|
+
**\u{73B0}\u{5728}\u{5F00}\u{59CB}\u{6267}\u{884C}\u{4EFB}\u{52A1}\u{FF0C}\u{6309}\u{7167}\u{4E0A}\u{8FF0}\u{6D41}\u{7A0B}\u{9010}\u{6B65}\u{5B8C}\u{6210}\u{5B9E}\u{65BD}\u{8BA1}\u{5212}\u{FF01}**
|
|
7560
|
+
`;
|
|
7561
|
+
return {
|
|
7562
|
+
content: [
|
|
7563
|
+
{
|
|
7564
|
+
type: "text",
|
|
7565
|
+
text: JSON.stringify({
|
|
7566
|
+
success: true,
|
|
7567
|
+
message: "\u4EFB\u52A1\u6267\u884C\u6307\u5BFC\u5DF2\u751F\u6210\uFF0CAI\u5C06\u6309\u7167\u6307\u5F15\u9010\u6B65\u5B8C\u6210\u5B9E\u65BD",
|
|
7568
|
+
data: {
|
|
7569
|
+
guidance: executionGuidance,
|
|
7570
|
+
implementation_plan,
|
|
7571
|
+
requirement_description,
|
|
7572
|
+
execution_phases: [
|
|
7573
|
+
"\u51C6\u5907\u5DE5\u4F5C - \u5206\u6790\u73B0\u6709\u4EE3\u7801",
|
|
7574
|
+
"\u4EE3\u7801\u5B9E\u73B0 - \u521B\u5EFA\u6587\u4EF6\u548C\u7F16\u5199\u4EE3\u7801",
|
|
7575
|
+
"\u9A8C\u8BC1\u6D4B\u8BD5 - \u7C7B\u578B\u68C0\u67E5\u548C\u529F\u80FD\u6D4B\u8BD5",
|
|
7576
|
+
"\u4F18\u5316\u5B8C\u5584 - \u4EE3\u7801\u5BA1\u67E5\u548C\u6027\u80FD\u4F18\u5316",
|
|
7577
|
+
"\u751F\u6210\u603B\u7ED3 - \u8F93\u51FA\u6267\u884C\u62A5\u544A"
|
|
7578
|
+
],
|
|
7579
|
+
recommended_tool_sequence: [
|
|
7580
|
+
"listDirectory \u2192 readFile \u2192 grepSearch (\u5206\u6790)",
|
|
7581
|
+
"fsWrite \u2192 strReplace (\u5B9E\u73B0)",
|
|
7582
|
+
"getDiagnostics \u2192 executeBash (\u9A8C\u8BC1)",
|
|
7583
|
+
"strReplace \u2192 getDiagnostics (\u4FEE\u590D)"
|
|
7584
|
+
]
|
|
7585
|
+
}
|
|
7586
|
+
}, null, 2)
|
|
7587
|
+
}
|
|
7588
|
+
]
|
|
7589
|
+
};
|
|
7590
|
+
} catch (error) {
|
|
7591
|
+
return {
|
|
7592
|
+
content: [
|
|
7593
|
+
{
|
|
7594
|
+
type: "text",
|
|
7595
|
+
text: JSON.stringify({
|
|
7596
|
+
success: false,
|
|
7597
|
+
message: `\u{4EFB}\u{52A1}\u{6267}\u{884C}\u{5931}\u{8D25}: ${error.message}`,
|
|
7598
|
+
data: null
|
|
7599
|
+
})
|
|
7600
|
+
}
|
|
7601
|
+
],
|
|
7602
|
+
isError: true
|
|
7603
|
+
};
|
|
7604
|
+
}
|
|
7605
|
+
}
|
|
7606
|
+
};
|
|
6963
7607
|
function createMcpServer() {
|
|
6964
7608
|
const server = new mcp_js_namespaceObject.McpServer({
|
|
6965
7609
|
name: SERVICE_CONFIG.name,
|
|
@@ -6968,12 +7612,16 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
|
|
|
6968
7612
|
const tools = [
|
|
6969
7613
|
word2mdTool,
|
|
6970
7614
|
pdf2mdTool,
|
|
7615
|
+
requirementAnalyzerTool,
|
|
6971
7616
|
changeSummarizer,
|
|
6972
7617
|
read_imageTool,
|
|
6973
7618
|
imageConverterTool,
|
|
6974
7619
|
imageRecognitionAgentTool,
|
|
6975
7620
|
readExcelTool,
|
|
6976
|
-
exportExcelTool
|
|
7621
|
+
exportExcelTool,
|
|
7622
|
+
requirementIdentifierTool,
|
|
7623
|
+
requirementAlignerTool,
|
|
7624
|
+
taskExecutorTool
|
|
6977
7625
|
];
|
|
6978
7626
|
tools.forEach((tool)=>{
|
|
6979
7627
|
server.tool(tool.name, tool.description, tool.inputSchema, tool.handler);
|
|
@@ -6982,7 +7630,7 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
|
|
|
6982
7630
|
}
|
|
6983
7631
|
const src_server = createMcpServer();
|
|
6984
7632
|
const transport = new stdio_js_namespaceObject.StdioServerTransport();
|
|
6985
|
-
|
|
7633
|
+
logger_logger.info("\u542F\u52A8\u667A\u80FD\u8F6F\u4EF6\u661F\u5DE5\u5382 MCP \u670D\u52A1\u5668 (stdio\u6A21\u5F0F)");
|
|
6986
7634
|
(async ()=>{
|
|
6987
7635
|
await src_server.connect(transport);
|
|
6988
7636
|
})();
|