@musistudio/claude-code-router 1.0.15 → 1.0.16
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 +9 -2
- package/dist/cli.js +528 -501
- package/package.json +2 -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 p2 = 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
|
+
p2.catch(noop);
|
|
283
|
+
return p2;
|
|
284
284
|
}
|
|
285
285
|
function unshift(value) {
|
|
286
|
-
var
|
|
286
|
+
var p2 = 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
|
+
p2.catch(noop);
|
|
296
|
+
return p2;
|
|
297
297
|
}
|
|
298
298
|
function drained() {
|
|
299
|
-
var
|
|
299
|
+
var p2 = 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 p2;
|
|
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 p2 = this._loadRegistered();
|
|
922
|
+
return p2.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((p2) => p2.replace(/'|"|`/g, ""));
|
|
3648
3648
|
const leadingBracket = strPath[0] === "[";
|
|
3649
|
-
path3 = path3.map((
|
|
3650
|
-
if (
|
|
3651
|
-
else return
|
|
3649
|
+
path3 = path3.map((p2) => {
|
|
3650
|
+
if (p2[0] === "[") return p2.substr(1, p2.length - 2);
|
|
3651
|
+
else return p2;
|
|
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((p2) => `o${delim}${p2}`).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((p2) => `
|
|
3731
|
+
case o${delim}${p2} === censor:
|
|
3732
|
+
secret[${escPath}].circle = ${JSON.stringify(p2)}
|
|
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, p2) {
|
|
3932
3932
|
var i = -1;
|
|
3933
|
-
var l =
|
|
3933
|
+
var l = p2.length;
|
|
3934
3934
|
var n = o;
|
|
3935
3935
|
while (n != null && ++i < l) {
|
|
3936
|
-
n = n[
|
|
3936
|
+
n = n[p2[i]];
|
|
3937
3937
|
}
|
|
3938
3938
|
return n;
|
|
3939
3939
|
}
|
|
@@ -4311,32 +4311,32 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
4311
4311
|
}
|
|
4312
4312
|
}
|
|
4313
4313
|
module2.exports = format;
|
|
4314
|
-
function format(
|
|
4314
|
+
function format(f, args, opts) {
|
|
4315
4315
|
var ss = opts && opts.stringify || tryStringify;
|
|
4316
4316
|
var offset = 1;
|
|
4317
|
-
if (typeof
|
|
4317
|
+
if (typeof f === "object" && f !== null) {
|
|
4318
4318
|
var len = args.length + offset;
|
|
4319
|
-
if (len === 1) return
|
|
4319
|
+
if (len === 1) return f;
|
|
4320
4320
|
var objects = new Array(len);
|
|
4321
|
-
objects[0] = ss(
|
|
4321
|
+
objects[0] = ss(f);
|
|
4322
4322
|
for (var index = 1; index < len; index++) {
|
|
4323
4323
|
objects[index] = ss(args[index]);
|
|
4324
4324
|
}
|
|
4325
4325
|
return objects.join(" ");
|
|
4326
4326
|
}
|
|
4327
|
-
if (typeof
|
|
4328
|
-
return
|
|
4327
|
+
if (typeof f !== "string") {
|
|
4328
|
+
return f;
|
|
4329
4329
|
}
|
|
4330
4330
|
var argLen = args.length;
|
|
4331
|
-
if (argLen === 0) return
|
|
4331
|
+
if (argLen === 0) return f;
|
|
4332
4332
|
var str = "";
|
|
4333
4333
|
var a = 1 - offset;
|
|
4334
4334
|
var lastPos = -1;
|
|
4335
|
-
var flen =
|
|
4335
|
+
var flen = f && f.length || 0;
|
|
4336
4336
|
for (var i = 0; i < flen; ) {
|
|
4337
|
-
if (
|
|
4337
|
+
if (f.charCodeAt(i) === 37 && i + 1 < flen) {
|
|
4338
4338
|
lastPos = lastPos > -1 ? lastPos : 0;
|
|
4339
|
-
switch (
|
|
4339
|
+
switch (f.charCodeAt(i + 1)) {
|
|
4340
4340
|
case 100:
|
|
4341
4341
|
// 'd'
|
|
4342
4342
|
case 102:
|
|
@@ -4344,7 +4344,7 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
4344
4344
|
break;
|
|
4345
4345
|
if (args[a] == null) break;
|
|
4346
4346
|
if (lastPos < i)
|
|
4347
|
-
str +=
|
|
4347
|
+
str += f.slice(lastPos, i);
|
|
4348
4348
|
str += Number(args[a]);
|
|
4349
4349
|
lastPos = i + 2;
|
|
4350
4350
|
i++;
|
|
@@ -4354,7 +4354,7 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
4354
4354
|
break;
|
|
4355
4355
|
if (args[a] == null) break;
|
|
4356
4356
|
if (lastPos < i)
|
|
4357
|
-
str +=
|
|
4357
|
+
str += f.slice(lastPos, i);
|
|
4358
4358
|
str += Math.floor(Number(args[a]));
|
|
4359
4359
|
lastPos = i + 2;
|
|
4360
4360
|
i++;
|
|
@@ -4368,7 +4368,7 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
4368
4368
|
break;
|
|
4369
4369
|
if (args[a] === void 0) break;
|
|
4370
4370
|
if (lastPos < i)
|
|
4371
|
-
str +=
|
|
4371
|
+
str += f.slice(lastPos, i);
|
|
4372
4372
|
var type = typeof args[a];
|
|
4373
4373
|
if (type === "string") {
|
|
4374
4374
|
str += "'" + args[a] + "'";
|
|
@@ -4390,14 +4390,14 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
4390
4390
|
if (a >= argLen)
|
|
4391
4391
|
break;
|
|
4392
4392
|
if (lastPos < i)
|
|
4393
|
-
str +=
|
|
4393
|
+
str += f.slice(lastPos, i);
|
|
4394
4394
|
str += String(args[a]);
|
|
4395
4395
|
lastPos = i + 2;
|
|
4396
4396
|
i++;
|
|
4397
4397
|
break;
|
|
4398
4398
|
case 37:
|
|
4399
4399
|
if (lastPos < i)
|
|
4400
|
-
str +=
|
|
4400
|
+
str += f.slice(lastPos, i);
|
|
4401
4401
|
str += "%";
|
|
4402
4402
|
lastPos = i + 2;
|
|
4403
4403
|
i++;
|
|
@@ -4409,9 +4409,9 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
4409
4409
|
++i;
|
|
4410
4410
|
}
|
|
4411
4411
|
if (lastPos === -1)
|
|
4412
|
-
return
|
|
4412
|
+
return f;
|
|
4413
4413
|
else if (lastPos < flen) {
|
|
4414
|
-
str +=
|
|
4414
|
+
str += f.slice(lastPos);
|
|
4415
4415
|
}
|
|
4416
4416
|
return str;
|
|
4417
4417
|
}
|
|
@@ -13188,12 +13188,12 @@ var require_util = __commonJS({
|
|
|
13188
13188
|
return str.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
13189
13189
|
}
|
|
13190
13190
|
exports2.unescapeJsonPointer = unescapeJsonPointer;
|
|
13191
|
-
function eachItem(xs,
|
|
13191
|
+
function eachItem(xs, f) {
|
|
13192
13192
|
if (Array.isArray(xs)) {
|
|
13193
13193
|
for (const x of xs)
|
|
13194
|
-
|
|
13194
|
+
f(x);
|
|
13195
13195
|
} else {
|
|
13196
|
-
|
|
13196
|
+
f(xs);
|
|
13197
13197
|
}
|
|
13198
13198
|
}
|
|
13199
13199
|
exports2.eachItem = eachItem;
|
|
@@ -13236,14 +13236,14 @@ 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((p2) => gen.assign((0, codegen_1._)`${props}${(0, codegen_1.getProperty)(p2)}`, true));
|
|
13240
13240
|
}
|
|
13241
13241
|
exports2.setEvaluated = setEvaluated;
|
|
13242
13242
|
var snippets = {};
|
|
13243
|
-
function useFunc(gen,
|
|
13243
|
+
function useFunc(gen, f) {
|
|
13244
13244
|
return gen.scopeValue("func", {
|
|
13245
|
-
ref:
|
|
13246
|
-
code: snippets[
|
|
13245
|
+
ref: f,
|
|
13246
|
+
code: snippets[f.code] || (snippets[f.code] = new code_1._Code(f.code))
|
|
13247
13247
|
});
|
|
13248
13248
|
}
|
|
13249
13249
|
exports2.useFunc = useFunc;
|
|
@@ -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((p2) => p2 !== "__proto__") : [];
|
|
13813
13813
|
}
|
|
13814
13814
|
exports2.allSchemaProperties = allSchemaProperties;
|
|
13815
13815
|
function schemaProperties(it, schemaMap) {
|
|
13816
|
-
return allSchemaProperties(schemaMap).filter((
|
|
13816
|
+
return allSchemaProperties(schemaMap).filter((p2) => !(0, util_1.alwaysValidSchema)(it, schemaMap[p2]));
|
|
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 p2 = resolver.parse(id2);
|
|
14295
|
+
return _getFullPath(resolver, p2);
|
|
14296
14296
|
}
|
|
14297
14297
|
exports2.getFullPath = getFullPath;
|
|
14298
|
-
function _getFullPath(resolver,
|
|
14299
|
-
const serialized = resolver.serialize(
|
|
14298
|
+
function _getFullPath(resolver, p2) {
|
|
14299
|
+
const serialized = resolver.serialize(p2);
|
|
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 p2 = this.opts.uriResolver.parse(ref);
|
|
15075
|
+
const refPath = (0, resolve_1._getFullPath)(this.opts.uriResolver, p2);
|
|
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, p2, 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, p2, 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, p2, schOrRef);
|
|
15101
15101
|
}
|
|
15102
15102
|
exports2.resolveSchema = resolveSchema;
|
|
15103
15103
|
var PREVENT_SCOPE_CHANGE = /* @__PURE__ */ new Set([
|
|
@@ -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 p2 = this._loading[ref];
|
|
16052
|
+
if (p2)
|
|
16053
|
+
return p2;
|
|
16054
16054
|
try {
|
|
16055
16055
|
return await (this._loading[ref] = loadSchema(ref));
|
|
16056
16056
|
} finally {
|
|
@@ -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((p2) => (0, codegen_1._)`${key} === ${p2}`));
|
|
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((p2) => (0, codegen_1._)`${(0, code_1.usePattern)(cxt, p2)}.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((p2) => !(0, util_1.alwaysValidSchema)(it, schema[p2]));
|
|
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((p2) => (0, util_1.alwaysValidSchema)(it, schema[p2]));
|
|
17662
17662
|
if (patterns.length === 0 || alwaysValidPatterns.length === patterns.length && (!it.opts.unevaluated || it.props === true)) {
|
|
17663
17663
|
return;
|
|
17664
17664
|
}
|
|
@@ -18774,17 +18774,17 @@ var require_dist2 = __commonJS({
|
|
|
18774
18774
|
};
|
|
18775
18775
|
formatsPlugin.get = (name, mode = "full") => {
|
|
18776
18776
|
const formats = mode === "fast" ? formats_1.fastFormats : formats_1.fullFormats;
|
|
18777
|
-
const
|
|
18778
|
-
if (!
|
|
18777
|
+
const f = formats[name];
|
|
18778
|
+
if (!f)
|
|
18779
18779
|
throw new Error(`Unknown format "${name}"`);
|
|
18780
|
-
return
|
|
18780
|
+
return f;
|
|
18781
18781
|
};
|
|
18782
18782
|
function addFormats(ajv, list, fs3, exportName) {
|
|
18783
18783
|
var _a;
|
|
18784
18784
|
var _b;
|
|
18785
18785
|
(_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
18786
|
-
for (const
|
|
18787
|
-
ajv.addFormat(
|
|
18786
|
+
for (const f of list)
|
|
18787
|
+
ajv.addFormat(f, fs3[f]);
|
|
18788
18788
|
}
|
|
18789
18789
|
module2.exports = exports2 = formatsPlugin;
|
|
18790
18790
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -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 p2 in props) {
|
|
21782
|
+
if (Object.prototype.hasOwnProperty.call(optProps, p2))
|
|
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((p2) => p2 === 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((p2) => !(0, util_1.alwaysValidSchema)(it, schema[p2]));
|
|
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((p2) => (0, codegen_1._)`${key} !== ${p2}`));
|
|
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((p2) => (0, codegen_1._)`${key} !== ${p2}`)) : 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((p2) => (0, codegen_1._)`${hasProp}.call(${data}, ${p2})`));
|
|
22843
22843
|
gen.if((0, codegen_1.not)(allProps), () => parsingError(cxt, (0, codegen_1.str)`missing required properties`));
|
|
22844
22844
|
}
|
|
22845
22845
|
}
|
|
@@ -23504,7 +23504,7 @@ var require_re = __commonJS({
|
|
|
23504
23504
|
} = require_constants2();
|
|
23505
23505
|
var debug = require_debug2();
|
|
23506
23506
|
exports2 = module2.exports = {};
|
|
23507
|
-
var
|
|
23507
|
+
var re = exports2.re = [];
|
|
23508
23508
|
var safeRe = exports2.safeRe = [];
|
|
23509
23509
|
var src = exports2.src = [];
|
|
23510
23510
|
var safeSrc = exports2.safeSrc = [];
|
|
@@ -23529,7 +23529,7 @@ var require_re = __commonJS({
|
|
|
23529
23529
|
t[name] = index;
|
|
23530
23530
|
src[index] = value;
|
|
23531
23531
|
safeSrc[index] = safe;
|
|
23532
|
-
|
|
23532
|
+
re[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: re, 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 ? re[t.LOOSE] : re[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 ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
|
|
23777
23777
|
if (!match || match[1] !== identifier) {
|
|
23778
23778
|
throw new Error(`invalid identifier: ${identifier}`);
|
|
23779
23779
|
}
|
|
@@ -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: re, 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 ? re[t.COERCEFULL] : re[t.COERCE]);
|
|
24240
24240
|
} else {
|
|
24241
|
-
const coerceRtlRegex = options.includePrerelease ?
|
|
24241
|
+
const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[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 ? re[t.HYPHENRANGELOOSE] : re[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(re[t.COMPARATORTRIM], comparatorTrimReplace);
|
|
24384
24384
|
debug("comparator trim", range);
|
|
24385
|
-
range = range.replace(
|
|
24385
|
+
range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
|
|
24386
24386
|
debug("tilde trim", range);
|
|
24387
|
-
range = range.replace(
|
|
24387
|
+
range = range.replace(re[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(re[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: re,
|
|
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, (_,
|
|
24494
|
-
debug("tilde", comp, _,
|
|
24492
|
+
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
|
24493
|
+
return comp.replace(r, (_, M, m, p2, pr) => {
|
|
24494
|
+
debug("tilde", comp, _, M, m, p2, pr);
|
|
24495
24495
|
let ret;
|
|
24496
|
-
if (isX(
|
|
24496
|
+
if (isX(M)) {
|
|
24497
24497
|
ret = "";
|
|
24498
24498
|
} else if (isX(m)) {
|
|
24499
|
-
ret = `>=${
|
|
24500
|
-
} else if (isX(
|
|
24501
|
-
ret = `>=${
|
|
24499
|
+
ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
|
24500
|
+
} else if (isX(p2)) {
|
|
24501
|
+
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
|
24502
24502
|
} else if (pr) {
|
|
24503
24503
|
debug("replaceTilde pr", pr);
|
|
24504
|
-
ret = `>=${
|
|
24504
|
+
ret = `>=${M}.${m}.${p2}-${pr} <${M}.${+m + 1}.0-0`;
|
|
24505
24505
|
} else {
|
|
24506
|
-
ret = `>=${
|
|
24506
|
+
ret = `>=${M}.${m}.${p2} <${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 ?
|
|
24517
|
+
const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
|
|
24518
24518
|
const z = options.includePrerelease ? "-0" : "";
|
|
24519
|
-
return comp.replace(r, (_,
|
|
24520
|
-
debug("caret", comp, _,
|
|
24519
|
+
return comp.replace(r, (_, M, m, p2, pr) => {
|
|
24520
|
+
debug("caret", comp, _, M, m, p2, pr);
|
|
24521
24521
|
let ret;
|
|
24522
|
-
if (isX(
|
|
24522
|
+
if (isX(M)) {
|
|
24523
24523
|
ret = "";
|
|
24524
24524
|
} else if (isX(m)) {
|
|
24525
|
-
ret = `>=${
|
|
24526
|
-
} else if (isX(
|
|
24527
|
-
if (
|
|
24528
|
-
ret = `>=${
|
|
24525
|
+
ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
24526
|
+
} else if (isX(p2)) {
|
|
24527
|
+
if (M === "0") {
|
|
24528
|
+
ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
24529
24529
|
} else {
|
|
24530
|
-
ret = `>=${
|
|
24530
|
+
ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
|
|
24531
24531
|
}
|
|
24532
24532
|
} else if (pr) {
|
|
24533
24533
|
debug("replaceCaret pr", pr);
|
|
24534
|
-
if (
|
|
24534
|
+
if (M === "0") {
|
|
24535
24535
|
if (m === "0") {
|
|
24536
|
-
ret = `>=${
|
|
24536
|
+
ret = `>=${M}.${m}.${p2}-${pr} <${M}.${m}.${+p2 + 1}-0`;
|
|
24537
24537
|
} else {
|
|
24538
|
-
ret = `>=${
|
|
24538
|
+
ret = `>=${M}.${m}.${p2}-${pr} <${M}.${+m + 1}.0-0`;
|
|
24539
24539
|
}
|
|
24540
24540
|
} else {
|
|
24541
|
-
ret = `>=${
|
|
24541
|
+
ret = `>=${M}.${m}.${p2}-${pr} <${+M + 1}.0.0-0`;
|
|
24542
24542
|
}
|
|
24543
24543
|
} else {
|
|
24544
24544
|
debug("no pr");
|
|
24545
|
-
if (
|
|
24545
|
+
if (M === "0") {
|
|
24546
24546
|
if (m === "0") {
|
|
24547
|
-
ret = `>=${
|
|
24547
|
+
ret = `>=${M}.${m}.${p2}${z} <${M}.${m}.${+p2 + 1}-0`;
|
|
24548
24548
|
} else {
|
|
24549
|
-
ret = `>=${
|
|
24549
|
+
ret = `>=${M}.${m}.${p2}${z} <${M}.${+m + 1}.0-0`;
|
|
24550
24550
|
}
|
|
24551
24551
|
} else {
|
|
24552
|
-
ret = `>=${
|
|
24552
|
+
ret = `>=${M}.${m}.${p2} <${+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,
|
|
24567
|
-
debug("xRange", comp, ret, gtlt,
|
|
24568
|
-
const xM = isX(
|
|
24565
|
+
const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
|
|
24566
|
+
return comp.replace(r, (ret, gtlt, M, m, p2, pr) => {
|
|
24567
|
+
debug("xRange", comp, ret, gtlt, M, m, p2, pr);
|
|
24568
|
+
const xM = isX(M);
|
|
24569
24569
|
const xm = xM || isX(m);
|
|
24570
|
-
const xp = xm || isX(
|
|
24570
|
+
const xp = xm || isX(p2);
|
|
24571
24571
|
const anyX = xp;
|
|
24572
24572
|
if (gtlt === "=" && anyX) {
|
|
24573
24573
|
gtlt = "";
|
|
@@ -24583,21 +24583,21 @@ var require_range = __commonJS({
|
|
|
24583
24583
|
if (xm) {
|
|
24584
24584
|
m = 0;
|
|
24585
24585
|
}
|
|
24586
|
-
|
|
24586
|
+
p2 = 0;
|
|
24587
24587
|
if (gtlt === ">") {
|
|
24588
24588
|
gtlt = ">=";
|
|
24589
24589
|
if (xm) {
|
|
24590
|
-
|
|
24590
|
+
M = +M + 1;
|
|
24591
24591
|
m = 0;
|
|
24592
|
-
|
|
24592
|
+
p2 = 0;
|
|
24593
24593
|
} else {
|
|
24594
24594
|
m = +m + 1;
|
|
24595
|
-
|
|
24595
|
+
p2 = 0;
|
|
24596
24596
|
}
|
|
24597
24597
|
} else if (gtlt === "<=") {
|
|
24598
24598
|
gtlt = "<";
|
|
24599
24599
|
if (xm) {
|
|
24600
|
-
|
|
24600
|
+
M = +M + 1;
|
|
24601
24601
|
} else {
|
|
24602
24602
|
m = +m + 1;
|
|
24603
24603
|
}
|
|
@@ -24605,11 +24605,11 @@ var require_range = __commonJS({
|
|
|
24605
24605
|
if (gtlt === "<") {
|
|
24606
24606
|
pr = "-0";
|
|
24607
24607
|
}
|
|
24608
|
-
ret = `${gtlt +
|
|
24608
|
+
ret = `${gtlt + M}.${m}.${p2}${pr}`;
|
|
24609
24609
|
} else if (xm) {
|
|
24610
|
-
ret = `>=${
|
|
24610
|
+
ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
|
|
24611
24611
|
} else if (xp) {
|
|
24612
|
-
ret = `>=${
|
|
24612
|
+
ret = `>=${M}.${m}.0${pr} <${M}.${+m + 1}.0-0`;
|
|
24613
24613
|
}
|
|
24614
24614
|
debug("xRange return", ret);
|
|
24615
24615
|
return ret;
|
|
@@ -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(re[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(re[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 ? re[t.COMPARATORLOOSE] : re[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: re, t } = require_re();
|
|
24785
24785
|
var cmp = require_cmp();
|
|
24786
24786
|
var debug = require_debug2();
|
|
24787
24787
|
var SemVer = require_semver();
|
|
@@ -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 p2 in m) if (p2 !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p2)) __createBinding(exports3, m, p2);
|
|
26391
26391
|
};
|
|
26392
26392
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
26393
26393
|
__exportStar(require_tokens(), exports2);
|
|
@@ -26498,13 +26498,13 @@ var require_util2 = __commonJS({
|
|
|
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 p2 = (_g = (_f = (_e = (_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 && _e !== void 0 ? _e : 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 (p2) {
|
|
26507
|
+
tokens.push(p2);
|
|
26508
26508
|
} else {
|
|
26509
26509
|
return [tokens, regexp.lastIndex];
|
|
26510
26510
|
}
|
|
@@ -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 p2 in m) if (p2 !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p2)) __createBinding(exports3, m, p2);
|
|
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(re, 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(re)) re = re.source;
|
|
27070
|
+
else if (typeof re !== "string") re = String(re);
|
|
27071
27071
|
try {
|
|
27072
|
-
|
|
27072
|
+
re = parse(re);
|
|
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
|
+
}(re, 0);
|
|
27101
27101
|
}
|
|
27102
27102
|
function isRegExp(x) {
|
|
27103
27103
|
return {}.toString.call(x) === "[object RegExp]";
|
|
@@ -37452,8 +37452,8 @@ var require_webidl = __commonJS({
|
|
|
37452
37452
|
message: `"${context.value}" is an invalid ${context.type}.`
|
|
37453
37453
|
});
|
|
37454
37454
|
};
|
|
37455
|
-
webidl.brandCheck = function(V2,
|
|
37456
|
-
if (!FunctionPrototypeSymbolHasInstance(
|
|
37455
|
+
webidl.brandCheck = function(V2, I2) {
|
|
37456
|
+
if (!FunctionPrototypeSymbolHasInstance(I2, V2)) {
|
|
37457
37457
|
const err = new TypeError("Illegal invocation");
|
|
37458
37458
|
err.code = "ERR_INVALID_THIS";
|
|
37459
37459
|
throw err;
|
|
@@ -37483,8 +37483,8 @@ var require_webidl = __commonJS({
|
|
|
37483
37483
|
message: "Illegal constructor"
|
|
37484
37484
|
});
|
|
37485
37485
|
};
|
|
37486
|
-
webidl.util.MakeTypeAssertion = function(
|
|
37487
|
-
return (O) => FunctionPrototypeSymbolHasInstance(
|
|
37486
|
+
webidl.util.MakeTypeAssertion = function(I2) {
|
|
37487
|
+
return (O) => FunctionPrototypeSymbolHasInstance(I2, O);
|
|
37488
37488
|
};
|
|
37489
37489
|
webidl.util.Type = function(V2) {
|
|
37490
37490
|
switch (typeof V2) {
|
|
@@ -38306,11 +38306,11 @@ var require_util4 = __commonJS({
|
|
|
38306
38306
|
}
|
|
38307
38307
|
function tryUpgradeRequestToAPotentiallyTrustworthyURL(request) {
|
|
38308
38308
|
}
|
|
38309
|
-
function sameOrigin(A2,
|
|
38310
|
-
if (A2.origin ===
|
|
38309
|
+
function sameOrigin(A2, B) {
|
|
38310
|
+
if (A2.origin === B.origin && A2.origin === "null") {
|
|
38311
38311
|
return true;
|
|
38312
38312
|
}
|
|
38313
|
-
if (A2.protocol ===
|
|
38313
|
+
if (A2.protocol === B.protocol && A2.hostname === B.hostname && A2.port === B.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: (p2, 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: (p2, at, len) => {
|
|
39620
|
+
assert(currentParser.ptr === p2);
|
|
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: (p2) => {
|
|
39629
|
+
assert(currentParser.ptr === p2);
|
|
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: (p2, at, len) => {
|
|
39639
|
+
assert(currentParser.ptr === p2);
|
|
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: (p2, at, len) => {
|
|
39650
|
+
assert(currentParser.ptr === p2);
|
|
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: (p2, statusCode, upgrade, shouldKeepAlive) => {
|
|
39662
|
+
assert(currentParser.ptr === p2);
|
|
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: (p2, at, len) => {
|
|
39672
|
+
assert(currentParser.ptr === p2);
|
|
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: (p2) => {
|
|
39681
|
+
assert(currentParser.ptr === p2);
|
|
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((p2) => p2[kUrl].origin);
|
|
42211
42211
|
}
|
|
42212
42212
|
[kGetDispatcher]() {
|
|
42213
42213
|
if (this[kClients].length === 0) {
|
|
@@ -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, p2) {
|
|
48577
|
+
return p2 in state ? state[p2] : target[p2];
|
|
48578
48578
|
},
|
|
48579
|
-
set(target,
|
|
48580
|
-
assert(!(
|
|
48581
|
-
target[
|
|
48579
|
+
set(target, p2, value) {
|
|
48580
|
+
assert(!(p2 in state));
|
|
48581
|
+
target[p2] = 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 p2 = createDeferredPromise();
|
|
49585
49585
|
let requestObject;
|
|
49586
49586
|
try {
|
|
49587
49587
|
requestObject = new Request(input, init);
|
|
49588
49588
|
} catch (e) {
|
|
49589
|
-
|
|
49590
|
-
return
|
|
49589
|
+
p2.reject(e);
|
|
49590
|
+
return p2.promise;
|
|
49591
49591
|
}
|
|
49592
49592
|
const request = getRequestState(requestObject);
|
|
49593
49593
|
if (requestObject.signal.aborted) {
|
|
49594
|
-
abortFetch(
|
|
49595
|
-
return
|
|
49594
|
+
abortFetch(p2, request, null, requestObject.signal.reason);
|
|
49595
|
+
return p2.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(p2, 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(p2, request, responseObject, controller.serializedAbortReason);
|
|
49620
49620
|
return;
|
|
49621
49621
|
}
|
|
49622
49622
|
if (response.type === "error") {
|
|
49623
|
-
|
|
49623
|
+
p2.reject(new TypeError("fetch failed", { cause: response.error }));
|
|
49624
49624
|
return;
|
|
49625
49625
|
}
|
|
49626
49626
|
responseObject = new WeakRef(fromInnerResponse(response, "immutable"));
|
|
49627
|
-
|
|
49628
|
-
|
|
49627
|
+
p2.resolve(responseObject.deref());
|
|
49628
|
+
p2 = 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 p2.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(p2, request, responseObject, error) {
|
|
49676
|
+
if (p2) {
|
|
49677
|
+
p2.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(A2,
|
|
50555
|
+
function urlEquals(A2, B, excludeFragment = false) {
|
|
50556
50556
|
const serializedA = URLSerializer(A2, excludeFragment);
|
|
50557
|
-
const serializedB = URLSerializer(
|
|
50557
|
+
const serializedB = URLSerializer(B, 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 p2 = this.#internalMatchAll(request, options, 1);
|
|
50611
|
+
if (p2.length === 0) {
|
|
50612
50612
|
return;
|
|
50613
50613
|
}
|
|
50614
|
-
return
|
|
50614
|
+
return p2[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 p2 = Promise.all(responsePromises);
|
|
50706
|
+
const responses = await p2;
|
|
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((p2) => p2.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((p2) => isValidSubprotocol(p2))) {
|
|
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((p2) => p2.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((p2) => isValidSubprotocol(p2))) {
|
|
53503
53503
|
throw new DOMException("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
|
|
53504
53504
|
}
|
|
53505
53505
|
this.#url = urlRecord.toString();
|
|
@@ -54471,9 +54471,9 @@ var require_tiktoken_bg = __commonJS({
|
|
|
54471
54471
|
heap[idx] = obj;
|
|
54472
54472
|
return idx;
|
|
54473
54473
|
}
|
|
54474
|
-
function handleError(
|
|
54474
|
+
function handleError(f, args) {
|
|
54475
54475
|
try {
|
|
54476
|
-
return
|
|
54476
|
+
return f.apply(this, args);
|
|
54477
54477
|
} catch (e) {
|
|
54478
54478
|
wasm.__wbindgen_export_0(addHeapObject(e));
|
|
54479
54479
|
}
|
|
@@ -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.5_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,11 +54966,12 @@ 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
|
|
54969
|
+
var import_node_module = __toESM(require("node:module"), 1);
|
|
54970
|
+
var W = ((a) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(a, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : a)(function(a) {
|
|
54970
54971
|
if (typeof require < "u") return require.apply(this, arguments);
|
|
54971
|
-
throw Error('Dynamic require of "' +
|
|
54972
|
+
throw Error('Dynamic require of "' + a + '" is not supported');
|
|
54972
54973
|
});
|
|
54973
|
-
var
|
|
54974
|
+
var N = class {
|
|
54974
54975
|
config = {};
|
|
54975
54976
|
options;
|
|
54976
54977
|
constructor(e = { jsonPath: "./config.json" }) {
|
|
@@ -55034,22 +55035,22 @@ var j = class {
|
|
|
55034
55035
|
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(", ")}`;
|
|
55035
55036
|
}
|
|
55036
55037
|
};
|
|
55037
|
-
function
|
|
55038
|
-
if (console.log(...
|
|
55039
|
-
let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(
|
|
55038
|
+
function p(...a) {
|
|
55039
|
+
if (console.log(...a), !(process.env.LOG === "true")) return;
|
|
55040
|
+
let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(a) ? a.map((r) => typeof r == "object" ? JSON.stringify(r) : String(r)).join(" ") : ""}
|
|
55040
55041
|
`, o = process.env.LOG_FILE || "app.log";
|
|
55041
55042
|
import_node_fs.default.appendFileSync(o, n, "utf8");
|
|
55042
55043
|
}
|
|
55043
|
-
function A(
|
|
55044
|
-
let o = new Error(
|
|
55044
|
+
function A(a, e = 500, t = "internal_error", n = "api_error") {
|
|
55045
|
+
let o = new Error(a);
|
|
55045
55046
|
return o.statusCode = e, o.code = t, o.type = n, o;
|
|
55046
55047
|
}
|
|
55047
|
-
async function
|
|
55048
|
-
e.log.error(
|
|
55049
|
-
let n =
|
|
55048
|
+
async function Z(a, e, t) {
|
|
55049
|
+
e.log.error(a);
|
|
55050
|
+
let n = a.statusCode || 500, o = { error: { message: a.message || "Internal Server Error", type: a.type || "api_error", code: a.code || "internal_error" } };
|
|
55050
55051
|
return t.code(n).send(o);
|
|
55051
55052
|
}
|
|
55052
|
-
function
|
|
55053
|
+
function ee(a, e, t) {
|
|
55053
55054
|
let n = new Headers({ "Content-Type": "application/json" });
|
|
55054
55055
|
t.headers && Object.entries(t.headers).forEach(([u, d]) => {
|
|
55055
55056
|
n.set(u, d);
|
|
@@ -55060,69 +55061,59 @@ function Q(i, e, t) {
|
|
|
55060
55061
|
t.signal.addEventListener("abort", d), r.addEventListener("abort", d), o = u.signal;
|
|
55061
55062
|
} else o = r;
|
|
55062
55063
|
let l = { method: "POST", headers: n, body: JSON.stringify(e), signal: o };
|
|
55063
|
-
return t.httpsProxy && (l.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())),
|
|
55064
|
+
return t.httpsProxy && (l.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), p("final request:", typeof a == "string" ? a : a.toString(), t.httpsProxy, l), fetch(typeof a == "string" ? a : a.toString(), l);
|
|
55064
55065
|
}
|
|
55065
|
-
var
|
|
55066
|
-
|
|
55067
|
-
let e =
|
|
55068
|
-
for (let { name: t, transformer: n } of e) n.endPoint &&
|
|
55069
|
-
let l = o.body, u = o.provider, d =
|
|
55066
|
+
var te = async (a) => {
|
|
55067
|
+
a.get("/", async (t, n) => ({ message: "LLMs API", version: "1.0.0" })), a.get("/health", async (t, n) => ({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
55068
|
+
let e = a._server.transformerService.getTransformersWithEndpoint();
|
|
55069
|
+
for (let { name: t, transformer: n } of e) n.endPoint && a.post(n.endPoint, async (o, r) => {
|
|
55070
|
+
let l = o.body, u = o.provider, d = a._server.providerService.getProvider(u);
|
|
55070
55071
|
if (!d) throw A(`Provider '${u}' not found`, 404, "provider_not_found");
|
|
55071
|
-
let
|
|
55072
|
+
let i = l, c = {};
|
|
55072
55073
|
if (typeof n.transformRequestOut == "function") {
|
|
55073
|
-
let s = n.transformRequestOut(l);
|
|
55074
|
-
s.body ? (
|
|
55075
|
-
}
|
|
55076
|
-
if (d.transformer?.use?.length) for (let s of d.transformer.use) {
|
|
55077
|
-
|
|
55078
|
-
|
|
55079
|
-
|
|
55080
|
-
|
|
55081
|
-
|
|
55082
|
-
|
|
55083
|
-
|
|
55084
|
-
|
|
55085
|
-
|
|
55086
|
-
|
|
55087
|
-
|
|
55088
|
-
|
|
55089
|
-
|
|
55090
|
-
|
|
55091
|
-
let h = v;
|
|
55092
|
-
if (d.transformer?.use?.length) for (let s of d.transformer.use) {
|
|
55093
|
-
let m = i._server.transformerService.getTransformer(s);
|
|
55094
|
-
!m || typeof m.transformResponseOut != "function" || (h = await m.transformResponseOut(h));
|
|
55095
|
-
}
|
|
55096
|
-
if (d.transformer?.[o.body.model]?.use?.length) for (let s of d.transformer[o.body.model].use) {
|
|
55097
|
-
let m = i._server.transformerService.getTransformer(s);
|
|
55098
|
-
!m || typeof m.transformResponseOut != "function" || (h = await m.transformResponseOut(h));
|
|
55099
|
-
}
|
|
55100
|
-
return n.transformResponseIn && (h = await n.transformResponseIn(h)), h.ok || r.code(h.status), l?.stream === true ? (r.header("Content-Type", "text/event-stream"), r.header("Cache-Control", "no-cache"), r.header("Connection", "keep-alive"), r.send(h.body)) : h.json();
|
|
55074
|
+
let s = await n.transformRequestOut(l);
|
|
55075
|
+
s.body ? (i = s.body, c = s.config || {}) : i = s;
|
|
55076
|
+
}
|
|
55077
|
+
if (p("use transformers:", d.transformer?.use), d.transformer?.use?.length) for (let s of d.transformer.use) {
|
|
55078
|
+
if (!s || typeof s.transformRequestIn != "function") continue;
|
|
55079
|
+
let _ = await s.transformRequestIn(i, d);
|
|
55080
|
+
_.body ? (i = _.body, c = { ...c, ..._.config }) : i = _;
|
|
55081
|
+
}
|
|
55082
|
+
if (d.transformer?.[o.body.model]?.use?.length) for (let s of d.transformer[o.body.model].use) !s || typeof s.transformRequestIn != "function" || (i = await s.transformRequestIn(i, d));
|
|
55083
|
+
let h = c.url || new URL(d.baseUrl), g = await ee(h, i, { httpsProxy: a._server.configService.getHttpsProxy(), ...c, headers: { Authorization: `Bearer ${d.apiKey}`, ...c?.headers || {} } });
|
|
55084
|
+
if (!g.ok) {
|
|
55085
|
+
let s = await g.text();
|
|
55086
|
+
throw p(`Error response from ${h}: ${s}`), A(`Error from provider: ${s}`, g.status, "provider_response_error");
|
|
55087
|
+
}
|
|
55088
|
+
let m = g;
|
|
55089
|
+
if (d.transformer?.use?.length) for (let s of d.transformer.use) !s || typeof s.transformResponseOut != "function" || (m = await s.transformResponseOut(m));
|
|
55090
|
+
if (d.transformer?.[o.body.model]?.use?.length) for (let s of d.transformer[o.body.model].use) !s || typeof s.transformResponseOut != "function" || (m = await s.transformResponseOut(m));
|
|
55091
|
+
return n.transformResponseIn && (m = await n.transformResponseIn(m)), m.ok || r.code(m.status), l?.stream === true ? (r.header("Content-Type", "text/event-stream"), r.header("Cache-Control", "no-cache"), r.header("Connection", "keep-alive"), r.send(m.body)) : m.json();
|
|
55101
55092
|
});
|
|
55102
|
-
|
|
55093
|
+
a.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) => {
|
|
55103
55094
|
let { name: o, type: r, baseUrl: l, apiKey: u, models: d } = t.body;
|
|
55104
55095
|
if (!o?.trim()) throw A("Provider name is required", 400, "invalid_request");
|
|
55105
|
-
if (!l || !
|
|
55096
|
+
if (!l || !le(l)) throw A("Valid base URL is required", 400, "invalid_request");
|
|
55106
55097
|
if (!u?.trim()) throw A("API key is required", 400, "invalid_request");
|
|
55107
55098
|
if (!d || !Array.isArray(d) || d.length === 0) throw A("At least one model is required", 400, "invalid_request");
|
|
55108
|
-
if (
|
|
55109
|
-
return
|
|
55110
|
-
}),
|
|
55111
|
-
let o =
|
|
55099
|
+
if (a._server.providerService.getProvider(id)) throw A(`Provider with ID '${id}' already exists`, 400, "provider_exists");
|
|
55100
|
+
return a._server.providerService.registerProvider(t.body);
|
|
55101
|
+
}), a.get("/providers", async (t, n) => a._server.providerService.getProviders()), a.get("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => {
|
|
55102
|
+
let o = a._server.providerService.getProvider(t.params.id);
|
|
55112
55103
|
return o || n.code(404).send({ error: "Provider not found" });
|
|
55113
|
-
}),
|
|
55114
|
-
let o =
|
|
55104
|
+
}), a.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) => {
|
|
55105
|
+
let o = a._server.providerService.updateProvider(t.params.id, t.body);
|
|
55115
55106
|
return o || n.code(404).send({ error: "Provider not found" });
|
|
55116
|
-
}),
|
|
55107
|
+
}), a.delete("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => a._server.providerService.deleteProvider(t.params.id) ? { message: "Provider deleted successfully" } : n.code(404).send({ error: "Provider not found" })), a.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) => a._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" }));
|
|
55117
55108
|
};
|
|
55118
|
-
function
|
|
55109
|
+
function le(a) {
|
|
55119
55110
|
try {
|
|
55120
|
-
return new URL(
|
|
55111
|
+
return new URL(a), true;
|
|
55121
55112
|
} catch {
|
|
55122
55113
|
return false;
|
|
55123
55114
|
}
|
|
55124
55115
|
}
|
|
55125
|
-
var
|
|
55116
|
+
var H = class {
|
|
55126
55117
|
constructor(e) {
|
|
55127
55118
|
this.providerService = e;
|
|
55128
55119
|
}
|
|
@@ -55159,9 +55150,10 @@ var q = class {
|
|
|
55159
55150
|
return this.providerService.getModelRoutes();
|
|
55160
55151
|
}
|
|
55161
55152
|
};
|
|
55162
|
-
var
|
|
55163
|
-
constructor(e) {
|
|
55153
|
+
var $ = class {
|
|
55154
|
+
constructor(e, t) {
|
|
55164
55155
|
this.configService = e;
|
|
55156
|
+
this.transformerService = t;
|
|
55165
55157
|
this.initializeCustomProviders();
|
|
55166
55158
|
}
|
|
55167
55159
|
providers = /* @__PURE__ */ new Map();
|
|
@@ -55177,9 +55169,24 @@ var J = class {
|
|
|
55177
55169
|
e.forEach((t) => {
|
|
55178
55170
|
try {
|
|
55179
55171
|
if (!t.name || !t.api_base_url || !t.api_key) return;
|
|
55180
|
-
|
|
55172
|
+
let n = {};
|
|
55173
|
+
t.transformer && Object.keys(t.transformer).forEach((o) => {
|
|
55174
|
+
o === "use" ? Array.isArray(t.transformer.use) && (n.use = t.transformer.use.map((r) => {
|
|
55175
|
+
if (Array.isArray(r) && typeof r[0] == "string") {
|
|
55176
|
+
let l = this.transformerService.getTransformer(r[0]);
|
|
55177
|
+
if (l) return new l(r[1]);
|
|
55178
|
+
}
|
|
55179
|
+
if (typeof r == "string") return this.transformerService.getTransformer(r);
|
|
55180
|
+
}).filter((r) => typeof r < "u")) : Array.isArray(t.transformer[o]?.use) && (n[o] = { use: t.transformer[o].use.map((r) => {
|
|
55181
|
+
if (Array.isArray(r) && typeof r[0] == "string") {
|
|
55182
|
+
let l = this.transformerService.getTransformer(r[0]);
|
|
55183
|
+
if (l) return new l(r[1]);
|
|
55184
|
+
}
|
|
55185
|
+
if (typeof r == "string") return this.transformerService.getTransformer(r);
|
|
55186
|
+
}).filter((r) => typeof r < "u") });
|
|
55187
|
+
}), console.log("providerConfig: ", t.name, n.use), this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: t.transformer ? n : void 0 }), p(`${t.name} provider registered`);
|
|
55181
55188
|
} catch (n) {
|
|
55182
|
-
|
|
55189
|
+
p(`${t.name} provider registered error: ${n}`);
|
|
55183
55190
|
}
|
|
55184
55191
|
});
|
|
55185
55192
|
}
|
|
@@ -55204,32 +55211,31 @@ var J = class {
|
|
|
55204
55211
|
let l = `${n.id},${r}`;
|
|
55205
55212
|
this.modelRoutes.delete(l), this.modelRoutes.delete(r);
|
|
55206
55213
|
}), t.models.forEach((r) => {
|
|
55207
|
-
let l = `${n.
|
|
55214
|
+
let l = `${n.name},${r}`, u = { provider: n.name, model: r, fullModel: l };
|
|
55208
55215
|
this.modelRoutes.set(l, u), this.modelRoutes.has(r) || this.modelRoutes.set(r, u);
|
|
55209
55216
|
})), o;
|
|
55210
55217
|
}
|
|
55211
55218
|
deleteProvider(e) {
|
|
55212
55219
|
let t = this.providers.get(e);
|
|
55213
55220
|
return t ? (t.models.forEach((n) => {
|
|
55214
|
-
let o = `${t.
|
|
55221
|
+
let o = `${t.name},${n}`;
|
|
55215
55222
|
this.modelRoutes.delete(o), this.modelRoutes.delete(n);
|
|
55216
55223
|
}), this.providers.delete(e), true) : false;
|
|
55217
55224
|
}
|
|
55218
55225
|
toggleProvider(e, t) {
|
|
55219
|
-
|
|
55220
|
-
return n ? (n.enabled = t, n.updatedAt = /* @__PURE__ */ new Date(), true) : false;
|
|
55226
|
+
return !!this.providers.get(e);
|
|
55221
55227
|
}
|
|
55222
55228
|
resolveModelRoute(e) {
|
|
55223
55229
|
let t = this.modelRoutes.get(e);
|
|
55224
55230
|
if (!t) return null;
|
|
55225
|
-
let n = this.providers.get(t.
|
|
55226
|
-
return
|
|
55231
|
+
let n = this.providers.get(t.provider);
|
|
55232
|
+
return n ? { provider: n, originalModel: e, targetModel: t.model } : null;
|
|
55227
55233
|
}
|
|
55228
55234
|
getAvailableModelNames() {
|
|
55229
55235
|
let e = [];
|
|
55230
55236
|
return this.providers.forEach((t) => {
|
|
55231
|
-
t.
|
|
55232
|
-
e.push(n), e.push(`${t.
|
|
55237
|
+
t.models.forEach((n) => {
|
|
55238
|
+
e.push(n), e.push(`${t.name},${n}`);
|
|
55233
55239
|
});
|
|
55234
55240
|
}), e;
|
|
55235
55241
|
}
|
|
@@ -55248,17 +55254,17 @@ var J = class {
|
|
|
55248
55254
|
async getAvailableModels() {
|
|
55249
55255
|
let e = [];
|
|
55250
55256
|
return this.providers.forEach((t) => {
|
|
55251
|
-
t.
|
|
55252
|
-
e.push({ id: n, object: "model",
|
|
55257
|
+
t.models.forEach((n) => {
|
|
55258
|
+
e.push({ id: n, object: "model", owned_by: t.name, provider: t.name }), e.push({ id: `${t.name},${n}`, object: "model", owned_by: t.name, provider: t.name });
|
|
55253
55259
|
});
|
|
55254
55260
|
}), { object: "list", data: e };
|
|
55255
55261
|
}
|
|
55256
55262
|
};
|
|
55257
|
-
var
|
|
55263
|
+
var F = class {
|
|
55258
55264
|
name = "Anthropic";
|
|
55259
55265
|
endPoint = "/v1/messages";
|
|
55260
55266
|
transformRequestOut(e) {
|
|
55261
|
-
|
|
55267
|
+
p("Anthropic Request:", JSON.stringify(e, null, 2));
|
|
55262
55268
|
let t = [];
|
|
55263
55269
|
if (e.system) {
|
|
55264
55270
|
if (typeof e.system == "string") t.push({ role: "system", content: e.system });
|
|
@@ -55274,17 +55280,17 @@ var M = class {
|
|
|
55274
55280
|
else if (Array.isArray(r.content)) {
|
|
55275
55281
|
if (r.role === "user") {
|
|
55276
55282
|
let d = r.content.filter((c) => c.type === "tool_result" && c.tool_use_id);
|
|
55277
|
-
d.length && d.forEach((c,
|
|
55278
|
-
let
|
|
55279
|
-
t.push(
|
|
55283
|
+
d.length && d.forEach((c, h) => {
|
|
55284
|
+
let g = { role: "tool", content: typeof c.content == "string" ? c.content : JSON.stringify(c.content), tool_call_id: c.tool_use_id, cache_control: c.cache_control };
|
|
55285
|
+
t.push(g);
|
|
55280
55286
|
});
|
|
55281
|
-
let
|
|
55282
|
-
|
|
55287
|
+
let i = r.content.filter((c) => c.type === "text" && c.text);
|
|
55288
|
+
i.length && t.push({ role: "user", content: i });
|
|
55283
55289
|
} else if (r.role === "assistant") {
|
|
55284
55290
|
let d = r.content.filter((c) => c.type === "text" && c.text);
|
|
55285
55291
|
d.length && t.push(...d.map((c) => ({ role: "assistant", content: c.text })));
|
|
55286
|
-
let
|
|
55287
|
-
|
|
55292
|
+
let i = r.content.filter((c) => c.type === "tool_use" && c.id);
|
|
55293
|
+
i.length && t.push({ role: "assistant", content: null, tool_calls: i.map((c) => ({ id: c.id, type: "function", function: { name: c.name, arguments: JSON.stringify(c.input || {}) } })) });
|
|
55288
55294
|
}
|
|
55289
55295
|
return;
|
|
55290
55296
|
}
|
|
@@ -55306,148 +55312,148 @@ var M = class {
|
|
|
55306
55312
|
}
|
|
55307
55313
|
async convertOpenAIStreamToAnthropic(e) {
|
|
55308
55314
|
return new ReadableStream({ async start(n) {
|
|
55309
|
-
let o = new TextEncoder(), r = `msg_${Date.now()}`, l = "unknown", u = false, d = false,
|
|
55315
|
+
let o = new TextEncoder(), r = `msg_${Date.now()}`, l = "unknown", u = false, d = false, i = false, c = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = 0, m = 0, f = 0, s = false, _ = false, y = 0, v = (x) => {
|
|
55310
55316
|
if (!s) try {
|
|
55311
|
-
n.enqueue(
|
|
55312
|
-
let
|
|
55313
|
-
|
|
55314
|
-
} catch (
|
|
55315
|
-
if (
|
|
55316
|
-
else throw
|
|
55317
|
-
}
|
|
55318
|
-
},
|
|
55317
|
+
n.enqueue(x);
|
|
55318
|
+
let C = new TextDecoder().decode(x);
|
|
55319
|
+
p("send data:", C.trim());
|
|
55320
|
+
} catch (C) {
|
|
55321
|
+
if (C instanceof TypeError && C.message.includes("Controller is already closed")) s = true;
|
|
55322
|
+
else throw p(`send data error: ${C.message}`), C;
|
|
55323
|
+
}
|
|
55324
|
+
}, z = () => {
|
|
55319
55325
|
if (!s) try {
|
|
55320
55326
|
n.close(), s = true;
|
|
55321
|
-
} catch (
|
|
55322
|
-
if (
|
|
55323
|
-
else throw
|
|
55327
|
+
} catch (x) {
|
|
55328
|
+
if (x instanceof TypeError && x.message.includes("Controller is already closed")) s = true;
|
|
55329
|
+
else throw x;
|
|
55324
55330
|
}
|
|
55325
|
-
},
|
|
55331
|
+
}, M = null;
|
|
55326
55332
|
try {
|
|
55327
|
-
|
|
55328
|
-
let
|
|
55333
|
+
M = e.getReader();
|
|
55334
|
+
let x = new TextDecoder(), C = "";
|
|
55329
55335
|
for (; !s; ) {
|
|
55330
|
-
let { done:
|
|
55331
|
-
if (
|
|
55332
|
-
|
|
55333
|
-
let
|
|
55336
|
+
let { done: oe, value: re } = await M.read();
|
|
55337
|
+
if (oe) break;
|
|
55338
|
+
C += x.decode(re, { stream: true });
|
|
55339
|
+
let K = C.split(`
|
|
55334
55340
|
`);
|
|
55335
|
-
|
|
55336
|
-
for (let
|
|
55337
|
-
if (s ||
|
|
55338
|
-
if (!
|
|
55339
|
-
let
|
|
55340
|
-
if (
|
|
55341
|
-
let
|
|
55342
|
-
if (
|
|
55341
|
+
C = K.pop() || "";
|
|
55342
|
+
for (let Y of K) {
|
|
55343
|
+
if (s || i) break;
|
|
55344
|
+
if (!Y.startsWith("data: ")) continue;
|
|
55345
|
+
let B = Y.slice(6);
|
|
55346
|
+
if (B !== "[DONE]") try {
|
|
55347
|
+
let P = JSON.parse(B);
|
|
55348
|
+
if (g++, p("Original Response:", JSON.stringify(P, null, 2)), l = P.model || l, !u && !s && !i) {
|
|
55343
55349
|
u = true;
|
|
55344
|
-
let
|
|
55345
|
-
|
|
55346
|
-
data: ${JSON.stringify(
|
|
55350
|
+
let k = { type: "message_start", message: { id: r, type: "message", role: "assistant", content: [], model: l, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
|
|
55351
|
+
v(o.encode(`event: message_start
|
|
55352
|
+
data: ${JSON.stringify(k)}
|
|
55347
55353
|
|
|
55348
55354
|
`));
|
|
55349
55355
|
}
|
|
55350
|
-
let
|
|
55351
|
-
if (!
|
|
55352
|
-
if (
|
|
55353
|
-
if (!
|
|
55354
|
-
let
|
|
55355
|
-
|
|
55356
|
-
data: ${JSON.stringify(
|
|
55357
|
-
|
|
55358
|
-
`)),
|
|
55356
|
+
let S = P.choices?.[0];
|
|
55357
|
+
if (!S) continue;
|
|
55358
|
+
if (S?.delta?.thinking && !s && !i) {
|
|
55359
|
+
if (!_) {
|
|
55360
|
+
let k = { type: "content_block_start", index: y, content_block: { type: "thinking", thinking: "" } };
|
|
55361
|
+
v(o.encode(`event: content_block_start
|
|
55362
|
+
data: ${JSON.stringify(k)}
|
|
55363
|
+
|
|
55364
|
+
`)), _ = true;
|
|
55359
55365
|
}
|
|
55360
|
-
if (
|
|
55361
|
-
let
|
|
55362
|
-
|
|
55363
|
-
data: ${JSON.stringify(
|
|
55366
|
+
if (S.delta.thinking.signature) {
|
|
55367
|
+
let k = { type: "content_block_delta", index: y, delta: { type: "signature_delta", signature: S.delta.thinking.signature } };
|
|
55368
|
+
v(o.encode(`event: content_block_delta
|
|
55369
|
+
data: ${JSON.stringify(k)}
|
|
55364
55370
|
|
|
55365
55371
|
`));
|
|
55366
|
-
let
|
|
55367
|
-
|
|
55368
|
-
data: ${JSON.stringify(_)}
|
|
55369
|
-
|
|
55370
|
-
`)), g++;
|
|
55371
|
-
} else if (P.delta.thinking.content) {
|
|
55372
|
-
let b = { type: "content_block_delta", index: g, delta: { type: "thinking_delta", thinking: P.delta.thinking.content || "" } };
|
|
55373
|
-
k(o.encode(`event: content_block_delta
|
|
55372
|
+
let b = { type: "content_block_stop", index: y };
|
|
55373
|
+
v(o.encode(`event: content_block_stop
|
|
55374
55374
|
data: ${JSON.stringify(b)}
|
|
55375
55375
|
|
|
55376
|
+
`)), y++;
|
|
55377
|
+
} else if (S.delta.thinking.content) {
|
|
55378
|
+
let k = { type: "content_block_delta", index: y, delta: { type: "thinking_delta", thinking: S.delta.thinking.content || "" } };
|
|
55379
|
+
v(o.encode(`event: content_block_delta
|
|
55380
|
+
data: ${JSON.stringify(k)}
|
|
55381
|
+
|
|
55376
55382
|
`));
|
|
55377
55383
|
}
|
|
55378
55384
|
}
|
|
55379
|
-
if (
|
|
55380
|
-
if (
|
|
55385
|
+
if (S?.delta?.content && !s && !i) {
|
|
55386
|
+
if (m++, !d && !i) {
|
|
55381
55387
|
d = true;
|
|
55382
|
-
let
|
|
55383
|
-
|
|
55384
|
-
data: ${JSON.stringify(
|
|
55388
|
+
let k = { type: "content_block_start", index: y, content_block: { type: "text", text: "" } };
|
|
55389
|
+
v(o.encode(`event: content_block_start
|
|
55390
|
+
data: ${JSON.stringify(k)}
|
|
55385
55391
|
|
|
55386
55392
|
`));
|
|
55387
55393
|
}
|
|
55388
|
-
if (!s && !
|
|
55389
|
-
let
|
|
55390
|
-
|
|
55391
|
-
data: ${JSON.stringify(
|
|
55394
|
+
if (!s && !i) {
|
|
55395
|
+
let k = { type: "content_block_delta", index: y, delta: { type: "text_delta", text: S.delta.content } };
|
|
55396
|
+
v(o.encode(`event: content_block_delta
|
|
55397
|
+
data: ${JSON.stringify(k)}
|
|
55392
55398
|
|
|
55393
55399
|
`));
|
|
55394
55400
|
}
|
|
55395
55401
|
}
|
|
55396
|
-
if (
|
|
55397
|
-
|
|
55398
|
-
let
|
|
55399
|
-
for (let
|
|
55402
|
+
if (S?.delta?.tool_calls && !s && !i) {
|
|
55403
|
+
f++;
|
|
55404
|
+
let k = /* @__PURE__ */ new Set();
|
|
55405
|
+
for (let b of S.delta.tool_calls) {
|
|
55400
55406
|
if (s) break;
|
|
55401
|
-
let R =
|
|
55402
|
-
if (
|
|
55403
|
-
if (
|
|
55404
|
-
let
|
|
55405
|
-
if (
|
|
55406
|
-
|
|
55407
|
-
let
|
|
55408
|
-
|
|
55409
|
-
data: ${JSON.stringify(
|
|
55410
|
-
|
|
55411
|
-
`)),
|
|
55407
|
+
let R = b.index ?? 0;
|
|
55408
|
+
if (k.has(R)) continue;
|
|
55409
|
+
if (k.add(R), !h.has(R)) {
|
|
55410
|
+
let T = d ? h.size + 1 : h.size;
|
|
55411
|
+
if (T !== 0) {
|
|
55412
|
+
p("content_block_stop2");
|
|
55413
|
+
let se = { type: "content_block_stop", index: y };
|
|
55414
|
+
v(o.encode(`event: content_block_stop
|
|
55415
|
+
data: ${JSON.stringify(se)}
|
|
55416
|
+
|
|
55417
|
+
`)), y++;
|
|
55412
55418
|
}
|
|
55413
|
-
|
|
55414
|
-
let E =
|
|
55415
|
-
|
|
55419
|
+
h.set(R, T);
|
|
55420
|
+
let E = b.id || `call_${Date.now()}_${R}`, w = b.function?.name || `tool_${R}`, O = { type: "content_block_start", index: y, content_block: { type: "tool_use", id: E, name: w, input: {} } };
|
|
55421
|
+
v(o.encode(`event: content_block_start
|
|
55416
55422
|
data: ${JSON.stringify(O)}
|
|
55417
55423
|
|
|
55418
55424
|
`));
|
|
55419
|
-
let L = { id: E, name: w, arguments: "", contentBlockIndex:
|
|
55425
|
+
let L = { id: E, name: w, arguments: "", contentBlockIndex: T };
|
|
55420
55426
|
c.set(R, L);
|
|
55421
|
-
} else if (
|
|
55422
|
-
let
|
|
55423
|
-
|
|
55427
|
+
} else if (b.id && b.function?.name) {
|
|
55428
|
+
let T = c.get(R);
|
|
55429
|
+
T.id.startsWith("call_") && T.name.startsWith("tool_") && (T.id = b.id, T.name = b.function.name);
|
|
55424
55430
|
}
|
|
55425
|
-
if (
|
|
55426
|
-
if (
|
|
55431
|
+
if (b.function?.arguments && !s && !i) {
|
|
55432
|
+
if (h.get(R) === void 0) continue;
|
|
55427
55433
|
let E = c.get(R);
|
|
55428
55434
|
if (E) {
|
|
55429
|
-
E.arguments +=
|
|
55435
|
+
E.arguments += b.function.arguments;
|
|
55430
55436
|
try {
|
|
55431
55437
|
let w = null, O = E.arguments.trim();
|
|
55432
55438
|
if (O.startsWith("{") && O.endsWith("}")) try {
|
|
55433
55439
|
w = JSON.parse(O);
|
|
55434
55440
|
} catch (L) {
|
|
55435
|
-
|
|
55441
|
+
p("Tool call index:", R, "error", L.message);
|
|
55436
55442
|
}
|
|
55437
55443
|
} catch (w) {
|
|
55438
|
-
|
|
55444
|
+
p("Tool call index:", R, "error", w.message);
|
|
55439
55445
|
}
|
|
55440
55446
|
}
|
|
55441
55447
|
try {
|
|
55442
|
-
let w = { type: "content_block_delta", index:
|
|
55443
|
-
|
|
55448
|
+
let w = { type: "content_block_delta", index: y, delta: { type: "input_json_delta", partial_json: b.function.arguments } };
|
|
55449
|
+
v(o.encode(`event: content_block_delta
|
|
55444
55450
|
data: ${JSON.stringify(w)}
|
|
55445
55451
|
|
|
55446
55452
|
`));
|
|
55447
55453
|
} catch {
|
|
55448
55454
|
try {
|
|
55449
|
-
let O =
|
|
55450
|
-
|
|
55455
|
+
let O = b.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), L = { type: "content_block_delta", index: y, delta: { type: "input_json_delta", partial_json: O } };
|
|
55456
|
+
v(o.encode(`event: content_block_delta
|
|
55451
55457
|
data: ${JSON.stringify(L)}
|
|
55452
55458
|
|
|
55453
55459
|
`));
|
|
@@ -55458,56 +55464,56 @@ data: ${JSON.stringify(L)}
|
|
|
55458
55464
|
}
|
|
55459
55465
|
}
|
|
55460
55466
|
}
|
|
55461
|
-
if (
|
|
55462
|
-
if (
|
|
55463
|
-
|
|
55464
|
-
let
|
|
55465
|
-
|
|
55466
|
-
data: ${JSON.stringify(
|
|
55467
|
+
if (S?.finish_reason && !s && !i) {
|
|
55468
|
+
if (i = true, m === 0 && f === 0 && console.error("Warning: No content in the stream response!"), (d || f > 0) && !s) {
|
|
55469
|
+
p("content_block_stop hasTextContentStarted");
|
|
55470
|
+
let k = { type: "content_block_stop", index: y };
|
|
55471
|
+
v(o.encode(`event: content_block_stop
|
|
55472
|
+
data: ${JSON.stringify(k)}
|
|
55467
55473
|
|
|
55468
55474
|
`));
|
|
55469
55475
|
}
|
|
55470
55476
|
if (!s) {
|
|
55471
|
-
let R = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[
|
|
55472
|
-
|
|
55477
|
+
let R = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[S.finish_reason] || "end_turn", stop_sequence: null }, usage: { input_tokens: P.usage?.prompt_tokens || 0, output_tokens: P.usage?.completion_tokens || 0 } };
|
|
55478
|
+
v(o.encode(`event: message_delta
|
|
55473
55479
|
data: ${JSON.stringify(R)}
|
|
55474
55480
|
|
|
55475
55481
|
`));
|
|
55476
55482
|
}
|
|
55477
55483
|
if (!s) {
|
|
55478
|
-
let
|
|
55479
|
-
|
|
55480
|
-
data: ${JSON.stringify(
|
|
55484
|
+
let k = { type: "message_stop" };
|
|
55485
|
+
v(o.encode(`event: message_stop
|
|
55486
|
+
data: ${JSON.stringify(k)}
|
|
55481
55487
|
|
|
55482
55488
|
`));
|
|
55483
55489
|
}
|
|
55484
55490
|
break;
|
|
55485
55491
|
}
|
|
55486
|
-
} catch (
|
|
55487
|
-
|
|
55492
|
+
} catch (P) {
|
|
55493
|
+
p(`parseError: ${P.name} message: ${P.message} stack: ${P.stack} data: ${B}`);
|
|
55488
55494
|
}
|
|
55489
55495
|
}
|
|
55490
55496
|
}
|
|
55491
|
-
|
|
55492
|
-
} catch (
|
|
55497
|
+
z();
|
|
55498
|
+
} catch (x) {
|
|
55493
55499
|
if (!s) try {
|
|
55494
|
-
n.error(
|
|
55495
|
-
} catch (
|
|
55496
|
-
console.error(
|
|
55500
|
+
n.error(x);
|
|
55501
|
+
} catch (C) {
|
|
55502
|
+
console.error(C);
|
|
55497
55503
|
}
|
|
55498
55504
|
} finally {
|
|
55499
|
-
if (
|
|
55500
|
-
|
|
55501
|
-
} catch (
|
|
55502
|
-
console.error(
|
|
55505
|
+
if (M) try {
|
|
55506
|
+
M.releaseLock();
|
|
55507
|
+
} catch (x) {
|
|
55508
|
+
console.error(x);
|
|
55503
55509
|
}
|
|
55504
55510
|
}
|
|
55505
55511
|
}, cancel(n) {
|
|
55506
|
-
|
|
55512
|
+
p("cancle stream:", n);
|
|
55507
55513
|
} });
|
|
55508
55514
|
}
|
|
55509
55515
|
convertOpenAIResponseToAnthropic(e) {
|
|
55510
|
-
|
|
55516
|
+
p("Original OpenAI response:", JSON.stringify(e, null, 2));
|
|
55511
55517
|
let t = e.choices[0];
|
|
55512
55518
|
if (!t) throw new Error("No choices found in OpenAI response");
|
|
55513
55519
|
let n = [];
|
|
@@ -55522,10 +55528,10 @@ data: ${JSON.stringify(b)}
|
|
|
55522
55528
|
n.push({ type: "tool_use", id: r.id, name: r.function.name, input: u });
|
|
55523
55529
|
});
|
|
55524
55530
|
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 } };
|
|
55525
|
-
return
|
|
55531
|
+
return p("Conversion complete, final Anthropic response:", JSON.stringify(o, null, 2)), o;
|
|
55526
55532
|
}
|
|
55527
55533
|
};
|
|
55528
|
-
var
|
|
55534
|
+
var I = class {
|
|
55529
55535
|
name = "gemini";
|
|
55530
55536
|
endPoint = "/v1beta/models/:modelAndAction";
|
|
55531
55537
|
transformRequestIn(e, t) {
|
|
@@ -55541,14 +55547,14 @@ var N = class {
|
|
|
55541
55547
|
}), { 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 } } };
|
|
55542
55548
|
}
|
|
55543
55549
|
transformRequestOut(e) {
|
|
55544
|
-
let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens, l = e.temperature, u = e.stream, d = e.tool_choice,
|
|
55550
|
+
let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens, l = e.temperature, u = e.stream, d = e.tool_choice, i = { messages: [], model: o, max_tokens: r, temperature: l, stream: u, tool_choice: d };
|
|
55545
55551
|
return Array.isArray(t) && t.forEach((c) => {
|
|
55546
|
-
typeof c == "string" ?
|
|
55547
|
-
}), Array.isArray(n) && (
|
|
55548
|
-
Array.isArray(c.functionDeclarations) && c.functionDeclarations.forEach((
|
|
55549
|
-
|
|
55552
|
+
typeof c == "string" ? i.messages.push({ role: "user", content: c }) : typeof c.text == "string" ? i.messages.push({ role: "user", content: c.text || null }) : c.role === "user" ? i.messages.push({ role: "user", content: c?.parts?.map((h) => ({ type: "text", text: h.text || "" })) || [] }) : c.role === "model" && i.messages.push({ role: "assistant", content: c?.parts?.map((h) => ({ type: "text", text: h.text || "" })) || [] });
|
|
55553
|
+
}), Array.isArray(n) && (i.tools = [], n.forEach((c) => {
|
|
55554
|
+
Array.isArray(c.functionDeclarations) && c.functionDeclarations.forEach((h) => {
|
|
55555
|
+
i.tools.push({ type: "function", function: { name: h.name, description: h.description, parameters: h.parameters } });
|
|
55550
55556
|
});
|
|
55551
|
-
})),
|
|
55557
|
+
})), i;
|
|
55552
55558
|
}
|
|
55553
55559
|
async transformResponseOut(e) {
|
|
55554
55560
|
if (e.headers.get("Content-Type")?.includes("application/json")) {
|
|
@@ -55563,13 +55569,13 @@ var N = class {
|
|
|
55563
55569
|
for (; ; ) {
|
|
55564
55570
|
let { done: u, value: d } = await l.read();
|
|
55565
55571
|
if (u) break;
|
|
55566
|
-
let
|
|
55567
|
-
if (
|
|
55572
|
+
let i = t.decode(d, { stream: true });
|
|
55573
|
+
if (i.startsWith("data: ")) i = i.slice(6).trim();
|
|
55568
55574
|
else break;
|
|
55569
|
-
|
|
55570
|
-
let c =
|
|
55571
|
-
`), tool_calls: c.length > 0 ? c : void 0 }, finish_reason:
|
|
55572
|
-
|
|
55575
|
+
p("gemini chunk:", i), i = JSON.parse(i);
|
|
55576
|
+
let c = i.candidates[0].content.parts.filter((g) => g.functionCall).map((g) => ({ id: g.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: g.functionCall?.name, arguments: JSON.stringify(g.functionCall?.args || {}) } })), h = { choices: [{ delta: { role: "assistant", content: i.candidates[0].content.parts.filter((g) => g.text).map((g) => g.text).join(`
|
|
55577
|
+
`), tool_calls: c.length > 0 ? c : void 0 }, finish_reason: i.candidates[0].finishReason?.toLowerCase() || null, index: i.candidates[0].index || c.length > 0 ? 1 : 0, logprobs: null }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), id: i.responseId || "", model: i.modelVersion || "", object: "chat.completion.chunk", system_fingerprint: "fp_a49d71b8a1" };
|
|
55578
|
+
p("gemini response:", JSON.stringify(h, null, 2)), r.enqueue(n.encode(`data: ${JSON.stringify(h)}
|
|
55573
55579
|
|
|
55574
55580
|
`));
|
|
55575
55581
|
}
|
|
@@ -55584,7 +55590,7 @@ var N = class {
|
|
|
55584
55590
|
return e;
|
|
55585
55591
|
}
|
|
55586
55592
|
};
|
|
55587
|
-
var
|
|
55593
|
+
var j = class {
|
|
55588
55594
|
name = "deepseek";
|
|
55589
55595
|
transformRequestIn(e) {
|
|
55590
55596
|
return e.max_tokens && e.max_tokens > 8192 && (e.max_tokens = 8192), e;
|
|
@@ -55599,52 +55605,52 @@ var H = class {
|
|
|
55599
55605
|
let d = e.body.getReader();
|
|
55600
55606
|
try {
|
|
55601
55607
|
for (; ; ) {
|
|
55602
|
-
let { done:
|
|
55603
|
-
if (
|
|
55604
|
-
let
|
|
55608
|
+
let { done: i, value: c } = await d.read();
|
|
55609
|
+
if (i) break;
|
|
55610
|
+
let g = t.decode(c, { stream: true }).split(`
|
|
55605
55611
|
`);
|
|
55606
|
-
for (let
|
|
55607
|
-
let
|
|
55608
|
-
if (
|
|
55609
|
-
o +=
|
|
55610
|
-
let s = { ...
|
|
55612
|
+
for (let m of g) if (m.startsWith("data: ") && m.trim() !== "data: [DONE]") try {
|
|
55613
|
+
let f = JSON.parse(m.slice(6));
|
|
55614
|
+
if (f.choices?.[0]?.delta?.reasoning_content) {
|
|
55615
|
+
o += f.choices[0].delta.reasoning_content;
|
|
55616
|
+
let s = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, thinking: { content: f.choices[0].delta.reasoning_content } } }] };
|
|
55611
55617
|
delete s.choices[0].delta.reasoning_content;
|
|
55612
|
-
let
|
|
55618
|
+
let _ = `data: ${JSON.stringify(s)}
|
|
55613
55619
|
|
|
55614
55620
|
`;
|
|
55615
|
-
u.enqueue(n.encode(
|
|
55621
|
+
u.enqueue(n.encode(_));
|
|
55616
55622
|
continue;
|
|
55617
55623
|
}
|
|
55618
|
-
if (
|
|
55624
|
+
if (f.choices?.[0]?.delta?.content && o && !r) {
|
|
55619
55625
|
r = true;
|
|
55620
|
-
let s = Date.now().toString(),
|
|
55621
|
-
delete
|
|
55622
|
-
let
|
|
55626
|
+
let s = Date.now().toString(), _ = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, content: null, thinking: { content: o, signature: s } } }] };
|
|
55627
|
+
delete _.choices[0].delta.reasoning_content;
|
|
55628
|
+
let y = `data: ${JSON.stringify(_)}
|
|
55623
55629
|
|
|
55624
55630
|
`;
|
|
55625
|
-
u.enqueue(n.encode(
|
|
55631
|
+
u.enqueue(n.encode(y));
|
|
55626
55632
|
}
|
|
55627
|
-
if (
|
|
55628
|
-
r &&
|
|
55629
|
-
let s = `data: ${JSON.stringify(
|
|
55633
|
+
if (f.choices[0]?.delta?.reasoning_content && delete f.choices[0].delta.reasoning_content, f.choices?.[0]?.delta && Object.keys(f.choices[0].delta).length > 0) {
|
|
55634
|
+
r && f.choices[0].index++;
|
|
55635
|
+
let s = `data: ${JSON.stringify(f)}
|
|
55630
55636
|
|
|
55631
55637
|
`;
|
|
55632
55638
|
u.enqueue(n.encode(s));
|
|
55633
55639
|
}
|
|
55634
55640
|
} catch {
|
|
55635
|
-
u.enqueue(n.encode(
|
|
55641
|
+
u.enqueue(n.encode(m + `
|
|
55636
55642
|
`));
|
|
55637
55643
|
}
|
|
55638
|
-
else u.enqueue(n.encode(
|
|
55644
|
+
else u.enqueue(n.encode(m + `
|
|
55639
55645
|
`));
|
|
55640
55646
|
}
|
|
55641
|
-
} catch (
|
|
55642
|
-
u.error(
|
|
55647
|
+
} catch (i) {
|
|
55648
|
+
u.error(i);
|
|
55643
55649
|
} finally {
|
|
55644
55650
|
try {
|
|
55645
55651
|
d.releaseLock();
|
|
55646
|
-
} catch (
|
|
55647
|
-
console.error("Error releasing reader lock:",
|
|
55652
|
+
} catch (i) {
|
|
55653
|
+
console.error("Error releasing reader lock:", i);
|
|
55648
55654
|
}
|
|
55649
55655
|
u.close();
|
|
55650
55656
|
}
|
|
@@ -55654,7 +55660,7 @@ var H = class {
|
|
|
55654
55660
|
return e;
|
|
55655
55661
|
}
|
|
55656
55662
|
};
|
|
55657
|
-
var
|
|
55663
|
+
var q = class {
|
|
55658
55664
|
name = "tooluse";
|
|
55659
55665
|
transformRequestIn(e) {
|
|
55660
55666
|
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.
|
|
@@ -55677,51 +55683,51 @@ Examples:
|
|
|
55677
55683
|
let d = e.body.getReader();
|
|
55678
55684
|
try {
|
|
55679
55685
|
for (; ; ) {
|
|
55680
|
-
let { done:
|
|
55681
|
-
if (
|
|
55682
|
-
let
|
|
55686
|
+
let { done: i, value: c } = await d.read();
|
|
55687
|
+
if (i) break;
|
|
55688
|
+
let g = t.decode(c, { stream: true }).split(`
|
|
55683
55689
|
`);
|
|
55684
|
-
for (let
|
|
55685
|
-
let
|
|
55686
|
-
if (
|
|
55687
|
-
let s =
|
|
55690
|
+
for (let m of g) if (m.startsWith("data: ") && m.trim() !== "data: [DONE]") try {
|
|
55691
|
+
let f = JSON.parse(m.slice(6));
|
|
55692
|
+
if (f.choices[0]?.delta?.tool_calls?.length) {
|
|
55693
|
+
let s = f.choices[0].delta.tool_calls[0];
|
|
55688
55694
|
if (s.function?.name === "ExitTool") {
|
|
55689
55695
|
o = s.index;
|
|
55690
55696
|
continue;
|
|
55691
55697
|
} else if (o > -1 && s.index === o && s.function.arguments) {
|
|
55692
55698
|
r += s.function.arguments;
|
|
55693
55699
|
try {
|
|
55694
|
-
let
|
|
55695
|
-
|
|
55696
|
-
let
|
|
55700
|
+
let _ = JSON.parse(r);
|
|
55701
|
+
f.choices = [{ delta: { role: "assistant", content: _.response || "" } }];
|
|
55702
|
+
let y = `data: ${JSON.stringify(f)}
|
|
55697
55703
|
|
|
55698
55704
|
`;
|
|
55699
|
-
u.enqueue(n.encode(
|
|
55705
|
+
u.enqueue(n.encode(y));
|
|
55700
55706
|
} catch {
|
|
55701
55707
|
}
|
|
55702
55708
|
continue;
|
|
55703
55709
|
}
|
|
55704
55710
|
}
|
|
55705
|
-
if (
|
|
55706
|
-
let s = `data: ${JSON.stringify(
|
|
55711
|
+
if (f.choices?.[0]?.delta && Object.keys(f.choices[0].delta).length > 0) {
|
|
55712
|
+
let s = `data: ${JSON.stringify(f)}
|
|
55707
55713
|
|
|
55708
55714
|
`;
|
|
55709
55715
|
u.enqueue(n.encode(s));
|
|
55710
55716
|
}
|
|
55711
55717
|
} catch {
|
|
55712
|
-
u.enqueue(n.encode(
|
|
55718
|
+
u.enqueue(n.encode(m + `
|
|
55713
55719
|
`));
|
|
55714
55720
|
}
|
|
55715
|
-
else u.enqueue(n.encode(
|
|
55721
|
+
else u.enqueue(n.encode(m + `
|
|
55716
55722
|
`));
|
|
55717
55723
|
}
|
|
55718
|
-
} catch (
|
|
55719
|
-
u.error(
|
|
55724
|
+
} catch (i) {
|
|
55725
|
+
u.error(i);
|
|
55720
55726
|
} finally {
|
|
55721
55727
|
try {
|
|
55722
55728
|
d.releaseLock();
|
|
55723
|
-
} catch (
|
|
55724
|
-
console.error("Error releasing reader lock:",
|
|
55729
|
+
} catch (i) {
|
|
55730
|
+
console.error("Error releasing reader lock:", i);
|
|
55725
55731
|
}
|
|
55726
55732
|
u.close();
|
|
55727
55733
|
}
|
|
@@ -55731,7 +55737,7 @@ Examples:
|
|
|
55731
55737
|
return e;
|
|
55732
55738
|
}
|
|
55733
55739
|
};
|
|
55734
|
-
var
|
|
55740
|
+
var J = class {
|
|
55735
55741
|
name = "openrouter";
|
|
55736
55742
|
transformRequestIn(e) {
|
|
55737
55743
|
return e.model.includes("claude") || e.messages.forEach((t) => {
|
|
@@ -55747,51 +55753,51 @@ var F = class {
|
|
|
55747
55753
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55748
55754
|
if (!e.body) return e;
|
|
55749
55755
|
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", l = false, u = new ReadableStream({ async start(d) {
|
|
55750
|
-
let
|
|
55756
|
+
let i = e.body.getReader();
|
|
55751
55757
|
try {
|
|
55752
55758
|
for (; ; ) {
|
|
55753
|
-
let { done: c, value:
|
|
55759
|
+
let { done: c, value: h } = await i.read();
|
|
55754
55760
|
if (c) break;
|
|
55755
|
-
let
|
|
55761
|
+
let m = t.decode(h, { stream: true }).split(`
|
|
55756
55762
|
`);
|
|
55757
|
-
for (let
|
|
55758
|
-
let s = JSON.parse(
|
|
55763
|
+
for (let f of m) if (f.startsWith("data: ") && f.trim() !== "data: [DONE]") try {
|
|
55764
|
+
let s = JSON.parse(f.slice(6));
|
|
55759
55765
|
if (s.choices[0]?.delta?.content && !o && (o = true), s.choices?.[0]?.delta?.reasoning) {
|
|
55760
55766
|
r += s.choices[0].delta.reasoning;
|
|
55761
|
-
let
|
|
55762
|
-
delete
|
|
55763
|
-
let
|
|
55767
|
+
let y = { ...s, choices: [{ ...s.choices[0], delta: { ...s.choices[0].delta, thinking: { content: s.choices[0].delta.reasoning } } }] };
|
|
55768
|
+
delete y.choices[0].delta.reasoning;
|
|
55769
|
+
let v = `data: ${JSON.stringify(y)}
|
|
55764
55770
|
|
|
55765
55771
|
`;
|
|
55766
|
-
d.enqueue(n.encode(
|
|
55772
|
+
d.enqueue(n.encode(v));
|
|
55767
55773
|
continue;
|
|
55768
55774
|
}
|
|
55769
55775
|
if (s.choices?.[0]?.delta?.content && r && !l) {
|
|
55770
55776
|
l = true;
|
|
55771
|
-
let
|
|
55772
|
-
delete
|
|
55773
|
-
let
|
|
55777
|
+
let y = Date.now().toString(), v = { ...s, choices: [{ ...s.choices[0], delta: { ...s.choices[0].delta, content: null, thinking: { content: r, signature: y } } }] };
|
|
55778
|
+
delete v.choices[0].delta.reasoning;
|
|
55779
|
+
let z = `data: ${JSON.stringify(v)}
|
|
55774
55780
|
|
|
55775
55781
|
`;
|
|
55776
|
-
d.enqueue(n.encode(
|
|
55782
|
+
d.enqueue(n.encode(z));
|
|
55777
55783
|
}
|
|
55778
55784
|
s.choices[0]?.delta?.reasoning && delete s.choices[0].delta.reasoning, s.choices[0]?.delta?.tool_calls?.length && o && (s.choices[0].index += 1);
|
|
55779
|
-
let
|
|
55785
|
+
let _ = `data: ${JSON.stringify(s)}
|
|
55780
55786
|
|
|
55781
55787
|
`;
|
|
55782
|
-
d.enqueue(n.encode(
|
|
55788
|
+
d.enqueue(n.encode(_));
|
|
55783
55789
|
} catch {
|
|
55784
|
-
d.enqueue(n.encode(
|
|
55790
|
+
d.enqueue(n.encode(f + `
|
|
55785
55791
|
`));
|
|
55786
55792
|
}
|
|
55787
|
-
else d.enqueue(n.encode(
|
|
55793
|
+
else d.enqueue(n.encode(f + `
|
|
55788
55794
|
`));
|
|
55789
55795
|
}
|
|
55790
55796
|
} catch (c) {
|
|
55791
55797
|
d.error(c);
|
|
55792
55798
|
} finally {
|
|
55793
55799
|
try {
|
|
55794
|
-
|
|
55800
|
+
i.releaseLock();
|
|
55795
55801
|
} catch (c) {
|
|
55796
55802
|
console.error("Error releasing reader lock:", c);
|
|
55797
55803
|
}
|
|
@@ -55804,13 +55810,24 @@ var F = class {
|
|
|
55804
55810
|
}
|
|
55805
55811
|
};
|
|
55806
55812
|
var U = class {
|
|
55813
|
+
constructor(e) {
|
|
55814
|
+
this.options = e;
|
|
55815
|
+
this.max_tokens = this.options?.max_tokens;
|
|
55816
|
+
}
|
|
55817
|
+
static TransformerName = "maxtoken";
|
|
55818
|
+
max_tokens;
|
|
55819
|
+
transformRequestIn(e) {
|
|
55820
|
+
return e.max_tokens && e.max_tokens > this.max_tokens && (e.max_tokens = this.max_tokens), e;
|
|
55821
|
+
}
|
|
55822
|
+
};
|
|
55823
|
+
var ne = { AnthropicTransformer: F, GeminiTransformer: I, DeepseekTransformer: j, TooluseTransformer: q, OpenrouterTransformer: J, MaxTokenTransformer: U };
|
|
55824
|
+
var D = class {
|
|
55807
55825
|
constructor(e) {
|
|
55808
55826
|
this.configService = e;
|
|
55809
|
-
this.initialize();
|
|
55810
55827
|
}
|
|
55811
55828
|
transformers = /* @__PURE__ */ new Map();
|
|
55812
55829
|
registerTransformer(e, t) {
|
|
55813
|
-
this.transformers.set(e, t),
|
|
55830
|
+
this.transformers.set(e, t), p(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
|
|
55814
55831
|
}
|
|
55815
55832
|
getTransformer(e) {
|
|
55816
55833
|
return this.transformers.get(e);
|
|
@@ -55838,32 +55855,40 @@ var U = class {
|
|
|
55838
55855
|
}
|
|
55839
55856
|
async registerTransformerFromConfig(e) {
|
|
55840
55857
|
try {
|
|
55841
|
-
|
|
55842
|
-
|
|
55843
|
-
|
|
55844
|
-
|
|
55845
|
-
|
|
55846
|
-
|
|
55858
|
+
let t = import_node_module.default._load;
|
|
55859
|
+
if (import_node_module.default._load = function(n, o, r) {
|
|
55860
|
+
return n === "claude-code-router" ? { log: p } : t.apply(import_node_module.default, arguments);
|
|
55861
|
+
}, e.path) {
|
|
55862
|
+
let n = W(W.resolve(e.path));
|
|
55863
|
+
if (n) {
|
|
55864
|
+
let o = new n(e.options);
|
|
55865
|
+
if (!o.name) throw new Error(`Transformer instance from ${e.path} does not have a name property.`);
|
|
55866
|
+
return this.registerTransformer(o.name, o), true;
|
|
55847
55867
|
}
|
|
55848
55868
|
}
|
|
55849
55869
|
return false;
|
|
55850
55870
|
} catch (t) {
|
|
55851
|
-
return
|
|
55871
|
+
return p(`load transformer (${e.path}) error:`, t.message, t.stack), false;
|
|
55852
55872
|
}
|
|
55853
55873
|
}
|
|
55854
55874
|
async initialize() {
|
|
55855
55875
|
try {
|
|
55856
55876
|
await this.registerDefaultTransformersInternal(), await this.loadFromConfig();
|
|
55857
55877
|
} catch (e) {
|
|
55858
|
-
|
|
55878
|
+
p("TransformerService init error:", e);
|
|
55859
55879
|
}
|
|
55860
55880
|
}
|
|
55861
55881
|
async registerDefaultTransformersInternal() {
|
|
55862
55882
|
try {
|
|
55863
|
-
|
|
55864
|
-
|
|
55883
|
+
Object.values(ne).forEach((e) => {
|
|
55884
|
+
if ("TransformerName" in e && typeof e.TransformerName == "string") this.registerTransformer(e.TransformerName, e);
|
|
55885
|
+
else {
|
|
55886
|
+
let t = new e();
|
|
55887
|
+
this.registerTransformer(t.name, t);
|
|
55888
|
+
}
|
|
55889
|
+
});
|
|
55865
55890
|
} catch (e) {
|
|
55866
|
-
|
|
55891
|
+
p("transformer regist error:", e);
|
|
55867
55892
|
}
|
|
55868
55893
|
}
|
|
55869
55894
|
async loadFromConfig() {
|
|
@@ -55871,18 +55896,20 @@ var U = class {
|
|
|
55871
55896
|
for (let t of e) await this.registerTransformerFromConfig(t);
|
|
55872
55897
|
}
|
|
55873
55898
|
};
|
|
55874
|
-
function
|
|
55875
|
-
let
|
|
55876
|
-
return
|
|
55899
|
+
function pe() {
|
|
55900
|
+
let a = (0, import_fastify.default)({});
|
|
55901
|
+
return a.setErrorHandler(Z), a.register(import_cors.default), a;
|
|
55877
55902
|
}
|
|
55878
|
-
var
|
|
55903
|
+
var G = class {
|
|
55879
55904
|
app;
|
|
55880
55905
|
configService;
|
|
55881
55906
|
llmService;
|
|
55882
55907
|
providerService;
|
|
55883
55908
|
transformerService;
|
|
55884
55909
|
constructor(e = {}) {
|
|
55885
|
-
this.configService = new
|
|
55910
|
+
this.configService = new N(e), this.transformerService = new D(this.configService), this.transformerService.initialize().finally(() => {
|
|
55911
|
+
this.providerService = new $(this.configService, this.transformerService), this.llmService = new H(this.providerService);
|
|
55912
|
+
}), this.app = pe();
|
|
55886
55913
|
}
|
|
55887
55914
|
async register(e, t) {
|
|
55888
55915
|
await this.app.register(e, t);
|
|
@@ -55902,23 +55929,23 @@ var B = class {
|
|
|
55902
55929
|
} catch (r) {
|
|
55903
55930
|
return n.log.error("Error in modelProviderMiddleware:", r), o.code(500).send({ error: "Internal server error" });
|
|
55904
55931
|
}
|
|
55905
|
-
}), this.app.register(
|
|
55932
|
+
}), this.app.register(te);
|
|
55906
55933
|
let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
|
|
55907
|
-
|
|
55934
|
+
p(`\u{1F680} LLMs API server listening on ${e}`);
|
|
55908
55935
|
let t = async (n) => {
|
|
55909
|
-
|
|
55936
|
+
p(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
|
|
55910
55937
|
};
|
|
55911
55938
|
process.on("SIGINT", () => t("SIGINT")), process.on("SIGTERM", () => t("SIGTERM"));
|
|
55912
55939
|
} catch (e) {
|
|
55913
|
-
|
|
55940
|
+
p(`Error starting server: ${e}`), process.exit(1);
|
|
55914
55941
|
}
|
|
55915
55942
|
}
|
|
55916
55943
|
};
|
|
55917
|
-
var
|
|
55944
|
+
var At = G;
|
|
55918
55945
|
|
|
55919
55946
|
// src/server.ts
|
|
55920
55947
|
var createServer = (config) => {
|
|
55921
|
-
const server = new
|
|
55948
|
+
const server = new At(config);
|
|
55922
55949
|
return server;
|
|
55923
55950
|
};
|
|
55924
55951
|
|
|
@@ -55951,15 +55978,15 @@ var getUseModel = (req, tokenCount, config) => {
|
|
|
55951
55978
|
if (req.body.model.includes(",")) {
|
|
55952
55979
|
return req.body.model;
|
|
55953
55980
|
}
|
|
55954
|
-
if (tokenCount > 1e3 * 60) {
|
|
55981
|
+
if (tokenCount > 1e3 * 60 && config.Router.longContext) {
|
|
55955
55982
|
log("Using long context model due to token count:", tokenCount);
|
|
55956
55983
|
return config.Router.longContext;
|
|
55957
55984
|
}
|
|
55958
|
-
if (req.body.model?.startsWith("claude-3-5-haiku")) {
|
|
55985
|
+
if (req.body.model?.startsWith("claude-3-5-haiku") && config.Router.background) {
|
|
55959
55986
|
log("Using background model for ", req.body.model);
|
|
55960
55987
|
return config.Router.background;
|
|
55961
55988
|
}
|
|
55962
|
-
if (req.body.thinking) {
|
|
55989
|
+
if (req.body.thinking && config.Router.think) {
|
|
55963
55990
|
log("Using think model for ", req.body.thinking);
|
|
55964
55991
|
return config.Router.think;
|
|
55965
55992
|
}
|
|
@@ -56237,7 +56264,7 @@ async function executeCodeCommand(args = []) {
|
|
|
56237
56264
|
}
|
|
56238
56265
|
|
|
56239
56266
|
// package.json
|
|
56240
|
-
var version = "1.0.
|
|
56267
|
+
var version = "1.0.16";
|
|
56241
56268
|
|
|
56242
56269
|
// src/cli.ts
|
|
56243
56270
|
var import_child_process2 = require("child_process");
|