litepaseo 0.8.1 → 0.9.1

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 (127) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +21 -8
  3. package/dist/server/cli.mjs +8 -2
  4. package/dist/server/{worker-CoORJLys.mjs → worker-Bp2G5wKD.mjs} +157 -27
  5. package/dist/web/assets/ChangesPanel-DOMLIz9b.js +2 -0
  6. package/dist/web/assets/ChangesPanel-DOMLIz9b.js.br +0 -0
  7. package/dist/web/assets/ChangesPanel-DOMLIz9b.js.gz +0 -0
  8. package/dist/web/assets/CodeBlockNode-C5HKFqZ0.js +3 -0
  9. package/dist/web/assets/CodeBlockNode-C5HKFqZ0.js.br +0 -0
  10. package/dist/web/assets/CodeBlockNode-C5HKFqZ0.js.gz +0 -0
  11. package/dist/web/assets/ConversationSearch-C5IiPRGV.js +1 -0
  12. package/dist/web/assets/ConversationSearch-C5IiPRGV.js.br +0 -0
  13. package/dist/web/assets/ConversationSearch-C5IiPRGV.js.gz +0 -0
  14. package/dist/web/assets/FileViewer-DhPj_aG0.js +2 -0
  15. package/dist/web/assets/FileViewer-DhPj_aG0.js.br +0 -0
  16. package/dist/web/assets/FileViewer-DhPj_aG0.js.gz +0 -0
  17. package/dist/web/assets/FilesPanel-C5A4T4Ea.js +1 -0
  18. package/dist/web/assets/FilesPanel-C5A4T4Ea.js.br +0 -0
  19. package/dist/web/assets/FilesPanel-C5A4T4Ea.js.gz +0 -0
  20. package/dist/web/assets/HostSettings-BwY-M6Zt.js +5 -0
  21. package/dist/web/assets/HostSettings-BwY-M6Zt.js.br +0 -0
  22. package/dist/web/assets/HostSettings-BwY-M6Zt.js.gz +0 -0
  23. package/dist/web/assets/MarkdownMessage-CCyi7hfO.js +199 -0
  24. package/dist/web/assets/MarkdownMessage-CCyi7hfO.js.br +0 -0
  25. package/dist/web/assets/MarkdownMessage-CCyi7hfO.js.gz +0 -0
  26. package/dist/web/assets/{PreCodeBlock-CUCyAlxd.js → PreCodeBlock-h-vER4fC.js} +1 -1
  27. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-n4zE2oPI.js +1 -0
  28. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-n4zE2oPI.js.br +0 -0
  29. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-n4zE2oPI.js.gz +0 -0
  30. package/dist/web/assets/SubagentsPanel-DkOeuHdO.js +1 -0
  31. package/dist/web/assets/SubagentsPanel-DkOeuHdO.js.br +0 -0
  32. package/dist/web/assets/SubagentsPanel-DkOeuHdO.js.gz +0 -0
  33. package/dist/web/assets/TerminalPanel-eVKbwhAM.js +3 -0
  34. package/dist/web/assets/TerminalPanel-eVKbwhAM.js.br +0 -0
  35. package/dist/web/assets/TerminalPanel-eVKbwhAM.js.gz +0 -0
  36. package/dist/web/assets/Tooltip-BaxHVP4x.js +1 -0
  37. package/dist/web/assets/Tooltip-BaxHVP4x.js.br +0 -0
  38. package/dist/web/assets/Tooltip-BaxHVP4x.js.gz +0 -0
  39. package/dist/web/assets/index-CB9VixeI.js +35 -0
  40. package/dist/web/assets/index-CB9VixeI.js.br +0 -0
  41. package/dist/web/assets/index-CB9VixeI.js.gz +0 -0
  42. package/dist/web/assets/index10-7IpT5PSM.js +6 -0
  43. package/dist/web/assets/index10-7IpT5PSM.js.br +0 -0
  44. package/dist/web/assets/index10-7IpT5PSM.js.gz +0 -0
  45. package/dist/web/assets/index3-gjUuQ-9z.js +1 -0
  46. package/dist/web/assets/index4-HZdwIocY.js +1 -0
  47. package/dist/web/assets/index5-B6evHk72.js +1 -0
  48. package/dist/web/assets/index5-B6evHk72.js.br +0 -0
  49. package/dist/web/assets/index5-B6evHk72.js.gz +0 -0
  50. package/dist/web/assets/index6-D7ieXlqa.js +1 -0
  51. package/dist/web/assets/index6-D7ieXlqa.js.br +0 -0
  52. package/dist/web/assets/index6-D7ieXlqa.js.gz +0 -0
  53. package/dist/web/assets/index7-CZ0TiU0G.js +2 -0
  54. package/dist/web/assets/index7-CZ0TiU0G.js.br +0 -0
  55. package/dist/web/assets/index7-CZ0TiU0G.js.gz +0 -0
  56. package/dist/web/assets/index8-DlTg7787.js +2 -0
  57. package/dist/web/assets/index8-DlTg7787.js.br +0 -0
  58. package/dist/web/assets/index8-DlTg7787.js.gz +0 -0
  59. package/dist/web/assets/index9-0kHMsOL6.js +1 -0
  60. package/dist/web/assets/index9-0kHMsOL6.js.br +0 -0
  61. package/dist/web/assets/index9-0kHMsOL6.js.gz +0 -0
  62. package/dist/web/assets/vue.runtime.esm-bundler-4XjPOHMM.js +4 -0
  63. package/dist/web/assets/vue.runtime.esm-bundler-4XjPOHMM.js.br +0 -0
  64. package/dist/web/assets/vue.runtime.esm-bundler-4XjPOHMM.js.gz +0 -0
  65. package/dist/web/index.html +2 -2
  66. package/dist/web/index.html.br +0 -0
  67. package/dist/web/index.html.gz +0 -0
  68. package/package.json +1 -1
  69. package/dist/web/assets/ChangesPanel-BfZlL4PP.js +0 -2
  70. package/dist/web/assets/ChangesPanel-BfZlL4PP.js.br +0 -0
  71. package/dist/web/assets/ChangesPanel-BfZlL4PP.js.gz +0 -0
  72. package/dist/web/assets/CodeBlockNode-Co9cOzhY.js +0 -3
  73. package/dist/web/assets/CodeBlockNode-Co9cOzhY.js.br +0 -0
  74. package/dist/web/assets/CodeBlockNode-Co9cOzhY.js.gz +0 -0
  75. package/dist/web/assets/ConversationSearch-V1Kn9VT8.js +0 -1
  76. package/dist/web/assets/ConversationSearch-V1Kn9VT8.js.br +0 -0
  77. package/dist/web/assets/ConversationSearch-V1Kn9VT8.js.gz +0 -0
  78. package/dist/web/assets/FileViewer-CfW5h6KD.js +0 -2
  79. package/dist/web/assets/FileViewer-CfW5h6KD.js.br +0 -0
  80. package/dist/web/assets/FileViewer-CfW5h6KD.js.gz +0 -0
  81. package/dist/web/assets/FilesPanel-CU6zdvaK.js +0 -1
  82. package/dist/web/assets/FilesPanel-CU6zdvaK.js.br +0 -0
  83. package/dist/web/assets/FilesPanel-CU6zdvaK.js.gz +0 -0
  84. package/dist/web/assets/HostSettings-Bq5NYGD5.js +0 -5
  85. package/dist/web/assets/HostSettings-Bq5NYGD5.js.br +0 -0
  86. package/dist/web/assets/HostSettings-Bq5NYGD5.js.gz +0 -0
  87. package/dist/web/assets/MarkdownMessage-DzQZoTAR.js +0 -199
  88. package/dist/web/assets/MarkdownMessage-DzQZoTAR.js.br +0 -0
  89. package/dist/web/assets/MarkdownMessage-DzQZoTAR.js.gz +0 -0
  90. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-CLiZArLE.js +0 -1
  91. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-CLiZArLE.js.br +0 -0
  92. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-CLiZArLE.js.gz +0 -0
  93. package/dist/web/assets/SubagentsPanel-Bkc-YBTq.js +0 -1
  94. package/dist/web/assets/SubagentsPanel-Bkc-YBTq.js.br +0 -0
  95. package/dist/web/assets/SubagentsPanel-Bkc-YBTq.js.gz +0 -0
  96. package/dist/web/assets/TerminalPanel-BMb200BW.js +0 -3
  97. package/dist/web/assets/TerminalPanel-BMb200BW.js.br +0 -0
  98. package/dist/web/assets/TerminalPanel-BMb200BW.js.gz +0 -0
  99. package/dist/web/assets/Tooltip-BTYtxBdq.js +0 -1
  100. package/dist/web/assets/Tooltip-BTYtxBdq.js.br +0 -0
  101. package/dist/web/assets/Tooltip-BTYtxBdq.js.gz +0 -0
  102. package/dist/web/assets/index-CqisJnas.js +0 -35
  103. package/dist/web/assets/index-CqisJnas.js.br +0 -0
  104. package/dist/web/assets/index-CqisJnas.js.gz +0 -0
  105. package/dist/web/assets/index10-Lnrrraal.js +0 -6
  106. package/dist/web/assets/index10-Lnrrraal.js.br +0 -0
  107. package/dist/web/assets/index10-Lnrrraal.js.gz +0 -0
  108. package/dist/web/assets/index3-BNz7EKXb.js +0 -1
  109. package/dist/web/assets/index4-ppcKJuG9.js +0 -1
  110. package/dist/web/assets/index5-CDOwxu2S.js +0 -1
  111. package/dist/web/assets/index5-CDOwxu2S.js.br +0 -0
  112. package/dist/web/assets/index5-CDOwxu2S.js.gz +0 -0
  113. package/dist/web/assets/index6-ChKgNVhi.js +0 -1
  114. package/dist/web/assets/index6-ChKgNVhi.js.br +0 -0
  115. package/dist/web/assets/index6-ChKgNVhi.js.gz +0 -0
  116. package/dist/web/assets/index7-C3HsgqDG.js +0 -2
  117. package/dist/web/assets/index7-C3HsgqDG.js.br +0 -0
  118. package/dist/web/assets/index7-C3HsgqDG.js.gz +0 -0
  119. package/dist/web/assets/index8-BAAbYvNT.js +0 -2
  120. package/dist/web/assets/index8-BAAbYvNT.js.br +0 -0
  121. package/dist/web/assets/index8-BAAbYvNT.js.gz +0 -0
  122. package/dist/web/assets/index9-D13iAaTq.js +0 -1
  123. package/dist/web/assets/index9-D13iAaTq.js.br +0 -0
  124. package/dist/web/assets/index9-D13iAaTq.js.gz +0 -0
  125. package/dist/web/assets/vue.runtime.esm-bundler-DwGo9CTz.js +0 -4
  126. package/dist/web/assets/vue.runtime.esm-bundler-DwGo9CTz.js.br +0 -0
  127. package/dist/web/assets/vue.runtime.esm-bundler-DwGo9CTz.js.gz +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.1
4
+
5
+ - Compress live streams and larger API responses (1 KB and up) with brotli or gzip, as the browser accepts. A conversation's first rows usually shrink 3-6 times, for example 157 KB to 27 KB, which saves mobile data. Every stream event is flushed as it is written, so compression never holds one back. Turn it off with `litepaseo config set compression off` if a proxy in between mishandles compressed streams.
6
+ - Diagnose slow conversation opens on phones: browser reports now say which kind of browser it was (engine, system, installed web app; never the user agent string), the connection protocol and compression, and how the stream's body arrived (pieces, sizes, arrival times, the longest silence). The 20-second waits still seen on an iPhone web app behind a Cloudflare Tunnel delivered first bytes within about 200 ms but the rows only with the next heartbeat; these reports should show where they were held.
7
+
8
+ ## 0.9.0
9
+
10
+ - Switch back to a conversation you opened recently and it shows at once, where you left it: the last 5 conversations (3 on phones) stay rendered. Out of view they do nothing: no connection, no timers, no rendering. Coming back, only messages that changed meanwhile render again. In a test switching between real conversations at 4x CPU slowdown (an approximation of a phone), rows were on screen in 162-196 ms instead of 340-384 ms, using less than half the CPU.
11
+ - Coming back to a conversation, or to the tab after it was in the background, downloads only what changed instead of the latest 200 rows again: in the same test, 0.1-0.4 KB instead of 175 KB. The server keeps a conversation ready for 5 minutes after the last viewer leaves (was 30 seconds), so coming back within that time does not reload it from the host.
12
+ - Next-input suggestions stay with their conversation: switching away and back keeps the Tab completion, and a suggestion that arrives after you switched no longer lands in another conversation's composer.
13
+
3
14
  ## 0.8.1
4
15
 
5
16
  - Fix conversations that sometimes took about 20 seconds to load behind a Cloudflare Tunnel, showing "Waiting for the host to load this conversation". The host had answered at once; the tunnel held the stream's latest bytes until more arrived, which for an idle conversation was the next 20-second heartbeat. Each burst of live updates is now followed by a few bytes of padding, which pushes it through. This applies to every live stream, including the sidebar and queues.
package/README.md CHANGED
@@ -37,12 +37,14 @@ battery runtime has not been measured.
37
37
  latency, rendering differences, raw data and reproduction steps.
38
38
 
39
39
  The approach is simple: update less often, send only changes, keep rendered history
40
- bounded, and pause streams while a tab is hidden. Everything ships in one npm
41
- package, with no separate database service to deploy.
40
+ bounded, and pause streams while a tab is hidden. Recently opened conversations stay
41
+ rendered but idle, so switching back costs neither a re-render nor a re-download.
42
+ Everything ships in one npm package, with no separate database service to deploy.
42
43
 
43
44
  ## What you can do
44
45
 
45
46
  - Manage conversations across multiple Paseo hosts in one place.
47
+ - Switch back and forth between recent conversations instantly: each one comes back as you left it, scrolled to the same place, and fetches only what changed meanwhile.
46
48
  - Pin projects from their ⋮ menu to keep important repositories at the top of the Projects sidebar. Pins follow pin order and sync across devices; Unpin restores activity ordering.
47
49
  - Create sessions, choose a provider/model, send messages, stop turns, and answer
48
50
  permission requests or structured questions.
@@ -245,6 +247,7 @@ litepaseo restart # apply (or: litepaseo
245
247
  | `port` | `8787` | HTTP port | `LITEPASEO_PORT` |
246
248
  | `bind` | `127.0.0.1` | Listening address | `LITEPASEO_BIND` |
247
249
  | `push-subject` | `mailto:litepaseo@example.com` | Contact for push services (see below) | `LITEPASEO_PUSH_SUBJECT` |
250
+ | `compression` | `on` | Compress API responses and live streams (`on` or `off`) | `LITEPASEO_COMPRESSION` |
248
251
 
249
252
  An environment variable, when set, wins over the saved value for that run.
250
253
  `LITEPASEO_HOME` (default `~/.litepaseo`) chooses the data directory itself, so it
@@ -282,16 +285,26 @@ page had just been in the background (`backgroundMs`, `visibleForMs`). A late
282
285
  `connectedMs` with no matching `timeline_slow` means the request took that long to reach
283
286
  the server, typically a connection the browser reused after sleep or a network change. A
284
287
  late `firstByteMs` after an early `connectedMs` means something in between, such as a
285
- proxy or tunnel, held the data. Find them with
288
+ proxy or tunnel, held the data. Browser reports also name the kind of browser (`engine`,
289
+ `os`, `standalone` for an installed web app; never the user agent string), the connection
290
+ (`protocol`, such as `h2` or `h3`, and `encoding`), and how the stream's body arrived:
291
+ `chunks` and `characters` up to the rows, `arrivals` (time and size of the first 10
292
+ pieces), `lastChunkMs`, and the longest silence between pieces (`maxGapMs`, ending at
293
+ `maxGapEndMs`). A long gap ending just before the rows means the data was held back on
294
+ the way rather than slow to send. Find them with
286
295
  `litepaseo logs -n 2000 | grep timeline_slow`.
287
296
 
288
297
  While a conversation is still loading after 3 seconds, the page says whether it is still
289
298
  connecting to LitePaseo, waiting for the network to deliver data, or waiting for the host.
290
-
291
- Some proxies hold a stream's latest bytes until more arrive. LitePaseo follows each burst
292
- of live updates with a few bytes of padding, so they get through without waiting for the
293
- next heartbeat. After an upgrade, open pages offer a
294
- reload so they run the installed version.
299
+ After an upgrade, open pages offer a reload so they run the installed version.
300
+
301
+ Live streams and larger API responses (1 KB and up) are compressed with brotli or gzip
302
+ for browsers that accept it: a conversation's first rows usually shrink 3-6 times. Each
303
+ stream event is flushed as it is written, so compression never delays it. If a proxy
304
+ between you and LitePaseo mishandles compressed streams, run
305
+ `litepaseo config set compression off` and restart. Some proxies also hold a stream's
306
+ latest bytes until more arrive, so each burst of live updates is followed by a few bytes
307
+ of padding.
295
308
 
296
309
  ## How it fits together
297
310
 
@@ -8,7 +8,7 @@ import { DatabaseSync } from "node:sqlite";
8
8
  import { homedir } from "node:os";
9
9
  import { fileURLToPath } from "node:url";
10
10
  // src/server/version.ts
11
- const VERSION = "0.8.1";
11
+ const VERSION = "0.9.1";
12
12
  // src/server/rotating-log.ts
13
13
  /** One writer (the supervisor); bounded active file plus numbered archives. */
14
14
  var RotatingLog = class {
@@ -1088,6 +1088,12 @@ const CONFIG_KEYS = {
1088
1088
  } catch {}
1089
1089
  return "Use mailto:you@example.com or an https:// address you control.";
1090
1090
  }
1091
+ },
1092
+ compression: {
1093
+ env: "LITEPASEO_COMPRESSION",
1094
+ fallback: "on",
1095
+ summary: "Compress API responses and live streams (on or off)",
1096
+ check: (value) => value === "on" || value === "off" ? null : "Use on or off."
1091
1097
  }
1092
1098
  };
1093
1099
  const configKeys = Object.keys(CONFIG_KEYS);
@@ -1715,7 +1721,7 @@ async function run() {
1715
1721
  if (name === "--help" || name === "-h") return console.log(mainHelp(VERSION, displayDirectory(), out));
1716
1722
  if (name === "worker") {
1717
1723
  const paths = await dataDirectory();
1718
- const { runWorker } = await import("./worker-CoORJLys.mjs");
1724
+ const { runWorker } = await import("./worker-Bp2G5wKD.mjs");
1719
1725
  return runWorker(paths.directory, fileURLToPath(new URL("../web/", import.meta.url)));
1720
1726
  }
1721
1727
  const command = findCommand(name);
@@ -11,6 +11,8 @@ import { getParentAgentIdFromLabels } from "@getpaseo/protocol/agent-labels";
11
11
  import { timelineItemIdentity } from "@getpaseo/protocol/timeline-identity";
12
12
  import { z } from "zod";
13
13
  import { AgentPermissionResponseSchema, AgentSkillSelectionSchema, MutableDaemonConfigPatchSchema } from "@getpaseo/protocol/messages";
14
+ import { brotliCompress, constants as constants$1, createBrotliCompress, createGzip, gzip } from "node:zlib";
15
+ import { promisify } from "node:util";
14
16
  import { lstat, readFile, realpath } from "node:fs/promises";
15
17
  import { Hono } from "hono";
16
18
  import { bodyLimit } from "hono/body-limit";
@@ -650,6 +652,11 @@ var TimelineView = class {
650
652
  lastSeq = -1;
651
653
  hasOlder = false;
652
654
  startCursor = null;
655
+ /**
656
+ * The view knows every row changed after this seq, so a browser holding everything up to it
657
+ * can resume with just those rows. Set by each load; raised when rows are trimmed.
658
+ */
659
+ resumeFloor = Number.POSITIVE_INFINITY;
653
660
  /** True while rows reach back to the first projected row, so unseen identities are new. */
654
661
  complete = false;
655
662
  state = "loading";
@@ -718,10 +725,17 @@ var TimelineView = class {
718
725
  this.subscription = null;
719
726
  return released;
720
727
  }
721
- watch(watcher) {
728
+ /**
729
+ * Adds a browser. A live view answers at once: with the rows changed since `since` when the
730
+ * browser holds this conversation up to a point the view can resume from (nothing when none
731
+ * changed), else with a reset. A loading view sends its reset once loaded.
732
+ */
733
+ watch(watcher, since) {
722
734
  if (this.state === "live" || this.state === "catching-up") {
723
735
  this.flush();
724
- watcher([this.resetOp()]);
736
+ const resumed = since ? this.resumeOps(since) : null;
737
+ if (!resumed) watcher([this.resetOp()]);
738
+ else if (resumed.length) watcher(resumed);
725
739
  } else if (this.watchers.size) this.joiners.push(now());
726
740
  this.watchers.add(watcher);
727
741
  return () => this.watchers.delete(watcher);
@@ -906,6 +920,7 @@ var TimelineView = class {
906
920
  this.pending.clear();
907
921
  this.epoch = page.epoch;
908
922
  this.lastSeq = page.window.maxSeq;
923
+ this.resumeFloor = this.lastSeq;
909
924
  this.hasOlder = page.hasOlder;
910
925
  this.startCursor = page.startCursor;
911
926
  this.complete = !page.hasOlder;
@@ -962,6 +977,7 @@ var TimelineView = class {
962
977
  trim() {
963
978
  const removed = this.rows.splice(0, this.rows.length - KEEP_ROWS);
964
979
  for (const row of removed) {
980
+ this.resumeFloor = Math.max(this.resumeFloor, row.seqEnd);
965
981
  this.bySeqStart.delete(row.seqStart);
966
982
  this.pending.delete(row.seqStart);
967
983
  const identity = timelineItemIdentity(row.item);
@@ -975,7 +991,7 @@ var TimelineView = class {
975
991
  };
976
992
  }
977
993
  mark(seqStart, full, text = "") {
978
- if (this.pendingReset) return;
994
+ if (this.pendingReset || !this.watchers.size) return;
979
995
  const pending = this.pending.get(seqStart);
980
996
  if (!pending) this.pending.set(seqStart, {
981
997
  full,
@@ -1019,6 +1035,20 @@ var TimelineView = class {
1019
1035
  this.pending.clear();
1020
1036
  if (ops.length) this.broadcast(ops);
1021
1037
  }
1038
+ /**
1039
+ * The rows a returning browser lacks: those from its window on that changed after `since.seq`,
1040
+ * as upserts. Null when the view cannot tell (another epoch, history it no longer holds) or
1041
+ * when so much changed that a reset is the smaller answer.
1042
+ */
1043
+ resumeOps(since) {
1044
+ if (since.epoch !== this.epoch || since.seq < this.resumeFloor || since.seq > this.lastSeq) return null;
1045
+ const changed = this.rows.filter((row) => row.seqEnd > since.seq && row.seqStart >= since.from);
1046
+ if (changed.length > RESET_ROWS) return null;
1047
+ return changed.map((row) => ({
1048
+ type: "upsert",
1049
+ row: { ...row }
1050
+ }));
1051
+ }
1022
1052
  resetOp() {
1023
1053
  const start = Math.max(0, this.rows.length - RESET_ROWS);
1024
1054
  const rows = this.rows.slice(start).map((row) => ({ ...row }));
@@ -1030,7 +1060,8 @@ var TimelineView = class {
1030
1060
  startCursor: start > 0 ? {
1031
1061
  epoch: this.epoch,
1032
1062
  seq: rows[0].seqStart
1033
- } : this.startCursor
1063
+ } : this.startCursor,
1064
+ seq: this.lastSeq
1034
1065
  };
1035
1066
  }
1036
1067
  /** The first rows went out: report how long the view, and anyone who joined it, waited. */
@@ -1358,8 +1389,12 @@ var UnknownHostError = class extends Error {
1358
1389
  super("Unknown host");
1359
1390
  }
1360
1391
  };
1361
- /** Idle grace before an unwatched timeline releases its daemon subscription. */
1362
- const TIMELINE_GRACE_MS = 3e4;
1392
+ /**
1393
+ * Idle grace before an unwatched timeline releases its daemon subscription. Browsers keep
1394
+ * recently opened conversations and come back to them; while the view lives, coming back
1395
+ * costs only the rows that changed meanwhile, not a reload from the daemon.
1396
+ */
1397
+ const TIMELINE_GRACE_MS = 3e5;
1363
1398
  /** Conversation opens slower than this are logged with a per-layer breakdown. */
1364
1399
  const SLOW_TIMELINE_MS = 3e3;
1365
1400
  /** A viewer still without rows after this long has the daemon checked for a silent connection. */
@@ -1520,9 +1555,10 @@ var Hosts = class {
1520
1555
  }
1521
1556
  /**
1522
1557
  * Shares one live timeline per agent across all watching browsers. With `subagentId`, the
1523
- * conversation of one of the agent's provider subagents.
1558
+ * conversation of one of the agent's provider subagents. With `since`, a browser that holds
1559
+ * the conversation resumes with what changed (see TimelineView.watch).
1524
1560
  */
1525
- watchTimeline(hostId, agentId, watcher, subagentId) {
1561
+ watchTimeline(hostId, agentId, watcher, subagentId, since) {
1526
1562
  const client = this.get(hostId);
1527
1563
  const key = subagentId ? `${hostId}:${agentId}:subagent:${subagentId}` : `${hostId}:${agentId}`;
1528
1564
  let entry = this.timelines.get(key);
@@ -1579,7 +1615,8 @@ var Hosts = class {
1579
1615
  const stop = entry.view.watch((ops) => {
1580
1616
  if (waiting && ops.some((op) => op.type === "reset")) finishWait(false);
1581
1617
  watcher(ops);
1582
- });
1618
+ }, since);
1619
+ if (joined.state === "live" || joined.state === "catching-up") finishWait(false);
1583
1620
  const current = entry;
1584
1621
  return () => {
1585
1622
  finishWait(true);
@@ -2374,33 +2411,63 @@ var ServerSendQueue = class {
2374
2411
  // src/server/sse.ts
2375
2412
  const HEARTBEAT_MS = 2e4;
2376
2413
  /**
2377
- * Some proxies hold a stream's latest bytes until more arrive: behind a Cloudflare Tunnel, a
2378
- * conversation's rows reached the browser only with the next heartbeat, 20 s later. So every
2379
- * burst of writes is followed by a tiny comment, which pushes it through.
2414
+ * Some proxies hold a stream's latest bytes until more arrive, so every burst of writes is
2415
+ * followed by a tiny comment. It did not cure the 20 s waits seen on an iPhone behind a
2416
+ * Cloudflare Tunnel (rows arrived with the next heartbeat anyway); slow-open reports now carry
2417
+ * the browser's side of each stream to find out why.
2380
2418
  */
2381
2419
  const NUDGE_MS = 50;
2382
- /** Server-sent events over a plain fetch response, so the bearer header still authenticates. */
2383
- function eventStream(signal, open, valid = () => true) {
2420
+ /** The best encoding the request accepts, when compression is on. */
2421
+ function streamEncoding(acceptEncoding, enabled) {
2422
+ if (!enabled || !acceptEncoding) return null;
2423
+ const accepted = /* @__PURE__ */ new Set();
2424
+ for (const part of acceptEncoding.split(",")) {
2425
+ const [name, ...params] = part.trim().toLowerCase().split(";");
2426
+ const q = params.map((p) => p.trim()).find((p) => p.startsWith("q="));
2427
+ if (!q || Number(q.slice(2)) > 0) accepted.add(name.trim());
2428
+ }
2429
+ return accepted.has("br") ? "br" : accepted.has("gzip") ? "gzip" : null;
2430
+ }
2431
+ /**
2432
+ * Server-sent events over a plain fetch response, so the bearer header still authenticates.
2433
+ * With an encoding, every write is compressed and flushed at once: compression never holds an
2434
+ * event back (a sync flush costs a few bytes per write).
2435
+ */
2436
+ function eventStream(signal, open, valid = () => true, encoding = null) {
2384
2437
  const encoder = new TextEncoder();
2385
2438
  let cleanup;
2386
2439
  let nudge;
2440
+ let compressor = null;
2387
2441
  let stopped = false;
2388
2442
  const stop = () => {
2389
2443
  stopped = true;
2390
2444
  clearTimeout(nudge);
2445
+ compressor?.destroy();
2391
2446
  cleanup?.();
2392
2447
  cleanup = void 0;
2393
2448
  };
2394
2449
  const body = new ReadableStream({
2395
2450
  start(controller) {
2396
- const enqueue = (text) => {
2451
+ const output = (bytes) => {
2397
2452
  if (stopped) return;
2398
2453
  try {
2399
- controller.enqueue(encoder.encode(text));
2454
+ controller.enqueue(bytes);
2400
2455
  } catch {
2401
2456
  stop();
2402
2457
  }
2403
2458
  };
2459
+ if (encoding) {
2460
+ compressor = encoding === "br" ? createBrotliCompress({ params: { [constants$1.BROTLI_PARAM_QUALITY]: 5 } }) : createGzip({ level: 6 });
2461
+ compressor.on("data", (chunk) => output(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength)));
2462
+ compressor.on("error", stop);
2463
+ }
2464
+ const flushMode = encoding === "br" ? constants$1.BROTLI_OPERATION_FLUSH : constants$1.Z_SYNC_FLUSH;
2465
+ const enqueue = (text) => {
2466
+ if (stopped) return;
2467
+ if (!compressor) return output(encoder.encode(text));
2468
+ compressor.write(text);
2469
+ compressor.flush(flushMode);
2470
+ };
2404
2471
  const write = (text) => {
2405
2472
  enqueue(text);
2406
2473
  if (stopped || nudge) return;
@@ -2435,9 +2502,37 @@ function eventStream(signal, open, valid = () => true) {
2435
2502
  return new Response(body, { headers: {
2436
2503
  "Content-Type": "text/event-stream",
2437
2504
  "Cache-Control": "no-cache, no-transform",
2438
- "X-Accel-Buffering": "no"
2505
+ "X-Accel-Buffering": "no",
2506
+ ...encoding ? {
2507
+ "Content-Encoding": encoding,
2508
+ Vary: "Accept-Encoding"
2509
+ } : {}
2439
2510
  } });
2440
2511
  }
2512
+ // src/server/compression.ts
2513
+ const brotli = promisify(brotliCompress);
2514
+ const gzipped = promisify(gzip);
2515
+ /**
2516
+ * Compresses JSON API responses (history pages, prompt indexes, directory reads) with brotli
2517
+ * or gzip, as the browser accepts. Live streams compress themselves (see eventStream).
2518
+ */
2519
+ function compressJson(enabled) {
2520
+ return async (c, next) => {
2521
+ await next();
2522
+ if (!enabled || c.req.method === "HEAD") return;
2523
+ const res = c.res;
2524
+ if (!res.body || res.headers.has("Content-Encoding") || !(res.headers.get("Content-Type") ?? "").startsWith("application/json")) return;
2525
+ const encoding = streamEncoding(c.req.header("Accept-Encoding"), true);
2526
+ if (!encoding) return;
2527
+ const body = new Uint8Array(await res.arrayBuffer());
2528
+ const compressed = body.byteLength < 1024 ? null : encoding === "br" ? await brotli(body, { params: { [constants$1.BROTLI_PARAM_QUALITY]: 5 } }) : await gzipped(body, { level: 6 });
2529
+ c.res = new Response(compressed ?? body, res);
2530
+ c.res.headers.delete("Content-Length");
2531
+ if (compressed) c.res.headers.set("Content-Encoding", encoding);
2532
+ const vary = c.res.headers.get("Vary");
2533
+ if (!vary || !/(?:^|,)\s*accept-encoding\s*(?:,|$)/i.test(vary)) c.res.headers.set("Vary", vary ? `${vary}, Accept-Encoding` : "Accept-Encoding");
2534
+ };
2535
+ }
2441
2536
  // src/server/media.ts
2442
2537
  /** Raster images only: an SVG opened directly could run script on this origin. */
2443
2538
  const IMAGE_MIME = {
@@ -2553,7 +2648,7 @@ const path = z.string().min(1).max(4096).refine((p) => !p.includes("\0"));
2553
2648
  * daemon, which confines file access to the workspace and owns the terminals; nothing here
2554
2649
  * keeps state beyond an open terminal stream.
2555
2650
  */
2556
- function registerWorkspaceRoutes(app, hosts, store, valid) {
2651
+ function registerWorkspaceRoutes(app, hosts, store, valid, encodingOf = () => null) {
2557
2652
  app.get("/api/hosts/:host/changes", async (c) => {
2558
2653
  const cwd = path.parse(c.req.query("cwd"));
2559
2654
  const result = await hosts.get(c.req.param("host")).driver.getCheckoutDiff(cwd, { mode: "uncommitted" });
@@ -2726,7 +2821,7 @@ function registerWorkspaceRoutes(app, hosts, store, valid) {
2726
2821
  stop();
2727
2822
  subscription.release().catch(() => {});
2728
2823
  };
2729
- }, valid(c));
2824
+ }, valid(c), encodingOf(c));
2730
2825
  });
2731
2826
  /** Every connected host's schedules; a host that fails reports its error instead. */
2732
2827
  app.get("/api/schedules", async (c) => {
@@ -4100,6 +4195,10 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4100
4195
  c.header("Referrer-Policy", "no-referrer");
4101
4196
  c.header("Content-Security-Policy", "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self'; img-src 'self' data: blob:; worker-src 'self'; manifest-src 'self'; frame-ancestors 'none'");
4102
4197
  });
4198
+ const compression = options.compression !== false;
4199
+ /** How a live stream to this request is compressed. */
4200
+ const encodingOf = (c) => streamEncoding(c.req.header("Accept-Encoding"), compression);
4201
+ app.use("/api/*", compressJson(compression));
4103
4202
  app.use("/api/*", (c, next) => bodyLimit({ maxSize: c.req.method !== "POST" ? 1048576 : c.req.path.endsWith("/attachments") ? MAX_FILE_BYTES : c.req.path === "/api/dictation/transcribe" ? MAX_DICTATION_BYTES : 1048576 })(c, next));
4104
4203
  app.use("/api/*", async (c, next) => {
4105
4204
  c.header("Cache-Control", "no-store");
@@ -4426,6 +4525,29 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4426
4525
  rowsMs: ms,
4427
4526
  renderMs: ms,
4428
4527
  firstByteMs: ms.optional(),
4528
+ engine: z.enum([
4529
+ "webkit",
4530
+ "blink",
4531
+ "gecko",
4532
+ "other"
4533
+ ]).optional(),
4534
+ os: z.enum([
4535
+ "ios",
4536
+ "android",
4537
+ "macos",
4538
+ "windows",
4539
+ "linux",
4540
+ "other"
4541
+ ]).optional(),
4542
+ standalone: z.boolean().optional(),
4543
+ protocol: z.string().max(20).nullable().optional(),
4544
+ encoding: z.string().max(10).nullable().optional(),
4545
+ chunks: z.number().int().nonnegative().max(1e6).optional(),
4546
+ characters: z.number().int().nonnegative().max(1e9).optional(),
4547
+ lastChunkMs: ms.optional(),
4548
+ maxGapMs: z.number().int().nonnegative().max(36e5).optional(),
4549
+ maxGapEndMs: ms.optional(),
4550
+ arrivals: z.array(z.tuple([z.number().int().nonnegative().max(36e5), z.number().int().nonnegative().max(1e9)])).max(10).optional(),
4429
4551
  attempts: z.number().int().nonnegative().max(1e3),
4430
4552
  hidden: z.boolean(),
4431
4553
  pageAgeMs: long.optional(),
@@ -4473,7 +4595,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4473
4595
  deliverAgents(stream);
4474
4596
  directoryStreams.add(stream);
4475
4597
  return () => directoryStreams.delete(stream);
4476
- }, streamValidity(c));
4598
+ }, streamValidity(c), encodingOf(c));
4477
4599
  });
4478
4600
  app.post("/api/hosts", async (c) => {
4479
4601
  const input = z.object({
@@ -4585,6 +4707,11 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4585
4707
  });
4586
4708
  app.get("/api/hosts/:host/agents/:agent/timeline/stream", (c) => {
4587
4709
  hosts.get(c.req.param("host"));
4710
+ const since = z.object({
4711
+ epoch: z.string().min(1).max(200),
4712
+ seq: z.coerce.number().int().nonnegative(),
4713
+ from: z.coerce.number().int().nonnegative()
4714
+ }).safeParse(c.req.query());
4588
4715
  return eventStream(c.req.raw.signal, (send) => {
4589
4716
  const stop = hosts.watchTimeline(c.req.param("host"), c.req.param("agent"), (ops) => send({
4590
4717
  type: "ops",
@@ -4601,7 +4728,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4601
4728
  row: enrich(op.row)
4602
4729
  } : op;
4603
4730
  })
4604
- }));
4731
+ }), void 0, since.success ? since.data : void 0);
4605
4732
  let sent = "";
4606
4733
  let stopSubagents = () => {};
4607
4734
  try {
@@ -4619,7 +4746,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4619
4746
  stop();
4620
4747
  stopSubagents();
4621
4748
  };
4622
- }, streamValidity(c));
4749
+ }, streamValidity(c), encodingOf(c));
4623
4750
  });
4624
4751
  /** One provider subagent's conversation, read-only, live like an agent's. */
4625
4752
  app.get("/api/hosts/:host/agents/:agent/subagents/:subagent/timeline/stream", (c) => {
@@ -4627,7 +4754,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4627
4754
  return eventStream(c.req.raw.signal, (send) => hosts.watchTimeline(c.req.param("host"), c.req.param("agent"), (ops) => send({
4628
4755
  type: "ops",
4629
4756
  ops
4630
- }), c.req.param("subagent")), streamValidity(c));
4757
+ }), c.req.param("subagent")), streamValidity(c), encodingOf(c));
4631
4758
  });
4632
4759
  app.get("/api/hosts/:host/agents/:agent/subagents/:subagent/timeline", async (c) => {
4633
4760
  const cursor = z.object({
@@ -4925,13 +5052,13 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4925
5052
  stop();
4926
5053
  stopHosts();
4927
5054
  };
4928
- }, streamValidity(c)));
5055
+ }, streamValidity(c), encodingOf(c)));
4929
5056
  app.get("/api/hosts/:host/agents/:agent/queue/stream", (c) => eventStream(c.req.raw.signal, (send) => {
4930
5057
  const publish = () => send(sendQueue.list(c.req.param("host"), c.req.param("agent")));
4931
5058
  const stop = sendQueue.onChange(publish);
4932
5059
  publish();
4933
5060
  return stop;
4934
- }, streamValidity(c)));
5061
+ }, streamValidity(c), encodingOf(c)));
4935
5062
  app.post("/api/hosts/:host/agents/:agent/queue/:id/control", async (c) => {
4936
5063
  const { action } = z.object({ action: z.enum([
4937
5064
  "pause",
@@ -5262,7 +5389,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
5262
5389
  }
5263
5390
  });
5264
5391
  registerHostSettings(app, hosts);
5265
- registerWorkspaceRoutes(app, hosts, store, (c) => streamValidity(c));
5392
+ registerWorkspaceRoutes(app, hosts, store, (c) => streamValidity(c), encodingOf);
5266
5393
  app.get("/api/usage", async (c) => c.json(await usage.report(c.req.query("refresh") === "1")));
5267
5394
  app.get("/api/board", (c) => c.json(store.board()));
5268
5395
  app.put("/api/board", async (c) => {
@@ -5371,7 +5498,10 @@ async function runWorker(directory, webRoot) {
5371
5498
  }
5372
5499
  const config = effectiveConfig(store, process.env);
5373
5500
  const port = Number(config.port.value), hostname = config.bind.value;
5374
- const app = createApp(store, hosts, tokenFile(tokenPath), webRoot, { pushSubject: config["push-subject"].value });
5501
+ const app = createApp(store, hosts, tokenFile(tokenPath), webRoot, {
5502
+ pushSubject: config["push-subject"].value,
5503
+ compression: config.compression.value !== "off"
5504
+ });
5375
5505
  const server = serve({
5376
5506
  fetch: app.fetch,
5377
5507
  port,
@@ -0,0 +1,2 @@
1
+ import{I as e,R as t,S as n,T as r,V as i,at as a,ct as o,f as s,g as c,q as l,tt as u,v as d,y as f}from"./vue.runtime.esm-bundler-4XjPOHMM.js";import{p}from"./index-CB9VixeI.js";var m={class:`changes-panel`},h=[`disabled`],g={key:0,role:`alert`},_={key:1},v={key:2},y=[`onToggle`],b=[`onClick`],x={key:0},S={key:1},C={class:`hunk`},w=p(r({__name:`ChangesPanel`,props:{hostId:{},cwd:{},api:{type:Function}},setup(r){let p=r,w=u([]),T=u(``),E=u(!1),D=u(!1),O=0,k=u(new Set);e(()=>O++);async function A(){let e=++O;E.value=!0,T.value=``,w.value=[],D.value=!1,k.value=new Set;try{let t=await p.api(`/hosts/${encodeURIComponent(p.hostId)}/changes?cwd=${encodeURIComponent(p.cwd)}`);if(e!==O)return;w.value=t.files,D.value=!!t.diffTooLarge}catch(t){e===O&&(T.value=t.message)}finally{e===O&&(E.value=!1)}}async function j(e){try{await navigator.clipboard.writeText(e)}catch{T.value=`Could not copy path.`}}return l(()=>[p.hostId,p.cwd],()=>{w.value=[],A()},{immediate:!0}),(e,r)=>(t(),f(`section`,m,[r[0]||=c(`p`,null,`Workspace uncommitted changes · includes changes from all contributors.`,-1),c(`button`,{class:`btn`,disabled:E.value,onClick:A},o(E.value?`Loading…`:`Refresh changes`),9,h),T.value?(t(),f(`p`,g,o(T.value),1)):d(``,!0),D.value?(t(),f(`p`,_,`Diff exceeds the host limit; some changes are omitted.`)):d(``,!0),!E.value&&!T.value&&!w.value.length?(t(),f(`p`,v,`No uncommitted changes.`)):d(``,!0),(t(!0),f(s,null,i(w.value,e=>(t(),f(`details`,{key:e.path,onToggle:t=>t.target.open?k.value.add(e.path):k.value.delete(e.path)},[c(`summary`,null,[n(o(e.oldPath?e.oldPath+` → `:``)+o(e.path)+` `,1),c(`span`,null,`+`+o(e.additions)+` −`+o(e.deletions),1)]),c(`button`,{class:`btn btn-ghost`,onClick:t=>j(e.path)},`Copy path`,8,b),e.status===`binary`?(t(),f(`p`,x,`Binary file changed.`)):e.status===`too_large`?(t(),f(`p`,S,`File diff is too large to display.`)):d(``,!0),k.value.has(e.path)?(t(!0),f(s,{key:2},i(e.hunks,(e,n)=>(t(),f(`pre`,{key:n},[c(`code`,null,[c(`span`,C,`@@ −`+o(e.oldStart)+`,`+o(e.oldCount)+` +`+o(e.newStart)+`,`+o(e.newCount)+` @@
2
+ `,1),(t(!0),f(s,null,i(e.lines,(e,n)=>(t(),f(`span`,{key:n,class:a(e.type)},o(e.type===`add`?`+`:e.type===`remove`?`−`:` `)+o(e.content),3))),128))])]))),128)):d(``,!0)],40,y))),128))]))}}),[[`__scopeId`,`data-v-4de9f4ce`]]);export{w as default};
@@ -0,0 +1,3 @@
1
+ import{C as e,E as t,F as n,H as r,I as i,K as a,N as o,R as s,T as c,X as l,Y as u,_ as d,at as f,b as p,ct as ee,d as m,g as h,h as g,it as te,j as _,k as ne,l as re,m as v,nt as ie,q as y,st as ae,tt as b,v as oe,y as se}from"./vue.runtime.esm-bundler-4XjPOHMM.js";import{E as ce,G as le,U as ue,W as de,X as fe,Y as pe,Z as me,a as he,at as ge,b as _e,c as ve,d as ye,et as be,ft as xe,g as Se,it as Ce,lt as we,n as Te,nt as Ee,ot as De,rt as Oe,ut as ke,v as Ae,w as je,x as Me}from"./MarkdownMessage-CCyi7hfO.js";import{n as Ne,r as Pe,t as Fe}from"./PreCodeBlock.vue_vue_type_style_index_0_lang-n4zE2oPI.js";import{n as Ie,t as x}from"./safeRaf-BDp3SJMs.js";import{o as Le}from"./index-CB9VixeI.js";var S=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())}),Re=!1,ze=null,Be=null,Ve=null;function He(){return S(this,null,function*(){if(Ve)return Ve;Ve=S(null,null,function*(){if(!Be)try{if(Be=function(e){let t=e,n=typeof t?.createCodeBlockRuntime==`function`||typeof t?.useMonaco==`function`?t:e?.default,r=n?.createCodeBlockRuntime??n?.useMonaco;return typeof r==`function`?{createCodeBlockRuntime:e=>r.call(n,e),detectLanguage:(n?.detectLanguage)?.bind(n),preloadStreamDiffs:(n?.preloadStreamDiffs)?.bind(n)}:null}(yield Le(()=>import(`./markstream_markstream-vue-Bj0UewdV.js`),[])),!Be)return null}catch{return null}try{return yield function(e){return S(this,null,function*(){if(!Re)return ze||(ze=S(null,null,function*(){let t=e?.preloadStreamDiffs;typeof t==`function`&&(yield t()),Re=!0}).finally(()=>{ze=null}),ze)})}(Be),de(),Be}catch{return null}});try{return yield Ve}finally{Ve=null}})}var Ue=Object.defineProperty,We=Object.defineProperties,C=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,Ge=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,Ke=(e,t,n)=>t in e?Ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,E=(e,t)=>{for(var n in t||={})Ge.call(t,n)&&Ke(e,n,t[n]);if(w)for(var n of w(t))T.call(t,n)&&Ke(e,n,t[n]);return e},qe=(e,t)=>We(e,C(t)),D=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())}),O={class:`html-preview-frame__header`},Je={class:`html-preview-frame__title`},Ye={class:`html-preview-frame__label`},k=[`sandbox`,`srcdoc`],Xe=Ae(c({__name:`HtmlPreviewFrame`,props:{code:{},isDark:{type:Boolean},htmlPreviewAllowScripts:{type:Boolean},htmlPreviewSandbox:{},onClose:{type:Function},title:{}},setup(e){let t=e,{t:r}=Me(),a=g(()=>{let e=t.code||``,n=e.trim().toLowerCase();return n.startsWith(`<!doctype`)||n.startsWith(`<html`)||n.startsWith(`<body`)?e:`<!doctype html>\n<html lang="en">\n <head>\n <meta charset="utf-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1" />\n <style>\n html, body {\n margin: 0;\n padding: 0;\n height: 100%;\n background-color: ${t.isDark?`#020617`:`#ffffff`};\n color: ${t.isDark?`#e5e7eb`:`#020617`};\n }\n body {\n font-family: system-ui, -apple-system, BlinkMacSystemFont, 'SF Pro Text', ui-sans-serif, sans-serif;\n }\n </style>\n </head>\n <body>\n ${e}\n </body>\n</html>`}),o=g(()=>{return e=t.htmlPreviewSandbox,n=t.htmlPreviewAllowScripts,typeof e==`string`?e:e===void 0&&!0===n?`allow-scripts`:``;var e,n});function c(e){var n;e.key!==`Escape`&&e.key!==`Esc`||(n=t.onClose)==null||n.call(t)}return n(()=>{typeof window<`u`&&window.addEventListener(`keydown`,c)}),i(()=>{typeof window<`u`&&window.removeEventListener(`keydown`,c)}),(e,n)=>(s(),d(v,{to:`body`},[h(`div`,{class:f([`markstream-vue`,{dark:t.isDark}])},[h(`div`,{class:`html-preview-frame__backdrop`,onClick:n[2]||=e=>t.onClose?.call(t)},[h(`div`,{class:`html-preview-frame`,onClick:n[1]||=m(()=>{},[`stop`])},[h(`div`,O,[h(`div`,Je,[n[3]||=h(`span`,{class:`html-preview-frame__dot`},null,-1),h(`span`,Ye,ee(t.title||te(r)(`common.preview`)||`Preview`),1)]),h(`button`,{type:`button`,class:`html-preview-frame__close`,onClick:n[0]||=e=>t.onClose?.call(t)},` × `)]),h(`iframe`,{class:`html-preview-frame__iframe`,sandbox:o.value,referrerpolicy:`no-referrer`,srcdoc:a.value},null,8,k)])])],2)]))}}),[[`__scopeId`,`data-v-24e66176`]]),Ze=[`data-markstream-enhanced`,`data-markstream-enhancement-state`,`data-markstream-code-block-state`,`data-markstream-pending`,`data-markstream-viewport-pending`],Qe={class:`code-header-main`},$e=[`innerHTML`],et={class:`code-header-copy`},tt={class:`code-header-title`},nt={key:0,class:`code-header-caption`},rt=[`data-markstream-host-hidden`],A=Ae(c({__name:`CodeBlockNode`,props:{node:{},codeBlockOptions:{},clipboardWriter:{},showLineNumbers:{type:Boolean,default:void 0},isDark:{type:Boolean,default:!1},loading:{type:Boolean,default:!0},stream:{type:Boolean,default:!0},theme:{},darkTheme:{default:void 0},lightTheme:{default:void 0},isShowPreview:{type:Boolean,default:!0},enableFontSizeControl:{type:Boolean,default:!0},minWidth:{default:void 0},maxWidth:{default:void 0},themes:{},showPreviewButton:{type:Boolean,default:!0},showCollapseButton:{type:Boolean,default:!0},showFontSizeButtons:{type:Boolean,default:!0},showTooltips:{type:Boolean},htmlPreviewAllowScripts:{type:Boolean},htmlPreviewSandbox:{},customId:{},showHeader:{type:Boolean,default:!0},showCopyButton:{type:Boolean,default:!0},showExpandButton:{type:Boolean,default:!0},estimatedHeightPx:{},estimatedContentHeightPx:{},estimatedDiffInline:{type:Boolean}},emits:[`previewCode`,`copy`],setup(c,{emit:m}){let v=c,de=m,Ae=g(()=>v.showLineNumbers??!0!==v.codeBlockOptions?.disableLineNumbers),Le=a(),S=ne(fe,null),Re=ne(`markstreamHostScrollManaged`,null),ze=ne(Se,void 0),Be=g(()=>ve(v,Le)),Ve=t(),Ue=g(()=>{let e=Ve?.vnode.props;return!(!e||!e.onPreviewCode&&!e[`onPreview-code`])}),{t:We}=Me(),C=b(null),w=b(null),Ge=b(!1),T=b(Hr(v.node.language,v.node.code,Vr())),Ke=g(()=>me(T.value)),O=g(()=>Ke.value===`plaintext`?`text`:Ke.value),Je=g(()=>Ke.value===`plaintext`),Ye=b(!1),k=b(!1),A=b(!1),j=b(!1),M=b(!1),it=b(!1),N=!1,at=!1,ot=null,st=null,ct=null,lt=0,ut=!1,dt=``,ft=b(null),pt=0,mt=!1,ht=Te(),gt=ce(),_t=ye(),vt=ie(null),P=b(typeof window>`u`||!_t.value),yt=t()?.vnode.el?.textContent??``,bt=typeof window<`u`&&String(v.node.code??``).length>0&&yt.includes(String(v.node.code)),xt=b(!bt);n(()=>{xt.value=!0}),typeof window<`u`&&y([()=>w.value,_t],([e,t],n,r)=>{var i;if((i=vt.value)==null||i.destroy(),vt.value=null,!t||P.value)return void(P.value=!0);if(!e)return void(P.value=!1);let a=!0,o=gt?.value.heavyBlockMargin??gt?.value.rootMargin??`0px`,s=ht(e,{rootMargin:o,allowIdle:!1});vt.value=s,P.value=P.value||s.isVisible.value,s.whenVisible.then(()=>{a&&vt.value===s&&(P.value=!0)}).catch(()=>{}),r(()=>{a=!1,s.destroy(),vt.value===s&&(vt.value=null)})},{immediate:!0}),o(()=>{var e;N=!0,function(){let e=dt;S&&e&&(dt=``,S.markSettled(e))}(),(e=vt.value)==null||e.destroy(),vt.value=null});let F=null,St=null,Ct=()=>{},wt=()=>{},Tt=()=>{},Et=()=>{},Dt=()=>null,I=()=>({getModel:()=>({getLineCount:()=>1}),getOption:()=>14,updateOptions:()=>{}}),L=()=>({getModel:()=>({getLineCount:()=>1}),getOption:()=>14,updateOptions:()=>{}}),Ot=()=>{},kt=()=>{},At=()=>{},jt=null,R=null,Mt=null,Nt=null,Pt=()=>String(v.node.language??`plaintext`),Ft=()=>D(null,null,function*(){}),It=!1,Lt=null,Rt=[],zt=[],Bt=null,Vt=null,z=g(()=>Oe(v.node)),Ht=b({removed:0,added:0}),Ut=g(()=>`-${Ht.value.removed} +${Ht.value.added}`);function Wt(e,t){return{original:e,updated:t}}function Gt(e){return String(e??``).replace(/\r\n$|\n$|\r$/,``)}function Kt(e){return String(e?.message??e).includes(`no diff result available`)}function qt(){if(!$())try{let e=At();e&&typeof e.catch==`function`&&e.catch(e=>{Kt(e)})}catch(e){Kt(e)}}let Jt=g(()=>{let e=E({},v.codeBlockOptions||{});for(let t of[`theme`,`themes`,`themeType`,`language`,`languages`,`stream`,`disableFileHeader`,`onThemeChange`,`renderCustomHeader`,`renderHeaderMetadata`,`renderHeaderPrefix`,`maxHeight`,`padding`,`tabSize`])delete e[t];if(!z.value)return e;let t=e.parseDiffOptions&&typeof e.parseDiffOptions==`object`?e.parseDiffOptions:{},n={diffStyle:`split`,expandUnchanged:!1,collapsedContextThreshold:5,hunkSeparators:`line-info`,parseDiffOptions:{context:2}};return qe(E(E({},n),e),{parseDiffOptions:E(E({},n.parseDiffOptions),t)})}),Yt=g(()=>{return(v.theme===void 0?!fi(v.darkTheme,v.lightTheme):(e=v.theme)&&typeof e==`object`&&`light`in e&&`dark`in e)?!!v.isDark:function(e){let t=di(e)??``;return Ce(t,!0===v.isDark)}(pi());var e}),Xt=g(()=>(z.value,Yt.value?`dark`:`light`)),Zt=g(()=>z.value?Xt.value===`dark`:Yt.value),B=g(()=>ke({darkTheme:v.darkTheme,isDark:v.isDark,lightTheme:v.lightTheme,theme:v.theme,themes:v.themes})),Qt=g(()=>z.value?`diff`:`single`),$t=b(Qt.value),V=b(!1),H=b(!1),en=b(!1),U=b(!1),tn=b(null),nn=b(0),rn=b(0),an=b(!1),on=null,sn=!1,cn=null,ln=!1,un=g(()=>!!z.value&&Jt.value?.diffStyle===`unified`),dn=g(()=>De(Jt.value));function fn(e){return!0===Re?.value||!!e&&(!!e.closest(`[data-markstream-virtual-timeline="1"], .markstream-virtual-timeline`)||!!e.closest(`.vue-recycle-scroller, [data-virtualizer], [data-virtual-scroll-root]`))}let pn=g(()=>fn(w.value)),mn=g(()=>!(V.value||!U.value&&H.value)),hn=g(()=>mn.value),gn=g(()=>mn.value&&!en.value),_n=g(()=>!V.value&&!U.value&&mn.value),vn=g(()=>H.value&&!V.value?`ready`:U.value?`fallback`:`pending`),yn=b(!1),W=g(()=>Gt(v.node.code)),bn=g(()=>z.value?!0===v.node.diff?v.node:qe(E({},v.node),{diff:!0}):W.value===v.node.code?v.node:qe(E({},v.node),{code:W.value}));function xn(e){let t=e.detectLanguage;typeof t==`function`&&(Pt=t),Vt=e,Bt=gi();let n=e.createCodeBlockRuntime(Bt);return!!n&&(F=n.createEditor||F,St=n.createDiffEditor||St,Ct=n.updateCode||Ct,wt=n.updateDiff||wt,Tt=n.finalizeCode||Tt,Et=n.finalizeDiff||Et,Dt=n.getEditor||Dt,I=n.getEditorView||I,L=n.getDiffEditorView||L,Ot=n.cleanupEditor||Ot,kt=n.safeClean||n.cleanupEditor||kt,At=n.refreshDiffPresentation||At,Ft=n.setTheme||Ft,jt=n.whenVisualReady||null,it.value=!0,!0)}let G=b(typeof v.codeBlockOptions?.fontSize==`number`?v.codeBlockOptions.fontSize:NaN),K=b(G.value),Sn=b(null),Cn=b(null),wn=b(null),Tn=b(null),En=g(()=>{let e=G.value,t=K.value;return typeof e==`number`&&Number.isFinite(e)&&e>0&&typeof t==`number`&&Number.isFinite(t)&&t>0}),Dn=g(()=>{let e=v.codeBlockOptions?.fontSize;if(typeof e==`number`&&Number.isFinite(e)&&e>0)return e;let t=K.value;return typeof t==`number`&&Number.isFinite(t)&&t>0?t:12}),On=g(()=>{let e=v.codeBlockOptions?.lineHeight;return typeof e==`number`&&Number.isFinite(e)&&e>0?e:Dn.value===12?18:Math.max(12,Math.round(1.5*Dn.value))}),kn=g(()=>On.value),An=g(()=>{let e=v.codeBlockOptions?.tabSize;return typeof e==`number`&&Number.isFinite(e)&&e>0?e:4}),jn=g(()=>{let e=v.codeBlockOptions?.padding,t=typeof e==`number`&&Number.isFinite(e)&&e>=0?e:8;return{top:t,bottom:t}}),Mn=g(()=>qe(E({},xe(v.codeBlockOptions)),{fontSize:Dn.value,lineHeight:kn.value,maxHeight:zr(),padding:jn.value.top,paddingBottom:jn.value.bottom,tabSize:An.value})),Nn=g(()=>{let e=v.estimatedContentHeightPx;return typeof e==`number`&&Number.isFinite(e)&&e>0?e:null});function Pn(e){if(e==null)return null;let t=Math.ceil(e);return!Number.isFinite(t)||t<=0?null:Math.min(t,Math.ceil(zr()))}function Fn(){return!z.value&&!1!==v.stream&&!1!==v.loading}let In=b(Fn());function Ln(){return Fn()||In.value}let Rn=g(()=>z.value?null:Nn.value==null||Ln()?Math.ceil((e=>{let t=String(e??``);if(!t)return 1;let n=1;for(let e=0;e<t.length;e++)t[e]===`
2
+ `?n++:t[e]===`\r`&&(n++,t[e+1]===`
3
+ `&&e++);return n})(W.value)*kn.value+1):null),zn=g(()=>{if(z.value)return null;let e=Nn.value;return e==null||Ln()?Pn(Rn.value):Pn(e)}),Bn=g(()=>{let e=v.estimatedHeightPx;return typeof e==`number`&&Number.isFinite(e)&&e>0?e:null}),Vn=b(null);function Hn(){let e=Vn.value;return typeof e==`number`&&Number.isFinite(e)&&e>0?Math.round(e):null}let Un=g(()=>Hn()??(!z.value&&an.value?null:mn.value||!H.value?zn.value:null));function Wn(e){let t=e?`hsl(152 42% 60%)`:`var(--diff-added-fg)`,n=e?`hsl(0 58% 58%)`:`var(--diff-removed-fg)`,r=e?`color-mix(in lab, #121212 80%, #4d9375)`:`color-mix(in lab, #ffffff 88%, #1e754f)`,i=e?`color-mix(in lab, #121212 80%, #cb7676)`:`color-mix(in lab, #ffffff 88%, #ab5959)`;return{"--markstream-diff-line-number-bg":`var(--markstream-diff-editor-bg)`,"--markstream-diff-added-fg":t,"--markstream-diff-removed-fg":n,"--markstream-diff-added-line":r,"--markstream-diff-removed-line":i,"--markstream-diff-added-line-fill":r,"--markstream-diff-added-number-fill":e?`color-mix(in lab, #121212 85%, #4d9375)`:`color-mix(in lab, #ffffff 91%, #1e754f)`,"--markstream-diff-removed-line-fill":i,"--markstream-diff-removed-number-fill":e?`color-mix(in lab, #121212 85%, #cb7676)`:`color-mix(in lab, #ffffff 91%, #ab5959)`,"--markstream-diff-added-gutter":`linear-gradient(90deg, ${t} 0 4px, transparent 4px 100%)`,"--markstream-diff-removed-gutter":`linear-gradient(90deg, ${n} 0 4px, transparent 4px 100%)`,"--markstream-diff-added-inline":e?`hsl(152 42% 60% / 0.28)`:`var(--diff-added-inline-bg)`,"--markstream-diff-removed-inline":e?`hsl(0 58% 58% / 0.28)`:`var(--diff-removed-inline-bg)`}}let Gn=g(()=>{let e=Pn(Nn.value),t=Pn(Rn.value),n=Ln(),r=E({},z.value||e==null||n?z.value||t==null?{}:{minHeight:`${t}px`}:{height:`${e}px`,minHeight:`${e}px`});if(r[`--markstream-code-fallback-bg`]=B.value.background,r[`--markstream-code-fallback-fg`]=B.value.foreground,B.value.builtin&&(r[`--markstream-code-theme-bg`]=B.value.background,r[`--markstream-code-theme-fg`]=B.value.foreground,r[`--markstream-code-theme-line-number`]=B.value.lineNumber),r[`--markstream-pre-line-number-top`]=`${jn.value.top}px`,r[`--markstream-pre-line-number-left`]=`0px`,r[`--markstream-pre-line-number-padding-left`]=`2ch`,r[`--markstream-pre-line-number-padding-right`]=`1ch`,r[`--markstream-pre-line-number-separator-width`]=`2px`,z.value){r[`--markstream-pre-diff-line-height`]=`${kn.value}px`,r[`--markstream-pre-diff-pane-bottom-padding`]=(un.value,`0px`);let e=Tn.value;e!=null&&e>0&&(r.height=`${e}px`,r.minHeight=`${e}px`,r.maxHeight=`${e}px`),Object.assign(r,Wn(Zt.value))}return r}),Kn=g(()=>Un.value!=null&&(!H.value||Hn()!=null)),qn=g(()=>{let e=Un.value;if(e==null)return null;if(z.value)return Math.ceil(e);let t=Bn.value,n=Nn.value;if(t==null||n==null)return Math.ceil(e);let r=Math.max(0,Math.ceil(t)-Math.ceil(n));return Math.ceil(e+r)}),Jn=g(()=>{if(z.value&&mn.value)return{};let e=Un.value;return Kn.value&&e!=null?{minHeight:`${e}px`}:{}});function Yn(){Vn.value=null}function Xn(){var e,t,n,r;let i=w.value?.querySelector(`pre.code-pre-fallback`),a=L(),o=i?.scrollTop??0;(t=(e=(a?.getOriginalEditor)?.call(a))?.setScrollTop)==null||t.call(e,o),(r=(n=(a?.getModifiedEditor)?.call(a))?.setScrollTop)==null||r.call(n,o)}function Zn(){return D(this,null,function*(){return z.value?(vr(),er(),X(!0),Xn(),Z(),en.value=!0,yield _(),X(!0),yield q(),X(!0),gr(),er(),!!(yield function(){return D(this,null,function*(){if(!z.value)return!0;for(let e=0;e<4;e++){let e=er();X(!0),Qn(e),$n(e),yield _(),yield q();let t=w.value?.querySelector(`pre.code-pre-fallback`);if(!t)return!1;if(e==null)return jr();let n=t.getBoundingClientRect().height;if(n>0&&Math.abs(n-e)<=2)return!0}return!1})}())&&(H.value=!0,yield _(),er(),X(!0),gr(),Z(),x(()=>{N||x(()=>{N||(function(){let e=w.value?.querySelector(`.code-block-shell-content`),t=w.value?.querySelector(`.code-editor-layer`);e&&t&&(t.style.removeProperty(`height`),t.style.removeProperty(`min-height`),e.style.removeProperty(`height`),e.style.removeProperty(`min-height`))}(),Q(!0))})}),Q(),!0)):!(jt&&!(yield jt())||(en.value=!0,yield _(),X(!0),H.value=!0,yield _(),Q(),0))})}function Qn(e){if(!z.value)return;let t=C.value,n=w.value?.querySelector(`pre.code-pre-fallback`);if(!t||!n)return;let r=e??Number.parseFloat(t.style.height||``);if(!Number.isFinite(r)||r<=0)return;let i=Math.ceil(r),a=`${i}px`;Tn.value=i;let o=w.value;o&&(o.dataset.markstreamDiffHandoffHeight=a),n.dataset.markstreamDiffHandoffHeight=a,n.style.setProperty(`height`,a),n.style.setProperty(`min-height`,a)}function $n(e){if(!z.value)return;let t=w.value?.querySelector(`.code-block-shell-content`),n=w.value?.querySelector(`.code-editor-layer`);if(!t||!n)return;let r=typeof e==`number`&&Number.isFinite(e)&&e>0?Math.ceil(e):Number.parseFloat(C.value?.style.height||``);if(!Number.isFinite(r)||r<=0)return;let i=`${r}px`;n.style.height=i,n.style.minHeight=i,t.style.height=i,t.style.minHeight=i}function er(){let e=C.value;if(e&&jr(e)){Z();let t=mr(e);if(t!=null&&t>0){let n=Math.ceil(t),r=Math.ceil(zr()),i=Math.min(n,r),a=`${i}px`;return e.style.height=a,e.style.minHeight=`0px`,e.style.maxHeight=`${r}px`,e.style.overflow=n>r+1?`auto`:`hidden`,mn.value&&(Tn.value=i,Qn(i)),Dr(),i}return Y({preferModelDiffHeight:!0}),Qn(),Dr(),Number.parseFloat(e.style.height||``)||null}return vr()}function tr(e,t=!1,n={}){let r=Math.ceil(e),i=Hn();if(i==null)return r;let a=!0===n.allowBelowEstimatedFloor;return r>=i||a?((t||a)&&M.value&&Yn(),r):i}function q(){return new Promise(e=>{let t=!1,n=null,r=null,i=()=>{t||(t=!0,r!=null&&globalThis.clearTimeout(r),n!=null&&Ie(n),e())};r=globalThis.setTimeout(i,50),n=x(i)})}function nr(){try{let e=C.value;if(!e)return null;let t=e.querySelector(`.stream-diffs-shell .stream-diffs-surface`)??e.querySelector(`.stream-diffs-shell`);if(t){let e=Math.ceil(t.getBoundingClientRect().height);if(e>0)return e}}catch{}return null}function rr(){var e;try{let t=z.value?((e=L())?.getModifiedEditor)?.call(e)??L():I(),n=Dt()?.EditorOption?.fontInfo;if(t&&n!=null){let e=t.getOption?.call(t,n)?.fontSize;if(typeof e==`number`&&Number.isFinite(e)&&e>0)return e}}catch{}try{let e=C.value;if(e){let t=e.querySelector(`.stream-diffs-shell .stream-diffs-surface`)??e.querySelector(`.stream-diffs-shell`);if(t)try{if(typeof window<`u`&&typeof window.getComputedStyle==`function`){let e=window.getComputedStyle(t).fontSize,n=e&&e.match(/^(\d+(?:\.\d+)?)/);if(n)return Number.parseFloat(n[1])}}catch{}}}catch{}return null}function ir(e){try{let t=Dt()?.EditorOption?.lineHeight;if(t!=null){let n=(e?.getOption)?.call(e,t);if(typeof n==`number`&&n>0)return n}}catch{}let t=nr();if(t&&t>0)return t;let n=Number.isFinite(K.value)&&K.value>0?K.value:14;return Math.max(12,Math.round(1.35*n))}function ar(){let e=v.codeBlockOptions?.padding;return typeof e==`number`&&Number.isFinite(e)?2*Math.max(0,e):z.value?24:0}function or(e){return!!Je.value||!!e&&($(e)||jt!=null)}function sr(){z.value?Ht.value=Ee(String(v.node.originalCode??``),String(v.node.updatedCode??``)):Ht.value={removed:0,added:0}}function cr(){if(Number.isFinite(K.value)&&K.value>0&&Number.isFinite(G.value))return K.value;if(typeof v.codeBlockOptions?.fontSize==`number`)return G.value=v.codeBlockOptions.fontSize,K.value=v.codeBlockOptions.fontSize,v.codeBlockOptions.fontSize;let e=rr();return e&&e>0?(G.value=e,K.value=e,e):(G.value=12,K.value=12,12)}function lr(){let e=cr(),t=Math.min(36,e+1);K.value=t}function ur(){let e=cr(),t=Math.max(10,e-1);K.value=t}function dr(){cr(),Number.isFinite(G.value)&&(K.value=G.value)}function fr(){var e,t,n,r,i;try{let a=z.value?L():null,o=z.value?a:I();if(!o)return null;if(a?.getOriginalEditor&&a?.getModifiedEditor){let i=a.getOriginalEditor?.call(a),o=a.getModifiedEditor?.call(a);(e=i?.layout)==null||e.call(i),(t=o?.layout)==null||t.call(o);let s=(i?.getContentHeight)?.call(i)||0,c=(o?.getContentHeight)?.call(o)||0,l=Math.max(s,c);if(l>0)return Math.ceil(l);let u=((n=(i?.getModel)?.call(i))?.getLineCount)?.call(n)||1,d=((r=(o?.getModel)?.call(o))?.getLineCount)?.call(r)||1,f=Math.max(u,d),p=Math.max(ir(i),ir(o)),ee=ar();return Math.ceil(f*p+ee+0)}if(o?.getContentHeight){(i=o?.layout)==null||i.call(o);let e=o.getContentHeight();if(e>0)return z.value||(an.value=!0),Math.ceil(e)}let s=(o?.getModel)?.call(o),c=1;s&&typeof s.getLineCount==`function`&&(c=s.getLineCount());let l=ir(o);return Math.ceil(c*(l+1.5)+0)}catch{return null}}function pr(){var e;if(z.value)return!1;try{let t=((e=I())?.getContentHeight)?.call(e),n=typeof t==`number`&&Number.isFinite(t)&&t>0;return n&&(an.value=!0),n}catch{return!1}}function mr(e){if(typeof window>`u`)return null;try{if(window.getComputedStyle(e).display===`none`)return null;let t=e.querySelector(`diffs-container`);if(t instanceof HTMLElement){let e=t.getBoundingClientRect();if(e.height>0)return Math.ceil(e.height)}let n=e.querySelector(`.stream-diffs-shell`);if(n){let e=n.getBoundingClientRect();if(e.height>0)return Math.ceil(e.height)}return null}catch{return null}}function hr(e){let t=String(e??``).trim(),n=t.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i)?.[1];if(n){let e=n.length===3?n.split(``).map(e=>`${e}${e}`).join(``):n;return .2126*Number.parseInt(e.slice(0,2),16)+.7152*Number.parseInt(e.slice(2,4),16)+.0722*Number.parseInt(e.slice(4,6),16)}let r=t.match(/\d+(?:\.\d+)?/g);if(!r||r.length<3)return null;let[i,a,o]=r.slice(0,3).map(Number);return .2126*i+.7152*a+.0722*o}function gr(){var e;if(_r())return;let t=rr();t&&t>0&&(Sn.value=t,K.value=t,G.value=t);try{let t=ir(z.value?((e=L())?.getModifiedEditor)?.call(e)??L():I());t&&t>0&&(Cn.value=t)}catch{}try{let e=nr();e&&e>0&&(Cn.value=e)}catch{}}function _r(){return z.value&&hn.value}function vr(){if(!mn.value)return null;let e=C.value,t=w.value?.querySelector(`pre.code-pre-fallback`);if(!e||!t)return null;let n=Math.ceil(t.getBoundingClientRect().height),r=z.value?mr(e):null,i=Math.max(n,r!=null&&r>0?Math.ceil(r):0),a=Math.ceil(zr()),o=Math.min(i,a);return!Number.isFinite(o)||o<=0?null:(z.value&&o>n&&(Tn.value=o),e.style.height=`${o}px`,e.style.minHeight=`${o}px`,e.style.maxHeight=`${a}px`,e.style.overflow=i>a+1?`auto`:`hidden`,o)}function yr(){let e=C.value,t=w.value;if(!e||!t)return;let n=e;n.style.setProperty(`--markstream-diff-metadata-bg`,B.value.background),n.style.setProperty(`--markstream-diff-metadata-fg`,B.value.lineNumber),n.style.setProperty(`--diffs-tab-size`,String(An.value)),n.style.setProperty(`--diffs-scrollbar-gutter-override`,`0px`),typeof v.codeBlockOptions?.padding==`number`?n.style.setProperty(`--diffs-gap-block`,`${jn.value.top}px`):n.style.removeProperty(`--diffs-gap-block`);let r=e.querySelector(`.stream-diffs-shell`)||e,i=r,a=r,o=null,s=null,c=null;try{typeof window<`u`&&typeof window.getComputedStyle==`function`&&(o=window.getComputedStyle(r),s=i===r?o:window.getComputedStyle(i),c=a===r?o:window.getComputedStyle(a))}catch{o=null,s=null,c=null}let l=String(o?.getPropertyValue(`--vscode-editor-foreground`)??``).trim(),u=String(o?.getPropertyValue(`--vscode-editor-background`)??``).trim(),d=String(o?.getPropertyValue(`--vscode-editor-selectionBackground`)??o?.getPropertyValue(`--vscode-editor-hoverHighlightBackground`)??``).trim(),f=l||String(c?.color??o?.color??``).trim(),p=u||String(s?.backgroundColor??o?.backgroundColor??``).trim(),ee=function(){var e;try{let t=z.value?((e=L())?.getModifiedEditor)?.call(e)??L():I(),n=Dt()?.EditorOption?.fontInfo;if(t&&n!=null){let e=t.getOption?.call(t,n)?.typicalHalfwidthCharacterWidth;if(typeof e==`number`&&Number.isFinite(e)&&e>0)return e}}catch{}return null}();if(ee!=null&&(wn.value=ee),z.value){let e=(e,r)=>{r?(t.style.setProperty(e,r),n.style.setProperty(e,r)):(t.style.removeProperty(e),n.style.removeProperty(e))};for(let[n,r]of Object.entries(Wn(t.classList.contains(`is-dark`))))e(n,r);f?(t.style.setProperty(`--markstream-diff-editor-fg`,f),n.style.setProperty(`--vscode-editor-foreground`,f)):(t.style.removeProperty(`--markstream-diff-editor-fg`),n.style.removeProperty(`--vscode-editor-foreground`)),p?(t.style.setProperty(`--markstream-diff-editor-bg`,p),t.style.setProperty(`--markstream-diff-panel-bg`,p),t.style.setProperty(`--markstream-diff-panel-bg-soft`,p),t.style.setProperty(`--markstream-diff-panel-bg-strong`,p),n.style.setProperty(`--vscode-editor-background`,p),n.style.backgroundColor=p):(t.style.removeProperty(`--markstream-diff-editor-bg`),t.style.removeProperty(`--markstream-diff-panel-bg`),t.style.removeProperty(`--markstream-diff-panel-bg-soft`),t.style.removeProperty(`--markstream-diff-panel-bg-strong`),n.style.removeProperty(`--vscode-editor-background`),n.style.backgroundColor=``),d?n.style.setProperty(`--vscode-editor-selectionBackground`,d):n.style.removeProperty(`--vscode-editor-selectionBackground`)}else{if(function(e,t,n){if(!Je.value)return!1;let r=hr(e),i=hr(t);return n?r!=null&&r>170||i!=null&&i<110:r!=null&&r<85||i!=null&&i>190}(p,f,t.classList.contains(`is-dark`)))return n.style.removeProperty(`--vscode-editor-foreground`),n.style.removeProperty(`--vscode-editor-background`),void n.style.removeProperty(`--vscode-editor-selectionBackground`);f&&n.style.setProperty(`--vscode-editor-foreground`,f),p&&n.style.setProperty(`--vscode-editor-background`,p),d&&n.style.setProperty(`--vscode-editor-selectionBackground`,d)}}y(()=>[v.stream,v.loading,v.node.loading,z.value],([e,t,n,r])=>{r||!1===e||!1===t||In.value?(r||!1===e)&&In.value&&(In.value=!1):(In.value=!0,Yn())},{immediate:!0});let br=0,xr=0,Sr=/auto|scroll|overlay/i;function J(e,t,n){if(typeof window>`u`||z.value||function(e){return pn.value||fn(e)}(e))return;let r=Math.ceil(n)-Math.ceil(t);if(Math.abs(r)<=1)return;let i=function(e){if(typeof window>`u`)return null;let t=e?.ownerDocument??document,n=t.scrollingElement||t.documentElement||t.body,r=e?.parentElement??null;for(;r&&r!==t.body&&r!==n;){let e=window.getComputedStyle(r),t=(e.overflowY||``).toLowerCase(),n=(e.overflow||``).toLowerCase();if(Sr.test(t)||Sr.test(n))return r;r=r.parentElement}return n}(e);if(!i)return;let a=e.ownerDocument??document,o=i===a.body||i===a.documentElement||i===a.scrollingElement,s=o?0:i.getBoundingClientRect().top;e.getBoundingClientRect().top-s>=0||(o&&typeof window.scrollBy==`function`?window.scrollBy(0,r):i.scrollTop+=r)}function Cr(){try{let e=C.value;if(!e)return;let t=e.getBoundingClientRect().height,n=fr();if(n!=null&&n>0){let r=tr(n,!0,{allowBelowEstimatedFloor:!z.value&&M.value&&pr()}),i=Hn();e.style.minHeight=i==null?`0px`:`${i}px`,e.style.height=`${r}px`,e.style.maxHeight=`none`,e.style.overflow=`visible`,J(e,t,r);return}let r=Hn();r!=null&&(e.style.minHeight=`${r}px`,e.style.height=`${r}px`,e.style.maxHeight=`none`,e.style.overflow=`visible`,J(e,t,r))}catch{}}function wr(){for(var e,t;Rt.length>0;)try{(t=(e=Rt.pop())?.dispose)==null||t.call(e)}catch{}ot!=null&&(Ie(ot),ot=null),st!=null&&(Ie(st),st=null),ct!=null&&(Ie(ct),ct=null),lt=0,ut=!1}function Tr(){for(var e;zt.length>0;)try{(e=zt.pop())==null||e()}catch{}}function Y(e=!1){k.value||(Ye.value?Cr():function(e={}){try{let t=C.value;if(!t)return;let n=t.getBoundingClientRect().height,r=Math.ceil(n||0),i=zr(),a=r,o=Number.parseFloat(t.style.height||``),s=a>0?a:Number.isFinite(o)&&o>0?Math.ceil(o):0,c=z.value?function(){var e,t;if($())return null;try{let n=L(),r=(n?.getOriginalEditor)?.call(n),i=(n?.getModifiedEditor)?.call(n);if(!r||!i)return null;let a=((e=r.getModel?.call(r))?.getLineCount)?.call(e)||1,o=((t=i.getModel?.call(i))?.getLineCount)?.call(t)||1,s=Math.max(a,o),c=Math.max(ir(r),ir(i)),l=ar(),u=Math.max(r.getContentHeight?.call(r)??0,i.getContentHeight?.call(i)??0);return Math.ceil(Math.max(u,s*c+l+0))}catch{return null}}():null,l=z.value&&jr(t);if(pt>0&&(pt--,ft.value!=null))return void J(t,n,Or(t,ft.value,i,{preserveScrollableOverflow:Ar(t)}));if(z.value&&!l&&mn.value){let e=vr();if(e!=null){let r=Or(t,e,i,{allowBelowEstimatedFloor:!0});X(!0),J(t,n,r);return}}let u=z.value&&!0===e.preferModelDiffHeight,d=z.value?mr(t):null,f=!z.value&&M.value&&pr(),p=z.value&&!1!==v.loading&&(d!=null||c!=null&&a>0&&c<a-1),ee=c!=null,m;if(z.value){if(u){let e=c!=null&&!1===v.loading&&s>0&&c<s-1;m=!1===v.loading&&d!=null?c==null?d:Math.max(d,c):e?c:d!=null&&c!=null?Math.max(d,c,!1===v.loading?0:s):Math.max(d??0,c??0,!1===v.loading?0:s)||null}else m=un.value&&d!=null||d!=null?ee?Math.max(d,c):d:z.value&&!1!==v.loading?c!=null&&s>0&&c<s-1?c:s>0?s:null:c}else m=fr();if(z.value&&m!=null&&s>0&&(!1!==v.loading||!0===e.holdCurrentDiffHeight)&&(m=Math.max(m,s)),m!=null&&m>0)return void J(t,n,Or(t,m,i,{clearEstimatedFloor:!0,allowBelowEstimatedFloor:f||p,preserveScrollableOverflow:Ar(t),renderedStreamingDiffHeight:d}));if(ft.value!=null)return void J(t,n,Or(t,ft.value,i,{preserveScrollableOverflow:Ar(t)}));let h=z.value&&!1!==v.loading?a:Math.max(a,c!=null&&c>0?c:0);if(h>0)return void J(t,n,Or(t,h,i));let g=Hn();if(!(g==null||z.value&&!1!==v.loading&&l))return void J(t,n,Or(t,g,i));let te=Number.parseFloat(t.style.height);!Number.isNaN(te)&&te>0?J(t,n,Or(t,te,i)):z.value||J(t,n,Or(t,i,i))}catch{}}(typeof e==`object`?e:{}))}function Er(){br=0,xr=0}function X(e=!1){if(k.value)return;let t=C.value;if(!t)return;let n=z.value?L():I();if(n&&typeof n.layout==`function`)try{let r=t.getBoundingClientRect?.call(t),i=Math.ceil((r?.width??0)||t.clientWidth||0),a=Math.ceil((r?.height??0)||t.clientHeight||Number.parseFloat(t.style.height||``)||0);if(i>0&&a>0){if(!e&&i===br&&a===xr)return;br=i,xr=a,n.layout({width:i,height:a})}else Er(),n.layout()}catch{}}function Z(){Tr()}function Q(e=!1){if(N||ot!=null)return;let t=()=>{N||(Z(),Y(e),X())};ot=x(()=>{ot=null,t(),st=x(()=>{st=null,t()})}),Dr()}function Dr(e=!1){if(!z.value||N||!e&&!1===v.loading||(ut||=e,lt=Math.max(lt,e?18:6),ct!=null))return;let t=()=>{if(ct=null,!z.value||N||lt<=0||!ut&&!1===v.loading)return lt=0,void(ut=!1);lt--,Z(),Y({preferModelDiffHeight:!0,holdCurrentDiffHeight:ut}),X(),lt>0?ct=x(t):ut=!1};ct=x(t)}function Or(e,t,n,r={}){var i;let a=z.value&&!1!==v.loading,o=`renderedStreamingDiffHeight`in r?a&&(i=r.renderedStreamingDiffHeight)!=null?i:null:a?mr(e):null,s=o!=null&&o>t+1?o:t,c=Math.min(s,n),l=!0===r.allowBelowEstimatedFloor,u=tr(c,!0===r.clearEstimatedFloor,{allowBelowEstimatedFloor:l}),d=Hn();e.style.minHeight=d==null||l?`0px`:`${Math.min(d,Math.ceil(n))}px`,e.style.height=`${u}px`,e.style.maxHeight=`${Math.ceil(n)}px`;let f=!0===r.preserveScrollableOverflow||s>n+1||kr(e,u);return e.style.overflow=f?`auto`:`hidden`,u}function kr(e,t=0){let n=Math.ceil(e.getBoundingClientRect?.call(e).height||0),r=Math.max(t,e.clientHeight||0,n);return r>0&&e.scrollHeight>r+1}function Ar(e){return mt||kr(e,ft.value??0)}function jr(e=C.value){return $(e)}function Mr(e=C.value){return $(e)}function Nr(){var e;if($())return!0;let t=((e=I())?.getModel)?.call(e);return typeof t?.getValue==`function`&&t.getValue()===W.value}function $(e=C.value){return!!e?.querySelector(`diffs-container`)}function Pr(){return!1!==v.loading||H.value}function Fr(){let e=L();return typeof e?.getOriginalEditor==`function`||typeof e?.getModifiedEditor==`function`||typeof e?.getLineChanges==`function`}function Ir(){return D(this,null,function*(){if(!z.value)return!0;for(let e=0;e<30;e++){if(N)return!1;if($())return yield _(),yield q(),!N&&$();yield _(),yield q()}return!1})}let Lr=``;function Rr(e,t,n){return D(this,null,function*(){let r=`${e}\0${t}\0${n}`;if(Lr!==r){try{yield wt(e,t,n),Lr=r;return}catch(e){if(!Kt(e))throw e}if(yield _(),yield q(),!N&&z.value)try{yield wt(e,t,n),Lr=r}catch(e){if(!Kt(e))throw e}}})}function zr(){return v.codeBlockOptions?.maxHeight??500}let Br=g(()=>v.isShowPreview&&(T.value===`html`||T.value===`svg`));function Vr(){return typeof v.node.loading==`boolean`?v.node.loading:!0===v.loading}function Hr(e,t,n){return!n||function(){if(!Vr())return!0;let e=String(v.node.raw??``),t=e.split(/\r\n|\n|\r/,1)[0]?.trimStart()??``;return!/^(?:`{3,}|~{3,})/.test(t)||/\r\n|\n|\r/.test(e)}()&&String(t??``)?ue(String(e??``)):`plain`}function Ur(){return Vr()}let Wr=null,Gr=!1,Kr=0;function qr(){Wr=null,Kr++}function Jr(){return D(this,arguments,function*(e=Kr){if(!Gr){Gr=!0;try{for(;Wr&&!N&&!z.value&&e===Kr;){let e=Wr;Wr=null;try{yield Promise.resolve(Ct(e.code,e.language)),yield _(),N||z.value||(Y(!1),X())}catch{}}}finally{Gr=!1,!Wr||N||z.value||Jr()}}})}function Yr(e,t){Wr={code:e,language:t},Jr(Kr)}y(()=>[v.node.language,v.node.code,v.node.raw,v.node.loading,v.loading],([e,t,n,r,i])=>{T.value=Hr(e,t,typeof r==`boolean`?r:!0===i)}),y(()=>[v.node.originalCode,v.node.updatedCode,z.value],()=>{x(()=>sr())},{immediate:!0});let Xr=0;y(()=>[v.node.originalCode,v.node.updatedCode,O.value,z.value,v.stream],e=>D(null,[e],function*([,,,e,t]){let n=++Xr;if(!e||Vr()||!1===t&&!A.value)return;if(!1!==t&&F&&!A.value&&C.value)try{yield ci(C.value)}catch{}let r=Mt;if(r&&!j.value){try{yield r}catch{}if(N||!z.value||n!==Xr)return}if(n!==Xr)return;let i=Wt(String(v.node.originalCode??``),String(v.node.updatedCode??``)),a=!1===v.loading;a&&_i();try{if(yield Rr(i.original,i.updated,O.value),N||!z.value||n!==Xr)return;yield _(),X(!0),Z(),Y(!1===v.loading||{preferModelDiffHeight:!0}),X(!0),Q(!0)}catch{return}if(a){if(N||!z.value)return;qt(),Z(),sr(),Q(),Dr(!0)}Ye.value&&x(()=>Cr())})),y(()=>v.node.code,e=>D(null,null,function*(){if(Vr()||!1===v.stream||(T.value||=ue(Pt(e)),z.value))return;let t=Mt;if(t&&!j.value){try{yield t}catch{}if(N||z.value)return}if(F&&!A.value&&C.value)try{yield ci(C.value)}catch{}Yr(Gt(v.node.code),O.value),Ye.value&&x(()=>Cr())}));let Zr=g(()=>{let e=T.value;return e?pe[e]||e.charAt(0).toUpperCase()+e.slice(1):pe[``]||`Plain Text`}),Qr=g(()=>ge(String(v.node.raw??``),Zr.value,z.value)),$r=g(()=>Qr.value.title),ei=g(()=>Qr.value.caption),ti=g(()=>(le.value,Pe(T.value||``,ze))),ni=g(()=>{let e={};e[`--markstream-code-layout-character-width`]=wn.value==null?`1ch`:`${wn.value}px`,e[`--markstream-code-fallback-bg`]=B.value.background,e[`--markstream-code-fallback-fg`]=B.value.foreground,B.value.builtin&&(e[`--markstream-code-theme-bg`]=B.value.background,e[`--markstream-code-theme-fg`]=B.value.foreground,e[`--markstream-code-theme-line-number`]=B.value.lineNumber),e[`--markstream-diff-added-line-fill`]=B.value.diffAddedLine,e[`--markstream-diff-added-number-fill`]=B.value.diffAddedNumber,e[`--markstream-diff-editor-bg`]=B.value.background,e[`--markstream-diff-removed-line-fill`]=B.value.diffRemovedLine,e[`--markstream-diff-removed-number-fill`]=B.value.diffRemovedNumber,e[`--markstream-diff-shell-bg`]=B.value.background,e[`--markstream-pre-resolved-theme-bg`]=B.value.background,e[`--markstream-pre-resolved-theme-fg`]=B.value.foreground,e[`--markstream-pre-resolved-theme-line-number`]=B.value.lineNumber;let t=e=>{if(e!=null)return typeof e==`number`?`${e}px`:String(e)},n=t(v.minWidth),r=t(v.maxWidth);if(n&&(e.minWidth=n),r&&(e.maxWidth=r),Kn.value&&!z.value&&!k.value){let t=qn.value;t!=null&&(e.minHeight=`${t}px`)}return e.color=`var(--markstream-code-fallback-fg, var(--markstream-code-theme-fg, var(--markstream-pre-resolved-theme-fg)))`,e.backgroundColor=`var(--markstream-code-fallback-bg, var(--markstream-code-theme-bg, var(--markstream-pre-resolved-theme-bg)))`,z.value||(e.borderColor=`var(--markstream-code-border-color, var(--code-border))`),e}),ri=g(()=>!1!==v.showTooltips);function ii(){return D(this,null,function*(){let e=v.node.code;try{v.clipboardWriter?yield v.clipboardWriter(e):typeof navigator<`u`&&navigator.clipboard&&typeof navigator.clipboard.writeText==`function`&&(yield navigator.clipboard.writeText(e)),Ge.value=!0,de(`copy`,e),setTimeout(()=>{Ge.value=!1},1e3)}catch(e){console.error(`复制失败:`,e)}})}function ai(){Ye.value=!Ye.value;let e=z.value?L():I(),t=C.value;e&&t&&(Ye.value?(t.style.maxHeight=`none`,t.style.overflow=`visible`,Y(!0)):(t.style.overflow=`auto`,Y(!0)))}function oi(){var e;if(k.value=!k.value,k.value){if(mt=!1,C.value){let t=Math.ceil((e=C.value).getBoundingClientRect?.call(e).height||0);mt=kr(C.value,t)||C.value.style.overflow===`auto`||C.value.style.overflowY===`auto`,t>0&&(ft.value=t)}}else C.value&&ft.value!=null&&(C.value.style.height=`${ft.value}px`),pt=2,_(()=>{k.value||N||(Y(!0),X(!0))})}function si(){if(!Br.value)return;let e=T.value;if(Ue.value){let t=e===`html`?`text/html`:`image/svg+xml`,n=e===`html`?We(`artifacts.htmlPreviewTitle`)||`HTML Preview`:We(`artifacts.svgPreviewTitle`)||`SVG Preview`;de(`previewCode`,{node:v.node,artifactType:t,artifactTitle:n,id:`temp-${e}-${Date.now()}`})}else e===`html`&&(yn.value=!yn.value)}function ci(e,t={}){if(!F||N||!1===v.stream&&!1!==v.loading||(Ci(),wi())||V.value||C.value!==e||Ur())return null;if(R)return R;if(A.value&&M.value)return Promise.resolve();let n=xi(),r=nn.value,i=!1;A.value=!0,function(){let e=Be.value;S&&e&&dt!==e&&(dt&&S.markSettled(dt),dt=e,S.markPending(e))}();let a=D(null,null,function*(){try{yield function(e){return D(this,null,function*(){var t;if(!F||N)return;at=!1;let n=Qt.value;if(ln=!1,U.value=!1,tn.value=null,j.value=!1,H.value=!1,en.value=!1,Sn.value=null,Cn.value=null,wn.value=null,Tn.value=null,Er(),function(){if(an.value=!1,Ln())return void(Vn.value=null);let e=zn.value;Vn.value=M.value||e==null?null:e}(),wr(),Tr(),function(e){e.replaceChildren()}(e),_i(),yield _e(hi()),N)return;let r=D(null,null,function*(){if(n===`diff`){(function(){if(It||typeof window>`u`)return;It=!0;let e=e=>{Kt(`reason`in e?e.reason:e.error??e.message)&&(e.preventDefault(),e.stopImmediatePropagation())};window.addEventListener(`error`,e,!0),window.addEventListener(`unhandledrejection`,e,!0),Lt=()=>{window.removeEventListener(`error`,e,!0),window.removeEventListener(`unhandledrejection`,e,!0),It=!1,Lt=null}})(),kt();let t=Wt(String(v.node.originalCode??``),String(v.node.updatedCode??``));St?yield St(e,t.original,t.updated,O.value):yield F(e,v.node.code,O.value)}else yield F(e,W.value,O.value);j.value=!0}).finally(()=>{Mt===r&&(Mt=null)});if(Mt=r,yield function(e){return D(this,null,function*(){if(!z.value)return void(yield e);let t,n=!1;for(e.then(()=>{n=!0},e=>{n=!0,t=e});;){if(N)return;if(n){if(t)throw t;return}if(jr()&&Fr())return;yield _(),yield q()}})}(r),N||Qt.value!==n)return;j.value=!0;let i=v.codeBlockOptions?.fontSize;if(typeof i==`number`&&Number.isFinite(i)&&i>0){let e=n===`diff`?L():I();(t=e?.updateOptions)==null||t.call(e,{fontSize:i}),G.value=i,K.value=i}else if(!_r()){let e=rr();e&&e>0?(G.value=e,K.value=e):(G.value=12,K.value=12)}for(gr();at;)if(at=!1,yield mi(),N)return;Ye.value||k.value||Y(!1),M.value=!0,$t.value=n,function(){if(wr(),z.value){let e=L(),t=(e?.getOriginalEditor)?.call(e),n=(e?.getModifiedEditor)?.call(e),r=(e,t)=>{try{let n=e?.[t];if(typeof n!=`function`)return;let r=n.call(e,()=>Q());r&&Rt.push(r)}catch{}};try{let t=(e?.onDidUpdateDiff)?.call(e,()=>{Q(),x(()=>sr())});t&&Rt.push(t)}catch{}r(t,`onDidContentSizeChange`),r(n,`onDidContentSizeChange`);let i=C.value;if(i&&typeof MutationObserver<`u`){let e=`diffs-container,.stream-diffs-shell,.stream-diffs-surface`,t=t=>{let n=t instanceof HTMLElement?t:t.parentElement;return!!(n?.closest)?.call(n,e)},n=t=>{let n=t instanceof HTMLElement?t:t.parentElement;return!!((n?.closest)?.call(n,e)||(n?.querySelector)?.call(n,e))},r=new MutationObserver(e=>{z.value&&Pr()&&e.some(e=>t(e.target)||Array.from(e.addedNodes).some(n)||Array.from(e.removedNodes).some(t))&&(Z(),Y({preferModelDiffHeight:!0}),X(),Dr())});r.observe(i,{attributeFilter:[`class`],attributes:!0,childList:!0,characterData:!0,subtree:!0}),Rt.push({dispose:()=>r.disconnect()})}if(i&&typeof ResizeObserver<`u`){let e=new ResizeObserver(()=>{if(!z.value||(X(),!Pr()))return;let e=mr(i);e!=null&&(Math.ceil(i.getBoundingClientRect().height||0)<=e+1||(Z(),Y({preferModelDiffHeight:!0}),X()))});e.observe(i),Rt.push({dispose:()=>e.disconnect()})}return}let e=I();try{let t=(e?.onDidContentSizeChange)?.call(e,()=>Q());t&&Rt.push(t)}catch{}try{let t=(e?.onDidLayoutChange)?.call(e,()=>Q());t&&Rt.push(t)}catch{}}(),yr(),gr(),Z(),sr(),Q(),yield _();let a=null;jt&&(a=yield jt(),a&&(yield _(),yield q()));let o=a??(n===`diff`?yield Ir():yield function(){return D(this,null,function*(){if($())return yield _(),yield q(),$();for(let e=0;e<30;e++){if(N||z.value)return!1;let e=C.value,t=Nr(),n=Mr(e),r=!W.value.trim()||or(e);if(t&&n&&r&&(yield _(),yield q(),!N&&!z.value&&Nr()&&Mr(C.value)&&(!W.value.trim()||or(C.value))))return!0;yield _(),yield q()}return!1})}());N||(o?(gr(),er(),(yield Zn())||Ti()):Ti())})}(e),on=null}catch(e){let a=xi(),o=r!==nn.value,s=!1!==t.allowStaleContentRetry&&o&&on!==a;if(n!==a||s)return s&&(on=a),i=!0,A.value=!1,M.value=!1,j.value=!1,void(H.value=!1);throw Ti(n),e}}).finally(()=>{R===a&&(R=null),function(){let e=dt;S&&e&&(dt=``,_(()=>{if(!N){let t=w.value?.offsetHeight??0;t>0&&S.reportHeight(e,t)}S.markSettled(e)}))}(),i&&!N&&queueMicrotask(()=>{var e;let t=C.value;t&&!N&&((e=ci(t))==null||e.catch(e=>{M.value=!1,H.value=!1,Ti()}))})});return R=a,a}y(ri,e=>{e||je()}),y(()=>K.value,(e,t)=>{var n;let r=z.value?L():I();r&&typeof e==`number`&&Number.isFinite(e)&&e>0&&((n=r.updateOptions)==null||n.call(r,{fontSize:e}),k.value||Y(!0))},{flush:`post`,immediate:!1});let li=0,ui=y(()=>[C.value,z.value,v.stream,v.loading,it.value,P.value,v.node.language,v.node.raw,v.node.code,v.node.loading],e=>D(null,[e],function*([e,t,n,r,i,a]){let o=++li;if(!e||!a||Vr()||sn||!1===n&&!1!==r||!F&&(yield function(){return D(this,null,function*(){if(typeof window>`u`||N||it.value||V.value)return;if(Nt)return Nt;let e=D(null,null,function*(){try{let e=yield He();if(N)return;if(!e)return void(V.value=!0);xn(e)}catch{if(N)return;V.value=!0}}).finally(()=>{Nt===e&&(Nt=null)});return Nt=e,e})}(),o!==li||!1===v.stream&&!1!==v.loading||Ur()||!P.value||!F||V.value||A.value||wi()||N||C.value!==e)||Ur())return;let s=ci(e);if(s){try{yield s}catch{M.value=!1,H.value=!1,Ti()}M.value&&H.value&&ui()}}));function di(e){return typeof e==`string`?e:null}function fi(e,t){if(e===t)return!0;let n=di(e),r=di(t);return!!n&&n===r}function pi(){return we({darkTheme:v.darkTheme,isDark:v.isDark,lightTheme:v.lightTheme,theme:v.theme,themes:v.themes})}function mi(){return D(this,arguments,function*(e={}){_i();let t=()=>{z.value&&qt(),x(()=>{yr(),Q()})};if(e.appearanceOnly)return void t();let n=pi();if(n)try{yield _e(hi()),yield Ft(n),t()}catch{}else t()})}function hi(){let e=v.themes;return e&&typeof e[0]==`string`&&typeof e[1]==`string`?{dark:e[0],light:e[1]}:pi()}function gi(){let e=Mn.value,t=qe(E({},Jt.value||{}),{wordWrap:e.overflow===`wrap`?`on`:`off`,overflow:e.overflow,themes:v.themes,stream:!1,MAX_HEIGHT:v.codeBlockOptions?.maxHeight??500,fontSize:Dn.value,lineHeight:kn.value,theme:pi(),themeType:v.isDark?`dark`:`light`,disableLineNumbers:!Ae.value,disableFileHeader:!0,workerManager:Jt.value?.workerManager??he()??void 0,onThemeChange(){yr()}}),n=function(){let e=Jt.value?.fontFamily;return typeof e==`string`&&e.trim()?e.trim():z.value?function(){if(typeof window>`u`)return;let e=w.value?.querySelector(`pre.code-pre-fallback`);if(e)return window.getComputedStyle(e).fontFamily.trim()||void 0}():void 0}();n&&(t.fontFamily??=n);let r=typeof t.unsafeCSS==`string`?t.unsafeCSS:``;return t.unsafeCSS=be(e.overflow,r),t}function _i(){let e=gi();if(!Bt)return Bt=e,Bt;for(let t of Object.keys(Bt))t in e||delete Bt[t];return Object.assign(Bt,e),Bt}y(Qt,(e,t)=>D(null,null,function*(){if(e===t||U.value||sn||(qr(),!F||!C.value)||!A.value||!1===v.stream&&!1!==v.loading||!P.value)return;let n=R;if(n){try{yield n}catch{}if(N||!C.value)return}if($t.value!==e||!A.value||!M.value)try{M.value=!1,H.value=!1,A.value=!1,j.value=!1,wr(),Tr(),kt(),yield _(),yield ci(C.value)}catch{M.value=!1,H.value=!1,Ti()}}));let vi=b(0),yi=g(()=>String(vi.value)),bi=!1;function xi(){let e=pi();return JSON.stringify({kind:Qt.value,language:O.value,structural:yi.value,optionsRevision:vi.value,settledContentGeneration:rn.value,theme:di(e)??(e==null?null:`custom`),isDark:v.isDark})}y(()=>v.codeBlockOptions?.fontSize,e=>{let t=typeof e==`number`&&Number.isFinite(e)&&e>0?e:12;G.value=t,K.value=t,Sn.value=null,Cn.value=null,wn.value=null}),y(()=>[v.codeBlockOptions,v.showLineNumbers],()=>{vi.value+=1,!1===v.stream&&!1!==v.loading&&(bi=!0)},{deep:!0}),y(()=>[W.value,v.node.originalCode,v.node.updatedCode],()=>{nn.value+=1,Vr()||(rn.value+=1)});let Si=g(()=>xi());function Ci(){U.value&&tn.value!==Si.value&&(U.value=!1,tn.value=null,on=null,cn=null,A.value=!1,M.value=!1,j.value=!1,H.value=!1,en.value=!1)}function wi(){return Ci(),U.value&&tn.value===Si.value}function Ti(e=Si.value){tn.value=e,U.value=!0,en.value=!1}return y(Si,()=>D(null,null,function*(){if(sn||!U.value||tn.value===Si.value||!F||!C.value||V.value||N||!P.value||!1===v.stream&&!1!==v.loading||Ur())return;let e=Si.value;sn=!0;try{if(Ci(),U.value)return;yield ci(C.value)}catch{M.value=!1,H.value=!1,Ti()}finally{cn=e,yield _(),sn=!1}})),y(()=>[v.codeBlockOptions,P.value],()=>{var e;if(_i(),!F||!P.value)return;let t=z.value?L():I(),n=typeof v.codeBlockOptions?.fontSize==`number`?v.codeBlockOptions.fontSize:Number.isFinite(K.value)?K.value:void 0;typeof n==`number`&&Number.isFinite(n)&&n>0&&((e=t?.updateOptions)==null||e.call(t,{fontSize:n})),Y(!1)},{deep:!0}),y(()=>[pi(),Xt.value,it.value,A.value,P.value],([e,t],n)=>{if(!it.value||!P.value)return;let r=n!=null&&fi(e,n[0]),i=n!=null&&t!==n[1];M.value?(at=!1,mi({appearanceOnly:r})):r&&!i||(at=!0)},{flush:`post`}),y(()=>[yi.value,it.value,P.value],(e,t)=>D(null,[e,t],function*([e,t,n],[r]){if(_i(),!t||!n||!F||!C.value||!A.value||e===r)return;if(!1===v.stream&&!1!==v.loading)return void(bi=!0);bi=!1;let i=R;if(i){try{yield i}catch{}if(N||!C.value)return}try{M.value=!1,H.value=!1,A.value=!1,j.value=!1,wr(),Tr(),kt(),Vt&&xn(Vt),yield _(),yield ci(C.value,{allowStaleContentRetry:!1})}catch{M.value=!1,H.value=!1,Ti()}}),{flush:`post`}),y(()=>[v.loading,P.value],([e,t])=>{!1===e&&t&&bi&&(bi=!1,vi.value+=1)},{flush:`post`}),y(()=>[v.loading,P.value],(e,t)=>D(null,[e,t],function*([e,t],n){if(!t)return;let r=n?.[0];if(!1===r&&!1!==e&&z.value&&A.value&&(yield _(),x(()=>{D(null,null,function*(){let e=R;if(e)try{yield e}catch{}!N&&z.value&&!1!==v.loading&&(_i(),qt(),Q())})})),e)return;let i=r!==void 0&&!1!==r;yield _(),x(()=>{D(null,null,function*(){try{if(i&&(yield function(){return D(this,null,function*(){if(!U.value||!F||!C.value||V.value||N||!P.value)return!1;if(cn===Si.value)return!0;sn=!0;try{U.value=!1,tn.value=null,on=null,A.value=!1,M.value=!1,j.value=!1,H.value=!1,wr(),Tr(),kt(),Vt&&xn(Vt),yield _();try{yield ci(C.value)}catch{M.value=!1,H.value=!1,Ti()}}finally{yield _(),sn=!1}return!0})}()))return void Y(!1);if(i&&z.value&&A.value&&ln&&C.value)return ln=!1,M.value=!1,H.value=!1,A.value=!1,j.value=!1,wr(),Tr(),kt(),yield _(),yield ci(C.value,{allowStaleContentRetry:!1}),void Dr(!0);if(i&&A.value){if(z.value&&C.value){let e=R;if(e)try{yield e}catch{}_i();let t=Wt(String(v.node.originalCode??``),String(v.node.updatedCode??``));if(yield Rr(t.original,t.updated,O.value),N||!z.value)return;yield Promise.resolve(Et()),qt(),X(!0),Xn(),Z(),sr();let n=yield Ir();N||!n||H.value||(yield Zn()),Q(),Dr(!0)}else qr(),Yr(W.value,O.value),yield new Promise(e=>{let t=()=>{N?e():Gr||Wr?setTimeout(t,16):e()};t()}),N||z.value||(yield Promise.resolve(Tt()))}i&&z.value?(Y({preferModelDiffHeight:!0,holdCurrentDiffHeight:!0}),Dr(!0)):Y(!1)}catch{}})})}),{immediate:!0,flush:`post`}),i(()=>{wr(),Tr(),Ot(),Lt?.()}),(t,n)=>{var i;return V.value?(s(),d(Fe,{key:0,style:ae(Gn.value),node:bn.value,loading:v.loading,"show-line-numbers":Ae.value,"diff-inline":un.value,"diff-hide-unchanged-regions":dn.value,"code-block-options":v.codeBlockOptions,"resolved-visual-options":Mn.value,"reserved-height-px":z.value&&(i=Tn.value)!=null?i:void 0,"is-dark":v.isDark,theme:v.theme,"dark-theme":v.darkTheme,"light-theme":v.lightTheme,themes:v.themes,"show-header":v.showHeader,"show-copy-button":v.showCopyButton,"clipboard-writer":v.clipboardWriter,"show-tooltips":v.showTooltips,onCopy:n[0]||=e=>de(`copy`,e)},p({_:2},[t.$slots[`header-left`]?{name:`header-left`,fn:u(()=>[r(t.$slots,`header-left`,{},void 0,!0)]),key:`0`}:void 0,t.$slots[`header-right`]?{name:`header-right`,fn:u(()=>[r(t.$slots,`header-right`,{},void 0,!0)]),key:`1`}:void 0]),1032,[`style`,`node`,`loading`,`show-line-numbers`,`diff-inline`,`diff-hide-unchanged-regions`,`code-block-options`,`resolved-visual-options`,`reserved-height-px`,`is-dark`,`theme`,`dark-theme`,`light-theme`,`themes`,`show-header`,`show-copy-button`,`clipboard-writer`,`show-tooltips`])):(s(),se(`div`,{key:1,ref_key:`container`,ref:w,style:ae(ni.value),class:f([`code-block-container rounded-lg border`,[{dark:v.isDark,"is-rendering":v.loading,"is-dark":Zt.value,"is-diff":z.value,"is-plain-text":Je.value}]]),"data-markstream-code-block":`1`,"data-markstream-enhanced":H.value&&!V.value?`true`:`false`,"data-markstream-enhancement-state":vn.value,"data-markstream-code-block-state":Vr()?`streaming`:`settled`,"data-markstream-pending":_n.value?`true`:void 0,"data-markstream-viewport-pending":xt.value&&te(_t)&&!P.value?`true`:void 0},[e(Ne,{"show-header":v.showHeader,"show-collapse-button":v.showCollapseButton,"show-font-size-buttons":v.showFontSizeButtons,"enable-font-size-control":v.enableFontSizeControl,"show-copy-button":v.showCopyButton,"show-expand-button":v.showExpandButton,"show-preview-button":v.showPreviewButton,"show-tooltips":v.showTooltips,"is-dark":v.isDark,loading:v.loading,stream:c.stream,"is-collapsed":k.value,"is-expanded":Ye.value,"copy-text":Ge.value,"is-previewable":Br.value,"code-font-size":K.value,"code-font-min":10,"code-font-max":36,"default-code-font-size":G.value,"font-baseline-ready":En.value,"diff-stats":z.value?Ht.value:null,"diff-stats-aria-label":Ut.value,onToggleCollapse:oi,onDecreaseFont:ur,onResetFont:dr,onIncreaseFont:lr,onCopy:ii,onToggleExpand:ai,onPreview:si},p({"header-left":u(()=>[r(t.$slots,`header-left`,{},()=>[h(`div`,Qe,[h(`span`,{class:`icon-slot h-4 w-4 flex-shrink-0`,innerHTML:ti.value},null,8,$e),h(`div`,et,[h(`div`,tt,ee($r.value),1),ei.value?(s(),se(`div`,nt,ee(ei.value),1)):oe(``,!0)])])],!0)]),loading:u(()=>[r(t.$slots,`loading`,{loading:c.loading,stream:c.stream},()=>[n[1]||=h(`div`,{class:`loading-skeleton`},[h(`div`,{class:`skeleton-line`}),h(`div`,{class:`skeleton-line`}),h(`div`,{class:`skeleton-line short`})],-1)],!0)]),default:u(()=>{var e;return[l(h(`div`,{class:f([`code-editor-layer`,{"code-editor-layer--collapsed":k.value}])},[h(`div`,{ref_key:`codeEditor`,ref:C,class:f([`code-editor-container`,c.stream?``:`code-height-placeholder`]),"data-markstream-host-hidden":gn.value?`true`:void 0,style:ae(Jn.value)},null,14,rt),hn.value?(s(),d(Fe,{key:0,style:ae(Gn.value),node:bn.value,loading:v.loading,"show-line-numbers":Ae.value,"diff-inline":un.value,"diff-hide-unchanged-regions":dn.value,"code-block-options":v.codeBlockOptions,"resolved-visual-options":Mn.value,"reserved-height-px":z.value&&(e=Tn.value)!=null?e:void 0,"is-dark":v.isDark,theme:v.theme,"dark-theme":v.darkTheme,"light-theme":v.lightTheme,themes:v.themes,"show-toolbar":!1},null,8,[`style`,`node`,`loading`,`show-line-numbers`,`diff-inline`,`diff-hide-unchanged-regions`,`code-block-options`,`resolved-visual-options`,`reserved-height-px`,`is-dark`,`theme`,`dark-theme`,`light-theme`,`themes`])):oe(``,!0)],2),[[re,!!c.stream||!c.loading]]),yn.value&&!Ue.value&&Br.value&&T.value===`html`?(s(),d(Xe,{key:0,code:v.node.code,"html-preview-allow-scripts":v.htmlPreviewAllowScripts,"html-preview-sandbox":v.htmlPreviewSandbox,"is-dark":v.isDark,"on-close":()=>yn.value=!1},null,8,[`code`,`html-preview-allow-scripts`,`html-preview-sandbox`,`is-dark`,`on-close`])):oe(``,!0)]}),_:2},[t.$slots[`header-right`]?{name:`header-right`,fn:u(()=>[r(t.$slots,`header-right`,{},void 0,!0)]),key:`0`}:void 0]),1032,[`show-header`,`show-collapse-button`,`show-font-size-buttons`,`enable-font-size-control`,`show-copy-button`,`show-expand-button`,`show-preview-button`,`show-tooltips`,`is-dark`,`loading`,`stream`,`is-collapsed`,`is-expanded`,`copy-text`,`is-previewable`,`code-font-size`,`default-code-font-size`,`font-baseline-ready`,`diff-stats`,`diff-stats-aria-label`])],14,Ze))}}}),[[`__scopeId`,`data-v-f293a87c`]]);export{A as default};