astragate 0.9.3 → 0.9.6
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 +131 -45
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
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
|
|
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
|
|
267
|
-
const
|
|
268
|
-
const
|
|
269
|
-
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return
|
|
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
|
|
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
|
-
|
|
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
|
|
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: "astragate",
|
|
1241
|
-
version: "0.9.
|
|
1278
|
+
version: "0.9.6",
|
|
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.
|
|
1273
|
-
"@aidotnet/server-darwin-x64": "0.9.
|
|
1274
|
-
"@aidotnet/server-linux-arm64": "0.9.
|
|
1275
|
-
"@aidotnet/server-linux-x64": "0.9.
|
|
1276
|
-
"@aidotnet/server-win32-arm64": "0.9.
|
|
1277
|
-
"@aidotnet/server-win32-x64": "0.9.
|
|
1309
|
+
"@aidotnet/server-darwin-arm64": "0.9.6",
|
|
1310
|
+
"@aidotnet/server-darwin-x64": "0.9.6",
|
|
1311
|
+
"@aidotnet/server-linux-arm64": "0.9.6",
|
|
1312
|
+
"@aidotnet/server-linux-x64": "0.9.6",
|
|
1313
|
+
"@aidotnet/server-win32-arm64": "0.9.6",
|
|
1314
|
+
"@aidotnet/server-win32-x64": "0.9.6"
|
|
1278
1315
|
},
|
|
1279
1316
|
devDependencies: {
|
|
1280
1317
|
"@aidotnet/update-core": "workspace:*",
|
|
@@ -1786,6 +1823,8 @@ import os3 from "os";
|
|
|
1786
1823
|
import path12 from "path";
|
|
1787
1824
|
var LAUNCHD_LABEL = "io.astra.server";
|
|
1788
1825
|
var SYSTEMD_UNIT_NAME = "astra.service";
|
|
1826
|
+
var RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
1827
|
+
var RUN_VALUE_NAME = "Astra Server";
|
|
1789
1828
|
var SCHTASKS_TASK_NAME = "Astra Server";
|
|
1790
1829
|
function xmlEscape(s) {
|
|
1791
1830
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
@@ -1840,12 +1879,17 @@ RestartSec=3
|
|
|
1840
1879
|
WantedBy=default.target
|
|
1841
1880
|
`;
|
|
1842
1881
|
}
|
|
1843
|
-
function
|
|
1844
|
-
|
|
1845
|
-
|
|
1882
|
+
function windowsCommandLine(argv) {
|
|
1883
|
+
return argv.map((a, i) => i === 0 || a === "" || /[\s"]/.test(a) ? `"${a.replace(/"/g, '\\"')}"` : a).join(" ");
|
|
1884
|
+
}
|
|
1885
|
+
function regAddArgs(argv) {
|
|
1886
|
+
return ["add", RUN_KEY, "/v", RUN_VALUE_NAME, "/t", "REG_SZ", "/d", windowsCommandLine(argv), "/f"];
|
|
1887
|
+
}
|
|
1888
|
+
function regDeleteArgs() {
|
|
1889
|
+
return ["delete", RUN_KEY, "/v", RUN_VALUE_NAME, "/f"];
|
|
1846
1890
|
}
|
|
1847
|
-
function
|
|
1848
|
-
return ["
|
|
1891
|
+
function regQueryArgs() {
|
|
1892
|
+
return ["query", RUN_KEY, "/v", RUN_VALUE_NAME];
|
|
1849
1893
|
}
|
|
1850
1894
|
function schtasksDeleteArgs() {
|
|
1851
1895
|
return ["/Delete", "/F", "/TN", SCHTASKS_TASK_NAME];
|
|
@@ -1911,21 +1955,39 @@ async function autostartStatusLinux(home = os3.homedir()) {
|
|
|
1911
1955
|
const r = await exec(["systemctl", "--user", "is-enabled", SYSTEMD_UNIT_NAME]).catch(() => null);
|
|
1912
1956
|
return r !== null && r.code === 0 && r.stdout.trim() === "enabled" ? "enabled" : "disabled";
|
|
1913
1957
|
}
|
|
1958
|
+
async function legacyTaskExists() {
|
|
1959
|
+
const r = await exec(["schtasks", ...schtasksQueryArgs()]).catch(() => null);
|
|
1960
|
+
return r !== null && r.code === 0;
|
|
1961
|
+
}
|
|
1962
|
+
async function removeLegacyTask() {
|
|
1963
|
+
if (!await legacyTaskExists()) return true;
|
|
1964
|
+
await exec(["schtasks", ...schtasksDeleteArgs()]).catch(() => void 0);
|
|
1965
|
+
return !await legacyTaskExists();
|
|
1966
|
+
}
|
|
1914
1967
|
async function enableAutostartWindows(argv) {
|
|
1915
|
-
const r = await exec(["
|
|
1968
|
+
const r = await exec(["reg", ...regAddArgs(argv)]);
|
|
1916
1969
|
if (r.code !== 0) {
|
|
1917
|
-
throw new AstraError("
|
|
1970
|
+
throw new AstraError("reg add failed.", r.stderr.trim() || void 0);
|
|
1918
1971
|
}
|
|
1972
|
+
await removeLegacyTask();
|
|
1919
1973
|
}
|
|
1920
1974
|
async function disableAutostartWindows() {
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1975
|
+
await exec(["reg", ...regDeleteArgs()]).catch(() => void 0);
|
|
1976
|
+
const still = await exec(["reg", ...regQueryArgs()]);
|
|
1977
|
+
if (still.code === 0) {
|
|
1978
|
+
throw new AstraError("reg delete failed.", `Remove the "${RUN_VALUE_NAME}" value under ${RUN_KEY}.`);
|
|
1979
|
+
}
|
|
1980
|
+
if (!await removeLegacyTask()) {
|
|
1981
|
+
throw new AstraError(
|
|
1982
|
+
`The scheduled task "${SCHTASKS_TASK_NAME}" could not be removed.`,
|
|
1983
|
+
`Run from an administrator prompt: schtasks /Delete /F /TN "${SCHTASKS_TASK_NAME}"`
|
|
1984
|
+
);
|
|
1924
1985
|
}
|
|
1925
1986
|
}
|
|
1926
1987
|
async function autostartStatusWindows() {
|
|
1927
|
-
const r = await exec(["
|
|
1928
|
-
|
|
1988
|
+
const r = await exec(["reg", ...regQueryArgs()]);
|
|
1989
|
+
if (r.code === 0) return "enabled";
|
|
1990
|
+
return await legacyTaskExists() ? "enabled" : "disabled";
|
|
1929
1991
|
}
|
|
1930
1992
|
|
|
1931
1993
|
// src/commands/autostart.ts
|
|
@@ -1980,9 +2042,9 @@ import { spawn as spawn6 } from "child_process";
|
|
|
1980
2042
|
function usesShell2(command) {
|
|
1981
2043
|
return process.platform === "win32" && command.endsWith(".cmd");
|
|
1982
2044
|
}
|
|
1983
|
-
async function npmInstallGlobal() {
|
|
2045
|
+
async function npmInstallGlobal(version) {
|
|
1984
2046
|
const npm = locateNpm();
|
|
1985
|
-
const full = [...npm.args, "install", "-g", `${PACKAGE_NAME}
|
|
2047
|
+
const full = [...npm.args, "install", "-g", `${PACKAGE_NAME}@${version}`, "--no-audit", "--no-fund", "--loglevel", "error"];
|
|
1986
2048
|
return new Promise((resolve, reject) => {
|
|
1987
2049
|
const child = spawn6(npm.command, full, {
|
|
1988
2050
|
stdio: "inherit",
|
|
@@ -2109,13 +2171,14 @@ async function runUninstallClient() {
|
|
|
2109
2171
|
}
|
|
2110
2172
|
async function runUpdate(opts) {
|
|
2111
2173
|
const home = astraHome();
|
|
2174
|
+
const channel = await resolveChannel(opts.channel);
|
|
2112
2175
|
if (opts.check) {
|
|
2113
|
-
await reportCheck();
|
|
2176
|
+
await reportCheck(channel, opts.channel !== void 0);
|
|
2114
2177
|
return;
|
|
2115
2178
|
}
|
|
2116
2179
|
let manifest;
|
|
2117
2180
|
try {
|
|
2118
|
-
manifest = await fetchManifest({ userAgent: `Astra-CLI/${VERSION}
|
|
2181
|
+
manifest = await fetchManifest({ userAgent: `Astra-CLI/${VERSION}`, channel });
|
|
2119
2182
|
} catch (err) {
|
|
2120
2183
|
if (!opts.client) throw err;
|
|
2121
2184
|
manifest = { version: VERSION };
|
|
@@ -2123,10 +2186,11 @@ async function runUpdate(opts) {
|
|
|
2123
2186
|
if (!opts.client) {
|
|
2124
2187
|
await updateServer(home, manifest, opts.retry ?? false);
|
|
2125
2188
|
if (isNewerVersion(manifest.version, VERSION)) {
|
|
2126
|
-
|
|
2127
|
-
|
|
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);
|
|
2128
2192
|
if (r.code !== 0) {
|
|
2129
|
-
info(`npm install -g ${
|
|
2193
|
+
info(`npm install -g ${target} failed \u2014 the server is updated; run \`npm i -g ${target}\` for the CLI.`);
|
|
2130
2194
|
} else {
|
|
2131
2195
|
success("The new CLI version is used the next time you run `astra`.");
|
|
2132
2196
|
}
|
|
@@ -2139,11 +2203,33 @@ async function runUpdate(opts) {
|
|
|
2139
2203
|
await installDesktopAt(home, target);
|
|
2140
2204
|
}
|
|
2141
2205
|
}
|
|
2142
|
-
async function
|
|
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) {
|
|
2143
2226
|
const status = await serverStatus();
|
|
2144
2227
|
const r = await checkForServerUpdate({
|
|
2145
2228
|
currentVersion: VERSION,
|
|
2146
|
-
|
|
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}`
|
|
2147
2233
|
});
|
|
2148
2234
|
if (r.availableVersion) {
|
|
2149
2235
|
console.log(`Update available: ${style.cyan(r.availableVersion)} (current ${VERSION}).`);
|
|
@@ -3070,7 +3156,7 @@ program.command("status").description("Show whether the server is running and it
|
|
|
3070
3156
|
program.command("logs").description("Show recent server logs").option("-f, --follow", "Keep printing new log output").action((opts) => runLogs(opts));
|
|
3071
3157
|
program.command("open").description("Open the Astra web UI in the default browser").action(() => runOpen());
|
|
3072
3158
|
var autostart = program.command("autostart").description("Manage starting Astra at login");
|
|
3073
|
-
autostart.command("enable").description("Enable autostart (LaunchAgent / systemd --user /
|
|
3159
|
+
autostart.command("enable").description("Enable autostart (LaunchAgent / systemd --user / Run registry key)").action(() => runAutostart("enable"));
|
|
3074
3160
|
autostart.command("disable").description("Disable autostart").action(() => runAutostart("disable"));
|
|
3075
3161
|
autostart.command("status").description("Show whether autostart is enabled").action(() => runAutostart("status"));
|
|
3076
3162
|
program.command("install").description("Install optional Astra components").option("--desktop", "Install the Astra desktop app for this platform").option("--client", "Alias of --desktop").action(
|
|
@@ -3080,8 +3166,8 @@ program.command("uninstall").description("Uninstall Astra (restore client config
|
|
|
3080
3166
|
if (opts.desktop || opts.client) return runUninstallClient();
|
|
3081
3167
|
return runUninstall({ purge: opts.purge });
|
|
3082
3168
|
});
|
|
3083
|
-
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(
|
|
3084
|
-
(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 })
|
|
3085
3171
|
);
|
|
3086
3172
|
var client = program.command("client").description("Manage AI clients (Codex, Claude Code, \u2026)");
|
|
3087
3173
|
client.command("list").description("List clients and their status").action(() => runClientList());
|