@musistudio/claude-code-router 1.0.21 → 1.0.22
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 +6 -0
- package/README_zh.md +6 -0
- package/dist/cli.js +423 -419
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -9138,7 +9138,7 @@ var require_reply = __commonJS({
|
|
|
9138
9138
|
handled--;
|
|
9139
9139
|
const result = reply[kReplyTrailers][trailerName](reply, payload, cb);
|
|
9140
9140
|
if (typeof result === "object" && typeof result.then === "function") {
|
|
9141
|
-
result.then((
|
|
9141
|
+
result.then((v2) => cb(null, v2), cb);
|
|
9142
9142
|
}
|
|
9143
9143
|
}
|
|
9144
9144
|
if (skipped) res.end(null, null, null);
|
|
@@ -15991,17 +15991,17 @@ var require_core = __commonJS({
|
|
|
15991
15991
|
return this.opts.defaultMeta = typeof meta == "object" ? meta[schemaId] || meta : void 0;
|
|
15992
15992
|
}
|
|
15993
15993
|
validate(schemaKeyRef, data) {
|
|
15994
|
-
let
|
|
15994
|
+
let v2;
|
|
15995
15995
|
if (typeof schemaKeyRef == "string") {
|
|
15996
|
-
|
|
15997
|
-
if (!
|
|
15996
|
+
v2 = this.getSchema(schemaKeyRef);
|
|
15997
|
+
if (!v2)
|
|
15998
15998
|
throw new Error(`no schema with key or ref "${schemaKeyRef}"`);
|
|
15999
15999
|
} else {
|
|
16000
|
-
|
|
16000
|
+
v2 = this.compile(schemaKeyRef);
|
|
16001
16001
|
}
|
|
16002
|
-
const valid =
|
|
16003
|
-
if (!("$async" in
|
|
16004
|
-
this.errors =
|
|
16002
|
+
const valid = v2(data);
|
|
16003
|
+
if (!("$async" in v2))
|
|
16004
|
+
this.errors = v2.errors;
|
|
16005
16005
|
return valid;
|
|
16006
16006
|
}
|
|
16007
16007
|
compile(schema, _meta) {
|
|
@@ -16495,8 +16495,8 @@ var require_ref = __commonJS({
|
|
|
16495
16495
|
return callRef(cxt, (0, codegen_1._)`${rootName}.validate`, root, root.$async);
|
|
16496
16496
|
}
|
|
16497
16497
|
function callValidate(sch) {
|
|
16498
|
-
const
|
|
16499
|
-
callRef(cxt,
|
|
16498
|
+
const v2 = getValidate(cxt, sch);
|
|
16499
|
+
callRef(cxt, v2, sch, sch.$async);
|
|
16500
16500
|
}
|
|
16501
16501
|
function inlineRefSchema(sch) {
|
|
16502
16502
|
const schName = gen.scopeValue("schema", opts.code.source === true ? { ref: sch, code: (0, codegen_1.stringify)(sch) } : { ref: sch });
|
|
@@ -16518,7 +16518,7 @@ var require_ref = __commonJS({
|
|
|
16518
16518
|
return sch.validate ? gen.scopeValue("validate", { ref: sch.validate }) : (0, codegen_1._)`${gen.scopeValue("wrapper", { ref: sch })}.validate`;
|
|
16519
16519
|
}
|
|
16520
16520
|
exports2.getValidate = getValidate;
|
|
16521
|
-
function callRef(cxt,
|
|
16521
|
+
function callRef(cxt, v2, sch, $async) {
|
|
16522
16522
|
const { gen, it } = cxt;
|
|
16523
16523
|
const { allErrors, schemaEnv: env, opts } = it;
|
|
16524
16524
|
const passCxt = opts.passContext ? names_1.default.this : codegen_1.nil;
|
|
@@ -16531,8 +16531,8 @@ var require_ref = __commonJS({
|
|
|
16531
16531
|
throw new Error("async schema referenced by sync schema");
|
|
16532
16532
|
const valid = gen.let("valid");
|
|
16533
16533
|
gen.try(() => {
|
|
16534
|
-
gen.code((0, codegen_1._)`await ${(0, code_1.callValidateCode)(cxt,
|
|
16535
|
-
addEvaluatedFrom(
|
|
16534
|
+
gen.code((0, codegen_1._)`await ${(0, code_1.callValidateCode)(cxt, v2, passCxt)}`);
|
|
16535
|
+
addEvaluatedFrom(v2);
|
|
16536
16536
|
if (!allErrors)
|
|
16537
16537
|
gen.assign(valid, true);
|
|
16538
16538
|
}, (e) => {
|
|
@@ -16544,7 +16544,7 @@ var require_ref = __commonJS({
|
|
|
16544
16544
|
cxt.ok(valid);
|
|
16545
16545
|
}
|
|
16546
16546
|
function callSyncRef() {
|
|
16547
|
-
cxt.result((0, code_1.callValidateCode)(cxt,
|
|
16547
|
+
cxt.result((0, code_1.callValidateCode)(cxt, v2, passCxt), () => addEvaluatedFrom(v2), () => addErrorsFrom(v2));
|
|
16548
16548
|
}
|
|
16549
16549
|
function addErrorsFrom(source) {
|
|
16550
16550
|
const errs = (0, codegen_1._)`${source}.errors`;
|
|
@@ -17034,7 +17034,7 @@ var require_enum = __commonJS({
|
|
|
17034
17034
|
cxt.pass(valid);
|
|
17035
17035
|
function loopEnum() {
|
|
17036
17036
|
gen.assign(valid, false);
|
|
17037
|
-
gen.forOf("v", schemaCode, (
|
|
17037
|
+
gen.forOf("v", schemaCode, (v2) => gen.if((0, codegen_1._)`${getEql()}(${data}, ${v2})`, () => gen.assign(valid, true).break()));
|
|
17038
17038
|
}
|
|
17039
17039
|
function equalCode(vSchema, i) {
|
|
17040
17040
|
const sch = schema[i];
|
|
@@ -18420,7 +18420,7 @@ var require_ajv = __commonJS({
|
|
|
18420
18420
|
var Ajv = class extends core_1.default {
|
|
18421
18421
|
_addVocabularies() {
|
|
18422
18422
|
super._addVocabularies();
|
|
18423
|
-
draft7_1.default.forEach((
|
|
18423
|
+
draft7_1.default.forEach((v2) => this.addVocabulary(v2));
|
|
18424
18424
|
if (this.opts.discriminator)
|
|
18425
18425
|
this.addKeyword(discriminator_1.default);
|
|
18426
18426
|
}
|
|
@@ -21449,9 +21449,9 @@ var require_ref2 = __commonJS({
|
|
|
21449
21449
|
}
|
|
21450
21450
|
function callValidate(schema) {
|
|
21451
21451
|
const sch = compile_1.compileSchema.call(it.self, new compile_1.SchemaEnv({ schema, root, schemaPath: `/definitions/${ref}` }));
|
|
21452
|
-
const
|
|
21452
|
+
const v2 = (0, ref_1.getValidate)(cxt, sch);
|
|
21453
21453
|
const errsCount = gen.const("_errs", names_1.default.errors);
|
|
21454
|
-
(0, ref_1.callRef)(cxt,
|
|
21454
|
+
(0, ref_1.callRef)(cxt, v2, sch, sch.$async);
|
|
21455
21455
|
gen.assign(valid, (0, codegen_1._)`${errsCount} === ${names_1.default.errors}`);
|
|
21456
21456
|
}
|
|
21457
21457
|
function inlineRefSchema(schema) {
|
|
@@ -21681,7 +21681,7 @@ var require_enum2 = __commonJS({
|
|
|
21681
21681
|
}
|
|
21682
21682
|
cxt.pass(valid);
|
|
21683
21683
|
function loopEnum() {
|
|
21684
|
-
gen.forOf("v", schemaValue, (
|
|
21684
|
+
gen.forOf("v", schemaValue, (v2) => gen.if((0, codegen_1._)`${valid} = ${data} === ${v2}`, () => gen.break()));
|
|
21685
21685
|
}
|
|
21686
21686
|
}
|
|
21687
21687
|
};
|
|
@@ -23173,10 +23173,10 @@ var require_standalone3 = __commonJS({
|
|
|
23173
23173
|
const { _n } = ajv.scope.opts;
|
|
23174
23174
|
return typeof refsOrFunc == "function" ? funcExportCode(refsOrFunc.source) : refsOrFunc !== void 0 ? multiExportsCode(refsOrFunc, getValidate) : multiExportsCode(ajv.schemas, (sch) => sch.meta ? void 0 : ajv.compile(sch.schema));
|
|
23175
23175
|
function getValidate(id2) {
|
|
23176
|
-
const
|
|
23177
|
-
if (!
|
|
23176
|
+
const v2 = ajv.getSchema(id2);
|
|
23177
|
+
if (!v2)
|
|
23178
23178
|
throw new Error(`moduleCode: no schema with id ${id2}`);
|
|
23179
|
-
return
|
|
23179
|
+
return v2;
|
|
23180
23180
|
}
|
|
23181
23181
|
function funcExportCode(source) {
|
|
23182
23182
|
const usedValues = {};
|
|
@@ -23192,11 +23192,11 @@ var require_standalone3 = __commonJS({
|
|
|
23192
23192
|
const usedValues = {};
|
|
23193
23193
|
let code = (0, code_1._)`"use strict";`;
|
|
23194
23194
|
for (const name in schemas) {
|
|
23195
|
-
const
|
|
23196
|
-
if (
|
|
23197
|
-
const vCode = validateCode(usedValues,
|
|
23195
|
+
const v2 = getValidateFunc(schemas[name]);
|
|
23196
|
+
if (v2) {
|
|
23197
|
+
const vCode = validateCode(usedValues, v2.source);
|
|
23198
23198
|
const exportSyntax = ajv.opts.code.esm ? (0, code_1._)`export const ${(0, code_1.getEsmExportName)(name)}` : (0, code_1._)`exports${(0, code_1.getProperty)(name)}`;
|
|
23199
|
-
code = (0, code_1._)`${code}${_n}${exportSyntax} = ${(_a =
|
|
23199
|
+
code = (0, code_1._)`${code}${_n}${exportSyntax} = ${(_a = v2.source) === null || _a === void 0 ? void 0 : _a.validateName};${_n}${vCode}`;
|
|
23200
23200
|
}
|
|
23201
23201
|
}
|
|
23202
23202
|
return `${code}`;
|
|
@@ -23214,8 +23214,8 @@ var require_standalone3 = __commonJS({
|
|
|
23214
23214
|
var _a;
|
|
23215
23215
|
const vRef = (_a = n.value) === null || _a === void 0 ? void 0 : _a.ref;
|
|
23216
23216
|
if (n.prefix === "validate" && typeof vRef == "function") {
|
|
23217
|
-
const
|
|
23218
|
-
return validateCode(usedValues,
|
|
23217
|
+
const v2 = vRef;
|
|
23218
|
+
return validateCode(usedValues, v2.source);
|
|
23219
23219
|
} else if ((n.prefix === "root" || n.prefix === "wrapper") && typeof vRef == "object") {
|
|
23220
23220
|
const { validate, validateName } = vRef;
|
|
23221
23221
|
if (!validateName)
|
|
@@ -23911,8 +23911,8 @@ var require_valid = __commonJS({
|
|
|
23911
23911
|
"use strict";
|
|
23912
23912
|
var parse = require_parse3();
|
|
23913
23913
|
var valid = (version2, options) => {
|
|
23914
|
-
const
|
|
23915
|
-
return
|
|
23914
|
+
const v2 = parse(version2, options);
|
|
23915
|
+
return v2 ? v2.version : null;
|
|
23916
23916
|
};
|
|
23917
23917
|
module2.exports = valid;
|
|
23918
23918
|
}
|
|
@@ -24831,10 +24831,10 @@ var require_max_satisfying = __commonJS({
|
|
|
24831
24831
|
} catch (er) {
|
|
24832
24832
|
return null;
|
|
24833
24833
|
}
|
|
24834
|
-
versions.forEach((
|
|
24835
|
-
if (rangeObj.test(
|
|
24836
|
-
if (!max || maxSV.compare(
|
|
24837
|
-
max =
|
|
24834
|
+
versions.forEach((v2) => {
|
|
24835
|
+
if (rangeObj.test(v2)) {
|
|
24836
|
+
if (!max || maxSV.compare(v2) === -1) {
|
|
24837
|
+
max = v2;
|
|
24838
24838
|
maxSV = new SemVer(max, options);
|
|
24839
24839
|
}
|
|
24840
24840
|
}
|
|
@@ -24860,10 +24860,10 @@ var require_min_satisfying = __commonJS({
|
|
|
24860
24860
|
} catch (er) {
|
|
24861
24861
|
return null;
|
|
24862
24862
|
}
|
|
24863
|
-
versions.forEach((
|
|
24864
|
-
if (rangeObj.test(
|
|
24865
|
-
if (!min || minSV.compare(
|
|
24866
|
-
min =
|
|
24863
|
+
versions.forEach((v2) => {
|
|
24864
|
+
if (rangeObj.test(v2)) {
|
|
24865
|
+
if (!min || minSV.compare(v2) === 1) {
|
|
24866
|
+
min = v2;
|
|
24867
24867
|
minSV = new SemVer(min, options);
|
|
24868
24868
|
}
|
|
24869
24869
|
}
|
|
@@ -25062,8 +25062,8 @@ var require_simplify = __commonJS({
|
|
|
25062
25062
|
const set = [];
|
|
25063
25063
|
let first = null;
|
|
25064
25064
|
let prev = null;
|
|
25065
|
-
const
|
|
25066
|
-
for (const version2 of
|
|
25065
|
+
const v2 = versions.sort((a, b2) => compare(a, b2, options));
|
|
25066
|
+
for (const version2 of v2) {
|
|
25067
25067
|
const included = satisfies(version2, range, options);
|
|
25068
25068
|
if (included) {
|
|
25069
25069
|
prev = version2;
|
|
@@ -25085,11 +25085,11 @@ var require_simplify = __commonJS({
|
|
|
25085
25085
|
for (const [min, max] of set) {
|
|
25086
25086
|
if (min === max) {
|
|
25087
25087
|
ranges.push(min);
|
|
25088
|
-
} else if (!max && min ===
|
|
25088
|
+
} else if (!max && min === v2[0]) {
|
|
25089
25089
|
ranges.push("*");
|
|
25090
25090
|
} else if (!max) {
|
|
25091
25091
|
ranges.push(`>=${min}`);
|
|
25092
|
-
} else if (min ===
|
|
25092
|
+
} else if (min === v2[0]) {
|
|
25093
25093
|
ranges.push(`<=${max}`);
|
|
25094
25094
|
} else {
|
|
25095
25095
|
ranges.push(`${min} - ${max}`);
|
|
@@ -26456,10 +26456,10 @@ var require_util2 = __commonJS({
|
|
|
26456
26456
|
if (k2 === void 0) k2 = k;
|
|
26457
26457
|
o[k2] = m[k];
|
|
26458
26458
|
});
|
|
26459
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o,
|
|
26460
|
-
Object.defineProperty(o, "default", { enumerable: true, value:
|
|
26461
|
-
} : function(o,
|
|
26462
|
-
o["default"] =
|
|
26459
|
+
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
|
|
26460
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v2 });
|
|
26461
|
+
} : function(o, v2) {
|
|
26462
|
+
o["default"] = v2;
|
|
26463
26463
|
});
|
|
26464
26464
|
var __importStar = exports2 && exports2.__importStar || function(mod) {
|
|
26465
26465
|
if (mod && mod.__esModule) return mod;
|
|
@@ -26527,10 +26527,10 @@ var require_tokenizer = __commonJS({
|
|
|
26527
26527
|
if (k2 === void 0) k2 = k;
|
|
26528
26528
|
o[k2] = m[k];
|
|
26529
26529
|
});
|
|
26530
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o,
|
|
26531
|
-
Object.defineProperty(o, "default", { enumerable: true, value:
|
|
26532
|
-
} : function(o,
|
|
26533
|
-
o["default"] =
|
|
26530
|
+
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
|
|
26531
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v2 });
|
|
26532
|
+
} : function(o, v2) {
|
|
26533
|
+
o["default"] = v2;
|
|
26534
26534
|
});
|
|
26535
26535
|
var __importStar = exports2 && exports2.__importStar || function(mod) {
|
|
26536
26536
|
if (mod && mod.__esModule) return mod;
|
|
@@ -26828,10 +26828,10 @@ var require_sets_lookup = __commonJS({
|
|
|
26828
26828
|
if (k2 === void 0) k2 = k;
|
|
26829
26829
|
o[k2] = m[k];
|
|
26830
26830
|
});
|
|
26831
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o,
|
|
26832
|
-
Object.defineProperty(o, "default", { enumerable: true, value:
|
|
26833
|
-
} : function(o,
|
|
26834
|
-
o["default"] =
|
|
26831
|
+
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
|
|
26832
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v2 });
|
|
26833
|
+
} : function(o, v2) {
|
|
26834
|
+
o["default"] = v2;
|
|
26835
26835
|
});
|
|
26836
26836
|
var __importStar = exports2 && exports2.__importStar || function(mod) {
|
|
26837
26837
|
if (mod && mod.__esModule) return mod;
|
|
@@ -26883,10 +26883,10 @@ var require_write_set_tokens = __commonJS({
|
|
|
26883
26883
|
if (k2 === void 0) k2 = k;
|
|
26884
26884
|
o[k2] = m[k];
|
|
26885
26885
|
});
|
|
26886
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o,
|
|
26887
|
-
Object.defineProperty(o, "default", { enumerable: true, value:
|
|
26888
|
-
} : function(o,
|
|
26889
|
-
o["default"] =
|
|
26886
|
+
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
|
|
26887
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v2 });
|
|
26888
|
+
} : function(o, v2) {
|
|
26889
|
+
o["default"] = v2;
|
|
26890
26890
|
});
|
|
26891
26891
|
var __importStar = exports2 && exports2.__importStar || function(mod) {
|
|
26892
26892
|
if (mod && mod.__esModule) return mod;
|
|
@@ -30410,10 +30410,10 @@ var require_dist4 = __commonJS({
|
|
|
30410
30410
|
var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
|
|
30411
30411
|
var __toString = Object.prototype.toString;
|
|
30412
30412
|
var NullObject = /* @__PURE__ */ (() => {
|
|
30413
|
-
const
|
|
30413
|
+
const C = function() {
|
|
30414
30414
|
};
|
|
30415
|
-
|
|
30416
|
-
return
|
|
30415
|
+
C.prototype = /* @__PURE__ */ Object.create(null);
|
|
30416
|
+
return C;
|
|
30417
30417
|
})();
|
|
30418
30418
|
function parse(str, options) {
|
|
30419
30419
|
const obj = new NullObject();
|
|
@@ -34619,7 +34619,7 @@ var require_util3 = __commonJS({
|
|
|
34619
34619
|
var { InvalidArgumentError, ConnectTimeoutError } = require_errors5();
|
|
34620
34620
|
var { headerNameLowerCasedRecord } = require_constants3();
|
|
34621
34621
|
var { tree } = require_tree();
|
|
34622
|
-
var [nodeMajor, nodeMinor] = process.versions.node.split(".", 2).map((
|
|
34622
|
+
var [nodeMajor, nodeMinor] = process.versions.node.split(".", 2).map((v2) => Number(v2));
|
|
34623
34623
|
var BodyAsyncIterable = class {
|
|
34624
34624
|
constructor(body) {
|
|
34625
34625
|
this[kBody] = body;
|
|
@@ -35763,14 +35763,14 @@ var require_wrap_handler = __commonJS({
|
|
|
35763
35763
|
onRequestUpgrade(controller, statusCode, headers, socket) {
|
|
35764
35764
|
const rawHeaders = [];
|
|
35765
35765
|
for (const [key, val] of Object.entries(headers)) {
|
|
35766
|
-
rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((
|
|
35766
|
+
rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((v2) => Buffer.from(v2)) : Buffer.from(val));
|
|
35767
35767
|
}
|
|
35768
35768
|
this.#handler.onUpgrade?.(statusCode, rawHeaders, socket);
|
|
35769
35769
|
}
|
|
35770
35770
|
onResponseStart(controller, statusCode, headers, statusMessage) {
|
|
35771
35771
|
const rawHeaders = [];
|
|
35772
35772
|
for (const [key, val] of Object.entries(headers)) {
|
|
35773
|
-
rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((
|
|
35773
|
+
rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((v2) => Buffer.from(v2)) : Buffer.from(val));
|
|
35774
35774
|
}
|
|
35775
35775
|
if (this.#handler.onHeaders?.(statusCode, rawHeaders, () => controller.resume(), statusMessage) === false) {
|
|
35776
35776
|
controller.pause();
|
|
@@ -35784,7 +35784,7 @@ var require_wrap_handler = __commonJS({
|
|
|
35784
35784
|
onResponseEnd(controller, trailers) {
|
|
35785
35785
|
const rawTrailers = [];
|
|
35786
35786
|
for (const [key, val] of Object.entries(trailers)) {
|
|
35787
|
-
rawTrailers.push(Buffer.from(key), Array.isArray(val) ? val.map((
|
|
35787
|
+
rawTrailers.push(Buffer.from(key), Array.isArray(val) ? val.map((v2) => Buffer.from(v2)) : Buffer.from(val));
|
|
35788
35788
|
}
|
|
35789
35789
|
this.#handler.onComplete?.(rawTrailers);
|
|
35790
35790
|
}
|
|
@@ -44490,8 +44490,8 @@ var require_mock_utils = __commonJS({
|
|
|
44490
44490
|
}
|
|
44491
44491
|
if (value.includes(",")) {
|
|
44492
44492
|
const values = value.split(",");
|
|
44493
|
-
for (const
|
|
44494
|
-
normalizedQp.append(key,
|
|
44493
|
+
for (const v2 of values) {
|
|
44494
|
+
normalizedQp.append(key, v2);
|
|
44495
44495
|
}
|
|
44496
44496
|
continue;
|
|
44497
44497
|
}
|
|
@@ -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.9_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");
|
|
@@ -55037,7 +55037,7 @@ 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
|
|
55040
|
+
function v(...s) {
|
|
55041
55041
|
if (console.log(...s), !(process.env.LOG === "true")) return;
|
|
55042
55042
|
let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(s) ? s.map((o) => typeof o == "object" ? JSON.stringify(o) : String(o)).join(" ") : ""}
|
|
55043
55043
|
`, r = process.env.LOG_FILE || "app.log";
|
|
@@ -55054,50 +55054,50 @@ async function le(s, e, t) {
|
|
|
55054
55054
|
}
|
|
55055
55055
|
function de(s, 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(([l, d]) => {
|
|
55058
|
+
n.set(l, d);
|
|
55059
55059
|
});
|
|
55060
55060
|
let r, o = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
|
|
55061
55061
|
if (t.signal) {
|
|
55062
|
-
let
|
|
55063
|
-
t.signal.addEventListener("abort",
|
|
55062
|
+
let l = new AbortController(), d = () => l.abort();
|
|
55063
|
+
t.signal.addEventListener("abort", d), o.addEventListener("abort", d), r = l.signal;
|
|
55064
55064
|
} else r = o;
|
|
55065
|
-
let
|
|
55066
|
-
return t.httpsProxy && (
|
|
55065
|
+
let c = { method: "POST", headers: n, body: JSON.stringify(e), signal: r };
|
|
55066
|
+
return t.httpsProxy && (c.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), v("final request:", typeof s == "string" ? s : s.toString(), t.httpsProxy, c), fetch(typeof s == "string" ? s : s.toString(), c);
|
|
55067
55067
|
}
|
|
55068
|
-
var
|
|
55068
|
+
var ue = async (s) => {
|
|
55069
55069
|
s.get("/", async (t, n) => ({ message: "LLMs API", version: "1.0.0" })), s.get("/health", async (t, n) => ({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
55070
55070
|
let e = s._server.transformerService.getTransformersWithEndpoint();
|
|
55071
55071
|
for (let { name: t, transformer: n } of e) n.endPoint && s.post(n.endPoint, async (r, o) => {
|
|
55072
|
-
let
|
|
55073
|
-
if (!
|
|
55074
|
-
let
|
|
55072
|
+
let c = r.body, l = r.provider, d = s._server.providerService.getProvider(l);
|
|
55073
|
+
if (!d) throw L(`Provider '${l}' not found`, 404, "provider_not_found");
|
|
55074
|
+
let i = c, p = {};
|
|
55075
55075
|
if (typeof n.transformRequestOut == "function") {
|
|
55076
|
-
let
|
|
55077
|
-
|
|
55078
|
-
}
|
|
55079
|
-
if (
|
|
55080
|
-
if (!
|
|
55081
|
-
let
|
|
55082
|
-
|
|
55083
|
-
}
|
|
55084
|
-
if (
|
|
55085
|
-
let
|
|
55086
|
-
if (!
|
|
55087
|
-
let
|
|
55088
|
-
throw
|
|
55089
|
-
}
|
|
55090
|
-
let g =
|
|
55091
|
-
if (
|
|
55092
|
-
if (
|
|
55093
|
-
return n.transformResponseIn && (g = await n.transformResponseIn(g)), g.ok || o.code(g.status),
|
|
55076
|
+
let a = await n.transformRequestOut(c);
|
|
55077
|
+
a.body ? (i = a.body, p = a.config || {}) : i = a;
|
|
55078
|
+
}
|
|
55079
|
+
if (v("use transformers:", d.transformer?.use), d.transformer?.use?.length) for (let a of d.transformer.use) {
|
|
55080
|
+
if (!a || typeof a.transformRequestIn != "function") continue;
|
|
55081
|
+
let y = await a.transformRequestIn(i, d);
|
|
55082
|
+
y.body ? (i = y.body, p = { ...p, ...y.config }) : i = y;
|
|
55083
|
+
}
|
|
55084
|
+
if (d.transformer?.[r.body.model]?.use?.length) for (let a of d.transformer[r.body.model].use) !a || typeof a.transformRequestIn != "function" || (i = await a.transformRequestIn(i, d));
|
|
55085
|
+
let _ = p.url || new URL(d.baseUrl), C = await de(_, i, { httpsProxy: s._server.configService.getHttpsProxy(), ...p, headers: { Authorization: `Bearer ${d.apiKey}`, ...p?.headers || {} } });
|
|
55086
|
+
if (!C.ok) {
|
|
55087
|
+
let a = await C.text();
|
|
55088
|
+
throw v(`Error response from ${_}: ${a}`), L(`Error from provider: ${a}`, C.status, "provider_response_error");
|
|
55089
|
+
}
|
|
55090
|
+
let g = C;
|
|
55091
|
+
if (d.transformer?.use?.length) for (let a of d.transformer.use) !a || typeof a.transformResponseOut != "function" || (g = await a.transformResponseOut(g));
|
|
55092
|
+
if (d.transformer?.[r.body.model]?.use?.length) for (let a of d.transformer[r.body.model].use) !a || typeof a.transformResponseOut != "function" || (g = await a.transformResponseOut(g));
|
|
55093
|
+
return n.transformResponseIn && (g = await n.transformResponseIn(g)), g.ok || o.code(g.status), c?.stream === true ? (o.header("Content-Type", "text/event-stream"), o.header("Cache-Control", "no-cache"), o.header("Connection", "keep-alive"), o.send(g.body)) : g.json();
|
|
55094
55094
|
});
|
|
55095
55095
|
s.post("/providers", { schema: { body: { type: "object", properties: { id: { type: "string" }, name: { type: "string" }, type: { type: "string", enum: ["openai", "anthropic"] }, baseUrl: { type: "string" }, apiKey: { type: "string" }, models: { type: "array", items: { type: "string" } } }, required: ["id", "name", "type", "baseUrl", "apiKey", "models"] } } }, async (t, n) => {
|
|
55096
|
-
let { name: r, type: o, baseUrl:
|
|
55096
|
+
let { name: r, type: o, baseUrl: c, apiKey: l, models: d } = t.body;
|
|
55097
55097
|
if (!r?.trim()) throw L("Provider name is required", 400, "invalid_request");
|
|
55098
|
-
if (!
|
|
55099
|
-
if (!
|
|
55100
|
-
if (!
|
|
55098
|
+
if (!c || !Ce(c)) throw L("Valid base URL is required", 400, "invalid_request");
|
|
55099
|
+
if (!l?.trim()) throw L("API key is required", 400, "invalid_request");
|
|
55100
|
+
if (!d || !Array.isArray(d) || d.length === 0) throw L("At least one model is required", 400, "invalid_request");
|
|
55101
55101
|
if (s._server.providerService.getProvider(id)) throw L(`Provider with ID '${id}' already exists`, 400, "provider_exists");
|
|
55102
55102
|
return s._server.providerService.registerProvider(t.body);
|
|
55103
55103
|
}), s.get("/providers", async (t, n) => s._server.providerService.getProviders()), s.get("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => {
|
|
@@ -55108,7 +55108,7 @@ var fe = async (s) => {
|
|
|
55108
55108
|
return r || n.code(404).send({ error: "Provider not found" });
|
|
55109
55109
|
}), s.delete("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => s._server.providerService.deleteProvider(t.params.id) ? { message: "Provider deleted successfully" } : n.code(404).send({ error: "Provider not found" })), s.patch("/providers/:id/toggle", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] }, body: { type: "object", properties: { enabled: { type: "boolean" } }, required: ["enabled"] } } }, async (t, n) => s._server.providerService.toggleProvider(t.params.id, t.body.enabled) ? { message: `Provider ${t.body.enabled ? "enabled" : "disabled"} successfully` } : n.code(404).send({ error: "Provider not found" }));
|
|
55110
55110
|
};
|
|
55111
|
-
function
|
|
55111
|
+
function Ce(s) {
|
|
55112
55112
|
try {
|
|
55113
55113
|
return new URL(s), true;
|
|
55114
55114
|
} catch {
|
|
@@ -55175,20 +55175,20 @@ var F = class {
|
|
|
55175
55175
|
t.transformer && Object.keys(t.transformer).forEach((r) => {
|
|
55176
55176
|
r === "use" ? Array.isArray(t.transformer.use) && (n.use = t.transformer.use.map((o) => {
|
|
55177
55177
|
if (Array.isArray(o) && typeof o[0] == "string") {
|
|
55178
|
-
let
|
|
55179
|
-
if (
|
|
55178
|
+
let c = this.transformerService.getTransformer(o[0]);
|
|
55179
|
+
if (c) return new c(o[1]);
|
|
55180
55180
|
}
|
|
55181
55181
|
if (typeof o == "string") return this.transformerService.getTransformer(o);
|
|
55182
55182
|
}).filter((o) => typeof o < "u")) : Array.isArray(t.transformer[r]?.use) && (n[r] = { use: t.transformer[r].use.map((o) => {
|
|
55183
55183
|
if (Array.isArray(o) && typeof o[0] == "string") {
|
|
55184
|
-
let
|
|
55185
|
-
if (
|
|
55184
|
+
let c = this.transformerService.getTransformer(o[0]);
|
|
55185
|
+
if (c) return new c(o[1]);
|
|
55186
55186
|
}
|
|
55187
55187
|
if (typeof o == "string") return this.transformerService.getTransformer(o);
|
|
55188
55188
|
}).filter((o) => typeof o < "u") });
|
|
55189
|
-
}), this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: t.transformer ? n : void 0 }),
|
|
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}`);
|
|
55192
55192
|
}
|
|
55193
55193
|
});
|
|
55194
55194
|
}
|
|
@@ -55210,11 +55210,11 @@ var F = class {
|
|
|
55210
55210
|
if (!n) return null;
|
|
55211
55211
|
let r = { ...n, ...t, updatedAt: /* @__PURE__ */ new Date() };
|
|
55212
55212
|
return this.providers.set(e, r), t.models && (n.models.forEach((o) => {
|
|
55213
|
-
let
|
|
55214
|
-
this.modelRoutes.delete(
|
|
55213
|
+
let c = `${n.id},${o}`;
|
|
55214
|
+
this.modelRoutes.delete(c), this.modelRoutes.delete(o);
|
|
55215
55215
|
}), t.models.forEach((o) => {
|
|
55216
|
-
let
|
|
55217
|
-
this.modelRoutes.set(
|
|
55216
|
+
let c = `${n.name},${o}`, l = { provider: n.name, model: o, fullModel: c };
|
|
55217
|
+
this.modelRoutes.set(c, l), this.modelRoutes.has(o) || this.modelRoutes.set(o, l);
|
|
55218
55218
|
})), r;
|
|
55219
55219
|
}
|
|
55220
55220
|
deleteProvider(e) {
|
|
@@ -55265,35 +55265,37 @@ var F = class {
|
|
|
55265
55265
|
var U = class {
|
|
55266
55266
|
name = "Anthropic";
|
|
55267
55267
|
endPoint = "/v1/messages";
|
|
55268
|
-
transformRequestOut(e) {
|
|
55269
|
-
|
|
55268
|
+
async transformRequestOut(e) {
|
|
55269
|
+
v("Anthropic Request:", JSON.stringify(e, null, 2));
|
|
55270
55270
|
let t = [];
|
|
55271
55271
|
if (e.system) {
|
|
55272
55272
|
if (typeof e.system == "string") t.push({ role: "system", content: e.system });
|
|
55273
55273
|
else if (Array.isArray(e.system)) {
|
|
55274
|
-
let o = e.system.filter((
|
|
55274
|
+
let o = e.system.filter((c) => c.type === "text" && c.text).map((c) => ({ type: "text", text: c.text, cache_control: c.cache_control }));
|
|
55275
55275
|
t.push({ role: "system", content: o });
|
|
55276
55276
|
}
|
|
55277
55277
|
}
|
|
55278
|
-
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((o,
|
|
55278
|
+
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((o, c) => {
|
|
55279
55279
|
if (o.role === "user" || o.role === "assistant") {
|
|
55280
|
-
|
|
55281
|
-
|
|
55282
|
-
|
|
55280
|
+
if (typeof o.content == "string") {
|
|
55281
|
+
t.push({ role: o.role, content: o.content });
|
|
55282
|
+
return;
|
|
55283
|
+
}
|
|
55284
|
+
if (Array.isArray(o.content)) {
|
|
55283
55285
|
if (o.role === "user") {
|
|
55284
|
-
let
|
|
55285
|
-
|
|
55286
|
-
let
|
|
55287
|
-
t.push(
|
|
55286
|
+
let l = o.content.filter((i) => i.type === "tool_result" && i.tool_use_id);
|
|
55287
|
+
l.length && l.forEach((i, p) => {
|
|
55288
|
+
let _ = { role: "tool", content: typeof i.content == "string" ? i.content : JSON.stringify(i.content), tool_call_id: i.tool_use_id, cache_control: i.cache_control };
|
|
55289
|
+
t.push(_);
|
|
55288
55290
|
});
|
|
55289
|
-
let
|
|
55290
|
-
|
|
55291
|
+
let d = o.content.filter((i) => i.type === "text" && i.text || i.type === "image" && i.source);
|
|
55292
|
+
d.length && t.push({ role: "user", content: d.map((i) => i?.type === "image" ? { type: "image_url", image_url: { url: i.source?.type === "base64" ? i.source.data : i.source.url }, media_type: i.source.media_type } : i) });
|
|
55291
55293
|
} else if (o.role === "assistant") {
|
|
55292
|
-
let
|
|
55293
|
-
|
|
55294
|
+
let l = { role: "assistant", content: null }, d = o.content.filter((p) => p.type === "text" && p.text);
|
|
55295
|
+
d.length && (l.content = d.map((p) => p.text).join(`
|
|
55294
55296
|
`));
|
|
55295
|
-
let
|
|
55296
|
-
|
|
55297
|
+
let i = o.content.filter((p) => p.type === "tool_use" && p.id);
|
|
55298
|
+
i.length && (l.tool_calls = i.map((p) => ({ id: p.id, type: "function", function: { name: p.name, arguments: JSON.stringify(p.input || {}) } }))), t.push(l);
|
|
55297
55299
|
}
|
|
55298
55300
|
return;
|
|
55299
55301
|
}
|
|
@@ -55315,27 +55317,27 @@ var U = class {
|
|
|
55315
55317
|
}
|
|
55316
55318
|
async convertOpenAIStreamToAnthropic(e) {
|
|
55317
55319
|
return new ReadableStream({ async start(n) {
|
|
55318
|
-
let r = new TextEncoder(), o = `msg_${Date.now()}`,
|
|
55319
|
-
if (!
|
|
55320
|
+
let r = new TextEncoder(), o = `msg_${Date.now()}`, c = "unknown", l = false, d = false, i = false, p = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map(), C = 0, g = 0, u = 0, a = false, y = false, h = 0, f = (x) => {
|
|
55321
|
+
if (!a) try {
|
|
55320
55322
|
n.enqueue(x);
|
|
55321
55323
|
let R = new TextDecoder().decode(x);
|
|
55322
|
-
|
|
55324
|
+
v("send data:", R.trim());
|
|
55323
55325
|
} catch (R) {
|
|
55324
|
-
if (R instanceof TypeError && R.message.includes("Controller is already closed"))
|
|
55325
|
-
else throw
|
|
55326
|
+
if (R instanceof TypeError && R.message.includes("Controller is already closed")) a = true;
|
|
55327
|
+
else throw v(`send data error: ${R.message}`), R;
|
|
55326
55328
|
}
|
|
55327
55329
|
}, m = () => {
|
|
55328
|
-
if (!
|
|
55329
|
-
n.close(),
|
|
55330
|
+
if (!a) try {
|
|
55331
|
+
n.close(), a = true;
|
|
55330
55332
|
} catch (x) {
|
|
55331
|
-
if (x instanceof TypeError && x.message.includes("Controller is already closed"))
|
|
55333
|
+
if (x instanceof TypeError && x.message.includes("Controller is already closed")) a = true;
|
|
55332
55334
|
else throw x;
|
|
55333
55335
|
}
|
|
55334
55336
|
}, T = null;
|
|
55335
55337
|
try {
|
|
55336
55338
|
T = e.getReader();
|
|
55337
55339
|
let x = new TextDecoder(), R = "";
|
|
55338
|
-
for (; !
|
|
55340
|
+
for (; !a; ) {
|
|
55339
55341
|
let { done: X, value: me } = await T.read();
|
|
55340
55342
|
if (X) break;
|
|
55341
55343
|
R += x.decode(me, { stream: true });
|
|
@@ -55343,129 +55345,129 @@ var U = class {
|
|
|
55343
55345
|
`);
|
|
55344
55346
|
R = se.pop() || "";
|
|
55345
55347
|
for (let ie of se) {
|
|
55346
|
-
if (
|
|
55348
|
+
if (a || i) break;
|
|
55347
55349
|
if (!ie.startsWith("data: ")) continue;
|
|
55348
55350
|
let Q = ie.slice(6);
|
|
55349
55351
|
if (Q !== "[DONE]") try {
|
|
55350
55352
|
let O = JSON.parse(Q);
|
|
55351
|
-
if (
|
|
55352
|
-
let
|
|
55353
|
-
|
|
55354
|
-
data: ${JSON.stringify(
|
|
55353
|
+
if (C++, v("Original Response:", JSON.stringify(O, null, 2)), O.error) {
|
|
55354
|
+
let k = { type: "error", message: { type: "api_error", message: JSON.stringify(O.error) } };
|
|
55355
|
+
f(r.encode(`event: error
|
|
55356
|
+
data: ${JSON.stringify(k)}
|
|
55355
55357
|
|
|
55356
55358
|
`));
|
|
55357
55359
|
continue;
|
|
55358
55360
|
}
|
|
55359
|
-
if (
|
|
55360
|
-
|
|
55361
|
-
let
|
|
55362
|
-
|
|
55363
|
-
data: ${JSON.stringify(
|
|
55361
|
+
if (c = O.model || c, !l && !a && !i) {
|
|
55362
|
+
l = true;
|
|
55363
|
+
let k = { type: "message_start", message: { id: o, type: "message", role: "assistant", content: [], model: c, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
|
|
55364
|
+
f(r.encode(`event: message_start
|
|
55365
|
+
data: ${JSON.stringify(k)}
|
|
55364
55366
|
|
|
55365
55367
|
`));
|
|
55366
55368
|
}
|
|
55367
55369
|
let w = O.choices?.[0];
|
|
55368
55370
|
if (!w) continue;
|
|
55369
|
-
if (w?.delta?.thinking && !
|
|
55370
|
-
if (!
|
|
55371
|
-
let
|
|
55372
|
-
|
|
55373
|
-
data: ${JSON.stringify(
|
|
55371
|
+
if (w?.delta?.thinking && !a && !i) {
|
|
55372
|
+
if (!y) {
|
|
55373
|
+
let k = { type: "content_block_start", index: h, content_block: { type: "thinking", thinking: "" } };
|
|
55374
|
+
f(r.encode(`event: content_block_start
|
|
55375
|
+
data: ${JSON.stringify(k)}
|
|
55374
55376
|
|
|
55375
|
-
`)),
|
|
55377
|
+
`)), y = true;
|
|
55376
55378
|
}
|
|
55377
55379
|
if (w.delta.thinking.signature) {
|
|
55378
|
-
let
|
|
55379
|
-
|
|
55380
|
-
data: ${JSON.stringify(
|
|
55380
|
+
let k = { type: "content_block_delta", index: h, delta: { type: "signature_delta", signature: w.delta.thinking.signature } };
|
|
55381
|
+
f(r.encode(`event: content_block_delta
|
|
55382
|
+
data: ${JSON.stringify(k)}
|
|
55381
55383
|
|
|
55382
55384
|
`));
|
|
55383
55385
|
let S = { type: "content_block_stop", index: h };
|
|
55384
|
-
|
|
55386
|
+
f(r.encode(`event: content_block_stop
|
|
55385
55387
|
data: ${JSON.stringify(S)}
|
|
55386
55388
|
|
|
55387
55389
|
`)), h++;
|
|
55388
55390
|
} else if (w.delta.thinking.content) {
|
|
55389
|
-
let
|
|
55390
|
-
|
|
55391
|
-
data: ${JSON.stringify(
|
|
55391
|
+
let k = { type: "content_block_delta", index: h, delta: { type: "thinking_delta", thinking: w.delta.thinking.content || "" } };
|
|
55392
|
+
f(r.encode(`event: content_block_delta
|
|
55393
|
+
data: ${JSON.stringify(k)}
|
|
55392
55394
|
|
|
55393
55395
|
`));
|
|
55394
55396
|
}
|
|
55395
55397
|
}
|
|
55396
|
-
if (w?.delta?.content && !
|
|
55397
|
-
if (g++, !
|
|
55398
|
-
|
|
55399
|
-
let
|
|
55400
|
-
|
|
55401
|
-
data: ${JSON.stringify(
|
|
55398
|
+
if (w?.delta?.content && !a && !i) {
|
|
55399
|
+
if (g++, !d && !i) {
|
|
55400
|
+
d = true;
|
|
55401
|
+
let k = { type: "content_block_start", index: h, content_block: { type: "text", text: "" } };
|
|
55402
|
+
f(r.encode(`event: content_block_start
|
|
55403
|
+
data: ${JSON.stringify(k)}
|
|
55402
55404
|
|
|
55403
55405
|
`));
|
|
55404
55406
|
}
|
|
55405
|
-
if (!
|
|
55406
|
-
let
|
|
55407
|
-
|
|
55408
|
-
data: ${JSON.stringify(
|
|
55407
|
+
if (!a && !i) {
|
|
55408
|
+
let k = { type: "content_block_delta", index: h, delta: { type: "text_delta", text: w.delta.content } };
|
|
55409
|
+
f(r.encode(`event: content_block_delta
|
|
55410
|
+
data: ${JSON.stringify(k)}
|
|
55409
55411
|
|
|
55410
55412
|
`));
|
|
55411
55413
|
}
|
|
55412
55414
|
}
|
|
55413
|
-
if (w?.delta?.tool_calls && !
|
|
55414
|
-
|
|
55415
|
-
let
|
|
55415
|
+
if (w?.delta?.tool_calls && !a && !i) {
|
|
55416
|
+
u++;
|
|
55417
|
+
let k = /* @__PURE__ */ new Set();
|
|
55416
55418
|
for (let S of w.delta.tool_calls) {
|
|
55417
|
-
if (
|
|
55419
|
+
if (a) break;
|
|
55418
55420
|
let P = S.index ?? 0;
|
|
55419
|
-
if (
|
|
55420
|
-
if (
|
|
55421
|
-
let E =
|
|
55421
|
+
if (k.has(P)) continue;
|
|
55422
|
+
if (k.add(P), !_.has(P)) {
|
|
55423
|
+
let E = d ? _.size + 1 : _.size;
|
|
55422
55424
|
if (E !== 0) {
|
|
55423
|
-
|
|
55425
|
+
v("content_block_stop2");
|
|
55424
55426
|
let he = { type: "content_block_stop", index: h };
|
|
55425
|
-
|
|
55427
|
+
f(r.encode(`event: content_block_stop
|
|
55426
55428
|
data: ${JSON.stringify(he)}
|
|
55427
55429
|
|
|
55428
55430
|
`)), h++;
|
|
55429
55431
|
}
|
|
55430
|
-
|
|
55431
|
-
let
|
|
55432
|
-
|
|
55432
|
+
_.set(P, E);
|
|
55433
|
+
let H = S.id || `call_${Date.now()}_${P}`, A = S.function?.name || `tool_${P}`, N = { type: "content_block_start", index: h, content_block: { type: "tool_use", id: H, name: A, input: {} } };
|
|
55434
|
+
f(r.encode(`event: content_block_start
|
|
55433
55435
|
data: ${JSON.stringify(N)}
|
|
55434
55436
|
|
|
55435
55437
|
`));
|
|
55436
|
-
let
|
|
55437
|
-
|
|
55438
|
+
let M = { id: H, name: A, arguments: "", contentBlockIndex: E };
|
|
55439
|
+
p.set(P, M);
|
|
55438
55440
|
} else if (S.id && S.function?.name) {
|
|
55439
|
-
let E =
|
|
55441
|
+
let E = p.get(P);
|
|
55440
55442
|
E.id.startsWith("call_") && E.name.startsWith("tool_") && (E.id = S.id, E.name = S.function.name);
|
|
55441
55443
|
}
|
|
55442
|
-
if (S.function?.arguments && !
|
|
55443
|
-
if (
|
|
55444
|
-
let
|
|
55445
|
-
if (
|
|
55446
|
-
|
|
55444
|
+
if (S.function?.arguments && !a && !i) {
|
|
55445
|
+
if (_.get(P) === void 0) continue;
|
|
55446
|
+
let H = p.get(P);
|
|
55447
|
+
if (H) {
|
|
55448
|
+
H.arguments += S.function.arguments;
|
|
55447
55449
|
try {
|
|
55448
|
-
let A = null, N =
|
|
55450
|
+
let A = null, N = H.arguments.trim();
|
|
55449
55451
|
if (N.startsWith("{") && N.endsWith("}")) try {
|
|
55450
55452
|
A = JSON.parse(N);
|
|
55451
|
-
} catch (
|
|
55452
|
-
|
|
55453
|
+
} catch (M) {
|
|
55454
|
+
v("Tool call index:", P, "error", M.message);
|
|
55453
55455
|
}
|
|
55454
55456
|
} catch (A) {
|
|
55455
|
-
|
|
55457
|
+
v("Tool call index:", P, "error", A.message);
|
|
55456
55458
|
}
|
|
55457
55459
|
}
|
|
55458
55460
|
try {
|
|
55459
55461
|
let A = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: S.function.arguments } };
|
|
55460
|
-
|
|
55462
|
+
f(r.encode(`event: content_block_delta
|
|
55461
55463
|
data: ${JSON.stringify(A)}
|
|
55462
55464
|
|
|
55463
55465
|
`));
|
|
55464
55466
|
} catch {
|
|
55465
55467
|
try {
|
|
55466
|
-
let N = S.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'),
|
|
55467
|
-
|
|
55468
|
-
data: ${JSON.stringify(
|
|
55468
|
+
let N = S.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), M = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: N } };
|
|
55469
|
+
f(r.encode(`event: content_block_delta
|
|
55470
|
+
data: ${JSON.stringify(M)}
|
|
55469
55471
|
|
|
55470
55472
|
`));
|
|
55471
55473
|
} catch (N) {
|
|
@@ -55475,39 +55477,39 @@ data: ${JSON.stringify(H)}
|
|
|
55475
55477
|
}
|
|
55476
55478
|
}
|
|
55477
55479
|
}
|
|
55478
|
-
if (w?.finish_reason && !
|
|
55479
|
-
if (
|
|
55480
|
-
|
|
55481
|
-
let
|
|
55482
|
-
|
|
55483
|
-
data: ${JSON.stringify(
|
|
55480
|
+
if (w?.finish_reason && !a && !i) {
|
|
55481
|
+
if (i = true, g === 0 && u === 0 && console.error("Warning: No content in the stream response!"), (d || u > 0) && !a) {
|
|
55482
|
+
v("content_block_stop hasTextContentStarted");
|
|
55483
|
+
let k = { type: "content_block_stop", index: h };
|
|
55484
|
+
f(r.encode(`event: content_block_stop
|
|
55485
|
+
data: ${JSON.stringify(k)}
|
|
55484
55486
|
|
|
55485
55487
|
`));
|
|
55486
55488
|
}
|
|
55487
|
-
if (!
|
|
55489
|
+
if (!a) {
|
|
55488
55490
|
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 } };
|
|
55489
|
-
|
|
55491
|
+
f(r.encode(`event: message_delta
|
|
55490
55492
|
data: ${JSON.stringify(P)}
|
|
55491
55493
|
|
|
55492
55494
|
`));
|
|
55493
55495
|
}
|
|
55494
|
-
if (!
|
|
55495
|
-
let
|
|
55496
|
-
|
|
55497
|
-
data: ${JSON.stringify(
|
|
55496
|
+
if (!a) {
|
|
55497
|
+
let k = { type: "message_stop" };
|
|
55498
|
+
f(r.encode(`event: message_stop
|
|
55499
|
+
data: ${JSON.stringify(k)}
|
|
55498
55500
|
|
|
55499
55501
|
`));
|
|
55500
55502
|
}
|
|
55501
55503
|
break;
|
|
55502
55504
|
}
|
|
55503
55505
|
} catch (O) {
|
|
55504
|
-
|
|
55506
|
+
v(`parseError: ${O.name} message: ${O.message} stack: ${O.stack} data: ${Q}`);
|
|
55505
55507
|
}
|
|
55506
55508
|
}
|
|
55507
55509
|
}
|
|
55508
55510
|
m();
|
|
55509
55511
|
} catch (x) {
|
|
55510
|
-
if (!
|
|
55512
|
+
if (!a) try {
|
|
55511
55513
|
n.error(x);
|
|
55512
55514
|
} catch (R) {
|
|
55513
55515
|
console.error(R);
|
|
@@ -55520,26 +55522,26 @@ data: ${JSON.stringify(_)}
|
|
|
55520
55522
|
}
|
|
55521
55523
|
}
|
|
55522
55524
|
}, cancel(n) {
|
|
55523
|
-
|
|
55525
|
+
v("cancle stream:", n);
|
|
55524
55526
|
} });
|
|
55525
55527
|
}
|
|
55526
55528
|
convertOpenAIResponseToAnthropic(e) {
|
|
55527
|
-
|
|
55529
|
+
v("Original OpenAI response:", JSON.stringify(e, null, 2));
|
|
55528
55530
|
let t = e.choices[0];
|
|
55529
55531
|
if (!t) throw new Error("No choices found in OpenAI response");
|
|
55530
55532
|
let n = [];
|
|
55531
|
-
t.message.content && n.push({ type: "text", text: t.message.content }), t.message.tool_calls && t.message.tool_calls.length > 0 && t.message.tool_calls.forEach((o,
|
|
55532
|
-
let
|
|
55533
|
+
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((o, c) => {
|
|
55534
|
+
let l = {};
|
|
55533
55535
|
try {
|
|
55534
|
-
let
|
|
55535
|
-
typeof
|
|
55536
|
+
let d = o.function.arguments || "{}";
|
|
55537
|
+
typeof d == "object" ? l = d : typeof d == "string" && (l = JSON.parse(d));
|
|
55536
55538
|
} catch {
|
|
55537
|
-
|
|
55539
|
+
l = { text: o.function.arguments || "" };
|
|
55538
55540
|
}
|
|
55539
|
-
n.push({ type: "tool_use", id: o.id, name: o.function.name, input:
|
|
55541
|
+
n.push({ type: "tool_use", id: o.id, name: o.function.name, input: l });
|
|
55540
55542
|
});
|
|
55541
55543
|
let r = { 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 } };
|
|
55542
|
-
return
|
|
55544
|
+
return v("Conversion complete, final Anthropic response:", JSON.stringify(r, null, 2)), r;
|
|
55543
55545
|
}
|
|
55544
55546
|
};
|
|
55545
55547
|
function ee(s) {
|
|
@@ -55556,25 +55558,26 @@ function ee(s) {
|
|
|
55556
55558
|
var J = class {
|
|
55557
55559
|
name = "gemini";
|
|
55558
55560
|
endPoint = "/v1beta/models/:modelAndAction";
|
|
55559
|
-
transformRequestIn(e, t) {
|
|
55561
|
+
async transformRequestIn(e, t) {
|
|
55560
55562
|
return { body: { contents: e.messages.map((n) => {
|
|
55561
55563
|
let r;
|
|
55562
55564
|
n.role === "assistant" ? r = "model" : (["user", "system", "tool"].includes(n.role), r = "user");
|
|
55563
55565
|
let o = [];
|
|
55564
|
-
return typeof n.content == "string" ? o.push({ text: n.content }) : Array.isArray(n.content) && o.push(...n.content.map((
|
|
55565
|
-
if (
|
|
55566
|
-
|
|
55566
|
+
return typeof n.content == "string" ? o.push({ text: n.content }) : Array.isArray(n.content) && o.push(...n.content.map((c) => {
|
|
55567
|
+
if (c.type === "text") return { text: c.text || "" };
|
|
55568
|
+
if (c.type === "image_url") return c.image_url.url.startsWith("http") ? { file_data: { mime_type: c.media_type, file_uri: c.image_url.url } } : { inlineData: { mime_type: c.media_type, data: c.image_url.url } };
|
|
55569
|
+
})), Array.isArray(n.tool_calls) && o.push(...n.tool_calls.map((c) => ({ functionCall: { id: c.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: c.function.name, args: JSON.parse(c.function.arguments || "{}") } }))), { role: r, parts: o };
|
|
55567
55570
|
}), tools: [{ functionDeclarations: e.tools?.map((n) => (n.function.parameters && ee(n.function.parameters), { name: n.function.name, description: n.function.description, parameters: n.function.parameters })) || [] }] }, config: { url: new URL(`./${e.model}:${e.stream ? "streamGenerateContent?alt=sse" : "generateContent"}`, t.baseUrl), headers: { "x-goog-api-key": t.apiKey, Authorization: void 0 } } };
|
|
55568
55571
|
}
|
|
55569
55572
|
transformRequestOut(e) {
|
|
55570
|
-
let t = e.contents, n = e.tools, r = e.model, o = e.max_tokens,
|
|
55571
|
-
return Array.isArray(t) && t.forEach((
|
|
55572
|
-
typeof
|
|
55573
|
-
}), Array.isArray(n) && (
|
|
55574
|
-
Array.isArray(
|
|
55575
|
-
|
|
55573
|
+
let t = e.contents, n = e.tools, r = e.model, o = e.max_tokens, c = e.temperature, l = e.stream, d = e.tool_choice, i = { messages: [], model: r, max_tokens: o, temperature: c, stream: l, tool_choice: d };
|
|
55574
|
+
return Array.isArray(t) && t.forEach((p) => {
|
|
55575
|
+
typeof p == "string" ? i.messages.push({ role: "user", content: p }) : typeof p.text == "string" ? i.messages.push({ role: "user", content: p.text || null }) : p.role === "user" ? i.messages.push({ role: "user", content: p?.parts?.map((_) => ({ type: "text", text: _.text || "" })) || [] }) : p.role === "model" && i.messages.push({ role: "assistant", content: p?.parts?.map((_) => ({ type: "text", text: _.text || "" })) || [] });
|
|
55576
|
+
}), Array.isArray(n) && (i.tools = [], n.forEach((p) => {
|
|
55577
|
+
Array.isArray(p.functionDeclarations) && p.functionDeclarations.forEach((_) => {
|
|
55578
|
+
i.tools.push({ type: "function", function: { name: _.name, description: _.description, parameters: _.parameters } });
|
|
55576
55579
|
});
|
|
55577
|
-
})),
|
|
55580
|
+
})), i;
|
|
55578
55581
|
}
|
|
55579
55582
|
async transformResponseOut(e) {
|
|
55580
55583
|
if (e.headers.get("Content-Type")?.includes("application/json")) {
|
|
@@ -55584,23 +55587,23 @@ var J = class {
|
|
|
55584
55587
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55585
55588
|
if (!e.body) return e;
|
|
55586
55589
|
let t = new TextDecoder(), n = new TextEncoder(), r = new ReadableStream({ async start(o) {
|
|
55587
|
-
let
|
|
55590
|
+
let c = e.body.getReader();
|
|
55588
55591
|
try {
|
|
55589
55592
|
for (; ; ) {
|
|
55590
|
-
let { done:
|
|
55591
|
-
if (
|
|
55592
|
-
let
|
|
55593
|
-
if (
|
|
55593
|
+
let { done: l, value: d } = await c.read();
|
|
55594
|
+
if (l) break;
|
|
55595
|
+
let i = t.decode(d, { stream: true });
|
|
55596
|
+
if (i.startsWith("data: ")) i = i.slice(6).trim();
|
|
55594
55597
|
else break;
|
|
55595
|
-
|
|
55596
|
-
let
|
|
55597
|
-
`), tool_calls:
|
|
55598
|
-
|
|
55598
|
+
v("gemini chunk:", i), i = JSON.parse(i);
|
|
55599
|
+
let p = i.candidates[0].content.parts.filter((C) => C.functionCall).map((C) => ({ id: C.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: C.functionCall?.name, arguments: JSON.stringify(C.functionCall?.args || {}) } })), _ = { choices: [{ delta: { role: "assistant", content: i.candidates[0].content.parts.filter((C) => C.text).map((C) => C.text).join(`
|
|
55600
|
+
`), tool_calls: p.length > 0 ? p : void 0 }, finish_reason: i.candidates[0].finishReason?.toLowerCase() || null, index: i.candidates[0].index || p.length > 0 ? 1 : 0, logprobs: null }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), id: i.responseId || "", model: i.modelVersion || "", object: "chat.completion.chunk", system_fingerprint: "fp_a49d71b8a1" };
|
|
55601
|
+
v("gemini response:", JSON.stringify(_, null, 2)), o.enqueue(n.encode(`data: ${JSON.stringify(_)}
|
|
55599
55602
|
|
|
55600
55603
|
`));
|
|
55601
55604
|
}
|
|
55602
|
-
} catch (
|
|
55603
|
-
o.error(
|
|
55605
|
+
} catch (l) {
|
|
55606
|
+
o.error(l);
|
|
55604
55607
|
} finally {
|
|
55605
55608
|
o.close();
|
|
55606
55609
|
}
|
|
@@ -55621,61 +55624,61 @@ var j = class {
|
|
|
55621
55624
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55622
55625
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55623
55626
|
if (!e.body) return e;
|
|
55624
|
-
let t = new TextDecoder(), n = new TextEncoder(), r = "", o = false,
|
|
55625
|
-
let
|
|
55627
|
+
let t = new TextDecoder(), n = new TextEncoder(), r = "", o = false, c = new ReadableStream({ async start(l) {
|
|
55628
|
+
let d = e.body.getReader();
|
|
55626
55629
|
try {
|
|
55627
55630
|
for (; ; ) {
|
|
55628
|
-
let { done:
|
|
55629
|
-
if (
|
|
55630
|
-
let
|
|
55631
|
+
let { done: i, value: p } = await d.read();
|
|
55632
|
+
if (i) break;
|
|
55633
|
+
let C = t.decode(p, { stream: true }).split(`
|
|
55631
55634
|
`);
|
|
55632
|
-
for (let g of
|
|
55633
|
-
let
|
|
55634
|
-
if (
|
|
55635
|
-
r +=
|
|
55636
|
-
let
|
|
55637
|
-
delete
|
|
55638
|
-
let
|
|
55635
|
+
for (let g of C) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
|
|
55636
|
+
let u = JSON.parse(g.slice(6));
|
|
55637
|
+
if (u.choices?.[0]?.delta?.reasoning_content) {
|
|
55638
|
+
r += u.choices[0].delta.reasoning_content;
|
|
55639
|
+
let a = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, thinking: { content: u.choices[0].delta.reasoning_content } } }] };
|
|
55640
|
+
delete a.choices[0].delta.reasoning_content;
|
|
55641
|
+
let y = `data: ${JSON.stringify(a)}
|
|
55639
55642
|
|
|
55640
55643
|
`;
|
|
55641
|
-
|
|
55644
|
+
l.enqueue(n.encode(y));
|
|
55642
55645
|
continue;
|
|
55643
55646
|
}
|
|
55644
|
-
if (
|
|
55647
|
+
if (u.choices?.[0]?.delta?.content && r && !o) {
|
|
55645
55648
|
o = true;
|
|
55646
|
-
let
|
|
55647
|
-
delete
|
|
55648
|
-
let h = `data: ${JSON.stringify(
|
|
55649
|
+
let a = Date.now().toString(), y = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, content: null, thinking: { content: r, signature: a } } }] };
|
|
55650
|
+
delete y.choices[0].delta.reasoning_content;
|
|
55651
|
+
let h = `data: ${JSON.stringify(y)}
|
|
55649
55652
|
|
|
55650
55653
|
`;
|
|
55651
|
-
|
|
55654
|
+
l.enqueue(n.encode(h));
|
|
55652
55655
|
}
|
|
55653
|
-
if (
|
|
55654
|
-
o &&
|
|
55655
|
-
let
|
|
55656
|
+
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
|
+
o && u.choices[0].index++;
|
|
55658
|
+
let a = `data: ${JSON.stringify(u)}
|
|
55656
55659
|
|
|
55657
55660
|
`;
|
|
55658
|
-
|
|
55661
|
+
l.enqueue(n.encode(a));
|
|
55659
55662
|
}
|
|
55660
55663
|
} catch {
|
|
55661
|
-
|
|
55664
|
+
l.enqueue(n.encode(g + `
|
|
55662
55665
|
`));
|
|
55663
55666
|
}
|
|
55664
|
-
else
|
|
55667
|
+
else l.enqueue(n.encode(g + `
|
|
55665
55668
|
`));
|
|
55666
55669
|
}
|
|
55667
|
-
} catch (
|
|
55668
|
-
|
|
55670
|
+
} catch (i) {
|
|
55671
|
+
l.error(i);
|
|
55669
55672
|
} finally {
|
|
55670
55673
|
try {
|
|
55671
|
-
|
|
55672
|
-
} catch (
|
|
55673
|
-
console.error("Error releasing reader lock:",
|
|
55674
|
+
d.releaseLock();
|
|
55675
|
+
} catch (i) {
|
|
55676
|
+
console.error("Error releasing reader lock:", i);
|
|
55674
55677
|
}
|
|
55675
|
-
|
|
55678
|
+
l.close();
|
|
55676
55679
|
}
|
|
55677
55680
|
} });
|
|
55678
|
-
return new Response(
|
|
55681
|
+
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" } });
|
|
55679
55682
|
}
|
|
55680
55683
|
return e;
|
|
55681
55684
|
}
|
|
@@ -55699,73 +55702,73 @@ Examples:
|
|
|
55699
55702
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55700
55703
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55701
55704
|
if (!e.body) return e;
|
|
55702
|
-
let t = new TextDecoder(), n = new TextEncoder(), r = -1, o = "",
|
|
55703
|
-
let
|
|
55705
|
+
let t = new TextDecoder(), n = new TextEncoder(), r = -1, o = "", c = new ReadableStream({ async start(l) {
|
|
55706
|
+
let d = e.body.getReader();
|
|
55704
55707
|
try {
|
|
55705
55708
|
for (; ; ) {
|
|
55706
|
-
let { done:
|
|
55707
|
-
if (
|
|
55708
|
-
let
|
|
55709
|
+
let { done: i, value: p } = await d.read();
|
|
55710
|
+
if (i) break;
|
|
55711
|
+
let C = t.decode(p, { stream: true }).split(`
|
|
55709
55712
|
`);
|
|
55710
|
-
for (let g of
|
|
55711
|
-
let
|
|
55712
|
-
if (
|
|
55713
|
-
let
|
|
55714
|
-
if (
|
|
55715
|
-
r =
|
|
55713
|
+
for (let g of C) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
|
|
55714
|
+
let u = JSON.parse(g.slice(6));
|
|
55715
|
+
if (u.choices[0]?.delta?.tool_calls?.length) {
|
|
55716
|
+
let a = u.choices[0].delta.tool_calls[0];
|
|
55717
|
+
if (a.function?.name === "ExitTool") {
|
|
55718
|
+
r = a.index;
|
|
55716
55719
|
continue;
|
|
55717
|
-
} else if (r > -1 &&
|
|
55718
|
-
o +=
|
|
55720
|
+
} else if (r > -1 && a.index === r && a.function.arguments) {
|
|
55721
|
+
o += a.function.arguments;
|
|
55719
55722
|
try {
|
|
55720
|
-
let
|
|
55721
|
-
|
|
55722
|
-
let h = `data: ${JSON.stringify(
|
|
55723
|
+
let y = JSON.parse(o);
|
|
55724
|
+
u.choices = [{ delta: { role: "assistant", content: y.response || "" } }];
|
|
55725
|
+
let h = `data: ${JSON.stringify(u)}
|
|
55723
55726
|
|
|
55724
55727
|
`;
|
|
55725
|
-
|
|
55728
|
+
l.enqueue(n.encode(h));
|
|
55726
55729
|
} catch {
|
|
55727
55730
|
}
|
|
55728
55731
|
continue;
|
|
55729
55732
|
}
|
|
55730
55733
|
}
|
|
55731
|
-
if (
|
|
55732
|
-
let
|
|
55734
|
+
if (u.choices?.[0]?.delta && Object.keys(u.choices[0].delta).length > 0) {
|
|
55735
|
+
let a = `data: ${JSON.stringify(u)}
|
|
55733
55736
|
|
|
55734
55737
|
`;
|
|
55735
|
-
|
|
55738
|
+
l.enqueue(n.encode(a));
|
|
55736
55739
|
}
|
|
55737
55740
|
} catch {
|
|
55738
|
-
|
|
55741
|
+
l.enqueue(n.encode(g + `
|
|
55739
55742
|
`));
|
|
55740
55743
|
}
|
|
55741
|
-
else
|
|
55744
|
+
else l.enqueue(n.encode(g + `
|
|
55742
55745
|
`));
|
|
55743
55746
|
}
|
|
55744
|
-
} catch (
|
|
55745
|
-
|
|
55747
|
+
} catch (i) {
|
|
55748
|
+
l.error(i);
|
|
55746
55749
|
} finally {
|
|
55747
55750
|
try {
|
|
55748
|
-
|
|
55749
|
-
} catch (
|
|
55750
|
-
console.error("Error releasing reader lock:",
|
|
55751
|
+
d.releaseLock();
|
|
55752
|
+
} catch (i) {
|
|
55753
|
+
console.error("Error releasing reader lock:", i);
|
|
55751
55754
|
}
|
|
55752
|
-
|
|
55755
|
+
l.close();
|
|
55753
55756
|
}
|
|
55754
55757
|
} });
|
|
55755
|
-
return new Response(
|
|
55758
|
+
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" } });
|
|
55756
55759
|
}
|
|
55757
55760
|
return e;
|
|
55758
55761
|
}
|
|
55759
55762
|
};
|
|
55760
55763
|
var b = [];
|
|
55761
55764
|
for (let s = 0; s < 256; ++s) b.push((s + 256).toString(16).slice(1));
|
|
55762
|
-
function
|
|
55765
|
+
function fe(s, e = 0) {
|
|
55763
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();
|
|
55764
55767
|
}
|
|
55765
|
-
var
|
|
55766
|
-
var B =
|
|
55768
|
+
var W = new Uint8Array(256);
|
|
55769
|
+
var B = W.length;
|
|
55767
55770
|
function te() {
|
|
55768
|
-
return B >
|
|
55771
|
+
return B > W.length - 16 && ((0, import_crypto.randomFillSync)(W), B = 0), W.slice(B, B += 16);
|
|
55769
55772
|
}
|
|
55770
55773
|
var ne = { randomUUID: import_crypto2.randomUUID };
|
|
55771
55774
|
function Re(s, e, t) {
|
|
@@ -55778,15 +55781,15 @@ function Re(s, e, t) {
|
|
|
55778
55781
|
for (let r = 0; r < 16; ++r) e[t + r] = n[r];
|
|
55779
55782
|
return e;
|
|
55780
55783
|
}
|
|
55781
|
-
return
|
|
55784
|
+
return fe(n);
|
|
55782
55785
|
}
|
|
55783
55786
|
var I = Re;
|
|
55784
|
-
var
|
|
55787
|
+
var z = class {
|
|
55785
55788
|
name = "openrouter";
|
|
55786
|
-
transformRequestIn(e) {
|
|
55789
|
+
async transformRequestIn(e) {
|
|
55787
55790
|
return e.model.includes("claude") || e.messages.forEach((t) => {
|
|
55788
55791
|
Array.isArray(t.content) ? t.content.forEach((n) => {
|
|
55789
|
-
n.cache_control && delete n.cache_control;
|
|
55792
|
+
n.cache_control && delete n.cache_control, n.type === "image_url" && (n.image_url.url.startsWith("http") || (n.image_url.url = `data:${n.media_type};base64,${n.image_url.url}`), delete n.media_type);
|
|
55790
55793
|
}) : t.cache_control && delete t.cache_control;
|
|
55791
55794
|
}), e;
|
|
55792
55795
|
}
|
|
@@ -55796,109 +55799,109 @@ var V = class {
|
|
|
55796
55799
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55797
55800
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55798
55801
|
if (!e.body) return e;
|
|
55799
|
-
let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "",
|
|
55800
|
-
let
|
|
55801
|
-
let h =
|
|
55802
|
+
let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "", c = false, l = false, d = "", i = new ReadableStream({ async start(p) {
|
|
55803
|
+
let _ = e.body.getReader(), C = (u, a, y) => {
|
|
55804
|
+
let h = u.split(`
|
|
55802
55805
|
`);
|
|
55803
|
-
for (let
|
|
55806
|
+
for (let f of h) f.trim() && a.enqueue(y.encode(f + `
|
|
55804
55807
|
`));
|
|
55805
|
-
}, g = (
|
|
55806
|
-
let { controller:
|
|
55807
|
-
if (
|
|
55808
|
-
let
|
|
55808
|
+
}, g = (u, a) => {
|
|
55809
|
+
let { controller: y, encoder: h } = a;
|
|
55810
|
+
if (u.startsWith("data: ") && u.trim() !== "data: [DONE]") {
|
|
55811
|
+
let f = u.slice(6);
|
|
55809
55812
|
try {
|
|
55810
|
-
let m = JSON.parse(
|
|
55811
|
-
if (m.usage && (
|
|
55813
|
+
let m = JSON.parse(f);
|
|
55814
|
+
if (m.usage && (v("usage", m.usage, l), m.choices[0].finish_reason = l ? "tool_calls" : "stop"), m.choices?.[0]?.finish_reason === "error" && y.enqueue(h.encode(`data: ${JSON.stringify({ error: m.choices?.[0].error })}
|
|
55812
55815
|
|
|
55813
|
-
`)), m.choices?.[0]?.delta?.content && !
|
|
55814
|
-
|
|
55816
|
+
`)), m.choices?.[0]?.delta?.content && !a.hasTextContent() && a.setHasTextContent(true), m.choices?.[0]?.delta?.reasoning) {
|
|
55817
|
+
a.appendReasoningContent(m.choices[0].delta.reasoning);
|
|
55815
55818
|
let x = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, thinking: { content: m.choices[0].delta.reasoning } } }] };
|
|
55816
55819
|
x.choices?.[0]?.delta && delete x.choices[0].delta.reasoning;
|
|
55817
55820
|
let R = `data: ${JSON.stringify(x)}
|
|
55818
55821
|
|
|
55819
55822
|
`;
|
|
55820
|
-
|
|
55823
|
+
y.enqueue(h.encode(R));
|
|
55821
55824
|
return;
|
|
55822
55825
|
}
|
|
55823
|
-
if (m.choices?.[0]?.delta?.content &&
|
|
55824
|
-
|
|
55825
|
-
let x = Date.now().toString(), R = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, content: null, thinking: { content:
|
|
55826
|
+
if (m.choices?.[0]?.delta?.content && a.reasoningContent() && !a.isReasoningComplete()) {
|
|
55827
|
+
a.setReasoningComplete(true);
|
|
55828
|
+
let x = Date.now().toString(), R = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, content: null, thinking: { content: a.reasoningContent(), signature: x } } }] };
|
|
55826
55829
|
R.choices?.[0]?.delta && delete R.choices[0].delta.reasoning;
|
|
55827
55830
|
let X = `data: ${JSON.stringify(R)}
|
|
55828
55831
|
|
|
55829
55832
|
`;
|
|
55830
|
-
|
|
55833
|
+
y.enqueue(h.encode(X));
|
|
55831
55834
|
}
|
|
55832
55835
|
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) => {
|
|
55833
55836
|
x.id = `call_${I()}`;
|
|
55834
|
-
}), m.choices?.[0]?.delta?.tool_calls?.length && !
|
|
55837
|
+
}), m.choices?.[0]?.delta?.tool_calls?.length && !l && (v("hasToolCall", true), l = 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);
|
|
55835
55838
|
let T = `data: ${JSON.stringify(m)}
|
|
55836
55839
|
|
|
55837
55840
|
`;
|
|
55838
|
-
|
|
55841
|
+
y.enqueue(h.encode(T));
|
|
55839
55842
|
} catch {
|
|
55840
|
-
|
|
55843
|
+
y.enqueue(h.encode(u + `
|
|
55841
55844
|
`));
|
|
55842
55845
|
}
|
|
55843
|
-
} else
|
|
55846
|
+
} else y.enqueue(h.encode(u + `
|
|
55844
55847
|
`));
|
|
55845
55848
|
};
|
|
55846
55849
|
try {
|
|
55847
55850
|
for (; ; ) {
|
|
55848
|
-
let { done:
|
|
55849
|
-
if (
|
|
55850
|
-
|
|
55851
|
+
let { done: u, value: a } = await _.read();
|
|
55852
|
+
if (u) {
|
|
55853
|
+
d.trim() && C(d, p, n);
|
|
55851
55854
|
break;
|
|
55852
55855
|
}
|
|
55853
|
-
if (!
|
|
55854
|
-
let
|
|
55856
|
+
if (!a || a.length === 0) continue;
|
|
55857
|
+
let y;
|
|
55855
55858
|
try {
|
|
55856
|
-
|
|
55857
|
-
} catch (
|
|
55858
|
-
console.warn("Failed to decode chunk",
|
|
55859
|
+
y = t.decode(a, { stream: true });
|
|
55860
|
+
} catch (f) {
|
|
55861
|
+
console.warn("Failed to decode chunk", f);
|
|
55859
55862
|
continue;
|
|
55860
55863
|
}
|
|
55861
|
-
if (
|
|
55862
|
-
if (
|
|
55864
|
+
if (y.length === 0) continue;
|
|
55865
|
+
if (d += y, d.length > 1e6) {
|
|
55863
55866
|
console.warn("Buffer size exceeds limit, processing partial data");
|
|
55864
|
-
let
|
|
55867
|
+
let f = d.split(`
|
|
55865
55868
|
`);
|
|
55866
|
-
|
|
55867
|
-
for (let m of
|
|
55868
|
-
g(m, { controller:
|
|
55869
|
+
d = f.pop() || "";
|
|
55870
|
+
for (let m of f) if (m.trim()) try {
|
|
55871
|
+
g(m, { controller: p, encoder: n, hasTextContent: () => r, setHasTextContent: (T) => r = T, reasoningContent: () => o, appendReasoningContent: (T) => o += T, isReasoningComplete: () => c, setReasoningComplete: (T) => c = T });
|
|
55869
55872
|
} catch (T) {
|
|
55870
|
-
console.error("Error processing line:", m, T),
|
|
55873
|
+
console.error("Error processing line:", m, T), p.enqueue(n.encode(m + `
|
|
55871
55874
|
`));
|
|
55872
55875
|
}
|
|
55873
55876
|
continue;
|
|
55874
55877
|
}
|
|
55875
|
-
let h =
|
|
55878
|
+
let h = d.split(`
|
|
55876
55879
|
`);
|
|
55877
|
-
|
|
55878
|
-
for (let
|
|
55879
|
-
g(
|
|
55880
|
+
d = h.pop() || "";
|
|
55881
|
+
for (let f of h) if (f.trim()) try {
|
|
55882
|
+
g(f, { controller: p, encoder: n, hasTextContent: () => r, setHasTextContent: (m) => r = m, reasoningContent: () => o, appendReasoningContent: (m) => o += m, isReasoningComplete: () => c, setReasoningComplete: (m) => c = m });
|
|
55880
55883
|
} catch (m) {
|
|
55881
|
-
console.error("Error processing line:",
|
|
55884
|
+
console.error("Error processing line:", f, m), p.enqueue(n.encode(f + `
|
|
55882
55885
|
`));
|
|
55883
55886
|
}
|
|
55884
55887
|
}
|
|
55885
|
-
} catch (
|
|
55886
|
-
console.error("Stream error:",
|
|
55888
|
+
} catch (u) {
|
|
55889
|
+
console.error("Stream error:", u), p.error(u);
|
|
55887
55890
|
} finally {
|
|
55888
55891
|
try {
|
|
55889
|
-
|
|
55890
|
-
} catch (
|
|
55891
|
-
console.error("Error releasing reader lock:",
|
|
55892
|
+
_.releaseLock();
|
|
55893
|
+
} catch (u) {
|
|
55894
|
+
console.error("Error releasing reader lock:", u);
|
|
55892
55895
|
}
|
|
55893
|
-
|
|
55896
|
+
p.close();
|
|
55894
55897
|
}
|
|
55895
55898
|
} });
|
|
55896
|
-
return new Response(
|
|
55899
|
+
return new Response(i, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
55897
55900
|
}
|
|
55898
55901
|
return e;
|
|
55899
55902
|
}
|
|
55900
55903
|
};
|
|
55901
|
-
var
|
|
55904
|
+
var V = class {
|
|
55902
55905
|
constructor(e) {
|
|
55903
55906
|
this.options = e;
|
|
55904
55907
|
this.max_tokens = this.options?.max_tokens;
|
|
@@ -55926,84 +55929,84 @@ var G = class {
|
|
|
55926
55929
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55927
55930
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55928
55931
|
if (!e.body) return e;
|
|
55929
|
-
let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "",
|
|
55930
|
-
let
|
|
55931
|
-
let
|
|
55932
|
+
let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "", c = false, l = "", d = new ReadableStream({ async start(i) {
|
|
55933
|
+
let p = e.body.getReader(), _ = (g, u, a) => {
|
|
55934
|
+
let y = g.split(`
|
|
55932
55935
|
`);
|
|
55933
|
-
for (let h of
|
|
55936
|
+
for (let h of y) h.trim() && u.enqueue(a.encode(h + `
|
|
55934
55937
|
`));
|
|
55935
|
-
},
|
|
55936
|
-
let { controller:
|
|
55938
|
+
}, C = (g, u) => {
|
|
55939
|
+
let { controller: a, encoder: y } = u;
|
|
55937
55940
|
if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") {
|
|
55938
55941
|
let h = g.slice(6);
|
|
55939
55942
|
try {
|
|
55940
|
-
let
|
|
55941
|
-
if (
|
|
55942
|
-
|
|
55943
|
+
let f = JSON.parse(h);
|
|
55944
|
+
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((T) => {
|
|
55943
55946
|
T.id = `call_${I()}`;
|
|
55944
|
-
}),
|
|
55945
|
-
let m = `data: ${JSON.stringify(
|
|
55947
|
+
}), 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
|
+
let m = `data: ${JSON.stringify(f)}
|
|
55946
55949
|
|
|
55947
55950
|
`;
|
|
55948
|
-
|
|
55951
|
+
a.enqueue(y.encode(m));
|
|
55949
55952
|
} catch {
|
|
55950
|
-
|
|
55953
|
+
a.enqueue(y.encode(g + `
|
|
55951
55954
|
`));
|
|
55952
55955
|
}
|
|
55953
|
-
} else
|
|
55956
|
+
} else a.enqueue(y.encode(g + `
|
|
55954
55957
|
`));
|
|
55955
55958
|
};
|
|
55956
55959
|
try {
|
|
55957
55960
|
for (; ; ) {
|
|
55958
|
-
let { done: g, value:
|
|
55961
|
+
let { done: g, value: u } = await p.read();
|
|
55959
55962
|
if (g) {
|
|
55960
|
-
|
|
55963
|
+
l.trim() && _(l, i, n);
|
|
55961
55964
|
break;
|
|
55962
55965
|
}
|
|
55963
|
-
if (!
|
|
55964
|
-
let
|
|
55966
|
+
if (!u || u.length === 0) continue;
|
|
55967
|
+
let a;
|
|
55965
55968
|
try {
|
|
55966
|
-
|
|
55969
|
+
a = t.decode(u, { stream: true });
|
|
55967
55970
|
} catch (h) {
|
|
55968
55971
|
console.warn("Failed to decode chunk", h);
|
|
55969
55972
|
continue;
|
|
55970
55973
|
}
|
|
55971
|
-
if (
|
|
55972
|
-
if (
|
|
55974
|
+
if (a.length === 0) continue;
|
|
55975
|
+
if (l += a, l.length > 1e6) {
|
|
55973
55976
|
console.warn("Buffer size exceeds limit, processing partial data");
|
|
55974
|
-
let h =
|
|
55977
|
+
let h = l.split(`
|
|
55975
55978
|
`);
|
|
55976
|
-
|
|
55977
|
-
for (let
|
|
55978
|
-
|
|
55979
|
+
l = h.pop() || "";
|
|
55980
|
+
for (let f of h) if (f.trim()) try {
|
|
55981
|
+
C(f, { controller: i, encoder: n, hasTextContent: () => r, setHasTextContent: (m) => r = m, reasoningContent: () => o, appendReasoningContent: (m) => o += m, isReasoningComplete: () => c, setReasoningComplete: (m) => c = m });
|
|
55979
55982
|
} catch (m) {
|
|
55980
|
-
console.error("Error processing line:",
|
|
55983
|
+
console.error("Error processing line:", f, m), i.enqueue(n.encode(f + `
|
|
55981
55984
|
`));
|
|
55982
55985
|
}
|
|
55983
55986
|
continue;
|
|
55984
55987
|
}
|
|
55985
|
-
let
|
|
55988
|
+
let y = l.split(`
|
|
55986
55989
|
`);
|
|
55987
|
-
|
|
55988
|
-
for (let h of
|
|
55989
|
-
|
|
55990
|
-
} catch (
|
|
55991
|
-
console.error("Error processing line:", h,
|
|
55990
|
+
l = y.pop() || "";
|
|
55991
|
+
for (let h of y) if (h.trim()) try {
|
|
55992
|
+
C(h, { controller: i, encoder: n, hasTextContent: () => r, setHasTextContent: (f) => r = f, reasoningContent: () => o, appendReasoningContent: (f) => o += f, isReasoningComplete: () => c, setReasoningComplete: (f) => c = f });
|
|
55993
|
+
} catch (f) {
|
|
55994
|
+
console.error("Error processing line:", h, f), i.enqueue(n.encode(h + `
|
|
55992
55995
|
`));
|
|
55993
55996
|
}
|
|
55994
55997
|
}
|
|
55995
55998
|
} catch (g) {
|
|
55996
|
-
console.error("Stream error:", g),
|
|
55999
|
+
console.error("Stream error:", g), i.error(g);
|
|
55997
56000
|
} finally {
|
|
55998
56001
|
try {
|
|
55999
|
-
|
|
56002
|
+
p.releaseLock();
|
|
56000
56003
|
} catch (g) {
|
|
56001
56004
|
console.error("Error releasing reader lock:", g);
|
|
56002
56005
|
}
|
|
56003
|
-
|
|
56006
|
+
i.close();
|
|
56004
56007
|
}
|
|
56005
56008
|
} });
|
|
56006
|
-
return new Response(
|
|
56009
|
+
return new Response(d, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
56007
56010
|
}
|
|
56008
56011
|
return e;
|
|
56009
56012
|
}
|
|
@@ -56018,14 +56021,14 @@ var K = class {
|
|
|
56018
56021
|
}), e;
|
|
56019
56022
|
}
|
|
56020
56023
|
};
|
|
56021
|
-
var pe = { AnthropicTransformer: U, GeminiTransformer: J, DeepseekTransformer: j, TooluseTransformer: D, OpenrouterTransformer:
|
|
56024
|
+
var pe = { AnthropicTransformer: U, GeminiTransformer: J, DeepseekTransformer: j, TooluseTransformer: D, OpenrouterTransformer: z, MaxTokenTransformer: V, GroqTransformer: G, CleancacheTransformer: K };
|
|
56022
56025
|
var Y = class {
|
|
56023
56026
|
constructor(e) {
|
|
56024
56027
|
this.configService = e;
|
|
56025
56028
|
}
|
|
56026
56029
|
transformers = /* @__PURE__ */ new Map();
|
|
56027
56030
|
registerTransformer(e, t) {
|
|
56028
|
-
this.transformers.set(e, t),
|
|
56031
|
+
this.transformers.set(e, t), v(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
|
|
56029
56032
|
}
|
|
56030
56033
|
getTransformer(e) {
|
|
56031
56034
|
return this.transformers.get(e);
|
|
@@ -56055,7 +56058,7 @@ var Y = class {
|
|
|
56055
56058
|
try {
|
|
56056
56059
|
let t = import_node_module.default._load;
|
|
56057
56060
|
if (import_node_module.default._load = function(n, r, o) {
|
|
56058
|
-
return n === "claude-code-router" ? { log:
|
|
56061
|
+
return n === "claude-code-router" ? { log: v } : t.apply(import_node_module.default, arguments);
|
|
56059
56062
|
}, e.path) {
|
|
56060
56063
|
let n = Z(Z.resolve(e.path));
|
|
56061
56064
|
if (n) {
|
|
@@ -56066,14 +56069,14 @@ var Y = class {
|
|
|
56066
56069
|
}
|
|
56067
56070
|
return false;
|
|
56068
56071
|
} catch (t) {
|
|
56069
|
-
return
|
|
56072
|
+
return v(`load transformer (${e.path}) error:`, t.message, t.stack), false;
|
|
56070
56073
|
}
|
|
56071
56074
|
}
|
|
56072
56075
|
async initialize() {
|
|
56073
56076
|
try {
|
|
56074
56077
|
await this.registerDefaultTransformersInternal(), await this.loadFromConfig();
|
|
56075
56078
|
} catch (e) {
|
|
56076
|
-
|
|
56079
|
+
v("TransformerService init error:", e);
|
|
56077
56080
|
}
|
|
56078
56081
|
}
|
|
56079
56082
|
async registerDefaultTransformersInternal() {
|
|
@@ -56086,7 +56089,7 @@ var Y = class {
|
|
|
56086
56089
|
}
|
|
56087
56090
|
});
|
|
56088
56091
|
} catch (e) {
|
|
56089
|
-
|
|
56092
|
+
v("transformer regist error:", e);
|
|
56090
56093
|
}
|
|
56091
56094
|
}
|
|
56092
56095
|
async loadFromConfig() {
|
|
@@ -56095,7 +56098,7 @@ var Y = class {
|
|
|
56095
56098
|
}
|
|
56096
56099
|
};
|
|
56097
56100
|
function Se() {
|
|
56098
|
-
let s = (0, import_fastify.default)({});
|
|
56101
|
+
let s = (0, import_fastify.default)({ bodyLimit: 52428800 });
|
|
56099
56102
|
return s.setErrorHandler(le), s.register(import_cors.default), s;
|
|
56100
56103
|
}
|
|
56101
56104
|
var re = class {
|
|
@@ -56121,21 +56124,21 @@ var re = class {
|
|
|
56121
56124
|
try {
|
|
56122
56125
|
let o = n.body;
|
|
56123
56126
|
if (!o || !o.model) return r.code(400).send({ error: "Missing model in request body" });
|
|
56124
|
-
let [
|
|
56125
|
-
o.model =
|
|
56127
|
+
let [c, l] = o.model.split(",");
|
|
56128
|
+
o.model = l, n.provider = c;
|
|
56126
56129
|
return;
|
|
56127
56130
|
} catch (o) {
|
|
56128
56131
|
return n.log.error("Error in modelProviderMiddleware:", o), r.code(500).send({ error: "Internal server error" });
|
|
56129
56132
|
}
|
|
56130
|
-
}), this.app.register(
|
|
56133
|
+
}), this.app.register(ue);
|
|
56131
56134
|
let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
|
|
56132
|
-
|
|
56135
|
+
v(`\u{1F680} LLMs API server listening on ${e}`);
|
|
56133
56136
|
let t = async (n) => {
|
|
56134
|
-
|
|
56137
|
+
v(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
|
|
56135
56138
|
};
|
|
56136
56139
|
process.on("SIGINT", () => t("SIGINT")), process.on("SIGTERM", () => t("SIGTERM"));
|
|
56137
56140
|
} catch (e) {
|
|
56138
|
-
|
|
56141
|
+
v(`Error starting server: ${e}`), process.exit(1);
|
|
56139
56142
|
}
|
|
56140
56143
|
}
|
|
56141
56144
|
};
|
|
@@ -56335,14 +56338,15 @@ function getServicePid() {
|
|
|
56335
56338
|
return null;
|
|
56336
56339
|
}
|
|
56337
56340
|
}
|
|
56338
|
-
function getServiceInfo() {
|
|
56341
|
+
async function getServiceInfo() {
|
|
56339
56342
|
const pid = getServicePid();
|
|
56340
56343
|
const running = isServiceRunning();
|
|
56344
|
+
const config = await readConfigFile();
|
|
56341
56345
|
return {
|
|
56342
56346
|
running,
|
|
56343
56347
|
pid,
|
|
56344
|
-
port:
|
|
56345
|
-
endpoint:
|
|
56348
|
+
port: config.PORT,
|
|
56349
|
+
endpoint: `http://127.0.0.1:${config.PORT}`,
|
|
56346
56350
|
pidFile: PID_FILE,
|
|
56347
56351
|
referenceCount: getReferenceCount()
|
|
56348
56352
|
};
|
|
@@ -56383,7 +56387,7 @@ async function run(options = {}) {
|
|
|
56383
56387
|
"\u26A0\uFE0F API key is not set. HOST is forced to 127.0.0.1."
|
|
56384
56388
|
);
|
|
56385
56389
|
}
|
|
56386
|
-
const port =
|
|
56390
|
+
const port = config.PORT || 3456;
|
|
56387
56391
|
savePid(process.pid);
|
|
56388
56392
|
process.on("SIGINT", () => {
|
|
56389
56393
|
console.log("Received SIGINT, cleaning up...");
|
|
@@ -56419,8 +56423,8 @@ async function run(options = {}) {
|
|
|
56419
56423
|
}
|
|
56420
56424
|
|
|
56421
56425
|
// src/utils/status.ts
|
|
56422
|
-
function showStatus() {
|
|
56423
|
-
const info = getServiceInfo();
|
|
56426
|
+
async function showStatus() {
|
|
56427
|
+
const info = await getServiceInfo();
|
|
56424
56428
|
console.log("\n\u{1F4CA} Claude Code Router Status");
|
|
56425
56429
|
console.log("\u2550".repeat(40));
|
|
56426
56430
|
if (info.running) {
|
|
@@ -56474,7 +56478,7 @@ async function executeCodeCommand(args = []) {
|
|
|
56474
56478
|
const env = {
|
|
56475
56479
|
...process.env,
|
|
56476
56480
|
ANTHROPIC_AUTH_TOKEN: "test",
|
|
56477
|
-
ANTHROPIC_BASE_URL: `http://127.0.0.1
|
|
56481
|
+
ANTHROPIC_BASE_URL: `http://127.0.0.1:${config.PORT || 3456}`,
|
|
56478
56482
|
API_TIMEOUT_MS: "600000"
|
|
56479
56483
|
};
|
|
56480
56484
|
if (config?.APIKEY) {
|
|
@@ -56504,7 +56508,7 @@ async function executeCodeCommand(args = []) {
|
|
|
56504
56508
|
}
|
|
56505
56509
|
|
|
56506
56510
|
// package.json
|
|
56507
|
-
var version = "1.0.
|
|
56511
|
+
var version = "1.0.22";
|
|
56508
56512
|
|
|
56509
56513
|
// src/cli.ts
|
|
56510
56514
|
var import_child_process2 = require("child_process");
|
|
@@ -56565,7 +56569,7 @@ async function main() {
|
|
|
56565
56569
|
}
|
|
56566
56570
|
break;
|
|
56567
56571
|
case "status":
|
|
56568
|
-
showStatus();
|
|
56572
|
+
await showStatus();
|
|
56569
56573
|
break;
|
|
56570
56574
|
case "code":
|
|
56571
56575
|
if (!isServiceRunning()) {
|