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.
@@ -16,15 +16,15 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
20
20
  // If the importer is in node compatibility mode or this is not an ESM
21
21
  // file that has been converted to a CommonJS file using a Babel-
22
22
  // compatible transform (i.e. "__esModule" has not been set), then set
23
23
  // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
24
+ isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
25
+ mod2
26
26
  ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
28
28
 
29
29
  // src/agent-chat/index.js
30
30
  var agent_chat_exports = {};
@@ -32,9 +32,12 @@ __export(agent_chat_exports, {
32
32
  AgentComposer: () => AgentComposer,
33
33
  AgentConversation: () => AgentConversation,
34
34
  AgentTurnView: () => AgentTurnView,
35
+ ArtifactPanel: () => ArtifactPanel,
35
36
  CopyButton: () => CopyButton,
36
37
  DEFAULT_AGENT_LABELS: () => DEFAULT_AGENT_LABELS,
37
38
  DiffBadge: () => DiffBadge,
39
+ FileCard: () => FileCard,
40
+ FilePreview: () => FilePreview,
38
41
  LinesBlock: () => LinesBlock,
39
42
  MARK_MOTIONS: () => MARK_MOTIONS,
40
43
  MOTIONS: () => MOTIONS,
@@ -1219,6 +1222,11 @@ var IcSend = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: 16, ch
1219
1222
  ] });
1220
1223
  var IcX = ({ size = 14 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { s: size, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M18 6 6 18M6 6l12 12" }) });
1221
1224
  var IcPaperclip = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { s: size, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M21.4 11.1 12.2 20.3a5.5 5.5 0 0 1-7.8-7.8l9.2-9.2a3.7 3.7 0 0 1 5.2 5.2l-9.2 9.2a1.8 1.8 0 0 1-2.6-2.6l8.5-8.5" }) });
1225
+ var IcDownload = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: size, children: [
1226
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }),
1227
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M7 10l5 5 5-5" }),
1228
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 15V3" })
1229
+ ] });
1222
1230
 
1223
1231
  // src/agent-chat/components.jsx
1224
1232
  var import_jsx_runtime2 = require("react/jsx-runtime");
@@ -2049,4 +2057,596 @@ function AgentConversation(props) {
2049
2057
  ] })
2050
2058
  ] });
2051
2059
  }
2060
+
2061
+ // src/agent-chat/artifacts.jsx
2062
+ var import_react7 = __toESM(require("react"), 1);
2063
+
2064
+ // src/components/FilePreview.jsx
2065
+ var import_react6 = require("react");
2066
+
2067
+ // src/components/FileTypeIcon.jsx
2068
+ var import_react4 = require("react");
2069
+ var import_jsx_runtime3 = require("react/jsx-runtime");
2070
+ function extOf(name) {
2071
+ const m = String(name || "").toLowerCase().match(/\.([a-z0-9]+)$/);
2072
+ return m ? m[1] : "";
2073
+ }
2074
+ var mod = null;
2075
+ var tried = false;
2076
+ function FileTypeIcon({ name, size = 36 }) {
2077
+ const [, force] = (0, import_react4.useState)(0);
2078
+ const ext = extOf(name);
2079
+ (0, import_react4.useEffect)(() => {
2080
+ if (tried || mod) return;
2081
+ tried = true;
2082
+ import("react-file-icon").then((m) => {
2083
+ mod = m;
2084
+ force((n) => n + 1);
2085
+ }).catch(() => {
2086
+ });
2087
+ }, []);
2088
+ const box = { width: size, height: Math.round(size * 1.16), display: "inline-block", flex: "0 0 auto" };
2089
+ if (!mod) {
2090
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "uic-fileglyph", style: box, "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "uic-fileglyph-ext", children: (ext || "file").slice(0, 4) }) });
2091
+ }
2092
+ const { FileIcon, defaultStyles } = mod;
2093
+ const style = defaultStyles?.[ext] || {};
2094
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: box, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FileIcon, { extension: ext || void 0, ...style }) });
2095
+ }
2096
+
2097
+ // src/components/CodeBlock.jsx
2098
+ var import_react5 = __toESM(require("react"), 1);
2099
+ var import_jsx_runtime4 = require("react/jsx-runtime");
2100
+ var _hljsPromise = null;
2101
+ function loadHljs() {
2102
+ if (!_hljsPromise) {
2103
+ _hljsPromise = import("highlight.js/lib/core").then((m) => m.default || m);
2104
+ }
2105
+ return _hljsPromise;
2106
+ }
2107
+ var GRAMMARS = {
2108
+ javascript: () => import("highlight.js/lib/languages/javascript"),
2109
+ typescript: () => import("highlight.js/lib/languages/typescript"),
2110
+ python: () => import("highlight.js/lib/languages/python"),
2111
+ json: () => import("highlight.js/lib/languages/json"),
2112
+ bash: () => import("highlight.js/lib/languages/bash"),
2113
+ sql: () => import("highlight.js/lib/languages/sql"),
2114
+ java: () => import("highlight.js/lib/languages/java"),
2115
+ go: () => import("highlight.js/lib/languages/go"),
2116
+ rust: () => import("highlight.js/lib/languages/rust"),
2117
+ xml: () => import("highlight.js/lib/languages/xml"),
2118
+ css: () => import("highlight.js/lib/languages/css"),
2119
+ yaml: () => import("highlight.js/lib/languages/yaml"),
2120
+ groovy: () => import("highlight.js/lib/languages/groovy")
2121
+ };
2122
+ var ALIASES = {
2123
+ js: "javascript",
2124
+ jsx: "javascript",
2125
+ mjs: "javascript",
2126
+ cjs: "javascript",
2127
+ node: "javascript",
2128
+ ts: "typescript",
2129
+ tsx: "typescript",
2130
+ py: "python",
2131
+ python3: "python",
2132
+ sh: "bash",
2133
+ shell: "bash",
2134
+ zsh: "bash",
2135
+ console: "bash",
2136
+ html: "xml",
2137
+ xhtml: "xml",
2138
+ svg: "xml",
2139
+ yml: "yaml",
2140
+ golang: "go",
2141
+ rs: "rust",
2142
+ jsonc: "json",
2143
+ postgres: "sql",
2144
+ postgresql: "sql",
2145
+ mysql: "sql",
2146
+ plsql: "sql",
2147
+ gremlin: "groovy"
2148
+ };
2149
+ function canonicalLang(tag) {
2150
+ const t = String(tag || "").toLowerCase();
2151
+ if (!t) return null;
2152
+ const name = ALIASES[t] || t;
2153
+ return GRAMMARS[name] ? name : null;
2154
+ }
2155
+ var _ready = /* @__PURE__ */ new Map();
2156
+ function ensureLanguage(name) {
2157
+ if (!_ready.has(name)) {
2158
+ const p = Promise.all([loadHljs(), GRAMMARS[name]()]).then(([hljs, mod2]) => {
2159
+ if (!hljs.getLanguage(name)) hljs.registerLanguage(name, mod2.default || mod2);
2160
+ return hljs;
2161
+ }).catch(() => null);
2162
+ _ready.set(name, p);
2163
+ }
2164
+ return _ready.get(name);
2165
+ }
2166
+ function CodeBlock(props) {
2167
+ const { code, language, className } = props;
2168
+ const src = String(code || "");
2169
+ const lang = canonicalLang(language);
2170
+ const [hl, setHl] = import_react5.default.useState(null);
2171
+ import_react5.default.useEffect(() => {
2172
+ if (!lang || !src) return void 0;
2173
+ let cancelled = false;
2174
+ const timer = setTimeout(() => {
2175
+ ensureLanguage(lang).then((hljs) => {
2176
+ if (!hljs || cancelled) return;
2177
+ try {
2178
+ const out = hljs.highlight(src, { language: lang, ignoreIllegals: true });
2179
+ if (!cancelled) setHl({ src, html: out.value });
2180
+ } catch {
2181
+ }
2182
+ });
2183
+ }, 200);
2184
+ return () => {
2185
+ cancelled = true;
2186
+ clearTimeout(timer);
2187
+ };
2188
+ }, [src, lang]);
2189
+ const html = hl && hl.src === src ? hl.html : null;
2190
+ const label = String(language || "").toLowerCase();
2191
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("pre", { className: "wbx-code" + (className ? " " + className : ""), children: [
2192
+ label ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "wbx-code-lang", "aria-hidden": "true", children: label }) : null,
2193
+ html != null ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("code", { className: "hljs language-" + label, dangerouslySetInnerHTML: { __html: html } }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("code", { className: label ? "language-" + label : void 0, children: src })
2194
+ ] });
2195
+ }
2196
+
2197
+ // src/components/FilePreview.jsx
2198
+ var import_jsx_runtime5 = require("react/jsx-runtime");
2199
+ var LANG = {
2200
+ js: "javascript",
2201
+ mjs: "javascript",
2202
+ cjs: "javascript",
2203
+ jsx: "javascript",
2204
+ ts: "typescript",
2205
+ tsx: "typescript",
2206
+ py: "python",
2207
+ rb: "ruby",
2208
+ go: "go",
2209
+ rs: "rust",
2210
+ java: "java",
2211
+ c: "c",
2212
+ h: "c",
2213
+ cpp: "cpp",
2214
+ hpp: "cpp",
2215
+ cs: "csharp",
2216
+ php: "php",
2217
+ swift: "swift",
2218
+ kt: "kotlin",
2219
+ scala: "scala",
2220
+ sh: "bash",
2221
+ bash: "bash",
2222
+ zsh: "bash",
2223
+ sql: "sql",
2224
+ css: "css",
2225
+ scss: "scss",
2226
+ less: "less",
2227
+ html: "xml",
2228
+ htm: "xml",
2229
+ xml: "xml",
2230
+ svg: "xml",
2231
+ json: "json",
2232
+ yaml: "yaml",
2233
+ yml: "yaml",
2234
+ toml: "ini",
2235
+ ini: "ini",
2236
+ r: "r",
2237
+ lua: "lua",
2238
+ pl: "perl",
2239
+ dockerfile: "dockerfile",
2240
+ diff: "diff",
2241
+ md: "markdown",
2242
+ txt: "plaintext",
2243
+ log: "plaintext",
2244
+ csv: "plaintext"
2245
+ };
2246
+ var OFFICE = /* @__PURE__ */ new Set(["pptx", "ppt", "pptm", "odp", "doc", "docx", "odt", "rtf"]);
2247
+ var SHEET = /* @__PURE__ */ new Set(["xls", "xlsx", "xlsm", "xlsb", "ods"]);
2248
+ function kindOf(name, mime = "") {
2249
+ const e = extOf(name);
2250
+ if (mime.startsWith("image/") || /^(png|jpe?g|gif|webp|svg|bmp|ico|avif)$/.test(e)) return "image";
2251
+ if (mime === "application/pdf" || e === "pdf") return "pdf";
2252
+ if (mime.startsWith("video/") || ["mp4", "webm", "mov", "m4v"].includes(e)) return "video";
2253
+ if (mime.startsWith("audio/") || ["mp3", "wav", "ogg", "m4a", "flac"].includes(e)) return "audio";
2254
+ if (e === "csv" || e === "tsv") return "csv";
2255
+ if (e === "md" || e === "markdown") return "markdown";
2256
+ if (e === "html" || e === "htm") return "html";
2257
+ if (SHEET.has(e)) return "sheet";
2258
+ if (OFFICE.has(e)) return "office";
2259
+ if (mime.startsWith("text/") || LANG[e] || /^(txt|log|env|conf|cfg|gitignore)$/.test(e)) return "code";
2260
+ return "binary";
2261
+ }
2262
+ function delimitedToRows(text, sep) {
2263
+ return text.split(/\r?\n/).filter((l) => l.length).slice(0, 1e3).map((line) => {
2264
+ const out = [];
2265
+ let cur = "";
2266
+ let q = false;
2267
+ for (const ch of line) {
2268
+ if (ch === '"') q = !q;
2269
+ else if (ch === sep && !q) {
2270
+ out.push(cur);
2271
+ cur = "";
2272
+ } else cur += ch;
2273
+ }
2274
+ out.push(cur);
2275
+ return out.map((c) => c.replace(/^"|"$/g, ""));
2276
+ });
2277
+ }
2278
+ function Grid({ rows }) {
2279
+ if (!rows?.length) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-empty", children: "This file is empty." });
2280
+ const [head, ...body] = rows;
2281
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-sheet", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("table", { children: [
2282
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { children: head.map((c, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("th", { children: c }, i)) }) }),
2283
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tbody", { children: body.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { children: r.map((c, j) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { children: c }, j)) }, i)) })
2284
+ ] }) });
2285
+ }
2286
+ var defaultDownload = (url, name) => {
2287
+ const a = document.createElement("a");
2288
+ a.href = url;
2289
+ a.download = name;
2290
+ a.rel = "noreferrer";
2291
+ document.body.appendChild(a);
2292
+ a.click();
2293
+ a.remove();
2294
+ };
2295
+ function FilePreview({
2296
+ file,
2297
+ onClose,
2298
+ fetchFile,
2299
+ officePdfUrl,
2300
+ renderMarkdown,
2301
+ parseWorkbook,
2302
+ onDownload,
2303
+ title,
2304
+ before
2305
+ }) {
2306
+ const { url, name } = file || {};
2307
+ const [st, setSt] = (0, import_react6.useState)({ kind: "loading" });
2308
+ const [tab, setTab] = (0, import_react6.useState)(0);
2309
+ const [view, setView] = (0, import_react6.useState)("preview");
2310
+ (0, import_react6.useEffect)(() => {
2311
+ if (!url) return void 0;
2312
+ let alive = true;
2313
+ let obj;
2314
+ setSt({ kind: "loading" });
2315
+ setTab(0);
2316
+ setView("preview");
2317
+ const get = fetchFile || ((u) => fetch(u, { cache: "no-store" }));
2318
+ (async () => {
2319
+ const res = await get(url);
2320
+ if (!res.ok) throw new Error(`${res.status}`);
2321
+ const mime = (res.headers.get("content-type") || "").toLowerCase();
2322
+ const kind = kindOf(name, mime);
2323
+ if (kind === "office") {
2324
+ if (!officePdfUrl) {
2325
+ setSt({ kind: "binary", error: "This format has no preview here. Download it to open it." });
2326
+ return;
2327
+ }
2328
+ const r = await get(officePdfUrl(url));
2329
+ if (!r.ok) throw new Error(`${r.status}`);
2330
+ obj = URL.createObjectURL(await r.blob());
2331
+ if (alive) setSt({ kind: "pdf", objUrl: obj });
2332
+ return;
2333
+ }
2334
+ if (kind === "sheet") {
2335
+ if (!parseWorkbook) {
2336
+ setSt({ kind: "binary", error: "This format has no preview here. Download it to open it." });
2337
+ return;
2338
+ }
2339
+ try {
2340
+ const sheets = await parseWorkbook(await res.arrayBuffer());
2341
+ const first = sheets.findIndex((s) => s.filled);
2342
+ if (alive) {
2343
+ setTab(first < 0 ? 0 : first);
2344
+ setSt({ kind: "sheet", sheets });
2345
+ }
2346
+ } catch (e) {
2347
+ if (alive) setSt({ kind: "binary", error: `This spreadsheet couldn\u2019t be read (${String(e?.message || "parse failed").slice(0, 80)}).` });
2348
+ }
2349
+ return;
2350
+ }
2351
+ if (kind === "csv" || kind === "markdown" || kind === "code" || kind === "html") {
2352
+ const text = await res.text();
2353
+ if (!alive) return;
2354
+ if (kind === "csv") setSt({ kind: "csv", rows: delimitedToRows(text, extOf(name) === "tsv" ? " " : ",") });
2355
+ else setSt({ kind, text: text.slice(0, 4e5) });
2356
+ return;
2357
+ }
2358
+ if (kind === "binary") {
2359
+ if (alive) setSt({ kind: "binary" });
2360
+ return;
2361
+ }
2362
+ obj = URL.createObjectURL(await res.blob());
2363
+ if (alive) setSt({ kind, objUrl: obj });
2364
+ })().catch(() => {
2365
+ if (alive) setSt({ kind: "binary", error: "Could not load this file." });
2366
+ });
2367
+ return () => {
2368
+ alive = false;
2369
+ if (obj) URL.revokeObjectURL(obj);
2370
+ };
2371
+ }, [url, name, fetchFile, officePdfUrl, parseWorkbook]);
2372
+ const download = () => onDownload ? onDownload(url, name) : defaultDownload(url, name);
2373
+ const [copied, setCopied] = (0, import_react6.useState)("");
2374
+ (0, import_react6.useEffect)(() => {
2375
+ if (!copied) return void 0;
2376
+ const t = setTimeout(() => setCopied(""), 1600);
2377
+ return () => clearTimeout(t);
2378
+ }, [copied]);
2379
+ const copyText = typeof st.text === "string" ? st.text : null;
2380
+ const copy = async () => {
2381
+ try {
2382
+ await navigator.clipboard.writeText(copyText || "");
2383
+ setCopied("ok");
2384
+ } catch {
2385
+ setCopied("no");
2386
+ }
2387
+ };
2388
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("aside", { className: "uic-fp", "aria-label": title || `Preview of ${name}`, children: [
2389
+ before,
2390
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("header", { className: "uic-fp-head", children: [
2391
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "uic-fp-ic", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FileTypeIcon, { name, size: 20 }) }),
2392
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "uic-fp-name", title: name, children: name }),
2393
+ st.kind === "html" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-seg", role: "tablist", "aria-label": "Show the page or its source", children: [["preview", "Preview"], ["source", "Source"]].map(([id, label]) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2394
+ "button",
2395
+ {
2396
+ type: "button",
2397
+ role: "tab",
2398
+ "aria-selected": view === id,
2399
+ className: "uic-fp-seg-btn" + (view === id ? " is-on" : ""),
2400
+ onClick: () => setView(id),
2401
+ children: label
2402
+ },
2403
+ id
2404
+ )) }),
2405
+ copyText != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2406
+ "button",
2407
+ {
2408
+ type: "button",
2409
+ className: "uic-fp-btn uic-fp-copy",
2410
+ "aria-label": copied === "ok" ? "Copied" : `Copy ${name}`,
2411
+ title: copied === "ok" ? "Copied" : copied === "no" ? "Could not copy" : "Copy",
2412
+ onClick: copy,
2413
+ children: copied === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M5 12l5 5L20 7" }) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("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: [
2414
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("rect", { x: "9", y: "9", width: "11", height: "11", rx: "2" }),
2415
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M5 15V6a2 2 0 0 1 2-2h9" })
2416
+ ] })
2417
+ }
2418
+ ),
2419
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2420
+ "button",
2421
+ {
2422
+ type: "button",
2423
+ className: "uic-fp-btn",
2424
+ "aria-label": `Download ${name}`,
2425
+ title: "Download",
2426
+ onClick: download,
2427
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(IcDownload, {})
2428
+ }
2429
+ ),
2430
+ onClose && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2431
+ "button",
2432
+ {
2433
+ type: "button",
2434
+ className: "uic-fp-btn",
2435
+ "aria-label": "Close preview",
2436
+ title: "Close",
2437
+ onClick: onClose,
2438
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(IcX, { size: 18 })
2439
+ }
2440
+ )
2441
+ ] }),
2442
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "uic-fp-body", children: [
2443
+ st.kind === "loading" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-pad", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "uic-skel uic-fp-skel" }) }),
2444
+ st.kind === "image" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { className: "uic-fp-img", src: st.objUrl, alt: name }) }),
2445
+ st.kind === "pdf" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("iframe", { className: "uic-fp-frame", src: st.objUrl, title: name }),
2446
+ st.kind === "video" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("video", { className: "uic-fp-media", src: st.objUrl, controls: true }) }),
2447
+ st.kind === "audio" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("audio", { src: st.objUrl, controls: true }) }),
2448
+ st.kind === "markdown" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-doc", children: renderMarkdown ? renderMarkdown(st.text || "") : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", { className: "uic-fp-pre", children: st.text }) }),
2449
+ st.kind === "code" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CodeBlock, { code: st.text || "", language: LANG[extOf(name)] || "plaintext" }),
2450
+ st.kind === "html" && view === "source" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CodeBlock, { code: st.text || "", language: "xml" }),
2451
+ st.kind === "html" && view === "preview" && // The page runs in its own origin with scripts only: a mockup's own script and styles
2452
+ // work, and nothing in it can read the host page, its cookies or its storage.
2453
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("iframe", { className: "uic-fp-frame", title: name, sandbox: "allow-scripts", srcDoc: st.text || "" }),
2454
+ st.kind === "csv" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Grid, { rows: st.rows }),
2455
+ st.kind === "sheet" && st.sheets && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "uic-fp-xlsx", children: [
2456
+ st.sheets[tab]?.filled ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Grid, { rows: st.sheets[tab].rows }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-empty", children: "This sheet is empty." }),
2457
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-tabs", children: st.sheets.map((s, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2458
+ "button",
2459
+ {
2460
+ type: "button",
2461
+ className: "uic-fp-tab" + (i === tab ? " is-on" : "") + (s.filled ? "" : " is-empty"),
2462
+ onClick: () => setTab(i),
2463
+ title: s.filled ? s.name : `${s.name} (empty)`,
2464
+ children: s.name
2465
+ },
2466
+ s.name + i
2467
+ )) })
2468
+ ] }),
2469
+ st.kind === "binary" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "uic-fp-fallback", children: [
2470
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FileTypeIcon, { name, size: 56 }),
2471
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: st.error || "No inline preview for this file type." }),
2472
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "uic-fp-dl", onClick: download, children: "Download" })
2473
+ ] }) })
2474
+ ] })
2475
+ ] });
2476
+ }
2477
+
2478
+ // src/agent-chat/artifacts.jsx
2479
+ var import_jsx_runtime6 = require("react/jsx-runtime");
2480
+ function ArtifactPanel(props) {
2481
+ const {
2482
+ files = [],
2483
+ active,
2484
+ onSelect,
2485
+ onClose,
2486
+ overlay = false,
2487
+ label = "Files in this conversation",
2488
+ fetchFile,
2489
+ renderMarkdown,
2490
+ officePdfUrl,
2491
+ parseWorkbook,
2492
+ onDownload,
2493
+ className
2494
+ } = props;
2495
+ const ref = (0, import_react7.useRef)(null);
2496
+ const cur = files.find((f) => f.key === active) || files[0] || null;
2497
+ (0, import_react7.useEffect)(() => {
2498
+ if (!overlay || !cur) return void 0;
2499
+ const back = document.activeElement;
2500
+ const t = setTimeout(() => {
2501
+ const b = ref.current && ref.current.querySelector("button");
2502
+ if (b) b.focus();
2503
+ }, 0);
2504
+ const key = (e) => {
2505
+ if (e.key === "Escape") {
2506
+ e.stopPropagation();
2507
+ onClose && onClose();
2508
+ }
2509
+ };
2510
+ document.addEventListener("keydown", key);
2511
+ return () => {
2512
+ clearTimeout(t);
2513
+ document.removeEventListener("keydown", key);
2514
+ if (back && back.focus) back.focus();
2515
+ };
2516
+ }, [overlay, !!cur]);
2517
+ if (!cur) return null;
2518
+ const switcher = files.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("nav", { className: "uac-art-files", "aria-label": label, children: files.map((f) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2519
+ "button",
2520
+ {
2521
+ type: "button",
2522
+ className: "uac-art-file" + (f.key === cur.key ? " is-on" : ""),
2523
+ "aria-current": f.key === cur.key ? "true" : void 0,
2524
+ title: f.name,
2525
+ onClick: () => onSelect && onSelect(f.key),
2526
+ children: [
2527
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FileTypeIcon, { name: f.name, size: 14 }),
2528
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: f.name })
2529
+ ]
2530
+ },
2531
+ f.key
2532
+ )) }) : null;
2533
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2534
+ overlay ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "uac-art-scrim", "aria-hidden": "true", onClick: () => onClose && onClose() }) : null,
2535
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2536
+ "div",
2537
+ {
2538
+ ref,
2539
+ className: "uac-art" + (overlay ? " is-overlay" : "") + (className ? ` ${className}` : ""),
2540
+ role: overlay ? "dialog" : void 0,
2541
+ "aria-modal": overlay ? "true" : void 0,
2542
+ "aria-label": overlay ? `Preview of ${cur.name}` : void 0,
2543
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2544
+ FilePreview,
2545
+ {
2546
+ file: { url: cur.url, name: cur.name },
2547
+ onClose,
2548
+ before: switcher,
2549
+ fetchFile,
2550
+ renderMarkdown,
2551
+ officePdfUrl,
2552
+ parseWorkbook,
2553
+ onDownload
2554
+ },
2555
+ cur.key
2556
+ )
2557
+ }
2558
+ )
2559
+ ] });
2560
+ }
2561
+
2562
+ // src/components/FileCard.jsx
2563
+ var import_react8 = require("react");
2564
+ var import_jsx_runtime7 = require("react/jsx-runtime");
2565
+ var IcCopy = () => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("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: [
2566
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("rect", { x: "9", y: "9", width: "11", height: "11", rx: "2" }),
2567
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: "M5 15V6a2 2 0 0 1 2-2h9" })
2568
+ ] });
2569
+ var IcCheckMark = () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("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__ */ (0, import_jsx_runtime7.jsx)("path", { d: "M5 12l5 5L20 7" }) });
2570
+ function subtitle(name, origin, bytes) {
2571
+ const parts = [(extOf(name) || "file").toUpperCase()];
2572
+ if (origin) parts.push(origin);
2573
+ if (bytes != null) parts.push(bytesLabel(bytes));
2574
+ return parts.join(" \xB7 ");
2575
+ }
2576
+ function bytesLabel(n) {
2577
+ if (n == null) return "";
2578
+ if (n < 1024) return `${n} B`;
2579
+ if (n < 1048576) return `${Math.round(n / 1024)} KB`;
2580
+ return `${(n / 1048576).toFixed(1)} MB`;
2581
+ }
2582
+ function FileCard({ name, origin = "output", bytes, onPreview, onDownload, onCopy, active = false, thumb, className = "" }) {
2583
+ const [copied, setCopied] = (0, import_react8.useState)("");
2584
+ (0, import_react8.useEffect)(() => {
2585
+ if (!copied) return void 0;
2586
+ const t = setTimeout(() => setCopied(""), 1600);
2587
+ return () => clearTimeout(t);
2588
+ }, [copied]);
2589
+ const open = onPreview ? (e) => {
2590
+ e.stopPropagation();
2591
+ onPreview();
2592
+ } : void 0;
2593
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2594
+ "div",
2595
+ {
2596
+ className: "uic-filecard" + (open ? " is-clickable" : "") + (active ? " is-active" : "") + (className ? " " + className : ""),
2597
+ "aria-current": active ? "true" : void 0,
2598
+ onClick: open,
2599
+ role: open ? "button" : void 0,
2600
+ tabIndex: open ? 0 : void 0,
2601
+ onKeyDown: open ? (e) => {
2602
+ if (e.key === "Enter" || e.key === " ") {
2603
+ e.preventDefault();
2604
+ open(e);
2605
+ }
2606
+ } : void 0,
2607
+ title: name,
2608
+ children: [
2609
+ thumb ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "uic-filecard-thumb", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src: thumb, alt: "" }) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "uic-filecard-ic", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FileTypeIcon, { name, size: 32 }) }),
2610
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "uic-filecard-meta", children: [
2611
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "uic-filecard-name", children: name }),
2612
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "uic-filecard-sub", children: subtitle(name, origin, bytes) })
2613
+ ] }),
2614
+ onCopy && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2615
+ "button",
2616
+ {
2617
+ type: "button",
2618
+ className: "uic-filecard-dl uic-filecard-copy",
2619
+ "aria-label": copied === "ok" ? "Copied" : `Copy ${name}`,
2620
+ title: copied === "ok" ? "Copied" : copied === "no" ? "Could not copy" : "Copy",
2621
+ onClick: async (e) => {
2622
+ e.stopPropagation();
2623
+ try {
2624
+ await onCopy();
2625
+ setCopied("ok");
2626
+ } catch {
2627
+ setCopied("no");
2628
+ }
2629
+ },
2630
+ children: copied === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IcCheckMark, {}) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IcCopy, {})
2631
+ }
2632
+ ),
2633
+ onDownload && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2634
+ "button",
2635
+ {
2636
+ type: "button",
2637
+ className: "uic-filecard-dl",
2638
+ "aria-label": `Download ${name}`,
2639
+ title: "Download",
2640
+ onClick: (e) => {
2641
+ e.stopPropagation();
2642
+ onDownload();
2643
+ },
2644
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IcDownload, { size: 18 })
2645
+ }
2646
+ ),
2647
+ onPreview && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "uic-filecard-open", "aria-label": `Preview ${name}`, onClick: open, children: "Preview" })
2648
+ ]
2649
+ }
2650
+ );
2651
+ }
2052
2652
  //# sourceMappingURL=agent-chat.cjs.map