π OpenHands: AI-Driven Development
Remove App tab from conversation workspace (#14395)
Graham Neubigcae76e54a590
diff --git a/frontend/__tests__/components/features/conversation/conversation-tab-content.test.tsx b/frontend/__tests__/components/features/conversation/conversation-tab-content.test.tsxindex 5b6ae64368..44cf9686dd 100644--- a/frontend/__tests__/components/features/conversation/conversation-tab-content.test.tsx+++ b/frontend/__tests__/components/features/conversation/conversation-tab-content.test.tsx@@ -31,7 +31,8 @@ vi.mock("#/routes/changes-tab", () => ({}));// Control for lazy loading test-let pendingBrowserTab: { promise: Promise<void>; resolve: () => void } | null = null;+let pendingBrowserTab: { promise: Promise<void>; resolve: () => void } | null =+ null;vi.mock("#/routes/browser-tab", () => ({default: () => {if (pendingBrowserTab) {@@ -41,16 +42,8 @@ vi.mock("#/routes/browser-tab", () => ({},}));-vi.mock("#/routes/served-tab", () => ({- default: () => (- <div data-testid="served-tab-content">Served Tab Content</div>- ),-}));-vi.mock("#/routes/vscode-tab", () => ({- default: () => (- <div data-testid="vscode-tab-content">VSCode Tab Content</div>- ),+ default: () => <div data-testid="vscode-tab-content">VSCode Tab Content</div>,}));vi.mock("#/routes/planner-tab", () => ({@@ -78,7 +71,9 @@ describe("ConversationTabContent", () => {const createWrapper = () => {return ({ children }: { children: React.ReactNode }) => (<MemoryRouter initialEntries={["/conversations/test-conversation-id"]}>- <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>+ <QueryClientProvider client={queryClient}>+ {children}+ </QueryClientProvider></MemoryRouter>);};@@ -154,18 +149,6 @@ describe("ConversationTabContent", () => {expect(screen.getByText("COMMON$BROWSER")).toBeInTheDocument();});- it("should render served tab when selected", async () => {- setSelectedTab("served");-- render(<ConversationTabContent />, { wrapper: createWrapper() });-- await waitFor(() => {- expect(screen.getByTestId("served-tab-content")).toBeInTheDocument();- });-- expect(screen.getByText("COMMON$APP")).toBeInTheDocument();- });-it("should render vscode tab when selected", async () => {setSelectedTab("vscode");@@ -208,13 +191,12 @@ describe("ConversationTabContent", () => {tab: ConversationTab;expectedTitle: string;}> = [- { tab: "editor", expectedTitle: "COMMON$CHANGES" },- { tab: "browser", expectedTitle: "COMMON$BROWSER" },- { tab: "served", expectedTitle: "COMMON$APP" },- { tab: "vscode", expectedTitle: "COMMON$CODE" },- { tab: "terminal", expectedTitle: "COMMON$TERMINAL" },- { tab: "planner", expectedTitle: "COMMON$PLANNER" },- ];+ { tab: "editor", expectedTitle: "COMMON$CHANGES" },+ { tab: "browser", expectedTitle: "COMMON$BROWSER" },+ { tab: "vscode", expectedTitle: "COMMON$CODE" },+ { tab: "terminal", expectedTitle: "COMMON$TERMINAL" },+ { tab: "planner", expectedTitle: "COMMON$PLANNER" },+ ];tabTitleMapping.forEach(({ tab, expectedTitle }) => {it(`should display "${expectedTitle}" title for "${tab}" tab`, async () => {diff --git a/frontend/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx b/frontend/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsxindex 9944b8e391..5d59829fcb 100644--- a/frontend/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx+++ b/frontend/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx@@ -45,12 +45,12 @@ describe("ConversationTabsContextMenu", () => {"COMMON$CHANGES","COMMON$CODE","COMMON$TERMINAL",- "COMMON$APP","COMMON$BROWSER",];for (const tab of expectedTabs) {expect(screen.getByText(tab)).toBeInTheDocument();}+ expect(screen.queryByText("COMMON$APP")).not.toBeInTheDocument();});it("should re-pin a tab when clicking an unpinned tab", async () => {diff --git a/frontend/__tests__/conversation-local-storage.test.ts b/frontend/__tests__/conversation-local-storage.test.tsindex 33e9e12a7e..5ff7c8fb65 100644--- a/frontend/__tests__/conversation-local-storage.test.ts+++ b/frontend/__tests__/conversation-local-storage.test.ts@@ -52,6 +52,22 @@ describe("conversation localStorage utilities", () => {expect(state.rightPanelShown).toBe(true);});+ it("drops removed app tab values from persisted state", () => {+ const key = `${LOCAL_STORAGE_KEYS.CONVERSATION_STATE}-conv-served`;+ localStorage.setItem(+ key,+ JSON.stringify({+ selectedTab: "served",+ unpinnedTabs: ["terminal", "served", "app", "custom-tab"],+ }),+ );++ const state = getConversationState("conv-served");++ expect(state.selectedTab).toBe("editor");+ expect(state.unpinnedTabs).toEqual(["terminal", "custom-tab"]);+ });+it("returns default state when key is missing or invalid", () => {expect(getConversationState("conv-missing").conversationMode).toBe("code",diff --git a/frontend/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content.tsx b/frontend/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content.tsxindex fa37243a43..e79398dbca 100644--- a/frontend/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content.tsx+++ b/frontend/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content.tsx@@ -13,7 +13,6 @@ import { useConversationId } from "#/hooks/use-conversation-id";// Lazy load all tab componentsconst EditorTab = lazy(() => import("#/routes/changes-tab"));const BrowserTab = lazy(() => import("#/routes/browser-tab"));-const ServedTab = lazy(() => import("#/routes/served-tab"));const VSCodeTab = lazy(() => import("#/routes/vscode-tab"));const PlannerTab = lazy(() => import("#/routes/planner-tab"));const TaskListTab = lazy(() => import("#/routes/task-list-tab"));@@ -31,10 +30,6 @@ const TAB_CONFIG = {component: BrowserTab,titleKey: I18nKey.COMMON$BROWSER,},- served: {- component: ServedTab,- titleKey: I18nKey.COMMON$APP,- },vscode: {component: VSCodeTab,titleKey: I18nKey.COMMON$CODE,@@ -55,7 +50,8 @@ export function ConversationTabContent() {const { t } = useTranslation();const activeTab = useMemo(- () => TAB_CONFIG[selectedTab ?? "editor"],+ () =>+ TAB_CONFIG[selectedTab as keyof typeof TAB_CONFIG] ?? TAB_CONFIG.editor,[selectedTab],);diff --git a/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx b/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsxindex 58ceae666a..99a4419182 100644--- a/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx+++ b/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx@@ -8,7 +8,6 @@ import { useConversationStore } from "#/stores/conversation-store";import { I18nKey } from "#/i18n/declaration";import TerminalIcon from "#/icons/terminal.svg?react";import GlobeIcon from "#/icons/globe.svg?react";-import ServerIcon from "#/icons/server.svg?react";import GitChanges from "#/icons/git_changes.svg?react";import VSCodeIcon from "#/icons/vscode.svg?react";import PillIcon from "#/icons/pill.svg?react";@@ -45,7 +44,6 @@ export function ConversationTabsContextMenu({{ tab: "editor", icon: GitChanges, i18nKey: I18nKey.COMMON$CHANGES },{ tab: "vscode", icon: VSCodeIcon, i18nKey: I18nKey.COMMON$CODE },{ tab: "terminal", icon: TerminalIcon, i18nKey: I18nKey.COMMON$TERMINAL },- { tab: "served", icon: ServerIcon, i18nKey: I18nKey.COMMON$APP },{ tab: "browser", icon: GlobeIcon, i18nKey: I18nKey.COMMON$BROWSER },];diff --git a/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs.tsx b/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs.tsxindex 5d3a8526d6..235c2b9d99 100644--- a/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs.tsx+++ b/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs.tsx@@ -2,7 +2,6 @@ import { useEffect, useState } from "react";import { useTranslation } from "react-i18next";import TerminalIcon from "#/icons/terminal.svg?react";import GlobeIcon from "#/icons/globe.svg?react";-import ServerIcon from "#/icons/server.svg?react";import GitChanges from "#/icons/git_changes.svg?react";import VSCodeIcon from "#/icons/vscode.svg?react";import ThreeDotsVerticalIcon from "#/icons/three-dots-vertical.svg?react";@@ -104,15 +103,6 @@ export function ConversationTabs() {label: t(I18nKey.COMMON$TERMINAL),className: "pl-2",},- {- tabValue: "served",- isActive: isTabActive("served"),- icon: ServerIcon,- onClick: () => selectTab("served"),- tooltipContent: t(I18nKey.COMMON$APP),- tooltipAriaLabel: t(I18nKey.COMMON$APP),- label: t(I18nKey.COMMON$APP),- },{tabValue: "browser",isActive: isTabActive("browser"),diff --git a/frontend/src/components/features/served-host/path-form.tsx b/frontend/src/components/features/served-host/path-form.tsxdeleted file mode 100644index daec8b7c7e..0000000000--- a/frontend/src/components/features/served-host/path-form.tsx+++ /dev/null@@ -1,19 +0,0 @@-interface PathFormProps {- ref: React.RefObject<HTMLFormElement | null>;- onBlur: () => void;- defaultValue: string;-}--export function PathForm({ ref, onBlur, defaultValue }: PathFormProps) {- return (- <form ref={ref} onSubmit={(e) => e.preventDefault()} className="flex-1">- <input- name="url"- type="text"- defaultValue={defaultValue}- className="w-full bg-transparent"- onBlur={onBlur}- />- </form>- );-}diff --git a/frontend/src/hooks/query/use-unified-active-host.ts b/frontend/src/hooks/query/use-unified-active-host.tsdeleted file mode 100644index 000f66e1b9..0000000000--- a/frontend/src/hooks/query/use-unified-active-host.ts+++ /dev/null@@ -1,80 +0,0 @@-import { useQueries, useQuery } from "@tanstack/react-query";-import axios from "axios";-import React from "react";-import { useConversationId } from "#/hooks/use-conversation-id";-import { useRuntimeIsReady } from "#/hooks/use-runtime-is-ready";-import { useActiveConversation } from "#/hooks/query/use-active-conversation";-import { useBatchSandboxes } from "./use-batch-sandboxes";--/**- * Unified hook to get active web host for both legacy (V0) and V1 conversations- * - V0: Uses the legacy getWebHosts API endpoint and polls them- * - V1: Gets worker URLs from sandbox exposed_urls (WORKER_1, WORKER_2, etc.)- */-export const useUnifiedActiveHost = () => {- const [activeHost, setActiveHost] = React.useState<string | null>(null);- const { conversationId } = useConversationId();- const runtimeIsReady = useRuntimeIsReady();- const { data: conversation, isLoading: isLoadingConversation } =- useActiveConversation();- const sandboxId = conversation?.sandbox_id;-- // Fetch sandbox data for V1 conversations- const sandboxesQuery = useBatchSandboxes(sandboxId ? [sandboxId] : []);- const sandbox = sandboxesQuery?.data?.[0];-- // Get worker URLs from V1 sandbox or legacy web hosts from V0- const { data, isLoading: hostsQueryLoading } = useQuery({- queryKey: [conversationId, "hosts", sandbox],- queryFn: async () => {- // V1: Get worker URLs from sandbox exposed_urls- if (!sandbox) {- return { hosts: [] };- }-- const workerUrls =- sandbox.exposed_urls- ?.filter((url) => url.name.startsWith("WORKER_"))- .map((url) => url.url) || [];-- return { hosts: workerUrls };- },- enabled: runtimeIsReady && !!conversationId && !!sandboxesQuery.data,- initialData: { hosts: [] },- meta: {- disableToast: true,- },- });-- // Poll all hosts to find which one is active- const apps = useQueries({- queries: data.hosts.map((host) => ({- queryKey: [conversationId, "unified", "hosts", host],- queryFn: async () => {- try {- await axios.get(host);- return host;- } catch (e) {- return "";- }- },- refetchInterval: 3000,- meta: {- disableToast: true,- },- })),- });-- const appsData = apps.map((app) => app.data);-- React.useEffect(() => {- const successfulApp = appsData.find((app) => app);- setActiveHost(successfulApp || "");- }, [appsData]);-- // Calculate overall loading state including dependent queries for V1- const isLoading =- isLoadingConversation || sandboxesQuery.isLoading || hostsQueryLoading;-- return { activeHost, isLoading };-};diff --git a/frontend/src/routes/served-tab.tsx b/frontend/src/routes/served-tab.tsxdeleted file mode 100644index b6abb5b3d3..0000000000--- a/frontend/src/routes/served-tab.tsx+++ /dev/null@@ -1,107 +0,0 @@-import React from "react";-import { FaArrowRotateRight } from "react-icons/fa6";-import { FaExternalLinkAlt, FaHome } from "react-icons/fa";-import { useTranslation } from "react-i18next";-import { useUnifiedActiveHost } from "#/hooks/query/use-unified-active-host";-import { PathForm } from "#/components/features/served-host/path-form";-import { I18nKey } from "#/i18n/declaration";-import ServerProcessIcon from "#/icons/server-process.svg?react";--function ServedApp() {- const { t } = useTranslation();- const { activeHost } = useUnifiedActiveHost();- const [refreshKey, setRefreshKey] = React.useState(0);- const [currentActiveHost, setCurrentActiveHost] = React.useState<- string | null- >(null);- const [path, setPath] = React.useState<string>("hello");-- const formRef = React.useRef<HTMLFormElement>(null);-- const handleOnBlur = () => {- if (formRef.current) {- const formData = new FormData(formRef.current);- const urlInputValue = formData.get("url")?.toString();-- if (urlInputValue) {- const url = new URL(urlInputValue);-- setCurrentActiveHost(url.origin);- setPath(url.pathname);- }- }- };-- const resetUrl = () => {- setCurrentActiveHost(activeHost);- setPath("");-- if (formRef.current) {- formRef.current.reset();- }- };-- React.useEffect(() => {- resetUrl();- }, [activeHost]);-- const fullUrl = `${currentActiveHost}/${path}`;-- if (!currentActiveHost) {- return (- <div className="flex flex-col items-center justify-center w-full h-full p-10">- <ServerProcessIcon width={113} height={113} color="#A1A1A1" />- <span className="text-[#8D95A9] text-[19px] font-normal leading-5">- {t(I18nKey.BROWSER$SERVER_MESSAGE)}- </span>- </div>- );- }-- return (- <div className="h-full w-full">- <div className="w-full p-2 flex items-center gap-4 border-b border-neutral-600">- <button- type="button"- onClick={() => window.open(fullUrl, "_blank")}- className="text-sm"- aria-label={t(I18nKey.BUTTON$OPEN_IN_NEW_TAB)}- >- <FaExternalLinkAlt className="w-4 h-4" />- </button>- <button- type="button"- onClick={() => setRefreshKey((prev) => prev + 1)}- className="text-sm"- aria-label={t(I18nKey.BUTTON$REFRESH)}- >- <FaArrowRotateRight className="w-4 h-4" />- </button>-- <button- type="button"- onClick={() => resetUrl()}- className="text-sm"- aria-label={t(I18nKey.BUTTON$HOME)}- >- <FaHome className="w-4 h-4" />- </button>- <div className="w-full flex">- <PathForm- ref={formRef}- onBlur={handleOnBlur}- defaultValue={fullUrl}- />- </div>- </div>- <iframe- key={refreshKey}- title={t(I18nKey.SERVED_APP$TITLE)}- src={fullUrl}- className="w-full h-full custom-scrollbar-always"- />- </div>- );-}--export default ServedApp;diff --git a/frontend/src/stores/conversation-store.ts b/frontend/src/stores/conversation-store.tsindex 3d864fe14e..830314d887 100644--- a/frontend/src/stores/conversation-store.ts+++ b/frontend/src/stores/conversation-store.ts@@ -8,7 +8,6 @@ import {export type ConversationTab =| "editor"| "browser"- | "served"| "vscode"| "terminal"| "planner"diff --git a/frontend/src/utils/conversation-local-storage.ts b/frontend/src/utils/conversation-local-storage.tsindex 4beb800b88..4cb88896ec 100644--- a/frontend/src/utils/conversation-local-storage.ts+++ b/frontend/src/utils/conversation-local-storage.ts@@ -35,6 +35,36 @@ const DEFAULT_CONVERSATION_STATE: ConversationState = {draftMessage: null,};+const REMOVED_CONVERSATION_TABS: ReadonlySet<string> = new Set([+ "served",+ "app",+]);++function sanitizeStoredState(+ stored: Partial<ConversationState>,+): Partial<ConversationState> {+ let result: Partial<ConversationState> = stored;++ if (+ typeof result.selectedTab === "string" &&+ REMOVED_CONVERSATION_TABS.has(result.selectedTab)+ ) {+ result = { ...result };+ delete result.selectedTab;+ }++ if (result.unpinnedTabs) {+ const filtered = result.unpinnedTabs.filter(+ (tab) => !REMOVED_CONVERSATION_TABS.has(tab),+ );+ if (filtered.length !== result.unpinnedTabs.length) {+ result = { ...result, unpinnedTabs: filtered };+ }+ }++ return result;+}+/*** Check if a conversation ID is a temporary task ID that should not be persisted.* Task IDs have the format "task-{uuid}" and are used during V1 conversation initialization.@@ -56,7 +86,10 @@ export function getConversationState(const key = `${LOCAL_STORAGE_KEYS.CONVERSATION_STATE}-${conversationId}`;const item = localStorage.getItem(key);if (item !== null) {- return { ...DEFAULT_CONVERSATION_STATE, ...JSON.parse(item) };+ return {+ ...DEFAULT_CONVERSATION_STATE,+ ...sanitizeStoredState(JSON.parse(item)),+ };}return DEFAULT_CONVERSATION_STATE;} catch {