codexmate 0.0.21 → 0.0.22

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 (114) hide show
  1. package/README.md +389 -284
  2. package/README.zh.md +321 -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 +575 -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 +198 -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 +161 -149
  52. package/web-ui/modules/app.methods.navigation.mjs +619 -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 +626 -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 +405 -412
  63. package/web-ui/modules/app.methods.task-orchestration.mjs +471 -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 +1609 -0
  67. package/web-ui/modules/plugins.computed.mjs +220 -0
  68. package/web-ui/modules/plugins.methods.mjs +620 -0
  69. package/web-ui/modules/plugins.storage.mjs +37 -0
  70. package/web-ui/modules/skills.computed.mjs +107 -107
  71. package/web-ui/modules/skills.methods.mjs +481 -481
  72. package/web-ui/partials/index/layout-footer.html +13 -13
  73. package/web-ui/partials/index/layout-header.html +461 -402
  74. package/web-ui/partials/index/modal-config-template-agents.html +175 -125
  75. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  76. package/web-ui/partials/index/modal-health-check.html +72 -72
  77. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  78. package/web-ui/partials/index/modal-skills.html +200 -184
  79. package/web-ui/partials/index/modals-basic.html +165 -156
  80. package/web-ui/partials/index/panel-config-claude.html +138 -126
  81. package/web-ui/partials/index/panel-config-codex.html +234 -237
  82. package/web-ui/partials/index/panel-config-openclaw.html +78 -78
  83. package/web-ui/partials/index/panel-docs.html +147 -130
  84. package/web-ui/partials/index/panel-market.html +174 -174
  85. package/web-ui/partials/index/panel-orchestration.html +397 -397
  86. package/web-ui/partials/index/panel-plugins.html +243 -0
  87. package/web-ui/partials/index/panel-sessions.html +292 -292
  88. package/web-ui/partials/index/panel-settings.html +258 -190
  89. package/web-ui/partials/index/panel-usage.html +353 -213
  90. package/web-ui/session-helpers.mjs +573 -559
  91. package/web-ui/source-bundle.cjs +233 -233
  92. package/web-ui/styles/base-theme.css +264 -271
  93. package/web-ui/styles/controls-forms.css +362 -360
  94. package/web-ui/styles/docs-panel.css +247 -182
  95. package/web-ui/styles/feedback.css +108 -108
  96. package/web-ui/styles/health-check-dialog.css +144 -144
  97. package/web-ui/styles/layout-shell.css +596 -376
  98. package/web-ui/styles/modals-core.css +464 -464
  99. package/web-ui/styles/navigation-panels.css +382 -348
  100. package/web-ui/styles/openclaw-structured.css +266 -266
  101. package/web-ui/styles/plugins-panel.css +518 -0
  102. package/web-ui/styles/responsive.css +456 -450
  103. package/web-ui/styles/sessions-list.css +400 -400
  104. package/web-ui/styles/sessions-preview.css +411 -411
  105. package/web-ui/styles/sessions-toolbar-trash.css +268 -243
  106. package/web-ui/styles/sessions-usage.css +851 -628
  107. package/web-ui/styles/settings-panel.css +166 -0
  108. package/web-ui/styles/skills-list.css +303 -296
  109. package/web-ui/styles/skills-market.css +396 -335
  110. package/web-ui/styles/task-orchestration.css +776 -776
  111. package/web-ui/styles/titles-cards.css +408 -408
  112. package/web-ui/styles.css +20 -18
  113. package/web-ui.html +17 -17
  114. package/README.en.md +0 -349
@@ -1,412 +1,405 @@
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
- const preserveLoading = !!options.preserveLoading;
20
- let startupOk = false;
21
- if (!preserveLoading) {
22
- this.loading = true;
23
- }
24
- this.initError = '';
25
- try {
26
- const statusRes = await api('status');
27
- if (statusRes && statusRes.error) {
28
- this.initError = statusRes.error;
29
- } else {
30
- const listRes = await api('list');
31
- if (listRes && listRes.error) {
32
- this.initError = listRes.error;
33
- } else {
34
- startupOk = true;
35
- this.currentProvider = statusRes.provider;
36
- this.currentModel = statusRes.model;
37
- {
38
- const tier = typeof statusRes.serviceTier === 'string'
39
- ? statusRes.serviceTier.trim().toLowerCase()
40
- : '';
41
- this.serviceTier = tier === 'fast' ? 'fast' : (tier ? 'standard' : 'fast');
42
- }
43
- {
44
- const effort = typeof statusRes.modelReasoningEffort === 'string'
45
- ? statusRes.modelReasoningEffort.trim().toLowerCase()
46
- : '';
47
- const allowedReasoningEfforts = new Set(['low', 'medium', 'high', 'xhigh']);
48
- this.modelReasoningEffort = allowedReasoningEfforts.has(effort) ? effort : 'medium';
49
- }
50
- {
51
- const contextWindow = this.normalizePositiveIntegerInput(
52
- statusRes.modelContextWindow,
53
- 'model_context_window',
54
- defaultModelContextWindow
55
- );
56
- if (this.editingCodexBudgetField !== 'modelContextWindowInput') {
57
- this.modelContextWindowInput = contextWindow.ok && contextWindow.text
58
- ? contextWindow.text
59
- : String(defaultModelContextWindow);
60
- }
61
- }
62
- {
63
- const autoCompactTokenLimit = this.normalizePositiveIntegerInput(
64
- statusRes.modelAutoCompactTokenLimit,
65
- 'model_auto_compact_token_limit',
66
- defaultModelAutoCompactTokenLimit
67
- );
68
- if (this.editingCodexBudgetField !== 'modelAutoCompactTokenLimitInput') {
69
- this.modelAutoCompactTokenLimitInput = autoCompactTokenLimit.ok && autoCompactTokenLimit.text
70
- ? autoCompactTokenLimit.text
71
- : String(defaultModelAutoCompactTokenLimit);
72
- }
73
- }
74
- this.providersList = listRes.providers;
75
- if (statusRes.configReady === false) {
76
- this.showMessage('配置已加载', 'info');
77
- }
78
- if (statusRes.initNotice) {
79
- this.showMessage('配置就绪', 'info');
80
- }
81
- this.maybeShowStarPrompt();
82
- }
83
- }
84
- } catch (e) {
85
- this.initError = '连接失败: ' + e.message;
86
- } finally {
87
- if (!preserveLoading) {
88
- this.loading = false;
89
- }
90
- }
91
-
92
- if (startupOk) {
93
- try {
94
- await this.loadModelsForProvider(this.currentProvider);
95
- } catch (_) {}
96
- try {
97
- await this.loadCodexAuthProfiles();
98
- } catch (_) {}
99
- }
100
-
101
- return startupOk;
102
- },
103
-
104
- async loadModelsForProvider(providerName, options = {}) {
105
- const silentError = !!options.silentError;
106
- const targetProvider = typeof providerName === 'string' ? providerName.trim() : '';
107
- const requestSeq = (Number(this.codexModelsRequestSeq) || 0) + 1;
108
- this.codexModelsRequestSeq = requestSeq;
109
- this.codexModelsLoading = true;
110
- if (!targetProvider) {
111
- this.models = [];
112
- this.modelsSource = 'unlimited';
113
- this.modelsHasCurrent = true;
114
- this.codexModelsLoading = false;
115
- return;
116
- }
117
- const isLatestRequest = () => {
118
- const currentProvider = typeof this.currentProvider === 'string' ? this.currentProvider.trim() : '';
119
- return requestSeq === Number(this.codexModelsRequestSeq || 0)
120
- && (!currentProvider || currentProvider === targetProvider);
121
- };
122
- try {
123
- const res = await api('models', { provider: targetProvider });
124
- if (!isLatestRequest()) {
125
- return;
126
- }
127
- if (res.unlimited) {
128
- this.models = [];
129
- this.modelsSource = 'unlimited';
130
- this.modelsHasCurrent = true;
131
- return;
132
- }
133
- if (res.error) {
134
- if (!silentError) {
135
- this.showMessage('获取模型列表失败', 'error');
136
- }
137
- this.models = [];
138
- this.modelsSource = 'error';
139
- this.modelsHasCurrent = true;
140
- return;
141
- }
142
- const list = Array.isArray(res.models) ? res.models : [];
143
- this.models = list;
144
- this.modelsSource = res.source || 'remote';
145
- this.modelsHasCurrent = !!this.currentModel && list.includes(this.currentModel);
146
- } catch (_) {
147
- if (!isLatestRequest()) {
148
- return;
149
- }
150
- if (!silentError) {
151
- this.showMessage('获取模型列表失败', 'error');
152
- }
153
- this.models = [];
154
- this.modelsSource = 'error';
155
- this.modelsHasCurrent = true;
156
- } finally {
157
- if (requestSeq === Number(this.codexModelsRequestSeq || 0)) {
158
- this.codexModelsLoading = false;
159
- }
160
- }
161
- },
162
-
163
- getCurrentClaudeConfig() {
164
- if (!this.currentClaudeConfig) return null;
165
- return this.claudeConfigs[this.currentClaudeConfig] || null;
166
- },
167
-
168
- normalizeClaudeValue,
169
-
170
- normalizeClaudeConfig(config) {
171
- return normalizeClaudeConfig(config);
172
- },
173
-
174
- normalizeClaudeSettingsEnv(env) {
175
- return normalizeClaudeSettingsEnv(env);
176
- },
177
-
178
- matchClaudeConfigFromSettings(env) {
179
- return matchClaudeConfigFromSettings(this.claudeConfigs, env);
180
- },
181
-
182
- findDuplicateClaudeConfigName(config) {
183
- return findDuplicateClaudeConfigName(this.claudeConfigs, config);
184
- },
185
-
186
- mergeClaudeConfig(existing = {}, updates = {}) {
187
- const previous = this.normalizeClaudeConfig(existing);
188
- const next = this.normalizeClaudeConfig({ ...existing, ...updates });
189
- const externalCredentialType = next.apiKey
190
- ? ''
191
- : (next.externalCredentialType || previous.externalCredentialType || '');
192
- return {
193
- apiKey: next.apiKey,
194
- baseUrl: next.baseUrl,
195
- model: next.model || previous.model || 'glm-4.7',
196
- hasKey: !!(next.apiKey || externalCredentialType),
197
- externalCredentialType
198
- };
199
- },
200
-
201
- buildClaudeImportedConfigName(baseUrl) {
202
- const normalizedUrl = typeof baseUrl === 'string' ? baseUrl.trim() : '';
203
- if (!normalizedUrl) return '导入配置';
204
- try {
205
- const parsed = new URL(normalizedUrl);
206
- const host = typeof parsed.host === 'string' ? parsed.host.trim() : '';
207
- if (host) return `导入-${host}`;
208
- } catch (_) {}
209
- return '导入配置';
210
- },
211
-
212
- ensureClaudeConfigFromSettings(env = {}) {
213
- const normalized = this.normalizeClaudeSettingsEnv(env);
214
- const hasCredential = !!(normalized.apiKey || normalized.authToken || normalized.useKey);
215
- if (!normalized.baseUrl || !hasCredential) return '';
216
-
217
- const duplicateName = this.findDuplicateClaudeConfigName(normalized);
218
- if (duplicateName) return duplicateName;
219
-
220
- const preferredName = this.buildClaudeImportedConfigName(normalized.baseUrl);
221
- let candidateName = preferredName;
222
- let suffix = 2;
223
- const maxAttempts = 1000;
224
- while (this.claudeConfigs[candidateName] && suffix <= maxAttempts) {
225
- candidateName = `${preferredName}-${suffix}`;
226
- suffix += 1;
227
- }
228
- if (this.claudeConfigs[candidateName]) {
229
- return '';
230
- }
231
-
232
- this.claudeConfigs[candidateName] = this.mergeClaudeConfig({}, normalized);
233
- this.saveClaudeConfigs();
234
- return candidateName;
235
- },
236
-
237
- async refreshClaudeSelectionFromSettings(options = {}) {
238
- const silent = !!options.silent;
239
- const silentModelError = !!options.silentModelError || silent;
240
- try {
241
- const res = await api('get-claude-settings');
242
- if (res && res.error) {
243
- if (!silent) {
244
- this.showMessage('读取配置失败', 'error');
245
- }
246
- return;
247
- }
248
- const matchName = this.matchClaudeConfigFromSettings((res && res.env) || {});
249
- if (matchName) {
250
- if (this.currentClaudeConfig !== matchName) {
251
- this.currentClaudeConfig = matchName;
252
- }
253
- this.refreshClaudeModelContext({ silentError: silentModelError });
254
- return;
255
- }
256
- const importedName = this.ensureClaudeConfigFromSettings((res && res.env) || {});
257
- if (importedName) {
258
- if (this.currentClaudeConfig !== importedName) {
259
- this.currentClaudeConfig = importedName;
260
- }
261
- this.refreshClaudeModelContext({ silentError: silentModelError });
262
- if (!silent) {
263
- this.showMessage(`检测到外部 Claude 配置,已自动导入:${importedName}`, 'success');
264
- }
265
- return;
266
- }
267
- this.currentClaudeConfig = '';
268
- this.currentClaudeModel = '';
269
- this.resetClaudeModelsState();
270
- if (!silent) {
271
- const tip = res && res.exists
272
- ? '当前 Claude settings.json 与本地配置不匹配,已取消选中'
273
- : '未检测到 Claude settings.json,已取消选中';
274
- this.showMessage(tip, 'info');
275
- }
276
- } catch (_) {
277
- if (!silent) {
278
- this.showMessage('读取配置失败', 'error');
279
- }
280
- }
281
- },
282
-
283
- syncClaudeModelFromConfig() {
284
- const config = this.getCurrentClaudeConfig();
285
- this.currentClaudeModel = config && config.model ? config.model : '';
286
- },
287
-
288
- refreshClaudeModelContext(options = {}) {
289
- this.syncClaudeModelFromConfig();
290
- return this.loadClaudeModels(options);
291
- },
292
-
293
- resetClaudeModelsState() {
294
- this.claudeModels = [];
295
- this.claudeModelsSource = 'idle';
296
- this.claudeModelsHasCurrent = true;
297
- this.claudeModelsLoading = false;
298
- },
299
-
300
- updateClaudeModelsCurrent() {
301
- const currentModel = (this.currentClaudeModel || '').trim();
302
- this.claudeModelsHasCurrent = !!currentModel && this.claudeModels.includes(currentModel);
303
- },
304
-
305
- async loadClaudeModels(options = {}) {
306
- const silentError = !!options.silentError;
307
- const config = this.getCurrentClaudeConfig();
308
- const requestSeq = (Number(this.claudeModelsRequestSeq) || 0) + 1;
309
- this.claudeModelsRequestSeq = requestSeq;
310
- if (!config) {
311
- this.resetClaudeModelsState();
312
- return;
313
- }
314
- const currentConfigName = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
315
- const baseUrl = (config.baseUrl || '').trim();
316
- const apiKey = (config.apiKey || '').trim();
317
- const externalCredentialType = typeof config.externalCredentialType === 'string'
318
- ? config.externalCredentialType.trim()
319
- : '';
320
-
321
- if (!baseUrl) {
322
- this.resetClaudeModelsState();
323
- return;
324
- }
325
- const localCatalog = getClaudeModelCatalogForBaseUrl(baseUrl);
326
- if (!apiKey && externalCredentialType) {
327
- this.claudeModels = localCatalog;
328
- this.claudeModelsSource = localCatalog.length ? 'catalog' : 'unlimited';
329
- if (localCatalog.length) {
330
- this.updateClaudeModelsCurrent();
331
- } else {
332
- this.claudeModelsHasCurrent = true;
333
- }
334
- this.claudeModelsLoading = false;
335
- return;
336
- }
337
-
338
- this.claudeModelsLoading = true;
339
- const isLatestRequest = () => {
340
- if (requestSeq !== Number(this.claudeModelsRequestSeq || 0)) {
341
- return false;
342
- }
343
- const liveConfigName = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
344
- if (currentConfigName && liveConfigName && liveConfigName !== currentConfigName) {
345
- return false;
346
- }
347
- const latestConfig = this.getCurrentClaudeConfig();
348
- if (!latestConfig) {
349
- return false;
350
- }
351
- return (latestConfig.baseUrl || '').trim() === baseUrl
352
- && (latestConfig.apiKey || '').trim() === apiKey
353
- && (typeof latestConfig.externalCredentialType === 'string' ? latestConfig.externalCredentialType.trim() : '') === externalCredentialType;
354
- };
355
- try {
356
- const res = await api('models-by-url', { baseUrl, apiKey });
357
- if (!isLatestRequest()) {
358
- return;
359
- }
360
- if (res.unlimited) {
361
- this.claudeModels = [];
362
- this.claudeModelsSource = 'unlimited';
363
- this.claudeModelsHasCurrent = true;
364
- return;
365
- }
366
- if (res.error) {
367
- if (!silentError) {
368
- this.showMessage('获取模型列表失败', 'error');
369
- }
370
- this.claudeModels = [];
371
- this.claudeModelsSource = 'error';
372
- this.claudeModelsHasCurrent = true;
373
- return;
374
- }
375
- const list = Array.isArray(res.models) ? res.models : [];
376
- this.claudeModels = list;
377
- this.claudeModelsSource = res.source || 'remote';
378
- this.updateClaudeModelsCurrent();
379
- } catch (_) {
380
- if (!isLatestRequest()) {
381
- return;
382
- }
383
- if (!silentError) {
384
- this.showMessage('获取模型列表失败', 'error');
385
- }
386
- this.claudeModels = [];
387
- this.claudeModelsSource = 'error';
388
- this.claudeModelsHasCurrent = true;
389
- } finally {
390
- if (requestSeq === Number(this.claudeModelsRequestSeq || 0)) {
391
- this.claudeModelsLoading = false;
392
- }
393
- }
394
- },
395
-
396
- openClaudeConfigModal() {
397
- this.showClaudeConfigModal = true;
398
- },
399
-
400
- maybeShowStarPrompt() {
401
- const storageKey = 'codexmateStarPrompted';
402
- try {
403
- if (!localStorage.getItem(storageKey)) {
404
- localStorage.setItem(storageKey, '1');
405
- }
406
- } catch (_) {
407
- // Ignore storage failures silently. The startup UI should not show
408
- // promotional prompts or block normal configuration work.
409
- }
410
- }
411
- };
412
- }
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
+ const preserveLoading = !!options.preserveLoading;
20
+ let startupOk = false;
21
+ if (!preserveLoading) {
22
+ this.loading = true;
23
+ }
24
+ this.initError = '';
25
+ try {
26
+ const statusRes = await api('status');
27
+ if (statusRes && statusRes.error) {
28
+ this.initError = statusRes.error;
29
+ } else {
30
+ const listRes = await api('list');
31
+ if (listRes && listRes.error) {
32
+ this.initError = listRes.error;
33
+ } else {
34
+ startupOk = true;
35
+ this.currentProvider = statusRes.provider;
36
+ this.currentModel = statusRes.model;
37
+ {
38
+ const tier = typeof statusRes.serviceTier === 'string'
39
+ ? statusRes.serviceTier.trim().toLowerCase()
40
+ : '';
41
+ this.serviceTier = tier === 'fast' ? 'fast' : (tier ? 'standard' : 'fast');
42
+ }
43
+ {
44
+ const effort = typeof statusRes.modelReasoningEffort === 'string'
45
+ ? statusRes.modelReasoningEffort.trim().toLowerCase()
46
+ : '';
47
+ const allowedReasoningEfforts = new Set(['low', 'medium', 'high', 'xhigh']);
48
+ this.modelReasoningEffort = allowedReasoningEfforts.has(effort) ? effort : 'medium';
49
+ }
50
+ {
51
+ const contextWindow = this.normalizePositiveIntegerInput(
52
+ statusRes.modelContextWindow,
53
+ 'model_context_window',
54
+ defaultModelContextWindow
55
+ );
56
+ if (this.editingCodexBudgetField !== 'modelContextWindowInput') {
57
+ this.modelContextWindowInput = contextWindow.ok && contextWindow.text
58
+ ? contextWindow.text
59
+ : String(defaultModelContextWindow);
60
+ }
61
+ }
62
+ {
63
+ const autoCompactTokenLimit = this.normalizePositiveIntegerInput(
64
+ statusRes.modelAutoCompactTokenLimit,
65
+ 'model_auto_compact_token_limit',
66
+ defaultModelAutoCompactTokenLimit
67
+ );
68
+ if (this.editingCodexBudgetField !== 'modelAutoCompactTokenLimitInput') {
69
+ this.modelAutoCompactTokenLimitInput = autoCompactTokenLimit.ok && autoCompactTokenLimit.text
70
+ ? autoCompactTokenLimit.text
71
+ : String(defaultModelAutoCompactTokenLimit);
72
+ }
73
+ }
74
+ this.providersList = listRes.providers;
75
+ if (statusRes.configReady === false) {
76
+ this.showMessage('配置已加载', 'info');
77
+ }
78
+ if (statusRes.initNotice) {
79
+ this.showMessage('配置就绪', 'info');
80
+ }
81
+ this.maybeShowStarPrompt();
82
+ }
83
+ }
84
+ } catch (e) {
85
+ this.initError = '连接失败: ' + e.message;
86
+ } finally {
87
+ if (!preserveLoading) {
88
+ this.loading = false;
89
+ }
90
+ }
91
+
92
+ if (startupOk) {
93
+ try {
94
+ await this.loadModelsForProvider(this.currentProvider);
95
+ } catch (_) {}
96
+ try {
97
+ await this.loadCodexAuthProfiles();
98
+ } catch (_) {}
99
+ }
100
+
101
+ return startupOk;
102
+ },
103
+
104
+ async loadModelsForProvider(providerName, options = {}) {
105
+ const targetProvider = typeof providerName === 'string' ? providerName.trim() : '';
106
+ const requestSeq = (Number(this.codexModelsRequestSeq) || 0) + 1;
107
+ this.codexModelsRequestSeq = requestSeq;
108
+ this.codexModelsLoading = true;
109
+ if (!targetProvider) {
110
+ this.models = [];
111
+ this.modelsSource = 'unlimited';
112
+ this.modelsHasCurrent = true;
113
+ this.codexModelsLoading = false;
114
+ return;
115
+ }
116
+ const isLatestRequest = () => {
117
+ const currentProvider = typeof this.currentProvider === 'string' ? this.currentProvider.trim() : '';
118
+ return requestSeq === Number(this.codexModelsRequestSeq || 0)
119
+ && (!currentProvider || currentProvider === targetProvider);
120
+ };
121
+ try {
122
+ const res = await api('models', { provider: targetProvider });
123
+ if (!isLatestRequest()) {
124
+ return;
125
+ }
126
+ if (res.unlimited) {
127
+ this.models = [];
128
+ this.modelsSource = 'unlimited';
129
+ this.modelsHasCurrent = true;
130
+ return;
131
+ }
132
+ if (res.error) {
133
+ this.models = [];
134
+ this.modelsSource = 'error';
135
+ this.modelsHasCurrent = true;
136
+ return;
137
+ }
138
+ const list = Array.isArray(res.models) ? res.models : [];
139
+ this.models = list;
140
+ this.modelsSource = res.source || 'remote';
141
+ this.modelsHasCurrent = !!this.currentModel && list.includes(this.currentModel);
142
+ } catch (_) {
143
+ if (!isLatestRequest()) {
144
+ return;
145
+ }
146
+ this.models = [];
147
+ this.modelsSource = 'error';
148
+ this.modelsHasCurrent = true;
149
+ } finally {
150
+ if (requestSeq === Number(this.codexModelsRequestSeq || 0)) {
151
+ this.codexModelsLoading = false;
152
+ }
153
+ }
154
+ },
155
+
156
+ getCurrentClaudeConfig() {
157
+ if (!this.currentClaudeConfig) return null;
158
+ return this.claudeConfigs[this.currentClaudeConfig] || null;
159
+ },
160
+
161
+ normalizeClaudeValue,
162
+
163
+ normalizeClaudeConfig(config) {
164
+ return normalizeClaudeConfig(config);
165
+ },
166
+
167
+ normalizeClaudeSettingsEnv(env) {
168
+ return normalizeClaudeSettingsEnv(env);
169
+ },
170
+
171
+ matchClaudeConfigFromSettings(env) {
172
+ return matchClaudeConfigFromSettings(this.claudeConfigs, env);
173
+ },
174
+
175
+ findDuplicateClaudeConfigName(config) {
176
+ return findDuplicateClaudeConfigName(this.claudeConfigs, config);
177
+ },
178
+
179
+ mergeClaudeConfig(existing = {}, updates = {}) {
180
+ const previous = this.normalizeClaudeConfig(existing);
181
+ const next = this.normalizeClaudeConfig({ ...existing, ...updates });
182
+ const externalCredentialType = next.apiKey
183
+ ? ''
184
+ : (next.externalCredentialType || previous.externalCredentialType || '');
185
+ return {
186
+ apiKey: next.apiKey,
187
+ baseUrl: next.baseUrl,
188
+ model: next.model || previous.model || 'glm-4.7',
189
+ hasKey: !!(next.apiKey || externalCredentialType),
190
+ externalCredentialType
191
+ };
192
+ },
193
+
194
+ buildClaudeImportedConfigName(baseUrl) {
195
+ const normalizedUrl = typeof baseUrl === 'string' ? baseUrl.trim() : '';
196
+ if (!normalizedUrl) return '导入配置';
197
+ try {
198
+ const parsed = new URL(normalizedUrl);
199
+ const host = typeof parsed.host === 'string' ? parsed.host.trim() : '';
200
+ if (host) return `导入-${host}`;
201
+ } catch (_) {}
202
+ return '导入配置';
203
+ },
204
+
205
+ ensureClaudeConfigFromSettings(env = {}) {
206
+ const normalized = this.normalizeClaudeSettingsEnv(env);
207
+ const hasCredential = !!(normalized.apiKey || normalized.authToken || normalized.useKey);
208
+ if (!normalized.baseUrl || !hasCredential) return '';
209
+
210
+ const duplicateName = this.findDuplicateClaudeConfigName(normalized);
211
+ if (duplicateName) return duplicateName;
212
+
213
+ const preferredName = this.buildClaudeImportedConfigName(normalized.baseUrl);
214
+ let candidateName = preferredName;
215
+ let suffix = 2;
216
+ const maxAttempts = 1000;
217
+ while (this.claudeConfigs[candidateName] && suffix <= maxAttempts) {
218
+ candidateName = `${preferredName}-${suffix}`;
219
+ suffix += 1;
220
+ }
221
+ if (this.claudeConfigs[candidateName]) {
222
+ return '';
223
+ }
224
+
225
+ this.claudeConfigs[candidateName] = this.mergeClaudeConfig({}, normalized);
226
+ this.saveClaudeConfigs();
227
+ return candidateName;
228
+ },
229
+
230
+ async refreshClaudeSelectionFromSettings(options = {}) {
231
+ const silent = !!options.silent;
232
+ const silentModelError = !!options.silentModelError || silent;
233
+ try {
234
+ const res = await api('get-claude-settings');
235
+ if (res && res.error) {
236
+ if (!silent) {
237
+ this.showMessage('读取配置失败', 'error');
238
+ }
239
+ return;
240
+ }
241
+ const matchName = this.matchClaudeConfigFromSettings((res && res.env) || {});
242
+ if (matchName) {
243
+ if (this.currentClaudeConfig !== matchName) {
244
+ this.currentClaudeConfig = matchName;
245
+ }
246
+ this.refreshClaudeModelContext({ silentError: silentModelError });
247
+ return;
248
+ }
249
+ const importedName = this.ensureClaudeConfigFromSettings((res && res.env) || {});
250
+ if (importedName) {
251
+ if (this.currentClaudeConfig !== importedName) {
252
+ this.currentClaudeConfig = importedName;
253
+ }
254
+ this.refreshClaudeModelContext({ silentError: silentModelError });
255
+ if (!silent) {
256
+ this.showMessage(`检测到外部 Claude 配置,已自动导入:${importedName}`, 'success');
257
+ }
258
+ return;
259
+ }
260
+ this.currentClaudeConfig = '';
261
+ this.currentClaudeModel = '';
262
+ this.resetClaudeModelsState();
263
+ if (!silent) {
264
+ const tip = res && res.exists
265
+ ? '当前 Claude settings.json 与本地配置不匹配,已取消选中'
266
+ : '未检测到 Claude settings.json,已取消选中';
267
+ this.showMessage(tip, 'info');
268
+ }
269
+ } catch (_) {
270
+ if (!silent) {
271
+ this.showMessage('读取配置失败', 'error');
272
+ }
273
+ }
274
+ },
275
+
276
+ syncClaudeModelFromConfig() {
277
+ const config = this.getCurrentClaudeConfig();
278
+ this.currentClaudeModel = config && config.model ? config.model : '';
279
+ },
280
+
281
+ refreshClaudeModelContext(options = {}) {
282
+ this.syncClaudeModelFromConfig();
283
+ return this.loadClaudeModels(options);
284
+ },
285
+
286
+ resetClaudeModelsState() {
287
+ this.claudeModels = [];
288
+ this.claudeModelsSource = 'idle';
289
+ this.claudeModelsHasCurrent = true;
290
+ this.claudeModelsLoading = false;
291
+ },
292
+
293
+ updateClaudeModelsCurrent() {
294
+ const currentModel = (this.currentClaudeModel || '').trim();
295
+ this.claudeModelsHasCurrent = !!currentModel && this.claudeModels.includes(currentModel);
296
+ },
297
+
298
+ async loadClaudeModels(options = {}) {
299
+ const silentError = !!options.silentError;
300
+ const config = this.getCurrentClaudeConfig();
301
+ const requestSeq = (Number(this.claudeModelsRequestSeq) || 0) + 1;
302
+ this.claudeModelsRequestSeq = requestSeq;
303
+ if (!config) {
304
+ this.resetClaudeModelsState();
305
+ return;
306
+ }
307
+ const currentConfigName = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
308
+ const baseUrl = (config.baseUrl || '').trim();
309
+ const apiKey = (config.apiKey || '').trim();
310
+ const externalCredentialType = typeof config.externalCredentialType === 'string'
311
+ ? config.externalCredentialType.trim()
312
+ : '';
313
+
314
+ if (!baseUrl) {
315
+ this.resetClaudeModelsState();
316
+ return;
317
+ }
318
+ const localCatalog = getClaudeModelCatalogForBaseUrl(baseUrl);
319
+ if (!apiKey && externalCredentialType) {
320
+ this.claudeModels = localCatalog;
321
+ this.claudeModelsSource = localCatalog.length ? 'catalog' : 'unlimited';
322
+ if (localCatalog.length) {
323
+ this.updateClaudeModelsCurrent();
324
+ } else {
325
+ this.claudeModelsHasCurrent = true;
326
+ }
327
+ this.claudeModelsLoading = false;
328
+ return;
329
+ }
330
+
331
+ this.claudeModelsLoading = true;
332
+ const isLatestRequest = () => {
333
+ if (requestSeq !== Number(this.claudeModelsRequestSeq || 0)) {
334
+ return false;
335
+ }
336
+ const liveConfigName = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
337
+ if (currentConfigName && liveConfigName && liveConfigName !== currentConfigName) {
338
+ return false;
339
+ }
340
+ const latestConfig = this.getCurrentClaudeConfig();
341
+ if (!latestConfig) {
342
+ return false;
343
+ }
344
+ return (latestConfig.baseUrl || '').trim() === baseUrl
345
+ && (latestConfig.apiKey || '').trim() === apiKey
346
+ && (typeof latestConfig.externalCredentialType === 'string' ? latestConfig.externalCredentialType.trim() : '') === externalCredentialType;
347
+ };
348
+ try {
349
+ const res = await api('models-by-url', { baseUrl, apiKey });
350
+ if (!isLatestRequest()) {
351
+ return;
352
+ }
353
+ if (res.unlimited) {
354
+ this.claudeModels = [];
355
+ this.claudeModelsSource = 'unlimited';
356
+ this.claudeModelsHasCurrent = true;
357
+ return;
358
+ }
359
+ if (res.error) {
360
+ if (!silentError) {
361
+ this.showMessage('获取模型列表失败', 'error');
362
+ }
363
+ this.claudeModels = [];
364
+ this.claudeModelsSource = 'error';
365
+ this.claudeModelsHasCurrent = true;
366
+ return;
367
+ }
368
+ const list = Array.isArray(res.models) ? res.models : [];
369
+ this.claudeModels = list;
370
+ this.claudeModelsSource = res.source || 'remote';
371
+ this.updateClaudeModelsCurrent();
372
+ } catch (_) {
373
+ if (!isLatestRequest()) {
374
+ return;
375
+ }
376
+ if (!silentError) {
377
+ this.showMessage('获取模型列表失败', 'error');
378
+ }
379
+ this.claudeModels = [];
380
+ this.claudeModelsSource = 'error';
381
+ this.claudeModelsHasCurrent = true;
382
+ } finally {
383
+ if (requestSeq === Number(this.claudeModelsRequestSeq || 0)) {
384
+ this.claudeModelsLoading = false;
385
+ }
386
+ }
387
+ },
388
+
389
+ openClaudeConfigModal() {
390
+ this.showClaudeConfigModal = true;
391
+ },
392
+
393
+ maybeShowStarPrompt() {
394
+ const storageKey = 'codexmateStarPrompted';
395
+ try {
396
+ if (!localStorage.getItem(storageKey)) {
397
+ localStorage.setItem(storageKey, '1');
398
+ }
399
+ } catch (_) {
400
+ // Ignore storage failures silently. The startup UI should not show
401
+ // promotional prompts or block normal configuration work.
402
+ }
403
+ }
404
+ };
405
+ }