@zhin.js/adapter-sandbox 6.0.0 → 6.0.1
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/CHANGELOG.md +30 -0
- package/README.md +5 -5
- package/adapters/sandbox.ts +5 -0
- package/lib/endpoint.d.ts +4 -0
- package/lib/endpoint.js +49 -3
- package/lib/protocol.d.ts +5 -0
- package/lib/protocol.js +7 -2
- package/package.json +15 -15
- package/pages/{sandbox.tsx → index.tsx} +1 -0
- package/src/endpoint.ts +55 -3
- package/src/protocol.ts +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @zhin.js/adapter-process
|
|
2
2
|
|
|
3
|
+
## 6.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5691aba: 第二轮全量审计修复批(8 面 ~60 bug):
|
|
8
|
+
|
|
9
|
+
- **安全**:email 附件路径穿越修复(basename + downloadPath 约束);lark/telegram/satori webhook 鉴权(缺密钥告警、timingSafeEqual、±5min 时效窗、chat_type 修正);onebot wss/webhook 缺 token 告警;qq webhook 改原始字节验签;renderJsx/JSX 转义注入修复;console runtime token 401 死循环。
|
|
10
|
+
- **P0 功能**:sandbox 多 endpoint 解析 + WS 路径隔离;short-url expand(undici opaqueredirect)改 follow;AI 压缩摘要失败不再静默丢历史(熔断恢复生效);console-ui 实时推送事件名归一化 + IndexedDB schema 对齐;process-monitor 热重载不再误判崩溃。
|
|
11
|
+
- **生命周期**:email IMAP 断线重连 + 在飞锁;onebot11/12 start 失败清理;line replyToken TTL + push 兜底;wechat-mp token 过期重试 + MsgId 去重;weixin-ilink buf 推进/防抖写盘/媒体 TTL/QR abort;satori PONG 看门狗;退避自毁修复。
|
|
12
|
+
- **游戏**:text-adventure 终局 restart 复活 + requires 服务端校验;tic-tac-toe PvP 占用/restart/队列清理/TTL;idiom-chain/word-riddle 闲聊不扣失误;别名中间件不劫持普通聊天。
|
|
13
|
+
- **共享库**:schema falsy 默认值/date/tuple/union 修复;database parseCondition Date/未知操作符、sqlite TEXT 往返、query 分派、belongsToMany 方言、migration dry-run;schedule DST 回拨死循环、重复 id 去重、flush 串行化;game-kit fallback 编号/onboarding 提示/尾缀边界/活引用拷贝。
|
|
14
|
+
- **渲染语音**:fetch 全部超时 + 渲染并发闸;sanitizeHtml form 保文本;STT 扩展名映射 + 删临时文件;TTS 未知 provider 报错;emojiCache LRU 负缓存/fontCache style/clearFonts 恢复;register 错误分类收窄。
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [cdf64e7]
|
|
17
|
+
- Updated dependencies [2d0a159]
|
|
18
|
+
- Updated dependencies [5691aba]
|
|
19
|
+
- Updated dependencies [078e3f7]
|
|
20
|
+
- Updated dependencies [9c997b2]
|
|
21
|
+
- Updated dependencies [09d4f25]
|
|
22
|
+
- Updated dependencies [f0ec5ab]
|
|
23
|
+
- Updated dependencies [fa66c4c]
|
|
24
|
+
- Updated dependencies [fa66c4c]
|
|
25
|
+
- Updated dependencies [6cb6152]
|
|
26
|
+
- @zhin.js/plugin-runtime@1.1.1
|
|
27
|
+
- @zhin.js/host-http@1.0.3
|
|
28
|
+
- @zhin.js/client@2.1.1
|
|
29
|
+
- @zhin.js/adapter@1.1.1
|
|
30
|
+
- @zhin.js/core@1.4.1
|
|
31
|
+
- @zhin.js/page@1.0.3
|
|
32
|
+
|
|
3
33
|
## 6.0.0
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -23,19 +23,19 @@ pnpm add @zhin.js/adapter-sandbox
|
|
|
23
23
|
- `@zhin.js/adapter` — 约定式 `adapters/sandbox.ts`
|
|
24
24
|
- `@zhin.js/host-http` — Root 提供的 `httpHostToken`(WebSocket `/sandbox` + Console HTTP)
|
|
25
25
|
- `@zhin.js/core` — `messageGatewayToken` / ImRuntime 入站出站
|
|
26
|
-
- `@zhin.js/page` + `pages/
|
|
26
|
+
- `@zhin.js/page` + `pages/index.tsx` — ADR 0046 约定页(`definePage`;路由 `/sandbox`)
|
|
27
27
|
|
|
28
28
|
Root 在 `zhin runtime start` 时装载 `@zhin.js/host-http`、`ConsoleRuntime` 与
|
|
29
29
|
`ClientBuildModuleRuntime`。打开 `http://<host>:<port>/console` 可浏览页面;Sandbox 页
|
|
30
|
-
|
|
30
|
+
(路由 `/sandbox`,与 WebSocket `/sandbox` 同 path:GET 开页、Upgrade 走 WS)内置聊天壳。
|
|
31
31
|
|
|
32
32
|
旧 `client/`(`register(api)` / `pageManager.addEntry`)仅保留给 legacy Host 栈参考,
|
|
33
33
|
**不是** Plugin Runtime 生产入口。
|
|
34
34
|
|
|
35
|
-
### 旧 Host
|
|
35
|
+
### 旧 Host 栈(已删除)
|
|
36
|
+
|
|
37
|
+
原 legacy 插件包 `@zhin.js/host-router`(HTTP 服务)与 `@zhin.js/host-api`(Host 侧 Console API,`addEntry` 注册 Sandbox 扩展)已删除;`zhin dev` 现由 `@zhin.js/cli` 自动装配 Console/HTTP Host(`@zhin.js/host-http` + `@zhin.js/pagemanager`),无需安装任何 Host 插件。
|
|
36
38
|
|
|
37
|
-
- `@zhin.js/host-router` — HTTP 服务(提供 Router 和 WebSocket)
|
|
38
|
-
- `@zhin.js/host-api` — Host 侧 Console API(`addEntry` 注册 Sandbox 扩展)
|
|
39
39
|
- `@zhin.js/client` — Remote Console 客户端 SDK(UI 在 zhin-console 仓库)
|
|
40
40
|
|
|
41
41
|
出站 wire 只做 JSON 封装;旧 `segment-mapper`(canonical segments)归一化上移到 gateway/core 渲染链。
|
package/adapters/sandbox.ts
CHANGED
|
@@ -15,6 +15,11 @@ export type { SandboxEndpointOptions } from '../src/endpoint.js';
|
|
|
15
15
|
|
|
16
16
|
export default defineAdapter<SandboxAdapterConfig>({
|
|
17
17
|
capabilities: ['inbound', 'outbound'],
|
|
18
|
+
// Console UI 直接渲染 base64 内联媒体;交互段由 Console 原生承载。
|
|
19
|
+
segments: {
|
|
20
|
+
outboundMedia: ['base64'],
|
|
21
|
+
interactive: 'native',
|
|
22
|
+
},
|
|
18
23
|
create(context) {
|
|
19
24
|
return new SandboxWsEndpoint({
|
|
20
25
|
id: context.id,
|
package/lib/endpoint.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ export interface SandboxEndpointOptions {
|
|
|
9
9
|
readonly http: HttpHost;
|
|
10
10
|
readonly defaults: ResolvedSandboxBot;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Sandbox 是本地开发/测试面,无平台社交图谱(好友/群/频道),
|
|
14
|
+
* 不适用 EndpointManagement 语义端口;本 endpoint 不暴露该端口。
|
|
15
|
+
*/
|
|
12
16
|
export declare class SandboxWsEndpoint implements EndpointInstance {
|
|
13
17
|
#private;
|
|
14
18
|
constructor(options: SandboxEndpointOptions);
|
package/lib/endpoint.js
CHANGED
|
@@ -5,10 +5,50 @@ import { randomUUID } from 'node:crypto';
|
|
|
5
5
|
import { formatCompact, getLogger } from '@zhin.js/logger';
|
|
6
6
|
import { bindSandboxWsSocket, formatSandboxOutbound, parseSandboxWsPayload, whenWsOpen, } from './protocol.js';
|
|
7
7
|
const logger = getLogger('sandbox');
|
|
8
|
+
/**
|
|
9
|
+
* 多 sandbox endpoint 共用同一个 HttpHost 时,同 path 的所有 WS listener
|
|
10
|
+
* 都会被回调(入站重复、出站互窜)。按 endpoint 名隔离挂载路径:
|
|
11
|
+
* 首个占用 `/sandbox`(保持 Console 默认兼容),其余退到 `/sandbox/<name>`。
|
|
12
|
+
* 认领记录按 HttpHost 隔离,endpoint stop() 时必须 release。
|
|
13
|
+
*/
|
|
14
|
+
const claimedWsPaths = new WeakMap();
|
|
15
|
+
function claimSandboxWsPath(http, name) {
|
|
16
|
+
let claims = claimedWsPaths.get(http);
|
|
17
|
+
if (!claims) {
|
|
18
|
+
claims = new Map();
|
|
19
|
+
claimedWsPaths.set(http, claims);
|
|
20
|
+
}
|
|
21
|
+
const candidates = ['/sandbox', `/sandbox/${encodeURIComponent(name)}`];
|
|
22
|
+
let path = candidates.find((candidate) => !claims.has(candidate) || claims.get(candidate) === name);
|
|
23
|
+
if (!path) {
|
|
24
|
+
let index = 2;
|
|
25
|
+
path = `/sandbox/${encodeURIComponent(name)}-${index}`;
|
|
26
|
+
while (claims.has(path)) {
|
|
27
|
+
index += 1;
|
|
28
|
+
path = `/sandbox/${encodeURIComponent(name)}-${index}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
claims.set(path, name);
|
|
32
|
+
const claimed = path;
|
|
33
|
+
const registry = claims;
|
|
34
|
+
return {
|
|
35
|
+
path: claimed,
|
|
36
|
+
release: () => {
|
|
37
|
+
if (registry.get(claimed) === name)
|
|
38
|
+
registry.delete(claimed);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sandbox 是本地开发/测试面,无平台社交图谱(好友/群/频道),
|
|
44
|
+
* 不适用 EndpointManagement 语义端口;本 endpoint 不暴露该端口。
|
|
45
|
+
*/
|
|
8
46
|
export class SandboxWsEndpoint {
|
|
9
47
|
#options;
|
|
10
48
|
#connections = new Map();
|
|
11
49
|
#wsHandleRelease;
|
|
50
|
+
#wsPathRelease;
|
|
51
|
+
#wsPath = '/sandbox';
|
|
12
52
|
#open = false;
|
|
13
53
|
#started = false;
|
|
14
54
|
constructor(options) {
|
|
@@ -22,7 +62,11 @@ export class SandboxWsEndpoint {
|
|
|
22
62
|
if (this.#started)
|
|
23
63
|
return;
|
|
24
64
|
this.#started = true;
|
|
25
|
-
|
|
65
|
+
// 多 endpoint 同 path 会被全部回调(入站重复、出站互窜),按名隔离。
|
|
66
|
+
const claim = claimSandboxWsPath(this.#options.http, this.#options.defaults.name);
|
|
67
|
+
this.#wsPathRelease = claim.release;
|
|
68
|
+
this.#wsPath = claim.path;
|
|
69
|
+
const handle = this.#options.http.ws(claim.path);
|
|
26
70
|
this.#wsHandleRelease = handle.onConnection((connection) => {
|
|
27
71
|
this.#acceptConnection(connection);
|
|
28
72
|
});
|
|
@@ -31,7 +75,7 @@ export class SandboxWsEndpoint {
|
|
|
31
75
|
}
|
|
32
76
|
logger.info(formatCompact({
|
|
33
77
|
op: 'sandbox_ws_mounted',
|
|
34
|
-
path:
|
|
78
|
+
path: claim.path,
|
|
35
79
|
endpoint: this.#options.defaults.name,
|
|
36
80
|
}));
|
|
37
81
|
}
|
|
@@ -45,6 +89,8 @@ export class SandboxWsEndpoint {
|
|
|
45
89
|
this.#open = false;
|
|
46
90
|
this.#wsHandleRelease?.();
|
|
47
91
|
this.#wsHandleRelease = undefined;
|
|
92
|
+
this.#wsPathRelease?.();
|
|
93
|
+
this.#wsPathRelease = undefined;
|
|
48
94
|
for (const connection of this.#connections.values()) {
|
|
49
95
|
connection.release();
|
|
50
96
|
if (!connection.placeholder) {
|
|
@@ -194,7 +240,7 @@ export class SandboxWsEndpoint {
|
|
|
194
240
|
data: {
|
|
195
241
|
text: [
|
|
196
242
|
`已连接 Sandbox「${target}」`,
|
|
197
|
-
|
|
243
|
+
`与 Node Host 控制台沙盒协议一致(${this.#wsPath})`,
|
|
198
244
|
'命令: help · ping · zt · status',
|
|
199
245
|
].join('\n'),
|
|
200
246
|
},
|
package/lib/protocol.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export type ResolvedSandboxBot = {
|
|
|
19
19
|
readonly randomNamePerConnection: boolean;
|
|
20
20
|
};
|
|
21
21
|
export interface SandboxAdapterConfig {
|
|
22
|
+
/** Runtime expands `endpoints[i]` onto the top level — prefer these. */
|
|
23
|
+
readonly context?: string;
|
|
24
|
+
readonly name?: string;
|
|
25
|
+
readonly owner?: string;
|
|
26
|
+
/** Legacy shape: endpoint entries nested under `endpoints[]`. */
|
|
22
27
|
readonly endpoints?: ReadonlyArray<{
|
|
23
28
|
readonly context?: string;
|
|
24
29
|
readonly name?: string;
|
package/lib/protocol.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/** Sandbox WebSocket wire protocol helpers (no legacy Adapter/Endpoint). */
|
|
2
2
|
export function resolveSandboxEndpoint(appConfig) {
|
|
3
3
|
const entry = appConfig.endpoints?.find((item) => item.context === 'sandbox');
|
|
4
|
-
const fixedName = typeof
|
|
4
|
+
const fixedName = typeof appConfig.name === 'string' && appConfig.name
|
|
5
|
+
? appConfig.name
|
|
6
|
+
: typeof entry?.name === 'string' && entry.name
|
|
7
|
+
? entry.name
|
|
8
|
+
: undefined;
|
|
5
9
|
const name = fixedName || process.env.SANDBOX_BOT_NAME || 'sandbox-bot';
|
|
6
|
-
const owner = (typeof
|
|
10
|
+
const owner = (typeof appConfig.owner === 'string' && appConfig.owner)
|
|
11
|
+
|| (typeof entry?.owner === 'string' && entry.owner)
|
|
7
12
|
|| process.env.SANDBOX_BOT_OWNER
|
|
8
13
|
|| 'sandbox-user';
|
|
9
14
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-sandbox",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Zhin.js Sandbox adapter for Plugin Runtime (WebSocket /sandbox)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"lucide-react": "^0.525.0",
|
|
50
50
|
"react": "^19.1.0",
|
|
51
|
-
"@zhin.js/
|
|
51
|
+
"@zhin.js/adapter": "1.1.1",
|
|
52
|
+
"@zhin.js/client": "2.1.1",
|
|
52
53
|
"@zhin.js/console-contract": "1.0.0",
|
|
53
|
-
"@zhin.js/
|
|
54
|
-
"@zhin.js/
|
|
55
|
-
"@zhin.js/host-http": "1.0.2",
|
|
54
|
+
"@zhin.js/core": "1.4.1",
|
|
55
|
+
"@zhin.js/host-http": "1.0.3",
|
|
56
56
|
"@zhin.js/logger": "1.0.75",
|
|
57
|
-
"@zhin.js/page": "1.0.
|
|
58
|
-
"@zhin.js/plugin-runtime": "1.1.
|
|
57
|
+
"@zhin.js/page": "1.0.3",
|
|
58
|
+
"@zhin.js/plugin-runtime": "1.1.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/react": "^19.1.8",
|
|
@@ -63,18 +63,18 @@
|
|
|
63
63
|
"typescript": "^6.0.3",
|
|
64
64
|
"vitest": "^4.1.10",
|
|
65
65
|
"ws": "^8.21.0",
|
|
66
|
-
"@zhin.js/pagemanager": "2.0.
|
|
67
|
-
"@zhin.js/runtime": "1.0.
|
|
66
|
+
"@zhin.js/pagemanager": "2.0.6",
|
|
67
|
+
"@zhin.js/runtime": "1.0.3"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"react": "^19.0.0",
|
|
71
|
-
"@zhin.js/adapter": "1.1.
|
|
72
|
-
"@zhin.js/client": "2.1.
|
|
71
|
+
"@zhin.js/adapter": "1.1.1",
|
|
72
|
+
"@zhin.js/client": "2.1.1",
|
|
73
73
|
"@zhin.js/console-contract": "1.0.0",
|
|
74
|
-
"@zhin.js/core": "1.4.
|
|
75
|
-
"@zhin.js/host-http": "1.0.
|
|
76
|
-
"@zhin.js/page": "1.0.
|
|
77
|
-
"@zhin.js/plugin-runtime": "1.1.
|
|
74
|
+
"@zhin.js/core": "1.4.1",
|
|
75
|
+
"@zhin.js/host-http": "1.0.3",
|
|
76
|
+
"@zhin.js/page": "1.0.3",
|
|
77
|
+
"@zhin.js/plugin-runtime": "1.1.1"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"react": {
|
|
@@ -9,6 +9,7 @@ export const meta = definePage({
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Convention page entry (ADR 0046).
|
|
12
|
+
* `pages/index.tsx` → `/sandbox` (plugin path; no `/p-` leaf).
|
|
12
13
|
* Restores the pre-runtime-migration Sandbox console UI (channels + rich text + faces).
|
|
13
14
|
* WebSocket targets Host `/sandbox` via zhin_api_base + token (see sandboxTransport.ts).
|
|
14
15
|
*/
|
package/src/endpoint.ts
CHANGED
|
@@ -18,6 +18,46 @@ import {
|
|
|
18
18
|
|
|
19
19
|
const logger = getLogger('sandbox');
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* 多 sandbox endpoint 共用同一个 HttpHost 时,同 path 的所有 WS listener
|
|
23
|
+
* 都会被回调(入站重复、出站互窜)。按 endpoint 名隔离挂载路径:
|
|
24
|
+
* 首个占用 `/sandbox`(保持 Console 默认兼容),其余退到 `/sandbox/<name>`。
|
|
25
|
+
* 认领记录按 HttpHost 隔离,endpoint stop() 时必须 release。
|
|
26
|
+
*/
|
|
27
|
+
const claimedWsPaths = new WeakMap<HttpHost, Map<string, string>>();
|
|
28
|
+
|
|
29
|
+
function claimSandboxWsPath(
|
|
30
|
+
http: HttpHost,
|
|
31
|
+
name: string,
|
|
32
|
+
): { readonly path: string; readonly release: () => void } {
|
|
33
|
+
let claims = claimedWsPaths.get(http);
|
|
34
|
+
if (!claims) {
|
|
35
|
+
claims = new Map();
|
|
36
|
+
claimedWsPaths.set(http, claims);
|
|
37
|
+
}
|
|
38
|
+
const candidates = ['/sandbox', `/sandbox/${encodeURIComponent(name)}`];
|
|
39
|
+
let path = candidates.find(
|
|
40
|
+
(candidate) => !claims!.has(candidate) || claims!.get(candidate) === name,
|
|
41
|
+
);
|
|
42
|
+
if (!path) {
|
|
43
|
+
let index = 2;
|
|
44
|
+
path = `/sandbox/${encodeURIComponent(name)}-${index}`;
|
|
45
|
+
while (claims.has(path)) {
|
|
46
|
+
index += 1;
|
|
47
|
+
path = `/sandbox/${encodeURIComponent(name)}-${index}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
claims.set(path, name);
|
|
51
|
+
const claimed = path;
|
|
52
|
+
const registry = claims;
|
|
53
|
+
return {
|
|
54
|
+
path: claimed,
|
|
55
|
+
release: () => {
|
|
56
|
+
if (registry.get(claimed) === name) registry.delete(claimed);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
21
61
|
interface SandboxChannel {
|
|
22
62
|
readonly type: string;
|
|
23
63
|
readonly id: string;
|
|
@@ -44,10 +84,16 @@ export interface SandboxEndpointOptions {
|
|
|
44
84
|
readonly defaults: ResolvedSandboxBot;
|
|
45
85
|
}
|
|
46
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Sandbox 是本地开发/测试面,无平台社交图谱(好友/群/频道),
|
|
89
|
+
* 不适用 EndpointManagement 语义端口;本 endpoint 不暴露该端口。
|
|
90
|
+
*/
|
|
47
91
|
export class SandboxWsEndpoint implements EndpointInstance {
|
|
48
92
|
readonly #options: SandboxEndpointOptions;
|
|
49
93
|
readonly #connections = new Map<string, SandboxConnection>();
|
|
50
94
|
#wsHandleRelease?: () => void;
|
|
95
|
+
#wsPathRelease?: () => void;
|
|
96
|
+
#wsPath = '/sandbox';
|
|
51
97
|
#open = false;
|
|
52
98
|
#started = false;
|
|
53
99
|
|
|
@@ -63,7 +109,11 @@ export class SandboxWsEndpoint implements EndpointInstance {
|
|
|
63
109
|
start(): void {
|
|
64
110
|
if (this.#started) return;
|
|
65
111
|
this.#started = true;
|
|
66
|
-
|
|
112
|
+
// 多 endpoint 同 path 会被全部回调(入站重复、出站互窜),按名隔离。
|
|
113
|
+
const claim = claimSandboxWsPath(this.#options.http, this.#options.defaults.name);
|
|
114
|
+
this.#wsPathRelease = claim.release;
|
|
115
|
+
this.#wsPath = claim.path;
|
|
116
|
+
const handle = this.#options.http.ws(claim.path);
|
|
67
117
|
this.#wsHandleRelease = handle.onConnection((connection) => {
|
|
68
118
|
this.#acceptConnection(connection);
|
|
69
119
|
});
|
|
@@ -72,7 +122,7 @@ export class SandboxWsEndpoint implements EndpointInstance {
|
|
|
72
122
|
}
|
|
73
123
|
logger.info(formatCompact({
|
|
74
124
|
op: 'sandbox_ws_mounted',
|
|
75
|
-
path:
|
|
125
|
+
path: claim.path,
|
|
76
126
|
endpoint: this.#options.defaults.name,
|
|
77
127
|
}));
|
|
78
128
|
}
|
|
@@ -89,6 +139,8 @@ export class SandboxWsEndpoint implements EndpointInstance {
|
|
|
89
139
|
this.#open = false;
|
|
90
140
|
this.#wsHandleRelease?.();
|
|
91
141
|
this.#wsHandleRelease = undefined;
|
|
142
|
+
this.#wsPathRelease?.();
|
|
143
|
+
this.#wsPathRelease = undefined;
|
|
92
144
|
for (const connection of this.#connections.values()) {
|
|
93
145
|
connection.release();
|
|
94
146
|
if (!connection.placeholder) {
|
|
@@ -237,7 +289,7 @@ export class SandboxWsEndpoint implements EndpointInstance {
|
|
|
237
289
|
data: {
|
|
238
290
|
text: [
|
|
239
291
|
`已连接 Sandbox「${target}」`,
|
|
240
|
-
|
|
292
|
+
`与 Node Host 控制台沙盒协议一致(${this.#wsPath})`,
|
|
241
293
|
'命令: help · ping · zt · status',
|
|
242
294
|
].join('\n'),
|
|
243
295
|
},
|
package/src/protocol.ts
CHANGED
|
@@ -33,6 +33,11 @@ export type ResolvedSandboxBot = {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export interface SandboxAdapterConfig {
|
|
36
|
+
/** Runtime expands `endpoints[i]` onto the top level — prefer these. */
|
|
37
|
+
readonly context?: string;
|
|
38
|
+
readonly name?: string;
|
|
39
|
+
readonly owner?: string;
|
|
40
|
+
/** Legacy shape: endpoint entries nested under `endpoints[]`. */
|
|
36
41
|
readonly endpoints?: ReadonlyArray<{
|
|
37
42
|
readonly context?: string;
|
|
38
43
|
readonly name?: string;
|
|
@@ -44,9 +49,14 @@ export function resolveSandboxEndpoint(
|
|
|
44
49
|
appConfig: SandboxAdapterConfig,
|
|
45
50
|
): ResolvedSandboxBot {
|
|
46
51
|
const entry = appConfig.endpoints?.find((item) => item.context === 'sandbox');
|
|
47
|
-
const fixedName = typeof
|
|
52
|
+
const fixedName = typeof appConfig.name === 'string' && appConfig.name
|
|
53
|
+
? appConfig.name
|
|
54
|
+
: typeof entry?.name === 'string' && entry.name
|
|
55
|
+
? entry.name
|
|
56
|
+
: undefined;
|
|
48
57
|
const name = fixedName || process.env.SANDBOX_BOT_NAME || 'sandbox-bot';
|
|
49
|
-
const owner = (typeof
|
|
58
|
+
const owner = (typeof appConfig.owner === 'string' && appConfig.owner)
|
|
59
|
+
|| (typeof entry?.owner === 'string' && entry.owner)
|
|
50
60
|
|| process.env.SANDBOX_BOT_OWNER
|
|
51
61
|
|| 'sandbox-user';
|
|
52
62
|
return {
|