codex-copilot-dx 0.8.5 → 0.8.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-copilot-dx",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "description": "Use Codex App with GitHub Copilot",
5
5
  "author": "Dale Xiao",
6
6
  "type": "module",
@@ -572,7 +572,15 @@ async function readIdentityText(req, maxBodyBytes, maxDecodedBodyBytes, signal)
572
572
  throw payloadTooLarge("Decoded", maxDecodedBodyBytes);
573
573
  }
574
574
 
575
- const decoder = new TextDecoder();
575
+ // Larger preallocations raise peak RSS; keep the streaming path for those bodies.
576
+ const preallocatedLength = Number.isFinite(contentLength)
577
+ && contentLength >= 1024 * 1024
578
+ && contentLength <= 24 * 1024 * 1024
579
+ ? contentLength
580
+ : 0;
581
+ let allocated = null;
582
+ let overflow = null;
583
+ const decoder = preallocatedLength ? null : new TextDecoder();
576
584
  let text = "";
577
585
  let total = 0;
578
586
  await consumeRequestChunks(req, {
@@ -581,9 +589,23 @@ async function readIdentityText(req, maxBodyBytes, maxDecodedBodyBytes, signal)
581
589
  total += buffer.length;
582
590
  if (total > maxBodyBytes) throw payloadTooLarge("Raw", maxBodyBytes);
583
591
  if (total > maxDecodedBodyBytes) throw payloadTooLarge("Decoded", maxDecodedBodyBytes);
584
- text += decoder.decode(buffer, { stream: true });
592
+ if (preallocatedLength) {
593
+ allocated ||= Buffer.allocUnsafe(preallocatedLength);
594
+ if (!overflow && total <= allocated.length) {
595
+ buffer.copy(allocated, total - buffer.length);
596
+ } else {
597
+ if (!overflow) overflow = [allocated.subarray(0, total - buffer.length)];
598
+ overflow.push(buffer);
599
+ }
600
+ } else {
601
+ text += decoder.decode(buffer, { stream: true });
602
+ }
585
603
  },
586
604
  });
605
+ if (preallocatedLength) {
606
+ if (!allocated) return "";
607
+ return new TextDecoder().decode(overflow ? Buffer.concat(overflow, total) : allocated.subarray(0, total));
608
+ }
587
609
  return text + decoder.decode();
588
610
  }
589
611
 
@@ -10,8 +10,15 @@ function cloneJson(value) {
10
10
  }
11
11
 
12
12
  function jsonStringByteLength(value) {
13
+ let start = 0;
13
14
  let bytes = 2;
14
- for (let index = 0; index < value.length; index += 1) {
15
+ if (value.length >= 1024) {
16
+ const firstEscape = /["\\\u0000-\u001f\uD800-\uDFFF]/u.exec(value);
17
+ if (!firstEscape) return Buffer.byteLength(value) + 2;
18
+ start = firstEscape.index;
19
+ bytes += Buffer.byteLength(value.slice(0, start));
20
+ }
21
+ for (let index = start; index < value.length; index += 1) {
15
22
  const code = value.charCodeAt(index);
16
23
  if (code === 0x22 || code === 0x5c) {
17
24
  bytes += 2;