mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 23:00:20 +08:00
* feat(workspace): manage workspace files from the web UI behind an explicit grant Files inside a workspace (question banks, notes, source material) could only be placed there over SSH/scp, which locks non-technical users out of the very folder the app is built around. This adds a file manager to Settings -> Personal -> Workspace: browse, create folders, upload, rename, and soft-delete, with a trash view to restore. The write path is deliberately narrow, because a workspace folder also holds DeepTutor's own state: * ``ContentWorkspaceService.resolve(write=True)`` already confined writes to ``outputs/`` and demanded "an explicit user grant" for anything else. That sentence had no implementation; this adds it rather than widening the rule. ``file_grants`` records one grant per workspace id in the caller's own account settings tree, so granting one folder never opens another. * ``.deeptutor/`` (session store, learning progress, caches), ``skills/`` and SQLite files are refused for reads and writes alike. The tree holds data whose loss is not "file management". * Deletes move entries into ``.deeptutor/trash/<batch>/`` keeping their relative path, so a mis-click on a question bank is reversible without shell access. Oldest batches are pruned past 30. * Uploads are bounded at 50 MB and names are validated for separators, reserved names and the protected extensions. * Every mutating service call re-checks the grant itself. The router check is defence in depth, not the only gate: a future caller that imports ``files`` directly cannot skip it. The router is mounted from ``server.json`` with ``auth: "admin"``, so the module loader's ``require_admin`` policy covers every endpoint. A learner account, or a workspace id belonging to another account, cannot reach it: ``binding_by_id`` re-derives the id from the caller's own bindings. A missing grant now answers 403 with the prompt the UI needs. Without that translation FastAPI turned the synchronous ``FileGrantError`` into a 500 and the panel could not tell "grant this workspace" from a real fault. Front end: a ``WorkspaceFileManager`` dialog (file list, breadcrumb, upload, rename, trash/restore, Markdown preview) plus a client in ``lib/workspace-files-api.ts``. Strings go through ``t()`` with en/zh entries; the panel is reachable from the workspace row in settings. Tests: 16 service-level cases over grant scoping, path confinement, protected paths, upload limits and the trash round trip; 3 router cases covering the manifest's admin policy, the full create/upload/rename/trash/restore cycle and the 403 mapping; 5 client cases for URL shape, verbs and error surfacing. Verified locally: pytest 19 passed, ruff clean, tsc clean, eslint clean, i18n parity OK, dependency-cruiser clean, vitest 5 passed. * fix(workspace): root uploads, folder-aware trash, bounded uploads Reviewing the file manager against real use surfaced four correctness bugs that the original 19 tests missed because they never exercised the root destination or a deleted folder. Root destination (#1). ``_normalise_relative`` rejects ``"."`` because a workspace-relative *file* path may never be empty, but the workspace root is a legitimate *destination directory* — it is the default upload target and the default restore target. Both went through the same normalisation and failed with "cannot leave the workspace" (HTTP 400) on the root. ``_resolve_target_dir`` handles ``""``/``"."`` as the root and leaves every other path on the existing guard; ``create_folder``/``rename_entry``/``trash_entry`` keep rejecting ``"."`` because those name an entry, not a directory to write into. Trash structure (#2). Deleting a folder used to scatter its children into ``files/<relative path>`` while ``rglob`` skipped the directory rows, so an empty folder vanished from the trash entirely and restoring a child of a deleted folder failed with "The restore folder does not exist." Each delete now gets its own slot: ``<batch>/entries/<uuid>/<name>`` plus a ``manifest.json`` holding ``original``, so a folder is one restorable row and comes back whole. A parent removed by the same delete is recreated on restore. Restore names (#3). With slots carrying identity the trash never appends ``.1``/``.2`` any more, so ``_strip_collision_suffix`` only did harm: a file legitimately named ``report.1`` or ``v1.10`` came back as ``report`` or ``v1``. Removed; the recorded name is restored verbatim. Uploads (#4). The route read the whole body with ``file.read()`` before ``save_upload`` checked the 50 MB cap, so a multi-GB upload would exhaust memory first. It now streams in 1 MB chunks and answers 413 as soon as the limit is passed, with an early check on the declared size. Also: preview now refuses database suffixes like the listing and the write paths do; ``trash_entry`` no longer resolves a symlink before moving it, so a link is trashed as a link instead of taking its target with it. Tests: 19 -> 37. New cases cover root upload/restore, empty and non-empty folder round trips, parent recreation, same-name entries in one batch, and names that merely look like collision suffixes. * fix(workspace): adapt the panel to the slot contract, i18n and input polish Companion to the backend fix in this same PR. This cannot ship on its own: the restore contract moved from ``{batch, name, destination, trashed_path}`` to ``{batch, slot, destination}`` and ``list_trash`` now returns one row per delete operation, so the previously committed client would break the trash view against the new server. Contract adaptation: * ``workspace-files-api.ts`` — ``WorkspaceTrashItem`` carries ``slot``, ``restoreWorkspaceEntry`` posts ``{batch, slot, destination}``. An empty destination means "put it back where it came from". * ``WorkspaceFileManager`` — the restore action passes the slot, and the row key uses ``${batch}:${item.slot}``. The old ``${batch}:${item.name}`` collided when two same-named files from different folders were deleted within the same second. Experience fixes: * Notices went through ``t()`` with en/zh entries. Nine ``setNotice`` calls were hard-coded English, so a Chinese UI still showed "Created …", "moved to trash", and so on. * Preview opens ``.MD``/``.TXT`` too — the suffix test was case-sensitive. * The new-folder and rename inputs submit on Enter, matching every other dialog in the app. * ``Dialog`` gained an optional ``closeTooltip`` (default ``true``) so a dialog whose close control sits next to other labelled controls can drop the hover bubble. All four file-manager dialogs turn it off; every other dialog in the app is untouched. Also wraps the four dialogs in a fragment: the grant, new-folder and rename modals were nested inside the manager's children, which trapped their backdrop and stacked two modals at once when an ungranted write opened the grant prompt. Those actions now close their own dialog before requesting the grant. * chore(contracts): regenerate the frontend OpenAPI contract The `export_frontend_contracts.py --check` job compares `web/contracts/schema/openapi.json` against what the FastAPI app renders, so adding a router without regenerating the artifact fails CI. Regenerated with the documented command: python scripts/export_frontend_contracts.py A deep comparison of the two documents before and after reports 13 differing leaves, all of them additions: eight `/api/settings/workspace/files*` paths and five request-body schemas (CreateFolderBody, DeleteBody, RenameBody, RestoreBody, and the upload multipart body). Nothing was removed or modified; the large line delta is the JSON being re-serialised with sorted keys. * chore(contracts): regenerate the generated TypeScript API types `npm run contracts:check` diffs `web/contracts/generated/api.ts` against a fresh run of openapi-typescript, so the regenerated schema alone leaves this artifact stale and fails the check. Regenerated with: npm run contracts:generate Pure addition: +611 lines, no deletions. It exposes the eight `/api/settings/workspace/files*` operations and the five request-body types. * i18n: translate the file-manager copy into all eleven other locales The English catalog is the source of truth and every first-class locale is expected to have no missing keys, so a feature that adds 25 keys to `en` and `zh` leaves ten locales falling back to English. Recent feature commits update every locale in the same change for this reason. Translated the 25 file-manager keys into de, fr, hu, it, ja, ko, pl, pt, tr, uk and vi, inserted at the same position as in the English catalog. Missing keys per locale drop from 25 to 0; `npm run i18n:check` passes. * fix(workspace): resume the upload after a first grant and ask before overwriting Two upload defects found in browser verification. **The selected file was lost when the grant was pending.** Choosing a file in a workspace without a grant opened the grant dialog and stashed the action, but the handler cleared the file input before `withGrant` ran. By the time the user approved, the `FileList` was empty, so nothing was sent and the file had to be picked again. The handler now snapshots the files into a plain array and resets the input up front, and the confirm dialog no longer closes on Escape while a pending action would be dropped with it. **A same-named upload replaced the file without asking.** The client always posted overwrite, and the service always wrote through. Uploads now default to `overwrite=false` and the service creates the target exclusively, so a conflict is reported even when the browser's listing is stale rather than being detected by a racy pre-check. A conflict surfaces as 409 and the panel asks before retrying with `overwrite=true`; declining keeps the original file and the rest of the batch continues. Also adds `UploadConflictBody` to the contract, the `Replace the existing file "{{name}}"?` key in all thirteen locales, and tests: a router test asserting the file survives a 409 and is replaced on the retry, an API-client test for the overwrite flag and conflict error, and a component test covering both the resumed upload and the declined/accepted replacement paths. * chore(api): regenerate the router index for the workspace files router `tests/api/test_router_loader.py::test_repository_index_matches_router_sources` asserts that `deeptutor/api/router_index.json` carries the fingerprint of the current router sources. Registering `workspace_files:router` in the module manifest changed that fingerprint without regenerating the index, so the assertion failed on every Python leg: AssertionError: Run scripts/build_router_index.py assert '89681f8f...' == 'cb9ea964...' Regenerated with `python scripts/build_router_index.py` (56 routers, 742 routes). The diff is the fingerprint plus the eleven `/api/settings/workspace/ files*` operations; no existing entry changed. --------- Co-authored-by: Qiuner <wdst3635@163.com>
190 lines
16 KiB
TypeScript
190 lines
16 KiB
TypeScript
'use client'
|
|
|
|
import Tooltip from "@/shared/ui/Tooltip";
|
|
import { useCallback, useEffect, useState } from 'react'
|
|
import Link from 'next/link'
|
|
import dynamic from 'next/dynamic'
|
|
import { Archive, ArchiveRestore, FileText, Folder, FolderInput, Globe2, Pencil, Plus, Settings2, FolderOpen } from 'lucide-react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { SettingSection, SettingsPageHeader, inputClass, subPanelClass } from '@/components/settings/shared'
|
|
import { WorkspaceResourcePicker } from '@/components/workspaces/WorkspaceResourcePicker'
|
|
import { WorkspaceInstructionsField } from '@/components/workspaces/WorkspaceInstructionsField'
|
|
import { WorkspaceFileManager } from '@/components/workspaces/WorkspaceFileManager'
|
|
import { SystemWorkspaceSnapshot } from '@/components/workspaces/SystemWorkspaceSnapshot'
|
|
import {
|
|
getWorkspaceCatalog, saveWorkspace, migrateWorkspace, workspaceChatHref, inheritedWorkspaceResources,
|
|
type WorkspaceCatalog, type ChatWorkspaceRegistration,
|
|
} from '@/lib/workspaces-api'
|
|
|
|
type RunAction = (action: () => Promise<unknown>) => Promise<boolean>
|
|
const ServerFolderPicker = dynamic(() => import('@/components/workspaces/ServerFolderPicker').then(module => module.ServerFolderPicker), { ssr: false })
|
|
const actionClass = 'inline-flex items-center justify-center gap-1.5 rounded-lg px-2.5 py-2 text-xs text-[var(--muted-foreground)] transition-colors hover:bg-[var(--muted)] hover:text-[var(--foreground)] disabled:opacity-50'
|
|
const primaryClass = 'inline-flex items-center justify-center gap-1.5 rounded-lg bg-[var(--foreground)] px-3 py-2 text-sm text-[var(--background)] disabled:opacity-50'
|
|
|
|
function WorkspaceRow({ row, run, busy }: { row: ChatWorkspaceRegistration; run: RunAction; busy: boolean }) {
|
|
const { t } = useTranslation()
|
|
const [resourcesOpen, setResourcesOpen] = useState(false)
|
|
const [instructionsOpen, setInstructionsOpen] = useState(false)
|
|
const [instructions, setInstructions] = useState(row.instructions ?? '')
|
|
const [resources, setResources] = useState(row.resources ?? inheritedWorkspaceResources())
|
|
const [editing, setEditing] = useState(false)
|
|
const [name, setName] = useState(row.display_name)
|
|
const [moving, setMoving] = useState(false)
|
|
const [filesOpen, setFilesOpen] = useState(false)
|
|
const [destination, setDestination] = useState('')
|
|
const custom = row.kind === 'workspace'
|
|
const Icon = row.kind === 'system' ? Settings2 : row.kind === 'general' ? Globe2 : Folder
|
|
const label = row.kind === 'system' ? t('System workspace') : row.kind === 'general' ? t('Default workspace') : row.display_name
|
|
return (
|
|
<article aria-label={label} className="group min-w-0 border-b border-[var(--border)] py-4 last:border-b-0">
|
|
<div className="flex flex-wrap items-center gap-x-3 gap-y-2">
|
|
<Icon size={18} strokeWidth={1.6} className="shrink-0 text-[var(--muted-foreground)]" />
|
|
<h3 className="min-w-0 flex-1 break-words text-[14px] font-medium">{label}</h3>
|
|
{row.archived && <span className="text-xs text-[var(--muted-foreground)]">{t('Archived')}</span>}
|
|
<div className="flex max-w-full flex-wrap items-center gap-0.5 sm:opacity-0 sm:transition-opacity sm:group-hover:opacity-100 sm:group-focus-within:opacity-100">
|
|
{row.kind !== 'system' && !row.archived && row.status === 'ready' && !busy && (
|
|
<Link className={actionClass} href={row.kind === 'general' ? '/chat?dt_workspace=' : workspaceChatHref(row.workspace_id)}>
|
|
<Plus size={14} />{t('New chat')}
|
|
</Link>
|
|
)}
|
|
{row.kind !== 'system' && !row.archived && <button type="button" className={actionClass} onClick={() => setFilesOpen(true)}><FolderOpen size={14} />{t('Manage files')}</button>}
|
|
{row.kind !== 'system' && !row.archived && <button type="button" className={actionClass} onClick={() => { setResources(row.resources ?? inheritedWorkspaceResources()); setResourcesOpen(!resourcesOpen) }}><Settings2 size={14} />{t('Assigned resources')}</button>}
|
|
{row.kind !== 'system' && !row.archived && <button type="button" className={actionClass} aria-expanded={instructionsOpen} onClick={() => { setInstructions(row.instructions ?? ''); setInstructionsOpen(!instructionsOpen) }}><FileText size={14} />{t('Workspace instructions')}</button>}
|
|
{custom && <Tooltip label={t('Rename workspace')} side="top">
|
|
<button type="button" className={actionClass} aria-label={t('Rename workspace')} onClick={() => { setName(row.display_name); setEditing(!editing); setMoving(false) }}><Pencil size={14} /></button>
|
|
</Tooltip>}
|
|
<Tooltip label={t('Move folder')} side="top">
|
|
<button type="button" className={actionClass} aria-label={t('Move folder')} onClick={() => { setMoving(!moving); setEditing(false); setDestination('') }}><FolderInput size={14} /></button>
|
|
</Tooltip>
|
|
{custom && <Tooltip label={row.archived ? t('Restore workspace') : t('Archive workspace')} side="top">
|
|
<button type="button" className={actionClass} aria-label={row.archived ? t('Restore workspace') : t('Archive workspace')} onClick={() => void run(() => saveWorkspace({ archived: !row.archived }, row.workspace_id))}>{row.archived ? <ArchiveRestore size={14} /> : <Archive size={14} />}</button>
|
|
</Tooltip>}
|
|
</div>
|
|
</div>
|
|
<div className="mt-1.5 min-w-0 sm:pl-[30px]">
|
|
{!custom && <p className="mb-2 text-[12.5px] leading-relaxed text-[var(--muted-foreground)]">{row.kind === 'system' ? t('Sanitized configuration snapshots, Skill files and MCP inventory. API keys and tokens remain in private configuration.') : t('Conversations without a selected workspace share files in this folder.')}</p>}
|
|
<p className="select-all break-all font-mono text-[11.5px] leading-relaxed text-[var(--muted-foreground)]">{row.path}</p>
|
|
{row.archived && <p className="mt-1 text-xs text-[var(--muted-foreground)]">{t('Archived. Existing conversations and files are kept.')}</p>}
|
|
{instructionsOpen && (
|
|
<form className={`${subPanelClass} mt-3 space-y-3 p-4`} onSubmit={async event => { event.preventDefault(); if (await run(() => saveWorkspace({ instructions }, row.workspace_id))) setInstructionsOpen(false) }}>
|
|
<WorkspaceInstructionsField value={instructions} onChange={setInstructions} />
|
|
<div className="flex gap-2"><button type="submit" className={primaryClass}>{t('Save')}</button><button type="button" className={actionClass} onClick={() => setInstructionsOpen(false)}>{t('Cancel')}</button></div>
|
|
</form>
|
|
)}
|
|
{resourcesOpen && (
|
|
<form className={`${subPanelClass} mt-3 space-y-3 p-4`} onSubmit={async event => { event.preventDefault(); if (await run(() => saveWorkspace({ resources }, row.workspace_id))) setResourcesOpen(false) }}>
|
|
<WorkspaceResourcePicker value={resources} onChange={setResources} workspaceId={row.workspace_id} />
|
|
<p className="text-xs text-[var(--muted-foreground)]">{t('Changes apply to subsequent turns. Existing conversations and files are kept.')}</p>
|
|
<div className="flex gap-2"><button type="submit" className={primaryClass}>{t('Save')}</button><button type="button" className={actionClass} onClick={() => setResourcesOpen(false)}>{t('Cancel')}</button></div>
|
|
</form>
|
|
)}
|
|
{editing && (
|
|
<form className="mt-3 flex flex-wrap items-end gap-2" onSubmit={async event => { event.preventDefault(); if (await run(() => saveWorkspace({ name: name.trim() }, row.workspace_id))) setEditing(false) }}>
|
|
<label className="min-w-0 flex-1 text-xs">{t('Workspace name')}<input autoFocus className={`${inputClass} mt-1`} value={name} onChange={event => setName(event.target.value)} maxLength={100} required /></label>
|
|
<button className={primaryClass} disabled={!name.trim()} type="submit">{t('Save')}</button>
|
|
<button className={actionClass} type="button" onClick={() => setEditing(false)}>{t('Cancel')}</button>
|
|
</form>
|
|
)}
|
|
{moving && (
|
|
<form className={`${subPanelClass} mt-3 space-y-3 p-4`} onSubmit={async event => { event.preventDefault(); if (await run(() => migrateWorkspace(destination.trim(), row.workspace_id))) setMoving(false) }}>
|
|
<p className="text-xs text-[var(--muted-foreground)]">{row.follows_root ? t('Follows root') : t('Custom location')}</p>
|
|
<label className="block text-xs">{t('New storage folder')}<input autoFocus className={`${inputClass} mt-1 font-mono`} value={destination} onChange={event => setDestination(event.target.value)} required placeholder={t('Enter a destination folder that does not exist yet')} /></label>
|
|
<p className="text-xs leading-relaxed text-[var(--muted-foreground)]">{t('Copy and verify before switching. The workspace ID and conversation bindings stay unchanged; the old folder is kept as a backup.')}</p>
|
|
<div className="flex gap-2"><button type="submit" disabled={!destination.trim()} className={primaryClass}>{t('Start migration')}</button><button type="button" className={actionClass} onClick={() => setMoving(false)}>{t('Cancel')}</button></div>
|
|
</form>
|
|
)}
|
|
{row.error && <p role="alert" className="mt-2 text-xs text-[var(--destructive)]">{row.error}</p>}
|
|
{row.kind === 'system' && <SystemWorkspaceSnapshot />}
|
|
</div>
|
|
{filesOpen && (
|
|
<WorkspaceFileManager
|
|
workspaceId={row.workspace_id}
|
|
workspaceName={row.display_name}
|
|
open={filesOpen}
|
|
onClose={() => setFilesOpen(false)}
|
|
/>
|
|
)}
|
|
</article>
|
|
)
|
|
}
|
|
|
|
export default function WorkspaceSettingsSection() {
|
|
const { t } = useTranslation()
|
|
const [catalog, setCatalog] = useState<WorkspaceCatalog | null>(null)
|
|
const [root, setRoot] = useState('')
|
|
const [busy, setBusy] = useState(false)
|
|
const [creating, setCreating] = useState(false)
|
|
const [browsing, setBrowsing] = useState(false)
|
|
const [resources, setResources] = useState(inheritedWorkspaceResources)
|
|
const [instructions, setInstructions] = useState('')
|
|
const [name, setName] = useState('')
|
|
const [path, setPath] = useState('')
|
|
const [error, setError] = useState('')
|
|
const [notice, setNotice] = useState('')
|
|
const refresh = useCallback(async () => {
|
|
const next = await getWorkspaceCatalog()
|
|
setCatalog(next)
|
|
setRoot(next.root)
|
|
setError('')
|
|
}, [])
|
|
useEffect(() => { void refresh().catch(err => setError(String(err.message))) }, [refresh])
|
|
const run: RunAction = async action => {
|
|
setBusy(true)
|
|
setError('')
|
|
setNotice('')
|
|
try {
|
|
await action()
|
|
await refresh()
|
|
setNotice(t('Workspace updated.'))
|
|
return true
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : String(err))
|
|
return false
|
|
} finally { setBusy(false) }
|
|
}
|
|
return (
|
|
<div>
|
|
<SettingsPageHeader title={t('Workspaces')} description={t('Keep conversations, learning materials and progress together in one workspace.')} actions={
|
|
<button type="button" disabled={busy || !catalog} onClick={() => setCreating(!creating)} className={primaryClass}><Plus size={15} />{t('New workspace')}</button>
|
|
} />
|
|
{error && <div role="alert" className="mb-4 rounded-lg border border-[var(--destructive)] p-3 text-sm text-[var(--destructive)]">{error}{!catalog && <button className="ml-3 underline" onClick={() => void refresh().catch(err => setError(String(err.message)))}>{t('Retry')}</button>}</div>}
|
|
{(busy || notice) && <p role="status" className="mb-4 text-sm text-[var(--muted-foreground)]">{busy ? t('Working. Migration copies and verifies your files; please wait…') : notice}</p>}
|
|
{!catalog ? (!error && <div aria-busy="true" className="h-44 animate-pulse rounded-xl bg-[var(--muted)]" />) : (
|
|
<fieldset disabled={busy} className="min-w-0 disabled:opacity-70">
|
|
<SettingSection title={t('Custom workspaces')} description={t('Books, Mastery Path, Reading, Watching and conversations are isolated by workspace.')}>
|
|
{creating && (
|
|
<form className={`${subPanelClass} my-4 space-y-3 p-4 sm:p-5`} onSubmit={async event => {
|
|
event.preventDefault()
|
|
if (await run(() => saveWorkspace({ name: name.trim(), resources, ...(instructions.trim() ? { instructions } : {}), ...(path.trim() ? { path: path.trim() } : {}) }))) { setName(''); setPath(''); setInstructions(''); setResources(inheritedWorkspaceResources()); setCreating(false) }
|
|
}}>
|
|
<label className="block text-sm">{t('Workspace name')}<input autoFocus className={`${inputClass} mt-1`} value={name} onChange={event => setName(event.target.value)} required maxLength={100} placeholder={t('e.g. Probability')} /></label>
|
|
<label className="block text-sm">{t('Existing folder path (optional)')}<input className={`${inputClass} mt-1 font-mono`} value={path} onChange={event => setPath(event.target.value)} placeholder={t('Leave empty to create under root')} /></label>
|
|
<button type="button" className={actionClass} onClick={() => setBrowsing(true)}><Folder size={15} />{t('Choose a server folder')}</button>
|
|
<p className="text-xs leading-relaxed text-[var(--muted-foreground)]">{t('Place files in the folder for the agent to read. Generated files go into outputs/.')}</p>
|
|
<WorkspaceInstructionsField value={instructions} onChange={setInstructions} />
|
|
<WorkspaceResourcePicker value={resources} onChange={setResources} />
|
|
<div className="flex gap-2"><button type="submit" disabled={!name.trim()} className={primaryClass}>{t('Create workspace')}</button><button type="button" className={actionClass} onClick={() => setCreating(false)}>{t('Cancel')}</button></div>
|
|
</form>
|
|
)}
|
|
{catalog.workspaces.filter(row => row.kind === 'workspace').map(row => <WorkspaceRow key={row.workspace_id} row={row} run={run} busy={busy} />)}
|
|
{!catalog.workspaces.some(row => row.kind === 'workspace') && !creating && <div className="flex flex-col items-center gap-3 py-10 text-center text-[var(--muted-foreground)]"><Folder size={28} strokeWidth={1.2} /><p className="max-w-sm text-sm leading-relaxed">{t('Create a workspace for a topic or project so related conversations share its files.')}</p></div>}
|
|
</SettingSection>
|
|
<SettingSection title={t('Built-in workspaces')}>
|
|
{catalog.workspaces.filter(row => row.kind !== 'workspace').map(row => <WorkspaceRow key={row.workspace_id} row={row} run={run} busy={busy} />)}
|
|
</SettingSection>
|
|
<SettingSection title={t('Storage location')} description={t('Workspaces default to root / workspace ID. Changing root migrates folders that follow it; custom locations stay in place. Remote deployments use server folders.')}>
|
|
<form className="space-y-3 py-4" onSubmit={async event => { event.preventDefault(); await run(() => migrateWorkspace(root.trim())) }}>
|
|
<label className="block text-sm">{t('Workspace root folder')}<input className={`${inputClass} mt-2 font-mono`} value={root} onChange={event => setRoot(event.target.value)} required /></label>
|
|
{root.trim() !== catalog.root && <div className="flex flex-wrap items-center gap-3"><button type="submit" disabled={!root.trim()} className={primaryClass}>{t('Migrate to new root')}</button><p className="text-xs text-[var(--muted-foreground)]">{t('Old folders are kept as a backup. Finish running conversations before migrating.')}</p></div>}
|
|
</form>
|
|
</SettingSection>
|
|
</fieldset>
|
|
)}
|
|
{browsing && <ServerFolderPicker onClose={() => setBrowsing(false)} onSelect={folder => {
|
|
setPath(folder.path)
|
|
if (!name.trim()) setName(folder.name.slice(0, 100))
|
|
}} />}
|
|
</div>
|
|
)
|
|
}
|