@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/src/ai/AiChatPanel.tsx
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { useI18n } from "alepha/react/i18n";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Maximize2,
|
|
4
|
+
Minimize2,
|
|
5
|
+
Minus,
|
|
6
|
+
SquarePen,
|
|
7
|
+
Sparkles,
|
|
8
|
+
X,
|
|
9
|
+
} from "lucide-react";
|
|
3
10
|
import { type ComponentType, type ReactNode, useEffect, useRef } from "react";
|
|
4
11
|
|
|
5
12
|
import { Alert, AlertDescription } from "../core/Alert.tsx";
|
|
@@ -17,7 +24,12 @@ import {
|
|
|
17
24
|
import { AiChatEmpty, type AiChatSuggestion } from "./AiChatEmpty.tsx";
|
|
18
25
|
import { AiChatHistory } from "./AiChatHistory.tsx";
|
|
19
26
|
import { AiChatMessage, type AiChatToolLabel } from "./AiChatMessage.tsx";
|
|
20
|
-
import
|
|
27
|
+
import {
|
|
28
|
+
type AiChatToolStep,
|
|
29
|
+
type AiChatToolSummary,
|
|
30
|
+
AiChatToolTrace,
|
|
31
|
+
} from "./AiChatToolTrace.tsx";
|
|
32
|
+
import type { AiChatItem, UseAiChat } from "./useAiChat.ts";
|
|
21
33
|
|
|
22
34
|
/**
|
|
23
35
|
* What the conversation looks like, whatever holds it: the props `AiChat`
|
|
@@ -28,6 +40,10 @@ export interface AiChatViewProps {
|
|
|
28
40
|
* The panel's title. Defaults to "Assistant".
|
|
29
41
|
*/
|
|
30
42
|
title?: string;
|
|
43
|
+
/**
|
|
44
|
+
* A second line under the title, quieter: the model that answers, say.
|
|
45
|
+
*/
|
|
46
|
+
subtitle?: string;
|
|
31
47
|
/**
|
|
32
48
|
* The app's own controls in the panel's header, before the history menu:
|
|
33
49
|
* a link to the assistant's help page, say.
|
|
@@ -46,6 +62,11 @@ export interface AiChatViewProps {
|
|
|
46
62
|
* and done. Without it a step shows the tool's own name.
|
|
47
63
|
*/
|
|
48
64
|
toolLabel?: AiChatToolLabel;
|
|
65
|
+
/**
|
|
66
|
+
* The folded line over a run of tool calls ("Read 2 quests, 1 folio").
|
|
67
|
+
* Without it, the line says how many tools ran.
|
|
68
|
+
*/
|
|
69
|
+
toolSummary?: AiChatToolSummary;
|
|
49
70
|
/**
|
|
50
71
|
* A confirmation card per tool name, in place of the generic field list:
|
|
51
72
|
* an app shows a booking as a booking. It gets the pending call as the
|
|
@@ -70,6 +91,15 @@ export interface AiChatPanelProps extends AiChatViewProps {
|
|
|
70
91
|
* header has no minimize button.
|
|
71
92
|
*/
|
|
72
93
|
onMinimize?: () => void;
|
|
94
|
+
/**
|
|
95
|
+
* Toggle full screen, the way an image lightbox maximizes. Without it the
|
|
96
|
+
* header has no full screen button.
|
|
97
|
+
*/
|
|
98
|
+
onMaximize?: () => void;
|
|
99
|
+
/**
|
|
100
|
+
* The panel fills the screen: the button reads as the way back.
|
|
101
|
+
*/
|
|
102
|
+
maximized?: boolean;
|
|
73
103
|
/**
|
|
74
104
|
* Renders the title, so a shell can give it its own element (a drawer
|
|
75
105
|
* names its dialog with it). Defaults to a heading.
|
|
@@ -99,20 +129,15 @@ export const AiChatPanel = (props: AiChatPanelProps) => {
|
|
|
99
129
|
}
|
|
100
130
|
}, [chat.items.length, chat.streaming, chat.activity, chat.pending]);
|
|
101
131
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
tr("ai.chat.running", {
|
|
105
|
-
default: "Running $1",
|
|
106
|
-
args: [chat.activity],
|
|
107
|
-
}))
|
|
108
|
-
: undefined;
|
|
132
|
+
const rows = groupToolRuns(chat.items, chat.activity);
|
|
133
|
+
const running = Boolean(chat.activity);
|
|
109
134
|
|
|
110
135
|
const Card = chat.pending
|
|
111
136
|
? (props.confirmCards?.[chat.pending.name] ?? AiChatConfirmCard)
|
|
112
137
|
: undefined;
|
|
113
138
|
|
|
114
139
|
const title = props.title ?? tr("ai.chat.title", { default: "Assistant" });
|
|
115
|
-
const titleClassName = "
|
|
140
|
+
const titleClassName = "truncate text-base font-medium";
|
|
116
141
|
|
|
117
142
|
return (
|
|
118
143
|
<div data-testid="ai-chat" className="flex h-full min-h-0 w-full flex-col">
|
|
@@ -120,11 +145,21 @@ export const AiChatPanel = (props: AiChatPanelProps) => {
|
|
|
120
145
|
two headers' bottom lines continue each other (#Q3584). */}
|
|
121
146
|
<div className="border-border flex h-14 shrink-0 items-center gap-2 border-b ps-4 pe-2.5">
|
|
122
147
|
<Sparkles className="text-primary size-4 shrink-0" />
|
|
123
|
-
|
|
124
|
-
props.renderTitle(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
148
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
149
|
+
{props.renderTitle ? (
|
|
150
|
+
props.renderTitle(title, titleClassName)
|
|
151
|
+
) : (
|
|
152
|
+
<h2 className={titleClassName}>{title}</h2>
|
|
153
|
+
)}
|
|
154
|
+
{props.subtitle && (
|
|
155
|
+
<p
|
|
156
|
+
data-testid="ai-chat-subtitle"
|
|
157
|
+
className="text-muted-foreground truncate text-xs leading-tight"
|
|
158
|
+
>
|
|
159
|
+
{props.subtitle}
|
|
160
|
+
</p>
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
128
163
|
{props.headerActions}
|
|
129
164
|
{props.history !== false && (
|
|
130
165
|
<AiChatHistory
|
|
@@ -152,6 +187,31 @@ export const AiChatPanel = (props: AiChatPanelProps) => {
|
|
|
152
187
|
<Minus className="size-4" />
|
|
153
188
|
</Button>
|
|
154
189
|
)}
|
|
190
|
+
{props.onMaximize && (
|
|
191
|
+
<Button
|
|
192
|
+
size="icon-sm"
|
|
193
|
+
variant="minimal"
|
|
194
|
+
data-testid="ai-chat-maximize"
|
|
195
|
+
aria-pressed={Boolean(props.maximized)}
|
|
196
|
+
aria-label={
|
|
197
|
+
props.maximized
|
|
198
|
+
? tr("ai.chat.exitFullscreen", { default: "Exit full screen" })
|
|
199
|
+
: tr("ai.chat.fullscreen", { default: "Full screen" })
|
|
200
|
+
}
|
|
201
|
+
title={
|
|
202
|
+
props.maximized
|
|
203
|
+
? tr("ai.chat.exitFullscreen", { default: "Exit full screen" })
|
|
204
|
+
: tr("ai.chat.fullscreen", { default: "Full screen" })
|
|
205
|
+
}
|
|
206
|
+
onClick={props.onMaximize}
|
|
207
|
+
>
|
|
208
|
+
{props.maximized ? (
|
|
209
|
+
<Minimize2 className="size-4" />
|
|
210
|
+
) : (
|
|
211
|
+
<Maximize2 className="size-4" />
|
|
212
|
+
)}
|
|
213
|
+
</Button>
|
|
214
|
+
)}
|
|
155
215
|
<Button
|
|
156
216
|
size="icon-sm"
|
|
157
217
|
variant="minimal"
|
|
@@ -163,10 +223,13 @@ export const AiChatPanel = (props: AiChatPanelProps) => {
|
|
|
163
223
|
</div>
|
|
164
224
|
<div
|
|
165
225
|
ref={thread}
|
|
226
|
+
data-testid="ai-chat-thread"
|
|
166
227
|
// `shrink-0` on every line: in a scrolling column a card (overflow
|
|
167
228
|
// hidden, so no content minimum) would shrink to its border once
|
|
168
|
-
// the thread outgrows the panel (#Q3174).
|
|
169
|
-
|
|
229
|
+
// the thread outgrows the panel (#Q3174). `overflow-x-hidden`: a
|
|
230
|
+
// line wider than the column scrolls inside itself, never the whole
|
|
231
|
+
// thread sideways (#Q4546).
|
|
232
|
+
className="flex min-h-0 flex-1 flex-col gap-3 overflow-x-hidden overflow-y-auto px-4 py-4 *:shrink-0"
|
|
170
233
|
>
|
|
171
234
|
{empty ? (
|
|
172
235
|
<AiChatEmpty
|
|
@@ -176,33 +239,42 @@ export const AiChatPanel = (props: AiChatPanelProps) => {
|
|
|
176
239
|
/>
|
|
177
240
|
) : (
|
|
178
241
|
<>
|
|
179
|
-
{
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
242
|
+
{rows.map((row) =>
|
|
243
|
+
row.kind === "tools" ? (
|
|
244
|
+
<AiChatToolTrace
|
|
245
|
+
key={row.key}
|
|
246
|
+
tools={row.tools}
|
|
247
|
+
label={props.toolLabel}
|
|
248
|
+
summary={props.toolSummary}
|
|
249
|
+
/>
|
|
250
|
+
) : (
|
|
251
|
+
<AiChatMessage
|
|
252
|
+
key={row.item.id}
|
|
253
|
+
item={row.item}
|
|
254
|
+
renderLink={props.renderLink}
|
|
255
|
+
toolLabel={props.toolLabel}
|
|
256
|
+
// Only where continuing still means "this answer": the
|
|
257
|
+
// last line, with no turn running and no card waiting.
|
|
258
|
+
onContinue={
|
|
259
|
+
row.item.cut &&
|
|
260
|
+
row.item === chat.items[chat.items.length - 1] &&
|
|
261
|
+
!chat.loading &&
|
|
262
|
+
!chat.pending
|
|
263
|
+
? () =>
|
|
264
|
+
void chat.send(
|
|
265
|
+
tr("ai.chat.continueMessage", {
|
|
266
|
+
default: "Continue",
|
|
267
|
+
}),
|
|
268
|
+
)
|
|
269
|
+
: undefined
|
|
270
|
+
}
|
|
271
|
+
/>
|
|
272
|
+
),
|
|
273
|
+
)}
|
|
202
274
|
{chat.streaming && (
|
|
203
275
|
<div
|
|
204
276
|
data-testid="ai-chat-streaming"
|
|
205
|
-
className="me-4 self-start text-sm leading-relaxed"
|
|
277
|
+
className="me-4 max-w-[calc(100%-1rem)] min-w-0 self-start text-sm leading-relaxed break-words"
|
|
206
278
|
>
|
|
207
279
|
<MarkdownView
|
|
208
280
|
content={chat.streaming}
|
|
@@ -210,12 +282,6 @@ export const AiChatPanel = (props: AiChatPanelProps) => {
|
|
|
210
282
|
/>
|
|
211
283
|
</div>
|
|
212
284
|
)}
|
|
213
|
-
{running && (
|
|
214
|
-
<div className="text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs">
|
|
215
|
-
<Spinner className="size-3.5" />
|
|
216
|
-
{running}
|
|
217
|
-
</div>
|
|
218
|
-
)}
|
|
219
285
|
{busy && !running && !chat.streaming && (
|
|
220
286
|
<div
|
|
221
287
|
className="text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs"
|
|
@@ -252,3 +318,44 @@ export const AiChatPanel = (props: AiChatPanelProps) => {
|
|
|
252
318
|
</div>
|
|
253
319
|
);
|
|
254
320
|
};
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* One line of the thread: a message, or a run of consecutive tool calls
|
|
324
|
+
* folded into one trace.
|
|
325
|
+
*/
|
|
326
|
+
type AiChatRow =
|
|
327
|
+
| { kind: "message"; item: AiChatItem }
|
|
328
|
+
| { kind: "tools"; key: string; tools: AiChatToolStep[] };
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* The thread's lines, with each run of consecutive tool calls as one row.
|
|
332
|
+
* The call in flight (`activity`) joins the run it continues, or starts one.
|
|
333
|
+
*/
|
|
334
|
+
const groupToolRuns = (
|
|
335
|
+
items: AiChatItem[],
|
|
336
|
+
activity: string | undefined,
|
|
337
|
+
): AiChatRow[] => {
|
|
338
|
+
const rows: AiChatRow[] = [];
|
|
339
|
+
const add = (key: string, step: AiChatToolStep) => {
|
|
340
|
+
const last = rows[rows.length - 1];
|
|
341
|
+
if (last?.kind === "tools") {
|
|
342
|
+
last.tools.push(step);
|
|
343
|
+
} else {
|
|
344
|
+
rows.push({ kind: "tools", key, tools: [step] });
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
for (const item of items) {
|
|
348
|
+
if (item.role === "tool") {
|
|
349
|
+
add(item.id, {
|
|
350
|
+
name: item.name ?? "",
|
|
351
|
+
state: item.denied ? "denied" : item.isError ? "failed" : "done",
|
|
352
|
+
});
|
|
353
|
+
} else {
|
|
354
|
+
rows.push({ kind: "message", item });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (activity) {
|
|
358
|
+
add("running", { name: activity, state: "running" });
|
|
359
|
+
}
|
|
360
|
+
return rows;
|
|
361
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { cn } from "../core/utils.ts";
|
|
2
|
+
import type { AiChatToolStep } from "./AiChatToolTrace.tsx";
|
|
3
|
+
|
|
4
|
+
export interface AiChatToolStepDetailsProps {
|
|
5
|
+
step: AiChatToolStep;
|
|
6
|
+
/**
|
|
7
|
+
* The step's words, shown when it has no `detail`.
|
|
8
|
+
*/
|
|
9
|
+
label: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A step that carries its input and result: its line opens on them, the
|
|
14
|
+
* result folded under it and marked when the call failed.
|
|
15
|
+
*/
|
|
16
|
+
export const AiChatToolStepDetails = (props: AiChatToolStepDetailsProps) => (
|
|
17
|
+
<details className="min-w-0 flex-1" data-testid="ai-chat-tool-details">
|
|
18
|
+
<summary className="flex cursor-pointer items-center gap-1.5">
|
|
19
|
+
<code className="bg-muted rounded px-1 font-mono text-[10px]">
|
|
20
|
+
{props.step.name}
|
|
21
|
+
</code>
|
|
22
|
+
<span className="min-w-0 truncate">
|
|
23
|
+
{props.step.detail ?? props.label}
|
|
24
|
+
</span>
|
|
25
|
+
</summary>
|
|
26
|
+
{props.step.input !== undefined && (
|
|
27
|
+
<pre className="bg-muted mt-1 max-h-64 overflow-auto rounded p-2 font-mono text-[11px] break-words whitespace-pre-wrap">
|
|
28
|
+
{props.step.input}
|
|
29
|
+
</pre>
|
|
30
|
+
)}
|
|
31
|
+
{props.step.result !== undefined && (
|
|
32
|
+
<pre
|
|
33
|
+
className={cn(
|
|
34
|
+
"bg-muted mt-1 max-h-64 overflow-auto rounded p-2 font-mono text-[11px] break-words whitespace-pre-wrap",
|
|
35
|
+
props.step.state === "failed" && "text-danger-text",
|
|
36
|
+
)}
|
|
37
|
+
>
|
|
38
|
+
{props.step.result}
|
|
39
|
+
</pre>
|
|
40
|
+
)}
|
|
41
|
+
</details>
|
|
42
|
+
);
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { useI18n } from "alepha/react/i18n";
|
|
2
|
+
import { Ban, Check, ChevronRight, Wrench, X } from "lucide-react";
|
|
3
|
+
import { useId, useState } from "react";
|
|
4
|
+
|
|
5
|
+
import { Spinner } from "../core/Spinner.tsx";
|
|
6
|
+
import { cn } from "../core/utils.ts";
|
|
7
|
+
import type { AiChatToolLabel } from "./AiChatMessage.tsx";
|
|
8
|
+
import { AiChatToolStepDetails } from "./AiChatToolStepDetails.tsx";
|
|
9
|
+
|
|
10
|
+
export interface AiChatToolTraceProps {
|
|
11
|
+
/**
|
|
12
|
+
* The calls of one run of tools, in order. A `running` one is the call in
|
|
13
|
+
* flight: while there is one, the line names it alone.
|
|
14
|
+
*/
|
|
15
|
+
tools: ReadonlyArray<AiChatToolStep>;
|
|
16
|
+
/**
|
|
17
|
+
* The words of one step, as `AiChat`'s `toolLabel`.
|
|
18
|
+
*/
|
|
19
|
+
label?: AiChatToolLabel;
|
|
20
|
+
/**
|
|
21
|
+
* The words of the folded line once nothing runs, such as "Read 2 quests,
|
|
22
|
+
* 1 folio". Return undefined to keep the default.
|
|
23
|
+
*/
|
|
24
|
+
summary?: AiChatToolSummary;
|
|
25
|
+
/**
|
|
26
|
+
* Open on mount: an agent job's transcript shows its calls unfolded.
|
|
27
|
+
*/
|
|
28
|
+
defaultOpen?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* One tool call of a run, as the trace shows it.
|
|
33
|
+
*/
|
|
34
|
+
export interface AiChatToolStep {
|
|
35
|
+
name: string;
|
|
36
|
+
state: "running" | "done" | "failed" | "denied";
|
|
37
|
+
/**
|
|
38
|
+
* The short of the call's input (a command, a path), shown beside its
|
|
39
|
+
* name. An agent job's transcript sets it; a chat answer has none.
|
|
40
|
+
*/
|
|
41
|
+
detail?: string;
|
|
42
|
+
/**
|
|
43
|
+
* The call's full input and its result: the step opens on them.
|
|
44
|
+
*/
|
|
45
|
+
input?: string;
|
|
46
|
+
result?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The folded line of a run of tool calls: `AiChat`'s `toolSummary`.
|
|
51
|
+
*/
|
|
52
|
+
export type AiChatToolSummary = (
|
|
53
|
+
tools: ReadonlyArray<AiChatToolStep>,
|
|
54
|
+
) => string | undefined;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A run of tool calls as one line that opens on every step: "Used 4 tools",
|
|
58
|
+
* or the app's own summary. While a call runs, the line names that call
|
|
59
|
+
* only, with a spinner. The AI chat and Lore's chat rooms both draw their
|
|
60
|
+
* tool calls with it.
|
|
61
|
+
*/
|
|
62
|
+
export const AiChatToolTrace = (props: AiChatToolTraceProps) => {
|
|
63
|
+
const { tr } = useI18n();
|
|
64
|
+
const [open, setOpen] = useState(props.defaultOpen ?? false);
|
|
65
|
+
const listId = useId();
|
|
66
|
+
if (props.tools.length === 0) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const labelOf = (step: AiChatToolStep) =>
|
|
71
|
+
props.label?.(step.name, step.state) ??
|
|
72
|
+
(step.state === "running"
|
|
73
|
+
? tr("ai.chat.running", { default: "Running $1", args: [step.name] })
|
|
74
|
+
: step.state === "denied"
|
|
75
|
+
? tr("ai.chat.toolDenied", {
|
|
76
|
+
default: "$1 cancelled",
|
|
77
|
+
args: [step.name],
|
|
78
|
+
})
|
|
79
|
+
: step.state === "failed"
|
|
80
|
+
? tr("ai.chat.toolFailed", {
|
|
81
|
+
default: "$1 failed",
|
|
82
|
+
args: [step.name],
|
|
83
|
+
})
|
|
84
|
+
: tr("ai.chat.toolDone", { default: "Ran $1", args: [step.name] }));
|
|
85
|
+
|
|
86
|
+
const running = props.tools.findLast((step) => step.state === "running");
|
|
87
|
+
const failed = props.tools.some((step) => step.state === "failed");
|
|
88
|
+
const line = running
|
|
89
|
+
? labelOf(running)
|
|
90
|
+
: (props.summary?.(props.tools) ??
|
|
91
|
+
(props.tools.length === 1
|
|
92
|
+
? labelOf(props.tools[0])
|
|
93
|
+
: tr("ai.chat.toolsUsed", {
|
|
94
|
+
default: "Used $1 tools",
|
|
95
|
+
args: [String(props.tools.length)],
|
|
96
|
+
})));
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div data-testid="ai-chat-tool-trace" className="px-0.5">
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
aria-expanded={open}
|
|
103
|
+
aria-controls={listId}
|
|
104
|
+
onClick={() => setOpen((value) => !value)}
|
|
105
|
+
className={cn(
|
|
106
|
+
"text-muted-foreground hover:text-foreground flex items-center gap-1.5 rounded text-start text-xs",
|
|
107
|
+
failed && !running && "text-danger-text",
|
|
108
|
+
)}
|
|
109
|
+
>
|
|
110
|
+
{running ? (
|
|
111
|
+
<Spinner className="size-3.5 shrink-0" />
|
|
112
|
+
) : (
|
|
113
|
+
<Wrench className="size-3.5 shrink-0" aria-hidden="true" />
|
|
114
|
+
)}
|
|
115
|
+
<span data-testid="ai-chat-tool-trace-line">{line}</span>
|
|
116
|
+
<ChevronRight
|
|
117
|
+
className={cn(
|
|
118
|
+
"size-3 shrink-0 transition-transform rtl:-scale-x-100",
|
|
119
|
+
open && "rotate-90",
|
|
120
|
+
)}
|
|
121
|
+
aria-hidden="true"
|
|
122
|
+
/>
|
|
123
|
+
</button>
|
|
124
|
+
{open && (
|
|
125
|
+
<ol
|
|
126
|
+
id={listId}
|
|
127
|
+
data-testid="ai-chat-tool-trace-steps"
|
|
128
|
+
className="text-muted-foreground ms-1.5 mt-1 mb-1 flex flex-col gap-0.5 border-s ps-3 text-xs"
|
|
129
|
+
>
|
|
130
|
+
{props.tools.map((step, index) => (
|
|
131
|
+
<li
|
|
132
|
+
key={`${step.name}-${index}`}
|
|
133
|
+
data-testid="ai-chat-tool"
|
|
134
|
+
className={cn(
|
|
135
|
+
"flex items-center gap-1.5",
|
|
136
|
+
step.state === "failed" && "text-danger-text",
|
|
137
|
+
)}
|
|
138
|
+
>
|
|
139
|
+
{step.state === "running" ? (
|
|
140
|
+
<Spinner className="size-3 shrink-0" />
|
|
141
|
+
) : step.state === "denied" ? (
|
|
142
|
+
<Ban className="size-3 shrink-0" aria-hidden="true" />
|
|
143
|
+
) : step.state === "failed" ? (
|
|
144
|
+
<X className="size-3 shrink-0" aria-hidden="true" />
|
|
145
|
+
) : (
|
|
146
|
+
<Check
|
|
147
|
+
className="text-success-text size-3 shrink-0"
|
|
148
|
+
aria-hidden="true"
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
151
|
+
{step.input !== undefined || step.result !== undefined ? (
|
|
152
|
+
<AiChatToolStepDetails step={step} label={labelOf(step)} />
|
|
153
|
+
) : (
|
|
154
|
+
<>
|
|
155
|
+
<span>{labelOf(step)}</span>
|
|
156
|
+
<code className="bg-muted rounded px-1 font-mono text-[10px]">
|
|
157
|
+
{step.name}
|
|
158
|
+
</code>
|
|
159
|
+
</>
|
|
160
|
+
)}
|
|
161
|
+
</li>
|
|
162
|
+
))}
|
|
163
|
+
</ol>
|
|
164
|
+
)}
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
};
|