codexmate 0.0.20 → 0.0.21

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