@zhin.js/adapter-sandbox 1.1.20 → 1.1.22
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 +64 -0
- package/README.md +55 -7
- package/adapters/sandbox/index.js +3 -12
- package/adapters/sandbox/index.ts +2 -12
- package/lib/adapter.d.ts +17 -0
- package/lib/adapter.js +17 -0
- package/lib/client.d.ts +7 -14
- package/lib/client.js +12 -11
- package/lib/endpoint.d.ts +16 -13
- package/lib/endpoint.js +171 -138
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/protocol.d.ts +22 -1
- package/lib/protocol.js +34 -4
- package/package.json +17 -17
- package/pages/index/ConversationRecoveryPanel.js +131 -0
- package/pages/index/ConversationRecoveryPanel.tsx +134 -0
- package/pages/index/SandboxChat.js +319 -111
- package/pages/index/SandboxChat.tsx +356 -126
- package/pages/index/agentTrace.js +21 -10
- package/pages/index/agentTrace.ts +24 -10
- package/pages/index/conversationRecovery.js +40 -0
- package/pages/index/conversationRecovery.ts +68 -0
- package/pages/index/index.js +5 -5
- package/pages/index/index.tsx +5 -5
- package/pages/index/messages.js +24 -6
- package/pages/index/messages.ts +24 -6
- package/pages/index/playgroundState.js +51 -1
- package/pages/index/playgroundState.ts +61 -1
- package/pages/index/sandboxTransport.js +25 -0
- package/pages/index/sandboxTransport.ts +35 -0
- package/pages/index/useSandboxHistory.js +161 -0
- package/pages/index/useSandboxHistory.ts +164 -0
- package/pages/index/workspaceDirectory.js +49 -0
- package/pages/index/workspaceDirectory.ts +74 -0
- package/pages/index/workspaceDirectoryState.js +120 -0
- package/pages/index/workspaceDirectoryState.ts +124 -0
- package/src/adapter.ts +22 -0
- package/src/client.ts +16 -18
- package/src/endpoint.ts +179 -140
- package/src/index.ts +1 -1
- package/src/protocol.ts +59 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,69 @@
|
|
|
1
1
|
# @zhin.js/adapter-process
|
|
2
2
|
|
|
3
|
+
## 1.1.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [5e878ba]
|
|
8
|
+
- @zhin.js/page@1.1.12
|
|
9
|
+
|
|
10
|
+
## 1.1.21
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 2c3610a: Move account lifecycle ownership into the generic Adapter base and let native Endpoints retain their SDK Client inheritance. Infer platform-specific operation Sessions from a single adapter registry while preserving command parameter, option, configuration and factory inference.
|
|
15
|
+
|
|
16
|
+
Bind message replies, management ports, login challenges and Agent cancellation to the captured account incarnation. Persist runtime account intent with encrypted, revision-checked Host storage; keep account management independent of Root process restarts. Require explicit operator confirmation before importing existing accounts, and give replacement accounts a new identity without inheriting previous Sessions.
|
|
17
|
+
|
|
18
|
+
Expose account save, start, stop, update and replacement through the existing adapter Console, with exact account ownership, truthful pending/unknown outcomes and no startup configuration or environment-file rewrites.
|
|
19
|
+
|
|
20
|
+
Complete the target migration across every adapter, the public authoring API, generators, examples and Console. This intentionally removes the old create factory, inheritable Endpoint/ClientEndpoint classes, Client descriptors and file-rewrite account management; plugin authors must use createAdapter, native Client inheritance and the single AdapterRegistry. Satori and OneBot12 require explicit platform/userId selection, and WeCom requires a separate agentId.
|
|
21
|
+
|
|
22
|
+
Verify opaque credential changes before the same configuration snapshot is committed. Drain admitted native callbacks across close/rollback, cancel target work on stop, and keep raw transport parsing, platform ACK timing and SDK native methods under their existing owners. Account metadata conceals credentials carried in URLs.
|
|
23
|
+
|
|
24
|
+
- a9f4e48: PATCH COMPATIBILITY CUTOVER: this batch intentionally changes plugin APIs. The maintainer explicitly chose patch releases with declared version boundaries. Upgrade the complete tested dependency set; patch numbering does not promise compatibility with the removed interfaces.
|
|
25
|
+
|
|
26
|
+
The first planned floors are zhin.js 1.1.19, Core 1.1.54, Adapter 1.1.26, FeatureKit 1.1.10, Plugin Runtime 1.1.18, Runtime/Isolate 1.1.16 and Agent 1.1.45. Keep old-interface plugins with the earlier locked stack until they are migrated. Adapter's independent Feature API changes from 1.0.0 to 2.0.0; official consumers declare ^2.0.0. Existing Feature API admission rejects explicitly incompatible ranges; omitted API metadata keeps its existing behavior and does not certify compatibility. Runtime engine and patch-only release gates remain unchanged.
|
|
27
|
+
|
|
28
|
+
Use the native-Client Adapter target contract, canonical FeatureKit AdapterRegistry augmentation and named Endpoint control/management requests. Route message controls from canonical message/conversation refs; retain exact source authority and propagate caller/account/explicit-Root-stop cancellation. Replace removed Agent activity feedback exports with source-bound feedback. HMR pause/resume belongs to concrete plugin instances; plugins choose accepted-work policy without changing Controller commit/rollback authority. Cooperative worker/process control cancellation does not kill an isolate or reopen retired business admission.
|
|
29
|
+
|
|
30
|
+
Provide authenticated historical-data preview, exact selected binding, transactional application, authoritative inspection and explicit resumption, including active games. Preserve before-images and journals; never replay an unconfirmed effect, infer an account from an alias, or reuse historical permission grants. Owner V2 approvals remain inactive legacy data, while new writes use V3. Rollback requires matching software, lockfile and verified data; installing old code alone cannot read a new V3 approval file. Conflicting after-images are never overwritten.
|
|
31
|
+
|
|
32
|
+
See docs/plans/adapter-operation-version-boundaries.md and the Chinese/English upgrade guide for the complete version inventory, custom-plugin changes, acceptance and recovery sequence. These code and metadata changes do not authorize merging, publication, deployment, login, production migration or removal of installed workspace patches.
|
|
33
|
+
|
|
34
|
+
- 6749002: Keep interactive runtime turns and their synchronous children running without fixed iteration or total wall-clock caps. Share configured token quotas across the live turn, retain cancellation and authorization, compact child context independently, and report periodic progress without additional model calls or blocking final delivery. Scheduled, unattended, independent background and legacy API budgets remain unchanged.
|
|
35
|
+
|
|
36
|
+
Stabilize prompt prefixes by keeping conversation identity in the session-stable system tail and fresh scene state after the current message. Shorten and escape the host-context boundary, preserve permission-filtered tool disclosure, and omit fixed iteration ceilings from continuous-run traces.
|
|
37
|
+
|
|
38
|
+
Project repeated inspections of the same private image only once per model request, preserving resource access checks, transient lifetime, and the existing inspection limit.
|
|
39
|
+
|
|
40
|
+
- d38fb4b: Pass normalized message segments through the canonical Core ingress. Approval callbacks now reach the existing interaction authority instead of being interpreted as ordinary text. Keep the legacy metadata projection for older consumers.
|
|
41
|
+
- 9a9bbd9: Support concurrent Console connections with per-conversation subscriptions and negotiated input echoes. Preserve Bot identities, legacy clients and server-side approvals; isolate other conversations and demo connections, and leave delivery unconfirmed when no subscriber accepts a reply.
|
|
42
|
+
|
|
43
|
+
Reuse Console conversation, usage and request readers within the active workspace when available, with a standalone-page fallback for older shells. Isolate trace reads and cancellation feedback across scene and connection changes without repeating cancellation requests.
|
|
44
|
+
|
|
45
|
+
Recover Host-scoped conversation metadata, canonical chat history, read-only offline results and current live interactions without migrating browser caches or replaying execution. Keep historical controls read-only and use the existing server authority for live answers.
|
|
46
|
+
|
|
47
|
+
Retire matching native prompt controls when an authoritative read confirms they are no longer pending, without disabling unrelated plugin messages or inferring approval success.
|
|
48
|
+
|
|
49
|
+
Keep cancellation feedback separate from trace-read errors, so cached events and subsequent trace refreshes cannot hide a failed stop request. Show read errors alongside the available trace and keep feedback scoped to the original connection and conversation.
|
|
50
|
+
|
|
51
|
+
- 8f2affe: Keep Sandbox WebSocket message IDs consistent with canonical delivery receipts, preserving explicit IDs from existing wire envelopes.
|
|
52
|
+
|
|
53
|
+
Present the Sandbox as Conversations and link its conversation and trace actions to the existing Console session details, preserving the encoded session identity.
|
|
54
|
+
|
|
55
|
+
- Updated dependencies [2c3610a]
|
|
56
|
+
- Updated dependencies [a9f4e48]
|
|
57
|
+
- Updated dependencies [f8505b0]
|
|
58
|
+
- Updated dependencies [2c3610a]
|
|
59
|
+
- @zhin.js/adapter@1.1.26
|
|
60
|
+
- @zhin.js/feature-kit@1.1.10
|
|
61
|
+
- @zhin.js/core@1.1.54
|
|
62
|
+
- @zhin.js/host-http@1.1.12
|
|
63
|
+
- @zhin.js/client@1.1.22
|
|
64
|
+
- @zhin.js/page@1.1.11
|
|
65
|
+
- @zhin.js/skill@1.1.11
|
|
66
|
+
|
|
3
67
|
## 1.1.20
|
|
4
68
|
|
|
5
69
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @zhin.js/adapter-sandbox
|
|
2
2
|
|
|
3
|
-
Zhin.js Sandbox
|
|
3
|
+
Zhin.js Sandbox 适配器,为 **[Remote Console](https://console.zhin.dev)** 提供会话工作区。Host 承载 WebSocket、真实聊天记录和执行状态,Console 提供聊天与工作界面。
|
|
4
|
+
|
|
5
|
+
账号由 `SandboxAdapter` 管理。Endpoint 直接继承实际 `SandboxClient`,保留原生方法与事件;框架生命周期、规范入站与发送经 `endpointSpec` 和 AdapterIndex 接入,不占用 Client 的原生 `start` / `stop` / `send` 方法。
|
|
4
6
|
|
|
5
7
|
## 功能特性
|
|
6
8
|
|
|
@@ -26,7 +28,7 @@ Sandbox 不需要外部账号。只需由 `zhin runtime start` 装配 HTTP Host
|
|
|
26
28
|
|
|
27
29
|
- `@zhin.js/adapter` — 约定式 `adapters/sandbox/index.ts`
|
|
28
30
|
- `@zhin.js/host-http` — Root 提供的 `httpHostToken`(WebSocket `/sandbox` + Console HTTP)
|
|
29
|
-
- `@zhin.js/core` — `
|
|
31
|
+
- `@zhin.js/core` — `endpointSpec.events` 入站、`outboundMessageToken` 出站
|
|
30
32
|
- `@zhin.js/page` + `pages/index/index.tsx` — ADR 0046 约定页(`definePage`;路由 `/sandbox`)
|
|
31
33
|
|
|
32
34
|
Root 在 `zhin runtime start` 时装载 `@zhin.js/host-http`、`ConsoleRuntime` 与
|
|
@@ -75,10 +77,22 @@ sandbox:
|
|
|
75
77
|
|
|
76
78
|
1. 启动 Zhin 实例:`pnpm dev`(终端会打印 Host 地址,一般为 `http://127.0.0.1:8086`)
|
|
77
79
|
2. 打开 **[Remote Console](https://console.zhin.dev)**,API Base 与 Host 地址一致,Token 与 `http.token` / `HTTP_TOKEN` 一致
|
|
78
|
-
3. 在 Console
|
|
80
|
+
3. 在 Console **会话** 页连接后发送消息
|
|
79
81
|
|
|
80
82
|
浏览器客户端连接到默认 `sandbox-bot`,也可以通过多个显式 endpoint 使用不同 WebSocket 路径。
|
|
81
83
|
|
|
84
|
+
支持工作区阅读的 Console 会在当前会话内打开「对话与轨迹」:读取真实收发记录,按需查看用量、逐轮轨迹与模型请求正文;返回聊天时保留输入草稿。未提供该阅读能力的旧 Console 仍打开记录页(`/agent/sessions?sessionKey=...`),会话分支操作保留在该页。路由 `/sandbox` 和已有会话标识保持兼容。
|
|
85
|
+
|
|
86
|
+
会话名称和运行配置保存在当前 Host 的数据库,按 Sandbox endpoint 与配置的 owner 隔离,同一 owner 的浏览器可共享目录。配置保存使用版本检查,冲突或结果不明时不自动重写。旧浏览器缓存不自动上传、迁移或清理;旧 Host 或明确不具备目录存储时继续使用原浏览器方式。主聊天读取真实收发记录,每次 50 条,按需加载更早记录。
|
|
87
|
+
|
|
88
|
+
关闭页面不会取消任务。重新进入会话后,可只读查看 journal 中已完成但未投递、部分投递或投递结果未知的结果,每页 50 个回合;这些结果不会补发、重跑,也不会写成已发送消息。结果正文复用 journal,媒体只保留已授权的资源链接,不复制 base64,不改变 journal 留存规则。
|
|
89
|
+
|
|
90
|
+
刷新后仅恢复当前进程和 generation 中仍有效的待处理交互,继续使用原发起人、会话、期限和单次处理规则。历史与浏览器缓存中的控件不提供当前审批权限;已结束或重启前的操作不会重新激活。
|
|
91
|
+
|
|
92
|
+
无人值守任务等产生的 Host 工具审批,可在任务中心的「Host 工具审批」中查看并逐次确认。该入口沿用 Console 操作者的权限,只显示当前有效请求,不改变 IM 审批规则。
|
|
93
|
+
|
|
94
|
+
「变更与产物」中的成功文件写入、编辑在 Host 提供项目文件引用时,可打开现有文件管理器查看当前文件。入口沿用文件管理器的项目根与读取权限;旧记录或无法映射的文件仍显示执行记录,不推测链接。该入口读取当前内容,不是执行时的历史快照。
|
|
95
|
+
|
|
82
96
|
每个 endpoint 通过 Root 提供的 HTTP Host(`httpHostToken`)挂载一个 WebSocket 路径,协议见下文「消息格式(wire 协议)」。
|
|
83
97
|
|
|
84
98
|
## 消息格式(wire 协议)
|
|
@@ -89,7 +103,20 @@ Console 沙盒页和自己写的测试客户端都用这套协议。每个 WebSo
|
|
|
89
103
|
|
|
90
104
|
- **地址**:`ws://<host>:<port>/sandbox`。同一个 HTTP Host 上的第一个 Sandbox endpoint 挂在 `/sandbox`,其余 endpoint 挂在 `/sandbox/<endpoint id>`(重名时依次加 `-2`、`-3`),启动日志会打印 `ws mounted <path>`。
|
|
91
105
|
- **鉴权**:Host 配置了 token 时,握手请求需带 `Authorization: Bearer <token>` 或查询参数 `?token=<token>`,否则返回 `401`。demo 权限的 token 只能连 `/sandbox`,而且是只读的:消息会被接收,但不会进入命令和 Agent,服务端回一条 `type: "error"`。
|
|
92
|
-
-
|
|
106
|
+
- **多连接**:同一 endpoint 的浏览器连接可以并存,共用已配置的 `owner`;`connectionId` 只标识连接,不改变 Bot 或 Agent 会话身份。关闭一个页面只移除该连接,不取消或重跑任务;endpoint 停止时关闭全部连接(`1001`),generation 退役继续由 Host 关闭(`1012`)。
|
|
107
|
+
- **会话投递**:每个 full 连接订阅一个 `type` + `id`;默认订阅 `private` + `owner`,发送普通消息也会更新该连接的订阅。回复只投递到同会话的 full 连接,demo 连接不能订阅或接收这些消息。无匹配连接时不确认发送,所有发送尝试失败时保留结果未知,不自动重试。
|
|
108
|
+
|
|
109
|
+
### 客户端 → 服务端:订阅当前会话
|
|
110
|
+
|
|
111
|
+
仅在本次 `ready.protocol` 为 `scoped-conversations-v1` 时发送:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{"op":"subscribe","conversation":{"type":"group","id":"test-group"}}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`type` 为 `private`、`group` 或 `channel`。订阅替换该连接的当前会话,服务端返回 `type: "subscribed"` 和同一个 `conversation`。这类控制帧及无效控制帧不会进入命令、Agent 或平台消息钩子。
|
|
118
|
+
|
|
119
|
+
已订阅新协议的页面会收到同会话用户消息的 `direction: "inbound"` 回声,用于同步显示;回声不会再次进入框架。旧客户端无需修改即可发送原消息格式、接收当前会话回复,服务端不会向其发送无法识别的用户回声。新页面连接旧服务端时不发送订阅控制帧,沿用原发送方式。重连只恢复订阅,不重新提交消息。
|
|
93
120
|
|
|
94
121
|
### 客户端 → 服务端:发送消息
|
|
95
122
|
|
|
@@ -111,7 +138,7 @@ Console 沙盒页和自己写的测试客户端都用这套协议。每个 WebSo
|
|
|
111
138
|
| `text` | string | 可选。没有 `content` 时作为纯文本;`content` 里没有文本段时也用它作为消息文本 |
|
|
112
139
|
| `messageId` | string | 可选。客户端生成的消息 id,须匹配 `^[A-Za-z0-9._:-]{1,160}$`,不匹配时忽略;填写后作为这条入站消息的 id,引用回复时可据此定位 |
|
|
113
140
|
| `timestamp` | number | 可选。毫秒时间戳,默认取服务端收到的时间 |
|
|
114
|
-
| `agentRun` | object |
|
|
141
|
+
| `agentRun` | object | 可选。「会话」运行配置,见下表 |
|
|
115
142
|
|
|
116
143
|
- 帧内容不是 JSON 时,整段文本按一条纯文本消息处理。
|
|
117
144
|
- 消息的发送者固定为 endpoint 的 `owner`。
|
|
@@ -135,6 +162,8 @@ Console 沙盒页和自己写的测试客户端都用这套协议。每个 WebSo
|
|
|
135
162
|
```json
|
|
136
163
|
{
|
|
137
164
|
"type": "ready",
|
|
165
|
+
"protocol": "scoped-conversations-v1",
|
|
166
|
+
"connectionId": "connection-uuid",
|
|
138
167
|
"id": "sandbox-user",
|
|
139
168
|
"endpoint": "sandbox-bot",
|
|
140
169
|
"workingDirectory": "/path/to/bot",
|
|
@@ -145,7 +174,7 @@ Console 沙盒页和自己写的测试客户端都用这套协议。每个 WebSo
|
|
|
145
174
|
}
|
|
146
175
|
```
|
|
147
176
|
|
|
148
|
-
`canExecute` 表示当前连接是否为 full 权限(能运行命令和 Agent 任务);`shellIsolation` 是 Docker
|
|
177
|
+
`canExecute` 表示当前连接是否为 full 权限(能运行命令和 Agent 任务);`shellIsolation` 是 Docker 隔离环境的探测结果,仅供展示。`ready` 与 `subscribed` 仅确认连接和订阅,不代表任务或审批成功。
|
|
149
178
|
|
|
150
179
|
**回复消息**:
|
|
151
180
|
|
|
@@ -160,11 +189,30 @@ Console 沙盒页和自己写的测试客户端都用这套协议。每个 WebSo
|
|
|
160
189
|
}
|
|
161
190
|
```
|
|
162
191
|
|
|
163
|
-
- `type` / `id`
|
|
192
|
+
- `conversation: { type, id }` 是框架发送请求确定的真实会话;新客户端优先用它归并消息,即使 legacy envelope 的 `type` / `id` 指向别处。`bot` 和 `endpoint` 是配置的 endpoint id。旧客户端仍可读取原 `type` / `id` 字段。
|
|
193
|
+
- `messageId` 与框架记录的发送回执使用同一个消息 ID,可用于关联实时回复和已保存的聊天记录;已有 wire envelope 的非空显式字符串 ID 保持不变。
|
|
164
194
|
- `content` 是消息段数组。文本、`html`(JSX 卡片,见上文 `html: direct`)、按钮等段原样透传。
|
|
165
195
|
- `image` / `audio` / `video` / `file` 段只读 `data.media`(MediaRef):`url` 原样透传;`base64` 补上 `base64://` 前缀后内联;`path` 由服务端读取文件后转成 `base64` 内联;其他类型和缺少 `data.media` 的媒体段会被丢弃,并在日志中记录 `sandbox_outbound_media_dropped`。
|
|
166
196
|
- 插件直接发送完整消息对象时,其他字段会原样保留。
|
|
167
197
|
|
|
198
|
+
**用户消息回声**:只发给已完成新协议订阅的同会话 full 连接。
|
|
199
|
+
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"type": "group",
|
|
203
|
+
"id": "test-group",
|
|
204
|
+
"conversation": { "type": "group", "id": "test-group" },
|
|
205
|
+
"direction": "inbound",
|
|
206
|
+
"senderId": "sandbox-user",
|
|
207
|
+
"messageId": "client-msg-001",
|
|
208
|
+
"endpoint": "sandbox-bot",
|
|
209
|
+
"content": [{ "type": "text", "data": { "text": "/hello" } }],
|
|
210
|
+
"timestamp": 1700000000000
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
客户端按会话、消息方向及 `messageId` 合并本页乐观消息、真实历史和回声。按钮操作仍由原服务端交互与审批逻辑裁决,页面显示「已提交」不代表审批通过。多连接沿用当前 Console 操作者和配置的 Sandbox owner,不增加多人账号体系。
|
|
215
|
+
|
|
168
216
|
**只读连接的提示**:demo 权限的连接发送消息后,服务端回复:
|
|
169
217
|
|
|
170
218
|
```json
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
-
import { projectLocaleToken, resolveLocale } from 'zhin.js/i18n';
|
|
3
2
|
/**
|
|
4
3
|
* Convention entry: discover `adapters/sandbox/index.ts` → defineAdapter.
|
|
5
4
|
*/
|
|
6
5
|
import { defineAdapter } from 'zhin.js/adapter';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { resolveSandboxEndpoint, } from "../../lib/protocol.js";
|
|
6
|
+
import { SandboxAdapter } from "../../lib/adapter.js";
|
|
7
|
+
import {} from "../../lib/protocol.js";
|
|
10
8
|
export { SandboxWsEndpoint } from "../../lib/endpoint.js";
|
|
11
9
|
export default defineAdapter({
|
|
12
10
|
capabilities: ['inbound', 'outbound'],
|
|
@@ -17,12 +15,5 @@ export default defineAdapter({
|
|
|
17
15
|
outboundMedia: ['url', 'base64', 'path'],
|
|
18
16
|
interactive: 'native',
|
|
19
17
|
},
|
|
20
|
-
|
|
21
|
-
return new SandboxWsEndpoint({
|
|
22
|
-
id: context.id,
|
|
23
|
-
locale: resolveLocale(context.use(projectLocaleToken)),
|
|
24
|
-
http: context.use(httpHostToken),
|
|
25
|
-
defaults: resolveSandboxEndpoint(context.config),
|
|
26
|
-
});
|
|
27
|
-
},
|
|
18
|
+
createAdapter: context => new SandboxAdapter(context),
|
|
28
19
|
});
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { projectLocaleToken, resolveLocale } from 'zhin.js/i18n';
|
|
2
1
|
/**
|
|
3
2
|
* Convention entry: discover `adapters/sandbox/index.ts` → defineAdapter.
|
|
4
3
|
*/
|
|
5
4
|
import { defineAdapter } from 'zhin.js/adapter';
|
|
6
|
-
import {
|
|
7
|
-
import { SandboxWsEndpoint } from '../../src/endpoint.js';
|
|
5
|
+
import { SandboxAdapter } from '../../src/adapter.js';
|
|
8
6
|
import {
|
|
9
|
-
resolveSandboxEndpoint,
|
|
10
7
|
type SandboxEndpointConfig,
|
|
11
8
|
} from '../../src/protocol.js';
|
|
12
9
|
|
|
@@ -22,12 +19,5 @@ export default defineAdapter<SandboxEndpointConfig>({
|
|
|
22
19
|
outboundMedia: ['url', 'base64', 'path'],
|
|
23
20
|
interactive: 'native',
|
|
24
21
|
},
|
|
25
|
-
|
|
26
|
-
return new SandboxWsEndpoint({
|
|
27
|
-
id: context.id,
|
|
28
|
-
locale: resolveLocale(context.use(projectLocaleToken)),
|
|
29
|
-
http: context.use(httpHostToken),
|
|
30
|
-
defaults: resolveSandboxEndpoint(context.config),
|
|
31
|
-
});
|
|
32
|
-
},
|
|
22
|
+
createAdapter: context => new SandboxAdapter(context),
|
|
33
23
|
});
|
package/lib/adapter.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Adapter, type AdapterContext, type EndpointCreationContext } from 'zhin.js/adapter';
|
|
2
|
+
import { type SandboxEndpointConfig } from './protocol.js';
|
|
3
|
+
import { SandboxWsEndpoint } from './endpoint.js';
|
|
4
|
+
import type { SandboxClientEventMap } from './client.js';
|
|
5
|
+
export declare class SandboxAdapter extends Adapter<SandboxWsEndpoint, SandboxEndpointConfig, SandboxClientEventMap> {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(context: AdapterContext<SandboxEndpointConfig>);
|
|
8
|
+
get configurationIdentityFields(): readonly string[];
|
|
9
|
+
get configurationUpdateFields(): readonly string[];
|
|
10
|
+
protected validateConfiguration(config: SandboxEndpointConfig): void;
|
|
11
|
+
protected createEndpoint(input: SandboxEndpointConfig, execution: EndpointCreationContext): SandboxWsEndpoint;
|
|
12
|
+
}
|
|
13
|
+
declare module '@zhin.js/feature-kit' {
|
|
14
|
+
interface AdapterRegistry {
|
|
15
|
+
readonly sandbox: SandboxAdapter;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/lib/adapter.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Adapter } from 'zhin.js/adapter';
|
|
2
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
3
|
+
import { projectLocaleToken, resolveLocale } from 'zhin.js/i18n';
|
|
4
|
+
import { resolveSandboxEndpoint } from './protocol.js';
|
|
5
|
+
import { SandboxWsEndpoint } from './endpoint.js';
|
|
6
|
+
export class SandboxAdapter extends Adapter {
|
|
7
|
+
#context;
|
|
8
|
+
constructor(context) { super(); this.#context = context; }
|
|
9
|
+
get configurationIdentityFields() { return ['id']; }
|
|
10
|
+
// owner binds the synthetic sender's existing permissions and is not a runtime connection setting.
|
|
11
|
+
get configurationUpdateFields() { return []; }
|
|
12
|
+
validateConfiguration(config) { resolveSandboxEndpoint(config); }
|
|
13
|
+
createEndpoint(input, execution) {
|
|
14
|
+
return new SandboxWsEndpoint({ id: execution.canonicalId, defaults: resolveSandboxEndpoint(input),
|
|
15
|
+
http: this.#context.use(httpHostToken), locale: resolveLocale(this.#context.use(projectLocaleToken)) });
|
|
16
|
+
}
|
|
17
|
+
}
|
package/lib/client.d.ts
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
import type { SandboxWsSocket } from './protocol.js';
|
|
2
2
|
export interface SandboxClientConnection {
|
|
3
|
+
readonly connectionId?: string;
|
|
3
4
|
readonly target: string;
|
|
4
5
|
readonly owner: string;
|
|
5
6
|
readonly socket: SandboxWsSocket;
|
|
6
|
-
readonly placeholder
|
|
7
|
+
readonly placeholder?: boolean;
|
|
7
8
|
}
|
|
8
9
|
/** Direct view of the live Sandbox protocol clients owned by one Endpoint. */
|
|
9
|
-
export declare class SandboxClient {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
export declare class SandboxClient<TConnection extends SandboxClientConnection = SandboxClientConnection> {
|
|
11
|
+
/** Real server resources, owned here rather than resolved through an Endpoint callback. */
|
|
12
|
+
protected readonly connectionRecords: Map<string, TConnection>;
|
|
13
|
+
protected wsPathValue: string;
|
|
13
14
|
get path(): string;
|
|
14
15
|
connections(): readonly SandboxClientConnection[];
|
|
15
16
|
connection(target: string): SandboxClientConnection | undefined;
|
|
17
|
+
connectionById(connectionId: string): SandboxClientConnection | undefined;
|
|
16
18
|
send(target: string, payload: string): void;
|
|
17
19
|
}
|
|
18
20
|
export type SandboxClientEventMap = Record<string, unknown>;
|
|
19
|
-
declare module '@zhin.js/feature-kit' {
|
|
20
|
-
interface AdapterClientRegistry {
|
|
21
|
-
readonly sandbox: {
|
|
22
|
-
readonly client: SandboxClient;
|
|
23
|
-
readonly events: SandboxClientEventMap;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export declare const sandboxClient: import("@zhin.js/adapter").EndpointClientToken<SandboxClient, SandboxClientEventMap>;
|
package/lib/client.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { defineEndpointClient } from 'zhin.js/adapter';
|
|
2
1
|
/** Direct view of the live Sandbox protocol clients owned by one Endpoint. */
|
|
3
2
|
export class SandboxClient {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.resolvePath = resolvePath;
|
|
8
|
-
this.resolveConnections = resolveConnections;
|
|
9
|
-
}
|
|
3
|
+
/** Real server resources, owned here rather than resolved through an Endpoint callback. */
|
|
4
|
+
connectionRecords = new Map();
|
|
5
|
+
wsPathValue = '/sandbox';
|
|
10
6
|
get path() {
|
|
11
|
-
return this.
|
|
7
|
+
return this.wsPathValue;
|
|
12
8
|
}
|
|
13
9
|
connections() {
|
|
14
|
-
return Object.freeze([...this.
|
|
10
|
+
return Object.freeze([...this.connectionRecords.values()].map(connection => Object.freeze({
|
|
11
|
+
connectionId: connection.connectionId, target: connection.target, owner: connection.owner,
|
|
12
|
+
socket: connection.socket, placeholder: connection.placeholder === true,
|
|
13
|
+
})));
|
|
15
14
|
}
|
|
16
15
|
connection(target) {
|
|
17
|
-
return this.connections().find((connection) => connection.target === target);
|
|
16
|
+
return [...this.connections()].reverse().find((connection) => connection.target === target);
|
|
17
|
+
}
|
|
18
|
+
connectionById(connectionId) {
|
|
19
|
+
return this.connections().find((connection) => connection.connectionId === connectionId);
|
|
18
20
|
}
|
|
19
21
|
send(target, payload) {
|
|
20
22
|
const connection = this.connection(target);
|
|
@@ -24,4 +26,3 @@ export class SandboxClient {
|
|
|
24
26
|
connection.socket.send(payload);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
|
-
export const sandboxClient = defineEndpointClient('sandbox');
|
package/lib/endpoint.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { type Locale } from 'zhin.js/i18n';
|
|
2
|
-
import { Endpoint, type
|
|
2
|
+
import { endpointSpec, type Endpoint, type EndpointSpecification } from 'zhin.js/adapter';
|
|
3
3
|
import type { HttpHost } from '@zhin.js/host-http';
|
|
4
4
|
import type { CapabilityId } from 'zhin.js';
|
|
5
|
-
import { type ResolvedSandboxBot } from './protocol.js';
|
|
5
|
+
import { type ResolvedSandboxBot, type SandboxWsSocket, type SandboxConversation } from './protocol.js';
|
|
6
6
|
import { SandboxClient } from './client.js';
|
|
7
|
+
interface SandboxConnection {
|
|
8
|
+
readonly connectionId: string;
|
|
9
|
+
readonly target: string;
|
|
10
|
+
readonly owner: string;
|
|
11
|
+
readonly socket: SandboxWsSocket;
|
|
12
|
+
readonly release: () => void;
|
|
13
|
+
readonly canExecute: boolean;
|
|
14
|
+
conversation: SandboxConversation;
|
|
15
|
+
scoped: boolean;
|
|
16
|
+
/** true = 占位连接(尚无真实 WS 客户端),send 命中时按 miss 处理。 */
|
|
17
|
+
readonly placeholder?: boolean;
|
|
18
|
+
}
|
|
7
19
|
type ShellIsolationStatus = Readonly<{
|
|
8
20
|
available: boolean;
|
|
9
21
|
provider: 'docker';
|
|
@@ -29,18 +41,9 @@ export interface SandboxEndpointOptions {
|
|
|
29
41
|
* Sandbox 是本地开发/测试面,无平台社交图谱(好友/群/频道),
|
|
30
42
|
* 不适用 EndpointManagement 语义端口;本 endpoint 不暴露该端口。
|
|
31
43
|
*/
|
|
32
|
-
export declare class SandboxWsEndpoint extends
|
|
44
|
+
export declare class SandboxWsEndpoint extends SandboxClient<SandboxConnection> implements Endpoint {
|
|
33
45
|
#private;
|
|
34
|
-
readonly
|
|
46
|
+
readonly [endpointSpec]: EndpointSpecification;
|
|
35
47
|
constructor(options: SandboxEndpointOptions);
|
|
36
|
-
/** Live endpoint id (config `id`) — Console endpoint.list/resolve uses it. */
|
|
37
|
-
get name(): string;
|
|
38
|
-
/** The Sandbox transport is the mounted local listener, not a remote account. */
|
|
39
|
-
get transportState(): 'open' | 'idle';
|
|
40
|
-
start(): void;
|
|
41
|
-
open(): void;
|
|
42
|
-
close(): void;
|
|
43
|
-
stop(): void;
|
|
44
|
-
send({ conversation, payload }: EndpointSendRequest): string;
|
|
45
48
|
}
|
|
46
49
|
export {};
|