mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 12:24:39 +00:00
feat(sandbox): default Network Sandbox to off and add settings toggle switch (#304)
This commit is contained in:
@@ -5,7 +5,8 @@ import { ScrollArea } from '@/ui/components/ui/scroll-area'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Loader2, Plus, X, Globe, Check, Trash2, ShieldAlert } from 'lucide-react'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { Loader2, Plus, X, Globe, Check, Trash2, ShieldAlert, Info } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
|
||||
@@ -25,7 +26,11 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
})
|
||||
|
||||
const { mutate: updateSandbox, isPending: isUpdating } = useMutation({
|
||||
mutationFn: async (params: { allowedDomains: string[]; pendingDomains: string[] }) => {
|
||||
mutationFn: async (params: {
|
||||
networkSandboxEnabled?: boolean
|
||||
allowedDomains?: string[]
|
||||
pendingDomains?: string[]
|
||||
}) => {
|
||||
const res = await client.api.teams[':teamId'].sandbox.$put({
|
||||
param: { teamId },
|
||||
json: params,
|
||||
@@ -42,6 +47,12 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
},
|
||||
})
|
||||
|
||||
const handleToggleNetworkSandbox = (enabled: boolean) => {
|
||||
updateSandbox({
|
||||
networkSandboxEnabled: enabled,
|
||||
})
|
||||
}
|
||||
|
||||
const handleAddDomain = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!newDomain.trim()) return
|
||||
@@ -80,6 +91,8 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
)
|
||||
}
|
||||
|
||||
const isNetworkSandboxEnabled = !!sandbox?.networkSandboxEnabled
|
||||
|
||||
return (
|
||||
<ScrollArea className="h-full">
|
||||
<div className="space-y-6 pr-4 pb-8">
|
||||
@@ -92,14 +105,42 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
<CardDescription>{m.network_sandbox_description()}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{/* Toggle Switch */}
|
||||
<div className="flex items-center justify-between p-4 mb-6 rounded-lg border border-border bg-muted/30">
|
||||
<div className="space-y-0.5 pr-4">
|
||||
<label
|
||||
htmlFor="network-sandbox-switch"
|
||||
className="text-sm font-medium text-foreground cursor-pointer"
|
||||
>
|
||||
{m.enable_network_sandbox()}
|
||||
</label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{m.network_sandbox_enabled_description()}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="network-sandbox-switch"
|
||||
checked={isNetworkSandboxEnabled}
|
||||
onCheckedChange={handleToggleNetworkSandbox}
|
||||
disabled={isUpdating}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{!isNetworkSandboxEnabled && (
|
||||
<div className="flex items-start gap-2.5 p-3.5 mb-6 rounded-lg bg-amber-500/10 border border-amber-500/20 text-amber-700 dark:text-amber-300 text-sm">
|
||||
<Info className="w-4 h-4 mt-0.5 shrink-0" />
|
||||
<span>{m.network_sandbox_disabled_notice()}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleAddDomain} className="flex gap-2 mb-6">
|
||||
<Input
|
||||
placeholder="e.g. api.openai.com"
|
||||
value={newDomain}
|
||||
onChange={(e) => setNewDomain(e.target.value)}
|
||||
disabled={isUpdating}
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
/>
|
||||
<Button type="submit" disabled={isUpdating}>
|
||||
<Button type="submit" disabled={isUpdating || !isNetworkSandboxEnabled}>
|
||||
{isUpdating ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
@@ -114,7 +155,7 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
{m.allowed_domains()}
|
||||
</h4>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{sandbox?.allowedDomains.map((domain) => (
|
||||
{sandbox?.allowedDomains.map((domain: string) => (
|
||||
<div
|
||||
key={domain}
|
||||
className="flex items-center gap-1 px-3 py-1.5 bg-muted rounded-full text-sm border border-border transition-all hover:border-muted-foreground/50"
|
||||
@@ -122,8 +163,8 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
<span className="font-medium text-foreground">{domain}</span>
|
||||
<button
|
||||
onClick={() => handleRemoveDomain(domain)}
|
||||
className="ml-1 text-muted-foreground hover:text-destructive transition-colors"
|
||||
disabled={isUpdating}
|
||||
className="ml-1 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
@@ -152,7 +193,7 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
<div className="space-y-3">
|
||||
{sandbox?.pendingDomains && sandbox.pendingDomains.length > 0 ? (
|
||||
<div className="divide-y divide-border">
|
||||
{sandbox.pendingDomains.map((domain) => (
|
||||
{sandbox.pendingDomains.map((domain: string) => (
|
||||
<div
|
||||
key={domain}
|
||||
className="flex items-center justify-between py-2.5 first:pt-0 last:pb-0"
|
||||
@@ -166,7 +207,7 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
variant="outline"
|
||||
className="h-8 border-emerald-500/20 text-emerald-600 hover:bg-emerald-500/10 hover:text-emerald-600 dark:text-emerald-400 dark:hover:bg-emerald-500/20"
|
||||
onClick={() => handleApproveDomain(domain)}
|
||||
disabled={isUpdating}
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
>
|
||||
<Check className="w-4 h-4 mr-1.5" />
|
||||
{m.approve()}
|
||||
@@ -176,7 +217,7 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
variant="outline"
|
||||
className="h-8 border-destructive/20 text-destructive hover:bg-destructive/10"
|
||||
onClick={() => handleDeletePendingDomain(domain)}
|
||||
disabled={isUpdating}
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
>
|
||||
<Trash2 className="w-4 h-4 mr-1.5" />
|
||||
{m.delete()}
|
||||
|
||||
@@ -491,7 +491,10 @@
|
||||
"failed_to_update_sandbox_settings": "Failed to update sandbox settings",
|
||||
"domain_already_exists": "Domain already exists",
|
||||
"network_sandbox": "Network Sandbox",
|
||||
"network_sandbox_description": "Configure allowed domains for the sandboxed agent. By default, only essential domains are allowed.",
|
||||
"network_sandbox_description": "Configure domain access controls for the sandboxed agent.",
|
||||
"enable_network_sandbox": "Enable Network Sandbox",
|
||||
"network_sandbox_enabled_description": "When enabled, network requests from the agent are restricted to allowed domains. When disabled, all network requests are permitted.",
|
||||
"network_sandbox_disabled_notice": "Network Sandbox is currently OFF. All outbound network requests from agent scripts are permitted without restrictions.",
|
||||
"add_domain": "Add Domain",
|
||||
"allowed_domains": "Allowed Domains",
|
||||
"no_custom_domains_allowed": "No custom domains allowed",
|
||||
|
||||
@@ -491,7 +491,10 @@
|
||||
"failed_to_update_sandbox_settings": "更新沙箱设置失败",
|
||||
"domain_already_exists": "域名已存在",
|
||||
"network_sandbox": "网络沙箱",
|
||||
"network_sandbox_description": "配置沙箱智能体的允许域名。默认情况下,仅允许必要域名。",
|
||||
"network_sandbox_description": "配置沙箱智能体的域名访问控制。",
|
||||
"enable_network_sandbox": "启用网络沙箱",
|
||||
"network_sandbox_enabled_description": "启用后,智能体的网络请求将受限于允许的域名列表。禁用时,允许所有网络请求。",
|
||||
"network_sandbox_disabled_notice": "网络沙箱目前处于关闭状态。智能体脚本的所有出站网络请求均不受限制。",
|
||||
"add_domain": "添加域名",
|
||||
"allowed_domains": "允许的域名",
|
||||
"no_custom_domains_allowed": "没有自定义允许域名",
|
||||
|
||||
+3
@@ -472,6 +472,9 @@ export * from "./failed_to_update_sandbox_settings.js";
|
||||
export * from "./domain_already_exists.js";
|
||||
export * from "./network_sandbox.js";
|
||||
export * from "./network_sandbox_description.js";
|
||||
export * from "./enable_network_sandbox.js";
|
||||
export * from "./network_sandbox_enabled_description.js";
|
||||
export * from "./network_sandbox_disabled_notice.js";
|
||||
export * from "./add_domain.js";
|
||||
export * from "./allowed_domains.js";
|
||||
export * from "./no_custom_domains_allowed.js";
|
||||
|
||||
+3
@@ -474,6 +474,9 @@ export * from './failed_to_update_sandbox_settings.js'
|
||||
export * from './domain_already_exists.js'
|
||||
export * from './network_sandbox.js'
|
||||
export * from './network_sandbox_description.js'
|
||||
export * from './enable_network_sandbox.js'
|
||||
export * from './network_sandbox_enabled_description.js'
|
||||
export * from './network_sandbox_disabled_notice.js'
|
||||
export * from './add_domain.js'
|
||||
export * from './allowed_domains.js'
|
||||
export * from './no_custom_domains_allowed.js'
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Enable Network Sandbox" |
|
||||
*
|
||||
* @param {Enable_Network_SandboxInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const enable_network_sandbox: ((inputs?: Enable_Network_SandboxInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Enable_Network_SandboxInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Enable_Network_SandboxInputs = {};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Enable_Network_SandboxInputs */
|
||||
|
||||
const en_enable_network_sandbox = /** @type {(inputs: Enable_Network_SandboxInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Enable Network Sandbox`)
|
||||
};
|
||||
|
||||
const zh_enable_network_sandbox = /** @type {(inputs: Enable_Network_SandboxInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`启用网络沙箱`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Enable Network Sandbox" |
|
||||
*
|
||||
* @param {Enable_Network_SandboxInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const enable_network_sandbox = /** @type {((inputs?: Enable_Network_SandboxInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Enable_Network_SandboxInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_enable_network_sandbox(inputs)
|
||||
return zh_enable_network_sandbox(inputs)
|
||||
});
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Configure allowed domains for the sandboxed agent. By default, only essential domains are allowed." |
|
||||
* | "Configure domain access controls for the sandboxed agent." |
|
||||
*
|
||||
* @param {Network_Sandbox_DescriptionInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
|
||||
@@ -6,17 +6,17 @@ import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
/** @typedef {{}} Network_Sandbox_DescriptionInputs */
|
||||
|
||||
const en_network_sandbox_description = /** @type {(inputs: Network_Sandbox_DescriptionInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Configure allowed domains for the sandboxed agent. By default, only essential domains are allowed.`)
|
||||
return /** @type {LocalizedString} */ (`Configure domain access controls for the sandboxed agent.`)
|
||||
};
|
||||
|
||||
const zh_network_sandbox_description = /** @type {(inputs: Network_Sandbox_DescriptionInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`配置沙箱智能体的允许域名。默认情况下,仅允许必要域名。`)
|
||||
return /** @type {LocalizedString} */ (`配置沙箱智能体的域名访问控制。`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Configure allowed domains for the sandboxed agent. By default, only essential domains are allowed." |
|
||||
* | "Configure domain access controls for the sandboxed agent." |
|
||||
*
|
||||
* @param {Network_Sandbox_DescriptionInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Network Sandbox is currently OFF. All outbound network requests from agent scripts are permitted without restrictions." |
|
||||
*
|
||||
* @param {Network_Sandbox_Disabled_NoticeInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const network_sandbox_disabled_notice: ((inputs?: Network_Sandbox_Disabled_NoticeInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Network_Sandbox_Disabled_NoticeInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Network_Sandbox_Disabled_NoticeInputs = {};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Network_Sandbox_Disabled_NoticeInputs */
|
||||
|
||||
const en_network_sandbox_disabled_notice = /** @type {(inputs: Network_Sandbox_Disabled_NoticeInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Network Sandbox is currently OFF. All outbound network requests from agent scripts are permitted without restrictions.`)
|
||||
};
|
||||
|
||||
const zh_network_sandbox_disabled_notice = /** @type {(inputs: Network_Sandbox_Disabled_NoticeInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`网络沙箱目前处于关闭状态。智能体脚本的所有出站网络请求均不受限制。`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Network Sandbox is currently OFF. All outbound network requests from agent scripts are permitted without restrictions." |
|
||||
*
|
||||
* @param {Network_Sandbox_Disabled_NoticeInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const network_sandbox_disabled_notice = /** @type {((inputs?: Network_Sandbox_Disabled_NoticeInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Network_Sandbox_Disabled_NoticeInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_network_sandbox_disabled_notice(inputs)
|
||||
return zh_network_sandbox_disabled_notice(inputs)
|
||||
});
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "When enabled, network requests from the agent are restricted to allowed domains. When disabled, all network requests are permitted." |
|
||||
*
|
||||
* @param {Network_Sandbox_Enabled_DescriptionInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const network_sandbox_enabled_description: ((inputs?: Network_Sandbox_Enabled_DescriptionInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Network_Sandbox_Enabled_DescriptionInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Network_Sandbox_Enabled_DescriptionInputs = {};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Network_Sandbox_Enabled_DescriptionInputs */
|
||||
|
||||
const en_network_sandbox_enabled_description = /** @type {(inputs: Network_Sandbox_Enabled_DescriptionInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`When enabled, network requests from the agent are restricted to allowed domains. When disabled, all network requests are permitted.`)
|
||||
};
|
||||
|
||||
const zh_network_sandbox_enabled_description = /** @type {(inputs: Network_Sandbox_Enabled_DescriptionInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`启用后,智能体的网络请求将受限于允许的域名列表。禁用时,允许所有网络请求。`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "When enabled, network requests from the agent are restricted to allowed domains. When disabled, all network requests are permitted." |
|
||||
*
|
||||
* @param {Network_Sandbox_Enabled_DescriptionInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const network_sandbox_enabled_description = /** @type {((inputs?: Network_Sandbox_Enabled_DescriptionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Network_Sandbox_Enabled_DescriptionInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_network_sandbox_enabled_description(inputs)
|
||||
return zh_network_sandbox_enabled_description(inputs)
|
||||
});
|
||||
Reference in New Issue
Block a user