-
Notifications
You must be signed in to change notification settings - Fork 966
Chat UI rehaul + animation #1693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
11b09ed
Update shimmer
Kitenite f16f1c1
Animate
Kitenite 77012ca
Refactor
Kitenite 44246ba
Refactor more
Kitenite 27cfe7b
Styles
Kitenite 85152cc
Tool styling
Kitenite 12c269f
More tools
Kitenite dcec605
bash tool
Kitenite b9437f2
Animate collapse
Kitenite b2ca005
style
Kitenite 761d8b4
CI
Kitenite a02f263
Fix
Kitenite 593e3e7
Fix animating
Kitenite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...atInterface/components/MastraToolCallBlock/components/GenericToolCall/GenericToolCall.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { | ||
| Tool, | ||
| ToolContent, | ||
| ToolHeader, | ||
| ToolInput, | ||
| ToolOutput, | ||
| } from "@superset/ui/ai-elements/tool"; | ||
| import type { ToolPart } from "../../../../utils/tool-helpers"; | ||
| import { getGenericToolCallState } from "./getGenericToolCallState"; | ||
|
|
||
| type GenericToolCallProps = { | ||
| part: ToolPart; | ||
| toolName: string; | ||
| }; | ||
|
|
||
| export function GenericToolCall({ part, toolName }: GenericToolCallProps) { | ||
| const { output, isError, displayState, errorText } = | ||
| getGenericToolCallState(part); | ||
|
|
||
| return ( | ||
| <Tool> | ||
| <ToolHeader title={toolName} state={displayState} /> | ||
| <ToolContent> | ||
| {part.input != null && <ToolInput input={part.input} />} | ||
| {(output != null || isError) && ( | ||
| <ToolOutput | ||
| output={!isError ? output : undefined} | ||
| errorText={isError ? errorText : undefined} | ||
| /> | ||
| )} | ||
| </ToolContent> | ||
| </Tool> | ||
| ); | ||
| } |
57 changes: 57 additions & 0 deletions
57
...face/components/MastraToolCallBlock/components/GenericToolCall/getGenericToolCallState.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import type { ToolDisplayState } from "@superset/ui/ai-elements/tool"; | ||
| import type { ToolPart } from "../../../../utils/tool-helpers"; | ||
| import { toToolDisplayState } from "../../../../utils/tool-helpers"; | ||
|
|
||
| export type GenericToolCallState = { | ||
| output: unknown; | ||
| isError: boolean; | ||
| displayState: ToolDisplayState; | ||
| errorText?: string; | ||
| }; | ||
|
|
||
| function stringifyValue(value: unknown): string { | ||
| try { | ||
| return JSON.stringify(value); | ||
| } catch { | ||
| return String(value); | ||
| } | ||
| } | ||
|
|
||
| export function getGenericToolCallState(part: ToolPart): GenericToolCallState { | ||
| const output = | ||
| "output" in part ? (part as { output: unknown }).output : undefined; | ||
| const outputObject = | ||
| output != null && typeof output === "object" | ||
| ? (output as Record<string, unknown>) | ||
| : undefined; | ||
| const outputError = outputObject?.error; | ||
| const isOutputError = | ||
| outputObject != null && "error" in outputObject && Boolean(outputError); | ||
| const isError = part.state === "output-error" || isOutputError; | ||
|
|
||
| const baseDisplayState = toToolDisplayState(part); | ||
| const displayState = | ||
| isOutputError && baseDisplayState === "output-available" | ||
| ? "output-error" | ||
| : baseDisplayState; | ||
|
|
||
| let errorText: string | undefined; | ||
| if (isError) { | ||
| if (typeof output === "string") { | ||
| errorText = output; | ||
| } else if (typeof outputError === "string") { | ||
| errorText = outputError; | ||
| } else if (typeof outputObject?.message === "string") { | ||
| errorText = outputObject.message; | ||
| } else if (outputError !== undefined) { | ||
| errorText = stringifyValue(outputError); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| output, | ||
| isError, | ||
| displayState, | ||
| errorText, | ||
| }; | ||
| } |
2 changes: 2 additions & 0 deletions
2
...ChatPane/ChatInterface/components/MastraToolCallBlock/components/GenericToolCall/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { GenericToolCall } from "./GenericToolCall"; | ||
| export { getGenericToolCallState } from "./getGenericToolCallState"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../components/MessagePartsRenderer/components/StreamingMessageText/StreamingMessageText.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { | ||
| MessageResponse, | ||
| type MessageResponseProps, | ||
| } from "@superset/ui/ai-elements/message"; | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| const STREAM_TEXT_TICK_MS = 16; | ||
| const STREAM_TEXT_CHARS_PER_TICK = 2; | ||
|
|
||
| interface StreamingMessageTextProps { | ||
| text: string; | ||
| isAnimating: boolean; | ||
| mermaid: MessageResponseProps["mermaid"]; | ||
| components?: MessageResponseProps["components"]; | ||
| } | ||
|
|
||
| export function StreamingMessageText({ | ||
| text, | ||
| isAnimating, | ||
| mermaid, | ||
| components, | ||
| }: StreamingMessageTextProps) { | ||
| const [displayText, setDisplayText] = useState(text); | ||
|
|
||
| useEffect(() => { | ||
| if (!isAnimating) { | ||
| setDisplayText(text); | ||
| return; | ||
| } | ||
|
|
||
| setDisplayText((previous) => (text.startsWith(previous) ? previous : text)); | ||
|
|
||
| const intervalId = window.setInterval(() => { | ||
| setDisplayText((previous) => { | ||
| if (previous.length >= text.length) return previous; | ||
| const nextLength = Math.min( | ||
| text.length, | ||
| previous.length + STREAM_TEXT_CHARS_PER_TICK, | ||
| ); | ||
| return text.slice(0, nextLength); | ||
| }); | ||
| }, STREAM_TEXT_TICK_MS); | ||
|
|
||
| return () => window.clearInterval(intervalId); | ||
| }, [text, isAnimating]); | ||
|
|
||
| return ( | ||
| <MessageResponse | ||
| animated={false} | ||
| isAnimating={isAnimating} | ||
| mermaid={mermaid} | ||
| components={components} | ||
| > | ||
| {displayText} | ||
| </MessageResponse> | ||
| ); | ||
| } | ||
1 change: 1 addition & 0 deletions
1
...ne/ChatInterface/components/MessagePartsRenderer/components/StreamingMessageText/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { StreamingMessageText } from "./StreamingMessageText"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 46
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 91
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 91
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 271
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 618
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 1066
🏁 Script executed:
# Read the StreamingMessageText file to understand context cat apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/ChatPane/ChatInterface/components/MessagePartsRenderer/components/StreamingMessageText/StreamingMessageText.tsxRepository: superset-sh/superset
Length of output: 1348
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 46
🏁 Script executed:
# Read the full MessageResponse component to understand the complete behavior cat packages/ui/src/components/ai-elements/message.tsxRepository: superset-sh/superset
Length of output: 10689
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 8855
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 187
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 555
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 46
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 79
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 3197
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 7650
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 901
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 3681
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 8234
Pass
isAnimatingprop through toMessageResponse.MessageResponsedisables plugins during animation withplugins={isAnimating ? undefined : streamdownPlugins}to safely handle partial markdown. By hardcodingisAnimating={false}, the mermaid plugin runs on incomplete markdown during the character-by-character animation, potentially causing rendering artifacts. Thread the actual animation state instead.🔧 Proposed fix
return ( <MessageResponse animated={false} - isAnimating={false} + isAnimating={isAnimating} mermaid={mermaid} components={components} > {displayText} </MessageResponse> );📝 Committable suggestion
🤖 Prompt for AI Agents