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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
feat: GA chat sidebar (#3919)
Myles Scolnickf223ce84acae
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsxindex e9136f884d..267e052637 100644--- a/frontend/src/components/app-config/user-config-form.tsx+++ b/frontend/src/components/app-config/user-config-form.tsx@@ -1067,28 +1067,6 @@ export const UserConfigForm: React.FC = () => {⚠️ These features are experimental and may require restarting yournotebook to take effect.</p>- <FormField- control={form.control}- name="experimental.chat_sidebar"- render={({ field }) => (- <div className="flex flex-col gap-y-1">- <FormItem className={formItemClasses}>- <FormLabel className="font-normal">Chat sidebar</FormLabel>- <FormControl>- <Checkbox- data-testid="chat-sidebar-checkbox"- checked={field.value === true}- onCheckedChange={field.onChange}- />- </FormControl>- </FormItem>- <FormDescription>- Enable experimental chat sidebar to ask questions with an AI- assistant.- </FormDescription>- </div>- )}- /><FormFieldcontrol={form.control}name="experimental.inline_ai_tooltip"diff --git a/frontend/src/components/chat/chat-panel.tsx b/frontend/src/components/chat/chat-panel.tsxindex ae11a290a5..fea274d368 100644--- a/frontend/src/components/chat/chat-panel.tsx+++ b/frontend/src/components/chat/chat-panel.tsx@@ -1,5 +1,5 @@/* Copyright 2024 Marimo. All rights reserved. */-import { useAtom } from "jotai";+import { useAtom, useAtomValue } from "jotai";import { Button } from "@/components/ui/button";import { ScrollArea } from "@/components/ui/scroll-area";import {@@ -7,7 +7,12 @@ import {PopoverContent,PopoverTrigger,} from "@/components/ui/popover";-import { ClockIcon, Loader2, PlusIcon } from "lucide-react";+import {+ BotMessageSquareIcon,+ ClockIcon,+ Loader2,+ PlusIcon,+} from "lucide-react";import {chatStateAtom,activeChatAtom,@@ -26,7 +31,7 @@ import { generateUUID } from "@/utils/uuid";import { type Message, useChat } from "ai/react";import { PromptInput } from "../editor/ai/add-cell-with-ai";import type { ReactCodeMirrorRef } from "@uiw/react-codemirror";-import { Tooltip } from "../ui/tooltip";+import { Tooltip, TooltipProvider } from "../ui/tooltip";import { asURL } from "@/utils/url";import { API } from "@/core/network/api";import { cn } from "@/utils/cn";@@ -37,6 +42,11 @@ import { getAICompletionBody } from "../editor/ai/completion-utils";import { addMessageToChat } from "@/core/ai/chat-utils";import { ErrorBanner } from "@/plugins/impl/common/error-banner";import { type ResolvedTheme, useTheme } from "@/theme/useTheme";+import { aiAtom, aiEnabledAtom } from "@/core/config/config";+import { useOpenSettingsToTab } from "../app-config/state";+import { PanelEmptyState } from "../editor/chrome/panels/empty-state";+import { CopyClipboardIcon } from "../icons/copy-icon";+import { timeAgo } from "@/utils/dates";interface ChatHeaderProps {onNewChat: () => void;@@ -52,54 +62,77 @@ const ChatHeader: React.FC<ChatHeaderProps> = ({setActiveChat,chats,setMessages,-}) => (- <div className="flex border-b px-2 py-1 justify-between flex-shrink-0">- <Tooltip content="New chat">- <Button variant="text" size="icon" onClick={onNewChat}>- <PlusIcon className="h-4 w-4" />- </Button>- </Tooltip>- <Popover>- <Tooltip content="Previous chats">- <PopoverTrigger asChild={true}>- <Button variant="text" size="icon">- <ClockIcon className="h-4 w-4" />+}) => {+ 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">+ <div className="flex items-center gap-2">+ <Tooltip content="New chat">+ <Button variant="text" size="icon" onClick={onNewChat}>+ <PlusIcon 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.map((chat) => (- <div- key={chat.id}- className={cn(- "p-3 rounded-md cursor-pointer hover:bg-accent",- chat.id === activeChatId && "bg-accent",- )}- onClick={() => {- setActiveChat(chat.id);- setMessages(- chat.messages.map(({ role, content, timestamp }) => ({- role,- content,- id: timestamp.toString(),- })),- );- }}- >- <div className="font-medium">{chat.title}</div>- <div className="text-sm text-muted-foreground">- {new Date(chat.updatedAt).toLocaleString()}+ </Tooltip>+ <Button+ variant="text"+ size="xs"+ className="hover:bg-foreground/10 py-2"+ onClick={() => handleClick("ai")}+ >+ {model}+ </Button>+ </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) => (+ <div+ key={chat.id}+ className={cn(+ "p-3 rounded-md cursor-pointer hover:bg-accent",+ chat.id === activeChatId && "bg-accent",+ )}+ onClick={() => {+ setActiveChat(chat.id);+ setMessages(+ chat.messages.map(({ role, content, timestamp }) => ({+ role,+ content,+ id: timestamp.toString(),+ })),+ );+ }}+ >+ <div className="font-medium">{chat.title}</div>+ <div className="text-sm text-muted-foreground">+ {timeAgo(chat.updatedAt)}+ </div></div>- </div>- ))}- </div>- </ScrollArea>- </PopoverContent>- </Popover>- </div>-);+ ))}+ </div>+ </ScrollArea>+ </PopoverContent>+ </Popover>+ </div>+ );+};interface ChatMessageProps {message: Message;@@ -114,7 +147,7 @@ const ChatMessage: React.FC<ChatMessageProps> = memo(({ message, index, theme, onEdit, setChatState, chatState }) => (<divclassName={cn(- "flex",+ "flex group relative",message.role === "user" ? "justify-end" : "justify-start",)}>@@ -151,6 +184,9 @@ const ChatMessage: React.FC<ChatMessageProps> = memo(</div>) : (<div className="w-[95%]">+ <div className="absolute right-1 top-1 opacity-0 group-hover:opacity-100 transition-opacity">+ <CopyClipboardIcon className="h-3 w-3" value={message.content} />+ </div><MarkdownRenderer content={message.content} /></div>)}@@ -183,7 +219,30 @@ const ChatInput: React.FC<ChatInputProps> = memo();ChatInput.displayName = "ChatInput";+export const ChatPanel = () => {+ const aiEnabled = useAtomValue(aiEnabledAtom);+ const { handleClick } = useOpenSettingsToTab();++ if (!aiEnabled) {+ return (+ <PanelEmptyState+ title="Chat with AI"+ description="AI is currently disabled. Add your API key to enable."+ action={+ <Button variant="outline" size="sm" onClick={() => handleClick("ai")}>+ Edit AI settings+ </Button>+ }+ icon={<BotMessageSquareIcon />}+ />+ );+ }++ return <ChatPanelBody />;+};++const ChatPanelBody = () => {const [chatState, setChatState] = useAtom(chatStateAtom);const [activeChat, setActiveChat] = useAtom(activeChatAtom);const [newThreadInput, setNewThreadInput] = useState("");@@ -323,13 +382,15 @@ export const ChatPanel = () => {return (<div className="flex flex-col h-[calc(100%-53px)]">- <ChatHeader- onNewChat={handleNewChat}- activeChatId={activeChat?.id}- setActiveChat={setActiveChat}- chats={chatState.chats}- setMessages={setMessages}- />+ <TooltipProvider>+ <ChatHeader+ onNewChat={handleNewChat}+ activeChatId={activeChat?.id}+ setActiveChat={setActiveChat}+ chats={chatState.chats}+ setMessages={setMessages}+ />+ </TooltipProvider><div className="flex-1 px-3 bg-[var(--slate-1)] gap-4 py-3 flex flex-col overflow-y-auto">{(!messages || messages.length === 0) && (diff --git a/frontend/src/components/chat/markdown-renderer.tsx b/frontend/src/components/chat/markdown-renderer.tsxindex 1c07f04d82..1bed046a78 100644--- a/frontend/src/components/chat/markdown-renderer.tsx+++ b/frontend/src/components/chat/markdown-renderer.tsx@@ -2,7 +2,7 @@import { useTheme } from "@/theme/useTheme";import { LazyAnyLanguageCodeMirror } from "@/plugins/impl/code/LazyAnyLanguageCodeMirror";import { useCellActions } from "@/core/cells/cells";-import { Button } from "@/components/ui/button";+import { Button, type ButtonProps } from "@/components/ui/button";import { BetweenHorizontalStartIcon } from "lucide-react";import { EditorView } from "@codemirror/view";import Markdown, { type Components } from "react-markdown";@@ -121,9 +121,9 @@ const CodeBlock = ({ code, language }: CodeBlockProps) => {onChange={setValue}/><div className="flex justify-end mt-2 space-x-2">- <Button size="xs" variant="outline" onClick={handleCopyCode}>+ <CopyButton size="xs" variant="outline" onClick={handleCopyCode}>Copy- </Button>+ </CopyButton><Button size="xs" variant="outline" onClick={handleInsertCode}>Add to Notebook<BetweenHorizontalStartIcon className="ml-2 h-4 w-4" />@@ -133,6 +133,28 @@ const CodeBlock = ({ code, language }: CodeBlockProps) => {);};+const CopyButton: React.FC<ButtonProps> = ({ onClick, ...props }) => {+ const [copied, setCopied] = useState(false);++ useEffect(() => {+ if (copied) {+ setTimeout(() => setCopied(false), 1000);+ }+ }, [copied]);++ return (+ <Button+ {...props}+ onClick={(e) => {+ onClick?.(e);+ setCopied(true);+ }}+ >+ {copied ? "Copied" : "Copy"}+ </Button>+ );+};+const COMPONENTS: Components = {code: ({ children, className }) => {const language = className?.replace("language-", "");diff --git a/frontend/src/components/editor/chrome/types.ts b/frontend/src/components/editor/chrome/types.tsindex c4f3122993..fc96aceae1 100644--- a/frontend/src/components/editor/chrome/types.ts+++ b/frontend/src/components/editor/chrome/types.ts@@ -82,7 +82,6 @@ export const PANELS: PanelDescriptor[] = [Icon: BotMessageSquareIcon,tooltip: "Chat with AI",position: "sidebar",- hidden: !getFeatureFlag("chat_sidebar"),},{type: "documentation",diff --git a/frontend/src/components/editor/chrome/wrapper/copilot-status.tsx b/frontend/src/components/editor/chrome/wrapper/copilot-status.tsxindex fa7441de84..7a8674f5e3 100644--- a/frontend/src/components/editor/chrome/wrapper/copilot-status.tsx+++ b/frontend/src/components/editor/chrome/wrapper/copilot-status.tsx@@ -8,7 +8,11 @@ import {copilotSignedInState,} from "@/core/codemirror/copilot/state";import { atom, useAtomValue, useSetAtom } from "jotai";-import { aiEnabledAtom, resolvedMarimoConfigAtom } from "@/core/config/config";+import {+ aiAtom,+ aiEnabledAtom,+ resolvedMarimoConfigAtom,+} from "@/core/config/config";import { GitHubCopilotIcon } from "@/components/icons/github-copilot";import { SparklesIcon } from "lucide-react";import { FooterItem } from "./footer-item";@@ -18,6 +22,7 @@ import { Logger } from "@/utils/Logger";import { Button } from "@/components/ui/button";import { useOnMount } from "@/hooks/useLifecycle";import { useOpenSettingsToTab } from "@/components/app-config/state";+export const AIStatusIcon: React.FC = () => {const ai = useAtomValue(aiAtom);const aiEnabled = useAtomValue(aiEnabledAtom);@@ -54,9 +59,6 @@ export const AIStatusIcon: React.FC = () => {const copilotAtom = atom((get) => {return get(resolvedMarimoConfigAtom).completion.copilot;});-const aiAtom = atom((get) => {- return get(resolvedMarimoConfigAtom).ai;-});export const CopilotStatusIcon: React.FC = () => {const copilot = useAtomValue(copilotAtom);diff --git a/frontend/src/core/config/config.ts b/frontend/src/core/config/config.tsindex 4a711bef1c..ae806c5344 100644--- a/frontend/src/core/config/config.ts+++ b/frontend/src/core/config/config.ts@@ -41,6 +41,10 @@ export const autoSaveConfigAtom = atom((get) => {return get(resolvedMarimoConfigAtom).save;});+export const aiAtom = atom((get) => {+ return get(resolvedMarimoConfigAtom).ai;+});+/*** Returns the user config.*/diff --git a/frontend/src/core/config/feature-flag.tsx b/frontend/src/core/config/feature-flag.tsxindex 2d84356db4..525967c994 100644--- a/frontend/src/core/config/feature-flag.tsx+++ b/frontend/src/core/config/feature-flag.tsx@@ -11,7 +11,6 @@ export interface ExperimentalFeatures {inline_ai_tooltip: boolean;wasm_layouts: boolean;scratchpad: boolean;- chat_sidebar: boolean;rtc: boolean;// Add new feature flags here}@@ -21,7 +20,6 @@ const defaultValues: ExperimentalFeatures = {inline_ai_tooltip: import.meta.env.DEV,wasm_layouts: false,scratchpad: true,- chat_sidebar: import.meta.env.DEV,rtc: false,};