intention-coding 0.3.8 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- 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,406 +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.DetailLevel = exports.AnalysisType = exports.AnalysisErrorCodes = exports.ImageAnalysisError = exports.ImageAnalyzer = exports.imageAnalysisTool = void 0;
|
|
13
|
-
const zod_1 = require("zod");
|
|
14
|
-
const logger_1 = require("../../utils/logger");
|
|
15
|
-
const analyzer_1 = require("./analyzer");
|
|
16
|
-
const types_1 = require("./types");
|
|
17
|
-
// 参数验证Schema
|
|
18
|
-
const ImageAnalysisParamsSchema = zod_1.z
|
|
19
|
-
.object({
|
|
20
|
-
image_path: zod_1.z.string().min(1).describe("图片文件路径"),
|
|
21
|
-
analysis_type: zod_1.z
|
|
22
|
-
.enum([
|
|
23
|
-
"general",
|
|
24
|
-
"objects",
|
|
25
|
-
"text",
|
|
26
|
-
"scene",
|
|
27
|
-
"people",
|
|
28
|
-
"technical",
|
|
29
|
-
"ui_design",
|
|
30
|
-
"requirement",
|
|
31
|
-
"custom",
|
|
32
|
-
])
|
|
33
|
-
.describe("分析类型:通用、物体识别、文字识别、场景分析、人物分析、技术分析、UI设计稿、需求识别、自定义"),
|
|
34
|
-
custom_prompt: zod_1.z
|
|
35
|
-
.string()
|
|
36
|
-
.optional()
|
|
37
|
-
.describe("自定义分析提示词(analysis_type为custom时必填)"),
|
|
38
|
-
detail_level: zod_1.z
|
|
39
|
-
.enum(["brief", "detailed", "comprehensive"])
|
|
40
|
-
.default("detailed")
|
|
41
|
-
.describe("详细程度:简要、详细、全面"),
|
|
42
|
-
language: zod_1.z.string().default("中文").describe("分析结果语言"),
|
|
43
|
-
})
|
|
44
|
-
.refine((data) => {
|
|
45
|
-
if (data.analysis_type === "custom") {
|
|
46
|
-
return data.custom_prompt && data.custom_prompt.trim().length > 0;
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
}, {
|
|
50
|
-
message: "自定义分析类型需要提供custom_prompt参数",
|
|
51
|
-
});
|
|
52
|
-
/**
|
|
53
|
-
* 图片内容理解智能体
|
|
54
|
-
* 提供多种类型的图片内容分析和理解
|
|
55
|
-
*/
|
|
56
|
-
exports.imageAnalysisTool = {
|
|
57
|
-
name: "图片内容理解智能体",
|
|
58
|
-
description: "专业图片内容分析工具,支持通用分析、物体识别、文字识别、场景分析、人物分析、技术分析、UI设计稿分析、需求识别等多种模式,特别擅长UI设计稿的结构分析和页面需求提取",
|
|
59
|
-
parameters: ImageAnalysisParamsSchema,
|
|
60
|
-
execute: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
-
const analyzer = new analyzer_1.ImageAnalyzer();
|
|
62
|
-
try {
|
|
63
|
-
logger_1.logger.info("图片内容理解智能体开始执行", {
|
|
64
|
-
imagePath: args.image_path,
|
|
65
|
-
analysisType: args.analysis_type,
|
|
66
|
-
detailLevel: args.detail_level,
|
|
67
|
-
});
|
|
68
|
-
// 转换参数格式
|
|
69
|
-
const analysisParams = {
|
|
70
|
-
image_path: args.image_path,
|
|
71
|
-
analysis_type: args.analysis_type,
|
|
72
|
-
custom_prompt: args.custom_prompt,
|
|
73
|
-
detail_level: args.detail_level,
|
|
74
|
-
language: args.language,
|
|
75
|
-
};
|
|
76
|
-
// 执行分析
|
|
77
|
-
const result = yield analyzer.analyzeImage(analysisParams);
|
|
78
|
-
// 格式化返回结果
|
|
79
|
-
return formatAnalysisResult(result, args);
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
logger_1.logger.error("图片内容理解智能体执行失败", { error, args });
|
|
83
|
-
if (error instanceof types_1.ImageAnalysisError) {
|
|
84
|
-
return formatErrorResponse(error);
|
|
85
|
-
}
|
|
86
|
-
return formatUnknownErrorResponse(error);
|
|
87
|
-
}
|
|
88
|
-
}),
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* 格式化分析结果
|
|
92
|
-
*/
|
|
93
|
-
function formatAnalysisResult(result, args) {
|
|
94
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
95
|
-
const { basic_info, content, processing_time_ms, confidence_score } = result;
|
|
96
|
-
return `
|
|
97
|
-
# 🔍 图片内容理解分析报告
|
|
98
|
-
|
|
99
|
-
## 📊 基本信息
|
|
100
|
-
- **图片路径**: \`${basic_info.path}\`
|
|
101
|
-
- **图片格式**: ${basic_info.format.toUpperCase()}
|
|
102
|
-
- **图片尺寸**: ${basic_info.dimensions.width} × ${basic_info.dimensions.height}
|
|
103
|
-
- **文件大小**: ${formatFileSize(basic_info.file_size)}
|
|
104
|
-
- **颜色空间**: ${basic_info.color_space || "未知"}
|
|
105
|
-
- **透明通道**: ${basic_info.has_alpha ? "是" : "否"}
|
|
106
|
-
|
|
107
|
-
## 🎯 分析配置
|
|
108
|
-
- **分析类型**: ${getAnalysisTypeLabel(args.analysis_type)}
|
|
109
|
-
- **详细程度**: ${getDetailLevelLabel(args.detail_level)}
|
|
110
|
-
- **分析语言**: ${args.language}
|
|
111
|
-
- **处理时间**: ${processing_time_ms}ms
|
|
112
|
-
- **置信度**: ${confidence_score ? (confidence_score * 100).toFixed(1) + "%" : "未知"}
|
|
113
|
-
|
|
114
|
-
## 📝 分析结果
|
|
115
|
-
|
|
116
|
-
### 内容概述
|
|
117
|
-
${content.summary}
|
|
118
|
-
|
|
119
|
-
${content.tags && content.tags.length > 0
|
|
120
|
-
? `
|
|
121
|
-
### 🏷️ 关键标签
|
|
122
|
-
${content.tags.map((tag) => `\`${tag}\``).join(" ")}
|
|
123
|
-
`
|
|
124
|
-
: ""}
|
|
125
|
-
|
|
126
|
-
${content.objects && content.objects.length > 0
|
|
127
|
-
? `
|
|
128
|
-
### 🎯 识别物体
|
|
129
|
-
${content.objects
|
|
130
|
-
.map((obj, index) => `
|
|
131
|
-
${index + 1}. **${obj.name}** (置信度: ${(obj.confidence * 100).toFixed(1)}%)
|
|
132
|
-
${obj.attributes
|
|
133
|
-
? Object.entries(obj.attributes)
|
|
134
|
-
.map(([key, value]) => `- ${key}: ${value}`)
|
|
135
|
-
.join("\n ")
|
|
136
|
-
: ""}
|
|
137
|
-
`)
|
|
138
|
-
.join("")}
|
|
139
|
-
`
|
|
140
|
-
: ""}
|
|
141
|
-
|
|
142
|
-
${content.text_content && content.text_content.length > 0
|
|
143
|
-
? `
|
|
144
|
-
### 📄 文字内容
|
|
145
|
-
${content.text_content
|
|
146
|
-
.map((text, index) => `
|
|
147
|
-
${index + 1}. "${text.text}" (置信度: ${(text.confidence * 100).toFixed(1)}%)
|
|
148
|
-
${text.language ? `- 语言: ${text.language}` : ""}
|
|
149
|
-
`)
|
|
150
|
-
.join("")}
|
|
151
|
-
`
|
|
152
|
-
: ""}
|
|
153
|
-
|
|
154
|
-
${content.scene_info
|
|
155
|
-
? `
|
|
156
|
-
### 🌍 场景信息
|
|
157
|
-
- **地点类型**: ${content.scene_info.location_type || "未识别"}
|
|
158
|
-
- **环境**: ${content.scene_info.environment || "未识别"}
|
|
159
|
-
- **光照**: ${content.scene_info.lighting || "未识别"}
|
|
160
|
-
${content.scene_info.weather ? `- **天气**: ${content.scene_info.weather}` : ""}
|
|
161
|
-
${content.scene_info.time_of_day
|
|
162
|
-
? `- **时间**: ${content.scene_info.time_of_day}`
|
|
163
|
-
: ""}
|
|
164
|
-
${content.scene_info.mood ? `- **氛围**: ${content.scene_info.mood}` : ""}
|
|
165
|
-
`
|
|
166
|
-
: ""}
|
|
167
|
-
|
|
168
|
-
${content.people_info && content.people_info.length > 0
|
|
169
|
-
? `
|
|
170
|
-
### 👥 人物信息
|
|
171
|
-
${content.people_info
|
|
172
|
-
.map((person, index) => `
|
|
173
|
-
${index + 1}. **人物${index + 1}**
|
|
174
|
-
- 数量: ${person.count}
|
|
175
|
-
${person.age_range ? `- 年龄: ${person.age_range}` : ""}
|
|
176
|
-
${person.gender ? `- 性别: ${person.gender}` : ""}
|
|
177
|
-
${person.emotions ? `- 情绪: ${person.emotions.join(", ")}` : ""}
|
|
178
|
-
${person.activities ? `- 活动: ${person.activities.join(", ")}` : ""}
|
|
179
|
-
${person.clothing ? `- 服装: ${person.clothing.join(", ")}` : ""}
|
|
180
|
-
`)
|
|
181
|
-
.join("")}
|
|
182
|
-
`
|
|
183
|
-
: ""}
|
|
184
|
-
|
|
185
|
-
${content.technical_info
|
|
186
|
-
? `
|
|
187
|
-
### 🔧 技术分析
|
|
188
|
-
#### 色彩分析
|
|
189
|
-
- **主色调**: ${((_b = (_a = content.technical_info.color_analysis) === null || _a === void 0 ? void 0 : _a.dominant_colors) === null || _b === void 0 ? void 0 : _b.join(", ")) ||
|
|
190
|
-
"未分析"}
|
|
191
|
-
- **色彩搭配**: ${((_d = (_c = content.technical_info.color_analysis) === null || _c === void 0 ? void 0 : _c.color_palette) === null || _d === void 0 ? void 0 : _d.join(", ")) ||
|
|
192
|
-
"未分析"}
|
|
193
|
-
- **亮度**: ${((_e = content.technical_info.color_analysis) === null || _e === void 0 ? void 0 : _e.brightness) || "未分析"}
|
|
194
|
-
- **对比度**: ${((_f = content.technical_info.color_analysis) === null || _f === void 0 ? void 0 : _f.contrast) || "未分析"}
|
|
195
|
-
|
|
196
|
-
#### 构图分析
|
|
197
|
-
- **三分法则**: ${((_g = content.technical_info.composition) === null || _g === void 0 ? void 0 : _g.rule_of_thirds) ? "符合" : "不符合"}
|
|
198
|
-
- **对称性**: ${((_h = content.technical_info.composition) === null || _h === void 0 ? void 0 : _h.symmetry) ? "对称" : "非对称"}
|
|
199
|
-
- **引导线**: ${((_j = content.technical_info.composition) === null || _j === void 0 ? void 0 : _j.leading_lines) ? "存在" : "不存在"}
|
|
200
|
-
|
|
201
|
-
#### 质量评估
|
|
202
|
-
- **清晰度**: ${((_k = content.technical_info.quality_metrics) === null || _k === void 0 ? void 0 : _k.sharpness) || "未评估"}
|
|
203
|
-
- **噪点水平**: ${((_l = content.technical_info.quality_metrics) === null || _l === void 0 ? void 0 : _l.noise_level) || "未评估"}
|
|
204
|
-
- **曝光**: ${((_m = content.technical_info.quality_metrics) === null || _m === void 0 ? void 0 : _m.exposure) || "未评估"}
|
|
205
|
-
`
|
|
206
|
-
: ""}
|
|
207
|
-
|
|
208
|
-
${content.ui_design_info
|
|
209
|
-
? `
|
|
210
|
-
### 🎨 UI设计分析
|
|
211
|
-
#### 布局结构
|
|
212
|
-
- **布局类型**: ${content.ui_design_info.layout_type}
|
|
213
|
-
- **响应式设计**: ${content.ui_design_info.responsive_design ? "支持" : "不支持"}
|
|
214
|
-
|
|
215
|
-
#### 组件分析
|
|
216
|
-
${content.ui_design_info.components && content.ui_design_info.components.length > 0
|
|
217
|
-
? content.ui_design_info.components
|
|
218
|
-
.map((comp, index) => `${index + 1}. **${comp.type}**: ${comp.name}`)
|
|
219
|
-
.join("\n")
|
|
220
|
-
: "未识别到具体组件"}
|
|
221
|
-
|
|
222
|
-
#### 色彩方案
|
|
223
|
-
- **主色调**: ${((_p = (_o = content.ui_design_info.color_scheme) === null || _o === void 0 ? void 0 : _o.primary_colors) === null || _p === void 0 ? void 0 : _p.join(", ")) || "未识别"}
|
|
224
|
-
- **辅助色**: ${((_r = (_q = content.ui_design_info.color_scheme) === null || _q === void 0 ? void 0 : _q.secondary_colors) === null || _r === void 0 ? void 0 : _r.join(", ")) || "未识别"}
|
|
225
|
-
- **背景色**: ${((_t = (_s = content.ui_design_info.color_scheme) === null || _s === void 0 ? void 0 : _s.background_colors) === null || _t === void 0 ? void 0 : _t.join(", ")) || "未识别"}
|
|
226
|
-
|
|
227
|
-
#### 导航设计
|
|
228
|
-
- **导航类型**: ${((_u = content.ui_design_info.navigation) === null || _u === void 0 ? void 0 : _u.type) || "未识别"}
|
|
229
|
-
- **导航元素**: ${((_w = (_v = content.ui_design_info.navigation) === null || _v === void 0 ? void 0 : _v.elements) === null || _w === void 0 ? void 0 : _w.join(", ")) || "未识别"}
|
|
230
|
-
|
|
231
|
-
#### 设计模式
|
|
232
|
-
${content.ui_design_info.design_patterns && content.ui_design_info.design_patterns.length > 0
|
|
233
|
-
? content.ui_design_info.design_patterns.map((pattern) => `- ${pattern}`).join("\n")
|
|
234
|
-
: "- 未识别到特定设计模式"}
|
|
235
|
-
`
|
|
236
|
-
: ""}
|
|
237
|
-
|
|
238
|
-
${content.requirement_info
|
|
239
|
-
? `
|
|
240
|
-
### 📋 需求分析
|
|
241
|
-
#### 功能需求
|
|
242
|
-
${content.requirement_info.functional_requirements && content.requirement_info.functional_requirements.length > 0
|
|
243
|
-
? content.requirement_info.functional_requirements
|
|
244
|
-
.map((req, index) => `
|
|
245
|
-
${index + 1}. **${req.title}** (优先级: ${req.priority})
|
|
246
|
-
- 描述: ${req.description}
|
|
247
|
-
- 类别: ${req.category}`)
|
|
248
|
-
.join("")
|
|
249
|
-
: "未识别到具体功能需求"}
|
|
250
|
-
|
|
251
|
-
#### 非功能需求
|
|
252
|
-
${content.requirement_info.non_functional_requirements && content.requirement_info.non_functional_requirements.length > 0
|
|
253
|
-
? content.requirement_info.non_functional_requirements
|
|
254
|
-
.map((req, index) => `
|
|
255
|
-
${index + 1}. **${req.type}**: ${req.description}`)
|
|
256
|
-
.join("")
|
|
257
|
-
: "未识别到非功能需求"}
|
|
258
|
-
|
|
259
|
-
#### 用户故事
|
|
260
|
-
${content.requirement_info.user_stories && content.requirement_info.user_stories.length > 0
|
|
261
|
-
? content.requirement_info.user_stories
|
|
262
|
-
.map((story, index) => `
|
|
263
|
-
${index + 1}. 作为 **${story.as_a}**,我希望 **${story.i_want}**,以便 **${story.so_that}** (优先级: ${story.priority})`)
|
|
264
|
-
.join("")
|
|
265
|
-
: "未识别到用户故事"}
|
|
266
|
-
|
|
267
|
-
#### 业务规则
|
|
268
|
-
${content.requirement_info.business_rules && content.requirement_info.business_rules.length > 0
|
|
269
|
-
? content.requirement_info.business_rules.map((rule) => `- ${rule}`).join("\n")
|
|
270
|
-
: "- 未识别到业务规则"}
|
|
271
|
-
`
|
|
272
|
-
: ""}
|
|
273
|
-
|
|
274
|
-
${Object.keys(content.details).length > 0
|
|
275
|
-
? `
|
|
276
|
-
### 📋 详细信息
|
|
277
|
-
${Object.entries(content.details)
|
|
278
|
-
.map(([key, value]) => `
|
|
279
|
-
**${key}**: ${typeof value === "object" ? JSON.stringify(value, null, 2) : value}
|
|
280
|
-
`)
|
|
281
|
-
.join("")}
|
|
282
|
-
`
|
|
283
|
-
: ""}
|
|
284
|
-
|
|
285
|
-
## 💡 分析总结
|
|
286
|
-
|
|
287
|
-
基于${getAnalysisTypeLabel(args.analysis_type)}分析,图片内容理解完成。
|
|
288
|
-
${confidence_score && confidence_score > 0.8
|
|
289
|
-
? "分析结果置信度较高,可信度良好。"
|
|
290
|
-
: ""}
|
|
291
|
-
${args.analysis_type === "custom"
|
|
292
|
-
? `使用自定义提示词: "${args.custom_prompt}"`
|
|
293
|
-
: ""}
|
|
294
|
-
|
|
295
|
-
**分析完成时间**: ${new Date().toISOString()}
|
|
296
|
-
`.trim();
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* 格式化错误响应
|
|
300
|
-
*/
|
|
301
|
-
function formatErrorResponse(error) {
|
|
302
|
-
const errorMessages = {
|
|
303
|
-
[types_1.AnalysisErrorCodes.INVALID_IMAGE_PATH]: "无效的图片路径",
|
|
304
|
-
[types_1.AnalysisErrorCodes.UNSUPPORTED_FORMAT]: "不支持的图片格式",
|
|
305
|
-
[types_1.AnalysisErrorCodes.FILE_NOT_FOUND]: "图片文件未找到",
|
|
306
|
-
[types_1.AnalysisErrorCodes.IMAGE_CORRUPTED]: "图片文件损坏",
|
|
307
|
-
[types_1.AnalysisErrorCodes.ANALYSIS_FAILED]: "分析失败",
|
|
308
|
-
[types_1.AnalysisErrorCodes.AI_SERVICE_ERROR]: "AI服务错误",
|
|
309
|
-
[types_1.AnalysisErrorCodes.INVALID_ANALYSIS_TYPE]: "无效的分析类型",
|
|
310
|
-
};
|
|
311
|
-
const errorTitle = errorMessages[error.code] || "分析错误";
|
|
312
|
-
return `
|
|
313
|
-
# ❌ ${errorTitle}
|
|
314
|
-
|
|
315
|
-
## 错误信息
|
|
316
|
-
${error.message}
|
|
317
|
-
|
|
318
|
-
## 错误代码
|
|
319
|
-
${error.code}
|
|
320
|
-
|
|
321
|
-
## 解决建议
|
|
322
|
-
${getErrorSuggestion(error.code)}
|
|
323
|
-
|
|
324
|
-
## 支持的功能
|
|
325
|
-
- **图片格式**: ${types_1.SUPPORTED_IMAGE_FORMATS.join(", ")}
|
|
326
|
-
- **分析类型**: 通用、物体识别、文字识别、场景分析、人物分析、技术分析、UI设计稿、需求识别、自定义
|
|
327
|
-
- **详细程度**: 简要、详细、全面
|
|
328
|
-
|
|
329
|
-
## 错误详情
|
|
330
|
-
- **时间**: ${new Date().toISOString()}
|
|
331
|
-
- **上下文**: ${error.context ? JSON.stringify(error.context, null, 2) : "无"}
|
|
332
|
-
|
|
333
|
-
请根据上述信息调整参数后重试。
|
|
334
|
-
`.trim();
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* 格式化未知错误响应
|
|
338
|
-
*/
|
|
339
|
-
function formatUnknownErrorResponse(error) {
|
|
340
|
-
return `
|
|
341
|
-
# ❌ 系统错误
|
|
342
|
-
|
|
343
|
-
图片内容分析过程中发生未知错误,请稍后重试或联系技术支持。
|
|
344
|
-
|
|
345
|
-
**错误信息**: ${(error === null || error === void 0 ? void 0 : error.message) || "未知错误"}
|
|
346
|
-
**时间**: ${new Date().toISOString()}
|
|
347
|
-
|
|
348
|
-
## 建议
|
|
349
|
-
1. 检查图片文件是否存在且可读
|
|
350
|
-
2. 确认图片格式是否支持
|
|
351
|
-
3. 验证图片文件是否损坏
|
|
352
|
-
4. 检查网络连接是否正常
|
|
353
|
-
5. 如问题持续,请联系技术支持
|
|
354
|
-
`.trim();
|
|
355
|
-
}
|
|
356
|
-
// 辅助函数
|
|
357
|
-
function formatFileSize(bytes) {
|
|
358
|
-
if (bytes === 0)
|
|
359
|
-
return "0 B";
|
|
360
|
-
const k = 1024;
|
|
361
|
-
const sizes = ["B", "KB", "MB", "GB"];
|
|
362
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
363
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
|
364
|
-
}
|
|
365
|
-
function getAnalysisTypeLabel(type) {
|
|
366
|
-
const labels = {
|
|
367
|
-
general: "通用分析",
|
|
368
|
-
objects: "物体识别",
|
|
369
|
-
text: "文字识别",
|
|
370
|
-
scene: "场景分析",
|
|
371
|
-
people: "人物分析",
|
|
372
|
-
technical: "技术分析",
|
|
373
|
-
ui_design: "UI设计稿分析",
|
|
374
|
-
requirement: "需求识别分析",
|
|
375
|
-
custom: "自定义分析",
|
|
376
|
-
};
|
|
377
|
-
return labels[type] || type;
|
|
378
|
-
}
|
|
379
|
-
function getDetailLevelLabel(level) {
|
|
380
|
-
const labels = {
|
|
381
|
-
brief: "简要",
|
|
382
|
-
detailed: "详细",
|
|
383
|
-
comprehensive: "全面",
|
|
384
|
-
};
|
|
385
|
-
return labels[level] || level;
|
|
386
|
-
}
|
|
387
|
-
function getErrorSuggestion(errorCode) {
|
|
388
|
-
const suggestions = {
|
|
389
|
-
[types_1.AnalysisErrorCodes.INVALID_IMAGE_PATH]: "请检查图片路径是否正确",
|
|
390
|
-
[types_1.AnalysisErrorCodes.UNSUPPORTED_FORMAT]: "请使用支持的图片格式(jpg, png, gif等)",
|
|
391
|
-
[types_1.AnalysisErrorCodes.FILE_NOT_FOUND]: "请确认图片文件存在且路径正确",
|
|
392
|
-
[types_1.AnalysisErrorCodes.IMAGE_CORRUPTED]: "请检查图片文件是否完整且未损坏",
|
|
393
|
-
[types_1.AnalysisErrorCodes.ANALYSIS_FAILED]: "请重试或使用不同的分析类型",
|
|
394
|
-
[types_1.AnalysisErrorCodes.AI_SERVICE_ERROR]: "请检查网络连接或稍后重试",
|
|
395
|
-
[types_1.AnalysisErrorCodes.INVALID_ANALYSIS_TYPE]: "请使用有效的分析类型",
|
|
396
|
-
};
|
|
397
|
-
return suggestions[errorCode] || "请检查输入参数并重试";
|
|
398
|
-
}
|
|
399
|
-
// 导出类型和服务
|
|
400
|
-
var analyzer_2 = require("./analyzer");
|
|
401
|
-
Object.defineProperty(exports, "ImageAnalyzer", { enumerable: true, get: function () { return analyzer_2.ImageAnalyzer; } });
|
|
402
|
-
var types_2 = require("./types");
|
|
403
|
-
Object.defineProperty(exports, "ImageAnalysisError", { enumerable: true, get: function () { return types_2.ImageAnalysisError; } });
|
|
404
|
-
Object.defineProperty(exports, "AnalysisErrorCodes", { enumerable: true, get: function () { return types_2.AnalysisErrorCodes; } });
|
|
405
|
-
Object.defineProperty(exports, "AnalysisType", { enumerable: true, get: function () { return types_2.AnalysisType; } });
|
|
406
|
-
Object.defineProperty(exports, "DetailLevel", { enumerable: true, get: function () { return types_2.DetailLevel; } });
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* 图片内容理解智能体的类型定义
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SUPPORTED_IMAGE_FORMATS = exports.AnalysisErrorCodes = exports.ImageAnalysisError = exports.DetailLevel = exports.AnalysisType = void 0;
|
|
7
|
-
var AnalysisType;
|
|
8
|
-
(function (AnalysisType) {
|
|
9
|
-
AnalysisType["GENERAL"] = "general";
|
|
10
|
-
AnalysisType["OBJECTS"] = "objects";
|
|
11
|
-
AnalysisType["TEXT"] = "text";
|
|
12
|
-
AnalysisType["SCENE"] = "scene";
|
|
13
|
-
AnalysisType["PEOPLE"] = "people";
|
|
14
|
-
AnalysisType["TECHNICAL"] = "technical";
|
|
15
|
-
AnalysisType["UI_DESIGN"] = "ui_design";
|
|
16
|
-
AnalysisType["REQUIREMENT"] = "requirement";
|
|
17
|
-
AnalysisType["CUSTOM"] = "custom"; // 自定义分析
|
|
18
|
-
})(AnalysisType || (exports.AnalysisType = AnalysisType = {}));
|
|
19
|
-
var DetailLevel;
|
|
20
|
-
(function (DetailLevel) {
|
|
21
|
-
DetailLevel["BRIEF"] = "brief";
|
|
22
|
-
DetailLevel["DETAILED"] = "detailed";
|
|
23
|
-
DetailLevel["COMPREHENSIVE"] = "comprehensive"; // 全面
|
|
24
|
-
})(DetailLevel || (exports.DetailLevel = DetailLevel = {}));
|
|
25
|
-
class ImageAnalysisError extends Error {
|
|
26
|
-
constructor(message, code, context) {
|
|
27
|
-
super(message);
|
|
28
|
-
this.code = code;
|
|
29
|
-
this.context = context;
|
|
30
|
-
this.name = 'ImageAnalysisError';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.ImageAnalysisError = ImageAnalysisError;
|
|
34
|
-
var AnalysisErrorCodes;
|
|
35
|
-
(function (AnalysisErrorCodes) {
|
|
36
|
-
AnalysisErrorCodes["INVALID_IMAGE_PATH"] = "INVALID_IMAGE_PATH";
|
|
37
|
-
AnalysisErrorCodes["UNSUPPORTED_FORMAT"] = "UNSUPPORTED_FORMAT";
|
|
38
|
-
AnalysisErrorCodes["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
|
|
39
|
-
AnalysisErrorCodes["IMAGE_CORRUPTED"] = "IMAGE_CORRUPTED";
|
|
40
|
-
AnalysisErrorCodes["ANALYSIS_FAILED"] = "ANALYSIS_FAILED";
|
|
41
|
-
AnalysisErrorCodes["AI_SERVICE_ERROR"] = "AI_SERVICE_ERROR";
|
|
42
|
-
AnalysisErrorCodes["INVALID_ANALYSIS_TYPE"] = "INVALID_ANALYSIS_TYPE";
|
|
43
|
-
})(AnalysisErrorCodes || (exports.AnalysisErrorCodes = AnalysisErrorCodes = {}));
|
|
44
|
-
exports.SUPPORTED_IMAGE_FORMATS = [
|
|
45
|
-
'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'tif', 'webp'
|
|
46
|
-
];
|