@shun-js/aibaiban-server 1.4.2 → 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.2",
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": "b7519073e9eca8171a0b54a5039901f1be1bb2e9"
49
+ "gitHead": "9d4e0bbc0f78fe5d2fcd8eb17549f5beda097c7e"
50
50
  }
@@ -52,29 +52,28 @@ exports.drawCC = async (req, res) => {
52
52
  clearInterval(keepalive);
53
53
  const duration = Date.now() - startTime;
54
54
 
55
- // 解析 Claude Code 返回结果
56
- try {
57
- const data = JSON.parse(result);
58
- if (data.type === "excalidraw" && data.elements) {
59
- req.logger.info(
60
- methodName,
61
- "excalidraw elements",
62
- data.elements.length,
63
- `${duration}ms`,
64
- );
65
- chatFeishuMsg(req, `cc-excalidraw-${data.elements.length}-elements`);
66
- res.streaming(
67
- `data: ${JSON.stringify({ type: "draw", elements: data.elements, duration })}\n\n`,
68
- );
69
- } else {
70
- res.streaming(
71
- `data: ${JSON.stringify({ type: "message", content: result })}\n\n`,
72
- );
73
- }
74
- } catch {
75
- // 非 JSON,当文字回复
55
+ // 解析 Claude Code 返回结果:[MERMAID]、[REPLY]、[IRRELEVANT] 前缀
56
+ const trimmed = result.trim();
57
+
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`,
69
+ );
70
+ } else if (trimmed === "[IRRELEVANT]") {
71
+ res.streaming(
72
+ `data: ${JSON.stringify({ type: "welcome", duration })}\n\n`,
73
+ );
74
+ } else {
76
75
  res.streaming(
77
- `data: ${JSON.stringify({ type: "message", content: result })}\n\n`,
76
+ `data: ${JSON.stringify({ type: "message", content: trimmed, duration })}\n\n`,
78
77
  );
79
78
  }
80
79