@linxin666/dsh-remote-bridge 0.4.15 → 0.4.17
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/README.i18n.yaml +2 -2
- package/README.md +11 -6
- package/README.zh.md +11 -6
- package/lib/client.js.map +1 -1
- package/lib/index.js +980 -413
- package/lib/types/core/approvals.d.ts +10 -0
- package/lib/types/core/attachment-paths.d.ts +89 -0
- package/lib/types/core/connection.d.ts +8 -0
- package/lib/types/core/hub.d.ts +33 -26
- package/lib/types/core/protocol.d.ts +39 -1
- package/lib/types/core/questions.d.ts +20 -4
- package/lib/types/core/wire.d.ts +8 -0
- package/lib/types/index.d.ts +2 -16
- package/package.json +14 -14
- package/src/core/approvals.ts +13 -0
- package/src/core/attachment-paths.ts +288 -0
- package/src/core/connection.ts +160 -2
- package/src/core/hub.ts +155 -156
- package/src/core/protocol.ts +41 -1
- package/src/core/questions.ts +61 -14
- package/src/core/wire.ts +9 -0
- package/src/index.ts +3 -25
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# node scripts/verify-docs.mjs --write <dir>
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 9d734cffc206d476df5b975eebbd3077d21a039b
|
|
6
|
+
README.zh.md: 6b9152398c4640b44f3933d5a0ce85038cd58b8c
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ English | [中文](README.zh.md)
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="https://img.shields.io/npm/v/@linxin666/dsh-remote-bridge?style=flat-square" alt="Version">
|
|
7
7
|
|
|
8
|
-
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.2-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
9
|
|
|
10
10
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
11
|
</p>
|
|
@@ -49,12 +49,13 @@ The package publishes one protocol and, beside it, one small browser surface. Wh
|
|
|
49
49
|
|
|
50
50
|
| method | request `p` | response `r` |
|
|
51
51
|
| --- | --- | --- |
|
|
52
|
-
| `hello` | `{proto:1, minor:17, client:"ios/0.1", cap:["session.snapshot.trim.v1","subagent.thread.v1"]}` | `{proto:1, minor:
|
|
52
|
+
| `hello` | `{proto:1, minor:17, client:"ios/0.1", cap:["session.snapshot.trim.v1","subagent.thread.v1"]}` | `{proto:1, minor:22, server:"dsh-remote-bridge", capabilities:["session.snapshot.trim.v1","session.snapshot.page.v1","questions.v1","questions.list.v1","subagent.thread.v1","jobs.v1","agents.v1","delta.v1","session.list.omit-archived.v1","session.deep-history.v1","frame.deflate.v1","session.list.compact.v1","session.snapshot.since.v1","session.fork.v1","commands.v1","workspace.v1","session.admin.v1","squads.v1","push.v1","usage.v1","usage.stats.v1","ui.v1","ui.list.v1","session.attachment.path.v1"], resume:"snapshot", auth:"paired" or "unpaired"}` |
|
|
53
53
|
| `session.list` | `{since?, cwd?, maxRows?, after?}` | `{mode, token, sessions:[{id, title, updatedAt, agentRunning, cwd?, parentSessionId?, origin?, blank, archived?}]}`, or `{mode:"reset", token:"", compact:true, sessions:[...], nextAfter?}` for a compact page |
|
|
54
54
|
| `session.titles` | `{ids:[<sessionId>, ...]}` | `{titles:{"<id>":"<title>", ...}}` |
|
|
55
55
|
| `session.snapshot` | `{sessionId, sinceSeq?, maxBytes?}` | `{turns:[...], lastSeq:<uint>, hasMore?}`, plus `mode:"since", reset:false` for an increment and `mode:"full", reset:true` for a baseline that replaces the copy a client holds |
|
|
56
56
|
| `session.history` | `{sessionId, before?, maxBytes?}` | `{turns:[...], nextBefore?:<uint>, hasMore:<bool>}` |
|
|
57
57
|
| `session.history.deep` | `{sessionId, before?, maxBytes?}` | `{turns:[...], nextBefore?:<uint>, hasMore:<bool>}` |
|
|
58
|
+
| `session.attachment.path` | `{sessionId, path}` | `{image:{path, mediaType?, bytes?, width?, height?}, data:"<base64>"}` — the reference the session's own record stated, beside the bytes at that path. The path must be absolute and byte-identical to one the session named; `path-not-in-session`, `not-found`, `not-an-image` or `frame-too-large` answers instead |
|
|
58
59
|
| `session.prompt` | `{sessionId, text, requestId}` | `{accepted:true}` |
|
|
59
60
|
| `session.interrupt` | `{sessionId}` | `{ok:true}` |
|
|
60
61
|
| `presets.list` | `{}` | the host's `agentPresets/list` body verbatim |
|
|
@@ -135,7 +136,7 @@ A compact listing is the roster's other form, and it takes both halves to appear
|
|
|
135
136
|
|
|
136
137
|
An `approval.request` carries a summary taken from the harness's display reason in the client's language, falling back to English and then to the tool name, plus the tool name itself. The client answers it with `approval.resolve`, whose `decision` is either `allowed-once` or `rejected`; an unknown or expired `id` is refused, and a request nobody answers is resolved after two minutes as unavailable, which the harness reads as a rejection. Every paired connection receives the event the moment the tool asks — the first broadcast is behind no capability — and a connection that declared `approvals.v1` in `hello` is handed every still-waiting request again, so a phone that reconnected, or a session screen opened after the fact, still holds a card. Only an unsettled request is replayed: one that was answered, timed out or withdrawn is gone from the claim registry, and re-handing a request never moves its two-minute deadline. The capability gates that second delivery and nothing else, which is why it is absent from `hello`'s `capabilities` and leaves `minor` alone: the handshake answers every client the same frame. The bridge claims an approval request only while a paired client is connected: with none, the request is left to the next answerer instead of waiting out a phone that is not there.
|
|
137
138
|
|
|
138
|
-
The question channel is the one claim that outlives the socket. A question arrives as a `question.request` event under the host's own call id, or under one this bridge mints when a blocking ask carries none, and `question.answer` settles the host's ask: while that ask is still open the answer resolves the promise the bridge holds, and once the host's deadline has released the model a late answer takes the host's Remote `answer` path instead.
|
|
139
|
+
The question channel is the one claim that outlives the socket. A question arrives as a `question.request` event under the host's own call id, or under one this bridge mints when a blocking ask carries none, and `question.answer` settles the host's ask: while that ask is still open the answer resolves the promise the bridge holds, and once the host's deadline has released the model a late answer takes the host's Remote `answer` path instead. Claiming yields to the host's own answerer chain the instant the claim exists, so both sides hold the card and the first answer wins: a host answer broadcasts `question.request` with `state:"settled"` and releases the claim, while a phone answer resolves the bridge's promise and leaves a later host settlement ignored; a host chain that rejects is not a verdict and leaves the claim answerable. `question.list` answers the questions the bridge is still holding, which is what a phone reconciles the cards it carries against. With no paired connection on the wire, but a device on the roster that registered for push, the bridge still claims the question, sends the alert when no live browser client is connected, and yields to the host's answerer chain at once: the claim lives until it is answered, the host's deadline ends it, or the bridge unloads, and it is given up if APNs refuses every registered token on the roster. Approvals keep the stricter rule above, where nothing is ever claimed for a phone that is not on the wire.
|
|
139
140
|
|
|
140
141
|
The interactive-reply channel is the one place a page travels instead of a question. `ui_present` is this bridge's own model tool: the agent writes one whole self-contained document (`<!doctype html>` first, at most 256 KiB of UTF-8) and it crosses as a `ui.request` event under the host's own `ToolCallId`, so the card hangs on the same tool-call row the transcript already draws. The call then blocks until the user's FIRST action inside the page arrives, and that action — `{type, payload?}` with `type` the page's own closed set and `payload` at most 8 KiB — is the tool call's result: one card settles one action, and a page that should keep taking them is presented again. The card is announced over as `state:"settled"` to every client that declared `ui.v1`, including the one that acted, so a second tap on the phone and a second phone both learn it is over. `ui.list` answers the cards this bridge still holds, which is what a phone reconciles against after a restart, and only a complete answer may retire one. A card never carries `expiresAt`: the tool schema declares no `timeout`, so this bridge invents no deadline, and it takes the same grace window as a question instead — a page nobody can answer any more is released to the agent as a timeout when the window the last paired device left behind runs out, and a phone that declares the channel inside that window is handed the live card and cancels the release. With no paired connection that declared `ui.v1`, `ui_present` answers `{ok:false, reason:"unavailable"}` at once instead of holding the agent. Every result of a page that did reach the wire carries the presentation payload as `meta.ui` — `{key, title?, html, height?, state}` with `key` spelled `"<sessionId>/<callId>"` — for a client that renders the card out of the transcript and holds no `ui.request` socket; the body of the result stays one human sentence.
|
|
141
142
|
|
|
@@ -150,7 +151,7 @@ The package publishes one generic seam and puts no vocabulary of its own in it.
|
|
|
150
151
|
|
|
151
152
|
A registered method is dispatched after both protocol gates: a name no plugin registered answers `unknown-method` before anything else runs, a client without a live device token answers `unpaired` exactly as it does for a protocol method, and a client that never declared the table's capability is told `unknown-method` — the method is absent from its protocol rather than forbidden to it. The handler receives the request payload and the calling connection's id, and answers `{ok:true, r}` or `{ok:false, code, msg}`; the bridge forwards either verbatim, because refusal codes belong to the registering plugin. A handler that throws, or answers neither shape, crosses as the bridge's own `internal`.
|
|
152
153
|
|
|
153
|
-
`hello` answers `minor:
|
|
154
|
+
`hello` answers `minor:22`, since the image-by-path channel shipped: behind `session.attachment.path.v1` — an announcement and nothing more, exactly as `session.deep-history.v1` is — a client may call `session.attachment.path` and read the bytes of one image the session's own durable transcript named, either the offload placeholder a message body carries or the image reference a durable tool result published, so it reads one new reply body off the wire and has to read the name before it asks. The method is open to every paired connection: the name is how a client learns it exists, never what lets the bridge serve it, and a client that does not declare it loses only that knowledge. No frame, no topic and no existing method changes shape. `minor:21` was when the interactive-reply channel shipped: it adds two capability names (`ui.v1`, `ui.list.v1`), one topic (`ui.request`), two methods (`ui.event`, `ui.list`) and one model tool (`ui_present`), so a client reads two new names, a new event and two new reply bodies off the wire, and no existing frame, method or key changes shape. `minor:20` was when the usage stats channel shipped: behind `usage.stats.v1` a client may call `usage.stats` and read the host's own ledger, and `usage.session` may answer `modelContextWindow` from the route's model catalog, so it reads one new reply body and one new optional key off the wire and has to read the name before it asks — a bridge below this one answers `unknown-method` and omits the key, and no frame, topic or existing method changes shape. `minor:19` was when the usage channel shipped: behind `usage.v1` a client may call `usage.session` and `usage.balance`, so it read two new reply bodies off the wire and had to read the name before it asked — a bridge below that one answers `unknown-method` for both. `minor:18` was when one lock-screen card learned to lay out several sessions: `content-state` may now carry `rows`, at most three `{name, status, phase}` items, ordered by the bridge — the sessions waiting on the user first, in the order their questions arrived, then the sessions running now, most recently updated first — so no method, no capability name and no existing key changes shape, and the minor rises by one. A row's `name` is the host's own title with its trailing path group taken off, because the wire carries no paths. `minor:17` was when the live-activity channel shipped: the lock-screen card is driven by the registration surface `push.v1` already carries, and this bridge gained only the sending path — a `liveactivity` push of one session's own state. `minor:16` was when the notification channel shipped: behind `push.v1` a client may call `push.register` and have the device table remember an APNs token, so a phone learns a turn ended — or that a question is waiting — while its own socket is not open. `minor:15` was when the squads channel shipped: behind `squads.v1` a client may call `squads.state`, `squads.list`, `squads.runs`, `squads.runMember` and `squads.runSquad`, so it reads five new reply bodies off the wire and drives the host's squad domain instead of deriving agents from anything else. `minor:14` was when the session-admin channel shipped: behind `workspace.v1` a client may call `workspace.list` and read the host's workspaces with both registry-global session sets, and behind `session.admin.v1` it may rename, pin, unpin, archive and unarchive a session, so it reads six new reply bodies off the wire. `minor:13` was when the question list shipped: behind `questions.list.v1` a client may call `question.list` and be answered the questions this bridge is still holding — the set a phone reconciles the cards it holds against, and the only way it learns that a question ended while it was away, because the bridge withdraws every claim when the last paired device leaves. `minor:12` was when the command channel shipped: behind `commands.v1` a client may call `session.commands` and `session.command`, so it reads a new reply body off the wire. `minor:11` was when the fork channel shipped, one step above the snapshot-`since` channel that landed on the integration branch first: behind `session.fork.v1` a client may call `session.fork` and be answered the host's own fork result. `minor:10` was when the snapshot became incremental on request: behind `session.snapshot.since.v1` a `session.snapshot` that names `sinceSeq` is answered either the entries above that watermark or a full baseline carrying `mode` and `reset`, so the number rises for a reply shape a client reads off the wire. `minor:9` was when the compact roster shipped: behind `session.list.compact.v1` a listing that names `cwd`, `maxRows` or `after` is answered a shorter row that may be paged, so the number rises for a row schema a client reads off the wire. `minor:8` was when the outbound frame form became a capability: behind `frame.deflate.v1` a declaring client may be answered in binary frames carrying raw DEFLATE of the text, so the number is raised for something a client reads off the wire. `minor:7` was when the two channels met; `minor:6` was either channel on its own — the agent channel on dev and durable history paging on its branch; `minor:5` was when the roster stopped carrying archived sessions. Behind `agents.v1`, `presets.list` and `session.create` forward the host's preset roster and one creation request; behind `session.deep-history.v1`, `session.history.deep` pages a session's durable store back to its first entry; behind `session.fork.v1`, `session.fork` branches one session into a new one that inherits it. `minor:4` added byte-level increments, `minor:3` the background-job channel, `minor:2` the subagent thread, and `minor:1` was this seam. Major 1 and every frozen field, method name and topic name are unchanged by all of them. The one body that shrank for every client rather than only for those that declare a capability is the roster itself, which no longer names an archived session; every other answer a client that declares nothing receives is protocol v1's own.
|
|
154
155
|
|
|
155
156
|
## Error codes
|
|
156
157
|
|
|
@@ -168,7 +169,9 @@ A registered method is dispatched after both protocol gates: a name no plugin re
|
|
|
168
169
|
| `snapshot-too-large` | the opening snapshot cannot be shrunk to one frame: even a single turn does not fit |
|
|
169
170
|
| `squads-unavailable` | this host serves no `dsh-agents` squad domain this bridge can reach: no answer on the plugin's loopback route, no readable ledger beside it, or a body this build cannot read as one domain. A squads read is never answered with an empty board, and a refusal the plugin itself raised crosses with the plugin's own code instead |
|
|
170
171
|
| `squads-run-unavailable` | the definitions are readable but the two run commands cannot be served: no loopback run route could be reached, and the read-only ledger cannot launch a session. Answering a run that never started is the one thing this channel will not do |
|
|
171
|
-
| `
|
|
172
|
+
| `path-not-in-session` | `session.attachment.path` named a path this session's own durable transcript never did — a path the client chose, or one whose `realpath()` resolves somewhere other than itself |
|
|
173
|
+
| `not-found` | the whitelist names the path, but no regular file is there any more: it was deleted, or a directory, device or fifo stands in its place |
|
|
174
|
+
| `not-an-image` | the file's own first bytes are none of PNG, JPEG, WebP or GIF. The extension is never consulted |
|
|
172
175
|
| `frame-too-large` | the frame exceeded the 10 MiB cap and was not parsed |
|
|
173
176
|
| `malformed` | the frame is not one JSON object with a recognizable shape |
|
|
174
177
|
| `direction-violation` | the client sent a `res` or `ev` frame, which only the host sends |
|
|
@@ -276,7 +279,7 @@ The plugin is configured through profile YAML (`cordis.patch.yml` or profile con
|
|
|
276
279
|
|
|
277
280
|
## Web GUI pairing panel
|
|
278
281
|
|
|
279
|
-
The browser half exists so that an operator who never opens a terminal still has a way to start pairing. It follows the family's sidebar-foot convention: the trigger registers into the official `sidebar.footer.action` list slot (declared by ui-sidebar,
|
|
282
|
+
The browser half exists so that an operator who never opens a terminal still has a way to start pairing. It follows the family's sidebar-foot convention: the trigger registers into the official `sidebar.footer.action` list slot (declared by ui-sidebar, the same list slot the family's other foot triggers use) and opens the official `Modal`, whose headless card this package fills. Every control it renders is a library primitive — the dialog, the three actions and their glyphs — so the mask, the card, the focus trap, Escape, focus restoration and each hover/focus/disabled state are the shell's behavior rather than a copy of it. It is delivered by the same plugin row: `exports["./client"]` is the artifact and `dsh.client` declares the client modules that must be live first.
|
|
280
283
|
|
|
281
284
|
The panel has one job — put the live one-time code in front of the operator, in one reading order:
|
|
282
285
|
|
|
@@ -353,6 +356,7 @@ The bridge is mounted like any other host plugin row. It carries no user-facing
|
|
|
353
356
|
- **The token comparison does not leak length.** It is a fixed-length comparison rather than an early-exit one, so a wrong token cannot be narrowed byte by byte.
|
|
354
357
|
- **Approvals fail closed while a client is connected.** The bridge claims a tool's permission request only while at least one paired client is connected; with none, the request goes to the next answerer rather than stalling. A claimed request that nobody answers normalizes to `unavailable`, which the harness treats as a rejection: silence from the phone is never consent.
|
|
355
358
|
- **The header is the safer carrier.** `Authorization: Bearer <deviceToken>` keeps the credential out of the URL; `?token=` exists for clients that cannot set handshake headers, and the relay, the edge and the access log all see a URL that authenticates as that device.
|
|
359
|
+
- **An image is served only from the session that named it.** `session.attachment.path` answers a file's bytes only when the string it was handed is, byte for byte, a path that session's OWN durable transcript named: an offload placeholder in a message body, or the image reference a durable tool result published. The whitelist is computed from that session's store and from nothing else — the same durable read `session.history.deep` performs, behind the same fence, so a delegated child whose parent this connection may not read is refused before any store call — and a client never contributes a path to it. Four decisions then stand between the whitelist and the bytes: byte equality, `realpath()` resolving the path to itself (a symlink pointing anywhere else is refused rather than followed), a regular file at that path, and one of the four image signatures in its first bytes; the extension is never consulted. Nothing outside the whitelist is read, and no directory is ever listed. A path that is not a host absolute path is not a whitelist entry at all, so `browser_screenshot`'s plugin-namespace name — which has no file behind it — can never be asked for.
|
|
356
360
|
- **Relay tier routing and grant credential boundaries.** The device roster (`devices.json`) schema upgrades from 3 to 4, adding an optional `relay: {grant, receivedAt}` to each device row. That `grant` is a 30-day HS256 credential signed by the account service, handed from the phone to the host over an **authenticated, paired connection**; the host merely passes it verbatim in the claim request body. The host therefore still does not know who the account is or what tier it holds: it only knows whether it holds a lease admitted by the relay. Tier evaluation occurs in a single loopback request between the self-hosted relay and the account service; the relay writes quotas into the lease row without recording any user identifier. The `hello.relay` announcement, capability identifier `relay.tier.v1`, and the `relay.grant` frame **exist only when a second meeting point is configured**; without configuration, the handshake is byte-for-byte identical to today, and that frame answers `unknown-method`. The two configuration keys are `relaySecondaryControlUrl` and `relaySecondaryPublicSuffix`, both unconfigured by default.
|
|
357
361
|
|
|
358
362
|
## Known limitations
|
|
@@ -372,6 +376,7 @@ The bridge is mounted like any other host plugin row. It carries no user-facing
|
|
|
372
376
|
- **Roster edits apply on the next host start.** The roster is read once per process, so removing a device takes effect when `dsh web` restarts.
|
|
373
377
|
- **The panel shows one code and nothing else.** It cannot list, name or revoke paired devices, and it never spends a code — pairing happens on the phone, and revocation stays a roster edit plus a host restart.
|
|
374
378
|
- **The panel is only as fresh as its last read.** It reads a code when it opens and on every **New code** press; a code that expires while the panel stays open flips to the expiry state instead of silently renewing itself.
|
|
379
|
+
- **A whitelist is computed per session watermark, not per request.** `session.attachment.path` walks a session's whole durable store to build its whitelist, which on the longest session this host holds (5,680 entries, 6.0 MiB compressed) costs 40.8 ms to inflate and 108 ms to inflate and parse — paid once per store page, and two pages at the bridge's own window. A connection therefore remembers the last four sessions' whitelists, keyed by the `asOfSeq` they were read at and evicting the least recently used one, so a request arriving under the same watermark is answered without a walk; any committed event moves the watermark and forces a fresh one. This is not a cache of image bytes — those are read from disk on every call, exactly as `session.attachment` reads them.
|
|
375
380
|
- **`scripts/client.mjs` is a check harness, not a client SDK.** It runs the fixed sequence once, keeps no state and has no reconnect logic.
|
|
376
381
|
- **A card's own subframes are not blocked on the desktop.** The phone refuses a nested `<iframe>` inside a card as a cross-document jump; a sandboxed frame here has no equivalent interception point, so a page's own subframe renders while every frame keeps its opaque origin.
|
|
377
382
|
- **The keyed registration reaches its slot through a local seam.** The SDK package that declares `tool.call.toolview` is not a dependency of this package, so the slot is reached through a narrowed `ctx.slots` port that mirrors the owner's stage union; taking that package as a devDependency replaces the seam with the SDK's own types.
|
package/README.zh.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="https://img.shields.io/npm/v/@linxin666/dsh-remote-bridge?style=flat-square" alt="Version">
|
|
7
7
|
|
|
8
|
-
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.2-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
9
|
|
|
10
10
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
11
|
</p>
|
|
@@ -48,12 +48,13 @@
|
|
|
48
48
|
|
|
49
49
|
| 方法 | 请求 `p` | 响应 `r` |
|
|
50
50
|
| --- | --- | --- |
|
|
51
|
-
| `hello` | `{proto:1, minor:17, client:"ios/0.1", cap:["session.snapshot.trim.v1","subagent.thread.v1"]}` | `{proto:1, minor:
|
|
51
|
+
| `hello` | `{proto:1, minor:17, client:"ios/0.1", cap:["session.snapshot.trim.v1","subagent.thread.v1"]}` | `{proto:1, minor:22, server:"dsh-remote-bridge", capabilities:["session.snapshot.trim.v1","session.snapshot.page.v1","questions.v1","questions.list.v1","subagent.thread.v1","jobs.v1","agents.v1","delta.v1","session.list.omit-archived.v1","session.deep-history.v1","frame.deflate.v1","session.list.compact.v1","session.snapshot.since.v1","session.fork.v1","commands.v1","workspace.v1","session.admin.v1","squads.v1","push.v1","usage.v1","usage.stats.v1","ui.v1","ui.list.v1","session.attachment.path.v1"], resume:"snapshot", auth:"paired" 或 "unpaired"}` |
|
|
52
52
|
| `session.list` | `{since?, cwd?, maxRows?, after?}` | `{mode, token, sessions:[{id, title, updatedAt, agentRunning, cwd?, parentSessionId?, origin?, blank, archived?}]}`;紧凑页为 `{mode:"reset", token:"", compact:true, sessions:[...], nextAfter?}` |
|
|
53
53
|
| `session.titles` | `{ids:[<sessionId>, ...]}` | `{titles:{"<id>":"<title>", ...}}` |
|
|
54
54
|
| `session.snapshot` | `{sessionId, sinceSeq?, maxBytes?}` | `{turns:[...], lastSeq:<uint>, hasMore?}`;增量另加 `mode:"since", reset:false`,替换客户端副本的基线另加 `mode:"full", reset:true` |
|
|
55
55
|
| `session.history` | `{sessionId, before?, maxBytes?}` | `{turns:[...], nextBefore?:<uint>, hasMore:<bool>}` |
|
|
56
56
|
| `session.history.deep` | `{sessionId, before?, maxBytes?}` | `{turns:[...], nextBefore?:<uint>, hasMore:<bool>}` |
|
|
57
|
+
| `session.attachment.path` | `{sessionId, path}` | `{image:{path, mediaType?, bytes?, width?, height?}, data:"<base64>"}` — the reference the session's own record stated, beside the bytes at that path. The path must be absolute and byte-identical to one the session named; `path-not-in-session`, `not-found`, `not-an-image` or `frame-too-large` answers instead |
|
|
57
58
|
| `session.prompt` | `{sessionId, text, requestId}` | `{accepted:true}` |
|
|
58
59
|
| `session.interrupt` | `{sessionId}` | `{ok:true}` |
|
|
59
60
|
| `presets.list` | `{}` | 宿主 `agentPresets/list` 的身体,逐字转发 |
|
|
@@ -132,7 +133,7 @@ fork 的方法同样什么都不解释。`session.fork` 把 `sessionId` 与客
|
|
|
132
133
|
|
|
133
134
|
`approval.request` 的摘要取自宿主按客户端语言给出的显示理由,缺失时回落英文、再回落工具名,并附带工具名本身。客户端用 `approval.resolve` 作答,`decision` 取 `allowed-once` 或 `rejected`;未知或过期的 `id` 会被拒绝,而无人应答的请求在两分钟后按 unavailable 结算,宿主视之为拒绝。工具发起请求的那一刻,每一条已配对连接都会收到该事件——首播不在任何能力名之后——而声明了 `approvals.v1` 的连接会在 `hello` 之后再次收到所有仍在等待的请求,因此重连过的手机、或事后才打开该会话的界面,手里依然有卡片。只有未结算的请求会被重放:已作答、已超时、已撤回的请求早已离开认领表,而重新递一次请求绝不会挪动它的两分钟截止时间。该能力只门控这第二次送达,因此它不出现在 `hello` 的 `capabilities` 里、也不改动 `minor`:握手对每个客户端都回同一个帧。桥只在下游有已配对客户端连接时才认领审批请求:一个都没有时,请求交给下一个应答者,而不是干等一台不在场的手机。
|
|
134
135
|
|
|
135
|
-
提问通道是唯一一条能比套接字活得久的认领。提问以 `question.request` 事件到达手机,call id 用宿主自己的;阻塞式提问没有 call id,就由本桥另铸一个。手机用 `question.answer` 结算宿主的询问:询问仍然开着时,答案直接解开本桥手里的 promise;宿主自己的截止时间已经放走模型之后,迟到的答案改走宿主的 Remote `answer
|
|
136
|
+
提问通道是唯一一条能比套接字活得久的认领。提问以 `question.request` 事件到达手机,call id 用宿主自己的;阻塞式提问没有 call id,就由本桥另铸一个。手机用 `question.answer` 结算宿主的询问:询问仍然开着时,答案直接解开本桥手里的 promise;宿主自己的截止时间已经放走模型之后,迟到的答案改走宿主的 Remote `answer`。认领成立即刻让位给宿主自己的应答者链,两端同时持有卡片,先答者胜:宿主链先答时,桥向已声明 `questions.v1` 的连接广播 `state:"settled"` 的 `question.request` 并释放认领;手机先答时,桥返回手机的答案并忽略宿主链随后到达的结算;宿主链 reject 不是判决,认领保留,手机仍可作答。`question.list` 回答本桥此刻仍持有的提问,手机据此与手里的卡对账。没有任何已配对连接在线、但设备名册里有登记过推送令牌的设备时,桥照旧替那台手机认领这道题、在宿主没有在线浏览器客户端时发推送,并立刻让位给宿主自己的应答者链:认领活到被答、宿主自己的截止时间到点或本桥卸载;若 APNs 对名册上每个已登记令牌都拒绝,则放弃这次认领。审批沿用上面更严的那条规则:永远不为不在线上的手机认领任何东西。
|
|
136
137
|
|
|
137
138
|
可交互回复是唯一一条「走一整页而不是走一个问题」的通道。`ui_present` 是本桥自己的模型工具:agent 写一整份自包含文档(以 `<!doctype html>` 开头,UTF-8 最多 256 KiB),它作为 `ui.request` 事件、用宿主自己的 `ToolCallId` 下发,于是这张卡正好挂在转录里那条工具调用行上。随后这次调用阻塞,直到用户在页面里的**第一条**动作为止——那个动作 `{type, payload?}`(`type` 是页面自己的闭集,`payload` 最多 8 KiB)就是这次工具调用的返回值:一张卡结算一个动作,需要继续接受动作就让 agent 再呈现一次。结算时这条卡以 `state:"settled"` 对每个声明了 `ui.v1` 的客户端再公告一次(包括刚作答的那台),所以手机上重复的第二次点击、以及第二台手机都能读到它已结束。`ui.list` 回答本桥此刻仍持有的卡,是手机重启后的对账依据,且只有 `complete` 的应答才允许退休一张卡。卡永不携带 `expiresAt`:工具 schema 不声明 `timeout`,本桥也就不发明超时;它拿的是与提问同一个宽限窗口——再没有人能作答的卡在「最后一次配对设备离开」留下的窗口到期时,以超时交还给 agent,而在这个窗口内声明了通道的手机则被重放活卡、并取消这次释放。没有任何声明了 `ui.v1` 的已配对连接时,`ui_present` 立即回 `{ok:false, reason:"unavailable"}`,不占用宿主的等待。真的到过线缆上的那次呈现,其结果在 `meta.ui` 里带着同一份展示载荷——`{key, title?, html, height?, state}`,`key` 是 `"<sessionId>/<callId>"` 拼法——供从转录渲染、手里没有 `ui.request` socket 的客户端使用;结果正文仍是一句人可读的话。
|
|
138
139
|
|
|
@@ -147,7 +148,7 @@ fork 的方法同样什么都不解释。`session.fork` 把 `sessionId` 与客
|
|
|
147
148
|
|
|
148
149
|
已注册方法的派发排在两道协议闸门之后:没有插件注册的名字最先回 `unknown-method`;没有有效设备令牌的连接回 `unpaired`,与协议方法完全一致;从未声明该表所需能力的客户端同样回 `unknown-method`——方法对它而言不存在,而不是没有权限。处理器收到请求载荷与本连接 id,回 `{ok:true, r}` 或 `{ok:false, code, msg}`;两种都原样穿过,因为错误码归注册它的插件所有。处理器抛错、或两种形状都没回时,以桥自己的 `internal` 穿过。
|
|
149
150
|
|
|
150
|
-
`hello` 现在回 `minor:21
|
|
151
|
+
`hello` 现在回 `minor:22`,起自按路径取图通道落地:`session.attachment.path.v1` 只是一个公告(与 `session.deep-history.v1` 同例),名字背后客户端可以调 `session.attachment.path`,读回这次会话自己的持久记录点过的某一张图的字节——来源要么是消息体里的 offload 占位符,要么是持久工具结果发布的那个图像引用——因此它从线上读到一种新的应答体,并且必须先读到这个名字才敢问。这个方法对每一条已配对连接都开放:能力名只决定客户端知不知道它存在,不决定桥放不放行,不声明这个名字的客户端只是少了这份知情。没有任何既有帧、既有主题或既有方法改形状。`minor:21` 是当时可交互回复通道落地:它新增两个能力名(`ui.v1`、`ui.list.v1`)、一个主题(`ui.request`)、两个方法(`ui.event`、`ui.list`)与一个模型工具(`ui_present`),因此客户端从线缆上读到两个新名字、一种新事件与两种新应答体,而任何既有帧、方法与键都不改形状。`minor:20` 是用量台账通道落地时:`usage.stats.v1` 背后,客户端可以调 `usage.stats` 读宿主自己的台账,`usage.session` 也多了可选的 `modelContextWindow`(取自那条路由的模型目录),因此它从线缆上读到一个新的应答体和一个新的可选键,并且必须先读到这个名字才敢问——低于这一版的桥回 `unknown-method`、也不带那个键,而任何帧、主题与既有方法都不改形状。`minor:19` 是用量通道落地:`usage.v1` 背后,客户端可以调 `usage.session` 与 `usage.balance`,因此它从线缆上读到两个新的应答体,并且必须先读到这个名字才敢问——低于那一版的桥对两者都回 `unknown-method`。`minor:18` 是「一张实况卡排下几个会话」:`content-state` 可以带 `rows`,最多三项 `{name, status, phase}`,顺序由桥定——先提问中的会话(按提问到达顺序),再正在跑的会话(按最近更新倒序)——因此不新增方法、不新增能力名、也不改动任何既有键,`minor` 只加一。行的 `name` 是宿主自己的标题摘掉尾部路径组的结果,因为线上不许出现路径。`minor:17` 是实况卡推送落地:锁屏卡与灵动岛由 `push.v1` 既有的登记面驱动,桥侧只新增发送路径(`liveactivity` 推送、按会话投影的 `SessionActivityState`)。`minor:16` 是通知推送通道落地:`push.v1` 背后,客户端可以调 `push.register`,让设备表记住自己的 APNs 令牌,于是回合结束或出现待答提问时手机会被叫醒,而它自己的 socket 并没有开着。`minor:15` 是小队通道落地:`squads.v1` 背后,客户端可以调 `squads.state`、`squads.list`、`squads.runs`、`squads.runMember` 与 `squads.runSquad`,因此它从线上读到五种新的应答体,并驱动宿主的小队域而不是从别处推导 agent。`minor:14` 是会话管理通道落地:`workspace.v1` 背后,客户端可以调 `workspace.list` 并读到宿主的工作区与两个全局会话集合;`session.admin.v1` 背后,它可以改名、置顶、取消置顶、归档与取消归档一条会话,因此它从线上读到六种新的应答体。`minor:13` 是待答提问列表落地:`questions.list.v1` 背后,客户端可以调 `question.list`,拿回本桥此刻仍持有的提问——手机据此对账它手里的卡,也是它得知「自己离线时某个提问已经结束」的唯一途径,因为最后一个配对设备离开时,桥会撤回全部认领。`minor:12` 是指令通道落地之时:`commands.v1` 背后,客户端可以调 `session.commands` 与 `session.command`,因此它从线上读到一种新的应答体。`minor:11` 是 fork 通道落地之时(比先一步在集成分支上落地的快照增量通道高一位):`session.fork.v1` 背后,客户端可以调 `session.fork` 并拿到宿主自己的 fork 结果。`minor:10` 是快照可按请求增量之时:`session.snapshot.since.v1` 背后,带 `sinceSeq` 的 `session.snapshot` 要么只回该水位之上的 entry,要么回一份带 `mode` 与 `reset` 的完整基线,所以这一位是为客户端能从线上读到的应答形状而提的。`minor:9` 是紧凑名册之时:`session.list.compact.v1` 背后,带 `cwd`、`maxRows` 或 `after` 的列出得到更短、且可分页的行,所以这一位是为客户端能从线上读到的行 schema 而提的。`minor:8` 是下行帧的形态本身成为一种能力之时:`frame.deflate.v1` 背后,声明了的客户端可能收到承载裸 DEFLATE 的 binary 帧,所以这一位是为客户端能从线上读到的东西而提的。`minor:7` 是两条通道汇合之时;`minor:6` 是其中任一条单独在位——agent 通道在 dev 上,持久历史分页在它自己的分支上;`minor:5` 时是名册不再携带已归档会话。`agents.v1` 背后,`presets.list` 与 `session.create` 转发宿主的预设名册与一次创建请求;`session.deep-history.v1` 背后,`session.history.deep` 把会话的持久存储一直翻到最早一条 entry;`session.fork.v1` 背后,`session.fork` 把一条会话分叉成继承它的新会话。`minor:4` 加了字节级增量,`minor:3` 是后台作业通道,`minor:2` 是子代理线程,`minor:1` 是本扩展缝。它们都没有改动主版本 1、任何冻结字段、方法名或主题名。唯一对每个客户端都变短的响应体是名册本身,它不再点名已归档会话;其余答案对什么都不声明的客户端仍是协议 v1 自己的。
|
|
151
152
|
|
|
152
153
|
## 错误码
|
|
153
154
|
|
|
@@ -165,7 +166,9 @@ fork 的方法同样什么都不解释。`session.fork` 把 `sessionId` 与客
|
|
|
165
166
|
| `snapshot-too-large` | 开帧快照无法压缩进单帧:连一个回合都放不下 |
|
|
166
167
|
| `squads-unavailable` | 本宿主没有本桥能到达的 `dsh-agents` 小队域:插件 loopback 路由没有应答、旁边没有可读的账本,或者应答体不是本构建读得懂的那一个域。小队读取从不以空板回答,而插件自己抛出的拒绝带着插件自己的码穿过 |
|
|
167
168
|
| `squads-run-unavailable` | 定义读得到,但两条运行指令服务不了:到达不了任何 loopback 运行路由,只读账本也启动不了会话。回一个从未启动的运行是这条通道唯一不做的事 |
|
|
168
|
-
| `
|
|
169
|
+
| `path-not-in-session` | `session.attachment.path` 点名的路径不在这次会话自己的持久 transcript 里——客户端自选的路径,或 `realpath()` 解析后不再等于它自己的那种 |
|
|
170
|
+
| `not-found` | 白名单里有这个路径,但那里已经没有常规文件:被删了,或被换成了目录、设备或 fifo |
|
|
171
|
+
| `not-an-image` | 文件自己的头几个字节不是 PNG、JPEG、WebP 或 GIF 中的任何一种;扩展名一律不作数 |
|
|
169
172
|
| `frame-too-large` | 该帧超过 10 MiB 上限,未被解析 |
|
|
170
173
|
| `malformed` | 该帧不是形状可辨的单个 JSON 对象 |
|
|
171
174
|
| `direction-violation` | 客户端发来了只有宿主才发的 `res` 或 `ev` 帧 |
|
|
@@ -273,7 +276,7 @@ curl -s http://127.0.0.1:3080/remote-bridge/pair/token
|
|
|
273
276
|
|
|
274
277
|
## Web GUI 配对面板
|
|
275
278
|
|
|
276
|
-
浏览器半区存在的理由,是让从不开终端的操作者也有一条发起配对的路径。它沿用家族在侧栏底部的惯例:触发器注册进官方 `sidebar.footer.action` 列表槽位(由 ui-sidebar
|
|
279
|
+
浏览器半区存在的理由,是让从不开终端的操作者也有一条发起配对的路径。它沿用家族在侧栏底部的惯例:触发器注册进官方 `sidebar.footer.action` 列表槽位(由 ui-sidebar 声明,与家族其它脚部触发器共用该列表槽位),点开后是官方 `Modal`,这张无头卡片由本包填充。它渲染的每个控件都是库里已有的 primitive——弹窗、三个动作与它们的字形——因此遮罩、卡片、焦点圈定、Esc、焦点归还,以及每个 hover/focus/disabled 状态都是官方壳自己的行为,而不是本包的一份复制品。它由同一插件行承载:产物是 `exports["./client"]`,`dsh.client` 声明必须先就位的 client 模块。
|
|
277
280
|
|
|
278
281
|
面板只做一件事——把活着的那个一次性配对码摆到操作者面前,且只有这一个阅读顺序:
|
|
279
282
|
|
|
@@ -350,6 +353,7 @@ dsh plugin --profile web add link:$(pwd)/packages/dsh-remote-bridge
|
|
|
350
353
|
- **令牌比对不泄漏长度。** 用的是定长比较而非提前返回的比较,因此错误令牌无法被逐字节逼近。
|
|
351
354
|
- **审批在客户端在线时 fail closed。** 只要还有一个已配对客户端在线,桥才认领工具的权限请求;一个都没有时,请求交给下一个应答者而不是卡住。已认领而无人应答的审批会被归一为 `unavailable`,宿主按拒绝处理:手机沉默永远不等于同意。
|
|
352
355
|
- **header 是更安全的载体。** `Authorization: Bearer <deviceToken>` 让凭据不进入 URL;`?token=` 是给无法设置握手 header 的客户端的,此时中继、边缘与访问日志都会看到一条以该设备身份鉴权的 URL。
|
|
356
|
+
- **一张图只能由点过它的那条会话取。** `session.attachment.path` 只在拿到的字符串逐字节等于**这次会话自己的持久 transcript** 点过的某个路径时才回字节:来源是消息体里的 offload 占位符,或持久工具结果发布的图像引用。白名单每次请求都从该会话自己的存储现算,别的什么都不读——走的就是 `session.history.deep` 那条持久读面、同一道栅栏,所以父会话不是本连接可读的委派子会话在任何存储调用之前就被拒——而客户端一个路径都贡献不了。白名单与字节之间还立着四道判定:逐字节相等、`realpath()` 必须解析回它自己(指向别处的软链接被拒而不是被跟随)、那里必须是常规文件、头几个字节必须是四种图像签名之一;扩展名一律不看。白名单之外的文件一个都不读,也不会去列目录。不是宿主绝对路径的条目根本不进白名单,所以 `browser_screenshot` 那个磁盘上没有对应文件的插件命名空间名永远发不出去。
|
|
353
357
|
- **中继档位分流与授权凭据边界。** 名册(`devices.json`)schema 3 → 4,每台设备行新增可选的 `relay: {grant, receivedAt}`。那枚 `grant` 是账号服务签发的 30 天 HS256 凭据,经**已配对的加密连接**由手机交给宿主,宿主只把它原样放进 claim 请求体。宿主因此仍然不知道账号是谁、也不知道档位:它只知道「我有没有一份被中继承认的租约」。档位判定发生在自建中继与账号服务之间的一次回环请求里,中继只把额度写进租约行,不落任何用户标识。`hello.relay`、能力名 `relay.tier.v1`、`relay.grant` 这一帧**只在配置了第二个会合点时才存在**;不配置时握手逐字节等于今天,那一帧回 `unknown-method`。两个配置项名:`relaySecondaryControlUrl` 与 `relaySecondaryPublicSuffix`,缺省都不配置。
|
|
354
358
|
|
|
355
359
|
## 已知限制
|
|
@@ -369,6 +373,7 @@ dsh plugin --profile web add link:$(pwd)/packages/dsh-remote-bridge
|
|
|
369
373
|
- **名册改动在下一次宿主启动时生效。** 名册每个进程只读一次,因此移除设备要等 `dsh web` 重启才起作用。
|
|
370
374
|
- **面板只显示一个配对码,别的都不做。** 它不能列出、命名或吊销已配对设备,也从不消耗配对码——配对发生在手机上,吊销仍然是改名册加重启宿主。
|
|
371
375
|
- **面板的新鲜度只到它上一次取码为止。** 它在打开时取一次码,之后每按一次「重新取码」再取一次;一直开着时过期的码会翻成过期状态,而不会自己悄悄续期。
|
|
376
|
+
- **白名单按会话水位算,不按请求算。** `session.attachment.path` 要读完一条会话的整份持久存储才能算出白名单,在宿主当前最长的那条会话上(5680 条 entry、压缩后 6.0 MiB)解压要 40.8 ms、解压加解析要 108 ms,而这条路按桥自己的窗口一次要翻两页,每页都付一次。因此每条连接只记住最近四个会话的白名单,键是读它时的那个 `asOfSeq`,最久没用的先逐出:同一水位下的第二次请求不再翻页,而任何一条事件落盘都会推高水位、逼出一次重算。这不是图像字节的缓存——字节每次调用都从磁盘直取,与 `session.attachment` 完全一致。
|
|
372
377
|
- **`scripts/client.mjs` 是检查用的工具,不是客户端 SDK。** 它只按固定顺序跑一遍,不保存状态,也没有重连逻辑。
|
|
373
378
|
- **卡片自己的子帧在桌面端没有被拦。** 手机端把卡片里的嵌套 `<iframe>` 当作跨文档跳转一律拒绝;这里沙箱化的画框没有等价的拦截点,所以页面自己的子帧仍会渲染,只是每一帧都保持不透明源。
|
|
374
379
|
- **keyed 注册经由一条本地缝到达槽位。** 声明 `tool.call.toolview` 的那个 SDK 包不是本包的依赖,因此槽位是经窄化后的 `ctx.slots` 端口到达的,端口里镜像了 owner 的阶段联合;把那个包收作 devDependency 后,这条缝会被 SDK 自己的类型替掉。
|