refactor(GlobalCommandPalette): streamline template structure for improved readability
Consolidated the template structure in GlobalCommandPalette.vue to enhance code clarity and maintainability. Adjusted the layout of various elements for better alignment without altering existing functionality. This refactor aims to improve the overall readability of the component for future development. Refs: #1303
This commit is contained in:
@@ -1,16 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<t-dialog
|
<t-dialog v-model:visible="dialogVisible" :footer="false" :header="false" :close-btn="false" width="640px" top="10vh"
|
||||||
v-model:visible="dialogVisible"
|
destroy-on-close class="cmdk-dialog" @close="handleClose" @opened="onDialogOpened">
|
||||||
:footer="false"
|
|
||||||
:header="false"
|
|
||||||
:close-btn="false"
|
|
||||||
width="640px"
|
|
||||||
top="10vh"
|
|
||||||
destroy-on-close
|
|
||||||
class="cmdk-dialog"
|
|
||||||
@close="handleClose"
|
|
||||||
@opened="onDialogOpened"
|
|
||||||
>
|
|
||||||
<div class="cmdk" @keydown="onKeyDown">
|
<div class="cmdk" @keydown="onKeyDown">
|
||||||
<!-- Input row -->
|
<!-- Input row -->
|
||||||
<div class="cmdk__input-row">
|
<div class="cmdk__input-row">
|
||||||
@@ -18,45 +8,23 @@
|
|||||||
<span v-if="activeKbScope" class="cmdk__scope-chip" :title="activeKbScope.name">
|
<span v-if="activeKbScope" class="cmdk__scope-chip" :title="activeKbScope.name">
|
||||||
<t-icon name="folder" size="12px" />
|
<t-icon name="folder" size="12px" />
|
||||||
<span class="cmdk__scope-chip-name">{{ activeKbScope.name }}</span>
|
<span class="cmdk__scope-chip-name">{{ activeKbScope.name }}</span>
|
||||||
<button
|
<button type="button" class="cmdk__scope-chip-x" :title="t('commandPalette.scope.remove')"
|
||||||
type="button"
|
:aria-label="t('commandPalette.scope.remove')" @click="clearKbScope">
|
||||||
class="cmdk__scope-chip-x"
|
|
||||||
:title="t('commandPalette.scope.remove')"
|
|
||||||
:aria-label="t('commandPalette.scope.remove')"
|
|
||||||
@click="clearKbScope"
|
|
||||||
>
|
|
||||||
<t-icon name="close" size="12px" />
|
<t-icon name="close" size="12px" />
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
<input
|
<input ref="inputRef" v-model="query" type="text" class="cmdk__input"
|
||||||
ref="inputRef"
|
|
||||||
v-model="query"
|
|
||||||
type="text"
|
|
||||||
class="cmdk__input"
|
|
||||||
:placeholder="activeKbScope ? t('commandPalette.scope.placeholder') : t('commandPalette.placeholder')"
|
:placeholder="activeKbScope ? t('commandPalette.scope.placeholder') : t('commandPalette.placeholder')"
|
||||||
autofocus
|
autofocus spellcheck="false" @keydown="onInputKeyDown" />
|
||||||
spellcheck="false"
|
|
||||||
@keydown="onInputKeyDown"
|
|
||||||
/>
|
|
||||||
<span v-if="loading" class="cmdk__input-spinner">
|
<span v-if="loading" class="cmdk__input-spinner">
|
||||||
<t-loading size="small" />
|
<t-loading size="small" />
|
||||||
</span>
|
</span>
|
||||||
<t-tooltip :content="t('commandPalette.retrieval')" placement="bottom">
|
<t-tooltip :content="t('commandPalette.retrieval')" placement="bottom">
|
||||||
<button
|
<button type="button" class="cmdk__icon-btn" :class="{ active: drawerVisible }" @click="drawerVisible = true">
|
||||||
type="button"
|
|
||||||
class="cmdk__icon-btn"
|
|
||||||
:class="{ active: drawerVisible }"
|
|
||||||
@click="drawerVisible = true"
|
|
||||||
>
|
|
||||||
<t-icon name="setting" size="16px" />
|
<t-icon name="setting" size="16px" />
|
||||||
</button>
|
</button>
|
||||||
</t-tooltip>
|
</t-tooltip>
|
||||||
<button
|
<button type="button" class="cmdk__icon-btn" :aria-label="t('commandPalette.hotkey.esc')" @click="handleClose">
|
||||||
type="button"
|
|
||||||
class="cmdk__icon-btn"
|
|
||||||
:aria-label="t('commandPalette.hotkey.esc')"
|
|
||||||
@click="handleClose"
|
|
||||||
>
|
|
||||||
<t-icon name="close" size="16px" />
|
<t-icon name="close" size="16px" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -65,60 +33,33 @@
|
|||||||
<div ref="scrollRef" class="cmdk__results">
|
<div ref="scrollRef" class="cmdk__results">
|
||||||
<!-- Empty idle state: recent + quick actions -->
|
<!-- Empty idle state: recent + quick actions -->
|
||||||
<template v-if="!query.trim()">
|
<template v-if="!query.trim()">
|
||||||
<ResultGroup
|
<ResultGroup v-if="recentQueries.length" :label="t('commandPalette.group.recent')"
|
||||||
v-if="recentQueries.length"
|
:action="t('commandPalette.clearRecent')" @action="commandPaletteStore.clearRecent()">
|
||||||
:label="t('commandPalette.group.recent')"
|
<ResultItem v-for="(q, i) in recentQueries" :key="'r-' + q" icon-name="history"
|
||||||
:action="t('commandPalette.clearRecent')"
|
:index="flatIndexFor('recent', i)" :selected="selectedIndex === flatIndexFor('recent', i)"
|
||||||
@action="commandPaletteStore.clearRecent()"
|
:shortcut="shortcutFor(flatIndexFor('recent', i))" :title="q" @primary="query = q"
|
||||||
>
|
@hover="selectItemAt($event)" />
|
||||||
<ResultItem
|
|
||||||
v-for="(q, i) in recentQueries"
|
|
||||||
:key="'r-' + q"
|
|
||||||
icon-name="history"
|
|
||||||
:index="flatIndexFor('recent', i)"
|
|
||||||
:selected="selectedIndex === flatIndexFor('recent', i)"
|
|
||||||
:shortcut="shortcutFor(flatIndexFor('recent', i))"
|
|
||||||
:title="q"
|
|
||||||
@primary="query = q"
|
|
||||||
@hover="selectItemAt($event)"
|
|
||||||
/>
|
|
||||||
</ResultGroup>
|
</ResultGroup>
|
||||||
|
|
||||||
<ResultGroup :label="t('commandPalette.group.quickActions')">
|
<ResultGroup :label="t('commandPalette.group.quickActions')">
|
||||||
<ResultItem
|
<ResultItem v-for="(c, i) in allCommands" :key="'cmd-' + c.id" :index="flatIndexFor('commands', i)"
|
||||||
v-for="(c, i) in allCommands"
|
|
||||||
:key="'cmd-' + c.id"
|
|
||||||
:index="flatIndexFor('commands', i)"
|
|
||||||
:selected="selectedIndex === flatIndexFor('commands', i)"
|
:selected="selectedIndex === flatIndexFor('commands', i)"
|
||||||
:shortcut="shortcutFor(flatIndexFor('commands', i))"
|
:shortcut="shortcutFor(flatIndexFor('commands', i))" :icon-name="c.icon" :title="c.label" @primary="c.run"
|
||||||
:icon-name="c.icon"
|
@hover="selectItemAt($event)" />
|
||||||
:title="c.label"
|
|
||||||
@primary="c.run"
|
|
||||||
@hover="selectItemAt($event)"
|
|
||||||
/>
|
|
||||||
</ResultGroup>
|
</ResultGroup>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Active search results -->
|
<!-- Active search results -->
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<!-- Chunks (per file) -->
|
<!-- Chunks (per file) -->
|
||||||
<ResultGroup
|
<ResultGroup v-if="isGroupVisible('chunks') && fileGroups.length" :label="t('commandPalette.group.chunks')"
|
||||||
v-if="isGroupVisible('chunks') && fileGroups.length"
|
:count="totalChunks">
|
||||||
:label="t('commandPalette.group.chunks')"
|
|
||||||
:count="totalChunks"
|
|
||||||
>
|
|
||||||
<template v-for="(item, i) in flatChunkItems" :key="'c-' + item.file.knowledgeId + '-' + item.chunk.id">
|
<template v-for="(item, i) in flatChunkItems" :key="'c-' + item.file.knowledgeId + '-' + item.chunk.id">
|
||||||
<ResultItem
|
<ResultItem :index="flatIndexFor('chunks', i)" :selected="selectedIndex === flatIndexFor('chunks', i)"
|
||||||
:index="flatIndexFor('chunks', i)"
|
:shortcut="shortcutFor(flatIndexFor('chunks', i))" icon-name="file"
|
||||||
:selected="selectedIndex === flatIndexFor('chunks', i)"
|
|
||||||
:shortcut="shortcutFor(flatIndexFor('chunks', i))"
|
|
||||||
icon-name="file"
|
|
||||||
:badge="item.chunk.match_type === 'vector' ? t('commandPalette.match.vector') : t('commandPalette.match.keyword')"
|
:badge="item.chunk.match_type === 'vector' ? t('commandPalette.match.vector') : t('commandPalette.match.keyword')"
|
||||||
:badge-variant="item.chunk.match_type === 'vector' ? 'vector' : 'keyword'"
|
:badge-variant="item.chunk.match_type === 'vector' ? 'vector' : 'keyword'" :score="item.chunk.score"
|
||||||
:score="item.chunk.score"
|
@primary="openChunk(item)" @hover="selectItemAt($event)">
|
||||||
@primary="openChunk(item)"
|
|
||||||
@hover="selectItemAt($event)"
|
|
||||||
>
|
|
||||||
<template #title>
|
<template #title>
|
||||||
<span class="cmdk-chunk-title">{{ item.file.title }}</span>
|
<span class="cmdk-chunk-title">{{ item.file.title }}</span>
|
||||||
<span v-if="item.file.kbName" class="cmdk-chunk-kb">{{ item.file.kbName }}</span>
|
<span v-if="item.file.kbName" class="cmdk-chunk-kb">{{ item.file.kbName }}</span>
|
||||||
@@ -131,21 +72,12 @@
|
|||||||
</ResultGroup>
|
</ResultGroup>
|
||||||
|
|
||||||
<!-- Messages -->
|
<!-- Messages -->
|
||||||
<ResultGroup
|
<ResultGroup v-if="isGroupVisible('messages') && messageGroups.length"
|
||||||
v-if="isGroupVisible('messages') && messageGroups.length"
|
:label="t('commandPalette.group.messages')" :count="totalMessages">
|
||||||
:label="t('commandPalette.group.messages')"
|
|
||||||
:count="totalMessages"
|
|
||||||
>
|
|
||||||
<template v-for="(item, i) in flatMessageItems" :key="'m-' + item.msg.request_id">
|
<template v-for="(item, i) in flatMessageItems" :key="'m-' + item.msg.request_id">
|
||||||
<ResultItem
|
<ResultItem :index="flatIndexFor('messages', i)" :selected="selectedIndex === flatIndexFor('messages', i)"
|
||||||
:index="flatIndexFor('messages', i)"
|
:shortcut="shortcutFor(flatIndexFor('messages', i))" icon-name="chat" :score="item.msg.score"
|
||||||
:selected="selectedIndex === flatIndexFor('messages', i)"
|
@primary="openMessage(item)" @hover="selectItemAt($event)">
|
||||||
:shortcut="shortcutFor(flatIndexFor('messages', i))"
|
|
||||||
icon-name="chat"
|
|
||||||
:score="item.msg.score"
|
|
||||||
@primary="openMessage(item)"
|
|
||||||
@hover="selectItemAt($event)"
|
|
||||||
>
|
|
||||||
<template #title>
|
<template #title>
|
||||||
<span>{{ item.group.sessionTitle || t('commandPalette.untitledSession') }}</span>
|
<span>{{ item.group.sessionTitle || t('commandPalette.untitledSession') }}</span>
|
||||||
</template>
|
</template>
|
||||||
@@ -158,83 +90,40 @@
|
|||||||
</ResultGroup>
|
</ResultGroup>
|
||||||
|
|
||||||
<!-- KB name matches -->
|
<!-- KB name matches -->
|
||||||
<ResultGroup
|
<ResultGroup v-if="isGroupVisible('kbs') && kbMatches.length" :label="t('commandPalette.group.kbs')">
|
||||||
v-if="isGroupVisible('kbs') && kbMatches.length"
|
<ResultItem v-for="(kb, i) in kbMatches" :key="'k-' + kb.id" :index="flatIndexFor('kbs', i)"
|
||||||
:label="t('commandPalette.group.kbs')"
|
:selected="selectedIndex === flatIndexFor('kbs', i)" :shortcut="shortcutFor(flatIndexFor('kbs', i))"
|
||||||
>
|
icon-name="folder" :title="kb.name" @primary="openKb(kb.id)" @hover="selectItemAt($event)" />
|
||||||
<ResultItem
|
|
||||||
v-for="(kb, i) in kbMatches"
|
|
||||||
:key="'k-' + kb.id"
|
|
||||||
:index="flatIndexFor('kbs', i)"
|
|
||||||
:selected="selectedIndex === flatIndexFor('kbs', i)"
|
|
||||||
:shortcut="shortcutFor(flatIndexFor('kbs', i))"
|
|
||||||
icon-name="folder"
|
|
||||||
:title="kb.name"
|
|
||||||
@primary="openKb(kb.id)"
|
|
||||||
@hover="selectItemAt($event)"
|
|
||||||
/>
|
|
||||||
</ResultGroup>
|
</ResultGroup>
|
||||||
|
|
||||||
<!-- Agent matches -->
|
<!-- Agent matches -->
|
||||||
<ResultGroup
|
<ResultGroup v-if="isGroupVisible('agents') && agentMatches.length" :label="t('commandPalette.group.agents')">
|
||||||
v-if="isGroupVisible('agents') && agentMatches.length"
|
<ResultItem v-for="(a, i) in agentMatches" :key="'a-' + a.id" :index="flatIndexFor('agents', i)"
|
||||||
:label="t('commandPalette.group.agents')"
|
:selected="selectedIndex === flatIndexFor('agents', i)" :shortcut="shortcutFor(flatIndexFor('agents', i))"
|
||||||
>
|
icon-name="user-circle" :title="a.name" :subtitle="a.description" @primary="openAgent(a.id)"
|
||||||
<ResultItem
|
@hover="selectItemAt($event)" />
|
||||||
v-for="(a, i) in agentMatches"
|
|
||||||
:key="'a-' + a.id"
|
|
||||||
:index="flatIndexFor('agents', i)"
|
|
||||||
:selected="selectedIndex === flatIndexFor('agents', i)"
|
|
||||||
:shortcut="shortcutFor(flatIndexFor('agents', i))"
|
|
||||||
icon-name="user-circle"
|
|
||||||
:title="a.name"
|
|
||||||
:subtitle="a.description"
|
|
||||||
@primary="openAgent(a.id)"
|
|
||||||
@hover="selectItemAt($event)"
|
|
||||||
/>
|
|
||||||
</ResultGroup>
|
</ResultGroup>
|
||||||
|
|
||||||
<!-- Session (chat) title matches -->
|
<!-- Session (chat) title matches -->
|
||||||
<ResultGroup
|
<ResultGroup v-if="isGroupVisible('sessions') && sessionMatches.length"
|
||||||
v-if="isGroupVisible('sessions') && sessionMatches.length"
|
:label="t('commandPalette.group.sessionsByTitle')">
|
||||||
:label="t('commandPalette.group.sessionsByTitle')"
|
<ResultItem v-for="(s, i) in sessionMatches" :key="'s-' + s.id" :index="flatIndexFor('sessions', i)"
|
||||||
>
|
|
||||||
<ResultItem
|
|
||||||
v-for="(s, i) in sessionMatches"
|
|
||||||
:key="'s-' + s.id"
|
|
||||||
:index="flatIndexFor('sessions', i)"
|
|
||||||
:selected="selectedIndex === flatIndexFor('sessions', i)"
|
:selected="selectedIndex === flatIndexFor('sessions', i)"
|
||||||
:shortcut="shortcutFor(flatIndexFor('sessions', i))"
|
:shortcut="shortcutFor(flatIndexFor('sessions', i))" icon-name="chat" :title="s.title"
|
||||||
icon-name="chat"
|
@primary="openSession(s.id)" @hover="selectItemAt($event)" />
|
||||||
:title="s.title"
|
|
||||||
@primary="openSession(s.id)"
|
|
||||||
@hover="selectItemAt($event)"
|
|
||||||
/>
|
|
||||||
</ResultGroup>
|
</ResultGroup>
|
||||||
|
|
||||||
<!-- Commands matching the query -->
|
<!-- Commands matching the query -->
|
||||||
<ResultGroup
|
<ResultGroup v-if="isGroupVisible('commands') && filteredCommands.length"
|
||||||
v-if="isGroupVisible('commands') && filteredCommands.length"
|
:label="t('commandPalette.group.commands')">
|
||||||
:label="t('commandPalette.group.commands')"
|
<ResultItem v-for="(c, i) in filteredCommands" :key="'fcmd-' + c.id" :index="flatIndexFor('commands', i)"
|
||||||
>
|
|
||||||
<ResultItem
|
|
||||||
v-for="(c, i) in filteredCommands"
|
|
||||||
:key="'fcmd-' + c.id"
|
|
||||||
:index="flatIndexFor('commands', i)"
|
|
||||||
:selected="selectedIndex === flatIndexFor('commands', i)"
|
:selected="selectedIndex === flatIndexFor('commands', i)"
|
||||||
:shortcut="shortcutFor(flatIndexFor('commands', i))"
|
:shortcut="shortcutFor(flatIndexFor('commands', i))" :icon-name="c.icon" :title="c.label" @primary="c.run"
|
||||||
:icon-name="c.icon"
|
@hover="selectItemAt($event)" />
|
||||||
:title="c.label"
|
|
||||||
@primary="c.run"
|
|
||||||
@hover="selectItemAt($event)"
|
|
||||||
/>
|
|
||||||
</ResultGroup>
|
</ResultGroup>
|
||||||
|
|
||||||
<!-- No results -->
|
<!-- No results -->
|
||||||
<div
|
<div v-if="!loading && !hasAnyResults && hasSearched" class="cmdk__empty">
|
||||||
v-if="!loading && !hasAnyResults && hasSearched"
|
|
||||||
class="cmdk__empty"
|
|
||||||
>
|
|
||||||
<p>{{ t('commandPalette.empty.noResults') }}</p>
|
<p>{{ t('commandPalette.empty.noResults') }}</p>
|
||||||
<div class="cmdk__empty-actions">
|
<div class="cmdk__empty-actions">
|
||||||
<t-button theme="primary" variant="outline" size="small" @click="askAi">
|
<t-button theme="primary" variant="outline" size="small" @click="askAi">
|
||||||
@@ -254,21 +143,16 @@
|
|||||||
<div class="cmdk__footer">
|
<div class="cmdk__footer">
|
||||||
<span class="cmdk__hotkey"><kbd>↑</kbd><kbd>↓</kbd> {{ t('commandPalette.hotkey.select') }}</span>
|
<span class="cmdk__hotkey"><kbd>↑</kbd><kbd>↓</kbd> {{ t('commandPalette.hotkey.select') }}</span>
|
||||||
<span class="cmdk__hotkey"><kbd>↵</kbd> {{ t('commandPalette.hotkey.enter') }}</span>
|
<span class="cmdk__hotkey"><kbd>↵</kbd> {{ t('commandPalette.hotkey.enter') }}</span>
|
||||||
<span class="cmdk__hotkey"><kbd>⌘</kbd><kbd>1</kbd>-<kbd>9</kbd> {{ t('commandPalette.hotkey.cmdNumber') }}</span>
|
<span class="cmdk__hotkey"><kbd>⌘</kbd><kbd>1</kbd>-<kbd>9</kbd> {{ t('commandPalette.hotkey.cmdNumber')
|
||||||
|
}}</span>
|
||||||
<span class="cmdk__hotkey"><kbd>⌘</kbd><kbd>↵</kbd> {{ t('commandPalette.hotkey.cmdEnter') }}</span>
|
<span class="cmdk__hotkey"><kbd>⌘</kbd><kbd>↵</kbd> {{ t('commandPalette.hotkey.cmdEnter') }}</span>
|
||||||
<span class="cmdk__hotkey"><kbd>Esc</kbd> {{ t('commandPalette.hotkey.esc') }}</span>
|
<span class="cmdk__hotkey"><kbd>Esc</kbd> {{ t('commandPalette.hotkey.esc') }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Retrieval settings drawer (layered on top of the palette) -->
|
<!-- Retrieval settings drawer (layered on top of the palette) -->
|
||||||
<t-drawer
|
<t-drawer v-model:visible="drawerVisible" :header="t('retrievalSettings.title')" size="420px" :footer="false"
|
||||||
v-model:visible="drawerVisible"
|
:close-on-overlay-click="true" class="cmdk-retrieval-drawer">
|
||||||
:header="t('retrievalSettings.title')"
|
|
||||||
size="420px"
|
|
||||||
:footer="false"
|
|
||||||
:close-on-overlay-click="true"
|
|
||||||
class="cmdk-retrieval-drawer"
|
|
||||||
>
|
|
||||||
<RetrievalSettings />
|
<RetrievalSettings />
|
||||||
</t-drawer>
|
</t-drawer>
|
||||||
</t-dialog>
|
</t-dialog>
|
||||||
@@ -280,6 +164,7 @@ import { useI18n } from 'vue-i18n'
|
|||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useCommandPaletteStore } from '@/stores/commandPalette'
|
import { useCommandPaletteStore } from '@/stores/commandPalette'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
import { useCmdkSearch, type CmdkFileGroup, type CmdkChunk, type CmdkMsgGroup } from './GlobalCommandPalette/useSearch'
|
import { useCmdkSearch, type CmdkFileGroup, type CmdkChunk, type CmdkMsgGroup } from './GlobalCommandPalette/useSearch'
|
||||||
import { highlightText } from './GlobalCommandPalette/useHighlight'
|
import { highlightText } from './GlobalCommandPalette/useHighlight'
|
||||||
import { useStartChat } from './GlobalCommandPalette/useStartChat'
|
import { useStartChat } from './GlobalCommandPalette/useStartChat'
|
||||||
@@ -293,6 +178,7 @@ const { t } = useI18n()
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const commandPaletteStore = useCommandPaletteStore()
|
const commandPaletteStore = useCommandPaletteStore()
|
||||||
|
const authStore = useAuthStore()
|
||||||
const { open, initialQuery, recentQueries } = storeToRefs(commandPaletteStore)
|
const { open, initialQuery, recentQueries } = storeToRefs(commandPaletteStore)
|
||||||
const { startChat } = useStartChat()
|
const { startChat } = useStartChat()
|
||||||
|
|
||||||
@@ -364,13 +250,18 @@ const flatMessageItems = computed<FlatMsgItem[]>(() => {
|
|||||||
// ─── Commands ───
|
// ─── Commands ───
|
||||||
// All palette commands live in a shared module so quick-action (empty state)
|
// All palette commands live in a shared module so quick-action (empty state)
|
||||||
// and the "commands" tab can use the same data.
|
// and the "commands" tab can use the same data.
|
||||||
const allCommands = computed(() =>
|
const allCommands = computed(() => {
|
||||||
buildCommands({
|
const cmds = buildCommands({
|
||||||
router,
|
router,
|
||||||
t,
|
t,
|
||||||
close: () => commandPaletteStore.closePalette(),
|
close: () => commandPaletteStore.closePalette(),
|
||||||
}),
|
})
|
||||||
)
|
// 共享空间入口与侧栏菜单保持一致:viewer / contributor 看不到。
|
||||||
|
if (!authStore.hasRole('admin')) {
|
||||||
|
return cmds.filter((c) => c.id !== 'open-organizations')
|
||||||
|
}
|
||||||
|
return cmds
|
||||||
|
})
|
||||||
|
|
||||||
const filteredCommands = computed(() => filterCommands(allCommands.value, query.value))
|
const filteredCommands = computed(() => filterCommands(allCommands.value, query.value))
|
||||||
|
|
||||||
|
|||||||
@@ -60,12 +60,20 @@ export const useMenuStore = defineStore('menuStore', () => {
|
|||||||
|
|
||||||
const liteHiddenPaths = new Set(['logout', 'organizations'])
|
const liteHiddenPaths = new Set(['logout', 'organizations'])
|
||||||
|
|
||||||
|
// 共享空间 (organizations) 仅对当前租户的 admin / owner 暴露入口。
|
||||||
|
// viewer / contributor 即便在共享空间里拥有资源,也无需自行管理共享关系,
|
||||||
|
// 入口在侧栏只会徒增噪音;后端 RBAC 才是权限的最终来源(见 middleware/rbac.go)。
|
||||||
const visibleMenuArr = computed(() => {
|
const visibleMenuArr = computed(() => {
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
if (authStore.isLiteMode) {
|
return menuArr.filter(item => {
|
||||||
return menuArr.filter(item => !liteHiddenPaths.has(item.path))
|
if (authStore.isLiteMode && liteHiddenPaths.has(item.path)) {
|
||||||
}
|
return false
|
||||||
return menuArr
|
}
|
||||||
|
if (item.path === 'organizations' && !authStore.hasRole('admin')) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const chatMenuIndex = menuArr.findIndex(item => item.path === 'creatChat')
|
const chatMenuIndex = menuArr.findIndex(item => item.path === 'creatChat')
|
||||||
|
|||||||
+83
-73
@@ -34,53 +34,53 @@ import (
|
|||||||
type RouterParams struct {
|
type RouterParams struct {
|
||||||
dig.In
|
dig.In
|
||||||
|
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
FileService interfaces.FileService
|
FileService interfaces.FileService
|
||||||
UserService interfaces.UserService
|
UserService interfaces.UserService
|
||||||
KBService interfaces.KnowledgeBaseService
|
KBService interfaces.KnowledgeBaseService
|
||||||
KnowledgeService interfaces.KnowledgeService
|
KnowledgeService interfaces.KnowledgeService
|
||||||
ChunkService interfaces.ChunkService
|
ChunkService interfaces.ChunkService
|
||||||
SessionService interfaces.SessionService
|
SessionService interfaces.SessionService
|
||||||
MessageService interfaces.MessageService
|
MessageService interfaces.MessageService
|
||||||
ModelService interfaces.ModelService
|
ModelService interfaces.ModelService
|
||||||
EvaluationService interfaces.EvaluationService
|
EvaluationService interfaces.EvaluationService
|
||||||
KBShareService interfaces.KBShareService
|
KBShareService interfaces.KBShareService
|
||||||
AgentShareService interfaces.AgentShareService
|
AgentShareService interfaces.AgentShareService
|
||||||
KBHandler *handler.KnowledgeBaseHandler
|
KBHandler *handler.KnowledgeBaseHandler
|
||||||
KnowledgeHandler *handler.KnowledgeHandler
|
KnowledgeHandler *handler.KnowledgeHandler
|
||||||
TenantHandler *handler.TenantHandler
|
TenantHandler *handler.TenantHandler
|
||||||
TenantService interfaces.TenantService
|
TenantService interfaces.TenantService
|
||||||
TenantMemberService interfaces.TenantMemberService
|
TenantMemberService interfaces.TenantMemberService
|
||||||
TenantMemberHandler *handler.TenantMemberHandler
|
TenantMemberHandler *handler.TenantMemberHandler
|
||||||
TenantInvitationHandler *handler.TenantInvitationHandler
|
TenantInvitationHandler *handler.TenantInvitationHandler
|
||||||
AuditLogHandler *handler.AuditLogHandler
|
AuditLogHandler *handler.AuditLogHandler
|
||||||
AuditLogService interfaces.AuditLogService
|
AuditLogService interfaces.AuditLogService
|
||||||
ChunkHandler *handler.ChunkHandler
|
ChunkHandler *handler.ChunkHandler
|
||||||
SessionHandler *session.Handler
|
SessionHandler *session.Handler
|
||||||
MessageHandler *handler.MessageHandler
|
MessageHandler *handler.MessageHandler
|
||||||
ModelHandler *handler.ModelHandler
|
ModelHandler *handler.ModelHandler
|
||||||
ModelCredentialsHandler *handler.ModelCredentialsHandler
|
ModelCredentialsHandler *handler.ModelCredentialsHandler
|
||||||
EvaluationHandler *handler.EvaluationHandler
|
EvaluationHandler *handler.EvaluationHandler
|
||||||
AuthHandler *handler.AuthHandler
|
AuthHandler *handler.AuthHandler
|
||||||
InitializationHandler *handler.InitializationHandler
|
InitializationHandler *handler.InitializationHandler
|
||||||
SystemHandler *handler.SystemHandler
|
SystemHandler *handler.SystemHandler
|
||||||
MCPServiceHandler *handler.MCPServiceHandler
|
MCPServiceHandler *handler.MCPServiceHandler
|
||||||
MCPCredentialsHandler *handler.MCPCredentialsHandler
|
MCPCredentialsHandler *handler.MCPCredentialsHandler
|
||||||
WebSearchHandler *handler.WebSearchHandler
|
WebSearchHandler *handler.WebSearchHandler
|
||||||
WebSearchProviderHandler *handler.WebSearchProviderHandler
|
WebSearchProviderHandler *handler.WebSearchProviderHandler
|
||||||
WebSearchCredentialsHandler *handler.WebSearchProviderCredentialsHandler
|
WebSearchCredentialsHandler *handler.WebSearchProviderCredentialsHandler
|
||||||
VectorStoreHandler *handler.VectorStoreHandler
|
VectorStoreHandler *handler.VectorStoreHandler
|
||||||
FAQHandler *handler.FAQHandler
|
FAQHandler *handler.FAQHandler
|
||||||
TagHandler *handler.TagHandler
|
TagHandler *handler.TagHandler
|
||||||
CustomAgentHandler *handler.CustomAgentHandler
|
CustomAgentHandler *handler.CustomAgentHandler
|
||||||
UserFavoriteHandler *handler.UserResourceFavoriteHandler
|
UserFavoriteHandler *handler.UserResourceFavoriteHandler
|
||||||
SkillHandler *handler.SkillHandler
|
SkillHandler *handler.SkillHandler
|
||||||
OrganizationHandler *handler.OrganizationHandler
|
OrganizationHandler *handler.OrganizationHandler
|
||||||
IMHandler *handler.IMHandler
|
IMHandler *handler.IMHandler
|
||||||
DataSourceHandler *handler.DataSourceHandler
|
DataSourceHandler *handler.DataSourceHandler
|
||||||
DataSourceCredentialsHandler *handler.DataSourceCredentialsHandler
|
DataSourceCredentialsHandler *handler.DataSourceCredentialsHandler
|
||||||
WeKnoraCloudHandler *handler.WeKnoraCloudHandler
|
WeKnoraCloudHandler *handler.WeKnoraCloudHandler
|
||||||
WikiPageHandler *handler.WikiPageHandler
|
WikiPageHandler *handler.WikiPageHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRouter 创建新的路由
|
// NewRouter 创建新的路由
|
||||||
@@ -201,7 +201,7 @@ func NewRouter(params RouterParams) *gin.Engine {
|
|||||||
RegisterDataSourceRoutes(v1, params.DataSourceHandler, params.DataSourceCredentialsHandler, rbacGuards)
|
RegisterDataSourceRoutes(v1, params.DataSourceHandler, params.DataSourceCredentialsHandler, rbacGuards)
|
||||||
RegisterWeKnoraCloudRoutes(v1, params.WeKnoraCloudHandler, rbacGuards)
|
RegisterWeKnoraCloudRoutes(v1, params.WeKnoraCloudHandler, rbacGuards)
|
||||||
RegisterWikiPageRoutes(v1, params.WikiPageHandler, rbacGuards)
|
RegisterWikiPageRoutes(v1, params.WikiPageHandler, rbacGuards)
|
||||||
RegisterChunkerDebugRoutes(v1)
|
RegisterChunkerDebugRoutes(v1, rbacGuards)
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
@@ -209,8 +209,13 @@ func NewRouter(params RouterParams) *gin.Engine {
|
|||||||
|
|
||||||
// RegisterChunkerDebugRoutes wires the read-only chunker preview endpoint
|
// RegisterChunkerDebugRoutes wires the read-only chunker preview endpoint
|
||||||
// used by the KB editor's debug panel. Stateless — uses no service deps.
|
// used by the KB editor's debug panel. Stateless — uses no service deps.
|
||||||
func RegisterChunkerDebugRoutes(r *gin.RouterGroup) {
|
//
|
||||||
r.POST("/chunker/preview", handler.PreviewChunking)
|
// Viewer+ floor: the endpoint surfaces inside the tenant UI, so any
|
||||||
|
// authenticated tenant member can call it; revoked accounts whose JWT
|
||||||
|
// has not yet expired are kept out by the role check, matching the
|
||||||
|
// rest of the RBAC matrix in this file.
|
||||||
|
func RegisterChunkerDebugRoutes(r *gin.RouterGroup, g *rbacGuards) {
|
||||||
|
r.POST("/chunker/preview", g.Viewer(), handler.PreviewChunking)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterChunkRoutes 注册分块相关的路由
|
// RegisterChunkRoutes 注册分块相关的路由
|
||||||
@@ -567,7 +572,6 @@ func RegisterTenantRoutes(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Models are tenant-wide infrastructure (LLM credentials, embeddings,
|
// Models are tenant-wide infrastructure (LLM credentials, embeddings,
|
||||||
// rerankers); Viewer+ for reads, Admin+ for any mutation. Credential
|
// rerankers); Viewer+ for reads, Admin+ for any mutation. Credential
|
||||||
// subresource writes are also Admin+ since secrets are tenant-scoped.
|
// subresource writes are also Admin+ since secrets are tenant-scoped.
|
||||||
@@ -886,20 +890,21 @@ func RegisterOrganizationRoutes(r *gin.RouterGroup, orgHandler *handler.Organiza
|
|||||||
{
|
{
|
||||||
// Create organization (Admin+ in caller's tenant only)
|
// Create organization (Admin+ in caller's tenant only)
|
||||||
orgs.POST("", g.Admin(), orgHandler.CreateOrganization)
|
orgs.POST("", g.Admin(), orgHandler.CreateOrganization)
|
||||||
// List my organizations
|
// List my organizations — Viewer+ floor so revoked/non-member
|
||||||
orgs.GET("", orgHandler.ListMyOrganizations)
|
// accounts whose JWT still validates can't enumerate org membership.
|
||||||
// Preview organization by invite code (without joining)
|
orgs.GET("", g.Viewer(), orgHandler.ListMyOrganizations)
|
||||||
orgs.GET("/preview/:code", orgHandler.PreviewByInviteCode)
|
// Preview organization by invite code (without joining) — Viewer+
|
||||||
|
orgs.GET("/preview/:code", g.Viewer(), orgHandler.PreviewByInviteCode)
|
||||||
// Join organization by invite code (Admin+ in caller's tenant only)
|
// Join organization by invite code (Admin+ in caller's tenant only)
|
||||||
orgs.POST("/join", g.Admin(), orgHandler.JoinByInviteCode)
|
orgs.POST("/join", g.Admin(), orgHandler.JoinByInviteCode)
|
||||||
// Submit join request (for organizations that require approval) (Admin+)
|
// Submit join request (for organizations that require approval) (Admin+)
|
||||||
orgs.POST("/join-request", g.Admin(), orgHandler.SubmitJoinRequest)
|
orgs.POST("/join-request", g.Admin(), orgHandler.SubmitJoinRequest)
|
||||||
// Search searchable (discoverable) organizations
|
// Search searchable (discoverable) organizations — Viewer+
|
||||||
orgs.GET("/search", orgHandler.SearchOrganizations)
|
orgs.GET("/search", g.Viewer(), orgHandler.SearchOrganizations)
|
||||||
// Join searchable organization by ID (no invite code) (Admin+)
|
// Join searchable organization by ID (no invite code) (Admin+)
|
||||||
orgs.POST("/join-by-id", g.Admin(), orgHandler.JoinByOrganizationID)
|
orgs.POST("/join-by-id", g.Admin(), orgHandler.JoinByOrganizationID)
|
||||||
// Get organization by ID
|
// Get organization by ID — Viewer+
|
||||||
orgs.GET("/:id", orgHandler.GetOrganization)
|
orgs.GET("/:id", g.Viewer(), orgHandler.GetOrganization)
|
||||||
// Update organization — Admin+ in caller's tenant.
|
// Update organization — Admin+ in caller's tenant.
|
||||||
// Service still gates on "caller's tenant is the org owner";
|
// Service still gates on "caller's tenant is the org owner";
|
||||||
// the route guard adds a defence-in-depth layer that stops a
|
// the route guard adds a defence-in-depth layer that stops a
|
||||||
@@ -930,8 +935,8 @@ func RegisterOrganizationRoutes(r *gin.RouterGroup, orgHandler *handler.Organiza
|
|||||||
orgs.GET("/:id/search-users", g.Admin(), orgHandler.SearchUsersForInvite)
|
orgs.GET("/:id/search-users", g.Admin(), orgHandler.SearchUsersForInvite)
|
||||||
// Invite member directly (admin only)
|
// Invite member directly (admin only)
|
||||||
orgs.POST("/:id/invite", g.Admin(), orgHandler.InviteMember)
|
orgs.POST("/:id/invite", g.Admin(), orgHandler.InviteMember)
|
||||||
// List members
|
// List members — Viewer+
|
||||||
orgs.GET("/:id/members", orgHandler.ListMembers)
|
orgs.GET("/:id/members", g.Viewer(), orgHandler.ListMembers)
|
||||||
// Update member role (path parameter is the member tenant_id) —
|
// Update member role (path parameter is the member tenant_id) —
|
||||||
// Admin+ in caller's tenant. Changing another tenant's org role
|
// Admin+ in caller's tenant. Changing another tenant's org role
|
||||||
// is the symmetric counterpart of removing them; both must be
|
// is the symmetric counterpart of removing them; both must be
|
||||||
@@ -948,14 +953,14 @@ func RegisterOrganizationRoutes(r *gin.RouterGroup, orgHandler *handler.Organiza
|
|||||||
orgs.GET("/:id/join-requests", g.Admin(), orgHandler.ListJoinRequests)
|
orgs.GET("/:id/join-requests", g.Admin(), orgHandler.ListJoinRequests)
|
||||||
// Review join request (admin only)
|
// Review join request (admin only)
|
||||||
orgs.PUT("/:id/join-requests/:request_id/review", g.Admin(), orgHandler.ReviewJoinRequest)
|
orgs.PUT("/:id/join-requests/:request_id/review", g.Admin(), orgHandler.ReviewJoinRequest)
|
||||||
// List knowledge bases shared to this organization
|
// List knowledge bases shared to this organization — Viewer+
|
||||||
orgs.GET("/:id/shares", orgHandler.ListOrgShares)
|
orgs.GET("/:id/shares", g.Viewer(), orgHandler.ListOrgShares)
|
||||||
// List agents shared to this organization
|
// List agents shared to this organization — Viewer+
|
||||||
orgs.GET("/:id/agent-shares", orgHandler.ListOrgAgentShares)
|
orgs.GET("/:id/agent-shares", g.Viewer(), orgHandler.ListOrgAgentShares)
|
||||||
// List all knowledge bases in this organization (including mine) for list-page space view
|
// List all knowledge bases in this organization (including mine) for list-page space view — Viewer+
|
||||||
orgs.GET("/:id/shared-knowledge-bases", orgHandler.ListOrganizationSharedKnowledgeBases)
|
orgs.GET("/:id/shared-knowledge-bases", g.Viewer(), orgHandler.ListOrganizationSharedKnowledgeBases)
|
||||||
// List all agents in this organization (including mine) for list-page space view
|
// List all agents in this organization (including mine) for list-page space view — Viewer+
|
||||||
orgs.GET("/:id/shared-agents", orgHandler.ListOrganizationSharedAgents)
|
orgs.GET("/:id/shared-agents", g.Viewer(), orgHandler.ListOrganizationSharedAgents)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Knowledge base sharing routes (add to existing kb routes).
|
// Knowledge base sharing routes (add to existing kb routes).
|
||||||
@@ -976,17 +981,22 @@ func RegisterOrganizationRoutes(r *gin.RouterGroup, orgHandler *handler.Organiza
|
|||||||
|
|
||||||
// Agent sharing routes — same rationale as KB shares: 分享/取消分享
|
// Agent sharing routes — same rationale as KB shares: 分享/取消分享
|
||||||
// 跟修改 agent 同等敏感,挂 OwnedAgentOrAdmin。
|
// 跟修改 agent 同等敏感,挂 OwnedAgentOrAdmin。
|
||||||
|
//
|
||||||
|
// GET 同样走 OwnedAgentOrAdmin:service.ListSharesByAgent 没有 owner
|
||||||
|
// 校验(与 ListSharesByKnowledgeBase 不对称),如果路由层只挂 Viewer
|
||||||
|
// 任何同租户成员都能枚举他人 agent 的分享去向——这里把 owner 校验
|
||||||
|
// 兜底到路由层,匹配 POST/DELETE 的矩阵。
|
||||||
agentShares := r.Group("/agents/:id/shares")
|
agentShares := r.Group("/agents/:id/shares")
|
||||||
{
|
{
|
||||||
agentShares.POST("", g.OwnedAgentOrAdmin(), orgHandler.ShareAgent)
|
agentShares.POST("", g.OwnedAgentOrAdmin(), orgHandler.ShareAgent)
|
||||||
agentShares.GET("", g.Viewer(), orgHandler.ListAgentShares)
|
agentShares.GET("", g.OwnedAgentOrAdmin(), orgHandler.ListAgentShares)
|
||||||
agentShares.DELETE("/:share_id", g.OwnedAgentOrAdmin(), orgHandler.RemoveAgentShare)
|
agentShares.DELETE("/:share_id", g.OwnedAgentOrAdmin(), orgHandler.RemoveAgentShare)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shared knowledge bases route
|
// Shared knowledge bases route — Viewer+
|
||||||
r.GET("/shared-knowledge-bases", orgHandler.ListSharedKnowledgeBases)
|
r.GET("/shared-knowledge-bases", g.Viewer(), orgHandler.ListSharedKnowledgeBases)
|
||||||
// Shared agents route
|
// Shared agents route — Viewer+
|
||||||
r.GET("/shared-agents", orgHandler.ListSharedAgents)
|
r.GET("/shared-agents", g.Viewer(), orgHandler.ListSharedAgents)
|
||||||
// "Disable by me" 是租户级偏好(写到 tenant_disabled_shared_agents),
|
// "Disable by me" 是租户级偏好(写到 tenant_disabled_shared_agents),
|
||||||
// 影响整个租户在会话下拉里看到的 agent 列表。任何 Viewer 改这个表就
|
// 影响整个租户在会话下拉里看到的 agent 列表。任何 Viewer 改这个表就
|
||||||
// 等于替整个租户做决定 — 必须 Admin+ 才允许调整。
|
// 等于替整个租户做决定 — 必须 Admin+ 才允许调整。
|
||||||
|
|||||||
Reference in New Issue
Block a user