@dbx-tools/ui-mastra 0.9.181 → 0.9.184
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/index.react.ts +3 -2
- package/index.support.ts +1 -1
- package/index.ts +1 -1
- package/package.json +8 -7
- package/src/react/_assistant-activity.ts +2 -6
- package/src/react/_assistant-response-status.tsx +2 -2
- package/src/react/_external-link-dialog.tsx +11 -14
- package/src/react/bubbles.tsx +21 -9
- package/src/react/chat-composer.tsx +13 -18
- package/src/react/chat-feedback.ts +21 -5
- package/src/react/chat-stream.ts +3 -5
- package/src/react/chat-thread-layout.tsx +4 -1
- package/src/react/chat-transcript.tsx +345 -149
- package/src/react/chat-view.tsx +13 -4
- package/src/react/feedback-controls.tsx +32 -2
- package/src/react/markdown.tsx +18 -22
- package/src/react/mastra-chat.tsx +24 -12
- package/src/react/suggestion-pills.tsx +20 -8
- package/src/react/tool-pill.tsx +76 -59
- package/src/react/types.ts +4 -1
- package/src/react/use-composer-viewport-lock.ts +299 -0
- package/src/styles.css +12 -0
- package/src/support/mastra-client.ts +15 -8
- package/src/support/tool-events.ts +35 -7
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
cn,
|
|
14
14
|
} from "@databricks/appkit-ui/react";
|
|
15
15
|
import { MessageSquareTextIcon, ThumbsDownIcon, ThumbsUpIcon } from "lucide-react";
|
|
16
|
-
import { useState } from "react";
|
|
16
|
+
import { useRef, useState } from "react";
|
|
17
17
|
import type { FeedbackSubmission, FeedbackValue } from "./types.ts";
|
|
18
18
|
|
|
19
19
|
/** Render per-message rating controls and a dedicated written-feedback modal. */
|
|
@@ -34,6 +34,8 @@ export const FeedbackControls = ({
|
|
|
34
34
|
const [open, setOpen] = useState(false);
|
|
35
35
|
const [comment, setComment] = useState("");
|
|
36
36
|
const [sending, setSending] = useState(false);
|
|
37
|
+
const commentTriggerRef = useRef<HTMLButtonElement>(null);
|
|
38
|
+
const restoreTriggerFocusRef = useRef(false);
|
|
37
39
|
const genieRequest = request?.trim();
|
|
38
40
|
const canComment = mode === "mlflow" || Boolean(value && genieRequest);
|
|
39
41
|
|
|
@@ -102,12 +104,21 @@ export const FeedbackControls = ({
|
|
|
102
104
|
<TooltipTrigger asChild>
|
|
103
105
|
<DialogTrigger asChild disabled={!canComment}>
|
|
104
106
|
<Button
|
|
107
|
+
ref={commentTriggerRef}
|
|
105
108
|
type="button"
|
|
106
109
|
size="icon"
|
|
107
110
|
variant="ghost"
|
|
108
111
|
className="size-7"
|
|
109
112
|
aria-label={canComment ? "Leave written feedback" : "Rate the response first"}
|
|
110
113
|
disabled={!canComment}
|
|
114
|
+
onPointerDown={() => {
|
|
115
|
+
restoreTriggerFocusRef.current = false;
|
|
116
|
+
}}
|
|
117
|
+
onKeyDown={(event) => {
|
|
118
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
119
|
+
restoreTriggerFocusRef.current = true;
|
|
120
|
+
}
|
|
121
|
+
}}
|
|
111
122
|
>
|
|
112
123
|
<MessageSquareTextIcon className="size-3" />
|
|
113
124
|
</Button>
|
|
@@ -119,7 +130,26 @@ export const FeedbackControls = ({
|
|
|
119
130
|
</TooltipContent>
|
|
120
131
|
)}
|
|
121
132
|
</Tooltip>
|
|
122
|
-
<DialogContent
|
|
133
|
+
<DialogContent
|
|
134
|
+
className="max-h-[calc(100dvh-1rem)] w-[calc(100vw-1rem)] overflow-y-auto sm:max-w-md"
|
|
135
|
+
onPointerDownCapture={() => {
|
|
136
|
+
restoreTriggerFocusRef.current = false;
|
|
137
|
+
}}
|
|
138
|
+
onPointerDownOutside={() => {
|
|
139
|
+
restoreTriggerFocusRef.current = false;
|
|
140
|
+
}}
|
|
141
|
+
onKeyDownCapture={(event) => {
|
|
142
|
+
if (event.key === "Escape") restoreTriggerFocusRef.current = true;
|
|
143
|
+
}}
|
|
144
|
+
onCloseAutoFocus={(event) => {
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
requestAnimationFrame(() => {
|
|
147
|
+
if (restoreTriggerFocusRef.current) commentTriggerRef.current?.focus();
|
|
148
|
+
else commentTriggerRef.current?.blur();
|
|
149
|
+
restoreTriggerFocusRef.current = false;
|
|
150
|
+
});
|
|
151
|
+
}}
|
|
152
|
+
>
|
|
123
153
|
<DialogHeader>
|
|
124
154
|
<DialogTitle>Share feedback</DialogTitle>
|
|
125
155
|
</DialogHeader>
|
package/src/react/markdown.tsx
CHANGED
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
import { createShikiPlugin, highlightToHtml, useHighlightedHtml } from "@dbx-tools/ui/react";
|
|
17
17
|
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
18
18
|
import React, { useEffect, useRef, useState } from "react";
|
|
19
|
-
import { Streamdown } from "streamdown";
|
|
20
|
-
import { ExternalLinkDialog,
|
|
19
|
+
import { Streamdown, type LinkSafetyConfig } from "streamdown";
|
|
20
|
+
import { ExternalLinkDialog, isSameOriginLink } from "./_external-link-dialog.tsx";
|
|
21
21
|
import { DataGrid, TABLE_WRAPPER_CLASSES, colorizeDelta, type DataRow } from "./data-grid.tsx";
|
|
22
22
|
import { copyText } from "../support/clipboard.ts";
|
|
23
23
|
|
|
@@ -135,18 +135,14 @@ const MARKDOWN_TABLE_PARTS = {
|
|
|
135
135
|
},
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
-
/** Chat links
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
"visited:text-blue-800 dark:text-blue-300 dark:decoration-blue-300/40 dark:visited:text-blue-300 dark:hover:text-blue-200",
|
|
147
|
-
className,
|
|
148
|
-
)}
|
|
149
|
-
/>
|
|
138
|
+
/** Chat links keep Streamdown's safety behavior while using a higher-contrast blue. */
|
|
139
|
+
const MARKDOWN_LINK_CLASSES = cn(
|
|
140
|
+
"[&_[data-streamdown=link]]:font-normal [&_[data-streamdown=link]]:text-blue-700",
|
|
141
|
+
"[&_[data-streamdown=link]]:decoration-blue-700/40 [&_[data-streamdown=link]]:decoration-1 [&_[data-streamdown=link]]:underline-offset-2",
|
|
142
|
+
"[&_[data-streamdown=link]]:transition-colors [&_[data-streamdown=link]]:hover:text-blue-800 [&_[data-streamdown=link]]:hover:decoration-current",
|
|
143
|
+
"[&_[data-streamdown=link]]:focus-visible:rounded-sm [&_[data-streamdown=link]]:focus-visible:outline-none",
|
|
144
|
+
"[&_[data-streamdown=link]]:focus-visible:ring-2 [&_[data-streamdown=link]]:focus-visible:ring-ring [&_[data-streamdown=link]]:focus-visible:ring-offset-2",
|
|
145
|
+
"dark:[&_[data-streamdown=link]]:text-blue-300 dark:[&_[data-streamdown=link]]:decoration-blue-300/40 dark:[&_[data-streamdown=link]]:hover:text-blue-200",
|
|
150
146
|
);
|
|
151
147
|
|
|
152
148
|
/**
|
|
@@ -158,7 +154,6 @@ const MarkdownLink = ({ className, ...props }: React.AnchorHTMLAttributes<HTMLAn
|
|
|
158
154
|
*/
|
|
159
155
|
const MARKDOWN_COMPONENTS = {
|
|
160
156
|
...MARKDOWN_TABLE_PARTS,
|
|
161
|
-
a: MarkdownLink,
|
|
162
157
|
table: ({
|
|
163
158
|
node,
|
|
164
159
|
children,
|
|
@@ -201,7 +196,6 @@ const STREAMING_MARKDOWN_COMPONENTS = {
|
|
|
201
196
|
*/
|
|
202
197
|
const TOOL_MARKDOWN_COMPONENTS = {
|
|
203
198
|
...MARKDOWN_TABLE_PARTS,
|
|
204
|
-
a: MarkdownLink,
|
|
205
199
|
table: plainMarkdownTable,
|
|
206
200
|
};
|
|
207
201
|
|
|
@@ -214,13 +208,13 @@ const TOOL_MARKDOWN_COMPONENTS = {
|
|
|
214
208
|
const SHIKI_PLUGIN = { code: createShikiPlugin() };
|
|
215
209
|
|
|
216
210
|
/** Keep Streamdown's link confirmation while matching the chat's AppKit UI. */
|
|
217
|
-
const
|
|
211
|
+
export const CHAT_LINK_SAFETY = {
|
|
218
212
|
enabled: true,
|
|
219
|
-
onLinkCheck:
|
|
213
|
+
onLinkCheck: isSameOriginLink,
|
|
220
214
|
renderModal: (props: React.ComponentProps<typeof ExternalLinkDialog>) => (
|
|
221
215
|
<ExternalLinkDialog {...props} />
|
|
222
216
|
),
|
|
223
|
-
};
|
|
217
|
+
} satisfies LinkSafetyConfig;
|
|
224
218
|
|
|
225
219
|
/**
|
|
226
220
|
* Per-word fade-in applied while a reply is still streaming. Streamdown
|
|
@@ -274,7 +268,7 @@ export const AssistantMarkdown = ({
|
|
|
274
268
|
components={animate ? STREAMING_MARKDOWN_COMPONENTS : MARKDOWN_COMPONENTS}
|
|
275
269
|
plugins={SHIKI_PLUGIN}
|
|
276
270
|
controls={false}
|
|
277
|
-
linkSafety={
|
|
271
|
+
linkSafety={CHAT_LINK_SAFETY}
|
|
278
272
|
animated={animate ? ANIMATE_OPTIONS : false}
|
|
279
273
|
isAnimating={animate}
|
|
280
274
|
className={cn(
|
|
@@ -285,6 +279,7 @@ export const AssistantMarkdown = ({
|
|
|
285
279
|
"prose-h1:text-lg prose-h1:mt-4 prose-h1:mb-2",
|
|
286
280
|
"prose-h2:text-base prose-h2:mt-4 prose-h2:mb-2",
|
|
287
281
|
"prose-h3:text-sm prose-h3:mt-3 prose-h3:mb-1.5 prose-h3:text-muted-foreground prose-h3:uppercase prose-h3:tracking-wider",
|
|
282
|
+
MARKDOWN_LINK_CLASSES,
|
|
288
283
|
)}
|
|
289
284
|
>
|
|
290
285
|
{children}
|
|
@@ -309,7 +304,7 @@ export const ToolMarkdown = ({ children, className }: { children: string; classN
|
|
|
309
304
|
components={TOOL_MARKDOWN_COMPONENTS}
|
|
310
305
|
plugins={SHIKI_PLUGIN}
|
|
311
306
|
controls={false}
|
|
312
|
-
linkSafety={
|
|
307
|
+
linkSafety={CHAT_LINK_SAFETY}
|
|
313
308
|
className={cn(
|
|
314
309
|
"prose prose-sm dark:prose-invert min-w-0 max-w-full overflow-x-hidden break-words",
|
|
315
310
|
"!text-xs leading-tight text-muted-foreground sm:leading-snug",
|
|
@@ -318,7 +313,8 @@ export const ToolMarkdown = ({ children, className }: { children: string; classN
|
|
|
318
313
|
"prose-li:my-0 prose-li:leading-tight prose-li:marker:text-muted-foreground/60 [&_li]:!text-xs sm:prose-li:leading-snug",
|
|
319
314
|
"prose-headings:my-1 prose-headings:text-xs prose-headings:font-semibold",
|
|
320
315
|
"prose-strong:text-foreground/90 prose-strong:font-medium [&_strong]:!text-xs",
|
|
321
|
-
"prose-code:font-medium [&_code]:!text-xs [&
|
|
316
|
+
"prose-code:font-medium [&_code]:!text-xs [&_[data-streamdown=link]]:!text-xs",
|
|
317
|
+
MARKDOWN_LINK_CLASSES,
|
|
322
318
|
className,
|
|
323
319
|
)}
|
|
324
320
|
>
|
|
@@ -81,6 +81,7 @@ export type ThreadIdChangeReason = "hydrate" | "select" | "new" | "delete" | "mi
|
|
|
81
81
|
// preserving the visual scroll position across the prepend.
|
|
82
82
|
|
|
83
83
|
const logger = log.logger("ui-mastra/chat");
|
|
84
|
+
const STEER_INTERRUPT_SETTLEMENT_TIMEOUT_MS = 2_000;
|
|
84
85
|
|
|
85
86
|
const makeUserMessage = (text: string, files: FileUIPart[] = []): UIMessage => ({
|
|
86
87
|
id: hash.id(),
|
|
@@ -326,7 +327,7 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
326
327
|
const enableFeedback = options.enableFeedback !== false;
|
|
327
328
|
const feedbackModes = enableFeedback ? mastraClient.feedbackModes : [];
|
|
328
329
|
const feedbackAvailable = feedbackModes.length > 0;
|
|
329
|
-
const { url: mlflowExperimentUrl } = useMastraMlflowExperiment(
|
|
330
|
+
const { url: mlflowExperimentUrl, tracePrefix: mlflowTracePrefix } = useMastraMlflowExperiment(
|
|
330
331
|
feedbackModes.includes("mlflow"),
|
|
331
332
|
);
|
|
332
333
|
const [resourceScope, setResourceScope] = useState<string | null>(null);
|
|
@@ -662,6 +663,7 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
662
663
|
if (
|
|
663
664
|
controller.signal.aborted ||
|
|
664
665
|
getSession(threadId).runToken !== token ||
|
|
666
|
+
getSession(threadId).status === "error" ||
|
|
665
667
|
initialError instanceof MastraChatRequestError ||
|
|
666
668
|
!mastraClient.backgroundTurns ||
|
|
667
669
|
!runId
|
|
@@ -995,12 +997,24 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
995
997
|
if (!isSessionRunning(current)) return;
|
|
996
998
|
const streamThreadId = threadId === DEFAULT_THREAD_SESSION_KEY ? undefined : threadId;
|
|
997
999
|
const runId = current.runId;
|
|
1000
|
+
const settlementSignal = AbortSignal.timeout(STEER_INTERRUPT_SETTLEMENT_TIMEOUT_MS);
|
|
998
1001
|
const settlement =
|
|
999
1002
|
mastraClient.backgroundTurns && runId
|
|
1000
1003
|
? mastraClient
|
|
1001
|
-
.observeAgentStream({
|
|
1004
|
+
.observeAgentStream({
|
|
1005
|
+
agentId,
|
|
1006
|
+
runId,
|
|
1007
|
+
threadId: streamThreadId,
|
|
1008
|
+
signal: settlementSignal,
|
|
1009
|
+
})
|
|
1002
1010
|
.then((stream) => waitForTerminalChunk(stream.stream))
|
|
1003
1011
|
.catch((error: unknown) => {
|
|
1012
|
+
if (settlementSignal.aborted) {
|
|
1013
|
+
logger.warn("interrupted background run did not settle before replacement", {
|
|
1014
|
+
runId,
|
|
1015
|
+
});
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1004
1018
|
logger.warn("failed to observe interrupted background run", {
|
|
1005
1019
|
runId,
|
|
1006
1020
|
error: toError(error),
|
|
@@ -1101,10 +1115,10 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
1101
1115
|
[appendUserMessage, runStream, activeKey, getSession, updateSession],
|
|
1102
1116
|
);
|
|
1103
1117
|
|
|
1104
|
-
// Fire a queued steer immediately, out of order: remove it from the queue
|
|
1105
|
-
// append it
|
|
1106
|
-
// in-flight run (abort
|
|
1107
|
-
//
|
|
1118
|
+
// Fire a queued steer immediately, out of order: remove it from the queue
|
|
1119
|
+
// and append it first so acceptance is visible while the prior durable run
|
|
1120
|
+
// settles. `runStream`/`driveStream` then supersede the in-flight run (abort
|
|
1121
|
+
// + runToken bump + settle running pills) and send the chosen steer.
|
|
1108
1122
|
const sendSteerNow = useCallback(
|
|
1109
1123
|
(steerId: string) => {
|
|
1110
1124
|
const threadId = activeKey;
|
|
@@ -1116,14 +1130,11 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
1116
1130
|
queuedSteers: removeSteerFromQueue(session.queuedSteers, steerId),
|
|
1117
1131
|
}));
|
|
1118
1132
|
logger.info("steer:send-now", { threadId });
|
|
1133
|
+
const { message } = appendUserMessage(threadId, steer.text ?? "", steer.files);
|
|
1134
|
+
const replacementMessages = interruptedTurnMessages(current.messages, message);
|
|
1119
1135
|
void (async () => {
|
|
1120
1136
|
await interruptActiveRun(threadId);
|
|
1121
|
-
|
|
1122
|
-
void runStream(
|
|
1123
|
-
threadId,
|
|
1124
|
-
interruptedTurnMessages(current.messages, message),
|
|
1125
|
-
steer.requestContext,
|
|
1126
|
-
);
|
|
1137
|
+
void runStream(threadId, replacementMessages, steer.requestContext);
|
|
1127
1138
|
})();
|
|
1128
1139
|
},
|
|
1129
1140
|
[activeKey, appendUserMessage, getSession, interruptActiveRun, runStream, updateSession],
|
|
@@ -1555,6 +1566,7 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
1555
1566
|
feedbackByMessage: activeSession.feedbackByMessage,
|
|
1556
1567
|
onFeedback: submitFeedback,
|
|
1557
1568
|
...(mlflowExperimentUrl ? { mlflowExperimentUrl } : {}),
|
|
1569
|
+
...(mlflowTracePrefix ? { mlflowTracePrefix } : {}),
|
|
1558
1570
|
}
|
|
1559
1571
|
: {}),
|
|
1560
1572
|
};
|
|
@@ -17,32 +17,44 @@ export interface SuggestionPillsProps {
|
|
|
17
17
|
* arrived yet.
|
|
18
18
|
*/
|
|
19
19
|
disabled?: boolean;
|
|
20
|
+
/** Arrange suggestions in a horizontal row or vertical list. */
|
|
21
|
+
orientation?: "horizontal" | "vertical";
|
|
20
22
|
/** Extra classes for the wrapping flex row (layout / spacing). */
|
|
21
23
|
className?: string;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
/**
|
|
25
|
-
* Render a flex-wrapped row of suggestion pills. Pills grow vertically
|
|
26
|
-
* for long questions (`h-auto` + `whitespace-normal`) and keep a
|
|
27
|
-
* capsule shape that scales cleanly when text wraps to multiple lines.
|
|
28
|
-
* Disabled when no `onSelect` is provided, or when `disabled` is set.
|
|
29
|
-
*/
|
|
26
|
+
/** Render suggestion actions in the requested layout. */
|
|
30
27
|
export const SuggestionPills = ({
|
|
31
28
|
questions,
|
|
32
29
|
onSelect,
|
|
33
30
|
disabled = false,
|
|
31
|
+
orientation = "horizontal",
|
|
34
32
|
className,
|
|
35
33
|
}: SuggestionPillsProps) => {
|
|
36
34
|
if (questions.length === 0) return null;
|
|
37
35
|
return (
|
|
38
|
-
<div
|
|
36
|
+
<div
|
|
37
|
+
aria-label="Suggested questions"
|
|
38
|
+
className={cn(
|
|
39
|
+
"flex gap-1.5",
|
|
40
|
+
orientation === "horizontal"
|
|
41
|
+
? "touch-pan-x flex-nowrap overflow-x-auto overscroll-x-contain [scrollbar-width:none] md:flex-wrap md:overflow-x-visible [&::-webkit-scrollbar]:hidden"
|
|
42
|
+
: "flex-col",
|
|
43
|
+
className,
|
|
44
|
+
)}
|
|
45
|
+
>
|
|
39
46
|
{questions.map((q) => (
|
|
40
47
|
<Button
|
|
41
48
|
key={q}
|
|
42
49
|
type="button"
|
|
43
50
|
size="sm"
|
|
44
51
|
variant="outline"
|
|
45
|
-
className=
|
|
52
|
+
className={cn(
|
|
53
|
+
"h-auto shrink-0 whitespace-normal rounded-2xl px-3 py-1.5 text-left text-xs font-normal leading-snug",
|
|
54
|
+
orientation === "horizontal"
|
|
55
|
+
? "max-w-[min(20rem,85vw)] md:max-w-full"
|
|
56
|
+
: "w-full max-w-full justify-start",
|
|
57
|
+
)}
|
|
46
58
|
onClick={() => onSelect?.(q)}
|
|
47
59
|
disabled={disabled || !onSelect}
|
|
48
60
|
>
|
package/src/react/tool-pill.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import { parse, toLabel, capitalize } from "@dbx-tools/shared-core";
|
|
|
9
9
|
import { humanizeStatus } from "@dbx-tools/shared-genie";
|
|
10
10
|
import { detectCodeLanguage, JsonBlock, RecordPreview } from "@dbx-tools/ui/react";
|
|
11
11
|
import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react";
|
|
12
|
-
import { SourceBlock, ToolMarkdown } from "./markdown.tsx";
|
|
12
|
+
import { CHAT_LINK_SAFETY, SourceBlock, ToolMarkdown } from "./markdown.tsx";
|
|
13
13
|
import type { ToolEvent, ToolProgress } from "./types.ts";
|
|
14
14
|
|
|
15
15
|
// Consolidated tool-session pill and its Genie progress detail view:
|
|
@@ -298,7 +298,7 @@ const MessageGroupBody = ({
|
|
|
298
298
|
// opens directly to its SQL instead of adding a redundant
|
|
299
299
|
// second "SQL" pill around the only child.
|
|
300
300
|
<Collapsible key={bucket.key} className="rounded border border-border/60 bg-background/40">
|
|
301
|
-
<CollapsibleTrigger className="group flex w-full items-center gap-1.5
|
|
301
|
+
<CollapsibleTrigger className="group flex w-full items-center gap-1.5 py-1 pl-0 pr-1 text-left text-xs uppercase tracking-wide text-muted-foreground hover:text-foreground">
|
|
302
302
|
<ChevronDownIcon className="size-3 shrink-0 transition-transform group-data-[state=closed]:-rotate-90" />
|
|
303
303
|
<span>{queryBuckets.length > 1 ? `Query ${i + 1}` : "Query"}</span>
|
|
304
304
|
{bucket.query?.title ? (
|
|
@@ -412,13 +412,20 @@ const RawToolPayload = ({
|
|
|
412
412
|
<CollapsibleContent className="min-w-0 max-w-full overflow-hidden">
|
|
413
413
|
<div className="max-h-48 max-w-full overflow-auto overscroll-contain sm:max-h-64">
|
|
414
414
|
{structured === undefined ? (
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
415
|
+
typeof value === "string" ? (
|
|
416
|
+
<div className="px-2 py-1.5">
|
|
417
|
+
<ToolMarkdown>{value}</ToolMarkdown>
|
|
418
|
+
</div>
|
|
419
|
+
) : (
|
|
420
|
+
<JsonBlock
|
|
421
|
+
json={formatRawToolPayload(value)}
|
|
422
|
+
className="py-2 leading-tight text-foreground sm:leading-relaxed"
|
|
423
|
+
/>
|
|
424
|
+
)
|
|
419
425
|
) : (
|
|
420
426
|
<RecordPreview
|
|
421
427
|
value={structured}
|
|
428
|
+
linkSafety={CHAT_LINK_SAFETY}
|
|
422
429
|
className="max-w-full bg-transparent text-foreground [&_pre]:rounded-none [&_pre]:bg-transparent"
|
|
423
430
|
/>
|
|
424
431
|
)}
|
|
@@ -591,14 +598,18 @@ const WebSearchProgressDetails = ({ event }: { event: ToolEvent }) => {
|
|
|
591
598
|
};
|
|
592
599
|
|
|
593
600
|
/** Latest cumulative detail emitted by a non-search tool. */
|
|
594
|
-
const
|
|
595
|
-
if (event.toolName === "web_search") return
|
|
596
|
-
|
|
601
|
+
const toolStatusProgressDetail = (event: ToolEvent): string | undefined => {
|
|
602
|
+
if (event.toolName === "web_search") return undefined;
|
|
603
|
+
return [...(event.progress ?? [])]
|
|
597
604
|
.reverse()
|
|
598
605
|
.find(
|
|
599
606
|
(progress): progress is ToolStatusProgress =>
|
|
600
607
|
progress.type === "tool_status" && Boolean(progress.detail?.trim()),
|
|
601
608
|
)?.detail;
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
const ToolStatusProgressDetails = ({ event }: { event: ToolEvent }) => {
|
|
612
|
+
const detail = toolStatusProgressDetail(event);
|
|
602
613
|
if (!detail) return null;
|
|
603
614
|
return (
|
|
604
615
|
<SourceBlock
|
|
@@ -616,8 +627,10 @@ const ToolStatusProgressDetails = ({ event }: { event: ToolEvent }) => {
|
|
|
616
627
|
* a row whose only content is the question stays non-expandable.
|
|
617
628
|
*/
|
|
618
629
|
const hasExpandableDetails = (event: ToolEvent): boolean => {
|
|
619
|
-
if (event.
|
|
620
|
-
if (
|
|
630
|
+
if (!event.toolName.startsWith("ask_genie") && event.input !== undefined) return true;
|
|
631
|
+
if (event.output !== undefined) return true;
|
|
632
|
+
if (webSearchProgressGroups(event).length > 0) return true;
|
|
633
|
+
if (toolStatusProgressDetail(event)) return true;
|
|
621
634
|
const summary = summarizeProgress(event.progress ?? []);
|
|
622
635
|
return summary.groups.some(
|
|
623
636
|
(g) => g.attachments.some(isAttachmentRenderable) || g.errors.length > 0,
|
|
@@ -724,7 +737,7 @@ const ToolCallRow = ({ event }: { event: ToolEvent }) => {
|
|
|
724
737
|
return (
|
|
725
738
|
<Collapsible className="min-w-0 max-w-full overflow-hidden rounded border border-border/40 bg-background/30">
|
|
726
739
|
<CollapsibleTrigger className="group flex w-full items-start gap-2 px-2 py-1 text-left text-xs text-muted-foreground cursor-pointer hover:text-foreground">
|
|
727
|
-
<ChevronDownIcon className="mt-0.5 size-3 shrink-0 transition-transform group-data-[state=
|
|
740
|
+
<ChevronDownIcon className="mt-0.5 size-3 shrink-0 transition-transform group-data-[state=closed]:-rotate-90" />
|
|
728
741
|
<span className="mt-0.5 shrink-0">
|
|
729
742
|
<ToolStatusIcon status={event.status} />
|
|
730
743
|
</span>
|
|
@@ -774,6 +787,32 @@ export const ToolSessionPill = ({ events }: { events: ToolEvent[] }) => {
|
|
|
774
787
|
? `Calling ${latestName}`
|
|
775
788
|
: `Called ${latestName}`;
|
|
776
789
|
const countSuffix = events.length > 1 ? ` · ${events.length} calls` : "";
|
|
790
|
+
const expandable =
|
|
791
|
+
events.length > 1 || hasExpandableDetails(latest) || Boolean(askGenieQuestion(latest));
|
|
792
|
+
|
|
793
|
+
const header = (
|
|
794
|
+
<>
|
|
795
|
+
{expandable ? (
|
|
796
|
+
<ChevronDownIcon className="size-3 shrink-0 transition-transform group-data-[state=closed]:-rotate-90" />
|
|
797
|
+
) : null}
|
|
798
|
+
<ToolStatusIcon status={tone} />
|
|
799
|
+
<span
|
|
800
|
+
className={cn(
|
|
801
|
+
"min-w-0 flex-1 truncate",
|
|
802
|
+
tone === "running" && "animate-pulse text-foreground/90",
|
|
803
|
+
)}
|
|
804
|
+
>
|
|
805
|
+
{verb}
|
|
806
|
+
{countSuffix}
|
|
807
|
+
</span>
|
|
808
|
+
{tone === "running" && (
|
|
809
|
+
<span className="relative ml-1 flex size-2 shrink-0" aria-hidden>
|
|
810
|
+
<span className="absolute inline-flex size-full animate-ping rounded-full bg-primary/60" />
|
|
811
|
+
<span className="relative inline-flex size-2 rounded-full bg-primary" />
|
|
812
|
+
</span>
|
|
813
|
+
)}
|
|
814
|
+
</>
|
|
815
|
+
);
|
|
777
816
|
|
|
778
817
|
return (
|
|
779
818
|
<div
|
|
@@ -790,53 +829,31 @@ export const ToolSessionPill = ({ events }: { events: ToolEvent[] }) => {
|
|
|
790
829
|
: "border-border/40",
|
|
791
830
|
)}
|
|
792
831
|
>
|
|
793
|
-
|
|
794
|
-
<
|
|
795
|
-
<
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
</
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
{tone === "running" && (
|
|
819
|
-
<span className="relative ml-1 flex size-2 shrink-0" aria-hidden>
|
|
820
|
-
<span className="absolute inline-flex size-full animate-ping rounded-full bg-primary/60" />
|
|
821
|
-
<span className="relative inline-flex size-2 rounded-full bg-primary" />
|
|
822
|
-
</span>
|
|
823
|
-
)}
|
|
824
|
-
</CollapsibleTrigger>
|
|
825
|
-
<CollapsibleContent className="min-w-0 max-w-full overflow-hidden">
|
|
826
|
-
<div
|
|
827
|
-
className={cn(
|
|
828
|
-
"mt-1.5 min-w-0 max-w-full overflow-hidden",
|
|
829
|
-
events.length > 1 && "flex flex-col gap-1",
|
|
830
|
-
)}
|
|
831
|
-
>
|
|
832
|
-
{events.length === 1 ? (
|
|
833
|
-
<ToolCallDetails event={latest} showQuestion />
|
|
834
|
-
) : (
|
|
835
|
-
events.map((event) => <ToolCallRow key={event.id} event={event} />)
|
|
836
|
-
)}
|
|
837
|
-
</div>
|
|
838
|
-
</CollapsibleContent>
|
|
839
|
-
</Collapsible>
|
|
832
|
+
{expandable ? (
|
|
833
|
+
<Collapsible>
|
|
834
|
+
<CollapsibleTrigger className="group flex w-full cursor-pointer items-center gap-2 text-left text-xs text-muted-foreground hover:text-foreground">
|
|
835
|
+
{header}
|
|
836
|
+
</CollapsibleTrigger>
|
|
837
|
+
<CollapsibleContent className="min-w-0 max-w-full overflow-hidden">
|
|
838
|
+
<div
|
|
839
|
+
className={cn(
|
|
840
|
+
"mt-1.5 min-w-0 max-w-full overflow-hidden",
|
|
841
|
+
events.length > 1 && "flex flex-col gap-1",
|
|
842
|
+
)}
|
|
843
|
+
>
|
|
844
|
+
{events.length === 1 ? (
|
|
845
|
+
<ToolCallDetails event={latest} showQuestion />
|
|
846
|
+
) : (
|
|
847
|
+
events.map((event) => <ToolCallRow key={event.id} event={event} />)
|
|
848
|
+
)}
|
|
849
|
+
</div>
|
|
850
|
+
</CollapsibleContent>
|
|
851
|
+
</Collapsible>
|
|
852
|
+
) : (
|
|
853
|
+
<div className="flex w-full items-center gap-2 text-left text-xs text-muted-foreground">
|
|
854
|
+
{header}
|
|
855
|
+
</div>
|
|
856
|
+
)}
|
|
840
857
|
</div>
|
|
841
858
|
);
|
|
842
859
|
};
|
package/src/react/types.ts
CHANGED
|
@@ -69,6 +69,7 @@ export type ChatModelOption = Pick<
|
|
|
69
69
|
*/
|
|
70
70
|
export type ChatInputMessage = { text?: string; files?: FileUIPart[] };
|
|
71
71
|
|
|
72
|
+
/** Queued chat input with the stable identifier used for ordering and removal. */
|
|
72
73
|
export type QueuedSteer = ChatInputMessage & { id: string };
|
|
73
74
|
|
|
74
75
|
/** Thumbs reaction a user can leave on an assistant turn. */
|
|
@@ -390,9 +391,11 @@ export type ChatViewProps = {
|
|
|
390
391
|
onFeedback?: (message: UIMessage, submission: FeedbackSubmission) => void | Promise<void>;
|
|
391
392
|
/**
|
|
392
393
|
* Configured MLflow experiment URL for viewers with effective
|
|
393
|
-
* `
|
|
394
|
+
* `CAN_READ`. When present, assistant action rows show a debug link.
|
|
394
395
|
*/
|
|
395
396
|
mlflowExperimentUrl?: string;
|
|
397
|
+
/** Unity Catalog trace prefix used to open the exact trace in MLflow. */
|
|
398
|
+
mlflowTracePrefix?: string;
|
|
396
399
|
};
|
|
397
400
|
|
|
398
401
|
/** Payload {@link ChatViewProps.onResolveToolApproval} receives. */
|