@shun-js/aibaiban-server 1.4.4 → 1.4.6
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 -2
- package/server/service/CCService.js +15 -3
- package/server/service/LLMService.js +73 -157
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shun-js/aibaiban-server",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6",
|
|
4
4
|
"description": "aibaiban.com server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai aibaiban"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"access": "public",
|
|
47
47
|
"registry": "https://registry.npmjs.org/"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "db63ae30bdb80c743746bdb4727bf3b9f0b62b83"
|
|
50
50
|
}
|
|
@@ -44,7 +44,7 @@ exports.drawCC = async (req, res) => {
|
|
|
44
44
|
const result = await sendPromptViaRelay({
|
|
45
45
|
wsUrl: relayConfig.wsUrl,
|
|
46
46
|
authSecret: relayConfig.authSecret,
|
|
47
|
-
userId: req.
|
|
47
|
+
userId: req.headers.userid || "guest",
|
|
48
48
|
prompt: lastUserMsg,
|
|
49
49
|
timeout: relayConfig.timeout || 600000,
|
|
50
50
|
});
|
|
@@ -52,10 +52,22 @@ exports.drawCC = async (req, res) => {
|
|
|
52
52
|
clearInterval(keepalive);
|
|
53
53
|
const duration = Date.now() - startTime;
|
|
54
54
|
|
|
55
|
-
// 解析 Claude Code 返回结果:[MERMAID]、[REPLY]、[IRRELEVANT] 前缀
|
|
55
|
+
// 解析 Claude Code 返回结果:[MERMAID]、[CLEAR_AND_MERMAID]、[REPLY]、[IRRELEVANT] 前缀
|
|
56
56
|
const trimmed = result.trim();
|
|
57
57
|
|
|
58
|
-
if (trimmed.startsWith("[
|
|
58
|
+
if (trimmed.startsWith("[CLEAR_AND_MERMAID]")) {
|
|
59
|
+
const code = trimmed.slice("[CLEAR_AND_MERMAID]".length).trim();
|
|
60
|
+
req.logger.info(
|
|
61
|
+
methodName,
|
|
62
|
+
"clear_and_mermaid",
|
|
63
|
+
code.length,
|
|
64
|
+
`${duration}ms`,
|
|
65
|
+
);
|
|
66
|
+
chatFeishuMsg(req, `cc-clear-mermaid-${code.length}chars`);
|
|
67
|
+
res.streaming(
|
|
68
|
+
`data: ${JSON.stringify({ type: "clear_and_mermaid", code, duration })}\n\n`,
|
|
69
|
+
);
|
|
70
|
+
} else if (trimmed.startsWith("[MERMAID]")) {
|
|
59
71
|
const code = trimmed.slice("[MERMAID]".length).trim();
|
|
60
72
|
req.logger.info(methodName, "mermaid", code.length, `${duration}ms`);
|
|
61
73
|
chatFeishuMsg(req, `cc-mermaid-${code.length}chars`);
|
|
@@ -4,7 +4,6 @@ const prompts = require("../util/prompt-agent.js");
|
|
|
4
4
|
|
|
5
5
|
// util
|
|
6
6
|
const { chatFeishuMsg, errorFeishuMsg } = require("../util/feishu.js");
|
|
7
|
-
const { sendPromptViaRelay } = require("../util/relay-client.js");
|
|
8
7
|
|
|
9
8
|
// LLM 配置
|
|
10
9
|
const llmConfig = global.QZ_CONFIG.llm;
|
|
@@ -196,86 +195,6 @@ exports.drawAgent = async (req, res) => {
|
|
|
196
195
|
try {
|
|
197
196
|
const startTime = Date.now();
|
|
198
197
|
|
|
199
|
-
// LLM Mermaid 管线函数
|
|
200
|
-
const runLLMMermaidPipeline = async () => {
|
|
201
|
-
let elaboration = "";
|
|
202
|
-
|
|
203
|
-
await runAgents([
|
|
204
|
-
// elaborate
|
|
205
|
-
{
|
|
206
|
-
agentStartCallback: () => {
|
|
207
|
-
res.streaming(
|
|
208
|
-
`data: ${JSON.stringify({ type: "status", step: "elaborate" })}\n\n`,
|
|
209
|
-
);
|
|
210
|
-
req.logger.info(methodName, "step: elaborate");
|
|
211
|
-
},
|
|
212
|
-
agentRequestOptions: {
|
|
213
|
-
llm,
|
|
214
|
-
modelName,
|
|
215
|
-
thinking,
|
|
216
|
-
get messages() {
|
|
217
|
-
return [
|
|
218
|
-
{
|
|
219
|
-
role: "user",
|
|
220
|
-
content: prompts.ELABORATE_PROMPT.replace(
|
|
221
|
-
"{input}",
|
|
222
|
-
decision.description,
|
|
223
|
-
).replace("{diagramType}", decision.diagramType),
|
|
224
|
-
},
|
|
225
|
-
];
|
|
226
|
-
},
|
|
227
|
-
},
|
|
228
|
-
agentEndCallback: (result) => {
|
|
229
|
-
elaboration = result;
|
|
230
|
-
req.logger.info(
|
|
231
|
-
methodName,
|
|
232
|
-
"elaboration",
|
|
233
|
-
String(elaboration).slice(0, 100) + "...",
|
|
234
|
-
);
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
// generate
|
|
238
|
-
{
|
|
239
|
-
agentStartCallback: () => {
|
|
240
|
-
res.streaming(
|
|
241
|
-
`data: ${JSON.stringify({ type: "status", step: "generate" })}\n\n`,
|
|
242
|
-
);
|
|
243
|
-
req.logger.info(methodName, "step: generate");
|
|
244
|
-
},
|
|
245
|
-
agentRequestOptions: {
|
|
246
|
-
llm,
|
|
247
|
-
modelName,
|
|
248
|
-
thinking,
|
|
249
|
-
get messages() {
|
|
250
|
-
return [
|
|
251
|
-
{
|
|
252
|
-
role: "user",
|
|
253
|
-
content: prompts.GENERATE_PROMPT.replace(
|
|
254
|
-
"{diagramType}",
|
|
255
|
-
decision.diagramType,
|
|
256
|
-
).replace("{elaboration}", elaboration),
|
|
257
|
-
},
|
|
258
|
-
];
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
agentEndCallback: (result) => {
|
|
262
|
-
const mermaidCode = result;
|
|
263
|
-
const duration = Date.now() - startTime;
|
|
264
|
-
req.logger.info(
|
|
265
|
-
methodName,
|
|
266
|
-
"mermaidCode",
|
|
267
|
-
String(mermaidCode).slice(0, 100) + "...",
|
|
268
|
-
`total: ${duration}ms`,
|
|
269
|
-
);
|
|
270
|
-
chatFeishuMsg(req, `mermaid-${mermaidCode}`);
|
|
271
|
-
res.streaming(
|
|
272
|
-
`data: ${JSON.stringify({ type: "mermaid", code: mermaidCode, duration })}\n\n`,
|
|
273
|
-
);
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
]);
|
|
277
|
-
};
|
|
278
|
-
|
|
279
198
|
// 1. Agent 决策
|
|
280
199
|
res.streaming(
|
|
281
200
|
`data: ${JSON.stringify({ type: "status", step: "thinking" })}\n\n`,
|
|
@@ -351,85 +270,82 @@ exports.drawAgent = async (req, res) => {
|
|
|
351
270
|
} else if (decision.action === "irrelevant") {
|
|
352
271
|
res.streaming(`data: ${JSON.stringify({ type: "welcome" })}\n\n`);
|
|
353
272
|
} else if (decision.action === "generate") {
|
|
354
|
-
|
|
355
|
-
const relayConfig = global.QZ_CONFIG.relay;
|
|
356
|
-
const useDocker = relayConfig?.wsUrl;
|
|
357
|
-
|
|
358
|
-
if (useDocker) {
|
|
359
|
-
try {
|
|
360
|
-
req.logger.info(methodName, "using Docker mode via relay");
|
|
361
|
-
res.streaming(
|
|
362
|
-
`data: ${JSON.stringify({ type: "status", step: "docker" })}\n\n`,
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
// SSE keepalive 防超时
|
|
366
|
-
const keepalive = setInterval(() => {
|
|
367
|
-
res.streaming(": keepalive\n\n");
|
|
368
|
-
}, 15000);
|
|
369
|
-
|
|
370
|
-
const result = await sendPromptViaRelay({
|
|
371
|
-
wsUrl: relayConfig.wsUrl,
|
|
372
|
-
authSecret: relayConfig.authSecret,
|
|
373
|
-
userId: req.user?.id || "guest",
|
|
374
|
-
prompt: JSON.stringify({ messages }),
|
|
375
|
-
timeout: relayConfig.timeout || 600000,
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
clearInterval(keepalive);
|
|
273
|
+
let elaboration = "";
|
|
379
274
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const replyText = result.slice(7).trim();
|
|
275
|
+
await runAgents([
|
|
276
|
+
// elaborate
|
|
277
|
+
{
|
|
278
|
+
agentStartCallback: () => {
|
|
385
279
|
res.streaming(
|
|
386
|
-
`data: ${JSON.stringify({ type: "
|
|
280
|
+
`data: ${JSON.stringify({ type: "status", step: "elaborate" })}\n\n`,
|
|
387
281
|
);
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
282
|
+
req.logger.info(methodName, "step: elaborate");
|
|
283
|
+
},
|
|
284
|
+
agentRequestOptions: {
|
|
285
|
+
llm,
|
|
286
|
+
modelName,
|
|
287
|
+
thinking,
|
|
288
|
+
get messages() {
|
|
289
|
+
return [
|
|
290
|
+
{
|
|
291
|
+
role: "user",
|
|
292
|
+
content: prompts.ELABORATE_PROMPT.replace(
|
|
293
|
+
"{input}",
|
|
294
|
+
decision.description,
|
|
295
|
+
).replace("{diagramType}", decision.diagramType),
|
|
296
|
+
},
|
|
297
|
+
];
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
agentEndCallback: (result) => {
|
|
301
|
+
elaboration = result;
|
|
302
|
+
req.logger.info(
|
|
303
|
+
methodName,
|
|
304
|
+
"elaboration",
|
|
305
|
+
String(elaboration).slice(0, 100) + "...",
|
|
306
|
+
);
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
// generate
|
|
310
|
+
{
|
|
311
|
+
agentStartCallback: () => {
|
|
312
|
+
res.streaming(
|
|
313
|
+
`data: ${JSON.stringify({ type: "status", step: "generate" })}\n\n`,
|
|
314
|
+
);
|
|
315
|
+
req.logger.info(methodName, "step: generate");
|
|
316
|
+
},
|
|
317
|
+
agentRequestOptions: {
|
|
318
|
+
llm,
|
|
319
|
+
modelName,
|
|
320
|
+
thinking,
|
|
321
|
+
get messages() {
|
|
322
|
+
return [
|
|
323
|
+
{
|
|
324
|
+
role: "user",
|
|
325
|
+
content: prompts.GENERATE_PROMPT.replace(
|
|
326
|
+
"{diagramType}",
|
|
327
|
+
decision.diagramType,
|
|
328
|
+
).replace("{elaboration}", elaboration),
|
|
329
|
+
},
|
|
330
|
+
];
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
agentEndCallback: (result) => {
|
|
334
|
+
const mermaidCode = result;
|
|
335
|
+
const duration = Date.now() - startTime;
|
|
336
|
+
req.logger.info(
|
|
337
|
+
methodName,
|
|
338
|
+
"mermaidCode",
|
|
339
|
+
String(mermaidCode).slice(0, 100) + "...",
|
|
340
|
+
`total: ${duration}ms`,
|
|
341
|
+
);
|
|
342
|
+
chatFeishuMsg(req, `mermaid-${mermaidCode}`);
|
|
343
|
+
res.streaming(
|
|
344
|
+
`data: ${JSON.stringify({ type: "mermaid", code: mermaidCode, duration })}\n\n`,
|
|
345
|
+
);
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
]);
|
|
433
349
|
} else if (decision.action === "canvas") {
|
|
434
350
|
// 3. Canvas - Function Calling 直接画图
|
|
435
351
|
res.streaming(
|