🙌 OpenHands: AI-Driven Development
feat: Add splash page mode toggle (#17199)
Rohit Malhotra09bb0b753651
diff --git a/__tests__/components/features/chat/components/chat-input-field.test.tsx b/__tests__/components/features/chat/components/chat-input-field.test.tsxindex 14a2b293c2..d2cfbd2b54 100644--- a/__tests__/components/features/chat/components/chat-input-field.test.tsx+++ b/__tests__/components/features/chat/components/chat-input-field.test.tsx@@ -45,6 +45,17 @@ describe("ChatInputField auto-focus", () => {expect(screen.getByTestId("chat-input")).not.toBe(document.activeElement);});++ it("uses the provided placeholder when one is passed", () => {+ renderWithProviders(+ <Harness disabled={false} placeholder="Custom placeholder" />,+ );++ expect(screen.getByTestId("chat-input")).toHaveAttribute(+ "data-placeholder",+ "Custom placeholder",+ );+ });});function describeEngineeringTask() {diff --git a/__tests__/components/features/home/home-chat-launcher-failed-launch.test.tsx b/__tests__/components/features/home/home-chat-launcher-failed-launch.test.tsxindex 77f75b39dc..5e97b59a3c 100644--- a/__tests__/components/features/home/home-chat-launcher-failed-launch.test.tsx+++ b/__tests__/components/features/home/home-chat-launcher-failed-launch.test.tsx@@ -128,8 +128,20 @@ describe("HomeChatLauncher failed launch", () => {this.textContent = value;},});- // <Toaster /> asks for the reduced-motion preference, which jsdom lacks.- vi.stubGlobal("matchMedia", vi.fn().mockReturnValue({ matches: true }));+ // <Toaster /> and framer-motion ask for the reduced-motion preference, which jsdom lacks.+ vi.stubGlobal(+ "matchMedia",+ vi.fn().mockReturnValue({+ matches: true,+ media: "(prefers-reduced-motion)",+ onchange: null,+ addEventListener: vi.fn(),+ removeEventListener: vi.fn(),+ addListener: vi.fn(),+ removeListener: vi.fn(),+ dispatchEvent: vi.fn(),+ }),+ );vi.spyOn(WorkspacesService, "listWorkspaces").mockResolvedValue({workspaces: [],workspaceParents: [],diff --git a/__tests__/components/features/home/home-chat-launcher.test.tsx b/__tests__/components/features/home/home-chat-launcher.test.tsxindex cf20f0d5cf..a0700f8b61 100644--- a/__tests__/components/features/home/home-chat-launcher.test.tsx+++ b/__tests__/components/features/home/home-chat-launcher.test.tsx@@ -367,13 +367,47 @@ describe("HomeChatLauncher", () => {window.localStorage.removeItem(LAST_LOCAL_WORKSPACE_MODE_STORAGE_KEY);});- it("asks for an engineering task in the launcher input placeholder", async () => {+ it("defaults to Code mode and switches to Automate mode", async () => {renderLauncher();+ const user = userEvent.setup();++ expect(screen.getByTestId("home-launcher-mode-code")).toHaveAttribute(+ "aria-checked",+ "true",+ );+ expect(screen.getByTestId("home-composer-actions")).toHaveAttribute(+ "aria-disabled",+ "false",+ );+ expect(screen.getByTestId("open-workspace-button")).toBeEnabled();+ expect(screen.getByTestId("open-plugin-picker")).toBeEnabled();+ expect(screen.getByTestId("stub-chat-submit")).toHaveAttribute(+ "data-placeholder",+ "SUGGESTIONS$WHAT_TO_BUILD",+ );+ expect(+ screen.queryByTestId("recommended-automations-rail"),+ ).not.toBeInTheDocument();+ await user.click(screen.getByTestId("home-launcher-mode-automate"));++ expect(screen.getByTestId("home-launcher-mode-automate")).toHaveAttribute(+ "aria-checked",+ "true",+ );+ expect(screen.getByTestId("home-composer-actions")).toHaveAttribute(+ "aria-disabled",+ "true",+ );+ expect(screen.getByTestId("open-workspace-button")).toBeDisabled();+ expect(screen.getByTestId("open-plugin-picker")).toBeDisabled();expect(screen.getByTestId("stub-chat-submit")).toHaveAttribute("data-placeholder",- "HOME$DESCRIBE_ENGINEERING_TASK",+ "HOME$AUTOMATE_PROMPT_PLACEHOLDER",);+ expect(+ screen.getByTestId("recommended-automations-rail"),+ ).toBeInTheDocument();});it("creates a conversation with just the typed query and navigates when no workspace is selected", async () => {@@ -744,8 +778,11 @@ describe("HomeChatLauncher", () => {});});- it("always renders the recommended automations rail above pinned activity", () => {+ it("renders the recommended automations rail above pinned activity in Automate mode", async () => {renderLauncher();+ const user = userEvent.setup();++ await user.click(screen.getByTestId("home-launcher-mode-automate"));expect(screen.getByTestId("recommended-automations-rail"),diff --git a/src/components/features/chat/components/chat-input-container.tsx b/src/components/features/chat/components/chat-input-container.tsxindex ef77a4ab04..4b7037d919 100644--- a/src/components/features/chat/components/chat-input-container.tsx+++ b/src/components/features/chat/components/chat-input-container.tsx@@ -17,9 +17,9 @@ interface ChatInputContainerProps {hasStartedConversation?: boolean;isNewConversationPending?: boolean;showButton: boolean;- placeholder?: string;buttonClassName: string;chatInputRef: React.RefObject<HTMLDivElement | null>;+ placeholder?: string;handleFileIconClick: (isDisabled: boolean) => void;handleSubmit: () => void;onDragOver: (e: React.DragEvent, isDisabled: boolean) => void;@@ -44,9 +44,9 @@ export function ChatInputContainer({hasStartedConversation,isNewConversationPending = false,showButton,- placeholder,buttonClassName,chatInputRef,+ placeholder,handleFileIconClick,handleSubmit,onDragOver,diff --git a/src/components/features/chat/custom-chat-input.tsx b/src/components/features/chat/custom-chat-input.tsxindex ab50f17b05..400700ecbe 100644--- a/src/components/features/chat/custom-chat-input.tsx+++ b/src/components/features/chat/custom-chat-input.tsx@@ -194,9 +194,9 @@ export function CustomChatInput({hasStartedConversation={hasStartedConversation}isNewConversationPending={isNewConversationPending}showButton={showButton}- placeholder={placeholder}buttonClassName={buttonClassName}chatInputRef={chatInputRef}+ placeholder={placeholder}handleFileIconClick={handleFileIconClick}handleSubmit={handleSubmitAndSync}onDragOver={handleDragOver}diff --git a/src/components/features/home/home-chat-launcher.tsx b/src/components/features/home/home-chat-launcher.tsxindex ab50865864..294e3aecb1 100644--- a/src/components/features/home/home-chat-launcher.tsx+++ b/src/components/features/home/home-chat-launcher.tsx@@ -21,6 +21,7 @@ import { Branch, GitRepository } from "#/types/git";import { Provider } from "#/types/settings";import { LocalWorkspace } from "#/types/workspace";import { I18nKey } from "#/i18n/declaration";+import { cn } from "#/utils/utils";import {displayErrorToast,TOAST_OPTIONS,@@ -38,6 +39,10 @@ import { RecommendedAutomationsLauncher } from "#/components/features/automationimport { PinnedAutomationsDashboard } from "./featured-automations/pinned-automations-dashboard";import { RunningAutomationsList } from "./featured-automations/running-automations-list";import { HomeHeaderTitle } from "./home-header/home-header-title";+import {+ HomeLauncherModeToggle,+ type HomeLauncherMode,+} from "./home-launcher-mode-toggle";import { OpenLauncherButton } from "./open-launcher-button";import { OpenWorkspaceDialog } from "./open-workspace-dialog";import { OpenRepositoryDialog } from "./open-repository-dialog";@@ -61,6 +66,8 @@ export function HomeChatLauncher() {);const [selectedPlugins, setSelectedPlugins] = useState<PluginSpec[]>([]);const [isPluginPickerOpen, setIsPluginPickerOpen] = useState(false);+ const [launcherMode, setLauncherMode] = useState<HomeLauncherMode>("code");+ const isAutomateMode = launcherMode === "automate";const isMountedRef = useRef(true);useEffect(() => {@@ -275,12 +282,23 @@ export function HomeChatLauncher() {<HomeHeaderTitle /></div>+ <div className="flex w-full justify-center">+ <HomeLauncherModeToggle+ mode={launcherMode}+ onChange={setLauncherMode}+ />+ </div>+<div className="w-full"><CustomChatInputonSubmit={handleSubmitWithModelGuard}onFilesPaste={handleUpload}- placeholder={t(I18nKey.HOME$DESCRIBE_ENGINEERING_TASK)}disabled={isCreating || llmBlocked}+ placeholder={+ isAutomateMode+ ? t(I18nKey.HOME$AUTOMATE_PROMPT_PLACEHOLDER)+ : t(I18nKey.SUGGESTIONS$WHAT_TO_BUILD)+ }/></div>@@ -300,7 +318,14 @@ export function HomeChatLauncher() {)}</p>)}- <div className="flex items-center justify-start gap-2">+ <div+ data-testid="home-composer-actions"+ aria-disabled={isAutomateMode}+ className={cn(+ "flex items-center justify-start gap-2",+ isAutomateMode && "pointer-events-none opacity-40",+ )}+ >{hasSelection ? (<HomeGitControlBarPreviewworkspace={pendingWorkspace}@@ -316,22 +341,28 @@ export function HomeChatLauncher() {<OpenLauncherButtonkind={isLocal ? "local" : "cloud"}onClick={() => setIsDialogOpen(true)}- disabled={isCreating || Boolean(workspacesUnsupportedMessage)}+ disabled={+ isCreating ||+ isAutomateMode ||+ Boolean(workspacesUnsupportedMessage)+ }disabledTooltip={workspacesUnsupportedMessage}/>)}<PluginPickerTriggercount={selectedPlugins.length}onClick={() => setIsPluginPickerOpen(true)}- disabled={isCreating}+ disabled={isCreating || isAutomateMode}/></div>- <div className="mt-8 flex w-full flex-col gap-8">- <RecommendedAutomationsLauncher variant="rail" />- <PinnedAutomationsDashboard />- <RunningAutomationsList />- </div>+ {isAutomateMode && (+ <div className="mt-8 flex w-full flex-col gap-8">+ <RecommendedAutomationsLauncher variant="rail" />+ <PinnedAutomationsDashboard />+ <RunningAutomationsList />+ </div>+ )}</div>{isLocal ? (diff --git a/src/components/features/home/home-launcher-mode-toggle.tsx b/src/components/features/home/home-launcher-mode-toggle.tsxnew file mode 100644index 0000000000..d96c28d15a--- /dev/null+++ b/src/components/features/home/home-launcher-mode-toggle.tsx@@ -0,0 +1,182 @@+import { useEffect, useRef, type ReactNode } from "react";+import { useTranslation } from "react-i18next";+import { LayoutGroup, motion, useReducedMotion } from "framer-motion";+import { I18nKey } from "#/i18n/declaration";+import { cn } from "#/utils/utils";++export type HomeLauncherMode = "code" | "automate";++interface HomeLauncherModeToggleProps {+ mode: HomeLauncherMode;+ onChange: (mode: HomeLauncherMode) => void;+}++const PILL_TRANSITION = {+ type: "spring",+ stiffness: 420,+ damping: 34,+ mass: 0.55,+} as const;++function CodeBracketsIcon({ active }: { active: boolean }) {+ return (+ <svg+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ className="size-4"+ aria-hidden+ >+ <motion.g+ animate={active ? { x: [0, -1.5, 0] } : { x: 0 }}+ transition={+ active ? { duration: 0.38, ease: "easeInOut" } : { duration: 0.15 }+ }+ >+ <path d="m8 6-6 6 6 6" />+ </motion.g>+ <motion.g+ animate={active ? { x: [0, 1.5, 0] } : { x: 0 }}+ transition={+ active ? { duration: 0.38, ease: "easeInOut" } : { duration: 0.15 }+ }+ >+ <path d="m16 18 6-6-6-6" />+ </motion.g>+ </svg>+ );+}++function AutomateClockIcon({ active }: { active: boolean }) {+ const handRef = useRef<HTMLSpanElement>(null);++ useEffect(() => {+ const node = handRef.current;+ if (!node || !active || import.meta.env.MODE === "test") {+ return undefined;+ }++ const animation = node.animate(+ [{ transform: "rotate(0deg)" }, { transform: "rotate(360deg)" }],+ {+ duration: 700,+ easing: "cubic-bezier(0.2, 0.7, 0.2, 1)",+ fill: "forwards",+ },+ );++ return () => {+ animation.cancel();+ };+ }, [active]);++ return (+ <span className="relative inline-flex size-4" aria-hidden>+ <svg+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ className="absolute inset-0 size-4"+ >+ <circle cx="12" cy="12" r="9" />+ <path d="M12 12V8" />+ </svg>+ <span ref={handRef} className="absolute inset-0 size-4 origin-center">+ <svg+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ className="size-4"+ >+ <path d="M12 12L16.5 15" />+ </svg>+ </span>+ </span>+ );+}++export function HomeLauncherModeToggle({+ mode,+ onChange,+}: HomeLauncherModeToggleProps) {+ const { t } = useTranslation("openhands");+ const reduceMotion = useReducedMotion();+ const disableAnimation = reduceMotion || import.meta.env.MODE === "test";++ const options: Array<{+ value: HomeLauncherMode;+ label: string;+ icon: (active: boolean) => ReactNode;+ }> = [+ {+ value: "code",+ label: t(I18nKey.COMMON$CODE),+ icon: (active) => (+ <CodeBracketsIcon active={active && !disableAnimation} />+ ),+ },+ {+ value: "automate",+ label: t(I18nKey.AUTOMATE$SECTION_TITLE),+ icon: (active) => <AutomateClockIcon active={active} />,+ },+ ];++ return (+ <div className="flex w-full justify-center">+ <LayoutGroup id="home-launch-mode">+ <div+ role="radiogroup"+ aria-label={t(I18nKey.HOME$MODE_TOGGLE_LABEL)}+ data-testid="home-launcher-mode-toggle"+ className="inline-flex items-center rounded-full bg-[var(--oh-surface-raised)] p-1 text-sm font-medium"+ >+ {options.map((option) => {+ const isActive = option.value === mode;+ return (+ <button+ key={option.value}+ type="button"+ role="radio"+ aria-checked={isActive}+ data-testid={`home-launcher-mode-${option.value}`}+ onClick={() => onChange(option.value)}+ className={cn(+ "relative inline-flex items-center gap-2 rounded-full px-5 py-2",+ "cursor-pointer transition-colors",+ isActive+ ? "text-content"+ : "text-[var(--oh-muted)] hover:text-content",+ disableAnimation &&+ isActive &&+ "bg-[var(--oh-interactive-hover)]",+ )}+ >+ {!disableAnimation && isActive ? (+ <motion.span+ layoutId="home-launch-mode-pill"+ className="absolute inset-0 rounded-full bg-[var(--oh-interactive-hover)]"+ transition={PILL_TRANSITION}+ />+ ) : null}+ <span className="relative z-10 inline-flex size-4 shrink-0 items-center justify-center">+ {option.icon(isActive)}+ </span>+ <span className="relative z-10">{option.label}</span>+ </button>+ );+ })}+ </div>+ </LayoutGroup>+ </div>+ );+}diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex 02094fd673..f04f16a856 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -1971,6 +1971,40 @@"uk": "Опишіть інженерне завдання…","ca": "Descriu una tasca d'enginyeria…"},+ "HOME$MODE_TOGGLE_LABEL": {+ "en": "Choose launcher mode",+ "ja": "ランチャーモードを選択",+ "zh-CN": "选择启动器模式",+ "zh-TW": "選擇啟動器模式",+ "ko-KR": "런처 모드 선택",+ "no": "Velg startmodus",+ "it": "Scegli la modalità di avvio",+ "pt": "Escolha o modo do iniciador",+ "es": "Elige el modo del lanzador",+ "ar": "اختر وضع المشغّل",+ "fr": "Choisir le mode du lanceur",+ "tr": "Başlatıcı modunu seç",+ "de": "Startmodus auswählen",+ "uk": "Виберіть режим запуску",+ "ca": "Tria el mode del llançador"+ },+ "HOME$AUTOMATE_PROMPT_PLACEHOLDER": {+ "en": "What work do you want to automate?",+ "ja": "どの作業を自動化しますか?",+ "zh-CN": "你想自动化什么工作?",+ "zh-TW": "你想自動化什麼工作?",+ "ko-KR": "어떤 작업을 자동화하고 싶나요?",+ "no": "Hvilket arbeid vil du automatisere?",+ "it": "Quale lavoro vuoi automatizzare?",+ "pt": "Que trabalho você quer automatizar?",+ "es": "¿Qué trabajo quieres automatizar?",+ "ar": "ما العمل الذي تريد أتمتته؟",+ "fr": "Quel travail voulez-vous automatiser ?",+ "tr": "Hangi işi otomatikleştirmek istiyorsunuz?",+ "de": "Welche Arbeit möchtest du automatisieren?",+ "uk": "Яку роботу ви хочете автоматизувати?",+ "ca": "Quina feina vols automatitzar?"+ },"HOME$OPENHANDS_DESCRIPTION": {"en": "OpenHands makes it easy to build and maintain software using AI-driven development.","ja": "OpenHandsはAI駆動の開発を使用してソフトウェアの開発と維持を容易にします。",