lianrouter 2.2.0 → 2.2.2
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/cli.js +126 -13
- package/package.json +43 -43
package/dist/cli.js
CHANGED
|
@@ -17,7 +17,7 @@ var package_default;
|
|
|
17
17
|
var init_package = __esm(() => {
|
|
18
18
|
package_default = {
|
|
19
19
|
name: "lianrouter",
|
|
20
|
-
version: "2.2.
|
|
20
|
+
version: "2.2.2",
|
|
21
21
|
description: "LianRouter launcher: install, run and control the gateway from one command",
|
|
22
22
|
type: "module",
|
|
23
23
|
bin: {
|
|
@@ -482,7 +482,7 @@ class GitHubReleaseSource {
|
|
|
482
482
|
};
|
|
483
483
|
});
|
|
484
484
|
return {
|
|
485
|
-
version: newest.tag_name,
|
|
485
|
+
version: normalizeVersion(newest.tag_name),
|
|
486
486
|
notesUrl: newest.html_url,
|
|
487
487
|
...newest.published_at.length > 0 ? { publishedAt: newest.published_at } : {},
|
|
488
488
|
assets
|
|
@@ -507,7 +507,7 @@ var init_github_source = __esm(() => {
|
|
|
507
507
|
});
|
|
508
508
|
|
|
509
509
|
// cli/update/install.ts
|
|
510
|
-
import { cp, mkdir as mkdir2, rename, rm as rm3, stat } from "fs/promises";
|
|
510
|
+
import { cp, mkdir as mkdir2, readdir as readdir2, rename, rm as rm3, stat } from "fs/promises";
|
|
511
511
|
import { dirname, join as join2, relative, resolve as resolve2, sep as sep2 } from "path";
|
|
512
512
|
async function pathExists(target) {
|
|
513
513
|
try {
|
|
@@ -534,6 +534,26 @@ async function assertNotDevCheckout(installRoot) {
|
|
|
534
534
|
throw new Error(`refusing to self-update ${root}: it is a source checkout (.git and src/main.ts present). ` + "Build locally with `bun run build` instead of installing a release over the working tree.");
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
|
+
async function sweepBackups(root, remove = rm3) {
|
|
538
|
+
const backupDir = join2(resolve2(root), BACKUP_DIR_NAME);
|
|
539
|
+
let entries;
|
|
540
|
+
try {
|
|
541
|
+
entries = await readdir2(backupDir);
|
|
542
|
+
} catch {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
let failed = false;
|
|
546
|
+
for (const entry of entries) {
|
|
547
|
+
await remove(join2(backupDir, entry), { recursive: true, force: true }).catch(() => {
|
|
548
|
+
failed = true;
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
if (!failed) {
|
|
552
|
+
await remove(backupDir, { recursive: true, force: true }).catch(() => {
|
|
553
|
+
return;
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
}
|
|
537
557
|
async function installAtomically(options) {
|
|
538
558
|
const root = resolve2(options.installRoot);
|
|
539
559
|
const staged = resolve2(options.stagedDir);
|
|
@@ -590,7 +610,7 @@ async function installAtomically(options) {
|
|
|
590
610
|
throw error;
|
|
591
611
|
}
|
|
592
612
|
onProgress?.({ percent: 100, message: "install complete" });
|
|
593
|
-
await
|
|
613
|
+
await sweepBackups(root, options.remove ?? rm3);
|
|
594
614
|
}
|
|
595
615
|
var BACKUP_DIR_NAME = ".backup";
|
|
596
616
|
var init_install = () => {};
|
|
@@ -618,15 +638,19 @@ async function readInstalledVersion(installRoot) {
|
|
|
618
638
|
if (typeof version !== "string" || version.trim().length === 0) {
|
|
619
639
|
return;
|
|
620
640
|
}
|
|
641
|
+
const normalized = normalizeVersion(version);
|
|
642
|
+
if (normalized.length === 0) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
621
645
|
return {
|
|
622
|
-
version:
|
|
646
|
+
version: normalized,
|
|
623
647
|
installedAt: typeof installedAt === "string" ? installedAt : "",
|
|
624
648
|
assetName: typeof assetName === "string" ? assetName : ""
|
|
625
649
|
};
|
|
626
650
|
}
|
|
627
651
|
async function writeInstalledVersion(installRoot, record) {
|
|
628
652
|
const payload = {
|
|
629
|
-
version: record.version,
|
|
653
|
+
version: normalizeVersion(record.version),
|
|
630
654
|
installedAt: record.installedAt,
|
|
631
655
|
assetName: record.assetName
|
|
632
656
|
};
|
|
@@ -646,7 +670,7 @@ var init_version_file = __esm(() => {
|
|
|
646
670
|
});
|
|
647
671
|
|
|
648
672
|
// cli/update/engine.ts
|
|
649
|
-
import { mkdtemp, readdir as
|
|
673
|
+
import { mkdtemp, readdir as readdir3, rm as rm4 } from "fs/promises";
|
|
650
674
|
import { tmpdir } from "os";
|
|
651
675
|
import { join as join4 } from "path";
|
|
652
676
|
function withinSlice(start, end, percent) {
|
|
@@ -700,7 +724,7 @@ async function resolveInstallCandidate(opts) {
|
|
|
700
724
|
};
|
|
701
725
|
}
|
|
702
726
|
async function payloadEntries(stagedDir) {
|
|
703
|
-
const entries = await
|
|
727
|
+
const entries = await readdir3(stagedDir, { withFileTypes: true });
|
|
704
728
|
return entries.map((entry) => entry.name);
|
|
705
729
|
}
|
|
706
730
|
async function runUpdate(opts) {
|
|
@@ -1572,7 +1596,7 @@ init_install();
|
|
|
1572
1596
|
init_version_file();
|
|
1573
1597
|
init_paths();
|
|
1574
1598
|
import { statSync } from "fs";
|
|
1575
|
-
import { mkdir as mkdir3, mkdtemp as mkdtemp2, readdir as
|
|
1599
|
+
import { mkdir as mkdir3, mkdtemp as mkdtemp2, readdir as readdir4, rm as rm5 } from "fs/promises";
|
|
1576
1600
|
import { tmpdir as tmpdir2 } from "os";
|
|
1577
1601
|
import { join as join6 } from "path";
|
|
1578
1602
|
var SLICE2 = {
|
|
@@ -1601,7 +1625,7 @@ function withinSlice2(start, end, percent) {
|
|
|
1601
1625
|
return start + (end - start) * clamped / 100;
|
|
1602
1626
|
}
|
|
1603
1627
|
async function payloadEntries2(stagedDir) {
|
|
1604
|
-
const entries = await
|
|
1628
|
+
const entries = await readdir4(stagedDir, { withFileTypes: true });
|
|
1605
1629
|
return entries.map((entry) => entry.name);
|
|
1606
1630
|
}
|
|
1607
1631
|
async function ensureGatewayInstalled(options) {
|
|
@@ -1990,7 +2014,7 @@ function buildMenuItems(input) {
|
|
|
1990
2014
|
if (input.update !== undefined) {
|
|
1991
2015
|
items.push({
|
|
1992
2016
|
action: "update",
|
|
1993
|
-
label: `Update to v${input.update.latest} (current: v${input.
|
|
2017
|
+
label: `Update to v${input.update.latest} (current: v${input.update.current})`
|
|
1994
2018
|
});
|
|
1995
2019
|
}
|
|
1996
2020
|
items.push({ action: "web", label: "Web UI (Open in Browser)" }, { action: "tui", label: "Terminal UI (Interactive CLI)" }, { action: "tray", label: "Hide to Tray (Background)" }, { action: "exit", label: "Exit" });
|
|
@@ -2796,6 +2820,82 @@ async function runUpdateSequence(deps) {
|
|
|
2796
2820
|
}
|
|
2797
2821
|
}
|
|
2798
2822
|
|
|
2823
|
+
// cli/src/update-notice.ts
|
|
2824
|
+
var ARROW = "\u2192";
|
|
2825
|
+
function renderUpdateNotices(input) {
|
|
2826
|
+
const lines = [];
|
|
2827
|
+
const launcher = input.launcher;
|
|
2828
|
+
if (launcher !== undefined && compareVersions(launcher.latest, launcher.current) > 0) {
|
|
2829
|
+
lines.push(`lianrouter: a newer launcher is published (${launcher.current} ${ARROW} ${launcher.latest}). Run: bun add -g lianrouter@latest`);
|
|
2830
|
+
}
|
|
2831
|
+
const gateway = input.gateway;
|
|
2832
|
+
if (gateway !== undefined && compareVersions(gateway.latest, gateway.current) > 0) {
|
|
2833
|
+
lines.push(`lianrouter: a gateway update is available (${gateway.current} ${ARROW} ${gateway.latest}). Run: lianrouter update`);
|
|
2834
|
+
}
|
|
2835
|
+
return lines;
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
// cli/update/npm-source.ts
|
|
2839
|
+
var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/lianrouter/latest";
|
|
2840
|
+
var REGISTRY_URL = (() => {
|
|
2841
|
+
const override = process.env.LIANROUTER_NPM_REGISTRY;
|
|
2842
|
+
return override !== undefined && override.trim().length > 0 ? override.trim() : DEFAULT_REGISTRY_URL;
|
|
2843
|
+
})();
|
|
2844
|
+
var REQUEST_TIMEOUT_MS2 = 2500;
|
|
2845
|
+
var UPDATE_CHECK_DISABLE_ENV = "LIANROUTER_NO_UPDATE_CHECK";
|
|
2846
|
+
function updateCheckDisabled() {
|
|
2847
|
+
return process.env[UPDATE_CHECK_DISABLE_ENV] === "1";
|
|
2848
|
+
}
|
|
2849
|
+
var VERSION_SHAPE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
2850
|
+
function isSemverish(value) {
|
|
2851
|
+
return typeof value === "string" && VERSION_SHAPE.test(normalizeVersion(value));
|
|
2852
|
+
}
|
|
2853
|
+
async function checkLauncherVersion(options) {
|
|
2854
|
+
const url = options.registryUrl ?? REGISTRY_URL;
|
|
2855
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
2856
|
+
const controller = new AbortController;
|
|
2857
|
+
let timer;
|
|
2858
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
2859
|
+
timer = setTimeout(() => {
|
|
2860
|
+
controller.abort();
|
|
2861
|
+
reject(new Error(`registry did not answer within ${REQUEST_TIMEOUT_MS2} ms`));
|
|
2862
|
+
}, REQUEST_TIMEOUT_MS2);
|
|
2863
|
+
});
|
|
2864
|
+
let response;
|
|
2865
|
+
try {
|
|
2866
|
+
response = await Promise.race([
|
|
2867
|
+
doFetch(url, { headers: { Accept: "application/json" }, signal: controller.signal }),
|
|
2868
|
+
deadline
|
|
2869
|
+
]);
|
|
2870
|
+
} catch (error) {
|
|
2871
|
+
return {
|
|
2872
|
+
status: "unavailable",
|
|
2873
|
+
reason: `registry unreachable: ${error instanceof Error ? error.message : String(error)}`
|
|
2874
|
+
};
|
|
2875
|
+
} finally {
|
|
2876
|
+
clearTimeout(timer);
|
|
2877
|
+
}
|
|
2878
|
+
if (!response.ok) {
|
|
2879
|
+
return { status: "unavailable", reason: `registry returned ${response.status}` };
|
|
2880
|
+
}
|
|
2881
|
+
let payload;
|
|
2882
|
+
try {
|
|
2883
|
+
payload = await response.json();
|
|
2884
|
+
} catch {
|
|
2885
|
+
return { status: "unavailable", reason: "registry returned a non-JSON body" };
|
|
2886
|
+
}
|
|
2887
|
+
if (typeof payload !== "object" || payload === null || !("version" in payload)) {
|
|
2888
|
+
return { status: "unavailable", reason: "registry returned no usable version" };
|
|
2889
|
+
}
|
|
2890
|
+
const published = payload.version;
|
|
2891
|
+
if (!isSemverish(published)) {
|
|
2892
|
+
return { status: "unavailable", reason: "registry returned no usable version" };
|
|
2893
|
+
}
|
|
2894
|
+
const latest = normalizeVersion(published);
|
|
2895
|
+
const current = normalizeVersion(options.currentVersion);
|
|
2896
|
+
return compareVersions(latest, current) > 0 ? { status: "outdated", latest, current } : { status: "current", latest };
|
|
2897
|
+
}
|
|
2898
|
+
|
|
2799
2899
|
// cli/src/tray-launcher.ts
|
|
2800
2900
|
init_paths();
|
|
2801
2901
|
import { existsSync as existsSync3 } from "fs";
|
|
@@ -3256,7 +3356,14 @@ ${cause}`);
|
|
|
3256
3356
|
return supervisor.status;
|
|
3257
3357
|
}
|
|
3258
3358
|
async function runInteractive(supervisor, options, runtime) {
|
|
3359
|
+
const checkDisabled = updateCheckDisabled();
|
|
3360
|
+
const noticesApply = !options.background && !options.headless;
|
|
3361
|
+
const launcherCheck = checkDisabled || !noticesApply ? undefined : checkLauncherVersion({ currentVersion: CLI_VERSION }).catch(() => {
|
|
3362
|
+
return;
|
|
3363
|
+
});
|
|
3259
3364
|
await ensureStarted(supervisor);
|
|
3365
|
+
const launcher = await launcherCheck;
|
|
3366
|
+
const launcherNotice = launcher?.status === "outdated" ? { launcher: { current: launcher.current, latest: launcher.latest } } : {};
|
|
3260
3367
|
const session = await openSession(supervisor, runtime, options.host);
|
|
3261
3368
|
if (options.background) {
|
|
3262
3369
|
supervisor.detach();
|
|
@@ -3267,11 +3374,17 @@ async function runInteractive(supervisor, options, runtime) {
|
|
|
3267
3374
|
if (options.headless) {
|
|
3268
3375
|
return await blockUntilTrayExit(supervisor, session, runtime);
|
|
3269
3376
|
}
|
|
3270
|
-
const update = await readUpdateInfo(runtime.installRoot);
|
|
3377
|
+
const update = checkDisabled ? null : await readUpdateInfo(runtime.installRoot);
|
|
3378
|
+
for (const line of renderUpdateNotices({
|
|
3379
|
+
...launcherNotice,
|
|
3380
|
+
...update !== null && update.available ? { gateway: { current: update.current, latest: update.latest } } : {}
|
|
3381
|
+
})) {
|
|
3382
|
+
console.log(line);
|
|
3383
|
+
}
|
|
3271
3384
|
const action = await promptMenu({
|
|
3272
3385
|
version: CLI_VERSION,
|
|
3273
3386
|
port: supervisor.status.port,
|
|
3274
|
-
update: update !== null && update.available ? { latest: update.latest } : undefined
|
|
3387
|
+
update: update !== null && update.available ? { latest: update.latest, current: update.current } : undefined
|
|
3275
3388
|
});
|
|
3276
3389
|
return await dispatch(action, supervisor, session, options, runtime);
|
|
3277
3390
|
}
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "lianrouter",
|
|
3
|
-
"version": "2.2.
|
|
4
|
-
"description": "LianRouter launcher: install, run and control the gateway from one command",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"lianrouter": "./dist/cli.js"
|
|
8
|
-
},
|
|
9
|
-
"engines": {
|
|
10
|
-
"bun": ">=1.4.2"
|
|
11
|
-
},
|
|
12
|
-
"files": [
|
|
13
|
-
"dist",
|
|
14
|
-
"README.md"
|
|
15
|
-
],
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "bun run ../scripts/build-cli.ts",
|
|
18
|
-
"typecheck": "tsc --noEmit -p .",
|
|
19
|
-
"postinstall": "echo lianrouter: the gateway binary installs on first run, not during this install",
|
|
20
|
-
"prepublishOnly": "bun run build"
|
|
21
|
-
},
|
|
22
|
-
"repository": {
|
|
23
|
-
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/ReXooGen/Lian-Router.git",
|
|
25
|
-
"directory": "cli"
|
|
26
|
-
},
|
|
27
|
-
"bugs": {
|
|
28
|
-
"url": "https://github.com/ReXooGen/Lian-Router/issues"
|
|
29
|
-
},
|
|
30
|
-
"homepage": "https://github.com/ReXooGen/Lian-Router#readme",
|
|
31
|
-
"publishConfig": {
|
|
32
|
-
"access": "public"
|
|
33
|
-
},
|
|
34
|
-
"keywords": [
|
|
35
|
-
"lianrouter",
|
|
36
|
-
"ai-gateway",
|
|
37
|
-
"openai-compatible",
|
|
38
|
-
"llm-router",
|
|
39
|
-
"self-hosted",
|
|
40
|
-
"cli",
|
|
41
|
-
"launcher"
|
|
42
|
-
]
|
|
43
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "lianrouter",
|
|
3
|
+
"version": "2.2.2",
|
|
4
|
+
"description": "LianRouter launcher: install, run and control the gateway from one command",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"lianrouter": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"bun": ">=1.4.2"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "bun run ../scripts/build-cli.ts",
|
|
18
|
+
"typecheck": "tsc --noEmit -p .",
|
|
19
|
+
"postinstall": "echo lianrouter: the gateway binary installs on first run, not during this install",
|
|
20
|
+
"prepublishOnly": "bun run build"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/ReXooGen/Lian-Router.git",
|
|
25
|
+
"directory": "cli"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/ReXooGen/Lian-Router/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/ReXooGen/Lian-Router#readme",
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"lianrouter",
|
|
36
|
+
"ai-gateway",
|
|
37
|
+
"openai-compatible",
|
|
38
|
+
"llm-router",
|
|
39
|
+
"self-hosted",
|
|
40
|
+
"cli",
|
|
41
|
+
"launcher"
|
|
42
|
+
]
|
|
43
|
+
}
|