-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapp.computed.session.mjs
More file actions
154 lines (153 loc) · 6.72 KB
/
app.computed.session.mjs
File metadata and controls
154 lines (153 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import {
buildSessionTimelineNodes,
buildUsageChartGroups,
isSessionQueryEnabled,
normalizeSessionMatch
} from '../logic.mjs';
import { SESSION_TRASH_PAGE_SIZE } from './app.constants.mjs';
export function createSessionComputed() {
return {
isSessionQueryEnabled() {
return isSessionQueryEnabled(this.sessionFilterSource);
},
activeSessionExportKey() {
return this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
},
sortedSessionsList() {
const list = Array.isArray(this.sessionsList) ? this.sessionsList : [];
if (list.length === 0) return [];
const pinnedMap = (this.sessionPinnedMap && typeof this.sessionPinnedMap === 'object')
? this.sessionPinnedMap
: {};
let hasPinned = false;
const decorated = list.map((session, index) => {
const key = session ? this.getSessionExportKey(session) : '';
const rawPinnedAt = key ? pinnedMap[key] : 0;
const pinnedAt = Number.isFinite(Number(rawPinnedAt))
? Math.floor(Number(rawPinnedAt))
: 0;
const isPinned = pinnedAt > 0;
if (isPinned) {
hasPinned = true;
}
return {
session,
index,
pinnedAt,
isPinned,
match: normalizeSessionMatch(session)
};
});
if (!hasPinned) return decorated.map(item => ({
...item.session,
match: item.match
}));
decorated.sort((a, b) => {
if (a.isPinned !== b.isPinned) return a.isPinned ? -1 : 1;
if (a.isPinned && a.pinnedAt !== b.pinnedAt) return b.pinnedAt - a.pinnedAt;
return a.index - b.index;
});
return decorated.map(item => ({
...item.session,
match: item.match
}));
},
activeSessionVisibleMessages() {
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
return [];
}
const list = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages : [];
const rawCount = Number(this.sessionPreviewVisibleCount);
const visibleCount = Number.isFinite(rawCount)
? Math.max(0, Math.floor(rawCount))
: 0;
if (visibleCount <= 0) {
if (!list.length) return [];
return list.slice(0, Math.min(8, list.length));
}
if (visibleCount >= list.length) return list;
return list.slice(0, visibleCount);
},
canLoadMoreSessionMessages() {
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
return false;
}
const total = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages.length : 0;
const visible = Array.isArray(this.activeSessionVisibleMessages) ? this.activeSessionVisibleMessages.length : 0;
return total > visible;
},
sessionPreviewRemainingCount() {
const total = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages.length : 0;
const visible = Array.isArray(this.activeSessionVisibleMessages) ? this.activeSessionVisibleMessages.length : 0;
return Math.max(0, total - visible);
},
sessionTimelineNodes() {
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
return [];
}
return buildSessionTimelineNodes(this.activeSessionVisibleMessages, {
getKey: (message, index) => this.getRecordRenderKey(message, index)
});
},
sessionTimelineNodeKeyMap() {
const nodes = Array.isArray(this.sessionTimelineNodes) ? this.sessionTimelineNodes : [];
if (!nodes.length) {
return Object.create(null);
}
const map = Object.create(null);
for (const node of nodes) {
if (!node || !node.key) continue;
map[node.key] = true;
}
return map;
},
sessionTimelineActiveTitle() {
if (!this.sessionTimelineActiveKey) return '';
const nodes = Array.isArray(this.sessionTimelineNodes) ? this.sessionTimelineNodes : [];
const matched = nodes.find(node => node.key === this.sessionTimelineActiveKey);
return matched ? matched.title : '';
},
sessionQueryPlaceholder() {
if (this.isSessionQueryEnabled) {
return '关键词检索(支持 Codex/Claude,例:claude code)';
}
return '当前来源暂不支持关键词检索';
},
sessionUsageCharts() {
return buildUsageChartGroups(this.sessionsList, {
range: this.sessionsUsageTimeRange
});
},
sessionUsageSummaryCards() {
const summary = this.sessionUsageCharts && this.sessionUsageCharts.summary
? this.sessionUsageCharts.summary
: { totalSessions: 0, totalMessages: 0, activeDays: 0 };
return [
{ key: 'sessions', label: '总会话数', value: summary.totalSessions || 0 },
{ key: 'messages', label: '总消息数', value: summary.totalMessages || 0 },
{ key: 'days', label: '活跃天数', value: summary.activeDays || 0 }
];
},
visibleSessionTrashItems() {
const items = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems : [];
const visibleCount = Number(this.sessionTrashVisibleCount);
const safeVisibleCount = Number.isFinite(visibleCount) && visibleCount > 0
? Math.floor(visibleCount)
: SESSION_TRASH_PAGE_SIZE;
return items.slice(0, safeVisibleCount);
},
sessionTrashHasMoreItems() {
return this.visibleSessionTrashItems.length < this.sessionTrashCount;
},
sessionTrashHiddenCount() {
return Math.max(0, this.sessionTrashCount - this.visibleSessionTrashItems.length);
},
sessionTrashCount() {
const totalCount = Number(this.sessionTrashTotalCount);
if (Number.isFinite(totalCount) && totalCount >= 0) {
return Math.max(0, Math.floor(totalCount));
}
return Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
}
};
}