intention-coding 0.4.0 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -3
- package/dist/db/file-storage.js +0 -638
- package/dist/index.js +0 -26
- package/dist/server/index.js +0 -88
- package/dist/services/bug-fix-agent/index.js +0 -320
- package/dist/services/change-summarizer/index.js +0 -123
- package/dist/services/change-summarizer/prompt/change-analysis.js +0 -56
- package/dist/services/code-generator/index.js +0 -403
- package/dist/services/code-generator/stages/execution-stage.js +0 -549
- package/dist/services/code-generator/stages/ideation-stage.js +0 -267
- package/dist/services/code-generator/stages/optimization-stage.js +0 -334
- package/dist/services/code-generator/stages/planning-stage.js +0 -295
- package/dist/services/code-generator/stages/research-stage.js +0 -283
- package/dist/services/code-generator/stages/review-stage.js +0 -270
- package/dist/services/code-generator/types.js +0 -37
- package/dist/services/code-generator/utils/instruction-executor.js +0 -207
- package/dist/services/code-generator/workflow-manager.js +0 -252
- package/dist/services/image-analysis/analyzer.js +0 -530
- package/dist/services/image-analysis/index.js +0 -406
- package/dist/services/image-analysis/types.js +0 -46
- package/dist/services/image-converter/converter.js +0 -310
- package/dist/services/image-converter/index.js +0 -262
- package/dist/services/image-converter/types.js +0 -31
- package/dist/services/integrated-generator/index.js +0 -1297
- package/dist/services/pdf2md/index.js +0 -180
- package/dist/services/project-template/index.js +0 -83
- package/dist/services/project-template/prompt/project-rules.js +0 -98
- package/dist/services/requirement-analyzer/chunk-reader.js +0 -218
- package/dist/services/requirement-analyzer/core/document-generator.js +0 -254
- package/dist/services/requirement-analyzer/core/intelligent-analyzer.js +0 -169
- package/dist/services/requirement-analyzer/core/project-analyzer.js +0 -199
- package/dist/services/requirement-analyzer/core/requirement-analyzer-service.js +0 -191
- package/dist/services/requirement-analyzer/core/template-selector.js +0 -124
- package/dist/services/requirement-analyzer/core/types.js +0 -23
- package/dist/services/requirement-analyzer/index.js +0 -177
- package/dist/services/requirement-analyzer/prompt/api-template.js +0 -302
- package/dist/services/requirement-analyzer/prompt/app-template.js +0 -455
- package/dist/services/requirement-analyzer/prompt/intelligent-requirement-analysis.js +0 -92
- package/dist/services/requirement-analyzer/prompt/pc-page-template.js +0 -582
- package/dist/services/requirement-analyzer/prompt/requirement-analysis.js +0 -664
- package/dist/services/requirement-analyzer/prompt/sdk-template.js +0 -582
- package/dist/services/requirement-analyzer/utils/file-reader.js +0 -169
- package/dist/services/world2md/index.js +0 -157
- package/dist/types/index.js +0 -2
- package/dist/utils/common.js +0 -72
- package/dist/utils/config.js +0 -163
- package/dist/utils/context-manager.js +0 -114
- package/dist/utils/dify.js +0 -243
- package/dist/utils/logger.js +0 -129
- package/dist/utils/openai.js +0 -225
- package/dist/utils/pack.js +0 -75
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.RequirementAnalyzerService = void 0;
|
|
46
|
-
const fs = __importStar(require("fs/promises"));
|
|
47
|
-
const logger_1 = require("../../../utils/logger");
|
|
48
|
-
const common_1 = require("../../../utils/common");
|
|
49
|
-
const file_reader_1 = require("../utils/file-reader");
|
|
50
|
-
const types_1 = require("./types");
|
|
51
|
-
const project_analyzer_1 = require("./project-analyzer");
|
|
52
|
-
const intelligent_analyzer_1 = require("./intelligent-analyzer");
|
|
53
|
-
const document_generator_1 = require("./document-generator");
|
|
54
|
-
/**
|
|
55
|
-
* 需求分析器服务
|
|
56
|
-
* 职责:协调各个组件完成需求分析流程
|
|
57
|
-
*/
|
|
58
|
-
class RequirementAnalyzerService {
|
|
59
|
-
constructor() {
|
|
60
|
-
this.projectAnalyzer = new project_analyzer_1.ProjectAnalyzer();
|
|
61
|
-
this.intelligentAnalyzer = new intelligent_analyzer_1.IntelligentAnalyzer();
|
|
62
|
-
this.documentGenerator = new document_generator_1.DocumentGenerator();
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* 执行需求分析
|
|
66
|
-
*/
|
|
67
|
-
analyzeRequirements(params) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
try {
|
|
70
|
-
logger_1.logger.info('开始需求分析流程', {
|
|
71
|
-
featureName: params.feature_name,
|
|
72
|
-
inputType: params.input_type
|
|
73
|
-
});
|
|
74
|
-
// 1. 验证和准备输入内容
|
|
75
|
-
const { inputContent, sourceInfo } = yield this.prepareInput(params);
|
|
76
|
-
// 2. 分析项目基本情况
|
|
77
|
-
const projectInfo = yield this.projectAnalyzer.analyzeProject();
|
|
78
|
-
// 3. 执行智能需求分析
|
|
79
|
-
const requirementAnalysis = yield this.intelligentAnalyzer.analyzeRequirements(inputContent, projectInfo, params.custom_prompt);
|
|
80
|
-
// 4. 处理不同类型的分析结果
|
|
81
|
-
if (this.isMultiFeatureAnalysis(requirementAnalysis)) {
|
|
82
|
-
return yield this.handleMultiFeatureAnalysis(requirementAnalysis, projectInfo, params, sourceInfo);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
return yield this.handleSingleFeatureAnalysis(requirementAnalysis, projectInfo, params, sourceInfo);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
if (error instanceof types_1.RequirementAnalysisError) {
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
logger_1.logger.error('需求分析流程失败', { error, params });
|
|
93
|
-
throw new types_1.RequirementAnalysisError('需求分析过程中发生未知错误,请检查输入参数和系统状态', types_1.ErrorCodes.REQUIREMENT_PARSING_FAILED, { params, originalError: error });
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 准备输入内容
|
|
99
|
-
*/
|
|
100
|
-
prepareInput(params) {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
let inputContent;
|
|
103
|
-
let sourceInfo;
|
|
104
|
-
try {
|
|
105
|
-
if (params.input_type === 'text') {
|
|
106
|
-
if (!params.content) {
|
|
107
|
-
throw new types_1.RequirementAnalysisError('文本输入模式下content参数不能为空', types_1.ErrorCodes.INVALID_INPUT);
|
|
108
|
-
}
|
|
109
|
-
inputContent = params.content;
|
|
110
|
-
sourceInfo = '用户直接输入';
|
|
111
|
-
}
|
|
112
|
-
else if (params.input_type === 'md_file') {
|
|
113
|
-
if (!params.md_file_path) {
|
|
114
|
-
throw new types_1.RequirementAnalysisError('MD文件模式下md_file_path参数不能为空', types_1.ErrorCodes.INVALID_INPUT);
|
|
115
|
-
}
|
|
116
|
-
const resolvedPath = yield (0, common_1.validateAndResolvePath)(params.md_file_path);
|
|
117
|
-
const stats = yield fs.stat(resolvedPath);
|
|
118
|
-
const fileSizeInMB = stats.size / (1024 * 1024);
|
|
119
|
-
logger_1.logger.info('读取MD文件', {
|
|
120
|
-
file: params.md_file_path,
|
|
121
|
-
size: `${fileSizeInMB.toFixed(2)} MB`,
|
|
122
|
-
useStreaming: params.use_streaming
|
|
123
|
-
});
|
|
124
|
-
// 根据文件大小选择读取方式
|
|
125
|
-
if (fileSizeInMB > 1 || params.use_streaming) {
|
|
126
|
-
const chunkSize = params.chunk_size || 100;
|
|
127
|
-
inputContent = yield (0, file_reader_1.readLargeFileContent)(resolvedPath, chunkSize);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
inputContent = yield fs.readFile(resolvedPath, 'utf8');
|
|
131
|
-
}
|
|
132
|
-
sourceInfo = `MD文件: ${params.md_file_path}`;
|
|
133
|
-
logger_1.logger.info('MD文件读取成功', {
|
|
134
|
-
file: params.md_file_path,
|
|
135
|
-
contentLength: inputContent.length
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
throw new types_1.RequirementAnalysisError(`不支持的输入类型: ${params.input_type}`, types_1.ErrorCodes.INVALID_INPUT);
|
|
140
|
-
}
|
|
141
|
-
// 验证内容长度
|
|
142
|
-
if (!inputContent || inputContent.trim().length < 10) {
|
|
143
|
-
throw new types_1.RequirementAnalysisError('输入内容过短,请提供更详细的需求描述', types_1.ErrorCodes.INVALID_INPUT);
|
|
144
|
-
}
|
|
145
|
-
return { inputContent, sourceInfo };
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
if (error instanceof types_1.RequirementAnalysisError) {
|
|
149
|
-
throw error;
|
|
150
|
-
}
|
|
151
|
-
logger_1.logger.error('输入内容准备失败', { error, params });
|
|
152
|
-
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
153
|
-
throw new types_1.RequirementAnalysisError(`指定的文件不存在: ${params.md_file_path}`, types_1.ErrorCodes.FILE_NOT_FOUND, { filePath: params.md_file_path });
|
|
154
|
-
}
|
|
155
|
-
throw new types_1.RequirementAnalysisError('读取输入内容时发生错误,请检查文件路径和权限', types_1.ErrorCodes.INVALID_INPUT, { originalError: error });
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* 判断是否为多功能点分析
|
|
161
|
-
*/
|
|
162
|
-
isMultiFeatureAnalysis(analysis) {
|
|
163
|
-
return analysis.analysisType === 'multi_specific_features' ||
|
|
164
|
-
analysis.requirements.length > 1;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* 处理多功能点分析
|
|
168
|
-
*/
|
|
169
|
-
handleMultiFeatureAnalysis(analysis, projectInfo, params, sourceInfo) {
|
|
170
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
-
logger_1.logger.info('执行多功能点统一分析', {
|
|
172
|
-
featureName: params.feature_name,
|
|
173
|
-
requirementCount: analysis.requirements.length
|
|
174
|
-
});
|
|
175
|
-
return yield this.documentGenerator.generateUnifiedDocument(analysis, projectInfo, params.feature_name, sourceInfo, params.custom_prompt);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* 处理单功能点分析
|
|
180
|
-
*/
|
|
181
|
-
handleSingleFeatureAnalysis(analysis, projectInfo, params, sourceInfo) {
|
|
182
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
-
logger_1.logger.info('执行单功能点分析', {
|
|
184
|
-
featureName: params.feature_name,
|
|
185
|
-
requirementType: analysis.requirementType
|
|
186
|
-
});
|
|
187
|
-
return yield this.documentGenerator.generateUnifiedDocument(analysis, projectInfo, params.feature_name, sourceInfo, params.custom_prompt);
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
exports.RequirementAnalyzerService = RequirementAnalyzerService;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TemplateSelector = void 0;
|
|
4
|
-
const logger_1 = require("../../../utils/logger");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
|
-
// 导入所有模板
|
|
7
|
-
const requirement_analysis_1 = require("../prompt/requirement-analysis");
|
|
8
|
-
const pc_page_template_1 = require("../prompt/pc-page-template");
|
|
9
|
-
const app_template_1 = require("../prompt/app-template");
|
|
10
|
-
const sdk_template_1 = require("../prompt/sdk-template");
|
|
11
|
-
const api_template_1 = require("../prompt/api-template");
|
|
12
|
-
/**
|
|
13
|
-
* 模板选择器
|
|
14
|
-
* 职责:根据需求类型选择合适的技术模板
|
|
15
|
-
*/
|
|
16
|
-
class TemplateSelector {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.templateMap = new Map([
|
|
19
|
-
['PC页面', pc_page_template_1.pcPageTemplatePrompt],
|
|
20
|
-
['APP', app_template_1.appTemplatePrompt],
|
|
21
|
-
['SDK集成', sdk_template_1.sdkTemplatePrompt],
|
|
22
|
-
['接口', api_template_1.apiTemplatePrompt],
|
|
23
|
-
['api', api_template_1.apiTemplatePrompt],
|
|
24
|
-
['pc', pc_page_template_1.pcPageTemplatePrompt],
|
|
25
|
-
['app', app_template_1.appTemplatePrompt],
|
|
26
|
-
['sdk', sdk_template_1.sdkTemplatePrompt]
|
|
27
|
-
]);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 根据需求类型选择模板
|
|
31
|
-
*/
|
|
32
|
-
selectTemplate(requirementType) {
|
|
33
|
-
logger_1.logger.info('开始选择技术模板', { requirementType });
|
|
34
|
-
// 精确匹配
|
|
35
|
-
if (this.templateMap.has(requirementType)) {
|
|
36
|
-
const template = this.templateMap.get(requirementType);
|
|
37
|
-
logger_1.logger.info('精确匹配模板成功', { requirementType });
|
|
38
|
-
return template;
|
|
39
|
-
}
|
|
40
|
-
// 模糊匹配
|
|
41
|
-
const fuzzyMatch = this.fuzzyMatchTemplate(requirementType);
|
|
42
|
-
if (fuzzyMatch) {
|
|
43
|
-
logger_1.logger.info('模糊匹配模板成功', {
|
|
44
|
-
requirementType,
|
|
45
|
-
matchedTemplate: fuzzyMatch.type
|
|
46
|
-
});
|
|
47
|
-
return fuzzyMatch.template;
|
|
48
|
-
}
|
|
49
|
-
// 如果都没有匹配,根据需求类型特征进行智能选择
|
|
50
|
-
const intelligentMatch = this.intelligentMatchTemplate(requirementType);
|
|
51
|
-
if (intelligentMatch) {
|
|
52
|
-
logger_1.logger.info('智能匹配模板成功', {
|
|
53
|
-
requirementType,
|
|
54
|
-
matchedTemplate: intelligentMatch.type
|
|
55
|
-
});
|
|
56
|
-
return intelligentMatch.template;
|
|
57
|
-
}
|
|
58
|
-
// 最后使用默认模板
|
|
59
|
-
logger_1.logger.warn('使用默认模板', { requirementType });
|
|
60
|
-
return requirement_analysis_1.requirementAnalysisPrompt;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* 模糊匹配模板
|
|
64
|
-
*/
|
|
65
|
-
fuzzyMatchTemplate(requirementType) {
|
|
66
|
-
const lowerType = requirementType.toLowerCase();
|
|
67
|
-
// PC页面相关关键词
|
|
68
|
-
if (this.containsAny(lowerType, ['页面', 'pc', 'web', '界面', 'ui', '网页', '浏览器', '前端'])) {
|
|
69
|
-
return { type: 'PC页面', template: pc_page_template_1.pcPageTemplatePrompt };
|
|
70
|
-
}
|
|
71
|
-
// APP相关关键词
|
|
72
|
-
if (this.containsAny(lowerType, ['app', '移动', 'ios', 'android', '小程序', '移动端'])) {
|
|
73
|
-
return { type: 'APP', template: app_template_1.appTemplatePrompt };
|
|
74
|
-
}
|
|
75
|
-
// SDK集成相关关键词
|
|
76
|
-
if (this.containsAny(lowerType, ['sdk', '第三方', '集成', '对接', '支付', '地图', '推送'])) {
|
|
77
|
-
return { type: 'SDK集成', template: sdk_template_1.sdkTemplatePrompt };
|
|
78
|
-
}
|
|
79
|
-
// 接口相关关键词
|
|
80
|
-
if (this.containsAny(lowerType, ['接口', 'api', 'rest', 'graphql', '微服务', '后端', '服务端'])) {
|
|
81
|
-
return { type: '接口', template: api_template_1.apiTemplatePrompt };
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* 智能匹配模板(基于需求内容特征)
|
|
87
|
-
*/
|
|
88
|
-
intelligentMatchTemplate(requirementType) {
|
|
89
|
-
// 如果包含系统、平台等关键词,可能是综合性需求,使用默认模板
|
|
90
|
-
if (this.containsAny(requirementType.toLowerCase(), ['系统', '平台', '架构', '综合'])) {
|
|
91
|
-
return { type: '系统', template: requirement_analysis_1.requirementAnalysisPrompt };
|
|
92
|
-
}
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* 检查字符串是否包含任意一个关键词
|
|
97
|
-
*/
|
|
98
|
-
containsAny(text, keywords) {
|
|
99
|
-
return keywords.some(keyword => text.includes(keyword));
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 验证模板选择结果
|
|
103
|
-
*/
|
|
104
|
-
validateTemplate(template, requirementType) {
|
|
105
|
-
if (!template || template.trim().length === 0) {
|
|
106
|
-
throw new types_1.RequirementAnalysisError(`无法为需求类型 "${requirementType}" 选择合适的模板`, types_1.ErrorCodes.TEMPLATE_SELECTION_FAILED, { requirementType });
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* 获取支持的需求类型列表
|
|
111
|
-
*/
|
|
112
|
-
getSupportedTypes() {
|
|
113
|
-
return Array.from(this.templateMap.keys());
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* 检查需求类型是否受支持
|
|
117
|
-
*/
|
|
118
|
-
isTypeSupported(requirementType) {
|
|
119
|
-
return this.templateMap.has(requirementType) ||
|
|
120
|
-
this.fuzzyMatchTemplate(requirementType) !== null ||
|
|
121
|
-
this.intelligentMatchTemplate(requirementType) !== null;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
exports.TemplateSelector = TemplateSelector;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ErrorCodes = exports.RequirementAnalysisError = void 0;
|
|
4
|
-
// 异常类型定义
|
|
5
|
-
class RequirementAnalysisError extends Error {
|
|
6
|
-
constructor(message, code, context) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.code = code;
|
|
9
|
-
this.context = context;
|
|
10
|
-
this.name = 'RequirementAnalysisError';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.RequirementAnalysisError = RequirementAnalysisError;
|
|
14
|
-
var ErrorCodes;
|
|
15
|
-
(function (ErrorCodes) {
|
|
16
|
-
ErrorCodes["INVALID_INPUT"] = "INVALID_INPUT";
|
|
17
|
-
ErrorCodes["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
|
|
18
|
-
ErrorCodes["PROJECT_ANALYSIS_FAILED"] = "PROJECT_ANALYSIS_FAILED";
|
|
19
|
-
ErrorCodes["REQUIREMENT_PARSING_FAILED"] = "REQUIREMENT_PARSING_FAILED";
|
|
20
|
-
ErrorCodes["TEMPLATE_SELECTION_FAILED"] = "TEMPLATE_SELECTION_FAILED";
|
|
21
|
-
ErrorCodes["DOCUMENT_GENERATION_FAILED"] = "DOCUMENT_GENERATION_FAILED";
|
|
22
|
-
ErrorCodes["UNSUPPORTED_REQUIREMENT_TYPE"] = "UNSUPPORTED_REQUIREMENT_TYPE";
|
|
23
|
-
})(ErrorCodes || (exports.ErrorCodes = ErrorCodes = {}));
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ErrorCodes = exports.RequirementAnalysisError = exports.RequirementAnalyzerService = exports.requirementAnalyzerTool = void 0;
|
|
13
|
-
const zod_1 = require("zod");
|
|
14
|
-
const logger_1 = require("../../utils/logger");
|
|
15
|
-
const requirement_analyzer_service_1 = require("./core/requirement-analyzer-service");
|
|
16
|
-
const types_1 = require("./core/types");
|
|
17
|
-
// 参数验证Schema
|
|
18
|
-
const RequirementAnalyzerParamsSchema = zod_1.z
|
|
19
|
-
.object({
|
|
20
|
-
input_type: zod_1.z
|
|
21
|
-
.enum(["text", "md_file"])
|
|
22
|
-
.describe("输入类型:直接文本输入或引用已生成的MD文件"),
|
|
23
|
-
content: zod_1.z
|
|
24
|
-
.string()
|
|
25
|
-
.optional()
|
|
26
|
-
.describe("当input_type为text时,直接输入的需求内容"),
|
|
27
|
-
md_file_path: zod_1.z
|
|
28
|
-
.string()
|
|
29
|
-
.optional()
|
|
30
|
-
.describe("当input_type为md_file时,要分析的MD文件路径"),
|
|
31
|
-
feature_name: zod_1.z.string().describe("功能名称,用于生成输出文件名"),
|
|
32
|
-
custom_prompt: zod_1.z
|
|
33
|
-
.string()
|
|
34
|
-
.optional()
|
|
35
|
-
.describe("自定义提示词,用于指导AI生成特定风格的需求文档"),
|
|
36
|
-
analysis_depth: zod_1.z
|
|
37
|
-
.enum(["basic", "detailed", "comprehensive"])
|
|
38
|
-
.default("detailed")
|
|
39
|
-
.describe("分析深度:基础、详细、综合"),
|
|
40
|
-
use_streaming: zod_1.z
|
|
41
|
-
.boolean()
|
|
42
|
-
.default(false)
|
|
43
|
-
.describe("是否使用流式处理(适用于大文件)"),
|
|
44
|
-
chunk_size: zod_1.z
|
|
45
|
-
.number()
|
|
46
|
-
.min(10)
|
|
47
|
-
.max(1000)
|
|
48
|
-
.default(100)
|
|
49
|
-
.describe("分块大小(仅在use_streaming为true时有效)"),
|
|
50
|
-
})
|
|
51
|
-
.refine((data) => {
|
|
52
|
-
if (data.input_type === "text") {
|
|
53
|
-
return data.content && data.content.trim().length > 0;
|
|
54
|
-
}
|
|
55
|
-
if (data.input_type === "md_file") {
|
|
56
|
-
return data.md_file_path && data.md_file_path.trim().length > 0;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
}, {
|
|
60
|
-
message: "当input_type为text时content必填,当input_type为md_file时md_file_path必填",
|
|
61
|
-
});
|
|
62
|
-
/**
|
|
63
|
-
* 需求分析智能体工具
|
|
64
|
-
*/
|
|
65
|
-
exports.requirementAnalyzerTool = {
|
|
66
|
-
name: "需求分析智能体",
|
|
67
|
-
description: "智能分析需求并生成统一的技术文档,支持项目情况感知和精确模板匹配",
|
|
68
|
-
parameters: RequirementAnalyzerParamsSchema,
|
|
69
|
-
execute: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
-
try {
|
|
71
|
-
logger_1.logger.info("开始执行需求分析", {
|
|
72
|
-
featureName: args.feature_name,
|
|
73
|
-
inputType: args.input_type,
|
|
74
|
-
});
|
|
75
|
-
// 转换参数格式
|
|
76
|
-
const analysisParams = {
|
|
77
|
-
input_type: args.input_type,
|
|
78
|
-
content: args.content,
|
|
79
|
-
md_file_path: args.md_file_path,
|
|
80
|
-
feature_name: args.feature_name,
|
|
81
|
-
custom_prompt: args.custom_prompt,
|
|
82
|
-
analysis_depth: args.analysis_depth,
|
|
83
|
-
use_streaming: args.use_streaming,
|
|
84
|
-
chunk_size: args.chunk_size,
|
|
85
|
-
};
|
|
86
|
-
// 创建服务实例并执行分析
|
|
87
|
-
const analyzerService = new requirement_analyzer_service_1.RequirementAnalyzerService();
|
|
88
|
-
const result = yield analyzerService.analyzeRequirements(analysisParams);
|
|
89
|
-
logger_1.logger.info("需求分析执行完成", {
|
|
90
|
-
success: result.success,
|
|
91
|
-
outputPath: result.outputPath,
|
|
92
|
-
featureCount: result.analysisInfo.featureCount,
|
|
93
|
-
});
|
|
94
|
-
return result.message;
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
// 统一的错误处理
|
|
98
|
-
if (error instanceof types_1.RequirementAnalysisError) {
|
|
99
|
-
logger_1.logger.error("需求分析业务错误", {
|
|
100
|
-
code: error.code,
|
|
101
|
-
message: error.message,
|
|
102
|
-
context: error.context,
|
|
103
|
-
});
|
|
104
|
-
return JSON.stringify(error);
|
|
105
|
-
}
|
|
106
|
-
// 未知错误
|
|
107
|
-
logger_1.logger.error("需求分析未知错误", { error });
|
|
108
|
-
return `
|
|
109
|
-
# ❌ 需求分析失败
|
|
110
|
-
|
|
111
|
-
## 错误信息
|
|
112
|
-
系统发生未知错误,请稍后重试或联系技术支持。
|
|
113
|
-
|
|
114
|
-
## 错误详情
|
|
115
|
-
- **错误类型**: 系统异常
|
|
116
|
-
- **时间**: ${new Date().toISOString()}
|
|
117
|
-
- **建议**: 请检查输入参数是否正确,或稍后重试
|
|
118
|
-
|
|
119
|
-
如果问题持续存在,请联系技术支持团队。
|
|
120
|
-
`.trim();
|
|
121
|
-
}
|
|
122
|
-
}),
|
|
123
|
-
/**
|
|
124
|
-
* 格式化错误消息
|
|
125
|
-
*/
|
|
126
|
-
formatErrorMessage(error) {
|
|
127
|
-
const errorMessages = {
|
|
128
|
-
[types_1.ErrorCodes.INVALID_INPUT]: "输入参数错误",
|
|
129
|
-
[types_1.ErrorCodes.FILE_NOT_FOUND]: "文件未找到",
|
|
130
|
-
[types_1.ErrorCodes.PROJECT_ANALYSIS_FAILED]: "项目分析失败",
|
|
131
|
-
[types_1.ErrorCodes.REQUIREMENT_PARSING_FAILED]: "需求解析失败",
|
|
132
|
-
[types_1.ErrorCodes.TEMPLATE_SELECTION_FAILED]: "模板选择失败",
|
|
133
|
-
[types_1.ErrorCodes.DOCUMENT_GENERATION_FAILED]: "文档生成失败",
|
|
134
|
-
[types_1.ErrorCodes.UNSUPPORTED_REQUIREMENT_TYPE]: "不支持的需求类型",
|
|
135
|
-
};
|
|
136
|
-
const errorTitle = errorMessages[error.code] || "未知错误";
|
|
137
|
-
return `
|
|
138
|
-
# ❌ ${errorTitle}
|
|
139
|
-
|
|
140
|
-
## 错误信息
|
|
141
|
-
${error.message}
|
|
142
|
-
|
|
143
|
-
## 错误代码
|
|
144
|
-
${error.code}
|
|
145
|
-
|
|
146
|
-
## 解决建议
|
|
147
|
-
${this.getErrorSuggestion(error.code)}
|
|
148
|
-
|
|
149
|
-
## 错误详情
|
|
150
|
-
- **时间**: ${new Date().toISOString()}
|
|
151
|
-
- **上下文**: ${error.context ? JSON.stringify(error.context, null, 2) : "无"}
|
|
152
|
-
|
|
153
|
-
请根据上述信息调整输入参数后重试。
|
|
154
|
-
`.trim();
|
|
155
|
-
},
|
|
156
|
-
/**
|
|
157
|
-
* 获取错误解决建议
|
|
158
|
-
*/
|
|
159
|
-
getErrorSuggestion(errorCode) {
|
|
160
|
-
const suggestions = {
|
|
161
|
-
[types_1.ErrorCodes.INVALID_INPUT]: "请检查输入参数是否完整和正确",
|
|
162
|
-
[types_1.ErrorCodes.FILE_NOT_FOUND]: "请确认文件路径是否正确,文件是否存在",
|
|
163
|
-
[types_1.ErrorCodes.PROJECT_ANALYSIS_FAILED]: "请检查项目结构是否完整,或手动指定项目信息",
|
|
164
|
-
[types_1.ErrorCodes.REQUIREMENT_PARSING_FAILED]: "请简化需求描述,确保内容清晰明确",
|
|
165
|
-
[types_1.ErrorCodes.TEMPLATE_SELECTION_FAILED]: "请明确指定需求类型(接口、PC页面、APP、SDK集成)",
|
|
166
|
-
[types_1.ErrorCodes.DOCUMENT_GENERATION_FAILED]: "请检查需求内容是否完整,或尝试使用自定义prompt",
|
|
167
|
-
[types_1.ErrorCodes.UNSUPPORTED_REQUIREMENT_TYPE]: "当前支持的类型:接口、PC页面、APP、SDK集成",
|
|
168
|
-
};
|
|
169
|
-
return (suggestions[errorCode] || "请检查输入参数并重试,如问题持续请联系技术支持");
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
// 导出主要类型和服务
|
|
173
|
-
var requirement_analyzer_service_2 = require("./core/requirement-analyzer-service");
|
|
174
|
-
Object.defineProperty(exports, "RequirementAnalyzerService", { enumerable: true, get: function () { return requirement_analyzer_service_2.RequirementAnalyzerService; } });
|
|
175
|
-
var types_2 = require("./core/types");
|
|
176
|
-
Object.defineProperty(exports, "RequirementAnalysisError", { enumerable: true, get: function () { return types_2.RequirementAnalysisError; } });
|
|
177
|
-
Object.defineProperty(exports, "ErrorCodes", { enumerable: true, get: function () { return types_2.ErrorCodes; } });
|