diff --git a/client/skill.go b/client/skill.go index 11655fe1..b89a04e0 100644 --- a/client/skill.go +++ b/client/skill.go @@ -3,6 +3,7 @@ package client import ( "context" "net/http" + "net/url" ) // SkillInfo represents skill metadata @@ -15,12 +16,17 @@ type SkillInfo struct { type SkillListResponse struct { Success bool `json:"success"` Data []SkillInfo `json:"data"` - SkillsAvailable bool `json:"skills_available"` + SkillsAvailable bool `json:"skills_available"` } -// ListSkills lists all preloaded agent skills -func (c *Client) ListSkills(ctx context.Context) ([]SkillInfo, bool, error) { - resp, err := c.doRequest(ctx, http.MethodGet, "/api/v1/skills", nil, nil) +// ListSkills lists the installed skills a chat turn can invoke on one sandbox +// config. An empty sandboxConfigID returns an empty list. +func (c *Client) ListSkills(ctx context.Context, sandboxConfigID string) ([]SkillInfo, bool, error) { + query := url.Values{} + if sandboxConfigID != "" { + query.Set("sandbox_config_id", sandboxConfigID) + } + resp, err := c.doRequest(ctx, http.MethodGet, "/api/v1/skills", nil, query) if err != nil { return nil, false, err } diff --git a/docker/Dockerfile.sandbox b/docker/Dockerfile.sandbox index edc37d40..3150780e 100644 --- a/docker/Dockerfile.sandbox +++ b/docker/Dockerfile.sandbox @@ -23,13 +23,28 @@ COPY --from=node-base /usr/local/lib/node_modules /usr/local/lib/node_modules RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \ ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx +# Python package manager: uv (fast pip replacement). Preinstalled because each +# skill gets its own venv at install time, and building that from a cold pip is +# what dominates an install's wall clock. +COPY --from=ghcr.io/astral-sh/uv:0.12.4 /uv /usr/local/bin/uv +RUN ln -s /usr/local/bin/uv /usr/local/bin/uvx + +# Node package manager: pnpm +RUN npm install -g pnpm + # Install minimal CLI tools (bash/grep/sed/coreutils/findutils already in slim # image). curl is not optional: the sandbox connectivity check probes egress -# with it, and skills that fetch a URL expect it to be there. +# with it, and skills that fetch a URL expect it to be there. The compression +# tools are here because skill bundles and their assets arrive archived. RUN apt-get update && apt-get install -y --no-install-recommends \ jq \ curl \ ca-certificates \ + zip \ + unzip \ + bzip2 \ + xz-utils \ + zstd \ && rm -rf /var/lib/apt/lists/* /var/cache/apt/* # Note: Current preloaded skills only use Python stdlib diff --git a/frontend/src/api/agent/index.ts b/frontend/src/api/agent/index.ts index fc966406..7c64878f 100644 --- a/frontend/src/api/agent/index.ts +++ b/frontend/src/api/agent/index.ts @@ -65,6 +65,11 @@ export interface CustomAgentConfig { skills_selection_mode?: 'all' | 'selected' | 'none'; selected_skills?: string[]; // 选择的Skill名称列表 + // ===== 沙盒设置 ===== + // 该智能体的技能脚本运行在哪个沙盒配置上;为空表示不启用沙盒执行。 + // 指向逻辑配置而非某个具体版本,凭据轮换时无需重新指派每个智能体。 + sandbox_config_id?: string; + // ===== 知识库设置 ===== // 知识库选择模式:all=全部知识库, selected=指定知识库, none=不使用知识库 kb_selection_mode?: 'all' | 'selected' | 'none'; diff --git a/frontend/src/api/skill/index.ts b/frontend/src/api/skill/index.ts index 3edbc96b..80c8c2b5 100644 --- a/frontend/src/api/skill/index.ts +++ b/frontend/src/api/skill/index.ts @@ -6,7 +6,10 @@ export interface SkillInfo { description: string; } -// 获取预装Skills列表;skills_available 为 false 表示沙箱未启用,前端应隐藏/禁用 Skills 配置 -export function listSkills() { - return get<{ data: SkillInfo[]; skills_available?: boolean }>('/api/v1/skills'); +// 获取当前沙盒配置上可执行的 Skills;未传 sandboxConfigId 或 +// skills_available 为 false 时,前端应隐藏/禁用 Skills 配置 +export function listSkills(sandboxConfigId?: string) { + return get<{ data: SkillInfo[]; skills_available?: boolean }>('/api/v1/skills', { + params: sandboxConfigId ? { sandbox_config_id: sandboxConfigId } : {}, + }); } diff --git a/frontend/src/api/system/index.ts b/frontend/src/api/system/index.ts index 47fb2eb7..e18b6d24 100644 --- a/frontend/src/api/system/index.ts +++ b/frontend/src/api/system/index.ts @@ -1,4 +1,4 @@ -import { get, post, put, del } from '@/utils/request' +import { get, post, put, del, patch, postUpload } from '@/utils/request' import type { CreatedTenantAPIKey, TenantAPIKey, TenantAPIKeyCapability } from '@/api/tenant' export interface CreatePlatformAPIKeyPayload { @@ -749,12 +749,22 @@ export interface SandboxE2BConfig { e2b_sandbox_ttl_seconds?: number } +export interface SandboxSkillImage { + snapshot_id?: string + generation?: number + built_at?: string + base_template_id?: string + owner_fingerprint?: string +} + export interface SandboxConfig { sandbox_type?: string default_timeout_sec?: number allow_private_endpoints?: boolean env_vars?: Record volume_mount?: SandboxVolumeMountConfig + skill_image?: SandboxSkillImage + skill_rollout?: 'next_turn' | 'new_session' cube?: SandboxCubeConfig e2b?: SandboxE2BConfig docker?: SandboxDockerConfig @@ -980,3 +990,88 @@ export function parseSandboxConflict(err: unknown): SandboxConflict | null { } return { code: detail.code, message: detail.message, inventory: detail.data } } + +// --- Agent skills installed onto a sandbox config's image --- + +export type ConfigSkillStatus = 'installing' | 'ready' | 'failed' | 'removing' | 'removed' + +export interface ConfigSkill { + id: string + name: string + version?: string + description?: string + enabled: boolean + status: ConfigSkillStatus | string + error?: string + bundle_sha256?: string + installed_snapshot_id?: string + // Locators for this skill's most recent install conversation. Absent for + // skills installed before transcripts existed, which is how the drawer + // decides whether to offer the "view install" entry point. + install_session_id?: string + install_message_id?: string + created_at: string + updated_at: string +} + +export interface ConfigSkillInstallEvent { + percent: number + stage: string + log?: string + status?: string + done: boolean +} + +export function listConfigSkills(configId: string): Promise<{ data: ConfigSkill[] }> { + return get(`/api/v1/sandbox-configs/${configId}/skills`) as unknown as Promise<{ data: ConfigSkill[] }> +} + +export function uploadConfigSkill( + configId: string, file: File, onProgress?: (percent: number) => void, +): Promise<{ data: { skill_id: string } }> { + const form = new FormData() + form.append('file', file) + return postUpload(`/api/v1/sandbox-configs/${configId}/skills`, form, (e: any) => { + if (e.total) onProgress?.(Math.round((e.loaded * 100) / e.total)) + }, { timeout: 5 * 60 * 1000 }) +} + +export function patchConfigSkill( + configId: string, + skillId: string, + payload: { enabled: boolean }, +): Promise<{ data: ConfigSkill }> { + return patch(`/api/v1/sandbox-configs/${configId}/skills/${skillId}`, payload) as unknown as Promise<{ + data: ConfigSkill + }> +} + +export function deleteConfigSkill( + configId: string, + skillId: string, +): Promise<{ data: { skill_id: string } }> { + return del(`/api/v1/sandbox-configs/${configId}/skills/${skillId}`) as unknown as Promise<{ + data: { skill_id: string } + }> +} + +export function getConfigSkill( + configId: string, + skillId: string, +): Promise<{ data: ConfigSkill }> { + return get(`/api/v1/sandbox-configs/${configId}/skills/${skillId}`) as unknown as Promise<{ + data: ConfigSkill + }> +} + +export function configSkillInstallEventsUrl(configId: string, skillId: string): string { + return `/api/v1/sandbox-configs/${configId}/skills/${skillId}/install-events` +} + +// The installer agent's own transcript: its prompt, thinking, commands and +// their output, replayed from the start and then followed live. Answers 404 +// once the event log has expired, which is the signal to read the durable +// message history instead. +export function configSkillTranscriptUrl(configId: string, skillId: string): string { + return `/api/v1/sandbox-configs/${configId}/skills/${skillId}/transcript` +} diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue index e1cfef13..f39dbbcc 100644 --- a/frontend/src/components/Input-field.vue +++ b/frontend/src/components/Input-field.vue @@ -1328,7 +1328,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => const skillsMode = agentSkillsSelectionMode.value; if (skillsMode !== 'none') { - await editorResources.ensureSkills(); + await editorResources.ensureSkills(currentAgentConfig.value?.sandbox_config_id); skillItems = editorResources.skills .filter(skill => isSkillAllowedByAgent(skill.name)) .map(skill => ({ diff --git a/frontend/src/components/SandboxConfigEditorDrawer.vue b/frontend/src/components/SandboxConfigEditorDrawer.vue index fede8182..e01d5298 100644 --- a/frontend/src/components/SandboxConfigEditorDrawer.vue +++ b/frontend/src/components/SandboxConfigEditorDrawer.vue @@ -23,15 +23,26 @@ + + +
@@ -433,6 +456,7 @@ import { MessagePlugin } from 'tdesign-vue-next' import { useI18n } from 'vue-i18n' import SettingDrawer from '@/components/settings/SettingDrawer.vue' import SandboxBackendBadge from '@/components/settings/SandboxBackendBadge.vue' +import SandboxSkillsPanel from '@/components/SandboxSkillsPanel.vue' import { checkSandboxConfig, createSandboxConfig, @@ -452,10 +476,15 @@ import { NAMED_SANDBOX_BACKEND_TYPES, } from '@/api/system' +type SandboxStepKey = 'connection' | 'template' | 'runtime' | 'skills' + const props = defineProps<{ visible: boolean record: SandboxConfigRecord | null presetType?: string + // Which page to land on when opening an existing config, e.g. 'skills' from + // the card's 管理技能 entry. Ignored while creating, where order is enforced. + initialStep?: SandboxStepKey }>() const emit = defineEmits<{ @@ -515,7 +544,6 @@ const currentTemplateId = computed(() => ( backend.value === 'cube' ? cube.template_id : backend.value === 'e2b' ? e2b.template_id : '' )?.trim() || '') const selectedTemplate = computed(() => templates.value.find((item) => item.id === currentTemplateId.value)) -type SandboxStepKey = 'connection' | 'template' | 'runtime' const wizardSteps = computed>(() => { const steps: Array<{ key: SandboxStepKey; title: string }> = [ { key: 'connection', title: t('settings.sandbox.stepConnection') }, @@ -524,6 +552,12 @@ const wizardSteps = computed>(() = steps.push({ key: 'template', title: t('settings.sandbox.stepTemplate') }) } steps.push({ key: 'runtime', title: t('settings.sandbox.stepRuntime') }) + // Skills are baked into the config's snapshot image, which only the remote + // backends have. Docker and local configs therefore end at runtime rather + // than showing a step that could never do anything. + if (isRemoteBackend.value) { + steps.push({ key: 'skills', title: t('settings.sandbox.stepSkills') }) + } return steps }) const currentStepKey = computed(() => wizardSteps.value[wizardStep.value]?.key || 'connection') @@ -531,12 +565,51 @@ const stepDescription = computed(() => t(`settings.sandbox.stepDescriptions.${cu const primaryText = computed(() => { if (currentStepKey.value === 'connection') return t('settings.sandbox.connectAndContinue') if (currentStepKey.value === 'template') return t('common.next') + // Nothing on the skills step is pending a save — each install, toggle and + // removal already went to the server on its own. + if (currentStepKey.value === 'skills') return t('common.finish') return t('common.save') }) const primaryDisabled = computed(() => ( currentStepKey.value === 'template' && (!selectedTemplate.value || !isTemplateSelectable(selectedTemplate.value)) )) + +// savedRecord is the config this drawer is editing, including one it just +// created: after the first save the wizard keeps going into the skills step, +// which needs an ID, and a second press of save must update that config rather +// than create another one. +const savedRecord = ref(null) +const effectiveRecord = computed(() => savedRecord.value || props.record) + +function onSkillsConfigUpdated(record: SandboxConfigRecord) { + savedRecord.value = record +} + +// Jumping is what separates editing from creating. A config that does not exist +// yet has to be built in order — its connection has to check out before there +// are templates to choose from, and it has no image to install skills into. Once +// it exists, every step is just a page of its settings, so all of them open +// directly; steps already visited stay clickable during creation so the rail +// works as a way back. +function canJumpTo(index: number): boolean { + if (index === wizardStep.value) return false + return Boolean(effectiveRecord.value) || index < wizardStep.value +} + +function goToStep(index: number) { + if (!canJumpTo(index)) return + wizardStep.value = index + if (currentStepKey.value !== 'template') { + stopTemplatePolling() + return + } + // Landing on the template step without having passed through the connection + // step still has to ask the cluster what it offers; a step already loaded + // just resumes its poll, as walking back through it always has. + if (templatesLoaded.value) scheduleTemplatePolling() + else void loadTemplates(true) +} const hasPendingTemplates = computed(() => templates.value.some(isTemplatePending)) const backendLabel = (value: string) => t(`settings.sandbox.backends.${value}`) @@ -663,7 +736,14 @@ function reset() { templates.value = [] templatesLoaded.value = false templatesError.value = '' + savedRecord.value = null wizardStep.value = 0 + // "管理技能" opens this drawer straight on the skills step. It is a jump like + // any other, so it only holds for a config that already exists. + if (props.initialStep && props.record) { + const index = wizardSteps.value.findIndex((step) => step.key === props.initialStep) + if (index >= 0) wizardStep.value = index + } } function selectBackend(value: string) { @@ -783,7 +863,7 @@ async function loadTemplates(ensureStandard: boolean, silent = false): Promise step.key === 'skills') + if (!existing && skillsStep >= 0 && savedRecord.value) { + // A config created a moment ago has an empty image; walking into the + // skills step is the whole reason the wizard has a fourth page. + wizardStep.value = skillsStep + return + } close() } catch (e: any) { const refusal = parseSandboxConflict(e) @@ -932,7 +1027,7 @@ async function runCheck(deep: boolean): Promise { // so an edited form can be probed without retyping the API key. const res = await checkSandboxConfig({ config: collectPayload(), - config_id: props.record?.id, + config_id: effectiveRecord.value?.id, deep, }) checkResult.value = res?.data || null @@ -1007,6 +1102,30 @@ onUnmounted(stopTemplatePolling) &.is-done { color: var(--td-text-color-secondary); } + + /* + Reachable steps render as