codexmate 0.0.39 → 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -156
- package/README.zh.md +168 -156
- package/cli/agents-files.js +230 -230
- package/cli/analytics-export-args.js +68 -68
- package/cli/archive-helpers.js +453 -453
- package/cli/auth-profiles.js +375 -375
- package/cli/builtin-proxy.js +2144 -2144
- package/cli/claude-proxy.js +1022 -1022
- package/cli/config-bootstrap.js +407 -402
- package/cli/config-health.js +454 -454
- package/cli/doctor-core.js +903 -903
- package/cli/import-skills-url.js +356 -356
- package/cli/local-bridge.js +556 -556
- package/cli/openai-bridge.js +1984 -1984
- package/cli/openclaw-config.js +629 -629
- package/cli/session-convert-args.js +69 -69
- package/cli/session-convert-io.js +82 -82
- package/cli/session-convert.js +150 -150
- package/cli/session-usage.concurrent.js +28 -28
- package/cli/session-usage.js +304 -304
- package/cli/session-usage.models.js +176 -176
- package/cli/skills.js +1141 -1141
- package/cli/update.js +171 -171
- package/cli/zip-commands.js +510 -510
- package/cli.js +16458 -16174
- package/lib/automation.js +404 -404
- package/lib/cli-file-utils.js +151 -151
- package/lib/cli-models-utils.js +440 -440
- package/lib/cli-network-utils.js +190 -190
- package/lib/cli-path-utils.js +85 -85
- package/lib/cli-session-utils.js +121 -121
- package/lib/cli-sessions.js +427 -427
- package/lib/cli-utils.js +155 -155
- package/lib/cli-webhook.js +154 -154
- package/lib/download-artifacts.js +92 -92
- package/lib/mcp-stdio.js +453 -453
- package/lib/task-orchestrator.js +869 -869
- package/lib/text-diff.js +303 -303
- package/lib/win-tray.js +119 -119
- package/lib/workflow-engine.js +340 -340
- package/package.json +77 -77
- package/plugins/README.md +20 -20
- package/plugins/README.zh-CN.md +20 -20
- package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
- package/plugins/prompt-templates/computed.mjs +311 -253
- package/plugins/prompt-templates/index.mjs +8 -8
- package/plugins/prompt-templates/manifest.mjs +18 -15
- package/plugins/prompt-templates/methods.mjs +553 -553
- package/plugins/prompt-templates/overview.mjs +91 -91
- package/plugins/prompt-templates/ownership.mjs +19 -19
- package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
- package/plugins/prompt-templates/storage.mjs +64 -64
- package/plugins/registry.mjs +16 -16
- package/web-ui/app.js +695 -693
- package/web-ui/index.html +37 -37
- package/web-ui/logic.agents-diff.mjs +386 -386
- package/web-ui/logic.claude.mjs +172 -172
- package/web-ui/logic.codex.mjs +69 -69
- package/web-ui/logic.mjs +5 -5
- package/web-ui/logic.runtime.mjs +128 -128
- package/web-ui/logic.session-convert.mjs +70 -70
- package/web-ui/logic.sessions.mjs +782 -782
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +252 -252
- package/web-ui/modules/app.computed.index.mjs +17 -17
- package/web-ui/modules/app.computed.main-tabs.mjs +214 -212
- package/web-ui/modules/app.computed.session.mjs +876 -876
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +651 -651
- package/web-ui/modules/app.methods.claude-config.mjs +412 -412
- package/web-ui/modules/app.methods.codex-config.mjs +869 -869
- package/web-ui/modules/app.methods.index.mjs +96 -94
- package/web-ui/modules/app.methods.install.mjs +205 -205
- package/web-ui/modules/app.methods.navigation.mjs +804 -804
- package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
- package/web-ui/modules/app.methods.openclaw-editing.mjs +420 -420
- package/web-ui/modules/app.methods.openclaw-persist.mjs +375 -375
- package/web-ui/modules/app.methods.providers.mjs +601 -601
- package/web-ui/modules/app.methods.runtime.mjs +420 -420
- package/web-ui/modules/app.methods.session-actions.mjs +591 -591
- package/web-ui/modules/app.methods.session-browser.mjs +1018 -1018
- package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
- package/web-ui/modules/app.methods.session-trash.mjs +468 -468
- package/web-ui/modules/app.methods.startup-claude.mjs +554 -548
- package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
- package/web-ui/modules/app.methods.tool-config-permissions.mjs +87 -0
- package/web-ui/modules/app.methods.webhook.mjs +87 -87
- package/web-ui/modules/config-mode.computed.mjs +124 -124
- package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
- package/web-ui/modules/i18n/locales/en.mjs +1140 -0
- package/web-ui/modules/i18n/locales/ja.mjs +1130 -0
- package/web-ui/modules/i18n/locales/vi.mjs +239 -0
- package/web-ui/modules/i18n/locales/zh.mjs +1143 -0
- package/web-ui/modules/i18n.dict.mjs +14 -3213
- package/web-ui/modules/i18n.mjs +111 -111
- package/web-ui/modules/plugins.computed.mjs +3 -3
- package/web-ui/modules/plugins.methods.mjs +3 -3
- package/web-ui/modules/plugins.storage.mjs +11 -11
- package/web-ui/modules/provider-url-display.mjs +17 -17
- package/web-ui/modules/sessions-filters-url.mjs +138 -138
- package/web-ui/modules/skills.computed.mjs +107 -107
- package/web-ui/modules/skills.methods.mjs +513 -513
- package/web-ui/partials/index/layout-footer.html +13 -13
- package/web-ui/partials/index/layout-header.html +478 -478
- package/web-ui/partials/index/modal-config-template-agents.html +185 -185
- package/web-ui/partials/index/modal-confirm-toast.html +32 -32
- package/web-ui/partials/index/modal-health-check.html +45 -45
- package/web-ui/partials/index/modal-openclaw-config.html +344 -344
- package/web-ui/partials/index/modal-skills.html +200 -200
- package/web-ui/partials/index/modal-webhook.html +42 -42
- package/web-ui/partials/index/modals-basic.html +263 -263
- package/web-ui/partials/index/panel-config-claude.html +187 -157
- package/web-ui/partials/index/panel-config-codex.html +205 -176
- package/web-ui/partials/index/panel-config-openclaw.html +89 -89
- package/web-ui/partials/index/panel-dashboard.html +171 -171
- package/web-ui/partials/index/panel-docs.html +114 -114
- package/web-ui/partials/index/panel-market.html +104 -104
- package/web-ui/partials/index/panel-orchestration.html +391 -391
- package/web-ui/partials/index/panel-plugins.html +253 -253
- package/web-ui/partials/index/panel-sessions.html +319 -319
- package/web-ui/partials/index/panel-settings.html +181 -181
- package/web-ui/partials/index/panel-trash.html +82 -82
- package/web-ui/partials/index/panel-usage.html +181 -181
- package/web-ui/res/json5.min.js +1 -1
- package/web-ui/res/vue.global.prod.js +13 -13
- package/web-ui/res/vue.runtime.global.prod.js +7 -7
- package/web-ui/res/web-ui-render.precompiled.js +7666 -7576
- package/web-ui/session-helpers.mjs +602 -602
- package/web-ui/source-bundle.cjs +305 -305
- package/web-ui/styles/base-theme.css +291 -291
- package/web-ui/styles/bridge-pool.css +266 -266
- package/web-ui/styles/controls-forms.css +532 -439
- package/web-ui/styles/dashboard.css +438 -438
- package/web-ui/styles/docs-panel.css +245 -245
- package/web-ui/styles/feedback.css +108 -108
- package/web-ui/styles/health-check-dialog.css +144 -144
- package/web-ui/styles/layout-shell.css +711 -711
- package/web-ui/styles/modals-core.css +499 -499
- package/web-ui/styles/navigation-panels.css +399 -399
- package/web-ui/styles/openclaw-structured.css +616 -616
- package/web-ui/styles/plugins-panel.css +564 -564
- package/web-ui/styles/responsive.css +501 -501
- package/web-ui/styles/sessions-list.css +683 -683
- package/web-ui/styles/sessions-preview.css +407 -407
- package/web-ui/styles/sessions-toolbar-trash.css +518 -518
- package/web-ui/styles/sessions-usage.css +849 -849
- package/web-ui/styles/settings-panel.css +419 -419
- package/web-ui/styles/skills-list.css +305 -305
- package/web-ui/styles/skills-market.css +723 -723
- package/web-ui/styles/task-orchestration.css +822 -822
- package/web-ui/styles/titles-cards.css +486 -486
- package/web-ui/styles/trash-panel.css +90 -90
- package/web-ui/styles/webhook.css +115 -115
- package/web-ui/styles.css +24 -24
- package/web-ui.html +17 -17
|
@@ -1,468 +1,468 @@
|
|
|
1
|
-
export function createSessionTrashMethods(options = {}) {
|
|
2
|
-
const {
|
|
3
|
-
api,
|
|
4
|
-
sessionTrashListLimit = 500,
|
|
5
|
-
sessionTrashPageSize = 200
|
|
6
|
-
} = options;
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
buildSessionTrashItemFromSession(session, result = {}) {
|
|
10
|
-
const deletedAt = typeof result.deletedAt === 'string' && result.deletedAt
|
|
11
|
-
? result.deletedAt
|
|
12
|
-
: new Date().toISOString();
|
|
13
|
-
const source = session && (session.source === 'claude' || session.source === 'gemini')
|
|
14
|
-
? session.source
|
|
15
|
-
: 'codex';
|
|
16
|
-
return {
|
|
17
|
-
trashId: typeof result.trashId === 'string' ? result.trashId : '',
|
|
18
|
-
source,
|
|
19
|
-
sourceLabel: session && typeof session.sourceLabel === 'string' && session.sourceLabel
|
|
20
|
-
? session.sourceLabel
|
|
21
|
-
: (source === 'claude' ? 'Claude Code' : (source === 'gemini' ? 'Gemini CLI' : 'Codex')),
|
|
22
|
-
sessionId: session && typeof session.sessionId === 'string' ? session.sessionId : '',
|
|
23
|
-
title: session && typeof session.title === 'string' && session.title
|
|
24
|
-
? session.title
|
|
25
|
-
: (session && typeof session.sessionId === 'string' ? session.sessionId : ''),
|
|
26
|
-
cwd: session && typeof session.cwd === 'string' ? session.cwd : '',
|
|
27
|
-
createdAt: session && typeof session.createdAt === 'string' ? session.createdAt : '',
|
|
28
|
-
updatedAt: session && typeof session.updatedAt === 'string' ? session.updatedAt : '',
|
|
29
|
-
deletedAt,
|
|
30
|
-
messageCount: Number.isFinite(Number(result && result.messageCount))
|
|
31
|
-
? Math.max(0, Math.floor(Number(result.messageCount)))
|
|
32
|
-
: (Number.isFinite(Number(session && session.messageCount))
|
|
33
|
-
? Math.max(0, Math.floor(Number(session.messageCount)))
|
|
34
|
-
: 0),
|
|
35
|
-
originalFilePath: session && typeof session.filePath === 'string' ? session.filePath : '',
|
|
36
|
-
provider: session && typeof session.provider === 'string' ? session.provider : source,
|
|
37
|
-
keywords: Array.isArray(session && session.keywords) ? session.keywords : [],
|
|
38
|
-
capabilities: session && typeof session.capabilities === 'object' && session.capabilities
|
|
39
|
-
? session.capabilities
|
|
40
|
-
: {},
|
|
41
|
-
claudeIndexPath: '',
|
|
42
|
-
claudeIndexEntry: null,
|
|
43
|
-
trashFilePath: ''
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
prependSessionTrashItem(item, options = {}) {
|
|
48
|
-
if (!item || !item.trashId) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const existing = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems : [];
|
|
52
|
-
const filtered = existing.filter((entry) => this.getSessionTrashActionKey(entry) !== item.trashId);
|
|
53
|
-
const nextItems = [item, ...filtered].slice(0, sessionTrashListLimit);
|
|
54
|
-
const previousTotalCount = Number(this.sessionTrashTotalCount);
|
|
55
|
-
const normalizedPreviousTotal = Number.isFinite(previousTotalCount) && previousTotalCount >= 0
|
|
56
|
-
? Math.max(existing.length, Math.floor(previousTotalCount))
|
|
57
|
-
: existing.length;
|
|
58
|
-
this.sessionTrashItems = nextItems;
|
|
59
|
-
const previousVisibleCount = Number(this.sessionTrashVisibleCount);
|
|
60
|
-
const normalizedPreviousVisibleCount = Number.isFinite(previousVisibleCount) && previousVisibleCount > 0
|
|
61
|
-
? Math.floor(previousVisibleCount)
|
|
62
|
-
: sessionTrashPageSize;
|
|
63
|
-
const wasFullyExpanded = normalizedPreviousVisibleCount >= existing.length
|
|
64
|
-
|| normalizedPreviousVisibleCount >= normalizedPreviousTotal;
|
|
65
|
-
if (wasFullyExpanded) {
|
|
66
|
-
this.sessionTrashVisibleCount = Math.min(
|
|
67
|
-
normalizedPreviousVisibleCount + 1,
|
|
68
|
-
nextItems.length || (normalizedPreviousVisibleCount + 1)
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
const fallbackTotalCount = filtered.length === existing.length
|
|
72
|
-
? normalizedPreviousTotal + 1
|
|
73
|
-
: normalizedPreviousTotal;
|
|
74
|
-
this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
|
|
75
|
-
options && options.totalCount !== undefined
|
|
76
|
-
? options.totalCount
|
|
77
|
-
: fallbackTotalCount,
|
|
78
|
-
nextItems
|
|
79
|
-
);
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
normalizeSessionTrashTotalCount(totalCount, fallbackItems = this.sessionTrashItems) {
|
|
83
|
-
const fallbackCount = Array.isArray(fallbackItems) ? fallbackItems.length : 0;
|
|
84
|
-
const numericTotal = Number(totalCount);
|
|
85
|
-
if (!Number.isFinite(numericTotal) || numericTotal < 0) {
|
|
86
|
-
return fallbackCount;
|
|
87
|
-
}
|
|
88
|
-
return Math.floor(numericTotal);
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
getSessionTrashViewState() {
|
|
92
|
-
if (this.sessionTrashLoading && !this.sessionTrashLoadedOnce) {
|
|
93
|
-
return 'loading';
|
|
94
|
-
}
|
|
95
|
-
const totalCount = Number(this.sessionTrashCount);
|
|
96
|
-
const normalizedTotalCount = Number.isFinite(totalCount) && totalCount >= 0
|
|
97
|
-
? Math.floor(totalCount)
|
|
98
|
-
: 0;
|
|
99
|
-
const hasVisibleItems = Array.isArray(this.sessionTrashItems) && this.sessionTrashItems.length > 0;
|
|
100
|
-
if (this.sessionTrashLastLoadFailed && (!this.sessionTrashLoadedOnce || !hasVisibleItems)) {
|
|
101
|
-
return 'retry';
|
|
102
|
-
}
|
|
103
|
-
if (!this.sessionTrashLoadedOnce) {
|
|
104
|
-
return normalizedTotalCount > 0 ? 'retry' : 'empty';
|
|
105
|
-
}
|
|
106
|
-
if (normalizedTotalCount === 0) {
|
|
107
|
-
return 'empty';
|
|
108
|
-
}
|
|
109
|
-
return hasVisibleItems ? 'list' : 'retry';
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
issueSessionTrashCountRequestToken() {
|
|
113
|
-
const currentToken = Number(this.sessionTrashCountRequestToken);
|
|
114
|
-
const nextToken = Number.isFinite(currentToken) && currentToken >= 0
|
|
115
|
-
? Math.floor(currentToken) + 1
|
|
116
|
-
: 1;
|
|
117
|
-
this.sessionTrashCountRequestToken = nextToken;
|
|
118
|
-
return nextToken;
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
issueSessionTrashListRequestToken() {
|
|
122
|
-
const currentToken = Number(this.sessionTrashListRequestToken);
|
|
123
|
-
const nextToken = Number.isFinite(currentToken) && currentToken >= 0
|
|
124
|
-
? Math.floor(currentToken) + 1
|
|
125
|
-
: 1;
|
|
126
|
-
this.sessionTrashListRequestToken = nextToken;
|
|
127
|
-
return nextToken;
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
invalidateSessionTrashRequests() {
|
|
131
|
-
this.issueSessionTrashCountRequestToken();
|
|
132
|
-
return this.issueSessionTrashListRequestToken();
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
isLatestSessionTrashCountRequestToken(token) {
|
|
136
|
-
return Number(token) === Number(this.sessionTrashCountRequestToken);
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
isLatestSessionTrashListRequestToken(token) {
|
|
140
|
-
return Number(token) === Number(this.sessionTrashListRequestToken);
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
resetSessionTrashVisibleCount() {
|
|
144
|
-
const totalItems = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
|
|
145
|
-
this.sessionTrashVisibleCount = Math.min(totalItems, sessionTrashPageSize) || sessionTrashPageSize;
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
loadMoreSessionTrashItems() {
|
|
149
|
-
const totalItems = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
|
|
150
|
-
const visibleCount = Number(this.sessionTrashVisibleCount);
|
|
151
|
-
const safeVisibleCount = Number.isFinite(visibleCount) && visibleCount > 0
|
|
152
|
-
? Math.floor(visibleCount)
|
|
153
|
-
: sessionTrashPageSize;
|
|
154
|
-
this.sessionTrashVisibleCount = Math.min(totalItems, safeVisibleCount + sessionTrashPageSize);
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
clearActiveSessionState() {
|
|
158
|
-
this.activeSession = null;
|
|
159
|
-
this.activeSessionMessages = [];
|
|
160
|
-
this.resetSessionDetailPagination();
|
|
161
|
-
this.resetSessionPreviewMessageRender();
|
|
162
|
-
this.activeSessionDetailError = '';
|
|
163
|
-
this.activeSessionDetailClipped = false;
|
|
164
|
-
this.cancelSessionTimelineSync();
|
|
165
|
-
this.sessionTimelineActiveKey = '';
|
|
166
|
-
this.clearSessionTimelineRefs();
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
async removeSessionFromCurrentList(session) {
|
|
170
|
-
const sessionKey = this.getSessionExportKey(session);
|
|
171
|
-
if (!sessionKey) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const currentList = Array.isArray(this.sessionsList) ? [...this.sessionsList] : [];
|
|
175
|
-
const removedIndex = currentList.findIndex((item) => this.getSessionExportKey(item) === sessionKey);
|
|
176
|
-
if (removedIndex < 0) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const activeKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
|
|
180
|
-
const renderedList = Array.isArray(this.sortedSessionsList) ? this.sortedSessionsList : [];
|
|
181
|
-
const renderedIndex = renderedList.findIndex((item) => this.getSessionExportKey(item) === sessionKey);
|
|
182
|
-
let nextActiveKey = '';
|
|
183
|
-
if (activeKey === sessionKey && renderedIndex >= 0) {
|
|
184
|
-
const fallbackSession = renderedList[renderedIndex - 1] || renderedList[renderedIndex + 1] || null;
|
|
185
|
-
nextActiveKey = fallbackSession ? this.getSessionExportKey(fallbackSession) : '';
|
|
186
|
-
}
|
|
187
|
-
currentList.splice(removedIndex, 1);
|
|
188
|
-
this.sessionsList = currentList;
|
|
189
|
-
this.syncSessionPathOptionsForSource(
|
|
190
|
-
this.sessionFilterSource,
|
|
191
|
-
this.extractPathOptionsFromSessions(currentList),
|
|
192
|
-
false
|
|
193
|
-
);
|
|
194
|
-
if (activeKey !== sessionKey) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
if (currentList.length === 0) {
|
|
198
|
-
this.clearActiveSessionState();
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const nextSession = currentList.find((item) => this.getSessionExportKey(item) === nextActiveKey)
|
|
202
|
-
|| currentList[Math.min(removedIndex, currentList.length - 1)];
|
|
203
|
-
if (!nextSession) {
|
|
204
|
-
this.clearActiveSessionState();
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
await this.selectSession(nextSession);
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
normalizeSettingsTab(tab) {
|
|
211
|
-
if (tab === 'general' || tab === 'data') {
|
|
212
|
-
return tab;
|
|
213
|
-
}
|
|
214
|
-
return 'general';
|
|
215
|
-
},
|
|
216
|
-
|
|
217
|
-
async onSettingsTabClick(tab) {
|
|
218
|
-
await this.switchSettingsTab(tab);
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
async onSettingsTabKeydown(event, tab) {
|
|
222
|
-
if (!event) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
const tabs = ['general', 'data'];
|
|
226
|
-
const currentTab = this.normalizeSettingsTab(tab || this.settingsTab);
|
|
227
|
-
const currentIndex = Math.max(0, tabs.indexOf(currentTab));
|
|
228
|
-
let nextIndex = currentIndex;
|
|
229
|
-
if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {
|
|
230
|
-
nextIndex = (currentIndex + 1) % tabs.length;
|
|
231
|
-
} else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {
|
|
232
|
-
nextIndex = (currentIndex - 1 + tabs.length) % tabs.length;
|
|
233
|
-
} else if (event.key === 'Home') {
|
|
234
|
-
nextIndex = 0;
|
|
235
|
-
} else if (event.key === 'End') {
|
|
236
|
-
nextIndex = tabs.length - 1;
|
|
237
|
-
} else {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
event.preventDefault();
|
|
241
|
-
const nextTab = tabs[nextIndex];
|
|
242
|
-
await this.switchSettingsTab(nextTab);
|
|
243
|
-
const target = typeof document !== 'undefined'
|
|
244
|
-
? document.getElementById(`settings-tab-${nextTab}`)
|
|
245
|
-
: null;
|
|
246
|
-
if (target && typeof target.focus === 'function') {
|
|
247
|
-
target.focus();
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
|
|
251
|
-
async switchSettingsTab(tab, options = {}) {
|
|
252
|
-
const nextTab = this.normalizeSettingsTab(tab);
|
|
253
|
-
this.settingsTab = nextTab;
|
|
254
|
-
if (typeof this.saveNavState === 'function') {
|
|
255
|
-
this.saveNavState();
|
|
256
|
-
}
|
|
257
|
-
if (nextTab !== 'data') {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
|
|
262
|
-
async loadSessionTrashCount(options = {}) {
|
|
263
|
-
if (this.sessionTrashCountLoading) {
|
|
264
|
-
this.sessionTrashCountPendingOptions = {
|
|
265
|
-
...(this.sessionTrashCountPendingOptions || {}),
|
|
266
|
-
...(options || {})
|
|
267
|
-
};
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
const requestToken = this.issueSessionTrashCountRequestToken();
|
|
271
|
-
this.sessionTrashCountLoading = true;
|
|
272
|
-
try {
|
|
273
|
-
const res = await api('list-session-trash', { countOnly: true });
|
|
274
|
-
if (!this.isLatestSessionTrashCountRequestToken(requestToken)) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
if (res.error) {
|
|
278
|
-
if (options.silent !== true) {
|
|
279
|
-
this.showMessage(res.error, 'error');
|
|
280
|
-
}
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
|
|
284
|
-
res.totalCount,
|
|
285
|
-
this.sessionTrashItems
|
|
286
|
-
);
|
|
287
|
-
this.sessionTrashCountLoadedOnce = true;
|
|
288
|
-
} catch (e) {
|
|
289
|
-
if (this.isLatestSessionTrashCountRequestToken(requestToken) && options.silent !== true) {
|
|
290
|
-
this.showMessage('加载回收站数量失败', 'error');
|
|
291
|
-
}
|
|
292
|
-
} finally {
|
|
293
|
-
this.sessionTrashCountLoading = false;
|
|
294
|
-
const pendingOptions = this.sessionTrashCountPendingOptions;
|
|
295
|
-
this.sessionTrashCountPendingOptions = null;
|
|
296
|
-
if (pendingOptions) {
|
|
297
|
-
await this.loadSessionTrashCount(pendingOptions);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
|
-
|
|
302
|
-
normalizeSessionTrashRetentionDays(value) {
|
|
303
|
-
const numeric = Number(value);
|
|
304
|
-
if (!Number.isFinite(numeric) || numeric < 1) {
|
|
305
|
-
return 30;
|
|
306
|
-
}
|
|
307
|
-
return Math.min(365, Math.max(1, Math.floor(numeric)));
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
setSessionTrashRetentionDays(days) {
|
|
311
|
-
const normalized = this.normalizeSessionTrashRetentionDays(days);
|
|
312
|
-
this.sessionTrashRetentionDays = normalized;
|
|
313
|
-
try { localStorage.setItem('codexmateSessionTrashRetentionDays', String(normalized)); } catch (_) {}
|
|
314
|
-
},
|
|
315
|
-
|
|
316
|
-
getSessionTrashActionKey(item) {
|
|
317
|
-
return item && typeof item.trashId === 'string' ? item.trashId : '';
|
|
318
|
-
},
|
|
319
|
-
|
|
320
|
-
isSessionTrashActionBusy(item) {
|
|
321
|
-
const key = typeof item === 'string' ? item : this.getSessionTrashActionKey(item);
|
|
322
|
-
return !!(key && (this.sessionTrashRestoring[key] || this.sessionTrashPurging[key]));
|
|
323
|
-
},
|
|
324
|
-
|
|
325
|
-
async loadSessionTrash(options = {}) {
|
|
326
|
-
if (this.sessionTrashLoading) {
|
|
327
|
-
this.sessionTrashPendingOptions = {
|
|
328
|
-
...(this.sessionTrashPendingOptions || {}),
|
|
329
|
-
...(options || {})
|
|
330
|
-
};
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
const requestToken = this.issueSessionTrashListRequestToken();
|
|
334
|
-
this.sessionTrashLoading = true;
|
|
335
|
-
this.sessionTrashLastLoadFailed = false;
|
|
336
|
-
let loadSucceeded = false;
|
|
337
|
-
try {
|
|
338
|
-
const res = await api('list-session-trash', {
|
|
339
|
-
limit: sessionTrashListLimit,
|
|
340
|
-
forceRefresh: !!options.forceRefresh,
|
|
341
|
-
retentionDays: this.sessionTrashRetentionDays
|
|
342
|
-
});
|
|
343
|
-
if (!this.isLatestSessionTrashListRequestToken(requestToken)) {
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
if (res.error) {
|
|
347
|
-
this.sessionTrashLastLoadFailed = true;
|
|
348
|
-
this.showMessage(res.error, 'error');
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
const nextItems = Array.isArray(res.items) ? res.items : [];
|
|
352
|
-
this.sessionTrashItems = nextItems;
|
|
353
|
-
this.resetSessionTrashVisibleCount();
|
|
354
|
-
this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(res.totalCount, nextItems);
|
|
355
|
-
this.sessionTrashCountLoadedOnce = true;
|
|
356
|
-
this.sessionTrashLastLoadFailed = false;
|
|
357
|
-
loadSucceeded = true;
|
|
358
|
-
} catch (e) {
|
|
359
|
-
if (this.isLatestSessionTrashListRequestToken(requestToken)) {
|
|
360
|
-
this.sessionTrashLastLoadFailed = true;
|
|
361
|
-
this.showMessage('加载回收站失败', 'error');
|
|
362
|
-
}
|
|
363
|
-
} finally {
|
|
364
|
-
this.sessionTrashLoading = false;
|
|
365
|
-
if (loadSucceeded) {
|
|
366
|
-
this.sessionTrashLoadedOnce = true;
|
|
367
|
-
}
|
|
368
|
-
const pendingOptions = this.sessionTrashPendingOptions;
|
|
369
|
-
this.sessionTrashPendingOptions = null;
|
|
370
|
-
if (pendingOptions) {
|
|
371
|
-
await this.loadSessionTrash(pendingOptions);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
},
|
|
375
|
-
|
|
376
|
-
async restoreSessionTrash(item) {
|
|
377
|
-
const key = this.getSessionTrashActionKey(item);
|
|
378
|
-
if (!key || this.isSessionTrashActionBusy(key) || this.sessionTrashClearing) {
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
this.sessionTrashRestoring[key] = true;
|
|
382
|
-
try {
|
|
383
|
-
const res = await api('restore-session-trash', { trashId: key });
|
|
384
|
-
if (res.error) {
|
|
385
|
-
this.showMessage(res.error, 'error');
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
this.showMessage('会话已恢复', 'success');
|
|
389
|
-
if (typeof this.invalidateSessionsUsageData === 'function') {
|
|
390
|
-
this.invalidateSessionsUsageData({ preserveList: true });
|
|
391
|
-
}
|
|
392
|
-
this.invalidateSessionTrashRequests();
|
|
393
|
-
await this.loadSessionTrash({ forceRefresh: true });
|
|
394
|
-
if (this.sessionsLoadedOnce) {
|
|
395
|
-
await this.loadSessions();
|
|
396
|
-
}
|
|
397
|
-
} catch (e) {
|
|
398
|
-
this.showMessage('恢复失败', 'error');
|
|
399
|
-
} finally {
|
|
400
|
-
this.sessionTrashRestoring[key] = false;
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
|
|
404
|
-
async purgeSessionTrash(item) {
|
|
405
|
-
const key = this.getSessionTrashActionKey(item);
|
|
406
|
-
if (!key || this.isSessionTrashActionBusy(key) || this.sessionTrashClearing) {
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
const confirmed = await this.requestConfirmDialog({
|
|
410
|
-
title: '彻底删除回收站记录',
|
|
411
|
-
message: '该会话将从回收站永久删除,且无法恢复。',
|
|
412
|
-
confirmText: '彻底删除',
|
|
413
|
-
cancelText: '取消',
|
|
414
|
-
danger: true
|
|
415
|
-
});
|
|
416
|
-
if (!confirmed) {
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
this.sessionTrashPurging[key] = true;
|
|
420
|
-
try {
|
|
421
|
-
const res = await api('purge-session-trash', { trashId: key });
|
|
422
|
-
if (res.error) {
|
|
423
|
-
this.showMessage(res.error, 'error');
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
this.showMessage('已彻底删除', 'success');
|
|
427
|
-
this.invalidateSessionTrashRequests();
|
|
428
|
-
await this.loadSessionTrash({ forceRefresh: true });
|
|
429
|
-
} catch (e) {
|
|
430
|
-
this.showMessage('彻底删除失败', 'error');
|
|
431
|
-
} finally {
|
|
432
|
-
this.sessionTrashPurging[key] = false;
|
|
433
|
-
}
|
|
434
|
-
},
|
|
435
|
-
|
|
436
|
-
async clearSessionTrash() {
|
|
437
|
-
const normalizedCount = Number(this.sessionTrashCount);
|
|
438
|
-
if (this.sessionTrashClearing || !Number.isFinite(normalizedCount) || normalizedCount <= 0) {
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
const confirmed = await this.requestConfirmDialog({
|
|
442
|
-
title: '清空回收站',
|
|
443
|
-
message: '该操作会永久删除回收站中的全部会话,且无法恢复。',
|
|
444
|
-
confirmText: '全部清空',
|
|
445
|
-
cancelText: '取消',
|
|
446
|
-
danger: true
|
|
447
|
-
});
|
|
448
|
-
if (!confirmed) {
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
this.sessionTrashClearing = true;
|
|
452
|
-
try {
|
|
453
|
-
const res = await api('purge-session-trash', { all: true });
|
|
454
|
-
if (res.error) {
|
|
455
|
-
this.showMessage(res.error, 'error');
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
this.showMessage('回收站已清空', 'success');
|
|
459
|
-
this.invalidateSessionTrashRequests();
|
|
460
|
-
await this.loadSessionTrash({ forceRefresh: true });
|
|
461
|
-
} catch (e) {
|
|
462
|
-
this.showMessage('清空回收站失败', 'error');
|
|
463
|
-
} finally {
|
|
464
|
-
this.sessionTrashClearing = false;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
}
|
|
1
|
+
export function createSessionTrashMethods(options = {}) {
|
|
2
|
+
const {
|
|
3
|
+
api,
|
|
4
|
+
sessionTrashListLimit = 500,
|
|
5
|
+
sessionTrashPageSize = 200
|
|
6
|
+
} = options;
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
buildSessionTrashItemFromSession(session, result = {}) {
|
|
10
|
+
const deletedAt = typeof result.deletedAt === 'string' && result.deletedAt
|
|
11
|
+
? result.deletedAt
|
|
12
|
+
: new Date().toISOString();
|
|
13
|
+
const source = session && (session.source === 'claude' || session.source === 'gemini')
|
|
14
|
+
? session.source
|
|
15
|
+
: 'codex';
|
|
16
|
+
return {
|
|
17
|
+
trashId: typeof result.trashId === 'string' ? result.trashId : '',
|
|
18
|
+
source,
|
|
19
|
+
sourceLabel: session && typeof session.sourceLabel === 'string' && session.sourceLabel
|
|
20
|
+
? session.sourceLabel
|
|
21
|
+
: (source === 'claude' ? 'Claude Code' : (source === 'gemini' ? 'Gemini CLI' : 'Codex')),
|
|
22
|
+
sessionId: session && typeof session.sessionId === 'string' ? session.sessionId : '',
|
|
23
|
+
title: session && typeof session.title === 'string' && session.title
|
|
24
|
+
? session.title
|
|
25
|
+
: (session && typeof session.sessionId === 'string' ? session.sessionId : ''),
|
|
26
|
+
cwd: session && typeof session.cwd === 'string' ? session.cwd : '',
|
|
27
|
+
createdAt: session && typeof session.createdAt === 'string' ? session.createdAt : '',
|
|
28
|
+
updatedAt: session && typeof session.updatedAt === 'string' ? session.updatedAt : '',
|
|
29
|
+
deletedAt,
|
|
30
|
+
messageCount: Number.isFinite(Number(result && result.messageCount))
|
|
31
|
+
? Math.max(0, Math.floor(Number(result.messageCount)))
|
|
32
|
+
: (Number.isFinite(Number(session && session.messageCount))
|
|
33
|
+
? Math.max(0, Math.floor(Number(session.messageCount)))
|
|
34
|
+
: 0),
|
|
35
|
+
originalFilePath: session && typeof session.filePath === 'string' ? session.filePath : '',
|
|
36
|
+
provider: session && typeof session.provider === 'string' ? session.provider : source,
|
|
37
|
+
keywords: Array.isArray(session && session.keywords) ? session.keywords : [],
|
|
38
|
+
capabilities: session && typeof session.capabilities === 'object' && session.capabilities
|
|
39
|
+
? session.capabilities
|
|
40
|
+
: {},
|
|
41
|
+
claudeIndexPath: '',
|
|
42
|
+
claudeIndexEntry: null,
|
|
43
|
+
trashFilePath: ''
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
prependSessionTrashItem(item, options = {}) {
|
|
48
|
+
if (!item || !item.trashId) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const existing = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems : [];
|
|
52
|
+
const filtered = existing.filter((entry) => this.getSessionTrashActionKey(entry) !== item.trashId);
|
|
53
|
+
const nextItems = [item, ...filtered].slice(0, sessionTrashListLimit);
|
|
54
|
+
const previousTotalCount = Number(this.sessionTrashTotalCount);
|
|
55
|
+
const normalizedPreviousTotal = Number.isFinite(previousTotalCount) && previousTotalCount >= 0
|
|
56
|
+
? Math.max(existing.length, Math.floor(previousTotalCount))
|
|
57
|
+
: existing.length;
|
|
58
|
+
this.sessionTrashItems = nextItems;
|
|
59
|
+
const previousVisibleCount = Number(this.sessionTrashVisibleCount);
|
|
60
|
+
const normalizedPreviousVisibleCount = Number.isFinite(previousVisibleCount) && previousVisibleCount > 0
|
|
61
|
+
? Math.floor(previousVisibleCount)
|
|
62
|
+
: sessionTrashPageSize;
|
|
63
|
+
const wasFullyExpanded = normalizedPreviousVisibleCount >= existing.length
|
|
64
|
+
|| normalizedPreviousVisibleCount >= normalizedPreviousTotal;
|
|
65
|
+
if (wasFullyExpanded) {
|
|
66
|
+
this.sessionTrashVisibleCount = Math.min(
|
|
67
|
+
normalizedPreviousVisibleCount + 1,
|
|
68
|
+
nextItems.length || (normalizedPreviousVisibleCount + 1)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
const fallbackTotalCount = filtered.length === existing.length
|
|
72
|
+
? normalizedPreviousTotal + 1
|
|
73
|
+
: normalizedPreviousTotal;
|
|
74
|
+
this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
|
|
75
|
+
options && options.totalCount !== undefined
|
|
76
|
+
? options.totalCount
|
|
77
|
+
: fallbackTotalCount,
|
|
78
|
+
nextItems
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
normalizeSessionTrashTotalCount(totalCount, fallbackItems = this.sessionTrashItems) {
|
|
83
|
+
const fallbackCount = Array.isArray(fallbackItems) ? fallbackItems.length : 0;
|
|
84
|
+
const numericTotal = Number(totalCount);
|
|
85
|
+
if (!Number.isFinite(numericTotal) || numericTotal < 0) {
|
|
86
|
+
return fallbackCount;
|
|
87
|
+
}
|
|
88
|
+
return Math.floor(numericTotal);
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
getSessionTrashViewState() {
|
|
92
|
+
if (this.sessionTrashLoading && !this.sessionTrashLoadedOnce) {
|
|
93
|
+
return 'loading';
|
|
94
|
+
}
|
|
95
|
+
const totalCount = Number(this.sessionTrashCount);
|
|
96
|
+
const normalizedTotalCount = Number.isFinite(totalCount) && totalCount >= 0
|
|
97
|
+
? Math.floor(totalCount)
|
|
98
|
+
: 0;
|
|
99
|
+
const hasVisibleItems = Array.isArray(this.sessionTrashItems) && this.sessionTrashItems.length > 0;
|
|
100
|
+
if (this.sessionTrashLastLoadFailed && (!this.sessionTrashLoadedOnce || !hasVisibleItems)) {
|
|
101
|
+
return 'retry';
|
|
102
|
+
}
|
|
103
|
+
if (!this.sessionTrashLoadedOnce) {
|
|
104
|
+
return normalizedTotalCount > 0 ? 'retry' : 'empty';
|
|
105
|
+
}
|
|
106
|
+
if (normalizedTotalCount === 0) {
|
|
107
|
+
return 'empty';
|
|
108
|
+
}
|
|
109
|
+
return hasVisibleItems ? 'list' : 'retry';
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
issueSessionTrashCountRequestToken() {
|
|
113
|
+
const currentToken = Number(this.sessionTrashCountRequestToken);
|
|
114
|
+
const nextToken = Number.isFinite(currentToken) && currentToken >= 0
|
|
115
|
+
? Math.floor(currentToken) + 1
|
|
116
|
+
: 1;
|
|
117
|
+
this.sessionTrashCountRequestToken = nextToken;
|
|
118
|
+
return nextToken;
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
issueSessionTrashListRequestToken() {
|
|
122
|
+
const currentToken = Number(this.sessionTrashListRequestToken);
|
|
123
|
+
const nextToken = Number.isFinite(currentToken) && currentToken >= 0
|
|
124
|
+
? Math.floor(currentToken) + 1
|
|
125
|
+
: 1;
|
|
126
|
+
this.sessionTrashListRequestToken = nextToken;
|
|
127
|
+
return nextToken;
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
invalidateSessionTrashRequests() {
|
|
131
|
+
this.issueSessionTrashCountRequestToken();
|
|
132
|
+
return this.issueSessionTrashListRequestToken();
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
isLatestSessionTrashCountRequestToken(token) {
|
|
136
|
+
return Number(token) === Number(this.sessionTrashCountRequestToken);
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
isLatestSessionTrashListRequestToken(token) {
|
|
140
|
+
return Number(token) === Number(this.sessionTrashListRequestToken);
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
resetSessionTrashVisibleCount() {
|
|
144
|
+
const totalItems = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
|
|
145
|
+
this.sessionTrashVisibleCount = Math.min(totalItems, sessionTrashPageSize) || sessionTrashPageSize;
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
loadMoreSessionTrashItems() {
|
|
149
|
+
const totalItems = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
|
|
150
|
+
const visibleCount = Number(this.sessionTrashVisibleCount);
|
|
151
|
+
const safeVisibleCount = Number.isFinite(visibleCount) && visibleCount > 0
|
|
152
|
+
? Math.floor(visibleCount)
|
|
153
|
+
: sessionTrashPageSize;
|
|
154
|
+
this.sessionTrashVisibleCount = Math.min(totalItems, safeVisibleCount + sessionTrashPageSize);
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
clearActiveSessionState() {
|
|
158
|
+
this.activeSession = null;
|
|
159
|
+
this.activeSessionMessages = [];
|
|
160
|
+
this.resetSessionDetailPagination();
|
|
161
|
+
this.resetSessionPreviewMessageRender();
|
|
162
|
+
this.activeSessionDetailError = '';
|
|
163
|
+
this.activeSessionDetailClipped = false;
|
|
164
|
+
this.cancelSessionTimelineSync();
|
|
165
|
+
this.sessionTimelineActiveKey = '';
|
|
166
|
+
this.clearSessionTimelineRefs();
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
async removeSessionFromCurrentList(session) {
|
|
170
|
+
const sessionKey = this.getSessionExportKey(session);
|
|
171
|
+
if (!sessionKey) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const currentList = Array.isArray(this.sessionsList) ? [...this.sessionsList] : [];
|
|
175
|
+
const removedIndex = currentList.findIndex((item) => this.getSessionExportKey(item) === sessionKey);
|
|
176
|
+
if (removedIndex < 0) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const activeKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
|
|
180
|
+
const renderedList = Array.isArray(this.sortedSessionsList) ? this.sortedSessionsList : [];
|
|
181
|
+
const renderedIndex = renderedList.findIndex((item) => this.getSessionExportKey(item) === sessionKey);
|
|
182
|
+
let nextActiveKey = '';
|
|
183
|
+
if (activeKey === sessionKey && renderedIndex >= 0) {
|
|
184
|
+
const fallbackSession = renderedList[renderedIndex - 1] || renderedList[renderedIndex + 1] || null;
|
|
185
|
+
nextActiveKey = fallbackSession ? this.getSessionExportKey(fallbackSession) : '';
|
|
186
|
+
}
|
|
187
|
+
currentList.splice(removedIndex, 1);
|
|
188
|
+
this.sessionsList = currentList;
|
|
189
|
+
this.syncSessionPathOptionsForSource(
|
|
190
|
+
this.sessionFilterSource,
|
|
191
|
+
this.extractPathOptionsFromSessions(currentList),
|
|
192
|
+
false
|
|
193
|
+
);
|
|
194
|
+
if (activeKey !== sessionKey) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (currentList.length === 0) {
|
|
198
|
+
this.clearActiveSessionState();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const nextSession = currentList.find((item) => this.getSessionExportKey(item) === nextActiveKey)
|
|
202
|
+
|| currentList[Math.min(removedIndex, currentList.length - 1)];
|
|
203
|
+
if (!nextSession) {
|
|
204
|
+
this.clearActiveSessionState();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
await this.selectSession(nextSession);
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
normalizeSettingsTab(tab) {
|
|
211
|
+
if (tab === 'general' || tab === 'data') {
|
|
212
|
+
return tab;
|
|
213
|
+
}
|
|
214
|
+
return 'general';
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
async onSettingsTabClick(tab) {
|
|
218
|
+
await this.switchSettingsTab(tab);
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
async onSettingsTabKeydown(event, tab) {
|
|
222
|
+
if (!event) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const tabs = ['general', 'data'];
|
|
226
|
+
const currentTab = this.normalizeSettingsTab(tab || this.settingsTab);
|
|
227
|
+
const currentIndex = Math.max(0, tabs.indexOf(currentTab));
|
|
228
|
+
let nextIndex = currentIndex;
|
|
229
|
+
if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {
|
|
230
|
+
nextIndex = (currentIndex + 1) % tabs.length;
|
|
231
|
+
} else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {
|
|
232
|
+
nextIndex = (currentIndex - 1 + tabs.length) % tabs.length;
|
|
233
|
+
} else if (event.key === 'Home') {
|
|
234
|
+
nextIndex = 0;
|
|
235
|
+
} else if (event.key === 'End') {
|
|
236
|
+
nextIndex = tabs.length - 1;
|
|
237
|
+
} else {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
event.preventDefault();
|
|
241
|
+
const nextTab = tabs[nextIndex];
|
|
242
|
+
await this.switchSettingsTab(nextTab);
|
|
243
|
+
const target = typeof document !== 'undefined'
|
|
244
|
+
? document.getElementById(`settings-tab-${nextTab}`)
|
|
245
|
+
: null;
|
|
246
|
+
if (target && typeof target.focus === 'function') {
|
|
247
|
+
target.focus();
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
async switchSettingsTab(tab, options = {}) {
|
|
252
|
+
const nextTab = this.normalizeSettingsTab(tab);
|
|
253
|
+
this.settingsTab = nextTab;
|
|
254
|
+
if (typeof this.saveNavState === 'function') {
|
|
255
|
+
this.saveNavState();
|
|
256
|
+
}
|
|
257
|
+
if (nextTab !== 'data') {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
async loadSessionTrashCount(options = {}) {
|
|
263
|
+
if (this.sessionTrashCountLoading) {
|
|
264
|
+
this.sessionTrashCountPendingOptions = {
|
|
265
|
+
...(this.sessionTrashCountPendingOptions || {}),
|
|
266
|
+
...(options || {})
|
|
267
|
+
};
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const requestToken = this.issueSessionTrashCountRequestToken();
|
|
271
|
+
this.sessionTrashCountLoading = true;
|
|
272
|
+
try {
|
|
273
|
+
const res = await api('list-session-trash', { countOnly: true });
|
|
274
|
+
if (!this.isLatestSessionTrashCountRequestToken(requestToken)) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (res.error) {
|
|
278
|
+
if (options.silent !== true) {
|
|
279
|
+
this.showMessage(res.error, 'error');
|
|
280
|
+
}
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
|
|
284
|
+
res.totalCount,
|
|
285
|
+
this.sessionTrashItems
|
|
286
|
+
);
|
|
287
|
+
this.sessionTrashCountLoadedOnce = true;
|
|
288
|
+
} catch (e) {
|
|
289
|
+
if (this.isLatestSessionTrashCountRequestToken(requestToken) && options.silent !== true) {
|
|
290
|
+
this.showMessage('加载回收站数量失败', 'error');
|
|
291
|
+
}
|
|
292
|
+
} finally {
|
|
293
|
+
this.sessionTrashCountLoading = false;
|
|
294
|
+
const pendingOptions = this.sessionTrashCountPendingOptions;
|
|
295
|
+
this.sessionTrashCountPendingOptions = null;
|
|
296
|
+
if (pendingOptions) {
|
|
297
|
+
await this.loadSessionTrashCount(pendingOptions);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
normalizeSessionTrashRetentionDays(value) {
|
|
303
|
+
const numeric = Number(value);
|
|
304
|
+
if (!Number.isFinite(numeric) || numeric < 1) {
|
|
305
|
+
return 30;
|
|
306
|
+
}
|
|
307
|
+
return Math.min(365, Math.max(1, Math.floor(numeric)));
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
setSessionTrashRetentionDays(days) {
|
|
311
|
+
const normalized = this.normalizeSessionTrashRetentionDays(days);
|
|
312
|
+
this.sessionTrashRetentionDays = normalized;
|
|
313
|
+
try { localStorage.setItem('codexmateSessionTrashRetentionDays', String(normalized)); } catch (_) {}
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
getSessionTrashActionKey(item) {
|
|
317
|
+
return item && typeof item.trashId === 'string' ? item.trashId : '';
|
|
318
|
+
},
|
|
319
|
+
|
|
320
|
+
isSessionTrashActionBusy(item) {
|
|
321
|
+
const key = typeof item === 'string' ? item : this.getSessionTrashActionKey(item);
|
|
322
|
+
return !!(key && (this.sessionTrashRestoring[key] || this.sessionTrashPurging[key]));
|
|
323
|
+
},
|
|
324
|
+
|
|
325
|
+
async loadSessionTrash(options = {}) {
|
|
326
|
+
if (this.sessionTrashLoading) {
|
|
327
|
+
this.sessionTrashPendingOptions = {
|
|
328
|
+
...(this.sessionTrashPendingOptions || {}),
|
|
329
|
+
...(options || {})
|
|
330
|
+
};
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const requestToken = this.issueSessionTrashListRequestToken();
|
|
334
|
+
this.sessionTrashLoading = true;
|
|
335
|
+
this.sessionTrashLastLoadFailed = false;
|
|
336
|
+
let loadSucceeded = false;
|
|
337
|
+
try {
|
|
338
|
+
const res = await api('list-session-trash', {
|
|
339
|
+
limit: sessionTrashListLimit,
|
|
340
|
+
forceRefresh: !!options.forceRefresh,
|
|
341
|
+
retentionDays: this.sessionTrashRetentionDays
|
|
342
|
+
});
|
|
343
|
+
if (!this.isLatestSessionTrashListRequestToken(requestToken)) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (res.error) {
|
|
347
|
+
this.sessionTrashLastLoadFailed = true;
|
|
348
|
+
this.showMessage(res.error, 'error');
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const nextItems = Array.isArray(res.items) ? res.items : [];
|
|
352
|
+
this.sessionTrashItems = nextItems;
|
|
353
|
+
this.resetSessionTrashVisibleCount();
|
|
354
|
+
this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(res.totalCount, nextItems);
|
|
355
|
+
this.sessionTrashCountLoadedOnce = true;
|
|
356
|
+
this.sessionTrashLastLoadFailed = false;
|
|
357
|
+
loadSucceeded = true;
|
|
358
|
+
} catch (e) {
|
|
359
|
+
if (this.isLatestSessionTrashListRequestToken(requestToken)) {
|
|
360
|
+
this.sessionTrashLastLoadFailed = true;
|
|
361
|
+
this.showMessage('加载回收站失败', 'error');
|
|
362
|
+
}
|
|
363
|
+
} finally {
|
|
364
|
+
this.sessionTrashLoading = false;
|
|
365
|
+
if (loadSucceeded) {
|
|
366
|
+
this.sessionTrashLoadedOnce = true;
|
|
367
|
+
}
|
|
368
|
+
const pendingOptions = this.sessionTrashPendingOptions;
|
|
369
|
+
this.sessionTrashPendingOptions = null;
|
|
370
|
+
if (pendingOptions) {
|
|
371
|
+
await this.loadSessionTrash(pendingOptions);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
|
|
376
|
+
async restoreSessionTrash(item) {
|
|
377
|
+
const key = this.getSessionTrashActionKey(item);
|
|
378
|
+
if (!key || this.isSessionTrashActionBusy(key) || this.sessionTrashClearing) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
this.sessionTrashRestoring[key] = true;
|
|
382
|
+
try {
|
|
383
|
+
const res = await api('restore-session-trash', { trashId: key });
|
|
384
|
+
if (res.error) {
|
|
385
|
+
this.showMessage(res.error, 'error');
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
this.showMessage('会话已恢复', 'success');
|
|
389
|
+
if (typeof this.invalidateSessionsUsageData === 'function') {
|
|
390
|
+
this.invalidateSessionsUsageData({ preserveList: true });
|
|
391
|
+
}
|
|
392
|
+
this.invalidateSessionTrashRequests();
|
|
393
|
+
await this.loadSessionTrash({ forceRefresh: true });
|
|
394
|
+
if (this.sessionsLoadedOnce) {
|
|
395
|
+
await this.loadSessions();
|
|
396
|
+
}
|
|
397
|
+
} catch (e) {
|
|
398
|
+
this.showMessage('恢复失败', 'error');
|
|
399
|
+
} finally {
|
|
400
|
+
this.sessionTrashRestoring[key] = false;
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
|
|
404
|
+
async purgeSessionTrash(item) {
|
|
405
|
+
const key = this.getSessionTrashActionKey(item);
|
|
406
|
+
if (!key || this.isSessionTrashActionBusy(key) || this.sessionTrashClearing) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const confirmed = await this.requestConfirmDialog({
|
|
410
|
+
title: '彻底删除回收站记录',
|
|
411
|
+
message: '该会话将从回收站永久删除,且无法恢复。',
|
|
412
|
+
confirmText: '彻底删除',
|
|
413
|
+
cancelText: '取消',
|
|
414
|
+
danger: true
|
|
415
|
+
});
|
|
416
|
+
if (!confirmed) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
this.sessionTrashPurging[key] = true;
|
|
420
|
+
try {
|
|
421
|
+
const res = await api('purge-session-trash', { trashId: key });
|
|
422
|
+
if (res.error) {
|
|
423
|
+
this.showMessage(res.error, 'error');
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
this.showMessage('已彻底删除', 'success');
|
|
427
|
+
this.invalidateSessionTrashRequests();
|
|
428
|
+
await this.loadSessionTrash({ forceRefresh: true });
|
|
429
|
+
} catch (e) {
|
|
430
|
+
this.showMessage('彻底删除失败', 'error');
|
|
431
|
+
} finally {
|
|
432
|
+
this.sessionTrashPurging[key] = false;
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
|
|
436
|
+
async clearSessionTrash() {
|
|
437
|
+
const normalizedCount = Number(this.sessionTrashCount);
|
|
438
|
+
if (this.sessionTrashClearing || !Number.isFinite(normalizedCount) || normalizedCount <= 0) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const confirmed = await this.requestConfirmDialog({
|
|
442
|
+
title: '清空回收站',
|
|
443
|
+
message: '该操作会永久删除回收站中的全部会话,且无法恢复。',
|
|
444
|
+
confirmText: '全部清空',
|
|
445
|
+
cancelText: '取消',
|
|
446
|
+
danger: true
|
|
447
|
+
});
|
|
448
|
+
if (!confirmed) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
this.sessionTrashClearing = true;
|
|
452
|
+
try {
|
|
453
|
+
const res = await api('purge-session-trash', { all: true });
|
|
454
|
+
if (res.error) {
|
|
455
|
+
this.showMessage(res.error, 'error');
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
this.showMessage('回收站已清空', 'success');
|
|
459
|
+
this.invalidateSessionTrashRequests();
|
|
460
|
+
await this.loadSessionTrash({ forceRefresh: true });
|
|
461
|
+
} catch (e) {
|
|
462
|
+
this.showMessage('清空回收站失败', 'error');
|
|
463
|
+
} finally {
|
|
464
|
+
this.sessionTrashClearing = false;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|