codexmate 0.0.29 → 0.0.30

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 (143) hide show
  1. package/README.md +421 -421
  2. package/README.zh.md +354 -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 -384
  9. package/cli/config-health.js +454 -338
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -356
  12. package/cli/local-bridge.js +324 -0
  13. package/cli/openai-bridge.js +1653 -1576
  14. package/cli/openclaw-config.js +629 -629
  15. package/cli/session-convert-args.js +65 -65
  16. package/cli/session-convert-io.js +82 -82
  17. package/cli/session-convert.js +43 -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 +15481 -15340
  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 +417 -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 +645 -639
  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 +765 -765
  60. package/web-ui/modules/api.mjs +90 -90
  61. package/web-ui/modules/app.computed.dashboard.mjs +248 -225
  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 +999 -999
  65. package/web-ui/modules/app.constants.mjs +15 -15
  66. package/web-ui/modules/app.methods.agents.mjs +632 -632
  67. package/web-ui/modules/app.methods.claude-config.mjs +200 -200
  68. package/web-ui/modules/app.methods.codex-config.mjs +917 -892
  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 -761
  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 -493
  76. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  77. package/web-ui/modules/app.methods.session-actions.mjs +593 -593
  78. package/web-ui/modules/app.methods.session-browser.mjs +984 -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 +534 -533
  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 +3146 -3131
  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 -481
  95. package/web-ui/partials/index/layout-footer.html +13 -13
  96. package/web-ui/partials/index/layout-header.html +500 -500
  97. package/web-ui/partials/index/modal-config-template-agents.html +174 -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 +194 -194
  104. package/web-ui/partials/index/panel-config-codex.html +337 -323
  105. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  106. package/web-ui/partials/index/panel-dashboard.html +219 -186
  107. package/web-ui/partials/index/panel-docs.html +147 -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 +308 -316
  112. package/web-ui/partials/index/panel-settings.html +190 -190
  113. package/web-ui/partials/index/panel-trash.html +88 -88
  114. package/web-ui/partials/index/panel-usage.html +371 -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 +594 -576
  118. package/web-ui/source-bundle.cjs +233 -233
  119. package/web-ui/styles/base-theme.css +281 -281
  120. package/web-ui/styles/controls-forms.css +422 -422
  121. package/web-ui/styles/dashboard.css +406 -274
  122. package/web-ui/styles/docs-panel.css +271 -271
  123. package/web-ui/styles/feedback.css +108 -108
  124. package/web-ui/styles/health-check-dialog.css +144 -144
  125. package/web-ui/styles/layout-shell.css +626 -626
  126. package/web-ui/styles/modals-core.css +466 -466
  127. package/web-ui/styles/navigation-panels.css +391 -391
  128. package/web-ui/styles/openclaw-structured.css +266 -266
  129. package/web-ui/styles/plugins-panel.css +564 -523
  130. package/web-ui/styles/responsive.css +454 -454
  131. package/web-ui/styles/sessions-list.css +417 -419
  132. package/web-ui/styles/sessions-preview.css +407 -411
  133. package/web-ui/styles/sessions-toolbar-trash.css +334 -330
  134. package/web-ui/styles/sessions-usage.css +1040 -1040
  135. package/web-ui/styles/settings-panel.css +349 -349
  136. package/web-ui/styles/skills-list.css +305 -303
  137. package/web-ui/styles/skills-market.css +429 -406
  138. package/web-ui/styles/task-orchestration.css +822 -822
  139. package/web-ui/styles/titles-cards.css +472 -472
  140. package/web-ui/styles/trash-panel.css +90 -90
  141. package/web-ui/styles/webhook.css +81 -81
  142. package/web-ui/styles.css +23 -23
  143. package/web-ui.html +17 -17
@@ -1,576 +1,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
- // Default behavior: always land on Prompt Templates + Compose when entering Plugins.
191
- this.pluginsActiveId = 'prompt-templates';
192
- this.promptTemplatesMode = 'compose';
193
- this.promptComposerPickerVisible = false;
194
- let pluginsLoad = null;
195
- try {
196
- pluginsLoad = this.loadPluginsOverview({ silent: true });
197
- } catch (_) {
198
- pluginsLoad = null;
199
- }
200
- void Promise.resolve(pluginsLoad).catch(() => {});
201
- }
202
- if (nextTab === 'config' && this.configMode === 'claude') {
203
- const expectedTab = nextTab;
204
- const expectedConfigMode = this.configMode;
205
- const refresh = () => {
206
- if (this.mainTab !== expectedTab || this.configMode !== expectedConfigMode) return;
207
- this.refreshClaudeModelContext();
208
- };
209
- if (typeof this.scheduleAfterFrame === 'function') {
210
- this.scheduleAfterFrame(refresh);
211
- } else {
212
- refresh();
213
- }
214
- }
215
- }
216
-
217
- export async function loadSessions(api, options = {}) {
218
- if (this.sessionsLoading) {
219
- this.__sessionPendingLoadOptions = mergeSessionLoadOptions(
220
- this.__sessionPendingLoadOptions,
221
- options
222
- );
223
- emitSessionLoadDebug(this, 'loadSessions:queued-while-busy');
224
- return;
225
- }
226
- const normalizedOptions = normalizeSessionLoadOptions(options);
227
- const includeActiveDetail = shouldIncludeActiveSessionDetail(this, normalizedOptions);
228
- this.sessionsLoading = true;
229
- this.activeSessionDetailError = '';
230
- let loadSucceeded = false;
231
- const params = buildSessionListParams({
232
- source: this.sessionFilterSource,
233
- pathFilter: this.sessionPathFilter,
234
- query: this.sessionQuery,
235
- roleFilter: this.sessionRoleFilter,
236
- timeRangePreset: this.sessionTimePreset,
237
- forceRefresh: normalizedOptions.forceRefresh
238
- });
239
- emitSessionLoadDebug(
240
- this,
241
- 'loadSessions:start',
242
- `source=${params.source || ''}\nforceRefresh=${!!params.forceRefresh}\nincludeActiveDetail=${includeActiveDetail}`
243
- );
244
- let pendingOptions = null;
245
- try {
246
- const res = await api('list-sessions', params);
247
- if (res.error) {
248
- emitSessionLoadDebug(this, 'loadSessions:error-response', `error=${res.error}`);
249
- this.showMessage(res.error, 'error');
250
- this.sessionsList = [];
251
- if (typeof this.primeSessionListRender === 'function') {
252
- this.primeSessionListRender();
253
- }
254
- this.activeSession = null;
255
- this.activeSessionMessages = [];
256
- this.resetSessionDetailPagination();
257
- this.resetSessionPreviewMessageRender();
258
- this.activeSessionDetailClipped = false;
259
- this.cancelSessionTimelineSync();
260
- this.sessionTimelineActiveKey = '';
261
- clearSessionTimelineRefs(this);
262
- } else {
263
- loadSucceeded = true;
264
- this.sessionsList = Array.isArray(res.sessions) ? res.sessions : [];
265
- emitSessionLoadDebug(this, 'loadSessions:response', `sessions=${this.sessionsList.length}`);
266
- if (typeof this.primeSessionListRender === 'function') {
267
- this.primeSessionListRender();
268
- }
269
- this.syncSessionPathOptionsForSource(
270
- this.sessionFilterSource,
271
- this.extractPathOptionsFromSessions(this.sessionsList),
272
- true
273
- );
274
- if (this.sessionsList.length === 0) {
275
- emitSessionLoadDebug(this, 'loadSessions:empty');
276
- this.activeSession = null;
277
- this.activeSessionMessages = [];
278
- this.resetSessionDetailPagination();
279
- this.resetSessionPreviewMessageRender();
280
- this.activeSessionDetailClipped = false;
281
- this.cancelSessionTimelineSync();
282
- this.sessionTimelineActiveKey = '';
283
- clearSessionTimelineRefs(this);
284
- } else {
285
- const oldKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
286
- const matched = this.sessionsList.find(item => this.getSessionExportKey(item) === oldKey);
287
- this.activeSession = matched || this.sessionsList[0];
288
- emitSessionLoadDebug(
289
- this,
290
- 'loadSessions:active-session-selected',
291
- `sessionId=${this.activeSession && this.activeSession.sessionId ? this.activeSession.sessionId : ''}`
292
- );
293
- this.activeSessionMessages = [];
294
- this.resetSessionDetailPagination();
295
- this.resetSessionPreviewMessageRender();
296
- this.activeSessionDetailError = '';
297
- this.activeSessionDetailClipped = false;
298
- this.cancelSessionTimelineSync();
299
- this.sessionTimelineActiveKey = '';
300
- clearSessionTimelineRefs(this);
301
- if (includeActiveDetail) {
302
- emitSessionLoadDebug(
303
- this,
304
- 'loadSessions:hydrate-active-detail',
305
- `sessionId=${this.activeSession && this.activeSession.sessionId ? this.activeSession.sessionId : ''}`
306
- );
307
- await this.loadActiveSessionDetail();
308
- }
309
- }
310
- }
311
- } catch (e) {
312
- emitSessionLoadDebug(this, 'loadSessions:exception', e && e.message ? e.message : String(e));
313
- this.sessionsList = [];
314
- if (typeof this.primeSessionListRender === 'function') {
315
- this.primeSessionListRender();
316
- }
317
- this.activeSession = null;
318
- this.activeSessionMessages = [];
319
- this.resetSessionDetailPagination();
320
- this.resetSessionPreviewMessageRender();
321
- this.activeSessionDetailClipped = false;
322
- this.cancelSessionTimelineSync();
323
- this.sessionTimelineActiveKey = '';
324
- clearSessionTimelineRefs(this);
325
- this.showMessage('加载会话失败', 'error');
326
- } finally {
327
- this.sessionsLoading = false;
328
- if (loadSucceeded) {
329
- this.sessionsLoadedOnce = true;
330
- }
331
- pendingOptions = this.__sessionPendingLoadOptions || null;
332
- this.__sessionPendingLoadOptions = null;
333
- emitSessionLoadDebug(
334
- this,
335
- 'loadSessions:complete',
336
- `loadSucceeded=${loadSucceeded}\npendingReload=${!!pendingOptions}`
337
- );
338
- }
339
- if (pendingOptions) {
340
- emitSessionLoadDebug(this, 'loadSessions:replay-pending-request');
341
- return loadSessions.call(this, api, pendingOptions);
342
- }
343
- }
344
-
345
- export async function loadActiveSessionDetail(api, options = {}) {
346
- if (!this.activeSession) {
347
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:skip-no-active-session');
348
- this.activeSessionMessages = [];
349
- this.resetSessionDetailPagination();
350
- this.resetSessionPreviewMessageRender();
351
- this.activeSessionDetailError = '';
352
- this.activeSessionDetailClipped = false;
353
- this.cancelSessionTimelineSync();
354
- this.sessionTimelineActiveKey = '';
355
- clearSessionTimelineRefs(this);
356
- return;
357
- }
358
-
359
- const currentActiveSession = this.activeSession;
360
- const requestSeq = ++this.sessionDetailRequestSeq;
361
- this.sessionDetailLoading = true;
362
- this.activeSessionDetailError = '';
363
- emitSessionLoadDebug(
364
- this,
365
- 'loadActiveSessionDetail:start',
366
- `sessionId=${currentActiveSession && currentActiveSession.sessionId ? currentActiveSession.sessionId : ''}\nrequestSeq=${requestSeq}`
367
- );
368
- const fallbackLimit = Number.isFinite(this.sessionDetailInitialMessageLimit)
369
- ? Math.max(1, Math.floor(this.sessionDetailInitialMessageLimit))
370
- : 80;
371
- const rawLimit = Number(this.sessionDetailMessageLimit);
372
- const messageLimit = Number.isFinite(rawLimit)
373
- ? Math.max(1, Math.floor(rawLimit))
374
- : fallbackLimit;
375
- const preview = this.mainTab === 'sessions' && !this.sessionStandalone;
376
- try {
377
- const res = await api('session-detail', {
378
- source: this.activeSession.source,
379
- sessionId: this.activeSession.sessionId,
380
- filePath: this.activeSession.filePath,
381
- messageLimit,
382
- preview
383
- });
384
-
385
- if (requestSeq !== this.sessionDetailRequestSeq) {
386
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:stale-request-seq', `requestSeq=${requestSeq}`);
387
- return;
388
- }
389
- if (!this.activeSession || this.activeSession !== currentActiveSession) {
390
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:active-session-changed', `requestSeq=${requestSeq}`);
391
- return;
392
- }
393
-
394
- if (res.error) {
395
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:error-response', `error=${res.error}`);
396
- this.activeSessionMessages = [];
397
- this.resetSessionPreviewMessageRender();
398
- this.activeSessionDetailClipped = false;
399
- this.activeSessionDetailError = res.error;
400
- this.cancelSessionTimelineSync();
401
- this.sessionTimelineActiveKey = '';
402
- clearSessionTimelineRefs(this);
403
- return;
404
- }
405
-
406
- const rawMessages = Array.isArray(res.messages) ? res.messages : [];
407
- const normalizedMessages = rawMessages.map((message) => Object.freeze(this.normalizeSessionMessage(message)));
408
- this.activeSessionMessages = Object.freeze(normalizedMessages);
409
- emitSessionLoadDebug(
410
- this,
411
- 'loadActiveSessionDetail:messages-ready',
412
- `sessionId=${currentActiveSession && currentActiveSession.sessionId ? currentActiveSession.sessionId : ''}\nmessages=${normalizedMessages.length}\nclipped=${!!res.clipped}`
413
- );
414
- if (typeof this.invalidateSessionTimelineMeasurementCache === 'function') {
415
- this.invalidateSessionTimelineMeasurementCache(true);
416
- }
417
- this.activeSessionDetailClipped = !!res.clipped;
418
- const responseLimitRaw = Number(res.messageLimit);
419
- this.sessionDetailMessageLimit = Number.isFinite(responseLimitRaw)
420
- ? Math.max(1, Math.floor(responseLimitRaw))
421
- : messageLimit;
422
- if (res.sourceLabel) {
423
- this.activeSession.sourceLabel = res.sourceLabel;
424
- }
425
- if (typeof res.derived === 'boolean') {
426
- this.activeSession.derived = res.derived;
427
- }
428
- if (res.sessionId) {
429
- this.activeSession.sessionId = res.sessionId;
430
- if (!this.activeSession.title) {
431
- this.activeSession.title = res.sessionId;
432
- }
433
- }
434
- if (res.filePath) {
435
- this.activeSession.filePath = res.filePath;
436
- }
437
- if (res.updatedAt) {
438
- this.activeSession.updatedAt = res.updatedAt;
439
- }
440
- if (res.cwd) {
441
- this.activeSession.cwd = res.cwd;
442
- }
443
- if (Number.isFinite(res.totalMessages)) {
444
- this.syncActiveSessionMessageCount(res.totalMessages);
445
- }
446
- if (this.mainTab === 'sessions' && this.sessionPreviewRenderEnabled) {
447
- const preserveVisibleCount = !!options.preserveVisibleCount;
448
- const pendingVisibleRaw = Number(this.sessionPreviewPendingVisibleCount);
449
- const pendingVisible = Number.isFinite(pendingVisibleRaw)
450
- ? Math.max(0, Math.floor(pendingVisibleRaw))
451
- : 0;
452
- if (preserveVisibleCount && pendingVisible > 0) {
453
- this.sessionPreviewVisibleCount = Math.min(pendingVisible, this.activeSessionMessages.length);
454
- } else {
455
- this.primeSessionPreviewMessageRender();
456
- }
457
- }
458
- this.sessionPreviewPendingVisibleCount = 0;
459
- this.$nextTick(() => {
460
- if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
461
- return;
462
- }
463
- this.updateSessionTimelineOffset();
464
- if (this.sessionTimelineEnabled) {
465
- const currentSession = this.activeSession;
466
- const syncTask = () => {
467
- if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
468
- return;
469
- }
470
- if (!this.activeSession || this.activeSession !== currentSession) {
471
- return;
472
- }
473
- this.scheduleSessionTimelineSync();
474
- };
475
- if (typeof this.scheduleAfterFrame === 'function') {
476
- this.scheduleAfterFrame(syncTask);
477
- return;
478
- }
479
- syncTask();
480
- }
481
- });
482
- } catch (e) {
483
- if (requestSeq !== this.sessionDetailRequestSeq) {
484
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:ignore-exception-stale-request', `requestSeq=${requestSeq}`);
485
- return;
486
- }
487
- if (!this.activeSession || this.activeSession !== currentActiveSession) {
488
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:ignore-exception-session-changed', `requestSeq=${requestSeq}`);
489
- return;
490
- }
491
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:exception', e && e.message ? e.message : String(e));
492
- this.activeSessionMessages = [];
493
- this.sessionPreviewPendingVisibleCount = 0;
494
- this.resetSessionPreviewMessageRender();
495
- this.activeSessionDetailClipped = false;
496
- this.activeSessionDetailError = '加载会话内容失败: ' + e.message;
497
- this.cancelSessionTimelineSync();
498
- this.sessionTimelineActiveKey = '';
499
- clearSessionTimelineRefs(this);
500
- } finally {
501
- if (requestSeq === this.sessionDetailRequestSeq) {
502
- this.sessionDetailLoading = false;
503
- }
504
- emitSessionLoadDebug(this, 'loadActiveSessionDetail:complete', `requestSeq=${requestSeq}`);
505
- }
506
- }
507
-
508
- export async function loadMoreSessionMessages(stepSize) {
509
- if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
510
- return;
511
- }
512
- const total = Array.isArray(this.activeSessionMessages)
513
- ? this.activeSessionMessages.length
514
- : 0;
515
- if (total <= 0) {
516
- this.sessionPreviewVisibleCount = 0;
517
- return;
518
- }
519
- const step = Number.isFinite(stepSize)
520
- ? Math.max(1, Math.floor(stepSize))
521
- : (Number.isFinite(this.sessionPreviewLoadStep)
522
- ? Math.max(1, Math.floor(this.sessionPreviewLoadStep))
523
- : 40);
524
- const current = Number.isFinite(this.sessionPreviewVisibleCount)
525
- ? Math.max(0, Math.floor(this.sessionPreviewVisibleCount))
526
- : 0;
527
- const targetVisible = current + step;
528
- if (targetVisible <= total) {
529
- this.sessionPreviewVisibleCount = Math.min(total, targetVisible);
530
- return;
531
- }
532
-
533
- this.sessionPreviewVisibleCount = total;
534
- if (this.sessionDetailLoading) {
535
- return;
536
- }
537
-
538
- const totalKnownRaw = Number(this.activeSession && this.activeSession.messageCount);
539
- const totalKnown = Number.isFinite(totalKnownRaw)
540
- ? Math.max(0, Math.floor(totalKnownRaw))
541
- : 0;
542
- const hasMoreOnDisk = this.activeSessionDetailClipped || (totalKnown > total);
543
- if (!hasMoreOnDisk) {
544
- return;
545
- }
546
-
547
- const currentLimitRaw = Number(this.sessionDetailMessageLimit);
548
- const currentLimit = Number.isFinite(currentLimitRaw)
549
- ? Math.max(1, Math.floor(currentLimitRaw))
550
- : Math.max(1, total);
551
- const fetchStep = Number.isFinite(this.sessionDetailFetchStep)
552
- ? Math.max(1, Math.floor(this.sessionDetailFetchStep))
553
- : 80;
554
- const limitCapRaw = Number(this.sessionDetailMessageLimitCap);
555
- const limitCap = Number.isFinite(limitCapRaw)
556
- ? Math.max(1, Math.floor(limitCapRaw))
557
- : 1000;
558
-
559
- let nextLimit = Math.max(currentLimit + fetchStep, targetVisible);
560
- if (totalKnown > total) {
561
- nextLimit = Math.min(nextLimit, totalKnown);
562
- }
563
- nextLimit = Math.min(nextLimit, limitCap);
564
- if (nextLimit <= currentLimit) {
565
- return;
566
- }
567
-
568
- this.sessionPreviewPendingVisibleCount = targetVisible;
569
- this.sessionDetailMessageLimit = nextLimit;
570
- this.sessionPreviewLoadingMore = true;
571
- try {
572
- await this.loadActiveSessionDetail({ preserveVisibleCount: true });
573
- } finally {
574
- this.sessionPreviewLoadingMore = false;
575
- }
576
- }
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
+ }