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,265 +1,363 @@
1
- export function createProvidersMethods(options = {}) {
2
- const { api } = options;
3
-
4
- return {
5
- async addProvider() {
6
- const rawName = typeof this.newProvider.name === 'string' ? this.newProvider.name : '';
7
- const rawUrl = typeof this.newProvider.url === 'string' ? this.newProvider.url.trim() : '';
8
- if (!rawName || !rawUrl) {
9
- return this.showMessage('名称和URL必填', 'error');
10
- }
11
- const name = rawName.trim();
12
- if (!name) {
13
- return this.showMessage('名称不能为空', 'error');
14
- }
15
- if (name.toLowerCase() === 'local') {
16
- return this.showMessage('local provider 为系统保留名称,不可新增', 'error');
17
- }
18
- if (this.providersList.some(item => item.name === name)) {
19
- return this.showMessage('名称已存在', 'error');
20
- }
21
-
22
- try {
23
- const res = await api('add-provider', {
24
- name,
25
- url: rawUrl,
26
- key: this.newProvider.key || ''
27
- });
28
- if (res.error) {
29
- this.showMessage(res.error, 'error');
30
- return;
31
- }
32
-
33
- this.showMessage('操作成功', 'success');
34
- this.closeAddModal();
35
- await this.loadAll();
36
- } catch (e) {
37
- this.showMessage('添加失败', 'error');
38
- }
39
- },
40
-
41
- getCurrentCodexAuthProfile() {
42
- const list = Array.isArray(this.codexAuthProfiles) ? this.codexAuthProfiles : [];
43
- return list.find((item) => !!(item && item.current)) || null;
44
- },
45
-
46
- isLocalLikeProvider(providerOrName) {
47
- if (!providerOrName) return false;
48
- const rawName = typeof providerOrName === 'object'
49
- ? String(providerOrName.name || '')
50
- : String(providerOrName);
51
- const normalized = rawName.trim().toLowerCase();
52
- return normalized === 'local';
53
- },
54
-
55
- providerPillState(provider) {
56
- if (this.isLocalLikeProvider(provider)) {
57
- const currentProfile = this.getCurrentCodexAuthProfile();
58
- return currentProfile
59
- ? { configured: true, text: '已登录' }
60
- : { configured: false, text: '未登录' };
61
- }
62
- const configured = !!(provider && provider.hasKey);
63
- return {
64
- configured,
65
- text: configured ? '已配置' : '未配置'
66
- };
67
- },
68
-
69
- providerPillConfigured(provider) {
70
- return this.providerPillState(provider).configured;
71
- },
72
-
73
- providerPillText(provider) {
74
- return this.providerPillState(provider).text;
75
- },
76
-
77
- isReadOnlyProvider(providerOrName) {
78
- if (!providerOrName) return false;
79
- if (typeof providerOrName === 'object') {
80
- return !!providerOrName.readOnly;
81
- }
82
- const name = String(providerOrName).trim();
83
- if (!name) return false;
84
- const target = (this.providersList || []).find((item) => item && item.name === name);
85
- return !!(target && target.readOnly);
86
- },
87
-
88
- isNonDeletableProvider(providerOrName) {
89
- if (!providerOrName) return false;
90
- if (typeof providerOrName === 'object') {
91
- const directName = String(providerOrName.name || '').trim().toLowerCase();
92
- if (directName === 'local') {
93
- return true;
94
- }
95
- return !!providerOrName.nonDeletable;
96
- }
97
- const name = String(providerOrName).trim();
98
- if (!name) return false;
99
- const normalized = name.toLowerCase();
100
- if (normalized === 'local') {
101
- return true;
102
- }
103
- const target = (this.providersList || []).find((item) => item && item.name === name);
104
- return !!(target && target.nonDeletable);
105
- },
106
-
107
- shouldShowProviderDelete(provider) {
108
- return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
109
- },
110
-
111
- shouldShowProviderEdit(provider) {
112
- return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
113
- },
114
-
115
- shouldAllowProviderShare(provider) {
116
- return !this.isReadOnlyProvider(provider) && !this.isLocalLikeProvider(provider);
117
- },
118
-
119
- async deleteProvider(name) {
120
- if (this.isNonDeletableProvider(name)) {
121
- this.showMessage('该 provider 为保留项,不可删除', 'info');
122
- return;
123
- }
124
- try {
125
- const res = await api('delete-provider', { name });
126
- if (res.error) {
127
- this.showMessage(res.error, 'error');
128
- return;
129
- }
130
- if (res.switched && res.provider) {
131
- this.showMessage(`已删除提供商,自动切换到 ${res.provider}${res.model ? ` / ${res.model}` : ''}`, 'success');
132
- } else {
133
- this.showMessage('操作成功', 'success');
134
- }
135
- await this.loadAll();
136
- } catch (_) {
137
- this.showMessage('删除失败', 'error');
138
- }
139
- },
140
-
141
- openEditModal(provider) {
142
- if (!this.shouldShowProviderEdit(provider)) {
143
- this.showMessage('该 provider 为保留项,不可编辑', 'info');
144
- return;
145
- }
146
- this.editingProvider = {
147
- name: provider.name,
148
- url: provider.url || '',
149
- key: '',
150
- readOnly: !!provider.readOnly,
151
- nonEditable: this.isNonDeletableProvider(provider)
152
- };
153
- this.showEditModal = true;
154
- },
155
-
156
- async updateProvider() {
157
- if (this.editingProvider.readOnly || this.editingProvider.nonEditable) {
158
- this.showMessage('该 provider 为保留项,不可编辑', 'error');
159
- this.closeEditModal();
160
- return;
161
- }
162
- const url = typeof this.editingProvider.url === 'string' ? this.editingProvider.url.trim() : '';
163
- if (!url) {
164
- return this.showMessage('URL 必填', 'error');
165
- }
166
-
167
- const name = this.editingProvider.name;
168
- const params = { name, url };
169
- if (typeof this.editingProvider.key === 'string' && this.editingProvider.key.trim()) {
170
- params.key = this.editingProvider.key;
171
- }
172
- try {
173
- const res = await api('update-provider', params);
174
- if (res.error) {
175
- this.showMessage(res.error, 'error');
176
- return;
177
- }
178
- this.closeEditModal();
179
- this.showMessage('操作成功', 'success');
180
- await this.loadAll();
181
- } catch (e) {
182
- this.showMessage('更新失败', 'error');
183
- }
184
- },
185
-
186
- closeEditModal() {
187
- this.showEditModal = false;
188
- this.editingProvider = { name: '', url: '', key: '', readOnly: false, nonEditable: false };
189
- },
190
-
191
- async resetConfig() {
192
- if (this.resetConfigLoading) return;
193
- this.resetConfigLoading = true;
194
- try {
195
- const res = await api('reset-config');
196
- if (res.error) {
197
- this.showMessage(res.error, 'error');
198
- return;
199
- }
200
- const backup = res.backupFile ? `(已备份: ${res.backupFile})` : '';
201
- this.showMessage(`配置已重装${backup}`, 'success');
202
- await this.loadAll();
203
- } catch (e) {
204
- this.showMessage('重装失败', 'error');
205
- } finally {
206
- this.resetConfigLoading = false;
207
- }
208
- },
209
-
210
- async addModel() {
211
- if (!this.newModelName || !this.newModelName.trim()) {
212
- return this.showMessage('请输入模型', 'error');
213
- }
214
- try {
215
- const res = await api('add-model', { model: this.newModelName.trim() });
216
- if (res.error) {
217
- this.showMessage(res.error, 'error');
218
- } else {
219
- this.showMessage('操作成功', 'success');
220
- this.closeModelModal();
221
- await this.loadAll();
222
- }
223
- } catch (_) {
224
- this.showMessage('新增模型失败', 'error');
225
- }
226
- },
227
-
228
- async removeModel(model) {
229
- try {
230
- const res = await api('delete-model', { model });
231
- if (res.error) {
232
- this.showMessage(res.error, 'error');
233
- } else {
234
- this.showMessage('操作成功', 'success');
235
- await this.loadAll();
236
- }
237
- } catch (_) {
238
- this.showMessage('删除模型失败', 'error');
239
- }
240
- },
241
-
242
- closeAddModal() {
243
- this.showAddModal = false;
244
- this.newProvider = { name: '', url: '', key: '' };
245
- },
246
-
247
- closeModelModal() {
248
- this.showModelModal = false;
249
- this.newModelName = '';
250
- },
251
-
252
- formatKey(key) {
253
- if (!key) return '(未设置)';
254
- if (key.length > 10) {
255
- return key.substring(0, 3) + '****' + key.substring(key.length - 3);
256
- }
257
- return '****';
258
- },
259
-
260
- displayApiKey(configName) {
261
- const key = this.claudeConfigs[configName]?.apiKey;
262
- return this.formatKey(key);
263
- }
264
- };
265
- }
1
+ const PROVIDER_NAME_PATTERN = /^[a-zA-Z0-9._-]+$/;
2
+ const RESERVED_PROXY_PROVIDER_NAME = 'codexmate-proxy';
3
+
4
+ function normalizeText(value) {
5
+ return typeof value === 'string' ? value.trim() : '';
6
+ }
7
+
8
+ function normalizeProviderUrl(value) {
9
+ return normalizeText(value).replace(/\/+$/g, '');
10
+ }
11
+
12
+ function isValidHttpUrl(value) {
13
+ if (!value) return false;
14
+ try {
15
+ const parsed = new URL(value);
16
+ return parsed.protocol === 'http:' || parsed.protocol === 'https:';
17
+ } catch (_) {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ function isReservedProviderCreationNameInput(name) {
23
+ const normalized = normalizeText(name).toLowerCase();
24
+ return normalized === RESERVED_PROXY_PROVIDER_NAME;
25
+ }
26
+
27
+ function isValidProviderNameInputValue(name) {
28
+ return PROVIDER_NAME_PATTERN.test(normalizeText(name));
29
+ }
30
+
31
+ function isValidProviderUrlInputValue(url) {
32
+ return isValidHttpUrl(normalizeProviderUrl(url));
33
+ }
34
+
35
+ function findProviderByName(list, name) {
36
+ const target = normalizeText(name);
37
+ if (!target) return null;
38
+ return (Array.isArray(list) ? list : []).find((item) => item && normalizeText(item.name) === target) || null;
39
+ }
40
+
41
+ function normalizeProviderDraftState(target) {
42
+ if (!target || typeof target !== 'object') return;
43
+ if (typeof target.name === 'string') {
44
+ target.name = target.name.trim();
45
+ }
46
+ if (typeof target.url === 'string') {
47
+ target.url = normalizeProviderUrl(target.url);
48
+ }
49
+ }
50
+
51
+ function getProviderValidationForContext(vm, mode = 'add') {
52
+ const draft = mode === 'edit' ? vm.editingProvider : vm.newProvider;
53
+ const editingName = mode === 'edit' ? normalizeText(draft && draft.name) : '';
54
+ const name = normalizeText(draft && draft.name);
55
+ const url = normalizeProviderUrl(draft && draft.url);
56
+ const errors = {
57
+ name: '',
58
+ url: ''
59
+ };
60
+
61
+ if (mode === 'add') {
62
+ if (!name) {
63
+ errors.name = '名称不能为空';
64
+ } else if (!isValidProviderNameInputValue(name)) {
65
+ errors.name = '名称仅支持字母/数字/._-';
66
+ } else if (isReservedProviderCreationNameInput(name)) {
67
+ errors.name = 'codexmate-proxy 为保留名称,不可手动添加';
68
+ } else if (findProviderByName(vm.providersList, name)) {
69
+ errors.name = '名称已存在';
70
+ }
71
+ } else if (!editingName) {
72
+ errors.name = '提供商名称不能为空';
73
+ }
74
+
75
+ if (!url) {
76
+ errors.url = 'URL 必填';
77
+ } else if (!isValidProviderUrlInputValue(url)) {
78
+ errors.url = 'URL 仅支持 http/https';
79
+ }
80
+
81
+ return {
82
+ mode,
83
+ name,
84
+ url,
85
+ errors,
86
+ ok: !errors.name && !errors.url
87
+ };
88
+ }
89
+
90
+ function canSubmitProviderForContext(vm, mode = 'add') {
91
+ if (mode === 'edit' && vm.editingProvider && (vm.editingProvider.readOnly || vm.editingProvider.nonEditable)) {
92
+ return false;
93
+ }
94
+ return getProviderValidationForContext(vm, mode).ok;
95
+ }
96
+
97
+ export function createProvidersMethods(options = {}) {
98
+ const { api } = options;
99
+
100
+ return {
101
+ normalizeProviderDraft(mode = 'add') {
102
+ normalizeProviderDraftState(mode === 'edit' ? this.editingProvider : this.newProvider);
103
+ },
104
+
105
+ isReservedProviderCreationName(name) {
106
+ return isReservedProviderCreationNameInput(name);
107
+ },
108
+
109
+ isValidProviderNameInput(name) {
110
+ return isValidProviderNameInputValue(name);
111
+ },
112
+
113
+ isValidProviderUrlInput(url) {
114
+ return isValidProviderUrlInputValue(url);
115
+ },
116
+
117
+ findProviderByName(name) {
118
+ return findProviderByName(this.providersList, name);
119
+ },
120
+
121
+ getProviderValidation(mode = 'add') {
122
+ return getProviderValidationForContext(this, mode);
123
+ },
124
+
125
+ providerFieldError(mode, fieldName) {
126
+ const validation = getProviderValidationForContext(this, mode);
127
+ return validation && validation.errors && typeof validation.errors[fieldName] === 'string'
128
+ ? validation.errors[fieldName]
129
+ : '';
130
+ },
131
+
132
+ canSubmitProvider(mode = 'add') {
133
+ return canSubmitProviderForContext(this, mode);
134
+ },
135
+
136
+ async addProvider() {
137
+ normalizeProviderDraftState(this.newProvider);
138
+ const validation = getProviderValidationForContext(this, 'add');
139
+ if (!validation.ok) {
140
+ return this.showMessage(validation.errors.name || validation.errors.url || '名称和URL必填', 'error');
141
+ }
142
+
143
+ try {
144
+ const res = await api('add-provider', {
145
+ name: validation.name,
146
+ url: validation.url,
147
+ key: this.newProvider.key || ''
148
+ });
149
+ if (res.error) {
150
+ this.showMessage(res.error, 'error');
151
+ return;
152
+ }
153
+
154
+ this.showMessage('操作成功', 'success');
155
+ this.closeAddModal();
156
+ await this.loadAll();
157
+ } catch (e) {
158
+ this.showMessage('添加失败', 'error');
159
+ }
160
+ },
161
+
162
+ getCurrentCodexAuthProfile() {
163
+ const list = Array.isArray(this.codexAuthProfiles) ? this.codexAuthProfiles : [];
164
+ return list.find((item) => !!(item && item.current)) || null;
165
+ },
166
+
167
+ providerPillState(provider) {
168
+ const configured = !!(provider && provider.hasKey);
169
+ return {
170
+ configured,
171
+ text: configured ? '已配置' : '未配置'
172
+ };
173
+ },
174
+
175
+ providerPillConfigured(provider) {
176
+ return this.providerPillState(provider).configured;
177
+ },
178
+
179
+ providerPillText(provider) {
180
+ return this.providerPillState(provider).text;
181
+ },
182
+
183
+ isReadOnlyProvider(providerOrName) {
184
+ if (!providerOrName) return false;
185
+ if (typeof providerOrName === 'object') {
186
+ return !!providerOrName.readOnly;
187
+ }
188
+ const name = String(providerOrName).trim();
189
+ if (!name) return false;
190
+ const target = (this.providersList || []).find((item) => item && item.name === name);
191
+ return !!(target && target.readOnly);
192
+ },
193
+
194
+ isNonDeletableProvider(providerOrName) {
195
+ if (!providerOrName) return false;
196
+ if (typeof providerOrName === 'object') {
197
+ return !!providerOrName.nonDeletable;
198
+ }
199
+ const name = String(providerOrName).trim();
200
+ if (!name) return false;
201
+ const target = (this.providersList || []).find((item) => item && item.name === name);
202
+ return !!(target && target.nonDeletable);
203
+ },
204
+
205
+ shouldShowProviderDelete(provider) {
206
+ return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
207
+ },
208
+
209
+ shouldShowProviderEdit(provider) {
210
+ return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
211
+ },
212
+
213
+ shouldAllowProviderShare(provider) {
214
+ return !this.isReadOnlyProvider(provider);
215
+ },
216
+
217
+ async deleteProvider(name) {
218
+ if (this.isNonDeletableProvider(name)) {
219
+ this.showMessage('该 provider 为保留项,不可删除', 'info');
220
+ return;
221
+ }
222
+ try {
223
+ const res = await api('delete-provider', { name });
224
+ if (res.error) {
225
+ this.showMessage(res.error, 'error');
226
+ return;
227
+ }
228
+ if (res.switched && res.provider) {
229
+ this.showMessage(`已删除提供商,自动切换到 ${res.provider}${res.model ? ` / ${res.model}` : ''}`, 'success');
230
+ } else {
231
+ this.showMessage('操作成功', 'success');
232
+ }
233
+ await this.loadAll();
234
+ } catch (_) {
235
+ this.showMessage('删除失败', 'error');
236
+ }
237
+ },
238
+
239
+ openEditModal(provider) {
240
+ if (!this.shouldShowProviderEdit(provider)) {
241
+ this.showMessage('该 provider 为保留项,不可编辑', 'info');
242
+ return;
243
+ }
244
+ this.editingProvider = {
245
+ name: provider.name,
246
+ url: normalizeProviderUrl(provider.url || ''),
247
+ key: '',
248
+ readOnly: !!provider.readOnly,
249
+ nonEditable: this.isNonDeletableProvider(provider)
250
+ };
251
+ this.showEditModal = true;
252
+ },
253
+
254
+ async updateProvider() {
255
+ if (this.editingProvider.readOnly || this.editingProvider.nonEditable) {
256
+ this.showMessage('该 provider 为保留项,不可编辑', 'error');
257
+ this.closeEditModal();
258
+ return;
259
+ }
260
+ normalizeProviderDraftState(this.editingProvider);
261
+ const validation = getProviderValidationForContext(this, 'edit');
262
+ if (!validation.ok) {
263
+ return this.showMessage(validation.errors.name || validation.errors.url || 'URL 必填', 'error');
264
+ }
265
+
266
+ const params = { name: validation.name, url: validation.url };
267
+ if (typeof this.editingProvider.key === 'string' && this.editingProvider.key.trim()) {
268
+ params.key = this.editingProvider.key;
269
+ }
270
+ try {
271
+ const res = await api('update-provider', params);
272
+ if (res.error) {
273
+ this.showMessage(res.error, 'error');
274
+ return;
275
+ }
276
+ this.closeEditModal();
277
+ this.showMessage('操作成功', 'success');
278
+ await this.loadAll();
279
+ } catch (e) {
280
+ this.showMessage('更新失败', 'error');
281
+ }
282
+ },
283
+
284
+ closeEditModal() {
285
+ this.showEditModal = false;
286
+ this.editingProvider = { name: '', url: '', key: '', readOnly: false, nonEditable: false };
287
+ },
288
+
289
+ async resetConfig() {
290
+ if (this.resetConfigLoading) return;
291
+ this.resetConfigLoading = true;
292
+ try {
293
+ const res = await api('reset-config');
294
+ if (res.error) {
295
+ this.showMessage(res.error, 'error');
296
+ return;
297
+ }
298
+ const backup = res.backupFile ? `(已备份: ${res.backupFile})` : '';
299
+ this.showMessage(`配置已重装${backup}`, 'success');
300
+ await this.loadAll();
301
+ } catch (e) {
302
+ this.showMessage('重装失败', 'error');
303
+ } finally {
304
+ this.resetConfigLoading = false;
305
+ }
306
+ },
307
+
308
+ async addModel() {
309
+ if (!this.newModelName || !this.newModelName.trim()) {
310
+ return this.showMessage('请输入模型', 'error');
311
+ }
312
+ try {
313
+ const res = await api('add-model', { model: this.newModelName.trim() });
314
+ if (res.error) {
315
+ this.showMessage(res.error, 'error');
316
+ } else {
317
+ this.showMessage('操作成功', 'success');
318
+ this.closeModelModal();
319
+ await this.loadAll();
320
+ }
321
+ } catch (_) {
322
+ this.showMessage('新增模型失败', 'error');
323
+ }
324
+ },
325
+
326
+ async removeModel(model) {
327
+ try {
328
+ const res = await api('delete-model', { model });
329
+ if (res.error) {
330
+ this.showMessage(res.error, 'error');
331
+ } else {
332
+ this.showMessage('操作成功', 'success');
333
+ await this.loadAll();
334
+ }
335
+ } catch (_) {
336
+ this.showMessage('删除模型失败', 'error');
337
+ }
338
+ },
339
+
340
+ closeAddModal() {
341
+ this.showAddModal = false;
342
+ this.newProvider = { name: '', url: '', key: '' };
343
+ },
344
+
345
+ closeModelModal() {
346
+ this.showModelModal = false;
347
+ this.newModelName = '';
348
+ },
349
+
350
+ formatKey(key) {
351
+ if (!key) return '(未设置)';
352
+ if (key.length > 10) {
353
+ return key.substring(0, 3) + '****' + key.substring(key.length - 3);
354
+ }
355
+ return '****';
356
+ },
357
+
358
+ displayApiKey(configName) {
359
+ const key = this.claudeConfigs[configName]?.apiKey;
360
+ return this.formatKey(key);
361
+ }
362
+ };
363
+ }