@shun-js/aibaiban-server 1.2.5 → 1.2.7

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": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "aibaiban.com server",
5
5
  "keywords": [
6
6
  "ai aibaiban"
@@ -45,5 +45,5 @@
45
45
  "access": "public",
46
46
  "registry": "https://registry.npmjs.org/"
47
47
  },
48
- "gitHead": "1f7c6983686ef774df53ad8aa2ec452ec439d8e9"
48
+ "gitHead": "7f2b401901bcf0070e9349fab5e18b8a7c8484ee"
49
49
  }
@@ -164,6 +164,14 @@ exports.drawAgent = async (req, res) => {
164
164
  req.logger.info(methodName, 'lastUserMsg', lastUserMsg);
165
165
  chatFeishuMsg(req, `${lastUserMsg}`);
166
166
 
167
+ // 清洗对话历史:将前端确认文案替换为简短标记,避免 LLM 模仿自然语言回复
168
+ const cleanedMessages = messages.map((m) => {
169
+ if (m.role === 'assistant' && /^[✅❌]/.test(m.content)) {
170
+ return { ...m, content: '[已执行]' };
171
+ }
172
+ return m;
173
+ });
174
+
167
175
  try {
168
176
  const startTime = Date.now();
169
177
 
@@ -171,26 +179,46 @@ exports.drawAgent = async (req, res) => {
171
179
  res.streaming(`data: ${JSON.stringify({ type: 'status', step: 'thinking' })}\n\n`);
172
180
 
173
181
  let decision = null;
174
- await runAgents([
175
- {
176
- agentStartCallback: () => {
177
- req.logger.info(methodName, 'step: agent decision');
178
- },
179
- agentRequestOptions: {
180
- llm,
181
- modelName,
182
- thinking,
183
- isJson: true,
184
- messages: [{ role: 'system', content: prompts.AGENT_PROMPT }, ...messages],
185
- },
186
- agentEndCallback: (result) => {
187
- decision = result;
188
- const duration = Date.now() - startTime;
189
- req.logger.info(methodName, 'decision', JSON.stringify(decision), `${duration}ms`);
190
- chatFeishuMsg(req, `decision-${decision.action}`);
182
+ try {
183
+ await runAgents([
184
+ {
185
+ agentStartCallback: () => {
186
+ req.logger.info(methodName, 'step: agent decision');
187
+ },
188
+ agentRequestOptions: {
189
+ llm,
190
+ modelName,
191
+ thinking,
192
+ isJson: true,
193
+ messages: [{ role: 'system', content: prompts.AGENT_PROMPT }, ...cleanedMessages],
194
+ },
195
+ agentEndCallback: (result) => {
196
+ decision = result;
197
+ const duration = Date.now() - startTime;
198
+ req.logger.info(methodName, 'decision', JSON.stringify(decision), `${duration}ms`);
199
+ chatFeishuMsg(req, `decision-${decision.action}`);
200
+ },
191
201
  },
192
- },
193
- ]);
202
+ ]);
203
+ } catch (jsonErr) {
204
+ // LLM 未返回 JSON,兜底为 reply
205
+ req.logger.warn(methodName, 'JSON parse fallback', jsonErr.message);
206
+ const rawText = jsonErr.message.replace('Cannot parse JSON from LLM response:', '').trim();
207
+ req.logger.info(methodName, 'LLM raw response', rawText);
208
+
209
+ // 尝试从原始文本中提取 JSON(LLM 可能在 JSON 前后加了多余文字)
210
+ const jsonMatch = rawText.match(/\{[\s\S]*\}/);
211
+ if (jsonMatch) {
212
+ try {
213
+ decision = JSON.parse(jsonMatch[0]);
214
+ req.logger.info(methodName, 'extracted JSON from raw text', JSON.stringify(decision));
215
+ } catch {
216
+ decision = { action: 'reply', message: '好的,请告诉我你想画什么图表?' };
217
+ }
218
+ } else {
219
+ decision = { action: 'reply', message: '好的,请告诉我你想画什么图表?' };
220
+ }
221
+ }
194
222
 
195
223
  // 2. 分发
196
224
  if (decision.action === 'reply') {
@@ -312,7 +340,11 @@ exports.drawAgent = async (req, res) => {
312
340
  } catch (error) {
313
341
  req.logger.error(methodName, 'error', error);
314
342
  errorFeishuMsg(req, error.message);
315
- res.streaming(`data: ${JSON.stringify({ type: 'error', message: error.message })}\n\n`);
343
+ // 对用户隐藏内部错误细节
344
+ const userMessage = error.message?.includes('Cannot parse JSON')
345
+ ? '请求处理失败,请重新描述你的需求'
346
+ : '服务暂时出错,请稍后重试';
347
+ res.streaming(`data: ${JSON.stringify({ type: 'error', message: userMessage })}\n\n`);
316
348
  res.streamingEnd();
317
349
  }
318
350
  };
@@ -45,7 +45,10 @@ module.exports = {
45
45
  - generate 时 description 要尽可能详细完整
46
46
  - canvas 时 description 要包含形状、颜色、位置等用户提到的所有细节
47
47
 
48
- 只回复 JSON。`,
48
+ 严格要求:
49
+ 1. 你的回复必须是且仅是一个合法的 JSON 对象,不要包含任何其他文字、解释或 markdown 标记。
50
+ 2. 每条用户消息都是独立的新请求,即使对话历史中有之前生成过图表的记录,也要重新判断当前消息的意图。
51
+ 3. 永远不要回复"已生成"、"已完成"之类的文字,你只负责决策,不负责执行。`,
49
52
 
50
53
  /**
51
54
  * 图表内容细化
@@ -62,7 +65,7 @@ module.exports = {
62
65
  - classDiagram: {"classes": [{"name": "", "attributes": [...], "methods": [...]}], "relations": [...]}
63
66
  - erDiagram: {"entities": [{"name": "", "attributes": [...]}], "relations": [...]}
64
67
 
65
- 只回复 JSON。`,
68
+ 严格要求:你的回复必须是且仅是一个合法的 JSON 对象,不要包含任何其他文字、解释或 markdown 标记。`,
66
69
 
67
70
  /**
68
71
  * Mermaid 生成
package/views/index.html CHANGED
@@ -105,7 +105,7 @@
105
105
  <script
106
106
  type="module"
107
107
  crossorigin
108
- src="https://static-small.vincentqiao.com/aibaiban/static/index-DCJwq4XN.js"
108
+ src="https://static-small.vincentqiao.com/aibaiban/static/index-BKiaaj_x.js"
109
109
  ></script>
110
110
  <link
111
111
  rel="modulepreload"