@lakphy/local-router 0.2.0 → 0.3.0
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 +1043 -40
- package/dist/entry.js +758 -207
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2406,7 +2406,7 @@ var require_codegen = __commonJS((exports) => {
|
|
|
2406
2406
|
ADD: new code_1._Code("+")
|
|
2407
2407
|
};
|
|
2408
2408
|
|
|
2409
|
-
class
|
|
2409
|
+
class Node3 {
|
|
2410
2410
|
optimizeNodes() {
|
|
2411
2411
|
return this;
|
|
2412
2412
|
}
|
|
@@ -2415,7 +2415,7 @@ var require_codegen = __commonJS((exports) => {
|
|
|
2415
2415
|
}
|
|
2416
2416
|
}
|
|
2417
2417
|
|
|
2418
|
-
class Def extends
|
|
2418
|
+
class Def extends Node3 {
|
|
2419
2419
|
constructor(varKind, name21, rhs) {
|
|
2420
2420
|
super();
|
|
2421
2421
|
this.varKind = varKind;
|
|
@@ -2439,7 +2439,7 @@ var require_codegen = __commonJS((exports) => {
|
|
|
2439
2439
|
}
|
|
2440
2440
|
}
|
|
2441
2441
|
|
|
2442
|
-
class Assign extends
|
|
2442
|
+
class Assign extends Node3 {
|
|
2443
2443
|
constructor(lhs, rhs, sideEffects) {
|
|
2444
2444
|
super();
|
|
2445
2445
|
this.lhs = lhs;
|
|
@@ -2471,7 +2471,7 @@ var require_codegen = __commonJS((exports) => {
|
|
|
2471
2471
|
}
|
|
2472
2472
|
}
|
|
2473
2473
|
|
|
2474
|
-
class Label extends
|
|
2474
|
+
class Label extends Node3 {
|
|
2475
2475
|
constructor(label) {
|
|
2476
2476
|
super();
|
|
2477
2477
|
this.label = label;
|
|
@@ -2482,7 +2482,7 @@ var require_codegen = __commonJS((exports) => {
|
|
|
2482
2482
|
}
|
|
2483
2483
|
}
|
|
2484
2484
|
|
|
2485
|
-
class Break extends
|
|
2485
|
+
class Break extends Node3 {
|
|
2486
2486
|
constructor(label) {
|
|
2487
2487
|
super();
|
|
2488
2488
|
this.label = label;
|
|
@@ -2494,7 +2494,7 @@ var require_codegen = __commonJS((exports) => {
|
|
|
2494
2494
|
}
|
|
2495
2495
|
}
|
|
2496
2496
|
|
|
2497
|
-
class Throw extends
|
|
2497
|
+
class Throw extends Node3 {
|
|
2498
2498
|
constructor(error48) {
|
|
2499
2499
|
super();
|
|
2500
2500
|
this.error = error48;
|
|
@@ -2507,7 +2507,7 @@ var require_codegen = __commonJS((exports) => {
|
|
|
2507
2507
|
}
|
|
2508
2508
|
}
|
|
2509
2509
|
|
|
2510
|
-
class AnyCode extends
|
|
2510
|
+
class AnyCode extends Node3 {
|
|
2511
2511
|
constructor(code) {
|
|
2512
2512
|
super();
|
|
2513
2513
|
this.code = code;
|
|
@@ -2527,7 +2527,7 @@ var require_codegen = __commonJS((exports) => {
|
|
|
2527
2527
|
}
|
|
2528
2528
|
}
|
|
2529
2529
|
|
|
2530
|
-
class ParentNode extends
|
|
2530
|
+
class ParentNode extends Node3 {
|
|
2531
2531
|
constructor(nodes = []) {
|
|
2532
2532
|
super();
|
|
2533
2533
|
this.nodes = nodes;
|
|
@@ -4935,7 +4935,7 @@ var require_compile = __commonJS((exports) => {
|
|
|
4935
4935
|
const schOrFunc = root2.refs[ref];
|
|
4936
4936
|
if (schOrFunc)
|
|
4937
4937
|
return schOrFunc;
|
|
4938
|
-
let _sch =
|
|
4938
|
+
let _sch = resolve5.call(this, root2, ref);
|
|
4939
4939
|
if (_sch === undefined) {
|
|
4940
4940
|
const schema = (_a21 = root2.localRefs) === null || _a21 === undefined ? undefined : _a21[ref];
|
|
4941
4941
|
const { schemaId } = this.opts;
|
|
@@ -4962,7 +4962,7 @@ var require_compile = __commonJS((exports) => {
|
|
|
4962
4962
|
function sameSchemaEnv(s1, s2) {
|
|
4963
4963
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
4964
4964
|
}
|
|
4965
|
-
function
|
|
4965
|
+
function resolve5(root2, ref) {
|
|
4966
4966
|
let sch;
|
|
4967
4967
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
4968
4968
|
ref = sch;
|
|
@@ -5492,7 +5492,7 @@ var require_fast_uri = __commonJS((exports, module) => {
|
|
|
5492
5492
|
}
|
|
5493
5493
|
return uri;
|
|
5494
5494
|
}
|
|
5495
|
-
function
|
|
5495
|
+
function resolve5(baseURI, relativeURI, options) {
|
|
5496
5496
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
5497
5497
|
const resolved = resolveComponent(parse7(baseURI, schemelessOptions), parse7(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
5498
5498
|
schemelessOptions.skipEscape = true;
|
|
@@ -5720,7 +5720,7 @@ var require_fast_uri = __commonJS((exports, module) => {
|
|
|
5720
5720
|
var fastUri = {
|
|
5721
5721
|
SCHEMES,
|
|
5722
5722
|
normalize,
|
|
5723
|
-
resolve:
|
|
5723
|
+
resolve: resolve5,
|
|
5724
5724
|
resolveComponent,
|
|
5725
5725
|
equal,
|
|
5726
5726
|
serialize,
|
|
@@ -5857,7 +5857,7 @@ var require_core = __commonJS((exports) => {
|
|
|
5857
5857
|
opts = this.opts = { ...opts, ...requiredOptions(opts) };
|
|
5858
5858
|
const { es5, lines } = this.opts.code;
|
|
5859
5859
|
this.scope = new codegen_2.ValueScope({ scope: {}, prefixes: EXT_SCOPE_NAMES, es5, lines });
|
|
5860
|
-
this.logger =
|
|
5860
|
+
this.logger = getLogger2(opts.logger);
|
|
5861
5861
|
const formatOpt = opts.validateFormats;
|
|
5862
5862
|
opts.validateFormats = false;
|
|
5863
5863
|
this.RULES = (0, rules_1.getRules)();
|
|
@@ -6254,7 +6254,7 @@ var require_core = __commonJS((exports) => {
|
|
|
6254
6254
|
return metaOpts;
|
|
6255
6255
|
}
|
|
6256
6256
|
var noLogs = { log() {}, warn() {}, error() {} };
|
|
6257
|
-
function
|
|
6257
|
+
function getLogger2(logger) {
|
|
6258
6258
|
if (logger === false)
|
|
6259
6259
|
return noLogs;
|
|
6260
6260
|
if (logger === undefined)
|
|
@@ -8757,10 +8757,537 @@ var require_2020 = __commonJS((exports, module) => {
|
|
|
8757
8757
|
} });
|
|
8758
8758
|
});
|
|
8759
8759
|
|
|
8760
|
+
// node_modules/.bun/ajv-formats@3.0.1/node_modules/ajv-formats/dist/formats.js
|
|
8761
|
+
var require_formats = __commonJS((exports) => {
|
|
8762
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8763
|
+
exports.formatNames = exports.fastFormats = exports.fullFormats = undefined;
|
|
8764
|
+
function fmtDef(validate, compare) {
|
|
8765
|
+
return { validate, compare };
|
|
8766
|
+
}
|
|
8767
|
+
exports.fullFormats = {
|
|
8768
|
+
date: fmtDef(date5, compareDate),
|
|
8769
|
+
time: fmtDef(getTime(true), compareTime),
|
|
8770
|
+
"date-time": fmtDef(getDateTime(true), compareDateTime),
|
|
8771
|
+
"iso-time": fmtDef(getTime(), compareIsoTime),
|
|
8772
|
+
"iso-date-time": fmtDef(getDateTime(), compareIsoDateTime),
|
|
8773
|
+
duration: /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,
|
|
8774
|
+
uri,
|
|
8775
|
+
"uri-reference": /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,
|
|
8776
|
+
"uri-template": /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,
|
|
8777
|
+
url: /^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,
|
|
8778
|
+
email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
|
|
8779
|
+
hostname: /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,
|
|
8780
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,
|
|
8781
|
+
ipv6: /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,
|
|
8782
|
+
regex,
|
|
8783
|
+
uuid: /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,
|
|
8784
|
+
"json-pointer": /^(?:\/(?:[^~/]|~0|~1)*)*$/,
|
|
8785
|
+
"json-pointer-uri-fragment": /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,
|
|
8786
|
+
"relative-json-pointer": /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,
|
|
8787
|
+
byte,
|
|
8788
|
+
int32: { type: "number", validate: validateInt32 },
|
|
8789
|
+
int64: { type: "number", validate: validateInt64 },
|
|
8790
|
+
float: { type: "number", validate: validateNumber },
|
|
8791
|
+
double: { type: "number", validate: validateNumber },
|
|
8792
|
+
password: true,
|
|
8793
|
+
binary: true
|
|
8794
|
+
};
|
|
8795
|
+
exports.fastFormats = {
|
|
8796
|
+
...exports.fullFormats,
|
|
8797
|
+
date: fmtDef(/^\d\d\d\d-[0-1]\d-[0-3]\d$/, compareDate),
|
|
8798
|
+
time: fmtDef(/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i, compareTime),
|
|
8799
|
+
"date-time": fmtDef(/^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i, compareDateTime),
|
|
8800
|
+
"iso-time": fmtDef(/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i, compareIsoTime),
|
|
8801
|
+
"iso-date-time": fmtDef(/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i, compareIsoDateTime),
|
|
8802
|
+
uri: /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,
|
|
8803
|
+
"uri-reference": /^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,
|
|
8804
|
+
email: /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i
|
|
8805
|
+
};
|
|
8806
|
+
exports.formatNames = Object.keys(exports.fullFormats);
|
|
8807
|
+
function isLeapYear(year) {
|
|
8808
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
8809
|
+
}
|
|
8810
|
+
var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
8811
|
+
var DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
8812
|
+
function date5(str) {
|
|
8813
|
+
const matches = DATE.exec(str);
|
|
8814
|
+
if (!matches)
|
|
8815
|
+
return false;
|
|
8816
|
+
const year = +matches[1];
|
|
8817
|
+
const month = +matches[2];
|
|
8818
|
+
const day = +matches[3];
|
|
8819
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= (month === 2 && isLeapYear(year) ? 29 : DAYS[month]);
|
|
8820
|
+
}
|
|
8821
|
+
function compareDate(d1, d2) {
|
|
8822
|
+
if (!(d1 && d2))
|
|
8823
|
+
return;
|
|
8824
|
+
if (d1 > d2)
|
|
8825
|
+
return 1;
|
|
8826
|
+
if (d1 < d2)
|
|
8827
|
+
return -1;
|
|
8828
|
+
return 0;
|
|
8829
|
+
}
|
|
8830
|
+
var TIME = /^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i;
|
|
8831
|
+
function getTime(strictTimeZone) {
|
|
8832
|
+
return function time3(str) {
|
|
8833
|
+
const matches = TIME.exec(str);
|
|
8834
|
+
if (!matches)
|
|
8835
|
+
return false;
|
|
8836
|
+
const hr = +matches[1];
|
|
8837
|
+
const min = +matches[2];
|
|
8838
|
+
const sec = +matches[3];
|
|
8839
|
+
const tz = matches[4];
|
|
8840
|
+
const tzSign = matches[5] === "-" ? -1 : 1;
|
|
8841
|
+
const tzH = +(matches[6] || 0);
|
|
8842
|
+
const tzM = +(matches[7] || 0);
|
|
8843
|
+
if (tzH > 23 || tzM > 59 || strictTimeZone && !tz)
|
|
8844
|
+
return false;
|
|
8845
|
+
if (hr <= 23 && min <= 59 && sec < 60)
|
|
8846
|
+
return true;
|
|
8847
|
+
const utcMin = min - tzM * tzSign;
|
|
8848
|
+
const utcHr = hr - tzH * tzSign - (utcMin < 0 ? 1 : 0);
|
|
8849
|
+
return (utcHr === 23 || utcHr === -1) && (utcMin === 59 || utcMin === -1) && sec < 61;
|
|
8850
|
+
};
|
|
8851
|
+
}
|
|
8852
|
+
function compareTime(s1, s2) {
|
|
8853
|
+
if (!(s1 && s2))
|
|
8854
|
+
return;
|
|
8855
|
+
const t1 = new Date("2020-01-01T" + s1).valueOf();
|
|
8856
|
+
const t2 = new Date("2020-01-01T" + s2).valueOf();
|
|
8857
|
+
if (!(t1 && t2))
|
|
8858
|
+
return;
|
|
8859
|
+
return t1 - t2;
|
|
8860
|
+
}
|
|
8861
|
+
function compareIsoTime(t1, t2) {
|
|
8862
|
+
if (!(t1 && t2))
|
|
8863
|
+
return;
|
|
8864
|
+
const a1 = TIME.exec(t1);
|
|
8865
|
+
const a2 = TIME.exec(t2);
|
|
8866
|
+
if (!(a1 && a2))
|
|
8867
|
+
return;
|
|
8868
|
+
t1 = a1[1] + a1[2] + a1[3];
|
|
8869
|
+
t2 = a2[1] + a2[2] + a2[3];
|
|
8870
|
+
if (t1 > t2)
|
|
8871
|
+
return 1;
|
|
8872
|
+
if (t1 < t2)
|
|
8873
|
+
return -1;
|
|
8874
|
+
return 0;
|
|
8875
|
+
}
|
|
8876
|
+
var DATE_TIME_SEPARATOR = /t|\s/i;
|
|
8877
|
+
function getDateTime(strictTimeZone) {
|
|
8878
|
+
const time3 = getTime(strictTimeZone);
|
|
8879
|
+
return function date_time(str) {
|
|
8880
|
+
const dateTime = str.split(DATE_TIME_SEPARATOR);
|
|
8881
|
+
return dateTime.length === 2 && date5(dateTime[0]) && time3(dateTime[1]);
|
|
8882
|
+
};
|
|
8883
|
+
}
|
|
8884
|
+
function compareDateTime(dt1, dt2) {
|
|
8885
|
+
if (!(dt1 && dt2))
|
|
8886
|
+
return;
|
|
8887
|
+
const d1 = new Date(dt1).valueOf();
|
|
8888
|
+
const d2 = new Date(dt2).valueOf();
|
|
8889
|
+
if (!(d1 && d2))
|
|
8890
|
+
return;
|
|
8891
|
+
return d1 - d2;
|
|
8892
|
+
}
|
|
8893
|
+
function compareIsoDateTime(dt1, dt2) {
|
|
8894
|
+
if (!(dt1 && dt2))
|
|
8895
|
+
return;
|
|
8896
|
+
const [d1, t1] = dt1.split(DATE_TIME_SEPARATOR);
|
|
8897
|
+
const [d2, t2] = dt2.split(DATE_TIME_SEPARATOR);
|
|
8898
|
+
const res = compareDate(d1, d2);
|
|
8899
|
+
if (res === undefined)
|
|
8900
|
+
return;
|
|
8901
|
+
return res || compareTime(t1, t2);
|
|
8902
|
+
}
|
|
8903
|
+
var NOT_URI_FRAGMENT = /\/|:/;
|
|
8904
|
+
var URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
8905
|
+
function uri(str) {
|
|
8906
|
+
return NOT_URI_FRAGMENT.test(str) && URI.test(str);
|
|
8907
|
+
}
|
|
8908
|
+
var BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
|
|
8909
|
+
function byte(str) {
|
|
8910
|
+
BYTE.lastIndex = 0;
|
|
8911
|
+
return BYTE.test(str);
|
|
8912
|
+
}
|
|
8913
|
+
var MIN_INT32 = -(2 ** 31);
|
|
8914
|
+
var MAX_INT32 = 2 ** 31 - 1;
|
|
8915
|
+
function validateInt32(value) {
|
|
8916
|
+
return Number.isInteger(value) && value <= MAX_INT32 && value >= MIN_INT32;
|
|
8917
|
+
}
|
|
8918
|
+
function validateInt64(value) {
|
|
8919
|
+
return Number.isInteger(value);
|
|
8920
|
+
}
|
|
8921
|
+
function validateNumber() {
|
|
8922
|
+
return true;
|
|
8923
|
+
}
|
|
8924
|
+
var Z_ANCHOR = /[^\\]\\Z/;
|
|
8925
|
+
function regex(str) {
|
|
8926
|
+
if (Z_ANCHOR.test(str))
|
|
8927
|
+
return false;
|
|
8928
|
+
try {
|
|
8929
|
+
new RegExp(str);
|
|
8930
|
+
return true;
|
|
8931
|
+
} catch (e) {
|
|
8932
|
+
return false;
|
|
8933
|
+
}
|
|
8934
|
+
}
|
|
8935
|
+
});
|
|
8936
|
+
|
|
8937
|
+
// node_modules/.bun/ajv@8.18.0/node_modules/ajv/dist/vocabularies/draft7.js
|
|
8938
|
+
var require_draft7 = __commonJS((exports) => {
|
|
8939
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8940
|
+
var core_1 = require_core2();
|
|
8941
|
+
var validation_1 = require_validation();
|
|
8942
|
+
var applicator_1 = require_applicator();
|
|
8943
|
+
var format_1 = require_format2();
|
|
8944
|
+
var metadata_1 = require_metadata();
|
|
8945
|
+
var draft7Vocabularies = [
|
|
8946
|
+
core_1.default,
|
|
8947
|
+
validation_1.default,
|
|
8948
|
+
(0, applicator_1.default)(),
|
|
8949
|
+
format_1.default,
|
|
8950
|
+
metadata_1.metadataVocabulary,
|
|
8951
|
+
metadata_1.contentVocabulary
|
|
8952
|
+
];
|
|
8953
|
+
exports.default = draft7Vocabularies;
|
|
8954
|
+
});
|
|
8955
|
+
|
|
8956
|
+
// node_modules/.bun/ajv@8.18.0/node_modules/ajv/dist/refs/json-schema-draft-07.json
|
|
8957
|
+
var require_json_schema_draft_07 = __commonJS((exports, module) => {
|
|
8958
|
+
module.exports = {
|
|
8959
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
8960
|
+
$id: "http://json-schema.org/draft-07/schema#",
|
|
8961
|
+
title: "Core schema meta-schema",
|
|
8962
|
+
definitions: {
|
|
8963
|
+
schemaArray: {
|
|
8964
|
+
type: "array",
|
|
8965
|
+
minItems: 1,
|
|
8966
|
+
items: { $ref: "#" }
|
|
8967
|
+
},
|
|
8968
|
+
nonNegativeInteger: {
|
|
8969
|
+
type: "integer",
|
|
8970
|
+
minimum: 0
|
|
8971
|
+
},
|
|
8972
|
+
nonNegativeIntegerDefault0: {
|
|
8973
|
+
allOf: [{ $ref: "#/definitions/nonNegativeInteger" }, { default: 0 }]
|
|
8974
|
+
},
|
|
8975
|
+
simpleTypes: {
|
|
8976
|
+
enum: ["array", "boolean", "integer", "null", "number", "object", "string"]
|
|
8977
|
+
},
|
|
8978
|
+
stringArray: {
|
|
8979
|
+
type: "array",
|
|
8980
|
+
items: { type: "string" },
|
|
8981
|
+
uniqueItems: true,
|
|
8982
|
+
default: []
|
|
8983
|
+
}
|
|
8984
|
+
},
|
|
8985
|
+
type: ["object", "boolean"],
|
|
8986
|
+
properties: {
|
|
8987
|
+
$id: {
|
|
8988
|
+
type: "string",
|
|
8989
|
+
format: "uri-reference"
|
|
8990
|
+
},
|
|
8991
|
+
$schema: {
|
|
8992
|
+
type: "string",
|
|
8993
|
+
format: "uri"
|
|
8994
|
+
},
|
|
8995
|
+
$ref: {
|
|
8996
|
+
type: "string",
|
|
8997
|
+
format: "uri-reference"
|
|
8998
|
+
},
|
|
8999
|
+
$comment: {
|
|
9000
|
+
type: "string"
|
|
9001
|
+
},
|
|
9002
|
+
title: {
|
|
9003
|
+
type: "string"
|
|
9004
|
+
},
|
|
9005
|
+
description: {
|
|
9006
|
+
type: "string"
|
|
9007
|
+
},
|
|
9008
|
+
default: true,
|
|
9009
|
+
readOnly: {
|
|
9010
|
+
type: "boolean",
|
|
9011
|
+
default: false
|
|
9012
|
+
},
|
|
9013
|
+
examples: {
|
|
9014
|
+
type: "array",
|
|
9015
|
+
items: true
|
|
9016
|
+
},
|
|
9017
|
+
multipleOf: {
|
|
9018
|
+
type: "number",
|
|
9019
|
+
exclusiveMinimum: 0
|
|
9020
|
+
},
|
|
9021
|
+
maximum: {
|
|
9022
|
+
type: "number"
|
|
9023
|
+
},
|
|
9024
|
+
exclusiveMaximum: {
|
|
9025
|
+
type: "number"
|
|
9026
|
+
},
|
|
9027
|
+
minimum: {
|
|
9028
|
+
type: "number"
|
|
9029
|
+
},
|
|
9030
|
+
exclusiveMinimum: {
|
|
9031
|
+
type: "number"
|
|
9032
|
+
},
|
|
9033
|
+
maxLength: { $ref: "#/definitions/nonNegativeInteger" },
|
|
9034
|
+
minLength: { $ref: "#/definitions/nonNegativeIntegerDefault0" },
|
|
9035
|
+
pattern: {
|
|
9036
|
+
type: "string",
|
|
9037
|
+
format: "regex"
|
|
9038
|
+
},
|
|
9039
|
+
additionalItems: { $ref: "#" },
|
|
9040
|
+
items: {
|
|
9041
|
+
anyOf: [{ $ref: "#" }, { $ref: "#/definitions/schemaArray" }],
|
|
9042
|
+
default: true
|
|
9043
|
+
},
|
|
9044
|
+
maxItems: { $ref: "#/definitions/nonNegativeInteger" },
|
|
9045
|
+
minItems: { $ref: "#/definitions/nonNegativeIntegerDefault0" },
|
|
9046
|
+
uniqueItems: {
|
|
9047
|
+
type: "boolean",
|
|
9048
|
+
default: false
|
|
9049
|
+
},
|
|
9050
|
+
contains: { $ref: "#" },
|
|
9051
|
+
maxProperties: { $ref: "#/definitions/nonNegativeInteger" },
|
|
9052
|
+
minProperties: { $ref: "#/definitions/nonNegativeIntegerDefault0" },
|
|
9053
|
+
required: { $ref: "#/definitions/stringArray" },
|
|
9054
|
+
additionalProperties: { $ref: "#" },
|
|
9055
|
+
definitions: {
|
|
9056
|
+
type: "object",
|
|
9057
|
+
additionalProperties: { $ref: "#" },
|
|
9058
|
+
default: {}
|
|
9059
|
+
},
|
|
9060
|
+
properties: {
|
|
9061
|
+
type: "object",
|
|
9062
|
+
additionalProperties: { $ref: "#" },
|
|
9063
|
+
default: {}
|
|
9064
|
+
},
|
|
9065
|
+
patternProperties: {
|
|
9066
|
+
type: "object",
|
|
9067
|
+
additionalProperties: { $ref: "#" },
|
|
9068
|
+
propertyNames: { format: "regex" },
|
|
9069
|
+
default: {}
|
|
9070
|
+
},
|
|
9071
|
+
dependencies: {
|
|
9072
|
+
type: "object",
|
|
9073
|
+
additionalProperties: {
|
|
9074
|
+
anyOf: [{ $ref: "#" }, { $ref: "#/definitions/stringArray" }]
|
|
9075
|
+
}
|
|
9076
|
+
},
|
|
9077
|
+
propertyNames: { $ref: "#" },
|
|
9078
|
+
const: true,
|
|
9079
|
+
enum: {
|
|
9080
|
+
type: "array",
|
|
9081
|
+
items: true,
|
|
9082
|
+
minItems: 1,
|
|
9083
|
+
uniqueItems: true
|
|
9084
|
+
},
|
|
9085
|
+
type: {
|
|
9086
|
+
anyOf: [
|
|
9087
|
+
{ $ref: "#/definitions/simpleTypes" },
|
|
9088
|
+
{
|
|
9089
|
+
type: "array",
|
|
9090
|
+
items: { $ref: "#/definitions/simpleTypes" },
|
|
9091
|
+
minItems: 1,
|
|
9092
|
+
uniqueItems: true
|
|
9093
|
+
}
|
|
9094
|
+
]
|
|
9095
|
+
},
|
|
9096
|
+
format: { type: "string" },
|
|
9097
|
+
contentMediaType: { type: "string" },
|
|
9098
|
+
contentEncoding: { type: "string" },
|
|
9099
|
+
if: { $ref: "#" },
|
|
9100
|
+
then: { $ref: "#" },
|
|
9101
|
+
else: { $ref: "#" },
|
|
9102
|
+
allOf: { $ref: "#/definitions/schemaArray" },
|
|
9103
|
+
anyOf: { $ref: "#/definitions/schemaArray" },
|
|
9104
|
+
oneOf: { $ref: "#/definitions/schemaArray" },
|
|
9105
|
+
not: { $ref: "#" }
|
|
9106
|
+
},
|
|
9107
|
+
default: true
|
|
9108
|
+
};
|
|
9109
|
+
});
|
|
9110
|
+
|
|
9111
|
+
// node_modules/.bun/ajv@8.18.0/node_modules/ajv/dist/ajv.js
|
|
9112
|
+
var require_ajv = __commonJS((exports, module) => {
|
|
9113
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9114
|
+
exports.MissingRefError = exports.ValidationError = exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = exports.Ajv = undefined;
|
|
9115
|
+
var core_1 = require_core();
|
|
9116
|
+
var draft7_1 = require_draft7();
|
|
9117
|
+
var discriminator_1 = require_discriminator();
|
|
9118
|
+
var draft7MetaSchema = require_json_schema_draft_07();
|
|
9119
|
+
var META_SUPPORT_DATA = ["/properties"];
|
|
9120
|
+
var META_SCHEMA_ID = "http://json-schema.org/draft-07/schema";
|
|
9121
|
+
|
|
9122
|
+
class Ajv extends core_1.default {
|
|
9123
|
+
_addVocabularies() {
|
|
9124
|
+
super._addVocabularies();
|
|
9125
|
+
draft7_1.default.forEach((v) => this.addVocabulary(v));
|
|
9126
|
+
if (this.opts.discriminator)
|
|
9127
|
+
this.addKeyword(discriminator_1.default);
|
|
9128
|
+
}
|
|
9129
|
+
_addDefaultMetaSchema() {
|
|
9130
|
+
super._addDefaultMetaSchema();
|
|
9131
|
+
if (!this.opts.meta)
|
|
9132
|
+
return;
|
|
9133
|
+
const metaSchema = this.opts.$data ? this.$dataMetaSchema(draft7MetaSchema, META_SUPPORT_DATA) : draft7MetaSchema;
|
|
9134
|
+
this.addMetaSchema(metaSchema, META_SCHEMA_ID, false);
|
|
9135
|
+
this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID;
|
|
9136
|
+
}
|
|
9137
|
+
defaultMeta() {
|
|
9138
|
+
return this.opts.defaultMeta = super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined);
|
|
9139
|
+
}
|
|
9140
|
+
}
|
|
9141
|
+
exports.Ajv = Ajv;
|
|
9142
|
+
module.exports = exports = Ajv;
|
|
9143
|
+
module.exports.Ajv = Ajv;
|
|
9144
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9145
|
+
exports.default = Ajv;
|
|
9146
|
+
var validate_1 = require_validate();
|
|
9147
|
+
Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
|
|
9148
|
+
return validate_1.KeywordCxt;
|
|
9149
|
+
} });
|
|
9150
|
+
var codegen_1 = require_codegen();
|
|
9151
|
+
Object.defineProperty(exports, "_", { enumerable: true, get: function() {
|
|
9152
|
+
return codegen_1._;
|
|
9153
|
+
} });
|
|
9154
|
+
Object.defineProperty(exports, "str", { enumerable: true, get: function() {
|
|
9155
|
+
return codegen_1.str;
|
|
9156
|
+
} });
|
|
9157
|
+
Object.defineProperty(exports, "stringify", { enumerable: true, get: function() {
|
|
9158
|
+
return codegen_1.stringify;
|
|
9159
|
+
} });
|
|
9160
|
+
Object.defineProperty(exports, "nil", { enumerable: true, get: function() {
|
|
9161
|
+
return codegen_1.nil;
|
|
9162
|
+
} });
|
|
9163
|
+
Object.defineProperty(exports, "Name", { enumerable: true, get: function() {
|
|
9164
|
+
return codegen_1.Name;
|
|
9165
|
+
} });
|
|
9166
|
+
Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
|
|
9167
|
+
return codegen_1.CodeGen;
|
|
9168
|
+
} });
|
|
9169
|
+
var validation_error_1 = require_validation_error();
|
|
9170
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function() {
|
|
9171
|
+
return validation_error_1.default;
|
|
9172
|
+
} });
|
|
9173
|
+
var ref_error_1 = require_ref_error();
|
|
9174
|
+
Object.defineProperty(exports, "MissingRefError", { enumerable: true, get: function() {
|
|
9175
|
+
return ref_error_1.default;
|
|
9176
|
+
} });
|
|
9177
|
+
});
|
|
9178
|
+
|
|
9179
|
+
// node_modules/.bun/ajv-formats@3.0.1/node_modules/ajv-formats/dist/limit.js
|
|
9180
|
+
var require_limit = __commonJS((exports) => {
|
|
9181
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9182
|
+
exports.formatLimitDefinition = undefined;
|
|
9183
|
+
var ajv_1 = require_ajv();
|
|
9184
|
+
var codegen_1 = require_codegen();
|
|
9185
|
+
var ops = codegen_1.operators;
|
|
9186
|
+
var KWDs = {
|
|
9187
|
+
formatMaximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
|
|
9188
|
+
formatMinimum: { okStr: ">=", ok: ops.GTE, fail: ops.LT },
|
|
9189
|
+
formatExclusiveMaximum: { okStr: "<", ok: ops.LT, fail: ops.GTE },
|
|
9190
|
+
formatExclusiveMinimum: { okStr: ">", ok: ops.GT, fail: ops.LTE }
|
|
9191
|
+
};
|
|
9192
|
+
var error48 = {
|
|
9193
|
+
message: ({ keyword, schemaCode }) => (0, codegen_1.str)`should be ${KWDs[keyword].okStr} ${schemaCode}`,
|
|
9194
|
+
params: ({ keyword, schemaCode }) => (0, codegen_1._)`{comparison: ${KWDs[keyword].okStr}, limit: ${schemaCode}}`
|
|
9195
|
+
};
|
|
9196
|
+
exports.formatLimitDefinition = {
|
|
9197
|
+
keyword: Object.keys(KWDs),
|
|
9198
|
+
type: "string",
|
|
9199
|
+
schemaType: "string",
|
|
9200
|
+
$data: true,
|
|
9201
|
+
error: error48,
|
|
9202
|
+
code(cxt) {
|
|
9203
|
+
const { gen, data, schemaCode, keyword, it } = cxt;
|
|
9204
|
+
const { opts, self } = it;
|
|
9205
|
+
if (!opts.validateFormats)
|
|
9206
|
+
return;
|
|
9207
|
+
const fCxt = new ajv_1.KeywordCxt(it, self.RULES.all.format.definition, "format");
|
|
9208
|
+
if (fCxt.$data)
|
|
9209
|
+
validate$DataFormat();
|
|
9210
|
+
else
|
|
9211
|
+
validateFormat();
|
|
9212
|
+
function validate$DataFormat() {
|
|
9213
|
+
const fmts = gen.scopeValue("formats", {
|
|
9214
|
+
ref: self.formats,
|
|
9215
|
+
code: opts.code.formats
|
|
9216
|
+
});
|
|
9217
|
+
const fmt = gen.const("fmt", (0, codegen_1._)`${fmts}[${fCxt.schemaCode}]`);
|
|
9218
|
+
cxt.fail$data((0, codegen_1.or)((0, codegen_1._)`typeof ${fmt} != "object"`, (0, codegen_1._)`${fmt} instanceof RegExp`, (0, codegen_1._)`typeof ${fmt}.compare != "function"`, compareCode(fmt)));
|
|
9219
|
+
}
|
|
9220
|
+
function validateFormat() {
|
|
9221
|
+
const format = fCxt.schema;
|
|
9222
|
+
const fmtDef = self.formats[format];
|
|
9223
|
+
if (!fmtDef || fmtDef === true)
|
|
9224
|
+
return;
|
|
9225
|
+
if (typeof fmtDef != "object" || fmtDef instanceof RegExp || typeof fmtDef.compare != "function") {
|
|
9226
|
+
throw new Error(`"${keyword}": format "${format}" does not define "compare" function`);
|
|
9227
|
+
}
|
|
9228
|
+
const fmt = gen.scopeValue("formats", {
|
|
9229
|
+
key: format,
|
|
9230
|
+
ref: fmtDef,
|
|
9231
|
+
code: opts.code.formats ? (0, codegen_1._)`${opts.code.formats}${(0, codegen_1.getProperty)(format)}` : undefined
|
|
9232
|
+
});
|
|
9233
|
+
cxt.fail$data(compareCode(fmt));
|
|
9234
|
+
}
|
|
9235
|
+
function compareCode(fmt) {
|
|
9236
|
+
return (0, codegen_1._)`${fmt}.compare(${data}, ${schemaCode}) ${KWDs[keyword].fail} 0`;
|
|
9237
|
+
}
|
|
9238
|
+
},
|
|
9239
|
+
dependencies: ["format"]
|
|
9240
|
+
};
|
|
9241
|
+
var formatLimitPlugin = (ajv) => {
|
|
9242
|
+
ajv.addKeyword(exports.formatLimitDefinition);
|
|
9243
|
+
return ajv;
|
|
9244
|
+
};
|
|
9245
|
+
exports.default = formatLimitPlugin;
|
|
9246
|
+
});
|
|
9247
|
+
|
|
9248
|
+
// node_modules/.bun/ajv-formats@3.0.1/node_modules/ajv-formats/dist/index.js
|
|
9249
|
+
var require_dist2 = __commonJS((exports, module) => {
|
|
9250
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9251
|
+
var formats_1 = require_formats();
|
|
9252
|
+
var limit_1 = require_limit();
|
|
9253
|
+
var codegen_1 = require_codegen();
|
|
9254
|
+
var fullName = new codegen_1.Name("fullFormats");
|
|
9255
|
+
var fastName = new codegen_1.Name("fastFormats");
|
|
9256
|
+
var formatsPlugin = (ajv, opts = { keywords: true }) => {
|
|
9257
|
+
if (Array.isArray(opts)) {
|
|
9258
|
+
addFormats(ajv, opts, formats_1.fullFormats, fullName);
|
|
9259
|
+
return ajv;
|
|
9260
|
+
}
|
|
9261
|
+
const [formats, exportName] = opts.mode === "fast" ? [formats_1.fastFormats, fastName] : [formats_1.fullFormats, fullName];
|
|
9262
|
+
const list = opts.formats || formats_1.formatNames;
|
|
9263
|
+
addFormats(ajv, list, formats, exportName);
|
|
9264
|
+
if (opts.keywords)
|
|
9265
|
+
(0, limit_1.default)(ajv);
|
|
9266
|
+
return ajv;
|
|
9267
|
+
};
|
|
9268
|
+
formatsPlugin.get = (name21, mode = "full") => {
|
|
9269
|
+
const formats = mode === "fast" ? formats_1.fastFormats : formats_1.fullFormats;
|
|
9270
|
+
const f = formats[name21];
|
|
9271
|
+
if (!f)
|
|
9272
|
+
throw new Error(`Unknown format "${name21}"`);
|
|
9273
|
+
return f;
|
|
9274
|
+
};
|
|
9275
|
+
function addFormats(ajv, list, fs, exportName) {
|
|
9276
|
+
var _a21;
|
|
9277
|
+
var _b16;
|
|
9278
|
+
(_a21 = (_b16 = ajv.opts.code).formats) !== null && _a21 !== undefined || (_b16.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`);
|
|
9279
|
+
for (const f of list)
|
|
9280
|
+
ajv.addFormat(f, fs[f]);
|
|
9281
|
+
}
|
|
9282
|
+
module.exports = exports = formatsPlugin;
|
|
9283
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9284
|
+
exports.default = formatsPlugin;
|
|
9285
|
+
});
|
|
9286
|
+
|
|
8760
9287
|
// src/cli.ts
|
|
8761
|
-
import { existsSync as existsSync8, readFileSync as
|
|
9288
|
+
import { existsSync as existsSync8, readFileSync as readFileSync8 } from "fs";
|
|
8762
9289
|
import { setTimeout as sleep2 } from "timers/promises";
|
|
8763
|
-
import { parseArgs as
|
|
9290
|
+
import { parseArgs as parseArgs3 } from "util";
|
|
8764
9291
|
|
|
8765
9292
|
// src/config.ts
|
|
8766
9293
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
@@ -9985,12 +10512,12 @@ function resolveLogBaseDir(logConfig) {
|
|
|
9985
10512
|
}
|
|
9986
10513
|
|
|
9987
10514
|
// src/cli/process.ts
|
|
9988
|
-
import { closeSync, openSync, readFileSync as
|
|
10515
|
+
import { closeSync, openSync, readFileSync as readFileSync6, statSync } from "fs";
|
|
9989
10516
|
import { setTimeout as sleep } from "timers/promises";
|
|
9990
10517
|
import { parseArgs } from "util";
|
|
9991
10518
|
|
|
9992
10519
|
// src/index.ts
|
|
9993
|
-
import { readFileSync as
|
|
10520
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
9994
10521
|
|
|
9995
10522
|
// node_modules/.bun/@ai-sdk+provider@3.0.8/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
9996
10523
|
var marker = "vercel.ai.error";
|
|
@@ -49066,9 +49593,6 @@ var middleware = (options) => async (c2) => {
|
|
|
49066
49593
|
`);
|
|
49067
49594
|
};
|
|
49068
49595
|
|
|
49069
|
-
// src/index.ts
|
|
49070
|
-
var import__2020 = __toESM(require_2020(), 1);
|
|
49071
|
-
|
|
49072
49596
|
// node_modules/.bun/hono@4.12.5/node_modules/hono/dist/compose.js
|
|
49073
49597
|
var compose = (middleware2, onError, onNotFound) => {
|
|
49074
49598
|
return (context2, next) => {
|
|
@@ -53919,6 +54443,37 @@ function getBundledWebRoot() {
|
|
|
53919
54443
|
return resolveBundledAssetPath("../dist/web/");
|
|
53920
54444
|
}
|
|
53921
54445
|
|
|
54446
|
+
// src/config-validate.ts
|
|
54447
|
+
var import__2020 = __toESM(require_2020(), 1);
|
|
54448
|
+
var import_ajv_formats = __toESM(require_dist2(), 1);
|
|
54449
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
54450
|
+
function validateBusinessRules(config2) {
|
|
54451
|
+
for (const [routeType, modelMap] of Object.entries(config2.routes)) {
|
|
54452
|
+
if (!modelMap["*"]) {
|
|
54453
|
+
throw new Error(`\u8DEF\u7531 "${routeType}" \u7F3A\u5C11 "*" \u515C\u5E95\u89C4\u5219`);
|
|
54454
|
+
}
|
|
54455
|
+
for (const target of Object.values(modelMap)) {
|
|
54456
|
+
if (!config2.providers[target.provider]) {
|
|
54457
|
+
throw new Error(`\u8DEF\u7531 "${routeType}" \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 provider "${target.provider}"`);
|
|
54458
|
+
}
|
|
54459
|
+
}
|
|
54460
|
+
}
|
|
54461
|
+
}
|
|
54462
|
+
function validateConfigOrThrow(config2) {
|
|
54463
|
+
validateBusinessRules(config2);
|
|
54464
|
+
const ajv = new import__2020.default({ allErrors: true, strict: false });
|
|
54465
|
+
import_ajv_formats.default(ajv);
|
|
54466
|
+
const schemaJson = JSON.parse(readFileSync3(getBundledSchemaPath(), "utf-8"));
|
|
54467
|
+
const validateBySchema = ajv.compile(schemaJson);
|
|
54468
|
+
const valid = validateBySchema(config2);
|
|
54469
|
+
if (!valid) {
|
|
54470
|
+
const firstError = validateBySchema.errors?.[0];
|
|
54471
|
+
const path = firstError?.instancePath || "(root)";
|
|
54472
|
+
const message = firstError?.message ?? "unknown schema validation error";
|
|
54473
|
+
throw new Error(`Schema \u6821\u9A8C\u5931\u8D25: ${path} ${message}`);
|
|
54474
|
+
}
|
|
54475
|
+
}
|
|
54476
|
+
|
|
53922
54477
|
// src/index.ts
|
|
53923
54478
|
var ROUTE_REGISTRY = {
|
|
53924
54479
|
"openai-completions": {
|
|
@@ -54037,10 +54592,8 @@ function createAdminApiRoutes(store, registerCleanup) {
|
|
|
54037
54592
|
const cryptoSessions = new Map;
|
|
54038
54593
|
const CRYPTO_SESSION_TTL_MS = 2 * 60 * 1000;
|
|
54039
54594
|
const CRYPTO_SESSION_MAX = 512;
|
|
54040
|
-
const ajv = new import__2020.default({ allErrors: true, strict: false });
|
|
54041
54595
|
const schemaPath = getBundledSchemaPath();
|
|
54042
|
-
const schemaJson = JSON.parse(
|
|
54043
|
-
const validateBySchema = ajv.compile(schemaJson);
|
|
54596
|
+
const schemaJson = JSON.parse(readFileSync4(schemaPath, "utf-8"));
|
|
54044
54597
|
const pruneExpiredCryptoSessions = (now2 = Date.now()) => {
|
|
54045
54598
|
for (const [id, record2] of Array.from(cryptoSessions.entries())) {
|
|
54046
54599
|
if (now2 - record2.createdAt > CRYPTO_SESSION_TTL_MS) {
|
|
@@ -54134,12 +54687,10 @@ function createAdminApiRoutes(store, registerCleanup) {
|
|
|
54134
54687
|
} catch (err) {
|
|
54135
54688
|
return c2.json({ error: `\u914D\u7F6E\u6821\u9A8C\u5931\u8D25: ${err instanceof Error ? err.message : err}` }, 400);
|
|
54136
54689
|
}
|
|
54137
|
-
|
|
54138
|
-
|
|
54139
|
-
|
|
54140
|
-
|
|
54141
|
-
const message = firstError?.message ?? "unknown schema validation error";
|
|
54142
|
-
return c2.json({ error: `Schema \u6821\u9A8C\u5931\u8D25: ${path} ${message}` }, 400);
|
|
54690
|
+
try {
|
|
54691
|
+
validateConfigOrThrow(candidate);
|
|
54692
|
+
} catch (err) {
|
|
54693
|
+
return c2.json({ error: `\u914D\u7F6E\u6821\u9A8C\u5931\u8D25: ${err instanceof Error ? err.message : err}` }, 400);
|
|
54143
54694
|
}
|
|
54144
54695
|
store.save(candidate);
|
|
54145
54696
|
return c2.json({ ok: true });
|
|
@@ -54674,7 +55225,7 @@ function startServer(options) {
|
|
|
54674
55225
|
}
|
|
54675
55226
|
|
|
54676
55227
|
// src/cli/runtime.ts
|
|
54677
|
-
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as
|
|
55228
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync5, rmSync, writeFileSync as writeFileSync4 } from "fs";
|
|
54678
55229
|
import { homedir as homedir2 } from "os";
|
|
54679
55230
|
import { join as join9, resolve as resolve5 } from "path";
|
|
54680
55231
|
function getRuntimeDirs() {
|
|
@@ -54712,7 +55263,7 @@ function readRuntimeState() {
|
|
|
54712
55263
|
return null;
|
|
54713
55264
|
}
|
|
54714
55265
|
try {
|
|
54715
|
-
return JSON.parse(
|
|
55266
|
+
return JSON.parse(readFileSync5(files.state, "utf-8"));
|
|
54716
55267
|
} catch {
|
|
54717
55268
|
return null;
|
|
54718
55269
|
}
|
|
@@ -54894,7 +55445,7 @@ async function startDaemon(flags) {
|
|
|
54894
55445
|
}
|
|
54895
55446
|
let tail = "";
|
|
54896
55447
|
try {
|
|
54897
|
-
const content =
|
|
55448
|
+
const content = readFileSync6(files.daemonLog, "utf-8");
|
|
54898
55449
|
tail = content.split(`
|
|
54899
55450
|
`).slice(-20).join(`
|
|
54900
55451
|
`);
|
|
@@ -54931,7 +55482,7 @@ function readLogDelta(filePath, offset) {
|
|
|
54931
55482
|
if (stats.size <= offset) {
|
|
54932
55483
|
return { content: "", nextOffset: offset };
|
|
54933
55484
|
}
|
|
54934
|
-
const full =
|
|
55485
|
+
const full = readFileSync6(filePath, "utf-8");
|
|
54935
55486
|
const content = full.slice(offset);
|
|
54936
55487
|
return { content, nextOffset: full.length };
|
|
54937
55488
|
} catch {
|
|
@@ -54939,6 +55490,454 @@ function readLogDelta(filePath, offset) {
|
|
|
54939
55490
|
}
|
|
54940
55491
|
}
|
|
54941
55492
|
|
|
55493
|
+
// src/cli/config-command.ts
|
|
55494
|
+
import { createInterface as createInterface4 } from "readline/promises";
|
|
55495
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "fs";
|
|
55496
|
+
import { dirname as dirname2, join as join10 } from "path";
|
|
55497
|
+
import { parseArgs as parseArgs2 } from "util";
|
|
55498
|
+
function readConfig(configArg) {
|
|
55499
|
+
const path = resolveConfigPath(configArg);
|
|
55500
|
+
return { path, config: loadConfig(path) };
|
|
55501
|
+
}
|
|
55502
|
+
function saveConfig(path, config2) {
|
|
55503
|
+
validateConfigOrThrow(config2);
|
|
55504
|
+
const backupDir = join10(dirname2(path), ".backups");
|
|
55505
|
+
mkdirSync4(backupDir, { recursive: true });
|
|
55506
|
+
const backupPath = join10(backupDir, `config-${Date.now()}.json5`);
|
|
55507
|
+
writeFileSync5(backupPath, readFileSync7(path, "utf-8"), "utf-8");
|
|
55508
|
+
const content = dist_default.stringify(config2, { space: 2, quote: '"' });
|
|
55509
|
+
writeFileSync5(path, content, "utf-8");
|
|
55510
|
+
}
|
|
55511
|
+
function maskApiKey(k) {
|
|
55512
|
+
if (k.length <= 8)
|
|
55513
|
+
return "***";
|
|
55514
|
+
return `${k.slice(0, 4)}***${k.slice(-4)}`;
|
|
55515
|
+
}
|
|
55516
|
+
function providerTypes() {
|
|
55517
|
+
return ["openai-completions", "openai-responses", "anthropic-messages"];
|
|
55518
|
+
}
|
|
55519
|
+
async function selectFromList(title, items) {
|
|
55520
|
+
if (items.length === 0)
|
|
55521
|
+
throw new Error(`${title}: \u65E0\u53EF\u9009\u9879`);
|
|
55522
|
+
console.log(`${title}:`);
|
|
55523
|
+
items.forEach((item, i) => console.log(` ${i + 1}) ${item}`));
|
|
55524
|
+
const rl = createInterface4({ input: process.stdin, output: process.stdout });
|
|
55525
|
+
try {
|
|
55526
|
+
const answer = await rl.question("\u8BF7\u8F93\u5165\u5E8F\u53F7: ");
|
|
55527
|
+
const idx = Number.parseInt(answer, 10) - 1;
|
|
55528
|
+
if (!Number.isFinite(idx) || idx < 0 || idx >= items.length) {
|
|
55529
|
+
throw new Error("\u65E0\u6548\u9009\u62E9");
|
|
55530
|
+
}
|
|
55531
|
+
return items[idx];
|
|
55532
|
+
} finally {
|
|
55533
|
+
rl.close();
|
|
55534
|
+
}
|
|
55535
|
+
}
|
|
55536
|
+
function printConfigHelp() {
|
|
55537
|
+
console.log(`
|
|
55538
|
+
local-router config
|
|
55539
|
+
|
|
55540
|
+
Commands:
|
|
55541
|
+
config provider list [--json] [--config <path>]
|
|
55542
|
+
config provider show <name> [--show-secrets] [--json] [--config <path>]
|
|
55543
|
+
config provider add <name> --type <type> --base <url> --api-key <key> --model <name> [--image-input] [--reasoning] [--config <path>]
|
|
55544
|
+
config provider set <name> [--base <url>] [--api-key <key>] [--proxy <url>] [--config <path>]
|
|
55545
|
+
config provider remove <name> [--force] [--config <path>]
|
|
55546
|
+
config provider model list <provider> [--json] [--config <path>]
|
|
55547
|
+
config provider model add <provider> <model> [--image-input] [--reasoning] [--config <path>]
|
|
55548
|
+
config provider model set <provider> <model> [--image-input <true|false>] [--reasoning <true|false>] [--config <path>]
|
|
55549
|
+
config provider model remove <provider> <model> [--config <path>]
|
|
55550
|
+
|
|
55551
|
+
config route list [--entry <entry>] [--json] [--config <path>]
|
|
55552
|
+
config route show <entry> [--json] [--config <path>]
|
|
55553
|
+
config route set <entry> <match-model> [--provider <name>] [--model <model>] [--interactive] [--config <path>]
|
|
55554
|
+
config route remove <entry> <match-model> [--allow-remove-fallback] [--config <path>]
|
|
55555
|
+
|
|
55556
|
+
config resolve --entry <entry> --model <request-model> [--json] [--config <path>]
|
|
55557
|
+
config validate [--config <path>]
|
|
55558
|
+
config apply
|
|
55559
|
+
`);
|
|
55560
|
+
}
|
|
55561
|
+
function parseBool(v) {
|
|
55562
|
+
if (v === undefined)
|
|
55563
|
+
return;
|
|
55564
|
+
if (v === "true")
|
|
55565
|
+
return true;
|
|
55566
|
+
if (v === "false")
|
|
55567
|
+
return false;
|
|
55568
|
+
throw new Error(`\u65E0\u6548\u5E03\u5C14\u503C: ${v}`);
|
|
55569
|
+
}
|
|
55570
|
+
function requireProvider(config2, name21) {
|
|
55571
|
+
const p = config2.providers[name21];
|
|
55572
|
+
if (!p)
|
|
55573
|
+
throw new Error(`provider \u4E0D\u5B58\u5728: ${name21}`);
|
|
55574
|
+
return p;
|
|
55575
|
+
}
|
|
55576
|
+
async function handleProvider(args) {
|
|
55577
|
+
const [sub, ...rest] = args;
|
|
55578
|
+
if (sub === "list") {
|
|
55579
|
+
const parsed = parseArgs2({ args: rest, options: { json: { type: "boolean", default: false }, config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55580
|
+
const { config: config2 } = readConfig(parsed.values.config);
|
|
55581
|
+
const rows = Object.entries(config2.providers).map(([name21, p]) => ({ name: name21, type: p.type, base: p.base, models: Object.keys(p.models).length, proxy: p.proxy ?? "" }));
|
|
55582
|
+
if (parsed.values.json)
|
|
55583
|
+
return void console.log(JSON.stringify(rows, null, 2));
|
|
55584
|
+
console.log("NAME\tTYPE\tMODELS\tBASE");
|
|
55585
|
+
rows.forEach((r) => console.log(`${r.name} ${r.type} ${r.models} ${r.base}`));
|
|
55586
|
+
return;
|
|
55587
|
+
}
|
|
55588
|
+
if (sub === "show") {
|
|
55589
|
+
const [name21, ...flagArgs] = rest;
|
|
55590
|
+
if (!name21)
|
|
55591
|
+
throw new Error("\u7528\u6CD5: config provider show <name>");
|
|
55592
|
+
const parsed = parseArgs2({ args: flagArgs, options: { json: { type: "boolean", default: false }, "show-secrets": { type: "boolean", default: false }, config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55593
|
+
const { config: config2 } = readConfig(parsed.values.config);
|
|
55594
|
+
const p = requireProvider(config2, name21);
|
|
55595
|
+
const out = { ...p, apiKey: parsed.values["show-secrets"] ? p.apiKey : maskApiKey(p.apiKey) };
|
|
55596
|
+
if (parsed.values.json)
|
|
55597
|
+
return void console.log(JSON.stringify(out, null, 2));
|
|
55598
|
+
console.log(JSON.stringify(out, null, 2));
|
|
55599
|
+
return;
|
|
55600
|
+
}
|
|
55601
|
+
if (sub === "add") {
|
|
55602
|
+
const [name21, ...flagArgs] = rest;
|
|
55603
|
+
if (!name21)
|
|
55604
|
+
throw new Error("\u7528\u6CD5: config provider add <name> --type <type> --base <url> --api-key <key> --model <name>");
|
|
55605
|
+
const parsed = parseArgs2({ args: flagArgs, options: { type: { type: "string" }, base: { type: "string" }, "api-key": { type: "string" }, model: { type: "string" }, "image-input": { type: "boolean", default: false }, reasoning: { type: "boolean", default: false }, proxy: { type: "string" }, config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55606
|
+
const { path, config: config2 } = readConfig(parsed.values.config);
|
|
55607
|
+
if (config2.providers[name21])
|
|
55608
|
+
throw new Error(`provider \u5DF2\u5B58\u5728: ${name21}`);
|
|
55609
|
+
const type = parsed.values.type;
|
|
55610
|
+
if (!type || !providerTypes().includes(type))
|
|
55611
|
+
throw new Error("type \u5FC5\u586B\u4E14\u5FC5\u987B\u662F openai-completions/openai-responses/anthropic-messages");
|
|
55612
|
+
const base = parsed.values.base;
|
|
55613
|
+
const apiKey = parsed.values["api-key"];
|
|
55614
|
+
const firstModel = parsed.values.model;
|
|
55615
|
+
if (!base || !apiKey || !firstModel)
|
|
55616
|
+
throw new Error("base/api-key/model \u5FC5\u586B");
|
|
55617
|
+
config2.providers[name21] = {
|
|
55618
|
+
type,
|
|
55619
|
+
base,
|
|
55620
|
+
apiKey,
|
|
55621
|
+
models: {
|
|
55622
|
+
[firstModel]: {
|
|
55623
|
+
"image-input": parsed.values["image-input"],
|
|
55624
|
+
reasoning: parsed.values.reasoning
|
|
55625
|
+
}
|
|
55626
|
+
},
|
|
55627
|
+
...parsed.values.proxy ? { proxy: parsed.values.proxy } : {}
|
|
55628
|
+
};
|
|
55629
|
+
saveConfig(path, config2);
|
|
55630
|
+
console.log(`\u5DF2\u6DFB\u52A0 provider: ${name21}`);
|
|
55631
|
+
return;
|
|
55632
|
+
}
|
|
55633
|
+
if (sub === "set") {
|
|
55634
|
+
const [name21, ...flagArgs] = rest;
|
|
55635
|
+
if (!name21)
|
|
55636
|
+
throw new Error("\u7528\u6CD5: config provider set <name> [--base] [--api-key] [--proxy]");
|
|
55637
|
+
const parsed = parseArgs2({ args: flagArgs, options: { base: { type: "string" }, "api-key": { type: "string" }, proxy: { type: "string" }, config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55638
|
+
const { path, config: config2 } = readConfig(parsed.values.config);
|
|
55639
|
+
const p = requireProvider(config2, name21);
|
|
55640
|
+
if (parsed.values.base)
|
|
55641
|
+
p.base = parsed.values.base;
|
|
55642
|
+
if (parsed.values["api-key"])
|
|
55643
|
+
p.apiKey = parsed.values["api-key"];
|
|
55644
|
+
if (parsed.values.proxy !== undefined)
|
|
55645
|
+
p.proxy = parsed.values.proxy;
|
|
55646
|
+
saveConfig(path, config2);
|
|
55647
|
+
console.log(`\u5DF2\u66F4\u65B0 provider: ${name21}`);
|
|
55648
|
+
return;
|
|
55649
|
+
}
|
|
55650
|
+
if (sub === "remove") {
|
|
55651
|
+
const [name21, ...flagArgs] = rest;
|
|
55652
|
+
if (!name21)
|
|
55653
|
+
throw new Error("\u7528\u6CD5: config provider remove <name> [--force]");
|
|
55654
|
+
const parsed = parseArgs2({ args: flagArgs, options: { force: { type: "boolean", default: false }, config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55655
|
+
const { path, config: config2 } = readConfig(parsed.values.config);
|
|
55656
|
+
requireProvider(config2, name21);
|
|
55657
|
+
const referencedRoutes = [];
|
|
55658
|
+
for (const [entry, modelMap] of Object.entries(config2.routes)) {
|
|
55659
|
+
for (const [match2, target] of Object.entries(modelMap)) {
|
|
55660
|
+
if (target.provider === name21) {
|
|
55661
|
+
referencedRoutes.push({ entry, match: match2 });
|
|
55662
|
+
}
|
|
55663
|
+
}
|
|
55664
|
+
}
|
|
55665
|
+
if (referencedRoutes.length > 0 && !parsed.values.force) {
|
|
55666
|
+
const first = referencedRoutes[0];
|
|
55667
|
+
throw new Error(`provider ${name21} \u88AB\u8DEF\u7531\u5F15\u7528: ${first?.entry}.${first?.match}\uFF0C\u5982\u9700\u5220\u9664\u5E76\u8054\u52A8\u6E05\u7406\u8DEF\u7531\u8BF7\u52A0 --force`);
|
|
55668
|
+
}
|
|
55669
|
+
if (parsed.values.force) {
|
|
55670
|
+
for (const ref of referencedRoutes) {
|
|
55671
|
+
delete config2.routes[ref.entry]?.[ref.match];
|
|
55672
|
+
}
|
|
55673
|
+
for (const [entry, modelMap] of Object.entries(config2.routes)) {
|
|
55674
|
+
if (Object.keys(modelMap).length === 0) {
|
|
55675
|
+
delete config2.routes[entry];
|
|
55676
|
+
}
|
|
55677
|
+
}
|
|
55678
|
+
}
|
|
55679
|
+
delete config2.providers[name21];
|
|
55680
|
+
saveConfig(path, config2);
|
|
55681
|
+
if (parsed.values.force && referencedRoutes.length > 0) {
|
|
55682
|
+
console.log(`\u5DF2\u5220\u9664 provider: ${name21}\uFF0C\u5E76\u6E05\u7406 ${referencedRoutes.length} \u6761\u5173\u8054\u8DEF\u7531`);
|
|
55683
|
+
} else {
|
|
55684
|
+
console.log(`\u5DF2\u5220\u9664 provider: ${name21}`);
|
|
55685
|
+
}
|
|
55686
|
+
return;
|
|
55687
|
+
}
|
|
55688
|
+
if (sub === "model") {
|
|
55689
|
+
const [action, provider, model, ...flagArgs] = rest;
|
|
55690
|
+
if (!action)
|
|
55691
|
+
throw new Error("\u7528\u6CD5: config provider model <list|add|set|remove> ...");
|
|
55692
|
+
if (!provider)
|
|
55693
|
+
throw new Error("provider \u5FC5\u586B");
|
|
55694
|
+
if (action === "list") {
|
|
55695
|
+
const parsed = parseArgs2({
|
|
55696
|
+
args: flagArgs,
|
|
55697
|
+
options: { config: { type: "string" }, json: { type: "boolean", default: false } },
|
|
55698
|
+
allowPositionals: true,
|
|
55699
|
+
strict: false
|
|
55700
|
+
});
|
|
55701
|
+
const { config: config2 } = readConfig(parsed.values.config);
|
|
55702
|
+
const p = requireProvider(config2, provider);
|
|
55703
|
+
const rows = Object.entries(p.models).map(([name21, caps]) => ({ name: name21, ...caps }));
|
|
55704
|
+
if (parsed.values.json)
|
|
55705
|
+
return void console.log(JSON.stringify(rows, null, 2));
|
|
55706
|
+
rows.forEach((r) => console.log(`${r.name} image-input=${Boolean(r["image-input"])} reasoning=${Boolean(r.reasoning)}`));
|
|
55707
|
+
return;
|
|
55708
|
+
}
|
|
55709
|
+
if (!model)
|
|
55710
|
+
throw new Error("model \u5FC5\u586B");
|
|
55711
|
+
if (action === "add") {
|
|
55712
|
+
const parsed = parseArgs2({
|
|
55713
|
+
args: flagArgs,
|
|
55714
|
+
options: {
|
|
55715
|
+
"image-input": { type: "boolean", default: false },
|
|
55716
|
+
reasoning: { type: "boolean", default: false },
|
|
55717
|
+
config: { type: "string" }
|
|
55718
|
+
},
|
|
55719
|
+
allowPositionals: true,
|
|
55720
|
+
strict: false
|
|
55721
|
+
});
|
|
55722
|
+
const { path, config: config2 } = readConfig(parsed.values.config);
|
|
55723
|
+
const p = requireProvider(config2, provider);
|
|
55724
|
+
p.models[model] = {
|
|
55725
|
+
"image-input": parsed.values["image-input"],
|
|
55726
|
+
reasoning: parsed.values.reasoning
|
|
55727
|
+
};
|
|
55728
|
+
saveConfig(path, config2);
|
|
55729
|
+
console.log(`\u5DF2\u6DFB\u52A0 model: ${provider}/${model}`);
|
|
55730
|
+
return;
|
|
55731
|
+
}
|
|
55732
|
+
if (action === "set") {
|
|
55733
|
+
const parsed = parseArgs2({
|
|
55734
|
+
args: flagArgs,
|
|
55735
|
+
options: {
|
|
55736
|
+
"image-input": { type: "string" },
|
|
55737
|
+
reasoning: { type: "string" },
|
|
55738
|
+
config: { type: "string" }
|
|
55739
|
+
},
|
|
55740
|
+
allowPositionals: true,
|
|
55741
|
+
strict: false
|
|
55742
|
+
});
|
|
55743
|
+
const { path, config: config2 } = readConfig(parsed.values.config);
|
|
55744
|
+
const p = requireProvider(config2, provider);
|
|
55745
|
+
if (!p.models[model])
|
|
55746
|
+
throw new Error(`model \u4E0D\u5B58\u5728: ${provider}/${model}`);
|
|
55747
|
+
if (parsed.values["image-input"] !== undefined) {
|
|
55748
|
+
p.models[model]["image-input"] = parseBool(parsed.values["image-input"]);
|
|
55749
|
+
}
|
|
55750
|
+
if (parsed.values.reasoning !== undefined) {
|
|
55751
|
+
p.models[model].reasoning = parseBool(parsed.values.reasoning);
|
|
55752
|
+
}
|
|
55753
|
+
saveConfig(path, config2);
|
|
55754
|
+
console.log(`\u5DF2\u66F4\u65B0 model: ${provider}/${model}`);
|
|
55755
|
+
return;
|
|
55756
|
+
}
|
|
55757
|
+
if (action === "remove") {
|
|
55758
|
+
const parsed = parseArgs2({
|
|
55759
|
+
args: flagArgs,
|
|
55760
|
+
options: { config: { type: "string" } },
|
|
55761
|
+
allowPositionals: true,
|
|
55762
|
+
strict: false
|
|
55763
|
+
});
|
|
55764
|
+
const { path, config: config2 } = readConfig(parsed.values.config);
|
|
55765
|
+
const p = requireProvider(config2, provider);
|
|
55766
|
+
delete p.models[model];
|
|
55767
|
+
saveConfig(path, config2);
|
|
55768
|
+
console.log(`\u5DF2\u5220\u9664 model: ${provider}/${model}`);
|
|
55769
|
+
return;
|
|
55770
|
+
}
|
|
55771
|
+
throw new Error(`\u672A\u77E5\u5B50\u547D\u4EE4: provider model ${action}`);
|
|
55772
|
+
}
|
|
55773
|
+
throw new Error(`\u672A\u77E5\u5B50\u547D\u4EE4: provider ${sub ?? ""}`);
|
|
55774
|
+
}
|
|
55775
|
+
function renderRouteRows(config2, entry) {
|
|
55776
|
+
const rows = [];
|
|
55777
|
+
for (const [entryName, modelMap] of Object.entries(config2.routes)) {
|
|
55778
|
+
if (entry && entryName !== entry)
|
|
55779
|
+
continue;
|
|
55780
|
+
for (const [match2, target] of Object.entries(modelMap)) {
|
|
55781
|
+
rows.push({ entry: entryName, match: match2, provider: target.provider, model: target.model });
|
|
55782
|
+
}
|
|
55783
|
+
}
|
|
55784
|
+
return rows;
|
|
55785
|
+
}
|
|
55786
|
+
async function handleRoute(args) {
|
|
55787
|
+
const [sub, ...rest] = args;
|
|
55788
|
+
if (sub === "list") {
|
|
55789
|
+
const parsed = parseArgs2({ args: rest, options: { entry: { type: "string" }, json: { type: "boolean", default: false }, config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55790
|
+
const { config: config2 } = readConfig(parsed.values.config);
|
|
55791
|
+
const rows = renderRouteRows(config2, parsed.values.entry);
|
|
55792
|
+
if (parsed.values.json)
|
|
55793
|
+
return void console.log(JSON.stringify(rows, null, 2));
|
|
55794
|
+
console.log("ENTRY\tMATCH\tTARGET");
|
|
55795
|
+
rows.forEach((r) => console.log(`${r.entry} ${r.match} ${r.provider}/${r.model}`));
|
|
55796
|
+
return;
|
|
55797
|
+
}
|
|
55798
|
+
if (sub === "show") {
|
|
55799
|
+
const [entry, ...flagArgs] = rest;
|
|
55800
|
+
if (!entry)
|
|
55801
|
+
throw new Error("\u7528\u6CD5: config route show <entry>");
|
|
55802
|
+
const parsed = parseArgs2({ args: flagArgs, options: { json: { type: "boolean", default: false }, config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55803
|
+
const { config: config2 } = readConfig(parsed.values.config);
|
|
55804
|
+
const modelMap = config2.routes[entry];
|
|
55805
|
+
if (!modelMap)
|
|
55806
|
+
throw new Error(`route entry \u4E0D\u5B58\u5728: ${entry}`);
|
|
55807
|
+
if (parsed.values.json)
|
|
55808
|
+
return void console.log(JSON.stringify(modelMap, null, 2));
|
|
55809
|
+
Object.entries(modelMap).forEach(([match2, target]) => console.log(`${entry}.${match2} -> ${target.provider}/${target.model}`));
|
|
55810
|
+
return;
|
|
55811
|
+
}
|
|
55812
|
+
if (sub === "set") {
|
|
55813
|
+
const [entry, matchModel, ...flagArgs] = rest;
|
|
55814
|
+
if (!entry || !matchModel)
|
|
55815
|
+
throw new Error("\u7528\u6CD5: config route set <entry> <match-model> [--provider] [--model]");
|
|
55816
|
+
const parsed = parseArgs2({ args: flagArgs, options: { provider: { type: "string" }, model: { type: "string" }, interactive: { type: "boolean", default: false }, config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55817
|
+
const { path, config: config2 } = readConfig(parsed.values.config);
|
|
55818
|
+
let provider = parsed.values.provider;
|
|
55819
|
+
let model = parsed.values.model;
|
|
55820
|
+
const shouldInteractive = parsed.values.interactive || !provider && !model;
|
|
55821
|
+
if (shouldInteractive) {
|
|
55822
|
+
if (!process.stdin.isTTY) {
|
|
55823
|
+
throw new Error("\u8BF7\u5728\u975E\u4EA4\u4E92\u73AF\u5883\u4E0B\u4F7F\u7528 --provider \u4E0E --model\uFF0C\u6216\u5728 TTY \u4E2D\u8FD0\u884C\u4EE5\u542F\u7528\u9009\u62E9\u5668");
|
|
55824
|
+
}
|
|
55825
|
+
const providerNames = Object.keys(config2.providers);
|
|
55826
|
+
if (providerNames.length === 0) {
|
|
55827
|
+
throw new Error("\u5F53\u524D\u6CA1\u6709 provider\uFF0C\u8BF7\u5148\u6267\u884C: local-router config provider add <name> ...");
|
|
55828
|
+
}
|
|
55829
|
+
provider = await selectFromList("\u8BF7\u9009\u62E9 provider", providerNames);
|
|
55830
|
+
const p2 = requireProvider(config2, provider);
|
|
55831
|
+
const models = Object.keys(p2.models);
|
|
55832
|
+
if (models.length === 0) {
|
|
55833
|
+
throw new Error(`provider ${provider} \u6CA1\u6709\u53EF\u9009 model\uFF0C\u8BF7\u5148\u6267\u884C: local-router config provider model add ${provider} <model>`);
|
|
55834
|
+
}
|
|
55835
|
+
model = await selectFromList(`\u8BF7\u9009\u62E9 ${provider} \u7684 model`, models);
|
|
55836
|
+
}
|
|
55837
|
+
if (!provider || !model)
|
|
55838
|
+
throw new Error("provider/model \u5FC5\u586B\uFF1B\u53EF\u901A\u8FC7 --provider/--model \u6307\u5B9A\uFF0C\u6216\u4F7F\u7528\u4EA4\u4E92\u6A21\u5F0F");
|
|
55839
|
+
const p = requireProvider(config2, provider);
|
|
55840
|
+
if (!p.models[model])
|
|
55841
|
+
throw new Error(`model \u4E0D\u5B58\u5728\u4E8E provider: ${provider}/${model}`);
|
|
55842
|
+
if (!config2.routes[entry])
|
|
55843
|
+
config2.routes[entry] = {};
|
|
55844
|
+
config2.routes[entry][matchModel] = { provider, model };
|
|
55845
|
+
saveConfig(path, config2);
|
|
55846
|
+
console.log(`\u5DF2\u8BBE\u7F6E\u8DEF\u7531: ${entry}.${matchModel} -> ${provider}/${model}`);
|
|
55847
|
+
return;
|
|
55848
|
+
}
|
|
55849
|
+
if (sub === "remove") {
|
|
55850
|
+
const [entry, matchModel, ...flagArgs] = rest;
|
|
55851
|
+
if (!entry || !matchModel)
|
|
55852
|
+
throw new Error("\u7528\u6CD5: config route remove <entry> <match-model> [--allow-remove-fallback]");
|
|
55853
|
+
const parsed = parseArgs2({ args: flagArgs, options: { "allow-remove-fallback": { type: "boolean", default: false }, config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55854
|
+
const { path, config: config2 } = readConfig(parsed.values.config);
|
|
55855
|
+
const modelMap = config2.routes[entry];
|
|
55856
|
+
if (!modelMap || !modelMap[matchModel])
|
|
55857
|
+
throw new Error(`\u8DEF\u7531\u4E0D\u5B58\u5728: ${entry}.${matchModel}`);
|
|
55858
|
+
if (matchModel === "*" && !parsed.values["allow-remove-fallback"]) {
|
|
55859
|
+
throw new Error("\u7981\u6B62\u5220\u9664 * \u515C\u5E95\u89C4\u5219\uFF0C\u5982\u9700\u5220\u9664\u8BF7\u52A0 --allow-remove-fallback");
|
|
55860
|
+
}
|
|
55861
|
+
delete modelMap[matchModel];
|
|
55862
|
+
saveConfig(path, config2);
|
|
55863
|
+
console.log(`\u5DF2\u5220\u9664\u8DEF\u7531: ${entry}.${matchModel}`);
|
|
55864
|
+
return;
|
|
55865
|
+
}
|
|
55866
|
+
throw new Error(`\u672A\u77E5\u5B50\u547D\u4EE4: route ${sub ?? ""}`);
|
|
55867
|
+
}
|
|
55868
|
+
async function handleResolve(args) {
|
|
55869
|
+
const parsed = parseArgs2({ args, options: { entry: { type: "string" }, model: { type: "string" }, json: { type: "boolean", default: false }, config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55870
|
+
const entry = parsed.values.entry;
|
|
55871
|
+
const reqModel = parsed.values.model;
|
|
55872
|
+
if (!entry || !reqModel)
|
|
55873
|
+
throw new Error("\u7528\u6CD5: config resolve --entry <entry> --model <request-model>");
|
|
55874
|
+
const { config: config2 } = readConfig(parsed.values.config);
|
|
55875
|
+
const modelMap = config2.routes[entry];
|
|
55876
|
+
if (!modelMap)
|
|
55877
|
+
throw new Error(`route entry \u4E0D\u5B58\u5728: ${entry}`);
|
|
55878
|
+
const hit = modelMap[reqModel] ? reqModel : "*";
|
|
55879
|
+
const target = modelMap[hit];
|
|
55880
|
+
if (!target)
|
|
55881
|
+
throw new Error(`\u672A\u547D\u4E2D\u8DEF\u7531\u4E14\u7F3A\u5C11\u515C\u5E95: ${entry}`);
|
|
55882
|
+
const provider = requireProvider(config2, target.provider);
|
|
55883
|
+
const payload = { matchedRule: `${entry}.${hit}`, provider: target.provider, targetModel: target.model, providerType: provider.type, providerBase: provider.base };
|
|
55884
|
+
if (parsed.values.json)
|
|
55885
|
+
return void console.log(JSON.stringify(payload, null, 2));
|
|
55886
|
+
console.log(`\u5339\u914D\u89C4\u5219: ${payload.matchedRule}`);
|
|
55887
|
+
console.log(`\u547D\u4E2D provider: ${payload.provider}`);
|
|
55888
|
+
console.log(`\u8F6C\u53D1 model: ${payload.targetModel}`);
|
|
55889
|
+
console.log(`provider: ${payload.providerType} ${payload.providerBase}`);
|
|
55890
|
+
}
|
|
55891
|
+
async function handleValidate(args) {
|
|
55892
|
+
const parsed = parseArgs2({ args, options: { config: { type: "string" } }, allowPositionals: true, strict: false });
|
|
55893
|
+
const { config: config2, path } = readConfig(parsed.values.config);
|
|
55894
|
+
validateConfigOrThrow(config2);
|
|
55895
|
+
console.log(`\u914D\u7F6E\u6821\u9A8C\u901A\u8FC7: ${path}`);
|
|
55896
|
+
}
|
|
55897
|
+
async function handleApply() {
|
|
55898
|
+
await cleanupIfStale();
|
|
55899
|
+
const state = readRuntimeState();
|
|
55900
|
+
if (!state)
|
|
55901
|
+
throw new Error("\u670D\u52A1\u672A\u8FD0\u884C\uFF0C\u65E0\u6CD5 apply");
|
|
55902
|
+
const res = await fetch(`${state.baseUrl}/api/config/apply`, { method: "POST" });
|
|
55903
|
+
if (!res.ok) {
|
|
55904
|
+
const text2 = await res.text();
|
|
55905
|
+
throw new Error(`apply \u5931\u8D25: ${res.status} ${text2}`);
|
|
55906
|
+
}
|
|
55907
|
+
const healthy = await checkHealth(state.baseUrl);
|
|
55908
|
+
if (!healthy)
|
|
55909
|
+
throw new Error(`apply \u540E\u5065\u5EB7\u68C0\u67E5\u5931\u8D25: ${state.baseUrl}`);
|
|
55910
|
+
console.log(`\u914D\u7F6E\u5DF2\u5E94\u7528: ${state.baseUrl}`);
|
|
55911
|
+
}
|
|
55912
|
+
async function cmdConfig(args) {
|
|
55913
|
+
const [group, ...rest] = args;
|
|
55914
|
+
switch (group) {
|
|
55915
|
+
case "provider":
|
|
55916
|
+
await handleProvider(rest);
|
|
55917
|
+
return;
|
|
55918
|
+
case "route":
|
|
55919
|
+
await handleRoute(rest);
|
|
55920
|
+
return;
|
|
55921
|
+
case "resolve":
|
|
55922
|
+
await handleResolve(rest);
|
|
55923
|
+
return;
|
|
55924
|
+
case "validate":
|
|
55925
|
+
await handleValidate(rest);
|
|
55926
|
+
return;
|
|
55927
|
+
case "apply":
|
|
55928
|
+
await handleApply();
|
|
55929
|
+
return;
|
|
55930
|
+
case "help":
|
|
55931
|
+
case "--help":
|
|
55932
|
+
case "-h":
|
|
55933
|
+
case undefined:
|
|
55934
|
+
printConfigHelp();
|
|
55935
|
+
return;
|
|
55936
|
+
default:
|
|
55937
|
+
throw new Error(`\u672A\u77E5 config \u547D\u4EE4: ${group}`);
|
|
55938
|
+
}
|
|
55939
|
+
}
|
|
55940
|
+
|
|
54942
55941
|
// src/cli.ts
|
|
54943
55942
|
function printHelp() {
|
|
54944
55943
|
console.log(`
|
|
@@ -54954,6 +55953,7 @@ Commands:
|
|
|
54954
55953
|
status [--json]
|
|
54955
55954
|
logs [--follow] [--lines <n>]
|
|
54956
55955
|
init [--config <path>] [--force]
|
|
55956
|
+
config <subcommand> [...args]
|
|
54957
55957
|
health
|
|
54958
55958
|
version
|
|
54959
55959
|
|
|
@@ -54971,7 +55971,7 @@ async function printVersion() {
|
|
|
54971
55971
|
}
|
|
54972
55972
|
}
|
|
54973
55973
|
async function cmdStart(args) {
|
|
54974
|
-
const parsed =
|
|
55974
|
+
const parsed = parseArgs3({
|
|
54975
55975
|
args,
|
|
54976
55976
|
options: {
|
|
54977
55977
|
daemon: { type: "boolean", default: false }
|
|
@@ -55005,7 +56005,7 @@ async function cmdRestart(args) {
|
|
|
55005
56005
|
}
|
|
55006
56006
|
async function cmdStatus(args) {
|
|
55007
56007
|
await cleanupIfStale();
|
|
55008
|
-
const parsed =
|
|
56008
|
+
const parsed = parseArgs3({
|
|
55009
56009
|
args,
|
|
55010
56010
|
options: {
|
|
55011
56011
|
json: { type: "boolean", default: false }
|
|
@@ -55063,7 +56063,7 @@ function printLastLines(filePath, lines) {
|
|
|
55063
56063
|
console.log(`\u65E5\u5FD7\u6587\u4EF6\u4E0D\u5B58\u5728: ${filePath}`);
|
|
55064
56064
|
return 0;
|
|
55065
56065
|
}
|
|
55066
|
-
const full =
|
|
56066
|
+
const full = readFileSync8(filePath, "utf-8");
|
|
55067
56067
|
const rendered = full.split(`
|
|
55068
56068
|
`).slice(-lines).join(`
|
|
55069
56069
|
`);
|
|
@@ -55073,7 +56073,7 @@ function printLastLines(filePath, lines) {
|
|
|
55073
56073
|
return full.length;
|
|
55074
56074
|
}
|
|
55075
56075
|
async function cmdLogs(args) {
|
|
55076
|
-
const parsed =
|
|
56076
|
+
const parsed = parseArgs3({
|
|
55077
56077
|
args,
|
|
55078
56078
|
options: {
|
|
55079
56079
|
follow: { type: "boolean", default: false },
|
|
@@ -55100,7 +56100,7 @@ async function cmdLogs(args) {
|
|
|
55100
56100
|
}
|
|
55101
56101
|
}
|
|
55102
56102
|
async function cmdInit(args) {
|
|
55103
|
-
const parsed =
|
|
56103
|
+
const parsed = parseArgs3({
|
|
55104
56104
|
args,
|
|
55105
56105
|
options: {
|
|
55106
56106
|
config: { type: "string" },
|
|
@@ -55134,7 +56134,7 @@ async function cmdHealth() {
|
|
|
55134
56134
|
console.log(`\u5065\u5EB7\u68C0\u67E5\u901A\u8FC7: ${state.baseUrl}`);
|
|
55135
56135
|
}
|
|
55136
56136
|
async function cmdRunServer(args) {
|
|
55137
|
-
const parsed =
|
|
56137
|
+
const parsed = parseArgs3({
|
|
55138
56138
|
args,
|
|
55139
56139
|
options: {
|
|
55140
56140
|
mode: { type: "string" },
|
|
@@ -55181,6 +56181,9 @@ async function main() {
|
|
|
55181
56181
|
case "health":
|
|
55182
56182
|
await cmdHealth();
|
|
55183
56183
|
return;
|
|
56184
|
+
case "config":
|
|
56185
|
+
await cmdConfig(rest);
|
|
56186
|
+
return;
|
|
55184
56187
|
case "version":
|
|
55185
56188
|
await printVersion();
|
|
55186
56189
|
return;
|