@mearl/cloud-connector 2.8.2 → 2.9.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/dist/chunks/{chunk-DFADDQ4W.js → chunk-JJFRVBNN.js} +2 -2
- package/dist/cli.d.ts +15 -0
- package/dist/cli.js +173 -100
- package/dist/index.js +1 -1
- package/package.json +8 -4
|
@@ -28,7 +28,7 @@ function resolveConnectorIdentity(options) {
|
|
|
28
28
|
if (!/^[A-Za-z0-9._:-]{1,128}$/.test(connectorId)) {
|
|
29
29
|
throw new Error('connectorId must contain only letters, numbers, ".", "_", ":", or "-"');
|
|
30
30
|
}
|
|
31
|
-
if (name.length > 128 ||
|
|
31
|
+
if (name.length > 128 || new RegExp("\\p{Cc}", "u").test(name)) {
|
|
32
32
|
throw new Error("connectorName must be 1-128 characters without control characters");
|
|
33
33
|
}
|
|
34
34
|
return { connectorId, name };
|
|
@@ -660,7 +660,7 @@ var QoderConnector = class {
|
|
|
660
660
|
};
|
|
661
661
|
|
|
662
662
|
// src/index.ts
|
|
663
|
-
var CLOUD_CONNECTOR_VERSION = true ? "2.
|
|
663
|
+
var CLOUD_CONNECTOR_VERSION = true ? "2.9.1" : "unknown";
|
|
664
664
|
var DEFAULT_RECONNECT_INTERVAL = 5e3;
|
|
665
665
|
var BACKOFF_BASE_MS = 1e3;
|
|
666
666
|
var BACKOFF_MAX_MS = 3e4;
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import type { CloudConnectorOptions } from './index.js';
|
|
3
|
+
declare const SUBCOMMANDS: readonly ["start", "stop", "restart", "status", "list", "logs"];
|
|
4
|
+
type Subcommand = (typeof SUBCOMMANDS)[number];
|
|
5
|
+
export interface ParsedCloudConnectorArgs {
|
|
6
|
+
command: Subcommand | null;
|
|
7
|
+
daemonArgs: string[];
|
|
8
|
+
foreground: boolean;
|
|
9
|
+
help: boolean;
|
|
10
|
+
options?: CloudConnectorOptions;
|
|
11
|
+
serverUrl?: string;
|
|
12
|
+
stopAll: boolean;
|
|
13
|
+
version: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseCloudConnectorArgs(argv: string[]): ParsedCloudConnectorArgs;
|
|
16
|
+
export declare function main(argv?: string[]): Promise<number>;
|
|
2
17
|
export {};
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
import {
|
|
3
3
|
CloudConnector,
|
|
4
4
|
isConnectorEndpoint
|
|
5
|
-
} from "./chunks/chunk-
|
|
5
|
+
} from "./chunks/chunk-JJFRVBNN.js";
|
|
6
|
+
|
|
7
|
+
// src/cli.ts
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
10
|
+
import { Command, CommanderError, InvalidArgumentError } from "commander";
|
|
6
11
|
|
|
7
12
|
// src/daemon.ts
|
|
8
13
|
import { fileURLToPath } from "node:url";
|
|
@@ -121,149 +126,217 @@ function runForeground(options) {
|
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
// src/cli.ts
|
|
124
|
-
var CLOUD_CONNECTOR_VERSION = true ? "2.
|
|
125
|
-
var args = process.argv.slice(2);
|
|
126
|
-
if (args.includes("--version") || args.includes("-v")) {
|
|
127
|
-
console.log(CLOUD_CONNECTOR_VERSION);
|
|
128
|
-
process.exit(0);
|
|
129
|
-
}
|
|
129
|
+
var CLOUD_CONNECTOR_VERSION = true ? "2.9.1" : "unknown";
|
|
130
130
|
var SUBCOMMANDS = ["start", "stop", "restart", "status", "list", "logs"];
|
|
131
|
+
var CONNECTION_OPTION_NAMES = /* @__PURE__ */ new Set([
|
|
132
|
+
"foreground",
|
|
133
|
+
"heartbeat",
|
|
134
|
+
"reconnect",
|
|
135
|
+
"maxReconnect",
|
|
136
|
+
"connectorId",
|
|
137
|
+
"name",
|
|
138
|
+
"failFast"
|
|
139
|
+
]);
|
|
131
140
|
function showHelp() {
|
|
132
141
|
console.error(`mearl-cloud-connector v${CLOUD_CONNECTOR_VERSION}
|
|
133
142
|
|
|
134
143
|
Usage:
|
|
135
|
-
mearl-cloud-connector <server-url> [options]
|
|
136
|
-
mearl-cloud-connector <command> [server-url] [options]
|
|
144
|
+
mearl-cloud-connector <server-url> [options]
|
|
145
|
+
mearl-cloud-connector <command> [server-url] [options]
|
|
137
146
|
|
|
138
147
|
Commands:
|
|
139
|
-
start <server-url> Start a background connector
|
|
140
|
-
stop <server-url> Stop
|
|
148
|
+
start <server-url> Start a background connector
|
|
149
|
+
stop <server-url> Stop one background connector
|
|
141
150
|
stop --all Stop every background connector
|
|
142
|
-
restart <server-url> Restart
|
|
143
|
-
status [server-url] Show one connector's status, or list all
|
|
151
|
+
restart <server-url> Restart a background connector
|
|
152
|
+
status [server-url] Show one connector's status, or list all
|
|
144
153
|
list List every running connector
|
|
145
|
-
logs <server-url> Print
|
|
146
|
-
|
|
147
|
-
Arguments:
|
|
148
|
-
server-url Connector URL (ws://, wss://, or qoder://)
|
|
154
|
+
logs <server-url> Print a connector's log
|
|
149
155
|
|
|
150
156
|
Options:
|
|
151
|
-
--foreground, -f Run
|
|
157
|
+
--foreground, -f Run directly instead of daemonizing
|
|
152
158
|
--heartbeat <seconds> Heartbeat interval (default: 30)
|
|
153
159
|
--reconnect <ms> Reconnect interval in ms (default: 5000)
|
|
154
|
-
--max-reconnect <n> Max reconnect attempts, -1 for unlimited
|
|
160
|
+
--max-reconnect <n> Max reconnect attempts, -1 for unlimited
|
|
155
161
|
--connector-id <id> Override this machine's stable connector id
|
|
156
|
-
--name <name> Human-readable connector name
|
|
157
|
-
--fail-fast Exit if the
|
|
162
|
+
--name <name> Human-readable connector name
|
|
163
|
+
--fail-fast Exit if the first connection fails
|
|
158
164
|
--version, -v Show version
|
|
159
165
|
--help, -h Show this help message
|
|
160
|
-
|
|
161
|
-
Examples:
|
|
162
|
-
# Start a self-managed background connector with its own log file (recommended)
|
|
163
|
-
mearl-cloud-connector start "wss://cloud.example.com/ws?token=xxx"
|
|
164
|
-
|
|
165
|
-
# Complete a Qoder custom-tool pairing, then keep the connector in the background
|
|
166
|
-
mearl-cloud-connector start "qoder://pair/pairing-code-1234?created=1786723200000"
|
|
167
|
-
|
|
168
|
-
# Run in the foreground for diagnostics or an external process manager
|
|
169
|
-
mearl-cloud-connector "ws://localhost:8080/ws?token=xxx"
|
|
170
|
-
|
|
171
|
-
# Inspect or stop background connectors
|
|
172
|
-
mearl-cloud-connector status
|
|
173
|
-
mearl-cloud-connector logs "wss://cloud.example.com/ws?token=xxx"
|
|
174
|
-
mearl-cloud-connector stop "wss://cloud.example.com/ws?token=xxx"
|
|
175
166
|
`);
|
|
176
167
|
}
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
168
|
+
function integerOption(label, minimum) {
|
|
169
|
+
return (value) => {
|
|
170
|
+
const parsed = Number(value);
|
|
171
|
+
if (!Number.isInteger(parsed) || parsed < minimum) {
|
|
172
|
+
throw new InvalidArgumentError(`${label} must be an integer of at least ${minimum}`);
|
|
173
|
+
}
|
|
174
|
+
return parsed;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function optionUsed(program, name) {
|
|
178
|
+
return program.getOptionValueSource(name) === "cli";
|
|
179
|
+
}
|
|
180
|
+
function assertAllowedOptions(program, command) {
|
|
181
|
+
const allowed = command === null || command === "start" || command === "restart" ? CONNECTION_OPTION_NAMES : command === "stop" ? /* @__PURE__ */ new Set(["all"]) : /* @__PURE__ */ new Set();
|
|
182
|
+
for (const option of program.options) {
|
|
183
|
+
const name = option.attributeName();
|
|
184
|
+
if (optionUsed(program, name) && !allowed.has(name) && name !== "help" && name !== "version") {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`${option.long ?? option.flags} is not available for ${command ?? "foreground"}`
|
|
187
|
+
);
|
|
193
188
|
}
|
|
194
189
|
}
|
|
195
|
-
|
|
190
|
+
if (command === "restart" && optionUsed(program, "foreground")) {
|
|
191
|
+
throw new Error("--foreground is only available for start or a bare server-url");
|
|
192
|
+
}
|
|
196
193
|
}
|
|
197
|
-
function
|
|
198
|
-
return
|
|
194
|
+
function connectorOptions(serverUrl, options) {
|
|
195
|
+
return {
|
|
196
|
+
serverUrl,
|
|
197
|
+
...options.heartbeat !== void 0 ? { heartbeatInterval: options.heartbeat } : {},
|
|
198
|
+
...options.reconnect !== void 0 ? { reconnectInterval: options.reconnect } : {},
|
|
199
|
+
...options.maxReconnect !== void 0 ? { maxReconnectAttempts: options.maxReconnect } : {},
|
|
200
|
+
...options.connectorId !== void 0 ? { connectorId: options.connectorId } : {},
|
|
201
|
+
...options.name !== void 0 ? { connectorName: options.name } : {},
|
|
202
|
+
...options.failFast ? { failFast: true } : {}
|
|
203
|
+
};
|
|
199
204
|
}
|
|
200
|
-
function
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
205
|
+
function daemonArgs(program, options) {
|
|
206
|
+
const args = [];
|
|
207
|
+
const add = (name, flag) => {
|
|
208
|
+
const value = options[name];
|
|
209
|
+
if (optionUsed(program, String(name)) && value !== void 0) args.push(flag, String(value));
|
|
210
|
+
};
|
|
211
|
+
add("heartbeat", "--heartbeat");
|
|
212
|
+
add("reconnect", "--reconnect");
|
|
213
|
+
add("maxReconnect", "--max-reconnect");
|
|
214
|
+
add("connectorId", "--connector-id");
|
|
215
|
+
add("name", "--name");
|
|
216
|
+
if (options.failFast) args.push("--fail-fast");
|
|
217
|
+
return args;
|
|
204
218
|
}
|
|
205
|
-
|
|
219
|
+
function parseCloudConnectorArgs(argv) {
|
|
220
|
+
const program = new Command().name("mearl-cloud-connector").helpOption(false).allowExcessArguments(false).exitOverride().configureOutput({ writeErr: () => {
|
|
221
|
+
}, writeOut: () => {
|
|
222
|
+
} }).argument("[command-or-url]").argument("[server-url]").option("-f, --foreground").option("--heartbeat <seconds>", "heartbeat interval", integerOption("heartbeat", 1)).option("--reconnect <ms>", "reconnect interval", integerOption("reconnect", 1)).option("--max-reconnect <n>", "reconnect attempt limit", integerOption("max-reconnect", -1)).option("--connector-id <id>").option("--name <name>").option("--fail-fast").option("--all").option("-v, --version").option("-h, --help");
|
|
223
|
+
try {
|
|
224
|
+
program.parse(["node", "mearl-cloud-connector", ...argv]);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (error instanceof CommanderError) {
|
|
227
|
+
throw new Error(error.message.replace(/^error:\s*/i, ""), { cause: error });
|
|
228
|
+
}
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
const cliOptions = program.opts();
|
|
232
|
+
if (cliOptions.help || cliOptions.version) {
|
|
233
|
+
return {
|
|
234
|
+
command: null,
|
|
235
|
+
daemonArgs: [],
|
|
236
|
+
foreground: false,
|
|
237
|
+
help: cliOptions.help === true,
|
|
238
|
+
stopAll: false,
|
|
239
|
+
version: cliOptions.version === true
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const first = program.processedArgs[0];
|
|
243
|
+
const second = program.processedArgs[1];
|
|
244
|
+
const bareEndpoint = first !== void 0 && isConnectorEndpoint(first);
|
|
245
|
+
if (first && !bareEndpoint && !SUBCOMMANDS.includes(first)) {
|
|
246
|
+
throw new Error(`Unknown command: ${first}`);
|
|
247
|
+
}
|
|
248
|
+
const command = bareEndpoint || first === void 0 ? null : first;
|
|
249
|
+
const serverUrl = bareEndpoint ? first : second;
|
|
250
|
+
if (serverUrl !== void 0 && !isConnectorEndpoint(serverUrl)) {
|
|
251
|
+
throw new Error("server-url must use ws://, wss://, or qoder://");
|
|
252
|
+
}
|
|
253
|
+
assertAllowedOptions(program, command);
|
|
254
|
+
if (command === null && !serverUrl) throw new Error("a command or server-url is required");
|
|
255
|
+
if ((command === "start" || command === "restart" || command === "logs") && !serverUrl) {
|
|
256
|
+
throw new Error(`\`${command}\` requires a server-url`);
|
|
257
|
+
}
|
|
258
|
+
if (command === "stop" && !serverUrl && !cliOptions.all) {
|
|
259
|
+
throw new Error("`stop` requires a server-url or --all");
|
|
260
|
+
}
|
|
261
|
+
if (command === "stop" && serverUrl && cliOptions.all) {
|
|
262
|
+
throw new Error("`stop` accepts either a server-url or --all, not both");
|
|
263
|
+
}
|
|
264
|
+
const foreground = command === null || cliOptions.foreground === true;
|
|
265
|
+
return {
|
|
266
|
+
command,
|
|
267
|
+
daemonArgs: daemonArgs(program, cliOptions),
|
|
268
|
+
foreground,
|
|
269
|
+
help: false,
|
|
270
|
+
...serverUrl ? { serverUrl } : {},
|
|
271
|
+
...foreground && serverUrl ? { options: connectorOptions(serverUrl, cliOptions) } : {},
|
|
272
|
+
stopAll: command === "stop" && cliOptions.all === true,
|
|
273
|
+
version: false
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
async function main(argv = process.argv.slice(2)) {
|
|
206
277
|
process.stdout.on("error", () => {
|
|
207
278
|
});
|
|
208
279
|
process.stderr.on("error", () => {
|
|
209
280
|
});
|
|
210
|
-
if (
|
|
281
|
+
if (argv.length === 0) {
|
|
211
282
|
showHelp();
|
|
212
|
-
|
|
283
|
+
return 1;
|
|
213
284
|
}
|
|
214
|
-
let
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
285
|
+
let parsed;
|
|
286
|
+
try {
|
|
287
|
+
parsed = parseCloudConnectorArgs(argv);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
290
|
+
showHelp();
|
|
291
|
+
return 2;
|
|
219
292
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
293
|
+
if (parsed.help) {
|
|
294
|
+
showHelp();
|
|
295
|
+
return 0;
|
|
296
|
+
}
|
|
297
|
+
if (parsed.version) {
|
|
298
|
+
console.log(CLOUD_CONNECTOR_VERSION);
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
if (parsed.foreground) {
|
|
228
302
|
console.log("[CloudConnector] Starting...");
|
|
229
|
-
console.log(`[CloudConnector] Connecting to: ${serverUrl}`);
|
|
230
|
-
runForeground(options);
|
|
231
|
-
return;
|
|
303
|
+
console.log(`[CloudConnector] Connecting to: ${parsed.serverUrl}`);
|
|
304
|
+
runForeground(parsed.options);
|
|
305
|
+
return 0;
|
|
232
306
|
}
|
|
233
|
-
switch (command) {
|
|
307
|
+
switch (parsed.command) {
|
|
234
308
|
case "start":
|
|
235
|
-
|
|
236
|
-
await startDaemon(serverUrl, optionArgs(rest));
|
|
309
|
+
await startDaemon(parsed.serverUrl, parsed.daemonArgs);
|
|
237
310
|
break;
|
|
238
311
|
case "stop":
|
|
239
|
-
if (
|
|
240
|
-
|
|
241
|
-
} else if (serverUrl) {
|
|
242
|
-
await stopDaemon(serverUrl);
|
|
243
|
-
} else {
|
|
244
|
-
exitHelp("`stop` requires a server-url or --all");
|
|
245
|
-
}
|
|
312
|
+
if (parsed.stopAll) await stopAllDaemons();
|
|
313
|
+
else await stopDaemon(parsed.serverUrl);
|
|
246
314
|
break;
|
|
247
315
|
case "restart":
|
|
248
|
-
|
|
249
|
-
await restartDaemon(serverUrl, optionArgs(rest));
|
|
316
|
+
await restartDaemon(parsed.serverUrl, parsed.daemonArgs);
|
|
250
317
|
break;
|
|
251
318
|
case "status":
|
|
252
|
-
statusDaemon(serverUrl);
|
|
319
|
+
statusDaemon(parsed.serverUrl);
|
|
253
320
|
break;
|
|
254
321
|
case "list":
|
|
255
322
|
listDaemons();
|
|
256
323
|
break;
|
|
257
324
|
case "logs":
|
|
258
|
-
|
|
259
|
-
printLogs(serverUrl);
|
|
325
|
+
printLogs(parsed.serverUrl);
|
|
260
326
|
break;
|
|
261
|
-
default:
|
|
262
|
-
showHelp();
|
|
263
|
-
process.exit(1);
|
|
264
327
|
}
|
|
328
|
+
return 0;
|
|
329
|
+
}
|
|
330
|
+
var currentFile = fileURLToPath2(import.meta.url);
|
|
331
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === currentFile) {
|
|
332
|
+
main().then((code) => {
|
|
333
|
+
process.exitCode = code;
|
|
334
|
+
}).catch((error) => {
|
|
335
|
+
console.error("[CloudConnector] Fatal error:", error);
|
|
336
|
+
process.exitCode = 1;
|
|
337
|
+
});
|
|
265
338
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
339
|
+
export {
|
|
340
|
+
main,
|
|
341
|
+
parseCloudConnectorArgs
|
|
342
|
+
};
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mearl/cloud-connector",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.1",
|
|
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",
|
|
@@ -27,14 +27,18 @@
|
|
|
27
27
|
"qoder"
|
|
28
28
|
],
|
|
29
29
|
"license": "ISC",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.12.0"
|
|
32
|
+
},
|
|
30
33
|
"publishConfig": {
|
|
31
34
|
"registry": "https://registry.npmjs.org"
|
|
32
35
|
},
|
|
33
36
|
"dependencies": {
|
|
37
|
+
"commander": "^15.0.0",
|
|
34
38
|
"ws": "^8.18.0",
|
|
35
|
-
"@mearl/
|
|
36
|
-
"@mearl/
|
|
37
|
-
"@mearl/
|
|
39
|
+
"@mearl/cloud-types": "2.9.1",
|
|
40
|
+
"@mearl/daemon-core": "2.9.1",
|
|
41
|
+
"@mearl/client": "2.9.1"
|
|
38
42
|
},
|
|
39
43
|
"devDependencies": {
|
|
40
44
|
"@types/node": "^24.9.1",
|