@mearl/cloud-connector 3.0.0-beta.0 → 3.0.0-beta.10
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 +79 -105
- package/README.zh-CN.md +178 -0
- package/dist/chunks/chunk-UWYEHBQ7.js +379 -0
- package/dist/cli.js +5 -5
- package/dist/contracts.d.ts +2 -0
- package/dist/contracts.js +0 -0
- package/dist/endpoint.d.ts +6 -14
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -15
- package/dist/plugins.d.ts +17 -0
- package/package.json +16 -8
- package/dist/chunks/chunk-5I7OGE7L.js +0 -1000
- package/dist/qoder-auth.d.ts +0 -12
- package/dist/qoder.d.ts +0 -108
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import WebSocket from "ws";
|
|
3
|
+
import {
|
|
4
|
+
isHeartbeatMessage,
|
|
5
|
+
MAX_BUFFER_SIZE,
|
|
6
|
+
DEFAULT_HEARTBEAT_INTERVAL
|
|
7
|
+
} from "@mearl/cloud-types";
|
|
8
|
+
import { resolveActionTimeoutSec } from "@mearl/client/action-timeouts";
|
|
9
|
+
|
|
10
|
+
// src/identity.ts
|
|
11
|
+
import { hostname } from "node:os";
|
|
12
|
+
import { randomUUID } from "node:crypto";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { DAEMON_HOME, readRecord, writeRecord } from "@mearl/daemon-core";
|
|
15
|
+
var IDENTITY_FILE = join(DAEMON_HOME, "cloud-connector-identity.json");
|
|
16
|
+
function resolveConnectorIdentity(options) {
|
|
17
|
+
const explicitId = options.connectorId?.trim() || process.env.MEARL_CONNECTOR_ID?.trim();
|
|
18
|
+
const explicitName = options.connectorName?.trim() || process.env.MEARL_CONNECTOR_NAME?.trim();
|
|
19
|
+
const stored = readRecord(IDENTITY_FILE);
|
|
20
|
+
const connectorId = explicitId || stored?.connectorId || randomUUID();
|
|
21
|
+
if (!explicitId && !stored?.connectorId) {
|
|
22
|
+
try {
|
|
23
|
+
writeRecord(IDENTITY_FILE, { pid: process.pid, connectorId });
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const name = explicitName || hostname() || `connector-${connectorId.slice(0, 8)}`;
|
|
28
|
+
if (!/^[A-Za-z0-9._:-]{1,128}$/.test(connectorId)) {
|
|
29
|
+
throw new Error('connectorId must contain only letters, numbers, ".", "_", ":", or "-"');
|
|
30
|
+
}
|
|
31
|
+
if (name.length > 128 || new RegExp("\\p{Cc}", "u").test(name)) {
|
|
32
|
+
throw new Error("connectorName must be 1-128 characters without control characters");
|
|
33
|
+
}
|
|
34
|
+
return { connectorId, name };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/endpoint.ts
|
|
38
|
+
function parseConnectorEndpoint(value) {
|
|
39
|
+
if (!value) return null;
|
|
40
|
+
const serverUrl = value.trim();
|
|
41
|
+
try {
|
|
42
|
+
const parsed = new URL(serverUrl);
|
|
43
|
+
if (!parsed.hostname || parsed.hash || parsed.username || parsed.password) return null;
|
|
44
|
+
const scheme = parsed.protocol.slice(0, -1);
|
|
45
|
+
if (!/^[a-z][a-z0-9+-]{0,31}$/.test(scheme) || ["http", "https", "file", "data", "javascript", "chrome"].includes(scheme)) return null;
|
|
46
|
+
return { serverUrl, transportUrl: serverUrl, scheme };
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function isConnectorEndpoint(value) {
|
|
52
|
+
return parseConnectorEndpoint(value) !== null;
|
|
53
|
+
}
|
|
54
|
+
function requireConnectorEndpoint(value) {
|
|
55
|
+
const endpoint = parseConnectorEndpoint(value);
|
|
56
|
+
if (!endpoint) throw new Error("serverUrl must be a valid connector URL without credentials or a fragment");
|
|
57
|
+
return endpoint;
|
|
58
|
+
}
|
|
59
|
+
function isWebSocketEndpoint(endpoint) {
|
|
60
|
+
return endpoint.scheme === "ws" || endpoint.scheme === "wss";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/plugins.ts
|
|
64
|
+
import { capabilityDirectory } from "@mearl/daemon-core/page-runtimes";
|
|
65
|
+
import { NodeCapabilityRegistry } from "@mearl/daemon-core/capabilities";
|
|
66
|
+
async function loadConnectorPlugin(scheme, options) {
|
|
67
|
+
const hook = `cloud.connector.${scheme}`;
|
|
68
|
+
const registry = new NodeCapabilityRegistry({}, capabilityDirectory(), { hooks: [hook] });
|
|
69
|
+
await registry.refresh();
|
|
70
|
+
const create = registry.require(hook);
|
|
71
|
+
const plugin = await create({ ...options, invokeAction: async (action, payload, requestOptions) => {
|
|
72
|
+
const client = await import("@mearl/client/local");
|
|
73
|
+
return client.invoke(action, payload, { ...requestOptions, controlSource: "remote" });
|
|
74
|
+
} });
|
|
75
|
+
if (!plugin || typeof plugin.connect !== "function" || typeof plugin.disconnect !== "function") throw new Error("Invalid connector capability");
|
|
76
|
+
return plugin;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/index.ts
|
|
80
|
+
var CLOUD_CONNECTOR_VERSION = true ? "3.0.0-beta.10" : "unknown";
|
|
81
|
+
var DEFAULT_RECONNECT_INTERVAL = 5e3;
|
|
82
|
+
var BACKOFF_BASE_MS = 1e3;
|
|
83
|
+
var BACKOFF_MAX_MS = 3e4;
|
|
84
|
+
var SLOW_PROBE_INTERVAL_MS = 6e4;
|
|
85
|
+
var FAST_RECONNECT_ATTEMPTS = 5;
|
|
86
|
+
var CONNECTOR_REPLACED_REASON = "Connector replaced by a newer connection";
|
|
87
|
+
var CloudConnector = class {
|
|
88
|
+
options;
|
|
89
|
+
endpoint;
|
|
90
|
+
identity;
|
|
91
|
+
plugin = null;
|
|
92
|
+
pluginLoad;
|
|
93
|
+
ws = null;
|
|
94
|
+
heartbeatTimer = null;
|
|
95
|
+
reconnectTimer = null;
|
|
96
|
+
reconnectAttempts = 0;
|
|
97
|
+
messageBuffer = "";
|
|
98
|
+
isManualClose = false;
|
|
99
|
+
shouldTryWss = false;
|
|
100
|
+
wssRetryAttempts = 0;
|
|
101
|
+
maxWssRetryAttempts = 1;
|
|
102
|
+
hasConnected = false;
|
|
103
|
+
lastConnectionError = null;
|
|
104
|
+
constructor(options) {
|
|
105
|
+
this.endpoint = requireConnectorEndpoint(options.serverUrl);
|
|
106
|
+
this.options = {
|
|
107
|
+
serverUrl: this.endpoint.serverUrl,
|
|
108
|
+
heartbeatInterval: options.heartbeatInterval ?? DEFAULT_HEARTBEAT_INTERVAL,
|
|
109
|
+
reconnectInterval: options.reconnectInterval ?? DEFAULT_RECONNECT_INTERVAL,
|
|
110
|
+
maxReconnectAttempts: options.maxReconnectAttempts ?? -1,
|
|
111
|
+
failFast: options.failFast ?? false,
|
|
112
|
+
onInitialConnectionFailed: options.onInitialConnectionFailed,
|
|
113
|
+
onConnected: options.onConnected,
|
|
114
|
+
onStateChange: options.onStateChange,
|
|
115
|
+
onSuperseded: options.onSuperseded
|
|
116
|
+
};
|
|
117
|
+
this.identity = resolveConnectorIdentity(options);
|
|
118
|
+
}
|
|
119
|
+
connect() {
|
|
120
|
+
if (!isWebSocketEndpoint(this.endpoint)) {
|
|
121
|
+
if (this.plugin) {
|
|
122
|
+
this.plugin.connect();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.isManualClose = false;
|
|
126
|
+
if (this.pluginLoad) return;
|
|
127
|
+
this.pluginLoad = loadConnectorPlugin(this.endpoint.scheme, {
|
|
128
|
+
serverUrl: this.endpoint.serverUrl,
|
|
129
|
+
identity: this.identity,
|
|
130
|
+
reconnectInterval: this.options.reconnectInterval,
|
|
131
|
+
maxReconnectAttempts: this.options.maxReconnectAttempts,
|
|
132
|
+
failFast: this.options.failFast,
|
|
133
|
+
onConnected: () => {
|
|
134
|
+
this.hasConnected = true;
|
|
135
|
+
this.options.onConnected?.(this.options.serverUrl, this.identity);
|
|
136
|
+
},
|
|
137
|
+
onStateChange: (change) => this.emitState(change),
|
|
138
|
+
onInitialConnectionFailed: this.options.onInitialConnectionFailed
|
|
139
|
+
}).then((plugin) => {
|
|
140
|
+
if (this.isManualClose) {
|
|
141
|
+
plugin.disconnect();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
this.plugin = plugin;
|
|
145
|
+
plugin.connect();
|
|
146
|
+
}).catch((error) => {
|
|
147
|
+
if (this.isManualClose) return;
|
|
148
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
149
|
+
this.emitState({ state: "failed", reason: message });
|
|
150
|
+
this.options.onInitialConnectionFailed?.(message);
|
|
151
|
+
}).finally(() => {
|
|
152
|
+
this.pluginLoad = void 0;
|
|
153
|
+
});
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (this.ws && (this.ws.readyState === 0 || this.ws.readyState === 1)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!this.hasConnected && this.reconnectAttempts === 0) {
|
|
160
|
+
this.emitState({ state: "connecting" });
|
|
161
|
+
}
|
|
162
|
+
let serverUrl = this.endpoint.transportUrl;
|
|
163
|
+
if (this.shouldTryWss && serverUrl.startsWith("ws://")) {
|
|
164
|
+
serverUrl = serverUrl.replace("ws://", "wss://");
|
|
165
|
+
console.log(`[CloudConnector] Retrying with wss://: ${serverUrl}`);
|
|
166
|
+
}
|
|
167
|
+
this.ws = new WebSocket(serverUrl);
|
|
168
|
+
this.ws.on("open", () => {
|
|
169
|
+
this.hasConnected = true;
|
|
170
|
+
this.lastConnectionError = null;
|
|
171
|
+
this.reconnectAttempts = 0;
|
|
172
|
+
this.shouldTryWss = false;
|
|
173
|
+
this.wssRetryAttempts = 0;
|
|
174
|
+
this.sendConnectorHello();
|
|
175
|
+
this.startHeartbeat();
|
|
176
|
+
this.emitState({ state: "connected" });
|
|
177
|
+
this.options.onConnected?.(this.options.serverUrl, this.identity);
|
|
178
|
+
console.log(`[CloudConnector] Connected to ${serverUrl}`);
|
|
179
|
+
});
|
|
180
|
+
this.ws.on("message", (data) => {
|
|
181
|
+
this.handleMessage(data);
|
|
182
|
+
});
|
|
183
|
+
this.ws.on("close", (code, reason) => {
|
|
184
|
+
this.handleClose(code, reason.toString(), serverUrl);
|
|
185
|
+
});
|
|
186
|
+
this.ws.on("error", (error) => {
|
|
187
|
+
console.error(`[CloudConnector] WebSocket error:`, error.message);
|
|
188
|
+
this.lastConnectionError = error.message;
|
|
189
|
+
if (error.message.includes("301") && !this.shouldTryWss && serverUrl.startsWith("ws://") && this.wssRetryAttempts < this.maxWssRetryAttempts) {
|
|
190
|
+
this.shouldTryWss = true;
|
|
191
|
+
this.wssRetryAttempts++;
|
|
192
|
+
this.ws = null;
|
|
193
|
+
console.log(
|
|
194
|
+
`[CloudConnector] Server requires wss://, retrying (${this.wssRetryAttempts}/${this.maxWssRetryAttempts})...`
|
|
195
|
+
);
|
|
196
|
+
setTimeout(() => this.connect(), 1e3);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
disconnect() {
|
|
201
|
+
this.isManualClose = true;
|
|
202
|
+
this.plugin?.disconnect();
|
|
203
|
+
this.plugin = null;
|
|
204
|
+
this.stopHeartbeat();
|
|
205
|
+
if (this.reconnectTimer) {
|
|
206
|
+
clearTimeout(this.reconnectTimer);
|
|
207
|
+
this.reconnectTimer = null;
|
|
208
|
+
}
|
|
209
|
+
if (this.ws) {
|
|
210
|
+
this.ws.close();
|
|
211
|
+
this.ws = null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
handleMessage(data) {
|
|
215
|
+
this.messageBuffer += data.toString("utf-8");
|
|
216
|
+
if (this.messageBuffer.length > MAX_BUFFER_SIZE) {
|
|
217
|
+
console.error("[CloudConnector] Message buffer exceeds limit, closing connection");
|
|
218
|
+
this.disconnect();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
let newlineIndex;
|
|
222
|
+
while ((newlineIndex = this.messageBuffer.indexOf("\n")) !== -1) {
|
|
223
|
+
const line = this.messageBuffer.slice(0, newlineIndex);
|
|
224
|
+
this.messageBuffer = this.messageBuffer.slice(newlineIndex + 1);
|
|
225
|
+
if (!line.trim()) continue;
|
|
226
|
+
try {
|
|
227
|
+
const message = JSON.parse(line);
|
|
228
|
+
this.handleCloudMessage(message);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
console.error(`[CloudConnector] Failed to parse message:`, line, error);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
handleClose(code, reasonText, serverUrl) {
|
|
235
|
+
console.log(`[CloudConnector] Disconnected (${code}: ${reasonText})`);
|
|
236
|
+
this.stopHeartbeat();
|
|
237
|
+
this.messageBuffer = "";
|
|
238
|
+
if (this.shouldTryWss && serverUrl.startsWith("ws://")) return;
|
|
239
|
+
if (code === 1e3 && reasonText === CONNECTOR_REPLACED_REASON) {
|
|
240
|
+
this.isManualClose = true;
|
|
241
|
+
console.error("[CloudConnector] Superseded by a newer connector; exiting");
|
|
242
|
+
this.options.onSuperseded?.();
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (this.options.failFast && !this.hasConnected) {
|
|
246
|
+
const message = this.lastConnectionError || reasonText || `Connection closed (${code})`;
|
|
247
|
+
this.emitState({ state: "failed", reason: message });
|
|
248
|
+
this.options.onInitialConnectionFailed?.(message);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
this.tryReconnect(this.lastConnectionError || reasonText || `Connection closed (${code})`);
|
|
252
|
+
}
|
|
253
|
+
async handleCloudMessage(message) {
|
|
254
|
+
if (isHeartbeatMessage(message)) {
|
|
255
|
+
this.emitState({ state: "connected", heartbeat: true });
|
|
256
|
+
if (message.type === "ping") {
|
|
257
|
+
this.sendHeartbeatResponse(message.timestamp);
|
|
258
|
+
}
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const request = message;
|
|
262
|
+
const { id, action, data, browser, timeoutSec } = request;
|
|
263
|
+
try {
|
|
264
|
+
const client = await import("@mearl/client/local");
|
|
265
|
+
const result = await client.invoke(action, data, {
|
|
266
|
+
browser,
|
|
267
|
+
timeoutSec: timeoutSec ?? resolveActionTimeoutSec(action, data, 15),
|
|
268
|
+
controlSource: "remote",
|
|
269
|
+
...request.controlSessionId ? { controlSessionId: request.controlSessionId } : {}
|
|
270
|
+
});
|
|
271
|
+
this.sendResponse({ id, success: true, data: result });
|
|
272
|
+
} catch (error) {
|
|
273
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
274
|
+
this.sendResponse({ id, success: false, error: errorMessage });
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
sendResponse(response) {
|
|
278
|
+
if (this.ws && this.ws.readyState === 1) {
|
|
279
|
+
const message = JSON.stringify(response) + "\n";
|
|
280
|
+
const bytes = Buffer.byteLength(message, "utf-8");
|
|
281
|
+
if (bytes > MAX_BUFFER_SIZE) {
|
|
282
|
+
console.error(
|
|
283
|
+
`[CloudConnector] Response ${response.id} exceeds message limit (${bytes} > ${MAX_BUFFER_SIZE} bytes)`
|
|
284
|
+
);
|
|
285
|
+
this.ws.send(
|
|
286
|
+
JSON.stringify({
|
|
287
|
+
id: response.id,
|
|
288
|
+
success: false,
|
|
289
|
+
error: `Cloud response exceeds ${MAX_BUFFER_SIZE} byte message limit (${bytes} bytes). Reduce the result size; for screenshots use JPEG quality or a selector.`
|
|
290
|
+
}) + "\n"
|
|
291
|
+
);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
this.ws.send(message);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
sendConnectorHello() {
|
|
298
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
299
|
+
const message = {
|
|
300
|
+
type: "connector_hello",
|
|
301
|
+
connectorId: this.identity.connectorId,
|
|
302
|
+
name: this.identity.name,
|
|
303
|
+
...CLOUD_CONNECTOR_VERSION === "unknown" ? {} : { version: CLOUD_CONNECTOR_VERSION }
|
|
304
|
+
};
|
|
305
|
+
this.ws.send(JSON.stringify(message) + "\n");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
sendHeartbeatResponse(_timestamp) {
|
|
309
|
+
if (this.ws && this.ws.readyState === 1) {
|
|
310
|
+
this.ws.send(
|
|
311
|
+
JSON.stringify({ type: "pong", timestamp: Date.now() }) + "\n"
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
startHeartbeat() {
|
|
316
|
+
this.stopHeartbeat();
|
|
317
|
+
this.heartbeatTimer = setInterval(() => {
|
|
318
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
319
|
+
this.ws.send(
|
|
320
|
+
JSON.stringify({ type: "ping", timestamp: Date.now() }) + "\n"
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
}, this.options.heartbeatInterval * 1e3);
|
|
324
|
+
}
|
|
325
|
+
stopHeartbeat() {
|
|
326
|
+
if (this.heartbeatTimer) {
|
|
327
|
+
clearInterval(this.heartbeatTimer);
|
|
328
|
+
this.heartbeatTimer = null;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
tryReconnect(reason) {
|
|
332
|
+
if (this.isManualClose) return;
|
|
333
|
+
if (this.reconnectTimer) return;
|
|
334
|
+
this.reconnectAttempts++;
|
|
335
|
+
if (this.options.maxReconnectAttempts !== -1 && this.reconnectAttempts > this.options.maxReconnectAttempts) {
|
|
336
|
+
console.log(
|
|
337
|
+
`[CloudConnector] Max reconnect attempts (${this.options.maxReconnectAttempts}) reached`
|
|
338
|
+
);
|
|
339
|
+
this.emitState({
|
|
340
|
+
state: "failed",
|
|
341
|
+
...reason ? { reason } : {},
|
|
342
|
+
reconnectAttempt: this.reconnectAttempts
|
|
343
|
+
});
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const isSlowProbe = this.reconnectAttempts > FAST_RECONNECT_ATTEMPTS;
|
|
347
|
+
const delay = isSlowProbe ? SLOW_PROBE_INTERVAL_MS : Math.min(BACKOFF_BASE_MS * Math.pow(2, this.reconnectAttempts - 1), BACKOFF_MAX_MS);
|
|
348
|
+
if (isSlowProbe) {
|
|
349
|
+
console.log(
|
|
350
|
+
`[CloudConnector] Slow probe reconnect in ${delay / 1e3}s (attempt ${this.reconnectAttempts})`
|
|
351
|
+
);
|
|
352
|
+
} else {
|
|
353
|
+
console.log(
|
|
354
|
+
`[CloudConnector] Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts}/${FAST_RECONNECT_ATTEMPTS})`
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
this.emitState({
|
|
358
|
+
state: "reconnecting",
|
|
359
|
+
...reason ? { reason } : {},
|
|
360
|
+
reconnectAttempt: this.reconnectAttempts,
|
|
361
|
+
retryInMs: delay
|
|
362
|
+
});
|
|
363
|
+
this.reconnectTimer = setTimeout(() => {
|
|
364
|
+
this.reconnectTimer = null;
|
|
365
|
+
this.connect();
|
|
366
|
+
}, delay);
|
|
367
|
+
}
|
|
368
|
+
emitState(change) {
|
|
369
|
+
this.options.onStateChange?.(change);
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
export {
|
|
374
|
+
parseConnectorEndpoint,
|
|
375
|
+
isConnectorEndpoint,
|
|
376
|
+
requireConnectorEndpoint,
|
|
377
|
+
resolveConnectorIdentity,
|
|
378
|
+
CloudConnector
|
|
379
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
CloudConnector,
|
|
4
4
|
isConnectorEndpoint,
|
|
5
5
|
resolveConnectorIdentity
|
|
6
|
-
} from "./chunks/chunk-
|
|
6
|
+
} from "./chunks/chunk-UWYEHBQ7.js";
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
9
9
|
import { Command, CommanderError, InvalidArgumentError } from "commander";
|
|
@@ -55,7 +55,7 @@ function resolveConnectorHealth(record, now = Date.now()) {
|
|
|
55
55
|
case "failed":
|
|
56
56
|
return "failed";
|
|
57
57
|
case "connected": {
|
|
58
|
-
if (record.serverUrl
|
|
58
|
+
if (!/^wss?:/i.test(record.serverUrl)) return "healthy";
|
|
59
59
|
const freshness = record.lastHeartbeatAt ?? record.connectedAt;
|
|
60
60
|
if (!freshness) return "degraded";
|
|
61
61
|
const timestamp = Date.parse(freshness);
|
|
@@ -83,7 +83,7 @@ function formatConnectorStatus(record, now = Date.now()) {
|
|
|
83
83
|
lines.push(` retry: attempt ${record.reconnectAttempt}`);
|
|
84
84
|
}
|
|
85
85
|
if (record.nextRetryAt) lines.push(` next retry: ${record.nextRetryAt}`);
|
|
86
|
-
if (
|
|
86
|
+
if (/^wss?:/i.test(record.serverUrl) && (health === "reconnecting" || health === "failed" || health === "degraded")) {
|
|
87
87
|
lines.push(
|
|
88
88
|
" next step: on the Agent machine, run mearl-cloud-server status; verify the current connection URL/token and that its port is reachable from this machine."
|
|
89
89
|
);
|
|
@@ -311,7 +311,7 @@ function runForeground(options) {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
// src/cli.ts
|
|
314
|
-
var CLOUD_CONNECTOR_VERSION = true ? "3.0.0-beta.
|
|
314
|
+
var CLOUD_CONNECTOR_VERSION = true ? "3.0.0-beta.10" : "unknown";
|
|
315
315
|
var SUBCOMMANDS = ["start", "stop", "restart", "status", "list", "logs"];
|
|
316
316
|
var CONNECTION_OPTION_NAMES = /* @__PURE__ */ new Set([
|
|
317
317
|
"foreground",
|
|
@@ -441,7 +441,7 @@ function parseCloudConnectorArgs(argv) {
|
|
|
441
441
|
const serverUrl = target && isConnectorEndpoint(target) ? target : void 0;
|
|
442
442
|
if (target !== void 0 && !serverUrl && stopPid === void 0) {
|
|
443
443
|
throw new Error(
|
|
444
|
-
command === "stop" ? "stop target must be a
|
|
444
|
+
command === "stop" ? "stop target must be a connector server-url, or a positive pid" : "server-url must be a valid connector URL"
|
|
445
445
|
);
|
|
446
446
|
}
|
|
447
447
|
assertAllowedOptions(program, command);
|
|
File without changes
|
package/dist/endpoint.d.ts
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
export type ConnectorEndpointScheme =
|
|
2
|
-
export interface
|
|
3
|
-
/** User-facing URL retained for daemon identity and lifecycle commands. */
|
|
1
|
+
export type ConnectorEndpointScheme = string;
|
|
2
|
+
export interface ConnectorEndpoint {
|
|
4
3
|
serverUrl: string;
|
|
5
|
-
/** WebSocket URL used for the network connection. */
|
|
6
4
|
transportUrl: string;
|
|
7
|
-
scheme:
|
|
5
|
+
scheme: string;
|
|
8
6
|
}
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
serverUrl: string;
|
|
12
|
-
scheme: 'qoder';
|
|
13
|
-
pairingCode: string;
|
|
14
|
-
createdAt?: number;
|
|
15
|
-
}
|
|
16
|
-
export type ConnectorEndpoint = WebSocketConnectorEndpoint | QoderConnectorEndpoint;
|
|
17
|
-
/** Parse a connector endpoint without changing its user-facing daemon identity. */
|
|
7
|
+
export type WebSocketConnectorEndpoint = ConnectorEndpoint;
|
|
8
|
+
/** WebSocket is built in; other schemes require a locally installed capability. */
|
|
18
9
|
export declare function parseConnectorEndpoint(value: string | undefined): ConnectorEndpoint | null;
|
|
19
10
|
export declare function isConnectorEndpoint(value: string | undefined): value is string;
|
|
20
11
|
export declare function requireConnectorEndpoint(value: string): ConnectorEndpoint;
|
|
12
|
+
export declare function isWebSocketEndpoint(endpoint: ConnectorEndpoint): boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type ConnectorIdentity } from './identity.js';
|
|
2
2
|
import type { CloudConnectorStateChange } from './state.js';
|
|
3
|
-
export { isConnectorEndpoint, parseConnectorEndpoint, requireConnectorEndpoint, type ConnectorEndpoint, type ConnectorEndpointScheme, type
|
|
4
|
-
export { DEFAULT_QODER_API_BASE_URL, QODER_TOOL_NAME, QoderApiClient, QoderApiError, QoderConnector, formatQoderToolResult, parseQoderSse, type QoderContentBlock, type QoderPairingRequest, type QoderPublicEvent, type QoderSseFrame, } from './qoder.js';
|
|
3
|
+
export { isConnectorEndpoint, parseConnectorEndpoint, requireConnectorEndpoint, type ConnectorEndpoint, type ConnectorEndpointScheme, type WebSocketConnectorEndpoint, } from './endpoint.js';
|
|
5
4
|
export type { CloudConnectorRuntimeState, CloudConnectorStateChange } from './state.js';
|
|
6
5
|
export interface CloudConnectorOptions {
|
|
7
6
|
serverUrl: string;
|
|
@@ -23,7 +22,8 @@ export declare class CloudConnector {
|
|
|
23
22
|
private options;
|
|
24
23
|
private endpoint;
|
|
25
24
|
private identity;
|
|
26
|
-
private
|
|
25
|
+
private plugin;
|
|
26
|
+
private pluginLoad;
|
|
27
27
|
private ws;
|
|
28
28
|
private heartbeatTimer;
|
|
29
29
|
private reconnectTimer;
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CloudConnector,
|
|
3
|
-
DEFAULT_QODER_API_BASE_URL,
|
|
4
|
-
QODER_TOOL_NAME,
|
|
5
|
-
QoderApiClient,
|
|
6
|
-
QoderApiError,
|
|
7
|
-
QoderConnector,
|
|
8
|
-
formatQoderToolResult,
|
|
9
3
|
isConnectorEndpoint,
|
|
10
4
|
parseConnectorEndpoint,
|
|
11
|
-
parseQoderSse,
|
|
12
5
|
requireConnectorEndpoint
|
|
13
|
-
} from "./chunks/chunk-
|
|
6
|
+
} from "./chunks/chunk-UWYEHBQ7.js";
|
|
14
7
|
export {
|
|
15
8
|
CloudConnector,
|
|
16
|
-
DEFAULT_QODER_API_BASE_URL,
|
|
17
|
-
QODER_TOOL_NAME,
|
|
18
|
-
QoderApiClient,
|
|
19
|
-
QoderApiError,
|
|
20
|
-
QoderConnector,
|
|
21
|
-
formatQoderToolResult,
|
|
22
9
|
isConnectorEndpoint,
|
|
23
10
|
parseConnectorEndpoint,
|
|
24
|
-
parseQoderSse,
|
|
25
11
|
requireConnectorEndpoint
|
|
26
12
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ConnectorIdentity } from './identity.js';
|
|
2
|
+
import type { CloudConnectorStateChange } from './state.js';
|
|
3
|
+
export interface ConnectorPlugin {
|
|
4
|
+
connect(): void;
|
|
5
|
+
disconnect(): void;
|
|
6
|
+
}
|
|
7
|
+
export interface ConnectorPluginOptions {
|
|
8
|
+
serverUrl: string;
|
|
9
|
+
identity: ConnectorIdentity;
|
|
10
|
+
reconnectInterval: number;
|
|
11
|
+
maxReconnectAttempts: number;
|
|
12
|
+
failFast: boolean;
|
|
13
|
+
onConnected(): void;
|
|
14
|
+
onStateChange(change: CloudConnectorStateChange): void;
|
|
15
|
+
onInitialConnectionFailed?: (message: string) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function loadConnectorPlugin(scheme: string, options: ConnectorPluginOptions): Promise<ConnectorPlugin>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mearl/cloud-connector",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.10",
|
|
4
4
|
"description": "Cloud connector for Mearl — bridges cloud agents to a local native-host",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./contracts": {
|
|
14
|
+
"types": "./dist/contracts.d.ts",
|
|
15
|
+
"import": "./dist/contracts.js"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"bin": {
|
|
@@ -23,22 +27,21 @@
|
|
|
23
27
|
"keywords": [
|
|
24
28
|
"mearl",
|
|
25
29
|
"cloud-connector",
|
|
26
|
-
"websocket"
|
|
27
|
-
"qoder"
|
|
30
|
+
"websocket"
|
|
28
31
|
],
|
|
29
32
|
"license": "Apache-2.0",
|
|
30
33
|
"engines": {
|
|
31
|
-
"node": ">=
|
|
34
|
+
"node": ">=20.18.0"
|
|
32
35
|
},
|
|
33
36
|
"publishConfig": {
|
|
34
37
|
"registry": "https://registry.npmjs.org"
|
|
35
38
|
},
|
|
36
39
|
"dependencies": {
|
|
37
|
-
"commander": "^
|
|
40
|
+
"commander": "^14.0.3",
|
|
38
41
|
"ws": "^8.18.0",
|
|
39
|
-
"@mearl/
|
|
40
|
-
"@mearl/
|
|
41
|
-
"@mearl/
|
|
42
|
+
"@mearl/cloud-types": "3.0.0-beta.10",
|
|
43
|
+
"@mearl/daemon-core": "3.0.0-beta.10",
|
|
44
|
+
"@mearl/client": "3.0.0-beta.10"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"@types/node": "^24.9.1",
|
|
@@ -46,6 +49,11 @@
|
|
|
46
49
|
"esbuild": "^0.28.2",
|
|
47
50
|
"typescript": "^5.8.3"
|
|
48
51
|
},
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/mearlhq/mearl.git",
|
|
55
|
+
"directory": "packages/cloud/cloud-connector"
|
|
56
|
+
},
|
|
49
57
|
"scripts": {
|
|
50
58
|
"build": "rm -rf dist/ && node build.mjs",
|
|
51
59
|
"dev": "tsc --watch",
|