From 01ec6c0509a6e1ad62617f6125d3093842910fb0 Mon Sep 17 00:00:00 2001 From: lyingbug Date: Tue, 25 Aug 2026 13:24:58 +0800 Subject: [PATCH] ui(sandbox): rename settings to skill sandbox and fix skill install (#2792) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ui(sandbox): rename settings to code sandbox and simplify cards "Sandbox backend" leaked implementation jargon into the settings nav. Call the page what users configure — an isolated runtime for skill scripts — and only surface incomplete-config warnings on the cards. * fix(sandbox): type the card overflow menu options vue-tsc rejected pushing a themed delete item onto an untyped options array; name the option shape so the menu still marks delete as danger. * fix(sandbox): keep the editor wizard moving into skills Saving on the runtime step used to close the drawer when editing, so step 4 was only reachable from the rail. Continue after save, move full verification off the runtime form, and stop treating "using the base template" as the empty value for every image field. * fix(sandbox): store skill bundles on the workspace default backend Skill install passed a stub tenant with no default storage, so saving the zip failed with empty provider and the 500 hid the real cause. * ui(sandbox): regroup skill install and rename to skill sandbox Show install vs installed groups, fold long descriptions in the list, and call the settings surface a skill sandbox. * ui(sandbox): show skill install transcript in a compact popup Keep the card from growing; the run opens beside the history button with a capped height and its own scroll. * ui(sandbox): show installed skills on config cards Cube/E2B tiles now list skill names so the list reads as skill sandboxes; a click opens the editor on the skills step. * ui(sandbox): show finished skill installs as static history A completed run already has durable messages; replaying the event log would animate the whole install again. Hide chat answer actions in this transcript. * style(frontend): enhance compact skill timeline display with improved font sizes Updated the CSS for the compact skill timeline to adjust font sizes for various elements, ensuring better readability in the popup interface. This includes specific adjustments for embedded agent streams and markdown content. * ui(sandbox): refactor header structure in SandboxConfigEditorDrawer and SettingDrawer Updated the header structure in both SandboxConfigEditorDrawer and SettingDrawer components to improve layout and organization. Added a new slot for extra header content in SettingDrawer and adjusted CSS for better alignment and spacing in both components. * ui(sandbox): enhance skill loading feedback and improve deep check logic Updated the SandboxConfigEditorDrawer to refine the logic for deep checks based on the current step. Enhanced the SkillInstallTimeline component to manage in-flight live loops and provide better feedback for skill loading failures. Adjusted the SandboxSettings view to display error messages for failed skill loads, ensuring users are informed of any issues during the skill installation process. --- .../components/SandboxConfigEditorDrawer.vue | 210 +++---- .../src/components/SandboxSkillsPanel.vue | 558 +++++++++++------- .../src/components/SkillInstallTimeline.vue | 106 +++- .../src/components/settings/SettingDrawer.vue | 34 +- frontend/src/i18n/locales/en-US.ts | 44 +- frontend/src/i18n/locales/ko-KR.ts | 52 +- frontend/src/i18n/locales/ru-RU.ts | 52 +- frontend/src/i18n/locales/zh-CN.ts | 70 ++- frontend/src/views/agent/AgentEditorModal.vue | 6 +- .../src/views/settings/SandboxSettings.vue | 444 ++++++++------ frontend/src/views/settings/Settings.vue | 13 +- .../application/service/storagebackend.go | 63 +- .../service/storagebackend_test.go | 39 ++ .../service/tenant_skill_install.go | 37 +- .../service/tenant_skill_install_test.go | 21 + .../service/tenant_skill_remove.go | 5 +- internal/middleware/logger.go | 12 +- 17 files changed, 1105 insertions(+), 661 deletions(-) diff --git a/frontend/src/components/SandboxConfigEditorDrawer.vue b/frontend/src/components/SandboxConfigEditorDrawer.vue index e01d5298..2fd47f31 100644 --- a/frontend/src/components/SandboxConfigEditorDrawer.vue +++ b/frontend/src/components/SandboxConfigEditorDrawer.vue @@ -4,7 +4,7 @@ :visible="visible" :title="record ? $t('settings.sandbox.editTitle') : $t('settings.sandbox.createTitle')" :description="stepDescription" - icon="server" + icon="code" width="680px" :min-width="560" :max-width="920" @@ -20,30 +20,41 @@ {{ $t('settings.sandbox.back') }} + + + {{ lastCheckWasDeep ? $t('settings.sandbox.recheck') : $t('settings.sandbox.deepCheck') }} + + - + -
-

- {{ $t('settings.sandbox.checkPendingHint', { names: pendingCheckNames.join('、') }) }} -

- - - {{ lastCheckWasDeep ? $t('settings.sandbox.recheck') : $t('settings.sandbox.deepCheck') }} - - -
+

+ {{ $t('settings.sandbox.checkPendingHint', { names: pendingCheckNames.join('、') }) }} +

- -
-

{{ $t('settings.sandbox.deepCheckIntro') }}

- - - {{ $t('settings.sandbox.deepCheck') }} - - -
- @@ -568,8 +548,21 @@ const primaryText = computed(() => { // 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') + // Runtime is the last page of settings. If skills follow, keep the wizard + // going after the save; otherwise this press closes the drawer. + if (wizardSteps.value.some((step) => step.key === 'skills')) { + return t('settings.sandbox.saveAndContinue') + } return t('common.save') }) +// Deep check needs the fields that actually get probed. Docker/local collect +// the image on the connection step; Cube/E2B still have an empty template_id +// there, so the action waits until the template step. +const canDeepCheck = computed(() => { + if (currentStepKey.value === 'template') return true + return currentStepKey.value === 'connection' && !isRemoteBackend.value +}) +const showCheckResult = computed(() => canDeepCheck.value) const primaryDisabled = computed(() => ( currentStepKey.value === 'template' && (!selectedTemplate.value || !isTemplateSelectable(selectedTemplate.value)) @@ -935,6 +928,7 @@ async function handlePrimaryAction() { if (!validateName() || !validateRequiredFields(false)) return if (!(await runCheck(false))) return if (isRemoteBackend.value) { + invalidateCheck() wizardStep.value += 1 await loadTemplates(true) return @@ -944,6 +938,7 @@ async function handlePrimaryAction() { if (backend.value === 'docker') { void loadTemplates(true) } + invalidateCheck() wizardStep.value += 1 return } @@ -993,9 +988,7 @@ async function save() { const saved = res?.data if (saved) savedRecord.value = saved const skillsStep = wizardSteps.value.findIndex((step) => 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. + if (skillsStep >= 0 && savedRecord.value) { wizardStep.value = skillsStep return } @@ -1079,7 +1072,7 @@ onUnmounted(stopTemplatePolling) display: flex; align-items: center; gap: 8px; - margin: 0 0 18px; + margin: 0; } .sandbox-step { @@ -1614,55 +1607,39 @@ onUnmounted(stopTemplatePolling) } .check-result { - margin-top: 12px; + margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--td-component-stroke); display: flex; flex-direction: column; - gap: 10px; -} - -.check-result__summary { - display: flex; - align-items: flex-start; - gap: 10px; - padding: 10px 12px; - border: 1px solid var(--td-component-stroke); - border-radius: 8px; - background: var(--td-bg-color-secondarycontainer); - - &.is-success .check-result__summary-icon { - color: var(--td-brand-color); - } - - &.is-error .check-result__summary-icon { - color: var(--td-error-color); - } -} - -.check-result__summary-icon { - flex-shrink: 0; - padding-top: 1px; - font-size: 17px; -} - -.check-result__title, -.check-result__subtitle { - margin: 0; + gap: 8px; } .check-result__title { + display: flex; + align-items: center; + gap: 6px; + margin: 0; color: var(--td-text-color-primary); font-size: 13px; font-weight: 600; line-height: 1.45; + + &.is-success { + color: var(--td-success-color); + } + + &.is-error { + color: var(--td-error-color); + } } -.check-result__subtitle { - margin-top: 2px; +.check-result__subtitle, +.check-result__hint { + margin: 0; color: var(--td-text-color-secondary); font-size: 12px; - line-height: 1.5; + line-height: 1.55; } .check-list { @@ -1704,29 +1681,6 @@ onUnmounted(stopTemplatePolling) color: var(--td-text-color-secondary); } -.check-pending { - display: flex; - align-items: center; - justify-content: flex-end; - gap: 12px; - padding: 10px 12px; - border: 1px dashed var(--td-component-stroke); - border-radius: 8px; -} - -.check-pending--standalone { - margin-top: 16px; -} - -.check-pending__text { - flex: 1; - min-width: 0; - margin: 0; - color: var(--td-text-color-secondary); - font-size: 12px; - line-height: 1.55; -} - .footer-check-ok { color: var(--td-success-color); } diff --git a/frontend/src/components/SandboxSkillsPanel.vue b/frontend/src/components/SandboxSkillsPanel.vue index 2a798693..54f72f39 100644 --- a/frontend/src/components/SandboxSkillsPanel.vue +++ b/frontend/src/components/SandboxSkillsPanel.vue @@ -3,29 +3,38 @@

{{ $t('settings.sandbox.imageInfoTitle') }}

+

+ {{ $t('settings.sandbox.imageInfoUsingBase') }} +

    -
  • - {{ $t('settings.sandbox.imageInfoBaseTemplate') }} + +
  • + {{ $t('settings.sandbox.imageInfoRuntimeTemplate') }} - {{ skillImage?.base_template_id || $t('settings.sandbox.imageInfoEmpty') }} + {{ runtimeTemplateId || $t('settings.sandbox.imageInfoUnset') }}
  • -
  • - {{ $t('settings.sandbox.imageInfoSnapshot') }} - - {{ skillImage?.snapshot_id || $t('settings.sandbox.imageInfoEmpty') }} - -
  • -
  • - {{ $t('settings.sandbox.imageInfoGeneration') }} - - {{ skillImage?.generation ? String(skillImage.generation) : $t('settings.sandbox.imageInfoEmpty') }} - -
  • -
  • - {{ $t('settings.sandbox.imageInfoBuiltAt') }} - {{ formatBuiltAt(skillImage?.built_at) }} -
@@ -55,6 +64,7 @@
+

{{ $t('settings.sandbox.skillInstallGroup') }}

- +
{{ $t('settings.sandbox.skillUploading', { percent: uploadPercent }) }} @@ -86,7 +96,10 @@

{{ uploadHint }}

+
+
+

{{ $t('settings.sandbox.skillInstalledGroup') }}

{{ $t('settings.sandbox.skillEmpty') }}

@@ -98,134 +111,146 @@ v-if="isBusy(skill)" theme="circle" :percentage="progressOf(skill)" - :size="32" + :size="16" />
-
{{ skill.name || skill.id }}
-

{{ skill.description }}

-

- {{ statusLabel(skill) }} - · {{ progressOf(skill) }}% -

-

- {{ skill.error || progressLog(skill) }} -

-
-
- - - - - - - - - - - - - - - - +
+
{{ skill.name || skill.id }}
+

+ {{ skill.version }} · + {{ statusLabel(skill) }} + · {{ progressOf(skill) }}% +

+
+
+ + + + - - - - + + + + + + + + + + + + +
+
+

+ {{ skill.description }} +

+ +

{{ failedError(skill) }}

- -
- - -
    -
  • - {{ $t('settings.sandbox.skillVersion') }} - {{ viewing.version || $t('settings.sandbox.skillVersionEmpty') }} -
  • -
  • - {{ $t('settings.sandbox.skillStatusLabel') }} - {{ statusLabel(viewing) }} -
  • -
  • - {{ $t('settings.sandbox.configDescription') }} - {{ viewing.description }} -
  • -
  • - {{ $t('settings.sandbox.skillError') }} - {{ viewing.error }} -
  • -
-
@@ -277,11 +302,10 @@ const skills = ref([]) const skillImage = ref(null) const togglingId = ref('') const deletingId = ref('') -const showView = ref(false) -const viewing = ref(null) // Only one install timeline is open at a time: each one holds an SSE // connection, and two runs' worth of agent steps in a drawer is unreadable. const expandedSkillId = ref('') +const expandedCopyIds = ref>(new Set()) const transcriptEpoch = ref(0) const fileInputRef = ref(null) const progressById = ref>({}) @@ -312,6 +336,11 @@ const deleteHint = computed(() => ? t('settings.sandbox.skillDeleteHintNewSession') : t('settings.sandbox.skillDeleteHint'), ) +const runtimeTemplateId = computed(() => { + const cfg = props.record?.config + return cfg?.cube?.template_id?.trim() || cfg?.e2b?.template_id?.trim() || '' +}) +const hasSkillSnapshot = computed(() => Boolean(skillImage.value?.snapshot_id?.trim())) function readLastChatModelID(): string { try { @@ -322,10 +351,10 @@ function readLastChatModelID(): string { } function formatBuiltAt(value?: string): string { - if (!value) return t('settings.sandbox.imageInfoEmpty') + if (!value) return t('settings.sandbox.imageInfoUnset') const date = new Date(value) if (Number.isNaN(date.getTime()) || date.getFullYear() <= 1) { - return t('settings.sandbox.imageInfoEmpty') + return t('settings.sandbox.imageInfoUnset') } return date.toLocaleString(locale.value) } @@ -355,16 +384,19 @@ function hasTranscript(skill: ConfigSkill): boolean { return Boolean(skill.install_session_id && skill.install_message_id) } -function toggleTranscript(skill: ConfigSkill) { - if (expandedSkillId.value === skill.id) { - expandedSkillId.value = '' +function onTranscriptVisible(skill: ConfigSkill, visible: boolean) { + if (visible) { + if (expandedSkillId.value !== skill.id) { + expandedSkillId.value = skill.id + // A run that finished while the popup was closed was tailed from the + // event log; reopening it should read the run again from the top. + transcriptEpoch.value += 1 + } return } - expandedSkillId.value = skill.id - // A run that finished while the timeline was open was tailed from the event - // log; reopening it should read the run again from the top rather than show - // whatever the closed stream left behind. - transcriptEpoch.value += 1 + if (expandedSkillId.value === skill.id) { + expandedSkillId.value = '' + } } function progressOf(skill: ConfigSkill): number { @@ -379,6 +411,31 @@ function progressLog(skill: ConfigSkill): string { return progressById.value[skill.id]?.log || '' } +function failedError(skill: ConfigSkill): string { + if (skill.status !== 'failed') return '' + return skill.error || progressLog(skill) +} + +function isCopyExpanded(skillId: string): boolean { + return expandedCopyIds.value.has(skillId) +} + +function descriptionNeedsToggle(skill: ConfigSkill): boolean { + const desc = skill.description?.trim() || '' + return desc.length > 80 || desc.includes('\n') +} + +function canToggleCopy(skill: ConfigSkill): boolean { + return descriptionNeedsToggle(skill) || isCopyExpanded(skill.id) +} + +function toggleCopy(skillId: string) { + const next = new Set(expandedCopyIds.value) + if (next.has(skillId)) next.delete(skillId) + else next.add(skillId) + expandedCopyIds.value = next +} + function stopFollow(skillId: string) { const controller = abortBySkill.get(skillId) if (controller) { @@ -643,11 +700,6 @@ async function removeSkill(skill: ConfigSkill) { } } -function openView(skill: ConfigSkill) { - viewing.value = skill - showView.value = true -} - // The panel is mounted only while its wizard step is showing, so switching // steps tears the follows down and coming back re-reads the list. watch( @@ -661,8 +713,7 @@ watch( stopPoll() skills.value = [] progressById.value = {} - showView.value = false - viewing.value = null + expandedCopyIds.value = new Set() installerAgent.value = null installerModelId.value = '' }, @@ -676,6 +727,13 @@ onUnmounted(() => { + + diff --git a/frontend/src/components/SkillInstallTimeline.vue b/frontend/src/components/SkillInstallTimeline.vue index a662a185..e886881c 100644 --- a/frontend/src/components/SkillInstallTimeline.vue +++ b/frontend/src/components/SkillInstallTimeline.vue @@ -1,5 +1,5 @@ @@ -41,6 +42,7 @@ const props = defineProps<{ // after the installer sandbox is up, so a 404 here means "not yet" rather // than "gone" and the stream is retried. live?: boolean + compact?: boolean }>() const messages = reactive([]) @@ -51,6 +53,9 @@ const fullContent = ref('') let controller: AbortController | null = null let closed = false +// stop() / a newer open() bump this so an in-flight live loop cannot keep +// calling follow() after closed is reset — that would replay a finished run. +let openRun = 0 // The timeline grows inside the drawer's own scroll container, so following the // tail would mean scrolling the whole drawer under a reader who is inspecting @@ -76,16 +81,18 @@ function applyPrompt(content: string) { messages.unshift({ id: `${props.messageId}-prompt`, role: 'user', content }) } -async function loadPersisted() { +async function loadPersisted(run: number) { const res: any = await getMessageList({ session_id: props.sessionId, limit: 100, created_at: '', }) + if (run !== openRun) return handleMsgList(res?.data || []) } function stop() { + openRun += 1 closed = true if (controller) { controller.abort() @@ -96,11 +103,16 @@ function stop() { // follow tails the transcript endpoint. It resolves when the stream ends, and // reports whether it ever produced anything: a 404 means the event log has // expired and the durable history is the only remaining source. -async function follow(): Promise { +async function follow(run: number): Promise { const url = `${getApiBaseUrl()}${configSkillTranscriptUrl(props.configId, props.skillId)}` const token = localStorage.getItem('weknora_token') const tenantId = localStorage.getItem('weknora_selected_tenant_id') - controller = new AbortController() + const ac = new AbortController() + controller = ac + if (run !== openRun) { + ac.abort() + return false + } let served = false await fetchEventSource(url, { @@ -111,7 +123,7 @@ async function follow(): Promise { 'X-Request-ID': generateRandomString(12), ...(tenantId ? { 'X-Tenant-ID': tenantId } : {}), }, - signal: controller.signal, + signal: ac.signal, openWhenHidden: true, onopen: async (response) => { if (response.ok) { @@ -123,6 +135,7 @@ async function follow(): Promise { throw new Error(`transcript stream refused: ${response.status}`) }, onmessage(ev) { + if (run !== openRun || !props.live) return if (!ev.data) return let frame: any try { @@ -152,28 +165,41 @@ function wait(ms: number): Promise { } async function open() { + const run = ++openRun closed = false messages.splice(0, messages.length) loading.value = true + const stale = () => run !== openRun || closed try { - // Locators land after the installer sandbox is up. Keep asking until the - // stream answers or this run is no longer live; falling through to the - // empty state on the first 404 would flash "no record" during setup. - for (;;) { - const served = await follow().catch(() => false) - if (closed || served) return - if (props.sessionId && props.messageId) { - await loadPersisted() - if (messages.length > 0 || closed) return + // A finished install already has durable rows. Replaying the event log + // through processStreamChunk would animate every tool call again, which + // is what "view the run" must not do. + if (!props.live) { + if (props.sessionId) { + await loadPersisted(run) } - if (!props.live || closed) return + return + } + + // Locators land after the installer sandbox is up. Keep asking until the + // stream answers; falling through to the empty state on the first 404 + // would flash "no record" during setup. + for (;;) { + if (stale() || !props.live) return + const served = await follow(run).catch(() => false) + if (stale() || !props.live || served) return + if (props.sessionId && props.messageId) { + await loadPersisted(run) + if (stale() || messages.length > 0) return + } + if (stale() || !props.live) return await wait(1000) - if (!props.live || closed) return + if (stale() || !props.live) return } } catch { // Both sources are gone; the empty state says so. } finally { - loading.value = false + if (!stale()) loading.value = false } } @@ -220,4 +246,50 @@ onUnmounted(stop) color: var(--td-text-color-placeholder, #999); font-size: 13px; } + +.skill-timeline--compact { + padding: 10px 12px 12px; + background: transparent; + border: 0; + border-radius: 0; +} + +.skill-timeline--compact .skill-timeline__prompt { + max-height: 72px; + padding: 6px 8px; + font-size: 11px; + line-height: 1.5; +} + +.skill-timeline--compact .skill-timeline__empty { + margin: 4px 0; + font-size: 12px; +} + +.skill-timeline--compact :deep(.agent-stream-display.is-embedded) { + font-size: 12px; + --agent-step-text-size: 12px; + --agent-step-summary-size: 12px; +} + +.skill-timeline--compact :deep(.agent-stream-display.is-embedded .tree-root .action-name) { + font-size: 12px; +} + +// Chat answer Markdown is 16px. That is the right size in a conversation and +// too loud in this 420px popup, where the prompt and step summary are 11–13px. +.skill-timeline--compact :deep(.agent-stream-display .answer-content.markdown-content) { + font-size: 12px; + line-height: 1.55; +} + +.skill-timeline--compact :deep(.agent-stream-display .answer-content.markdown-content h1) { + font-size: 13px; + margin-bottom: 0.35em; +} + +.skill-timeline--compact :deep(.agent-stream-display .answer-content.markdown-content h2), +.skill-timeline--compact :deep(.agent-stream-display .answer-content.markdown-content h3) { + font-size: 12px; +} diff --git a/frontend/src/components/settings/SettingDrawer.vue b/frontend/src/components/settings/SettingDrawer.vue index b5a88b50..ccced816 100644 --- a/frontend/src/components/settings/SettingDrawer.vue +++ b/frontend/src/components/settings/SettingDrawer.vue @@ -18,17 +18,22 @@ so we don't need a redundant X button. --> @@ -258,6 +263,15 @@ const handleCancel = () => {