@vymalo/opencode-browser 0.12.0 → 0.14.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.
Files changed (44) hide show
  1. package/dist/agent-client.d.ts +36 -36
  2. package/dist/agent-client.js +201 -189
  3. package/dist/agent-client.js.map +1 -1
  4. package/dist/broker.d.ts +85 -87
  5. package/dist/broker.js +614 -599
  6. package/dist/broker.js.map +1 -1
  7. package/dist/catalog.d.ts +76 -76
  8. package/dist/catalog.js +826 -596
  9. package/dist/catalog.js.map +1 -1
  10. package/dist/endpoint.d.ts +42 -42
  11. package/dist/endpoint.js +132 -131
  12. package/dist/endpoint.js.map +1 -1
  13. package/dist/index.js +1 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/lib.js +1 -0
  16. package/dist/lib.js.map +1 -1
  17. package/dist/logging.d.ts +6 -6
  18. package/dist/logging.js +60 -63
  19. package/dist/logging.js.map +1 -1
  20. package/dist/node-transport.d.ts +6 -6
  21. package/dist/node-transport.js +48 -44
  22. package/dist/node-transport.js.map +1 -1
  23. package/dist/opencode.d.ts +10 -10
  24. package/dist/opencode.js +143 -146
  25. package/dist/opencode.js.map +1 -1
  26. package/dist/protocol.d.ts +127 -127
  27. package/dist/protocol.js +148 -128
  28. package/dist/protocol.js.map +1 -1
  29. package/dist/schema.d.ts +32 -32
  30. package/dist/schema.js +39 -44
  31. package/dist/schema.js.map +1 -1
  32. package/dist/token-file.d.ts +4 -4
  33. package/dist/token-file.js +68 -60
  34. package/dist/token-file.js.map +1 -1
  35. package/dist/tools.d.ts +11 -11
  36. package/dist/tools.js +128 -123
  37. package/dist/tools.js.map +1 -1
  38. package/dist/transport.d.ts +17 -17
  39. package/dist/transport.js +3 -9
  40. package/dist/transport.js.map +1 -1
  41. package/dist/types.d.ts +61 -61
  42. package/dist/types.js +1 -0
  43. package/dist/types.js.map +1 -1
  44. package/package.json +3 -3
package/dist/protocol.js CHANGED
@@ -1,159 +1,179 @@
1
1
  /**
2
- * Wire protocol shared by the OpenCode plugin (the bridge **server**) and the
3
- * browser extension (the **client**). This module is intentionally
4
- * dependency-free and runtime-agnostic so the extension can mirror it verbatim
5
- * into a browser bundle without pulling in any Bun/Node code.
6
- *
7
- * Canonical copy lives here (`packages/opencode-browser/src/protocol.ts`); the
8
- * extension keeps a byte-for-byte copy at
9
- * `apps/browser-extension/src/shared/protocol.ts`. Keep them in sync.
10
- *
11
- * Topology: extensions cannot host servers, so the plugin opens the WebSocket
12
- * server on 127.0.0.1 and the extension's background worker dials out to it.
13
- * The extension authenticates with a `hello`; the server replies `ready`. From
14
- * then on the server issues `command` frames and the extension answers with a
15
- * matching `result` frame (correlated by `id`). The extension may also push
16
- * unsolicited `event` frames. Heartbeats use `ping`/`pong`.
17
- */
2
+ * Wire protocol shared by the OpenCode plugin (the bridge **server**) and the
3
+ * browser extension (the **client**). This module is intentionally
4
+ * dependency-free and runtime-agnostic so the extension can mirror it verbatim
5
+ * into a browser bundle without pulling in any Bun/Node code.
6
+ *
7
+ * Canonical copy lives here (`packages/opencode-browser/src/protocol.ts`); the
8
+ * extension keeps a byte-for-byte copy at
9
+ * `apps/browser-extension/src/shared/protocol.ts`. Keep them in sync.
10
+ *
11
+ * Topology: extensions cannot host servers, so the plugin opens the WebSocket
12
+ * server on 127.0.0.1 and the extension's background worker dials out to it.
13
+ * The extension authenticates with a `hello`; the server replies `ready`. From
14
+ * then on the server issues `command` frames and the extension answers with a
15
+ * matching `result` frame (correlated by `id`). The extension may also push
16
+ * unsolicited `event` frames. Heartbeats use `ping`/`pong`.
17
+ */
18
18
  /** Bump when the frame shapes change incompatibly. */
19
19
  export const PROTOCOL_VERSION = 1;
20
20
  export const BROWSER_ACTIONS = [
21
- "open",
22
- "navigate",
23
- "click",
24
- "double_click",
25
- "type",
26
- "fill",
27
- "select",
28
- "scroll",
29
- "press_key",
30
- "screenshot",
31
- "snapshot",
32
- "get_text",
33
- "wait",
34
- "tabs",
35
- "close",
36
- "back",
37
- "forward",
38
- "reload",
39
- "hover",
40
- "activate",
41
- "drag",
42
- "upload",
43
- "get_html",
44
- "get_attribute",
45
- "query",
46
- "eval",
47
- "console",
48
- "network",
49
- "handle_dialog",
50
- "set_viewport",
51
- "cookies",
52
- "targets",
53
- "release",
54
- "request_feedback"
21
+ "open",
22
+ "navigate",
23
+ "click",
24
+ "double_click",
25
+ "type",
26
+ "fill",
27
+ "select",
28
+ "scroll",
29
+ "press_key",
30
+ "screenshot",
31
+ "snapshot",
32
+ "get_text",
33
+ "wait",
34
+ "tabs",
35
+ "close",
36
+ "back",
37
+ "forward",
38
+ "reload",
39
+ "hover",
40
+ "activate",
41
+ "drag",
42
+ "upload",
43
+ "get_html",
44
+ "get_attribute",
45
+ "query",
46
+ "eval",
47
+ "console",
48
+ "network",
49
+ "handle_dialog",
50
+ "set_viewport",
51
+ "cookies",
52
+ "targets",
53
+ "release",
54
+ "request_feedback"
55
55
  ];
56
56
  /** Serialize a frame for the wire. */
57
57
  export function encodeFrame(frame) {
58
- return JSON.stringify(frame);
58
+ return JSON.stringify(frame);
59
59
  }
60
60
  function isRecord(value) {
61
- return typeof value === "object" && value !== null;
61
+ return typeof value === "object" && value !== null;
62
62
  }
63
63
  /**
64
- * Parse and shape-check an inbound frame. Returns the typed frame, or `null` if
65
- * the payload is not a recognizable frame (caller decides whether to drop or
66
- * log). Validation is deliberately lightweight — both ends are trusted once the
67
- * token handshake succeeds; this guards against malformed JSON and version skew,
68
- * not a hostile peer.
69
- */
64
+ * Parse and shape-check an inbound frame. Returns the typed frame, or `null` if
65
+ * the payload is not a recognizable frame (caller decides whether to drop or
66
+ * log). Validation is deliberately lightweight — both ends are trusted once the
67
+ * token handshake succeeds; this guards against malformed JSON and version skew,
68
+ * not a hostile peer.
69
+ */
70
70
  export function decodeFrame(raw) {
71
- let parsed;
72
- try {
73
- parsed = JSON.parse(raw);
74
- }
75
- catch {
76
- return null;
77
- }
78
- if (!isRecord(parsed) || typeof parsed.type !== "string") {
79
- return null;
80
- }
81
- switch (parsed.type) {
82
- case "hello":
83
- return typeof parsed.token === "string" ? parsed : null;
84
- case "ready":
85
- return parsed;
86
- case "command":
87
- return typeof parsed.id === "string" &&
88
- typeof parsed.action === "string" &&
89
- typeof parsed.group === "string"
90
- ? parsed
91
- : null;
92
- case "result":
93
- return typeof parsed.id === "string" && typeof parsed.ok === "boolean"
94
- ? parsed
95
- : null;
96
- case "event":
97
- return typeof parsed.name === "string" ? parsed : null;
98
- case "release":
99
- return { v: PROTOCOL_VERSION, type: "release" };
100
- case "cancel":
101
- return typeof parsed.id === "string" ? parsed : null;
102
- case "rejected":
103
- return typeof parsed.reason === "string" ? parsed : null;
104
- case "ping":
105
- return { v: PROTOCOL_VERSION, type: "ping" };
106
- case "pong":
107
- return { v: PROTOCOL_VERSION, type: "pong" };
108
- default:
109
- return null;
110
- }
71
+ let parsed;
72
+ try {
73
+ parsed = JSON.parse(raw);
74
+ } catch {
75
+ return null;
76
+ }
77
+ if (!isRecord(parsed) || typeof parsed.type !== "string") {
78
+ return null;
79
+ }
80
+ switch (parsed.type) {
81
+ case "hello": return typeof parsed.token === "string" ? parsed : null;
82
+ case "ready": return parsed;
83
+ case "command": return typeof parsed.id === "string" && typeof parsed.action === "string" && typeof parsed.group === "string" ? parsed : null;
84
+ case "result": return typeof parsed.id === "string" && typeof parsed.ok === "boolean" ? parsed : null;
85
+ case "event": return typeof parsed.name === "string" ? parsed : null;
86
+ case "release": return {
87
+ v: PROTOCOL_VERSION,
88
+ type: "release"
89
+ };
90
+ case "cancel": return typeof parsed.id === "string" ? parsed : null;
91
+ case "rejected": return typeof parsed.reason === "string" ? parsed : null;
92
+ case "ping": return {
93
+ v: PROTOCOL_VERSION,
94
+ type: "ping"
95
+ };
96
+ case "pong": return {
97
+ v: PROTOCOL_VERSION,
98
+ type: "pong"
99
+ };
100
+ default: return null;
101
+ }
111
102
  }
112
103
  let idCounter = 0;
113
104
  /**
114
- * Monotonic correlation id for command frames. Process-local and collision-free
115
- * within a single bridge instance, which is all that's required (the server is
116
- * the only id minter).
117
- */
105
+ * Monotonic correlation id for command frames. Process-local and collision-free
106
+ * within a single bridge instance, which is all that's required (the server is
107
+ * the only id minter).
108
+ */
118
109
  export function nextId() {
119
- idCounter = (idCounter + 1) % Number.MAX_SAFE_INTEGER;
120
- return `c${idCounter.toString(36)}`;
110
+ idCounter = (idCounter + 1) % Number.MAX_SAFE_INTEGER;
111
+ return `c${idCounter.toString(36)}`;
121
112
  }
122
113
  export function helloFrame(token, opts = {}) {
123
- return { v: PROTOCOL_VERSION, type: "hello", token, ...opts };
114
+ return {
115
+ v: PROTOCOL_VERSION,
116
+ type: "hello",
117
+ token,
118
+ ...opts
119
+ };
124
120
  }
125
121
  export function resultFrame(id, data) {
126
- return { v: PROTOCOL_VERSION, type: "result", id, ok: true, data };
122
+ return {
123
+ v: PROTOCOL_VERSION,
124
+ type: "result",
125
+ id,
126
+ ok: true,
127
+ data
128
+ };
127
129
  }
128
130
  export function errorFrame(id, message, code) {
129
- return { v: PROTOCOL_VERSION, type: "result", id, ok: false, error: { message, code } };
131
+ return {
132
+ v: PROTOCOL_VERSION,
133
+ type: "result",
134
+ id,
135
+ ok: false,
136
+ error: {
137
+ message,
138
+ code
139
+ }
140
+ };
130
141
  }
131
142
  export function rejectedFrame(reason) {
132
- return { v: PROTOCOL_VERSION, type: "rejected", reason };
143
+ return {
144
+ v: PROTOCOL_VERSION,
145
+ type: "rejected",
146
+ reason
147
+ };
133
148
  }
134
149
  /**
135
- * A short, **non-secret** fingerprint of a bridge token, safe to log. It never
136
- * reveals the token: just its length plus a base36 digest, so two sides can log
137
- * `tokenFingerprint(...)` and a human can see at a glance whether the executor's
138
- * token matches the broker's — the whole point when debugging `bad_token`.
139
- */
150
+ * A short, **non-secret** fingerprint of a bridge token, safe to log. It never
151
+ * reveals the token: just its length plus a base36 digest, so two sides can log
152
+ * `tokenFingerprint(...)` and a human can see at a glance whether the executor's
153
+ * token matches the broker's — the whole point when debugging `bad_token`.
154
+ */
140
155
  export function tokenFingerprint(token) {
141
- // Defensive: this is logged from a connection handler, so never throw on a
142
- // non-string slipping through (a malformed/forged frame) — a crash there is
143
- // worse than a vague fingerprint.
144
- if (typeof token !== "string") {
145
- return "invalid";
146
- }
147
- // djb2 — tiny, dependency-free, stable. Collisions are irrelevant: this is a
148
- // visual match aid, not a security primitive.
149
- let hash = 5381;
150
- for (let i = 0; i < token.length; i++) {
151
- hash = (hash * 33) ^ token.charCodeAt(i);
152
- }
153
- const digest = (hash >>> 0).toString(36);
154
- return token.length === 0 ? "empty" : `len${token.length}.${digest}`;
156
+ // Defensive: this is logged from a connection handler, so never throw on a
157
+ // non-string slipping through (a malformed/forged frame) — a crash there is
158
+ // worse than a vague fingerprint.
159
+ if (typeof token !== "string") {
160
+ return "invalid";
161
+ }
162
+ // djb2 — tiny, dependency-free, stable. Collisions are irrelevant: this is a
163
+ // visual match aid, not a security primitive.
164
+ let hash = 5381;
165
+ for (let i = 0; i < token.length; i++) {
166
+ hash = hash * 33 ^ token.charCodeAt(i);
167
+ }
168
+ const digest = (hash >>> 0).toString(36);
169
+ return token.length === 0 ? "empty" : `len${token.length}.${digest}`;
155
170
  }
156
171
  export function cancelFrame(id) {
157
- return { v: PROTOCOL_VERSION, type: "cancel", id };
172
+ return {
173
+ v: PROTOCOL_VERSION,
174
+ type: "cancel",
175
+ id
176
+ };
158
177
  }
178
+
159
179
  //# sourceMappingURL=protocol.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,sDAAsD;AACtD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAuClC,MAAM,CAAC,MAAM,eAAe,GAA6B;IACvD,MAAM;IACN,UAAU;IACV,OAAO;IACP,cAAc;IACd,MAAM;IACN,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,YAAY;IACZ,UAAU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ol.ts"],"version":3,"file":"protocol.js","sourceRoot":""}
package/dist/schema.d.ts CHANGED
@@ -1,51 +1,51 @@
1
1
  /**
2
- * A tiny, neutral schema vocabulary for tool arguments. The tool catalog
3
- * (`catalog.ts`) is the single source of truth; each adapter turns these specs
4
- * into its own format:
5
- * - the OpenCode plugin builds a zod shape (see `inputToZodShape` in tools.ts),
6
- * - the MCP server emits standard JSON Schema via `toJsonSchema` below.
7
- *
8
- * Keeping the vocabulary small (string/number/boolean/array/object + enum +
9
- * optional + description) avoids dragging a specific zod version across the
10
- * package boundary while still covering every tool's args.
11
- */
2
+ * A tiny, neutral schema vocabulary for tool arguments. The tool catalog
3
+ * (`catalog.ts`) is the single source of truth; each adapter turns these specs
4
+ * into its own format:
5
+ * - the OpenCode plugin builds a zod shape (see `inputToZodShape` in tools.ts),
6
+ * - the MCP server emits standard JSON Schema via `toJsonSchema` below.
7
+ *
8
+ * Keeping the vocabulary small (string/number/boolean/array/object + enum +
9
+ * optional + description) avoids dragging a specific zod version across the
10
+ * package boundary while still covering every tool's args.
11
+ */
12
12
  export type ToolGroup = "page" | "control" | "debug" | "interactive";
13
13
  export interface StringField {
14
- type: "string";
15
- description?: string;
16
- optional?: boolean;
17
- enum?: readonly string[];
14
+ type: "string";
15
+ description?: string;
16
+ optional?: boolean;
17
+ enum?: readonly string[];
18
18
  }
19
19
  export interface NumberField {
20
- type: "number";
21
- description?: string;
22
- optional?: boolean;
20
+ type: "number";
21
+ description?: string;
22
+ optional?: boolean;
23
23
  }
24
24
  export interface BooleanField {
25
- type: "boolean";
26
- description?: string;
27
- optional?: boolean;
25
+ type: "boolean";
26
+ description?: string;
27
+ optional?: boolean;
28
28
  }
29
29
  export interface ArrayField {
30
- type: "array";
31
- description?: string;
32
- optional?: boolean;
33
- items: Field;
30
+ type: "array";
31
+ description?: string;
32
+ optional?: boolean;
33
+ items: Field;
34
34
  }
35
35
  export interface ObjectField {
36
- type: "object";
37
- description?: string;
38
- optional?: boolean;
39
- properties: Record<string, Field>;
36
+ type: "object";
37
+ description?: string;
38
+ optional?: boolean;
39
+ properties: Record<string, Field>;
40
40
  }
41
41
  export type Field = StringField | NumberField | BooleanField | ArrayField | ObjectField;
42
42
  /** Top-level argument map for a tool. */
43
43
  export type JsonInput = Record<string, Field>;
44
44
  export interface JsonSchema {
45
- type: "object";
46
- properties: Record<string, unknown>;
47
- required: string[];
48
- additionalProperties: false;
45
+ type: "object";
46
+ properties: Record<string, unknown>;
47
+ required: string[];
48
+ additionalProperties: false;
49
49
  }
50
50
  /** Convert a tool's input spec to a standard JSON Schema object (for MCP). */
51
51
  export declare function toJsonSchema(input: JsonInput): JsonSchema;
package/dist/schema.js CHANGED
@@ -1,50 +1,45 @@
1
- /**
2
- * A tiny, neutral schema vocabulary for tool arguments. The tool catalog
3
- * (`catalog.ts`) is the single source of truth; each adapter turns these specs
4
- * into its own format:
5
- * - the OpenCode plugin builds a zod shape (see `inputToZodShape` in tools.ts),
6
- * - the MCP server emits standard JSON Schema via `toJsonSchema` below.
7
- *
8
- * Keeping the vocabulary small (string/number/boolean/array/object + enum +
9
- * optional + description) avoids dragging a specific zod version across the
10
- * package boundary while still covering every tool's args.
11
- */
12
1
  function fieldToJsonSchema(field) {
13
- const out = { type: field.type };
14
- if (field.description) {
15
- out.description = field.description;
16
- }
17
- if (field.type === "string" && field.enum) {
18
- out.enum = [...field.enum];
19
- }
20
- if (field.type === "array") {
21
- out.items = fieldToJsonSchema(field.items);
22
- }
23
- if (field.type === "object") {
24
- const properties = {};
25
- const required = [];
26
- for (const [key, value] of Object.entries(field.properties)) {
27
- properties[key] = fieldToJsonSchema(value);
28
- if (!value.optional) {
29
- required.push(key);
30
- }
31
- }
32
- out.properties = properties;
33
- out.required = required;
34
- out.additionalProperties = false;
35
- }
36
- return out;
2
+ const out = { type: field.type };
3
+ if (field.description) {
4
+ out.description = field.description;
5
+ }
6
+ if (field.type === "string" && field.enum) {
7
+ out.enum = [...field.enum];
8
+ }
9
+ if (field.type === "array") {
10
+ out.items = fieldToJsonSchema(field.items);
11
+ }
12
+ if (field.type === "object") {
13
+ const properties = {};
14
+ const required = [];
15
+ for (const [key, value] of Object.entries(field.properties)) {
16
+ properties[key] = fieldToJsonSchema(value);
17
+ if (!value.optional) {
18
+ required.push(key);
19
+ }
20
+ }
21
+ out.properties = properties;
22
+ out.required = required;
23
+ out.additionalProperties = false;
24
+ }
25
+ return out;
37
26
  }
38
27
  /** Convert a tool's input spec to a standard JSON Schema object (for MCP). */
39
28
  export function toJsonSchema(input) {
40
- const properties = {};
41
- const required = [];
42
- for (const [key, field] of Object.entries(input)) {
43
- properties[key] = fieldToJsonSchema(field);
44
- if (!field.optional) {
45
- required.push(key);
46
- }
47
- }
48
- return { type: "object", properties, required, additionalProperties: false };
29
+ const properties = {};
30
+ const required = [];
31
+ for (const [key, field] of Object.entries(input)) {
32
+ properties[key] = fieldToJsonSchema(field);
33
+ if (!field.optional) {
34
+ required.push(key);
35
+ }
36
+ }
37
+ return {
38
+ type: "object",
39
+ properties,
40
+ required,
41
+ additionalProperties: false
42
+ };
49
43
  }
44
+
50
45
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA4CH,SAAS,iBAAiB,CAAC,KAAY;IACrC,MAAM,GAAG,GAA4B,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1D,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;QACtB,GAAG,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;IACtC,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QAC1C,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,C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C;AAC/E,CAAC"}
1
+ {"mappings":"AAsDA,SAAS,kBAAkB,OAAuC;CAChE,MAAM,MAA+B,EAAE,MAAM,MAAM,KAAK;CACxD,IAAI,MAAM,aAAa;EACrB,IAAI,cAAc,MAAM;CAC1B;CACA,IAAI,MAAM,SAAS,YAAY,MAAM,MAAM;EACzC,IAAI,OAAO,CAAC,GAAG,MAAM,IAAI;CAC3B;CACA,IAAI,MAAM,SAAS,SAAS;EAC1B,IAAI,QAAQ,kBAAkB,MAAM,KAAK;CAC3C;CACA,IAAI,MAAM,SAAS,UAAU;EAC3B,MAAM,aAAsC,CAAC;EAC7C,MAAM,WAAqB,CAAC;EAC5B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,UAAU,GAAG;GAC3D,WAAW,OAAO,kBAAkB,KAAK;GACzC,IAAI,CAAC,MAAM,UAAU;IACnB,SAAS,KAAK,GAAG;GACnB;EACF;EACA,IAAI,aAAa;EACjB,IAAI,WAAW;EACf,IAAI,uBAAuB;CAC7B;CACA,OAAO;AACT;;AAGA,OAAO,SAAS,aAAa,OAA8B;CACzD,MAAM,aAAsC,CAAC;CAC7C,MAAM,WAAqB,CAAC;CAC5B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,GAAG;EAChD,WAAW,OAAO,kBAAkB,KAAK;EACzC,IAAI,CAAC,MAAM,UAAU;GACnB,SAAS,KAAK,GAAG;EACnB;CACF;CACA,OAAO;EAAE,MAAM;EAAU;EAAY;EAAU,sBAAsB;CAAM;AAC7E","names":[],"sources":["../src/schema.ts"],"version":3,"file":"schema.js","sourceRoot":""}
@@ -1,12 +1,12 @@
1
1
  export interface BridgeFile {
2
- port?: number;
3
- token?: string;
2
+ port?: number;
3
+ token?: string;
4
4
  }
5
5
  export declare function readBridgeFile(): BridgeFile | null;
6
6
  export declare function writeBridgeFile(port: number, token: string): void;
7
7
  export type TokenSource = "explicit" | "file" | "generated";
8
8
  /** Resolve the bridge token: explicit option wins, else a shared file, else generate. */
9
9
  export declare function resolveSharedToken(port: number, explicit: string | undefined, generate: () => string): {
10
- token: string;
11
- source: TokenSource;
10
+ token: string;
11
+ source: TokenSource;
12
12
  };