codexmate 0.0.21 → 0.0.23

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