@musistudio/claude-code-router 1.0.17 → 1.0.19
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 +96 -2
- package/dist/cli.js +519 -451
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -2150,20 +2150,20 @@ var require_hooks = __commonJS({
|
|
|
2150
2150
|
this.validate(hook, fn);
|
|
2151
2151
|
this[hook].push(fn);
|
|
2152
2152
|
};
|
|
2153
|
-
function buildHooks(
|
|
2153
|
+
function buildHooks(h2) {
|
|
2154
2154
|
const hooks = new Hooks();
|
|
2155
|
-
hooks.onRequest =
|
|
2156
|
-
hooks.preParsing =
|
|
2157
|
-
hooks.preValidation =
|
|
2158
|
-
hooks.preSerialization =
|
|
2159
|
-
hooks.preHandler =
|
|
2160
|
-
hooks.onSend =
|
|
2161
|
-
hooks.onResponse =
|
|
2162
|
-
hooks.onError =
|
|
2163
|
-
hooks.onRoute =
|
|
2164
|
-
hooks.onRegister =
|
|
2165
|
-
hooks.onTimeout =
|
|
2166
|
-
hooks.onRequestAbort =
|
|
2155
|
+
hooks.onRequest = h2.onRequest.slice();
|
|
2156
|
+
hooks.preParsing = h2.preParsing.slice();
|
|
2157
|
+
hooks.preValidation = h2.preValidation.slice();
|
|
2158
|
+
hooks.preSerialization = h2.preSerialization.slice();
|
|
2159
|
+
hooks.preHandler = h2.preHandler.slice();
|
|
2160
|
+
hooks.onSend = h2.onSend.slice();
|
|
2161
|
+
hooks.onResponse = h2.onResponse.slice();
|
|
2162
|
+
hooks.onError = h2.onError.slice();
|
|
2163
|
+
hooks.onRoute = h2.onRoute.slice();
|
|
2164
|
+
hooks.onRegister = h2.onRegister.slice();
|
|
2165
|
+
hooks.onTimeout = h2.onTimeout.slice();
|
|
2166
|
+
hooks.onRequestAbort = h2.onRequestAbort.slice();
|
|
2167
2167
|
hooks.onReady = [];
|
|
2168
2168
|
hooks.onListen = [];
|
|
2169
2169
|
hooks.preClose = [];
|
|
@@ -2782,7 +2782,7 @@ var require_validation = __commonJS({
|
|
|
2782
2782
|
headersSchemaLowerCase[k] = headers[k];
|
|
2783
2783
|
});
|
|
2784
2784
|
if (headersSchemaLowerCase.required instanceof Array) {
|
|
2785
|
-
headersSchemaLowerCase.required = headersSchemaLowerCase.required.map((
|
|
2785
|
+
headersSchemaLowerCase.required = headersSchemaLowerCase.required.map((h2) => h2.toLowerCase());
|
|
2786
2786
|
}
|
|
2787
2787
|
if (headers.properties) {
|
|
2788
2788
|
headersSchemaLowerCase.properties = {};
|
|
@@ -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;
|
|
@@ -13240,10 +13240,10 @@ var require_util = __commonJS({
|
|
|
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;
|
|
@@ -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 });
|
|
@@ -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, p, pr) => {
|
|
24494
|
+
debug("tilde", comp, _, M, m, p, pr);
|
|
24495
24495
|
let ret;
|
|
24496
|
-
if (isX(
|
|
24496
|
+
if (isX(M)) {
|
|
24497
24497
|
ret = "";
|
|
24498
24498
|
} else if (isX(m)) {
|
|
24499
|
-
ret = `>=${
|
|
24499
|
+
ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
|
24500
24500
|
} else if (isX(p)) {
|
|
24501
|
-
ret = `>=${
|
|
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}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
24505
24505
|
} else {
|
|
24506
|
-
ret = `>=${
|
|
24506
|
+
ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
|
|
24507
24507
|
}
|
|
24508
24508
|
debug("tilde return", ret);
|
|
24509
24509
|
return ret;
|
|
@@ -24514,42 +24514,42 @@ var require_range = __commonJS({
|
|
|
24514
24514
|
};
|
|
24515
24515
|
var replaceCaret = (comp, options) => {
|
|
24516
24516
|
debug("caret", comp, options);
|
|
24517
|
-
const r = options.loose ?
|
|
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, p, pr) => {
|
|
24520
|
+
debug("caret", comp, _, M, m, p, pr);
|
|
24521
24521
|
let ret;
|
|
24522
|
-
if (isX(
|
|
24522
|
+
if (isX(M)) {
|
|
24523
24523
|
ret = "";
|
|
24524
24524
|
} else if (isX(m)) {
|
|
24525
|
-
ret = `>=${
|
|
24525
|
+
ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
24526
24526
|
} else if (isX(p)) {
|
|
24527
|
-
if (
|
|
24528
|
-
ret = `>=${
|
|
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}.${p}-${pr} <${M}.${m}.${+p + 1}-0`;
|
|
24537
24537
|
} else {
|
|
24538
|
-
ret = `>=${
|
|
24538
|
+
ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
24539
24539
|
}
|
|
24540
24540
|
} else {
|
|
24541
|
-
ret = `>=${
|
|
24541
|
+
ret = `>=${M}.${m}.${p}-${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}.${p}${z} <${M}.${m}.${+p + 1}-0`;
|
|
24548
24548
|
} else {
|
|
24549
|
-
ret = `>=${
|
|
24549
|
+
ret = `>=${M}.${m}.${p}${z} <${M}.${+m + 1}.0-0`;
|
|
24550
24550
|
}
|
|
24551
24551
|
} else {
|
|
24552
|
-
ret = `>=${
|
|
24552
|
+
ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
|
|
24553
24553
|
}
|
|
24554
24554
|
}
|
|
24555
24555
|
debug("caret return", ret);
|
|
@@ -24562,10 +24562,10 @@ 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, p, pr) => {
|
|
24567
|
+
debug("xRange", comp, ret, gtlt, M, m, p, pr);
|
|
24568
|
+
const xM = isX(M);
|
|
24569
24569
|
const xm = xM || isX(m);
|
|
24570
24570
|
const xp = xm || isX(p);
|
|
24571
24571
|
const anyX = xp;
|
|
@@ -24587,7 +24587,7 @@ var require_range = __commonJS({
|
|
|
24587
24587
|
if (gtlt === ">") {
|
|
24588
24588
|
gtlt = ">=";
|
|
24589
24589
|
if (xm) {
|
|
24590
|
-
|
|
24590
|
+
M = +M + 1;
|
|
24591
24591
|
m = 0;
|
|
24592
24592
|
p = 0;
|
|
24593
24593
|
} else {
|
|
@@ -24597,7 +24597,7 @@ var require_range = __commonJS({
|
|
|
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}.${p}${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();
|
|
@@ -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]";
|
|
@@ -28943,7 +28943,7 @@ var require_route = __commonJS({
|
|
|
28943
28943
|
context.schemaErrorFormatter = opts.schemaErrorFormatter || this[kSchemaErrorFormatter] || context.schemaErrorFormatter;
|
|
28944
28944
|
avvio.once("preReady", () => {
|
|
28945
28945
|
for (const hook of lifecycleHooks) {
|
|
28946
|
-
const toSet = this[kHooks][hook].concat(opts[hook] || []).map((
|
|
28946
|
+
const toSet = this[kHooks][hook].concat(opts[hook] || []).map((h2) => h2.bind(this));
|
|
28947
28947
|
context[hook] = toSet.length ? toSet : null;
|
|
28948
28948
|
}
|
|
28949
28949
|
while (!context.Request[kHasBeenDecorated] && context.Request.parent) {
|
|
@@ -29231,7 +29231,7 @@ var require_fourOhFour = __commonJS({
|
|
|
29231
29231
|
avvio.once("preReady", () => {
|
|
29232
29232
|
const context2 = this[kFourOhFourContext];
|
|
29233
29233
|
for (const hook of lifecycleHooks) {
|
|
29234
|
-
const toSet = this[kHooks][hook].concat(opts[hook] || []).map((
|
|
29234
|
+
const toSet = this[kHooks][hook].concat(opts[hook] || []).map((h2) => h2.bind(this));
|
|
29235
29235
|
context2[hook] = toSet.length ? toSet : null;
|
|
29236
29236
|
}
|
|
29237
29237
|
context2.errorHandler = opts.errorHandler ? buildErrorHandler(this[kErrorHandler], opts.errorHandler) : this[kErrorHandler];
|
|
@@ -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(
|
|
38310
|
-
if (
|
|
38309
|
+
function sameOrigin(A, B2) {
|
|
38310
|
+
if (A.origin === B2.origin && A.origin === "null") {
|
|
38311
38311
|
return true;
|
|
38312
38312
|
}
|
|
38313
|
-
if (
|
|
38313
|
+
if (A.protocol === B2.protocol && A.hostname === B2.hostname && A.port === B2.port) {
|
|
38314
38314
|
return true;
|
|
38315
38315
|
}
|
|
38316
38316
|
return false;
|
|
@@ -50552,8 +50552,8 @@ var require_util5 = __commonJS({
|
|
|
50552
50552
|
var assert = require("node:assert");
|
|
50553
50553
|
var { URLSerializer } = require_data_url();
|
|
50554
50554
|
var { isValidHeaderName } = require_util4();
|
|
50555
|
-
function urlEquals(
|
|
50556
|
-
const serializedA = URLSerializer(
|
|
50555
|
+
function urlEquals(A, B2, excludeFragment = false) {
|
|
50556
|
+
const serializedA = URLSerializer(A, excludeFragment);
|
|
50557
50557
|
const serializedB = URLSerializer(B2, excludeFragment);
|
|
50558
50558
|
return serializedA === serializedB;
|
|
50559
50559
|
}
|
|
@@ -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.6_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,95 +55035,85 @@ 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 h(...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
|
|
55044
|
-
let o = new Error(
|
|
55044
|
+
function L(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
|
-
t.headers && Object.entries(t.headers).forEach(([
|
|
55055
|
-
n.set(
|
|
55055
|
+
t.headers && Object.entries(t.headers).forEach(([d, u]) => {
|
|
55056
|
+
n.set(d, u);
|
|
55056
55057
|
});
|
|
55057
55058
|
let o, r = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
|
|
55058
55059
|
if (t.signal) {
|
|
55059
|
-
let
|
|
55060
|
-
t.signal.addEventListener("abort",
|
|
55060
|
+
let d = new AbortController(), u = () => d.abort();
|
|
55061
|
+
t.signal.addEventListener("abort", u), r.addEventListener("abort", u), o = d.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())), h("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,
|
|
55070
|
-
if (!
|
|
55071
|
-
let
|
|
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, d = o.provider, u = a._server.providerService.getProvider(d);
|
|
55071
|
+
if (!u) throw L(`Provider '${d}' not found`, 404, "provider_not_found");
|
|
55072
|
+
let i = l, c = {};
|
|
55072
55073
|
if (typeof n.transformRequestOut == "function") {
|
|
55073
|
-
let s = n.transformRequestOut(l);
|
|
55074
|
-
s.body ? (
|
|
55074
|
+
let s = await n.transformRequestOut(l);
|
|
55075
|
+
s.body ? (i = s.body, c = s.config || {}) : i = s;
|
|
55075
55076
|
}
|
|
55076
|
-
if (
|
|
55077
|
-
|
|
55078
|
-
|
|
55079
|
-
|
|
55080
|
-
g.body ? (a = g.body, c = { ...c, ...g.config }) : a = g;
|
|
55077
|
+
if (h("use transformers:", u.transformer?.use), u.transformer?.use?.length) for (let s of u.transformer.use) {
|
|
55078
|
+
if (!s || typeof s.transformRequestIn != "function") continue;
|
|
55079
|
+
let y = await s.transformRequestIn(i, u);
|
|
55080
|
+
y.body ? (i = y.body, c = { ...c, ...y.config }) : i = y;
|
|
55081
55081
|
}
|
|
55082
|
-
if (
|
|
55083
|
-
|
|
55084
|
-
!m || typeof m.transformRequestIn != "function" || (a = m.transformRequestIn(a, d));
|
|
55085
|
-
}
|
|
55086
|
-
let y = c.url || new URL(d.baseUrl), v = await Q(y, a, { httpsProxy: i._server.configService.getHttpsProxy(), ...c, headers: { Authorization: `Bearer ${d.apiKey}`, ...c?.headers || {} } });
|
|
55082
|
+
if (u.transformer?.[o.body.model]?.use?.length) for (let s of u.transformer[o.body.model].use) !s || typeof s.transformRequestIn != "function" || (i = await s.transformRequestIn(i, u));
|
|
55083
|
+
let k = c.url || new URL(u.baseUrl), v = await ee(k, i, { httpsProxy: a._server.configService.getHttpsProxy(), ...c, headers: { Authorization: `Bearer ${u.apiKey}`, ...c?.headers || {} } });
|
|
55087
55084
|
if (!v.ok) {
|
|
55088
55085
|
let s = await v.text();
|
|
55089
|
-
throw
|
|
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));
|
|
55086
|
+
throw h(`Error response from ${k}: ${s}`), L(`Error from provider: ${s}`, v.status, "provider_response_error");
|
|
55095
55087
|
}
|
|
55096
|
-
|
|
55097
|
-
|
|
55098
|
-
|
|
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();
|
|
55088
|
+
let m = v;
|
|
55089
|
+
if (u.transformer?.use?.length) for (let s of u.transformer.use) !s || typeof s.transformResponseOut != "function" || (m = await s.transformResponseOut(m));
|
|
55090
|
+
if (u.transformer?.[o.body.model]?.use?.length) for (let s of u.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
|
-
|
|
55103
|
-
let { name: o, type: r, baseUrl: l, apiKey:
|
|
55104
|
-
if (!o?.trim()) throw
|
|
55105
|
-
if (!l || !
|
|
55106
|
-
if (!
|
|
55107
|
-
if (!
|
|
55108
|
-
if (
|
|
55109
|
-
return
|
|
55110
|
-
}),
|
|
55111
|
-
let o =
|
|
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) => {
|
|
55094
|
+
let { name: o, type: r, baseUrl: l, apiKey: d, models: u } = t.body;
|
|
55095
|
+
if (!o?.trim()) throw L("Provider name is required", 400, "invalid_request");
|
|
55096
|
+
if (!l || !de(l)) throw L("Valid base URL is required", 400, "invalid_request");
|
|
55097
|
+
if (!d?.trim()) throw L("API key is required", 400, "invalid_request");
|
|
55098
|
+
if (!u || !Array.isArray(u) || u.length === 0) throw L("At least one model is required", 400, "invalid_request");
|
|
55099
|
+
if (a._server.providerService.getProvider(id)) throw L(`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 de(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 $ = 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 F = 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 }), h(`${t.name} provider registered`);
|
|
55181
55188
|
} catch (n) {
|
|
55182
|
-
|
|
55189
|
+
h(`${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.
|
|
55208
|
-
this.modelRoutes.set(l,
|
|
55214
|
+
let l = `${n.name},${r}`, d = { provider: n.name, model: r, fullModel: l };
|
|
55215
|
+
this.modelRoutes.set(l, d), this.modelRoutes.has(r) || this.modelRoutes.set(r, d);
|
|
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 I = class {
|
|
55258
55264
|
name = "Anthropic";
|
|
55259
55265
|
endPoint = "/v1/messages";
|
|
55260
55266
|
transformRequestOut(e) {
|
|
55261
|
-
|
|
55267
|
+
h("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 });
|
|
@@ -55269,22 +55275,22 @@ var M = class {
|
|
|
55269
55275
|
}
|
|
55270
55276
|
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((r, l) => {
|
|
55271
55277
|
if (r.role === "user" || r.role === "assistant") {
|
|
55272
|
-
let
|
|
55278
|
+
let d = { role: r.role, content: null };
|
|
55273
55279
|
if (typeof r.content == "string") t.push({ role: r.role, content: r.content });
|
|
55274
55280
|
else if (Array.isArray(r.content)) {
|
|
55275
55281
|
if (r.role === "user") {
|
|
55276
|
-
let
|
|
55277
|
-
|
|
55282
|
+
let u = r.content.filter((c) => c.type === "tool_result" && c.tool_use_id);
|
|
55283
|
+
u.length && u.forEach((c, k) => {
|
|
55278
55284
|
let v = { 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 };
|
|
55279
55285
|
t.push(v);
|
|
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
|
-
let
|
|
55285
|
-
|
|
55286
|
-
let
|
|
55287
|
-
|
|
55290
|
+
let u = r.content.filter((c) => c.type === "text" && c.text);
|
|
55291
|
+
u.length && t.push(...u.map((c) => ({ role: "assistant", content: c.text })));
|
|
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,226 +55312,226 @@ 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",
|
|
55315
|
+
let o = new TextEncoder(), r = `msg_${Date.now()}`, l = "unknown", d = false, u = false, i = false, c = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map(), v = 0, m = 0, f = 0, s = false, y = false, g = 0, p = (_) => {
|
|
55310
55316
|
if (!s) try {
|
|
55311
|
-
n.enqueue(
|
|
55312
|
-
let
|
|
55313
|
-
|
|
55314
|
-
} catch (
|
|
55315
|
-
if (
|
|
55316
|
-
else throw
|
|
55317
|
-
}
|
|
55318
|
-
},
|
|
55317
|
+
n.enqueue(_);
|
|
55318
|
+
let R = new TextDecoder().decode(_);
|
|
55319
|
+
h("send data:", R.trim());
|
|
55320
|
+
} catch (R) {
|
|
55321
|
+
if (R instanceof TypeError && R.message.includes("Controller is already closed")) s = true;
|
|
55322
|
+
else throw h(`send data error: ${R.message}`), R;
|
|
55323
|
+
}
|
|
55324
|
+
}, S = () => {
|
|
55319
55325
|
if (!s) try {
|
|
55320
55326
|
n.close(), s = true;
|
|
55321
|
-
} catch (
|
|
55322
|
-
if (
|
|
55323
|
-
else throw
|
|
55327
|
+
} catch (_) {
|
|
55328
|
+
if (_ instanceof TypeError && _.message.includes("Controller is already closed")) s = true;
|
|
55329
|
+
else throw _;
|
|
55324
55330
|
}
|
|
55325
|
-
},
|
|
55331
|
+
}, P = null;
|
|
55326
55332
|
try {
|
|
55327
|
-
|
|
55328
|
-
let
|
|
55333
|
+
P = e.getReader();
|
|
55334
|
+
let _ = new TextDecoder(), R = "";
|
|
55329
55335
|
for (; !s; ) {
|
|
55330
|
-
let { done:
|
|
55331
|
-
if (
|
|
55332
|
-
|
|
55333
|
-
let
|
|
55336
|
+
let { done: oe, value: re } = await P.read();
|
|
55337
|
+
if (oe) break;
|
|
55338
|
+
R += _.decode(re, { stream: true });
|
|
55339
|
+
let K = R.split(`
|
|
55334
55340
|
`);
|
|
55335
|
-
|
|
55336
|
-
for (let
|
|
55337
|
-
if (s ||
|
|
55338
|
-
if (!
|
|
55339
|
-
let z =
|
|
55341
|
+
R = K.pop() || "";
|
|
55342
|
+
for (let Y of K) {
|
|
55343
|
+
if (s || i) break;
|
|
55344
|
+
if (!Y.startsWith("data: ")) continue;
|
|
55345
|
+
let z = Y.slice(6);
|
|
55340
55346
|
if (z !== "[DONE]") try {
|
|
55341
|
-
let
|
|
55342
|
-
if (v++,
|
|
55343
|
-
|
|
55347
|
+
let w = JSON.parse(z);
|
|
55348
|
+
if (v++, h("Original Response:", JSON.stringify(w, null, 2)), l = w.model || l, !d && !s && !i) {
|
|
55349
|
+
d = true;
|
|
55344
55350
|
let b = { 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 } } };
|
|
55345
|
-
|
|
55351
|
+
p(o.encode(`event: message_start
|
|
55346
55352
|
data: ${JSON.stringify(b)}
|
|
55347
55353
|
|
|
55348
55354
|
`));
|
|
55349
55355
|
}
|
|
55350
|
-
let
|
|
55351
|
-
if (!
|
|
55352
|
-
if (
|
|
55353
|
-
if (!
|
|
55356
|
+
let T = w.choices?.[0];
|
|
55357
|
+
if (!T) continue;
|
|
55358
|
+
if (T?.delta?.thinking && !s && !i) {
|
|
55359
|
+
if (!y) {
|
|
55354
55360
|
let b = { type: "content_block_start", index: g, content_block: { type: "thinking", thinking: "" } };
|
|
55355
|
-
|
|
55361
|
+
p(o.encode(`event: content_block_start
|
|
55356
55362
|
data: ${JSON.stringify(b)}
|
|
55357
55363
|
|
|
55358
|
-
`)),
|
|
55364
|
+
`)), y = true;
|
|
55359
55365
|
}
|
|
55360
|
-
if (
|
|
55361
|
-
let b = { type: "content_block_delta", index: g, delta: { type: "signature_delta", signature:
|
|
55362
|
-
|
|
55366
|
+
if (T.delta.thinking.signature) {
|
|
55367
|
+
let b = { type: "content_block_delta", index: g, delta: { type: "signature_delta", signature: T.delta.thinking.signature } };
|
|
55368
|
+
p(o.encode(`event: content_block_delta
|
|
55363
55369
|
data: ${JSON.stringify(b)}
|
|
55364
55370
|
|
|
55365
55371
|
`));
|
|
55366
|
-
let
|
|
55367
|
-
|
|
55368
|
-
data: ${JSON.stringify(
|
|
55372
|
+
let C = { type: "content_block_stop", index: g };
|
|
55373
|
+
p(o.encode(`event: content_block_stop
|
|
55374
|
+
data: ${JSON.stringify(C)}
|
|
55369
55375
|
|
|
55370
55376
|
`)), g++;
|
|
55371
|
-
} else if (
|
|
55372
|
-
let b = { type: "content_block_delta", index: g, delta: { type: "thinking_delta", thinking:
|
|
55373
|
-
|
|
55377
|
+
} else if (T.delta.thinking.content) {
|
|
55378
|
+
let b = { type: "content_block_delta", index: g, delta: { type: "thinking_delta", thinking: T.delta.thinking.content || "" } };
|
|
55379
|
+
p(o.encode(`event: content_block_delta
|
|
55374
55380
|
data: ${JSON.stringify(b)}
|
|
55375
55381
|
|
|
55376
55382
|
`));
|
|
55377
55383
|
}
|
|
55378
55384
|
}
|
|
55379
|
-
if (
|
|
55380
|
-
if (
|
|
55381
|
-
|
|
55385
|
+
if (T?.delta?.content && !s && !i) {
|
|
55386
|
+
if (m++, !u && !i) {
|
|
55387
|
+
u = true;
|
|
55382
55388
|
let b = { type: "content_block_start", index: g, content_block: { type: "text", text: "" } };
|
|
55383
|
-
|
|
55389
|
+
p(o.encode(`event: content_block_start
|
|
55384
55390
|
data: ${JSON.stringify(b)}
|
|
55385
55391
|
|
|
55386
55392
|
`));
|
|
55387
55393
|
}
|
|
55388
|
-
if (!s && !
|
|
55389
|
-
let b = { type: "content_block_delta", index: g, delta: { type: "text_delta", text:
|
|
55390
|
-
|
|
55394
|
+
if (!s && !i) {
|
|
55395
|
+
let b = { type: "content_block_delta", index: g, delta: { type: "text_delta", text: T.delta.content } };
|
|
55396
|
+
p(o.encode(`event: content_block_delta
|
|
55391
55397
|
data: ${JSON.stringify(b)}
|
|
55392
55398
|
|
|
55393
55399
|
`));
|
|
55394
55400
|
}
|
|
55395
55401
|
}
|
|
55396
|
-
if (
|
|
55397
|
-
|
|
55402
|
+
if (T?.delta?.tool_calls && !s && !i) {
|
|
55403
|
+
f++;
|
|
55398
55404
|
let b = /* @__PURE__ */ new Set();
|
|
55399
|
-
for (let
|
|
55405
|
+
for (let C of T.delta.tool_calls) {
|
|
55400
55406
|
if (s) break;
|
|
55401
|
-
let
|
|
55402
|
-
if (b.has(
|
|
55403
|
-
if (b.add(
|
|
55404
|
-
let
|
|
55405
|
-
if (
|
|
55406
|
-
|
|
55407
|
-
let
|
|
55408
|
-
|
|
55409
|
-
data: ${JSON.stringify(
|
|
55407
|
+
let x = C.index ?? 0;
|
|
55408
|
+
if (b.has(x)) continue;
|
|
55409
|
+
if (b.add(x), !k.has(x)) {
|
|
55410
|
+
let O = u ? k.size + 1 : k.size;
|
|
55411
|
+
if (O !== 0) {
|
|
55412
|
+
h("content_block_stop2");
|
|
55413
|
+
let se = { type: "content_block_stop", index: g };
|
|
55414
|
+
p(o.encode(`event: content_block_stop
|
|
55415
|
+
data: ${JSON.stringify(se)}
|
|
55410
55416
|
|
|
55411
55417
|
`)), g++;
|
|
55412
55418
|
}
|
|
55413
|
-
|
|
55414
|
-
let
|
|
55415
|
-
|
|
55416
|
-
data: ${JSON.stringify(
|
|
55419
|
+
k.set(x, O);
|
|
55420
|
+
let H = C.id || `call_${Date.now()}_${x}`, A = C.function?.name || `tool_${x}`, E = { type: "content_block_start", index: g, content_block: { type: "tool_use", id: H, name: A, input: {} } };
|
|
55421
|
+
p(o.encode(`event: content_block_start
|
|
55422
|
+
data: ${JSON.stringify(E)}
|
|
55417
55423
|
|
|
55418
55424
|
`));
|
|
55419
|
-
let
|
|
55420
|
-
c.set(
|
|
55421
|
-
} else if (
|
|
55422
|
-
let
|
|
55423
|
-
|
|
55425
|
+
let M = { id: H, name: A, arguments: "", contentBlockIndex: O };
|
|
55426
|
+
c.set(x, M);
|
|
55427
|
+
} else if (C.id && C.function?.name) {
|
|
55428
|
+
let O = c.get(x);
|
|
55429
|
+
O.id.startsWith("call_") && O.name.startsWith("tool_") && (O.id = C.id, O.name = C.function.name);
|
|
55424
55430
|
}
|
|
55425
|
-
if (
|
|
55426
|
-
if (
|
|
55427
|
-
let
|
|
55428
|
-
if (
|
|
55429
|
-
|
|
55431
|
+
if (C.function?.arguments && !s && !i) {
|
|
55432
|
+
if (k.get(x) === void 0) continue;
|
|
55433
|
+
let H = c.get(x);
|
|
55434
|
+
if (H) {
|
|
55435
|
+
H.arguments += C.function.arguments;
|
|
55430
55436
|
try {
|
|
55431
|
-
let
|
|
55432
|
-
if (
|
|
55433
|
-
|
|
55434
|
-
} catch (
|
|
55435
|
-
|
|
55437
|
+
let A = null, E = H.arguments.trim();
|
|
55438
|
+
if (E.startsWith("{") && E.endsWith("}")) try {
|
|
55439
|
+
A = JSON.parse(E);
|
|
55440
|
+
} catch (M) {
|
|
55441
|
+
h("Tool call index:", x, "error", M.message);
|
|
55436
55442
|
}
|
|
55437
|
-
} catch (
|
|
55438
|
-
|
|
55443
|
+
} catch (A) {
|
|
55444
|
+
h("Tool call index:", x, "error", A.message);
|
|
55439
55445
|
}
|
|
55440
55446
|
}
|
|
55441
55447
|
try {
|
|
55442
|
-
let
|
|
55443
|
-
|
|
55444
|
-
data: ${JSON.stringify(
|
|
55448
|
+
let A = { type: "content_block_delta", index: g, delta: { type: "input_json_delta", partial_json: C.function.arguments } };
|
|
55449
|
+
p(o.encode(`event: content_block_delta
|
|
55450
|
+
data: ${JSON.stringify(A)}
|
|
55445
55451
|
|
|
55446
55452
|
`));
|
|
55447
55453
|
} catch {
|
|
55448
55454
|
try {
|
|
55449
|
-
let
|
|
55450
|
-
|
|
55451
|
-
data: ${JSON.stringify(
|
|
55455
|
+
let E = C.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), M = { type: "content_block_delta", index: g, delta: { type: "input_json_delta", partial_json: E } };
|
|
55456
|
+
p(o.encode(`event: content_block_delta
|
|
55457
|
+
data: ${JSON.stringify(M)}
|
|
55452
55458
|
|
|
55453
55459
|
`));
|
|
55454
|
-
} catch (
|
|
55455
|
-
console.error(
|
|
55460
|
+
} catch (E) {
|
|
55461
|
+
console.error(E);
|
|
55456
55462
|
}
|
|
55457
55463
|
}
|
|
55458
55464
|
}
|
|
55459
55465
|
}
|
|
55460
55466
|
}
|
|
55461
|
-
if (
|
|
55462
|
-
if (
|
|
55463
|
-
|
|
55467
|
+
if (T?.finish_reason && !s && !i) {
|
|
55468
|
+
if (i = true, m === 0 && f === 0 && console.error("Warning: No content in the stream response!"), (u || f > 0) && !s) {
|
|
55469
|
+
h("content_block_stop hasTextContentStarted");
|
|
55464
55470
|
let b = { type: "content_block_stop", index: g };
|
|
55465
|
-
|
|
55471
|
+
p(o.encode(`event: content_block_stop
|
|
55466
55472
|
data: ${JSON.stringify(b)}
|
|
55467
55473
|
|
|
55468
55474
|
`));
|
|
55469
55475
|
}
|
|
55470
55476
|
if (!s) {
|
|
55471
|
-
let
|
|
55472
|
-
|
|
55473
|
-
data: ${JSON.stringify(
|
|
55477
|
+
let x = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[T.finish_reason] || "end_turn", stop_sequence: null }, usage: { input_tokens: w.usage?.prompt_tokens || 0, output_tokens: w.usage?.completion_tokens || 0 } };
|
|
55478
|
+
p(o.encode(`event: message_delta
|
|
55479
|
+
data: ${JSON.stringify(x)}
|
|
55474
55480
|
|
|
55475
55481
|
`));
|
|
55476
55482
|
}
|
|
55477
55483
|
if (!s) {
|
|
55478
55484
|
let b = { type: "message_stop" };
|
|
55479
|
-
|
|
55485
|
+
p(o.encode(`event: message_stop
|
|
55480
55486
|
data: ${JSON.stringify(b)}
|
|
55481
55487
|
|
|
55482
55488
|
`));
|
|
55483
55489
|
}
|
|
55484
55490
|
break;
|
|
55485
55491
|
}
|
|
55486
|
-
} catch (
|
|
55487
|
-
|
|
55492
|
+
} catch (w) {
|
|
55493
|
+
h(`parseError: ${w.name} message: ${w.message} stack: ${w.stack} data: ${z}`);
|
|
55488
55494
|
}
|
|
55489
55495
|
}
|
|
55490
55496
|
}
|
|
55491
|
-
|
|
55492
|
-
} catch (
|
|
55497
|
+
S();
|
|
55498
|
+
} catch (_) {
|
|
55493
55499
|
if (!s) try {
|
|
55494
|
-
n.error(
|
|
55495
|
-
} catch (
|
|
55496
|
-
console.error(
|
|
55500
|
+
n.error(_);
|
|
55501
|
+
} catch (R) {
|
|
55502
|
+
console.error(R);
|
|
55497
55503
|
}
|
|
55498
55504
|
} finally {
|
|
55499
|
-
if (
|
|
55500
|
-
|
|
55501
|
-
} catch (
|
|
55502
|
-
console.error(
|
|
55505
|
+
if (P) try {
|
|
55506
|
+
P.releaseLock();
|
|
55507
|
+
} catch (_) {
|
|
55508
|
+
console.error(_);
|
|
55503
55509
|
}
|
|
55504
55510
|
}
|
|
55505
55511
|
}, cancel(n) {
|
|
55506
|
-
|
|
55512
|
+
h("cancle stream:", n);
|
|
55507
55513
|
} });
|
|
55508
55514
|
}
|
|
55509
55515
|
convertOpenAIResponseToAnthropic(e) {
|
|
55510
|
-
|
|
55516
|
+
h("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 = [];
|
|
55514
55520
|
t.message.content && n.push({ type: "text", text: t.message.content }), t.message.tool_calls && t.message.tool_calls.length > 0 && t.message.tool_calls.forEach((r, l) => {
|
|
55515
|
-
let
|
|
55521
|
+
let d = {};
|
|
55516
55522
|
try {
|
|
55517
|
-
let
|
|
55518
|
-
typeof
|
|
55523
|
+
let u = r.function.arguments || "{}";
|
|
55524
|
+
typeof u == "object" ? d = u : typeof u == "string" && (d = JSON.parse(u));
|
|
55519
55525
|
} catch {
|
|
55520
|
-
|
|
55526
|
+
d = { text: r.function.arguments || "" };
|
|
55521
55527
|
}
|
|
55522
|
-
n.push({ type: "tool_use", id: r.id, name: r.function.name, input:
|
|
55528
|
+
n.push({ type: "tool_use", id: r.id, name: r.function.name, input: d });
|
|
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 h("Conversion complete, final Anthropic response:", JSON.stringify(o, null, 2)), o;
|
|
55526
55532
|
}
|
|
55527
55533
|
};
|
|
55528
|
-
var
|
|
55534
|
+
var q = 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,
|
|
55550
|
+
let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens, l = e.temperature, d = e.stream, u = e.tool_choice, i = { messages: [], model: o, max_tokens: r, temperature: l, stream: d, tool_choice: u };
|
|
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((k) => ({ type: "text", text: k.text || "" })) || [] }) : c.role === "model" && i.messages.push({ role: "assistant", content: c?.parts?.map((k) => ({ type: "text", text: k.text || "" })) || [] });
|
|
55553
|
+
}), Array.isArray(n) && (i.tools = [], n.forEach((c) => {
|
|
55554
|
+
Array.isArray(c.functionDeclarations) && c.functionDeclarations.forEach((k) => {
|
|
55555
|
+
i.tools.push({ type: "function", function: { name: k.name, description: k.description, parameters: k.parameters } });
|
|
55550
55556
|
});
|
|
55551
|
-
})),
|
|
55557
|
+
})), i;
|
|
55552
55558
|
}
|
|
55553
55559
|
async transformResponseOut(e) {
|
|
55554
55560
|
if (e.headers.get("Content-Type")?.includes("application/json")) {
|
|
@@ -55561,20 +55567,20 @@ var N = class {
|
|
|
55561
55567
|
let l = e.body.getReader();
|
|
55562
55568
|
try {
|
|
55563
55569
|
for (; ; ) {
|
|
55564
|
-
let { done:
|
|
55565
|
-
if (
|
|
55566
|
-
let
|
|
55567
|
-
if (
|
|
55570
|
+
let { done: d, value: u } = await l.read();
|
|
55571
|
+
if (d) break;
|
|
55572
|
+
let i = t.decode(u, { 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
|
+
h("gemini chunk:", i), i = JSON.parse(i);
|
|
55576
|
+
let c = i.candidates[0].content.parts.filter((v) => v.functionCall).map((v) => ({ id: v.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: v.functionCall?.name, arguments: JSON.stringify(v.functionCall?.args || {}) } })), k = { choices: [{ delta: { role: "assistant", content: i.candidates[0].content.parts.filter((v) => v.text).map((v) => v.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
|
+
h("gemini response:", JSON.stringify(k, null, 2)), r.enqueue(n.encode(`data: ${JSON.stringify(k)}
|
|
55573
55579
|
|
|
55574
55580
|
`));
|
|
55575
55581
|
}
|
|
55576
|
-
} catch (
|
|
55577
|
-
r.error(
|
|
55582
|
+
} catch (d) {
|
|
55583
|
+
r.error(d);
|
|
55578
55584
|
} finally {
|
|
55579
55585
|
r.close();
|
|
55580
55586
|
}
|
|
@@ -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;
|
|
@@ -55595,58 +55601,58 @@ var H = class {
|
|
|
55595
55601
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55596
55602
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55597
55603
|
if (!e.body) return e;
|
|
55598
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false, l = new ReadableStream({ async start(
|
|
55599
|
-
let
|
|
55604
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false, l = new ReadableStream({ async start(d) {
|
|
55605
|
+
let u = e.body.getReader();
|
|
55600
55606
|
try {
|
|
55601
55607
|
for (; ; ) {
|
|
55602
|
-
let { done:
|
|
55603
|
-
if (
|
|
55608
|
+
let { done: i, value: c } = await u.read();
|
|
55609
|
+
if (i) break;
|
|
55604
55610
|
let v = 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 v) 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 y = `data: ${JSON.stringify(s)}
|
|
55613
55619
|
|
|
55614
55620
|
`;
|
|
55615
|
-
|
|
55621
|
+
d.enqueue(n.encode(y));
|
|
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 g = `data: ${JSON.stringify(
|
|
55626
|
+
let s = Date.now().toString(), y = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, content: null, thinking: { content: o, signature: s } } }] };
|
|
55627
|
+
delete y.choices[0].delta.reasoning_content;
|
|
55628
|
+
let g = `data: ${JSON.stringify(y)}
|
|
55623
55629
|
|
|
55624
55630
|
`;
|
|
55625
|
-
|
|
55631
|
+
d.enqueue(n.encode(g));
|
|
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
|
+
d.enqueue(n.encode(s));
|
|
55633
55639
|
}
|
|
55634
55640
|
} catch {
|
|
55635
|
-
|
|
55641
|
+
d.enqueue(n.encode(m + `
|
|
55636
55642
|
`));
|
|
55637
55643
|
}
|
|
55638
|
-
else
|
|
55644
|
+
else d.enqueue(n.encode(m + `
|
|
55639
55645
|
`));
|
|
55640
55646
|
}
|
|
55641
|
-
} catch (
|
|
55642
|
-
|
|
55647
|
+
} catch (i) {
|
|
55648
|
+
d.error(i);
|
|
55643
55649
|
} finally {
|
|
55644
55650
|
try {
|
|
55645
|
-
|
|
55646
|
-
} catch (
|
|
55647
|
-
console.error("Error releasing reader lock:",
|
|
55651
|
+
u.releaseLock();
|
|
55652
|
+
} catch (i) {
|
|
55653
|
+
console.error("Error releasing reader lock:", i);
|
|
55648
55654
|
}
|
|
55649
|
-
|
|
55655
|
+
d.close();
|
|
55650
55656
|
}
|
|
55651
55657
|
} });
|
|
55652
55658
|
return new Response(l, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
@@ -55654,7 +55660,7 @@ var H = class {
|
|
|
55654
55660
|
return e;
|
|
55655
55661
|
}
|
|
55656
55662
|
};
|
|
55657
|
-
var
|
|
55663
|
+
var J = 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.
|
|
@@ -55673,57 +55679,57 @@ Examples:
|
|
|
55673
55679
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55674
55680
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55675
55681
|
if (!e.body) return e;
|
|
55676
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "", l = new ReadableStream({ async start(
|
|
55677
|
-
let
|
|
55682
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "", l = new ReadableStream({ async start(d) {
|
|
55683
|
+
let u = e.body.getReader();
|
|
55678
55684
|
try {
|
|
55679
55685
|
for (; ; ) {
|
|
55680
|
-
let { done:
|
|
55681
|
-
if (
|
|
55686
|
+
let { done: i, value: c } = await u.read();
|
|
55687
|
+
if (i) break;
|
|
55682
55688
|
let v = t.decode(c, { stream: true }).split(`
|
|
55683
55689
|
`);
|
|
55684
|
-
for (let
|
|
55685
|
-
let
|
|
55686
|
-
if (
|
|
55687
|
-
let s =
|
|
55690
|
+
for (let m of v) 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 g = `data: ${JSON.stringify(
|
|
55700
|
+
let y = JSON.parse(r);
|
|
55701
|
+
f.choices = [{ delta: { role: "assistant", content: y.response || "" } }];
|
|
55702
|
+
let g = `data: ${JSON.stringify(f)}
|
|
55697
55703
|
|
|
55698
55704
|
`;
|
|
55699
|
-
|
|
55705
|
+
d.enqueue(n.encode(g));
|
|
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
|
+
d.enqueue(n.encode(s));
|
|
55710
55716
|
}
|
|
55711
55717
|
} catch {
|
|
55712
|
-
|
|
55718
|
+
d.enqueue(n.encode(m + `
|
|
55713
55719
|
`));
|
|
55714
55720
|
}
|
|
55715
|
-
else
|
|
55721
|
+
else d.enqueue(n.encode(m + `
|
|
55716
55722
|
`));
|
|
55717
55723
|
}
|
|
55718
|
-
} catch (
|
|
55719
|
-
|
|
55724
|
+
} catch (i) {
|
|
55725
|
+
d.error(i);
|
|
55720
55726
|
} finally {
|
|
55721
55727
|
try {
|
|
55722
|
-
|
|
55723
|
-
} catch (
|
|
55724
|
-
console.error("Error releasing reader lock:",
|
|
55728
|
+
u.releaseLock();
|
|
55729
|
+
} catch (i) {
|
|
55730
|
+
console.error("Error releasing reader lock:", i);
|
|
55725
55731
|
}
|
|
55726
|
-
|
|
55732
|
+
d.close();
|
|
55727
55733
|
}
|
|
55728
55734
|
} });
|
|
55729
55735
|
return new Response(l, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
@@ -55731,7 +55737,7 @@ Examples:
|
|
|
55731
55737
|
return e;
|
|
55732
55738
|
}
|
|
55733
55739
|
};
|
|
55734
|
-
var
|
|
55740
|
+
var U = class {
|
|
55735
55741
|
name = "openrouter";
|
|
55736
55742
|
transformRequestIn(e) {
|
|
55737
55743
|
return e.model.includes("claude") || e.messages.forEach((t) => {
|
|
@@ -55746,56 +55752,97 @@ var F = class {
|
|
|
55746
55752
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55747
55753
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55748
55754
|
if (!e.body) return e;
|
|
55749
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", l = false, u = new ReadableStream({ async start(
|
|
55750
|
-
let
|
|
55751
|
-
|
|
55752
|
-
for (; ; ) {
|
|
55753
|
-
let { done: c, value: y } = await a.read();
|
|
55754
|
-
if (c) break;
|
|
55755
|
-
let h = t.decode(y, { stream: true }).split(`
|
|
55755
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", l = false, d = "", u = new ReadableStream({ async start(i) {
|
|
55756
|
+
let c = e.body.getReader(), k = (m, f, s) => {
|
|
55757
|
+
let y = m.split(`
|
|
55756
55758
|
`);
|
|
55757
|
-
|
|
55758
|
-
|
|
55759
|
-
|
|
55760
|
-
|
|
55761
|
-
|
|
55762
|
-
|
|
55763
|
-
|
|
55759
|
+
for (let g of y) g.trim() && f.enqueue(s.encode(g + `
|
|
55760
|
+
`));
|
|
55761
|
+
}, v = (m, f) => {
|
|
55762
|
+
let { controller: s, encoder: y } = f;
|
|
55763
|
+
if (m.startsWith("data: ") && m.trim() !== "data: [DONE]") {
|
|
55764
|
+
let g = m.slice(6);
|
|
55765
|
+
try {
|
|
55766
|
+
let p = JSON.parse(g);
|
|
55767
|
+
if (p.choices?.[0]?.delta?.content && !f.hasTextContent() && f.setHasTextContent(true), p.choices?.[0]?.delta?.reasoning) {
|
|
55768
|
+
f.appendReasoningContent(p.choices[0].delta.reasoning);
|
|
55769
|
+
let P = { ...p, choices: [{ ...p.choices?.[0], delta: { ...p.choices[0].delta, thinking: { content: p.choices[0].delta.reasoning } } }] };
|
|
55770
|
+
P.choices?.[0]?.delta && delete P.choices[0].delta.reasoning;
|
|
55771
|
+
let _ = `data: ${JSON.stringify(P)}
|
|
55764
55772
|
|
|
55765
55773
|
`;
|
|
55766
|
-
|
|
55767
|
-
|
|
55774
|
+
s.enqueue(y.encode(_));
|
|
55775
|
+
return;
|
|
55768
55776
|
}
|
|
55769
|
-
if (
|
|
55770
|
-
|
|
55771
|
-
let
|
|
55772
|
-
delete
|
|
55773
|
-
let
|
|
55777
|
+
if (p.choices?.[0]?.delta?.content && f.reasoningContent() && !f.isReasoningComplete()) {
|
|
55778
|
+
f.setReasoningComplete(true);
|
|
55779
|
+
let P = Date.now().toString(), _ = { ...p, choices: [{ ...p.choices?.[0], delta: { ...p.choices[0].delta, content: null, thinking: { content: f.reasoningContent(), signature: P } } }] };
|
|
55780
|
+
_.choices?.[0]?.delta && delete _.choices[0].delta.reasoning;
|
|
55781
|
+
let R = `data: ${JSON.stringify(_)}
|
|
55774
55782
|
|
|
55775
55783
|
`;
|
|
55776
|
-
|
|
55784
|
+
s.enqueue(y.encode(R));
|
|
55777
55785
|
}
|
|
55778
|
-
|
|
55779
|
-
let
|
|
55786
|
+
p.choices?.[0]?.delta?.reasoning && delete p.choices[0].delta.reasoning, p.choices?.[0]?.delta?.tool_calls?.length && f.hasTextContent() && (typeof p.choices[0].index == "number" ? p.choices[0].index += 1 : p.choices[0].index = 1);
|
|
55787
|
+
let S = `data: ${JSON.stringify(p)}
|
|
55780
55788
|
|
|
55781
55789
|
`;
|
|
55782
|
-
|
|
55790
|
+
s.enqueue(y.encode(S));
|
|
55783
55791
|
} catch {
|
|
55784
|
-
|
|
55792
|
+
s.enqueue(y.encode(m + `
|
|
55785
55793
|
`));
|
|
55786
55794
|
}
|
|
55787
|
-
|
|
55795
|
+
} else s.enqueue(y.encode(m + `
|
|
55788
55796
|
`));
|
|
55797
|
+
};
|
|
55798
|
+
try {
|
|
55799
|
+
for (; ; ) {
|
|
55800
|
+
let { done: m, value: f } = await c.read();
|
|
55801
|
+
if (m) {
|
|
55802
|
+
d.trim() && k(d, i, n);
|
|
55803
|
+
break;
|
|
55804
|
+
}
|
|
55805
|
+
if (!f || f.length === 0) continue;
|
|
55806
|
+
let s;
|
|
55807
|
+
try {
|
|
55808
|
+
s = t.decode(f, { stream: true });
|
|
55809
|
+
} catch (g) {
|
|
55810
|
+
console.warn("Failed to decode chunk", g);
|
|
55811
|
+
continue;
|
|
55812
|
+
}
|
|
55813
|
+
if (s.length === 0) continue;
|
|
55814
|
+
if (d += s, d.length > 1e6) {
|
|
55815
|
+
console.warn("Buffer size exceeds limit, processing partial data");
|
|
55816
|
+
let g = d.split(`
|
|
55817
|
+
`);
|
|
55818
|
+
d = g.pop() || "";
|
|
55819
|
+
for (let p of g) if (p.trim()) try {
|
|
55820
|
+
v(p, { controller: i, encoder: n, hasTextContent: () => o, setHasTextContent: (S) => o = S, reasoningContent: () => r, appendReasoningContent: (S) => r += S, isReasoningComplete: () => l, setReasoningComplete: (S) => l = S });
|
|
55821
|
+
} catch (S) {
|
|
55822
|
+
console.error("Error processing line:", p, S), i.enqueue(n.encode(p + `
|
|
55823
|
+
`));
|
|
55824
|
+
}
|
|
55825
|
+
continue;
|
|
55826
|
+
}
|
|
55827
|
+
let y = d.split(`
|
|
55828
|
+
`);
|
|
55829
|
+
d = y.pop() || "";
|
|
55830
|
+
for (let g of y) if (g.trim()) try {
|
|
55831
|
+
v(g, { controller: i, encoder: n, hasTextContent: () => o, setHasTextContent: (p) => o = p, reasoningContent: () => r, appendReasoningContent: (p) => r += p, isReasoningComplete: () => l, setReasoningComplete: (p) => l = p });
|
|
55832
|
+
} catch (p) {
|
|
55833
|
+
console.error("Error processing line:", g, p), i.enqueue(n.encode(g + `
|
|
55834
|
+
`));
|
|
55835
|
+
}
|
|
55789
55836
|
}
|
|
55790
|
-
} catch (
|
|
55791
|
-
|
|
55837
|
+
} catch (m) {
|
|
55838
|
+
console.error("Stream error:", m), i.error(m);
|
|
55792
55839
|
} finally {
|
|
55793
55840
|
try {
|
|
55794
|
-
|
|
55795
|
-
} catch (
|
|
55796
|
-
console.error("Error releasing reader lock:",
|
|
55841
|
+
c.releaseLock();
|
|
55842
|
+
} catch (m) {
|
|
55843
|
+
console.error("Error releasing reader lock:", m);
|
|
55797
55844
|
}
|
|
55798
|
-
|
|
55845
|
+
i.close();
|
|
55799
55846
|
}
|
|
55800
55847
|
} });
|
|
55801
55848
|
return new Response(u, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
@@ -55803,14 +55850,25 @@ var F = class {
|
|
|
55803
55850
|
return e;
|
|
55804
55851
|
}
|
|
55805
55852
|
};
|
|
55806
|
-
var
|
|
55853
|
+
var D = class {
|
|
55854
|
+
constructor(e) {
|
|
55855
|
+
this.options = e;
|
|
55856
|
+
this.max_tokens = this.options?.max_tokens;
|
|
55857
|
+
}
|
|
55858
|
+
static TransformerName = "maxtoken";
|
|
55859
|
+
max_tokens;
|
|
55860
|
+
transformRequestIn(e) {
|
|
55861
|
+
return e.max_tokens && e.max_tokens > this.max_tokens && (e.max_tokens = this.max_tokens), e;
|
|
55862
|
+
}
|
|
55863
|
+
};
|
|
55864
|
+
var ne = { AnthropicTransformer: I, GeminiTransformer: q, DeepseekTransformer: j, TooluseTransformer: J, OpenrouterTransformer: U, MaxTokenTransformer: D };
|
|
55865
|
+
var B = class {
|
|
55807
55866
|
constructor(e) {
|
|
55808
55867
|
this.configService = e;
|
|
55809
|
-
this.initialize();
|
|
55810
55868
|
}
|
|
55811
55869
|
transformers = /* @__PURE__ */ new Map();
|
|
55812
55870
|
registerTransformer(e, t) {
|
|
55813
|
-
this.transformers.set(e, t),
|
|
55871
|
+
this.transformers.set(e, t), h(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
|
|
55814
55872
|
}
|
|
55815
55873
|
getTransformer(e) {
|
|
55816
55874
|
return this.transformers.get(e);
|
|
@@ -55838,32 +55896,40 @@ var U = class {
|
|
|
55838
55896
|
}
|
|
55839
55897
|
async registerTransformerFromConfig(e) {
|
|
55840
55898
|
try {
|
|
55841
|
-
|
|
55842
|
-
|
|
55843
|
-
|
|
55844
|
-
|
|
55845
|
-
|
|
55846
|
-
|
|
55899
|
+
let t = import_node_module.default._load;
|
|
55900
|
+
if (import_node_module.default._load = function(n, o, r) {
|
|
55901
|
+
return n === "claude-code-router" ? { log: h } : t.apply(import_node_module.default, arguments);
|
|
55902
|
+
}, e.path) {
|
|
55903
|
+
let n = W(W.resolve(e.path));
|
|
55904
|
+
if (n) {
|
|
55905
|
+
let o = new n(e.options);
|
|
55906
|
+
if (!o.name) throw new Error(`Transformer instance from ${e.path} does not have a name property.`);
|
|
55907
|
+
return this.registerTransformer(o.name, o), true;
|
|
55847
55908
|
}
|
|
55848
55909
|
}
|
|
55849
55910
|
return false;
|
|
55850
55911
|
} catch (t) {
|
|
55851
|
-
return
|
|
55912
|
+
return h(`load transformer (${e.path}) error:`, t.message, t.stack), false;
|
|
55852
55913
|
}
|
|
55853
55914
|
}
|
|
55854
55915
|
async initialize() {
|
|
55855
55916
|
try {
|
|
55856
55917
|
await this.registerDefaultTransformersInternal(), await this.loadFromConfig();
|
|
55857
55918
|
} catch (e) {
|
|
55858
|
-
|
|
55919
|
+
h("TransformerService init error:", e);
|
|
55859
55920
|
}
|
|
55860
55921
|
}
|
|
55861
55922
|
async registerDefaultTransformersInternal() {
|
|
55862
55923
|
try {
|
|
55863
|
-
|
|
55864
|
-
|
|
55924
|
+
Object.values(ne).forEach((e) => {
|
|
55925
|
+
if ("TransformerName" in e && typeof e.TransformerName == "string") this.registerTransformer(e.TransformerName, e);
|
|
55926
|
+
else {
|
|
55927
|
+
let t = new e();
|
|
55928
|
+
this.registerTransformer(t.name, t);
|
|
55929
|
+
}
|
|
55930
|
+
});
|
|
55865
55931
|
} catch (e) {
|
|
55866
|
-
|
|
55932
|
+
h("transformer regist error:", e);
|
|
55867
55933
|
}
|
|
55868
55934
|
}
|
|
55869
55935
|
async loadFromConfig() {
|
|
@@ -55871,18 +55937,20 @@ var U = class {
|
|
|
55871
55937
|
for (let t of e) await this.registerTransformerFromConfig(t);
|
|
55872
55938
|
}
|
|
55873
55939
|
};
|
|
55874
|
-
function
|
|
55875
|
-
let
|
|
55876
|
-
return
|
|
55940
|
+
function pe() {
|
|
55941
|
+
let a = (0, import_fastify.default)({});
|
|
55942
|
+
return a.setErrorHandler(Z), a.register(import_cors.default), a;
|
|
55877
55943
|
}
|
|
55878
|
-
var
|
|
55944
|
+
var G = class {
|
|
55879
55945
|
app;
|
|
55880
55946
|
configService;
|
|
55881
55947
|
llmService;
|
|
55882
55948
|
providerService;
|
|
55883
55949
|
transformerService;
|
|
55884
55950
|
constructor(e = {}) {
|
|
55885
|
-
this.configService = new
|
|
55951
|
+
this.configService = new N(e), this.transformerService = new B(this.configService), this.transformerService.initialize().finally(() => {
|
|
55952
|
+
this.providerService = new F(this.configService, this.transformerService), this.llmService = new $(this.providerService);
|
|
55953
|
+
}), this.app = pe();
|
|
55886
55954
|
}
|
|
55887
55955
|
async register(e, t) {
|
|
55888
55956
|
await this.app.register(e, t);
|
|
@@ -55896,29 +55964,29 @@ var B = class {
|
|
|
55896
55964
|
try {
|
|
55897
55965
|
let r = n.body;
|
|
55898
55966
|
if (!r || !r.model) return o.code(400).send({ error: "Missing model in request body" });
|
|
55899
|
-
let [l,
|
|
55900
|
-
r.model =
|
|
55967
|
+
let [l, d] = r.model.split(",");
|
|
55968
|
+
r.model = d, n.provider = l;
|
|
55901
55969
|
return;
|
|
55902
55970
|
} catch (r) {
|
|
55903
55971
|
return n.log.error("Error in modelProviderMiddleware:", r), o.code(500).send({ error: "Internal server error" });
|
|
55904
55972
|
}
|
|
55905
|
-
}), this.app.register(
|
|
55973
|
+
}), this.app.register(te);
|
|
55906
55974
|
let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
|
|
55907
|
-
|
|
55975
|
+
h(`\u{1F680} LLMs API server listening on ${e}`);
|
|
55908
55976
|
let t = async (n) => {
|
|
55909
|
-
|
|
55977
|
+
h(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
|
|
55910
55978
|
};
|
|
55911
55979
|
process.on("SIGINT", () => t("SIGINT")), process.on("SIGTERM", () => t("SIGTERM"));
|
|
55912
55980
|
} catch (e) {
|
|
55913
|
-
|
|
55981
|
+
h(`Error starting server: ${e}`), process.exit(1);
|
|
55914
55982
|
}
|
|
55915
55983
|
}
|
|
55916
55984
|
};
|
|
55917
|
-
var
|
|
55985
|
+
var At = G;
|
|
55918
55986
|
|
|
55919
55987
|
// src/server.ts
|
|
55920
55988
|
var createServer = (config) => {
|
|
55921
|
-
const server = new
|
|
55989
|
+
const server = new At(config);
|
|
55922
55990
|
return server;
|
|
55923
55991
|
};
|
|
55924
55992
|
|
|
@@ -56237,7 +56305,7 @@ async function executeCodeCommand(args = []) {
|
|
|
56237
56305
|
}
|
|
56238
56306
|
|
|
56239
56307
|
// package.json
|
|
56240
|
-
var version = "1.0.
|
|
56308
|
+
var version = "1.0.19";
|
|
56241
56309
|
|
|
56242
56310
|
// src/cli.ts
|
|
56243
56311
|
var import_child_process2 = require("child_process");
|