diff --git a/frontend/src/api/agent/index.ts b/frontend/src/api/agent/index.ts index 9a783693..e40a713a 100644 --- a/frontend/src/api/agent/index.ts +++ b/frontend/src/api/agent/index.ts @@ -99,6 +99,8 @@ export interface CustomAgent { is_builtin: boolean; tenant_id?: number; created_by?: string; + // creator_name 由后端 list 接口批量回填,仅用于列表卡片来源徽章。 + creator_name?: string; config: CustomAgentConfig; created_at?: string; updated_at?: string; diff --git a/frontend/src/api/auth/index.ts b/frontend/src/api/auth/index.ts index 5a28361a..e6b86d5a 100644 --- a/frontend/src/api/auth/index.ts +++ b/frontend/src/api/auth/index.ts @@ -115,6 +115,9 @@ export interface KnowledgeBaseInfo { // Set by PR 5 of the multi-tenant RBAC series; nullable for legacy // KBs created before that migration backfilled the column. creator_id?: string + // creator_name 由后端 list 接口批量回填(username 优先,退化到 email), + // 仅用于列表卡片来源徽章;缺失代表无法解析(已删除 / 老数据)。 + creator_name?: string created_at: string updated_at: string document_count?: number diff --git a/frontend/src/components/ResourceOriginBadge.vue b/frontend/src/components/ResourceOriginBadge.vue index 0e52080a..e41e39a3 100644 --- a/frontend/src/components/ResourceOriginBadge.vue +++ b/frontend/src/components/ResourceOriginBadge.vue @@ -15,23 +15,30 @@ import { useAuthStore } from '@/stores/auth' * ResourceOriginBadge – a unified, compact label that explains *where* a * KB or Agent comes from. Replaces the ad-hoc "我的" / "shared-by-me-badge" * / org_name pills scattered across KnowledgeBaseList and AgentList. The - * variants below cover the four origin shapes the list views actually + * variants below cover the five origin shapes the list views actually * surface; future origins (e.g. "system" / "imported") should add a new * variant rather than re-using one of these. * * Variants: * - mine : created by the current user in the current tenant * - tenant : owned by the current tenant but created by someone else + * — label shows tenant name; use when context doesn't say + * - creator : same data shape as `tenant`, but the surrounding section + * header already names the tenant ("本空间 · 仅查看"), so + * the badge only carries the creator name to avoid the + * duplicated "本空间 / wizardchen's Workspace" pill on + * every card. Falls back to the i18n label when the + * creator name is unknown. * - space : reached through a cross-tenant space (organization) * - shared : cross-tenant share without a useful org name to show * * Pass `creatorName` to surface "by 张三" in the tooltip for the `tenant` - * variant; omit it for the `mine` / `space` / `shared` variants where the - * subject is implicit. + * variant, or to drive the visible label of the `creator` variant; omit it + * for the `mine` / `space` / `shared` variants where the subject is implicit. */ const props = withDefaults( defineProps<{ - variant: 'mine' | 'tenant' | 'space' | 'shared' + variant: 'mine' | 'tenant' | 'creator' | 'space' | 'shared' /** Used in `space` variant — the organization (space) display name. */ spaceName?: string /** Optional creator display name, surfaces in tooltip for `tenant` variant. */ @@ -51,6 +58,8 @@ const iconName = computed(() => { return 'user' case 'tenant': return 'usergroup' + case 'creator': + return 'user' case 'space': return 'building' case 'shared': @@ -70,6 +79,11 @@ const displayText = computed(() => { // Prefer the tenant name when known so the badge says where the // resource lives, not a vague "tenant" label. Falls back to i18n. return authStore.currentTenantName || t('resourceOrigin.tenant') + case 'creator': + // Section header already provides the「本空间」context, so we just + // show who created it. Fall back to a generic label when the user + // can't be resolved (creator_name 缺失,例如已删除账号 / 老数据)。 + return props.creatorName || t('resourceOrigin.tenant') case 'space': return props.spaceName || t('resourceOrigin.space') case 'shared': @@ -88,6 +102,12 @@ const tooltipText = computed(() => { return t('resourceOrigin.tenantTooltipWithCreator', { creator: props.creatorName }) } return t('resourceOrigin.tenantTooltip') + case 'creator': + // 卡片标签只露名字;tooltip 把完整含义补回来。 + if (props.creatorName) { + return t('resourceOrigin.tenantTooltipWithCreator', { creator: props.creatorName }) + } + return t('resourceOrigin.tenantTooltip') case 'space': if (props.sourceTenantName) { return t('resourceOrigin.spaceTooltipWithTenant', { @@ -136,6 +156,11 @@ const tooltipText = computed(() => { background: var(--td-bg-color-secondarycontainer); } + &.origin-creator { + color: var(--td-text-color-secondary); + background: var(--td-bg-color-secondarycontainer); + } + &.origin-space { color: var(--td-warning-color-7, #b86e02); background: var(--td-warning-color-1, #fff7e6); diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 39319ebe..3bcf8f9b 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -425,6 +425,11 @@ export default { mine: 'My Agents', sharedToMe: 'Shared to Me', }, + sections: { + tenantReadonly: 'Workspace · View only', + sharedEditable: 'Shared with me · Can edit', + sharedReadonly: 'Shared with me · View only', + }, empty: { title: 'No Custom Agents', description: 'Click the button in the top right to create your first agent', @@ -1618,6 +1623,9 @@ export default { sections: { pinned: 'Pinned', others: 'Others', + tenantReadonly: 'Workspace · View only', + sharedEditable: 'Shared with me · Can edit', + sharedReadonly: 'Shared with me · View only', }, messages: { deleted: 'Knowledge base deleted', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 798153d2..4c533a4f 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -1317,6 +1317,11 @@ export default { mine: "내 에이전트", sharedToMe: "나와 공유됨", }, + sections: { + tenantReadonly: "워크스페이스 · 읽기 전용", + sharedEditable: "공유받음 · 편집 가능", + sharedReadonly: "공유받음 · 읽기 전용", + }, empty: { title: "아직 맞춤 에이전트가 없습니다.", description: "첫 번째 에이전트를 생성하려면 오른쪽 상단에 있는 버튼을 클릭하세요.", @@ -2276,6 +2281,9 @@ export default { sections: { pinned: "고정됨", others: "기타", + tenantReadonly: "워크스페이스 · 읽기 전용", + sharedEditable: "공유받음 · 편집 가능", + sharedReadonly: "공유받음 · 읽기 전용", }, detail: { title: "공유 지식베이스", diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 695c0c2d..7ae39fda 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -517,6 +517,11 @@ export default { mine: 'My Agents', sharedToMe: 'Shared to Me' }, + sections: { + tenantReadonly: 'Рабочая область · Только просмотр', + sharedEditable: 'Доступно мне · Можно редактировать', + sharedReadonly: 'Доступно мне · Только просмотр' + }, empty: { title: 'No Custom Agents', description: 'Click the button in the top right to create your first agent', @@ -1850,7 +1855,10 @@ export default { }, sections: { pinned: 'Закреплённые', - others: 'Другие' + others: 'Другие', + tenantReadonly: 'Рабочая область · Только просмотр', + sharedEditable: 'Доступно мне · Можно редактировать', + sharedReadonly: 'Доступно мне · Только просмотр' }, messages: { deleted: 'База знаний удалена', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index e19fa4a1..c4878b0a 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -1311,6 +1311,11 @@ export default { mine: "我的智能体", sharedToMe: "共享给我", }, + sections: { + tenantReadonly: "本空间 · 仅查看", + sharedEditable: "共享给我 · 可编辑", + sharedReadonly: "共享给我 · 仅查看", + }, empty: { title: "暂无自定义智能体", description: "点击右上角按钮创建您的第一个智能体", @@ -2252,6 +2257,9 @@ export default { sections: { pinned: "置顶", others: "其他", + tenantReadonly: "本空间 · 仅查看", + sharedEditable: "共享给我 · 可编辑", + sharedReadonly: "共享给我 · 仅查看", }, detail: { title: "共享知识库", diff --git a/frontend/src/views/agent/AgentList.vue b/frontend/src/views/agent/AgentList.vue index 3d1ed05d..6bc604ab 100644 --- a/frontend/src/views/agent/AgentList.vue +++ b/frontend/src/views/agent/AgentList.vue @@ -64,402 +64,457 @@
-
+ +
+ {{ $t('agent.sections.tenantReadonly') }} +
+ +
+ {{ $t('agent.sections.sharedEditable') }} +
+ +
+ {{ $t('agent.sections.sharedReadonly') }} +
+
- - - -
- - - - - - -
-
-
-
- -
-
{{ agent.avatar }}
- - {{ agent.name }} + + + +
+ + + + + +
- -
- -
- -
- -
- +
{{ agent.avatar }}
+ + {{ agent.name }}
- -
-
-
-
{{ agent.description || $t('agent.noDescription') }}
-
-
-
-
- {{ $t('agent.disabled') }} - {{ - $t('agent.disabled') }} - -
- + + + +
+ +
+ +
+
+
+
{{ agent.description || $t('agent.noDescription') }}
+
+
+
+
+ {{ $t('agent.disabled') }} + {{ + $t('agent.disabled') }} + +
+ +
+
+ + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
-
- -
- - {{ agent.org_name }} -
-
- - {{ $t('agent.builtin') }} -
-
- {{ $t('agent.type.custom') }} + +
+ + {{ agent.org_name }} +
+
+ + {{ $t('agent.builtin') }} +
+
-
+
-
-
- - - -
- - - - - - +
+
-
-
0" class="agent-card-wrap"> +
@@ -649,6 +704,7 @@ import type { SharedAgentInfo, OrganizationSharedAgentItem } from '@/api/organiz import AgentEditorModal from './AgentEditorModal.vue' import AgentAvatar from '@/components/AgentAvatar.vue' import ListSpaceSidebar from '@/components/ListSpaceSidebar.vue' +import ResourceOriginBadge from '@/components/ResourceOriginBadge.vue' import { useAuthStore } from '@/stores/auth' import { useListUrlState } from '@/composables/useListUrlState' import { useResourcePins } from '@/composables/useResourcePins' @@ -665,8 +721,10 @@ interface AgentWithUI extends CustomAgent { disabled_by_me?: boolean } -/** Merged agent for "all" tab: my agents (isMine: true) or shared (isMine: false, org_name, source_tenant_id, share_id, disabled_by_me?) */ -type DisplayAgent = (AgentWithUI & { isMine: true }) | (CustomAgent & { isMine: false; org_name: string; source_tenant_id: number; share_id: string; showMore?: boolean; disabled_by_me?: boolean }) +/** Merged agent for "all" tab: my agents (isMine: true) or shared + * (isMine: false, org_name, source_tenant_id, share_id, permission, disabled_by_me?). + * `permission` drives the「可编辑 / 仅查看」分组,仅在 shared 分支携带。 */ +type DisplayAgent = (AgentWithUI & { isMine: true }) | (CustomAgent & { isMine: false; org_name: string; source_tenant_id: number; share_id: string; permission?: string; showMore?: boolean; disabled_by_me?: boolean }) // 左侧空间选择:默认根据当前角色决定。 // 与 KnowledgeBaseList 同款逻辑:Viewer 在当前租户里通常没有自建智能体, @@ -795,8 +853,27 @@ const filteredAgents = computed(() => { } if (spaceSelection.value !== 'all') return [] const list: DisplayAgent[] = [] - agents.value.forEach(a => list.push({ ...a, isMine: true as const })) - sharedAgents.value.forEach(shared => { + // 本租户内的 agent 拆成「我创建」与「同事创建」两段,让 contributor + // 视图能在二者之间插入「本空间 · 仅查看」分组标题。内建 agent + // (is_builtin=true, created_by="") 视作"非我"——它本来就是租户共有的, + // 也归到只读那一档;如果不是 contributor,标题被开关压住,看起来无差别。 + const ownMine: AgentWithUI[] = [] + const teammateMine: AgentWithUI[] = [] + agents.value.forEach(a => { + if (isMyAgent(a)) ownMine.push(a) + else teammateMine.push(a) + }) + ownMine.forEach(a => list.push({ ...a, isMine: true as const })) + teammateMine.forEach(a => list.push({ ...a, isMine: true as const })) + // 共享区按 share permission 排序:editor/admin 在前,viewer 在后, + // 让「共享给我 · 可编辑 / 仅查看」分组标题正好落在过渡处。即便当前角色 + // 不显示分组标题,排序也保留——展示更可预测。 + const sortedShared = [...sharedAgents.value].sort((a, b) => { + const aE = isSharedAgentEditable(a.permission) ? 0 : 1 + const bE = isSharedAgentEditable(b.permission) ? 0 : 1 + return aE - bE + }) + sortedShared.forEach(shared => { if (!shared.agent) return list.push({ ...shared.agent, @@ -804,12 +881,37 @@ const filteredAgents = computed(() => { org_name: shared.org_name, source_tenant_id: shared.source_tenant_id, share_id: shared.share_id, + permission: shared.permission, disabled_by_me: shared.disabled_by_me, showMore: false } as DisplayAgent) }) return list }) + +// 「工作空间」视图下的稳定排序:本租户内「我创建」在前、「同事创建 / 内建」 +// 在后。给 contributor 视图把「本空间 · 仅查看」分组标题正好插在过渡处。 +const sortedMineAgents = computed(() => { + const own: AgentWithUI[] = [] + const teammate: AgentWithUI[] = [] + agents.value.forEach(a => { + if (isMyAgent(a)) own.push(a) + else teammate.push(a) + }) + return [...own, ...teammate] +}) + +// 空间视角下的稳定排序:我自己创建的(is_mine)放前面,其余按 permission 切分。 +const sortedSpaceAgentsList = computed(() => { + return [...spaceAgentsList.value].sort((a, b) => { + const aMine = a.is_mine ? 0 : 1 + const bMine = b.is_mine ? 0 : 1 + if (aMine !== bMine) return aMine - bMine + const aE = isSharedAgentEditable(a.permission) ? 0 : 1 + const bE = isSharedAgentEditable(b.permission) ? 0 : 1 + return aE - bE + }) +}) const loading = ref(false) const deleteVisible = ref(false) const deletingAgent = ref(null) @@ -1042,6 +1144,32 @@ function canManageAgent(agent: AgentWithUI): boolean { return authStore.hasRole('admin') } +// isMyAgent 仅用于卡片来源徽章在「我创建」与「同租户其他成员创建」之间切换。 +// 跟 canManageAgent 区别:管理权限有 admin 兜底;徽章纯粹按 created_by 匹配。 +// 内建 agent(created_by="")也归到非 mine 一档,由模板上的 builtin 分支 +// 提前拦截,不会落到 ResourceOriginBadge。 +function isMyAgent(agent: { created_by?: string }): boolean { + const userId = authStore.user?.id || '' + return !!(agent.created_by && userId && agent.created_by === userId) +} + +// agentOriginVariant 跟 kbOriginVariant 对齐:右下角徽章不再重复租户名 +// (顶部 TenantSelector 已经标了租户身份),所有角色都用 creator 变体。 +// 内建 agent 走 v-else 前的 builtin 分支,到不了这里。 +function agentOriginVariant(agent: { created_by?: string }): 'mine' | 'creator' { + return isMyAgent(agent) ? 'mine' : 'creator' +} + +// 共享 agent 的可编辑/只读分组开关,与 KB 列表逻辑保持一致:仅对 +// contributor / editor 中间档展示分组标题。Viewer / Admin+ 不分组。 +const AGENT_EDITABLE_PERMS = new Set(['admin', 'editor']) +function isSharedAgentEditable(perm: string | undefined): boolean { + return !!perm && AGENT_EDITABLE_PERMS.has(perm) +} +const showShareGroupHeaders = computed(() => { + return authStore.hasRole('contributor') && !authStore.hasRole('admin') +}) + const handleDelete = (agent: AgentWithUI) => { openMoreAgentId.value = null deletingAgent.value = agent @@ -1417,6 +1545,20 @@ defineExpose({ flex-shrink: 0; } +// 共享给我 · 可编辑 / 仅查看 分组标题,与 KB 列表 .kb-section-header 对齐。 +.agent-section-header { + grid-column: 1 / -1; + display: flex; + align-items: center; + gap: 6px; + padding: 2px 0; + color: var(--td-text-color-secondary); + font-family: var(--app-font-family); + font-size: 13px; + font-weight: 600; + line-height: 20px; +} + @keyframes contentFadeIn { from { diff --git a/frontend/src/views/knowledge/KnowledgeBaseList.vue b/frontend/src/views/knowledge/KnowledgeBaseList.vue index 0a9940c9..6ef5627f 100644 --- a/frontend/src/views/knowledge/KnowledgeBaseList.vue +++ b/frontend/src/views/knowledge/KnowledgeBaseList.vue @@ -102,13 +102,45 @@