@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.
- package/dist/account/$pageAccount.d.ts +1 -1
- package/dist/account/$pageAccount.d.ts.map +1 -1
- package/dist/account/$pageAccount.js.map +1 -1
- package/dist/account/AccountDisplay.d.ts +13 -0
- package/dist/account/AccountDisplay.d.ts.map +1 -0
- package/dist/account/AccountDisplay.js +48 -0
- package/dist/account/AccountDisplay.js.map +1 -0
- package/dist/account/AccountProfile.d.ts.map +1 -1
- package/dist/account/AccountProfile.js +14 -10
- package/dist/account/AccountProfile.js.map +1 -1
- package/dist/account/AccountRouter.d.ts +6 -6
- package/dist/account/AccountRouter.d.ts.map +1 -1
- package/dist/account/index.d.ts +5 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +2 -1
- package/dist/admin/$pageAdmin.d.ts +1 -1
- package/dist/admin/$pageAdmin.d.ts.map +1 -1
- package/dist/admin/$pageAdmin.js.map +1 -1
- package/dist/admin/AdminAudits.js.map +1 -1
- package/dist/admin/AdminJobDetail.js.map +1 -1
- package/dist/admin/AdminJobs.js.map +1 -1
- package/dist/admin/AdminNotifications.js.map +1 -1
- package/dist/admin/AdminRouter.d.ts +14 -14
- package/dist/admin/AdminRouter.d.ts.map +1 -1
- package/dist/admin/AdminUserDetail.js.map +1 -1
- package/dist/admin/AdminUsers.js.map +1 -1
- package/dist/admin/ParameterHistoryItem.js.map +1 -1
- package/dist/ai/AiChat.d.ts +26 -39
- package/dist/ai/AiChat.d.ts.map +1 -1
- package/dist/ai/AiChat.js +65 -123
- package/dist/ai/AiChat.js.map +1 -1
- package/dist/ai/AiChatDock.d.ts +23 -0
- package/dist/ai/AiChatDock.d.ts.map +1 -0
- package/dist/ai/AiChatDock.js +90 -0
- package/dist/ai/AiChatDock.js.map +1 -0
- package/dist/ai/AiChatDockSlot.d.ts +15 -0
- package/dist/ai/AiChatDockSlot.d.ts.map +1 -0
- package/dist/ai/AiChatDockSlot.js +20 -0
- package/dist/ai/AiChatDockSlot.js.map +1 -0
- package/dist/ai/AiChatLauncher.d.ts +17 -0
- package/dist/ai/AiChatLauncher.d.ts.map +1 -0
- package/dist/ai/AiChatLauncher.js +42 -0
- package/dist/ai/AiChatLauncher.js.map +1 -0
- package/dist/ai/AiChatMessage.d.ts +7 -1
- package/dist/ai/AiChatMessage.d.ts.map +1 -1
- package/dist/ai/AiChatMessage.js +27 -7
- package/dist/ai/AiChatMessage.js.map +1 -1
- package/dist/ai/AiChatPanel.d.ts +71 -0
- package/dist/ai/AiChatPanel.d.ts.map +1 -0
- package/dist/ai/AiChatPanel.js +143 -0
- package/dist/ai/AiChatPanel.js.map +1 -0
- package/dist/ai/index.d.ts +8 -4
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -1
- package/dist/ai/useAiChat.d.ts +17 -0
- package/dist/ai/useAiChat.d.ts.map +1 -1
- package/dist/ai/useAiChat.js +38 -17
- package/dist/ai/useAiChat.js.map +1 -1
- package/dist/auth/AuthLogin.d.ts +9 -0
- package/dist/auth/AuthLogin.d.ts.map +1 -1
- package/dist/auth/AuthLogin.js +2 -2
- package/dist/auth/AuthLogin.js.map +1 -1
- package/dist/auth/AuthRegister.d.ts +4 -1
- package/dist/auth/AuthRegister.d.ts.map +1 -1
- package/dist/auth/AuthRegister.js +1 -1
- package/dist/auth/AuthRegister.js.map +1 -1
- package/dist/auth/AuthResetPassword.d.ts +8 -0
- package/dist/auth/AuthResetPassword.d.ts.map +1 -1
- package/dist/auth/AuthResetPassword.js +2 -2
- package/dist/auth/AuthResetPassword.js.map +1 -1
- package/dist/auth/AuthRouter.d.ts +4 -4
- package/dist/auth/AuthRouter.d.ts.map +1 -1
- package/dist/core/Badge.d.ts.map +1 -1
- package/dist/core/Badge.js +7 -3
- package/dist/core/Badge.js.map +1 -1
- package/dist/core/Collapsible.d.ts +50 -0
- package/dist/core/Collapsible.d.ts.map +1 -0
- package/dist/core/Collapsible.js +70 -0
- package/dist/core/Collapsible.js.map +1 -0
- package/dist/core/Combobox.d.ts +7 -1
- package/dist/core/Combobox.d.ts.map +1 -1
- package/dist/core/Combobox.js +2 -2
- package/dist/core/Combobox.js.map +1 -1
- package/dist/core/PaneRail.d.ts +24 -7
- package/dist/core/PaneRail.d.ts.map +1 -1
- package/dist/core/PaneRail.js +24 -19
- package/dist/core/PaneRail.js.map +1 -1
- package/dist/core/Stepper.d.ts +36 -0
- package/dist/core/Stepper.d.ts.map +1 -0
- package/dist/core/Stepper.js +54 -0
- package/dist/core/Stepper.js.map +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -1
- package/dist/core/useToast.js +13 -13
- package/dist/core/useToast.js.map +1 -1
- package/dist/form/AutoForm.d.ts.map +1 -1
- package/dist/form/AutoForm.js +29 -0
- package/dist/form/AutoForm.js.map +1 -1
- package/dist/form/AutoFormErrorPopover.js +13 -3
- package/dist/form/AutoFormErrorPopover.js.map +1 -1
- package/dist/form/Control.d.ts +14 -1
- package/dist/form/Control.d.ts.map +1 -1
- package/dist/form/Control.js +12 -2
- package/dist/form/Control.js.map +1 -1
- package/dist/form/ControlDate.d.ts.map +1 -1
- package/dist/form/ControlDate.js +3 -0
- package/dist/form/ControlDate.js.map +1 -1
- package/dist/form/ControlDateRange.d.ts +12 -1
- package/dist/form/ControlDateRange.d.ts.map +1 -1
- package/dist/form/ControlDateRange.js +11 -1
- package/dist/form/ControlDateRange.js.map +1 -1
- package/dist/form/ControlNumber.d.ts.map +1 -1
- package/dist/form/ControlNumber.js +2 -0
- package/dist/form/ControlNumber.js.map +1 -1
- package/dist/form/ControlObject.d.ts.map +1 -1
- package/dist/form/ControlObject.js +15 -1
- package/dist/form/ControlObject.js.map +1 -1
- package/dist/form/ControlPassword.d.ts +4 -0
- package/dist/form/ControlPassword.d.ts.map +1 -1
- package/dist/form/ControlPassword.js +1 -0
- package/dist/form/ControlPassword.js.map +1 -1
- package/dist/form/ControlSelect.d.ts +23 -1
- package/dist/form/ControlSelect.d.ts.map +1 -1
- package/dist/form/ControlSelect.js +5 -0
- package/dist/form/ControlSelect.js.map +1 -1
- package/dist/form/ControlSelectCombobox.d.ts +11 -1
- package/dist/form/ControlSelectCombobox.d.ts.map +1 -1
- package/dist/form/ControlSelectCombobox.js +9 -1
- package/dist/form/ControlSelectCombobox.js.map +1 -1
- package/dist/form/ControlUpload.d.ts.map +1 -1
- package/dist/form/ControlUpload.js +1 -0
- package/dist/form/ControlUpload.js.map +1 -1
- package/dist/form/FormField.d.ts +5 -0
- package/dist/form/FormField.d.ts.map +1 -1
- package/dist/form/FormField.js +7 -0
- package/dist/form/FormField.js.map +1 -1
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +15 -0
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/shell/$pageNav.d.ts +2 -2
- package/dist/shell/$pageNav.d.ts.map +1 -1
- package/dist/shell/$pageNav.js.map +1 -1
- package/dist/shell/AppShell.d.ts +6 -0
- package/dist/shell/AppShell.d.ts.map +1 -1
- package/dist/shell/AppShell.js +31 -27
- package/dist/shell/AppShell.js.map +1 -1
- package/dist/shell/ButtonSettings.d.ts +6 -2
- package/dist/shell/ButtonSettings.d.ts.map +1 -1
- package/dist/shell/ButtonSettings.js +17 -3
- package/dist/shell/ButtonSettings.js.map +1 -1
- package/dist/shell/ButtonSettingsVisionMenuItem.d.ts +16 -0
- package/dist/shell/ButtonSettingsVisionMenuItem.d.ts.map +1 -0
- package/dist/shell/ButtonSettingsVisionMenuItem.js +24 -0
- package/dist/shell/ButtonSettingsVisionMenuItem.js.map +1 -0
- package/dist/shell/ButtonVision.d.ts +28 -0
- package/dist/shell/ButtonVision.d.ts.map +1 -0
- package/dist/shell/ButtonVision.js +46 -0
- package/dist/shell/ButtonVision.js.map +1 -0
- package/dist/shell/index.d.ts +6 -3
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +2 -1
- package/dist/styles.css +57 -0
- package/dist/table/DataTable.d.ts.map +1 -1
- package/dist/table/DataTable.js +29 -4
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableColumnPicker.d.ts.map +1 -1
- package/dist/table/DataTableColumnPicker.js +1 -0
- package/dist/table/DataTableColumnPicker.js.map +1 -1
- package/dist/table/DataTableFilterBar.d.ts +1 -1
- package/dist/table/DataTableFilterBar.d.ts.map +1 -1
- package/dist/table/DataTableFilterBar.js +5 -108
- package/dist/table/DataTableFilterBar.js.map +1 -1
- package/dist/table/DataTableHeaderFilter.d.ts +51 -0
- package/dist/table/DataTableHeaderFilter.d.ts.map +1 -0
- package/dist/table/DataTableHeaderFilter.js +113 -0
- package/dist/table/DataTableHeaderFilter.js.map +1 -0
- package/dist/table/DataTableHeaderRow.d.ts +7 -0
- package/dist/table/DataTableHeaderRow.d.ts.map +1 -1
- package/dist/table/DataTableHeaderRow.js +92 -74
- package/dist/table/DataTableHeaderRow.js.map +1 -1
- package/dist/table/DataTableTabs.d.ts +42 -0
- package/dist/table/DataTableTabs.d.ts.map +1 -0
- package/dist/table/DataTableTabs.js +55 -0
- package/dist/table/DataTableTabs.js.map +1 -0
- package/dist/table/dataTableBaseProps.d.ts +12 -0
- package/dist/table/dataTableBaseProps.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.js +4 -2
- package/dist/table/dataTablePersistence.js.map +1 -1
- package/dist/table/dataTableTypes.d.ts +18 -0
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/index.d.ts +5 -2
- package/dist/table/index.d.ts.map +1 -1
- package/dist/table/index.js +2 -1
- package/dist/table/useDataTableColumns.d.ts.map +1 -1
- package/dist/table/useDataTableColumns.js +1 -0
- package/dist/table/useDataTableColumns.js.map +1 -1
- package/dist/table/useDataTableFilterModel.d.ts +110 -0
- package/dist/table/useDataTableFilterModel.d.ts.map +1 -0
- package/dist/table/useDataTableFilterModel.js +154 -0
- package/dist/table/useDataTableFilterModel.js.map +1 -0
- package/docs/packages-alepha-ui-account.md +4 -0
- package/docs/packages-alepha-ui-ai.md +5 -5
- package/docs/packages-alepha-ui-shell.md +4 -3
- package/docs/packages-alepha-ui-table.md +4 -2
- package/package.json +8 -8
- package/src/account/$pageAccount.tsx +5 -4
- package/src/account/AccountDisplay.tsx +58 -0
- package/src/account/AccountProfile.tsx +30 -42
- package/src/account/__tests__/AccountProfile.browser.spec.tsx +141 -0
- package/src/account/__tests__/AccountRecoveryCodes.browser.spec.tsx +1 -1
- package/src/account/index.ts +5 -0
- package/src/admin/$pageAdmin.tsx +5 -4
- package/src/admin/AdminAudits.tsx +1 -1
- package/src/admin/AdminJobDetail.tsx +1 -1
- package/src/admin/AdminJobs.tsx +1 -1
- package/src/admin/AdminNotifications.tsx +1 -1
- package/src/admin/AdminUserDetail.tsx +1 -1
- package/src/admin/AdminUsers.tsx +1 -1
- package/src/admin/ParameterHistoryItem.tsx +1 -1
- package/src/admin/__tests__/AdminFilesUsageCard.browser.spec.tsx +17 -9
- package/src/ai/AiChat.tsx +94 -183
- package/src/ai/AiChatDock.tsx +129 -0
- package/src/ai/AiChatDockSlot.tsx +23 -0
- package/src/ai/AiChatLauncher.tsx +58 -0
- package/src/ai/AiChatMessage.tsx +48 -9
- package/src/ai/AiChatPanel.tsx +252 -0
- package/src/ai/__tests__/AiChat.browser.spec.tsx +197 -5
- package/src/ai/index.ts +8 -4
- package/src/ai/useAiChat.ts +80 -14
- package/src/auth/AuthLogin.tsx +19 -4
- package/src/auth/AuthRegister.tsx +6 -3
- package/src/auth/AuthResetPassword.tsx +18 -8
- package/src/auth/__tests__/AuthCancel.browser.spec.tsx +129 -0
- package/src/core/Badge.tsx +7 -3
- package/src/core/Collapsible.tsx +95 -0
- package/src/core/Combobox.tsx +11 -3
- package/src/core/PaneRail.tsx +36 -20
- package/src/core/Stepper.tsx +118 -0
- package/src/core/__tests__/Badge.browser.spec.tsx +5 -5
- package/src/core/__tests__/Collapsible.browser.spec.tsx +88 -0
- package/src/core/__tests__/PaneRail.browser.spec.tsx +48 -0
- package/src/core/__tests__/Stepper.browser.spec.tsx +39 -0
- package/src/core/__tests__/primitiveSlots.spec.ts +7 -0
- package/src/core/index.ts +15 -0
- package/src/form/AutoForm.tsx +32 -0
- package/src/form/AutoFormErrorPopover.tsx +27 -6
- package/src/form/Control.tsx +22 -0
- package/src/form/ControlDate.tsx +3 -0
- package/src/form/ControlDateRange.tsx +87 -58
- package/src/form/ControlNumber.tsx +2 -0
- package/src/form/ControlObject.tsx +20 -1
- package/src/form/ControlPassword.tsx +5 -0
- package/src/form/ControlSelect.tsx +32 -1
- package/src/form/ControlSelectCombobox.tsx +82 -56
- package/src/form/ControlUpload.tsx +1 -0
- package/src/form/FormField.tsx +23 -1
- package/src/form/__tests__/ControlFieldErrors.browser.spec.tsx +253 -0
- package/src/form/__tests__/ControlValidateMode.browser.spec.tsx +217 -0
- package/src/form/__tests__/ControlVariantErrors.browser.spec.tsx +133 -0
- package/src/i18n/fr/uiFr.ts +19 -1
- package/src/markdown/css.d.ts +11 -0
- package/src/shell/$pageNav.tsx +6 -4
- package/src/shell/AppShell.tsx +7 -0
- package/src/shell/ButtonSettings.tsx +20 -5
- package/src/shell/ButtonSettingsVisionMenuItem.tsx +40 -0
- package/src/shell/ButtonVision.tsx +73 -0
- package/src/shell/__tests__/ButtonSettings.browser.spec.tsx +42 -2
- package/src/shell/__tests__/ButtonVision.browser.spec.tsx +73 -0
- package/src/shell/__tests__/visionTokens.spec.ts +104 -0
- package/src/shell/index.ts +6 -3
- package/src/styles.css +57 -0
- package/src/table/DataTable.tsx +52 -4
- package/src/table/DataTableColumnPicker.tsx +3 -0
- package/src/table/DataTableFilterBar.tsx +18 -191
- package/src/table/DataTableHeaderFilter.tsx +156 -0
- package/src/table/DataTableHeaderRow.tsx +78 -40
- package/src/table/DataTableTabs.tsx +114 -0
- package/src/table/__tests__/DataTableHeaderFilter.browser.spec.tsx +174 -0
- package/src/table/__tests__/DataTableStaleColumns.browser.spec.tsx +80 -0
- package/src/table/__tests__/DataTableTabs.browser.spec.tsx +72 -0
- package/src/table/dataTableBaseProps.ts +12 -0
- package/src/table/dataTablePersistence.ts +11 -5
- package/src/table/dataTableTypes.ts +18 -0
- package/src/table/index.ts +9 -2
- package/src/table/useDataTableColumns.ts +1 -0
- package/src/table/useDataTableFilterModel.tsx +240 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { useI18n } from "alepha/react/i18n";
|
|
2
|
+
import { Minus, SquarePen, Sparkles, X } from "lucide-react";
|
|
3
|
+
import { type ComponentType, type ReactNode, useEffect, useRef } from "react";
|
|
4
|
+
|
|
5
|
+
import { Alert, AlertDescription } from "../core/Alert.tsx";
|
|
6
|
+
import { Button } from "../core/Button.tsx";
|
|
7
|
+
import { Spinner } from "../core/Spinner.tsx";
|
|
8
|
+
import {
|
|
9
|
+
type MarkdownLinkRenderer,
|
|
10
|
+
MarkdownView,
|
|
11
|
+
} from "../markdown/MarkdownView.tsx";
|
|
12
|
+
import { AiChatComposer } from "./AiChatComposer.tsx";
|
|
13
|
+
import {
|
|
14
|
+
AiChatConfirmCard,
|
|
15
|
+
type AiChatConfirmCardProps,
|
|
16
|
+
} from "./AiChatConfirmCard.tsx";
|
|
17
|
+
import { AiChatEmpty, type AiChatSuggestion } from "./AiChatEmpty.tsx";
|
|
18
|
+
import { AiChatHistory } from "./AiChatHistory.tsx";
|
|
19
|
+
import { AiChatMessage, type AiChatToolLabel } from "./AiChatMessage.tsx";
|
|
20
|
+
import type { UseAiChat } from "./useAiChat.ts";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* What the conversation looks like, whatever holds it: the props `AiChat`
|
|
24
|
+
* passes through to its panel.
|
|
25
|
+
*/
|
|
26
|
+
export interface AiChatViewProps {
|
|
27
|
+
/**
|
|
28
|
+
* The panel's title. Defaults to "Assistant".
|
|
29
|
+
*/
|
|
30
|
+
title?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The app's own controls in the panel's header, before the history menu:
|
|
33
|
+
* a link to the assistant's help page, say.
|
|
34
|
+
*/
|
|
35
|
+
headerActions?: ReactNode;
|
|
36
|
+
/**
|
|
37
|
+
* Offer the list of past conversations, in a header menu. Default true.
|
|
38
|
+
*/
|
|
39
|
+
history?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Questions a new conversation offers to start from.
|
|
42
|
+
*/
|
|
43
|
+
suggestions?: AiChatSuggestion[];
|
|
44
|
+
/**
|
|
45
|
+
* Names each tool step in the user's words ("Searched clients"), running
|
|
46
|
+
* and done. Without it a step shows the tool's own name.
|
|
47
|
+
*/
|
|
48
|
+
toolLabel?: AiChatToolLabel;
|
|
49
|
+
/**
|
|
50
|
+
* A confirmation card per tool name, in place of the generic field list:
|
|
51
|
+
* an app shows a booking as a booking. It gets the pending call as the
|
|
52
|
+
* server stored it, and the approve and deny callbacks.
|
|
53
|
+
*/
|
|
54
|
+
confirmCards?: Record<string, ComponentType<AiChatConfirmCardProps>>;
|
|
55
|
+
/**
|
|
56
|
+
* How links in the assistant's replies render (`MarkdownView`'s
|
|
57
|
+
* `renderLink`): route the paths the app knows, leave the rest as text.
|
|
58
|
+
*/
|
|
59
|
+
renderLink?: MarkdownLinkRenderer;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface AiChatPanelProps extends AiChatViewProps {
|
|
63
|
+
/**
|
|
64
|
+
* The conversation to show, from `useAiChat()`.
|
|
65
|
+
*/
|
|
66
|
+
chat: UseAiChat;
|
|
67
|
+
onClose: () => void;
|
|
68
|
+
/**
|
|
69
|
+
* Fold the panel away without ending the conversation. Without it the
|
|
70
|
+
* header has no minimize button.
|
|
71
|
+
*/
|
|
72
|
+
onMinimize?: () => void;
|
|
73
|
+
/**
|
|
74
|
+
* Renders the title, so a shell can give it its own element (a drawer
|
|
75
|
+
* names its dialog with it). Defaults to a heading.
|
|
76
|
+
*/
|
|
77
|
+
renderTitle?: (title: string, className: string) => ReactNode;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The conversation itself, with no container: a quiet header (history menu,
|
|
82
|
+
* new conversation, minimize, close), the thread with its tool steps and a
|
|
83
|
+
* confirmation card for every mutation the assistant wants to run, and the
|
|
84
|
+
* composer. `AiChat` puts it in a drawer or in a dock; an app with its own
|
|
85
|
+
* container renders it there, with the `useAiChat()` it owns.
|
|
86
|
+
*/
|
|
87
|
+
export const AiChatPanel = (props: AiChatPanelProps) => {
|
|
88
|
+
const { tr } = useI18n();
|
|
89
|
+
const { chat } = props;
|
|
90
|
+
const thread = useRef<HTMLDivElement>(null);
|
|
91
|
+
const busy = chat.loading && !chat.pending;
|
|
92
|
+
const empty = chat.items.length === 0 && !chat.streaming && !busy;
|
|
93
|
+
|
|
94
|
+
// Keep the newest line in view as the conversation grows.
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
const node = thread.current;
|
|
97
|
+
if (node) {
|
|
98
|
+
node.scrollTop = node.scrollHeight;
|
|
99
|
+
}
|
|
100
|
+
}, [chat.items.length, chat.streaming, chat.activity, chat.pending]);
|
|
101
|
+
|
|
102
|
+
const running = chat.activity
|
|
103
|
+
? (props.toolLabel?.(chat.activity, "running") ??
|
|
104
|
+
tr("ai.chat.running", {
|
|
105
|
+
default: "Running $1",
|
|
106
|
+
args: [chat.activity],
|
|
107
|
+
}))
|
|
108
|
+
: undefined;
|
|
109
|
+
|
|
110
|
+
const Card = chat.pending
|
|
111
|
+
? (props.confirmCards?.[chat.pending.name] ?? AiChatConfirmCard)
|
|
112
|
+
: undefined;
|
|
113
|
+
|
|
114
|
+
const title = props.title ?? tr("ai.chat.title", { default: "Assistant" });
|
|
115
|
+
const titleClassName = "flex-1 truncate text-base font-medium";
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<div data-testid="ai-chat" className="flex h-full min-h-0 w-full flex-col">
|
|
119
|
+
<div className="border-border flex items-center gap-2 border-b py-2.5 pr-2.5 pl-4">
|
|
120
|
+
<Sparkles className="text-primary size-4 shrink-0" />
|
|
121
|
+
{props.renderTitle ? (
|
|
122
|
+
props.renderTitle(title, titleClassName)
|
|
123
|
+
) : (
|
|
124
|
+
<h2 className={titleClassName}>{title}</h2>
|
|
125
|
+
)}
|
|
126
|
+
{props.headerActions}
|
|
127
|
+
{props.history !== false && (
|
|
128
|
+
<AiChatHistory
|
|
129
|
+
current={chat.conversationId}
|
|
130
|
+
disabled={chat.loading}
|
|
131
|
+
onOpen={(id) => chat.open(id)}
|
|
132
|
+
/>
|
|
133
|
+
)}
|
|
134
|
+
<Button
|
|
135
|
+
size="icon-sm"
|
|
136
|
+
variant="minimal"
|
|
137
|
+
disabled={chat.loading || empty}
|
|
138
|
+
aria-label={tr("ai.chat.new", { default: "New conversation" })}
|
|
139
|
+
onClick={() => chat.open(undefined)}
|
|
140
|
+
>
|
|
141
|
+
<SquarePen className="size-4" />
|
|
142
|
+
</Button>
|
|
143
|
+
{props.onMinimize && (
|
|
144
|
+
<Button
|
|
145
|
+
size="icon-sm"
|
|
146
|
+
variant="minimal"
|
|
147
|
+
aria-label={tr("ai.chat.minimize", { default: "Minimize" })}
|
|
148
|
+
onClick={props.onMinimize}
|
|
149
|
+
>
|
|
150
|
+
<Minus className="size-4" />
|
|
151
|
+
</Button>
|
|
152
|
+
)}
|
|
153
|
+
<Button
|
|
154
|
+
size="icon-sm"
|
|
155
|
+
variant="minimal"
|
|
156
|
+
aria-label={tr("ai.chat.close", { default: "Close" })}
|
|
157
|
+
onClick={props.onClose}
|
|
158
|
+
>
|
|
159
|
+
<X className="size-4" />
|
|
160
|
+
</Button>
|
|
161
|
+
</div>
|
|
162
|
+
<div
|
|
163
|
+
ref={thread}
|
|
164
|
+
// `shrink-0` on every line: in a scrolling column a card (overflow
|
|
165
|
+
// hidden, so no content minimum) would shrink to its border once
|
|
166
|
+
// the thread outgrows the panel (#Q3174).
|
|
167
|
+
className="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-4 py-4 *:shrink-0"
|
|
168
|
+
>
|
|
169
|
+
{empty ? (
|
|
170
|
+
<AiChatEmpty
|
|
171
|
+
suggestions={props.suggestions}
|
|
172
|
+
disabled={chat.loading}
|
|
173
|
+
onPick={(prompt) => chat.send(prompt)}
|
|
174
|
+
/>
|
|
175
|
+
) : (
|
|
176
|
+
<>
|
|
177
|
+
{chat.items.map((item, index) => (
|
|
178
|
+
<AiChatMessage
|
|
179
|
+
key={item.id}
|
|
180
|
+
item={item}
|
|
181
|
+
renderLink={props.renderLink}
|
|
182
|
+
toolLabel={props.toolLabel}
|
|
183
|
+
// Only where continuing still means "this answer": the last
|
|
184
|
+
// line, with no turn running and no card waiting.
|
|
185
|
+
onContinue={
|
|
186
|
+
item.cut &&
|
|
187
|
+
index === chat.items.length - 1 &&
|
|
188
|
+
!chat.loading &&
|
|
189
|
+
!chat.pending
|
|
190
|
+
? () =>
|
|
191
|
+
void chat.send(
|
|
192
|
+
tr("ai.chat.continueMessage", {
|
|
193
|
+
default: "Continue",
|
|
194
|
+
}),
|
|
195
|
+
)
|
|
196
|
+
: undefined
|
|
197
|
+
}
|
|
198
|
+
/>
|
|
199
|
+
))}
|
|
200
|
+
{chat.streaming && (
|
|
201
|
+
<div
|
|
202
|
+
data-testid="ai-chat-streaming"
|
|
203
|
+
className="mr-4 self-start text-sm leading-relaxed"
|
|
204
|
+
>
|
|
205
|
+
<MarkdownView
|
|
206
|
+
content={chat.streaming}
|
|
207
|
+
renderLink={props.renderLink}
|
|
208
|
+
/>
|
|
209
|
+
</div>
|
|
210
|
+
)}
|
|
211
|
+
{running && (
|
|
212
|
+
<div className="text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs">
|
|
213
|
+
<Spinner className="size-3.5" />
|
|
214
|
+
{running}
|
|
215
|
+
</div>
|
|
216
|
+
)}
|
|
217
|
+
{busy && !running && !chat.streaming && (
|
|
218
|
+
<div
|
|
219
|
+
className="text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs"
|
|
220
|
+
aria-live="polite"
|
|
221
|
+
>
|
|
222
|
+
<Spinner className="size-3.5" />
|
|
223
|
+
{tr("ai.chat.thinking", { default: "Thinking…" })}
|
|
224
|
+
</div>
|
|
225
|
+
)}
|
|
226
|
+
{chat.pending?.kind === "confirm" && Card && (
|
|
227
|
+
<Card
|
|
228
|
+
pending={chat.pending}
|
|
229
|
+
loading={chat.loading}
|
|
230
|
+
onApprove={() => chat.approve()}
|
|
231
|
+
onDeny={() => chat.deny()}
|
|
232
|
+
/>
|
|
233
|
+
)}
|
|
234
|
+
</>
|
|
235
|
+
)}
|
|
236
|
+
{chat.error && (
|
|
237
|
+
<Alert variant="destructive" data-testid="ai-chat-error">
|
|
238
|
+
<AlertDescription>{chat.error}</AlertDescription>
|
|
239
|
+
</Alert>
|
|
240
|
+
)}
|
|
241
|
+
</div>
|
|
242
|
+
<div className="border-border border-t px-3 pt-3 pb-2.5">
|
|
243
|
+
<AiChatComposer
|
|
244
|
+
busy={busy}
|
|
245
|
+
waiting={chat.pending?.kind === "confirm"}
|
|
246
|
+
onSend={(message) => chat.send(message)}
|
|
247
|
+
onStop={() => chat.stop()}
|
|
248
|
+
/>
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
);
|
|
252
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fireEvent, render, waitFor } from "@testing-library/react";
|
|
1
|
+
import { fireEvent, render, waitFor, within } from "@testing-library/react";
|
|
2
2
|
import { Alepha, z } from "alepha";
|
|
3
3
|
import { AlephaLogger } from "alepha/logger";
|
|
4
4
|
import { AlephaContext, AlephaReact } from "alepha/react";
|
|
@@ -7,10 +7,12 @@ import { AlephaReactI18n, I18nProvider } from "alepha/react/i18n";
|
|
|
7
7
|
import { $page, AlephaReactRouter } from "alepha/react/router";
|
|
8
8
|
import { LinkProvider } from "alepha/server/links";
|
|
9
9
|
import { setupJsdomMocks } from "alepha/testing/react";
|
|
10
|
+
import { type ComponentType, useState } from "react";
|
|
10
11
|
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
11
12
|
|
|
12
13
|
import { AiChat, type AiChatProps } from "../AiChat.tsx";
|
|
13
14
|
import type { AiChatConfirmCardProps } from "../AiChatConfirmCard.tsx";
|
|
15
|
+
import { AiChatDockSlot } from "../AiChatDockSlot.tsx";
|
|
14
16
|
import { useAiContext } from "../useAiContext.ts";
|
|
15
17
|
|
|
16
18
|
const conversationId = "00000000-0000-4000-8000-000000000041";
|
|
@@ -79,6 +81,26 @@ const InvoicePage = (props: InvoicePageProps) => {
|
|
|
79
81
|
return null;
|
|
80
82
|
};
|
|
81
83
|
|
|
84
|
+
/**
|
|
85
|
+
* A layout with a dock column and the app's own open button, the state
|
|
86
|
+
* `AiChat` reports its minimize through.
|
|
87
|
+
*/
|
|
88
|
+
const DockLayout = (props: Partial<AiChatProps>) => {
|
|
89
|
+
const [open, setOpen] = useState(true);
|
|
90
|
+
return (
|
|
91
|
+
<div data-testid="layout" style={{ display: "flex" }}>
|
|
92
|
+
<main>
|
|
93
|
+
<button type="button" onClick={() => setOpen(true)}>
|
|
94
|
+
Ask
|
|
95
|
+
</button>
|
|
96
|
+
<span data-testid="open-state">{String(open)}</span>
|
|
97
|
+
</main>
|
|
98
|
+
<AiChatDockSlot />
|
|
99
|
+
<AiChat {...props} mode="dock" open={open} onOpenChange={setOpen} />
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
82
104
|
describe("AiChat", () => {
|
|
83
105
|
let alepha: Alepha | undefined;
|
|
84
106
|
|
|
@@ -94,6 +116,7 @@ describe("AiChat", () => {
|
|
|
94
116
|
const mount = async (
|
|
95
117
|
setup: (links: Links) => void = () => {},
|
|
96
118
|
chatProps: Partial<AiChatProps> = {},
|
|
119
|
+
Layout?: ComponentType<Partial<AiChatProps>>,
|
|
97
120
|
) => {
|
|
98
121
|
alepha = Alepha.create()
|
|
99
122
|
.with(AlephaLogger)
|
|
@@ -117,7 +140,11 @@ describe("AiChat", () => {
|
|
|
117
140
|
const view = render(
|
|
118
141
|
<AlephaContext.Provider value={alepha}>
|
|
119
142
|
<InvoicePage onForm={(f) => (form = f)} />
|
|
120
|
-
|
|
143
|
+
{Layout ? (
|
|
144
|
+
<Layout {...chatProps} />
|
|
145
|
+
) : (
|
|
146
|
+
<AiChat open onOpenChange={() => {}} {...chatProps} />
|
|
147
|
+
)}
|
|
121
148
|
</AlephaContext.Provider>,
|
|
122
149
|
);
|
|
123
150
|
const say = async (text: string) => {
|
|
@@ -162,6 +189,59 @@ describe("AiChat", () => {
|
|
|
162
189
|
]);
|
|
163
190
|
});
|
|
164
191
|
|
|
192
|
+
it("says when a reply was cut at the length limit, and continues on request", async () => {
|
|
193
|
+
const { links, view, say } = await mount((l) => {
|
|
194
|
+
l.streams.push([
|
|
195
|
+
{ type: "conversation", conversationId },
|
|
196
|
+
{ type: "text", text: "Folio 1, folio 2, **" },
|
|
197
|
+
{ type: "end", reason: "length" },
|
|
198
|
+
]);
|
|
199
|
+
l.streams.push([
|
|
200
|
+
{ type: "text", text: "folio 3." },
|
|
201
|
+
{ type: "end", reason: "stop" },
|
|
202
|
+
]);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
await say("list the folios");
|
|
206
|
+
|
|
207
|
+
const notice = await waitFor(() => view.getByTestId("ai-chat-cut"));
|
|
208
|
+
expect(notice.textContent).toContain("This answer was cut short");
|
|
209
|
+
// The cut text stays, and the notice belongs to that reply.
|
|
210
|
+
const cut = view.getByTestId("ai-chat-assistant");
|
|
211
|
+
expect(cut.textContent).toContain("Folio 1, folio 2,");
|
|
212
|
+
expect(cut.contains(notice)).toBe(true);
|
|
213
|
+
|
|
214
|
+
fireEvent.click(within(notice).getByRole("button", { name: "Continue" }));
|
|
215
|
+
|
|
216
|
+
await waitFor(() =>
|
|
217
|
+
expect(view.getAllByTestId("ai-chat-assistant").at(-1)?.textContent).toBe(
|
|
218
|
+
"folio 3.",
|
|
219
|
+
),
|
|
220
|
+
);
|
|
221
|
+
expect(links.bodies("chat").map((body: any) => body.message)).toEqual([
|
|
222
|
+
"list the folios",
|
|
223
|
+
"Continue",
|
|
224
|
+
]);
|
|
225
|
+
// The older reply keeps its notice and loses its button: continuing now
|
|
226
|
+
// would no longer mean that answer. A finished reply carries none.
|
|
227
|
+
const notices = view.getAllByTestId("ai-chat-cut");
|
|
228
|
+
expect(notices).toHaveLength(1);
|
|
229
|
+
expect(within(notices[0]!).queryByRole("button")).toBeNull();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("marks a turn cut before any text, so an empty reply is not silence", async () => {
|
|
233
|
+
const { view, say } = await mount((l) => {
|
|
234
|
+
l.streams.push([
|
|
235
|
+
{ type: "conversation", conversationId },
|
|
236
|
+
{ type: "end", reason: "length" },
|
|
237
|
+
]);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
await say("list everything");
|
|
241
|
+
|
|
242
|
+
await waitFor(() => expect(view.getByTestId("ai-chat-cut")).toBeTruthy());
|
|
243
|
+
});
|
|
244
|
+
|
|
165
245
|
it("keeps what was typed when the drawer re-renders before Send", async () => {
|
|
166
246
|
const { links, view } = await mount((l) => {
|
|
167
247
|
l.streams.push([
|
|
@@ -283,13 +363,58 @@ describe("AiChat", () => {
|
|
|
283
363
|
name: "resume",
|
|
284
364
|
input: {
|
|
285
365
|
params: { id: conversationId },
|
|
286
|
-
body: {
|
|
366
|
+
body: {
|
|
367
|
+
callId: "c1",
|
|
368
|
+
decision: "approve",
|
|
369
|
+
// The page context rides on the resume, for the server's `allow`.
|
|
370
|
+
context: expect.objectContaining({ route: "/" }),
|
|
371
|
+
},
|
|
287
372
|
},
|
|
288
373
|
},
|
|
289
374
|
]);
|
|
290
375
|
expect(view.queryByTestId("ai-chat-confirm")).toBeNull();
|
|
291
376
|
});
|
|
292
377
|
|
|
378
|
+
it("tells onToolsRan which tools succeeded once the stream ends", async () => {
|
|
379
|
+
const ran: string[][] = [];
|
|
380
|
+
const { view, say } = await mount(
|
|
381
|
+
(l) => {
|
|
382
|
+
l.streams.push([
|
|
383
|
+
{ type: "conversation", conversationId },
|
|
384
|
+
{
|
|
385
|
+
type: "confirm",
|
|
386
|
+
callId: "c4",
|
|
387
|
+
name: "createInvoice",
|
|
388
|
+
input: { body: { amount: 5 } },
|
|
389
|
+
},
|
|
390
|
+
{ type: "end", reason: "paused" },
|
|
391
|
+
]);
|
|
392
|
+
l.streams.push([
|
|
393
|
+
{
|
|
394
|
+
type: "tool_result",
|
|
395
|
+
callId: "c4",
|
|
396
|
+
name: "createInvoice",
|
|
397
|
+
isError: false,
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
type: "tool_result",
|
|
401
|
+
callId: "c5",
|
|
402
|
+
name: "listInvoices",
|
|
403
|
+
isError: true,
|
|
404
|
+
},
|
|
405
|
+
{ type: "text", text: "Billed." },
|
|
406
|
+
{ type: "end", reason: "stop" },
|
|
407
|
+
]);
|
|
408
|
+
},
|
|
409
|
+
{ onToolsRan: (names) => ran.push(names) },
|
|
410
|
+
);
|
|
411
|
+
await say("bill 5");
|
|
412
|
+
fireEvent.click(await view.findByRole("button", { name: "Approve" }));
|
|
413
|
+
await view.findByText("Billed.");
|
|
414
|
+
// The failed one is left out: only a success changed anything.
|
|
415
|
+
expect(ran).toEqual([["createInvoice"]]);
|
|
416
|
+
});
|
|
417
|
+
|
|
293
418
|
it("denies a mutation by call id only", async () => {
|
|
294
419
|
const { links, view, say } = await mount((l) => {
|
|
295
420
|
l.streams.push([
|
|
@@ -298,6 +423,12 @@ describe("AiChat", () => {
|
|
|
298
423
|
{ type: "end", reason: "paused" },
|
|
299
424
|
]);
|
|
300
425
|
l.streams.push([
|
|
426
|
+
{
|
|
427
|
+
type: "tool_result",
|
|
428
|
+
callId: "c2",
|
|
429
|
+
name: "deleteAll",
|
|
430
|
+
isError: true,
|
|
431
|
+
},
|
|
301
432
|
{ type: "text", text: "Not done." },
|
|
302
433
|
{ type: "end", reason: "stop" },
|
|
303
434
|
]);
|
|
@@ -306,8 +437,16 @@ describe("AiChat", () => {
|
|
|
306
437
|
fireEvent.click(await view.findByRole("button", { name: "Deny" }));
|
|
307
438
|
await view.findByText("Not done.");
|
|
308
439
|
expect(links.bodies("resume")).toEqual([
|
|
309
|
-
{
|
|
440
|
+
{
|
|
441
|
+
callId: "c2",
|
|
442
|
+
decision: "deny",
|
|
443
|
+
context: expect.objectContaining({ route: "/" }),
|
|
444
|
+
},
|
|
310
445
|
]);
|
|
446
|
+
// A denial reads as cancelled, not as a failure.
|
|
447
|
+
expect(view.getByTestId("ai-chat-tool").textContent).toBe(
|
|
448
|
+
"deleteAll cancelled",
|
|
449
|
+
);
|
|
311
450
|
});
|
|
312
451
|
|
|
313
452
|
it("fills the offered form without submitting, then resumes with what it filled", async () => {
|
|
@@ -344,6 +483,7 @@ describe("AiChat", () => {
|
|
|
344
483
|
ignored: ["password"],
|
|
345
484
|
submitted: false,
|
|
346
485
|
},
|
|
486
|
+
context: expect.objectContaining({ route: "/" }),
|
|
347
487
|
},
|
|
348
488
|
]);
|
|
349
489
|
});
|
|
@@ -432,7 +572,11 @@ describe("AiChat", () => {
|
|
|
432
572
|
fireEvent.click(view.getByRole("button", { name: "Book it" }));
|
|
433
573
|
await view.findByText("Booked.");
|
|
434
574
|
expect(links.bodies("resume")).toEqual([
|
|
435
|
-
{
|
|
575
|
+
{
|
|
576
|
+
callId: "c3",
|
|
577
|
+
decision: "approve",
|
|
578
|
+
context: expect.objectContaining({ route: "/" }),
|
|
579
|
+
},
|
|
436
580
|
]);
|
|
437
581
|
});
|
|
438
582
|
|
|
@@ -529,4 +673,52 @@ describe("AiChat", () => {
|
|
|
529
673
|
expect(box.disabled).toBe(true);
|
|
530
674
|
expect(box.placeholder).toBe("Confirm or cancel the card to go on");
|
|
531
675
|
});
|
|
676
|
+
|
|
677
|
+
it("docks beside the page without a backdrop, minimizes into a pill that shows a waiting action, and restores", async () => {
|
|
678
|
+
const { view, say } = await mount(
|
|
679
|
+
(l) => {
|
|
680
|
+
l.streams.push([
|
|
681
|
+
{ type: "conversation", conversationId },
|
|
682
|
+
{
|
|
683
|
+
type: "confirm",
|
|
684
|
+
callId: "c1",
|
|
685
|
+
name: "createNote",
|
|
686
|
+
input: { body: { title: "x" } },
|
|
687
|
+
},
|
|
688
|
+
{ type: "end", reason: "paused" },
|
|
689
|
+
]);
|
|
690
|
+
},
|
|
691
|
+
{},
|
|
692
|
+
DockLayout,
|
|
693
|
+
);
|
|
694
|
+
|
|
695
|
+
// In the layout's slot, a sibling of the page, and not a dialog.
|
|
696
|
+
const dock = await view.findByTestId("ai-chat-dock");
|
|
697
|
+
expect(dock.parentElement?.getAttribute("data-slot")).toBe("ai-chat-dock");
|
|
698
|
+
expect(view.queryByRole("dialog")).toBeNull();
|
|
699
|
+
expect(document.querySelector("[data-slot='drawer-overlay']")).toBeNull();
|
|
700
|
+
|
|
701
|
+
await say("add a note");
|
|
702
|
+
await view.findByTestId("ai-chat-confirm");
|
|
703
|
+
|
|
704
|
+
fireEvent.click(view.getByRole("button", { name: "Minimize" }));
|
|
705
|
+
expect(view.queryByTestId("ai-chat-dock")).toBeNull();
|
|
706
|
+
expect(view.getByTestId("open-state").textContent).toBe("false");
|
|
707
|
+
const pill = view.getByTestId("ai-chat-launcher");
|
|
708
|
+
expect(pill.textContent).toContain("Action to approve");
|
|
709
|
+
|
|
710
|
+
// The app's own button brings it back, conversation and card included.
|
|
711
|
+
fireEvent.click(view.getByRole("button", { name: "Ask" }));
|
|
712
|
+
await view.findByTestId("ai-chat-dock");
|
|
713
|
+
expect(view.queryByTestId("ai-chat-launcher")).toBeNull();
|
|
714
|
+
expect(view.getByTestId("ai-chat-confirm")).toBeTruthy();
|
|
715
|
+
|
|
716
|
+
// Closing ends with no pill left behind; the pill restores too.
|
|
717
|
+
fireEvent.click(view.getByRole("button", { name: "Minimize" }));
|
|
718
|
+
fireEvent.click(view.getByTestId("ai-chat-launcher"));
|
|
719
|
+
await view.findByTestId("ai-chat-dock");
|
|
720
|
+
fireEvent.click(view.getByRole("button", { name: "Close" }));
|
|
721
|
+
expect(view.queryByTestId("ai-chat-dock")).toBeNull();
|
|
722
|
+
expect(view.queryByTestId("ai-chat-launcher")).toBeNull();
|
|
723
|
+
});
|
|
532
724
|
});
|
package/src/ai/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The in-app assistant on the client: a chat drawer
|
|
3
|
-
* history and a confirmation card per
|
|
4
|
-
* and `useAiContext` for a page to
|
|
5
|
-
* `alepha/api/ai`.
|
|
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
|
|
4
|
+
* mutation, the headless `useAiChat`, and `useAiContext` for a page to
|
|
5
|
+
* declare what it shows. Talks to `alepha/api/ai`.
|
|
6
6
|
*
|
|
7
7
|
* @module alepha.ui.ai
|
|
8
8
|
*/
|
|
@@ -11,9 +11,13 @@ export * from "./AiChat.tsx";
|
|
|
11
11
|
export * from "./AiChatComposer.tsx";
|
|
12
12
|
export * from "./AiChatConfirmCard.tsx";
|
|
13
13
|
export * from "./AiChatConfirmFields.tsx";
|
|
14
|
+
export * from "./AiChatDock.tsx";
|
|
15
|
+
export * from "./AiChatDockSlot.tsx";
|
|
14
16
|
export * from "./AiChatEmpty.tsx";
|
|
15
17
|
export * from "./AiChatHistory.tsx";
|
|
18
|
+
export * from "./AiChatLauncher.tsx";
|
|
16
19
|
export * from "./AiChatMessage.tsx";
|
|
20
|
+
export * from "./AiChatPanel.tsx";
|
|
17
21
|
export * from "./aiChatMessageFormSchema.ts";
|
|
18
22
|
export * from "./aiContextAtom.ts";
|
|
19
23
|
export * from "./AiFormRegistry.ts";
|