@linxin666/dsh-remote-bridge 0.4.7 → 0.4.8

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.
@@ -95,7 +95,14 @@ export declare class WebSocketCarrier implements BridgeTransport {
95
95
  onClose(handler: () => void): void;
96
96
  /** Feed raw bytes from the socket into the frame loop. */
97
97
  feed(chunk: Buffer): void;
98
- /** Send one text frame. */
98
+ /**
99
+ * Record the peer's `frame.deflate.v1` declaration, as `hello` reported it.
100
+ *
101
+ * It defaults to off, so a connection that never declares the capability keeps
102
+ * the text frame this carrier always wrote, byte for byte.
103
+ */
104
+ frameDeflate(declared: boolean): void;
105
+ /** Send one frame: the text itself, or raw DEFLATE of it as a binary frame. */
99
106
  send(text: string): void;
100
107
  /** Send a close frame and end the socket. Idempotent. */
101
108
  close(code: number, reason: string): void;
@@ -35,6 +35,21 @@ export declare const inject: string[];
35
35
  export declare const ROSTER_PATH = "remote-bridge/devices.json";
36
36
  /**
37
37
  * Mount the bridge.
38
+ *
39
+ * Guarded by the family's single-instance rule: the aggregate row
40
+ * (`web-ui-remote-bridge`) and a standalone install of this same package can
41
+ * both be live in one profile, and the second mount would otherwise register
42
+ * `/ios/v1` and the token route a second time. Whichever source mounts first
43
+ * owns the package name; the other is queued and replayed when that owner
44
+ * disposes.
38
45
  * @param ctx - the plugin's context, carrying the gateway and web server.
39
46
  */
40
- export declare function apply(ctx: Context): void;
47
+ declare function applyImpl(ctx: Context): void;
48
+ /**
49
+ * The plugin's mount point: {@link applyImpl} behind the family's
50
+ * single-instance guard. The name is the npm package identity, which every
51
+ * install source of this plugin shares — the aggregate's `web-ui-remote-bridge`
52
+ * row and the standalone `remote-bridge` row alike.
53
+ */
54
+ export declare const apply: typeof applyImpl;
55
+ export {};
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Host single-instance guard shared by the plugin family. The family bundle
3
+ * (dsh-web-all / dsh-skins) namespaces every child row id (web-ui-*), so
4
+ * the loader accepts a standalone install of the same package side by side;
5
+ * without this guard the second instance would still re-register the same
6
+ * webserver routes, tools, settings namespaces, and system-prompt sections
7
+ * and fail the boot. mountOnce makes a mount of an already-mounted package a
8
+ * no-op for as long as the first instance lives (the browser half is already
9
+ * deduped by package name in the client module host).
10
+ *
11
+ * A no-op is only safe while the holder is ALIVE. The holder can be disposed
12
+ * long after the refused mount ran its course: the Host reloads a profile by
13
+ * creating the new loader entries before the old ones are torn down (a
14
+ * plugin-manager enable/disable/install write, a settings-driven row reload,
15
+ * HMR), so the new aggregate shell entry mounts its family plugin while the
16
+ * previous entry still owns the name. Dropping that refused mount lost the
17
+ * plugin for good - the previous entry then disposed its own mount, releasing
18
+ * the name with nobody left to take it, and the family row stayed listed as
19
+ * active while its host routes 404ed (the task-board panel showed
20
+ * "board.hostError.notMounted", no degraded record appeared, and only a Host
21
+ * restart recovered it).
22
+ *
23
+ * The refused mount is therefore QUEUED, not dropped, and replayed the moment
24
+ * the holder releases the name - if the waiting fiber is still alive then. The
25
+ * single-instance guarantee is unchanged: exactly one mount is live per
26
+ * package name, and the replay re-enters the guard so a later mount still
27
+ * dedupes against it.
28
+ *
29
+ * The registry rides a global symbol so two module instances of the same
30
+ * package (npm copy vs repository link) still share one verdict. That symbol
31
+ * is a CROSS-REPOSITORY contract, not this file's private state: the four
32
+ * satellite packages (dsh-skins / dsh-pet / dsh-presets /
33
+ * dsh-community-plugins) are separate repositories carrying their own copy of
34
+ * this guard, rebuilt on their own schedule, so the value under `MOUNTED`
35
+ * must keep the shape every published copy reads (a `Set` of package names
36
+ * with `has`/`add`/`delete`). The wait queues this guard added therefore live
37
+ * under their own additive key, and the registry reads back a `Set` even when
38
+ * some other build left a different value there. Changing `MOUNTED`'s shape
39
+ * in place broke that contract once: a satellite's legacy copy created a
40
+ * `Set`, the family's new copy read it as a `Map`, and every family row
41
+ * mounted after it failed with "claims.get is not a function".
42
+ *
43
+ * cordis `ctx.effect` runs its callback immediately and treats the callback's
44
+ * return value as the fiber disposer, so the unmarker is returned, not run.
45
+ */
46
+ /**
47
+ * Wrap a cordis plugin apply so the package runs at most once per process.
48
+ * The first mount registers normally and releases the name when its fiber
49
+ * disposes; a mount refused while that name is held waits for the release and
50
+ * then runs, unless its own fiber disposes first.
51
+ * @param packageName - npm package identity shared by every install source.
52
+ * @param fn - the original plugin apply.
53
+ * @returns an apply of the same shape.
54
+ */
55
+ export declare function mountOnce<T extends (...args: any[]) => unknown>(packageName: string, fn: T): T;
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Remote bridge",
4
+ "description": "Serve DSH as protocol v1 over one paired WebSocket route for native clients."
5
+ }
6
+ }
package/locale/ru.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Удалённый мост",
4
+ "description": "Публикует DSH как протокол v1 для нативных клиентов после сопряжения."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "远程桥接",
4
+ "description": "为原生手机端提供配对后的协议 v1 通道"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-remote-bridge",
3
3
  "description": "DSH remote bridge: the host half serves protocol v1 over one exact /ios/v1 WebSocket route — session roster, history baseline, prompting, live turn increments with tool activity, interrupt, and in-process agent approval — to a device paired by a one-shot bootstrap token and a P-256 challenge-response, with the token endpoint admitted only from this machine; the browser half adds one sidebar-foot panel that shows that same one-shot token as a QR symbol, and no wire surface",
4
- "version": "0.4.7",
4
+ "version": "0.4.8",
5
+ "icon": "./icon.svg",
5
6
  "type": "module",
6
7
  "engines": {
7
8
  "node": "^22.19.0 || >=24.0.0"
@@ -18,6 +19,9 @@
18
19
  "default": "./lib/client.js"
19
20
  },
20
21
  "./src/*": "./src/*",
22
+ "./locale/en.json": "./locale/en.json",
23
+ "./locale/ru.json": "./locale/ru.json",
24
+ "./locale/zh.json": "./locale/zh.json",
21
25
  "./package.json": "./package.json"
22
26
  },
23
27
  "files": [
@@ -26,7 +30,9 @@
26
30
  "lib/**/*.d.ts",
27
31
  "lib/**/*.d.ts.map",
28
32
  "src",
29
- "cordis.patch.yml"
33
+ "cordis.patch.yml",
34
+ "icon.svg",
35
+ "locale"
30
36
  ],
31
37
  "license": "Apache-2.0",
32
38
  "dsh": {
@@ -39,8 +39,25 @@ export interface ApprovalPrompt {
39
39
  readonly answer: Promise<ApprovalAnswer>
40
40
  }
41
41
 
42
+ /**
43
+ * One live question as a second delivery publishes it.
44
+ *
45
+ * The same four fields the first broadcast carries, so a card a phone was shown
46
+ * and the same card handed to it again after a reconnect cannot be spelled
47
+ * differently.
48
+ */
49
+ export interface PendingPromptView {
50
+ readonly id: string
51
+ readonly sessionId: string
52
+ readonly toolName: string
53
+ readonly summary: string
54
+ }
55
+
42
56
  /** One live question. */
43
57
  interface PendingPrompt {
58
+ readonly sessionId: string
59
+ readonly toolName: string
60
+ readonly summary: string
44
61
  readonly settle: (answer: ApprovalAnswer) => void
45
62
  readonly timer: NodeJS.Timeout
46
63
  readonly detached: () => void
@@ -74,6 +91,20 @@ export class ApprovalRegistry {
74
91
  return this.#pending.size
75
92
  }
76
93
 
94
+ /**
95
+ * Every question still waiting for a phone, in claim order.
96
+ *
97
+ * Only a live claim can be named here: {@link #settle} is the single path out
98
+ * of the pending map, and an answer, the bridge's own timeout, the agent's
99
+ * cancellation and every withdrawal all pass through it before this reads the
100
+ * map again. A question this bridge released therefore cannot come back to a
101
+ * client that reconnects.
102
+ * @returns the fields a second delivery republishes, oldest claim first.
103
+ */
104
+ openPrompts(): readonly PendingPromptView[] {
105
+ return [...this.#pending].map(([id, entry]) => ({ id, sessionId: entry.sessionId, toolName: entry.toolName, summary: entry.summary }))
106
+ }
107
+
77
108
  /**
78
109
  * Claim one question.
79
110
  * @param input - session identity, tool name, presentation summary, and the agent's own lifetime.
@@ -89,7 +120,7 @@ export class ApprovalRegistry {
89
120
  const signal = input.signal
90
121
  const detached = signal === undefined ? (): void => undefined : (): void => { signal.removeEventListener('abort', withdraw) }
91
122
  signal?.addEventListener('abort', withdraw, { once: true })
92
- this.#pending.set(id, { settle, timer, detached })
123
+ this.#pending.set(id, { sessionId: input.sessionId, toolName: input.toolName, summary: input.summary, settle, timer, detached })
93
124
  return { id, sessionId: input.sessionId, toolName: input.toolName, summary: input.summary, answer }
94
125
  }
95
126