@av-pi-studio/workbench 0.0.122 → 0.0.124

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 (62) hide show
  1. package/README.md +16 -4
  2. package/dist/chunks/{BinaryFallbackViewer-EznEIpRC.js → BinaryFallbackViewer-ua5VmtNP.js} +1 -1
  3. package/dist/chunks/{ChatPanel-DgJlK-yP.js → ChatPanel-9mV7jLOD.js} +3 -3
  4. package/dist/chunks/{CodeView-klpk8qD0.js → CodeView--Yo9YYpl.js} +2 -2
  5. package/dist/chunks/{FilePanel-Beg5Fs8X.js → FilePanel-CBNc1csX.js} +2 -2
  6. package/dist/chunks/HtmlViewer-BjvrS29T.js +539 -0
  7. package/dist/chunks/{ImageViewer-BLrsKWwI.js → ImageViewer-DQFVe58O.js} +1 -1
  8. package/dist/chunks/{MarkdownFileViewer-DxJJlrsv.js → MarkdownFileViewer-BEaGxGyd.js} +4 -4
  9. package/dist/chunks/{ModelProvidersPanel-C3TXoq1L.js → ModelProvidersPanel-CUdM6FMu.js} +2 -2
  10. package/dist/chunks/{MoleculeViewerPanel-BAWs5F2j.js → MoleculeViewerPanel-DhkadYBP.js} +3 -3
  11. package/dist/chunks/{PdfViewer-B_kiY-Tw.js → PdfViewer-PKAEVwco.js} +2 -2
  12. package/dist/chunks/{SaveFileButton-Bsz3wG4a.js → SaveFileButton-qwf_ewMX.js} +1 -1
  13. package/dist/chunks/SettingsDialog-ChDFOPih.js +454 -0
  14. package/dist/chunks/{SkillsPanel-BB5_yrcx.js → SkillsPanel-DP72YesV.js} +1 -1
  15. package/dist/chunks/{TerminalPanel-DgH4re05.js → TerminalPanel-BKnfLGNl.js} +1 -1
  16. package/dist/chunks/{TextViewer-BiwFYLLc.js → TextViewer-ZT99BjEP.js} +2 -2
  17. package/dist/chunks/{VideoViewer-BSGjTTQR.js → VideoViewer-C_gj8A0b.js} +1 -1
  18. package/dist/chunks/{ViewersPanel-BYHmKfOh.js → ViewersPanel-CTRov7NQ.js} +1 -1
  19. package/dist/chunks/external-link-BsgjS-QP.js +24 -0
  20. package/dist/chunks/{href-resolution-AtzN0oCd.js → href-resolution-AG-Co7Sm.js} +1 -1
  21. package/dist/chunks/index-CitLJdIo.js +7415 -0
  22. package/dist/chunks/{markdown-CypQ7TkY.js → markdown-CVWWeRbe.js} +97 -90
  23. package/dist/chunks/{use-file-download-zheHRdGQ.js → use-file-download-DbQCEsRG.js} +1 -1
  24. package/dist/chunks/{use-file-watch-CyVeSj2A.js → use-file-watch-CrgiCMCF.js} +1 -1
  25. package/dist/chunks/{use-provider-auth-list-jNjjSAD_.js → use-provider-auth-list-Bcdz9-zE.js} +1 -1
  26. package/dist/features/connection/ConnectionBar.d.ts +4 -0
  27. package/dist/features/connection/DaemonSwitcher.d.ts +16 -0
  28. package/dist/features/connection/daemon-switcher-presentation.d.ts +69 -0
  29. package/dist/features/connection/outdated-daemon.d.ts +17 -0
  30. package/dist/features/connection/use-outdated-daemon-notice.d.ts +26 -0
  31. package/dist/features/daemons/DaemonForm.d.ts +18 -0
  32. package/dist/features/daemons/DaemonsScreen.d.ts +17 -0
  33. package/dist/features/daemons/connect-current.d.ts +19 -0
  34. package/dist/features/daemons/daemon-form-actions.d.ts +27 -0
  35. package/dist/features/daemons/daemon-form.d.ts +103 -0
  36. package/dist/features/daemons/daemon-lifecycle.d.ts +58 -0
  37. package/dist/features/daemons/daemon-presentation.d.ts +46 -0
  38. package/dist/features/daemons/daemons-screen-actions.d.ts +37 -0
  39. package/dist/features/daemons/daemons-screen-view.d.ts +62 -0
  40. package/dist/features/daemons/daemons-store.d.ts +30 -0
  41. package/dist/features/daemons/use-daemon-lifecycle.d.ts +3 -0
  42. package/dist/features/daemons/use-daemons.d.ts +8 -0
  43. package/dist/features/files/preview-mounts.d.ts +25 -0
  44. package/dist/features/sessions/RenameSessionDialog.d.ts +8 -0
  45. package/dist/features/sessions/rename-title.d.ts +6 -0
  46. package/dist/features/sessions/session-actions.d.ts +6 -5
  47. package/dist/hooks/use-connection.d.ts +17 -5
  48. package/dist/host/browser-files.d.ts +2 -2
  49. package/dist/host/browser-host.d.ts +6 -1
  50. package/dist/host/types.d.ts +149 -2
  51. package/dist/index.d.ts +1 -1
  52. package/dist/index.js +1 -1
  53. package/dist/lib/connection/connect-failure.d.ts +14 -0
  54. package/dist/lib/connection/connection-store.d.ts +7 -1
  55. package/dist/stores/session-rename-store.d.ts +13 -0
  56. package/dist/styles.css +1 -1
  57. package/dist/timeline/FileLink.d.ts +4 -2
  58. package/dist/timeline/external-href.d.ts +9 -0
  59. package/package.json +4 -4
  60. package/dist/chunks/HtmlViewer-KGQcSEm3.js +0 -490
  61. package/dist/chunks/SettingsDialog-AHnoT7nN.js +0 -471
  62. package/dist/chunks/index-QzeFcHmH.js +0 -6261
package/README.md CHANGED
@@ -116,8 +116,8 @@ provider. Mount `ToastViewport` and `Announcer` yourself (the default shell does
116
116
  | `useConnection()` | `{ status, serverInfo, error, connect(options), disconnect() }` |
117
117
  | `useShellLayout()` | `{ left, right }`, each `{ collapsed, width, toggle(), resize(delta) }` |
118
118
  | `useSettingsDialog()` | `{ open, openSettings(), closeSettings() }` |
119
- | `createBrowserHost(options?)` | The browser host (`options.app`, `options.pdf`) |
120
- | Types | `WorkbenchHost` and its member types (below), `WorkbenchProviderProps`, `SettingsDialogProps`, `WorkbenchConnection`, `SidebarLayout`, `ConnectOptions`, `BrowserHostOptions` |
119
+ | `createBrowserHost(options?)` | The browser host (`options.app`, `options.pdf`, `options.saveTarget`) |
120
+ | Types | `WorkbenchHost` and its member types (below), `WorkbenchProviderProps`, `SettingsDialogProps`, `WorkbenchConnection`, `SidebarLayout`, `ConnectOptions`, `BrowserHostOptions`, `SaveTarget` |
121
121
 
122
122
  Entries: `.` (the above), `./styles.css`, `./fonts.css`, `./vite` (Node, for `vite.config.ts`).
123
123
 
@@ -132,8 +132,8 @@ render; the first host wins (a later different one is ignored, with a developmen
132
132
  | `app` | `{ title, version, platform? }`: shown in the top bar; `platform` is sent as `hello.platform` (the desktop app passes `"desktop"`; a browser omits it) |
133
133
  | `storage` | `{ get(key): string \| null, set(key, value) }`. **Synchronous**: stores read it while initialising. If your storage is asynchronous, load it into memory before the first render and write behind. Never throws |
134
134
  | `clipboard.writeText(text)` | Promise; rejects on failure |
135
- | `dialogs.confirm/alert/prompt` | Promises. Dismissal resolves `false` / `null` |
136
- | `links.openExternal?(url)` | Optional. When present, every external link calls it instead of navigating |
135
+ | `dialogs.confirm/alert` | Promises. Dismissal resolves `false` / nothing. Session rename is not a host dialog: the workbench draws its own |
136
+ | `links.openExternal?(url)` | Optional. When present, every external link (login dialog, messages, Markdown files) calls it and the default navigation is suppressed; when absent the link opens in a new tab (`target="_blank"`, `rel="noreferrer"`) |
137
137
  | `launch.initialConnect()` | Read once at boot: `{ url?, password?, cwd?, connect } \| null`. `url` may be a pairing link |
138
138
  | `launch.agentDeepLink` | `{ current(), subscribe(listener), consume() }`: "open this agent" requests |
139
139
  | `connection.createTransport(target, { password })` | The `Transport` for one connect, or `undefined` for the SDK's WebSocket. `target` is `{ mode: "direct", url }` or `{ mode: "relay", url, daemonPublicKey }`. **A transport must deliver frames in wire order and binary frames as `ArrayBuffer`.** Throwing fails that connect with your message |
@@ -144,6 +144,18 @@ render; the first host wins (a later different one is ignored, with a developmen
144
144
  | `files.openForView(path)` | `{ url, mimeType?, fileName?, release() }` for viewers; `release` is called when the URL is unused |
145
145
  | `files.pickUploads?()` | Optional native picker, replacing the file input |
146
146
  | `pdf?` | Optional `{ createWorker(), assetBaseUrl }`. Without it PDFs show an error with Download |
147
+ | `preview?` | Optional `{ kind: "origin", mount(html) → Promise<{ url, release() }> }`: the HTML viewer loads its frame from `url` instead of `srcdoc` (same sandbox; `release` when replaced or unmounted), or `{ kind: "inert" }`: `srcdoc` with a "Scripts are disabled" line. Absent: `srcdoc`, unchanged |
148
+ | `daemons?` | Optional daemon registry (`HostDaemons`): `snapshot()` (entries without secrets, current id, local daemon state, the two local-daemon settings), `subscribe`, `add`/`update`/`remove`, `local.start/stop/restart/refresh`, `setSettings`, `resolveCurrent()`, `switchTo(id)`, `onManageRequest`. Rejections carry a `code` (`DaemonError`, a type only). Absent in a browser. Read by the switcher and the Daemons screen |
149
+ | `app.minDaemonVersion?` | Optional oldest daemon version the shell expects; an older daemon still connects and gets a notice. Read by the connection bar |
150
+
151
+ `createBrowserHost({ saveTarget })` lets a shell own where a saved file goes while keeping the
152
+ browser host's download logic. `saveTarget(suggestedName)` returns a `SaveTarget`
153
+ (`write(chunk)`, `finish()`, `discard()`, all promises) or `null` when the user cancelled (nothing
154
+ happens). The file is then fetched in 8 MiB ranges: the first learns its size and modification time,
155
+ later ones send them as `ifUnchanged`; each range's chunks go through `write`, awaited in order,
156
+ before the next range is asked for, so memory stays bounded however slow the target is. `finish()`
157
+ runs after the last range; on any failure `discard()` runs once and the original error is rethrown.
158
+ Without `saveTarget`, "Download" builds a `Blob` and clicks an anchor.
147
159
 
148
160
  ## PDF viewing
149
161
 
@@ -1,6 +1,6 @@
1
1
  import { jsxs as n, jsx as e } from "react/jsx-runtime";
2
2
  import { FileQuestion as s } from "lucide-react";
3
- import { S as l } from "./SaveFileButton-Bsz3wG4a.js";
3
+ import { S as l } from "./SaveFileButton-qwf_ewMX.js";
4
4
  const o = "piwb-BinaryFallbackViewer_wrap_FwVTc", c = "piwb-BinaryFallbackViewer_name_6bPhR", a = {
5
5
  wrap: o,
6
6
  name: c
@@ -1,14 +1,14 @@
1
1
  import { jsxs as l, jsx as n, Fragment as $ } from "react/jsx-runtime";
2
2
  import { useEffect as I, useState as D, useRef as O, Fragment as dn, useCallback as Ae, useMemo as un, useId as mn } from "react";
3
3
  import { useQueryClient as pn, useQuery as Fe } from "@tanstack/react-query";
4
- import { t as Oe, c as K, d as hn, u as ee, o as fn, e as gn, f as wn, h as _t, i as vt, n as kt, j as bn, k as _n, l as vn, m as Ct, p as kn, q as ye, r as $e, s as we, v as Cn, w as yn, x as Ce, y as Nn, z as Tn, A as Sn, B as lt, C as Dn, D as xn, E as Bn, F as An, G as dt } from "./index-QzeFcHmH.js";
4
+ import { t as Oe, c as K, d as hn, u as ee, o as fn, e as gn, f as wn, h as _t, i as vt, n as kt, j as bn, k as _n, l as vn, m as Ct, p as kn, q as ye, r as $e, s as we, v as Cn, w as yn, x as Ce, y as Nn, z as Tn, A as Sn, B as lt, C as Dn, D as xn, E as Bn, F as An, G as dt } from "./index-CitLJdIo.js";
5
5
  import { ListTree as En, Globe as Mn, Search as Rn, FilePlus as Pn, Pencil as On, Eye as Ln, Terminal as yt, HelpCircle as Te, Check as be, Bot as In, Brain as Nt, ChevronRight as _e, ArrowUpRight as Fn, Clock as $n, GitFork as zn, User as Hn, CircleAlert as Tt, ArrowDown as Kn, Plus as Wn, Slash as qn, Cpu as Un, ChevronDown as ut, Square as Gn, Navigation as Yn, ArrowUp as Vn, Circle as jn } from "lucide-react";
6
6
  import { Icon as R, Button as F, TextInput as Qn, TextArea as St, Spinner as re, Dialog as Xn, IconButton as Jn, EmptyState as Zn, MenuContent as ze, groupOptions as eo, filterOptions as Dt, MenuGroup as to, Panel as mt } from "@av-pi-studio/ui-library";
7
7
  import { useVirtualizer as no, measureElement as oo } from "@tanstack/react-virtual";
8
- import { u as so } from "./use-provider-auth-list-jNjjSAD_.js";
8
+ import { u as so } from "./use-provider-auth-list-Bcdz9-zE.js";
9
9
  import { clsx as B } from "clsx";
10
10
  import { remainingMs as ro } from "@av-pi-studio/client";
11
- import { S as xt, M as He, r as io } from "./markdown-CypQ7TkY.js";
11
+ import { S as xt, M as He, r as io } from "./markdown-CVWWeRbe.js";
12
12
  import { D as ao, p as co } from "./DiffView-BqDuT3CF.js";
13
13
  import * as Z from "@radix-ui/react-dropdown-menu";
14
14
  import { AGENT_TODOS_MAX_TASKS as lo } from "@av-pi-studio/protocol";
@@ -1,6 +1,6 @@
1
1
  import { useQuery as u } from "@tanstack/react-query";
2
- import { u as g, r as d } from "./index-QzeFcHmH.js";
3
- import { u as m } from "./use-file-download-zheHRdGQ.js";
2
+ import { u as g, r as d } from "./index-CitLJdIo.js";
3
+ import { u as m } from "./use-file-download-DbQCEsRG.js";
4
4
  import { jsx as a } from "react/jsx-runtime";
5
5
  import { useState as E, useEffect as p } from "react";
6
6
  import w from "@uiw/react-codemirror";
@@ -3,8 +3,8 @@ import { useEffect as _, useState as m, Suspense as F } from "react";
3
3
  import { clsx as b } from "clsx";
4
4
  import { Panel as D, Button as g, EmptyState as d, Spinner as w } from "@av-pi-studio/ui-library";
5
5
  import { useQuery as E, useQueryClient as k } from "@tanstack/react-query";
6
- import { u as P, r as f, L as K, H as q, I as z, V as C, J as N } from "./index-QzeFcHmH.js";
7
- import { u as S } from "./use-file-watch-CyVeSj2A.js";
6
+ import { u as P, r as f, L as K, H as q, I as z, V as C, J as N } from "./index-CitLJdIo.js";
7
+ import { u as S } from "./use-file-watch-CrgiCMCF.js";
8
8
  import { D as V } from "./DiffView-BqDuT3CF.js";
9
9
  function x(e, o, r, i = !0) {
10
10
  const a = P((n) => n.client);
@@ -0,0 +1,539 @@
1
+ import { jsx as p, jsxs as m } from "react/jsx-runtime";
2
+ import { useState as R, useMemo as S, useEffect as Z } from "react";
3
+ import { useQueryClient as ge, useQuery as we } from "@tanstack/react-query";
4
+ import { EmptyState as L, Spinner as P, Button as $, Switch as ve } from "@av-pi-studio/ui-library";
5
+ import { u as xe, C as be } from "./CodeView--Yo9YYpl.js";
6
+ import { n as ye, H as oe, _ as ke, Q as ie, u as G, i as _e, r as z, g as Ee, $ as Se } from "./index-CitLJdIo.js";
7
+ import { p as Le, S as Ne } from "./href-resolution-AG-Co7Sm.js";
8
+ import { S as Ae } from "./SaveFileButton-qwf_ewMX.js";
9
+ const D = {
10
+ maxCount: 64,
11
+ maxBytesPerAsset: 2 * 1024 * 1024,
12
+ // 2 MiB
13
+ maxBytesTotal: 16 * 1024 * 1024
14
+ // 16 MiB — base64 inflates raw bytes ~33%; this cap keeps the
15
+ // assembled `srcdoc` string off the main thread as a multi-hundred-MB allocation.
16
+ };
17
+ function X(n, t, e) {
18
+ return !(n >= D.maxCount || e > D.maxBytesPerAsset || t + e > D.maxBytesTotal);
19
+ }
20
+ function ae(n) {
21
+ return n === "" || n.startsWith("#") ? "unsupported" : n.startsWith("//") || Ne.test(n) ? "external" : null;
22
+ }
23
+ function Ce(n, t, e) {
24
+ return e !== null && t === e ? n : t;
25
+ }
26
+ function le(n, t, e, s, r = null) {
27
+ const o = n.trim(), c = ae(o);
28
+ if (c) return { kind: "skip", raw: n, reason: c };
29
+ const a = Le(o);
30
+ let h;
31
+ if (a.startsWith("/") ? h = a : a === "~" || a.startsWith("~/") ? h = r !== null ? ye(a, r) : null : h = oe(a, t), !h) return { kind: "skip", raw: n, reason: "unsupported" };
32
+ const v = ke(h);
33
+ return v !== e && !v.startsWith(`${e}/`) ? { kind: "skip", raw: n, reason: "outside-workspace" } : { kind: "local", raw: n, path: v, context: s };
34
+ }
35
+ const Te = {
36
+ css: "text/css",
37
+ js: "text/javascript",
38
+ mjs: "text/javascript",
39
+ html: "text/html",
40
+ htm: "text/html",
41
+ json: "application/json",
42
+ png: "image/png",
43
+ jpg: "image/jpeg",
44
+ jpeg: "image/jpeg",
45
+ gif: "image/gif",
46
+ webp: "image/webp",
47
+ svg: "image/svg+xml",
48
+ ico: "image/x-icon",
49
+ bmp: "image/bmp",
50
+ avif: "image/avif",
51
+ mp4: "video/mp4",
52
+ webm: "video/webm",
53
+ mov: "video/quicktime",
54
+ m4v: "video/x-m4v",
55
+ ogv: "video/ogg",
56
+ mp3: "audio/mpeg",
57
+ wav: "audio/wav",
58
+ oga: "audio/ogg",
59
+ ogg: "audio/ogg",
60
+ m4a: "audio/mp4",
61
+ woff: "font/woff",
62
+ woff2: "font/woff2",
63
+ ttf: "font/ttf",
64
+ otf: "font/otf",
65
+ eot: "application/vnd.ms-fontobject"
66
+ };
67
+ function Be(n) {
68
+ const t = n.lastIndexOf("/"), e = n.lastIndexOf(".");
69
+ return e <= t ? "application/octet-stream" : Te[n.slice(e + 1).toLowerCase()] ?? "application/octet-stream";
70
+ }
71
+ function Re(n) {
72
+ let t = "";
73
+ for (let s = 0; s < n.length; s += 32768)
74
+ t += String.fromCharCode(...n.subarray(s, s + 32768));
75
+ return btoa(t);
76
+ }
77
+ function Y(n, t) {
78
+ return `data:${n};base64,${Re(t)}`;
79
+ }
80
+ const I = /<([a-zA-Z][a-zA-Z0-9]*)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*)(\s*\/?>)/g, F = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/g;
81
+ function ce(n) {
82
+ const t = /* @__PURE__ */ new Map();
83
+ F.lastIndex = 0;
84
+ let e;
85
+ for (; e = F.exec(n); ) {
86
+ const s = e[1].toLowerCase();
87
+ t.has(s) || t.set(s, e[2] ?? e[3] ?? e[4] ?? "");
88
+ }
89
+ return t;
90
+ }
91
+ function ue(n, t) {
92
+ switch (n) {
93
+ case "link": {
94
+ const e = t.get("rel") ?? "";
95
+ return /(^|\s)stylesheet(\s|$)/i.test(e) ? t.has("href") ? [{ name: "href", context: "style", multi: !1 }] : [] : [];
96
+ }
97
+ case "script":
98
+ return t.has("src") ? [{ name: "src", context: "script", multi: !1 }] : [];
99
+ case "img": {
100
+ const e = [];
101
+ return t.has("src") && e.push({ name: "src", context: "image", multi: !1 }), t.has("srcset") && e.push({ name: "srcset", context: "image", multi: !0 }), e;
102
+ }
103
+ case "source": {
104
+ const e = [];
105
+ return t.has("src") && e.push({ name: "src", context: "media", multi: !1 }), t.has("srcset") && e.push({ name: "srcset", context: "media", multi: !0 }), e;
106
+ }
107
+ case "video": {
108
+ const e = [];
109
+ return t.has("src") && e.push({ name: "src", context: "media", multi: !1 }), t.has("poster") && e.push({ name: "poster", context: "media", multi: !1 }), e;
110
+ }
111
+ case "audio":
112
+ return t.has("src") ? [{ name: "src", context: "media", multi: !1 }] : [];
113
+ default:
114
+ return [];
115
+ }
116
+ }
117
+ function de(n) {
118
+ return n.split(",").map((t) => t.trim()).filter((t) => t !== "").map((t) => {
119
+ const e = t.search(/\s/);
120
+ return e === -1 ? { url: t, descriptor: "" } : { url: t.slice(0, e), descriptor: t.slice(e).trim() };
121
+ });
122
+ }
123
+ function He(n) {
124
+ return n.map((t) => t.descriptor ? `${t.url} ${t.descriptor}` : t.url).join(", ");
125
+ }
126
+ function K(n, t, e) {
127
+ ae(t.trim()) || n.has(t) || n.set(t, { raw: t, context: e });
128
+ }
129
+ function Me(n) {
130
+ const t = /* @__PURE__ */ new Map();
131
+ I.lastIndex = 0;
132
+ let e;
133
+ for (; e = I.exec(n); ) {
134
+ const s = e[1].toLowerCase(), r = ce(e[2] ?? "");
135
+ for (const o of ue(s, r)) {
136
+ const c = r.get(o.name) ?? "";
137
+ if (o.multi)
138
+ for (const a of de(c)) K(t, a.url, o.context);
139
+ else
140
+ K(t, c, o.context);
141
+ }
142
+ }
143
+ return [...t.values()];
144
+ }
145
+ function Pe(n, t) {
146
+ let e = !1;
147
+ const s = de(n).map((r) => {
148
+ const o = t[r.url];
149
+ return o === void 0 ? r : (e = !0, { url: o, descriptor: r.descriptor });
150
+ });
151
+ return e ? He(s) : null;
152
+ }
153
+ function ze(n, t) {
154
+ return Object.keys(t).length === 0 ? n : (I.lastIndex = 0, n.replace(I, (e, s, r, o) => {
155
+ const c = ce(r), a = ue(s.toLowerCase(), c);
156
+ if (a.length === 0) return e;
157
+ const h = new Map(a.map((d) => [d.name, d]));
158
+ let v = !1;
159
+ const H = r.replace(
160
+ F,
161
+ (d, f, l, x, k) => {
162
+ const b = h.get(f.toLowerCase());
163
+ if (!b) return d;
164
+ const g = l ?? x ?? k ?? "", N = b.multi ? Pe(g, t) : t[g] ?? null;
165
+ return N === null ? d : (v = !0, `${f}="${N}"`);
166
+ }
167
+ );
168
+ return v ? `<${s}${H}${o}` : e;
169
+ }));
170
+ }
171
+ const V = /url\(\s*(?:"([^"]*)"|'([^']*)'|([^'")\s]*))\s*\)/gi, J = /@font-face\s*\{[^}]*\}/gi;
172
+ function fe(n, t, e) {
173
+ return n ?? t ?? e ?? "";
174
+ }
175
+ function je(n) {
176
+ const t = [];
177
+ J.lastIndex = 0;
178
+ let e;
179
+ for (; e = J.exec(n); ) t.push([e.index, e.index + e[0].length]);
180
+ return t;
181
+ }
182
+ function Ie(n) {
183
+ const t = je(n), e = /* @__PURE__ */ new Map();
184
+ V.lastIndex = 0;
185
+ let s;
186
+ for (; s = V.exec(n); ) {
187
+ const r = fe(s[1], s[2], s[3]), o = t.some(
188
+ ([c, a]) => s.index >= c && s.index < a
189
+ ) ? "font" : "image";
190
+ K(e, r, o);
191
+ }
192
+ return [...e.values()];
193
+ }
194
+ function Ve(n, t) {
195
+ return Object.keys(t).length === 0 ? n : (V.lastIndex = 0, n.replace(V, (e, s, r, o) => {
196
+ const c = t[fe(s, r, o)];
197
+ return c === void 0 ? e : `url("${c}")`;
198
+ }));
199
+ }
200
+ const Oe = Object.freeze(["allow-scripts"]), $e = "https://pi-studio-preview.invalid/", De = "default-src 'none'; img-src data:; style-src 'unsafe-inline' data:; script-src 'unsafe-inline' data:; font-src data:; media-src data:", Fe = `<script>(function(){document.addEventListener("click",function(e){var a=e.target&&e.target.closest&&e.target.closest('a[href^="#"]');if(!a)return;var frag=a.getAttribute("href").slice(1);e.preventDefault();if(!frag){window.scrollTo(0,0);return;}var el=document.getElementById(frag)||document.getElementsByName(frag)[0];if(el)el.scrollIntoView();},true);})();<\/script>`, Ke = /<head(\s[^>]*)?>/i, qe = /<html(\s[^>]*)?>/i, Ue = /<base[\s/>]/i;
201
+ function Qe(n, t) {
202
+ const e = ze(n, t.assets ?? {}), s = [];
203
+ t.blockRemote && s.push(
204
+ `<meta http-equiv="Content-Security-Policy" content="${De}">`
205
+ ), Ue.test(e) || (s.push(`<base href="${$e}">`), s.push(Fe));
206
+ const r = s.join("");
207
+ if (r === "") return e;
208
+ const o = Ke.exec(e);
209
+ if (o) {
210
+ const a = o.index + o[0].length;
211
+ return e.slice(0, a) + r + e.slice(a);
212
+ }
213
+ const c = qe.exec(e);
214
+ if (c) {
215
+ const a = c.index + c[0].length;
216
+ return e.slice(0, a) + `<head>${r}</head>` + e.slice(a);
217
+ }
218
+ return `<head>${r}</head>` + e;
219
+ }
220
+ function We() {
221
+ let n = 0, t = null;
222
+ return {
223
+ begin: () => ++n,
224
+ isCurrent: (e) => e === n,
225
+ settle: (e, s) => {
226
+ if (e !== n)
227
+ return s.release(), !1;
228
+ const r = t;
229
+ return t = s, r && r !== s && r.release(), !0;
230
+ },
231
+ dispose: () => {
232
+ n++;
233
+ const e = t;
234
+ t = null, e?.release();
235
+ }
236
+ };
237
+ }
238
+ const ee = 6;
239
+ async function te(n, t, e) {
240
+ let s = 0;
241
+ async function r() {
242
+ for (; s < n.length; ) {
243
+ const o = n[s];
244
+ s += 1, await e(o);
245
+ }
246
+ }
247
+ await Promise.all(Array.from({ length: Math.min(t, n.length) }, r));
248
+ }
249
+ function ne(n) {
250
+ const t = /* @__PURE__ */ new Map();
251
+ for (const e of n) {
252
+ const s = t.get(e.path);
253
+ s ? s.push(e) : t.set(e.path, [e]);
254
+ }
255
+ return t;
256
+ }
257
+ async function Ze(n, t) {
258
+ const e = {}, s = [];
259
+ let r = 0, o = 0, c = !1;
260
+ const a = [];
261
+ for (const d of n)
262
+ d.kind === "skip" ? s.push({ raw: d.raw, reason: d.reason }) : a.push(d);
263
+ function h(d, f) {
264
+ for (const l of d) s.push({ raw: l.raw, reason: f });
265
+ }
266
+ async function v(d, f) {
267
+ if (c) {
268
+ h(f, "over-cap");
269
+ return;
270
+ }
271
+ let l;
272
+ try {
273
+ l = await t.fetchBytes(d);
274
+ } catch {
275
+ h(f, "fetch-failed");
276
+ return;
277
+ }
278
+ if (!X(r, o, l.byteLength)) {
279
+ c = !0, h(f, "over-cap");
280
+ return;
281
+ }
282
+ if (r += 1, o += l.byteLength, f[0].context !== "style") {
283
+ const u = Y(Be(d), l);
284
+ for (const y of f) e[y.raw] = u;
285
+ return;
286
+ }
287
+ const x = new TextDecoder().decode(l), k = ie(d), b = Ie(x).map(
288
+ (u) => le(u.raw, k, t.root, u.context, t.homeDir)
289
+ ), g = [];
290
+ for (const u of b)
291
+ u.kind === "skip" ? s.push({ raw: u.raw, reason: u.reason }) : g.push(u);
292
+ const N = ne(g);
293
+ await te(
294
+ [...N.entries()],
295
+ ee,
296
+ ([u, y]) => v(u, y)
297
+ );
298
+ const M = {};
299
+ for (const u of g) {
300
+ const y = e[u.raw];
301
+ y !== void 0 && (M[u.raw] = y);
302
+ }
303
+ const A = Ve(x, M), C = new TextEncoder().encode(A), _ = C.byteLength - l.byteLength;
304
+ if (_ > 0 && !X(r - 1, o - l.byteLength, C.byteLength)) {
305
+ c = !0, h(f, "over-cap");
306
+ return;
307
+ }
308
+ o += _;
309
+ const T = Y("text/css", C);
310
+ for (const u of f) e[u.raw] = T;
311
+ }
312
+ const H = ne(a);
313
+ return await te(
314
+ [...H.entries()],
315
+ ee,
316
+ ([d, f]) => v(d, f)
317
+ ), { assets: e, skipped: s };
318
+ }
319
+ const Ge = "piwb-HtmlViewer_wrap_zVa2Y", Xe = "piwb-HtmlViewer_toolbar_BJS-C", Ye = "piwb-HtmlViewer_modeToggle_vtj-V", Je = "piwb-HtmlViewer_controls_7oQnM", et = "piwb-HtmlViewer_switchLabel_lI99i", tt = "piwb-HtmlViewer_streamedNote_Dbx4P", nt = "piwb-HtmlViewer_inertNote_7cAEL", st = "piwb-HtmlViewer_skippedNote_ITPaJ", rt = "piwb-HtmlViewer_skippedToggle_X2Aij", ot = "piwb-HtmlViewer_skippedList_cCdE1", it = "piwb-HtmlViewer_body_Ub6gT", at = "piwb-HtmlViewer_frame_feA57", lt = "piwb-HtmlViewer_tooLarge_W3dLq", w = {
320
+ wrap: Ge,
321
+ toolbar: Xe,
322
+ modeToggle: Ye,
323
+ controls: Je,
324
+ switchLabel: et,
325
+ streamedNote: tt,
326
+ inertNote: nt,
327
+ skippedNote: st,
328
+ skippedToggle: rt,
329
+ skippedList: ot,
330
+ body: it,
331
+ frame: at,
332
+ tooLarge: lt
333
+ }, se = Oe.join(" "), re = Object.freeze({}), ct = Object.freeze([]), me = {
334
+ external: "external",
335
+ "outside-workspace": "outside workspace",
336
+ unsupported: "unsupported",
337
+ "over-cap": "over cap",
338
+ "fetch-failed": "not found"
339
+ };
340
+ function ut(n) {
341
+ const t = /* @__PURE__ */ new Map();
342
+ for (const e of n) {
343
+ const s = me[e.reason];
344
+ t.set(s, (t.get(s) ?? 0) + 1);
345
+ }
346
+ return [...t.entries()].map(([e, s]) => `${s} ${e}`).join(", ");
347
+ }
348
+ function dt(n) {
349
+ let t = 2166136261;
350
+ for (let e = 0; e < n.length; e++)
351
+ t ^= n.charCodeAt(e), t = Math.imul(t, 16777619);
352
+ return (t >>> 0).toString(16);
353
+ }
354
+ function j(n) {
355
+ return `${(n / (1024 * 1024)).toFixed(1)} MB`;
356
+ }
357
+ function yt({ path: n, workspaceCwd: t }) {
358
+ const e = xe(n), [s, r] = R("preview"), [o, c] = R(!1), [a, h] = R(!1), v = ge(), H = G((i) => i.client), d = G((i) => i.daemon), f = _e(), l = e.kind === "inline" || e.kind === "streamed" ? e.content : null, x = S(() => {
359
+ const i = oe(n, t);
360
+ return i ? ie(i) : null;
361
+ }, [n, t]), k = S(
362
+ () => x !== null ? Ce(x, t, f) : null,
363
+ [x, t, f]
364
+ ), b = S(() => l === null || x === null || k === null ? [] : Me(l).map(
365
+ (i) => le(i.raw, x, k, i.context, f)
366
+ ), [l, x, k, f]), g = S(() => b.some((i) => i.kind === "local"), [b]), N = S(
367
+ () => b.flatMap(
368
+ (i) => i.kind === "skip" ? [{ raw: i.raw, reason: i.reason }] : []
369
+ ),
370
+ [b]
371
+ ), M = S(
372
+ () => g && l !== null ? dt(l) : "",
373
+ [l, g]
374
+ ), A = we({
375
+ queryKey: z.htmlAssetBundle(n, M),
376
+ queryFn: () => k === null ? Promise.resolve({ assets: {}, skipped: [] }) : Ze(b, { root: k, homeDir: f, fetchBytes: async (E) => {
377
+ if (!H || !d) throw new Error("not connected");
378
+ return (await Se(d).download(E)).bytes;
379
+ } }),
380
+ enabled: g,
381
+ // Immutable per (path, content hash) — a change is only ever observed via a new key
382
+ // (document edited) or an explicit Reload invalidation, never a background refetch.
383
+ staleTime: 1 / 0
384
+ }), C = g ? A.data?.assets ?? re : re, _ = g ? A.data?.skipped ?? ct : N, T = S(() => l === null ? null : Qe(l, { assets: C, blockRemote: o }), [l, C, o]), u = Ee().preview, y = u?.kind === "origin" && T !== null && !(g && A.data === void 0) ? T : null, O = u?.kind === "origin" ? u.mount : null, [B] = R(We), [q, pe] = R(null), [U, Q] = R(null);
385
+ Z(() => {
386
+ if (y === null || O === null) return;
387
+ const i = B.begin();
388
+ Q(null), O(y).then(
389
+ (E) => {
390
+ B.settle(i, E) && pe(E.url);
391
+ },
392
+ (E) => {
393
+ B.isCurrent(i) && Q(E instanceof Error ? E.message : String(E));
394
+ }
395
+ );
396
+ }, [y, O, B]), Z(() => () => B.dispose(), [B]);
397
+ function he() {
398
+ v.invalidateQueries({ queryKey: z.fileRead(n) }), v.invalidateQueries({ queryKey: z.fileDownload(n) }), v.invalidateQueries({ queryKey: z.htmlAssetBundleByPath(n) });
399
+ }
400
+ switch (e.kind) {
401
+ case "loading":
402
+ return /* @__PURE__ */ m(L, { children: [
403
+ /* @__PURE__ */ p(P, { size: "sm" }),
404
+ " Loading..."
405
+ ] });
406
+ case "streaming":
407
+ return /* @__PURE__ */ m(L, { children: [
408
+ /* @__PURE__ */ p(P, { size: "sm" }),
409
+ " Streaming ",
410
+ j(e.size),
411
+ " file..."
412
+ ] });
413
+ case "stream-error":
414
+ case "error":
415
+ return /* @__PURE__ */ m(L, { children: [
416
+ "Error: ",
417
+ e.message
418
+ ] });
419
+ case "too-large":
420
+ return /* @__PURE__ */ p(L, { children: /* @__PURE__ */ m("div", { className: w.tooLarge, children: [
421
+ /* @__PURE__ */ m("div", { children: [
422
+ j(e.size),
423
+ " — too large to display (display ceiling is",
424
+ " ",
425
+ j(e.maxDisplayBytes),
426
+ ")."
427
+ ] }),
428
+ /* @__PURE__ */ p(Ae, { path: n })
429
+ ] }) });
430
+ }
431
+ if (l === null || T === null) return null;
432
+ if (g && A.data === void 0)
433
+ return /* @__PURE__ */ m(L, { children: [
434
+ /* @__PURE__ */ p(P, { size: "sm" }),
435
+ " Loading assets..."
436
+ ] });
437
+ const W = n.split("/").pop() || n;
438
+ return /* @__PURE__ */ m("div", { className: w.wrap, children: [
439
+ /* @__PURE__ */ m("div", { className: w.toolbar, children: [
440
+ /* @__PURE__ */ m("div", { className: w.modeToggle, children: [
441
+ /* @__PURE__ */ p(
442
+ $,
443
+ {
444
+ size: "xs",
445
+ variant: s === "preview" ? "default" : "ghost",
446
+ onClick: () => r("preview"),
447
+ children: "Preview"
448
+ }
449
+ ),
450
+ /* @__PURE__ */ p(
451
+ $,
452
+ {
453
+ size: "xs",
454
+ variant: s === "source" ? "default" : "ghost",
455
+ onClick: () => r("source"),
456
+ children: "Source"
457
+ }
458
+ )
459
+ ] }),
460
+ /* @__PURE__ */ m("div", { className: w.controls, children: [
461
+ /* @__PURE__ */ m("label", { className: w.switchLabel, children: [
462
+ /* @__PURE__ */ p(
463
+ ve,
464
+ {
465
+ checked: o,
466
+ onCheckedChange: c,
467
+ "aria-label": "Block remote resources"
468
+ }
469
+ ),
470
+ "Block remote resources"
471
+ ] }),
472
+ /* @__PURE__ */ p($, { size: "xs", variant: "ghost", onClick: he, children: "Reload" })
473
+ ] })
474
+ ] }),
475
+ e.kind === "streamed" ? /* @__PURE__ */ m("div", { className: w.streamedNote, children: [
476
+ j(e.size),
477
+ " file streamed"
478
+ ] }) : null,
479
+ u?.kind === "inert" ? /* @__PURE__ */ p("div", { className: w.inertNote, children: "Scripts are disabled in the desktop app on this platform." }) : null,
480
+ _.length > 0 ? /* @__PURE__ */ m("div", { className: w.skippedNote, children: [
481
+ /* @__PURE__ */ m(
482
+ "button",
483
+ {
484
+ type: "button",
485
+ className: w.skippedToggle,
486
+ onClick: () => h((i) => !i),
487
+ children: [
488
+ _.length,
489
+ " reference",
490
+ _.length === 1 ? "" : "s",
491
+ " not inlined (",
492
+ ut(_),
493
+ ")"
494
+ ]
495
+ }
496
+ ),
497
+ a ? /* @__PURE__ */ p("ul", { className: w.skippedList, children: _.map((i) => /* @__PURE__ */ m("li", { children: [
498
+ i.raw,
499
+ " — ",
500
+ me[i.reason]
501
+ ] }, i.raw)) }) : null
502
+ ] }) : null,
503
+ /* @__PURE__ */ m("div", { className: w.body, children: [
504
+ u?.kind !== "origin" ? /* @__PURE__ */ p(
505
+ "iframe",
506
+ {
507
+ sandbox: se,
508
+ srcDoc: T,
509
+ referrerPolicy: "no-referrer",
510
+ allow: "",
511
+ className: w.frame,
512
+ style: s === "preview" ? void 0 : { display: "none" },
513
+ title: W
514
+ }
515
+ ) : U !== null ? s === "preview" ? /* @__PURE__ */ m(L, { children: [
516
+ "Error: ",
517
+ U
518
+ ] }) : null : q !== null ? /* @__PURE__ */ p(
519
+ "iframe",
520
+ {
521
+ sandbox: se,
522
+ src: q,
523
+ referrerPolicy: "no-referrer",
524
+ allow: "",
525
+ className: w.frame,
526
+ style: s === "preview" ? void 0 : { display: "none" },
527
+ title: W
528
+ }
529
+ ) : s === "preview" ? /* @__PURE__ */ m(L, { children: [
530
+ /* @__PURE__ */ p(P, { size: "sm" }),
531
+ " Loading..."
532
+ ] }) : null,
533
+ s === "source" ? /* @__PURE__ */ p(be, { path: n, content: l }) : null
534
+ ] })
535
+ ] });
536
+ }
537
+ export {
538
+ yt as HtmlViewer
539
+ };
@@ -1,6 +1,6 @@
1
1
  import { jsxs as o, jsx as i } from "react/jsx-runtime";
2
2
  import { EmptyState as a, Spinner as n } from "@av-pi-studio/ui-library";
3
- import { u as t } from "./use-file-download-zheHRdGQ.js";
3
+ import { u as t } from "./use-file-download-DbQCEsRG.js";
4
4
  const m = "piwb-ImageViewer_wrap_ANXrA", c = "piwb-ImageViewer_image_fw4so", s = {
5
5
  wrap: m,
6
6
  image: c
@@ -1,10 +1,10 @@
1
1
  import { jsxs as o, jsx as e } from "react/jsx-runtime";
2
2
  import { useState as f, useMemo as g } from "react";
3
3
  import { Button as m, EmptyState as a, Spinner as w } from "@av-pi-studio/ui-library";
4
- import { u as v, C as h } from "./CodeView-klpk8qD0.js";
5
- import { H as b, Q as M } from "./index-QzeFcHmH.js";
6
- import { M as k } from "./markdown-CypQ7TkY.js";
7
- import { S as N } from "./SaveFileButton-Bsz3wG4a.js";
4
+ import { u as v, C as h } from "./CodeView--Yo9YYpl.js";
5
+ import { H as b, Q as M } from "./index-CitLJdIo.js";
6
+ import { M as k } from "./markdown-CVWWeRbe.js";
7
+ import { S as N } from "./SaveFileButton-qwf_ewMX.js";
8
8
  const _ = "piwb-MarkdownFileViewer_wrap_b6KEN", F = "piwb-MarkdownFileViewer_toolbar_ALfg9", S = "piwb-MarkdownFileViewer_rendered_8pDh3", x = "piwb-MarkdownFileViewer_streamedNote_wlOSB", y = "piwb-MarkdownFileViewer_tooLarge_1oWTj", t = {
9
9
  wrap: _,
10
10
  toolbar: F,
@@ -2,8 +2,8 @@ import { jsxs as l, jsx as t, Fragment as R } from "react/jsx-runtime";
2
2
  import { useState as v } from "react";
3
3
  import { useQueryClient as q } from "@tanstack/react-query";
4
4
  import { EmptyState as g, Spinner as E, StatusBadge as p, Button as y } from "@av-pi-studio/ui-library";
5
- import { u as I, g as T, r as L } from "./index-QzeFcHmH.js";
6
- import { u as x } from "./use-provider-auth-list-jNjjSAD_.js";
5
+ import { u as I, g as T, r as L } from "./index-CitLJdIo.js";
6
+ import { u as x } from "./use-provider-auth-list-Bcdz9-zE.js";
7
7
  import { u as _ } from "./provider-auth-store-C1GaLTlw.js";
8
8
  const N = "env:";
9
9
  function O(n) {