reifyui 0.16.1 → 0.17.0

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.
@@ -38,9 +38,11 @@ __export(agent_chat_exports, {
38
38
  DiffBadge: () => DiffBadge,
39
39
  FileCard: () => FileCard,
40
40
  FilePreview: () => FilePreview,
41
+ FileSwitcher: () => FileSwitcher,
41
42
  LinesBlock: () => LinesBlock,
42
43
  MARK_MOTIONS: () => MARK_MOTIONS,
43
44
  MOTIONS: () => MOTIONS,
45
+ MidName: () => MidName,
44
46
  StepRow: () => StepRow,
45
47
  StreamingText: () => StreamingText,
46
48
  ThinkingRow: () => ThinkingRow,
@@ -62,6 +64,7 @@ __export(agent_chat_exports, {
62
64
  latestPlan: () => latestPlan,
63
65
  lineCount: () => lineCount,
64
66
  liveState: () => liveState,
67
+ middleEllipsis: () => middleEllipsis,
65
68
  motionFor: () => motionFor,
66
69
  newTurn: () => newTurn,
67
70
  parseToolArgs: () => parseToolArgs,
@@ -2301,7 +2304,8 @@ function FilePreview({
2301
2304
  parseWorkbook,
2302
2305
  onDownload,
2303
2306
  title,
2304
- before
2307
+ before,
2308
+ nameSlot
2305
2309
  }) {
2306
2310
  const { url, name } = file || {};
2307
2311
  const [st, setSt] = (0, import_react6.useState)({ kind: "loading" });
@@ -2389,7 +2393,7 @@ function FilePreview({
2389
2393
  before,
2390
2394
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("header", { className: "uic-fp-head", children: [
2391
2395
  /* @__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 }),
2396
+ nameSlot || /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "uic-fp-name", title: name, children: name }),
2393
2397
  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
2398
  "button",
2395
2399
  {
@@ -2475,8 +2479,218 @@ function FilePreview({
2475
2479
  ] });
2476
2480
  }
2477
2481
 
2482
+ // src/format.js
2483
+ function bytesLabel(n) {
2484
+ if (n == null) return "";
2485
+ if (n < 1024) return `${n} B`;
2486
+ if (n < 1048576) return `${Math.round(n / 1024)} KB`;
2487
+ return `${(n / 1048576).toFixed(1)} MB`;
2488
+ }
2489
+
2478
2490
  // src/agent-chat/artifacts.jsx
2479
2491
  var import_jsx_runtime6 = require("react/jsx-runtime");
2492
+ var FILTER_AT = 8;
2493
+ function middleEllipsis(name, max = 40) {
2494
+ const s = String(name || "");
2495
+ if (s.length <= max) return s;
2496
+ const tail = Math.min(Math.max(10, Math.floor(max * 0.45)), max - 4);
2497
+ return `${s.slice(0, max - tail - 1)}\u2026${s.slice(-tail)}`;
2498
+ }
2499
+ function MidName(props) {
2500
+ const { name, className } = props;
2501
+ const s = String(name || "");
2502
+ const cut = s.length > 16 ? s.length - Math.min(14, Math.floor(s.length / 2)) : s.length;
2503
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "uac-mid" + (className ? ` ${className}` : ""), children: [
2504
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "uac-mid-h", children: s.slice(0, cut) }),
2505
+ cut < s.length ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "uac-mid-t", children: s.slice(cut) }) : null
2506
+ ] });
2507
+ }
2508
+ function dirOf(path) {
2509
+ const p = String(path || "");
2510
+ const i = p.lastIndexOf("/");
2511
+ return i > 0 ? p.slice(0, i) : "";
2512
+ }
2513
+ function Check() {
2514
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M5 12l5 5L20 7" }) });
2515
+ }
2516
+ function FileSwitcher(props) {
2517
+ const { files, current, onSelect, label = "Files in this conversation", turnLabel = (n) => `Turn ${n}` } = props;
2518
+ const [open, setOpen] = (0, import_react7.useState)(false);
2519
+ const [q, setQ] = (0, import_react7.useState)("");
2520
+ const [hi, setHi] = (0, import_react7.useState)(0);
2521
+ const root = (0, import_react7.useRef)(null);
2522
+ const list = (0, import_react7.useRef)(null);
2523
+ const input = (0, import_react7.useRef)(null);
2524
+ const btn = (0, import_react7.useRef)(null);
2525
+ const id = (0, import_react7.useRef)(`uac-fs-${Math.random().toString(36).slice(2, 9)}`).current;
2526
+ const cur = files.find((f) => f.key === current) || files[0];
2527
+ const needle = q.trim().toLowerCase();
2528
+ const shown = (0, import_react7.useMemo)(() => files.filter((f) => !needle || String(f.path || f.name).toLowerCase().includes(needle)), [files, needle]);
2529
+ const groups = (0, import_react7.useMemo)(() => {
2530
+ const by = /* @__PURE__ */ new Map();
2531
+ for (const f of shown) {
2532
+ const d = dirOf(f.path);
2533
+ if (!by.has(d)) by.set(d, []);
2534
+ by.get(d).push(f);
2535
+ }
2536
+ return [...by.entries()].sort((a, b) => a[0] === "" ? -1 : b[0] === "" ? 1 : 0);
2537
+ }, [shown]);
2538
+ const flat = groups.flatMap(([, fs]) => fs);
2539
+ const grouped = groups.length > 1 || groups.length === 1 && groups[0][0] !== "";
2540
+ const many = files.length > FILTER_AT;
2541
+ (0, import_react7.useEffect)(() => {
2542
+ if (!open) return void 0;
2543
+ setHi(Math.max(0, flat.findIndex((f) => f.key === (cur && cur.key))));
2544
+ const t = setTimeout(() => {
2545
+ if (many && input.current) input.current.focus();
2546
+ else if (list.current) list.current.focus();
2547
+ }, 0);
2548
+ const away = (e) => {
2549
+ if (root.current && !root.current.contains(e.target)) setOpen(false);
2550
+ };
2551
+ document.addEventListener("mousedown", away);
2552
+ document.addEventListener("touchstart", away);
2553
+ return () => {
2554
+ clearTimeout(t);
2555
+ document.removeEventListener("mousedown", away);
2556
+ document.removeEventListener("touchstart", away);
2557
+ };
2558
+ }, [open]);
2559
+ (0, import_react7.useEffect)(() => {
2560
+ setHi(0);
2561
+ }, [needle]);
2562
+ (0, import_react7.useEffect)(() => {
2563
+ if (!open || !list.current) return;
2564
+ const el = list.current.querySelector(`[data-i="${hi}"]`);
2565
+ if (el && el.scrollIntoView) el.scrollIntoView({ block: "nearest" });
2566
+ }, [hi, open]);
2567
+ if (!cur) return null;
2568
+ const pick = (f) => {
2569
+ setOpen(false);
2570
+ setQ("");
2571
+ if (f && onSelect) onSelect(f.key);
2572
+ if (btn.current) btn.current.focus();
2573
+ };
2574
+ const keys = (e) => {
2575
+ if (e.key === "ArrowDown") {
2576
+ e.preventDefault();
2577
+ setHi((i2) => Math.min(flat.length - 1, i2 + 1));
2578
+ } else if (e.key === "ArrowUp") {
2579
+ e.preventDefault();
2580
+ setHi((i2) => Math.max(0, i2 - 1));
2581
+ } else if (e.key === "Home") {
2582
+ e.preventDefault();
2583
+ setHi(0);
2584
+ } else if (e.key === "End") {
2585
+ e.preventDefault();
2586
+ setHi(flat.length - 1);
2587
+ } else if (e.key === "Enter") {
2588
+ e.preventDefault();
2589
+ pick(flat[hi]);
2590
+ } else if (e.key === "Escape") {
2591
+ e.preventDefault();
2592
+ e.stopPropagation();
2593
+ setOpen(false);
2594
+ if (btn.current) btn.current.focus();
2595
+ } else if (e.key === "Tab") setOpen(false);
2596
+ };
2597
+ const single = files.length < 2;
2598
+ let i = -1;
2599
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { ref: root, className: "uac-fs" + (open ? " is-open" : ""), children: [
2600
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2601
+ "button",
2602
+ {
2603
+ ref: btn,
2604
+ type: "button",
2605
+ className: "uac-fs-btn",
2606
+ title: cur.path || cur.name,
2607
+ disabled: single,
2608
+ "aria-haspopup": single ? void 0 : "listbox",
2609
+ "aria-expanded": single ? void 0 : open,
2610
+ "aria-controls": single ? void 0 : id,
2611
+ onClick: () => setOpen((v) => !v),
2612
+ onKeyDown: (e) => {
2613
+ if (!single && (e.key === "ArrowDown" || e.key === "ArrowUp")) {
2614
+ e.preventDefault();
2615
+ setOpen(true);
2616
+ }
2617
+ },
2618
+ children: [
2619
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MidName, { name: cur.name, className: "uac-fs-name" }),
2620
+ single ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("svg", { className: "uac-fs-chev", width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M6 9l6 6 6-6" }) })
2621
+ ]
2622
+ }
2623
+ ),
2624
+ open ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2625
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "uac-fs-scrim", "aria-hidden": "true", onClick: () => setOpen(false) }),
2626
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "uac-fs-pop", onKeyDown: keys, children: [
2627
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "uac-fs-head", children: [
2628
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: label }),
2629
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "uac-fs-count", children: files.length })
2630
+ ] }),
2631
+ many ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2632
+ "input",
2633
+ {
2634
+ ref: input,
2635
+ className: "uac-fs-q",
2636
+ type: "search",
2637
+ placeholder: "Find a file",
2638
+ value: q,
2639
+ autoComplete: "off",
2640
+ spellCheck: false,
2641
+ "aria-label": "Find a file",
2642
+ "aria-controls": id,
2643
+ onChange: (e) => setQ(e.target.value)
2644
+ }
2645
+ ) : null,
2646
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2647
+ "div",
2648
+ {
2649
+ ref: list,
2650
+ id,
2651
+ className: "uac-fs-list",
2652
+ role: "listbox",
2653
+ tabIndex: -1,
2654
+ "aria-label": label,
2655
+ "aria-activedescendant": flat[hi] ? `${id}-${hi}` : void 0,
2656
+ children: [
2657
+ groups.map(([dir, fs]) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { role: "group", "aria-label": dir || "Top level", children: [
2658
+ grouped ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "uac-fs-dir", "aria-hidden": "true", children: dir || "Top level" }) : null,
2659
+ fs.map((f) => {
2660
+ i += 1;
2661
+ const n = i;
2662
+ const on = f.key === cur.key;
2663
+ const meta = [f.size != null ? bytesLabel(f.size) : "", f.turn != null ? turnLabel(f.turn) : ""].filter(Boolean).join(" \xB7 ");
2664
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2665
+ "div",
2666
+ {
2667
+ id: `${id}-${n}`,
2668
+ "data-i": n,
2669
+ role: "option",
2670
+ "aria-selected": on,
2671
+ className: "uac-fs-opt" + (on ? " is-on" : "") + (n === hi ? " is-hi" : ""),
2672
+ title: f.path || f.name,
2673
+ onMouseEnter: () => setHi(n),
2674
+ onClick: () => pick(f),
2675
+ children: [
2676
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FileTypeIcon, { name: f.name, size: 16 }),
2677
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MidName, { name: f.name, className: "uac-fs-on" }),
2678
+ meta ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "uac-fs-meta", children: meta }) : null,
2679
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "uac-fs-ck", children: on ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Check, {}) : null })
2680
+ ]
2681
+ },
2682
+ f.key
2683
+ );
2684
+ })
2685
+ ] }, dir || ".")),
2686
+ !flat.length ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "uac-fs-none", children: "No file matches." }) : null
2687
+ ]
2688
+ }
2689
+ )
2690
+ ] })
2691
+ ] }) : null
2692
+ ] });
2693
+ }
2480
2694
  function ArtifactPanel(props) {
2481
2695
  const {
2482
2696
  files = [],
@@ -2485,6 +2699,7 @@ function ArtifactPanel(props) {
2485
2699
  onClose,
2486
2700
  overlay = false,
2487
2701
  label = "Files in this conversation",
2702
+ turnLabel,
2488
2703
  fetchFile,
2489
2704
  renderMarkdown,
2490
2705
  officePdfUrl,
@@ -2502,7 +2717,7 @@ function ArtifactPanel(props) {
2502
2717
  if (b) b.focus();
2503
2718
  }, 0);
2504
2719
  const key = (e) => {
2505
- if (e.key === "Escape") {
2720
+ if (e.key === "Escape" && !e.defaultPrevented) {
2506
2721
  e.stopPropagation();
2507
2722
  onClose && onClose();
2508
2723
  }
@@ -2515,21 +2730,7 @@ function ArtifactPanel(props) {
2515
2730
  };
2516
2731
  }, [overlay, !!cur]);
2517
2732
  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;
2733
+ const switcher = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FileSwitcher, { files, current: cur.key, onSelect, label, turnLabel });
2533
2734
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2534
2735
  overlay ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "uac-art-scrim", "aria-hidden": "true", onClick: () => onClose && onClose() }) : null,
2535
2736
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
@@ -2545,7 +2746,7 @@ function ArtifactPanel(props) {
2545
2746
  {
2546
2747
  file: { url: cur.url, name: cur.name },
2547
2748
  onClose,
2548
- before: switcher,
2749
+ nameSlot: switcher,
2549
2750
  fetchFile,
2550
2751
  renderMarkdown,
2551
2752
  officePdfUrl,
@@ -2570,10 +2771,10 @@ var IcCheckMark = () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", { wi
2570
2771
  function subtitle(name, origin, bytes) {
2571
2772
  const parts = [(extOf(name) || "file").toUpperCase()];
2572
2773
  if (origin) parts.push(origin);
2573
- if (bytes != null) parts.push(bytesLabel(bytes));
2774
+ if (bytes != null) parts.push(bytesLabel2(bytes));
2574
2775
  return parts.join(" \xB7 ");
2575
2776
  }
2576
- function bytesLabel(n) {
2777
+ function bytesLabel2(n) {
2577
2778
  if (n == null) return "";
2578
2779
  if (n < 1024) return `${n} B`;
2579
2780
  if (n < 1048576) return `${Math.round(n / 1024)} KB`;