codexmate 0.0.26 → 0.0.27

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