oasis_test 0.1.15 → 0.1.17
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/index.js +51 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33532,6 +33532,15 @@ function nodesDomain(deps) {
|
|
|
33532
33532
|
await deps.nodeStore.deleteNode(nodeId);
|
|
33533
33533
|
return { status: 200, body: { ok: true } };
|
|
33534
33534
|
});
|
|
33535
|
+
router.post("/api/nodes/:nodeId/update", async (req) => {
|
|
33536
|
+
const nodeId = req.params["nodeId"];
|
|
33537
|
+
if (!nodeId) return { status: 400, body: { error: "missing nodeId" } };
|
|
33538
|
+
const hub = deps.getHub();
|
|
33539
|
+
if (!hub) return { status: 503, body: { error: "node gateway \u672A\u5C31\u7EEA" } };
|
|
33540
|
+
const sent = hub.dispatch(nodeId, { type: "update" });
|
|
33541
|
+
if (!sent) return { status: 409, body: { error: `\u8282\u70B9 ${nodeId} \u5F53\u524D\u4E0D\u5728\u7EBF\uFF0C\u65E0\u6CD5\u66F4\u65B0` } };
|
|
33542
|
+
return { status: 200, body: { ok: true } };
|
|
33543
|
+
});
|
|
33535
33544
|
router.delete("/api/runtimes/:runtimeId", async (req) => {
|
|
33536
33545
|
const runtimeId = req.params["runtimeId"];
|
|
33537
33546
|
if (!runtimeId) return { status: 400, body: { error: "missing runtimeId" } };
|
|
@@ -49303,7 +49312,7 @@ async function preflightOasisAccess(job) {
|
|
|
49303
49312
|
}
|
|
49304
49313
|
}
|
|
49305
49314
|
var DaemonWsClient = class {
|
|
49306
|
-
constructor(serverUrl, daemonId, sessions, adapters = ["claude-code"], token, runtimes = adapters.map((kind) => ({ kind })), nodeName, reportRuntimes = true, preflight = true) {
|
|
49315
|
+
constructor(serverUrl, daemonId, sessions, adapters = ["claude-code"], token, runtimes = adapters.map((kind) => ({ kind })), nodeName, reportRuntimes = true, preflight = true, onUpdate) {
|
|
49307
49316
|
this.serverUrl = serverUrl;
|
|
49308
49317
|
this.daemonId = daemonId;
|
|
49309
49318
|
this.sessions = sessions;
|
|
@@ -49313,6 +49322,7 @@ var DaemonWsClient = class {
|
|
|
49313
49322
|
this.nodeName = nodeName;
|
|
49314
49323
|
this.reportRuntimes = reportRuntimes;
|
|
49315
49324
|
this.preflight = preflight;
|
|
49325
|
+
this.onUpdate = onUpdate;
|
|
49316
49326
|
}
|
|
49317
49327
|
ws = null;
|
|
49318
49328
|
pingTimer = null;
|
|
@@ -49409,6 +49419,12 @@ var DaemonWsClient = class {
|
|
|
49409
49419
|
case "ping":
|
|
49410
49420
|
this.send({ type: "pong" });
|
|
49411
49421
|
break;
|
|
49422
|
+
case "update": {
|
|
49423
|
+
log2("[node-cli]", "\u2190 update\uFF1A\u62C9\u53D6\u6700\u65B0\u7248\u672C\u5E76\u91CD\u542F");
|
|
49424
|
+
if (this.onUpdate) this.onUpdate();
|
|
49425
|
+
else log2("[node-cli]", " update \u5FFD\u7565\uFF1A\u672C\u8FDB\u7A0B\u672A\u6CE8\u5165\u81EA\u66F4\u65B0\u903B\u8F91\uFF08\u975E node-daemon \u6258\u7BA1\uFF1F\uFF09");
|
|
49426
|
+
break;
|
|
49427
|
+
}
|
|
49412
49428
|
}
|
|
49413
49429
|
}
|
|
49414
49430
|
send(msg) {
|
|
@@ -49517,7 +49533,7 @@ async function startNode(opts) {
|
|
|
49517
49533
|
claude
|
|
49518
49534
|
)
|
|
49519
49535
|
);
|
|
49520
|
-
const client = new DaemonWsClient(opts.serverUrl, opts.nodeId, sessions, adapters, opts.token, runtimes, opts.nodeName, opts.reportRuntimes ?? false);
|
|
49536
|
+
const client = new DaemonWsClient(opts.serverUrl, opts.nodeId, sessions, adapters, opts.token, runtimes, opts.nodeName, opts.reportRuntimes ?? false, true, opts.onUpdate);
|
|
49521
49537
|
console.log(`[oasis node] ${opts.nodeId} \u2192 ${opts.serverUrl}`);
|
|
49522
49538
|
client.start();
|
|
49523
49539
|
await new Promise((resolve3) => {
|
|
@@ -50974,6 +50990,7 @@ var PID_FILE = path13.join(OASIS_DIR, "node.pid");
|
|
|
50974
50990
|
var BIN_FILE = path13.join(OASIS_DIR, "bin", "oasis.js");
|
|
50975
50991
|
var LOCAL_BIN = path13.join(os8.homedir(), ".local", "bin", "oasis");
|
|
50976
50992
|
var LOG_FILE = path13.join(OASIS_DIR, "node.log");
|
|
50993
|
+
var PKG_NAME = "oasis_test";
|
|
50977
50994
|
var parseFlags = (argv) => {
|
|
50978
50995
|
const flags = /* @__PURE__ */ new Map();
|
|
50979
50996
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -51102,6 +51119,14 @@ function stopDaemon() {
|
|
|
51102
51119
|
} catch {
|
|
51103
51120
|
}
|
|
51104
51121
|
}
|
|
51122
|
+
function selfUpdate() {
|
|
51123
|
+
const cfg = readConfig();
|
|
51124
|
+
if (!cfg?.serverUrl) throw new Error("no config \u2014 run `oasis start` first");
|
|
51125
|
+
const args = ["-y", `${PKG_NAME}@latest`, "start", "--server-ws", cfg.serverUrl, ...cfg.name ? ["--name", cfg.name] : []];
|
|
51126
|
+
const log3 = fs16.openSync(LOG_FILE, "a");
|
|
51127
|
+
const child = (0, import_node_child_process12.spawn)("npx", args, { detached: true, stdio: ["ignore", log3, log3] });
|
|
51128
|
+
child.unref();
|
|
51129
|
+
}
|
|
51105
51130
|
void (async () => {
|
|
51106
51131
|
const [, , cmd] = process.argv;
|
|
51107
51132
|
const flags = parseFlags(process.argv.slice(3));
|
|
@@ -51146,7 +51171,14 @@ void (async () => {
|
|
|
51146
51171
|
process.exit(1);
|
|
51147
51172
|
})(),
|
|
51148
51173
|
nodeName: cfg.name ?? cfg.nodeId,
|
|
51149
|
-
reportRuntimes
|
|
51174
|
+
reportRuntimes,
|
|
51175
|
+
onUpdate: () => {
|
|
51176
|
+
try {
|
|
51177
|
+
selfUpdate();
|
|
51178
|
+
} catch (e) {
|
|
51179
|
+
console.error("[oasis] self-update failed:", String(e));
|
|
51180
|
+
}
|
|
51181
|
+
}
|
|
51150
51182
|
});
|
|
51151
51183
|
return;
|
|
51152
51184
|
}
|
|
@@ -51161,19 +51193,20 @@ void (async () => {
|
|
|
51161
51193
|
let nodeId = serverChanged ? void 0 : prev?.nodeId;
|
|
51162
51194
|
let token = serverChanged ? flags.get("token") ?? process.env["OASIS_NODE_TOKEN"] : flags.get("token") ?? process.env["OASIS_NODE_TOKEN"] ?? prev?.token;
|
|
51163
51195
|
const enrollToken = flags.get("enroll-token") ?? process.env["OASIS_ENROLL_TOKEN"];
|
|
51164
|
-
|
|
51165
|
-
|
|
51166
|
-
token = prev.token;
|
|
51167
|
-
} else if (enrollToken) {
|
|
51196
|
+
const derivedNodeId = resolveNodeId();
|
|
51197
|
+
if (enrollToken) {
|
|
51168
51198
|
const res = await fetch(`${httpBase(serverUrl)}/api/nodes/exchange`, {
|
|
51169
51199
|
method: "POST",
|
|
51170
51200
|
headers: { "content-type": "application/json" },
|
|
51171
|
-
body: JSON.stringify({ enrollToken, hostname: os8.hostname() })
|
|
51201
|
+
body: JSON.stringify({ enrollToken, nodeId: derivedNodeId, hostname: os8.hostname() })
|
|
51172
51202
|
});
|
|
51173
51203
|
if (!res.ok) throw new Error(`enroll token exchange failed: HTTP ${res.status}`);
|
|
51174
51204
|
const body = await res.json();
|
|
51175
51205
|
token = body.token;
|
|
51176
51206
|
nodeId = body.nodeId;
|
|
51207
|
+
} else if (prev?.nodeId && prev?.token && !serverChanged) {
|
|
51208
|
+
nodeId = prev.nodeId;
|
|
51209
|
+
token = prev.token;
|
|
51177
51210
|
}
|
|
51178
51211
|
if (!token || !nodeId) {
|
|
51179
51212
|
console.error("Usage: oasis start --server-ws <wss://...> (--enroll-token <ent_...> | --token <ont_...>) [--name <name>]");
|
|
@@ -51207,6 +51240,16 @@ void (async () => {
|
|
|
51207
51240
|
console.log(`\u2713 restarted (PID ${pid})`);
|
|
51208
51241
|
return;
|
|
51209
51242
|
}
|
|
51243
|
+
if (cmd === "update") {
|
|
51244
|
+
if (!readConfig()?.serverUrl) {
|
|
51245
|
+
console.error("no config \u2014 run `oasis start` first");
|
|
51246
|
+
process.exit(1);
|
|
51247
|
+
}
|
|
51248
|
+
console.log(`\u2192 \u66F4\u65B0 ${PKG_NAME} \u5230\u6700\u65B0\u7248\u672C\u5E76\u91CD\u542F\u8282\u70B9\u2026`);
|
|
51249
|
+
selfUpdate();
|
|
51250
|
+
console.log(`\u2713 \u66F4\u65B0\u5DF2\u89E6\u53D1\uFF08\u540E\u53F0\u62C9\u53D6 ${PKG_NAME}@latest \u5E76\u91CD\u542F\uFF09\uFF1B\u67E5\u770B\u65E5\u5FD7\uFF1Atail -f ${LOG_FILE}`);
|
|
51251
|
+
return;
|
|
51252
|
+
}
|
|
51210
51253
|
if (cmd === "status") {
|
|
51211
51254
|
const pid = readPid();
|
|
51212
51255
|
const cfg = readConfig();
|