@buda-ai/connector 0.1.8 → 0.1.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/dist/cli.js +37 -20
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -517,7 +517,7 @@ import path2 from "path";
|
|
|
517
517
|
// package.json
|
|
518
518
|
var package_default = {
|
|
519
519
|
name: "@buda-ai/connector",
|
|
520
|
-
version: "0.1.
|
|
520
|
+
version: "0.1.10",
|
|
521
521
|
private: false,
|
|
522
522
|
type: "module",
|
|
523
523
|
publishConfig: {
|
|
@@ -2199,6 +2199,12 @@ var BASE_CONNECTOR_CAPABILITIES = [
|
|
|
2199
2199
|
"shell",
|
|
2200
2200
|
"git"
|
|
2201
2201
|
];
|
|
2202
|
+
var ConnectorDeletedError = class extends Error {
|
|
2203
|
+
constructor(message) {
|
|
2204
|
+
super(message);
|
|
2205
|
+
this.name = "ConnectorDeletedError";
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2202
2208
|
async function resolveConnectorScope(deviceId, launchConfig) {
|
|
2203
2209
|
const serverUrl = normalizeServerOrigin(getServerUrl(launchConfig));
|
|
2204
2210
|
const headers = { "Content-Type": "application/json" };
|
|
@@ -2309,6 +2315,9 @@ async function postJson(serverUrl, pathname, body, config, launchConfig) {
|
|
|
2309
2315
|
`This device is prohibited/revoked and cannot reconnect. Contact support. (${errorMessage3})`
|
|
2310
2316
|
);
|
|
2311
2317
|
}
|
|
2318
|
+
if (errorCode === "connector_deleted") {
|
|
2319
|
+
throw new ConnectorDeletedError(errorMessage3 || "Connector no longer exists");
|
|
2320
|
+
}
|
|
2312
2321
|
throw new Error(`${pathname} failed: ${response.status} ${errorMessage3}`);
|
|
2313
2322
|
}
|
|
2314
2323
|
return await response.json();
|
|
@@ -2320,7 +2329,7 @@ async function warnIfStaleBundle(result) {
|
|
|
2320
2329
|
if (!result.bundle?.staleClient) return;
|
|
2321
2330
|
await writeLog(
|
|
2322
2331
|
"warn",
|
|
2323
|
-
`connector
|
|
2332
|
+
`connector runtime out of date \u2014 latest published version is ${result.bundle.latestVersion ?? "newer"}; run \`pnpm up @buda-ai/connector\``
|
|
2324
2333
|
);
|
|
2325
2334
|
}
|
|
2326
2335
|
async function registerConnector(config, launchConfig, bunnyDaemon, options) {
|
|
@@ -5315,30 +5324,18 @@ async function runConnectorDaemon(launchConfig, options = {}) {
|
|
|
5315
5324
|
await writeLog("info", `workdir root ${config.workdirRoot}`);
|
|
5316
5325
|
await writeLog("info", `log file ${getDatedConnectorLogPath(paths.logPath)}`);
|
|
5317
5326
|
await writeLog("info", `bunny daemon ${activeBunnyDaemon.baseUrl}`);
|
|
5318
|
-
|
|
5319
|
-
heartbeatConnector(config, launchConfig, activeBunnyDaemon).then(({ relayProtocol: nextRelayProtocol }) => {
|
|
5320
|
-
lastHeartbeatAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5321
|
-
relay.updateRelayProtocol(nextRelayProtocol);
|
|
5322
|
-
relay.resumeAfterAccessRestore();
|
|
5323
|
-
updateConnectorDashboardStatus({
|
|
5324
|
-
heartbeat: `OK ${(/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", { hour12: false })}`
|
|
5325
|
-
});
|
|
5326
|
-
}).catch((error) => {
|
|
5327
|
-
void writeLog(
|
|
5328
|
-
"warn",
|
|
5329
|
-
`heartbeat failed: ${error instanceof Error ? error.message : String(error)}`
|
|
5330
|
-
);
|
|
5331
|
-
});
|
|
5332
|
-
}, HEARTBEAT_INTERVAL_MS);
|
|
5327
|
+
let interval;
|
|
5333
5328
|
let shuttingDown = false;
|
|
5334
|
-
const shutdown = async () => {
|
|
5329
|
+
const shutdown = async (shutdownOptions = {}) => {
|
|
5335
5330
|
if (shuttingDown) return;
|
|
5336
5331
|
shuttingDown = true;
|
|
5337
|
-
clearInterval(interval);
|
|
5332
|
+
if (interval) clearInterval(interval);
|
|
5338
5333
|
relay.stop();
|
|
5339
5334
|
try {
|
|
5340
5335
|
await closeAllBrowserSessions();
|
|
5341
|
-
|
|
5336
|
+
if (shutdownOptions.unregister !== false) {
|
|
5337
|
+
await unregisterConnector(config, launchConfig);
|
|
5338
|
+
}
|
|
5342
5339
|
await stopEmbeddedBunnyDaemon(activeBunnyDaemon);
|
|
5343
5340
|
} finally {
|
|
5344
5341
|
await control?.close();
|
|
@@ -5347,6 +5344,26 @@ async function runConnectorDaemon(launchConfig, options = {}) {
|
|
|
5347
5344
|
if (options.exitOnShutdown !== false) process.exit(0);
|
|
5348
5345
|
}
|
|
5349
5346
|
};
|
|
5347
|
+
interval = setInterval(() => {
|
|
5348
|
+
heartbeatConnector(config, launchConfig, activeBunnyDaemon).then(({ relayProtocol: nextRelayProtocol }) => {
|
|
5349
|
+
lastHeartbeatAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5350
|
+
relay.updateRelayProtocol(nextRelayProtocol);
|
|
5351
|
+
relay.resumeAfterAccessRestore();
|
|
5352
|
+
updateConnectorDashboardStatus({
|
|
5353
|
+
heartbeat: `OK ${(/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", { hour12: false })}`
|
|
5354
|
+
});
|
|
5355
|
+
}).catch((error) => {
|
|
5356
|
+
if (error instanceof ConnectorDeletedError) {
|
|
5357
|
+
void writeLog("warn", "connector deleted remotely; stopping daemon");
|
|
5358
|
+
void shutdown({ unregister: false });
|
|
5359
|
+
return;
|
|
5360
|
+
}
|
|
5361
|
+
void writeLog(
|
|
5362
|
+
"warn",
|
|
5363
|
+
`heartbeat failed: ${error instanceof Error ? error.message : String(error)}`
|
|
5364
|
+
);
|
|
5365
|
+
});
|
|
5366
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
5350
5367
|
control = await startDaemonControlServer({
|
|
5351
5368
|
config,
|
|
5352
5369
|
configRoot,
|