@camerontaylor/paseo-client 0.8.0-fork.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 +44 -0
- package/dist/compat/normalize-provider-models.d.ts +11 -0
- package/dist/compat/normalize-provider-models.js +51 -0
- package/dist/connection/index.d.ts +42 -0
- package/dist/connection/index.js +111 -0
- package/dist/creation/index.d.ts +47 -0
- package/dist/creation/index.js +216 -0
- package/dist/daemon-client-relay-e2ee-transport.d.ts +8 -0
- package/dist/daemon-client-relay-e2ee-transport.js +161 -0
- package/dist/daemon-client-runtime-metrics.d.ts +39 -0
- package/dist/daemon-client-runtime-metrics.js +173 -0
- package/dist/daemon-client-transport-types.d.ts +36 -0
- package/dist/daemon-client-transport-types.js +2 -0
- package/dist/daemon-client-transport-utils.d.ts +13 -0
- package/dist/daemon-client-transport-utils.js +123 -0
- package/dist/daemon-client-transport.d.ts +5 -0
- package/dist/daemon-client-transport.js +4 -0
- package/dist/daemon-client-websocket-transport.d.ts +12 -0
- package/dist/daemon-client-websocket-transport.js +140 -0
- package/dist/daemon-client.d.ts +1245 -0
- package/dist/daemon-client.js +4783 -0
- package/dist/index.d.ts +383 -0
- package/dist/index.js +407 -0
- package/dist/provider-snapshots/index.d.ts +23 -0
- package/dist/provider-snapshots/index.js +60 -0
- package/dist/terminal-stream-router.d.ts +28 -0
- package/dist/terminal-stream-router.js +109 -0
- package/dist/terminals/index.d.ts +69 -0
- package/dist/terminals/index.js +103 -0
- package/package.json +51 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { extractRelayMessage } from "./daemon-client-transport-utils.js";
|
|
2
|
+
function getGlobalWebSocket() {
|
|
3
|
+
const globalWs = globalThis.WebSocket;
|
|
4
|
+
if (!globalWs) {
|
|
5
|
+
throw new Error("WebSocket is not available in this runtime");
|
|
6
|
+
}
|
|
7
|
+
return globalWs;
|
|
8
|
+
}
|
|
9
|
+
export function defaultWebSocketFactory(url, options) {
|
|
10
|
+
const globalWs = getGlobalWebSocket();
|
|
11
|
+
if (options?.protocols === undefined) {
|
|
12
|
+
return new globalWs(url);
|
|
13
|
+
}
|
|
14
|
+
return new globalWs(url, options.protocols);
|
|
15
|
+
}
|
|
16
|
+
// React Native and Node-compatible WebSocket implementations accept this extra options object.
|
|
17
|
+
// Keep it out of the standard browser factory above.
|
|
18
|
+
export function nativeWebSocketFactory(url, options) {
|
|
19
|
+
return new (getGlobalWebSocket())(url, options?.protocols, { headers: options?.headers });
|
|
20
|
+
}
|
|
21
|
+
export function createWebSocketTransportFactory(factory) {
|
|
22
|
+
return ({ url, headers, protocols }) => {
|
|
23
|
+
const ws = factory(url, { headers, protocols });
|
|
24
|
+
if ("binaryType" in ws) {
|
|
25
|
+
try {
|
|
26
|
+
ws.binaryType = "arraybuffer";
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// no-op
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
send: (data) => {
|
|
34
|
+
if (typeof ws.readyState === "number" && ws.readyState !== 1) {
|
|
35
|
+
throw new Error(`WebSocket not open (readyState=${ws.readyState})`);
|
|
36
|
+
}
|
|
37
|
+
ws.send(data);
|
|
38
|
+
},
|
|
39
|
+
close: (code, reason) => {
|
|
40
|
+
// Node's `ws` may emit an `error` when a connecting socket is closed before the
|
|
41
|
+
// handshake completes. Keep a temporary no-op handler attached so cleanup during
|
|
42
|
+
// connect timeouts does not crash the CLI with an unhandled error event.
|
|
43
|
+
const suppressEarlyCloseError = bindTemporaryEarlyCloseErrorHandler(ws);
|
|
44
|
+
try {
|
|
45
|
+
ws.close(code, reason);
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
if (typeof ws.on !== "function" && typeof ws.addEventListener !== "function") {
|
|
49
|
+
suppressEarlyCloseError();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
onOpen: (handler) => bindWsHandler(ws, "open", handler),
|
|
54
|
+
onClose: (handler) => bindWsHandler(ws, "close", handler),
|
|
55
|
+
onError: (handler) => bindWsHandler(ws, "error", handler),
|
|
56
|
+
onMessage: (handler) => bindWsMessageHandler(ws, handler),
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function bindWsMessageHandler(ws, handler) {
|
|
61
|
+
const listener = (...args) => {
|
|
62
|
+
const message = extractRelayMessage(args[0], typeof args[1] === "boolean" ? args[1] : undefined);
|
|
63
|
+
handler(message.data, message.isBinary);
|
|
64
|
+
};
|
|
65
|
+
return bindWsHandler(ws, "message", listener);
|
|
66
|
+
}
|
|
67
|
+
function bindTemporaryEarlyCloseErrorHandler(ws) {
|
|
68
|
+
const noop = () => { };
|
|
69
|
+
if (typeof ws.addEventListener === "function") {
|
|
70
|
+
ws.addEventListener("error", noop);
|
|
71
|
+
const removeOnClose = bindWsHandler(ws, "close", () => {
|
|
72
|
+
removeOnClose();
|
|
73
|
+
if (typeof ws.removeEventListener === "function") {
|
|
74
|
+
ws.removeEventListener("error", noop);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return () => {
|
|
78
|
+
removeOnClose();
|
|
79
|
+
if (typeof ws.removeEventListener === "function") {
|
|
80
|
+
ws.removeEventListener("error", noop);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (typeof ws.on === "function") {
|
|
85
|
+
ws.on("error", noop);
|
|
86
|
+
const removeOnClose = bindWsHandler(ws, "close", () => {
|
|
87
|
+
removeOnClose();
|
|
88
|
+
if (typeof ws.off === "function") {
|
|
89
|
+
ws.off("error", noop);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (typeof ws.removeListener === "function") {
|
|
93
|
+
ws.removeListener("error", noop);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return () => {
|
|
97
|
+
removeOnClose();
|
|
98
|
+
if (typeof ws.off === "function") {
|
|
99
|
+
ws.off("error", noop);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (typeof ws.removeListener === "function") {
|
|
103
|
+
ws.removeListener("error", noop);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return () => { };
|
|
108
|
+
}
|
|
109
|
+
export function bindWsHandler(ws, event, handler) {
|
|
110
|
+
if (typeof ws.addEventListener === "function") {
|
|
111
|
+
ws.addEventListener(event, handler);
|
|
112
|
+
return () => {
|
|
113
|
+
if (typeof ws.removeEventListener === "function") {
|
|
114
|
+
ws.removeEventListener(event, handler);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (typeof ws.on === "function") {
|
|
119
|
+
ws.on(event, handler);
|
|
120
|
+
return () => {
|
|
121
|
+
if (typeof ws.off === "function") {
|
|
122
|
+
ws.off(event, handler);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (typeof ws.removeListener === "function") {
|
|
126
|
+
ws.removeListener(event, handler);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const prop = `on${event}`;
|
|
131
|
+
const wsRecord = ws;
|
|
132
|
+
const previous = wsRecord[prop];
|
|
133
|
+
wsRecord[prop] = handler;
|
|
134
|
+
return () => {
|
|
135
|
+
if (wsRecord[prop] === handler) {
|
|
136
|
+
wsRecord[prop] = previous ?? null;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=daemon-client-websocket-transport.js.map
|