@kevisual/cnb 0.0.10 → 0.0.13

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": "@kevisual/cnb",
3
- "version": "0.0.10",
3
+ "version": "0.0.13",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -25,17 +25,22 @@
25
25
  "@types/bun": "^1.3.8",
26
26
  "@types/node": "^25.1.0",
27
27
  "@types/ws": "^8.18.1",
28
+ "dayjs": "^1.11.19",
28
29
  "dotenv": "^17.2.3"
29
30
  },
30
31
  "publishConfig": {
31
32
  "access": "public"
32
33
  },
34
+ "resolutions": {
35
+ "zod": "^4.3.6"
36
+ },
33
37
  "dependencies": {
34
38
  "@kevisual/query": "^0.0.38",
35
- "@kevisual/router": "^0.0.63",
39
+ "@kevisual/router": "^0.0.64",
36
40
  "@kevisual/use-config": "^1.0.28",
37
41
  "es-toolkit": "^1.44.0",
38
42
  "nanoid": "^5.1.6",
43
+ "unstorage": "^1.17.4",
39
44
  "ws": "npm:@kevisual/ws",
40
45
  "zod": "^4.3.6"
41
46
  },
@@ -43,6 +48,7 @@
43
48
  ".": "./mod.ts",
44
49
  "./opencode": "./dist/opencode.js",
45
50
  "./keep": "./dist/keep.js",
51
+ "./routes": "./dist/routes.js",
46
52
  "./src/*": "./src/*",
47
53
  "./agent/*": "./agent/*"
48
54
  }
@@ -12,6 +12,7 @@ export interface KeepAliveConfig {
12
12
  onDisconnect?: (code: number) => void;
13
13
  onError?: (error: Error) => void;
14
14
  onSign?: (data: { type: string; data: string; signedData: string }) => void;
15
+ onExit?: (code?: number) => void;
15
16
  debug?: boolean;
16
17
  }
17
18
 
@@ -38,11 +39,12 @@ export class WSKeepAlive {
38
39
  reconnectInterval: config.reconnectInterval ?? 5000,
39
40
  maxReconnectAttempts: config.maxReconnectAttempts ?? 3,
40
41
  pingInterval: config.pingInterval ?? 30000,
41
- onMessage: config.onMessage ?? (() => {}),
42
- onConnect: config.onConnect ?? (() => {}),
43
- onDisconnect: config.onDisconnect ?? (() => {}),
44
- onError: config.onError ?? (() => {}),
45
- onSign: config.onSign ?? (() => {}),
42
+ onMessage: config.onMessage ?? (() => { }),
43
+ onConnect: config.onConnect ?? (() => { }),
44
+ onDisconnect: config.onDisconnect ?? (() => { }),
45
+ onError: config.onError ?? (() => { }),
46
+ onSign: config.onSign ?? (() => { }),
47
+ onExit: config.onExit ?? (() => { }),
46
48
  debug: config.debug ?? false,
47
49
  };
48
50
  this.url = new URL(this.config.wsUrl);
@@ -158,6 +160,7 @@ export class WSKeepAlive {
158
160
  private handleReconnect() {
159
161
  if (this.reconnectAttempts >= this.config.maxReconnectAttempts) {
160
162
  this.log(`Max reconnect attempts (${this.config.maxReconnectAttempts}) reached. Giving up.`);
163
+ this.config.onExit(1);
161
164
  return;
162
165
  }
163
166
  this.reconnectAttempts++;
@@ -174,6 +177,7 @@ export class WSKeepAlive {
174
177
  this.stopPing();
175
178
  if (this.ws) {
176
179
  this.ws.close();
180
+ this.config.onExit(0);
177
181
  this.ws = null;
178
182
  }
179
183
  }
@@ -0,0 +1,13 @@
1
+ import { createKeepAlive } from '@kevisual/cnb/keep';
2
+
3
+ const wsUrl = process.argv[2];
4
+ const cookie = process.argv[3];
5
+
6
+ createKeepAlive({
7
+ wsUrl,
8
+ cookie,
9
+ onConnect: () => console.log('已连接'),
10
+ debug: true
11
+ });
12
+
13
+ process.on('SIGINT', () => process.exit(0));