@aidotnet/astra-gate 0.9.4 → 0.9.7

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 CHANGED
@@ -215,6 +215,11 @@ import process3 from "process";
215
215
  // ../packages/update-core/src/manifest.ts
216
216
  var DEFAULT_FEED_URL = "https://astra-gate.si/api/client-releases";
217
217
  var DEFAULT_CHANNEL = "stable";
218
+ var PREVIEW_CHANNEL = "preview";
219
+ function normalizeChannel(value) {
220
+ const v = (value ?? "").trim().toLowerCase();
221
+ return v === PREVIEW_CHANNEL || v === "beta" ? PREVIEW_CHANNEL : DEFAULT_CHANNEL;
222
+ }
218
223
  var UpdateFeedError = class extends Error {
219
224
  constructor(message) {
220
225
  super(message);
@@ -223,7 +228,7 @@ var UpdateFeedError = class extends Error {
223
228
  };
224
229
  async function fetchManifest(o = {}) {
225
230
  const feed = (o.feedUrl ?? DEFAULT_FEED_URL).trim();
226
- const channel = (o.channel ?? DEFAULT_CHANNEL).trim() || DEFAULT_CHANNEL;
231
+ const channel = normalizeChannel(o.channel);
227
232
  const url = `${feed.replace(/\/+$/, "")}/${channel}/latest.json`;
228
233
  const doFetch = o.fetchImpl ?? globalThis.fetch;
229
234
  if (!doFetch) throw new UpdateFeedError("fetch is unavailable (Node.js 18+ required).");
@@ -263,16 +268,35 @@ function parseVersion(v) {
263
268
  if (!m) return null;
264
269
  return [Number(m[1]), Number(m[2] ?? 0), Number(m[3] ?? 0)];
265
270
  }
266
- function isNewerVersion(candidate, current) {
267
- const c = parseVersion(candidate);
268
- const cur = parseVersion(current);
269
- if (!c || !cur) return false;
271
+ function prereleaseOf(v) {
272
+ const text = v.trim().split("+", 1)[0];
273
+ const dash = text.indexOf("-");
274
+ return dash === -1 ? [] : text.slice(dash + 1).split(".");
275
+ }
276
+ function compareVersions(a, b) {
277
+ const ca = parseVersion(a);
278
+ const cb = parseVersion(b);
279
+ if (!ca || !cb) return null;
270
280
  for (let i = 0; i < 3; i++) {
271
- const a = c[i];
272
- const b = cur[i];
273
- if (a !== b) return a > b;
274
- }
275
- return false;
281
+ if (ca[i] !== cb[i]) return ca[i] > cb[i] ? 1 : -1;
282
+ }
283
+ const pa = prereleaseOf(a);
284
+ const pb = prereleaseOf(b);
285
+ if (pa.length === 0 || pb.length === 0) return pb.length - pa.length;
286
+ for (let i = 0; i < Math.min(pa.length, pb.length); i++) {
287
+ const x = pa[i];
288
+ const y = pb[i];
289
+ if (x === y) continue;
290
+ const nx = /^\d+$/.test(x);
291
+ const ny = /^\d+$/.test(y);
292
+ if (nx && ny) return Number(x) > Number(y) ? 1 : -1;
293
+ if (nx !== ny) return nx ? -1 : 1;
294
+ return x > y ? 1 : -1;
295
+ }
296
+ return pa.length - pb.length;
297
+ }
298
+ function isNewerVersion(candidate, current) {
299
+ return (compareVersions(candidate, current) ?? 0) > 0;
276
300
  }
277
301
  function majorOf(v) {
278
302
  const m = /^\s*(\d+)(?:\.|$)/.exec(v ?? "");
@@ -802,7 +826,7 @@ async function applyServerUpdate(o) {
802
826
  log(`Could not update the web UI files: ${err instanceof Error ? err.message : String(err)}`);
803
827
  }
804
828
  await o.control.start();
805
- const reported = await o.control.probeVersion();
829
+ const reported = await probeRestartedVersion(o.control);
806
830
  if (reported !== o.manifest.version) {
807
831
  throw new UpdateError(
808
832
  `The server reports ${reported ?? "no version"} after the restart; expected ${o.manifest.version}.`
@@ -830,6 +854,16 @@ async function applyServerUpdate(o) {
830
854
  throw err instanceof UpdateError ? err : new UpdateError(message);
831
855
  }
832
856
  }
857
+ var RESTART_PROBE_TIMEOUT_MS = 3e4;
858
+ var RESTART_PROBE_INTERVAL_MS = 500;
859
+ async function probeRestartedVersion(control) {
860
+ const deadline = Date.now() + RESTART_PROBE_TIMEOUT_MS;
861
+ for (; ; ) {
862
+ const reported = await control.probeVersion().catch(() => null);
863
+ if (reported !== null || Date.now() >= deadline) return reported;
864
+ await new Promise((resolve) => setTimeout(resolve, RESTART_PROBE_INTERVAL_MS));
865
+ }
866
+ }
833
867
  async function rollback(o, previousInstall, backupPath, webRootSwapped, setState, log) {
834
868
  const restorePath = previousInstall?.serverPath ?? backupPath;
835
869
  try {
@@ -840,7 +874,7 @@ async function rollback(o, previousInstall, backupPath, webRootSwapped, setState
840
874
  log("Rolling back to the server bundled with the app");
841
875
  clearServerInfo(o.home, previousInstall);
842
876
  }
843
- if (await o.control.isRunning()) await o.control.stop();
877
+ await o.control.stop();
844
878
  const serverDir = updatePaths(o.home).serverDir;
845
879
  if (webRootSwapped) restoreManagedWebRoot(serverDir);
846
880
  restoreNativeCompanions(serverDir);
@@ -864,15 +898,17 @@ async function checkForServerUpdate(o) {
864
898
  return {
865
899
  availableVersion: status.available ?? null,
866
900
  notes: status.notes ?? null,
867
- source: "server"
901
+ source: "server",
902
+ channel: normalizeChannel(status.channel ?? o.channel)
868
903
  };
869
904
  }
870
905
  } catch {
871
906
  }
872
907
  }
908
+ const channel = normalizeChannel(o.channel);
873
909
  const manifest = await fetchManifest({
874
910
  feedUrl: o.feedUrl ?? DEFAULT_FEED_URL,
875
- channel: o.channel ?? DEFAULT_CHANNEL,
911
+ channel,
876
912
  timeoutMs: o.timeoutMs,
877
913
  fetchImpl: o.fetchImpl,
878
914
  userAgent: o.userAgent
@@ -881,6 +917,7 @@ async function checkForServerUpdate(o) {
881
917
  availableVersion: isNewerVersion(manifest.version, o.currentVersion) ? manifest.version : null,
882
918
  notes: manifest.notes ?? null,
883
919
  source: "feed",
920
+ channel,
884
921
  manifest
885
922
  };
886
923
  }
@@ -1238,7 +1275,7 @@ import { fileURLToPath } from "url";
1238
1275
  // package.json
1239
1276
  var package_default = {
1240
1277
  name: "@aidotnet/astra-gate",
1241
- version: "0.9.4",
1278
+ version: "0.9.7",
1242
1279
  description: "Astra \u2014 a local AI gateway. Install, start, stop and manage the astra-server from the terminal.",
1243
1280
  license: "MIT",
1244
1281
  type: "module",
@@ -1269,12 +1306,12 @@ var package_default = {
1269
1306
  commander: "^12.1.0"
1270
1307
  },
1271
1308
  optionalDependencies: {
1272
- "@aidotnet/server-darwin-arm64": "0.9.4",
1273
- "@aidotnet/server-darwin-x64": "0.9.4",
1274
- "@aidotnet/server-linux-arm64": "0.9.4",
1275
- "@aidotnet/server-linux-x64": "0.9.4",
1276
- "@aidotnet/server-win32-arm64": "0.9.4",
1277
- "@aidotnet/server-win32-x64": "0.9.4"
1309
+ "@aidotnet/server-darwin-arm64": "0.9.7",
1310
+ "@aidotnet/server-darwin-x64": "0.9.7",
1311
+ "@aidotnet/server-linux-arm64": "0.9.7",
1312
+ "@aidotnet/server-linux-x64": "0.9.7",
1313
+ "@aidotnet/server-win32-arm64": "0.9.7",
1314
+ "@aidotnet/server-win32-x64": "0.9.7"
1278
1315
  },
1279
1316
  devDependencies: {
1280
1317
  "@aidotnet/update-core": "workspace:*",
@@ -2005,9 +2042,9 @@ import { spawn as spawn6 } from "child_process";
2005
2042
  function usesShell2(command) {
2006
2043
  return process.platform === "win32" && command.endsWith(".cmd");
2007
2044
  }
2008
- async function npmInstallGlobal() {
2045
+ async function npmInstallGlobal(version) {
2009
2046
  const npm = locateNpm();
2010
- const full = [...npm.args, "install", "-g", `${PACKAGE_NAME}@latest`, "--no-audit", "--no-fund", "--loglevel", "error"];
2047
+ const full = [...npm.args, "install", "-g", `${PACKAGE_NAME}@${version}`, "--no-audit", "--no-fund", "--loglevel", "error"];
2011
2048
  return new Promise((resolve, reject) => {
2012
2049
  const child = spawn6(npm.command, full, {
2013
2050
  stdio: "inherit",
@@ -2134,13 +2171,14 @@ async function runUninstallClient() {
2134
2171
  }
2135
2172
  async function runUpdate(opts) {
2136
2173
  const home = astraHome();
2174
+ const channel = await resolveChannel(opts.channel);
2137
2175
  if (opts.check) {
2138
- await reportCheck();
2176
+ await reportCheck(channel, opts.channel !== void 0);
2139
2177
  return;
2140
2178
  }
2141
2179
  let manifest;
2142
2180
  try {
2143
- manifest = await fetchManifest({ userAgent: `Astra-CLI/${VERSION}` });
2181
+ manifest = await fetchManifest({ userAgent: `Astra-CLI/${VERSION}`, channel });
2144
2182
  } catch (err) {
2145
2183
  if (!opts.client) throw err;
2146
2184
  manifest = { version: VERSION };
@@ -2148,10 +2186,11 @@ async function runUpdate(opts) {
2148
2186
  if (!opts.client) {
2149
2187
  await updateServer(home, manifest, opts.retry ?? false);
2150
2188
  if (isNewerVersion(manifest.version, VERSION)) {
2151
- console.log(`Updating the Astra CLI (npm install -g ${PACKAGE_NAME}@latest)\u2026`);
2152
- const r = await npmInstallGlobal();
2189
+ const target = `${PACKAGE_NAME}@${manifest.version}`;
2190
+ console.log(`Updating the Astra CLI (npm install -g ${target})\u2026`);
2191
+ const r = await npmInstallGlobal(manifest.version);
2153
2192
  if (r.code !== 0) {
2154
- info(`npm install -g ${PACKAGE_NAME}@latest failed \u2014 the server is updated; run \`npm i -g ${PACKAGE_NAME}\` for the CLI.`);
2193
+ info(`npm install -g ${target} failed \u2014 the server is updated; run \`npm i -g ${target}\` for the CLI.`);
2155
2194
  } else {
2156
2195
  success("The new CLI version is used the next time you run `astra`.");
2157
2196
  }
@@ -2164,11 +2203,33 @@ async function runUpdate(opts) {
2164
2203
  await installDesktopAt(home, target);
2165
2204
  }
2166
2205
  }
2167
- async function reportCheck() {
2206
+ async function resolveChannel(explicit) {
2207
+ if (explicit !== void 0) {
2208
+ const value = explicit.trim().toLowerCase();
2209
+ if (value !== "stable" && value !== "preview") {
2210
+ throw new AstraError(`Unknown release channel '${explicit}' (use stable or preview).`);
2211
+ }
2212
+ return value;
2213
+ }
2214
+ const status = await serverStatus();
2215
+ if (!status.running || !status.base) return "stable";
2216
+ try {
2217
+ const s = await apiRequest({ base: status.base, path: "/api/update/status" });
2218
+ const channel = normalizeChannel(s.channel);
2219
+ if (channel === "preview") info("Preview updates are on (Settings \u2192 About); using the preview channel.");
2220
+ return channel;
2221
+ } catch {
2222
+ return "stable";
2223
+ }
2224
+ }
2225
+ async function reportCheck(channel, explicit) {
2168
2226
  const status = await serverStatus();
2169
2227
  const r = await checkForServerUpdate({
2170
2228
  currentVersion: VERSION,
2171
- baseUrl: status.running ? status.base ?? void 0 : void 0
2229
+ // The server answers for its own channel; an explicit --channel asks the feed directly.
2230
+ baseUrl: status.running && !explicit ? status.base ?? void 0 : void 0,
2231
+ channel,
2232
+ userAgent: `Astra-CLI/${VERSION}`
2172
2233
  });
2173
2234
  if (r.availableVersion) {
2174
2235
  console.log(`Update available: ${style.cyan(r.availableVersion)} (current ${VERSION}).`);
@@ -3105,8 +3166,8 @@ program.command("uninstall").description("Uninstall Astra (restore client config
3105
3166
  if (opts.desktop || opts.client) return runUninstallClient();
3106
3167
  return runUninstall({ purge: opts.purge });
3107
3168
  });
3108
- program.command("update").description("Update astra (and the desktop app when installed), then restart the server").option("--desktop", "Only update the desktop app").option("--client", "Alias of --desktop").option("--check", "Only check for updates, do not install").option("--retry", "Retry even after repeated update failures").action(
3109
- (opts) => runUpdate({ client: opts.desktop || opts.client, check: opts.check, retry: opts.retry })
3169
+ program.command("update").description("Update astra (and the desktop app when installed), then restart the server").option("--desktop", "Only update the desktop app").option("--client", "Alias of --desktop").option("--check", "Only check for updates, do not install").option("--retry", "Retry even after repeated update failures").option("--channel <channel>", "Release channel for this run: stable | preview (default: the server setting)").action(
3170
+ (opts) => runUpdate({ client: opts.desktop || opts.client, check: opts.check, retry: opts.retry, channel: opts.channel })
3110
3171
  );
3111
3172
  var client = program.command("client").description("Manage AI clients (Codex, Claude Code, \u2026)");
3112
3173
  client.command("list").description("List clients and their status").action(() => runClientList());