oasis_test 0.1.16 → 0.1.18

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 (2) hide show
  1. package/dist/index.js +63 -3
  2. 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,32 @@ 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 startArgs = ["-y", `${PKG_NAME}@latest`, "start", "--server-ws", cfg.serverUrl, ...cfg.name ? ["--name", cfg.name] : []];
51126
+ const quoted = startArgs.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
51127
+ const inner = `sleep 2; npx ${quoted} >> '${LOG_FILE}' 2>&1`;
51128
+ const hasSystemd = process.platform === "linux" && (() => {
51129
+ try {
51130
+ (0, import_node_child_process12.execSync)("command -v systemd-run", { stdio: "ignore" });
51131
+ return true;
51132
+ } catch {
51133
+ return false;
51134
+ }
51135
+ })();
51136
+ if (hasSystemd) {
51137
+ const child = (0, import_node_child_process12.spawn)("systemd-run", ["--user", "--scope", "--quiet", "sh", "-c", inner], {
51138
+ detached: true,
51139
+ stdio: "ignore"
51140
+ });
51141
+ child.unref();
51142
+ } else {
51143
+ const log3 = fs16.openSync(LOG_FILE, "a");
51144
+ const child = (0, import_node_child_process12.spawn)("sh", ["-c", inner], { detached: true, stdio: ["ignore", log3, log3] });
51145
+ child.unref();
51146
+ }
51147
+ }
51105
51148
  void (async () => {
51106
51149
  const [, , cmd] = process.argv;
51107
51150
  const flags = parseFlags(process.argv.slice(3));
@@ -51146,7 +51189,14 @@ void (async () => {
51146
51189
  process.exit(1);
51147
51190
  })(),
51148
51191
  nodeName: cfg.name ?? cfg.nodeId,
51149
- reportRuntimes
51192
+ reportRuntimes,
51193
+ onUpdate: () => {
51194
+ try {
51195
+ selfUpdate();
51196
+ } catch (e) {
51197
+ console.error("[oasis] self-update failed:", String(e));
51198
+ }
51199
+ }
51150
51200
  });
51151
51201
  return;
51152
51202
  }
@@ -51208,6 +51258,16 @@ void (async () => {
51208
51258
  console.log(`\u2713 restarted (PID ${pid})`);
51209
51259
  return;
51210
51260
  }
51261
+ if (cmd === "update") {
51262
+ if (!readConfig()?.serverUrl) {
51263
+ console.error("no config \u2014 run `oasis start` first");
51264
+ process.exit(1);
51265
+ }
51266
+ console.log(`\u2192 \u66F4\u65B0 ${PKG_NAME} \u5230\u6700\u65B0\u7248\u672C\u5E76\u91CD\u542F\u8282\u70B9\u2026`);
51267
+ selfUpdate();
51268
+ 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}`);
51269
+ return;
51270
+ }
51211
51271
  if (cmd === "status") {
51212
51272
  const pid = readPid();
51213
51273
  const cfg = readConfig();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oasis_test",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "Oasis node daemon + CLI — background daemon, auto-start, full server CLI",
5
5
  "bin": {
6
6
  "oasis": "./dist/index.js"