@lunaroute/cli 0.5.0 → 0.6.1
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 +103 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Command, InvalidArgumentError, Option } from "commander";
|
|
5
5
|
|
|
6
6
|
// package.json
|
|
7
|
-
var version = "0.
|
|
7
|
+
var version = "0.6.1";
|
|
8
8
|
|
|
9
9
|
// src/login.ts
|
|
10
10
|
import { createServer } from "http";
|
|
@@ -442,6 +442,17 @@ function whoami(profile) {
|
|
|
442
442
|
console.log(` API: ${creds.api_url}`);
|
|
443
443
|
}
|
|
444
444
|
|
|
445
|
+
// src/commands/key.ts
|
|
446
|
+
function key(profile) {
|
|
447
|
+
const creds = loadProfile(profile);
|
|
448
|
+
if (!creds?.routing_key) {
|
|
449
|
+
console.error('Not logged in. Run "lunaroute login" to get started.');
|
|
450
|
+
process.exitCode = 1;
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
console.log(creds.routing_key);
|
|
454
|
+
}
|
|
455
|
+
|
|
445
456
|
// src/commands/logout.ts
|
|
446
457
|
function logout(profile) {
|
|
447
458
|
if (!loadProfile(profile)) {
|
|
@@ -458,7 +469,8 @@ var KeyRejectedError = class extends Error {
|
|
|
458
469
|
var NON_CHAT_CAPABILITIES = [
|
|
459
470
|
"image_generation",
|
|
460
471
|
"embeddings",
|
|
461
|
-
"rerank"
|
|
472
|
+
"rerank",
|
|
473
|
+
"systemone"
|
|
462
474
|
];
|
|
463
475
|
function isChatModel(m) {
|
|
464
476
|
for (const c of NON_CHAT_CAPABILITIES) {
|
|
@@ -466,14 +478,14 @@ function isChatModel(m) {
|
|
|
466
478
|
}
|
|
467
479
|
return true;
|
|
468
480
|
}
|
|
469
|
-
async function fetchModels(routingUrl,
|
|
481
|
+
async function fetchModels(routingUrl, key2, opts) {
|
|
470
482
|
const url = `${routingUrl}/v1/models`;
|
|
471
|
-
const headers =
|
|
483
|
+
const headers = key2 ? { Authorization: `Bearer ${key2}` } : {};
|
|
472
484
|
const res = await fetch(url, { method: "GET", headers, signal: opts?.signal });
|
|
473
485
|
if (!res.ok) {
|
|
474
486
|
if (res.status === 401) {
|
|
475
487
|
throw new KeyRejectedError(
|
|
476
|
-
|
|
488
|
+
key2 ? `the routing service rejected that key (HTTP 401) \u2014 check that you copied the whole lr_ key` : `the routing service requires a key for /v1/models (HTTP 401) \u2014 run "lunaroute login" or pass --key`
|
|
477
489
|
);
|
|
478
490
|
}
|
|
479
491
|
throw new Error(`failed to fetch models: HTTP ${res.status} from ${url}`);
|
|
@@ -504,6 +516,13 @@ import {
|
|
|
504
516
|
} from "fs";
|
|
505
517
|
import { dirname } from "path";
|
|
506
518
|
import { parseDocument } from "yaml";
|
|
519
|
+
|
|
520
|
+
// src/shell.ts
|
|
521
|
+
function shQuote(value) {
|
|
522
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// src/setup/apply.ts
|
|
507
526
|
function readExistingJson(path) {
|
|
508
527
|
if (!existsSync3(path)) return null;
|
|
509
528
|
const raw = readFileSync3(path, "utf8").trim();
|
|
@@ -571,9 +590,23 @@ ${nextStr}`);
|
|
|
571
590
|
const printed = plan.exports.filter((e) => !process.env[e.name]);
|
|
572
591
|
if (printed.length > 0) {
|
|
573
592
|
console.log("\n# Add these to your shell profile:");
|
|
593
|
+
let referencedKey = false;
|
|
574
594
|
for (const e of printed) {
|
|
575
|
-
|
|
576
|
-
|
|
595
|
+
if (e.value === "__KEY__") {
|
|
596
|
+
referencedKey = true;
|
|
597
|
+
const profileArg = opts.profile && opts.profile !== "default" ? ` -p ${shQuote(opts.profile)}` : "";
|
|
598
|
+
console.log(`export ${e.name}="$(lunaroute key${profileArg})"`);
|
|
599
|
+
} else {
|
|
600
|
+
console.log(`export ${e.name}=${e.value}`);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (referencedKey) {
|
|
604
|
+
console.log(
|
|
605
|
+
"# The line above shells out to 'lunaroute key' \u2014 install the CLI first: npm install -g @lunaroute/cli"
|
|
606
|
+
);
|
|
607
|
+
console.log(
|
|
608
|
+
"# For non-shell config (systemd Environment=, docker .env), run 'lunaroute key' once and paste the value."
|
|
609
|
+
);
|
|
577
610
|
}
|
|
578
611
|
}
|
|
579
612
|
for (const e of plan.exports) {
|
|
@@ -844,7 +877,7 @@ function providerPlan(ctx) {
|
|
|
844
877
|
]
|
|
845
878
|
};
|
|
846
879
|
}
|
|
847
|
-
function buildKeyPlan(
|
|
880
|
+
function buildKeyPlan(key2) {
|
|
848
881
|
return {
|
|
849
882
|
fileWrites: [
|
|
850
883
|
{
|
|
@@ -853,7 +886,7 @@ function buildKeyPlan(key) {
|
|
|
853
886
|
merge: (existing) => {
|
|
854
887
|
const obj = existing ?? {};
|
|
855
888
|
delete obj["lunaroute/"];
|
|
856
|
-
return { ...obj, lunaroute: { type: "api", key } };
|
|
889
|
+
return { ...obj, lunaroute: { type: "api", key: key2 } };
|
|
857
890
|
}
|
|
858
891
|
}
|
|
859
892
|
],
|
|
@@ -969,7 +1002,7 @@ function buildStaleProviderCleanupPlan() {
|
|
|
969
1002
|
};
|
|
970
1003
|
}
|
|
971
1004
|
var KEY_EXPIRES_MS = 10 * 365 * 24 * 60 * 60 * 1e3;
|
|
972
|
-
function buildKeyPlan2(
|
|
1005
|
+
function buildKeyPlan2(key2) {
|
|
973
1006
|
return {
|
|
974
1007
|
fileWrites: [
|
|
975
1008
|
{
|
|
@@ -979,7 +1012,7 @@ function buildKeyPlan2(key) {
|
|
|
979
1012
|
const obj = existing ?? {};
|
|
980
1013
|
return {
|
|
981
1014
|
...obj,
|
|
982
|
-
lunaroute: { type: "oauth", access:
|
|
1015
|
+
lunaroute: { type: "oauth", access: key2, refresh: "", expires: Date.now() + KEY_EXPIRES_MS }
|
|
983
1016
|
};
|
|
984
1017
|
}
|
|
985
1018
|
}
|
|
@@ -989,9 +1022,20 @@ function buildKeyPlan2(key) {
|
|
|
989
1022
|
};
|
|
990
1023
|
}
|
|
991
1024
|
|
|
1025
|
+
// src/setup/adapters/first-model.ts
|
|
1026
|
+
function requireFirstModel(ctx, harness) {
|
|
1027
|
+
const first = ctx.models[0]?.id;
|
|
1028
|
+
if (!first) {
|
|
1029
|
+
throw new Error(
|
|
1030
|
+
`no LunaRoute chat models in the catalog \u2014 nothing to configure for ${harness}`
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
1033
|
+
return first;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
992
1036
|
// src/setup/adapters/claudeCode.ts
|
|
993
1037
|
function buildPlan3(ctx) {
|
|
994
|
-
const firstModel = ctx
|
|
1038
|
+
const firstModel = requireFirstModel(ctx, "claude-code");
|
|
995
1039
|
return {
|
|
996
1040
|
fileWrites: [],
|
|
997
1041
|
exports: [
|
|
@@ -1046,7 +1090,7 @@ function validatedRoutingUrl(routingUrl) {
|
|
|
1046
1090
|
// src/setup/adapters/codex.ts
|
|
1047
1091
|
function buildPlan4(ctx) {
|
|
1048
1092
|
const base = validatedRoutingUrl(ctx.routingUrl);
|
|
1049
|
-
const model = ctx
|
|
1093
|
+
const model = requireFirstModel(ctx, "codex");
|
|
1050
1094
|
const contextWindow = ctx.models[0]?.context_window_tokens;
|
|
1051
1095
|
const lines = [`model = "${model}"`, 'model_provider = "lunaroute"'];
|
|
1052
1096
|
if (Number.isInteger(contextWindow) && (contextWindow ?? 0) > 0) {
|
|
@@ -1075,7 +1119,7 @@ function buildPlan4(ctx) {
|
|
|
1075
1119
|
|
|
1076
1120
|
// src/setup/adapters/copilotCli.ts
|
|
1077
1121
|
function buildPlan5(ctx) {
|
|
1078
|
-
const firstModel = ctx
|
|
1122
|
+
const firstModel = requireFirstModel(ctx, "copilot-cli");
|
|
1079
1123
|
return {
|
|
1080
1124
|
fileWrites: [],
|
|
1081
1125
|
exports: [
|
|
@@ -1109,8 +1153,8 @@ function buildPlan6(ctx) {
|
|
|
1109
1153
|
` Base URL: ${ctx.routingUrl}/v1`,
|
|
1110
1154
|
` Auth: header Authorization: Bearer $${ctx.keyEnvVar}`,
|
|
1111
1155
|
` Auth (alt): path ${ctx.routingUrl}/a/$${ctx.keyEnvVar}/v1`,
|
|
1112
|
-
` Sample model id: ${ctx.models[0]?.id ?? "
|
|
1113
|
-
` All models: ${ctx.models.map((m) => m.id).join(", ")}`
|
|
1156
|
+
` Sample model id: ${ctx.models[0]?.id ?? "(no chat models in the catalog yet)"}`,
|
|
1157
|
+
` All models: ${ctx.models.map((m) => m.id).join(", ") || "(none)"}`
|
|
1114
1158
|
]
|
|
1115
1159
|
};
|
|
1116
1160
|
}
|
|
@@ -1122,6 +1166,7 @@ function asRecord(v) {
|
|
|
1122
1166
|
function buildPlan7(ctx) {
|
|
1123
1167
|
const base = validatedRoutingUrl(ctx.routingUrl);
|
|
1124
1168
|
const models = ctx.models.map((m) => ({ id: m.id, name: m.id }));
|
|
1169
|
+
const primary = requireFirstModel(ctx, "openclaw");
|
|
1125
1170
|
return {
|
|
1126
1171
|
fileWrites: [
|
|
1127
1172
|
{
|
|
@@ -1159,7 +1204,7 @@ function buildPlan7(ctx) {
|
|
|
1159
1204
|
model: {
|
|
1160
1205
|
...model,
|
|
1161
1206
|
// Preserve an existing primary model, like OpenClaw onboarding.
|
|
1162
|
-
primary: model.primary ?? `lunaroute/${
|
|
1207
|
+
primary: model.primary ?? `lunaroute/${primary}`
|
|
1163
1208
|
}
|
|
1164
1209
|
}
|
|
1165
1210
|
}
|
|
@@ -1170,7 +1215,7 @@ function buildPlan7(ctx) {
|
|
|
1170
1215
|
exports: [{ name: ctx.keyEnvVar, value: "__KEY__" }],
|
|
1171
1216
|
notes: [
|
|
1172
1217
|
`
|
|
1173
|
-
openclaw: restart the gateway, then \`openclaw models list\` and \`openclaw models set lunaroute/${
|
|
1218
|
+
openclaw: restart the gateway, then \`openclaw models list\` and \`openclaw models set lunaroute/${primary}\` (only if you have no default model already). If lunaroute/* models do not appear in \`openclaw models list\`, check that models.mode is merge \u2014 setup preserves whatever mode you have.`
|
|
1174
1219
|
]
|
|
1175
1220
|
};
|
|
1176
1221
|
}
|
|
@@ -1253,11 +1298,11 @@ function ensureProviderRow(doc) {
|
|
|
1253
1298
|
seq.add(row);
|
|
1254
1299
|
return row;
|
|
1255
1300
|
}
|
|
1256
|
-
function ensureMap(doc, parent,
|
|
1257
|
-
const existing = parent.get(
|
|
1301
|
+
function ensureMap(doc, parent, key2) {
|
|
1302
|
+
const existing = parent.get(key2);
|
|
1258
1303
|
if (isMap(existing)) return existing;
|
|
1259
1304
|
const created = doc.createNode({});
|
|
1260
|
-
parent.set(
|
|
1305
|
+
parent.set(key2, created);
|
|
1261
1306
|
return created;
|
|
1262
1307
|
}
|
|
1263
1308
|
function mergeProvider(doc, provider) {
|
|
@@ -1348,7 +1393,7 @@ async function runSetup(harness, opts, deps = {
|
|
|
1348
1393
|
return 1;
|
|
1349
1394
|
}
|
|
1350
1395
|
if (opts.key && (opts.extension || opts.models)) {
|
|
1351
|
-
console.error("--key runs the full
|
|
1396
|
+
console.error("--key runs the full setup flow for every harness; drop --extension/--models.");
|
|
1352
1397
|
return 1;
|
|
1353
1398
|
}
|
|
1354
1399
|
const adapter = ADAPTERS[harness];
|
|
@@ -1417,7 +1462,7 @@ async function runSetup(harness, opts, deps = {
|
|
|
1417
1462
|
models = await fetchModels(routingUrl, creds.routing_key);
|
|
1418
1463
|
} catch (err) {
|
|
1419
1464
|
console.error(
|
|
1420
|
-
`Could not fetch the model catalog (${err instanceof Error ? err.message : err})
|
|
1465
|
+
`Could not fetch the model catalog (${err instanceof Error ? err.message : err}).`
|
|
1421
1466
|
);
|
|
1422
1467
|
models = [];
|
|
1423
1468
|
}
|
|
@@ -1435,7 +1480,7 @@ async function runSetup(harness, opts, deps = {
|
|
|
1435
1480
|
return 1;
|
|
1436
1481
|
}
|
|
1437
1482
|
try {
|
|
1438
|
-
const summary = await applyPlan(plan, { print: opts.print, key: creds.routing_key });
|
|
1483
|
+
const summary = await applyPlan(plan, { print: opts.print, key: creds.routing_key, profile: opts.profile });
|
|
1439
1484
|
if (!opts.print && summary.written.length > 0) {
|
|
1440
1485
|
console.log(`
|
|
1441
1486
|
Wrote: ${summary.written.join(", ")}`);
|
|
@@ -1498,7 +1543,8 @@ async function runPiSetup(opts, stored, routingUrl, deps) {
|
|
|
1498
1543
|
return applyPiModels(
|
|
1499
1544
|
creds2,
|
|
1500
1545
|
routingUrl,
|
|
1501
|
-
await deps.confirm("Merge LunaRoute provider into ~/.pi/agent/models.json (backup kept, other providers preserved)?", { yes: opts.yes })
|
|
1546
|
+
await deps.confirm("Merge LunaRoute provider into ~/.pi/agent/models.json (backup kept, other providers preserved)?", { yes: opts.yes }),
|
|
1547
|
+
opts.profile
|
|
1502
1548
|
);
|
|
1503
1549
|
}
|
|
1504
1550
|
const code = await installPiPackages(deps);
|
|
@@ -1512,7 +1558,7 @@ async function runPiSetup(opts, stored, routingUrl, deps) {
|
|
|
1512
1558
|
return 0;
|
|
1513
1559
|
}
|
|
1514
1560
|
const plan = combinePlans(buildKeyPlan2(creds2.routing_key), stalePiProviderExists() ? buildStaleProviderCleanupPlan() : null);
|
|
1515
|
-
const wcode = await applyAndReport(plan, creds2.routing_key, true);
|
|
1561
|
+
const wcode = await applyAndReport(plan, creds2.routing_key, true, opts.profile);
|
|
1516
1562
|
if (wcode !== 0) return wcode;
|
|
1517
1563
|
console.log("\nDone. Start pi \u2014 it is signed in. Pick a model with /model.");
|
|
1518
1564
|
return 0;
|
|
@@ -1535,7 +1581,8 @@ async function runPiSetup(opts, stored, routingUrl, deps) {
|
|
|
1535
1581
|
return applyPiModels(
|
|
1536
1582
|
creds2,
|
|
1537
1583
|
routingUrl,
|
|
1538
|
-
await deps.confirm("Merge LunaRoute provider into ~/.pi/agent/models.json (backup kept, other providers preserved)?", { yes: opts.yes })
|
|
1584
|
+
await deps.confirm("Merge LunaRoute provider into ~/.pi/agent/models.json (backup kept, other providers preserved)?", { yes: opts.yes }),
|
|
1585
|
+
opts.profile
|
|
1539
1586
|
);
|
|
1540
1587
|
}
|
|
1541
1588
|
if (await deps.confirm(
|
|
@@ -1551,7 +1598,8 @@ async function runPiSetup(opts, stored, routingUrl, deps) {
|
|
|
1551
1598
|
routingUrl,
|
|
1552
1599
|
await deps.confirm("Merge LunaRoute provider into ~/.pi/agent/models.json (backup kept, other providers preserved)?", {
|
|
1553
1600
|
yes: opts.yes
|
|
1554
|
-
})
|
|
1601
|
+
}),
|
|
1602
|
+
opts.profile
|
|
1555
1603
|
);
|
|
1556
1604
|
} catch (err) {
|
|
1557
1605
|
if (err instanceof NonInteractiveTerminalError) {
|
|
@@ -1569,7 +1617,7 @@ async function runHermesSetup(creds, routingUrl, opts, deps) {
|
|
|
1569
1617
|
try {
|
|
1570
1618
|
if (opts.print) {
|
|
1571
1619
|
console.log("\n# would run:");
|
|
1572
|
-
for (const args of commands) console.log(` hermes ${args.
|
|
1620
|
+
for (const args of commands) console.log(` hermes ${hermesCommandLine(args, creds.routing_key, opts.profile)}`);
|
|
1573
1621
|
console.log(
|
|
1574
1622
|
"\nThen start hermes and run /model custom:lunaroute:<model> to pick a LunaRoute model (models auto-discover from /v1/models)."
|
|
1575
1623
|
);
|
|
@@ -1581,7 +1629,7 @@ async function runHermesSetup(creds, routingUrl, opts, deps) {
|
|
|
1581
1629
|
return runHermesConfigSets(deps.spawn, routingUrl, creds.routing_key);
|
|
1582
1630
|
}
|
|
1583
1631
|
console.log("Skipped. Re-run with --yes, or configure manually:");
|
|
1584
|
-
for (const args of commands) console.log(` hermes ${args.
|
|
1632
|
+
for (const args of commands) console.log(` hermes ${hermesCommandLine(args, creds.routing_key, opts.profile)}`);
|
|
1585
1633
|
console.log("\nThen start hermes and run /model custom:lunaroute:<model> to pick a LunaRoute model.");
|
|
1586
1634
|
return 0;
|
|
1587
1635
|
} catch (err) {
|
|
@@ -1593,16 +1641,20 @@ async function runHermesSetup(creds, routingUrl, opts, deps) {
|
|
|
1593
1641
|
return 1;
|
|
1594
1642
|
}
|
|
1595
1643
|
}
|
|
1596
|
-
function hermesConfigSetArgs(routingUrl,
|
|
1644
|
+
function hermesConfigSetArgs(routingUrl, key2) {
|
|
1597
1645
|
return [
|
|
1598
1646
|
["config", "set", "providers.lunaroute.api", `${routingUrl}/v1`],
|
|
1599
1647
|
["config", "set", "providers.lunaroute.key_env", "LUNAROUTE_API_KEY"],
|
|
1600
1648
|
["config", "set", "providers.lunaroute.transport", "chat_completions"],
|
|
1601
|
-
["config", "set", "LUNAROUTE_API_KEY",
|
|
1649
|
+
["config", "set", "LUNAROUTE_API_KEY", key2]
|
|
1602
1650
|
];
|
|
1603
1651
|
}
|
|
1604
|
-
|
|
1605
|
-
const
|
|
1652
|
+
function hermesCommandLine(args, key2, profile) {
|
|
1653
|
+
const profileArg = profile && profile !== "default" ? ` -p ${shQuote(profile)}` : "";
|
|
1654
|
+
return args.map((a) => a === key2 ? `"$(lunaroute key${profileArg})"` : a).join(" ");
|
|
1655
|
+
}
|
|
1656
|
+
async function runHermesConfigSets(spawn, routingUrl, key2) {
|
|
1657
|
+
const commands = hermesConfigSetArgs(routingUrl, key2);
|
|
1606
1658
|
const setKeys = commands.map((c) => c[2]);
|
|
1607
1659
|
for (let i = 0; i < commands.length; i++) {
|
|
1608
1660
|
const code = await new Promise((resolve) => {
|
|
@@ -1643,7 +1695,7 @@ async function runOpencodeSetup(stored, settings, routingUrl, opts, deps) {
|
|
|
1643
1695
|
),
|
|
1644
1696
|
opts.key ? buildKeyPlan("<your-api-key>") : null
|
|
1645
1697
|
);
|
|
1646
|
-
return applyAndReport(plan, stored?.routing_key ?? "", false);
|
|
1698
|
+
return applyAndReport(plan, stored?.routing_key ?? "", false, opts.profile);
|
|
1647
1699
|
}
|
|
1648
1700
|
if (opts.key) {
|
|
1649
1701
|
const creds2 = await requireCreds(opts, deps, stored);
|
|
@@ -1657,14 +1709,15 @@ async function runOpencodeSetup(stored, settings, routingUrl, opts, deps) {
|
|
|
1657
1709
|
routingUrl,
|
|
1658
1710
|
await deps.confirm("Merge LunaRoute provider into opencode.json (backup kept, other providers preserved)?", {
|
|
1659
1711
|
yes: opts.yes
|
|
1660
|
-
})
|
|
1712
|
+
}),
|
|
1713
|
+
opts.profile
|
|
1661
1714
|
);
|
|
1662
1715
|
}
|
|
1663
1716
|
const plan = buildPlan(
|
|
1664
1717
|
{ routingUrl, orgId: settings.org_id, models: [], keyEnvVar: "LUNAROUTE_API_KEY" },
|
|
1665
1718
|
{ extension: true }
|
|
1666
1719
|
);
|
|
1667
|
-
const code = await applyAndReport(plan, creds2.routing_key, true);
|
|
1720
|
+
const code = await applyAndReport(plan, creds2.routing_key, true, opts.profile);
|
|
1668
1721
|
if (code !== 0) return code;
|
|
1669
1722
|
const store = await deps.confirm(
|
|
1670
1723
|
"Store the key in ~/.local/share/opencode/auth.json (replaces any existing LunaRoute login; other credentials preserved)?",
|
|
@@ -1674,7 +1727,7 @@ async function runOpencodeSetup(stored, settings, routingUrl, opts, deps) {
|
|
|
1674
1727
|
console.log("\nSkipped. Inside opencode, run /connect to sign in.");
|
|
1675
1728
|
return 0;
|
|
1676
1729
|
}
|
|
1677
|
-
const wcode = await applyAndReport(buildKeyPlan(creds2.routing_key), creds2.routing_key, true);
|
|
1730
|
+
const wcode = await applyAndReport(buildKeyPlan(creds2.routing_key), creds2.routing_key, true, opts.profile);
|
|
1678
1731
|
if (wcode !== 0) return wcode;
|
|
1679
1732
|
console.log("\nDone. Start opencode \u2014 it is signed in. Pick a model with /models.");
|
|
1680
1733
|
return 0;
|
|
@@ -1687,7 +1740,7 @@ async function runOpencodeSetup(stored, settings, routingUrl, opts, deps) {
|
|
|
1687
1740
|
{ routingUrl, orgId: settings.org_id, models: [], keyEnvVar: "LUNAROUTE_API_KEY" },
|
|
1688
1741
|
{ extension: true }
|
|
1689
1742
|
);
|
|
1690
|
-
const code = await applyAndReport(plan, stored?.routing_key ?? "", true);
|
|
1743
|
+
const code = await applyAndReport(plan, stored?.routing_key ?? "", true, opts.profile);
|
|
1691
1744
|
if (code !== 0) return code;
|
|
1692
1745
|
if (await deps.confirm("Start opencode now? (if it's already open, quit and reopen it to load the extension)", {
|
|
1693
1746
|
yes: opts.yes
|
|
@@ -1703,7 +1756,7 @@ async function runOpencodeSetup(stored, settings, routingUrl, opts, deps) {
|
|
|
1703
1756
|
"Merge LunaRoute provider into opencode.json instead? (backup kept, other providers preserved)",
|
|
1704
1757
|
{ yes: opts.yes }
|
|
1705
1758
|
);
|
|
1706
|
-
return applyOpencodeProvider(creds, routingUrl, write);
|
|
1759
|
+
return applyOpencodeProvider(creds, routingUrl, write, opts.profile);
|
|
1707
1760
|
} catch (err) {
|
|
1708
1761
|
if (err instanceof NonInteractiveTerminalError) {
|
|
1709
1762
|
console.error(
|
|
@@ -1715,7 +1768,7 @@ async function runOpencodeSetup(stored, settings, routingUrl, opts, deps) {
|
|
|
1715
1768
|
return 1;
|
|
1716
1769
|
}
|
|
1717
1770
|
}
|
|
1718
|
-
async function applyOpencodeProvider(creds, routingUrl, write) {
|
|
1771
|
+
async function applyOpencodeProvider(creds, routingUrl, write, profile = "default") {
|
|
1719
1772
|
let models;
|
|
1720
1773
|
try {
|
|
1721
1774
|
models = await fetchModels(routingUrl, creds.routing_key);
|
|
@@ -1729,7 +1782,7 @@ async function applyOpencodeProvider(creds, routingUrl, write) {
|
|
|
1729
1782
|
models,
|
|
1730
1783
|
keyEnvVar: "LUNAROUTE_API_KEY"
|
|
1731
1784
|
});
|
|
1732
|
-
return applyAndReport(plan, creds.routing_key, write);
|
|
1785
|
+
return applyAndReport(plan, creds.routing_key, write, profile);
|
|
1733
1786
|
}
|
|
1734
1787
|
function combinePlans(a, b) {
|
|
1735
1788
|
if (!b) return a;
|
|
@@ -1739,9 +1792,9 @@ function combinePlans(a, b) {
|
|
|
1739
1792
|
notes: [...a.notes, ...b.notes]
|
|
1740
1793
|
};
|
|
1741
1794
|
}
|
|
1742
|
-
async function applyAndReport(plan,
|
|
1795
|
+
async function applyAndReport(plan, key2, write, profile = "default") {
|
|
1743
1796
|
try {
|
|
1744
|
-
const summary = await applyPlan(plan, { print: !write, key });
|
|
1797
|
+
const summary = await applyPlan(plan, { print: !write, key: key2, profile });
|
|
1745
1798
|
if (write && summary.written.length > 0) {
|
|
1746
1799
|
console.log(`
|
|
1747
1800
|
Wrote: ${summary.written.join(", ")}`);
|
|
@@ -1802,7 +1855,7 @@ async function installPiExtension(deps, opts) {
|
|
|
1802
1855
|
{ yes: opts.yes }
|
|
1803
1856
|
);
|
|
1804
1857
|
if (remove) {
|
|
1805
|
-
const ccode = await applyAndReport(buildStaleProviderCleanupPlan(), "", true);
|
|
1858
|
+
const ccode = await applyAndReport(buildStaleProviderCleanupPlan(), "", true, opts.profile);
|
|
1806
1859
|
if (ccode !== 0) return ccode;
|
|
1807
1860
|
}
|
|
1808
1861
|
}
|
|
@@ -1827,7 +1880,7 @@ async function launchPi(spawn) {
|
|
|
1827
1880
|
});
|
|
1828
1881
|
});
|
|
1829
1882
|
}
|
|
1830
|
-
async function applyPiModels(creds, routingUrl, write) {
|
|
1883
|
+
async function applyPiModels(creds, routingUrl, write, profile = "default") {
|
|
1831
1884
|
let models;
|
|
1832
1885
|
try {
|
|
1833
1886
|
models = await fetchModels(routingUrl, creds.routing_key);
|
|
@@ -1842,7 +1895,7 @@ async function applyPiModels(creds, routingUrl, write) {
|
|
|
1842
1895
|
keyEnvVar: "LUNAROUTE_API_KEY"
|
|
1843
1896
|
});
|
|
1844
1897
|
try {
|
|
1845
|
-
const summary = await applyPlan(plan, { print: !write, key: creds.routing_key });
|
|
1898
|
+
const summary = await applyPlan(plan, { print: !write, key: creds.routing_key, profile });
|
|
1846
1899
|
if (write && summary.written.length > 0) {
|
|
1847
1900
|
console.log(`
|
|
1848
1901
|
Wrote: ${summary.written.join(", ")}`);
|
|
@@ -2516,6 +2569,9 @@ program.command("login").description("Authorize this device via the browser and
|
|
|
2516
2569
|
program.command("whoami").description("Show the signed-in user and organization.").action(() => {
|
|
2517
2570
|
whoami(program.opts().profile);
|
|
2518
2571
|
});
|
|
2572
|
+
program.command("key").description('Print the stored routing key, for shell use (e.g. "$(lunaroute key)").').action(() => {
|
|
2573
|
+
key(program.opts().profile);
|
|
2574
|
+
});
|
|
2519
2575
|
program.command("logout").description("Remove stored credentials for the active profile.").action(() => {
|
|
2520
2576
|
logout(program.opts().profile);
|
|
2521
2577
|
});
|