@octane-xplat/devtools 0.0.0-nightly.g1b95ef7

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 (64) hide show
  1. package/README.md +5 -0
  2. package/dist/app.d.ts +28 -0
  3. package/dist/app.js +66 -0
  4. package/dist/backend.d.ts +31 -0
  5. package/dist/backend.js +182 -0
  6. package/dist/client.d.ts +49 -0
  7. package/dist/client.js +168 -0
  8. package/dist/host/desktop.d.ts +15 -0
  9. package/dist/host/desktop.js +133 -0
  10. package/dist/host/panels.d.ts +14 -0
  11. package/dist/host/panels.js +156 -0
  12. package/dist/host/records.d.ts +5 -0
  13. package/dist/host/records.js +46 -0
  14. package/dist/host/server.d.ts +8 -0
  15. package/dist/host/server.js +67 -0
  16. package/dist/host/web.d.ts +5 -0
  17. package/dist/host/web.js +74 -0
  18. package/dist/macos/index.macos.d.ts +3 -0
  19. package/dist/macos/index.macos.js +5 -0
  20. package/dist/macos/servers.macos.d.ts +4 -0
  21. package/dist/macos/servers.macos.js +57 -0
  22. package/dist/macos/socket.macos.d.ts +2 -0
  23. package/dist/macos/socket.macos.js +152 -0
  24. package/dist/macos/ws-frames.d.ts +24 -0
  25. package/dist/macos/ws-frames.js +205 -0
  26. package/dist/node.d.ts +12 -0
  27. package/dist/node.js +51 -0
  28. package/dist/record.d.ts +9 -0
  29. package/dist/record.js +38 -0
  30. package/dist/types.d.ts +128 -0
  31. package/dist/types.js +25 -0
  32. package/package.json +88 -0
  33. package/src/app.ts +105 -0
  34. package/src/assets.d.ts +2 -0
  35. package/src/backend.ts +278 -0
  36. package/src/client.ts +248 -0
  37. package/src/desktop/Shell.macos.tsrx +158 -0
  38. package/src/desktop/Shell.ts +16 -0
  39. package/src/desktop/index.macos.ts +7 -0
  40. package/src/desktop/main.macos.ts +130 -0
  41. package/src/desktop/panels.d.ts +10 -0
  42. package/src/desktop/target.ts +34 -0
  43. package/src/host/desktop.ts +176 -0
  44. package/src/host/panels.ts +193 -0
  45. package/src/host/records.ts +62 -0
  46. package/src/host/server.ts +92 -0
  47. package/src/host/web.ts +68 -0
  48. package/src/macos/index.macos.ts +7 -0
  49. package/src/macos/servers.macos.ts +83 -0
  50. package/src/macos/socket.macos.ts +218 -0
  51. package/src/macos/ws-frames.ts +249 -0
  52. package/src/node.ts +60 -0
  53. package/src/panel/App.tsrx +288 -0
  54. package/src/panel/index.html +12 -0
  55. package/src/panel/index.ts +24 -0
  56. package/src/panel/main.tsrx +2 -0
  57. package/src/panel/main.web.tsrx +89 -0
  58. package/src/panel/model.ts +216 -0
  59. package/src/panel/panel.css +189 -0
  60. package/src/panel/plugin.ts +65 -0
  61. package/src/panel/styles.ts +5 -0
  62. package/src/panel/tsconfig.browser.json +9 -0
  63. package/src/record.ts +66 -0
  64. package/src/types.ts +129 -0
@@ -0,0 +1,205 @@
1
+ // Pure WebSocket framing: handshake request/accept, masked client frame
2
+ // encoding, and an incremental decoder (chunked input, fragmented
3
+ // continuation frames, 16/64-bit lengths). No host APIs — node --test-able.
4
+ export function utf8Encode(s) {
5
+ const out = new Uint8Array(s.length * 4);
6
+ let n = 0;
7
+ for (let i = 0; i < s.length; i++) {
8
+ let c = s.charCodeAt(i);
9
+ if (c >= 0xd800 && c < 0xdc00 && i + 1 < s.length) {
10
+ c = 0x10000 + ((c - 0xd800) << 10) + (s.charCodeAt(++i) - 0xdc00);
11
+ }
12
+ if (c < 0x80) {
13
+ out[n++] = c;
14
+ }
15
+ else if (c < 0x800) {
16
+ out[n++] = 0xc0 | (c >> 6);
17
+ out[n++] = 0x80 | (c & 0x3f);
18
+ }
19
+ else if (c < 0x10000) {
20
+ out[n++] = 0xe0 | (c >> 12);
21
+ out[n++] = 0x80 | ((c >> 6) & 0x3f);
22
+ out[n++] = 0x80 | (c & 0x3f);
23
+ }
24
+ else {
25
+ out[n++] = 0xf0 | (c >> 18);
26
+ out[n++] = 0x80 | ((c >> 12) & 0x3f);
27
+ out[n++] = 0x80 | ((c >> 6) & 0x3f);
28
+ out[n++] = 0x80 | (c & 0x3f);
29
+ }
30
+ }
31
+ return out.subarray(0, n);
32
+ }
33
+ export function utf8Decode(bytes) {
34
+ let s = '';
35
+ for (let i = 0; i < bytes.length; i++) {
36
+ const b = bytes[i];
37
+ if (b < 0x80) {
38
+ s += String.fromCharCode(b);
39
+ }
40
+ else if (b < 0xe0) {
41
+ s += String.fromCharCode(((b & 0x1f) << 6) | (bytes[++i] & 0x3f));
42
+ }
43
+ else if (b < 0xf0) {
44
+ s += String.fromCharCode(((b & 0x0f) << 12) | ((bytes[++i] & 0x3f) << 6) | (bytes[++i] & 0x3f));
45
+ }
46
+ else {
47
+ const cp = ((b & 0x07) << 18) |
48
+ ((bytes[++i] & 0x3f) << 12) |
49
+ ((bytes[++i] & 0x3f) << 6) |
50
+ (bytes[++i] & 0x3f);
51
+ s += String.fromCharCode(0xd800 + ((cp - 0x10000) >> 10), 0xdc00 + ((cp - 0x10000) & 0x3ff));
52
+ }
53
+ }
54
+ return s;
55
+ }
56
+ const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
57
+ export function base64Encode(bytes) {
58
+ let out = '';
59
+ for (let i = 0; i < bytes.length; i += 3) {
60
+ const a = bytes[i], b = bytes[i + 1], c = bytes[i + 2];
61
+ out +=
62
+ B64[a >> 2] +
63
+ B64[((a & 3) << 4) | ((b ?? 0) >> 4)] +
64
+ (b === undefined ? '=' : B64[((b & 15) << 2) | ((c ?? 0) >> 6)]) +
65
+ (c === undefined ? '=' : B64[c & 63]);
66
+ }
67
+ return out;
68
+ }
69
+ export function handshakeRequest(host, port, path) {
70
+ const key = base64Encode(utf8Encode(`${Date.now()}${Math.random()}`).subarray(0, 16));
71
+ const request = `GET ${path} HTTP/1.1\r\nHost: ${host}:${port}\r\nUpgrade: websocket\r\n` +
72
+ `Connection: Upgrade\r\nSec-WebSocket-Key: ${key}\r\nSec-WebSocket-Version: 13\r\n\r\n`;
73
+ return utf8Encode(request);
74
+ }
75
+ // Returns the byte offset past the headers on 101, or -1 when incomplete,
76
+ // or throws on a rejected upgrade.
77
+ export function handshakeAccept(buffer) {
78
+ const text = utf8Decode(buffer);
79
+ const end = text.indexOf('\r\n\r\n');
80
+ if (end < 0) {
81
+ return -1;
82
+ }
83
+ const status = /^HTTP\/[\d.]+ (\d+)/.exec(text)?.[1];
84
+ if (status !== '101') {
85
+ throw new Error(`websocket upgrade rejected: ${text.slice(0, end)}`);
86
+ }
87
+ return end + 4;
88
+ }
89
+ export function encodeFrame(opcode, payload, maskKey) {
90
+ const mask = maskKey ?? new Uint8Array(4);
91
+ if (!maskKey) {
92
+ for (let i = 0; i < 4; i++) {
93
+ mask[i] = (Math.random() * 256) | 0;
94
+ }
95
+ }
96
+ const len = payload.length;
97
+ const header = [0x80 | opcode];
98
+ if (len < 126) {
99
+ header.push(0x80 | len);
100
+ }
101
+ else if (len < 65536) {
102
+ header.push(0x80 | 126, len >> 8, len & 0xff);
103
+ }
104
+ else {
105
+ header.push(0x80 | 127);
106
+ for (let s = 56; s >= 0; s -= 8) {
107
+ header.push(((len / 2 ** s) | 0) & 0xff);
108
+ }
109
+ }
110
+ const out = new Uint8Array(header.length + 4 + len);
111
+ out.set(header, 0);
112
+ out.set(mask, header.length);
113
+ for (let i = 0; i < len; i++) {
114
+ out[header.length + 4 + i] = payload[i] ^ mask[i & 3];
115
+ }
116
+ return out;
117
+ }
118
+ // Incremental server→client decoder. Server frames arrive unmasked; control
119
+ // frames are never fragmented; data frames may fragment — continuation
120
+ // payloads accumulate until FIN.
121
+ export class FrameDecoder {
122
+ constructor() {
123
+ this.buffer = new Uint8Array(0);
124
+ this.fragments = [];
125
+ this.fragmentOpcode = -1;
126
+ }
127
+ push(chunk) {
128
+ const merged = new Uint8Array(this.buffer.length + chunk.length);
129
+ merged.set(this.buffer, 0);
130
+ merged.set(chunk, this.buffer.length);
131
+ this.buffer = merged;
132
+ const events = [];
133
+ for (;;) {
134
+ if (this.buffer.length < 2) {
135
+ return events;
136
+ }
137
+ const b = this.buffer;
138
+ const fin = (b[0] & 0x80) !== 0;
139
+ const opcode = b[0] & 0x0f;
140
+ if (b[1] & 0x80) {
141
+ throw new Error('masked server frame');
142
+ }
143
+ const len0 = b[1] & 0x7f;
144
+ const off = len0 < 126 ? 2 : len0 === 126 ? 4 : 10;
145
+ let len = len0;
146
+ if (len0 === 126) {
147
+ len = (b[2] << 8) | b[3];
148
+ }
149
+ else if (len0 === 127) {
150
+ const n = (BigInt(b[2]) << 56n) |
151
+ (BigInt(b[3]) << 48n) |
152
+ (BigInt(b[4]) << 40n) |
153
+ (BigInt(b[5]) << 32n) |
154
+ (BigInt(b[6]) << 24n) |
155
+ (BigInt(b[7]) << 16n) |
156
+ (BigInt(b[8]) << 8n) |
157
+ BigInt(b[9]);
158
+ len = Number(n);
159
+ }
160
+ if (this.buffer.length < off + len) {
161
+ return events;
162
+ }
163
+ const payload = b.subarray(off, off + len);
164
+ this.buffer = b.subarray(off + len);
165
+ if (opcode === 0) {
166
+ if (this.fragmentOpcode < 0) {
167
+ throw new Error('continuation without start');
168
+ }
169
+ this.fragments.push(payload);
170
+ if (fin) {
171
+ const total = this.fragments.reduce((n, f) => n + f.length, 0);
172
+ const joined = new Uint8Array(total);
173
+ let o = 0;
174
+ for (const f of this.fragments) {
175
+ joined.set(f, o);
176
+ o += f.length;
177
+ }
178
+ this.fragments = [];
179
+ if (this.fragmentOpcode === 1) {
180
+ events.push({ type: 'text', data: utf8Decode(joined) });
181
+ }
182
+ this.fragmentOpcode = -1;
183
+ }
184
+ }
185
+ else if (opcode === 1) {
186
+ if (fin) {
187
+ events.push({ type: 'text', data: utf8Decode(payload) });
188
+ }
189
+ else {
190
+ this.fragmentOpcode = 1;
191
+ this.fragments = [payload];
192
+ }
193
+ }
194
+ else if (opcode === 8) {
195
+ events.push({ type: 'close' });
196
+ }
197
+ else if (opcode === 9) {
198
+ events.push({ type: 'ping', payload });
199
+ }
200
+ else if (opcode === 10) {
201
+ events.push({ type: 'pong', payload });
202
+ }
203
+ }
204
+ }
205
+ }
package/dist/node.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { serveDevtools } from './host/server.ts';
2
+ import { listDevtoolsServers } from './host/records.ts';
3
+ export { serveDevtools, listDevtoolsServers };
4
+ export type { DevtoolsHost } from './host/server.ts';
5
+ export type { ListedDevtoolsServer } from './host/records.ts';
6
+ /**
7
+ * Starts the panel host. `--port N` pins a port (default 0 = ephemeral);
8
+ * `--json` reports the endpoint as JSON for launchers, otherwise a URL line
9
+ * is printed. Resolves once the server is listening and stays alive until
10
+ * SIGINT/SIGTERM.
11
+ */
12
+ export declare function devtoolsHostMain(argv?: string[]): Promise<void>;
package/dist/node.js ADDED
@@ -0,0 +1,51 @@
1
+ // Node-side devtools host entry — `@octane-xplat/devtools/node`.
2
+ // The Go `xplat devtools` command (or a direct `node dist/node.js --serve`)
3
+ // launches this module; it serves the panel over loopback and prints the
4
+ // endpoint as a single JSON line for the launching process.
5
+ import { serveDevtools } from './host/server.js';
6
+ import { listDevtoolsServers } from './host/records.js';
7
+ export { serveDevtools, listDevtoolsServers };
8
+ /**
9
+ * Starts the panel host. `--port N` pins a port (default 0 = ephemeral);
10
+ * `--json` reports the endpoint as JSON for launchers, otherwise a URL line
11
+ * is printed. Resolves once the server is listening and stays alive until
12
+ * SIGINT/SIGTERM.
13
+ */
14
+ export async function devtoolsHostMain(argv = process.argv.slice(2)) {
15
+ let port = 0;
16
+ let json = false;
17
+ for (let i = 0; i < argv.length; i++) {
18
+ if (argv[i] === '--json') {
19
+ json = true;
20
+ }
21
+ else if (argv[i] === '--port') {
22
+ port = Number.parseInt(argv[++i] ?? '', 10);
23
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
24
+ throw new Error('devtools host port must be an integer from 0 to 65535');
25
+ }
26
+ }
27
+ else {
28
+ throw new Error(`Unknown devtools host argument: ${argv[i]}`);
29
+ }
30
+ }
31
+ const host = await serveDevtools({ port });
32
+ if (json) {
33
+ process.stdout.write(`${JSON.stringify({ endpoint: host.endpoint })}\n`);
34
+ }
35
+ else {
36
+ process.stdout.write(`Octane Xplat devtools: ${host.endpoint}\n`);
37
+ }
38
+ const close = async () => {
39
+ await host.close();
40
+ process.exit(0);
41
+ };
42
+ process.once('SIGINT', close);
43
+ process.once('SIGTERM', close);
44
+ }
45
+ const invoked = process.argv[1];
46
+ if (invoked && import.meta.url === new URL(`file://${invoked}`).href) {
47
+ devtoolsHostMain().catch((error) => {
48
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
49
+ process.exit(1);
50
+ });
51
+ }
@@ -0,0 +1,9 @@
1
+ export interface ListedDevtoolsServer {
2
+ /** app-key directory the record was published under. */
3
+ key: string;
4
+ appRoot: string;
5
+ endpoint: string;
6
+ instanceId: string;
7
+ devtoolsToken: string;
8
+ }
9
+ export declare function parseDevtoolsServerRecord(key: string, data: string, isAbsolutePath: (path: string) => boolean): ListedDevtoolsServer | null;
package/dist/record.js ADDED
@@ -0,0 +1,38 @@
1
+ // Host-neutral discovery-record validation, shared by the Node records leaf
2
+ // (src/host/records.ts) and the macOS Foundation leaf
3
+ // (src/macos/servers.macos.ts). Mirrors dev_server_record.go: records live
4
+ // under the native history cache in dev-servers-v1/<app-key>/server.json, one
5
+ // per app, each carrying the panel's devtoolsToken. The RPC token is never
6
+ // returned to the panel.
7
+ const ENDPOINT = /^http:\/\/127\.0\.0\.1:\d{1,5}\/rpc$/;
8
+ // Light validation only — connectDevtools enforces the full contract before
9
+ // opening a socket. Records that fail here are omitted, not fatal.
10
+ // `isAbsolutePath` is the host's own absolute-path check (node:path on Node,
11
+ // a POSIX leading-slash check on the JSC host).
12
+ export function parseDevtoolsServerRecord(key, data, isAbsolutePath) {
13
+ let record;
14
+ try {
15
+ record = JSON.parse(data);
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ if (typeof record !== 'object' ||
21
+ record === null ||
22
+ record.protocol !== 'octane-dev-server' ||
23
+ record.version !== 1) {
24
+ return null;
25
+ }
26
+ const { appRoot, endpoint, instanceId, devtoolsToken } = record;
27
+ if (typeof appRoot !== 'string' ||
28
+ !isAbsolutePath(appRoot) ||
29
+ typeof endpoint !== 'string' ||
30
+ !ENDPOINT.test(endpoint) ||
31
+ typeof instanceId !== 'string' ||
32
+ !/^[a-f0-9]{32}$/.test(instanceId) ||
33
+ typeof devtoolsToken !== 'string' ||
34
+ !/^[a-f0-9]{64}$/.test(devtoolsToken)) {
35
+ return null;
36
+ }
37
+ return { key, appRoot, endpoint, instanceId, devtoolsToken };
38
+ }
@@ -0,0 +1,128 @@
1
+ /** A declared dev action as the app's registry announces it. */
2
+ export interface DevActionRef {
3
+ id: string;
4
+ title?: string;
5
+ description?: string;
6
+ input?: {
7
+ fields?: Record<string, unknown>;
8
+ } & Record<string, unknown>;
9
+ result?: Record<string, unknown>;
10
+ effects?: Record<string, unknown>;
11
+ availability?: {
12
+ platforms?: string[];
13
+ readyWhen?: string;
14
+ route?: {
15
+ url?: string;
16
+ fromInput?: boolean;
17
+ };
18
+ ready?: boolean;
19
+ reason?: string;
20
+ };
21
+ execution?: {
22
+ timeoutMs?: number;
23
+ cancellable?: boolean;
24
+ } & Record<string, unknown>;
25
+ }
26
+ /** A connected app session as the hub reports it in `ready`/`sessions`. */
27
+ export interface SessionSnapshot {
28
+ sessionId: string;
29
+ targetId: string;
30
+ appInstanceId: string;
31
+ platform: string;
32
+ appLabel?: string;
33
+ registryRevision: number;
34
+ state: 'ready' | 'disconnected' | string;
35
+ ownership: string;
36
+ origin: string;
37
+ readiness: string;
38
+ connectedAt: string;
39
+ disconnectedAt: string;
40
+ inspection?: unknown;
41
+ actions?: DevActionRef[];
42
+ channels: {
43
+ id: string;
44
+ version: number;
45
+ }[];
46
+ }
47
+ /** A routing failure reported to a frame's sender (never a close). */
48
+ export interface ChannelError {
49
+ type: 'channel-error';
50
+ code: 'oversize' | 'undeclared_channel' | 'no_backend' | 'no_session' | 'invalid_target';
51
+ channel?: string;
52
+ detail: string;
53
+ }
54
+ /** A connected backend as the hub reports it in `ready`/`backends`. */
55
+ export interface BackendRef {
56
+ channel: string;
57
+ targetId: string;
58
+ }
59
+ interface ReadyFrame {
60
+ type: 'ready';
61
+ panel?: string;
62
+ sessions?: SessionSnapshot[];
63
+ backends?: BackendRef[];
64
+ }
65
+ interface SessionsFrame {
66
+ type: 'sessions';
67
+ sessions?: SessionSnapshot[];
68
+ }
69
+ interface BackendsFrame {
70
+ type: 'backends';
71
+ backends?: BackendRef[];
72
+ }
73
+ /** Frames the hub sends to a `/backend` connection. */
74
+ export type BackendInboundFrame = ReadyFrame | SessionsFrame | {
75
+ type: 'channel';
76
+ channel?: string;
77
+ from: 'app';
78
+ session: string;
79
+ data: unknown;
80
+ } | {
81
+ type: 'channel';
82
+ channel?: string;
83
+ from: 'panel';
84
+ panel: string;
85
+ data: unknown;
86
+ } | ChannelError;
87
+ /** Frames the hub sends to a `/devtools` panel connection. */
88
+ export type PanelInboundFrame = ReadyFrame | SessionsFrame | BackendsFrame | {
89
+ type: 'channel';
90
+ channel: string;
91
+ from: 'app';
92
+ session: string;
93
+ data: unknown;
94
+ } | {
95
+ type: 'channel';
96
+ channel: string;
97
+ from: 'backend';
98
+ targetId: string;
99
+ data: unknown;
100
+ } | ChannelError;
101
+ /**
102
+ * Parse one hub frame at the JSON boundary. The `as` here is the single
103
+ * documented assertion point: frame field validation happens at each call
104
+ * site on the narrowed `type` union, so untrusted input never needs a cast
105
+ * anywhere else.
106
+ */
107
+ export declare function parseHubFrame(text: string): BackendInboundFrame | PanelInboundFrame | undefined;
108
+ /** Structural WebSocket contract shared by Node, browser and JSC hosts. */
109
+ export interface DevSocket {
110
+ readyState: number;
111
+ onopen: (() => void) | null;
112
+ onmessage: ((event: {
113
+ data: unknown;
114
+ }) => void) | null;
115
+ onerror: (() => void) | null;
116
+ onclose: ((event: {
117
+ code: number;
118
+ reason: string;
119
+ }) => void) | null;
120
+ send(data: string): void;
121
+ close(): void;
122
+ }
123
+ /** Named host environment for the global WebSocket constructor. */
124
+ export interface DevGlobalWebSocket {
125
+ WebSocket?: new (url: string) => DevSocket;
126
+ }
127
+ export declare function devSocket(url: string): DevSocket | undefined;
128
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,25 @@
1
+ // Shared wire types for the xplat dev hub's devtools channels. The Go hub
2
+ // routes opaque per-channel JSON between app sessions (/app), per-target Node
3
+ // backends (/backend) and devtools panels (/devtools); these are the frame
4
+ // shapes the three peers exchange.
5
+ /**
6
+ * Parse one hub frame at the JSON boundary. The `as` here is the single
7
+ * documented assertion point: frame field validation happens at each call
8
+ * site on the narrowed `type` union, so untrusted input never needs a cast
9
+ * anywhere else.
10
+ */
11
+ export function parseHubFrame(text) {
12
+ try {
13
+ const frame = JSON.parse(text);
14
+ return typeof frame?.type === 'string'
15
+ ? frame
16
+ : undefined;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ export function devSocket(url) {
23
+ const Constructor = globalThis.WebSocket;
24
+ return Constructor ? new Constructor(url) : undefined;
25
+ }
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@octane-xplat/devtools",
3
+ "version": "0.0.0-nightly.g1b95ef7",
4
+ "description": "Devtools channel clients for Octane Xplat — app channels, per-target Node backends, and devtools panel connections over the xplat dev hub",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/octane-xplat/octane-xplat",
9
+ "directory": "packages/devtools"
10
+ },
11
+ "files": [
12
+ "src",
13
+ "dist"
14
+ ],
15
+ "type": "module",
16
+ "exports": {
17
+ "./app": {
18
+ "types": "./dist/app.d.ts",
19
+ "web": "./src/app.ts",
20
+ "native": "./src/app.ts",
21
+ "default": "./src/app.ts"
22
+ },
23
+ "./backend": {
24
+ "types": "./dist/backend.d.ts",
25
+ "default": "./dist/backend.js"
26
+ },
27
+ "./client": {
28
+ "types": "./dist/client.d.ts",
29
+ "web": "./src/client.ts",
30
+ "default": "./dist/client.js"
31
+ },
32
+ "./macos": {
33
+ "types": "./src/macos/index.macos.ts",
34
+ "default": "./src/macos/index.macos.ts"
35
+ },
36
+ "./desktop": {
37
+ "types": "./src/desktop/index.macos.ts",
38
+ "default": "./src/desktop/index.macos.ts"
39
+ },
40
+ "./desktop-node": {
41
+ "types": "./dist/host/desktop.d.ts",
42
+ "default": "./dist/host/desktop.js"
43
+ },
44
+ "./web-build": {
45
+ "types": "./dist/host/web.d.ts",
46
+ "default": "./dist/host/web.js"
47
+ },
48
+ "./panel": {
49
+ "types": "./src/panel/index.ts",
50
+ "default": "./src/panel/index.ts"
51
+ },
52
+ "./node": {
53
+ "types": "./dist/node.d.ts",
54
+ "default": "./dist/node.js"
55
+ },
56
+ "./host/records": {
57
+ "types": "./dist/host/records.d.ts",
58
+ "default": "./dist/host/records.js"
59
+ },
60
+ "./package.json": "./package.json"
61
+ },
62
+ "scripts": {
63
+ "build": "tsc --runExternalCode -p tsconfig.build.json && vite build --config vite.panel.config.mjs",
64
+ "typegen": "tsc --runExternalCode -p tsconfig.build.json",
65
+ "typecheck": "node ../../scripts/typecheck.ts",
66
+ "test": "node --test tests/*.test.mts"
67
+ },
68
+ "dependencies": {
69
+ "@octane-xplat/platform": "0.0.0-nightly.g1b95ef7",
70
+ "@octane-xplat/ui": "0.0.0-nightly.g1b95ef7"
71
+ },
72
+ "peerDependencies": {
73
+ "octane": ">=0.6.3 <1"
74
+ },
75
+ "devDependencies": {
76
+ "@nativescript/macos-node-api": "0.5.0-beta.0",
77
+ "@octane-xplat/cli": "0.0.0-nightly.g1b95ef7",
78
+ "@octane-xplat/jsx": "0.0.0-nightly.g1b95ef7",
79
+ "@octane-xplat/macos-appkit": "0.0.0-nightly.g1b95ef7",
80
+ "@octanejs/vite-plugin": "0.6.6",
81
+ "@tsrx/content-mapper": "0.1.2",
82
+ "@types/node": "26.6.6",
83
+ "octane": "0.23.2",
84
+ "typescript": "7.1.0-dev.20261121.1",
85
+ "vite": "8.3.6"
86
+ },
87
+ "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/devtools"
88
+ }
package/src/app.ts ADDED
@@ -0,0 +1,105 @@
1
+ // App-side devtools channel: declares a channel on the app's dev socket so
2
+ // the xplat dev hub routes its frames to the target's backend and connected
3
+ // devtools panels. Inert outside `xplat dev` — the Vite fallback bridge has
4
+ // no channels and reports 'unavailable'.
5
+
6
+ import {
7
+ registerDevChannel,
8
+ type ChannelErrorCode,
9
+ type DevChannelState,
10
+ type DevChannelRegistration,
11
+ } from '@octane-xplat/platform/dev-actions'
12
+
13
+ export type { ChannelErrorCode, DevChannelState }
14
+
15
+ /** One routed channel message delivered to the app. */
16
+ export interface DevChannelMessage<In> {
17
+ from: 'backend' | 'panel'
18
+ panel?: string
19
+ data: In
20
+ }
21
+
22
+ /** A routing failure the hub bounced back to this channel's sender. */
23
+ export interface DevChannelFailure {
24
+ code: ChannelErrorCode
25
+ detail: string
26
+ }
27
+
28
+ /** An app-side devtools channel. @internal */
29
+ export interface DevChannel<In, Out> {
30
+ readonly state: DevChannelState
31
+ /** False unless the app socket is live and the hub advertised 'channels'. */
32
+ send(to: 'backend' | 'panels', data: Out): boolean
33
+ subscribe(listener: (message: DevChannelMessage<In>) => void): () => void
34
+ onStateChange(listener: (state: DevChannelState) => void): () => void
35
+ onError(listener: (failure: DevChannelFailure) => void): () => void
36
+ close(): void
37
+ }
38
+
39
+ /**
40
+ * Declare a devtools channel. `id` must match /^[a-z][a-z0-9-]{0,31}$/ and
41
+ * `version` a positive int32; the pair joins the app's registry announcement.
42
+ */
43
+ export function openDevChannel<In = unknown, Out = unknown>(
44
+ id: string,
45
+ version: number,
46
+ ): DevChannel<In, Out> {
47
+ const listeners = new Set<(message: DevChannelMessage<In>) => void>()
48
+ const stateListeners = new Set<(state: DevChannelState) => void>()
49
+ const errorListeners = new Set<(failure: DevChannelFailure) => void>()
50
+ let current: DevChannelState = 'connecting'
51
+
52
+ const registration: DevChannelRegistration = registerDevChannel(id, version, {
53
+ message(frame) {
54
+ // Channel payloads are typed by the channel's own protocol; `as In` is
55
+ // the documented boundary for this module.
56
+ for (const listener of listeners) {
57
+ listener({
58
+ from: frame.from,
59
+ ...(frame.panel ? { panel: frame.panel } : {}),
60
+ data: frame.data as In,
61
+ })
62
+ }
63
+ },
64
+ state(state) {
65
+ current = state
66
+ for (const listener of stateListeners) {
67
+ listener(state)
68
+ }
69
+ },
70
+ error(failure) {
71
+ for (const listener of errorListeners) {
72
+ listener(failure)
73
+ }
74
+ },
75
+ })
76
+
77
+ let closed = false
78
+
79
+ return {
80
+ get state() {
81
+ return current
82
+ },
83
+ send(to, data) {
84
+ return !closed && registration.send(to, data)
85
+ },
86
+ subscribe(listener) {
87
+ listeners.add(listener)
88
+ return () => listeners.delete(listener)
89
+ },
90
+ onStateChange(listener) {
91
+ stateListeners.add(listener)
92
+ return () => stateListeners.delete(listener)
93
+ },
94
+ onError(listener) {
95
+ errorListeners.add(listener)
96
+ return () => errorListeners.delete(listener)
97
+ },
98
+ close() {
99
+ if (!closed) {
100
+ closed = true
101
+ registration.dispose()
102
+ }
103
+ },
104
+ }
105
+ }
@@ -0,0 +1,2 @@
1
+ /** Stylesheet imports are handled by the platform build presets. */
2
+ declare module '*.css' {}