@alepha/ui 0.36.1 → 0.37.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 (288) hide show
  1. package/dist/account/$pageAccount.d.ts +1 -1
  2. package/dist/account/$pageAccount.d.ts.map +1 -1
  3. package/dist/account/$pageAccount.js.map +1 -1
  4. package/dist/account/AccountDisplay.d.ts +13 -0
  5. package/dist/account/AccountDisplay.d.ts.map +1 -0
  6. package/dist/account/AccountDisplay.js +48 -0
  7. package/dist/account/AccountDisplay.js.map +1 -0
  8. package/dist/account/AccountProfile.d.ts.map +1 -1
  9. package/dist/account/AccountProfile.js +14 -10
  10. package/dist/account/AccountProfile.js.map +1 -1
  11. package/dist/account/AccountRouter.d.ts +6 -6
  12. package/dist/account/AccountRouter.d.ts.map +1 -1
  13. package/dist/account/index.d.ts +5 -0
  14. package/dist/account/index.d.ts.map +1 -1
  15. package/dist/account/index.js +2 -1
  16. package/dist/admin/$pageAdmin.d.ts +1 -1
  17. package/dist/admin/$pageAdmin.d.ts.map +1 -1
  18. package/dist/admin/$pageAdmin.js.map +1 -1
  19. package/dist/admin/AdminAudits.js.map +1 -1
  20. package/dist/admin/AdminJobDetail.js.map +1 -1
  21. package/dist/admin/AdminJobs.js.map +1 -1
  22. package/dist/admin/AdminNotifications.js.map +1 -1
  23. package/dist/admin/AdminRouter.d.ts +14 -14
  24. package/dist/admin/AdminRouter.d.ts.map +1 -1
  25. package/dist/admin/AdminUserDetail.js.map +1 -1
  26. package/dist/admin/AdminUsers.js.map +1 -1
  27. package/dist/admin/ParameterHistoryItem.js.map +1 -1
  28. package/dist/ai/AiChat.d.ts +26 -39
  29. package/dist/ai/AiChat.d.ts.map +1 -1
  30. package/dist/ai/AiChat.js +65 -123
  31. package/dist/ai/AiChat.js.map +1 -1
  32. package/dist/ai/AiChatDock.d.ts +23 -0
  33. package/dist/ai/AiChatDock.d.ts.map +1 -0
  34. package/dist/ai/AiChatDock.js +90 -0
  35. package/dist/ai/AiChatDock.js.map +1 -0
  36. package/dist/ai/AiChatDockSlot.d.ts +15 -0
  37. package/dist/ai/AiChatDockSlot.d.ts.map +1 -0
  38. package/dist/ai/AiChatDockSlot.js +20 -0
  39. package/dist/ai/AiChatDockSlot.js.map +1 -0
  40. package/dist/ai/AiChatLauncher.d.ts +17 -0
  41. package/dist/ai/AiChatLauncher.d.ts.map +1 -0
  42. package/dist/ai/AiChatLauncher.js +42 -0
  43. package/dist/ai/AiChatLauncher.js.map +1 -0
  44. package/dist/ai/AiChatMessage.d.ts +6 -0
  45. package/dist/ai/AiChatMessage.d.ts.map +1 -1
  46. package/dist/ai/AiChatMessage.js +20 -4
  47. package/dist/ai/AiChatMessage.js.map +1 -1
  48. package/dist/ai/AiChatPanel.d.ts +71 -0
  49. package/dist/ai/AiChatPanel.d.ts.map +1 -0
  50. package/dist/ai/AiChatPanel.js +143 -0
  51. package/dist/ai/AiChatPanel.js.map +1 -0
  52. package/dist/ai/index.d.ts +8 -4
  53. package/dist/ai/index.d.ts.map +1 -1
  54. package/dist/ai/index.js +5 -1
  55. package/dist/ai/useAiChat.d.ts +12 -0
  56. package/dist/ai/useAiChat.d.ts.map +1 -1
  57. package/dist/ai/useAiChat.js +32 -15
  58. package/dist/ai/useAiChat.js.map +1 -1
  59. package/dist/auth/AuthLogin.d.ts +9 -0
  60. package/dist/auth/AuthLogin.d.ts.map +1 -1
  61. package/dist/auth/AuthLogin.js +2 -2
  62. package/dist/auth/AuthLogin.js.map +1 -1
  63. package/dist/auth/AuthRegister.d.ts +4 -1
  64. package/dist/auth/AuthRegister.d.ts.map +1 -1
  65. package/dist/auth/AuthRegister.js +1 -1
  66. package/dist/auth/AuthRegister.js.map +1 -1
  67. package/dist/auth/AuthResetPassword.d.ts +8 -0
  68. package/dist/auth/AuthResetPassword.d.ts.map +1 -1
  69. package/dist/auth/AuthResetPassword.js +2 -2
  70. package/dist/auth/AuthResetPassword.js.map +1 -1
  71. package/dist/auth/AuthRouter.d.ts +4 -4
  72. package/dist/auth/AuthRouter.d.ts.map +1 -1
  73. package/dist/core/Badge.d.ts.map +1 -1
  74. package/dist/core/Badge.js +7 -3
  75. package/dist/core/Badge.js.map +1 -1
  76. package/dist/core/Collapsible.d.ts +50 -0
  77. package/dist/core/Collapsible.d.ts.map +1 -0
  78. package/dist/core/Collapsible.js +70 -0
  79. package/dist/core/Collapsible.js.map +1 -0
  80. package/dist/core/Combobox.d.ts +7 -1
  81. package/dist/core/Combobox.d.ts.map +1 -1
  82. package/dist/core/Combobox.js +2 -2
  83. package/dist/core/Combobox.js.map +1 -1
  84. package/dist/core/PaneRail.d.ts +24 -7
  85. package/dist/core/PaneRail.d.ts.map +1 -1
  86. package/dist/core/PaneRail.js +24 -19
  87. package/dist/core/PaneRail.js.map +1 -1
  88. package/dist/core/Stepper.d.ts +36 -0
  89. package/dist/core/Stepper.d.ts.map +1 -0
  90. package/dist/core/Stepper.js +54 -0
  91. package/dist/core/Stepper.js.map +1 -0
  92. package/dist/core/index.d.ts +2 -0
  93. package/dist/core/index.d.ts.map +1 -1
  94. package/dist/core/index.js +3 -1
  95. package/dist/core/useToast.js +13 -13
  96. package/dist/core/useToast.js.map +1 -1
  97. package/dist/form/AutoForm.d.ts.map +1 -1
  98. package/dist/form/AutoForm.js +29 -0
  99. package/dist/form/AutoForm.js.map +1 -1
  100. package/dist/form/AutoFormErrorPopover.js +13 -3
  101. package/dist/form/AutoFormErrorPopover.js.map +1 -1
  102. package/dist/form/Control.d.ts +14 -1
  103. package/dist/form/Control.d.ts.map +1 -1
  104. package/dist/form/Control.js +12 -2
  105. package/dist/form/Control.js.map +1 -1
  106. package/dist/form/ControlDate.d.ts.map +1 -1
  107. package/dist/form/ControlDate.js +3 -0
  108. package/dist/form/ControlDate.js.map +1 -1
  109. package/dist/form/ControlDateRange.d.ts +12 -1
  110. package/dist/form/ControlDateRange.d.ts.map +1 -1
  111. package/dist/form/ControlDateRange.js +11 -1
  112. package/dist/form/ControlDateRange.js.map +1 -1
  113. package/dist/form/ControlNumber.d.ts.map +1 -1
  114. package/dist/form/ControlNumber.js +2 -0
  115. package/dist/form/ControlNumber.js.map +1 -1
  116. package/dist/form/ControlObject.d.ts.map +1 -1
  117. package/dist/form/ControlObject.js +15 -1
  118. package/dist/form/ControlObject.js.map +1 -1
  119. package/dist/form/ControlPassword.d.ts +4 -0
  120. package/dist/form/ControlPassword.d.ts.map +1 -1
  121. package/dist/form/ControlPassword.js +1 -0
  122. package/dist/form/ControlPassword.js.map +1 -1
  123. package/dist/form/ControlSelect.d.ts +23 -1
  124. package/dist/form/ControlSelect.d.ts.map +1 -1
  125. package/dist/form/ControlSelect.js +5 -0
  126. package/dist/form/ControlSelect.js.map +1 -1
  127. package/dist/form/ControlSelectCombobox.d.ts +11 -1
  128. package/dist/form/ControlSelectCombobox.d.ts.map +1 -1
  129. package/dist/form/ControlSelectCombobox.js +9 -1
  130. package/dist/form/ControlSelectCombobox.js.map +1 -1
  131. package/dist/form/ControlUpload.d.ts.map +1 -1
  132. package/dist/form/ControlUpload.js +1 -0
  133. package/dist/form/ControlUpload.js.map +1 -1
  134. package/dist/form/FormField.d.ts +5 -0
  135. package/dist/form/FormField.d.ts.map +1 -1
  136. package/dist/form/FormField.js +7 -0
  137. package/dist/form/FormField.js.map +1 -1
  138. package/dist/i18n/fr/uiFr.d.ts.map +1 -1
  139. package/dist/i18n/fr/uiFr.js +14 -0
  140. package/dist/i18n/fr/uiFr.js.map +1 -1
  141. package/dist/shell/$pageNav.d.ts +2 -2
  142. package/dist/shell/$pageNav.d.ts.map +1 -1
  143. package/dist/shell/$pageNav.js.map +1 -1
  144. package/dist/shell/AppShell.d.ts +6 -0
  145. package/dist/shell/AppShell.d.ts.map +1 -1
  146. package/dist/shell/AppShell.js +31 -27
  147. package/dist/shell/AppShell.js.map +1 -1
  148. package/dist/shell/ButtonSettings.d.ts +6 -2
  149. package/dist/shell/ButtonSettings.d.ts.map +1 -1
  150. package/dist/shell/ButtonSettings.js +17 -3
  151. package/dist/shell/ButtonSettings.js.map +1 -1
  152. package/dist/shell/ButtonSettingsVisionMenuItem.d.ts +16 -0
  153. package/dist/shell/ButtonSettingsVisionMenuItem.d.ts.map +1 -0
  154. package/dist/shell/ButtonSettingsVisionMenuItem.js +24 -0
  155. package/dist/shell/ButtonSettingsVisionMenuItem.js.map +1 -0
  156. package/dist/shell/ButtonVision.d.ts +28 -0
  157. package/dist/shell/ButtonVision.d.ts.map +1 -0
  158. package/dist/shell/ButtonVision.js +46 -0
  159. package/dist/shell/ButtonVision.js.map +1 -0
  160. package/dist/shell/index.d.ts +6 -3
  161. package/dist/shell/index.d.ts.map +1 -1
  162. package/dist/shell/index.js +2 -1
  163. package/dist/styles.css +57 -0
  164. package/dist/table/DataTable.d.ts.map +1 -1
  165. package/dist/table/DataTable.js +29 -4
  166. package/dist/table/DataTable.js.map +1 -1
  167. package/dist/table/DataTableColumnPicker.d.ts.map +1 -1
  168. package/dist/table/DataTableColumnPicker.js +1 -0
  169. package/dist/table/DataTableColumnPicker.js.map +1 -1
  170. package/dist/table/DataTableFilterBar.d.ts +1 -1
  171. package/dist/table/DataTableFilterBar.d.ts.map +1 -1
  172. package/dist/table/DataTableFilterBar.js +5 -108
  173. package/dist/table/DataTableFilterBar.js.map +1 -1
  174. package/dist/table/DataTableHeaderFilter.d.ts +51 -0
  175. package/dist/table/DataTableHeaderFilter.d.ts.map +1 -0
  176. package/dist/table/DataTableHeaderFilter.js +113 -0
  177. package/dist/table/DataTableHeaderFilter.js.map +1 -0
  178. package/dist/table/DataTableHeaderRow.d.ts +7 -0
  179. package/dist/table/DataTableHeaderRow.d.ts.map +1 -1
  180. package/dist/table/DataTableHeaderRow.js +92 -74
  181. package/dist/table/DataTableHeaderRow.js.map +1 -1
  182. package/dist/table/DataTableTabs.d.ts +42 -0
  183. package/dist/table/DataTableTabs.d.ts.map +1 -0
  184. package/dist/table/DataTableTabs.js +55 -0
  185. package/dist/table/DataTableTabs.js.map +1 -0
  186. package/dist/table/dataTableBaseProps.d.ts +12 -0
  187. package/dist/table/dataTableBaseProps.d.ts.map +1 -1
  188. package/dist/table/dataTablePersistence.d.ts.map +1 -1
  189. package/dist/table/dataTablePersistence.js +4 -2
  190. package/dist/table/dataTablePersistence.js.map +1 -1
  191. package/dist/table/dataTableTypes.d.ts +18 -0
  192. package/dist/table/dataTableTypes.d.ts.map +1 -1
  193. package/dist/table/index.d.ts +5 -2
  194. package/dist/table/index.d.ts.map +1 -1
  195. package/dist/table/index.js +2 -1
  196. package/dist/table/useDataTableColumns.d.ts.map +1 -1
  197. package/dist/table/useDataTableColumns.js +1 -0
  198. package/dist/table/useDataTableColumns.js.map +1 -1
  199. package/dist/table/useDataTableFilterModel.d.ts +110 -0
  200. package/dist/table/useDataTableFilterModel.d.ts.map +1 -0
  201. package/dist/table/useDataTableFilterModel.js +154 -0
  202. package/dist/table/useDataTableFilterModel.js.map +1 -0
  203. package/docs/packages-alepha-ui-account.md +4 -0
  204. package/docs/packages-alepha-ui-ai.md +5 -5
  205. package/docs/packages-alepha-ui-shell.md +4 -3
  206. package/docs/packages-alepha-ui-table.md +4 -2
  207. package/package.json +8 -8
  208. package/src/account/$pageAccount.tsx +5 -4
  209. package/src/account/AccountDisplay.tsx +58 -0
  210. package/src/account/AccountProfile.tsx +30 -42
  211. package/src/account/__tests__/AccountProfile.browser.spec.tsx +141 -0
  212. package/src/account/__tests__/AccountRecoveryCodes.browser.spec.tsx +1 -1
  213. package/src/account/index.ts +5 -0
  214. package/src/admin/$pageAdmin.tsx +5 -4
  215. package/src/admin/AdminAudits.tsx +1 -1
  216. package/src/admin/AdminJobDetail.tsx +1 -1
  217. package/src/admin/AdminJobs.tsx +1 -1
  218. package/src/admin/AdminNotifications.tsx +1 -1
  219. package/src/admin/AdminUserDetail.tsx +1 -1
  220. package/src/admin/AdminUsers.tsx +1 -1
  221. package/src/admin/ParameterHistoryItem.tsx +1 -1
  222. package/src/admin/__tests__/AdminFilesUsageCard.browser.spec.tsx +17 -9
  223. package/src/ai/AiChat.tsx +94 -183
  224. package/src/ai/AiChatDock.tsx +129 -0
  225. package/src/ai/AiChatDockSlot.tsx +23 -0
  226. package/src/ai/AiChatLauncher.tsx +58 -0
  227. package/src/ai/AiChatMessage.tsx +36 -2
  228. package/src/ai/AiChatPanel.tsx +252 -0
  229. package/src/ai/__tests__/AiChat.browser.spec.tsx +187 -5
  230. package/src/ai/index.ts +8 -4
  231. package/src/ai/useAiChat.ts +63 -14
  232. package/src/auth/AuthLogin.tsx +19 -4
  233. package/src/auth/AuthRegister.tsx +6 -3
  234. package/src/auth/AuthResetPassword.tsx +18 -8
  235. package/src/auth/__tests__/AuthCancel.browser.spec.tsx +129 -0
  236. package/src/core/Badge.tsx +7 -3
  237. package/src/core/Collapsible.tsx +95 -0
  238. package/src/core/Combobox.tsx +11 -3
  239. package/src/core/PaneRail.tsx +36 -20
  240. package/src/core/Stepper.tsx +118 -0
  241. package/src/core/__tests__/Badge.browser.spec.tsx +5 -5
  242. package/src/core/__tests__/Collapsible.browser.spec.tsx +88 -0
  243. package/src/core/__tests__/PaneRail.browser.spec.tsx +48 -0
  244. package/src/core/__tests__/Stepper.browser.spec.tsx +39 -0
  245. package/src/core/__tests__/primitiveSlots.spec.ts +7 -0
  246. package/src/core/index.ts +15 -0
  247. package/src/form/AutoForm.tsx +32 -0
  248. package/src/form/AutoFormErrorPopover.tsx +27 -6
  249. package/src/form/Control.tsx +22 -0
  250. package/src/form/ControlDate.tsx +3 -0
  251. package/src/form/ControlDateRange.tsx +87 -58
  252. package/src/form/ControlNumber.tsx +2 -0
  253. package/src/form/ControlObject.tsx +20 -1
  254. package/src/form/ControlPassword.tsx +5 -0
  255. package/src/form/ControlSelect.tsx +32 -1
  256. package/src/form/ControlSelectCombobox.tsx +82 -56
  257. package/src/form/ControlUpload.tsx +1 -0
  258. package/src/form/FormField.tsx +23 -1
  259. package/src/form/__tests__/ControlFieldErrors.browser.spec.tsx +253 -0
  260. package/src/form/__tests__/ControlValidateMode.browser.spec.tsx +217 -0
  261. package/src/form/__tests__/ControlVariantErrors.browser.spec.tsx +133 -0
  262. package/src/i18n/fr/uiFr.ts +18 -1
  263. package/src/markdown/css.d.ts +11 -0
  264. package/src/shell/$pageNav.tsx +6 -4
  265. package/src/shell/AppShell.tsx +7 -0
  266. package/src/shell/ButtonSettings.tsx +20 -5
  267. package/src/shell/ButtonSettingsVisionMenuItem.tsx +40 -0
  268. package/src/shell/ButtonVision.tsx +73 -0
  269. package/src/shell/__tests__/ButtonSettings.browser.spec.tsx +42 -2
  270. package/src/shell/__tests__/ButtonVision.browser.spec.tsx +73 -0
  271. package/src/shell/__tests__/visionTokens.spec.ts +104 -0
  272. package/src/shell/index.ts +6 -3
  273. package/src/styles.css +57 -0
  274. package/src/table/DataTable.tsx +52 -4
  275. package/src/table/DataTableColumnPicker.tsx +3 -0
  276. package/src/table/DataTableFilterBar.tsx +18 -191
  277. package/src/table/DataTableHeaderFilter.tsx +156 -0
  278. package/src/table/DataTableHeaderRow.tsx +78 -40
  279. package/src/table/DataTableTabs.tsx +114 -0
  280. package/src/table/__tests__/DataTableHeaderFilter.browser.spec.tsx +174 -0
  281. package/src/table/__tests__/DataTableStaleColumns.browser.spec.tsx +80 -0
  282. package/src/table/__tests__/DataTableTabs.browser.spec.tsx +72 -0
  283. package/src/table/dataTableBaseProps.ts +12 -0
  284. package/src/table/dataTablePersistence.ts +11 -5
  285. package/src/table/dataTableTypes.ts +18 -0
  286. package/src/table/index.ts +9 -2
  287. package/src/table/useDataTableColumns.ts +1 -0
  288. package/src/table/useDataTableFilterModel.tsx +240 -0
package/src/ai/AiChat.tsx CHANGED
@@ -1,77 +1,69 @@
1
- import { useI18n } from "alepha/react/i18n";
2
- import { SquarePen, Sparkles, X } from "lucide-react";
3
- import { type ComponentType, useEffect, useRef } from "react";
1
+ import { useEffect, useState, useSyncExternalStore } from "react";
4
2
 
5
- import { Alert, AlertDescription } from "../core/Alert.tsx";
6
- import { Button } from "../core/Button.tsx";
7
- import {
8
- Drawer,
9
- DrawerClose,
10
- DrawerContent,
11
- DrawerTitle,
12
- } from "../core/Drawer.tsx";
13
- import { Spinner } from "../core/Spinner.tsx";
14
- import {
15
- type MarkdownLinkRenderer,
16
- MarkdownView,
17
- } from "../markdown/MarkdownView.tsx";
18
- import { AiChatComposer } from "./AiChatComposer.tsx";
19
- import {
20
- AiChatConfirmCard,
21
- type AiChatConfirmCardProps,
22
- } from "./AiChatConfirmCard.tsx";
23
- import { AiChatEmpty, type AiChatSuggestion } from "./AiChatEmpty.tsx";
24
- import { AiChatHistory } from "./AiChatHistory.tsx";
25
- import { AiChatMessage, type AiChatToolLabel } from "./AiChatMessage.tsx";
3
+ import { Drawer, DrawerContent, DrawerTitle } from "../core/Drawer.tsx";
4
+ import { AiChatDock } from "./AiChatDock.tsx";
5
+ import { AiChatLauncher } from "./AiChatLauncher.tsx";
6
+ import { AiChatPanel, type AiChatViewProps } from "./AiChatPanel.tsx";
26
7
  import { type UseAiChatOptions, useAiChat } from "./useAiChat.ts";
27
8
 
28
- export interface AiChatProps extends UseAiChatOptions {
9
+ /**
10
+ * Where the conversation sits.
11
+ * - `drawer`: a modal drawer from the right, over a dimmed page.
12
+ * - `dock`: a panel beside the page, which stays readable and usable
13
+ * (see `AiChatDock`), and folds into a pill.
14
+ * - `auto`: the dock from 1024px up, the drawer below, where a page has no
15
+ * width to give.
16
+ */
17
+ export type AiChatMode = "auto" | "dock" | "drawer";
18
+
19
+ export interface AiChatProps extends UseAiChatOptions, AiChatViewProps {
29
20
  open: boolean;
30
21
  onOpenChange: (open: boolean) => void;
31
22
  /**
32
- * The drawer's title. Defaults to "Assistant".
33
- */
34
- title?: string;
35
- /**
36
- * Offer the list of past conversations, in a header menu. Default true.
37
- */
38
- history?: boolean;
39
- /**
40
- * Questions a new conversation offers to start from.
41
- */
42
- suggestions?: AiChatSuggestion[];
43
- /**
44
- * Names each tool step in the user's words ("Searched clients"), running
45
- * and done. Without it a step shows the tool's own name.
46
- */
47
- toolLabel?: AiChatToolLabel;
48
- /**
49
- * A confirmation card per tool name, in place of the generic field list:
50
- * an app shows a booking as a booking. It gets the pending call as the
51
- * server stored it, and the approve and deny callbacks.
52
- */
53
- confirmCards?: Record<string, ComponentType<AiChatConfirmCardProps>>;
54
- /**
55
- * How links in the assistant's replies render (`MarkdownView`'s
56
- * `renderLink`): route the paths the app knows, leave the rest as text.
23
+ * Where the conversation sits. Defaults to `drawer`.
57
24
  */
58
- renderLink?: MarkdownLinkRenderer;
25
+ mode?: AiChatMode;
59
26
  }
60
27
 
28
+ const DOCK_QUERY = "(min-width: 1024px)";
29
+
30
+ const subscribe = (onChange: () => void) => {
31
+ const mql = window.matchMedia?.(DOCK_QUERY);
32
+ mql?.addEventListener("change", onChange);
33
+ return () => mql?.removeEventListener("change", onChange);
34
+ };
35
+
36
+ /**
37
+ * True where `auto` docks. The server snapshot is false, which is also what
38
+ * the hydration render reads, and the chat is closed on the server anyway.
39
+ */
40
+ const useWideScreen = () =>
41
+ useSyncExternalStore(
42
+ subscribe,
43
+ () => window.matchMedia?.(DOCK_QUERY).matches ?? false,
44
+ () => false,
45
+ );
46
+
61
47
  /**
62
- * The assistant in a drawer: a quiet header (history menu, new
63
- * conversation, close), the conversation with its tool steps and a
64
- * confirmation card for every mutation the assistant wants to run, and a
65
- * composer that sends on Enter and stops a running turn. It knows the page
66
- * through `useAiContext()`, and runs `navigate` and `fillForm` for the model.
48
+ * The assistant: the conversation of `AiChatPanel`, in a drawer or a dock.
49
+ * It knows the page through `useAiContext()`, and runs `navigate` and
50
+ * `fillForm` for the model. The conversation lives here, so it survives a
51
+ * close, a minimize and a switch between drawer and dock.
67
52
  *
68
- * Needs `AlephaApiAi` on the server and a `$ai` declared by the app.
53
+ * A docked chat minimizes into a pill (`AiChatLauncher`): it reports itself
54
+ * closed through `onOpenChange(false)`, so the app's own button opens it
55
+ * again, and the pill does too.
56
+ *
57
+ * Needs `AlephaApiAi` on the server and a `$ai` declared by the app. A dock
58
+ * needs an `AiChatDockSlot` in the layout to make room for it (`AppShell`'s
59
+ * `aside`); without one it floats over the page's right edge.
69
60
  *
70
61
  * @example
71
62
  * ```tsx
72
63
  * const [open, setOpen] = useState(false);
73
64
  * <Button onClick={() => setOpen(true)}>Ask</Button>
74
65
  * <AiChat
66
+ * mode="auto"
75
67
  * open={open}
76
68
  * onOpenChange={setOpen}
77
69
  * suggestions={[{ label: "Who still owes today?" }]}
@@ -79,150 +71,69 @@ export interface AiChatProps extends UseAiChatOptions {
79
71
  * ```
80
72
  */
81
73
  export const AiChat = (props: AiChatProps) => {
82
- const { tr } = useI18n();
83
74
  const chat = useAiChat(props);
84
- const thread = useRef<HTMLDivElement>(null);
85
- const busy = chat.loading && !chat.pending;
86
- const empty = chat.items.length === 0 && !chat.streaming && !busy;
75
+ const wide = useWideScreen();
76
+ const [minimized, setMinimized] = useState(false);
77
+ const mode = props.mode ?? "drawer";
78
+ const docked = mode === "dock" || (mode === "auto" && wide);
87
79
 
88
- // Keep the newest line in view as the conversation grows.
80
+ // Opened again, from the pill or from the app's own button: the pill goes.
89
81
  useEffect(() => {
90
- const node = thread.current;
91
- if (node) {
92
- node.scrollTop = node.scrollHeight;
82
+ if (props.open) {
83
+ // oxlint-disable-next-line react/set-state-in-effect -- `open` is the app's state; the pill follows it
84
+ setMinimized(false);
93
85
  }
94
- }, [chat.items.length, chat.streaming, chat.activity, chat.pending]);
86
+ }, [props.open]);
95
87
 
96
- const running = chat.activity
97
- ? (props.toolLabel?.(chat.activity, "running") ??
98
- tr("ai.chat.running", {
99
- default: "Running $1",
100
- args: [chat.activity],
101
- }))
102
- : undefined;
88
+ const close = () => {
89
+ setMinimized(false);
90
+ props.onOpenChange(false);
91
+ };
103
92
 
104
- const Card = chat.pending
105
- ? (props.confirmCards?.[chat.pending.name] ?? AiChatConfirmCard)
106
- : undefined;
93
+ if (docked) {
94
+ if (props.open) {
95
+ return (
96
+ <AiChatDock>
97
+ <AiChatPanel
98
+ {...props}
99
+ chat={chat}
100
+ onClose={close}
101
+ onMinimize={() => {
102
+ setMinimized(true);
103
+ props.onOpenChange(false);
104
+ }}
105
+ />
106
+ </AiChatDock>
107
+ );
108
+ }
109
+ return minimized ? (
110
+ <AiChatLauncher
111
+ chat={chat}
112
+ title={props.title}
113
+ onRestore={() => props.onOpenChange(true)}
114
+ />
115
+ ) : null;
116
+ }
107
117
 
108
118
  return (
109
119
  <Drawer
110
120
  open={props.open}
111
- onOpenChange={(open) => props.onOpenChange(open)}
121
+ onOpenChange={(open) => (open ? props.onOpenChange(true) : close())}
112
122
  swipeDirection="right"
113
123
  >
114
124
  <DrawerContent
115
- data-testid="ai-chat"
116
125
  // From `sm` up the panel floats: a gap from the page's edges, every
117
126
  // corner rounded, a shadow, and no bleed strip past its edge.
118
127
  className="flex h-full w-full flex-col gap-0 p-0 sm:h-[calc(100dvh-1.5rem)] sm:max-w-md sm:[--drawer-inset:0.75rem] sm:after:hidden sm:data-[swipe-direction=right]:rounded-2xl sm:data-[swipe-direction=right]:border sm:data-[swipe-direction=right]:shadow-2xl"
119
128
  >
120
- <div className="border-border flex items-center gap-2 border-b py-2.5 pr-2.5 pl-4">
121
- <Sparkles className="text-primary size-4 shrink-0" />
122
- <DrawerTitle className="flex-1 truncate text-base font-medium">
123
- {props.title ?? tr("ai.chat.title", { default: "Assistant" })}
124
- </DrawerTitle>
125
- {props.history !== false && (
126
- <AiChatHistory
127
- current={chat.conversationId}
128
- disabled={chat.loading}
129
- onOpen={(id) => chat.open(id)}
130
- />
129
+ <AiChatPanel
130
+ {...props}
131
+ chat={chat}
132
+ onClose={close}
133
+ renderTitle={(title, className) => (
134
+ <DrawerTitle className={className}>{title}</DrawerTitle>
131
135
  )}
132
- <Button
133
- size="icon-sm"
134
- variant="minimal"
135
- disabled={chat.loading || empty}
136
- aria-label={tr("ai.chat.new", { default: "New conversation" })}
137
- onClick={() => chat.open(undefined)}
138
- >
139
- <SquarePen className="size-4" />
140
- </Button>
141
- <DrawerClose
142
- render={
143
- <Button
144
- size="icon-sm"
145
- variant="minimal"
146
- aria-label={tr("ai.chat.close", { default: "Close" })}
147
- />
148
- }
149
- >
150
- <X className="size-4" />
151
- </DrawerClose>
152
- </div>
153
- <div
154
- ref={thread}
155
- // `shrink-0` on every line: in a scrolling column a card (overflow
156
- // hidden, so no content minimum) would shrink to its border once
157
- // the thread outgrows the drawer (#Q3174).
158
- className="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-4 py-4 *:shrink-0"
159
- >
160
- {empty ? (
161
- <AiChatEmpty
162
- suggestions={props.suggestions}
163
- disabled={chat.loading}
164
- onPick={(prompt) => chat.send(prompt)}
165
- />
166
- ) : (
167
- <>
168
- {chat.items.map((item) => (
169
- <AiChatMessage
170
- key={item.id}
171
- item={item}
172
- renderLink={props.renderLink}
173
- toolLabel={props.toolLabel}
174
- />
175
- ))}
176
- {chat.streaming && (
177
- <div
178
- data-testid="ai-chat-streaming"
179
- className="mr-4 self-start text-sm leading-relaxed"
180
- >
181
- <MarkdownView
182
- content={chat.streaming}
183
- renderLink={props.renderLink}
184
- />
185
- </div>
186
- )}
187
- {running && (
188
- <div className="text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs">
189
- <Spinner className="size-3.5" />
190
- {running}
191
- </div>
192
- )}
193
- {busy && !running && !chat.streaming && (
194
- <div
195
- className="text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs"
196
- aria-live="polite"
197
- >
198
- <Spinner className="size-3.5" />
199
- {tr("ai.chat.thinking", { default: "Thinking…" })}
200
- </div>
201
- )}
202
- {chat.pending?.kind === "confirm" && Card && (
203
- <Card
204
- pending={chat.pending}
205
- loading={chat.loading}
206
- onApprove={() => chat.approve()}
207
- onDeny={() => chat.deny()}
208
- />
209
- )}
210
- </>
211
- )}
212
- {chat.error && (
213
- <Alert variant="destructive" data-testid="ai-chat-error">
214
- <AlertDescription>{chat.error}</AlertDescription>
215
- </Alert>
216
- )}
217
- </div>
218
- <div className="border-border border-t px-3 pt-3 pb-2.5">
219
- <AiChatComposer
220
- busy={busy}
221
- waiting={chat.pending?.kind === "confirm"}
222
- onSend={(message) => chat.send(message)}
223
- onStop={() => chat.stop()}
224
- />
225
- </div>
136
+ />
226
137
  </DrawerContent>
227
138
  </Drawer>
228
139
  );
@@ -0,0 +1,129 @@
1
+ import { useI18n } from "alepha/react/i18n";
2
+ import {
3
+ type PointerEvent as ReactPointerEvent,
4
+ type ReactNode,
5
+ useCallback,
6
+ useEffect,
7
+ useRef,
8
+ useState,
9
+ } from "react";
10
+ import { createPortal } from "react-dom";
11
+
12
+ import { cn } from "../core/utils.ts";
13
+ import { AI_CHAT_DOCK_SLOT } from "./AiChatDockSlot.tsx";
14
+
15
+ /**
16
+ * The clamp on the dock's width. Narrower than 320px and a confirmation card
17
+ * wraps every field; wider than 640px and the page it sits beside is what
18
+ * suffers.
19
+ */
20
+ export const AI_CHAT_DOCK_MIN = 320;
21
+ export const AI_CHAT_DOCK_MAX = 640;
22
+ export const AI_CHAT_DOCK_DEFAULT = 384;
23
+
24
+ const STORAGE_KEY = "alepha.ui.ai.dockWidth";
25
+
26
+ const clamp = (value: number): number =>
27
+ Math.max(AI_CHAT_DOCK_MIN, Math.min(AI_CHAT_DOCK_MAX, Math.round(value)));
28
+
29
+ export interface AiChatDockProps {
30
+ children: ReactNode;
31
+ className?: string;
32
+ }
33
+
34
+ /**
35
+ * The assistant beside the page, not over it: no backdrop, no focus trap,
36
+ * nothing that closes it on a click elsewhere, so the page stays readable
37
+ * and usable while the conversation goes on, and a link in a reply changes
38
+ * the page next to it. It renders into the layout's `AiChatDockSlot`, which
39
+ * narrows the page to make room, and its left edge drags to resize; the
40
+ * width is remembered in this browser.
41
+ */
42
+ export const AiChatDock = (props: AiChatDockProps) => {
43
+ const { tr } = useI18n();
44
+ const [target, setTarget] = useState<{ node: Element; slot: boolean }>();
45
+ const [width, setWidth] = useState(AI_CHAT_DOCK_DEFAULT);
46
+ const drag = useRef<{ x: number; width: number } | null>(null);
47
+
48
+ useEffect(() => {
49
+ // After the commit, not in an initializer: the server has no document,
50
+ // and the slot is a sibling the same commit mounts.
51
+ const slot = document.querySelector(`[data-slot="${AI_CHAT_DOCK_SLOT}"]`);
52
+ // oxlint-disable-next-line react/set-state-in-effect -- the portal target only exists after the commit, see above
53
+ setTarget(
54
+ slot ? { node: slot, slot: true } : { node: document.body, slot: false },
55
+ );
56
+ try {
57
+ const stored = window.localStorage.getItem(STORAGE_KEY);
58
+ if (stored) setWidth(clamp(Number(stored)));
59
+ } catch {
60
+ // Private mode, or storage denied: the default width is a fine answer.
61
+ }
62
+ }, []);
63
+
64
+ useEffect(() => {
65
+ const onMove = (event: PointerEvent) => {
66
+ if (!drag.current) return;
67
+ // The handle is on the left edge: dragging left widens the dock.
68
+ setWidth(clamp(drag.current.width - (event.clientX - drag.current.x)));
69
+ };
70
+ const onUp = () => {
71
+ if (!drag.current) return;
72
+ drag.current = null;
73
+ document.body.style.removeProperty("cursor");
74
+ try {
75
+ window.localStorage.setItem(STORAGE_KEY, String(width));
76
+ } catch {
77
+ // Losing the preference is not worth an error.
78
+ }
79
+ };
80
+ document.addEventListener("pointermove", onMove);
81
+ document.addEventListener("pointerup", onUp);
82
+ return () => {
83
+ document.removeEventListener("pointermove", onMove);
84
+ document.removeEventListener("pointerup", onUp);
85
+ };
86
+ }, [width]);
87
+
88
+ const startResize = useCallback(
89
+ (event: ReactPointerEvent) => {
90
+ drag.current = { x: event.clientX, width };
91
+ // Keeps the resize cursor while the pointer outruns the strip.
92
+ document.body.style.cursor = "col-resize";
93
+ event.preventDefault();
94
+ },
95
+ [width],
96
+ );
97
+
98
+ if (!target) {
99
+ return null;
100
+ }
101
+
102
+ return createPortal(
103
+ <aside
104
+ data-testid="ai-chat-dock"
105
+ aria-label={tr("ai.chat.title", { default: "Assistant" })}
106
+ style={{ width }}
107
+ className={cn(
108
+ "bg-card text-card-foreground relative flex flex-col overflow-hidden rounded-xl border text-sm shadow-sm",
109
+ target.slot
110
+ ? // In the layout's column: a card the page narrows for, kept in
111
+ // view when the page itself scrolls.
112
+ "sticky top-2 my-2 me-2 h-[calc(100%-1rem)] max-h-[calc(100svh-1rem)]"
113
+ : // No slot: over the page's right edge, still without a backdrop.
114
+ "fixed inset-y-2 end-2 z-40 shadow-2xl",
115
+ props.className,
116
+ )}
117
+ >
118
+ <div
119
+ role="separator"
120
+ aria-orientation="vertical"
121
+ aria-label={tr("ai.chat.resize", { default: "Resize the assistant" })}
122
+ onPointerDown={startResize}
123
+ className="hover:bg-primary/20 absolute inset-y-0 start-0 z-10 w-1.5 cursor-col-resize transition-colors"
124
+ />
125
+ {props.children}
126
+ </aside>,
127
+ target.node,
128
+ );
129
+ };
@@ -0,0 +1,23 @@
1
+ import { cn } from "../core/utils.ts";
2
+
3
+ /**
4
+ * The `data-slot` that marks the column an `AiChatDock` renders into.
5
+ */
6
+ export const AI_CHAT_DOCK_SLOT = "ai-chat-dock";
7
+
8
+ export interface AiChatDockSlotProps {
9
+ className?: string;
10
+ }
11
+
12
+ /**
13
+ * Where a layout makes room for the assistant's dock: a column beside the
14
+ * page, empty and zero-wide until the dock opens. Pass it to `AppShell` as
15
+ * `aside`; any other layout puts it as a flex sibling of its content. Without one, the dock floats over the page's right edge
16
+ * instead, still without a backdrop.
17
+ */
18
+ export const AiChatDockSlot = (props: AiChatDockSlotProps) => (
19
+ <div
20
+ data-slot={AI_CHAT_DOCK_SLOT}
21
+ className={cn("flex min-h-0 shrink-0", props.className)}
22
+ />
23
+ );
@@ -0,0 +1,58 @@
1
+ import { useI18n } from "alepha/react/i18n";
2
+ import { Sparkles } from "lucide-react";
3
+
4
+ import { Badge } from "../core/Badge.tsx";
5
+ import { Spinner } from "../core/Spinner.tsx";
6
+ import { cn } from "../core/utils.ts";
7
+ import type { UseAiChat } from "./useAiChat.ts";
8
+
9
+ export interface AiChatLauncherProps {
10
+ /**
11
+ * The conversation the pill speaks for.
12
+ */
13
+ chat: UseAiChat;
14
+ title?: string;
15
+ onRestore: () => void;
16
+ className?: string;
17
+ }
18
+
19
+ /**
20
+ * A minimized assistant: a pill at the bottom corner that brings the panel
21
+ * back, and still says what the conversation is doing, so folding it away
22
+ * never hides an action waiting for the user's approval.
23
+ */
24
+ export const AiChatLauncher = (props: AiChatLauncherProps) => {
25
+ const { tr } = useI18n();
26
+ const { chat } = props;
27
+ const waiting = chat.pending?.kind === "confirm";
28
+ const busy = chat.loading && !chat.pending;
29
+ const title = props.title ?? tr("ai.chat.title", { default: "Assistant" });
30
+
31
+ return (
32
+ <button
33
+ type="button"
34
+ data-testid="ai-chat-launcher"
35
+ onClick={props.onRestore}
36
+ aria-label={tr("ai.chat.restore", {
37
+ default: "Open $1",
38
+ args: [title],
39
+ })}
40
+ className={cn(
41
+ "bg-card text-card-foreground hover:bg-accent focus-visible:ring-ring/50 fixed end-4 bottom-4 z-40 inline-flex items-center gap-2 rounded-full border py-2 ps-3.5 pe-4 text-sm font-medium shadow-lg transition-colors outline-none focus-visible:ring-3",
42
+ props.className,
43
+ )}
44
+ >
45
+ {busy ? (
46
+ <Spinner className="size-4" />
47
+ ) : (
48
+ <Sparkles className="text-primary size-4" />
49
+ )}
50
+ {title}
51
+ {waiting && (
52
+ <Badge variant="tint" tone="warning" aria-live="polite">
53
+ {tr("ai.chat.awaiting", { default: "Action to approve" })}
54
+ </Badge>
55
+ )}
56
+ </button>
57
+ );
58
+ };
@@ -1,6 +1,7 @@
1
1
  import { useI18n } from "alepha/react/i18n";
2
- import { Ban, Check, X } from "lucide-react";
2
+ import { Ban, Check, Scissors, X } from "lucide-react";
3
3
 
4
+ import { Button } from "../core/Button.tsx";
4
5
  import { cn } from "../core/utils.ts";
5
6
  import {
6
7
  type MarkdownLinkRenderer,
@@ -18,6 +19,12 @@ export interface AiChatMessageProps {
18
19
  * The words a tool step shows: `AiChat`'s `toolLabel`.
19
20
  */
20
21
  toolLabel?: AiChatToolLabel;
22
+ /**
23
+ * Asks the assistant to go on, from the notice under a reply that was cut
24
+ * short. Absent, the notice shows without its button: `AiChatPanel` passes
25
+ * it on the last line only, and never while a turn runs.
26
+ */
27
+ onContinue?: () => void;
21
28
  }
22
29
 
23
30
  /**
@@ -83,7 +90,34 @@ export const AiChatMessage = (props: AiChatMessageProps) => {
83
90
  data-testid="ai-chat-assistant"
84
91
  className="mr-4 self-start text-sm leading-relaxed"
85
92
  >
86
- <MarkdownView content={item.content} renderLink={props.renderLink} />
93
+ {item.content ? (
94
+ <MarkdownView content={item.content} renderLink={props.renderLink} />
95
+ ) : null}
96
+ {item.cut ? (
97
+ <div
98
+ data-testid="ai-chat-cut"
99
+ role="status"
100
+ className="text-warning-text mt-2 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs"
101
+ >
102
+ <Scissors className="size-3.5 shrink-0" />
103
+ <span>
104
+ {tr("ai.chat.cut", {
105
+ default:
106
+ "This answer was cut short: it reached the length limit. Ask a narrower question, or continue.",
107
+ })}
108
+ </span>
109
+ {props.onContinue ? (
110
+ <Button
111
+ type="button"
112
+ variant="outlined"
113
+ size="xs"
114
+ onClick={props.onContinue}
115
+ >
116
+ {tr("ai.chat.continue", { default: "Continue" })}
117
+ </Button>
118
+ ) : null}
119
+ </div>
120
+ ) : null}
87
121
  </div>
88
122
  );
89
123
  };