codexmate 0.0.26 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/README.md +421 -416
  2. package/README.zh.md +354 -349
  3. package/cli/agents-files.js +224 -224
  4. package/cli/archive-helpers.js +446 -446
  5. package/cli/auth-profiles.js +375 -375
  6. package/cli/builtin-proxy.js +1299 -1079
  7. package/cli/claude-proxy.js +1022 -1022
  8. package/cli/config-bootstrap.js +384 -384
  9. package/cli/config-health.js +338 -338
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -356
  12. package/cli/openai-bridge.js +1091 -997
  13. package/cli/openclaw-config.js +629 -629
  14. package/cli/session-convert-args.js +65 -65
  15. package/cli/session-convert-io.js +82 -82
  16. package/cli/session-convert.js +43 -43
  17. package/cli/session-usage.concurrent.js +28 -28
  18. package/cli/session-usage.js +118 -118
  19. package/cli/session-usage.models.js +176 -176
  20. package/cli/skills.js +1141 -1141
  21. package/cli/zip-commands.js +510 -510
  22. package/cli.js +15251 -15218
  23. package/lib/automation.js +404 -404
  24. package/lib/cli-file-utils.js +151 -151
  25. package/lib/cli-models-utils.js +379 -379
  26. package/lib/cli-network-utils.js +190 -190
  27. package/lib/cli-path-utils.js +85 -85
  28. package/lib/cli-session-utils.js +121 -121
  29. package/lib/cli-sessions.js +417 -417
  30. package/lib/cli-utils.js +155 -155
  31. package/lib/download-artifacts.js +92 -92
  32. package/lib/mcp-stdio.js +453 -453
  33. package/lib/task-orchestrator.js +869 -869
  34. package/lib/text-diff.js +303 -303
  35. package/lib/workflow-engine.js +340 -340
  36. package/package.json +1 -1
  37. package/plugins/README.md +20 -20
  38. package/plugins/README.zh-CN.md +20 -20
  39. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  40. package/plugins/prompt-templates/computed.mjs +253 -253
  41. package/plugins/prompt-templates/index.mjs +8 -8
  42. package/plugins/prompt-templates/manifest.mjs +15 -15
  43. package/plugins/prompt-templates/methods.mjs +619 -619
  44. package/plugins/prompt-templates/overview.mjs +90 -90
  45. package/plugins/prompt-templates/ownership.mjs +19 -19
  46. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  47. package/plugins/prompt-templates/storage.mjs +64 -64
  48. package/plugins/registry.mjs +16 -16
  49. package/web-ui/app.js +634 -625
  50. package/web-ui/index.html +35 -35
  51. package/web-ui/logic.agents-diff.mjs +386 -386
  52. package/web-ui/logic.claude.mjs +168 -168
  53. package/web-ui/logic.mjs +5 -5
  54. package/web-ui/logic.runtime.mjs +128 -128
  55. package/web-ui/logic.session-convert.mjs +70 -70
  56. package/web-ui/logic.sessions.mjs +765 -709
  57. package/web-ui/modules/api.mjs +90 -90
  58. package/web-ui/modules/app.computed.dashboard.mjs +171 -171
  59. package/web-ui/modules/app.computed.index.mjs +17 -17
  60. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  61. package/web-ui/modules/app.computed.session.mjs +994 -946
  62. package/web-ui/modules/app.constants.mjs +15 -15
  63. package/web-ui/modules/app.methods.agents.mjs +632 -632
  64. package/web-ui/modules/app.methods.claude-config.mjs +184 -179
  65. package/web-ui/modules/app.methods.codex-config.mjs +860 -860
  66. package/web-ui/modules/app.methods.index.mjs +92 -92
  67. package/web-ui/modules/app.methods.install.mjs +205 -205
  68. package/web-ui/modules/app.methods.navigation.mjs +743 -743
  69. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  70. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  71. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  72. package/web-ui/modules/app.methods.providers.mjs +404 -404
  73. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  74. package/web-ui/modules/app.methods.session-actions.mjs +596 -596
  75. package/web-ui/modules/app.methods.session-browser.mjs +989 -985
  76. package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
  77. package/web-ui/modules/app.methods.session-trash.mjs +439 -424
  78. package/web-ui/modules/app.methods.startup-claude.mjs +526 -522
  79. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  80. package/web-ui/modules/config-mode.computed.mjs +124 -124
  81. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  82. package/web-ui/modules/i18n.dict.mjs +2131 -2113
  83. package/web-ui/modules/i18n.mjs +56 -56
  84. package/web-ui/modules/plugins.computed.mjs +3 -3
  85. package/web-ui/modules/plugins.methods.mjs +3 -3
  86. package/web-ui/modules/plugins.storage.mjs +11 -11
  87. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  88. package/web-ui/modules/skills.computed.mjs +107 -107
  89. package/web-ui/modules/skills.methods.mjs +481 -481
  90. package/web-ui/partials/index/layout-footer.html +13 -13
  91. package/web-ui/partials/index/layout-header.html +475 -475
  92. package/web-ui/partials/index/modal-config-template-agents.html +174 -174
  93. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  94. package/web-ui/partials/index/modal-health-check.html +45 -45
  95. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  96. package/web-ui/partials/index/modal-skills.html +200 -200
  97. package/web-ui/partials/index/modals-basic.html +165 -165
  98. package/web-ui/partials/index/panel-config-claude.html +187 -184
  99. package/web-ui/partials/index/panel-config-codex.html +283 -283
  100. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  101. package/web-ui/partials/index/panel-dashboard.html +186 -186
  102. package/web-ui/partials/index/panel-docs.html +147 -147
  103. package/web-ui/partials/index/panel-market.html +177 -177
  104. package/web-ui/partials/index/panel-orchestration.html +391 -391
  105. package/web-ui/partials/index/panel-plugins.html +279 -279
  106. package/web-ui/partials/index/panel-sessions.html +326 -326
  107. package/web-ui/partials/index/panel-settings.html +274 -258
  108. package/web-ui/partials/index/panel-usage.html +371 -342
  109. package/web-ui/res/json5.min.js +1 -1
  110. package/web-ui/res/vue.global.prod.js +13 -13
  111. package/web-ui/session-helpers.mjs +576 -576
  112. package/web-ui/source-bundle.cjs +233 -233
  113. package/web-ui/styles/base-theme.css +268 -268
  114. package/web-ui/styles/controls-forms.css +423 -423
  115. package/web-ui/styles/dashboard.css +274 -274
  116. package/web-ui/styles/docs-panel.css +247 -247
  117. package/web-ui/styles/feedback.css +108 -108
  118. package/web-ui/styles/health-check-dialog.css +144 -144
  119. package/web-ui/styles/layout-shell.css +603 -603
  120. package/web-ui/styles/modals-core.css +464 -464
  121. package/web-ui/styles/navigation-panels.css +390 -390
  122. package/web-ui/styles/openclaw-structured.css +266 -266
  123. package/web-ui/styles/plugins-panel.css +523 -523
  124. package/web-ui/styles/responsive.css +454 -454
  125. package/web-ui/styles/sessions-list.css +415 -415
  126. package/web-ui/styles/sessions-preview.css +411 -411
  127. package/web-ui/styles/sessions-toolbar-trash.css +330 -330
  128. package/web-ui/styles/sessions-usage.css +1040 -945
  129. package/web-ui/styles/settings-panel.css +185 -166
  130. package/web-ui/styles/skills-list.css +303 -303
  131. package/web-ui/styles/skills-market.css +406 -406
  132. package/web-ui/styles/task-orchestration.css +822 -822
  133. package/web-ui/styles/titles-cards.css +408 -408
  134. package/web-ui/styles.css +21 -21
  135. package/web-ui.html +17 -17
@@ -1,522 +1,526 @@
1
- import {
2
- findDuplicateClaudeConfigName,
3
- getClaudeModelCatalogForBaseUrl,
4
- matchClaudeConfigFromSettings,
5
- normalizeClaudeConfig,
6
- normalizeClaudeSettingsEnv,
7
- normalizeClaudeValue
8
- } from '../logic.mjs';
9
-
10
- export function createStartupClaudeMethods(options = {}) {
11
- const {
12
- api,
13
- defaultModelContextWindow = 190000,
14
- defaultModelAutoCompactTokenLimit = 185000
15
- } = options;
16
-
17
- return {
18
- async loadAll(options = {}) {
19
- if (this._loadAllPromise) {
20
- this._loadAllPendingOptions = options;
21
- return this._loadAllPromise;
22
- }
23
- const preserveLoading = !!options.preserveLoading;
24
- const run = async () => {
25
- const configLoadTimeoutMs = 6000;
26
- const withTimeout = async (promise, ms) => {
27
- const timeoutMs = Number.isFinite(Number(ms)) ? Math.max(0, Number(ms)) : 0;
28
- if (!timeoutMs) {
29
- return promise;
30
- }
31
- let timer = null;
32
- try {
33
- return await Promise.race([
34
- promise,
35
- new Promise((_, reject) => {
36
- timer = setTimeout(() => reject(new Error('timeout')), timeoutMs);
37
- })
38
- ]);
39
- } finally {
40
- if (timer) {
41
- clearTimeout(timer);
42
- }
43
- }
44
- };
45
- if (!preserveLoading) {
46
- this.loading = true;
47
- }
48
- this.initError = '';
49
- const startedAt = Date.now();
50
- const timeLeftMs = () => configLoadTimeoutMs - (Date.now() - startedAt);
51
- try {
52
- const statusRes = await withTimeout(api('status'), timeLeftMs());
53
- if (statusRes && statusRes.error) {
54
- this.initError = statusRes.error;
55
- return false;
56
- }
57
- const listRes = await withTimeout(api('list'), timeLeftMs());
58
- if (listRes && listRes.error) {
59
- this.initError = listRes.error;
60
- return false;
61
- }
62
- this.currentProvider = statusRes.provider;
63
- this.currentModel = statusRes.model;
64
- try {
65
- const installRes = await withTimeout(api('install-status'), Math.max(0, Math.min(1200, timeLeftMs())));
66
- if (installRes && !installRes.error) {
67
- const targets = Array.isArray(installRes.targets) ? installRes.targets : null;
68
- if (targets) {
69
- this.installStatusTargets = targets;
70
- }
71
- if (typeof installRes.packageManager === 'string' && typeof this.normalizeInstallPackageManager === 'function') {
72
- this.installPackageManager = this.normalizeInstallPackageManager(installRes.packageManager);
73
- }
74
- }
75
- } catch (_) {}
76
- {
77
- const tier = typeof statusRes.serviceTier === 'string'
78
- ? statusRes.serviceTier.trim().toLowerCase()
79
- : '';
80
- this.serviceTier = tier === 'fast' ? 'fast' : (tier ? 'standard' : 'fast');
81
- }
82
- {
83
- const effort = typeof statusRes.modelReasoningEffort === 'string'
84
- ? statusRes.modelReasoningEffort.trim().toLowerCase()
85
- : '';
86
- const allowedReasoningEfforts = new Set(['low', 'medium', 'high', 'xhigh']);
87
- this.modelReasoningEffort = allowedReasoningEfforts.has(effort) ? effort : 'medium';
88
- }
89
- {
90
- const contextWindow = this.normalizePositiveIntegerInput(
91
- statusRes.modelContextWindow,
92
- 'model_context_window',
93
- defaultModelContextWindow
94
- );
95
- if (this.editingCodexBudgetField !== 'modelContextWindowInput') {
96
- this.modelContextWindowInput = contextWindow.ok && contextWindow.text
97
- ? contextWindow.text
98
- : String(defaultModelContextWindow);
99
- }
100
- }
101
- {
102
- const autoCompactTokenLimit = this.normalizePositiveIntegerInput(
103
- statusRes.modelAutoCompactTokenLimit,
104
- 'model_auto_compact_token_limit',
105
- defaultModelAutoCompactTokenLimit
106
- );
107
- if (this.editingCodexBudgetField !== 'modelAutoCompactTokenLimitInput') {
108
- this.modelAutoCompactTokenLimitInput = autoCompactTokenLimit.ok && autoCompactTokenLimit.text
109
- ? autoCompactTokenLimit.text
110
- : String(defaultModelAutoCompactTokenLimit);
111
- }
112
- }
113
- this.providersList = listRes.providers;
114
- if (statusRes.configReady === false) {
115
- this.showMessage('配置已加载', 'info');
116
- }
117
- if (statusRes.initNotice) {
118
- this.showMessage('配置就绪', 'info');
119
- }
120
- this.maybeShowStarPrompt();
121
- return true;
122
- } catch (e) {
123
- this.initError = e && e.message === 'timeout'
124
- ? '读取配置超时'
125
- : '连接失败: ' + (e && e.message ? e.message : '');
126
- return false;
127
- } finally {
128
- if (!preserveLoading) {
129
- this.loading = false;
130
- }
131
- }
132
- };
133
-
134
- this._loadAllPromise = run()
135
- .finally(() => {
136
- this._loadAllPromise = null;
137
- });
138
-
139
- const result = await this._loadAllPromise;
140
- if (result) {
141
- Promise.resolve(this.loadModelsForProvider(this.currentProvider)).catch(() => {});
142
- Promise.resolve(this.loadCodexAuthProfiles()).catch(() => {});
143
- }
144
- const pending = this._loadAllPendingOptions;
145
- this._loadAllPendingOptions = null;
146
- if (pending) {
147
- return this.loadAll(pending);
148
- }
149
- return result;
150
- },
151
-
152
- async loadModelsForProvider(providerName, options = {}) {
153
- const targetProvider = typeof providerName === 'string' ? providerName.trim() : '';
154
- const requestSeq = (Number(this.codexModelsRequestSeq) || 0) + 1;
155
- this.codexModelsRequestSeq = requestSeq;
156
- this.codexModelsLoading = true;
157
- if (!targetProvider) {
158
- this.models = [];
159
- this.modelsSource = 'unlimited';
160
- this.modelsHasCurrent = true;
161
- this.codexModelsLoading = false;
162
- return;
163
- }
164
- const isLatestRequest = () => {
165
- const currentProvider = typeof this.currentProvider === 'string' ? this.currentProvider.trim() : '';
166
- return requestSeq === Number(this.codexModelsRequestSeq || 0)
167
- && (!currentProvider || currentProvider === targetProvider);
168
- };
169
- try {
170
- const res = await api('models', { provider: targetProvider });
171
- if (!isLatestRequest()) {
172
- return;
173
- }
174
- if (res.unlimited) {
175
- this.models = [];
176
- this.modelsSource = 'unlimited';
177
- this.modelsHasCurrent = true;
178
- return;
179
- }
180
- if (res.error) {
181
- this.models = [];
182
- this.modelsSource = 'error';
183
- this.modelsHasCurrent = true;
184
- return;
185
- }
186
- const list = Array.isArray(res.models) ? res.models : [];
187
- this.models = list;
188
- this.modelsSource = res.source || 'remote';
189
- this.modelsHasCurrent = !!this.currentModel && list.includes(this.currentModel);
190
- } catch (_) {
191
- if (!isLatestRequest()) {
192
- return;
193
- }
194
- this.models = [];
195
- this.modelsSource = 'error';
196
- this.modelsHasCurrent = true;
197
- } finally {
198
- if (requestSeq === Number(this.codexModelsRequestSeq || 0)) {
199
- this.codexModelsLoading = false;
200
- }
201
- }
202
- },
203
-
204
- getCurrentClaudeConfig() {
205
- if (!this.currentClaudeConfig) return null;
206
- return this.claudeConfigs[this.currentClaudeConfig] || null;
207
- },
208
-
209
- normalizeClaudeValue,
210
-
211
- normalizeClaudeConfig(config) {
212
- return normalizeClaudeConfig(config);
213
- },
214
-
215
- normalizeClaudeSettingsEnv(env) {
216
- return normalizeClaudeSettingsEnv(env);
217
- },
218
-
219
- matchClaudeConfigFromSettings(env) {
220
- return matchClaudeConfigFromSettings(this.claudeConfigs, env);
221
- },
222
-
223
- findDuplicateClaudeConfigName(config) {
224
- return findDuplicateClaudeConfigName(this.claudeConfigs, config);
225
- },
226
-
227
- mergeClaudeConfig(existing = {}, updates = {}) {
228
- const previous = this.normalizeClaudeConfig(existing);
229
- const next = this.normalizeClaudeConfig({ ...existing, ...updates });
230
- const externalCredentialType = next.apiKey
231
- ? ''
232
- : (next.externalCredentialType || previous.externalCredentialType || '');
233
- return {
234
- apiKey: next.apiKey,
235
- baseUrl: next.baseUrl,
236
- model: next.model || previous.model || 'glm-4.7',
237
- hasKey: !!(next.apiKey || externalCredentialType),
238
- externalCredentialType
239
- };
240
- },
241
-
242
- buildClaudeImportedConfigName(baseUrl) {
243
- const normalizedUrl = typeof baseUrl === 'string' ? baseUrl.trim() : '';
244
- if (!normalizedUrl) return '导入配置';
245
- try {
246
- const parsed = new URL(normalizedUrl);
247
- const host = typeof parsed.host === 'string' ? parsed.host.trim() : '';
248
- if (host) return `导入-${host}`;
249
- } catch (_) {}
250
- return '导入配置';
251
- },
252
-
253
- ensureClaudeConfigFromSettings(env = {}) {
254
- const normalized = this.normalizeClaudeSettingsEnv(env);
255
- const hasCredential = !!(normalized.apiKey || normalized.authToken || normalized.useKey);
256
- if (!normalized.baseUrl || !hasCredential) return '';
257
-
258
- const duplicateName = this.findDuplicateClaudeConfigName(normalized);
259
- if (duplicateName) return duplicateName;
260
-
261
- const preferredName = this.buildClaudeImportedConfigName(normalized.baseUrl);
262
- let candidateName = preferredName;
263
- let suffix = 2;
264
- const maxAttempts = 1000;
265
- while (this.claudeConfigs[candidateName] && suffix <= maxAttempts) {
266
- candidateName = `${preferredName}-${suffix}`;
267
- suffix += 1;
268
- }
269
- if (this.claudeConfigs[candidateName]) {
270
- return '';
271
- }
272
-
273
- this.claudeConfigs[candidateName] = this.mergeClaudeConfig({}, normalized);
274
- this.saveClaudeConfigs();
275
- return candidateName;
276
- },
277
-
278
- async refreshClaudeSelectionFromSettings(options = {}) {
279
- if (this._refreshClaudeSelectionPromise) {
280
- this._refreshClaudeSelectionPendingOptions = options;
281
- return this._refreshClaudeSelectionPromise;
282
- }
283
- const silent = !!options.silent;
284
- const silentModelError = !!options.silentModelError || silent;
285
- const run = async () => {
286
- const configLoadTimeoutMs = 6000;
287
- const withTimeout = async (promise, ms) => {
288
- const timeoutMs = Number.isFinite(Number(ms)) ? Math.max(0, Number(ms)) : 0;
289
- if (!timeoutMs) {
290
- return promise;
291
- }
292
- let timer = null;
293
- try {
294
- return await Promise.race([
295
- promise,
296
- new Promise((_, reject) => {
297
- timer = setTimeout(() => reject(new Error('timeout')), timeoutMs);
298
- })
299
- ]);
300
- } finally {
301
- if (timer) {
302
- clearTimeout(timer);
303
- }
304
- }
305
- };
306
- try {
307
- const res = await withTimeout(api('get-claude-settings'), configLoadTimeoutMs);
308
- if (res && res.error) {
309
- if (!silent) {
310
- this.showMessage('读取配置失败', 'error');
311
- }
312
- return;
313
- }
314
- const matchName = this.matchClaudeConfigFromSettings((res && res.env) || {});
315
- if (matchName) {
316
- if (this.currentClaudeConfig !== matchName) {
317
- this.currentClaudeConfig = matchName;
318
- }
319
- this.refreshClaudeModelContext({ silentError: silentModelError });
320
- return;
321
- }
322
- const importedName = this.ensureClaudeConfigFromSettings((res && res.env) || {});
323
- if (importedName) {
324
- if (this.currentClaudeConfig !== importedName) {
325
- this.currentClaudeConfig = importedName;
326
- }
327
- this.refreshClaudeModelContext({ silentError: silentModelError });
328
- if (!silent) {
329
- this.showMessage(`检测到外部 Claude 配置,已自动导入:${importedName}`, 'success');
330
- }
331
- return;
332
- }
333
- {
334
- const configNames = Object.keys(this.claudeConfigs || {});
335
- const current = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
336
- const fallback = current && this.claudeConfigs && this.claudeConfigs[current]
337
- ? current
338
- : (configNames[0] || '');
339
- if (!fallback) {
340
- this.currentClaudeConfig = '';
341
- this.currentClaudeModel = '';
342
- this.resetClaudeModelsState();
343
- return;
344
- }
345
- if (this.currentClaudeConfig !== fallback) {
346
- this.currentClaudeConfig = fallback;
347
- }
348
- this.refreshClaudeModelContext({ silentError: silentModelError });
349
- }
350
- } catch (e) {
351
- if (!silent) {
352
- this.showMessage(e && e.message === 'timeout' ? '读取配置超时' : '读取配置失败', 'error');
353
- }
354
- }
355
- };
356
-
357
- this._refreshClaudeSelectionPromise = Promise.resolve(run())
358
- .finally(() => {
359
- this._refreshClaudeSelectionPromise = null;
360
- });
361
- await this._refreshClaudeSelectionPromise;
362
- const pending = this._refreshClaudeSelectionPendingOptions;
363
- this._refreshClaudeSelectionPendingOptions = null;
364
- if (pending) {
365
- return this.refreshClaudeSelectionFromSettings(pending);
366
- }
367
- },
368
-
369
- syncClaudeModelFromConfig() {
370
- const config = this.getCurrentClaudeConfig();
371
- this.currentClaudeModel = config && config.model ? config.model : '';
372
- this.claudeCustomModelDraft = this.currentClaudeModel;
373
- },
374
-
375
- refreshClaudeModelContext(options = {}) {
376
- this.syncClaudeModelFromConfig();
377
- return this.loadClaudeModels(options);
378
- },
379
-
380
- resetClaudeModelsState() {
381
- this.claudeModels = [];
382
- this.claudeModelsSource = 'idle';
383
- this.claudeModelsHasCurrent = true;
384
- this.claudeModelsLoading = false;
385
- },
386
-
387
- updateClaudeModelsCurrent() {
388
- const currentModel = (this.currentClaudeModel || '').trim();
389
- this.claudeModelsHasCurrent = !!currentModel && this.claudeModels.includes(currentModel);
390
- },
391
-
392
- async loadClaudeModels(options = {}) {
393
- const config = this.getCurrentClaudeConfig();
394
- const requestSeq = (Number(this.claudeModelsRequestSeq) || 0) + 1;
395
- this.claudeModelsRequestSeq = requestSeq;
396
- if (!config) {
397
- this.resetClaudeModelsState();
398
- return;
399
- }
400
- const currentConfigName = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
401
- const baseUrl = (config.baseUrl || '').trim();
402
- const apiKey = (config.apiKey || '').trim();
403
- const externalCredentialType = typeof config.externalCredentialType === 'string'
404
- ? config.externalCredentialType.trim()
405
- : '';
406
-
407
- if (!baseUrl) {
408
- this.resetClaudeModelsState();
409
- return;
410
- }
411
- const localCatalog = getClaudeModelCatalogForBaseUrl(baseUrl);
412
- if (!apiKey && externalCredentialType) {
413
- this.claudeModels = localCatalog;
414
- this.claudeModelsSource = localCatalog.length ? 'catalog' : 'unlimited';
415
- if (localCatalog.length) {
416
- this.updateClaudeModelsCurrent();
417
- } else {
418
- this.claudeModelsHasCurrent = true;
419
- }
420
- this.claudeModelsLoading = false;
421
- return;
422
- }
423
-
424
- const cache = typeof globalThis !== 'undefined'
425
- ? (globalThis.__codexmateClaudeModelsCache || (globalThis.__codexmateClaudeModelsCache = new Map()))
426
- : new Map();
427
- const cacheKey = baseUrl;
428
- const ttlMs = 2 * 60 * 1000;
429
- const now = Date.now();
430
- const cached = cache.get(cacheKey);
431
- const cachedOk = cached
432
- && Number.isFinite(cached.ts)
433
- && now - cached.ts < ttlMs
434
- && Array.isArray(cached.models);
435
- if (cachedOk) {
436
- this.claudeModels = cached.models;
437
- this.claudeModelsSource = cached.source || 'remote';
438
- if (this.claudeModels.length) {
439
- this.updateClaudeModelsCurrent();
440
- } else {
441
- this.claudeModelsHasCurrent = true;
442
- }
443
- this.claudeModelsLoading = false;
444
- } else if (localCatalog.length) {
445
- this.claudeModels = localCatalog;
446
- this.claudeModelsSource = 'catalog';
447
- this.updateClaudeModelsCurrent();
448
- this.claudeModelsLoading = false;
449
- }
450
- const isLatestRequest = () => {
451
- if (requestSeq !== Number(this.claudeModelsRequestSeq || 0)) {
452
- return false;
453
- }
454
- const liveConfigName = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
455
- if (currentConfigName && liveConfigName && liveConfigName !== currentConfigName) {
456
- return false;
457
- }
458
- const latestConfig = this.getCurrentClaudeConfig();
459
- if (!latestConfig) {
460
- return false;
461
- }
462
- return (latestConfig.baseUrl || '').trim() === baseUrl
463
- && (latestConfig.apiKey || '').trim() === apiKey
464
- && (typeof latestConfig.externalCredentialType === 'string' ? latestConfig.externalCredentialType.trim() : '') === externalCredentialType;
465
- };
466
- if (cachedOk) {
467
- return;
468
- }
469
- try {
470
- const res = await api('models-by-url', { baseUrl, apiKey });
471
- if (!isLatestRequest()) {
472
- return;
473
- }
474
- if (res.unlimited) {
475
- this.claudeModels = [];
476
- this.claudeModelsSource = 'unlimited';
477
- this.claudeModelsHasCurrent = true;
478
- cache.set(cacheKey, { ts: Date.now(), models: [], source: 'unlimited' });
479
- return;
480
- }
481
- if (res.error) {
482
- this.claudeModels = [];
483
- this.claudeModelsSource = 'error';
484
- this.claudeModelsHasCurrent = true;
485
- return;
486
- }
487
- const list = Array.isArray(res.models) ? res.models : [];
488
- this.claudeModels = list;
489
- this.claudeModelsSource = res.source || 'remote';
490
- this.updateClaudeModelsCurrent();
491
- cache.set(cacheKey, { ts: Date.now(), models: list, source: this.claudeModelsSource });
492
- } catch (_) {
493
- if (!isLatestRequest()) {
494
- return;
495
- }
496
- this.claudeModels = [];
497
- this.claudeModelsSource = 'error';
498
- this.claudeModelsHasCurrent = true;
499
- } finally {
500
- if (requestSeq === Number(this.claudeModelsRequestSeq || 0)) {
501
- this.claudeModelsLoading = false;
502
- }
503
- }
504
- },
505
-
506
- openClaudeConfigModal() {
507
- this.showClaudeConfigModal = true;
508
- },
509
-
510
- maybeShowStarPrompt() {
511
- const storageKey = 'codexmateStarPrompted';
512
- try {
513
- if (!localStorage.getItem(storageKey)) {
514
- localStorage.setItem(storageKey, '1');
515
- }
516
- } catch (_) {
517
- // Ignore storage failures silently. The startup UI should not show
518
- // promotional prompts or block normal configuration work.
519
- }
520
- }
521
- };
522
- }
1
+ import {
2
+ findDuplicateClaudeConfigName,
3
+ getClaudeModelCatalogForBaseUrl,
4
+ matchClaudeConfigFromSettings,
5
+ normalizeClaudeConfig,
6
+ normalizeClaudeSettingsEnv,
7
+ normalizeClaudeValue
8
+ } from '../logic.mjs';
9
+
10
+ export function createStartupClaudeMethods(options = {}) {
11
+ const {
12
+ api,
13
+ defaultModelContextWindow = 190000,
14
+ defaultModelAutoCompactTokenLimit = 185000
15
+ } = options;
16
+
17
+ return {
18
+ async loadAll(options = {}) {
19
+ if (this._loadAllPromise) {
20
+ this._loadAllPendingOptions = options;
21
+ return this._loadAllPromise;
22
+ }
23
+ const preserveLoading = !!options.preserveLoading;
24
+ const run = async () => {
25
+ const configLoadTimeoutMs = 6000;
26
+ const withTimeout = async (promise, ms) => {
27
+ const timeoutMs = Number.isFinite(Number(ms)) ? Math.max(0, Number(ms)) : 0;
28
+ if (!timeoutMs) {
29
+ return promise;
30
+ }
31
+ let timer = null;
32
+ try {
33
+ return await Promise.race([
34
+ promise,
35
+ new Promise((_, reject) => {
36
+ timer = setTimeout(() => reject(new Error('timeout')), timeoutMs);
37
+ })
38
+ ]);
39
+ } finally {
40
+ if (timer) {
41
+ clearTimeout(timer);
42
+ }
43
+ }
44
+ };
45
+ if (!preserveLoading) {
46
+ this.loading = true;
47
+ }
48
+ this.initError = '';
49
+ const startedAt = Date.now();
50
+ const timeLeftMs = () => configLoadTimeoutMs - (Date.now() - startedAt);
51
+ try {
52
+ const statusRes = await withTimeout(api('status'), timeLeftMs());
53
+ if (statusRes && statusRes.error) {
54
+ this.initError = statusRes.error;
55
+ return false;
56
+ }
57
+ const listRes = await withTimeout(api('list'), timeLeftMs());
58
+ if (listRes && listRes.error) {
59
+ this.initError = listRes.error;
60
+ return false;
61
+ }
62
+ this.currentProvider = statusRes.provider;
63
+ this.currentModel = statusRes.model;
64
+ try {
65
+ const installRes = await withTimeout(api('install-status'), Math.max(0, Math.min(1200, timeLeftMs())));
66
+ if (installRes && !installRes.error) {
67
+ const targets = Array.isArray(installRes.targets) ? installRes.targets : null;
68
+ if (targets) {
69
+ this.installStatusTargets = targets;
70
+ }
71
+ if (typeof installRes.packageManager === 'string' && typeof this.normalizeInstallPackageManager === 'function') {
72
+ this.installPackageManager = this.normalizeInstallPackageManager(installRes.packageManager);
73
+ }
74
+ }
75
+ } catch (_) {}
76
+ {
77
+ const tier = typeof statusRes.serviceTier === 'string'
78
+ ? statusRes.serviceTier.trim().toLowerCase()
79
+ : '';
80
+ this.serviceTier = tier === 'fast' ? 'fast' : (tier ? 'standard' : 'fast');
81
+ }
82
+ {
83
+ const effort = typeof statusRes.modelReasoningEffort === 'string'
84
+ ? statusRes.modelReasoningEffort.trim().toLowerCase()
85
+ : '';
86
+ const allowedReasoningEfforts = new Set(['low', 'medium', 'high', 'xhigh']);
87
+ this.modelReasoningEffort = allowedReasoningEfforts.has(effort) ? effort : 'medium';
88
+ }
89
+ {
90
+ const contextWindow = this.normalizePositiveIntegerInput(
91
+ statusRes.modelContextWindow,
92
+ 'model_context_window',
93
+ defaultModelContextWindow
94
+ );
95
+ if (this.editingCodexBudgetField !== 'modelContextWindowInput') {
96
+ this.modelContextWindowInput = contextWindow.ok && contextWindow.text
97
+ ? contextWindow.text
98
+ : String(defaultModelContextWindow);
99
+ }
100
+ }
101
+ {
102
+ const autoCompactTokenLimit = this.normalizePositiveIntegerInput(
103
+ statusRes.modelAutoCompactTokenLimit,
104
+ 'model_auto_compact_token_limit',
105
+ defaultModelAutoCompactTokenLimit
106
+ );
107
+ if (this.editingCodexBudgetField !== 'modelAutoCompactTokenLimitInput') {
108
+ this.modelAutoCompactTokenLimitInput = autoCompactTokenLimit.ok && autoCompactTokenLimit.text
109
+ ? autoCompactTokenLimit.text
110
+ : String(defaultModelAutoCompactTokenLimit);
111
+ }
112
+ }
113
+ this.providersList = listRes.providers;
114
+ if (statusRes.configReady === false) {
115
+ this.showMessage('配置已加载', 'info');
116
+ }
117
+ if (statusRes.initNotice) {
118
+ this.showMessage('配置就绪', 'info');
119
+ }
120
+ this.maybeShowStarPrompt();
121
+ return true;
122
+ } catch (e) {
123
+ this.initError = e && e.message === 'timeout'
124
+ ? '读取配置超时'
125
+ : '连接失败: ' + (e && e.message ? e.message : '');
126
+ return false;
127
+ } finally {
128
+ if (!preserveLoading) {
129
+ this.loading = false;
130
+ }
131
+ }
132
+ };
133
+
134
+ this._loadAllPromise = run()
135
+ .finally(() => {
136
+ this._loadAllPromise = null;
137
+ });
138
+
139
+ const result = await this._loadAllPromise;
140
+ if (result) {
141
+ Promise.resolve(this.loadModelsForProvider(this.currentProvider)).catch(() => {});
142
+ Promise.resolve(this.loadCodexAuthProfiles()).catch(() => {});
143
+ }
144
+ const pending = this._loadAllPendingOptions;
145
+ this._loadAllPendingOptions = null;
146
+ if (pending) {
147
+ return this.loadAll(pending);
148
+ }
149
+ return result;
150
+ },
151
+
152
+ async loadModelsForProvider(providerName, options = {}) {
153
+ const targetProvider = typeof providerName === 'string' ? providerName.trim() : '';
154
+ const requestSeq = (Number(this.codexModelsRequestSeq) || 0) + 1;
155
+ this.codexModelsRequestSeq = requestSeq;
156
+ this.codexModelsLoading = true;
157
+ if (!targetProvider) {
158
+ this.models = [];
159
+ this.modelsSource = 'unlimited';
160
+ this.modelsHasCurrent = true;
161
+ this.codexModelsLoading = false;
162
+ return;
163
+ }
164
+ const isLatestRequest = () => {
165
+ const currentProvider = typeof this.currentProvider === 'string' ? this.currentProvider.trim() : '';
166
+ return requestSeq === Number(this.codexModelsRequestSeq || 0)
167
+ && (!currentProvider || currentProvider === targetProvider);
168
+ };
169
+ try {
170
+ const res = await api('models', { provider: targetProvider });
171
+ if (!isLatestRequest()) {
172
+ return;
173
+ }
174
+ if (res.unlimited) {
175
+ this.models = [];
176
+ this.modelsSource = 'unlimited';
177
+ this.modelsHasCurrent = true;
178
+ return;
179
+ }
180
+ if (res.error) {
181
+ this.models = [];
182
+ this.modelsSource = 'error';
183
+ this.modelsHasCurrent = true;
184
+ return;
185
+ }
186
+ const list = Array.isArray(res.models) ? res.models : [];
187
+ this.models = list;
188
+ this.modelsSource = res.source || 'remote';
189
+ this.modelsHasCurrent = !!this.currentModel && list.includes(this.currentModel);
190
+ } catch (_) {
191
+ if (!isLatestRequest()) {
192
+ return;
193
+ }
194
+ this.models = [];
195
+ this.modelsSource = 'error';
196
+ this.modelsHasCurrent = true;
197
+ } finally {
198
+ if (requestSeq === Number(this.codexModelsRequestSeq || 0)) {
199
+ this.codexModelsLoading = false;
200
+ }
201
+ }
202
+ },
203
+
204
+ getCurrentClaudeConfig() {
205
+ if (!this.currentClaudeConfig) return null;
206
+ return this.claudeConfigs[this.currentClaudeConfig] || null;
207
+ },
208
+
209
+ normalizeClaudeValue,
210
+
211
+ normalizeClaudeConfig(config) {
212
+ return normalizeClaudeConfig(config);
213
+ },
214
+
215
+ normalizeClaudeSettingsEnv(env) {
216
+ return normalizeClaudeSettingsEnv(env);
217
+ },
218
+
219
+ matchClaudeConfigFromSettings(env) {
220
+ return matchClaudeConfigFromSettings(this.claudeConfigs, env);
221
+ },
222
+
223
+ findDuplicateClaudeConfigName(config) {
224
+ return findDuplicateClaudeConfigName(this.claudeConfigs, config);
225
+ },
226
+
227
+ mergeClaudeConfig(existing = {}, updates = {}) {
228
+ const previous = this.normalizeClaudeConfig(existing);
229
+ const next = this.normalizeClaudeConfig({ ...existing, ...updates });
230
+ const externalCredentialType = next.apiKey
231
+ ? ''
232
+ : (next.externalCredentialType || previous.externalCredentialType || '');
233
+ return {
234
+ apiKey: next.apiKey,
235
+ baseUrl: next.baseUrl,
236
+ model: next.model || previous.model || 'glm-4.7',
237
+ hasKey: !!(next.apiKey || externalCredentialType),
238
+ externalCredentialType
239
+ };
240
+ },
241
+
242
+ buildClaudeImportedConfigName(baseUrl) {
243
+ const normalizedUrl = typeof baseUrl === 'string' ? baseUrl.trim() : '';
244
+ if (!normalizedUrl) return '导入配置';
245
+ try {
246
+ const parsed = new URL(normalizedUrl);
247
+ const host = typeof parsed.host === 'string' ? parsed.host.trim() : '';
248
+ if (host) return `导入-${host}`;
249
+ } catch (_) {}
250
+ return '导入配置';
251
+ },
252
+
253
+ ensureClaudeConfigFromSettings(env = {}) {
254
+ const normalized = this.normalizeClaudeSettingsEnv(env);
255
+ const hasCredential = !!(normalized.apiKey || normalized.authToken || normalized.useKey);
256
+ if (!normalized.baseUrl || !hasCredential) return '';
257
+
258
+ const duplicateName = this.findDuplicateClaudeConfigName(normalized);
259
+ if (duplicateName) return duplicateName;
260
+
261
+ const preferredName = this.buildClaudeImportedConfigName(normalized.baseUrl);
262
+ let candidateName = preferredName;
263
+ let suffix = 2;
264
+ const maxAttempts = 1000;
265
+ while (this.claudeConfigs[candidateName] && suffix <= maxAttempts) {
266
+ candidateName = `${preferredName}-${suffix}`;
267
+ suffix += 1;
268
+ }
269
+ if (this.claudeConfigs[candidateName]) {
270
+ return '';
271
+ }
272
+
273
+ this.claudeConfigs[candidateName] = this.mergeClaudeConfig({}, normalized);
274
+ this.saveClaudeConfigs();
275
+ return candidateName;
276
+ },
277
+
278
+ async refreshClaudeSelectionFromSettings(options = {}) {
279
+ if (this._refreshClaudeSelectionPromise) {
280
+ this._refreshClaudeSelectionPendingOptions = options;
281
+ return this._refreshClaudeSelectionPromise;
282
+ }
283
+ const silent = !!options.silent;
284
+ const silentModelError = !!options.silentModelError || silent;
285
+ const run = async () => {
286
+ const configLoadTimeoutMs = 6000;
287
+ const withTimeout = async (promise, ms) => {
288
+ const timeoutMs = Number.isFinite(Number(ms)) ? Math.max(0, Number(ms)) : 0;
289
+ if (!timeoutMs) {
290
+ return promise;
291
+ }
292
+ let timer = null;
293
+ try {
294
+ return await Promise.race([
295
+ promise,
296
+ new Promise((_, reject) => {
297
+ timer = setTimeout(() => reject(new Error('timeout')), timeoutMs);
298
+ })
299
+ ]);
300
+ } finally {
301
+ if (timer) {
302
+ clearTimeout(timer);
303
+ }
304
+ }
305
+ };
306
+ try {
307
+ const res = await withTimeout(api('get-claude-settings'), configLoadTimeoutMs);
308
+ if (res && res.error) {
309
+ if (!silent) {
310
+ this.showMessage('读取配置失败', 'error');
311
+ }
312
+ return;
313
+ }
314
+ const matchName = this.matchClaudeConfigFromSettings((res && res.env) || {});
315
+ if (matchName) {
316
+ if (this.currentClaudeConfig !== matchName) {
317
+ this.currentClaudeConfig = matchName;
318
+ try { localStorage.setItem('currentClaudeConfig', matchName); } catch (_) {}
319
+ }
320
+ this.refreshClaudeModelContext({ silentError: silentModelError });
321
+ return;
322
+ }
323
+ const importedName = this.ensureClaudeConfigFromSettings((res && res.env) || {});
324
+ if (importedName) {
325
+ if (this.currentClaudeConfig !== importedName) {
326
+ this.currentClaudeConfig = importedName;
327
+ try { localStorage.setItem('currentClaudeConfig', importedName); } catch (_) {}
328
+ }
329
+ this.refreshClaudeModelContext({ silentError: silentModelError });
330
+ if (!silent) {
331
+ this.showMessage(`检测到外部 Claude 配置,已自动导入:${importedName}`, 'success');
332
+ }
333
+ return;
334
+ }
335
+ {
336
+ const configNames = Object.keys(this.claudeConfigs || {});
337
+ const current = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
338
+ const fallback = current && this.claudeConfigs && this.claudeConfigs[current]
339
+ ? current
340
+ : (configNames[0] || '');
341
+ if (!fallback) {
342
+ this.currentClaudeConfig = '';
343
+ try { localStorage.setItem('currentClaudeConfig', ''); } catch (_) {}
344
+ this.currentClaudeModel = '';
345
+ this.resetClaudeModelsState();
346
+ return;
347
+ }
348
+ if (this.currentClaudeConfig !== fallback) {
349
+ this.currentClaudeConfig = fallback;
350
+ try { localStorage.setItem('currentClaudeConfig', fallback); } catch (_) {}
351
+ }
352
+ this.refreshClaudeModelContext({ silentError: silentModelError });
353
+ }
354
+ } catch (e) {
355
+ if (!silent) {
356
+ this.showMessage(e && e.message === 'timeout' ? '读取配置超时' : '读取配置失败', 'error');
357
+ }
358
+ }
359
+ };
360
+
361
+ this._refreshClaudeSelectionPromise = Promise.resolve(run())
362
+ .finally(() => {
363
+ this._refreshClaudeSelectionPromise = null;
364
+ });
365
+ await this._refreshClaudeSelectionPromise;
366
+ const pending = this._refreshClaudeSelectionPendingOptions;
367
+ this._refreshClaudeSelectionPendingOptions = null;
368
+ if (pending) {
369
+ return this.refreshClaudeSelectionFromSettings(pending);
370
+ }
371
+ },
372
+
373
+ syncClaudeModelFromConfig() {
374
+ const config = this.getCurrentClaudeConfig();
375
+ this.currentClaudeModel = config && config.model ? config.model : '';
376
+ this.claudeCustomModelDraft = this.currentClaudeModel;
377
+ },
378
+
379
+ refreshClaudeModelContext(options = {}) {
380
+ this.syncClaudeModelFromConfig();
381
+ return this.loadClaudeModels(options);
382
+ },
383
+
384
+ resetClaudeModelsState() {
385
+ this.claudeModels = [];
386
+ this.claudeModelsSource = 'idle';
387
+ this.claudeModelsHasCurrent = true;
388
+ this.claudeModelsLoading = false;
389
+ },
390
+
391
+ updateClaudeModelsCurrent() {
392
+ const currentModel = (this.currentClaudeModel || '').trim();
393
+ this.claudeModelsHasCurrent = !!currentModel && this.claudeModels.includes(currentModel);
394
+ },
395
+
396
+ async loadClaudeModels(options = {}) {
397
+ const config = this.getCurrentClaudeConfig();
398
+ const requestSeq = (Number(this.claudeModelsRequestSeq) || 0) + 1;
399
+ this.claudeModelsRequestSeq = requestSeq;
400
+ if (!config) {
401
+ this.resetClaudeModelsState();
402
+ return;
403
+ }
404
+ const currentConfigName = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
405
+ const baseUrl = (config.baseUrl || '').trim();
406
+ const apiKey = (config.apiKey || '').trim();
407
+ const externalCredentialType = typeof config.externalCredentialType === 'string'
408
+ ? config.externalCredentialType.trim()
409
+ : '';
410
+
411
+ if (!baseUrl) {
412
+ this.resetClaudeModelsState();
413
+ return;
414
+ }
415
+ const localCatalog = getClaudeModelCatalogForBaseUrl(baseUrl);
416
+ if (!apiKey && externalCredentialType) {
417
+ this.claudeModels = localCatalog;
418
+ this.claudeModelsSource = localCatalog.length ? 'catalog' : 'unlimited';
419
+ if (localCatalog.length) {
420
+ this.updateClaudeModelsCurrent();
421
+ } else {
422
+ this.claudeModelsHasCurrent = true;
423
+ }
424
+ this.claudeModelsLoading = false;
425
+ return;
426
+ }
427
+
428
+ const cache = typeof globalThis !== 'undefined'
429
+ ? (globalThis.__codexmateClaudeModelsCache || (globalThis.__codexmateClaudeModelsCache = new Map()))
430
+ : new Map();
431
+ const cacheKey = baseUrl;
432
+ const ttlMs = 2 * 60 * 1000;
433
+ const now = Date.now();
434
+ const cached = cache.get(cacheKey);
435
+ const cachedOk = cached
436
+ && Number.isFinite(cached.ts)
437
+ && now - cached.ts < ttlMs
438
+ && Array.isArray(cached.models);
439
+ if (cachedOk) {
440
+ this.claudeModels = cached.models;
441
+ this.claudeModelsSource = cached.source || 'remote';
442
+ if (this.claudeModels.length) {
443
+ this.updateClaudeModelsCurrent();
444
+ } else {
445
+ this.claudeModelsHasCurrent = true;
446
+ }
447
+ this.claudeModelsLoading = false;
448
+ } else if (localCatalog.length) {
449
+ this.claudeModels = localCatalog;
450
+ this.claudeModelsSource = 'catalog';
451
+ this.updateClaudeModelsCurrent();
452
+ this.claudeModelsLoading = false;
453
+ }
454
+ const isLatestRequest = () => {
455
+ if (requestSeq !== Number(this.claudeModelsRequestSeq || 0)) {
456
+ return false;
457
+ }
458
+ const liveConfigName = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
459
+ if (currentConfigName && liveConfigName && liveConfigName !== currentConfigName) {
460
+ return false;
461
+ }
462
+ const latestConfig = this.getCurrentClaudeConfig();
463
+ if (!latestConfig) {
464
+ return false;
465
+ }
466
+ return (latestConfig.baseUrl || '').trim() === baseUrl
467
+ && (latestConfig.apiKey || '').trim() === apiKey
468
+ && (typeof latestConfig.externalCredentialType === 'string' ? latestConfig.externalCredentialType.trim() : '') === externalCredentialType;
469
+ };
470
+ if (cachedOk) {
471
+ return;
472
+ }
473
+ try {
474
+ const res = await api('models-by-url', { baseUrl, apiKey });
475
+ if (!isLatestRequest()) {
476
+ return;
477
+ }
478
+ if (res.unlimited) {
479
+ this.claudeModels = [];
480
+ this.claudeModelsSource = 'unlimited';
481
+ this.claudeModelsHasCurrent = true;
482
+ cache.set(cacheKey, { ts: Date.now(), models: [], source: 'unlimited' });
483
+ return;
484
+ }
485
+ if (res.error) {
486
+ this.claudeModels = [];
487
+ this.claudeModelsSource = 'error';
488
+ this.claudeModelsHasCurrent = true;
489
+ return;
490
+ }
491
+ const list = Array.isArray(res.models) ? res.models : [];
492
+ this.claudeModels = list;
493
+ this.claudeModelsSource = res.source || 'remote';
494
+ this.updateClaudeModelsCurrent();
495
+ cache.set(cacheKey, { ts: Date.now(), models: list, source: this.claudeModelsSource });
496
+ } catch (_) {
497
+ if (!isLatestRequest()) {
498
+ return;
499
+ }
500
+ this.claudeModels = [];
501
+ this.claudeModelsSource = 'error';
502
+ this.claudeModelsHasCurrent = true;
503
+ } finally {
504
+ if (requestSeq === Number(this.claudeModelsRequestSeq || 0)) {
505
+ this.claudeModelsLoading = false;
506
+ }
507
+ }
508
+ },
509
+
510
+ openClaudeConfigModal() {
511
+ this.showClaudeConfigModal = true;
512
+ },
513
+
514
+ maybeShowStarPrompt() {
515
+ const storageKey = 'codexmateStarPrompted';
516
+ try {
517
+ if (!localStorage.getItem(storageKey)) {
518
+ localStorage.setItem(storageKey, '1');
519
+ }
520
+ } catch (_) {
521
+ // Ignore storage failures silently. The startup UI should not show
522
+ // promotional prompts or block normal configuration work.
523
+ }
524
+ }
525
+ };
526
+ }