reifyui 0.15.2 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  Chevron,
3
+ CodeBlock,
3
4
  IcDoc,
5
+ IcDownload,
4
6
  IcGlobe,
5
7
  IcList,
6
8
  IcPaperclip,
@@ -14,7 +16,7 @@ import {
14
16
  IcThink,
15
17
  IcTool,
16
18
  IcX
17
- } from "./chunk-WAND7AYD.js";
19
+ } from "./chunk-QCISEB67.js";
18
20
 
19
21
  // src/agent-chat/tools.js
20
22
  function parseToolArgs(args) {
@@ -1848,6 +1850,409 @@ function AgentConversation(props) {
1848
1850
  ] });
1849
1851
  }
1850
1852
 
1853
+ // src/components/FileTypeIcon.jsx
1854
+ import { useEffect as useEffect3, useState as useState3 } from "react";
1855
+ import { jsx as jsx2 } from "react/jsx-runtime";
1856
+ function extOf(name) {
1857
+ const m = String(name || "").toLowerCase().match(/\.([a-z0-9]+)$/);
1858
+ return m ? m[1] : "";
1859
+ }
1860
+ var mod = null;
1861
+ var tried = false;
1862
+ function FileTypeIcon({ name, size = 36 }) {
1863
+ const [, force] = useState3(0);
1864
+ const ext = extOf(name);
1865
+ useEffect3(() => {
1866
+ if (tried || mod) return;
1867
+ tried = true;
1868
+ import("react-file-icon").then((m) => {
1869
+ mod = m;
1870
+ force((n) => n + 1);
1871
+ }).catch(() => {
1872
+ });
1873
+ }, []);
1874
+ const box = { width: size, height: Math.round(size * 1.16), display: "inline-block", flex: "0 0 auto" };
1875
+ if (!mod) {
1876
+ return /* @__PURE__ */ jsx2("span", { className: "uic-fileglyph", style: box, "aria-hidden": "true", children: /* @__PURE__ */ jsx2("span", { className: "uic-fileglyph-ext", children: (ext || "file").slice(0, 4) }) });
1877
+ }
1878
+ const { FileIcon, defaultStyles } = mod;
1879
+ const style = defaultStyles?.[ext] || {};
1880
+ return /* @__PURE__ */ jsx2("span", { style: box, children: /* @__PURE__ */ jsx2(FileIcon, { extension: ext || void 0, ...style }) });
1881
+ }
1882
+
1883
+ // src/components/FileCard.jsx
1884
+ import { useEffect as useEffect4, useState as useState4 } from "react";
1885
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
1886
+ var IcCopy = () => /* @__PURE__ */ jsxs2("svg", { width: "17", height: "17", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.9", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
1887
+ /* @__PURE__ */ jsx3("rect", { x: "9", y: "9", width: "11", height: "11", rx: "2" }),
1888
+ /* @__PURE__ */ jsx3("path", { d: "M5 15V6a2 2 0 0 1 2-2h9" })
1889
+ ] });
1890
+ var IcCheckMark = () => /* @__PURE__ */ jsx3("svg", { width: "17", height: "17", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx3("path", { d: "M5 12l5 5L20 7" }) });
1891
+ function subtitle(name, origin, bytes) {
1892
+ const parts = [(extOf(name) || "file").toUpperCase()];
1893
+ if (origin) parts.push(origin);
1894
+ if (bytes != null) parts.push(bytesLabel(bytes));
1895
+ return parts.join(" \xB7 ");
1896
+ }
1897
+ function bytesLabel(n) {
1898
+ if (n == null) return "";
1899
+ if (n < 1024) return `${n} B`;
1900
+ if (n < 1048576) return `${Math.round(n / 1024)} KB`;
1901
+ return `${(n / 1048576).toFixed(1)} MB`;
1902
+ }
1903
+ function FileCard({ name, origin = "output", bytes, onPreview, onDownload, onCopy, active = false, thumb, className = "" }) {
1904
+ const [copied, setCopied] = useState4("");
1905
+ useEffect4(() => {
1906
+ if (!copied) return void 0;
1907
+ const t = setTimeout(() => setCopied(""), 1600);
1908
+ return () => clearTimeout(t);
1909
+ }, [copied]);
1910
+ const open = onPreview ? (e) => {
1911
+ e.stopPropagation();
1912
+ onPreview();
1913
+ } : void 0;
1914
+ return /* @__PURE__ */ jsxs2(
1915
+ "div",
1916
+ {
1917
+ className: "uic-filecard" + (open ? " is-clickable" : "") + (active ? " is-active" : "") + (className ? " " + className : ""),
1918
+ "aria-current": active ? "true" : void 0,
1919
+ onClick: open,
1920
+ role: open ? "button" : void 0,
1921
+ tabIndex: open ? 0 : void 0,
1922
+ onKeyDown: open ? (e) => {
1923
+ if (e.key === "Enter" || e.key === " ") {
1924
+ e.preventDefault();
1925
+ open(e);
1926
+ }
1927
+ } : void 0,
1928
+ title: name,
1929
+ children: [
1930
+ thumb ? /* @__PURE__ */ jsx3("span", { className: "uic-filecard-thumb", children: /* @__PURE__ */ jsx3("img", { src: thumb, alt: "" }) }) : /* @__PURE__ */ jsx3("span", { className: "uic-filecard-ic", children: /* @__PURE__ */ jsx3(FileTypeIcon, { name, size: 32 }) }),
1931
+ /* @__PURE__ */ jsxs2("span", { className: "uic-filecard-meta", children: [
1932
+ /* @__PURE__ */ jsx3("span", { className: "uic-filecard-name", children: name }),
1933
+ /* @__PURE__ */ jsx3("span", { className: "uic-filecard-sub", children: subtitle(name, origin, bytes) })
1934
+ ] }),
1935
+ onCopy && /* @__PURE__ */ jsx3(
1936
+ "button",
1937
+ {
1938
+ type: "button",
1939
+ className: "uic-filecard-dl uic-filecard-copy",
1940
+ "aria-label": copied === "ok" ? "Copied" : `Copy ${name}`,
1941
+ title: copied === "ok" ? "Copied" : copied === "no" ? "Could not copy" : "Copy",
1942
+ onClick: async (e) => {
1943
+ e.stopPropagation();
1944
+ try {
1945
+ await onCopy();
1946
+ setCopied("ok");
1947
+ } catch {
1948
+ setCopied("no");
1949
+ }
1950
+ },
1951
+ children: copied === "ok" ? /* @__PURE__ */ jsx3(IcCheckMark, {}) : /* @__PURE__ */ jsx3(IcCopy, {})
1952
+ }
1953
+ ),
1954
+ onDownload && /* @__PURE__ */ jsx3(
1955
+ "button",
1956
+ {
1957
+ type: "button",
1958
+ className: "uic-filecard-dl",
1959
+ "aria-label": `Download ${name}`,
1960
+ title: "Download",
1961
+ onClick: (e) => {
1962
+ e.stopPropagation();
1963
+ onDownload();
1964
+ },
1965
+ children: /* @__PURE__ */ jsx3(IcDownload, { size: 18 })
1966
+ }
1967
+ ),
1968
+ onPreview && /* @__PURE__ */ jsx3("button", { type: "button", className: "uic-filecard-open", "aria-label": `Preview ${name}`, onClick: open, children: "Preview" })
1969
+ ]
1970
+ }
1971
+ );
1972
+ }
1973
+
1974
+ // src/components/FilePreview.jsx
1975
+ import { useEffect as useEffect5, useState as useState5 } from "react";
1976
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
1977
+ var LANG = {
1978
+ js: "javascript",
1979
+ mjs: "javascript",
1980
+ cjs: "javascript",
1981
+ jsx: "javascript",
1982
+ ts: "typescript",
1983
+ tsx: "typescript",
1984
+ py: "python",
1985
+ rb: "ruby",
1986
+ go: "go",
1987
+ rs: "rust",
1988
+ java: "java",
1989
+ c: "c",
1990
+ h: "c",
1991
+ cpp: "cpp",
1992
+ hpp: "cpp",
1993
+ cs: "csharp",
1994
+ php: "php",
1995
+ swift: "swift",
1996
+ kt: "kotlin",
1997
+ scala: "scala",
1998
+ sh: "bash",
1999
+ bash: "bash",
2000
+ zsh: "bash",
2001
+ sql: "sql",
2002
+ css: "css",
2003
+ scss: "scss",
2004
+ less: "less",
2005
+ html: "xml",
2006
+ htm: "xml",
2007
+ xml: "xml",
2008
+ svg: "xml",
2009
+ json: "json",
2010
+ yaml: "yaml",
2011
+ yml: "yaml",
2012
+ toml: "ini",
2013
+ ini: "ini",
2014
+ r: "r",
2015
+ lua: "lua",
2016
+ pl: "perl",
2017
+ dockerfile: "dockerfile",
2018
+ diff: "diff",
2019
+ md: "markdown",
2020
+ txt: "plaintext",
2021
+ log: "plaintext",
2022
+ csv: "plaintext"
2023
+ };
2024
+ var OFFICE = /* @__PURE__ */ new Set(["pptx", "ppt", "pptm", "odp", "doc", "docx", "odt", "rtf"]);
2025
+ var SHEET = /* @__PURE__ */ new Set(["xls", "xlsx", "xlsm", "xlsb", "ods"]);
2026
+ function kindOf(name, mime = "") {
2027
+ const e = extOf(name);
2028
+ if (mime.startsWith("image/") || /^(png|jpe?g|gif|webp|svg|bmp|ico|avif)$/.test(e)) return "image";
2029
+ if (mime === "application/pdf" || e === "pdf") return "pdf";
2030
+ if (mime.startsWith("video/") || ["mp4", "webm", "mov", "m4v"].includes(e)) return "video";
2031
+ if (mime.startsWith("audio/") || ["mp3", "wav", "ogg", "m4a", "flac"].includes(e)) return "audio";
2032
+ if (e === "csv" || e === "tsv") return "csv";
2033
+ if (e === "md" || e === "markdown") return "markdown";
2034
+ if (e === "html" || e === "htm") return "html";
2035
+ if (SHEET.has(e)) return "sheet";
2036
+ if (OFFICE.has(e)) return "office";
2037
+ if (mime.startsWith("text/") || LANG[e] || /^(txt|log|env|conf|cfg|gitignore)$/.test(e)) return "code";
2038
+ return "binary";
2039
+ }
2040
+ function delimitedToRows(text, sep) {
2041
+ return text.split(/\r?\n/).filter((l) => l.length).slice(0, 1e3).map((line) => {
2042
+ const out = [];
2043
+ let cur = "";
2044
+ let q = false;
2045
+ for (const ch of line) {
2046
+ if (ch === '"') q = !q;
2047
+ else if (ch === sep && !q) {
2048
+ out.push(cur);
2049
+ cur = "";
2050
+ } else cur += ch;
2051
+ }
2052
+ out.push(cur);
2053
+ return out.map((c) => c.replace(/^"|"$/g, ""));
2054
+ });
2055
+ }
2056
+ function Grid({ rows }) {
2057
+ if (!rows?.length) return /* @__PURE__ */ jsx4("div", { className: "uic-fp-empty", children: "This file is empty." });
2058
+ const [head, ...body] = rows;
2059
+ return /* @__PURE__ */ jsx4("div", { className: "uic-fp-sheet", children: /* @__PURE__ */ jsxs3("table", { children: [
2060
+ /* @__PURE__ */ jsx4("thead", { children: /* @__PURE__ */ jsx4("tr", { children: head.map((c, i) => /* @__PURE__ */ jsx4("th", { children: c }, i)) }) }),
2061
+ /* @__PURE__ */ jsx4("tbody", { children: body.map((r, i) => /* @__PURE__ */ jsx4("tr", { children: r.map((c, j) => /* @__PURE__ */ jsx4("td", { children: c }, j)) }, i)) })
2062
+ ] }) });
2063
+ }
2064
+ var defaultDownload = (url, name) => {
2065
+ const a = document.createElement("a");
2066
+ a.href = url;
2067
+ a.download = name;
2068
+ a.rel = "noreferrer";
2069
+ document.body.appendChild(a);
2070
+ a.click();
2071
+ a.remove();
2072
+ };
2073
+ function FilePreview({
2074
+ file,
2075
+ onClose,
2076
+ fetchFile,
2077
+ officePdfUrl,
2078
+ renderMarkdown,
2079
+ parseWorkbook,
2080
+ onDownload,
2081
+ title,
2082
+ before
2083
+ }) {
2084
+ const { url, name } = file || {};
2085
+ const [st, setSt] = useState5({ kind: "loading" });
2086
+ const [tab, setTab] = useState5(0);
2087
+ const [view, setView] = useState5("preview");
2088
+ useEffect5(() => {
2089
+ if (!url) return void 0;
2090
+ let alive = true;
2091
+ let obj;
2092
+ setSt({ kind: "loading" });
2093
+ setTab(0);
2094
+ setView("preview");
2095
+ const get = fetchFile || ((u) => fetch(u, { cache: "no-store" }));
2096
+ (async () => {
2097
+ const res = await get(url);
2098
+ if (!res.ok) throw new Error(`${res.status}`);
2099
+ const mime = (res.headers.get("content-type") || "").toLowerCase();
2100
+ const kind = kindOf(name, mime);
2101
+ if (kind === "office") {
2102
+ if (!officePdfUrl) {
2103
+ setSt({ kind: "binary", error: "This format has no preview here. Download it to open it." });
2104
+ return;
2105
+ }
2106
+ const r = await get(officePdfUrl(url));
2107
+ if (!r.ok) throw new Error(`${r.status}`);
2108
+ obj = URL.createObjectURL(await r.blob());
2109
+ if (alive) setSt({ kind: "pdf", objUrl: obj });
2110
+ return;
2111
+ }
2112
+ if (kind === "sheet") {
2113
+ if (!parseWorkbook) {
2114
+ setSt({ kind: "binary", error: "This format has no preview here. Download it to open it." });
2115
+ return;
2116
+ }
2117
+ try {
2118
+ const sheets = await parseWorkbook(await res.arrayBuffer());
2119
+ const first = sheets.findIndex((s) => s.filled);
2120
+ if (alive) {
2121
+ setTab(first < 0 ? 0 : first);
2122
+ setSt({ kind: "sheet", sheets });
2123
+ }
2124
+ } catch (e) {
2125
+ if (alive) setSt({ kind: "binary", error: `This spreadsheet couldn\u2019t be read (${String(e?.message || "parse failed").slice(0, 80)}).` });
2126
+ }
2127
+ return;
2128
+ }
2129
+ if (kind === "csv" || kind === "markdown" || kind === "code" || kind === "html") {
2130
+ const text = await res.text();
2131
+ if (!alive) return;
2132
+ if (kind === "csv") setSt({ kind: "csv", rows: delimitedToRows(text, extOf(name) === "tsv" ? " " : ",") });
2133
+ else setSt({ kind, text: text.slice(0, 4e5) });
2134
+ return;
2135
+ }
2136
+ if (kind === "binary") {
2137
+ if (alive) setSt({ kind: "binary" });
2138
+ return;
2139
+ }
2140
+ obj = URL.createObjectURL(await res.blob());
2141
+ if (alive) setSt({ kind, objUrl: obj });
2142
+ })().catch(() => {
2143
+ if (alive) setSt({ kind: "binary", error: "Could not load this file." });
2144
+ });
2145
+ return () => {
2146
+ alive = false;
2147
+ if (obj) URL.revokeObjectURL(obj);
2148
+ };
2149
+ }, [url, name, fetchFile, officePdfUrl, parseWorkbook]);
2150
+ const download = () => onDownload ? onDownload(url, name) : defaultDownload(url, name);
2151
+ const [copied, setCopied] = useState5("");
2152
+ useEffect5(() => {
2153
+ if (!copied) return void 0;
2154
+ const t = setTimeout(() => setCopied(""), 1600);
2155
+ return () => clearTimeout(t);
2156
+ }, [copied]);
2157
+ const copyText = typeof st.text === "string" ? st.text : null;
2158
+ const copy = async () => {
2159
+ try {
2160
+ await navigator.clipboard.writeText(copyText || "");
2161
+ setCopied("ok");
2162
+ } catch {
2163
+ setCopied("no");
2164
+ }
2165
+ };
2166
+ return /* @__PURE__ */ jsxs3("aside", { className: "uic-fp", "aria-label": title || `Preview of ${name}`, children: [
2167
+ before,
2168
+ /* @__PURE__ */ jsxs3("header", { className: "uic-fp-head", children: [
2169
+ /* @__PURE__ */ jsx4("span", { className: "uic-fp-ic", children: /* @__PURE__ */ jsx4(FileTypeIcon, { name, size: 20 }) }),
2170
+ /* @__PURE__ */ jsx4("span", { className: "uic-fp-name", title: name, children: name }),
2171
+ st.kind === "html" && /* @__PURE__ */ jsx4("div", { className: "uic-fp-seg", role: "tablist", "aria-label": "Show the page or its source", children: [["preview", "Preview"], ["source", "Source"]].map(([id, label]) => /* @__PURE__ */ jsx4(
2172
+ "button",
2173
+ {
2174
+ type: "button",
2175
+ role: "tab",
2176
+ "aria-selected": view === id,
2177
+ className: "uic-fp-seg-btn" + (view === id ? " is-on" : ""),
2178
+ onClick: () => setView(id),
2179
+ children: label
2180
+ },
2181
+ id
2182
+ )) }),
2183
+ copyText != null && /* @__PURE__ */ jsx4(
2184
+ "button",
2185
+ {
2186
+ type: "button",
2187
+ className: "uic-fp-btn uic-fp-copy",
2188
+ "aria-label": copied === "ok" ? "Copied" : `Copy ${name}`,
2189
+ title: copied === "ok" ? "Copied" : copied === "no" ? "Could not copy" : "Copy",
2190
+ onClick: copy,
2191
+ children: copied === "ok" ? /* @__PURE__ */ jsx4("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx4("path", { d: "M5 12l5 5L20 7" }) }) : /* @__PURE__ */ jsxs3("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.9", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
2192
+ /* @__PURE__ */ jsx4("rect", { x: "9", y: "9", width: "11", height: "11", rx: "2" }),
2193
+ /* @__PURE__ */ jsx4("path", { d: "M5 15V6a2 2 0 0 1 2-2h9" })
2194
+ ] })
2195
+ }
2196
+ ),
2197
+ /* @__PURE__ */ jsx4(
2198
+ "button",
2199
+ {
2200
+ type: "button",
2201
+ className: "uic-fp-btn",
2202
+ "aria-label": `Download ${name}`,
2203
+ title: "Download",
2204
+ onClick: download,
2205
+ children: /* @__PURE__ */ jsx4(IcDownload, {})
2206
+ }
2207
+ ),
2208
+ onClose && /* @__PURE__ */ jsx4(
2209
+ "button",
2210
+ {
2211
+ type: "button",
2212
+ className: "uic-fp-btn",
2213
+ "aria-label": "Close preview",
2214
+ title: "Close",
2215
+ onClick: onClose,
2216
+ children: /* @__PURE__ */ jsx4(IcX, { size: 18 })
2217
+ }
2218
+ )
2219
+ ] }),
2220
+ /* @__PURE__ */ jsxs3("div", { className: "uic-fp-body", children: [
2221
+ st.kind === "loading" && /* @__PURE__ */ jsx4("div", { className: "uic-fp-pad", children: /* @__PURE__ */ jsx4("span", { className: "uic-skel uic-fp-skel" }) }),
2222
+ st.kind === "image" && st.objUrl && /* @__PURE__ */ jsx4("div", { className: "uic-fp-center", children: /* @__PURE__ */ jsx4("img", { className: "uic-fp-img", src: st.objUrl, alt: name }) }),
2223
+ st.kind === "pdf" && st.objUrl && /* @__PURE__ */ jsx4("iframe", { className: "uic-fp-frame", src: st.objUrl, title: name }),
2224
+ st.kind === "video" && st.objUrl && /* @__PURE__ */ jsx4("div", { className: "uic-fp-center", children: /* @__PURE__ */ jsx4("video", { className: "uic-fp-media", src: st.objUrl, controls: true }) }),
2225
+ st.kind === "audio" && st.objUrl && /* @__PURE__ */ jsx4("div", { className: "uic-fp-center", children: /* @__PURE__ */ jsx4("audio", { src: st.objUrl, controls: true }) }),
2226
+ st.kind === "markdown" && /* @__PURE__ */ jsx4("div", { className: "uic-fp-doc", children: renderMarkdown ? renderMarkdown(st.text || "") : /* @__PURE__ */ jsx4("pre", { className: "uic-fp-pre", children: st.text }) }),
2227
+ st.kind === "code" && /* @__PURE__ */ jsx4(CodeBlock, { code: st.text || "", language: LANG[extOf(name)] || "plaintext" }),
2228
+ st.kind === "html" && view === "source" && /* @__PURE__ */ jsx4(CodeBlock, { code: st.text || "", language: "xml" }),
2229
+ st.kind === "html" && view === "preview" && // The page runs in its own origin with scripts only: a mockup's own script and styles
2230
+ // work, and nothing in it can read the host page, its cookies or its storage.
2231
+ /* @__PURE__ */ jsx4("iframe", { className: "uic-fp-frame", title: name, sandbox: "allow-scripts", srcDoc: st.text || "" }),
2232
+ st.kind === "csv" && /* @__PURE__ */ jsx4(Grid, { rows: st.rows }),
2233
+ st.kind === "sheet" && st.sheets && /* @__PURE__ */ jsxs3("div", { className: "uic-fp-xlsx", children: [
2234
+ st.sheets[tab]?.filled ? /* @__PURE__ */ jsx4(Grid, { rows: st.sheets[tab].rows }) : /* @__PURE__ */ jsx4("div", { className: "uic-fp-empty", children: "This sheet is empty." }),
2235
+ /* @__PURE__ */ jsx4("div", { className: "uic-fp-tabs", children: st.sheets.map((s, i) => /* @__PURE__ */ jsx4(
2236
+ "button",
2237
+ {
2238
+ type: "button",
2239
+ className: "uic-fp-tab" + (i === tab ? " is-on" : "") + (s.filled ? "" : " is-empty"),
2240
+ onClick: () => setTab(i),
2241
+ title: s.filled ? s.name : `${s.name} (empty)`,
2242
+ children: s.name
2243
+ },
2244
+ s.name + i
2245
+ )) })
2246
+ ] }),
2247
+ st.kind === "binary" && /* @__PURE__ */ jsx4("div", { className: "uic-fp-center", children: /* @__PURE__ */ jsxs3("div", { className: "uic-fp-fallback", children: [
2248
+ /* @__PURE__ */ jsx4(FileTypeIcon, { name, size: 56 }),
2249
+ /* @__PURE__ */ jsx4("p", { children: st.error || "No inline preview for this file type." }),
2250
+ /* @__PURE__ */ jsx4("button", { type: "button", className: "uic-fp-dl", onClick: download, children: "Download" })
2251
+ ] }) })
2252
+ ] })
2253
+ ] });
2254
+ }
2255
+
1851
2256
  export {
1852
2257
  parseToolArgs,
1853
2258
  toolKind,
@@ -1893,6 +2298,10 @@ export {
1893
2298
  AgentTurnView,
1894
2299
  AgentComposer,
1895
2300
  useStickToBottom,
1896
- AgentConversation
2301
+ AgentConversation,
2302
+ extOf,
2303
+ FileTypeIcon,
2304
+ FileCard,
2305
+ FilePreview
1897
2306
  };
1898
- //# sourceMappingURL=chunk-SF5QML3U.js.map
2307
+ //# sourceMappingURL=chunk-UP3CNKZR.js.map