feat(webui): guide sandbox launcher recovery from chat
This commit is contained in:
1 parent
16250540d3
commit
f5e5bd6ea0
47 files changed
+613
-32
No files matched your search
@@ -2,7 +2,7 @@ import { ChevronLeft } from "lucide-react";
|
||||
import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogLayoutContext, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import type { SettingsExitGuard } from "@/components/settings/contracts";
|
||||
import type { SettingsExitGuard, SettingsFocusTarget } from "@/components/settings/contracts";
|
||||
import { isCapabilitySection, type SettingsSectionKey } from "@/components/settings/contracts";
|
||||
import { SettingsFeature } from "@/components/settings/shared/SettingsFeature";
|
||||
import type { EditCompletion } from "@/components/settings/shared/useEditCompletion";
|
||||
@@ -53,6 +53,7 @@ import { cn } from "@/lib/utils";
|
||||
|
||||
interface SettingsPageProps {
|
||||
registerExitGuard?: (guard: SettingsExitGuard | null) => void;
|
||||
focusTarget?: SettingsFocusTarget;
|
||||
controller: SettingsController;
|
||||
themePreference: ThemePreference;
|
||||
showSidebar: boolean;
|
||||
@@ -77,6 +78,7 @@ interface SettingsPageProps {
|
||||
|
||||
export function SettingsPage({
|
||||
registerExitGuard,
|
||||
focusTarget,
|
||||
controller,
|
||||
themePreference,
|
||||
showSidebar,
|
||||
@@ -196,6 +198,7 @@ export function SettingsPage({
|
||||
|
||||
const runtimeConfiguration = (page: RuntimeConfigPage) => settings && (
|
||||
<RuntimeConfigSettings page={page} settings={settings} state={controller.runtimeConfigState} client={client}
|
||||
focusTarget={page === "advanced" ? focusTarget : undefined}
|
||||
sandboxSupported={webuiCapabilities.includes("webui.sandbox-settings.v1")}
|
||||
onRestart={showSidebar ? undefined : restartViaSettingsSurface} isRestarting={restartInProgress}
|
||||
remoteBrowserAccess={remoteBrowserAccess}>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { SettingsPage } from "@/components/settings/SettingsPage";
|
||||
import type { SettingsExitGuard, SettingsSectionKey } from "@/components/settings/contracts";
|
||||
import type { SettingsExitGuard, SettingsFocusTarget, SettingsSectionKey } from "@/components/settings/contracts";
|
||||
import { useSettingsController } from "@/components/settings/useSettingsController";
|
||||
import type { SendAttachment, SendOptions } from "@/hooks/useNanobotStream";
|
||||
import type { ThemePreference } from "@/hooks/useTheme";
|
||||
@@ -11,6 +11,7 @@ interface SettingsViewProps {
|
||||
registerExitGuard?: (guard: SettingsExitGuard | null) => void;
|
||||
themePreference: ThemePreference;
|
||||
initialSection?: SettingsSectionKey;
|
||||
focusTarget?: SettingsFocusTarget;
|
||||
initialSettings?: SettingsPayload | null;
|
||||
showSidebar?: boolean;
|
||||
mainNavigationExpanded?: boolean;
|
||||
@@ -41,6 +42,7 @@ export function SettingsView({
|
||||
registerExitGuard,
|
||||
themePreference,
|
||||
initialSection = "overview",
|
||||
focusTarget,
|
||||
initialSettings = null,
|
||||
showSidebar = true,
|
||||
mainNavigationExpanded = false,
|
||||
@@ -74,6 +76,7 @@ export function SettingsView({
|
||||
return (
|
||||
<SettingsPage
|
||||
registerExitGuard={registerExitGuard}
|
||||
focusTarget={focusTarget}
|
||||
controller={controller}
|
||||
themePreference={themePreference}
|
||||
showSidebar={showSidebar}
|
||||
|
||||
@@ -40,3 +40,4 @@ export type ApplySettingsPayload = (
|
||||
) => void;
|
||||
|
||||
export type MaybeRestartHostEngine = (payload: RestartAwarePayload) => Promise<void>;
|
||||
export type SettingsFocusTarget = "sandbox" | "sandbox-launcher";
|
||||
@@ -6,10 +6,11 @@ import { SettingsGroup, SettingsRow } from "@/components/settings/shared/Setting
|
||||
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
import { Disclosure } from "@/components/ui/disclosure";
|
||||
|
||||
export function SettingsAdvancedOptions({ children }: { children: ReactNode }) {
|
||||
export function SettingsAdvancedOptions({ children, initialOpen = false }: { children: ReactNode; initialOpen?: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Disclosure
|
||||
initialOpen={initialOpen}
|
||||
summaryClassName="settings-list-inset flex min-h-12 cursor-pointer items-center justify-between gap-4 rounded-xl text-[13px] leading-5 text-muted-foreground settings-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
summary={<>
|
||||
{t("settings.runtimeConfig.advancedOptions")}
|
||||
|
||||
@@ -17,7 +17,7 @@ import { updateRuntimeConfigSettings } from "@/lib/api";
|
||||
import { invalidateToolsCatalog } from "@/lib/tools-catalog-cache";
|
||||
import type { NanobotClient } from "@/lib/nanobot-client";
|
||||
import type { RuntimeConfigValue, SettingsPayload } from "@/lib/types";
|
||||
import type { ApplySettingsPayload } from "@/components/settings/contracts";
|
||||
import type { ApplySettingsPayload, SettingsFocusTarget } from "@/components/settings/contracts";
|
||||
|
||||
type Draft = string | boolean;
|
||||
|
||||
@@ -172,13 +172,14 @@ export function useRuntimeConfigSettings(
|
||||
export type RuntimeConfigController = ReturnType<typeof useRuntimeConfigSettings>;
|
||||
|
||||
export function RuntimeConfigSettings({
|
||||
page, settings, state, client, sandboxSupported = false, onRestart, isRestarting, remoteBrowserAccess, children,
|
||||
page, settings, state, client, sandboxSupported = false, onRestart, isRestarting, remoteBrowserAccess, children, focusTarget,
|
||||
}: {
|
||||
page: RuntimeConfigPage;
|
||||
settings: SettingsPayload;
|
||||
state: RuntimeConfigController;
|
||||
client?: NanobotClient;
|
||||
sandboxSupported?: boolean;
|
||||
focusTarget?: SettingsFocusTarget;
|
||||
onRestart?: () => void;
|
||||
isRestarting: boolean;
|
||||
remoteBrowserAccess: boolean;
|
||||
@@ -310,6 +311,7 @@ export function RuntimeConfigSettings({
|
||||
</section>
|
||||
);
|
||||
return sandbox ? <SandboxSettings key={group.id} settings={settings} state={state}
|
||||
focusTarget={focusTarget}
|
||||
client={client!} isRestarting={isRestarting}>{section}</SandboxSettings> : section;
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -13,14 +13,16 @@ import { checkSandboxSettings } from "@/lib/api";
|
||||
import type { NanobotClient } from "@/lib/nanobot-client";
|
||||
import type { SandboxCheck, SettingsPayload } from "@/lib/types";
|
||||
import type { RuntimeConfigController } from "./RuntimeConfigSettings";
|
||||
import type { SettingsFocusTarget } from "@/components/settings/contracts";
|
||||
import { RUNTIME_CONFIG_FIELDS } from "./runtime-config-fields";
|
||||
|
||||
export function SandboxSettings({ settings, state, client, isRestarting, children }: {
|
||||
export function SandboxSettings({ settings, state, client, isRestarting, children, focusTarget }: {
|
||||
settings: SettingsPayload;
|
||||
state: RuntimeConfigController;
|
||||
client: NanobotClient;
|
||||
isRestarting: boolean;
|
||||
children: ReactNode;
|
||||
focusTarget?: SettingsFocusTarget;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const tx = (key: string) => t(`settings.sandbox.${key}`);
|
||||
@@ -30,6 +32,15 @@ export function SandboxSettings({ settings, state, client, isRestarting, childre
|
||||
const [checkError, setCheckError] = useState(false);
|
||||
const [confirmDisable, setConfirmDisable] = useState(false);
|
||||
const generation = useRef(0);
|
||||
const section = useRef<HTMLElement>(null);
|
||||
const launcherInput = useRef<HTMLInputElement>(null);
|
||||
useEffect(() => {
|
||||
if (!focusTarget) return;
|
||||
section.current?.scrollIntoView({ block: "start" });
|
||||
const target = focusTarget === "sandbox-launcher" && launcherInput.current && !launcherInput.current.disabled
|
||||
? launcherInput.current : section.current;
|
||||
target?.focus({ preventScroll: true });
|
||||
}, [focusTarget]);
|
||||
useEffect(() => {
|
||||
generation.current += 1;
|
||||
setResult(null);
|
||||
@@ -68,7 +79,7 @@ export function SandboxSettings({ settings, state, client, isRestarting, childre
|
||||
if (id === generation.current) setChecking(false);
|
||||
}
|
||||
};
|
||||
return <section aria-label={tx("title")}>
|
||||
return <section ref={section} tabIndex={-1} className="scroll-mt-6" aria-label={tx("title")}>
|
||||
<SettingsSectionTitle>{tx("title")}</SettingsSectionTitle>
|
||||
<SettingsGroup>
|
||||
<SettingsRow title={t("settings.runtimeConfig.fields.tools_exec_enable.label")}>
|
||||
@@ -98,12 +109,12 @@ export function SandboxSettings({ settings, state, client, isRestarting, childre
|
||||
{checkError ? <p role="alert" className="mt-2 text-caption text-destructive">{tx("checkError")}</p> : null}
|
||||
{error ? <p id="sandbox-settings-error" role="alert" className="mt-2 text-caption text-destructive">{error}</p> : null}
|
||||
</div>
|
||||
<SettingsAdvancedOptions>
|
||||
<SettingsAdvancedOptions initialOpen={focusTarget === "sandbox-launcher"}>
|
||||
{saved.supported_backend ? <div className="settings-list-inset pb-4 pt-2">
|
||||
<label htmlFor="runtime-tools.exec.sandbox_launcher" className="text-control-label">{tx("path")}</label>
|
||||
<p id="sandbox-launcher-help" className="mb-3 mt-1 text-caption leading-5 text-muted-foreground">{tx("pathHelp")}</p>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Input id="runtime-tools.exec.sandbox_launcher" className="min-w-0 flex-1 basis-56 text-ui" value={String(state.value(launcherField.path))}
|
||||
<Input ref={launcherInput} id="runtime-tools.exec.sandbox_launcher" className="min-w-0 flex-1 basis-56 text-ui" value={String(state.value(launcherField.path))}
|
||||
aria-invalid={state.invalidField === launcherField.path || undefined}
|
||||
aria-describedby={state.invalidField === launcherField.path ? "sandbox-launcher-help sandbox-settings-error" : "sandbox-launcher-help"}
|
||||
placeholder={tx("automatic")} disabled={busy} onChange={(event) => state.change(launcherField, event.target.value)} />
|
||||
|
||||
Reference in new issue
Block a user