codexmate 0.0.32 → 0.0.34

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.
Files changed (148) hide show
  1. package/README.md +147 -363
  2. package/README.zh.md +147 -371
  3. package/cli/agents-files.js +230 -224
  4. package/cli/archive-helpers.js +453 -446
  5. package/cli/auth-profiles.js +375 -375
  6. package/cli/builtin-proxy.js +1725 -1725
  7. package/cli/claude-proxy.js +1022 -1022
  8. package/cli/config-bootstrap.js +402 -402
  9. package/cli/config-health.js +454 -454
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -356
  12. package/cli/local-bridge.js +556 -324
  13. package/cli/openai-bridge.js +1653 -1653
  14. package/cli/openclaw-config.js +629 -629
  15. package/cli/session-convert-args.js +69 -69
  16. package/cli/session-convert-io.js +82 -82
  17. package/cli/session-convert.js +150 -150
  18. package/cli/session-usage.concurrent.js +28 -28
  19. package/cli/session-usage.js +118 -118
  20. package/cli/session-usage.models.js +176 -176
  21. package/cli/skills.js +1141 -1141
  22. package/cli/update.js +171 -0
  23. package/cli/zip-commands.js +510 -510
  24. package/cli.js +16079 -15829
  25. package/lib/automation.js +404 -404
  26. package/lib/cli-file-utils.js +151 -151
  27. package/lib/cli-models-utils.js +440 -440
  28. package/lib/cli-network-utils.js +190 -190
  29. package/lib/cli-path-utils.js +85 -85
  30. package/lib/cli-session-utils.js +121 -121
  31. package/lib/cli-sessions.js +427 -426
  32. package/lib/cli-utils.js +155 -155
  33. package/lib/cli-webhook.js +154 -126
  34. package/lib/download-artifacts.js +92 -92
  35. package/lib/mcp-stdio.js +453 -453
  36. package/lib/task-orchestrator.js +869 -869
  37. package/lib/text-diff.js +303 -303
  38. package/lib/win-tray.js +119 -0
  39. package/lib/workflow-engine.js +340 -340
  40. package/package.json +76 -76
  41. package/plugins/README.md +20 -20
  42. package/plugins/README.zh-CN.md +20 -20
  43. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  44. package/plugins/prompt-templates/computed.mjs +253 -253
  45. package/plugins/prompt-templates/index.mjs +8 -8
  46. package/plugins/prompt-templates/manifest.mjs +15 -15
  47. package/plugins/prompt-templates/methods.mjs +553 -553
  48. package/plugins/prompt-templates/overview.mjs +91 -91
  49. package/plugins/prompt-templates/ownership.mjs +19 -19
  50. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  51. package/plugins/prompt-templates/storage.mjs +64 -64
  52. package/plugins/registry.mjs +16 -16
  53. package/web-ui/app.js +654 -647
  54. package/web-ui/index.html +37 -36
  55. package/web-ui/logic.agents-diff.mjs +386 -386
  56. package/web-ui/logic.claude.mjs +172 -168
  57. package/web-ui/logic.codex.mjs +69 -69
  58. package/web-ui/logic.mjs +5 -5
  59. package/web-ui/logic.runtime.mjs +128 -128
  60. package/web-ui/logic.session-convert.mjs +70 -70
  61. package/web-ui/logic.sessions.mjs +781 -781
  62. package/web-ui/modules/api.mjs +90 -90
  63. package/web-ui/modules/app.computed.dashboard.mjs +248 -248
  64. package/web-ui/modules/app.computed.index.mjs +17 -17
  65. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  66. package/web-ui/modules/app.computed.session.mjs +735 -693
  67. package/web-ui/modules/app.constants.mjs +15 -15
  68. package/web-ui/modules/app.methods.agents.mjs +651 -651
  69. package/web-ui/modules/app.methods.claude-config.mjs +306 -200
  70. package/web-ui/modules/app.methods.codex-config.mjs +869 -861
  71. package/web-ui/modules/app.methods.index.mjs +94 -94
  72. package/web-ui/modules/app.methods.install.mjs +205 -205
  73. package/web-ui/modules/app.methods.navigation.mjs +788 -774
  74. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  75. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  76. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  77. package/web-ui/modules/app.methods.providers.mjs +575 -529
  78. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  79. package/web-ui/modules/app.methods.session-actions.mjs +591 -591
  80. package/web-ui/modules/app.methods.session-browser.mjs +1011 -1012
  81. package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
  82. package/web-ui/modules/app.methods.session-trash.mjs +438 -438
  83. package/web-ui/modules/app.methods.startup-claude.mjs +547 -537
  84. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  85. package/web-ui/modules/app.methods.webhook.mjs +87 -79
  86. package/web-ui/modules/config-mode.computed.mjs +124 -124
  87. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  88. package/web-ui/modules/i18n.dict.mjs +3195 -3177
  89. package/web-ui/modules/i18n.mjs +62 -62
  90. package/web-ui/modules/plugins.computed.mjs +3 -3
  91. package/web-ui/modules/plugins.methods.mjs +3 -3
  92. package/web-ui/modules/plugins.storage.mjs +11 -11
  93. package/web-ui/modules/provider-url-display.mjs +17 -17
  94. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  95. package/web-ui/modules/skills.computed.mjs +107 -107
  96. package/web-ui/modules/skills.methods.mjs +482 -482
  97. package/web-ui/partials/index/layout-footer.html +13 -13
  98. package/web-ui/partials/index/layout-header.html +499 -503
  99. package/web-ui/partials/index/modal-config-template-agents.html +185 -185
  100. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  101. package/web-ui/partials/index/modal-health-check.html +45 -45
  102. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  103. package/web-ui/partials/index/modal-skills.html +200 -200
  104. package/web-ui/partials/index/modal-webhook.html +42 -0
  105. package/web-ui/partials/index/modals-basic.html +223 -162
  106. package/web-ui/partials/index/panel-config-claude.html +155 -136
  107. package/web-ui/partials/index/panel-config-codex.html +176 -196
  108. package/web-ui/partials/index/panel-config-codex.html.bak +337 -0
  109. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  110. package/web-ui/partials/index/panel-dashboard.html +186 -219
  111. package/web-ui/partials/index/panel-docs.html +114 -114
  112. package/web-ui/partials/index/panel-market.html +177 -177
  113. package/web-ui/partials/index/panel-orchestration.html +391 -391
  114. package/web-ui/partials/index/panel-plugins.html +253 -253
  115. package/web-ui/partials/index/panel-sessions.html +319 -313
  116. package/web-ui/partials/index/panel-settings.html +158 -190
  117. package/web-ui/partials/index/panel-trash.html +82 -82
  118. package/web-ui/partials/index/panel-usage.html +137 -137
  119. package/web-ui/res/json5.min.js +1 -1
  120. package/web-ui/res/vue.global.prod.js +13 -13
  121. package/web-ui/session-helpers.mjs +591 -591
  122. package/web-ui/source-bundle.cjs +233 -233
  123. package/web-ui/styles/base-theme.css +281 -281
  124. package/web-ui/styles/bridge-pool.css +266 -197
  125. package/web-ui/styles/controls-forms.css +433 -433
  126. package/web-ui/styles/dashboard.css +406 -406
  127. package/web-ui/styles/docs-panel.css +245 -245
  128. package/web-ui/styles/feedback.css +108 -108
  129. package/web-ui/styles/health-check-dialog.css +144 -144
  130. package/web-ui/styles/layout-shell.css +628 -638
  131. package/web-ui/styles/modals-core.css +499 -466
  132. package/web-ui/styles/navigation-panels.css +391 -391
  133. package/web-ui/styles/openclaw-structured.css +266 -266
  134. package/web-ui/styles/plugins-panel.css +564 -564
  135. package/web-ui/styles/responsive.css +392 -392
  136. package/web-ui/styles/sessions-list.css +683 -647
  137. package/web-ui/styles/sessions-preview.css +407 -407
  138. package/web-ui/styles/sessions-toolbar-trash.css +518 -518
  139. package/web-ui/styles/sessions-usage.css +588 -588
  140. package/web-ui/styles/settings-panel.css +415 -349
  141. package/web-ui/styles/skills-list.css +305 -305
  142. package/web-ui/styles/skills-market.css +429 -429
  143. package/web-ui/styles/task-orchestration.css +822 -822
  144. package/web-ui/styles/titles-cards.css +472 -472
  145. package/web-ui/styles/trash-panel.css +90 -90
  146. package/web-ui/styles/webhook.css +115 -81
  147. package/web-ui/styles.css +24 -24
  148. package/web-ui.html +17 -17
@@ -1,591 +1,591 @@
1
- import { buildSessionListParams } from './logic.mjs';
2
-
3
- function clearSessionTimelineRefs(vm) {
4
- if (typeof vm.clearSessionTimelineRefs === 'function') {
5
- vm.clearSessionTimelineRefs();
6
- return;
7
- }
8
- vm.sessionMessageRefMap = Object.create(null);
9
- if (vm && typeof vm === 'object' && Object.prototype.hasOwnProperty.call(vm, 'sessionMessageRefBinderMap')) {
10
- vm.sessionMessageRefBinderMap = Object.create(null);
11
- }
12
- }
13
-
14
- function hasOwnOption(options, key) {
15
- return !!options && typeof options === 'object' && Object.prototype.hasOwnProperty.call(options, key);
16
- }
17
-
18
- function normalizeSessionLoadOptions(options = {}) {
19
- const normalized = options && typeof options === 'object' ? options : {};
20
- const hasIncludeActiveDetail = hasOwnOption(normalized, 'includeActiveDetail');
21
- return {
22
- hasIncludeActiveDetail,
23
- includeActiveDetail: hasIncludeActiveDetail
24
- ? normalized.includeActiveDetail !== false
25
- : false,
26
- forceRefresh: !!normalized.forceRefresh
27
- };
28
- }
29
-
30
- function mergeSessionLoadOptions(baseOptions = {}, nextOptions = {}) {
31
- const base = normalizeSessionLoadOptions(baseOptions);
32
- const next = normalizeSessionLoadOptions(nextOptions);
33
- return {
34
- hasIncludeActiveDetail: base.hasIncludeActiveDetail || next.hasIncludeActiveDetail,
35
- includeActiveDetail: (base.hasIncludeActiveDetail && base.includeActiveDetail)
36
- || (next.hasIncludeActiveDetail && next.includeActiveDetail),
37
- forceRefresh: base.forceRefresh || next.forceRefresh
38
- };
39
- }
40
-
41
- function shouldIncludeActiveSessionDetail(vm, options = {}) {
42
- if (options.hasIncludeActiveDetail) {
43
- return options.includeActiveDetail;
44
- }
45
- return vm.mainTab === 'sessions' || !!vm.sessionStandalone;
46
- }
47
-
48
- function emitSessionLoadDebug(vm, step, details = '') {
49
- if (!vm || typeof vm.emitSessionLoadNativeDialog !== 'function') {
50
- return;
51
- }
52
- vm.emitSessionLoadNativeDialog(step, details);
53
- }
54
-
55
- function scheduleSessionDetailHydration(vm, options = {}) {
56
- if (!vm || typeof vm.loadActiveSessionDetail !== 'function') {
57
- return;
58
- }
59
- const hydrationTicket = (Number(vm.__sessionDetailHydrationTicket) || 0) + 1;
60
- vm.__sessionDetailHydrationTicket = hydrationTicket;
61
- const task = () => {
62
- if (hydrationTicket !== Number(vm.__sessionDetailHydrationTicket || 0)) return;
63
- if (!vm.activeSession) return;
64
- if (vm.mainTab !== 'sessions' && !vm.sessionStandalone) return;
65
- if (vm.sessionDetailLoading) return;
66
- const currentMessages = Array.isArray(vm.activeSessionMessages) ? vm.activeSessionMessages : [];
67
- if (!options.force && currentMessages.length > 0) {
68
- emitSessionLoadDebug(vm, 'scheduleSessionDetailHydration:skip-existing-messages', `messages=${currentMessages.length}`);
69
- return;
70
- }
71
- emitSessionLoadDebug(vm, 'scheduleSessionDetailHydration:run', `sessionId=${vm.activeSession && vm.activeSession.sessionId ? vm.activeSession.sessionId : ''}`);
72
- void vm.loadActiveSessionDetail(options);
73
- };
74
- if (typeof vm.scheduleAfterFrame === 'function') {
75
- emitSessionLoadDebug(vm, 'scheduleSessionDetailHydration:queued');
76
- vm.scheduleAfterFrame(task);
77
- return;
78
- }
79
- task();
80
- }
81
-
82
- export function switchMainTab(tab) {
83
- const nextTab = typeof tab === 'string' ? tab : '';
84
- const previousTab = this.mainTab;
85
- const leavingSessions = previousTab === 'sessions' && nextTab !== 'sessions';
86
- const enteringSessionsTab = nextTab === 'sessions';
87
- const enteringUsageTab = nextTab === 'usage';
88
- const enteringOrchestrationTab = nextTab === 'orchestration';
89
- const enteringPluginsTab = nextTab === 'plugins';
90
- emitSessionLoadDebug(this, 'switchMainTab:start', `from=${previousTab}\nto=${nextTab}`);
91
- this.mainTab = nextTab;
92
-
93
- if (leavingSessions) {
94
- const teardown = () => {
95
- if (this.mainTab === 'sessions') return;
96
- if (typeof this.finalizeSessionTabTeardown === 'function') {
97
- if (typeof this.suspendSessionTabRender === 'function') {
98
- this.suspendSessionTabRender();
99
- }
100
- this.finalizeSessionTabTeardown();
101
- return;
102
- }
103
- if (typeof this.teardownSessionTabRender === 'function') {
104
- this.teardownSessionTabRender();
105
- }
106
- };
107
- if (typeof this.scheduleSessionTabDeferredTeardown === 'function') {
108
- this.scheduleSessionTabDeferredTeardown(teardown);
109
- } else if (typeof this.scheduleAfterFrame === 'function') {
110
- this.scheduleAfterFrame(teardown);
111
- } else {
112
- teardown();
113
- }
114
- }
115
-
116
- if (enteringSessionsTab && !this.sessionsLoadedOnce) {
117
- const canStageInitialSessionDetail = typeof this.scheduleAfterFrame === 'function';
118
- emitSessionLoadDebug(
119
- this,
120
- 'switchMainTab:enter-sessions',
121
- `sessionsLoadedOnce=${!!this.sessionsLoadedOnce}\nstagedDetail=${canStageInitialSessionDetail}`
122
- );
123
- const loadResult = this.loadSessions({
124
- includeActiveDetail: !canStageInitialSessionDetail
125
- });
126
- if (canStageInitialSessionDetail) {
127
- void Promise.resolve(loadResult)
128
- .then(() => {
129
- emitSessionLoadDebug(this, 'switchMainTab:loadSessions-resolved');
130
- scheduleSessionDetailHydration(this);
131
- })
132
- .catch((error) => {
133
- emitSessionLoadDebug(
134
- this,
135
- 'switchMainTab:loadSessions-rejected',
136
- error && error.message ? error.message : String(error)
137
- );
138
- });
139
- }
140
- }
141
- if (enteringUsageTab && !this.sessionsUsageLoadedOnce && typeof this.loadSessionsUsage === 'function') {
142
- this.loadSessionsUsage();
143
- }
144
- if (enteringOrchestrationTab && typeof this.loadTaskOrchestrationOverview === 'function') {
145
- let orchestrationOverviewLoad = null;
146
- try {
147
- orchestrationOverviewLoad = this.loadTaskOrchestrationOverview({
148
- silent: true,
149
- includeDetail: true
150
- });
151
- } catch (_) {
152
- orchestrationOverviewLoad = null;
153
- }
154
- void Promise.resolve(orchestrationOverviewLoad).catch(() => {});
155
- }
156
- if (nextTab !== 'orchestration' && typeof this.stopTaskOrchestrationPolling === 'function') {
157
- this.stopTaskOrchestrationPolling();
158
- }
159
- if (nextTab === 'sessions') {
160
- this.prepareSessionTabRender();
161
- }
162
- const shouldLoadTrashListOnSettingsEnter = nextTab === 'settings'
163
- && this.settingsTab === 'data'
164
- && typeof this.loadSessionTrash === 'function';
165
- if (shouldLoadTrashListOnSettingsEnter) {
166
- this.loadSessionTrash({
167
- forceRefresh: !!this.sessionTrashLoadedOnce
168
- });
169
- }
170
- const shouldPrimeTrashCountOnSettingsEnter = nextTab === 'settings'
171
- && this.settingsTab !== 'data'
172
- && typeof this.loadSessionTrashCount === 'function';
173
- if (shouldPrimeTrashCountOnSettingsEnter) {
174
- this.sessionTrashLoadedOnce = false;
175
- this.loadSessionTrashCount({ silent: true });
176
- }
177
- const shouldLoadSkillsMarketOnEnter = nextTab === 'market'
178
- && previousTab !== 'market'
179
- && typeof this.loadSkillsMarketOverview === 'function';
180
- if (shouldLoadSkillsMarketOnEnter) {
181
- let marketOverviewLoad = null;
182
- try {
183
- marketOverviewLoad = this.loadSkillsMarketOverview({ silent: true });
184
- } catch (_) {
185
- marketOverviewLoad = null;
186
- }
187
- void Promise.resolve(marketOverviewLoad).catch(() => {});
188
- }
189
- if (enteringPluginsTab && typeof this.loadPluginsOverview === 'function') {
190
- this.pluginsActiveId = 'prompt-templates';
191
- this.promptComposerPickerVisible = false;
192
- let pluginsLoad = null;
193
- try {
194
- pluginsLoad = this.loadPluginsOverview({ silent: true });
195
- } catch (_) {
196
- pluginsLoad = null;
197
- }
198
- void Promise.resolve(pluginsLoad).catch(() => {});
199
- }
200
- if (nextTab === 'config' && this.configMode === 'claude') {
201
- const expectedTab = nextTab;
202
- const expectedConfigMode = this.configMode;
203
- const refresh = () => {
204
- if (this.mainTab !== expectedTab || this.configMode !== expectedConfigMode) return;
205
- this.refreshClaudeModelContext();
206
- };
207
- if (typeof this.scheduleAfterFrame === 'function') {
208
- this.scheduleAfterFrame(refresh);
209
- } else {
210
- refresh();
211
- }
212
- }
213
- }
214
-
215
- export async function loadSessions(api, options = {}) {
216
- if (this.sessionsLoading) {
217
- this.__sessionPendingLoadOptions = mergeSessionLoadOptions(
218
- this.__sessionPendingLoadOptions,
219
- options
220
- );
221
- emitSessionLoadDebug(this, 'loadSessions:queued-while-busy');
222
- return;
223
- }
224
- const normalizedOptions = normalizeSessionLoadOptions(options);
225
- const includeActiveDetail = shouldIncludeActiveSessionDetail(this, normalizedOptions);
226
- this.sessionsLoading = true;
227
- this.activeSessionDetailError = '';
228
- let loadSucceeded = false;
229
- const params = buildSessionListParams({
230
- source: this.sessionFilterSource,
231
- pathFilter: this.sessionPathFilter,
232
- query: this.sessionQuery,
233
- roleFilter: this.sessionRoleFilter,
234
- timeRangePreset: this.sessionTimePreset,
235
- forceRefresh: normalizedOptions.forceRefresh
236
- });
237
- emitSessionLoadDebug(
238
- this,
239
- 'loadSessions:start',
240
- `source=${params.source || ''}\nforceRefresh=${!!params.forceRefresh}\nincludeActiveDetail=${includeActiveDetail}`
241
- );
242
- let pendingOptions = null;
243
- try {
244
- const res = await api('list-sessions', params);
245
- if (res.error) {
246
- emitSessionLoadDebug(this, 'loadSessions:error-response', `error=${res.error}`);
247
- this.showMessage(res.error, 'error');
248
- this.sessionsList = [];
249
- if (typeof this.primeSessionListRender === 'function') {
250
- this.primeSessionListRender();
251
- }
252
- this.activeSession = null;
253
- this.activeSessionMessages = [];
254
- this.resetSessionDetailPagination();
255
- this.resetSessionPreviewMessageRender();
256
- this.activeSessionDetailClipped = false;
257
- this.cancelSessionTimelineSync();
258
- this.sessionTimelineActiveKey = '';
259
- clearSessionTimelineRefs(this);
260
- } else {
261
- loadSucceeded = true;
262
- this.sessionsList = Array.isArray(res.sessions) ? res.sessions : [];
263
- emitSessionLoadDebug(this, 'loadSessions:response', `sessions=${this.sessionsList.length}`);
264
- if (typeof this.primeSessionListRender === 'function') {
265
- this.primeSessionListRender();
266
- }
267
- this.syncSessionPathOptionsForSource(
268
- this.sessionFilterSource,
269
- this.extractPathOptionsFromSessions(this.sessionsList),
270
- true
271
- );
272
- if (this.sessionsList.length === 0) {
273
- emitSessionLoadDebug(this, 'loadSessions:empty');
274
- this.activeSession = null;
275
- this.activeSessionMessages = [];
276
- this.resetSessionDetailPagination();
277
- this.resetSessionPreviewMessageRender();
278
- this.activeSessionDetailClipped = false;
279
- this.cancelSessionTimelineSync();
280
- this.sessionTimelineActiveKey = '';
281
- clearSessionTimelineRefs(this);
282
- } else {
283
- const oldKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
284
- const matched = this.sessionsList.find(item => this.getSessionExportKey(item) === oldKey);
285
- this.activeSession = matched || this.sessionsList[0];
286
- emitSessionLoadDebug(
287
- this,
288
- 'loadSessions:active-session-selected',
289
- `sessionId=${this.activeSession && this.activeSession.sessionId ? this.activeSession.sessionId : ''}`
290
- );
291
- this.activeSessionMessages = [];
292
- this.resetSessionDetailPagination();
293
- this.resetSessionPreviewMessageRender();
294
- this.activeSessionDetailError = '';
295
- this.activeSessionDetailClipped = false;
296
- this.cancelSessionTimelineSync();
297
- this.sessionTimelineActiveKey = '';
298
- clearSessionTimelineRefs(this);
299
- if (includeActiveDetail) {
300
- emitSessionLoadDebug(
301
- this,
302
- 'loadSessions:hydrate-active-detail',
303
- `sessionId=${this.activeSession && this.activeSession.sessionId ? this.activeSession.sessionId : ''}`
304
- );
305
- await this.loadActiveSessionDetail();
306
- }
307
- }
308
- }
309
- } catch (e) {
310
- emitSessionLoadDebug(this, 'loadSessions:exception', e && e.message ? e.message : String(e));
311
- this.sessionsList = [];
312
- if (typeof this.primeSessionListRender === 'function') {
313
- this.primeSessionListRender();
314
- }
315
- this.activeSession = null;
316
- this.activeSessionMessages = [];
317
- this.resetSessionDetailPagination();
318
- this.resetSessionPreviewMessageRender();
319
- this.activeSessionDetailClipped = false;
320
- this.cancelSessionTimelineSync();
321
- this.sessionTimelineActiveKey = '';
322
- clearSessionTimelineRefs(this);
323
- this.showMessage('加载会话失败', 'error');
324
- } finally {
325
- this.sessionsLoading = false;
326
- if (loadSucceeded) {
327
- this.sessionsLoadedOnce = true;
328
- }
329
- pendingOptions = this.__sessionPendingLoadOptions || null;
330
- this.__sessionPendingLoadOptions = null;
331
- emitSessionLoadDebug(
332
- this,
333
- 'loadSessions:complete',
334
- `loadSucceeded=${loadSucceeded}\npendingReload=${!!pendingOptions}`
335
- );
336
- }
337
- if (pendingOptions) {
338
- emitSessionLoadDebug(this, 'loadSessions:replay-pending-request');
339
- return loadSessions.call(this, api, pendingOptions);
340
- }
341
- }
342
-
343
- export async function loadActiveSessionDetail(api, options = {}) {
344
- if (!this.activeSession) {
345
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:skip-no-active-session');
346
- this.activeSessionMessages = [];
347
- this.resetSessionDetailPagination();
348
- this.resetSessionPreviewMessageRender();
349
- this.activeSessionDetailError = '';
350
- this.activeSessionDetailClipped = false;
351
- this.cancelSessionTimelineSync();
352
- this.sessionTimelineActiveKey = '';
353
- clearSessionTimelineRefs(this);
354
- return;
355
- }
356
-
357
- const currentActiveSession = this.activeSession;
358
- const requestSeq = ++this.sessionDetailRequestSeq;
359
- this.sessionDetailLoading = true;
360
- this.activeSessionDetailError = '';
361
- emitSessionLoadDebug(
362
- this,
363
- 'loadActiveSessionDetail:start',
364
- `sessionId=${currentActiveSession && currentActiveSession.sessionId ? currentActiveSession.sessionId : ''}\nrequestSeq=${requestSeq}`
365
- );
366
- const fallbackLimit = Number.isFinite(this.sessionDetailInitialMessageLimit)
367
- ? Math.max(1, Math.floor(this.sessionDetailInitialMessageLimit))
368
- : 80;
369
- const rawLimit = Number(this.sessionDetailMessageLimit);
370
- const messageLimit = Number.isFinite(rawLimit)
371
- ? Math.max(1, Math.floor(rawLimit))
372
- : fallbackLimit;
373
- const preview = this.mainTab === 'sessions' && !this.sessionStandalone;
374
- try {
375
- const res = await api('session-detail', {
376
- source: this.activeSession.source,
377
- sessionId: this.activeSession.sessionId,
378
- filePath: this.activeSession.filePath,
379
- messageLimit,
380
- preview
381
- });
382
-
383
- if (requestSeq !== this.sessionDetailRequestSeq) {
384
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:stale-request-seq', `requestSeq=${requestSeq}`);
385
- return;
386
- }
387
- if (!this.activeSession || this.activeSession !== currentActiveSession) {
388
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:active-session-changed', `requestSeq=${requestSeq}`);
389
- return;
390
- }
391
-
392
- if (res.error) {
393
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:error-response', `error=${res.error}`);
394
- this.activeSessionMessages = [];
395
- this.resetSessionPreviewMessageRender();
396
- this.activeSessionDetailClipped = false;
397
- this.activeSessionDetailError = res.error;
398
- this.cancelSessionTimelineSync();
399
- this.sessionTimelineActiveKey = '';
400
- clearSessionTimelineRefs(this);
401
- return;
402
- }
403
-
404
- const rawMessages = Array.isArray(res.messages) ? res.messages : [];
405
- const normalizedMessages = rawMessages.map((message) => Object.freeze(this.normalizeSessionMessage(message)));
406
- this.activeSessionMessages = Object.freeze(normalizedMessages);
407
- emitSessionLoadDebug(
408
- this,
409
- 'loadActiveSessionDetail:messages-ready',
410
- `sessionId=${currentActiveSession && currentActiveSession.sessionId ? currentActiveSession.sessionId : ''}\nmessages=${normalizedMessages.length}\nclipped=${!!res.clipped}`
411
- );
412
- if (typeof this.invalidateSessionTimelineMeasurementCache === 'function') {
413
- this.invalidateSessionTimelineMeasurementCache(true);
414
- }
415
- this.activeSessionDetailClipped = !!res.clipped;
416
- const responseLimitRaw = Number(res.messageLimit);
417
- this.sessionDetailMessageLimit = Number.isFinite(responseLimitRaw)
418
- ? Math.max(1, Math.floor(responseLimitRaw))
419
- : messageLimit;
420
- if (res.sourceLabel) {
421
- this.activeSession.sourceLabel = res.sourceLabel;
422
- }
423
- if (res.sessionId) {
424
- this.activeSession.sessionId = res.sessionId;
425
- if (!this.activeSession.title) {
426
- this.activeSession.title = res.sessionId;
427
- }
428
- }
429
- if (res.filePath) {
430
- this.activeSession.filePath = res.filePath;
431
- }
432
- if (res.updatedAt) {
433
- this.activeSession.updatedAt = res.updatedAt;
434
- }
435
- if (res.cwd) {
436
- this.activeSession.cwd = res.cwd;
437
- }
438
- if (Number.isFinite(res.totalMessages)) {
439
- this.syncActiveSessionMessageCount(res.totalMessages);
440
- }
441
- if (this.mainTab === 'sessions' && this.sessionPreviewRenderEnabled) {
442
- const preserveVisibleCount = !!options.preserveVisibleCount;
443
- const pendingVisibleRaw = Number(this.sessionPreviewPendingVisibleCount);
444
- const pendingVisible = Number.isFinite(pendingVisibleRaw)
445
- ? Math.max(0, Math.floor(pendingVisibleRaw))
446
- : 0;
447
- if (preserveVisibleCount && pendingVisible > 0) {
448
- this.sessionPreviewVisibleCount = Math.min(pendingVisible, this.activeSessionMessages.length);
449
- } else {
450
- this.primeSessionPreviewMessageRender();
451
- }
452
- }
453
- this.sessionPreviewPendingVisibleCount = 0;
454
- if (this.activeSessionDetailClipped) {
455
- const autoFetchSession = currentActiveSession;
456
- this.$nextTick(() => {
457
- if (this.activeSession !== autoFetchSession) return;
458
- if (this.sessionDetailLoading) return;
459
- if (!this.activeSessionDetailClipped) return;
460
- const currentLimit = Number(this.sessionDetailMessageLimit);
461
- const fetchStep = Number.isFinite(this.sessionDetailFetchStep)
462
- ? Math.max(1, Math.floor(this.sessionDetailFetchStep))
463
- : 300;
464
- const limitCap = Number.isFinite(this.sessionDetailMessageLimitCap)
465
- ? Math.max(1, Math.floor(this.sessionDetailMessageLimitCap))
466
- : 1000;
467
- const nextLimit = Math.min(currentLimit + fetchStep, limitCap);
468
- if (nextLimit <= currentLimit) return;
469
- this.sessionDetailMessageLimit = nextLimit;
470
- this.sessionPreviewPendingVisibleCount = nextLimit;
471
- void this.loadActiveSessionDetail({ preserveVisibleCount: true });
472
- });
473
- }
474
- this.$nextTick(() => {
475
- if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
476
- return;
477
- }
478
- this.updateSessionTimelineOffset();
479
- if (this.sessionTimelineEnabled) {
480
- const currentSession = this.activeSession;
481
- const syncTask = () => {
482
- if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
483
- return;
484
- }
485
- if (!this.activeSession || this.activeSession !== currentSession) {
486
- return;
487
- }
488
- this.scheduleSessionTimelineSync();
489
- };
490
- if (typeof this.scheduleAfterFrame === 'function') {
491
- this.scheduleAfterFrame(syncTask);
492
- return;
493
- }
494
- syncTask();
495
- }
496
- });
497
- } catch (e) {
498
- if (requestSeq !== this.sessionDetailRequestSeq) {
499
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:ignore-exception-stale-request', `requestSeq=${requestSeq}`);
500
- return;
501
- }
502
- if (!this.activeSession || this.activeSession !== currentActiveSession) {
503
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:ignore-exception-session-changed', `requestSeq=${requestSeq}`);
504
- return;
505
- }
506
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:exception', e && e.message ? e.message : String(e));
507
- this.activeSessionMessages = [];
508
- this.sessionPreviewPendingVisibleCount = 0;
509
- this.resetSessionPreviewMessageRender();
510
- this.activeSessionDetailClipped = false;
511
- this.activeSessionDetailError = '加载会话内容失败: ' + e.message;
512
- this.cancelSessionTimelineSync();
513
- this.sessionTimelineActiveKey = '';
514
- clearSessionTimelineRefs(this);
515
- } finally {
516
- if (requestSeq === this.sessionDetailRequestSeq) {
517
- this.sessionDetailLoading = false;
518
- }
519
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:complete', `requestSeq=${requestSeq}`);
520
- }
521
- }
522
-
523
- export async function loadMoreSessionMessages(stepSize) {
524
- if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
525
- return;
526
- }
527
- const total = Array.isArray(this.activeSessionMessages)
528
- ? this.activeSessionMessages.length
529
- : 0;
530
- if (total <= 0) {
531
- this.sessionPreviewVisibleCount = 0;
532
- return;
533
- }
534
- const step = Number.isFinite(stepSize)
535
- ? Math.max(1, Math.floor(stepSize))
536
- : (Number.isFinite(this.sessionPreviewLoadStep)
537
- ? Math.max(1, Math.floor(this.sessionPreviewLoadStep))
538
- : 40);
539
- const current = Number.isFinite(this.sessionPreviewVisibleCount)
540
- ? Math.max(0, Math.floor(this.sessionPreviewVisibleCount))
541
- : 0;
542
- const targetVisible = current + step;
543
- if (targetVisible <= total) {
544
- this.sessionPreviewVisibleCount = Math.min(total, targetVisible);
545
- return;
546
- }
547
-
548
- this.sessionPreviewVisibleCount = total;
549
- if (this.sessionDetailLoading) {
550
- return;
551
- }
552
-
553
- const totalKnownRaw = Number(this.activeSession && this.activeSession.messageCount);
554
- const totalKnown = Number.isFinite(totalKnownRaw)
555
- ? Math.max(0, Math.floor(totalKnownRaw))
556
- : 0;
557
- const hasMoreOnDisk = this.activeSessionDetailClipped || (totalKnown > total);
558
- if (!hasMoreOnDisk) {
559
- return;
560
- }
561
-
562
- const currentLimitRaw = Number(this.sessionDetailMessageLimit);
563
- const currentLimit = Number.isFinite(currentLimitRaw)
564
- ? Math.max(1, Math.floor(currentLimitRaw))
565
- : Math.max(1, total);
566
- const fetchStep = Number.isFinite(this.sessionDetailFetchStep)
567
- ? Math.max(1, Math.floor(this.sessionDetailFetchStep))
568
- : 80;
569
- const limitCapRaw = Number(this.sessionDetailMessageLimitCap);
570
- const limitCap = Number.isFinite(limitCapRaw)
571
- ? Math.max(1, Math.floor(limitCapRaw))
572
- : 1000;
573
-
574
- let nextLimit = Math.max(currentLimit + fetchStep, targetVisible);
575
- if (totalKnown > total) {
576
- nextLimit = Math.min(nextLimit, totalKnown);
577
- }
578
- nextLimit = Math.min(nextLimit, limitCap);
579
- if (nextLimit <= currentLimit) {
580
- return;
581
- }
582
-
583
- this.sessionPreviewPendingVisibleCount = targetVisible;
584
- this.sessionDetailMessageLimit = nextLimit;
585
- this.sessionPreviewLoadingMore = true;
586
- try {
587
- await this.loadActiveSessionDetail({ preserveVisibleCount: true });
588
- } finally {
589
- this.sessionPreviewLoadingMore = false;
590
- }
591
- }
1
+ import { buildSessionListParams } from './logic.mjs';
2
+
3
+ function clearSessionTimelineRefs(vm) {
4
+ if (typeof vm.clearSessionTimelineRefs === 'function') {
5
+ vm.clearSessionTimelineRefs();
6
+ return;
7
+ }
8
+ vm.sessionMessageRefMap = Object.create(null);
9
+ if (vm && typeof vm === 'object' && Object.prototype.hasOwnProperty.call(vm, 'sessionMessageRefBinderMap')) {
10
+ vm.sessionMessageRefBinderMap = Object.create(null);
11
+ }
12
+ }
13
+
14
+ function hasOwnOption(options, key) {
15
+ return !!options && typeof options === 'object' && Object.prototype.hasOwnProperty.call(options, key);
16
+ }
17
+
18
+ function normalizeSessionLoadOptions(options = {}) {
19
+ const normalized = options && typeof options === 'object' ? options : {};
20
+ const hasIncludeActiveDetail = hasOwnOption(normalized, 'includeActiveDetail');
21
+ return {
22
+ hasIncludeActiveDetail,
23
+ includeActiveDetail: hasIncludeActiveDetail
24
+ ? normalized.includeActiveDetail !== false
25
+ : false,
26
+ forceRefresh: !!normalized.forceRefresh
27
+ };
28
+ }
29
+
30
+ function mergeSessionLoadOptions(baseOptions = {}, nextOptions = {}) {
31
+ const base = normalizeSessionLoadOptions(baseOptions);
32
+ const next = normalizeSessionLoadOptions(nextOptions);
33
+ return {
34
+ hasIncludeActiveDetail: base.hasIncludeActiveDetail || next.hasIncludeActiveDetail,
35
+ includeActiveDetail: (base.hasIncludeActiveDetail && base.includeActiveDetail)
36
+ || (next.hasIncludeActiveDetail && next.includeActiveDetail),
37
+ forceRefresh: base.forceRefresh || next.forceRefresh
38
+ };
39
+ }
40
+
41
+ function shouldIncludeActiveSessionDetail(vm, options = {}) {
42
+ if (options.hasIncludeActiveDetail) {
43
+ return options.includeActiveDetail;
44
+ }
45
+ return vm.mainTab === 'sessions' || !!vm.sessionStandalone;
46
+ }
47
+
48
+ function emitSessionLoadDebug(vm, step, details = '') {
49
+ if (!vm || typeof vm.emitSessionLoadNativeDialog !== 'function') {
50
+ return;
51
+ }
52
+ vm.emitSessionLoadNativeDialog(step, details);
53
+ }
54
+
55
+ function scheduleSessionDetailHydration(vm, options = {}) {
56
+ if (!vm || typeof vm.loadActiveSessionDetail !== 'function') {
57
+ return;
58
+ }
59
+ const hydrationTicket = (Number(vm.__sessionDetailHydrationTicket) || 0) + 1;
60
+ vm.__sessionDetailHydrationTicket = hydrationTicket;
61
+ const task = () => {
62
+ if (hydrationTicket !== Number(vm.__sessionDetailHydrationTicket || 0)) return;
63
+ if (!vm.activeSession) return;
64
+ if (vm.mainTab !== 'sessions' && !vm.sessionStandalone) return;
65
+ if (vm.sessionDetailLoading) return;
66
+ const currentMessages = Array.isArray(vm.activeSessionMessages) ? vm.activeSessionMessages : [];
67
+ if (!options.force && currentMessages.length > 0) {
68
+ emitSessionLoadDebug(vm, 'scheduleSessionDetailHydration:skip-existing-messages', `messages=${currentMessages.length}`);
69
+ return;
70
+ }
71
+ emitSessionLoadDebug(vm, 'scheduleSessionDetailHydration:run', `sessionId=${vm.activeSession && vm.activeSession.sessionId ? vm.activeSession.sessionId : ''}`);
72
+ void vm.loadActiveSessionDetail(options);
73
+ };
74
+ if (typeof vm.scheduleAfterFrame === 'function') {
75
+ emitSessionLoadDebug(vm, 'scheduleSessionDetailHydration:queued');
76
+ vm.scheduleAfterFrame(task);
77
+ return;
78
+ }
79
+ task();
80
+ }
81
+
82
+ export function switchMainTab(tab) {
83
+ const nextTab = typeof tab === 'string' ? tab : '';
84
+ const previousTab = this.mainTab;
85
+ const leavingSessions = previousTab === 'sessions' && nextTab !== 'sessions';
86
+ const enteringSessionsTab = nextTab === 'sessions';
87
+ const enteringUsageTab = nextTab === 'usage';
88
+ const enteringOrchestrationTab = nextTab === 'orchestration';
89
+ const enteringPluginsTab = nextTab === 'plugins';
90
+ emitSessionLoadDebug(this, 'switchMainTab:start', `from=${previousTab}\nto=${nextTab}`);
91
+ this.mainTab = nextTab;
92
+
93
+ if (leavingSessions) {
94
+ const teardown = () => {
95
+ if (this.mainTab === 'sessions') return;
96
+ if (typeof this.finalizeSessionTabTeardown === 'function') {
97
+ if (typeof this.suspendSessionTabRender === 'function') {
98
+ this.suspendSessionTabRender();
99
+ }
100
+ this.finalizeSessionTabTeardown();
101
+ return;
102
+ }
103
+ if (typeof this.teardownSessionTabRender === 'function') {
104
+ this.teardownSessionTabRender();
105
+ }
106
+ };
107
+ if (typeof this.scheduleSessionTabDeferredTeardown === 'function') {
108
+ this.scheduleSessionTabDeferredTeardown(teardown);
109
+ } else if (typeof this.scheduleAfterFrame === 'function') {
110
+ this.scheduleAfterFrame(teardown);
111
+ } else {
112
+ teardown();
113
+ }
114
+ }
115
+
116
+ if (enteringSessionsTab && !this.sessionsLoadedOnce) {
117
+ const canStageInitialSessionDetail = typeof this.scheduleAfterFrame === 'function';
118
+ emitSessionLoadDebug(
119
+ this,
120
+ 'switchMainTab:enter-sessions',
121
+ `sessionsLoadedOnce=${!!this.sessionsLoadedOnce}\nstagedDetail=${canStageInitialSessionDetail}`
122
+ );
123
+ const loadResult = this.loadSessions({
124
+ includeActiveDetail: !canStageInitialSessionDetail
125
+ });
126
+ if (canStageInitialSessionDetail) {
127
+ void Promise.resolve(loadResult)
128
+ .then(() => {
129
+ emitSessionLoadDebug(this, 'switchMainTab:loadSessions-resolved');
130
+ scheduleSessionDetailHydration(this);
131
+ })
132
+ .catch((error) => {
133
+ emitSessionLoadDebug(
134
+ this,
135
+ 'switchMainTab:loadSessions-rejected',
136
+ error && error.message ? error.message : String(error)
137
+ );
138
+ });
139
+ }
140
+ }
141
+ if (enteringUsageTab && !this.sessionsUsageLoadedOnce && typeof this.loadSessionsUsage === 'function') {
142
+ this.loadSessionsUsage();
143
+ }
144
+ if (enteringOrchestrationTab && typeof this.loadTaskOrchestrationOverview === 'function') {
145
+ let orchestrationOverviewLoad = null;
146
+ try {
147
+ orchestrationOverviewLoad = this.loadTaskOrchestrationOverview({
148
+ silent: true,
149
+ includeDetail: true
150
+ });
151
+ } catch (_) {
152
+ orchestrationOverviewLoad = null;
153
+ }
154
+ void Promise.resolve(orchestrationOverviewLoad).catch(() => {});
155
+ }
156
+ if (nextTab !== 'orchestration' && typeof this.stopTaskOrchestrationPolling === 'function') {
157
+ this.stopTaskOrchestrationPolling();
158
+ }
159
+ if (nextTab === 'sessions') {
160
+ this.prepareSessionTabRender();
161
+ }
162
+ const shouldLoadTrashListOnSettingsEnter = nextTab === 'settings'
163
+ && this.settingsTab === 'data'
164
+ && typeof this.loadSessionTrash === 'function';
165
+ if (shouldLoadTrashListOnSettingsEnter) {
166
+ this.loadSessionTrash({
167
+ forceRefresh: !!this.sessionTrashLoadedOnce
168
+ });
169
+ }
170
+ const shouldPrimeTrashCountOnSettingsEnter = nextTab === 'settings'
171
+ && this.settingsTab !== 'data'
172
+ && typeof this.loadSessionTrashCount === 'function';
173
+ if (shouldPrimeTrashCountOnSettingsEnter) {
174
+ this.sessionTrashLoadedOnce = false;
175
+ this.loadSessionTrashCount({ silent: true });
176
+ }
177
+ const shouldLoadSkillsMarketOnEnter = nextTab === 'market'
178
+ && previousTab !== 'market'
179
+ && typeof this.loadSkillsMarketOverview === 'function';
180
+ if (shouldLoadSkillsMarketOnEnter) {
181
+ let marketOverviewLoad = null;
182
+ try {
183
+ marketOverviewLoad = this.loadSkillsMarketOverview({ silent: true });
184
+ } catch (_) {
185
+ marketOverviewLoad = null;
186
+ }
187
+ void Promise.resolve(marketOverviewLoad).catch(() => {});
188
+ }
189
+ if (enteringPluginsTab && typeof this.loadPluginsOverview === 'function') {
190
+ this.pluginsActiveId = 'prompt-templates';
191
+ this.promptComposerPickerVisible = false;
192
+ let pluginsLoad = null;
193
+ try {
194
+ pluginsLoad = this.loadPluginsOverview({ silent: true });
195
+ } catch (_) {
196
+ pluginsLoad = null;
197
+ }
198
+ void Promise.resolve(pluginsLoad).catch(() => {});
199
+ }
200
+ if (nextTab === 'config' && this.configMode === 'claude') {
201
+ const expectedTab = nextTab;
202
+ const expectedConfigMode = this.configMode;
203
+ const refresh = () => {
204
+ if (this.mainTab !== expectedTab || this.configMode !== expectedConfigMode) return;
205
+ this.refreshClaudeModelContext();
206
+ };
207
+ if (typeof this.scheduleAfterFrame === 'function') {
208
+ this.scheduleAfterFrame(refresh);
209
+ } else {
210
+ refresh();
211
+ }
212
+ }
213
+ }
214
+
215
+ export async function loadSessions(api, options = {}) {
216
+ if (this.sessionsLoading) {
217
+ this.__sessionPendingLoadOptions = mergeSessionLoadOptions(
218
+ this.__sessionPendingLoadOptions,
219
+ options
220
+ );
221
+ emitSessionLoadDebug(this, 'loadSessions:queued-while-busy');
222
+ return;
223
+ }
224
+ const normalizedOptions = normalizeSessionLoadOptions(options);
225
+ const includeActiveDetail = shouldIncludeActiveSessionDetail(this, normalizedOptions);
226
+ this.sessionsLoading = true;
227
+ this.activeSessionDetailError = '';
228
+ let loadSucceeded = false;
229
+ const params = buildSessionListParams({
230
+ source: this.sessionFilterSource,
231
+ pathFilter: this.sessionPathFilter,
232
+ query: this.sessionQuery,
233
+ roleFilter: this.sessionRoleFilter,
234
+ timeRangePreset: this.sessionTimePreset,
235
+ forceRefresh: normalizedOptions.forceRefresh
236
+ });
237
+ emitSessionLoadDebug(
238
+ this,
239
+ 'loadSessions:start',
240
+ `source=${params.source || ''}\nforceRefresh=${!!params.forceRefresh}\nincludeActiveDetail=${includeActiveDetail}`
241
+ );
242
+ let pendingOptions = null;
243
+ try {
244
+ const res = await api('list-sessions', params);
245
+ if (res.error) {
246
+ emitSessionLoadDebug(this, 'loadSessions:error-response', `error=${res.error}`);
247
+ this.showMessage(res.error, 'error');
248
+ this.sessionsList = [];
249
+ if (typeof this.primeSessionListRender === 'function') {
250
+ this.primeSessionListRender();
251
+ }
252
+ this.activeSession = null;
253
+ this.activeSessionMessages = [];
254
+ this.resetSessionDetailPagination();
255
+ this.resetSessionPreviewMessageRender();
256
+ this.activeSessionDetailClipped = false;
257
+ this.cancelSessionTimelineSync();
258
+ this.sessionTimelineActiveKey = '';
259
+ clearSessionTimelineRefs(this);
260
+ } else {
261
+ loadSucceeded = true;
262
+ this.sessionsList = Array.isArray(res.sessions) ? res.sessions : [];
263
+ emitSessionLoadDebug(this, 'loadSessions:response', `sessions=${this.sessionsList.length}`);
264
+ if (typeof this.primeSessionListRender === 'function') {
265
+ this.primeSessionListRender();
266
+ }
267
+ this.syncSessionPathOptionsForSource(
268
+ this.sessionFilterSource,
269
+ this.extractPathOptionsFromSessions(this.sessionsList),
270
+ true
271
+ );
272
+ if (this.sessionsList.length === 0) {
273
+ emitSessionLoadDebug(this, 'loadSessions:empty');
274
+ this.activeSession = null;
275
+ this.activeSessionMessages = [];
276
+ this.resetSessionDetailPagination();
277
+ this.resetSessionPreviewMessageRender();
278
+ this.activeSessionDetailClipped = false;
279
+ this.cancelSessionTimelineSync();
280
+ this.sessionTimelineActiveKey = '';
281
+ clearSessionTimelineRefs(this);
282
+ } else {
283
+ const oldKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
284
+ const matched = this.sessionsList.find(item => this.getSessionExportKey(item) === oldKey);
285
+ this.activeSession = matched || this.sessionsList[0];
286
+ emitSessionLoadDebug(
287
+ this,
288
+ 'loadSessions:active-session-selected',
289
+ `sessionId=${this.activeSession && this.activeSession.sessionId ? this.activeSession.sessionId : ''}`
290
+ );
291
+ this.activeSessionMessages = [];
292
+ this.resetSessionDetailPagination();
293
+ this.resetSessionPreviewMessageRender();
294
+ this.activeSessionDetailError = '';
295
+ this.activeSessionDetailClipped = false;
296
+ this.cancelSessionTimelineSync();
297
+ this.sessionTimelineActiveKey = '';
298
+ clearSessionTimelineRefs(this);
299
+ if (includeActiveDetail) {
300
+ emitSessionLoadDebug(
301
+ this,
302
+ 'loadSessions:hydrate-active-detail',
303
+ `sessionId=${this.activeSession && this.activeSession.sessionId ? this.activeSession.sessionId : ''}`
304
+ );
305
+ await this.loadActiveSessionDetail();
306
+ }
307
+ }
308
+ }
309
+ } catch (e) {
310
+ emitSessionLoadDebug(this, 'loadSessions:exception', e && e.message ? e.message : String(e));
311
+ this.sessionsList = [];
312
+ if (typeof this.primeSessionListRender === 'function') {
313
+ this.primeSessionListRender();
314
+ }
315
+ this.activeSession = null;
316
+ this.activeSessionMessages = [];
317
+ this.resetSessionDetailPagination();
318
+ this.resetSessionPreviewMessageRender();
319
+ this.activeSessionDetailClipped = false;
320
+ this.cancelSessionTimelineSync();
321
+ this.sessionTimelineActiveKey = '';
322
+ clearSessionTimelineRefs(this);
323
+ this.showMessage('加载会话失败', 'error');
324
+ } finally {
325
+ this.sessionsLoading = false;
326
+ if (loadSucceeded) {
327
+ this.sessionsLoadedOnce = true;
328
+ }
329
+ pendingOptions = this.__sessionPendingLoadOptions || null;
330
+ this.__sessionPendingLoadOptions = null;
331
+ emitSessionLoadDebug(
332
+ this,
333
+ 'loadSessions:complete',
334
+ `loadSucceeded=${loadSucceeded}\npendingReload=${!!pendingOptions}`
335
+ );
336
+ }
337
+ if (pendingOptions) {
338
+ emitSessionLoadDebug(this, 'loadSessions:replay-pending-request');
339
+ return loadSessions.call(this, api, pendingOptions);
340
+ }
341
+ }
342
+
343
+ export async function loadActiveSessionDetail(api, options = {}) {
344
+ if (!this.activeSession) {
345
+ emitSessionLoadDebug(this, 'loadActiveSessionDetail:skip-no-active-session');
346
+ this.activeSessionMessages = [];
347
+ this.resetSessionDetailPagination();
348
+ this.resetSessionPreviewMessageRender();
349
+ this.activeSessionDetailError = '';
350
+ this.activeSessionDetailClipped = false;
351
+ this.cancelSessionTimelineSync();
352
+ this.sessionTimelineActiveKey = '';
353
+ clearSessionTimelineRefs(this);
354
+ return;
355
+ }
356
+
357
+ const currentActiveSession = this.activeSession;
358
+ const requestSeq = ++this.sessionDetailRequestSeq;
359
+ this.sessionDetailLoading = true;
360
+ this.activeSessionDetailError = '';
361
+ emitSessionLoadDebug(
362
+ this,
363
+ 'loadActiveSessionDetail:start',
364
+ `sessionId=${currentActiveSession && currentActiveSession.sessionId ? currentActiveSession.sessionId : ''}\nrequestSeq=${requestSeq}`
365
+ );
366
+ const fallbackLimit = Number.isFinite(this.sessionDetailInitialMessageLimit)
367
+ ? Math.max(1, Math.floor(this.sessionDetailInitialMessageLimit))
368
+ : 80;
369
+ const rawLimit = Number(this.sessionDetailMessageLimit);
370
+ const messageLimit = Number.isFinite(rawLimit)
371
+ ? Math.max(1, Math.floor(rawLimit))
372
+ : fallbackLimit;
373
+ const preview = this.mainTab === 'sessions' && !this.sessionStandalone;
374
+ try {
375
+ const res = await api('session-detail', {
376
+ source: this.activeSession.source,
377
+ sessionId: this.activeSession.sessionId,
378
+ filePath: this.activeSession.filePath,
379
+ messageLimit,
380
+ preview
381
+ });
382
+
383
+ if (requestSeq !== this.sessionDetailRequestSeq) {
384
+ emitSessionLoadDebug(this, 'loadActiveSessionDetail:stale-request-seq', `requestSeq=${requestSeq}`);
385
+ return;
386
+ }
387
+ if (!this.activeSession || this.activeSession !== currentActiveSession) {
388
+ emitSessionLoadDebug(this, 'loadActiveSessionDetail:active-session-changed', `requestSeq=${requestSeq}`);
389
+ return;
390
+ }
391
+
392
+ if (res.error) {
393
+ emitSessionLoadDebug(this, 'loadActiveSessionDetail:error-response', `error=${res.error}`);
394
+ this.activeSessionMessages = [];
395
+ this.resetSessionPreviewMessageRender();
396
+ this.activeSessionDetailClipped = false;
397
+ this.activeSessionDetailError = res.error;
398
+ this.cancelSessionTimelineSync();
399
+ this.sessionTimelineActiveKey = '';
400
+ clearSessionTimelineRefs(this);
401
+ return;
402
+ }
403
+
404
+ const rawMessages = Array.isArray(res.messages) ? res.messages : [];
405
+ const normalizedMessages = rawMessages.map((message) => Object.freeze(this.normalizeSessionMessage(message)));
406
+ this.activeSessionMessages = Object.freeze(normalizedMessages);
407
+ emitSessionLoadDebug(
408
+ this,
409
+ 'loadActiveSessionDetail:messages-ready',
410
+ `sessionId=${currentActiveSession && currentActiveSession.sessionId ? currentActiveSession.sessionId : ''}\nmessages=${normalizedMessages.length}\nclipped=${!!res.clipped}`
411
+ );
412
+ if (typeof this.invalidateSessionTimelineMeasurementCache === 'function') {
413
+ this.invalidateSessionTimelineMeasurementCache(true);
414
+ }
415
+ this.activeSessionDetailClipped = !!res.clipped;
416
+ const responseLimitRaw = Number(res.messageLimit);
417
+ this.sessionDetailMessageLimit = Number.isFinite(responseLimitRaw)
418
+ ? Math.max(1, Math.floor(responseLimitRaw))
419
+ : messageLimit;
420
+ if (res.sourceLabel) {
421
+ this.activeSession.sourceLabel = res.sourceLabel;
422
+ }
423
+ if (res.sessionId) {
424
+ this.activeSession.sessionId = res.sessionId;
425
+ if (!this.activeSession.title) {
426
+ this.activeSession.title = res.sessionId;
427
+ }
428
+ }
429
+ if (res.filePath) {
430
+ this.activeSession.filePath = res.filePath;
431
+ }
432
+ if (res.updatedAt) {
433
+ this.activeSession.updatedAt = res.updatedAt;
434
+ }
435
+ if (res.cwd) {
436
+ this.activeSession.cwd = res.cwd;
437
+ }
438
+ if (Number.isFinite(res.totalMessages)) {
439
+ this.syncActiveSessionMessageCount(res.totalMessages);
440
+ }
441
+ if (this.mainTab === 'sessions' && this.sessionPreviewRenderEnabled) {
442
+ const preserveVisibleCount = !!options.preserveVisibleCount;
443
+ const pendingVisibleRaw = Number(this.sessionPreviewPendingVisibleCount);
444
+ const pendingVisible = Number.isFinite(pendingVisibleRaw)
445
+ ? Math.max(0, Math.floor(pendingVisibleRaw))
446
+ : 0;
447
+ if (preserveVisibleCount && pendingVisible > 0) {
448
+ this.sessionPreviewVisibleCount = Math.min(pendingVisible, this.activeSessionMessages.length);
449
+ } else {
450
+ this.primeSessionPreviewMessageRender();
451
+ }
452
+ }
453
+ this.sessionPreviewPendingVisibleCount = 0;
454
+ if (this.activeSessionDetailClipped) {
455
+ const autoFetchSession = currentActiveSession;
456
+ this.$nextTick(() => {
457
+ if (this.activeSession !== autoFetchSession) return;
458
+ if (this.sessionDetailLoading) return;
459
+ if (!this.activeSessionDetailClipped) return;
460
+ const currentLimit = Number(this.sessionDetailMessageLimit);
461
+ const fetchStep = Number.isFinite(this.sessionDetailFetchStep)
462
+ ? Math.max(1, Math.floor(this.sessionDetailFetchStep))
463
+ : 300;
464
+ const limitCap = Number.isFinite(this.sessionDetailMessageLimitCap)
465
+ ? Math.max(1, Math.floor(this.sessionDetailMessageLimitCap))
466
+ : 1000;
467
+ const nextLimit = Math.min(currentLimit + fetchStep, limitCap);
468
+ if (nextLimit <= currentLimit) return;
469
+ this.sessionDetailMessageLimit = nextLimit;
470
+ this.sessionPreviewPendingVisibleCount = nextLimit;
471
+ void this.loadActiveSessionDetail({ preserveVisibleCount: true });
472
+ });
473
+ }
474
+ this.$nextTick(() => {
475
+ if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
476
+ return;
477
+ }
478
+ this.updateSessionTimelineOffset();
479
+ if (this.sessionTimelineEnabled) {
480
+ const currentSession = this.activeSession;
481
+ const syncTask = () => {
482
+ if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
483
+ return;
484
+ }
485
+ if (!this.activeSession || this.activeSession !== currentSession) {
486
+ return;
487
+ }
488
+ this.scheduleSessionTimelineSync();
489
+ };
490
+ if (typeof this.scheduleAfterFrame === 'function') {
491
+ this.scheduleAfterFrame(syncTask);
492
+ return;
493
+ }
494
+ syncTask();
495
+ }
496
+ });
497
+ } catch (e) {
498
+ if (requestSeq !== this.sessionDetailRequestSeq) {
499
+ emitSessionLoadDebug(this, 'loadActiveSessionDetail:ignore-exception-stale-request', `requestSeq=${requestSeq}`);
500
+ return;
501
+ }
502
+ if (!this.activeSession || this.activeSession !== currentActiveSession) {
503
+ emitSessionLoadDebug(this, 'loadActiveSessionDetail:ignore-exception-session-changed', `requestSeq=${requestSeq}`);
504
+ return;
505
+ }
506
+ emitSessionLoadDebug(this, 'loadActiveSessionDetail:exception', e && e.message ? e.message : String(e));
507
+ this.activeSessionMessages = [];
508
+ this.sessionPreviewPendingVisibleCount = 0;
509
+ this.resetSessionPreviewMessageRender();
510
+ this.activeSessionDetailClipped = false;
511
+ this.activeSessionDetailError = '加载会话内容失败: ' + e.message;
512
+ this.cancelSessionTimelineSync();
513
+ this.sessionTimelineActiveKey = '';
514
+ clearSessionTimelineRefs(this);
515
+ } finally {
516
+ if (requestSeq === this.sessionDetailRequestSeq) {
517
+ this.sessionDetailLoading = false;
518
+ }
519
+ emitSessionLoadDebug(this, 'loadActiveSessionDetail:complete', `requestSeq=${requestSeq}`);
520
+ }
521
+ }
522
+
523
+ export async function loadMoreSessionMessages(stepSize) {
524
+ if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
525
+ return;
526
+ }
527
+ const total = Array.isArray(this.activeSessionMessages)
528
+ ? this.activeSessionMessages.length
529
+ : 0;
530
+ if (total <= 0) {
531
+ this.sessionPreviewVisibleCount = 0;
532
+ return;
533
+ }
534
+ const step = Number.isFinite(stepSize)
535
+ ? Math.max(1, Math.floor(stepSize))
536
+ : (Number.isFinite(this.sessionPreviewLoadStep)
537
+ ? Math.max(1, Math.floor(this.sessionPreviewLoadStep))
538
+ : 40);
539
+ const current = Number.isFinite(this.sessionPreviewVisibleCount)
540
+ ? Math.max(0, Math.floor(this.sessionPreviewVisibleCount))
541
+ : 0;
542
+ const targetVisible = current + step;
543
+ if (targetVisible <= total) {
544
+ this.sessionPreviewVisibleCount = Math.min(total, targetVisible);
545
+ return;
546
+ }
547
+
548
+ this.sessionPreviewVisibleCount = total;
549
+ if (this.sessionDetailLoading) {
550
+ return;
551
+ }
552
+
553
+ const totalKnownRaw = Number(this.activeSession && this.activeSession.messageCount);
554
+ const totalKnown = Number.isFinite(totalKnownRaw)
555
+ ? Math.max(0, Math.floor(totalKnownRaw))
556
+ : 0;
557
+ const hasMoreOnDisk = this.activeSessionDetailClipped || (totalKnown > total);
558
+ if (!hasMoreOnDisk) {
559
+ return;
560
+ }
561
+
562
+ const currentLimitRaw = Number(this.sessionDetailMessageLimit);
563
+ const currentLimit = Number.isFinite(currentLimitRaw)
564
+ ? Math.max(1, Math.floor(currentLimitRaw))
565
+ : Math.max(1, total);
566
+ const fetchStep = Number.isFinite(this.sessionDetailFetchStep)
567
+ ? Math.max(1, Math.floor(this.sessionDetailFetchStep))
568
+ : 80;
569
+ const limitCapRaw = Number(this.sessionDetailMessageLimitCap);
570
+ const limitCap = Number.isFinite(limitCapRaw)
571
+ ? Math.max(1, Math.floor(limitCapRaw))
572
+ : 1000;
573
+
574
+ let nextLimit = Math.max(currentLimit + fetchStep, targetVisible);
575
+ if (totalKnown > total) {
576
+ nextLimit = Math.min(nextLimit, totalKnown);
577
+ }
578
+ nextLimit = Math.min(nextLimit, limitCap);
579
+ if (nextLimit <= currentLimit) {
580
+ return;
581
+ }
582
+
583
+ this.sessionPreviewPendingVisibleCount = targetVisible;
584
+ this.sessionDetailMessageLimit = nextLimit;
585
+ this.sessionPreviewLoadingMore = true;
586
+ try {
587
+ await this.loadActiveSessionDetail({ preserveVisibleCount: true });
588
+ } finally {
589
+ this.sessionPreviewLoadingMore = false;
590
+ }
591
+ }