@alepha/ui 0.39.0 → 0.40.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.
Files changed (187) hide show
  1. package/README.md +4 -2
  2. package/dist/admin/AdminJobExecutionSheet.d.ts.map +1 -1
  3. package/dist/admin/AdminJobExecutionSheet.js +7 -0
  4. package/dist/admin/AdminJobExecutionSheet.js.map +1 -1
  5. package/dist/admin/analytics/RequestDialog.js +1 -1
  6. package/dist/admin/analytics/RequestDialog.js.map +1 -1
  7. package/dist/ai/AiChat.d.ts +6 -3
  8. package/dist/ai/AiChat.d.ts.map +1 -1
  9. package/dist/ai/AiChat.js +34 -5
  10. package/dist/ai/AiChat.js.map +1 -1
  11. package/dist/ai/AiChatConfirmCard.d.ts.map +1 -1
  12. package/dist/ai/AiChatConfirmCard.js +5 -1
  13. package/dist/ai/AiChatConfirmCard.js.map +1 -1
  14. package/dist/ai/AiChatFloat.d.ts +14 -0
  15. package/dist/ai/AiChatFloat.d.ts.map +1 -0
  16. package/dist/ai/AiChatFloat.js +30 -0
  17. package/dist/ai/AiChatFloat.js.map +1 -0
  18. package/dist/ai/AiChatMessage.js +2 -2
  19. package/dist/ai/AiChatMessage.js.map +1 -1
  20. package/dist/ai/AiChatPanel.d.ts +19 -0
  21. package/dist/ai/AiChatPanel.d.ts.map +1 -1
  22. package/dist/ai/AiChatPanel.js +65 -19
  23. package/dist/ai/AiChatPanel.js.map +1 -1
  24. package/dist/ai/AiChatToolStepDetails.d.ts +14 -0
  25. package/dist/ai/AiChatToolStepDetails.d.ts.map +1 -0
  26. package/dist/ai/AiChatToolStepDetails.js +34 -0
  27. package/dist/ai/AiChatToolStepDetails.js.map +1 -0
  28. package/dist/ai/AiChatToolTrace.d.ts +50 -0
  29. package/dist/ai/AiChatToolTrace.d.ts.map +1 -0
  30. package/dist/ai/AiChatToolTrace.js +91 -0
  31. package/dist/ai/AiChatToolTrace.js.map +1 -0
  32. package/dist/ai/index.d.ts +4 -2
  33. package/dist/ai/index.d.ts.map +1 -1
  34. package/dist/ai/index.js +3 -1
  35. package/dist/core/Button.d.ts.map +1 -1
  36. package/dist/core/Button.js +17 -1
  37. package/dist/core/Button.js.map +1 -1
  38. package/dist/core/Dialog.d.ts.map +1 -1
  39. package/dist/core/Dialog.js +1 -1
  40. package/dist/core/Dialog.js.map +1 -1
  41. package/dist/core/TimeAgo.d.ts +3 -4
  42. package/dist/core/TimeAgo.d.ts.map +1 -1
  43. package/dist/core/TimeAgo.js +3 -4
  44. package/dist/core/TimeAgo.js.map +1 -1
  45. package/dist/i18n/en/index.d.ts +22 -0
  46. package/dist/i18n/en/index.d.ts.map +1 -0
  47. package/dist/i18n/en/index.js +1 -0
  48. package/dist/i18n/en/uiEn.d.ts +37 -0
  49. package/dist/i18n/en/uiEn.d.ts.map +1 -0
  50. package/dist/i18n/en/uiEn.js +1468 -0
  51. package/dist/i18n/en/uiEn.js.map +1 -0
  52. package/dist/i18n/fr/uiFr.d.ts +3 -2
  53. package/dist/i18n/fr/uiFr.d.ts.map +1 -1
  54. package/dist/i18n/fr/uiFr.js +7 -2
  55. package/dist/i18n/fr/uiFr.js.map +1 -1
  56. package/dist/markdown/MarkdownView.d.ts +14 -0
  57. package/dist/markdown/MarkdownView.d.ts.map +1 -1
  58. package/dist/markdown/MarkdownView.js +16 -3
  59. package/dist/markdown/MarkdownView.js.map +1 -1
  60. package/dist/markdown/highlightLines.d.ts +27 -0
  61. package/dist/markdown/highlightLines.d.ts.map +1 -0
  62. package/dist/markdown/highlightLines.js +91 -0
  63. package/dist/markdown/highlightLines.js.map +1 -0
  64. package/dist/markdown/index.d.ts +5 -2
  65. package/dist/markdown/index.d.ts.map +1 -1
  66. package/dist/markdown/index.js +2 -1
  67. package/dist/shell/ButtonInbox.d.ts +8 -0
  68. package/dist/shell/ButtonInbox.d.ts.map +1 -1
  69. package/dist/shell/ButtonInbox.js +3 -1
  70. package/dist/shell/ButtonInbox.js.map +1 -1
  71. package/dist/shell/PlateLayout.d.ts.map +1 -1
  72. package/dist/shell/PlateLayout.js +2 -2
  73. package/dist/shell/PlateLayout.js.map +1 -1
  74. package/dist/sortable/index.d.ts +17 -0
  75. package/dist/sortable/index.d.ts.map +1 -0
  76. package/dist/sortable/index.js +4 -0
  77. package/dist/sortable/useSortableItem.d.ts +32 -0
  78. package/dist/sortable/useSortableItem.d.ts.map +1 -0
  79. package/dist/sortable/useSortableItem.js +35 -0
  80. package/dist/sortable/useSortableItem.js.map +1 -0
  81. package/dist/sortable/useSortableList.d.ts +85 -0
  82. package/dist/sortable/useSortableList.d.ts.map +1 -0
  83. package/dist/sortable/useSortableList.js +125 -0
  84. package/dist/sortable/useSortableList.js.map +1 -0
  85. package/dist/table/DataTable.d.ts.map +1 -1
  86. package/dist/table/DataTable.js +9 -6
  87. package/dist/table/DataTable.js.map +1 -1
  88. package/dist/table/DataTableRowActionGroupItem.d.ts +23 -0
  89. package/dist/table/DataTableRowActionGroupItem.d.ts.map +1 -0
  90. package/dist/table/DataTableRowActionGroupItem.js +38 -0
  91. package/dist/table/DataTableRowActionGroupItem.js.map +1 -0
  92. package/dist/table/DataTableRowActionItem.d.ts.map +1 -1
  93. package/dist/table/DataTableRowActionItem.js +15 -2
  94. package/dist/table/DataTableRowActionItem.js.map +1 -1
  95. package/dist/table/DataTableRowActionsInline.d.ts.map +1 -1
  96. package/dist/table/DataTableRowActionsInline.js +2 -1
  97. package/dist/table/DataTableRowActionsInline.js.map +1 -1
  98. package/dist/table/DataTableRowActionsMenu.d.ts +3 -2
  99. package/dist/table/DataTableRowActionsMenu.d.ts.map +1 -1
  100. package/dist/table/DataTableRowActionsMenu.js +12 -14
  101. package/dist/table/DataTableRowActionsMenu.js.map +1 -1
  102. package/dist/table/dataTableBaseProps.d.ts +16 -2
  103. package/dist/table/dataTableBaseProps.d.ts.map +1 -1
  104. package/dist/table/dataTablePersistence.d.ts +53 -11
  105. package/dist/table/dataTablePersistence.d.ts.map +1 -1
  106. package/dist/table/dataTablePersistence.js +66 -29
  107. package/dist/table/dataTablePersistence.js.map +1 -1
  108. package/dist/table/dataTableTypes.d.ts +20 -3
  109. package/dist/table/dataTableTypes.d.ts.map +1 -1
  110. package/dist/table/index.d.ts +8 -1
  111. package/dist/table/index.d.ts.map +1 -1
  112. package/dist/table/index.js +2 -1
  113. package/dist/table/useDataTableColumns.d.ts.map +1 -1
  114. package/dist/table/useDataTableColumns.js +4 -4
  115. package/dist/table/useDataTableColumns.js.map +1 -1
  116. package/dist/table/useDataTableData.d.ts.map +1 -1
  117. package/dist/table/useDataTableData.js +3 -3
  118. package/dist/table/useDataTableData.js.map +1 -1
  119. package/dist/table/useDataTableFilterForm.d.ts.map +1 -1
  120. package/dist/table/useDataTableFilterForm.js +6 -2
  121. package/dist/table/useDataTableFilterForm.js.map +1 -1
  122. package/dist/table/useDataTableFilterVisibility.d.ts +5 -0
  123. package/dist/table/useDataTableFilterVisibility.d.ts.map +1 -1
  124. package/dist/table/useDataTableFilterVisibility.js +16 -8
  125. package/dist/table/useDataTableFilterVisibility.js.map +1 -1
  126. package/dist/table/useDataTableRefresh.d.ts.map +1 -1
  127. package/dist/table/useDataTableRefresh.js +3 -2
  128. package/dist/table/useDataTableRefresh.js.map +1 -1
  129. package/dist/table/useDataTableSummary.d.ts +5 -0
  130. package/dist/table/useDataTableSummary.d.ts.map +1 -1
  131. package/dist/table/useDataTableSummary.js +6 -6
  132. package/dist/table/useDataTableSummary.js.map +1 -1
  133. package/docs/packages-alepha-ui-ai.md +3 -3
  134. package/docs/packages-alepha-ui-i18n-en.md +35 -0
  135. package/docs/packages-alepha-ui-markdown.md +3 -1
  136. package/docs/packages-alepha-ui-overview.md +4 -2
  137. package/docs/packages-alepha-ui-sortable.md +34 -0
  138. package/docs/packages-alepha-ui-table.md +7 -1
  139. package/package.json +21 -3
  140. package/src/admin/AdminJobExecutionSheet.tsx +9 -0
  141. package/src/admin/analytics/RequestDialog.tsx +1 -1
  142. package/src/ai/AiChat.tsx +44 -6
  143. package/src/ai/AiChatConfirmCard.tsx +7 -1
  144. package/src/ai/AiChatFloat.tsx +46 -0
  145. package/src/ai/AiChatMessage.tsx +2 -2
  146. package/src/ai/AiChatPanel.tsx +154 -47
  147. package/src/ai/AiChatToolStepDetails.tsx +42 -0
  148. package/src/ai/AiChatToolTrace.tsx +167 -0
  149. package/src/ai/__tests__/AiChat.browser.spec.tsx +270 -2
  150. package/src/ai/index.ts +4 -2
  151. package/src/core/Button.tsx +26 -1
  152. package/src/core/Dialog.tsx +6 -2
  153. package/src/core/TimeAgo.tsx +3 -4
  154. package/src/core/__tests__/Button.browser.spec.tsx +57 -0
  155. package/src/i18n/en/__tests__/uiEn.spec.ts +110 -0
  156. package/src/i18n/en/index.ts +22 -0
  157. package/src/i18n/en/uiEn.ts +1647 -0
  158. package/src/i18n/fr/uiFr.ts +7 -2
  159. package/src/markdown/MarkdownView.tsx +30 -1
  160. package/src/markdown/__tests__/highlightLines.spec.ts +45 -0
  161. package/src/markdown/highlightLines.ts +120 -0
  162. package/src/markdown/index.ts +14 -2
  163. package/src/shell/ButtonInbox.tsx +11 -1
  164. package/src/shell/PlateLayout.tsx +18 -9
  165. package/src/shell/__tests__/ButtonInbox.browser.spec.tsx +40 -0
  166. package/src/shell/__tests__/PlateLayout.browser.spec.tsx +19 -2
  167. package/src/sortable/__tests__/useSortableList.browser.spec.tsx +157 -0
  168. package/src/sortable/index.ts +22 -0
  169. package/src/sortable/useSortableItem.ts +65 -0
  170. package/src/sortable/useSortableList.ts +231 -0
  171. package/src/table/DataTable.tsx +8 -5
  172. package/src/table/DataTableRowActionGroupItem.tsx +75 -0
  173. package/src/table/DataTableRowActionItem.tsx +6 -0
  174. package/src/table/DataTableRowActionsInline.tsx +3 -1
  175. package/src/table/DataTableRowActionsMenu.tsx +33 -49
  176. package/src/table/__tests__/DataTablePersistenceStorage.browser.spec.tsx +204 -0
  177. package/src/table/__tests__/DataTableRowActionGroup.browser.spec.tsx +118 -1
  178. package/src/table/dataTableBaseProps.ts +16 -2
  179. package/src/table/dataTablePersistence.ts +118 -32
  180. package/src/table/dataTableTypes.ts +20 -3
  181. package/src/table/index.ts +14 -1
  182. package/src/table/useDataTableColumns.ts +9 -4
  183. package/src/table/useDataTableData.ts +8 -3
  184. package/src/table/useDataTableFilterForm.ts +6 -2
  185. package/src/table/useDataTableFilterVisibility.ts +20 -7
  186. package/src/table/useDataTableRefresh.ts +4 -2
  187. package/src/table/useDataTableSummary.ts +25 -8
@@ -38,6 +38,11 @@ class Links extends LinkProvider {
38
38
  const events = this.streams.shift() ?? [];
39
39
  return (async function* () {
40
40
  for (const event of events) {
41
+ // A `wait` holds the stream, so a spec sees a call running.
42
+ if (event.wait instanceof Promise) {
43
+ await event.wait;
44
+ continue;
45
+ }
41
46
  yield event;
42
47
  }
43
48
  })();
@@ -101,6 +106,29 @@ const DockLayout = (props: Partial<AiChatProps>) => {
101
106
  );
102
107
  };
103
108
 
109
+ /**
110
+ * The same, floating over the page's corner instead (#Q4269): no slot.
111
+ */
112
+ const FloatLayout = (props: Partial<AiChatProps>) => {
113
+ const [open, setOpen] = useState(true);
114
+ const [clicks, setClicks] = useState(0);
115
+ return (
116
+ <div data-testid="layout">
117
+ <main>
118
+ <button type="button" onClick={() => setOpen(true)}>
119
+ Ask
120
+ </button>
121
+ <button type="button" onClick={() => setClicks((n) => n + 1)}>
122
+ Page action
123
+ </button>
124
+ <span data-testid="open-state">{String(open)}</span>
125
+ <span data-testid="page-clicks">{clicks}</span>
126
+ </main>
127
+ <AiChat {...props} mode="floating" open={open} onOpenChange={setOpen} />
128
+ </div>
129
+ );
130
+ };
131
+
104
132
  describe("AiChat", () => {
105
133
  let alepha: Alepha | undefined;
106
134
 
@@ -357,6 +385,14 @@ describe("AiChat", () => {
357
385
  expect(fields.textContent).toContain("amount");
358
386
  expect(fields.textContent).toContain("120");
359
387
  expect(fields.textContent).not.toContain("body");
388
+ // A long input scrolls inside the card, and the answers stay outside the
389
+ // scroll, always on screen.
390
+ const body = view.getByTestId("ai-chat-confirm-body");
391
+ expect(body.className).toContain("max-h-80");
392
+ expect(body.className).toContain("overflow-y-auto");
393
+ expect(body.contains(view.getByRole("button", { name: "Approve" }))).toBe(
394
+ false,
395
+ );
360
396
 
361
397
  fireEvent.click(view.getByRole("button", { name: "Approve" }));
362
398
  await view.findByText("Created.");
@@ -446,7 +482,7 @@ describe("AiChat", () => {
446
482
  },
447
483
  ]);
448
484
  // A denial reads as cancelled, not as a failure.
449
- expect(view.getByTestId("ai-chat-tool").textContent).toBe(
485
+ expect(view.getByTestId("ai-chat-tool-trace-line").textContent).toBe(
450
486
  "deleteAll cancelled",
451
487
  );
452
488
  });
@@ -638,7 +674,9 @@ describe("AiChat", () => {
638
674
  fireEvent.click(await view.findByRole("button", { name: "My notes" }));
639
675
  await view.findByText("Two notes.");
640
676
  expect(links.bodies("chat")[0].message).toBe("list my notes");
641
- expect(view.getByTestId("ai-chat-tool").textContent).toBe("Searched notes");
677
+ expect(view.getByTestId("ai-chat-tool-trace-line").textContent).toBe(
678
+ "Searched notes",
679
+ );
642
680
  expect(view.queryByTestId("ai-chat-empty")).toBeNull();
643
681
 
644
682
  const box = document.querySelector(
@@ -654,6 +692,84 @@ describe("AiChat", () => {
654
692
  expect(box.value).toBe("");
655
693
  });
656
694
 
695
+ it("folds a run of tool calls into one line that opens on every step, and names only the call in flight", async () => {
696
+ let release = () => {};
697
+ const held = new Promise<void>((resolve) => {
698
+ release = resolve;
699
+ });
700
+ const { view, say } = await mount(
701
+ (l) => {
702
+ l.streams.push([
703
+ { type: "conversation", conversationId },
704
+ ...["s1", "s2", "s3", "s4"].flatMap((callId) => [
705
+ { type: "tool_call", callId, name: "search", input: {} },
706
+ { type: "tool_result", callId, name: "search" },
707
+ ]),
708
+ { type: "tool_call", callId: "q1", name: "quest_get", input: {} },
709
+ { wait: held },
710
+ { type: "tool_result", callId: "q1", name: "quest_get" },
711
+ { type: "text", text: "Found it." },
712
+ { type: "end", reason: "stop" },
713
+ ]);
714
+ },
715
+ {
716
+ toolLabel: (name, state) =>
717
+ name === "search"
718
+ ? "Searched the project"
719
+ : state === "running"
720
+ ? "Reading a quest"
721
+ : "Read a quest",
722
+ toolSummary: (tools) =>
723
+ `Searched ${tools.filter((t) => t.name === "search").length} times, read a quest`,
724
+ },
725
+ );
726
+ await say("find it");
727
+
728
+ // In flight: one line, naming the running call only.
729
+ await waitFor(() =>
730
+ expect(view.getByTestId("ai-chat-tool-trace-line").textContent).toBe(
731
+ "Reading a quest",
732
+ ),
733
+ );
734
+ expect(view.getAllByTestId("ai-chat-tool-trace")).toHaveLength(1);
735
+ expect(view.queryAllByTestId("ai-chat-tool")).toHaveLength(0);
736
+
737
+ release();
738
+ await view.findByText("Found it.");
739
+ expect(view.getAllByTestId("ai-chat-tool-trace")).toHaveLength(1);
740
+ const line = view.getByTestId("ai-chat-tool-trace-line");
741
+ expect(line.textContent).toBe("Searched 4 times, read a quest");
742
+
743
+ fireEvent.click(line);
744
+ const steps = view.getAllByTestId("ai-chat-tool");
745
+ expect(steps.map((step) => step.textContent)).toEqual([
746
+ "Searched the projectsearch",
747
+ "Searched the projectsearch",
748
+ "Searched the projectsearch",
749
+ "Searched the projectsearch",
750
+ "Read a questquest_get",
751
+ ]);
752
+ });
753
+
754
+ it("says how many tools ran when the app gives no summary", async () => {
755
+ const { view, say } = await mount((l) => {
756
+ l.streams.push([
757
+ { type: "conversation", conversationId },
758
+ { type: "tool_call", callId: "a", name: "findNotes", input: {} },
759
+ { type: "tool_result", callId: "a", name: "findNotes" },
760
+ { type: "tool_call", callId: "b", name: "readNote", input: {} },
761
+ { type: "tool_result", callId: "b", name: "readNote", isError: true },
762
+ { type: "text", text: "Partly." },
763
+ { type: "end", reason: "stop" },
764
+ ]);
765
+ });
766
+ await say("notes");
767
+ await view.findByText("Partly.");
768
+ expect(view.getByTestId("ai-chat-tool-trace-line").textContent).toBe(
769
+ "Used 2 tools",
770
+ );
771
+ });
772
+
657
773
  it("locks the composer while a confirmation waits", async () => {
658
774
  const { view, say } = await mount((l) => {
659
775
  l.streams.push([
@@ -676,6 +792,158 @@ describe("AiChat", () => {
676
792
  expect(box.placeholder).toBe("Confirm or cancel the card to go on");
677
793
  });
678
794
 
795
+ it("goes full screen between minimize and close, keeps the conversation, and comes back by its button or Escape", async () => {
796
+ const { view, say } = await mount(
797
+ (l) => {
798
+ l.streams.push([
799
+ { type: "conversation", conversationId },
800
+ { type: "text", text: "Hello there." },
801
+ { type: "end", reason: "stop" },
802
+ ]);
803
+ },
804
+ {},
805
+ DockLayout,
806
+ );
807
+ await view.findByTestId("ai-chat-dock");
808
+ await say("hi");
809
+ await view.findByText("Hello there.");
810
+
811
+ const labels = () =>
812
+ [
813
+ ...view.getByTestId("ai-chat").querySelectorAll("button[aria-label]"),
814
+ ].map((button) => button.getAttribute("aria-label"));
815
+ const header = labels();
816
+ const at = header.indexOf("Minimize");
817
+ expect(header.slice(at, at + 3)).toEqual([
818
+ "Minimize",
819
+ "Full screen",
820
+ "Close",
821
+ ]);
822
+
823
+ fireEvent.click(view.getByRole("button", { name: "Full screen" }));
824
+ const dialog = await view.findByTestId("ai-chat-fullscreen");
825
+ expect(dialog.getAttribute("role")).toBe("dialog");
826
+ expect(view.queryByTestId("ai-chat-dock")).toBeNull();
827
+ expect(within(dialog).getByText("Hello there.")).toBeTruthy();
828
+ const back = within(dialog).getByRole("button", {
829
+ name: "Exit full screen",
830
+ });
831
+ expect(back.getAttribute("aria-pressed")).toBe("true");
832
+
833
+ fireEvent.click(back);
834
+ await view.findByTestId("ai-chat-dock");
835
+ await waitFor(() =>
836
+ expect(view.queryByTestId("ai-chat-fullscreen")).toBeNull(),
837
+ );
838
+ expect(view.getByText("Hello there.")).toBeTruthy();
839
+
840
+ fireEvent.click(view.getByRole("button", { name: "Full screen" }));
841
+ await view.findByTestId("ai-chat-fullscreen");
842
+ fireEvent.keyDown(document.activeElement ?? document.body, {
843
+ key: "Escape",
844
+ });
845
+ await view.findByTestId("ai-chat-dock");
846
+ });
847
+
848
+ it("floats over the page's corner without a backdrop, keeps the page usable, minimizes into a pill and restores", async () => {
849
+ const { view } = await mount(
850
+ () => {},
851
+ { title: "Lore", subtitle: "claude-sonnet-5-5" },
852
+ FloatLayout,
853
+ );
854
+
855
+ const card = await view.findByTestId("ai-chat-float");
856
+ expect(card.parentElement).toBe(document.body);
857
+ expect(view.queryByRole("dialog")).toBeNull();
858
+ expect(document.querySelector("[data-slot='drawer-overlay']")).toBeNull();
859
+ expect(view.getByTestId("ai-chat-subtitle").textContent).toBe(
860
+ "claude-sonnet-5-5",
861
+ );
862
+ // The composer is the card's last part, under the conversation.
863
+ expect(card.querySelector("textarea")).toBeTruthy();
864
+
865
+ // The page under it still answers a click, and the card stays.
866
+ fireEvent.click(view.getByRole("button", { name: "Page action" }));
867
+ expect(view.getByTestId("page-clicks").textContent).toBe("1");
868
+ expect(view.getByTestId("ai-chat-float")).toBeTruthy();
869
+
870
+ fireEvent.click(view.getByRole("button", { name: "Minimize" }));
871
+ expect(view.queryByTestId("ai-chat-float")).toBeNull();
872
+ expect(view.getByTestId("open-state").textContent).toBe("false");
873
+ fireEvent.click(view.getByTestId("ai-chat-launcher"));
874
+ await view.findByTestId("ai-chat-float");
875
+
876
+ fireEvent.click(view.getByTestId("ai-chat-maximize"));
877
+ await view.findByTestId("ai-chat-fullscreen");
878
+ fireEvent.keyDown(document.activeElement ?? document.body, {
879
+ key: "Escape",
880
+ });
881
+ await view.findByTestId("ai-chat-float");
882
+
883
+ fireEvent.click(view.getByRole("button", { name: "Close" }));
884
+ expect(view.queryByTestId("ai-chat-float")).toBeNull();
885
+ expect(view.queryByTestId("ai-chat-launcher")).toBeNull();
886
+ });
887
+
888
+ it("keeps a long code line inside its own block: the thread never scrolls sideways, and the float is wider (#Q4546)", async () => {
889
+ const long = `lore host update my-vps --stats-history --stats-interval 60 ${"--flag ".repeat(40)}`;
890
+ const { view, say } = await mount(
891
+ (l) => {
892
+ l.streams.push([
893
+ { type: "conversation", conversationId },
894
+ {
895
+ type: "text",
896
+ text: `Run:\n\n\`\`\`sh\n${long}\n\`\`\`\n\n| flag | value |\n| --- | --- |\n| a | b |\n`,
897
+ },
898
+ { type: "end", reason: "stop" },
899
+ ]);
900
+ },
901
+ {},
902
+ FloatLayout,
903
+ );
904
+
905
+ await say(`and ${"https://example.app/a/very/long/path/".repeat(6)}?`);
906
+ const reply = await waitFor(() => {
907
+ const found = view.getByTestId("ai-chat-assistant");
908
+ expect(found.querySelector("pre")?.textContent?.trim()).toBe(long.trim());
909
+ return found;
910
+ });
911
+
912
+ const thread = view.getByTestId("ai-chat-thread");
913
+ expect(thread.scrollWidth).toBeLessThanOrEqual(thread.clientWidth);
914
+ // jsdom lays nothing out, so the classes are what hold it: the thread
915
+ // hides what is wider than it, each row is capped at the column (its
916
+ // margin taken off) and may shrink below its content, the code block
917
+ // scrolls on its own, and a long word or URL breaks.
918
+ const classes = (element: Element) => element.className.split(/\s+/);
919
+ expect(classes(thread)).toEqual(
920
+ expect.arrayContaining(["overflow-x-hidden", "overflow-y-auto"]),
921
+ );
922
+ expect(classes(reply)).toEqual(
923
+ expect.arrayContaining([
924
+ "min-w-0",
925
+ "max-w-[calc(100%-1rem)]",
926
+ "break-words",
927
+ ]),
928
+ );
929
+ expect(classes(view.getByTestId("ai-chat-user"))).toEqual(
930
+ expect.arrayContaining([
931
+ "min-w-0",
932
+ "max-w-[calc(100%-2.5rem)]",
933
+ "break-words",
934
+ ]),
935
+ );
936
+ expect(classes(reply.querySelector("pre")!)).toContain("overflow-auto");
937
+ // A wide table scrolls in its own box, since the thread hides overflow.
938
+ expect(classes(reply.querySelector("table")!.parentElement!)).toContain(
939
+ "overflow-x-auto",
940
+ );
941
+ // 30rem on a desktop, and never past the viewport on a phone.
942
+ expect(classes(view.getByTestId("ai-chat-float"))).toContain(
943
+ "w-[min(30rem,calc(100vw-2rem))]",
944
+ );
945
+ });
946
+
679
947
  it("docks beside the page without a backdrop, minimizes into a pill that shows a waiting action, and restores", async () => {
680
948
  const { view, say } = await mount(
681
949
  (l) => {
package/src/ai/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The in-app assistant on the client: a chat in a drawer or docked beside
3
- * the page, with streamed replies, history and a confirmation card per
2
+ * The in-app assistant on the client: a chat in a drawer, docked beside
3
+ * the page or floating over its corner, with streamed replies, history and a confirmation card per
4
4
  * mutation, the headless `useAiChat`, and `useAiContext` for a page to
5
5
  * declare what it shows. Talks to `alepha/api/ai`.
6
6
  *
@@ -14,10 +14,12 @@ export * from "./AiChatConfirmFields.tsx";
14
14
  export * from "./AiChatDock.tsx";
15
15
  export * from "./AiChatDockSlot.tsx";
16
16
  export * from "./AiChatEmpty.tsx";
17
+ export * from "./AiChatFloat.tsx";
17
18
  export * from "./AiChatHistory.tsx";
18
19
  export * from "./AiChatLauncher.tsx";
19
20
  export * from "./AiChatMessage.tsx";
20
21
  export * from "./AiChatPanel.tsx";
22
+ export * from "./AiChatToolTrace.tsx";
21
23
  export * from "./aiChatMessageFormSchema.ts";
22
24
  export * from "./aiContextAtom.ts";
23
25
  export * from "./AiFormRegistry.ts";
@@ -2,6 +2,7 @@ import { Button as ButtonPrimitive } from "@base-ui/react/button";
2
2
  import { Link } from "alepha/react/router";
3
3
  import { cva, type VariantProps } from "class-variance-authority";
4
4
  import { Loader2Icon } from "lucide-react";
5
+ import { Children, type ReactNode } from "react";
5
6
 
6
7
  import { textLinkUnderlineClassName } from "./TextLink.tsx";
7
8
  import { cn } from "./utils.ts";
@@ -386,10 +387,34 @@ const Button = (props: ButtonProps) => {
386
387
  "text-transparent [&_*]:opacity-0": loading,
387
388
  })}
388
389
  >
389
- {children}
390
+ {Children.count(children) > 1
391
+ ? Children.map(children, wrapLabelText)
392
+ : children}
390
393
  </span>
391
394
  </ButtonPrimitive>
392
395
  );
393
396
  };
394
397
 
398
+ /**
399
+ * Gives a label that sits beside other children an element of its own.
400
+ *
401
+ * A page translator (Chrome's "Translate this page") replaces each text node
402
+ * it translates with `<font>` elements, while React keeps the original node.
403
+ * The next icon swap beside it, `{busy ? <Loader2 /> : <Paperclip />}`, calls
404
+ * `insertBefore(newIcon, textNode)` with a node that is no longer a child, and
405
+ * the whole tree throws `NotFoundError` (#Q4189). Inside a `<span>` the label
406
+ * is replaced in place and the span stays the reference node.
407
+ *
408
+ * A lone label is left bare: with no sibling there is no insert against it.
409
+ * Whitespace stays bare too, since a flex container ignores it and a span of
410
+ * it would add a gap.
411
+ */
412
+ const wrapLabelText = (child: ReactNode): ReactNode =>
413
+ (typeof child === "string" && child.trim() !== "") ||
414
+ typeof child === "number" ? (
415
+ <span>{child}</span>
416
+ ) : (
417
+ child
418
+ );
419
+
395
420
  export { Button, buttonVariants };
@@ -58,8 +58,12 @@ const DialogContent = (props: DialogContentProps) => {
58
58
  data-slot="dialog-content"
59
59
  className={cn(
60
60
  // `left-1/2` with `-translate-x-1/2` is physical on purpose: centring
61
- // lands on the same point in either reading direction.
62
- "bg-popover text-popover-foreground ring-foreground/10 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl p-4 text-sm ring-1 duration-100 outline-none sm:max-w-sm",
61
+ // lands on the same point in either reading direction. The height is
62
+ // bound to the viewport and the popup scrolls, so a tall body never
63
+ // pushes the footer's buttons out of reach. A dialog that sizes and
64
+ // scrolls itself overrides both (`overflow-visible` keeps what it
65
+ // had before the cap).
66
+ "bg-popover text-popover-foreground ring-foreground/10 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 fixed top-1/2 left-1/2 z-50 grid max-h-[calc(100dvh-2rem)] w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 overflow-y-auto rounded-xl p-4 text-sm ring-1 duration-100 outline-none sm:max-w-sm",
63
67
  className,
64
68
  )}
65
69
  {...rest}
@@ -45,10 +45,9 @@ export interface TimeAgoProps {
45
45
  *
46
46
  * The server renders the EXACT datetime rather than nothing. A crawler, a
47
47
  * reader with no JavaScript and the first paint all get a true answer instead
48
- * of a blank, which matters on `/:projectSlug/roadmap` - the one page Lore
49
- * server-renders for an audience that may never run the client. The visible
50
- * swap on hydration is the price, and it is a swap from correct to more
51
- * readable.
48
+ * of a blank, which matters on a page server-rendered for an audience that
49
+ * may never run the client. The visible swap on hydration is the price, and
50
+ * it is a swap from correct to more readable.
52
51
  *
53
52
  * ## Where NOT to use it
54
53
  *
@@ -61,3 +61,60 @@ describe("Button loading", () => {
61
61
  );
62
62
  });
63
63
  });
64
+
65
+ /**
66
+ * A page translator (Chrome's "Translate this page") replaces every text node
67
+ * it translates with `<font>` elements. React still holds the original node,
68
+ * so the next `insertBefore(newIcon, textNode)` throws `NotFoundError` and the
69
+ * whole tree falls to the error boundary. A label beside a conditional icon is
70
+ * exactly that shape: the label must be an element of its own.
71
+ */
72
+ describe("Button under a page translator", () => {
73
+ const translate = (root: HTMLElement) => {
74
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
75
+ const nodes: Text[] = [];
76
+ while (walker.nextNode()) nodes.push(walker.currentNode as Text);
77
+ for (const node of nodes) {
78
+ const font = document.createElement("font");
79
+ font.textContent = `fr:${node.data}`;
80
+ node.replaceWith(font);
81
+ }
82
+ };
83
+
84
+ const IconSwap = (props: { busy: boolean }) => (
85
+ <Button>
86
+ {props.busy ? <i data-testid="busy" /> : <b data-testid="idle" />}
87
+ Attach
88
+ </Button>
89
+ );
90
+
91
+ it("swaps an icon beside a translated label without throwing", () => {
92
+ const view = render(<IconSwap busy={false} />);
93
+ translate(view.container);
94
+
95
+ expect(() => view.rerender(<IconSwap busy />)).not.toThrow();
96
+ expect(screen.getByTestId("busy")).toBeTruthy();
97
+ expect(screen.queryByTestId("idle")).toBeNull();
98
+ });
99
+
100
+ it("mounts a conditional icon beside a translated label without throwing", () => {
101
+ const Submit = (props: { busy: boolean }) => (
102
+ <Button>
103
+ {props.busy && <i data-testid="busy" />}
104
+ Send
105
+ </Button>
106
+ );
107
+ const view = render(<Submit busy={false} />);
108
+ translate(view.container);
109
+
110
+ expect(() => view.rerender(<Submit busy />)).not.toThrow();
111
+ expect(screen.getByTestId("busy")).toBeTruthy();
112
+ });
113
+
114
+ it("leaves a lone label as the content itself", () => {
115
+ render(<Button>Save</Button>);
116
+
117
+ expect(screen.getByText("Save").getAttribute("data-slot")).toBeNull();
118
+ expect(screen.getByText("Save").className).toContain("contents");
119
+ });
120
+ });
@@ -0,0 +1,110 @@
1
+ import { readdirSync, readFileSync, statSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import { describe, expect, it } from "vitest";
5
+
6
+ import { uiFr } from "../../fr/uiFr.ts";
7
+ import { uiEn } from "../uiEn.ts";
8
+
9
+ /**
10
+ * The English catalogue must say what the components already say.
11
+ *
12
+ * An application spreads `uiEn` into its `en` catalogue, where it wins over the
13
+ * `default` a component passes to `tr()`. So the two must agree: a component
14
+ * whose default is reworded while `uiEn` keeps the old text would show the old
15
+ * text to every application that spreads it, and nothing else would notice.
16
+ *
17
+ * Coverage is checked against `uiFr`, whose own spec checks it against every
18
+ * key the package asks for: the same key set here means the same coverage.
19
+ */
20
+ const SRC = join(import.meta.dirname, "..", "..", "..", "..", "src");
21
+
22
+ /**
23
+ * Every literal default, by key: `tr("key", { default: "…" })` on one call,
24
+ * the form most call sites take. A key may carry two (an `aria-label` and a
25
+ * heading reading the same key), so each key maps to the set it was given.
26
+ * Defaults built from a template literal or a variant object are not read
27
+ * here; the placeholder check below still covers them.
28
+ */
29
+ const DEFAULT_PATTERN =
30
+ /\btr\(\s*"([a-zA-Z][\w.]*)",\s*\{\s*default:\s*"((?:[^"\\]|\\.)*)"/g;
31
+
32
+ const collectDefaults = (
33
+ dir: string,
34
+ found = new Map<string, Set<string>>(),
35
+ ): Map<string, Set<string>> => {
36
+ for (const entry of readdirSync(dir)) {
37
+ const path = join(dir, entry);
38
+ if (statSync(path).isDirectory()) {
39
+ if (entry !== "__tests__" && entry !== "i18n") {
40
+ collectDefaults(path, found);
41
+ }
42
+ continue;
43
+ }
44
+ if (!/\.tsx?$/.test(entry)) {
45
+ continue;
46
+ }
47
+ for (const match of readFileSync(path, "utf8").matchAll(DEFAULT_PATTERN)) {
48
+ const key = match[1] as string;
49
+ const value = JSON.parse(`"${match[2]}"`) as string;
50
+ found.set(key, (found.get(key) ?? new Set()).add(value));
51
+ }
52
+ }
53
+ return found;
54
+ };
55
+
56
+ /** The `$1` and `{name}` placeholders of an entry, every variant included. */
57
+ const placeholders = (entry: (typeof uiEn)[string]): string[] => {
58
+ const text =
59
+ typeof entry === "string" ? entry : Object.values(entry).join(" ");
60
+ return [...new Set(text.match(/\$\d+|\{\w+\}/g) ?? [])].sort();
61
+ };
62
+
63
+ describe("uiEn", () => {
64
+ it("holds exactly the keys uiFr holds", () => {
65
+ expect(Object.keys(uiEn).sort()).toEqual(Object.keys(uiFr).sort());
66
+ });
67
+
68
+ it("matches each component's literal default", () => {
69
+ const defaults = collectDefaults(SRC);
70
+ // Guards the guard: a pattern matching nothing would pass for nothing.
71
+ expect(defaults.size).toBeGreaterThan(500);
72
+
73
+ const drift = [...defaults]
74
+ .filter(([key, values]) => {
75
+ const entry = uiEn[key];
76
+ return typeof entry !== "string" || !values.has(entry);
77
+ })
78
+ .map(
79
+ ([key, values]) =>
80
+ `${key}: ${JSON.stringify(uiEn[key])} vs ${[...values].map((v) => JSON.stringify(v)).join(" | ")}`,
81
+ );
82
+ expect(drift).toEqual([]);
83
+ });
84
+
85
+ it("uses the placeholders uiFr uses, key by key", () => {
86
+ const mismatched = Object.keys(uiFr)
87
+ .filter((key) => {
88
+ const en = uiEn[key];
89
+ const fr = uiFr[key];
90
+ return (
91
+ en === undefined ||
92
+ fr === undefined ||
93
+ placeholders(en).join() !== placeholders(fr).join()
94
+ );
95
+ })
96
+ .sort();
97
+ expect(mismatched).toEqual([]);
98
+ });
99
+
100
+ it("leaves no value empty, nor any variant of a plural entry", () => {
101
+ const blank = Object.entries(uiEn)
102
+ .filter(([, value]) =>
103
+ typeof value === "string"
104
+ ? value.trim() === ""
105
+ : Object.values(value).some((variant) => variant.trim() === ""),
106
+ )
107
+ .map(([key]) => key);
108
+ expect(blank).toEqual([]);
109
+ });
110
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The English catalogue for every key `@alepha/ui` asks for.
3
+ *
4
+ * The components default to English already; this record is for an application
5
+ * whose fallback language is not English, where a key missing from the `en`
6
+ * catalogue would otherwise be read in the fallback language. A plain record
7
+ * the application spreads into its own catalogue, and a subpath of its own so
8
+ * that catalogue can load it lazily:
9
+ *
10
+ * ```ts
11
+ * en = $dictionary({
12
+ * lazy: async () => {
13
+ * const { uiEn } = await import("@alepha/ui/i18n/en");
14
+ * return { default: { ...uiEn, "nav.home": "Home" } };
15
+ * },
16
+ * });
17
+ * ```
18
+ *
19
+ * @module alepha.ui.i18n.en
20
+ */
21
+
22
+ export { uiEn } from "./uiEn.ts";