litepaseo 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +25 -8
  3. package/dist/server/cli.mjs +8 -2
  4. package/dist/server/{worker-CmsAgviJ.mjs → worker-Cq2Lf-Zo.mjs} +169 -21
  5. package/dist/web/assets/{ChangesPanel-DdtJswMt.js → ChangesPanel-BXtRMTqp.js} +1 -1
  6. package/dist/web/assets/ChangesPanel-BXtRMTqp.js.br +0 -0
  7. package/dist/web/assets/ChangesPanel-BXtRMTqp.js.gz +0 -0
  8. package/dist/web/assets/{CodeBlockNode-BOeBLCjf.js → CodeBlockNode-B9X7WZtj.js} +1 -1
  9. package/dist/web/assets/CodeBlockNode-B9X7WZtj.js.br +0 -0
  10. package/dist/web/assets/CodeBlockNode-B9X7WZtj.js.gz +0 -0
  11. package/dist/web/assets/{ConversationSearch-BXfGhrtx.js → ConversationSearch-DgRoYzWP.js} +1 -1
  12. package/dist/web/assets/ConversationSearch-DgRoYzWP.js.br +0 -0
  13. package/dist/web/assets/ConversationSearch-DgRoYzWP.js.gz +0 -0
  14. package/dist/web/assets/{FileViewer-C93qu9YH.js → FileViewer-B-N8t-A2.js} +1 -1
  15. package/dist/web/assets/FileViewer-B-N8t-A2.js.br +0 -0
  16. package/dist/web/assets/FileViewer-B-N8t-A2.js.gz +0 -0
  17. package/dist/web/assets/{FilesPanel-DyqtBDO_.js → FilesPanel-By85fwCy.js} +1 -1
  18. package/dist/web/assets/FilesPanel-By85fwCy.js.br +0 -0
  19. package/dist/web/assets/FilesPanel-By85fwCy.js.gz +0 -0
  20. package/dist/web/assets/{HostSettings-BCsvyF_3.js → HostSettings-Bzv1FBbL.js} +1 -1
  21. package/dist/web/assets/HostSettings-Bzv1FBbL.js.br +0 -0
  22. package/dist/web/assets/HostSettings-Bzv1FBbL.js.gz +0 -0
  23. package/dist/web/assets/{MarkdownMessage-CejBvgRc.js → MarkdownMessage-DbSS5ULZ.js} +5 -5
  24. package/dist/web/assets/MarkdownMessage-DbSS5ULZ.js.br +0 -0
  25. package/dist/web/assets/MarkdownMessage-DbSS5ULZ.js.gz +0 -0
  26. package/dist/web/assets/{PreCodeBlock-BBTzkaAH.js → PreCodeBlock-B-6jTSFa.js} +1 -1
  27. package/dist/web/assets/{PreCodeBlock.vue_vue_type_style_index_0_lang-4BQzC8nU.js → PreCodeBlock.vue_vue_type_style_index_0_lang-CunCuyah.js} +1 -1
  28. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-CunCuyah.js.br +0 -0
  29. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-CunCuyah.js.gz +0 -0
  30. package/dist/web/assets/{SubagentsPanel-D1bEm5QC.js → SubagentsPanel-CdZce3Xr.js} +1 -1
  31. package/dist/web/assets/SubagentsPanel-CdZce3Xr.js.br +0 -0
  32. package/dist/web/assets/SubagentsPanel-CdZce3Xr.js.gz +0 -0
  33. package/dist/web/assets/{TerminalPanel-wazWBZjN.js → TerminalPanel-iBK2wpI0.js} +1 -1
  34. package/dist/web/assets/TerminalPanel-iBK2wpI0.js.br +0 -0
  35. package/dist/web/assets/TerminalPanel-iBK2wpI0.js.gz +0 -0
  36. package/dist/web/assets/{Tooltip-CrG6tFax.js → Tooltip-DLPAOJ1c.js} +1 -1
  37. package/dist/web/assets/Tooltip-DLPAOJ1c.js.br +0 -0
  38. package/dist/web/assets/Tooltip-DLPAOJ1c.js.gz +0 -0
  39. package/dist/web/assets/index-DV5BdS_U.js +35 -0
  40. package/dist/web/assets/index-DV5BdS_U.js.br +0 -0
  41. package/dist/web/assets/index-DV5BdS_U.js.gz +0 -0
  42. package/dist/web/assets/{index10-C9Xw5wOS.js → index10-DgcnbLc5.js} +1 -1
  43. package/dist/web/assets/index10-DgcnbLc5.js.br +0 -0
  44. package/dist/web/assets/index10-DgcnbLc5.js.gz +0 -0
  45. package/dist/web/assets/index3-BdNVIlGK.js +1 -0
  46. package/dist/web/assets/index4-DnuPr-1i.js +1 -0
  47. package/dist/web/assets/{index5-Cxc_iCM3.js → index5-Bp-1tRh4.js} +1 -1
  48. package/dist/web/assets/index5-Bp-1tRh4.js.br +0 -0
  49. package/dist/web/assets/index5-Bp-1tRh4.js.gz +0 -0
  50. package/dist/web/assets/{index6-DsTT-iog.js → index6-B8l4-gzx.js} +1 -1
  51. package/dist/web/assets/index6-B8l4-gzx.js.br +0 -0
  52. package/dist/web/assets/index6-B8l4-gzx.js.gz +0 -0
  53. package/dist/web/assets/{index7-Bgw61c0t.js → index7-CIxLf3CP.js} +1 -1
  54. package/dist/web/assets/index7-CIxLf3CP.js.br +0 -0
  55. package/dist/web/assets/index7-CIxLf3CP.js.gz +0 -0
  56. package/dist/web/assets/{index8-DLEM8iM5.js → index8-CnHhIOzI.js} +1 -1
  57. package/dist/web/assets/index8-CnHhIOzI.js.br +0 -0
  58. package/dist/web/assets/index8-CnHhIOzI.js.gz +0 -0
  59. package/dist/web/assets/{index9-CUy1AFI-.js → index9-B_ZyF9x1.js} +1 -1
  60. package/dist/web/assets/index9-B_ZyF9x1.js.br +0 -0
  61. package/dist/web/assets/index9-B_ZyF9x1.js.gz +0 -0
  62. package/dist/web/index.html +1 -1
  63. package/dist/web/index.html.br +0 -0
  64. package/dist/web/index.html.gz +0 -0
  65. package/package.json +1 -1
  66. package/dist/web/assets/ChangesPanel-DdtJswMt.js.br +0 -0
  67. package/dist/web/assets/ChangesPanel-DdtJswMt.js.gz +0 -0
  68. package/dist/web/assets/CodeBlockNode-BOeBLCjf.js.br +0 -0
  69. package/dist/web/assets/CodeBlockNode-BOeBLCjf.js.gz +0 -0
  70. package/dist/web/assets/ConversationSearch-BXfGhrtx.js.br +0 -0
  71. package/dist/web/assets/ConversationSearch-BXfGhrtx.js.gz +0 -0
  72. package/dist/web/assets/FileViewer-C93qu9YH.js.br +0 -0
  73. package/dist/web/assets/FileViewer-C93qu9YH.js.gz +0 -0
  74. package/dist/web/assets/FilesPanel-DyqtBDO_.js.br +0 -0
  75. package/dist/web/assets/FilesPanel-DyqtBDO_.js.gz +0 -0
  76. package/dist/web/assets/HostSettings-BCsvyF_3.js.br +0 -0
  77. package/dist/web/assets/HostSettings-BCsvyF_3.js.gz +0 -0
  78. package/dist/web/assets/MarkdownMessage-CejBvgRc.js.br +0 -0
  79. package/dist/web/assets/MarkdownMessage-CejBvgRc.js.gz +0 -0
  80. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-4BQzC8nU.js.br +0 -0
  81. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-4BQzC8nU.js.gz +0 -0
  82. package/dist/web/assets/SubagentsPanel-D1bEm5QC.js.br +0 -0
  83. package/dist/web/assets/SubagentsPanel-D1bEm5QC.js.gz +0 -0
  84. package/dist/web/assets/TerminalPanel-wazWBZjN.js.br +0 -0
  85. package/dist/web/assets/TerminalPanel-wazWBZjN.js.gz +0 -0
  86. package/dist/web/assets/Tooltip-CrG6tFax.js.br +0 -0
  87. package/dist/web/assets/Tooltip-CrG6tFax.js.gz +0 -0
  88. package/dist/web/assets/index-Cmpdc3EH.js +0 -35
  89. package/dist/web/assets/index-Cmpdc3EH.js.br +0 -0
  90. package/dist/web/assets/index-Cmpdc3EH.js.gz +0 -0
  91. package/dist/web/assets/index10-C9Xw5wOS.js.br +0 -0
  92. package/dist/web/assets/index10-C9Xw5wOS.js.gz +0 -0
  93. package/dist/web/assets/index3-dduGUVTy.js +0 -1
  94. package/dist/web/assets/index4-qdeznE4u.js +0 -1
  95. package/dist/web/assets/index5-Cxc_iCM3.js.br +0 -0
  96. package/dist/web/assets/index5-Cxc_iCM3.js.gz +0 -0
  97. package/dist/web/assets/index6-DsTT-iog.js.br +0 -0
  98. package/dist/web/assets/index6-DsTT-iog.js.gz +0 -0
  99. package/dist/web/assets/index7-Bgw61c0t.js.br +0 -0
  100. package/dist/web/assets/index7-Bgw61c0t.js.gz +0 -0
  101. package/dist/web/assets/index8-DLEM8iM5.js.br +0 -0
  102. package/dist/web/assets/index8-DLEM8iM5.js.gz +0 -0
  103. package/dist/web/assets/index9-CUy1AFI-.js.br +0 -0
  104. package/dist/web/assets/index9-CUy1AFI-.js.gz +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.2
4
+
5
+ - Open conversations with a plain request instead of the live stream. On an iPhone web app behind a Cloudflare Tunnel, the stream's first 16 KB arrived at once but the rest of a conversation was held back until the stream's next heartbeat, about 20 seconds later. A plain response has an end, so nothing waits for more data. The live stream then resumes from those rows and carries only what changes. Servers or proxies that do not offer the new request (`GET …/timeline/latest`) still get the rows from the stream, as before.
6
+ - While a conversation opened this way is still loading after 3 seconds, the page says "Still loading this conversation": the request answers only with the whole conversation, so it cannot tell which layer is waiting. Slow-open reports say which way the rows came (`via`).
7
+
8
+ ## 0.9.1
9
+
10
+ - 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.
11
+ - 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.
12
+
3
13
  ## 0.9.0
4
14
 
5
15
  - 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.
package/README.md CHANGED
@@ -247,6 +247,7 @@ litepaseo restart # apply (or: litepaseo
247
247
  | `port` | `8787` | HTTP port | `LITEPASEO_PORT` |
248
248
  | `bind` | `127.0.0.1` | Listening address | `LITEPASEO_BIND` |
249
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` |
250
251
 
251
252
  An environment variable, when set, wins over the saved value for that run.
252
253
  `LITEPASEO_HOME` (default `~/.litepaseo`) chooses the data directory itself, so it
@@ -284,16 +285,32 @@ page had just been in the background (`backgroundMs`, `visibleForMs`). A late
284
285
  `connectedMs` with no matching `timeline_slow` means the request took that long to reach
285
286
  the server, typically a connection the browser reused after sleep or a network change. A
286
287
  late `firstByteMs` after an early `connectedMs` means something in between, such as a
287
- 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
288
295
  `litepaseo logs -n 2000 | grep timeline_slow`.
289
296
 
290
- While a conversation is still loading after 3 seconds, the page says whether it is still
291
- connecting to LitePaseo, waiting for the network to deliver data, or waiting for the host.
292
-
293
- Some proxies hold a stream's latest bytes until more arrive. LitePaseo follows each burst
294
- of live updates with a few bytes of padding, so they get through without waiting for the
295
- next heartbeat. After an upgrade, open pages offer a
296
- reload so they run the installed version.
297
+ A conversation opens with a plain request (`GET …/timeline/latest`) for its latest rows;
298
+ its live stream then resumes from them and carries only changes. A plain response has an
299
+ end, so no proxy holds its tail back the way some hold back a long-lived stream. Reports
300
+ say which way the first rows came (`via`: `latest`, or `stream` when the request failed).
301
+
302
+ While a conversation is still loading after 3 seconds, the page says what it waits for:
303
+ the plain request ("Still loading this conversation"), or, when the stream carries the
304
+ rows, the connection to LitePaseo, the network, or the host. After an upgrade, open pages
305
+ offer a reload so they run the installed version.
306
+
307
+ Live streams and larger API responses (1 KB and up) are compressed with brotli or gzip
308
+ for browsers that accept it: a conversation's first rows usually shrink 3-6 times. Each
309
+ stream event is flushed as it is written, so compression never delays it. If a proxy
310
+ between you and LitePaseo mishandles compressed streams, run
311
+ `litepaseo config set compression off` and restart. Some proxies also hold a stream's
312
+ latest bytes until more arrive, so each burst of live updates is followed by a few bytes
313
+ of padding.
297
314
 
298
315
  ## How it fits together
299
316
 
@@ -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.9.0";
11
+ const VERSION = "0.9.2";
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-CmsAgviJ.mjs");
1724
+ const { runWorker } = await import("./worker-Cq2Lf-Zo.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";
@@ -1397,6 +1399,13 @@ const TIMELINE_GRACE_MS = 3e5;
1397
1399
  const SLOW_TIMELINE_MS = 3e3;
1398
1400
  /** A viewer still without rows after this long has the daemon checked for a silent connection. */
1399
1401
  const LIVENESS_CHECK_MS = 2e3;
1402
+ /** How long a conversation snapshot waits for the host before giving up. */
1403
+ const SNAPSHOT_TIMEOUT_MS = 45e3;
1404
+ var TimelineTimeoutError = class extends Error {
1405
+ constructor() {
1406
+ super("The host did not load this conversation in time.");
1407
+ }
1408
+ };
1400
1409
  var Hosts = class {
1401
1410
  agents = new VersionedCollection();
1402
1411
  workspaces = new VersionedCollection();
@@ -1628,6 +1637,36 @@ var Hosts = class {
1628
1637
  current.idle.unref?.();
1629
1638
  };
1630
1639
  }
1640
+ /**
1641
+ * The conversation as it is now, for a plain request that opens it: the shared view's reset
1642
+ * (loaded first if nobody watched it). Its seq lets the browser's stream resume from there.
1643
+ */
1644
+ timelineSnapshot(hostId, agentId, timeoutMs = SNAPSHOT_TIMEOUT_MS) {
1645
+ return new Promise((resolve, reject) => {
1646
+ let stop = null, done = false, released = false;
1647
+ const release = () => {
1648
+ if (released || !stop) return;
1649
+ released = true;
1650
+ stop();
1651
+ };
1652
+ const timer = setTimeout(() => {
1653
+ if (done) return;
1654
+ done = true;
1655
+ release();
1656
+ reject(new TimelineTimeoutError());
1657
+ }, timeoutMs);
1658
+ timer.unref?.();
1659
+ stop = this.watchTimeline(hostId, agentId, (ops) => {
1660
+ const reset = ops.find((op) => op.type === "reset");
1661
+ if (done || !reset) return;
1662
+ done = true;
1663
+ clearTimeout(timer);
1664
+ resolve(reset);
1665
+ queueMicrotask(release);
1666
+ });
1667
+ if (done) release();
1668
+ });
1669
+ }
1631
1670
  emit(listeners) {
1632
1671
  for (const listener of listeners) listener();
1633
1672
  }
@@ -2409,33 +2448,63 @@ var ServerSendQueue = class {
2409
2448
  // src/server/sse.ts
2410
2449
  const HEARTBEAT_MS = 2e4;
2411
2450
  /**
2412
- * Some proxies hold a stream's latest bytes until more arrive: behind a Cloudflare Tunnel, a
2413
- * conversation's rows reached the browser only with the next heartbeat, 20 s later. So every
2414
- * burst of writes is followed by a tiny comment, which pushes it through.
2451
+ * Some proxies hold a stream's latest bytes until more arrive, so every burst of writes is
2452
+ * followed by a tiny comment. It did not cure the 20 s waits seen on an iPhone behind a
2453
+ * Cloudflare Tunnel (rows arrived with the next heartbeat anyway); slow-open reports now carry
2454
+ * the browser's side of each stream to find out why.
2415
2455
  */
2416
2456
  const NUDGE_MS = 50;
2417
- /** Server-sent events over a plain fetch response, so the bearer header still authenticates. */
2418
- function eventStream(signal, open, valid = () => true) {
2457
+ /** The best encoding the request accepts, when compression is on. */
2458
+ function streamEncoding(acceptEncoding, enabled) {
2459
+ if (!enabled || !acceptEncoding) return null;
2460
+ const accepted = /* @__PURE__ */ new Set();
2461
+ for (const part of acceptEncoding.split(",")) {
2462
+ const [name, ...params] = part.trim().toLowerCase().split(";");
2463
+ const q = params.map((p) => p.trim()).find((p) => p.startsWith("q="));
2464
+ if (!q || Number(q.slice(2)) > 0) accepted.add(name.trim());
2465
+ }
2466
+ return accepted.has("br") ? "br" : accepted.has("gzip") ? "gzip" : null;
2467
+ }
2468
+ /**
2469
+ * Server-sent events over a plain fetch response, so the bearer header still authenticates.
2470
+ * With an encoding, every write is compressed and flushed at once: compression never holds an
2471
+ * event back (a sync flush costs a few bytes per write).
2472
+ */
2473
+ function eventStream(signal, open, valid = () => true, encoding = null) {
2419
2474
  const encoder = new TextEncoder();
2420
2475
  let cleanup;
2421
2476
  let nudge;
2477
+ let compressor = null;
2422
2478
  let stopped = false;
2423
2479
  const stop = () => {
2424
2480
  stopped = true;
2425
2481
  clearTimeout(nudge);
2482
+ compressor?.destroy();
2426
2483
  cleanup?.();
2427
2484
  cleanup = void 0;
2428
2485
  };
2429
2486
  const body = new ReadableStream({
2430
2487
  start(controller) {
2431
- const enqueue = (text) => {
2488
+ const output = (bytes) => {
2432
2489
  if (stopped) return;
2433
2490
  try {
2434
- controller.enqueue(encoder.encode(text));
2491
+ controller.enqueue(bytes);
2435
2492
  } catch {
2436
2493
  stop();
2437
2494
  }
2438
2495
  };
2496
+ if (encoding) {
2497
+ compressor = encoding === "br" ? createBrotliCompress({ params: { [constants$1.BROTLI_PARAM_QUALITY]: 5 } }) : createGzip({ level: 6 });
2498
+ compressor.on("data", (chunk) => output(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength)));
2499
+ compressor.on("error", stop);
2500
+ }
2501
+ const flushMode = encoding === "br" ? constants$1.BROTLI_OPERATION_FLUSH : constants$1.Z_SYNC_FLUSH;
2502
+ const enqueue = (text) => {
2503
+ if (stopped) return;
2504
+ if (!compressor) return output(encoder.encode(text));
2505
+ compressor.write(text);
2506
+ compressor.flush(flushMode);
2507
+ };
2439
2508
  const write = (text) => {
2440
2509
  enqueue(text);
2441
2510
  if (stopped || nudge) return;
@@ -2470,9 +2539,37 @@ function eventStream(signal, open, valid = () => true) {
2470
2539
  return new Response(body, { headers: {
2471
2540
  "Content-Type": "text/event-stream",
2472
2541
  "Cache-Control": "no-cache, no-transform",
2473
- "X-Accel-Buffering": "no"
2542
+ "X-Accel-Buffering": "no",
2543
+ ...encoding ? {
2544
+ "Content-Encoding": encoding,
2545
+ Vary: "Accept-Encoding"
2546
+ } : {}
2474
2547
  } });
2475
2548
  }
2549
+ // src/server/compression.ts
2550
+ const brotli = promisify(brotliCompress);
2551
+ const gzipped = promisify(gzip);
2552
+ /**
2553
+ * Compresses JSON API responses (history pages, prompt indexes, directory reads) with brotli
2554
+ * or gzip, as the browser accepts. Live streams compress themselves (see eventStream).
2555
+ */
2556
+ function compressJson(enabled) {
2557
+ return async (c, next) => {
2558
+ await next();
2559
+ if (!enabled || c.req.method === "HEAD") return;
2560
+ const res = c.res;
2561
+ if (!res.body || res.headers.has("Content-Encoding") || !(res.headers.get("Content-Type") ?? "").startsWith("application/json")) return;
2562
+ const encoding = streamEncoding(c.req.header("Accept-Encoding"), true);
2563
+ if (!encoding) return;
2564
+ const body = new Uint8Array(await res.arrayBuffer());
2565
+ const compressed = body.byteLength < 1024 ? null : encoding === "br" ? await brotli(body, { params: { [constants$1.BROTLI_PARAM_QUALITY]: 5 } }) : await gzipped(body, { level: 6 });
2566
+ c.res = new Response(compressed ?? body, res);
2567
+ c.res.headers.delete("Content-Length");
2568
+ if (compressed) c.res.headers.set("Content-Encoding", encoding);
2569
+ const vary = c.res.headers.get("Vary");
2570
+ if (!vary || !/(?:^|,)\s*accept-encoding\s*(?:,|$)/i.test(vary)) c.res.headers.set("Vary", vary ? `${vary}, Accept-Encoding` : "Accept-Encoding");
2571
+ };
2572
+ }
2476
2573
  // src/server/media.ts
2477
2574
  /** Raster images only: an SVG opened directly could run script on this origin. */
2478
2575
  const IMAGE_MIME = {
@@ -2588,7 +2685,7 @@ const path = z.string().min(1).max(4096).refine((p) => !p.includes("\0"));
2588
2685
  * daemon, which confines file access to the workspace and owns the terminals; nothing here
2589
2686
  * keeps state beyond an open terminal stream.
2590
2687
  */
2591
- function registerWorkspaceRoutes(app, hosts, store, valid) {
2688
+ function registerWorkspaceRoutes(app, hosts, store, valid, encodingOf = () => null) {
2592
2689
  app.get("/api/hosts/:host/changes", async (c) => {
2593
2690
  const cwd = path.parse(c.req.query("cwd"));
2594
2691
  const result = await hosts.get(c.req.param("host")).driver.getCheckoutDiff(cwd, { mode: "uncommitted" });
@@ -2761,7 +2858,7 @@ function registerWorkspaceRoutes(app, hosts, store, valid) {
2761
2858
  stop();
2762
2859
  subscription.release().catch(() => {});
2763
2860
  };
2764
- }, valid(c));
2861
+ }, valid(c), encodingOf(c));
2765
2862
  });
2766
2863
  /** Every connected host's schedules; a host that fails reports its error instead. */
2767
2864
  app.get("/api/schedules", async (c) => {
@@ -4135,6 +4232,10 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4135
4232
  c.header("Referrer-Policy", "no-referrer");
4136
4233
  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'");
4137
4234
  });
4235
+ const compression = options.compression !== false;
4236
+ /** How a live stream to this request is compressed. */
4237
+ const encodingOf = (c) => streamEncoding(c.req.header("Accept-Encoding"), compression);
4238
+ app.use("/api/*", compressJson(compression));
4138
4239
  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));
4139
4240
  app.use("/api/*", async (c, next) => {
4140
4241
  c.header("Cache-Control", "no-store");
@@ -4461,6 +4562,30 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4461
4562
  rowsMs: ms,
4462
4563
  renderMs: ms,
4463
4564
  firstByteMs: ms.optional(),
4565
+ via: z.enum(["latest", "stream"]).optional(),
4566
+ engine: z.enum([
4567
+ "webkit",
4568
+ "blink",
4569
+ "gecko",
4570
+ "other"
4571
+ ]).optional(),
4572
+ os: z.enum([
4573
+ "ios",
4574
+ "android",
4575
+ "macos",
4576
+ "windows",
4577
+ "linux",
4578
+ "other"
4579
+ ]).optional(),
4580
+ standalone: z.boolean().optional(),
4581
+ protocol: z.string().max(20).nullable().optional(),
4582
+ encoding: z.string().max(10).nullable().optional(),
4583
+ chunks: z.number().int().nonnegative().max(1e6).optional(),
4584
+ characters: z.number().int().nonnegative().max(1e9).optional(),
4585
+ lastChunkMs: ms.optional(),
4586
+ maxGapMs: z.number().int().nonnegative().max(36e5).optional(),
4587
+ maxGapEndMs: ms.optional(),
4588
+ arrivals: z.array(z.tuple([z.number().int().nonnegative().max(36e5), z.number().int().nonnegative().max(1e9)])).max(10).optional(),
4464
4589
  attempts: z.number().int().nonnegative().max(1e3),
4465
4590
  hidden: z.boolean(),
4466
4591
  pageAgeMs: long.optional(),
@@ -4508,7 +4633,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4508
4633
  deliverAgents(stream);
4509
4634
  directoryStreams.add(stream);
4510
4635
  return () => directoryStreams.delete(stream);
4511
- }, streamValidity(c));
4636
+ }, streamValidity(c), encodingOf(c));
4512
4637
  });
4513
4638
  app.post("/api/hosts", async (c) => {
4514
4639
  const input = z.object({
@@ -4618,6 +4743,29 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4618
4743
  return c.json({ error: error instanceof Error && error.message ? `Could not start the session: ${error.message}` : "Creation outcome unknown. Check the session list before retrying." }, 502);
4619
4744
  }
4620
4745
  });
4746
+ /** Rows as browsers get them: images the agent sent are served from here. */
4747
+ const enrichRow = (hostId, agentId) => (row) => ({
4748
+ ...row,
4749
+ item: withMessageImages(store, hostId, agentId, row.item)
4750
+ });
4751
+ /**
4752
+ * The conversation as it is now, to open it: a plain response with an end, which no proxy
4753
+ * holds back the way some held back a long-lived stream's first rows. The stream then resumes
4754
+ * from the snapshot's seq and carries only what changed.
4755
+ */
4756
+ app.get("/api/hosts/:host/agents/:agent/timeline/latest", async (c) => {
4757
+ const hostId = c.req.param("host"), agentId = c.req.param("agent");
4758
+ try {
4759
+ const reset = await hosts.timelineSnapshot(hostId, agentId);
4760
+ return c.json({
4761
+ ...reset,
4762
+ rows: reset.rows.map(enrichRow(hostId, agentId))
4763
+ });
4764
+ } catch (error) {
4765
+ if (error instanceof TimelineTimeoutError) return c.json({ error: error.message }, 504);
4766
+ throw error;
4767
+ }
4768
+ });
4621
4769
  app.get("/api/hosts/:host/agents/:agent/timeline/stream", (c) => {
4622
4770
  hosts.get(c.req.param("host"));
4623
4771
  const since = z.object({
@@ -4629,10 +4777,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4629
4777
  const stop = hosts.watchTimeline(c.req.param("host"), c.req.param("agent"), (ops) => send({
4630
4778
  type: "ops",
4631
4779
  ops: ops.map((op) => {
4632
- const enrich = (row) => ({
4633
- ...row,
4634
- item: withMessageImages(store, c.req.param("host"), c.req.param("agent"), row.item)
4635
- });
4780
+ const enrich = enrichRow(c.req.param("host"), c.req.param("agent"));
4636
4781
  return op.type === "reset" ? {
4637
4782
  ...op,
4638
4783
  rows: op.rows.map(enrich)
@@ -4659,7 +4804,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4659
4804
  stop();
4660
4805
  stopSubagents();
4661
4806
  };
4662
- }, streamValidity(c));
4807
+ }, streamValidity(c), encodingOf(c));
4663
4808
  });
4664
4809
  /** One provider subagent's conversation, read-only, live like an agent's. */
4665
4810
  app.get("/api/hosts/:host/agents/:agent/subagents/:subagent/timeline/stream", (c) => {
@@ -4667,7 +4812,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4667
4812
  return eventStream(c.req.raw.signal, (send) => hosts.watchTimeline(c.req.param("host"), c.req.param("agent"), (ops) => send({
4668
4813
  type: "ops",
4669
4814
  ops
4670
- }), c.req.param("subagent")), streamValidity(c));
4815
+ }), c.req.param("subagent")), streamValidity(c), encodingOf(c));
4671
4816
  });
4672
4817
  app.get("/api/hosts/:host/agents/:agent/subagents/:subagent/timeline", async (c) => {
4673
4818
  const cursor = z.object({
@@ -4965,13 +5110,13 @@ function createApp(store, hosts, token, webRoot, options = {}) {
4965
5110
  stop();
4966
5111
  stopHosts();
4967
5112
  };
4968
- }, streamValidity(c)));
5113
+ }, streamValidity(c), encodingOf(c)));
4969
5114
  app.get("/api/hosts/:host/agents/:agent/queue/stream", (c) => eventStream(c.req.raw.signal, (send) => {
4970
5115
  const publish = () => send(sendQueue.list(c.req.param("host"), c.req.param("agent")));
4971
5116
  const stop = sendQueue.onChange(publish);
4972
5117
  publish();
4973
5118
  return stop;
4974
- }, streamValidity(c)));
5119
+ }, streamValidity(c), encodingOf(c)));
4975
5120
  app.post("/api/hosts/:host/agents/:agent/queue/:id/control", async (c) => {
4976
5121
  const { action } = z.object({ action: z.enum([
4977
5122
  "pause",
@@ -5302,7 +5447,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
5302
5447
  }
5303
5448
  });
5304
5449
  registerHostSettings(app, hosts);
5305
- registerWorkspaceRoutes(app, hosts, store, (c) => streamValidity(c));
5450
+ registerWorkspaceRoutes(app, hosts, store, (c) => streamValidity(c), encodingOf);
5306
5451
  app.get("/api/usage", async (c) => c.json(await usage.report(c.req.query("refresh") === "1")));
5307
5452
  app.get("/api/board", (c) => c.json(store.board()));
5308
5453
  app.put("/api/board", async (c) => {
@@ -5411,7 +5556,10 @@ async function runWorker(directory, webRoot) {
5411
5556
  }
5412
5557
  const config = effectiveConfig(store, process.env);
5413
5558
  const port = Number(config.port.value), hostname = config.bind.value;
5414
- const app = createApp(store, hosts, tokenFile(tokenPath), webRoot, { pushSubject: config["push-subject"].value });
5559
+ const app = createApp(store, hosts, tokenFile(tokenPath), webRoot, {
5560
+ pushSubject: config["push-subject"].value,
5561
+ compression: config.compression.value !== "off"
5562
+ });
5415
5563
  const server = serve({
5416
5564
  fetch: app.fetch,
5417
5565
  port,
@@ -1,2 +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-Cmpdc3EH.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)+` @@
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-DV5BdS_U.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
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};
@@ -1,3 +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-CejBvgRc.js";import{n as Ne,r as Pe,t as Fe}from"./PreCodeBlock.vue_vue_type_style_index_0_lang-4BQzC8nU.js";import{n as Ie,t as x}from"./safeRaf-BDp3SJMs.js";import{o as Le}from"./index-Cmpdc3EH.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]===`
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-DbSS5ULZ.js";import{n as Ne,r as Pe,t as Fe}from"./PreCodeBlock.vue_vue_type_style_index_0_lang-CunCuyah.js";import{n as Ie,t as x}from"./safeRaf-BDp3SJMs.js";import{o as Le}from"./index-DV5BdS_U.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
2
  `?n++:t[e]===`\r`&&(n++,t[e+1]===`
3
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};
@@ -1 +1 @@
1
- import{I as e,R as t,T as n,V as r,X as i,c as a,ct as o,d as s,f as c,g as l,q as u,tt as d,v as f,y as p}from"./vue.runtime.esm-bundler-4XjPOHMM.js";import{p as m}from"./index-Cmpdc3EH.js";var h={class:`conversation-search`},g=[`disabled`],_={key:0,role:`alert`},v={key:1},y={key:2},b=[`onClick`],x=[`disabled`],S=m(n({__name:`ConversationSearch`,props:{base:{},api:{type:Function}},emits:[`jump`],setup(n,{emit:m}){let S=n,C=m,w=d(``),T=d(``),E=d(!1),D=d(!1),O=d([]),k=d(null),A=d(``),j=0,M=``;e(()=>j++);function N(){j++,O.value=[],k.value=null,D.value=!1,E.value=!1,T.value=``}u(w,N),u(()=>S.base,()=>{w.value=``,N()});async function P(e=!1){if(E.value||!w.value.trim())return;let t=++j;e||(O.value=[],k.value=null,M=w.value.trim()),E.value=!0,T.value=``;try{let n=await S.api(S.base+`/search?q=`+encodeURIComponent(M)+(e&&k.value!==null?`&cursor=`+k.value:``));if(t!==j)return;if(e&&A.value!==n.epoch)throw Error(`Conversation changed. Search again.`);A.value=n.epoch,O.value=[...new Map((e?[...O.value,...n.locations]:n.locations).map(e=>[e.seq,e])).values()],k.value=n.nextCursor,D.value=!0}catch(e){t===j&&(T.value=e.message)}finally{t===j&&(E.value=!1)}}return(e,n)=>(t(),p(`section`,h,[n[3]||=l(`p`,null,`Search user and agent messages across the full conversation history. Select a result to read it in context.`,-1),l(`form`,{onSubmit:n[1]||=s(e=>P(!1),[`prevent`])},[i(l(`input`,{"onUpdate:modelValue":n[0]||=e=>w.value=e,type:`search`,maxlength:`500`,"aria-label":`Search conversation content`,placeholder:`Search all messages…`},null,512),[[a,w.value]]),l(`button`,{class:`btn`,disabled:E.value||!w.value.trim()},`Search`,8,g)],32),T.value?(t(),p(`p`,_,o(T.value),1)):f(``,!0),D.value&&!O.value.length&&!E.value?(t(),p(`p`,v,`No matching messages.`)):f(``,!0),E.value?(t(),p(`p`,y,`Searching…`)):f(``,!0),(t(!0),p(c,null,r(O.value,e=>(t(),p(`button`,{key:e.seq,class:`btn result`,onClick:t=>C(`jump`,e.seq,A.value)},o(e.role===`assistant`?`Agent reply`:`Your message`)+` · #`+o(e.seq)+o(e.count?` · ${e.count} matches`:``)+` →`,9,b))),128)),k.value===null?f(``,!0):(t(),p(`button`,{key:3,class:`btn`,disabled:E.value,onClick:n[2]||=e=>P(!0)},`More results`,8,x))]))}}),[[`__scopeId`,`data-v-c9855449`]]);export{S as default};
1
+ import{I as e,R as t,T as n,V as r,X as i,c as a,ct as o,d as s,f as c,g as l,q as u,tt as d,v as f,y as p}from"./vue.runtime.esm-bundler-4XjPOHMM.js";import{p as m}from"./index-DV5BdS_U.js";var h={class:`conversation-search`},g=[`disabled`],_={key:0,role:`alert`},v={key:1},y={key:2},b=[`onClick`],x=[`disabled`],S=m(n({__name:`ConversationSearch`,props:{base:{},api:{type:Function}},emits:[`jump`],setup(n,{emit:m}){let S=n,C=m,w=d(``),T=d(``),E=d(!1),D=d(!1),O=d([]),k=d(null),A=d(``),j=0,M=``;e(()=>j++);function N(){j++,O.value=[],k.value=null,D.value=!1,E.value=!1,T.value=``}u(w,N),u(()=>S.base,()=>{w.value=``,N()});async function P(e=!1){if(E.value||!w.value.trim())return;let t=++j;e||(O.value=[],k.value=null,M=w.value.trim()),E.value=!0,T.value=``;try{let n=await S.api(S.base+`/search?q=`+encodeURIComponent(M)+(e&&k.value!==null?`&cursor=`+k.value:``));if(t!==j)return;if(e&&A.value!==n.epoch)throw Error(`Conversation changed. Search again.`);A.value=n.epoch,O.value=[...new Map((e?[...O.value,...n.locations]:n.locations).map(e=>[e.seq,e])).values()],k.value=n.nextCursor,D.value=!0}catch(e){t===j&&(T.value=e.message)}finally{t===j&&(E.value=!1)}}return(e,n)=>(t(),p(`section`,h,[n[3]||=l(`p`,null,`Search user and agent messages across the full conversation history. Select a result to read it in context.`,-1),l(`form`,{onSubmit:n[1]||=s(e=>P(!1),[`prevent`])},[i(l(`input`,{"onUpdate:modelValue":n[0]||=e=>w.value=e,type:`search`,maxlength:`500`,"aria-label":`Search conversation content`,placeholder:`Search all messages…`},null,512),[[a,w.value]]),l(`button`,{class:`btn`,disabled:E.value||!w.value.trim()},`Search`,8,g)],32),T.value?(t(),p(`p`,_,o(T.value),1)):f(``,!0),D.value&&!O.value.length&&!E.value?(t(),p(`p`,v,`No matching messages.`)):f(``,!0),E.value?(t(),p(`p`,y,`Searching…`)):f(``,!0),(t(!0),p(c,null,r(O.value,e=>(t(),p(`button`,{key:e.seq,class:`btn result`,onClick:t=>C(`jump`,e.seq,A.value)},o(e.role===`assistant`?`Agent reply`:`Your message`)+` · #`+o(e.seq)+o(e.count?` · ${e.count} matches`:``)+` →`,9,b))),128)),k.value===null?f(``,!0):(t(),p(`button`,{key:3,class:`btn`,disabled:E.value,onClick:n[2]||=e=>P(!0)},`More results`,8,x))]))}}),[[`__scopeId`,`data-v-c9855449`]]);export{S as default};