codexmate 0.0.30 → 0.0.32

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 (144) hide show
  1. package/README.md +363 -421
  2. package/README.zh.md +371 -354
  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 +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 +324 -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 -65
  16. package/cli/session-convert-io.js +82 -82
  17. package/cli/session-convert.js +150 -43
  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/zip-commands.js +510 -510
  23. package/cli.js +15829 -15481
  24. package/lib/automation.js +404 -404
  25. package/lib/cli-file-utils.js +151 -151
  26. package/lib/cli-models-utils.js +440 -440
  27. package/lib/cli-network-utils.js +190 -190
  28. package/lib/cli-path-utils.js +85 -85
  29. package/lib/cli-session-utils.js +121 -121
  30. package/lib/cli-sessions.js +426 -417
  31. package/lib/cli-utils.js +155 -155
  32. package/lib/cli-webhook.js +126 -126
  33. package/lib/download-artifacts.js +92 -92
  34. package/lib/mcp-stdio.js +453 -453
  35. package/lib/task-orchestrator.js +869 -869
  36. package/lib/text-diff.js +303 -303
  37. package/lib/workflow-engine.js +340 -340
  38. package/package.json +76 -76
  39. package/plugins/README.md +20 -20
  40. package/plugins/README.zh-CN.md +20 -20
  41. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  42. package/plugins/prompt-templates/computed.mjs +253 -253
  43. package/plugins/prompt-templates/index.mjs +8 -8
  44. package/plugins/prompt-templates/manifest.mjs +15 -15
  45. package/plugins/prompt-templates/methods.mjs +553 -553
  46. package/plugins/prompt-templates/overview.mjs +91 -91
  47. package/plugins/prompt-templates/ownership.mjs +19 -19
  48. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  49. package/plugins/prompt-templates/storage.mjs +64 -64
  50. package/plugins/registry.mjs +16 -16
  51. package/web-ui/app.js +647 -645
  52. package/web-ui/index.html +36 -36
  53. package/web-ui/logic.agents-diff.mjs +386 -386
  54. package/web-ui/logic.claude.mjs +168 -168
  55. package/web-ui/logic.codex.mjs +69 -69
  56. package/web-ui/logic.mjs +5 -5
  57. package/web-ui/logic.runtime.mjs +128 -128
  58. package/web-ui/logic.session-convert.mjs +70 -70
  59. package/web-ui/logic.sessions.mjs +781 -765
  60. package/web-ui/modules/api.mjs +90 -90
  61. package/web-ui/modules/app.computed.dashboard.mjs +248 -248
  62. package/web-ui/modules/app.computed.index.mjs +17 -17
  63. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  64. package/web-ui/modules/app.computed.session.mjs +693 -999
  65. package/web-ui/modules/app.constants.mjs +15 -15
  66. package/web-ui/modules/app.methods.agents.mjs +651 -632
  67. package/web-ui/modules/app.methods.claude-config.mjs +200 -200
  68. package/web-ui/modules/app.methods.codex-config.mjs +861 -917
  69. package/web-ui/modules/app.methods.index.mjs +94 -94
  70. package/web-ui/modules/app.methods.install.mjs +205 -205
  71. package/web-ui/modules/app.methods.navigation.mjs +774 -774
  72. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  73. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  74. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  75. package/web-ui/modules/app.methods.providers.mjs +529 -529
  76. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  77. package/web-ui/modules/app.methods.session-actions.mjs +591 -593
  78. package/web-ui/modules/app.methods.session-browser.mjs +1012 -984
  79. package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
  80. package/web-ui/modules/app.methods.session-trash.mjs +438 -438
  81. package/web-ui/modules/app.methods.startup-claude.mjs +537 -534
  82. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  83. package/web-ui/modules/app.methods.webhook.mjs +79 -79
  84. package/web-ui/modules/config-mode.computed.mjs +124 -124
  85. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  86. package/web-ui/modules/i18n.dict.mjs +3177 -3146
  87. package/web-ui/modules/i18n.mjs +62 -62
  88. package/web-ui/modules/plugins.computed.mjs +3 -3
  89. package/web-ui/modules/plugins.methods.mjs +3 -3
  90. package/web-ui/modules/plugins.storage.mjs +11 -11
  91. package/web-ui/modules/provider-url-display.mjs +17 -17
  92. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  93. package/web-ui/modules/skills.computed.mjs +107 -107
  94. package/web-ui/modules/skills.methods.mjs +482 -482
  95. package/web-ui/partials/index/layout-footer.html +13 -13
  96. package/web-ui/partials/index/layout-header.html +503 -500
  97. package/web-ui/partials/index/modal-config-template-agents.html +185 -174
  98. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  99. package/web-ui/partials/index/modal-health-check.html +45 -45
  100. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  101. package/web-ui/partials/index/modal-skills.html +200 -200
  102. package/web-ui/partials/index/modals-basic.html +162 -162
  103. package/web-ui/partials/index/panel-config-claude.html +136 -194
  104. package/web-ui/partials/index/panel-config-codex.html +197 -337
  105. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  106. package/web-ui/partials/index/panel-dashboard.html +219 -219
  107. package/web-ui/partials/index/panel-docs.html +115 -147
  108. package/web-ui/partials/index/panel-market.html +177 -177
  109. package/web-ui/partials/index/panel-orchestration.html +391 -391
  110. package/web-ui/partials/index/panel-plugins.html +253 -253
  111. package/web-ui/partials/index/panel-sessions.html +313 -308
  112. package/web-ui/partials/index/panel-settings.html +190 -190
  113. package/web-ui/partials/index/panel-trash.html +83 -88
  114. package/web-ui/partials/index/panel-usage.html +138 -371
  115. package/web-ui/res/json5.min.js +1 -1
  116. package/web-ui/res/vue.global.prod.js +13 -13
  117. package/web-ui/session-helpers.mjs +591 -594
  118. package/web-ui/source-bundle.cjs +233 -233
  119. package/web-ui/styles/base-theme.css +281 -281
  120. package/web-ui/styles/bridge-pool.css +197 -0
  121. package/web-ui/styles/controls-forms.css +433 -422
  122. package/web-ui/styles/dashboard.css +406 -406
  123. package/web-ui/styles/docs-panel.css +245 -271
  124. package/web-ui/styles/feedback.css +108 -108
  125. package/web-ui/styles/health-check-dialog.css +144 -144
  126. package/web-ui/styles/layout-shell.css +638 -626
  127. package/web-ui/styles/modals-core.css +466 -466
  128. package/web-ui/styles/navigation-panels.css +391 -391
  129. package/web-ui/styles/openclaw-structured.css +266 -266
  130. package/web-ui/styles/plugins-panel.css +564 -564
  131. package/web-ui/styles/responsive.css +392 -454
  132. package/web-ui/styles/sessions-list.css +647 -417
  133. package/web-ui/styles/sessions-preview.css +407 -407
  134. package/web-ui/styles/sessions-toolbar-trash.css +518 -334
  135. package/web-ui/styles/sessions-usage.css +588 -1040
  136. package/web-ui/styles/settings-panel.css +349 -349
  137. package/web-ui/styles/skills-list.css +305 -305
  138. package/web-ui/styles/skills-market.css +429 -429
  139. package/web-ui/styles/task-orchestration.css +822 -822
  140. package/web-ui/styles/titles-cards.css +472 -472
  141. package/web-ui/styles/trash-panel.css +90 -90
  142. package/web-ui/styles/webhook.css +81 -81
  143. package/web-ui/styles.css +24 -23
  144. package/web-ui.html +17 -17
@@ -1,594 +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 (typeof res.derived === 'boolean') {
424
- this.activeSession.derived = res.derived;
425
- }
426
- if (res.sessionId) {
427
- this.activeSession.sessionId = res.sessionId;
428
- if (!this.activeSession.title) {
429
- this.activeSession.title = res.sessionId;
430
- }
431
- }
432
- if (res.filePath) {
433
- this.activeSession.filePath = res.filePath;
434
- }
435
- if (res.updatedAt) {
436
- this.activeSession.updatedAt = res.updatedAt;
437
- }
438
- if (res.cwd) {
439
- this.activeSession.cwd = res.cwd;
440
- }
441
- if (Number.isFinite(res.totalMessages)) {
442
- this.syncActiveSessionMessageCount(res.totalMessages);
443
- }
444
- if (this.mainTab === 'sessions' && this.sessionPreviewRenderEnabled) {
445
- const preserveVisibleCount = !!options.preserveVisibleCount;
446
- const pendingVisibleRaw = Number(this.sessionPreviewPendingVisibleCount);
447
- const pendingVisible = Number.isFinite(pendingVisibleRaw)
448
- ? Math.max(0, Math.floor(pendingVisibleRaw))
449
- : 0;
450
- if (preserveVisibleCount && pendingVisible > 0) {
451
- this.sessionPreviewVisibleCount = Math.min(pendingVisible, this.activeSessionMessages.length);
452
- } else {
453
- this.primeSessionPreviewMessageRender();
454
- }
455
- }
456
- this.sessionPreviewPendingVisibleCount = 0;
457
- if (this.activeSessionDetailClipped) {
458
- const autoFetchSession = currentActiveSession;
459
- this.$nextTick(() => {
460
- if (this.activeSession !== autoFetchSession) return;
461
- if (this.sessionDetailLoading) return;
462
- if (!this.activeSessionDetailClipped) return;
463
- const currentLimit = Number(this.sessionDetailMessageLimit);
464
- const fetchStep = Number.isFinite(this.sessionDetailFetchStep)
465
- ? Math.max(1, Math.floor(this.sessionDetailFetchStep))
466
- : 300;
467
- const limitCap = Number.isFinite(this.sessionDetailMessageLimitCap)
468
- ? Math.max(1, Math.floor(this.sessionDetailMessageLimitCap))
469
- : 1000;
470
- const nextLimit = Math.min(currentLimit + fetchStep, limitCap);
471
- if (nextLimit <= currentLimit) return;
472
- this.sessionDetailMessageLimit = nextLimit;
473
- this.sessionPreviewPendingVisibleCount = nextLimit;
474
- void this.loadActiveSessionDetail({ preserveVisibleCount: true });
475
- });
476
- }
477
- this.$nextTick(() => {
478
- if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
479
- return;
480
- }
481
- this.updateSessionTimelineOffset();
482
- if (this.sessionTimelineEnabled) {
483
- const currentSession = this.activeSession;
484
- const syncTask = () => {
485
- if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
486
- return;
487
- }
488
- if (!this.activeSession || this.activeSession !== currentSession) {
489
- return;
490
- }
491
- this.scheduleSessionTimelineSync();
492
- };
493
- if (typeof this.scheduleAfterFrame === 'function') {
494
- this.scheduleAfterFrame(syncTask);
495
- return;
496
- }
497
- syncTask();
498
- }
499
- });
500
- } catch (e) {
501
- if (requestSeq !== this.sessionDetailRequestSeq) {
502
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:ignore-exception-stale-request', `requestSeq=${requestSeq}`);
503
- return;
504
- }
505
- if (!this.activeSession || this.activeSession !== currentActiveSession) {
506
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:ignore-exception-session-changed', `requestSeq=${requestSeq}`);
507
- return;
508
- }
509
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:exception', e && e.message ? e.message : String(e));
510
- this.activeSessionMessages = [];
511
- this.sessionPreviewPendingVisibleCount = 0;
512
- this.resetSessionPreviewMessageRender();
513
- this.activeSessionDetailClipped = false;
514
- this.activeSessionDetailError = '加载会话内容失败: ' + e.message;
515
- this.cancelSessionTimelineSync();
516
- this.sessionTimelineActiveKey = '';
517
- clearSessionTimelineRefs(this);
518
- } finally {
519
- if (requestSeq === this.sessionDetailRequestSeq) {
520
- this.sessionDetailLoading = false;
521
- }
522
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:complete', `requestSeq=${requestSeq}`);
523
- }
524
- }
525
-
526
- export async function loadMoreSessionMessages(stepSize) {
527
- if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
528
- return;
529
- }
530
- const total = Array.isArray(this.activeSessionMessages)
531
- ? this.activeSessionMessages.length
532
- : 0;
533
- if (total <= 0) {
534
- this.sessionPreviewVisibleCount = 0;
535
- return;
536
- }
537
- const step = Number.isFinite(stepSize)
538
- ? Math.max(1, Math.floor(stepSize))
539
- : (Number.isFinite(this.sessionPreviewLoadStep)
540
- ? Math.max(1, Math.floor(this.sessionPreviewLoadStep))
541
- : 40);
542
- const current = Number.isFinite(this.sessionPreviewVisibleCount)
543
- ? Math.max(0, Math.floor(this.sessionPreviewVisibleCount))
544
- : 0;
545
- const targetVisible = current + step;
546
- if (targetVisible <= total) {
547
- this.sessionPreviewVisibleCount = Math.min(total, targetVisible);
548
- return;
549
- }
550
-
551
- this.sessionPreviewVisibleCount = total;
552
- if (this.sessionDetailLoading) {
553
- return;
554
- }
555
-
556
- const totalKnownRaw = Number(this.activeSession && this.activeSession.messageCount);
557
- const totalKnown = Number.isFinite(totalKnownRaw)
558
- ? Math.max(0, Math.floor(totalKnownRaw))
559
- : 0;
560
- const hasMoreOnDisk = this.activeSessionDetailClipped || (totalKnown > total);
561
- if (!hasMoreOnDisk) {
562
- return;
563
- }
564
-
565
- const currentLimitRaw = Number(this.sessionDetailMessageLimit);
566
- const currentLimit = Number.isFinite(currentLimitRaw)
567
- ? Math.max(1, Math.floor(currentLimitRaw))
568
- : Math.max(1, total);
569
- const fetchStep = Number.isFinite(this.sessionDetailFetchStep)
570
- ? Math.max(1, Math.floor(this.sessionDetailFetchStep))
571
- : 80;
572
- const limitCapRaw = Number(this.sessionDetailMessageLimitCap);
573
- const limitCap = Number.isFinite(limitCapRaw)
574
- ? Math.max(1, Math.floor(limitCapRaw))
575
- : 1000;
576
-
577
- let nextLimit = Math.max(currentLimit + fetchStep, targetVisible);
578
- if (totalKnown > total) {
579
- nextLimit = Math.min(nextLimit, totalKnown);
580
- }
581
- nextLimit = Math.min(nextLimit, limitCap);
582
- if (nextLimit <= currentLimit) {
583
- return;
584
- }
585
-
586
- this.sessionPreviewPendingVisibleCount = targetVisible;
587
- this.sessionDetailMessageLimit = nextLimit;
588
- this.sessionPreviewLoadingMore = true;
589
- try {
590
- await this.loadActiveSessionDetail({ preserveVisibleCount: true });
591
- } finally {
592
- this.sessionPreviewLoadingMore = false;
593
- }
594
- }
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
+ }