@aidotnet/astra-gate 0.14.3101 → 0.14.3103
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 +141 -24
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ function adminHeaders(mutating, runtimeToken) {
|
|
|
36
36
|
return headers;
|
|
37
37
|
}
|
|
38
38
|
async function apiRequest(options) {
|
|
39
|
-
const { base, path:
|
|
39
|
+
const { base, path: path15, method = "GET", body, runtimeToken, timeoutMs = 1e4 } = options;
|
|
40
40
|
const doFetch = options.fetchImpl ?? globalThis.fetch;
|
|
41
41
|
if (!doFetch) {
|
|
42
42
|
throw new AstraError("fetch is unavailable. The Astra CLI requires Node.js 18+.");
|
|
@@ -46,7 +46,7 @@ async function apiRequest(options) {
|
|
|
46
46
|
if (body !== void 0) headers["Content-Type"] = "application/json";
|
|
47
47
|
let response;
|
|
48
48
|
try {
|
|
49
|
-
response = await doFetch(base +
|
|
49
|
+
response = await doFetch(base + path15, {
|
|
50
50
|
method,
|
|
51
51
|
headers,
|
|
52
52
|
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
@@ -1313,7 +1313,7 @@ import { fileURLToPath } from "url";
|
|
|
1313
1313
|
// package.json
|
|
1314
1314
|
var package_default = {
|
|
1315
1315
|
name: "@aidotnet/astra-gate",
|
|
1316
|
-
version: "0.14.
|
|
1316
|
+
version: "0.14.3103",
|
|
1317
1317
|
description: "Astra \u2014 a local AI gateway. Install, start, stop and manage the astra-server from the terminal.",
|
|
1318
1318
|
license: "MIT",
|
|
1319
1319
|
type: "module",
|
|
@@ -1344,12 +1344,12 @@ var package_default = {
|
|
|
1344
1344
|
commander: "^12.1.0"
|
|
1345
1345
|
},
|
|
1346
1346
|
optionalDependencies: {
|
|
1347
|
-
"@aidotnet/server-darwin-arm64": "0.14.
|
|
1348
|
-
"@aidotnet/server-darwin-x64": "0.14.
|
|
1349
|
-
"@aidotnet/server-linux-arm64": "0.14.
|
|
1350
|
-
"@aidotnet/server-linux-x64": "0.14.
|
|
1351
|
-
"@aidotnet/server-win32-arm64": "0.14.
|
|
1352
|
-
"@aidotnet/server-win32-x64": "0.14.
|
|
1347
|
+
"@aidotnet/server-darwin-arm64": "0.14.3103",
|
|
1348
|
+
"@aidotnet/server-darwin-x64": "0.14.3103",
|
|
1349
|
+
"@aidotnet/server-linux-arm64": "0.14.3103",
|
|
1350
|
+
"@aidotnet/server-linux-x64": "0.14.3103",
|
|
1351
|
+
"@aidotnet/server-win32-arm64": "0.14.3103",
|
|
1352
|
+
"@aidotnet/server-win32-x64": "0.14.3103"
|
|
1353
1353
|
},
|
|
1354
1354
|
devDependencies: {
|
|
1355
1355
|
"@aidotnet/update-core": "workspace:*",
|
|
@@ -2406,12 +2406,15 @@ async function runUninstall(opts) {
|
|
|
2406
2406
|
}
|
|
2407
2407
|
|
|
2408
2408
|
// src/commands/admin.ts
|
|
2409
|
-
|
|
2409
|
+
import { existsSync } from "fs";
|
|
2410
|
+
import { chmod, readFile, stat, writeFile } from "fs/promises";
|
|
2411
|
+
import path13 from "path";
|
|
2412
|
+
async function api(path15, options = {}) {
|
|
2410
2413
|
const { base, runtime, started } = await ensureServerRunning();
|
|
2411
2414
|
if (started) console.log("Server was not running \u2014 started it in the background.");
|
|
2412
2415
|
return apiRequest({
|
|
2413
2416
|
base,
|
|
2414
|
-
path:
|
|
2417
|
+
path: path15,
|
|
2415
2418
|
method: options.method ?? "GET",
|
|
2416
2419
|
body: options.body,
|
|
2417
2420
|
runtimeToken: runtime?.runtimeToken
|
|
@@ -2674,6 +2677,116 @@ async function runProviderImport(opts) {
|
|
|
2674
2677
|
for (const a of result.added) success(`Imported: ${a.name} (id: ${a.id}).`);
|
|
2675
2678
|
for (const k of result.skipped) console.log(`Skipped ${k.ref}: ${SKIP_TEXT[k.reason] ?? k.reason}`);
|
|
2676
2679
|
}
|
|
2680
|
+
var BACKUP_PASSPHRASE_ENV = "ASTRA_BACKUP_PASSPHRASE";
|
|
2681
|
+
var BACKUP_MAX_BYTES = 32 * 1024 * 1024;
|
|
2682
|
+
async function readBackupPassphrase(question) {
|
|
2683
|
+
const fromEnv = process.env[BACKUP_PASSPHRASE_ENV];
|
|
2684
|
+
if (fromEnv) return fromEnv;
|
|
2685
|
+
const entered = await promptHidden(question);
|
|
2686
|
+
if (!entered) throw new AstraError("No passphrase given.", `Pipe it on stdin or set ${BACKUP_PASSPHRASE_ENV}.`);
|
|
2687
|
+
return entered;
|
|
2688
|
+
}
|
|
2689
|
+
function backupNote(r) {
|
|
2690
|
+
const notes = [];
|
|
2691
|
+
if (r.error) notes.push(r.error);
|
|
2692
|
+
if (r.status === "same" && r.existing) notes.push(`already added as "${r.existing.name}"`);
|
|
2693
|
+
if (r.status === "sameHost" && r.existing) notes.push(`same address as "${r.existing.name}"`);
|
|
2694
|
+
if (r.ignored.length > 0) notes.push(`ignores ${r.ignored.join(", ")}`);
|
|
2695
|
+
return notes.join("; ");
|
|
2696
|
+
}
|
|
2697
|
+
async function runProviderExport(opts) {
|
|
2698
|
+
const sealed = Boolean(opts.passphraseStdin) || Boolean(process.env[BACKUP_PASSPHRASE_ENV]);
|
|
2699
|
+
if (sealed && opts.includeKeys) {
|
|
2700
|
+
throw new AstraError("--include-keys and a passphrase exclude each other.", "Choose plaintext keys or an encrypted file, not both.");
|
|
2701
|
+
}
|
|
2702
|
+
const out = path13.resolve(opts.out ?? `astra-providers-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.json`);
|
|
2703
|
+
if (!opts.force && existsSync(out)) {
|
|
2704
|
+
throw new AstraError(`${out} already exists.`, "Pass --force to replace it, or choose another file with --out.");
|
|
2705
|
+
}
|
|
2706
|
+
const secrets = sealed ? "passphrase" : opts.includeKeys ? "plaintext" : "none";
|
|
2707
|
+
const passphrase = sealed ? await readBackupPassphrase("Passphrase for the backup: ") : void 0;
|
|
2708
|
+
const file = await api("/api/providers/backup/export", {
|
|
2709
|
+
method: "POST",
|
|
2710
|
+
body: { secrets, passphrase, ids: opts.id?.length ? opts.id : void 0 }
|
|
2711
|
+
});
|
|
2712
|
+
await writeFile(out, `${JSON.stringify(file, null, 2)}
|
|
2713
|
+
`, { mode: 384 });
|
|
2714
|
+
await chmod(out, 384);
|
|
2715
|
+
const count = file.providers?.length ?? 0;
|
|
2716
|
+
success(`Exported ${count} provider${count === 1 ? "" : "s"} to ${out}.`);
|
|
2717
|
+
if (secrets === "none") console.log("The file has no API keys; enter them again after importing.");
|
|
2718
|
+
else if (secrets === "passphrase") console.log("API keys are encrypted with your passphrase; it cannot be recovered if lost.");
|
|
2719
|
+
else console.log("Warning: API keys are in the file in plain text. Keep it where only you can read it.");
|
|
2720
|
+
}
|
|
2721
|
+
async function runProviderImportFile(file, opts) {
|
|
2722
|
+
const only = opts.only?.map((n) => Number(n));
|
|
2723
|
+
if (only?.length && !opts.yes) {
|
|
2724
|
+
throw new AstraError("--only needs --yes.", "Run without options first to see the row numbers, then add --yes.");
|
|
2725
|
+
}
|
|
2726
|
+
if (only?.some((n) => !Number.isInteger(n) || n < 0)) {
|
|
2727
|
+
throw new AstraError("--only takes the row numbers shown by the preview.");
|
|
2728
|
+
}
|
|
2729
|
+
const abs = path13.resolve(file);
|
|
2730
|
+
let doc;
|
|
2731
|
+
try {
|
|
2732
|
+
if ((await stat(abs)).size > BACKUP_MAX_BYTES) throw new AstraError(`${abs} is too large to be a provider backup.`);
|
|
2733
|
+
doc = JSON.parse(await readFile(abs, "utf8"));
|
|
2734
|
+
} catch (e) {
|
|
2735
|
+
if (e instanceof AstraError) throw e;
|
|
2736
|
+
throw new AstraError(`Cannot read ${abs} as a backup file.`, e instanceof Error ? e.message : void 0);
|
|
2737
|
+
}
|
|
2738
|
+
if (doc.format !== "astra-providers" || !Array.isArray(doc.providers)) {
|
|
2739
|
+
throw new AstraError(`${abs} is not an Astra provider backup file.`);
|
|
2740
|
+
}
|
|
2741
|
+
const passphrase = doc.secrets === "passphrase" ? await readBackupPassphrase("Passphrase of the backup: ") : void 0;
|
|
2742
|
+
const preview = await api("/api/providers/backup/preview", {
|
|
2743
|
+
method: "POST",
|
|
2744
|
+
body: { file: doc, passphrase }
|
|
2745
|
+
});
|
|
2746
|
+
printTable(
|
|
2747
|
+
preview.items.map((r) => [
|
|
2748
|
+
String(r.index),
|
|
2749
|
+
r.status,
|
|
2750
|
+
r.name,
|
|
2751
|
+
(r.endpoints ?? []).map((e) => `${e.protocol} ${e.baseUrl}`).join(" | "),
|
|
2752
|
+
r.hasKey ? r.keyMasked ?? "\u2022\u2022\u2022\u2022" : "-",
|
|
2753
|
+
String(r.modelCount),
|
|
2754
|
+
backupNote(r)
|
|
2755
|
+
]),
|
|
2756
|
+
["ROW", "STATUS", "NAME", "ENDPOINTS", "KEY", "MODELS", "NOTE"]
|
|
2757
|
+
);
|
|
2758
|
+
const importable = (r) => r.status === "new" || r.status === "sameHost";
|
|
2759
|
+
if (!opts.yes) {
|
|
2760
|
+
const fresh = preview.items.filter((r) => r.status === "new").length;
|
|
2761
|
+
console.log("");
|
|
2762
|
+
console.log(
|
|
2763
|
+
fresh > 0 ? `Nothing was changed. Run again with --yes to import the ${fresh} new entr${fresh === 1 ? "y" : "ies"}, or --yes --only <row>\u2026 to pick.` : "Nothing new to import."
|
|
2764
|
+
);
|
|
2765
|
+
return;
|
|
2766
|
+
}
|
|
2767
|
+
let indexes;
|
|
2768
|
+
if (only?.length) {
|
|
2769
|
+
indexes = [];
|
|
2770
|
+
for (const n of only) {
|
|
2771
|
+
const row = preview.items.find((r) => r.index === n);
|
|
2772
|
+
if (!row) throw new AstraError(`No row ${n} in this backup.`);
|
|
2773
|
+
if (!importable(row)) throw new AstraError(`Row ${n} cannot be imported (${row.status === "same" ? "already added" : backupNote(row) || row.status}).`);
|
|
2774
|
+
indexes.push(n);
|
|
2775
|
+
}
|
|
2776
|
+
} else {
|
|
2777
|
+
indexes = preview.items.filter((r) => r.status === "new").map((r) => r.index);
|
|
2778
|
+
}
|
|
2779
|
+
if (indexes.length === 0) {
|
|
2780
|
+
console.log("Nothing to import.");
|
|
2781
|
+
return;
|
|
2782
|
+
}
|
|
2783
|
+
const result = await api(
|
|
2784
|
+
"/api/providers/backup/import",
|
|
2785
|
+
{ method: "POST", body: { file: doc, passphrase, indexes } }
|
|
2786
|
+
);
|
|
2787
|
+
for (const a of result.added) success(`Imported: ${a.name} (id: ${a.id}).`);
|
|
2788
|
+
for (const k of result.skipped) console.log(`Skipped row ${k.index}: ${k.reason}`);
|
|
2789
|
+
}
|
|
2677
2790
|
|
|
2678
2791
|
// src/commands/config.ts
|
|
2679
2792
|
import { spawn as spawn8 } from "child_process";
|
|
@@ -2702,10 +2815,10 @@ async function runSetPassword() {
|
|
|
2702
2815
|
}
|
|
2703
2816
|
|
|
2704
2817
|
// src/commands/plugin.ts
|
|
2705
|
-
async function api2(
|
|
2818
|
+
async function api2(path15, method = "GET", body) {
|
|
2706
2819
|
const { base, runtime, started } = await ensureServerRunning();
|
|
2707
2820
|
if (started) console.log("Server was not running \u2014 started it in the background.");
|
|
2708
|
-
return apiRequest({ base, path:
|
|
2821
|
+
return apiRequest({ base, path: path15, method, body, runtimeToken: runtime?.runtimeToken, timeoutMs: 6e4 });
|
|
2709
2822
|
}
|
|
2710
2823
|
async function find(name) {
|
|
2711
2824
|
const { plugins } = await api2("/api/plugins");
|
|
@@ -2838,7 +2951,7 @@ async function runRestoreAll(opts) {
|
|
|
2838
2951
|
// src/commands/claude.ts
|
|
2839
2952
|
import fs16 from "fs";
|
|
2840
2953
|
import os6 from "os";
|
|
2841
|
-
import
|
|
2954
|
+
import path14 from "path";
|
|
2842
2955
|
import process5 from "process";
|
|
2843
2956
|
import { spawn as spawn10 } from "child_process";
|
|
2844
2957
|
var PREPARE_PATH = "/api/clients/claude-code/direct/prepare";
|
|
@@ -2954,9 +3067,9 @@ async function prepareLaunch(accountId) {
|
|
|
2954
3067
|
return validateLaunchResponse(response);
|
|
2955
3068
|
}
|
|
2956
3069
|
function claudeConfigDir(env, override) {
|
|
2957
|
-
if (override) return
|
|
3070
|
+
if (override) return path14.resolve(override);
|
|
2958
3071
|
const configured = env.CLAUDE_CONFIG_DIR?.trim();
|
|
2959
|
-
return configured ? configured :
|
|
3072
|
+
return configured ? configured : path14.join(os6.homedir(), ".claude");
|
|
2960
3073
|
}
|
|
2961
3074
|
function validateLaunchResponse(raw) {
|
|
2962
3075
|
if (!isPlainObject(raw)) throw invalidLaunch();
|
|
@@ -3023,24 +3136,24 @@ function assertNoSettingsConflicts(configDirectory, cwd) {
|
|
|
3023
3136
|
);
|
|
3024
3137
|
}
|
|
3025
3138
|
function settingsFilesToCheck(configDirectory, cwd) {
|
|
3026
|
-
const files = [
|
|
3139
|
+
const files = [path14.join(configDirectory, "settings.json")];
|
|
3027
3140
|
const root = findGitRoot(cwd);
|
|
3028
|
-
let dir =
|
|
3141
|
+
let dir = path14.resolve(cwd);
|
|
3029
3142
|
for (; ; ) {
|
|
3030
|
-
files.push(
|
|
3031
|
-
files.push(
|
|
3143
|
+
files.push(path14.join(dir, ".claude", "settings.json"));
|
|
3144
|
+
files.push(path14.join(dir, ".claude", "settings.local.json"));
|
|
3032
3145
|
if (root === null || dir === root) break;
|
|
3033
|
-
const parent =
|
|
3146
|
+
const parent = path14.dirname(dir);
|
|
3034
3147
|
if (parent === dir) break;
|
|
3035
3148
|
dir = parent;
|
|
3036
3149
|
}
|
|
3037
3150
|
return [...new Set(files)];
|
|
3038
3151
|
}
|
|
3039
3152
|
function findGitRoot(startDir) {
|
|
3040
|
-
let dir =
|
|
3153
|
+
let dir = path14.resolve(startDir);
|
|
3041
3154
|
for (; ; ) {
|
|
3042
|
-
if (fs16.existsSync(
|
|
3043
|
-
const parent =
|
|
3155
|
+
if (fs16.existsSync(path14.join(dir, ".git"))) return dir;
|
|
3156
|
+
const parent = path14.dirname(dir);
|
|
3044
3157
|
if (parent === dir) return null;
|
|
3045
3158
|
dir = parent;
|
|
3046
3159
|
}
|
|
@@ -3225,6 +3338,10 @@ provider.command("add").description("Add a provider from a template").requiredOp
|
|
|
3225
3338
|
(opts) => runProviderAdd(opts)
|
|
3226
3339
|
);
|
|
3227
3340
|
provider.command("import").description("Import providers from CC Switch, Alma, Claude Code, Codex or Magpie (lists only, unless --yes)").option("--from <source>", "Only this source: cc-switch | alma | claude-code | codex | magpie").option("--yes", "Import the new entries (or those named with --only)").option("--only <ref...>", "With --yes: import only these refs (see the listing)").action((opts) => runProviderImport(opts));
|
|
3341
|
+
provider.command("export").description("Export providers and their models to a backup file (no API keys unless asked)").option("--out <file>", "File to write (default: ./astra-providers-<date>.json)").option("--force", "Replace the file when it already exists").option("--include-keys", "Write API keys in plain text (this machine only)").option("--passphrase-stdin", "Encrypt API keys with a passphrase read from stdin (or ASTRA_BACKUP_PASSPHRASE)").option("--id <id...>", "Only these provider ids").action(
|
|
3342
|
+
(opts) => runProviderExport(opts)
|
|
3343
|
+
);
|
|
3344
|
+
provider.command("import-file <file>").description("Preview a backup file made by `provider export`, or with --yes import its providers").option("--yes", "Import the new entries (or those named with --only)").option("--only <row...>", "With --yes: import only these preview rows").action((file, opts) => runProviderImportFile(file, opts));
|
|
3228
3345
|
provider.command("remove").description("Remove a provider").argument("<id>", "Provider id").action((id) => runProviderRemove(id));
|
|
3229
3346
|
var plugin = program.command("plugin").alias("plugins").description("Manage plugins (magpie-compatible provider plugins, gateway middleware and clients)");
|
|
3230
3347
|
plugin.command("list").alias("ls").description("List installed plugins").option("--json", "Print JSON").action((opts) => runPluginList(opts));
|