@tonyclaw/agent-inspector 3.0.18 → 3.0.19

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.
Files changed (97) hide show
  1. package/.output/cli.js +1255 -504
  2. package/.output/nitro.json +3 -3
  3. package/.output/public/assets/CompareDrawer-DR3WgrId.js +1 -0
  4. package/.output/public/assets/ProxyViewerContainer-B7PZaz5j.js +127 -0
  5. package/.output/public/assets/ReplayDialog-Bt9jgdvJ.js +1 -0
  6. package/.output/public/assets/RequestAnatomy-C-4630lw.js +1 -0
  7. package/.output/public/assets/ResponseView-f_JrN1iQ.js +3 -0
  8. package/.output/public/assets/StreamingChunkSequence-D8dBm1d8.js +1 -0
  9. package/.output/public/assets/_sessionId-CtoSDXDC.js +1 -0
  10. package/.output/public/assets/index-B-rVc2xu.js +12 -0
  11. package/.output/public/assets/index-B3YOj8-_.css +1 -0
  12. package/.output/public/assets/{index-ClQ7Vi3J.js → index-BNCySZM-.js} +1 -1
  13. package/.output/public/assets/index-BtCnkWve.js +1 -0
  14. package/.output/public/assets/json-viewer-DT6QQY81.js +1 -0
  15. package/.output/server/_chunks/ssr-renderer.mjs +18 -2
  16. package/.output/server/_libs/@radix-ui/react-dismissable-layer+[...].mjs +165 -31
  17. package/.output/server/_libs/@radix-ui/react-use-callback-ref+[...].mjs +1 -1
  18. package/.output/server/_libs/@radix-ui/react-use-controllable-state+[...].mjs +2 -2
  19. package/.output/server/_libs/@radix-ui/react-use-is-hydrated+[...].mjs +28 -1
  20. package/.output/server/_libs/mistralai__mistralai.mjs +1 -1
  21. package/.output/server/_libs/modelcontextprotocol__server.mjs +11571 -8127
  22. package/.output/server/_libs/radix-ui__primitive.mjs +1 -1
  23. package/.output/server/_libs/radix-ui__react-collapsible.mjs +1 -1
  24. package/.output/server/_libs/radix-ui__react-collection.mjs +8 -8
  25. package/.output/server/_libs/radix-ui__react-compose-refs.mjs +0 -1
  26. package/.output/server/_libs/radix-ui__react-context.mjs +4 -18
  27. package/.output/server/_libs/radix-ui__react-dialog.mjs +41 -88
  28. package/.output/server/_libs/radix-ui__react-focus-guards.mjs +15 -5
  29. package/.output/server/_libs/radix-ui__react-focus-scope.mjs +6 -2
  30. package/.output/server/_libs/radix-ui__react-id.mjs +3 -3
  31. package/.output/server/_libs/radix-ui__react-popper.mjs +62 -8
  32. package/.output/server/_libs/radix-ui__react-portal.mjs +2 -2
  33. package/.output/server/_libs/radix-ui__react-presence.mjs +50 -5
  34. package/.output/server/_libs/radix-ui__react-roving-focus.mjs +15 -4
  35. package/.output/server/_libs/radix-ui__react-scroll-area.mjs +30 -20
  36. package/.output/server/_libs/radix-ui__react-select.mjs +167 -123
  37. package/.output/server/_libs/radix-ui__react-slot.mjs +74 -41
  38. package/.output/server/_libs/radix-ui__react-tabs.mjs +6 -1
  39. package/.output/server/_libs/radix-ui__react-tooltip.mjs +6 -3
  40. package/.output/server/_libs/react-dom.mjs +13 -15
  41. package/.output/server/_libs/react.mjs +45 -45
  42. package/.output/server/_libs/srvx.mjs +409 -53
  43. package/.output/server/_libs/swr.mjs +10 -2
  44. package/.output/server/_libs/tailwind-merge.mjs +286 -41
  45. package/.output/server/_libs/tanstack__history.mjs +9 -13
  46. package/.output/server/_libs/tanstack__react-router.mjs +788 -1092
  47. package/.output/server/_libs/tanstack__react-store.mjs +1 -1
  48. package/.output/server/_libs/tanstack__react-virtual.mjs +82 -7
  49. package/.output/server/_libs/tanstack__router-core.mjs +1841 -2060
  50. package/.output/server/_libs/tanstack__virtual-core.mjs +116 -45
  51. package/.output/server/_libs/use-sync-external-store.mjs +1 -1
  52. package/.output/server/_libs/zod-to-json-schema.mjs +1 -1
  53. package/.output/server/_libs/zod.mjs +5085 -200
  54. package/.output/server/{_sessionId-Bi3ZIrqT.mjs → _sessionId-DbRqqzqz.mjs} +30 -32
  55. package/.output/server/_ssr/{CompareDrawer-BYZS_hCR.mjs → CompareDrawer-CVhUSZu1.mjs} +29 -31
  56. package/.output/server/_ssr/{ProxyViewerContainer-BE4umfVs.mjs → ProxyViewerContainer-BNnDYtc5.mjs} +54 -52
  57. package/.output/server/_ssr/{ReplayDialog-BlID2ZH4.mjs → ReplayDialog-DVkGajZU.mjs} +30 -32
  58. package/.output/server/_ssr/{RequestAnatomy-CGJ2lkzT.mjs → RequestAnatomy-_FIfVjDR.mjs} +29 -31
  59. package/.output/server/_ssr/{ResponseView-DDjcGf7M.mjs → ResponseView-Bnv5ejVA.mjs} +29 -31
  60. package/.output/server/_ssr/{StreamingChunkSequence-G7B8M5G2.mjs → StreamingChunkSequence-vtwzxw7A.mjs} +29 -31
  61. package/.output/server/_ssr/empty-plugin-adapters-BFgPZ6_d.mjs +6 -0
  62. package/.output/server/_ssr/{index-ClQ9FvRJ.mjs → index-DFJbRoyq.mjs} +31 -33
  63. package/.output/server/_ssr/index.mjs +1102 -784
  64. package/.output/server/_ssr/{json-viewer-CFbpkiBJ.mjs → json-viewer-BkweASh3.mjs} +29 -31
  65. package/.output/server/_ssr/{router-Cq8LEvhE.mjs → router-gFd3g7WM.mjs} +10 -7
  66. package/.output/server/_tanstack-start-manifest_v-DeLutIlq.mjs +4 -0
  67. package/.output/server/index.mjs +81 -99
  68. package/package.json +17 -8
  69. package/src/components/clients/ClientLogo.tsx +5 -1
  70. package/src/components/proxy-viewer/RequestToolsPanel.tsx +1 -0
  71. package/src/components/proxy-viewer/ResponseView.tsx +1 -0
  72. package/src/components/proxy-viewer/StreamingChunkSequence.tsx +1 -0
  73. package/src/components/proxy-viewer/TurnGroup.tsx +1 -0
  74. package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +1 -0
  75. package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +4 -0
  76. package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +1 -0
  77. package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +2 -0
  78. package/src/components/ui/dialog.tsx +1 -1
  79. package/src/components/ui/json-viewer.tsx +2 -0
  80. package/src/components/ui/select.tsx +1 -1
  81. package/src/router.tsx +9 -0
  82. package/.output/public/assets/CompareDrawer-Daj03-RL.js +0 -1
  83. package/.output/public/assets/ProxyViewerContainer-BLCRQtU_.js +0 -106
  84. package/.output/public/assets/ReplayDialog-5FR5crdo.js +0 -1
  85. package/.output/public/assets/RequestAnatomy-DF0hHdQY.js +0 -1
  86. package/.output/public/assets/ResponseView-BwkMSsUa.js +0 -3
  87. package/.output/public/assets/StreamingChunkSequence-CKeUd58x.js +0 -1
  88. package/.output/public/assets/_sessionId-CThgXa41.js +0 -1
  89. package/.output/public/assets/index-BHXN1Fsx.css +0 -1
  90. package/.output/public/assets/index-gm3A0idN.js +0 -1
  91. package/.output/public/assets/json-viewer-BA-W-PZq.js +0 -1
  92. package/.output/public/assets/main-BnRC1932.js +0 -18
  93. package/.output/server/_libs/@radix-ui/react-use-escape-keydown+[...].mjs +0 -17
  94. package/.output/server/_libs/cfworker__json-schema.mjs +0 -1
  95. package/.output/server/_libs/tiny-invariant.mjs +0 -12
  96. package/.output/server/_libs/tiny-warning.mjs +0 -5
  97. package/.output/server/_tanstack-start-manifest_v-p7J0QCMh.mjs +0 -4
@@ -3,7 +3,7 @@ import { Readable, PassThrough } from "node:stream";
3
3
  import { pipeline } from "node:stream/promises";
4
4
  import nodeHTTPS from "node:https";
5
5
  import nodeHTTP2 from "node:http2";
6
- function lazyInherit$1(target, source, sourceKey) {
6
+ function lazyInherit$2(target, source, sourceKey) {
7
7
  for (const key of [...Object.getOwnPropertyNames(source), ...Object.getOwnPropertySymbols(source)]) {
8
8
  if (key === "constructor") continue;
9
9
  const targetDesc = Object.getOwnPropertyDescriptor(target, key);
@@ -30,8 +30,9 @@ function lazyInherit$1(target, source, sourceKey) {
30
30
  if (modified) Object.defineProperty(target, key, desc);
31
31
  }
32
32
  }
33
- const _needsNormRE$1 = /(?:(?:^|\/)(?:\.|\.\.|%2e|%2e\.|\.%2e|%2e%2e)(?:\/|$))|[\\^\x80-\uffff]/i;
34
- const FastURL$1 = /* @__PURE__ */ (() => {
33
+ const _needsNormRE$2 = /(?:(?:^|\/)(?:\.|\.\.|%2e|%2e\.|\.%2e|%2e%2e)(?:\/|$))|[\\^#"<>{}`\x80-\uffff]/i;
34
+ const _searchNeedsNormRE = /[#"'<>]/;
35
+ const FastURL$2 = /* @__PURE__ */ (() => {
35
36
  const NativeURL = globalThis.URL;
36
37
  const FastURL2 = class URL {
37
38
  #url;
@@ -43,9 +44,11 @@ const FastURL$1 = /* @__PURE__ */ (() => {
43
44
  #searchParams;
44
45
  #pos;
45
46
  constructor(url) {
46
- if (typeof url === "string") if (url[0] === "/") this.#href = url;
47
- else this.#url = new NativeURL(url);
48
- else if (_needsNormRE$1.test(url.pathname)) this.#url = new NativeURL(`${url.protocol || "http:"}//${url.host || "localhost"}${url.pathname}${url.search || ""}`);
47
+ if (typeof url === "string") {
48
+ const isOriginForm = url[0] === "/";
49
+ if (isOriginForm && !_searchNeedsNormRE.test(url)) this.#href = url;
50
+ else this.#url = new NativeURL(isOriginForm ? `http://localhost${url}` : url);
51
+ } else if (_needsNormRE$2.test(url.pathname) || url.search && _searchNeedsNormRE.test(url.search)) this.#url = new NativeURL(`${url.protocol || "http:"}//${url.host || "localhost"}${url.pathname}${url.search || ""}`);
49
52
  else {
50
53
  this.#protocol = url.protocol;
51
54
  this.#host = url.host;
@@ -128,7 +131,7 @@ const FastURL$1 = /* @__PURE__ */ (() => {
128
131
  return this.href;
129
132
  }
130
133
  };
131
- lazyInherit$1(FastURL2.prototype, NativeURL.prototype, "_url");
134
+ lazyInherit$2(FastURL2.prototype, NativeURL.prototype, "_url");
132
135
  Object.setPrototypeOf(FastURL2.prototype, NativeURL.prototype);
133
136
  Object.setPrototypeOf(FastURL2, NativeURL);
134
137
  return FastURL2;
@@ -267,10 +270,56 @@ const gracefulShutdownPlugin = (server) => {
267
270
  };
268
271
  for (const sig of ["SIGINT", "SIGTERM"]) globalThis.process.on(sig, shutdown);
269
272
  };
270
- async function sendNodeResponse(nodeRes, webRes) {
273
+ function createBodyTooLargeError(maxRequestBodySize) {
274
+ return Object.assign(/* @__PURE__ */ new Error(`Request body exceeds the maximum allowed size of ${maxRequestBodySize} bytes.`), {
275
+ code: "ERR_BODY_TOO_LARGE",
276
+ statusCode: 413,
277
+ status: 413
278
+ });
279
+ }
280
+ function limitBodyStream(stream, maxRequestBodySize) {
281
+ const reader = stream.getReader();
282
+ let size = 0;
283
+ return new ReadableStream({
284
+ async pull(controller) {
285
+ const { done, value } = await reader.read();
286
+ if (done) {
287
+ controller.close();
288
+ return;
289
+ }
290
+ size += value.byteLength;
291
+ if (size > maxRequestBodySize) {
292
+ const error = createBodyTooLargeError(maxRequestBodySize);
293
+ reader.cancel(error).catch(() => {
294
+ });
295
+ controller.error(error);
296
+ return;
297
+ }
298
+ controller.enqueue(value);
299
+ },
300
+ cancel(reason) {
301
+ return reader.cancel(reason);
302
+ }
303
+ });
304
+ }
305
+ function sendNodeResponseDetached(nodeRes, webRes) {
306
+ try {
307
+ return _sendNodeResponse(nodeRes, webRes, true);
308
+ } catch (error) {
309
+ handleSendError(nodeRes);
310
+ }
311
+ }
312
+ function handleSendError(nodeRes, _error) {
313
+ if (nodeRes.headersSent) nodeRes.destroy();
314
+ else {
315
+ nodeRes.statusCode = 500;
316
+ nodeRes.end();
317
+ }
318
+ }
319
+ function _sendNodeResponse(nodeRes, webRes, detached) {
271
320
  if (!webRes) {
272
321
  nodeRes.statusCode = 500;
273
- return endNodeResponse(nodeRes);
322
+ return endNodeResponse(nodeRes, detached);
274
323
  }
275
324
  if (webRes._toNodeResponse) {
276
325
  const res = webRes._toNodeResponse();
@@ -282,18 +331,22 @@ async function sendNodeResponse(nodeRes, webRes) {
282
331
  writeHead(nodeRes, res.status, res.statusText, res.headers);
283
332
  nodeRes.write(res.body);
284
333
  } else writeHead(nodeRes, res.status, res.statusText, res.headers);
285
- return endNodeResponse(nodeRes);
334
+ return endNodeResponse(nodeRes, detached);
286
335
  }
287
- const rawHeaders = [...webRes.headers];
336
+ const rawHeaders = [];
337
+ for (const [key, value] of webRes.headers) rawHeaders.push(key, value);
288
338
  writeHead(nodeRes, webRes.status, webRes.statusText, rawHeaders);
289
- return webRes.body ? streamBody(webRes.body, nodeRes) : endNodeResponse(nodeRes);
339
+ return webRes.body ? streamBody(webRes.body, nodeRes) : endNodeResponse(nodeRes, detached);
290
340
  }
291
341
  function writeHead(nodeRes, status, statusText, rawHeaders) {
292
- const writeHeaders = rawHeaders.flat();
293
- if (!nodeRes.headersSent) if (nodeRes.req?.httpVersion === "2.0") nodeRes.writeHead(status, writeHeaders);
294
- else nodeRes.writeHead(status, statusText, writeHeaders);
342
+ if (!nodeRes.headersSent) if (nodeRes.req?.httpVersion === "2.0") nodeRes.writeHead(status, rawHeaders);
343
+ else nodeRes.writeHead(status, statusText, rawHeaders);
295
344
  }
296
- function endNodeResponse(nodeRes) {
345
+ function endNodeResponse(nodeRes, detached) {
346
+ if (detached) {
347
+ nodeRes.end();
348
+ return;
349
+ }
297
350
  return new Promise((resolve) => nodeRes.end(resolve));
298
351
  }
299
352
  function pipeBody(stream, nodeRes, status, statusText, headers) {
@@ -360,8 +413,7 @@ function streamBody(stream, nodeRes) {
360
413
  });
361
414
  }
362
415
  const HOST_RE = /^(\[(?:[A-Fa-f0-9:.]+)\]|(?:[A-Za-z0-9_-]+\.)*[A-Za-z0-9_-]+|(?:\d{1,3}\.){3}\d{1,3})(:\d{1,5})?$/;
363
- var NodeRequestURL = class extends FastURL$1 {
364
- #req;
416
+ var NodeRequestURL = class extends FastURL$2 {
365
417
  constructor({ req }) {
366
418
  const path = req.url || "/";
367
419
  let host = req.headers.host || req.headers[":authority"];
@@ -384,16 +436,40 @@ var NodeRequestURL = class extends FastURL$1 {
384
436
  search: ""
385
437
  });
386
438
  else super(path);
387
- this.#req = req;
388
- }
389
- get pathname() {
390
- return super.pathname;
391
- }
392
- set pathname(value) {
393
- this._url.pathname = value;
394
- this.#req.url = this._url.pathname + this._url.search;
395
439
  }
396
440
  };
441
+ const _nonJoinedHeaders = /* @__PURE__ */ new Set([
442
+ "age",
443
+ "authorization",
444
+ "content-length",
445
+ "content-type",
446
+ "etag",
447
+ "expires",
448
+ "from",
449
+ "host",
450
+ "if-modified-since",
451
+ "if-unmodified-since",
452
+ "last-modified",
453
+ "location",
454
+ "max-forwards",
455
+ "proxy-authorization",
456
+ "referer",
457
+ "retry-after",
458
+ "server",
459
+ "user-agent"
460
+ ]);
461
+ const _validHeaderNameRE = /^[!#$%&'*+\-.^_`|~\dA-Za-z]+$/;
462
+ function _isRepeated(rawHeaders, lowerName) {
463
+ let seen = false;
464
+ for (let i = 0; i < rawHeaders.length; i += 2) {
465
+ const key = rawHeaders[i];
466
+ if (key.length === lowerName.length && key.toLowerCase() === lowerName) {
467
+ if (seen) return true;
468
+ seen = true;
469
+ }
470
+ }
471
+ return false;
472
+ }
397
473
  const NodeRequestHeaders = /* @__PURE__ */ (() => {
398
474
  const NativeHeaders = globalThis.Headers;
399
475
  class Headers2 {
@@ -422,17 +498,24 @@ const NodeRequestHeaders = /* @__PURE__ */ (() => {
422
498
  }
423
499
  get(name) {
424
500
  if (this.#headers) return this.#headers.get(name);
425
- const value = this.#req.headers[name.toLowerCase()];
426
- return Array.isArray(value) ? value.join(", ") : value || null;
501
+ const lower = name.toLowerCase();
502
+ if (lower.charCodeAt(0) === 58) return this._headers.get(name);
503
+ const value = this.#req.headers[lower];
504
+ if (typeof value === "string") return _nonJoinedHeaders.has(lower) && _isRepeated(this.#req.rawHeaders, lower) ? this._headers.get(name) : value;
505
+ if (Array.isArray(value)) return value.join(", ");
506
+ return lower !== "__proto__" && _validHeaderNameRE.test(name) ? null : this._headers.get(name);
427
507
  }
428
508
  has(name) {
429
509
  if (this.#headers) return this.#headers.has(name);
430
- return name.toLowerCase() in this.#req.headers;
510
+ const lower = name.toLowerCase();
511
+ if (lower.charCodeAt(0) === 58) return this._headers.has(name);
512
+ if (Object.hasOwn(this.#req.headers, lower)) return true;
513
+ return lower !== "__proto__" && _validHeaderNameRE.test(name) ? false : this._headers.has(name);
431
514
  }
432
515
  getSetCookie() {
433
516
  if (this.#headers) return this.#headers.getSetCookie();
434
517
  const value = this.#req.headers["set-cookie"];
435
- return Array.isArray(value) ? value : value ? [value] : [];
518
+ return Array.isArray(value) ? value.slice() : value ? [value] : [];
436
519
  }
437
520
  entries() {
438
521
  return this._headers.entries();
@@ -441,23 +524,27 @@ const NodeRequestHeaders = /* @__PURE__ */ (() => {
441
524
  return this.entries();
442
525
  }
443
526
  }
444
- lazyInherit$1(Headers2.prototype, NativeHeaders.prototype, "_headers");
527
+ lazyInherit$2(Headers2.prototype, NativeHeaders.prototype, "_headers");
445
528
  Object.setPrototypeOf(Headers2, NativeHeaders);
446
529
  Object.setPrototypeOf(Headers2.prototype, NativeHeaders.prototype);
447
530
  return Headers2;
448
531
  })();
532
+ const kNativeRequest = /* @__PURE__ */ Symbol.for("srvx.nativeRequest");
449
533
  const NodeRequest = /* @__PURE__ */ (() => {
450
- const NativeRequest = globalThis.Request;
534
+ const NativeRequest = getNativeRequest();
451
535
  class Request {
452
536
  runtime;
537
+ waitUntil;
453
538
  #req;
454
539
  #url;
455
540
  #bodyStream;
456
541
  #request;
457
542
  #headers;
458
543
  #abortController;
544
+ #maxRequestBodySize;
459
545
  constructor(ctx) {
460
546
  this.#req = ctx.req;
547
+ this.#maxRequestBodySize = ctx.maxRequestBodySize;
461
548
  this.runtime = {
462
549
  name: "node",
463
550
  node: ctx
@@ -511,19 +598,24 @@ const NodeRequest = /* @__PURE__ */ (() => {
511
598
  if (this.#request) return this.#request.body;
512
599
  if (this.#bodyStream === void 0) {
513
600
  const method = this.method;
514
- const hasBody = !(method === "GET" || method === "HEAD");
515
- this.#bodyStream = hasBody ? Readable.toWeb(this.#req) : null;
601
+ let stream = !(method === "GET" || method === "HEAD") ? Readable.toWeb(this.#req) : null;
602
+ if (stream && this.#maxRequestBodySize !== void 0) stream = limitBodyStream(stream, this.#maxRequestBodySize);
603
+ this.#bodyStream = stream;
516
604
  }
517
605
  return this.#bodyStream;
518
606
  }
607
+ #readBuffered() {
608
+ return readBody(this.#req, this.#maxRequestBodySize);
609
+ }
519
610
  text() {
520
611
  if (this.#request) return this.#request.text();
521
612
  if (this.#bodyStream !== void 0) return this.#bodyStream ? new Response(this.#bodyStream).text() : Promise.resolve("");
522
- return readBody(this.#req).then((buf) => buf.toString());
613
+ return this.#readBuffered().then((buf) => buf.toString());
523
614
  }
524
615
  json() {
525
616
  if (this.#request) return this.#request.json();
526
- return this.text().then((text) => JSON.parse(text));
617
+ if (this.#bodyStream !== void 0) return this.text().then((text) => JSON.parse(text));
618
+ return this.#readBuffered().then((buf) => JSON.parse(buf.toString()));
527
619
  }
528
620
  get _request() {
529
621
  if (!this.#request) {
@@ -541,29 +633,52 @@ const NodeRequest = /* @__PURE__ */ (() => {
541
633
  return this.#request;
542
634
  }
543
635
  }
544
- lazyInherit$1(Request.prototype, NativeRequest.prototype, "_request");
636
+ lazyInherit$2(Request.prototype, NativeRequest.prototype, "_request");
545
637
  Object.setPrototypeOf(Request.prototype, NativeRequest.prototype);
546
638
  return Request;
547
639
  })();
548
- function readBody(req) {
549
- if ("rawBody" in req && Buffer.isBuffer(req.rawBody)) return Promise.resolve(req.rawBody);
640
+ function readBody(req, maxRequestBodySize) {
641
+ if ("rawBody" in req && Buffer.isBuffer(req.rawBody)) {
642
+ if (maxRequestBodySize !== void 0 && req.rawBody.length > maxRequestBodySize) return Promise.reject(createBodyTooLargeError(maxRequestBodySize));
643
+ return Promise.resolve(req.rawBody);
644
+ }
550
645
  return new Promise((resolve, reject) => {
551
646
  const chunks = [];
647
+ let size = 0;
648
+ const cleanup = () => {
649
+ req.off("data", onData);
650
+ req.off("end", onEnd);
651
+ req.off("error", onError);
652
+ };
552
653
  const onData = (chunk) => {
654
+ if (maxRequestBodySize !== void 0) {
655
+ size += chunk.length;
656
+ if (size > maxRequestBodySize) {
657
+ cleanup();
658
+ req.pause?.();
659
+ reject(createBodyTooLargeError(maxRequestBodySize));
660
+ return;
661
+ }
662
+ }
553
663
  chunks.push(chunk);
554
664
  };
555
665
  const onError = (err) => {
666
+ cleanup();
556
667
  reject(err);
557
668
  };
558
669
  const onEnd = () => {
559
- req.off("error", onError);
560
- req.off("data", onData);
561
- resolve(Buffer.concat(chunks));
670
+ cleanup();
671
+ resolve(chunks.length === 1 ? chunks[0] : Buffer.concat(chunks));
562
672
  };
563
673
  req.on("data", onData).once("end", onEnd).once("error", onError);
564
674
  });
565
675
  }
566
- const NodeResponse$1 = /* @__PURE__ */ (() => {
676
+ function getNativeRequest() {
677
+ let R = globalThis[kNativeRequest] || globalThis.Request;
678
+ while (R?._srvx) R = Object.getPrototypeOf(R);
679
+ return globalThis[kNativeRequest] ??= R;
680
+ }
681
+ const NodeResponse$2 = /* @__PURE__ */ (() => {
567
682
  const NativeResponse = globalThis.Response;
568
683
  const STATUS_CODES = globalThis.process?.getBuiltinModule?.("node:http")?.STATUS_CODES || {};
569
684
  class NodeResponse2 {
@@ -643,17 +758,18 @@ const NodeResponse$1 = /* @__PURE__ */ (() => {
643
758
  else body = this._response.body;
644
759
  const headers = [];
645
760
  const initHeaders = this.#init?.headers;
646
- const headerEntries = this.#response?.headers || this.#headers || (initHeaders ? Array.isArray(initHeaders) ? initHeaders : initHeaders?.entries ? initHeaders.entries() : Object.entries(initHeaders).map(([k, v]) => [k.toLowerCase(), v]) : void 0);
761
+ const headerEntries = this.#response?.headers || this.#headers || (initHeaders ? Array.isArray(initHeaders) ? initHeaders : initHeaders?.entries ? initHeaders.entries() : Object.entries(initHeaders) : void 0);
647
762
  let hasContentTypeHeader;
648
763
  let hasContentLength;
649
764
  if (headerEntries) for (const [key, value] of headerEntries) {
650
- if (Array.isArray(value)) for (const v of value) headers.push([key, v]);
651
- else headers.push([key, value]);
652
- if (key === "content-type") hasContentTypeHeader = true;
653
- else if (key === "content-length") hasContentLength = true;
765
+ const lowerKey = typeof key === "string" ? key.toLowerCase() : String(key);
766
+ if (Array.isArray(value)) for (const v of value) headers.push(lowerKey, v);
767
+ else headers.push(lowerKey, value);
768
+ if (lowerKey === "content-type") hasContentTypeHeader = true;
769
+ else if (lowerKey === "content-length") hasContentLength = true;
654
770
  }
655
- if (contentType && !hasContentTypeHeader) headers.push(["content-type", contentType]);
656
- if (contentLength && !hasContentLength) headers.push(["content-length", String(contentLength)]);
771
+ if (contentType && !hasContentTypeHeader) headers.push("content-type", contentType);
772
+ if (contentLength && !hasContentLength) headers.push("content-length", String(contentLength));
657
773
  this.#init = void 0;
658
774
  this.#headers = void 0;
659
775
  this.#response = void 0;
@@ -666,7 +782,7 @@ const NodeResponse$1 = /* @__PURE__ */ (() => {
666
782
  };
667
783
  }
668
784
  }
669
- lazyInherit$1(NodeResponse2.prototype, NativeResponse.prototype, "_response");
785
+ lazyInherit$2(NodeResponse2.prototype, NativeResponse.prototype, "_response");
670
786
  Object.setPrototypeOf(NodeResponse2, NativeResponse);
671
787
  Object.setPrototypeOf(NodeResponse2.prototype, NativeResponse.prototype);
672
788
  return NodeResponse2;
@@ -702,11 +818,12 @@ var NodeServer = class {
702
818
  }
703
819
  const request = new NodeRequest({
704
820
  req: nodeReq,
705
- res: nodeRes
821
+ res: nodeRes,
822
+ maxRequestBodySize: this.options.maxRequestBodySize
706
823
  });
707
824
  request.waitUntil = this.#wait?.waitUntil;
708
825
  const res = fetchHandler(request);
709
- return res instanceof Promise ? res.then((resolvedRes) => sendNodeResponse(nodeRes, resolvedRes)) : sendNodeResponse(nodeRes, res);
826
+ return res instanceof Promise ? res.then((resolvedRes) => sendNodeResponseDetached(nodeRes, resolvedRes)) : sendNodeResponseDetached(nodeRes, res);
710
827
  };
711
828
  this.node = {
712
829
  handler,
@@ -787,6 +904,244 @@ var NodeServer = class {
787
904
  })]);
788
905
  }
789
906
  };
907
+ function lazyInherit$1(target, source, sourceKey) {
908
+ for (const key of [...Object.getOwnPropertyNames(source), ...Object.getOwnPropertySymbols(source)]) {
909
+ if (key === "constructor") continue;
910
+ const targetDesc = Object.getOwnPropertyDescriptor(target, key);
911
+ const desc = Object.getOwnPropertyDescriptor(source, key);
912
+ let modified = false;
913
+ if (desc.get) {
914
+ modified = true;
915
+ desc.get = targetDesc?.get || function() {
916
+ return this[sourceKey][key];
917
+ };
918
+ }
919
+ if (desc.set) {
920
+ modified = true;
921
+ desc.set = targetDesc?.set || function(value) {
922
+ this[sourceKey][key] = value;
923
+ };
924
+ }
925
+ if (!targetDesc?.value && typeof desc.value === "function") {
926
+ modified = true;
927
+ desc.value = function(...args) {
928
+ return this[sourceKey][key](...args);
929
+ };
930
+ }
931
+ if (modified) Object.defineProperty(target, key, desc);
932
+ }
933
+ }
934
+ const _needsNormRE$1 = /(?:(?:^|\/)(?:\.|\.\.|%2e|%2e\.|\.%2e|%2e%2e)(?:\/|$))|[\\^\x80-\uffff]/i;
935
+ const FastURL$1 = /* @__PURE__ */ (() => {
936
+ const NativeURL = globalThis.URL;
937
+ const FastURL2 = class URL {
938
+ #url;
939
+ #href;
940
+ #protocol;
941
+ #host;
942
+ #pathname;
943
+ #search;
944
+ #searchParams;
945
+ #pos;
946
+ constructor(url) {
947
+ if (typeof url === "string") if (url[0] === "/") this.#href = url;
948
+ else this.#url = new NativeURL(url);
949
+ else if (_needsNormRE$1.test(url.pathname)) this.#url = new NativeURL(`${url.protocol || "http:"}//${url.host || "localhost"}${url.pathname}${url.search || ""}`);
950
+ else {
951
+ this.#protocol = url.protocol;
952
+ this.#host = url.host;
953
+ this.#pathname = url.pathname;
954
+ this.#search = url.search;
955
+ }
956
+ }
957
+ static [Symbol.hasInstance](val) {
958
+ return val instanceof NativeURL;
959
+ }
960
+ get _url() {
961
+ if (this.#url) return this.#url;
962
+ this.#url = new NativeURL(this.href);
963
+ this.#href = void 0;
964
+ this.#protocol = void 0;
965
+ this.#host = void 0;
966
+ this.#pathname = void 0;
967
+ this.#search = void 0;
968
+ this.#searchParams = void 0;
969
+ this.#pos = void 0;
970
+ return this.#url;
971
+ }
972
+ get href() {
973
+ if (this.#url) return this.#url.href;
974
+ if (!this.#href) this.#href = `${this.#protocol || "http:"}//${this.#host || "localhost"}${this.#pathname || "/"}${this.#search || ""}`;
975
+ return this.#href;
976
+ }
977
+ #getPos() {
978
+ if (!this.#pos) {
979
+ const url = this.href;
980
+ const protoIndex = url.indexOf("://");
981
+ const pathnameIndex = protoIndex === -1 ? -1 : url.indexOf("/", protoIndex + 4);
982
+ const qIndex = pathnameIndex === -1 ? -1 : url.indexOf("?", pathnameIndex);
983
+ this.#pos = [
984
+ protoIndex,
985
+ pathnameIndex,
986
+ qIndex
987
+ ];
988
+ }
989
+ return this.#pos;
990
+ }
991
+ get pathname() {
992
+ if (this.#url) return this.#url.pathname;
993
+ if (this.#pathname === void 0) {
994
+ const [, pathnameIndex, queryIndex] = this.#getPos();
995
+ if (pathnameIndex === -1) return this._url.pathname;
996
+ this.#pathname = this.href.slice(pathnameIndex, queryIndex === -1 ? void 0 : queryIndex);
997
+ }
998
+ return this.#pathname;
999
+ }
1000
+ get search() {
1001
+ if (this.#url) return this.#url.search;
1002
+ if (this.#search === void 0) {
1003
+ const [, pathnameIndex, queryIndex] = this.#getPos();
1004
+ if (pathnameIndex === -1) return this._url.search;
1005
+ const url = this.href;
1006
+ this.#search = queryIndex === -1 || queryIndex === url.length - 1 ? "" : url.slice(queryIndex);
1007
+ }
1008
+ return this.#search;
1009
+ }
1010
+ get searchParams() {
1011
+ if (this.#url) return this.#url.searchParams;
1012
+ if (!this.#searchParams) this.#searchParams = new URLSearchParams(this.search);
1013
+ return this.#searchParams;
1014
+ }
1015
+ get protocol() {
1016
+ if (this.#url) return this.#url.protocol;
1017
+ if (this.#protocol === void 0) {
1018
+ const [protocolIndex] = this.#getPos();
1019
+ if (protocolIndex === -1) return this._url.protocol;
1020
+ const url = this.href;
1021
+ this.#protocol = url.slice(0, protocolIndex + 1);
1022
+ }
1023
+ return this.#protocol;
1024
+ }
1025
+ toString() {
1026
+ return this.href;
1027
+ }
1028
+ toJSON() {
1029
+ return this.href;
1030
+ }
1031
+ };
1032
+ lazyInherit$1(FastURL2.prototype, NativeURL.prototype, "_url");
1033
+ Object.setPrototypeOf(FastURL2.prototype, NativeURL.prototype);
1034
+ Object.setPrototypeOf(FastURL2, NativeURL);
1035
+ return FastURL2;
1036
+ })();
1037
+ const NodeResponse$1 = /* @__PURE__ */ (() => {
1038
+ const NativeResponse = globalThis.Response;
1039
+ const STATUS_CODES = globalThis.process?.getBuiltinModule?.("node:http")?.STATUS_CODES || {};
1040
+ class NodeResponse2 {
1041
+ #body;
1042
+ #init;
1043
+ #headers;
1044
+ #response;
1045
+ constructor(body, init) {
1046
+ this.#body = body;
1047
+ this.#init = init;
1048
+ }
1049
+ static [Symbol.hasInstance](val) {
1050
+ return val instanceof NativeResponse;
1051
+ }
1052
+ get status() {
1053
+ return this.#response?.status || this.#init?.status || 200;
1054
+ }
1055
+ get statusText() {
1056
+ return this.#response?.statusText || this.#init?.statusText || STATUS_CODES[this.status] || "";
1057
+ }
1058
+ get headers() {
1059
+ if (this.#response) return this.#response.headers;
1060
+ if (this.#headers) return this.#headers;
1061
+ const initHeaders = this.#init?.headers;
1062
+ return this.#headers = initHeaders instanceof Headers ? initHeaders : new Headers(initHeaders);
1063
+ }
1064
+ get ok() {
1065
+ if (this.#response) return this.#response.ok;
1066
+ const status = this.status;
1067
+ return status >= 200 && status < 300;
1068
+ }
1069
+ get _response() {
1070
+ if (this.#response) return this.#response;
1071
+ let body = this.#body;
1072
+ if (body && typeof body.pipe === "function" && !(body instanceof Readable)) {
1073
+ const stream = new PassThrough();
1074
+ body.pipe(stream);
1075
+ const abort = body.abort;
1076
+ if (abort) stream.once("close", () => abort());
1077
+ body = stream;
1078
+ }
1079
+ this.#response = new NativeResponse(body, this.#headers ? {
1080
+ ...this.#init,
1081
+ headers: this.#headers
1082
+ } : this.#init);
1083
+ this.#init = void 0;
1084
+ this.#headers = void 0;
1085
+ this.#body = void 0;
1086
+ return this.#response;
1087
+ }
1088
+ _toNodeResponse() {
1089
+ const status = this.status;
1090
+ const statusText = this.statusText;
1091
+ let body;
1092
+ let contentType;
1093
+ let contentLength;
1094
+ if (this.#response) body = this.#response.body;
1095
+ else if (this.#body) if (this.#body instanceof ReadableStream) body = this.#body;
1096
+ else if (typeof this.#body === "string") {
1097
+ body = this.#body;
1098
+ contentType = "text/plain; charset=UTF-8";
1099
+ contentLength = Buffer.byteLength(this.#body);
1100
+ } else if (this.#body instanceof ArrayBuffer) {
1101
+ body = Buffer.from(this.#body);
1102
+ contentLength = this.#body.byteLength;
1103
+ } else if (this.#body instanceof Uint8Array) {
1104
+ body = this.#body;
1105
+ contentLength = this.#body.byteLength;
1106
+ } else if (this.#body instanceof DataView) {
1107
+ body = Buffer.from(this.#body.buffer);
1108
+ contentLength = this.#body.byteLength;
1109
+ } else if (this.#body instanceof Blob) {
1110
+ body = this.#body.stream();
1111
+ contentType = this.#body.type;
1112
+ contentLength = this.#body.size;
1113
+ } else if (typeof this.#body.pipe === "function") body = this.#body;
1114
+ else body = this._response.body;
1115
+ const headers = [];
1116
+ const initHeaders = this.#init?.headers;
1117
+ const headerEntries = this.#response?.headers || this.#headers || (initHeaders ? Array.isArray(initHeaders) ? initHeaders : initHeaders?.entries ? initHeaders.entries() : Object.entries(initHeaders).map(([k, v]) => [k.toLowerCase(), v]) : void 0);
1118
+ let hasContentTypeHeader;
1119
+ let hasContentLength;
1120
+ if (headerEntries) for (const [key, value] of headerEntries) {
1121
+ if (Array.isArray(value)) for (const v of value) headers.push([key, v]);
1122
+ else headers.push([key, value]);
1123
+ if (key === "content-type") hasContentTypeHeader = true;
1124
+ else if (key === "content-length") hasContentLength = true;
1125
+ }
1126
+ if (contentType && !hasContentTypeHeader) headers.push(["content-type", contentType]);
1127
+ if (contentLength && !hasContentLength) headers.push(["content-length", String(contentLength)]);
1128
+ this.#init = void 0;
1129
+ this.#headers = void 0;
1130
+ this.#response = void 0;
1131
+ this.#body = void 0;
1132
+ return {
1133
+ status,
1134
+ statusText,
1135
+ headers,
1136
+ body
1137
+ };
1138
+ }
1139
+ }
1140
+ lazyInherit$1(NodeResponse2.prototype, NativeResponse.prototype, "_response");
1141
+ Object.setPrototypeOf(NodeResponse2, NativeResponse);
1142
+ Object.setPrototypeOf(NodeResponse2.prototype, NativeResponse.prototype);
1143
+ return NodeResponse2;
1144
+ })();
790
1145
  function lazyInherit(target, source, sourceKey) {
791
1146
  for (const key of [...Object.getOwnPropertyNames(source), ...Object.getOwnPropertySymbols(source)]) {
792
1147
  if (key === "constructor") continue;
@@ -1030,5 +1385,6 @@ export {
1030
1385
  NodeResponse$1 as N,
1031
1386
  FastURL as a,
1032
1387
  NodeResponse as b,
1388
+ NodeResponse$2 as c,
1033
1389
  serve as s
1034
1390
  };
@@ -1,4 +1,4 @@
1
- import { r as reactExports, a as React } from "./react.mjs";
1
+ import { r as reactExports, R as React } from "./react.mjs";
2
2
  import { s as shimExports } from "./use-sync-external-store.mjs";
3
3
  import { d as dequal } from "./dequal.mjs";
4
4
  const FOCUS_EVENT = 0;
@@ -307,7 +307,13 @@ const initCache = (provider, options) => {
307
307
  const subs = subscriptions[key] || [];
308
308
  subscriptions[key] = subs;
309
309
  subs.push(callback);
310
- return () => subs.splice(subs.indexOf(callback), 1);
310
+ return () => {
311
+ const index = subs.indexOf(callback);
312
+ if (index >= 0) {
313
+ subs[index] = subs[subs.length - 1];
314
+ subs.pop();
315
+ }
316
+ };
311
317
  };
312
318
  const setter = (key, value, prev) => {
313
319
  provider.set(key, value);
@@ -536,6 +542,8 @@ const WITH_DEDUPE = {
536
542
  dedupe: true
537
543
  };
538
544
  const resolvedUndef = Promise.resolve(UNDEFINED);
545
+ resolvedUndef.status = "fulfilled";
546
+ resolvedUndef.value = UNDEFINED;
539
547
  const sub = () => noop;
540
548
  const useSWRHandler = (_key, fetcher, config) => {
541
549
  const { cache: cache2, compare: compare2, suspense, fallbackData, revalidateOnMount, revalidateIfStale, refreshInterval, refreshWhenHidden, refreshWhenOffline, keepPreviousData, strictServerPrefetchWarning } = config;