codexmate 0.0.28 → 0.0.29

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