@shun-js/aibaiban-server 1.1.8 → 1.2.0

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.1.8",
3
+ "version": "1.2.0",
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": "4b29e10a1051e2364ccd96f6f74daba34f49a7e4"
48
+ "gitHead": "7b094023fede487784f42ca71277997906841cb1"
49
49
  }
@@ -12,6 +12,44 @@ const llm = OpenAIAPI(finalLLMConfig);
12
12
  const modelName = finalLLMConfig.modelName;
13
13
  const thinking = finalLLMConfig.thinking;
14
14
 
15
+ /**
16
+ * 从 LLM 返回文本中提取 JSON(兼容 markdown 代码块、前后有多余文字等情况)
17
+ */
18
+ function extractJSON(text) {
19
+ if (typeof text === 'object' && text !== null) return text;
20
+ const str = String(text).trim();
21
+
22
+ // 1. 尝试直接解析
23
+ try {
24
+ return JSON.parse(str);
25
+ } catch (_) {
26
+ /* ignore */
27
+ }
28
+
29
+ // 2. 尝试从 markdown 代码块提取
30
+ const codeBlockMatch = str.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
31
+ if (codeBlockMatch) {
32
+ try {
33
+ return JSON.parse(codeBlockMatch[1].trim());
34
+ } catch (_) {
35
+ /* ignore */
36
+ }
37
+ }
38
+
39
+ // 3. 尝试提取第一个 {...} 块
40
+ const firstBrace = str.indexOf('{');
41
+ const lastBrace = str.lastIndexOf('}');
42
+ if (firstBrace !== -1 && lastBrace > firstBrace) {
43
+ try {
44
+ return JSON.parse(str.slice(firstBrace, lastBrace + 1));
45
+ } catch (_) {
46
+ /* ignore */
47
+ }
48
+ }
49
+
50
+ throw new Error(`Cannot parse JSON from LLM response: ${str.slice(0, 200)}`);
51
+ }
52
+
15
53
  /**
16
54
  * drawAgentV2 - 对话式 Agent
17
55
  * 1 次决策 LLM → reply / generate(elaborate+generate) / irrelevant
@@ -50,11 +88,10 @@ exports.drawAgent = async (req, res) => {
50
88
  llm,
51
89
  modelName,
52
90
  thinking,
53
- isJson: true,
54
91
  messages: [{ role: 'system', content: prompts.AGENT_PROMPT }, ...messages],
55
92
  },
56
93
  agentEndCallback: (result) => {
57
- decision = result;
94
+ decision = extractJSON(result);
58
95
  const duration = Date.now() - startTime;
59
96
  req.logger.info(methodName, 'decision', JSON.stringify(decision), `${duration}ms`);
60
97
  chatFeishuMsg(req, `v2-decision-${decision.action}`);
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-DOG-SsSX.js"
108
+ src="https://static-small.vincentqiao.com/aibaiban/static/index-BaMP5IJA.js"
109
109
  ></script>
110
110
  <link
111
111
  rel="modulepreload"
@@ -130,7 +130,7 @@
130
130
  <link
131
131
  rel="modulepreload"
132
132
  crossorigin
133
- href="https://static-small.vincentqiao.com/aibaiban/static/chunks/excalidraw-2a4_XeZV.js"
133
+ href="https://static-small.vincentqiao.com/aibaiban/static/chunks/excalidraw-7ypewro4.js"
134
134
  />
135
135
  <link
136
136
  rel="stylesheet"