@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.
- 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 +6 -0
- package/dist/ai/AiChatMessage.d.ts.map +1 -1
- package/dist/ai/AiChatMessage.js +20 -4
- 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 +12 -0
- package/dist/ai/useAiChat.d.ts.map +1 -1
- package/dist/ai/useAiChat.js +32 -15
- 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 +14 -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 +36 -2
- package/src/ai/AiChatPanel.tsx +252 -0
- package/src/ai/__tests__/AiChat.browser.spec.tsx +187 -5
- package/src/ai/index.ts +8 -4
- package/src/ai/useAiChat.ts +63 -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 +18 -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,42 @@
|
|
|
1
|
+
import { Badge } from "../core/Badge.js";
|
|
2
|
+
import { Spinner } from "../core/Spinner.js";
|
|
3
|
+
import { cn } from "../core/utils.js";
|
|
4
|
+
import { useI18n } from "alepha/react/i18n";
|
|
5
|
+
import { Sparkles } from "lucide-react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/ai/AiChatLauncher.tsx
|
|
8
|
+
/**
|
|
9
|
+
* A minimized assistant: a pill at the bottom corner that brings the panel
|
|
10
|
+
* back, and still says what the conversation is doing, so folding it away
|
|
11
|
+
* never hides an action waiting for the user's approval.
|
|
12
|
+
*/
|
|
13
|
+
const AiChatLauncher = (props) => {
|
|
14
|
+
const { tr } = useI18n();
|
|
15
|
+
const { chat } = props;
|
|
16
|
+
const waiting = chat.pending?.kind === "confirm";
|
|
17
|
+
const busy = chat.loading && !chat.pending;
|
|
18
|
+
const title = props.title ?? tr("ai.chat.title", { default: "Assistant" });
|
|
19
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
20
|
+
type: "button",
|
|
21
|
+
"data-testid": "ai-chat-launcher",
|
|
22
|
+
onClick: props.onRestore,
|
|
23
|
+
"aria-label": tr("ai.chat.restore", {
|
|
24
|
+
default: "Open $1",
|
|
25
|
+
args: [title]
|
|
26
|
+
}),
|
|
27
|
+
className: cn("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", props.className),
|
|
28
|
+
children: [
|
|
29
|
+
busy ? /* @__PURE__ */ jsx(Spinner, { className: "size-4" }) : /* @__PURE__ */ jsx(Sparkles, { className: "text-primary size-4" }),
|
|
30
|
+
title,
|
|
31
|
+
waiting && /* @__PURE__ */ jsx(Badge, {
|
|
32
|
+
variant: "tint",
|
|
33
|
+
tone: "warning",
|
|
34
|
+
"aria-live": "polite",
|
|
35
|
+
children: tr("ai.chat.awaiting", { default: "Action to approve" })
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export { AiChatLauncher };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=AiChatLauncher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatLauncher.js","names":[],"sources":["../../src/ai/AiChatLauncher.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { Sparkles } from \"lucide-react\";\n\nimport { Badge } from \"../core/Badge.tsx\";\nimport { Spinner } from \"../core/Spinner.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport type { UseAiChat } from \"./useAiChat.ts\";\n\nexport interface AiChatLauncherProps {\n /**\n * The conversation the pill speaks for.\n */\n chat: UseAiChat;\n title?: string;\n onRestore: () => void;\n className?: string;\n}\n\n/**\n * A minimized assistant: a pill at the bottom corner that brings the panel\n * back, and still says what the conversation is doing, so folding it away\n * never hides an action waiting for the user's approval.\n */\nexport const AiChatLauncher = (props: AiChatLauncherProps) => {\n const { tr } = useI18n();\n const { chat } = props;\n const waiting = chat.pending?.kind === \"confirm\";\n const busy = chat.loading && !chat.pending;\n const title = props.title ?? tr(\"ai.chat.title\", { default: \"Assistant\" });\n\n return (\n <button\n type=\"button\"\n data-testid=\"ai-chat-launcher\"\n onClick={props.onRestore}\n aria-label={tr(\"ai.chat.restore\", {\n default: \"Open $1\",\n args: [title],\n })}\n className={cn(\n \"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\",\n props.className,\n )}\n >\n {busy ? (\n <Spinner className=\"size-4\" />\n ) : (\n <Sparkles className=\"text-primary size-4\" />\n )}\n {title}\n {waiting && (\n <Badge variant=\"tint\" tone=\"warning\" aria-live=\"polite\">\n {tr(\"ai.chat.awaiting\", { default: \"Action to approve\" })}\n </Badge>\n )}\n </button>\n );\n};\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,kBAAkB,UAA+B;CAC5D,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,EAAE,SAAS;CACjB,MAAM,UAAU,KAAK,SAAS,SAAS;CACvC,MAAM,OAAO,KAAK,WAAW,CAAC,KAAK;CACnC,MAAM,QAAQ,MAAM,SAAS,GAAG,iBAAiB,EAAE,SAAS,YAAY,CAAC;CAEzE,OACE,qBAAC,UAAD;EACE,MAAK;EACL,eAAY;EACZ,SAAS,MAAM;EACf,cAAY,GAAG,mBAAmB;GAChC,SAAS;GACT,MAAM,CAAC,KAAK;EACd,CAAC;EACD,WAAW,GACT,2PACA,MAAM,SACR;EAXF,UAAA;GAaG,OACC,oBAAC,SAAD,EAAS,WAAU,SAAU,CAAA,IAE7B,oBAAC,UAAD,EAAU,WAAU,sBAAuB,CAAA;GAE5C;GACA,WACC,oBAAC,OAAD;IAAO,SAAQ;IAAO,MAAK;IAAU,aAAU;IAC5C,UAAA,GAAG,oBAAoB,EAAE,SAAS,oBAAoB,CAAC;GACnD,CAAA;EAEH;;AAEZ"}
|
|
@@ -10,6 +10,12 @@ export interface AiChatMessageProps {
|
|
|
10
10
|
* The words a tool step shows: `AiChat`'s `toolLabel`.
|
|
11
11
|
*/
|
|
12
12
|
toolLabel?: AiChatToolLabel;
|
|
13
|
+
/**
|
|
14
|
+
* Asks the assistant to go on, from the notice under a reply that was cut
|
|
15
|
+
* short. Absent, the notice shows without its button: `AiChatPanel` passes
|
|
16
|
+
* it on the last line only, and never while a turn runs.
|
|
17
|
+
*/
|
|
18
|
+
onContinue?: () => void;
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
21
|
* Names a tool step in the user's words ("Searched clients") instead of the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiChatMessage.d.ts","sourceRoot":"","sources":["../../src/ai/AiChatMessage.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AiChatMessage.d.ts","sourceRoot":"","sources":["../../src/ai/AiChatMessage.tsx"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,UAAU,CAAC;IACjB;;OAEG;IACH,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC;;OAEG;IACH,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,KAC5C,MAAM,GAAG,SAAS,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,aAAa,UAAW,kBAAkB,gCAgFtD,CAAC"}
|
package/dist/ai/AiChatMessage.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Button } from "../core/Button.js";
|
|
1
2
|
import { cn } from "../core/utils.js";
|
|
2
3
|
import { MarkdownView } from "../markdown/MarkdownView.js";
|
|
3
4
|
import { useI18n } from "alepha/react/i18n";
|
|
4
|
-
import { Ban, Check, X } from "lucide-react";
|
|
5
|
+
import { Ban, Check, Scissors, X } from "lucide-react";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
// src/ai/AiChatMessage.tsx
|
|
7
8
|
/**
|
|
@@ -35,13 +36,28 @@ const AiChatMessage = (props) => {
|
|
|
35
36
|
className: "bg-muted ml-10 self-end rounded-2xl rounded-br-md px-3.5 py-2 text-sm leading-relaxed whitespace-pre-wrap",
|
|
36
37
|
children: item.content
|
|
37
38
|
});
|
|
38
|
-
return /* @__PURE__ */
|
|
39
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
39
40
|
"data-testid": "ai-chat-assistant",
|
|
40
41
|
className: "mr-4 self-start text-sm leading-relaxed",
|
|
41
|
-
children: /* @__PURE__ */ jsx(MarkdownView, {
|
|
42
|
+
children: [item.content ? /* @__PURE__ */ jsx(MarkdownView, {
|
|
42
43
|
content: item.content,
|
|
43
44
|
renderLink: props.renderLink
|
|
44
|
-
})
|
|
45
|
+
}) : null, item.cut ? /* @__PURE__ */ jsxs("div", {
|
|
46
|
+
"data-testid": "ai-chat-cut",
|
|
47
|
+
role: "status",
|
|
48
|
+
className: "text-warning-text mt-2 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs",
|
|
49
|
+
children: [
|
|
50
|
+
/* @__PURE__ */ jsx(Scissors, { className: "size-3.5 shrink-0" }),
|
|
51
|
+
/* @__PURE__ */ jsx("span", { children: tr("ai.chat.cut", { default: "This answer was cut short: it reached the length limit. Ask a narrower question, or continue." }) }),
|
|
52
|
+
props.onContinue ? /* @__PURE__ */ jsx(Button, {
|
|
53
|
+
type: "button",
|
|
54
|
+
variant: "outlined",
|
|
55
|
+
size: "xs",
|
|
56
|
+
onClick: props.onContinue,
|
|
57
|
+
children: tr("ai.chat.continue", { default: "Continue" })
|
|
58
|
+
}) : null
|
|
59
|
+
]
|
|
60
|
+
}) : null]
|
|
45
61
|
});
|
|
46
62
|
};
|
|
47
63
|
export { AiChatMessage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiChatMessage.js","names":[],"sources":["../../src/ai/AiChatMessage.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { Ban, Check, X } from \"lucide-react\";\n\nimport { cn } from \"../core/utils.ts\";\nimport {\n type MarkdownLinkRenderer,\n MarkdownView,\n} from \"../markdown/MarkdownView.tsx\";\nimport type { AiChatItem } from \"./useAiChat.ts\";\n\nexport interface AiChatMessageProps {\n item: AiChatItem;\n /**\n * How the assistant's links render. See `MarkdownView`'s `renderLink`.\n */\n renderLink?: MarkdownLinkRenderer;\n /**\n * The words a tool step shows: `AiChat`'s `toolLabel`.\n */\n toolLabel?: AiChatToolLabel;\n}\n\n/**\n * Names a tool step in the user's words (\"Searched clients\") instead of the\n * tool's own name. Return undefined to keep the default line.\n */\nexport type AiChatToolLabel = (\n name: string,\n state: \"running\" | \"done\" | \"failed\" | \"denied\",\n) => string | undefined;\n\n/**\n * One line of the conversation: the user's message as typed, the\n * assistant's as markdown, a tool call as a quiet one-liner.\n */\nexport const AiChatMessage = (props: AiChatMessageProps) => {\n const { tr } = useI18n();\n const item = props.item;\n\n if (item.role === \"tool\") {\n const name = item.name ?? \"\";\n const state = item.denied ? \"denied\" : item.isError ? \"failed\" : \"done\";\n const label =\n props.toolLabel?.(name, state) ??\n (state === \"denied\"\n ? tr(\"ai.chat.toolDenied\", { default: \"$1 cancelled\", args: [name] })\n : state === \"failed\"\n ? tr(\"ai.chat.toolFailed\", { default: \"$1 failed\", args: [name] })\n : tr(\"ai.chat.toolDone\", { default: \"Ran $1\", args: [name] }));\n return (\n <div\n data-testid=\"ai-chat-tool\"\n className={cn(\n \"text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs\",\n state === \"failed\" && \"text-danger-text\",\n )}\n >\n {state === \"denied\" ? (\n <Ban className=\"size-3.5 shrink-0\" />\n ) : state === \"failed\" ? (\n <X className=\"size-3.5 shrink-0\" />\n ) : (\n <Check className=\"text-success-text size-3.5 shrink-0\" />\n )}\n <span>{label}</span>\n </div>\n );\n }\n\n if (item.role === \"user\") {\n return (\n <div\n data-testid=\"ai-chat-user\"\n className=\"bg-muted ml-10 self-end rounded-2xl rounded-br-md px-3.5 py-2 text-sm leading-relaxed whitespace-pre-wrap\"\n >\n {item.content}\n </div>\n );\n }\n\n return (\n <div\n data-testid=\"ai-chat-assistant\"\n className=\"mr-4 self-start text-sm leading-relaxed\"\n >\n <MarkdownView content={item.content} renderLink={props.renderLink} />\n </div>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AiChatMessage.js","names":[],"sources":["../../src/ai/AiChatMessage.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { Ban, Check, Scissors, X } from \"lucide-react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport {\n type MarkdownLinkRenderer,\n MarkdownView,\n} from \"../markdown/MarkdownView.tsx\";\nimport type { AiChatItem } from \"./useAiChat.ts\";\n\nexport interface AiChatMessageProps {\n item: AiChatItem;\n /**\n * How the assistant's links render. See `MarkdownView`'s `renderLink`.\n */\n renderLink?: MarkdownLinkRenderer;\n /**\n * The words a tool step shows: `AiChat`'s `toolLabel`.\n */\n toolLabel?: AiChatToolLabel;\n /**\n * Asks the assistant to go on, from the notice under a reply that was cut\n * short. Absent, the notice shows without its button: `AiChatPanel` passes\n * it on the last line only, and never while a turn runs.\n */\n onContinue?: () => void;\n}\n\n/**\n * Names a tool step in the user's words (\"Searched clients\") instead of the\n * tool's own name. Return undefined to keep the default line.\n */\nexport type AiChatToolLabel = (\n name: string,\n state: \"running\" | \"done\" | \"failed\" | \"denied\",\n) => string | undefined;\n\n/**\n * One line of the conversation: the user's message as typed, the\n * assistant's as markdown, a tool call as a quiet one-liner.\n */\nexport const AiChatMessage = (props: AiChatMessageProps) => {\n const { tr } = useI18n();\n const item = props.item;\n\n if (item.role === \"tool\") {\n const name = item.name ?? \"\";\n const state = item.denied ? \"denied\" : item.isError ? \"failed\" : \"done\";\n const label =\n props.toolLabel?.(name, state) ??\n (state === \"denied\"\n ? tr(\"ai.chat.toolDenied\", { default: \"$1 cancelled\", args: [name] })\n : state === \"failed\"\n ? tr(\"ai.chat.toolFailed\", { default: \"$1 failed\", args: [name] })\n : tr(\"ai.chat.toolDone\", { default: \"Ran $1\", args: [name] }));\n return (\n <div\n data-testid=\"ai-chat-tool\"\n className={cn(\n \"text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs\",\n state === \"failed\" && \"text-danger-text\",\n )}\n >\n {state === \"denied\" ? (\n <Ban className=\"size-3.5 shrink-0\" />\n ) : state === \"failed\" ? (\n <X className=\"size-3.5 shrink-0\" />\n ) : (\n <Check className=\"text-success-text size-3.5 shrink-0\" />\n )}\n <span>{label}</span>\n </div>\n );\n }\n\n if (item.role === \"user\") {\n return (\n <div\n data-testid=\"ai-chat-user\"\n className=\"bg-muted ml-10 self-end rounded-2xl rounded-br-md px-3.5 py-2 text-sm leading-relaxed whitespace-pre-wrap\"\n >\n {item.content}\n </div>\n );\n }\n\n return (\n <div\n data-testid=\"ai-chat-assistant\"\n className=\"mr-4 self-start text-sm leading-relaxed\"\n >\n {item.content ? (\n <MarkdownView content={item.content} renderLink={props.renderLink} />\n ) : null}\n {item.cut ? (\n <div\n data-testid=\"ai-chat-cut\"\n role=\"status\"\n className=\"text-warning-text mt-2 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs\"\n >\n <Scissors className=\"size-3.5 shrink-0\" />\n <span>\n {tr(\"ai.chat.cut\", {\n default:\n \"This answer was cut short: it reached the length limit. Ask a narrower question, or continue.\",\n })}\n </span>\n {props.onContinue ? (\n <Button\n type=\"button\"\n variant=\"outlined\"\n size=\"xs\"\n onClick={props.onContinue}\n >\n {tr(\"ai.chat.continue\", { default: \"Continue\" })}\n </Button>\n ) : null}\n </div>\n ) : null}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;AA0CA,MAAa,iBAAiB,UAA8B;CAC1D,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,OAAO,MAAM;CAEnB,IAAI,KAAK,SAAS,QAAQ;EACxB,MAAM,OAAO,KAAK,QAAQ;EAC1B,MAAM,QAAQ,KAAK,SAAS,WAAW,KAAK,UAAU,WAAW;EACjE,MAAM,QACJ,MAAM,YAAY,MAAM,KAAK,MAC5B,UAAU,WACP,GAAG,sBAAsB;GAAE,SAAS;GAAgB,MAAM,CAAC,IAAI;EAAE,CAAC,IAClE,UAAU,WACR,GAAG,sBAAsB;GAAE,SAAS;GAAa,MAAM,CAAC,IAAI;EAAE,CAAC,IAC/D,GAAG,oBAAoB;GAAE,SAAS;GAAU,MAAM,CAAC,IAAI;EAAE,CAAC;EAClE,OACE,qBAAC,OAAD;GACE,eAAY;GACZ,WAAW,GACT,kEACA,UAAU,YAAY,kBACxB;GALF,UAAA,CAOG,UAAU,WACT,oBAAC,KAAD,EAAK,WAAU,oBAAqB,CAAA,IAClC,UAAU,WACZ,oBAAC,GAAD,EAAG,WAAU,oBAAqB,CAAA,IAElC,oBAAC,OAAD,EAAO,WAAU,sCAAuC,CAAA,GAE1D,oBAAC,QAAD,EAAA,UAAO,MAAY,CAAA,CAChB;;CAET;CAEA,IAAI,KAAK,SAAS,QAChB,OACE,oBAAC,OAAD;EACE,eAAY;EACZ,WAAU;EAET,UAAA,KAAK;CACH,CAAA;CAIT,OACE,qBAAC,OAAD;EACE,eAAY;EACZ,WAAU;EAFZ,UAAA,CAIG,KAAK,UACJ,oBAAC,cAAD;GAAc,SAAS,KAAK;GAAS,YAAY,MAAM;EAAa,CAAA,IAClE,MACH,KAAK,MACJ,qBAAC,OAAD;GACE,eAAY;GACZ,MAAK;GACL,WAAU;GAHZ,UAAA;IAKE,oBAAC,UAAD,EAAU,WAAU,oBAAqB,CAAA;IACzC,oBAAC,QAAD,EAAA,UACG,GAAG,eAAe,EACjB,SACE,gGACJ,CAAC,EACG,CAAA;IACL,MAAM,aACL,oBAAC,QAAD;KACE,MAAK;KACL,SAAQ;KACR,MAAK;KACL,SAAS,MAAM;KAEd,UAAA,GAAG,oBAAoB,EAAE,SAAS,WAAW,CAAC;IACzC,CAAA,IACN;GACD;EACH,CAAA,IAAA,IACD;;AAET"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type ComponentType, type ReactNode } from "react";
|
|
2
|
+
import { type MarkdownLinkRenderer } from "../markdown/MarkdownView.tsx";
|
|
3
|
+
import { type AiChatConfirmCardProps } from "./AiChatConfirmCard.tsx";
|
|
4
|
+
import { type AiChatSuggestion } from "./AiChatEmpty.tsx";
|
|
5
|
+
import { type AiChatToolLabel } from "./AiChatMessage.tsx";
|
|
6
|
+
import type { UseAiChat } from "./useAiChat.ts";
|
|
7
|
+
/**
|
|
8
|
+
* What the conversation looks like, whatever holds it: the props `AiChat`
|
|
9
|
+
* passes through to its panel.
|
|
10
|
+
*/
|
|
11
|
+
export interface AiChatViewProps {
|
|
12
|
+
/**
|
|
13
|
+
* The panel's title. Defaults to "Assistant".
|
|
14
|
+
*/
|
|
15
|
+
title?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The app's own controls in the panel's header, before the history menu:
|
|
18
|
+
* a link to the assistant's help page, say.
|
|
19
|
+
*/
|
|
20
|
+
headerActions?: ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Offer the list of past conversations, in a header menu. Default true.
|
|
23
|
+
*/
|
|
24
|
+
history?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Questions a new conversation offers to start from.
|
|
27
|
+
*/
|
|
28
|
+
suggestions?: AiChatSuggestion[];
|
|
29
|
+
/**
|
|
30
|
+
* Names each tool step in the user's words ("Searched clients"), running
|
|
31
|
+
* and done. Without it a step shows the tool's own name.
|
|
32
|
+
*/
|
|
33
|
+
toolLabel?: AiChatToolLabel;
|
|
34
|
+
/**
|
|
35
|
+
* A confirmation card per tool name, in place of the generic field list:
|
|
36
|
+
* an app shows a booking as a booking. It gets the pending call as the
|
|
37
|
+
* server stored it, and the approve and deny callbacks.
|
|
38
|
+
*/
|
|
39
|
+
confirmCards?: Record<string, ComponentType<AiChatConfirmCardProps>>;
|
|
40
|
+
/**
|
|
41
|
+
* How links in the assistant's replies render (`MarkdownView`'s
|
|
42
|
+
* `renderLink`): route the paths the app knows, leave the rest as text.
|
|
43
|
+
*/
|
|
44
|
+
renderLink?: MarkdownLinkRenderer;
|
|
45
|
+
}
|
|
46
|
+
export interface AiChatPanelProps extends AiChatViewProps {
|
|
47
|
+
/**
|
|
48
|
+
* The conversation to show, from `useAiChat()`.
|
|
49
|
+
*/
|
|
50
|
+
chat: UseAiChat;
|
|
51
|
+
onClose: () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Fold the panel away without ending the conversation. Without it the
|
|
54
|
+
* header has no minimize button.
|
|
55
|
+
*/
|
|
56
|
+
onMinimize?: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Renders the title, so a shell can give it its own element (a drawer
|
|
59
|
+
* names its dialog with it). Defaults to a heading.
|
|
60
|
+
*/
|
|
61
|
+
renderTitle?: (title: string, className: string) => ReactNode;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The conversation itself, with no container: a quiet header (history menu,
|
|
65
|
+
* new conversation, minimize, close), the thread with its tool steps and a
|
|
66
|
+
* confirmation card for every mutation the assistant wants to run, and the
|
|
67
|
+
* composer. `AiChat` puts it in a drawer or in a dock; an app with its own
|
|
68
|
+
* container renders it there, with the `useAiChat()` it owns.
|
|
69
|
+
*/
|
|
70
|
+
export declare const AiChatPanel: (props: AiChatPanelProps) => import("react").JSX.Element;
|
|
71
|
+
//# sourceMappingURL=AiChatPanel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatPanel.d.ts","sourceRoot":"","sources":["../../src/ai/AiChatPanel.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAqB,MAAM,OAAO,CAAC;AAK9E,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC,CAAC;IACrE;;;OAGG;IACH,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC;AAED,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD;;OAEG;IACH,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,SAAS,CAAC;CAC/D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,UAAW,gBAAgB,gCAqKlD,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Alert, AlertDescription } from "../core/Alert.js";
|
|
2
|
+
import { Button } from "../core/Button.js";
|
|
3
|
+
import { Spinner } from "../core/Spinner.js";
|
|
4
|
+
import { MarkdownView } from "../markdown/MarkdownView.js";
|
|
5
|
+
import { AiChatComposer } from "./AiChatComposer.js";
|
|
6
|
+
import { AiChatConfirmCard } from "./AiChatConfirmCard.js";
|
|
7
|
+
import { AiChatEmpty } from "./AiChatEmpty.js";
|
|
8
|
+
import { AiChatHistory } from "./AiChatHistory.js";
|
|
9
|
+
import { AiChatMessage } from "./AiChatMessage.js";
|
|
10
|
+
import { useI18n } from "alepha/react/i18n";
|
|
11
|
+
import { Minus, Sparkles, SquarePen, X } from "lucide-react";
|
|
12
|
+
import { useEffect, useRef } from "react";
|
|
13
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
// src/ai/AiChatPanel.tsx
|
|
15
|
+
/**
|
|
16
|
+
* The conversation itself, with no container: a quiet header (history menu,
|
|
17
|
+
* new conversation, minimize, close), the thread with its tool steps and a
|
|
18
|
+
* confirmation card for every mutation the assistant wants to run, and the
|
|
19
|
+
* composer. `AiChat` puts it in a drawer or in a dock; an app with its own
|
|
20
|
+
* container renders it there, with the `useAiChat()` it owns.
|
|
21
|
+
*/
|
|
22
|
+
const AiChatPanel = (props) => {
|
|
23
|
+
const { tr } = useI18n();
|
|
24
|
+
const { chat } = props;
|
|
25
|
+
const thread = useRef(null);
|
|
26
|
+
const busy = chat.loading && !chat.pending;
|
|
27
|
+
const empty = chat.items.length === 0 && !chat.streaming && !busy;
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const node = thread.current;
|
|
30
|
+
if (node) node.scrollTop = node.scrollHeight;
|
|
31
|
+
}, [
|
|
32
|
+
chat.items.length,
|
|
33
|
+
chat.streaming,
|
|
34
|
+
chat.activity,
|
|
35
|
+
chat.pending
|
|
36
|
+
]);
|
|
37
|
+
const running = chat.activity ? props.toolLabel?.(chat.activity, "running") ?? tr("ai.chat.running", {
|
|
38
|
+
default: "Running $1",
|
|
39
|
+
args: [chat.activity]
|
|
40
|
+
}) : void 0;
|
|
41
|
+
const Card = chat.pending ? props.confirmCards?.[chat.pending.name] ?? AiChatConfirmCard : void 0;
|
|
42
|
+
const title = props.title ?? tr("ai.chat.title", { default: "Assistant" });
|
|
43
|
+
const titleClassName = "flex-1 truncate text-base font-medium";
|
|
44
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
45
|
+
"data-testid": "ai-chat",
|
|
46
|
+
className: "flex h-full min-h-0 w-full flex-col",
|
|
47
|
+
children: [
|
|
48
|
+
/* @__PURE__ */ jsxs("div", {
|
|
49
|
+
className: "border-border flex items-center gap-2 border-b py-2.5 pr-2.5 pl-4",
|
|
50
|
+
children: [
|
|
51
|
+
/* @__PURE__ */ jsx(Sparkles, { className: "text-primary size-4 shrink-0" }),
|
|
52
|
+
props.renderTitle ? props.renderTitle(title, titleClassName) : /* @__PURE__ */ jsx("h2", {
|
|
53
|
+
className: titleClassName,
|
|
54
|
+
children: title
|
|
55
|
+
}),
|
|
56
|
+
props.headerActions,
|
|
57
|
+
props.history !== false && /* @__PURE__ */ jsx(AiChatHistory, {
|
|
58
|
+
current: chat.conversationId,
|
|
59
|
+
disabled: chat.loading,
|
|
60
|
+
onOpen: (id) => chat.open(id)
|
|
61
|
+
}),
|
|
62
|
+
/* @__PURE__ */ jsx(Button, {
|
|
63
|
+
size: "icon-sm",
|
|
64
|
+
variant: "minimal",
|
|
65
|
+
disabled: chat.loading || empty,
|
|
66
|
+
"aria-label": tr("ai.chat.new", { default: "New conversation" }),
|
|
67
|
+
onClick: () => chat.open(void 0),
|
|
68
|
+
children: /* @__PURE__ */ jsx(SquarePen, { className: "size-4" })
|
|
69
|
+
}),
|
|
70
|
+
props.onMinimize && /* @__PURE__ */ jsx(Button, {
|
|
71
|
+
size: "icon-sm",
|
|
72
|
+
variant: "minimal",
|
|
73
|
+
"aria-label": tr("ai.chat.minimize", { default: "Minimize" }),
|
|
74
|
+
onClick: props.onMinimize,
|
|
75
|
+
children: /* @__PURE__ */ jsx(Minus, { className: "size-4" })
|
|
76
|
+
}),
|
|
77
|
+
/* @__PURE__ */ jsx(Button, {
|
|
78
|
+
size: "icon-sm",
|
|
79
|
+
variant: "minimal",
|
|
80
|
+
"aria-label": tr("ai.chat.close", { default: "Close" }),
|
|
81
|
+
onClick: props.onClose,
|
|
82
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-4" })
|
|
83
|
+
})
|
|
84
|
+
]
|
|
85
|
+
}),
|
|
86
|
+
/* @__PURE__ */ jsxs("div", {
|
|
87
|
+
ref: thread,
|
|
88
|
+
className: "flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-4 py-4 *:shrink-0",
|
|
89
|
+
children: [empty ? /* @__PURE__ */ jsx(AiChatEmpty, {
|
|
90
|
+
suggestions: props.suggestions,
|
|
91
|
+
disabled: chat.loading,
|
|
92
|
+
onPick: (prompt) => chat.send(prompt)
|
|
93
|
+
}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
94
|
+
chat.items.map((item, index) => /* @__PURE__ */ jsx(AiChatMessage, {
|
|
95
|
+
item,
|
|
96
|
+
renderLink: props.renderLink,
|
|
97
|
+
toolLabel: props.toolLabel,
|
|
98
|
+
onContinue: item.cut && index === chat.items.length - 1 && !chat.loading && !chat.pending ? () => void chat.send(tr("ai.chat.continueMessage", { default: "Continue" })) : void 0
|
|
99
|
+
}, item.id)),
|
|
100
|
+
chat.streaming && /* @__PURE__ */ jsx("div", {
|
|
101
|
+
"data-testid": "ai-chat-streaming",
|
|
102
|
+
className: "mr-4 self-start text-sm leading-relaxed",
|
|
103
|
+
children: /* @__PURE__ */ jsx(MarkdownView, {
|
|
104
|
+
content: chat.streaming,
|
|
105
|
+
renderLink: props.renderLink
|
|
106
|
+
})
|
|
107
|
+
}),
|
|
108
|
+
running && /* @__PURE__ */ jsxs("div", {
|
|
109
|
+
className: "text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs",
|
|
110
|
+
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }), running]
|
|
111
|
+
}),
|
|
112
|
+
busy && !running && !chat.streaming && /* @__PURE__ */ jsxs("div", {
|
|
113
|
+
className: "text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs",
|
|
114
|
+
"aria-live": "polite",
|
|
115
|
+
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }), tr("ai.chat.thinking", { default: "Thinking…" })]
|
|
116
|
+
}),
|
|
117
|
+
chat.pending?.kind === "confirm" && Card && /* @__PURE__ */ jsx(Card, {
|
|
118
|
+
pending: chat.pending,
|
|
119
|
+
loading: chat.loading,
|
|
120
|
+
onApprove: () => chat.approve(),
|
|
121
|
+
onDeny: () => chat.deny()
|
|
122
|
+
})
|
|
123
|
+
] }), chat.error && /* @__PURE__ */ jsx(Alert, {
|
|
124
|
+
variant: "destructive",
|
|
125
|
+
"data-testid": "ai-chat-error",
|
|
126
|
+
children: /* @__PURE__ */ jsx(AlertDescription, { children: chat.error })
|
|
127
|
+
})]
|
|
128
|
+
}),
|
|
129
|
+
/* @__PURE__ */ jsx("div", {
|
|
130
|
+
className: "border-border border-t px-3 pt-3 pb-2.5",
|
|
131
|
+
children: /* @__PURE__ */ jsx(AiChatComposer, {
|
|
132
|
+
busy,
|
|
133
|
+
waiting: chat.pending?.kind === "confirm",
|
|
134
|
+
onSend: (message) => chat.send(message),
|
|
135
|
+
onStop: () => chat.stop()
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
]
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
export { AiChatPanel };
|
|
142
|
+
|
|
143
|
+
//# sourceMappingURL=AiChatPanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatPanel.js","names":[],"sources":["../../src/ai/AiChatPanel.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { Minus, SquarePen, Sparkles, X } from \"lucide-react\";\nimport { type ComponentType, type ReactNode, useEffect, useRef } from \"react\";\n\nimport { Alert, AlertDescription } from \"../core/Alert.tsx\";\nimport { Button } from \"../core/Button.tsx\";\nimport { Spinner } from \"../core/Spinner.tsx\";\nimport {\n type MarkdownLinkRenderer,\n MarkdownView,\n} from \"../markdown/MarkdownView.tsx\";\nimport { AiChatComposer } from \"./AiChatComposer.tsx\";\nimport {\n AiChatConfirmCard,\n type AiChatConfirmCardProps,\n} from \"./AiChatConfirmCard.tsx\";\nimport { AiChatEmpty, type AiChatSuggestion } from \"./AiChatEmpty.tsx\";\nimport { AiChatHistory } from \"./AiChatHistory.tsx\";\nimport { AiChatMessage, type AiChatToolLabel } from \"./AiChatMessage.tsx\";\nimport type { UseAiChat } from \"./useAiChat.ts\";\n\n/**\n * What the conversation looks like, whatever holds it: the props `AiChat`\n * passes through to its panel.\n */\nexport interface AiChatViewProps {\n /**\n * The panel's title. Defaults to \"Assistant\".\n */\n title?: string;\n /**\n * The app's own controls in the panel's header, before the history menu:\n * a link to the assistant's help page, say.\n */\n headerActions?: ReactNode;\n /**\n * Offer the list of past conversations, in a header menu. Default true.\n */\n history?: boolean;\n /**\n * Questions a new conversation offers to start from.\n */\n suggestions?: AiChatSuggestion[];\n /**\n * Names each tool step in the user's words (\"Searched clients\"), running\n * and done. Without it a step shows the tool's own name.\n */\n toolLabel?: AiChatToolLabel;\n /**\n * A confirmation card per tool name, in place of the generic field list:\n * an app shows a booking as a booking. It gets the pending call as the\n * server stored it, and the approve and deny callbacks.\n */\n confirmCards?: Record<string, ComponentType<AiChatConfirmCardProps>>;\n /**\n * How links in the assistant's replies render (`MarkdownView`'s\n * `renderLink`): route the paths the app knows, leave the rest as text.\n */\n renderLink?: MarkdownLinkRenderer;\n}\n\nexport interface AiChatPanelProps extends AiChatViewProps {\n /**\n * The conversation to show, from `useAiChat()`.\n */\n chat: UseAiChat;\n onClose: () => void;\n /**\n * Fold the panel away without ending the conversation. Without it the\n * header has no minimize button.\n */\n onMinimize?: () => void;\n /**\n * Renders the title, so a shell can give it its own element (a drawer\n * names its dialog with it). Defaults to a heading.\n */\n renderTitle?: (title: string, className: string) => ReactNode;\n}\n\n/**\n * The conversation itself, with no container: a quiet header (history menu,\n * new conversation, minimize, close), the thread with its tool steps and a\n * confirmation card for every mutation the assistant wants to run, and the\n * composer. `AiChat` puts it in a drawer or in a dock; an app with its own\n * container renders it there, with the `useAiChat()` it owns.\n */\nexport const AiChatPanel = (props: AiChatPanelProps) => {\n const { tr } = useI18n();\n const { chat } = props;\n const thread = useRef<HTMLDivElement>(null);\n const busy = chat.loading && !chat.pending;\n const empty = chat.items.length === 0 && !chat.streaming && !busy;\n\n // Keep the newest line in view as the conversation grows.\n useEffect(() => {\n const node = thread.current;\n if (node) {\n node.scrollTop = node.scrollHeight;\n }\n }, [chat.items.length, chat.streaming, chat.activity, chat.pending]);\n\n const running = chat.activity\n ? (props.toolLabel?.(chat.activity, \"running\") ??\n tr(\"ai.chat.running\", {\n default: \"Running $1\",\n args: [chat.activity],\n }))\n : undefined;\n\n const Card = chat.pending\n ? (props.confirmCards?.[chat.pending.name] ?? AiChatConfirmCard)\n : undefined;\n\n const title = props.title ?? tr(\"ai.chat.title\", { default: \"Assistant\" });\n const titleClassName = \"flex-1 truncate text-base font-medium\";\n\n return (\n <div data-testid=\"ai-chat\" className=\"flex h-full min-h-0 w-full flex-col\">\n <div className=\"border-border flex items-center gap-2 border-b py-2.5 pr-2.5 pl-4\">\n <Sparkles className=\"text-primary size-4 shrink-0\" />\n {props.renderTitle ? (\n props.renderTitle(title, titleClassName)\n ) : (\n <h2 className={titleClassName}>{title}</h2>\n )}\n {props.headerActions}\n {props.history !== false && (\n <AiChatHistory\n current={chat.conversationId}\n disabled={chat.loading}\n onOpen={(id) => chat.open(id)}\n />\n )}\n <Button\n size=\"icon-sm\"\n variant=\"minimal\"\n disabled={chat.loading || empty}\n aria-label={tr(\"ai.chat.new\", { default: \"New conversation\" })}\n onClick={() => chat.open(undefined)}\n >\n <SquarePen className=\"size-4\" />\n </Button>\n {props.onMinimize && (\n <Button\n size=\"icon-sm\"\n variant=\"minimal\"\n aria-label={tr(\"ai.chat.minimize\", { default: \"Minimize\" })}\n onClick={props.onMinimize}\n >\n <Minus className=\"size-4\" />\n </Button>\n )}\n <Button\n size=\"icon-sm\"\n variant=\"minimal\"\n aria-label={tr(\"ai.chat.close\", { default: \"Close\" })}\n onClick={props.onClose}\n >\n <X className=\"size-4\" />\n </Button>\n </div>\n <div\n ref={thread}\n // `shrink-0` on every line: in a scrolling column a card (overflow\n // hidden, so no content minimum) would shrink to its border once\n // the thread outgrows the panel (#Q3174).\n className=\"flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-4 py-4 *:shrink-0\"\n >\n {empty ? (\n <AiChatEmpty\n suggestions={props.suggestions}\n disabled={chat.loading}\n onPick={(prompt) => chat.send(prompt)}\n />\n ) : (\n <>\n {chat.items.map((item, index) => (\n <AiChatMessage\n key={item.id}\n item={item}\n renderLink={props.renderLink}\n toolLabel={props.toolLabel}\n // Only where continuing still means \"this answer\": the last\n // line, with no turn running and no card waiting.\n onContinue={\n item.cut &&\n index === chat.items.length - 1 &&\n !chat.loading &&\n !chat.pending\n ? () =>\n void chat.send(\n tr(\"ai.chat.continueMessage\", {\n default: \"Continue\",\n }),\n )\n : undefined\n }\n />\n ))}\n {chat.streaming && (\n <div\n data-testid=\"ai-chat-streaming\"\n className=\"mr-4 self-start text-sm leading-relaxed\"\n >\n <MarkdownView\n content={chat.streaming}\n renderLink={props.renderLink}\n />\n </div>\n )}\n {running && (\n <div className=\"text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs\">\n <Spinner className=\"size-3.5\" />\n {running}\n </div>\n )}\n {busy && !running && !chat.streaming && (\n <div\n className=\"text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs\"\n aria-live=\"polite\"\n >\n <Spinner className=\"size-3.5\" />\n {tr(\"ai.chat.thinking\", { default: \"Thinking…\" })}\n </div>\n )}\n {chat.pending?.kind === \"confirm\" && Card && (\n <Card\n pending={chat.pending}\n loading={chat.loading}\n onApprove={() => chat.approve()}\n onDeny={() => chat.deny()}\n />\n )}\n </>\n )}\n {chat.error && (\n <Alert variant=\"destructive\" data-testid=\"ai-chat-error\">\n <AlertDescription>{chat.error}</AlertDescription>\n </Alert>\n )}\n </div>\n <div className=\"border-border border-t px-3 pt-3 pb-2.5\">\n <AiChatComposer\n busy={busy}\n waiting={chat.pending?.kind === \"confirm\"}\n onSend={(message) => chat.send(message)}\n onStop={() => chat.stop()}\n />\n </div>\n </div>\n );\n};\n"],"mappings":"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"}
|
package/dist/ai/index.d.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
|
*/
|
|
@@ -10,9 +10,13 @@ export * from "./AiChat.tsx";
|
|
|
10
10
|
export * from "./AiChatComposer.tsx";
|
|
11
11
|
export * from "./AiChatConfirmCard.tsx";
|
|
12
12
|
export * from "./AiChatConfirmFields.tsx";
|
|
13
|
+
export * from "./AiChatDock.tsx";
|
|
14
|
+
export * from "./AiChatDockSlot.tsx";
|
|
13
15
|
export * from "./AiChatEmpty.tsx";
|
|
14
16
|
export * from "./AiChatHistory.tsx";
|
|
17
|
+
export * from "./AiChatLauncher.tsx";
|
|
15
18
|
export * from "./AiChatMessage.tsx";
|
|
19
|
+
export * from "./AiChatPanel.tsx";
|
|
16
20
|
export * from "./aiChatMessageFormSchema.ts";
|
|
17
21
|
export * from "./aiContextAtom.ts";
|
|
18
22
|
export * from "./AiFormRegistry.ts";
|
package/dist/ai/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
|
package/dist/ai/index.js
CHANGED
|
@@ -2,12 +2,16 @@ import { AiChat } from "./AiChat.js";
|
|
|
2
2
|
import { AiChatComposer } from "./AiChatComposer.js";
|
|
3
3
|
import { AiChatConfirmCard } from "./AiChatConfirmCard.js";
|
|
4
4
|
import { AiChatConfirmFields } from "./AiChatConfirmFields.js";
|
|
5
|
+
import { AI_CHAT_DOCK_DEFAULT, AI_CHAT_DOCK_MAX, AI_CHAT_DOCK_MIN, AiChatDock } from "./AiChatDock.js";
|
|
6
|
+
import { AI_CHAT_DOCK_SLOT, AiChatDockSlot } from "./AiChatDockSlot.js";
|
|
5
7
|
import { AiChatEmpty } from "./AiChatEmpty.js";
|
|
6
8
|
import { AiChatHistory } from "./AiChatHistory.js";
|
|
9
|
+
import { AiChatLauncher } from "./AiChatLauncher.js";
|
|
7
10
|
import { AiChatMessage } from "./AiChatMessage.js";
|
|
11
|
+
import { AiChatPanel } from "./AiChatPanel.js";
|
|
8
12
|
import { aiChatMessageFormSchema } from "./aiChatMessageFormSchema.js";
|
|
9
13
|
import { aiContextAtom } from "./aiContextAtom.js";
|
|
10
14
|
import { AiFormRegistry } from "./AiFormRegistry.js";
|
|
11
15
|
import { useAiChat } from "./useAiChat.js";
|
|
12
16
|
import { useAiContext } from "./useAiContext.js";
|
|
13
|
-
export { AiChat, AiChatComposer, AiChatConfirmCard, AiChatConfirmFields, AiChatEmpty, AiChatHistory, AiChatMessage, AiFormRegistry, aiChatMessageFormSchema, aiContextAtom, useAiChat, useAiContext };
|
|
17
|
+
export { AI_CHAT_DOCK_DEFAULT, AI_CHAT_DOCK_MAX, AI_CHAT_DOCK_MIN, AI_CHAT_DOCK_SLOT, AiChat, AiChatComposer, AiChatConfirmCard, AiChatConfirmFields, AiChatDock, AiChatDockSlot, AiChatEmpty, AiChatHistory, AiChatLauncher, AiChatMessage, AiChatPanel, AiFormRegistry, aiChatMessageFormSchema, aiContextAtom, useAiChat, useAiContext };
|
package/dist/ai/useAiChat.d.ts
CHANGED
|
@@ -35,6 +35,12 @@ export interface UseAiChatOptions {
|
|
|
35
35
|
* what the assistant may have changed (`[["notes"]]`).
|
|
36
36
|
*/
|
|
37
37
|
invalidates?: unknown[][];
|
|
38
|
+
/**
|
|
39
|
+
* Called after a stream in which tools ran, with the names of those that
|
|
40
|
+
* succeeded, for what `invalidates` cannot reach: a page whose data its
|
|
41
|
+
* route loaders fill re-runs them (`router.invalidate()`) after a write.
|
|
42
|
+
*/
|
|
43
|
+
onToolsRan?: (names: string[]) => void;
|
|
38
44
|
/**
|
|
39
45
|
* The app's own client tools, by name, beside `navigate` and `fillForm`.
|
|
40
46
|
* The result goes back to the model.
|
|
@@ -58,6 +64,12 @@ export interface AiChatItem {
|
|
|
58
64
|
* model, a cancellation to the user.
|
|
59
65
|
*/
|
|
60
66
|
denied?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* An `assistant` line the model did not finish: the turn ended on its
|
|
69
|
+
* output limit (`reason: "length"`). Known for a reply streamed in this
|
|
70
|
+
* session only; a stored conversation does not keep it.
|
|
71
|
+
*/
|
|
72
|
+
cut?: boolean;
|
|
61
73
|
}
|
|
62
74
|
/**
|
|
63
75
|
* What {@link useAiChat} returns.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAiChat.d.ts","sourceRoot":"","sources":["../../src/ai/useAiChat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,qBAAqB,EAEtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,SAAS,EAKf,MAAM,cAAc,CAAC;AAOtB;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,SAAS,aAAa,gBAAgB,KAAQ,
|
|
1
|
+
{"version":3,"file":"useAiChat.d.ts","sourceRoot":"","sources":["../../src/ai/useAiChat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,qBAAqB,EAEtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,SAAS,EAKf,MAAM,cAAc,CAAC;AAOtB;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,SAAS,aAAa,gBAAgB,KAAQ,SA+S1D,CAAC;AAIF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC;IAC1B;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACvC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC;CAC3E;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACpD,OAAO,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACxC,IAAI,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACrC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD;;OAEG;IACH,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB"}
|
package/dist/ai/useAiChat.js
CHANGED
|
@@ -45,6 +45,20 @@ const useAiChat = (options = {}) => {
|
|
|
45
45
|
}]);
|
|
46
46
|
}, []);
|
|
47
47
|
/**
|
|
48
|
+
* The page context a turn carries: the route, and the innermost page's
|
|
49
|
+
* name and data. Sent on a chat and on every resume, since the server's
|
|
50
|
+
* `allow` reads it to decide what the assistant is offered.
|
|
51
|
+
*/
|
|
52
|
+
const pageContext = useCallback(() => {
|
|
53
|
+
const stack = alepha.store.get(aiContextAtom) ?? [];
|
|
54
|
+
const innermost = stack[stack.length - 1];
|
|
55
|
+
return {
|
|
56
|
+
route: router.pathname,
|
|
57
|
+
page: innermost?.page,
|
|
58
|
+
data: innermost?.data
|
|
59
|
+
};
|
|
60
|
+
}, [alepha, router]);
|
|
61
|
+
/**
|
|
48
62
|
* Run a client tool the turn paused on, and return its result. A failure
|
|
49
63
|
* is a result too: the model reads it and recovers.
|
|
50
64
|
*/
|
|
@@ -97,6 +111,7 @@ const useAiChat = (options = {}) => {
|
|
|
97
111
|
const consume = useCallback(async (first, signal) => {
|
|
98
112
|
let stream = first;
|
|
99
113
|
let ranTools = false;
|
|
114
|
+
const succeeded = [];
|
|
100
115
|
while (stream) {
|
|
101
116
|
let text = "";
|
|
102
117
|
let clientCall;
|
|
@@ -110,6 +125,7 @@ const useAiChat = (options = {}) => {
|
|
|
110
125
|
} else if (event.type === "tool_call") setActivity(event.name);
|
|
111
126
|
else if (event.type === "tool_result") {
|
|
112
127
|
ranTools = true;
|
|
128
|
+
if (!event.isError && event.name) succeeded.push(event.name);
|
|
113
129
|
setActivity(void 0);
|
|
114
130
|
push({
|
|
115
131
|
role: "tool",
|
|
@@ -131,10 +147,12 @@ const useAiChat = (options = {}) => {
|
|
|
131
147
|
kind: "client_tool"
|
|
132
148
|
};
|
|
133
149
|
else if (event.type === "error") setError(event.message ?? event.name ?? "The assistant failed");
|
|
134
|
-
|
|
150
|
+
const cut = event.type === "end" && event.reason === "length";
|
|
151
|
+
if (text && (event.type === "tool_call" || event.type === "end") || cut) {
|
|
135
152
|
push({
|
|
136
153
|
role: "assistant",
|
|
137
|
-
content: text
|
|
154
|
+
content: text,
|
|
155
|
+
...cut ? { cut } : {}
|
|
138
156
|
});
|
|
139
157
|
text = "";
|
|
140
158
|
setStreaming("");
|
|
@@ -144,6 +162,7 @@ const useAiChat = (options = {}) => {
|
|
|
144
162
|
stream = void 0;
|
|
145
163
|
if (ranTools) {
|
|
146
164
|
for (const key of options.invalidates ?? []) queries.invalidate(key);
|
|
165
|
+
if (succeeded.length) options.onToolsRan?.(succeeded.splice(0));
|
|
147
166
|
ranTools = false;
|
|
148
167
|
}
|
|
149
168
|
if (clientCall && idRef.current) {
|
|
@@ -152,7 +171,8 @@ const useAiChat = (options = {}) => {
|
|
|
152
171
|
params: { id: idRef.current },
|
|
153
172
|
body: {
|
|
154
173
|
callId: clientCall.callId,
|
|
155
|
-
result
|
|
174
|
+
result,
|
|
175
|
+
context: pageContext()
|
|
156
176
|
}
|
|
157
177
|
}, { request: { signal } });
|
|
158
178
|
}
|
|
@@ -162,7 +182,9 @@ const useAiChat = (options = {}) => {
|
|
|
162
182
|
push,
|
|
163
183
|
runClientTool,
|
|
164
184
|
queries,
|
|
165
|
-
options.invalidates
|
|
185
|
+
options.invalidates,
|
|
186
|
+
options.onToolsRan,
|
|
187
|
+
pageContext
|
|
166
188
|
]);
|
|
167
189
|
const send = useAction({
|
|
168
190
|
handler: async ({ signal }, message) => {
|
|
@@ -171,28 +193,21 @@ const useAiChat = (options = {}) => {
|
|
|
171
193
|
role: "user",
|
|
172
194
|
content: message
|
|
173
195
|
});
|
|
174
|
-
const stack = alepha.store.get(aiContextAtom) ?? [];
|
|
175
|
-
const innermost = stack[stack.length - 1];
|
|
176
196
|
const stream = await api.chat({ body: {
|
|
177
197
|
conversationId: idRef.current,
|
|
178
198
|
message,
|
|
179
199
|
assistant: options.assistant,
|
|
180
|
-
context:
|
|
181
|
-
route: router.pathname,
|
|
182
|
-
page: innermost?.page,
|
|
183
|
-
data: innermost?.data
|
|
184
|
-
}
|
|
200
|
+
context: pageContext()
|
|
185
201
|
} }, { request: { signal } });
|
|
186
202
|
await consume(stream, signal);
|
|
187
203
|
},
|
|
188
204
|
onError: (cause) => setError(cause.message)
|
|
189
205
|
}, [
|
|
190
206
|
api,
|
|
191
|
-
alepha,
|
|
192
207
|
consume,
|
|
193
208
|
options.assistant,
|
|
194
209
|
push,
|
|
195
|
-
|
|
210
|
+
pageContext
|
|
196
211
|
]);
|
|
197
212
|
const answer = useAction({
|
|
198
213
|
handler: async ({ signal }, decision) => {
|
|
@@ -205,7 +220,8 @@ const useAiChat = (options = {}) => {
|
|
|
205
220
|
params: { id: idRef.current },
|
|
206
221
|
body: {
|
|
207
222
|
callId,
|
|
208
|
-
decision
|
|
223
|
+
decision,
|
|
224
|
+
context: pageContext()
|
|
209
225
|
}
|
|
210
226
|
}, { request: { signal } });
|
|
211
227
|
await consume(stream, signal);
|
|
@@ -214,7 +230,8 @@ const useAiChat = (options = {}) => {
|
|
|
214
230
|
}, [
|
|
215
231
|
api,
|
|
216
232
|
consume,
|
|
217
|
-
pending
|
|
233
|
+
pending,
|
|
234
|
+
pageContext
|
|
218
235
|
]);
|
|
219
236
|
const open = useAction({
|
|
220
237
|
handler: async (_ctx, id) => {
|