feat(sandbox-ui): show host sandbox upgrade command in local mode

- Display copyable host upgrade command (`git pull` / `./update.sh --upgrade --tag <version>`) on /system/sandbox and settings SandboxCard when running in local mode.
- Hide the upgrade prompt automatically when Docker sandbox mode is enabled.
This commit is contained in:
ji ruo committed 2026-12-04 15:43:21 +08:00
1 parent c49aa703c2
commit efeb150f26
2 files changed
+145 -6

No files matched your search

+81 -3
View File
@@ -7,6 +7,8 @@ import Link from "next/link";
import {
ActivityIcon,
BoxIcon,
CheckIcon,
CopyIcon,
CpuIcon,
ExternalLinkIcon,
HardDriveIcon,
@@ -15,7 +17,9 @@ import {
RotateCcwIcon,
SearchIcon,
Settings2Icon,
ShieldCheckIcon,
SquareIcon,
TerminalIcon,
Trash2Icon,
} from "lucide-react";
import { toast } from "sonner";
@@ -87,7 +91,8 @@ export default function SandboxPage() {
const [saving, setSaving] = React.useState(false);
const [pruning, setPruning] = React.useState(false);
const [busyKey, setBusyKey] = React.useState<string>("");
const [upgradeTag, setUpgradeTag] = React.useState("v0.3.34");
const [copiedUpgradeCmd, setCopiedUpgradeCmd] = React.useState(false);
// Filters
const [scopeFilter, setScopeFilter] = React.useState<"all" | "task" | "session">("all");
const [stateFilter, setStateFilter] = React.useState<"all" | "running" | "stopped">("all");
@@ -165,6 +170,33 @@ export default function SandboxPage() {
void load(false, true, true);
}, [load]);
React.useEffect(() => {
api
.version()
.then((v) => {
const raw = (v.version ?? "").trim().replace(/^v(?=\d)/, "");
if (/^\d+\.\d+\.\d+$/.test(raw)) {
setUpgradeTag(`v${raw}`);
}
})
.catch(() => {
// keep default release tag fallback
});
}, []);
const upgradeCommand = `git pull\n./update.sh --upgrade --tag ${upgradeTag}`;
const handleCopyUpgradeCommand = async () => {
try {
await navigator.clipboard.writeText(upgradeCommand);
setCopiedUpgradeCmd(true);
toast.success(L("升级命令已复制", "Upgrade command copied"));
window.setTimeout(() => setCopiedUpgradeCmd(false), 2000);
} catch {
toast.error(L("复制失败,请手动复制命令", "Copy failed, please copy manually"));
}
};
React.useEffect(() => {
if (!autoRefresh) return;
const timer = window.setInterval(() => {
@@ -351,8 +383,8 @@ export default function SandboxPage() {
`Manage lifecycle and resource usage for isolated task and chat containers (network: ${status.network}, ICC disabled).`,
)
: L(
"当前为本地执行模式。部署时配置 ARTEX_SANDBOX_MODE=docker 即可启用任务与对话级容器隔离。",
"Running in local execution mode. Set ARTEX_SANDBOX_MODE=docker to enable container isolation.",
"当前为本地执行模式,请按下方命令在宿主机升级至沙箱隔离版以启用任务与对话级容器隔离。",
"Running in local execution mode. Use the host command below to upgrade to the Docker sandbox edition.",
)}
</p>
</div>
@@ -394,6 +426,52 @@ export default function SandboxPage() {
</div>
) : null}
{status && !status.enabled ? (
<Card className="border-amber-500/40 bg-amber-500/5">
<CardHeader className="pb-3">
<CardTitle className="flex items-center gap-2 text-base">
<ShieldCheckIcon className="size-4 text-amber-600 dark:text-amber-400" />
{L("升级至沙箱隔离版(Sandbox)", "Upgrade to Sandbox Edition")}
</CardTitle>
<CardDescription>
{L(
"页面内「一键更新」仅替换容器内的 artex 主控程序,不会自动拉起 docker-socket-proxy、artex-gateway 透明网关与独立沙箱容器。请在宿主机原部署目录执行以下命令完成切换:",
"In-app updates only replace the artex binary inside the container and cannot start docker-socket-proxy, artex-gateway, or isolated sandbox containers. Run the following commands on the host in your deployment directory to switch:",
)}
</CardDescription>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex items-start justify-between gap-3 rounded-md border bg-background px-3.5 py-2.5">
<div className="flex min-w-0 items-start gap-2.5">
<TerminalIcon className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
<pre className="overflow-x-auto font-mono text-foreground text-xs leading-relaxed">
<code>{upgradeCommand}</code>
</pre>
</div>
<Button
size="sm"
variant="outline"
className="h-7 shrink-0 gap-1.5 px-2.5 text-xs"
onClick={() => void handleCopyUpgradeCommand()}
>
{copiedUpgradeCmd ? (
<CheckIcon className="size-3.5 text-emerald-500" />
) : (
<CopyIcon className="size-3.5" />
)}
{copiedUpgradeCmd ? L("已复制", "Copied") : L("复制命令", "Copy")}
</Button>
</div>
<p className="text-muted-foreground text-xs leading-relaxed">
{L(
`升级会保留原有 PostgreSQL 数据、./data 与 ./skills,切换后无法回滚但会显著提高运行安全性。若非 git clone 部署,请先同步最新 docker-compose.yml、update.sh 与 scripts/ 后再执行 ./update.sh --upgrade --tag ${upgradeTag};完成后刷新本页即可进入 Docker 沙箱模式。`,
`Preserves PostgreSQL data, ./data, and ./skills. This switch is irreversible but significantly improves isolation security. If not deployed via git clone, sync the latest docker-compose.yml, update.sh, and scripts/ first, then run ./update.sh --upgrade --tag ${upgradeTag} and refresh this page.`,
)}
</p>
</CardContent>
</Card>
) : null}
{/* Summary KPI cards */}
{status?.enabled ? (
<div className="grid min-w-0 grid-cols-2 gap-3 lg:grid-cols-4">
@@ -6,11 +6,14 @@ import Link from "next/link";
import {
BoxIcon,
CheckIcon,
CopyIcon,
ExternalLinkIcon,
PlayIcon,
RefreshCwIcon,
RotateCcwIcon,
SquareIcon,
TerminalIcon,
Trash2Icon,
} from "lucide-react";
import { toast } from "sonner";
@@ -53,7 +56,8 @@ export function SandboxCard() {
const [saving, setSaving] = React.useState(false);
const [pruning, setPruning] = React.useState(false);
const [busyKey, setBusyKey] = React.useState("");
const [upgradeTag, setUpgradeTag] = React.useState("v0.3.34");
const [copiedUpgradeCmd, setCopiedUpgradeCmd] = React.useState(false);
const [image, setImage] = React.useState("");
const [memoryMB, setMemoryMB] = React.useState("2048");
const [cpus, setCpus] = React.useState("2");
@@ -102,6 +106,33 @@ export function SandboxCard() {
void load(true);
}, [load]);
React.useEffect(() => {
api
.version()
.then((v) => {
const raw = (v.version ?? "").trim().replace(/^v(?=\d)/, "");
if (/^\d+\.\d+\.\d+$/.test(raw)) {
setUpgradeTag(`v${raw}`);
}
})
.catch(() => {
// keep default release tag fallback
});
}, []);
const upgradeCommand = `git pull && ./update.sh --upgrade --tag ${upgradeTag}`;
const handleCopyUpgradeCommand = async () => {
try {
await navigator.clipboard.writeText(upgradeCommand);
setCopiedUpgradeCmd(true);
toast.success(L("升级命令已复制", "Upgrade command copied"));
window.setTimeout(() => setCopiedUpgradeCmd(false), 2000);
} catch {
toast.error(L("复制失败,请手动复制命令", "Copy failed, please copy manually"));
}
};
const handleSave = async () => {
setSaving(true);
try {
@@ -235,8 +266,8 @@ export function SandboxCard() {
`Docker sandbox isolation is active (network: ${status.network}, ICC disabled). Tasks and chat sessions execute tools in isolated non-root containers.`,
)
: L(
"当前为本地执行模式。部署时设置 ARTEX_SANDBOX_MODE=docker 即可启用任务级容器隔离。",
"Running in local mode. Set ARTEX_SANDBOX_MODE=docker on deployment to enable per-task container isolation.",
"当前为本地执行模式,请在宿主机执行升级脚本切换至沙箱隔离版。",
"Running in local mode. Run the host upgrade script to switch to the Docker sandbox edition.",
)}
</CardDescription>
</CardHeader>
@@ -248,6 +279,36 @@ export function SandboxCard() {
</div>
) : null}
{status && !status.enabled ? (
<div className="space-y-2 rounded-md border border-amber-500/40 bg-amber-500/5 p-3">
<p className="text-muted-foreground text-xs">
{L(
"在宿主机原部署目录执行以下命令升级至沙箱隔离版(保留数据库、./data 与 ./skills):",
"Run the following command on the host deployment directory to upgrade to the sandbox edition (preserves DB, ./data, and ./skills):",
)}
</p>
<div className="flex items-center justify-between gap-2 rounded border bg-background px-3 py-2">
<div className="flex min-w-0 items-center gap-2">
<TerminalIcon className="size-3.5 shrink-0 text-muted-foreground" />
<code className="overflow-x-auto font-mono text-foreground text-xs">{upgradeCommand}</code>
</div>
<Button
size="sm"
variant="outline"
className="h-7 shrink-0 gap-1 px-2 text-xs"
onClick={() => void handleCopyUpgradeCommand()}
>
{copiedUpgradeCmd ? (
<CheckIcon className="size-3.5 text-emerald-500" />
) : (
<CopyIcon className="size-3.5" />
)}
{copiedUpgradeCmd ? L("已复制", "Copied") : L("复制", "Copy")}
</Button>
</div>
</div>
) : null}
{status?.enabled ? (
<>
<div className="grid grid-cols-1 gap-3 md:grid-cols-3">