@alepha/ui 0.36.0 → 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 +7 -1
  45. package/dist/ai/AiChatMessage.d.ts.map +1 -1
  46. package/dist/ai/AiChatMessage.js +27 -7
  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 +17 -0
  56. package/dist/ai/useAiChat.d.ts.map +1 -1
  57. package/dist/ai/useAiChat.js +38 -17
  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 +15 -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 +48 -9
  228. package/src/ai/AiChatPanel.tsx +252 -0
  229. package/src/ai/__tests__/AiChat.browser.spec.tsx +197 -5
  230. package/src/ai/index.ts +8 -4
  231. package/src/ai/useAiChat.ts +80 -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 +19 -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
@@ -50,6 +50,8 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
50
50
  const [error, setError] = useState<string | undefined>();
51
51
  // The id the next request uses, ahead of the render that shows it.
52
52
  const idRef = useRef<string | undefined>(options.conversationId);
53
+ // Calls the user denied, so their result reads as cancelled, not failed.
54
+ const deniedRef = useRef(new Set<string>());
53
55
  const counter = useRef(0);
54
56
 
55
57
  const push = useCallback((item: Omit<AiChatItem, "id">) => {
@@ -58,6 +60,21 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
58
60
  setItems((current) => [...current, { id, ...item }]);
59
61
  }, []);
60
62
 
63
+ /**
64
+ * The page context a turn carries: the route, and the innermost page's
65
+ * name and data. Sent on a chat and on every resume, since the server's
66
+ * `allow` reads it to decide what the assistant is offered.
67
+ */
68
+ const pageContext = useCallback(() => {
69
+ const stack = alepha.store.get(aiContextAtom) ?? [];
70
+ const innermost = stack[stack.length - 1];
71
+ return {
72
+ route: router.pathname,
73
+ page: innermost?.page,
74
+ data: innermost?.data,
75
+ };
76
+ }, [alepha, router]);
77
+
61
78
  /**
62
79
  * Run a client tool the turn paused on, and return its result. A failure
63
80
  * is a result too: the model reads it and recovers.
@@ -115,6 +132,7 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
115
132
  ): Promise<void> => {
116
133
  let stream: AsyncIterable<AiStreamEvent> | undefined = first;
117
134
  let ranTools = false;
135
+ const succeeded: string[] = [];
118
136
  while (stream) {
119
137
  let text = "";
120
138
  let clientCall: AiPendingCallResource | undefined;
@@ -129,12 +147,18 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
129
147
  setActivity(event.name);
130
148
  } else if (event.type === "tool_result") {
131
149
  ranTools = true;
150
+ if (!event.isError && event.name) {
151
+ succeeded.push(event.name);
152
+ }
132
153
  setActivity(undefined);
133
154
  push({
134
155
  role: "tool",
135
156
  content: "",
136
157
  name: event.name,
137
158
  isError: event.isError,
159
+ denied: Boolean(
160
+ event.callId && deniedRef.current.has(event.callId),
161
+ ),
138
162
  });
139
163
  } else if (event.type === "confirm") {
140
164
  setPending({
@@ -153,8 +177,14 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
153
177
  } else if (event.type === "error") {
154
178
  setError(event.message ?? event.name ?? "The assistant failed");
155
179
  }
156
- if (text && (event.type === "tool_call" || event.type === "end")) {
157
- push({ role: "assistant", content: text });
180
+ // The model ran out of output tokens (or of steps): the reply is
181
+ // marked, so it reads as cut short and not as a finished answer.
182
+ const cut = event.type === "end" && event.reason === "length";
183
+ if (
184
+ (text && (event.type === "tool_call" || event.type === "end")) ||
185
+ cut
186
+ ) {
187
+ push({ role: "assistant", content: text, ...(cut ? { cut } : {}) });
158
188
  text = "";
159
189
  setStreaming("");
160
190
  }
@@ -166,6 +196,9 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
166
196
  for (const key of options.invalidates ?? []) {
167
197
  queries.invalidate(key);
168
198
  }
199
+ if (succeeded.length) {
200
+ options.onToolsRan?.(succeeded.splice(0));
201
+ }
169
202
  ranTools = false;
170
203
  }
171
204
  if (clientCall && idRef.current) {
@@ -173,14 +206,26 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
173
206
  stream = await api.resume(
174
207
  {
175
208
  params: { id: idRef.current },
176
- body: { callId: clientCall.callId, result },
209
+ body: {
210
+ callId: clientCall.callId,
211
+ result,
212
+ context: pageContext(),
213
+ },
177
214
  },
178
215
  { request: { signal } },
179
216
  );
180
217
  }
181
218
  }
182
219
  },
183
- [api, push, runClientTool, queries, options.invalidates],
220
+ [
221
+ api,
222
+ push,
223
+ runClientTool,
224
+ queries,
225
+ options.invalidates,
226
+ options.onToolsRan,
227
+ pageContext,
228
+ ],
184
229
  );
185
230
 
186
231
  const send = useAction<[message: string]>(
@@ -188,19 +233,13 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
188
233
  handler: async ({ signal }, message) => {
189
234
  setError(undefined);
190
235
  push({ role: "user", content: message });
191
- const stack = alepha.store.get(aiContextAtom) ?? [];
192
- const innermost = stack[stack.length - 1];
193
236
  const stream = await api.chat(
194
237
  {
195
238
  body: {
196
239
  conversationId: idRef.current,
197
240
  message,
198
241
  assistant: options.assistant,
199
- context: {
200
- route: router.pathname,
201
- page: innermost?.page,
202
- data: innermost?.data,
203
- },
242
+ context: pageContext(),
204
243
  },
205
244
  },
206
245
  { request: { signal } },
@@ -209,7 +248,7 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
209
248
  },
210
249
  onError: (cause) => setError(cause.message),
211
250
  },
212
- [api, alepha, consume, options.assistant, push, router],
251
+ [api, consume, options.assistant, push, pageContext],
213
252
  );
214
253
 
215
254
  const answer = useAction<[decision: "approve" | "deny"]>(
@@ -220,16 +259,22 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
220
259
  }
221
260
  setError(undefined);
222
261
  const callId = pending.callId;
262
+ if (decision === "deny") {
263
+ deniedRef.current.add(callId);
264
+ }
223
265
  setPending(undefined);
224
266
  const stream = await api.resume(
225
- { params: { id: idRef.current }, body: { callId, decision } },
267
+ {
268
+ params: { id: idRef.current },
269
+ body: { callId, decision, context: pageContext() },
270
+ },
226
271
  { request: { signal } },
227
272
  );
228
273
  await consume(stream, signal);
229
274
  },
230
275
  onError: (cause) => setError(cause.message),
231
276
  },
232
- [api, consume, pending],
277
+ [api, consume, pending, pageContext],
233
278
  );
234
279
 
235
280
  const open = useAction<[id?: string]>(
@@ -252,6 +297,10 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
252
297
  content: message.content,
253
298
  name: message.name,
254
299
  isError: message.isError,
300
+ // `alepha/ai`'s AI_CALL_DENIED: a stored denial keeps this text.
301
+ denied:
302
+ message.role === "tool" &&
303
+ message.content === "Denied by the user.",
255
304
  })),
256
305
  );
257
306
  setPending(detail.conversation.pendingCall);
@@ -309,6 +358,12 @@ export interface UseAiChatOptions {
309
358
  * what the assistant may have changed (`[["notes"]]`).
310
359
  */
311
360
  invalidates?: unknown[][];
361
+ /**
362
+ * Called after a stream in which tools ran, with the names of those that
363
+ * succeeded, for what `invalidates` cannot reach: a page whose data its
364
+ * route loaders fill re-runs them (`router.invalidate()`) after a write.
365
+ */
366
+ onToolsRan?: (names: string[]) => void;
312
367
  /**
313
368
  * The app's own client tools, by name, beside `navigate` and `fillForm`.
314
369
  * The result goes back to the model.
@@ -328,6 +383,17 @@ export interface AiChatItem {
328
383
  */
329
384
  name?: string;
330
385
  isError?: boolean;
386
+ /**
387
+ * A `tool` line the user refused on its confirmation card: an error to the
388
+ * model, a cancellation to the user.
389
+ */
390
+ denied?: boolean;
391
+ /**
392
+ * An `assistant` line the model did not finish: the turn ended on its
393
+ * output limit (`reason: "length"`). Known for a reply streamed in this
394
+ * session only; a stored conversation does not keep it.
395
+ */
396
+ cut?: boolean;
331
397
  }
332
398
 
333
399
  /**
@@ -59,11 +59,20 @@ export interface AuthLoginProps {
59
59
  * component (e.g. with light/dark variants or an animation).
60
60
  */
61
61
  logo?: ReactNode;
62
+ /**
63
+ * Where the "Cancel" link under the form leads. Defaults to "/".
64
+ *
65
+ * Pass `false` to hide the link, for an application where every page
66
+ * needs an account: there "/" only leads back to this page. It is
67
+ * intentionally decoupled from the post-auth `?redirect=` target, which is
68
+ * a protected destination the visitor has not reached yet.
69
+ */
70
+ cancelPath?: string | false;
62
71
  }
63
72
 
64
73
  export const AuthLogin = (props: AuthLoginProps) => {
65
74
  const auth = useAuth();
66
- const router = useRouter();
75
+ const router = useRouter<any>();
67
76
  const { tr } = useI18n();
68
77
  const redirect = safeRedirect(router.query.redirect);
69
78
  const error = router.query.error;
@@ -348,9 +357,15 @@ export const AuthLogin = (props: AuthLoginProps) => {
348
357
  )}
349
358
  </CardContent>
350
359
  </Card>
351
- <Button variant="minimal" nativeButton={false} render={<a href="/" />}>
352
- {tr("auth.login.cancel", { default: "Cancel" })}
353
- </Button>
360
+ {props.cancelPath !== false && (
361
+ <Button
362
+ variant="minimal"
363
+ nativeButton={false}
364
+ render={<a href={props.cancelPath ?? "/"} />}
365
+ >
366
+ {tr("auth.login.cancel", { default: "Cancel" })}
367
+ </Button>
368
+ )}
354
369
  </div>
355
370
  );
356
371
 
@@ -66,8 +66,11 @@ export interface AuthRegisterProps {
66
66
  * an unauthenticated registration must land somewhere public (home), not the
67
67
  * protected destination the user was *heading* to — which would only bounce
68
68
  * them back to this page.
69
+ *
70
+ * Pass `false` to hide the link, for an application where every page
71
+ * needs an account.
69
72
  */
70
- cancelPath?: string;
73
+ cancelPath?: string | false;
71
74
  /**
72
75
  * Render the form even though `settings.registrationAllowed` is `false`.
73
76
  *
@@ -108,7 +111,7 @@ export interface AuthRegisterProps {
108
111
  export const AuthRegister = (props: AuthRegisterProps) => {
109
112
  const auth = useAuth();
110
113
  const userCtrl = useClient<UserController>();
111
- const router = useRouter();
114
+ const router = useRouter<any>();
112
115
  const { tr } = useI18n();
113
116
  const redirect = safeRedirect(props.redirect ?? router.query.redirect);
114
117
  // Surface upstream auth errors (e.g. failed OAuth callback redirects with
@@ -492,7 +495,7 @@ export const AuthRegister = (props: AuthRegisterProps) => {
492
495
  </div>
493
496
  </CardContent>
494
497
  </Card>
495
- {!isVerifying && (
498
+ {!isVerifying && props.cancelPath !== false && (
496
499
  <Button
497
500
  variant="minimal"
498
501
  nativeButton={false}
@@ -44,6 +44,14 @@ export interface AuthResetPasswordProps {
44
44
  * component (e.g. with light/dark variants or an animation).
45
45
  */
46
46
  logo?: ReactNode;
47
+ /**
48
+ * Where the "Cancel" link under the form leads. Defaults to the
49
+ * `?redirect=` target of the URL, else "/".
50
+ *
51
+ * Pass `false` to hide the link, for an application where every page
52
+ * needs an account: there the default only leads back to sign-in.
53
+ */
54
+ cancelPath?: string | false;
47
55
  }
48
56
 
49
57
  type Step = "email" | "code" | "password" | "success";
@@ -56,7 +64,7 @@ interface State {
56
64
  }
57
65
 
58
66
  export const AuthResetPassword = (props: AuthResetPasswordProps) => {
59
- const router = useRouter();
67
+ const router = useRouter<any>();
60
68
  const { tr } = useI18n();
61
69
  const userCtrl = useClient<UserController>();
62
70
  const [state, setState] = useState<State>({ step: "email" });
@@ -420,13 +428,15 @@ export const AuthResetPassword = (props: AuthResetPasswordProps) => {
420
428
  )}
421
429
  </CardContent>
422
430
  </Card>
423
- <Button
424
- variant="minimal"
425
- nativeButton={false}
426
- render={<a href={redirect} />}
427
- >
428
- {tr("auth.reset.cancel", { default: "Cancel" })}
429
- </Button>
431
+ {props.cancelPath !== false && (
432
+ <Button
433
+ variant="minimal"
434
+ nativeButton={false}
435
+ render={<a href={props.cancelPath ?? redirect} />}
436
+ >
437
+ {tr("auth.reset.cancel", { default: "Cancel" })}
438
+ </Button>
439
+ )}
430
440
  </div>
431
441
  </div>
432
442
  );
@@ -0,0 +1,129 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import { Alepha } from "alepha";
3
+ import type { RealmConfig } from "alepha/api/users";
4
+ import { AlephaContext } from "alepha/react";
5
+ import { AlephaReactAuth } from "alepha/react/auth";
6
+ import { AlephaReactI18n } from "alepha/react/i18n";
7
+ import { AlephaReactRouter } from "alepha/react/router";
8
+ import { AlephaServerLinks } from "alepha/server/links";
9
+ import { setupJsdomMocks } from "alepha/testing/react";
10
+ import type { ReactNode } from "react";
11
+ import { afterEach, beforeAll, describe, expect, it } from "vitest";
12
+
13
+ import { DialogProvider } from "../../core/useDialog.tsx";
14
+ import { AuthLogin } from "../AuthLogin.tsx";
15
+ import { AuthRegister } from "../AuthRegister.tsx";
16
+ import { AuthResetPassword } from "../AuthResetPassword.tsx";
17
+
18
+ /**
19
+ * The "Cancel" link under the sign-in, registration and password-reset forms.
20
+ *
21
+ * It leads to "/" by default, which is right for an application with public
22
+ * pages. In an application where every page needs an account, "/" sends the
23
+ * visitor straight back to sign-in, so `cancelPath={false}` hides the link and
24
+ * a string points it elsewhere.
25
+ */
26
+ describe("Auth forms - the Cancel link", () => {
27
+ let alepha: Alepha | undefined;
28
+
29
+ beforeAll(() => {
30
+ setupJsdomMocks();
31
+ });
32
+
33
+ afterEach(async () => {
34
+ await alepha?.stop();
35
+ alepha = undefined;
36
+ });
37
+
38
+ const realmConfig = {
39
+ realmName: "default",
40
+ authenticationMethods: [{ type: "CREDENTIALS", name: "credentials" }],
41
+ settings: {
42
+ username: "none",
43
+ email: "required",
44
+ phoneNumber: "none",
45
+ registrationAllowed: true,
46
+ resetPasswordAllowed: true,
47
+ },
48
+ } as unknown as RealmConfig;
49
+
50
+ const mount = async (node: ReactNode) => {
51
+ alepha = Alepha.create()
52
+ .with(AlephaReactRouter)
53
+ .with(AlephaReactI18n)
54
+ .with(AlephaReactAuth)
55
+ .with(AlephaServerLinks);
56
+ await alepha.start();
57
+ return render(
58
+ <AlephaContext.Provider value={alepha}>
59
+ <DialogProvider>{node}</DialogProvider>
60
+ </AlephaContext.Provider>,
61
+ );
62
+ };
63
+
64
+ /**
65
+ * The kit's `Button` rendered as an anchor keeps `role="button"`.
66
+ */
67
+ const cancelLink = () => screen.queryByRole("button", { name: "Cancel" });
68
+
69
+ describe("AuthLogin", () => {
70
+ it("should lead to / by default", async () => {
71
+ await mount(<AuthLogin realmConfig={realmConfig} />);
72
+
73
+ expect(cancelLink()?.getAttribute("href")).toBe("/");
74
+ });
75
+
76
+ it("should lead to the given cancelPath", async () => {
77
+ await mount(<AuthLogin realmConfig={realmConfig} cancelPath="/home" />);
78
+
79
+ expect(cancelLink()?.getAttribute("href")).toBe("/home");
80
+ });
81
+
82
+ it("should hide the link when cancelPath is false", async () => {
83
+ await mount(<AuthLogin realmConfig={realmConfig} cancelPath={false} />);
84
+
85
+ expect(screen.queryByText("Sign up")).toBeTruthy();
86
+ expect(cancelLink()).toBeNull();
87
+ });
88
+ });
89
+
90
+ describe("AuthRegister", () => {
91
+ it("should lead to / by default", async () => {
92
+ await mount(<AuthRegister realmConfig={realmConfig} />);
93
+
94
+ expect(cancelLink()?.getAttribute("href")).toBe("/");
95
+ });
96
+
97
+ it("should hide the link when cancelPath is false", async () => {
98
+ await mount(
99
+ <AuthRegister realmConfig={realmConfig} cancelPath={false} />,
100
+ );
101
+
102
+ expect(cancelLink()).toBeNull();
103
+ });
104
+ });
105
+
106
+ describe("AuthResetPassword", () => {
107
+ it("should lead to / by default", async () => {
108
+ await mount(<AuthResetPassword realmConfig={realmConfig} />);
109
+
110
+ expect(cancelLink()?.getAttribute("href")).toBe("/");
111
+ });
112
+
113
+ it("should lead to the given cancelPath", async () => {
114
+ await mount(
115
+ <AuthResetPassword realmConfig={realmConfig} cancelPath="/home" />,
116
+ );
117
+
118
+ expect(cancelLink()?.getAttribute("href")).toBe("/home");
119
+ });
120
+
121
+ it("should hide the link when cancelPath is false", async () => {
122
+ await mount(
123
+ <AuthResetPassword realmConfig={realmConfig} cancelPath={false} />,
124
+ );
125
+
126
+ expect(cancelLink()).toBeNull();
127
+ });
128
+ });
129
+ });
@@ -47,6 +47,10 @@ const badgeVariants = cva(
47
47
  * would fight them: before this was enforced, a `default` badge given a
48
48
  * tone lost its primary fill to the tone's wash, since tailwind-merge
49
49
  * keeps the last `bg-*`.
50
+ *
51
+ * success, warning and danger paint from the signal tokens, not fixed
52
+ * Tailwind hues, so colour-blind mode (`:root.cvd`) repaints them.
53
+ * info stays blue: blue is already safe under every common deficiency.
50
54
  */
51
55
  tone: {
52
56
  neutral: "",
@@ -70,17 +74,17 @@ const badgeVariants = cva(
70
74
  {
71
75
  variant: "tint",
72
76
  tone: "success",
73
- class: "border-emerald-500/40 bg-emerald-500/15",
77
+ class: "border-success/40 bg-success/15",
74
78
  },
75
79
  {
76
80
  variant: "tint",
77
81
  tone: "warning",
78
- class: "border-amber-500/40 bg-amber-500/15",
82
+ class: "border-warning/40 bg-warning/15",
79
83
  },
80
84
  {
81
85
  variant: "tint",
82
86
  tone: "danger",
83
- class: "border-red-500/40 bg-red-500/15",
87
+ class: "border-danger/40 bg-danger/15",
84
88
  },
85
89
  ],
86
90
  defaultVariants: {
@@ -0,0 +1,95 @@
1
+ import { Collapsible as CollapsiblePrimitive } from "@base-ui/react/collapsible";
2
+ import { ChevronDownIcon } from "lucide-react";
3
+
4
+ import { cn } from "./utils.ts";
5
+
6
+ export type CollapsibleProps = CollapsiblePrimitive.Root.Props;
7
+
8
+ /**
9
+ * A disclosure: a trigger that opens and closes a panel, its height
10
+ * animated. Uncontrolled with `defaultOpen`, controlled with `open` and
11
+ * `onOpenChange`.
12
+ *
13
+ * ```tsx
14
+ * <Collapsible>
15
+ * <CollapsibleTrigger chevron>Advanced options</CollapsibleTrigger>
16
+ * <CollapsiblePanel>...</CollapsiblePanel>
17
+ * </Collapsible>
18
+ * ```
19
+ *
20
+ * The root and the panel carry `data-open` or `data-closed`, and the trigger
21
+ * `data-panel-open` while the panel is open, for the caller's own styles.
22
+ */
23
+ const Collapsible = (props: CollapsibleProps) => {
24
+ return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />;
25
+ };
26
+
27
+ export interface CollapsibleTriggerProps
28
+ extends CollapsiblePrimitive.Trigger.Props {
29
+ /**
30
+ * Draw a chevron after the children, pointing down while closed and up
31
+ * while open. Defaults to `false`.
32
+ */
33
+ chevron?: boolean;
34
+ }
35
+
36
+ /**
37
+ * The button that opens and closes the panel. It carries `aria-expanded` and
38
+ * `aria-controls`. Its own styles are minimal (a row of its children, a focus
39
+ * ring): pass `render={<Button variant="ghost" />}` for a button look.
40
+ */
41
+ const CollapsibleTrigger = (props: CollapsibleTriggerProps) => {
42
+ const { className, chevron = false, children, ...rest } = props;
43
+ return (
44
+ <CollapsiblePrimitive.Trigger
45
+ data-slot="collapsible-trigger"
46
+ className={cn(
47
+ "group/collapsible-trigger focus-visible:ring-ring/50 inline-flex items-center gap-1.5 rounded-md text-sm font-medium outline-none focus-visible:ring-3 disabled:pointer-events-none disabled:opacity-50",
48
+ className,
49
+ )}
50
+ {...rest}
51
+ >
52
+ {children}
53
+ {chevron && (
54
+ <ChevronDownIcon
55
+ aria-hidden
56
+ data-slot="collapsible-chevron"
57
+ className="text-muted-foreground size-4 shrink-0 transition-transform duration-200 group-data-[panel-open]/collapsible-trigger:rotate-180 motion-reduce:transition-none"
58
+ />
59
+ )}
60
+ </CollapsiblePrimitive.Trigger>
61
+ );
62
+ };
63
+
64
+ export type CollapsiblePanelProps = CollapsiblePrimitive.Panel.Props;
65
+
66
+ /**
67
+ * The panel the trigger opens. Its height runs from 0 to its content's
68
+ * through `--collapsible-panel-height`, which Base UI measures, and the
69
+ * transition is dropped under `prefers-reduced-motion`.
70
+ *
71
+ * Closed, it is not rendered, so nothing in it can take focus; on the server
72
+ * it renders open or not at all, per `defaultOpen`, and opens at its natural
73
+ * height, with no animation on the first paint. `keepMounted` keeps it in the
74
+ * DOM while closed (hidden), and `hiddenUntilFound` lets the browser's page
75
+ * search find and open it.
76
+ *
77
+ * It clips its content while it moves (`overflow-hidden`): give the content
78
+ * its own padding rather than the panel, so the height runs to the padding's
79
+ * edge too.
80
+ */
81
+ const CollapsiblePanel = (props: CollapsiblePanelProps) => {
82
+ const { className, ...rest } = props;
83
+ return (
84
+ <CollapsiblePrimitive.Panel
85
+ data-slot="collapsible-panel"
86
+ className={cn(
87
+ "h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-200 ease-out data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none",
88
+ className,
89
+ )}
90
+ {...rest}
91
+ />
92
+ );
93
+ };
94
+
95
+ export { Collapsible, CollapsiblePanel, CollapsibleTrigger };
@@ -19,10 +19,16 @@ const ComboboxValue = (props: ComboboxValueProps) => {
19
19
  return <ComboboxPrimitive.Value data-slot="combobox-value" {...props} />;
20
20
  };
21
21
 
22
- export type ComboboxTriggerProps = ComboboxPrimitive.Trigger.Props;
22
+ export type ComboboxTriggerProps = ComboboxPrimitive.Trigger.Props & {
23
+ /**
24
+ * Draw the trailing caret. Defaults to true; off for a trigger that is not
25
+ * a field, such as a table header's funnel button.
26
+ */
27
+ chevron?: boolean;
28
+ };
23
29
 
24
30
  const ComboboxTrigger = (props: ComboboxTriggerProps) => {
25
- const { className, children, ...rest } = props;
31
+ const { className, children, chevron = true, ...rest } = props;
26
32
  return (
27
33
  <ComboboxPrimitive.Trigger
28
34
  data-slot="combobox-trigger"
@@ -30,7 +36,9 @@ const ComboboxTrigger = (props: ComboboxTriggerProps) => {
30
36
  {...rest}
31
37
  >
32
38
  {children}
33
- <ChevronDownIcon className="text-muted-foreground pointer-events-none size-4" />
39
+ {chevron && (
40
+ <ChevronDownIcon className="text-muted-foreground pointer-events-none size-4" />
41
+ )}
34
42
  </ComboboxPrimitive.Trigger>
35
43
  );
36
44
  };