Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): keep workspace selection in one dialog
chengyongrud5dc59ea766a
diff --git a/docs/webui.md b/docs/webui.mdindex 92c02b2eb..80ccaa322 100644--- a/docs/webui.md+++ b/docs/webui.md@@ -294,9 +294,8 @@ or a result you must retain.Use the workspace picker to browse folders on the connected nanobot host, enteran absolute path, or return to recent and starred projects; favorites persistacross gateway restarts. Tab completes paths and Shift+wheel scrolls directory-columns. Local hosts may also offer a native folder chooser; hosts without-browsing support accept manual paths. Project paths refer to the gateway-machine, not the browser's filesystem.+columns. Hosts without browsing support accept manual paths in the same dialog.+Project paths refer to the gateway machine, not the browser's filesystem.Selecting a project does not replace the configured agent workspace. The twopaths have different responsibilities:diff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsxindex 15ba73d98..b04b82da0 100644--- a/webui/src/components/thread/ThreadComposer.tsx+++ b/webui/src/components/thread/ThreadComposer.tsx@@ -243,7 +243,6 @@ interface ThreadComposerProps {workspaceControls?: WorkspacesPayload["controls"] | null;workspaceScopeDisabled?: boolean;workspaceError?: string | null;- onPickWorkspaceFolder?: () => Promise<string | null>;onFavoriteWorkspaceProject?: (path: string, pinned: boolean) => Promise<ProjectDirectory[]>;onResolveWorkspaceProject?: (path: string) => Promise<ProjectDirectory>;onLoadWorkspaceProjects?: () => Promise<WorkspacesPayload>;@@ -970,7 +969,6 @@ export function ThreadComposer({workspaceControls = null,workspaceScopeDisabled = false,workspaceError = null,- onPickWorkspaceFolder,onLoadWorkspaceProjects,onResolveWorkspaceProject,onFavoriteWorkspaceProject,@@ -2393,7 +2391,6 @@ export function ThreadComposer({defaultScope={workspaceDefaultScope}controls={workspaceControls}error={workspaceError}- onPickFolder={onPickWorkspaceFolder}onFavoriteProject={onFavoriteWorkspaceProject}onResolveProject={onResolveWorkspaceProject}onLoadProjects={onLoadWorkspaceProjects}diff --git a/webui/src/components/thread/ThreadShell.tsx b/webui/src/components/thread/ThreadShell.tsxindex 767f39f6d..0de24c5e0 100644--- a/webui/src/components/thread/ThreadShell.tsx+++ b/webui/src/components/thread/ThreadShell.tsx@@ -702,14 +702,6 @@ export function ThreadShell({forkBoundaryMessageCount,} = useSessionHistory(historyKey);const { client, getToken, ingressLimits, modelName, token, webuiCapabilities } = useClient();- const pickWorkspaceFolder = useCallback(async (): Promise<string | null> => {- const response = await client.requestMutation<{ path: unknown }>(- "workspace.pick_folder",- {},- 300_000,- );- return typeof response.path === "string" ? response.path : null;- }, [client]);const favoriteWorkspaceProject = useCallback(async (path: string, pinned: boolean) => {const response = await client.requestMutation<{ favorite_projects: ProjectDirectory[] }>("workspace.favorite", { path, pinned });@@ -1802,9 +1794,6 @@ export function ThreadShell({workspaceControls={workspaceControls}workspaceScopeDisabled={workspaceScopeDisabled}workspaceError={workspaceError}- onPickWorkspaceFolder={- workspaceControls?.can_pick_folder ? pickWorkspaceFolder : undefined- }onWorkspaceScopeChange={onWorkspaceScopeChange}pendingQueueKey={temporary ? null : chatId}transcriptionProvider={settingsSnapshot?.transcription?.provider}@@ -1861,9 +1850,6 @@ export function ThreadShell({workspaceControls={workspaceControls}workspaceScopeDisabled={workspaceScopeDisabled}workspaceError={workspaceError}- onPickWorkspaceFolder={- workspaceControls?.can_pick_folder ? pickWorkspaceFolder : undefined- }onWorkspaceScopeChange={onWorkspaceScopeChange}transcriptionProvider={settingsSnapshot?.transcription?.provider}ingressLimits={ingressLimits}diff --git a/webui/src/components/thread/WorkspaceControls.tsx b/webui/src/components/thread/WorkspaceControls.tsxindex 43b6e79bd..9c5e37364 100644--- a/webui/src/components/thread/WorkspaceControls.tsx+++ b/webui/src/components/thread/WorkspaceControls.tsx@@ -1,7 +1,7 @@import { FullAccessIcon, WorkspaceIcon, RestrictedAccessIcon } from "@/components/icons/product-icons";import type { HTMLAttributes, ReactElement } from "react";import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";-import { Check, FolderOpen, Search, Star } from "lucide-react";+import { Check, Search, Star } from "lucide-react";import { useTranslation } from "react-i18next";import { ToggleButton } from "@/components/settings/ToggleButton";import { Button } from "@/components/ui/button";@@ -11,7 +11,6 @@ import { Input } from "@/components/ui/input";import { Dialog, DialogContent, DialogTrigger, DialogTitle, DialogDescription } from "@/components/ui/dialog";import type { WorkspaceScopePayload, ProjectDirectory, WorkspaceDirectoriesPayload, WorkspacesPayload } from "@/lib/types";import { createWorkspaceDirectoryCache } from "@/lib/workspace-directory-cache";-import { getRuntimeHost } from "@/lib/runtime";import { cn } from "@/lib/utils";import { isAbsoluteWorkspacePath, projectNameFromPath, sameWorkspacePath, scopeWithAccessMode, workspacePathCompletionQuery, workspaceDirectoryPrefix, selectedProjectScope, type BrowseWorkspaceDirectories } from "@/lib/workspace";@@ -135,7 +134,7 @@ function WorkspacePickerPath({ path }: { path: string }) {);}-export function WorkspaceProjectPicker({ isHero, connected = false, disabled, scope, defaultScope, controls, error, onPickFolder, onLoadProjects, onResolveProject, onFavoriteProject, onBrowseDirectories, layoutAnchor, onChange }: {+export function WorkspaceProjectPicker({ isHero, connected = false, disabled, scope, defaultScope, controls, error, onLoadProjects, onResolveProject, onFavoriteProject, onBrowseDirectories, layoutAnchor, onChange }: {layoutAnchor?: HTMLElement | null;isHero: boolean;connected?: boolean;@@ -144,7 +143,6 @@ export function WorkspaceProjectPicker({ isHero, connected = false, disabled, scdefaultScope: WorkspaceScopePayload | null;controls: WorkspacesPayload["controls"] | null;error?: string | null;- onPickFolder?: () => Promise<string | null>;onResolveProject?: (path: string) => Promise<ProjectDirectory>;onLoadProjects?: () => Promise<WorkspacesPayload>;onFavoriteProject?: (path: string, pinned: boolean) => Promise<ProjectDirectory[]>;@@ -188,7 +186,6 @@ export function WorkspaceProjectPicker({ isHero, connected = false, disabled, scconst visible = isHero && !!defaultScope && !!onChange && controls?.can_change_project !== false;const canBrowse = !!controls?.can_browse_directories && !!onBrowseDirectories;const directoryCache = useMemo(() => onBrowseDirectories ? createWorkspaceDirectoryCache(onBrowseDirectories) : null, [onBrowseDirectories, connected]);- const pickFolder = controls?.can_pick_folder ? getRuntimeHost().pickFolder ?? onPickFolder : undefined;const absoluteDraft = isAbsoluteWorkspacePath(pathDraft);const requestedPath = absoluteDraft ? pathDraft.trim() : basePath;const folderQuery = absoluteDraft ? "" : pathDraft.trim();@@ -355,18 +352,6 @@ export function WorkspaceProjectPicker({ isHero, connected = false, disabled, sc} finally { setPickingFolder(false); }}, [applyProjectPath, controls?.can_resolve_project, onResolveProject]);- const pickNativeFolder = async () => {- if (!pickFolder || disabled) return;- const session = pickerSession.current;- setPickingFolder(true);- try {- const path = await pickFolder();- if (path && session === pickerSession.current) await chooseProject(path);- } catch (err) {- if (session === pickerSession.current) setPathError((err as Error).message);- } finally { setPickingFolder(false); }- };-const favorites = catalog?.favorite_projects ?? [];const canFavorite = !!catalog?.controls.can_manage_favorites && !!onFavoriteProject;const isFavorite = (path: string) => favorites.some(item => sameWorkspacePath(item.path, path));@@ -513,12 +498,9 @@ export function WorkspaceProjectPicker({ isHero, connected = false, disabled, sc</WorkspaceDirectoryColumn>)}</div></div>- <div className="flex shrink-0 items-center justify-between gap-2 px-2 pt-1">- <div className="flex min-w-0 items-center gap-1">- {canBrowse && <label className="flex items-center gap-2 text-[12px] text-muted-foreground"><ToggleButton checked={showHidden} onChange={setShowHidden} label={t("workspace.picker.hidden")} />{t("workspace.picker.hidden")}</label>}- {pickFolder && <WorkspacePickerTooltip label={t("workspace.picker.native")}><Button type="button" variant="ghost" size="icon" aria-label={t("workspace.picker.native")} disabled={pickingFolder} onClick={() => void pickNativeFolder()}><FolderOpen className="h-4 w-4" /></Button></WorkspacePickerTooltip>}- </div>- </div>+ {canBrowse && <div className="flex shrink-0 items-center gap-2 px-2 pt-1">+ <label className="flex items-center gap-2 text-[12px] text-muted-foreground"><ToggleButton checked={showHidden} onChange={setShowHidden} label={t("workspace.picker.hidden")} />{t("workspace.picker.hidden")}</label>+ </div>}</DialogContent></Dialog></TooltipProvider>diff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.jsonindex 099f368fc..36c1f81c1 100644--- a/webui/src/i18n/locales/en/common.json+++ b/webui/src/i18n/locales/en/common.json@@ -2498,7 +2498,6 @@"search": "Enter a path or filter this folder…","shortcuts": "Saved locations","favoriteHint": "Use a folder’s star to add it here.",- "native": "Use system folder picker…","loading": "Loading folders…","truncated": "Showing 500 folders. Continue typing the path to narrow the list.","hidden": "Show hidden folders",diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.jsonindex 85798d6db..ee1eecd9b 100644--- a/webui/src/i18n/locales/es/common.json+++ b/webui/src/i18n/locales/es/common.json@@ -2299,7 +2299,6 @@"search": "Introduce una ruta o filtra esta carpeta…","shortcuts": "Ubicaciones guardadas","favoriteHint": "Pulsa la estrella de una carpeta para añadirla aquí.",- "native": "Usar el selector de carpetas del sistema…","loading": "Cargando carpetas…","truncated": "Se muestran 500 carpetas. Sigue escribiendo la ruta para reducir la lista.","hidden": "Mostrar carpetas ocultas",diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.jsonindex b09f11f59..599039a03 100644--- a/webui/src/i18n/locales/fr/common.json+++ b/webui/src/i18n/locales/fr/common.json@@ -2298,7 +2298,6 @@"search": "Saisir un chemin ou filtrer ce dossier…","shortcuts": "Emplacements enregistrés","favoriteHint": "Cliquez sur l’étoile d’un dossier pour l’ajouter ici.",- "native": "Utiliser le sélecteur de dossiers du système…","loading": "Chargement des dossiers…","truncated": "500 dossiers affichés. Continuez à saisir le chemin pour réduire la liste.","hidden": "Afficher les dossiers cachés",diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.jsonindex 5a9f4fc98..9ed4c64f3 100644--- a/webui/src/i18n/locales/id/common.json+++ b/webui/src/i18n/locales/id/common.json@@ -2298,7 +2298,6 @@"search": "Masukkan jalur atau filter folder ini…","shortcuts": "Lokasi tersimpan","favoriteHint": "Klik bintang di samping folder untuk menambahkannya di sini.",- "native": "Gunakan pemilih folder sistem…","loading": "Memuat folder…","truncated": "Menampilkan 500 folder. Lanjutkan mengetik jalur untuk mempersempit daftar.","hidden": "Tampilkan folder tersembunyi",diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.jsonindex db3b4d7a7..71a29058f 100644--- a/webui/src/i18n/locales/ja/common.json+++ b/webui/src/i18n/locales/ja/common.json@@ -2298,7 +2298,6 @@"search": "パスを入力、または現在のフォルダを絞り込む…","shortcuts": "保存した場所","favoriteHint": "フォルダの星をクリックして追加します。",- "native": "システムのフォルダー選択を使用…","loading": "フォルダーを読み込み中…","truncated": "500 個のフォルダーを表示しています。パスの入力を続けて絞り込んでください。","hidden": "隠しフォルダーを表示",diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.jsonindex 218c631ae..57172573c 100644--- a/webui/src/i18n/locales/ko/common.json+++ b/webui/src/i18n/locales/ko/common.json@@ -2298,7 +2298,6 @@"search": "경로 입력 또는 현재 폴더 필터링…","shortcuts": "저장된 위치","favoriteHint": "폴더 옆의 별을 눌러 즐겨찾기에 추가하세요.",- "native": "시스템 폴더 선택기 사용…","loading": "폴더 불러오는 중…","truncated": "폴더 500개를 표시합니다. 경로를 계속 입력하여 목록을 좁히세요.","hidden": "숨김 폴더 표시",diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.jsonindex 3d6f3d50e..c1151ca71 100644--- a/webui/src/i18n/locales/pt-BR/common.json+++ b/webui/src/i18n/locales/pt-BR/common.json@@ -2312,7 +2312,6 @@"search": "Digite um caminho ou filtre esta pasta…","shortcuts": "Locais salvos","favoriteHint": "Clique na estrela de uma pasta para adicioná-la aqui.",- "native": "Usar o seletor de pastas do sistema…","loading": "Carregando pastas…","truncated": "Exibindo 500 pastas. Continue digitando o caminho para reduzir a lista.","hidden": "Mostrar pastas ocultas",diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.jsonindex 7391b57b2..951d18d6a 100644--- a/webui/src/i18n/locales/vi/common.json+++ b/webui/src/i18n/locales/vi/common.json@@ -2298,7 +2298,6 @@"search": "Nhập đường dẫn hoặc lọc thư mục này…","shortcuts": "Vị trí đã lưu","favoriteHint": "Nhấn ngôi sao bên cạnh thư mục để thêm vào đây.",- "native": "Dùng bộ chọn thư mục hệ thống…","loading": "Đang tải thư mục…","truncated": "Hiển thị 500 thư mục. Tiếp tục nhập đường dẫn để thu hẹp danh sách.","hidden": "Hiện thư mục ẩn",diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.jsonindex 823a7e7e6..300febfba 100644--- a/webui/src/i18n/locales/zh-CN/common.json+++ b/webui/src/i18n/locales/zh-CN/common.json@@ -2498,7 +2498,6 @@"search": "输入路径或筛选当前目录…","shortcuts": "快捷位置","favoriteHint": "点击文件夹旁的星标收藏。",- "native": "使用系统文件夹选择器…","loading": "正在加载文件夹…","truncated": "已显示 500 个文件夹,继续输入路径以缩小范围。","hidden": "显示隐藏文件夹",diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.jsonindex 6291d1c56..48b460627 100644--- a/webui/src/i18n/locales/zh-TW/common.json+++ b/webui/src/i18n/locales/zh-TW/common.json@@ -2298,7 +2298,6 @@"search": "輸入路徑或篩選目前目錄…","shortcuts": "快捷位置","favoriteHint": "點擊資料夾旁的星號收藏。",- "native": "使用系統資料夾選擇器…","loading": "正在載入資料夾…","truncated": "已顯示 500 個資料夾,繼續輸入路徑以縮小範圍。","hidden": "顯示隱藏資料夾",diff --git a/webui/src/tests/thread-composer.test.tsx b/webui/src/tests/thread-composer.test.tsxindex b403fb2ff..8ed730f26 100644--- a/webui/src/tests/thread-composer.test.tsx+++ b/webui/src/tests/thread-composer.test.tsx@@ -1593,7 +1593,8 @@ describe("ThreadComposer", () => {expect(screen.getAllByRole("button", { name: "Switch working directory" })).toHaveLength(1);});- it("uses the native folder picker for project selection on native host", async () => {+ it("browses and selects the connected host's project in one dialog on a native client", async () => {+ const user = userEvent.setup();const onWorkspaceScopeChange = vi.fn();const pickFolder = vi.fn().mockResolvedValue("/Users/test/native-project");const defaultScope = {@@ -1602,6 +1603,16 @@ describe("ThreadComposer", () => {access_mode: "full" as const,restrict_to_workspace: false,};+ const project = { path: `${defaultScope.project_path}/project`, name: "project" };+ const onBrowseWorkspaceDirectories = vi.fn((rawPath: string) => {+ const path = rawPath.replace(/\/$/, "");+ return Promise.resolve({+ path, parent: path === defaultScope.project_path ? "/Users/test/.nanobot" : defaultScope.project_path,+ entries: path === defaultScope.project_path ? [project] : [],+ truncated: false, host: "dev-mac", platform: "Darwin",+ });+ });+ const onResolveWorkspaceProject = vi.fn().mockResolvedValue(project);Object.defineProperty(window, "nanobotHost", {configurable: true,value: {@@ -1624,41 +1635,41 @@ describe("ThreadComposer", () => {can_change_project: true,can_use_full_access: true,can_pick_folder: true,+ can_browse_directories: true,+ can_resolve_project: true,}}+ onBrowseWorkspaceDirectories={onBrowseWorkspaceDirectories}+ onResolveWorkspaceProject={onResolveWorkspaceProject}onWorkspaceScopeChange={onWorkspaceScopeChange}/>,);- fireEvent.click(screen.getByRole("button", { name: "Switch working directory" }));-+ await user.click(screen.getByRole("button", { name: "Switch working directory" }));expect(screen.getByRole("dialog", { name: "Choose project" })).toBeInTheDocument();- fireEvent.click(screen.getByRole("button", { name: "Use system folder picker…" }));- await waitFor(() => expect(pickFolder).toHaveBeenCalled());- expect(screen.queryByRole("dialog", { name: "Choose project" })).not.toBeInTheDocument();+ await user.click(await screen.findByRole("option", { name: project.path }));+ await waitFor(() => expect(screen.getByRole("button", { name: "Select" })).toBeEnabled());+ expect(onWorkspaceScopeChange).not.toHaveBeenCalled();+ await user.click(screen.getByRole("button", { name: "Select" }));+ await waitFor(() => expect(screen.queryByRole("dialog", { name: "Choose project" })).not.toBeInTheDocument());+ expect(onResolveWorkspaceProject).toHaveBeenCalledWith(project.path);+ expect(pickFolder).not.toHaveBeenCalled();expect(onWorkspaceScopeChange).toHaveBeenCalledWith(expect.objectContaining({- project_path: "/Users/test/native-project",- project_name: "native-project",+ project_path: project.path,+ project_name: project.name,access_mode: "full",restrict_to_workspace: false,}));});- it("does not use a native host picker when the gateway disallows folder picking", async () => {+ it("selects a restricted project manually when the host lacks directory browsing", async () => {const user = userEvent.setup();const onWorkspaceScopeChange = vi.fn();- const pickFolder = vi.fn().mockResolvedValue("/Users/test/native-project");- const onPickWorkspaceFolder = vi.fn().mockResolvedValue("/srv/nas-project");const defaultScope = {project_path: "/srv/nanobot/workspace",project_name: "workspace",access_mode: "full" as const,restrict_to_workspace: false,};- Object.defineProperty(window, "nanobotHost", {- configurable: true,- value: { pickFolder },- });-render(<ThreadComposeronSend={vi.fn()}@@ -1671,7 +1682,6 @@ describe("ThreadComposer", () => {can_use_full_access: false,can_pick_folder: false,}}- onPickWorkspaceFolder={onPickWorkspaceFolder}onWorkspaceScopeChange={onWorkspaceScopeChange}/>,);@@ -1679,8 +1689,6 @@ describe("ThreadComposer", () => {await user.click(screen.getByRole("button", { name: "Switch working directory" }));expect(await screen.findByLabelText("Paste path")).toBeInTheDocument();- expect(pickFolder).not.toHaveBeenCalled();- expect(onPickWorkspaceFolder).not.toHaveBeenCalled();fireEvent.change(screen.getByLabelText("Paste path"), {target: { value: "/srv/nas-project" },@@ -1694,48 +1702,7 @@ describe("ThreadComposer", () => {}));});- it("uses the gateway folder picker for a locally hosted WebUI", async () => {- const onWorkspaceScopeChange = vi.fn();- const pickFolder = vi.fn().mockResolvedValue("/Users/test/gateway-project");- const defaultScope = {- project_path: "/Users/test/.nanobot/workspace",- project_name: "workspace",- access_mode: "full" as const,- restrict_to_workspace: false,- };-- render(- <ThreadComposer- onSend={vi.fn()}- placeholder="Ask anything..."- variant="hero"- workspaceScope={defaultScope}- workspaceDefaultScope={defaultScope}- workspaceControls={{- can_change_project: true,- can_use_full_access: true,- can_pick_folder: true,- }}- onPickWorkspaceFolder={pickFolder}- onWorkspaceScopeChange={onWorkspaceScopeChange}- />,- );-- fireEvent.click(screen.getByRole("button", { name: "Switch working directory" }));-- expect(screen.getByRole("dialog", { name: "Choose project" })).toBeInTheDocument();- fireEvent.click(screen.getByRole("button", { name: "Use system folder picker…" }));- await waitFor(() => expect(pickFolder).toHaveBeenCalled());- expect(screen.queryByLabelText("Paste path")).not.toBeInTheDocument();- expect(onWorkspaceScopeChange).toHaveBeenCalledWith(expect.objectContaining({- project_path: "/Users/test/gateway-project",- project_name: "gateway-project",- access_mode: "full",- restrict_to_workspace: false,- }));- });-- it("uses the web path menu when no native host picker is available", async () => {+ it("offers manual path entry when the host lacks directory browsing", async () => {const user = userEvent.setup();const defaultScope = {project_path: "/Users/test/.nanobot/workspace",