codexmate 0.0.28 → 0.0.29

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