codexmate 0.0.21 → 0.0.23

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