From 2d6b84cb23ce6eac25b420773429194d7faf8520 Mon Sep 17 00:00:00 2001 From: FincherYuan Date: Fri, 4 Sep 2026 16:58:02 +0800 Subject: [PATCH] feat(session): show owner badge for API sessions in sidebar Sessions owned by synthetic principals (api_external_user::, api_tenant_key::) have no real account row to display, so the sidebar previously showed nothing about who created them. Render a small badge next to the title: the readable sub for external-user sessions, a generic "API" tag for key-scoped sessions. Regular account/web sessions stay unchanged (no badge). user_id already flows through mapSessionRow -> bucket items -> SessionSidebarRow; only the render was missing. Co-Authored-By: Claude Code --- frontend/src/components/SessionSidebarRow.vue | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/SessionSidebarRow.vue b/frontend/src/components/SessionSidebarRow.vue index 0ff20766..3109e786 100644 --- a/frontend/src/components/SessionSidebarRow.vue +++ b/frontend/src/components/SessionSidebarRow.vue @@ -35,6 +35,12 @@ {{ item.title }} + {{ apiOwnerTag.label }}
( : 'session-action-menu-popup is-confirm' )) +/** + * API/渠道会话的 owner 是合成主体(api_external_user:: / + * api_tenant_key::),不是真实账号。为方便管理员稽核"这条是谁的", + * 在标题旁渲染一个小徽标:外部员工会话取 sub(可读标识),平台 key 会话标 generic。 + * 普通账号会话(user_id 为空或为真实用户 UUID)不显示。 + */ +interface ApiOwnerTag { kind: 'user' | 'key'; label: string; full: string } +const API_EXTERNAL_USER_PREFIX = 'api_external_user:' +const API_TENANT_KEY_PREFIX = 'api_tenant_key:' + +const apiOwnerTag = computed(() => { + const uid = props.item.user_id || '' + if (uid.startsWith(API_EXTERNAL_USER_PREFIX)) { + const tail = uid.slice(API_EXTERNAL_USER_PREFIX.length) + const segments = tail.split(':').filter(Boolean) + const label = segments.length ? segments[segments.length - 1] : tail + return label ? { kind: 'user', label, full: uid } : null + } + if (uid.startsWith(API_TENANT_KEY_PREFIX)) { + return { kind: 'key', label: 'API', full: uid } + } + return null +}) + const onMenuVisibleChange = (visible: boolean): void => { if (!visible) menuMode.value = 'menu' } @@ -265,6 +295,36 @@ const confirmDangerAction = (): void => { background: var(--td-bg-color-container-hover); } } + +// 合成 owner(api_external_user / api_tenant_key)会话的"提问人"徽标。 +// 父级 .submenu_title 是 flex,故必须 flex:0 0 auto,标题省略号只压缩标题文本。 +.session-owner-tag { + flex: 0 0 auto; + margin-left: 8px; + max-width: 108px; + height: 16px; + padding: 0 6px; + box-sizing: border-box; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + font-size: 11px; + line-height: 15px; + font-weight: 400; + border-radius: 4px; + + &--user { + color: var(--td-brand-color); + background: var(--td-brand-color-light); + border: 0.5px solid var(--td-brand-color-light-active); + } + + &--key { + color: var(--td-text-color-secondary); + background: var(--td-bg-color-container-hover); + border: 0.5px solid var(--td-component-stroke); + } +}