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