codexmate 0.0.32 → 0.0.34

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