diff --git a/frontend/src/components/SandboxSkillsPanel.vue b/frontend/src/components/SandboxSkillsPanel.vue index 5ee4cf11..5c2b4a61 100644 --- a/frontend/src/components/SandboxSkillsPanel.vue +++ b/frontend/src/components/SandboxSkillsPanel.vue @@ -179,27 +179,134 @@ @change="(v: any) => toggleEnabled(skill, Boolean(v))" /> - onEnvVisible(skill, visible, context)" > - - - - + + + + + + + + + {{ skill.name || skill.id }} + + {{ $t('settings.sandbox.skillEnv.workspaceTitle') }} + + + + + + + + {{ $t('settings.sandbox.skillEnv.workspaceHint') }} + + + + {{ env.name }} + + {{ $t('settings.sandbox.skillEnv.required') }} + + + {{ + env.is_set + ? $t('settings.sandbox.skillEnv.isSet') + : $t('settings.sandbox.skillEnv.notSet') + }} + + {{ env.description }} + + + setEnvDraft(skill.id, env.name, v)" + /> + + + {{ $t('settings.sandbox.skillEnv.clear') }} + + + + + + + + + + - onTranscriptVisible(skill, visible)" > - onTranscriptVisible(skill, visible)" + v-bind="expandedSkillId === skill.id ? { visible: false } : {}" > - + + @@ -285,19 +394,23 @@ - - - - - {{ $t('settings.sandbox.skillTranscriptLive') }} - - - + + + + + {{ $t('settings.sandbox.skillTranscriptLive') }} + + + {{ line }} - - - - {{ $t('settings.sandbox.skillEnv.none') }} - - - {{ $t('settings.sandbox.skillEnv.workspaceTitle') }} - {{ $t('settings.sandbox.skillEnv.workspaceHint') }} - - - - {{ env.name }} - - {{ $t('settings.sandbox.skillEnv.required') }} - - - {{ - env.is_set - ? $t('settings.sandbox.skillEnv.isSet') - : $t('settings.sandbox.skillEnv.notSet') - }} - - {{ env.description }} - - - - - - {{ $t('settings.sandbox.skillEnv.clear') }} - - - - - - - - @@ -482,6 +522,7 @@ import { editedSkillEnvPayload, isSkillEnvSaveInFlight, isValidEnvValueLength, + skillHasDeclaredEnvs, type SkillEnvSavesInFlight, } from '@/views/settings/envVarState' @@ -520,14 +561,15 @@ const transcriptEpoch = ref(0) const focusedSkillId = ref('') const skillItemEls = new Map() let focusTimer: number | null = null -// Workspace-wide env values. Only one skill's editor is open at a time, for the -// same reason as the timeline: the row is already dense. +// Workspace-wide env values. Only one skill's editor popup is open at a time, +// same as the install timeline. const expandedEnvSkillId = ref('') // Drafts keyed by skill then variable name. An absent key means "the admin did // not touch this field", which is what keeps the PATCH partial: an empty string // clears the stored value server-side, so submitting every input would wipe // values nobody looked at. const envDrafts = reactive>>({}) +const envInputUnlocked = reactive>({}) const envSavesInFlight = ref({}) const fileInputRef = ref(null) const progressById = ref>({}) @@ -639,6 +681,7 @@ function revealSkill(skillId: string) { function onTranscriptVisible(skill: ConfigSkill, visible: boolean) { if (visible) { filesDrawerVisible.value = false + expandedEnvSkillId.value = '' if (expandedSkillId.value !== skill.id) { expandedSkillId.value = skill.id // A run that finished while the popup was closed was tailed from the @@ -654,6 +697,7 @@ function onTranscriptVisible(skill: ConfigSkill, visible: boolean) { function openSkillFiles(skill: ConfigSkill) { expandedSkillId.value = '' + expandedEnvSkillId.value = '' if (filesDrawerVisible.value && filesSkillId.value === skill.id) { filesDrawerVisible.value = false return @@ -663,15 +707,56 @@ function openSkillFiles(skill: ConfigSkill) { filesDrawerVisible.value = true } -function toggleEnvs(skill: ConfigSkill) { - if (expandedEnvSkillId.value === skill.id) { - expandedEnvSkillId.value = '' +function ensureEnvDrafts(skillId: string) { + if (!envDrafts[skillId]) envDrafts[skillId] = {} +} + +function setEnvDraft(skillId: string, name: string, value: string) { + ensureEnvDrafts(skillId) + envDrafts[skillId][name] = value ?? '' +} + +function envInputLockKey(skillId: string, name: string) { + return `${skillId}\n${name}` +} + +function isEnvInputUnlocked(skillId: string, name: string) { + return envInputUnlocked[envInputLockKey(skillId, name)] === true +} + +function unlockEnvInput(skillId: string, name: string) { + envInputUnlocked[envInputLockKey(skillId, name)] = true +} + +function resetEnvInputLocks() { + for (const key of Object.keys(envInputUnlocked)) delete envInputUnlocked[key] +} + +function onEnvVisible(skill: ConfigSkill, visible: boolean, context?: { e?: Event }) { + if (visible) { + if (!skillHasDeclaredEnvs(skill)) return + filesDrawerVisible.value = false + expandedSkillId.value = '' + if (expandedEnvSkillId.value !== skill.id) { + // Reopening starts from a clean slate rather than resurrecting a + // half-typed secret from the last time the editor was open. + envDrafts[skill.id] = {} + resetEnvInputLocks() + expandedEnvSkillId.value = skill.id + } else { + ensureEnvDrafts(skill.id) + } return } - // Reopening starts from a clean slate rather than resurrecting a half-typed - // secret from the last time the editor was open. - envDrafts[skill.id] = {} - expandedEnvSkillId.value = skill.id + // The clear confirm is another body-attached popup, so TDesign treats a + // click on it as an outside click on this editor. + const target = context?.e?.target + if (target instanceof Element && target.closest('.t-popconfirm')) { + return + } + if (expandedEnvSkillId.value === skill.id) { + expandedEnvSkillId.value = '' + } } function envPayload(skill: ConfigSkill): Record { @@ -1379,101 +1464,6 @@ onUnmounted(() => { box-shadow: 0 0 0 2px var(--td-brand-color-focus, rgba(0, 168, 112, 0.18)); } -.skill-item__envs { - grid-column: 1 / -1; - border-top: 1px solid var(--td-component-stroke); - padding-top: 10px; -} - -.skill-envs__none { - margin: 0; - font-size: 12px; - color: var(--td-text-color-placeholder); -} - -.skill-envs__title { - margin: 0; - font-size: 13px; - font-weight: 600; - color: var(--td-text-color-primary); -} - -.skill-envs__hint { - margin: 2px 0 0; - font-size: 12px; - line-height: 1.5; - color: var(--td-text-color-secondary); -} - -.skill-envs__rows { - margin-top: 10px; - display: flex; - flex-direction: column; - gap: 10px; -} - -.skill-envs__row { - display: flex; - flex-direction: column; - gap: 4px; -} - -.skill-envs__meta { - display: flex; - align-items: center; - flex-wrap: wrap; - gap: 6px; -} - -.skill-envs__name { - font-family: var(--td-font-family-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace); - font-size: 12px; - color: var(--td-text-color-primary); - overflow-wrap: anywhere; -} - -.skill-envs__tag { - font-size: 12px; - line-height: 18px; - padding: 0 8px; - border-radius: 10px; - background: var(--td-bg-color-secondarycontainer); - color: var(--td-text-color-secondary); -} - -.skill-envs__tag--required { - background: var(--td-warning-color-light); - color: var(--td-warning-color); -} - -.skill-envs__tag--set { - background: var(--td-success-color-light); - color: var(--td-success-color); -} - -.skill-envs__desc { - font-size: 12px; - line-height: 1.5; - color: var(--td-text-color-secondary); -} - -.skill-envs__editor { - display: flex; - align-items: center; - gap: 8px; -} - -.skill-envs__editor :deep(.t-input__wrap) { - flex: 1; - min-width: 0; -} - -.skill-envs__footer { - margin-top: 10px; - display: flex; - justify-content: flex-end; -} - .skill-status-ring { width: 16px; height: 16px; @@ -1610,6 +1600,11 @@ onUnmounted(() => { align-items: center; gap: 2px; flex-shrink: 0; + + :deep(.t-popup), + :deep(.t-popup__reference) { + display: inline-flex; + } } .skill-item__actions-divider { @@ -1631,8 +1626,13 @@ onUnmounted(() => { background: transparent; color: var(--td-text-color-placeholder); cursor: pointer; + line-height: 0; transition: background 0.15s ease, color 0.15s ease; + :deep(.t-icon) { + display: block; + } + &:hover:not(:disabled) { background: var(--td-bg-color-secondarycontainer); color: var(--td-text-color-primary); @@ -1664,6 +1664,13 @@ onUnmounted(() => { background: var(--td-error-color-1, var(--td-bg-color-secondarycontainer)); color: var(--td-error-color); } + + /* TDesign's key glyph sits in a smaller ink box than folder/refresh/delete. */ + &--key :deep(.t-icon) { + width: 18px; + height: 18px; + font-size: 18px; + } } .skill-item__live-dot { @@ -1694,7 +1701,8 @@ onUnmounted(() => { diff --git a/frontend/src/views/settings/envVarState.test.ts b/frontend/src/views/settings/envVarState.test.ts index fa2a73ad..d814fb81 100644 --- a/frontend/src/views/settings/envVarState.test.ts +++ b/frontend/src/views/settings/envVarState.test.ts @@ -17,6 +17,7 @@ import { isSkillEnvSaveInFlight, isValidEnvName, isValidEnvValueLength, + skillHasDeclaredEnvs, sortedConfigGroups, statusOf, } from './envVarState' @@ -174,6 +175,13 @@ test('canClearAdminSkillEnv is only true once a workspace value is stored', () = assert.equal(canClearAdminSkillEnv({}), false) }) +test('skillHasDeclaredEnvs is true only when the installer declared variables', () => { + assert.equal(skillHasDeclaredEnvs({}), false) + assert.equal(skillHasDeclaredEnvs({ envs: null }), false) + assert.equal(skillHasDeclaredEnvs({ envs: [] }), false) + assert.equal(skillHasDeclaredEnvs({ envs: [{ name: 'WEKNORA_API_KEY' }] }), true) +}) + test('editedSkillEnvPayload includes only drafted names declared by the skill', () => { assert.deepEqual( editedSkillEnvPayload(['TOKEN', 'EMPTY'], { diff --git a/frontend/src/views/settings/envVarState.ts b/frontend/src/views/settings/envVarState.ts index 7a0332d9..f1e517a6 100644 --- a/frontend/src/views/settings/envVarState.ts +++ b/frontend/src/views/settings/envVarState.ts @@ -54,6 +54,11 @@ export function canClearAdminSkillEnv(env: { is_set?: boolean }): boolean { return env.is_set === true } +/** The key control only belongs on a skill that declared at least one variable. */ +export function skillHasDeclaredEnvs(skill: { envs?: readonly unknown[] | null }): boolean { + return (skill.envs?.length ?? 0) > 0 +} + /** * Removes a submitted draft only if it still equals the sent value. New input * typed while the request was in flight always wins over response cleanup.
{{ $t('settings.sandbox.skillEnv.workspaceHint') }}
{{ env.name }}
- {{ $t('settings.sandbox.skillEnv.none') }} -