@shun-js/aibaiban-server 1.4.2 → 1.4.3
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/CCService.js +34 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shun-js/aibaiban-server",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
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": "
|
|
49
|
+
"gitHead": "a07951954c905f106f4bbec45d23b133a73d15dd"
|
|
50
50
|
}
|
|
@@ -53,26 +53,43 @@ exports.drawCC = async (req, res) => {
|
|
|
53
53
|
const duration = Date.now() - startTime;
|
|
54
54
|
|
|
55
55
|
// 解析 Claude Code 返回结果
|
|
56
|
+
// Claude Code 可能返回:纯 JSON、markdown 包裹的 JSON、或普通文本
|
|
57
|
+
let parsed = null;
|
|
56
58
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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;
|
|
73
75
|
}
|
|
74
76
|
} catch {
|
|
75
|
-
// 非 JSON
|
|
77
|
+
// 非 excalidraw JSON
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (parsed) {
|
|
81
|
+
req.logger.info(
|
|
82
|
+
methodName,
|
|
83
|
+
"excalidraw elements",
|
|
84
|
+
parsed.elements.length,
|
|
85
|
+
`${duration}ms`,
|
|
86
|
+
);
|
|
87
|
+
chatFeishuMsg(req, `cc-excalidraw-${parsed.elements.length}-elements`);
|
|
88
|
+
res.streaming(`data: ${JSON.stringify({ type: "clear" })}\n\n`);
|
|
89
|
+
res.streaming(
|
|
90
|
+
`data: ${JSON.stringify({ type: "draw", elements: parsed.elements, duration })}\n\n`,
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
76
93
|
res.streaming(
|
|
77
94
|
`data: ${JSON.stringify({ type: "message", content: result })}\n\n`,
|
|
78
95
|
);
|