Skip to content

Commit 8912293

Browse files
author
linyuan.yang
committed
saver 引用问题
1 parent 8066bab commit 8912293

5 files changed

Lines changed: 58 additions & 10 deletions

File tree

‎packages/admin/src/components/ResourceRefs.vue‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const { t } = useI18n()
2828
{{ p.name }}<span v-if="p.sessionCount" class="ref-chip-sub">{{ t('common.ref_profile_sessions', { n: p.sessionCount }) }}</span>
2929
</span>
3030
</SInfoRow>
31+
<SInfoRow v-if="refs.sessions.length" :label="t('common.ref_sessions')">
32+
<span v-for="s in refs.sessions" :key="s.id" class="ref-chip">{{ s.name }}</span>
33+
</SInfoRow>
3134
<SInfoRow v-if="refs.agents.length" :label="t('common.ref_agents')">
3235
<span v-for="a in refs.agents" :key="a.id" class="ref-chip">{{ a.name }}</span>
3336
</SInfoRow>

‎packages/admin/src/composables/useResourceRefs.ts‎

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ref } from 'vue'
44
import { apiFetch } from '@/shared/api'
55
import { store } from '@/shared/store'
66

7-
/** 会话档案列表行(GET /api/session-profiles),仅取引用计算需要的字段。 */
7+
/** 会话档案列表行(GET /api/session-profiles,仅 visible profile),仅取引用计算需要的字段。 */
88
interface ProfileLite {
99
id: number
1010
name: string
@@ -17,21 +17,47 @@ interface ProfileLite {
1717
sessionCount?: number
1818
}
1919

20+
/**
21+
* 会话列表行(GET /api/channel-sessions),仅取引用计算需要的字段。
22+
* 字段值已是 profile 自身覆盖值(null = 继承频道默认);notes/wikis 已解析为 string[]。
23+
* 用于补全「按会话直接覆盖、存在各自 auto profile 上」的引用 —— 这些 profile 不在
24+
* /api/session-profiles(只返回 visible profile)里,否则会被漏扫。
25+
*/
26+
interface SessionLite {
27+
id: number
28+
profileId: number
29+
channelId: string
30+
sessionName: string
31+
autoSessionName: string
32+
agentId: string | null
33+
saver: string | null
34+
notes: string[] | null
35+
wikis: string[] | null
36+
memory: string | null
37+
agenda: string | null
38+
}
39+
2040
/** 单个引用方。 */
2141
export interface RefItem { id: string | number; name: string; sessionCount?: number }
2242

23-
/** 某资源的全部引用方,分频道 / 会话档案 / 智能体三类。 */
43+
/** 某资源的全部引用方,分频道 / 会话档案 / 会话 / 智能体四类。 */
2444
export interface ResourceRefsValue {
2545
channels: RefItem[]
2646
profiles: RefItem[]
47+
sessions: RefItem[]
2748
agents: RefItem[]
2849
total: number
2950
}
3051

31-
/** 三类引用方的匹配器;`agent` 可选(仅存储页用到)。 */
52+
/**
53+
* 各类引用方的匹配器。
54+
* - `agent` 可选(仅存储页用到)。
55+
* - `session` 可选:匹配「会话私有覆盖」(auto profile),与 visible profile 互斥统计,不重复计数。
56+
*/
3257
export interface RefMatchers {
3358
channel: (c: any, id: string) => boolean
3459
profile: (p: ProfileLite, id: string) => boolean
60+
session?: (s: SessionLite, id: string) => boolean
3561
agent?: (a: any, id: string) => boolean
3662
}
3763

@@ -41,15 +67,20 @@ export function parseList(raw: string | null | undefined): string[] {
4167
try { const v = JSON.parse(raw); return Array.isArray(v) ? v : [] } catch { return [] }
4268
}
4369

44-
// 模块级共享:多个页面实例共用同一份会话档案列表。
70+
// 模块级共享:多个页面实例共用同一份会话档案 / 会话列表。
4571
const profilesList = ref<ProfileLite[]>([])
72+
const sessionsList = ref<SessionLite[]>([])
4673

4774
export function useResourceRefs() {
4875
async function loadProfiles() {
49-
try {
50-
const res = await apiFetch('/api/session-profiles')
51-
profilesList.value = (res.data || []) as ProfileLite[]
52-
} catch { /* 引用信息为辅助展示,加载失败时静默降级为空 */ }
76+
// visible profile 与会话各取所需字段:会话用于补全 auto profile 上的私有覆盖引用。
77+
const [profilesRes, sessionsRes] = await Promise.allSettled([
78+
apiFetch('/api/session-profiles'),
79+
apiFetch('/api/channel-sessions'),
80+
])
81+
// 引用信息为辅助展示,任一接口失败时静默降级为空。
82+
profilesList.value = profilesRes.status === 'fulfilled' ? (profilesRes.value.data || []) as ProfileLite[] : []
83+
sessionsList.value = sessionsRes.status === 'fulfilled' ? (sessionsRes.value.data || []) as SessionLite[] : []
5384
}
5485

5586
/** 用匹配器生成本页的 refs(id) 计算函数。 */
@@ -61,12 +92,23 @@ export function useResourceRefs() {
6192
const profiles = profilesList.value
6293
.filter(p => matchers.profile(p, id))
6394
.map(p => ({ id: p.id, name: p.name || String(p.id), sessionCount: p.sessionCount ?? 0 }))
95+
// 会话私有覆盖:仅统计走各自 auto profile 的会话(profileId 不在 visible profile 集合里),
96+
// 避免与上面共享 visible profile 的会话重复计数。
97+
const visibleProfileIds = new Set(profilesList.value.map(p => p.id))
98+
const sessions = matchers.session
99+
? sessionsList.value
100+
.filter(s => !visibleProfileIds.has(s.profileId) && matchers.session!(s, id))
101+
.map(s => ({ id: s.id, name: s.sessionName || s.autoSessionName || String(s.id) }))
102+
: []
64103
const agents = matchers.agent
65104
? Object.entries(store.settings.agents || {})
66105
.filter(([, a]) => matchers.agent!(a as any, id))
67106
.map(([aid, a]) => ({ id: aid, name: (a as any).name || aid }))
68107
: []
69-
return { channels, profiles, agents, total: channels.length + profiles.length + agents.length }
108+
return {
109+
channels, profiles, sessions, agents,
110+
total: channels.length + profiles.length + sessions.length + agents.length,
111+
}
70112
}
71113
}
72114

‎packages/admin/src/i18n/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default {
7878
ref_unused_hint: 'This item is not referenced by any channel, session profile, or agent — safe to delete.',
7979
ref_channels: 'Channels',
8080
ref_profiles: 'Session Profiles',
81+
ref_sessions: 'Sessions (private override)',
8182
ref_agents: 'Agents',
8283
ref_profile_sessions: '{n} session(s)',
8384
enabled: 'Enabled',

‎packages/admin/src/i18n/zh.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default {
7878
ref_unused_hint: '该项未被任何频道、会话档案或智能体引用,可安全删除。',
7979
ref_channels: '频道',
8080
ref_profiles: '会话档案',
81+
ref_sessions: '会话(私有覆盖)',
8182
ref_agents: '智能体',
8283
ref_profile_sessions: '{n} 个会话',
8384
enabled: '启用',

‎packages/admin/src/views/savers/SaversView.vue‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ const saverColumns = computed<STableColumn[]>(() => [
3434
{ key: 'ops', label: t('common.ops'), ops: true },
3535
])
3636
37-
// ── 被引用情况(频道 / 会话档案 / 智能体) ──
37+
// ── 被引用情况(频道 / 会话档案 / 会话 / 智能体) ──
3838
const { loadProfiles, makeResourceRefs } = useResourceRefs()
3939
const refs = makeResourceRefs({
4040
channel: (c, id) => c.saver === id,
4141
profile: (p, id) => p.saver === id,
42+
session: (s, id) => s.saver === id, // 会话私有覆盖(存在各自 auto profile 上,否则被漏扫)
4243
agent: (a, id) => a.saver === id,
4344
})
4445
onMounted(loadProfiles)

0 commit comments

Comments
 (0)