@shun-js/aibaiban-server 1.2.4 → 1.2.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/LLMService.js +45 -21
- package/server/util/prompt-agent.js +5 -8
- package/views/index.html +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shun-js/aibaiban-server",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
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": "
|
|
48
|
+
"gitHead": "66c933a20f3e0b055d9e414c0651acd821e6a320"
|
|
49
49
|
}
|
|
@@ -171,32 +171,52 @@ exports.drawAgent = async (req, res) => {
|
|
|
171
171
|
res.streaming(`data: ${JSON.stringify({ type: 'status', step: 'thinking' })}\n\n`);
|
|
172
172
|
|
|
173
173
|
let decision = null;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
174
|
+
try {
|
|
175
|
+
await runAgents([
|
|
176
|
+
{
|
|
177
|
+
agentStartCallback: () => {
|
|
178
|
+
req.logger.info(methodName, 'step: agent decision');
|
|
179
|
+
},
|
|
180
|
+
agentRequestOptions: {
|
|
181
|
+
llm,
|
|
182
|
+
modelName,
|
|
183
|
+
thinking,
|
|
184
|
+
isJson: true,
|
|
185
|
+
messages: [{ role: 'system', content: prompts.AGENT_PROMPT }, ...messages],
|
|
186
|
+
},
|
|
187
|
+
agentEndCallback: (result) => {
|
|
188
|
+
decision = result;
|
|
189
|
+
const duration = Date.now() - startTime;
|
|
190
|
+
req.logger.info(methodName, 'decision', JSON.stringify(decision), `${duration}ms`);
|
|
191
|
+
chatFeishuMsg(req, `decision-${decision.action}`);
|
|
192
|
+
},
|
|
191
193
|
},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
]);
|
|
195
|
+
} catch (jsonErr) {
|
|
196
|
+
// LLM 未返回 JSON,兜底为 reply
|
|
197
|
+
req.logger.warn(methodName, 'JSON parse fallback', jsonErr.message);
|
|
198
|
+
const rawText = jsonErr.message.replace('Cannot parse JSON from LLM response:', '').trim();
|
|
199
|
+
req.logger.info(methodName, 'LLM raw response', rawText);
|
|
200
|
+
|
|
201
|
+
// 尝试从原始文本中提取 JSON(LLM 可能在 JSON 前后加了多余文字)
|
|
202
|
+
const jsonMatch = rawText.match(/\{[\s\S]*\}/);
|
|
203
|
+
if (jsonMatch) {
|
|
204
|
+
try {
|
|
205
|
+
decision = JSON.parse(jsonMatch[0]);
|
|
206
|
+
req.logger.info(methodName, 'extracted JSON from raw text', JSON.stringify(decision));
|
|
207
|
+
} catch {
|
|
208
|
+
decision = { action: 'reply', message: '好的,请告诉我你想画什么图表?' };
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
decision = { action: 'reply', message: '好的,请告诉我你想画什么图表?' };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
194
214
|
|
|
195
215
|
// 2. 分发
|
|
196
216
|
if (decision.action === 'reply') {
|
|
197
217
|
res.streaming(`data: ${JSON.stringify({ type: 'message', content: decision.message })}\n\n`);
|
|
198
218
|
} else if (decision.action === 'irrelevant') {
|
|
199
|
-
res.streaming(`data: ${JSON.stringify({ type: '
|
|
219
|
+
res.streaming(`data: ${JSON.stringify({ type: 'welcome' })}\n\n`);
|
|
200
220
|
} else if (decision.action === 'generate') {
|
|
201
221
|
let elaboration = '';
|
|
202
222
|
|
|
@@ -312,7 +332,11 @@ exports.drawAgent = async (req, res) => {
|
|
|
312
332
|
} catch (error) {
|
|
313
333
|
req.logger.error(methodName, 'error', error);
|
|
314
334
|
errorFeishuMsg(req, error.message);
|
|
315
|
-
|
|
335
|
+
// 对用户隐藏内部错误细节
|
|
336
|
+
const userMessage = error.message?.includes('Cannot parse JSON')
|
|
337
|
+
? '请求处理失败,请重新描述你的需求'
|
|
338
|
+
: '服务暂时出错,请稍后重试';
|
|
339
|
+
res.streaming(`data: ${JSON.stringify({ type: 'error', message: userMessage })}\n\n`);
|
|
316
340
|
res.streamingEnd();
|
|
317
341
|
}
|
|
318
342
|
};
|
|
@@ -45,7 +45,10 @@ module.exports = {
|
|
|
45
45
|
- generate 时 description 要尽可能详细完整
|
|
46
46
|
- canvas 时 description 要包含形状、颜色、位置等用户提到的所有细节
|
|
47
47
|
|
|
48
|
-
|
|
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
|
-
|
|
68
|
+
严格要求:你的回复必须是且仅是一个合法的 JSON 对象,不要包含任何其他文字、解释或 markdown 标记。`,
|
|
66
69
|
|
|
67
70
|
/**
|
|
68
71
|
* Mermaid 生成
|
|
@@ -104,12 +107,6 @@ flowchart TD
|
|
|
104
107
|
|
|
105
108
|
只回复 Mermaid 代码,不要包含 \`\`\`mermaid 标记。`,
|
|
106
109
|
|
|
107
|
-
/**
|
|
108
|
-
* 非白板请求的固定回复
|
|
109
|
-
*/
|
|
110
|
-
FIXED_REPLY:
|
|
111
|
-
'你好!👋 我是 AI 白板助手,支持以下功能:\n\n📊 流程图 — 例如"画一个用户注册登录的流程图"\n🔄 时序图 — 例如"画一个用户下单支付的时序图"\n🏗️ 类图 — 例如"画一个电商系统的类图"\n🗄️ ER图 — 例如"画一个博客系统的ER图"\n🎨 自由绘图 — 例如"画一个红色的圆"、"画两个矩形用箭头连接"\n\n💡 试试直接输入你的需求吧!',
|
|
112
|
-
|
|
113
110
|
/**
|
|
114
111
|
* Canvas Function Calling 系统提示词
|
|
115
112
|
*/
|
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-
|
|
108
|
+
src="https://static-small.vincentqiao.com/aibaiban/static/index-DCJwq4XN.js"
|
|
109
109
|
></script>
|
|
110
110
|
<link
|
|
111
111
|
rel="modulepreload"
|