codexmate 0.0.41 → 0.0.43

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 (155) hide show
  1. package/README.md +168 -168
  2. package/README.zh.md +168 -168
  3. package/cli/agents-files.js +230 -230
  4. package/cli/analytics-export-args.js +68 -68
  5. package/cli/archive-helpers.js +453 -453
  6. package/cli/auth-profiles.js +375 -375
  7. package/cli/builtin-proxy.js +2144 -2144
  8. package/cli/claude-proxy.js +1022 -1022
  9. package/cli/config-bootstrap.js +407 -407
  10. package/cli/config-health.js +454 -454
  11. package/cli/doctor-core.js +903 -903
  12. package/cli/import-skills-url.js +356 -356
  13. package/cli/local-bridge.js +556 -556
  14. package/cli/openai-bridge.js +1984 -1984
  15. package/cli/openclaw-config.js +629 -629
  16. package/cli/session-convert-args.js +69 -69
  17. package/cli/session-convert-io.js +82 -82
  18. package/cli/session-convert.js +150 -150
  19. package/cli/session-usage.concurrent.js +28 -28
  20. package/cli/session-usage.js +304 -304
  21. package/cli/session-usage.models.js +176 -176
  22. package/cli/skills.js +1141 -1141
  23. package/cli/update.js +171 -171
  24. package/cli/zip-commands.js +510 -510
  25. package/cli.js +16495 -16458
  26. package/lib/automation.js +404 -404
  27. package/lib/cli-file-utils.js +151 -151
  28. package/lib/cli-models-utils.js +440 -440
  29. package/lib/cli-network-utils.js +190 -190
  30. package/lib/cli-path-utils.js +85 -85
  31. package/lib/cli-session-utils.js +121 -121
  32. package/lib/cli-sessions.js +427 -427
  33. package/lib/cli-utils.js +155 -155
  34. package/lib/cli-webhook.js +154 -154
  35. package/lib/download-artifacts.js +92 -92
  36. package/lib/mcp-stdio.js +453 -453
  37. package/lib/task-orchestrator.js +869 -869
  38. package/lib/text-diff.js +303 -303
  39. package/lib/win-tray.js +119 -119
  40. package/lib/workflow-engine.js +340 -340
  41. package/package.json +77 -77
  42. package/plugins/README.md +20 -20
  43. package/plugins/README.zh-CN.md +20 -20
  44. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  45. package/plugins/prompt-templates/computed.mjs +311 -311
  46. package/plugins/prompt-templates/index.mjs +8 -8
  47. package/plugins/prompt-templates/manifest.mjs +18 -18
  48. package/plugins/prompt-templates/methods.mjs +553 -553
  49. package/plugins/prompt-templates/overview.mjs +91 -91
  50. package/plugins/prompt-templates/ownership.mjs +19 -19
  51. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  52. package/plugins/prompt-templates/storage.mjs +64 -64
  53. package/plugins/registry.mjs +16 -16
  54. package/web-ui/app.js +705 -695
  55. package/web-ui/index.html +37 -37
  56. package/web-ui/logic.agents-diff.mjs +386 -386
  57. package/web-ui/logic.claude.mjs +172 -172
  58. package/web-ui/logic.codex.mjs +69 -69
  59. package/web-ui/logic.mjs +5 -5
  60. package/web-ui/logic.runtime.mjs +128 -128
  61. package/web-ui/logic.session-convert.mjs +70 -70
  62. package/web-ui/logic.sessions.mjs +782 -782
  63. package/web-ui/modules/api.mjs +90 -90
  64. package/web-ui/modules/app.computed.dashboard.mjs +252 -252
  65. package/web-ui/modules/app.computed.index.mjs +17 -17
  66. package/web-ui/modules/app.computed.main-tabs.mjs +214 -214
  67. package/web-ui/modules/app.computed.session.mjs +876 -876
  68. package/web-ui/modules/app.constants.mjs +15 -15
  69. package/web-ui/modules/app.methods.agents.mjs +651 -651
  70. package/web-ui/modules/app.methods.claude-config.mjs +412 -412
  71. package/web-ui/modules/app.methods.codex-config.mjs +869 -869
  72. package/web-ui/modules/app.methods.index.mjs +96 -96
  73. package/web-ui/modules/app.methods.install.mjs +205 -205
  74. package/web-ui/modules/app.methods.navigation.mjs +804 -804
  75. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  76. package/web-ui/modules/app.methods.openclaw-editing.mjs +420 -420
  77. package/web-ui/modules/app.methods.openclaw-persist.mjs +375 -375
  78. package/web-ui/modules/app.methods.providers.mjs +602 -601
  79. package/web-ui/modules/app.methods.runtime.mjs +426 -420
  80. package/web-ui/modules/app.methods.session-actions.mjs +617 -591
  81. package/web-ui/modules/app.methods.session-browser.mjs +1018 -1018
  82. package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
  83. package/web-ui/modules/app.methods.session-trash.mjs +468 -468
  84. package/web-ui/modules/app.methods.startup-claude.mjs +557 -554
  85. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  86. package/web-ui/modules/app.methods.tool-config-permissions.mjs +90 -87
  87. package/web-ui/modules/app.methods.webhook.mjs +87 -87
  88. package/web-ui/modules/config-mode.computed.mjs +124 -124
  89. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  90. package/web-ui/modules/i18n/locales/en.mjs +1187 -1140
  91. package/web-ui/modules/i18n/locales/ja.mjs +1178 -1130
  92. package/web-ui/modules/i18n/locales/vi.mjs +294 -239
  93. package/web-ui/modules/i18n/locales/zh.mjs +1190 -1143
  94. package/web-ui/modules/i18n.dict.mjs +14 -14
  95. package/web-ui/modules/i18n.mjs +111 -111
  96. package/web-ui/modules/plugins.computed.mjs +3 -3
  97. package/web-ui/modules/plugins.methods.mjs +3 -3
  98. package/web-ui/modules/plugins.storage.mjs +11 -11
  99. package/web-ui/modules/provider-url-display.mjs +17 -17
  100. package/web-ui/modules/sessions-filters-url.mjs +138 -138
  101. package/web-ui/modules/skills.computed.mjs +107 -107
  102. package/web-ui/modules/skills.methods.mjs +513 -513
  103. package/web-ui/partials/index/layout-footer.html +13 -13
  104. package/web-ui/partials/index/layout-header.html +478 -478
  105. package/web-ui/partials/index/modal-config-template-agents.html +185 -185
  106. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  107. package/web-ui/partials/index/modal-health-check.html +45 -45
  108. package/web-ui/partials/index/modal-openclaw-config.html +344 -344
  109. package/web-ui/partials/index/modal-skills.html +200 -200
  110. package/web-ui/partials/index/modal-webhook.html +42 -42
  111. package/web-ui/partials/index/modals-basic.html +263 -263
  112. package/web-ui/partials/index/panel-config-claude.html +187 -187
  113. package/web-ui/partials/index/panel-config-codex.html +205 -205
  114. package/web-ui/partials/index/panel-config-openclaw.html +89 -89
  115. package/web-ui/partials/index/panel-dashboard.html +171 -171
  116. package/web-ui/partials/index/panel-docs.html +114 -114
  117. package/web-ui/partials/index/panel-market.html +104 -104
  118. package/web-ui/partials/index/panel-orchestration.html +391 -391
  119. package/web-ui/partials/index/panel-plugins.html +253 -253
  120. package/web-ui/partials/index/panel-sessions.html +325 -319
  121. package/web-ui/partials/index/panel-settings.html +181 -181
  122. package/web-ui/partials/index/panel-trash.html +82 -82
  123. package/web-ui/partials/index/panel-usage.html +181 -181
  124. package/web-ui/res/json5.min.js +1 -1
  125. package/web-ui/res/vue.global.prod.js +13 -13
  126. package/web-ui/res/vue.runtime.global.prod.js +7 -7
  127. package/web-ui/res/web-ui-render.precompiled.js +7671 -7666
  128. package/web-ui/session-helpers.mjs +602 -602
  129. package/web-ui/source-bundle.cjs +305 -305
  130. package/web-ui/styles/base-theme.css +291 -291
  131. package/web-ui/styles/bridge-pool.css +266 -266
  132. package/web-ui/styles/controls-forms.css +532 -532
  133. package/web-ui/styles/dashboard.css +438 -438
  134. package/web-ui/styles/docs-panel.css +245 -245
  135. package/web-ui/styles/feedback.css +108 -108
  136. package/web-ui/styles/health-check-dialog.css +144 -144
  137. package/web-ui/styles/layout-shell.css +711 -711
  138. package/web-ui/styles/modals-core.css +499 -499
  139. package/web-ui/styles/navigation-panels.css +399 -399
  140. package/web-ui/styles/openclaw-structured.css +616 -616
  141. package/web-ui/styles/plugins-panel.css +564 -564
  142. package/web-ui/styles/responsive.css +501 -501
  143. package/web-ui/styles/sessions-list.css +683 -683
  144. package/web-ui/styles/sessions-preview.css +407 -407
  145. package/web-ui/styles/sessions-toolbar-trash.css +518 -518
  146. package/web-ui/styles/sessions-usage.css +849 -849
  147. package/web-ui/styles/settings-panel.css +419 -419
  148. package/web-ui/styles/skills-list.css +305 -305
  149. package/web-ui/styles/skills-market.css +723 -723
  150. package/web-ui/styles/task-orchestration.css +822 -822
  151. package/web-ui/styles/titles-cards.css +492 -486
  152. package/web-ui/styles/trash-panel.css +90 -90
  153. package/web-ui/styles/webhook.css +115 -115
  154. package/web-ui/styles.css +24 -24
  155. package/web-ui.html +17 -17
@@ -1,804 +1,804 @@
1
- export function createNavigationMethods(options = {}) {
2
- const {
3
- configModeSet,
4
- switchMainTabHelper,
5
- loadMoreSessionMessagesHelper
6
- } = options;
7
- const NAV_STATE_STORAGE_KEY = 'codexmateNavState.v1';
8
- const MAIN_TAB_SET = new Set([
9
- 'dashboard',
10
- 'config',
11
- 'sessions',
12
- 'usage',
13
- 'orchestration',
14
- 'market',
15
- 'plugins',
16
- 'docs',
17
- 'settings',
18
- 'trash'
19
- ]);
20
- const loadDoctorOverview = async (vm, options = {}) => {
21
- if (!vm || typeof vm !== 'object') return false;
22
- if (vm.__doctorLoading) return false;
23
- const forceRefresh = !!(options && options.forceRefresh);
24
- vm.__doctorLoading = true;
25
- let ok = true;
26
- try {
27
- if (typeof vm.runHealthCheck === 'function') {
28
- await vm.runHealthCheck({ doctor: true, silent: true, forceRefresh });
29
- }
30
- vm.__doctorLoadedOnce = true;
31
- return true;
32
- } catch (_) {
33
- ok = false;
34
- vm.__doctorLoadedOnce = true;
35
- return false;
36
- } finally {
37
- vm.__doctorLoading = false;
38
- if (!ok) {
39
- vm.__doctorLoadedOnce = true;
40
- }
41
- }
42
- };
43
- const readNavState = () => {
44
- if (typeof localStorage === 'undefined') return null;
45
- let raw = '';
46
- try {
47
- raw = localStorage.getItem(NAV_STATE_STORAGE_KEY) || '';
48
- } catch (_) {
49
- raw = '';
50
- }
51
- if (!raw) return null;
52
- try {
53
- const parsed = JSON.parse(raw);
54
- return parsed && typeof parsed === 'object' ? parsed : null;
55
- } catch (_) {
56
- return null;
57
- }
58
- };
59
-
60
- const canonicalizeWebUiRuntimeUrl = () => {
61
- if (typeof window === 'undefined' || !window.location) return;
62
- try {
63
- const url = new URL(window.location.href);
64
- if (url.pathname === '/session') return;
65
- let pathname = url.pathname;
66
- let previousPathname = '';
67
- do {
68
- previousPathname = pathname;
69
- pathname = pathname.replace(/\/+web-ui\/+web-ui\/+/, '/web-ui/');
70
- } while (pathname !== previousPathname);
71
- if (pathname === '/web-ui' || pathname === '/web-ui/' || pathname === '/web-ui/index.html') {
72
- pathname = '/';
73
- }
74
- url.pathname = pathname;
75
- url.search = '';
76
- url.hash = '';
77
- const nextUrl = url.toString();
78
- if (nextUrl === window.location.href) return;
79
- if (window.history && typeof window.history.replaceState === 'function') {
80
- window.history.replaceState(null, '', nextUrl);
81
- }
82
- } catch (_) {}
83
- };
84
-
85
- const persistNavState = (vm, overrides = null) => {
86
- if (!vm || vm.__navStateRestoring) return;
87
- if (typeof localStorage === 'undefined') return;
88
- const resolvedOverrides = overrides && typeof overrides === 'object' ? overrides : null;
89
- const mainTabSource = resolvedOverrides && typeof resolvedOverrides.mainTab === 'string'
90
- ? resolvedOverrides.mainTab
91
- : vm.mainTab;
92
- const configModeSource = resolvedOverrides && typeof resolvedOverrides.configMode === 'string'
93
- ? resolvedOverrides.configMode
94
- : vm.configMode;
95
- const mainTab = typeof mainTabSource === 'string' ? mainTabSource.trim().toLowerCase() : '';
96
- const configMode = typeof configModeSource === 'string' ? configModeSource.trim().toLowerCase() : '';
97
- const settingsTab = typeof vm.settingsTab === 'string' ? vm.settingsTab.trim().toLowerCase() : 'general';
98
- const skillsTargetApp = typeof vm.skillsTargetApp === 'string' && (vm.skillsTargetApp === 'codex' || vm.skillsTargetApp === 'claude') ? vm.skillsTargetApp : 'codex';
99
- const promptTemplatesMode = typeof vm.promptTemplatesMode === 'string' && (vm.promptTemplatesMode === 'compose' || vm.promptTemplatesMode === 'manage') ? vm.promptTemplatesMode : 'compose';
100
- const snapshot = {
101
- settingsTab: settingsTab === 'data' ? 'data' : 'general',
102
- mainTab: MAIN_TAB_SET.has(mainTab) ? mainTab : 'dashboard',
103
- configMode: configModeSet && configModeSet.has(configMode) ? configMode : 'codex',
104
- skillsTargetApp,
105
- promptTemplatesMode
106
- };
107
- try {
108
- localStorage.setItem(NAV_STATE_STORAGE_KEY, JSON.stringify(snapshot));
109
- } catch (_) {}
110
- };
111
-
112
- return {
113
- saveNavState() {
114
- persistNavState(this);
115
- },
116
- restoreNavStateFromStorage() {
117
- if (this.__navStateRestoring) return false;
118
- const restored = readNavState();
119
- if (!restored) return false;
120
- const nextMainTab = restored && typeof restored.mainTab === 'string'
121
- ? restored.mainTab.trim().toLowerCase()
122
- : '';
123
- const nextConfigMode = restored && typeof restored.configMode === 'string'
124
- ? restored.configMode.trim().toLowerCase()
125
- : '';
126
- const shouldUpdateConfigMode = !!(nextConfigMode && configModeSet && configModeSet.has(nextConfigMode));
127
- const shouldUpdateMainTab = !!(nextMainTab && MAIN_TAB_SET.has(nextMainTab) && nextMainTab !== this.mainTab);
128
- const nextSettingsTab = restored && typeof restored.settingsTab === 'string'
129
- ? restored.settingsTab.trim().toLowerCase()
130
- : '';
131
- const shouldUpdateSettingsTab = !!(nextSettingsTab && (nextSettingsTab === 'general' || nextSettingsTab === 'data') && nextSettingsTab !== this.settingsTab);
132
- const nextSkillsTargetApp = restored && typeof restored.skillsTargetApp === 'string' && (restored.skillsTargetApp === 'codex' || restored.skillsTargetApp === 'claude')
133
- ? restored.skillsTargetApp : '';
134
- const shouldUpdateSkillsTargetApp = !!(nextSkillsTargetApp && nextSkillsTargetApp !== this.skillsTargetApp);
135
- const nextPromptTemplatesMode = restored && typeof restored.promptTemplatesMode === 'string' && (restored.promptTemplatesMode === 'compose' || restored.promptTemplatesMode === 'manage')
136
- ? restored.promptTemplatesMode : '';
137
- const shouldUpdatePromptTemplatesMode = !!(nextPromptTemplatesMode && nextPromptTemplatesMode !== this.promptTemplatesMode);
138
- if (!shouldUpdateConfigMode && !shouldUpdateMainTab && !shouldUpdateSettingsTab && !shouldUpdateSkillsTargetApp && !shouldUpdatePromptTemplatesMode) {
139
- return false;
140
- }
141
- this.__navStateRestoring = true;
142
- try {
143
- if (shouldUpdateConfigMode) {
144
- this.configMode = nextConfigMode;
145
- }
146
- if (shouldUpdateSettingsTab) {
147
- this.settingsTab = nextSettingsTab;
148
- }
149
- if (shouldUpdateMainTab) {
150
- this.switchMainTab(nextMainTab);
151
- }
152
- if (shouldUpdateSkillsTargetApp) {
153
- this.skillsTargetApp = nextSkillsTargetApp;
154
- }
155
- if (shouldUpdatePromptTemplatesMode) {
156
- this.promptTemplatesMode = nextPromptTemplatesMode;
157
- }
158
- } finally {
159
- this.__navStateRestoring = false;
160
- }
161
- return true;
162
- },
163
- switchConfigMode(mode) {
164
- const normalizedMode = typeof mode === 'string'
165
- ? mode.trim().toLowerCase()
166
- : '';
167
- canonicalizeWebUiRuntimeUrl();
168
- this.cancelTouchNavIntentReset();
169
- if (typeof this.ensureMainTabSwitchState === 'function') {
170
- this.ensureMainTabSwitchState().pendingConfigMode = '';
171
- }
172
- this.configMode = configModeSet.has(normalizedMode) ? normalizedMode : 'codex';
173
- if (this.mainTab === 'config') {
174
- if (this.configMode === 'claude') {
175
- const expectedMainTab = 'config';
176
- const expectedConfigMode = 'claude';
177
- const refresh = () => {
178
- if (this.mainTab !== expectedMainTab || this.configMode !== expectedConfigMode) {
179
- return;
180
- }
181
- this.refreshClaudeModelContext();
182
- };
183
- if (typeof this.scheduleAfterFrame === 'function') {
184
- this.scheduleAfterFrame(refresh);
185
- } else {
186
- refresh();
187
- }
188
- }
189
- this.scheduleAfterFrame(() => {
190
- this.clearMainTabSwitchIntent('config');
191
- });
192
- persistNavState(this);
193
- return;
194
- }
195
- persistNavState(this, {
196
- mainTab: 'config',
197
- configMode: normalizedMode
198
- });
199
- this.switchMainTab('config');
200
- },
201
-
202
- ensureMainTabSwitchState() {
203
- if (this.__mainTabSwitchState) {
204
- return this.__mainTabSwitchState;
205
- }
206
- this.__mainTabSwitchState = {
207
- intent: '',
208
- pendingTarget: '',
209
- pendingConfigMode: '',
210
- ticket: 0
211
- };
212
- return this.__mainTabSwitchState;
213
- },
214
- ensureImmediateNavDomState() {
215
- if (typeof document === 'undefined') {
216
- return {
217
- navNodes: [],
218
- sessionPanelEl: null
219
- };
220
- }
221
- if (!this.__immediateNavDomState) {
222
- this.__immediateNavDomState = {
223
- navNodes: [],
224
- sessionPanelEl: null
225
- };
226
- }
227
- const state = this.__immediateNavDomState;
228
- const needsNavRefresh = !Array.isArray(state.navNodes)
229
- || !state.navNodes.length
230
- || state.navNodes.some((node) => !node || !node.isConnected);
231
- if (needsNavRefresh) {
232
- state.navNodes = Array.from(document.querySelectorAll('[data-main-tab]'));
233
- }
234
- if (!state.sessionPanelEl || !state.sessionPanelEl.isConnected) {
235
- state.sessionPanelEl = document.getElementById('panel-sessions');
236
- }
237
- return state;
238
- },
239
- setMainTabSwitchIntent(tab) {
240
- const normalizedTab = typeof tab === 'string'
241
- ? tab.trim().toLowerCase()
242
- : '';
243
- if (!normalizedTab) return;
244
- const state = this.ensureMainTabSwitchState();
245
- state.intent = normalizedTab;
246
- },
247
- cancelTouchNavIntentReset() {
248
- if (this.__touchNavIntentResetTimer) {
249
- clearTimeout(this.__touchNavIntentResetTimer);
250
- this.__touchNavIntentResetTimer = null;
251
- }
252
- this.__touchNavIntentResetToken = 0;
253
- },
254
- scheduleTouchNavIntentReset(kind, value) {
255
- const normalizedKind = typeof kind === 'string' ? kind.trim().toLowerCase() : '';
256
- const normalizedValue = typeof value === 'string' ? value.trim().toLowerCase() : '';
257
- if (!normalizedKind || !normalizedValue) {
258
- return;
259
- }
260
- const expectedIntent = normalizedKind === 'config' ? 'config' : normalizedValue;
261
- this.cancelTouchNavIntentReset();
262
- const token = (Number(this.__touchNavIntentResetToken) || 0) + 1;
263
- this.__touchNavIntentResetToken = token;
264
- this.__touchNavIntentResetTimer = setTimeout(() => {
265
- if (this.__touchNavIntentResetToken !== token) {
266
- return;
267
- }
268
- this.__touchNavIntentResetTimer = null;
269
- this.__touchNavIntentResetToken = 0;
270
- const liveIntent = String(this.ensureMainTabSwitchState().intent || '').trim().toLowerCase();
271
- if (liveIntent !== expectedIntent) {
272
- return;
273
- }
274
- this.clearMainTabSwitchIntent(expectedIntent);
275
- }, 1000);
276
- },
277
- applyImmediateNavIntent(tab, configMode = '') {
278
- if (typeof document === 'undefined') return;
279
- const normalizedTab = typeof tab === 'string' ? tab.trim().toLowerCase() : '';
280
- if (!normalizedTab) return;
281
- const normalizedMode = typeof configMode === 'string' ? configMode.trim().toLowerCase() : '';
282
- const domState = this.ensureImmediateNavDomState();
283
- const nodes = Array.isArray(domState.navNodes) ? domState.navNodes : [];
284
- for (const node of nodes) {
285
- if (!node || !node.classList) continue;
286
- const nodeTab = String(node.getAttribute('data-main-tab') || '').trim().toLowerCase();
287
- const nodeMode = String(node.getAttribute('data-config-mode') || '').trim().toLowerCase();
288
- let shouldActivate = nodeTab === normalizedTab;
289
- if (shouldActivate && normalizedTab === 'config') {
290
- shouldActivate = nodeMode ? nodeMode === normalizedMode : false;
291
- }
292
- node.classList.toggle('nav-intent-active', !!shouldActivate);
293
- node.classList.toggle('nav-intent-inactive', !shouldActivate);
294
- }
295
- },
296
- clearImmediateNavIntent() {
297
- if (typeof document === 'undefined') return;
298
- const domState = this.ensureImmediateNavDomState();
299
- const nodes = Array.isArray(domState.navNodes) ? domState.navNodes : [];
300
- for (const node of nodes) {
301
- if (!node || !node.classList) continue;
302
- node.classList.remove('nav-intent-active');
303
- node.classList.remove('nav-intent-inactive');
304
- }
305
- },
306
- setSessionPanelFastHidden(hidden) {
307
- if (typeof document === 'undefined') return;
308
- const domState = this.ensureImmediateNavDomState();
309
- const panel = domState.sessionPanelEl;
310
- if (!panel || !panel.classList) return;
311
- panel.classList.toggle('session-panel-fast-hidden', !!hidden);
312
- },
313
- isSessionPanelFastHidden() {
314
- if (typeof document === 'undefined') return false;
315
- const domState = this.ensureImmediateNavDomState();
316
- const panel = domState.sessionPanelEl;
317
- return !!(panel && panel.classList && panel.classList.contains('session-panel-fast-hidden'));
318
- },
319
- recordPointerNavCommit(kind, value) {
320
- const normalizedKind = typeof kind === 'string' ? kind.trim().toLowerCase() : '';
321
- const normalizedValue = typeof value === 'string' ? value.trim().toLowerCase() : '';
322
- if (!normalizedKind || !normalizedValue) {
323
- this.__pointerNavCommitState = null;
324
- return;
325
- }
326
- this.__pointerNavCommitState = {
327
- kind: normalizedKind,
328
- value: normalizedValue,
329
- at: Date.now()
330
- };
331
- },
332
- consumePointerNavCommit(kind, value) {
333
- const normalizedKind = typeof kind === 'string' ? kind.trim().toLowerCase() : '';
334
- const normalizedValue = typeof value === 'string' ? value.trim().toLowerCase() : '';
335
- const state = this.__pointerNavCommitState;
336
- this.__pointerNavCommitState = null;
337
- if (!state || !normalizedKind || !normalizedValue) {
338
- return false;
339
- }
340
- if (state.kind !== normalizedKind || state.value !== normalizedValue) {
341
- return false;
342
- }
343
- return (Date.now() - Number(state.at || 0)) <= 1000;
344
- },
345
- onMainTabPointerDown(tab) {
346
- const event = arguments.length > 1 ? arguments[1] : null;
347
- if (event && typeof event.button === 'number' && event.button !== 0) {
348
- return;
349
- }
350
- const normalizedTab = typeof tab === 'string' ? tab.trim().toLowerCase() : '';
351
- if (!normalizedTab) return;
352
- persistNavState(this, { mainTab: normalizedTab });
353
- this.setMainTabSwitchIntent(normalizedTab);
354
- this.applyImmediateNavIntent(normalizedTab);
355
- const shouldHideSessionPanel = this.mainTab === 'sessions' && normalizedTab !== 'sessions';
356
- this.setSessionPanelFastHidden(shouldHideSessionPanel);
357
- const pointerType = event && typeof event.pointerType === 'string'
358
- ? event.pointerType.trim().toLowerCase()
359
- : '';
360
- if (pointerType === 'touch') {
361
- this.scheduleTouchNavIntentReset('main', normalizedTab);
362
- return;
363
- }
364
- this.recordPointerNavCommit('main', normalizedTab);
365
- this.switchMainTab(normalizedTab);
366
- },
367
- onConfigTabPointerDown(mode) {
368
- const event = arguments.length > 1 ? arguments[1] : null;
369
- if (event && typeof event.button === 'number' && event.button !== 0) {
370
- return;
371
- }
372
- const normalizedMode = typeof mode === 'string' ? mode.trim().toLowerCase() : '';
373
- if (!normalizedMode) return;
374
- persistNavState(this, { mainTab: 'config', configMode: normalizedMode });
375
- this.setMainTabSwitchIntent('config');
376
- if (typeof this.ensureMainTabSwitchState === 'function') {
377
- this.ensureMainTabSwitchState().pendingConfigMode = normalizedMode;
378
- }
379
- this.applyImmediateNavIntent('config', normalizedMode);
380
- const shouldHideSessionPanel = this.mainTab === 'sessions';
381
- this.setSessionPanelFastHidden(shouldHideSessionPanel);
382
- const pointerType = event && typeof event.pointerType === 'string'
383
- ? event.pointerType.trim().toLowerCase()
384
- : '';
385
- if (pointerType === 'touch') {
386
- this.scheduleTouchNavIntentReset('config', normalizedMode);
387
- return;
388
- }
389
- this.recordPointerNavCommit('config', normalizedMode);
390
- this.switchConfigMode(normalizedMode);
391
- },
392
- onMainTabClick(tab) {
393
- const normalizedTab = typeof tab === 'string' ? tab.trim().toLowerCase() : '';
394
- if (!normalizedTab) return;
395
- if (this.consumePointerNavCommit('main', normalizedTab)) return;
396
- this.switchMainTab(normalizedTab);
397
- },
398
- onConfigTabClick(mode) {
399
- const normalizedMode = typeof mode === 'string' ? mode.trim().toLowerCase() : '';
400
- if (!normalizedMode) return;
401
- if (this.consumePointerNavCommit('config', normalizedMode)) return;
402
- this.switchConfigMode(normalizedMode);
403
- },
404
- clearMainTabSwitchIntent(expectedTab = '') {
405
- const state = this.ensureMainTabSwitchState();
406
- if (expectedTab && state.intent && state.intent !== expectedTab) {
407
- return;
408
- }
409
- this.cancelTouchNavIntentReset();
410
- state.intent = '';
411
- state.pendingTarget = '';
412
- state.pendingConfigMode = '';
413
- this.clearImmediateNavIntent();
414
- this.setSessionPanelFastHidden(false);
415
- },
416
- getMainTabForNav() {
417
- const state = this.ensureMainTabSwitchState();
418
- return state.intent || this.mainTab;
419
- },
420
- isMainTabNavActive(tab) {
421
- return this.getMainTabForNav() === tab;
422
- },
423
- isConfigModeNavActive(mode) {
424
- if (!this.isMainTabNavActive('config')) {
425
- return false;
426
- }
427
- const state = this.ensureMainTabSwitchState();
428
- const pendingMode = typeof state.pendingConfigMode === 'string'
429
- ? state.pendingConfigMode.trim().toLowerCase()
430
- : '';
431
- if (state.intent === 'config' && pendingMode) {
432
- return pendingMode === mode;
433
- }
434
- return this.configMode === mode;
435
- },
436
- switchMainTab(tab) {
437
- const normalizedTab = typeof tab === 'string'
438
- ? tab.trim().toLowerCase()
439
- : '';
440
- const targetTab = normalizedTab || tab;
441
- if (!targetTab) return;
442
- canonicalizeWebUiRuntimeUrl();
443
- if (targetTab === 'orchestration' && this.taskOrchestrationTabEnabled !== true) {
444
- return this.switchMainTab('config');
445
- }
446
- persistNavState(this, {
447
- mainTab: targetTab,
448
- configMode: targetTab === 'config' ? this.configMode : this.configMode
449
- });
450
- // URL 保持静态,不写入任何状态
451
- this.cancelTouchNavIntentReset();
452
- if (targetTab === 'sessions') {
453
- this.cancelScheduledSessionTabDeferredTeardown();
454
- }
455
-
456
- this.setMainTabSwitchIntent(targetTab);
457
- if (targetTab === 'config') {
458
- this.applyImmediateNavIntent('config', this.configMode);
459
- } else {
460
- this.applyImmediateNavIntent(targetTab);
461
- }
462
-
463
- const previousTab = this.mainTab;
464
- const switchState = this.ensureMainTabSwitchState();
465
- if (targetTab !== 'config') {
466
- switchState.pendingConfigMode = '';
467
- }
468
- if (targetTab === previousTab) {
469
- switchState.ticket += 1;
470
- switchState.pendingTarget = '';
471
- if (targetTab === 'dashboard' && !this.__doctorLoadedOnce) {
472
- if (targetTab === 'trash' && !this.sessionTrashLoadedOnce) {
473
- if (typeof this.loadSessionTrash === 'function') {
474
- void this.loadSessionTrash({ forceRefresh: false });
475
- }
476
- }
477
- void loadDoctorOverview(this);
478
- }
479
- if (
480
- targetTab === 'sessions'
481
- && typeof this.prepareSessionTabRender === 'function'
482
- && (!this.sessionListRenderEnabled || !this.sessionPreviewRenderEnabled)
483
- ) {
484
- this.prepareSessionTabRender();
485
- }
486
- this.scheduleAfterFrame(() => {
487
- this.clearMainTabSwitchIntent(normalizedTab);
488
- });
489
- return;
490
- }
491
- const isLeavingSessions = previousTab === 'sessions' && targetTab !== 'sessions';
492
- const shouldPreserveSessionRender = isLeavingSessions && this.preserveSessionRenderOnTabLeave === true;
493
- const shouldDeferApply = isLeavingSessions && !shouldPreserveSessionRender;
494
- if (isLeavingSessions && !this.isSessionPanelFastHidden()) {
495
- this.setSessionPanelFastHidden(!shouldPreserveSessionRender);
496
- }
497
- if (shouldDeferApply && typeof this.suspendSessionTabRender === 'function') {
498
- this.suspendSessionTabRender();
499
- }
500
- if (!shouldDeferApply) {
501
- switchState.ticket += 1;
502
- switchState.pendingTarget = '';
503
- const result = switchMainTabHelper.call(this, targetTab);
504
- persistNavState(this);
505
- if (targetTab === 'dashboard') {
506
- void loadDoctorOverview(this);
507
- }
508
- this.scheduleAfterFrame(() => {
509
- this.clearMainTabSwitchIntent(normalizedTab);
510
- });
511
- return result;
512
- }
513
-
514
- const ticket = ++switchState.ticket;
515
- switchState.pendingTarget = targetTab;
516
- this.scheduleAfterFrame(() => {
517
- const liveState = this.ensureMainTabSwitchState();
518
- if (ticket !== liveState.ticket) return;
519
- const pendingTarget = liveState.pendingTarget || targetTab;
520
- liveState.pendingTarget = '';
521
- switchMainTabHelper.call(this, pendingTarget);
522
- persistNavState(this);
523
- if (pendingTarget === 'dashboard') {
524
- void loadDoctorOverview(this);
525
- }
526
- this.clearMainTabSwitchIntent(normalizedTab);
527
- });
528
- },
529
-
530
- scheduleAfterFrame(task) {
531
- const callback = typeof task === 'function' ? task : () => {};
532
- if (typeof requestAnimationFrame === 'function') {
533
- requestAnimationFrame(callback);
534
- return;
535
- }
536
- setTimeout(callback, 16);
537
- },
538
- scheduleIdleTask(task, timeoutMs = 160) {
539
- const callback = typeof task === 'function' ? task : () => {};
540
- const timeout = Number.isFinite(timeoutMs)
541
- ? Math.max(16, Math.floor(timeoutMs))
542
- : 160;
543
- if (typeof requestIdleCallback === 'function') {
544
- const id = requestIdleCallback(callback, { timeout });
545
- return {
546
- type: 'idle',
547
- id
548
- };
549
- }
550
- const id = setTimeout(callback, timeout);
551
- return {
552
- type: 'timeout',
553
- id
554
- };
555
- },
556
- cancelIdleTask(handle) {
557
- if (!handle || typeof handle !== 'object') return;
558
- const type = handle.type;
559
- const id = handle.id;
560
- if (type === 'idle') {
561
- if (typeof cancelIdleCallback === 'function') {
562
- cancelIdleCallback(id);
563
- } else {
564
- clearTimeout(id);
565
- }
566
- return;
567
- }
568
- if (type === 'timeout') {
569
- clearTimeout(id);
570
- }
571
- },
572
- scheduleSessionTabDeferredTeardown(task) {
573
- const callback = typeof task === 'function' ? task : () => {};
574
- this.cancelScheduledSessionTabDeferredTeardown();
575
- this.__sessionTabDeferredTeardownHandle = this.scheduleIdleTask(() => {
576
- this.__sessionTabDeferredTeardownHandle = null;
577
- callback();
578
- }, 180);
579
- },
580
- cancelScheduledSessionTabDeferredTeardown() {
581
- const handle = this.__sessionTabDeferredTeardownHandle || null;
582
- if (!handle) return;
583
- this.cancelIdleTask(handle);
584
- this.__sessionTabDeferredTeardownHandle = null;
585
- },
586
-
587
- setSessionListRef(element) {
588
- this.__sessionListRef = element || null;
589
- if (this.__sessionListRef && this.mainTab === 'sessions' && this.sessionListRenderEnabled) {
590
- this.scheduleSessionListViewportFill();
591
- }
592
- },
593
- getSessionListRenderSource() {
594
- return Array.isArray(this.sortedSessionsList) ? this.sortedSessionsList : [];
595
- },
596
- cancelScheduledSessionListViewportFill() {
597
- const handle = this.__sessionListViewportFillHandle || null;
598
- if (!handle) return;
599
- this.cancelIdleTask(handle);
600
- this.__sessionListViewportFillHandle = null;
601
- },
602
- resetSessionListRender() {
603
- this.cancelScheduledSessionListViewportFill();
604
- this.sessionListVisibleCount = 0;
605
- },
606
- expandVisibleSessionList(stepSize, options = {}) {
607
- const list = this.getSessionListRenderSource();
608
- const total = list.length;
609
- if (total <= 0) {
610
- this.sessionListVisibleCount = 0;
611
- return false;
612
- }
613
- const rawVisibleCount = Number(this.sessionListVisibleCount);
614
- const currentCount = Number.isFinite(rawVisibleCount)
615
- ? Math.max(0, Math.floor(rawVisibleCount))
616
- : 0;
617
- const initialBatchSize = Number.isFinite(this.sessionListInitialBatchSize)
618
- ? Math.max(1, Math.floor(this.sessionListInitialBatchSize))
619
- : 80;
620
- const loadStep = Number.isFinite(stepSize)
621
- ? Math.max(0, Math.floor(stepSize))
622
- : (Number.isFinite(this.sessionListLoadStep)
623
- ? Math.max(1, Math.floor(this.sessionListLoadStep))
624
- : 120);
625
- let nextCount = currentCount > 0
626
- ? Math.min(total, currentCount + loadStep)
627
- : Math.min(total, initialBatchSize);
628
- if (options && options.ensureActive !== false) {
629
- const activeKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
630
- if (activeKey) {
631
- const activeIndex = list.findIndex((session) => this.getSessionExportKey(session) === activeKey);
632
- if (activeIndex >= 0) {
633
- nextCount = Math.max(nextCount, activeIndex + 1);
634
- }
635
- }
636
- }
637
- nextCount = Math.min(total, nextCount);
638
- if (nextCount <= currentCount) {
639
- return false;
640
- }
641
- this.sessionListVisibleCount = nextCount;
642
- return true;
643
- },
644
- scheduleSessionListViewportFill() {
645
- this.cancelScheduledSessionListViewportFill();
646
- if (this.mainTab !== 'sessions' || !this.sessionListRenderEnabled) {
647
- return;
648
- }
649
- const run = () => {
650
- this.__sessionListViewportFillHandle = null;
651
- if (this.mainTab !== 'sessions' || !this.sessionListRenderEnabled) {
652
- return;
653
- }
654
- const list = this.getSessionListRenderSource();
655
- const total = list.length;
656
- const visibleCount = Number(this.sessionListVisibleCount);
657
- const normalizedVisibleCount = Number.isFinite(visibleCount)
658
- ? Math.max(0, Math.floor(visibleCount))
659
- : 0;
660
- if (total <= 0 || normalizedVisibleCount >= total) {
661
- return;
662
- }
663
- const listEl = this.__sessionListRef || null;
664
- if (!listEl) {
665
- return;
666
- }
667
- const clientHeight = Number(listEl.clientHeight) || 0;
668
- const scrollHeight = Number(listEl.scrollHeight) || 0;
669
- const scrollTop = Number(listEl.scrollTop) || 0;
670
- const remaining = Math.max(0, scrollHeight - scrollTop - clientHeight);
671
- const shouldGrow = scrollHeight <= (clientHeight + 160) || remaining <= Math.max(160, clientHeight);
672
- if (!shouldGrow) {
673
- return;
674
- }
675
- if (this.expandVisibleSessionList(undefined, { ensureActive: true })) {
676
- this.scheduleSessionListViewportFill();
677
- }
678
- };
679
- this.__sessionListViewportFillHandle = this.scheduleIdleTask(run, 120);
680
- },
681
- primeSessionListRender() {
682
- this.resetSessionListRender();
683
- if (this.mainTab !== 'sessions' || !this.sessionListRenderEnabled) {
684
- return;
685
- }
686
- this.expandVisibleSessionList(undefined, { ensureActive: true });
687
- this.scheduleSessionListViewportFill();
688
- },
689
- onSessionListScroll(event) {
690
- const nextRef = event && event.currentTarget ? event.currentTarget : this.__sessionListRef;
691
- if (nextRef) {
692
- this.__sessionListRef = nextRef;
693
- }
694
- this.scheduleSessionListViewportFill();
695
- if (typeof this.scheduleSessionListMessageCountHydrate === 'function') {
696
- this.scheduleSessionListMessageCountHydrate();
697
- }
698
- },
699
-
700
- resetSessionPreviewMessageRender() {
701
- this.sessionPreviewVisibleCount = 0;
702
- this.invalidateSessionTimelineMeasurementCache();
703
- },
704
-
705
- resetSessionDetailPagination() {
706
- const initialLimit = Number.isFinite(this.sessionDetailInitialMessageLimit)
707
- ? Math.max(1, Math.floor(this.sessionDetailInitialMessageLimit))
708
- : 80;
709
- this.sessionDetailMessageLimit = initialLimit;
710
- this.sessionPreviewPendingVisibleCount = 0;
711
- },
712
-
713
- primeSessionPreviewMessageRender() {
714
- this.sessionPreviewVisibleCount = 0;
715
- this.invalidateSessionTimelineMeasurementCache();
716
- if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
717
- return;
718
- }
719
- const total = Array.isArray(this.activeSessionMessages)
720
- ? this.activeSessionMessages.length
721
- : 0;
722
- if (total <= 0) return;
723
- this.sessionPreviewVisibleCount = total;
724
- this.invalidateSessionTimelineMeasurementCache();
725
- },
726
-
727
- async loadMoreSessionMessages(stepSize) {
728
- return loadMoreSessionMessagesHelper.call(this, stepSize);
729
- },
730
-
731
- suspendSessionTabRender() {
732
- this.sessionTabRenderTicket += 1;
733
- this.sessionListRenderEnabled = false;
734
- this.sessionPreviewRenderEnabled = false;
735
- this.cancelScheduledSessionListViewportFill();
736
- this.cancelSessionTimelineSync();
737
- this.sessionTimelineActiveKey = '';
738
- this.sessionTimelineLastSyncAt = 0;
739
- this.sessionTimelineLastScrollTop = 0;
740
- this.sessionTimelineLastAnchorY = 0;
741
- this.sessionTimelineLastDirection = 0;
742
- this.__sessionListRef = null;
743
- this.sessionPreviewScrollEl = null;
744
- this.sessionPreviewContainerEl = null;
745
- this.sessionPreviewHeaderEl = null;
746
- },
747
-
748
- finalizeSessionTabTeardown() {
749
- this.resetSessionListRender();
750
- this.resetSessionPreviewMessageRender();
751
- this.sessionPreviewPendingVisibleCount = 0;
752
- this.clearSessionTimelineRefs();
753
- },
754
-
755
- teardownSessionTabRender() {
756
- this.suspendSessionTabRender();
757
- this.finalizeSessionTabTeardown();
758
- },
759
-
760
- prepareSessionTabRender() {
761
- const ticket = ++this.sessionTabRenderTicket;
762
- this.sessionListRenderEnabled = false;
763
- this.sessionPreviewRenderEnabled = false;
764
- this.resetSessionListRender();
765
- this.resetSessionPreviewMessageRender();
766
-
767
- this.scheduleAfterFrame(() => {
768
- if (ticket !== this.sessionTabRenderTicket || this.mainTab !== 'sessions') {
769
- return;
770
- }
771
- this.sessionListRenderEnabled = true;
772
- this.primeSessionListRender();
773
-
774
- this.scheduleAfterFrame(() => {
775
- if (ticket !== this.sessionTabRenderTicket || this.mainTab !== 'sessions') {
776
- return;
777
- }
778
- this.sessionPreviewRenderEnabled = true;
779
- this.$nextTick(() => {
780
- if (ticket !== this.sessionTabRenderTicket || this.mainTab !== 'sessions') {
781
- return;
782
- }
783
- this.primeSessionPreviewMessageRender();
784
- this.updateSessionTimelineOffset();
785
- if (!this.sessionTimelineEnabled) {
786
- return;
787
- }
788
- const syncTask = () => {
789
- if (ticket !== this.sessionTabRenderTicket || this.mainTab !== 'sessions') {
790
- return;
791
- }
792
- this.scheduleSessionTimelineSync();
793
- };
794
- if (typeof this.scheduleAfterFrame === 'function') {
795
- this.scheduleAfterFrame(syncTask);
796
- return;
797
- }
798
- syncTask();
799
- });
800
- });
801
- });
802
- }
803
- };
804
- }
1
+ export function createNavigationMethods(options = {}) {
2
+ const {
3
+ configModeSet,
4
+ switchMainTabHelper,
5
+ loadMoreSessionMessagesHelper
6
+ } = options;
7
+ const NAV_STATE_STORAGE_KEY = 'codexmateNavState.v1';
8
+ const MAIN_TAB_SET = new Set([
9
+ 'dashboard',
10
+ 'config',
11
+ 'sessions',
12
+ 'usage',
13
+ 'orchestration',
14
+ 'market',
15
+ 'plugins',
16
+ 'docs',
17
+ 'settings',
18
+ 'trash'
19
+ ]);
20
+ const loadDoctorOverview = async (vm, options = {}) => {
21
+ if (!vm || typeof vm !== 'object') return false;
22
+ if (vm.__doctorLoading) return false;
23
+ const forceRefresh = !!(options && options.forceRefresh);
24
+ vm.__doctorLoading = true;
25
+ let ok = true;
26
+ try {
27
+ if (typeof vm.runHealthCheck === 'function') {
28
+ await vm.runHealthCheck({ doctor: true, silent: true, forceRefresh });
29
+ }
30
+ vm.__doctorLoadedOnce = true;
31
+ return true;
32
+ } catch (_) {
33
+ ok = false;
34
+ vm.__doctorLoadedOnce = true;
35
+ return false;
36
+ } finally {
37
+ vm.__doctorLoading = false;
38
+ if (!ok) {
39
+ vm.__doctorLoadedOnce = true;
40
+ }
41
+ }
42
+ };
43
+ const readNavState = () => {
44
+ if (typeof localStorage === 'undefined') return null;
45
+ let raw = '';
46
+ try {
47
+ raw = localStorage.getItem(NAV_STATE_STORAGE_KEY) || '';
48
+ } catch (_) {
49
+ raw = '';
50
+ }
51
+ if (!raw) return null;
52
+ try {
53
+ const parsed = JSON.parse(raw);
54
+ return parsed && typeof parsed === 'object' ? parsed : null;
55
+ } catch (_) {
56
+ return null;
57
+ }
58
+ };
59
+
60
+ const canonicalizeWebUiRuntimeUrl = () => {
61
+ if (typeof window === 'undefined' || !window.location) return;
62
+ try {
63
+ const url = new URL(window.location.href);
64
+ if (url.pathname === '/session') return;
65
+ let pathname = url.pathname;
66
+ let previousPathname = '';
67
+ do {
68
+ previousPathname = pathname;
69
+ pathname = pathname.replace(/\/+web-ui\/+web-ui\/+/, '/web-ui/');
70
+ } while (pathname !== previousPathname);
71
+ if (pathname === '/web-ui' || pathname === '/web-ui/' || pathname === '/web-ui/index.html') {
72
+ pathname = '/';
73
+ }
74
+ url.pathname = pathname;
75
+ url.search = '';
76
+ url.hash = '';
77
+ const nextUrl = url.toString();
78
+ if (nextUrl === window.location.href) return;
79
+ if (window.history && typeof window.history.replaceState === 'function') {
80
+ window.history.replaceState(null, '', nextUrl);
81
+ }
82
+ } catch (_) {}
83
+ };
84
+
85
+ const persistNavState = (vm, overrides = null) => {
86
+ if (!vm || vm.__navStateRestoring) return;
87
+ if (typeof localStorage === 'undefined') return;
88
+ const resolvedOverrides = overrides && typeof overrides === 'object' ? overrides : null;
89
+ const mainTabSource = resolvedOverrides && typeof resolvedOverrides.mainTab === 'string'
90
+ ? resolvedOverrides.mainTab
91
+ : vm.mainTab;
92
+ const configModeSource = resolvedOverrides && typeof resolvedOverrides.configMode === 'string'
93
+ ? resolvedOverrides.configMode
94
+ : vm.configMode;
95
+ const mainTab = typeof mainTabSource === 'string' ? mainTabSource.trim().toLowerCase() : '';
96
+ const configMode = typeof configModeSource === 'string' ? configModeSource.trim().toLowerCase() : '';
97
+ const settingsTab = typeof vm.settingsTab === 'string' ? vm.settingsTab.trim().toLowerCase() : 'general';
98
+ const skillsTargetApp = typeof vm.skillsTargetApp === 'string' && (vm.skillsTargetApp === 'codex' || vm.skillsTargetApp === 'claude') ? vm.skillsTargetApp : 'codex';
99
+ const promptTemplatesMode = typeof vm.promptTemplatesMode === 'string' && (vm.promptTemplatesMode === 'compose' || vm.promptTemplatesMode === 'manage') ? vm.promptTemplatesMode : 'compose';
100
+ const snapshot = {
101
+ settingsTab: settingsTab === 'data' ? 'data' : 'general',
102
+ mainTab: MAIN_TAB_SET.has(mainTab) ? mainTab : 'dashboard',
103
+ configMode: configModeSet && configModeSet.has(configMode) ? configMode : 'codex',
104
+ skillsTargetApp,
105
+ promptTemplatesMode
106
+ };
107
+ try {
108
+ localStorage.setItem(NAV_STATE_STORAGE_KEY, JSON.stringify(snapshot));
109
+ } catch (_) {}
110
+ };
111
+
112
+ return {
113
+ saveNavState() {
114
+ persistNavState(this);
115
+ },
116
+ restoreNavStateFromStorage() {
117
+ if (this.__navStateRestoring) return false;
118
+ const restored = readNavState();
119
+ if (!restored) return false;
120
+ const nextMainTab = restored && typeof restored.mainTab === 'string'
121
+ ? restored.mainTab.trim().toLowerCase()
122
+ : '';
123
+ const nextConfigMode = restored && typeof restored.configMode === 'string'
124
+ ? restored.configMode.trim().toLowerCase()
125
+ : '';
126
+ const shouldUpdateConfigMode = !!(nextConfigMode && configModeSet && configModeSet.has(nextConfigMode));
127
+ const shouldUpdateMainTab = !!(nextMainTab && MAIN_TAB_SET.has(nextMainTab) && nextMainTab !== this.mainTab);
128
+ const nextSettingsTab = restored && typeof restored.settingsTab === 'string'
129
+ ? restored.settingsTab.trim().toLowerCase()
130
+ : '';
131
+ const shouldUpdateSettingsTab = !!(nextSettingsTab && (nextSettingsTab === 'general' || nextSettingsTab === 'data') && nextSettingsTab !== this.settingsTab);
132
+ const nextSkillsTargetApp = restored && typeof restored.skillsTargetApp === 'string' && (restored.skillsTargetApp === 'codex' || restored.skillsTargetApp === 'claude')
133
+ ? restored.skillsTargetApp : '';
134
+ const shouldUpdateSkillsTargetApp = !!(nextSkillsTargetApp && nextSkillsTargetApp !== this.skillsTargetApp);
135
+ const nextPromptTemplatesMode = restored && typeof restored.promptTemplatesMode === 'string' && (restored.promptTemplatesMode === 'compose' || restored.promptTemplatesMode === 'manage')
136
+ ? restored.promptTemplatesMode : '';
137
+ const shouldUpdatePromptTemplatesMode = !!(nextPromptTemplatesMode && nextPromptTemplatesMode !== this.promptTemplatesMode);
138
+ if (!shouldUpdateConfigMode && !shouldUpdateMainTab && !shouldUpdateSettingsTab && !shouldUpdateSkillsTargetApp && !shouldUpdatePromptTemplatesMode) {
139
+ return false;
140
+ }
141
+ this.__navStateRestoring = true;
142
+ try {
143
+ if (shouldUpdateConfigMode) {
144
+ this.configMode = nextConfigMode;
145
+ }
146
+ if (shouldUpdateSettingsTab) {
147
+ this.settingsTab = nextSettingsTab;
148
+ }
149
+ if (shouldUpdateMainTab) {
150
+ this.switchMainTab(nextMainTab);
151
+ }
152
+ if (shouldUpdateSkillsTargetApp) {
153
+ this.skillsTargetApp = nextSkillsTargetApp;
154
+ }
155
+ if (shouldUpdatePromptTemplatesMode) {
156
+ this.promptTemplatesMode = nextPromptTemplatesMode;
157
+ }
158
+ } finally {
159
+ this.__navStateRestoring = false;
160
+ }
161
+ return true;
162
+ },
163
+ switchConfigMode(mode) {
164
+ const normalizedMode = typeof mode === 'string'
165
+ ? mode.trim().toLowerCase()
166
+ : '';
167
+ canonicalizeWebUiRuntimeUrl();
168
+ this.cancelTouchNavIntentReset();
169
+ if (typeof this.ensureMainTabSwitchState === 'function') {
170
+ this.ensureMainTabSwitchState().pendingConfigMode = '';
171
+ }
172
+ this.configMode = configModeSet.has(normalizedMode) ? normalizedMode : 'codex';
173
+ if (this.mainTab === 'config') {
174
+ if (this.configMode === 'claude') {
175
+ const expectedMainTab = 'config';
176
+ const expectedConfigMode = 'claude';
177
+ const refresh = () => {
178
+ if (this.mainTab !== expectedMainTab || this.configMode !== expectedConfigMode) {
179
+ return;
180
+ }
181
+ this.refreshClaudeModelContext();
182
+ };
183
+ if (typeof this.scheduleAfterFrame === 'function') {
184
+ this.scheduleAfterFrame(refresh);
185
+ } else {
186
+ refresh();
187
+ }
188
+ }
189
+ this.scheduleAfterFrame(() => {
190
+ this.clearMainTabSwitchIntent('config');
191
+ });
192
+ persistNavState(this);
193
+ return;
194
+ }
195
+ persistNavState(this, {
196
+ mainTab: 'config',
197
+ configMode: normalizedMode
198
+ });
199
+ this.switchMainTab('config');
200
+ },
201
+
202
+ ensureMainTabSwitchState() {
203
+ if (this.__mainTabSwitchState) {
204
+ return this.__mainTabSwitchState;
205
+ }
206
+ this.__mainTabSwitchState = {
207
+ intent: '',
208
+ pendingTarget: '',
209
+ pendingConfigMode: '',
210
+ ticket: 0
211
+ };
212
+ return this.__mainTabSwitchState;
213
+ },
214
+ ensureImmediateNavDomState() {
215
+ if (typeof document === 'undefined') {
216
+ return {
217
+ navNodes: [],
218
+ sessionPanelEl: null
219
+ };
220
+ }
221
+ if (!this.__immediateNavDomState) {
222
+ this.__immediateNavDomState = {
223
+ navNodes: [],
224
+ sessionPanelEl: null
225
+ };
226
+ }
227
+ const state = this.__immediateNavDomState;
228
+ const needsNavRefresh = !Array.isArray(state.navNodes)
229
+ || !state.navNodes.length
230
+ || state.navNodes.some((node) => !node || !node.isConnected);
231
+ if (needsNavRefresh) {
232
+ state.navNodes = Array.from(document.querySelectorAll('[data-main-tab]'));
233
+ }
234
+ if (!state.sessionPanelEl || !state.sessionPanelEl.isConnected) {
235
+ state.sessionPanelEl = document.getElementById('panel-sessions');
236
+ }
237
+ return state;
238
+ },
239
+ setMainTabSwitchIntent(tab) {
240
+ const normalizedTab = typeof tab === 'string'
241
+ ? tab.trim().toLowerCase()
242
+ : '';
243
+ if (!normalizedTab) return;
244
+ const state = this.ensureMainTabSwitchState();
245
+ state.intent = normalizedTab;
246
+ },
247
+ cancelTouchNavIntentReset() {
248
+ if (this.__touchNavIntentResetTimer) {
249
+ clearTimeout(this.__touchNavIntentResetTimer);
250
+ this.__touchNavIntentResetTimer = null;
251
+ }
252
+ this.__touchNavIntentResetToken = 0;
253
+ },
254
+ scheduleTouchNavIntentReset(kind, value) {
255
+ const normalizedKind = typeof kind === 'string' ? kind.trim().toLowerCase() : '';
256
+ const normalizedValue = typeof value === 'string' ? value.trim().toLowerCase() : '';
257
+ if (!normalizedKind || !normalizedValue) {
258
+ return;
259
+ }
260
+ const expectedIntent = normalizedKind === 'config' ? 'config' : normalizedValue;
261
+ this.cancelTouchNavIntentReset();
262
+ const token = (Number(this.__touchNavIntentResetToken) || 0) + 1;
263
+ this.__touchNavIntentResetToken = token;
264
+ this.__touchNavIntentResetTimer = setTimeout(() => {
265
+ if (this.__touchNavIntentResetToken !== token) {
266
+ return;
267
+ }
268
+ this.__touchNavIntentResetTimer = null;
269
+ this.__touchNavIntentResetToken = 0;
270
+ const liveIntent = String(this.ensureMainTabSwitchState().intent || '').trim().toLowerCase();
271
+ if (liveIntent !== expectedIntent) {
272
+ return;
273
+ }
274
+ this.clearMainTabSwitchIntent(expectedIntent);
275
+ }, 1000);
276
+ },
277
+ applyImmediateNavIntent(tab, configMode = '') {
278
+ if (typeof document === 'undefined') return;
279
+ const normalizedTab = typeof tab === 'string' ? tab.trim().toLowerCase() : '';
280
+ if (!normalizedTab) return;
281
+ const normalizedMode = typeof configMode === 'string' ? configMode.trim().toLowerCase() : '';
282
+ const domState = this.ensureImmediateNavDomState();
283
+ const nodes = Array.isArray(domState.navNodes) ? domState.navNodes : [];
284
+ for (const node of nodes) {
285
+ if (!node || !node.classList) continue;
286
+ const nodeTab = String(node.getAttribute('data-main-tab') || '').trim().toLowerCase();
287
+ const nodeMode = String(node.getAttribute('data-config-mode') || '').trim().toLowerCase();
288
+ let shouldActivate = nodeTab === normalizedTab;
289
+ if (shouldActivate && normalizedTab === 'config') {
290
+ shouldActivate = nodeMode ? nodeMode === normalizedMode : false;
291
+ }
292
+ node.classList.toggle('nav-intent-active', !!shouldActivate);
293
+ node.classList.toggle('nav-intent-inactive', !shouldActivate);
294
+ }
295
+ },
296
+ clearImmediateNavIntent() {
297
+ if (typeof document === 'undefined') return;
298
+ const domState = this.ensureImmediateNavDomState();
299
+ const nodes = Array.isArray(domState.navNodes) ? domState.navNodes : [];
300
+ for (const node of nodes) {
301
+ if (!node || !node.classList) continue;
302
+ node.classList.remove('nav-intent-active');
303
+ node.classList.remove('nav-intent-inactive');
304
+ }
305
+ },
306
+ setSessionPanelFastHidden(hidden) {
307
+ if (typeof document === 'undefined') return;
308
+ const domState = this.ensureImmediateNavDomState();
309
+ const panel = domState.sessionPanelEl;
310
+ if (!panel || !panel.classList) return;
311
+ panel.classList.toggle('session-panel-fast-hidden', !!hidden);
312
+ },
313
+ isSessionPanelFastHidden() {
314
+ if (typeof document === 'undefined') return false;
315
+ const domState = this.ensureImmediateNavDomState();
316
+ const panel = domState.sessionPanelEl;
317
+ return !!(panel && panel.classList && panel.classList.contains('session-panel-fast-hidden'));
318
+ },
319
+ recordPointerNavCommit(kind, value) {
320
+ const normalizedKind = typeof kind === 'string' ? kind.trim().toLowerCase() : '';
321
+ const normalizedValue = typeof value === 'string' ? value.trim().toLowerCase() : '';
322
+ if (!normalizedKind || !normalizedValue) {
323
+ this.__pointerNavCommitState = null;
324
+ return;
325
+ }
326
+ this.__pointerNavCommitState = {
327
+ kind: normalizedKind,
328
+ value: normalizedValue,
329
+ at: Date.now()
330
+ };
331
+ },
332
+ consumePointerNavCommit(kind, value) {
333
+ const normalizedKind = typeof kind === 'string' ? kind.trim().toLowerCase() : '';
334
+ const normalizedValue = typeof value === 'string' ? value.trim().toLowerCase() : '';
335
+ const state = this.__pointerNavCommitState;
336
+ this.__pointerNavCommitState = null;
337
+ if (!state || !normalizedKind || !normalizedValue) {
338
+ return false;
339
+ }
340
+ if (state.kind !== normalizedKind || state.value !== normalizedValue) {
341
+ return false;
342
+ }
343
+ return (Date.now() - Number(state.at || 0)) <= 1000;
344
+ },
345
+ onMainTabPointerDown(tab) {
346
+ const event = arguments.length > 1 ? arguments[1] : null;
347
+ if (event && typeof event.button === 'number' && event.button !== 0) {
348
+ return;
349
+ }
350
+ const normalizedTab = typeof tab === 'string' ? tab.trim().toLowerCase() : '';
351
+ if (!normalizedTab) return;
352
+ persistNavState(this, { mainTab: normalizedTab });
353
+ this.setMainTabSwitchIntent(normalizedTab);
354
+ this.applyImmediateNavIntent(normalizedTab);
355
+ const shouldHideSessionPanel = this.mainTab === 'sessions' && normalizedTab !== 'sessions';
356
+ this.setSessionPanelFastHidden(shouldHideSessionPanel);
357
+ const pointerType = event && typeof event.pointerType === 'string'
358
+ ? event.pointerType.trim().toLowerCase()
359
+ : '';
360
+ if (pointerType === 'touch') {
361
+ this.scheduleTouchNavIntentReset('main', normalizedTab);
362
+ return;
363
+ }
364
+ this.recordPointerNavCommit('main', normalizedTab);
365
+ this.switchMainTab(normalizedTab);
366
+ },
367
+ onConfigTabPointerDown(mode) {
368
+ const event = arguments.length > 1 ? arguments[1] : null;
369
+ if (event && typeof event.button === 'number' && event.button !== 0) {
370
+ return;
371
+ }
372
+ const normalizedMode = typeof mode === 'string' ? mode.trim().toLowerCase() : '';
373
+ if (!normalizedMode) return;
374
+ persistNavState(this, { mainTab: 'config', configMode: normalizedMode });
375
+ this.setMainTabSwitchIntent('config');
376
+ if (typeof this.ensureMainTabSwitchState === 'function') {
377
+ this.ensureMainTabSwitchState().pendingConfigMode = normalizedMode;
378
+ }
379
+ this.applyImmediateNavIntent('config', normalizedMode);
380
+ const shouldHideSessionPanel = this.mainTab === 'sessions';
381
+ this.setSessionPanelFastHidden(shouldHideSessionPanel);
382
+ const pointerType = event && typeof event.pointerType === 'string'
383
+ ? event.pointerType.trim().toLowerCase()
384
+ : '';
385
+ if (pointerType === 'touch') {
386
+ this.scheduleTouchNavIntentReset('config', normalizedMode);
387
+ return;
388
+ }
389
+ this.recordPointerNavCommit('config', normalizedMode);
390
+ this.switchConfigMode(normalizedMode);
391
+ },
392
+ onMainTabClick(tab) {
393
+ const normalizedTab = typeof tab === 'string' ? tab.trim().toLowerCase() : '';
394
+ if (!normalizedTab) return;
395
+ if (this.consumePointerNavCommit('main', normalizedTab)) return;
396
+ this.switchMainTab(normalizedTab);
397
+ },
398
+ onConfigTabClick(mode) {
399
+ const normalizedMode = typeof mode === 'string' ? mode.trim().toLowerCase() : '';
400
+ if (!normalizedMode) return;
401
+ if (this.consumePointerNavCommit('config', normalizedMode)) return;
402
+ this.switchConfigMode(normalizedMode);
403
+ },
404
+ clearMainTabSwitchIntent(expectedTab = '') {
405
+ const state = this.ensureMainTabSwitchState();
406
+ if (expectedTab && state.intent && state.intent !== expectedTab) {
407
+ return;
408
+ }
409
+ this.cancelTouchNavIntentReset();
410
+ state.intent = '';
411
+ state.pendingTarget = '';
412
+ state.pendingConfigMode = '';
413
+ this.clearImmediateNavIntent();
414
+ this.setSessionPanelFastHidden(false);
415
+ },
416
+ getMainTabForNav() {
417
+ const state = this.ensureMainTabSwitchState();
418
+ return state.intent || this.mainTab;
419
+ },
420
+ isMainTabNavActive(tab) {
421
+ return this.getMainTabForNav() === tab;
422
+ },
423
+ isConfigModeNavActive(mode) {
424
+ if (!this.isMainTabNavActive('config')) {
425
+ return false;
426
+ }
427
+ const state = this.ensureMainTabSwitchState();
428
+ const pendingMode = typeof state.pendingConfigMode === 'string'
429
+ ? state.pendingConfigMode.trim().toLowerCase()
430
+ : '';
431
+ if (state.intent === 'config' && pendingMode) {
432
+ return pendingMode === mode;
433
+ }
434
+ return this.configMode === mode;
435
+ },
436
+ switchMainTab(tab) {
437
+ const normalizedTab = typeof tab === 'string'
438
+ ? tab.trim().toLowerCase()
439
+ : '';
440
+ const targetTab = normalizedTab || tab;
441
+ if (!targetTab) return;
442
+ canonicalizeWebUiRuntimeUrl();
443
+ if (targetTab === 'orchestration' && this.taskOrchestrationTabEnabled !== true) {
444
+ return this.switchMainTab('config');
445
+ }
446
+ persistNavState(this, {
447
+ mainTab: targetTab,
448
+ configMode: targetTab === 'config' ? this.configMode : this.configMode
449
+ });
450
+ // URL 保持静态,不写入任何状态
451
+ this.cancelTouchNavIntentReset();
452
+ if (targetTab === 'sessions') {
453
+ this.cancelScheduledSessionTabDeferredTeardown();
454
+ }
455
+
456
+ this.setMainTabSwitchIntent(targetTab);
457
+ if (targetTab === 'config') {
458
+ this.applyImmediateNavIntent('config', this.configMode);
459
+ } else {
460
+ this.applyImmediateNavIntent(targetTab);
461
+ }
462
+
463
+ const previousTab = this.mainTab;
464
+ const switchState = this.ensureMainTabSwitchState();
465
+ if (targetTab !== 'config') {
466
+ switchState.pendingConfigMode = '';
467
+ }
468
+ if (targetTab === previousTab) {
469
+ switchState.ticket += 1;
470
+ switchState.pendingTarget = '';
471
+ if (targetTab === 'dashboard' && !this.__doctorLoadedOnce) {
472
+ if (targetTab === 'trash' && !this.sessionTrashLoadedOnce) {
473
+ if (typeof this.loadSessionTrash === 'function') {
474
+ void this.loadSessionTrash({ forceRefresh: false });
475
+ }
476
+ }
477
+ void loadDoctorOverview(this);
478
+ }
479
+ if (
480
+ targetTab === 'sessions'
481
+ && typeof this.prepareSessionTabRender === 'function'
482
+ && (!this.sessionListRenderEnabled || !this.sessionPreviewRenderEnabled)
483
+ ) {
484
+ this.prepareSessionTabRender();
485
+ }
486
+ this.scheduleAfterFrame(() => {
487
+ this.clearMainTabSwitchIntent(normalizedTab);
488
+ });
489
+ return;
490
+ }
491
+ const isLeavingSessions = previousTab === 'sessions' && targetTab !== 'sessions';
492
+ const shouldPreserveSessionRender = isLeavingSessions && this.preserveSessionRenderOnTabLeave === true;
493
+ const shouldDeferApply = isLeavingSessions && !shouldPreserveSessionRender;
494
+ if (isLeavingSessions && !this.isSessionPanelFastHidden()) {
495
+ this.setSessionPanelFastHidden(!shouldPreserveSessionRender);
496
+ }
497
+ if (shouldDeferApply && typeof this.suspendSessionTabRender === 'function') {
498
+ this.suspendSessionTabRender();
499
+ }
500
+ if (!shouldDeferApply) {
501
+ switchState.ticket += 1;
502
+ switchState.pendingTarget = '';
503
+ const result = switchMainTabHelper.call(this, targetTab);
504
+ persistNavState(this);
505
+ if (targetTab === 'dashboard') {
506
+ void loadDoctorOverview(this);
507
+ }
508
+ this.scheduleAfterFrame(() => {
509
+ this.clearMainTabSwitchIntent(normalizedTab);
510
+ });
511
+ return result;
512
+ }
513
+
514
+ const ticket = ++switchState.ticket;
515
+ switchState.pendingTarget = targetTab;
516
+ this.scheduleAfterFrame(() => {
517
+ const liveState = this.ensureMainTabSwitchState();
518
+ if (ticket !== liveState.ticket) return;
519
+ const pendingTarget = liveState.pendingTarget || targetTab;
520
+ liveState.pendingTarget = '';
521
+ switchMainTabHelper.call(this, pendingTarget);
522
+ persistNavState(this);
523
+ if (pendingTarget === 'dashboard') {
524
+ void loadDoctorOverview(this);
525
+ }
526
+ this.clearMainTabSwitchIntent(normalizedTab);
527
+ });
528
+ },
529
+
530
+ scheduleAfterFrame(task) {
531
+ const callback = typeof task === 'function' ? task : () => {};
532
+ if (typeof requestAnimationFrame === 'function') {
533
+ requestAnimationFrame(callback);
534
+ return;
535
+ }
536
+ setTimeout(callback, 16);
537
+ },
538
+ scheduleIdleTask(task, timeoutMs = 160) {
539
+ const callback = typeof task === 'function' ? task : () => {};
540
+ const timeout = Number.isFinite(timeoutMs)
541
+ ? Math.max(16, Math.floor(timeoutMs))
542
+ : 160;
543
+ if (typeof requestIdleCallback === 'function') {
544
+ const id = requestIdleCallback(callback, { timeout });
545
+ return {
546
+ type: 'idle',
547
+ id
548
+ };
549
+ }
550
+ const id = setTimeout(callback, timeout);
551
+ return {
552
+ type: 'timeout',
553
+ id
554
+ };
555
+ },
556
+ cancelIdleTask(handle) {
557
+ if (!handle || typeof handle !== 'object') return;
558
+ const type = handle.type;
559
+ const id = handle.id;
560
+ if (type === 'idle') {
561
+ if (typeof cancelIdleCallback === 'function') {
562
+ cancelIdleCallback(id);
563
+ } else {
564
+ clearTimeout(id);
565
+ }
566
+ return;
567
+ }
568
+ if (type === 'timeout') {
569
+ clearTimeout(id);
570
+ }
571
+ },
572
+ scheduleSessionTabDeferredTeardown(task) {
573
+ const callback = typeof task === 'function' ? task : () => {};
574
+ this.cancelScheduledSessionTabDeferredTeardown();
575
+ this.__sessionTabDeferredTeardownHandle = this.scheduleIdleTask(() => {
576
+ this.__sessionTabDeferredTeardownHandle = null;
577
+ callback();
578
+ }, 180);
579
+ },
580
+ cancelScheduledSessionTabDeferredTeardown() {
581
+ const handle = this.__sessionTabDeferredTeardownHandle || null;
582
+ if (!handle) return;
583
+ this.cancelIdleTask(handle);
584
+ this.__sessionTabDeferredTeardownHandle = null;
585
+ },
586
+
587
+ setSessionListRef(element) {
588
+ this.__sessionListRef = element || null;
589
+ if (this.__sessionListRef && this.mainTab === 'sessions' && this.sessionListRenderEnabled) {
590
+ this.scheduleSessionListViewportFill();
591
+ }
592
+ },
593
+ getSessionListRenderSource() {
594
+ return Array.isArray(this.sortedSessionsList) ? this.sortedSessionsList : [];
595
+ },
596
+ cancelScheduledSessionListViewportFill() {
597
+ const handle = this.__sessionListViewportFillHandle || null;
598
+ if (!handle) return;
599
+ this.cancelIdleTask(handle);
600
+ this.__sessionListViewportFillHandle = null;
601
+ },
602
+ resetSessionListRender() {
603
+ this.cancelScheduledSessionListViewportFill();
604
+ this.sessionListVisibleCount = 0;
605
+ },
606
+ expandVisibleSessionList(stepSize, options = {}) {
607
+ const list = this.getSessionListRenderSource();
608
+ const total = list.length;
609
+ if (total <= 0) {
610
+ this.sessionListVisibleCount = 0;
611
+ return false;
612
+ }
613
+ const rawVisibleCount = Number(this.sessionListVisibleCount);
614
+ const currentCount = Number.isFinite(rawVisibleCount)
615
+ ? Math.max(0, Math.floor(rawVisibleCount))
616
+ : 0;
617
+ const initialBatchSize = Number.isFinite(this.sessionListInitialBatchSize)
618
+ ? Math.max(1, Math.floor(this.sessionListInitialBatchSize))
619
+ : 80;
620
+ const loadStep = Number.isFinite(stepSize)
621
+ ? Math.max(0, Math.floor(stepSize))
622
+ : (Number.isFinite(this.sessionListLoadStep)
623
+ ? Math.max(1, Math.floor(this.sessionListLoadStep))
624
+ : 120);
625
+ let nextCount = currentCount > 0
626
+ ? Math.min(total, currentCount + loadStep)
627
+ : Math.min(total, initialBatchSize);
628
+ if (options && options.ensureActive !== false) {
629
+ const activeKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
630
+ if (activeKey) {
631
+ const activeIndex = list.findIndex((session) => this.getSessionExportKey(session) === activeKey);
632
+ if (activeIndex >= 0) {
633
+ nextCount = Math.max(nextCount, activeIndex + 1);
634
+ }
635
+ }
636
+ }
637
+ nextCount = Math.min(total, nextCount);
638
+ if (nextCount <= currentCount) {
639
+ return false;
640
+ }
641
+ this.sessionListVisibleCount = nextCount;
642
+ return true;
643
+ },
644
+ scheduleSessionListViewportFill() {
645
+ this.cancelScheduledSessionListViewportFill();
646
+ if (this.mainTab !== 'sessions' || !this.sessionListRenderEnabled) {
647
+ return;
648
+ }
649
+ const run = () => {
650
+ this.__sessionListViewportFillHandle = null;
651
+ if (this.mainTab !== 'sessions' || !this.sessionListRenderEnabled) {
652
+ return;
653
+ }
654
+ const list = this.getSessionListRenderSource();
655
+ const total = list.length;
656
+ const visibleCount = Number(this.sessionListVisibleCount);
657
+ const normalizedVisibleCount = Number.isFinite(visibleCount)
658
+ ? Math.max(0, Math.floor(visibleCount))
659
+ : 0;
660
+ if (total <= 0 || normalizedVisibleCount >= total) {
661
+ return;
662
+ }
663
+ const listEl = this.__sessionListRef || null;
664
+ if (!listEl) {
665
+ return;
666
+ }
667
+ const clientHeight = Number(listEl.clientHeight) || 0;
668
+ const scrollHeight = Number(listEl.scrollHeight) || 0;
669
+ const scrollTop = Number(listEl.scrollTop) || 0;
670
+ const remaining = Math.max(0, scrollHeight - scrollTop - clientHeight);
671
+ const shouldGrow = scrollHeight <= (clientHeight + 160) || remaining <= Math.max(160, clientHeight);
672
+ if (!shouldGrow) {
673
+ return;
674
+ }
675
+ if (this.expandVisibleSessionList(undefined, { ensureActive: true })) {
676
+ this.scheduleSessionListViewportFill();
677
+ }
678
+ };
679
+ this.__sessionListViewportFillHandle = this.scheduleIdleTask(run, 120);
680
+ },
681
+ primeSessionListRender() {
682
+ this.resetSessionListRender();
683
+ if (this.mainTab !== 'sessions' || !this.sessionListRenderEnabled) {
684
+ return;
685
+ }
686
+ this.expandVisibleSessionList(undefined, { ensureActive: true });
687
+ this.scheduleSessionListViewportFill();
688
+ },
689
+ onSessionListScroll(event) {
690
+ const nextRef = event && event.currentTarget ? event.currentTarget : this.__sessionListRef;
691
+ if (nextRef) {
692
+ this.__sessionListRef = nextRef;
693
+ }
694
+ this.scheduleSessionListViewportFill();
695
+ if (typeof this.scheduleSessionListMessageCountHydrate === 'function') {
696
+ this.scheduleSessionListMessageCountHydrate();
697
+ }
698
+ },
699
+
700
+ resetSessionPreviewMessageRender() {
701
+ this.sessionPreviewVisibleCount = 0;
702
+ this.invalidateSessionTimelineMeasurementCache();
703
+ },
704
+
705
+ resetSessionDetailPagination() {
706
+ const initialLimit = Number.isFinite(this.sessionDetailInitialMessageLimit)
707
+ ? Math.max(1, Math.floor(this.sessionDetailInitialMessageLimit))
708
+ : 80;
709
+ this.sessionDetailMessageLimit = initialLimit;
710
+ this.sessionPreviewPendingVisibleCount = 0;
711
+ },
712
+
713
+ primeSessionPreviewMessageRender() {
714
+ this.sessionPreviewVisibleCount = 0;
715
+ this.invalidateSessionTimelineMeasurementCache();
716
+ if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
717
+ return;
718
+ }
719
+ const total = Array.isArray(this.activeSessionMessages)
720
+ ? this.activeSessionMessages.length
721
+ : 0;
722
+ if (total <= 0) return;
723
+ this.sessionPreviewVisibleCount = total;
724
+ this.invalidateSessionTimelineMeasurementCache();
725
+ },
726
+
727
+ async loadMoreSessionMessages(stepSize) {
728
+ return loadMoreSessionMessagesHelper.call(this, stepSize);
729
+ },
730
+
731
+ suspendSessionTabRender() {
732
+ this.sessionTabRenderTicket += 1;
733
+ this.sessionListRenderEnabled = false;
734
+ this.sessionPreviewRenderEnabled = false;
735
+ this.cancelScheduledSessionListViewportFill();
736
+ this.cancelSessionTimelineSync();
737
+ this.sessionTimelineActiveKey = '';
738
+ this.sessionTimelineLastSyncAt = 0;
739
+ this.sessionTimelineLastScrollTop = 0;
740
+ this.sessionTimelineLastAnchorY = 0;
741
+ this.sessionTimelineLastDirection = 0;
742
+ this.__sessionListRef = null;
743
+ this.sessionPreviewScrollEl = null;
744
+ this.sessionPreviewContainerEl = null;
745
+ this.sessionPreviewHeaderEl = null;
746
+ },
747
+
748
+ finalizeSessionTabTeardown() {
749
+ this.resetSessionListRender();
750
+ this.resetSessionPreviewMessageRender();
751
+ this.sessionPreviewPendingVisibleCount = 0;
752
+ this.clearSessionTimelineRefs();
753
+ },
754
+
755
+ teardownSessionTabRender() {
756
+ this.suspendSessionTabRender();
757
+ this.finalizeSessionTabTeardown();
758
+ },
759
+
760
+ prepareSessionTabRender() {
761
+ const ticket = ++this.sessionTabRenderTicket;
762
+ this.sessionListRenderEnabled = false;
763
+ this.sessionPreviewRenderEnabled = false;
764
+ this.resetSessionListRender();
765
+ this.resetSessionPreviewMessageRender();
766
+
767
+ this.scheduleAfterFrame(() => {
768
+ if (ticket !== this.sessionTabRenderTicket || this.mainTab !== 'sessions') {
769
+ return;
770
+ }
771
+ this.sessionListRenderEnabled = true;
772
+ this.primeSessionListRender();
773
+
774
+ this.scheduleAfterFrame(() => {
775
+ if (ticket !== this.sessionTabRenderTicket || this.mainTab !== 'sessions') {
776
+ return;
777
+ }
778
+ this.sessionPreviewRenderEnabled = true;
779
+ this.$nextTick(() => {
780
+ if (ticket !== this.sessionTabRenderTicket || this.mainTab !== 'sessions') {
781
+ return;
782
+ }
783
+ this.primeSessionPreviewMessageRender();
784
+ this.updateSessionTimelineOffset();
785
+ if (!this.sessionTimelineEnabled) {
786
+ return;
787
+ }
788
+ const syncTask = () => {
789
+ if (ticket !== this.sessionTabRenderTicket || this.mainTab !== 'sessions') {
790
+ return;
791
+ }
792
+ this.scheduleSessionTimelineSync();
793
+ };
794
+ if (typeof this.scheduleAfterFrame === 'function') {
795
+ this.scheduleAfterFrame(syncTask);
796
+ return;
797
+ }
798
+ syncTask();
799
+ });
800
+ });
801
+ });
802
+ }
803
+ };
804
+ }