codexmate 0.0.21 → 0.0.23

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