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
package/dist/utils/dify.js
DELETED
|
@@ -1,243 +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.invokeFlow = invokeFlow;
|
|
13
|
-
exports.removeCodeBlock = removeCodeBlock;
|
|
14
|
-
/**
|
|
15
|
-
* 调用工作流
|
|
16
|
-
*
|
|
17
|
-
* @param params 请求参数对象
|
|
18
|
-
* @param params.appid 应用ID,如果不提供则使用默认值 "app-ESTcrkOPOmkxdrO0120mE4s1"
|
|
19
|
-
* @param params.data 工作流输入数据
|
|
20
|
-
* @param params.timeout 请求超时时间(毫秒)
|
|
21
|
-
* @param streamCb 流回调函数,用于处理流式响应
|
|
22
|
-
* @returns Promise 返回一个Promise对象,解析为工作流响应结果或流响应对象
|
|
23
|
-
*/
|
|
24
|
-
function invokeFlow(params, streamCb) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const { appid = 'app-ESTcrkOPOmkxdrO0120mE4s1', data, timeout = 30 * 60 * 1000 // 默认设置为30分钟
|
|
27
|
-
} = params;
|
|
28
|
-
const controller = new AbortController();
|
|
29
|
-
const signal = controller.signal;
|
|
30
|
-
const fetchData = (...args_1) => __awaiter(this, [...args_1], void 0, function* (retryCount = 0) {
|
|
31
|
-
try {
|
|
32
|
-
// 设置fetch的timeout选项
|
|
33
|
-
const fetchOptions = {
|
|
34
|
-
method: 'POST',
|
|
35
|
-
headers: {
|
|
36
|
-
Authorization: `Bearer ${appid}`,
|
|
37
|
-
'Content-Type': 'application/json'
|
|
38
|
-
},
|
|
39
|
-
body: JSON.stringify({
|
|
40
|
-
'inputs': data,
|
|
41
|
-
'response_mode': 'streaming',
|
|
42
|
-
'user': "aico-mcp"
|
|
43
|
-
}),
|
|
44
|
-
signal
|
|
45
|
-
};
|
|
46
|
-
// 发起请求,加入 abort 信号
|
|
47
|
-
const res = yield fetch('http://11.0.166.20:9199/v1/workflows/run', fetchOptions);
|
|
48
|
-
if (!res.ok) {
|
|
49
|
-
if (retryCount < 3) {
|
|
50
|
-
yield new Promise(resolve => setTimeout(resolve, 1000));
|
|
51
|
-
return fetchData(retryCount + 1);
|
|
52
|
-
}
|
|
53
|
-
const errorResponse = yield res.text();
|
|
54
|
-
throw new Error(`网络响应异常: ${res.status} ${res.statusText} - ${errorResponse}`);
|
|
55
|
-
}
|
|
56
|
-
if (res.ok) {
|
|
57
|
-
if (res.body) {
|
|
58
|
-
const reader = res.body.getReader();
|
|
59
|
-
const decoder = new TextDecoder('utf-8');
|
|
60
|
-
if (streamCb) {
|
|
61
|
-
// 流式处理,调用 streamCb
|
|
62
|
-
const streamResponse = new ReadableStream({
|
|
63
|
-
start(controller) {
|
|
64
|
-
let buffer = '';
|
|
65
|
-
function push() {
|
|
66
|
-
reader.read().then(({ done, value }) => {
|
|
67
|
-
if (done) {
|
|
68
|
-
// 处理剩余的缓冲区数据
|
|
69
|
-
const lines = buffer.split('\n');
|
|
70
|
-
for (const line of lines) {
|
|
71
|
-
handleLine(line, controller);
|
|
72
|
-
}
|
|
73
|
-
// 调用结束回调
|
|
74
|
-
if (streamCb) {
|
|
75
|
-
streamCb({ isEnd: true });
|
|
76
|
-
}
|
|
77
|
-
controller.close();
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const chunkText = decoder.decode(value, { stream: true });
|
|
81
|
-
buffer += chunkText;
|
|
82
|
-
// 按行分割缓冲区数据
|
|
83
|
-
const lines = buffer.split('\n');
|
|
84
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
85
|
-
handleLine(lines[i], controller);
|
|
86
|
-
}
|
|
87
|
-
// 保留最后一行未处理的数据
|
|
88
|
-
buffer = lines[lines.length - 1];
|
|
89
|
-
// 继续读取下一部分数据
|
|
90
|
-
push();
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
function handleLine(line, controller) {
|
|
94
|
-
var _a;
|
|
95
|
-
line = line.trim();
|
|
96
|
-
if (line.startsWith('data:')) {
|
|
97
|
-
const dataStr = line.slice(5).trim();
|
|
98
|
-
if (dataStr === '')
|
|
99
|
-
return;
|
|
100
|
-
try {
|
|
101
|
-
const jsonData = JSON.parse(dataStr);
|
|
102
|
-
if ((_a = jsonData.data) === null || _a === void 0 ? void 0 : _a.text) {
|
|
103
|
-
const wrappedData = {
|
|
104
|
-
content: jsonData.data.text.toString(),
|
|
105
|
-
controller
|
|
106
|
-
};
|
|
107
|
-
if (streamCb) {
|
|
108
|
-
streamCb(wrappedData);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (e) {
|
|
113
|
-
console.error('解析JSON失败:', e);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
push();
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
// 返回一个 Promise,resolve undefined 表示流式处理开始
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
// 非流式处理,收集所有数据并返回
|
|
125
|
-
let buffer = '';
|
|
126
|
-
let accumulatedText = '';
|
|
127
|
-
let isResponseEnded = false;
|
|
128
|
-
const readAll = () => __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
const { done, value } = yield reader.read();
|
|
130
|
-
if (done) {
|
|
131
|
-
if (!isResponseEnded) {
|
|
132
|
-
// 响应提前结束,抛出错误
|
|
133
|
-
throw new Error('响应提前结束');
|
|
134
|
-
}
|
|
135
|
-
// 返回最终的响应对象
|
|
136
|
-
return accumulatedText;
|
|
137
|
-
}
|
|
138
|
-
const chunkText = decoder.decode(value, { stream: true });
|
|
139
|
-
buffer += chunkText;
|
|
140
|
-
// 按行分割缓冲区数据
|
|
141
|
-
const lines = buffer.split('\n');
|
|
142
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
143
|
-
const line = lines[i].trim();
|
|
144
|
-
if (!line.startsWith('data:'))
|
|
145
|
-
continue;
|
|
146
|
-
const dataStr = line.slice(5).trim();
|
|
147
|
-
if (dataStr === '')
|
|
148
|
-
continue;
|
|
149
|
-
try {
|
|
150
|
-
const jsonData = JSON.parse(dataStr);
|
|
151
|
-
switch (jsonData.event) {
|
|
152
|
-
case 'message':
|
|
153
|
-
case 'agent_message':
|
|
154
|
-
case 'text_chunk': {
|
|
155
|
-
const content = jsonData.event === 'text_chunk' ? jsonData.data.text : jsonData.answer;
|
|
156
|
-
accumulatedText += content;
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
case 'workflow_finished':
|
|
160
|
-
accumulatedText = jsonData.data;
|
|
161
|
-
isResponseEnded = true;
|
|
162
|
-
break;
|
|
163
|
-
case 'message_end':
|
|
164
|
-
isResponseEnded = true;
|
|
165
|
-
break;
|
|
166
|
-
case 'error':
|
|
167
|
-
throw new Error(`服务器错误: ${jsonData.code}, ${jsonData.message}`);
|
|
168
|
-
default:
|
|
169
|
-
// 忽略其他事件类型
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
catch (e) {
|
|
174
|
-
throw new Error('解析JSON失败: ' + e.message);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
// 保留最后一行未处理的数据
|
|
178
|
-
buffer = lines[lines.length - 1];
|
|
179
|
-
return readAll();
|
|
180
|
-
});
|
|
181
|
-
return readAll();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
throw new Error('响应体为空');
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
const errorResponse = yield res.text();
|
|
190
|
-
throw new Error(`网络响应异常: ${res.status} ${res.statusText} - ${errorResponse}`);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
catch (error) {
|
|
194
|
-
// 捕获并抛出错误
|
|
195
|
-
if (error.name === 'AbortError') {
|
|
196
|
-
throw new Error('请求已被中止,超时');
|
|
197
|
-
}
|
|
198
|
-
throw error;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
try {
|
|
202
|
-
const result = yield Promise.race([
|
|
203
|
-
fetchData(),
|
|
204
|
-
new Promise((_, reject) => {
|
|
205
|
-
setTimeout(() => {
|
|
206
|
-
controller.abort();
|
|
207
|
-
reject(new Error('请求超时'));
|
|
208
|
-
}, timeout);
|
|
209
|
-
})
|
|
210
|
-
]);
|
|
211
|
-
if (streamCb) {
|
|
212
|
-
// 流式处理,不返回数据
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
// 非流式处理,返回数据
|
|
217
|
-
return result;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
catch (error) {
|
|
221
|
-
controller.abort(); // 确保请求被中止
|
|
222
|
-
throw error;
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* 移除指定语言的代码块
|
|
228
|
-
*
|
|
229
|
-
* @param content 包含代码块的内容
|
|
230
|
-
* @returns 移除代码块后的内容
|
|
231
|
-
*/
|
|
232
|
-
function removeCodeBlock(content) {
|
|
233
|
-
const codeBlockMatch = content.trim().match(/^```(\w+)\n/);
|
|
234
|
-
let language = '';
|
|
235
|
-
if (codeBlockMatch) {
|
|
236
|
-
language = codeBlockMatch[1]; // 提取语言类型,如 json、sql 等
|
|
237
|
-
}
|
|
238
|
-
const startRegExp = new RegExp(`^\\\`\\\`\\\`${language}\\n`);
|
|
239
|
-
return content
|
|
240
|
-
.trim()
|
|
241
|
-
.replace(startRegExp, '')
|
|
242
|
-
.replace(/\n?```$/, '');
|
|
243
|
-
}
|
package/dist/utils/logger.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.logger = void 0;
|
|
18
|
-
const winston_1 = __importDefault(require("winston"));
|
|
19
|
-
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
|
20
|
-
const config_1 = require("./config");
|
|
21
|
-
const path_1 = __importDefault(require("path"));
|
|
22
|
-
// 确保日志目录存在
|
|
23
|
-
let logDir;
|
|
24
|
-
try {
|
|
25
|
-
const storageDir = (0, config_1.getStorageDir)();
|
|
26
|
-
if (storageDir) {
|
|
27
|
-
logDir = storageDir + '/logs';
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
logDir = './.aico/logs';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
// 如果getStorageDir失败,使用默认日志目录
|
|
35
|
-
logDir = './.aico/logs';
|
|
36
|
-
}
|
|
37
|
-
// 定义日志级别和颜色
|
|
38
|
-
const levels = {
|
|
39
|
-
error: 0,
|
|
40
|
-
warn: 1,
|
|
41
|
-
info: 2,
|
|
42
|
-
debug: 3,
|
|
43
|
-
verbose: 4
|
|
44
|
-
};
|
|
45
|
-
const colors = {
|
|
46
|
-
error: 'red',
|
|
47
|
-
warn: 'yellow',
|
|
48
|
-
info: 'green',
|
|
49
|
-
debug: 'blue',
|
|
50
|
-
verbose: 'cyan'
|
|
51
|
-
};
|
|
52
|
-
winston_1.default.addColors(colors);
|
|
53
|
-
// 控制台输出的格式化
|
|
54
|
-
const consoleFormat = winston_1.default.format.combine(winston_1.default.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.colorize(), winston_1.default.format.printf((_a) => {
|
|
55
|
-
var { timestamp, level, message } = _a, meta = __rest(_a, ["timestamp", "level", "message"]);
|
|
56
|
-
const metaStr = Object.keys(meta).length ? JSON.stringify(meta, null, 2) : '';
|
|
57
|
-
return `${timestamp} [${level}]: ${message} ${metaStr}`;
|
|
58
|
-
}));
|
|
59
|
-
// 文件输出的格式化(JSON格式,包含完整的错误信息)
|
|
60
|
-
const fileFormat = winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.errors({ stack: true }), winston_1.default.format.json());
|
|
61
|
-
// 异常和拒绝处理的专用格式化
|
|
62
|
-
const exceptionFormat = winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.errors({ stack: true }), winston_1.default.format.printf(info => {
|
|
63
|
-
const { timestamp, level, message, stack } = info, meta = __rest(info, ["timestamp", "level", "message", "stack"]);
|
|
64
|
-
// 获取错误对象
|
|
65
|
-
const error = meta.error || meta;
|
|
66
|
-
// 构建完整的错误信息对象
|
|
67
|
-
const errorInfo = {
|
|
68
|
-
timestamp,
|
|
69
|
-
level: level || 'error',
|
|
70
|
-
message: message || 'Uncaught Exception',
|
|
71
|
-
stack: stack || (error && error.stack) || 'No stack trace available',
|
|
72
|
-
error: Object.assign({ name: (error && error.name) || 'Error', message: (error && error.message) || String(error || message), code: (error && error.code) || meta.code }, meta)
|
|
73
|
-
};
|
|
74
|
-
return JSON.stringify(errorInfo, null, 2);
|
|
75
|
-
}));
|
|
76
|
-
// 创建日志传输器
|
|
77
|
-
const transports = [
|
|
78
|
-
// 控制台输出
|
|
79
|
-
new winston_1.default.transports.Console({
|
|
80
|
-
format: consoleFormat,
|
|
81
|
-
level: 'verbose'
|
|
82
|
-
})
|
|
83
|
-
];
|
|
84
|
-
// 只有当logDir有效时才添加文件传输器
|
|
85
|
-
if (logDir) {
|
|
86
|
-
transports.push(new winston_daily_rotate_file_1.default({
|
|
87
|
-
filename: path_1.default.join(logDir, 'application-%DATE%.log'),
|
|
88
|
-
datePattern: 'YYYY-MM-DD',
|
|
89
|
-
zippedArchive: true,
|
|
90
|
-
maxSize: '2m',
|
|
91
|
-
maxFiles: '1d',
|
|
92
|
-
format: fileFormat,
|
|
93
|
-
level: 'info'
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
96
|
-
// 创建logger实例
|
|
97
|
-
exports.logger = winston_1.default.createLogger({
|
|
98
|
-
level: 'debug',
|
|
99
|
-
levels,
|
|
100
|
-
format: winston_1.default.format.combine(winston_1.default.format.errors({ stack: true }), winston_1.default.format.splat()),
|
|
101
|
-
transports,
|
|
102
|
-
exceptionHandlers: logDir ? [
|
|
103
|
-
new winston_daily_rotate_file_1.default({
|
|
104
|
-
filename: path_1.default.join(logDir, 'exceptions-%DATE%.log'),
|
|
105
|
-
datePattern: 'YYYY-MM-DD',
|
|
106
|
-
zippedArchive: true,
|
|
107
|
-
maxSize: '1m',
|
|
108
|
-
maxFiles: '1d',
|
|
109
|
-
format: exceptionFormat
|
|
110
|
-
})
|
|
111
|
-
] : [],
|
|
112
|
-
rejectionHandlers: logDir ? [
|
|
113
|
-
new winston_daily_rotate_file_1.default({
|
|
114
|
-
filename: path_1.default.join(logDir, 'rejections-%DATE%.log'),
|
|
115
|
-
datePattern: 'YYYY-MM-DD',
|
|
116
|
-
zippedArchive: true,
|
|
117
|
-
maxSize: '1m',
|
|
118
|
-
maxFiles: '1d',
|
|
119
|
-
format: exceptionFormat
|
|
120
|
-
})
|
|
121
|
-
] : []
|
|
122
|
-
});
|
|
123
|
-
// 添加一个关闭时的监听,确保日志都写入完毕
|
|
124
|
-
process.on('SIGINT', () => {
|
|
125
|
-
exports.logger.end(() => {
|
|
126
|
-
exports.logger.info('日志已关闭');
|
|
127
|
-
process.exit(0);
|
|
128
|
-
});
|
|
129
|
-
});
|
package/dist/utils/openai.js
DELETED
|
@@ -1,225 +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
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
17
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
18
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
19
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
20
|
-
function fulfill(value) { resume("next", value); }
|
|
21
|
-
function reject(value) { resume("throw", value); }
|
|
22
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.openAIService = exports.OpenAIService = void 0;
|
|
26
|
-
class OpenAIService {
|
|
27
|
-
constructor() {
|
|
28
|
-
this.apiKey = 'sk-d535ca964a434f20898150f77d6cdb2a';
|
|
29
|
-
this.baseUrl = 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions';
|
|
30
|
-
this.model = 'qwen3-coder-plus';
|
|
31
|
-
this.kimiApiKey = 'sk-fp8wJSigZBEP3x8y6MAZWGPuVIHJ5PDZtX9lMQQk8hjP2R0u';
|
|
32
|
-
this.kimiBaseUrl = 'https://api.moonshot.cn/anthropic';
|
|
33
|
-
this.kimiModel = 'kimi-k2-0711-preview';
|
|
34
|
-
}
|
|
35
|
-
generateText(params) {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const { prompt, temperature, system_prompt } = params;
|
|
38
|
-
let lastError = null;
|
|
39
|
-
// First try with qwen3-coder-plus
|
|
40
|
-
try {
|
|
41
|
-
const response = yield fetch(this.baseUrl, {
|
|
42
|
-
method: 'POST',
|
|
43
|
-
headers: {
|
|
44
|
-
'Content-Type': 'application/json',
|
|
45
|
-
'Authorization': `Bearer ${this.apiKey}`,
|
|
46
|
-
},
|
|
47
|
-
body: JSON.stringify({
|
|
48
|
-
model: this.model,
|
|
49
|
-
messages: [
|
|
50
|
-
...(system_prompt ? [{ role: 'system', content: system_prompt }] : []),
|
|
51
|
-
{ role: 'user', content: prompt }
|
|
52
|
-
],
|
|
53
|
-
max_tokens: 65536,
|
|
54
|
-
temperature,
|
|
55
|
-
stream: false,
|
|
56
|
-
}),
|
|
57
|
-
});
|
|
58
|
-
if (!response.ok) {
|
|
59
|
-
const errorText = yield response.text();
|
|
60
|
-
throw new Error(`OpenAI API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
61
|
-
}
|
|
62
|
-
const data = yield response.json();
|
|
63
|
-
if (!data.choices || data.choices.length === 0) {
|
|
64
|
-
throw new Error('No choices returned from OpenAI API');
|
|
65
|
-
}
|
|
66
|
-
return data.choices[0].message.content;
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
lastError = error;
|
|
70
|
-
// If first attempt fails, retry with kimi model
|
|
71
|
-
try {
|
|
72
|
-
const response = yield fetch(this.kimiBaseUrl, {
|
|
73
|
-
method: 'POST',
|
|
74
|
-
headers: {
|
|
75
|
-
'Content-Type': 'application/json',
|
|
76
|
-
'Authorization': `Bearer ${this.kimiApiKey}`,
|
|
77
|
-
},
|
|
78
|
-
body: JSON.stringify({
|
|
79
|
-
model: this.kimiModel,
|
|
80
|
-
messages: [
|
|
81
|
-
...(system_prompt ? [{ role: 'system', content: system_prompt }] : []),
|
|
82
|
-
{ role: 'user', content: prompt }
|
|
83
|
-
],
|
|
84
|
-
max_tokens: 65536,
|
|
85
|
-
temperature,
|
|
86
|
-
stream: false,
|
|
87
|
-
}),
|
|
88
|
-
});
|
|
89
|
-
if (!response.ok) {
|
|
90
|
-
const errorText = yield response.text();
|
|
91
|
-
throw new Error(`Kimi API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
92
|
-
}
|
|
93
|
-
const data = yield response.json();
|
|
94
|
-
if (!data.choices || data.choices.length === 0) {
|
|
95
|
-
throw new Error('No choices returned from Kimi API');
|
|
96
|
-
}
|
|
97
|
-
return data.choices[0].message.content;
|
|
98
|
-
}
|
|
99
|
-
catch (kimiError) {
|
|
100
|
-
// If both attempts fail, throw the original error
|
|
101
|
-
throw lastError;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
generateStream(params) {
|
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
const { prompt, model, temperature, system_prompt } = params;
|
|
109
|
-
try {
|
|
110
|
-
const response = yield fetch(this.baseUrl, {
|
|
111
|
-
method: 'POST',
|
|
112
|
-
headers: {
|
|
113
|
-
'Content-Type': 'application/json',
|
|
114
|
-
'Authorization': `Bearer ${this.apiKey}`,
|
|
115
|
-
},
|
|
116
|
-
body: JSON.stringify({
|
|
117
|
-
model,
|
|
118
|
-
messages: [
|
|
119
|
-
...(system_prompt ? [{ role: 'system', content: system_prompt }] : []),
|
|
120
|
-
{ role: 'user', content: prompt }
|
|
121
|
-
],
|
|
122
|
-
max_tokens: 65536,
|
|
123
|
-
temperature,
|
|
124
|
-
stream: true,
|
|
125
|
-
}),
|
|
126
|
-
});
|
|
127
|
-
if (!response.ok) {
|
|
128
|
-
const errorText = yield response.text();
|
|
129
|
-
throw new Error(`OpenAI API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
130
|
-
}
|
|
131
|
-
if (!response.body) {
|
|
132
|
-
throw new Error('Response body is null');
|
|
133
|
-
}
|
|
134
|
-
const reader = response.body.getReader();
|
|
135
|
-
const decoder = new TextDecoder();
|
|
136
|
-
return {
|
|
137
|
-
[Symbol.asyncIterator]() {
|
|
138
|
-
return __asyncGenerator(this, arguments, function* _a() {
|
|
139
|
-
var _b, _c, _d;
|
|
140
|
-
try {
|
|
141
|
-
while (true) {
|
|
142
|
-
const { done, value } = yield __await(reader.read());
|
|
143
|
-
if (done)
|
|
144
|
-
break;
|
|
145
|
-
const chunk = decoder.decode(value);
|
|
146
|
-
const lines = chunk.split('\n').filter(line => line.trim() !== '');
|
|
147
|
-
for (const line of lines) {
|
|
148
|
-
if (line.startsWith('data: ')) {
|
|
149
|
-
const data = line.slice(6);
|
|
150
|
-
if (data === '[DONE]')
|
|
151
|
-
return yield __await(void 0);
|
|
152
|
-
try {
|
|
153
|
-
const parsed = JSON.parse(data);
|
|
154
|
-
const content = (_d = (_c = (_b = parsed.choices) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.delta) === null || _d === void 0 ? void 0 : _d.content;
|
|
155
|
-
if (content) {
|
|
156
|
-
yield yield __await(content);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
// Skip invalid JSON
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
finally {
|
|
167
|
-
reader.releaseLock();
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
throw error;
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Analyze an image using vision capabilities
|
|
180
|
-
*
|
|
181
|
-
* @param params - Vision analysis parameters
|
|
182
|
-
* @returns Analysis result content
|
|
183
|
-
*/
|
|
184
|
-
analyzeImage(params) {
|
|
185
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
const { prompt, image_base64, system_prompt } = params;
|
|
187
|
-
const response = yield fetch("https://api.moonshot.cn/v1/chat/completions", {
|
|
188
|
-
method: 'POST',
|
|
189
|
-
headers: {
|
|
190
|
-
'Content-Type': 'application/json',
|
|
191
|
-
'Authorization': `Bearer sk-fp8wJSigZBEP3x8y6MAZWGPuVIHJ5PDZtX9lMQQk8hjP2R0u`,
|
|
192
|
-
},
|
|
193
|
-
body: JSON.stringify({
|
|
194
|
-
model: 'kimi-latest',
|
|
195
|
-
messages: [
|
|
196
|
-
...(system_prompt ? [{
|
|
197
|
-
role: 'system',
|
|
198
|
-
content: [{ type: 'text', text: system_prompt }]
|
|
199
|
-
}] : []),
|
|
200
|
-
{
|
|
201
|
-
role: 'user',
|
|
202
|
-
content: [
|
|
203
|
-
{ type: 'image_url', image_url: { url: image_base64 } },
|
|
204
|
-
{ type: 'text', text: prompt }
|
|
205
|
-
]
|
|
206
|
-
}
|
|
207
|
-
],
|
|
208
|
-
stream: false,
|
|
209
|
-
}),
|
|
210
|
-
});
|
|
211
|
-
if (!response.ok) {
|
|
212
|
-
const errorText = yield response.text();
|
|
213
|
-
throw new Error(`OpenAI Vision API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
214
|
-
}
|
|
215
|
-
const data = yield response.json();
|
|
216
|
-
if (!data.choices || data.choices.length === 0) {
|
|
217
|
-
throw new Error('No choices returned from OpenAI Vision API');
|
|
218
|
-
}
|
|
219
|
-
return data.choices[0].message.content;
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
exports.OpenAIService = OpenAIService;
|
|
224
|
-
// Export singleton instance
|
|
225
|
-
exports.openAIService = new OpenAIService();
|
package/dist/utils/pack.js
DELETED
|
@@ -1,75 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.packProject = packProject;
|
|
16
|
-
exports.processRemoteRepo = processRemoteRepo;
|
|
17
|
-
const aico_pack_1 = require("aico-pack");
|
|
18
|
-
const config_1 = require("./config");
|
|
19
|
-
const logger_1 = require("./logger");
|
|
20
|
-
const path_1 = __importDefault(require("path"));
|
|
21
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
22
|
-
function packProject(projectPath) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
// ---------------------- 步骤1:准备Markdown存储目录 ----------------------
|
|
25
|
-
const mdDir = path_1.default.join((0, config_1.getStorageDir)(), 'tech');
|
|
26
|
-
yield promises_1.default.mkdir(mdDir, { recursive: true });
|
|
27
|
-
// ---------------------- 步骤2:生成架构设计Markdown文档 ----------------------
|
|
28
|
-
logger_1.logger.info(`📂 正在分析当前本地项目`);
|
|
29
|
-
// 定义输出文件路径
|
|
30
|
-
const mdPath = path_1.default.join(mdDir, `项目架构分析.md`);
|
|
31
|
-
const options = {
|
|
32
|
-
output: mdPath,
|
|
33
|
-
style: 'markdown',
|
|
34
|
-
headerText: "智能软件星工厂",
|
|
35
|
-
fileSummary: true,
|
|
36
|
-
removeEmptyLines: true,
|
|
37
|
-
removeComments: true,
|
|
38
|
-
showLineNumbers: true,
|
|
39
|
-
compress: true,
|
|
40
|
-
quiet: true,
|
|
41
|
-
customPatterns: [
|
|
42
|
-
"**/*.md",
|
|
43
|
-
"**/*.log",
|
|
44
|
-
"**/*.json",
|
|
45
|
-
"**/*.txt",
|
|
46
|
-
"**/*.dockerfile",
|
|
47
|
-
"**/*.yml",
|
|
48
|
-
"**/*.yaml",
|
|
49
|
-
"**/*.sh",
|
|
50
|
-
"**/*.env",
|
|
51
|
-
"**/*.env.example",
|
|
52
|
-
"**/LICENSE",
|
|
53
|
-
"**/test/**",
|
|
54
|
-
],
|
|
55
|
-
};
|
|
56
|
-
// 如果提供了项目路径,则使用该路径,否则使用默认的PROJECT_ROOT
|
|
57
|
-
const targetPath = projectPath || config_1.PROJECT_ROOT;
|
|
58
|
-
yield (0, aico_pack_1.runCli)([targetPath], process.cwd(), options);
|
|
59
|
-
return mdPath;
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* 处理远程仓库生成Markdown
|
|
64
|
-
*/
|
|
65
|
-
function processRemoteRepo(repoUrl, outputPath) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
const options = {
|
|
68
|
-
remote: repoUrl,
|
|
69
|
-
output: outputPath,
|
|
70
|
-
compress: true
|
|
71
|
-
};
|
|
72
|
-
yield (0, aico_pack_1.runCli)([config_1.PROJECT_ROOT], process.cwd(), options);
|
|
73
|
-
return outputPath;
|
|
74
|
-
});
|
|
75
|
-
}
|