@alepha/ui 0.39.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/admin/AdminJobExecutionSheet.d.ts.map +1 -1
- package/dist/admin/AdminJobExecutionSheet.js +7 -0
- package/dist/admin/AdminJobExecutionSheet.js.map +1 -1
- package/dist/admin/analytics/RequestDialog.js +1 -1
- package/dist/admin/analytics/RequestDialog.js.map +1 -1
- package/dist/ai/AiChat.d.ts +6 -3
- package/dist/ai/AiChat.d.ts.map +1 -1
- package/dist/ai/AiChat.js +34 -5
- package/dist/ai/AiChat.js.map +1 -1
- package/dist/ai/AiChatConfirmCard.d.ts.map +1 -1
- package/dist/ai/AiChatConfirmCard.js +5 -1
- package/dist/ai/AiChatConfirmCard.js.map +1 -1
- package/dist/ai/AiChatFloat.d.ts +14 -0
- package/dist/ai/AiChatFloat.d.ts.map +1 -0
- package/dist/ai/AiChatFloat.js +30 -0
- package/dist/ai/AiChatFloat.js.map +1 -0
- package/dist/ai/AiChatMessage.js +2 -2
- package/dist/ai/AiChatMessage.js.map +1 -1
- package/dist/ai/AiChatPanel.d.ts +19 -0
- package/dist/ai/AiChatPanel.d.ts.map +1 -1
- package/dist/ai/AiChatPanel.js +65 -19
- package/dist/ai/AiChatPanel.js.map +1 -1
- package/dist/ai/AiChatToolStepDetails.d.ts +14 -0
- package/dist/ai/AiChatToolStepDetails.d.ts.map +1 -0
- package/dist/ai/AiChatToolStepDetails.js +34 -0
- package/dist/ai/AiChatToolStepDetails.js.map +1 -0
- package/dist/ai/AiChatToolTrace.d.ts +50 -0
- package/dist/ai/AiChatToolTrace.d.ts.map +1 -0
- package/dist/ai/AiChatToolTrace.js +91 -0
- package/dist/ai/AiChatToolTrace.js.map +1 -0
- package/dist/ai/index.d.ts +4 -2
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +3 -1
- package/dist/core/Button.d.ts.map +1 -1
- package/dist/core/Button.js +17 -1
- package/dist/core/Button.js.map +1 -1
- package/dist/core/Dialog.d.ts.map +1 -1
- package/dist/core/Dialog.js +1 -1
- package/dist/core/Dialog.js.map +1 -1
- package/dist/core/TimeAgo.d.ts +3 -4
- package/dist/core/TimeAgo.d.ts.map +1 -1
- package/dist/core/TimeAgo.js +3 -4
- package/dist/core/TimeAgo.js.map +1 -1
- package/dist/i18n/en/index.d.ts +22 -0
- package/dist/i18n/en/index.d.ts.map +1 -0
- package/dist/i18n/en/index.js +1 -0
- package/dist/i18n/en/uiEn.d.ts +37 -0
- package/dist/i18n/en/uiEn.d.ts.map +1 -0
- package/dist/i18n/en/uiEn.js +1468 -0
- package/dist/i18n/en/uiEn.js.map +1 -0
- package/dist/i18n/fr/uiFr.d.ts +3 -2
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +7 -2
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/markdown/MarkdownView.d.ts +14 -0
- package/dist/markdown/MarkdownView.d.ts.map +1 -1
- package/dist/markdown/MarkdownView.js +16 -3
- package/dist/markdown/MarkdownView.js.map +1 -1
- package/dist/markdown/highlightLines.d.ts +27 -0
- package/dist/markdown/highlightLines.d.ts.map +1 -0
- package/dist/markdown/highlightLines.js +91 -0
- package/dist/markdown/highlightLines.js.map +1 -0
- package/dist/markdown/index.d.ts +5 -2
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +2 -1
- package/dist/shell/ButtonInbox.d.ts +8 -0
- package/dist/shell/ButtonInbox.d.ts.map +1 -1
- package/dist/shell/ButtonInbox.js +3 -1
- package/dist/shell/ButtonInbox.js.map +1 -1
- package/dist/shell/PlateLayout.d.ts.map +1 -1
- package/dist/shell/PlateLayout.js +2 -2
- package/dist/shell/PlateLayout.js.map +1 -1
- package/dist/sortable/index.d.ts +17 -0
- package/dist/sortable/index.d.ts.map +1 -0
- package/dist/sortable/index.js +4 -0
- package/dist/sortable/useSortableItem.d.ts +32 -0
- package/dist/sortable/useSortableItem.d.ts.map +1 -0
- package/dist/sortable/useSortableItem.js +35 -0
- package/dist/sortable/useSortableItem.js.map +1 -0
- package/dist/sortable/useSortableList.d.ts +85 -0
- package/dist/sortable/useSortableList.d.ts.map +1 -0
- package/dist/sortable/useSortableList.js +125 -0
- package/dist/sortable/useSortableList.js.map +1 -0
- package/dist/table/DataTable.d.ts.map +1 -1
- package/dist/table/DataTable.js +9 -6
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableRowActionGroupItem.d.ts +23 -0
- package/dist/table/DataTableRowActionGroupItem.d.ts.map +1 -0
- package/dist/table/DataTableRowActionGroupItem.js +38 -0
- package/dist/table/DataTableRowActionGroupItem.js.map +1 -0
- package/dist/table/DataTableRowActionItem.d.ts.map +1 -1
- package/dist/table/DataTableRowActionItem.js +15 -2
- package/dist/table/DataTableRowActionItem.js.map +1 -1
- package/dist/table/DataTableRowActionsInline.d.ts.map +1 -1
- package/dist/table/DataTableRowActionsInline.js +2 -1
- package/dist/table/DataTableRowActionsInline.js.map +1 -1
- package/dist/table/DataTableRowActionsMenu.d.ts +3 -2
- package/dist/table/DataTableRowActionsMenu.d.ts.map +1 -1
- package/dist/table/DataTableRowActionsMenu.js +12 -14
- package/dist/table/DataTableRowActionsMenu.js.map +1 -1
- package/dist/table/dataTableBaseProps.d.ts +16 -2
- package/dist/table/dataTableBaseProps.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.d.ts +53 -11
- package/dist/table/dataTablePersistence.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.js +66 -29
- package/dist/table/dataTablePersistence.js.map +1 -1
- package/dist/table/dataTableTypes.d.ts +20 -3
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/index.d.ts +8 -1
- 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 +4 -4
- package/dist/table/useDataTableColumns.js.map +1 -1
- package/dist/table/useDataTableData.d.ts.map +1 -1
- package/dist/table/useDataTableData.js +3 -3
- package/dist/table/useDataTableData.js.map +1 -1
- package/dist/table/useDataTableFilterForm.d.ts.map +1 -1
- package/dist/table/useDataTableFilterForm.js +6 -2
- package/dist/table/useDataTableFilterForm.js.map +1 -1
- package/dist/table/useDataTableFilterVisibility.d.ts +5 -0
- package/dist/table/useDataTableFilterVisibility.d.ts.map +1 -1
- package/dist/table/useDataTableFilterVisibility.js +16 -8
- package/dist/table/useDataTableFilterVisibility.js.map +1 -1
- package/dist/table/useDataTableRefresh.d.ts.map +1 -1
- package/dist/table/useDataTableRefresh.js +3 -2
- package/dist/table/useDataTableRefresh.js.map +1 -1
- package/dist/table/useDataTableSummary.d.ts +5 -0
- package/dist/table/useDataTableSummary.d.ts.map +1 -1
- package/dist/table/useDataTableSummary.js +6 -6
- package/dist/table/useDataTableSummary.js.map +1 -1
- package/docs/packages-alepha-ui-ai.md +3 -3
- package/docs/packages-alepha-ui-i18n-en.md +35 -0
- package/docs/packages-alepha-ui-markdown.md +3 -1
- package/docs/packages-alepha-ui-overview.md +4 -2
- package/docs/packages-alepha-ui-sortable.md +34 -0
- package/docs/packages-alepha-ui-table.md +7 -1
- package/package.json +21 -3
- package/src/admin/AdminJobExecutionSheet.tsx +9 -0
- package/src/admin/analytics/RequestDialog.tsx +1 -1
- package/src/ai/AiChat.tsx +44 -6
- package/src/ai/AiChatConfirmCard.tsx +7 -1
- package/src/ai/AiChatFloat.tsx +46 -0
- package/src/ai/AiChatMessage.tsx +2 -2
- package/src/ai/AiChatPanel.tsx +154 -47
- package/src/ai/AiChatToolStepDetails.tsx +42 -0
- package/src/ai/AiChatToolTrace.tsx +167 -0
- package/src/ai/__tests__/AiChat.browser.spec.tsx +270 -2
- package/src/ai/index.ts +4 -2
- package/src/core/Button.tsx +26 -1
- package/src/core/Dialog.tsx +6 -2
- package/src/core/TimeAgo.tsx +3 -4
- package/src/core/__tests__/Button.browser.spec.tsx +57 -0
- package/src/i18n/en/__tests__/uiEn.spec.ts +110 -0
- package/src/i18n/en/index.ts +22 -0
- package/src/i18n/en/uiEn.ts +1647 -0
- package/src/i18n/fr/uiFr.ts +7 -2
- package/src/markdown/MarkdownView.tsx +30 -1
- package/src/markdown/__tests__/highlightLines.spec.ts +45 -0
- package/src/markdown/highlightLines.ts +120 -0
- package/src/markdown/index.ts +14 -2
- package/src/shell/ButtonInbox.tsx +11 -1
- package/src/shell/PlateLayout.tsx +18 -9
- package/src/shell/__tests__/ButtonInbox.browser.spec.tsx +40 -0
- package/src/shell/__tests__/PlateLayout.browser.spec.tsx +19 -2
- package/src/sortable/__tests__/useSortableList.browser.spec.tsx +157 -0
- package/src/sortable/index.ts +22 -0
- package/src/sortable/useSortableItem.ts +65 -0
- package/src/sortable/useSortableList.ts +231 -0
- package/src/table/DataTable.tsx +8 -5
- package/src/table/DataTableRowActionGroupItem.tsx +75 -0
- package/src/table/DataTableRowActionItem.tsx +6 -0
- package/src/table/DataTableRowActionsInline.tsx +3 -1
- package/src/table/DataTableRowActionsMenu.tsx +33 -49
- package/src/table/__tests__/DataTablePersistenceStorage.browser.spec.tsx +204 -0
- package/src/table/__tests__/DataTableRowActionGroup.browser.spec.tsx +118 -1
- package/src/table/dataTableBaseProps.ts +16 -2
- package/src/table/dataTablePersistence.ts +118 -32
- package/src/table/dataTableTypes.ts +20 -3
- package/src/table/index.ts +14 -1
- package/src/table/useDataTableColumns.ts +9 -4
- package/src/table/useDataTableData.ts +8 -3
- package/src/table/useDataTableFilterForm.ts +6 -2
- package/src/table/useDataTableFilterVisibility.ts +20 -7
- package/src/table/useDataTableRefresh.ts +4 -2
- package/src/table/useDataTableSummary.ts +25 -8
package/dist/ai/AiChatPanel.js
CHANGED
|
@@ -7,8 +7,9 @@ import { AiChatConfirmCard } from "./AiChatConfirmCard.js";
|
|
|
7
7
|
import { AiChatEmpty } from "./AiChatEmpty.js";
|
|
8
8
|
import { AiChatHistory } from "./AiChatHistory.js";
|
|
9
9
|
import { AiChatMessage } from "./AiChatMessage.js";
|
|
10
|
+
import { AiChatToolTrace } from "./AiChatToolTrace.js";
|
|
10
11
|
import { useI18n } from "alepha/react/i18n";
|
|
11
|
-
import { Minus, Sparkles, SquarePen, X } from "lucide-react";
|
|
12
|
+
import { Maximize2, Minimize2, Minus, Sparkles, SquarePen, X } from "lucide-react";
|
|
12
13
|
import { useEffect, useRef } from "react";
|
|
13
14
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
14
15
|
// src/ai/AiChatPanel.tsx
|
|
@@ -34,13 +35,11 @@ const AiChatPanel = (props) => {
|
|
|
34
35
|
chat.activity,
|
|
35
36
|
chat.pending
|
|
36
37
|
]);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
args: [chat.activity]
|
|
40
|
-
}) : void 0;
|
|
38
|
+
const rows = groupToolRuns(chat.items, chat.activity);
|
|
39
|
+
const running = Boolean(chat.activity);
|
|
41
40
|
const Card = chat.pending ? props.confirmCards?.[chat.pending.name] ?? AiChatConfirmCard : void 0;
|
|
42
41
|
const title = props.title ?? tr("ai.chat.title", { default: "Assistant" });
|
|
43
|
-
const titleClassName = "
|
|
42
|
+
const titleClassName = "truncate text-base font-medium";
|
|
44
43
|
return /* @__PURE__ */ jsxs("div", {
|
|
45
44
|
"data-testid": "ai-chat",
|
|
46
45
|
className: "flex h-full min-h-0 w-full flex-col",
|
|
@@ -49,9 +48,16 @@ const AiChatPanel = (props) => {
|
|
|
49
48
|
className: "border-border flex h-14 shrink-0 items-center gap-2 border-b ps-4 pe-2.5",
|
|
50
49
|
children: [
|
|
51
50
|
/* @__PURE__ */ jsx(Sparkles, { className: "text-primary size-4 shrink-0" }),
|
|
52
|
-
|
|
53
|
-
className:
|
|
54
|
-
children: title
|
|
51
|
+
/* @__PURE__ */ jsxs("div", {
|
|
52
|
+
className: "flex min-w-0 flex-1 flex-col",
|
|
53
|
+
children: [props.renderTitle ? props.renderTitle(title, titleClassName) : /* @__PURE__ */ jsx("h2", {
|
|
54
|
+
className: titleClassName,
|
|
55
|
+
children: title
|
|
56
|
+
}), props.subtitle && /* @__PURE__ */ jsx("p", {
|
|
57
|
+
"data-testid": "ai-chat-subtitle",
|
|
58
|
+
className: "text-muted-foreground truncate text-xs leading-tight",
|
|
59
|
+
children: props.subtitle
|
|
60
|
+
})]
|
|
55
61
|
}),
|
|
56
62
|
props.headerActions,
|
|
57
63
|
props.history !== false && /* @__PURE__ */ jsx(AiChatHistory, {
|
|
@@ -74,6 +80,16 @@ const AiChatPanel = (props) => {
|
|
|
74
80
|
onClick: props.onMinimize,
|
|
75
81
|
children: /* @__PURE__ */ jsx(Minus, { className: "size-4" })
|
|
76
82
|
}),
|
|
83
|
+
props.onMaximize && /* @__PURE__ */ jsx(Button, {
|
|
84
|
+
size: "icon-sm",
|
|
85
|
+
variant: "minimal",
|
|
86
|
+
"data-testid": "ai-chat-maximize",
|
|
87
|
+
"aria-pressed": Boolean(props.maximized),
|
|
88
|
+
"aria-label": props.maximized ? tr("ai.chat.exitFullscreen", { default: "Exit full screen" }) : tr("ai.chat.fullscreen", { default: "Full screen" }),
|
|
89
|
+
title: props.maximized ? tr("ai.chat.exitFullscreen", { default: "Exit full screen" }) : tr("ai.chat.fullscreen", { default: "Full screen" }),
|
|
90
|
+
onClick: props.onMaximize,
|
|
91
|
+
children: props.maximized ? /* @__PURE__ */ jsx(Minimize2, { className: "size-4" }) : /* @__PURE__ */ jsx(Maximize2, { className: "size-4" })
|
|
92
|
+
}),
|
|
77
93
|
/* @__PURE__ */ jsx(Button, {
|
|
78
94
|
size: "icon-sm",
|
|
79
95
|
variant: "minimal",
|
|
@@ -85,30 +101,31 @@ const AiChatPanel = (props) => {
|
|
|
85
101
|
}),
|
|
86
102
|
/* @__PURE__ */ jsxs("div", {
|
|
87
103
|
ref: thread,
|
|
88
|
-
|
|
104
|
+
"data-testid": "ai-chat-thread",
|
|
105
|
+
className: "flex min-h-0 flex-1 flex-col gap-3 overflow-x-hidden overflow-y-auto px-4 py-4 *:shrink-0",
|
|
89
106
|
children: [empty ? /* @__PURE__ */ jsx(AiChatEmpty, {
|
|
90
107
|
suggestions: props.suggestions,
|
|
91
108
|
disabled: chat.loading,
|
|
92
109
|
onPick: (prompt) => chat.send(prompt)
|
|
93
110
|
}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
94
|
-
|
|
95
|
-
|
|
111
|
+
rows.map((row) => row.kind === "tools" ? /* @__PURE__ */ jsx(AiChatToolTrace, {
|
|
112
|
+
tools: row.tools,
|
|
113
|
+
label: props.toolLabel,
|
|
114
|
+
summary: props.toolSummary
|
|
115
|
+
}, row.key) : /* @__PURE__ */ jsx(AiChatMessage, {
|
|
116
|
+
item: row.item,
|
|
96
117
|
renderLink: props.renderLink,
|
|
97
118
|
toolLabel: props.toolLabel,
|
|
98
|
-
onContinue: item.cut &&
|
|
99
|
-
}, item.id)),
|
|
119
|
+
onContinue: row.item.cut && row.item === chat.items[chat.items.length - 1] && !chat.loading && !chat.pending ? () => void chat.send(tr("ai.chat.continueMessage", { default: "Continue" })) : void 0
|
|
120
|
+
}, row.item.id)),
|
|
100
121
|
chat.streaming && /* @__PURE__ */ jsx("div", {
|
|
101
122
|
"data-testid": "ai-chat-streaming",
|
|
102
|
-
className: "me-4 self-start text-sm leading-relaxed",
|
|
123
|
+
className: "me-4 max-w-[calc(100%-1rem)] min-w-0 self-start text-sm leading-relaxed break-words",
|
|
103
124
|
children: /* @__PURE__ */ jsx(MarkdownView, {
|
|
104
125
|
content: chat.streaming,
|
|
105
126
|
renderLink: props.renderLink
|
|
106
127
|
})
|
|
107
128
|
}),
|
|
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
129
|
busy && !running && !chat.streaming && /* @__PURE__ */ jsxs("div", {
|
|
113
130
|
className: "text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs",
|
|
114
131
|
"aria-live": "polite",
|
|
@@ -138,6 +155,35 @@ const AiChatPanel = (props) => {
|
|
|
138
155
|
]
|
|
139
156
|
});
|
|
140
157
|
};
|
|
158
|
+
/**
|
|
159
|
+
* The thread's lines, with each run of consecutive tool calls as one row.
|
|
160
|
+
* The call in flight (`activity`) joins the run it continues, or starts one.
|
|
161
|
+
*/
|
|
162
|
+
const groupToolRuns = (items, activity) => {
|
|
163
|
+
const rows = [];
|
|
164
|
+
const add = (key, step) => {
|
|
165
|
+
const last = rows[rows.length - 1];
|
|
166
|
+
if (last?.kind === "tools") last.tools.push(step);
|
|
167
|
+
else rows.push({
|
|
168
|
+
kind: "tools",
|
|
169
|
+
key,
|
|
170
|
+
tools: [step]
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
for (const item of items) if (item.role === "tool") add(item.id, {
|
|
174
|
+
name: item.name ?? "",
|
|
175
|
+
state: item.denied ? "denied" : item.isError ? "failed" : "done"
|
|
176
|
+
});
|
|
177
|
+
else rows.push({
|
|
178
|
+
kind: "message",
|
|
179
|
+
item
|
|
180
|
+
});
|
|
181
|
+
if (activity) add("running", {
|
|
182
|
+
name: activity,
|
|
183
|
+
state: "running"
|
|
184
|
+
});
|
|
185
|
+
return rows;
|
|
186
|
+
};
|
|
141
187
|
export { AiChatPanel };
|
|
142
188
|
|
|
143
189
|
//# sourceMappingURL=AiChatPanel.js.map
|
|
@@ -1 +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 {/* `h-14`, the height of `AppShell`'s header: docked beside a page, the\n two headers' bottom lines continue each other (#Q3584). */}\n <div className=\"border-border flex h-14 shrink-0 items-center gap-2 border-b ps-4 pe-2.5\">\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=\"me-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":";;;;;;;;;;;;;;;;;;;;;AAsFA,MAAa,eAAe,UAA4B;CACtD,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,EAAE,SAAS;CACjB,MAAM,SAAS,OAAuB,IAAI;CAC1C,MAAM,OAAO,KAAK,WAAW,CAAC,KAAK;CACnC,MAAM,QAAQ,KAAK,MAAM,WAAW,KAAK,CAAC,KAAK,aAAa,CAAC;CAG7D,gBAAgB;EACd,MAAM,OAAO,OAAO;EACpB,IAAI,MACF,KAAK,YAAY,KAAK;CAE1B,GAAG;EAAC,KAAK,MAAM;EAAQ,KAAK;EAAW,KAAK;EAAU,KAAK;CAAO,CAAC;CAEnE,MAAM,UAAU,KAAK,WAChB,MAAM,YAAY,KAAK,UAAU,SAAS,KAC3C,GAAG,mBAAmB;EACpB,SAAS;EACT,MAAM,CAAC,KAAK,QAAQ;CACtB,CAAC,IACD,KAAA;CAEJ,MAAM,OAAO,KAAK,UACb,MAAM,eAAe,KAAK,QAAQ,SAAS,oBAC5C,KAAA;CAEJ,MAAM,QAAQ,MAAM,SAAS,GAAG,iBAAiB,EAAE,SAAS,YAAY,CAAC;CACzE,MAAM,iBAAiB;CAEvB,OACE,qBAAC,OAAD;EAAK,eAAY;EAAU,WAAU;EAArC,UAAA;GAGE,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA;KACE,oBAAC,UAAD,EAAU,WAAU,+BAAgC,CAAA;KACnD,MAAM,cACL,MAAM,YAAY,OAAO,cAAc,IAEvC,oBAAC,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aACJ,oBAAC,OAAD;MACE,eAAY;MACZ,WAAU;MAEV,UAAA,oBAAC,cAAD;OACE,SAAS,KAAK;OACd,YAAY,MAAM;MACnB,CAAA;KACE,CAAA;KAEN,WACC,qBAAC,OAAD;MAAK,WAAU;MAAf,UAAA,CACE,oBAAC,SAAD,EAAS,WAAU,WAAY,CAAA,GAC9B,OACE;;KAEN,QAAQ,CAAC,WAAW,CAAC,KAAK,aACzB,qBAAC,OAAD;MACE,WAAU;MACV,aAAU;MAFZ,UAAA,CAIE,oBAAC,SAAD,EAAS,WAAU,WAAY,CAAA,GAC9B,GAAG,oBAAoB,EAAE,SAAS,YAAY,CAAC,CAC7C;;KAEN,KAAK,SAAS,SAAS,aAAa,QACnC,oBAAC,MAAD;MACE,SAAS,KAAK;MACd,SAAS,KAAK;MACd,iBAAiB,KAAK,QAAQ;MAC9B,cAAc,KAAK,KAAK;KACzB,CAAA;IAEH,EAAA,CAAA,GAEH,KAAK,SACJ,oBAAC,OAAD;KAAO,SAAQ;KAAc,eAAY;KACvC,UAAA,oBAAC,kBAAD,EAAA,UAAmB,KAAK,MAAwB,CAAA;IAC3C,CAAA,CAEN;;GACL,oBAAC,OAAD;IAAK,WAAU;IACb,UAAA,oBAAC,gBAAD;KACQ;KACN,SAAS,KAAK,SAAS,SAAS;KAChC,SAAS,YAAY,KAAK,KAAK,OAAO;KACtC,cAAc,KAAK,KAAK;IACzB,CAAA;GACE,CAAA;EACF;;AAET"}
|
|
1
|
+
{"version":3,"file":"AiChatPanel.js","names":[],"sources":["../../src/ai/AiChatPanel.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport {\n Maximize2,\n Minimize2,\n Minus,\n SquarePen,\n Sparkles,\n X,\n} 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 {\n type AiChatToolStep,\n type AiChatToolSummary,\n AiChatToolTrace,\n} from \"./AiChatToolTrace.tsx\";\nimport type { AiChatItem, 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 * A second line under the title, quieter: the model that answers, say.\n */\n subtitle?: 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 * The folded line over a run of tool calls (\"Read 2 quests, 1 folio\").\n * Without it, the line says how many tools ran.\n */\n toolSummary?: AiChatToolSummary;\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 * Toggle full screen, the way an image lightbox maximizes. Without it the\n * header has no full screen button.\n */\n onMaximize?: () => void;\n /**\n * The panel fills the screen: the button reads as the way back.\n */\n maximized?: boolean;\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 rows = groupToolRuns(chat.items, chat.activity);\n const running = Boolean(chat.activity);\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 = \"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 {/* `h-14`, the height of `AppShell`'s header: docked beside a page, the\n two headers' bottom lines continue each other (#Q3584). */}\n <div className=\"border-border flex h-14 shrink-0 items-center gap-2 border-b ps-4 pe-2.5\">\n <Sparkles className=\"text-primary size-4 shrink-0\" />\n <div className=\"flex min-w-0 flex-1 flex-col\">\n {props.renderTitle ? (\n props.renderTitle(title, titleClassName)\n ) : (\n <h2 className={titleClassName}>{title}</h2>\n )}\n {props.subtitle && (\n <p\n data-testid=\"ai-chat-subtitle\"\n className=\"text-muted-foreground truncate text-xs leading-tight\"\n >\n {props.subtitle}\n </p>\n )}\n </div>\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 {props.onMaximize && (\n <Button\n size=\"icon-sm\"\n variant=\"minimal\"\n data-testid=\"ai-chat-maximize\"\n aria-pressed={Boolean(props.maximized)}\n aria-label={\n props.maximized\n ? tr(\"ai.chat.exitFullscreen\", { default: \"Exit full screen\" })\n : tr(\"ai.chat.fullscreen\", { default: \"Full screen\" })\n }\n title={\n props.maximized\n ? tr(\"ai.chat.exitFullscreen\", { default: \"Exit full screen\" })\n : tr(\"ai.chat.fullscreen\", { default: \"Full screen\" })\n }\n onClick={props.onMaximize}\n >\n {props.maximized ? (\n <Minimize2 className=\"size-4\" />\n ) : (\n <Maximize2 className=\"size-4\" />\n )}\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 data-testid=\"ai-chat-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). `overflow-x-hidden`: a\n // line wider than the column scrolls inside itself, never the whole\n // thread sideways (#Q4546).\n className=\"flex min-h-0 flex-1 flex-col gap-3 overflow-x-hidden 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 {rows.map((row) =>\n row.kind === \"tools\" ? (\n <AiChatToolTrace\n key={row.key}\n tools={row.tools}\n label={props.toolLabel}\n summary={props.toolSummary}\n />\n ) : (\n <AiChatMessage\n key={row.item.id}\n item={row.item}\n renderLink={props.renderLink}\n toolLabel={props.toolLabel}\n // Only where continuing still means \"this answer\": the\n // last line, with no turn running and no card waiting.\n onContinue={\n row.item.cut &&\n row.item === chat.items[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 )}\n {chat.streaming && (\n <div\n data-testid=\"ai-chat-streaming\"\n className=\"me-4 max-w-[calc(100%-1rem)] min-w-0 self-start text-sm leading-relaxed break-words\"\n >\n <MarkdownView\n content={chat.streaming}\n renderLink={props.renderLink}\n />\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\n/**\n * One line of the thread: a message, or a run of consecutive tool calls\n * folded into one trace.\n */\ntype AiChatRow =\n | { kind: \"message\"; item: AiChatItem }\n | { kind: \"tools\"; key: string; tools: AiChatToolStep[] };\n\n/**\n * The thread's lines, with each run of consecutive tool calls as one row.\n * The call in flight (`activity`) joins the run it continues, or starts one.\n */\nconst groupToolRuns = (\n items: AiChatItem[],\n activity: string | undefined,\n): AiChatRow[] => {\n const rows: AiChatRow[] = [];\n const add = (key: string, step: AiChatToolStep) => {\n const last = rows[rows.length - 1];\n if (last?.kind === \"tools\") {\n last.tools.push(step);\n } else {\n rows.push({ kind: \"tools\", key, tools: [step] });\n }\n };\n for (const item of items) {\n if (item.role === \"tool\") {\n add(item.id, {\n name: item.name ?? \"\",\n state: item.denied ? \"denied\" : item.isError ? \"failed\" : \"done\",\n });\n } else {\n rows.push({ kind: \"message\", item });\n }\n }\n if (activity) {\n add(\"running\", { name: activity, state: \"running\" });\n }\n return rows;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoHA,MAAa,eAAe,UAA4B;CACtD,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,EAAE,SAAS;CACjB,MAAM,SAAS,OAAuB,IAAI;CAC1C,MAAM,OAAO,KAAK,WAAW,CAAC,KAAK;CACnC,MAAM,QAAQ,KAAK,MAAM,WAAW,KAAK,CAAC,KAAK,aAAa,CAAC;CAG7D,gBAAgB;EACd,MAAM,OAAO,OAAO;EACpB,IAAI,MACF,KAAK,YAAY,KAAK;CAE1B,GAAG;EAAC,KAAK,MAAM;EAAQ,KAAK;EAAW,KAAK;EAAU,KAAK;CAAO,CAAC;CAEnE,MAAM,OAAO,cAAc,KAAK,OAAO,KAAK,QAAQ;CACpD,MAAM,UAAU,QAAQ,KAAK,QAAQ;CAErC,MAAM,OAAO,KAAK,UACb,MAAM,eAAe,KAAK,QAAQ,SAAS,oBAC5C,KAAA;CAEJ,MAAM,QAAQ,MAAM,SAAS,G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
+
step: AiChatToolStep;
|
|
4
|
+
/**
|
|
5
|
+
* The step's words, shown when it has no `detail`.
|
|
6
|
+
*/
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A step that carries its input and result: its line opens on them, the
|
|
11
|
+
* result folded under it and marked when the call failed.
|
|
12
|
+
*/
|
|
13
|
+
export declare const AiChatToolStepDetails: (props: AiChatToolStepDetailsProps) => import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=AiChatToolStepDetails.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatToolStepDetails.d.ts","sourceRoot":"","sources":["../../src/ai/AiChatToolStepDetails.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,cAAc,CAAC;IACrB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,UAAW,0BAA0B,gCA0BtE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { cn } from "../core/utils.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
// src/ai/AiChatToolStepDetails.tsx
|
|
4
|
+
/**
|
|
5
|
+
* A step that carries its input and result: its line opens on them, the
|
|
6
|
+
* result folded under it and marked when the call failed.
|
|
7
|
+
*/
|
|
8
|
+
const AiChatToolStepDetails = (props) => /* @__PURE__ */ jsxs("details", {
|
|
9
|
+
className: "min-w-0 flex-1",
|
|
10
|
+
"data-testid": "ai-chat-tool-details",
|
|
11
|
+
children: [
|
|
12
|
+
/* @__PURE__ */ jsxs("summary", {
|
|
13
|
+
className: "flex cursor-pointer items-center gap-1.5",
|
|
14
|
+
children: [/* @__PURE__ */ jsx("code", {
|
|
15
|
+
className: "bg-muted rounded px-1 font-mono text-[10px]",
|
|
16
|
+
children: props.step.name
|
|
17
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
18
|
+
className: "min-w-0 truncate",
|
|
19
|
+
children: props.step.detail ?? props.label
|
|
20
|
+
})]
|
|
21
|
+
}),
|
|
22
|
+
props.step.input !== void 0 && /* @__PURE__ */ jsx("pre", {
|
|
23
|
+
className: "bg-muted mt-1 max-h-64 overflow-auto rounded p-2 font-mono text-[11px] break-words whitespace-pre-wrap",
|
|
24
|
+
children: props.step.input
|
|
25
|
+
}),
|
|
26
|
+
props.step.result !== void 0 && /* @__PURE__ */ jsx("pre", {
|
|
27
|
+
className: cn("bg-muted mt-1 max-h-64 overflow-auto rounded p-2 font-mono text-[11px] break-words whitespace-pre-wrap", props.step.state === "failed" && "text-danger-text"),
|
|
28
|
+
children: props.step.result
|
|
29
|
+
})
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
export { AiChatToolStepDetails };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=AiChatToolStepDetails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatToolStepDetails.js","names":[],"sources":["../../src/ai/AiChatToolStepDetails.tsx"],"sourcesContent":["import { cn } from \"../core/utils.ts\";\nimport type { AiChatToolStep } from \"./AiChatToolTrace.tsx\";\n\nexport interface AiChatToolStepDetailsProps {\n step: AiChatToolStep;\n /**\n * The step's words, shown when it has no `detail`.\n */\n label: string;\n}\n\n/**\n * A step that carries its input and result: its line opens on them, the\n * result folded under it and marked when the call failed.\n */\nexport const AiChatToolStepDetails = (props: AiChatToolStepDetailsProps) => (\n <details className=\"min-w-0 flex-1\" data-testid=\"ai-chat-tool-details\">\n <summary className=\"flex cursor-pointer items-center gap-1.5\">\n <code className=\"bg-muted rounded px-1 font-mono text-[10px]\">\n {props.step.name}\n </code>\n <span className=\"min-w-0 truncate\">\n {props.step.detail ?? props.label}\n </span>\n </summary>\n {props.step.input !== undefined && (\n <pre className=\"bg-muted mt-1 max-h-64 overflow-auto rounded p-2 font-mono text-[11px] break-words whitespace-pre-wrap\">\n {props.step.input}\n </pre>\n )}\n {props.step.result !== undefined && (\n <pre\n className={cn(\n \"bg-muted mt-1 max-h-64 overflow-auto rounded p-2 font-mono text-[11px] break-words whitespace-pre-wrap\",\n props.step.state === \"failed\" && \"text-danger-text\",\n )}\n >\n {props.step.result}\n </pre>\n )}\n </details>\n);\n"],"mappings":";;;;;;;AAeA,MAAa,yBAAyB,UACpC,qBAAC,WAAD;CAAS,WAAU;CAAiB,eAAY;CAAhD,UAAA;EACE,qBAAC,WAAD;GAAS,WAAU;GAAnB,UAAA,CACE,oBAAC,QAAD;IAAM,WAAU;IACb,UAAA,MAAM,KAAK;GACR,CAAA,GACN,oBAAC,QAAD;IAAM,WAAU;IACb,UAAA,MAAM,KAAK,UAAU,MAAM;GACxB,CAAA,CACC;;EACR,MAAM,KAAK,UAAU,KAAA,KACpB,oBAAC,OAAD;GAAK,WAAU;GACZ,UAAA,MAAM,KAAK;EACT,CAAA;EAEN,MAAM,KAAK,WAAW,KAAA,KACrB,oBAAC,OAAD;GACE,WAAW,GACT,0GACA,MAAM,KAAK,UAAU,YAAY,kBACnC;GAEC,UAAA,MAAM,KAAK;EACT,CAAA;CAEA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AiChatToolLabel } from "./AiChatMessage.tsx";
|
|
2
|
+
export interface AiChatToolTraceProps {
|
|
3
|
+
/**
|
|
4
|
+
* The calls of one run of tools, in order. A `running` one is the call in
|
|
5
|
+
* flight: while there is one, the line names it alone.
|
|
6
|
+
*/
|
|
7
|
+
tools: ReadonlyArray<AiChatToolStep>;
|
|
8
|
+
/**
|
|
9
|
+
* The words of one step, as `AiChat`'s `toolLabel`.
|
|
10
|
+
*/
|
|
11
|
+
label?: AiChatToolLabel;
|
|
12
|
+
/**
|
|
13
|
+
* The words of the folded line once nothing runs, such as "Read 2 quests,
|
|
14
|
+
* 1 folio". Return undefined to keep the default.
|
|
15
|
+
*/
|
|
16
|
+
summary?: AiChatToolSummary;
|
|
17
|
+
/**
|
|
18
|
+
* Open on mount: an agent job's transcript shows its calls unfolded.
|
|
19
|
+
*/
|
|
20
|
+
defaultOpen?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* One tool call of a run, as the trace shows it.
|
|
24
|
+
*/
|
|
25
|
+
export interface AiChatToolStep {
|
|
26
|
+
name: string;
|
|
27
|
+
state: "running" | "done" | "failed" | "denied";
|
|
28
|
+
/**
|
|
29
|
+
* The short of the call's input (a command, a path), shown beside its
|
|
30
|
+
* name. An agent job's transcript sets it; a chat answer has none.
|
|
31
|
+
*/
|
|
32
|
+
detail?: string;
|
|
33
|
+
/**
|
|
34
|
+
* The call's full input and its result: the step opens on them.
|
|
35
|
+
*/
|
|
36
|
+
input?: string;
|
|
37
|
+
result?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The folded line of a run of tool calls: `AiChat`'s `toolSummary`.
|
|
41
|
+
*/
|
|
42
|
+
export type AiChatToolSummary = (tools: ReadonlyArray<AiChatToolStep>) => string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* A run of tool calls as one line that opens on every step: "Used 4 tools",
|
|
45
|
+
* or the app's own summary. While a call runs, the line names that call
|
|
46
|
+
* only, with a spinner. The AI chat and Lore's chat rooms both draw their
|
|
47
|
+
* tool calls with it.
|
|
48
|
+
*/
|
|
49
|
+
export declare const AiChatToolTrace: (props: AiChatToolTraceProps) => import("react").JSX.Element | null;
|
|
50
|
+
//# sourceMappingURL=AiChatToolTrace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatToolTrace.d.ts","sourceRoot":"","sources":["../../src/ai/AiChatToolTrace.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,KAAK,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACrC;;OAEG;IACH,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAChD;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,KAAK,EAAE,aAAa,CAAC,cAAc,CAAC,KACjC,MAAM,GAAG,SAAS,CAAC;AAExB;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,oBAAoB,uCAyG1D,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Spinner } from "../core/Spinner.js";
|
|
2
|
+
import { cn } from "../core/utils.js";
|
|
3
|
+
import { AiChatToolStepDetails } from "./AiChatToolStepDetails.js";
|
|
4
|
+
import { useI18n } from "alepha/react/i18n";
|
|
5
|
+
import { Ban, Check, ChevronRight, Wrench, X } from "lucide-react";
|
|
6
|
+
import { useId, useState } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// src/ai/AiChatToolTrace.tsx
|
|
9
|
+
/**
|
|
10
|
+
* A run of tool calls as one line that opens on every step: "Used 4 tools",
|
|
11
|
+
* or the app's own summary. While a call runs, the line names that call
|
|
12
|
+
* only, with a spinner. The AI chat and Lore's chat rooms both draw their
|
|
13
|
+
* tool calls with it.
|
|
14
|
+
*/
|
|
15
|
+
const AiChatToolTrace = (props) => {
|
|
16
|
+
const { tr } = useI18n();
|
|
17
|
+
const [open, setOpen] = useState(props.defaultOpen ?? false);
|
|
18
|
+
const listId = useId();
|
|
19
|
+
if (props.tools.length === 0) return null;
|
|
20
|
+
const labelOf = (step) => props.label?.(step.name, step.state) ?? (step.state === "running" ? tr("ai.chat.running", {
|
|
21
|
+
default: "Running $1",
|
|
22
|
+
args: [step.name]
|
|
23
|
+
}) : step.state === "denied" ? tr("ai.chat.toolDenied", {
|
|
24
|
+
default: "$1 cancelled",
|
|
25
|
+
args: [step.name]
|
|
26
|
+
}) : step.state === "failed" ? tr("ai.chat.toolFailed", {
|
|
27
|
+
default: "$1 failed",
|
|
28
|
+
args: [step.name]
|
|
29
|
+
}) : tr("ai.chat.toolDone", {
|
|
30
|
+
default: "Ran $1",
|
|
31
|
+
args: [step.name]
|
|
32
|
+
}));
|
|
33
|
+
const running = props.tools.findLast((step) => step.state === "running");
|
|
34
|
+
const failed = props.tools.some((step) => step.state === "failed");
|
|
35
|
+
const line = running ? labelOf(running) : props.summary?.(props.tools) ?? (props.tools.length === 1 ? labelOf(props.tools[0]) : tr("ai.chat.toolsUsed", {
|
|
36
|
+
default: "Used $1 tools",
|
|
37
|
+
args: [String(props.tools.length)]
|
|
38
|
+
}));
|
|
39
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
40
|
+
"data-testid": "ai-chat-tool-trace",
|
|
41
|
+
className: "px-0.5",
|
|
42
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
43
|
+
type: "button",
|
|
44
|
+
"aria-expanded": open,
|
|
45
|
+
"aria-controls": listId,
|
|
46
|
+
onClick: () => setOpen((value) => !value),
|
|
47
|
+
className: cn("text-muted-foreground hover:text-foreground flex items-center gap-1.5 rounded text-start text-xs", failed && !running && "text-danger-text"),
|
|
48
|
+
children: [
|
|
49
|
+
running ? /* @__PURE__ */ jsx(Spinner, { className: "size-3.5 shrink-0" }) : /* @__PURE__ */ jsx(Wrench, {
|
|
50
|
+
className: "size-3.5 shrink-0",
|
|
51
|
+
"aria-hidden": "true"
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ jsx("span", {
|
|
54
|
+
"data-testid": "ai-chat-tool-trace-line",
|
|
55
|
+
children: line
|
|
56
|
+
}),
|
|
57
|
+
/* @__PURE__ */ jsx(ChevronRight, {
|
|
58
|
+
className: cn("size-3 shrink-0 transition-transform rtl:-scale-x-100", open && "rotate-90"),
|
|
59
|
+
"aria-hidden": "true"
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
}), open && /* @__PURE__ */ jsx("ol", {
|
|
63
|
+
id: listId,
|
|
64
|
+
"data-testid": "ai-chat-tool-trace-steps",
|
|
65
|
+
className: "text-muted-foreground ms-1.5 mt-1 mb-1 flex flex-col gap-0.5 border-s ps-3 text-xs",
|
|
66
|
+
children: props.tools.map((step, index) => /* @__PURE__ */ jsxs("li", {
|
|
67
|
+
"data-testid": "ai-chat-tool",
|
|
68
|
+
className: cn("flex items-center gap-1.5", step.state === "failed" && "text-danger-text"),
|
|
69
|
+
children: [step.state === "running" ? /* @__PURE__ */ jsx(Spinner, { className: "size-3 shrink-0" }) : step.state === "denied" ? /* @__PURE__ */ jsx(Ban, {
|
|
70
|
+
className: "size-3 shrink-0",
|
|
71
|
+
"aria-hidden": "true"
|
|
72
|
+
}) : step.state === "failed" ? /* @__PURE__ */ jsx(X, {
|
|
73
|
+
className: "size-3 shrink-0",
|
|
74
|
+
"aria-hidden": "true"
|
|
75
|
+
}) : /* @__PURE__ */ jsx(Check, {
|
|
76
|
+
className: "text-success-text size-3 shrink-0",
|
|
77
|
+
"aria-hidden": "true"
|
|
78
|
+
}), step.input !== void 0 || step.result !== void 0 ? /* @__PURE__ */ jsx(AiChatToolStepDetails, {
|
|
79
|
+
step,
|
|
80
|
+
label: labelOf(step)
|
|
81
|
+
}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", { children: labelOf(step) }), /* @__PURE__ */ jsx("code", {
|
|
82
|
+
className: "bg-muted rounded px-1 font-mono text-[10px]",
|
|
83
|
+
children: step.name
|
|
84
|
+
})] })]
|
|
85
|
+
}, `${step.name}-${index}`))
|
|
86
|
+
})]
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
export { AiChatToolTrace };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=AiChatToolTrace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatToolTrace.js","names":[],"sources":["../../src/ai/AiChatToolTrace.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { Ban, Check, ChevronRight, Wrench, X } from \"lucide-react\";\nimport { useId, useState } from \"react\";\n\nimport { Spinner } from \"../core/Spinner.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport type { AiChatToolLabel } from \"./AiChatMessage.tsx\";\nimport { AiChatToolStepDetails } from \"./AiChatToolStepDetails.tsx\";\n\nexport interface AiChatToolTraceProps {\n /**\n * The calls of one run of tools, in order. A `running` one is the call in\n * flight: while there is one, the line names it alone.\n */\n tools: ReadonlyArray<AiChatToolStep>;\n /**\n * The words of one step, as `AiChat`'s `toolLabel`.\n */\n label?: AiChatToolLabel;\n /**\n * The words of the folded line once nothing runs, such as \"Read 2 quests,\n * 1 folio\". Return undefined to keep the default.\n */\n summary?: AiChatToolSummary;\n /**\n * Open on mount: an agent job's transcript shows its calls unfolded.\n */\n defaultOpen?: boolean;\n}\n\n/**\n * One tool call of a run, as the trace shows it.\n */\nexport interface AiChatToolStep {\n name: string;\n state: \"running\" | \"done\" | \"failed\" | \"denied\";\n /**\n * The short of the call's input (a command, a path), shown beside its\n * name. An agent job's transcript sets it; a chat answer has none.\n */\n detail?: string;\n /**\n * The call's full input and its result: the step opens on them.\n */\n input?: string;\n result?: string;\n}\n\n/**\n * The folded line of a run of tool calls: `AiChat`'s `toolSummary`.\n */\nexport type AiChatToolSummary = (\n tools: ReadonlyArray<AiChatToolStep>,\n) => string | undefined;\n\n/**\n * A run of tool calls as one line that opens on every step: \"Used 4 tools\",\n * or the app's own summary. While a call runs, the line names that call\n * only, with a spinner. The AI chat and Lore's chat rooms both draw their\n * tool calls with it.\n */\nexport const AiChatToolTrace = (props: AiChatToolTraceProps) => {\n const { tr } = useI18n();\n const [open, setOpen] = useState(props.defaultOpen ?? false);\n const listId = useId();\n if (props.tools.length === 0) {\n return null;\n }\n\n const labelOf = (step: AiChatToolStep) =>\n props.label?.(step.name, step.state) ??\n (step.state === \"running\"\n ? tr(\"ai.chat.running\", { default: \"Running $1\", args: [step.name] })\n : step.state === \"denied\"\n ? tr(\"ai.chat.toolDenied\", {\n default: \"$1 cancelled\",\n args: [step.name],\n })\n : step.state === \"failed\"\n ? tr(\"ai.chat.toolFailed\", {\n default: \"$1 failed\",\n args: [step.name],\n })\n : tr(\"ai.chat.toolDone\", { default: \"Ran $1\", args: [step.name] }));\n\n const running = props.tools.findLast((step) => step.state === \"running\");\n const failed = props.tools.some((step) => step.state === \"failed\");\n const line = running\n ? labelOf(running)\n : (props.summary?.(props.tools) ??\n (props.tools.length === 1\n ? labelOf(props.tools[0])\n : tr(\"ai.chat.toolsUsed\", {\n default: \"Used $1 tools\",\n args: [String(props.tools.length)],\n })));\n\n return (\n <div data-testid=\"ai-chat-tool-trace\" className=\"px-0.5\">\n <button\n type=\"button\"\n aria-expanded={open}\n aria-controls={listId}\n onClick={() => setOpen((value) => !value)}\n className={cn(\n \"text-muted-foreground hover:text-foreground flex items-center gap-1.5 rounded text-start text-xs\",\n failed && !running && \"text-danger-text\",\n )}\n >\n {running ? (\n <Spinner className=\"size-3.5 shrink-0\" />\n ) : (\n <Wrench className=\"size-3.5 shrink-0\" aria-hidden=\"true\" />\n )}\n <span data-testid=\"ai-chat-tool-trace-line\">{line}</span>\n <ChevronRight\n className={cn(\n \"size-3 shrink-0 transition-transform rtl:-scale-x-100\",\n open && \"rotate-90\",\n )}\n aria-hidden=\"true\"\n />\n </button>\n {open && (\n <ol\n id={listId}\n data-testid=\"ai-chat-tool-trace-steps\"\n className=\"text-muted-foreground ms-1.5 mt-1 mb-1 flex flex-col gap-0.5 border-s ps-3 text-xs\"\n >\n {props.tools.map((step, index) => (\n <li\n key={`${step.name}-${index}`}\n data-testid=\"ai-chat-tool\"\n className={cn(\n \"flex items-center gap-1.5\",\n step.state === \"failed\" && \"text-danger-text\",\n )}\n >\n {step.state === \"running\" ? (\n <Spinner className=\"size-3 shrink-0\" />\n ) : step.state === \"denied\" ? (\n <Ban className=\"size-3 shrink-0\" aria-hidden=\"true\" />\n ) : step.state === \"failed\" ? (\n <X className=\"size-3 shrink-0\" aria-hidden=\"true\" />\n ) : (\n <Check\n className=\"text-success-text size-3 shrink-0\"\n aria-hidden=\"true\"\n />\n )}\n {step.input !== undefined || step.result !== undefined ? (\n <AiChatToolStepDetails step={step} label={labelOf(step)} />\n ) : (\n <>\n <span>{labelOf(step)}</span>\n <code className=\"bg-muted rounded px-1 font-mono text-[10px]\">\n {step.name}\n </code>\n </>\n )}\n </li>\n ))}\n </ol>\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;AA6DA,MAAa,mBAAmB,UAAgC;CAC9D,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,CAAC,MAAM,WAAW,SAAS,MAAM,eAAe,KAAK;CAC3D,MAAM,SAAS,MAAM;CACrB,IAAI,MAAM,MAAM,WAAW,GACzB,OAAO;CAGT,MAAM,WAAW,SACf,MAAM,QAAQ,KAAK,MAAM,KAAK,KAAK,MAClC,KAAK,UAAU,YACZ,GAAG,mBAAmB;EAAE,SAAS;EAAc,MAAM,CAAC,KAAK,IAAI;CAAE,CAAC,IAClE,KAAK,UAAU,WACb,GAAG,sBAAsB;EACvB,SAAS;EACT,MAAM,CAAC,KAAK,IAAI;CAClB,CAAC,IACD,KAAK,UAAU,WACb,GAAG,sBAAsB;EACvB,SAAS;EACT,MAAM,CAAC,KAAK,IAAI;CAClB,CAAC,IACD,GAAG,oBAAoB;EAAE,SAAS;EAAU,MAAM,CAAC,KAAK,IAAI;CAAE,CA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AU;KACV,eAAY;IACb,CAAA,GAEF,KAAK,UAAU,KAAA,KAAa,KAAK,WAAW,KAAA,IAC3C,oBAAC,uBAAD;KAA6B;KAAM,OAAO,QAAQ,IAAI;IAAI,CAAA,IAE1D,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,QAAD,EAAA,UAAO,QAAQ,IAAI,EAAQ,CAAA,GAC3B,oBAAC,QAAD;KAAM,WAAU;KACb,UAAA,KAAK;IACF,CAAA,CACN,EAAA,CAAA,CAEF;GA7BG,GAAA,GAAG,KAAK,KAAK,GAAG,OA6BnB,CACL;EACC,CAAA,CAEH;;AAET"}
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The in-app assistant on the client: a chat in a drawer
|
|
3
|
-
* the page, with streamed replies, history and a confirmation card per
|
|
2
|
+
* The in-app assistant on the client: a chat in a drawer, docked beside
|
|
3
|
+
* the page or floating over its corner, with streamed replies, history and a confirmation card per
|
|
4
4
|
* mutation, the headless `useAiChat`, and `useAiContext` for a page to
|
|
5
5
|
* declare what it shows. Talks to `alepha/api/ai`.
|
|
6
6
|
*
|
|
@@ -13,10 +13,12 @@ export * from "./AiChatConfirmFields.tsx";
|
|
|
13
13
|
export * from "./AiChatDock.tsx";
|
|
14
14
|
export * from "./AiChatDockSlot.tsx";
|
|
15
15
|
export * from "./AiChatEmpty.tsx";
|
|
16
|
+
export * from "./AiChatFloat.tsx";
|
|
16
17
|
export * from "./AiChatHistory.tsx";
|
|
17
18
|
export * from "./AiChatLauncher.tsx";
|
|
18
19
|
export * from "./AiChatMessage.tsx";
|
|
19
20
|
export * from "./AiChatPanel.tsx";
|
|
21
|
+
export * from "./AiChatToolTrace.tsx";
|
|
20
22
|
export * from "./aiChatMessageFormSchema.ts";
|
|
21
23
|
export * from "./aiContextAtom.ts";
|
|
22
24
|
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,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"}
|
|
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,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,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
|
@@ -5,13 +5,15 @@ import { AiChatConfirmFields } from "./AiChatConfirmFields.js";
|
|
|
5
5
|
import { AI_CHAT_DOCK_DEFAULT, AI_CHAT_DOCK_MAX, AI_CHAT_DOCK_MIN, AiChatDock } from "./AiChatDock.js";
|
|
6
6
|
import { AI_CHAT_DOCK_SLOT, AiChatDockSlot } from "./AiChatDockSlot.js";
|
|
7
7
|
import { AiChatEmpty } from "./AiChatEmpty.js";
|
|
8
|
+
import { AiChatFloat } from "./AiChatFloat.js";
|
|
8
9
|
import { AiChatHistory } from "./AiChatHistory.js";
|
|
9
10
|
import { AiChatLauncher } from "./AiChatLauncher.js";
|
|
10
11
|
import { AiChatMessage } from "./AiChatMessage.js";
|
|
11
12
|
import { AiChatPanel } from "./AiChatPanel.js";
|
|
13
|
+
import { AiChatToolTrace } from "./AiChatToolTrace.js";
|
|
12
14
|
import { aiChatMessageFormSchema } from "./aiChatMessageFormSchema.js";
|
|
13
15
|
import { aiContextAtom } from "./aiContextAtom.js";
|
|
14
16
|
import { AiFormRegistry } from "./AiFormRegistry.js";
|
|
15
17
|
import { useAiChat } from "./useAiChat.js";
|
|
16
18
|
import { useAiContext } from "./useAiContext.js";
|
|
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 };
|
|
19
|
+
export { AI_CHAT_DOCK_DEFAULT, AI_CHAT_DOCK_MAX, AI_CHAT_DOCK_MIN, AI_CHAT_DOCK_SLOT, AiChat, AiChatComposer, AiChatConfirmCard, AiChatConfirmFields, AiChatDock, AiChatDockSlot, AiChatEmpty, AiChatFloat, AiChatHistory, AiChatLauncher, AiChatMessage, AiChatPanel, AiChatToolTrace, AiFormRegistry, aiChatMessageFormSchema, aiContextAtom, useAiChat, useAiContext };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../src/core/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../src/core/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAiHlE,QAAA,MAAM,SAAS;;;;8EAuId,CAAC;AAEF,KAAK,cAAc,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;AAEnE,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEjE,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IAC/B;;;;OAIG;IACH,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,IAAI,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAaD,QAAA,MAAM,cAAc,WAAW,kBAAkB,WACwB,CAAC;AAE1E,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,WAAW,CAAC,GAChE,kBAAkB,GAAG;IACnB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAQJ,QAAA,MAAM,MAAM,UAAW,WAAW,gCAkEjC,CAAC;AAwBF,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/core/Button.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { textLinkUnderlineClassName } from "./TextLink.js";
|
|
2
2
|
import { cn } from "./utils.js";
|
|
3
3
|
import { Loader2Icon } from "lucide-react";
|
|
4
|
+
import { Children } from "react";
|
|
4
5
|
import { cva } from "class-variance-authority";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
import { Button as Button$1 } from "@base-ui/react/button";
|
|
@@ -196,10 +197,25 @@ const Button = (props) => {
|
|
|
196
197
|
})
|
|
197
198
|
}), /* @__PURE__ */ jsx("span", {
|
|
198
199
|
className: cn("contents", { "text-transparent [&_*]:opacity-0": loading }),
|
|
199
|
-
children
|
|
200
|
+
children: Children.count(children) > 1 ? Children.map(children, wrapLabelText) : children
|
|
200
201
|
})]
|
|
201
202
|
});
|
|
202
203
|
};
|
|
204
|
+
/**
|
|
205
|
+
* Gives a label that sits beside other children an element of its own.
|
|
206
|
+
*
|
|
207
|
+
* A page translator (Chrome's "Translate this page") replaces each text node
|
|
208
|
+
* it translates with `<font>` elements, while React keeps the original node.
|
|
209
|
+
* The next icon swap beside it, `{busy ? <Loader2 /> : <Paperclip />}`, calls
|
|
210
|
+
* `insertBefore(newIcon, textNode)` with a node that is no longer a child, and
|
|
211
|
+
* the whole tree throws `NotFoundError` (#Q4189). Inside a `<span>` the label
|
|
212
|
+
* is replaced in place and the span stays the reference node.
|
|
213
|
+
*
|
|
214
|
+
* A lone label is left bare: with no sibling there is no insert against it.
|
|
215
|
+
* Whitespace stays bare too, since a flex container ignores it and a span of
|
|
216
|
+
* it would add a gap.
|
|
217
|
+
*/
|
|
218
|
+
const wrapLabelText = (child) => typeof child === "string" && child.trim() !== "" || typeof child === "number" ? /* @__PURE__ */ jsx("span", { children: child }) : child;
|
|
203
219
|
export { Button, buttonVariants };
|
|
204
220
|
|
|
205
221
|
//# sourceMappingURL=Button.js.map
|