diff --git a/frontend/src/assets/img/toolbox-green.svg b/frontend/src/assets/img/toolbox-green.svg new file mode 100644 index 00000000..c6b850f6 --- /dev/null +++ b/frontend/src/assets/img/toolbox-green.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/frontend/src/assets/img/toolbox.svg b/frontend/src/assets/img/toolbox.svg new file mode 100644 index 00000000..1da182ea --- /dev/null +++ b/frontend/src/assets/img/toolbox.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/frontend/src/components/Input-field.browser.test.mjs b/frontend/src/components/Input-field.browser.test.mjs index b8b47dd0..dd9334a8 100644 --- a/frontend/src/components/Input-field.browser.test.mjs +++ b/frontend/src/components/Input-field.browser.test.mjs @@ -14,7 +14,7 @@ test('composer browser button is disabled and opens settings when the extension assert.match(button, /active: settingsStore\.isLocalBrowserEnabled && browserConnection\.online/) assert.match(button, /:aria-disabled="browserConnection\.knownOffline"/) assert.match(inputField, /if \(browserConnection\.knownOffline\) \{\s*openBrowserConnectionSettings\(\)/) - assert.match(inputField, /uiStore\.openSettings\('browserconnection'\)/) + assert.match(inputField, /router\.push\(toolboxLocation\('browserconnection'\)\)/) assert.match(inputField, /browserConnection\.watchStatus\(\)/) assert.match(inputField, /\$t\('localBrowser\.reconnectHint'\)|\$t\(browserSourceUnavailableHint\)/) }) diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue index 64f1e12e..a25b17de 100644 --- a/frontend/src/components/Input-field.vue +++ b/frontend/src/components/Input-field.vue @@ -52,6 +52,7 @@ import { } from '@/utils/agent-readiness'; import { formatLocalizedList } from '@/utils/format-list'; import { SKILL_ICON, type MentionItem, type MentionItemType, type MentionRequestItem } from '@/types/mention'; +import { toolboxLocation } from '@/config/toolbox'; import { supportedLevels, levelLabelKey, levelFromLegacy, clampLevel, type ReasoningLevel } from '@/utils/reasoningEffort'; const route = useRoute(); @@ -870,7 +871,7 @@ const browserSourceUnavailableHint = computed(() => { }); const openBrowserConnectionSettings = () => { - uiStore.openSettings('browserconnection'); + void router.push(toolboxLocation('browserconnection')); }; const toggleBrowserSource = () => { diff --git a/frontend/src/components/UserMenu.vue b/frontend/src/components/UserMenu.vue index 1d45617d..43c0d905 100644 --- a/frontend/src/components/UserMenu.vue +++ b/frontend/src/components/UserMenu.vue @@ -92,10 +92,6 @@ {{ $t('settings.modelManagement') }} - @@ -255,6 +262,8 @@ import { useMenuStore } from '@/stores/menu'; import { useSessionActivityStore } from '@/stores/sessionActivity'; import { useAuthStore } from '@/stores/auth'; import { useDeploymentCapabilitiesStore } from '@/stores/deploymentCapabilities'; +import { TOOLBOX_ITEMS, canAccessToolboxSection } from '@/config/toolbox'; +import BrowserIcon from '@/components/icons/BrowserIcon.vue'; import { useOrganizationStore } from '@/stores/organization'; import { useUIStore } from '@/stores/ui'; import { useCommandPaletteStore } from '@/stores/commandPalette'; @@ -298,6 +307,12 @@ const { entries: sessionActivityEntries } = storeToRefs(sessionActivity); let sessionActivityTimer: ReturnType | undefined; const authStore = useAuthStore(); const deploymentCapabilities = useDeploymentCapabilitiesStore(); +const toolboxPreview = computed(() => TOOLBOX_ITEMS.filter((item) => canAccessToolboxSection(item.key, { + currentTenantRole: authStore.currentTenantRole, + canAccessAllTenants: authStore.canAccessAllTenants, + hasRole: (role) => authStore.hasRole(role), + isSupported: (capability) => deploymentCapabilities.isSupported(capability), +}))); const orgStore = useOrganizationStore(); const uiStore = useUIStore(); const commandPaletteStore = useCommandPaletteStore(); @@ -415,6 +430,8 @@ const isMenuItemActive = (itemPath: string): boolean => { currentRoute === 'knowledgeBaseSettings'; case 'agents': return currentRoute === 'agentList'; + case 'toolbox': + return currentRoute === 'toolbox'; case 'artifacts': return currentRoute === 'artifactLibrary'; case 'organizations': @@ -445,7 +462,7 @@ const getIconActiveState = (itemPath: string) => { }; // 分离上下两部分菜单(使用 visibleMenuArr 以便 lite 模式过滤 logout) -const TOP_MENU_PATHS = new Set(['creatChat', 'knowledge-bases', 'artifacts', 'agents', 'organizations']); +const TOP_MENU_PATHS = new Set(['creatChat', 'knowledge-bases', 'artifacts', 'agents', 'toolbox', 'organizations']); const topMenuItems = computed(() => { return (visibleMenuArr.value as unknown as MenuItem[]).filter((item: MenuItem) => TOP_MENU_PATHS.has(item.path)); @@ -1087,6 +1104,7 @@ let logoutIcon = ref('logout.svg'); let settingIcon = ref('setting.svg'); let agentIcon = ref('agent.svg'); let artifactIcon = ref('artifact.svg'); +let toolboxIcon = ref('toolbox.svg'); let organizationIcon = ref('organization.svg'); let pathPrefix = ref(route.name) const getIcon = (path: string) => { @@ -1107,6 +1125,8 @@ const getIcon = (path: string) => { // 产物图标:只在产物页面显示绿色 artifactIcon.value = artifactsActiveState ? 'artifact-green.svg' : 'artifact.svg'; + toolboxIcon.value = route.name === 'toolbox' ? 'toolbox-green.svg' : 'toolbox.svg'; + // 组织图标:只在组织页面显示绿色 organizationIcon.value = organizationsActiveState ? 'organization-green.svg' : 'organization.svg'; @@ -1259,7 +1279,7 @@ const resizeSidebar = (delta: number, keyboard: boolean) => { .menu_item { justify-content: center; - padding: 9px 0; + padding: 7px 0; .menu_item-box { justify-content: center; @@ -1425,10 +1445,10 @@ const resizeSidebar = (delta: number, keyboard: boolean) => { display: flex; align-items: center; justify-content: space-between; - height: 38px; - padding: 8px 10px 8px var(--sidebar-inset-x); + height: 34px; + padding: 6px 10px 6px var(--sidebar-inset-x); box-sizing: border-box; - margin-bottom: 2px; + margin-bottom: 1px; border-radius: var(--app-radius-xs); transition: background-color var(--app-motion-base) ease; @@ -1797,6 +1817,68 @@ const resizeSidebar = (delta: number, keyboard: boolean) => { } } +.menu-toolbox-stack { + display: inline-flex; + align-items: center; + flex-shrink: 0; + margin-left: auto; +} + +.menu-toolbox-stack__item { + position: relative; + display: inline-flex; + align-items: center; + justify-content: center; + width: 20px; + height: 20px; + box-sizing: border-box; + border: 1px solid var(--td-component-stroke); + border-radius: 50%; + background: var(--td-bg-color-container); + color: var(--td-text-color-secondary); + rotate: var(--stack-rotate, 0deg); + animation: menu-toolbox-stack-in 420ms cubic-bezier(0.34, 1.56, 0.64, 1) both; + transition: + margin 320ms cubic-bezier(0.34, 1.56, 0.64, 1), + rotate 320ms cubic-bezier(0.34, 1.56, 0.64, 1), + translate 320ms cubic-bezier(0.34, 1.56, 0.64, 1), + color 200ms ease, + box-shadow 200ms ease; + + & + & { + margin-left: -6px; + } + + &:nth-child(1) { z-index: 3; --stack-rotate: -10deg; } + &:nth-child(2) { z-index: 2; animation-delay: 60ms; transition-delay: 40ms; } + &:nth-child(3) { z-index: 1; --stack-rotate: 10deg; animation-delay: 120ms; transition-delay: 80ms; } +} + +@keyframes menu-toolbox-stack-in { + from { + opacity: 0; + scale: 0.4; + } +} + +.menu_item:hover .menu-toolbox-stack__item { + color: var(--td-text-color-primary); + rotate: 0deg; + translate: 0 -1px; + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08); +} + +.menu_item:hover .menu-toolbox-stack__item + .menu-toolbox-stack__item { + margin-left: 3px; +} + +@media (prefers-reduced-motion: reduce) { + .menu-toolbox-stack__item { + animation: none; + transition: color 200ms ease; + } +} + .menu-pending-badge { min-width: 18px; height: 18px; diff --git a/frontend/src/composables/useModalShell.ts b/frontend/src/composables/useModalShell.ts index fca97076..5cb86970 100644 --- a/frontend/src/composables/useModalShell.ts +++ b/frontend/src/composables/useModalShell.ts @@ -62,10 +62,16 @@ export function useModalShell(options: ModalShellOptions) { return serialize(options.snapshot()) !== cleanSnapshot } - const requestClose = () => { + // Template handlers pass the DOM event as the first argument, so only call + // afterClose when it really is a callback. + const requestClose = (afterClose?: unknown) => { if (!options.visible() || confirming) return - if (!isDirty()) { + const close = () => { options.close() + if (typeof afterClose === 'function') afterClose() + } + if (!isDirty()) { + close() return } confirming = true @@ -78,7 +84,7 @@ export function useModalShell(options: ModalShellOptions) { onConfirm: () => { confirming = false dialog.destroy() - options.close() + close() }, onClose: () => { confirming = false diff --git a/frontend/src/config/settingsAccess.test.ts b/frontend/src/config/settingsAccess.test.ts index 6df8293d..b2da7ac7 100644 --- a/frontend/src/config/settingsAccess.test.ts +++ b/frontend/src/config/settingsAccess.test.ts @@ -17,7 +17,8 @@ test('management shortcuts are stricter than read-only settings pages', () => { test('the skill catalog is admin-only like the sandbox it installs into', () => { assert.equal(SETTINGS_SECTION_MIN_ROLE.skills, 'admin') assert.equal(SETTINGS_SECTION_MIN_ROLE.skills, SETTINGS_SECTION_MIN_ROLE.sandbox) - assert.equal(SETTINGS_MANAGEMENT_SHORTCUT_MIN_ROLE.skills, 'admin') + // Skills live in the sidebar toolbox, so the avatar menu has no shortcut. + assert.equal(Object.prototype.hasOwnProperty.call(SETTINGS_MANAGEMENT_SHORTCUT_MIN_ROLE, 'skills'), false) }) test('personal skill environment variables are visible to every member', () => { diff --git a/frontend/src/config/settingsAccess.ts b/frontend/src/config/settingsAccess.ts index 02811cc4..cdc6dad5 100644 --- a/frontend/src/config/settingsAccess.ts +++ b/frontend/src/config/settingsAccess.ts @@ -41,7 +41,6 @@ export const SETTINGS_SECTION_MIN_ROLE: Record = { export const SETTINGS_MANAGEMENT_SHORTCUT_MIN_ROLE = { members: 'owner', models: 'admin', - skills: 'admin', } as const satisfies Record export const SYSTEM_ADMIN_SETTINGS_SECTIONS = new Set([ diff --git a/frontend/src/config/toolbox.test.ts b/frontend/src/config/toolbox.test.ts new file mode 100644 index 00000000..3059169f --- /dev/null +++ b/frontend/src/config/toolbox.test.ts @@ -0,0 +1,100 @@ +import assert from 'node:assert/strict' +import test from 'node:test' +import { readFileSync } from 'node:fs' +import { computed, ref } from 'vue' +import { runInNewContext } from 'node:vm' +import ts from 'typescript' +import { TOOLBOX_ITEMS, canAccessToolboxSection, isToolboxSection, toolboxLocation } from './toolbox' +import zhCN from '../i18n/locales/zh-CN' + +const roles = ['viewer', 'contributor', 'admin', 'owner'] +const access = (role: string | null, unsupported: string[] = [], superuser = false) => ({ + currentTenantRole: role, + canAccessAllTenants: superuser, + hasRole: (min: string) => roles.indexOf(role || '') >= roles.indexOf(min), + isSupported: (capability?: string) => !capability || !unsupported.includes(capability), +}) + +test('toolbox contains only the agreed tools; infrastructure and secrets stay in settings', () => { + assert.deepEqual(TOOLBOX_ITEMS.map((item) => item.key), ['skills', 'mcp', 'browserconnection']) + const lookup = (key: string) => key.split('.').reduce((node, part) => node?.[part], zhCN) + for (const item of TOOLBOX_ITEMS) { + for (const key of [item.title, item.description, 'help' in item ? item.help : undefined, + 'action' in item ? item.action : undefined]) { + if (key) assert.equal(typeof lookup(key), 'string', key) + } + } + for (const key of ['sandbox', 'websearch', 'envvars', 'integration-api', undefined, 'unknown']) { + assert.equal(isToolboxSection(key), false) + } +}) + +test('toolbox preserves role and deployment gates, including workspace switches', () => { + for (const role of ['viewer', 'contributor']) { + assert.equal(canAccessToolboxSection('skills', access(role)), false) + assert.equal(canAccessToolboxSection('mcp', access(role)), false) + assert.equal(canAccessToolboxSection('browserconnection', access(role)), true) + } + assert.equal(canAccessToolboxSection('skills', access('admin')), true) + assert.equal(canAccessToolboxSection('skills', access('owner', ['settings.sandbox'])), false) + assert.equal(canAccessToolboxSection('mcp', access('owner', ['settings.mcp'])), false) + assert.equal(canAccessToolboxSection('mcp', access(null)), false) + assert.equal(canAccessToolboxSection('mcp', access(null, [], true)), true) + assert.equal(canAccessToolboxSection('mcp', access(null, ['settings.mcp'], true)), false) + const role = ref('admin') + const allowed = computed(() => canAccessToolboxSection('skills', access(role.value))) + assert.equal(allowed.value, true) + role.value = 'viewer' + assert.equal(allowed.value, false) +}) + +test('skill shortcut retains its target sandbox without leaking it to other tools', () => { + assert.deepEqual(toolboxLocation('skills', 'sandbox-123'), { + path: '/platform/toolbox/skills', query: { sandboxId: 'sandbox-123' }, + }) + assert.deepEqual(toolboxLocation('browserconnection', 'sandbox-123'), { + path: '/platform/toolbox/browserconnection', query: {}, + }) + assert.deepEqual(toolboxLocation(), { path: '/platform/toolbox', query: {} }) +}) + +const settings = readFileSync(new URL('../views/settings/Settings.vue', import.meta.url), 'utf8') +const script = settings.match(/ diff --git a/frontend/src/views/toolbox/Toolbox.vue b/frontend/src/views/toolbox/Toolbox.vue new file mode 100644 index 00000000..6717ae4f --- /dev/null +++ b/frontend/src/views/toolbox/Toolbox.vue @@ -0,0 +1,342 @@ + + + + +