@musistudio/claude-code-router 1.0.22 → 1.0.24
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 +35 -11
- package/README_zh.md +34 -11
- package/custom-router.example.js +3 -0
- package/dist/cli.js +616 -552
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -1517,19 +1517,19 @@ var require_process_warning = __commonJS({
|
|
|
1517
1517
|
if (typeof unlimited !== "boolean") throw new Error("Warning opts.unlimited must be a boolean");
|
|
1518
1518
|
code = code.toUpperCase();
|
|
1519
1519
|
let warningContainer = {
|
|
1520
|
-
[name]: function(a,
|
|
1520
|
+
[name]: function(a, b, c) {
|
|
1521
1521
|
if (warning.emitted === true && warning.unlimited !== true) {
|
|
1522
1522
|
return;
|
|
1523
1523
|
}
|
|
1524
1524
|
warning.emitted = true;
|
|
1525
|
-
process.emitWarning(warning.format(a,
|
|
1525
|
+
process.emitWarning(warning.format(a, b, c), warning.name, warning.code);
|
|
1526
1526
|
}
|
|
1527
1527
|
};
|
|
1528
1528
|
if (unlimited) {
|
|
1529
1529
|
warningContainer = {
|
|
1530
|
-
[name]: function(a,
|
|
1530
|
+
[name]: function(a, b, c) {
|
|
1531
1531
|
warning.emitted = true;
|
|
1532
|
-
process.emitWarning(warning.format(a,
|
|
1532
|
+
process.emitWarning(warning.format(a, b, c), warning.name, warning.code);
|
|
1533
1533
|
}
|
|
1534
1534
|
};
|
|
1535
1535
|
}
|
|
@@ -1538,12 +1538,12 @@ var require_process_warning = __commonJS({
|
|
|
1538
1538
|
warning.message = message;
|
|
1539
1539
|
warning.unlimited = unlimited;
|
|
1540
1540
|
warning.code = code;
|
|
1541
|
-
warning.format = function(a,
|
|
1541
|
+
warning.format = function(a, b, c) {
|
|
1542
1542
|
let formatted;
|
|
1543
|
-
if (a &&
|
|
1544
|
-
formatted = format(message, a,
|
|
1545
|
-
} else if (a &&
|
|
1546
|
-
formatted = format(message, a,
|
|
1543
|
+
if (a && b && c) {
|
|
1544
|
+
formatted = format(message, a, b, c);
|
|
1545
|
+
} else if (a && b) {
|
|
1546
|
+
formatted = format(message, a, b);
|
|
1547
1547
|
} else if (a) {
|
|
1548
1548
|
formatted = format(message, a);
|
|
1549
1549
|
} else {
|
|
@@ -7299,8 +7299,8 @@ var require_multistream = __commonJS({
|
|
|
7299
7299
|
};
|
|
7300
7300
|
}
|
|
7301
7301
|
}
|
|
7302
|
-
function compareByLevel(a,
|
|
7303
|
-
return a.level -
|
|
7302
|
+
function compareByLevel(a, b) {
|
|
7303
|
+
return a.level - b.level;
|
|
7304
7304
|
}
|
|
7305
7305
|
function initLoopVar(length, dedupe) {
|
|
7306
7306
|
return dedupe ? length - 1 : 0;
|
|
@@ -12189,22 +12189,22 @@ var require_code = __commonJS({
|
|
|
12189
12189
|
i++;
|
|
12190
12190
|
}
|
|
12191
12191
|
}
|
|
12192
|
-
function mergeExprItems(a,
|
|
12193
|
-
if (
|
|
12192
|
+
function mergeExprItems(a, b) {
|
|
12193
|
+
if (b === '""')
|
|
12194
12194
|
return a;
|
|
12195
12195
|
if (a === '""')
|
|
12196
|
-
return
|
|
12196
|
+
return b;
|
|
12197
12197
|
if (typeof a == "string") {
|
|
12198
|
-
if (
|
|
12198
|
+
if (b instanceof Name || a[a.length - 1] !== '"')
|
|
12199
12199
|
return;
|
|
12200
|
-
if (typeof
|
|
12201
|
-
return `${a.slice(0, -1)}${
|
|
12202
|
-
if (
|
|
12203
|
-
return a.slice(0, -1) +
|
|
12200
|
+
if (typeof b != "string")
|
|
12201
|
+
return `${a.slice(0, -1)}${b}"`;
|
|
12202
|
+
if (b[0] === '"')
|
|
12203
|
+
return a.slice(0, -1) + b.slice(1);
|
|
12204
12204
|
return;
|
|
12205
12205
|
}
|
|
12206
|
-
if (typeof
|
|
12207
|
-
return `"${a}${
|
|
12206
|
+
if (typeof b == "string" && b[0] === '"' && !(a instanceof Name))
|
|
12207
|
+
return `"${a}${b.slice(1)}`;
|
|
12208
12208
|
return;
|
|
12209
12209
|
}
|
|
12210
12210
|
function strConcat(c1, c2) {
|
|
@@ -14097,33 +14097,33 @@ var require_subschema = __commonJS({
|
|
|
14097
14097
|
var require_fast_deep_equal = __commonJS({
|
|
14098
14098
|
"node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js"(exports2, module2) {
|
|
14099
14099
|
"use strict";
|
|
14100
|
-
module2.exports = function equal(a,
|
|
14101
|
-
if (a ===
|
|
14102
|
-
if (a &&
|
|
14103
|
-
if (a.constructor !==
|
|
14100
|
+
module2.exports = function equal(a, b) {
|
|
14101
|
+
if (a === b) return true;
|
|
14102
|
+
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
14103
|
+
if (a.constructor !== b.constructor) return false;
|
|
14104
14104
|
var length, i, keys;
|
|
14105
14105
|
if (Array.isArray(a)) {
|
|
14106
14106
|
length = a.length;
|
|
14107
|
-
if (length !=
|
|
14107
|
+
if (length != b.length) return false;
|
|
14108
14108
|
for (i = length; i-- !== 0; )
|
|
14109
|
-
if (!equal(a[i],
|
|
14109
|
+
if (!equal(a[i], b[i])) return false;
|
|
14110
14110
|
return true;
|
|
14111
14111
|
}
|
|
14112
|
-
if (a.constructor === RegExp) return a.source ===
|
|
14113
|
-
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() ===
|
|
14114
|
-
if (a.toString !== Object.prototype.toString) return a.toString() ===
|
|
14112
|
+
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
14113
|
+
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
14114
|
+
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
14115
14115
|
keys = Object.keys(a);
|
|
14116
14116
|
length = keys.length;
|
|
14117
|
-
if (length !== Object.keys(
|
|
14117
|
+
if (length !== Object.keys(b).length) return false;
|
|
14118
14118
|
for (i = length; i-- !== 0; )
|
|
14119
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
14119
|
+
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
14120
14120
|
for (i = length; i-- !== 0; ) {
|
|
14121
14121
|
var key = keys[i];
|
|
14122
|
-
if (!equal(a[key],
|
|
14122
|
+
if (!equal(a[key], b[key])) return false;
|
|
14123
14123
|
}
|
|
14124
14124
|
return true;
|
|
14125
14125
|
}
|
|
14126
|
-
return a !== a &&
|
|
14126
|
+
return a !== a && b !== b;
|
|
14127
14127
|
};
|
|
14128
14128
|
}
|
|
14129
14129
|
});
|
|
@@ -20043,8 +20043,8 @@ var require_resolvers = __commonJS({
|
|
|
20043
20043
|
mergedSchema[keyword] = Math.max(...values);
|
|
20044
20044
|
}
|
|
20045
20045
|
function commonMultiple(keyword, values, mergedSchema) {
|
|
20046
|
-
const gcd = (a,
|
|
20047
|
-
const lcm = (a,
|
|
20046
|
+
const gcd = (a, b) => !b ? a : gcd(b, a % b);
|
|
20047
|
+
const lcm = (a, b) => a * b / gcd(a, b);
|
|
20048
20048
|
let scale = 1;
|
|
20049
20049
|
for (const value of values) {
|
|
20050
20050
|
while (value * scale % 1 !== 0) {
|
|
@@ -23605,16 +23605,16 @@ var require_identifiers = __commonJS({
|
|
|
23605
23605
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/identifiers.js"(exports2, module2) {
|
|
23606
23606
|
"use strict";
|
|
23607
23607
|
var numeric = /^[0-9]+$/;
|
|
23608
|
-
var compareIdentifiers = (a,
|
|
23608
|
+
var compareIdentifiers = (a, b) => {
|
|
23609
23609
|
const anum = numeric.test(a);
|
|
23610
|
-
const bnum = numeric.test(
|
|
23610
|
+
const bnum = numeric.test(b);
|
|
23611
23611
|
if (anum && bnum) {
|
|
23612
23612
|
a = +a;
|
|
23613
|
-
|
|
23613
|
+
b = +b;
|
|
23614
23614
|
}
|
|
23615
|
-
return a ===
|
|
23615
|
+
return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
|
|
23616
23616
|
};
|
|
23617
|
-
var rcompareIdentifiers = (a,
|
|
23617
|
+
var rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
|
|
23618
23618
|
module2.exports = {
|
|
23619
23619
|
compareIdentifiers,
|
|
23620
23620
|
rcompareIdentifiers
|
|
@@ -23728,18 +23728,18 @@ var require_semver = __commonJS({
|
|
|
23728
23728
|
let i = 0;
|
|
23729
23729
|
do {
|
|
23730
23730
|
const a = this.prerelease[i];
|
|
23731
|
-
const
|
|
23732
|
-
debug("prerelease compare", i, a,
|
|
23733
|
-
if (a === void 0 &&
|
|
23731
|
+
const b = other.prerelease[i];
|
|
23732
|
+
debug("prerelease compare", i, a, b);
|
|
23733
|
+
if (a === void 0 && b === void 0) {
|
|
23734
23734
|
return 0;
|
|
23735
|
-
} else if (
|
|
23735
|
+
} else if (b === void 0) {
|
|
23736
23736
|
return 1;
|
|
23737
23737
|
} else if (a === void 0) {
|
|
23738
23738
|
return -1;
|
|
23739
|
-
} else if (a ===
|
|
23739
|
+
} else if (a === b) {
|
|
23740
23740
|
continue;
|
|
23741
23741
|
} else {
|
|
23742
|
-
return compareIdentifiers(a,
|
|
23742
|
+
return compareIdentifiers(a, b);
|
|
23743
23743
|
}
|
|
23744
23744
|
} while (++i);
|
|
23745
23745
|
}
|
|
@@ -23750,18 +23750,18 @@ var require_semver = __commonJS({
|
|
|
23750
23750
|
let i = 0;
|
|
23751
23751
|
do {
|
|
23752
23752
|
const a = this.build[i];
|
|
23753
|
-
const
|
|
23754
|
-
debug("build compare", i, a,
|
|
23755
|
-
if (a === void 0 &&
|
|
23753
|
+
const b = other.build[i];
|
|
23754
|
+
debug("build compare", i, a, b);
|
|
23755
|
+
if (a === void 0 && b === void 0) {
|
|
23756
23756
|
return 0;
|
|
23757
|
-
} else if (
|
|
23757
|
+
} else if (b === void 0) {
|
|
23758
23758
|
return 1;
|
|
23759
23759
|
} else if (a === void 0) {
|
|
23760
23760
|
return -1;
|
|
23761
|
-
} else if (a ===
|
|
23761
|
+
} else if (a === b) {
|
|
23762
23762
|
continue;
|
|
23763
23763
|
} else {
|
|
23764
|
-
return compareIdentifiers(a,
|
|
23764
|
+
return compareIdentifiers(a, b);
|
|
23765
23765
|
}
|
|
23766
23766
|
} while (++i);
|
|
23767
23767
|
}
|
|
@@ -24047,7 +24047,7 @@ var require_compare = __commonJS({
|
|
|
24047
24047
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare.js"(exports2, module2) {
|
|
24048
24048
|
"use strict";
|
|
24049
24049
|
var SemVer = require_semver();
|
|
24050
|
-
var compare = (a,
|
|
24050
|
+
var compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
|
|
24051
24051
|
module2.exports = compare;
|
|
24052
24052
|
}
|
|
24053
24053
|
});
|
|
@@ -24057,7 +24057,7 @@ var require_rcompare = __commonJS({
|
|
|
24057
24057
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rcompare.js"(exports2, module2) {
|
|
24058
24058
|
"use strict";
|
|
24059
24059
|
var compare = require_compare();
|
|
24060
|
-
var rcompare = (a,
|
|
24060
|
+
var rcompare = (a, b, loose) => compare(b, a, loose);
|
|
24061
24061
|
module2.exports = rcompare;
|
|
24062
24062
|
}
|
|
24063
24063
|
});
|
|
@@ -24067,7 +24067,7 @@ var require_compare_loose = __commonJS({
|
|
|
24067
24067
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-loose.js"(exports2, module2) {
|
|
24068
24068
|
"use strict";
|
|
24069
24069
|
var compare = require_compare();
|
|
24070
|
-
var compareLoose = (a,
|
|
24070
|
+
var compareLoose = (a, b) => compare(a, b, true);
|
|
24071
24071
|
module2.exports = compareLoose;
|
|
24072
24072
|
}
|
|
24073
24073
|
});
|
|
@@ -24077,9 +24077,9 @@ var require_compare_build = __commonJS({
|
|
|
24077
24077
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-build.js"(exports2, module2) {
|
|
24078
24078
|
"use strict";
|
|
24079
24079
|
var SemVer = require_semver();
|
|
24080
|
-
var compareBuild = (a,
|
|
24080
|
+
var compareBuild = (a, b, loose) => {
|
|
24081
24081
|
const versionA = new SemVer(a, loose);
|
|
24082
|
-
const versionB = new SemVer(
|
|
24082
|
+
const versionB = new SemVer(b, loose);
|
|
24083
24083
|
return versionA.compare(versionB) || versionA.compareBuild(versionB);
|
|
24084
24084
|
};
|
|
24085
24085
|
module2.exports = compareBuild;
|
|
@@ -24091,7 +24091,7 @@ var require_sort = __commonJS({
|
|
|
24091
24091
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/sort.js"(exports2, module2) {
|
|
24092
24092
|
"use strict";
|
|
24093
24093
|
var compareBuild = require_compare_build();
|
|
24094
|
-
var sort = (list, loose) => list.sort((a,
|
|
24094
|
+
var sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
|
|
24095
24095
|
module2.exports = sort;
|
|
24096
24096
|
}
|
|
24097
24097
|
});
|
|
@@ -24101,7 +24101,7 @@ var require_rsort = __commonJS({
|
|
|
24101
24101
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rsort.js"(exports2, module2) {
|
|
24102
24102
|
"use strict";
|
|
24103
24103
|
var compareBuild = require_compare_build();
|
|
24104
|
-
var rsort = (list, loose) => list.sort((a,
|
|
24104
|
+
var rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
|
|
24105
24105
|
module2.exports = rsort;
|
|
24106
24106
|
}
|
|
24107
24107
|
});
|
|
@@ -24111,7 +24111,7 @@ var require_gt = __commonJS({
|
|
|
24111
24111
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gt.js"(exports2, module2) {
|
|
24112
24112
|
"use strict";
|
|
24113
24113
|
var compare = require_compare();
|
|
24114
|
-
var gt = (a,
|
|
24114
|
+
var gt = (a, b, loose) => compare(a, b, loose) > 0;
|
|
24115
24115
|
module2.exports = gt;
|
|
24116
24116
|
}
|
|
24117
24117
|
});
|
|
@@ -24121,7 +24121,7 @@ var require_lt = __commonJS({
|
|
|
24121
24121
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lt.js"(exports2, module2) {
|
|
24122
24122
|
"use strict";
|
|
24123
24123
|
var compare = require_compare();
|
|
24124
|
-
var lt = (a,
|
|
24124
|
+
var lt = (a, b, loose) => compare(a, b, loose) < 0;
|
|
24125
24125
|
module2.exports = lt;
|
|
24126
24126
|
}
|
|
24127
24127
|
});
|
|
@@ -24131,7 +24131,7 @@ var require_eq = __commonJS({
|
|
|
24131
24131
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/eq.js"(exports2, module2) {
|
|
24132
24132
|
"use strict";
|
|
24133
24133
|
var compare = require_compare();
|
|
24134
|
-
var eq = (a,
|
|
24134
|
+
var eq = (a, b, loose) => compare(a, b, loose) === 0;
|
|
24135
24135
|
module2.exports = eq;
|
|
24136
24136
|
}
|
|
24137
24137
|
});
|
|
@@ -24141,7 +24141,7 @@ var require_neq = __commonJS({
|
|
|
24141
24141
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/neq.js"(exports2, module2) {
|
|
24142
24142
|
"use strict";
|
|
24143
24143
|
var compare = require_compare();
|
|
24144
|
-
var neq = (a,
|
|
24144
|
+
var neq = (a, b, loose) => compare(a, b, loose) !== 0;
|
|
24145
24145
|
module2.exports = neq;
|
|
24146
24146
|
}
|
|
24147
24147
|
});
|
|
@@ -24151,7 +24151,7 @@ var require_gte = __commonJS({
|
|
|
24151
24151
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gte.js"(exports2, module2) {
|
|
24152
24152
|
"use strict";
|
|
24153
24153
|
var compare = require_compare();
|
|
24154
|
-
var gte = (a,
|
|
24154
|
+
var gte = (a, b, loose) => compare(a, b, loose) >= 0;
|
|
24155
24155
|
module2.exports = gte;
|
|
24156
24156
|
}
|
|
24157
24157
|
});
|
|
@@ -24161,7 +24161,7 @@ var require_lte = __commonJS({
|
|
|
24161
24161
|
"node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lte.js"(exports2, module2) {
|
|
24162
24162
|
"use strict";
|
|
24163
24163
|
var compare = require_compare();
|
|
24164
|
-
var lte = (a,
|
|
24164
|
+
var lte = (a, b, loose) => compare(a, b, loose) <= 0;
|
|
24165
24165
|
module2.exports = lte;
|
|
24166
24166
|
}
|
|
24167
24167
|
});
|
|
@@ -24176,38 +24176,38 @@ var require_cmp = __commonJS({
|
|
|
24176
24176
|
var gte = require_gte();
|
|
24177
24177
|
var lt = require_lt();
|
|
24178
24178
|
var lte = require_lte();
|
|
24179
|
-
var cmp = (a, op,
|
|
24179
|
+
var cmp = (a, op, b, loose) => {
|
|
24180
24180
|
switch (op) {
|
|
24181
24181
|
case "===":
|
|
24182
24182
|
if (typeof a === "object") {
|
|
24183
24183
|
a = a.version;
|
|
24184
24184
|
}
|
|
24185
|
-
if (typeof
|
|
24186
|
-
|
|
24185
|
+
if (typeof b === "object") {
|
|
24186
|
+
b = b.version;
|
|
24187
24187
|
}
|
|
24188
|
-
return a ===
|
|
24188
|
+
return a === b;
|
|
24189
24189
|
case "!==":
|
|
24190
24190
|
if (typeof a === "object") {
|
|
24191
24191
|
a = a.version;
|
|
24192
24192
|
}
|
|
24193
|
-
if (typeof
|
|
24194
|
-
|
|
24193
|
+
if (typeof b === "object") {
|
|
24194
|
+
b = b.version;
|
|
24195
24195
|
}
|
|
24196
|
-
return a !==
|
|
24196
|
+
return a !== b;
|
|
24197
24197
|
case "":
|
|
24198
24198
|
case "=":
|
|
24199
24199
|
case "==":
|
|
24200
|
-
return eq(a,
|
|
24200
|
+
return eq(a, b, loose);
|
|
24201
24201
|
case "!=":
|
|
24202
|
-
return neq(a,
|
|
24202
|
+
return neq(a, b, loose);
|
|
24203
24203
|
case ">":
|
|
24204
|
-
return gt(a,
|
|
24204
|
+
return gt(a, b, loose);
|
|
24205
24205
|
case ">=":
|
|
24206
|
-
return gte(a,
|
|
24206
|
+
return gte(a, b, loose);
|
|
24207
24207
|
case "<":
|
|
24208
|
-
return lt(a,
|
|
24208
|
+
return lt(a, b, loose);
|
|
24209
24209
|
case "<=":
|
|
24210
|
-
return lte(a,
|
|
24210
|
+
return lte(a, b, loose);
|
|
24211
24211
|
default:
|
|
24212
24212
|
throw new TypeError(`Invalid operator: ${op}`);
|
|
24213
24213
|
}
|
|
@@ -25062,7 +25062,7 @@ var require_simplify = __commonJS({
|
|
|
25062
25062
|
const set = [];
|
|
25063
25063
|
let first = null;
|
|
25064
25064
|
let prev = null;
|
|
25065
|
-
const v2 = versions.sort((a,
|
|
25065
|
+
const v2 = versions.sort((a, b) => compare(a, b, options));
|
|
25066
25066
|
for (const version2 of v2) {
|
|
25067
25067
|
const included = satisfies(version2, range, options);
|
|
25068
25068
|
if (included) {
|
|
@@ -25246,19 +25246,19 @@ var require_subset = __commonJS({
|
|
|
25246
25246
|
}
|
|
25247
25247
|
return true;
|
|
25248
25248
|
};
|
|
25249
|
-
var higherGT = (a,
|
|
25249
|
+
var higherGT = (a, b, options) => {
|
|
25250
25250
|
if (!a) {
|
|
25251
|
-
return
|
|
25251
|
+
return b;
|
|
25252
25252
|
}
|
|
25253
|
-
const comp = compare(a.semver,
|
|
25254
|
-
return comp > 0 ? a : comp < 0 ?
|
|
25253
|
+
const comp = compare(a.semver, b.semver, options);
|
|
25254
|
+
return comp > 0 ? a : comp < 0 ? b : b.operator === ">" && a.operator === ">=" ? b : a;
|
|
25255
25255
|
};
|
|
25256
|
-
var lowerLT = (a,
|
|
25256
|
+
var lowerLT = (a, b, options) => {
|
|
25257
25257
|
if (!a) {
|
|
25258
|
-
return
|
|
25258
|
+
return b;
|
|
25259
25259
|
}
|
|
25260
|
-
const comp = compare(a.semver,
|
|
25261
|
-
return comp < 0 ? a : comp > 0 ?
|
|
25260
|
+
const comp = compare(a.semver, b.semver, options);
|
|
25261
|
+
return comp < 0 ? a : comp > 0 ? b : b.operator === "<" && a.operator === "<=" ? b : a;
|
|
25262
25262
|
};
|
|
25263
25263
|
module2.exports = subset;
|
|
25264
25264
|
}
|
|
@@ -26477,11 +26477,11 @@ var require_util2 = __commonJS({
|
|
|
26477
26477
|
var CTRL = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?";
|
|
26478
26478
|
exports2.strToChars = (str) => {
|
|
26479
26479
|
const charsRegex = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;
|
|
26480
|
-
return str.replace(charsRegex, (s,
|
|
26480
|
+
return str.replace(charsRegex, (s, b, lbs, a16, b16, dctrl, eslsh) => {
|
|
26481
26481
|
if (lbs) {
|
|
26482
26482
|
return s;
|
|
26483
26483
|
}
|
|
26484
|
-
let code =
|
|
26484
|
+
let code = b ? 8 : a16 ? parseInt(a16, 16) : b16 ? parseInt(b16, 16) : dctrl ? CTRL.indexOf(dctrl) : {
|
|
26485
26485
|
0: 0,
|
|
26486
26486
|
t: 9,
|
|
26487
26487
|
n: 10,
|
|
@@ -27330,7 +27330,7 @@ var require_handler_storage = __commonJS({
|
|
|
27330
27330
|
throw new Error("find-my-way supports a maximum of 31 route handlers per node when there are constraints, limit reached");
|
|
27331
27331
|
}
|
|
27332
27332
|
this.handlers.push(handlerObject);
|
|
27333
|
-
this.handlers.sort((a,
|
|
27333
|
+
this.handlers.sort((a, b) => Object.keys(a.constraints).length - Object.keys(b.constraints).length);
|
|
27334
27334
|
if (!isMergedTree) {
|
|
27335
27335
|
this._compileGetHandlerMatchingConstraints(constrainer, constraints);
|
|
27336
27336
|
}
|
|
@@ -30571,19 +30571,19 @@ var require_process_warning2 = __commonJS({
|
|
|
30571
30571
|
if (typeof unlimited !== "boolean") throw new Error("Warning opts.unlimited must be a boolean");
|
|
30572
30572
|
code = code.toUpperCase();
|
|
30573
30573
|
let warningContainer = {
|
|
30574
|
-
[name]: function(a,
|
|
30574
|
+
[name]: function(a, b, c) {
|
|
30575
30575
|
if (warning.emitted === true && warning.unlimited !== true) {
|
|
30576
30576
|
return;
|
|
30577
30577
|
}
|
|
30578
30578
|
warning.emitted = true;
|
|
30579
|
-
process.emitWarning(warning.format(a,
|
|
30579
|
+
process.emitWarning(warning.format(a, b, c), warning.name, warning.code);
|
|
30580
30580
|
}
|
|
30581
30581
|
};
|
|
30582
30582
|
if (unlimited) {
|
|
30583
30583
|
warningContainer = {
|
|
30584
|
-
[name]: function(a,
|
|
30584
|
+
[name]: function(a, b, c) {
|
|
30585
30585
|
warning.emitted = true;
|
|
30586
|
-
process.emitWarning(warning.format(a,
|
|
30586
|
+
process.emitWarning(warning.format(a, b, c), warning.name, warning.code);
|
|
30587
30587
|
}
|
|
30588
30588
|
};
|
|
30589
30589
|
}
|
|
@@ -30592,12 +30592,12 @@ var require_process_warning2 = __commonJS({
|
|
|
30592
30592
|
warning.message = message;
|
|
30593
30593
|
warning.unlimited = unlimited;
|
|
30594
30594
|
warning.code = code;
|
|
30595
|
-
warning.format = function(a,
|
|
30595
|
+
warning.format = function(a, b, c) {
|
|
30596
30596
|
let formatted;
|
|
30597
|
-
if (a &&
|
|
30598
|
-
formatted = format(message, a,
|
|
30599
|
-
} else if (a &&
|
|
30600
|
-
formatted = format(message, a,
|
|
30597
|
+
if (a && b && c) {
|
|
30598
|
+
formatted = format(message, a, b, c);
|
|
30599
|
+
} else if (a && b) {
|
|
30600
|
+
formatted = format(message, a, b);
|
|
30601
30601
|
} else if (a) {
|
|
30602
30602
|
formatted = format(message, a);
|
|
30603
30603
|
} else {
|
|
@@ -32538,7 +32538,7 @@ var require_fastify = __commonJS({
|
|
|
32538
32538
|
listen,
|
|
32539
32539
|
server,
|
|
32540
32540
|
addresses: function() {
|
|
32541
|
-
const binded = this[kServerBindings].map((
|
|
32541
|
+
const binded = this[kServerBindings].map((b) => b.address());
|
|
32542
32542
|
binded.push(this.server.address());
|
|
32543
32543
|
return binded.filter((adr) => adr);
|
|
32544
32544
|
},
|
|
@@ -37824,12 +37824,12 @@ var require_webidl = __commonJS({
|
|
|
37824
37824
|
}
|
|
37825
37825
|
return V2;
|
|
37826
37826
|
};
|
|
37827
|
-
webidl.converters.TypedArray = function(V2,
|
|
37828
|
-
if (webidl.util.Type(V2) !== OBJECT || !types.isTypedArray(V2) || V2.constructor.name !==
|
|
37827
|
+
webidl.converters.TypedArray = function(V2, T2, prefix, name, opts) {
|
|
37828
|
+
if (webidl.util.Type(V2) !== OBJECT || !types.isTypedArray(V2) || V2.constructor.name !== T2.name) {
|
|
37829
37829
|
throw webidl.errors.conversionFailed({
|
|
37830
37830
|
prefix,
|
|
37831
37831
|
argument: `${name} ("${webidl.util.Stringify(V2)}")`,
|
|
37832
|
-
types: [
|
|
37832
|
+
types: [T2.name]
|
|
37833
37833
|
});
|
|
37834
37834
|
}
|
|
37835
37835
|
if (opts?.allowShared === false && types.isSharedArrayBuffer(V2.buffer)) {
|
|
@@ -38882,15 +38882,15 @@ var require_formdata = __commonJS({
|
|
|
38882
38882
|
}
|
|
38883
38883
|
}
|
|
38884
38884
|
[nodeUtil.inspect.custom](depth, options) {
|
|
38885
|
-
const state = this.#state.reduce((a,
|
|
38886
|
-
if (a[
|
|
38887
|
-
if (Array.isArray(a[
|
|
38888
|
-
a[
|
|
38885
|
+
const state = this.#state.reduce((a, b) => {
|
|
38886
|
+
if (a[b.name]) {
|
|
38887
|
+
if (Array.isArray(a[b.name])) {
|
|
38888
|
+
a[b.name].push(b.value);
|
|
38889
38889
|
} else {
|
|
38890
|
-
a[
|
|
38890
|
+
a[b.name] = [a[b.name], b.value];
|
|
38891
38891
|
}
|
|
38892
38892
|
} else {
|
|
38893
|
-
a[
|
|
38893
|
+
a[b.name] = b.value;
|
|
38894
38894
|
}
|
|
38895
38895
|
return a;
|
|
38896
38896
|
}, { __proto__: null });
|
|
@@ -42132,11 +42132,11 @@ var require_balanced_pool = __commonJS({
|
|
|
42132
42132
|
var kWeight = Symbol("kWeight");
|
|
42133
42133
|
var kMaxWeightPerServer = Symbol("kMaxWeightPerServer");
|
|
42134
42134
|
var kErrorPenalty = Symbol("kErrorPenalty");
|
|
42135
|
-
function getGreatestCommonDivisor(a,
|
|
42136
|
-
if (a === 0) return
|
|
42137
|
-
while (
|
|
42138
|
-
const t =
|
|
42139
|
-
|
|
42135
|
+
function getGreatestCommonDivisor(a, b) {
|
|
42136
|
+
if (a === 0) return b;
|
|
42137
|
+
while (b !== 0) {
|
|
42138
|
+
const t = b;
|
|
42139
|
+
b = a % b;
|
|
42140
42140
|
a = t;
|
|
42141
42141
|
}
|
|
42142
42142
|
return a;
|
|
@@ -42217,7 +42217,7 @@ var require_balanced_pool = __commonJS({
|
|
|
42217
42217
|
if (!dispatcher) {
|
|
42218
42218
|
return;
|
|
42219
42219
|
}
|
|
42220
|
-
const allClientsBusy = this[kClients].map((pool) => pool[kNeedDrain]).reduce((a,
|
|
42220
|
+
const allClientsBusy = this[kClients].map((pool) => pool[kNeedDrain]).reduce((a, b) => a && b, true);
|
|
42221
42221
|
if (allClientsBusy) {
|
|
42222
42222
|
return;
|
|
42223
42223
|
}
|
|
@@ -47932,8 +47932,8 @@ var require_headers = __commonJS({
|
|
|
47932
47932
|
}
|
|
47933
47933
|
return headersList.sortedMap = headers;
|
|
47934
47934
|
}
|
|
47935
|
-
function compareHeaderName(a,
|
|
47936
|
-
return a[0] <
|
|
47935
|
+
function compareHeaderName(a, b) {
|
|
47936
|
+
return a[0] < b[0] ? -1 : 1;
|
|
47937
47937
|
}
|
|
47938
47938
|
var HeadersList = class _HeadersList {
|
|
47939
47939
|
/** @type {[string, string][]|null} */
|
|
@@ -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.11_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");
|
|
@@ -54969,11 +54969,11 @@ var import_undici = __toESM(require_undici(), 1);
|
|
|
54969
54969
|
var import_crypto = require("crypto");
|
|
54970
54970
|
var import_crypto2 = require("crypto");
|
|
54971
54971
|
var import_node_module = __toESM(require("node:module"), 1);
|
|
54972
|
-
var Z = ((
|
|
54972
|
+
var Z = ((i) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(i, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : i)(function(i) {
|
|
54973
54973
|
if (typeof require < "u") return require.apply(this, arguments);
|
|
54974
|
-
throw Error('Dynamic require of "' +
|
|
54974
|
+
throw Error('Dynamic require of "' + i + '" is not supported');
|
|
54975
54975
|
});
|
|
54976
|
-
var
|
|
54976
|
+
var I = class {
|
|
54977
54977
|
config = {};
|
|
54978
54978
|
options;
|
|
54979
54979
|
constructor(e = { jsonPath: "./config.json" }) {
|
|
@@ -55037,85 +55037,85 @@ var $ = class {
|
|
|
55037
55037
|
return this.options.initialConfig && e.push("Initial Config"), this.options.useJsonFile && this.options.jsonPath && e.push(`JSON: ${this.options.jsonPath}`), this.options.useEnvFile && e.push(`ENV: ${this.options.envPath}`), this.options.useEnvironmentVariables && e.push("Environment Variables"), `Config sources: ${e.join(", ")}`;
|
|
55038
55038
|
}
|
|
55039
55039
|
};
|
|
55040
|
-
function v(...
|
|
55041
|
-
if (console.log(...
|
|
55042
|
-
let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(
|
|
55043
|
-
`,
|
|
55044
|
-
import_node_fs.default.appendFileSync(
|
|
55040
|
+
function v(...i) {
|
|
55041
|
+
if (console.log(...i), !(process.env.LOG === "true")) return;
|
|
55042
|
+
let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(i) ? i.map((r) => typeof r == "object" ? JSON.stringify(r) : String(r)).join(" ") : ""}
|
|
55043
|
+
`, o = process.env.LOG_FILE || "app.log";
|
|
55044
|
+
import_node_fs.default.appendFileSync(o, n, "utf8");
|
|
55045
55045
|
}
|
|
55046
|
-
function L(
|
|
55047
|
-
let
|
|
55048
|
-
return
|
|
55046
|
+
function L(i, e = 500, t = "internal_error", n = "api_error") {
|
|
55047
|
+
let o = new Error(i);
|
|
55048
|
+
return o.statusCode = e, o.code = t, o.type = n, o;
|
|
55049
55049
|
}
|
|
55050
|
-
async function le(
|
|
55051
|
-
e.log.error(
|
|
55052
|
-
let n =
|
|
55053
|
-
return t.code(n).send(
|
|
55050
|
+
async function le(i, e, t) {
|
|
55051
|
+
e.log.error(i);
|
|
55052
|
+
let n = i.statusCode || 500, o = { error: { message: i.message || "Internal Server Error", type: i.type || "api_error", code: i.code || "internal_error" } };
|
|
55053
|
+
return t.code(n).send(o);
|
|
55054
55054
|
}
|
|
55055
|
-
function de(
|
|
55055
|
+
function de(i, e, t) {
|
|
55056
55056
|
let n = new Headers({ "Content-Type": "application/json" });
|
|
55057
|
-
t.headers && Object.entries(t.headers).forEach(([
|
|
55058
|
-
n.set(
|
|
55057
|
+
t.headers && Object.entries(t.headers).forEach(([d, l]) => {
|
|
55058
|
+
n.set(d, l);
|
|
55059
55059
|
});
|
|
55060
|
-
let
|
|
55060
|
+
let o, r = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
|
|
55061
55061
|
if (t.signal) {
|
|
55062
|
-
let
|
|
55063
|
-
t.signal.addEventListener("abort",
|
|
55064
|
-
} else
|
|
55065
|
-
let c = { method: "POST", headers: n, body: JSON.stringify(e), signal:
|
|
55066
|
-
return t.httpsProxy && (c.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), v("final request:", typeof
|
|
55062
|
+
let d = new AbortController(), l = () => d.abort();
|
|
55063
|
+
t.signal.addEventListener("abort", l), r.addEventListener("abort", l), o = d.signal;
|
|
55064
|
+
} else o = r;
|
|
55065
|
+
let c = { method: "POST", headers: n, body: JSON.stringify(e), signal: o };
|
|
55066
|
+
return t.httpsProxy && (c.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), v("final request:", typeof i == "string" ? i : i.toString(), t.httpsProxy, c), fetch(typeof i == "string" ? i : i.toString(), c);
|
|
55067
55067
|
}
|
|
55068
|
-
var ue = async (
|
|
55069
|
-
|
|
55070
|
-
let e =
|
|
55071
|
-
for (let { name: t, transformer: n } of e) n.endPoint &&
|
|
55072
|
-
let c =
|
|
55073
|
-
if (!
|
|
55074
|
-
let
|
|
55068
|
+
var ue = async (i) => {
|
|
55069
|
+
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() }));
|
|
55070
|
+
let e = i._server.transformerService.getTransformersWithEndpoint();
|
|
55071
|
+
for (let { name: t, transformer: n } of e) n.endPoint && i.post(n.endPoint, async (o, r) => {
|
|
55072
|
+
let c = o.body, d = o.provider, l = i._server.providerService.getProvider(d);
|
|
55073
|
+
if (!l) throw L(`Provider '${d}' not found`, 404, "provider_not_found");
|
|
55074
|
+
let s = c, p = {};
|
|
55075
55075
|
if (typeof n.transformRequestOut == "function") {
|
|
55076
55076
|
let a = await n.transformRequestOut(c);
|
|
55077
|
-
a.body ? (
|
|
55077
|
+
a.body ? (s = a.body, p = a.config || {}) : s = a;
|
|
55078
55078
|
}
|
|
55079
|
-
if (v("use transformers:",
|
|
55079
|
+
if (v("use transformers:", l.transformer?.use), l.transformer?.use?.length) for (let a of l.transformer.use) {
|
|
55080
55080
|
if (!a || typeof a.transformRequestIn != "function") continue;
|
|
55081
|
-
let y = await a.transformRequestIn(
|
|
55082
|
-
y.body ? (
|
|
55083
|
-
}
|
|
55084
|
-
if (
|
|
55085
|
-
let _ = p.url || new URL(
|
|
55086
|
-
if (!
|
|
55087
|
-
let a = await
|
|
55088
|
-
throw v(`Error response from ${_}: ${a}`), L(`Error from provider: ${a}`,
|
|
55089
|
-
}
|
|
55090
|
-
let g =
|
|
55091
|
-
if (
|
|
55092
|
-
if (
|
|
55093
|
-
return n.transformResponseIn && (g = await n.transformResponseIn(g)), g.ok ||
|
|
55081
|
+
let y = await a.transformRequestIn(s, l);
|
|
55082
|
+
y.body ? (s = y.body, p = { ...p, ...y.config }) : s = y;
|
|
55083
|
+
}
|
|
55084
|
+
if (l.transformer?.[o.body.model]?.use?.length) for (let a of l.transformer[o.body.model].use) !a || typeof a.transformRequestIn != "function" || (s = await a.transformRequestIn(s, l));
|
|
55085
|
+
let _ = p.url || new URL(l.baseUrl), k = await de(_, s, { httpsProxy: i._server.configService.getHttpsProxy(), ...p, headers: { Authorization: `Bearer ${l.apiKey}`, ...p?.headers || {} } });
|
|
55086
|
+
if (!k.ok) {
|
|
55087
|
+
let a = await k.text();
|
|
55088
|
+
throw v(`Error response from ${_}: ${a}`), L(`Error from provider: ${a}`, k.status, "provider_response_error");
|
|
55089
|
+
}
|
|
55090
|
+
let g = k;
|
|
55091
|
+
if (l.transformer?.use?.length) for (let a of l.transformer.use) !a || typeof a.transformResponseOut != "function" || (g = await a.transformResponseOut(g));
|
|
55092
|
+
if (l.transformer?.[o.body.model]?.use?.length) for (let a of l.transformer[o.body.model].use) !a || typeof a.transformResponseOut != "function" || (g = await a.transformResponseOut(g));
|
|
55093
|
+
return n.transformResponseIn && (g = await n.transformResponseIn(g)), g.ok || r.code(g.status), c?.stream === true ? (r.header("Content-Type", "text/event-stream"), r.header("Cache-Control", "no-cache"), r.header("Connection", "keep-alive"), r.send(g.body)) : g.json();
|
|
55094
55094
|
});
|
|
55095
|
-
|
|
55096
|
-
let { name:
|
|
55097
|
-
if (!
|
|
55095
|
+
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) => {
|
|
55096
|
+
let { name: o, type: r, baseUrl: c, apiKey: d, models: l } = t.body;
|
|
55097
|
+
if (!o?.trim()) throw L("Provider name is required", 400, "invalid_request");
|
|
55098
55098
|
if (!c || !Ce(c)) throw L("Valid base URL is required", 400, "invalid_request");
|
|
55099
|
-
if (!
|
|
55100
|
-
if (!
|
|
55101
|
-
if (
|
|
55102
|
-
return
|
|
55103
|
-
}),
|
|
55104
|
-
let
|
|
55105
|
-
return
|
|
55106
|
-
}),
|
|
55107
|
-
let
|
|
55108
|
-
return
|
|
55109
|
-
}),
|
|
55099
|
+
if (!d?.trim()) throw L("API key is required", 400, "invalid_request");
|
|
55100
|
+
if (!l || !Array.isArray(l) || l.length === 0) throw L("At least one model is required", 400, "invalid_request");
|
|
55101
|
+
if (i._server.providerService.getProvider(id)) throw L(`Provider with ID '${id}' already exists`, 400, "provider_exists");
|
|
55102
|
+
return i._server.providerService.registerProvider(t.body);
|
|
55103
|
+
}), i.get("/providers", async (t, n) => i._server.providerService.getProviders()), i.get("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => {
|
|
55104
|
+
let o = i._server.providerService.getProvider(t.params.id);
|
|
55105
|
+
return o || n.code(404).send({ error: "Provider not found" });
|
|
55106
|
+
}), i.put("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] }, body: { type: "object", properties: { name: { type: "string" }, type: { type: "string", enum: ["openai", "anthropic"] }, baseUrl: { type: "string" }, apiKey: { type: "string" }, models: { type: "array", items: { type: "string" } }, enabled: { type: "boolean" } } } } }, async (t, n) => {
|
|
55107
|
+
let o = i._server.providerService.updateProvider(t.params.id, t.body);
|
|
55108
|
+
return o || n.code(404).send({ error: "Provider not found" });
|
|
55109
|
+
}), i.delete("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => i._server.providerService.deleteProvider(t.params.id) ? { message: "Provider deleted successfully" } : n.code(404).send({ error: "Provider not found" })), i.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) => i._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" }));
|
|
55110
55110
|
};
|
|
55111
|
-
function Ce(
|
|
55111
|
+
function Ce(i) {
|
|
55112
55112
|
try {
|
|
55113
|
-
return new URL(
|
|
55113
|
+
return new URL(i), true;
|
|
55114
55114
|
} catch {
|
|
55115
55115
|
return false;
|
|
55116
55116
|
}
|
|
55117
55117
|
}
|
|
55118
|
-
var
|
|
55118
|
+
var F = class {
|
|
55119
55119
|
constructor(e) {
|
|
55120
55120
|
this.providerService = e;
|
|
55121
55121
|
}
|
|
@@ -55152,7 +55152,7 @@ var q = class {
|
|
|
55152
55152
|
return this.providerService.getModelRoutes();
|
|
55153
55153
|
}
|
|
55154
55154
|
};
|
|
55155
|
-
var
|
|
55155
|
+
var q = class {
|
|
55156
55156
|
constructor(e, t) {
|
|
55157
55157
|
this.configService = e;
|
|
55158
55158
|
this.transformerService = t;
|
|
@@ -55172,20 +55172,20 @@ var F = class {
|
|
|
55172
55172
|
try {
|
|
55173
55173
|
if (!t.name || !t.api_base_url || !t.api_key) return;
|
|
55174
55174
|
let n = {};
|
|
55175
|
-
t.transformer && Object.keys(t.transformer).forEach((
|
|
55176
|
-
|
|
55177
|
-
if (Array.isArray(
|
|
55178
|
-
let c = this.transformerService.getTransformer(
|
|
55179
|
-
if (c) return new c(
|
|
55180
|
-
}
|
|
55181
|
-
if (typeof
|
|
55182
|
-
}).filter((
|
|
55183
|
-
if (Array.isArray(
|
|
55184
|
-
let c = this.transformerService.getTransformer(
|
|
55185
|
-
if (c) return new c(
|
|
55186
|
-
}
|
|
55187
|
-
if (typeof
|
|
55188
|
-
}).filter((
|
|
55175
|
+
t.transformer && Object.keys(t.transformer).forEach((o) => {
|
|
55176
|
+
o === "use" ? Array.isArray(t.transformer.use) && (n.use = t.transformer.use.map((r) => {
|
|
55177
|
+
if (Array.isArray(r) && typeof r[0] == "string") {
|
|
55178
|
+
let c = this.transformerService.getTransformer(r[0]);
|
|
55179
|
+
if (c) return new c(r[1]);
|
|
55180
|
+
}
|
|
55181
|
+
if (typeof r == "string") return this.transformerService.getTransformer(r);
|
|
55182
|
+
}).filter((r) => typeof r < "u")) : Array.isArray(t.transformer[o]?.use) && (n[o] = { use: t.transformer[o].use.map((r) => {
|
|
55183
|
+
if (Array.isArray(r) && typeof r[0] == "string") {
|
|
55184
|
+
let c = this.transformerService.getTransformer(r[0]);
|
|
55185
|
+
if (c) return new c(r[1]);
|
|
55186
|
+
}
|
|
55187
|
+
if (typeof r == "string") return this.transformerService.getTransformer(r);
|
|
55188
|
+
}).filter((r) => typeof r < "u") });
|
|
55189
55189
|
}), this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: t.transformer ? n : void 0 }), v(`${t.name} provider registered`);
|
|
55190
55190
|
} catch (n) {
|
|
55191
55191
|
v(`${t.name} provider registered error: ${n}`);
|
|
@@ -55195,8 +55195,8 @@ var F = class {
|
|
|
55195
55195
|
registerProvider(e) {
|
|
55196
55196
|
let t = { ...e };
|
|
55197
55197
|
return this.providers.set(t.name, t), e.models.forEach((n) => {
|
|
55198
|
-
let
|
|
55199
|
-
this.modelRoutes.set(
|
|
55198
|
+
let o = `${t.name},${n}`, r = { provider: t.name, model: n, fullModel: o };
|
|
55199
|
+
this.modelRoutes.set(o, r), this.modelRoutes.has(n) || this.modelRoutes.set(n, r);
|
|
55200
55200
|
}), t;
|
|
55201
55201
|
}
|
|
55202
55202
|
getProviders() {
|
|
@@ -55208,20 +55208,20 @@ var F = class {
|
|
|
55208
55208
|
updateProvider(e, t) {
|
|
55209
55209
|
let n = this.providers.get(e);
|
|
55210
55210
|
if (!n) return null;
|
|
55211
|
-
let
|
|
55212
|
-
return this.providers.set(e,
|
|
55213
|
-
let c = `${n.id},${
|
|
55214
|
-
this.modelRoutes.delete(c), this.modelRoutes.delete(
|
|
55215
|
-
}), t.models.forEach((
|
|
55216
|
-
let c = `${n.name},${
|
|
55217
|
-
this.modelRoutes.set(c,
|
|
55218
|
-
})),
|
|
55211
|
+
let o = { ...n, ...t, updatedAt: /* @__PURE__ */ new Date() };
|
|
55212
|
+
return this.providers.set(e, o), t.models && (n.models.forEach((r) => {
|
|
55213
|
+
let c = `${n.id},${r}`;
|
|
55214
|
+
this.modelRoutes.delete(c), this.modelRoutes.delete(r);
|
|
55215
|
+
}), t.models.forEach((r) => {
|
|
55216
|
+
let c = `${n.name},${r}`, d = { provider: n.name, model: r, fullModel: c };
|
|
55217
|
+
this.modelRoutes.set(c, d), this.modelRoutes.has(r) || this.modelRoutes.set(r, d);
|
|
55218
|
+
})), o;
|
|
55219
55219
|
}
|
|
55220
55220
|
deleteProvider(e) {
|
|
55221
55221
|
let t = this.providers.get(e);
|
|
55222
55222
|
return t ? (t.models.forEach((n) => {
|
|
55223
|
-
let
|
|
55224
|
-
this.modelRoutes.delete(
|
|
55223
|
+
let o = `${t.name},${n}`;
|
|
55224
|
+
this.modelRoutes.delete(o), this.modelRoutes.delete(n);
|
|
55225
55225
|
}), this.providers.delete(e), true) : false;
|
|
55226
55226
|
}
|
|
55227
55227
|
toggleProvider(e, t) {
|
|
@@ -55247,8 +55247,8 @@ var F = class {
|
|
|
55247
55247
|
parseTransformerConfig(e) {
|
|
55248
55248
|
return e ? Array.isArray(e) ? e.reduce((t, n) => {
|
|
55249
55249
|
if (Array.isArray(n)) {
|
|
55250
|
-
let [
|
|
55251
|
-
t[
|
|
55250
|
+
let [o, r = {}] = n;
|
|
55251
|
+
t[o] = r;
|
|
55252
55252
|
} else t[n] = {};
|
|
55253
55253
|
return t;
|
|
55254
55254
|
}, {}) : e : {};
|
|
@@ -55262,7 +55262,31 @@ var F = class {
|
|
|
55262
55262
|
}), { object: "list", data: e };
|
|
55263
55263
|
}
|
|
55264
55264
|
};
|
|
55265
|
-
var
|
|
55265
|
+
var T = [];
|
|
55266
|
+
for (let i = 0; i < 256; ++i) T.push((i + 256).toString(16).slice(1));
|
|
55267
|
+
function fe(i, e = 0) {
|
|
55268
|
+
return (T[i[e + 0]] + T[i[e + 1]] + T[i[e + 2]] + T[i[e + 3]] + "-" + T[i[e + 4]] + T[i[e + 5]] + "-" + T[i[e + 6]] + T[i[e + 7]] + "-" + T[i[e + 8]] + T[i[e + 9]] + "-" + T[i[e + 10]] + T[i[e + 11]] + T[i[e + 12]] + T[i[e + 13]] + T[i[e + 14]] + T[i[e + 15]]).toLowerCase();
|
|
55269
|
+
}
|
|
55270
|
+
var J = new Uint8Array(256);
|
|
55271
|
+
var U = J.length;
|
|
55272
|
+
function ee() {
|
|
55273
|
+
return U > J.length - 16 && ((0, import_crypto.randomFillSync)(J), U = 0), J.slice(U, U += 16);
|
|
55274
|
+
}
|
|
55275
|
+
var te = { randomUUID: import_crypto2.randomUUID };
|
|
55276
|
+
function Re(i, e, t) {
|
|
55277
|
+
if (te.randomUUID && !e && !i) return te.randomUUID();
|
|
55278
|
+
i = i || {};
|
|
55279
|
+
let n = i.random ?? i.rng?.() ?? ee();
|
|
55280
|
+
if (n.length < 16) throw new Error("Random bytes length must be >= 16");
|
|
55281
|
+
if (n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, e) {
|
|
55282
|
+
if (t = t || 0, t < 0 || t + 16 > e.length) throw new RangeError(`UUID byte range ${t}:${t + 15} is out of buffer bounds`);
|
|
55283
|
+
for (let o = 0; o < 16; ++o) e[t + o] = n[o];
|
|
55284
|
+
return e;
|
|
55285
|
+
}
|
|
55286
|
+
return fe(n);
|
|
55287
|
+
}
|
|
55288
|
+
var H = Re;
|
|
55289
|
+
var j = class {
|
|
55266
55290
|
name = "Anthropic";
|
|
55267
55291
|
endPoint = "/v1/messages";
|
|
55268
55292
|
async transformRequestOut(e) {
|
|
@@ -55270,32 +55294,32 @@ var U = class {
|
|
|
55270
55294
|
let t = [];
|
|
55271
55295
|
if (e.system) {
|
|
55272
55296
|
if (typeof e.system == "string") t.push({ role: "system", content: e.system });
|
|
55273
|
-
else if (Array.isArray(e.system)) {
|
|
55274
|
-
let
|
|
55275
|
-
t.push({ role: "system", content:
|
|
55297
|
+
else if (Array.isArray(e.system) && e.system.length) {
|
|
55298
|
+
let r = e.system.filter((c) => c.type === "text" && c.text).map((c) => ({ type: "text", text: c.text, cache_control: c.cache_control }));
|
|
55299
|
+
t.push({ role: "system", content: r });
|
|
55276
55300
|
}
|
|
55277
55301
|
}
|
|
55278
|
-
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((
|
|
55279
|
-
if (
|
|
55280
|
-
if (typeof
|
|
55281
|
-
t.push({ role:
|
|
55302
|
+
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((r, c) => {
|
|
55303
|
+
if (r.role === "user" || r.role === "assistant") {
|
|
55304
|
+
if (typeof r.content == "string") {
|
|
55305
|
+
t.push({ role: r.role, content: r.content });
|
|
55282
55306
|
return;
|
|
55283
55307
|
}
|
|
55284
|
-
if (Array.isArray(
|
|
55285
|
-
if (
|
|
55286
|
-
let
|
|
55287
|
-
|
|
55288
|
-
let _ = { role: "tool", content: typeof
|
|
55308
|
+
if (Array.isArray(r.content)) {
|
|
55309
|
+
if (r.role === "user") {
|
|
55310
|
+
let d = r.content.filter((s) => s.type === "tool_result" && s.tool_use_id);
|
|
55311
|
+
d.length && d.forEach((s, p) => {
|
|
55312
|
+
let _ = { role: "tool", content: typeof s.content == "string" ? s.content : JSON.stringify(s.content), tool_call_id: s.tool_use_id, cache_control: s.cache_control };
|
|
55289
55313
|
t.push(_);
|
|
55290
55314
|
});
|
|
55291
|
-
let
|
|
55292
|
-
|
|
55293
|
-
} else if (
|
|
55294
|
-
let
|
|
55295
|
-
|
|
55315
|
+
let l = r.content.filter((s) => s.type === "text" && s.text || s.type === "image" && s.source);
|
|
55316
|
+
l.length && t.push({ role: "user", content: l.map((s) => s?.type === "image" ? { type: "image_url", image_url: { url: s.source?.type === "base64" ? s.source.data : s.source.url }, media_type: s.source.media_type } : s) });
|
|
55317
|
+
} else if (r.role === "assistant") {
|
|
55318
|
+
let d = { role: "assistant", content: null }, l = r.content.filter((p) => p.type === "text" && p.text);
|
|
55319
|
+
l.length && (d.content = l.map((p) => p.text).join(`
|
|
55296
55320
|
`));
|
|
55297
|
-
let
|
|
55298
|
-
|
|
55321
|
+
let s = r.content.filter((p) => p.type === "tool_use" && p.id);
|
|
55322
|
+
s.length && (d.tool_calls = s.map((p) => ({ id: p.id, type: "function", function: { name: p.name, arguments: JSON.stringify(p.input || {}) } }))), t.push(d);
|
|
55299
55323
|
}
|
|
55300
55324
|
return;
|
|
55301
55325
|
}
|
|
@@ -55308,8 +55332,8 @@ var U = class {
|
|
|
55308
55332
|
let n = await this.convertOpenAIStreamToAnthropic(e.body);
|
|
55309
55333
|
return new Response(n, { headers: { "Content-Type": "text/event-stream", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
55310
55334
|
} else {
|
|
55311
|
-
let n = await e.json(),
|
|
55312
|
-
return new Response(JSON.stringify(
|
|
55335
|
+
let n = await e.json(), o = this.convertOpenAIResponseToAnthropic(n);
|
|
55336
|
+
return new Response(JSON.stringify(o), { headers: { "Content-Type": "application/json" } });
|
|
55313
55337
|
}
|
|
55314
55338
|
}
|
|
55315
55339
|
convertAnthropicToolsToUnified(e) {
|
|
@@ -55317,14 +55341,14 @@ var U = class {
|
|
|
55317
55341
|
}
|
|
55318
55342
|
async convertOpenAIStreamToAnthropic(e) {
|
|
55319
55343
|
return new ReadableStream({ async start(n) {
|
|
55320
|
-
let
|
|
55344
|
+
let o = new TextEncoder(), r = `msg_${Date.now()}`, c = "unknown", d = false, l = false, s = false, p = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map(), k = 0, g = 0, u = 0, a = false, y = false, h = 0, f = (x) => {
|
|
55321
55345
|
if (!a) try {
|
|
55322
55346
|
n.enqueue(x);
|
|
55323
|
-
let
|
|
55324
|
-
v("send data:",
|
|
55325
|
-
} catch (
|
|
55326
|
-
if (
|
|
55327
|
-
else throw v(`send data error: ${
|
|
55347
|
+
let b = new TextDecoder().decode(x);
|
|
55348
|
+
v("send data:", b.trim());
|
|
55349
|
+
} catch (b) {
|
|
55350
|
+
if (b instanceof TypeError && b.message.includes("Controller is already closed")) a = true;
|
|
55351
|
+
else throw v(`send data error: ${b.message}`), b;
|
|
55328
55352
|
}
|
|
55329
55353
|
}, m = () => {
|
|
55330
55354
|
if (!a) try {
|
|
@@ -55333,170 +55357,189 @@ var U = class {
|
|
|
55333
55357
|
if (x instanceof TypeError && x.message.includes("Controller is already closed")) a = true;
|
|
55334
55358
|
else throw x;
|
|
55335
55359
|
}
|
|
55336
|
-
},
|
|
55360
|
+
}, S = null;
|
|
55337
55361
|
try {
|
|
55338
|
-
|
|
55339
|
-
let x = new TextDecoder(),
|
|
55362
|
+
S = e.getReader();
|
|
55363
|
+
let x = new TextDecoder(), b = "";
|
|
55340
55364
|
for (; !a; ) {
|
|
55341
|
-
let { done: X, value: me } = await
|
|
55365
|
+
let { done: X, value: me } = await S.read();
|
|
55342
55366
|
if (X) break;
|
|
55343
|
-
|
|
55344
|
-
let se =
|
|
55367
|
+
b += x.decode(me, { stream: true });
|
|
55368
|
+
let se = b.split(`
|
|
55345
55369
|
`);
|
|
55346
|
-
|
|
55370
|
+
b = se.pop() || "";
|
|
55347
55371
|
for (let ie of se) {
|
|
55348
|
-
if (a ||
|
|
55372
|
+
if (a || s) break;
|
|
55349
55373
|
if (!ie.startsWith("data: ")) continue;
|
|
55350
55374
|
let Q = ie.slice(6);
|
|
55351
55375
|
if (Q !== "[DONE]") try {
|
|
55352
55376
|
let O = JSON.parse(Q);
|
|
55353
|
-
if (
|
|
55354
|
-
let
|
|
55355
|
-
f(
|
|
55356
|
-
data: ${JSON.stringify(
|
|
55377
|
+
if (k++, v("Original Response:", JSON.stringify(O, null, 2)), O.error) {
|
|
55378
|
+
let C = { type: "error", message: { type: "api_error", message: JSON.stringify(O.error) } };
|
|
55379
|
+
f(o.encode(`event: error
|
|
55380
|
+
data: ${JSON.stringify(C)}
|
|
55357
55381
|
|
|
55358
55382
|
`));
|
|
55359
55383
|
continue;
|
|
55360
55384
|
}
|
|
55361
|
-
if (c = O.model || c, !
|
|
55362
|
-
|
|
55363
|
-
let
|
|
55364
|
-
f(
|
|
55365
|
-
data: ${JSON.stringify(
|
|
55385
|
+
if (c = O.model || c, !d && !a && !s) {
|
|
55386
|
+
d = true;
|
|
55387
|
+
let C = { type: "message_start", message: { id: r, type: "message", role: "assistant", content: [], model: c, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
|
|
55388
|
+
f(o.encode(`event: message_start
|
|
55389
|
+
data: ${JSON.stringify(C)}
|
|
55366
55390
|
|
|
55367
55391
|
`));
|
|
55368
55392
|
}
|
|
55369
55393
|
let w = O.choices?.[0];
|
|
55370
55394
|
if (!w) continue;
|
|
55371
|
-
if (w?.delta?.thinking && !a && !
|
|
55395
|
+
if (w?.delta?.thinking && !a && !s) {
|
|
55372
55396
|
if (!y) {
|
|
55373
|
-
let
|
|
55374
|
-
f(
|
|
55375
|
-
data: ${JSON.stringify(
|
|
55397
|
+
let C = { type: "content_block_start", index: h, content_block: { type: "thinking", thinking: "" } };
|
|
55398
|
+
f(o.encode(`event: content_block_start
|
|
55399
|
+
data: ${JSON.stringify(C)}
|
|
55376
55400
|
|
|
55377
55401
|
`)), y = true;
|
|
55378
55402
|
}
|
|
55379
55403
|
if (w.delta.thinking.signature) {
|
|
55380
|
-
let
|
|
55381
|
-
f(
|
|
55382
|
-
data: ${JSON.stringify(
|
|
55404
|
+
let C = { type: "content_block_delta", index: h, delta: { type: "signature_delta", signature: w.delta.thinking.signature } };
|
|
55405
|
+
f(o.encode(`event: content_block_delta
|
|
55406
|
+
data: ${JSON.stringify(C)}
|
|
55383
55407
|
|
|
55384
55408
|
`));
|
|
55385
|
-
let
|
|
55386
|
-
f(
|
|
55387
|
-
data: ${JSON.stringify(
|
|
55409
|
+
let R = { type: "content_block_stop", index: h };
|
|
55410
|
+
f(o.encode(`event: content_block_stop
|
|
55411
|
+
data: ${JSON.stringify(R)}
|
|
55388
55412
|
|
|
55389
55413
|
`)), h++;
|
|
55390
55414
|
} else if (w.delta.thinking.content) {
|
|
55391
|
-
let
|
|
55392
|
-
f(
|
|
55393
|
-
data: ${JSON.stringify(
|
|
55415
|
+
let C = { type: "content_block_delta", index: h, delta: { type: "thinking_delta", thinking: w.delta.thinking.content || "" } };
|
|
55416
|
+
f(o.encode(`event: content_block_delta
|
|
55417
|
+
data: ${JSON.stringify(C)}
|
|
55394
55418
|
|
|
55395
55419
|
`));
|
|
55396
55420
|
}
|
|
55397
55421
|
}
|
|
55398
|
-
if (w?.delta?.content && !a && !
|
|
55399
|
-
if (g++, !
|
|
55400
|
-
|
|
55401
|
-
let
|
|
55402
|
-
f(
|
|
55403
|
-
data: ${JSON.stringify(
|
|
55422
|
+
if (w?.delta?.content && !a && !s) {
|
|
55423
|
+
if (g++, !l && !s) {
|
|
55424
|
+
l = true;
|
|
55425
|
+
let C = { type: "content_block_start", index: h, content_block: { type: "text", text: "" } };
|
|
55426
|
+
f(o.encode(`event: content_block_start
|
|
55427
|
+
data: ${JSON.stringify(C)}
|
|
55404
55428
|
|
|
55405
55429
|
`));
|
|
55406
55430
|
}
|
|
55407
|
-
if (!a && !
|
|
55408
|
-
let
|
|
55409
|
-
f(
|
|
55410
|
-
data: ${JSON.stringify(
|
|
55431
|
+
if (!a && !s) {
|
|
55432
|
+
let C = { type: "content_block_delta", index: h, delta: { type: "text_delta", text: w.delta.content } };
|
|
55433
|
+
f(o.encode(`event: content_block_delta
|
|
55434
|
+
data: ${JSON.stringify(C)}
|
|
55411
55435
|
|
|
55412
55436
|
`));
|
|
55413
55437
|
}
|
|
55414
55438
|
}
|
|
55415
|
-
if (w?.delta?.
|
|
55439
|
+
if (w?.delta?.annotations?.length && !a && !s) {
|
|
55440
|
+
let C = { type: "content_block_stop", index: h };
|
|
55441
|
+
f(o.encode(`event: content_block_stop
|
|
55442
|
+
data: ${JSON.stringify(C)}
|
|
55443
|
+
|
|
55444
|
+
`)), l = false, w?.delta?.annotations.forEach((R, P, he) => {
|
|
55445
|
+
h++;
|
|
55446
|
+
let E = { type: "content_block_start", index: h, content_block: { type: "web_search_tool_result", tool_use_id: `srvtoolu_${H()}`, content: [{ type: "web_search_result", title: R.url_citation.title, url: R.url_citation.url }] } };
|
|
55447
|
+
f(o.encode(`event: content_block_start
|
|
55448
|
+
data: ${JSON.stringify(E)}
|
|
55449
|
+
|
|
55450
|
+
`));
|
|
55451
|
+
let A = { type: "content_block_stop", index: h };
|
|
55452
|
+
f(o.encode(`event: content_block_stop
|
|
55453
|
+
data: ${JSON.stringify(A)}
|
|
55454
|
+
|
|
55455
|
+
`));
|
|
55456
|
+
});
|
|
55457
|
+
}
|
|
55458
|
+
if (w?.delta?.tool_calls && !a && !s) {
|
|
55416
55459
|
u++;
|
|
55417
|
-
let
|
|
55418
|
-
for (let
|
|
55460
|
+
let C = /* @__PURE__ */ new Set();
|
|
55461
|
+
for (let R of w.delta.tool_calls) {
|
|
55419
55462
|
if (a) break;
|
|
55420
|
-
let P =
|
|
55421
|
-
if (
|
|
55422
|
-
if (
|
|
55423
|
-
let E =
|
|
55463
|
+
let P = R.index ?? 0;
|
|
55464
|
+
if (C.has(P)) continue;
|
|
55465
|
+
if (C.add(P), !_.has(P)) {
|
|
55466
|
+
let E = l ? _.size + 1 : _.size;
|
|
55424
55467
|
if (E !== 0) {
|
|
55425
55468
|
v("content_block_stop2");
|
|
55426
|
-
let
|
|
55427
|
-
f(
|
|
55428
|
-
data: ${JSON.stringify(
|
|
55469
|
+
let ge = { type: "content_block_stop", index: h };
|
|
55470
|
+
f(o.encode(`event: content_block_stop
|
|
55471
|
+
data: ${JSON.stringify(ge)}
|
|
55429
55472
|
|
|
55430
55473
|
`)), h++;
|
|
55431
55474
|
}
|
|
55432
55475
|
_.set(P, E);
|
|
55433
|
-
let
|
|
55434
|
-
f(
|
|
55435
|
-
data: ${JSON.stringify(
|
|
55476
|
+
let A = R.id || `call_${Date.now()}_${P}`, N = R.function?.name || `tool_${P}`, M = { type: "content_block_start", index: h, content_block: { type: "tool_use", id: A, name: N, input: {} } };
|
|
55477
|
+
f(o.encode(`event: content_block_start
|
|
55478
|
+
data: ${JSON.stringify(M)}
|
|
55436
55479
|
|
|
55437
55480
|
`));
|
|
55438
|
-
let
|
|
55439
|
-
p.set(P,
|
|
55440
|
-
} else if (
|
|
55481
|
+
let $ = { id: A, name: N, arguments: "", contentBlockIndex: E };
|
|
55482
|
+
p.set(P, $);
|
|
55483
|
+
} else if (R.id && R.function?.name) {
|
|
55441
55484
|
let E = p.get(P);
|
|
55442
|
-
E.id.startsWith("call_") && E.name.startsWith("tool_") && (E.id =
|
|
55485
|
+
E.id.startsWith("call_") && E.name.startsWith("tool_") && (E.id = R.id, E.name = R.function.name);
|
|
55443
55486
|
}
|
|
55444
|
-
if (
|
|
55487
|
+
if (R.function?.arguments && !a && !s) {
|
|
55445
55488
|
if (_.get(P) === void 0) continue;
|
|
55446
|
-
let
|
|
55447
|
-
if (
|
|
55448
|
-
|
|
55489
|
+
let A = p.get(P);
|
|
55490
|
+
if (A) {
|
|
55491
|
+
A.arguments += R.function.arguments;
|
|
55449
55492
|
try {
|
|
55450
|
-
let
|
|
55451
|
-
if (
|
|
55452
|
-
|
|
55453
|
-
} catch (
|
|
55454
|
-
v("Tool call index:", P, "error",
|
|
55493
|
+
let N = null, M = A.arguments.trim();
|
|
55494
|
+
if (M.startsWith("{") && M.endsWith("}")) try {
|
|
55495
|
+
N = JSON.parse(M);
|
|
55496
|
+
} catch ($) {
|
|
55497
|
+
v("Tool call index:", P, "error", $.message);
|
|
55455
55498
|
}
|
|
55456
|
-
} catch (
|
|
55457
|
-
v("Tool call index:", P, "error",
|
|
55499
|
+
} catch (N) {
|
|
55500
|
+
v("Tool call index:", P, "error", N.message);
|
|
55458
55501
|
}
|
|
55459
55502
|
}
|
|
55460
55503
|
try {
|
|
55461
|
-
let
|
|
55462
|
-
f(
|
|
55463
|
-
data: ${JSON.stringify(
|
|
55504
|
+
let N = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: R.function.arguments } };
|
|
55505
|
+
f(o.encode(`event: content_block_delta
|
|
55506
|
+
data: ${JSON.stringify(N)}
|
|
55464
55507
|
|
|
55465
55508
|
`));
|
|
55466
55509
|
} catch {
|
|
55467
55510
|
try {
|
|
55468
|
-
let
|
|
55469
|
-
f(
|
|
55470
|
-
data: ${JSON.stringify(
|
|
55511
|
+
let M = R.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), $ = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: M } };
|
|
55512
|
+
f(o.encode(`event: content_block_delta
|
|
55513
|
+
data: ${JSON.stringify($)}
|
|
55471
55514
|
|
|
55472
55515
|
`));
|
|
55473
|
-
} catch (
|
|
55474
|
-
console.error(
|
|
55516
|
+
} catch (M) {
|
|
55517
|
+
console.error(M);
|
|
55475
55518
|
}
|
|
55476
55519
|
}
|
|
55477
55520
|
}
|
|
55478
55521
|
}
|
|
55479
55522
|
}
|
|
55480
|
-
if (w?.finish_reason && !a && !
|
|
55481
|
-
if (
|
|
55523
|
+
if (w?.finish_reason && !a && !s) {
|
|
55524
|
+
if (s = true, g === 0 && u === 0 && console.error("Warning: No content in the stream response!"), (l || u > 0) && !a) {
|
|
55482
55525
|
v("content_block_stop hasTextContentStarted");
|
|
55483
|
-
let
|
|
55484
|
-
f(
|
|
55485
|
-
data: ${JSON.stringify(
|
|
55526
|
+
let C = { type: "content_block_stop", index: h };
|
|
55527
|
+
f(o.encode(`event: content_block_stop
|
|
55528
|
+
data: ${JSON.stringify(C)}
|
|
55486
55529
|
|
|
55487
55530
|
`));
|
|
55488
55531
|
}
|
|
55489
55532
|
if (!a) {
|
|
55490
55533
|
let P = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[w.finish_reason] || "end_turn", stop_sequence: null }, usage: { input_tokens: O.usage?.prompt_tokens || 0, output_tokens: O.usage?.completion_tokens || 0 } };
|
|
55491
|
-
f(
|
|
55534
|
+
f(o.encode(`event: message_delta
|
|
55492
55535
|
data: ${JSON.stringify(P)}
|
|
55493
55536
|
|
|
55494
55537
|
`));
|
|
55495
55538
|
}
|
|
55496
55539
|
if (!a) {
|
|
55497
|
-
let
|
|
55498
|
-
f(
|
|
55499
|
-
data: ${JSON.stringify(
|
|
55540
|
+
let C = { type: "message_stop" };
|
|
55541
|
+
f(o.encode(`event: message_stop
|
|
55542
|
+
data: ${JSON.stringify(C)}
|
|
55500
55543
|
|
|
55501
55544
|
`));
|
|
55502
55545
|
}
|
|
@@ -55511,12 +55554,12 @@ data: ${JSON.stringify(k)}
|
|
|
55511
55554
|
} catch (x) {
|
|
55512
55555
|
if (!a) try {
|
|
55513
55556
|
n.error(x);
|
|
55514
|
-
} catch (
|
|
55515
|
-
console.error(
|
|
55557
|
+
} catch (b) {
|
|
55558
|
+
console.error(b);
|
|
55516
55559
|
}
|
|
55517
55560
|
} finally {
|
|
55518
|
-
if (
|
|
55519
|
-
|
|
55561
|
+
if (S) try {
|
|
55562
|
+
S.releaseLock();
|
|
55520
55563
|
} catch (x) {
|
|
55521
55564
|
console.error(x);
|
|
55522
55565
|
}
|
|
@@ -55530,82 +55573,105 @@ data: ${JSON.stringify(k)}
|
|
|
55530
55573
|
let t = e.choices[0];
|
|
55531
55574
|
if (!t) throw new Error("No choices found in OpenAI response");
|
|
55532
55575
|
let n = [];
|
|
55533
|
-
|
|
55534
|
-
let
|
|
55576
|
+
if (t.message.annotations) {
|
|
55577
|
+
let r = `srvtoolu_${H()}`;
|
|
55578
|
+
n.push({ type: "server_tool_use", id: r, name: "web_search", input: { query: "" } }), n.push({ type: "web_search_tool_result", tool_use_id: r, content: t.message.annotations.map((c) => ({ type: "web_search_result", url: c.url_citation.url, title: c.url_citation.title })) });
|
|
55579
|
+
}
|
|
55580
|
+
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, c) => {
|
|
55581
|
+
let d = {};
|
|
55535
55582
|
try {
|
|
55536
|
-
let
|
|
55537
|
-
typeof
|
|
55583
|
+
let l = r.function.arguments || "{}";
|
|
55584
|
+
typeof l == "object" ? d = l : typeof l == "string" && (d = JSON.parse(l));
|
|
55538
55585
|
} catch {
|
|
55539
|
-
|
|
55586
|
+
d = { text: r.function.arguments || "" };
|
|
55540
55587
|
}
|
|
55541
|
-
n.push({ type: "tool_use", id:
|
|
55588
|
+
n.push({ type: "tool_use", id: r.id, name: r.function.name, input: d });
|
|
55542
55589
|
});
|
|
55543
|
-
let
|
|
55544
|
-
return v("Conversion complete, final Anthropic response:", JSON.stringify(
|
|
55590
|
+
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 } };
|
|
55591
|
+
return v("Conversion complete, final Anthropic response:", JSON.stringify(o, null, 2)), o;
|
|
55545
55592
|
}
|
|
55546
55593
|
};
|
|
55547
|
-
function
|
|
55548
|
-
if (!(!
|
|
55549
|
-
if (Array.isArray(
|
|
55550
|
-
|
|
55594
|
+
function ne(i) {
|
|
55595
|
+
if (!(!i || typeof i != "object")) {
|
|
55596
|
+
if (Array.isArray(i)) {
|
|
55597
|
+
i.forEach(ne);
|
|
55551
55598
|
return;
|
|
55552
55599
|
}
|
|
55553
|
-
delete
|
|
55554
|
-
|
|
55600
|
+
delete i.$schema, delete i.additionalProperties, i.type === "string" && i.format && !["enum", "date-time"].includes(i.format) && delete i.format, Object.keys(i).forEach((e) => {
|
|
55601
|
+
ne(i[e]);
|
|
55555
55602
|
});
|
|
55556
55603
|
}
|
|
55557
55604
|
}
|
|
55558
|
-
var
|
|
55605
|
+
var D = class {
|
|
55559
55606
|
name = "gemini";
|
|
55560
55607
|
endPoint = "/v1beta/models/:modelAndAction";
|
|
55561
55608
|
async transformRequestIn(e, t) {
|
|
55562
|
-
|
|
55563
|
-
|
|
55564
|
-
|
|
55565
|
-
|
|
55566
|
-
|
|
55567
|
-
|
|
55568
|
-
if (
|
|
55569
|
-
|
|
55570
|
-
|
|
55609
|
+
let n = [], o = e.tools?.filter((c) => c.function.name !== "web_search")?.map((c) => (c.function.parameters && ne(c.function.parameters), { name: c.function.name, description: c.function.description, parameters: c.function.parameters }));
|
|
55610
|
+
return o?.length && n.push({ functionDeclarations: o }), e.tools?.find((c) => c.function.name === "web_search") && n.push({ google_search: {} }), { body: { contents: e.messages.map((c) => {
|
|
55611
|
+
let d;
|
|
55612
|
+
c.role === "assistant" ? d = "model" : (["user", "system", "tool"].includes(c.role), d = "user");
|
|
55613
|
+
let l = [];
|
|
55614
|
+
return typeof c.content == "string" ? l.push({ text: c.content }) : Array.isArray(c.content) && l.push(...c.content.map((s) => {
|
|
55615
|
+
if (s.type === "text") return { text: s.text || "" };
|
|
55616
|
+
if (s.type === "image_url") return s.image_url.url.startsWith("http") ? { file_data: { mime_type: s.media_type, file_uri: s.image_url.url } } : { inlineData: { mime_type: s.media_type, data: s.image_url.url } };
|
|
55617
|
+
})), Array.isArray(c.tool_calls) && l.push(...c.tool_calls.map((s) => ({ functionCall: { id: s.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: s.function.name, args: JSON.parse(s.function.arguments || "{}") } }))), { role: d, parts: l };
|
|
55618
|
+
}), tools: n.length ? n : void 0 }, config: { url: new URL(`./${e.model}:${e.stream ? "streamGenerateContent?alt=sse" : "generateContent"}`, t.baseUrl), headers: { "x-goog-api-key": t.apiKey, Authorization: void 0 } } };
|
|
55571
55619
|
}
|
|
55572
55620
|
transformRequestOut(e) {
|
|
55573
|
-
let t = e.contents, n = e.tools,
|
|
55621
|
+
let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens, c = e.temperature, d = e.stream, l = e.tool_choice, s = { messages: [], model: o, max_tokens: r, temperature: c, stream: d, tool_choice: l };
|
|
55574
55622
|
return Array.isArray(t) && t.forEach((p) => {
|
|
55575
|
-
typeof p == "string" ?
|
|
55576
|
-
}), Array.isArray(n) && (
|
|
55623
|
+
typeof p == "string" ? s.messages.push({ role: "user", content: p }) : typeof p.text == "string" ? s.messages.push({ role: "user", content: p.text || null }) : p.role === "user" ? s.messages.push({ role: "user", content: p?.parts?.map((_) => ({ type: "text", text: _.text || "" })) || [] }) : p.role === "model" && s.messages.push({ role: "assistant", content: p?.parts?.map((_) => ({ type: "text", text: _.text || "" })) || [] });
|
|
55624
|
+
}), Array.isArray(n) && (s.tools = [], n.forEach((p) => {
|
|
55577
55625
|
Array.isArray(p.functionDeclarations) && p.functionDeclarations.forEach((_) => {
|
|
55578
|
-
|
|
55626
|
+
s.tools.push({ type: "function", function: { name: _.name, description: _.description, parameters: _.parameters } });
|
|
55579
55627
|
});
|
|
55580
|
-
})),
|
|
55628
|
+
})), s;
|
|
55581
55629
|
}
|
|
55582
55630
|
async transformResponseOut(e) {
|
|
55583
55631
|
if (e.headers.get("Content-Type")?.includes("application/json")) {
|
|
55584
|
-
let t = await e.json(), n = t.candidates[0].content.parts
|
|
55632
|
+
let t = await e.json(), n = t.candidates[0].content.parts?.filter((r) => r.functionCall)?.map((r) => ({ id: r.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: r.functionCall?.name, arguments: JSON.stringify(r.functionCall?.args || {}) } })), o = { id: t.responseId, choices: [{ finish_reason: t.candidates[0].finishReason?.toLowerCase() || null, index: 0, message: { content: t.candidates[0].content.parts?.filter((r) => r.text)?.map((r) => r.text)?.join(`
|
|
55585
55633
|
`), role: "assistant", tool_calls: n.length > 0 ? n : void 0 } }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), model: t.modelVersion, object: "chat.completion", usage: { completion_tokens: t.usageMetadata.candidatesTokenCount, prompt_tokens: t.usageMetadata.promptTokenCount, total_tokens: t.usageMetadata.totalTokenCount } };
|
|
55586
|
-
return new Response(JSON.stringify(
|
|
55634
|
+
return new Response(JSON.stringify(o), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55587
55635
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55588
55636
|
if (!e.body) return e;
|
|
55589
|
-
let t = new TextDecoder(), n = new TextEncoder(),
|
|
55590
|
-
|
|
55591
|
-
|
|
55592
|
-
|
|
55593
|
-
|
|
55594
|
-
|
|
55595
|
-
|
|
55596
|
-
|
|
55597
|
-
|
|
55598
|
-
|
|
55599
|
-
|
|
55600
|
-
|
|
55601
|
-
v("gemini response:", JSON.stringify(_, null, 2)), o.enqueue(n.encode(`data: ${JSON.stringify(_)}
|
|
55637
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = (c, d) => {
|
|
55638
|
+
if (c.startsWith("data: ")) {
|
|
55639
|
+
let l = c.slice(6).trim();
|
|
55640
|
+
if (l) {
|
|
55641
|
+
v("gemini chunk:", l);
|
|
55642
|
+
try {
|
|
55643
|
+
let s = JSON.parse(l), p = s.candidates[0].content.parts?.filter((k) => k.functionCall)?.map((k) => ({ id: k.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: k.functionCall?.name, arguments: JSON.stringify(k.functionCall?.args || {}) } })), _ = { choices: [{ delta: { role: "assistant", content: s.candidates[0].content.parts?.filter((k) => k.text)?.map((k) => k.text)?.join(`
|
|
55644
|
+
`), tool_calls: p.length > 0 ? p : void 0 }, finish_reason: s.candidates[0].finishReason?.toLowerCase() || null, index: s.candidates[0].index || p.length > 0 ? 1 : 0, logprobs: null }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), id: s.responseId || "", model: s.modelVersion || "", object: "chat.completion.chunk", system_fingerprint: "fp_a49d71b8a1", usage: { completion_tokens: s.usageMetadata.candidatesTokenCount, prompt_tokens: s.usageMetadata.promptTokenCount, total_tokens: s.usageMetadata.totalTokenCount } };
|
|
55645
|
+
s.candidates[0]?.groundingMetadata?.groundingChunks?.length && (_.choices[0].delta.annotations = s.candidates[0].groundingMetadata.groundingChunks.map((k, g) => {
|
|
55646
|
+
let u = s.candidates[0]?.groundingMetadata?.groundingSupports?.filter((a) => a.groundingChunkIndices.includes(g));
|
|
55647
|
+
return { type: "url_citation", url_citation: { url: k.web.uri, title: k.web.title, content: u?.[0].segment.text, start_index: u?.[0].segment.startIndex, end_index: u?.[0].segment.endIndex } };
|
|
55648
|
+
})), d.enqueue(n.encode(`data: ${JSON.stringify(_)}
|
|
55602
55649
|
|
|
55603
55650
|
`));
|
|
55651
|
+
} catch (s) {
|
|
55652
|
+
v("Error parsing Gemini stream chunk", l, s.message);
|
|
55653
|
+
}
|
|
55654
|
+
}
|
|
55655
|
+
}
|
|
55656
|
+
}, r = new ReadableStream({ async start(c) {
|
|
55657
|
+
let d = e.body.getReader(), l = "";
|
|
55658
|
+
try {
|
|
55659
|
+
for (; ; ) {
|
|
55660
|
+
let { done: s, value: p } = await d.read();
|
|
55661
|
+
if (s) {
|
|
55662
|
+
l && o(l, c);
|
|
55663
|
+
break;
|
|
55664
|
+
}
|
|
55665
|
+
l += t.decode(p, { stream: true });
|
|
55666
|
+
let _ = l.split(`
|
|
55667
|
+
`);
|
|
55668
|
+
l = _.pop() || "";
|
|
55669
|
+
for (let k of _) o(k, c);
|
|
55604
55670
|
}
|
|
55605
|
-
} catch (
|
|
55606
|
-
|
|
55671
|
+
} catch (s) {
|
|
55672
|
+
c.error(s);
|
|
55607
55673
|
} finally {
|
|
55608
|
-
|
|
55674
|
+
c.close();
|
|
55609
55675
|
}
|
|
55610
55676
|
} });
|
|
55611
55677
|
return new Response(r, { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
@@ -55613,7 +55679,7 @@ var J = class {
|
|
|
55613
55679
|
return e;
|
|
55614
55680
|
}
|
|
55615
55681
|
};
|
|
55616
|
-
var
|
|
55682
|
+
var B = class {
|
|
55617
55683
|
name = "deepseek";
|
|
55618
55684
|
transformRequestIn(e) {
|
|
55619
55685
|
return e.max_tokens && e.max_tokens > 8192 && (e.max_tokens = 8192), e;
|
|
@@ -55624,58 +55690,58 @@ var j = class {
|
|
|
55624
55690
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55625
55691
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55626
55692
|
if (!e.body) return e;
|
|
55627
|
-
let t = new TextDecoder(), n = new TextEncoder(),
|
|
55628
|
-
let
|
|
55693
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false, c = new ReadableStream({ async start(d) {
|
|
55694
|
+
let l = e.body.getReader();
|
|
55629
55695
|
try {
|
|
55630
55696
|
for (; ; ) {
|
|
55631
|
-
let { done:
|
|
55632
|
-
if (
|
|
55633
|
-
let
|
|
55697
|
+
let { done: s, value: p } = await l.read();
|
|
55698
|
+
if (s) break;
|
|
55699
|
+
let k = t.decode(p, { stream: true }).split(`
|
|
55634
55700
|
`);
|
|
55635
|
-
for (let g of
|
|
55701
|
+
for (let g of k) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
|
|
55636
55702
|
let u = JSON.parse(g.slice(6));
|
|
55637
55703
|
if (u.choices?.[0]?.delta?.reasoning_content) {
|
|
55638
|
-
|
|
55704
|
+
o += u.choices[0].delta.reasoning_content;
|
|
55639
55705
|
let a = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, thinking: { content: u.choices[0].delta.reasoning_content } } }] };
|
|
55640
55706
|
delete a.choices[0].delta.reasoning_content;
|
|
55641
55707
|
let y = `data: ${JSON.stringify(a)}
|
|
55642
55708
|
|
|
55643
55709
|
`;
|
|
55644
|
-
|
|
55710
|
+
d.enqueue(n.encode(y));
|
|
55645
55711
|
continue;
|
|
55646
55712
|
}
|
|
55647
|
-
if (u.choices?.[0]?.delta?.content &&
|
|
55648
|
-
|
|
55649
|
-
let a = Date.now().toString(), y = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, content: null, thinking: { content:
|
|
55713
|
+
if (u.choices?.[0]?.delta?.content && o && !r) {
|
|
55714
|
+
r = true;
|
|
55715
|
+
let a = Date.now().toString(), y = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, content: null, thinking: { content: o, signature: a } } }] };
|
|
55650
55716
|
delete y.choices[0].delta.reasoning_content;
|
|
55651
55717
|
let h = `data: ${JSON.stringify(y)}
|
|
55652
55718
|
|
|
55653
55719
|
`;
|
|
55654
|
-
|
|
55720
|
+
d.enqueue(n.encode(h));
|
|
55655
55721
|
}
|
|
55656
55722
|
if (u.choices[0]?.delta?.reasoning_content && delete u.choices[0].delta.reasoning_content, u.choices?.[0]?.delta && Object.keys(u.choices[0].delta).length > 0) {
|
|
55657
|
-
|
|
55723
|
+
r && u.choices[0].index++;
|
|
55658
55724
|
let a = `data: ${JSON.stringify(u)}
|
|
55659
55725
|
|
|
55660
55726
|
`;
|
|
55661
|
-
|
|
55727
|
+
d.enqueue(n.encode(a));
|
|
55662
55728
|
}
|
|
55663
55729
|
} catch {
|
|
55664
|
-
|
|
55730
|
+
d.enqueue(n.encode(g + `
|
|
55665
55731
|
`));
|
|
55666
55732
|
}
|
|
55667
|
-
else
|
|
55733
|
+
else d.enqueue(n.encode(g + `
|
|
55668
55734
|
`));
|
|
55669
55735
|
}
|
|
55670
|
-
} catch (
|
|
55671
|
-
|
|
55736
|
+
} catch (s) {
|
|
55737
|
+
d.error(s);
|
|
55672
55738
|
} finally {
|
|
55673
55739
|
try {
|
|
55674
|
-
|
|
55675
|
-
} catch (
|
|
55676
|
-
console.error("Error releasing reader lock:",
|
|
55740
|
+
l.releaseLock();
|
|
55741
|
+
} catch (s) {
|
|
55742
|
+
console.error("Error releasing reader lock:", s);
|
|
55677
55743
|
}
|
|
55678
|
-
|
|
55744
|
+
d.close();
|
|
55679
55745
|
}
|
|
55680
55746
|
} });
|
|
55681
55747
|
return new Response(c, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
@@ -55683,7 +55749,7 @@ var j = class {
|
|
|
55683
55749
|
return e;
|
|
55684
55750
|
}
|
|
55685
55751
|
};
|
|
55686
|
-
var
|
|
55752
|
+
var W = class {
|
|
55687
55753
|
name = "tooluse";
|
|
55688
55754
|
transformRequestIn(e) {
|
|
55689
55755
|
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.
|
|
@@ -55696,36 +55762,36 @@ Examples:
|
|
|
55696
55762
|
if (e.headers.get("Content-Type")?.includes("application/json")) {
|
|
55697
55763
|
let t = await e.json();
|
|
55698
55764
|
if (t?.choices[0]?.message.tool_calls?.length && t?.choices[0]?.message.tool_calls[0]?.function?.name === "ExitTool") {
|
|
55699
|
-
let n = t?.choices[0]?.message.tool_calls[0],
|
|
55700
|
-
t.choices[0].message.content =
|
|
55765
|
+
let n = t?.choices[0]?.message.tool_calls[0], o = JSON.parse(n.function.arguments || "{}");
|
|
55766
|
+
t.choices[0].message.content = o.response || "", delete t.choices[0].message.tool_calls;
|
|
55701
55767
|
}
|
|
55702
55768
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55703
55769
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55704
55770
|
if (!e.body) return e;
|
|
55705
|
-
let t = new TextDecoder(), n = new TextEncoder(),
|
|
55706
|
-
let
|
|
55771
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "", c = new ReadableStream({ async start(d) {
|
|
55772
|
+
let l = e.body.getReader();
|
|
55707
55773
|
try {
|
|
55708
55774
|
for (; ; ) {
|
|
55709
|
-
let { done:
|
|
55710
|
-
if (
|
|
55711
|
-
let
|
|
55775
|
+
let { done: s, value: p } = await l.read();
|
|
55776
|
+
if (s) break;
|
|
55777
|
+
let k = t.decode(p, { stream: true }).split(`
|
|
55712
55778
|
`);
|
|
55713
|
-
for (let g of
|
|
55779
|
+
for (let g of k) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
|
|
55714
55780
|
let u = JSON.parse(g.slice(6));
|
|
55715
55781
|
if (u.choices[0]?.delta?.tool_calls?.length) {
|
|
55716
55782
|
let a = u.choices[0].delta.tool_calls[0];
|
|
55717
55783
|
if (a.function?.name === "ExitTool") {
|
|
55718
|
-
|
|
55784
|
+
o = a.index;
|
|
55719
55785
|
continue;
|
|
55720
|
-
} else if (
|
|
55721
|
-
|
|
55786
|
+
} else if (o > -1 && a.index === o && a.function.arguments) {
|
|
55787
|
+
r += a.function.arguments;
|
|
55722
55788
|
try {
|
|
55723
|
-
let y = JSON.parse(
|
|
55789
|
+
let y = JSON.parse(r);
|
|
55724
55790
|
u.choices = [{ delta: { role: "assistant", content: y.response || "" } }];
|
|
55725
55791
|
let h = `data: ${JSON.stringify(u)}
|
|
55726
55792
|
|
|
55727
55793
|
`;
|
|
55728
|
-
|
|
55794
|
+
d.enqueue(n.encode(h));
|
|
55729
55795
|
} catch {
|
|
55730
55796
|
}
|
|
55731
55797
|
continue;
|
|
@@ -55735,24 +55801,24 @@ Examples:
|
|
|
55735
55801
|
let a = `data: ${JSON.stringify(u)}
|
|
55736
55802
|
|
|
55737
55803
|
`;
|
|
55738
|
-
|
|
55804
|
+
d.enqueue(n.encode(a));
|
|
55739
55805
|
}
|
|
55740
55806
|
} catch {
|
|
55741
|
-
|
|
55807
|
+
d.enqueue(n.encode(g + `
|
|
55742
55808
|
`));
|
|
55743
55809
|
}
|
|
55744
|
-
else
|
|
55810
|
+
else d.enqueue(n.encode(g + `
|
|
55745
55811
|
`));
|
|
55746
55812
|
}
|
|
55747
|
-
} catch (
|
|
55748
|
-
|
|
55813
|
+
} catch (s) {
|
|
55814
|
+
d.error(s);
|
|
55749
55815
|
} finally {
|
|
55750
55816
|
try {
|
|
55751
|
-
|
|
55752
|
-
} catch (
|
|
55753
|
-
console.error("Error releasing reader lock:",
|
|
55817
|
+
l.releaseLock();
|
|
55818
|
+
} catch (s) {
|
|
55819
|
+
console.error("Error releasing reader lock:", s);
|
|
55754
55820
|
}
|
|
55755
|
-
|
|
55821
|
+
d.close();
|
|
55756
55822
|
}
|
|
55757
55823
|
} });
|
|
55758
55824
|
return new Response(c, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
@@ -55760,30 +55826,6 @@ Examples:
|
|
|
55760
55826
|
return e;
|
|
55761
55827
|
}
|
|
55762
55828
|
};
|
|
55763
|
-
var b = [];
|
|
55764
|
-
for (let s = 0; s < 256; ++s) b.push((s + 256).toString(16).slice(1));
|
|
55765
|
-
function fe(s, e = 0) {
|
|
55766
|
-
return (b[s[e + 0]] + b[s[e + 1]] + b[s[e + 2]] + b[s[e + 3]] + "-" + b[s[e + 4]] + b[s[e + 5]] + "-" + b[s[e + 6]] + b[s[e + 7]] + "-" + b[s[e + 8]] + b[s[e + 9]] + "-" + b[s[e + 10]] + b[s[e + 11]] + b[s[e + 12]] + b[s[e + 13]] + b[s[e + 14]] + b[s[e + 15]]).toLowerCase();
|
|
55767
|
-
}
|
|
55768
|
-
var W = new Uint8Array(256);
|
|
55769
|
-
var B = W.length;
|
|
55770
|
-
function te() {
|
|
55771
|
-
return B > W.length - 16 && ((0, import_crypto.randomFillSync)(W), B = 0), W.slice(B, B += 16);
|
|
55772
|
-
}
|
|
55773
|
-
var ne = { randomUUID: import_crypto2.randomUUID };
|
|
55774
|
-
function Re(s, e, t) {
|
|
55775
|
-
if (ne.randomUUID && !e && !s) return ne.randomUUID();
|
|
55776
|
-
s = s || {};
|
|
55777
|
-
let n = s.random ?? s.rng?.() ?? te();
|
|
55778
|
-
if (n.length < 16) throw new Error("Random bytes length must be >= 16");
|
|
55779
|
-
if (n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, e) {
|
|
55780
|
-
if (t = t || 0, t < 0 || t + 16 > e.length) throw new RangeError(`UUID byte range ${t}:${t + 15} is out of buffer bounds`);
|
|
55781
|
-
for (let r = 0; r < 16; ++r) e[t + r] = n[r];
|
|
55782
|
-
return e;
|
|
55783
|
-
}
|
|
55784
|
-
return fe(n);
|
|
55785
|
-
}
|
|
55786
|
-
var I = Re;
|
|
55787
55829
|
var z = class {
|
|
55788
55830
|
name = "openrouter";
|
|
55789
55831
|
async transformRequestIn(e) {
|
|
@@ -55799,8 +55841,8 @@ var z = class {
|
|
|
55799
55841
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55800
55842
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55801
55843
|
if (!e.body) return e;
|
|
55802
|
-
let t = new TextDecoder(), n = new TextEncoder(),
|
|
55803
|
-
let _ = e.body.getReader(),
|
|
55844
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", c = false, d = false, l = "", s = new ReadableStream({ async start(p) {
|
|
55845
|
+
let _ = e.body.getReader(), k = (u, a, y) => {
|
|
55804
55846
|
let h = u.split(`
|
|
55805
55847
|
`);
|
|
55806
55848
|
for (let f of h) f.trim() && a.enqueue(y.encode(f + `
|
|
@@ -55811,34 +55853,34 @@ var z = class {
|
|
|
55811
55853
|
let f = u.slice(6);
|
|
55812
55854
|
try {
|
|
55813
55855
|
let m = JSON.parse(f);
|
|
55814
|
-
if (m.usage && (v("usage", m.usage,
|
|
55856
|
+
if (m.usage && (v("usage", m.usage, d), m.choices[0].finish_reason = d ? "tool_calls" : "stop"), m.choices?.[0]?.finish_reason === "error" && y.enqueue(h.encode(`data: ${JSON.stringify({ error: m.choices?.[0].error })}
|
|
55815
55857
|
|
|
55816
55858
|
`)), m.choices?.[0]?.delta?.content && !a.hasTextContent() && a.setHasTextContent(true), m.choices?.[0]?.delta?.reasoning) {
|
|
55817
55859
|
a.appendReasoningContent(m.choices[0].delta.reasoning);
|
|
55818
55860
|
let x = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, thinking: { content: m.choices[0].delta.reasoning } } }] };
|
|
55819
55861
|
x.choices?.[0]?.delta && delete x.choices[0].delta.reasoning;
|
|
55820
|
-
let
|
|
55862
|
+
let b = `data: ${JSON.stringify(x)}
|
|
55821
55863
|
|
|
55822
55864
|
`;
|
|
55823
|
-
y.enqueue(h.encode(
|
|
55865
|
+
y.enqueue(h.encode(b));
|
|
55824
55866
|
return;
|
|
55825
55867
|
}
|
|
55826
55868
|
if (m.choices?.[0]?.delta?.content && a.reasoningContent() && !a.isReasoningComplete()) {
|
|
55827
55869
|
a.setReasoningComplete(true);
|
|
55828
|
-
let x = Date.now().toString(),
|
|
55829
|
-
|
|
55830
|
-
let X = `data: ${JSON.stringify(
|
|
55870
|
+
let x = Date.now().toString(), b = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, content: null, thinking: { content: a.reasoningContent(), signature: x } } }] };
|
|
55871
|
+
b.choices?.[0]?.delta && delete b.choices[0].delta.reasoning;
|
|
55872
|
+
let X = `data: ${JSON.stringify(b)}
|
|
55831
55873
|
|
|
55832
55874
|
`;
|
|
55833
55875
|
y.enqueue(h.encode(X));
|
|
55834
55876
|
}
|
|
55835
55877
|
m.choices?.[0]?.delta?.reasoning && delete m.choices[0].delta.reasoning, m.choices?.[0]?.delta?.tool_calls?.length && !Number.isNaN(parseInt(m.choices?.[0]?.delta?.tool_calls[0].id, 10)) && m.choices?.[0]?.delta?.tool_calls.forEach((x) => {
|
|
55836
|
-
x.id = `call_${
|
|
55837
|
-
}), m.choices?.[0]?.delta?.tool_calls?.length && !
|
|
55838
|
-
let
|
|
55878
|
+
x.id = `call_${H()}`;
|
|
55879
|
+
}), m.choices?.[0]?.delta?.tool_calls?.length && !d && (v("hasToolCall", true), d = true), m.choices?.[0]?.delta?.tool_calls?.length && a.hasTextContent() && (typeof m.choices[0].index == "number" ? m.choices[0].index += 1 : m.choices[0].index = 1);
|
|
55880
|
+
let S = `data: ${JSON.stringify(m)}
|
|
55839
55881
|
|
|
55840
55882
|
`;
|
|
55841
|
-
y.enqueue(h.encode(
|
|
55883
|
+
y.enqueue(h.encode(S));
|
|
55842
55884
|
} catch {
|
|
55843
55885
|
y.enqueue(h.encode(u + `
|
|
55844
55886
|
`));
|
|
@@ -55850,7 +55892,7 @@ var z = class {
|
|
|
55850
55892
|
for (; ; ) {
|
|
55851
55893
|
let { done: u, value: a } = await _.read();
|
|
55852
55894
|
if (u) {
|
|
55853
|
-
|
|
55895
|
+
l.trim() && k(l, p, n);
|
|
55854
55896
|
break;
|
|
55855
55897
|
}
|
|
55856
55898
|
if (!a || a.length === 0) continue;
|
|
@@ -55862,24 +55904,24 @@ var z = class {
|
|
|
55862
55904
|
continue;
|
|
55863
55905
|
}
|
|
55864
55906
|
if (y.length === 0) continue;
|
|
55865
|
-
if (
|
|
55907
|
+
if (l += y, l.length > 1e6) {
|
|
55866
55908
|
console.warn("Buffer size exceeds limit, processing partial data");
|
|
55867
|
-
let f =
|
|
55909
|
+
let f = l.split(`
|
|
55868
55910
|
`);
|
|
55869
|
-
|
|
55911
|
+
l = f.pop() || "";
|
|
55870
55912
|
for (let m of f) if (m.trim()) try {
|
|
55871
|
-
g(m, { controller: p, encoder: n, hasTextContent: () =>
|
|
55872
|
-
} catch (
|
|
55873
|
-
console.error("Error processing line:", m,
|
|
55913
|
+
g(m, { controller: p, encoder: n, hasTextContent: () => o, setHasTextContent: (S) => o = S, reasoningContent: () => r, appendReasoningContent: (S) => r += S, isReasoningComplete: () => c, setReasoningComplete: (S) => c = S });
|
|
55914
|
+
} catch (S) {
|
|
55915
|
+
console.error("Error processing line:", m, S), p.enqueue(n.encode(m + `
|
|
55874
55916
|
`));
|
|
55875
55917
|
}
|
|
55876
55918
|
continue;
|
|
55877
55919
|
}
|
|
55878
|
-
let h =
|
|
55920
|
+
let h = l.split(`
|
|
55879
55921
|
`);
|
|
55880
|
-
|
|
55922
|
+
l = h.pop() || "";
|
|
55881
55923
|
for (let f of h) if (f.trim()) try {
|
|
55882
|
-
g(f, { controller: p, encoder: n, hasTextContent: () =>
|
|
55924
|
+
g(f, { controller: p, encoder: n, hasTextContent: () => o, setHasTextContent: (m) => o = m, reasoningContent: () => r, appendReasoningContent: (m) => r += m, isReasoningComplete: () => c, setReasoningComplete: (m) => c = m });
|
|
55883
55925
|
} catch (m) {
|
|
55884
55926
|
console.error("Error processing line:", f, m), p.enqueue(n.encode(f + `
|
|
55885
55927
|
`));
|
|
@@ -55896,7 +55938,7 @@ var z = class {
|
|
|
55896
55938
|
p.close();
|
|
55897
55939
|
}
|
|
55898
55940
|
} });
|
|
55899
|
-
return new Response(
|
|
55941
|
+
return new Response(s, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
55900
55942
|
}
|
|
55901
55943
|
return e;
|
|
55902
55944
|
}
|
|
@@ -55929,21 +55971,21 @@ var G = class {
|
|
|
55929
55971
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55930
55972
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55931
55973
|
if (!e.body) return e;
|
|
55932
|
-
let t = new TextDecoder(), n = new TextEncoder(),
|
|
55974
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", c = false, d = "", l = new ReadableStream({ async start(s) {
|
|
55933
55975
|
let p = e.body.getReader(), _ = (g, u, a) => {
|
|
55934
55976
|
let y = g.split(`
|
|
55935
55977
|
`);
|
|
55936
55978
|
for (let h of y) h.trim() && u.enqueue(a.encode(h + `
|
|
55937
55979
|
`));
|
|
55938
|
-
},
|
|
55980
|
+
}, k = (g, u) => {
|
|
55939
55981
|
let { controller: a, encoder: y } = u;
|
|
55940
55982
|
if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") {
|
|
55941
55983
|
let h = g.slice(6);
|
|
55942
55984
|
try {
|
|
55943
55985
|
let f = JSON.parse(h);
|
|
55944
55986
|
if (f.error) throw new Error(JSON.stringify(f));
|
|
55945
|
-
f.choices?.[0]?.delta?.content && !u.hasTextContent() && u.setHasTextContent(true), f.choices?.[0]?.delta?.tool_calls?.length && f.choices?.[0]?.delta?.tool_calls.forEach((
|
|
55946
|
-
|
|
55987
|
+
f.choices?.[0]?.delta?.content && !u.hasTextContent() && u.setHasTextContent(true), f.choices?.[0]?.delta?.tool_calls?.length && f.choices?.[0]?.delta?.tool_calls.forEach((S) => {
|
|
55988
|
+
S.id = `call_${H()}`;
|
|
55947
55989
|
}), f.choices?.[0]?.delta?.tool_calls?.length && u.hasTextContent() && (typeof f.choices[0].index == "number" ? f.choices[0].index += 1 : f.choices[0].index = 1);
|
|
55948
55990
|
let m = `data: ${JSON.stringify(f)}
|
|
55949
55991
|
|
|
@@ -55960,7 +56002,7 @@ var G = class {
|
|
|
55960
56002
|
for (; ; ) {
|
|
55961
56003
|
let { done: g, value: u } = await p.read();
|
|
55962
56004
|
if (g) {
|
|
55963
|
-
|
|
56005
|
+
d.trim() && _(d, s, n);
|
|
55964
56006
|
break;
|
|
55965
56007
|
}
|
|
55966
56008
|
if (!u || u.length === 0) continue;
|
|
@@ -55972,41 +56014,41 @@ var G = class {
|
|
|
55972
56014
|
continue;
|
|
55973
56015
|
}
|
|
55974
56016
|
if (a.length === 0) continue;
|
|
55975
|
-
if (
|
|
56017
|
+
if (d += a, d.length > 1e6) {
|
|
55976
56018
|
console.warn("Buffer size exceeds limit, processing partial data");
|
|
55977
|
-
let h =
|
|
56019
|
+
let h = d.split(`
|
|
55978
56020
|
`);
|
|
55979
|
-
|
|
56021
|
+
d = h.pop() || "";
|
|
55980
56022
|
for (let f of h) if (f.trim()) try {
|
|
55981
|
-
|
|
56023
|
+
k(f, { controller: s, encoder: n, hasTextContent: () => o, setHasTextContent: (m) => o = m, reasoningContent: () => r, appendReasoningContent: (m) => r += m, isReasoningComplete: () => c, setReasoningComplete: (m) => c = m });
|
|
55982
56024
|
} catch (m) {
|
|
55983
|
-
console.error("Error processing line:", f, m),
|
|
56025
|
+
console.error("Error processing line:", f, m), s.enqueue(n.encode(f + `
|
|
55984
56026
|
`));
|
|
55985
56027
|
}
|
|
55986
56028
|
continue;
|
|
55987
56029
|
}
|
|
55988
|
-
let y =
|
|
56030
|
+
let y = d.split(`
|
|
55989
56031
|
`);
|
|
55990
|
-
|
|
56032
|
+
d = y.pop() || "";
|
|
55991
56033
|
for (let h of y) if (h.trim()) try {
|
|
55992
|
-
|
|
56034
|
+
k(h, { controller: s, encoder: n, hasTextContent: () => o, setHasTextContent: (f) => o = f, reasoningContent: () => r, appendReasoningContent: (f) => r += f, isReasoningComplete: () => c, setReasoningComplete: (f) => c = f });
|
|
55993
56035
|
} catch (f) {
|
|
55994
|
-
console.error("Error processing line:", h, f),
|
|
56036
|
+
console.error("Error processing line:", h, f), s.enqueue(n.encode(h + `
|
|
55995
56037
|
`));
|
|
55996
56038
|
}
|
|
55997
56039
|
}
|
|
55998
56040
|
} catch (g) {
|
|
55999
|
-
console.error("Stream error:", g),
|
|
56041
|
+
console.error("Stream error:", g), s.error(g);
|
|
56000
56042
|
} finally {
|
|
56001
56043
|
try {
|
|
56002
56044
|
p.releaseLock();
|
|
56003
56045
|
} catch (g) {
|
|
56004
56046
|
console.error("Error releasing reader lock:", g);
|
|
56005
56047
|
}
|
|
56006
|
-
|
|
56048
|
+
s.close();
|
|
56007
56049
|
}
|
|
56008
56050
|
} });
|
|
56009
|
-
return new Response(
|
|
56051
|
+
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" } });
|
|
56010
56052
|
}
|
|
56011
56053
|
return e;
|
|
56012
56054
|
}
|
|
@@ -56021,7 +56063,7 @@ var K = class {
|
|
|
56021
56063
|
}), e;
|
|
56022
56064
|
}
|
|
56023
56065
|
};
|
|
56024
|
-
var pe = { AnthropicTransformer:
|
|
56066
|
+
var pe = { AnthropicTransformer: j, GeminiTransformer: D, DeepseekTransformer: B, TooluseTransformer: W, OpenrouterTransformer: z, MaxTokenTransformer: V, GroqTransformer: G, CleancacheTransformer: K };
|
|
56025
56067
|
var Y = class {
|
|
56026
56068
|
constructor(e) {
|
|
56027
56069
|
this.configService = e;
|
|
@@ -56057,14 +56099,14 @@ var Y = class {
|
|
|
56057
56099
|
async registerTransformerFromConfig(e) {
|
|
56058
56100
|
try {
|
|
56059
56101
|
let t = import_node_module.default._load;
|
|
56060
|
-
if (import_node_module.default._load = function(n,
|
|
56102
|
+
if (import_node_module.default._load = function(n, o, r) {
|
|
56061
56103
|
return n === "claude-code-router" ? { log: v } : t.apply(import_node_module.default, arguments);
|
|
56062
56104
|
}, e.path) {
|
|
56063
56105
|
let n = Z(Z.resolve(e.path));
|
|
56064
56106
|
if (n) {
|
|
56065
|
-
let
|
|
56066
|
-
if (!
|
|
56067
|
-
return this.registerTransformer(
|
|
56107
|
+
let o = new n(e.options);
|
|
56108
|
+
if (!o.name) throw new Error(`Transformer instance from ${e.path} does not have a name property.`);
|
|
56109
|
+
return this.registerTransformer(o.name, o), true;
|
|
56068
56110
|
}
|
|
56069
56111
|
}
|
|
56070
56112
|
return false;
|
|
@@ -56097,9 +56139,9 @@ var Y = class {
|
|
|
56097
56139
|
for (let t of e) await this.registerTransformerFromConfig(t);
|
|
56098
56140
|
}
|
|
56099
56141
|
};
|
|
56100
|
-
function
|
|
56101
|
-
let
|
|
56102
|
-
return
|
|
56142
|
+
function Pe() {
|
|
56143
|
+
let i = (0, import_fastify.default)({ bodyLimit: 52428800 });
|
|
56144
|
+
return i.setErrorHandler(le), i.register(import_cors.default), i;
|
|
56103
56145
|
}
|
|
56104
56146
|
var re = class {
|
|
56105
56147
|
app;
|
|
@@ -56108,9 +56150,9 @@ var re = class {
|
|
|
56108
56150
|
providerService;
|
|
56109
56151
|
transformerService;
|
|
56110
56152
|
constructor(e = {}) {
|
|
56111
|
-
this.configService = new
|
|
56112
|
-
this.providerService = new
|
|
56113
|
-
}), this.app =
|
|
56153
|
+
this.configService = new I(e), this.transformerService = new Y(this.configService), this.transformerService.initialize().finally(() => {
|
|
56154
|
+
this.providerService = new q(this.configService, this.transformerService), this.llmService = new F(this.providerService);
|
|
56155
|
+
}), this.app = Pe();
|
|
56114
56156
|
}
|
|
56115
56157
|
async register(e, t) {
|
|
56116
56158
|
await this.app.register(e, t);
|
|
@@ -56120,15 +56162,15 @@ var re = class {
|
|
|
56120
56162
|
}
|
|
56121
56163
|
async start() {
|
|
56122
56164
|
try {
|
|
56123
|
-
this.app._server = this, this.app.addHook("preHandler", async (n,
|
|
56165
|
+
this.app._server = this, this.app.addHook("preHandler", async (n, o) => {
|
|
56124
56166
|
try {
|
|
56125
|
-
let
|
|
56126
|
-
if (!
|
|
56127
|
-
let [c,
|
|
56128
|
-
|
|
56167
|
+
let r = n.body;
|
|
56168
|
+
if (!r || !r.model) return o.code(400).send({ error: "Missing model in request body" });
|
|
56169
|
+
let [c, d] = r.model.split(",");
|
|
56170
|
+
r.model = d, n.provider = c;
|
|
56129
56171
|
return;
|
|
56130
|
-
} catch (
|
|
56131
|
-
return n.log.error("Error in modelProviderMiddleware:",
|
|
56172
|
+
} catch (r) {
|
|
56173
|
+
return n.log.error("Error in modelProviderMiddleware:", r), o.code(500).send({ error: "Internal server error" });
|
|
56132
56174
|
}
|
|
56133
56175
|
}), this.app.register(ue);
|
|
56134
56176
|
let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
|
|
@@ -56142,11 +56184,11 @@ var re = class {
|
|
|
56142
56184
|
}
|
|
56143
56185
|
}
|
|
56144
56186
|
};
|
|
56145
|
-
var
|
|
56187
|
+
var ln = re;
|
|
56146
56188
|
|
|
56147
56189
|
// src/server.ts
|
|
56148
56190
|
var createServer = (config) => {
|
|
56149
|
-
const server = new
|
|
56191
|
+
const server = new ln(config);
|
|
56150
56192
|
return server;
|
|
56151
56193
|
};
|
|
56152
56194
|
|
|
@@ -56175,6 +56217,55 @@ function log(...args) {
|
|
|
56175
56217
|
|
|
56176
56218
|
// src/utils/router.ts
|
|
56177
56219
|
var enc = (0, import_tiktoken.get_encoding)("cl100k_base");
|
|
56220
|
+
var calculateTokenCount = (messages, system, tools) => {
|
|
56221
|
+
let tokenCount = 0;
|
|
56222
|
+
if (Array.isArray(messages)) {
|
|
56223
|
+
messages.forEach((message) => {
|
|
56224
|
+
if (typeof message.content === "string") {
|
|
56225
|
+
tokenCount += enc.encode(message.content).length;
|
|
56226
|
+
} else if (Array.isArray(message.content)) {
|
|
56227
|
+
message.content.forEach((contentPart) => {
|
|
56228
|
+
if (contentPart.type === "text") {
|
|
56229
|
+
tokenCount += enc.encode(contentPart.text).length;
|
|
56230
|
+
} else if (contentPart.type === "tool_use") {
|
|
56231
|
+
tokenCount += enc.encode(
|
|
56232
|
+
JSON.stringify(contentPart.input)
|
|
56233
|
+
).length;
|
|
56234
|
+
} else if (contentPart.type === "tool_result") {
|
|
56235
|
+
tokenCount += enc.encode(
|
|
56236
|
+
typeof contentPart.content === "string" ? contentPart.content : JSON.stringify(contentPart.content)
|
|
56237
|
+
).length;
|
|
56238
|
+
}
|
|
56239
|
+
});
|
|
56240
|
+
}
|
|
56241
|
+
});
|
|
56242
|
+
}
|
|
56243
|
+
if (typeof system === "string") {
|
|
56244
|
+
tokenCount += enc.encode(system).length;
|
|
56245
|
+
} else if (Array.isArray(system)) {
|
|
56246
|
+
system.forEach((item) => {
|
|
56247
|
+
if (item.type !== "text") return;
|
|
56248
|
+
if (typeof item.text === "string") {
|
|
56249
|
+
tokenCount += enc.encode(item.text).length;
|
|
56250
|
+
} else if (Array.isArray(item.text)) {
|
|
56251
|
+
item.text.forEach((textPart) => {
|
|
56252
|
+
tokenCount += enc.encode(textPart || "").length;
|
|
56253
|
+
});
|
|
56254
|
+
}
|
|
56255
|
+
});
|
|
56256
|
+
}
|
|
56257
|
+
if (tools) {
|
|
56258
|
+
tools.forEach((tool) => {
|
|
56259
|
+
if (tool.description) {
|
|
56260
|
+
tokenCount += enc.encode(tool.name + tool.description).length;
|
|
56261
|
+
}
|
|
56262
|
+
if (tool.input_schema) {
|
|
56263
|
+
tokenCount += enc.encode(JSON.stringify(tool.input_schema)).length;
|
|
56264
|
+
}
|
|
56265
|
+
});
|
|
56266
|
+
}
|
|
56267
|
+
return tokenCount;
|
|
56268
|
+
};
|
|
56178
56269
|
var getUseModel = (req, tokenCount, config) => {
|
|
56179
56270
|
if (req.body.model.includes(",")) {
|
|
56180
56271
|
return req.body.model;
|
|
@@ -56191,58 +56282,31 @@ var getUseModel = (req, tokenCount, config) => {
|
|
|
56191
56282
|
log("Using think model for ", req.body.thinking);
|
|
56192
56283
|
return config.Router.think;
|
|
56193
56284
|
}
|
|
56285
|
+
if (Array.isArray(req.body.tools) && req.body.tools.some((tool) => tool.type?.startsWith("web_search")) && config.Router.webSearch) {
|
|
56286
|
+
return config.Router.webSearch;
|
|
56287
|
+
}
|
|
56194
56288
|
return config.Router.default;
|
|
56195
56289
|
};
|
|
56196
|
-
var router = async (req,
|
|
56290
|
+
var router = async (req, _res, config) => {
|
|
56197
56291
|
const { messages, system = [], tools } = req.body;
|
|
56198
56292
|
try {
|
|
56199
|
-
|
|
56200
|
-
|
|
56201
|
-
|
|
56202
|
-
|
|
56203
|
-
|
|
56204
|
-
|
|
56205
|
-
|
|
56206
|
-
|
|
56207
|
-
|
|
56208
|
-
|
|
56209
|
-
|
|
56210
|
-
|
|
56211
|
-
|
|
56212
|
-
} else if (contentPart.type === "tool_result") {
|
|
56213
|
-
tokenCount += enc.encode(
|
|
56214
|
-
typeof contentPart.content === "string" ? contentPart.content : JSON.stringify(contentPart.content)
|
|
56215
|
-
).length;
|
|
56216
|
-
}
|
|
56217
|
-
});
|
|
56218
|
-
}
|
|
56219
|
-
});
|
|
56220
|
-
}
|
|
56221
|
-
if (typeof system === "string") {
|
|
56222
|
-
tokenCount += enc.encode(system).length;
|
|
56223
|
-
} else if (Array.isArray(system)) {
|
|
56224
|
-
system.forEach((item) => {
|
|
56225
|
-
if (item.type !== "text") return;
|
|
56226
|
-
if (typeof item.text === "string") {
|
|
56227
|
-
tokenCount += enc.encode(item.text).length;
|
|
56228
|
-
} else if (Array.isArray(item.text)) {
|
|
56229
|
-
item.text.forEach((textPart) => {
|
|
56230
|
-
tokenCount += enc.encode(textPart || "").length;
|
|
56231
|
-
});
|
|
56232
|
-
}
|
|
56233
|
-
});
|
|
56293
|
+
const tokenCount = calculateTokenCount(
|
|
56294
|
+
messages,
|
|
56295
|
+
system,
|
|
56296
|
+
tools
|
|
56297
|
+
);
|
|
56298
|
+
let model;
|
|
56299
|
+
if (config.CUSTOM_ROUTER_PATH) {
|
|
56300
|
+
try {
|
|
56301
|
+
const customRouter = require(config.CUSTOM_ROUTER_PATH);
|
|
56302
|
+
model = await customRouter(req, config);
|
|
56303
|
+
} catch (e) {
|
|
56304
|
+
log("failed to load custom router", e.message);
|
|
56305
|
+
}
|
|
56234
56306
|
}
|
|
56235
|
-
if (
|
|
56236
|
-
|
|
56237
|
-
if (tool.description) {
|
|
56238
|
-
tokenCount += enc.encode(tool.name + tool.description).length;
|
|
56239
|
-
}
|
|
56240
|
-
if (tool.input_schema) {
|
|
56241
|
-
tokenCount += enc.encode(JSON.stringify(tool.input_schema)).length;
|
|
56242
|
-
}
|
|
56243
|
-
});
|
|
56307
|
+
if (!model) {
|
|
56308
|
+
model = getUseModel(req, tokenCount, config);
|
|
56244
56309
|
}
|
|
56245
|
-
const model = getUseModel(req, tokenCount, config);
|
|
56246
56310
|
req.body.model = model;
|
|
56247
56311
|
} catch (error) {
|
|
56248
56312
|
log("Error in router middleware:", error.message);
|
|
@@ -56508,7 +56572,7 @@ async function executeCodeCommand(args = []) {
|
|
|
56508
56572
|
}
|
|
56509
56573
|
|
|
56510
56574
|
// package.json
|
|
56511
|
-
var version = "1.0.
|
|
56575
|
+
var version = "1.0.23";
|
|
56512
56576
|
|
|
56513
56577
|
// src/cli.ts
|
|
56514
56578
|
var import_child_process2 = require("child_process");
|