@octane-xplat/devtools 0.0.0-nightly.g1b95ef7 → 0.0.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/README.md +1 -3
- package/package.json +9 -86
- package/dist/app.d.ts +0 -28
- package/dist/app.js +0 -66
- package/dist/backend.d.ts +0 -31
- package/dist/backend.js +0 -182
- package/dist/client.d.ts +0 -49
- package/dist/client.js +0 -168
- package/dist/host/desktop.d.ts +0 -15
- package/dist/host/desktop.js +0 -133
- package/dist/host/panels.d.ts +0 -14
- package/dist/host/panels.js +0 -156
- package/dist/host/records.d.ts +0 -5
- package/dist/host/records.js +0 -46
- package/dist/host/server.d.ts +0 -8
- package/dist/host/server.js +0 -67
- package/dist/host/web.d.ts +0 -5
- package/dist/host/web.js +0 -74
- package/dist/macos/index.macos.d.ts +0 -3
- package/dist/macos/index.macos.js +0 -5
- package/dist/macos/servers.macos.d.ts +0 -4
- package/dist/macos/servers.macos.js +0 -57
- package/dist/macos/socket.macos.d.ts +0 -2
- package/dist/macos/socket.macos.js +0 -152
- package/dist/macos/ws-frames.d.ts +0 -24
- package/dist/macos/ws-frames.js +0 -205
- package/dist/node.d.ts +0 -12
- package/dist/node.js +0 -51
- package/dist/record.d.ts +0 -9
- package/dist/record.js +0 -38
- package/dist/types.d.ts +0 -128
- package/dist/types.js +0 -25
- package/src/app.ts +0 -105
- package/src/assets.d.ts +0 -2
- package/src/backend.ts +0 -278
- package/src/client.ts +0 -248
- package/src/desktop/Shell.macos.tsrx +0 -158
- package/src/desktop/Shell.ts +0 -16
- package/src/desktop/index.macos.ts +0 -7
- package/src/desktop/main.macos.ts +0 -130
- package/src/desktop/panels.d.ts +0 -10
- package/src/desktop/target.ts +0 -34
- package/src/host/desktop.ts +0 -176
- package/src/host/panels.ts +0 -193
- package/src/host/records.ts +0 -62
- package/src/host/server.ts +0 -92
- package/src/host/web.ts +0 -68
- package/src/macos/index.macos.ts +0 -7
- package/src/macos/servers.macos.ts +0 -83
- package/src/macos/socket.macos.ts +0 -218
- package/src/macos/ws-frames.ts +0 -249
- package/src/node.ts +0 -60
- package/src/panel/App.tsrx +0 -288
- package/src/panel/index.html +0 -12
- package/src/panel/index.ts +0 -24
- package/src/panel/main.tsrx +0 -2
- package/src/panel/main.web.tsrx +0 -89
- package/src/panel/model.ts +0 -216
- package/src/panel/panel.css +0 -189
- package/src/panel/plugin.ts +0 -65
- package/src/panel/styles.ts +0 -5
- package/src/panel/tsconfig.browser.json +0 -9
- package/src/record.ts +0 -66
- package/src/types.ts +0 -129
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
// DevSocket over Network.framework (NWConnection). The JSC host has no
|
|
2
|
-
// WebSocket, and NSURLSessionWebSocketTask is unreachable through the bundled
|
|
3
|
-
// node-api metadata — webSocketTaskWithURL returns an object whose prototype is
|
|
4
|
-
// plain NSURLSessionTask (no ws selectors). C functions are bridged, so the
|
|
5
|
-
// connection is opened by hand and frames are codec'd by ./ws-frames.ts.
|
|
6
|
-
// Local ws:// only — no TLS.
|
|
7
|
-
import { interop, NSData, NSOperationQueue } from '@octane-xplat/platform/macos';
|
|
8
|
-
import { _nw_content_context_default_message, _nw_parameters_configure_protocol_default_configuration, _nw_parameters_configure_protocol_disable, dispatch_data_create, dispatch_queue_create, nw_connection_cancel, nw_connection_create, nw_connection_receive, nw_connection_send, nw_connection_set_queue, nw_connection_set_state_changed_handler, nw_connection_start, nw_endpoint_create_host, nw_parameters_create_secure_tcp, } from '@octane-xplat/platform/macos';
|
|
9
|
-
import { encodeFrame, FrameDecoder, handshakeAccept, handshakeRequest, utf8Encode, } from './ws-frames.js';
|
|
10
|
-
export function nwDevSocket(url) {
|
|
11
|
-
const m = /^ws:\/\/([^:/]+):(\d+)(\/.*)$/.exec(url);
|
|
12
|
-
if (!m) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
const [, host, port, path] = m;
|
|
16
|
-
const queue = NSOperationQueue.mainQueue.underlyingQueue ??
|
|
17
|
-
dispatch_queue_create('devtools.ws', null);
|
|
18
|
-
const sendQueue = dispatch_queue_create('devtools.ws.send', null);
|
|
19
|
-
const endpoint = nw_endpoint_create_host(host, port);
|
|
20
|
-
const params = nw_parameters_create_secure_tcp(
|
|
21
|
-
// _disable as the TLS configure block → plain TCP.
|
|
22
|
-
_nw_parameters_configure_protocol_disable, _nw_parameters_configure_protocol_default_configuration);
|
|
23
|
-
const conn = nw_connection_create(endpoint, params);
|
|
24
|
-
let closed = false;
|
|
25
|
-
let ready = false;
|
|
26
|
-
let handshaken = false;
|
|
27
|
-
const socket = {
|
|
28
|
-
get readyState() {
|
|
29
|
-
// WebSocket constants: 0 CONNECTING, 1 OPEN, 3 CLOSED (no CLOSING — the
|
|
30
|
-
// transport has no half-close state to report).
|
|
31
|
-
if (closed) {
|
|
32
|
-
return 3;
|
|
33
|
-
}
|
|
34
|
-
return ready ? 1 : 0;
|
|
35
|
-
},
|
|
36
|
-
onopen: null,
|
|
37
|
-
onmessage: null,
|
|
38
|
-
onerror: null,
|
|
39
|
-
onclose: null,
|
|
40
|
-
send: () => { },
|
|
41
|
-
close: () => { },
|
|
42
|
-
};
|
|
43
|
-
const decoder = new FrameDecoder();
|
|
44
|
-
const fail = () => {
|
|
45
|
-
if (closed) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
closed = true;
|
|
49
|
-
socket.onerror?.();
|
|
50
|
-
socket.onclose?.({ code: 1006, reason: '' });
|
|
51
|
-
};
|
|
52
|
-
// dispatch_data_t toll-free bridges with NSData.
|
|
53
|
-
function sendBytes(bytes) {
|
|
54
|
-
const data = NSData.dataWithBytesLength(bytes, bytes.length);
|
|
55
|
-
const d = dispatch_data_create(data.bytes, bytes.length, sendQueue, () => { });
|
|
56
|
-
nw_connection_send(conn, d, _nw_content_context_default_message, false, (error) => {
|
|
57
|
-
if (error) {
|
|
58
|
-
fail();
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
socket.send = (data) => {
|
|
63
|
-
if (!ready || closed) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
sendBytes(encodeFrame(1, utf8Encode(data)));
|
|
67
|
-
};
|
|
68
|
-
socket.close = () => {
|
|
69
|
-
if (closed) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
closed = true;
|
|
73
|
-
try {
|
|
74
|
-
sendBytes(encodeFrame(8, new Uint8Array(0)));
|
|
75
|
-
}
|
|
76
|
-
catch { }
|
|
77
|
-
nw_connection_cancel(conn);
|
|
78
|
-
socket.onclose?.({ code: 1000, reason: '' });
|
|
79
|
-
};
|
|
80
|
-
function pump() {
|
|
81
|
-
nw_connection_receive(conn, 1, 1 << 20, (data, _ctx, _complete, error) => {
|
|
82
|
-
if (error || closed) {
|
|
83
|
-
if (!closed) {
|
|
84
|
-
fail();
|
|
85
|
-
}
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
try {
|
|
89
|
-
if (data) {
|
|
90
|
-
if (!handshaken) {
|
|
91
|
-
handshakeBuffer = concat(handshakeBuffer, new Uint8Array(interop.bufferFromData(data)));
|
|
92
|
-
const end = handshakeAccept(handshakeBuffer);
|
|
93
|
-
if (end >= 0) {
|
|
94
|
-
handshaken = true;
|
|
95
|
-
ready = true;
|
|
96
|
-
socket.onopen?.();
|
|
97
|
-
for (const ev of decoder.push(handshakeBuffer.subarray(end))) {
|
|
98
|
-
deliver(ev);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
for (const ev of decoder.push(new Uint8Array(interop.bufferFromData(data)))) {
|
|
104
|
-
deliver(ev);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
console.error('[devtools socket]', e);
|
|
111
|
-
fail();
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (!closed) {
|
|
115
|
-
pump();
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
let handshakeBuffer = new Uint8Array(0);
|
|
120
|
-
function concat(a, b) {
|
|
121
|
-
const out = new Uint8Array(a.length + b.length);
|
|
122
|
-
out.set(a, 0);
|
|
123
|
-
out.set(b, a.length);
|
|
124
|
-
return out;
|
|
125
|
-
}
|
|
126
|
-
function deliver(ev) {
|
|
127
|
-
if (ev.type === 'text') {
|
|
128
|
-
socket.onmessage?.({ data: ev.data });
|
|
129
|
-
}
|
|
130
|
-
else if (ev.type === 'close') {
|
|
131
|
-
closed = true;
|
|
132
|
-
nw_connection_cancel(conn);
|
|
133
|
-
socket.onclose?.({ code: 1000, reason: '' });
|
|
134
|
-
}
|
|
135
|
-
else if (ev.type === 'ping') {
|
|
136
|
-
sendBytes(encodeFrame(10, ev.payload));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
nw_connection_set_state_changed_handler(conn, (state, error) => {
|
|
140
|
-
// nw_connection_state_ready = 3
|
|
141
|
-
if (state === 3 && !handshaken) {
|
|
142
|
-
sendBytes(handshakeRequest(host, port, path));
|
|
143
|
-
}
|
|
144
|
-
else if (state === 4 || state === 5 || error) {
|
|
145
|
-
fail();
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
nw_connection_set_queue(conn, queue);
|
|
149
|
-
nw_connection_start(conn);
|
|
150
|
-
pump();
|
|
151
|
-
return socket;
|
|
152
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare function utf8Encode(s: string): Uint8Array;
|
|
2
|
-
export declare function utf8Decode(bytes: Uint8Array): string;
|
|
3
|
-
export declare function base64Encode(bytes: Uint8Array): string;
|
|
4
|
-
export declare function handshakeRequest(host: string, port: string, path: string): Uint8Array;
|
|
5
|
-
export declare function handshakeAccept(buffer: Uint8Array): number;
|
|
6
|
-
export type FrameEvent = {
|
|
7
|
-
type: 'text';
|
|
8
|
-
data: string;
|
|
9
|
-
} | {
|
|
10
|
-
type: 'close';
|
|
11
|
-
} | {
|
|
12
|
-
type: 'ping';
|
|
13
|
-
payload: Uint8Array;
|
|
14
|
-
} | {
|
|
15
|
-
type: 'pong';
|
|
16
|
-
payload: Uint8Array;
|
|
17
|
-
};
|
|
18
|
-
export declare function encodeFrame(opcode: number, payload: Uint8Array, maskKey?: Uint8Array): Uint8Array;
|
|
19
|
-
export declare class FrameDecoder {
|
|
20
|
-
private buffer;
|
|
21
|
-
private fragments;
|
|
22
|
-
private fragmentOpcode;
|
|
23
|
-
push(chunk: Uint8Array): FrameEvent[];
|
|
24
|
-
}
|
package/dist/macos/ws-frames.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/record.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|