Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
<template>
<div class="skill-settings">
<div class="section-header">
<div class="section-header__title-row">
<h2>{{ $t('settings.skills.title') }}</h2>
<t-tooltip :content="skillText('helpTooltip')" placement="right"
overlay-class-name="skill-settings__help-tooltip">
<t-icon name="help-circle" class="section-header__help" :aria-label="skillText('helpTooltip')" />
</t-tooltip>
</div>
<p class="section-description">{{ skillText('description') }}</p>
</div>
<!-- Lite has no sandbox settings page, so its script kill switch is cleared here. -->
<div v-if="hostOnly && scriptsDisabled" class="skill-settings__scripts-off" role="status">
<p>{{ $t('settings.sandbox.scriptsDisabled') }}</p>
<t-button size="small" theme="primary" variant="outline" :loading="policySaving" @click="enableScripts">
{{ $t('settings.sandbox.enableScripts') }}
</t-button>
</div>
<div v-if="loading" class="loading-container">
<t-loading :text="$t('common.loading')" />
</div>
<template v-else>
<Teleport to="#toolbox-toolbar" defer>
<t-input v-if="catalog.length > 0" v-model="query" class="list-search" :placeholder="$t('menu.search')"
:aria-label="$t('menu.search')" clearable>
<template #prefix-icon><t-icon name="search" size="16px" /></template>
</t-input>
</Teleport>
<div v-if="catalog.length === 0" class="empty-state">
<t-empty :description="skillText('emptyDesc')" />
<p v-if="skillConfigs.length === 0" class="empty-hint">
{{ $t('settings.skills.emptyNoSandboxHint') }}
</p>
<div class="empty-actions">
<t-button theme="primary" @click="openAdd">
{{ $t('settings.skills.addSkill') }}
</t-button>
<t-button v-if="skillConfigs.length === 0 && !hostOnly" theme="default" variant="outline"
@click="uiStore.openSettings('sandbox')">
{{ $t('settings.skills.goSandboxSettings') }}
</t-button>
</div>
</div>
<div v-else-if="filteredCatalog.length === 0" class="empty-state">
<t-empty :description="$t('common.noResult')" />
<div class="empty-actions">
<t-button variant="outline" @click="query = ''">{{ $t('common.clear') }}</t-button>
<t-button variant="text" @click="openAdd">{{ $t('settings.skills.addSkill') }}</t-button>
</div>
</div>
<div v-else class="skill-list">
<article v-for="item in filteredCatalog" :key="item.id" class="skill-card" :class="{
'skill-card--focused': focusedCatalogId === item.id,
'skill-card--installed': liveInstalls(item).length > 0,
'skill-card--idle': liveInstalls(item).length === 0,
}">
<div class="skill-card__main">
<div class="skill-card__body">
<div class="skill-card__header">
<div class="skill-card__badge" :style="skillBadgeStyle(item.name)" aria-hidden="true">
{{ skillInitial(item.name) }}
</div>
<div class="skill-card__heading">
<h3 class="skill-card__title" :title="item.name">{{ item.name }}</h3>
<span v-if="item.version" class="skill-card__type">{{ item.version }}</span>
</div>
<div class="skill-card__actions">
<button type="button" class="skill-card__icon-btn" :title="$t('settings.sandbox.skillFiles')"
:aria-label="$t('settings.sandbox.skillFiles')" @click="openCatalogFiles(item)">
<folder-icon size="14px" />
</button>
<button v-if="canDelete(item)" type="button" class="skill-card__icon-btn skill-card__icon-btn--danger"
:disabled="deletingId === item.id" :title="$t('settings.skills.deleteCatalog')"
:aria-label="$t('settings.skills.deleteCatalog')" @click="askDelete(item)">
<delete-icon size="14px" />
</button>
</div>
</div>
<p v-if="item.description" class="skill-card__desc" :title="item.description">
{{ compactText(item.description) }}
</p>
<div v-for="view in [installsView(item)]" :key="'installs'" class="skill-card__installs">
<span v-if="view.installs.length === 0 && !view.canAdd" class="skill-card__installs-label">
{{ skillText('noInstalls') }}
</span>
<button v-else-if="!view.needsPanel" type="button" class="skill-card__chip"
:class="chipClass(item, view)"
:disabled="Boolean(view.installs[0] && !recordFor(view.installs[0].sandbox_config_id))"
:title="installSummaryTooltip(item, view)" :aria-label="installSummary(item, view)"
@click="onInstallChipClick(item, view)">
<t-icon v-if="view.installs.length === 0" name="add" size="14px" class="skill-card__chip-lead" />
<span v-else class="skill-card__chip-dot" aria-hidden="true" />
<span class="skill-card__chip-text">{{ installChipText(view) }}</span>
<t-icon v-if="view.installs.length > 0" name="chevron-right" size="14px" class="skill-card__chip-go" />
</button>
<t-popup v-else :visible="openPanelId === item.id" trigger="click" placement="bottom-left" attach="body"
destroy-on-close overlay-class-name="skill-install-panel-overlay"
:overlay-inner-style="{ padding: 0 }"
@visible-change="(visible: boolean) => setInstallPanel(item.id, visible)">
<button type="button" class="skill-card__chip" :class="chipClass(item, view)"
:title="installSummaryTooltip(item, view)" :aria-label="installSummary(item, view)"
:aria-expanded="openPanelId === item.id">
<t-icon v-if="view.installs.length === 0" name="add" size="14px" class="skill-card__chip-lead" />
<span v-else class="skill-card__chip-dot" aria-hidden="true" />
<span class="skill-card__chip-text">{{ installChipText(view) }}</span>
<span v-if="view.installs.length > CHIP_NAME_LIMIT" class="skill-card__chip-more">
+{{ view.installs.length - CHIP_NAME_LIMIT }}
</span>
<t-icon name="chevron-down" size="14px" class="skill-card__chip-go"
:class="{ 'is-open': openPanelId === item.id }" />
</button>
<template #content>
<div class="skill-install-panel">
<template v-if="view.installs.length > 0">
<p class="skill-install-panel__group">
{{ $t('settings.skills.installPanelGroup') }}
<span class="skill-install-panel__group-count">{{ view.installs.length }}</span>
</p>
<button v-for="inst in view.installs" :key="inst.skill_id" type="button"
class="skill-install-panel__item" :class="installEntryClass(item, inst)"
:disabled="!recordFor(inst.sandbox_config_id)" :title="installTooltip(item, inst)"
@click="openManageFromPanel(item, inst)">
<SandboxBackendBadge v-if="inst.sandbox_type" :type="inst.sandbox_type" size="xs" />
<span class="skill-install-panel__name">{{ installName(inst) }}</span>
<span v-if="installChipStatus(item, inst)" class="skill-install-panel__status">
<span v-if="isInstallBusy(inst)" class="skill-card__entry-dot" aria-hidden="true" />
<t-icon v-else-if="installChipStatusIcon(item, inst)"
:name="installChipStatusIcon(item, inst)" size="12px" class="skill-card__entry-status" />
{{ installChipStatus(item, inst) }}
</span>
<t-icon name="chevron-right" size="14px" class="skill-install-panel__go" />
</button>
</template>
<template v-if="view.available.length > 0">
<div v-if="view.installs.length > 0" class="skill-install-panel__split" role="separator" />
<p class="skill-install-panel__group">
{{ $t('settings.skills.installPanelAvailable') }}
<span class="skill-install-panel__group-count">{{ view.available.length }}</span>
</p>
<button v-for="cfg in view.available" :key="cfg.id" type="button"
class="skill-install-panel__item skill-install-panel__item--available"
:title="sandboxMetaLine(cfg)" @click="openInstallTo(item, cfg)">
<SandboxBackendBadge :type="cfg.sandbox_type" size="xs" />
<span class="skill-install-panel__name">{{ cfg.name }}</span>
<span class="skill-install-panel__add">
<t-icon name="add" size="12px" />
{{ $t('settings.skills.installAction') }}
</span>
</button>
</template>
</div>
</template>
</t-popup>
<button v-if="view.upgradable.length > 0" type="button"
class="skill-card__chip skill-card__chip--upgrade" :title="upgradeTooltip(item, view)"
:aria-label="upgradeLabel(view)" @click="openUpgrade(item)">
<t-icon name="arrow-up" size="14px" class="skill-card__chip-go" />
<span class="skill-card__chip-text">{{ upgradeLabel(view) }}</span>
</button>
</div>
</div>
</div>
</article>
<button type="button" class="skill-card skill-card--add" @click="openAdd">
<span class="skill-card--add__icon" aria-hidden="true">
<add-icon />
</span>
<span class="skill-card--add__label">{{ $t('settings.skills.addSkill') }}</span>
</button>
</div>
</template>
<SettingDrawer v-model:visible="showAdd" :title="$t('settings.skills.addSkill')" :description="addStepDescription"
:icon="SKILL_ICON" width="680px" :min-width="560" :max-width="920"
storage-key="setting-drawer:width:skill-catalog-add" :confirm-loading="addPrimaryLoading"
:confirm-disabled="addPrimaryDisabled" :confirm-text="addPrimaryText" @confirm="handleAddPrimary">
<template #header-extra>
<nav class="skill-add-steps" :aria-label="$t('settings.skills.addProgress')">
<component :is="canJumpAddStep(index) ? 'button' : 'div'" v-for="(item, index) in addSteps" :key="item.key"
:type="canJumpAddStep(index) ? 'button' : undefined" :class="['skill-add-step', {
'is-active': addStep === index,
'is-done': addStep > index,
'is-clickable': canJumpAddStep(index),
}]" :aria-current="addStep === index ? 'step' : undefined" @click="goToAddStep(index)">
<span class="skill-add-step__marker">
<t-icon v-if="addStep > index" name="check" />
<template v-else>{{ index + 1 }}</template>
</span>
<span class="skill-add-step__title">{{ item.title }}</span>
<span v-if="index < addSteps.length - 1" class="skill-add-step__line" aria-hidden="true" />
</component>
</nav>
</template>
<template #footer-left>
<t-button v-if="addStep > 0" variant="outline" @click="addPreviousStep">
{{ $t('settings.sandbox.back') }}
</t-button>
</template>
<article v-if="addStep > 0 && registeredCatalog" class="skill-card parsed-skill">
<div class="skill-card__main">
<div class="skill-card__body">
<div class="skill-card__header">
<div class="skill-card__badge" :style="skillBadgeStyle(registeredCatalog.name)" aria-hidden="true">
{{ skillInitial(registeredCatalog.name) }}
</div>
<h3 class="skill-card__title" :title="registeredCatalog.name">{{ registeredCatalog.name }}</h3>
<span v-if="registeredCatalog.version" class="skill-card__type">{{ registeredCatalog.version }}</span>
</div>
<p v-if="registeredCatalog.description" class="skill-card__desc" :title="registeredCatalog.description">
{{ compactText(registeredCatalog.description) }}
</p>
</div>
</div>
</article>
<template v-if="addStep === 0">
<section class="setting-drawer__section">
<h4 class="setting-drawer__section-title">{{ $t('settings.sandbox.skillSourceSection') }}</h4>
<p class="installer-model-hint">{{ $t('settings.sandbox.skillSourceSectionHint', { size: maxSkillBundleMB })
}}</p>
<t-input v-model="sourceInput" :placeholder="$t('settings.sandbox.skillSourcePlaceholder')"
:disabled="addBusy || !!registeredCatalog" @enter="handleAddPrimary" />
</section>
<section class="setting-drawer__section">
<h4 class="setting-drawer__section-title">{{ $t('settings.sandbox.skillUploadSection') }}</h4>
<p class="installer-model-hint">{{ $t('settings.sandbox.skillUploadSectionHint', { size: maxSkillBundleMB })
}}</p>
<input ref="fileInputRef" type="file" accept=".zip,application/zip" class="file-input-hidden"
@change="onFileInputChange" />
<div class="file-upload-area file-upload-area--large"
:class="{ 'has-file': !!pendingFile, 'is-disabled': addBusy || !!registeredCatalog }"
@click="!addBusy && !registeredCatalog && fileInputRef?.click()" @dragover.prevent @dragenter.prevent
@drop.prevent="onFileDrop">
<div class="file-upload-content">
<div class="file-upload-icon-wrap" aria-hidden="true">
<t-icon name="cloud-upload" size="32px" class="upload-icon" />
</div>
<div class="upload-text">
<span v-if="pendingFile" class="upload-file-name">
{{ t('settings.skills.addFileSelected', { name: pendingFile.name }) }}
</span>
<template v-else>
<span class="upload-primary-text">{{ $t('settings.sandbox.skillUploadClick') }}</span>
<span class="upload-secondary-text">{{ $t('settings.sandbox.skillUploadDrag') }}</span>
</template>
</div>
<t-progress v-if="uploading" :percentage="uploadPercent" size="small" />
</div>
</div>
<t-button v-if="pendingFile && !registeredCatalog" variant="text" size="small" :disabled="addBusy"
@click="pendingFile = null">
{{ $t('settings.skills.addClearFile') }}
</t-button>
</section>
</template>
<template v-else>
<section v-if="!hostOnly && skillConfigs.length > 0" class="setting-drawer__section">
<h4 class="setting-drawer__section-title">{{ $t('settings.skills.pickSandboxes') }}</h4>
<p class="installer-model-hint">{{ $t('settings.skills.pickSandboxesHint') }}</p>
<div class="sandbox-pick-list">
<div v-for="row in addPickRows" :key="row.cfg.id" class="sandbox-pick-row"
:class="{ 'is-busy': row.busy, 'is-ready': row.ready }">
<t-checkbox v-if="row.selectable" :checked="addTargetIds.includes(row.cfg.id)" :disabled="installing"
class="sandbox-pick" @change="(checked: boolean) => setAddPick(row.cfg.id, checked)">
<span class="sandbox-pick__main">
<SandboxBackendBadge :type="row.cfg.sandbox_type" size="sm" />
<span class="sandbox-pick__text">
<span class="sandbox-pick__name">{{ row.cfg.name }}</span>
<span class="sandbox-pick__meta">{{ pickRowMeta(row) }}</span>
</span>
</span>
</t-checkbox>
<div v-else class="sandbox-pick sandbox-pick--status">
<span class="sandbox-pick__main">
<SandboxBackendBadge :type="row.cfg.sandbox_type" size="sm" />
<span class="sandbox-pick__text">
<span class="sandbox-pick__name">{{ row.cfg.name }}</span>
<span class="sandbox-pick__meta">{{ sandboxPickStatus(row) }}</span>
</span>
</span>
<div v-if="row.busy" class="sandbox-pick__progress">
<t-progress theme="circle" :percentage="sandboxPickPercent(row) ?? 0" :size="18" :stroke-width="2"
:label="false" />
<span v-if="sandboxPickPercent(row) != null">{{ sandboxPickPercent(row) }}%</span>
</div>
<t-button v-if="row.busy && row.install" size="small" variant="text" theme="primary"
@click="openManageFromPick(registeredCatalog?.id, row.install)">
{{ $t('settings.skills.viewInstallProgress') }}
</t-button>
</div>
</div>
</div>
</section>
<p v-else-if="!hostOnly" class="installer-model-hint">{{ $t('settings.skills.emptyNoSandboxHint') }}</p>
<section v-if="addTargetIds.length > 0" class="setting-drawer__section">
<h4 class="setting-drawer__section-title">{{ $t('settings.sandbox.skillInstallerModel') }}</h4>
<p class="installer-model-hint">{{ $t('settings.sandbox.skillInstallerModelHint') }}</p>
<ModelSelector model-type="KnowledgeQA" :selected-model-id="installerModelId"
:disabled="savingInstallerModel || installing" @update:selected-model-id="onInstallerModelChange" />
</section>
</template>
</SettingDrawer>
<SettingDrawer v-model:visible="showInstall" :title="installDrawerTitle"
:description="installDrawerDesc" :icon="SKILL_ICON" width="560px" :min-width="480" :max-width="760"
storage-key="setting-drawer:width:skill-catalog-install" :confirm-loading="installing"
:confirm-disabled="installConfirmDisabled" :confirm-text="installConfirmText" @confirm="onInstallDrawerConfirm">
<template v-if="installCatalog" #headerIcon>
<span class="skill-drawer-avatar" :style="skillBadgeStyle(installCatalog.name)">
{{ skillInitial(installCatalog.name) }}
</span>
</template>
<p v-if="installMode === 'install'" class="installer-model-hint">{{ skillText('installToSandboxDesc') }}</p>
<section v-if="!hostOnly && installPickRows.length > 0" class="setting-drawer__section">
<div class="sandbox-pick-list">
<div v-for="row in installPickRows" :key="row.cfg.id" class="sandbox-pick-row"
:class="{ 'is-busy': row.busy, 'is-ready': row.ready }">
<t-checkbox v-if="row.selectable" :checked="installTargetIds.includes(row.cfg.id)" :disabled="installing"
class="sandbox-pick" @change="(checked: boolean) => setInstallPick(row.cfg.id, checked)">
<span class="sandbox-pick__main">
<SandboxBackendBadge :type="row.cfg.sandbox_type" size="sm" />
<span class="sandbox-pick__text">
<span class="sandbox-pick__name">{{ row.cfg.name }}</span>
<span class="sandbox-pick__meta">{{ pickRowMeta(row) }}</span>
</span>
</span>
</t-checkbox>
<div v-else class="sandbox-pick sandbox-pick--status">
<span class="sandbox-pick__main">
<SandboxBackendBadge :type="row.cfg.sandbox_type" size="sm" />
<span class="sandbox-pick__text">
<span class="sandbox-pick__name">{{ row.cfg.name }}</span>
<span class="sandbox-pick__meta">{{ sandboxPickStatus(row) }}</span>
</span>
</span>
<div v-if="row.busy" class="sandbox-pick__progress">
<t-progress theme="circle" :percentage="sandboxPickPercent(row) ?? 0" :size="18" :stroke-width="2"
:label="false" />
<span v-if="sandboxPickPercent(row) != null">{{ sandboxPickPercent(row) }}%</span>
</div>
<t-button v-if="row.busy && row.install" size="small" variant="text" theme="primary"
@click="openManageFromPick(installCatalog?.id, row.install)">
{{ $t('settings.skills.viewInstallProgress') }}
</t-button>
</div>
</div>
</div>
</section>
<p v-else-if="!hostOnly" class="installer-model-hint">
{{ installMode === 'upgrade' ? $t('settings.skills.noSandboxToUpgrade') : $t('settings.skills.noSandboxToInstall') }}
</p>
<section v-if="installTargetIds.length > 0" class="setting-drawer__section">
<h4 class="setting-drawer__section-title">{{ $t('settings.sandbox.skillInstallerModel') }}</h4>
<p class="installer-model-hint">{{ $t('settings.sandbox.skillInstallerModelHint') }}</p>
<ModelSelector model-type="KnowledgeQA" :selected-model-id="installerModelId"
:disabled="savingInstallerModel || installing" @update:selected-model-id="onInstallerModelChange" />
</section>
</SettingDrawer>
<SettingDrawer v-model:visible="showManage" :title="manageTitle" :description="manageDesc" :icon="SKILL_ICON"
width="680px" :min-width="560" :max-width="920" storage-key="setting-drawer:width:skill-catalog-manage"
:hide-footer="true" :z-index="2600">
<template v-if="manageTitle" #headerIcon>
<span class="skill-drawer-avatar" :style="skillBadgeStyle(manageTitle)">{{ skillInitial(manageTitle) }}</span>
</template>
<SandboxSkillsPanel v-if="showManage && manageRecord && manageSkillId" :record="manageRecord" mode="list" hide-add
:focus-skill-id="manageSkillId" :catalog-item="catalogItemById(manageCatalogId)" @updated="onPanelUpdated"
@skills-changed="loadCatalog" />
</SettingDrawer>
<SkillFilesDrawer v-model:visible="filesDrawerVisible" :catalog-id="filesCatalogId"
:skill-name="filesCatalogName" />
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import { MessagePlugin } from 'tdesign-vue-next'
import { AddIcon, DeleteIcon, FolderIcon } from 'tdesign-icons-vue-next'
import { useI18n } from 'vue-i18n'
import SandboxSkillsPanel from '@/components/SandboxSkillsPanel.vue'
import SkillFilesDrawer from '@/components/SkillFilesDrawer.vue'
import SandboxBackendBadge from '@/components/settings/SandboxBackendBadge.vue'
import SettingDrawer from '@/components/settings/SettingDrawer.vue'
import ModelSelector from '@/components/ModelSelector.vue'
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
import { useConfigSkillInstallProgress } from '@/composables/useConfigSkillInstallProgress'
import { matchesResourceQuery } from '@/utils/resourceListSearch'
import { SKILL_ICON } from '@/types/mention'
import { useUIStore } from '@/stores/ui'
import { useDeploymentCapabilitiesStore } from '@/stores/deploymentCapabilities'
import { MAX_SKILL_BUNDLE_SIZE_BYTES, MAX_SKILL_BUNDLE_SIZE_MB } from '@/utils'
import {
deleteSkillCatalog,
installSkillCatalog,
listSkillCatalog,
registerSkillCatalogFromFile,
registerSkillCatalogFromSource,
type SkillCatalogInstall,
type SkillCatalogItem,
type SkillCatalogRegisterResult,
} from '@/api/skill'
import { useSkillInstallerModel } from '@/composables/useSkillInstallerModel'
import { useAssistantDataChange } from '@/utils/assistantDataChange'
import { installOutdated, installUpgradable, servedPreviousText, upgradeVersions } from '@/utils/skillUpgrade'
import {
HOST_SKILL_TARGET_ID,
hostSkillTargetRecord,
hostSkillsOnly,
isHostSkillTarget,
} from '@/utils/skillTarget'
import {
isNamedSandboxBackend,
listSandboxConfigs,
setSandboxWorkspacePolicy,
type SandboxConfigRecord,
} from '@/api/system'
const props = defineProps<{
initialSandboxId?: string
}>()
const emit = defineEmits<{ count: [value: number] }>()
const { t, te, locale } = useI18n()
const uiStore = useUIStore()
const deploymentCapabilities = useDeploymentCapabilitiesStore()
const confirmDelete = useConfirmDelete()
const hostOnly = computed(() => hostSkillsOnly(
deploymentCapabilities.isSupported('settings.sandbox.remote'),
deploymentCapabilities.isSupported('settings.sandbox.host'),
))
function skillText(key: string, params: Record<string, unknown> = {}) {
const hostKey = `settings.skills.host.${key}`
if (hostOnly.value && te(hostKey)) return t(hostKey, params)
return t(`settings.skills.${key}`, params)
}
const hostRecord = computed(() => hostSkillTargetRecord(t('settings.skills.hostTarget')))
const loading = ref(false)
const records = ref<SandboxConfigRecord[]>([])
const scriptsDisabled = ref(false)
const policySaving = ref(false)
const catalog = ref<SkillCatalogItem[]>([])
const query = ref('')
const filteredCatalog = computed(() => catalog.value.filter((item) => matchesResourceQuery(item, query.value)))
const focusedCatalogId = ref('')
const deletingId = ref('')
const showAdd = ref(false)
const showInstall = ref(false)
const showManage = ref(false)
const addStep = ref(0)
const registeredCatalog = ref<SkillCatalogRegisterResult | null>(null)
const pendingFile = ref<File | null>(null)
const addTargetIds = ref<string[]>([])
const addSessionIds = ref<string[]>([])
const installTargetIds = ref<string[]>([])
const installSessionIds = ref<string[]>([])
const installCatalog = ref<SkillCatalogItem | null>(null)
const installMode = ref<'install' | 'upgrade'>('install')
const manageRecord = ref<SandboxConfigRecord | null>(null)
const manageSkillId = ref('')
const manageCatalogId = ref('')
const manageTitle = ref('')
const filesDrawerVisible = ref(false)
const filesCatalogId = ref('')
const filesCatalogName = ref('')
const openPanelId = ref('')
const sourceInput = ref('')
const uploading = ref(false)
const addingFromSource = ref(false)
const installing = ref(false)
const uploadPercent = ref(0)
const fileInputRef = ref<HTMLInputElement | null>(null)
const {
installerModelId, savingInstallerModel, loadInstallerModel, persistInstallerModel,
onInstallerModelChange,
} = useSkillInstallerModel()
const {
percentOf: installEventPercent,
sync: syncInstallProgress,
stopAll: stopInstallProgress,
} = useConfigSkillInstallProgress({
onDone() {
void loadCatalog(true)
},
})
let pollTimer: number | null = null
let focusTimer: number | null = null
const skillConfigs = computed(() =>
hostOnly.value
? [hostRecord.value]
: records.value.filter((record) => isNamedSandboxBackend(record.sandbox_type)),
)
const addBusy = computed(() => uploading.value || addingFromSource.value)
const maxSkillBundleMB = MAX_SKILL_BUNDLE_SIZE_MB
const addSteps = computed(() => [
{ key: 'register', title: t('settings.skills.addStepRegister') },
{ key: 'install', title: t('settings.skills.addStepInstall') },
])
const addStepDescription = computed(() =>
addStep.value === 0
? t('settings.skills.addStepRegisterDesc')
: skillText('addStepInstallDesc'),
)
const addPrimaryLoading = computed(() =>
addStep.value === 0 ? addBusy.value : installing.value,
)
const addPrimaryDisabled = computed(() => {
if (addBusy.value || installing.value) return true
if (addStep.value === 0) {
if (registeredCatalog.value) return false
return !sourceInput.value.trim() && !pendingFile.value
}
return addTargetIds.value.length > 0 && !installerModelId.value
})
const addPrimaryText = computed(() => {
if (addStep.value === 0) return t('common.next')
if (addTargetIds.value.length > 0) return pickConfirmText(addPickRows.value, addTargetIds.value)
return t('settings.skills.addFinish')
})
const installConfirmText = computed(() =>
installTargetIds.value.length > 0
? pickConfirmText(installPickRows.value, installTargetIds.value)
: t('settings.skills.addFinish'),
)
const installConfirmDisabled = computed(() =>
installing.value || (installTargetIds.value.length > 0 && !installerModelId.value),
)
const installPickRows = computed(() =>
sandboxPickRows(
catalogItemById(installCatalog.value?.id),
installMode.value === 'upgrade' ? 'upgrade' : 'remaining',
installSessionIds.value,
),
)
const addPickRows = computed(() =>
sandboxPickRows(catalogItemById(registeredCatalog.value?.id), 'all', addSessionIds.value),
)
const installDrawerTitle = computed(() =>
installMode.value === 'upgrade'
? t('settings.skills.upgradeTitle')
: skillText('installToSandbox'),
)
const installDrawerDesc = computed(() => {
const item = installCatalog.value
if (!item) return skillText('installToSandboxDesc')
if (installMode.value === 'upgrade') return skillText('upgradeDrawerDesc', { name: item.name })
return skillText('installDrawerDesc', { name: item.name })
})
const manageDesc = computed(() => {
const record = manageRecord.value
if (!record) return ''
return skillText('manageDrawerDesc', { name: record.name })
})
function liveInstalls(item: SkillCatalogItem): SkillCatalogInstall[] {
return (item.installations || []).filter((inst) => inst.status && inst.status !== 'removed')
}
function canDelete(item: SkillCatalogItem): boolean {
return liveInstalls(item).length === 0
}
function targetsFor(item: SkillCatalogItem): SandboxConfigRecord[] {
const taken = new Set(
liveInstalls(item)
.filter((inst) => inst.status === 'installing' || inst.status === 'ready' || inst.status === 'removing')
.map((inst) => inst.sandbox_config_id),
)
return skillConfigs.value.filter((cfg) => !taken.has(cfg.id))
}
function recordFor(id: string): SandboxConfigRecord | undefined {
if (hostOnly.value && id === HOST_SKILL_TARGET_ID) return hostRecord.value
return records.value.find((record) => record.id === id)
}
function backendLabel(type: string): string {
return t(`settings.sandbox.backends.${type}`)
}
function sandboxTargetLine(record: SandboxConfigRecord): string {
if (record.sandbox_type === 'docker') {
return record.config?.docker?.image?.trim() || ''
}
const remote = record.config?.e2b || record.config?.cube
const raw = remote?.api_url?.trim() || ''
if (!raw) return ''
try {
return new URL(raw).host
} catch {
return raw
}
}
function sandboxMetaLine(record: SandboxConfigRecord): string {
const type = backendLabel(record.sandbox_type)
const target = sandboxTargetLine(record)
return target ? `${type} · ${target}` : type
}
type SandboxPickRow = {
cfg: SandboxConfigRecord
install?: SkillCatalogInstall
selectable: boolean
busy: boolean
ready: boolean
// A ready install still on an older archive than the catalog. Picking it
// installs the catalog over it, which is the upgrade.
upgradable: boolean
upgradeNote: string
}
function catalogItemById(id: string | undefined | null): SkillCatalogItem | null {
const key = (id || '').trim()
if (!key) return null
return catalog.value.find((row) => row.id === key) || null
}
function sandboxPickRows(
item: SkillCatalogItem | null,
mode: 'remaining' | 'upgrade' | 'all',
sessionIds: string[],
): SandboxPickRow[] {
const byId = new Map(
(item ? liveInstalls(item) : []).map((inst) => [inst.sandbox_config_id, inst]),
)
const session = new Set(sessionIds)
return skillConfigs.value
.filter((cfg) => {
if (mode === 'all') return true
const inst = byId.get(cfg.id)
if (session.has(cfg.id)) return true
if (inst && isInstallBusy(inst)) return true
if (inst && item && installUpgradable(item, inst)) return true
if (mode === 'upgrade') return false
if (!inst || inst.status === 'failed') return true
return false
})
.map((cfg) => {
const install = byId.get(cfg.id)
const busy = Boolean(install && isInstallBusy(install))
const ready = install?.status === 'ready'
const upgradable = Boolean(item && install && installUpgradable(item, install))
return {
cfg,
install,
selectable: !busy && (!ready || upgradable),
busy,
ready,
upgradable,
upgradeNote: item && install && upgradable ? upgradeVersionText(item, install) : '',
}
})
}
function pickRowMeta(row: SandboxPickRow): string {
const meta = sandboxMetaLine(row.cfg)
return row.upgradeNote ? `${row.upgradeNote} · ${meta}` : meta
}
function pickedOnlyUpgrades(rows: SandboxPickRow[], ids: string[]): boolean {
const byId = new Map(rows.map((row) => [row.cfg.id, row]))
return ids.length > 0 && ids.every((id) => byId.get(id)?.upgradable)
}
function pickConfirmText(rows: SandboxPickRow[], ids: string[]): string {
return pickedOnlyUpgrades(rows, ids)
? skillText('upgrade')
: skillText('installToSandbox')
}
function sandboxPickPercent(row: SandboxPickRow): number | null {
if (!row.busy || !row.install) return null
return installEventPercent(row.cfg.id, row.install.skill_id)
}
function sandboxPickStatus(row: SandboxPickRow): string {
if (row.install && isInstallBusy(row.install)) return installStatusText(row.install)
if (row.ready) return t('settings.sandbox.skillStatusReady')
return sandboxMetaLine(row.cfg)
}
function setAddPick(id: string, checked: boolean) {
setPickId(addTargetIds, id, checked)
}
function setInstallPick(id: string, checked: boolean) {
setPickId(installTargetIds, id, checked)
}
function setPickId(ids: { value: string[] }, id: string, checked: boolean) {
const on = Boolean(checked)
if (on) {
if (!ids.value.includes(id)) ids.value = [...ids.value, id]
return
}
ids.value = ids.value.filter((item) => item !== id)
}
function prunePicks(ids: { value: string[] }, rows: SandboxPickRow[]) {
const allowed = new Set(rows.filter((row) => row.selectable).map((row) => row.cfg.id))
ids.value = ids.value.filter((id) => allowed.has(id))
}
function rememberSession(session: { value: string[] }, ids: string[]) {
session.value = [...new Set([...session.value, ...ids])]
}
function catalogFromRegister(data: SkillCatalogRegisterResult | undefined, fallbackName: string): SkillCatalogRegisterResult | null {
const id = data?.id || ''
if (!id) return null
return {
id,
name: data?.name || fallbackName,
version: data?.version,
description: data?.description,
}
}
function syncRegisteredFromCatalog() {
const current = registeredCatalog.value
if (!current?.id) return
const item = catalog.value.find((row) => row.id === current.id)
if (!item) return
registeredCatalog.value = {
id: item.id,
name: item.name,
version: item.version,
description: item.description,
}
}
function compactText(value: string): string {
return value.replace(/\s+/g, ' ').trim()
}
const SKILL_BADGE_HUES = ['#366ef4', '#0594fa', '#00a870', '#8e56dd', '#e37318', '#d6418f', '#5b5bd6', '#b07b3b']
function skillInitial(name: string): string {
const ch = Array.from((name || '').replace(/^[^\p{L}\p{N}]+/u, ''))[0] || '?'
return ch.toUpperCase()
}
function skillBadgeStyle(name: string): Record<string, string> {
let hash = 0
for (const ch of name || '') hash = (hash * 31 + ch.codePointAt(0)!) >>> 0
return { '--skill-hue': SKILL_BADGE_HUES[hash % SKILL_BADGE_HUES.length] }
}
function upgradeVersionText(item: SkillCatalogItem, inst: SkillCatalogInstall): string {
const versions = upgradeVersions(item, inst)
return versions
? t('settings.skills.upgradeFromTo', versions)
: t('settings.skills.upgradeAvailable')
}
function installStatusText(inst: SkillCatalogInstall): string {
const served = servedPreviousText(t, inst)
if (served) return served
if (inst.status === 'installing') return t('settings.sandbox.skillStatusInstalling')
if (inst.status === 'removing') return t('settings.sandbox.skillStatusRemoving')
if (inst.status === 'failed') return t('settings.sandbox.skillStatusFailed')
if (inst.status === 'ready' && !inst.enabled) return t('common.off')
if (inst.status === 'ready') return t('settings.sandbox.skillStatusReady')
return inst.status
}
function installChipStatus(item: SkillCatalogItem, inst: SkillCatalogInstall): string {
if (inst.status === 'ready' && inst.enabled && installOutdated(item, inst)) {
return t('settings.skills.installOutdated')
}
if (inst.status === 'ready' && inst.enabled) return ''
return installStatusText(inst)
}
function installChipStatusIcon(item: SkillCatalogItem, inst: SkillCatalogInstall): string {
if (inst.status === 'failed') return 'close-circle-filled'
if (inst.status === 'ready' && inst.enabled && installOutdated(item, inst)) return 'error-circle-filled'
if (inst.status === 'ready' && inst.enabled) return 'check-circle-filled'
return ''
}
function isInstallBusy(inst: SkillCatalogInstall): boolean {
return inst.status === 'installing' || inst.status === 'removing'
}
function installPriority(item: SkillCatalogItem, inst: SkillCatalogInstall): number {
if (inst.status === 'failed') return 0
if (isInstallBusy(inst)) return 1
if (installOutdated(item, inst)) return 2
if (inst.status === 'ready' && !inst.enabled) return 3
return 4
}
function unusedTargets(item: SkillCatalogItem): SandboxConfigRecord[] {
const live = new Set(liveInstalls(item).map((inst) => inst.sandbox_config_id))
return skillConfigs.value
.filter((cfg) => !live.has(cfg.id))
.sort((a, b) => a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }))
}
function installsView(item: SkillCatalogItem) {
const installs = [...liveInstalls(item)].sort((a, b) => {
const diff = installPriority(item, a) - installPriority(item, b)
if (diff !== 0) return diff
return installName(a).localeCompare(installName(b), undefined, { sensitivity: 'base' })
})
const available = unusedTargets(item)
return {
installs,
available,
upgradable: installs.filter((inst) => installUpgradable(item, inst)),
canAdd: available.length > 0,
needsPanel: installs.length + available.length > 1,
}
}
function upgradeLabel(view: ReturnType<typeof installsView>): string {
const count = view.upgradable.length
return count > 1 ? t('settings.skills.upgradeCount', { count }) : t('settings.skills.upgrade')
}
function upgradeTooltip(item: SkillCatalogItem, view: ReturnType<typeof installsView>): string {
return view.upgradable
.map((inst) => `${installName(inst)} · ${upgradeVersionText(item, inst)}`)
.join('\n')
}
function installSummary(item: SkillCatalogItem, view: ReturnType<typeof installsView>): string {
if (view.installs.length === 0) return skillText('installToSandbox')
if (view.installs.length === 1) {
return skillText('installedOnName', { name: installName(view.installs[0]) })
}
return t('settings.skills.installedCount', { count: view.installs.length })
}
const CHIP_NAME_LIMIT = 2
function installChipText(view: ReturnType<typeof installsView>): string {
if (view.installs.length === 0) return skillText('installToSandbox')
const sep = /^(zh|ja)/.test(String(locale.value)) ? '、' : ', '
return view.installs.slice(0, CHIP_NAME_LIMIT).map(installName).join(sep)
}
function chipClass(item: SkillCatalogItem, view: ReturnType<typeof installsView>): (string | undefined)[] {
return [
view.installs.length === 0 ? 'skill-card__chip--idle' : 'skill-card__chip--installed',
view.installs[0] ? installEntryClass(item, view.installs[0]) : undefined,
]
}
function installSummaryTooltip(item: SkillCatalogItem, view: ReturnType<typeof installsView>): string {
const lines = view.installs.map((inst) => installTooltip(item, inst))
for (const cfg of view.available) {
const meta = sandboxMetaLine(cfg)
lines.push(
meta
? `${cfg.name} · ${t('settings.skills.installPanelAvailable')} · ${meta}`
: `${cfg.name} · ${t('settings.skills.installPanelAvailable')}`,
)
}
if (lines.length === 0) return skillText('installToSandbox')
return lines.join('\n')
}
function onInstallChipClick(item: SkillCatalogItem, view: ReturnType<typeof installsView>) {
if (view.installs[0]) {
openManage(item, view.installs[0])
return
}
if (view.canAdd) openInstall(item)
}
function setInstallPanel(id: string, visible: boolean) {
if (visible) {
openPanelId.value = id
return
}
if (openPanelId.value === id) openPanelId.value = ''
}
function openManageFromPanel(item: SkillCatalogItem, inst: SkillCatalogInstall) {
openPanelId.value = ''
openManage(item, inst)
}
function openInstallTo(item: SkillCatalogItem, cfg: SandboxConfigRecord) {
openPanelId.value = ''
installMode.value = 'install'
installCatalog.value = item
installSessionIds.value = []
installTargetIds.value = [cfg.id]
void loadInstallerModel()
showInstall.value = true
}
function openManageFromPick(catalogId: string | undefined, inst: SkillCatalogInstall) {
const item = catalogItemById(catalogId)
if (!item) return
openManage(item, inst)
}
function installEntryClass(item: SkillCatalogItem, inst: SkillCatalogInstall): string {
if (inst.status === 'failed') return 'skill-card__entry--failed'
if (isInstallBusy(inst)) return 'skill-card__entry--busy'
if (inst.status === 'ready' && !inst.enabled) return 'skill-card__entry--off'
if (installOutdated(item, inst)) return 'skill-card__entry--stale'
return 'skill-card__entry--ready'
}
function installTargetName(inst: { sandbox_config_id: string; sandbox_config_name?: string }): string {
if (isHostSkillTarget(inst.sandbox_config_id)) return t('settings.skills.hostTarget')
return inst.sandbox_config_name || inst.sandbox_config_id
}
function installName(inst: SkillCatalogInstall): string {
return installTargetName(inst)
}
function installTooltip(item: SkillCatalogItem, inst: SkillCatalogInstall): string {
const parts = [
installTargetName(inst),
inst.sandbox_type ? backendLabel(inst.sandbox_type) : '',
installChipStatus(item, inst) || installStatusText(inst),
].filter(Boolean)
return parts.join(' · ')
}
function openCatalogFiles(item: SkillCatalogItem) {
filesCatalogId.value = item.id
filesCatalogName.value = item.name
filesDrawerVisible.value = true
}
function askDelete(item: SkillCatalogItem) {
if (!canDelete(item)) {
MessagePlugin.warning(skillText('deleteCatalogBlocked'))
return
}
confirmDelete({
body: skillText('deleteCatalogConfirm', { name: item.name }),
onConfirm: () => removeCatalog(item),
})
}
function defaultAddTargets(): string[] {
const preferred = (props.initialSandboxId || '').trim()
if (preferred && skillConfigs.value.some((cfg) => cfg.id === preferred)) return [preferred]
if (skillConfigs.value.length === 1) return [skillConfigs.value[0].id]
return []
}
function revealCatalog(id: string) {
focusedCatalogId.value = id
if (focusTimer != null) window.clearTimeout(focusTimer)
focusTimer = window.setTimeout(() => {
if (focusedCatalogId.value === id) focusedCatalogId.value = ''
focusTimer = null
}, 2400)
}
function resetAddWizard() {
addStep.value = 0
registeredCatalog.value = null
pendingFile.value = null
sourceInput.value = ''
addTargetIds.value = []
addSessionIds.value = []
uploadPercent.value = 0
if (fileInputRef.value) fileInputRef.value.value = ''
}
async function openAdd() {
resetAddWizard()
await loadInstallerModel()
showAdd.value = true
}
function canJumpAddStep(index: number) {
if (index === addStep.value) return false
return Boolean(registeredCatalog.value) || index < addStep.value
}
function goToAddStep(index: number) {
if (!canJumpAddStep(index) && index !== addStep.value) return
addStep.value = index
}
function addPreviousStep() {
if (addStep.value <= 0) return
addStep.value -= 1
}
function openInstall(item: SkillCatalogItem) {
installMode.value = 'install'
installCatalog.value = item
installSessionIds.value = []
const remaining = targetsFor(item)
installTargetIds.value = remaining.length === 1 ? [remaining[0].id] : []
void loadInstallerModel()
showInstall.value = true
}
// Upgrading is the catalog install onto sandboxes that already carry an older
// archive; the server treats a same-name install as an in-place upgrade. Every
// outdated sandbox starts checked, so one confirm upgrades them all.
function openUpgrade(item: SkillCatalogItem) {
openPanelId.value = ''
installMode.value = 'upgrade'
installCatalog.value = item
installSessionIds.value = []
installTargetIds.value = installsView(item).upgradable.map((inst) => inst.sandbox_config_id)
void loadInstallerModel()
showInstall.value = true
}
function openManage(item: SkillCatalogItem, inst: SkillCatalogInstall) {
const record = recordFor(inst.sandbox_config_id)
if (!record) return
manageRecord.value = record
manageSkillId.value = inst.skill_id
manageCatalogId.value = item.id
manageTitle.value = item.name
showManage.value = true
}
function onPanelUpdated(record: SandboxConfigRecord) {
records.value = records.value.map((item) => (item.id === record.id ? { ...item, ...record } : item))
}
async function ensureInstallerModelIfNeeded(configIds: string[]) {
if (configIds.length === 0) return
if (!installerModelId.value) {
throw new Error(t('settings.sandbox.skillInstallerModelRequired'))
}
await persistInstallerModel(installerModelId.value)
}
function isZipFile(file: File): boolean {
return file.name.toLowerCase().endsWith('.zip') || file.type === 'application/zip'
}
function acceptPendingFile(file: File) {
if (addBusy.value || registeredCatalog.value) return
if (!isZipFile(file)) {
MessagePlugin.error(t('settings.sandbox.skillUploadFailed'))
return
}
if (file.size > MAX_SKILL_BUNDLE_SIZE_BYTES) {
MessagePlugin.error(t('settings.sandbox.skillBundleTooLarge', { size: maxSkillBundleMB }))
return
}
pendingFile.value = file
}
function skillRegisterErrorMessage(err: any, fromFile: boolean): string {
const raw = String(err?.message || '')
if (/cannot exceed \d+\s*MB/i.test(raw)) {
return t('settings.sandbox.skillBundleTooLarge', { size: maxSkillBundleMB })
}
const tooManyFiles = raw.match(/skill directory holds more than (\d+) files/i)
if (tooManyFiles) {
return t('settings.sandbox.skillBundleTooManyFiles', { count: tooManyFiles[1] })
}
const tooManyEntries = raw.match(/archive has more than (\d+) zip entries/i)
if (tooManyEntries) {
return t('settings.sandbox.skillBundleTooManyZipEntries', { count: tooManyEntries[1] })
}
const legacyTooMany = raw.match(/archive holds more than (\d+) files/i)
if (legacyTooMany) {
return t('settings.sandbox.skillBundleTooManyFiles', { count: legacyTooMany[1] })
}
if (raw) return raw
return fromFile
? t('settings.sandbox.skillUploadFailed')
: t('settings.sandbox.skillSourceFailed')
}
async function registerThenAdvance() {
if (registeredCatalog.value) {
addTargetIds.value = defaultAddTargets()
addStep.value = 1
return
}
const source = sourceInput.value.trim()
if (!pendingFile.value && !source) return
try {
let registered: SkillCatalogRegisterResult | null = null
if (pendingFile.value) {
uploading.value = true
uploadPercent.value = 0
const res = await registerSkillCatalogFromFile(pendingFile.value, (percent) => {
uploadPercent.value = percent
})
registered = catalogFromRegister(res?.data, pendingFile.value.name)
} else {
addingFromSource.value = true
const res = await registerSkillCatalogFromSource(source)
registered = catalogFromRegister(res?.data, source)
}
if (!registered) {
await loadCatalog()
return
}
registeredCatalog.value = registered
addTargetIds.value = defaultAddTargets()
addStep.value = 1
MessagePlugin.success(t('settings.skills.registerAccepted'))
await loadCatalog()
syncRegisteredFromCatalog()
} catch (e: any) {
MessagePlugin.error(skillRegisterErrorMessage(e, Boolean(pendingFile.value)))
} finally {
uploading.value = false
addingFromSource.value = false
uploadPercent.value = 0
if (fileInputRef.value) fileInputRef.value.value = ''
}
}
function catalogInstallFailedCount(res: { data?: { errors?: Record<string, string> } } | null | undefined): number {
return Object.keys(res?.data?.errors || {}).length
}
async function handleAddPrimary() {
if (addPrimaryLoading.value || addPrimaryDisabled.value) return
if (addStep.value === 0) {
await registerThenAdvance()
return
}
const catalogId = registeredCatalog.value?.id
if (!catalogId) return
const targets = [...addTargetIds.value]
if (targets.length === 0) {
showAdd.value = false
revealCatalog(catalogId)
return
}
const upgrading = pickedOnlyUpgrades(addPickRows.value, targets)
installing.value = true
try {
await ensureInstallerModelIfNeeded(targets)
const res = await installSkillCatalog(catalogId, targets)
const failed = catalogInstallFailedCount(res)
if (failed > 0) {
MessagePlugin.warning(t('settings.skills.installPartial', { failed }))
} else {
MessagePlugin.success(t(upgrading ? 'settings.skills.upgradeAccepted' : 'settings.skills.installAccepted'))
}
rememberSession(addSessionIds, targets)
await loadCatalog()
prunePicks(addTargetIds, addPickRows.value)
} catch (e: any) {
MessagePlugin.error(e?.message || t('settings.sandbox.skillUploadFailed'))
} finally {
installing.value = false
}
}
function onFileInputChange(event: Event) {
const input = event.target as HTMLInputElement
const file = input.files?.[0]
if (file) acceptPendingFile(file)
}
function onFileDrop(event: DragEvent) {
if (addBusy.value || registeredCatalog.value) return
const file = event.dataTransfer?.files?.[0]
if (file) acceptPendingFile(file)
}
function onInstallDrawerConfirm() {
if (installTargetIds.value.length === 0) {
showInstall.value = false
return
}
void confirmInstall()
}
async function confirmInstall() {
const item = installCatalog.value
const targets = [...installTargetIds.value]
if (!item || targets.length === 0) return
const upgrading = pickedOnlyUpgrades(installPickRows.value, targets)
installing.value = true
try {
await ensureInstallerModelIfNeeded(targets)
const res = await installSkillCatalog(item.id, targets)
const failed = catalogInstallFailedCount(res)
if (failed > 0) {
MessagePlugin.warning(t('settings.skills.installPartial', { failed }))
} else {
MessagePlugin.success(t(upgrading ? 'settings.skills.upgradeAccepted' : 'settings.skills.installAccepted'))
}
rememberSession(installSessionIds, targets)
await loadCatalog()
prunePicks(installTargetIds, installPickRows.value)
} catch (e: any) {
MessagePlugin.error(e?.message || t('settings.sandbox.skillUploadFailed'))
} finally {
installing.value = false
}
}
async function removeCatalog(item: SkillCatalogItem) {
if (!canDelete(item)) {
MessagePlugin.warning(t('settings.skills.deleteCatalogBlocked'))
return
}
deletingId.value = item.id
try {
await deleteSkillCatalog(item.id)
MessagePlugin.success(t('settings.skills.deleteSuccess'))
await loadCatalog()
} catch (e: any) {
MessagePlugin.error(e?.message || t('common.deleteFailed'))
} finally {
deletingId.value = ''
}
}
function catalogBusy(): boolean {
return catalog.value.some((item) =>
liveInstalls(item).some((inst) => inst.status === 'installing' || inst.status === 'removing'),
)
}
function stopPoll() {
if (pollTimer != null) {
window.clearInterval(pollTimer)
pollTimer = null
}
}
function ensurePoll() {
if (!catalogBusy()) {
stopPoll()
return
}
if (pollTimer != null) return
pollTimer = window.setInterval(() => {
void loadCatalog(true)
}, 2500)
}
async function loadCatalog(silent = false) {
try {
const res = await listSkillCatalog()
catalog.value = res?.data || []
emit('count', catalog.value.length)
} catch (e: any) {
if (!silent) MessagePlugin.error(e?.message || t('settings.skills.loadFailed'))
} finally {
ensurePoll()
}
}
async function load() {
loading.value = true
try {
await deploymentCapabilities.ensureLoaded()
// Lite lists no configs but still reports the workspace script policy.
const [configRes] = await Promise.all([listSandboxConfigs(), loadCatalog()])
records.value = hostOnly.value ? [] : configRes?.data || []
scriptsDisabled.value = configRes?.workspace_scripts_disabled === true
} catch (e: any) {
MessagePlugin.error(e?.message || t('settings.skills.loadFailed'))
} finally {
loading.value = false
}
}
async function enableScripts() {
policySaving.value = true
try {
const res = await setSandboxWorkspacePolicy(false)
scriptsDisabled.value = res?.workspace_scripts_disabled === true
MessagePlugin.success(t('settings.sandbox.scriptsEnabled'))
} catch (e: any) {
MessagePlugin.error(e?.message || t('settings.sandbox.policySaveFailed'))
} finally {
policySaving.value = false
}
}
watch(showManage, (open) => {
if (!open) {
void loadCatalog()
manageSkillId.value = ''
manageCatalogId.value = ''
manageRecord.value = null
} else {
openPanelId.value = ''
}
})
watch(showInstall, (open) => {
if (open) {
openPanelId.value = ''
return
}
installSessionIds.value = []
})
watch(showAdd, (open) => {
if (open) {
openPanelId.value = ''
return
}
const catalogId = registeredCatalog.value?.id
resetAddWizard()
void loadCatalog()
if (catalogId) revealCatalog(catalogId)
})
const busyPickTargets = computed(() => {
const seen = new Set<string>()
const targets: { configId: string; skillId: string }[] = []
const consider = (rows: SandboxPickRow[]) => {
for (const row of rows) {
if (!row.busy || !row.install?.skill_id) continue
const key = `${row.cfg.id}:${row.install.skill_id}`
if (seen.has(key)) continue
seen.add(key)
targets.push({ configId: row.cfg.id, skillId: row.install.skill_id })
}
}
if (showInstall.value) consider(installPickRows.value)
if (showAdd.value && addStep.value === 1) consider(addPickRows.value)
return targets
})
watch(busyPickTargets, (targets) => {
syncInstallProgress(targets)
}, { immediate: true })
onMounted(load)
useAssistantDataChange(() => { void loadCatalog(true) }, { areas: ['skill'] })
defineExpose({ openAdd })
onUnmounted(() => {
stopPoll()
stopInstallProgress()
if (focusTimer != null) window.clearTimeout(focusTimer)
})
</script>
<style lang="less" scoped>
@import (reference) '@/components/css/provider-card.less';
@import (reference) '@/components/css/settings-section.less';
.skill-settings {
width: 100%;
}
.skill-settings__scripts-off {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
padding: 10px 12px;
border: 1px solid var(--td-warning-color-3);
border-radius: var(--app-radius-md);
background: var(--td-warning-color-1);
p {
margin: 0;
color: var(--td-text-color-primary);
}
}
.section-header {
.settings-section-header();
&__title-row {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
}
&__help {
color: var(--td-text-color-placeholder);
font-size: var(--app-text-xl);
cursor: help;
transition: color var(--app-motion-fast) ease;
&:hover {
color: var(--td-text-color-secondary);
}
}
}
:global(.skill-settings__help-tooltip .t-popup__content) {
max-width: 340px;
line-height: 1.55;
}
:global(.skill-install-panel-overlay) {
z-index: 3050 !important;
}
:global(.skill-install-panel-overlay .t-popup__content) {
padding: 0 !important;
border-radius: var(--app-radius-md) !important;
border: 1px solid var(--td-component-stroke) !important;
background: var(--td-bg-color-container) !important;
box-shadow: var(--td-shadow-2) !important;
}
.loading-container {
padding: 40px 0;
text-align: center;
}
.empty-state {
padding: 80px 0;
text-align: center;
:deep(.t-empty__description) {
font-size: var(--app-text-base);
color: var(--td-text-color-placeholder);
margin-bottom: 16px;
}
}
.empty-hint {
margin: 0 0 16px;
font-size: var(--app-text-md);
color: var(--td-text-color-placeholder);
}
.empty-actions {
display: flex;
justify-content: center;
gap: 8px;
}
.skill-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
gap: 12px;
align-items: stretch;
}
.skill-card {
position: relative;
display: flex;
flex-direction: column;
padding: 0;
overflow: hidden;
border: 1px solid var(--td-component-stroke);
border-radius: var(--app-radius-md);
background: var(--td-bg-color-container);
transition: border-color 0.18s ease, box-shadow 0.18s ease;
min-width: 0;
height: 100%;
&:hover:not(.skill-card--add, .skill-card--focused) {
border-color: color-mix(in srgb, var(--td-brand-color) 40%, var(--td-component-stroke));
box-shadow: 0 3px 12px color-mix(in srgb, var(--td-text-color-primary) 6%, transparent);
}
&--focused {
border-color: var(--td-brand-color);
box-shadow: 0 0 0 2px var(--td-brand-color-focus);
}
&--idle .skill-card__badge {
background: var(--td-bg-color-secondarycontainer);
color: var(--td-text-color-placeholder);
}
&:hover .skill-card__actions,
&:focus-within .skill-card__actions,
&--focused .skill-card__actions {
opacity: 1;
}
&--add {
flex-direction: column;
align-items: center;
justify-content: center;
gap: 6px;
height: 100%;
min-height: 88px;
padding: 12px;
border-style: dashed;
background: transparent;
color: var(--td-text-color-placeholder);
cursor: pointer;
font: inherit;
text-align: center;
&:hover,
&:focus-visible {
color: var(--td-brand-color);
border-color: var(--td-brand-color);
background: color-mix(in srgb, var(--td-brand-color) 6%, transparent);
box-shadow: none;
.skill-card--add__icon {
background: color-mix(in srgb, var(--td-brand-color) 10%, transparent);
color: var(--td-brand-color);
}
}
&__icon {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border-radius: var(--app-radius-md);
background: var(--td-bg-color-secondarycontainer);
color: var(--td-text-color-secondary);
font-size: var(--app-text-2xl);
}
&__label {
font-size: var(--app-text-md);
font-weight: 500;
line-height: 1.4;
}
}
}
.skill-card__main {
display: flex;
align-items: stretch;
padding: 12px 14px 8px;
min-width: 0;
flex: 1;
}
.skill-card__badge {
.provider-card-badge(28px, 7px);
--skill-hue: var(--td-brand-color);
margin-top: 0;
font-size: var(--app-text-base);
font-weight: 600;
line-height: 1;
letter-spacing: 0;
background: color-mix(in srgb, var(--skill-hue) 12%, transparent);
color: var(--skill-hue);
user-select: none;
}
.skill-drawer-avatar {
--skill-hue: var(--td-brand-color);
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
border-radius: inherit;
background: color-mix(in srgb, var(--skill-hue) 12%, var(--td-bg-color-container));
color: var(--skill-hue);
font-size: var(--app-text-md);
font-weight: 600;
line-height: 1;
user-select: none;
}
.skill-card__body {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 6px;
}
.skill-card__header {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
min-height: 28px;
}
.skill-card__heading {
flex: 1;
min-width: 0;
display: flex;
align-items: baseline;
gap: 6px;
}
.skill-card__title {
flex: 0 1 auto;
min-width: 0;
margin: 0;
font-size: var(--app-text-base);
font-weight: 600;
line-height: 20px;
color: var(--td-text-color-primary);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.skill-card__actions {
flex-shrink: 0;
display: flex;
align-items: center;
gap: 2px;
opacity: 0;
transition: opacity var(--app-motion-fast) ease;
@media (hover: none) {
opacity: 1;
}
}
.skill-card__icon-btn {
flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
margin: 0;
padding: 0;
border: 0;
border-radius: var(--app-radius-sm);
background: none;
color: var(--td-text-color-placeholder);
cursor: pointer;
:deep(svg) {
display: block;
overflow: visible;
}
&:hover:not(:disabled) {
color: var(--td-text-color-primary);
background: var(--td-bg-color-container-hover);
}
&--danger:hover:not(:disabled) {
color: var(--td-error-color);
background: color-mix(in srgb, var(--td-error-color) 8%, transparent);
}
&:disabled {
cursor: not-allowed;
opacity: 0.4;
}
}
.skill-card__type {
flex-shrink: 0;
padding: 0 6px;
border-radius: var(--app-radius-sm);
background: var(--td-bg-color-secondarycontainer);
font-size: var(--app-text-xs);
font-weight: 500;
line-height: 18px;
color: var(--td-text-color-placeholder);
font-variant-numeric: tabular-nums;
}
.skill-card__desc {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
line-clamp: 2;
margin: 0;
min-height: calc(2 * 1.5em);
overflow: hidden;
font-size: var(--app-text-sm);
line-height: 1.5;
color: var(--td-text-color-secondary);
overflow-wrap: anywhere;
}
.skill-card__installs {
display: flex;
align-items: center;
gap: 6px;
min-width: 0;
margin-top: auto;
padding-top: 6px;
border-top: 1px solid var(--td-component-stroke);
}
.skill-card__installs-label {
font-size: var(--app-text-sm);
line-height: 18px;
color: var(--td-text-color-placeholder);
}
.skill-card__chip {
display: inline-flex;
align-items: center;
gap: 6px;
min-width: 0;
max-width: 100%;
height: 26px;
margin: 0 0 0 -6px;
padding: 0 6px;
border: 0;
border-radius: var(--app-radius-sm);
background: transparent;
color: var(--td-text-color-secondary);
cursor: pointer;
font: inherit;
font-size: var(--app-text-sm);
line-height: 18px;
text-align: left;
transition: background-color var(--app-motion-fast) ease, color var(--app-motion-fast) ease;
&:hover:not(:disabled),
&[aria-expanded='true'] {
color: var(--td-text-color-primary);
background: var(--td-bg-color-container-hover);
}
&:disabled {
cursor: default;
opacity: 0.6;
}
&--idle {
color: var(--td-brand-color);
&:hover:not(:disabled),
&[aria-expanded='true'] {
color: var(--td-brand-color);
background: color-mix(in srgb, var(--td-brand-color) 8%, transparent);
}
.skill-card__chip-go {
color: var(--td-brand-color);
}
}
&--upgrade {
flex-shrink: 0;
gap: 2px;
margin: 0 0 0 auto;
height: 22px;
padding: 0 8px 0 6px;
border-radius: 999px;
color: var(--td-brand-color);
background: color-mix(in srgb, var(--td-brand-color) 10%, transparent);
font-size: var(--app-text-xs);
font-weight: 500;
&:hover:not(:disabled) {
color: var(--td-brand-color);
background: color-mix(in srgb, var(--td-brand-color) 16%, transparent);
}
.skill-card__chip-go {
color: var(--td-brand-color);
}
}
&.skill-card__entry--off .skill-card__chip-dot {
background: var(--td-text-color-disabled);
}
&.skill-card__entry--stale .skill-card__chip-dot {
background: var(--td-warning-color);
}
&.skill-card__entry--failed .skill-card__chip-dot {
background: var(--td-error-color);
}
&.skill-card__entry--busy .skill-card__chip-dot {
background: var(--td-warning-color);
animation: skill-chip-dot 1.2s ease-in-out infinite;
}
}
.skill-card__chip-text {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.skill-card button:focus-visible,
.skill-card--add:focus-visible {
outline: 2px solid var(--td-brand-color);
outline-offset: -2px;
}
.skill-card__chip-go,
.skill-card__entry-status {
flex-shrink: 0;
}
.skill-card__entry--ready .skill-card__entry-status {
color: var(--td-success-color);
}
.skill-card__chip-go {
color: var(--td-text-color-placeholder);
}
.skill-card__chip:hover:not(:disabled) .skill-card__chip-go {
color: currentColor;
}
.skill-card__chip-go {
transition: transform var(--app-motion-fast) ease;
&.is-open {
transform: rotate(180deg);
}
}
.skill-card__chip-lead {
flex-shrink: 0;
}
.skill-card__chip-dot {
flex-shrink: 0;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--td-success-color);
}
.skill-card__chip-more {
flex-shrink: 0;
color: var(--td-text-color-placeholder);
font-variant-numeric: tabular-nums;
}
.skill-card__entry-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
animation: skill-chip-dot 1.2s ease-in-out infinite;
}
.skill-install-panel {
display: flex;
flex-direction: column;
width: 280px;
max-width: calc(100vw - 32px);
max-height: min(380px, 70vh);
overflow-y: auto;
padding: 6px;
box-sizing: border-box;
}
.skill-install-panel__group {
display: flex;
align-items: center;
gap: 6px;
margin: 0;
padding: 4px 8px 4px;
font-size: var(--app-text-xs);
font-weight: 500;
line-height: 18px;
color: var(--td-text-color-placeholder);
}
.skill-install-panel__group-count {
font-variant-numeric: tabular-nums;
opacity: 0.8;
}
.skill-install-panel__item {
display: flex;
align-items: center;
gap: 8px;
width: 100%;
min-height: 34px;
margin: 0 0 1px;
padding: 0 8px;
border: 0;
border-radius: var(--app-radius-sm);
background: none;
color: var(--td-text-color-primary);
cursor: pointer;
font: inherit;
font-size: var(--app-text-md);
line-height: 22px;
text-align: left;
transition: background-color var(--app-motion-fast) ease;
&:hover:not(:disabled),
&:focus-visible {
background: var(--td-bg-color-container-hover);
}
&:disabled {
cursor: default;
opacity: 0.5;
}
&.skill-card__entry--off .skill-install-panel__name {
color: var(--td-text-color-placeholder);
}
&.skill-card__entry--stale .skill-install-panel__status {
color: var(--td-warning-color);
background: color-mix(in srgb, var(--td-warning-color) 10%, transparent);
}
&.skill-card__entry--failed .skill-install-panel__status {
color: var(--td-error-color);
background: color-mix(in srgb, var(--td-error-color) 10%, transparent);
}
&.skill-card__entry--busy .skill-install-panel__status {
color: var(--td-warning-color);
}
&.skill-card__entry--busy .skill-card__entry-dot {
background: var(--td-warning-color);
}
}
.skill-install-panel__name {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.skill-install-panel__status {
flex-shrink: 0;
display: inline-flex;
align-items: center;
gap: 3px;
max-width: 120px;
padding: 0 6px;
border-radius: 999px;
background: var(--td-bg-color-secondarycontainer);
color: var(--td-text-color-secondary);
font-size: var(--app-text-xs);
line-height: 18px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.skill-install-panel__go {
flex-shrink: 0;
margin-right: -2px;
color: var(--td-text-color-placeholder);
opacity: 0;
transition: opacity var(--app-motion-fast) ease;
}
.skill-install-panel__item:hover:not(:disabled) .skill-install-panel__go,
.skill-install-panel__item:focus-visible .skill-install-panel__go {
opacity: 1;
}
.skill-install-panel__item--available {
color: var(--td-text-color-secondary);
:deep(.sandbox-badge) {
filter: grayscale(1);
opacity: 0.7;
transition: filter var(--app-motion-fast) ease, opacity var(--app-motion-fast) ease;
}
&:hover,
&:focus-visible {
color: var(--td-text-color-primary);
:deep(.sandbox-badge) {
filter: none;
opacity: 1;
}
}
}
.skill-install-panel__add {
flex-shrink: 0;
display: inline-flex;
align-items: center;
gap: 2px;
font-size: var(--app-text-xs);
font-weight: 500;
line-height: 18px;
color: var(--td-brand-color);
opacity: 0;
transition: opacity var(--app-motion-fast) ease;
}
.skill-install-panel__item--available:hover .skill-install-panel__add,
.skill-install-panel__item--available:focus-visible .skill-install-panel__add {
opacity: 1;
}
.skill-install-panel__split {
height: 1px;
margin: 5px 2px;
background: var(--td-component-stroke);
}
@keyframes skill-chip-dot {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.35;
}
}
.installer-model-hint {
margin: 0;
font-size: var(--app-text-sm);
line-height: 1.5;
color: var(--td-text-color-secondary);
}
.parsed-skill {
margin: 0 0 16px;
}
.skill-add-steps {
display: flex;
align-items: center;
gap: 8px;
margin: 0;
}
.skill-add-step {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
color: var(--td-text-color-placeholder);
transition: color var(--app-motion-fast) ease;
&:not(:last-child) {
flex: 1;
}
&.is-active {
color: var(--td-brand-color);
}
&.is-done {
color: var(--td-text-color-secondary);
}
&.is-clickable {
padding: 0;
font: inherit;
text-align: left;
background: none;
border: 0;
cursor: pointer;
&:hover:not(.is-active) {
color: var(--td-brand-color);
}
&:focus-visible {
outline: 2px solid var(--td-brand-color);
outline-offset: 2px;
border-radius: var(--app-radius-xs);
}
}
}
.skill-add-step__marker {
display: inline-flex;
align-items: center;
justify-content: center;
width: 22px;
height: 22px;
flex-shrink: 0;
border: 1px solid currentColor;
border-radius: 50%;
font-size: var(--app-text-xs);
font-weight: 600;
line-height: 1;
.is-active & {
background: var(--td-brand-color);
border-color: var(--td-brand-color);
color: #fff;
}
.is-done & {
background: color-mix(in srgb, var(--td-brand-color) 12%, transparent);
border-color: color-mix(in srgb, var(--td-brand-color) 35%, transparent);
color: var(--td-brand-color);
}
}
.skill-add-step__title {
overflow: hidden;
font-size: var(--app-text-md);
font-weight: 500;
text-overflow: ellipsis;
white-space: nowrap;
}
.skill-add-step__line {
flex: 1;
min-width: 16px;
height: 1px;
margin: 0 4px;
background: var(--td-component-stroke);
.is-done & {
background: color-mix(in srgb, var(--td-brand-color) 35%, transparent);
}
}
.sandbox-pick-list {
display: flex;
flex-direction: column;
gap: 8px;
width: 100%;
min-width: 0;
max-width: 100%;
box-sizing: border-box;
:deep(.t-checkbox) {
width: 100%;
max-width: 100%;
margin: 0;
align-items: center;
padding: 10px 12px;
border: 1px solid var(--td-component-stroke);
border-radius: var(--app-radius-lg);
background: var(--td-bg-color-container);
cursor: pointer;
box-sizing: border-box;
&:hover:not(.t-is-disabled) {
border-color: color-mix(in srgb, var(--td-brand-color) 40%, transparent);
background: color-mix(in srgb, var(--td-brand-color) 4%, transparent);
}
&.t-is-checked {
border-color: color-mix(in srgb, var(--td-brand-color) 40%, transparent);
background: color-mix(in srgb, var(--td-brand-color) 5%, transparent);
}
}
:deep(.t-checkbox__label) {
width: 100%;
min-width: 0;
margin: 0;
padding-left: 8px;
white-space: normal;
}
:deep(.t-checkbox__former),
:deep(.t-checkbox__input) {
flex-shrink: 0;
margin-top: 0;
align-self: center;
}
}
.sandbox-pick-row {
min-width: 0;
max-width: 100%;
}
.sandbox-pick--status {
display: flex;
align-items: center;
gap: 10px;
width: 100%;
max-width: 100%;
min-width: 0;
box-sizing: border-box;
padding: 10px 12px;
border: 1px solid var(--td-component-stroke);
border-radius: var(--app-radius-lg);
background: var(--td-bg-color-container);
.sandbox-pick__main {
flex: 1;
min-width: 0;
}
.sandbox-pick__progress,
:deep(.t-button) {
flex-shrink: 0;
}
.sandbox-pick-row.is-busy & {
border-color: color-mix(in srgb, var(--td-warning-color) 35%, transparent);
}
}
.sandbox-pick__main {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
}
.sandbox-pick__text {
display: flex;
flex-direction: column;
gap: 1px;
min-width: 0;
}
.sandbox-pick__name {
font-size: var(--app-text-md);
font-weight: 500;
color: var(--td-text-color-primary);
line-height: 1.3;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.sandbox-pick__meta {
font-size: var(--app-text-sm);
color: var(--td-text-color-secondary);
line-height: 1.3;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.sandbox-pick__progress {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: var(--app-text-sm);
font-weight: 500;
line-height: 1;
color: var(--td-brand-color);
:deep(.t-progress--circle svg) {
display: block;
}
}
.skill-source-row {
width: 100%;
}
.file-input-hidden {
display: none;
}
.file-upload-area {
border: 1px dashed var(--td-component-stroke);
border-radius: var(--app-radius-lg);
cursor: pointer;
transition: border-color var(--app-motion-fast) ease, background var(--app-motion-fast) ease;
&:hover:not(.is-disabled) {
border-color: var(--td-brand-color);
background: color-mix(in srgb, var(--td-brand-color) 4%, transparent);
}
&.is-disabled {
cursor: not-allowed;
opacity: 0.6;
}
}
.file-upload-content {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
padding: 24px 20px;
}
.file-upload-icon-wrap {
display: flex;
align-items: center;
justify-content: center;
width: 56px;
height: 56px;
border-radius: 50%;
background: color-mix(in srgb, var(--td-brand-color) 12%, transparent);
}
.upload-icon {
color: var(--td-brand-color);
}
.upload-text {
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
}
.upload-primary-text {
font-size: var(--app-text-lg);
font-weight: 500;
color: var(--td-text-color-primary);
}
.upload-secondary-text {
font-size: var(--app-text-md);
color: var(--td-text-color-secondary);
}
.upload-file-name {
font-size: var(--app-text-base);
font-weight: 500;
color: var(--td-brand-color);
}
</style>