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/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.3.3",
4
+ "version": "0.4.1",
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.1",
56
- "@deepseek-ai/dsh-host-apiproxy": "^0.1.1-rc.1",
57
- "@deepseek-ai/dsh-host-webserver": "^0.1.1-rc.1",
58
- "@deepseek-ai/dsh-invariants": "^0.1.1-rc.1",
59
- "@deepseek-ai/dsh-home-paths": "^0.1.1-rc.1",
60
- "@deepseek-ai/dsh-tools": "^0.1.1-rc.1"
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.1",
74
- "@deepseek-ai/cordis-plugin-include": "1.0.6",
75
- "@deepseek-ai/cordis-plugin-loader": "1.0.2",
76
- "@deepseek-ai/dsh-agent": "0.1.1-rc.1",
77
- "@deepseek-ai/dsh-agent-loop": "0.1.1-rc.1",
78
- "@deepseek-ai/dsh-host-apiproxy": "0.1.1-rc.1",
79
- "@deepseek-ai/dsh-host-webserver": "0.1.1-rc.1",
80
- "@deepseek-ai/dsh-invariants": "0.1.1-rc.1",
81
- "@deepseek-ai/dsh-llm": "0.1.1-rc.1",
82
- "@deepseek-ai/dsh-home-paths": "0.1.1-rc.1",
83
- "@deepseek-ai/dsh-session": "0.1.1-rc.1",
84
- "@deepseek-ai/dsh-storage": "0.1.1-rc.1",
85
- "@deepseek-ai/dsh-storage-domain": "0.1.1-rc.1",
86
- "@deepseek-ai/dsh-storage-json": "0.1.1-rc.1",
87
- "@deepseek-ai/dsh-system-prompt": "0.1.1-rc.1",
88
- "@deepseek-ai/dsh-tools": "0.1.1-rc.1",
89
- "@deepseek-ai/dsh-user-questions": "0.1.1-rc.1",
90
- "@deepseek-ai/dsh-workspace": "0.1.1-rc.1",
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",
package/src/index.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). 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.
@@ -16,28 +18,24 @@
16
18
  * @module @deepseek-ai/dsh-bridge-browser
17
19
  */
18
20
 
19
- import { randomUUID } from 'node:crypto'
20
21
  import type { Context } from '@deepseek-ai/cordis'
21
22
  import z from '@deepseek-ai/schemastery'
22
23
  import type {} from '@deepseek-ai/dsh-tools'
23
- import type {} from '@deepseek-ai/dsh-host-apiproxy'
24
+ import type {} from '@deepseek-ai/dsh-api-gateway/types'
24
25
  import type { WebRoute, WebUpgradeRoute } from '@deepseek-ai/dsh-host-webserver'
25
- import type { ApiProxy } from '@deepseek-ai/dsh-host-apiproxy/api'
26
- import { RpcId } from '@deepseek-ai/dsh-host-apiproxy/api'
27
- import { toFetchHandler } from '@deepseek-ai/dsh-host-apiproxy'
28
26
  import { dshHomePath } from '@deepseek-ai/dsh-home-paths'
29
27
  import { BridgeServer } from './server.ts'
30
28
  import { registerBrowserTools } from './tools.ts'
31
- import { BRIDGE_CONFIG_PATH, BRIDGE_PATH } from './protocol.ts'
29
+ import { BRIDGE_CONFIG_PATH, BRIDGE_PATH, type RemoteWireResult } from './protocol.ts'
32
30
  import { withSessionDeferral } from './session-deferral.ts'
33
- import { withSessionWorkspace } from './session-workspace.ts'
31
+ import { withSessionWorkspace, type RpcDispatch } from './session-workspace.ts'
34
32
  import { resolveToken } from './token.ts'
35
33
 
36
34
  /** Cordis plugin name used by loader diagnostics. */
37
35
  export const name = 'bridge-browser'
38
36
 
39
37
  /** Services required by this plugin. */
40
- export const inject = ['webServer', 'apiProxy', 'tools']
38
+ export const inject = ['webServer', 'typertGateway', 'tools']
41
39
 
42
40
  /** Default per-tool-call budget (ms). */
43
41
  const DEFAULT_TOOL_TIMEOUT_MS = 60_000
@@ -120,11 +118,27 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
120
118
  const resolved = resolveConfig(config)
121
119
 
122
120
  const tokenRes = await resolveToken(resolved.token)
123
- // Workspace grouping wraps the gateway create; session deferral wraps the
121
+ // Base dispatch: split the slash-joined endpoint and invoke the Remote
122
+ // method; Remote failures are folded into the wire result (never thrown
123
+ // across the bridge), everything else is an internal failure.
124
+ const invoke: RpcDispatch = async (method, args, signal) => {
125
+ const slash = method.indexOf('/')
126
+ const namespace = slash === -1 ? method : method.slice(0, slash)
127
+ const remoteMethod = slash === -1 ? '' : method.slice(slash + 1)
128
+ try {
129
+ const value = await ctx.typertGateway.invoke({ namespace, method: remoteMethod, args, signal })
130
+ return { ok: true, value }
131
+ } catch (error: unknown) {
132
+ const failure = ctx.typertGateway.wireStream.failure(error)
133
+ const result: RemoteWireResult = { ok: false, error: failure }
134
+ return result
135
+ }
136
+ }
137
+ // Workspace grouping intercepts session/create; session deferral wraps the
124
138
  // result so materialization at first prompt still flows through grouping.
125
- const api: ApiProxy = withSessionDeferral(
139
+ const dispatchRpc = withSessionDeferral(
126
140
  withSessionWorkspace(
127
- ctx.apiProxy,
141
+ invoke,
128
142
  resolved.sessionWorkspacePath,
129
143
  message => { ctx.logger.warn(message) },
130
144
  ),
@@ -132,8 +146,13 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
132
146
  )
133
147
  const server = new BridgeServer({
134
148
  token: tokenRes.token,
135
- apiHandler: toFetchHandler(api),
136
- openEvents: (signal) => api.events.mux({ rpcId: RpcId(randomUUID()), payload: {} }, signal),
149
+ dispatchRpc,
150
+ openStream: (method, args, signal) => {
151
+ const slash = method.indexOf('/')
152
+ const namespace = slash === -1 ? method : method.slice(0, slash)
153
+ const remoteMethod = slash === -1 ? '' : method.slice(slash + 1)
154
+ return ctx.typertGateway.stream({ namespace, method: remoteMethod, args, signal })
155
+ },
137
156
  toolTimeoutMs: resolved.toolTimeoutMs,
138
157
  caps: {
139
158
  textOnly: true,
package/src/protocol.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 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
 
@@ -35,6 +41,8 @@ export type ToolErrorCode =
35
41
  | 'timeout'
36
42
  | 'bridge-closed'
37
43
  | 'bad-args'
44
+ | 'approval-denied'
45
+ | 'cancelled'
38
46
  | 'internal'
39
47
 
40
48
  /** One tool-call failure: stable machine code plus human text for the model. */
@@ -53,12 +61,28 @@ export interface BridgeCaps {
53
61
  maxInteractiveItems: number
54
62
  }
55
63
 
64
+ /** One Remote failure as plain wire data (RemoteError's message is non-enumerable, so it is restated explicitly). */
65
+ export interface RemoteWireFailure {
66
+ code: string
67
+ message: string
68
+ details?: object
69
+ }
70
+
71
+ /** The RemoteResult wire form answered to one `rpc` frame. */
72
+ export type RemoteWireResult =
73
+ | { ok: true; value: unknown }
74
+ | { ok: false; error: RemoteWireFailure }
75
+
56
76
  /** Frames sent by the extension to the bridge plugin. */
57
77
  export type ClientFrame =
58
78
  /** First frame, within HELLO_TIMEOUT_MS of socket open. */
59
79
  | { t: 'hello'; token: string; caps: BridgeCaps }
60
- /** Unary gateway RPC passthrough (method names from the apiproxy RpcMethodMap). */
61
- | { t: 'rpc'; id: string; method: string; payload: unknown }
80
+ /** Unary Remote call: slash-joined endpoint plus the descriptor's native args object. */
81
+ | { t: 'rpc'; id: string; method: string; args: Record<string, unknown> }
82
+ /** Open one Remote stream (`session/follow`, `workspace/follow`); frames arrive as `stream.frame`. */
83
+ | { t: 'stream.open'; id: string; method: string; args: Record<string, unknown> }
84
+ /** Cancel one open stream. */
85
+ | { t: 'stream.close'; id: string }
62
86
  /** Result of a previously dispatched tool call. */
63
87
  | { t: 'tool.result'; id: string; ok: true; result: unknown }
64
88
  | { t: 'tool.result'; id: string; ok: false; error: ToolError }
@@ -69,11 +93,13 @@ export type ClientFrame =
69
93
  export type ServerFrame =
70
94
  /** Accepted after a valid `hello`. */
71
95
  | { t: 'hello.ok'; caps: BridgeCaps }
72
- /** Reply to an `rpc` frame; `result` is the apiproxy ServerResponse envelope. */
73
- | { t: 'rpc.result'; id: string; ok: true; result: unknown }
74
- | { t: 'rpc.result'; id: string; ok: false; error: { code: string; message: string } }
75
- /** One gateway event envelope (the same server-request shape the GUI's /api/events.mux carries). */
76
- | { t: 'event'; frame: { rpcId: string; method: string; payload: unknown } }
96
+ /** Reply to an `rpc` frame: the RemoteResult wire form, flattened onto the frame. */
97
+ | { t: 'rpc.result'; id: string; ok: true; value: unknown }
98
+ | { t: 'rpc.result'; id: string; ok: false; error: RemoteWireFailure }
99
+ /** One native frame of an open stream (SessionFollowFrame / WorkspaceFollowFrame, unmodified). */
100
+ | { t: 'stream.frame'; id: string; frame: unknown }
101
+ /** A stream failed (or its open was rejected); the client may reopen it. */
102
+ | { t: 'stream.error'; id: string; message: string }
77
103
  /** A model-requested browser action to execute in the user-controlled tab. `expiresAt` (ms epoch) withdraws the call once the caller stops waiting. */
78
104
  | { t: 'tool.call'; id: string; name: string; args: Record<string, unknown>; expiresAt?: number; sessionId?: string; title?: string }
79
105
  /** Withdraw a tool call that timed out or whose caller was cancelled. */
@@ -88,15 +114,16 @@ export type BridgeFrame = ClientFrame | ServerFrame
88
114
 
89
115
  /**
90
116
  * Type guard: is this frame one the SERVER may send? Client-only shapes
91
- * (hello/tool.result/pong) narrow out, so server-side consumers never
92
- * dispatch on their own request vocabulary.
117
+ * (hello/rpc/stream.open/stream.close/tool.result/pong) narrow out, so
118
+ * server-side consumers never dispatch on their own request vocabulary.
93
119
  * @param frame - parsed frame.
94
120
  * @returns true for server-sendable frames.
95
121
  */
96
122
  export function isServerFrame(frame: BridgeFrame): frame is ServerFrame {
97
123
  return frame.t === 'hello.ok'
98
124
  || frame.t === 'rpc.result'
99
- || frame.t === 'event'
125
+ || frame.t === 'stream.frame'
126
+ || frame.t === 'stream.error'
100
127
  || frame.t === 'tool.call'
101
128
  || frame.t === 'tool.cancel'
102
129
  || frame.t === 'ping'
@@ -110,7 +137,17 @@ export function isServerFrame(frame: BridgeFrame): frame is ServerFrame {
110
137
  * @returns true for client-sendable frames.
111
138
  */
112
139
  export function isClientFrame(frame: BridgeFrame): frame is ClientFrame {
113
- return frame.t === 'hello' || frame.t === 'rpc' || frame.t === 'tool.result' || frame.t === 'pong'
140
+ return frame.t === 'hello'
141
+ || frame.t === 'rpc'
142
+ || frame.t === 'stream.open'
143
+ || frame.t === 'stream.close'
144
+ || frame.t === 'tool.result'
145
+ || frame.t === 'pong'
146
+ }
147
+
148
+ /** Wire args must be a plain object (the Remote descriptor's named arguments). */
149
+ function isArgs(value: unknown): value is Record<string, unknown> {
150
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
114
151
  }
115
152
 
116
153
  /**
@@ -135,9 +172,15 @@ export function parseBridgeFrame(text: string): BridgeFrame | undefined {
135
172
  ? { t: 'hello', token: frame.token, caps: frame.caps }
136
173
  : undefined
137
174
  case 'rpc':
138
- return typeof frame.id === 'string' && typeof frame.method === 'string'
139
- ? { t: 'rpc', id: frame.id, method: frame.method, payload: frame.payload }
175
+ return typeof frame.id === 'string' && typeof frame.method === 'string' && isArgs(frame.args)
176
+ ? { t: 'rpc', id: frame.id, method: frame.method, args: frame.args }
177
+ : undefined
178
+ case 'stream.open':
179
+ return typeof frame.id === 'string' && typeof frame.method === 'string' && isArgs(frame.args)
180
+ ? { t: 'stream.open', id: frame.id, method: frame.method, args: frame.args }
140
181
  : undefined
182
+ case 'stream.close':
183
+ return typeof frame.id === 'string' ? { t: 'stream.close', id: frame.id } : undefined
141
184
  case 'tool.result':
142
185
  if (typeof frame.id !== 'string') return undefined
143
186
  if (frame.ok === true && 'result' in frame) {
@@ -154,15 +197,19 @@ export function parseBridgeFrame(text: string): BridgeFrame | undefined {
154
197
  : undefined
155
198
  case 'rpc.result':
156
199
  if (typeof frame.id !== 'string') return undefined
157
- if (frame.ok === true && 'result' in frame) {
158
- return { t: 'rpc.result', id: frame.id, ok: true, result: frame.result }
200
+ if (frame.ok === true && 'value' in frame) {
201
+ return { t: 'rpc.result', id: frame.id, ok: true, value: frame.value }
159
202
  }
160
- return typeof frame.error === 'object' && frame.error !== null
161
- ? { t: 'rpc.result', id: frame.id, ok: false, error: frame.error as { code: string; message: string } }
203
+ return isWireFailure(frame.error)
204
+ ? { t: 'rpc.result', id: frame.id, ok: false, error: frame.error }
205
+ : undefined
206
+ case 'stream.frame':
207
+ return typeof frame.id === 'string'
208
+ ? { t: 'stream.frame', id: frame.id, frame: frame.frame }
162
209
  : undefined
163
- case 'event':
164
- return typeof frame.frame === 'object' && frame.frame !== null
165
- ? { t: 'event', frame: frame.frame as ServerFrame extends { t: 'event' } ? ServerFrame['frame'] : never }
210
+ case 'stream.error':
211
+ return typeof frame.id === 'string' && typeof frame.message === 'string'
212
+ ? { t: 'stream.error', id: frame.id, message: frame.message }
166
213
  : undefined
167
214
  case 'tool.call':
168
215
  if (typeof frame.id !== 'string' || typeof frame.name !== 'string') return undefined
@@ -206,3 +253,9 @@ function isToolError(value: unknown): value is ToolError {
206
253
  && typeof (value as Record<string, unknown>).code === 'string'
207
254
  && typeof (value as Record<string, unknown>).message === 'string'
208
255
  }
256
+
257
+ function isWireFailure(value: unknown): value is RemoteWireFailure {
258
+ return typeof value === 'object' && value !== null
259
+ && typeof (value as Record<string, unknown>).code === 'string'
260
+ && typeof (value as Record<string, unknown>).message === 'string'
261
+ }