@musistudio/claude-code-router 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +343 -335
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -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(f2, args, opts) {
|
|
4315
4315
|
var ss = opts && opts.stringify || tryStringify;
|
|
4316
4316
|
var offset = 1;
|
|
4317
|
-
if (typeof
|
|
4317
|
+
if (typeof f2 === "object" && f2 !== null) {
|
|
4318
4318
|
var len = args.length + offset;
|
|
4319
|
-
if (len === 1) return
|
|
4319
|
+
if (len === 1) return f2;
|
|
4320
4320
|
var objects = new Array(len);
|
|
4321
|
-
objects[0] = ss(
|
|
4321
|
+
objects[0] = ss(f2);
|
|
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 f2 !== "string") {
|
|
4328
|
+
return f2;
|
|
4329
4329
|
}
|
|
4330
4330
|
var argLen = args.length;
|
|
4331
|
-
if (argLen === 0) return
|
|
4331
|
+
if (argLen === 0) return f2;
|
|
4332
4332
|
var str = "";
|
|
4333
4333
|
var a = 1 - offset;
|
|
4334
4334
|
var lastPos = -1;
|
|
4335
|
-
var flen =
|
|
4335
|
+
var flen = f2 && f2.length || 0;
|
|
4336
4336
|
for (var i = 0; i < flen; ) {
|
|
4337
|
-
if (
|
|
4337
|
+
if (f2.charCodeAt(i) === 37 && i + 1 < flen) {
|
|
4338
4338
|
lastPos = lastPos > -1 ? lastPos : 0;
|
|
4339
|
-
switch (
|
|
4339
|
+
switch (f2.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 += f2.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 += f2.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 += f2.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 += f2.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 += f2.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 f2;
|
|
4413
4413
|
else if (lastPos < flen) {
|
|
4414
|
-
str +=
|
|
4414
|
+
str += f2.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, f2) {
|
|
13192
13192
|
if (Array.isArray(xs)) {
|
|
13193
13193
|
for (const x of xs)
|
|
13194
|
-
|
|
13194
|
+
f2(x);
|
|
13195
13195
|
} else {
|
|
13196
|
-
|
|
13196
|
+
f2(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, f2) {
|
|
13244
13244
|
return gen.scopeValue("func", {
|
|
13245
|
-
ref:
|
|
13246
|
-
code: snippets[
|
|
13245
|
+
ref: f2,
|
|
13246
|
+
code: snippets[f2.code] || (snippets[f2.code] = new code_1._Code(f2.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 f2 = formats[name];
|
|
18778
|
+
if (!f2)
|
|
18779
18779
|
throw new Error(`Unknown format "${name}"`);
|
|
18780
|
-
return
|
|
18780
|
+
return f2;
|
|
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 f2 of list)
|
|
18787
|
+
ajv.addFormat(f2, fs3[f2]);
|
|
18788
18788
|
}
|
|
18789
18789
|
module2.exports = exports2 = formatsPlugin;
|
|
18790
18790
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -21498,10 +21498,10 @@ var require_timestamp = __commonJS({
|
|
|
21498
21498
|
if (!matches)
|
|
21499
21499
|
return false;
|
|
21500
21500
|
const y = +matches[1];
|
|
21501
|
-
const
|
|
21501
|
+
const m = +matches[2];
|
|
21502
21502
|
const d = +matches[3];
|
|
21503
|
-
return
|
|
21504
|
-
|
|
21503
|
+
return m >= 1 && m <= 12 && d >= 1 && (d <= DAYS[m] || // leap year: https://tools.ietf.org/html/rfc3339#appendix-C
|
|
21504
|
+
m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0));
|
|
21505
21505
|
}
|
|
21506
21506
|
function validTime(str) {
|
|
21507
21507
|
const matches = TIME.exec(str);
|
|
@@ -23652,14 +23652,14 @@ var require_semver = __commonJS({
|
|
|
23652
23652
|
this.options = options;
|
|
23653
23653
|
this.loose = !!options.loose;
|
|
23654
23654
|
this.includePrerelease = !!options.includePrerelease;
|
|
23655
|
-
const
|
|
23656
|
-
if (!
|
|
23655
|
+
const m = version2.trim().match(options.loose ? re2[t.LOOSE] : re2[t.FULL]);
|
|
23656
|
+
if (!m) {
|
|
23657
23657
|
throw new TypeError(`Invalid Version: ${version2}`);
|
|
23658
23658
|
}
|
|
23659
23659
|
this.raw = version2;
|
|
23660
|
-
this.major = +
|
|
23661
|
-
this.minor = +
|
|
23662
|
-
this.patch = +
|
|
23660
|
+
this.major = +m[1];
|
|
23661
|
+
this.minor = +m[2];
|
|
23662
|
+
this.patch = +m[3];
|
|
23663
23663
|
if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
|
|
23664
23664
|
throw new TypeError("Invalid major version");
|
|
23665
23665
|
}
|
|
@@ -23669,10 +23669,10 @@ var require_semver = __commonJS({
|
|
|
23669
23669
|
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
|
|
23670
23670
|
throw new TypeError("Invalid patch version");
|
|
23671
23671
|
}
|
|
23672
|
-
if (!
|
|
23672
|
+
if (!m[4]) {
|
|
23673
23673
|
this.prerelease = [];
|
|
23674
23674
|
} else {
|
|
23675
|
-
this.prerelease =
|
|
23675
|
+
this.prerelease = m[4].split(".").map((id2) => {
|
|
23676
23676
|
if (/^[0-9]+$/.test(id2)) {
|
|
23677
23677
|
const num = +id2;
|
|
23678
23678
|
if (num >= 0 && num < MAX_SAFE_INTEGER) {
|
|
@@ -23682,7 +23682,7 @@ var require_semver = __commonJS({
|
|
|
23682
23682
|
return id2;
|
|
23683
23683
|
});
|
|
23684
23684
|
}
|
|
23685
|
-
this.build =
|
|
23685
|
+
this.build = m[5] ? m[5].split(".") : [];
|
|
23686
23686
|
this.format();
|
|
23687
23687
|
}
|
|
23688
23688
|
format() {
|
|
@@ -24490,20 +24490,20 @@ var require_range = __commonJS({
|
|
|
24490
24490
|
};
|
|
24491
24491
|
var replaceTilde = (comp, options) => {
|
|
24492
24492
|
const r = options.loose ? re2[t.TILDELOOSE] : re2[t.TILDE];
|
|
24493
|
-
return comp.replace(r, (_, M2,
|
|
24494
|
-
debug("tilde", comp, _, M2,
|
|
24493
|
+
return comp.replace(r, (_, M2, m, p, pr) => {
|
|
24494
|
+
debug("tilde", comp, _, M2, m, p, pr);
|
|
24495
24495
|
let ret;
|
|
24496
24496
|
if (isX(M2)) {
|
|
24497
24497
|
ret = "";
|
|
24498
|
-
} else if (isX(
|
|
24498
|
+
} else if (isX(m)) {
|
|
24499
24499
|
ret = `>=${M2}.0.0 <${+M2 + 1}.0.0-0`;
|
|
24500
24500
|
} else if (isX(p)) {
|
|
24501
|
-
ret = `>=${M2}.${
|
|
24501
|
+
ret = `>=${M2}.${m}.0 <${M2}.${+m + 1}.0-0`;
|
|
24502
24502
|
} else if (pr) {
|
|
24503
24503
|
debug("replaceTilde pr", pr);
|
|
24504
|
-
ret = `>=${M2}.${
|
|
24504
|
+
ret = `>=${M2}.${m}.${p}-${pr} <${M2}.${+m + 1}.0-0`;
|
|
24505
24505
|
} else {
|
|
24506
|
-
ret = `>=${M2}.${
|
|
24506
|
+
ret = `>=${M2}.${m}.${p} <${M2}.${+m + 1}.0-0`;
|
|
24507
24507
|
}
|
|
24508
24508
|
debug("tilde return", ret);
|
|
24509
24509
|
return ret;
|
|
@@ -24516,40 +24516,40 @@ var require_range = __commonJS({
|
|
|
24516
24516
|
debug("caret", comp, options);
|
|
24517
24517
|
const r = options.loose ? re2[t.CARETLOOSE] : re2[t.CARET];
|
|
24518
24518
|
const z = options.includePrerelease ? "-0" : "";
|
|
24519
|
-
return comp.replace(r, (_, M2,
|
|
24520
|
-
debug("caret", comp, _, M2,
|
|
24519
|
+
return comp.replace(r, (_, M2, m, p, pr) => {
|
|
24520
|
+
debug("caret", comp, _, M2, m, p, pr);
|
|
24521
24521
|
let ret;
|
|
24522
24522
|
if (isX(M2)) {
|
|
24523
24523
|
ret = "";
|
|
24524
|
-
} else if (isX(
|
|
24524
|
+
} else if (isX(m)) {
|
|
24525
24525
|
ret = `>=${M2}.0.0${z} <${+M2 + 1}.0.0-0`;
|
|
24526
24526
|
} else if (isX(p)) {
|
|
24527
24527
|
if (M2 === "0") {
|
|
24528
|
-
ret = `>=${M2}.${
|
|
24528
|
+
ret = `>=${M2}.${m}.0${z} <${M2}.${+m + 1}.0-0`;
|
|
24529
24529
|
} else {
|
|
24530
|
-
ret = `>=${M2}.${
|
|
24530
|
+
ret = `>=${M2}.${m}.0${z} <${+M2 + 1}.0.0-0`;
|
|
24531
24531
|
}
|
|
24532
24532
|
} else if (pr) {
|
|
24533
24533
|
debug("replaceCaret pr", pr);
|
|
24534
24534
|
if (M2 === "0") {
|
|
24535
|
-
if (
|
|
24536
|
-
ret = `>=${M2}.${
|
|
24535
|
+
if (m === "0") {
|
|
24536
|
+
ret = `>=${M2}.${m}.${p}-${pr} <${M2}.${m}.${+p + 1}-0`;
|
|
24537
24537
|
} else {
|
|
24538
|
-
ret = `>=${M2}.${
|
|
24538
|
+
ret = `>=${M2}.${m}.${p}-${pr} <${M2}.${+m + 1}.0-0`;
|
|
24539
24539
|
}
|
|
24540
24540
|
} else {
|
|
24541
|
-
ret = `>=${M2}.${
|
|
24541
|
+
ret = `>=${M2}.${m}.${p}-${pr} <${+M2 + 1}.0.0-0`;
|
|
24542
24542
|
}
|
|
24543
24543
|
} else {
|
|
24544
24544
|
debug("no pr");
|
|
24545
24545
|
if (M2 === "0") {
|
|
24546
|
-
if (
|
|
24547
|
-
ret = `>=${M2}.${
|
|
24546
|
+
if (m === "0") {
|
|
24547
|
+
ret = `>=${M2}.${m}.${p}${z} <${M2}.${m}.${+p + 1}-0`;
|
|
24548
24548
|
} else {
|
|
24549
|
-
ret = `>=${M2}.${
|
|
24549
|
+
ret = `>=${M2}.${m}.${p}${z} <${M2}.${+m + 1}.0-0`;
|
|
24550
24550
|
}
|
|
24551
24551
|
} else {
|
|
24552
|
-
ret = `>=${M2}.${
|
|
24552
|
+
ret = `>=${M2}.${m}.${p} <${+M2 + 1}.0.0-0`;
|
|
24553
24553
|
}
|
|
24554
24554
|
}
|
|
24555
24555
|
debug("caret return", ret);
|
|
@@ -24563,10 +24563,10 @@ var require_range = __commonJS({
|
|
|
24563
24563
|
var replaceXRange = (comp, options) => {
|
|
24564
24564
|
comp = comp.trim();
|
|
24565
24565
|
const r = options.loose ? re2[t.XRANGELOOSE] : re2[t.XRANGE];
|
|
24566
|
-
return comp.replace(r, (ret, gtlt, M2,
|
|
24567
|
-
debug("xRange", comp, ret, gtlt, M2,
|
|
24566
|
+
return comp.replace(r, (ret, gtlt, M2, m, p, pr) => {
|
|
24567
|
+
debug("xRange", comp, ret, gtlt, M2, m, p, pr);
|
|
24568
24568
|
const xM = isX(M2);
|
|
24569
|
-
const xm = xM || isX(
|
|
24569
|
+
const xm = xM || isX(m);
|
|
24570
24570
|
const xp = xm || isX(p);
|
|
24571
24571
|
const anyX = xp;
|
|
24572
24572
|
if (gtlt === "=" && anyX) {
|
|
@@ -24581,17 +24581,17 @@ var require_range = __commonJS({
|
|
|
24581
24581
|
}
|
|
24582
24582
|
} else if (gtlt && anyX) {
|
|
24583
24583
|
if (xm) {
|
|
24584
|
-
|
|
24584
|
+
m = 0;
|
|
24585
24585
|
}
|
|
24586
24586
|
p = 0;
|
|
24587
24587
|
if (gtlt === ">") {
|
|
24588
24588
|
gtlt = ">=";
|
|
24589
24589
|
if (xm) {
|
|
24590
24590
|
M2 = +M2 + 1;
|
|
24591
|
-
|
|
24591
|
+
m = 0;
|
|
24592
24592
|
p = 0;
|
|
24593
24593
|
} else {
|
|
24594
|
-
|
|
24594
|
+
m = +m + 1;
|
|
24595
24595
|
p = 0;
|
|
24596
24596
|
}
|
|
24597
24597
|
} else if (gtlt === "<=") {
|
|
@@ -24599,17 +24599,17 @@ var require_range = __commonJS({
|
|
|
24599
24599
|
if (xm) {
|
|
24600
24600
|
M2 = +M2 + 1;
|
|
24601
24601
|
} else {
|
|
24602
|
-
|
|
24602
|
+
m = +m + 1;
|
|
24603
24603
|
}
|
|
24604
24604
|
}
|
|
24605
24605
|
if (gtlt === "<") {
|
|
24606
24606
|
pr = "-0";
|
|
24607
24607
|
}
|
|
24608
|
-
ret = `${gtlt + M2}.${
|
|
24608
|
+
ret = `${gtlt + M2}.${m}.${p}${pr}`;
|
|
24609
24609
|
} else if (xm) {
|
|
24610
24610
|
ret = `>=${M2}.0.0${pr} <${+M2 + 1}.0.0-0`;
|
|
24611
24611
|
} else if (xp) {
|
|
24612
|
-
ret = `>=${M2}.${
|
|
24612
|
+
ret = `>=${M2}.${m}.0${pr} <${M2}.${+m + 1}.0-0`;
|
|
24613
24613
|
}
|
|
24614
24614
|
debug("xRange return", ret);
|
|
24615
24615
|
return ret;
|
|
@@ -24708,18 +24708,18 @@ var require_comparator = __commonJS({
|
|
|
24708
24708
|
}
|
|
24709
24709
|
parse(comp) {
|
|
24710
24710
|
const r = this.options.loose ? re2[t.COMPARATORLOOSE] : re2[t.COMPARATOR];
|
|
24711
|
-
const
|
|
24712
|
-
if (!
|
|
24711
|
+
const m = comp.match(r);
|
|
24712
|
+
if (!m) {
|
|
24713
24713
|
throw new TypeError(`Invalid comparator: ${comp}`);
|
|
24714
24714
|
}
|
|
24715
|
-
this.operator =
|
|
24715
|
+
this.operator = m[1] !== void 0 ? m[1] : "";
|
|
24716
24716
|
if (this.operator === "=") {
|
|
24717
24717
|
this.operator = "";
|
|
24718
24718
|
}
|
|
24719
|
-
if (!
|
|
24719
|
+
if (!m[2]) {
|
|
24720
24720
|
this.semver = ANY;
|
|
24721
24721
|
} else {
|
|
24722
|
-
this.semver = new SemVer(
|
|
24722
|
+
this.semver = new SemVer(m[2], this.options.loose);
|
|
24723
24723
|
}
|
|
24724
24724
|
}
|
|
24725
24725
|
toString() {
|
|
@@ -26377,17 +26377,17 @@ var require_set_lookup = __commonJS({
|
|
|
26377
26377
|
var require_types4 = __commonJS({
|
|
26378
26378
|
"node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/types/index.js"(exports2) {
|
|
26379
26379
|
"use strict";
|
|
26380
|
-
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o,
|
|
26380
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
26381
26381
|
if (k2 === void 0) k2 = k;
|
|
26382
26382
|
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
26383
|
-
return
|
|
26383
|
+
return m[k];
|
|
26384
26384
|
} });
|
|
26385
|
-
} : function(o,
|
|
26385
|
+
} : function(o, m, k, k2) {
|
|
26386
26386
|
if (k2 === void 0) k2 = k;
|
|
26387
|
-
o[k2] =
|
|
26387
|
+
o[k2] = m[k];
|
|
26388
26388
|
});
|
|
26389
|
-
var __exportStar = exports2 && exports2.__exportStar || function(
|
|
26390
|
-
for (var p in
|
|
26389
|
+
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
26390
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
26391
26391
|
};
|
|
26392
26392
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
26393
26393
|
__exportStar(require_tokens(), exports2);
|
|
@@ -26447,14 +26447,14 @@ var require_sets = __commonJS({
|
|
|
26447
26447
|
var require_util2 = __commonJS({
|
|
26448
26448
|
"node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/util.js"(exports2) {
|
|
26449
26449
|
"use strict";
|
|
26450
|
-
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o,
|
|
26450
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
26451
26451
|
if (k2 === void 0) k2 = k;
|
|
26452
26452
|
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
26453
|
-
return
|
|
26453
|
+
return m[k];
|
|
26454
26454
|
} });
|
|
26455
|
-
} : function(o,
|
|
26455
|
+
} : function(o, m, k, k2) {
|
|
26456
26456
|
if (k2 === void 0) k2 = k;
|
|
26457
|
-
o[k2] =
|
|
26457
|
+
o[k2] = m[k];
|
|
26458
26458
|
});
|
|
26459
26459
|
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
|
|
26460
26460
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
@@ -26518,14 +26518,14 @@ var require_util2 = __commonJS({
|
|
|
26518
26518
|
var require_tokenizer = __commonJS({
|
|
26519
26519
|
"node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/tokenizer.js"(exports2) {
|
|
26520
26520
|
"use strict";
|
|
26521
|
-
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o,
|
|
26521
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
26522
26522
|
if (k2 === void 0) k2 = k;
|
|
26523
26523
|
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
26524
|
-
return
|
|
26524
|
+
return m[k];
|
|
26525
26525
|
} });
|
|
26526
|
-
} : function(o,
|
|
26526
|
+
} : function(o, m, k, k2) {
|
|
26527
26527
|
if (k2 === void 0) k2 = k;
|
|
26528
|
-
o[k2] =
|
|
26528
|
+
o[k2] = m[k];
|
|
26529
26529
|
});
|
|
26530
26530
|
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
|
|
26531
26531
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
@@ -26819,14 +26819,14 @@ var require_tokenizer = __commonJS({
|
|
|
26819
26819
|
var require_sets_lookup = __commonJS({
|
|
26820
26820
|
"node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/sets-lookup.js"(exports2) {
|
|
26821
26821
|
"use strict";
|
|
26822
|
-
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o,
|
|
26822
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
26823
26823
|
if (k2 === void 0) k2 = k;
|
|
26824
26824
|
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
26825
|
-
return
|
|
26825
|
+
return m[k];
|
|
26826
26826
|
} });
|
|
26827
|
-
} : function(o,
|
|
26827
|
+
} : function(o, m, k, k2) {
|
|
26828
26828
|
if (k2 === void 0) k2 = k;
|
|
26829
|
-
o[k2] =
|
|
26829
|
+
o[k2] = m[k];
|
|
26830
26830
|
});
|
|
26831
26831
|
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
|
|
26832
26832
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
@@ -26874,14 +26874,14 @@ var require_sets_lookup = __commonJS({
|
|
|
26874
26874
|
var require_write_set_tokens = __commonJS({
|
|
26875
26875
|
"node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/write-set-tokens.js"(exports2) {
|
|
26876
26876
|
"use strict";
|
|
26877
|
-
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o,
|
|
26877
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
26878
26878
|
if (k2 === void 0) k2 = k;
|
|
26879
26879
|
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
26880
|
-
return
|
|
26880
|
+
return m[k];
|
|
26881
26881
|
} });
|
|
26882
|
-
} : function(o,
|
|
26882
|
+
} : function(o, m, k, k2) {
|
|
26883
26883
|
if (k2 === void 0) k2 = k;
|
|
26884
|
-
o[k2] =
|
|
26884
|
+
o[k2] = m[k];
|
|
26885
26885
|
});
|
|
26886
26886
|
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
|
|
26887
26887
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
@@ -27027,17 +27027,17 @@ var require_reconstruct = __commonJS({
|
|
|
27027
27027
|
var require_dist3 = __commonJS({
|
|
27028
27028
|
"node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/index.js"(exports2, module2) {
|
|
27029
27029
|
"use strict";
|
|
27030
|
-
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o,
|
|
27030
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
27031
27031
|
if (k2 === void 0) k2 = k;
|
|
27032
27032
|
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
27033
|
-
return
|
|
27033
|
+
return m[k];
|
|
27034
27034
|
} });
|
|
27035
|
-
} : function(o,
|
|
27035
|
+
} : function(o, m, k, k2) {
|
|
27036
27036
|
if (k2 === void 0) k2 = k;
|
|
27037
|
-
o[k2] =
|
|
27037
|
+
o[k2] = m[k];
|
|
27038
27038
|
});
|
|
27039
|
-
var __exportStar = exports2 && exports2.__exportStar || function(
|
|
27040
|
-
for (var p in
|
|
27039
|
+
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
27040
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
27041
27041
|
};
|
|
27042
27042
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
27043
27043
|
exports2.types = void 0;
|
|
@@ -27162,7 +27162,7 @@ var require_pretty_print = __commonJS({
|
|
|
27162
27162
|
return fName;
|
|
27163
27163
|
}
|
|
27164
27164
|
function parseMeta(meta) {
|
|
27165
|
-
if (Array.isArray(meta)) return meta.map((
|
|
27165
|
+
if (Array.isArray(meta)) return meta.map((m) => parseMeta(m));
|
|
27166
27166
|
if (typeof meta === "symbol") return meta.toString();
|
|
27167
27167
|
if (typeof meta === "function") return parseFunctionName(meta);
|
|
27168
27168
|
return meta;
|
|
@@ -28551,10 +28551,10 @@ var require_find_my_way = __commonJS({
|
|
|
28551
28551
|
};
|
|
28552
28552
|
for (const i in httpMethods) {
|
|
28553
28553
|
if (!httpMethods.hasOwnProperty(i)) continue;
|
|
28554
|
-
const
|
|
28555
|
-
const methodName =
|
|
28554
|
+
const m = httpMethods[i];
|
|
28555
|
+
const methodName = m.toLowerCase();
|
|
28556
28556
|
Router.prototype[methodName] = function(path3, handler, store) {
|
|
28557
|
-
return this.on(
|
|
28557
|
+
return this.on(m, path3, handler, store);
|
|
28558
28558
|
};
|
|
28559
28559
|
}
|
|
28560
28560
|
Router.prototype.all = function(path3, handler, store) {
|
|
@@ -33051,8 +33051,8 @@ var require_getPluginName = __commonJS({
|
|
|
33051
33051
|
}
|
|
33052
33052
|
};
|
|
33053
33053
|
function extractPluginName(stack) {
|
|
33054
|
-
const
|
|
33055
|
-
return
|
|
33054
|
+
const m = stack.match(fpStackTracePattern);
|
|
33055
|
+
return m ? m[1].split(/[/\\]/).slice(-1)[0].match(fileNamePattern)[1] : "anonymous";
|
|
33056
33056
|
}
|
|
33057
33057
|
module2.exports.extractPluginName = extractPluginName;
|
|
33058
33058
|
}
|
|
@@ -34806,8 +34806,8 @@ var require_util3 = __commonJS({
|
|
|
34806
34806
|
}
|
|
34807
34807
|
var KEEPALIVE_TIMEOUT_EXPR = /timeout=(\d+)/;
|
|
34808
34808
|
function parseKeepAliveTimeout(val) {
|
|
34809
|
-
const
|
|
34810
|
-
return
|
|
34809
|
+
const m = val.match(KEEPALIVE_TIMEOUT_EXPR);
|
|
34810
|
+
return m ? parseInt(m[1], 10) * 1e3 : null;
|
|
34811
34811
|
}
|
|
34812
34812
|
function headerNameToString(value) {
|
|
34813
34813
|
return typeof value === "string" ? headerNameLowerCasedRecord[value] ?? value.toLowerCase() : tree.lookup(value) ?? value.toString("latin1").toLowerCase();
|
|
@@ -35009,11 +35009,11 @@ var require_util3 = __commonJS({
|
|
|
35009
35009
|
var rangeHeaderRegex = /^bytes (\d+)-(\d+)\/(\d+)?$/;
|
|
35010
35010
|
function parseRangeHeader(range) {
|
|
35011
35011
|
if (range == null || range === "") return { start: 0, end: null, size: null };
|
|
35012
|
-
const
|
|
35013
|
-
return
|
|
35014
|
-
start: parseInt(
|
|
35015
|
-
end:
|
|
35016
|
-
size:
|
|
35012
|
+
const m = range ? range.match(rangeHeaderRegex) : null;
|
|
35013
|
+
return m ? {
|
|
35014
|
+
start: parseInt(m[1]),
|
|
35015
|
+
end: m[2] ? parseInt(m[2]) : null,
|
|
35016
|
+
size: m[3] ? parseInt(m[3]) : null
|
|
35017
35017
|
} : null;
|
|
35018
35018
|
}
|
|
35019
35019
|
function addListener(obj, name, listener) {
|
|
@@ -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(f2, args) {
|
|
54475
54475
|
try {
|
|
54476
|
-
return
|
|
54476
|
+
return f2.apply(this, args);
|
|
54477
54477
|
} catch (e) {
|
|
54478
54478
|
wasm.__wbindgen_export_0(addHeapObject(e));
|
|
54479
54479
|
}
|
|
@@ -54927,20 +54927,21 @@ var readConfigFile = async () => {
|
|
|
54927
54927
|
const config = await import_promises.default.readFile(CONFIG_FILE, "utf-8");
|
|
54928
54928
|
return JSON.parse(config);
|
|
54929
54929
|
} catch {
|
|
54930
|
-
const
|
|
54931
|
-
const
|
|
54932
|
-
const
|
|
54930
|
+
const name = await question("Enter Provider Name: ");
|
|
54931
|
+
const apiKey = await question("Enter Provider API KEY: ");
|
|
54932
|
+
const baseUrl = await question("Enter Provider URL: ");
|
|
54933
|
+
const model = await question("Enter MODEL Name: ");
|
|
54933
54934
|
const config = Object.assign({}, DEFAULT_CONFIG, {
|
|
54934
54935
|
Providers: [
|
|
54935
54936
|
{
|
|
54936
|
-
name
|
|
54937
|
+
name,
|
|
54937
54938
|
api_base_url: baseUrl,
|
|
54938
54939
|
api_key: apiKey,
|
|
54939
54940
|
models: [model]
|
|
54940
54941
|
}
|
|
54941
54942
|
],
|
|
54942
54943
|
Router: {
|
|
54943
|
-
default:
|
|
54944
|
+
default: `${name},${model}`
|
|
54944
54945
|
}
|
|
54945
54946
|
});
|
|
54946
54947
|
await writeConfigFile(config);
|
|
@@ -54957,7 +54958,7 @@ var initConfig = async () => {
|
|
|
54957
54958
|
return config;
|
|
54958
54959
|
};
|
|
54959
54960
|
|
|
54960
|
-
// node_modules/.pnpm/@musistudio+llms@1.0.
|
|
54961
|
+
// node_modules/.pnpm/@musistudio+llms@1.0.4_ws@8.18.3_zod@3.25.67/node_modules/@musistudio/llms/dist/esm/server.mjs
|
|
54961
54962
|
var import_fastify = __toESM(require_fastify(), 1);
|
|
54962
54963
|
var import_cors = __toESM(require_cors(), 1);
|
|
54963
54964
|
var import_fs = require("fs");
|
|
@@ -55033,7 +55034,7 @@ var j = class {
|
|
|
55033
55034
|
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(", ")}`;
|
|
55034
55035
|
}
|
|
55035
55036
|
};
|
|
55036
|
-
function
|
|
55037
|
+
function f(...i) {
|
|
55037
55038
|
if (console.log(...i), !(process.env.LOG === "true")) return;
|
|
55038
55039
|
let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(i) ? i.map((r) => typeof r == "object" ? JSON.stringify(r) : String(r)).join(" ") : ""}
|
|
55039
55040
|
`, o = process.env.LOG_FILE || "app.log";
|
|
@@ -55050,59 +55051,59 @@ async function X(i, e, t) {
|
|
|
55050
55051
|
}
|
|
55051
55052
|
function Q(i, e, t) {
|
|
55052
55053
|
let n = new Headers({ "Content-Type": "application/json" });
|
|
55053
|
-
t.headers && Object.entries(t.headers).forEach(([
|
|
55054
|
-
n.set(
|
|
55054
|
+
t.headers && Object.entries(t.headers).forEach(([u, d]) => {
|
|
55055
|
+
n.set(u, d);
|
|
55055
55056
|
});
|
|
55056
55057
|
let o, r = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
|
|
55057
55058
|
if (t.signal) {
|
|
55058
|
-
let
|
|
55059
|
-
t.signal.addEventListener("abort", d), r.addEventListener("abort", d), o =
|
|
55059
|
+
let u = new AbortController(), d = () => u.abort();
|
|
55060
|
+
t.signal.addEventListener("abort", d), r.addEventListener("abort", d), o = u.signal;
|
|
55060
55061
|
} else o = r;
|
|
55061
|
-
let
|
|
55062
|
-
return t.httpsProxy && (
|
|
55062
|
+
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())), f("final request:", typeof i == "string" ? i : i.toString(), t.httpsProxy, l), fetch(typeof i == "string" ? i : i.toString(), l);
|
|
55063
55064
|
}
|
|
55064
55065
|
var Z = async (i) => {
|
|
55065
55066
|
i.get("/", async (t, n) => ({ message: "LLMs API", version: "1.0.0" })), i.get("/health", async (t, n) => ({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
55066
55067
|
let e = i._server.transformerService.getTransformersWithEndpoint();
|
|
55067
55068
|
for (let { name: t, transformer: n } of e) n.endPoint && i.post(n.endPoint, async (o, r) => {
|
|
55068
|
-
let
|
|
55069
|
-
if (!d) throw A(`Provider '${
|
|
55070
|
-
let a =
|
|
55069
|
+
let l = o.body, u = o.provider, d = i._server.providerService.getProvider(u);
|
|
55070
|
+
if (!d) throw A(`Provider '${u}' not found`, 404, "provider_not_found");
|
|
55071
|
+
let a = l, c = {};
|
|
55071
55072
|
if (typeof n.transformRequestOut == "function") {
|
|
55072
|
-
let s = n.transformRequestOut(
|
|
55073
|
-
s.body ? (a = s.body,
|
|
55073
|
+
let s = n.transformRequestOut(l);
|
|
55074
|
+
s.body ? (a = s.body, c = s.config || {}) : a = s;
|
|
55074
55075
|
}
|
|
55075
55076
|
if (d.transformer?.use?.length) for (let s of d.transformer.use) {
|
|
55076
|
-
let
|
|
55077
|
-
if (!
|
|
55078
|
-
let
|
|
55079
|
-
|
|
55077
|
+
let m = i._server.transformerService.getTransformer(s);
|
|
55078
|
+
if (!m || typeof m.transformRequestIn != "function") continue;
|
|
55079
|
+
let g = m.transformRequestIn(a, d);
|
|
55080
|
+
g.body ? (a = g.body, c = { ...c, ...g.config }) : a = g;
|
|
55080
55081
|
}
|
|
55081
55082
|
if (d.transformer?.[o.body.model]?.use?.length) for (let s of d.transformer[o.body.model].use) {
|
|
55082
|
-
let
|
|
55083
|
-
!
|
|
55083
|
+
let m = i._server.transformerService.getTransformer(s);
|
|
55084
|
+
!m || typeof m.transformRequestIn != "function" || (a = m.transformRequestIn(a, d));
|
|
55084
55085
|
}
|
|
55085
|
-
let
|
|
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 || {} } });
|
|
55086
55087
|
if (!v.ok) {
|
|
55087
55088
|
let s = await v.text();
|
|
55088
|
-
throw
|
|
55089
|
+
throw f(`Error response from ${y}: ${s}`), A(`Error from provider: ${s}`, v.status, "provider_response_error");
|
|
55089
55090
|
}
|
|
55090
55091
|
let h = v;
|
|
55091
55092
|
if (d.transformer?.use?.length) for (let s of d.transformer.use) {
|
|
55092
|
-
let
|
|
55093
|
-
!
|
|
55093
|
+
let m = i._server.transformerService.getTransformer(s);
|
|
55094
|
+
!m || typeof m.transformResponseOut != "function" || (h = await m.transformResponseOut(h));
|
|
55094
55095
|
}
|
|
55095
55096
|
if (d.transformer?.[o.body.model]?.use?.length) for (let s of d.transformer[o.body.model].use) {
|
|
55096
|
-
let
|
|
55097
|
-
!
|
|
55097
|
+
let m = i._server.transformerService.getTransformer(s);
|
|
55098
|
+
!m || typeof m.transformResponseOut != "function" || (h = await m.transformResponseOut(h));
|
|
55098
55099
|
}
|
|
55099
|
-
return n.transformResponseIn && (h = await n.transformResponseIn(h)), h.ok || r.code(h.status),
|
|
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();
|
|
55100
55101
|
});
|
|
55101
55102
|
i.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) => {
|
|
55102
|
-
let { name: o, type: r, baseUrl:
|
|
55103
|
+
let { name: o, type: r, baseUrl: l, apiKey: u, models: d } = t.body;
|
|
55103
55104
|
if (!o?.trim()) throw A("Provider name is required", 400, "invalid_request");
|
|
55104
|
-
if (!
|
|
55105
|
-
if (!
|
|
55105
|
+
if (!l || !ae(l)) throw A("Valid base URL is required", 400, "invalid_request");
|
|
55106
|
+
if (!u?.trim()) throw A("API key is required", 400, "invalid_request");
|
|
55106
55107
|
if (!d || !Array.isArray(d) || d.length === 0) throw A("At least one model is required", 400, "invalid_request");
|
|
55107
55108
|
if (i._server.providerService.getProvider(id)) throw A(`Provider with ID '${id}' already exists`, 400, "provider_exists");
|
|
55108
55109
|
return i._server.providerService.registerProvider(t.body);
|
|
@@ -55176,9 +55177,9 @@ var J = class {
|
|
|
55176
55177
|
e.forEach((t) => {
|
|
55177
55178
|
try {
|
|
55178
55179
|
if (!t.name || !t.api_base_url || !t.api_key) return;
|
|
55179
|
-
this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: this.parseTransformerConfig(t.transformer) || {} }),
|
|
55180
|
+
this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: this.parseTransformerConfig(t.transformer) || {} }), f(`${t.name} provider registered`);
|
|
55180
55181
|
} catch (n) {
|
|
55181
|
-
|
|
55182
|
+
f(`${t.name} provider registered error: ${n}`);
|
|
55182
55183
|
}
|
|
55183
55184
|
});
|
|
55184
55185
|
}
|
|
@@ -55200,11 +55201,11 @@ var J = class {
|
|
|
55200
55201
|
if (!n) return null;
|
|
55201
55202
|
let o = { ...n, ...t, updatedAt: /* @__PURE__ */ new Date() };
|
|
55202
55203
|
return this.providers.set(e, o), t.models && (n.models.forEach((r) => {
|
|
55203
|
-
let
|
|
55204
|
-
this.modelRoutes.delete(
|
|
55204
|
+
let l = `${n.id},${r}`;
|
|
55205
|
+
this.modelRoutes.delete(l), this.modelRoutes.delete(r);
|
|
55205
55206
|
}), t.models.forEach((r) => {
|
|
55206
|
-
let
|
|
55207
|
-
this.modelRoutes.set(
|
|
55207
|
+
let l = `${n.id},${r}`, u = { providerId: n.id, model: r, fullModel: l };
|
|
55208
|
+
this.modelRoutes.set(l, u), this.modelRoutes.has(r) || this.modelRoutes.set(r, u);
|
|
55208
55209
|
})), o;
|
|
55209
55210
|
}
|
|
55210
55211
|
deleteProvider(e) {
|
|
@@ -55253,37 +55254,37 @@ var J = class {
|
|
|
55253
55254
|
}), { object: "list", data: e };
|
|
55254
55255
|
}
|
|
55255
55256
|
};
|
|
55256
|
-
var
|
|
55257
|
+
var M = class {
|
|
55257
55258
|
name = "Anthropic";
|
|
55258
55259
|
endPoint = "/v1/messages";
|
|
55259
55260
|
transformRequestOut(e) {
|
|
55260
|
-
|
|
55261
|
-
let t = []
|
|
55261
|
+
f("Anthropic Request:", JSON.stringify(e, null, 2));
|
|
55262
|
+
let t = [];
|
|
55262
55263
|
if (e.system) {
|
|
55263
55264
|
if (typeof e.system == "string") t.push({ role: "system", content: e.system });
|
|
55264
55265
|
else if (Array.isArray(e.system)) {
|
|
55265
|
-
let
|
|
55266
|
-
t.push(
|
|
55267
|
-
}
|
|
55268
|
-
}
|
|
55269
|
-
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((
|
|
55270
|
-
if (
|
|
55271
|
-
let
|
|
55272
|
-
if (typeof
|
|
55273
|
-
else if (Array.isArray(
|
|
55274
|
-
if (
|
|
55275
|
-
let
|
|
55276
|
-
|
|
55277
|
-
let
|
|
55278
|
-
t.push(
|
|
55266
|
+
let r = e.system.filter((l) => l.type === "text" && l.text).map((l) => ({ type: "text", text: l.text, cache_control: l.cache_control }));
|
|
55267
|
+
t.push({ role: "system", content: r });
|
|
55268
|
+
}
|
|
55269
|
+
}
|
|
55270
|
+
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((r, l) => {
|
|
55271
|
+
if (r.role === "user" || r.role === "assistant") {
|
|
55272
|
+
let u = { role: r.role, content: null };
|
|
55273
|
+
if (typeof r.content == "string") t.push({ role: r.role, content: r.content });
|
|
55274
|
+
else if (Array.isArray(r.content)) {
|
|
55275
|
+
if (r.role === "user") {
|
|
55276
|
+
let d = r.content.filter((c) => c.type === "tool_result" && c.tool_use_id);
|
|
55277
|
+
d.length && d.forEach((c, y) => {
|
|
55278
|
+
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
|
+
t.push(v);
|
|
55279
55280
|
});
|
|
55280
|
-
let
|
|
55281
|
-
|
|
55282
|
-
} else if (
|
|
55283
|
-
let
|
|
55284
|
-
|
|
55285
|
-
let
|
|
55286
|
-
|
|
55281
|
+
let a = r.content.filter((c) => c.type === "text" && c.text);
|
|
55282
|
+
a.length && t.push({ role: "user", content: a });
|
|
55283
|
+
} else if (r.role === "assistant") {
|
|
55284
|
+
let d = r.content.filter((c) => c.type === "text" && c.text);
|
|
55285
|
+
d.length && t.push(...d.map((c) => ({ role: "assistant", content: c.text })));
|
|
55286
|
+
let a = r.content.filter((c) => c.type === "tool_use" && c.id);
|
|
55287
|
+
a.length && t.push({ role: "assistant", content: null, tool_calls: a.map((c) => ({ id: c.id, type: "function", function: { name: c.name, arguments: JSON.stringify(c.input || {}) } })) });
|
|
55287
55288
|
}
|
|
55288
55289
|
return;
|
|
55289
55290
|
}
|
|
@@ -55305,14 +55306,14 @@ var N = class {
|
|
|
55305
55306
|
}
|
|
55306
55307
|
async convertOpenAIStreamToAnthropic(e) {
|
|
55307
55308
|
return new ReadableStream({ async start(n) {
|
|
55308
|
-
let o = new TextEncoder(), r = `msg_${Date.now()}`,
|
|
55309
|
+
let o = new TextEncoder(), r = `msg_${Date.now()}`, l = "unknown", u = false, d = false, a = false, c = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), v = 0, h = 0, p = 0, s = false, m = false, g = 0, k = (S) => {
|
|
55309
55310
|
if (!s) try {
|
|
55310
55311
|
n.enqueue(S);
|
|
55311
|
-
let
|
|
55312
|
-
|
|
55313
|
-
} catch (
|
|
55314
|
-
if (
|
|
55315
|
-
else throw
|
|
55312
|
+
let x = new TextDecoder().decode(S);
|
|
55313
|
+
f("send data:", x.trim());
|
|
55314
|
+
} catch (x) {
|
|
55315
|
+
if (x instanceof TypeError && x.message.includes("Controller is already closed")) s = true;
|
|
55316
|
+
else throw f(`send data error: ${x.message}`), x;
|
|
55316
55317
|
}
|
|
55317
55318
|
}, D = () => {
|
|
55318
55319
|
if (!s) try {
|
|
@@ -55324,106 +55325,106 @@ var N = class {
|
|
|
55324
55325
|
}, I = null;
|
|
55325
55326
|
try {
|
|
55326
55327
|
I = e.getReader();
|
|
55327
|
-
let S = new TextDecoder(),
|
|
55328
|
+
let S = new TextDecoder(), x = "";
|
|
55328
55329
|
for (; !s; ) {
|
|
55329
55330
|
let { done: ee, value: te } = await I.read();
|
|
55330
55331
|
if (ee) break;
|
|
55331
|
-
|
|
55332
|
-
let W =
|
|
55332
|
+
x += S.decode(te, { stream: true });
|
|
55333
|
+
let W = x.split(`
|
|
55333
55334
|
`);
|
|
55334
|
-
|
|
55335
|
+
x = W.pop() || "";
|
|
55335
55336
|
for (let G of W) {
|
|
55336
55337
|
if (s || a) break;
|
|
55337
55338
|
if (!G.startsWith("data: ")) continue;
|
|
55338
55339
|
let z = G.slice(6);
|
|
55339
55340
|
if (z !== "[DONE]") try {
|
|
55340
55341
|
let T = JSON.parse(z);
|
|
55341
|
-
if (v++,
|
|
55342
|
-
|
|
55343
|
-
let b = { type: "message_start", message: { id: r, type: "message", role: "assistant", content: [], model:
|
|
55342
|
+
if (v++, f("Original Response:", JSON.stringify(T, null, 2)), l = T.model || l, !u && !s && !a) {
|
|
55343
|
+
u = true;
|
|
55344
|
+
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 } } };
|
|
55344
55345
|
k(o.encode(`event: message_start
|
|
55345
55346
|
data: ${JSON.stringify(b)}
|
|
55346
55347
|
|
|
55347
55348
|
`));
|
|
55348
55349
|
}
|
|
55349
|
-
let
|
|
55350
|
-
if (!
|
|
55351
|
-
if (
|
|
55352
|
-
if (!
|
|
55353
|
-
let b = { type: "content_block_start", index:
|
|
55350
|
+
let P = T.choices?.[0];
|
|
55351
|
+
if (!P) continue;
|
|
55352
|
+
if (P?.delta?.thinking && !s && !a) {
|
|
55353
|
+
if (!m) {
|
|
55354
|
+
let b = { type: "content_block_start", index: g, content_block: { type: "thinking", thinking: "" } };
|
|
55354
55355
|
k(o.encode(`event: content_block_start
|
|
55355
55356
|
data: ${JSON.stringify(b)}
|
|
55356
55357
|
|
|
55357
|
-
`)),
|
|
55358
|
+
`)), m = true;
|
|
55358
55359
|
}
|
|
55359
|
-
if (
|
|
55360
|
-
let b = { type: "content_block_delta", index:
|
|
55360
|
+
if (P.delta.thinking.signature) {
|
|
55361
|
+
let b = { type: "content_block_delta", index: g, delta: { type: "signature_delta", signature: P.delta.thinking.signature } };
|
|
55361
55362
|
k(o.encode(`event: content_block_delta
|
|
55362
55363
|
data: ${JSON.stringify(b)}
|
|
55363
55364
|
|
|
55364
55365
|
`));
|
|
55365
|
-
let _ = { type: "content_block_stop", index:
|
|
55366
|
+
let _ = { type: "content_block_stop", index: g };
|
|
55366
55367
|
k(o.encode(`event: content_block_stop
|
|
55367
55368
|
data: ${JSON.stringify(_)}
|
|
55368
55369
|
|
|
55369
|
-
`)),
|
|
55370
|
-
} else if (
|
|
55371
|
-
let b = { type: "content_block_delta", index:
|
|
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 || "" } };
|
|
55372
55373
|
k(o.encode(`event: content_block_delta
|
|
55373
55374
|
data: ${JSON.stringify(b)}
|
|
55374
55375
|
|
|
55375
55376
|
`));
|
|
55376
55377
|
}
|
|
55377
55378
|
}
|
|
55378
|
-
if (
|
|
55379
|
+
if (P?.delta?.content && !s && !a) {
|
|
55379
55380
|
if (h++, !d && !a) {
|
|
55380
55381
|
d = true;
|
|
55381
|
-
let b = { type: "content_block_start", index:
|
|
55382
|
+
let b = { type: "content_block_start", index: g, content_block: { type: "text", text: "" } };
|
|
55382
55383
|
k(o.encode(`event: content_block_start
|
|
55383
55384
|
data: ${JSON.stringify(b)}
|
|
55384
55385
|
|
|
55385
55386
|
`));
|
|
55386
55387
|
}
|
|
55387
55388
|
if (!s && !a) {
|
|
55388
|
-
let b = { type: "content_block_delta", index:
|
|
55389
|
+
let b = { type: "content_block_delta", index: g, delta: { type: "text_delta", text: P.delta.content } };
|
|
55389
55390
|
k(o.encode(`event: content_block_delta
|
|
55390
55391
|
data: ${JSON.stringify(b)}
|
|
55391
55392
|
|
|
55392
55393
|
`));
|
|
55393
55394
|
}
|
|
55394
55395
|
}
|
|
55395
|
-
if (
|
|
55396
|
-
|
|
55396
|
+
if (P?.delta?.tool_calls && !s && !a) {
|
|
55397
|
+
p++;
|
|
55397
55398
|
let b = /* @__PURE__ */ new Set();
|
|
55398
|
-
for (let _ of
|
|
55399
|
+
for (let _ of P.delta.tool_calls) {
|
|
55399
55400
|
if (s) break;
|
|
55400
55401
|
let R = _.index ?? 0;
|
|
55401
55402
|
if (b.has(R)) continue;
|
|
55402
|
-
if (b.add(R), !
|
|
55403
|
-
let C = d ?
|
|
55403
|
+
if (b.add(R), !y.has(R)) {
|
|
55404
|
+
let C = d ? y.size + 1 : y.size;
|
|
55404
55405
|
if (C !== 0) {
|
|
55405
|
-
|
|
55406
|
-
let ne = { type: "content_block_stop", index:
|
|
55406
|
+
f("content_block_stop2");
|
|
55407
|
+
let ne = { type: "content_block_stop", index: g };
|
|
55407
55408
|
k(o.encode(`event: content_block_stop
|
|
55408
55409
|
data: ${JSON.stringify(ne)}
|
|
55409
55410
|
|
|
55410
|
-
`)),
|
|
55411
|
+
`)), g++;
|
|
55411
55412
|
}
|
|
55412
|
-
|
|
55413
|
-
let E = _.id || `call_${Date.now()}_${R}`, w = _.function?.name || `tool_${R}`, O = { type: "content_block_start", index:
|
|
55413
|
+
y.set(R, C);
|
|
55414
|
+
let E = _.id || `call_${Date.now()}_${R}`, w = _.function?.name || `tool_${R}`, O = { type: "content_block_start", index: g, content_block: { type: "tool_use", id: E, name: w, input: {} } };
|
|
55414
55415
|
k(o.encode(`event: content_block_start
|
|
55415
55416
|
data: ${JSON.stringify(O)}
|
|
55416
55417
|
|
|
55417
55418
|
`));
|
|
55418
55419
|
let L = { id: E, name: w, arguments: "", contentBlockIndex: C };
|
|
55419
|
-
|
|
55420
|
+
c.set(R, L);
|
|
55420
55421
|
} else if (_.id && _.function?.name) {
|
|
55421
|
-
let C =
|
|
55422
|
+
let C = c.get(R);
|
|
55422
55423
|
C.id.startsWith("call_") && C.name.startsWith("tool_") && (C.id = _.id, C.name = _.function.name);
|
|
55423
55424
|
}
|
|
55424
55425
|
if (_.function?.arguments && !s && !a) {
|
|
55425
|
-
if (
|
|
55426
|
-
let E =
|
|
55426
|
+
if (y.get(R) === void 0) continue;
|
|
55427
|
+
let E = c.get(R);
|
|
55427
55428
|
if (E) {
|
|
55428
55429
|
E.arguments += _.function.arguments;
|
|
55429
55430
|
try {
|
|
@@ -55431,21 +55432,21 @@ data: ${JSON.stringify(O)}
|
|
|
55431
55432
|
if (O.startsWith("{") && O.endsWith("}")) try {
|
|
55432
55433
|
w = JSON.parse(O);
|
|
55433
55434
|
} catch (L) {
|
|
55434
|
-
|
|
55435
|
+
f("Tool call index:", R, "error", L.message);
|
|
55435
55436
|
}
|
|
55436
55437
|
} catch (w) {
|
|
55437
|
-
|
|
55438
|
+
f("Tool call index:", R, "error", w.message);
|
|
55438
55439
|
}
|
|
55439
55440
|
}
|
|
55440
55441
|
try {
|
|
55441
|
-
let w = { type: "content_block_delta", index:
|
|
55442
|
+
let w = { type: "content_block_delta", index: g, delta: { type: "input_json_delta", partial_json: _.function.arguments } };
|
|
55442
55443
|
k(o.encode(`event: content_block_delta
|
|
55443
55444
|
data: ${JSON.stringify(w)}
|
|
55444
55445
|
|
|
55445
55446
|
`));
|
|
55446
55447
|
} catch {
|
|
55447
55448
|
try {
|
|
55448
|
-
let O = _.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), L = { type: "content_block_delta", index:
|
|
55449
|
+
let O = _.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), L = { type: "content_block_delta", index: g, delta: { type: "input_json_delta", partial_json: O } };
|
|
55449
55450
|
k(o.encode(`event: content_block_delta
|
|
55450
55451
|
data: ${JSON.stringify(L)}
|
|
55451
55452
|
|
|
@@ -55457,17 +55458,17 @@ data: ${JSON.stringify(L)}
|
|
|
55457
55458
|
}
|
|
55458
55459
|
}
|
|
55459
55460
|
}
|
|
55460
|
-
if (
|
|
55461
|
-
if (a = true, h === 0 &&
|
|
55462
|
-
|
|
55463
|
-
let b = { type: "content_block_stop", index:
|
|
55461
|
+
if (P?.finish_reason && !s && !a) {
|
|
55462
|
+
if (a = true, h === 0 && p === 0 && console.error("Warning: No content in the stream response!"), (d || p > 0) && !s) {
|
|
55463
|
+
f("content_block_stop hasTextContentStarted");
|
|
55464
|
+
let b = { type: "content_block_stop", index: g };
|
|
55464
55465
|
k(o.encode(`event: content_block_stop
|
|
55465
55466
|
data: ${JSON.stringify(b)}
|
|
55466
55467
|
|
|
55467
55468
|
`));
|
|
55468
55469
|
}
|
|
55469
55470
|
if (!s) {
|
|
55470
|
-
let R = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[
|
|
55471
|
+
let R = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[P.finish_reason] || "end_turn", stop_sequence: null }, usage: { input_tokens: T.usage?.prompt_tokens || 0, output_tokens: T.usage?.completion_tokens || 0 } };
|
|
55471
55472
|
k(o.encode(`event: message_delta
|
|
55472
55473
|
data: ${JSON.stringify(R)}
|
|
55473
55474
|
|
|
@@ -55483,7 +55484,7 @@ data: ${JSON.stringify(b)}
|
|
|
55483
55484
|
break;
|
|
55484
55485
|
}
|
|
55485
55486
|
} catch (T) {
|
|
55486
|
-
|
|
55487
|
+
f(`parseError: ${T.name} message: ${T.message} stack: ${T.stack} data: ${z}`);
|
|
55487
55488
|
}
|
|
55488
55489
|
}
|
|
55489
55490
|
}
|
|
@@ -55491,8 +55492,8 @@ data: ${JSON.stringify(b)}
|
|
|
55491
55492
|
} catch (S) {
|
|
55492
55493
|
if (!s) try {
|
|
55493
55494
|
n.error(S);
|
|
55494
|
-
} catch (
|
|
55495
|
-
console.error(
|
|
55495
|
+
} catch (x) {
|
|
55496
|
+
console.error(x);
|
|
55496
55497
|
}
|
|
55497
55498
|
} finally {
|
|
55498
55499
|
if (I) try {
|
|
@@ -55502,29 +55503,29 @@ data: ${JSON.stringify(b)}
|
|
|
55502
55503
|
}
|
|
55503
55504
|
}
|
|
55504
55505
|
}, cancel(n) {
|
|
55505
|
-
|
|
55506
|
+
f("cancle stream:", n);
|
|
55506
55507
|
} });
|
|
55507
55508
|
}
|
|
55508
55509
|
convertOpenAIResponseToAnthropic(e) {
|
|
55509
|
-
|
|
55510
|
+
f("Original OpenAI response:", JSON.stringify(e, null, 2));
|
|
55510
55511
|
let t = e.choices[0];
|
|
55511
55512
|
if (!t) throw new Error("No choices found in OpenAI response");
|
|
55512
55513
|
let n = [];
|
|
55513
|
-
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,
|
|
55514
|
-
let
|
|
55514
|
+
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 u = {};
|
|
55515
55516
|
try {
|
|
55516
55517
|
let d = r.function.arguments || "{}";
|
|
55517
|
-
typeof d == "object" ?
|
|
55518
|
+
typeof d == "object" ? u = d : typeof d == "string" && (u = JSON.parse(d));
|
|
55518
55519
|
} catch {
|
|
55519
|
-
|
|
55520
|
+
u = { text: r.function.arguments || "" };
|
|
55520
55521
|
}
|
|
55521
|
-
n.push({ type: "tool_use", id: r.id, name: r.function.name, input:
|
|
55522
|
+
n.push({ type: "tool_use", id: r.id, name: r.function.name, input: u });
|
|
55522
55523
|
});
|
|
55523
55524
|
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 } };
|
|
55524
|
-
return
|
|
55525
|
+
return f("Conversion complete, final Anthropic response:", JSON.stringify(o, null, 2)), o;
|
|
55525
55526
|
}
|
|
55526
55527
|
};
|
|
55527
|
-
var
|
|
55528
|
+
var N = class {
|
|
55528
55529
|
name = "gemini";
|
|
55529
55530
|
endPoint = "/v1beta/models/:modelAndAction";
|
|
55530
55531
|
transformRequestIn(e, t) {
|
|
@@ -55532,20 +55533,20 @@ var M = class {
|
|
|
55532
55533
|
let o;
|
|
55533
55534
|
n.role === "assistant" ? o = "model" : (["user", "system", "tool"].includes(n.role), o = "user");
|
|
55534
55535
|
let r = [];
|
|
55535
|
-
return typeof n.content == "string" ? r.push({ text: n.content }) : Array.isArray(n.content) && r.push(...n.content.map((
|
|
55536
|
-
if (
|
|
55537
|
-
})), Array.isArray(n.tool_calls) && r.push(...n.tool_calls.map((
|
|
55536
|
+
return typeof n.content == "string" ? r.push({ text: n.content }) : Array.isArray(n.content) && r.push(...n.content.map((l) => {
|
|
55537
|
+
if (l.type === "text") return { text: l.text || "" };
|
|
55538
|
+
})), Array.isArray(n.tool_calls) && r.push(...n.tool_calls.map((l) => ({ functionCall: { id: l.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: l.function.name, args: JSON.parse(l.function.arguments || "{}") } }))), { role: o, parts: r };
|
|
55538
55539
|
}), tools: [{ functionDeclarations: e.tools?.map((n) => (delete n.function.parameters?.$schema, delete n.function.parameters?.additionalProperties, n.function.parameters?.properties && Object.keys(n.function.parameters.properties).forEach((o) => {
|
|
55539
55540
|
delete n.function.parameters.properties[o].$schema, delete n.function.parameters.properties[o].additionalProperties, n.function.parameters.properties[o].items && typeof n.function.parameters.properties[o].items == "object" && (delete n.function.parameters.properties[o].items.$schema, delete n.function.parameters.properties[o].items.additionalProperties), n.function.parameters.properties[o].type === "string" && (["enum", "date-time"].includes(n.function.parameters.properties[o].format) || delete n.function.parameters.properties[o].format);
|
|
55540
55541
|
}), { 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 } } };
|
|
55541
55542
|
}
|
|
55542
55543
|
transformRequestOut(e) {
|
|
55543
|
-
let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens,
|
|
55544
|
-
return Array.isArray(t) && t.forEach((
|
|
55545
|
-
typeof
|
|
55546
|
-
}), Array.isArray(n) && (a.tools = [], n.forEach((
|
|
55547
|
-
Array.isArray(
|
|
55548
|
-
a.tools.push({ type: "function", function: { name:
|
|
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, a = { messages: [], model: o, max_tokens: r, temperature: l, stream: u, tool_choice: d };
|
|
55545
|
+
return Array.isArray(t) && t.forEach((c) => {
|
|
55546
|
+
typeof c == "string" ? a.messages.push({ role: "user", content: c }) : typeof c.text == "string" ? a.messages.push({ role: "user", content: c.text || null }) : c.role === "user" ? a.messages.push({ role: "user", content: c?.parts?.map((y) => ({ type: "text", text: y.text || "" })) || [] }) : c.role === "model" && a.messages.push({ role: "assistant", content: c?.parts?.map((y) => ({ type: "text", text: y.text || "" })) || [] });
|
|
55547
|
+
}), Array.isArray(n) && (a.tools = [], n.forEach((c) => {
|
|
55548
|
+
Array.isArray(c.functionDeclarations) && c.functionDeclarations.forEach((y) => {
|
|
55549
|
+
a.tools.push({ type: "function", function: { name: y.name, description: y.description, parameters: y.parameters } });
|
|
55549
55550
|
});
|
|
55550
55551
|
})), a;
|
|
55551
55552
|
}
|
|
@@ -55557,23 +55558,23 @@ var M = class {
|
|
|
55557
55558
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55558
55559
|
if (!e.body) return e;
|
|
55559
55560
|
let t = new TextDecoder(), n = new TextEncoder(), o = new ReadableStream({ async start(r) {
|
|
55560
|
-
let
|
|
55561
|
+
let l = e.body.getReader();
|
|
55561
55562
|
try {
|
|
55562
55563
|
for (; ; ) {
|
|
55563
|
-
let { done:
|
|
55564
|
-
if (
|
|
55564
|
+
let { done: u, value: d } = await l.read();
|
|
55565
|
+
if (u) break;
|
|
55565
55566
|
let a = t.decode(d, { stream: true });
|
|
55566
55567
|
if (a.startsWith("data: ")) a = a.slice(6).trim();
|
|
55567
55568
|
else break;
|
|
55568
|
-
|
|
55569
|
-
let
|
|
55570
|
-
`), tool_calls:
|
|
55571
|
-
|
|
55569
|
+
f("gemini chunk:", a), a = JSON.parse(a);
|
|
55570
|
+
let c = a.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 || {}) } })), y = { choices: [{ delta: { role: "assistant", content: a.candidates[0].content.parts.filter((v) => v.text).map((v) => v.text).join(`
|
|
55571
|
+
`), tool_calls: c.length > 0 ? c : void 0 }, finish_reason: a.candidates[0].finishReason?.toLowerCase() || null, index: a.candidates[0].index || c.length > 0 ? 1 : 0, logprobs: null }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), id: a.responseId || "", model: a.modelVersion || "", object: "chat.completion.chunk", system_fingerprint: "fp_a49d71b8a1" };
|
|
55572
|
+
f("gemini response:", JSON.stringify(y, null, 2)), r.enqueue(n.encode(`data: ${JSON.stringify(y)}
|
|
55572
55573
|
|
|
55573
55574
|
`));
|
|
55574
55575
|
}
|
|
55575
|
-
} catch (
|
|
55576
|
-
r.error(
|
|
55576
|
+
} catch (u) {
|
|
55577
|
+
r.error(u);
|
|
55577
55578
|
} finally {
|
|
55578
55579
|
r.close();
|
|
55579
55580
|
}
|
|
@@ -55594,61 +55595,61 @@ var H = class {
|
|
|
55594
55595
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55595
55596
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55596
55597
|
if (!e.body) return e;
|
|
55597
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false,
|
|
55598
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false, l = new ReadableStream({ async start(u) {
|
|
55598
55599
|
let d = e.body.getReader();
|
|
55599
55600
|
try {
|
|
55600
55601
|
for (; ; ) {
|
|
55601
|
-
let { done: a, value:
|
|
55602
|
+
let { done: a, value: c } = await d.read();
|
|
55602
55603
|
if (a) break;
|
|
55603
|
-
let v = t.decode(
|
|
55604
|
+
let v = t.decode(c, { stream: true }).split(`
|
|
55604
55605
|
`);
|
|
55605
55606
|
for (let h of v) if (h.startsWith("data: ") && h.trim() !== "data: [DONE]") try {
|
|
55606
|
-
let
|
|
55607
|
-
if (
|
|
55608
|
-
o +=
|
|
55609
|
-
let s = { ...
|
|
55607
|
+
let p = JSON.parse(h.slice(6));
|
|
55608
|
+
if (p.choices?.[0]?.delta?.reasoning_content) {
|
|
55609
|
+
o += p.choices[0].delta.reasoning_content;
|
|
55610
|
+
let s = { ...p, choices: [{ ...p.choices[0], delta: { ...p.choices[0].delta, thinking: { content: p.choices[0].delta.reasoning_content } } }] };
|
|
55610
55611
|
delete s.choices[0].delta.reasoning_content;
|
|
55611
|
-
let
|
|
55612
|
+
let m = `data: ${JSON.stringify(s)}
|
|
55612
55613
|
|
|
55613
55614
|
`;
|
|
55614
|
-
|
|
55615
|
+
u.enqueue(n.encode(m));
|
|
55615
55616
|
continue;
|
|
55616
55617
|
}
|
|
55617
|
-
if (
|
|
55618
|
+
if (p.choices?.[0]?.delta?.content && o && !r) {
|
|
55618
55619
|
r = true;
|
|
55619
|
-
let s = Date.now().toString(),
|
|
55620
|
-
delete
|
|
55621
|
-
let
|
|
55620
|
+
let s = Date.now().toString(), m = { ...p, choices: [{ ...p.choices[0], delta: { ...p.choices[0].delta, content: null, thinking: { content: o, signature: s } } }] };
|
|
55621
|
+
delete m.choices[0].delta.reasoning_content;
|
|
55622
|
+
let g = `data: ${JSON.stringify(m)}
|
|
55622
55623
|
|
|
55623
55624
|
`;
|
|
55624
|
-
|
|
55625
|
+
u.enqueue(n.encode(g));
|
|
55625
55626
|
}
|
|
55626
|
-
if (
|
|
55627
|
-
r &&
|
|
55628
|
-
let s = `data: ${JSON.stringify(
|
|
55627
|
+
if (p.choices[0]?.delta?.reasoning_content && delete p.choices[0].delta.reasoning_content, p.choices?.[0]?.delta && Object.keys(p.choices[0].delta).length > 0) {
|
|
55628
|
+
r && p.choices[0].index++;
|
|
55629
|
+
let s = `data: ${JSON.stringify(p)}
|
|
55629
55630
|
|
|
55630
55631
|
`;
|
|
55631
|
-
|
|
55632
|
+
u.enqueue(n.encode(s));
|
|
55632
55633
|
}
|
|
55633
55634
|
} catch {
|
|
55634
|
-
|
|
55635
|
+
u.enqueue(n.encode(h + `
|
|
55635
55636
|
`));
|
|
55636
55637
|
}
|
|
55637
|
-
else
|
|
55638
|
+
else u.enqueue(n.encode(h + `
|
|
55638
55639
|
`));
|
|
55639
55640
|
}
|
|
55640
55641
|
} catch (a) {
|
|
55641
|
-
|
|
55642
|
+
u.error(a);
|
|
55642
55643
|
} finally {
|
|
55643
55644
|
try {
|
|
55644
55645
|
d.releaseLock();
|
|
55645
55646
|
} catch (a) {
|
|
55646
55647
|
console.error("Error releasing reader lock:", a);
|
|
55647
55648
|
}
|
|
55648
|
-
|
|
55649
|
+
u.close();
|
|
55649
55650
|
}
|
|
55650
55651
|
} });
|
|
55651
|
-
return new Response(
|
|
55652
|
+
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" } });
|
|
55652
55653
|
}
|
|
55653
55654
|
return e;
|
|
55654
55655
|
}
|
|
@@ -55672,95 +55673,102 @@ Examples:
|
|
|
55672
55673
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55673
55674
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55674
55675
|
if (!e.body) return e;
|
|
55675
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "",
|
|
55676
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "", l = new ReadableStream({ async start(u) {
|
|
55676
55677
|
let d = e.body.getReader();
|
|
55677
55678
|
try {
|
|
55678
55679
|
for (; ; ) {
|
|
55679
|
-
let { done: a, value:
|
|
55680
|
+
let { done: a, value: c } = await d.read();
|
|
55680
55681
|
if (a) break;
|
|
55681
|
-
let v = t.decode(
|
|
55682
|
+
let v = t.decode(c, { stream: true }).split(`
|
|
55682
55683
|
`);
|
|
55683
55684
|
for (let h of v) if (h.startsWith("data: ") && h.trim() !== "data: [DONE]") try {
|
|
55684
|
-
let
|
|
55685
|
-
if (
|
|
55686
|
-
let s =
|
|
55685
|
+
let p = JSON.parse(h.slice(6));
|
|
55686
|
+
if (p.choices[0]?.delta?.tool_calls?.length) {
|
|
55687
|
+
let s = p.choices[0].delta.tool_calls[0];
|
|
55687
55688
|
if (s.function?.name === "ExitTool") {
|
|
55688
55689
|
o = s.index;
|
|
55689
55690
|
continue;
|
|
55690
55691
|
} else if (o > -1 && s.index === o && s.function.arguments) {
|
|
55691
55692
|
r += s.function.arguments;
|
|
55692
55693
|
try {
|
|
55693
|
-
let
|
|
55694
|
-
|
|
55695
|
-
let
|
|
55694
|
+
let m = JSON.parse(r);
|
|
55695
|
+
p.choices = [{ delta: { role: "assistant", content: m.response || "" } }];
|
|
55696
|
+
let g = `data: ${JSON.stringify(p)}
|
|
55696
55697
|
|
|
55697
55698
|
`;
|
|
55698
|
-
|
|
55699
|
+
u.enqueue(n.encode(g));
|
|
55699
55700
|
} catch {
|
|
55700
55701
|
}
|
|
55701
55702
|
continue;
|
|
55702
55703
|
}
|
|
55703
55704
|
}
|
|
55704
|
-
if (
|
|
55705
|
-
let s = `data: ${JSON.stringify(
|
|
55705
|
+
if (p.choices?.[0]?.delta && Object.keys(p.choices[0].delta).length > 0) {
|
|
55706
|
+
let s = `data: ${JSON.stringify(p)}
|
|
55706
55707
|
|
|
55707
55708
|
`;
|
|
55708
|
-
|
|
55709
|
+
u.enqueue(n.encode(s));
|
|
55709
55710
|
}
|
|
55710
55711
|
} catch {
|
|
55711
|
-
|
|
55712
|
+
u.enqueue(n.encode(h + `
|
|
55712
55713
|
`));
|
|
55713
55714
|
}
|
|
55714
|
-
else
|
|
55715
|
+
else u.enqueue(n.encode(h + `
|
|
55715
55716
|
`));
|
|
55716
55717
|
}
|
|
55717
55718
|
} catch (a) {
|
|
55718
|
-
|
|
55719
|
+
u.error(a);
|
|
55719
55720
|
} finally {
|
|
55720
55721
|
try {
|
|
55721
55722
|
d.releaseLock();
|
|
55722
55723
|
} catch (a) {
|
|
55723
55724
|
console.error("Error releasing reader lock:", a);
|
|
55724
55725
|
}
|
|
55725
|
-
|
|
55726
|
+
u.close();
|
|
55726
55727
|
}
|
|
55727
55728
|
} });
|
|
55728
|
-
return new Response(
|
|
55729
|
+
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" } });
|
|
55729
55730
|
}
|
|
55730
55731
|
return e;
|
|
55731
55732
|
}
|
|
55732
55733
|
};
|
|
55733
55734
|
var F = class {
|
|
55734
55735
|
name = "openrouter";
|
|
55736
|
+
transformRequestIn(e) {
|
|
55737
|
+
return e.model.includes("claude") || e.messages.forEach((t) => {
|
|
55738
|
+
Array.isArray(t.content) ? t.content.forEach((n) => {
|
|
55739
|
+
n.cache_control && delete n.cache_control;
|
|
55740
|
+
}) : t.cache_control && delete t.cache_control;
|
|
55741
|
+
}), e;
|
|
55742
|
+
}
|
|
55735
55743
|
async transformResponseOut(e) {
|
|
55736
55744
|
if (e.headers.get("Content-Type")?.includes("application/json")) {
|
|
55737
55745
|
let t = await e.json();
|
|
55738
55746
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55739
55747
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55740
55748
|
if (!e.body) return e;
|
|
55741
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "",
|
|
55749
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", l = false, u = new ReadableStream({ async start(d) {
|
|
55742
55750
|
let a = e.body.getReader();
|
|
55743
55751
|
try {
|
|
55744
55752
|
for (; ; ) {
|
|
55745
|
-
let { done:
|
|
55746
|
-
if (
|
|
55747
|
-
let h = t.decode(
|
|
55753
|
+
let { done: c, value: y } = await a.read();
|
|
55754
|
+
if (c) break;
|
|
55755
|
+
let h = t.decode(y, { stream: true }).split(`
|
|
55748
55756
|
`);
|
|
55749
|
-
for (let
|
|
55750
|
-
let s = JSON.parse(
|
|
55757
|
+
for (let p of h) if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") try {
|
|
55758
|
+
let s = JSON.parse(p.slice(6));
|
|
55751
55759
|
if (s.choices[0]?.delta?.content && !o && (o = true), s.choices?.[0]?.delta?.reasoning) {
|
|
55752
55760
|
r += s.choices[0].delta.reasoning;
|
|
55753
|
-
let
|
|
55754
|
-
delete
|
|
55755
|
-
let k = `data: ${JSON.stringify(
|
|
55761
|
+
let g = { ...s, choices: [{ ...s.choices[0], delta: { ...s.choices[0].delta, thinking: { content: s.choices[0].delta.reasoning } } }] };
|
|
55762
|
+
delete g.choices[0].delta.reasoning;
|
|
55763
|
+
let k = `data: ${JSON.stringify(g)}
|
|
55756
55764
|
|
|
55757
55765
|
`;
|
|
55758
55766
|
d.enqueue(n.encode(k));
|
|
55759
55767
|
continue;
|
|
55760
55768
|
}
|
|
55761
|
-
if (s.choices?.[0]?.delta?.content && r && !
|
|
55762
|
-
|
|
55763
|
-
let
|
|
55769
|
+
if (s.choices?.[0]?.delta?.content && r && !l) {
|
|
55770
|
+
l = true;
|
|
55771
|
+
let g = Date.now().toString(), k = { ...s, choices: [{ ...s.choices[0], delta: { ...s.choices[0].delta, content: null, thinking: { content: r, signature: g } } }] };
|
|
55764
55772
|
delete k.choices[0].delta.reasoning;
|
|
55765
55773
|
let D = `data: ${JSON.stringify(k)}
|
|
55766
55774
|
|
|
@@ -55768,29 +55776,29 @@ var F = class {
|
|
|
55768
55776
|
d.enqueue(n.encode(D));
|
|
55769
55777
|
}
|
|
55770
55778
|
s.choices[0]?.delta?.reasoning && delete s.choices[0].delta.reasoning, s.choices[0]?.delta?.tool_calls?.length && o && (s.choices[0].index += 1);
|
|
55771
|
-
let
|
|
55779
|
+
let m = `data: ${JSON.stringify(s)}
|
|
55772
55780
|
|
|
55773
55781
|
`;
|
|
55774
|
-
d.enqueue(n.encode(
|
|
55782
|
+
d.enqueue(n.encode(m));
|
|
55775
55783
|
} catch {
|
|
55776
|
-
d.enqueue(n.encode(
|
|
55784
|
+
d.enqueue(n.encode(p + `
|
|
55777
55785
|
`));
|
|
55778
55786
|
}
|
|
55779
|
-
else d.enqueue(n.encode(
|
|
55787
|
+
else d.enqueue(n.encode(p + `
|
|
55780
55788
|
`));
|
|
55781
55789
|
}
|
|
55782
|
-
} catch (
|
|
55783
|
-
d.error(
|
|
55790
|
+
} catch (c) {
|
|
55791
|
+
d.error(c);
|
|
55784
55792
|
} finally {
|
|
55785
55793
|
try {
|
|
55786
55794
|
a.releaseLock();
|
|
55787
|
-
} catch (
|
|
55788
|
-
console.error("Error releasing reader lock:",
|
|
55795
|
+
} catch (c) {
|
|
55796
|
+
console.error("Error releasing reader lock:", c);
|
|
55789
55797
|
}
|
|
55790
55798
|
d.close();
|
|
55791
55799
|
}
|
|
55792
55800
|
} });
|
|
55793
|
-
return new Response(
|
|
55801
|
+
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" } });
|
|
55794
55802
|
}
|
|
55795
55803
|
return e;
|
|
55796
55804
|
}
|
|
@@ -55802,7 +55810,7 @@ var U = class {
|
|
|
55802
55810
|
}
|
|
55803
55811
|
transformers = /* @__PURE__ */ new Map();
|
|
55804
55812
|
registerTransformer(e, t) {
|
|
55805
|
-
this.transformers.set(e, t),
|
|
55813
|
+
this.transformers.set(e, t), f(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
|
|
55806
55814
|
}
|
|
55807
55815
|
getTransformer(e) {
|
|
55808
55816
|
return this.transformers.get(e);
|
|
@@ -55840,22 +55848,22 @@ var U = class {
|
|
|
55840
55848
|
}
|
|
55841
55849
|
return false;
|
|
55842
55850
|
} catch (t) {
|
|
55843
|
-
return
|
|
55851
|
+
return f(`load transformer (${e.path}):`, t), false;
|
|
55844
55852
|
}
|
|
55845
55853
|
}
|
|
55846
55854
|
async initialize() {
|
|
55847
55855
|
try {
|
|
55848
55856
|
await this.registerDefaultTransformersInternal(), await this.loadFromConfig();
|
|
55849
55857
|
} catch (e) {
|
|
55850
|
-
|
|
55858
|
+
f("TransformerService init error:", e);
|
|
55851
55859
|
}
|
|
55852
55860
|
}
|
|
55853
55861
|
async registerDefaultTransformersInternal() {
|
|
55854
55862
|
try {
|
|
55855
|
-
let e = new
|
|
55863
|
+
let e = new M(), t = new N(), n = new H(), o = new $(), r = new F();
|
|
55856
55864
|
this.registerTransformer(e.name, e), this.registerTransformer(t.name, t), this.registerTransformer(n.name, n), this.registerTransformer(o.name, o), this.registerTransformer(r.name, r);
|
|
55857
55865
|
} catch (e) {
|
|
55858
|
-
|
|
55866
|
+
f("transformer regist error:", e);
|
|
55859
55867
|
}
|
|
55860
55868
|
}
|
|
55861
55869
|
async loadFromConfig() {
|
|
@@ -55888,29 +55896,29 @@ var B = class {
|
|
|
55888
55896
|
try {
|
|
55889
55897
|
let r = n.body;
|
|
55890
55898
|
if (!r || !r.model) return o.code(400).send({ error: "Missing model in request body" });
|
|
55891
|
-
let [
|
|
55892
|
-
r.model =
|
|
55899
|
+
let [l, u] = r.model.split(",");
|
|
55900
|
+
r.model = u, n.provider = l;
|
|
55893
55901
|
return;
|
|
55894
55902
|
} catch (r) {
|
|
55895
55903
|
return n.log.error("Error in modelProviderMiddleware:", r), o.code(500).send({ error: "Internal server error" });
|
|
55896
55904
|
}
|
|
55897
55905
|
}), this.app.register(Z);
|
|
55898
55906
|
let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
|
|
55899
|
-
|
|
55907
|
+
f(`\u{1F680} LLMs API server listening on ${e}`);
|
|
55900
55908
|
let t = async (n) => {
|
|
55901
|
-
|
|
55909
|
+
f(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
|
|
55902
55910
|
};
|
|
55903
55911
|
process.on("SIGINT", () => t("SIGINT")), process.on("SIGTERM", () => t("SIGTERM"));
|
|
55904
55912
|
} catch (e) {
|
|
55905
|
-
|
|
55913
|
+
f(`Error starting server: ${e}`), process.exit(1);
|
|
55906
55914
|
}
|
|
55907
55915
|
}
|
|
55908
55916
|
};
|
|
55909
|
-
var
|
|
55917
|
+
var xt = B;
|
|
55910
55918
|
|
|
55911
55919
|
// src/server.ts
|
|
55912
55920
|
var createServer = (config) => {
|
|
55913
|
-
const server = new
|
|
55921
|
+
const server = new xt(config);
|
|
55914
55922
|
return server;
|
|
55915
55923
|
};
|
|
55916
55924
|
|
|
@@ -56229,7 +56237,7 @@ async function executeCodeCommand(args = []) {
|
|
|
56229
56237
|
}
|
|
56230
56238
|
|
|
56231
56239
|
// package.json
|
|
56232
|
-
var version = "1.0.
|
|
56240
|
+
var version = "1.0.15";
|
|
56233
56241
|
|
|
56234
56242
|
// src/cli.ts
|
|
56235
56243
|
var import_child_process2 = require("child_process");
|