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)} />
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { ArrowRight, ShieldAlert, X } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export type SandboxIssue = "missing" | "path" | "permissions" | "startup";
|
||||
|
||||
/** A command needs attention; the conversation itself is still usable. */
|
||||
export function SandboxNotice({ issue, onOpenSettings, onDismiss }: {
|
||||
issue: SandboxIssue;
|
||||
onOpenSettings: () => void;
|
||||
onDismiss: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return <div role="status" aria-live="polite" aria-atomic="true"
|
||||
className="thread-composer-notice mb-2 flex items-start gap-3 rounded-control border border-border/60 bg-muted/40 px-3 py-3 text-caption text-foreground animate-in fade-in-0 slide-in-from-bottom-1 motion-reduce:animate-none">
|
||||
<ShieldAlert className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
|
||||
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-x-4 gap-y-2">
|
||||
<div className="min-w-0 flex-1 basis-64 leading-5">
|
||||
<p className="font-medium">{t("settings.sandbox.notice.title")}</p>
|
||||
<p className="mt-0.5 break-words text-muted-foreground">{t(`settings.sandbox.notice.${issue}`)}</p>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" className="shrink-0 gap-1.5 rounded-full" onClick={onOpenSettings}>
|
||||
{t("settings.sandbox.notice.openSettings")}<ArrowRight className="h-3.5 w-3.5" aria-hidden />
|
||||
</Button>
|
||||
</div>
|
||||
<Button variant="ghost" size="icon" className="h-6 w-6 shrink-0 rounded-full text-muted-foreground"
|
||||
aria-label={t("common.dismiss")} onClick={onDismiss}><X className="h-3.5 w-3.5" aria-hidden /></Button>
|
||||
</div>;
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import { SessionHandleLabel } from "@/components/SessionHandleLabel";
|
||||
import { PromptNavigator } from "@/components/thread/PromptNavigator";
|
||||
import { usePromptHistory } from "@/hooks/usePromptHistory";
|
||||
import { ModelFallbackNotice } from "@/components/thread/ModelFallbackNotice";
|
||||
import { SandboxNotice } from "@/components/thread/SandboxNotice";
|
||||
import { useSandboxNotice } from "@/components/thread/useSandboxNotice";
|
||||
import { RecoveryNotice } from "@/components/thread/RecoveryNotice";
|
||||
import { SubagentTasksProvider } from "@/components/thread/SubagentTasks";
|
||||
import { SubagentTaskDock } from "@/components/thread/SubagentTaskDock";
|
||||
@@ -254,6 +256,7 @@ interface ThreadShellProps {
|
||||
settingsSnapshot?: SettingsPayload | null;
|
||||
settingsLoading?: boolean;
|
||||
onOpenModelSettings?: () => void;
|
||||
onOpenSandboxSettings?: (target: "sandbox" | "sandbox-launcher") => void;
|
||||
skills?: SkillSummary[];
|
||||
}
|
||||
|
||||
@@ -476,6 +479,7 @@ export function ThreadShell({
|
||||
settingsSnapshot = null,
|
||||
settingsLoading = false,
|
||||
onOpenModelSettings,
|
||||
onOpenSandboxSettings,
|
||||
skills = [],
|
||||
}: ThreadShellProps) {
|
||||
const { t } = useTranslation();
|
||||
@@ -534,6 +538,7 @@ export function ThreadShell({
|
||||
reauthProvider?: string;
|
||||
dismissed: boolean;
|
||||
} | null>(null);
|
||||
const sandboxNotice = useSandboxNotice(client, chatId, webuiCapabilities.includes("webui.sandbox-settings.v1"));
|
||||
const [heroGreetingKey, setHeroGreetingKey] = useState(randomHeroGreetingKey);
|
||||
const [submittedViewportTurnId, setSubmittedViewportTurnId] = useState<string | null>(null);
|
||||
const { state: previewState, openFile, resolveFile, selectTab, closeTab, close: closePreview, setWidth: setFilePreviewWidth } =
|
||||
@@ -1353,6 +1358,12 @@ export function ThreadShell({
|
||||
onOpenSettings={onOpenModelSettings}
|
||||
/>
|
||||
) : null}
|
||||
{sandboxNotice.issue && onOpenSandboxSettings && !streamError && !recoveryState ? (
|
||||
<SandboxNotice issue={sandboxNotice.issue} onDismiss={sandboxNotice.dismiss}
|
||||
onOpenSettings={() => onOpenSandboxSettings(
|
||||
sandboxNotice.issue === "missing" || sandboxNotice.issue === "path" ? "sandbox-launcher" : "sandbox",
|
||||
)} />
|
||||
) : null}
|
||||
{restoredFirstDraft?.chatId === chatId && restoredFirstDraft.error ? (
|
||||
<p role="alert" className="px-3 text-sm text-destructive">{restoredFirstDraft.error}</p>
|
||||
) : null}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
import type { NanobotClient } from "@/lib/nanobot-client";
|
||||
import { normalizeToolProgressEvents } from "@/lib/tool-traces";
|
||||
import type { SandboxIssue } from "./SandboxNotice";
|
||||
|
||||
const issues = new Map<string, SandboxIssue>([
|
||||
["sandbox_launcher_missing", "missing"],
|
||||
["sandbox_path_not_absolute", "path"],
|
||||
["sandbox_not_executable", "path"],
|
||||
["sandbox_path_unavailable", "path"],
|
||||
["sandbox_agent_writable", "permissions"],
|
||||
["sandbox_unprotected_installation", "permissions"],
|
||||
["sandbox_start_failed", "startup"],
|
||||
]);
|
||||
|
||||
/** Observe live execution only; opening history must not replay old warnings. */
|
||||
export function useSandboxNotice(client: NanobotClient, chatId: string | null, enabled: boolean) {
|
||||
const scope = useMemo(() => ({ client, chatId, enabled }), [client, chatId, enabled]);
|
||||
const [notice, setNotice] = useState<{
|
||||
scope: typeof scope;
|
||||
issue: SandboxIssue;
|
||||
turnId: string | null;
|
||||
dismissed: boolean;
|
||||
} | null>(null);
|
||||
useEffect(() => {
|
||||
setNotice(null);
|
||||
if (!enabled || !chatId) return;
|
||||
return client.onChat(chatId, (event) => {
|
||||
if ((event.event === "message_accepted" || event.event === "user_message") && event.starts_turn) {
|
||||
setNotice(null);
|
||||
return;
|
||||
}
|
||||
if (event.event !== "message") return;
|
||||
const latestTurn = client.getRunState(chatId).latestTurnId;
|
||||
if (event.turn_id && latestTurn && event.turn_id !== latestTurn) return;
|
||||
const turnId = event.turn_id ?? latestTurn;
|
||||
for (const tool of normalizeToolProgressEvents(event.tool_events)) {
|
||||
if (tool.name !== "exec") continue;
|
||||
if (tool.phase === "end") {
|
||||
setNotice(null);
|
||||
} else if (tool.phase === "error" && typeof tool.error_code === "string") {
|
||||
const issue = issues.get(tool.error_code);
|
||||
if (!issue) continue;
|
||||
setNotice((current) => current?.scope === scope && current.issue === issue && current.turnId === turnId
|
||||
? current : { scope, issue, turnId, dismissed: false });
|
||||
}
|
||||
}
|
||||
});
|
||||
}, [client, chatId, enabled, scope]);
|
||||
return {
|
||||
issue: enabled && notice?.scope === scope && !notice.dismissed ? notice.issue : null,
|
||||
dismiss: () => setNotice((current) => current?.scope === scope ? { ...current, dismissed: true } : current),
|
||||
};
|
||||
}
|
||||
@@ -47,15 +47,16 @@ export function DisclosureContent({
|
||||
}
|
||||
|
||||
export function Disclosure({
|
||||
summary, children, className, summaryClassName, contentClassName,
|
||||
summary, children, className, summaryClassName, contentClassName, initialOpen = false,
|
||||
}: {
|
||||
summary: ReactNode;
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
summaryClassName?: string;
|
||||
contentClassName?: string;
|
||||
initialOpen?: boolean;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [open, setOpen] = useState(initialOpen);
|
||||
const id = useId();
|
||||
return (
|
||||
<div className={className}>
|
||||
|
||||
Reference in new issue
Block a user