feat(webui): guide sandbox launcher recovery from chat

This commit is contained in:
Xubin Ren committed 2026-11-08 14:29:46 +08:00
1 parent 16250540d3
commit f5e5bd6ea0
47 files changed
+613 -32

No files matched your search

@@ -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),
};
}