Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat: add footer for chat-panel chat input and change settings button (#5354)

Joaquin Corominacddaef310a17
diff --git a/frontend/src/components/chat/chat-panel.tsx b/frontend/src/components/chat/chat-panel.tsx
index f80c29d37a..932cf3d229 100644
--- a/frontend/src/components/chat/chat-panel.tsx
+++ b/frontend/src/components/chat/chat-panel.tsx
@@ -9,6 +9,9 @@ import {
ClockIcon,
Loader2,
PlusIcon,
+ SendIcon,
+ SettingsIcon,
+ SquareIcon,
} from "lucide-react";
import {
type Dispatch,
@@ -26,6 +29,13 @@ import {
PopoverTrigger,
} from "@/components/ui/popover";
import { ScrollArea } from "@/components/ui/scroll-area";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
import { addMessageToChat } from "@/core/ai/chat-utils";
import {
activeChatAtom,
@@ -34,7 +44,9 @@ import {
chatStateAtom,
} from "@/core/ai/state";
import { getCodes } from "@/core/codemirror/copilot/getCodes";
-import { aiAtom, aiEnabledAtom } from "@/core/config/config";
+import { aiAtom, aiEnabledAtom, userConfigAtom } from "@/core/config/config";
+import type { UserConfig } from "@/core/config/config-schema";
+import { saveUserConfig } from "@/core/network/requests";
import { useRuntimeManager } from "@/core/runtime/config";
import { ErrorBanner } from "@/plugins/impl/common/error-banner";
import { type ResolvedTheme, useTheme } from "@/theme/useTheme";
@@ -42,6 +54,7 @@ import { cn } from "@/utils/cn";
import { timeAgo } from "@/utils/dates";
import { Logger } from "@/utils/Logger";
import { generateUUID } from "@/utils/uuid";
+import { KNOWN_AI_MODELS } from "../app-config/constants";
import { useOpenSettingsToTab } from "../app-config/state";
import { PromptInput } from "../editor/ai/add-cell-with-ai";
import { getAICompletionBody } from "../editor/ai/completion-utils";
@@ -64,66 +77,66 @@ const ChatHeader: React.FC<ChatHeaderProps> = ({
setActiveChat,
chats,
}) => {
- const ai = useAtomValue(aiAtom);
const { handleClick } = useOpenSettingsToTab();
- const model = ai?.open_ai?.model || "gpt-4-turbo";
return (
<div className="flex border-b px-2 py-1 justify-between flex-shrink-0 items-center">
+ <Tooltip content="New chat">
+ <Button variant="text" size="icon" onClick={onNewChat}>
+ <PlusIcon className="h-4 w-4" />
+ </Button>
+ </Tooltip>
<div className="flex items-center gap-2">
- <Tooltip content="New chat">
- <Button variant="text" size="icon" onClick={onNewChat}>
- <PlusIcon className="h-4 w-4" />
+ <Tooltip content="AI Settings">
+ <Button
+ variant="text"
+ size="xs"
+ className="hover:bg-foreground/10 py-2"
+ onClick={() => handleClick("ai")}
+ >
+ <SettingsIcon className="h-4 w-4" />
</Button>
</Tooltip>
- <Button
- variant="text"
- size="xs"
- className="hover:bg-foreground/10 py-2"
- onClick={() => handleClick("ai")}
- >
- {model}
- </Button>
+ <Popover>
+ <Tooltip content="Previous chats">
+ <PopoverTrigger asChild={true}>
+ <Button variant="text" size="icon">
+ <ClockIcon className="h-4 w-4" />
+ </Button>
+ </PopoverTrigger>
+ </Tooltip>
+ <PopoverContent className="w-[520px] p-0" align="start" side="right">
+ <ScrollArea className="h-[500px] p-4">
+ <div className="space-y-4">
+ {chats.length === 0 && (
+ <PanelEmptyState
+ title="No chats yet"
+ description="Start a new chat to get started"
+ icon={<BotMessageSquareIcon />}
+ />
+ )}
+ {chats.map((chat) => (
+ <button
+ key={chat.id}
+ className={cn(
+ "w-full p-3 rounded-md cursor-pointer hover:bg-accent text-left",
+ chat.id === activeChatId && "bg-accent",
+ )}
+ onClick={() => {
+ setActiveChat(chat.id);
+ }}
+ >
+ <div className="font-medium">{chat.title}</div>
+ <div className="text-sm text-muted-foreground">
+ {timeAgo(chat.updatedAt)}
+ </div>
+ </button>
+ ))}
+ </div>
+ </ScrollArea>
+ </PopoverContent>
+ </Popover>
</div>
- <Popover>
- <Tooltip content="Previous chats">
- <PopoverTrigger asChild={true}>
- <Button variant="text" size="icon">
- <ClockIcon className="h-4 w-4" />
- </Button>
- </PopoverTrigger>
- </Tooltip>
- <PopoverContent className="w-[520px] p-0" align="start" side="right">
- <ScrollArea className="h-[500px] p-4">
- <div className="space-y-4">
- {chats.length === 0 && (
- <PanelEmptyState
- title="No chats yet"
- description="Start a new chat to get started"
- icon={<BotMessageSquareIcon />}
- />
- )}
- {chats.map((chat) => (
- <button
- key={chat.id}
- className={cn(
- "p-3 rounded-md cursor-pointer hover:bg-accent",
- chat.id === activeChatId && "bg-accent",
- )}
- onClick={() => {
- setActiveChat(chat.id);
- }}
- >
- <div className="font-medium">{chat.title}</div>
- <div className="text-sm text-muted-foreground">
- {timeAgo(chat.updatedAt)}
- </div>
- </button>
- ))}
- </div>
- </ScrollArea>
- </PopoverContent>
- </Popover>
</div>
);
};
@@ -211,27 +224,169 @@ const ChatMessage: React.FC<ChatMessageProps> = memo(
);
ChatMessage.displayName = "ChatMessage";
+interface ChatInputFooterProps {
+ input: string;
+ onSendClick: () => void;
+ isLoading: boolean;
+ onStop: () => void;
+}
+
+const ChatInputFooter: React.FC<ChatInputFooterProps> = memo(
+ ({ input, onSendClick, isLoading, onStop }) => {
+ const ai = useAtomValue(aiAtom);
+ const [userConfig, setUserConfig] = useAtom(userConfigAtom);
+ // const currentMode = ai?.mode || "manual";
+ const currentModel = ai?.open_ai?.model || "o4-mini";
+
+ // const modeOptions = [
+ // {
+ // value: "ask",
+ // label: "Ask",
+ // subtitle: "Read-only tools",
+ // },
+ // {
+ // value: "manual",
+ // label: "Manual",
+ // subtitle: "No tools",
+ // },
+ // ];
+
+ // const handleModeChange = async (newMode: "ask" | "manual") => {
+ // const newConfig: UserConfig = {
+ // ...userConfig,
+ // ai: {
+ // ...userConfig.ai,
+ // mode: newMode,
+ // },
+ // };
+ // saveConfig(newConfig);
+ // };
+
+ const handleModelChange = async (newModel: string) => {
+ const newConfig: UserConfig = {
+ ...userConfig,
+ ai: {
+ ...userConfig.ai,
+ open_ai: {
+ ...userConfig.ai?.open_ai,
+ model: newModel,
+ },
+ },
+ };
+ saveConfig(newConfig);
+ };
+
+ const saveConfig = async (newConfig: UserConfig) => {
+ await saveUserConfig({ config: newConfig }).then(() => {
+ setUserConfig(newConfig);
+ });
+ };
+
+ return (
+ <div className="px-3 py-2 border-t border-border/20 flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ {/* TODO: ADD BACK ONCE THERE ARE TOOLS FOR ASK MODE */}
+ {/* <Select value={currentMode} onValueChange={handleModeChange}>
+ <SelectTrigger className="h-6 text-xs border-border !shadow-none !ring-0 bg-muted hover:bg-muted/30 py-0 px-2 gap-1">
+ <SelectValue placeholder="manual" />
+ </SelectTrigger>
+ <SelectContent>
+ {modeOptions.map((option) => (
+ <SelectItem
+ key={option.value}
+ value={option.value}
+ className="text-xs"
+ subtitle={<div className="text-muted-foreground text-xs pl-2">{option.subtitle}</div>}
+ >
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select> */}
+ <Select value={currentModel} onValueChange={handleModelChange}>
+ <SelectTrigger className="h-6 text-xs border-border !shadow-none !ring-0 bg-muted hover:bg-muted/30 py-0 px-2 gap-1">
+ <SelectValue placeholder="Model" />
+ </SelectTrigger>
+ <SelectContent>
+ {/* Show current model if it's not in the known models list */}
+ {!(KNOWN_AI_MODELS as readonly string[]).includes(
+ currentModel,
+ ) && (
+ <SelectItem
+ key={currentModel}
+ value={currentModel}
+ className="text-sm"
+ >
+ {currentModel}
+ </SelectItem>
+ )}
+ {KNOWN_AI_MODELS.map((model) => (
+ <SelectItem key={model} value={model} className="text-sm">
+ {model}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-6 w-6 p-0 hover:bg-muted/30"
+ onClick={isLoading ? onStop : onSendClick}
+ disabled={isLoading ? false : !input.trim()}
+ >
+ {isLoading ? (
+ <SquareIcon className="h-3 w-3 fill-current" />
+ ) : (
+ <SendIcon className="h-3 w-3" />
+ )}
+ </Button>
+ </div>
+ );
+ },
+);
+
+ChatInputFooter.displayName = "ChatInputFooter";
+
interface ChatInputProps {
input: string;
setInput: (value: string) => void;
onSubmit: (e: KeyboardEvent | undefined, value: string) => void;
theme: ResolvedTheme;
inputRef: React.RefObject<ReactCodeMirrorRef | null>;
+ isLoading: boolean;
+ onStop: () => void;
}
const ChatInput: React.FC<ChatInputProps> = memo(
- ({ input, setInput, onSubmit, theme, inputRef }) => (
- <div className="px-2 py-3 border-t relative flex-shrink-0 min-h-[80px]">
- <PromptInput
- value={input}
- onChange={setInput}
- onSubmit={onSubmit}
- onClose={() => inputRef.current?.editor?.blur()}
- theme={theme}
- placeholder="Type your message..."
- />
- </div>
- ),
+ ({ input, setInput, onSubmit, theme, inputRef, isLoading, onStop }) => {
+ const handleSendClick = () => {
+ if (input.trim()) {
+ onSubmit(undefined, input);
+ }
+ };
+
+ return (
+ <div className="border-t relative flex-shrink-0 min-h-[80px] flex flex-col">
+ <div className="px-2 py-3 flex-1">
+ <PromptInput
+ value={input}
+ onChange={setInput}
+ onSubmit={onSubmit}
+ onClose={() => inputRef.current?.editor?.blur()}
+ theme={theme}
+ placeholder="Type your message..."
+ />
+ </div>
+ <ChatInputFooter
+ input={input}
+ onSendClick={handleSendClick}
+ isLoading={isLoading}
+ onStop={onStop}
+ />
+ </div>
+ );
+ },
);
ChatInput.displayName = "ChatInput";
@@ -317,6 +472,10 @@ const ChatPanelBody = () => {
),
);
},
+ onToolCall: (_toolCall) => {
+ // Logger.warn("Tool call:", toolCall);
+ // TODO: Handle tool calls
+ },
onError: (error) => {
Logger.error("An error occurred:", error);
},
@@ -370,7 +529,10 @@ const ChatPanelBody = () => {
const createNewThread = (initialMessage: string) => {
const newChat: Chat = {
id: generateUUID(),
- title: `${initialMessage.slice(0, 30)}...`,
+ title:
+ initialMessage.length > 50
+ ? `${initialMessage.slice(0, 50)}...`
+ : initialMessage,
messages: [
{
role: "user",
@@ -462,7 +624,7 @@ const ChatPanelBody = () => {
onNewChat={handleNewChat}
activeChatId={activeChat?.id}
setActiveChat={setActiveChat}
- chats={chatState.chats}
+ chats={[...chatState.chats].sort((a, b) => b.updatedAt - a.updatedAt)}
/>
</TooltipProvider>
@@ -471,15 +633,23 @@ const ChatPanelBody = () => {
ref={scrollContainerRef}
>
{(!messages || messages.length === 0) && (
- <div className="flex rounded-md border px-1 bg-background">
- <PromptInput
- key="new-thread-input"
- value={newThreadInput}
- placeholder="Ask anything, @ to include context about tables or dataframes"
- theme={theme}
- onClose={handleOnCloseThread}
- onChange={setNewThreadInput}
- onSubmit={handleNewThreadSubmit}
+ <div className="flex flex-col rounded-md border bg-background">
+ <div className="px-1">
+ <PromptInput
+ key="new-thread-input"
+ value={newThreadInput}
+ placeholder="Ask anything, @ to include context about tables or dataframes"
+ theme={theme}
+ onClose={handleOnCloseThread}
+ onChange={setNewThreadInput}
+ onSubmit={handleNewThreadSubmit}
+ />
+ </div>
+ <ChatInputFooter
+ input={newThreadInput}
+ onSendClick={handleNewThreadSubmit}
+ isLoading={isLoading}
+ onStop={stop}
/>
</div>
)}
@@ -531,6 +701,8 @@ const ChatPanelBody = () => {
onSubmit={handleChatInputSubmit}
theme={theme}
inputRef={newMessageInputRef}
+ isLoading={isLoading}
+ onStop={stop}
/>
)}
</div>
diff --git a/frontend/src/core/config/__tests__/config-schema.test.ts b/frontend/src/core/config/__tests__/config-schema.test.ts
index 0356811d90..382b28e127 100644
--- a/frontend/src/core/config/__tests__/config-schema.test.ts
+++ b/frontend/src/core/config/__tests__/config-schema.test.ts
@@ -44,6 +44,7 @@ test("default UserConfig - empty", () => {
expect(defaultConfig).toMatchInlineSnapshot(`
{
"ai": {
+ "mode": "manual",
"rules": "",
},
"completion": {
@@ -99,6 +100,7 @@ test("default UserConfig - one level", () => {
expect(defaultConfig).toMatchInlineSnapshot(`
{
"ai": {
+ "mode": "manual",
"rules": "",
},
"completion": {
diff --git a/frontend/src/core/config/config-schema.ts b/frontend/src/core/config/config-schema.ts
index 70b568e09a..75d6fc7e8f 100644
--- a/frontend/src/core/config/config-schema.ts
+++ b/frontend/src/core/config/config-schema.ts
@@ -123,6 +123,7 @@ export const UserConfigSchema = z
ai: z
.object({
rules: z.string().default(""),
+ mode: z.enum(["manual", "ask"]).default("manual"),
open_ai: z
.object({
api_key: z.string().optional(),
@@ -175,6 +176,7 @@ export const UserConfigSchema = z
server: {},
ai: {
rules: "",
+ mode: "manual",
open_ai: {},
},
});