deep-roon-mcp 0.2.2 → 0.3.2
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 +13 -0
- package/dist/THIRD_PARTY_LICENSES.txt +76 -0
- package/dist/deep-roon-mcp.js +2622 -294
- package/package.json +1 -1
package/dist/deep-roon-mcp.js
CHANGED
|
@@ -459,11 +459,11 @@ var require_codegen = __commonJS({
|
|
|
459
459
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
460
460
|
return `${varKind} ${this.name}${rhs};` + _n;
|
|
461
461
|
}
|
|
462
|
-
optimizeNames(names2,
|
|
462
|
+
optimizeNames(names2, constants2) {
|
|
463
463
|
if (!names2[this.name.str])
|
|
464
464
|
return;
|
|
465
465
|
if (this.rhs)
|
|
466
|
-
this.rhs = optimizeExpr(this.rhs, names2,
|
|
466
|
+
this.rhs = optimizeExpr(this.rhs, names2, constants2);
|
|
467
467
|
return this;
|
|
468
468
|
}
|
|
469
469
|
get names() {
|
|
@@ -483,10 +483,10 @@ var require_codegen = __commonJS({
|
|
|
483
483
|
render({ _n }) {
|
|
484
484
|
return `${this.lhs} = ${this.rhs};` + _n;
|
|
485
485
|
}
|
|
486
|
-
optimizeNames(names2,
|
|
486
|
+
optimizeNames(names2, constants2) {
|
|
487
487
|
if (this.lhs instanceof code_1.Name && !names2[this.lhs.str] && !this.sideEffects)
|
|
488
488
|
return;
|
|
489
|
-
this.rhs = optimizeExpr(this.rhs, names2,
|
|
489
|
+
this.rhs = optimizeExpr(this.rhs, names2, constants2);
|
|
490
490
|
return this;
|
|
491
491
|
}
|
|
492
492
|
get names() {
|
|
@@ -562,8 +562,8 @@ var require_codegen = __commonJS({
|
|
|
562
562
|
optimizeNodes() {
|
|
563
563
|
return `${this.code}` ? this : void 0;
|
|
564
564
|
}
|
|
565
|
-
optimizeNames(names2,
|
|
566
|
-
this.code = optimizeExpr(this.code, names2,
|
|
565
|
+
optimizeNames(names2, constants2) {
|
|
566
|
+
this.code = optimizeExpr(this.code, names2, constants2);
|
|
567
567
|
return this;
|
|
568
568
|
}
|
|
569
569
|
get names() {
|
|
@@ -595,12 +595,12 @@ var require_codegen = __commonJS({
|
|
|
595
595
|
}
|
|
596
596
|
return nodes.length > 0 ? this : void 0;
|
|
597
597
|
}
|
|
598
|
-
optimizeNames(names2,
|
|
598
|
+
optimizeNames(names2, constants2) {
|
|
599
599
|
const { nodes } = this;
|
|
600
600
|
let i = nodes.length;
|
|
601
601
|
while (i--) {
|
|
602
602
|
const n = nodes[i];
|
|
603
|
-
if (n.optimizeNames(names2,
|
|
603
|
+
if (n.optimizeNames(names2, constants2))
|
|
604
604
|
continue;
|
|
605
605
|
subtractNames(names2, n.names);
|
|
606
606
|
nodes.splice(i, 1);
|
|
@@ -665,12 +665,12 @@ var require_codegen = __commonJS({
|
|
|
665
665
|
return void 0;
|
|
666
666
|
return this;
|
|
667
667
|
}
|
|
668
|
-
optimizeNames(names2,
|
|
668
|
+
optimizeNames(names2, constants2) {
|
|
669
669
|
var _a3;
|
|
670
|
-
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2,
|
|
671
|
-
if (!(super.optimizeNames(names2,
|
|
670
|
+
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2, constants2);
|
|
671
|
+
if (!(super.optimizeNames(names2, constants2) || this.else))
|
|
672
672
|
return;
|
|
673
|
-
this.condition = optimizeExpr(this.condition, names2,
|
|
673
|
+
this.condition = optimizeExpr(this.condition, names2, constants2);
|
|
674
674
|
return this;
|
|
675
675
|
}
|
|
676
676
|
get names() {
|
|
@@ -699,10 +699,10 @@ var require_codegen = __commonJS({
|
|
|
699
699
|
render(opts) {
|
|
700
700
|
return `for(${this.iteration})` + super.render(opts);
|
|
701
701
|
}
|
|
702
|
-
optimizeNames(names2,
|
|
703
|
-
if (!super.optimizeNames(names2,
|
|
702
|
+
optimizeNames(names2, constants2) {
|
|
703
|
+
if (!super.optimizeNames(names2, constants2))
|
|
704
704
|
return;
|
|
705
|
-
this.iteration = optimizeExpr(this.iteration, names2,
|
|
705
|
+
this.iteration = optimizeExpr(this.iteration, names2, constants2);
|
|
706
706
|
return this;
|
|
707
707
|
}
|
|
708
708
|
get names() {
|
|
@@ -744,10 +744,10 @@ var require_codegen = __commonJS({
|
|
|
744
744
|
render(opts) {
|
|
745
745
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
746
746
|
}
|
|
747
|
-
optimizeNames(names2,
|
|
748
|
-
if (!super.optimizeNames(names2,
|
|
747
|
+
optimizeNames(names2, constants2) {
|
|
748
|
+
if (!super.optimizeNames(names2, constants2))
|
|
749
749
|
return;
|
|
750
|
-
this.iterable = optimizeExpr(this.iterable, names2,
|
|
750
|
+
this.iterable = optimizeExpr(this.iterable, names2, constants2);
|
|
751
751
|
return this;
|
|
752
752
|
}
|
|
753
753
|
get names() {
|
|
@@ -798,11 +798,11 @@ var require_codegen = __commonJS({
|
|
|
798
798
|
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
|
|
799
799
|
return this;
|
|
800
800
|
}
|
|
801
|
-
optimizeNames(names2,
|
|
801
|
+
optimizeNames(names2, constants2) {
|
|
802
802
|
var _a3, _b;
|
|
803
|
-
super.optimizeNames(names2,
|
|
804
|
-
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2,
|
|
805
|
-
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names2,
|
|
803
|
+
super.optimizeNames(names2, constants2);
|
|
804
|
+
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2, constants2);
|
|
805
|
+
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names2, constants2);
|
|
806
806
|
return this;
|
|
807
807
|
}
|
|
808
808
|
get names() {
|
|
@@ -1114,7 +1114,7 @@ var require_codegen = __commonJS({
|
|
|
1114
1114
|
return from instanceof code_1._CodeOrName ? addNames(names2, from.names) : names2;
|
|
1115
1115
|
}
|
|
1116
1116
|
__name(addExprNames, "addExprNames");
|
|
1117
|
-
function optimizeExpr(expr, names2,
|
|
1117
|
+
function optimizeExpr(expr, names2, constants2) {
|
|
1118
1118
|
if (expr instanceof code_1.Name)
|
|
1119
1119
|
return replaceName(expr);
|
|
1120
1120
|
if (!canOptimize(expr))
|
|
@@ -1129,7 +1129,7 @@ var require_codegen = __commonJS({
|
|
|
1129
1129
|
return items2;
|
|
1130
1130
|
}, []));
|
|
1131
1131
|
function replaceName(n) {
|
|
1132
|
-
const c =
|
|
1132
|
+
const c = constants2[n.str];
|
|
1133
1133
|
if (c === void 0 || names2[n.str] !== 1)
|
|
1134
1134
|
return n;
|
|
1135
1135
|
delete names2[n.str];
|
|
@@ -1137,7 +1137,7 @@ var require_codegen = __commonJS({
|
|
|
1137
1137
|
}
|
|
1138
1138
|
__name(replaceName, "replaceName");
|
|
1139
1139
|
function canOptimize(e) {
|
|
1140
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names2[c.str] === 1 &&
|
|
1140
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names2[c.str] === 1 && constants2[c.str] !== void 0);
|
|
1141
1141
|
}
|
|
1142
1142
|
__name(canOptimize, "canOptimize");
|
|
1143
1143
|
}
|
|
@@ -4036,7 +4036,7 @@ var require_schemes = __commonJS({
|
|
|
4036
4036
|
return urnComponent;
|
|
4037
4037
|
}
|
|
4038
4038
|
__name(urnuuidSerialize, "urnuuidSerialize");
|
|
4039
|
-
var
|
|
4039
|
+
var http2 = (
|
|
4040
4040
|
/** @type {SchemeHandler} */
|
|
4041
4041
|
{
|
|
4042
4042
|
scheme: "http",
|
|
@@ -4049,7 +4049,7 @@ var require_schemes = __commonJS({
|
|
|
4049
4049
|
/** @type {SchemeHandler} */
|
|
4050
4050
|
{
|
|
4051
4051
|
scheme: "https",
|
|
4052
|
-
domainHost:
|
|
4052
|
+
domainHost: http2.domainHost,
|
|
4053
4053
|
parse: httpParse,
|
|
4054
4054
|
serialize: httpSerialize
|
|
4055
4055
|
}
|
|
@@ -4093,7 +4093,7 @@ var require_schemes = __commonJS({
|
|
|
4093
4093
|
var SCHEMES = (
|
|
4094
4094
|
/** @type {Record<SchemeName, SchemeHandler>} */
|
|
4095
4095
|
{
|
|
4096
|
-
http,
|
|
4096
|
+
http: http2,
|
|
4097
4097
|
https,
|
|
4098
4098
|
ws,
|
|
4099
4099
|
wss,
|
|
@@ -4879,8 +4879,8 @@ var require_core = __commonJS({
|
|
|
4879
4879
|
return this;
|
|
4880
4880
|
}
|
|
4881
4881
|
case "object": {
|
|
4882
|
-
const
|
|
4883
|
-
this._cache.delete(
|
|
4882
|
+
const cacheKey2 = schemaKeyRef;
|
|
4883
|
+
this._cache.delete(cacheKey2);
|
|
4884
4884
|
let id = schemaKeyRef[this.opts.schemaId];
|
|
4885
4885
|
if (id) {
|
|
4886
4886
|
id = (0, resolve_1.normalizeId)(id);
|
|
@@ -7624,13 +7624,122 @@ var require_dist = __commonJS({
|
|
|
7624
7624
|
}
|
|
7625
7625
|
});
|
|
7626
7626
|
|
|
7627
|
+
// node_modules/content-type/index.js
|
|
7628
|
+
var require_content_type = __commonJS({
|
|
7629
|
+
"node_modules/content-type/index.js"(exports2) {
|
|
7630
|
+
"use strict";
|
|
7631
|
+
var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g;
|
|
7632
|
+
var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/;
|
|
7633
|
+
var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
7634
|
+
var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g;
|
|
7635
|
+
var QUOTE_REGEXP = /([\\"])/g;
|
|
7636
|
+
var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
7637
|
+
exports2.format = format;
|
|
7638
|
+
exports2.parse = parse4;
|
|
7639
|
+
function format(obj2) {
|
|
7640
|
+
if (!obj2 || typeof obj2 !== "object") {
|
|
7641
|
+
throw new TypeError("argument obj is required");
|
|
7642
|
+
}
|
|
7643
|
+
var parameters = obj2.parameters;
|
|
7644
|
+
var type = obj2.type;
|
|
7645
|
+
if (!type || !TYPE_REGEXP.test(type)) {
|
|
7646
|
+
throw new TypeError("invalid type");
|
|
7647
|
+
}
|
|
7648
|
+
var string4 = type;
|
|
7649
|
+
if (parameters && typeof parameters === "object") {
|
|
7650
|
+
var param;
|
|
7651
|
+
var params = Object.keys(parameters).sort();
|
|
7652
|
+
for (var i = 0; i < params.length; i++) {
|
|
7653
|
+
param = params[i];
|
|
7654
|
+
if (!TOKEN_REGEXP.test(param)) {
|
|
7655
|
+
throw new TypeError("invalid parameter name");
|
|
7656
|
+
}
|
|
7657
|
+
string4 += "; " + param + "=" + qstring(parameters[param]);
|
|
7658
|
+
}
|
|
7659
|
+
}
|
|
7660
|
+
return string4;
|
|
7661
|
+
}
|
|
7662
|
+
__name(format, "format");
|
|
7663
|
+
function parse4(string4) {
|
|
7664
|
+
if (!string4) {
|
|
7665
|
+
throw new TypeError("argument string is required");
|
|
7666
|
+
}
|
|
7667
|
+
var header = typeof string4 === "object" ? getcontenttype(string4) : string4;
|
|
7668
|
+
if (typeof header !== "string") {
|
|
7669
|
+
throw new TypeError("argument string is required to be a string");
|
|
7670
|
+
}
|
|
7671
|
+
var index = header.indexOf(";");
|
|
7672
|
+
var type = index !== -1 ? header.slice(0, index).trim() : header.trim();
|
|
7673
|
+
if (!TYPE_REGEXP.test(type)) {
|
|
7674
|
+
throw new TypeError("invalid media type");
|
|
7675
|
+
}
|
|
7676
|
+
var obj2 = new ContentType(type.toLowerCase());
|
|
7677
|
+
if (index !== -1) {
|
|
7678
|
+
var key;
|
|
7679
|
+
var match;
|
|
7680
|
+
var value;
|
|
7681
|
+
PARAM_REGEXP.lastIndex = index;
|
|
7682
|
+
while (match = PARAM_REGEXP.exec(header)) {
|
|
7683
|
+
if (match.index !== index) {
|
|
7684
|
+
throw new TypeError("invalid parameter format");
|
|
7685
|
+
}
|
|
7686
|
+
index += match[0].length;
|
|
7687
|
+
key = match[1].toLowerCase();
|
|
7688
|
+
value = match[2];
|
|
7689
|
+
if (value.charCodeAt(0) === 34) {
|
|
7690
|
+
value = value.slice(1, -1);
|
|
7691
|
+
if (value.indexOf("\\") !== -1) {
|
|
7692
|
+
value = value.replace(QESC_REGEXP, "$1");
|
|
7693
|
+
}
|
|
7694
|
+
}
|
|
7695
|
+
obj2.parameters[key] = value;
|
|
7696
|
+
}
|
|
7697
|
+
if (index !== header.length) {
|
|
7698
|
+
throw new TypeError("invalid parameter format");
|
|
7699
|
+
}
|
|
7700
|
+
}
|
|
7701
|
+
return obj2;
|
|
7702
|
+
}
|
|
7703
|
+
__name(parse4, "parse");
|
|
7704
|
+
function getcontenttype(obj2) {
|
|
7705
|
+
var header;
|
|
7706
|
+
if (typeof obj2.getHeader === "function") {
|
|
7707
|
+
header = obj2.getHeader("content-type");
|
|
7708
|
+
} else if (typeof obj2.headers === "object") {
|
|
7709
|
+
header = obj2.headers && obj2.headers["content-type"];
|
|
7710
|
+
}
|
|
7711
|
+
if (typeof header !== "string") {
|
|
7712
|
+
throw new TypeError("content-type header is missing from object");
|
|
7713
|
+
}
|
|
7714
|
+
return header;
|
|
7715
|
+
}
|
|
7716
|
+
__name(getcontenttype, "getcontenttype");
|
|
7717
|
+
function qstring(val) {
|
|
7718
|
+
var str = String(val);
|
|
7719
|
+
if (TOKEN_REGEXP.test(str)) {
|
|
7720
|
+
return str;
|
|
7721
|
+
}
|
|
7722
|
+
if (str.length > 0 && !TEXT_REGEXP.test(str)) {
|
|
7723
|
+
throw new TypeError("invalid parameter value");
|
|
7724
|
+
}
|
|
7725
|
+
return '"' + str.replace(QUOTE_REGEXP, "\\$1") + '"';
|
|
7726
|
+
}
|
|
7727
|
+
__name(qstring, "qstring");
|
|
7728
|
+
function ContentType(type) {
|
|
7729
|
+
this.parameters = /* @__PURE__ */ Object.create(null);
|
|
7730
|
+
this.type = type;
|
|
7731
|
+
}
|
|
7732
|
+
__name(ContentType, "ContentType");
|
|
7733
|
+
}
|
|
7734
|
+
});
|
|
7735
|
+
|
|
7627
7736
|
// src/intern/proto/connection.ts
|
|
7628
|
-
var net,
|
|
7737
|
+
var net, crypto2, MAGIC, CONNECT_REQUEST_TEMPLATE, RoonConnection;
|
|
7629
7738
|
var init_connection = __esm({
|
|
7630
7739
|
"src/intern/proto/connection.ts"() {
|
|
7631
7740
|
"use strict";
|
|
7632
7741
|
net = __toESM(require("net"));
|
|
7633
|
-
|
|
7742
|
+
crypto2 = __toESM(require("crypto"));
|
|
7634
7743
|
MAGIC = Buffer.from("ROON");
|
|
7635
7744
|
CONNECT_REQUEST_TEMPLATE = "470181670000000100012c536f6f6c6f6f732e4d73672e446973747269627574656442726f6b65722e436f6e6e6563745265717565737424840e436c69656e7442726f6b65724964XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX228110436c69656e7442726f6b65724e616d650000000848512d30303435321b810f50726f746f636f6c56657273696f6e0000000232383e810c50726f746f636f6c48617368000000286161656464323265326536653435323233316537346464333039666662396432376139373531656420810c436c69656e744272616e63680000000a70726f64756374696f6e05030503";
|
|
7636
7745
|
RoonConnection = class {
|
|
@@ -7645,7 +7754,7 @@ var init_connection = __esm({
|
|
|
7645
7754
|
dataHandler = /* @__PURE__ */ __name(() => {
|
|
7646
7755
|
}, "dataHandler");
|
|
7647
7756
|
established = false;
|
|
7648
|
-
clientBrokerId =
|
|
7757
|
+
clientBrokerId = crypto2.randomBytes(16);
|
|
7649
7758
|
/**
|
|
7650
7759
|
* Fired when the socket closes for any reason (explicit close(), peer
|
|
7651
7760
|
* disconnect, error) so the remoting layer can fail in-flight requests
|
|
@@ -10028,13 +10137,13 @@ var require_buffer_util = __commonJS({
|
|
|
10028
10137
|
}
|
|
10029
10138
|
}
|
|
10030
10139
|
__name(_unmask, "_unmask");
|
|
10031
|
-
function
|
|
10140
|
+
function toArrayBuffer2(buf) {
|
|
10032
10141
|
if (buf.length === buf.buffer.byteLength) {
|
|
10033
10142
|
return buf.buffer;
|
|
10034
10143
|
}
|
|
10035
10144
|
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
10036
10145
|
}
|
|
10037
|
-
__name(
|
|
10146
|
+
__name(toArrayBuffer2, "toArrayBuffer");
|
|
10038
10147
|
function toBuffer(data) {
|
|
10039
10148
|
toBuffer.readOnly = true;
|
|
10040
10149
|
if (Buffer.isBuffer(data)) return data;
|
|
@@ -10053,7 +10162,7 @@ var require_buffer_util = __commonJS({
|
|
|
10053
10162
|
module2.exports = {
|
|
10054
10163
|
concat,
|
|
10055
10164
|
mask: _mask,
|
|
10056
|
-
toArrayBuffer,
|
|
10165
|
+
toArrayBuffer: toArrayBuffer2,
|
|
10057
10166
|
toBuffer,
|
|
10058
10167
|
unmask: _unmask
|
|
10059
10168
|
};
|
|
@@ -10732,7 +10841,7 @@ var require_receiver = __commonJS({
|
|
|
10732
10841
|
kStatusCode,
|
|
10733
10842
|
kWebSocket
|
|
10734
10843
|
} = require_constants();
|
|
10735
|
-
var { concat, toArrayBuffer, unmask } = require_buffer_util();
|
|
10844
|
+
var { concat, toArrayBuffer: toArrayBuffer2, unmask } = require_buffer_util();
|
|
10736
10845
|
var { isValidStatusCode, isValidUTF8 } = require_validation2();
|
|
10737
10846
|
var FastBuffer = Buffer[Symbol.species];
|
|
10738
10847
|
var GET_INFO = 0;
|
|
@@ -11214,7 +11323,7 @@ var require_receiver = __commonJS({
|
|
|
11214
11323
|
if (this._binaryType === "nodebuffer") {
|
|
11215
11324
|
data = concat(fragments, messageLength);
|
|
11216
11325
|
} else if (this._binaryType === "arraybuffer") {
|
|
11217
|
-
data =
|
|
11326
|
+
data = toArrayBuffer2(concat(fragments, messageLength));
|
|
11218
11327
|
} else if (this._binaryType === "blob") {
|
|
11219
11328
|
data = new Blob(fragments);
|
|
11220
11329
|
} else {
|
|
@@ -11857,7 +11966,7 @@ var require_event_target = __commonJS({
|
|
|
11857
11966
|
var kTarget = /* @__PURE__ */ Symbol("kTarget");
|
|
11858
11967
|
var kType = /* @__PURE__ */ Symbol("kType");
|
|
11859
11968
|
var kWasClean = /* @__PURE__ */ Symbol("kWasClean");
|
|
11860
|
-
var
|
|
11969
|
+
var Event2 = class {
|
|
11861
11970
|
static {
|
|
11862
11971
|
__name(this, "Event");
|
|
11863
11972
|
}
|
|
@@ -11884,9 +11993,9 @@ var require_event_target = __commonJS({
|
|
|
11884
11993
|
return this[kType];
|
|
11885
11994
|
}
|
|
11886
11995
|
};
|
|
11887
|
-
Object.defineProperty(
|
|
11888
|
-
Object.defineProperty(
|
|
11889
|
-
var
|
|
11996
|
+
Object.defineProperty(Event2.prototype, "target", { enumerable: true });
|
|
11997
|
+
Object.defineProperty(Event2.prototype, "type", { enumerable: true });
|
|
11998
|
+
var CloseEvent2 = class extends Event2 {
|
|
11890
11999
|
static {
|
|
11891
12000
|
__name(this, "CloseEvent");
|
|
11892
12001
|
}
|
|
@@ -11928,10 +12037,10 @@ var require_event_target = __commonJS({
|
|
|
11928
12037
|
return this[kWasClean];
|
|
11929
12038
|
}
|
|
11930
12039
|
};
|
|
11931
|
-
Object.defineProperty(
|
|
11932
|
-
Object.defineProperty(
|
|
11933
|
-
Object.defineProperty(
|
|
11934
|
-
var
|
|
12040
|
+
Object.defineProperty(CloseEvent2.prototype, "code", { enumerable: true });
|
|
12041
|
+
Object.defineProperty(CloseEvent2.prototype, "reason", { enumerable: true });
|
|
12042
|
+
Object.defineProperty(CloseEvent2.prototype, "wasClean", { enumerable: true });
|
|
12043
|
+
var ErrorEvent2 = class extends Event2 {
|
|
11935
12044
|
static {
|
|
11936
12045
|
__name(this, "ErrorEvent");
|
|
11937
12046
|
}
|
|
@@ -11962,9 +12071,9 @@ var require_event_target = __commonJS({
|
|
|
11962
12071
|
return this[kMessage];
|
|
11963
12072
|
}
|
|
11964
12073
|
};
|
|
11965
|
-
Object.defineProperty(
|
|
11966
|
-
Object.defineProperty(
|
|
11967
|
-
var
|
|
12074
|
+
Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: true });
|
|
12075
|
+
Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: true });
|
|
12076
|
+
var MessageEvent2 = class extends Event2 {
|
|
11968
12077
|
static {
|
|
11969
12078
|
__name(this, "MessageEvent");
|
|
11970
12079
|
}
|
|
@@ -11987,7 +12096,7 @@ var require_event_target = __commonJS({
|
|
|
11987
12096
|
return this[kData];
|
|
11988
12097
|
}
|
|
11989
12098
|
};
|
|
11990
|
-
Object.defineProperty(
|
|
12099
|
+
Object.defineProperty(MessageEvent2.prototype, "data", { enumerable: true });
|
|
11991
12100
|
var EventTarget = {
|
|
11992
12101
|
/**
|
|
11993
12102
|
* Register an event listener.
|
|
@@ -12010,7 +12119,7 @@ var require_event_target = __commonJS({
|
|
|
12010
12119
|
let wrapper;
|
|
12011
12120
|
if (type === "message") {
|
|
12012
12121
|
wrapper = /* @__PURE__ */ __name(function onMessage(data, isBinary) {
|
|
12013
|
-
const event = new
|
|
12122
|
+
const event = new MessageEvent2("message", {
|
|
12014
12123
|
data: isBinary ? data : data.toString()
|
|
12015
12124
|
});
|
|
12016
12125
|
event[kTarget] = this;
|
|
@@ -12018,7 +12127,7 @@ var require_event_target = __commonJS({
|
|
|
12018
12127
|
}, "onMessage");
|
|
12019
12128
|
} else if (type === "close") {
|
|
12020
12129
|
wrapper = /* @__PURE__ */ __name(function onClose(code, message) {
|
|
12021
|
-
const event = new
|
|
12130
|
+
const event = new CloseEvent2("close", {
|
|
12022
12131
|
code,
|
|
12023
12132
|
reason: message.toString(),
|
|
12024
12133
|
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
@@ -12028,7 +12137,7 @@ var require_event_target = __commonJS({
|
|
|
12028
12137
|
}, "onClose");
|
|
12029
12138
|
} else if (type === "error") {
|
|
12030
12139
|
wrapper = /* @__PURE__ */ __name(function onError(error62) {
|
|
12031
|
-
const event = new
|
|
12140
|
+
const event = new ErrorEvent2("error", {
|
|
12032
12141
|
error: error62,
|
|
12033
12142
|
message: error62.message
|
|
12034
12143
|
});
|
|
@@ -12037,7 +12146,7 @@ var require_event_target = __commonJS({
|
|
|
12037
12146
|
}, "onError");
|
|
12038
12147
|
} else if (type === "open") {
|
|
12039
12148
|
wrapper = /* @__PURE__ */ __name(function onOpen() {
|
|
12040
|
-
const event = new
|
|
12149
|
+
const event = new Event2("open");
|
|
12041
12150
|
event[kTarget] = this;
|
|
12042
12151
|
callListener(handler, this, event);
|
|
12043
12152
|
}, "onOpen");
|
|
@@ -12069,11 +12178,11 @@ var require_event_target = __commonJS({
|
|
|
12069
12178
|
}
|
|
12070
12179
|
};
|
|
12071
12180
|
module2.exports = {
|
|
12072
|
-
CloseEvent,
|
|
12073
|
-
ErrorEvent,
|
|
12074
|
-
Event,
|
|
12181
|
+
CloseEvent: CloseEvent2,
|
|
12182
|
+
ErrorEvent: ErrorEvent2,
|
|
12183
|
+
Event: Event2,
|
|
12075
12184
|
EventTarget,
|
|
12076
|
-
MessageEvent
|
|
12185
|
+
MessageEvent: MessageEvent2
|
|
12077
12186
|
};
|
|
12078
12187
|
function callListener(listener, thisArg, event) {
|
|
12079
12188
|
if (typeof listener === "object" && listener.handleEvent) {
|
|
@@ -12248,11 +12357,11 @@ var require_websocket = __commonJS({
|
|
|
12248
12357
|
"use strict";
|
|
12249
12358
|
var EventEmitter = require("events");
|
|
12250
12359
|
var https = require("https");
|
|
12251
|
-
var
|
|
12360
|
+
var http2 = require("http");
|
|
12252
12361
|
var net2 = require("net");
|
|
12253
12362
|
var tls = require("tls");
|
|
12254
12363
|
var { randomBytes: randomBytes2, createHash } = require("crypto");
|
|
12255
|
-
var { Duplex, Readable } = require("stream");
|
|
12364
|
+
var { Duplex, Readable: Readable2 } = require("stream");
|
|
12256
12365
|
var { URL: URL2 } = require("url");
|
|
12257
12366
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
12258
12367
|
var Receiver2 = require_receiver();
|
|
@@ -12806,7 +12915,7 @@ var require_websocket = __commonJS({
|
|
|
12806
12915
|
}
|
|
12807
12916
|
const defaultPort = isSecure ? 443 : 80;
|
|
12808
12917
|
const key = randomBytes2(16).toString("base64");
|
|
12809
|
-
const request = isSecure ? https.request :
|
|
12918
|
+
const request = isSecure ? https.request : http2.request;
|
|
12810
12919
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
12811
12920
|
let perMessageDeflate;
|
|
12812
12921
|
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
@@ -13327,7 +13436,7 @@ var require_websocket_server = __commonJS({
|
|
|
13327
13436
|
"node_modules/ws/lib/websocket-server.js"(exports2, module2) {
|
|
13328
13437
|
"use strict";
|
|
13329
13438
|
var EventEmitter = require("events");
|
|
13330
|
-
var
|
|
13439
|
+
var http2 = require("http");
|
|
13331
13440
|
var { Duplex } = require("stream");
|
|
13332
13441
|
var { createHash } = require("crypto");
|
|
13333
13442
|
var extension2 = require_extension();
|
|
@@ -13411,8 +13520,8 @@ var require_websocket_server = __commonJS({
|
|
|
13411
13520
|
);
|
|
13412
13521
|
}
|
|
13413
13522
|
if (options.port != null) {
|
|
13414
|
-
this._server =
|
|
13415
|
-
const body =
|
|
13523
|
+
this._server = http2.createServer((req, res) => {
|
|
13524
|
+
const body = http2.STATUS_CODES[426];
|
|
13416
13525
|
res.writeHead(426, {
|
|
13417
13526
|
"Content-Length": body.length,
|
|
13418
13527
|
"Content-Type": "text/plain"
|
|
@@ -13704,7 +13813,7 @@ var require_websocket_server = __commonJS({
|
|
|
13704
13813
|
}
|
|
13705
13814
|
__name(socketOnError, "socketOnError");
|
|
13706
13815
|
function abortHandshake(socket, code, message, headers) {
|
|
13707
|
-
message = message ||
|
|
13816
|
+
message = message || http2.STATUS_CODES[code];
|
|
13708
13817
|
headers = {
|
|
13709
13818
|
Connection: "close",
|
|
13710
13819
|
"Content-Type": "text/html",
|
|
@@ -13713,7 +13822,7 @@ var require_websocket_server = __commonJS({
|
|
|
13713
13822
|
};
|
|
13714
13823
|
socket.once("finish", socket.destroy);
|
|
13715
13824
|
socket.end(
|
|
13716
|
-
`HTTP/1.1 ${code} ${
|
|
13825
|
+
`HTTP/1.1 ${code} ${http2.STATUS_CODES[code]}\r
|
|
13717
13826
|
` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
|
|
13718
13827
|
);
|
|
13719
13828
|
}
|
|
@@ -14112,11 +14221,11 @@ var require_moo = __commonJS({
|
|
|
14112
14221
|
this.logger.log("MOO: bad message; has Content-Length but not Content-Type: ", msg);
|
|
14113
14222
|
return void 0;
|
|
14114
14223
|
} else if (msg.content_type == "application/json") {
|
|
14115
|
-
var
|
|
14224
|
+
var json3 = buf.toString("utf8", e + 1, e + 1 + msg.content_length);
|
|
14116
14225
|
try {
|
|
14117
|
-
msg.body = JSON.parse(
|
|
14226
|
+
msg.body = JSON.parse(json3);
|
|
14118
14227
|
} catch (e2) {
|
|
14119
|
-
this.logger.log("MOO: bad json body: ",
|
|
14228
|
+
this.logger.log("MOO: bad json body: ", json3, msg);
|
|
14120
14229
|
return void 0;
|
|
14121
14230
|
}
|
|
14122
14231
|
} else {
|
|
@@ -15416,7 +15525,7 @@ var require_lib2 = __commonJS({
|
|
|
15416
15525
|
var version2;
|
|
15417
15526
|
var init_package = __esm({
|
|
15418
15527
|
"package.json"() {
|
|
15419
|
-
version2 = "0.
|
|
15528
|
+
version2 = "0.3.2";
|
|
15420
15529
|
}
|
|
15421
15530
|
});
|
|
15422
15531
|
|
|
@@ -16706,6 +16815,9 @@ var init_focus = __esm({
|
|
|
16706
16815
|
}
|
|
16707
16816
|
});
|
|
16708
16817
|
|
|
16818
|
+
// src/index.ts
|
|
16819
|
+
var import_http = __toESM(require("http"));
|
|
16820
|
+
|
|
16709
16821
|
// node_modules/zod/v3/helpers/util.js
|
|
16710
16822
|
var util;
|
|
16711
16823
|
(function(util2) {
|
|
@@ -36636,13 +36748,13 @@ function initializeContext(params) {
|
|
|
36636
36748
|
};
|
|
36637
36749
|
}
|
|
36638
36750
|
__name(initializeContext, "initializeContext");
|
|
36639
|
-
function handleUnrepresentable(schema, ctx,
|
|
36751
|
+
function handleUnrepresentable(schema, ctx, json3, params, message) {
|
|
36640
36752
|
const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({ zodSchema: schema, path: params.path, message }) : ctx.unrepresentable;
|
|
36641
36753
|
if (result === "any")
|
|
36642
36754
|
return false;
|
|
36643
36755
|
if (result === void 0 || result === "throw")
|
|
36644
36756
|
throw new Error(message);
|
|
36645
|
-
Object.assign(
|
|
36757
|
+
Object.assign(json3, result);
|
|
36646
36758
|
return true;
|
|
36647
36759
|
}
|
|
36648
36760
|
__name(handleUnrepresentable, "handleUnrepresentable");
|
|
@@ -36885,12 +36997,12 @@ function foldObjects(members2) {
|
|
|
36885
36997
|
return folded;
|
|
36886
36998
|
}
|
|
36887
36999
|
__name(foldObjects, "foldObjects");
|
|
36888
|
-
function foldIntersection(
|
|
36889
|
-
const allOf =
|
|
37000
|
+
function foldIntersection(json3) {
|
|
37001
|
+
const allOf = json3.allOf;
|
|
36890
37002
|
if (!Array.isArray(allOf) || allOf.length < 2)
|
|
36891
37003
|
return;
|
|
36892
37004
|
for (const key of FOLDABLE_KEYS)
|
|
36893
|
-
if (key in
|
|
37005
|
+
if (key in json3)
|
|
36894
37006
|
return;
|
|
36895
37007
|
const unions = allOf.filter((m) => UNION_KEYS.some((k) => Array.isArray(m[k])));
|
|
36896
37008
|
let folded = null;
|
|
@@ -36909,8 +37021,8 @@ function foldIntersection(json2) {
|
|
|
36909
37021
|
}
|
|
36910
37022
|
if (!folded)
|
|
36911
37023
|
return;
|
|
36912
|
-
delete
|
|
36913
|
-
assignProps(
|
|
37024
|
+
delete json3.allOf;
|
|
37025
|
+
assignProps(json3, folded);
|
|
36914
37026
|
}
|
|
36915
37027
|
__name(foldIntersection, "foldIntersection");
|
|
36916
37028
|
function finalize(ctx, schema) {
|
|
@@ -36993,20 +37105,20 @@ function finalize(ctx, schema) {
|
|
|
36993
37105
|
if (ctx.intersections.length) {
|
|
36994
37106
|
const carriers = /* @__PURE__ */ new Map();
|
|
36995
37107
|
for (const seen2 of ctx.seen.values()) {
|
|
36996
|
-
for (const
|
|
36997
|
-
const allOf =
|
|
37108
|
+
for (const json3 of [seen2.schema, seen2.def]) {
|
|
37109
|
+
const allOf = json3?.allOf;
|
|
36998
37110
|
if (!Array.isArray(allOf))
|
|
36999
37111
|
continue;
|
|
37000
37112
|
const existing = carriers.get(allOf);
|
|
37001
37113
|
if (existing)
|
|
37002
|
-
existing.push(
|
|
37114
|
+
existing.push(json3);
|
|
37003
37115
|
else
|
|
37004
|
-
carriers.set(allOf, [
|
|
37116
|
+
carriers.set(allOf, [json3]);
|
|
37005
37117
|
}
|
|
37006
37118
|
}
|
|
37007
37119
|
for (const allOf of ctx.intersections) {
|
|
37008
|
-
for (const
|
|
37009
|
-
foldIntersection(
|
|
37120
|
+
for (const json3 of carriers.get(allOf) ?? [])
|
|
37121
|
+
foldIntersection(json3);
|
|
37010
37122
|
}
|
|
37011
37123
|
}
|
|
37012
37124
|
}
|
|
@@ -37244,29 +37356,29 @@ var exactPatterns = /* @__PURE__ */ new Map([
|
|
|
37244
37356
|
]);
|
|
37245
37357
|
var exactPattern = /* @__PURE__ */ __name((p) => exactPatterns.get(p) ?? p, "exactPattern");
|
|
37246
37358
|
var stringProcessor = /* @__PURE__ */ __name((schema, ctx, _json, _params) => {
|
|
37247
|
-
const
|
|
37248
|
-
|
|
37359
|
+
const json3 = _json;
|
|
37360
|
+
json3.type = "string";
|
|
37249
37361
|
const { minimum, maximum, format, patterns, contentEncoding, laxFormat } = aggregateChecks(schema);
|
|
37250
37362
|
if (typeof minimum === "number")
|
|
37251
|
-
|
|
37363
|
+
json3.minLength = minimum;
|
|
37252
37364
|
if (typeof maximum === "number")
|
|
37253
|
-
|
|
37365
|
+
json3.maxLength = maximum;
|
|
37254
37366
|
if (format) {
|
|
37255
|
-
|
|
37256
|
-
if (
|
|
37257
|
-
delete
|
|
37367
|
+
json3.format = formatMap[format] ?? format;
|
|
37368
|
+
if (json3.format === "")
|
|
37369
|
+
delete json3.format;
|
|
37258
37370
|
if (format === "time" || laxFormat) {
|
|
37259
|
-
delete
|
|
37371
|
+
delete json3.format;
|
|
37260
37372
|
}
|
|
37261
37373
|
}
|
|
37262
37374
|
if (contentEncoding)
|
|
37263
|
-
|
|
37375
|
+
json3.contentEncoding = contentEncoding;
|
|
37264
37376
|
if (patterns && patterns.size > 0) {
|
|
37265
37377
|
const patternList = [...patterns].map(exactPattern);
|
|
37266
37378
|
if (patternList.length === 1)
|
|
37267
|
-
|
|
37379
|
+
json3.pattern = patternList[0].source;
|
|
37268
37380
|
else if (patternList.length > 1) {
|
|
37269
|
-
|
|
37381
|
+
json3.allOf = [
|
|
37270
37382
|
...patternList.map((regex) => ({
|
|
37271
37383
|
...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
|
|
37272
37384
|
pattern: regex.source
|
|
@@ -37276,31 +37388,31 @@ var stringProcessor = /* @__PURE__ */ __name((schema, ctx, _json, _params) => {
|
|
|
37276
37388
|
}
|
|
37277
37389
|
}, "stringProcessor");
|
|
37278
37390
|
var numberProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37279
|
-
const
|
|
37391
|
+
const json3 = _json;
|
|
37280
37392
|
const { minimum, maximum, multipleOf, exclusiveMaximum, exclusiveMinimum, isInt } = aggregateChecks(schema);
|
|
37281
|
-
|
|
37393
|
+
json3.type = isInt ? "integer" : "number";
|
|
37282
37394
|
const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
|
|
37283
37395
|
const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
|
|
37284
37396
|
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
|
|
37285
37397
|
if (exMin) {
|
|
37286
37398
|
if (legacy) {
|
|
37287
|
-
|
|
37288
|
-
|
|
37399
|
+
json3.minimum = exclusiveMinimum;
|
|
37400
|
+
json3.exclusiveMinimum = true;
|
|
37289
37401
|
} else {
|
|
37290
|
-
|
|
37402
|
+
json3.exclusiveMinimum = exclusiveMinimum;
|
|
37291
37403
|
}
|
|
37292
37404
|
} else if (typeof minimum === "number") {
|
|
37293
|
-
|
|
37405
|
+
json3.minimum = minimum;
|
|
37294
37406
|
}
|
|
37295
37407
|
if (exMax) {
|
|
37296
37408
|
if (legacy) {
|
|
37297
|
-
|
|
37298
|
-
|
|
37409
|
+
json3.maximum = exclusiveMaximum;
|
|
37410
|
+
json3.exclusiveMaximum = true;
|
|
37299
37411
|
} else {
|
|
37300
|
-
|
|
37412
|
+
json3.exclusiveMaximum = exclusiveMaximum;
|
|
37301
37413
|
}
|
|
37302
37414
|
} else if (typeof maximum === "number") {
|
|
37303
|
-
|
|
37415
|
+
json3.maximum = maximum;
|
|
37304
37416
|
}
|
|
37305
37417
|
if (multipleOf) {
|
|
37306
37418
|
const divisors = /* @__PURE__ */ new Set();
|
|
@@ -37308,75 +37420,75 @@ var numberProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37308
37420
|
if (Number.isFinite(divisor) && divisor !== 0)
|
|
37309
37421
|
divisors.add(Math.abs(divisor));
|
|
37310
37422
|
else
|
|
37311
|
-
handleUnrepresentable(schema, ctx,
|
|
37423
|
+
handleUnrepresentable(schema, ctx, json3, params, `A multipleOf divisor of ${divisor} cannot be represented in JSON Schema`);
|
|
37312
37424
|
}
|
|
37313
37425
|
const [first, ...rest] = divisors;
|
|
37314
37426
|
if (first !== void 0)
|
|
37315
|
-
|
|
37427
|
+
json3.multipleOf = first;
|
|
37316
37428
|
if (rest.length)
|
|
37317
|
-
|
|
37429
|
+
json3.allOf = [...json3.allOf ?? [], ...rest.map((m) => ({ multipleOf: m }))];
|
|
37318
37430
|
}
|
|
37319
37431
|
}, "numberProcessor");
|
|
37320
|
-
var booleanProcessor = /* @__PURE__ */ __name((_schema, _ctx,
|
|
37321
|
-
|
|
37432
|
+
var booleanProcessor = /* @__PURE__ */ __name((_schema, _ctx, json3, _params) => {
|
|
37433
|
+
json3.type = "boolean";
|
|
37322
37434
|
}, "booleanProcessor");
|
|
37323
|
-
var bigintProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37324
|
-
handleUnrepresentable(schema, ctx,
|
|
37435
|
+
var bigintProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37436
|
+
handleUnrepresentable(schema, ctx, json3, params, "BigInt cannot be represented in JSON Schema");
|
|
37325
37437
|
}, "bigintProcessor");
|
|
37326
|
-
var symbolProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37327
|
-
handleUnrepresentable(schema, ctx,
|
|
37438
|
+
var symbolProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37439
|
+
handleUnrepresentable(schema, ctx, json3, params, "Symbols cannot be represented in JSON Schema");
|
|
37328
37440
|
}, "symbolProcessor");
|
|
37329
|
-
var nullProcessor = /* @__PURE__ */ __name((_schema, ctx,
|
|
37441
|
+
var nullProcessor = /* @__PURE__ */ __name((_schema, ctx, json3, _params) => {
|
|
37330
37442
|
if (ctx.target === "openapi-3.0") {
|
|
37331
|
-
|
|
37332
|
-
|
|
37333
|
-
|
|
37443
|
+
json3.type = "string";
|
|
37444
|
+
json3.nullable = true;
|
|
37445
|
+
json3.enum = [null];
|
|
37334
37446
|
} else {
|
|
37335
|
-
|
|
37447
|
+
json3.type = "null";
|
|
37336
37448
|
}
|
|
37337
37449
|
}, "nullProcessor");
|
|
37338
|
-
var undefinedProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37339
|
-
handleUnrepresentable(schema, ctx,
|
|
37450
|
+
var undefinedProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37451
|
+
handleUnrepresentable(schema, ctx, json3, params, "Undefined cannot be represented in JSON Schema");
|
|
37340
37452
|
}, "undefinedProcessor");
|
|
37341
|
-
var voidProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37342
|
-
handleUnrepresentable(schema, ctx,
|
|
37453
|
+
var voidProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37454
|
+
handleUnrepresentable(schema, ctx, json3, params, "Void cannot be represented in JSON Schema");
|
|
37343
37455
|
}, "voidProcessor");
|
|
37344
|
-
var neverProcessor = /* @__PURE__ */ __name((_schema, _ctx,
|
|
37345
|
-
|
|
37456
|
+
var neverProcessor = /* @__PURE__ */ __name((_schema, _ctx, json3, _params) => {
|
|
37457
|
+
json3.not = {};
|
|
37346
37458
|
}, "neverProcessor");
|
|
37347
37459
|
var anyProcessor = /* @__PURE__ */ __name((_schema, _ctx, _json, _params) => {
|
|
37348
37460
|
}, "anyProcessor");
|
|
37349
37461
|
var unknownProcessor = /* @__PURE__ */ __name((_schema, _ctx, _json, _params) => {
|
|
37350
37462
|
}, "unknownProcessor");
|
|
37351
|
-
var dateProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37352
|
-
handleUnrepresentable(schema, ctx,
|
|
37463
|
+
var dateProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37464
|
+
handleUnrepresentable(schema, ctx, json3, params, "Date cannot be represented in JSON Schema");
|
|
37353
37465
|
}, "dateProcessor");
|
|
37354
|
-
var enumProcessor = /* @__PURE__ */ __name((schema, _ctx,
|
|
37466
|
+
var enumProcessor = /* @__PURE__ */ __name((schema, _ctx, json3, _params) => {
|
|
37355
37467
|
const def = schema._zod.def;
|
|
37356
37468
|
const values = getEnumValues(def.entries);
|
|
37357
37469
|
if (values.length === 0) {
|
|
37358
|
-
|
|
37470
|
+
json3.not = {};
|
|
37359
37471
|
return;
|
|
37360
37472
|
}
|
|
37361
37473
|
if (values.every((v) => typeof v === "number"))
|
|
37362
|
-
|
|
37474
|
+
json3.type = "number";
|
|
37363
37475
|
if (values.every((v) => typeof v === "string"))
|
|
37364
|
-
|
|
37365
|
-
|
|
37476
|
+
json3.type = "string";
|
|
37477
|
+
json3.enum = values;
|
|
37366
37478
|
}, "enumProcessor");
|
|
37367
|
-
var literalProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37479
|
+
var literalProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37368
37480
|
const def = schema._zod.def;
|
|
37369
37481
|
if (def.values.length === 0) {
|
|
37370
|
-
|
|
37482
|
+
json3.not = {};
|
|
37371
37483
|
return;
|
|
37372
37484
|
}
|
|
37373
37485
|
const vals = [];
|
|
37374
37486
|
for (const val of def.values) {
|
|
37375
37487
|
if (val === void 0) {
|
|
37376
|
-
if (handleUnrepresentable(schema, ctx,
|
|
37488
|
+
if (handleUnrepresentable(schema, ctx, json3, params, "Literal `undefined` cannot be represented in JSON Schema"))
|
|
37377
37489
|
return;
|
|
37378
37490
|
} else if (typeof val === "bigint") {
|
|
37379
|
-
if (handleUnrepresentable(schema, ctx,
|
|
37491
|
+
if (handleUnrepresentable(schema, ctx, json3, params, "BigInt literals cannot be represented in JSON Schema"))
|
|
37380
37492
|
return;
|
|
37381
37493
|
vals.push(Number(val));
|
|
37382
37494
|
} else {
|
|
@@ -37386,37 +37498,37 @@ var literalProcessor = /* @__PURE__ */ __name((schema, ctx, json2, params) => {
|
|
|
37386
37498
|
if (vals.length === 0) {
|
|
37387
37499
|
} else if (vals.length === 1) {
|
|
37388
37500
|
const val = vals[0];
|
|
37389
|
-
|
|
37501
|
+
json3.type = val === null ? "null" : typeof val;
|
|
37390
37502
|
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
37391
|
-
|
|
37503
|
+
json3.enum = [val];
|
|
37392
37504
|
} else {
|
|
37393
|
-
|
|
37505
|
+
json3.const = val;
|
|
37394
37506
|
}
|
|
37395
37507
|
} else {
|
|
37396
37508
|
if (vals.every((v) => typeof v === "number"))
|
|
37397
|
-
|
|
37509
|
+
json3.type = "number";
|
|
37398
37510
|
if (vals.every((v) => typeof v === "string"))
|
|
37399
|
-
|
|
37511
|
+
json3.type = "string";
|
|
37400
37512
|
if (vals.every((v) => typeof v === "boolean"))
|
|
37401
|
-
|
|
37513
|
+
json3.type = "boolean";
|
|
37402
37514
|
if (vals.every((v) => v === null))
|
|
37403
|
-
|
|
37404
|
-
|
|
37515
|
+
json3.type = "null";
|
|
37516
|
+
json3.enum = vals;
|
|
37405
37517
|
}
|
|
37406
37518
|
}, "literalProcessor");
|
|
37407
|
-
var nanProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37408
|
-
handleUnrepresentable(schema, ctx,
|
|
37519
|
+
var nanProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37520
|
+
handleUnrepresentable(schema, ctx, json3, params, "NaN cannot be represented in JSON Schema");
|
|
37409
37521
|
}, "nanProcessor");
|
|
37410
|
-
var templateLiteralProcessor = /* @__PURE__ */ __name((schema, _ctx,
|
|
37411
|
-
const _json =
|
|
37522
|
+
var templateLiteralProcessor = /* @__PURE__ */ __name((schema, _ctx, json3, _params) => {
|
|
37523
|
+
const _json = json3;
|
|
37412
37524
|
const pattern = schema._zod.pattern;
|
|
37413
37525
|
if (!pattern)
|
|
37414
37526
|
throw new Error("Pattern not found in template literal");
|
|
37415
37527
|
_json.type = "string";
|
|
37416
37528
|
_json.pattern = pattern.source;
|
|
37417
37529
|
}, "templateLiteralProcessor");
|
|
37418
|
-
var fileProcessor = /* @__PURE__ */ __name((schema, _ctx,
|
|
37419
|
-
const _json =
|
|
37530
|
+
var fileProcessor = /* @__PURE__ */ __name((schema, _ctx, json3, _params) => {
|
|
37531
|
+
const _json = json3;
|
|
37420
37532
|
_json.type = "string";
|
|
37421
37533
|
_json.format = "binary";
|
|
37422
37534
|
_json.contentEncoding = "binary";
|
|
@@ -37434,34 +37546,34 @@ var fileProcessor = /* @__PURE__ */ __name((schema, _ctx, json2, _params) => {
|
|
|
37434
37546
|
else
|
|
37435
37547
|
_json.anyOf = mime.map((m) => ({ contentMediaType: m }));
|
|
37436
37548
|
}, "fileProcessor");
|
|
37437
|
-
var successProcessor = /* @__PURE__ */ __name((_schema, _ctx,
|
|
37438
|
-
|
|
37549
|
+
var successProcessor = /* @__PURE__ */ __name((_schema, _ctx, json3, _params) => {
|
|
37550
|
+
json3.type = "boolean";
|
|
37439
37551
|
}, "successProcessor");
|
|
37440
|
-
var customProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37441
|
-
handleUnrepresentable(schema, ctx,
|
|
37552
|
+
var customProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37553
|
+
handleUnrepresentable(schema, ctx, json3, params, "Custom types cannot be represented in JSON Schema");
|
|
37442
37554
|
}, "customProcessor");
|
|
37443
|
-
var functionProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37444
|
-
handleUnrepresentable(schema, ctx,
|
|
37555
|
+
var functionProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37556
|
+
handleUnrepresentable(schema, ctx, json3, params, "Function types cannot be represented in JSON Schema");
|
|
37445
37557
|
}, "functionProcessor");
|
|
37446
|
-
var transformProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37447
|
-
handleUnrepresentable(schema, ctx,
|
|
37558
|
+
var transformProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37559
|
+
handleUnrepresentable(schema, ctx, json3, params, "Transforms cannot be represented in JSON Schema");
|
|
37448
37560
|
}, "transformProcessor");
|
|
37449
|
-
var mapProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37450
|
-
handleUnrepresentable(schema, ctx,
|
|
37561
|
+
var mapProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37562
|
+
handleUnrepresentable(schema, ctx, json3, params, "Map cannot be represented in JSON Schema");
|
|
37451
37563
|
}, "mapProcessor");
|
|
37452
|
-
var setProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37453
|
-
handleUnrepresentable(schema, ctx,
|
|
37564
|
+
var setProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37565
|
+
handleUnrepresentable(schema, ctx, json3, params, "Set cannot be represented in JSON Schema");
|
|
37454
37566
|
}, "setProcessor");
|
|
37455
37567
|
var arrayProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37456
|
-
const
|
|
37568
|
+
const json3 = _json;
|
|
37457
37569
|
const def = schema._zod.def;
|
|
37458
37570
|
const { minimum, maximum } = aggregateChecks(schema);
|
|
37459
37571
|
if (typeof minimum === "number")
|
|
37460
|
-
|
|
37572
|
+
json3.minItems = minimum;
|
|
37461
37573
|
if (typeof maximum === "number")
|
|
37462
|
-
|
|
37463
|
-
|
|
37464
|
-
|
|
37574
|
+
json3.maxItems = maximum;
|
|
37575
|
+
json3.type = "array";
|
|
37576
|
+
json3.items = processSchema(def.element, ctx, {
|
|
37465
37577
|
...params,
|
|
37466
37578
|
path: [...params.path, "items"]
|
|
37467
37579
|
});
|
|
@@ -37478,17 +37590,17 @@ function inputOptin(schema) {
|
|
|
37478
37590
|
}
|
|
37479
37591
|
__name(inputOptin, "inputOptin");
|
|
37480
37592
|
var objectProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37481
|
-
const
|
|
37593
|
+
const json3 = _json;
|
|
37482
37594
|
const def = schema._zod.def;
|
|
37483
37595
|
const shape = def.shape;
|
|
37484
37596
|
const symbolKeys = Object.getOwnPropertySymbols(shape);
|
|
37485
|
-
if (symbolKeys.length && handleUnrepresentable(schema, ctx,
|
|
37597
|
+
if (symbolKeys.length && handleUnrepresentable(schema, ctx, json3, params, "Symbol keys cannot be represented in JSON Schema")) {
|
|
37486
37598
|
return;
|
|
37487
37599
|
}
|
|
37488
|
-
|
|
37489
|
-
|
|
37600
|
+
json3.type = "object";
|
|
37601
|
+
json3.properties = {};
|
|
37490
37602
|
for (const key in shape) {
|
|
37491
|
-
assignProp(
|
|
37603
|
+
assignProp(json3.properties, key, processSchema(shape[key], ctx, {
|
|
37492
37604
|
...params,
|
|
37493
37605
|
path: [...params.path, "properties", key]
|
|
37494
37606
|
}));
|
|
@@ -37501,21 +37613,21 @@ var objectProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37501
37613
|
}
|
|
37502
37614
|
}
|
|
37503
37615
|
if (requiredKeys.length > 0) {
|
|
37504
|
-
|
|
37616
|
+
json3.required = requiredKeys;
|
|
37505
37617
|
}
|
|
37506
37618
|
if (def.catchall?._zod.def.type === "never") {
|
|
37507
|
-
|
|
37619
|
+
json3.additionalProperties = false;
|
|
37508
37620
|
} else if (!def.catchall) {
|
|
37509
37621
|
if (ctx.io === "output")
|
|
37510
|
-
|
|
37622
|
+
json3.additionalProperties = false;
|
|
37511
37623
|
} else if (def.catchall) {
|
|
37512
|
-
|
|
37624
|
+
json3.additionalProperties = processSchema(def.catchall, ctx, {
|
|
37513
37625
|
...params,
|
|
37514
37626
|
path: [...params.path, "additionalProperties"]
|
|
37515
37627
|
});
|
|
37516
37628
|
}
|
|
37517
37629
|
}, "objectProcessor");
|
|
37518
|
-
var unionProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37630
|
+
var unionProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37519
37631
|
const def = schema._zod.def;
|
|
37520
37632
|
const isExclusive = def.inclusive === false;
|
|
37521
37633
|
const options = def.options.map((x, i) => processSchema(x, ctx, {
|
|
@@ -37523,12 +37635,12 @@ var unionProcessor = /* @__PURE__ */ __name((schema, ctx, json2, params) => {
|
|
|
37523
37635
|
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
|
|
37524
37636
|
}));
|
|
37525
37637
|
if (isExclusive) {
|
|
37526
|
-
|
|
37638
|
+
json3.oneOf = options;
|
|
37527
37639
|
} else {
|
|
37528
|
-
|
|
37640
|
+
json3.anyOf = options;
|
|
37529
37641
|
}
|
|
37530
37642
|
}, "unionProcessor");
|
|
37531
|
-
var intersectionProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37643
|
+
var intersectionProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37532
37644
|
const def = schema._zod.def;
|
|
37533
37645
|
const a = processSchema(def.left, ctx, {
|
|
37534
37646
|
...params,
|
|
@@ -37543,13 +37655,13 @@ var intersectionProcessor = /* @__PURE__ */ __name((schema, ctx, json2, params)
|
|
|
37543
37655
|
...isSimpleIntersection(a) ? a.allOf : [a],
|
|
37544
37656
|
...isSimpleIntersection(b) ? b.allOf : [b]
|
|
37545
37657
|
];
|
|
37546
|
-
|
|
37658
|
+
json3.allOf = allOf;
|
|
37547
37659
|
ctx.intersections.push(allOf);
|
|
37548
37660
|
}, "intersectionProcessor");
|
|
37549
37661
|
var tupleProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37550
|
-
const
|
|
37662
|
+
const json3 = _json;
|
|
37551
37663
|
const def = schema._zod.def;
|
|
37552
|
-
|
|
37664
|
+
json3.type = "array";
|
|
37553
37665
|
const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
|
|
37554
37666
|
const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
|
|
37555
37667
|
const prefixItems = def.items.map((x, i) => processSchema(x, ctx, {
|
|
@@ -37571,70 +37683,70 @@ var tupleProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37571
37683
|
const maxItems = def.items.length;
|
|
37572
37684
|
const isClosed = !def.rest;
|
|
37573
37685
|
if (ctx.target === "draft-2020-12") {
|
|
37574
|
-
|
|
37686
|
+
json3.prefixItems = prefixItems;
|
|
37575
37687
|
if (isClosed) {
|
|
37576
|
-
|
|
37688
|
+
json3.items = false;
|
|
37577
37689
|
} else if (rest) {
|
|
37578
|
-
|
|
37690
|
+
json3.items = rest;
|
|
37579
37691
|
}
|
|
37580
37692
|
if (minItems > 0)
|
|
37581
|
-
|
|
37693
|
+
json3.minItems = minItems;
|
|
37582
37694
|
if (isClosed)
|
|
37583
|
-
|
|
37695
|
+
json3.maxItems = maxItems;
|
|
37584
37696
|
} else if (ctx.target === "openapi-3.0") {
|
|
37585
|
-
|
|
37697
|
+
json3.items = {
|
|
37586
37698
|
anyOf: prefixItems
|
|
37587
37699
|
};
|
|
37588
37700
|
if (rest) {
|
|
37589
|
-
|
|
37701
|
+
json3.items.anyOf.push(rest);
|
|
37590
37702
|
}
|
|
37591
37703
|
if (minItems > 0)
|
|
37592
|
-
|
|
37704
|
+
json3.minItems = minItems;
|
|
37593
37705
|
if (isClosed)
|
|
37594
|
-
|
|
37706
|
+
json3.maxItems = maxItems;
|
|
37595
37707
|
} else {
|
|
37596
|
-
|
|
37708
|
+
json3.items = prefixItems;
|
|
37597
37709
|
if (isClosed) {
|
|
37598
|
-
|
|
37710
|
+
json3.additionalItems = false;
|
|
37599
37711
|
} else if (rest) {
|
|
37600
|
-
|
|
37712
|
+
json3.additionalItems = rest;
|
|
37601
37713
|
}
|
|
37602
37714
|
if (minItems > 0)
|
|
37603
|
-
|
|
37715
|
+
json3.minItems = minItems;
|
|
37604
37716
|
if (isClosed)
|
|
37605
|
-
|
|
37717
|
+
json3.maxItems = maxItems;
|
|
37606
37718
|
}
|
|
37607
37719
|
const { minimum, maximum } = aggregateChecks(schema);
|
|
37608
37720
|
if (typeof minimum === "number")
|
|
37609
|
-
|
|
37721
|
+
json3.minItems = minimum;
|
|
37610
37722
|
if (typeof maximum === "number")
|
|
37611
|
-
|
|
37723
|
+
json3.maxItems = maximum;
|
|
37612
37724
|
}, "tupleProcessor");
|
|
37613
|
-
function stringifyKeyNames(bySchema,
|
|
37614
|
-
if (
|
|
37615
|
-
if (visited.has(
|
|
37616
|
-
return
|
|
37617
|
-
visited.add(
|
|
37618
|
-
const def = bySchema.get(
|
|
37725
|
+
function stringifyKeyNames(bySchema, json3, visited) {
|
|
37726
|
+
if (json3.$ref) {
|
|
37727
|
+
if (visited.has(json3))
|
|
37728
|
+
return json3;
|
|
37729
|
+
visited.add(json3);
|
|
37730
|
+
const def = bySchema.get(json3)?.def;
|
|
37619
37731
|
if (!def)
|
|
37620
|
-
return
|
|
37732
|
+
return json3;
|
|
37621
37733
|
const inlined = stringifyKeyNames(bySchema, def, visited);
|
|
37622
|
-
return inlined === def ?
|
|
37734
|
+
return inlined === def ? json3 : inlined;
|
|
37623
37735
|
}
|
|
37624
37736
|
for (const keyword of ["anyOf", "oneOf"]) {
|
|
37625
|
-
const branches =
|
|
37737
|
+
const branches = json3[keyword];
|
|
37626
37738
|
if (!Array.isArray(branches))
|
|
37627
37739
|
continue;
|
|
37628
37740
|
const mapped = branches.map((branch) => stringifyKeyNames(bySchema, branch, visited));
|
|
37629
37741
|
if (mapped.some((branch, i) => branch !== branches[i]))
|
|
37630
|
-
|
|
37742
|
+
json3 = { ...json3, [keyword]: mapped };
|
|
37631
37743
|
}
|
|
37632
|
-
const types = Array.isArray(
|
|
37744
|
+
const types = Array.isArray(json3.type) ? json3.type : [json3.type];
|
|
37633
37745
|
const numericType = !types.includes("string") && types.some((t) => t === "number" || t === "integer");
|
|
37634
|
-
const values =
|
|
37746
|
+
const values = json3.enum ?? (json3.const !== void 0 ? [json3.const] : void 0);
|
|
37635
37747
|
if (!numericType && !values?.some((v) => typeof v === "number"))
|
|
37636
|
-
return
|
|
37637
|
-
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } =
|
|
37748
|
+
return json3;
|
|
37749
|
+
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } = json3;
|
|
37638
37750
|
if (rest.enum)
|
|
37639
37751
|
rest.enum = rest.enum.map((v) => typeof v === "number" ? String(v) : v);
|
|
37640
37752
|
else if (typeof rest.const === "number")
|
|
@@ -37676,9 +37788,9 @@ function rewriteKeyNames(ctx) {
|
|
|
37676
37788
|
}
|
|
37677
37789
|
__name(rewriteKeyNames, "rewriteKeyNames");
|
|
37678
37790
|
var recordProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37679
|
-
const
|
|
37791
|
+
const json3 = _json;
|
|
37680
37792
|
const def = schema._zod.def;
|
|
37681
|
-
|
|
37793
|
+
json3.type = "object";
|
|
37682
37794
|
const keyType = def.keyType;
|
|
37683
37795
|
const patterns = aggregateChecks(keyType).patterns;
|
|
37684
37796
|
if (def.mode === "loose" && patterns && patterns.size > 0) {
|
|
@@ -37686,13 +37798,13 @@ var recordProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37686
37798
|
...params,
|
|
37687
37799
|
path: [...params.path, "patternProperties", "*"]
|
|
37688
37800
|
});
|
|
37689
|
-
|
|
37801
|
+
json3.patternProperties = {};
|
|
37690
37802
|
for (const pattern of patterns) {
|
|
37691
|
-
assignProp(
|
|
37803
|
+
assignProp(json3.patternProperties, exactPattern(pattern).source, valueSchema);
|
|
37692
37804
|
}
|
|
37693
37805
|
} else {
|
|
37694
37806
|
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
|
|
37695
|
-
|
|
37807
|
+
json3.propertyNames = processSchema(def.keyType, ctx, {
|
|
37696
37808
|
...params,
|
|
37697
37809
|
path: [...params.path, "propertyNames"]
|
|
37698
37810
|
});
|
|
@@ -37704,7 +37816,7 @@ var recordProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37704
37816
|
}
|
|
37705
37817
|
pending.push(schema);
|
|
37706
37818
|
}
|
|
37707
|
-
|
|
37819
|
+
json3.additionalProperties = processSchema(def.valueType, ctx, {
|
|
37708
37820
|
...params,
|
|
37709
37821
|
path: [...params.path, "additionalProperties"]
|
|
37710
37822
|
});
|
|
@@ -37714,19 +37826,19 @@ var recordProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37714
37826
|
if (keyValues && !def.partial && !omittableOnInput) {
|
|
37715
37827
|
const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
|
|
37716
37828
|
if (validKeyValues.length > 0) {
|
|
37717
|
-
|
|
37829
|
+
json3.required = validKeyValues.map(String);
|
|
37718
37830
|
}
|
|
37719
37831
|
}
|
|
37720
37832
|
}, "recordProcessor");
|
|
37721
|
-
var nullableProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37833
|
+
var nullableProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37722
37834
|
const def = schema._zod.def;
|
|
37723
37835
|
const inner = processSchema(def.innerType, ctx, params);
|
|
37724
37836
|
const seen2 = ctx.seen.get(schema);
|
|
37725
37837
|
if (ctx.target === "openapi-3.0") {
|
|
37726
37838
|
seen2.ref = def.innerType;
|
|
37727
|
-
|
|
37839
|
+
json3.nullable = true;
|
|
37728
37840
|
} else {
|
|
37729
|
-
|
|
37841
|
+
json3.anyOf = [inner, { type: "null" }];
|
|
37730
37842
|
}
|
|
37731
37843
|
}, "nullableProcessor");
|
|
37732
37844
|
var nonoptionalProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
@@ -37736,7 +37848,7 @@ var nonoptionalProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) =
|
|
|
37736
37848
|
seen2.ref = def.innerType;
|
|
37737
37849
|
}, "nonoptionalProcessor");
|
|
37738
37850
|
var UNREPRESENTABLE_DEFAULT = /* @__PURE__ */ Symbol();
|
|
37739
|
-
function serializeDefaultValue(value, schema, ctx,
|
|
37851
|
+
function serializeDefaultValue(value, schema, ctx, json3, params) {
|
|
37740
37852
|
let unrepresentable = false;
|
|
37741
37853
|
const serialized = JSON.stringify(value, (_, val) => {
|
|
37742
37854
|
if (typeof val !== "bigint")
|
|
@@ -37746,31 +37858,31 @@ function serializeDefaultValue(value, schema, ctx, json2, params) {
|
|
|
37746
37858
|
});
|
|
37747
37859
|
if (!unrepresentable)
|
|
37748
37860
|
return JSON.parse(serialized);
|
|
37749
|
-
handleUnrepresentable(schema, ctx,
|
|
37861
|
+
handleUnrepresentable(schema, ctx, json3, params, "BigInt defaults cannot be represented in JSON Schema");
|
|
37750
37862
|
return UNREPRESENTABLE_DEFAULT;
|
|
37751
37863
|
}
|
|
37752
37864
|
__name(serializeDefaultValue, "serializeDefaultValue");
|
|
37753
|
-
var defaultProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37865
|
+
var defaultProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37754
37866
|
const def = schema._zod.def;
|
|
37755
37867
|
processSchema(def.innerType, ctx, params);
|
|
37756
37868
|
const seen2 = ctx.seen.get(schema);
|
|
37757
37869
|
seen2.ref = def.innerType;
|
|
37758
|
-
const value = serializeDefaultValue(def.defaultValue, schema, ctx,
|
|
37870
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json3, params);
|
|
37759
37871
|
if (value !== UNREPRESENTABLE_DEFAULT)
|
|
37760
|
-
|
|
37872
|
+
json3.default = value;
|
|
37761
37873
|
}, "defaultProcessor");
|
|
37762
|
-
var prefaultProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37874
|
+
var prefaultProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37763
37875
|
const def = schema._zod.def;
|
|
37764
37876
|
processSchema(def.innerType, ctx, params);
|
|
37765
37877
|
const seen2 = ctx.seen.get(schema);
|
|
37766
37878
|
seen2.ref = def.innerType;
|
|
37767
37879
|
if (ctx.io !== "input")
|
|
37768
37880
|
return;
|
|
37769
|
-
const value = serializeDefaultValue(def.defaultValue, schema, ctx,
|
|
37881
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json3, params);
|
|
37770
37882
|
if (value !== UNREPRESENTABLE_DEFAULT)
|
|
37771
|
-
|
|
37883
|
+
json3._prefault = value;
|
|
37772
37884
|
}, "prefaultProcessor");
|
|
37773
|
-
var catchProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37885
|
+
var catchProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37774
37886
|
const def = schema._zod.def;
|
|
37775
37887
|
processSchema(def.innerType, ctx, params);
|
|
37776
37888
|
const seen2 = ctx.seen.get(schema);
|
|
@@ -37779,10 +37891,10 @@ var catchProcessor = /* @__PURE__ */ __name((schema, ctx, json2, params) => {
|
|
|
37779
37891
|
try {
|
|
37780
37892
|
catchValue = def.catchValue(void 0);
|
|
37781
37893
|
} catch {
|
|
37782
|
-
handleUnrepresentable(schema, ctx,
|
|
37894
|
+
handleUnrepresentable(schema, ctx, json3, params, "Dynamic catch values are not supported in JSON Schema");
|
|
37783
37895
|
return;
|
|
37784
37896
|
}
|
|
37785
|
-
|
|
37897
|
+
json3.default = catchValue;
|
|
37786
37898
|
}, "catchProcessor");
|
|
37787
37899
|
var pipeProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37788
37900
|
const def = schema._zod.def;
|
|
@@ -37792,12 +37904,12 @@ var pipeProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37792
37904
|
const seen2 = ctx.seen.get(schema);
|
|
37793
37905
|
seen2.ref = innerType;
|
|
37794
37906
|
}, "pipeProcessor");
|
|
37795
|
-
var readonlyProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37907
|
+
var readonlyProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37796
37908
|
const def = schema._zod.def;
|
|
37797
37909
|
processSchema(def.innerType, ctx, params);
|
|
37798
37910
|
const seen2 = ctx.seen.get(schema);
|
|
37799
37911
|
seen2.ref = def.innerType;
|
|
37800
|
-
|
|
37912
|
+
json3.readOnly = true;
|
|
37801
37913
|
}, "readonlyProcessor");
|
|
37802
37914
|
var promiseProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37803
37915
|
const def = schema._zod.def;
|
|
@@ -39105,7 +39217,7 @@ var _ZodString = /* @__PURE__ */ $constructor(
|
|
|
39105
39217
|
(inst, def) => {
|
|
39106
39218
|
$ZodString.init(inst, def);
|
|
39107
39219
|
ZodType2.init(inst, def);
|
|
39108
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39220
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => stringProcessor(inst, ctx, json3, params);
|
|
39109
39221
|
},
|
|
39110
39222
|
/* @__PURE__ */ util_exports.derived({
|
|
39111
39223
|
format: /* @__PURE__ */ __name((inst) => aggregateChecks(inst).format ?? null, "format"),
|
|
@@ -39496,7 +39608,7 @@ var ZodNumber2 = /* @__PURE__ */ $constructor(
|
|
|
39496
39608
|
(inst, def) => {
|
|
39497
39609
|
$ZodNumber.init(inst, def);
|
|
39498
39610
|
ZodType2.init(inst, def);
|
|
39499
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39611
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => numberProcessor(inst, ctx, json3, params);
|
|
39500
39612
|
inst.isFinite = true;
|
|
39501
39613
|
},
|
|
39502
39614
|
/* @__PURE__ */ util_exports.derived({
|
|
@@ -39592,7 +39704,7 @@ __name(uint32, "uint32");
|
|
|
39592
39704
|
var ZodBoolean2 = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
|
|
39593
39705
|
$ZodBoolean.init(inst, def);
|
|
39594
39706
|
ZodType2.init(inst, def);
|
|
39595
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39707
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => booleanProcessor(inst, ctx, json3, params);
|
|
39596
39708
|
});
|
|
39597
39709
|
function boolean2(params) {
|
|
39598
39710
|
return _boolean(ZodBoolean2, params);
|
|
@@ -39603,7 +39715,7 @@ var ZodBigInt2 = /* @__PURE__ */ $constructor(
|
|
|
39603
39715
|
(inst, def) => {
|
|
39604
39716
|
$ZodBigInt.init(inst, def);
|
|
39605
39717
|
ZodType2.init(inst, def);
|
|
39606
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39718
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => bigintProcessor(inst, ctx, json3, params);
|
|
39607
39719
|
},
|
|
39608
39720
|
/* @__PURE__ */ util_exports.derived({
|
|
39609
39721
|
minValue: /* @__PURE__ */ __name((inst) => aggregateChecks(inst).minimum ?? null, "minValue"),
|
|
@@ -39664,7 +39776,7 @@ __name(uint64, "uint64");
|
|
|
39664
39776
|
var ZodSymbol2 = /* @__PURE__ */ $constructor("ZodSymbol", (inst, def) => {
|
|
39665
39777
|
$ZodSymbol.init(inst, def);
|
|
39666
39778
|
ZodType2.init(inst, def);
|
|
39667
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39779
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => symbolProcessor(inst, ctx, json3, params);
|
|
39668
39780
|
});
|
|
39669
39781
|
function symbol(params) {
|
|
39670
39782
|
return _symbol(ZodSymbol2, params);
|
|
@@ -39673,7 +39785,7 @@ __name(symbol, "symbol");
|
|
|
39673
39785
|
var ZodUndefined2 = /* @__PURE__ */ $constructor("ZodUndefined", (inst, def) => {
|
|
39674
39786
|
$ZodUndefined.init(inst, def);
|
|
39675
39787
|
ZodType2.init(inst, def);
|
|
39676
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39788
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => undefinedProcessor(inst, ctx, json3, params);
|
|
39677
39789
|
});
|
|
39678
39790
|
function _undefined3(params) {
|
|
39679
39791
|
return _undefined2(ZodUndefined2, params);
|
|
@@ -39682,7 +39794,7 @@ __name(_undefined3, "_undefined");
|
|
|
39682
39794
|
var ZodNull2 = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
|
|
39683
39795
|
$ZodNull.init(inst, def);
|
|
39684
39796
|
ZodType2.init(inst, def);
|
|
39685
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39797
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nullProcessor(inst, ctx, json3, params);
|
|
39686
39798
|
});
|
|
39687
39799
|
function _null3(params) {
|
|
39688
39800
|
return _null2(ZodNull2, params);
|
|
@@ -39691,7 +39803,7 @@ __name(_null3, "_null");
|
|
|
39691
39803
|
var ZodAny2 = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
|
|
39692
39804
|
$ZodAny.init(inst, def);
|
|
39693
39805
|
ZodType2.init(inst, def);
|
|
39694
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39806
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => anyProcessor(inst, ctx, json3, params);
|
|
39695
39807
|
});
|
|
39696
39808
|
function any() {
|
|
39697
39809
|
return _any(ZodAny2);
|
|
@@ -39700,7 +39812,7 @@ __name(any, "any");
|
|
|
39700
39812
|
var ZodUnknown2 = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
|
|
39701
39813
|
$ZodUnknown.init(inst, def);
|
|
39702
39814
|
ZodType2.init(inst, def);
|
|
39703
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39815
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => unknownProcessor(inst, ctx, json3, params);
|
|
39704
39816
|
});
|
|
39705
39817
|
function unknown() {
|
|
39706
39818
|
return _unknown(ZodUnknown2);
|
|
@@ -39709,7 +39821,7 @@ __name(unknown, "unknown");
|
|
|
39709
39821
|
var ZodNever2 = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
|
|
39710
39822
|
$ZodNever.init(inst, def);
|
|
39711
39823
|
ZodType2.init(inst, def);
|
|
39712
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39824
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => neverProcessor(inst, ctx, json3, params);
|
|
39713
39825
|
});
|
|
39714
39826
|
function never(params) {
|
|
39715
39827
|
return _never(ZodNever2, params);
|
|
@@ -39718,7 +39830,7 @@ __name(never, "never");
|
|
|
39718
39830
|
var ZodVoid2 = /* @__PURE__ */ $constructor("ZodVoid", (inst, def) => {
|
|
39719
39831
|
$ZodVoid.init(inst, def);
|
|
39720
39832
|
ZodType2.init(inst, def);
|
|
39721
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39833
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => voidProcessor(inst, ctx, json3, params);
|
|
39722
39834
|
});
|
|
39723
39835
|
function _void2(params) {
|
|
39724
39836
|
return _void(ZodVoid2, params);
|
|
@@ -39729,7 +39841,7 @@ var ZodDate2 = /* @__PURE__ */ $constructor(
|
|
|
39729
39841
|
(inst, def) => {
|
|
39730
39842
|
$ZodDate.init(inst, def);
|
|
39731
39843
|
ZodType2.init(inst, def);
|
|
39732
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39844
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => dateProcessor(inst, ctx, json3, params);
|
|
39733
39845
|
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
39734
39846
|
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
39735
39847
|
},
|
|
@@ -39752,7 +39864,7 @@ var ZodArray2 = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
|
|
|
39752
39864
|
_ensureDefaultMemoizer();
|
|
39753
39865
|
$ZodArray.init(inst, def);
|
|
39754
39866
|
ZodType2.init(inst, def);
|
|
39755
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39867
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => arrayProcessor(inst, ctx, json3, params);
|
|
39756
39868
|
inst.element = def.element;
|
|
39757
39869
|
}, {
|
|
39758
39870
|
min(n, params) {
|
|
@@ -39784,7 +39896,7 @@ var ZodObject2 = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
|
39784
39896
|
_ensureDefaultMemoizer();
|
|
39785
39897
|
$ZodObjectJIT.init(inst, def);
|
|
39786
39898
|
ZodType2.init(inst, def);
|
|
39787
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39899
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => objectProcessor(inst, ctx, json3, params);
|
|
39788
39900
|
util_exports.installLazyProp(inst, "shape", (self) => self._zod.def.shape, false);
|
|
39789
39901
|
}, {
|
|
39790
39902
|
keyof() {
|
|
@@ -39860,7 +39972,7 @@ __name(looseObject, "looseObject");
|
|
|
39860
39972
|
var ZodUnion2 = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
|
|
39861
39973
|
$ZodUnion.init(inst, def);
|
|
39862
39974
|
ZodType2.init(inst, def);
|
|
39863
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39975
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => unionProcessor(inst, ctx, json3, params);
|
|
39864
39976
|
inst.options = def.options;
|
|
39865
39977
|
});
|
|
39866
39978
|
function union(options, params) {
|
|
@@ -39874,7 +39986,7 @@ __name(union, "union");
|
|
|
39874
39986
|
var ZodXor = /* @__PURE__ */ $constructor("ZodXor", (inst, def) => {
|
|
39875
39987
|
ZodUnion2.init(inst, def);
|
|
39876
39988
|
$ZodXor.init(inst, def);
|
|
39877
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39989
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => unionProcessor(inst, ctx, json3, params);
|
|
39878
39990
|
inst.options = def.options;
|
|
39879
39991
|
});
|
|
39880
39992
|
function xor(options, params) {
|
|
@@ -39902,7 +40014,7 @@ __name(discriminatedUnion, "discriminatedUnion");
|
|
|
39902
40014
|
var ZodIntersection2 = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
|
|
39903
40015
|
$ZodIntersection.init(inst, def);
|
|
39904
40016
|
ZodType2.init(inst, def);
|
|
39905
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40017
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => intersectionProcessor(inst, ctx, json3, params);
|
|
39906
40018
|
});
|
|
39907
40019
|
function intersection(left, right) {
|
|
39908
40020
|
return new ZodIntersection2({
|
|
@@ -39916,7 +40028,7 @@ var ZodTuple2 = /* @__PURE__ */ $constructor("ZodTuple", (inst, def) => {
|
|
|
39916
40028
|
_ensureDefaultMemoizer();
|
|
39917
40029
|
$ZodTuple.init(inst, def);
|
|
39918
40030
|
ZodType2.init(inst, def);
|
|
39919
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40031
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => tupleProcessor(inst, ctx, json3, params);
|
|
39920
40032
|
}, {
|
|
39921
40033
|
rest(rest) {
|
|
39922
40034
|
return this.clone({
|
|
@@ -39950,7 +40062,7 @@ var ZodRecord2 = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
|
|
|
39950
40062
|
_ensureDefaultMemoizer();
|
|
39951
40063
|
$ZodRecord.init(inst, def);
|
|
39952
40064
|
ZodType2.init(inst, def);
|
|
39953
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40065
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => recordProcessor(inst, ctx, json3, params);
|
|
39954
40066
|
inst.keyType = def.keyType;
|
|
39955
40067
|
inst.valueType = def.valueType;
|
|
39956
40068
|
});
|
|
@@ -39995,7 +40107,7 @@ var ZodMap2 = /* @__PURE__ */ $constructor("ZodMap", (inst, def) => {
|
|
|
39995
40107
|
_ensureDefaultMemoizer();
|
|
39996
40108
|
$ZodMap.init(inst, def);
|
|
39997
40109
|
ZodType2.init(inst, def);
|
|
39998
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40110
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => mapProcessor(inst, ctx, json3, params);
|
|
39999
40111
|
inst.keyType = def.keyType;
|
|
40000
40112
|
inst.valueType = def.valueType;
|
|
40001
40113
|
inst.min = (...args) => inst.check(_minSize(...args));
|
|
@@ -40016,7 +40128,7 @@ var ZodSet2 = /* @__PURE__ */ $constructor("ZodSet", (inst, def) => {
|
|
|
40016
40128
|
_ensureDefaultMemoizer();
|
|
40017
40129
|
$ZodSet.init(inst, def);
|
|
40018
40130
|
ZodType2.init(inst, def);
|
|
40019
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40131
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => setProcessor(inst, ctx, json3, params);
|
|
40020
40132
|
inst.min = (...args) => inst.check(_minSize(...args));
|
|
40021
40133
|
inst.nonempty = (params) => inst.check(_minSize(1, params));
|
|
40022
40134
|
inst.max = (...args) => inst.check(_maxSize(...args));
|
|
@@ -40033,7 +40145,7 @@ __name(set, "set");
|
|
|
40033
40145
|
var ZodEnum2 = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
40034
40146
|
$ZodEnum.init(inst, def);
|
|
40035
40147
|
ZodType2.init(inst, def);
|
|
40036
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40148
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => enumProcessor(inst, ctx, json3, params);
|
|
40037
40149
|
inst.enum = def.entries;
|
|
40038
40150
|
inst.options = [...inst._zod.values];
|
|
40039
40151
|
const keys = new Set(Object.keys(def.entries));
|
|
@@ -40088,7 +40200,7 @@ __name(nativeEnum, "nativeEnum");
|
|
|
40088
40200
|
var ZodLiteral2 = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
|
|
40089
40201
|
$ZodLiteral.init(inst, def);
|
|
40090
40202
|
ZodType2.init(inst, def);
|
|
40091
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40203
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => literalProcessor(inst, ctx, json3, params);
|
|
40092
40204
|
inst.values = new Set(def.values);
|
|
40093
40205
|
Object.defineProperty(inst, "value", {
|
|
40094
40206
|
get() {
|
|
@@ -40110,7 +40222,7 @@ __name(literal, "literal");
|
|
|
40110
40222
|
var ZodFile = /* @__PURE__ */ $constructor("ZodFile", (inst, def) => {
|
|
40111
40223
|
$ZodFile.init(inst, def);
|
|
40112
40224
|
ZodType2.init(inst, def);
|
|
40113
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40225
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => fileProcessor(inst, ctx, json3, params);
|
|
40114
40226
|
inst.min = (size, params) => inst.check(_minSize(size, params));
|
|
40115
40227
|
inst.max = (size, params) => inst.check(_maxSize(size, params));
|
|
40116
40228
|
inst.mime = (types, params) => inst.check(_mime(Array.isArray(types) ? types : [types], params));
|
|
@@ -40123,7 +40235,7 @@ var ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
|
|
|
40123
40235
|
_ensureDefaultMemoizer();
|
|
40124
40236
|
$ZodTransform.init(inst, def);
|
|
40125
40237
|
ZodType2.init(inst, def);
|
|
40126
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40238
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => transformProcessor(inst, ctx, json3, params);
|
|
40127
40239
|
inst._zod.parse = (payload, _ctx) => {
|
|
40128
40240
|
if (_ctx.direction === "backward") {
|
|
40129
40241
|
throw new $ZodEncodeError(inst.constructor.name);
|
|
@@ -40163,7 +40275,7 @@ __name(transform, "transform");
|
|
|
40163
40275
|
var ZodOptional2 = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
|
|
40164
40276
|
$ZodOptional.init(inst, def);
|
|
40165
40277
|
ZodType2.init(inst, def);
|
|
40166
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40278
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => optionalProcessor(inst, ctx, json3, params);
|
|
40167
40279
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40168
40280
|
});
|
|
40169
40281
|
function optional(innerType) {
|
|
@@ -40176,7 +40288,7 @@ __name(optional, "optional");
|
|
|
40176
40288
|
var ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
|
|
40177
40289
|
$ZodExactOptional.init(inst, def);
|
|
40178
40290
|
ZodType2.init(inst, def);
|
|
40179
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40291
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => optionalProcessor(inst, ctx, json3, params);
|
|
40180
40292
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40181
40293
|
});
|
|
40182
40294
|
function exactOptional(innerType) {
|
|
@@ -40189,7 +40301,7 @@ __name(exactOptional, "exactOptional");
|
|
|
40189
40301
|
var ZodNullable2 = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
|
|
40190
40302
|
$ZodNullable.init(inst, def);
|
|
40191
40303
|
ZodType2.init(inst, def);
|
|
40192
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40304
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nullableProcessor(inst, ctx, json3, params);
|
|
40193
40305
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40194
40306
|
});
|
|
40195
40307
|
function nullable(innerType) {
|
|
@@ -40206,7 +40318,7 @@ __name(nullish2, "nullish");
|
|
|
40206
40318
|
var ZodDefault2 = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
|
|
40207
40319
|
$ZodDefault.init(inst, def);
|
|
40208
40320
|
ZodType2.init(inst, def);
|
|
40209
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40321
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => defaultProcessor(inst, ctx, json3, params);
|
|
40210
40322
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40211
40323
|
inst.removeDefault = inst.unwrap;
|
|
40212
40324
|
});
|
|
@@ -40223,7 +40335,7 @@ __name(_default2, "_default");
|
|
|
40223
40335
|
var ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
|
|
40224
40336
|
$ZodPrefault.init(inst, def);
|
|
40225
40337
|
ZodType2.init(inst, def);
|
|
40226
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40338
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => prefaultProcessor(inst, ctx, json3, params);
|
|
40227
40339
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40228
40340
|
});
|
|
40229
40341
|
function prefault(innerType, defaultValue) {
|
|
@@ -40239,7 +40351,7 @@ __name(prefault, "prefault");
|
|
|
40239
40351
|
var ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
|
|
40240
40352
|
$ZodNonOptional.init(inst, def);
|
|
40241
40353
|
ZodType2.init(inst, def);
|
|
40242
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40354
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nonoptionalProcessor(inst, ctx, json3, params);
|
|
40243
40355
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40244
40356
|
});
|
|
40245
40357
|
function nonoptional(innerType, params) {
|
|
@@ -40253,7 +40365,7 @@ __name(nonoptional, "nonoptional");
|
|
|
40253
40365
|
var ZodSuccess = /* @__PURE__ */ $constructor("ZodSuccess", (inst, def) => {
|
|
40254
40366
|
$ZodSuccess.init(inst, def);
|
|
40255
40367
|
ZodType2.init(inst, def);
|
|
40256
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40368
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => successProcessor(inst, ctx, json3, params);
|
|
40257
40369
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40258
40370
|
});
|
|
40259
40371
|
function success(innerType) {
|
|
@@ -40266,7 +40378,7 @@ __name(success, "success");
|
|
|
40266
40378
|
var ZodCatch2 = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
|
|
40267
40379
|
$ZodCatch.init(inst, def);
|
|
40268
40380
|
ZodType2.init(inst, def);
|
|
40269
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40381
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => catchProcessor(inst, ctx, json3, params);
|
|
40270
40382
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40271
40383
|
inst.removeCatch = inst.unwrap;
|
|
40272
40384
|
});
|
|
@@ -40281,7 +40393,7 @@ __name(_catch2, "_catch");
|
|
|
40281
40393
|
var ZodNaN2 = /* @__PURE__ */ $constructor("ZodNaN", (inst, def) => {
|
|
40282
40394
|
$ZodNaN.init(inst, def);
|
|
40283
40395
|
ZodType2.init(inst, def);
|
|
40284
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40396
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nanProcessor(inst, ctx, json3, params);
|
|
40285
40397
|
});
|
|
40286
40398
|
function nan(params) {
|
|
40287
40399
|
return _nan(ZodNaN2, params);
|
|
@@ -40290,7 +40402,7 @@ __name(nan, "nan");
|
|
|
40290
40402
|
var ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
|
|
40291
40403
|
$ZodPipe.init(inst, def);
|
|
40292
40404
|
ZodType2.init(inst, def);
|
|
40293
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40405
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => pipeProcessor(inst, ctx, json3, params);
|
|
40294
40406
|
inst.in = def.in;
|
|
40295
40407
|
inst.out = def.out;
|
|
40296
40408
|
});
|
|
@@ -40335,7 +40447,7 @@ var ZodPreprocess = /* @__PURE__ */ $constructor("ZodPreprocess", (inst, def) =>
|
|
|
40335
40447
|
var ZodReadonly2 = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
|
|
40336
40448
|
$ZodReadonly.init(inst, def);
|
|
40337
40449
|
ZodType2.init(inst, def);
|
|
40338
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40450
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => readonlyProcessor(inst, ctx, json3, params);
|
|
40339
40451
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40340
40452
|
});
|
|
40341
40453
|
function readonly(innerType) {
|
|
@@ -40348,7 +40460,7 @@ __name(readonly, "readonly");
|
|
|
40348
40460
|
var ZodTemplateLiteral = /* @__PURE__ */ $constructor("ZodTemplateLiteral", (inst, def) => {
|
|
40349
40461
|
$ZodTemplateLiteral.init(inst, def);
|
|
40350
40462
|
ZodType2.init(inst, def);
|
|
40351
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40463
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => templateLiteralProcessor(inst, ctx, json3, params);
|
|
40352
40464
|
});
|
|
40353
40465
|
function templateLiteral(parts, params) {
|
|
40354
40466
|
return new ZodTemplateLiteral({
|
|
@@ -40361,7 +40473,7 @@ __name(templateLiteral, "templateLiteral");
|
|
|
40361
40473
|
var ZodLazy2 = /* @__PURE__ */ $constructor("ZodLazy", (inst, def) => {
|
|
40362
40474
|
$ZodLazy.init(inst, def);
|
|
40363
40475
|
ZodType2.init(inst, def);
|
|
40364
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40476
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => lazyProcessor(inst, ctx, json3, params);
|
|
40365
40477
|
inst.unwrap = () => inst._zod.def.getter();
|
|
40366
40478
|
});
|
|
40367
40479
|
function lazy(getter) {
|
|
@@ -40374,7 +40486,7 @@ __name(lazy, "lazy");
|
|
|
40374
40486
|
var ZodPromise2 = /* @__PURE__ */ $constructor("ZodPromise", (inst, def) => {
|
|
40375
40487
|
$ZodPromise.init(inst, def);
|
|
40376
40488
|
ZodType2.init(inst, def);
|
|
40377
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40489
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => promiseProcessor(inst, ctx, json3, params);
|
|
40378
40490
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40379
40491
|
});
|
|
40380
40492
|
function promise(innerType) {
|
|
@@ -40387,7 +40499,7 @@ __name(promise, "promise");
|
|
|
40387
40499
|
var ZodFunction2 = /* @__PURE__ */ $constructor("ZodFunction", (inst, def) => {
|
|
40388
40500
|
$ZodFunction.init(inst, def);
|
|
40389
40501
|
ZodType2.init(inst, def);
|
|
40390
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40502
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => functionProcessor(inst, ctx, json3, params);
|
|
40391
40503
|
});
|
|
40392
40504
|
function _function(params) {
|
|
40393
40505
|
return new ZodFunction2({
|
|
@@ -40400,7 +40512,7 @@ __name(_function, "_function");
|
|
|
40400
40512
|
var ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
|
|
40401
40513
|
$ZodCustom.init(inst, def);
|
|
40402
40514
|
ZodType2.init(inst, def);
|
|
40403
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40515
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => customProcessor(inst, ctx, json3, params);
|
|
40404
40516
|
});
|
|
40405
40517
|
function check(fn) {
|
|
40406
40518
|
const ch = new $ZodCheck({
|
|
@@ -41359,6 +41471,7 @@ __name(date4, "date");
|
|
|
41359
41471
|
|
|
41360
41472
|
// node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
41361
41473
|
var LATEST_PROTOCOL_VERSION = "2025-11-25";
|
|
41474
|
+
var DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
|
|
41362
41475
|
var SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
|
|
41363
41476
|
var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
41364
41477
|
var JSONRPC_VERSION = "2.0";
|
|
@@ -41687,6 +41800,7 @@ var InitializeRequestSchema = RequestSchema.extend({
|
|
|
41687
41800
|
method: literal("initialize"),
|
|
41688
41801
|
params: InitializeRequestParamsSchema
|
|
41689
41802
|
});
|
|
41803
|
+
var isInitializeRequest = /* @__PURE__ */ __name((value) => InitializeRequestSchema.safeParse(value).success, "isInitializeRequest");
|
|
41690
41804
|
var ServerCapabilitiesSchema = object2({
|
|
41691
41805
|
/**
|
|
41692
41806
|
* Experimental, non-standard capabilities that the server supports.
|
|
@@ -46993,8 +47107,8 @@ var StdioServerTransport = class {
|
|
|
46993
47107
|
}
|
|
46994
47108
|
send(message) {
|
|
46995
47109
|
return new Promise((resolve) => {
|
|
46996
|
-
const
|
|
46997
|
-
if (this._stdout.write(
|
|
47110
|
+
const json3 = serializeMessage(message);
|
|
47111
|
+
if (this._stdout.write(json3)) {
|
|
46998
47112
|
resolve();
|
|
46999
47113
|
} else {
|
|
47000
47114
|
this._stdout.once("drain", resolve);
|
|
@@ -47003,6 +47117,2156 @@ var StdioServerTransport = class {
|
|
|
47003
47117
|
}
|
|
47004
47118
|
};
|
|
47005
47119
|
|
|
47120
|
+
// node_modules/@hono/node-server/dist/constants-BLSFu_RU.mjs
|
|
47121
|
+
var X_ALREADY_SENT = "x-hono-already-sent";
|
|
47122
|
+
|
|
47123
|
+
// node_modules/@hono/node-server/dist/index.mjs
|
|
47124
|
+
var import_node_http = require("node:http");
|
|
47125
|
+
var import_node_http2 = require("node:http2");
|
|
47126
|
+
var import_node_stream = require("node:stream");
|
|
47127
|
+
|
|
47128
|
+
// node_modules/hono/dist/helper/websocket/index.js
|
|
47129
|
+
var defineWebSocketHelper = /* @__PURE__ */ __name((handler) => {
|
|
47130
|
+
return ((...args) => {
|
|
47131
|
+
if (typeof args[0] === "function") {
|
|
47132
|
+
const [createEvents, options] = args;
|
|
47133
|
+
return /* @__PURE__ */ __name(async function upgradeWebSocket2(c, next) {
|
|
47134
|
+
const result = await handler(c, await createEvents(c), options);
|
|
47135
|
+
if (result) return result;
|
|
47136
|
+
await next();
|
|
47137
|
+
}, "upgradeWebSocket");
|
|
47138
|
+
} else {
|
|
47139
|
+
const [c, events, options] = args;
|
|
47140
|
+
return (async () => {
|
|
47141
|
+
const upgraded = await handler(c, events, options);
|
|
47142
|
+
if (!upgraded) throw new Error("Failed to upgrade WebSocket");
|
|
47143
|
+
return upgraded;
|
|
47144
|
+
})();
|
|
47145
|
+
}
|
|
47146
|
+
});
|
|
47147
|
+
}, "defineWebSocketHelper");
|
|
47148
|
+
|
|
47149
|
+
// node_modules/@hono/node-server/dist/index.mjs
|
|
47150
|
+
var RequestError = class extends Error {
|
|
47151
|
+
static {
|
|
47152
|
+
__name(this, "RequestError");
|
|
47153
|
+
}
|
|
47154
|
+
constructor(message, options) {
|
|
47155
|
+
super(message, options);
|
|
47156
|
+
this.name = "RequestError";
|
|
47157
|
+
}
|
|
47158
|
+
};
|
|
47159
|
+
var nonJoinedHeaders = /* @__PURE__ */ new Set([
|
|
47160
|
+
"age",
|
|
47161
|
+
"authorization",
|
|
47162
|
+
"content-length",
|
|
47163
|
+
"content-type",
|
|
47164
|
+
"etag",
|
|
47165
|
+
"expires",
|
|
47166
|
+
"from",
|
|
47167
|
+
"host",
|
|
47168
|
+
"if-modified-since",
|
|
47169
|
+
"if-unmodified-since",
|
|
47170
|
+
"last-modified",
|
|
47171
|
+
"location",
|
|
47172
|
+
"max-forwards",
|
|
47173
|
+
"proxy-authorization",
|
|
47174
|
+
"referer",
|
|
47175
|
+
"retry-after",
|
|
47176
|
+
"server",
|
|
47177
|
+
"user-agent"
|
|
47178
|
+
]);
|
|
47179
|
+
var validHeaderName = /^[!#$%&'*+\-.^_`|~\dA-Za-z]+$/;
|
|
47180
|
+
var isHttpWhitespace = /* @__PURE__ */ __name((code) => code === 9 || code === 10 || code === 13 || code === 32, "isHttpWhitespace");
|
|
47181
|
+
var normalizeHeaderValue = /* @__PURE__ */ __name((value) => {
|
|
47182
|
+
if (!isHttpWhitespace(value.charCodeAt(0)) && !isHttpWhitespace(value.charCodeAt(value.length - 1))) return value;
|
|
47183
|
+
let start = 0;
|
|
47184
|
+
let end = value.length;
|
|
47185
|
+
while (start < end && isHttpWhitespace(value.charCodeAt(start))) start++;
|
|
47186
|
+
while (end > start && isHttpWhitespace(value.charCodeAt(end - 1))) end--;
|
|
47187
|
+
return value.slice(start, end);
|
|
47188
|
+
}, "normalizeHeaderValue");
|
|
47189
|
+
var forbiddenHeaderValue = /[\0\r\n]/;
|
|
47190
|
+
var GlobalHeaders = globalThis.Headers;
|
|
47191
|
+
var materializeHeaders = /* @__PURE__ */ __name((rawHeaders, HeadersCtor = GlobalHeaders) => {
|
|
47192
|
+
const headers = new HeadersCtor();
|
|
47193
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
47194
|
+
const name = rawHeaders[i];
|
|
47195
|
+
if (!name.startsWith(":")) headers.append(name, rawHeaders[i + 1]);
|
|
47196
|
+
}
|
|
47197
|
+
return headers;
|
|
47198
|
+
}, "materializeHeaders");
|
|
47199
|
+
var RequestHeaders = class {
|
|
47200
|
+
static {
|
|
47201
|
+
__name(this, "RequestHeaders");
|
|
47202
|
+
}
|
|
47203
|
+
#incoming;
|
|
47204
|
+
#rawHeaders;
|
|
47205
|
+
#headers;
|
|
47206
|
+
#invalidValue;
|
|
47207
|
+
constructor(incoming) {
|
|
47208
|
+
this.#incoming = incoming;
|
|
47209
|
+
if (incoming instanceof import_node_http2.Http2ServerRequest) this.#rawHeaders = incoming.rawHeaders.slice();
|
|
47210
|
+
}
|
|
47211
|
+
get #lazyRawHeaders() {
|
|
47212
|
+
return this.#rawHeaders ??= this.#incoming.rawHeaders.slice();
|
|
47213
|
+
}
|
|
47214
|
+
get #native() {
|
|
47215
|
+
if (!this.#headers) {
|
|
47216
|
+
this.#headers = materializeHeaders(this.#lazyRawHeaders);
|
|
47217
|
+
this.#rawHeaders = void 0;
|
|
47218
|
+
}
|
|
47219
|
+
return this.#headers;
|
|
47220
|
+
}
|
|
47221
|
+
#normalizedName(name) {
|
|
47222
|
+
if (typeof name !== "string") return;
|
|
47223
|
+
if (!validHeaderName.test(name)) throw new TypeError(`Invalid header name: ${name}`);
|
|
47224
|
+
return name.toLowerCase();
|
|
47225
|
+
}
|
|
47226
|
+
#lookupHttp1(lowerName) {
|
|
47227
|
+
const headers = this.#incoming instanceof import_node_http2.Http2ServerRequest ? void 0 : this.#incoming.headers;
|
|
47228
|
+
if (!headers || nonJoinedHeaders.has(lowerName) || lowerName === "set-cookie" || lowerName === "__proto__") return;
|
|
47229
|
+
if (!Object.hasOwn(headers, lowerName)) return null;
|
|
47230
|
+
const rawValue = headers[lowerName];
|
|
47231
|
+
if (typeof rawValue === "string") {
|
|
47232
|
+
const value = normalizeHeaderValue(rawValue);
|
|
47233
|
+
return forbiddenHeaderValue.test(value) ? void 0 : value;
|
|
47234
|
+
}
|
|
47235
|
+
}
|
|
47236
|
+
#lookup(rawHeaders, lowerName) {
|
|
47237
|
+
const separator = lowerName === "cookie" ? "; " : ", ";
|
|
47238
|
+
let value = null;
|
|
47239
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
47240
|
+
const rawName = rawHeaders[i];
|
|
47241
|
+
if (rawName.length === lowerName.length && rawName.toLowerCase() === lowerName) {
|
|
47242
|
+
const rawValue = normalizeHeaderValue(rawHeaders[i + 1]);
|
|
47243
|
+
if (forbiddenHeaderValue.test(rawValue)) {
|
|
47244
|
+
this.#invalidValue = true;
|
|
47245
|
+
return;
|
|
47246
|
+
}
|
|
47247
|
+
value = value === null ? rawValue : value + separator + rawValue;
|
|
47248
|
+
}
|
|
47249
|
+
}
|
|
47250
|
+
return value;
|
|
47251
|
+
}
|
|
47252
|
+
append(name, value) {
|
|
47253
|
+
this.#native.append(name, value);
|
|
47254
|
+
}
|
|
47255
|
+
delete(name) {
|
|
47256
|
+
this.#native.delete(name);
|
|
47257
|
+
}
|
|
47258
|
+
get(name) {
|
|
47259
|
+
const lowerName = this.#normalizedName(name);
|
|
47260
|
+
if (lowerName && !this.#headers && !this.#invalidValue) {
|
|
47261
|
+
const http1Value = this.#lookupHttp1(lowerName);
|
|
47262
|
+
if (http1Value !== void 0) return http1Value;
|
|
47263
|
+
const value = this.#lookup(this.#lazyRawHeaders, lowerName);
|
|
47264
|
+
if (value !== void 0) return value;
|
|
47265
|
+
}
|
|
47266
|
+
return this.#native.get(name);
|
|
47267
|
+
}
|
|
47268
|
+
has(name) {
|
|
47269
|
+
const lowerName = this.#normalizedName(name);
|
|
47270
|
+
if (lowerName && !this.#headers && !this.#invalidValue) {
|
|
47271
|
+
const http1Value = this.#lookupHttp1(lowerName);
|
|
47272
|
+
if (http1Value !== void 0) return http1Value !== null;
|
|
47273
|
+
const value = this.#lookup(this.#lazyRawHeaders, lowerName);
|
|
47274
|
+
if (value !== void 0) return value !== null;
|
|
47275
|
+
}
|
|
47276
|
+
return this.#native.has(name);
|
|
47277
|
+
}
|
|
47278
|
+
set(name, value) {
|
|
47279
|
+
this.#native.set(name, value);
|
|
47280
|
+
}
|
|
47281
|
+
getSetCookie() {
|
|
47282
|
+
return this.#native.getSetCookie();
|
|
47283
|
+
}
|
|
47284
|
+
keys() {
|
|
47285
|
+
return this.#native.keys();
|
|
47286
|
+
}
|
|
47287
|
+
values() {
|
|
47288
|
+
return this.#native.values();
|
|
47289
|
+
}
|
|
47290
|
+
entries() {
|
|
47291
|
+
return this.#native.entries();
|
|
47292
|
+
}
|
|
47293
|
+
forEach(callback, thisArg) {
|
|
47294
|
+
this.#native.forEach((value, key) => {
|
|
47295
|
+
callback.call(thisArg, value, key, this);
|
|
47296
|
+
});
|
|
47297
|
+
}
|
|
47298
|
+
[Symbol.iterator]() {
|
|
47299
|
+
return this.entries();
|
|
47300
|
+
}
|
|
47301
|
+
};
|
|
47302
|
+
Object.defineProperty(RequestHeaders.prototype, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"), { value: /* @__PURE__ */ __name(function(depth, options, inspectFn) {
|
|
47303
|
+
return `Headers (lightweight) ${inspectFn(Object.fromEntries(this), {
|
|
47304
|
+
...options,
|
|
47305
|
+
depth: depth == null ? null : depth - 1
|
|
47306
|
+
})}`;
|
|
47307
|
+
}, "value") });
|
|
47308
|
+
Object.setPrototypeOf(RequestHeaders.prototype, GlobalHeaders.prototype);
|
|
47309
|
+
var newHeadersFromIncoming = /* @__PURE__ */ __name((incoming) => globalThis.Headers === GlobalHeaders ? new RequestHeaders(incoming) : materializeHeaders(incoming.rawHeaders, globalThis.Headers), "newHeadersFromIncoming");
|
|
47310
|
+
var reValidRequestUrl = /^\/[!#$&-;=?-\[\]_a-z~]*$/;
|
|
47311
|
+
var reDotSegment = /\/\.\.?(?:[/?#]|$)/;
|
|
47312
|
+
var reValidHost = /^[a-z0-9._-]+(?::(?:[1-5]\d{3,4}|[6-9]\d{3}))?$/;
|
|
47313
|
+
var buildUrl = /* @__PURE__ */ __name((scheme, host, incomingUrl) => {
|
|
47314
|
+
const url2 = `${scheme}://${host}${incomingUrl}`;
|
|
47315
|
+
if (!reValidHost.test(host)) {
|
|
47316
|
+
const urlObj = new URL(url2);
|
|
47317
|
+
if (urlObj.hostname.length !== host.length && urlObj.hostname !== (host.includes(":") ? host.replace(/:\d+$/, "") : host).toLowerCase()) throw new RequestError("Invalid host header");
|
|
47318
|
+
return urlObj.href;
|
|
47319
|
+
} else if (incomingUrl.length === 0) return url2 + "/";
|
|
47320
|
+
else {
|
|
47321
|
+
if (incomingUrl.charCodeAt(0) !== 47) throw new RequestError("Invalid URL");
|
|
47322
|
+
if (!reValidRequestUrl.test(incomingUrl) || reDotSegment.test(incomingUrl)) return new URL(url2).href;
|
|
47323
|
+
return url2;
|
|
47324
|
+
}
|
|
47325
|
+
}, "buildUrl");
|
|
47326
|
+
var toRequestError = /* @__PURE__ */ __name((e) => {
|
|
47327
|
+
if (e instanceof RequestError) return e;
|
|
47328
|
+
return new RequestError(e.message, { cause: e });
|
|
47329
|
+
}, "toRequestError");
|
|
47330
|
+
var GlobalRequest = global.Request;
|
|
47331
|
+
var Request$1 = class extends GlobalRequest {
|
|
47332
|
+
static {
|
|
47333
|
+
__name(this, "Request$1");
|
|
47334
|
+
}
|
|
47335
|
+
constructor(input2, options) {
|
|
47336
|
+
if (typeof input2 === "object" && getRequestCache in input2) {
|
|
47337
|
+
const hasReplacementBody = options !== void 0 && "body" in options && options.body != null;
|
|
47338
|
+
if (input2[bodyConsumedDirectlyKey] && !hasReplacementBody) throw new TypeError("Cannot construct a Request with a Request object that has already been used.");
|
|
47339
|
+
input2 = input2[getRequestCache]();
|
|
47340
|
+
}
|
|
47341
|
+
if (typeof options?.body?.getReader !== "undefined") options.duplex ??= "half";
|
|
47342
|
+
super(input2, options);
|
|
47343
|
+
}
|
|
47344
|
+
};
|
|
47345
|
+
var wrapBodyStream = /* @__PURE__ */ Symbol("wrapBodyStream");
|
|
47346
|
+
var byteExactEncodings = /* @__PURE__ */ new Set([
|
|
47347
|
+
"latin1",
|
|
47348
|
+
"binary",
|
|
47349
|
+
"hex",
|
|
47350
|
+
"base64",
|
|
47351
|
+
"base64url"
|
|
47352
|
+
]);
|
|
47353
|
+
var isByteExactEncoding = /* @__PURE__ */ __name((encoding) => encoding === null || byteExactEncodings.has(encoding), "isByteExactEncoding");
|
|
47354
|
+
var bodyBufferedBeforeDisconnectKey = /* @__PURE__ */ Symbol("bodyBufferedBeforeDisconnect");
|
|
47355
|
+
var bodyBufferedLengthBeforeDisconnectKey = /* @__PURE__ */ Symbol("bodyBufferedLengthBeforeDisconnect");
|
|
47356
|
+
var toBufferChunk = /* @__PURE__ */ __name((chunk, encoding) => Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding ?? "utf8"), "toBufferChunk");
|
|
47357
|
+
var isRecoverableDisconnectedIncoming = /* @__PURE__ */ __name((incoming) => !(incoming instanceof import_node_http2.Http2ServerRequest) && !!incoming.complete && !!incoming.readableAborted && typeof incoming.read === "function" && isByteExactEncoding(incoming.readableEncoding), "isRecoverableDisconnectedIncoming");
|
|
47358
|
+
var recordBodyBufferedBeforeDisconnect = /* @__PURE__ */ __name((incoming) => {
|
|
47359
|
+
if (incoming.readableDidRead || !isRecoverableDisconnectedIncoming(incoming)) return;
|
|
47360
|
+
const incomingWithRecovery = incoming;
|
|
47361
|
+
incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey] ??= incoming.readableLength;
|
|
47362
|
+
}, "recordBodyBufferedBeforeDisconnect");
|
|
47363
|
+
var readBodyBufferedBeforeDisconnect = /* @__PURE__ */ __name((incoming, chunks) => {
|
|
47364
|
+
if (incoming.readableDidRead && !chunks || !isRecoverableDisconnectedIncoming(incoming)) return;
|
|
47365
|
+
const incomingWithRecovery = incoming;
|
|
47366
|
+
if (incomingWithRecovery[bodyBufferedBeforeDisconnectKey] !== void 0) return incomingWithRecovery[bodyBufferedBeforeDisconnectKey];
|
|
47367
|
+
let result;
|
|
47368
|
+
const errored = incoming.errored;
|
|
47369
|
+
if (errored && errored.code !== "ECONNRESET") result = errored;
|
|
47370
|
+
else if (incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey] !== void 0 && incoming.readableLength !== incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey]) result = newBodyUnusableError();
|
|
47371
|
+
else {
|
|
47372
|
+
const bodyChunks = chunks ?? [];
|
|
47373
|
+
const chunk = incoming.read();
|
|
47374
|
+
if (chunk !== null) bodyChunks.push(toBufferChunk(chunk, incoming.readableEncoding));
|
|
47375
|
+
const buffer = bodyChunks.length === 1 ? bodyChunks[0] : Buffer.concat(bodyChunks);
|
|
47376
|
+
result = buffer;
|
|
47377
|
+
const contentLength = incoming.headers["content-length"];
|
|
47378
|
+
if (typeof contentLength === "string" && /^\d+$/.test(contentLength)) {
|
|
47379
|
+
const expectedLength = Number(contentLength);
|
|
47380
|
+
if (Number.isSafeInteger(expectedLength) && buffer.length !== expectedLength) result = newBodyUnusableError();
|
|
47381
|
+
}
|
|
47382
|
+
}
|
|
47383
|
+
incomingWithRecovery[bodyBufferedBeforeDisconnectKey] = result;
|
|
47384
|
+
return result;
|
|
47385
|
+
}, "readBodyBufferedBeforeDisconnect");
|
|
47386
|
+
var enqueueBufferedBody = /* @__PURE__ */ __name((controller, buffered) => {
|
|
47387
|
+
if (buffered instanceof Error) {
|
|
47388
|
+
controller.error(buffered);
|
|
47389
|
+
return;
|
|
47390
|
+
}
|
|
47391
|
+
if (buffered.length > 0) controller.enqueue(buffered);
|
|
47392
|
+
controller.close();
|
|
47393
|
+
}, "enqueueBufferedBody");
|
|
47394
|
+
var newRequestFromIncoming = /* @__PURE__ */ __name((method, url2, headers, incoming, abortController) => {
|
|
47395
|
+
const init = {
|
|
47396
|
+
method,
|
|
47397
|
+
headers,
|
|
47398
|
+
signal: abortController.signal
|
|
47399
|
+
};
|
|
47400
|
+
if (method === "TRACE") {
|
|
47401
|
+
init.method = "GET";
|
|
47402
|
+
const req = new Request$1(url2, init);
|
|
47403
|
+
Object.defineProperty(req, "method", { get() {
|
|
47404
|
+
return "TRACE";
|
|
47405
|
+
} });
|
|
47406
|
+
return req;
|
|
47407
|
+
}
|
|
47408
|
+
if (!(method === "GET" || method === "HEAD")) if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) init.body = new ReadableStream({ start(controller) {
|
|
47409
|
+
controller.enqueue(incoming.rawBody);
|
|
47410
|
+
controller.close();
|
|
47411
|
+
} });
|
|
47412
|
+
else if (incoming[wrapBodyStream]) {
|
|
47413
|
+
let reader;
|
|
47414
|
+
init.body = new ReadableStream({ async pull(controller) {
|
|
47415
|
+
try {
|
|
47416
|
+
if (!reader) {
|
|
47417
|
+
const buffered = readBodyBufferedBeforeDisconnect(incoming);
|
|
47418
|
+
if (buffered !== void 0) {
|
|
47419
|
+
enqueueBufferedBody(controller, buffered);
|
|
47420
|
+
return;
|
|
47421
|
+
}
|
|
47422
|
+
}
|
|
47423
|
+
reader ||= import_node_stream.Readable.toWeb(incoming).getReader();
|
|
47424
|
+
const { done, value } = await reader.read();
|
|
47425
|
+
if (done) controller.close();
|
|
47426
|
+
else controller.enqueue(value);
|
|
47427
|
+
} catch (error62) {
|
|
47428
|
+
controller.error(error62);
|
|
47429
|
+
}
|
|
47430
|
+
} });
|
|
47431
|
+
} else {
|
|
47432
|
+
const buffered = readBodyBufferedBeforeDisconnect(incoming);
|
|
47433
|
+
if (buffered !== void 0) init.body = new ReadableStream({ start(controller) {
|
|
47434
|
+
enqueueBufferedBody(controller, buffered);
|
|
47435
|
+
} });
|
|
47436
|
+
else init.body = import_node_stream.Readable.toWeb(incoming);
|
|
47437
|
+
}
|
|
47438
|
+
return new Request$1(url2, init);
|
|
47439
|
+
}, "newRequestFromIncoming");
|
|
47440
|
+
var getRequestCache = /* @__PURE__ */ Symbol("getRequestCache");
|
|
47441
|
+
var requestCache = /* @__PURE__ */ Symbol("requestCache");
|
|
47442
|
+
var incomingKey = /* @__PURE__ */ Symbol("incomingKey");
|
|
47443
|
+
var urlKey = /* @__PURE__ */ Symbol("urlKey");
|
|
47444
|
+
var methodKey = /* @__PURE__ */ Symbol("methodKey");
|
|
47445
|
+
var headersKey = /* @__PURE__ */ Symbol("headersKey");
|
|
47446
|
+
var abortControllerKey = /* @__PURE__ */ Symbol("abortControllerKey");
|
|
47447
|
+
var getAbortController = /* @__PURE__ */ Symbol("getAbortController");
|
|
47448
|
+
var abortRequest = /* @__PURE__ */ Symbol("abortRequest");
|
|
47449
|
+
var bodyBufferKey = /* @__PURE__ */ Symbol("bodyBuffer");
|
|
47450
|
+
var bodyReadPromiseKey = /* @__PURE__ */ Symbol("bodyReadPromise");
|
|
47451
|
+
var bodyConsumedDirectlyKey = /* @__PURE__ */ Symbol("bodyConsumedDirectly");
|
|
47452
|
+
var bodyLockReaderKey = /* @__PURE__ */ Symbol("bodyLockReader");
|
|
47453
|
+
var abortReasonKey = /* @__PURE__ */ Symbol("abortReason");
|
|
47454
|
+
var newBodyUnusableError = /* @__PURE__ */ __name(() => {
|
|
47455
|
+
return /* @__PURE__ */ new TypeError("Body is unusable");
|
|
47456
|
+
}, "newBodyUnusableError");
|
|
47457
|
+
var rejectBodyUnusable = /* @__PURE__ */ __name(() => {
|
|
47458
|
+
return Promise.reject(newBodyUnusableError());
|
|
47459
|
+
}, "rejectBodyUnusable");
|
|
47460
|
+
var textDecoder = new TextDecoder();
|
|
47461
|
+
var consumeBodyDirectOnce = /* @__PURE__ */ __name((request) => {
|
|
47462
|
+
if (request[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
47463
|
+
request[bodyConsumedDirectlyKey] = true;
|
|
47464
|
+
}, "consumeBodyDirectOnce");
|
|
47465
|
+
var toArrayBuffer = /* @__PURE__ */ __name((buf) => {
|
|
47466
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
47467
|
+
}, "toArrayBuffer");
|
|
47468
|
+
var contentType = /* @__PURE__ */ __name((request) => {
|
|
47469
|
+
return (request[headersKey] ||= newHeadersFromIncoming(request[incomingKey])).get("content-type") || "";
|
|
47470
|
+
}, "contentType");
|
|
47471
|
+
var methodTokenRegExp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
47472
|
+
var normalizeIncomingMethod = /* @__PURE__ */ __name((method) => {
|
|
47473
|
+
if (typeof method !== "string" || method.length === 0) return "GET";
|
|
47474
|
+
switch (method) {
|
|
47475
|
+
case "DELETE":
|
|
47476
|
+
case "GET":
|
|
47477
|
+
case "HEAD":
|
|
47478
|
+
case "OPTIONS":
|
|
47479
|
+
case "PATCH":
|
|
47480
|
+
case "POST":
|
|
47481
|
+
case "PUT":
|
|
47482
|
+
case "QUERY":
|
|
47483
|
+
return method;
|
|
47484
|
+
}
|
|
47485
|
+
const upper = method.toUpperCase();
|
|
47486
|
+
switch (upper) {
|
|
47487
|
+
case "DELETE":
|
|
47488
|
+
case "GET":
|
|
47489
|
+
case "HEAD":
|
|
47490
|
+
case "OPTIONS":
|
|
47491
|
+
case "POST":
|
|
47492
|
+
case "PUT":
|
|
47493
|
+
return upper;
|
|
47494
|
+
default:
|
|
47495
|
+
return method;
|
|
47496
|
+
}
|
|
47497
|
+
}, "normalizeIncomingMethod");
|
|
47498
|
+
var validateDirectReadMethod = /* @__PURE__ */ __name((method) => {
|
|
47499
|
+
if (!methodTokenRegExp.test(method)) return /* @__PURE__ */ new TypeError(`'${method}' is not a valid HTTP method.`);
|
|
47500
|
+
const normalized = method.toUpperCase();
|
|
47501
|
+
if (normalized === "CONNECT" || normalized === "TRACK" || normalized === "TRACE" && method !== "TRACE") return /* @__PURE__ */ new TypeError(`'${method}' HTTP method is unsupported.`);
|
|
47502
|
+
}, "validateDirectReadMethod");
|
|
47503
|
+
var readBodyWithFastPath = /* @__PURE__ */ __name((request, method, fromBuffer) => {
|
|
47504
|
+
if (request[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
47505
|
+
const methodName = request.method;
|
|
47506
|
+
if (methodName === "GET" || methodName === "HEAD") return request[getRequestCache]()[method]();
|
|
47507
|
+
const methodValidationError = validateDirectReadMethod(methodName);
|
|
47508
|
+
if (methodValidationError) return Promise.reject(methodValidationError);
|
|
47509
|
+
if (request[requestCache]) {
|
|
47510
|
+
if (methodName !== "TRACE") return request[requestCache][method]();
|
|
47511
|
+
}
|
|
47512
|
+
const alreadyUsedError = consumeBodyDirectOnce(request);
|
|
47513
|
+
if (alreadyUsedError) return alreadyUsedError;
|
|
47514
|
+
const raw = readRawBodyIfAvailable(request);
|
|
47515
|
+
if (raw) {
|
|
47516
|
+
const result = Promise.resolve(fromBuffer(raw, request));
|
|
47517
|
+
request[bodyBufferKey] = void 0;
|
|
47518
|
+
return result;
|
|
47519
|
+
}
|
|
47520
|
+
return readBodyDirect(request).then((buf) => {
|
|
47521
|
+
const result = fromBuffer(buf, request);
|
|
47522
|
+
request[bodyBufferKey] = void 0;
|
|
47523
|
+
return result;
|
|
47524
|
+
});
|
|
47525
|
+
}, "readBodyWithFastPath");
|
|
47526
|
+
var readRawBodyIfAvailable = /* @__PURE__ */ __name((request) => {
|
|
47527
|
+
const incoming = request[incomingKey];
|
|
47528
|
+
if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) return incoming.rawBody;
|
|
47529
|
+
}, "readRawBodyIfAvailable");
|
|
47530
|
+
var normalizeAbortError = /* @__PURE__ */ __name((request, incoming) => {
|
|
47531
|
+
if (incoming.errored) return incoming.errored;
|
|
47532
|
+
const reason = request[abortReasonKey];
|
|
47533
|
+
if (reason !== void 0) return reason instanceof Error ? reason : new Error(String(reason));
|
|
47534
|
+
return /* @__PURE__ */ new Error("Client connection prematurely closed.");
|
|
47535
|
+
}, "normalizeAbortError");
|
|
47536
|
+
var readBodyDirect = /* @__PURE__ */ __name((request) => {
|
|
47537
|
+
if (request[bodyBufferKey]) return Promise.resolve(request[bodyBufferKey]);
|
|
47538
|
+
if (request[bodyReadPromiseKey]) return request[bodyReadPromiseKey];
|
|
47539
|
+
const incoming = request[incomingKey];
|
|
47540
|
+
if (incoming.readableDidRead) return rejectBodyUnusable();
|
|
47541
|
+
const buffered = readBodyBufferedBeforeDisconnect(incoming);
|
|
47542
|
+
if (buffered !== void 0) {
|
|
47543
|
+
if (buffered instanceof Error) return Promise.reject(buffered);
|
|
47544
|
+
request[bodyBufferKey] = buffered;
|
|
47545
|
+
return Promise.resolve(buffered);
|
|
47546
|
+
}
|
|
47547
|
+
const promise2 = new Promise((resolve, reject) => {
|
|
47548
|
+
const chunks = [];
|
|
47549
|
+
let settled = false;
|
|
47550
|
+
const finish = /* @__PURE__ */ __name((callback) => {
|
|
47551
|
+
if (settled) return;
|
|
47552
|
+
settled = true;
|
|
47553
|
+
cleanup();
|
|
47554
|
+
callback();
|
|
47555
|
+
}, "finish");
|
|
47556
|
+
const recoverCompleteBodyAfterDisconnect = /* @__PURE__ */ __name((error62) => {
|
|
47557
|
+
const streamError = incoming.errored ?? error62;
|
|
47558
|
+
if (!isRecoverableDisconnectedIncoming(incoming) || streamError && streamError.code !== "ECONNRESET") return false;
|
|
47559
|
+
finish(() => {
|
|
47560
|
+
const recovered = readBodyBufferedBeforeDisconnect(incoming, chunks);
|
|
47561
|
+
if (recovered instanceof Error) reject(recovered);
|
|
47562
|
+
else if (recovered === void 0) reject(error62 ?? normalizeAbortError(request, incoming));
|
|
47563
|
+
else {
|
|
47564
|
+
request[bodyBufferKey] = recovered;
|
|
47565
|
+
resolve(recovered);
|
|
47566
|
+
}
|
|
47567
|
+
});
|
|
47568
|
+
return true;
|
|
47569
|
+
}, "recoverCompleteBodyAfterDisconnect");
|
|
47570
|
+
const onData = /* @__PURE__ */ __name((chunk) => {
|
|
47571
|
+
chunks.push(toBufferChunk(chunk, incoming.readableEncoding));
|
|
47572
|
+
}, "onData");
|
|
47573
|
+
const onEnd = /* @__PURE__ */ __name(() => {
|
|
47574
|
+
finish(() => {
|
|
47575
|
+
const buffer = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks);
|
|
47576
|
+
request[bodyBufferKey] = buffer;
|
|
47577
|
+
resolve(buffer);
|
|
47578
|
+
});
|
|
47579
|
+
}, "onEnd");
|
|
47580
|
+
const onError = /* @__PURE__ */ __name((error62) => {
|
|
47581
|
+
if (recoverCompleteBodyAfterDisconnect(error62)) return;
|
|
47582
|
+
finish(() => {
|
|
47583
|
+
reject(error62);
|
|
47584
|
+
});
|
|
47585
|
+
}, "onError");
|
|
47586
|
+
const onClose = /* @__PURE__ */ __name(() => {
|
|
47587
|
+
if (incoming.readableEnded) {
|
|
47588
|
+
onEnd();
|
|
47589
|
+
return;
|
|
47590
|
+
}
|
|
47591
|
+
if (recoverCompleteBodyAfterDisconnect()) return;
|
|
47592
|
+
finish(() => {
|
|
47593
|
+
reject(normalizeAbortError(request, incoming));
|
|
47594
|
+
});
|
|
47595
|
+
}, "onClose");
|
|
47596
|
+
const cleanup = /* @__PURE__ */ __name(() => {
|
|
47597
|
+
incoming.off("data", onData);
|
|
47598
|
+
incoming.off("end", onEnd);
|
|
47599
|
+
incoming.off("error", onError);
|
|
47600
|
+
incoming.off("close", onClose);
|
|
47601
|
+
request[bodyReadPromiseKey] = void 0;
|
|
47602
|
+
}, "cleanup");
|
|
47603
|
+
incoming.on("data", onData);
|
|
47604
|
+
incoming.on("end", onEnd);
|
|
47605
|
+
incoming.on("error", onError);
|
|
47606
|
+
incoming.on("close", onClose);
|
|
47607
|
+
queueMicrotask(() => {
|
|
47608
|
+
if (settled) return;
|
|
47609
|
+
if (incoming.readableEnded) onEnd();
|
|
47610
|
+
else if (incoming.errored) onError(incoming.errored);
|
|
47611
|
+
else if (incoming.destroyed) onClose();
|
|
47612
|
+
});
|
|
47613
|
+
});
|
|
47614
|
+
request[bodyReadPromiseKey] = promise2;
|
|
47615
|
+
return promise2;
|
|
47616
|
+
}, "readBodyDirect");
|
|
47617
|
+
var requestPrototype = {
|
|
47618
|
+
get method() {
|
|
47619
|
+
return this[methodKey];
|
|
47620
|
+
},
|
|
47621
|
+
get url() {
|
|
47622
|
+
return this[urlKey];
|
|
47623
|
+
},
|
|
47624
|
+
get headers() {
|
|
47625
|
+
return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
|
|
47626
|
+
},
|
|
47627
|
+
[abortRequest](reason) {
|
|
47628
|
+
if (this[abortReasonKey] === void 0) this[abortReasonKey] = reason;
|
|
47629
|
+
const abortController = this[abortControllerKey];
|
|
47630
|
+
if (abortController && !abortController.signal.aborted) abortController.abort(reason);
|
|
47631
|
+
},
|
|
47632
|
+
[getAbortController]() {
|
|
47633
|
+
this[abortControllerKey] ||= new AbortController();
|
|
47634
|
+
if (this[abortReasonKey] !== void 0 && !this[abortControllerKey].signal.aborted) this[abortControllerKey].abort(this[abortReasonKey]);
|
|
47635
|
+
return this[abortControllerKey];
|
|
47636
|
+
},
|
|
47637
|
+
[getRequestCache]() {
|
|
47638
|
+
const abortController = this[getAbortController]();
|
|
47639
|
+
if (this[requestCache]) return this[requestCache];
|
|
47640
|
+
const method = this.method;
|
|
47641
|
+
if (this[bodyConsumedDirectlyKey] && !(method === "GET" || method === "HEAD")) {
|
|
47642
|
+
this[bodyBufferKey] = void 0;
|
|
47643
|
+
const init = {
|
|
47644
|
+
method: method === "TRACE" ? "GET" : method,
|
|
47645
|
+
headers: this.headers,
|
|
47646
|
+
signal: abortController.signal
|
|
47647
|
+
};
|
|
47648
|
+
if (method !== "TRACE") {
|
|
47649
|
+
init.body = new ReadableStream({ start(c) {
|
|
47650
|
+
c.close();
|
|
47651
|
+
} });
|
|
47652
|
+
init.duplex = "half";
|
|
47653
|
+
}
|
|
47654
|
+
const req = new Request$1(this[urlKey], init);
|
|
47655
|
+
if (method === "TRACE") Object.defineProperty(req, "method", { get() {
|
|
47656
|
+
return "TRACE";
|
|
47657
|
+
} });
|
|
47658
|
+
return this[requestCache] = req;
|
|
47659
|
+
}
|
|
47660
|
+
return this[requestCache] = newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], abortController);
|
|
47661
|
+
},
|
|
47662
|
+
get body() {
|
|
47663
|
+
if (!this[bodyConsumedDirectlyKey]) return this[getRequestCache]().body;
|
|
47664
|
+
const request = this[getRequestCache]();
|
|
47665
|
+
if (!this[bodyLockReaderKey] && request.body) this[bodyLockReaderKey] = request.body.getReader();
|
|
47666
|
+
return request.body;
|
|
47667
|
+
},
|
|
47668
|
+
get bodyUsed() {
|
|
47669
|
+
if (this[bodyConsumedDirectlyKey]) return true;
|
|
47670
|
+
if (this[requestCache]) return this[requestCache].bodyUsed;
|
|
47671
|
+
return false;
|
|
47672
|
+
}
|
|
47673
|
+
};
|
|
47674
|
+
Object.defineProperty(requestPrototype, "signal", { get() {
|
|
47675
|
+
return this[getAbortController]().signal;
|
|
47676
|
+
} });
|
|
47677
|
+
[
|
|
47678
|
+
"cache",
|
|
47679
|
+
"credentials",
|
|
47680
|
+
"destination",
|
|
47681
|
+
"integrity",
|
|
47682
|
+
"mode",
|
|
47683
|
+
"redirect",
|
|
47684
|
+
"referrer",
|
|
47685
|
+
"referrerPolicy",
|
|
47686
|
+
"keepalive"
|
|
47687
|
+
].forEach((k) => {
|
|
47688
|
+
Object.defineProperty(requestPrototype, k, { get() {
|
|
47689
|
+
return this[getRequestCache]()[k];
|
|
47690
|
+
} });
|
|
47691
|
+
});
|
|
47692
|
+
["clone", "formData"].forEach((k) => {
|
|
47693
|
+
Object.defineProperty(requestPrototype, k, { value: /* @__PURE__ */ __name(function() {
|
|
47694
|
+
if (this[bodyConsumedDirectlyKey]) {
|
|
47695
|
+
if (k === "clone") throw newBodyUnusableError();
|
|
47696
|
+
return rejectBodyUnusable();
|
|
47697
|
+
}
|
|
47698
|
+
return this[getRequestCache]()[k]();
|
|
47699
|
+
}, "value") });
|
|
47700
|
+
});
|
|
47701
|
+
Object.defineProperty(requestPrototype, "text", { value: /* @__PURE__ */ __name(function() {
|
|
47702
|
+
return readBodyWithFastPath(this, "text", (buf) => textDecoder.decode(buf));
|
|
47703
|
+
}, "value") });
|
|
47704
|
+
Object.defineProperty(requestPrototype, "arrayBuffer", { value: /* @__PURE__ */ __name(function() {
|
|
47705
|
+
return readBodyWithFastPath(this, "arrayBuffer", (buf) => toArrayBuffer(buf));
|
|
47706
|
+
}, "value") });
|
|
47707
|
+
Object.defineProperty(requestPrototype, "blob", { value: /* @__PURE__ */ __name(function() {
|
|
47708
|
+
return readBodyWithFastPath(this, "blob", (buf, request) => {
|
|
47709
|
+
const type = contentType(request);
|
|
47710
|
+
const init = type ? { headers: { "content-type": type } } : void 0;
|
|
47711
|
+
return new Response(buf, init).blob();
|
|
47712
|
+
});
|
|
47713
|
+
}, "value") });
|
|
47714
|
+
Object.defineProperty(requestPrototype, "json", { value: /* @__PURE__ */ __name(function() {
|
|
47715
|
+
if (this[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
47716
|
+
return this.text().then(JSON.parse);
|
|
47717
|
+
}, "value") });
|
|
47718
|
+
Object.defineProperty(requestPrototype, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"), { value: /* @__PURE__ */ __name(function(depth, options, inspectFn) {
|
|
47719
|
+
return `Request (lightweight) ${inspectFn({
|
|
47720
|
+
method: this.method,
|
|
47721
|
+
url: this.url,
|
|
47722
|
+
headers: this.headers,
|
|
47723
|
+
nativeRequest: this[requestCache]
|
|
47724
|
+
}, {
|
|
47725
|
+
...options,
|
|
47726
|
+
depth: depth == null ? null : depth - 1
|
|
47727
|
+
})}`;
|
|
47728
|
+
}, "value") });
|
|
47729
|
+
Object.setPrototypeOf(requestPrototype, Request$1.prototype);
|
|
47730
|
+
var newRequest = /* @__PURE__ */ __name((incoming, defaultHostname) => {
|
|
47731
|
+
const req = Object.create(requestPrototype);
|
|
47732
|
+
req[incomingKey] = incoming;
|
|
47733
|
+
req[methodKey] = normalizeIncomingMethod(incoming.method);
|
|
47734
|
+
const incomingUrl = incoming.url || "";
|
|
47735
|
+
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
47736
|
+
if (incoming instanceof import_node_http2.Http2ServerRequest) throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
47737
|
+
try {
|
|
47738
|
+
req[urlKey] = new URL(incomingUrl).href;
|
|
47739
|
+
} catch (e) {
|
|
47740
|
+
throw new RequestError("Invalid absolute URL", { cause: e });
|
|
47741
|
+
}
|
|
47742
|
+
return req;
|
|
47743
|
+
}
|
|
47744
|
+
const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
|
|
47745
|
+
if (!host) throw new RequestError("Missing host header");
|
|
47746
|
+
let scheme;
|
|
47747
|
+
if (incoming instanceof import_node_http2.Http2ServerRequest) {
|
|
47748
|
+
scheme = incoming.scheme;
|
|
47749
|
+
if (!(scheme === "http" || scheme === "https")) throw new RequestError("Unsupported scheme");
|
|
47750
|
+
} else scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
|
|
47751
|
+
try {
|
|
47752
|
+
req[urlKey] = buildUrl(scheme, host, incomingUrl);
|
|
47753
|
+
} catch (e) {
|
|
47754
|
+
if (e instanceof RequestError) throw e;
|
|
47755
|
+
else throw new RequestError("Invalid URL", { cause: e });
|
|
47756
|
+
}
|
|
47757
|
+
return req;
|
|
47758
|
+
}, "newRequest");
|
|
47759
|
+
var defaultContentType = "text/plain; charset=UTF-8";
|
|
47760
|
+
var responseCache = /* @__PURE__ */ Symbol("responseCache");
|
|
47761
|
+
var getResponseCache = /* @__PURE__ */ Symbol("getResponseCache");
|
|
47762
|
+
var cacheKey = /* @__PURE__ */ Symbol("cache");
|
|
47763
|
+
var GlobalResponse = global.Response;
|
|
47764
|
+
var Response$1 = class Response$12 {
|
|
47765
|
+
static {
|
|
47766
|
+
__name(this, "Response$1");
|
|
47767
|
+
}
|
|
47768
|
+
#body;
|
|
47769
|
+
#init;
|
|
47770
|
+
[getResponseCache]() {
|
|
47771
|
+
const cache = this[cacheKey];
|
|
47772
|
+
const liveHeaders = cache && cache[2] instanceof Headers ? cache[2] : void 0;
|
|
47773
|
+
delete this[cacheKey];
|
|
47774
|
+
return this[responseCache] ||= new GlobalResponse(this.#body, liveHeaders ? {
|
|
47775
|
+
status: this.#init?.status,
|
|
47776
|
+
statusText: this.#init?.statusText,
|
|
47777
|
+
headers: liveHeaders
|
|
47778
|
+
} : this.#init);
|
|
47779
|
+
}
|
|
47780
|
+
constructor(body, init) {
|
|
47781
|
+
let headers;
|
|
47782
|
+
this.#body = body;
|
|
47783
|
+
if (init instanceof GlobalResponse) {
|
|
47784
|
+
const cachedGlobalResponse = init[responseCache];
|
|
47785
|
+
if (cachedGlobalResponse) {
|
|
47786
|
+
this.#init = cachedGlobalResponse;
|
|
47787
|
+
this[getResponseCache]();
|
|
47788
|
+
return;
|
|
47789
|
+
}
|
|
47790
|
+
this.#init = init instanceof Response$12 ? init.#init : init;
|
|
47791
|
+
headers = new Headers(init.headers);
|
|
47792
|
+
} else this.#init = init;
|
|
47793
|
+
if (body == null || typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) this[cacheKey] = [
|
|
47794
|
+
init?.status || 200,
|
|
47795
|
+
body ?? null,
|
|
47796
|
+
headers || init?.headers
|
|
47797
|
+
];
|
|
47798
|
+
}
|
|
47799
|
+
get headers() {
|
|
47800
|
+
const cache = this[cacheKey];
|
|
47801
|
+
if (cache) {
|
|
47802
|
+
if (!(cache[2] instanceof Headers)) cache[2] = new Headers(cache[2] || (cache[1] === null ? void 0 : { "content-type": defaultContentType }));
|
|
47803
|
+
return cache[2];
|
|
47804
|
+
}
|
|
47805
|
+
return this[getResponseCache]().headers;
|
|
47806
|
+
}
|
|
47807
|
+
get status() {
|
|
47808
|
+
return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
|
|
47809
|
+
}
|
|
47810
|
+
get ok() {
|
|
47811
|
+
const status = this.status;
|
|
47812
|
+
return status >= 200 && status < 300;
|
|
47813
|
+
}
|
|
47814
|
+
};
|
|
47815
|
+
[
|
|
47816
|
+
"body",
|
|
47817
|
+
"bodyUsed",
|
|
47818
|
+
"redirected",
|
|
47819
|
+
"statusText",
|
|
47820
|
+
"trailers",
|
|
47821
|
+
"type",
|
|
47822
|
+
"url"
|
|
47823
|
+
].forEach((k) => {
|
|
47824
|
+
Object.defineProperty(Response$1.prototype, k, { get() {
|
|
47825
|
+
return this[getResponseCache]()[k];
|
|
47826
|
+
} });
|
|
47827
|
+
});
|
|
47828
|
+
[
|
|
47829
|
+
"arrayBuffer",
|
|
47830
|
+
"blob",
|
|
47831
|
+
"clone",
|
|
47832
|
+
"formData",
|
|
47833
|
+
"json",
|
|
47834
|
+
"text"
|
|
47835
|
+
].forEach((k) => {
|
|
47836
|
+
Object.defineProperty(Response$1.prototype, k, { value: /* @__PURE__ */ __name(function() {
|
|
47837
|
+
return this[getResponseCache]()[k]();
|
|
47838
|
+
}, "value") });
|
|
47839
|
+
});
|
|
47840
|
+
Object.defineProperty(Response$1.prototype, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"), { value: /* @__PURE__ */ __name(function(depth, options, inspectFn) {
|
|
47841
|
+
return `Response (lightweight) ${inspectFn({
|
|
47842
|
+
status: this.status,
|
|
47843
|
+
headers: this.headers,
|
|
47844
|
+
ok: this.ok,
|
|
47845
|
+
nativeResponse: this[responseCache]
|
|
47846
|
+
}, {
|
|
47847
|
+
...options,
|
|
47848
|
+
depth: depth == null ? null : depth - 1
|
|
47849
|
+
})}`;
|
|
47850
|
+
}, "value") });
|
|
47851
|
+
Object.setPrototypeOf(Response$1, GlobalResponse);
|
|
47852
|
+
Object.setPrototypeOf(Response$1.prototype, GlobalResponse.prototype);
|
|
47853
|
+
var validRedirectUrl = /^https?:\/\/[!#-;=?-[\]_a-z~A-Z]+$/;
|
|
47854
|
+
var parseRedirectUrl = /* @__PURE__ */ __name((url2) => {
|
|
47855
|
+
if (url2 instanceof URL) return url2.href;
|
|
47856
|
+
if (validRedirectUrl.test(url2)) return url2;
|
|
47857
|
+
return new URL(url2).href;
|
|
47858
|
+
}, "parseRedirectUrl");
|
|
47859
|
+
var validRedirectStatuses = /* @__PURE__ */ new Set([
|
|
47860
|
+
301,
|
|
47861
|
+
302,
|
|
47862
|
+
303,
|
|
47863
|
+
307,
|
|
47864
|
+
308
|
|
47865
|
+
]);
|
|
47866
|
+
Object.defineProperty(Response$1, "redirect", {
|
|
47867
|
+
value: /* @__PURE__ */ __name(function redirect(url2, status = 302) {
|
|
47868
|
+
if (!validRedirectStatuses.has(status)) throw new RangeError("Invalid status code");
|
|
47869
|
+
return new Response$1(null, {
|
|
47870
|
+
status,
|
|
47871
|
+
headers: { location: parseRedirectUrl(url2) }
|
|
47872
|
+
});
|
|
47873
|
+
}, "redirect"),
|
|
47874
|
+
writable: true,
|
|
47875
|
+
configurable: true
|
|
47876
|
+
});
|
|
47877
|
+
Object.defineProperty(Response$1, "json", {
|
|
47878
|
+
value: /* @__PURE__ */ __name(function json2(data, init) {
|
|
47879
|
+
const body = JSON.stringify(data);
|
|
47880
|
+
if (body === void 0) throw new TypeError("The data is not JSON serializable");
|
|
47881
|
+
const initHeaders = init?.headers;
|
|
47882
|
+
let headers;
|
|
47883
|
+
if (initHeaders) {
|
|
47884
|
+
headers = new Headers(initHeaders);
|
|
47885
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
47886
|
+
} else headers = { "content-type": "application/json" };
|
|
47887
|
+
return new Response$1(body, {
|
|
47888
|
+
status: init?.status ?? 200,
|
|
47889
|
+
statusText: init?.statusText,
|
|
47890
|
+
headers
|
|
47891
|
+
});
|
|
47892
|
+
}, "json"),
|
|
47893
|
+
writable: true,
|
|
47894
|
+
configurable: true
|
|
47895
|
+
});
|
|
47896
|
+
async function readWithoutBlocking(readPromise) {
|
|
47897
|
+
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]);
|
|
47898
|
+
}
|
|
47899
|
+
__name(readWithoutBlocking, "readWithoutBlocking");
|
|
47900
|
+
function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
|
|
47901
|
+
const cancel = /* @__PURE__ */ __name((error62) => {
|
|
47902
|
+
reader.cancel(error62).catch(() => {
|
|
47903
|
+
});
|
|
47904
|
+
}, "cancel");
|
|
47905
|
+
writable.on("close", cancel);
|
|
47906
|
+
writable.on("error", cancel);
|
|
47907
|
+
(currentReadPromise ?? reader.read()).then(flow, handleStreamError);
|
|
47908
|
+
return reader.closed.finally(() => {
|
|
47909
|
+
writable.off("close", cancel);
|
|
47910
|
+
writable.off("error", cancel);
|
|
47911
|
+
});
|
|
47912
|
+
function handleStreamError(error62) {
|
|
47913
|
+
if (error62) writable.destroy(error62);
|
|
47914
|
+
}
|
|
47915
|
+
__name(handleStreamError, "handleStreamError");
|
|
47916
|
+
function onDrain() {
|
|
47917
|
+
reader.read().then(flow, handleStreamError);
|
|
47918
|
+
}
|
|
47919
|
+
__name(onDrain, "onDrain");
|
|
47920
|
+
function flow({ done, value }) {
|
|
47921
|
+
try {
|
|
47922
|
+
if (done) writable.end();
|
|
47923
|
+
else if (!writable.write(value)) writable.once("drain", onDrain);
|
|
47924
|
+
else return reader.read().then(flow, handleStreamError);
|
|
47925
|
+
} catch (e) {
|
|
47926
|
+
handleStreamError(e);
|
|
47927
|
+
}
|
|
47928
|
+
}
|
|
47929
|
+
__name(flow, "flow");
|
|
47930
|
+
}
|
|
47931
|
+
__name(writeFromReadableStreamDefaultReader, "writeFromReadableStreamDefaultReader");
|
|
47932
|
+
function writeFromReadableStream(stream, writable) {
|
|
47933
|
+
if (stream.locked) throw new TypeError("ReadableStream is locked.");
|
|
47934
|
+
else if (writable.destroyed) return;
|
|
47935
|
+
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
47936
|
+
}
|
|
47937
|
+
__name(writeFromReadableStream, "writeFromReadableStream");
|
|
47938
|
+
var buildOutgoingHttpHeaders = /* @__PURE__ */ __name((headers, defaultContentType2) => {
|
|
47939
|
+
const res = {};
|
|
47940
|
+
if (!(headers instanceof Headers)) headers = new Headers(headers ?? void 0);
|
|
47941
|
+
if (headers.has("set-cookie")) {
|
|
47942
|
+
const cookies = [];
|
|
47943
|
+
for (const [k, v] of headers) if (k === "set-cookie") cookies.push(v);
|
|
47944
|
+
else res[k] = v;
|
|
47945
|
+
if (cookies.length > 0) res["set-cookie"] = cookies;
|
|
47946
|
+
} else for (const [k, v] of headers) res[k] = v;
|
|
47947
|
+
if (defaultContentType2) res["content-type"] ??= defaultContentType2;
|
|
47948
|
+
return res;
|
|
47949
|
+
}, "buildOutgoingHttpHeaders");
|
|
47950
|
+
var outgoingEnded = /* @__PURE__ */ Symbol("outgoingEnded");
|
|
47951
|
+
var incomingDraining = /* @__PURE__ */ Symbol("incomingDraining");
|
|
47952
|
+
var DRAIN_TIMEOUT_MS = 500;
|
|
47953
|
+
var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
|
|
47954
|
+
var drainIncoming = /* @__PURE__ */ __name((incoming) => {
|
|
47955
|
+
const incomingWithDrainState = incoming;
|
|
47956
|
+
if (incoming.destroyed || incomingWithDrainState[incomingDraining]) return;
|
|
47957
|
+
incomingWithDrainState[incomingDraining] = true;
|
|
47958
|
+
if (incoming instanceof import_node_http2.Http2ServerRequest) {
|
|
47959
|
+
try {
|
|
47960
|
+
incoming.stream?.close?.(import_node_http2.constants.NGHTTP2_NO_ERROR);
|
|
47961
|
+
} catch {
|
|
47962
|
+
}
|
|
47963
|
+
return;
|
|
47964
|
+
}
|
|
47965
|
+
let bytesRead = 0;
|
|
47966
|
+
const cleanup = /* @__PURE__ */ __name(() => {
|
|
47967
|
+
clearTimeout(timer);
|
|
47968
|
+
incoming.off("data", onData);
|
|
47969
|
+
incoming.off("end", cleanup);
|
|
47970
|
+
incoming.off("error", cleanup);
|
|
47971
|
+
}, "cleanup");
|
|
47972
|
+
const forceClose = /* @__PURE__ */ __name(() => {
|
|
47973
|
+
cleanup();
|
|
47974
|
+
const socket = incoming.socket;
|
|
47975
|
+
if (socket && !socket.destroyed) {
|
|
47976
|
+
if (typeof socket.destroySoon === "function") socket.destroySoon();
|
|
47977
|
+
else if (typeof socket.destroy === "function") socket.destroy();
|
|
47978
|
+
}
|
|
47979
|
+
}, "forceClose");
|
|
47980
|
+
const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
|
|
47981
|
+
timer.unref?.();
|
|
47982
|
+
const onData = /* @__PURE__ */ __name((chunk) => {
|
|
47983
|
+
bytesRead += chunk.length;
|
|
47984
|
+
if (bytesRead > MAX_DRAIN_BYTES) forceClose();
|
|
47985
|
+
}, "onData");
|
|
47986
|
+
incoming.on("data", onData);
|
|
47987
|
+
incoming.on("end", cleanup);
|
|
47988
|
+
incoming.on("error", cleanup);
|
|
47989
|
+
incoming.resume();
|
|
47990
|
+
}, "drainIncoming");
|
|
47991
|
+
var makeCloseHandler = /* @__PURE__ */ __name((req, incoming, outgoing, needsBodyCleanup) => () => {
|
|
47992
|
+
if (incoming.errored) {
|
|
47993
|
+
recordBodyBufferedBeforeDisconnect(incoming);
|
|
47994
|
+
req[abortRequest](incoming.errored.toString());
|
|
47995
|
+
} else if (!outgoing.writableFinished) {
|
|
47996
|
+
recordBodyBufferedBeforeDisconnect(incoming);
|
|
47997
|
+
req[abortRequest]("Client connection prematurely closed.");
|
|
47998
|
+
}
|
|
47999
|
+
if (needsBodyCleanup && !incoming.readableEnded) setTimeout(() => {
|
|
48000
|
+
if (!incoming.readableEnded) setTimeout(() => {
|
|
48001
|
+
drainIncoming(incoming);
|
|
48002
|
+
});
|
|
48003
|
+
});
|
|
48004
|
+
}, "makeCloseHandler");
|
|
48005
|
+
var isImmediateCacheableResponse = /* @__PURE__ */ __name((res) => {
|
|
48006
|
+
if (!(cacheKey in res)) return false;
|
|
48007
|
+
const body = res[cacheKey][1];
|
|
48008
|
+
return body === null || typeof body === "string" || body instanceof Uint8Array;
|
|
48009
|
+
}, "isImmediateCacheableResponse");
|
|
48010
|
+
var handleRequestError = /* @__PURE__ */ __name(() => new Response(null, { status: 400 }), "handleRequestError");
|
|
48011
|
+
var handleFetchError = /* @__PURE__ */ __name((e) => new Response(null, { status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 }), "handleFetchError");
|
|
48012
|
+
var handleResponseError = /* @__PURE__ */ __name((e, outgoing) => {
|
|
48013
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
48014
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") console.info("The user aborted a request.");
|
|
48015
|
+
else {
|
|
48016
|
+
console.error(e);
|
|
48017
|
+
if (!outgoing.headersSent) {
|
|
48018
|
+
if (outgoing instanceof import_node_http.ServerResponse) outgoing._contentLength = null;
|
|
48019
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
48020
|
+
}
|
|
48021
|
+
outgoing.end(`Error: ${err.message}`);
|
|
48022
|
+
outgoing.destroy(err);
|
|
48023
|
+
}
|
|
48024
|
+
}, "handleResponseError");
|
|
48025
|
+
var flushHeaders = /* @__PURE__ */ __name((outgoing) => {
|
|
48026
|
+
if ("flushHeaders" in outgoing && outgoing.writable) outgoing.flushHeaders();
|
|
48027
|
+
}, "flushHeaders");
|
|
48028
|
+
var trySetContentLength = /* @__PURE__ */ __name((outgoing, status, length) => {
|
|
48029
|
+
const http1 = outgoing;
|
|
48030
|
+
if (http1._contentLength === null && http1._hasBody && http1.useChunkedEncodingByDefault && !http1._removedContLen && status >= 200 && status !== 204 && status !== 304 && !outgoing.hasHeader("content-length") && !outgoing.hasHeader("transfer-encoding") && !outgoing.hasHeader("trailer")) {
|
|
48031
|
+
http1._contentLength = length;
|
|
48032
|
+
return true;
|
|
48033
|
+
}
|
|
48034
|
+
return false;
|
|
48035
|
+
}, "trySetContentLength");
|
|
48036
|
+
var writeDefaultHeaders = /* @__PURE__ */ __name((outgoing, status, length) => {
|
|
48037
|
+
if (trySetContentLength(outgoing, status, length)) outgoing.writeHead(status, { "Content-Type": defaultContentType });
|
|
48038
|
+
else outgoing.writeHead(status, {
|
|
48039
|
+
"Content-Type": defaultContentType,
|
|
48040
|
+
"Content-Length": length
|
|
48041
|
+
});
|
|
48042
|
+
}, "writeDefaultHeaders");
|
|
48043
|
+
var responseViaCache = /* @__PURE__ */ __name(async (res, outgoing) => {
|
|
48044
|
+
let [status, body, header] = res[cacheKey];
|
|
48045
|
+
if (!header) {
|
|
48046
|
+
if (body === null) {
|
|
48047
|
+
outgoing.writeHead(status);
|
|
48048
|
+
outgoing.end();
|
|
48049
|
+
} else if (typeof body === "string") {
|
|
48050
|
+
writeDefaultHeaders(outgoing, status, Buffer.byteLength(body));
|
|
48051
|
+
outgoing.end(body);
|
|
48052
|
+
} else if (body instanceof Uint8Array) {
|
|
48053
|
+
writeDefaultHeaders(outgoing, status, body.byteLength);
|
|
48054
|
+
outgoing.end(body);
|
|
48055
|
+
} else if (body instanceof Blob) {
|
|
48056
|
+
writeDefaultHeaders(outgoing, status, body.size);
|
|
48057
|
+
outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
48058
|
+
} else {
|
|
48059
|
+
outgoing.writeHead(status, { "Content-Type": defaultContentType });
|
|
48060
|
+
flushHeaders(outgoing);
|
|
48061
|
+
await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
|
|
48062
|
+
}
|
|
48063
|
+
outgoing[outgoingEnded]?.();
|
|
48064
|
+
return;
|
|
48065
|
+
}
|
|
48066
|
+
let hasContentLength = false;
|
|
48067
|
+
let plainHeaders = false;
|
|
48068
|
+
let canAutoLength = true;
|
|
48069
|
+
if (header instanceof Headers) {
|
|
48070
|
+
hasContentLength = header.has("content-length");
|
|
48071
|
+
header = buildOutgoingHttpHeaders(header, body === null ? void 0 : defaultContentType);
|
|
48072
|
+
} else if (Array.isArray(header)) {
|
|
48073
|
+
const headerObj = new Headers(header);
|
|
48074
|
+
hasContentLength = headerObj.has("content-length");
|
|
48075
|
+
header = buildOutgoingHttpHeaders(headerObj, body === null ? void 0 : defaultContentType);
|
|
48076
|
+
} else {
|
|
48077
|
+
plainHeaders = true;
|
|
48078
|
+
for (const key in header) {
|
|
48079
|
+
if (key.length === 14 && key.toLowerCase() === "content-length") {
|
|
48080
|
+
hasContentLength = true;
|
|
48081
|
+
break;
|
|
48082
|
+
}
|
|
48083
|
+
if (key.length === 17 && key.toLowerCase() === "transfer-encoding" || key.length === 7 && key.toLowerCase() === "trailer") canAutoLength = false;
|
|
48084
|
+
}
|
|
48085
|
+
}
|
|
48086
|
+
if (!hasContentLength) {
|
|
48087
|
+
let length;
|
|
48088
|
+
if (typeof body === "string") length = Buffer.byteLength(body);
|
|
48089
|
+
else if (body instanceof Uint8Array) length = body.byteLength;
|
|
48090
|
+
else if (body instanceof Blob) length = body.size;
|
|
48091
|
+
if (length !== void 0 && (!plainHeaders || !canAutoLength || !trySetContentLength(outgoing, status, length))) {
|
|
48092
|
+
if (plainHeaders) header = { ...header };
|
|
48093
|
+
header["Content-Length"] = length;
|
|
48094
|
+
}
|
|
48095
|
+
}
|
|
48096
|
+
outgoing.writeHead(status, header);
|
|
48097
|
+
if (body == null) outgoing.end();
|
|
48098
|
+
else if (typeof body === "string" || body instanceof Uint8Array) outgoing.end(body);
|
|
48099
|
+
else if (body instanceof Blob) outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
48100
|
+
else {
|
|
48101
|
+
flushHeaders(outgoing);
|
|
48102
|
+
await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
|
|
48103
|
+
}
|
|
48104
|
+
outgoing[outgoingEnded]?.();
|
|
48105
|
+
}, "responseViaCache");
|
|
48106
|
+
var isPromise = /* @__PURE__ */ __name((res) => typeof res.then === "function", "isPromise");
|
|
48107
|
+
var responseViaResponseObject = /* @__PURE__ */ __name(async (res, outgoing, options = {}) => {
|
|
48108
|
+
if (isPromise(res)) if (options.errorHandler) try {
|
|
48109
|
+
res = await res;
|
|
48110
|
+
} catch (err) {
|
|
48111
|
+
const errRes = await options.errorHandler(err);
|
|
48112
|
+
if (!errRes) return;
|
|
48113
|
+
res = errRes;
|
|
48114
|
+
}
|
|
48115
|
+
else res = await res.catch(handleFetchError);
|
|
48116
|
+
if (cacheKey in res) return responseViaCache(res, outgoing);
|
|
48117
|
+
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers, res.body === null ? void 0 : defaultContentType);
|
|
48118
|
+
if (res.body) {
|
|
48119
|
+
const reader = res.body.getReader();
|
|
48120
|
+
const values = [];
|
|
48121
|
+
let done = false;
|
|
48122
|
+
let currentReadPromise = void 0;
|
|
48123
|
+
if (resHeaderRecord["transfer-encoding"] !== "chunked") {
|
|
48124
|
+
let maxReadCount = 2;
|
|
48125
|
+
for (let i = 0; i < maxReadCount; i++) {
|
|
48126
|
+
currentReadPromise ||= reader.read();
|
|
48127
|
+
const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
|
|
48128
|
+
console.error(e);
|
|
48129
|
+
done = true;
|
|
48130
|
+
});
|
|
48131
|
+
if (!chunk) {
|
|
48132
|
+
if (i === 1) {
|
|
48133
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
48134
|
+
maxReadCount = 3;
|
|
48135
|
+
continue;
|
|
48136
|
+
}
|
|
48137
|
+
break;
|
|
48138
|
+
}
|
|
48139
|
+
currentReadPromise = void 0;
|
|
48140
|
+
if (chunk.value) values.push(chunk.value);
|
|
48141
|
+
if (chunk.done) {
|
|
48142
|
+
done = true;
|
|
48143
|
+
break;
|
|
48144
|
+
}
|
|
48145
|
+
}
|
|
48146
|
+
if (done && !("content-length" in resHeaderRecord)) resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
|
|
48147
|
+
}
|
|
48148
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
48149
|
+
values.forEach((value) => {
|
|
48150
|
+
outgoing.write(value);
|
|
48151
|
+
});
|
|
48152
|
+
if (done) outgoing.end();
|
|
48153
|
+
else {
|
|
48154
|
+
if (values.length === 0) flushHeaders(outgoing);
|
|
48155
|
+
await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
|
|
48156
|
+
}
|
|
48157
|
+
} else if (resHeaderRecord[X_ALREADY_SENT]) {
|
|
48158
|
+
} else {
|
|
48159
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
48160
|
+
outgoing.end();
|
|
48161
|
+
}
|
|
48162
|
+
outgoing[outgoingEnded]?.();
|
|
48163
|
+
}, "responseViaResponseObject");
|
|
48164
|
+
var getRequestListener = /* @__PURE__ */ __name((fetchCallback, options = {}) => {
|
|
48165
|
+
const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
|
|
48166
|
+
if (options.overrideGlobalObjects !== false && global.Request !== Request$1) {
|
|
48167
|
+
Object.defineProperty(global, "Request", { value: Request$1 });
|
|
48168
|
+
Object.defineProperty(global, "Response", { value: Response$1 });
|
|
48169
|
+
}
|
|
48170
|
+
return async (incoming, outgoing) => {
|
|
48171
|
+
let res, req;
|
|
48172
|
+
let needsBodyCleanup = false;
|
|
48173
|
+
let closeHandlerAttached = false;
|
|
48174
|
+
const ensureCloseHandler = /* @__PURE__ */ __name(() => {
|
|
48175
|
+
if (!req || closeHandlerAttached) return;
|
|
48176
|
+
closeHandlerAttached = true;
|
|
48177
|
+
outgoing.on("close", makeCloseHandler(req, incoming, outgoing, needsBodyCleanup));
|
|
48178
|
+
}, "ensureCloseHandler");
|
|
48179
|
+
try {
|
|
48180
|
+
req = newRequest(incoming, options.hostname);
|
|
48181
|
+
needsBodyCleanup = autoCleanupIncoming && !(incoming.method === "GET" || incoming.method === "HEAD");
|
|
48182
|
+
if (needsBodyCleanup) {
|
|
48183
|
+
incoming[wrapBodyStream] = true;
|
|
48184
|
+
if (incoming instanceof import_node_http2.Http2ServerRequest) outgoing[outgoingEnded] = () => {
|
|
48185
|
+
if (!incoming.readableEnded) setTimeout(() => {
|
|
48186
|
+
if (!incoming.readableEnded) setTimeout(() => {
|
|
48187
|
+
incoming.destroy();
|
|
48188
|
+
outgoing.destroy();
|
|
48189
|
+
});
|
|
48190
|
+
});
|
|
48191
|
+
};
|
|
48192
|
+
}
|
|
48193
|
+
res = fetchCallback(req, {
|
|
48194
|
+
incoming,
|
|
48195
|
+
outgoing
|
|
48196
|
+
});
|
|
48197
|
+
if (!isPromise(res) && isImmediateCacheableResponse(res)) {
|
|
48198
|
+
if (needsBodyCleanup && !incoming.readableEnded) outgoing.once("finish", () => {
|
|
48199
|
+
if (!incoming.readableEnded) drainIncoming(incoming);
|
|
48200
|
+
});
|
|
48201
|
+
return responseViaCache(res, outgoing);
|
|
48202
|
+
}
|
|
48203
|
+
ensureCloseHandler();
|
|
48204
|
+
} catch (e) {
|
|
48205
|
+
if (!res) if (options.errorHandler) {
|
|
48206
|
+
ensureCloseHandler();
|
|
48207
|
+
res = await options.errorHandler(req ? e : toRequestError(e));
|
|
48208
|
+
if (!res) return;
|
|
48209
|
+
} else if (!req) res = handleRequestError();
|
|
48210
|
+
else res = handleFetchError(e);
|
|
48211
|
+
else return handleResponseError(e, outgoing);
|
|
48212
|
+
}
|
|
48213
|
+
try {
|
|
48214
|
+
return await responseViaResponseObject(res, outgoing, options);
|
|
48215
|
+
} catch (e) {
|
|
48216
|
+
return handleResponseError(e, outgoing);
|
|
48217
|
+
}
|
|
48218
|
+
};
|
|
48219
|
+
}, "getRequestListener");
|
|
48220
|
+
var CloseEvent = globalThis.CloseEvent ?? class extends Event {
|
|
48221
|
+
#eventInitDict;
|
|
48222
|
+
constructor(type, eventInitDict = {}) {
|
|
48223
|
+
super(type, eventInitDict);
|
|
48224
|
+
this.#eventInitDict = eventInitDict;
|
|
48225
|
+
}
|
|
48226
|
+
get wasClean() {
|
|
48227
|
+
return this.#eventInitDict.wasClean ?? false;
|
|
48228
|
+
}
|
|
48229
|
+
get code() {
|
|
48230
|
+
return this.#eventInitDict.code ?? 0;
|
|
48231
|
+
}
|
|
48232
|
+
get reason() {
|
|
48233
|
+
return this.#eventInitDict.reason ?? "";
|
|
48234
|
+
}
|
|
48235
|
+
};
|
|
48236
|
+
var ErrorEvent = globalThis.ErrorEvent ?? class extends Event {
|
|
48237
|
+
#eventInitDict;
|
|
48238
|
+
constructor(type, eventInitDict = {}) {
|
|
48239
|
+
super(type, eventInitDict);
|
|
48240
|
+
this.#eventInitDict = eventInitDict;
|
|
48241
|
+
}
|
|
48242
|
+
get message() {
|
|
48243
|
+
return this.#eventInitDict.message ?? "";
|
|
48244
|
+
}
|
|
48245
|
+
get filename() {
|
|
48246
|
+
return this.#eventInitDict.filename ?? "";
|
|
48247
|
+
}
|
|
48248
|
+
get lineno() {
|
|
48249
|
+
return this.#eventInitDict.lineno ?? 0;
|
|
48250
|
+
}
|
|
48251
|
+
get colno() {
|
|
48252
|
+
return this.#eventInitDict.colno ?? 0;
|
|
48253
|
+
}
|
|
48254
|
+
get error() {
|
|
48255
|
+
return this.#eventInitDict.error ?? null;
|
|
48256
|
+
}
|
|
48257
|
+
};
|
|
48258
|
+
var generateConnectionSymbol = /* @__PURE__ */ __name(() => /* @__PURE__ */ Symbol("connection"), "generateConnectionSymbol");
|
|
48259
|
+
var CONNECTION_SYMBOL_KEY = /* @__PURE__ */ Symbol("CONNECTION_SYMBOL_KEY");
|
|
48260
|
+
var WAIT_FOR_WEBSOCKET_SYMBOL = /* @__PURE__ */ Symbol("WAIT_FOR_WEBSOCKET_SYMBOL");
|
|
48261
|
+
var upgradeWebSocket = defineWebSocketHelper(async (c, events, options) => {
|
|
48262
|
+
if (c.req.header("upgrade")?.toLowerCase() !== "websocket") return;
|
|
48263
|
+
const env = c.env;
|
|
48264
|
+
const waitForWebSocket = env[WAIT_FOR_WEBSOCKET_SYMBOL];
|
|
48265
|
+
if (!waitForWebSocket || !env.incoming) return new Response(null, { status: 500 });
|
|
48266
|
+
const connectionSymbol = generateConnectionSymbol();
|
|
48267
|
+
env[CONNECTION_SYMBOL_KEY] = connectionSymbol;
|
|
48268
|
+
(async () => {
|
|
48269
|
+
let ws;
|
|
48270
|
+
try {
|
|
48271
|
+
ws = await waitForWebSocket(env.incoming, connectionSymbol);
|
|
48272
|
+
} catch {
|
|
48273
|
+
return;
|
|
48274
|
+
}
|
|
48275
|
+
const messagesReceivedInStarting = [];
|
|
48276
|
+
const bufferMessage = /* @__PURE__ */ __name((data, isBinary) => {
|
|
48277
|
+
messagesReceivedInStarting.push([data, isBinary]);
|
|
48278
|
+
}, "bufferMessage");
|
|
48279
|
+
ws.on("message", bufferMessage);
|
|
48280
|
+
const ctx = {
|
|
48281
|
+
binaryType: "arraybuffer",
|
|
48282
|
+
close(code, reason) {
|
|
48283
|
+
ws.close(code, reason);
|
|
48284
|
+
},
|
|
48285
|
+
protocol: ws.protocol,
|
|
48286
|
+
raw: ws,
|
|
48287
|
+
get readyState() {
|
|
48288
|
+
return ws.readyState;
|
|
48289
|
+
},
|
|
48290
|
+
send(source, opts) {
|
|
48291
|
+
ws.send(source, { compress: opts?.compress });
|
|
48292
|
+
},
|
|
48293
|
+
url: new URL(c.req.url)
|
|
48294
|
+
};
|
|
48295
|
+
try {
|
|
48296
|
+
events?.onOpen?.(new Event("open"), ctx);
|
|
48297
|
+
} catch (e) {
|
|
48298
|
+
(options?.onError ?? console.error)(e);
|
|
48299
|
+
}
|
|
48300
|
+
const handleMessage = /* @__PURE__ */ __name((data, isBinary) => {
|
|
48301
|
+
const datas = Array.isArray(data) ? data : [data];
|
|
48302
|
+
for (const data2 of datas) try {
|
|
48303
|
+
events?.onMessage?.(new MessageEvent("message", { data: isBinary ? data2 instanceof ArrayBuffer ? data2 : data2.buffer.slice(data2.byteOffset, data2.byteOffset + data2.byteLength) : typeof data2 === "string" ? data2 : Buffer.from(data2).toString("utf-8") }), ctx);
|
|
48304
|
+
} catch (e) {
|
|
48305
|
+
(options?.onError ?? console.error)(e);
|
|
48306
|
+
}
|
|
48307
|
+
}, "handleMessage");
|
|
48308
|
+
ws.off("message", bufferMessage);
|
|
48309
|
+
for (const message of messagesReceivedInStarting) handleMessage(...message);
|
|
48310
|
+
ws.on("message", (data, isBinary) => {
|
|
48311
|
+
handleMessage(data, isBinary);
|
|
48312
|
+
});
|
|
48313
|
+
ws.on("close", (code, reason) => {
|
|
48314
|
+
try {
|
|
48315
|
+
events?.onClose?.(new CloseEvent("close", {
|
|
48316
|
+
code,
|
|
48317
|
+
reason: reason.toString()
|
|
48318
|
+
}), ctx);
|
|
48319
|
+
} catch (e) {
|
|
48320
|
+
(options?.onError ?? console.error)(e);
|
|
48321
|
+
}
|
|
48322
|
+
});
|
|
48323
|
+
ws.on("error", (error62) => {
|
|
48324
|
+
try {
|
|
48325
|
+
events?.onError?.(new ErrorEvent("error", { error: error62 }), ctx);
|
|
48326
|
+
} catch (e) {
|
|
48327
|
+
(options?.onError ?? console.error)(e);
|
|
48328
|
+
}
|
|
48329
|
+
});
|
|
48330
|
+
})();
|
|
48331
|
+
return new Response();
|
|
48332
|
+
});
|
|
48333
|
+
|
|
48334
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js
|
|
48335
|
+
var import_content_type = __toESM(require_content_type(), 1);
|
|
48336
|
+
function mediaTypeEssence(header) {
|
|
48337
|
+
if (!header) {
|
|
48338
|
+
return void 0;
|
|
48339
|
+
}
|
|
48340
|
+
try {
|
|
48341
|
+
return import_content_type.default.parse(header).type;
|
|
48342
|
+
} catch {
|
|
48343
|
+
const essence = (header.split(";", 1)[0] ?? "").trim().toLowerCase();
|
|
48344
|
+
if (essence === "" || header.slice(essence.length).includes(",")) {
|
|
48345
|
+
return void 0;
|
|
48346
|
+
}
|
|
48347
|
+
return essence;
|
|
48348
|
+
}
|
|
48349
|
+
}
|
|
48350
|
+
__name(mediaTypeEssence, "mediaTypeEssence");
|
|
48351
|
+
function isJsonContentType(header) {
|
|
48352
|
+
if (header === "application/json") {
|
|
48353
|
+
return true;
|
|
48354
|
+
}
|
|
48355
|
+
return mediaTypeEssence(header) === "application/json";
|
|
48356
|
+
}
|
|
48357
|
+
__name(isJsonContentType, "isJsonContentType");
|
|
48358
|
+
|
|
48359
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/requestBody.js
|
|
48360
|
+
var DEFAULT_MAX_REQUEST_BODY_SIZE = 4 * 1024 * 1024;
|
|
48361
|
+
var MAX_BATCH_SIZE = 100;
|
|
48362
|
+
function requestBodyTooLargeMessage(maxBytes) {
|
|
48363
|
+
return `Payload Too Large: Request body must not exceed ${maxBytes} bytes`;
|
|
48364
|
+
}
|
|
48365
|
+
__name(requestBodyTooLargeMessage, "requestBodyTooLargeMessage");
|
|
48366
|
+
function resolveMaxRequestBodySize(value) {
|
|
48367
|
+
if (value === void 0) {
|
|
48368
|
+
return DEFAULT_MAX_REQUEST_BODY_SIZE;
|
|
48369
|
+
}
|
|
48370
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
48371
|
+
throw new RangeError(`maxRequestBodySize must be a positive number of bytes, got ${String(value)}`);
|
|
48372
|
+
}
|
|
48373
|
+
return value;
|
|
48374
|
+
}
|
|
48375
|
+
__name(resolveMaxRequestBodySize, "resolveMaxRequestBodySize");
|
|
48376
|
+
async function readRequestBody(request, maxBytes = DEFAULT_MAX_REQUEST_BODY_SIZE) {
|
|
48377
|
+
if (Number(request.headers.get("content-length")) > maxBytes) {
|
|
48378
|
+
return { tooLarge: true };
|
|
48379
|
+
}
|
|
48380
|
+
if (request.body === null) {
|
|
48381
|
+
return { tooLarge: false, text: "" };
|
|
48382
|
+
}
|
|
48383
|
+
const reader = request.body.getReader();
|
|
48384
|
+
const decoder = new TextDecoder();
|
|
48385
|
+
let received = 0;
|
|
48386
|
+
let text2 = "";
|
|
48387
|
+
try {
|
|
48388
|
+
for (; ; ) {
|
|
48389
|
+
const { done, value } = await reader.read();
|
|
48390
|
+
if (done) {
|
|
48391
|
+
break;
|
|
48392
|
+
}
|
|
48393
|
+
received += value.byteLength;
|
|
48394
|
+
if (received > maxBytes) {
|
|
48395
|
+
return { tooLarge: true };
|
|
48396
|
+
}
|
|
48397
|
+
text2 += decoder.decode(value, { stream: true });
|
|
48398
|
+
}
|
|
48399
|
+
} finally {
|
|
48400
|
+
reader.releaseLock();
|
|
48401
|
+
}
|
|
48402
|
+
return { tooLarge: false, text: text2 + decoder.decode() };
|
|
48403
|
+
}
|
|
48404
|
+
__name(readRequestBody, "readRequestBody");
|
|
48405
|
+
|
|
48406
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.js
|
|
48407
|
+
var DEFAULT_SSE_KEEP_ALIVE_MS = 15e3;
|
|
48408
|
+
var MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
|
|
48409
|
+
function armSseKeepAlive(intervalMs, onTick) {
|
|
48410
|
+
if (!Number.isFinite(intervalMs) || intervalMs < 1) {
|
|
48411
|
+
return void 0;
|
|
48412
|
+
}
|
|
48413
|
+
const timer = setInterval(onTick, Math.min(intervalMs, MAX_TIMER_DELAY_MS));
|
|
48414
|
+
timer.unref?.();
|
|
48415
|
+
return timer;
|
|
48416
|
+
}
|
|
48417
|
+
__name(armSseKeepAlive, "armSseKeepAlive");
|
|
48418
|
+
|
|
48419
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js
|
|
48420
|
+
var WebStandardStreamableHTTPServerTransport = class {
|
|
48421
|
+
static {
|
|
48422
|
+
__name(this, "WebStandardStreamableHTTPServerTransport");
|
|
48423
|
+
}
|
|
48424
|
+
constructor(options = {}) {
|
|
48425
|
+
this._started = false;
|
|
48426
|
+
this._hasHandledRequest = false;
|
|
48427
|
+
this._streamMapping = /* @__PURE__ */ new Map();
|
|
48428
|
+
this._requestToStreamMapping = /* @__PURE__ */ new Map();
|
|
48429
|
+
this._resumableStreams = /* @__PURE__ */ new Set();
|
|
48430
|
+
this._requestResponseMap = /* @__PURE__ */ new Map();
|
|
48431
|
+
this._initialized = false;
|
|
48432
|
+
this._enableJsonResponse = false;
|
|
48433
|
+
this._standaloneSseStreamId = "_GET_stream";
|
|
48434
|
+
this._closed = false;
|
|
48435
|
+
this.sessionIdGenerator = options.sessionIdGenerator;
|
|
48436
|
+
this._enableJsonResponse = options.enableJsonResponse ?? false;
|
|
48437
|
+
this._eventStore = options.eventStore;
|
|
48438
|
+
this._onsessioninitialized = options.onsessioninitialized;
|
|
48439
|
+
this._onsessionclosed = options.onsessionclosed;
|
|
48440
|
+
this._allowedHosts = options.allowedHosts;
|
|
48441
|
+
this._allowedOrigins = options.allowedOrigins;
|
|
48442
|
+
this._enableDnsRebindingProtection = options.enableDnsRebindingProtection ?? false;
|
|
48443
|
+
this._retryInterval = options.retryInterval;
|
|
48444
|
+
this._keepAliveMs = options.keepAliveMs ?? DEFAULT_SSE_KEEP_ALIVE_MS;
|
|
48445
|
+
this._maxRequestBodySize = resolveMaxRequestBodySize(options.maxRequestBodySize);
|
|
48446
|
+
}
|
|
48447
|
+
/**
|
|
48448
|
+
* Arms a keep-alive interval for an SSE stream that periodically writes an SSE
|
|
48449
|
+
* comment frame so intermediaries and idle timeouts don't kill the connection.
|
|
48450
|
+
* The returned timer is owned by the stream it was armed for: the stream's
|
|
48451
|
+
* cancel/cleanup callbacks must clear it. The interval clears itself if a
|
|
48452
|
+
* write fails (stream already closed/cancelled).
|
|
48453
|
+
*/
|
|
48454
|
+
startKeepAlive(controller, encoder) {
|
|
48455
|
+
if (this._closed)
|
|
48456
|
+
return void 0;
|
|
48457
|
+
const timer = armSseKeepAlive(this._keepAliveMs, () => {
|
|
48458
|
+
try {
|
|
48459
|
+
controller.enqueue(encoder.encode(": keepalive\n\n"));
|
|
48460
|
+
} catch {
|
|
48461
|
+
if (timer !== void 0)
|
|
48462
|
+
clearInterval(timer);
|
|
48463
|
+
}
|
|
48464
|
+
});
|
|
48465
|
+
return timer;
|
|
48466
|
+
}
|
|
48467
|
+
/**
|
|
48468
|
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
|
48469
|
+
* for the Streamable HTTP transport as connections are managed per-request.
|
|
48470
|
+
*/
|
|
48471
|
+
async start() {
|
|
48472
|
+
if (this._started) {
|
|
48473
|
+
throw new Error("Transport already started");
|
|
48474
|
+
}
|
|
48475
|
+
this._started = true;
|
|
48476
|
+
}
|
|
48477
|
+
/**
|
|
48478
|
+
* Helper to create a JSON error response
|
|
48479
|
+
*/
|
|
48480
|
+
createJsonErrorResponse(status, code, message, options) {
|
|
48481
|
+
const error62 = { code, message };
|
|
48482
|
+
if (options?.data !== void 0) {
|
|
48483
|
+
error62.data = options.data;
|
|
48484
|
+
}
|
|
48485
|
+
return new Response(JSON.stringify({
|
|
48486
|
+
jsonrpc: "2.0",
|
|
48487
|
+
error: error62,
|
|
48488
|
+
id: null
|
|
48489
|
+
}), {
|
|
48490
|
+
status,
|
|
48491
|
+
headers: {
|
|
48492
|
+
"Content-Type": "application/json",
|
|
48493
|
+
...options?.headers
|
|
48494
|
+
}
|
|
48495
|
+
});
|
|
48496
|
+
}
|
|
48497
|
+
/**
|
|
48498
|
+
* Validates request headers for DNS rebinding protection.
|
|
48499
|
+
* @returns Error response if validation fails, undefined if validation passes.
|
|
48500
|
+
*/
|
|
48501
|
+
validateRequestHeaders(req) {
|
|
48502
|
+
if (!this._enableDnsRebindingProtection) {
|
|
48503
|
+
return void 0;
|
|
48504
|
+
}
|
|
48505
|
+
if (this._allowedHosts && this._allowedHosts.length > 0) {
|
|
48506
|
+
const hostHeader = req.headers.get("host");
|
|
48507
|
+
if (!hostHeader || !this._allowedHosts.includes(hostHeader)) {
|
|
48508
|
+
const error62 = `Invalid Host header: ${hostHeader}`;
|
|
48509
|
+
this.onerror?.(new Error(error62));
|
|
48510
|
+
return this.createJsonErrorResponse(403, -32e3, error62);
|
|
48511
|
+
}
|
|
48512
|
+
}
|
|
48513
|
+
if (this._allowedOrigins && this._allowedOrigins.length > 0) {
|
|
48514
|
+
const originHeader = req.headers.get("origin");
|
|
48515
|
+
if (originHeader && !this._allowedOrigins.includes(originHeader)) {
|
|
48516
|
+
const error62 = `Invalid Origin header: ${originHeader}`;
|
|
48517
|
+
this.onerror?.(new Error(error62));
|
|
48518
|
+
return this.createJsonErrorResponse(403, -32e3, error62);
|
|
48519
|
+
}
|
|
48520
|
+
}
|
|
48521
|
+
return void 0;
|
|
48522
|
+
}
|
|
48523
|
+
/**
|
|
48524
|
+
* Handles an incoming HTTP request, whether GET, POST, or DELETE
|
|
48525
|
+
* Returns a Response object (Web Standard)
|
|
48526
|
+
*/
|
|
48527
|
+
async handleRequest(req, options) {
|
|
48528
|
+
if (this._closed) {
|
|
48529
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
48530
|
+
}
|
|
48531
|
+
if (!this.sessionIdGenerator && this._hasHandledRequest) {
|
|
48532
|
+
throw new Error("Stateless transport cannot be reused across requests. Create a new transport per request.");
|
|
48533
|
+
}
|
|
48534
|
+
this._hasHandledRequest = true;
|
|
48535
|
+
const validationError = this.validateRequestHeaders(req);
|
|
48536
|
+
if (validationError) {
|
|
48537
|
+
return validationError;
|
|
48538
|
+
}
|
|
48539
|
+
switch (req.method) {
|
|
48540
|
+
case "POST":
|
|
48541
|
+
return this.handlePostRequest(req, options);
|
|
48542
|
+
case "GET":
|
|
48543
|
+
return this.handleGetRequest(req);
|
|
48544
|
+
case "DELETE":
|
|
48545
|
+
return this.handleDeleteRequest(req);
|
|
48546
|
+
default:
|
|
48547
|
+
return this.handleUnsupportedRequest();
|
|
48548
|
+
}
|
|
48549
|
+
}
|
|
48550
|
+
/**
|
|
48551
|
+
* Writes a priming event to establish resumption capability.
|
|
48552
|
+
* Only sends if eventStore is configured (opt-in for resumability) and
|
|
48553
|
+
* the client's protocol version supports empty SSE data (>= 2025-11-25).
|
|
48554
|
+
*/
|
|
48555
|
+
async writePrimingEvent(controller, encoder, streamId, protocolVersion) {
|
|
48556
|
+
if (!this._eventStore) {
|
|
48557
|
+
return;
|
|
48558
|
+
}
|
|
48559
|
+
if (protocolVersion < "2025-11-25") {
|
|
48560
|
+
return;
|
|
48561
|
+
}
|
|
48562
|
+
const primingEventId = await this._eventStore.storeEvent(streamId, {});
|
|
48563
|
+
let primingEvent = `id: ${primingEventId}
|
|
48564
|
+
data:
|
|
48565
|
+
|
|
48566
|
+
`;
|
|
48567
|
+
if (this._retryInterval !== void 0) {
|
|
48568
|
+
primingEvent = `id: ${primingEventId}
|
|
48569
|
+
retry: ${this._retryInterval}
|
|
48570
|
+
data:
|
|
48571
|
+
|
|
48572
|
+
`;
|
|
48573
|
+
}
|
|
48574
|
+
controller.enqueue(encoder.encode(primingEvent));
|
|
48575
|
+
this._resumableStreams.add(streamId);
|
|
48576
|
+
}
|
|
48577
|
+
/**
|
|
48578
|
+
* Handles GET requests for SSE stream
|
|
48579
|
+
*/
|
|
48580
|
+
async handleGetRequest(req) {
|
|
48581
|
+
const acceptHeader = req.headers.get("accept");
|
|
48582
|
+
if (!acceptHeader?.includes("text/event-stream")) {
|
|
48583
|
+
this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
|
|
48584
|
+
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
|
|
48585
|
+
}
|
|
48586
|
+
const sessionError = this.validateSession(req);
|
|
48587
|
+
if (sessionError) {
|
|
48588
|
+
return sessionError;
|
|
48589
|
+
}
|
|
48590
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
48591
|
+
if (protocolError) {
|
|
48592
|
+
return protocolError;
|
|
48593
|
+
}
|
|
48594
|
+
if (this._eventStore) {
|
|
48595
|
+
const lastEventId = req.headers.get("last-event-id");
|
|
48596
|
+
if (lastEventId) {
|
|
48597
|
+
return this.replayEvents(lastEventId);
|
|
48598
|
+
}
|
|
48599
|
+
}
|
|
48600
|
+
if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
|
|
48601
|
+
this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
|
|
48602
|
+
return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
|
|
48603
|
+
}
|
|
48604
|
+
const encoder = new TextEncoder();
|
|
48605
|
+
let streamController;
|
|
48606
|
+
let keepAliveTimer = void 0;
|
|
48607
|
+
const readable = new ReadableStream({
|
|
48608
|
+
start: /* @__PURE__ */ __name((controller) => {
|
|
48609
|
+
streamController = controller;
|
|
48610
|
+
}, "start"),
|
|
48611
|
+
cancel: /* @__PURE__ */ __name(() => {
|
|
48612
|
+
if (keepAliveTimer !== void 0) {
|
|
48613
|
+
clearInterval(keepAliveTimer);
|
|
48614
|
+
}
|
|
48615
|
+
if (this._streamMapping.get(this._standaloneSseStreamId)?.controller === streamController) {
|
|
48616
|
+
this._streamMapping.delete(this._standaloneSseStreamId);
|
|
48617
|
+
}
|
|
48618
|
+
}, "cancel")
|
|
48619
|
+
});
|
|
48620
|
+
const headers = {
|
|
48621
|
+
"Content-Type": "text/event-stream",
|
|
48622
|
+
"Cache-Control": "no-cache, no-transform",
|
|
48623
|
+
Connection: "keep-alive",
|
|
48624
|
+
"X-Accel-Buffering": "no"
|
|
48625
|
+
};
|
|
48626
|
+
if (this.sessionId !== void 0) {
|
|
48627
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
48628
|
+
}
|
|
48629
|
+
this._streamMapping.set(this._standaloneSseStreamId, {
|
|
48630
|
+
controller: streamController,
|
|
48631
|
+
encoder,
|
|
48632
|
+
cleanup: /* @__PURE__ */ __name(() => {
|
|
48633
|
+
if (keepAliveTimer !== void 0) {
|
|
48634
|
+
clearInterval(keepAliveTimer);
|
|
48635
|
+
}
|
|
48636
|
+
this._streamMapping.delete(this._standaloneSseStreamId);
|
|
48637
|
+
try {
|
|
48638
|
+
streamController.close();
|
|
48639
|
+
} catch {
|
|
48640
|
+
}
|
|
48641
|
+
}, "cleanup")
|
|
48642
|
+
});
|
|
48643
|
+
keepAliveTimer = this.startKeepAlive(streamController, encoder);
|
|
48644
|
+
return new Response(readable, { headers });
|
|
48645
|
+
}
|
|
48646
|
+
/**
|
|
48647
|
+
* Replays events that would have been sent after the specified event ID
|
|
48648
|
+
* Only used when resumability is enabled
|
|
48649
|
+
*/
|
|
48650
|
+
async replayEvents(lastEventId) {
|
|
48651
|
+
if (!this._eventStore) {
|
|
48652
|
+
this.onerror?.(new Error("Event store not configured"));
|
|
48653
|
+
return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
|
|
48654
|
+
}
|
|
48655
|
+
try {
|
|
48656
|
+
let streamId;
|
|
48657
|
+
if (this._eventStore.getStreamIdForEventId) {
|
|
48658
|
+
streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
|
|
48659
|
+
if (!streamId) {
|
|
48660
|
+
this.onerror?.(new Error("Invalid event ID format"));
|
|
48661
|
+
return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
|
|
48662
|
+
}
|
|
48663
|
+
if (this._streamMapping.get(streamId) !== void 0) {
|
|
48664
|
+
this.onerror?.(new Error("Conflict: Stream already has an active connection"));
|
|
48665
|
+
return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
|
|
48666
|
+
}
|
|
48667
|
+
}
|
|
48668
|
+
const headers = {
|
|
48669
|
+
"Content-Type": "text/event-stream",
|
|
48670
|
+
"Cache-Control": "no-cache, no-transform",
|
|
48671
|
+
Connection: "keep-alive",
|
|
48672
|
+
"X-Accel-Buffering": "no"
|
|
48673
|
+
};
|
|
48674
|
+
if (this.sessionId !== void 0) {
|
|
48675
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
48676
|
+
}
|
|
48677
|
+
const encoder = new TextEncoder();
|
|
48678
|
+
let streamController;
|
|
48679
|
+
let keepAliveTimer = void 0;
|
|
48680
|
+
let replayedStreamId = void 0;
|
|
48681
|
+
let cancelled = false;
|
|
48682
|
+
const readable = new ReadableStream({
|
|
48683
|
+
start: /* @__PURE__ */ __name((controller) => {
|
|
48684
|
+
streamController = controller;
|
|
48685
|
+
}, "start"),
|
|
48686
|
+
cancel: /* @__PURE__ */ __name(() => {
|
|
48687
|
+
cancelled = true;
|
|
48688
|
+
if (keepAliveTimer !== void 0) {
|
|
48689
|
+
clearInterval(keepAliveTimer);
|
|
48690
|
+
}
|
|
48691
|
+
if (replayedStreamId !== void 0 && this._streamMapping.get(replayedStreamId)?.controller === streamController) {
|
|
48692
|
+
this._streamMapping.delete(replayedStreamId);
|
|
48693
|
+
}
|
|
48694
|
+
}, "cancel")
|
|
48695
|
+
});
|
|
48696
|
+
const replayedEventIds = /* @__PURE__ */ new Set();
|
|
48697
|
+
replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, {
|
|
48698
|
+
send: /* @__PURE__ */ __name(async (eventId, message) => {
|
|
48699
|
+
const success2 = this.writeSSEEvent(streamController, encoder, message, eventId);
|
|
48700
|
+
if (!success2) {
|
|
48701
|
+
this.onerror?.(new Error("Failed replay events"));
|
|
48702
|
+
try {
|
|
48703
|
+
streamController.close();
|
|
48704
|
+
} catch {
|
|
48705
|
+
}
|
|
48706
|
+
} else {
|
|
48707
|
+
replayedEventIds.add(eventId);
|
|
48708
|
+
}
|
|
48709
|
+
}, "send")
|
|
48710
|
+
});
|
|
48711
|
+
if (this._closed || cancelled) {
|
|
48712
|
+
try {
|
|
48713
|
+
streamController.close();
|
|
48714
|
+
} catch {
|
|
48715
|
+
}
|
|
48716
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
48717
|
+
}
|
|
48718
|
+
this._streamMapping.get(replayedStreamId)?.cleanup();
|
|
48719
|
+
this._streamMapping.set(replayedStreamId, {
|
|
48720
|
+
controller: streamController,
|
|
48721
|
+
encoder,
|
|
48722
|
+
replayedEventIds,
|
|
48723
|
+
cleanup: /* @__PURE__ */ __name(() => {
|
|
48724
|
+
if (keepAliveTimer !== void 0) {
|
|
48725
|
+
clearInterval(keepAliveTimer);
|
|
48726
|
+
}
|
|
48727
|
+
this._streamMapping.delete(replayedStreamId);
|
|
48728
|
+
try {
|
|
48729
|
+
streamController.close();
|
|
48730
|
+
} catch {
|
|
48731
|
+
}
|
|
48732
|
+
}, "cleanup")
|
|
48733
|
+
});
|
|
48734
|
+
this._resumableStreams.add(replayedStreamId);
|
|
48735
|
+
keepAliveTimer = this.startKeepAlive(streamController, encoder);
|
|
48736
|
+
return new Response(readable, { headers });
|
|
48737
|
+
} catch (error62) {
|
|
48738
|
+
this.onerror?.(error62);
|
|
48739
|
+
return this.createJsonErrorResponse(500, -32e3, "Error replaying events");
|
|
48740
|
+
}
|
|
48741
|
+
}
|
|
48742
|
+
/**
|
|
48743
|
+
* Writes an event to an SSE stream via controller with proper formatting
|
|
48744
|
+
*/
|
|
48745
|
+
writeSSEEvent(controller, encoder, message, eventId) {
|
|
48746
|
+
try {
|
|
48747
|
+
let eventData = `event: message
|
|
48748
|
+
`;
|
|
48749
|
+
if (eventId) {
|
|
48750
|
+
eventData += `id: ${eventId}
|
|
48751
|
+
`;
|
|
48752
|
+
}
|
|
48753
|
+
eventData += `data: ${JSON.stringify(message)}
|
|
48754
|
+
|
|
48755
|
+
`;
|
|
48756
|
+
controller.enqueue(encoder.encode(eventData));
|
|
48757
|
+
return true;
|
|
48758
|
+
} catch (error62) {
|
|
48759
|
+
this.onerror?.(error62);
|
|
48760
|
+
return false;
|
|
48761
|
+
}
|
|
48762
|
+
}
|
|
48763
|
+
/**
|
|
48764
|
+
* Handles unsupported requests (PUT, PATCH, etc.)
|
|
48765
|
+
*/
|
|
48766
|
+
handleUnsupportedRequest() {
|
|
48767
|
+
this.onerror?.(new Error("Method not allowed."));
|
|
48768
|
+
return new Response(JSON.stringify({
|
|
48769
|
+
jsonrpc: "2.0",
|
|
48770
|
+
error: {
|
|
48771
|
+
code: -32e3,
|
|
48772
|
+
message: "Method not allowed."
|
|
48773
|
+
},
|
|
48774
|
+
id: null
|
|
48775
|
+
}), {
|
|
48776
|
+
status: 405,
|
|
48777
|
+
headers: {
|
|
48778
|
+
Allow: "GET, POST, DELETE",
|
|
48779
|
+
"Content-Type": "application/json"
|
|
48780
|
+
}
|
|
48781
|
+
});
|
|
48782
|
+
}
|
|
48783
|
+
/**
|
|
48784
|
+
* Handles POST requests containing JSON-RPC messages
|
|
48785
|
+
*/
|
|
48786
|
+
async handlePostRequest(req, options) {
|
|
48787
|
+
try {
|
|
48788
|
+
const acceptHeader = req.headers.get("accept");
|
|
48789
|
+
if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
|
|
48790
|
+
this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
|
|
48791
|
+
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
|
|
48792
|
+
}
|
|
48793
|
+
const ct = req.headers.get("content-type");
|
|
48794
|
+
if (!isJsonContentType(ct)) {
|
|
48795
|
+
this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
|
|
48796
|
+
return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
|
|
48797
|
+
}
|
|
48798
|
+
const requestInfo = {
|
|
48799
|
+
headers: Object.fromEntries(req.headers.entries()),
|
|
48800
|
+
url: new URL(req.url)
|
|
48801
|
+
};
|
|
48802
|
+
let rawMessage;
|
|
48803
|
+
if (options?.parsedBody !== void 0) {
|
|
48804
|
+
rawMessage = options.parsedBody;
|
|
48805
|
+
} else {
|
|
48806
|
+
try {
|
|
48807
|
+
const body = await readRequestBody(req, this._maxRequestBodySize);
|
|
48808
|
+
if (body.tooLarge) {
|
|
48809
|
+
const message = requestBodyTooLargeMessage(this._maxRequestBodySize);
|
|
48810
|
+
this.onerror?.(new Error(message));
|
|
48811
|
+
return this.createJsonErrorResponse(413, -32e3, message);
|
|
48812
|
+
}
|
|
48813
|
+
rawMessage = JSON.parse(body.text);
|
|
48814
|
+
} catch {
|
|
48815
|
+
this.onerror?.(new Error("Parse error: Invalid JSON"));
|
|
48816
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
|
|
48817
|
+
}
|
|
48818
|
+
}
|
|
48819
|
+
if (Array.isArray(rawMessage) && rawMessage.length > MAX_BATCH_SIZE) {
|
|
48820
|
+
this.onerror?.(new Error(`Invalid Request: Batch must not exceed ${MAX_BATCH_SIZE} messages`));
|
|
48821
|
+
return this.createJsonErrorResponse(400, -32600, `Invalid Request: Batch must not exceed ${MAX_BATCH_SIZE} messages`);
|
|
48822
|
+
}
|
|
48823
|
+
let messages;
|
|
48824
|
+
try {
|
|
48825
|
+
if (Array.isArray(rawMessage)) {
|
|
48826
|
+
messages = rawMessage.map((msg) => JSONRPCMessageSchema.parse(msg));
|
|
48827
|
+
} else {
|
|
48828
|
+
messages = [JSONRPCMessageSchema.parse(rawMessage)];
|
|
48829
|
+
}
|
|
48830
|
+
} catch {
|
|
48831
|
+
this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
|
|
48832
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
|
|
48833
|
+
}
|
|
48834
|
+
if (this._closed) {
|
|
48835
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
48836
|
+
}
|
|
48837
|
+
const isInitializationRequest = messages.some(isInitializeRequest);
|
|
48838
|
+
if (isInitializationRequest) {
|
|
48839
|
+
if (this._initialized && this.sessionId !== void 0) {
|
|
48840
|
+
this.onerror?.(new Error("Invalid Request: Server already initialized"));
|
|
48841
|
+
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
|
|
48842
|
+
}
|
|
48843
|
+
if (messages.length > 1) {
|
|
48844
|
+
this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
|
|
48845
|
+
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
|
|
48846
|
+
}
|
|
48847
|
+
this.sessionId = this.sessionIdGenerator?.();
|
|
48848
|
+
this._initialized = true;
|
|
48849
|
+
if (this.sessionId && this._onsessioninitialized) {
|
|
48850
|
+
await Promise.resolve(this._onsessioninitialized(this.sessionId));
|
|
48851
|
+
}
|
|
48852
|
+
}
|
|
48853
|
+
if (!isInitializationRequest) {
|
|
48854
|
+
const sessionError = this.validateSession(req);
|
|
48855
|
+
if (sessionError) {
|
|
48856
|
+
return sessionError;
|
|
48857
|
+
}
|
|
48858
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
48859
|
+
if (protocolError) {
|
|
48860
|
+
return protocolError;
|
|
48861
|
+
}
|
|
48862
|
+
}
|
|
48863
|
+
if (this._closed) {
|
|
48864
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
48865
|
+
}
|
|
48866
|
+
const hasRequests = messages.some(isJSONRPCRequest);
|
|
48867
|
+
if (!hasRequests) {
|
|
48868
|
+
for (const message of messages) {
|
|
48869
|
+
this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo });
|
|
48870
|
+
}
|
|
48871
|
+
return new Response(null, { status: 202 });
|
|
48872
|
+
}
|
|
48873
|
+
const streamId = crypto.randomUUID();
|
|
48874
|
+
const initRequest = messages.find((m) => isInitializeRequest(m));
|
|
48875
|
+
const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
|
|
48876
|
+
if (this._enableJsonResponse) {
|
|
48877
|
+
return new Promise((resolve) => {
|
|
48878
|
+
this._streamMapping.set(streamId, {
|
|
48879
|
+
resolveJson: resolve,
|
|
48880
|
+
cleanup: /* @__PURE__ */ __name(() => {
|
|
48881
|
+
this._streamMapping.delete(streamId);
|
|
48882
|
+
}, "cleanup")
|
|
48883
|
+
});
|
|
48884
|
+
for (const message of messages) {
|
|
48885
|
+
if (isJSONRPCRequest(message)) {
|
|
48886
|
+
this._requestToStreamMapping.set(message.id, streamId);
|
|
48887
|
+
}
|
|
48888
|
+
}
|
|
48889
|
+
for (const message of messages) {
|
|
48890
|
+
this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo });
|
|
48891
|
+
}
|
|
48892
|
+
});
|
|
48893
|
+
}
|
|
48894
|
+
const encoder = new TextEncoder();
|
|
48895
|
+
let streamController;
|
|
48896
|
+
let keepAliveTimer = void 0;
|
|
48897
|
+
const readable = new ReadableStream({
|
|
48898
|
+
start: /* @__PURE__ */ __name((controller) => {
|
|
48899
|
+
streamController = controller;
|
|
48900
|
+
}, "start"),
|
|
48901
|
+
cancel: /* @__PURE__ */ __name(() => {
|
|
48902
|
+
if (keepAliveTimer !== void 0) {
|
|
48903
|
+
clearInterval(keepAliveTimer);
|
|
48904
|
+
}
|
|
48905
|
+
if (this._streamMapping.get(streamId)?.controller === streamController) {
|
|
48906
|
+
this._streamMapping.delete(streamId);
|
|
48907
|
+
}
|
|
48908
|
+
}, "cancel")
|
|
48909
|
+
});
|
|
48910
|
+
const headers = {
|
|
48911
|
+
"Content-Type": "text/event-stream",
|
|
48912
|
+
"Cache-Control": "no-cache, no-transform",
|
|
48913
|
+
Connection: "keep-alive",
|
|
48914
|
+
"X-Accel-Buffering": "no"
|
|
48915
|
+
};
|
|
48916
|
+
if (this.sessionId !== void 0) {
|
|
48917
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
48918
|
+
}
|
|
48919
|
+
for (const message of messages) {
|
|
48920
|
+
if (isJSONRPCRequest(message)) {
|
|
48921
|
+
this._streamMapping.set(streamId, {
|
|
48922
|
+
controller: streamController,
|
|
48923
|
+
encoder,
|
|
48924
|
+
cleanup: /* @__PURE__ */ __name(() => {
|
|
48925
|
+
if (keepAliveTimer !== void 0) {
|
|
48926
|
+
clearInterval(keepAliveTimer);
|
|
48927
|
+
}
|
|
48928
|
+
this._streamMapping.delete(streamId);
|
|
48929
|
+
try {
|
|
48930
|
+
streamController.close();
|
|
48931
|
+
} catch {
|
|
48932
|
+
}
|
|
48933
|
+
}, "cleanup")
|
|
48934
|
+
});
|
|
48935
|
+
this._requestToStreamMapping.set(message.id, streamId);
|
|
48936
|
+
}
|
|
48937
|
+
}
|
|
48938
|
+
try {
|
|
48939
|
+
await this.writePrimingEvent(streamController, encoder, streamId, clientProtocolVersion);
|
|
48940
|
+
for (const message of messages) {
|
|
48941
|
+
let closeSSEStream;
|
|
48942
|
+
let closeStandaloneSSEStream;
|
|
48943
|
+
if (isJSONRPCRequest(message) && this._eventStore && clientProtocolVersion >= "2025-11-25") {
|
|
48944
|
+
closeSSEStream = /* @__PURE__ */ __name(() => {
|
|
48945
|
+
this.closeSSEStream(message.id);
|
|
48946
|
+
}, "closeSSEStream");
|
|
48947
|
+
closeStandaloneSSEStream = /* @__PURE__ */ __name(() => {
|
|
48948
|
+
this.closeStandaloneSSEStream();
|
|
48949
|
+
}, "closeStandaloneSSEStream");
|
|
48950
|
+
}
|
|
48951
|
+
this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo, closeSSEStream, closeStandaloneSSEStream });
|
|
48952
|
+
}
|
|
48953
|
+
} catch (error62) {
|
|
48954
|
+
this._streamMapping.get(streamId)?.cleanup();
|
|
48955
|
+
this._resumableStreams.delete(streamId);
|
|
48956
|
+
for (const message of messages) {
|
|
48957
|
+
if (isJSONRPCRequest(message)) {
|
|
48958
|
+
this._requestToStreamMapping.delete(message.id);
|
|
48959
|
+
}
|
|
48960
|
+
}
|
|
48961
|
+
throw error62;
|
|
48962
|
+
}
|
|
48963
|
+
if (this._streamMapping.get(streamId)?.controller === streamController) {
|
|
48964
|
+
keepAliveTimer = this.startKeepAlive(streamController, encoder);
|
|
48965
|
+
}
|
|
48966
|
+
return new Response(readable, { status: 200, headers });
|
|
48967
|
+
} catch (error62) {
|
|
48968
|
+
this.onerror?.(error62);
|
|
48969
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error", { data: String(error62) });
|
|
48970
|
+
}
|
|
48971
|
+
}
|
|
48972
|
+
/**
|
|
48973
|
+
* Handles DELETE requests to terminate sessions
|
|
48974
|
+
*/
|
|
48975
|
+
async handleDeleteRequest(req) {
|
|
48976
|
+
const sessionError = this.validateSession(req);
|
|
48977
|
+
if (sessionError) {
|
|
48978
|
+
return sessionError;
|
|
48979
|
+
}
|
|
48980
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
48981
|
+
if (protocolError) {
|
|
48982
|
+
return protocolError;
|
|
48983
|
+
}
|
|
48984
|
+
try {
|
|
48985
|
+
await Promise.resolve(this._onsessionclosed?.(this.sessionId));
|
|
48986
|
+
return new Response(null, { status: 200 });
|
|
48987
|
+
} finally {
|
|
48988
|
+
await this.close();
|
|
48989
|
+
}
|
|
48990
|
+
}
|
|
48991
|
+
/**
|
|
48992
|
+
* Validates session ID for non-initialization requests.
|
|
48993
|
+
* Returns Response error if invalid, undefined otherwise
|
|
48994
|
+
*/
|
|
48995
|
+
validateSession(req) {
|
|
48996
|
+
if (this.sessionIdGenerator === void 0) {
|
|
48997
|
+
return void 0;
|
|
48998
|
+
}
|
|
48999
|
+
if (!this._initialized) {
|
|
49000
|
+
this.onerror?.(new Error("Bad Request: Server not initialized"));
|
|
49001
|
+
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
|
|
49002
|
+
}
|
|
49003
|
+
const sessionId = req.headers.get("mcp-session-id");
|
|
49004
|
+
if (!sessionId) {
|
|
49005
|
+
this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
|
|
49006
|
+
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
|
|
49007
|
+
}
|
|
49008
|
+
if (sessionId !== this.sessionId) {
|
|
49009
|
+
this.onerror?.(new Error("Session not found"));
|
|
49010
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
49011
|
+
}
|
|
49012
|
+
return void 0;
|
|
49013
|
+
}
|
|
49014
|
+
/**
|
|
49015
|
+
* Validates the MCP-Protocol-Version header on incoming requests.
|
|
49016
|
+
*
|
|
49017
|
+
* For initialization: Version negotiation handles unknown versions gracefully
|
|
49018
|
+
* (server responds with its supported version).
|
|
49019
|
+
*
|
|
49020
|
+
* For subsequent requests with MCP-Protocol-Version header:
|
|
49021
|
+
* - Accept if in supported list
|
|
49022
|
+
* - 400 if unsupported
|
|
49023
|
+
*
|
|
49024
|
+
* For HTTP requests without the MCP-Protocol-Version header:
|
|
49025
|
+
* - Accept and default to the version negotiated at initialization
|
|
49026
|
+
*/
|
|
49027
|
+
validateProtocolVersion(req) {
|
|
49028
|
+
const protocolVersion = req.headers.get("mcp-protocol-version");
|
|
49029
|
+
if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
|
|
49030
|
+
this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
|
|
49031
|
+
return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
|
|
49032
|
+
}
|
|
49033
|
+
return void 0;
|
|
49034
|
+
}
|
|
49035
|
+
async close() {
|
|
49036
|
+
if (this._closed) {
|
|
49037
|
+
return;
|
|
49038
|
+
}
|
|
49039
|
+
this._closed = true;
|
|
49040
|
+
this._streamMapping.forEach(({ cleanup }) => {
|
|
49041
|
+
cleanup();
|
|
49042
|
+
});
|
|
49043
|
+
this._streamMapping.clear();
|
|
49044
|
+
this._requestResponseMap.clear();
|
|
49045
|
+
this._resumableStreams.clear();
|
|
49046
|
+
this.onclose?.();
|
|
49047
|
+
}
|
|
49048
|
+
/**
|
|
49049
|
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
|
49050
|
+
* Use this to implement polling behavior during long-running operations -
|
|
49051
|
+
* client will reconnect after the retry interval specified in the priming event.
|
|
49052
|
+
*/
|
|
49053
|
+
closeSSEStream(requestId) {
|
|
49054
|
+
const streamId = this._requestToStreamMapping.get(requestId);
|
|
49055
|
+
if (!streamId)
|
|
49056
|
+
return;
|
|
49057
|
+
const stream = this._streamMapping.get(streamId);
|
|
49058
|
+
if (stream) {
|
|
49059
|
+
stream.cleanup();
|
|
49060
|
+
}
|
|
49061
|
+
}
|
|
49062
|
+
/**
|
|
49063
|
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
|
49064
|
+
* Use this to implement polling behavior for server-initiated notifications.
|
|
49065
|
+
*/
|
|
49066
|
+
closeStandaloneSSEStream() {
|
|
49067
|
+
const stream = this._streamMapping.get(this._standaloneSseStreamId);
|
|
49068
|
+
if (stream) {
|
|
49069
|
+
stream.cleanup();
|
|
49070
|
+
}
|
|
49071
|
+
}
|
|
49072
|
+
async send(message, options) {
|
|
49073
|
+
let requestId = options?.relatedRequestId;
|
|
49074
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
49075
|
+
requestId = message.id;
|
|
49076
|
+
}
|
|
49077
|
+
if (requestId === void 0) {
|
|
49078
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
49079
|
+
throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
|
|
49080
|
+
}
|
|
49081
|
+
let eventId;
|
|
49082
|
+
if (this._eventStore) {
|
|
49083
|
+
eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message);
|
|
49084
|
+
}
|
|
49085
|
+
const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId);
|
|
49086
|
+
if (standaloneSse === void 0) {
|
|
49087
|
+
return;
|
|
49088
|
+
}
|
|
49089
|
+
if (standaloneSse.controller && standaloneSse.encoder && (eventId === void 0 || !standaloneSse.replayedEventIds?.has(eventId))) {
|
|
49090
|
+
this.writeSSEEvent(standaloneSse.controller, standaloneSse.encoder, message, eventId);
|
|
49091
|
+
}
|
|
49092
|
+
return;
|
|
49093
|
+
}
|
|
49094
|
+
const streamId = this._requestToStreamMapping.get(requestId);
|
|
49095
|
+
if (!streamId) {
|
|
49096
|
+
throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
|
49097
|
+
}
|
|
49098
|
+
let stream = this._streamMapping.get(streamId);
|
|
49099
|
+
if (!this._enableJsonResponse) {
|
|
49100
|
+
let eventId;
|
|
49101
|
+
if (this._eventStore) {
|
|
49102
|
+
eventId = await this._eventStore.storeEvent(streamId, message);
|
|
49103
|
+
stream = this._streamMapping.get(streamId);
|
|
49104
|
+
}
|
|
49105
|
+
if (stream?.controller && stream?.encoder && (eventId === void 0 || !stream.replayedEventIds?.has(eventId))) {
|
|
49106
|
+
const written = this.writeSSEEvent(stream.controller, stream.encoder, message, eventId);
|
|
49107
|
+
if (written && eventId !== void 0) {
|
|
49108
|
+
this._resumableStreams.add(streamId);
|
|
49109
|
+
}
|
|
49110
|
+
}
|
|
49111
|
+
}
|
|
49112
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
49113
|
+
this._requestResponseMap.set(requestId, message);
|
|
49114
|
+
const relatedIds = Array.from(this._requestToStreamMapping.entries()).filter(([_, sid]) => sid === streamId).map(([id]) => id);
|
|
49115
|
+
const allResponsesReady = relatedIds.every((id) => this._requestResponseMap.has(id));
|
|
49116
|
+
if (allResponsesReady) {
|
|
49117
|
+
if (!stream) {
|
|
49118
|
+
if (this._closed) {
|
|
49119
|
+
for (const id of relatedIds) {
|
|
49120
|
+
this._requestResponseMap.delete(id);
|
|
49121
|
+
this._requestToStreamMapping.delete(id);
|
|
49122
|
+
}
|
|
49123
|
+
return;
|
|
49124
|
+
}
|
|
49125
|
+
if (!this._enableJsonResponse && this._eventStore && this._resumableStreams.has(streamId)) {
|
|
49126
|
+
for (const id of relatedIds) {
|
|
49127
|
+
this._requestResponseMap.delete(id);
|
|
49128
|
+
this._requestToStreamMapping.delete(id);
|
|
49129
|
+
}
|
|
49130
|
+
this._resumableStreams.delete(streamId);
|
|
49131
|
+
return;
|
|
49132
|
+
}
|
|
49133
|
+
for (const id of relatedIds) {
|
|
49134
|
+
this._requestResponseMap.delete(id);
|
|
49135
|
+
this._requestToStreamMapping.delete(id);
|
|
49136
|
+
}
|
|
49137
|
+
throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
|
49138
|
+
}
|
|
49139
|
+
if (this._enableJsonResponse && stream.resolveJson) {
|
|
49140
|
+
const headers = {
|
|
49141
|
+
"Content-Type": "application/json"
|
|
49142
|
+
};
|
|
49143
|
+
if (this.sessionId !== void 0) {
|
|
49144
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
49145
|
+
}
|
|
49146
|
+
const responses = relatedIds.map((id) => this._requestResponseMap.get(id));
|
|
49147
|
+
if (responses.length === 1) {
|
|
49148
|
+
stream.resolveJson(new Response(JSON.stringify(responses[0]), { status: 200, headers }));
|
|
49149
|
+
} else {
|
|
49150
|
+
stream.resolveJson(new Response(JSON.stringify(responses), { status: 200, headers }));
|
|
49151
|
+
}
|
|
49152
|
+
} else {
|
|
49153
|
+
stream.cleanup();
|
|
49154
|
+
}
|
|
49155
|
+
for (const id of relatedIds) {
|
|
49156
|
+
this._requestResponseMap.delete(id);
|
|
49157
|
+
this._requestToStreamMapping.delete(id);
|
|
49158
|
+
}
|
|
49159
|
+
this._resumableStreams.delete(streamId);
|
|
49160
|
+
}
|
|
49161
|
+
}
|
|
49162
|
+
}
|
|
49163
|
+
};
|
|
49164
|
+
|
|
49165
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.js
|
|
49166
|
+
var StreamableHTTPServerTransport = class {
|
|
49167
|
+
static {
|
|
49168
|
+
__name(this, "StreamableHTTPServerTransport");
|
|
49169
|
+
}
|
|
49170
|
+
constructor(options = {}) {
|
|
49171
|
+
this._requestContext = /* @__PURE__ */ new WeakMap();
|
|
49172
|
+
this._webStandardTransport = new WebStandardStreamableHTTPServerTransport(options);
|
|
49173
|
+
this._requestListener = getRequestListener(async (webRequest) => {
|
|
49174
|
+
const context = this._requestContext.get(webRequest);
|
|
49175
|
+
return this._webStandardTransport.handleRequest(webRequest, {
|
|
49176
|
+
authInfo: context?.authInfo,
|
|
49177
|
+
parsedBody: context?.parsedBody
|
|
49178
|
+
});
|
|
49179
|
+
}, { overrideGlobalObjects: false });
|
|
49180
|
+
}
|
|
49181
|
+
/**
|
|
49182
|
+
* Gets the session ID for this transport instance.
|
|
49183
|
+
*/
|
|
49184
|
+
get sessionId() {
|
|
49185
|
+
return this._webStandardTransport.sessionId;
|
|
49186
|
+
}
|
|
49187
|
+
/**
|
|
49188
|
+
* Sets callback for when the transport is closed.
|
|
49189
|
+
*/
|
|
49190
|
+
set onclose(handler) {
|
|
49191
|
+
this._webStandardTransport.onclose = handler;
|
|
49192
|
+
}
|
|
49193
|
+
get onclose() {
|
|
49194
|
+
return this._webStandardTransport.onclose;
|
|
49195
|
+
}
|
|
49196
|
+
/**
|
|
49197
|
+
* Sets callback for transport errors.
|
|
49198
|
+
*/
|
|
49199
|
+
set onerror(handler) {
|
|
49200
|
+
this._webStandardTransport.onerror = handler;
|
|
49201
|
+
}
|
|
49202
|
+
get onerror() {
|
|
49203
|
+
return this._webStandardTransport.onerror;
|
|
49204
|
+
}
|
|
49205
|
+
/**
|
|
49206
|
+
* Sets callback for incoming messages.
|
|
49207
|
+
*/
|
|
49208
|
+
set onmessage(handler) {
|
|
49209
|
+
this._webStandardTransport.onmessage = handler;
|
|
49210
|
+
}
|
|
49211
|
+
get onmessage() {
|
|
49212
|
+
return this._webStandardTransport.onmessage;
|
|
49213
|
+
}
|
|
49214
|
+
/**
|
|
49215
|
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
|
49216
|
+
* for the Streamable HTTP transport as connections are managed per-request.
|
|
49217
|
+
*/
|
|
49218
|
+
async start() {
|
|
49219
|
+
return this._webStandardTransport.start();
|
|
49220
|
+
}
|
|
49221
|
+
/**
|
|
49222
|
+
* Closes the transport and all active connections.
|
|
49223
|
+
*/
|
|
49224
|
+
async close() {
|
|
49225
|
+
return this._webStandardTransport.close();
|
|
49226
|
+
}
|
|
49227
|
+
/**
|
|
49228
|
+
* Sends a JSON-RPC message through the transport.
|
|
49229
|
+
*/
|
|
49230
|
+
async send(message, options) {
|
|
49231
|
+
return this._webStandardTransport.send(message, options);
|
|
49232
|
+
}
|
|
49233
|
+
/**
|
|
49234
|
+
* Handles an incoming HTTP request, whether GET or POST.
|
|
49235
|
+
*
|
|
49236
|
+
* This method converts Node.js HTTP objects to Web Standard Request/Response
|
|
49237
|
+
* and delegates to the underlying WebStandardStreamableHTTPServerTransport.
|
|
49238
|
+
*
|
|
49239
|
+
* @param req - Node.js IncomingMessage, optionally with auth property from middleware
|
|
49240
|
+
* @param res - Node.js ServerResponse
|
|
49241
|
+
* @param parsedBody - Optional pre-parsed body from body-parser middleware
|
|
49242
|
+
*/
|
|
49243
|
+
async handleRequest(req, res, parsedBody) {
|
|
49244
|
+
const authInfo = req.auth;
|
|
49245
|
+
const handler = getRequestListener(async (webRequest) => {
|
|
49246
|
+
return this._webStandardTransport.handleRequest(webRequest, {
|
|
49247
|
+
authInfo,
|
|
49248
|
+
parsedBody
|
|
49249
|
+
});
|
|
49250
|
+
}, { overrideGlobalObjects: false });
|
|
49251
|
+
await handler(req, res);
|
|
49252
|
+
}
|
|
49253
|
+
/**
|
|
49254
|
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
|
49255
|
+
* Use this to implement polling behavior during long-running operations -
|
|
49256
|
+
* client will reconnect after the retry interval specified in the priming event.
|
|
49257
|
+
*/
|
|
49258
|
+
closeSSEStream(requestId) {
|
|
49259
|
+
this._webStandardTransport.closeSSEStream(requestId);
|
|
49260
|
+
}
|
|
49261
|
+
/**
|
|
49262
|
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
|
49263
|
+
* Use this to implement polling behavior for server-initiated notifications.
|
|
49264
|
+
*/
|
|
49265
|
+
closeStandaloneSSEStream() {
|
|
49266
|
+
this._webStandardTransport.closeStandaloneSSEStream();
|
|
49267
|
+
}
|
|
49268
|
+
};
|
|
49269
|
+
|
|
47006
49270
|
// src/tools/read.ts
|
|
47007
49271
|
init_library();
|
|
47008
49272
|
|
|
@@ -47133,7 +49397,10 @@ async function nowPlaying() {
|
|
|
47133
49397
|
if (r.state === "stopped") return r;
|
|
47134
49398
|
const np = obj(c, field2(z2, "NowPlaying"));
|
|
47135
49399
|
const tr = obj(c, field2(items(c, field2(np, "Tracks"))[0], "Track"));
|
|
47136
|
-
|
|
49400
|
+
const lines = off?.now_playing?.three_line;
|
|
49401
|
+
const t = String(field2(tr, "Title") ?? "").toLowerCase(), l1 = String(lines?.line1 ?? "").toLowerCase();
|
|
49402
|
+
const stream = !!l1 && !!t && !l1.includes(t) && !t.includes(l1);
|
|
49403
|
+
if (tr && field2(tr, "Title") && !stream) {
|
|
47137
49404
|
const al = obj(c, field2(tr, "Album"));
|
|
47138
49405
|
r.title = field2(tr, "Title");
|
|
47139
49406
|
r.artist = clean(field2(al, "PerformedBy"));
|
|
@@ -47143,7 +49410,6 @@ async function nowPlaying() {
|
|
|
47143
49410
|
const l = field2(tr, "LengthSeconds");
|
|
47144
49411
|
if (typeof l === "number") r.length = duration3(l);
|
|
47145
49412
|
} else {
|
|
47146
|
-
const lines = off?.now_playing?.three_line;
|
|
47147
49413
|
if (lines?.line1) {
|
|
47148
49414
|
r.title = lines.line1;
|
|
47149
49415
|
if (lines.line2) r.artist = lines.line2;
|
|
@@ -47154,7 +49420,7 @@ async function nowPlaying() {
|
|
|
47154
49420
|
const pos = field2(z2, "SeekPosition");
|
|
47155
49421
|
if (typeof pos === "number") r.position = duration3(pos);
|
|
47156
49422
|
const left = field2(obj(c, field2(z2, "Queue")), "TrackCountRemaining");
|
|
47157
|
-
if (typeof left === "number") r.tracks_left_in_queue = left;
|
|
49423
|
+
if (typeof left === "number" && !r.source) r.tracks_left_in_queue = left;
|
|
47158
49424
|
return r;
|
|
47159
49425
|
});
|
|
47160
49426
|
return { zones: out };
|
|
@@ -47602,6 +49868,14 @@ async function playTracks(keys, zoneName, how) {
|
|
|
47602
49868
|
__name(playTracks, "playTracks");
|
|
47603
49869
|
var BUTTONS = { pause: "Pause", play: "Play", playpause: "PlayPause", stop: "Stop", next: "Next", previous: "Previous" };
|
|
47604
49870
|
async function control2(zoneName, action) {
|
|
49871
|
+
if (action === "release") {
|
|
49872
|
+
return withCore(async (c) => {
|
|
49873
|
+
const z2 = findZone(c, zoneName);
|
|
49874
|
+
c.remoting.callMethodNoReply(z2.oid, formatMethodSignature("Zone", "Suspend", []), Buffer.alloc(0));
|
|
49875
|
+
log(`control: Suspend on ${z2.name}`);
|
|
49876
|
+
return { ok: true, zone: z2.name, action };
|
|
49877
|
+
});
|
|
49878
|
+
}
|
|
47605
49879
|
const m = BUTTONS[action];
|
|
47606
49880
|
if (!m) throw new RoonError(`Unknown action; choose from ${Object.keys(BUTTONS).join(", ")}`, "invalid");
|
|
47607
49881
|
const r = await withCore(async (c) => {
|
|
@@ -47864,10 +50138,10 @@ function registerControlTools(server, internal = true) {
|
|
|
47864
50138
|
}, ({ keys, zone: zn, mode: m }) => run(() => playTracks(keys, zn, m ?? "now")));
|
|
47865
50139
|
reg("roon_control", {
|
|
47866
50140
|
title: "Transport",
|
|
47867
|
-
description: "The buttons of a Roon zone: pause, play (resume), playpause, stop, next, previous. Only on an explicit request, never as a probe.",
|
|
47868
|
-
inputSchema: { zone, action: external_exports.enum(["pause", "play", "playpause", "stop", "next", "previous"]) },
|
|
50141
|
+
description: "The buttons of a Roon zone: pause, play (resume), playpause, stop, next, previous \u2014 and release: let go of the audio device right away (what Roon does by itself a few seconds after a pause), so another source can use the speaker. Only on an explicit request, never as a probe.",
|
|
50142
|
+
inputSchema: { zone, action: external_exports.enum(["pause", "play", "playpause", "stop", "next", "previous", "release"]) },
|
|
47869
50143
|
annotations: PLAYS
|
|
47870
|
-
}, ({ zone: zn, action }) => run(() => internal ? control2(zn, action) : control(zn, action)));
|
|
50144
|
+
}, ({ zone: zn, action }) => run(() => internal ? control2(zn, action) : action === "release" ? Promise.reject(new Error("release needs Roon's internal protocol (switched off)")) : control(zn, action)));
|
|
47871
50145
|
reg("roon_seek", {
|
|
47872
50146
|
title: "Seek",
|
|
47873
50147
|
description: "Jump to a position in the track that plays on a Roon zone, in seconds from the start. Only on an explicit request.",
|
|
@@ -49006,10 +51280,8 @@ var INSTRUCTIONS = `Deep Roon MCP connects to the user's own Roon Core (music pl
|
|
|
49006
51280
|
- What plays changes all the time: read roon_now_playing afresh before describing it.
|
|
49007
51281
|
- "Daily Mixes" are Roon's own (roon_mixes); the user's TIDAL mixes (My Mix 1 \u2026, My Daily Discovery) are roon_tidal_playlists with shelf my_mixes, and their tracks can be read with roon_playlist.
|
|
49008
51282
|
- Unofficial: this uses Roon's internal protocol, which a Roon update can change; if a tool says so, tell the user to check for an update.`;
|
|
49009
|
-
|
|
51283
|
+
function buildServer(internal, essentials) {
|
|
49010
51284
|
const server = new McpServer({ name: "deep-roon-mcp", title: "Deep Roon MCP", version: version2, websiteUrl: "https://github.com/renebouwmeester/deep-roon-mcp" }, { instructions: INSTRUCTIONS });
|
|
49011
|
-
const internal = !/^(off|false|0|no)$/i.test(process.env.DEEP_ROON_INTERNAL ?? "");
|
|
49012
|
-
const essentials = /^(essentials|true|1|yes)$/i.test(process.env.DEEP_ROON_TOOLS ?? process.env.DEEP_ROON_ESSENTIALS ?? "");
|
|
49013
51285
|
if (essentials) {
|
|
49014
51286
|
const keep = /* @__PURE__ */ new Set([
|
|
49015
51287
|
"roon_status",
|
|
@@ -49036,15 +51308,71 @@ async function main() {
|
|
|
49036
51308
|
registerStatusTool(server, internal);
|
|
49037
51309
|
registerReadTools(server, internal);
|
|
49038
51310
|
registerControlTools(server, internal);
|
|
49039
|
-
if (internal)
|
|
49040
|
-
|
|
49041
|
-
|
|
49042
|
-
|
|
51311
|
+
if (internal) registerLibraryTools(server);
|
|
51312
|
+
return server;
|
|
51313
|
+
}
|
|
51314
|
+
__name(buildServer, "buildServer");
|
|
51315
|
+
function serveHttp(spec, internal, essentials) {
|
|
51316
|
+
const m = /^(?:(.+):)?(\d+)$/.exec(spec.trim());
|
|
51317
|
+
if (!m) {
|
|
51318
|
+
log(`DEEP_ROON_HTTP should be [host:]port, not "${spec}"`);
|
|
51319
|
+
process.exit(1);
|
|
51320
|
+
}
|
|
51321
|
+
const host = m[1] || "127.0.0.1", port = Number(m[2]);
|
|
51322
|
+
const web = import_http.default.createServer(async (req, res) => {
|
|
51323
|
+
if (req.url?.split("?")[0] !== "/mcp") {
|
|
51324
|
+
res.writeHead(404).end();
|
|
51325
|
+
return;
|
|
51326
|
+
}
|
|
51327
|
+
if (req.method !== "POST") {
|
|
51328
|
+
res.writeHead(405, { allow: "POST" }).end();
|
|
51329
|
+
return;
|
|
51330
|
+
}
|
|
51331
|
+
const chunks = [];
|
|
51332
|
+
for await (const c of req) chunks.push(c);
|
|
51333
|
+
let body;
|
|
51334
|
+
try {
|
|
51335
|
+
body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
51336
|
+
} catch {
|
|
51337
|
+
res.writeHead(400).end("Parse error");
|
|
51338
|
+
return;
|
|
51339
|
+
}
|
|
51340
|
+
const server = buildServer(internal, essentials);
|
|
51341
|
+
const transport2 = new StreamableHTTPServerTransport({ sessionIdGenerator: void 0, enableJsonResponse: true });
|
|
51342
|
+
res.on("close", () => {
|
|
51343
|
+
transport2.close().catch(() => {
|
|
51344
|
+
});
|
|
51345
|
+
server.close().catch(() => {
|
|
51346
|
+
});
|
|
51347
|
+
});
|
|
51348
|
+
try {
|
|
51349
|
+
await server.connect(transport2);
|
|
51350
|
+
await transport2.handleRequest(req, res, body);
|
|
51351
|
+
} catch (e) {
|
|
51352
|
+
log(`http: ${e.message}`);
|
|
51353
|
+
if (!res.headersSent) res.writeHead(500).end();
|
|
51354
|
+
}
|
|
51355
|
+
});
|
|
51356
|
+
web.listen(port, host, () => log(`${version2} ready (http://${host}:${port}/mcp)`));
|
|
51357
|
+
}
|
|
51358
|
+
__name(serveHttp, "serveHttp");
|
|
51359
|
+
async function main() {
|
|
51360
|
+
const internal = !/^(off|false|0|no)$/i.test(process.env.DEEP_ROON_INTERNAL ?? "");
|
|
51361
|
+
const essentials = /^(essentials|true|1|yes)$/i.test(process.env.DEEP_ROON_TOOLS ?? process.env.DEEP_ROON_ESSENTIALS ?? "");
|
|
51362
|
+
if (internal) afterFirstConnect(() => selfTest(runSelfTest));
|
|
49043
51363
|
checkForUpdate().catch(() => {
|
|
49044
51364
|
});
|
|
49045
51365
|
log(`${internal ? "internal protocol on" : "internal protocol OFF \u2014 official API only"}${essentials ? ", essentials" : ""}`);
|
|
49046
|
-
|
|
49047
|
-
|
|
51366
|
+
const httpSpec = process.env.DEEP_ROON_HTTP;
|
|
51367
|
+
if (httpSpec) serveHttp(httpSpec, internal, essentials);
|
|
51368
|
+
else {
|
|
51369
|
+
await buildServer(internal, essentials).connect(new StdioServerTransport());
|
|
51370
|
+
log(`${version2} ready (stdio)`);
|
|
51371
|
+
process.stdin.on("close", () => {
|
|
51372
|
+
shutdown();
|
|
51373
|
+
process.exit(0);
|
|
51374
|
+
});
|
|
51375
|
+
}
|
|
49048
51376
|
findTarget().catch((e) => log(`no Roon Core yet: ${e.message}`));
|
|
49049
51377
|
const stop = /* @__PURE__ */ __name(() => {
|
|
49050
51378
|
shutdown();
|
|
@@ -49052,10 +51380,10 @@ async function main() {
|
|
|
49052
51380
|
}, "stop");
|
|
49053
51381
|
process.on("SIGINT", stop);
|
|
49054
51382
|
process.on("SIGTERM", stop);
|
|
49055
|
-
process.stdin.on("close", stop);
|
|
49056
51383
|
}
|
|
49057
51384
|
__name(main, "main");
|
|
49058
51385
|
main().catch((e) => {
|
|
49059
51386
|
log(`fatal: ${e.message}`);
|
|
49060
51387
|
process.exit(1);
|
|
49061
51388
|
});
|
|
51389
|
+
/*! For license information please see deep-roon-mcp.js.LEGAL.txt */
|