@shun-js/aibaiban-server 1.4.1 → 1.4.2

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/app.js CHANGED
@@ -1,12 +1,12 @@
1
1
  // config
2
- const { parseServerConfig } = require('@shun-js/shun-config');
2
+ const { parseServerConfig } = require("@shun-js/shun-config");
3
3
 
4
4
  // init
5
5
  (async () => {
6
6
  // config
7
7
  const config = await parseServerConfig(process.argv);
8
8
  if (!config) {
9
- console.log('read server config fail');
9
+ console.log("read server config fail");
10
10
  return;
11
11
  }
12
12
 
@@ -20,23 +20,23 @@ const { parseServerConfig } = require('@shun-js/shun-config');
20
20
  options.config = config;
21
21
 
22
22
  // options.redis
23
- options.redis = require('qiao-redis');
23
+ options.redis = require("qiao-redis");
24
24
  options.redisOptions = config.redisOptions;
25
25
 
26
26
  // options log
27
- options.log = require('qiao-log');
28
- options.logOptions = require('./server/log-options.js')();
27
+ options.log = require("qiao-log");
28
+ options.logOptions = require("./server/log-options.js")();
29
29
 
30
30
  // options rate limit
31
- options.rateLimitLib = require('qiao-rate-limit');
31
+ options.rateLimitLib = require("qiao-rate-limit");
32
32
  options.rateLimitOptions = config.rateLimitOptions;
33
33
 
34
34
  // options checks
35
- options.checks = [require('./server/util/check.js').checkUserAuth];
35
+ options.checks = [require("./server/util/check.js").checkUserAuth];
36
36
 
37
37
  // options modules
38
- options.modules = [require('qiao-z-sms').init, require('qiao-z-nuser').init];
38
+ options.modules = [require("qiao-z-sms").init, require("qiao-z-nuser").init];
39
39
 
40
- const app = await require('qiao-z')(options);
40
+ const app = await require("qiao-z")(options);
41
41
  app.listen(config.port);
42
42
  })();
package/assets/sw.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Service Worker - 仅用于满足 PWA 安装条件
2
- self.addEventListener('install', () => self.skipWaiting());
3
- self.addEventListener('activate', (e) => e.waitUntil(self.clients.claim()));
2
+ self.addEventListener("install", () => self.skipWaiting());
3
+ self.addEventListener("activate", (e) => e.waitUntil(self.clients.claim()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shun-js/aibaiban-server",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "aibaiban.com server",
5
5
  "keywords": [
6
6
  "ai aibaiban"
@@ -38,6 +38,7 @@
38
38
  "qiao-z-service": "^6.0.0",
39
39
  "qiao-z-sms": "^6.0.0",
40
40
  "viho-llm": "^1.1.0",
41
+ "ws": "^8.20.0",
41
42
  "zod": "^4.3.6",
42
43
  "zod-to-json-schema": "^3.25.1"
43
44
  },
@@ -45,5 +46,5 @@
45
46
  "access": "public",
46
47
  "registry": "https://registry.npmjs.org/"
47
48
  },
48
- "gitHead": "31816288306545bca83a6378d28bcb10109b5365"
49
+ "gitHead": "b7519073e9eca8171a0b54a5039901f1be1bb2e9"
49
50
  }
@@ -1,12 +1,12 @@
1
1
  // service
2
- const service = require('../service/IndexService.js');
2
+ const service = require("../service/IndexService.js");
3
3
 
4
4
  /**
5
5
  * controller
6
6
  */
7
7
  module.exports = (app) => {
8
8
  // index
9
- app.get('/', (req, res) => {
9
+ app.get("/", (req, res) => {
10
10
  service.index(req, res);
11
11
  });
12
12
  };
@@ -1,12 +1,18 @@
1
1
  // service
2
- const service = require('../service/LLMService.js');
2
+ const service = require("../service/LLMService.js");
3
+ const ccService = require("../service/CCService.js");
3
4
 
4
5
  /**
5
6
  * controller
6
7
  */
7
8
  module.exports = (app) => {
8
9
  // draw agent
9
- app.post('/draw-agent', (req, res) => {
10
+ app.post("/draw-agent", (req, res) => {
10
11
  service.drawAgent(req, res);
11
12
  });
13
+
14
+ // draw cc (Claude Code via Docker)
15
+ app.post("/draw-cc", (req, res) => {
16
+ ccService.drawCC(req, res);
17
+ });
12
18
  };
@@ -1,32 +1,32 @@
1
1
  // service
2
- const service = require('../service/SEOService.js');
2
+ const service = require("../service/SEOService.js");
3
3
 
4
4
  /**
5
5
  * controller
6
6
  */
7
7
  module.exports = (app) => {
8
8
  // seo
9
- app.get('/robots.txt', (req, res) => {
9
+ app.get("/robots.txt", (req, res) => {
10
10
  service.robots(req, res);
11
11
  });
12
- app.get('/sitemap.xml', (req, res) => {
12
+ app.get("/sitemap.xml", (req, res) => {
13
13
  service.sitemap(req, res);
14
14
  });
15
- app.get('/4cb288d7aef5469c92616c0f5b5aeb89.txt', (req, res) => {
15
+ app.get("/4cb288d7aef5469c92616c0f5b5aeb89.txt", (req, res) => {
16
16
  service.bingIndexNow(req, res);
17
17
  });
18
18
 
19
19
  // pwa
20
- app.get('/manifest.json', (req, res) => {
20
+ app.get("/manifest.json", (req, res) => {
21
21
  service.manifestJson(req, res);
22
22
  });
23
- app.get('/sw.js', (req, res) => {
23
+ app.get("/sw.js", (req, res) => {
24
24
  service.swJs(req, res);
25
25
  });
26
- app.get('/icon-192.png', (req, res) => {
26
+ app.get("/icon-192.png", (req, res) => {
27
27
  service.icon192Png(req, res);
28
28
  });
29
- app.get('/icon-512.png', (req, res) => {
29
+ app.get("/icon-512.png", (req, res) => {
30
30
  service.icon512Png(req, res);
31
31
  });
32
32
  };
@@ -4,19 +4,19 @@
4
4
  */
5
5
  module.exports = () => {
6
6
  // log options
7
- const logLevel = 'debug';
8
- const logPattern = 'yyyy-MM-dd-hh';
9
- const logPath = require('path').resolve(__dirname, '../logs/qiao-z.log');
7
+ const logLevel = "debug";
8
+ const logPattern = "yyyy-MM-dd-hh";
9
+ const logPath = require("path").resolve(__dirname, "../logs/qiao-z.log");
10
10
 
11
11
  return {
12
12
  pm2: true,
13
- pm2InstanceVar: 'INSTANCE_ID',
13
+ pm2InstanceVar: "INSTANCE_ID",
14
14
  appenders: {
15
15
  stdout: {
16
- type: 'stdout',
16
+ type: "stdout",
17
17
  },
18
18
  datefile: {
19
- type: 'dateFile',
19
+ type: "dateFile",
20
20
  pattern: logPattern,
21
21
  filename: logPath,
22
22
  keepFileExt: true,
@@ -27,7 +27,7 @@ module.exports = () => {
27
27
  categories: {
28
28
  default: {
29
29
  level: logLevel,
30
- appenders: ['stdout', 'datefile'],
30
+ appenders: ["stdout", "datefile"],
31
31
  },
32
32
  },
33
33
  };
@@ -0,0 +1,94 @@
1
+ const { chatFeishuMsg, errorFeishuMsg } = require("../util/feishu.js");
2
+ const { sendPromptViaRelay } = require("../util/relay-client.js");
3
+
4
+ /**
5
+ * drawCC - Claude Code via Docker
6
+ * 所有请求直接通过 WS relay 发送给 Docker 内的 Claude Code 处理
7
+ */
8
+ exports.drawCC = async (req, res) => {
9
+ const methodName = "drawCC";
10
+ const messages = req.body.messages;
11
+
12
+ if (!messages?.length) {
13
+ const msg = "need messages";
14
+ req.logger.error(methodName, msg);
15
+ res.jsonFail(msg);
16
+ return;
17
+ }
18
+
19
+ const relayConfig = global.QZ_CONFIG.relay;
20
+ if (!relayConfig?.wsUrl) {
21
+ req.logger.error(methodName, "relay config missing");
22
+ res.jsonFail("relay not configured");
23
+ return;
24
+ }
25
+
26
+ res.streamingStart();
27
+
28
+ const lastUserMsg =
29
+ messages.filter((m) => m.role === "user").pop()?.content || "";
30
+ req.logger.info(methodName, "lastUserMsg", lastUserMsg);
31
+ chatFeishuMsg(req, `cc-${lastUserMsg}`);
32
+
33
+ try {
34
+ const startTime = Date.now();
35
+
36
+ res.streaming(
37
+ `data: ${JSON.stringify({ type: "status", step: "thinking" })}\n\n`,
38
+ );
39
+
40
+ const keepalive = setInterval(() => {
41
+ res.streaming(": keepalive\n\n");
42
+ }, 15000);
43
+
44
+ const result = await sendPromptViaRelay({
45
+ wsUrl: relayConfig.wsUrl,
46
+ authSecret: relayConfig.authSecret,
47
+ userId: req.user?.id || "guest",
48
+ prompt: lastUserMsg,
49
+ timeout: relayConfig.timeout || 600000,
50
+ });
51
+
52
+ clearInterval(keepalive);
53
+ const duration = Date.now() - startTime;
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,当文字回复
76
+ res.streaming(
77
+ `data: ${JSON.stringify({ type: "message", content: result })}\n\n`,
78
+ );
79
+ }
80
+
81
+ res.streamingEnd();
82
+ } catch (error) {
83
+ req.logger.error(methodName, "error", error);
84
+ errorFeishuMsg(req, error.message);
85
+ const userMessage =
86
+ error.message === "AI agent is offline"
87
+ ? "AI 助手离线中,请稍后重试"
88
+ : "服务暂时出错,请稍后重试";
89
+ res.streaming(
90
+ `data: ${JSON.stringify({ type: "error", message: userMessage })}\n\n`,
91
+ );
92
+ res.streamingEnd();
93
+ }
94
+ };
@@ -5,7 +5,7 @@
5
5
  */
6
6
  exports.index = async (req, res) => {
7
7
  // const
8
- const pagePath = './views/index.html';
8
+ const pagePath = "./views/index.html";
9
9
 
10
10
  // is static
11
11
  const isStatic = await res.staticRender(pagePath);