@shun-js/aibaiban-server 1.4.3 → 1.4.4

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.4.3",
3
+ "version": "1.4.4",
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": "a07951954c905f106f4bbec45d23b133a73d15dd"
49
+ "gitHead": "9d4e0bbc0f78fe5d2fcd8eb17549f5beda097c7e"
50
50
  }
@@ -52,46 +52,28 @@ exports.drawCC = async (req, res) => {
52
52
  clearInterval(keepalive);
53
53
  const duration = Date.now() - startTime;
54
54
 
55
- // 解析 Claude Code 返回结果
56
- // Claude Code 可能返回:纯 JSON、markdown 包裹的 JSON、或普通文本
57
- let parsed = null;
58
- try {
59
- let raw = result;
60
- // 剥离 markdown 代码块: ```json\n...\n```
61
- const fenceMatch = raw.match(/```(?:json)?\s*\n([\s\S]*?)\n```/);
62
- if (fenceMatch) {
63
- raw = fenceMatch[1].trim();
64
- }
65
- // 处理可能的双重 JSON 编码
66
- let decoded = raw;
67
- if (typeof decoded === "string") {
68
- decoded = JSON.parse(decoded);
69
- }
70
- if (typeof decoded === "string") {
71
- decoded = JSON.parse(decoded);
72
- }
73
- if (decoded && decoded.type === "excalidraw" && decoded.elements) {
74
- parsed = decoded;
75
- }
76
- } catch {
77
- // 非 excalidraw JSON
78
- }
55
+ // 解析 Claude Code 返回结果:[MERMAID]、[REPLY]、[IRRELEVANT] 前缀
56
+ const trimmed = result.trim();
79
57
 
80
- if (parsed) {
81
- req.logger.info(
82
- methodName,
83
- "excalidraw elements",
84
- parsed.elements.length,
85
- `${duration}ms`,
58
+ if (trimmed.startsWith("[MERMAID]")) {
59
+ const code = trimmed.slice("[MERMAID]".length).trim();
60
+ req.logger.info(methodName, "mermaid", code.length, `${duration}ms`);
61
+ chatFeishuMsg(req, `cc-mermaid-${code.length}chars`);
62
+ res.streaming(
63
+ `data: ${JSON.stringify({ type: "mermaid", code, duration })}\n\n`,
64
+ );
65
+ } else if (trimmed.startsWith("[REPLY] ")) {
66
+ const content = trimmed.slice("[REPLY] ".length);
67
+ res.streaming(
68
+ `data: ${JSON.stringify({ type: "message", content, duration })}\n\n`,
86
69
  );
87
- chatFeishuMsg(req, `cc-excalidraw-${parsed.elements.length}-elements`);
88
- res.streaming(`data: ${JSON.stringify({ type: "clear" })}\n\n`);
70
+ } else if (trimmed === "[IRRELEVANT]") {
89
71
  res.streaming(
90
- `data: ${JSON.stringify({ type: "draw", elements: parsed.elements, duration })}\n\n`,
72
+ `data: ${JSON.stringify({ type: "welcome", duration })}\n\n`,
91
73
  );
92
74
  } else {
93
75
  res.streaming(
94
- `data: ${JSON.stringify({ type: "message", content: result })}\n\n`,
76
+ `data: ${JSON.stringify({ type: "message", content: trimmed, duration })}\n\n`,
95
77
  );
96
78
  }
97
79