dsh-browser-firefox 0.3.3 → 0.4.0
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/index.js +249 -208
- package/lib/protocol.js +42 -13
- package/lib/types/events.d.ts +59 -0
- package/lib/types/gateway.d.ts +87 -0
- package/lib/types/index.d.ts +7 -5
- package/lib/types/protocol.d.ts +51 -19
- package/lib/types/server.d.ts +26 -19
- package/lib/types/session-deferral.d.ts +12 -13
- package/lib/types/session-workspace.d.ts +14 -9
- package/package.json +29 -25
- package/src/index.ts +37 -18
- package/src/protocol.ts +73 -22
- package/src/server.ts +121 -74
- package/src/session-deferral.ts +59 -66
- package/src/session-workspace.ts +46 -39
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
|
|
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
|
|
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 === "
|
|
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
|
-
|
|
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 && "
|
|
112
|
+
if (frame.ok === true && "value" in frame) return {
|
|
93
113
|
t: "rpc.result",
|
|
94
114
|
id: frame.id,
|
|
95
115
|
ok: true,
|
|
96
|
-
|
|
116
|
+
value: frame.value
|
|
97
117
|
};
|
|
98
|
-
return
|
|
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 "
|
|
105
|
-
t: "
|
|
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
|
package/lib/types/index.d.ts
CHANGED
|
@@ -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).
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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.
|
package/lib/types/protocol.d.ts
CHANGED
|
@@ -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
|
|
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. */
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
122
|
+
/** One native frame of an open stream (SessionFollowFrame / WorkspaceFollowFrame, unmodified). */
|
|
94
123
|
| {
|
|
95
|
-
t: '
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
|
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
|
*/
|
package/lib/types/server.d.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Bridge WebSocket carrier: token-authenticated connection registry,
|
|
3
|
-
*
|
|
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.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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
|
|
17
|
-
*
|
|
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
|
|
24
|
-
import { type BridgeCaps, type ToolErrorCode } from './protocol.ts';
|
|
23
|
+
import { type BridgeCaps, type RemoteWireResult, type ToolErrorCode } from './protocol.ts';
|
|
25
24
|
/** Loopback IPv4/IPv6 literals (IPv4-mapped included). Exported for tests and reuse. */
|
|
26
25
|
export declare function isLoopbackAddress(address: string | undefined): boolean;
|
|
27
26
|
/** Error thrown by requestTool; the tool registry turns it into an isError result. */
|
|
@@ -33,12 +32,14 @@ export declare class BridgeToolError extends Error {
|
|
|
33
32
|
export interface BridgeServerDeps {
|
|
34
33
|
/** Bearer token the extension must present in `hello`. */
|
|
35
34
|
token: string;
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Unary Remote dispatch (slash endpoint + native args), answering the
|
|
37
|
+
* RemoteResult wire form. Plugin-side interceptors (workspace grouping,
|
|
38
|
+
* session deferral) sit on this seam.
|
|
39
|
+
*/
|
|
40
|
+
dispatchRpc: (method: string, args: Record<string, unknown>, signal: AbortSignal) => Promise<RemoteWireResult>;
|
|
41
|
+
/** Open one Remote stream (slash endpoint + native args). */
|
|
42
|
+
openStream: (method: string, args: Record<string, unknown>, signal: AbortSignal) => Promise<AsyncIterable<unknown>>;
|
|
42
43
|
/** Default per-tool-call timeout in ms. */
|
|
43
44
|
toolTimeoutMs: number;
|
|
44
45
|
/** Capabilities to echo in `hello.ok` (negotiated snapshot budgets). */
|
|
@@ -94,7 +95,7 @@ export declare class BridgeServer {
|
|
|
94
95
|
requestTool(name: string, args: Record<string, unknown>, signal: AbortSignal, timeoutMs?: number, sessionId?: string, title?: string): Promise<unknown>;
|
|
95
96
|
/**
|
|
96
97
|
* Terminate the server: close the acceptor, drop all sockets, reject all
|
|
97
|
-
* in-flight tool calls.
|
|
98
|
+
* in-flight tool calls, abort all streams.
|
|
98
99
|
* @returns a promise resolving after the acceptor and all pumps stop.
|
|
99
100
|
*/
|
|
100
101
|
close(): Promise<void>;
|
|
@@ -110,9 +111,15 @@ export declare class BridgeServer {
|
|
|
110
111
|
* must not reach the gateway until that admission has completed.
|
|
111
112
|
*/
|
|
112
113
|
private routeRpc;
|
|
114
|
+
/** Whether the connection owning this frame may call the endpoint at all. */
|
|
115
|
+
private forbidden;
|
|
113
116
|
private handleRpc;
|
|
117
|
+
/** Open one Remote stream and pump its frames until closed, failed, or replaced. */
|
|
118
|
+
private openStream;
|
|
119
|
+
/** Abort one open stream (client `stream.close`). */
|
|
120
|
+
private closeStream;
|
|
114
121
|
private settleTool;
|
|
115
|
-
/** Close the current connection (if any) and settle its in-flight calls. */
|
|
122
|
+
/** Close the current connection (if any) and settle its in-flight calls and streams. */
|
|
116
123
|
private replaceConnection;
|
|
117
124
|
}
|
|
118
125
|
/**
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Defer real session creation until the first prompt.
|
|
3
3
|
*
|
|
4
|
-
* The panel calls `session
|
|
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
|
-
*
|
|
7
|
-
* nothing persisted)
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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 {
|
|
13
|
+
import type { RpcDispatch } from './session-workspace.ts';
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
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
|
|
17
|
+
* `session/prompt` for that id.
|
|
19
18
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @param enabled - Whether deferral is active; false returns the
|
|
22
|
-
* @returns the original
|
|
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(
|
|
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
|
|
4
|
-
* explicit workspace choices and every other
|
|
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 {
|
|
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
|
|
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,
|
|
13
|
-
* cached for the
|
|
17
|
+
* and registers the configured path (`workspace/create`); that result,
|
|
18
|
+
* including failure, is cached for the interceptor lifetime.
|
|
14
19
|
*
|
|
15
|
-
* @param
|
|
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
|
|
23
|
+
* @returns the original dispatch for opt-out, otherwise a dispatch with intercepted session creation.
|
|
19
24
|
*/
|
|
20
|
-
export declare function withSessionWorkspace(
|
|
25
|
+
export declare function withSessionWorkspace(dispatch: RpcDispatch, workspacePath: string, warn: Warn): RpcDispatch;
|
|
21
26
|
export {};
|
|
22
27
|
//# sourceMappingURL=session-workspace.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-browser-firefox",
|
|
3
3
|
"description": "Firefox browser control for DeepSeek Harness: token-authenticated WebSocket bridge + text-first browser_* tools driving the user's own Firefox via the companion AMO extension",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"author": "tuojc",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -52,12 +52,14 @@
|
|
|
52
52
|
"src"
|
|
53
53
|
],
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@deepseek-ai/cordis": "^4.0.
|
|
56
|
-
"@deepseek-ai/dsh-
|
|
57
|
-
"@deepseek-ai/dsh-
|
|
58
|
-
"@deepseek-ai/dsh-
|
|
59
|
-
"@deepseek-ai/dsh-
|
|
60
|
-
"@deepseek-ai/dsh-
|
|
55
|
+
"@deepseek-ai/cordis": "^4.0.2",
|
|
56
|
+
"@deepseek-ai/dsh-api-gateway": "^0.1.2-alpha.2",
|
|
57
|
+
"@deepseek-ai/dsh-api-session-controller": "^0.1.2-alpha.2",
|
|
58
|
+
"@deepseek-ai/dsh-api-workspace-controller": "^0.1.2-alpha.2",
|
|
59
|
+
"@deepseek-ai/dsh-host-webserver": "^0.1.2-alpha.2",
|
|
60
|
+
"@deepseek-ai/dsh-invariants": "^0.1.2-alpha.2",
|
|
61
|
+
"@deepseek-ai/dsh-home-paths": "^0.1.2-alpha.2",
|
|
62
|
+
"@deepseek-ai/dsh-tools": "^0.1.2-alpha.2"
|
|
61
63
|
},
|
|
62
64
|
"dependencies": {
|
|
63
65
|
"@deepseek-ai/schemastery": "^3.18.1",
|
|
@@ -70,24 +72,26 @@
|
|
|
70
72
|
"prepublishOnly": "pnpm run build"
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
73
|
-
"@deepseek-ai/cordis": "4.0.
|
|
74
|
-
"@deepseek-ai/cordis-plugin-include": "1.0.
|
|
75
|
-
"@deepseek-ai/cordis-plugin-loader": "1.0.
|
|
76
|
-
"@deepseek-ai/dsh-agent": "0.1.
|
|
77
|
-
"@deepseek-ai/dsh-agent-loop": "0.1.
|
|
78
|
-
"@deepseek-ai/dsh-
|
|
79
|
-
"@deepseek-ai/dsh-
|
|
80
|
-
"@deepseek-ai/dsh-
|
|
81
|
-
"@deepseek-ai/dsh-
|
|
82
|
-
"@deepseek-ai/dsh-
|
|
83
|
-
"@deepseek-ai/dsh-
|
|
84
|
-
"@deepseek-ai/dsh-
|
|
85
|
-
"@deepseek-ai/dsh-
|
|
86
|
-
"@deepseek-ai/dsh-storage
|
|
87
|
-
"@deepseek-ai/dsh-
|
|
88
|
-
"@deepseek-ai/dsh-
|
|
89
|
-
"@deepseek-ai/dsh-
|
|
90
|
-
"@deepseek-ai/dsh-
|
|
75
|
+
"@deepseek-ai/cordis": "4.0.2",
|
|
76
|
+
"@deepseek-ai/cordis-plugin-include": "1.0.7",
|
|
77
|
+
"@deepseek-ai/cordis-plugin-loader": "1.0.3",
|
|
78
|
+
"@deepseek-ai/dsh-agent": "0.1.2-alpha.5",
|
|
79
|
+
"@deepseek-ai/dsh-agent-loop": "0.1.2-alpha.5",
|
|
80
|
+
"@deepseek-ai/dsh-api-gateway": "0.1.2-alpha.5",
|
|
81
|
+
"@deepseek-ai/dsh-api-session-controller": "0.1.2-alpha.5",
|
|
82
|
+
"@deepseek-ai/dsh-api-workspace-controller": "0.1.2-alpha.5",
|
|
83
|
+
"@deepseek-ai/dsh-host-webserver": "0.1.2-alpha.5",
|
|
84
|
+
"@deepseek-ai/dsh-invariants": "0.1.2-alpha.5",
|
|
85
|
+
"@deepseek-ai/dsh-llm": "0.1.2-alpha.5",
|
|
86
|
+
"@deepseek-ai/dsh-home-paths": "0.1.2-alpha.5",
|
|
87
|
+
"@deepseek-ai/dsh-session": "0.1.2-alpha.5",
|
|
88
|
+
"@deepseek-ai/dsh-storage": "0.1.2-alpha.5",
|
|
89
|
+
"@deepseek-ai/dsh-storage-domain": "0.1.2-alpha.5",
|
|
90
|
+
"@deepseek-ai/dsh-storage-json": "0.1.2-alpha.5",
|
|
91
|
+
"@deepseek-ai/dsh-system-prompt": "0.1.2-alpha.5",
|
|
92
|
+
"@deepseek-ai/dsh-tools": "0.1.2-alpha.5",
|
|
93
|
+
"@deepseek-ai/dsh-user-questions": "0.1.2-alpha.5",
|
|
94
|
+
"@deepseek-ai/dsh-workspace": "0.1.2-alpha.5",
|
|
91
95
|
"@types/node": "^22.20.0",
|
|
92
96
|
"@types/ws": "^8.18.1",
|
|
93
97
|
"playwright-core": "^1.61.1",
|