@musistudio/claude-code-router 1.0.19 → 1.0.20
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 +168 -202
- package/README_zh.md +312 -0
- package/config.example.json +78 -0
- package/dist/cli.js +690 -514
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -2150,20 +2150,20 @@ var require_hooks = __commonJS({
|
|
|
2150
2150
|
this.validate(hook, fn);
|
|
2151
2151
|
this[hook].push(fn);
|
|
2152
2152
|
};
|
|
2153
|
-
function buildHooks(
|
|
2153
|
+
function buildHooks(h) {
|
|
2154
2154
|
const hooks = new Hooks();
|
|
2155
|
-
hooks.onRequest =
|
|
2156
|
-
hooks.preParsing =
|
|
2157
|
-
hooks.preValidation =
|
|
2158
|
-
hooks.preSerialization =
|
|
2159
|
-
hooks.preHandler =
|
|
2160
|
-
hooks.onSend =
|
|
2161
|
-
hooks.onResponse =
|
|
2162
|
-
hooks.onError =
|
|
2163
|
-
hooks.onRoute =
|
|
2164
|
-
hooks.onRegister =
|
|
2165
|
-
hooks.onTimeout =
|
|
2166
|
-
hooks.onRequestAbort =
|
|
2155
|
+
hooks.onRequest = h.onRequest.slice();
|
|
2156
|
+
hooks.preParsing = h.preParsing.slice();
|
|
2157
|
+
hooks.preValidation = h.preValidation.slice();
|
|
2158
|
+
hooks.preSerialization = h.preSerialization.slice();
|
|
2159
|
+
hooks.preHandler = h.preHandler.slice();
|
|
2160
|
+
hooks.onSend = h.onSend.slice();
|
|
2161
|
+
hooks.onResponse = h.onResponse.slice();
|
|
2162
|
+
hooks.onError = h.onError.slice();
|
|
2163
|
+
hooks.onRoute = h.onRoute.slice();
|
|
2164
|
+
hooks.onRegister = h.onRegister.slice();
|
|
2165
|
+
hooks.onTimeout = h.onTimeout.slice();
|
|
2166
|
+
hooks.onRequestAbort = h.onRequestAbort.slice();
|
|
2167
2167
|
hooks.onReady = [];
|
|
2168
2168
|
hooks.onListen = [];
|
|
2169
2169
|
hooks.preClose = [];
|
|
@@ -2782,7 +2782,7 @@ var require_validation = __commonJS({
|
|
|
2782
2782
|
headersSchemaLowerCase[k] = headers[k];
|
|
2783
2783
|
});
|
|
2784
2784
|
if (headersSchemaLowerCase.required instanceof Array) {
|
|
2785
|
-
headersSchemaLowerCase.required = headersSchemaLowerCase.required.map((
|
|
2785
|
+
headersSchemaLowerCase.required = headersSchemaLowerCase.required.map((h) => h.toLowerCase());
|
|
2786
2786
|
}
|
|
2787
2787
|
if (headers.properties) {
|
|
2788
2788
|
headersSchemaLowerCase.properties = {};
|
|
@@ -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);
|
|
@@ -9200,8 +9200,8 @@ var require_reply = __commonJS({
|
|
|
9200
9200
|
responseTime
|
|
9201
9201
|
}, "request completed");
|
|
9202
9202
|
}
|
|
9203
|
-
function buildReply(
|
|
9204
|
-
const props =
|
|
9203
|
+
function buildReply(R2) {
|
|
9204
|
+
const props = R2.props.slice();
|
|
9205
9205
|
function _Reply(res, request, log2) {
|
|
9206
9206
|
this.raw = res;
|
|
9207
9207
|
this[kReplyIsError] = false;
|
|
@@ -9220,9 +9220,9 @@ var require_reply = __commonJS({
|
|
|
9220
9220
|
this[prop.key] = prop.value;
|
|
9221
9221
|
}
|
|
9222
9222
|
}
|
|
9223
|
-
Object.setPrototypeOf(_Reply.prototype,
|
|
9224
|
-
Object.setPrototypeOf(_Reply,
|
|
9225
|
-
_Reply.parent =
|
|
9223
|
+
Object.setPrototypeOf(_Reply.prototype, R2.prototype);
|
|
9224
|
+
Object.setPrototypeOf(_Reply, R2);
|
|
9225
|
+
_Reply.parent = R2;
|
|
9226
9226
|
_Reply.props = props;
|
|
9227
9227
|
return _Reply;
|
|
9228
9228
|
}
|
|
@@ -10300,14 +10300,14 @@ var require_request = __commonJS({
|
|
|
10300
10300
|
}
|
|
10301
10301
|
return proxyAddr.compile(tp);
|
|
10302
10302
|
}
|
|
10303
|
-
function buildRequest(
|
|
10303
|
+
function buildRequest(R2, trustProxy) {
|
|
10304
10304
|
if (trustProxy) {
|
|
10305
|
-
return buildRequestWithTrustProxy(
|
|
10305
|
+
return buildRequestWithTrustProxy(R2, trustProxy);
|
|
10306
10306
|
}
|
|
10307
|
-
return buildRegularRequest(
|
|
10307
|
+
return buildRegularRequest(R2);
|
|
10308
10308
|
}
|
|
10309
|
-
function buildRegularRequest(
|
|
10310
|
-
const props =
|
|
10309
|
+
function buildRegularRequest(R2) {
|
|
10310
|
+
const props = R2.props.slice();
|
|
10311
10311
|
function _Request(id2, params, req, query, log2, context) {
|
|
10312
10312
|
this.id = id2;
|
|
10313
10313
|
this[kRouteContext] = context;
|
|
@@ -10322,18 +10322,18 @@ var require_request = __commonJS({
|
|
|
10322
10322
|
this[prop.key] = prop.value;
|
|
10323
10323
|
}
|
|
10324
10324
|
}
|
|
10325
|
-
Object.setPrototypeOf(_Request.prototype,
|
|
10326
|
-
Object.setPrototypeOf(_Request,
|
|
10325
|
+
Object.setPrototypeOf(_Request.prototype, R2.prototype);
|
|
10326
|
+
Object.setPrototypeOf(_Request, R2);
|
|
10327
10327
|
_Request.props = props;
|
|
10328
|
-
_Request.parent =
|
|
10328
|
+
_Request.parent = R2;
|
|
10329
10329
|
return _Request;
|
|
10330
10330
|
}
|
|
10331
10331
|
function getLastEntryInMultiHeaderValue(headerValue) {
|
|
10332
10332
|
const lastIndex = headerValue.lastIndexOf(",");
|
|
10333
10333
|
return lastIndex === -1 ? headerValue.trim() : headerValue.slice(lastIndex + 1).trim();
|
|
10334
10334
|
}
|
|
10335
|
-
function buildRequestWithTrustProxy(
|
|
10336
|
-
const _Request = buildRegularRequest(
|
|
10335
|
+
function buildRequestWithTrustProxy(R2, trustProxy) {
|
|
10336
|
+
const _Request = buildRegularRequest(R2);
|
|
10337
10337
|
const proxyFn = getTrustProxyFn(trustProxy);
|
|
10338
10338
|
_Request[kHasBeenDecorated] = true;
|
|
10339
10339
|
Object.defineProperties(_Request.prototype, {
|
|
@@ -15916,14 +15916,14 @@ var require_core = __commonJS({
|
|
|
15916
15916
|
};
|
|
15917
15917
|
var MAX_EXPRESSION = 200;
|
|
15918
15918
|
function requiredOptions(o) {
|
|
15919
|
-
var _a, _b, _c, _d,
|
|
15919
|
+
var _a, _b, _c, _d, _e2, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
15920
15920
|
const s = o.strict;
|
|
15921
15921
|
const _optz = (_a = o.code) === null || _a === void 0 ? void 0 : _a.optimize;
|
|
15922
15922
|
const optimize = _optz === true || _optz === void 0 ? 1 : _optz || 0;
|
|
15923
15923
|
const regExp = (_c = (_b = o.code) === null || _b === void 0 ? void 0 : _b.regExp) !== null && _c !== void 0 ? _c : defaultRegExp;
|
|
15924
15924
|
const uriResolver = (_d = o.uriResolver) !== null && _d !== void 0 ? _d : uri_1.default;
|
|
15925
15925
|
return {
|
|
15926
|
-
strictSchema: (_f = (
|
|
15926
|
+
strictSchema: (_f = (_e2 = o.strictSchema) !== null && _e2 !== void 0 ? _e2 : s) !== null && _f !== void 0 ? _f : true,
|
|
15927
15927
|
strictNumbers: (_h = (_g = o.strictNumbers) !== null && _g !== void 0 ? _g : s) !== null && _h !== void 0 ? _h : true,
|
|
15928
15928
|
strictTypes: (_k = (_j = o.strictTypes) !== null && _j !== void 0 ? _j : s) !== null && _k !== void 0 ? _k : "log",
|
|
15929
15929
|
strictTuples: (_m = (_l = o.strictTuples) !== null && _l !== void 0 ? _l : s) !== null && _m !== void 0 ? _m : "log",
|
|
@@ -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)
|
|
@@ -23504,12 +23504,12 @@ var require_re = __commonJS({
|
|
|
23504
23504
|
} = require_constants2();
|
|
23505
23505
|
var debug = require_debug2();
|
|
23506
23506
|
exports2 = module2.exports = {};
|
|
23507
|
-
var
|
|
23507
|
+
var re2 = exports2.re = [];
|
|
23508
23508
|
var safeRe = exports2.safeRe = [];
|
|
23509
23509
|
var src = exports2.src = [];
|
|
23510
23510
|
var safeSrc = exports2.safeSrc = [];
|
|
23511
23511
|
var t = exports2.t = {};
|
|
23512
|
-
var
|
|
23512
|
+
var R2 = 0;
|
|
23513
23513
|
var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
|
|
23514
23514
|
var safeRegexReplacements = [
|
|
23515
23515
|
["\\s", 1],
|
|
@@ -23524,12 +23524,12 @@ var require_re = __commonJS({
|
|
|
23524
23524
|
};
|
|
23525
23525
|
var createToken = (name, value, isGlobal) => {
|
|
23526
23526
|
const safe = makeSafeRegex(value);
|
|
23527
|
-
const index =
|
|
23527
|
+
const index = R2++;
|
|
23528
23528
|
debug(name, index, value);
|
|
23529
23529
|
t[name] = index;
|
|
23530
23530
|
src[index] = value;
|
|
23531
23531
|
safeSrc[index] = safe;
|
|
23532
|
-
|
|
23532
|
+
re2[index] = new RegExp(value, isGlobal ? "g" : void 0);
|
|
23533
23533
|
safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
|
|
23534
23534
|
};
|
|
23535
23535
|
createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
|
|
@@ -23628,7 +23628,7 @@ var require_semver = __commonJS({
|
|
|
23628
23628
|
"use strict";
|
|
23629
23629
|
var debug = require_debug2();
|
|
23630
23630
|
var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants2();
|
|
23631
|
-
var { safeRe:
|
|
23631
|
+
var { safeRe: re2, t } = require_re();
|
|
23632
23632
|
var parseOptions = require_parse_options();
|
|
23633
23633
|
var { compareIdentifiers } = require_identifiers();
|
|
23634
23634
|
var SemVer = class _SemVer {
|
|
@@ -23652,7 +23652,7 @@ var require_semver = __commonJS({
|
|
|
23652
23652
|
this.options = options;
|
|
23653
23653
|
this.loose = !!options.loose;
|
|
23654
23654
|
this.includePrerelease = !!options.includePrerelease;
|
|
23655
|
-
const m = version2.trim().match(options.loose ?
|
|
23655
|
+
const m = version2.trim().match(options.loose ? re2[t.LOOSE] : re2[t.FULL]);
|
|
23656
23656
|
if (!m) {
|
|
23657
23657
|
throw new TypeError(`Invalid Version: ${version2}`);
|
|
23658
23658
|
}
|
|
@@ -23773,7 +23773,7 @@ var require_semver = __commonJS({
|
|
|
23773
23773
|
throw new Error("invalid increment argument: identifier is empty");
|
|
23774
23774
|
}
|
|
23775
23775
|
if (identifier) {
|
|
23776
|
-
const match = `-${identifier}`.match(this.options.loose ?
|
|
23776
|
+
const match = `-${identifier}`.match(this.options.loose ? re2[t.PRERELEASELOOSE] : re2[t.PRERELEASE]);
|
|
23777
23777
|
if (!match || match[1] !== identifier) {
|
|
23778
23778
|
throw new Error(`invalid identifier: ${identifier}`);
|
|
23779
23779
|
}
|
|
@@ -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
|
}
|
|
@@ -24222,7 +24222,7 @@ var require_coerce = __commonJS({
|
|
|
24222
24222
|
"use strict";
|
|
24223
24223
|
var SemVer = require_semver();
|
|
24224
24224
|
var parse = require_parse3();
|
|
24225
|
-
var { safeRe:
|
|
24225
|
+
var { safeRe: re2, t } = require_re();
|
|
24226
24226
|
var coerce = (version2, options) => {
|
|
24227
24227
|
if (version2 instanceof SemVer) {
|
|
24228
24228
|
return version2;
|
|
@@ -24236,9 +24236,9 @@ var require_coerce = __commonJS({
|
|
|
24236
24236
|
options = options || {};
|
|
24237
24237
|
let match = null;
|
|
24238
24238
|
if (!options.rtl) {
|
|
24239
|
-
match = version2.match(options.includePrerelease ?
|
|
24239
|
+
match = version2.match(options.includePrerelease ? re2[t.COERCEFULL] : re2[t.COERCE]);
|
|
24240
24240
|
} else {
|
|
24241
|
-
const coerceRtlRegex = options.includePrerelease ?
|
|
24241
|
+
const coerceRtlRegex = options.includePrerelease ? re2[t.COERCERTLFULL] : re2[t.COERCERTL];
|
|
24242
24242
|
let next;
|
|
24243
24243
|
while ((next = coerceRtlRegex.exec(version2)) && (!match || match.index + match[0].length !== version2.length)) {
|
|
24244
24244
|
if (!match || next.index + next[0].length !== match.index + match[0].length) {
|
|
@@ -24377,20 +24377,20 @@ var require_range = __commonJS({
|
|
|
24377
24377
|
return cached;
|
|
24378
24378
|
}
|
|
24379
24379
|
const loose = this.options.loose;
|
|
24380
|
-
const hr = loose ?
|
|
24380
|
+
const hr = loose ? re2[t.HYPHENRANGELOOSE] : re2[t.HYPHENRANGE];
|
|
24381
24381
|
range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
|
|
24382
24382
|
debug("hyphen replace", range);
|
|
24383
|
-
range = range.replace(
|
|
24383
|
+
range = range.replace(re2[t.COMPARATORTRIM], comparatorTrimReplace);
|
|
24384
24384
|
debug("comparator trim", range);
|
|
24385
|
-
range = range.replace(
|
|
24385
|
+
range = range.replace(re2[t.TILDETRIM], tildeTrimReplace);
|
|
24386
24386
|
debug("tilde trim", range);
|
|
24387
|
-
range = range.replace(
|
|
24387
|
+
range = range.replace(re2[t.CARETTRIM], caretTrimReplace);
|
|
24388
24388
|
debug("caret trim", range);
|
|
24389
24389
|
let rangeList = range.split(" ").map((comp) => parseComparator(comp, this.options)).join(" ").split(/\s+/).map((comp) => replaceGTE0(comp, this.options));
|
|
24390
24390
|
if (loose) {
|
|
24391
24391
|
rangeList = rangeList.filter((comp) => {
|
|
24392
24392
|
debug("loose invalid filter", comp, this.options);
|
|
24393
|
-
return !!comp.match(
|
|
24393
|
+
return !!comp.match(re2[t.COMPARATORLOOSE]);
|
|
24394
24394
|
});
|
|
24395
24395
|
}
|
|
24396
24396
|
debug("range list", rangeList);
|
|
@@ -24451,7 +24451,7 @@ var require_range = __commonJS({
|
|
|
24451
24451
|
var debug = require_debug2();
|
|
24452
24452
|
var SemVer = require_semver();
|
|
24453
24453
|
var {
|
|
24454
|
-
safeRe:
|
|
24454
|
+
safeRe: re2,
|
|
24455
24455
|
t,
|
|
24456
24456
|
comparatorTrimReplace,
|
|
24457
24457
|
tildeTrimReplace,
|
|
@@ -24489,7 +24489,7 @@ var require_range = __commonJS({
|
|
|
24489
24489
|
return comp.trim().split(/\s+/).map((c) => replaceTilde(c, options)).join(" ");
|
|
24490
24490
|
};
|
|
24491
24491
|
var replaceTilde = (comp, options) => {
|
|
24492
|
-
const r = options.loose ?
|
|
24492
|
+
const r = options.loose ? re2[t.TILDELOOSE] : re2[t.TILDE];
|
|
24493
24493
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
24494
24494
|
debug("tilde", comp, _, M, m, p, pr);
|
|
24495
24495
|
let ret;
|
|
@@ -24514,20 +24514,20 @@ var require_range = __commonJS({
|
|
|
24514
24514
|
};
|
|
24515
24515
|
var replaceCaret = (comp, options) => {
|
|
24516
24516
|
debug("caret", comp, options);
|
|
24517
|
-
const r = options.loose ?
|
|
24518
|
-
const
|
|
24517
|
+
const r = options.loose ? re2[t.CARETLOOSE] : re2[t.CARET];
|
|
24518
|
+
const z2 = options.includePrerelease ? "-0" : "";
|
|
24519
24519
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
24520
24520
|
debug("caret", comp, _, M, m, p, pr);
|
|
24521
24521
|
let ret;
|
|
24522
24522
|
if (isX(M)) {
|
|
24523
24523
|
ret = "";
|
|
24524
24524
|
} else if (isX(m)) {
|
|
24525
|
-
ret = `>=${M}.0.0${
|
|
24525
|
+
ret = `>=${M}.0.0${z2} <${+M + 1}.0.0-0`;
|
|
24526
24526
|
} else if (isX(p)) {
|
|
24527
24527
|
if (M === "0") {
|
|
24528
|
-
ret = `>=${M}.${m}.0${
|
|
24528
|
+
ret = `>=${M}.${m}.0${z2} <${M}.${+m + 1}.0-0`;
|
|
24529
24529
|
} else {
|
|
24530
|
-
ret = `>=${M}.${m}.0${
|
|
24530
|
+
ret = `>=${M}.${m}.0${z2} <${+M + 1}.0.0-0`;
|
|
24531
24531
|
}
|
|
24532
24532
|
} else if (pr) {
|
|
24533
24533
|
debug("replaceCaret pr", pr);
|
|
@@ -24544,9 +24544,9 @@ var require_range = __commonJS({
|
|
|
24544
24544
|
debug("no pr");
|
|
24545
24545
|
if (M === "0") {
|
|
24546
24546
|
if (m === "0") {
|
|
24547
|
-
ret = `>=${M}.${m}.${p}${
|
|
24547
|
+
ret = `>=${M}.${m}.${p}${z2} <${M}.${m}.${+p + 1}-0`;
|
|
24548
24548
|
} else {
|
|
24549
|
-
ret = `>=${M}.${m}.${p}${
|
|
24549
|
+
ret = `>=${M}.${m}.${p}${z2} <${M}.${+m + 1}.0-0`;
|
|
24550
24550
|
}
|
|
24551
24551
|
} else {
|
|
24552
24552
|
ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
|
|
@@ -24562,7 +24562,7 @@ var require_range = __commonJS({
|
|
|
24562
24562
|
};
|
|
24563
24563
|
var replaceXRange = (comp, options) => {
|
|
24564
24564
|
comp = comp.trim();
|
|
24565
|
-
const r = options.loose ?
|
|
24565
|
+
const r = options.loose ? re2[t.XRANGELOOSE] : re2[t.XRANGE];
|
|
24566
24566
|
return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
|
|
24567
24567
|
debug("xRange", comp, ret, gtlt, M, m, p, pr);
|
|
24568
24568
|
const xM = isX(M);
|
|
@@ -24617,11 +24617,11 @@ var require_range = __commonJS({
|
|
|
24617
24617
|
};
|
|
24618
24618
|
var replaceStars = (comp, options) => {
|
|
24619
24619
|
debug("replaceStars", comp, options);
|
|
24620
|
-
return comp.trim().replace(
|
|
24620
|
+
return comp.trim().replace(re2[t.STAR], "");
|
|
24621
24621
|
};
|
|
24622
24622
|
var replaceGTE0 = (comp, options) => {
|
|
24623
24623
|
debug("replaceGTE0", comp, options);
|
|
24624
|
-
return comp.trim().replace(
|
|
24624
|
+
return comp.trim().replace(re2[options.includePrerelease ? t.GTE0PRE : t.GTE0], "");
|
|
24625
24625
|
};
|
|
24626
24626
|
var hyphenReplace = (incPr) => ($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr) => {
|
|
24627
24627
|
if (isX(fM)) {
|
|
@@ -24707,7 +24707,7 @@ var require_comparator = __commonJS({
|
|
|
24707
24707
|
debug("comp", this);
|
|
24708
24708
|
}
|
|
24709
24709
|
parse(comp) {
|
|
24710
|
-
const r = this.options.loose ?
|
|
24710
|
+
const r = this.options.loose ? re2[t.COMPARATORLOOSE] : re2[t.COMPARATOR];
|
|
24711
24711
|
const m = comp.match(r);
|
|
24712
24712
|
if (!m) {
|
|
24713
24713
|
throw new TypeError(`Invalid comparator: ${comp}`);
|
|
@@ -24781,7 +24781,7 @@ var require_comparator = __commonJS({
|
|
|
24781
24781
|
};
|
|
24782
24782
|
module2.exports = Comparator;
|
|
24783
24783
|
var parseOptions = require_parse_options();
|
|
24784
|
-
var { safeRe:
|
|
24784
|
+
var { safeRe: re2, t } = require_re();
|
|
24785
24785
|
var cmp = require_cmp();
|
|
24786
24786
|
var debug = require_debug2();
|
|
24787
24787
|
var SemVer = require_semver();
|
|
@@ -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, b) => compare(a, b, 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;
|
|
@@ -26494,11 +26494,11 @@ var require_util2 = __commonJS({
|
|
|
26494
26494
|
});
|
|
26495
26495
|
};
|
|
26496
26496
|
exports2.tokenizeClass = (str, regexpStr) => {
|
|
26497
|
-
var _a, _b, _c, _d,
|
|
26497
|
+
var _a, _b, _c, _d, _e2, _f, _g;
|
|
26498
26498
|
let tokens = [], rs, c;
|
|
26499
26499
|
const regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(((?:\\)])|(((?:\\)?([^\]])))))|(\])|(?:\\)?([^])/g;
|
|
26500
26500
|
while ((rs = regexp.exec(str)) !== null) {
|
|
26501
|
-
const p = (_g = (_f = (
|
|
26501
|
+
const p = (_g = (_f = (_e2 = (_d = (_c = (_b = (_a = rs[1] && sets.words()) !== null && _a !== void 0 ? _a : rs[2] && sets.ints()) !== null && _b !== void 0 ? _b : rs[3] && sets.whitespace()) !== null && _c !== void 0 ? _c : rs[4] && sets.notWords()) !== null && _d !== void 0 ? _d : rs[5] && sets.notInts()) !== null && _e2 !== void 0 ? _e2 : rs[6] && sets.notWhitespace()) !== null && _f !== void 0 ? _f : rs[7] && {
|
|
26502
26502
|
type: types_1.types.RANGE,
|
|
26503
26503
|
from: (rs[8] || rs[9]).charCodeAt(0),
|
|
26504
26504
|
to: (c = rs[10]).charCodeAt(c.length - 1)
|
|
@@ -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;
|
|
@@ -27063,13 +27063,13 @@ var require_safe_regex2 = __commonJS({
|
|
|
27063
27063
|
"use strict";
|
|
27064
27064
|
var parse = require_dist3();
|
|
27065
27065
|
var types = parse.types;
|
|
27066
|
-
function safeRegex(
|
|
27066
|
+
function safeRegex(re2, opts) {
|
|
27067
27067
|
if (!opts) opts = {};
|
|
27068
27068
|
const replimit = opts.limit === void 0 ? 25 : opts.limit;
|
|
27069
|
-
if (isRegExp(
|
|
27070
|
-
else if (typeof
|
|
27069
|
+
if (isRegExp(re2)) re2 = re2.source;
|
|
27070
|
+
else if (typeof re2 !== "string") re2 = String(re2);
|
|
27071
27071
|
try {
|
|
27072
|
-
|
|
27072
|
+
re2 = parse(re2);
|
|
27073
27073
|
} catch {
|
|
27074
27074
|
return false;
|
|
27075
27075
|
}
|
|
@@ -27097,7 +27097,7 @@ var require_safe_regex2 = __commonJS({
|
|
|
27097
27097
|
if (!ok) return false;
|
|
27098
27098
|
}
|
|
27099
27099
|
return true;
|
|
27100
|
-
}(
|
|
27100
|
+
}(re2, 0);
|
|
27101
27101
|
}
|
|
27102
27102
|
function isRegExp(x) {
|
|
27103
27103
|
return {}.toString.call(x) === "[object RegExp]";
|
|
@@ -28943,7 +28943,7 @@ var require_route = __commonJS({
|
|
|
28943
28943
|
context.schemaErrorFormatter = opts.schemaErrorFormatter || this[kSchemaErrorFormatter] || context.schemaErrorFormatter;
|
|
28944
28944
|
avvio.once("preReady", () => {
|
|
28945
28945
|
for (const hook of lifecycleHooks) {
|
|
28946
|
-
const toSet = this[kHooks][hook].concat(opts[hook] || []).map((
|
|
28946
|
+
const toSet = this[kHooks][hook].concat(opts[hook] || []).map((h) => h.bind(this));
|
|
28947
28947
|
context[hook] = toSet.length ? toSet : null;
|
|
28948
28948
|
}
|
|
28949
28949
|
while (!context.Request[kHasBeenDecorated] && context.Request.parent) {
|
|
@@ -29231,7 +29231,7 @@ var require_fourOhFour = __commonJS({
|
|
|
29231
29231
|
avvio.once("preReady", () => {
|
|
29232
29232
|
const context2 = this[kFourOhFourContext];
|
|
29233
29233
|
for (const hook of lifecycleHooks) {
|
|
29234
|
-
const toSet = this[kHooks][hook].concat(opts[hook] || []).map((
|
|
29234
|
+
const toSet = this[kHooks][hook].concat(opts[hook] || []).map((h) => h.bind(this));
|
|
29235
29235
|
context2[hook] = toSet.length ? toSet : null;
|
|
29236
29236
|
}
|
|
29237
29237
|
context2.errorHandler = opts.errorHandler ? buildErrorHandler(this[kErrorHandler], opts.errorHandler) : this[kErrorHandler];
|
|
@@ -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
|
}
|
|
@@ -54928,7 +54928,7 @@ var readConfigFile = async () => {
|
|
|
54928
54928
|
return JSON.parse(config);
|
|
54929
54929
|
} catch {
|
|
54930
54930
|
const name = await question("Enter Provider Name: ");
|
|
54931
|
-
const
|
|
54931
|
+
const APIKEY = await question("Enter Provider API KEY: ");
|
|
54932
54932
|
const baseUrl = await question("Enter Provider URL: ");
|
|
54933
54933
|
const model = await question("Enter MODEL Name: ");
|
|
54934
54934
|
const config = Object.assign({}, DEFAULT_CONFIG, {
|
|
@@ -54936,7 +54936,7 @@ var readConfigFile = async () => {
|
|
|
54936
54936
|
{
|
|
54937
54937
|
name,
|
|
54938
54938
|
api_base_url: baseUrl,
|
|
54939
|
-
api_key:
|
|
54939
|
+
api_key: APIKEY,
|
|
54940
54940
|
models: [model]
|
|
54941
54941
|
}
|
|
54942
54942
|
],
|
|
@@ -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.7_ws@8.18.3_zod@3.25.67/node_modules/@musistudio/llms/dist/esm/server.mjs
|
|
54962
54962
|
var import_fastify = __toESM(require_fastify(), 1);
|
|
54963
54963
|
var import_cors = __toESM(require_cors(), 1);
|
|
54964
54964
|
var import_fs = require("fs");
|
|
@@ -54966,19 +54966,21 @@ var import_path = require("path");
|
|
|
54966
54966
|
var import_dotenv = __toESM(require_main(), 1);
|
|
54967
54967
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
54968
54968
|
var import_undici = __toESM(require_undici(), 1);
|
|
54969
|
+
var import_crypto = require("crypto");
|
|
54970
|
+
var import_crypto2 = require("crypto");
|
|
54969
54971
|
var import_node_module = __toESM(require("node:module"), 1);
|
|
54970
|
-
var
|
|
54972
|
+
var Y = ((s) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(s, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : s)(function(s) {
|
|
54971
54973
|
if (typeof require < "u") return require.apply(this, arguments);
|
|
54972
|
-
throw Error('Dynamic require of "' +
|
|
54974
|
+
throw Error('Dynamic require of "' + s + '" is not supported');
|
|
54973
54975
|
});
|
|
54974
|
-
var
|
|
54976
|
+
var I = class {
|
|
54975
54977
|
config = {};
|
|
54976
54978
|
options;
|
|
54977
54979
|
constructor(e = { jsonPath: "./config.json" }) {
|
|
54978
54980
|
this.options = { envPath: e.envPath || ".env", jsonPath: e.jsonPath, useEnvFile: false, useJsonFile: e.useJsonFile !== false, useEnvironmentVariables: e.useEnvironmentVariables !== false, ...e }, this.loadConfig();
|
|
54979
54981
|
}
|
|
54980
54982
|
loadConfig() {
|
|
54981
|
-
this.options.initialConfig && (this.config = { ...this.config, ...this.options.initialConfig }), this.options.useEnvFile && this.loadEnvConfig(), this.
|
|
54983
|
+
this.options.useJsonFile && this.options.jsonPath && this.loadJsonConfig(), this.options.initialConfig && (this.config = { ...this.config, ...this.options.initialConfig }), this.options.useEnvFile && this.loadEnvConfig(), this.config.LOG_FILE && (process.env.LOG_FILE = this.config.LOG_FILE), this.config.LOG && (process.env.LOG = this.config.LOG);
|
|
54982
54984
|
}
|
|
54983
54985
|
loadJsonConfig() {
|
|
54984
54986
|
if (!this.options.jsonPath) return;
|
|
@@ -55035,80 +55037,80 @@ var N = class {
|
|
|
55035
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(", ")}`;
|
|
55036
55038
|
}
|
|
55037
55039
|
};
|
|
55038
|
-
function
|
|
55039
|
-
if (console.log(...
|
|
55040
|
-
let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(
|
|
55040
|
+
function v(...s) {
|
|
55041
|
+
if (console.log(...s), !(process.env.LOG === "true")) return;
|
|
55042
|
+
let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(s) ? s.map((r) => typeof r == "object" ? JSON.stringify(r) : String(r)).join(" ") : ""}
|
|
55041
55043
|
`, o = process.env.LOG_FILE || "app.log";
|
|
55042
55044
|
import_node_fs.default.appendFileSync(o, n, "utf8");
|
|
55043
55045
|
}
|
|
55044
|
-
function
|
|
55045
|
-
let o = new Error(
|
|
55046
|
+
function N(s, e = 500, t = "internal_error", n = "api_error") {
|
|
55047
|
+
let o = new Error(s);
|
|
55046
55048
|
return o.statusCode = e, o.code = t, o.type = n, o;
|
|
55047
55049
|
}
|
|
55048
|
-
async function
|
|
55049
|
-
e.log.error(
|
|
55050
|
-
let n =
|
|
55050
|
+
async function ie(s, e, t) {
|
|
55051
|
+
e.log.error(s);
|
|
55052
|
+
let n = s.statusCode || 500, o = { error: { message: s.message || "Internal Server Error", type: s.type || "api_error", code: s.code || "internal_error" } };
|
|
55051
55053
|
return t.code(n).send(o);
|
|
55052
55054
|
}
|
|
55053
|
-
function
|
|
55055
|
+
function ae(s, e, t) {
|
|
55054
55056
|
let n = new Headers({ "Content-Type": "application/json" });
|
|
55055
|
-
t.headers && Object.entries(t.headers).forEach(([
|
|
55056
|
-
n.set(
|
|
55057
|
+
t.headers && Object.entries(t.headers).forEach(([l, f]) => {
|
|
55058
|
+
n.set(l, f);
|
|
55057
55059
|
});
|
|
55058
55060
|
let o, r = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
|
|
55059
55061
|
if (t.signal) {
|
|
55060
|
-
let
|
|
55061
|
-
t.signal.addEventListener("abort",
|
|
55062
|
+
let l = new AbortController(), f = () => l.abort();
|
|
55063
|
+
t.signal.addEventListener("abort", f), r.addEventListener("abort", f), o = l.signal;
|
|
55062
55064
|
} else o = r;
|
|
55063
|
-
let
|
|
55064
|
-
return t.httpsProxy && (
|
|
55065
|
+
let d = { method: "POST", headers: n, body: JSON.stringify(e), signal: o };
|
|
55066
|
+
return t.httpsProxy && (d.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), v("final request:", typeof s == "string" ? s : s.toString(), t.httpsProxy, d), fetch(typeof s == "string" ? s : s.toString(), d);
|
|
55065
55067
|
}
|
|
55066
|
-
var
|
|
55067
|
-
|
|
55068
|
-
let e =
|
|
55069
|
-
for (let { name: t, transformer: n } of e) n.endPoint &&
|
|
55070
|
-
let
|
|
55071
|
-
if (!
|
|
55072
|
-
let
|
|
55068
|
+
var ce = async (s) => {
|
|
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
|
+
let e = s._server.transformerService.getTransformersWithEndpoint();
|
|
55071
|
+
for (let { name: t, transformer: n } of e) n.endPoint && s.post(n.endPoint, async (o, r) => {
|
|
55072
|
+
let d = o.body, l = o.provider, f = s._server.providerService.getProvider(l);
|
|
55073
|
+
if (!f) throw N(`Provider '${l}' not found`, 404, "provider_not_found");
|
|
55074
|
+
let a = d, m = {};
|
|
55073
55075
|
if (typeof n.transformRequestOut == "function") {
|
|
55074
|
-
let
|
|
55075
|
-
|
|
55076
|
-
}
|
|
55077
|
-
if (
|
|
55078
|
-
if (!
|
|
55079
|
-
let y = await
|
|
55080
|
-
y.body ? (
|
|
55081
|
-
}
|
|
55082
|
-
if (
|
|
55083
|
-
let
|
|
55084
|
-
if (!
|
|
55085
|
-
let
|
|
55086
|
-
throw
|
|
55087
|
-
}
|
|
55088
|
-
let
|
|
55089
|
-
if (
|
|
55090
|
-
if (
|
|
55091
|
-
return n.transformResponseIn && (
|
|
55076
|
+
let i = await n.transformRequestOut(d);
|
|
55077
|
+
i.body ? (a = i.body, m = i.config || {}) : a = i;
|
|
55078
|
+
}
|
|
55079
|
+
if (v("use transformers:", f.transformer?.use), f.transformer?.use?.length) for (let i of f.transformer.use) {
|
|
55080
|
+
if (!i || typeof i.transformRequestIn != "function") continue;
|
|
55081
|
+
let y = await i.transformRequestIn(a, f);
|
|
55082
|
+
y.body ? (a = y.body, m = { ...m, ...y.config }) : a = y;
|
|
55083
|
+
}
|
|
55084
|
+
if (f.transformer?.[o.body.model]?.use?.length) for (let i of f.transformer[o.body.model].use) !i || typeof i.transformRequestIn != "function" || (a = await i.transformRequestIn(a, f));
|
|
55085
|
+
let g = m.url || new URL(f.baseUrl), C = await ae(g, a, { httpsProxy: s._server.configService.getHttpsProxy(), ...m, headers: { Authorization: `Bearer ${f.apiKey}`, ...m?.headers || {} } });
|
|
55086
|
+
if (!C.ok) {
|
|
55087
|
+
let i = await C.text();
|
|
55088
|
+
throw v(`Error response from ${g}: ${i}`), N(`Error from provider: ${i}`, C.status, "provider_response_error");
|
|
55089
|
+
}
|
|
55090
|
+
let p = C;
|
|
55091
|
+
if (f.transformer?.use?.length) for (let i of f.transformer.use) !i || typeof i.transformResponseOut != "function" || (p = await i.transformResponseOut(p));
|
|
55092
|
+
if (f.transformer?.[o.body.model]?.use?.length) for (let i of f.transformer[o.body.model].use) !i || typeof i.transformResponseOut != "function" || (p = await i.transformResponseOut(p));
|
|
55093
|
+
return n.transformResponseIn && (p = await n.transformResponseIn(p)), p.ok || r.code(p.status), d?.stream === true ? (r.header("Content-Type", "text/event-stream"), r.header("Cache-Control", "no-cache"), r.header("Connection", "keep-alive"), r.send(p.body)) : p.json();
|
|
55092
55094
|
});
|
|
55093
|
-
|
|
55094
|
-
let { name: o, type: r, baseUrl:
|
|
55095
|
-
if (!o?.trim()) throw
|
|
55096
|
-
if (!
|
|
55097
|
-
if (!
|
|
55098
|
-
if (!
|
|
55099
|
-
if (
|
|
55100
|
-
return
|
|
55101
|
-
}),
|
|
55102
|
-
let o =
|
|
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: o, type: r, baseUrl: d, apiKey: l, models: f } = t.body;
|
|
55097
|
+
if (!o?.trim()) throw N("Provider name is required", 400, "invalid_request");
|
|
55098
|
+
if (!d || !ve(d)) throw N("Valid base URL is required", 400, "invalid_request");
|
|
55099
|
+
if (!l?.trim()) throw N("API key is required", 400, "invalid_request");
|
|
55100
|
+
if (!f || !Array.isArray(f) || f.length === 0) throw N("At least one model is required", 400, "invalid_request");
|
|
55101
|
+
if (s._server.providerService.getProvider(id)) throw N(`Provider with ID '${id}' already exists`, 400, "provider_exists");
|
|
55102
|
+
return s._server.providerService.registerProvider(t.body);
|
|
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) => {
|
|
55104
|
+
let o = s._server.providerService.getProvider(t.params.id);
|
|
55103
55105
|
return o || n.code(404).send({ error: "Provider not found" });
|
|
55104
|
-
}),
|
|
55105
|
-
let o =
|
|
55106
|
+
}), s.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 = s._server.providerService.updateProvider(t.params.id, t.body);
|
|
55106
55108
|
return o || n.code(404).send({ error: "Provider not found" });
|
|
55107
|
-
}),
|
|
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" }));
|
|
55108
55110
|
};
|
|
55109
|
-
function
|
|
55111
|
+
function ve(s) {
|
|
55110
55112
|
try {
|
|
55111
|
-
return new URL(
|
|
55113
|
+
return new URL(s), true;
|
|
55112
55114
|
} catch {
|
|
55113
55115
|
return false;
|
|
55114
55116
|
}
|
|
@@ -55173,20 +55175,20 @@ var F = class {
|
|
|
55173
55175
|
t.transformer && Object.keys(t.transformer).forEach((o) => {
|
|
55174
55176
|
o === "use" ? Array.isArray(t.transformer.use) && (n.use = t.transformer.use.map((r) => {
|
|
55175
55177
|
if (Array.isArray(r) && typeof r[0] == "string") {
|
|
55176
|
-
let
|
|
55177
|
-
if (
|
|
55178
|
+
let d = this.transformerService.getTransformer(r[0]);
|
|
55179
|
+
if (d) return new d(r[1]);
|
|
55178
55180
|
}
|
|
55179
55181
|
if (typeof r == "string") return this.transformerService.getTransformer(r);
|
|
55180
55182
|
}).filter((r) => typeof r < "u")) : Array.isArray(t.transformer[o]?.use) && (n[o] = { use: t.transformer[o].use.map((r) => {
|
|
55181
55183
|
if (Array.isArray(r) && typeof r[0] == "string") {
|
|
55182
|
-
let
|
|
55183
|
-
if (
|
|
55184
|
+
let d = this.transformerService.getTransformer(r[0]);
|
|
55185
|
+
if (d) return new d(r[1]);
|
|
55184
55186
|
}
|
|
55185
55187
|
if (typeof r == "string") return this.transformerService.getTransformer(r);
|
|
55186
55188
|
}).filter((r) => typeof r < "u") });
|
|
55187
|
-
}),
|
|
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`);
|
|
55188
55190
|
} catch (n) {
|
|
55189
|
-
|
|
55191
|
+
v(`${t.name} provider registered error: ${n}`);
|
|
55190
55192
|
}
|
|
55191
55193
|
});
|
|
55192
55194
|
}
|
|
@@ -55208,11 +55210,11 @@ var F = class {
|
|
|
55208
55210
|
if (!n) return null;
|
|
55209
55211
|
let o = { ...n, ...t, updatedAt: /* @__PURE__ */ new Date() };
|
|
55210
55212
|
return this.providers.set(e, o), t.models && (n.models.forEach((r) => {
|
|
55211
|
-
let
|
|
55212
|
-
this.modelRoutes.delete(
|
|
55213
|
+
let d = `${n.id},${r}`;
|
|
55214
|
+
this.modelRoutes.delete(d), this.modelRoutes.delete(r);
|
|
55213
55215
|
}), t.models.forEach((r) => {
|
|
55214
|
-
let
|
|
55215
|
-
this.modelRoutes.set(
|
|
55216
|
+
let d = `${n.name},${r}`, l = { provider: n.name, model: r, fullModel: d };
|
|
55217
|
+
this.modelRoutes.set(d, l), this.modelRoutes.has(r) || this.modelRoutes.set(r, l);
|
|
55216
55218
|
})), o;
|
|
55217
55219
|
}
|
|
55218
55220
|
deleteProvider(e) {
|
|
@@ -55260,37 +55262,38 @@ var F = class {
|
|
|
55260
55262
|
}), { object: "list", data: e };
|
|
55261
55263
|
}
|
|
55262
55264
|
};
|
|
55263
|
-
var
|
|
55265
|
+
var q = class {
|
|
55264
55266
|
name = "Anthropic";
|
|
55265
55267
|
endPoint = "/v1/messages";
|
|
55266
55268
|
transformRequestOut(e) {
|
|
55267
|
-
|
|
55269
|
+
v("Anthropic Request:", JSON.stringify(e, null, 2));
|
|
55268
55270
|
let t = [];
|
|
55269
55271
|
if (e.system) {
|
|
55270
55272
|
if (typeof e.system == "string") t.push({ role: "system", content: e.system });
|
|
55271
55273
|
else if (Array.isArray(e.system)) {
|
|
55272
|
-
let r = e.system.filter((
|
|
55274
|
+
let r = e.system.filter((d) => d.type === "text" && d.text).map((d) => ({ type: "text", text: d.text, cache_control: d.cache_control }));
|
|
55273
55275
|
t.push({ role: "system", content: r });
|
|
55274
55276
|
}
|
|
55275
55277
|
}
|
|
55276
|
-
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((r,
|
|
55278
|
+
return JSON.parse(JSON.stringify(e.messages || []))?.forEach((r, d) => {
|
|
55277
55279
|
if (r.role === "user" || r.role === "assistant") {
|
|
55278
|
-
let
|
|
55280
|
+
let l = { role: r.role, content: null };
|
|
55279
55281
|
if (typeof r.content == "string") t.push({ role: r.role, content: r.content });
|
|
55280
55282
|
else if (Array.isArray(r.content)) {
|
|
55281
55283
|
if (r.role === "user") {
|
|
55282
|
-
let
|
|
55283
|
-
|
|
55284
|
-
let
|
|
55285
|
-
t.push(
|
|
55284
|
+
let f = r.content.filter((m) => m.type === "tool_result" && m.tool_use_id);
|
|
55285
|
+
f.length && f.forEach((m, g) => {
|
|
55286
|
+
let C = { role: "tool", content: typeof m.content == "string" ? m.content : JSON.stringify(m.content), tool_call_id: m.tool_use_id, cache_control: m.cache_control };
|
|
55287
|
+
t.push(C);
|
|
55286
55288
|
});
|
|
55287
|
-
let
|
|
55288
|
-
|
|
55289
|
+
let a = r.content.filter((m) => m.type === "text" && m.text);
|
|
55290
|
+
a.length && t.push({ role: "user", content: a });
|
|
55289
55291
|
} else if (r.role === "assistant") {
|
|
55290
|
-
let
|
|
55291
|
-
|
|
55292
|
-
|
|
55293
|
-
|
|
55292
|
+
let f = { role: "assistant", content: null }, a = r.content.filter((g) => g.type === "text" && g.text);
|
|
55293
|
+
a.length && (f.content = a.map((g) => g.text).join(`
|
|
55294
|
+
`));
|
|
55295
|
+
let m = r.content.filter((g) => g.type === "tool_use" && g.id);
|
|
55296
|
+
m.length && (f.tool_calls = m.map((g) => ({ id: g.id, type: "function", function: { name: g.name, arguments: JSON.stringify(g.input || {}) } }))), t.push(f);
|
|
55294
55297
|
}
|
|
55295
55298
|
return;
|
|
55296
55299
|
}
|
|
@@ -55312,226 +55315,234 @@ var I = class {
|
|
|
55312
55315
|
}
|
|
55313
55316
|
async convertOpenAIStreamToAnthropic(e) {
|
|
55314
55317
|
return new ReadableStream({ async start(n) {
|
|
55315
|
-
let o = new TextEncoder(), r = `msg_${Date.now()}`,
|
|
55316
|
-
if (!
|
|
55317
|
-
n.enqueue(
|
|
55318
|
-
let
|
|
55319
|
-
|
|
55320
|
-
} catch (R) {
|
|
55321
|
-
if (R instanceof TypeError && R.message.includes("Controller is already closed")) s = true;
|
|
55322
|
-
else throw h(`send data error: ${R.message}`), R;
|
|
55323
|
-
}
|
|
55324
|
-
}, S = () => {
|
|
55325
|
-
if (!s) try {
|
|
55326
|
-
n.close(), s = true;
|
|
55318
|
+
let o = new TextEncoder(), r = `msg_${Date.now()}`, d = "unknown", l = false, f = false, a = false, m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), C = 0, p = 0, u = 0, i = false, y = false, h = 0, c = (b) => {
|
|
55319
|
+
if (!i) try {
|
|
55320
|
+
n.enqueue(b);
|
|
55321
|
+
let _ = new TextDecoder().decode(b);
|
|
55322
|
+
v("send data:", _.trim());
|
|
55327
55323
|
} catch (_) {
|
|
55328
|
-
if (_ instanceof TypeError && _.message.includes("Controller is already closed"))
|
|
55329
|
-
else throw _;
|
|
55324
|
+
if (_ instanceof TypeError && _.message.includes("Controller is already closed")) i = true;
|
|
55325
|
+
else throw v(`send data error: ${_.message}`), _;
|
|
55326
|
+
}
|
|
55327
|
+
}, k = () => {
|
|
55328
|
+
if (!i) try {
|
|
55329
|
+
n.close(), i = true;
|
|
55330
|
+
} catch (b) {
|
|
55331
|
+
if (b instanceof TypeError && b.message.includes("Controller is already closed")) i = true;
|
|
55332
|
+
else throw b;
|
|
55330
55333
|
}
|
|
55331
55334
|
}, P = null;
|
|
55332
55335
|
try {
|
|
55333
55336
|
P = e.getReader();
|
|
55334
|
-
let
|
|
55335
|
-
for (; !
|
|
55336
|
-
let { done:
|
|
55337
|
-
if (
|
|
55338
|
-
|
|
55339
|
-
let
|
|
55337
|
+
let b = new TextDecoder(), _ = "";
|
|
55338
|
+
for (; !i; ) {
|
|
55339
|
+
let { done: ue, value: fe } = await P.read();
|
|
55340
|
+
if (ue) break;
|
|
55341
|
+
_ += b.decode(fe, { stream: true });
|
|
55342
|
+
let ne = _.split(`
|
|
55340
55343
|
`);
|
|
55341
|
-
|
|
55342
|
-
for (let
|
|
55343
|
-
if (
|
|
55344
|
-
if (!
|
|
55345
|
-
let
|
|
55346
|
-
if (
|
|
55347
|
-
let
|
|
55348
|
-
if (
|
|
55349
|
-
|
|
55350
|
-
|
|
55351
|
-
|
|
55352
|
-
data: ${JSON.stringify(b)}
|
|
55344
|
+
_ = ne.pop() || "";
|
|
55345
|
+
for (let oe of ne) {
|
|
55346
|
+
if (i || a) break;
|
|
55347
|
+
if (!oe.startsWith("data: ")) continue;
|
|
55348
|
+
let K = oe.slice(6);
|
|
55349
|
+
if (K !== "[DONE]") try {
|
|
55350
|
+
let O = JSON.parse(K);
|
|
55351
|
+
if (C++, v("Original Response:", JSON.stringify(O, null, 2)), O.error) {
|
|
55352
|
+
let x = { type: "error", message: { type: "api_error", message: JSON.stringify(O.error) } };
|
|
55353
|
+
c(o.encode(`event: error
|
|
55354
|
+
data: ${JSON.stringify(x)}
|
|
55353
55355
|
|
|
55354
55356
|
`));
|
|
55357
|
+
continue;
|
|
55355
55358
|
}
|
|
55356
|
-
|
|
55357
|
-
|
|
55358
|
-
|
|
55359
|
+
if (d = O.model || d, !l && !i && !a) {
|
|
55360
|
+
l = true;
|
|
55361
|
+
let x = { type: "message_start", message: { id: r, type: "message", role: "assistant", content: [], model: d, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
|
|
55362
|
+
c(o.encode(`event: message_start
|
|
55363
|
+
data: ${JSON.stringify(x)}
|
|
55364
|
+
|
|
55365
|
+
`));
|
|
55366
|
+
}
|
|
55367
|
+
let w = O.choices?.[0];
|
|
55368
|
+
if (!w) continue;
|
|
55369
|
+
if (w?.delta?.thinking && !i && !a) {
|
|
55359
55370
|
if (!y) {
|
|
55360
|
-
let
|
|
55361
|
-
|
|
55362
|
-
data: ${JSON.stringify(
|
|
55371
|
+
let x = { type: "content_block_start", index: h, content_block: { type: "thinking", thinking: "" } };
|
|
55372
|
+
c(o.encode(`event: content_block_start
|
|
55373
|
+
data: ${JSON.stringify(x)}
|
|
55363
55374
|
|
|
55364
55375
|
`)), y = true;
|
|
55365
55376
|
}
|
|
55366
|
-
if (
|
|
55367
|
-
let
|
|
55368
|
-
|
|
55369
|
-
data: ${JSON.stringify(
|
|
55377
|
+
if (w.delta.thinking.signature) {
|
|
55378
|
+
let x = { type: "content_block_delta", index: h, delta: { type: "signature_delta", signature: w.delta.thinking.signature } };
|
|
55379
|
+
c(o.encode(`event: content_block_delta
|
|
55380
|
+
data: ${JSON.stringify(x)}
|
|
55370
55381
|
|
|
55371
55382
|
`));
|
|
55372
|
-
let
|
|
55373
|
-
|
|
55374
|
-
data: ${JSON.stringify(
|
|
55375
|
-
|
|
55376
|
-
`)),
|
|
55377
|
-
} else if (
|
|
55378
|
-
let
|
|
55379
|
-
|
|
55380
|
-
data: ${JSON.stringify(
|
|
55383
|
+
let T = { type: "content_block_stop", index: h };
|
|
55384
|
+
c(o.encode(`event: content_block_stop
|
|
55385
|
+
data: ${JSON.stringify(T)}
|
|
55386
|
+
|
|
55387
|
+
`)), h++;
|
|
55388
|
+
} else if (w.delta.thinking.content) {
|
|
55389
|
+
let x = { type: "content_block_delta", index: h, delta: { type: "thinking_delta", thinking: w.delta.thinking.content || "" } };
|
|
55390
|
+
c(o.encode(`event: content_block_delta
|
|
55391
|
+
data: ${JSON.stringify(x)}
|
|
55381
55392
|
|
|
55382
55393
|
`));
|
|
55383
55394
|
}
|
|
55384
55395
|
}
|
|
55385
|
-
if (
|
|
55386
|
-
if (
|
|
55387
|
-
|
|
55388
|
-
let
|
|
55389
|
-
|
|
55390
|
-
data: ${JSON.stringify(
|
|
55396
|
+
if (w?.delta?.content && !i && !a) {
|
|
55397
|
+
if (p++, !f && !a) {
|
|
55398
|
+
f = true;
|
|
55399
|
+
let x = { type: "content_block_start", index: h, content_block: { type: "text", text: "" } };
|
|
55400
|
+
c(o.encode(`event: content_block_start
|
|
55401
|
+
data: ${JSON.stringify(x)}
|
|
55391
55402
|
|
|
55392
55403
|
`));
|
|
55393
55404
|
}
|
|
55394
|
-
if (!
|
|
55395
|
-
let
|
|
55396
|
-
|
|
55397
|
-
data: ${JSON.stringify(
|
|
55405
|
+
if (!i && !a) {
|
|
55406
|
+
let x = { type: "content_block_delta", index: h, delta: { type: "text_delta", text: w.delta.content } };
|
|
55407
|
+
c(o.encode(`event: content_block_delta
|
|
55408
|
+
data: ${JSON.stringify(x)}
|
|
55398
55409
|
|
|
55399
55410
|
`));
|
|
55400
55411
|
}
|
|
55401
55412
|
}
|
|
55402
|
-
if (
|
|
55403
|
-
|
|
55404
|
-
let
|
|
55405
|
-
for (let
|
|
55406
|
-
if (
|
|
55407
|
-
let
|
|
55408
|
-
if (
|
|
55409
|
-
if (
|
|
55410
|
-
let
|
|
55411
|
-
if (
|
|
55412
|
-
|
|
55413
|
-
let
|
|
55414
|
-
|
|
55415
|
-
data: ${JSON.stringify(
|
|
55416
|
-
|
|
55417
|
-
`)),
|
|
55413
|
+
if (w?.delta?.tool_calls && !i && !a) {
|
|
55414
|
+
u++;
|
|
55415
|
+
let x = /* @__PURE__ */ new Set();
|
|
55416
|
+
for (let T of w.delta.tool_calls) {
|
|
55417
|
+
if (i) break;
|
|
55418
|
+
let S = T.index ?? 0;
|
|
55419
|
+
if (x.has(S)) continue;
|
|
55420
|
+
if (x.add(S), !g.has(S)) {
|
|
55421
|
+
let E = f ? g.size + 1 : g.size;
|
|
55422
|
+
if (E !== 0) {
|
|
55423
|
+
v("content_block_stop2");
|
|
55424
|
+
let pe = { type: "content_block_stop", index: h };
|
|
55425
|
+
c(o.encode(`event: content_block_stop
|
|
55426
|
+
data: ${JSON.stringify(pe)}
|
|
55427
|
+
|
|
55428
|
+
`)), h++;
|
|
55418
55429
|
}
|
|
55419
|
-
|
|
55420
|
-
let H =
|
|
55421
|
-
|
|
55422
|
-
data: ${JSON.stringify(
|
|
55430
|
+
g.set(S, E);
|
|
55431
|
+
let H = T.id || `call_${Date.now()}_${S}`, A = T.function?.name || `tool_${S}`, L = { type: "content_block_start", index: h, content_block: { type: "tool_use", id: H, name: A, input: {} } };
|
|
55432
|
+
c(o.encode(`event: content_block_start
|
|
55433
|
+
data: ${JSON.stringify(L)}
|
|
55423
55434
|
|
|
55424
55435
|
`));
|
|
55425
|
-
let M = { id: H, name: A, arguments: "", contentBlockIndex:
|
|
55426
|
-
|
|
55427
|
-
} else if (
|
|
55428
|
-
let
|
|
55429
|
-
|
|
55436
|
+
let M = { id: H, name: A, arguments: "", contentBlockIndex: E };
|
|
55437
|
+
m.set(S, M);
|
|
55438
|
+
} else if (T.id && T.function?.name) {
|
|
55439
|
+
let E = m.get(S);
|
|
55440
|
+
E.id.startsWith("call_") && E.name.startsWith("tool_") && (E.id = T.id, E.name = T.function.name);
|
|
55430
55441
|
}
|
|
55431
|
-
if (
|
|
55432
|
-
if (
|
|
55433
|
-
let H =
|
|
55442
|
+
if (T.function?.arguments && !i && !a) {
|
|
55443
|
+
if (g.get(S) === void 0) continue;
|
|
55444
|
+
let H = m.get(S);
|
|
55434
55445
|
if (H) {
|
|
55435
|
-
H.arguments +=
|
|
55446
|
+
H.arguments += T.function.arguments;
|
|
55436
55447
|
try {
|
|
55437
|
-
let A = null,
|
|
55438
|
-
if (
|
|
55439
|
-
A = JSON.parse(
|
|
55448
|
+
let A = null, L = H.arguments.trim();
|
|
55449
|
+
if (L.startsWith("{") && L.endsWith("}")) try {
|
|
55450
|
+
A = JSON.parse(L);
|
|
55440
55451
|
} catch (M) {
|
|
55441
|
-
|
|
55452
|
+
v("Tool call index:", S, "error", M.message);
|
|
55442
55453
|
}
|
|
55443
55454
|
} catch (A) {
|
|
55444
|
-
|
|
55455
|
+
v("Tool call index:", S, "error", A.message);
|
|
55445
55456
|
}
|
|
55446
55457
|
}
|
|
55447
55458
|
try {
|
|
55448
|
-
let A = { type: "content_block_delta", index:
|
|
55449
|
-
|
|
55459
|
+
let A = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: T.function.arguments } };
|
|
55460
|
+
c(o.encode(`event: content_block_delta
|
|
55450
55461
|
data: ${JSON.stringify(A)}
|
|
55451
55462
|
|
|
55452
55463
|
`));
|
|
55453
55464
|
} catch {
|
|
55454
55465
|
try {
|
|
55455
|
-
let
|
|
55456
|
-
|
|
55466
|
+
let L = T.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: L } };
|
|
55467
|
+
c(o.encode(`event: content_block_delta
|
|
55457
55468
|
data: ${JSON.stringify(M)}
|
|
55458
55469
|
|
|
55459
55470
|
`));
|
|
55460
|
-
} catch (
|
|
55461
|
-
console.error(
|
|
55471
|
+
} catch (L) {
|
|
55472
|
+
console.error(L);
|
|
55462
55473
|
}
|
|
55463
55474
|
}
|
|
55464
55475
|
}
|
|
55465
55476
|
}
|
|
55466
55477
|
}
|
|
55467
|
-
if (
|
|
55468
|
-
if (
|
|
55469
|
-
|
|
55470
|
-
let
|
|
55471
|
-
|
|
55472
|
-
data: ${JSON.stringify(
|
|
55478
|
+
if (w?.finish_reason && !i && !a) {
|
|
55479
|
+
if (a = true, p === 0 && u === 0 && console.error("Warning: No content in the stream response!"), (f || u > 0) && !i) {
|
|
55480
|
+
v("content_block_stop hasTextContentStarted");
|
|
55481
|
+
let x = { type: "content_block_stop", index: h };
|
|
55482
|
+
c(o.encode(`event: content_block_stop
|
|
55483
|
+
data: ${JSON.stringify(x)}
|
|
55473
55484
|
|
|
55474
55485
|
`));
|
|
55475
55486
|
}
|
|
55476
|
-
if (!
|
|
55477
|
-
let
|
|
55478
|
-
|
|
55479
|
-
data: ${JSON.stringify(
|
|
55487
|
+
if (!i) {
|
|
55488
|
+
let S = { 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
|
+
c(o.encode(`event: message_delta
|
|
55490
|
+
data: ${JSON.stringify(S)}
|
|
55480
55491
|
|
|
55481
55492
|
`));
|
|
55482
55493
|
}
|
|
55483
|
-
if (!
|
|
55484
|
-
let
|
|
55485
|
-
|
|
55486
|
-
data: ${JSON.stringify(
|
|
55494
|
+
if (!i) {
|
|
55495
|
+
let x = { type: "message_stop" };
|
|
55496
|
+
c(o.encode(`event: message_stop
|
|
55497
|
+
data: ${JSON.stringify(x)}
|
|
55487
55498
|
|
|
55488
55499
|
`));
|
|
55489
55500
|
}
|
|
55490
55501
|
break;
|
|
55491
55502
|
}
|
|
55492
|
-
} catch (
|
|
55493
|
-
|
|
55503
|
+
} catch (O) {
|
|
55504
|
+
v(`parseError: ${O.name} message: ${O.message} stack: ${O.stack} data: ${K}`);
|
|
55494
55505
|
}
|
|
55495
55506
|
}
|
|
55496
55507
|
}
|
|
55497
|
-
|
|
55498
|
-
} catch (
|
|
55499
|
-
if (!
|
|
55500
|
-
n.error(
|
|
55501
|
-
} catch (
|
|
55502
|
-
console.error(
|
|
55508
|
+
k();
|
|
55509
|
+
} catch (b) {
|
|
55510
|
+
if (!i) try {
|
|
55511
|
+
n.error(b);
|
|
55512
|
+
} catch (_) {
|
|
55513
|
+
console.error(_);
|
|
55503
55514
|
}
|
|
55504
55515
|
} finally {
|
|
55505
55516
|
if (P) try {
|
|
55506
55517
|
P.releaseLock();
|
|
55507
|
-
} catch (
|
|
55508
|
-
console.error(
|
|
55518
|
+
} catch (b) {
|
|
55519
|
+
console.error(b);
|
|
55509
55520
|
}
|
|
55510
55521
|
}
|
|
55511
55522
|
}, cancel(n) {
|
|
55512
|
-
|
|
55523
|
+
v("cancle stream:", n);
|
|
55513
55524
|
} });
|
|
55514
55525
|
}
|
|
55515
55526
|
convertOpenAIResponseToAnthropic(e) {
|
|
55516
|
-
|
|
55527
|
+
v("Original OpenAI response:", JSON.stringify(e, null, 2));
|
|
55517
55528
|
let t = e.choices[0];
|
|
55518
55529
|
if (!t) throw new Error("No choices found in OpenAI response");
|
|
55519
55530
|
let n = [];
|
|
55520
|
-
t.message.content && n.push({ type: "text", text: t.message.content }), t.message.tool_calls && t.message.tool_calls.length > 0 && t.message.tool_calls.forEach((r,
|
|
55521
|
-
let
|
|
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((r, d) => {
|
|
55532
|
+
let l = {};
|
|
55522
55533
|
try {
|
|
55523
|
-
let
|
|
55524
|
-
typeof
|
|
55534
|
+
let f = r.function.arguments || "{}";
|
|
55535
|
+
typeof f == "object" ? l = f : typeof f == "string" && (l = JSON.parse(f));
|
|
55525
55536
|
} catch {
|
|
55526
|
-
|
|
55537
|
+
l = { text: r.function.arguments || "" };
|
|
55527
55538
|
}
|
|
55528
|
-
n.push({ type: "tool_use", id: r.id, name: r.function.name, input:
|
|
55539
|
+
n.push({ type: "tool_use", id: r.id, name: r.function.name, input: l });
|
|
55529
55540
|
});
|
|
55530
55541
|
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 } };
|
|
55531
|
-
return
|
|
55542
|
+
return v("Conversion complete, final Anthropic response:", JSON.stringify(o, null, 2)), o;
|
|
55532
55543
|
}
|
|
55533
55544
|
};
|
|
55534
|
-
var
|
|
55545
|
+
var U = class {
|
|
55535
55546
|
name = "gemini";
|
|
55536
55547
|
endPoint = "/v1beta/models/:modelAndAction";
|
|
55537
55548
|
transformRequestIn(e, t) {
|
|
@@ -55539,22 +55550,22 @@ var q = class {
|
|
|
55539
55550
|
let o;
|
|
55540
55551
|
n.role === "assistant" ? o = "model" : (["user", "system", "tool"].includes(n.role), o = "user");
|
|
55541
55552
|
let r = [];
|
|
55542
|
-
return typeof n.content == "string" ? r.push({ text: n.content }) : Array.isArray(n.content) && r.push(...n.content.map((
|
|
55543
|
-
if (
|
|
55544
|
-
})), Array.isArray(n.tool_calls) && r.push(...n.tool_calls.map((
|
|
55553
|
+
return typeof n.content == "string" ? r.push({ text: n.content }) : Array.isArray(n.content) && r.push(...n.content.map((d) => {
|
|
55554
|
+
if (d.type === "text") return { text: d.text || "" };
|
|
55555
|
+
})), Array.isArray(n.tool_calls) && r.push(...n.tool_calls.map((d) => ({ functionCall: { id: d.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: d.function.name, args: JSON.parse(d.function.arguments || "{}") } }))), { role: o, parts: r };
|
|
55545
55556
|
}), tools: [{ functionDeclarations: e.tools?.map((n) => (delete n.function.parameters?.$schema, delete n.function.parameters?.additionalProperties, n.function.parameters?.properties && Object.keys(n.function.parameters.properties).forEach((o) => {
|
|
55546
55557
|
delete n.function.parameters.properties[o].$schema, delete n.function.parameters.properties[o].additionalProperties, n.function.parameters.properties[o].items && typeof n.function.parameters.properties[o].items == "object" && (delete n.function.parameters.properties[o].items.$schema, delete n.function.parameters.properties[o].items.additionalProperties), n.function.parameters.properties[o].type === "string" && (["enum", "date-time"].includes(n.function.parameters.properties[o].format) || delete n.function.parameters.properties[o].format);
|
|
55547
55558
|
}), { 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 } } };
|
|
55548
55559
|
}
|
|
55549
55560
|
transformRequestOut(e) {
|
|
55550
|
-
let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens,
|
|
55551
|
-
return Array.isArray(t) && t.forEach((
|
|
55552
|
-
typeof
|
|
55553
|
-
}), Array.isArray(n) && (
|
|
55554
|
-
Array.isArray(
|
|
55555
|
-
|
|
55561
|
+
let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens, d = e.temperature, l = e.stream, f = e.tool_choice, a = { messages: [], model: o, max_tokens: r, temperature: d, stream: l, tool_choice: f };
|
|
55562
|
+
return Array.isArray(t) && t.forEach((m) => {
|
|
55563
|
+
typeof m == "string" ? a.messages.push({ role: "user", content: m }) : typeof m.text == "string" ? a.messages.push({ role: "user", content: m.text || null }) : m.role === "user" ? a.messages.push({ role: "user", content: m?.parts?.map((g) => ({ type: "text", text: g.text || "" })) || [] }) : m.role === "model" && a.messages.push({ role: "assistant", content: m?.parts?.map((g) => ({ type: "text", text: g.text || "" })) || [] });
|
|
55564
|
+
}), Array.isArray(n) && (a.tools = [], n.forEach((m) => {
|
|
55565
|
+
Array.isArray(m.functionDeclarations) && m.functionDeclarations.forEach((g) => {
|
|
55566
|
+
a.tools.push({ type: "function", function: { name: g.name, description: g.description, parameters: g.parameters } });
|
|
55556
55567
|
});
|
|
55557
|
-
})),
|
|
55568
|
+
})), a;
|
|
55558
55569
|
}
|
|
55559
55570
|
async transformResponseOut(e) {
|
|
55560
55571
|
if (e.headers.get("Content-Type")?.includes("application/json")) {
|
|
@@ -55564,23 +55575,23 @@ var q = class {
|
|
|
55564
55575
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55565
55576
|
if (!e.body) return e;
|
|
55566
55577
|
let t = new TextDecoder(), n = new TextEncoder(), o = new ReadableStream({ async start(r) {
|
|
55567
|
-
let
|
|
55578
|
+
let d = e.body.getReader();
|
|
55568
55579
|
try {
|
|
55569
55580
|
for (; ; ) {
|
|
55570
|
-
let { done:
|
|
55571
|
-
if (
|
|
55572
|
-
let
|
|
55573
|
-
if (
|
|
55581
|
+
let { done: l, value: f } = await d.read();
|
|
55582
|
+
if (l) break;
|
|
55583
|
+
let a = t.decode(f, { stream: true });
|
|
55584
|
+
if (a.startsWith("data: ")) a = a.slice(6).trim();
|
|
55574
55585
|
else break;
|
|
55575
|
-
|
|
55576
|
-
let
|
|
55577
|
-
`), tool_calls:
|
|
55578
|
-
|
|
55586
|
+
v("gemini chunk:", a), a = JSON.parse(a);
|
|
55587
|
+
let m = a.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 || {}) } })), g = { choices: [{ delta: { role: "assistant", content: a.candidates[0].content.parts.filter((C) => C.text).map((C) => C.text).join(`
|
|
55588
|
+
`), tool_calls: m.length > 0 ? m : void 0 }, finish_reason: a.candidates[0].finishReason?.toLowerCase() || null, index: a.candidates[0].index || m.length > 0 ? 1 : 0, logprobs: null }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), id: a.responseId || "", model: a.modelVersion || "", object: "chat.completion.chunk", system_fingerprint: "fp_a49d71b8a1" };
|
|
55589
|
+
v("gemini response:", JSON.stringify(g, null, 2)), r.enqueue(n.encode(`data: ${JSON.stringify(g)}
|
|
55579
55590
|
|
|
55580
55591
|
`));
|
|
55581
55592
|
}
|
|
55582
|
-
} catch (
|
|
55583
|
-
r.error(
|
|
55593
|
+
} catch (l) {
|
|
55594
|
+
r.error(l);
|
|
55584
55595
|
} finally {
|
|
55585
55596
|
r.close();
|
|
55586
55597
|
}
|
|
@@ -55601,61 +55612,61 @@ var j = class {
|
|
|
55601
55612
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55602
55613
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55603
55614
|
if (!e.body) return e;
|
|
55604
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false,
|
|
55605
|
-
let
|
|
55615
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false, d = new ReadableStream({ async start(l) {
|
|
55616
|
+
let f = e.body.getReader();
|
|
55606
55617
|
try {
|
|
55607
55618
|
for (; ; ) {
|
|
55608
|
-
let { done:
|
|
55609
|
-
if (
|
|
55610
|
-
let
|
|
55619
|
+
let { done: a, value: m } = await f.read();
|
|
55620
|
+
if (a) break;
|
|
55621
|
+
let C = t.decode(m, { stream: true }).split(`
|
|
55611
55622
|
`);
|
|
55612
|
-
for (let
|
|
55613
|
-
let
|
|
55614
|
-
if (
|
|
55615
|
-
o +=
|
|
55616
|
-
let
|
|
55617
|
-
delete
|
|
55618
|
-
let y = `data: ${JSON.stringify(
|
|
55623
|
+
for (let p of C) if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") try {
|
|
55624
|
+
let u = JSON.parse(p.slice(6));
|
|
55625
|
+
if (u.choices?.[0]?.delta?.reasoning_content) {
|
|
55626
|
+
o += u.choices[0].delta.reasoning_content;
|
|
55627
|
+
let i = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, thinking: { content: u.choices[0].delta.reasoning_content } } }] };
|
|
55628
|
+
delete i.choices[0].delta.reasoning_content;
|
|
55629
|
+
let y = `data: ${JSON.stringify(i)}
|
|
55619
55630
|
|
|
55620
55631
|
`;
|
|
55621
|
-
|
|
55632
|
+
l.enqueue(n.encode(y));
|
|
55622
55633
|
continue;
|
|
55623
55634
|
}
|
|
55624
|
-
if (
|
|
55635
|
+
if (u.choices?.[0]?.delta?.content && o && !r) {
|
|
55625
55636
|
r = true;
|
|
55626
|
-
let
|
|
55637
|
+
let i = Date.now().toString(), y = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, content: null, thinking: { content: o, signature: i } } }] };
|
|
55627
55638
|
delete y.choices[0].delta.reasoning_content;
|
|
55628
|
-
let
|
|
55639
|
+
let h = `data: ${JSON.stringify(y)}
|
|
55629
55640
|
|
|
55630
55641
|
`;
|
|
55631
|
-
|
|
55642
|
+
l.enqueue(n.encode(h));
|
|
55632
55643
|
}
|
|
55633
|
-
if (
|
|
55634
|
-
r &&
|
|
55635
|
-
let
|
|
55644
|
+
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) {
|
|
55645
|
+
r && u.choices[0].index++;
|
|
55646
|
+
let i = `data: ${JSON.stringify(u)}
|
|
55636
55647
|
|
|
55637
55648
|
`;
|
|
55638
|
-
|
|
55649
|
+
l.enqueue(n.encode(i));
|
|
55639
55650
|
}
|
|
55640
55651
|
} catch {
|
|
55641
|
-
|
|
55652
|
+
l.enqueue(n.encode(p + `
|
|
55642
55653
|
`));
|
|
55643
55654
|
}
|
|
55644
|
-
else
|
|
55655
|
+
else l.enqueue(n.encode(p + `
|
|
55645
55656
|
`));
|
|
55646
55657
|
}
|
|
55647
|
-
} catch (
|
|
55648
|
-
|
|
55658
|
+
} catch (a) {
|
|
55659
|
+
l.error(a);
|
|
55649
55660
|
} finally {
|
|
55650
55661
|
try {
|
|
55651
|
-
|
|
55652
|
-
} catch (
|
|
55653
|
-
console.error("Error releasing reader lock:",
|
|
55662
|
+
f.releaseLock();
|
|
55663
|
+
} catch (a) {
|
|
55664
|
+
console.error("Error releasing reader lock:", a);
|
|
55654
55665
|
}
|
|
55655
|
-
|
|
55666
|
+
l.close();
|
|
55656
55667
|
}
|
|
55657
55668
|
} });
|
|
55658
|
-
return new Response(
|
|
55669
|
+
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" } });
|
|
55659
55670
|
}
|
|
55660
55671
|
return e;
|
|
55661
55672
|
}
|
|
@@ -55679,65 +55690,65 @@ Examples:
|
|
|
55679
55690
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55680
55691
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55681
55692
|
if (!e.body) return e;
|
|
55682
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "",
|
|
55683
|
-
let
|
|
55693
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "", d = new ReadableStream({ async start(l) {
|
|
55694
|
+
let f = e.body.getReader();
|
|
55684
55695
|
try {
|
|
55685
55696
|
for (; ; ) {
|
|
55686
|
-
let { done:
|
|
55687
|
-
if (
|
|
55688
|
-
let
|
|
55697
|
+
let { done: a, value: m } = await f.read();
|
|
55698
|
+
if (a) break;
|
|
55699
|
+
let C = t.decode(m, { stream: true }).split(`
|
|
55689
55700
|
`);
|
|
55690
|
-
for (let
|
|
55691
|
-
let
|
|
55692
|
-
if (
|
|
55693
|
-
let
|
|
55694
|
-
if (
|
|
55695
|
-
o =
|
|
55701
|
+
for (let p of C) if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") try {
|
|
55702
|
+
let u = JSON.parse(p.slice(6));
|
|
55703
|
+
if (u.choices[0]?.delta?.tool_calls?.length) {
|
|
55704
|
+
let i = u.choices[0].delta.tool_calls[0];
|
|
55705
|
+
if (i.function?.name === "ExitTool") {
|
|
55706
|
+
o = i.index;
|
|
55696
55707
|
continue;
|
|
55697
|
-
} else if (o > -1 &&
|
|
55698
|
-
r +=
|
|
55708
|
+
} else if (o > -1 && i.index === o && i.function.arguments) {
|
|
55709
|
+
r += i.function.arguments;
|
|
55699
55710
|
try {
|
|
55700
55711
|
let y = JSON.parse(r);
|
|
55701
|
-
|
|
55702
|
-
let
|
|
55712
|
+
u.choices = [{ delta: { role: "assistant", content: y.response || "" } }];
|
|
55713
|
+
let h = `data: ${JSON.stringify(u)}
|
|
55703
55714
|
|
|
55704
55715
|
`;
|
|
55705
|
-
|
|
55716
|
+
l.enqueue(n.encode(h));
|
|
55706
55717
|
} catch {
|
|
55707
55718
|
}
|
|
55708
55719
|
continue;
|
|
55709
55720
|
}
|
|
55710
55721
|
}
|
|
55711
|
-
if (
|
|
55712
|
-
let
|
|
55722
|
+
if (u.choices?.[0]?.delta && Object.keys(u.choices[0].delta).length > 0) {
|
|
55723
|
+
let i = `data: ${JSON.stringify(u)}
|
|
55713
55724
|
|
|
55714
55725
|
`;
|
|
55715
|
-
|
|
55726
|
+
l.enqueue(n.encode(i));
|
|
55716
55727
|
}
|
|
55717
55728
|
} catch {
|
|
55718
|
-
|
|
55729
|
+
l.enqueue(n.encode(p + `
|
|
55719
55730
|
`));
|
|
55720
55731
|
}
|
|
55721
|
-
else
|
|
55732
|
+
else l.enqueue(n.encode(p + `
|
|
55722
55733
|
`));
|
|
55723
55734
|
}
|
|
55724
|
-
} catch (
|
|
55725
|
-
|
|
55735
|
+
} catch (a) {
|
|
55736
|
+
l.error(a);
|
|
55726
55737
|
} finally {
|
|
55727
55738
|
try {
|
|
55728
|
-
|
|
55729
|
-
} catch (
|
|
55730
|
-
console.error("Error releasing reader lock:",
|
|
55739
|
+
f.releaseLock();
|
|
55740
|
+
} catch (a) {
|
|
55741
|
+
console.error("Error releasing reader lock:", a);
|
|
55731
55742
|
}
|
|
55732
|
-
|
|
55743
|
+
l.close();
|
|
55733
55744
|
}
|
|
55734
55745
|
} });
|
|
55735
|
-
return new Response(
|
|
55746
|
+
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" } });
|
|
55736
55747
|
}
|
|
55737
55748
|
return e;
|
|
55738
55749
|
}
|
|
55739
55750
|
};
|
|
55740
|
-
var
|
|
55751
|
+
var D = class {
|
|
55741
55752
|
name = "openrouter";
|
|
55742
55753
|
transformRequestIn(e) {
|
|
55743
55754
|
return e.model.includes("claude") || e.messages.forEach((t) => {
|
|
@@ -55752,105 +55763,105 @@ var U = class {
|
|
|
55752
55763
|
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55753
55764
|
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55754
55765
|
if (!e.body) return e;
|
|
55755
|
-
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "",
|
|
55756
|
-
let
|
|
55757
|
-
let y =
|
|
55766
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", d = false, l = "", f = new ReadableStream({ async start(a) {
|
|
55767
|
+
let m = e.body.getReader(), g = (p, u, i) => {
|
|
55768
|
+
let y = p.split(`
|
|
55758
55769
|
`);
|
|
55759
|
-
for (let
|
|
55770
|
+
for (let h of y) h.trim() && u.enqueue(i.encode(h + `
|
|
55760
55771
|
`));
|
|
55761
|
-
},
|
|
55762
|
-
let { controller:
|
|
55763
|
-
if (
|
|
55764
|
-
let
|
|
55772
|
+
}, C = (p, u) => {
|
|
55773
|
+
let { controller: i, encoder: y } = u;
|
|
55774
|
+
if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") {
|
|
55775
|
+
let h = p.slice(6);
|
|
55765
55776
|
try {
|
|
55766
|
-
let
|
|
55767
|
-
if (
|
|
55768
|
-
|
|
55769
|
-
let P = { ...
|
|
55777
|
+
let c = JSON.parse(h);
|
|
55778
|
+
if (c.choices?.[0]?.delta?.content && !u.hasTextContent() && u.setHasTextContent(true), c.choices?.[0]?.delta?.reasoning) {
|
|
55779
|
+
u.appendReasoningContent(c.choices[0].delta.reasoning);
|
|
55780
|
+
let P = { ...c, choices: [{ ...c.choices?.[0], delta: { ...c.choices[0].delta, thinking: { content: c.choices[0].delta.reasoning } } }] };
|
|
55770
55781
|
P.choices?.[0]?.delta && delete P.choices[0].delta.reasoning;
|
|
55771
|
-
let
|
|
55782
|
+
let b = `data: ${JSON.stringify(P)}
|
|
55772
55783
|
|
|
55773
55784
|
`;
|
|
55774
|
-
|
|
55785
|
+
i.enqueue(y.encode(b));
|
|
55775
55786
|
return;
|
|
55776
55787
|
}
|
|
55777
|
-
if (
|
|
55778
|
-
|
|
55779
|
-
let P = Date.now().toString(),
|
|
55780
|
-
|
|
55781
|
-
let
|
|
55788
|
+
if (c.choices?.[0]?.delta?.content && u.reasoningContent() && !u.isReasoningComplete()) {
|
|
55789
|
+
u.setReasoningComplete(true);
|
|
55790
|
+
let P = Date.now().toString(), b = { ...c, choices: [{ ...c.choices?.[0], delta: { ...c.choices[0].delta, content: null, thinking: { content: u.reasoningContent(), signature: P } } }] };
|
|
55791
|
+
b.choices?.[0]?.delta && delete b.choices[0].delta.reasoning;
|
|
55792
|
+
let _ = `data: ${JSON.stringify(b)}
|
|
55782
55793
|
|
|
55783
55794
|
`;
|
|
55784
|
-
|
|
55795
|
+
i.enqueue(y.encode(_));
|
|
55785
55796
|
}
|
|
55786
|
-
|
|
55787
|
-
let
|
|
55797
|
+
c.choices?.[0]?.delta?.reasoning && delete c.choices[0].delta.reasoning, c.choices?.[0]?.delta?.tool_calls?.length && u.hasTextContent() && (typeof c.choices[0].index == "number" ? c.choices[0].index += 1 : c.choices[0].index = 1);
|
|
55798
|
+
let k = `data: ${JSON.stringify(c)}
|
|
55788
55799
|
|
|
55789
55800
|
`;
|
|
55790
|
-
|
|
55801
|
+
i.enqueue(y.encode(k));
|
|
55791
55802
|
} catch {
|
|
55792
|
-
|
|
55803
|
+
i.enqueue(y.encode(p + `
|
|
55793
55804
|
`));
|
|
55794
55805
|
}
|
|
55795
|
-
} else
|
|
55806
|
+
} else i.enqueue(y.encode(p + `
|
|
55796
55807
|
`));
|
|
55797
55808
|
};
|
|
55798
55809
|
try {
|
|
55799
55810
|
for (; ; ) {
|
|
55800
|
-
let { done:
|
|
55801
|
-
if (
|
|
55802
|
-
|
|
55811
|
+
let { done: p, value: u } = await m.read();
|
|
55812
|
+
if (p) {
|
|
55813
|
+
l.trim() && g(l, a, n);
|
|
55803
55814
|
break;
|
|
55804
55815
|
}
|
|
55805
|
-
if (!
|
|
55806
|
-
let
|
|
55816
|
+
if (!u || u.length === 0) continue;
|
|
55817
|
+
let i;
|
|
55807
55818
|
try {
|
|
55808
|
-
|
|
55809
|
-
} catch (
|
|
55810
|
-
console.warn("Failed to decode chunk",
|
|
55819
|
+
i = t.decode(u, { stream: true });
|
|
55820
|
+
} catch (h) {
|
|
55821
|
+
console.warn("Failed to decode chunk", h);
|
|
55811
55822
|
continue;
|
|
55812
55823
|
}
|
|
55813
|
-
if (
|
|
55814
|
-
if (
|
|
55824
|
+
if (i.length === 0) continue;
|
|
55825
|
+
if (l += i, l.length > 1e6) {
|
|
55815
55826
|
console.warn("Buffer size exceeds limit, processing partial data");
|
|
55816
|
-
let
|
|
55827
|
+
let h = l.split(`
|
|
55817
55828
|
`);
|
|
55818
|
-
|
|
55819
|
-
for (let
|
|
55820
|
-
|
|
55821
|
-
} catch (
|
|
55822
|
-
console.error("Error processing line:",
|
|
55829
|
+
l = h.pop() || "";
|
|
55830
|
+
for (let c of h) if (c.trim()) try {
|
|
55831
|
+
C(c, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (k) => o = k, reasoningContent: () => r, appendReasoningContent: (k) => r += k, isReasoningComplete: () => d, setReasoningComplete: (k) => d = k });
|
|
55832
|
+
} catch (k) {
|
|
55833
|
+
console.error("Error processing line:", c, k), a.enqueue(n.encode(c + `
|
|
55823
55834
|
`));
|
|
55824
55835
|
}
|
|
55825
55836
|
continue;
|
|
55826
55837
|
}
|
|
55827
|
-
let y =
|
|
55838
|
+
let y = l.split(`
|
|
55828
55839
|
`);
|
|
55829
|
-
|
|
55830
|
-
for (let
|
|
55831
|
-
|
|
55832
|
-
} catch (
|
|
55833
|
-
console.error("Error processing line:",
|
|
55840
|
+
l = y.pop() || "";
|
|
55841
|
+
for (let h of y) if (h.trim()) try {
|
|
55842
|
+
C(h, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (c) => o = c, reasoningContent: () => r, appendReasoningContent: (c) => r += c, isReasoningComplete: () => d, setReasoningComplete: (c) => d = c });
|
|
55843
|
+
} catch (c) {
|
|
55844
|
+
console.error("Error processing line:", h, c), a.enqueue(n.encode(h + `
|
|
55834
55845
|
`));
|
|
55835
55846
|
}
|
|
55836
55847
|
}
|
|
55837
|
-
} catch (
|
|
55838
|
-
console.error("Stream error:",
|
|
55848
|
+
} catch (p) {
|
|
55849
|
+
console.error("Stream error:", p), a.error(p);
|
|
55839
55850
|
} finally {
|
|
55840
55851
|
try {
|
|
55841
|
-
|
|
55842
|
-
} catch (
|
|
55843
|
-
console.error("Error releasing reader lock:",
|
|
55852
|
+
m.releaseLock();
|
|
55853
|
+
} catch (p) {
|
|
55854
|
+
console.error("Error releasing reader lock:", p);
|
|
55844
55855
|
}
|
|
55845
|
-
|
|
55856
|
+
a.close();
|
|
55846
55857
|
}
|
|
55847
55858
|
} });
|
|
55848
|
-
return new Response(
|
|
55859
|
+
return new Response(f, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
55849
55860
|
}
|
|
55850
55861
|
return e;
|
|
55851
55862
|
}
|
|
55852
55863
|
};
|
|
55853
|
-
var
|
|
55864
|
+
var B = class {
|
|
55854
55865
|
constructor(e) {
|
|
55855
55866
|
this.options = e;
|
|
55856
55867
|
this.max_tokens = this.options?.max_tokens;
|
|
@@ -55861,14 +55872,137 @@ var D = class {
|
|
|
55861
55872
|
return e.max_tokens && e.max_tokens > this.max_tokens && (e.max_tokens = this.max_tokens), e;
|
|
55862
55873
|
}
|
|
55863
55874
|
};
|
|
55864
|
-
var
|
|
55865
|
-
|
|
55875
|
+
var R = [];
|
|
55876
|
+
for (let s = 0; s < 256; ++s) R.push((s + 256).toString(16).slice(1));
|
|
55877
|
+
function le(s, e = 0) {
|
|
55878
|
+
return (R[s[e + 0]] + R[s[e + 1]] + R[s[e + 2]] + R[s[e + 3]] + "-" + R[s[e + 4]] + R[s[e + 5]] + "-" + R[s[e + 6]] + R[s[e + 7]] + "-" + R[s[e + 8]] + R[s[e + 9]] + "-" + R[s[e + 10]] + R[s[e + 11]] + R[s[e + 12]] + R[s[e + 13]] + R[s[e + 14]] + R[s[e + 15]]).toLowerCase();
|
|
55879
|
+
}
|
|
55880
|
+
var V = new Uint8Array(256);
|
|
55881
|
+
var z = V.length;
|
|
55882
|
+
function X() {
|
|
55883
|
+
return z > V.length - 16 && ((0, import_crypto.randomFillSync)(V), z = 0), V.slice(z, z += 16);
|
|
55884
|
+
}
|
|
55885
|
+
var Q = { randomUUID: import_crypto2.randomUUID };
|
|
55886
|
+
function xe(s, e, t) {
|
|
55887
|
+
if (Q.randomUUID && !e && !s) return Q.randomUUID();
|
|
55888
|
+
s = s || {};
|
|
55889
|
+
let n = s.random ?? s.rng?.() ?? X();
|
|
55890
|
+
if (n.length < 16) throw new Error("Random bytes length must be >= 16");
|
|
55891
|
+
if (n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, e) {
|
|
55892
|
+
if (t = t || 0, t < 0 || t + 16 > e.length) throw new RangeError(`UUID byte range ${t}:${t + 15} is out of buffer bounds`);
|
|
55893
|
+
for (let o = 0; o < 16; ++o) e[t + o] = n[o];
|
|
55894
|
+
return e;
|
|
55895
|
+
}
|
|
55896
|
+
return le(n);
|
|
55897
|
+
}
|
|
55898
|
+
var Z = xe;
|
|
55899
|
+
var W = class {
|
|
55900
|
+
name = "groq";
|
|
55901
|
+
async transformRequestIn(e) {
|
|
55902
|
+
return e.messages.forEach((t) => {
|
|
55903
|
+
Array.isArray(t.content) ? t.content.forEach((n) => {
|
|
55904
|
+
n.cache_control && delete n.cache_control;
|
|
55905
|
+
}) : t.cache_control && delete t.cache_control;
|
|
55906
|
+
}), Array.isArray(e.tools) && e.tools.forEach((t) => {
|
|
55907
|
+
delete t.function.parameters.$schema;
|
|
55908
|
+
}), e;
|
|
55909
|
+
}
|
|
55910
|
+
async transformResponseOut(e) {
|
|
55911
|
+
if (e.headers.get("Content-Type")?.includes("application/json")) {
|
|
55912
|
+
let t = await e.json();
|
|
55913
|
+
return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
|
|
55914
|
+
} else if (e.headers.get("Content-Type")?.includes("stream")) {
|
|
55915
|
+
if (!e.body) return e;
|
|
55916
|
+
let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", d = false, l = "", f = new ReadableStream({ async start(a) {
|
|
55917
|
+
let m = e.body.getReader(), g = (p, u, i) => {
|
|
55918
|
+
let y = p.split(`
|
|
55919
|
+
`);
|
|
55920
|
+
for (let h of y) h.trim() && u.enqueue(i.encode(h + `
|
|
55921
|
+
`));
|
|
55922
|
+
}, C = (p, u) => {
|
|
55923
|
+
let { controller: i, encoder: y } = u;
|
|
55924
|
+
if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") {
|
|
55925
|
+
let h = p.slice(6);
|
|
55926
|
+
try {
|
|
55927
|
+
let c = JSON.parse(h);
|
|
55928
|
+
if (c.error) throw new Error(JSON.stringify(c));
|
|
55929
|
+
c.choices?.[0]?.delta?.content && !u.hasTextContent() && u.setHasTextContent(true), c.choices?.[0]?.delta?.tool_calls?.length && c.choices?.[0]?.delta?.tool_calls.forEach((P) => {
|
|
55930
|
+
P.id = `call_${Z()}`;
|
|
55931
|
+
}), c.choices?.[0]?.delta?.tool_calls?.length && u.hasTextContent() && (typeof c.choices[0].index == "number" ? c.choices[0].index += 1 : c.choices[0].index = 1);
|
|
55932
|
+
let k = `data: ${JSON.stringify(c)}
|
|
55933
|
+
|
|
55934
|
+
`;
|
|
55935
|
+
i.enqueue(y.encode(k));
|
|
55936
|
+
} catch {
|
|
55937
|
+
i.enqueue(y.encode(p + `
|
|
55938
|
+
`));
|
|
55939
|
+
}
|
|
55940
|
+
} else i.enqueue(y.encode(p + `
|
|
55941
|
+
`));
|
|
55942
|
+
};
|
|
55943
|
+
try {
|
|
55944
|
+
for (; ; ) {
|
|
55945
|
+
let { done: p, value: u } = await m.read();
|
|
55946
|
+
if (p) {
|
|
55947
|
+
l.trim() && g(l, a, n);
|
|
55948
|
+
break;
|
|
55949
|
+
}
|
|
55950
|
+
if (!u || u.length === 0) continue;
|
|
55951
|
+
let i;
|
|
55952
|
+
try {
|
|
55953
|
+
i = t.decode(u, { stream: true });
|
|
55954
|
+
} catch (h) {
|
|
55955
|
+
console.warn("Failed to decode chunk", h);
|
|
55956
|
+
continue;
|
|
55957
|
+
}
|
|
55958
|
+
if (i.length === 0) continue;
|
|
55959
|
+
if (l += i, l.length > 1e6) {
|
|
55960
|
+
console.warn("Buffer size exceeds limit, processing partial data");
|
|
55961
|
+
let h = l.split(`
|
|
55962
|
+
`);
|
|
55963
|
+
l = h.pop() || "";
|
|
55964
|
+
for (let c of h) if (c.trim()) try {
|
|
55965
|
+
C(c, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (k) => o = k, reasoningContent: () => r, appendReasoningContent: (k) => r += k, isReasoningComplete: () => d, setReasoningComplete: (k) => d = k });
|
|
55966
|
+
} catch (k) {
|
|
55967
|
+
console.error("Error processing line:", c, k), a.enqueue(n.encode(c + `
|
|
55968
|
+
`));
|
|
55969
|
+
}
|
|
55970
|
+
continue;
|
|
55971
|
+
}
|
|
55972
|
+
let y = l.split(`
|
|
55973
|
+
`);
|
|
55974
|
+
l = y.pop() || "";
|
|
55975
|
+
for (let h of y) if (h.trim()) try {
|
|
55976
|
+
C(h, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (c) => o = c, reasoningContent: () => r, appendReasoningContent: (c) => r += c, isReasoningComplete: () => d, setReasoningComplete: (c) => d = c });
|
|
55977
|
+
} catch (c) {
|
|
55978
|
+
console.error("Error processing line:", h, c), a.enqueue(n.encode(h + `
|
|
55979
|
+
`));
|
|
55980
|
+
}
|
|
55981
|
+
}
|
|
55982
|
+
} catch (p) {
|
|
55983
|
+
console.error("Stream error:", p), a.error(p);
|
|
55984
|
+
} finally {
|
|
55985
|
+
try {
|
|
55986
|
+
m.releaseLock();
|
|
55987
|
+
} catch (p) {
|
|
55988
|
+
console.error("Error releasing reader lock:", p);
|
|
55989
|
+
}
|
|
55990
|
+
a.close();
|
|
55991
|
+
}
|
|
55992
|
+
} });
|
|
55993
|
+
return new Response(f, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
|
|
55994
|
+
}
|
|
55995
|
+
return e;
|
|
55996
|
+
}
|
|
55997
|
+
};
|
|
55998
|
+
var de = { AnthropicTransformer: q, GeminiTransformer: U, DeepseekTransformer: j, TooluseTransformer: J, OpenrouterTransformer: D, MaxTokenTransformer: B, GroqTransformer: W };
|
|
55999
|
+
var G = class {
|
|
55866
56000
|
constructor(e) {
|
|
55867
56001
|
this.configService = e;
|
|
55868
56002
|
}
|
|
55869
56003
|
transformers = /* @__PURE__ */ new Map();
|
|
55870
56004
|
registerTransformer(e, t) {
|
|
55871
|
-
this.transformers.set(e, t),
|
|
56005
|
+
this.transformers.set(e, t), v(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
|
|
55872
56006
|
}
|
|
55873
56007
|
getTransformer(e) {
|
|
55874
56008
|
return this.transformers.get(e);
|
|
@@ -55898,9 +56032,9 @@ var B = class {
|
|
|
55898
56032
|
try {
|
|
55899
56033
|
let t = import_node_module.default._load;
|
|
55900
56034
|
if (import_node_module.default._load = function(n, o, r) {
|
|
55901
|
-
return n === "claude-code-router" ? { log:
|
|
56035
|
+
return n === "claude-code-router" ? { log: v } : t.apply(import_node_module.default, arguments);
|
|
55902
56036
|
}, e.path) {
|
|
55903
|
-
let n =
|
|
56037
|
+
let n = Y(Y.resolve(e.path));
|
|
55904
56038
|
if (n) {
|
|
55905
56039
|
let o = new n(e.options);
|
|
55906
56040
|
if (!o.name) throw new Error(`Transformer instance from ${e.path} does not have a name property.`);
|
|
@@ -55909,19 +56043,19 @@ var B = class {
|
|
|
55909
56043
|
}
|
|
55910
56044
|
return false;
|
|
55911
56045
|
} catch (t) {
|
|
55912
|
-
return
|
|
56046
|
+
return v(`load transformer (${e.path}) error:`, t.message, t.stack), false;
|
|
55913
56047
|
}
|
|
55914
56048
|
}
|
|
55915
56049
|
async initialize() {
|
|
55916
56050
|
try {
|
|
55917
56051
|
await this.registerDefaultTransformersInternal(), await this.loadFromConfig();
|
|
55918
56052
|
} catch (e) {
|
|
55919
|
-
|
|
56053
|
+
v("TransformerService init error:", e);
|
|
55920
56054
|
}
|
|
55921
56055
|
}
|
|
55922
56056
|
async registerDefaultTransformersInternal() {
|
|
55923
56057
|
try {
|
|
55924
|
-
Object.values(
|
|
56058
|
+
Object.values(de).forEach((e) => {
|
|
55925
56059
|
if ("TransformerName" in e && typeof e.TransformerName == "string") this.registerTransformer(e.TransformerName, e);
|
|
55926
56060
|
else {
|
|
55927
56061
|
let t = new e();
|
|
@@ -55929,7 +56063,7 @@ var B = class {
|
|
|
55929
56063
|
}
|
|
55930
56064
|
});
|
|
55931
56065
|
} catch (e) {
|
|
55932
|
-
|
|
56066
|
+
v("transformer regist error:", e);
|
|
55933
56067
|
}
|
|
55934
56068
|
}
|
|
55935
56069
|
async loadFromConfig() {
|
|
@@ -55937,20 +56071,20 @@ var B = class {
|
|
|
55937
56071
|
for (let t of e) await this.registerTransformerFromConfig(t);
|
|
55938
56072
|
}
|
|
55939
56073
|
};
|
|
55940
|
-
function
|
|
55941
|
-
let
|
|
55942
|
-
return
|
|
56074
|
+
function _e() {
|
|
56075
|
+
let s = (0, import_fastify.default)({});
|
|
56076
|
+
return s.setErrorHandler(ie), s.register(import_cors.default), s;
|
|
55943
56077
|
}
|
|
55944
|
-
var
|
|
56078
|
+
var te = class {
|
|
55945
56079
|
app;
|
|
55946
56080
|
configService;
|
|
55947
56081
|
llmService;
|
|
55948
56082
|
providerService;
|
|
55949
56083
|
transformerService;
|
|
55950
56084
|
constructor(e = {}) {
|
|
55951
|
-
this.configService = new
|
|
56085
|
+
this.configService = new I(e), this.transformerService = new G(this.configService), this.transformerService.initialize().finally(() => {
|
|
55952
56086
|
this.providerService = new F(this.configService, this.transformerService), this.llmService = new $(this.providerService);
|
|
55953
|
-
}), this.app =
|
|
56087
|
+
}), this.app = _e();
|
|
55954
56088
|
}
|
|
55955
56089
|
async register(e, t) {
|
|
55956
56090
|
await this.app.register(e, t);
|
|
@@ -55964,29 +56098,29 @@ var G = class {
|
|
|
55964
56098
|
try {
|
|
55965
56099
|
let r = n.body;
|
|
55966
56100
|
if (!r || !r.model) return o.code(400).send({ error: "Missing model in request body" });
|
|
55967
|
-
let [
|
|
55968
|
-
r.model =
|
|
56101
|
+
let [d, l] = r.model.split(",");
|
|
56102
|
+
r.model = l, n.provider = d;
|
|
55969
56103
|
return;
|
|
55970
56104
|
} catch (r) {
|
|
55971
56105
|
return n.log.error("Error in modelProviderMiddleware:", r), o.code(500).send({ error: "Internal server error" });
|
|
55972
56106
|
}
|
|
55973
|
-
}), this.app.register(
|
|
56107
|
+
}), this.app.register(ce);
|
|
55974
56108
|
let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
|
|
55975
|
-
|
|
56109
|
+
v(`\u{1F680} LLMs API server listening on ${e}`);
|
|
55976
56110
|
let t = async (n) => {
|
|
55977
|
-
|
|
56111
|
+
v(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
|
|
55978
56112
|
};
|
|
55979
56113
|
process.on("SIGINT", () => t("SIGINT")), process.on("SIGTERM", () => t("SIGTERM"));
|
|
55980
56114
|
} catch (e) {
|
|
55981
|
-
|
|
56115
|
+
v(`Error starting server: ${e}`), process.exit(1);
|
|
55982
56116
|
}
|
|
55983
56117
|
}
|
|
55984
56118
|
};
|
|
55985
|
-
var
|
|
56119
|
+
var tn = te;
|
|
55986
56120
|
|
|
55987
56121
|
// src/server.ts
|
|
55988
56122
|
var createServer = (config) => {
|
|
55989
|
-
const server = new
|
|
56123
|
+
const server = new tn(config);
|
|
55990
56124
|
return server;
|
|
55991
56125
|
};
|
|
55992
56126
|
|
|
@@ -56091,6 +56225,33 @@ var router = async (req, res, config) => {
|
|
|
56091
56225
|
return;
|
|
56092
56226
|
};
|
|
56093
56227
|
|
|
56228
|
+
// src/middleware/auth.ts
|
|
56229
|
+
var apiKeyAuth = (config) => (req, reply, done) => {
|
|
56230
|
+
if (["/", "/health"].includes(req.url)) {
|
|
56231
|
+
return done();
|
|
56232
|
+
}
|
|
56233
|
+
const apiKey = config.APIKEY;
|
|
56234
|
+
if (!apiKey) {
|
|
56235
|
+
return done();
|
|
56236
|
+
}
|
|
56237
|
+
const authKey = req.headers.authorization || req.headers["x-api-key"];
|
|
56238
|
+
if (!authKey) {
|
|
56239
|
+
reply.status(401).send("APIKEY is missing");
|
|
56240
|
+
return;
|
|
56241
|
+
}
|
|
56242
|
+
let token = "";
|
|
56243
|
+
if (authKey.startsWith("Bearer")) {
|
|
56244
|
+
token = authKey.split(" ")[1];
|
|
56245
|
+
} else {
|
|
56246
|
+
token = authKey;
|
|
56247
|
+
}
|
|
56248
|
+
if (token !== apiKey) {
|
|
56249
|
+
reply.status(401).send("Invalid API key");
|
|
56250
|
+
return;
|
|
56251
|
+
}
|
|
56252
|
+
done();
|
|
56253
|
+
};
|
|
56254
|
+
|
|
56094
56255
|
// src/utils/processCheck.ts
|
|
56095
56256
|
var import_fs2 = require("fs");
|
|
56096
56257
|
function incrementReferenceCount() {
|
|
@@ -56192,6 +56353,13 @@ async function run(options = {}) {
|
|
|
56192
56353
|
await initializeClaudeConfig();
|
|
56193
56354
|
await initDir();
|
|
56194
56355
|
const config = await initConfig();
|
|
56356
|
+
let HOST = config.HOST;
|
|
56357
|
+
if (config.HOST && !config.APIKEY) {
|
|
56358
|
+
HOST = "127.0.0.1";
|
|
56359
|
+
console.warn(
|
|
56360
|
+
"\u26A0\uFE0F API key is not set. HOST is forced to 127.0.0.1."
|
|
56361
|
+
);
|
|
56362
|
+
}
|
|
56195
56363
|
const port = options.port || 3456;
|
|
56196
56364
|
savePid(process.pid);
|
|
56197
56365
|
process.on("SIGINT", () => {
|
|
@@ -56203,12 +56371,14 @@ async function run(options = {}) {
|
|
|
56203
56371
|
cleanupPidFile();
|
|
56204
56372
|
process.exit(0);
|
|
56205
56373
|
});
|
|
56374
|
+
console.log(HOST);
|
|
56206
56375
|
const servicePort = process.env.SERVICE_PORT ? parseInt(process.env.SERVICE_PORT) : port;
|
|
56207
56376
|
const server = createServer({
|
|
56208
56377
|
jsonPath: CONFIG_FILE,
|
|
56209
56378
|
initialConfig: {
|
|
56210
56379
|
// ...config,
|
|
56211
56380
|
providers: config.Providers || config.providers,
|
|
56381
|
+
HOST,
|
|
56212
56382
|
PORT: servicePort,
|
|
56213
56383
|
LOG_FILE: (0, import_path2.join)(
|
|
56214
56384
|
(0, import_os.homedir)(),
|
|
@@ -56217,6 +56387,7 @@ async function run(options = {}) {
|
|
|
56217
56387
|
)
|
|
56218
56388
|
}
|
|
56219
56389
|
});
|
|
56390
|
+
server.addHook("preHandler", apiKeyAuth(config));
|
|
56220
56391
|
server.addHook(
|
|
56221
56392
|
"preHandler",
|
|
56222
56393
|
async (req, reply) => router(req, reply, config)
|
|
@@ -56276,12 +56447,17 @@ async function closeService() {
|
|
|
56276
56447
|
|
|
56277
56448
|
// src/utils/codeCommand.ts
|
|
56278
56449
|
async function executeCodeCommand(args = []) {
|
|
56450
|
+
const config = await readConfigFile();
|
|
56279
56451
|
const env = {
|
|
56280
56452
|
...process.env,
|
|
56281
56453
|
ANTHROPIC_AUTH_TOKEN: "test",
|
|
56282
56454
|
ANTHROPIC_BASE_URL: `http://127.0.0.1:3456`,
|
|
56283
56455
|
API_TIMEOUT_MS: "600000"
|
|
56284
56456
|
};
|
|
56457
|
+
if (config?.APIKEY) {
|
|
56458
|
+
env.ANTHROPIC_API_KEY = config.APIKEY;
|
|
56459
|
+
delete env.ANTHROPIC_AUTH_TOKEN;
|
|
56460
|
+
}
|
|
56285
56461
|
incrementReferenceCount();
|
|
56286
56462
|
const claudePath = process.env.CLAUDE_PATH || "claude";
|
|
56287
56463
|
const claudeProcess = (0, import_child_process.spawn)(claudePath, args, {
|
|
@@ -56305,7 +56481,7 @@ async function executeCodeCommand(args = []) {
|
|
|
56305
56481
|
}
|
|
56306
56482
|
|
|
56307
56483
|
// package.json
|
|
56308
|
-
var version = "1.0.
|
|
56484
|
+
var version = "1.0.20";
|
|
56309
56485
|
|
|
56310
56486
|
// src/cli.ts
|
|
56311
56487
|
var import_child_process2 = require("child_process");
|