codexmate 0.0.24 → 0.0.26

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