codexmate 0.0.24 → 0.0.26

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