dsh-browser-firefox 0.4.5 → 0.4.6

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 CHANGED
@@ -1,5 +1,6 @@
1
1
  import { BRIDGE_CONFIG_PATH, BRIDGE_PATH, parseBridgeFrame } from "./protocol.js";
2
2
  import z from "@deepseek-ai/schemastery";
3
+ import { readFileSync } from "node:fs";
3
4
  import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
4
5
  import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
5
6
  import { WebSocket, WebSocketServer } from "ws";
@@ -377,7 +378,7 @@ var BridgeServer = class {
377
378
  }
378
379
  clearTimeout(helloTimer);
379
380
  helloTimer = void 0;
380
- this.promote(ws, remoteAddress, frame.caps);
381
+ this.promote(ws, remoteAddress, frame.caps, frame.version);
381
382
  return;
382
383
  }
383
384
  this.handleReadyFrame(frame);
@@ -391,8 +392,9 @@ var BridgeServer = class {
391
392
  ws.once("error", onClose);
392
393
  }
393
394
  /** Promote an authenticated socket to the single active slot. */
394
- promote(ws, remoteAddress, clientCaps) {
395
+ promote(ws, remoteAddress, clientCaps, clientVersion) {
395
396
  this.replaceConnection();
397
+ if (clientVersion !== void 0 && this.deps.version !== void 0 && clientVersion !== this.deps.version) this.deps.onVersionMismatch?.(clientVersion);
396
398
  const abort = new AbortController();
397
399
  const intervalMs = this.deps.pingIntervalMs ?? 3e4;
398
400
  const allowed = this.deps.missedPongsAllowed ?? DEFAULT_MISSED_PONGS_ALLOWED;
@@ -416,7 +418,8 @@ var BridgeServer = class {
416
418
  this.current = conn;
417
419
  sendFrame(ws, {
418
420
  t: "hello.ok",
419
- caps: this.deps.caps
421
+ caps: this.deps.caps,
422
+ ...this.deps.version === void 0 ? {} : { version: this.deps.version }
420
423
  });
421
424
  ws.once("close", () => {
422
425
  clearInterval(ping);
@@ -1550,6 +1553,13 @@ async function apply(ctx, config) {
1550
1553
  }
1551
1554
  return result;
1552
1555
  };
1556
+ let pluginVersion;
1557
+ try {
1558
+ const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
1559
+ pluginVersion = typeof pkg.version === "string" ? pkg.version : void 0;
1560
+ } catch {
1561
+ pluginVersion = void 0;
1562
+ }
1553
1563
  const questions = new QuestionBridge({ push: (frame) => {
1554
1564
  server.push(frame);
1555
1565
  } });
@@ -1577,6 +1587,10 @@ async function apply(ctx, config) {
1577
1587
  onConnectionLost: () => {
1578
1588
  questions.delegateAll();
1579
1589
  },
1590
+ version: pluginVersion,
1591
+ onVersionMismatch: (clientVersion) => {
1592
+ ctx.logger.warn(`browser extension version ${clientVersion} != plugin version ${pluginVersion ?? "?"}; both components must be updated together`);
1593
+ },
1580
1594
  toolTimeoutMs: resolved.toolTimeoutMs,
1581
1595
  caps: {
1582
1596
  snapshotMaxChars: resolved.snapshotMaxChars,
package/lib/protocol.js CHANGED
@@ -67,11 +67,15 @@ function parseBridgeFrame(text) {
67
67
  const frame = value;
68
68
  if (typeof frame.t !== "string") return void 0;
69
69
  switch (frame.t) {
70
- case "hello": return typeof frame.token === "string" && isCaps(frame.caps) ? {
71
- t: "hello",
72
- token: frame.token,
73
- caps: frame.caps
74
- } : void 0;
70
+ case "hello":
71
+ if (typeof frame.token !== "string" || !isCaps(frame.caps)) return void 0;
72
+ if (frame.version !== void 0 && typeof frame.version !== "string") return void 0;
73
+ return {
74
+ t: "hello",
75
+ token: frame.token,
76
+ caps: frame.caps,
77
+ ...frame.version === void 0 ? {} : { version: frame.version }
78
+ };
75
79
  case "rpc": return typeof frame.id === "string" && typeof frame.method === "string" && isArgs(frame.args) ? {
76
80
  t: "rpc",
77
81
  id: frame.id,
@@ -103,10 +107,14 @@ function parseBridgeFrame(text) {
103
107
  error: frame.error
104
108
  } : void 0;
105
109
  case "pong": return { t: "pong" };
106
- case "hello.ok": return isCaps(frame.caps) ? {
107
- t: "hello.ok",
108
- caps: frame.caps
109
- } : void 0;
110
+ case "hello.ok":
111
+ if (!isCaps(frame.caps)) return void 0;
112
+ if (frame.version !== void 0 && typeof frame.version !== "string") return void 0;
113
+ return {
114
+ t: "hello.ok",
115
+ caps: frame.caps,
116
+ ...frame.version === void 0 ? {} : { version: frame.version }
117
+ };
110
118
  case "rpc.result":
111
119
  if (typeof frame.id !== "string") return void 0;
112
120
  if (frame.ok === true && "value" in frame) return {
@@ -85,11 +85,12 @@ export interface QuestionItem {
85
85
  }
86
86
  /** Frames sent by the extension to the bridge plugin. */
87
87
  export type ClientFrame =
88
- /** First frame, within HELLO_TIMEOUT_MS of socket open. */
88
+ /** First frame, within HELLO_TIMEOUT_MS of socket open. `version` (extension version) lets the plugin detect a version mismatch; absent on pre-0.4.6 clients. */
89
89
  {
90
90
  t: 'hello';
91
91
  token: string;
92
92
  caps: BridgeCaps;
93
+ version?: string;
93
94
  }
94
95
  /** Unary Remote call: slash-joined endpoint plus the descriptor's native args object. */
95
96
  | {
@@ -128,10 +129,11 @@ export type ClientFrame =
128
129
  };
129
130
  /** Frames sent by the bridge plugin to the extension. */
130
131
  export type ServerFrame =
131
- /** Accepted after a valid `hello`. */
132
+ /** Accepted after a valid `hello`. `version` (plugin version) lets the extension detect a version mismatch; absent on pre-0.4.6 servers. */
132
133
  {
133
134
  t: 'hello.ok';
134
135
  caps: BridgeCaps;
136
+ version?: string;
135
137
  }
136
138
  /** Reply to an `rpc` frame: the RemoteResult wire form, flattened onto the frame. */
137
139
  | {
@@ -54,6 +54,10 @@ export interface BridgeServerDeps {
54
54
  toolTimeoutMs: number;
55
55
  /** Capabilities to echo in `hello.ok` (negotiated snapshot budgets). */
56
56
  caps: BridgeCaps;
57
+ /** Plugin version echoed in `hello.ok` so the extension can flag a mismatch (0.4.6+). */
58
+ version?: string | undefined;
59
+ /** An authenticated client arrived with a version different from ours. */
60
+ onVersionMismatch?: (clientVersion: string) => void;
57
61
  /**
58
62
  * Plugin-local endpoint `bridge/questionAnswer`: settle one pending
59
63
  * ask_user_question the bridge pushed to this extension. Answered as the
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 + browser_* tools (native-image screenshots) driving the user's own Firefox via the companion AMO extension, with sidebar ask_user_question answering",
4
- "version": "0.4.5",
4
+ "version": "0.4.6",
5
5
  "author": "tuojc",
6
6
  "license": "MIT",
7
7
  "repository": {
package/src/index.ts CHANGED
@@ -32,6 +32,7 @@ import type {} from '@deepseek-ai/dsh-tools'
32
32
  import type {} from '@deepseek-ai/dsh-api-gateway/types'
33
33
  import type {} from '@deepseek-ai/dsh-user-questions/types'
34
34
  import type { WebRoute, WebUpgradeRoute } from '@deepseek-ai/dsh-host-webserver'
35
+ import { readFileSync } from 'node:fs'
35
36
  import { dshHomePath } from '@deepseek-ai/dsh-home-paths'
36
37
  import { BridgeServer } from './server.ts'
37
38
  import { registerBrowserTools } from './tools.ts'
@@ -175,6 +176,16 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
175
176
  }
176
177
  return result
177
178
  }
179
+ // Plugin version for the hello.ok handshake (extension flags a mismatch in
180
+ // the sidebar). src/ and lib/ layouts both resolve to the same package.json.
181
+ let pluginVersion: string | undefined
182
+ try {
183
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) as { version?: unknown }
184
+ pluginVersion = typeof pkg.version === 'string' ? pkg.version : undefined
185
+ } catch {
186
+ pluginVersion = undefined
187
+ }
188
+
178
189
  const questions = new QuestionBridge({
179
190
  // Late-bound through the closure: server is constructed right below.
180
191
  push: (frame) => { server.push(frame) },
@@ -195,6 +206,10 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
195
206
  : questions.answer(parsed)
196
207
  },
197
208
  onConnectionLost: () => { questions.delegateAll() },
209
+ version: pluginVersion,
210
+ onVersionMismatch: (clientVersion) => {
211
+ ctx.logger.warn(`browser extension version ${clientVersion} != plugin version ${pluginVersion ?? '?'}; both components must be updated together`)
212
+ },
198
213
  toolTimeoutMs: resolved.toolTimeoutMs,
199
214
  caps: {
200
215
  snapshotMaxChars: resolved.snapshotMaxChars,
package/src/protocol.ts CHANGED
@@ -103,8 +103,8 @@ export interface QuestionItem {
103
103
 
104
104
  /** Frames sent by the extension to the bridge plugin. */
105
105
  export type ClientFrame =
106
- /** First frame, within HELLO_TIMEOUT_MS of socket open. */
107
- | { t: 'hello'; token: string; caps: BridgeCaps }
106
+ /** First frame, within HELLO_TIMEOUT_MS of socket open. `version` (extension version) lets the plugin detect a version mismatch; absent on pre-0.4.6 clients. */
107
+ | { t: 'hello'; token: string; caps: BridgeCaps; version?: string }
108
108
  /** Unary Remote call: slash-joined endpoint plus the descriptor's native args object. */
109
109
  | { t: 'rpc'; id: string; method: string; args: Record<string, unknown> }
110
110
  /** Open one Remote stream (`session/follow`, `workspace/follow`); frames arrive as `stream.frame`. */
@@ -119,8 +119,8 @@ export type ClientFrame =
119
119
 
120
120
  /** Frames sent by the bridge plugin to the extension. */
121
121
  export type ServerFrame =
122
- /** Accepted after a valid `hello`. */
123
- | { t: 'hello.ok'; caps: BridgeCaps }
122
+ /** Accepted after a valid `hello`. `version` (plugin version) lets the extension detect a version mismatch; absent on pre-0.4.6 servers. */
123
+ | { t: 'hello.ok'; caps: BridgeCaps; version?: string }
124
124
  /** Reply to an `rpc` frame: the RemoteResult wire form, flattened onto the frame. */
125
125
  | { t: 'rpc.result'; id: string; ok: true; value: unknown }
126
126
  | { t: 'rpc.result'; id: string; ok: false; error: RemoteWireFailure }
@@ -208,10 +208,14 @@ export function parseBridgeFrame(text: string): BridgeFrame | undefined {
208
208
  if (typeof frame.t !== 'string') return undefined
209
209
  switch (frame.t) {
210
210
  case 'hello':
211
- return typeof frame.token === 'string'
212
- && isCaps(frame.caps)
213
- ? { t: 'hello', token: frame.token, caps: frame.caps }
214
- : undefined
211
+ if (typeof frame.token !== 'string' || !isCaps(frame.caps)) return undefined
212
+ if (frame.version !== undefined && typeof frame.version !== 'string') return undefined
213
+ return {
214
+ t: 'hello',
215
+ token: frame.token,
216
+ caps: frame.caps,
217
+ ...(frame.version === undefined ? {} : { version: frame.version as string }),
218
+ }
215
219
  case 'rpc':
216
220
  return typeof frame.id === 'string' && typeof frame.method === 'string' && isArgs(frame.args)
217
221
  ? { t: 'rpc', id: frame.id, method: frame.method, args: frame.args }
@@ -233,9 +237,13 @@ export function parseBridgeFrame(text: string): BridgeFrame | undefined {
233
237
  case 'pong':
234
238
  return { t: 'pong' }
235
239
  case 'hello.ok':
236
- return isCaps(frame.caps)
237
- ? { t: 'hello.ok', caps: frame.caps }
238
- : undefined
240
+ if (!isCaps(frame.caps)) return undefined
241
+ if (frame.version !== undefined && typeof frame.version !== 'string') return undefined
242
+ return {
243
+ t: 'hello.ok',
244
+ caps: frame.caps,
245
+ ...(frame.version === undefined ? {} : { version: frame.version as string }),
246
+ }
239
247
  case 'rpc.result':
240
248
  if (typeof frame.id !== 'string') return undefined
241
249
  if (frame.ok === true && 'value' in frame) {
package/src/server.ts CHANGED
@@ -151,6 +151,10 @@ export interface BridgeServerDeps {
151
151
  toolTimeoutMs: number
152
152
  /** Capabilities to echo in `hello.ok` (negotiated snapshot budgets). */
153
153
  caps: BridgeCaps
154
+ /** Plugin version echoed in `hello.ok` so the extension can flag a mismatch (0.4.6+). */
155
+ version?: string | undefined
156
+ /** An authenticated client arrived with a version different from ours. */
157
+ onVersionMismatch?: (clientVersion: string) => void
154
158
  /**
155
159
  * Plugin-local endpoint `bridge/questionAnswer`: settle one pending
156
160
  * ask_user_question the bridge pushed to this extension. Answered as the
@@ -415,7 +419,7 @@ export class BridgeServer {
415
419
  }
416
420
  clearTimeout(helloTimer)
417
421
  helloTimer = undefined
418
- this.promote(ws, remoteAddress, frame.caps)
422
+ this.promote(ws, remoteAddress, frame.caps, frame.version)
419
423
  return
420
424
  }
421
425
  this.handleReadyFrame(frame)
@@ -430,8 +434,11 @@ export class BridgeServer {
430
434
  }
431
435
 
432
436
  /** Promote an authenticated socket to the single active slot. */
433
- private promote(ws: WebSocket, remoteAddress: string | undefined, clientCaps: BridgeCaps): void {
437
+ private promote(ws: WebSocket, remoteAddress: string | undefined, clientCaps: BridgeCaps, clientVersion?: string): void {
434
438
  this.replaceConnection()
439
+ if (clientVersion !== undefined && this.deps.version !== undefined && clientVersion !== this.deps.version) {
440
+ this.deps.onVersionMismatch?.(clientVersion)
441
+ }
435
442
  const abort = new AbortController()
436
443
  const intervalMs = this.deps.pingIntervalMs ?? PING_INTERVAL_MS
437
444
  const allowed = this.deps.missedPongsAllowed ?? DEFAULT_MISSED_PONGS_ALLOWED
@@ -448,7 +455,11 @@ export class BridgeServer {
448
455
  }, intervalMs)
449
456
  conn.ping = ping
450
457
  this.current = conn
451
- sendFrame(ws, { t: 'hello.ok', caps: this.deps.caps })
458
+ sendFrame(ws, {
459
+ t: 'hello.ok',
460
+ caps: this.deps.caps,
461
+ ...(this.deps.version === undefined ? {} : { version: this.deps.version }),
462
+ })
452
463
  ws.once('close', () => {
453
464
  clearInterval(ping)
454
465
  abort.abort()