reifyui 0.16.1 → 0.18.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,
@@ -51,6 +53,8 @@ __export(agent_chat_exports, {
51
53
  WorkingIndicator: () => WorkingIndicator,
52
54
  WorkingMark: () => WorkingMark,
53
55
  baseNameOf: () => baseNameOf,
56
+ browserActOf: () => browserActOf,
57
+ browserElements: () => browserElements,
54
58
  commandText: () => commandText,
55
59
  describeTool: () => describeTool,
56
60
  diffOf: () => diffOf,
@@ -62,6 +66,7 @@ __export(agent_chat_exports, {
62
66
  latestPlan: () => latestPlan,
63
67
  lineCount: () => lineCount,
64
68
  liveState: () => liveState,
69
+ middleEllipsis: () => middleEllipsis,
65
70
  motionFor: () => motionFor,
66
71
  newTurn: () => newTurn,
67
72
  parseToolArgs: () => parseToolArgs,
@@ -226,6 +231,7 @@ var NS = /^(developer|platform|computercontroller|builtin|default|functions|tool
226
231
  function toolKind(name) {
227
232
  const raw = String(name || "").trim();
228
233
  if (!raw) return "tool";
234
+ if (browserActOf(raw) !== null) return "browser";
229
235
  if (/^mcp__/i.test(raw)) return "mcp";
230
236
  const n = raw.toLowerCase().replace(NS, "");
231
237
  if (KIND_BY_NAME[n]) return KIND_BY_NAME[n];
@@ -376,6 +382,195 @@ function shortUrl(u) {
376
382
  function humanizeName(n) {
377
383
  return str(n).replace(/^mcp__/i, "").replace(/__|\./g, " \xB7 ").replace(/[_-]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").trim().replace(/^\w/, (c) => c.toUpperCase());
378
384
  }
385
+ var NS_BROWSER = /^(?:mcp__.+?__|[a-z0-9_-]+?(?:__|\.))(browser[_\-.].+)$/i;
386
+ var BROWSER_SERVER = /^(?:mcp__)?(?:browser|playwright|puppeteer|browserbase|browser[_-]use|chrome[_-]?devtools)(?:__|\.)(.+)$/i;
387
+ function browserActOf(name) {
388
+ const raw = String(name || "").trim();
389
+ if (!raw) return null;
390
+ const n = raw.toLowerCase().replace(NS, "");
391
+ if (KIND_BY_NAME[n] === "browser") return n === "navigate" || n === "screenshot" ? n : "";
392
+ let m = n.match(/^(?:browser|playwright|computer)[_\-.](.+)$/);
393
+ if (m) return m[1];
394
+ m = raw.match(NS_BROWSER);
395
+ if (m) return m[1].replace(/^browser[_\-.]/i, "").toLowerCase();
396
+ m = raw.match(BROWSER_SERVER);
397
+ if (m) return m[1].replace(/^browser[_\-.]/i, "").toLowerCase();
398
+ if (/[_\-.]browser$/.test(n)) return "";
399
+ return null;
400
+ }
401
+ var ROLE_NOUN = {
402
+ link: "link",
403
+ button: "button",
404
+ submit: "button",
405
+ textbox: "field",
406
+ searchbox: "search field",
407
+ combobox: "list",
408
+ listbox: "list",
409
+ checkbox: "checkbox",
410
+ radio: "option",
411
+ option: "option",
412
+ tab: "tab",
413
+ menuitem: "menu item",
414
+ heading: "heading",
415
+ img: "image",
416
+ image: "image",
417
+ switch: "switch",
418
+ slider: "slider"
419
+ };
420
+ function cut(s, max) {
421
+ const t = str(s).replace(/\s+/g, " ").trim();
422
+ return t.length > max ? `${t.slice(0, max - 1).trimEnd()}\u2026` : t;
423
+ }
424
+ function elementWords(a, element, act) {
425
+ const desc = str(firstOf(a, ["element", "element_description", "description", "label"])).trim();
426
+ if (desc) return cut(desc, 60);
427
+ if (element && element.role) {
428
+ const noun = ROLE_NOUN[String(element.role).toLowerCase()] || "";
429
+ const name = cut(element.name, 40);
430
+ if (noun && name) return `the \u201C${name}\u201D ${noun}`;
431
+ if (noun) return `a ${noun}`;
432
+ if (name) return `\u201C${name}\u201D`;
433
+ }
434
+ const sel = str(a.selector).trim().toLowerCase();
435
+ if (sel) {
436
+ if (/^a(?=$|[\s.#[:>])|role=["']?link/.test(sel)) return "a link";
437
+ if (/^button|\[type=["']?submit|role=["']?button/.test(sel)) return "a button";
438
+ if (/^(input|textarea)|role=["']?(textbox|searchbox)|contenteditable/.test(sel)) return "a field";
439
+ if (/^select|role=["']?(combobox|listbox)/.test(sel)) return "a list";
440
+ }
441
+ if (act === "click") {
442
+ const t = str(a.text).trim();
443
+ if (t) return `\u201C${cut(t, 40)}\u201D`;
444
+ }
445
+ return "";
446
+ }
447
+ function msWords(ms) {
448
+ const s = Math.round(Number(ms) / 100) / 10;
449
+ return s >= 1 ? `${s}s` : `${Math.round(Number(ms))} ms`;
450
+ }
451
+ var BROWSER_ACTS = [
452
+ [
453
+ /^(navigate|goto|go_to|open|open_url|visit|new_tab|tab_new|browse|go)$/,
454
+ "Opening",
455
+ "Opened",
456
+ (a) => {
457
+ const u = str(firstOf(a, ["url", "href", "uri", "link", "address"]));
458
+ return u ? shortUrl(u) : "";
459
+ },
460
+ ["Opening a page", "Opened a page"]
461
+ ],
462
+ [/^(navigate_back|back|go_back|history_back)$/, "", "", null, ["Going back a page", "Went back a page"]],
463
+ [/^(navigate_forward|forward|go_forward)$/, "", "", null, ["Going forward a page", "Went forward a page"]],
464
+ [/^(reload|refresh)$/, "", "", null, ["Reloading the page", "Reloaded the page"]],
465
+ [
466
+ /^(click|left_click|double_click|right_click|triple_click|middle_click|tap|click_element)$/,
467
+ "Clicking",
468
+ "Clicked",
469
+ (a, e, act) => elementWords(a, e, act),
470
+ ["Clicking on the page", "Clicked on the page"]
471
+ ],
472
+ [/^(hover|mouse_move|move_mouse)$/, "Pointing at", "Pointed at", (a, e, act) => elementWords(a, e, act), ["Moving the pointer", "Moved the pointer"]],
473
+ [
474
+ /^(type|fill|input|input_text|type_text|insert_text|fill_form|send_keys_to)$/,
475
+ "Typing into",
476
+ "Typed into",
477
+ (a, e, act) => elementWords(a, e, act),
478
+ ["Typing into a field", "Typed into a field"]
479
+ ],
480
+ [
481
+ /^(select|select_option|choose|select_dropdown_option)$/,
482
+ "Choosing an option in",
483
+ "Chose an option in",
484
+ (a, e, act) => elementWords(a, e, act),
485
+ ["Choosing an option", "Chose an option"]
486
+ ],
487
+ [
488
+ /^(press|press_key|key|keypress|send_keys|hotkey)$/,
489
+ "Pressing",
490
+ "Pressed",
491
+ (a) => cut(firstOf(a, ["key", "keys", "text"]), 30),
492
+ ["Pressing a key", "Pressed a key"]
493
+ ],
494
+ [/^(scroll|scroll_down|scroll_up|wheel|scroll_page)$/, "Scrolling", "Scrolled", (a, e, act) => {
495
+ const d = str(firstOf(a, ["direction", "scroll_direction"])).toLowerCase();
496
+ if (/^(up|down|left|right)$/.test(d)) return d;
497
+ if (/_up$/.test(act)) return "up";
498
+ if (/_down$/.test(act)) return "down";
499
+ const dy = Number(firstOf(a, ["pixels", "delta_y", "deltaY", "amount", "scroll_amount"]));
500
+ return Number.isFinite(dy) && dy < 0 ? "up" : Number.isFinite(dy) && dy > 0 ? "down" : "";
501
+ }, ["Scrolling the page", "Scrolled the page"]],
502
+ [
503
+ /^(screenshot|take_screenshot|capture|capture_screenshot)$/,
504
+ "",
505
+ "",
506
+ null,
507
+ ["Taking a screenshot", "Took a screenshot"],
508
+ (a) => a.full_page || a.fullPage ? ["Taking a screenshot of the whole page", "Took a screenshot of the whole page"] : null
509
+ ],
510
+ [/^(snapshot|read|read_page|get_page|accessibility_snapshot|page_content|get_content|get_elements|observe)$/, "", "", null, ["Reading the page", "Read the page"]],
511
+ [/^(extract_text|get_text|extract|text|extract_content|get_page_text)$/, "", "", null, ["Reading the page\u2019s text", "Read the page\u2019s text"]],
512
+ [/^(get_url|url|current_url|location|get_title)$/, "", "", null, ["Checking the address", "Checked the address"]],
513
+ [/^(wait|wait_for|wait_for_text|wait_for_selector|sleep)$/, "Waiting", "Waited", (a) => {
514
+ const t = str(a.text).trim();
515
+ if (t) return `for \u201C${cut(t, 40)}\u201D`;
516
+ if (str(a.selector).trim()) return "for the page";
517
+ const ms = a.ms != null ? Number(a.ms) : a.time != null ? Number(a.time) * 1e3 : Number(firstOf(a, ["timeout", "duration"]));
518
+ return Number.isFinite(ms) && ms > 0 ? msWords(ms) : "";
519
+ }, ["Waiting", "Waited"]],
520
+ [/^(tabs|list_tabs|tab_list|get_tabs)$/, "", "", null, ["Listing the tabs", "Listed the tabs"]],
521
+ [/^(switch_tab|tab_select|select_tab|focus_tab|switch_to_tab)$/, "", "", null, ["Switching tabs", "Switched tabs"]],
522
+ [/^(close_tab|tab_close)$/, "", "", null, ["Closing a tab", "Closed a tab"]],
523
+ [/^(close|quit|close_browser)$/, "", "", null, ["Closing the browser", "Closed the browser"]],
524
+ [/^(drag|drag_and_drop|left_click_drag)$/, "", "", null, ["Dragging on the page", "Dragged on the page"]],
525
+ [/^(file_upload|upload|upload_file|set_input_files)$/, "", "", null, ["Uploading a file", "Uploaded a file"]],
526
+ [/^(handle_dialog|dialog|accept_dialog|dismiss_dialog)$/, "", "", null, ["Answering a dialog", "Answered a dialog"]],
527
+ [/^(resize|set_viewport|resize_window)$/, "", "", null, ["Resizing the window", "Resized the window"]],
528
+ [/^(evaluate|run_code|execute_js|eval|execute_script|run_javascript)$/, "", "", null, ["Running a script on the page", "Ran a script on the page"]],
529
+ [/^(console_messages|console|get_console)$/, "", "", null, ["Reading the console", "Read the console"]],
530
+ [/^(network_requests|network|get_network)$/, "", "", null, ["Reading the network requests", "Read the network requests"]],
531
+ [/^(pdf_save|save_pdf|pdf|print_pdf)$/, "", "", null, ["Saving the page as a PDF", "Saved the page as a PDF"]],
532
+ [/^(cursor_position)$/, "", "", null, ["Finding the pointer", "Found the pointer"]],
533
+ [/^(install)$/, "", "", null, ["Installing the browser", "Installed the browser"]]
534
+ ];
535
+ function describeBrowser(name, a, element) {
536
+ const fromName = browserActOf(name) || "";
537
+ const fromArgs = str(firstOf(a, ["action", "command", "type"])).trim();
538
+ const act = (fromName && fromName !== "use" ? fromName : fromArgs || fromName).toLowerCase().replace(/[\s-]+/g, "_");
539
+ const row = BROWSER_ACTS.find((r) => r[0].test(act));
540
+ if (row) {
541
+ const [, running, done, target, bare, special] = row;
542
+ const sp = special ? special(a) : null;
543
+ if (sp) return { running: sp[0], done: sp[1], target: "" };
544
+ const t = target ? target(a, element, act) : "";
545
+ return t ? { running, done, target: t } : { running: bare[0], done: bare[1], target: "" };
546
+ }
547
+ const u = str(firstOf(a, ["url", "href", "uri"]));
548
+ return u ? { running: "Browsing", done: "Browsed", target: shortUrl(u) } : { running: "Using the browser", done: "Used the browser", target: "" };
549
+ }
550
+ function browserElements(items) {
551
+ const out = {};
552
+ let refs = /* @__PURE__ */ new Map();
553
+ for (const it of items || []) {
554
+ if (!it || it.kind !== "tool" || toolKind(it.name) !== "browser") continue;
555
+ const a = parseToolArgs(it.args);
556
+ const ref = str(firstOf(a, ["ref", "element_ref"])).trim();
557
+ if (ref && refs.has(ref)) out[it.id] = refs.get(ref);
558
+ const text = str(it.output);
559
+ if (!text) continue;
560
+ const next = /* @__PURE__ */ new Map();
561
+ for (const ln of text.split("\n")) {
562
+ let m = ln.match(/^\s*(e\d+)\s+([a-z]+)\s+"(.*?)"/i);
563
+ if (m) {
564
+ next.set(m[1], { role: m[2], name: m[3] });
565
+ continue;
566
+ }
567
+ m = ln.match(/^\s*-\s+([a-z]+)(?:\s+"(.*?)")?[^\n]*\[ref=(e\d+)\]/i);
568
+ if (m) next.set(m[3], { role: m[1], name: m[2] || "" });
569
+ }
570
+ if (next.size) refs = next;
571
+ }
572
+ return out;
573
+ }
379
574
  var VERBS = {
380
575
  shell: ["Running", "Ran"],
381
576
  shell_output: ["Reading output of", "Read output of"],
@@ -396,7 +591,7 @@ var VERBS = {
396
591
  mcp: ["Using", "Used"],
397
592
  tool: ["Using", "Used"]
398
593
  };
399
- function describeTool(name, args) {
594
+ function describeTool(name, args, opts) {
400
595
  const a = parseToolArgs(args);
401
596
  let kind = toolKind(name);
402
597
  const nm = str(name);
@@ -406,6 +601,7 @@ function describeTool(name, args) {
406
601
  let targetFull = "";
407
602
  let mono = false;
408
603
  let note = "";
604
+ let browser = null;
409
605
  const pathOf = () => firstOf(a, [
410
606
  "file_path",
411
607
  "path",
@@ -483,11 +679,9 @@ function describeTool(name, args) {
483
679
  targetFull = target;
484
680
  break;
485
681
  case "browser": {
486
- const act = str(firstOf(a, ["action", "command", "type"]));
487
- const u = str(firstOf(a, ["url", "selector", "text"]));
488
- target = [act, u ? shortUrl(u) : ""].filter(Boolean).join(" ");
489
- targetFull = target;
490
- if (/^browser[_\-.]/i.test(nm)) note = humanizeName(nm.replace(/^browser[_\-.]/i, ""));
682
+ browser = describeBrowser(nm, a, opts && opts.element);
683
+ target = browser.target;
684
+ targetFull = str(firstOf(a, ["url", "href", "uri"])) || target;
491
685
  break;
492
686
  }
493
687
  case "mcp":
@@ -499,7 +693,7 @@ function describeTool(name, args) {
499
693
  default:
500
694
  break;
501
695
  }
502
- const v = VERBS[kind] || VERBS.tool;
696
+ const v = browser ? [browser.running, browser.done] : VERBS[kind] || VERBS.tool;
503
697
  return {
504
698
  kind,
505
699
  target: target.replace(/\s+/g, " ").trim(),
@@ -517,7 +711,9 @@ function toolLine(d, state) {
517
711
  if (d.kind === "todo" || d.kind === "toolsearch" || d.kind === "think") return verb;
518
712
  if (d.kind === "shell" && d.target && !d.mono) return d.target;
519
713
  if (d.kind === "mcp" || d.kind === "tool") return `${verb} ${d.target || "a tool"}`;
520
- return d.target ? `${verb} ${d.target}` : `${verb} ${KIND_NOUN[d.kind] || "a tool"}`;
714
+ if (d.target) return `${verb} ${d.target}`;
715
+ const noun = KIND_NOUN[d.kind];
716
+ return noun ? `${verb} ${noun}` : verb.replace(/\s+(for|of)$/, "");
521
717
  }
522
718
  var KIND_NOUN = {
523
719
  shell: "a command",
@@ -557,7 +753,7 @@ var PHRASES = {
557
753
  function summarizeCalls(calls) {
558
754
  const list = (calls || []).filter(Boolean);
559
755
  if (!list.length) return "";
560
- if (list.length === 1) return toolLine(describeTool(list[0].name, list[0].args), "done");
756
+ if (list.length === 1) return toolLine(describeTool(list[0].name, list[0].args, { element: list[0].element }), "done");
561
757
  const order = [];
562
758
  const count = {};
563
759
  for (const c of list) {
@@ -1477,8 +1673,9 @@ function StepDetail(props) {
1477
1673
  ] });
1478
1674
  }
1479
1675
  function StepRow(props) {
1480
- const { item, labels = DEFAULT_AGENT_LABELS, defaultOpen = false } = props;
1481
- const d = (0, import_react3.useMemo)(() => describeTool(item.name, item.args), [item.name, item.args]);
1676
+ const { item, labels = DEFAULT_AGENT_LABELS, defaultOpen = false, element = null, openStep, active = false } = props;
1677
+ const d = (0, import_react3.useMemo)(() => describeTool(item.name, item.args, { element }), [item.name, item.args, element]);
1678
+ const opener = openStep ? openStep(item, d) || null : null;
1482
1679
  const [open, setOpen] = (0, import_react3.useState)(defaultOpen);
1483
1680
  const uid = (0, import_react3.useRef)(`uac-s-${Math.random().toString(36).slice(2, 9)}`).current;
1484
1681
  const running = item.status === "running";
@@ -1488,8 +1685,8 @@ function StepRow(props) {
1488
1685
  const verb = running ? d.running : d.done;
1489
1686
  const hasTarget = d.target && line === `${verb} ${d.target}`;
1490
1687
  const note = !running && item.status !== "failed" ? resultNote(d.kind, item.output) : "";
1491
- const hasDetail = !!(item.args && item.args !== "{}" && item.args !== '""') || item.output !== void 0;
1492
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cls("uac-step", `is-${item.status}`), "data-kind": d.kind, children: [
1688
+ const hasDetail = !opener && (!!(item.args && item.args !== "{}" && item.args !== '""') || item.output !== void 0);
1689
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cls("uac-step", `is-${item.status}`, opener && "is-opens", opener && active && "is-active"), "data-kind": d.kind, children: [
1493
1690
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1494
1691
  "button",
1495
1692
  {
@@ -1497,8 +1694,9 @@ function StepRow(props) {
1497
1694
  className: "uac-step-h",
1498
1695
  "aria-expanded": hasDetail ? open : void 0,
1499
1696
  "aria-controls": hasDetail ? uid : void 0,
1500
- disabled: !hasDetail,
1501
- onClick: () => setOpen((v) => !v),
1697
+ "aria-current": opener && active ? "true" : void 0,
1698
+ disabled: !opener && !hasDetail,
1699
+ onClick: opener || (() => setOpen((v) => !v)),
1502
1700
  title: d.targetFull || void 0,
1503
1701
  children: [
1504
1702
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StatusGlyph, { status: item.status, kind: d.kind }),
@@ -1514,7 +1712,7 @@ function StepRow(props) {
1514
1712
  note ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-n", children: note }) : null,
1515
1713
  item.status === "stopped" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-n", children: labels.stoppedCall }) : null,
1516
1714
  running && runMs != null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-time", children: formatElapsed(runMs) }) : tookMs != null && tookMs >= 1e3 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-time", children: formatDuration(tookMs) }) : null,
1517
- hasDetail ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-chev", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Chevron, { dir: open ? "down" : "right", size: 12 }) }) : null
1715
+ hasDetail || opener ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-chev", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Chevron, { dir: open && !opener ? "down" : "right", size: 12 }) }) : null
1518
1716
  ]
1519
1717
  }
1520
1718
  ),
@@ -1566,14 +1764,26 @@ function sumDiff(tools) {
1566
1764
  return any ? { added, removed } : null;
1567
1765
  }
1568
1766
  function WorkGroup(props) {
1569
- const { items, live = false, liveLabel, start = null, mark, motion, labels = DEFAULT_AGENT_LABELS, defaultOpen = false } = props;
1767
+ const {
1768
+ items,
1769
+ live = false,
1770
+ liveLabel,
1771
+ start = null,
1772
+ mark,
1773
+ motion,
1774
+ labels = DEFAULT_AGENT_LABELS,
1775
+ defaultOpen = false,
1776
+ elements = null,
1777
+ openStep,
1778
+ activeStep = null
1779
+ } = props;
1570
1780
  const [open, setOpen] = (0, import_react3.useState)(defaultOpen);
1571
1781
  const uid = (0, import_react3.useRef)(`uac-g-${Math.random().toString(36).slice(2, 9)}`).current;
1572
1782
  const tools = items.filter((x) => x.kind === "tool");
1573
1783
  const thoughts = items.filter((x) => x.kind === "thinking");
1574
1784
  const failed = tools.filter((x) => x.status === "failed").length;
1575
1785
  let summary = "";
1576
- if (tools.length) summary = summarizeCalls(tools);
1786
+ if (tools.length) summary = summarizeCalls(elements ? tools.map((t) => ({ name: t.name, args: t.args, element: elements[t.id] })) : tools);
1577
1787
  else if (thoughts.length) {
1578
1788
  const t = thoughts[0];
1579
1789
  const ms = t.startedAt != null && t.endedAt != null ? t.endedAt - t.startedAt : null;
@@ -1581,7 +1791,17 @@ function WorkGroup(props) {
1581
1791
  }
1582
1792
  const diff = sumDiff(tools);
1583
1793
  if (!live && !tools.length && !thoughts.some((t) => String(t.text || "").trim())) return null;
1584
- const body = open ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-calls", id: uid, children: items.map((it) => it.kind === "tool" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StepRow, { item: it, labels }, it.id) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ThinkingRow, { item: it, labels }, it.id)) }) : null;
1794
+ const body = open ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-calls", id: uid, children: items.map((it) => it.kind === "tool" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1795
+ StepRow,
1796
+ {
1797
+ item: it,
1798
+ labels,
1799
+ element: elements ? elements[it.id] || null : null,
1800
+ openStep,
1801
+ active: activeStep != null && activeStep === it.id
1802
+ },
1803
+ it.id
1804
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ThinkingRow, { item: it, labels }, it.id)) }) : null;
1585
1805
  if (live) {
1586
1806
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cls("uac-group", "is-live", open && "is-open"), children: [
1587
1807
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -1719,9 +1939,13 @@ function AgentTurnView(props) {
1719
1939
  renderFiles,
1720
1940
  actions,
1721
1941
  describeIncomplete,
1722
- liveStart
1942
+ liveStart,
1943
+ openStep,
1944
+ activeStep = null
1723
1945
  } = props;
1724
1946
  const labels = (0, import_react3.useMemo)(() => ({ ...DEFAULT_AGENT_LABELS, ...labelsIn || {} }), [labelsIn]);
1947
+ const items = turn ? turn.items : null;
1948
+ const elements = (0, import_react3.useMemo)(() => browserElements(items), [items]);
1725
1949
  if (!turn) return null;
1726
1950
  const running = turn.status === "running";
1727
1951
  const segs = segments(turn);
@@ -1732,7 +1956,7 @@ function AgentTurnView(props) {
1732
1956
  const liveWork = running && lastSeg && lastSeg.type === "work";
1733
1957
  let liveLabel = labels.thinking;
1734
1958
  if (now) {
1735
- if (now.phase === "tool" && now.tool) liveLabel = toolLine(describeTool(now.tool.name, now.tool.args), "running");
1959
+ if (now.phase === "tool" && now.tool) liveLabel = toolLine(describeTool(now.tool.name, now.tool.args, { element: elements[now.tool.id] }), "running");
1736
1960
  else if (now.phase === "writing") liveLabel = labels.writing;
1737
1961
  else if (now.phase === "starting") liveLabel = labels.starting;
1738
1962
  }
@@ -1750,7 +1974,21 @@ function AgentTurnView(props) {
1750
1974
  if (isLive) {
1751
1975
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react3.default.Fragment, { children: [
1752
1976
  plan ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TodoCard, { todos: plan, labels, running: true }) : null,
1753
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WorkGroup, { items: s.items, live: true, liveLabel, start, mark, motion, labels })
1977
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1978
+ WorkGroup,
1979
+ {
1980
+ items: s.items,
1981
+ live: true,
1982
+ liveLabel,
1983
+ start,
1984
+ mark,
1985
+ motion,
1986
+ labels,
1987
+ elements,
1988
+ openStep,
1989
+ activeStep
1990
+ }
1991
+ )
1754
1992
  ] }, `w${i}`);
1755
1993
  }
1756
1994
  if (s.type === "text") {
@@ -1764,7 +2002,17 @@ function AgentTurnView(props) {
1764
2002
  s.item.id || `t${i}`
1765
2003
  );
1766
2004
  }
1767
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WorkGroup, { items: s.items, labels }, `w${i}-${s.items[0] && s.items[0].id}`);
2005
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2006
+ WorkGroup,
2007
+ {
2008
+ items: s.items,
2009
+ labels,
2010
+ elements,
2011
+ openStep,
2012
+ activeStep
2013
+ },
2014
+ `w${i}-${s.items[0] && s.items[0].id}`
2015
+ );
1768
2016
  }),
1769
2017
  !liveWork && plan ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TodoCard, { todos: plan, labels, running }) : null,
1770
2018
  running && !liveWork ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WorkingIndicator, { mark, motion, start, label: liveLabel }) : null,
@@ -2301,7 +2549,8 @@ function FilePreview({
2301
2549
  parseWorkbook,
2302
2550
  onDownload,
2303
2551
  title,
2304
- before
2552
+ before,
2553
+ nameSlot
2305
2554
  }) {
2306
2555
  const { url, name } = file || {};
2307
2556
  const [st, setSt] = (0, import_react6.useState)({ kind: "loading" });
@@ -2389,7 +2638,7 @@ function FilePreview({
2389
2638
  before,
2390
2639
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("header", { className: "uic-fp-head", children: [
2391
2640
  /* @__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 }),
2641
+ nameSlot || /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "uic-fp-name", title: name, children: name }),
2393
2642
  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
2643
  "button",
2395
2644
  {
@@ -2475,8 +2724,218 @@ function FilePreview({
2475
2724
  ] });
2476
2725
  }
2477
2726
 
2727
+ // src/format.js
2728
+ function bytesLabel(n) {
2729
+ if (n == null) return "";
2730
+ if (n < 1024) return `${n} B`;
2731
+ if (n < 1048576) return `${Math.round(n / 1024)} KB`;
2732
+ return `${(n / 1048576).toFixed(1)} MB`;
2733
+ }
2734
+
2478
2735
  // src/agent-chat/artifacts.jsx
2479
2736
  var import_jsx_runtime6 = require("react/jsx-runtime");
2737
+ var FILTER_AT = 8;
2738
+ function middleEllipsis(name, max = 40) {
2739
+ const s = String(name || "");
2740
+ if (s.length <= max) return s;
2741
+ const tail = Math.min(Math.max(10, Math.floor(max * 0.45)), max - 4);
2742
+ return `${s.slice(0, max - tail - 1)}\u2026${s.slice(-tail)}`;
2743
+ }
2744
+ function MidName(props) {
2745
+ const { name, className } = props;
2746
+ const s = String(name || "");
2747
+ const cut2 = s.length > 16 ? s.length - Math.min(14, Math.floor(s.length / 2)) : s.length;
2748
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "uac-mid" + (className ? ` ${className}` : ""), children: [
2749
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "uac-mid-h", children: s.slice(0, cut2) }),
2750
+ cut2 < s.length ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "uac-mid-t", children: s.slice(cut2) }) : null
2751
+ ] });
2752
+ }
2753
+ function dirOf(path) {
2754
+ const p = String(path || "");
2755
+ const i = p.lastIndexOf("/");
2756
+ return i > 0 ? p.slice(0, i) : "";
2757
+ }
2758
+ function Check() {
2759
+ 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" }) });
2760
+ }
2761
+ function FileSwitcher(props) {
2762
+ const { files, current, onSelect, label = "Files in this conversation", turnLabel = (n) => `Turn ${n}` } = props;
2763
+ const [open, setOpen] = (0, import_react7.useState)(false);
2764
+ const [q, setQ] = (0, import_react7.useState)("");
2765
+ const [hi, setHi] = (0, import_react7.useState)(0);
2766
+ const root = (0, import_react7.useRef)(null);
2767
+ const list = (0, import_react7.useRef)(null);
2768
+ const input = (0, import_react7.useRef)(null);
2769
+ const btn = (0, import_react7.useRef)(null);
2770
+ const id = (0, import_react7.useRef)(`uac-fs-${Math.random().toString(36).slice(2, 9)}`).current;
2771
+ const cur = files.find((f) => f.key === current) || files[0];
2772
+ const needle = q.trim().toLowerCase();
2773
+ const shown = (0, import_react7.useMemo)(() => files.filter((f) => !needle || String(f.path || f.name).toLowerCase().includes(needle)), [files, needle]);
2774
+ const groups = (0, import_react7.useMemo)(() => {
2775
+ const by = /* @__PURE__ */ new Map();
2776
+ for (const f of shown) {
2777
+ const d = dirOf(f.path);
2778
+ if (!by.has(d)) by.set(d, []);
2779
+ by.get(d).push(f);
2780
+ }
2781
+ return [...by.entries()].sort((a, b) => a[0] === "" ? -1 : b[0] === "" ? 1 : 0);
2782
+ }, [shown]);
2783
+ const flat = groups.flatMap(([, fs]) => fs);
2784
+ const grouped = groups.length > 1 || groups.length === 1 && groups[0][0] !== "";
2785
+ const many = files.length > FILTER_AT;
2786
+ (0, import_react7.useEffect)(() => {
2787
+ if (!open) return void 0;
2788
+ setHi(Math.max(0, flat.findIndex((f) => f.key === (cur && cur.key))));
2789
+ const t = setTimeout(() => {
2790
+ if (many && input.current) input.current.focus();
2791
+ else if (list.current) list.current.focus();
2792
+ }, 0);
2793
+ const away = (e) => {
2794
+ if (root.current && !root.current.contains(e.target)) setOpen(false);
2795
+ };
2796
+ document.addEventListener("mousedown", away);
2797
+ document.addEventListener("touchstart", away);
2798
+ return () => {
2799
+ clearTimeout(t);
2800
+ document.removeEventListener("mousedown", away);
2801
+ document.removeEventListener("touchstart", away);
2802
+ };
2803
+ }, [open]);
2804
+ (0, import_react7.useEffect)(() => {
2805
+ setHi(0);
2806
+ }, [needle]);
2807
+ (0, import_react7.useEffect)(() => {
2808
+ if (!open || !list.current) return;
2809
+ const el = list.current.querySelector(`[data-i="${hi}"]`);
2810
+ if (el && el.scrollIntoView) el.scrollIntoView({ block: "nearest" });
2811
+ }, [hi, open]);
2812
+ if (!cur) return null;
2813
+ const pick = (f) => {
2814
+ setOpen(false);
2815
+ setQ("");
2816
+ if (f && onSelect) onSelect(f.key);
2817
+ if (btn.current) btn.current.focus();
2818
+ };
2819
+ const keys = (e) => {
2820
+ if (e.key === "ArrowDown") {
2821
+ e.preventDefault();
2822
+ setHi((i2) => Math.min(flat.length - 1, i2 + 1));
2823
+ } else if (e.key === "ArrowUp") {
2824
+ e.preventDefault();
2825
+ setHi((i2) => Math.max(0, i2 - 1));
2826
+ } else if (e.key === "Home") {
2827
+ e.preventDefault();
2828
+ setHi(0);
2829
+ } else if (e.key === "End") {
2830
+ e.preventDefault();
2831
+ setHi(flat.length - 1);
2832
+ } else if (e.key === "Enter") {
2833
+ e.preventDefault();
2834
+ pick(flat[hi]);
2835
+ } else if (e.key === "Escape") {
2836
+ e.preventDefault();
2837
+ e.stopPropagation();
2838
+ setOpen(false);
2839
+ if (btn.current) btn.current.focus();
2840
+ } else if (e.key === "Tab") setOpen(false);
2841
+ };
2842
+ const single = files.length < 2;
2843
+ let i = -1;
2844
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { ref: root, className: "uac-fs" + (open ? " is-open" : ""), children: [
2845
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2846
+ "button",
2847
+ {
2848
+ ref: btn,
2849
+ type: "button",
2850
+ className: "uac-fs-btn",
2851
+ title: cur.path || cur.name,
2852
+ disabled: single,
2853
+ "aria-haspopup": single ? void 0 : "listbox",
2854
+ "aria-expanded": single ? void 0 : open,
2855
+ "aria-controls": single ? void 0 : id,
2856
+ onClick: () => setOpen((v) => !v),
2857
+ onKeyDown: (e) => {
2858
+ if (!single && (e.key === "ArrowDown" || e.key === "ArrowUp")) {
2859
+ e.preventDefault();
2860
+ setOpen(true);
2861
+ }
2862
+ },
2863
+ children: [
2864
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MidName, { name: cur.name, className: "uac-fs-name" }),
2865
+ 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" }) })
2866
+ ]
2867
+ }
2868
+ ),
2869
+ open ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2870
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "uac-fs-scrim", "aria-hidden": "true", onClick: () => setOpen(false) }),
2871
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "uac-fs-pop", onKeyDown: keys, children: [
2872
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "uac-fs-head", children: [
2873
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: label }),
2874
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "uac-fs-count", children: files.length })
2875
+ ] }),
2876
+ many ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2877
+ "input",
2878
+ {
2879
+ ref: input,
2880
+ className: "uac-fs-q",
2881
+ type: "search",
2882
+ placeholder: "Find a file",
2883
+ value: q,
2884
+ autoComplete: "off",
2885
+ spellCheck: false,
2886
+ "aria-label": "Find a file",
2887
+ "aria-controls": id,
2888
+ onChange: (e) => setQ(e.target.value)
2889
+ }
2890
+ ) : null,
2891
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2892
+ "div",
2893
+ {
2894
+ ref: list,
2895
+ id,
2896
+ className: "uac-fs-list",
2897
+ role: "listbox",
2898
+ tabIndex: -1,
2899
+ "aria-label": label,
2900
+ "aria-activedescendant": flat[hi] ? `${id}-${hi}` : void 0,
2901
+ children: [
2902
+ groups.map(([dir, fs]) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { role: "group", "aria-label": dir || "Top level", children: [
2903
+ grouped ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "uac-fs-dir", "aria-hidden": "true", children: dir || "Top level" }) : null,
2904
+ fs.map((f) => {
2905
+ i += 1;
2906
+ const n = i;
2907
+ const on = f.key === cur.key;
2908
+ const meta = [f.size != null ? bytesLabel(f.size) : "", f.turn != null ? turnLabel(f.turn) : ""].filter(Boolean).join(" \xB7 ");
2909
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2910
+ "div",
2911
+ {
2912
+ id: `${id}-${n}`,
2913
+ "data-i": n,
2914
+ role: "option",
2915
+ "aria-selected": on,
2916
+ className: "uac-fs-opt" + (on ? " is-on" : "") + (n === hi ? " is-hi" : ""),
2917
+ title: f.path || f.name,
2918
+ onMouseEnter: () => setHi(n),
2919
+ onClick: () => pick(f),
2920
+ children: [
2921
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FileTypeIcon, { name: f.name, size: 16 }),
2922
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MidName, { name: f.name, className: "uac-fs-on" }),
2923
+ meta ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "uac-fs-meta", children: meta }) : null,
2924
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "uac-fs-ck", children: on ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Check, {}) : null })
2925
+ ]
2926
+ },
2927
+ f.key
2928
+ );
2929
+ })
2930
+ ] }, dir || ".")),
2931
+ !flat.length ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "uac-fs-none", children: "No file matches." }) : null
2932
+ ]
2933
+ }
2934
+ )
2935
+ ] })
2936
+ ] }) : null
2937
+ ] });
2938
+ }
2480
2939
  function ArtifactPanel(props) {
2481
2940
  const {
2482
2941
  files = [],
@@ -2485,6 +2944,7 @@ function ArtifactPanel(props) {
2485
2944
  onClose,
2486
2945
  overlay = false,
2487
2946
  label = "Files in this conversation",
2947
+ turnLabel,
2488
2948
  fetchFile,
2489
2949
  renderMarkdown,
2490
2950
  officePdfUrl,
@@ -2502,7 +2962,7 @@ function ArtifactPanel(props) {
2502
2962
  if (b) b.focus();
2503
2963
  }, 0);
2504
2964
  const key = (e) => {
2505
- if (e.key === "Escape") {
2965
+ if (e.key === "Escape" && !e.defaultPrevented) {
2506
2966
  e.stopPropagation();
2507
2967
  onClose && onClose();
2508
2968
  }
@@ -2515,21 +2975,7 @@ function ArtifactPanel(props) {
2515
2975
  };
2516
2976
  }, [overlay, !!cur]);
2517
2977
  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;
2978
+ const switcher = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FileSwitcher, { files, current: cur.key, onSelect, label, turnLabel });
2533
2979
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2534
2980
  overlay ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "uac-art-scrim", "aria-hidden": "true", onClick: () => onClose && onClose() }) : null,
2535
2981
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
@@ -2545,7 +2991,7 @@ function ArtifactPanel(props) {
2545
2991
  {
2546
2992
  file: { url: cur.url, name: cur.name },
2547
2993
  onClose,
2548
- before: switcher,
2994
+ nameSlot: switcher,
2549
2995
  fetchFile,
2550
2996
  renderMarkdown,
2551
2997
  officePdfUrl,
@@ -2570,10 +3016,10 @@ var IcCheckMark = () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", { wi
2570
3016
  function subtitle(name, origin, bytes) {
2571
3017
  const parts = [(extOf(name) || "file").toUpperCase()];
2572
3018
  if (origin) parts.push(origin);
2573
- if (bytes != null) parts.push(bytesLabel(bytes));
3019
+ if (bytes != null) parts.push(bytesLabel2(bytes));
2574
3020
  return parts.join(" \xB7 ");
2575
3021
  }
2576
- function bytesLabel(n) {
3022
+ function bytesLabel2(n) {
2577
3023
  if (n == null) return "";
2578
3024
  if (n < 1024) return `${n} B`;
2579
3025
  if (n < 1048576) return `${Math.round(n / 1024)} KB`;