-
Notifications
You must be signed in to change notification settings - Fork 976
feat(desktop): add chat pane UI and tabs rework #1205
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
Closed
Closed
Changes from all commits
Commits
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
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
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
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,19 @@ | ||
| /** | ||
| * Get the most recently opened workspace path from grouped workspaces. | ||
| */ | ||
| export function getMostRecentWorkspacePath( | ||
| groups: Array<{ | ||
| workspaces: Array<{ | ||
| worktreePath: string; | ||
| lastOpenedAt: number; | ||
| }>; | ||
| }>, | ||
| ): string | null { | ||
| const allWorkspaces = groups.flatMap((g) => g.workspaces); | ||
| if (allWorkspaces.length === 0) return null; | ||
|
|
||
| const sorted = [...allWorkspaces].sort( | ||
| (a, b) => b.lastOpenedAt - a.lastOpenedAt, | ||
| ); | ||
| return sorted[0].worktreePath || null; | ||
| } |
96 changes: 96 additions & 0 deletions
96
apps/desktop/src/renderer/routes/_authenticated/_dashboard/chats/$chatId/page.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,96 @@ | ||
| import { createStream } from "@superset/ai-chat/stream"; | ||
| import { Button } from "@superset/ui/button"; | ||
| import { ScrollArea } from "@superset/ui/scroll-area"; | ||
| import { cn } from "@superset/ui/utils"; | ||
| import { createFileRoute, useNavigate } from "@tanstack/react-router"; | ||
| import { useCallback, useEffect } from "react"; | ||
| import { env } from "renderer/env.renderer"; | ||
| import { ChatView } from "../components/ChatView"; | ||
| import { useChatStore } from "../stores/chatStore"; | ||
|
|
||
| export const Route = createFileRoute( | ||
| "/_authenticated/_dashboard/chats/$chatId/", | ||
| )({ | ||
| component: ChatDetailPage, | ||
| }); | ||
|
|
||
| function ChatDetailPage() { | ||
| const { chatId } = Route.useParams(); | ||
| const navigate = useNavigate(); | ||
| const { sessions, createSession } = useChatStore(); | ||
|
|
||
| // Ensure stream exists when page loads | ||
| useEffect(() => { | ||
| createStream(env.NEXT_PUBLIC_STREAMS_URL, chatId).catch((err) => { | ||
| console.error("[chats] Failed to ensure stream exists on load:", err); | ||
| }); | ||
| }, [chatId]); | ||
|
|
||
| const handleCreateChat = useCallback(async () => { | ||
| const session = createSession(); | ||
| try { | ||
| await createStream(env.NEXT_PUBLIC_STREAMS_URL, session.id); | ||
| } catch (err) { | ||
| console.error("[chats] Failed to create stream:", err); | ||
| } | ||
| navigate({ to: "/chats/$chatId", params: { chatId: session.id } }); | ||
| }, [navigate, createSession]); | ||
|
|
||
| const handleSelectChat = useCallback( | ||
| async (id: string) => { | ||
| try { | ||
| await createStream(env.NEXT_PUBLIC_STREAMS_URL, id); | ||
| } catch (err) { | ||
| console.error("[chats] Failed to ensure stream exists:", err); | ||
| } | ||
| navigate({ to: "/chats/$chatId", params: { chatId: id } }); | ||
| }, | ||
| [navigate], | ||
| ); | ||
|
|
||
| return ( | ||
| <div className="flex h-full"> | ||
| {/* Sidebar */} | ||
| <div className="w-64 border-r border-border flex flex-col bg-muted/30"> | ||
| <div className="p-3 border-b border-border"> | ||
| <Button onClick={handleCreateChat} className="w-full" size="sm"> | ||
| + New Chat | ||
| </Button> | ||
| </div> | ||
|
|
||
| <ScrollArea className="flex-1"> | ||
| <div className="p-2 space-y-1"> | ||
| {sessions.length === 0 ? ( | ||
| <div className="text-center text-muted-foreground text-sm py-8 px-4"> | ||
| No chats yet. | ||
| </div> | ||
| ) : ( | ||
| sessions.map((session) => ( | ||
| <button | ||
| key={session.id} | ||
| type="button" | ||
| onClick={() => handleSelectChat(session.id)} | ||
| className={cn( | ||
| "w-full text-left px-3 py-2 rounded-md text-sm transition-colors", | ||
| "hover:bg-accent hover:text-accent-foreground", | ||
| chatId === session.id && "bg-accent text-accent-foreground", | ||
| )} | ||
| > | ||
| <span className="truncate block">{session.name}</span> | ||
| <span className="text-xs text-muted-foreground"> | ||
| {new Date(session.createdAt).toLocaleDateString()} | ||
| </span> | ||
| </button> | ||
| )) | ||
| )} | ||
| </div> | ||
| </ScrollArea> | ||
| </div> | ||
|
|
||
| {/* Chat View */} | ||
| <div className="flex-1 min-w-0"> | ||
| <ChatView sessionId={chatId} className="h-full" /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
157 changes: 157 additions & 0 deletions
157
...rc/renderer/routes/_authenticated/_dashboard/chats/components/ChatMessage/ChatMessage.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,157 @@ | ||
| /** | ||
| * Individual chat message component | ||
| */ | ||
|
|
||
| import type { BetaContentBlock, ToolResult } from "@superset/ai-chat/stream"; | ||
| import { | ||
| Collapsible, | ||
| CollapsibleContent, | ||
| CollapsibleTrigger, | ||
| } from "@superset/ui/collapsible"; | ||
| import { cn } from "@superset/ui/utils"; | ||
| import { useState } from "react"; | ||
| import { LuChevronRight } from "react-icons/lu"; | ||
| import ReactMarkdown from "react-markdown"; | ||
| import rehypeRaw from "rehype-raw"; | ||
| import rehypeSanitize from "rehype-sanitize"; | ||
| import remarkGfm from "remark-gfm"; | ||
| import { ToolCallPart } from "../ToolCallPart"; | ||
|
|
||
| export interface ChatMessageProps { | ||
| role?: "user" | "assistant"; | ||
| content: string; | ||
| contentBlocks?: BetaContentBlock[]; | ||
| toolResults?: Map<string, ToolResult>; | ||
| timestamp?: Date; | ||
| isStreaming?: boolean; | ||
| } | ||
|
|
||
| function ThinkingBlock({ thinking }: { thinking: string }) { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
|
|
||
| return ( | ||
| <Collapsible open={isOpen} onOpenChange={setIsOpen}> | ||
| <CollapsibleTrigger className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"> | ||
| <LuChevronRight | ||
| className={cn("h-3 w-3 transition-transform", isOpen && "rotate-90")} | ||
| /> | ||
| Thinking | ||
| </CollapsibleTrigger> | ||
| <CollapsibleContent> | ||
| <div className="mt-1 rounded border border-border bg-muted/30 p-2 text-xs text-muted-foreground italic whitespace-pre-wrap"> | ||
| {thinking} | ||
| </div> | ||
| </CollapsibleContent> | ||
| </Collapsible> | ||
| ); | ||
| } | ||
|
|
||
| function AssistantContent({ | ||
| content, | ||
| contentBlocks, | ||
| toolResults, | ||
| }: { | ||
| content: string; | ||
| contentBlocks?: BetaContentBlock[]; | ||
| toolResults?: Map<string, ToolResult>; | ||
| }) { | ||
| if (!contentBlocks || contentBlocks.length === 0) { | ||
| return ( | ||
| <div className="prose prose-sm dark:prose-invert max-w-none"> | ||
| <ReactMarkdown | ||
| remarkPlugins={[remarkGfm]} | ||
| rehypePlugins={[rehypeRaw, rehypeSanitize]} | ||
| > | ||
| {content} | ||
| </ReactMarkdown> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="space-y-3"> | ||
| {contentBlocks.map((block, index) => { | ||
| const key = `${block.type}-${index}`; | ||
| switch (block.type) { | ||
| case "text": | ||
| return ( | ||
| <div | ||
| key={key} | ||
| className="prose prose-sm dark:prose-invert max-w-none" | ||
| > | ||
| <ReactMarkdown | ||
| remarkPlugins={[remarkGfm]} | ||
| rehypePlugins={[rehypeRaw, rehypeSanitize]} | ||
| > | ||
| {block.text} | ||
| </ReactMarkdown> | ||
| </div> | ||
| ); | ||
| case "tool_use": | ||
| return ( | ||
| <ToolCallPart | ||
| key={block.id} | ||
| block={block} | ||
| result={toolResults?.get(block.id)} | ||
| /> | ||
| ); | ||
| case "thinking": | ||
| return <ThinkingBlock key={key} thinking={block.thinking} />; | ||
| default: | ||
| return ( | ||
| <div | ||
| key={key} | ||
| className="rounded border border-border bg-muted/30 p-2 text-xs text-muted-foreground" | ||
| > | ||
| <span className="font-mono">{block.type}</span> block | ||
| </div> | ||
| ); | ||
| } | ||
| })} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export function ChatMessage({ | ||
| role = "assistant", | ||
| content, | ||
| contentBlocks, | ||
| toolResults, | ||
| timestamp, | ||
| isStreaming, | ||
| }: ChatMessageProps) { | ||
| const isUser = role === "user"; | ||
|
|
||
| return ( | ||
| <div | ||
| className={cn("flex w-full", isUser ? "justify-end" : "justify-start")} | ||
| > | ||
| <div | ||
| className={cn( | ||
| "max-w-[80%] rounded-lg px-4 py-3", | ||
| isUser | ||
| ? "bg-primary text-primary-foreground" | ||
| : "bg-muted text-foreground", | ||
| )} | ||
| > | ||
| {isUser ? ( | ||
| <p className="whitespace-pre-wrap">{content}</p> | ||
| ) : ( | ||
| <AssistantContent | ||
| content={content} | ||
| contentBlocks={contentBlocks} | ||
| toolResults={toolResults} | ||
| /> | ||
| )} | ||
| {timestamp && ( | ||
| <span className="mt-1 block text-xs opacity-60"> | ||
| {timestamp.toLocaleTimeString()} | ||
| </span> | ||
| )} | ||
| {isStreaming && ( | ||
| <span className="mt-1 inline-block h-4 w-1 animate-pulse bg-current" /> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
2 changes: 2 additions & 0 deletions
2
...sktop/src/renderer/routes/_authenticated/_dashboard/chats/components/ChatMessage/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 type { ChatMessageProps } from "./ChatMessage"; | ||
| export { ChatMessage } from "./ChatMessage"; |
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: 917
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 7056
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 6264
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 707
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 421
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 195
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 91
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 7748
🏁 Script executed:
# Let's check the env validation more carefully to understand the full picture cat -n apps/desktop/src/renderer/env.renderer.tsRepository: superset-sh/superset
Length of output: 2482
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 929
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 518
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 439
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 534
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 4600
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 673
Fix inconsistent localhost default for NEXT_PUBLIC_STREAMS_URL.
The fallback to
"http://localhost:8080"is inconsistent with other NEXT_PUBLIC URLs (NEXT_PUBLIC_API_URL,NEXT_PUBLIC_WEB_URL,NEXT_PUBLIC_DOCS_URL), which all default to production endpoints. This will break chat functionality in production if the environment variable is not set at build time. Either requireNEXT_PUBLIC_STREAMS_URLfor production builds or provide a production-appropriate fallback.🤖 Prompt for AI Agents