@getmateo/client 0.0.0-stage → 0.17.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.
Files changed (51) hide show
  1. package/LICENSE +211 -0
  2. package/README.md +43 -2
  3. package/dist/compat/normalize-provider-models.d.ts +11 -0
  4. package/dist/compat/normalize-provider-models.js +51 -0
  5. package/dist/connection/index.d.ts +51 -0
  6. package/dist/connection/index.js +113 -0
  7. package/dist/connection/legacy-workspaces.d.ts +19 -0
  8. package/dist/connection/legacy-workspaces.js +161 -0
  9. package/dist/connection/legacy.d.ts +31 -0
  10. package/dist/connection/legacy.js +245 -0
  11. package/dist/connection/owned.d.ts +36 -0
  12. package/dist/connection/owned.js +210 -0
  13. package/dist/creation/index.d.ts +40 -0
  14. package/dist/creation/index.js +197 -0
  15. package/dist/daemon-client-relay-e2ee-transport.d.ts +10 -0
  16. package/dist/daemon-client-relay-e2ee-transport.js +190 -0
  17. package/dist/daemon-client-runtime-metrics.d.ts +39 -0
  18. package/dist/daemon-client-runtime-metrics.js +173 -0
  19. package/dist/daemon-client-transport-types.d.ts +43 -0
  20. package/dist/daemon-client-transport-types.js +2 -0
  21. package/dist/daemon-client-transport-utils.d.ts +14 -0
  22. package/dist/daemon-client-transport-utils.js +127 -0
  23. package/dist/daemon-client-transport.d.ts +5 -0
  24. package/dist/daemon-client-transport.js +4 -0
  25. package/dist/daemon-client-websocket-transport.d.ts +15 -0
  26. package/dist/daemon-client-websocket-transport.js +183 -0
  27. package/dist/daemon-client.d.ts +1507 -0
  28. package/dist/daemon-client.js +5465 -0
  29. package/dist/fleet/index.d.ts +29 -0
  30. package/dist/fleet/index.js +81 -0
  31. package/dist/hosts/index.d.ts +16 -0
  32. package/dist/hosts/index.js +201 -0
  33. package/dist/index.d.ts +430 -0
  34. package/dist/index.js +583 -0
  35. package/dist/legacy-usage-icons.d.ts +2 -0
  36. package/dist/legacy-usage-icons.js +16 -0
  37. package/dist/node/buffering.d.ts +10 -0
  38. package/dist/node/buffering.js +28 -0
  39. package/dist/node/index.d.ts +17 -0
  40. package/dist/node/index.js +191 -0
  41. package/dist/node/ssh-tunnel.d.ts +9 -0
  42. package/dist/node/ssh-tunnel.js +81 -0
  43. package/dist/provider-snapshots/index.d.ts +21 -0
  44. package/dist/provider-snapshots/index.js +56 -0
  45. package/dist/terminal-stream-router.d.ts +25 -0
  46. package/dist/terminal-stream-router.js +62 -0
  47. package/dist/terminals/index.d.ts +80 -0
  48. package/dist/terminals/index.js +120 -0
  49. package/dist/timeline-subscription/index.d.ts +25 -0
  50. package/dist/timeline-subscription/index.js +56 -0
  51. package/package.json +59 -4
@@ -0,0 +1,127 @@
1
+ export function copyArrayBufferViewToBuffer(data) {
2
+ const view = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
3
+ const out = new Uint8Array(view.byteLength);
4
+ out.set(view);
5
+ return out.buffer;
6
+ }
7
+ export function normalizeTransportPayload(data) {
8
+ if (typeof data === "string" || data instanceof ArrayBuffer) {
9
+ return data;
10
+ }
11
+ return copyArrayBufferViewToBuffer(data);
12
+ }
13
+ export function extractRelayMessage(event, nodeIsBinary) {
14
+ const raw = event && typeof event === "object" && "data" in event
15
+ ? event.data
16
+ : event;
17
+ const isBinary = nodeIsBinary ?? typeof raw !== "string";
18
+ if (!isBinary) {
19
+ return { data: decodeMessageData(raw) ?? String(raw ?? ""), isBinary: false };
20
+ }
21
+ if (raw instanceof ArrayBuffer)
22
+ return { data: raw, isBinary: true };
23
+ if (ArrayBuffer.isView(raw)) {
24
+ return { data: copyArrayBufferViewToBuffer(raw), isBinary: true };
25
+ }
26
+ return { data: String(raw ?? ""), isBinary: true };
27
+ }
28
+ export function describeTransportClose(event) {
29
+ if (!event) {
30
+ return "Transport closed";
31
+ }
32
+ if (event instanceof Error) {
33
+ return event.message;
34
+ }
35
+ if (typeof event === "string") {
36
+ return event;
37
+ }
38
+ if (typeof event === "object") {
39
+ const record = event;
40
+ if (typeof record.reason === "string" && record.reason.trim().length > 0) {
41
+ return record.reason.trim();
42
+ }
43
+ if (typeof record.message === "string" && record.message.trim().length > 0) {
44
+ return record.message.trim();
45
+ }
46
+ if (typeof record.code === "number") {
47
+ return `Transport closed (code ${record.code})`;
48
+ }
49
+ }
50
+ return "Transport closed";
51
+ }
52
+ export function describeTransportError(event) {
53
+ if (!event) {
54
+ return "Transport error";
55
+ }
56
+ if (event instanceof Error) {
57
+ return event.message;
58
+ }
59
+ if (typeof event === "string") {
60
+ return event;
61
+ }
62
+ if (typeof event === "object") {
63
+ const record = event;
64
+ if (typeof record.message === "string" && record.message.trim().length > 0) {
65
+ return record.message.trim();
66
+ }
67
+ }
68
+ return "Transport error";
69
+ }
70
+ export function safeRandomId() {
71
+ try {
72
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
73
+ return crypto.randomUUID();
74
+ }
75
+ }
76
+ catch {
77
+ // ignore
78
+ }
79
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
80
+ }
81
+ export function decodeMessageData(data) {
82
+ if (data === null || data === undefined) {
83
+ return null;
84
+ }
85
+ if (typeof data === "string") {
86
+ return data;
87
+ }
88
+ if (typeof ArrayBuffer !== "undefined" && data instanceof ArrayBuffer) {
89
+ if (typeof Buffer !== "undefined") {
90
+ return Buffer.from(data).toString("utf8");
91
+ }
92
+ if (typeof TextDecoder !== "undefined") {
93
+ return new TextDecoder().decode(data);
94
+ }
95
+ }
96
+ if (ArrayBuffer.isView(data)) {
97
+ const view = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
98
+ if (typeof Buffer !== "undefined") {
99
+ return Buffer.from(view).toString("utf8");
100
+ }
101
+ if (typeof TextDecoder !== "undefined") {
102
+ return new TextDecoder().decode(view);
103
+ }
104
+ }
105
+ if (typeof data.toString === "function") {
106
+ return data.toString();
107
+ }
108
+ return null;
109
+ }
110
+ export function encodeUtf8String(value) {
111
+ if (typeof TextEncoder !== "undefined") {
112
+ return new TextEncoder().encode(value);
113
+ }
114
+ if (typeof Buffer !== "undefined") {
115
+ return new Uint8Array(Buffer.from(value, "utf8"));
116
+ }
117
+ const out = new Uint8Array(value.length);
118
+ for (let i = 0; i < value.length; i++) {
119
+ out[i] = value.charCodeAt(i) & 0xff;
120
+ }
121
+ return out;
122
+ }
123
+ export function messageTooLargeError(size, limit) {
124
+ const toMiB = (bytes) => (bytes / (1024 * 1024)).toFixed(1);
125
+ return new Error(`Message is too large to send (${toMiB(size)} MiB). The limit is ${toMiB(limit)} MiB, so send fewer or smaller attachments.`);
126
+ }
127
+ //# sourceMappingURL=daemon-client-transport-utils.js.map
@@ -0,0 +1,5 @@
1
+ export type { DaemonTransport, DaemonTransportFactory, TransportLogger, WebSocketFactory, WebSocketLike, } from "./daemon-client-transport-types.js";
2
+ export { decodeMessageData, describeTransportClose, describeTransportError, encodeUtf8String, extractRelayMessage, normalizeTransportPayload, safeRandomId, } from "./daemon-client-transport-utils.js";
3
+ export { createEncryptedTransport, createRelayE2eeTransportFactory, createRelayTransportFactory, } from "./daemon-client-relay-e2ee-transport.js";
4
+ export { bindWsHandler, createWebSocketTransportFactory, defaultWebSocketFactory, } from "./daemon-client-websocket-transport.js";
5
+ //# sourceMappingURL=daemon-client-transport.d.ts.map
@@ -0,0 +1,4 @@
1
+ export { decodeMessageData, describeTransportClose, describeTransportError, encodeUtf8String, extractRelayMessage, normalizeTransportPayload, safeRandomId, } from "./daemon-client-transport-utils.js";
2
+ export { createEncryptedTransport, createRelayE2eeTransportFactory, createRelayTransportFactory, } from "./daemon-client-relay-e2ee-transport.js";
3
+ export { bindWsHandler, createWebSocketTransportFactory, defaultWebSocketFactory, } from "./daemon-client-websocket-transport.js";
4
+ //# sourceMappingURL=daemon-client-transport.js.map
@@ -0,0 +1,15 @@
1
+ import type { DaemonTransportFactory, WebSocketFactory, WebSocketLike } from "./daemon-client-transport-types.js";
2
+ export declare function defaultWebSocketFactory(url: string, options?: {
3
+ headers?: Record<string, string>;
4
+ protocols?: string[];
5
+ }): WebSocketLike;
6
+ export declare function nativeWebSocketFactory(url: string, options?: {
7
+ headers?: Record<string, string>;
8
+ protocols?: string[];
9
+ }): WebSocketLike;
10
+ export declare namespace nativeWebSocketFactory {
11
+ var supportsDrain: boolean;
12
+ }
13
+ export declare function createWebSocketTransportFactory(factory: WebSocketFactory): DaemonTransportFactory;
14
+ export declare function bindWsHandler(ws: WebSocketLike, event: "open" | "close" | "error" | "message", handler: (...args: unknown[]) => void): () => void;
15
+ //# sourceMappingURL=daemon-client-websocket-transport.d.ts.map
@@ -0,0 +1,183 @@
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
+ // React Native leaves bufferedAmount at zero, including while native output is queued.
22
+ nativeWebSocketFactory.supportsDrain = false;
23
+ export function createWebSocketTransportFactory(factory) {
24
+ return ({ url, headers, protocols }) => {
25
+ const ws = factory(url, { headers, protocols });
26
+ if ("binaryType" in ws) {
27
+ try {
28
+ ws.binaryType = "arraybuffer";
29
+ }
30
+ catch {
31
+ // no-op
32
+ }
33
+ }
34
+ return {
35
+ supportsDrain: factory.supportsDrain !== false,
36
+ send: (data) => {
37
+ if (typeof ws.readyState === "number" && ws.readyState !== 1) {
38
+ throw new Error(`WebSocket not open (readyState=${ws.readyState})`);
39
+ }
40
+ ws.send(data);
41
+ if ((ws.bufferedAmount ?? 0) > 1024 * 1024) {
42
+ return new Promise((resolve, reject) => {
43
+ const drain = () => {
44
+ if (ws.readyState !== 1) {
45
+ reject(new Error("WebSocket closed while draining"));
46
+ return;
47
+ }
48
+ if ((ws.bufferedAmount ?? 0) <= 1024 * 1024) {
49
+ resolve();
50
+ return;
51
+ }
52
+ setTimeout(drain, 10);
53
+ };
54
+ drain();
55
+ });
56
+ }
57
+ },
58
+ close: (code, reason) => {
59
+ // Node's `ws` may emit an `error` when a connecting socket is closed before the
60
+ // handshake completes. Keep a temporary no-op handler attached so cleanup during
61
+ // connect timeouts does not crash the CLI with an unhandled error event.
62
+ const suppressEarlyCloseError = bindTemporaryEarlyCloseErrorHandler(ws);
63
+ try {
64
+ ws.close(toSendableCloseCode(code), toSendableCloseReason(reason));
65
+ }
66
+ finally {
67
+ if (typeof ws.on !== "function" && typeof ws.addEventListener !== "function") {
68
+ suppressEarlyCloseError();
69
+ }
70
+ }
71
+ },
72
+ onOpen: (handler) => bindWsHandler(ws, "open", handler),
73
+ onClose: (handler) => bindWsHandler(ws, "close", handler),
74
+ onError: (handler) => bindWsHandler(ws, "error", handler),
75
+ onMessage: (handler) => bindWsMessageHandler(ws, handler),
76
+ };
77
+ };
78
+ }
79
+ // WHATWG sockets reject other codes and reasons exceeding 123 UTF-8 bytes,
80
+ // leaving abandoned connections open. Node's ws accepts more than browsers do.
81
+ const MAX_CLOSE_REASON_BYTES = 123;
82
+ function toSendableCloseCode(code) {
83
+ if (code === 1000 || (code !== undefined && code >= 3000 && code <= 4999))
84
+ return code;
85
+ return 1000;
86
+ }
87
+ function toSendableCloseReason(reason) {
88
+ if (reason === undefined)
89
+ return undefined;
90
+ const encoder = new TextEncoder();
91
+ if (encoder.encode(reason).byteLength <= MAX_CLOSE_REASON_BYTES)
92
+ return reason;
93
+ let truncated = "";
94
+ let bytes = 0;
95
+ for (const character of reason) {
96
+ bytes += encoder.encode(character).byteLength;
97
+ if (bytes > MAX_CLOSE_REASON_BYTES)
98
+ break;
99
+ truncated += character;
100
+ }
101
+ return truncated;
102
+ }
103
+ function bindWsMessageHandler(ws, handler) {
104
+ const listener = (...args) => {
105
+ const message = extractRelayMessage(args[0], typeof args[1] === "boolean" ? args[1] : undefined);
106
+ handler(message.data, message.isBinary);
107
+ };
108
+ return bindWsHandler(ws, "message", listener);
109
+ }
110
+ function bindTemporaryEarlyCloseErrorHandler(ws) {
111
+ const noop = () => { };
112
+ if (typeof ws.addEventListener === "function") {
113
+ ws.addEventListener("error", noop);
114
+ const removeOnClose = bindWsHandler(ws, "close", () => {
115
+ removeOnClose();
116
+ if (typeof ws.removeEventListener === "function") {
117
+ ws.removeEventListener("error", noop);
118
+ }
119
+ });
120
+ return () => {
121
+ removeOnClose();
122
+ if (typeof ws.removeEventListener === "function") {
123
+ ws.removeEventListener("error", noop);
124
+ }
125
+ };
126
+ }
127
+ if (typeof ws.on === "function") {
128
+ ws.on("error", noop);
129
+ const removeOnClose = bindWsHandler(ws, "close", () => {
130
+ removeOnClose();
131
+ if (typeof ws.off === "function") {
132
+ ws.off("error", noop);
133
+ return;
134
+ }
135
+ if (typeof ws.removeListener === "function") {
136
+ ws.removeListener("error", noop);
137
+ }
138
+ });
139
+ return () => {
140
+ removeOnClose();
141
+ if (typeof ws.off === "function") {
142
+ ws.off("error", noop);
143
+ return;
144
+ }
145
+ if (typeof ws.removeListener === "function") {
146
+ ws.removeListener("error", noop);
147
+ }
148
+ };
149
+ }
150
+ return () => { };
151
+ }
152
+ export function bindWsHandler(ws, event, handler) {
153
+ if (typeof ws.addEventListener === "function") {
154
+ ws.addEventListener(event, handler);
155
+ return () => {
156
+ if (typeof ws.removeEventListener === "function") {
157
+ ws.removeEventListener(event, handler);
158
+ }
159
+ };
160
+ }
161
+ if (typeof ws.on === "function") {
162
+ ws.on(event, handler);
163
+ return () => {
164
+ if (typeof ws.off === "function") {
165
+ ws.off(event, handler);
166
+ return;
167
+ }
168
+ if (typeof ws.removeListener === "function") {
169
+ ws.removeListener(event, handler);
170
+ }
171
+ };
172
+ }
173
+ const prop = `on${event}`;
174
+ const wsRecord = ws;
175
+ const previous = wsRecord[prop];
176
+ wsRecord[prop] = handler;
177
+ return () => {
178
+ if (wsRecord[prop] === handler) {
179
+ wsRecord[prop] = previous ?? null;
180
+ }
181
+ };
182
+ }
183
+ //# sourceMappingURL=daemon-client-websocket-transport.js.map