dsh-browser-firefox 0.3.3 → 0.4.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/lib/protocol.js CHANGED
@@ -3,13 +3,19 @@
3
3
  * Wire contract between the dsh bridge plugin and the browser extension.
4
4
  *
5
5
  * Zero-dependency module (pure types, constants, and a parser): both the
6
- * plugin (node) and the Chrome extension (browser bundle) import this file, so
7
- * the frame shapes can never drift between the two halves.
6
+ * plugin (node) and the Firefox extension (browser bundle) import this file,
7
+ * so the frame shapes can never drift between the two halves.
8
8
  *
9
9
  * Frames are one JSON object per WebSocket message, discriminated by `t`.
10
10
  * Correlation ids (`id`) are minted by the requestor and echoed by the
11
11
  * responder; they are opaque strings, never parsed.
12
12
  *
13
+ * The RPC/stream vocabulary is the alpha Typert Remote dialect verbatim:
14
+ * methods are slash-joined endpoints (`session/create`), `args` is the Remote
15
+ * descriptor's native args object (`{ request: {...} }`, `{ _request: {} }`),
16
+ * and stream frames carry the native Session/Workspace follow frames
17
+ * unmodified.
18
+ *
13
19
  * @module
14
20
  */
15
21
  /** WebSocket pathname the bridge plugin registers on the host webserver. */
@@ -24,13 +30,13 @@ const PING_INTERVAL_MS = 3e4;
24
30
  const DEFAULT_TOKEN_BYTES = 32;
25
31
  /**
26
32
  * Type guard: is this frame one the SERVER may send? Client-only shapes
27
- * (hello/tool.result/pong) narrow out, so server-side consumers never
28
- * dispatch on their own request vocabulary.
33
+ * (hello/rpc/stream.open/stream.close/tool.result/pong) narrow out, so
34
+ * server-side consumers never dispatch on their own request vocabulary.
29
35
  * @param frame - parsed frame.
30
36
  * @returns true for server-sendable frames.
31
37
  */
32
38
  function isServerFrame(frame) {
33
- return frame.t === "hello.ok" || frame.t === "rpc.result" || frame.t === "event" || frame.t === "tool.call" || frame.t === "tool.cancel" || frame.t === "ping" || frame.t === "error";
39
+ return frame.t === "hello.ok" || frame.t === "rpc.result" || frame.t === "stream.frame" || frame.t === "stream.error" || frame.t === "tool.call" || frame.t === "tool.cancel" || frame.t === "ping" || frame.t === "error";
34
40
  }
35
41
  /**
36
42
  * Type guard: is this frame one the CLIENT may send? Server-only shapes
@@ -39,7 +45,11 @@ function isServerFrame(frame) {
39
45
  * @returns true for client-sendable frames.
40
46
  */
41
47
  function isClientFrame(frame) {
42
- return frame.t === "hello" || frame.t === "rpc" || frame.t === "tool.result" || frame.t === "pong";
48
+ return frame.t === "hello" || frame.t === "rpc" || frame.t === "stream.open" || frame.t === "stream.close" || frame.t === "tool.result" || frame.t === "pong";
49
+ }
50
+ /** Wire args must be a plain object (the Remote descriptor's named arguments). */
51
+ function isArgs(value) {
52
+ return typeof value === "object" && value !== null && !Array.isArray(value);
43
53
  }
44
54
  /**
45
55
  * Parse one WebSocket message into a frame.
@@ -62,11 +72,21 @@ function parseBridgeFrame(text) {
62
72
  token: frame.token,
63
73
  caps: frame.caps
64
74
  } : void 0;
65
- case "rpc": return typeof frame.id === "string" && typeof frame.method === "string" ? {
75
+ case "rpc": return typeof frame.id === "string" && typeof frame.method === "string" && isArgs(frame.args) ? {
66
76
  t: "rpc",
67
77
  id: frame.id,
68
78
  method: frame.method,
69
- payload: frame.payload
79
+ args: frame.args
80
+ } : void 0;
81
+ case "stream.open": return typeof frame.id === "string" && typeof frame.method === "string" && isArgs(frame.args) ? {
82
+ t: "stream.open",
83
+ id: frame.id,
84
+ method: frame.method,
85
+ args: frame.args
86
+ } : void 0;
87
+ case "stream.close": return typeof frame.id === "string" ? {
88
+ t: "stream.close",
89
+ id: frame.id
70
90
  } : void 0;
71
91
  case "tool.result":
72
92
  if (typeof frame.id !== "string") return void 0;
@@ -89,22 +109,28 @@ function parseBridgeFrame(text) {
89
109
  } : void 0;
90
110
  case "rpc.result":
91
111
  if (typeof frame.id !== "string") return void 0;
92
- if (frame.ok === true && "result" in frame) return {
112
+ if (frame.ok === true && "value" in frame) return {
93
113
  t: "rpc.result",
94
114
  id: frame.id,
95
115
  ok: true,
96
- result: frame.result
116
+ value: frame.value
97
117
  };
98
- return typeof frame.error === "object" && frame.error !== null ? {
118
+ return isWireFailure(frame.error) ? {
99
119
  t: "rpc.result",
100
120
  id: frame.id,
101
121
  ok: false,
102
122
  error: frame.error
103
123
  } : void 0;
104
- case "event": return typeof frame.frame === "object" && frame.frame !== null ? {
105
- t: "event",
124
+ case "stream.frame": return typeof frame.id === "string" ? {
125
+ t: "stream.frame",
126
+ id: frame.id,
106
127
  frame: frame.frame
107
128
  } : void 0;
129
+ case "stream.error": return typeof frame.id === "string" && typeof frame.message === "string" ? {
130
+ t: "stream.error",
131
+ id: frame.id,
132
+ message: frame.message
133
+ } : void 0;
108
134
  case "tool.call":
109
135
  if (typeof frame.id !== "string" || typeof frame.name !== "string") return void 0;
110
136
  if (typeof frame.args !== "object" || frame.args === null || Array.isArray(frame.args)) return void 0;
@@ -139,5 +165,8 @@ function isCaps(value) {
139
165
  function isToolError(value) {
140
166
  return typeof value === "object" && value !== null && typeof value.code === "string" && typeof value.message === "string";
141
167
  }
168
+ function isWireFailure(value) {
169
+ return typeof value === "object" && value !== null && typeof value.code === "string" && typeof value.message === "string";
170
+ }
142
171
  //#endregion
143
172
  export { BRIDGE_CONFIG_PATH, BRIDGE_PATH, DEFAULT_TOKEN_BYTES, HELLO_TIMEOUT_MS, PING_INTERVAL_MS, isClientFrame, isServerFrame, parseBridgeFrame };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Session event pump: the alpha replacement for the rc `events.mux` SSE
3
+ * aggregate. alpha exposes per-session `session/follow` Remote streams, so
4
+ * this module maintains one follow stream per session the extension has
5
+ * touched and fans their event frames out to every connected bridge client,
6
+ * translated back to the rc `session/event` mux shape the extension renders.
7
+ *
8
+ * Snapshot frames are never replayed: the panel reconciles through
9
+ * `session.history` at turn boundaries, so replaying the opening window would
10
+ * duplicate rows it already drew.
11
+ *
12
+ * @module
13
+ */
14
+ import type { TypertGateway } from '@deepseek-ai/dsh-api-gateway/types';
15
+ import type { SessionWireEvent } from '@deepseek-ai/dsh-api-session-controller/types';
16
+ /** One translated event envelope, the bridge's local replacement for rc MuxFrame pushes. */
17
+ export interface SessionEventEnvelope {
18
+ readonly rpcId: string;
19
+ readonly payload: {
20
+ readonly type: 'session/event';
21
+ readonly sessionId: string;
22
+ readonly event: SessionWireEvent;
23
+ };
24
+ }
25
+ /**
26
+ * Multiplex `session/follow` streams onto bridge event subscribers. Shared by
27
+ * all connections of one plugin instance; dispose with {@link close}.
28
+ */
29
+ export declare class SessionEventMux {
30
+ private readonly gateway;
31
+ private readonly warn;
32
+ private readonly listeners;
33
+ private readonly streams;
34
+ private readonly warned;
35
+ private closed;
36
+ constructor(gateway: TypertGateway, warn: (message: string) => void);
37
+ /**
38
+ * Record that the extension addressed this session. The first touch opens
39
+ * the session's follow stream; later touches are no-ops.
40
+ */
41
+ touch(sessionId: string): void;
42
+ /** Stop every follow stream and drop all subscribers. */
43
+ close(): void;
44
+ /**
45
+ * Subscribe one bridge connection: yields translated `session/event`
46
+ * envelopes until the signal aborts. Late subscribers hear only future
47
+ * events — history reconciliation owns the backlog.
48
+ */
49
+ openEvents(signal: AbortSignal): AsyncIterable<SessionEventEnvelope>;
50
+ /**
51
+ * One session's follow loop. Event frames are translated and broadcast;
52
+ * failures reopen the stream after {@link FOLLOW_RETRY_MS} until the mux is
53
+ * closed (a stream can outlive its session's visibility, and transient
54
+ * resume failures must not silence a live session).
55
+ */
56
+ private follow;
57
+ private broadcast;
58
+ }
59
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1,87 @@
1
+ /**
2
+ * rc→alpha gateway translation for the bridge RPC path.
3
+ *
4
+ * The browser extension speaks the rc-line bridge protocol: dot-joined method
5
+ * names (`session.create`) and rc-shaped response envelopes. The alpha line
6
+ * removed `ctx.apiProxy`; its `/api` carrier expects slash-joined endpoints
7
+ * (`session/create`) and a strict `{ args: { request | _request } }` payload
8
+ * envelope. This module is the ONLY place that knows both dialects: unary
9
+ * methods are re-enveloped onto Connection's shared fetch handler, while
10
+ * `workspace.list` and `session.history` (deleted in alpha) are synthesized
11
+ * from the `workspace/follow` and `session/follow` Remote streams.
12
+ *
13
+ * @module
14
+ */
15
+ import type { ConnectionFetchHandler } from '@deepseek-ai/dsh-client-connection';
16
+ import type { TypertGateway } from '@deepseek-ai/dsh-api-gateway/types';
17
+ /** Success/failure result inside one server-response body. */
18
+ export type GatewayResult = {
19
+ readonly ok: true;
20
+ readonly value: unknown;
21
+ } | {
22
+ readonly ok: false;
23
+ readonly error: {
24
+ readonly code: string;
25
+ readonly message: string;
26
+ readonly details?: object;
27
+ };
28
+ };
29
+ /** The response body relayed verbatim as the extension's `rpc.result.result`. */
30
+ export interface GatewayResponse {
31
+ readonly type: 'server-response';
32
+ readonly rpcId: string;
33
+ readonly result: GatewayResult;
34
+ }
35
+ /**
36
+ * One dispatch of a bridge RPC frame: dot-joined method plus the extension's
37
+ * raw payload, answered with the rc-shaped server-response body. Business
38
+ * failures ride the envelope (`result.ok: false`); only carrier-level
39
+ * failures reject (see {@link GatewayDispatchError}).
40
+ */
41
+ export type RpcDispatch = (rpcId: string, method: string, payload: unknown) => Promise<GatewayResponse>;
42
+ /** Carrier-level dispatch failure; `code` becomes the `rpc.result` error code. */
43
+ export declare class GatewayDispatchError extends Error {
44
+ readonly code: 'http' | 'internal';
45
+ constructor(code: 'http' | 'internal', message: string);
46
+ }
47
+ /** Wrap one business value in the rc-shaped server-response body. */
48
+ export declare function okResponse(rpcId: string, value: unknown): GatewayResponse;
49
+ /** Wrap one business failure in the rc-shaped server-response body. */
50
+ export declare function failResponse(rpcId: string, code: string, message: string, details?: object): GatewayResponse;
51
+ /** Callback the gateway uses to report sessions the extension has addressed. */
52
+ export type TouchSession = (sessionId: string) => void;
53
+ export interface BridgeGatewayDeps {
54
+ /** Authenticated `/api` carrier from `ctx.connection.createSharedFetchHandler('/api')`. */
55
+ readonly fetchHandler: ConnectionFetchHandler;
56
+ /** Live Typert Remote dispatcher (stream methods only; unary goes through the carrier). */
57
+ readonly gateway: TypertGateway;
58
+ /** Notified with every session id the extension addresses (drives the event pump). */
59
+ readonly touch: TouchSession;
60
+ /** Logger for degraded synthesized methods. */
61
+ readonly warn: (message: string) => void;
62
+ }
63
+ /**
64
+ * The bridge's alpha gateway face: unary translation onto the shared `/api`
65
+ * carrier plus the two synthesized rc methods. Construct once per plugin
66
+ * instance; wrap with the session-workspace/session-deferral interceptors,
67
+ * then hand the outermost {@link RpcDispatch} to the bridge server.
68
+ */
69
+ export declare class BridgeGateway {
70
+ private readonly deps;
71
+ private readonly workspaces;
72
+ constructor(deps: BridgeGatewayDeps);
73
+ /** Bound dispatch, safe to wrap and hand to the bridge server. */
74
+ readonly dispatch: RpcDispatch;
75
+ /** Start the workspace/follow stream backing `workspace.list`. */
76
+ start(): void;
77
+ /** Stop owned streams (plugin dispose). */
78
+ close(): void;
79
+ private dispatchImpl;
80
+ /**
81
+ * alpha has no `session/history`: one short-lived `session/follow` stream
82
+ * supplies its opening snapshot, whose records replay exactly what the rc
83
+ * tail page carried (`{ event }` entries plus `hasMore`).
84
+ */
85
+ private sessionHistory;
86
+ }
87
+ //# sourceMappingURL=gateway.d.ts.map
@@ -4,11 +4,13 @@
4
4
  *
5
5
  * The bridge mounts its own upgrade route (`/ext/bridge`) on the host
6
6
  * webserver, OUTSIDE the /api trust fence — so it brings its own bearer-token
7
- * authentication (first frame `hello` within HELLO_TIMEOUT_MS). Gateway RPCs
8
- * from the extension are dispatched through the same fetch-shaped handler the
9
- * /api carrier uses, and session events are pumped per connection. Tools
10
- * execute by dispatching `tool.call` frames to the connected extension, which
11
- * performs the action in the user's active tab.
7
+ * authentication (first frame `hello` within HELLO_TIMEOUT_MS). The wire
8
+ * protocol IS the alpha Typert Remote dialect: unary `rpc` frames carry
9
+ * slash-joined endpoints and native args objects straight into
10
+ * `ctx.typertGateway.invoke`, and `stream.open` frames open
11
+ * `ctx.typertGateway.stream` subscriptions whose native follow frames flow
12
+ * back unmodified. Tools execute by dispatching `tool.call` frames to the
13
+ * connected extension, which performs the action in the user's active tab.
12
14
  *
13
15
  * Opt-in by design: nothing is registered unless this plugin appears in the
14
16
  * composition. No dsh core code is touched.
@@ -2,13 +2,19 @@
2
2
  * Wire contract between the dsh bridge plugin and the browser extension.
3
3
  *
4
4
  * Zero-dependency module (pure types, constants, and a parser): both the
5
- * plugin (node) and the Chrome extension (browser bundle) import this file, so
6
- * the frame shapes can never drift between the two halves.
5
+ * plugin (node) and the Firefox extension (browser bundle) import this file,
6
+ * so the frame shapes can never drift between the two halves.
7
7
  *
8
8
  * Frames are one JSON object per WebSocket message, discriminated by `t`.
9
9
  * Correlation ids (`id`) are minted by the requestor and echoed by the
10
10
  * responder; they are opaque strings, never parsed.
11
11
  *
12
+ * The RPC/stream vocabulary is the alpha Typert Remote dialect verbatim:
13
+ * methods are slash-joined endpoints (`session/create`), `args` is the Remote
14
+ * descriptor's native args object (`{ request: {...} }`, `{ _request: {} }`),
15
+ * and stream frames carry the native Session/Workspace follow frames
16
+ * unmodified.
17
+ *
12
18
  * @module
13
19
  */
14
20
  /** WebSocket pathname the bridge plugin registers on the host webserver. */
@@ -22,7 +28,7 @@ export declare const PING_INTERVAL_MS = 30000;
22
28
  /** Default bytes of the generated bearer token (256-bit). */
23
29
  export declare const DEFAULT_TOKEN_BYTES = 32;
24
30
  /** Error codes a tool call may settle with. Open set: consumers must tolerate unknown codes. */
25
- export type ToolErrorCode = 'no-active-tab' | 'content-unavailable' | 'action-failed' | 'timeout' | 'bridge-closed' | 'bad-args' | 'internal';
31
+ export type ToolErrorCode = 'no-active-tab' | 'content-unavailable' | 'action-failed' | 'timeout' | 'bridge-closed' | 'bad-args' | 'approval-denied' | 'cancelled' | 'internal';
26
32
  /** One tool-call failure: stable machine code plus human text for the model. */
27
33
  export interface ToolError {
28
34
  code: ToolErrorCode;
@@ -37,6 +43,20 @@ export interface BridgeCaps {
37
43
  /** Upper bound on interactive inventory items per snapshot (plugin config). */
38
44
  maxInteractiveItems: number;
39
45
  }
46
+ /** One Remote failure as plain wire data (RemoteError's message is non-enumerable, so it is restated explicitly). */
47
+ export interface RemoteWireFailure {
48
+ code: string;
49
+ message: string;
50
+ details?: object;
51
+ }
52
+ /** The RemoteResult wire form answered to one `rpc` frame. */
53
+ export type RemoteWireResult = {
54
+ ok: true;
55
+ value: unknown;
56
+ } | {
57
+ ok: false;
58
+ error: RemoteWireFailure;
59
+ };
40
60
  /** Frames sent by the extension to the bridge plugin. */
41
61
  export type ClientFrame =
42
62
  /** First frame, within HELLO_TIMEOUT_MS of socket open. */
@@ -45,12 +65,24 @@ export type ClientFrame =
45
65
  token: string;
46
66
  caps: BridgeCaps;
47
67
  }
48
- /** Unary gateway RPC passthrough (method names from the apiproxy RpcMethodMap). */
68
+ /** Unary Remote call: slash-joined endpoint plus the descriptor's native args object. */
49
69
  | {
50
70
  t: 'rpc';
51
71
  id: string;
52
72
  method: string;
53
- payload: unknown;
73
+ args: Record<string, unknown>;
74
+ }
75
+ /** Open one Remote stream (`session/follow`, `workspace/follow`); frames arrive as `stream.frame`. */
76
+ | {
77
+ t: 'stream.open';
78
+ id: string;
79
+ method: string;
80
+ args: Record<string, unknown>;
81
+ }
82
+ /** Cancel one open stream. */
83
+ | {
84
+ t: 'stream.close';
85
+ id: string;
54
86
  }
55
87
  /** Result of a previously dispatched tool call. */
56
88
  | {
@@ -75,29 +107,29 @@ export type ServerFrame =
75
107
  t: 'hello.ok';
76
108
  caps: BridgeCaps;
77
109
  }
78
- /** Reply to an `rpc` frame; `result` is the apiproxy ServerResponse envelope. */
110
+ /** Reply to an `rpc` frame: the RemoteResult wire form, flattened onto the frame. */
79
111
  | {
80
112
  t: 'rpc.result';
81
113
  id: string;
82
114
  ok: true;
83
- result: unknown;
115
+ value: unknown;
84
116
  } | {
85
117
  t: 'rpc.result';
86
118
  id: string;
87
119
  ok: false;
88
- error: {
89
- code: string;
90
- message: string;
91
- };
120
+ error: RemoteWireFailure;
92
121
  }
93
- /** One gateway event envelope (the same server-request shape the GUI's /api/events.mux carries). */
122
+ /** One native frame of an open stream (SessionFollowFrame / WorkspaceFollowFrame, unmodified). */
94
123
  | {
95
- t: 'event';
96
- frame: {
97
- rpcId: string;
98
- method: string;
99
- payload: unknown;
100
- };
124
+ t: 'stream.frame';
125
+ id: string;
126
+ frame: unknown;
127
+ }
128
+ /** A stream failed (or its open was rejected); the client may reopen it. */
129
+ | {
130
+ t: 'stream.error';
131
+ id: string;
132
+ message: string;
101
133
  }
102
134
  /** A model-requested browser action to execute in the user-controlled tab. `expiresAt` (ms epoch) withdraws the call once the caller stops waiting. */
103
135
  | {
@@ -128,8 +160,8 @@ export type ServerFrame =
128
160
  export type BridgeFrame = ClientFrame | ServerFrame;
129
161
  /**
130
162
  * Type guard: is this frame one the SERVER may send? Client-only shapes
131
- * (hello/tool.result/pong) narrow out, so server-side consumers never
132
- * dispatch on their own request vocabulary.
163
+ * (hello/rpc/stream.open/stream.close/tool.result/pong) narrow out, so
164
+ * server-side consumers never dispatch on their own request vocabulary.
133
165
  * @param frame - parsed frame.
134
166
  * @returns true for server-sendable frames.
135
167
  */
@@ -1,27 +1,36 @@
1
1
  /**
2
- * Bridge WebSocket carrier: token-authenticated connection registry, gateway
3
- * RPC passthrough, per-connection event pump, and tool-call dispatch to the
2
+ * Bridge WebSocket carrier: token-authenticated connection registry, Typert
3
+ * Remote passthrough (unary + streams), and tool-call dispatch to the
4
4
  * connected browser extension.
5
5
  *
6
6
  * The route this server mounts (`/ext/bridge`) lives OUTSIDE the /api trust
7
7
  * fence (which only guards the client-connection routes), so the bridge brings
8
8
  * its own authentication: a bearer token presented in the `hello` frame within
9
- * HELLO_TIMEOUT_MS. Gateway RPCs are dispatched through the same fetch-shaped
10
- * handler the /api carrier uses (`toFetchHandler`), so schema validation and
11
- * error envelopes are identical to the GUI path. Methods the /api carrier
12
- * pins to loopback (`PRIVILEGED_METHODS`) stay loopback-only here regardless
13
- * of the token, defense in depth for `--host 0.0.0.0` deployments.
9
+ * HELLO_TIMEOUT_MS. RPC and stream frames speak the alpha Typert dialect
10
+ * verbatim: slash-joined endpoints, native `args` objects, and unmodified
11
+ * follow frames. Methods the bridge pins to loopback (`PRIVILEGED_METHODS`)
12
+ * stay loopback-only here regardless of the token, defense in depth for
13
+ * `--host 0.0.0.0` deployments.
14
14
  *
15
15
  * One active connection at a time: a new authenticated socket replaces the
16
- * previous one (the old socket is closed and its in-flight tool calls settle
17
- * as `bridge-closed`).
16
+ * previous one (the old socket is closed, its in-flight tool calls settle as
17
+ * `bridge-closed`, and its streams are aborted).
18
18
  *
19
19
  * @module
20
20
  */
21
21
  import type { IncomingMessage } from 'node:http';
22
22
  import type { Duplex } from 'node:stream';
23
- import type { MuxFrame, RpcRequest } from '@deepseek-ai/dsh-host-apiproxy/api';
24
- import { type BridgeCaps, type ToolErrorCode } from './protocol.ts';
23
+ import { type BridgeCaps, type RemoteWireResult, type ToolErrorCode } from './protocol.ts';
24
+ /**
25
+ * Gateway endpoints the bridge pins to loopback (the rc line's
26
+ * PRIVILEGED_METHODS, restated against the alpha Remote endpoint names:
27
+ * settings/credentials mutation and host-desktop/filesystem actions). The
28
+ * bridge rejects these for non-loopback remotes even with a valid token.
29
+ * Exported so tests can tripwire the list against accidental shrinkage —
30
+ * when the host line adds new privileged endpoints, extend this set in the
31
+ * same commit.
32
+ */
33
+ export declare const PRIVILEGED_METHODS: Set<string>;
25
34
  /** Loopback IPv4/IPv6 literals (IPv4-mapped included). Exported for tests and reuse. */
26
35
  export declare function isLoopbackAddress(address: string | undefined): boolean;
27
36
  /** Error thrown by requestTool; the tool registry turns it into an isError result. */
@@ -33,12 +42,14 @@ export declare class BridgeToolError extends Error {
33
42
  export interface BridgeServerDeps {
34
43
  /** Bearer token the extension must present in `hello`. */
35
44
  token: string;
36
- /** Fetch-shaped gateway carrier (from `toFetchHandler(ctx.apiProxy)`). */
37
- apiHandler: {
38
- fetch: (request: Request) => Promise<Response>;
39
- };
40
- /** Per-connection event stream (usually `ctx.apiProxy.events.mux`). */
41
- openEvents: (signal: AbortSignal) => AsyncIterable<RpcRequest<MuxFrame>>;
45
+ /**
46
+ * Unary Remote dispatch (slash endpoint + native args), answering the
47
+ * RemoteResult wire form. Plugin-side interceptors (workspace grouping,
48
+ * session deferral) sit on this seam.
49
+ */
50
+ dispatchRpc: (method: string, args: Record<string, unknown>, signal: AbortSignal) => Promise<RemoteWireResult>;
51
+ /** Open one Remote stream (slash endpoint + native args). */
52
+ openStream: (method: string, args: Record<string, unknown>, signal: AbortSignal) => Promise<AsyncIterable<unknown>>;
42
53
  /** Default per-tool-call timeout in ms. */
43
54
  toolTimeoutMs: number;
44
55
  /** Capabilities to echo in `hello.ok` (negotiated snapshot budgets). */
@@ -53,6 +64,14 @@ export interface BridgeServerDeps {
53
64
  helloTimeoutMs?: number;
54
65
  /** Server ping cadence; defaults to PING_INTERVAL_MS. */
55
66
  pingIntervalMs?: number;
67
+ /** Cap on one incoming message in bytes; defaults to 4MiB. */
68
+ maxPayloadBytes?: number;
69
+ /** Pump backpressure threshold (ws bufferedAmount) in bytes; defaults to 4MiB. */
70
+ maxBufferedBytes?: number;
71
+ /** Grace period for stream pumps during close(); defaults to 5000. */
72
+ closePumpTimeoutMs?: number;
73
+ /** Consecutive missed ping cycles before a zombie connection is terminated; defaults to 3. */
74
+ missedPongsAllowed?: number;
56
75
  }
57
76
  /**
58
77
  * Decode one ws message payload to text. Exported so all three delivery
@@ -94,7 +113,7 @@ export declare class BridgeServer {
94
113
  requestTool(name: string, args: Record<string, unknown>, signal: AbortSignal, timeoutMs?: number, sessionId?: string, title?: string): Promise<unknown>;
95
114
  /**
96
115
  * Terminate the server: close the acceptor, drop all sockets, reject all
97
- * in-flight tool calls.
116
+ * in-flight tool calls, abort all streams.
98
117
  * @returns a promise resolving after the acceptor and all pumps stop.
99
118
  */
100
119
  close(): Promise<void>;
@@ -110,9 +129,20 @@ export declare class BridgeServer {
110
129
  * must not reach the gateway until that admission has completed.
111
130
  */
112
131
  private routeRpc;
132
+ /** Whether the connection owning this frame may call the endpoint at all. */
133
+ private forbidden;
113
134
  private handleRpc;
135
+ /** Open one Remote stream and pump its frames until closed, failed, or replaced. */
136
+ private openStream;
137
+ /**
138
+ * Backpressure gate for stream pumps. Returns false when the wait ended
139
+ * because the socket died or the pump was aborted (the caller then stops).
140
+ */
141
+ private waitForDrain;
142
+ /** Abort one open stream (client `stream.close`). */
143
+ private closeStream;
114
144
  private settleTool;
115
- /** Close the current connection (if any) and settle its in-flight calls. */
145
+ /** Close the current connection (if any) and settle its in-flight calls and streams. */
116
146
  private replaceConnection;
117
147
  }
118
148
  /**
@@ -1,25 +1,24 @@
1
1
  /**
2
2
  * Defer real session creation until the first prompt.
3
3
  *
4
- * The panel calls `session.create` as soon as it connects, but a session that
4
+ * The panel calls `session/create` as soon as it connects, but a session that
5
5
  * is opened and never used should leave zero trace in the store/GUI. This
6
- * wrapper answers `session.create` with a provisional id (minted locally,
7
- * nothing persisted), serves `session.history` for provisional ids as empty,
8
- * and materializes the real session — same id, original create payload — on
9
- * the first `session.prompt` for that id. Abandoned provisional ids are
10
- * pruned after {@link PROVISIONAL_TTL_MS}.
6
+ * interceptor answers `session/create` with a provisional id (minted locally,
7
+ * nothing persisted) and materializes the real session — same id, original
8
+ * create request — on the first `session/prompt` for that id. Abandoned
9
+ * provisional ids are pruned after {@link PROVISIONAL_TTL_MS}.
11
10
  *
12
11
  * @module @deepseek-ai/dsh-bridge-browser/src/session-deferral
13
12
  */
14
- import type { ApiProxy } from '@deepseek-ai/dsh-host-apiproxy/api';
13
+ import type { RpcDispatch } from './session-workspace.ts';
15
14
  /**
16
- * Wrap the gateway sessions API so `session.create` returns a provisional id
15
+ * Intercept the Remote dispatch so `session/create` returns a provisional id
17
16
  * without creating anything; the real session materializes on the first
18
- * `session.prompt` for that id.
17
+ * `session/prompt` for that id.
19
18
  *
20
- * @param api - Gateway API implementation.
21
- * @param enabled - Whether deferral is active; false returns the API untouched.
22
- * @returns the original API when disabled, otherwise the wrapped API.
19
+ * @param dispatch - Inner Remote dispatch.
20
+ * @param enabled - Whether deferral is active; false returns the dispatch untouched.
21
+ * @returns the original dispatch when disabled, otherwise the intercepting dispatch.
23
22
  */
24
- export declare function withSessionDeferral(api: ApiProxy, enabled: boolean): ApiProxy;
23
+ export declare function withSessionDeferral(dispatch: RpcDispatch, enabled: boolean): RpcDispatch;
25
24
  //# sourceMappingURL=session-deferral.d.ts.map
@@ -1,22 +1,27 @@
1
1
  /**
2
2
  * Best-effort workspace grouping for sessions created through the browser
3
- * bridge. The wrapper changes only implicit `session.create` requests;
4
- * explicit workspace choices and every other gateway method pass through.
3
+ * bridge. The interceptor changes only implicit `session/create` requests;
4
+ * explicit workspace choices and every other Remote endpoint pass through.
5
5
  * @module @deepseek-ai/dsh-bridge-browser/src/session-workspace
6
6
  */
7
- import type { ApiProxy } from '@deepseek-ai/dsh-host-apiproxy/api';
7
+ import type { RemoteWireResult } from './protocol.ts';
8
+ /**
9
+ * Unary Remote dispatch seam: slash-joined endpoint, native args object,
10
+ * RemoteResult wire form. The bridge server and the interceptors share it.
11
+ */
12
+ export type RpcDispatch = (method: string, args: Record<string, unknown>, signal: AbortSignal) => Promise<RemoteWireResult>;
8
13
  type Warn = (message: string) => void;
9
14
  /**
10
- * Add a dedicated Workspace to implicit session creation without making
15
+ * Add the dedicated Workspace to implicit session creation without making
11
16
  * grouping a session-creation dependency. The first implicit create mkdirs
12
- * and registers the configured path; that result, including failure, is
13
- * cached for the wrapper lifetime.
17
+ * and registers the configured path (`workspace/create`); that result,
18
+ * including failure, is cached for the interceptor lifetime.
14
19
  *
15
- * @param api - Injected gateway API implementation.
20
+ * @param dispatch - Inner Remote dispatch.
16
21
  * @param workspacePath - Dedicated directory, or an empty string to opt out.
17
22
  * @param warn - Logger called once when grouping cannot be established.
18
- * @returns the original API for opt-out, otherwise an API with wrapped session creation.
23
+ * @returns the original dispatch for opt-out, otherwise a dispatch with intercepted session creation.
19
24
  */
20
- export declare function withSessionWorkspace(api: ApiProxy, workspacePath: string, warn: Warn): ApiProxy;
25
+ export declare function withSessionWorkspace(dispatch: RpcDispatch, workspacePath: string, warn: Warn): RpcDispatch;
21
26
  export {};
22
27
  //# sourceMappingURL=session-workspace.d.ts.map
@@ -23,7 +23,7 @@ export interface BrowserToolsOptions {
23
23
  maxInteractiveItems: number;
24
24
  }
25
25
  /** The keys the extension accepts as wire action names (tool name == action name). */
26
- export declare const BROWSER_TOOL_NAMES: readonly ["browser_snapshot", "browser_click", "browser_type", "browser_press", "browser_scroll", "browser_navigate", "browser_back", "browser_forward", "browser_reload", "browser_get_text", "browser_wait", "browser_evaluate", "browser_screenshot", "browser_list_tabs"];
26
+ export declare const BROWSER_TOOL_NAMES: readonly ["browser_snapshot", "browser_click", "browser_type", "browser_press", "browser_scroll", "browser_navigate", "browser_back", "browser_forward", "browser_reload", "browser_get_text", "browser_wait", "browser_evaluate", "browser_screenshot", "browser_list_tabs", "browser_open_tab", "browser_follow_tab", "browser_close_tab"];
27
27
  /**
28
28
  * Register the browser tools on `ctx.tools`. Disposers are returned for the
29
29
  * caller's effect to own; each tool's cooperative timeout budget is declared