@shun-js/aibaiban-server 0.8.8 → 0.8.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shun-js/aibaiban-server",
3
- "version": "0.8.8",
3
+ "version": "0.8.9",
4
4
  "description": "aibaiban.com server",
5
5
  "keywords": [
6
6
  "ai aibaiban"
@@ -44,5 +44,5 @@
44
44
  "access": "public",
45
45
  "registry": "https://registry.npmjs.org/"
46
46
  },
47
- "gitHead": "2ef5979706688cf913a6e74caa24bcfea4143803"
47
+ "gitHead": "b7126491abd4565dd2cdc69e5787579c10265a79"
48
48
  }
@@ -2,6 +2,9 @@
2
2
  const { callLLMForJSON, callLLM } = require('../util/llm-agent.js');
3
3
  const prompts = require('../util/prompt-agent.js');
4
4
 
5
+ // util
6
+ const { chatFeishuMsg, errorFeishuMsg } = require('../util/feishu.js');
7
+
5
8
  /**
6
9
  * drawAgent - 流式 Agent 接口
7
10
  * 流程:router -> classify -> elaborate -> review -> generate
@@ -22,15 +25,18 @@ exports.drawAgent = async (req, res) => {
22
25
 
23
26
  const input = decodeURIComponent(req.body.userPrompt);
24
27
  req.logger.info(methodName, 'userPrompt', input);
28
+ chatFeishuMsg(req, `userPrompt-${input}`);
25
29
 
26
30
  try {
27
- // 1. router - 判断意图
31
+ // start
28
32
  res.streaming(`data: ${JSON.stringify({ step: 'router', status: 'start' })}\n\n`);
29
33
  req.logger.info(methodName, 'step: router');
34
+
35
+ // intent
30
36
  const intentResult = await callLLMForJSON(prompts.ROUTER_PROMPT.replace('{input}', input), res, 'router');
31
37
  const intent = intentResult.intent;
32
38
  req.logger.info(methodName, 'intent', intent);
33
- // 发送结果
39
+ chatFeishuMsg(req, `intent-${intent}`);
34
40
  res.streaming(`data: ${JSON.stringify({ step: 'router', intent })}\n\n`);
35
41
 
36
42
  // 非白板请求
@@ -48,7 +54,7 @@ exports.drawAgent = async (req, res) => {
48
54
  const classifyResult = await callLLMForJSON(prompts.CLASSIFY_PROMPT.replace('{input}', input), res, 'classify');
49
55
  const diagramType = classifyResult.diagramType;
50
56
  req.logger.info(methodName, 'diagramType', diagramType);
51
- // 发送结果
57
+ chatFeishuMsg(req, `diagramType-${diagramType}`);
52
58
  res.streaming(`data: ${JSON.stringify({ step: 'classify', diagramType })}\n\n`);
53
59
 
54
60
  // 3. elaborate - 细化内容
@@ -60,7 +66,7 @@ exports.drawAgent = async (req, res) => {
60
66
  'elaborate',
61
67
  );
62
68
  req.logger.info(methodName, 'elaboration', elaboration.slice(0, 100) + '...');
63
- // 发送结果(不显示内容,只标记完成)
69
+ chatFeishuMsg(req, `elaboration-${elaboration}`);
64
70
  res.streaming(`data: ${JSON.stringify({ step: 'elaborate', done: true })}\n\n`);
65
71
 
66
72
  // 4. review - 质量检查
@@ -74,7 +80,7 @@ exports.drawAgent = async (req, res) => {
74
80
  'review',
75
81
  );
76
82
  req.logger.info(methodName, 'reviewResult', reviewResult);
77
- // 发送结果
83
+ chatFeishuMsg(req, `reviewResult-${reviewResult}`);
78
84
  res.streaming(`data: ${JSON.stringify({ step: 'review', result: reviewResult.result })}\n\n`);
79
85
 
80
86
  // 信息不足,追问用户
@@ -98,14 +104,15 @@ exports.drawAgent = async (req, res) => {
98
104
  res,
99
105
  'generate',
100
106
  );
101
-
102
107
  req.logger.info(methodName, 'mermaidCode', mermaidCode.slice(0, 100) + '...');
108
+ chatFeishuMsg(req, `mermaidCode-${mermaidCode}`);
103
109
 
104
110
  // 返回最终结果
105
111
  res.streaming(`data: ${JSON.stringify({ step: 'generate', mermaidCode })}\n\n`);
106
112
  res.streamingEnd();
107
113
  } catch (error) {
108
114
  req.logger.error(methodName, 'error', error);
115
+ errorFeishuMsg(req, error.message);
109
116
  res.streaming(`data: ${JSON.stringify({ step: 'error', message: error.message })}\n\n`);
110
117
  res.streamingEnd();
111
118
  }
@@ -43,35 +43,17 @@ exports.errorFeishuMsg = (req, msg) => {
43
43
  /**
44
44
  * chatFeishuMsg
45
45
  * @param {*} req
46
+ * @param {*} msg
46
47
  * @returns
47
48
  */
48
- exports.chatFeishuMsg = (req) => {
49
- // check
50
- if (isBot(req)) return;
51
-
52
- // msg
53
- const uaJson = JSON.stringify(req.useragent || {});
54
- const userid = req.headers.userid;
55
- const prompt = decodeURIComponent(req.body.userPrompt);
56
-
57
- const msg = `【通知】/chat被访问\nuserid:${userid}\nua:\n${uaJson}\nprompt:\n${prompt}`;
58
- exports.feishuMsg(msg);
59
- };
60
-
61
- /**
62
- * chatResFeishuMsg
63
- * @param {*} req
64
- * @returns
65
- */
66
- exports.chatResFeishuMsg = (req, chatRes) => {
49
+ exports.chatFeishuMsg = (req, msg) => {
67
50
  // check
68
51
  if (isBot(req)) return;
69
52
 
70
53
  // msg
71
54
  const uaJson = JSON.stringify(req.useragent || {});
72
55
  const userid = req.headers.userid;
73
- const prompt = decodeURIComponent(req.body.userPrompt);
74
56
 
75
- const msg = `【通知】/chat生成成功\nuserid:${userid}\nua:\n${uaJson}\nprompt:\n${prompt}\nres:${chatRes}`;
76
- exports.feishuMsg(msg);
57
+ const finalMsg = `【通知】/chat被访问\nuserid:${userid}\nua:\n${uaJson}\nmsg:\n${msg}`;
58
+ exports.feishuMsg(finalMsg);
77
59
  };