@@ -4,7 +4,7 @@ import { ref } from 'vue'
44import { apiFetch } from '@/shared/api'
55import { store } from '@/shared/store'
66
7- /** 会话档案列表行(GET /api/session-profiles),仅取引用计算需要的字段。 */
7+ /** 会话档案列表行(GET /api/session-profiles,仅 visible profile ),仅取引用计算需要的字段。 */
88interface 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/** 单个引用方。 */
2141export interface RefItem { id : string | number ; name : string ; sessionCount ?: number }
2242
23- /** 某资源的全部引用方,分频道 / 会话档案 / 智能体三类 。 */
43+ /** 某资源的全部引用方,分频道 / 会话档案 / 会话 / 智能体四类 。 */
2444export 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+ */
3257export 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+ // 模块级共享:多个页面实例共用同一份会话档案 / 会话列表 。
4571const profilesList = ref < ProfileLite [ ] > ( [ ] )
72+ const sessionsList = ref < SessionLite [ ] > ( [ ] )
4673
4774export 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
0 commit comments