@musistudio/claude-code-router 1.0.18 → 1.0.20
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/README.md +187 -127
- package/README_zh.md +312 -0
- package/config.example.json +78 -0
- package/dist/cli.js +834 -617
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -270,7 +270,7 @@ var require_queue = __commonJS({
|
|
|
270
270
|
queue.drained = drained;
|
|
271
271
|
return queue;
|
|
272
272
|
function push(value) {
|
|
273
|
-
var
|
|
273
|
+
var p = new Promise(function(resolve, reject) {
|
|
274
274
|
pushCb(value, function(err, result) {
|
|
275
275
|
if (err) {
|
|
276
276
|
reject(err);
|
|
@@ -279,11 +279,11 @@ var require_queue = __commonJS({
|
|
|
279
279
|
resolve(result);
|
|
280
280
|
});
|
|
281
281
|
});
|
|
282
|
-
|
|
283
|
-
return
|
|
282
|
+
p.catch(noop);
|
|
283
|
+
return p;
|
|
284
284
|
}
|
|
285
285
|
function unshift(value) {
|
|
286
|
-
var
|
|
286
|
+
var p = new Promise(function(resolve, reject) {
|
|
287
287
|
unshiftCb(value, function(err, result) {
|
|
288
288
|
if (err) {
|
|
289
289
|
reject(err);
|
|
@@ -292,11 +292,11 @@ var require_queue = __commonJS({
|
|
|
292
292
|
resolve(result);
|
|
293
293
|
});
|
|
294
294
|
});
|
|
295
|
-
|
|
296
|
-
return
|
|
295
|
+
p.catch(noop);
|
|
296
|
+
return p;
|
|
297
297
|
}
|
|
298
298
|
function drained() {
|
|
299
|
-
var
|
|
299
|
+
var p = new Promise(function(resolve) {
|
|
300
300
|
process.nextTick(function() {
|
|
301
301
|
if (queue.idle()) {
|
|
302
302
|
resolve();
|
|
@@ -310,7 +310,7 @@ var require_queue = __commonJS({
|
|
|
310
310
|
}
|
|
311
311
|
});
|
|
312
312
|
});
|
|
313
|
-
return
|
|
313
|
+
return p;
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
module2.exports = fastqueue;
|
|
@@ -918,8 +918,8 @@ var require_thenify = __commonJS({
|
|
|
918
918
|
}
|
|
919
919
|
debug("thenify");
|
|
920
920
|
return (resolve, reject) => {
|
|
921
|
-
const
|
|
922
|
-
return
|
|
921
|
+
const p = this._loadRegistered();
|
|
922
|
+
return p.then(() => {
|
|
923
923
|
this[kThenifyDoNotWrap] = true;
|
|
924
924
|
return resolve(this._server);
|
|
925
925
|
}, reject);
|
|
@@ -3644,11 +3644,11 @@ var require_parse = __commonJS({
|
|
|
3644
3644
|
const wildcards = [];
|
|
3645
3645
|
var wcLen = 0;
|
|
3646
3646
|
const secret = paths.reduce(function(o, strPath, ix) {
|
|
3647
|
-
var path3 = strPath.match(rx).map((
|
|
3647
|
+
var path3 = strPath.match(rx).map((p) => p.replace(/'|"|`/g, ""));
|
|
3648
3648
|
const leadingBracket = strPath[0] === "[";
|
|
3649
|
-
path3 = path3.map((
|
|
3650
|
-
if (
|
|
3651
|
-
else return
|
|
3649
|
+
path3 = path3.map((p) => {
|
|
3650
|
+
if (p[0] === "[") return p.substr(1, p.length - 2);
|
|
3651
|
+
else return p;
|
|
3652
3652
|
});
|
|
3653
3653
|
const star = path3.indexOf("*");
|
|
3654
3654
|
if (star > -1) {
|
|
@@ -3722,14 +3722,14 @@ var require_redactor = __commonJS({
|
|
|
3722
3722
|
const { index, input } = match;
|
|
3723
3723
|
if (index > skip) hops.push(input.substring(0, index - (ix ? 0 : 1)));
|
|
3724
3724
|
}
|
|
3725
|
-
var existence = hops.map((
|
|
3725
|
+
var existence = hops.map((p) => `o${delim}${p}`).join(" && ");
|
|
3726
3726
|
if (existence.length === 0) existence += `o${delim}${path3} != null`;
|
|
3727
3727
|
else existence += ` && o${delim}${path3} != null`;
|
|
3728
3728
|
const circularDetection = `
|
|
3729
3729
|
switch (true) {
|
|
3730
|
-
${hops.reverse().map((
|
|
3731
|
-
case o${delim}${
|
|
3732
|
-
secret[${escPath}].circle = ${JSON.stringify(
|
|
3730
|
+
${hops.reverse().map((p) => `
|
|
3731
|
+
case o${delim}${p} === censor:
|
|
3732
|
+
secret[${escPath}].circle = ${JSON.stringify(p)}
|
|
3733
3733
|
break
|
|
3734
3734
|
`).join("\n")}
|
|
3735
3735
|
}
|
|
@@ -3928,12 +3928,12 @@ var require_modifiers = __commonJS({
|
|
|
3928
3928
|
}
|
|
3929
3929
|
}
|
|
3930
3930
|
}
|
|
3931
|
-
function get(o,
|
|
3931
|
+
function get(o, p) {
|
|
3932
3932
|
var i = -1;
|
|
3933
|
-
var l =
|
|
3933
|
+
var l = p.length;
|
|
3934
3934
|
var n = o;
|
|
3935
3935
|
while (n != null && ++i < l) {
|
|
3936
|
-
n = n[
|
|
3936
|
+
n = n[p[i]];
|
|
3937
3937
|
}
|
|
3938
3938
|
return n;
|
|
3939
3939
|
}
|
|
@@ -9138,7 +9138,7 @@ var require_reply = __commonJS({
|
|
|
9138
9138
|
handled--;
|
|
9139
9139
|
const result = reply[kReplyTrailers][trailerName](reply, payload, cb);
|
|
9140
9140
|
if (typeof result === "object" && typeof result.then === "function") {
|
|
9141
|
-
result.then((
|
|
9141
|
+
result.then((v2) => cb(null, v2), cb);
|
|
9142
9142
|
}
|
|
9143
9143
|
}
|
|
9144
9144
|
if (skipped) res.end(null, null, null);
|
|
@@ -9200,8 +9200,8 @@ var require_reply = __commonJS({
|
|
|
9200
9200
|
responseTime
|
|
9201
9201
|
}, "request completed");
|
|
9202
9202
|
}
|
|
9203
|
-
function buildReply(
|
|
9204
|
-
const props =
|
|
9203
|
+
function buildReply(R2) {
|
|
9204
|
+
const props = R2.props.slice();
|
|
9205
9205
|
function _Reply(res, request, log2) {
|
|
9206
9206
|
this.raw = res;
|
|
9207
9207
|
this[kReplyIsError] = false;
|
|
@@ -9220,9 +9220,9 @@ var require_reply = __commonJS({
|
|
|
9220
9220
|
this[prop.key] = prop.value;
|
|
9221
9221
|
}
|
|
9222
9222
|
}
|
|
9223
|
-
Object.setPrototypeOf(_Reply.prototype,
|
|
9224
|
-
Object.setPrototypeOf(_Reply,
|
|
9225
|
-
_Reply.parent =
|
|
9223
|
+
Object.setPrototypeOf(_Reply.prototype, R2.prototype);
|
|
9224
|
+
Object.setPrototypeOf(_Reply, R2);
|
|
9225
|
+
_Reply.parent = R2;
|
|
9226
9226
|
_Reply.props = props;
|
|
9227
9227
|
return _Reply;
|
|
9228
9228
|
}
|
|
@@ -10300,14 +10300,14 @@ var require_request = __commonJS({
|
|
|
10300
10300
|
}
|
|
10301
10301
|
return proxyAddr.compile(tp);
|
|
10302
10302
|
}
|
|
10303
|
-
function buildRequest(
|
|
10303
|
+
function buildRequest(R2, trustProxy) {
|
|
10304
10304
|
if (trustProxy) {
|
|
10305
|
-
return buildRequestWithTrustProxy(
|
|
10305
|
+
return buildRequestWithTrustProxy(R2, trustProxy);
|
|
10306
10306
|
}
|
|
10307
|
-
return buildRegularRequest(
|
|
10307
|
+
return buildRegularRequest(R2);
|
|
10308
10308
|
}
|
|
10309
|
-
function buildRegularRequest(
|
|
10310
|
-
const props =
|
|
10309
|
+
function buildRegularRequest(R2) {
|
|
10310
|
+
const props = R2.props.slice();
|
|
10311
10311
|
function _Request(id2, params, req, query, log2, context) {
|
|
10312
10312
|
this.id = id2;
|
|
10313
10313
|
this[kRouteContext] = context;
|
|
@@ -10322,18 +10322,18 @@ var require_request = __commonJS({
|
|
|
10322
10322
|
this[prop.key] = prop.value;
|
|
10323
10323
|
}
|
|
10324
10324
|
}
|
|
10325
|
-
Object.setPrototypeOf(_Request.prototype,
|
|
10326
|
-
Object.setPrototypeOf(_Request,
|
|
10325
|
+
Object.setPrototypeOf(_Request.prototype, R2.prototype);
|
|
10326
|
+
Object.setPrototypeOf(_Request, R2);
|
|
10327
10327
|
_Request.props = props;
|
|
10328
|
-
_Request.parent =
|
|
10328
|
+
_Request.parent = R2;
|
|
10329
10329
|
return _Request;
|
|
10330
10330
|
}
|
|
10331
10331
|
function getLastEntryInMultiHeaderValue(headerValue) {
|
|
10332
10332
|
const lastIndex = headerValue.lastIndexOf(",");
|
|
10333
10333
|
return lastIndex === -1 ? headerValue.trim() : headerValue.slice(lastIndex + 1).trim();
|
|
10334
10334
|
}
|
|
10335
|
-
function buildRequestWithTrustProxy(
|
|
10336
|
-
const _Request = buildRegularRequest(
|
|
10335
|
+
function buildRequestWithTrustProxy(R2, trustProxy) {
|
|
10336
|
+
const _Request = buildRegularRequest(R2);
|
|
10337
10337
|
const proxyFn = getTrustProxyFn(trustProxy);
|
|
10338
10338
|
_Request[kHasBeenDecorated] = true;
|
|
10339
10339
|
Object.defineProperties(_Request.prototype, {
|
|
@@ -13236,7 +13236,7 @@ var require_util = __commonJS({
|
|
|
13236
13236
|
}
|
|
13237
13237
|
exports2.evaluatedPropsToName = evaluatedPropsToName;
|
|
13238
13238
|
function setEvaluated(gen, props, ps) {
|
|
13239
|
-
Object.keys(ps).forEach((
|
|
13239
|
+
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1._)`${props}${(0, codegen_1.getProperty)(p)}`, true));
|
|
13240
13240
|
}
|
|
13241
13241
|
exports2.setEvaluated = setEvaluated;
|
|
13242
13242
|
var snippets = {};
|
|
@@ -13809,11 +13809,11 @@ var require_code2 = __commonJS({
|
|
|
13809
13809
|
}
|
|
13810
13810
|
exports2.noPropertyInData = noPropertyInData;
|
|
13811
13811
|
function allSchemaProperties(schemaMap) {
|
|
13812
|
-
return schemaMap ? Object.keys(schemaMap).filter((
|
|
13812
|
+
return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
|
|
13813
13813
|
}
|
|
13814
13814
|
exports2.allSchemaProperties = allSchemaProperties;
|
|
13815
13815
|
function schemaProperties(it, schemaMap) {
|
|
13816
|
-
return allSchemaProperties(schemaMap).filter((
|
|
13816
|
+
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1.alwaysValidSchema)(it, schemaMap[p]));
|
|
13817
13817
|
}
|
|
13818
13818
|
exports2.schemaProperties = schemaProperties;
|
|
13819
13819
|
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
|
|
@@ -14291,12 +14291,12 @@ var require_resolve = __commonJS({
|
|
|
14291
14291
|
function getFullPath(resolver, id2 = "", normalize) {
|
|
14292
14292
|
if (normalize !== false)
|
|
14293
14293
|
id2 = normalizeId(id2);
|
|
14294
|
-
const
|
|
14295
|
-
return _getFullPath(resolver,
|
|
14294
|
+
const p = resolver.parse(id2);
|
|
14295
|
+
return _getFullPath(resolver, p);
|
|
14296
14296
|
}
|
|
14297
14297
|
exports2.getFullPath = getFullPath;
|
|
14298
|
-
function _getFullPath(resolver,
|
|
14299
|
-
const serialized = resolver.serialize(
|
|
14298
|
+
function _getFullPath(resolver, p) {
|
|
14299
|
+
const serialized = resolver.serialize(p);
|
|
14300
14300
|
return serialized.split("#")[0] + "#";
|
|
14301
14301
|
}
|
|
14302
14302
|
exports2._getFullPath = _getFullPath;
|
|
@@ -15071,11 +15071,11 @@ var require_compile = __commonJS({
|
|
|
15071
15071
|
return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
|
|
15072
15072
|
}
|
|
15073
15073
|
function resolveSchema(root, ref) {
|
|
15074
|
-
const
|
|
15075
|
-
const refPath = (0, resolve_1._getFullPath)(this.opts.uriResolver,
|
|
15074
|
+
const p = this.opts.uriResolver.parse(ref);
|
|
15075
|
+
const refPath = (0, resolve_1._getFullPath)(this.opts.uriResolver, p);
|
|
15076
15076
|
let baseId = (0, resolve_1.getFullPath)(this.opts.uriResolver, root.baseId, void 0);
|
|
15077
15077
|
if (Object.keys(root.schema).length > 0 && refPath === baseId) {
|
|
15078
|
-
return getJsonPointer.call(this,
|
|
15078
|
+
return getJsonPointer.call(this, p, root);
|
|
15079
15079
|
}
|
|
15080
15080
|
const id2 = (0, resolve_1.normalizeId)(refPath);
|
|
15081
15081
|
const schOrRef = this.refs[id2] || this.schemas[id2];
|
|
@@ -15083,7 +15083,7 @@ var require_compile = __commonJS({
|
|
|
15083
15083
|
const sch = resolveSchema.call(this, root, schOrRef);
|
|
15084
15084
|
if (typeof (sch === null || sch === void 0 ? void 0 : sch.schema) !== "object")
|
|
15085
15085
|
return;
|
|
15086
|
-
return getJsonPointer.call(this,
|
|
15086
|
+
return getJsonPointer.call(this, p, sch);
|
|
15087
15087
|
}
|
|
15088
15088
|
if (typeof (schOrRef === null || schOrRef === void 0 ? void 0 : schOrRef.schema) !== "object")
|
|
15089
15089
|
return;
|
|
@@ -15097,7 +15097,7 @@ var require_compile = __commonJS({
|
|
|
15097
15097
|
baseId = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, schId);
|
|
15098
15098
|
return new SchemaEnv({ schema, schemaId, root, baseId });
|
|
15099
15099
|
}
|
|
15100
|
-
return getJsonPointer.call(this,
|
|
15100
|
+
return getJsonPointer.call(this, p, schOrRef);
|
|
15101
15101
|
}
|
|
15102
15102
|
exports2.resolveSchema = resolveSchema;
|
|
15103
15103
|
var PREVENT_SCOPE_CHANGE = /* @__PURE__ */ new Set([
|
|
@@ -15916,14 +15916,14 @@ var require_core = __commonJS({
|
|
|
15916
15916
|
};
|
|
15917
15917
|
var MAX_EXPRESSION = 200;
|
|
15918
15918
|
function requiredOptions(o) {
|
|
15919
|
-
var _a, _b, _c, _d,
|
|
15919
|
+
var _a, _b, _c, _d, _e2, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
15920
15920
|
const s = o.strict;
|
|
15921
15921
|
const _optz = (_a = o.code) === null || _a === void 0 ? void 0 : _a.optimize;
|
|
15922
15922
|
const optimize = _optz === true || _optz === void 0 ? 1 : _optz || 0;
|
|
15923
15923
|
const regExp = (_c = (_b = o.code) === null || _b === void 0 ? void 0 : _b.regExp) !== null && _c !== void 0 ? _c : defaultRegExp;
|
|
15924
15924
|
const uriResolver = (_d = o.uriResolver) !== null && _d !== void 0 ? _d : uri_1.default;
|
|
15925
15925
|
return {
|
|
15926
|
-
strictSchema: (_f = (
|
|
15926
|
+
strictSchema: (_f = (_e2 = o.strictSchema) !== null && _e2 !== void 0 ? _e2 : s) !== null && _f !== void 0 ? _f : true,
|
|
15927
15927
|
strictNumbers: (_h = (_g = o.strictNumbers) !== null && _g !== void 0 ? _g : s) !== null && _h !== void 0 ? _h : true,
|
|
15928
15928
|
strictTypes: (_k = (_j = o.strictTypes) !== null && _j !== void 0 ? _j : s) !== null && _k !== void 0 ? _k : "log",
|
|
15929
15929
|
strictTuples: (_m = (_l = o.strictTuples) !== null && _l !== void 0 ? _l : s) !== null && _m !== void 0 ? _m : "log",
|
|
@@ -15991,17 +15991,17 @@ var require_core = __commonJS({
|
|
|
15991
15991
|
return this.opts.defaultMeta = typeof meta == "object" ? meta[schemaId] || meta : void 0;
|
|
15992
15992
|
}
|
|
15993
15993
|
validate(schemaKeyRef, data) {
|
|
15994
|
-
let
|
|
15994
|
+
let v2;
|
|
15995
15995
|
if (typeof schemaKeyRef == "string") {
|
|
15996
|
-
|
|
15997
|
-
if (!
|
|
15996
|
+
v2 = this.getSchema(schemaKeyRef);
|
|
15997
|
+
if (!v2)
|
|
15998
15998
|
throw new Error(`no schema with key or ref "${schemaKeyRef}"`);
|
|
15999
15999
|
} else {
|
|
16000
|
-
|
|
16000
|
+
v2 = this.compile(schemaKeyRef);
|
|
16001
16001
|
}
|
|
16002
|
-
const valid =
|
|
16003
|
-
if (!("$async" in
|
|
16004
|
-
this.errors =
|
|
16002
|
+
const valid = v2(data);
|
|
16003
|
+
if (!("$async" in v2))
|
|
16004
|
+
this.errors = v2.errors;
|
|
16005
16005
|
return valid;
|
|
16006
16006
|
}
|
|
16007
16007
|
compile(schema, _meta) {
|
|
@@ -16048,9 +16048,9 @@ var require_core = __commonJS({
|
|
|
16048
16048
|
this.addSchema(_schema, ref, meta);
|
|
16049
16049
|
}
|
|
16050
16050
|
async function _loadSchema(ref) {
|
|
16051
|
-
const
|
|
16052
|
-
if (
|
|
16053
|
-
return
|
|
16051
|
+
const p = this._loading[ref];
|
|
16052
|
+
if (p)
|
|
16053
|
+
return p;
|
|
16054
16054
|
try {
|
|
16055
16055
|
return await (this._loading[ref] = loadSchema(ref));
|
|
16056
16056
|
} finally {
|
|
@@ -16495,8 +16495,8 @@ var require_ref = __commonJS({
|
|
|
16495
16495
|
return callRef(cxt, (0, codegen_1._)`${rootName}.validate`, root, root.$async);
|
|
16496
16496
|
}
|
|
16497
16497
|
function callValidate(sch) {
|
|
16498
|
-
const
|
|
16499
|
-
callRef(cxt,
|
|
16498
|
+
const v2 = getValidate(cxt, sch);
|
|
16499
|
+
callRef(cxt, v2, sch, sch.$async);
|
|
16500
16500
|
}
|
|
16501
16501
|
function inlineRefSchema(sch) {
|
|
16502
16502
|
const schName = gen.scopeValue("schema", opts.code.source === true ? { ref: sch, code: (0, codegen_1.stringify)(sch) } : { ref: sch });
|
|
@@ -16518,7 +16518,7 @@ var require_ref = __commonJS({
|
|
|
16518
16518
|
return sch.validate ? gen.scopeValue("validate", { ref: sch.validate }) : (0, codegen_1._)`${gen.scopeValue("wrapper", { ref: sch })}.validate`;
|
|
16519
16519
|
}
|
|
16520
16520
|
exports2.getValidate = getValidate;
|
|
16521
|
-
function callRef(cxt,
|
|
16521
|
+
function callRef(cxt, v2, sch, $async) {
|
|
16522
16522
|
const { gen, it } = cxt;
|
|
16523
16523
|
const { allErrors, schemaEnv: env, opts } = it;
|
|
16524
16524
|
const passCxt = opts.passContext ? names_1.default.this : codegen_1.nil;
|
|
@@ -16531,8 +16531,8 @@ var require_ref = __commonJS({
|
|
|
16531
16531
|
throw new Error("async schema referenced by sync schema");
|
|
16532
16532
|
const valid = gen.let("valid");
|
|
16533
16533
|
gen.try(() => {
|
|
16534
|
-
gen.code((0, codegen_1._)`await ${(0, code_1.callValidateCode)(cxt,
|
|
16535
|
-
addEvaluatedFrom(
|
|
16534
|
+
gen.code((0, codegen_1._)`await ${(0, code_1.callValidateCode)(cxt, v2, passCxt)}`);
|
|
16535
|
+
addEvaluatedFrom(v2);
|
|
16536
16536
|
if (!allErrors)
|
|
16537
16537
|
gen.assign(valid, true);
|
|
16538
16538
|
}, (e) => {
|
|
@@ -16544,7 +16544,7 @@ var require_ref = __commonJS({
|
|
|
16544
16544
|
cxt.ok(valid);
|
|
16545
16545
|
}
|
|
16546
16546
|
function callSyncRef() {
|
|
16547
|
-
cxt.result((0, code_1.callValidateCode)(cxt,
|
|
16547
|
+
cxt.result((0, code_1.callValidateCode)(cxt, v2, passCxt), () => addEvaluatedFrom(v2), () => addErrorsFrom(v2));
|
|
16548
16548
|
}
|
|
16549
16549
|
function addErrorsFrom(source) {
|
|
16550
16550
|
const errs = (0, codegen_1._)`${source}.errors`;
|
|
@@ -17034,7 +17034,7 @@ var require_enum = __commonJS({
|
|
|
17034
17034
|
cxt.pass(valid);
|
|
17035
17035
|
function loopEnum() {
|
|
17036
17036
|
gen.assign(valid, false);
|
|
17037
|
-
gen.forOf("v", schemaCode, (
|
|
17037
|
+
gen.forOf("v", schemaCode, (v2) => gen.if((0, codegen_1._)`${getEql()}(${data}, ${v2})`, () => gen.assign(valid, true).break()));
|
|
17038
17038
|
}
|
|
17039
17039
|
function equalCode(vSchema, i) {
|
|
17040
17040
|
const sch = schema[i];
|
|
@@ -17523,12 +17523,12 @@ var require_additionalProperties = __commonJS({
|
|
|
17523
17523
|
const propsSchema = (0, util_1.schemaRefOrVal)(it, parentSchema.properties, "properties");
|
|
17524
17524
|
definedProp = (0, code_1.isOwnProperty)(gen, propsSchema, key);
|
|
17525
17525
|
} else if (props.length) {
|
|
17526
|
-
definedProp = (0, codegen_1.or)(...props.map((
|
|
17526
|
+
definedProp = (0, codegen_1.or)(...props.map((p) => (0, codegen_1._)`${key} === ${p}`));
|
|
17527
17527
|
} else {
|
|
17528
17528
|
definedProp = codegen_1.nil;
|
|
17529
17529
|
}
|
|
17530
17530
|
if (patProps.length) {
|
|
17531
|
-
definedProp = (0, codegen_1.or)(definedProp, ...patProps.map((
|
|
17531
|
+
definedProp = (0, codegen_1.or)(definedProp, ...patProps.map((p) => (0, codegen_1._)`${(0, code_1.usePattern)(cxt, p)}.test(${key})`));
|
|
17532
17532
|
}
|
|
17533
17533
|
return (0, codegen_1.not)(definedProp);
|
|
17534
17534
|
}
|
|
@@ -17608,7 +17608,7 @@ var require_properties = __commonJS({
|
|
|
17608
17608
|
if (it.opts.unevaluated && allProps.length && it.props !== true) {
|
|
17609
17609
|
it.props = util_1.mergeEvaluated.props(gen, (0, util_1.toHash)(allProps), it.props);
|
|
17610
17610
|
}
|
|
17611
|
-
const properties = allProps.filter((
|
|
17611
|
+
const properties = allProps.filter((p) => !(0, util_1.alwaysValidSchema)(it, schema[p]));
|
|
17612
17612
|
if (properties.length === 0)
|
|
17613
17613
|
return;
|
|
17614
17614
|
const valid = gen.name("valid");
|
|
@@ -17658,7 +17658,7 @@ var require_patternProperties = __commonJS({
|
|
|
17658
17658
|
const { gen, schema, data, parentSchema, it } = cxt;
|
|
17659
17659
|
const { opts } = it;
|
|
17660
17660
|
const patterns = (0, code_1.allSchemaProperties)(schema);
|
|
17661
|
-
const alwaysValidPatterns = patterns.filter((
|
|
17661
|
+
const alwaysValidPatterns = patterns.filter((p) => (0, util_1.alwaysValidSchema)(it, schema[p]));
|
|
17662
17662
|
if (patterns.length === 0 || alwaysValidPatterns.length === patterns.length && (!it.opts.unevaluated || it.props === true)) {
|
|
17663
17663
|
return;
|
|
17664
17664
|
}
|
|
@@ -18420,7 +18420,7 @@ var require_ajv = __commonJS({
|
|
|
18420
18420
|
var Ajv = class extends core_1.default {
|
|
18421
18421
|
_addVocabularies() {
|
|
18422
18422
|
super._addVocabularies();
|
|
18423
|
-
draft7_1.default.forEach((
|
|
18423
|
+
draft7_1.default.forEach((v2) => this.addVocabulary(v2));
|
|
18424
18424
|
if (this.opts.discriminator)
|
|
18425
18425
|
this.addKeyword(discriminator_1.default);
|
|
18426
18426
|
}
|
|
@@ -21449,9 +21449,9 @@ var require_ref2 = __commonJS({
|
|
|
21449
21449
|
}
|
|
21450
21450
|
function callValidate(schema) {
|
|
21451
21451
|
const sch = compile_1.compileSchema.call(it.self, new compile_1.SchemaEnv({ schema, root, schemaPath: `/definitions/${ref}` }));
|
|
21452
|
-
const
|
|
21452
|
+
const v2 = (0, ref_1.getValidate)(cxt, sch);
|
|
21453
21453
|
const errsCount = gen.const("_errs", names_1.default.errors);
|
|
21454
|
-
(0, ref_1.callRef)(cxt,
|
|
21454
|
+
(0, ref_1.callRef)(cxt, v2, sch, sch.$async);
|
|
21455
21455
|
gen.assign(valid, (0, codegen_1._)`${errsCount} === ${names_1.default.errors}`);
|
|
21456
21456
|
}
|
|
21457
21457
|
function inlineRefSchema(schema) {
|
|
@@ -21681,7 +21681,7 @@ var require_enum2 = __commonJS({
|
|
|
21681
21681
|
}
|
|
21682
21682
|
cxt.pass(valid);
|
|
21683
21683
|
function loopEnum() {
|
|
21684
|
-
gen.forOf("v", schemaValue, (
|
|
21684
|
+
gen.forOf("v", schemaValue, (v2) => gen.if((0, codegen_1._)`${valid} = ${data} === ${v2}`, () => gen.break()));
|
|
21685
21685
|
}
|
|
21686
21686
|
}
|
|
21687
21687
|
};
|
|
@@ -21778,8 +21778,8 @@ var require_properties2 = __commonJS({
|
|
|
21778
21778
|
const optProps = parentSchema.optionalProperties;
|
|
21779
21779
|
if (!(props && optProps))
|
|
21780
21780
|
return false;
|
|
21781
|
-
for (const
|
|
21782
|
-
if (Object.prototype.hasOwnProperty.call(optProps,
|
|
21781
|
+
for (const p in props) {
|
|
21782
|
+
if (Object.prototype.hasOwnProperty.call(optProps, p))
|
|
21783
21783
|
return true;
|
|
21784
21784
|
}
|
|
21785
21785
|
return false;
|
|
@@ -21787,10 +21787,10 @@ var require_properties2 = __commonJS({
|
|
|
21787
21787
|
function schemaProperties(keyword) {
|
|
21788
21788
|
const schema = parentSchema[keyword];
|
|
21789
21789
|
const allPs = schema ? (0, code_1.allSchemaProperties)(schema) : [];
|
|
21790
|
-
if (it.jtdDiscriminator && allPs.some((
|
|
21790
|
+
if (it.jtdDiscriminator && allPs.some((p) => p === it.jtdDiscriminator)) {
|
|
21791
21791
|
throw new Error(`JTD: discriminator tag used in ${keyword}`);
|
|
21792
21792
|
}
|
|
21793
|
-
const ps = allPs.filter((
|
|
21793
|
+
const ps = allPs.filter((p) => !(0, util_1.alwaysValidSchema)(it, schema[p]));
|
|
21794
21794
|
return [allPs, ps];
|
|
21795
21795
|
}
|
|
21796
21796
|
function validateProps(props, keyword, required) {
|
|
@@ -21841,7 +21841,7 @@ var require_properties2 = __commonJS({
|
|
|
21841
21841
|
}
|
|
21842
21842
|
} else if (props.length || jtdDiscriminator !== void 0) {
|
|
21843
21843
|
const ps = jtdDiscriminator === void 0 ? props : [jtdDiscriminator].concat(props);
|
|
21844
|
-
additional = (0, codegen_1.and)(...ps.map((
|
|
21844
|
+
additional = (0, codegen_1.and)(...ps.map((p) => (0, codegen_1._)`${key} !== ${p}`));
|
|
21845
21845
|
} else {
|
|
21846
21846
|
additional = true;
|
|
21847
21847
|
}
|
|
@@ -22397,7 +22397,7 @@ var require_serialize = __commonJS({
|
|
|
22397
22397
|
serializeCode({ ...cxt, schema: propSchema, data: value });
|
|
22398
22398
|
}
|
|
22399
22399
|
function isAdditional(key, ps) {
|
|
22400
|
-
return ps.length ? (0, codegen_1.and)(...ps.map((
|
|
22400
|
+
return ps.length ? (0, codegen_1.and)(...ps.map((p) => (0, codegen_1._)`${key} !== ${p}`)) : true;
|
|
22401
22401
|
}
|
|
22402
22402
|
}
|
|
22403
22403
|
function serializeType(cxt) {
|
|
@@ -22839,7 +22839,7 @@ var require_parse2 = __commonJS({
|
|
|
22839
22839
|
});
|
|
22840
22840
|
if (properties) {
|
|
22841
22841
|
const hasProp = (0, code_1.hasPropFunc)(gen);
|
|
22842
|
-
const allProps = (0, codegen_1.and)(...Object.keys(properties).map((
|
|
22842
|
+
const allProps = (0, codegen_1.and)(...Object.keys(properties).map((p) => (0, codegen_1._)`${hasProp}.call(${data}, ${p})`));
|
|
22843
22843
|
gen.if((0, codegen_1.not)(allProps), () => parsingError(cxt, (0, codegen_1.str)`missing required properties`));
|
|
22844
22844
|
}
|
|
22845
22845
|
}
|
|
@@ -23173,10 +23173,10 @@ var require_standalone3 = __commonJS({
|
|
|
23173
23173
|
const { _n } = ajv.scope.opts;
|
|
23174
23174
|
return typeof refsOrFunc == "function" ? funcExportCode(refsOrFunc.source) : refsOrFunc !== void 0 ? multiExportsCode(refsOrFunc, getValidate) : multiExportsCode(ajv.schemas, (sch) => sch.meta ? void 0 : ajv.compile(sch.schema));
|
|
23175
23175
|
function getValidate(id2) {
|
|
23176
|
-
const
|
|
23177
|
-
if (!
|
|
23176
|
+
const v2 = ajv.getSchema(id2);
|
|
23177
|
+
if (!v2)
|
|
23178
23178
|
throw new Error(`moduleCode: no schema with id ${id2}`);
|
|
23179
|
-
return
|
|
23179
|
+
return v2;
|
|
23180
23180
|
}
|
|
23181
23181
|
function funcExportCode(source) {
|
|
23182
23182
|
const usedValues = {};
|
|
@@ -23192,11 +23192,11 @@ var require_standalone3 = __commonJS({
|
|
|
23192
23192
|
const usedValues = {};
|
|
23193
23193
|
let code = (0, code_1._)`"use strict";`;
|
|
23194
23194
|
for (const name in schemas) {
|
|
23195
|
-
const
|
|
23196
|
-
if (
|
|
23197
|
-
const vCode = validateCode(usedValues,
|
|
23195
|
+
const v2 = getValidateFunc(schemas[name]);
|
|
23196
|
+
if (v2) {
|
|
23197
|
+
const vCode = validateCode(usedValues, v2.source);
|
|
23198
23198
|
const exportSyntax = ajv.opts.code.esm ? (0, code_1._)`export const ${(0, code_1.getEsmExportName)(name)}` : (0, code_1._)`exports${(0, code_1.getProperty)(name)}`;
|
|
23199
|
-
code = (0, code_1._)`${code}${_n}${exportSyntax} = ${(_a =
|
|
23199
|
+
code = (0, code_1._)`${code}${_n}${exportSyntax} = ${(_a = v2.source) === null || _a === void 0 ? void 0 : _a.validateName};${_n}${vCode}`;
|
|
23200
23200
|
}
|
|
23201
23201
|
}
|
|
23202
23202
|
return `${code}`;
|
|
@@ -23214,8 +23214,8 @@ var require_standalone3 = __commonJS({
|
|
|
23214
23214
|
var _a;
|
|
23215
23215
|
const vRef = (_a = n.value) === null || _a === void 0 ? void 0 : _a.ref;
|
|
23216
23216
|
if (n.prefix === "validate" && typeof vRef == "function") {
|
|
23217
|
-
const
|
|
23218
|
-
return validateCode(usedValues,
|
|
23217
|
+
const v2 = vRef;
|
|
23218
|
+
return validateCode(usedValues, v2.source);
|
|
23219
23219
|
} else if ((n.prefix === "root" || n.prefix === "wrapper") && typeof vRef == "object") {
|
|
23220
23220
|
const { validate, validateName } = vRef;
|
|
23221
23221
|
if (!validateName)
|
|
@@ -23504,12 +23504,12 @@ var require_re = __commonJS({
|
|
|
23504
23504
|
} = require_constants2();
|
|
23505
23505
|
var debug = require_debug2();
|
|
23506
23506
|
exports2 = module2.exports = {};
|
|
23507
|
-
var
|
|
23507
|
+
var re2 = exports2.re = [];
|
|
23508
23508
|
var safeRe = exports2.safeRe = [];
|
|
23509
23509
|
var src = exports2.src = [];
|
|
23510
23510
|
var safeSrc = exports2.safeSrc = [];
|
|
23511
23511
|
var t = exports2.t = {};
|
|
23512
|
-
var
|
|
23512
|
+
var R2 = 0;
|
|
23513
23513
|
var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
|
|
23514
23514
|
var safeRegexReplacements = [
|
|
23515
23515
|
["\\s", 1],
|
|
@@ -23524,12 +23524,12 @@ var require_re = __commonJS({
|
|
|
23524
23524
|
};
|
|
23525
23525
|
var createToken = (name, value, isGlobal) => {
|
|
23526
23526
|
const safe = makeSafeRegex(value);
|
|
23527
|
-
const index =
|
|
23527
|
+
const index = R2++;
|
|
23528
23528
|
debug(name, index, value);
|
|
23529
23529
|
t[name] = index;
|
|
23530
23530
|
src[index] = value;
|
|
23531
23531
|
safeSrc[index] = safe;
|
|
23532
|
-
|
|
23532
|
+
re2[index] = new RegExp(value, isGlobal ? "g" : void 0);
|
|
23533
23533
|
safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
|
|
23534
23534
|
};
|
|
23535
23535
|
createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
|
|
@@ -23628,7 +23628,7 @@ var require_semver = __commonJS({
|
|
|
23628
23628
|
"use strict";
|
|
23629
23629
|
var debug = require_debug2();
|
|
23630
23630
|
var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants2();
|
|
23631
|
-
var { safeRe:
|
|
23631
|
+
var { safeRe: re2, t } = require_re();
|
|
23632
23632
|
var parseOptions = require_parse_options();
|
|
23633
23633
|
var { compareIdentifiers } = require_identifiers();
|
|
23634
23634
|
var SemVer = class _SemVer {
|
|
@@ -23652,7 +23652,7 @@ var require_semver = __commonJS({
|
|
|
23652
23652
|
this.options = options;
|
|
23653
23653
|
this.loose = !!options.loose;
|
|
23654
23654
|
this.includePrerelease = !!options.includePrerelease;
|
|
23655
|
-
const m = version2.trim().match(options.loose ?
|
|
23655
|
+
const m = version2.trim().match(options.loose ? re2[t.LOOSE] : re2[t.FULL]);
|
|
23656
23656
|
if (!m) {
|
|
23657
23657
|
throw new TypeError(`Invalid Version: ${version2}`);
|
|
23658
23658
|
}
|
|
@@ -23773,7 +23773,7 @@ var require_semver = __commonJS({
|
|
|
23773
23773
|
throw new Error("invalid increment argument: identifier is empty");
|
|
23774
23774
|
}
|
|
23775
23775
|
if (identifier) {
|
|
23776
|
-
const match = `-${identifier}`.match(this.options.loose ?
|
|
23776
|
+
const match = `-${identifier}`.match(this.options.loose ? re2[t.PRERELEASELOOSE] : re2[t.PRERELEASE]);
|
|
23777
23777
|
if (!match || match[1] !== identifier) {
|
|
23778
23778
|
throw new Error(`invalid identifier: ${identifier}`);
|
|
23779
23779
|
}
|
|
@@ -23911,8 +23911,8 @@ var require_valid = __commonJS({
|
|
|
23911
23911
|
"use strict";
|
|
23912
23912
|
var parse = require_parse3();
|
|
23913
23913
|
var valid = (version2, options) => {
|
|
23914
|
-
const
|
|
23915
|
-
return
|
|
23914
|
+
const v2 = parse(version2, options);
|
|
23915
|
+
return v2 ? v2.version : null;
|
|
23916
23916
|
};
|
|
23917
23917
|
module2.exports = valid;
|
|
23918
23918
|
}
|
|
@@ -24222,7 +24222,7 @@ var require_coerce = __commonJS({
|
|
|
24222
24222
|
"use strict";
|
|
24223
24223
|
var SemVer = require_semver();
|
|
24224
24224
|
var parse = require_parse3();
|
|
24225
|
-
var { safeRe:
|
|
24225
|
+
var { safeRe: re2, t } = require_re();
|
|
24226
24226
|
var coerce = (version2, options) => {
|
|
24227
24227
|
if (version2 instanceof SemVer) {
|
|
24228
24228
|
return version2;
|
|
@@ -24236,9 +24236,9 @@ var require_coerce = __commonJS({
|
|
|
24236
24236
|
options = options || {};
|
|
24237
24237
|
let match = null;
|
|
24238
24238
|
if (!options.rtl) {
|
|
24239
|
-
match = version2.match(options.includePrerelease ?
|
|
24239
|
+
match = version2.match(options.includePrerelease ? re2[t.COERCEFULL] : re2[t.COERCE]);
|
|
24240
24240
|
} else {
|
|
24241
|
-
const coerceRtlRegex = options.includePrerelease ?
|
|
24241
|
+
const coerceRtlRegex = options.includePrerelease ? re2[t.COERCERTLFULL] : re2[t.COERCERTL];
|
|
24242
24242
|
let next;
|
|
24243
24243
|
while ((next = coerceRtlRegex.exec(version2)) && (!match || match.index + match[0].length !== version2.length)) {
|
|
24244
24244
|
if (!match || next.index + next[0].length !== match.index + match[0].length) {
|
|
@@ -24377,20 +24377,20 @@ var require_range = __commonJS({
|
|
|
24377
24377
|
return cached;
|
|
24378
24378
|
}
|
|
24379
24379
|
const loose = this.options.loose;
|
|
24380
|
-
const hr = loose ?
|
|
24380
|
+
const hr = loose ? re2[t.HYPHENRANGELOOSE] : re2[t.HYPHENRANGE];
|
|
24381
24381
|
range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
|
|
24382
24382
|
debug("hyphen replace", range);
|
|
24383
|
-
range = range.replace(
|
|
24383
|
+
range = range.replace(re2[t.COMPARATORTRIM], comparatorTrimReplace);
|
|
24384
24384
|
debug("comparator trim", range);
|
|
24385
|
-
range = range.replace(
|
|
24385
|
+
range = range.replace(re2[t.TILDETRIM], tildeTrimReplace);
|
|
24386
24386
|
debug("tilde trim", range);
|
|
24387
|
-
range = range.replace(
|
|
24387
|
+
range = range.replace(re2[t.CARETTRIM], caretTrimReplace);
|
|
24388
24388
|
debug("caret trim", range);
|
|
24389
24389
|
let rangeList = range.split(" ").map((comp) => parseComparator(comp, this.options)).join(" ").split(/\s+/).map((comp) => replaceGTE0(comp, this.options));
|
|
24390
24390
|
if (loose) {
|
|
24391
24391
|
rangeList = rangeList.filter((comp) => {
|
|
24392
24392
|
debug("loose invalid filter", comp, this.options);
|
|
24393
|
-
return !!comp.match(
|
|
24393
|
+
return !!comp.match(re2[t.COMPARATORLOOSE]);
|
|
24394
24394
|
});
|
|
24395
24395
|
}
|
|
24396
24396
|
debug("range list", rangeList);
|
|
@@ -24451,7 +24451,7 @@ var require_range = __commonJS({
|
|
|
24451
24451
|
var debug = require_debug2();
|
|
24452
24452
|
var SemVer = require_semver();
|
|
24453
24453
|
var {
|
|
24454
|
-
safeRe:
|
|
24454
|
+
safeRe: re2,
|
|
24455
24455
|
t,
|
|
24456
24456
|
comparatorTrimReplace,
|
|
24457
24457
|
tildeTrimReplace,
|
|
@@ -24489,21 +24489,21 @@ var require_range = __commonJS({
|
|
|
24489
24489
|
return comp.trim().split(/\s+/).map((c) => replaceTilde(c, options)).join(" ");
|
|
24490
24490
|
};
|
|
24491
24491
|
var replaceTilde = (comp, options) => {
|
|
24492
|
-
const r = options.loose ?
|
|
24493
|
-
return comp.replace(r, (_, M, m,
|
|
24494
|
-
debug("tilde", comp, _, M, m,
|
|
24492
|
+
const r = options.loose ? re2[t.TILDELOOSE] : re2[t.TILDE];
|
|
24493
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
|
24494
|
+
debug("tilde", comp, _, M, m, p, pr);
|
|
24495
24495
|
let ret;
|
|
24496
24496
|
if (isX(M)) {
|
|
24497
24497
|
ret = "";
|
|
24498
24498
|
} else if (isX(m)) {
|
|
24499
24499
|
ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
|
24500
|
-
} else if (isX(
|
|
24500
|
+
} else if (isX(p)) {
|
|
24501
24501
|
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
|
24502
24502
|
} else if (pr) {
|
|
24503
24503
|
debug("replaceTilde pr", pr);
|
|
24504
|
-
ret = `>=${M}.${m}.${
|
|
24504
|
+
ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
24505
24505
|
} else {
|
|
24506
|
-
ret = `>=${M}.${m}.${
|
|
24506
|
+
ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
|
|
24507
24507
|
}
|
|
24508
24508
|
debug("tilde return", ret);
|
|
24509
24509
|
return ret;
|
|
@@ -24514,42 +24514,42 @@ var require_range = __commonJS({
|
|
|
24514
24514
|
};
|
|
24515
24515
|
var replaceCaret = (comp, options) => {
|
|
24516
24516
|
debug("caret", comp, options);
|
|
24517
|
-
const r = options.loose ?
|
|
24518
|
-
const
|
|
24519
|
-
return comp.replace(r, (_, M, m,
|
|
24520
|
-
debug("caret", comp, _, M, m,
|
|
24517
|
+
const r = options.loose ? re2[t.CARETLOOSE] : re2[t.CARET];
|
|
24518
|
+
const z2 = options.includePrerelease ? "-0" : "";
|
|
24519
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
|
24520
|
+
debug("caret", comp, _, M, m, p, pr);
|
|
24521
24521
|
let ret;
|
|
24522
24522
|
if (isX(M)) {
|
|
24523
24523
|
ret = "";
|
|
24524
24524
|
} else if (isX(m)) {
|
|
24525
|
-
ret = `>=${M}.0.0${
|
|
24526
|
-
} else if (isX(
|
|
24525
|
+
ret = `>=${M}.0.0${z2} <${+M + 1}.0.0-0`;
|
|
24526
|
+
} else if (isX(p)) {
|
|
24527
24527
|
if (M === "0") {
|
|
24528
|
-
ret = `>=${M}.${m}.0${
|
|
24528
|
+
ret = `>=${M}.${m}.0${z2} <${M}.${+m + 1}.0-0`;
|
|
24529
24529
|
} else {
|
|
24530
|
-
ret = `>=${M}.${m}.0${
|
|
24530
|
+
ret = `>=${M}.${m}.0${z2} <${+M + 1}.0.0-0`;
|
|
24531
24531
|
}
|
|
24532
24532
|
} else if (pr) {
|
|
24533
24533
|
debug("replaceCaret pr", pr);
|
|
24534
24534
|
if (M === "0") {
|
|
24535
24535
|
if (m === "0") {
|
|
24536
|
-
ret = `>=${M}.${m}.${
|
|
24536
|
+
ret = `>=${M}.${m}.${p}-${pr} <${M}.${m}.${+p + 1}-0`;
|
|
24537
24537
|
} else {
|
|
24538
|
-
ret = `>=${M}.${m}.${
|
|
24538
|
+
ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
24539
24539
|
}
|
|
24540
24540
|
} else {
|
|
24541
|
-
ret = `>=${M}.${m}.${
|
|
24541
|
+
ret = `>=${M}.${m}.${p}-${pr} <${+M + 1}.0.0-0`;
|
|
24542
24542
|
}
|
|
24543
24543
|
} else {
|
|
24544
24544
|
debug("no pr");
|
|
24545
24545
|
if (M === "0") {
|
|
24546
24546
|
if (m === "0") {
|
|
24547
|
-
ret = `>=${M}.${m}.${
|
|
24547
|
+
ret = `>=${M}.${m}.${p}${z2} <${M}.${m}.${+p + 1}-0`;
|
|
24548
24548
|
} else {
|
|
24549
|
-
ret = `>=${M}.${m}.${
|
|
24549
|
+
ret = `>=${M}.${m}.${p}${z2} <${M}.${+m + 1}.0-0`;
|
|
24550
24550
|
}
|
|
24551
24551
|
} else {
|
|
24552
|
-
ret = `>=${M}.${m}.${
|
|
24552
|
+
ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
|
|
24553
24553
|
}
|
|
24554
24554
|
}
|
|
24555
24555
|
debug("caret return", ret);
|
|
@@ -24562,12 +24562,12 @@ var require_range = __commonJS({
|
|
|
24562
24562
|
};
|
|
24563
24563
|
var replaceXRange = (comp, options) => {
|
|
24564
24564
|
comp = comp.trim();
|
|
24565
|
-
const r = options.loose ?
|
|
24566
|
-
return comp.replace(r, (ret, gtlt, M, m,
|
|
24567
|
-
debug("xRange", comp, ret, gtlt, M, m,
|
|
24565
|
+
const r = options.loose ? re2[t.XRANGELOOSE] : re2[t.XRANGE];
|
|
24566
|
+
return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
|
|
24567
|
+
debug("xRange", comp, ret, gtlt, M, m, p, pr);
|
|
24568
24568
|
const xM = isX(M);
|
|
24569
24569
|
const xm = xM || isX(m);
|
|
24570
|
-
const xp = xm || isX(
|
|
24570
|
+
const xp = xm || isX(p);
|
|
24571
24571
|
const anyX = xp;
|
|
24572
24572
|
if (gtlt === "=" && anyX) {
|
|
24573
24573
|
gtlt = "";
|
|
@@ -24583,16 +24583,16 @@ var require_range = __commonJS({
|
|
|
24583
24583
|
if (xm) {
|
|
24584
24584
|
m = 0;
|
|
24585
24585
|
}
|
|
24586
|
-
|
|
24586
|
+
p = 0;
|
|
24587
24587
|
if (gtlt === ">") {
|
|
24588
24588
|
gtlt = ">=";
|
|
24589
24589
|
if (xm) {
|
|
24590
24590
|
M = +M + 1;
|
|
24591
24591
|
m = 0;
|
|
24592
|
-
|
|
24592
|
+
p = 0;
|
|
24593
24593
|
} else {
|
|
24594
24594
|
m = +m + 1;
|
|
24595
|
-
|
|
24595
|
+
p = 0;
|
|
24596
24596
|
}
|
|
24597
24597
|
} else if (gtlt === "<=") {
|
|
24598
24598
|
gtlt = "<";
|
|
@@ -24605,7 +24605,7 @@ var require_range = __commonJS({
|
|
|
24605
24605
|
if (gtlt === "<") {
|
|
24606
24606
|
pr = "-0";
|
|
24607
24607
|
}
|
|
24608
|
-
ret = `${gtlt + M}.${m}.${
|
|
24608
|
+
ret = `${gtlt + M}.${m}.${p}${pr}`;
|
|
24609
24609
|
} else if (xm) {
|
|
24610
24610
|
ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
|
|
24611
24611
|
} else if (xp) {
|
|
@@ -24617,11 +24617,11 @@ var require_range = __commonJS({
|
|
|
24617
24617
|
};
|
|
24618
24618
|
var replaceStars = (comp, options) => {
|
|
24619
24619
|
debug("replaceStars", comp, options);
|
|
24620
|
-
return comp.trim().replace(
|
|
24620
|
+
return comp.trim().replace(re2[t.STAR], "");
|
|
24621
24621
|
};
|
|
24622
24622
|
var replaceGTE0 = (comp, options) => {
|
|
24623
24623
|
debug("replaceGTE0", comp, options);
|
|
24624
|
-
return comp.trim().replace(
|
|
24624
|
+
return comp.trim().replace(re2[options.includePrerelease ? t.GTE0PRE : t.GTE0], "");
|
|
24625
24625
|
};
|
|
24626
24626
|
var hyphenReplace = (incPr) => ($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr) => {
|
|
24627
24627
|
if (isX(fM)) {
|
|
@@ -24707,7 +24707,7 @@ var require_comparator = __commonJS({
|
|
|
24707
24707
|
debug("comp", this);
|
|
24708
24708
|
}
|
|
24709
24709
|
parse(comp) {
|
|
24710
|
-
const r = this.options.loose ?
|
|
24710
|
+
const r = this.options.loose ? re2[t.COMPARATORLOOSE] : re2[t.COMPARATOR];
|
|
24711
24711
|
const m = comp.match(r);
|
|
24712
24712
|
if (!m) {
|
|
24713
24713
|
throw new TypeError(`Invalid comparator: ${comp}`);
|
|
@@ -24781,7 +24781,7 @@ var require_comparator = __commonJS({
|
|
|
24781
24781
|
};
|
|
24782
24782
|
module2.exports = Comparator;
|
|
24783
24783
|
var parseOptions = require_parse_options();
|
|
24784
|
-
var { safeRe:
|
|
24784
|
+
var { safeRe: re2, t } = require_re();
|
|
24785
24785
|
var cmp = require_cmp();
|
|
24786
24786
|
var debug = require_debug2();
|
|
24787
24787
|
var SemVer = require_semver();
|
|
@@ -24831,10 +24831,10 @@ var require_max_satisfying = __commonJS({
|
|
|
24831
24831
|
} catch (er) {
|
|
24832
24832
|
return null;
|
|
24833
24833
|
}
|
|
24834
|
-
versions.forEach((
|
|
24835
|
-
if (rangeObj.test(
|
|
24836
|
-
if (!max || maxSV.compare(
|
|
24837
|
-
max =
|
|
24834
|
+
versions.forEach((v2) => {
|
|
24835
|
+
if (rangeObj.test(v2)) {
|
|
24836
|
+
if (!max || maxSV.compare(v2) === -1) {
|
|
24837
|
+
max = v2;
|
|
24838
24838
|
maxSV = new SemVer(max, options);
|
|
24839
24839
|
}
|
|
24840
24840
|
}
|
|
@@ -24860,10 +24860,10 @@ var require_min_satisfying = __commonJS({
|
|
|
24860
24860
|
} catch (er) {
|
|
24861
24861
|
return null;
|
|
24862
24862
|
}
|
|
24863
|
-
versions.forEach((
|
|
24864
|
-
if (rangeObj.test(
|
|
24865
|
-
if (!min || minSV.compare(
|
|
24866
|
-
min =
|
|
24863
|
+
versions.forEach((v2) => {
|
|
24864
|
+
if (rangeObj.test(v2)) {
|
|
24865
|
+
if (!min || minSV.compare(v2) === 1) {
|
|
24866
|
+
min = v2;
|
|
24867
24867
|
minSV = new SemVer(min, options);
|
|
24868
24868
|
}
|
|
24869
24869
|
}
|
|
@@ -25062,8 +25062,8 @@ var require_simplify = __commonJS({
|
|
|
25062
25062
|
const set = [];
|
|
25063
25063
|
let first = null;
|
|
25064
25064
|
let prev = null;
|
|
25065
|
-
const
|
|
25066
|
-
for (const version2 of
|
|
25065
|
+
const v2 = versions.sort((a, b) => compare(a, b, options));
|
|
25066
|
+
for (const version2 of v2) {
|
|
25067
25067
|
const included = satisfies(version2, range, options);
|
|
25068
25068
|
if (included) {
|
|
25069
25069
|
prev = version2;
|
|
@@ -25085,11 +25085,11 @@ var require_simplify = __commonJS({
|
|
|
25085
25085
|
for (const [min, max] of set) {
|
|
25086
25086
|
if (min === max) {
|
|
25087
25087
|
ranges.push(min);
|
|
25088
|
-
} else if (!max && min ===
|
|
25088
|
+
} else if (!max && min === v2[0]) {
|
|
25089
25089
|
ranges.push("*");
|
|
25090
25090
|
} else if (!max) {
|
|
25091
25091
|
ranges.push(`>=${min}`);
|
|
25092
|
-
} else if (min ===
|
|
25092
|
+
} else if (min === v2[0]) {
|
|
25093
25093
|
ranges.push(`<=${max}`);
|
|
25094
25094
|
} else {
|
|
25095
25095
|
ranges.push(`${min} - ${max}`);
|
|
@@ -26387,7 +26387,7 @@ var require_types4 = __commonJS({
|
|
|
26387
26387
|
o[k2] = m[k];
|
|
26388
26388
|
});
|
|
26389
26389
|
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
26390
|
-
for (var
|
|
26390
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
26391
26391
|
};
|
|
26392
26392
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
26393
26393
|
__exportStar(require_tokens(), exports2);
|
|
@@ -26456,10 +26456,10 @@ var require_util2 = __commonJS({
|
|
|
26456
26456
|
if (k2 === void 0) k2 = k;
|
|
26457
26457
|
o[k2] = m[k];
|
|
26458
26458
|
});
|
|
26459
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o,
|
|
26460
|
-
Object.defineProperty(o, "default", { enumerable: true, value:
|
|
26461
|
-
} : function(o,
|
|
26462
|
-
o["default"] =
|
|
26459
|
+
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
|
|
26460
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v2 });
|
|
26461
|
+
} : function(o, v2) {
|
|
26462
|
+
o["default"] = v2;
|
|
26463
26463
|
});
|
|
26464
26464
|
var __importStar = exports2 && exports2.__importStar || function(mod) {
|
|
26465
26465
|
if (mod && mod.__esModule) return mod;
|
|
@@ -26494,17 +26494,17 @@ var require_util2 = __commonJS({
|
|
|
26494
26494
|
});
|
|
26495
26495
|
};
|
|
26496
26496
|
exports2.tokenizeClass = (str, regexpStr) => {
|
|
26497
|
-
var _a, _b, _c, _d,
|
|
26497
|
+
var _a, _b, _c, _d, _e2, _f, _g;
|
|
26498
26498
|
let tokens = [], rs, c;
|
|
26499
26499
|
const regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(((?:\\)])|(((?:\\)?([^\]])))))|(\])|(?:\\)?([^])/g;
|
|
26500
26500
|
while ((rs = regexp.exec(str)) !== null) {
|
|
26501
|
-
const
|
|
26501
|
+
const p = (_g = (_f = (_e2 = (_d = (_c = (_b = (_a = rs[1] && sets.words()) !== null && _a !== void 0 ? _a : rs[2] && sets.ints()) !== null && _b !== void 0 ? _b : rs[3] && sets.whitespace()) !== null && _c !== void 0 ? _c : rs[4] && sets.notWords()) !== null && _d !== void 0 ? _d : rs[5] && sets.notInts()) !== null && _e2 !== void 0 ? _e2 : rs[6] && sets.notWhitespace()) !== null && _f !== void 0 ? _f : rs[7] && {
|
|
26502
26502
|
type: types_1.types.RANGE,
|
|
26503
26503
|
from: (rs[8] || rs[9]).charCodeAt(0),
|
|
26504
26504
|
to: (c = rs[10]).charCodeAt(c.length - 1)
|
|
26505
26505
|
}) !== null && _g !== void 0 ? _g : (c = rs[16]) && { type: types_1.types.CHAR, value: c.charCodeAt(0) };
|
|
26506
|
-
if (
|
|
26507
|
-
tokens.push(
|
|
26506
|
+
if (p) {
|
|
26507
|
+
tokens.push(p);
|
|
26508
26508
|
} else {
|
|
26509
26509
|
return [tokens, regexp.lastIndex];
|
|
26510
26510
|
}
|
|
@@ -26527,10 +26527,10 @@ var require_tokenizer = __commonJS({
|
|
|
26527
26527
|
if (k2 === void 0) k2 = k;
|
|
26528
26528
|
o[k2] = m[k];
|
|
26529
26529
|
});
|
|
26530
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o,
|
|
26531
|
-
Object.defineProperty(o, "default", { enumerable: true, value:
|
|
26532
|
-
} : function(o,
|
|
26533
|
-
o["default"] =
|
|
26530
|
+
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
|
|
26531
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v2 });
|
|
26532
|
+
} : function(o, v2) {
|
|
26533
|
+
o["default"] = v2;
|
|
26534
26534
|
});
|
|
26535
26535
|
var __importStar = exports2 && exports2.__importStar || function(mod) {
|
|
26536
26536
|
if (mod && mod.__esModule) return mod;
|
|
@@ -26828,10 +26828,10 @@ var require_sets_lookup = __commonJS({
|
|
|
26828
26828
|
if (k2 === void 0) k2 = k;
|
|
26829
26829
|
o[k2] = m[k];
|
|
26830
26830
|
});
|
|
26831
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o,
|
|
26832
|
-
Object.defineProperty(o, "default", { enumerable: true, value:
|
|
26833
|
-
} : function(o,
|
|
26834
|
-
o["default"] =
|
|
26831
|
+
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
|
|
26832
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v2 });
|
|
26833
|
+
} : function(o, v2) {
|
|
26834
|
+
o["default"] = v2;
|
|
26835
26835
|
});
|
|
26836
26836
|
var __importStar = exports2 && exports2.__importStar || function(mod) {
|
|
26837
26837
|
if (mod && mod.__esModule) return mod;
|
|
@@ -26883,10 +26883,10 @@ var require_write_set_tokens = __commonJS({
|
|
|
26883
26883
|
if (k2 === void 0) k2 = k;
|
|
26884
26884
|
o[k2] = m[k];
|
|
26885
26885
|
});
|
|
26886
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o,
|
|
26887
|
-
Object.defineProperty(o, "default", { enumerable: true, value:
|
|
26888
|
-
} : function(o,
|
|
26889
|
-
o["default"] =
|
|
26886
|
+
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
|
|
26887
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v2 });
|
|
26888
|
+
} : function(o, v2) {
|
|
26889
|
+
o["default"] = v2;
|
|
26890
26890
|
});
|
|
26891
26891
|
var __importStar = exports2 && exports2.__importStar || function(mod) {
|
|
26892
26892
|
if (mod && mod.__esModule) return mod;
|
|
@@ -27037,7 +27037,7 @@ var require_dist3 = __commonJS({
|
|
|
27037
27037
|
o[k2] = m[k];
|
|
27038
27038
|
});
|
|
27039
27039
|
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
27040
|
-
for (var
|
|
27040
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
27041
27041
|
};
|
|
27042
27042
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
27043
27043
|
exports2.types = void 0;
|
|
@@ -27063,13 +27063,13 @@ var require_safe_regex2 = __commonJS({
|
|
|
27063
27063
|
"use strict";
|
|
27064
27064
|
var parse = require_dist3();
|
|
27065
27065
|
var types = parse.types;
|
|
27066
|
-
function safeRegex(
|
|
27066
|
+
function safeRegex(re2, opts) {
|
|
27067
27067
|
if (!opts) opts = {};
|
|
27068
27068
|
const replimit = opts.limit === void 0 ? 25 : opts.limit;
|
|
27069
|
-
if (isRegExp(
|
|
27070
|
-
else if (typeof
|
|
27069
|
+
if (isRegExp(re2)) re2 = re2.source;
|
|
27070
|
+
else if (typeof re2 !== "string") re2 = String(re2);
|
|
27071
27071
|
try {
|
|
27072
|
-
|
|
27072
|
+
re2 = parse(re2);
|
|
27073
27073
|
} catch {
|
|
27074
27074
|
return false;
|
|
27075
27075
|
}
|
|
@@ -27097,7 +27097,7 @@ var require_safe_regex2 = __commonJS({
|
|
|
27097
27097
|
if (!ok) return false;
|
|
27098
27098
|
}
|
|
27099
27099
|
return true;
|
|
27100
|
-
}(
|
|
27100
|
+
}(re2, 0);
|
|
27101
27101
|
}
|
|
27102
27102
|
function isRegExp(x) {
|
|
27103
27103
|
return {}.toString.call(x) === "[object RegExp]";
|
|
@@ -34619,7 +34619,7 @@ var require_util3 = __commonJS({
|
|
|
34619
34619
|
var { InvalidArgumentError, ConnectTimeoutError } = require_errors5();
|
|
34620
34620
|
var { headerNameLowerCasedRecord } = require_constants3();
|
|
34621
34621
|
var { tree } = require_tree();
|
|
34622
|
-
var [nodeMajor, nodeMinor] = process.versions.node.split(".", 2).map((
|
|
34622
|
+
var [nodeMajor, nodeMinor] = process.versions.node.split(".", 2).map((v2) => Number(v2));
|
|
34623
34623
|
var BodyAsyncIterable = class {
|
|
34624
34624
|
constructor(body) {
|
|
34625
34625
|
this[kBody] = body;
|
|
@@ -35763,14 +35763,14 @@ var require_wrap_handler = __commonJS({
|
|
|
35763
35763
|
onRequestUpgrade(controller, statusCode, headers, socket) {
|
|
35764
35764
|
const rawHeaders = [];
|
|
35765
35765
|
for (const [key, val] of Object.entries(headers)) {
|
|
35766
|
-
rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((
|
|
35766
|
+
rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((v2) => Buffer.from(v2)) : Buffer.from(val));
|
|
35767
35767
|
}
|
|
35768
35768
|
this.#handler.onUpgrade?.(statusCode, rawHeaders, socket);
|
|
35769
35769
|
}
|
|
35770
35770
|
onResponseStart(controller, statusCode, headers, statusMessage) {
|
|
35771
35771
|
const rawHeaders = [];
|
|
35772
35772
|
for (const [key, val] of Object.entries(headers)) {
|
|
35773
|
-
rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((
|
|
35773
|
+
rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((v2) => Buffer.from(v2)) : Buffer.from(val));
|
|
35774
35774
|
}
|
|
35775
35775
|
if (this.#handler.onHeaders?.(statusCode, rawHeaders, () => controller.resume(), statusMessage) === false) {
|
|
35776
35776
|
controller.pause();
|
|
@@ -35784,7 +35784,7 @@ var require_wrap_handler = __commonJS({
|
|
|
35784
35784
|
onResponseEnd(controller, trailers) {
|
|
35785
35785
|
const rawTrailers = [];
|
|
35786
35786
|
for (const [key, val] of Object.entries(trailers)) {
|
|
35787
|
-
rawTrailers.push(Buffer.from(key), Array.isArray(val) ? val.map((
|
|
35787
|
+
rawTrailers.push(Buffer.from(key), Array.isArray(val) ? val.map((v2) => Buffer.from(v2)) : Buffer.from(val));
|
|
35788
35788
|
}
|
|
35789
35789
|
this.#handler.onComplete?.(rawTrailers);
|
|
35790
35790
|
}
|
|
@@ -38306,11 +38306,11 @@ var require_util4 = __commonJS({
|
|
|
38306
38306
|
}
|
|
38307
38307
|
function tryUpgradeRequestToAPotentiallyTrustworthyURL(request) {
|
|
38308
38308
|
}
|
|
38309
|
-
function sameOrigin(
|
|
38310
|
-
if (
|
|
38309
|
+
function sameOrigin(A, B2) {
|
|
38310
|
+
if (A.origin === B2.origin && A.origin === "null") {
|
|
38311
38311
|
return true;
|
|
38312
38312
|
}
|
|
38313
|
-
if (
|
|
38313
|
+
if (A.protocol === B2.protocol && A.hostname === B2.hostname && A.port === B2.port) {
|
|
38314
38314
|
return true;
|
|
38315
38315
|
}
|
|
38316
38316
|
return false;
|
|
@@ -39607,7 +39607,7 @@ var require_client_h1 = __commonJS({
|
|
|
39607
39607
|
* @param {number} len
|
|
39608
39608
|
* @returns {number}
|
|
39609
39609
|
*/
|
|
39610
|
-
wasm_on_url: (
|
|
39610
|
+
wasm_on_url: (p, at, len) => {
|
|
39611
39611
|
return 0;
|
|
39612
39612
|
},
|
|
39613
39613
|
/**
|
|
@@ -39616,8 +39616,8 @@ var require_client_h1 = __commonJS({
|
|
|
39616
39616
|
* @param {number} len
|
|
39617
39617
|
* @returns {number}
|
|
39618
39618
|
*/
|
|
39619
|
-
wasm_on_status: (
|
|
39620
|
-
assert(currentParser.ptr ===
|
|
39619
|
+
wasm_on_status: (p, at, len) => {
|
|
39620
|
+
assert(currentParser.ptr === p);
|
|
39621
39621
|
const start = at - currentBufferPtr + currentBufferRef.byteOffset;
|
|
39622
39622
|
return currentParser.onStatus(new FastBuffer(currentBufferRef.buffer, start, len));
|
|
39623
39623
|
},
|
|
@@ -39625,8 +39625,8 @@ var require_client_h1 = __commonJS({
|
|
|
39625
39625
|
* @param {number} p
|
|
39626
39626
|
* @returns {number}
|
|
39627
39627
|
*/
|
|
39628
|
-
wasm_on_message_begin: (
|
|
39629
|
-
assert(currentParser.ptr ===
|
|
39628
|
+
wasm_on_message_begin: (p) => {
|
|
39629
|
+
assert(currentParser.ptr === p);
|
|
39630
39630
|
return currentParser.onMessageBegin();
|
|
39631
39631
|
},
|
|
39632
39632
|
/**
|
|
@@ -39635,8 +39635,8 @@ var require_client_h1 = __commonJS({
|
|
|
39635
39635
|
* @param {number} len
|
|
39636
39636
|
* @returns {number}
|
|
39637
39637
|
*/
|
|
39638
|
-
wasm_on_header_field: (
|
|
39639
|
-
assert(currentParser.ptr ===
|
|
39638
|
+
wasm_on_header_field: (p, at, len) => {
|
|
39639
|
+
assert(currentParser.ptr === p);
|
|
39640
39640
|
const start = at - currentBufferPtr + currentBufferRef.byteOffset;
|
|
39641
39641
|
return currentParser.onHeaderField(new FastBuffer(currentBufferRef.buffer, start, len));
|
|
39642
39642
|
},
|
|
@@ -39646,8 +39646,8 @@ var require_client_h1 = __commonJS({
|
|
|
39646
39646
|
* @param {number} len
|
|
39647
39647
|
* @returns {number}
|
|
39648
39648
|
*/
|
|
39649
|
-
wasm_on_header_value: (
|
|
39650
|
-
assert(currentParser.ptr ===
|
|
39649
|
+
wasm_on_header_value: (p, at, len) => {
|
|
39650
|
+
assert(currentParser.ptr === p);
|
|
39651
39651
|
const start = at - currentBufferPtr + currentBufferRef.byteOffset;
|
|
39652
39652
|
return currentParser.onHeaderValue(new FastBuffer(currentBufferRef.buffer, start, len));
|
|
39653
39653
|
},
|
|
@@ -39658,8 +39658,8 @@ var require_client_h1 = __commonJS({
|
|
|
39658
39658
|
* @param {0|1} shouldKeepAlive
|
|
39659
39659
|
* @returns {number}
|
|
39660
39660
|
*/
|
|
39661
|
-
wasm_on_headers_complete: (
|
|
39662
|
-
assert(currentParser.ptr ===
|
|
39661
|
+
wasm_on_headers_complete: (p, statusCode, upgrade, shouldKeepAlive) => {
|
|
39662
|
+
assert(currentParser.ptr === p);
|
|
39663
39663
|
return currentParser.onHeadersComplete(statusCode, upgrade === 1, shouldKeepAlive === 1);
|
|
39664
39664
|
},
|
|
39665
39665
|
/**
|
|
@@ -39668,8 +39668,8 @@ var require_client_h1 = __commonJS({
|
|
|
39668
39668
|
* @param {number} len
|
|
39669
39669
|
* @returns {number}
|
|
39670
39670
|
*/
|
|
39671
|
-
wasm_on_body: (
|
|
39672
|
-
assert(currentParser.ptr ===
|
|
39671
|
+
wasm_on_body: (p, at, len) => {
|
|
39672
|
+
assert(currentParser.ptr === p);
|
|
39673
39673
|
const start = at - currentBufferPtr + currentBufferRef.byteOffset;
|
|
39674
39674
|
return currentParser.onBody(new FastBuffer(currentBufferRef.buffer, start, len));
|
|
39675
39675
|
},
|
|
@@ -39677,8 +39677,8 @@ var require_client_h1 = __commonJS({
|
|
|
39677
39677
|
* @param {number} p
|
|
39678
39678
|
* @returns {number}
|
|
39679
39679
|
*/
|
|
39680
|
-
wasm_on_message_complete: (
|
|
39681
|
-
assert(currentParser.ptr ===
|
|
39680
|
+
wasm_on_message_complete: (p) => {
|
|
39681
|
+
assert(currentParser.ptr === p);
|
|
39682
39682
|
return currentParser.onMessageComplete();
|
|
39683
39683
|
}
|
|
39684
39684
|
}
|
|
@@ -42207,7 +42207,7 @@ var require_balanced_pool = __commonJS({
|
|
|
42207
42207
|
return this;
|
|
42208
42208
|
}
|
|
42209
42209
|
get upstreams() {
|
|
42210
|
-
return this[kClients].filter((dispatcher) => dispatcher.closed !== true && dispatcher.destroyed !== true).map((
|
|
42210
|
+
return this[kClients].filter((dispatcher) => dispatcher.closed !== true && dispatcher.destroyed !== true).map((p) => p[kUrl].origin);
|
|
42211
42211
|
}
|
|
42212
42212
|
[kGetDispatcher]() {
|
|
42213
42213
|
if (this[kClients].length === 0) {
|
|
@@ -44490,8 +44490,8 @@ var require_mock_utils = __commonJS({
|
|
|
44490
44490
|
}
|
|
44491
44491
|
if (value.includes(",")) {
|
|
44492
44492
|
const values = value.split(",");
|
|
44493
|
-
for (const
|
|
44494
|
-
normalizedQp.append(key,
|
|
44493
|
+
for (const v2 of values) {
|
|
44494
|
+
normalizedQp.append(key, v2);
|
|
44495
44495
|
}
|
|
44496
44496
|
continue;
|
|
44497
44497
|
}
|
|
@@ -48573,12 +48573,12 @@ var require_response2 = __commonJS({
|
|
|
48573
48573
|
...state
|
|
48574
48574
|
};
|
|
48575
48575
|
return new Proxy(response, {
|
|
48576
|
-
get(target,
|
|
48577
|
-
return
|
|
48576
|
+
get(target, p) {
|
|
48577
|
+
return p in state ? state[p] : target[p];
|
|
48578
48578
|
},
|
|
48579
|
-
set(target,
|
|
48580
|
-
assert(!(
|
|
48581
|
-
target[
|
|
48579
|
+
set(target, p, value) {
|
|
48580
|
+
assert(!(p in state));
|
|
48581
|
+
target[p] = value;
|
|
48582
48582
|
return true;
|
|
48583
48583
|
}
|
|
48584
48584
|
});
|
|
@@ -49581,18 +49581,18 @@ var require_fetch = __commonJS({
|
|
|
49581
49581
|
}
|
|
49582
49582
|
function fetch2(input, init = void 0) {
|
|
49583
49583
|
webidl.argumentLengthCheck(arguments, 1, "globalThis.fetch");
|
|
49584
|
-
let
|
|
49584
|
+
let p = createDeferredPromise();
|
|
49585
49585
|
let requestObject;
|
|
49586
49586
|
try {
|
|
49587
49587
|
requestObject = new Request(input, init);
|
|
49588
49588
|
} catch (e) {
|
|
49589
|
-
|
|
49590
|
-
return
|
|
49589
|
+
p.reject(e);
|
|
49590
|
+
return p.promise;
|
|
49591
49591
|
}
|
|
49592
49592
|
const request = getRequestState(requestObject);
|
|
49593
49593
|
if (requestObject.signal.aborted) {
|
|
49594
|
-
abortFetch(
|
|
49595
|
-
return
|
|
49594
|
+
abortFetch(p, request, null, requestObject.signal.reason);
|
|
49595
|
+
return p.promise;
|
|
49596
49596
|
}
|
|
49597
49597
|
const globalObject = request.client.globalObject;
|
|
49598
49598
|
if (globalObject?.constructor?.name === "ServiceWorkerGlobalScope") {
|
|
@@ -49608,7 +49608,7 @@ var require_fetch = __commonJS({
|
|
|
49608
49608
|
assert(controller != null);
|
|
49609
49609
|
controller.abort(requestObject.signal.reason);
|
|
49610
49610
|
const realResponse = responseObject?.deref();
|
|
49611
|
-
abortFetch(
|
|
49611
|
+
abortFetch(p, request, realResponse, requestObject.signal.reason);
|
|
49612
49612
|
}
|
|
49613
49613
|
);
|
|
49614
49614
|
const processResponse = (response) => {
|
|
@@ -49616,16 +49616,16 @@ var require_fetch = __commonJS({
|
|
|
49616
49616
|
return;
|
|
49617
49617
|
}
|
|
49618
49618
|
if (response.aborted) {
|
|
49619
|
-
abortFetch(
|
|
49619
|
+
abortFetch(p, request, responseObject, controller.serializedAbortReason);
|
|
49620
49620
|
return;
|
|
49621
49621
|
}
|
|
49622
49622
|
if (response.type === "error") {
|
|
49623
|
-
|
|
49623
|
+
p.reject(new TypeError("fetch failed", { cause: response.error }));
|
|
49624
49624
|
return;
|
|
49625
49625
|
}
|
|
49626
49626
|
responseObject = new WeakRef(fromInnerResponse(response, "immutable"));
|
|
49627
|
-
|
|
49628
|
-
|
|
49627
|
+
p.resolve(responseObject.deref());
|
|
49628
|
+
p = null;
|
|
49629
49629
|
};
|
|
49630
49630
|
controller = fetching({
|
|
49631
49631
|
request,
|
|
@@ -49634,7 +49634,7 @@ var require_fetch = __commonJS({
|
|
|
49634
49634
|
dispatcher: getRequestDispatcher(requestObject)
|
|
49635
49635
|
// undici
|
|
49636
49636
|
});
|
|
49637
|
-
return
|
|
49637
|
+
return p.promise;
|
|
49638
49638
|
}
|
|
49639
49639
|
function finalizeAndReportTiming(response, initiatorType = "other") {
|
|
49640
49640
|
if (response.type === "error" && response.aborted) {
|
|
@@ -49672,9 +49672,9 @@ var require_fetch = __commonJS({
|
|
|
49672
49672
|
);
|
|
49673
49673
|
}
|
|
49674
49674
|
var markResourceTiming = performance.markResourceTiming;
|
|
49675
|
-
function abortFetch(
|
|
49676
|
-
if (
|
|
49677
|
-
|
|
49675
|
+
function abortFetch(p, request, responseObject, error) {
|
|
49676
|
+
if (p) {
|
|
49677
|
+
p.reject(error);
|
|
49678
49678
|
}
|
|
49679
49679
|
if (request.body?.stream != null && isReadable(request.body.stream)) {
|
|
49680
49680
|
request.body.stream.cancel(error).catch((err) => {
|
|
@@ -50552,9 +50552,9 @@ var require_util5 = __commonJS({
|
|
|
50552
50552
|
var assert = require("node:assert");
|
|
50553
50553
|
var { URLSerializer } = require_data_url();
|
|
50554
50554
|
var { isValidHeaderName } = require_util4();
|
|
50555
|
-
function urlEquals(
|
|
50556
|
-
const serializedA = URLSerializer(
|
|
50557
|
-
const serializedB = URLSerializer(
|
|
50555
|
+
function urlEquals(A, B2, excludeFragment = false) {
|
|
50556
|
+
const serializedA = URLSerializer(A, excludeFragment);
|
|
50557
|
+
const serializedB = URLSerializer(B2, excludeFragment);
|
|
50558
50558
|
return serializedA === serializedB;
|
|
50559
50559
|
}
|
|
50560
50560
|
function getFieldValues(header) {
|
|
@@ -50607,11 +50607,11 @@ var require_cache3 = __commonJS({
|
|
|
50607
50607
|
webidl.argumentLengthCheck(arguments, 1, prefix);
|
|
50608
50608
|
request = webidl.converters.RequestInfo(request, prefix, "request");
|
|
50609
50609
|
options = webidl.converters.CacheQueryOptions(options, prefix, "options");
|
|
50610
|
-
const
|
|
50611
|
-
if (
|
|
50610
|
+
const p = this.#internalMatchAll(request, options, 1);
|
|
50611
|
+
if (p.length === 0) {
|
|
50612
50612
|
return;
|
|
50613
50613
|
}
|
|
50614
|
-
return
|
|
50614
|
+
return p[0];
|
|
50615
50615
|
}
|
|
50616
50616
|
async matchAll(request = void 0, options = {}) {
|
|
50617
50617
|
webidl.brandCheck(this, _Cache);
|
|
@@ -50702,8 +50702,8 @@ var require_cache3 = __commonJS({
|
|
|
50702
50702
|
}));
|
|
50703
50703
|
responsePromises.push(responsePromise.promise);
|
|
50704
50704
|
}
|
|
50705
|
-
const
|
|
50706
|
-
const responses = await
|
|
50705
|
+
const p = Promise.all(responsePromises);
|
|
50706
|
+
const responses = await p;
|
|
50707
50707
|
const operations = [];
|
|
50708
50708
|
let index = 0;
|
|
50709
50709
|
for (const response of responses) {
|
|
@@ -53005,10 +53005,10 @@ var require_websocket = __commonJS({
|
|
|
53005
53005
|
if (typeof protocols === "string") {
|
|
53006
53006
|
protocols = [protocols];
|
|
53007
53007
|
}
|
|
53008
|
-
if (protocols.length !== new Set(protocols.map((
|
|
53008
|
+
if (protocols.length !== new Set(protocols.map((p) => p.toLowerCase())).size) {
|
|
53009
53009
|
throw new DOMException("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
|
|
53010
53010
|
}
|
|
53011
|
-
if (protocols.length > 0 && !protocols.every((
|
|
53011
|
+
if (protocols.length > 0 && !protocols.every((p) => isValidSubprotocol(p))) {
|
|
53012
53012
|
throw new DOMException("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
|
|
53013
53013
|
}
|
|
53014
53014
|
this.#url = new URL(urlRecord.href);
|
|
@@ -53496,10 +53496,10 @@ var require_websocketstream = __commonJS({
|
|
|
53496
53496
|
const baseURL = environmentSettingsObject.settingsObject.baseUrl;
|
|
53497
53497
|
const urlRecord = getURLRecord(url, baseURL);
|
|
53498
53498
|
const protocols = options.protocols;
|
|
53499
|
-
if (protocols.length !== new Set(protocols.map((
|
|
53499
|
+
if (protocols.length !== new Set(protocols.map((p) => p.toLowerCase())).size) {
|
|
53500
53500
|
throw new DOMException("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
|
|
53501
53501
|
}
|
|
53502
|
-
if (protocols.length > 0 && !protocols.every((
|
|
53502
|
+
if (protocols.length > 0 && !protocols.every((p) => isValidSubprotocol(p))) {
|
|
53503
53503
|
throw new DOMException("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
|
|
53504
53504
|
}
|
|
53505
53505
|
this.#url = urlRecord.toString();
|
|
@@ -54928,7 +54928,7 @@ var readConfigFile = async () => {
|
|
|
54928
54928
|
return JSON.parse(config);
|
|
54929
54929
|
} catch {
|
|
54930
54930
|
const name = await question("Enter Provider Name: ");
|
|
54931
|
-
const
|
|
54931
|
+
const APIKEY = await question("Enter Provider API KEY: ");
|
|
54932
54932
|
const baseUrl = await question("Enter Provider URL: ");
|
|
54933
54933
|
const model = await question("Enter MODEL Name: ");
|
|
54934
54934
|
const config = Object.assign({}, DEFAULT_CONFIG, {
|
|
@@ -54936,7 +54936,7 @@ var readConfigFile = async () => {
|
|
|
54936
54936
|
{
|
|
54937
54937
|
name,
|
|
54938
54938
|
api_base_url: baseUrl,
|
|
54939
|
-
api_key:
|
|
54939
|
+
api_key: APIKEY,
|
|
54940
54940
|
models: [model]
|
|
54941
54941
|
}
|
|
54942
54942
|
],
|
|
@@ -54958,7 +54958,7 @@ var initConfig = async () => {
|
|
|
54958
54958
|
return config;
|
|
54959
54959
|
};
|
|
54960
54960
|
|
|
54961
|
-
// node_modules/.pnpm/@musistudio+llms@1.0.
|
|
54961
|
+
// node_modules/.pnpm/@musistudio+llms@1.0.7_ws@8.18.3_zod@3.25.67/node_modules/@musistudio/llms/dist/esm/server.mjs
|
|
54962
54962
|
var import_fastify = __toESM(require_fastify(), 1);
|
|
54963
54963
|
var import_cors = __toESM(require_cors(), 1);
|
|
54964
54964
|
var import_fs = require("fs");
|
|
@@ -54966,19 +54966,21 @@ var import_path = require("path");
|
|
|
54966
54966
|
var import_dotenv = __toESM(require_main(), 1);
|
|
54967
54967
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
54968
54968
|
var import_undici = __toESM(require_undici(), 1);
|
|
54969
|
+
var import_crypto = require("crypto");
|
|
54970
|
+
var import_crypto2 = require("crypto");
|
|
54969
54971
|
var import_node_module = __toESM(require("node:module"), 1);
|
|
54970
|
-
var
|
|
54972
|
+
var Y = ((s) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(s, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : s)(function(s) {
|
|
54971
54973
|
if (typeof require < "u") return require.apply(this, arguments);
|
|
54972
|
-
throw Error('Dynamic require of "' +
|
|
54974
|
+
throw Error('Dynamic require of "' + s + '" is not supported');
|
|
54973
54975
|
});
|
|
54974
|
-
var
|
|
54976
|
+
var I = class {
|
|
54975
54977
|
config = {};
|
|
54976
54978
|
options;
|
|
54977
54979
|
constructor(e = { jsonPath: "./config.json" }) {
|
|
54978
54980
|
this.options = { envPath: e.envPath || ".env", jsonPath: e.jsonPath, useEnvFile: false, useJsonFile: e.useJsonFile !== false, useEnvironmentVariables: e.useEnvironmentVariables !== false, ...e }, this.loadConfig();
|
|
54979
54981
|
}
|
|
54980
54982
|
loadConfig() {
|
|
54981
|
-
this.options.initialConfig && (this.config = { ...this.config, ...this.options.initialConfig }), this.options.useEnvFile && this.loadEnvConfig(), this.
|
|
54983
|
+
this.options.useJsonFile && this.options.jsonPath && this.loadJsonConfig(), this.options.initialConfig && (this.config = { ...this.config, ...this.options.initialConfig }), this.options.useEnvFile && this.loadEnvConfig(), this.config.LOG_FILE && (process.env.LOG_FILE = this.config.LOG_FILE), this.config.LOG && (process.env.LOG = this.config.LOG);
|
|
54982
54984
|
}
|
|
54983
54985
|
loadJsonConfig() {
|
|
54984
54986
|
if (!this.options.jsonPath) return;
|
|
@@ -55035,85 +55037,85 @@ var N = class {
|
|
|
55035
55037
|
return this.options.initialConfig && e.push("Initial Config"), this.options.useJsonFile && this.options.jsonPath && e.push(`JSON: ${this.options.jsonPath}`), this.options.useEnvFile && e.push(`ENV: ${this.options.envPath}`), this.options.useEnvironmentVariables && e.push("Environment Variables"), `Config sources: ${e.join(", ")}`;
|
|
55036
55038
|
}
|
|
55037
55039
|
};
|
|
55038
|
-
function
|
|
55039
|
-
if (console.log(...
|
|
55040
|
-
let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(
|
|
55040
|
+
function v(...s) {
|
|
55041
|
+
if (console.log(...s), !(process.env.LOG === "true")) return;
|
|
55042
|
+
let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(s) ? s.map((r) => typeof r == "object" ? JSON.stringify(r) : String(r)).join(" ") : ""}
|
|
55041
55043
|
`, o = process.env.LOG_FILE || "app.log";
|
|
55042
55044
|
import_node_fs.default.appendFileSync(o, n, "utf8");
|
|
55043
55045
|
}
|
|
55044
|
-
function
|
|
55045
|
-
let o = new Error(
|
|
55046
|
+
function N(s, e = 500, t = "internal_error", n = "api_error") {
|
|
55047
|
+
let o = new Error(s);
|
|
55046
55048
|
return o.statusCode = e, o.code = t, o.type = n, o;
|
|
55047
55049
|
}
|
|
55048
|
-
async function
|
|
55049
|
-
e.log.error(
|
|
55050
|
-
let n =
|
|
55050
|
+
async function ie(s, e, t) {
|
|
55051
|
+
e.log.error(s);
|
|
55052
|
+
let n = s.statusCode || 500, o = { error: { message: s.message || "Internal Server Error", type: s.type || "api_error", code: s.code || "internal_error" } };
|
|
55051
55053
|
return t.code(n).send(o);
|
|
55052
55054
|
}
|
|
55053
|
-
function
|
|
55055
|
+
function ae(s, e, t) {
|
|
55054
55056
|
let n = new Headers({ "Content-Type": "application/json" });
|
|
55055
|
-
t.headers && Object.entries(t.headers).forEach(([
|
|
55056
|
-
n.set(
|
|
55057
|
+
t.headers && Object.entries(t.headers).forEach(([l, f]) => {
|
|
55058
|
+
n.set(l, f);
|
|
55057
55059
|
});
|
|
55058
55060
|
let o, r = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
|
|
55059
55061
|
if (t.signal) {
|
|
55060
|
-
let
|
|
55061
|
-
t.signal.addEventListener("abort",
|
|
55062
|
+
let l = new AbortController(), f = () => l.abort();
|
|
55063
|
+
t.signal.addEventListener("abort", f), r.addEventListener("abort", f), o = l.signal;
|
|
55062
55064
|
} else o = r;
|
|
55063
|
-
let
|
|
55064
|
-
return t.httpsProxy && (
|
|
55065
|
+
let d = { method: "POST", headers: n, body: JSON.stringify(e), signal: o };
|
|
55066
|
+
return t.httpsProxy && (d.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), v("final request:", typeof s == "string" ? s : s.toString(), t.httpsProxy, d), fetch(typeof s == "string" ? s : s.toString(), d);
|
|
55065
55067
|
}
|
|
55066
|
-
var
|
|
55067
|
-
|
|
55068
|
-
let e =
|
|
55069
|
-
for (let { name: t, transformer: n } of e) n.endPoint &&
|
|
55070
|
-
let
|
|
55071
|
-
if (!
|
|
55072
|
-
let
|
|
55068
|
+
var ce = async (s) => {
|
|
55069
|
+
s.get("/", async (t, n) => ({ message: "LLMs API", version: "1.0.0" })), s.get("/health", async (t, n) => ({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
55070
|
+
let e = s._server.transformerService.getTransformersWithEndpoint();
|
|
55071
|
+
for (let { name: t, transformer: n } of e) n.endPoint && s.post(n.endPoint, async (o, r) => {
|
|
55072
|
+
let d = o.body, l = o.provider, f = s._server.providerService.getProvider(l);
|
|
55073
|
+
if (!f) throw N(`Provider '${l}' not found`, 404, "provider_not_found");
|
|
55074
|
+
let a = d, m = {};
|
|
55073
55075
|
if (typeof n.transformRequestOut == "function") {
|
|
55074
|
-
let
|
|
55075
|
-
|
|
55076
|
-
}
|
|
55077
|
-
if (
|
|
55078
|
-
if (!
|
|
55079
|
-
let
|
|
55080
|
-
|
|
55081
|
-
}
|
|
55082
|
-
if (
|
|
55083
|
-
let
|
|
55084
|
-
if (!
|
|
55085
|
-
let
|
|
55086
|
-
throw
|
|
55087
|
-
}
|
|
55088
|
-
let
|
|
55089
|
-
if (
|
|
55090
|
-
if (
|
|
55091
|
-
return n.transformResponseIn && (
|
|
55076
|
+
let i = await n.transformRequestOut(d);
|
|
55077
|
+
i.body ? (a = i.body, m = i.config || {}) : a = i;
|
|
55078
|
+
}
|
|
55079
|
+
if (v("use transformers:", f.transformer?.use), f.transformer?.use?.length) for (let i of f.transformer.use) {
|
|
55080
|
+
if (!i || typeof i.transformRequestIn != "function") continue;
|
|
55081
|
+
let y = await i.transformRequestIn(a, f);
|
|
55082
|
+
y.body ? (a = y.body, m = { ...m, ...y.config }) : a = y;
|
|
55083
|
+
}
|
|
55084
|
+
if (f.transformer?.[o.body.model]?.use?.length) for (let i of f.transformer[o.body.model].use) !i || typeof i.transformRequestIn != "function" || (a = await i.transformRequestIn(a, f));
|
|
55085
|
+
let g = m.url || new URL(f.baseUrl), C = await ae(g, a, { httpsProxy: s._server.configService.getHttpsProxy(), ...m, headers: { Authorization: `Bearer ${f.apiKey}`, ...m?.headers || {} } });
|
|
55086
|
+
if (!C.ok) {
|
|
55087
|
+
let i = await C.text();
|
|
55088
|
+
throw v(`Error response from ${g}: ${i}`), N(`Error from provider: ${i}`, C.status, "provider_response_error");
|
|
55089
|
+
}
|
|
55090
|
+
let p = C;
|
|
55091
|
+
if (f.transformer?.use?.length) for (let i of f.transformer.use) !i || typeof i.transformResponseOut != "function" || (p = await i.transformResponseOut(p));
|
|
55092
|
+
if (f.transformer?.[o.body.model]?.use?.length) for (let i of f.transformer[o.body.model].use) !i || typeof i.transformResponseOut != "function" || (p = await i.transformResponseOut(p));
|
|
55093
|
+
return n.transformResponseIn && (p = await n.transformResponseIn(p)), p.ok || r.code(p.status), d?.stream === true ? (r.header("Content-Type", "text/event-stream"), r.header("Cache-Control", "no-cache"), r.header("Connection", "keep-alive"), r.send(p.body)) : p.json();
|
|
55092
55094
|
});
|
|
55093
|
-
|
|
55094
|
-
let { name: o, type: r, baseUrl:
|
|
55095
|
-
if (!o?.trim()) throw
|
|
55096
|
-
if (!
|
|
55097
|
-
if (!
|
|
55098
|
-
if (!
|
|
55099
|
-
if (
|
|
55100
|
-
return
|
|
55101
|
-
}),
|
|
55102
|
-
let o =
|
|
55095
|
+
s.post("/providers", { schema: { body: { type: "object", properties: { id: { type: "string" }, name: { type: "string" }, type: { type: "string", enum: ["openai", "anthropic"] }, baseUrl: { type: "string" }, apiKey: { type: "string" }, models: { type: "array", items: { type: "string" } } }, required: ["id", "name", "type", "baseUrl", "apiKey", "models"] } } }, async (t, n) => {
|
|
55096
|
+
let { name: o, type: r, baseUrl: d, apiKey: l, models: f } = t.body;
|
|
55097
|
+
if (!o?.trim()) throw N("Provider name is required", 400, "invalid_request");
|
|
55098
|
+
if (!d || !ve(d)) throw N("Valid base URL is required", 400, "invalid_request");
|
|
55099
|
+
if (!l?.trim()) throw N("API key is required", 400, "invalid_request");
|
|
55100
|
+
if (!f || !Array.isArray(f) || f.length === 0) throw N("At least one model is required", 400, "invalid_request");
|
|
55101
|
+
if (s._server.providerService.getProvider(id)) throw N(`Provider with ID '${id}' already exists`, 400, "provider_exists");
|
|
55102
|
+
return s._server.providerService.registerProvider(t.body);
|
|
55103
|
+
}), s.get("/providers", async (t, n) => s._server.providerService.getProviders()), s.get("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => {
|
|
55104
|
+
let o = s._server.providerService.getProvider(t.params.id);
|
|
55103
55105
|
return o || n.code(404).send({ error: "Provider not found" });
|
|
55104
|
-
}),
|
|
55105
|
-
let o =
|
|
55106
|
+
}), s.put("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] }, body: { type: "object", properties: { name: { type: "string" }, type: { type: "string", enum: ["openai", "anthropic"] }, baseUrl: { type: "string" }, apiKey: { type: "string" }, models: { type: "array", items: { type: "string" } }, enabled: { type: "boolean" } } } } }, async (t, n) => {
|
|
55107
|
+
let o = s._server.providerService.updateProvider(t.params.id, t.body);
|
|
55106
55108
|
return o || n.code(404).send({ error: "Provider not found" });
|
|
55107
|
-
}),
|
|
55109
|
+
}), s.delete("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => s._server.providerService.deleteProvider(t.params.id) ? { message: "Provider deleted successfully" } : n.code(404).send({ error: "Provider not found" })), s.patch("/providers/:id/toggle", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] }, body: { type: "object", properties: { enabled: { type: "boolean" } }, required: ["enabled"] } } }, async (t, n) => s._server.providerService.toggleProvider(t.params.id, t.body.enabled) ? { message: `Provider ${t.body.enabled ? "enabled" : "disabled"} successfully` } : n.code(404).send({ error: "Provider not found" }));
|
|
55108
55110
|
};
|
|
55109
|
-
function
|
|
55111
|
+
function ve(s) {
|
|
55110
55112
|
try {
|
|
55111
|
-
return new URL(
|
|
55113
|
+
return new URL(s), true;
|
|
55112
55114
|
} catch {
|
|
55113
55115
|
return false;
|
|
55114
55116
|
}
|
|
55115
55117
|
}
|
|
55116
|
-
var
|
|
55118
|
+
var $ = class {
|
|
55117
55119
|
constructor(e) {
|
|
55118
55120
|
this.providerService = e;
|
|
55119
55121
|
}
|
|
@@ -55150,7 +55152,7 @@ var H = class {
|
|
|
55150
55152
|
return this.providerService.getModelRoutes();
|
|
55151
55153
|
}
|
|
55152
55154
|
};
|
|
55153
|
-
var
|
|
55155
|
+
var F = class {
|
|
55154
55156
|
constructor(e, t) {
|
|
55155
55157
|
this.configService = e;
|
|
55156
55158
|
this.transformerService = t;
|
|
@@ -55173,20 +55175,20 @@ var $ = class {
|
|
|
55173
55175
|
t.transformer && Object.keys(t.transformer).forEach((o) => {
|
|
55174
55176
|
o === "use" ? Array.isArray(t.transformer.use) && (n.use = t.transformer.use.map((r) => {
|
|
55175
55177
|
if (Array.isArray(r) && typeof r[0] == "string") {
|
|
55176
|
-
let
|
|
55177
|
-
if (
|
|
55178
|
+
let d = this.transformerService.getTransformer(r[0]);
|
|
55179
|
+
if (d) return new d(r[1]);
|
|
55178
55180
|
}
|
|
55179
55181
|
if (typeof r == "string") return this.transformerService.getTransformer(r);
|
|
55180
55182
|
}).filter((r) => typeof r < "u")) : Array.isArray(t.transformer[o]?.use) && (n[o] = { use: t.transformer[o].use.map((r) => {
|
|
55181
55183
|
if (Array.isArray(r) && typeof r[0] == "string") {
|
|
55182
|
-
let
|
|
55183
|
-
if (
|
|
55184
|
+
let d = this.transformerService.getTransformer(r[0]);
|
|
55185
|
+
if (d) return new d(r[1]);
|
|
55184
55186
|
}
|
|
55185
55187
|
if (typeof r == "string") return this.transformerService.getTransformer(r);
|
|
55186
55188
|
}).filter((r) => typeof r < "u") });
|
|
55187
|
-
}),
|
|
55189
|
+
}), this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: t.transformer ? n : void 0 }), v(`${t.name} provider registered`);
|
|
55188
55190
|
} catch (n) {
|
|
55189
|
-
|
|
55191
|
+
v(`${t.name} provider registered error: ${n}`);
|
|
55190
55192
|
}
|
|
55191
55193
|
});
|
|
55192
55194
|
}
|
|
@@ -55208,11 +55210,11 @@ var $ = class {
|
|
|
55208
55210
|
if (!n) return null;
|
|
55209
55211
|
let o = { ...n, ...t, updatedAt: /* @__PURE__ */ new Date() };
|
|
55210
55212
|
return this.providers.set(e, o), t.models && (n.models.forEach((r) => {
|
|
55211
|
-
let
|
|
55212
|
-
this.modelRoutes.delete(
|
|
55213
|
+
let d = `${n.id},${r}`;
|
|
55214
|
+
this.modelRoutes.delete(d), this.modelRoutes.delete(r);
|
|
55213
55215
|
}), t.models.forEach((r) => {
|
|
55214
|
-
let
|
|
55215
|
-
this.modelRoutes.set(
|
|
55216
|
+
let d = `${n.name},${r}`, l = { provider: n.name, model: r, fullModel: d };
|
|
55217
|
+
this.modelRoutes.set(d, l), this.modelRoutes.has(r) || this.modelRoutes.set(r, l);
|
|
55216
55218
|
})), o;
|
|
55217
55219
|
}
|
|
55218
55220
|
deleteProvider(e) {
|
|
@@ -55260,37 +55262,38 @@ var $ = class {
|
|
|
55260
55262
|
}), { object: "list", data: e };
|
|
55261
55263
|
}
|
|
55262
55264
|
};
|
|
55263
|
-
var
|
|
55265
|
+
var q = class {
|
|
55264
55266
|
name = "Anthropic";
|
|
55265
55267
|
endPoint = "/v1/messages";
|
|
55266
55268
|
transformRequestOut(e) {
|
|
55267
|
-
|
|
55269
|
+
v("Anthropic Request:", JSON.stringify(e, null, 2));
|
|
55268
55270
|
let t = [];
|
|
55269
55271
|
if (e.system) {
|
|
55270
55272
|
if (typeof e.system == "string") t.push({ role: "system", content: e.system });
|
|
55271
55273
|
else if (Array.isArray(e.system)) {
|
|
55272
|
-
let r = e.system.filter((
|
|
55274
|
+
let r = e.system.filter((d) => d.type === "text" && d.text).map((d) => ({ type: "text", text: d.text, cache_control: d.cache_control }));
|
|
55273
55275
|
t.push({ role: "system", content: r });
|
|
55274
55276
|
}
|
|
55275
55277
|
}
|
|
55276
|
-
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((r,
|
|
55278
|
+
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((r, d) => {
|
|
55277
55279
|
if (r.role === "user" || r.role === "assistant") {
|
|
55278
|
-
let
|
|
55280
|
+
let l = { role: r.role, content: null };
|
|
55279
55281
|
if (typeof r.content == "string") t.push({ role: r.role, content: r.content });
|
|
55280
55282
|
else if (Array.isArray(r.content)) {
|
|
55281
55283
|
if (r.role === "user") {
|
|
55282
|
-
let
|
|
55283
|
-
|
|
55284
|
-
let
|
|
55285
|
-
t.push(
|
|
55284
|
+
let f = r.content.filter((m) => m.type === "tool_result" && m.tool_use_id);
|
|
55285
|
+
f.length && f.forEach((m, g) => {
|
|
55286
|
+
let C = { role: "tool", content: typeof m.content == "string" ? m.content : JSON.stringify(m.content), tool_call_id: m.tool_use_id, cache_control: m.cache_control };
|
|
55287
|
+
t.push(C);
|
|
55286
55288
|
});
|
|
55287
|
-
let
|
|
55288
|
-
|
|
55289
|
+
let a = r.content.filter((m) => m.type === "text" && m.text);
|
|
55290
|
+
a.length && t.push({ role: "user", content: a });
|
|
55289
55291
|
} else if (r.role === "assistant") {
|
|
55290
|
-
let
|
|
55291
|
-
|
|
55292
|
-
|
|
55293
|
-
|
|
55292
|
+
let f = { role: "assistant", content: null }, a = r.content.filter((g) => g.type === "text" && g.text);
|
|
55293
|
+
a.length && (f.content = a.map((g) => g.text).join(`
|
|
55294
|
+
`));
|
|
55295
|
+
let m = r.content.filter((g) => g.type === "tool_use" && g.id);
|
|
55296
|
+
m.length && (f.tool_calls = m.map((g) => ({ id: g.id, type: "function", function: { name: g.name, arguments: JSON.stringify(g.input || {}) } }))), t.push(f);
|
|
55294
55297
|
}
|
|
55295
55298
|
return;
|
|
55296
55299
|
}
|
|
@@ -55312,226 +55315,234 @@ var F = class {
|
|
|
55312
55315
|
}
|
|
55313
55316
|
async convertOpenAIStreamToAnthropic(e) {
|
|
55314
55317
|
return new ReadableStream({ async start(n) {
|
|
55315
|
-
let o = new TextEncoder(), r = `msg_${Date.now()}`,
|
|
55316
|
-
if (!
|
|
55317
|
-
n.enqueue(
|
|
55318
|
-
let
|
|
55319
|
-
|
|
55320
|
-
} catch (
|
|
55321
|
-
if (
|
|
55322
|
-
else throw
|
|
55323
|
-
}
|
|
55324
|
-
},
|
|
55325
|
-
if (!
|
|
55326
|
-
n.close(),
|
|
55327
|
-
} catch (
|
|
55328
|
-
if (
|
|
55329
|
-
else throw
|
|
55330
|
-
}
|
|
55331
|
-
},
|
|
55318
|
+
let o = new TextEncoder(), r = `msg_${Date.now()}`, d = "unknown", l = false, f = false, a = false, m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), C = 0, p = 0, u = 0, i = false, y = false, h = 0, c = (b) => {
|
|
55319
|
+
if (!i) try {
|
|
55320
|
+
n.enqueue(b);
|
|
55321
|
+
let _ = new TextDecoder().decode(b);
|
|
55322
|
+
v("send data:", _.trim());
|
|
55323
|
+
} catch (_) {
|
|
55324
|
+
if (_ instanceof TypeError && _.message.includes("Controller is already closed")) i = true;
|
|
55325
|
+
else throw v(`send data error: ${_.message}`), _;
|
|
55326
|
+
}
|
|
55327
|
+
}, k = () => {
|
|
55328
|
+
if (!i) try {
|
|
55329
|
+
n.close(), i = true;
|
|
55330
|
+
} catch (b) {
|
|
55331
|
+
if (b instanceof TypeError && b.message.includes("Controller is already closed")) i = true;
|
|
55332
|
+
else throw b;
|
|
55333
|
+
}
|
|
55334
|
+
}, P = null;
|
|
55332
55335
|
try {
|
|
55333
|
-
|
|
55334
|
-
let
|
|
55335
|
-
for (; !
|
|
55336
|
-
let { done:
|
|
55337
|
-
if (
|
|
55338
|
-
|
|
55339
|
-
let
|
|
55336
|
+
P = e.getReader();
|
|
55337
|
+
let b = new TextDecoder(), _ = "";
|
|
55338
|
+
for (; !i; ) {
|
|
55339
|
+
let { done: ue, value: fe } = await P.read();
|
|
55340
|
+
if (ue) break;
|
|
55341
|
+
_ += b.decode(fe, { stream: true });
|
|
55342
|
+
let ne = _.split(`
|
|
55340
55343
|
`);
|
|
55341
|
-
|
|
55342
|
-
for (let
|
|
55343
|
-
if (
|
|
55344
|
-
if (!
|
|
55345
|
-
let
|
|
55346
|
-
if (
|
|
55347
|
-
let
|
|
55348
|
-
if (
|
|
55349
|
-
|
|
55350
|
-
|
|
55351
|
-
|
|
55352
|
-
data: ${JSON.stringify(k)}
|
|
55344
|
+
_ = ne.pop() || "";
|
|
55345
|
+
for (let oe of ne) {
|
|
55346
|
+
if (i || a) break;
|
|
55347
|
+
if (!oe.startsWith("data: ")) continue;
|
|
55348
|
+
let K = oe.slice(6);
|
|
55349
|
+
if (K !== "[DONE]") try {
|
|
55350
|
+
let O = JSON.parse(K);
|
|
55351
|
+
if (C++, v("Original Response:", JSON.stringify(O, null, 2)), O.error) {
|
|
55352
|
+
let x = { type: "error", message: { type: "api_error", message: JSON.stringify(O.error) } };
|
|
55353
|
+
c(o.encode(`event: error
|
|
55354
|
+
data: ${JSON.stringify(x)}
|
|
55353
55355
|
|
|
55354
55356
|
`));
|
|
55357
|
+
continue;
|
|
55355
55358
|
}
|
|
55356
|
-
|
|
55357
|
-
|
|
55358
|
-
|
|
55359
|
-
|
|
55360
|
-
|
|
55361
|
-
|
|
55362
|
-
|
|
55363
|
-
|
|
55364
|
-
|
|
55359
|
+
if (d = O.model || d, !l && !i && !a) {
|
|
55360
|
+
l = true;
|
|
55361
|
+
let x = { type: "message_start", message: { id: r, type: "message", role: "assistant", content: [], model: d, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
|
|
55362
|
+
c(o.encode(`event: message_start
|
|
55363
|
+
data: ${JSON.stringify(x)}
|
|
55364
|
+
|
|
55365
|
+
`));
|
|
55366
|
+
}
|
|
55367
|
+
let w = O.choices?.[0];
|
|
55368
|
+
if (!w) continue;
|
|
55369
|
+
if (w?.delta?.thinking && !i && !a) {
|
|
55370
|
+
if (!y) {
|
|
55371
|
+
let x = { type: "content_block_start", index: h, content_block: { type: "thinking", thinking: "" } };
|
|
55372
|
+
c(o.encode(`event: content_block_start
|
|
55373
|
+
data: ${JSON.stringify(x)}
|
|
55374
|
+
|
|
55375
|
+
`)), y = true;
|
|
55365
55376
|
}
|
|
55366
|
-
if (
|
|
55367
|
-
let
|
|
55368
|
-
|
|
55369
|
-
data: ${JSON.stringify(
|
|
55377
|
+
if (w.delta.thinking.signature) {
|
|
55378
|
+
let x = { type: "content_block_delta", index: h, delta: { type: "signature_delta", signature: w.delta.thinking.signature } };
|
|
55379
|
+
c(o.encode(`event: content_block_delta
|
|
55380
|
+
data: ${JSON.stringify(x)}
|
|
55370
55381
|
|
|
55371
55382
|
`));
|
|
55372
|
-
let
|
|
55373
|
-
|
|
55374
|
-
data: ${JSON.stringify(
|
|
55383
|
+
let T = { type: "content_block_stop", index: h };
|
|
55384
|
+
c(o.encode(`event: content_block_stop
|
|
55385
|
+
data: ${JSON.stringify(T)}
|
|
55375
55386
|
|
|
55376
|
-
`)),
|
|
55377
|
-
} else if (
|
|
55378
|
-
let
|
|
55379
|
-
|
|
55380
|
-
data: ${JSON.stringify(
|
|
55387
|
+
`)), h++;
|
|
55388
|
+
} else if (w.delta.thinking.content) {
|
|
55389
|
+
let x = { type: "content_block_delta", index: h, delta: { type: "thinking_delta", thinking: w.delta.thinking.content || "" } };
|
|
55390
|
+
c(o.encode(`event: content_block_delta
|
|
55391
|
+
data: ${JSON.stringify(x)}
|
|
55381
55392
|
|
|
55382
55393
|
`));
|
|
55383
55394
|
}
|
|
55384
55395
|
}
|
|
55385
|
-
if (
|
|
55386
|
-
if (
|
|
55387
|
-
|
|
55388
|
-
let
|
|
55389
|
-
|
|
55390
|
-
data: ${JSON.stringify(
|
|
55396
|
+
if (w?.delta?.content && !i && !a) {
|
|
55397
|
+
if (p++, !f && !a) {
|
|
55398
|
+
f = true;
|
|
55399
|
+
let x = { type: "content_block_start", index: h, content_block: { type: "text", text: "" } };
|
|
55400
|
+
c(o.encode(`event: content_block_start
|
|
55401
|
+
data: ${JSON.stringify(x)}
|
|
55391
55402
|
|
|
55392
55403
|
`));
|
|
55393
55404
|
}
|
|
55394
|
-
if (!
|
|
55395
|
-
let
|
|
55396
|
-
|
|
55397
|
-
data: ${JSON.stringify(
|
|
55405
|
+
if (!i && !a) {
|
|
55406
|
+
let x = { type: "content_block_delta", index: h, delta: { type: "text_delta", text: w.delta.content } };
|
|
55407
|
+
c(o.encode(`event: content_block_delta
|
|
55408
|
+
data: ${JSON.stringify(x)}
|
|
55398
55409
|
|
|
55399
55410
|
`));
|
|
55400
55411
|
}
|
|
55401
55412
|
}
|
|
55402
|
-
if (
|
|
55403
|
-
|
|
55404
|
-
let
|
|
55405
|
-
for (let
|
|
55406
|
-
if (
|
|
55407
|
-
let
|
|
55408
|
-
if (
|
|
55409
|
-
if (
|
|
55410
|
-
let
|
|
55411
|
-
if (
|
|
55412
|
-
|
|
55413
|
-
let
|
|
55414
|
-
|
|
55415
|
-
data: ${JSON.stringify(
|
|
55416
|
-
|
|
55417
|
-
`)),
|
|
55413
|
+
if (w?.delta?.tool_calls && !i && !a) {
|
|
55414
|
+
u++;
|
|
55415
|
+
let x = /* @__PURE__ */ new Set();
|
|
55416
|
+
for (let T of w.delta.tool_calls) {
|
|
55417
|
+
if (i) break;
|
|
55418
|
+
let S = T.index ?? 0;
|
|
55419
|
+
if (x.has(S)) continue;
|
|
55420
|
+
if (x.add(S), !g.has(S)) {
|
|
55421
|
+
let E = f ? g.size + 1 : g.size;
|
|
55422
|
+
if (E !== 0) {
|
|
55423
|
+
v("content_block_stop2");
|
|
55424
|
+
let pe = { type: "content_block_stop", index: h };
|
|
55425
|
+
c(o.encode(`event: content_block_stop
|
|
55426
|
+
data: ${JSON.stringify(pe)}
|
|
55427
|
+
|
|
55428
|
+
`)), h++;
|
|
55418
55429
|
}
|
|
55419
|
-
|
|
55420
|
-
let
|
|
55421
|
-
|
|
55422
|
-
data: ${JSON.stringify(
|
|
55430
|
+
g.set(S, E);
|
|
55431
|
+
let H = T.id || `call_${Date.now()}_${S}`, A = T.function?.name || `tool_${S}`, L = { type: "content_block_start", index: h, content_block: { type: "tool_use", id: H, name: A, input: {} } };
|
|
55432
|
+
c(o.encode(`event: content_block_start
|
|
55433
|
+
data: ${JSON.stringify(L)}
|
|
55423
55434
|
|
|
55424
55435
|
`));
|
|
55425
|
-
let
|
|
55426
|
-
|
|
55427
|
-
} else if (
|
|
55428
|
-
let
|
|
55429
|
-
|
|
55436
|
+
let M = { id: H, name: A, arguments: "", contentBlockIndex: E };
|
|
55437
|
+
m.set(S, M);
|
|
55438
|
+
} else if (T.id && T.function?.name) {
|
|
55439
|
+
let E = m.get(S);
|
|
55440
|
+
E.id.startsWith("call_") && E.name.startsWith("tool_") && (E.id = T.id, E.name = T.function.name);
|
|
55430
55441
|
}
|
|
55431
|
-
if (
|
|
55432
|
-
if (
|
|
55433
|
-
let
|
|
55434
|
-
if (
|
|
55435
|
-
|
|
55442
|
+
if (T.function?.arguments && !i && !a) {
|
|
55443
|
+
if (g.get(S) === void 0) continue;
|
|
55444
|
+
let H = m.get(S);
|
|
55445
|
+
if (H) {
|
|
55446
|
+
H.arguments += T.function.arguments;
|
|
55436
55447
|
try {
|
|
55437
|
-
let
|
|
55438
|
-
if (
|
|
55439
|
-
|
|
55440
|
-
} catch (
|
|
55441
|
-
|
|
55448
|
+
let A = null, L = H.arguments.trim();
|
|
55449
|
+
if (L.startsWith("{") && L.endsWith("}")) try {
|
|
55450
|
+
A = JSON.parse(L);
|
|
55451
|
+
} catch (M) {
|
|
55452
|
+
v("Tool call index:", S, "error", M.message);
|
|
55442
55453
|
}
|
|
55443
|
-
} catch (
|
|
55444
|
-
|
|
55454
|
+
} catch (A) {
|
|
55455
|
+
v("Tool call index:", S, "error", A.message);
|
|
55445
55456
|
}
|
|
55446
55457
|
}
|
|
55447
55458
|
try {
|
|
55448
|
-
let
|
|
55449
|
-
|
|
55450
|
-
data: ${JSON.stringify(
|
|
55459
|
+
let A = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: T.function.arguments } };
|
|
55460
|
+
c(o.encode(`event: content_block_delta
|
|
55461
|
+
data: ${JSON.stringify(A)}
|
|
55451
55462
|
|
|
55452
55463
|
`));
|
|
55453
55464
|
} catch {
|
|
55454
55465
|
try {
|
|
55455
|
-
let
|
|
55456
|
-
|
|
55457
|
-
data: ${JSON.stringify(
|
|
55466
|
+
let L = T.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), M = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: L } };
|
|
55467
|
+
c(o.encode(`event: content_block_delta
|
|
55468
|
+
data: ${JSON.stringify(M)}
|
|
55458
55469
|
|
|
55459
55470
|
`));
|
|
55460
|
-
} catch (
|
|
55461
|
-
console.error(
|
|
55471
|
+
} catch (L) {
|
|
55472
|
+
console.error(L);
|
|
55462
55473
|
}
|
|
55463
55474
|
}
|
|
55464
55475
|
}
|
|
55465
55476
|
}
|
|
55466
55477
|
}
|
|
55467
|
-
if (
|
|
55468
|
-
if (
|
|
55469
|
-
|
|
55470
|
-
let
|
|
55471
|
-
|
|
55472
|
-
data: ${JSON.stringify(
|
|
55478
|
+
if (w?.finish_reason && !i && !a) {
|
|
55479
|
+
if (a = true, p === 0 && u === 0 && console.error("Warning: No content in the stream response!"), (f || u > 0) && !i) {
|
|
55480
|
+
v("content_block_stop hasTextContentStarted");
|
|
55481
|
+
let x = { type: "content_block_stop", index: h };
|
|
55482
|
+
c(o.encode(`event: content_block_stop
|
|
55483
|
+
data: ${JSON.stringify(x)}
|
|
55473
55484
|
|
|
55474
55485
|
`));
|
|
55475
55486
|
}
|
|
55476
|
-
if (!
|
|
55477
|
-
let
|
|
55478
|
-
|
|
55479
|
-
data: ${JSON.stringify(
|
|
55487
|
+
if (!i) {
|
|
55488
|
+
let S = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[w.finish_reason] || "end_turn", stop_sequence: null }, usage: { input_tokens: O.usage?.prompt_tokens || 0, output_tokens: O.usage?.completion_tokens || 0 } };
|
|
55489
|
+
c(o.encode(`event: message_delta
|
|
55490
|
+
data: ${JSON.stringify(S)}
|
|
55480
55491
|
|
|
55481
55492
|
`));
|
|
55482
55493
|
}
|
|
55483
|
-
if (!
|
|
55484
|
-
let
|
|
55485
|
-
|
|
55486
|
-
data: ${JSON.stringify(
|
|
55494
|
+
if (!i) {
|
|
55495
|
+
let x = { type: "message_stop" };
|
|
55496
|
+
c(o.encode(`event: message_stop
|
|
55497
|
+
data: ${JSON.stringify(x)}
|
|
55487
55498
|
|
|
55488
55499
|
`));
|
|
55489
55500
|
}
|
|
55490
55501
|
break;
|
|
55491
55502
|
}
|
|
55492
|
-
} catch (
|
|
55493
|
-
|
|
55503
|
+
} catch (O) {
|
|
55504
|
+
v(`parseError: ${O.name} message: ${O.message} stack: ${O.stack} data: ${K}`);
|
|
55494
55505
|
}
|
|
55495
55506
|
}
|
|
55496
55507
|
}
|
|
55497
|
-
|
|
55498
|
-
} catch (
|
|
55499
|
-
if (!
|
|
55500
|
-
n.error(
|
|
55501
|
-
} catch (
|
|
55502
|
-
console.error(
|
|
55508
|
+
k();
|
|
55509
|
+
} catch (b) {
|
|
55510
|
+
if (!i) try {
|
|
55511
|
+
n.error(b);
|
|
55512
|
+
} catch (_) {
|
|
55513
|
+
console.error(_);
|
|
55503
55514
|
}
|
|
55504
55515
|
} finally {
|
|
55505
|
-
if (
|
|
55506
|
-
|
|
55507
|
-
} catch (
|
|
55508
|
-
console.error(
|
|
55516
|
+
if (P) try {
|
|
55517
|
+
P.releaseLock();
|
|
55518
|
+
} catch (b) {
|
|
55519
|
+
console.error(b);
|
|
55509
55520
|
}
|
|
55510
55521
|
}
|
|
55511
55522
|
}, cancel(n) {
|
|
55512
|
-
|
|
55523
|
+
v("cancle stream:", n);
|
|
55513
55524
|
} });
|
|
55514
55525
|
}
|
|
55515
55526
|
convertOpenAIResponseToAnthropic(e) {
|
|
55516
|
-
|
|
55527
|
+
v("Original OpenAI response:", JSON.stringify(e, null, 2));
|
|
55517
55528
|
let t = e.choices[0];
|
|
55518
55529
|
if (!t) throw new Error("No choices found in OpenAI response");
|
|
55519
55530
|
let n = [];
|
|
55520
|
-
t.message.content && n.push({ type: "text", text: t.message.content }), t.message.tool_calls && t.message.tool_calls.length > 0 && t.message.tool_calls.forEach((r,
|
|
55521
|
-
let
|
|
55531
|
+
t.message.content && n.push({ type: "text", text: t.message.content }), t.message.tool_calls && t.message.tool_calls.length > 0 && t.message.tool_calls.forEach((r, d) => {
|
|
55532
|
+
let l = {};
|
|
55522
55533
|
try {
|
|
55523
|
-
let
|
|
55524
|
-
typeof
|
|
55534
|
+
let f = r.function.arguments || "{}";
|
|
55535
|
+
typeof f == "object" ? l = f : typeof f == "string" && (l = JSON.parse(f));
|
|
55525
55536
|
} catch {
|
|
55526
|
-
|
|
55537
|
+
l = { text: r.function.arguments || "" };
|
|
55527
55538
|
}
|
|
55528
|
-
n.push({ type: "tool_use", id: r.id, name: r.function.name, input:
|
|
55539
|
+
n.push({ type: "tool_use", id: r.id, name: r.function.name, input: l });
|
|
55529
55540
|
});
|
|
55530
55541
|
let o = { id: e.id, type: "message", role: "assistant", model: e.model, content: n, stop_reason: t.finish_reason === "stop" ? "end_turn" : t.finish_reason === "length" ? "max_tokens" : t.finish_reason === "tool_calls" ? "tool_use" : t.finish_reason === "content_filter" ? "stop_sequence" : "end_turn", stop_sequence: null, usage: { input_tokens: e.usage?.prompt_tokens || 0, output_tokens: e.usage?.completion_tokens || 0 } };
|
|
55531
|
-
return
|
|
55542
|
+
return v("Conversion complete, final Anthropic response:", JSON.stringify(o, null, 2)), o;
|
|
55532
55543
|
}
|
|
55533
55544
|
};
|
|
55534
|
-
var
|
|
55545
|
+
var U = class {
|
|
55535
55546
|
name = "gemini";
|
|
55536
55547
|
endPoint = "/v1beta/models/:modelAndAction";
|
|
55537
55548
|
transformRequestIn(e, t) {
|
|
@@ -55539,22 +55550,22 @@ var I = class {
|
|
|
55539
55550
|
let o;
|
|
55540
55551
|
n.role === "assistant" ? o = "model" : (["user", "system", "tool"].includes(n.role), o = "user");
|
|
55541
55552
|
let r = [];
|
|
55542
|
-
return typeof n.content == "string" ? r.push({ text: n.content }) : Array.isArray(n.content) && r.push(...n.content.map((
|
|
55543
|
-
if (
|
|
55544
|
-
})), Array.isArray(n.tool_calls) && r.push(...n.tool_calls.map((
|
|
55553
|
+
return typeof n.content == "string" ? r.push({ text: n.content }) : Array.isArray(n.content) && r.push(...n.content.map((d) => {
|
|
55554
|
+
if (d.type === "text") return { text: d.text || "" };
|
|
55555
|
+
})), Array.isArray(n.tool_calls) && r.push(...n.tool_calls.map((d) => ({ functionCall: { id: d.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: d.function.name, args: JSON.parse(d.function.arguments || "{}") } }))), { role: o, parts: r };
|
|
55545
55556
|
}), tools: [{ functionDeclarations: e.tools?.map((n) => (delete n.function.parameters?.$schema, delete n.function.parameters?.additionalProperties, n.function.parameters?.properties && Object.keys(n.function.parameters.properties).forEach((o) => {
|
|
55546
55557
|
delete n.function.parameters.properties[o].$schema, delete n.function.parameters.properties[o].additionalProperties, n.function.parameters.properties[o].items && typeof n.function.parameters.properties[o].items == "object" && (delete n.function.parameters.properties[o].items.$schema, delete n.function.parameters.properties[o].items.additionalProperties), n.function.parameters.properties[o].type === "string" && (["enum", "date-time"].includes(n.function.parameters.properties[o].format) || delete n.function.parameters.properties[o].format);
|
|
55547
55558
|
}), { name: n.function.name, description: n.function.description, parameters: n.function.parameters })) || [] }] }, config: { url: new URL(`./${e.model}:${e.stream ? "streamGenerateContent?alt=sse" : "generateContent"}`, t.baseUrl), headers: { "x-goog-api-key": t.apiKey, Authorization: void 0 } } };
|
|
55548
55559
|
}
|
|
55549
55560
|
transformRequestOut(e) {
|
|
55550
|
-
let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens,
|
|
55551
|
-
return Array.isArray(t) && t.forEach((
|
|
55552
|
-
typeof
|
|
55553
|
-
}), Array.isArray(n) && (
|
|
55554
|
-
Array.isArray(
|
|
55555
|
-
|
|
55561
|
+
let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens, d = e.temperature, l = e.stream, f = e.tool_choice, a = { messages: [], model: o, max_tokens: r, temperature: d, stream: l, tool_choice: f };
|
|
55562
|
+
return Array.isArray(t) && t.forEach((m) => {
|
|
55563
|
+
typeof m == "string" ? a.messages.push({ role: "user", content: m }) : typeof m.text == "string" ? a.messages.push({ role: "user", content: m.text || null }) : m.role === "user" ? a.messages.push({ role: "user", content: m?.parts?.map((g) => ({ type: "text", text: g.text || "" })) || [] }) : m.role === "model" && a.messages.push({ role: "assistant", content: m?.parts?.map((g) => ({ type: "text", text: g.text || "" })) || [] });
|
|
55564
|
+
}), Array.isArray(n) && (a.tools = [], n.forEach((m) => {
|
|
55565
|
+
Array.isArray(m.functionDeclarations) && m.functionDeclarations.forEach((g) => {
|
|
55566
|
+
a.tools.push({ type: "function", function: { name: g.name, description: g.description, parameters: g.parameters } });
|
|
55556
55567
|
});
|
|
55557
|
-
})),
|
|
55568
|
+
})), a;
|
|
55558
55569
|
}
|
|
55559
55570
|
async transformResponseOut(e) {
|
|
55560
55571
|
if (e.headers.get("Content-Type")?.includes("application/json")) {
|
|
@@ -55564,23 +55575,23 @@ var I = class {
|
|
|
55564
55575
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55565
55576
|
if (!e.body) return e;
|
|
55566
55577
|
let t = new TextDecoder(), n = new TextEncoder(), o = new ReadableStream({ async start(r) {
|
|
55567
|
-
let
|
|
55578
|
+
let d = e.body.getReader();
|
|
55568
55579
|
try {
|
|
55569
55580
|
for (; ; ) {
|
|
55570
|
-
let { done:
|
|
55571
|
-
if (
|
|
55572
|
-
let
|
|
55573
|
-
if (
|
|
55581
|
+
let { done: l, value: f } = await d.read();
|
|
55582
|
+
if (l) break;
|
|
55583
|
+
let a = t.decode(f, { stream: true });
|
|
55584
|
+
if (a.startsWith("data: ")) a = a.slice(6).trim();
|
|
55574
55585
|
else break;
|
|
55575
|
-
|
|
55576
|
-
let
|
|
55577
|
-
`), tool_calls:
|
|
55578
|
-
|
|
55586
|
+
v("gemini chunk:", a), a = JSON.parse(a);
|
|
55587
|
+
let m = a.candidates[0].content.parts.filter((C) => C.functionCall).map((C) => ({ id: C.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: C.functionCall?.name, arguments: JSON.stringify(C.functionCall?.args || {}) } })), g = { choices: [{ delta: { role: "assistant", content: a.candidates[0].content.parts.filter((C) => C.text).map((C) => C.text).join(`
|
|
55588
|
+
`), tool_calls: m.length > 0 ? m : void 0 }, finish_reason: a.candidates[0].finishReason?.toLowerCase() || null, index: a.candidates[0].index || m.length > 0 ? 1 : 0, logprobs: null }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), id: a.responseId || "", model: a.modelVersion || "", object: "chat.completion.chunk", system_fingerprint: "fp_a49d71b8a1" };
|
|
55589
|
+
v("gemini response:", JSON.stringify(g, null, 2)), r.enqueue(n.encode(`data: ${JSON.stringify(g)}
|
|
55579
55590
|
|
|
55580
55591
|
`));
|
|
55581
55592
|
}
|
|
55582
|
-
} catch (
|
|
55583
|
-
r.error(
|
|
55593
|
+
} catch (l) {
|
|
55594
|
+
r.error(l);
|
|
55584
55595
|
} finally {
|
|
55585
55596
|
r.close();
|
|
55586
55597
|
}
|
|
@@ -55601,66 +55612,66 @@ var j = class {
|
|
|
55601
55612
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55602
55613
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55603
55614
|
if (!e.body) return e;
|
|
55604
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false,
|
|
55605
|
-
let
|
|
55615
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false, d = new ReadableStream({ async start(l) {
|
|
55616
|
+
let f = e.body.getReader();
|
|
55606
55617
|
try {
|
|
55607
55618
|
for (; ; ) {
|
|
55608
|
-
let { done:
|
|
55609
|
-
if (
|
|
55610
|
-
let
|
|
55619
|
+
let { done: a, value: m } = await f.read();
|
|
55620
|
+
if (a) break;
|
|
55621
|
+
let C = t.decode(m, { stream: true }).split(`
|
|
55611
55622
|
`);
|
|
55612
|
-
for (let
|
|
55613
|
-
let
|
|
55614
|
-
if (
|
|
55615
|
-
o +=
|
|
55616
|
-
let
|
|
55617
|
-
delete
|
|
55618
|
-
let
|
|
55623
|
+
for (let p of C) if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") try {
|
|
55624
|
+
let u = JSON.parse(p.slice(6));
|
|
55625
|
+
if (u.choices?.[0]?.delta?.reasoning_content) {
|
|
55626
|
+
o += u.choices[0].delta.reasoning_content;
|
|
55627
|
+
let i = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, thinking: { content: u.choices[0].delta.reasoning_content } } }] };
|
|
55628
|
+
delete i.choices[0].delta.reasoning_content;
|
|
55629
|
+
let y = `data: ${JSON.stringify(i)}
|
|
55619
55630
|
|
|
55620
55631
|
`;
|
|
55621
|
-
|
|
55632
|
+
l.enqueue(n.encode(y));
|
|
55622
55633
|
continue;
|
|
55623
55634
|
}
|
|
55624
|
-
if (
|
|
55635
|
+
if (u.choices?.[0]?.delta?.content && o && !r) {
|
|
55625
55636
|
r = true;
|
|
55626
|
-
let
|
|
55627
|
-
delete
|
|
55628
|
-
let
|
|
55637
|
+
let i = Date.now().toString(), y = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, content: null, thinking: { content: o, signature: i } } }] };
|
|
55638
|
+
delete y.choices[0].delta.reasoning_content;
|
|
55639
|
+
let h = `data: ${JSON.stringify(y)}
|
|
55629
55640
|
|
|
55630
55641
|
`;
|
|
55631
|
-
|
|
55642
|
+
l.enqueue(n.encode(h));
|
|
55632
55643
|
}
|
|
55633
|
-
if (
|
|
55634
|
-
r &&
|
|
55635
|
-
let
|
|
55644
|
+
if (u.choices[0]?.delta?.reasoning_content && delete u.choices[0].delta.reasoning_content, u.choices?.[0]?.delta && Object.keys(u.choices[0].delta).length > 0) {
|
|
55645
|
+
r && u.choices[0].index++;
|
|
55646
|
+
let i = `data: ${JSON.stringify(u)}
|
|
55636
55647
|
|
|
55637
55648
|
`;
|
|
55638
|
-
|
|
55649
|
+
l.enqueue(n.encode(i));
|
|
55639
55650
|
}
|
|
55640
55651
|
} catch {
|
|
55641
|
-
|
|
55652
|
+
l.enqueue(n.encode(p + `
|
|
55642
55653
|
`));
|
|
55643
55654
|
}
|
|
55644
|
-
else
|
|
55655
|
+
else l.enqueue(n.encode(p + `
|
|
55645
55656
|
`));
|
|
55646
55657
|
}
|
|
55647
|
-
} catch (
|
|
55648
|
-
|
|
55658
|
+
} catch (a) {
|
|
55659
|
+
l.error(a);
|
|
55649
55660
|
} finally {
|
|
55650
55661
|
try {
|
|
55651
|
-
|
|
55652
|
-
} catch (
|
|
55653
|
-
console.error("Error releasing reader lock:",
|
|
55662
|
+
f.releaseLock();
|
|
55663
|
+
} catch (a) {
|
|
55664
|
+
console.error("Error releasing reader lock:", a);
|
|
55654
55665
|
}
|
|
55655
|
-
|
|
55666
|
+
l.close();
|
|
55656
55667
|
}
|
|
55657
55668
|
} });
|
|
55658
|
-
return new Response(
|
|
55669
|
+
return new Response(d, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
55659
55670
|
}
|
|
55660
55671
|
return e;
|
|
55661
55672
|
}
|
|
55662
55673
|
};
|
|
55663
|
-
var
|
|
55674
|
+
var J = class {
|
|
55664
55675
|
name = "tooluse";
|
|
55665
55676
|
transformRequestIn(e) {
|
|
55666
55677
|
return e.messages.push({ role: "system", content: "<system-reminder>Tool mode is active. The user expects you to proactively execute the most suitable tool to help complete the task. \nBefore invoking a tool, you must carefully evaluate whether it matches the current task. If no available tool is appropriate for the task, you MUST call the `ExitTool` to exit tool mode \u2014 this is the only valid way to terminate tool mode.\nAlways prioritize completing the user's task effectively and efficiently by using tools whenever appropriate.</system-reminder>" }), e.tools?.length && (e.tool_choice = "required", e.tools.unshift({ type: "function", function: { name: "ExitTool", description: `Use this tool when you are in tool mode and have completed the task. This is the only valid way to exit tool mode.
|
|
@@ -55679,65 +55690,65 @@ Examples:
|
|
|
55679
55690
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55680
55691
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55681
55692
|
if (!e.body) return e;
|
|
55682
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "",
|
|
55683
|
-
let
|
|
55693
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "", d = new ReadableStream({ async start(l) {
|
|
55694
|
+
let f = e.body.getReader();
|
|
55684
55695
|
try {
|
|
55685
55696
|
for (; ; ) {
|
|
55686
|
-
let { done:
|
|
55687
|
-
if (
|
|
55688
|
-
let
|
|
55697
|
+
let { done: a, value: m } = await f.read();
|
|
55698
|
+
if (a) break;
|
|
55699
|
+
let C = t.decode(m, { stream: true }).split(`
|
|
55689
55700
|
`);
|
|
55690
|
-
for (let
|
|
55691
|
-
let
|
|
55692
|
-
if (
|
|
55693
|
-
let
|
|
55694
|
-
if (
|
|
55695
|
-
o =
|
|
55701
|
+
for (let p of C) if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") try {
|
|
55702
|
+
let u = JSON.parse(p.slice(6));
|
|
55703
|
+
if (u.choices[0]?.delta?.tool_calls?.length) {
|
|
55704
|
+
let i = u.choices[0].delta.tool_calls[0];
|
|
55705
|
+
if (i.function?.name === "ExitTool") {
|
|
55706
|
+
o = i.index;
|
|
55696
55707
|
continue;
|
|
55697
|
-
} else if (o > -1 &&
|
|
55698
|
-
r +=
|
|
55708
|
+
} else if (o > -1 && i.index === o && i.function.arguments) {
|
|
55709
|
+
r += i.function.arguments;
|
|
55699
55710
|
try {
|
|
55700
|
-
let
|
|
55701
|
-
|
|
55702
|
-
let
|
|
55711
|
+
let y = JSON.parse(r);
|
|
55712
|
+
u.choices = [{ delta: { role: "assistant", content: y.response || "" } }];
|
|
55713
|
+
let h = `data: ${JSON.stringify(u)}
|
|
55703
55714
|
|
|
55704
55715
|
`;
|
|
55705
|
-
|
|
55716
|
+
l.enqueue(n.encode(h));
|
|
55706
55717
|
} catch {
|
|
55707
55718
|
}
|
|
55708
55719
|
continue;
|
|
55709
55720
|
}
|
|
55710
55721
|
}
|
|
55711
|
-
if (
|
|
55712
|
-
let
|
|
55722
|
+
if (u.choices?.[0]?.delta && Object.keys(u.choices[0].delta).length > 0) {
|
|
55723
|
+
let i = `data: ${JSON.stringify(u)}
|
|
55713
55724
|
|
|
55714
55725
|
`;
|
|
55715
|
-
|
|
55726
|
+
l.enqueue(n.encode(i));
|
|
55716
55727
|
}
|
|
55717
55728
|
} catch {
|
|
55718
|
-
|
|
55729
|
+
l.enqueue(n.encode(p + `
|
|
55719
55730
|
`));
|
|
55720
55731
|
}
|
|
55721
|
-
else
|
|
55732
|
+
else l.enqueue(n.encode(p + `
|
|
55722
55733
|
`));
|
|
55723
55734
|
}
|
|
55724
|
-
} catch (
|
|
55725
|
-
|
|
55735
|
+
} catch (a) {
|
|
55736
|
+
l.error(a);
|
|
55726
55737
|
} finally {
|
|
55727
55738
|
try {
|
|
55728
|
-
|
|
55729
|
-
} catch (
|
|
55730
|
-
console.error("Error releasing reader lock:",
|
|
55739
|
+
f.releaseLock();
|
|
55740
|
+
} catch (a) {
|
|
55741
|
+
console.error("Error releasing reader lock:", a);
|
|
55731
55742
|
}
|
|
55732
|
-
|
|
55743
|
+
l.close();
|
|
55733
55744
|
}
|
|
55734
55745
|
} });
|
|
55735
|
-
return new Response(
|
|
55746
|
+
return new Response(d, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
55736
55747
|
}
|
|
55737
55748
|
return e;
|
|
55738
55749
|
}
|
|
55739
55750
|
};
|
|
55740
|
-
var
|
|
55751
|
+
var D = class {
|
|
55741
55752
|
name = "openrouter";
|
|
55742
55753
|
transformRequestIn(e) {
|
|
55743
55754
|
return e.model.includes("claude") || e.messages.forEach((t) => {
|
|
@@ -55752,64 +55763,105 @@ var J = class {
|
|
|
55752
55763
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55753
55764
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55754
55765
|
if (!e.body) return e;
|
|
55755
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "",
|
|
55756
|
-
let
|
|
55757
|
-
|
|
55758
|
-
for (; ; ) {
|
|
55759
|
-
let { done: c, value: h } = await i.read();
|
|
55760
|
-
if (c) break;
|
|
55761
|
-
let m = t.decode(h, { stream: true }).split(`
|
|
55766
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", d = false, l = "", f = new ReadableStream({ async start(a) {
|
|
55767
|
+
let m = e.body.getReader(), g = (p, u, i) => {
|
|
55768
|
+
let y = p.split(`
|
|
55762
55769
|
`);
|
|
55763
|
-
|
|
55764
|
-
|
|
55765
|
-
|
|
55766
|
-
|
|
55767
|
-
|
|
55768
|
-
|
|
55769
|
-
|
|
55770
|
+
for (let h of y) h.trim() && u.enqueue(i.encode(h + `
|
|
55771
|
+
`));
|
|
55772
|
+
}, C = (p, u) => {
|
|
55773
|
+
let { controller: i, encoder: y } = u;
|
|
55774
|
+
if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") {
|
|
55775
|
+
let h = p.slice(6);
|
|
55776
|
+
try {
|
|
55777
|
+
let c = JSON.parse(h);
|
|
55778
|
+
if (c.choices?.[0]?.delta?.content && !u.hasTextContent() && u.setHasTextContent(true), c.choices?.[0]?.delta?.reasoning) {
|
|
55779
|
+
u.appendReasoningContent(c.choices[0].delta.reasoning);
|
|
55780
|
+
let P = { ...c, choices: [{ ...c.choices?.[0], delta: { ...c.choices[0].delta, thinking: { content: c.choices[0].delta.reasoning } } }] };
|
|
55781
|
+
P.choices?.[0]?.delta && delete P.choices[0].delta.reasoning;
|
|
55782
|
+
let b = `data: ${JSON.stringify(P)}
|
|
55770
55783
|
|
|
55771
55784
|
`;
|
|
55772
|
-
|
|
55773
|
-
|
|
55785
|
+
i.enqueue(y.encode(b));
|
|
55786
|
+
return;
|
|
55774
55787
|
}
|
|
55775
|
-
if (
|
|
55776
|
-
|
|
55777
|
-
let
|
|
55778
|
-
delete
|
|
55779
|
-
let
|
|
55788
|
+
if (c.choices?.[0]?.delta?.content && u.reasoningContent() && !u.isReasoningComplete()) {
|
|
55789
|
+
u.setReasoningComplete(true);
|
|
55790
|
+
let P = Date.now().toString(), b = { ...c, choices: [{ ...c.choices?.[0], delta: { ...c.choices[0].delta, content: null, thinking: { content: u.reasoningContent(), signature: P } } }] };
|
|
55791
|
+
b.choices?.[0]?.delta && delete b.choices[0].delta.reasoning;
|
|
55792
|
+
let _ = `data: ${JSON.stringify(b)}
|
|
55780
55793
|
|
|
55781
55794
|
`;
|
|
55782
|
-
|
|
55795
|
+
i.enqueue(y.encode(_));
|
|
55783
55796
|
}
|
|
55784
|
-
|
|
55785
|
-
let
|
|
55797
|
+
c.choices?.[0]?.delta?.reasoning && delete c.choices[0].delta.reasoning, c.choices?.[0]?.delta?.tool_calls?.length && u.hasTextContent() && (typeof c.choices[0].index == "number" ? c.choices[0].index += 1 : c.choices[0].index = 1);
|
|
55798
|
+
let k = `data: ${JSON.stringify(c)}
|
|
55786
55799
|
|
|
55787
55800
|
`;
|
|
55788
|
-
|
|
55801
|
+
i.enqueue(y.encode(k));
|
|
55789
55802
|
} catch {
|
|
55790
|
-
|
|
55803
|
+
i.enqueue(y.encode(p + `
|
|
55791
55804
|
`));
|
|
55792
55805
|
}
|
|
55793
|
-
|
|
55806
|
+
} else i.enqueue(y.encode(p + `
|
|
55794
55807
|
`));
|
|
55808
|
+
};
|
|
55809
|
+
try {
|
|
55810
|
+
for (; ; ) {
|
|
55811
|
+
let { done: p, value: u } = await m.read();
|
|
55812
|
+
if (p) {
|
|
55813
|
+
l.trim() && g(l, a, n);
|
|
55814
|
+
break;
|
|
55815
|
+
}
|
|
55816
|
+
if (!u || u.length === 0) continue;
|
|
55817
|
+
let i;
|
|
55818
|
+
try {
|
|
55819
|
+
i = t.decode(u, { stream: true });
|
|
55820
|
+
} catch (h) {
|
|
55821
|
+
console.warn("Failed to decode chunk", h);
|
|
55822
|
+
continue;
|
|
55823
|
+
}
|
|
55824
|
+
if (i.length === 0) continue;
|
|
55825
|
+
if (l += i, l.length > 1e6) {
|
|
55826
|
+
console.warn("Buffer size exceeds limit, processing partial data");
|
|
55827
|
+
let h = l.split(`
|
|
55828
|
+
`);
|
|
55829
|
+
l = h.pop() || "";
|
|
55830
|
+
for (let c of h) if (c.trim()) try {
|
|
55831
|
+
C(c, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (k) => o = k, reasoningContent: () => r, appendReasoningContent: (k) => r += k, isReasoningComplete: () => d, setReasoningComplete: (k) => d = k });
|
|
55832
|
+
} catch (k) {
|
|
55833
|
+
console.error("Error processing line:", c, k), a.enqueue(n.encode(c + `
|
|
55834
|
+
`));
|
|
55835
|
+
}
|
|
55836
|
+
continue;
|
|
55837
|
+
}
|
|
55838
|
+
let y = l.split(`
|
|
55839
|
+
`);
|
|
55840
|
+
l = y.pop() || "";
|
|
55841
|
+
for (let h of y) if (h.trim()) try {
|
|
55842
|
+
C(h, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (c) => o = c, reasoningContent: () => r, appendReasoningContent: (c) => r += c, isReasoningComplete: () => d, setReasoningComplete: (c) => d = c });
|
|
55843
|
+
} catch (c) {
|
|
55844
|
+
console.error("Error processing line:", h, c), a.enqueue(n.encode(h + `
|
|
55845
|
+
`));
|
|
55846
|
+
}
|
|
55795
55847
|
}
|
|
55796
|
-
} catch (
|
|
55797
|
-
|
|
55848
|
+
} catch (p) {
|
|
55849
|
+
console.error("Stream error:", p), a.error(p);
|
|
55798
55850
|
} finally {
|
|
55799
55851
|
try {
|
|
55800
|
-
|
|
55801
|
-
} catch (
|
|
55802
|
-
console.error("Error releasing reader lock:",
|
|
55852
|
+
m.releaseLock();
|
|
55853
|
+
} catch (p) {
|
|
55854
|
+
console.error("Error releasing reader lock:", p);
|
|
55803
55855
|
}
|
|
55804
|
-
|
|
55856
|
+
a.close();
|
|
55805
55857
|
}
|
|
55806
55858
|
} });
|
|
55807
|
-
return new Response(
|
|
55859
|
+
return new Response(f, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
55808
55860
|
}
|
|
55809
55861
|
return e;
|
|
55810
55862
|
}
|
|
55811
55863
|
};
|
|
55812
|
-
var
|
|
55864
|
+
var B = class {
|
|
55813
55865
|
constructor(e) {
|
|
55814
55866
|
this.options = e;
|
|
55815
55867
|
this.max_tokens = this.options?.max_tokens;
|
|
@@ -55820,14 +55872,137 @@ var U = class {
|
|
|
55820
55872
|
return e.max_tokens && e.max_tokens > this.max_tokens && (e.max_tokens = this.max_tokens), e;
|
|
55821
55873
|
}
|
|
55822
55874
|
};
|
|
55823
|
-
var
|
|
55824
|
-
|
|
55875
|
+
var R = [];
|
|
55876
|
+
for (let s = 0; s < 256; ++s) R.push((s + 256).toString(16).slice(1));
|
|
55877
|
+
function le(s, e = 0) {
|
|
55878
|
+
return (R[s[e + 0]] + R[s[e + 1]] + R[s[e + 2]] + R[s[e + 3]] + "-" + R[s[e + 4]] + R[s[e + 5]] + "-" + R[s[e + 6]] + R[s[e + 7]] + "-" + R[s[e + 8]] + R[s[e + 9]] + "-" + R[s[e + 10]] + R[s[e + 11]] + R[s[e + 12]] + R[s[e + 13]] + R[s[e + 14]] + R[s[e + 15]]).toLowerCase();
|
|
55879
|
+
}
|
|
55880
|
+
var V = new Uint8Array(256);
|
|
55881
|
+
var z = V.length;
|
|
55882
|
+
function X() {
|
|
55883
|
+
return z > V.length - 16 && ((0, import_crypto.randomFillSync)(V), z = 0), V.slice(z, z += 16);
|
|
55884
|
+
}
|
|
55885
|
+
var Q = { randomUUID: import_crypto2.randomUUID };
|
|
55886
|
+
function xe(s, e, t) {
|
|
55887
|
+
if (Q.randomUUID && !e && !s) return Q.randomUUID();
|
|
55888
|
+
s = s || {};
|
|
55889
|
+
let n = s.random ?? s.rng?.() ?? X();
|
|
55890
|
+
if (n.length < 16) throw new Error("Random bytes length must be >= 16");
|
|
55891
|
+
if (n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, e) {
|
|
55892
|
+
if (t = t || 0, t < 0 || t + 16 > e.length) throw new RangeError(`UUID byte range ${t}:${t + 15} is out of buffer bounds`);
|
|
55893
|
+
for (let o = 0; o < 16; ++o) e[t + o] = n[o];
|
|
55894
|
+
return e;
|
|
55895
|
+
}
|
|
55896
|
+
return le(n);
|
|
55897
|
+
}
|
|
55898
|
+
var Z = xe;
|
|
55899
|
+
var W = class {
|
|
55900
|
+
name = "groq";
|
|
55901
|
+
async transformRequestIn(e) {
|
|
55902
|
+
return e.messages.forEach((t) => {
|
|
55903
|
+
Array.isArray(t.content) ? t.content.forEach((n) => {
|
|
55904
|
+
n.cache_control && delete n.cache_control;
|
|
55905
|
+
}) : t.cache_control && delete t.cache_control;
|
|
55906
|
+
}), Array.isArray(e.tools) && e.tools.forEach((t) => {
|
|
55907
|
+
delete t.function.parameters.$schema;
|
|
55908
|
+
}), e;
|
|
55909
|
+
}
|
|
55910
|
+
async transformResponseOut(e) {
|
|
55911
|
+
if (e.headers.get("Content-Type")?.includes("application/json")) {
|
|
55912
|
+
let t = await e.json();
|
|
55913
|
+
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55914
|
+
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55915
|
+
if (!e.body) return e;
|
|
55916
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", d = false, l = "", f = new ReadableStream({ async start(a) {
|
|
55917
|
+
let m = e.body.getReader(), g = (p, u, i) => {
|
|
55918
|
+
let y = p.split(`
|
|
55919
|
+
`);
|
|
55920
|
+
for (let h of y) h.trim() && u.enqueue(i.encode(h + `
|
|
55921
|
+
`));
|
|
55922
|
+
}, C = (p, u) => {
|
|
55923
|
+
let { controller: i, encoder: y } = u;
|
|
55924
|
+
if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") {
|
|
55925
|
+
let h = p.slice(6);
|
|
55926
|
+
try {
|
|
55927
|
+
let c = JSON.parse(h);
|
|
55928
|
+
if (c.error) throw new Error(JSON.stringify(c));
|
|
55929
|
+
c.choices?.[0]?.delta?.content && !u.hasTextContent() && u.setHasTextContent(true), c.choices?.[0]?.delta?.tool_calls?.length && c.choices?.[0]?.delta?.tool_calls.forEach((P) => {
|
|
55930
|
+
P.id = `call_${Z()}`;
|
|
55931
|
+
}), c.choices?.[0]?.delta?.tool_calls?.length && u.hasTextContent() && (typeof c.choices[0].index == "number" ? c.choices[0].index += 1 : c.choices[0].index = 1);
|
|
55932
|
+
let k = `data: ${JSON.stringify(c)}
|
|
55933
|
+
|
|
55934
|
+
`;
|
|
55935
|
+
i.enqueue(y.encode(k));
|
|
55936
|
+
} catch {
|
|
55937
|
+
i.enqueue(y.encode(p + `
|
|
55938
|
+
`));
|
|
55939
|
+
}
|
|
55940
|
+
} else i.enqueue(y.encode(p + `
|
|
55941
|
+
`));
|
|
55942
|
+
};
|
|
55943
|
+
try {
|
|
55944
|
+
for (; ; ) {
|
|
55945
|
+
let { done: p, value: u } = await m.read();
|
|
55946
|
+
if (p) {
|
|
55947
|
+
l.trim() && g(l, a, n);
|
|
55948
|
+
break;
|
|
55949
|
+
}
|
|
55950
|
+
if (!u || u.length === 0) continue;
|
|
55951
|
+
let i;
|
|
55952
|
+
try {
|
|
55953
|
+
i = t.decode(u, { stream: true });
|
|
55954
|
+
} catch (h) {
|
|
55955
|
+
console.warn("Failed to decode chunk", h);
|
|
55956
|
+
continue;
|
|
55957
|
+
}
|
|
55958
|
+
if (i.length === 0) continue;
|
|
55959
|
+
if (l += i, l.length > 1e6) {
|
|
55960
|
+
console.warn("Buffer size exceeds limit, processing partial data");
|
|
55961
|
+
let h = l.split(`
|
|
55962
|
+
`);
|
|
55963
|
+
l = h.pop() || "";
|
|
55964
|
+
for (let c of h) if (c.trim()) try {
|
|
55965
|
+
C(c, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (k) => o = k, reasoningContent: () => r, appendReasoningContent: (k) => r += k, isReasoningComplete: () => d, setReasoningComplete: (k) => d = k });
|
|
55966
|
+
} catch (k) {
|
|
55967
|
+
console.error("Error processing line:", c, k), a.enqueue(n.encode(c + `
|
|
55968
|
+
`));
|
|
55969
|
+
}
|
|
55970
|
+
continue;
|
|
55971
|
+
}
|
|
55972
|
+
let y = l.split(`
|
|
55973
|
+
`);
|
|
55974
|
+
l = y.pop() || "";
|
|
55975
|
+
for (let h of y) if (h.trim()) try {
|
|
55976
|
+
C(h, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (c) => o = c, reasoningContent: () => r, appendReasoningContent: (c) => r += c, isReasoningComplete: () => d, setReasoningComplete: (c) => d = c });
|
|
55977
|
+
} catch (c) {
|
|
55978
|
+
console.error("Error processing line:", h, c), a.enqueue(n.encode(h + `
|
|
55979
|
+
`));
|
|
55980
|
+
}
|
|
55981
|
+
}
|
|
55982
|
+
} catch (p) {
|
|
55983
|
+
console.error("Stream error:", p), a.error(p);
|
|
55984
|
+
} finally {
|
|
55985
|
+
try {
|
|
55986
|
+
m.releaseLock();
|
|
55987
|
+
} catch (p) {
|
|
55988
|
+
console.error("Error releasing reader lock:", p);
|
|
55989
|
+
}
|
|
55990
|
+
a.close();
|
|
55991
|
+
}
|
|
55992
|
+
} });
|
|
55993
|
+
return new Response(f, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
55994
|
+
}
|
|
55995
|
+
return e;
|
|
55996
|
+
}
|
|
55997
|
+
};
|
|
55998
|
+
var de = { AnthropicTransformer: q, GeminiTransformer: U, DeepseekTransformer: j, TooluseTransformer: J, OpenrouterTransformer: D, MaxTokenTransformer: B, GroqTransformer: W };
|
|
55999
|
+
var G = class {
|
|
55825
56000
|
constructor(e) {
|
|
55826
56001
|
this.configService = e;
|
|
55827
56002
|
}
|
|
55828
56003
|
transformers = /* @__PURE__ */ new Map();
|
|
55829
56004
|
registerTransformer(e, t) {
|
|
55830
|
-
this.transformers.set(e, t),
|
|
56005
|
+
this.transformers.set(e, t), v(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
|
|
55831
56006
|
}
|
|
55832
56007
|
getTransformer(e) {
|
|
55833
56008
|
return this.transformers.get(e);
|
|
@@ -55857,9 +56032,9 @@ var D = class {
|
|
|
55857
56032
|
try {
|
|
55858
56033
|
let t = import_node_module.default._load;
|
|
55859
56034
|
if (import_node_module.default._load = function(n, o, r) {
|
|
55860
|
-
return n === "claude-code-router" ? { log:
|
|
56035
|
+
return n === "claude-code-router" ? { log: v } : t.apply(import_node_module.default, arguments);
|
|
55861
56036
|
}, e.path) {
|
|
55862
|
-
let n =
|
|
56037
|
+
let n = Y(Y.resolve(e.path));
|
|
55863
56038
|
if (n) {
|
|
55864
56039
|
let o = new n(e.options);
|
|
55865
56040
|
if (!o.name) throw new Error(`Transformer instance from ${e.path} does not have a name property.`);
|
|
@@ -55868,19 +56043,19 @@ var D = class {
|
|
|
55868
56043
|
}
|
|
55869
56044
|
return false;
|
|
55870
56045
|
} catch (t) {
|
|
55871
|
-
return
|
|
56046
|
+
return v(`load transformer (${e.path}) error:`, t.message, t.stack), false;
|
|
55872
56047
|
}
|
|
55873
56048
|
}
|
|
55874
56049
|
async initialize() {
|
|
55875
56050
|
try {
|
|
55876
56051
|
await this.registerDefaultTransformersInternal(), await this.loadFromConfig();
|
|
55877
56052
|
} catch (e) {
|
|
55878
|
-
|
|
56053
|
+
v("TransformerService init error:", e);
|
|
55879
56054
|
}
|
|
55880
56055
|
}
|
|
55881
56056
|
async registerDefaultTransformersInternal() {
|
|
55882
56057
|
try {
|
|
55883
|
-
Object.values(
|
|
56058
|
+
Object.values(de).forEach((e) => {
|
|
55884
56059
|
if ("TransformerName" in e && typeof e.TransformerName == "string") this.registerTransformer(e.TransformerName, e);
|
|
55885
56060
|
else {
|
|
55886
56061
|
let t = new e();
|
|
@@ -55888,7 +56063,7 @@ var D = class {
|
|
|
55888
56063
|
}
|
|
55889
56064
|
});
|
|
55890
56065
|
} catch (e) {
|
|
55891
|
-
|
|
56066
|
+
v("transformer regist error:", e);
|
|
55892
56067
|
}
|
|
55893
56068
|
}
|
|
55894
56069
|
async loadFromConfig() {
|
|
@@ -55896,20 +56071,20 @@ var D = class {
|
|
|
55896
56071
|
for (let t of e) await this.registerTransformerFromConfig(t);
|
|
55897
56072
|
}
|
|
55898
56073
|
};
|
|
55899
|
-
function
|
|
55900
|
-
let
|
|
55901
|
-
return
|
|
56074
|
+
function _e() {
|
|
56075
|
+
let s = (0, import_fastify.default)({});
|
|
56076
|
+
return s.setErrorHandler(ie), s.register(import_cors.default), s;
|
|
55902
56077
|
}
|
|
55903
|
-
var
|
|
56078
|
+
var te = class {
|
|
55904
56079
|
app;
|
|
55905
56080
|
configService;
|
|
55906
56081
|
llmService;
|
|
55907
56082
|
providerService;
|
|
55908
56083
|
transformerService;
|
|
55909
56084
|
constructor(e = {}) {
|
|
55910
|
-
this.configService = new
|
|
55911
|
-
this.providerService = new
|
|
55912
|
-
}), this.app =
|
|
56085
|
+
this.configService = new I(e), this.transformerService = new G(this.configService), this.transformerService.initialize().finally(() => {
|
|
56086
|
+
this.providerService = new F(this.configService, this.transformerService), this.llmService = new $(this.providerService);
|
|
56087
|
+
}), this.app = _e();
|
|
55913
56088
|
}
|
|
55914
56089
|
async register(e, t) {
|
|
55915
56090
|
await this.app.register(e, t);
|
|
@@ -55923,29 +56098,29 @@ var G = class {
|
|
|
55923
56098
|
try {
|
|
55924
56099
|
let r = n.body;
|
|
55925
56100
|
if (!r || !r.model) return o.code(400).send({ error: "Missing model in request body" });
|
|
55926
|
-
let [
|
|
55927
|
-
r.model =
|
|
56101
|
+
let [d, l] = r.model.split(",");
|
|
56102
|
+
r.model = l, n.provider = d;
|
|
55928
56103
|
return;
|
|
55929
56104
|
} catch (r) {
|
|
55930
56105
|
return n.log.error("Error in modelProviderMiddleware:", r), o.code(500).send({ error: "Internal server error" });
|
|
55931
56106
|
}
|
|
55932
|
-
}), this.app.register(
|
|
56107
|
+
}), this.app.register(ce);
|
|
55933
56108
|
let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
|
|
55934
|
-
|
|
56109
|
+
v(`\u{1F680} LLMs API server listening on ${e}`);
|
|
55935
56110
|
let t = async (n) => {
|
|
55936
|
-
|
|
56111
|
+
v(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
|
|
55937
56112
|
};
|
|
55938
56113
|
process.on("SIGINT", () => t("SIGINT")), process.on("SIGTERM", () => t("SIGTERM"));
|
|
55939
56114
|
} catch (e) {
|
|
55940
|
-
|
|
56115
|
+
v(`Error starting server: ${e}`), process.exit(1);
|
|
55941
56116
|
}
|
|
55942
56117
|
}
|
|
55943
56118
|
};
|
|
55944
|
-
var
|
|
56119
|
+
var tn = te;
|
|
55945
56120
|
|
|
55946
56121
|
// src/server.ts
|
|
55947
56122
|
var createServer = (config) => {
|
|
55948
|
-
const server = new
|
|
56123
|
+
const server = new tn(config);
|
|
55949
56124
|
return server;
|
|
55950
56125
|
};
|
|
55951
56126
|
|
|
@@ -56050,6 +56225,33 @@ var router = async (req, res, config) => {
|
|
|
56050
56225
|
return;
|
|
56051
56226
|
};
|
|
56052
56227
|
|
|
56228
|
+
// src/middleware/auth.ts
|
|
56229
|
+
var apiKeyAuth = (config) => (req, reply, done) => {
|
|
56230
|
+
if (["/", "/health"].includes(req.url)) {
|
|
56231
|
+
return done();
|
|
56232
|
+
}
|
|
56233
|
+
const apiKey = config.APIKEY;
|
|
56234
|
+
if (!apiKey) {
|
|
56235
|
+
return done();
|
|
56236
|
+
}
|
|
56237
|
+
const authKey = req.headers.authorization || req.headers["x-api-key"];
|
|
56238
|
+
if (!authKey) {
|
|
56239
|
+
reply.status(401).send("APIKEY is missing");
|
|
56240
|
+
return;
|
|
56241
|
+
}
|
|
56242
|
+
let token = "";
|
|
56243
|
+
if (authKey.startsWith("Bearer")) {
|
|
56244
|
+
token = authKey.split(" ")[1];
|
|
56245
|
+
} else {
|
|
56246
|
+
token = authKey;
|
|
56247
|
+
}
|
|
56248
|
+
if (token !== apiKey) {
|
|
56249
|
+
reply.status(401).send("Invalid API key");
|
|
56250
|
+
return;
|
|
56251
|
+
}
|
|
56252
|
+
done();
|
|
56253
|
+
};
|
|
56254
|
+
|
|
56053
56255
|
// src/utils/processCheck.ts
|
|
56054
56256
|
var import_fs2 = require("fs");
|
|
56055
56257
|
function incrementReferenceCount() {
|
|
@@ -56151,6 +56353,13 @@ async function run(options = {}) {
|
|
|
56151
56353
|
await initializeClaudeConfig();
|
|
56152
56354
|
await initDir();
|
|
56153
56355
|
const config = await initConfig();
|
|
56356
|
+
let HOST = config.HOST;
|
|
56357
|
+
if (config.HOST && !config.APIKEY) {
|
|
56358
|
+
HOST = "127.0.0.1";
|
|
56359
|
+
console.warn(
|
|
56360
|
+
"\u26A0\uFE0F API key is not set. HOST is forced to 127.0.0.1."
|
|
56361
|
+
);
|
|
56362
|
+
}
|
|
56154
56363
|
const port = options.port || 3456;
|
|
56155
56364
|
savePid(process.pid);
|
|
56156
56365
|
process.on("SIGINT", () => {
|
|
@@ -56162,12 +56371,14 @@ async function run(options = {}) {
|
|
|
56162
56371
|
cleanupPidFile();
|
|
56163
56372
|
process.exit(0);
|
|
56164
56373
|
});
|
|
56374
|
+
console.log(HOST);
|
|
56165
56375
|
const servicePort = process.env.SERVICE_PORT ? parseInt(process.env.SERVICE_PORT) : port;
|
|
56166
56376
|
const server = createServer({
|
|
56167
56377
|
jsonPath: CONFIG_FILE,
|
|
56168
56378
|
initialConfig: {
|
|
56169
56379
|
// ...config,
|
|
56170
56380
|
providers: config.Providers || config.providers,
|
|
56381
|
+
HOST,
|
|
56171
56382
|
PORT: servicePort,
|
|
56172
56383
|
LOG_FILE: (0, import_path2.join)(
|
|
56173
56384
|
(0, import_os.homedir)(),
|
|
@@ -56176,6 +56387,7 @@ async function run(options = {}) {
|
|
|
56176
56387
|
)
|
|
56177
56388
|
}
|
|
56178
56389
|
});
|
|
56390
|
+
server.addHook("preHandler", apiKeyAuth(config));
|
|
56179
56391
|
server.addHook(
|
|
56180
56392
|
"preHandler",
|
|
56181
56393
|
async (req, reply) => router(req, reply, config)
|
|
@@ -56235,12 +56447,17 @@ async function closeService() {
|
|
|
56235
56447
|
|
|
56236
56448
|
// src/utils/codeCommand.ts
|
|
56237
56449
|
async function executeCodeCommand(args = []) {
|
|
56450
|
+
const config = await readConfigFile();
|
|
56238
56451
|
const env = {
|
|
56239
56452
|
...process.env,
|
|
56240
56453
|
ANTHROPIC_AUTH_TOKEN: "test",
|
|
56241
56454
|
ANTHROPIC_BASE_URL: `http://127.0.0.1:3456`,
|
|
56242
56455
|
API_TIMEOUT_MS: "600000"
|
|
56243
56456
|
};
|
|
56457
|
+
if (config?.APIKEY) {
|
|
56458
|
+
env.ANTHROPIC_API_KEY = config.APIKEY;
|
|
56459
|
+
delete env.ANTHROPIC_AUTH_TOKEN;
|
|
56460
|
+
}
|
|
56244
56461
|
incrementReferenceCount();
|
|
56245
56462
|
const claudePath = process.env.CLAUDE_PATH || "claude";
|
|
56246
56463
|
const claudeProcess = (0, import_child_process.spawn)(claudePath, args, {
|
|
@@ -56264,7 +56481,7 @@ async function executeCodeCommand(args = []) {
|
|
|
56264
56481
|
}
|
|
56265
56482
|
|
|
56266
56483
|
// package.json
|
|
56267
|
-
var version = "1.0.
|
|
56484
|
+
var version = "1.0.20";
|
|
56268
56485
|
|
|
56269
56486
|
// src/cli.ts
|
|
56270
56487
|
var import_child_process2 = require("child_process");
|