codexmate 0.0.29 → 0.0.30

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