ui(sandbox): explain who still holds a config (#2816)

* ui(sandbox): explain who still holds a config instead of occupancy metrics

The occupancy drawer was a three-stat dashboard plus truncated session
IDs, which did not say why a config could not be deleted. Show a plain
summary, named sessions, and bound agents; slim the card menu to edit /
who-is-using / delete.

* ui(sandbox): tighten occupancy chrome and rename running instances

Drop TDesign's extra divider (it stacked a second line), compact the
card menu and drawer, and replace the colloquial copy with a single
sentence plus the session list.

* ui(sandbox): match occupancy UI to settings chrome

Drop the homemade menu divider and occupancy-only drawer styling that stacked extra hairlines. Use the same dropdown as other setting cards, and label occupying chats as sessions so the drawer is readable.
main
lyingbug 2026-08-26 18:19:42 +08:00 committed by GitHub
parent 7fda02637c
commit 45be62276a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 205 additions and 100 deletions

View File

@ -1106,13 +1106,18 @@ export default {
identityFieldHint: 'While this config owns sandboxes, these cannot be changed: backend type, API endpoint, API key, sandbox domain, proxy endpoint.',
connectionLockedBySkills: 'This sandbox already has skills. Connection, credentials, and DNS would retarget the skill snapshot, and DNS only applies after a template rebuild. Create a new sandbox instead.',
connectionLockedByInFlight: 'A skill is still installing or being removed. Connection, credentials, and DNS cannot change until that finishes.',
viewSandboxes: 'View sandbox usage',
inventoryTitle: 'Sandbox usage',
viewSandboxes: 'Running instances',
inventoryTitle: 'Running instances',
inventoryDrawerDesc: 'Sandboxes this config still holds, plus the sessions and agents affected.',
inventoryFailed: 'Failed to load sandbox usage',
sandboxCount: 'Sandboxes',
sandboxCountUnknown: 'Unknown (backend unreachable)',
inventoryUnverifiableHint: 'The backend is unreachable, so the sandbox count is unknown — that is not the same as none.',
inventorySessions: 'Sessions',
inventorySessionKind: 'Conversation',
inventoryEmpty: 'No occupying sessions',
inventoryAgentsTitle: 'Linked agents',
inventoryUntitledSession: 'Untitled session',
sandboxesStillLive: 'This config still owns {count} running or paused sandbox(es), so identity fields cannot be changed yet.',
blockedHint: 'End or delete those sessions (deleting a session destroys its sandbox), or create a second config and point the agents at it.',
unverifiableBlocked: 'The backend cannot be reached to verify whether sandboxes remain, so the stored credentials will not be overwritten.',

View File

@ -4959,13 +4959,18 @@ export default {
identityFieldHint: 'While this config owns sandboxes, these cannot be changed: backend type, API endpoint, API key, sandbox domain, proxy endpoint.',
connectionLockedBySkills: '이 샌드박스에는 이미 Skill이 있습니다. 연결, 자격 증명, DNS를 바꾸면 스킬 스냅샷의 환경이 달라지고, DNS는 템플릿을 재구축해야 적용됩니다. 새 샌드박스를 만드세요.',
connectionLockedByInFlight: 'Skill을 설치하거나 제거하는 중입니다. 끝날 때까지 연결, 자격 증명, DNS를 바꿀 수 없습니다.',
viewSandboxes: 'View sandbox usage',
inventoryTitle: 'Sandbox usage',
viewSandboxes: '실행 인스턴스',
inventoryTitle: '실행 인스턴스',
inventoryDrawerDesc: '이 설정이 아직 점유한 샌드박스와 영향을 받는 세션·에이전트입니다.',
inventoryFailed: 'Failed to load sandbox usage',
sandboxCount: 'Sandboxes',
sandboxCountUnknown: 'Unknown (backend unreachable)',
inventoryUnverifiableHint: 'The backend is unreachable, so the sandbox count is unknown — that is not the same as none.',
inventorySessions: '세션',
inventorySessionKind: '대화',
inventoryEmpty: '점유 중인 세션이 없습니다',
inventoryAgentsTitle: '연결된 에이전트',
inventoryUntitledSession: '제목 없는 세션',
sandboxesStillLive: 'This config still owns {count} running or paused sandbox(es), so identity fields cannot be changed yet.',
blockedHint: 'End or delete those sessions (deleting a session destroys its sandbox), or create a second config and point the agents at it.',
unverifiableBlocked: 'The backend cannot be reached to verify whether sandboxes remain, so the stored credentials will not be overwritten.',

View File

@ -4959,13 +4959,18 @@ export default {
identityFieldHint: 'While this config owns sandboxes, these cannot be changed: backend type, API endpoint, API key, sandbox domain, proxy endpoint.',
connectionLockedBySkills: 'В этой песочнице уже установлены навыки. Смена подключения, учётных данных или DNS меняет среду снимка, а DNS применяется только после пересборки шаблона. Создайте новую песочницу.',
connectionLockedByInFlight: 'Навык ещё устанавливается или удаляется. Подключение, учётные данные и DNS нельзя менять, пока это не закончится.',
viewSandboxes: 'View sandbox usage',
inventoryTitle: 'Sandbox usage',
viewSandboxes: 'Запущенные экземпляры',
inventoryTitle: 'Запущенные экземпляры',
inventoryDrawerDesc: 'Песочницы, которые всё ещё занимает эта конфигурация, а также затронутые сессии и агенты.',
inventoryFailed: 'Failed to load sandbox usage',
sandboxCount: 'Sandboxes',
sandboxCountUnknown: 'Unknown (backend unreachable)',
inventoryUnverifiableHint: 'The backend is unreachable, so the sandbox count is unknown — that is not the same as none.',
inventorySessions: 'Сессии',
inventorySessionKind: 'Чат',
inventoryEmpty: 'Нет занимающих сессий',
inventoryAgentsTitle: 'Связанные агенты',
inventoryUntitledSession: 'Сессия без названия',
sandboxesStillLive: 'This config still owns {count} running or paused sandbox(es), so identity fields cannot be changed yet.',
blockedHint: 'End or delete those sessions (deleting a session destroys its sandbox), or create a second config and point the agents at it.',
unverifiableBlocked: 'The backend cannot be reached to verify whether sandboxes remain, so the stored credentials will not be overwritten.',

View File

@ -4961,13 +4961,18 @@ export default {
identityFieldHint: '该配置下有沙箱运行时,以下项无法修改:后端类型、API 端点、API Key、沙箱域名、Proxy 端点。',
connectionLockedBySkills: '该沙箱已安装 Skill。连接地址、凭据和 DNS 会改变技能快照所属环境,且 DNS 需重建模板才能生效;请新建一份沙箱。',
connectionLockedByInFlight: '该沙箱正在安装或移除 Skill,完成前不能更换连接、凭据或 DNS。',
viewSandboxes: '查看沙箱占用',
inventoryTitle: '沙箱占用',
viewSandboxes: '运行实例',
inventoryTitle: '运行实例',
inventoryDrawerDesc: '该配置当前占用的沙箱,以及受影响的会话与智能体。',
inventoryFailed: '获取沙箱占用失败',
sandboxCount: '沙箱数量',
sandboxCountUnknown: '未知(无法连接该后端)',
inventoryUnverifiableHint: '无法连接该后端,因此沙箱数量未知——这不代表没有沙箱。',
inventorySessions: '会话',
inventorySessionKind: '对话',
inventoryEmpty: '暂无占用的会话',
inventoryAgentsTitle: '关联智能体',
inventoryUntitledSession: '未命名会话',
sandboxesStillLive: '该配置仍有 {count} 个运行中或已暂停的沙箱,暂时无法修改身份字段。',
blockedHint: '可结束或删除这些会话(删除会话会销毁其沙箱),或新建一份配置并把智能体指过去。',
unverifiableBlocked: '无法连接该后端核实是否仍有沙箱,因此不能覆盖现有凭据。',

View File

@ -78,8 +78,13 @@
{{ $t('settings.sandbox.legacyConfig') }}
</t-tag>
<div class="sandbox-card__actions" @click.stop>
<t-dropdown :options="cardMenu(record)" trigger="click" attach="body"
placement="bottom-right" @click="(data: any) => onMenuAction(data.value, record)">
<t-dropdown
:options="cardMenu(record)"
placement="bottom-right"
attach="body"
trigger="click"
@click="(data: any) => onMenuAction(data.value, record)"
>
<t-button variant="text" shape="square" size="small" class="sandbox-card__more">
<t-icon name="ellipsis" />
</t-button>
@ -144,63 +149,71 @@
@saved="load" @skills-changed="onSkillsChanged" />
<!--
Occupancy is a list of sessions and agents, not a one-line status, and it
is also what explains a refused delete — so it gets a drawer rather than a
toast or a cramped dialog.
Same SettingDrawer chrome as the skill editor. The list is chat sessions
that still hold a live sandbox for this config — their titles often look
like skill names, so the section label has to say "session".
-->
<SettingDrawer v-model:visible="showInventory" :title="$t('settings.sandbox.inventoryTitle')"
:description="$t('settings.sandbox.inventoryDrawerDesc')" icon="code"
width="480px" storage-key="setting-drawer:width:sandbox-inventory" hide-footer>
<SettingDrawer
v-model:visible="showInventory"
:title="$t('settings.sandbox.inventoryTitle')"
:description="inventorySubtitle"
width="400px"
:resizable="false"
storage-key="setting-drawer:width:sandbox-inventory"
:hide-footer="inventoryNotice !== 'unverifiable'"
>
<t-loading :loading="inventoryLoading" size="small">
<section class="setting-drawer__section">
<t-alert v-if="inventoryNotice === 'blocked'" theme="warning"
<div v-if="inventoryNotice === 'blocked'" class="inventory-banner">
<t-alert theme="warning"
:message="$t('settings.sandbox.sandboxesStillLive', { count: inventory?.sandbox_count ?? 0 })">
<template #description>
<p>{{ $t('settings.sandbox.blockedHint') }}</p>
</template>
</t-alert>
<t-alert v-else-if="inventory?.unverifiable" theme="warning"
:message="$t('settings.sandbox.inventoryUnverifiableHint')" />
</div>
<div v-else-if="inventory?.unverifiable" class="inventory-banner">
<t-alert theme="warning" :message="$t('settings.sandbox.inventoryUnverifiableHint')" />
</div>
<ul v-if="inventory" class="inventory-list">
<li v-if="inventoryRecord">
<span class="inventory-label">{{ $t('settings.sandbox.configName') }}</span>
<span class="inventory-value">{{ inventoryRecord.name }}</span>
</li>
<li>
<span class="inventory-label">{{ $t('settings.sandbox.sandboxCount') }}</span>
<span class="inventory-value">{{ inventory.unverifiable
? $t('settings.sandbox.sandboxCountUnknown')
: inventory.sandbox_count }}</span>
</li>
<li v-if="inventory.session_ids?.length">
<span class="inventory-label">{{ $t('settings.sandbox.affectedSessions', {
count: inventory.session_ids.length }) }}</span>
</li>
<li v-if="inventory.agent_names?.length">
<span class="inventory-label">{{ $t('settings.sandbox.affectedAgents', {
names: inventory.agent_names.join('、') }) }}</span>
<section class="setting-drawer__section inventory-section">
<h4 class="setting-drawer__section-title">{{ $t('settings.sandbox.inventorySessions') }}</h4>
<ul v-if="inventorySessions.length" class="inventory-list">
<li v-for="id in inventorySessions" :key="id">
<button type="button" class="inventory-row" @click="openSession(id)">
<span class="inventory-row__text">
<span class="inventory-row__title" :title="id">{{ sessionTitle(id) }}</span>
<span class="inventory-row__meta">{{ $t('settings.sandbox.inventorySessionKind') }}</span>
</span>
<t-icon name="chevron-right" size="16px" />
</button>
</li>
</ul>
<p v-else-if="!inventoryLoading" class="inventory-empty">
{{ $t('settings.sandbox.inventoryEmpty') }}
</p>
</section>
<!--
Force delete only surfaces where its justification is on screen: the
occupancy could not be verified, so the admin decides with the
unverifiable warning right above the button.
-->
<section v-if="inventoryNotice === 'unverifiable' && inventoryRecord" class="setting-drawer__section">
<h4 class="setting-drawer__section-title">{{ $t('settings.sandbox.forceDeleteTitle') }}</h4>
<t-popconfirm theme="warning" :content="$t('settings.sandbox.forceDeleteConfirm')"
:confirm-btn="{ content: $t('settings.sandbox.forceDelete'), theme: 'danger' }"
:cancel-btn="{ content: $t('common.cancel') }" placement="top"
@confirm="forceRemove(inventoryRecord)">
<t-button theme="danger" variant="outline" size="small">
{{ $t('settings.sandbox.forceDelete') }}
</t-button>
</t-popconfirm>
<section v-if="inventoryAgents.length" class="setting-drawer__section inventory-section">
<h4 class="setting-drawer__section-title">{{ $t('settings.sandbox.inventoryAgentsTitle') }}</h4>
<p class="inventory-agents">{{ inventoryAgents.join('、') }}</p>
</section>
</t-loading>
<!--
Force delete only surfaces where its justification is on screen: the
occupancy could not be verified, so the admin decides with the
unverifiable warning above the button.
-->
<template v-if="inventoryNotice === 'unverifiable' && inventoryRecord" #footer-right>
<t-popconfirm theme="warning" :content="$t('settings.sandbox.forceDeleteConfirm')"
:confirm-btn="{ content: $t('settings.sandbox.forceDelete'), theme: 'danger' }"
:cancel-btn="{ content: $t('common.cancel') }" placement="top"
@confirm="forceRemove(inventoryRecord)">
<t-button theme="danger">
{{ $t('settings.sandbox.forceDelete') }}
</t-button>
</t-popconfirm>
</template>
</SettingDrawer>
</div>
</template>
@ -209,12 +222,13 @@
import { computed, onMounted, ref } from 'vue'
import { MessagePlugin } from 'tdesign-vue-next'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import SandboxConfigEditorDrawer from '@/components/SandboxConfigEditorDrawer.vue'
import SandboxBackendBadge from '@/components/settings/SandboxBackendBadge.vue'
import SettingDrawer from '@/components/settings/SettingDrawer.vue'
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
import { getSession } from '@/api/chat/index'
import {
checkSandboxConfig,
deleteSandboxConfig,
getSandboxConfigInventory,
isNamedSandboxBackend,
@ -229,6 +243,7 @@ import {
} from '@/api/system'
const { t } = useI18n()
const router = useRouter()
const confirmDelete = useConfirmDelete()
const sandboxGuideUrl = 'https://github.com/Tencent/WeKnora/blob/main/docs/sandbox-cluster.md'
@ -250,7 +265,7 @@ const SKILL_TAG_LIMIT = 3
const showEditor = ref(false)
const editingRecord = ref<SandboxConfigRecord | null>(null)
// Which page of the editor to open on. Skills live there as the last step, so
// "管理技能" is the same drawer opened further along.
// clicking a cube/e2b/docker card lands on that page.
const editorStep = ref<'skills' | undefined>(undefined)
const showInventory = ref(false)
@ -316,24 +331,62 @@ const countByType = (type: string) =>
type CardMenuOption = { content: string; value: string; theme?: 'error' }
// Card click already opens skills, and the editor has the connection check,
// so the menu stays edit / running instances / delete.
const cardMenu = (record: SandboxConfigRecord): CardMenuOption[] => {
if (isLegacyRecord(record)) {
return [{ content: t('common.delete'), value: 'delete', theme: 'error' }]
}
const options: CardMenuOption[] = [
{ content: t('common.edit'), value: 'edit' },
{ content: t('settings.sandbox.testConnection'), value: 'check' },
]
if (record.sandbox_type === 'cube' || record.sandbox_type === 'e2b') {
options.push({ content: t('settings.sandbox.viewSandboxes'), value: 'inventory' })
}
if (supportsSkills(record)) {
options.push({ content: t('settings.sandbox.manageSkills'), value: 'skills' })
}
options.push({ content: t('common.delete'), value: 'delete', theme: 'error' })
return options
}
const inventorySubtitle = computed(() => {
const record = inventoryRecord.value
if (!record) return ''
return `${record.name} · ${backendLabel(record.sandbox_type)}`
})
const inventorySessions = computed(() => inventory.value?.session_ids || [])
const inventoryAgents = computed(() => inventory.value?.agent_names || [])
const sessionTitles = ref<Record<string, string>>({})
function sessionTitle(id: string) {
const title = sessionTitles.value[id]
if (title) return title
return t('settings.sandbox.inventoryUntitledSession')
}
async function loadSessionTitles(ids: string[]) {
const unique = [...new Set(ids.filter(Boolean))]
if (!unique.length) {
sessionTitles.value = {}
return
}
const next: Record<string, string> = {}
await Promise.all(unique.map(async (id) => {
try {
const res: any = await getSession(id)
next[id] = String(res?.data?.title || '').trim()
} catch {
next[id] = ''
}
}))
sessionTitles.value = next
}
function openSession(id: string) {
showInventory.value = false
router.push(`/platform/chat/${encodeURIComponent(id)}`)
}
// The endpoint host is what tells two configs of the same backend apart at a
// glance, which is the whole point of allowing several of them.
function endpointHost(record: SandboxConfigRecord): string {
@ -520,18 +573,10 @@ async function onMenuAction(action: string, record: SandboxConfigRecord) {
openEdit(record)
return
}
if (action === 'check') {
await runQuickCheck(record)
return
}
if (action === 'inventory') {
await openInventory(record)
return
}
if (action === 'skills') {
openSkills(record)
return
}
if (action === 'delete') {
void confirmRemove(record)
}
@ -545,33 +590,17 @@ async function confirmRemove(record: SandboxConfigRecord) {
})
}
// A card-level probe answers "is this backend still alive" without opening the
// form; the per-probe breakdown and the sandbox-consuming deep check stay in the
// editor, where the config being probed is on screen.
async function runQuickCheck(record: SandboxConfigRecord) {
try {
const res = await checkSandboxConfig({ config_id: record.id })
const result = res?.data
if (result?.ok) {
MessagePlugin.success(t('settings.sandbox.checkPassed'))
return
}
const failed = result?.checks?.find((item) => item.ok === false)
MessagePlugin.error(failed?.message || t('settings.sandbox.checkFailed'))
} catch (e: any) {
MessagePlugin.error(e?.message || t('settings.sandbox.checkFailed'))
}
}
async function openInventory(record: SandboxConfigRecord) {
inventoryRecord.value = record
inventoryNotice.value = ''
showInventory.value = true
inventoryLoading.value = true
inventory.value = null
sessionTitles.value = {}
try {
const res = await getSandboxConfigInventory(record.id)
inventory.value = res?.data || null
await loadSessionTitles(inventory.value?.session_ids || [])
} catch (e: any) {
MessagePlugin.error(e?.message || t('settings.sandbox.inventoryFailed'))
showInventory.value = false
@ -615,6 +644,7 @@ function showRefusal(
inventory.value = inv || { sandbox_count: 0, unverifiable: notice === 'unverifiable' }
inventoryLoading.value = false
showInventory.value = true
void loadSessionTitles(inventory.value.session_ids || [])
}
async function forceRemove(record: SandboxConfigRecord) {
@ -1033,29 +1063,84 @@ onMounted(load)
color: var(--td-text-color-placeholder);
}
.inventory-banner {
margin-bottom: 4px;
}
.inventory-list {
margin: 0;
padding: 0;
list-style: none;
}
.inventory-row {
display: flex;
align-items: center;
gap: 8px;
width: 100%;
margin: 0;
padding: 6px 8px;
border: 0;
border-radius: 6px;
background: transparent;
color: inherit;
font: inherit;
text-align: left;
cursor: pointer;
&:hover,
&:focus-visible {
background: var(--td-bg-color-container-hover);
}
&:focus-visible {
outline: 2px solid var(--td-brand-color);
outline-offset: 2px;
}
}
.inventory-row__text {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 8px;
font-size: 13px;
gap: 1px;
}
.inventory-list li {
display: flex;
align-items: baseline;
gap: 8px;
line-height: 1.55;
}
.inventory-label {
color: var(--td-text-color-secondary);
}
.inventory-value {
.inventory-row__title {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--td-text-color-primary);
font-weight: 500;
font-size: 13px;
line-height: 1.4;
}
.inventory-row__meta {
color: var(--td-text-color-secondary);
font-size: 12px;
line-height: 1.4;
}
.inventory-row .t-icon {
flex-shrink: 0;
color: var(--td-text-color-placeholder);
}
.inventory-empty,
.inventory-agents {
margin: 0;
color: var(--td-text-color-secondary);
font-size: 13px;
line-height: 1.5;
}
</style>
<style lang="less">
.setting-drawer .inventory-section.setting-drawer__section {
padding: 0;
gap: 8px;
border-bottom: none;
animation: none;
}
</style>