codexmate 0.0.30 → 0.0.32
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.
- package/README.md +363 -421
- package/README.zh.md +371 -354
- package/cli/agents-files.js +224 -224
- package/cli/archive-helpers.js +446 -446
- package/cli/auth-profiles.js +375 -375
- package/cli/builtin-proxy.js +1725 -1725
- package/cli/claude-proxy.js +1022 -1022
- package/cli/config-bootstrap.js +402 -402
- package/cli/config-health.js +454 -454
- package/cli/doctor-core.js +903 -903
- package/cli/import-skills-url.js +356 -356
- package/cli/local-bridge.js +324 -324
- package/cli/openai-bridge.js +1653 -1653
- package/cli/openclaw-config.js +629 -629
- package/cli/session-convert-args.js +69 -65
- package/cli/session-convert-io.js +82 -82
- package/cli/session-convert.js +150 -43
- package/cli/session-usage.concurrent.js +28 -28
- package/cli/session-usage.js +118 -118
- package/cli/session-usage.models.js +176 -176
- package/cli/skills.js +1141 -1141
- package/cli/zip-commands.js +510 -510
- package/cli.js +15829 -15481
- package/lib/automation.js +404 -404
- package/lib/cli-file-utils.js +151 -151
- package/lib/cli-models-utils.js +440 -440
- package/lib/cli-network-utils.js +190 -190
- package/lib/cli-path-utils.js +85 -85
- package/lib/cli-session-utils.js +121 -121
- package/lib/cli-sessions.js +426 -417
- package/lib/cli-utils.js +155 -155
- package/lib/cli-webhook.js +126 -126
- package/lib/download-artifacts.js +92 -92
- package/lib/mcp-stdio.js +453 -453
- package/lib/task-orchestrator.js +869 -869
- package/lib/text-diff.js +303 -303
- package/lib/workflow-engine.js +340 -340
- package/package.json +76 -76
- package/plugins/README.md +20 -20
- package/plugins/README.zh-CN.md +20 -20
- package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
- package/plugins/prompt-templates/computed.mjs +253 -253
- package/plugins/prompt-templates/index.mjs +8 -8
- package/plugins/prompt-templates/manifest.mjs +15 -15
- package/plugins/prompt-templates/methods.mjs +553 -553
- package/plugins/prompt-templates/overview.mjs +91 -91
- package/plugins/prompt-templates/ownership.mjs +19 -19
- package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
- package/plugins/prompt-templates/storage.mjs +64 -64
- package/plugins/registry.mjs +16 -16
- package/web-ui/app.js +647 -645
- package/web-ui/index.html +36 -36
- package/web-ui/logic.agents-diff.mjs +386 -386
- package/web-ui/logic.claude.mjs +168 -168
- package/web-ui/logic.codex.mjs +69 -69
- package/web-ui/logic.mjs +5 -5
- package/web-ui/logic.runtime.mjs +128 -128
- package/web-ui/logic.session-convert.mjs +70 -70
- package/web-ui/logic.sessions.mjs +781 -765
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +248 -248
- package/web-ui/modules/app.computed.index.mjs +17 -17
- package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
- package/web-ui/modules/app.computed.session.mjs +693 -999
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +651 -632
- package/web-ui/modules/app.methods.claude-config.mjs +200 -200
- package/web-ui/modules/app.methods.codex-config.mjs +861 -917
- package/web-ui/modules/app.methods.index.mjs +94 -94
- package/web-ui/modules/app.methods.install.mjs +205 -205
- package/web-ui/modules/app.methods.navigation.mjs +774 -774
- package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
- package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
- package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
- package/web-ui/modules/app.methods.providers.mjs +529 -529
- package/web-ui/modules/app.methods.runtime.mjs +345 -345
- package/web-ui/modules/app.methods.session-actions.mjs +591 -593
- package/web-ui/modules/app.methods.session-browser.mjs +1012 -984
- package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
- package/web-ui/modules/app.methods.session-trash.mjs +438 -438
- package/web-ui/modules/app.methods.startup-claude.mjs +537 -534
- package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
- package/web-ui/modules/app.methods.webhook.mjs +79 -79
- package/web-ui/modules/config-mode.computed.mjs +124 -124
- package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
- package/web-ui/modules/i18n.dict.mjs +3177 -3146
- package/web-ui/modules/i18n.mjs +62 -62
- package/web-ui/modules/plugins.computed.mjs +3 -3
- package/web-ui/modules/plugins.methods.mjs +3 -3
- package/web-ui/modules/plugins.storage.mjs +11 -11
- package/web-ui/modules/provider-url-display.mjs +17 -17
- package/web-ui/modules/sessions-filters-url.mjs +85 -85
- package/web-ui/modules/skills.computed.mjs +107 -107
- package/web-ui/modules/skills.methods.mjs +482 -482
- package/web-ui/partials/index/layout-footer.html +13 -13
- package/web-ui/partials/index/layout-header.html +503 -500
- package/web-ui/partials/index/modal-config-template-agents.html +185 -174
- package/web-ui/partials/index/modal-confirm-toast.html +32 -32
- package/web-ui/partials/index/modal-health-check.html +45 -45
- package/web-ui/partials/index/modal-openclaw-config.html +280 -280
- package/web-ui/partials/index/modal-skills.html +200 -200
- package/web-ui/partials/index/modals-basic.html +162 -162
- package/web-ui/partials/index/panel-config-claude.html +136 -194
- package/web-ui/partials/index/panel-config-codex.html +197 -337
- package/web-ui/partials/index/panel-config-openclaw.html +83 -83
- package/web-ui/partials/index/panel-dashboard.html +219 -219
- package/web-ui/partials/index/panel-docs.html +115 -147
- package/web-ui/partials/index/panel-market.html +177 -177
- package/web-ui/partials/index/panel-orchestration.html +391 -391
- package/web-ui/partials/index/panel-plugins.html +253 -253
- package/web-ui/partials/index/panel-sessions.html +313 -308
- package/web-ui/partials/index/panel-settings.html +190 -190
- package/web-ui/partials/index/panel-trash.html +83 -88
- package/web-ui/partials/index/panel-usage.html +138 -371
- package/web-ui/res/json5.min.js +1 -1
- package/web-ui/res/vue.global.prod.js +13 -13
- package/web-ui/session-helpers.mjs +591 -594
- package/web-ui/source-bundle.cjs +233 -233
- package/web-ui/styles/base-theme.css +281 -281
- package/web-ui/styles/bridge-pool.css +197 -0
- package/web-ui/styles/controls-forms.css +433 -422
- package/web-ui/styles/dashboard.css +406 -406
- package/web-ui/styles/docs-panel.css +245 -271
- package/web-ui/styles/feedback.css +108 -108
- package/web-ui/styles/health-check-dialog.css +144 -144
- package/web-ui/styles/layout-shell.css +638 -626
- package/web-ui/styles/modals-core.css +466 -466
- package/web-ui/styles/navigation-panels.css +391 -391
- package/web-ui/styles/openclaw-structured.css +266 -266
- package/web-ui/styles/plugins-panel.css +564 -564
- package/web-ui/styles/responsive.css +392 -454
- package/web-ui/styles/sessions-list.css +647 -417
- package/web-ui/styles/sessions-preview.css +407 -407
- package/web-ui/styles/sessions-toolbar-trash.css +518 -334
- package/web-ui/styles/sessions-usage.css +588 -1040
- package/web-ui/styles/settings-panel.css +349 -349
- package/web-ui/styles/skills-list.css +305 -305
- package/web-ui/styles/skills-market.css +429 -429
- package/web-ui/styles/task-orchestration.css +822 -822
- package/web-ui/styles/titles-cards.css +472 -472
- package/web-ui/styles/trash-panel.css +90 -90
- package/web-ui/styles/webhook.css +81 -81
- package/web-ui/styles.css +24 -23
- package/web-ui.html +17 -17
|
@@ -1,529 +1,529 @@
|
|
|
1
|
-
const PROVIDER_NAME_PATTERN = /^[a-zA-Z0-9._-]+$/;
|
|
2
|
-
const RESERVED_PROXY_PROVIDER_NAME = 'codexmate-proxy';
|
|
3
|
-
const RESERVED_LOCAL_PROVIDER_NAME = 'local';
|
|
4
|
-
|
|
5
|
-
function normalizeText(value) {
|
|
6
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function normalizeProviderUrl(value) {
|
|
10
|
-
return normalizeText(value).replace(/\/+$/g, '');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function isValidHttpUrl(value) {
|
|
14
|
-
if (!value) return false;
|
|
15
|
-
try {
|
|
16
|
-
const parsed = new URL(value);
|
|
17
|
-
return parsed.protocol === 'http:' || parsed.protocol === 'https:';
|
|
18
|
-
} catch (_) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isReservedProviderCreationNameInput(name) {
|
|
24
|
-
const normalized = normalizeText(name).toLowerCase();
|
|
25
|
-
return normalized === RESERVED_PROXY_PROVIDER_NAME || normalized === RESERVED_LOCAL_PROVIDER_NAME;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function isValidProviderNameInputValue(name) {
|
|
29
|
-
return PROVIDER_NAME_PATTERN.test(normalizeText(name));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function isValidProviderUrlInputValue(url) {
|
|
33
|
-
return isValidHttpUrl(normalizeProviderUrl(url));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function findProviderByName(list, name) {
|
|
37
|
-
const target = normalizeText(name);
|
|
38
|
-
if (!target) return null;
|
|
39
|
-
return (Array.isArray(list) ? list : []).find((item) => item && normalizeText(item.name) === target) || null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function normalizeProviderDraftState(target) {
|
|
43
|
-
if (!target || typeof target !== 'object') return;
|
|
44
|
-
if (typeof target.name === 'string') {
|
|
45
|
-
target.name = target.name.trim();
|
|
46
|
-
}
|
|
47
|
-
if (typeof target.url === 'string') {
|
|
48
|
-
target.url = normalizeProviderUrl(target.url);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function maskKeyLocal(key) {
|
|
53
|
-
if (!key) return '';
|
|
54
|
-
if (key.length <= 8) return '****';
|
|
55
|
-
return key.substring(0, 4) + '...' + key.substring(key.length - 4);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function getProviderValidationForContext(vm, mode = 'add') {
|
|
59
|
-
const draft = mode === 'edit' ? vm.editingProvider : vm.newProvider;
|
|
60
|
-
const editingName = mode === 'edit' ? normalizeText(draft && draft.name) : '';
|
|
61
|
-
const name = normalizeText(draft && draft.name);
|
|
62
|
-
const url = normalizeProviderUrl(draft && draft.url);
|
|
63
|
-
const errors = {
|
|
64
|
-
name: '',
|
|
65
|
-
url: ''
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
if (mode === 'add') {
|
|
69
|
-
if (!name) {
|
|
70
|
-
errors.name = '名称不能为空';
|
|
71
|
-
} else if (!isValidProviderNameInputValue(name)) {
|
|
72
|
-
errors.name = '名称仅支持字母/数字/._-';
|
|
73
|
-
} else if (isReservedProviderCreationNameInput(name)) {
|
|
74
|
-
errors.name = 'codexmate-proxy 为保留名称,不可手动添加';
|
|
75
|
-
} else if (findProviderByName(vm.providersList, name)) {
|
|
76
|
-
errors.name = '名称已存在';
|
|
77
|
-
}
|
|
78
|
-
} else if (!editingName) {
|
|
79
|
-
errors.name = '提供商名称不能为空';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!url) {
|
|
83
|
-
errors.url = 'URL 必填';
|
|
84
|
-
} else if (!isValidProviderUrlInputValue(url)) {
|
|
85
|
-
errors.url = 'URL 仅支持 http/https';
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
mode,
|
|
90
|
-
name,
|
|
91
|
-
url,
|
|
92
|
-
errors,
|
|
93
|
-
ok: !errors.name && !errors.url
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function canSubmitProviderForContext(vm, mode = 'add') {
|
|
98
|
-
if (mode === 'edit' && vm.editingProvider && (vm.editingProvider.readOnly || vm.editingProvider.nonEditable)) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
return getProviderValidationForContext(vm, mode).ok;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function createProvidersMethods(options = {}) {
|
|
105
|
-
const { api } = options;
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
normalizeProviderDraft(mode = 'add') {
|
|
109
|
-
normalizeProviderDraftState(mode === 'edit' ? this.editingProvider : this.newProvider);
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
isReservedProviderCreationName(name) {
|
|
113
|
-
return isReservedProviderCreationNameInput(name);
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
isValidProviderNameInput(name) {
|
|
117
|
-
return isValidProviderNameInputValue(name);
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
isValidProviderUrlInput(url) {
|
|
121
|
-
return isValidProviderUrlInputValue(url);
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
findProviderByName(name) {
|
|
125
|
-
return findProviderByName(this.providersList, name);
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
getProviderValidation(mode = 'add') {
|
|
129
|
-
return getProviderValidationForContext(this, mode);
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
providerFieldError(mode, fieldName) {
|
|
133
|
-
const validation = getProviderValidationForContext(this, mode);
|
|
134
|
-
return validation && validation.errors && typeof validation.errors[fieldName] === 'string'
|
|
135
|
-
? validation.errors[fieldName]
|
|
136
|
-
: '';
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
canSubmitProvider(mode = 'add') {
|
|
140
|
-
return canSubmitProviderForContext(this, mode);
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
async addProvider() {
|
|
144
|
-
normalizeProviderDraftState(this.newProvider);
|
|
145
|
-
const validation = getProviderValidationForContext(this, 'add');
|
|
146
|
-
if (!validation.ok) {
|
|
147
|
-
return this.showMessage(validation.errors.name || validation.errors.url || '名称和URL必填', 'error');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
try {
|
|
151
|
-
const payload = {
|
|
152
|
-
name: validation.name,
|
|
153
|
-
url: validation.url,
|
|
154
|
-
key: this.newProvider.key || ''
|
|
155
|
-
};
|
|
156
|
-
if (this.newProvider && this.newProvider.useTransform) {
|
|
157
|
-
payload.useTransform = true;
|
|
158
|
-
}
|
|
159
|
-
const suggestedModel = typeof this.newProvider._suggestedModel === 'string'
|
|
160
|
-
? this.newProvider._suggestedModel.trim()
|
|
161
|
-
: '';
|
|
162
|
-
const res = await api('add-provider', payload);
|
|
163
|
-
if (res.error) {
|
|
164
|
-
this.showMessage(res.error, 'error');
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// 本地更新:构造新 provider 对象并追加到列表
|
|
169
|
-
const newProvider = {
|
|
170
|
-
name: validation.name,
|
|
171
|
-
url: validation.url,
|
|
172
|
-
upstreamUrl: '',
|
|
173
|
-
codexmate_bridge: payload.useTransform ? 'openai' : '',
|
|
174
|
-
key: maskKeyLocal(payload.key),
|
|
175
|
-
hasKey: !!payload.key,
|
|
176
|
-
models: [],
|
|
177
|
-
current: false,
|
|
178
|
-
readOnly: false,
|
|
179
|
-
nonDeletable: false,
|
|
180
|
-
nonEditable: false
|
|
181
|
-
};
|
|
182
|
-
this.providersList = [...this.providersList, newProvider];
|
|
183
|
-
|
|
184
|
-
this.showMessage('操作成功', 'success');
|
|
185
|
-
this.closeAddModal();
|
|
186
|
-
|
|
187
|
-
if (suggestedModel) {
|
|
188
|
-
if (!this.currentModels || typeof this.currentModels !== 'object') this.currentModels = {};
|
|
189
|
-
this.currentModels[validation.name] = suggestedModel;
|
|
190
|
-
}
|
|
191
|
-
} catch (e) {
|
|
192
|
-
this.showMessage('添加失败', 'error');
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
getCurrentCodexAuthProfile() {
|
|
197
|
-
const list = Array.isArray(this.codexAuthProfiles) ? this.codexAuthProfiles : [];
|
|
198
|
-
return list.find((item) => !!(item && item.current)) || null;
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
providerPillState(provider) {
|
|
202
|
-
const configured = !!(provider && provider.hasKey);
|
|
203
|
-
return {
|
|
204
|
-
configured,
|
|
205
|
-
text: configured ? '已配置' : '未配置'
|
|
206
|
-
};
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
providerPillConfigured(provider) {
|
|
210
|
-
return this.providerPillState(provider).configured;
|
|
211
|
-
},
|
|
212
|
-
|
|
213
|
-
providerPillText(provider) {
|
|
214
|
-
return this.providerPillState(provider).text;
|
|
215
|
-
},
|
|
216
|
-
|
|
217
|
-
isReadOnlyProvider(providerOrName) {
|
|
218
|
-
if (!providerOrName) return false;
|
|
219
|
-
if (typeof providerOrName === 'object') {
|
|
220
|
-
return !!providerOrName.readOnly;
|
|
221
|
-
}
|
|
222
|
-
const name = String(providerOrName).trim();
|
|
223
|
-
if (!name) return false;
|
|
224
|
-
const target = (this.providersList || []).find((item) => item && item.name === name);
|
|
225
|
-
return !!(target && target.readOnly);
|
|
226
|
-
},
|
|
227
|
-
|
|
228
|
-
isNonDeletableProvider(providerOrName) {
|
|
229
|
-
if (!providerOrName) return false;
|
|
230
|
-
if (typeof providerOrName === 'object') {
|
|
231
|
-
return !!providerOrName.nonDeletable;
|
|
232
|
-
}
|
|
233
|
-
const name = String(providerOrName).trim();
|
|
234
|
-
if (!name) return false;
|
|
235
|
-
const target = (this.providersList || []).find((item) => item && item.name === name);
|
|
236
|
-
return !!(target && target.nonDeletable);
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
-
shouldShowProviderDelete(provider) {
|
|
240
|
-
return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
|
|
241
|
-
},
|
|
242
|
-
|
|
243
|
-
shouldShowProviderEdit(provider) {
|
|
244
|
-
return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
|
|
245
|
-
},
|
|
246
|
-
|
|
247
|
-
shouldAllowProviderShare(provider) {
|
|
248
|
-
return !this.isReadOnlyProvider(provider);
|
|
249
|
-
},
|
|
250
|
-
|
|
251
|
-
async deleteProvider(name) {
|
|
252
|
-
if (this.isNonDeletableProvider(name)) {
|
|
253
|
-
this.showMessage('该 provider 为保留项,不可删除', 'info');
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
try {
|
|
257
|
-
const res = await api('delete-provider', { name });
|
|
258
|
-
if (res.error) {
|
|
259
|
-
this.showMessage(res.error, 'error');
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// 本地更新:从列表中移除
|
|
264
|
-
this.providersList = this.providersList.filter(p => p.name !== name);
|
|
265
|
-
|
|
266
|
-
// 清理 currentModels
|
|
267
|
-
if (this.currentModels && this.currentModels[name]) {
|
|
268
|
-
delete this.currentModels[name];
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (res.switched && res.provider) {
|
|
272
|
-
this.currentProvider = res.provider;
|
|
273
|
-
if (res.model) this.currentModel = res.model;
|
|
274
|
-
// 更新 current 标记
|
|
275
|
-
this.providersList = this.providersList.map(p => ({
|
|
276
|
-
...p,
|
|
277
|
-
current: p.name === res.provider
|
|
278
|
-
}));
|
|
279
|
-
this.showMessage(`已删除提供商,自动切换到 ${res.provider}${res.model ? ` / ${res.model}` : ''}`, 'success');
|
|
280
|
-
} else {
|
|
281
|
-
this.showMessage('操作成功', 'success');
|
|
282
|
-
}
|
|
283
|
-
} catch (_) {
|
|
284
|
-
this.showMessage('删除失败', 'error');
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
|
|
288
|
-
openCloneProviderModal(provider) {
|
|
289
|
-
this.newProvider = {
|
|
290
|
-
name: '',
|
|
291
|
-
url: normalizeProviderUrl(provider.url || ''),
|
|
292
|
-
key: '',
|
|
293
|
-
useTransform: !!(provider.codexmate_bridge || '').trim() || /\/bridge\/openai\//.test(provider.url || '')
|
|
294
|
-
};
|
|
295
|
-
this.showAddModal = true;
|
|
296
|
-
},
|
|
297
|
-
|
|
298
|
-
async openEditModal(provider) {
|
|
299
|
-
const requestId = Symbol('openEditModal');
|
|
300
|
-
this._openEditModalRequestId = requestId;
|
|
301
|
-
if (!this.shouldShowProviderEdit(provider)) {
|
|
302
|
-
this.showMessage('该 provider 为保留项,不可编辑', 'info');
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
const isTransformProvider = (() => {
|
|
306
|
-
if (!provider || typeof provider !== 'object') return false;
|
|
307
|
-
const bridge = typeof provider.codexmate_bridge === 'string' ? provider.codexmate_bridge.trim() : '';
|
|
308
|
-
if (bridge === 'openai') return true;
|
|
309
|
-
const url = String(provider.url || '');
|
|
310
|
-
return url.includes('/bridge/openai/');
|
|
311
|
-
})();
|
|
312
|
-
this.editingProvider = {
|
|
313
|
-
name: provider.name,
|
|
314
|
-
url: normalizeProviderUrl(provider.url || ''),
|
|
315
|
-
key: '',
|
|
316
|
-
readOnly: !!provider.readOnly,
|
|
317
|
-
nonEditable: typeof provider.nonEditable === 'boolean'
|
|
318
|
-
? provider.nonEditable
|
|
319
|
-
: this.isNonDeletableProvider(provider),
|
|
320
|
-
useTransform: isTransformProvider
|
|
321
|
-
};
|
|
322
|
-
this.showEditModal = true;
|
|
323
|
-
|
|
324
|
-
if (isTransformProvider) {
|
|
325
|
-
try {
|
|
326
|
-
const res = await api('openai-bridge-get-provider', { name: provider.name });
|
|
327
|
-
if (
|
|
328
|
-
this._openEditModalRequestId === requestId
|
|
329
|
-
&& this.showEditModal
|
|
330
|
-
&& this.editingProvider
|
|
331
|
-
&& this.editingProvider.name === provider.name
|
|
332
|
-
&& res && !res.error
|
|
333
|
-
&& typeof res.baseUrl === 'string'
|
|
334
|
-
&& res.baseUrl.trim()
|
|
335
|
-
) {
|
|
336
|
-
this.editingProvider.url = normalizeProviderUrl(res.baseUrl);
|
|
337
|
-
}
|
|
338
|
-
} catch (_) {
|
|
339
|
-
// ignore
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
|
|
344
|
-
async updateProvider() {
|
|
345
|
-
if (this.editingProvider.readOnly || this.editingProvider.nonEditable) {
|
|
346
|
-
this.showMessage('该 provider 为保留项,不可编辑', 'error');
|
|
347
|
-
this.closeEditModal();
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
normalizeProviderDraftState(this.editingProvider);
|
|
351
|
-
const validation = getProviderValidationForContext(this, 'edit');
|
|
352
|
-
if (!validation.ok) {
|
|
353
|
-
return this.showMessage(validation.errors.name || validation.errors.url || 'URL 必填', 'error');
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const params = { name: validation.name, url: validation.url };
|
|
357
|
-
if (this.editingProvider && this.editingProvider.useTransform) {
|
|
358
|
-
params.useTransform = true;
|
|
359
|
-
}
|
|
360
|
-
if (typeof this.editingProvider.key === 'string' && this.editingProvider.key.trim()) {
|
|
361
|
-
params.key = this.editingProvider.key;
|
|
362
|
-
}
|
|
363
|
-
try {
|
|
364
|
-
const res = await api('update-provider', params);
|
|
365
|
-
if (res.error) {
|
|
366
|
-
this.showMessage(res.error, 'error');
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// 本地更新:更新列表中对应 provider 的 url 和 key
|
|
371
|
-
this.providersList = this.providersList.map(p => {
|
|
372
|
-
if (p.name === validation.name) {
|
|
373
|
-
return {
|
|
374
|
-
...p,
|
|
375
|
-
url: validation.url,
|
|
376
|
-
key: params.key ? maskKeyLocal(params.key) : p.key,
|
|
377
|
-
hasKey: params.key ? true : p.hasKey
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
return p;
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
this.closeEditModal();
|
|
384
|
-
this.showMessage('操作成功', 'success');
|
|
385
|
-
} catch (e) {
|
|
386
|
-
this.showMessage('更新失败', 'error');
|
|
387
|
-
}
|
|
388
|
-
},
|
|
389
|
-
|
|
390
|
-
closeEditModal() {
|
|
391
|
-
this.showEditModal = false;
|
|
392
|
-
this.editingProvider = { name: '', url: '', key: '', readOnly: false, nonEditable: false, useTransform: false };
|
|
393
|
-
},
|
|
394
|
-
|
|
395
|
-
async resetConfig() {
|
|
396
|
-
if (this.resetConfigLoading) return;
|
|
397
|
-
this.resetConfigLoading = true;
|
|
398
|
-
try {
|
|
399
|
-
const res = await api('reset-config');
|
|
400
|
-
if (res.error) {
|
|
401
|
-
this.showMessage(res.error, 'error');
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
const backup = res.backupFile ? `(已备份: ${res.backupFile})` : '';
|
|
405
|
-
this.showMessage(`配置已重装${backup}`, 'success');
|
|
406
|
-
await this.loadAll();
|
|
407
|
-
} catch (e) {
|
|
408
|
-
this.showMessage('重装失败', 'error');
|
|
409
|
-
} finally {
|
|
410
|
-
this.resetConfigLoading = false;
|
|
411
|
-
}
|
|
412
|
-
},
|
|
413
|
-
|
|
414
|
-
async addModel() {
|
|
415
|
-
if (!this.newModelName || !this.newModelName.trim()) {
|
|
416
|
-
return this.showMessage('请输入模型', 'error');
|
|
417
|
-
}
|
|
418
|
-
try {
|
|
419
|
-
const modelName = this.newModelName.trim();
|
|
420
|
-
const res = await api('add-model', { model: modelName });
|
|
421
|
-
if (res.error) {
|
|
422
|
-
this.showMessage(res.error, 'error');
|
|
423
|
-
} else {
|
|
424
|
-
// 本地更新:在当前 provider 的 models 中追加
|
|
425
|
-
this.providersList = this.providersList.map(p => {
|
|
426
|
-
if (p.name === this.currentProvider) {
|
|
427
|
-
const exists = p.models.some(m => m.id === modelName);
|
|
428
|
-
if (!exists) {
|
|
429
|
-
return {
|
|
430
|
-
...p,
|
|
431
|
-
models: [...p.models, { id: modelName, name: modelName, cost: null, contextWindow: undefined, maxTokens: undefined }]
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
return p;
|
|
436
|
-
});
|
|
437
|
-
this.showMessage('操作成功', 'success');
|
|
438
|
-
this.closeModelModal();
|
|
439
|
-
}
|
|
440
|
-
} catch (_) {
|
|
441
|
-
this.showMessage('新增模型失败', 'error');
|
|
442
|
-
}
|
|
443
|
-
},
|
|
444
|
-
|
|
445
|
-
async removeModel(model) {
|
|
446
|
-
try {
|
|
447
|
-
const res = await api('delete-model', { model });
|
|
448
|
-
if (res.error) {
|
|
449
|
-
this.showMessage(res.error, 'error');
|
|
450
|
-
} else {
|
|
451
|
-
// 本地更新:从当前 provider 的 models 中移除
|
|
452
|
-
this.providersList = this.providersList.map(p => {
|
|
453
|
-
if (p.name === this.currentProvider) {
|
|
454
|
-
return {
|
|
455
|
-
...p,
|
|
456
|
-
models: p.models.filter(m => m.id !== model)
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
return p;
|
|
460
|
-
});
|
|
461
|
-
this.showMessage('操作成功', 'success');
|
|
462
|
-
}
|
|
463
|
-
} catch (_) {
|
|
464
|
-
this.showMessage('删除模型失败', 'error');
|
|
465
|
-
}
|
|
466
|
-
},
|
|
467
|
-
|
|
468
|
-
closeAddModal() {
|
|
469
|
-
this.showAddModal = false;
|
|
470
|
-
this.newProvider = { name: '', url: '', key: '', useTransform: false, _suggestedModel: '' };
|
|
471
|
-
},
|
|
472
|
-
|
|
473
|
-
closeModelModal() {
|
|
474
|
-
this.showModelModal = false;
|
|
475
|
-
this.newModelName = '';
|
|
476
|
-
},
|
|
477
|
-
|
|
478
|
-
formatKey(key) {
|
|
479
|
-
if (!key) return '(未设置)';
|
|
480
|
-
if (key.length > 10) {
|
|
481
|
-
return key.substring(0, 3) + '****' + key.substring(key.length - 3);
|
|
482
|
-
}
|
|
483
|
-
return '****';
|
|
484
|
-
},
|
|
485
|
-
|
|
486
|
-
displayApiKey(configName) {
|
|
487
|
-
const config = this.claudeConfigs && this.claudeConfigs[configName]
|
|
488
|
-
? this.claudeConfigs[configName]
|
|
489
|
-
: null;
|
|
490
|
-
const key = config ? config.apiKey : '';
|
|
491
|
-
return this.formatKey(key);
|
|
492
|
-
},
|
|
493
|
-
|
|
494
|
-
async loadLocalBridgeExcluded() {
|
|
495
|
-
try {
|
|
496
|
-
const res = await api('local-bridge-get-excluded');
|
|
497
|
-
if (res && Array.isArray(res.excludedProviders)) {
|
|
498
|
-
this.localBridgeExcluded = res.excludedProviders;
|
|
499
|
-
}
|
|
500
|
-
} catch (e) { /* ignore */ }
|
|
501
|
-
},
|
|
502
|
-
|
|
503
|
-
async toggleLocalBridgeExcluded(providerName) {
|
|
504
|
-
const name = String(providerName || '').trim();
|
|
505
|
-
if (!name) return;
|
|
506
|
-
const idx = this.localBridgeExcluded.indexOf(name);
|
|
507
|
-
const next = [...this.localBridgeExcluded];
|
|
508
|
-
if (idx >= 0) {
|
|
509
|
-
next.splice(idx, 1);
|
|
510
|
-
} else {
|
|
511
|
-
next.push(name);
|
|
512
|
-
}
|
|
513
|
-
try {
|
|
514
|
-
const res = await api('local-bridge-set-excluded', { names: next });
|
|
515
|
-
if (res && !res.error) {
|
|
516
|
-
this.localBridgeExcluded = next;
|
|
517
|
-
}
|
|
518
|
-
} catch (e) { /* ignore */ }
|
|
519
|
-
},
|
|
520
|
-
|
|
521
|
-
isLocalBridgeExcluded(providerName) {
|
|
522
|
-
return this.localBridgeExcluded.indexOf(String(providerName || '').trim()) >= 0;
|
|
523
|
-
},
|
|
524
|
-
|
|
525
|
-
localBridgeCandidateProviders() {
|
|
526
|
-
return (this.providersList || []).filter(p => p && p.name !== 'local' && p.name !== 'codexmate-proxy' && p.codexmate_bridge !== 'local');
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
}
|
|
1
|
+
const PROVIDER_NAME_PATTERN = /^[a-zA-Z0-9._-]+$/;
|
|
2
|
+
const RESERVED_PROXY_PROVIDER_NAME = 'codexmate-proxy';
|
|
3
|
+
const RESERVED_LOCAL_PROVIDER_NAME = 'local';
|
|
4
|
+
|
|
5
|
+
function normalizeText(value) {
|
|
6
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function normalizeProviderUrl(value) {
|
|
10
|
+
return normalizeText(value).replace(/\/+$/g, '');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isValidHttpUrl(value) {
|
|
14
|
+
if (!value) return false;
|
|
15
|
+
try {
|
|
16
|
+
const parsed = new URL(value);
|
|
17
|
+
return parsed.protocol === 'http:' || parsed.protocol === 'https:';
|
|
18
|
+
} catch (_) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isReservedProviderCreationNameInput(name) {
|
|
24
|
+
const normalized = normalizeText(name).toLowerCase();
|
|
25
|
+
return normalized === RESERVED_PROXY_PROVIDER_NAME || normalized === RESERVED_LOCAL_PROVIDER_NAME;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isValidProviderNameInputValue(name) {
|
|
29
|
+
return PROVIDER_NAME_PATTERN.test(normalizeText(name));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isValidProviderUrlInputValue(url) {
|
|
33
|
+
return isValidHttpUrl(normalizeProviderUrl(url));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function findProviderByName(list, name) {
|
|
37
|
+
const target = normalizeText(name);
|
|
38
|
+
if (!target) return null;
|
|
39
|
+
return (Array.isArray(list) ? list : []).find((item) => item && normalizeText(item.name) === target) || null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function normalizeProviderDraftState(target) {
|
|
43
|
+
if (!target || typeof target !== 'object') return;
|
|
44
|
+
if (typeof target.name === 'string') {
|
|
45
|
+
target.name = target.name.trim();
|
|
46
|
+
}
|
|
47
|
+
if (typeof target.url === 'string') {
|
|
48
|
+
target.url = normalizeProviderUrl(target.url);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function maskKeyLocal(key) {
|
|
53
|
+
if (!key) return '';
|
|
54
|
+
if (key.length <= 8) return '****';
|
|
55
|
+
return key.substring(0, 4) + '...' + key.substring(key.length - 4);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getProviderValidationForContext(vm, mode = 'add') {
|
|
59
|
+
const draft = mode === 'edit' ? vm.editingProvider : vm.newProvider;
|
|
60
|
+
const editingName = mode === 'edit' ? normalizeText(draft && draft.name) : '';
|
|
61
|
+
const name = normalizeText(draft && draft.name);
|
|
62
|
+
const url = normalizeProviderUrl(draft && draft.url);
|
|
63
|
+
const errors = {
|
|
64
|
+
name: '',
|
|
65
|
+
url: ''
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
if (mode === 'add') {
|
|
69
|
+
if (!name) {
|
|
70
|
+
errors.name = '名称不能为空';
|
|
71
|
+
} else if (!isValidProviderNameInputValue(name)) {
|
|
72
|
+
errors.name = '名称仅支持字母/数字/._-';
|
|
73
|
+
} else if (isReservedProviderCreationNameInput(name)) {
|
|
74
|
+
errors.name = 'codexmate-proxy 为保留名称,不可手动添加';
|
|
75
|
+
} else if (findProviderByName(vm.providersList, name)) {
|
|
76
|
+
errors.name = '名称已存在';
|
|
77
|
+
}
|
|
78
|
+
} else if (!editingName) {
|
|
79
|
+
errors.name = '提供商名称不能为空';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!url) {
|
|
83
|
+
errors.url = 'URL 必填';
|
|
84
|
+
} else if (!isValidProviderUrlInputValue(url)) {
|
|
85
|
+
errors.url = 'URL 仅支持 http/https';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
mode,
|
|
90
|
+
name,
|
|
91
|
+
url,
|
|
92
|
+
errors,
|
|
93
|
+
ok: !errors.name && !errors.url
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function canSubmitProviderForContext(vm, mode = 'add') {
|
|
98
|
+
if (mode === 'edit' && vm.editingProvider && (vm.editingProvider.readOnly || vm.editingProvider.nonEditable)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return getProviderValidationForContext(vm, mode).ok;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function createProvidersMethods(options = {}) {
|
|
105
|
+
const { api } = options;
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
normalizeProviderDraft(mode = 'add') {
|
|
109
|
+
normalizeProviderDraftState(mode === 'edit' ? this.editingProvider : this.newProvider);
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
isReservedProviderCreationName(name) {
|
|
113
|
+
return isReservedProviderCreationNameInput(name);
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
isValidProviderNameInput(name) {
|
|
117
|
+
return isValidProviderNameInputValue(name);
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
isValidProviderUrlInput(url) {
|
|
121
|
+
return isValidProviderUrlInputValue(url);
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
findProviderByName(name) {
|
|
125
|
+
return findProviderByName(this.providersList, name);
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
getProviderValidation(mode = 'add') {
|
|
129
|
+
return getProviderValidationForContext(this, mode);
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
providerFieldError(mode, fieldName) {
|
|
133
|
+
const validation = getProviderValidationForContext(this, mode);
|
|
134
|
+
return validation && validation.errors && typeof validation.errors[fieldName] === 'string'
|
|
135
|
+
? validation.errors[fieldName]
|
|
136
|
+
: '';
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
canSubmitProvider(mode = 'add') {
|
|
140
|
+
return canSubmitProviderForContext(this, mode);
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
async addProvider() {
|
|
144
|
+
normalizeProviderDraftState(this.newProvider);
|
|
145
|
+
const validation = getProviderValidationForContext(this, 'add');
|
|
146
|
+
if (!validation.ok) {
|
|
147
|
+
return this.showMessage(validation.errors.name || validation.errors.url || '名称和URL必填', 'error');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
const payload = {
|
|
152
|
+
name: validation.name,
|
|
153
|
+
url: validation.url,
|
|
154
|
+
key: this.newProvider.key || ''
|
|
155
|
+
};
|
|
156
|
+
if (this.newProvider && this.newProvider.useTransform) {
|
|
157
|
+
payload.useTransform = true;
|
|
158
|
+
}
|
|
159
|
+
const suggestedModel = typeof this.newProvider._suggestedModel === 'string'
|
|
160
|
+
? this.newProvider._suggestedModel.trim()
|
|
161
|
+
: '';
|
|
162
|
+
const res = await api('add-provider', payload);
|
|
163
|
+
if (res.error) {
|
|
164
|
+
this.showMessage(res.error, 'error');
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 本地更新:构造新 provider 对象并追加到列表
|
|
169
|
+
const newProvider = {
|
|
170
|
+
name: validation.name,
|
|
171
|
+
url: validation.url,
|
|
172
|
+
upstreamUrl: '',
|
|
173
|
+
codexmate_bridge: payload.useTransform ? 'openai' : '',
|
|
174
|
+
key: maskKeyLocal(payload.key),
|
|
175
|
+
hasKey: !!payload.key,
|
|
176
|
+
models: [],
|
|
177
|
+
current: false,
|
|
178
|
+
readOnly: false,
|
|
179
|
+
nonDeletable: false,
|
|
180
|
+
nonEditable: false
|
|
181
|
+
};
|
|
182
|
+
this.providersList = [...this.providersList, newProvider];
|
|
183
|
+
|
|
184
|
+
this.showMessage('操作成功', 'success');
|
|
185
|
+
this.closeAddModal();
|
|
186
|
+
|
|
187
|
+
if (suggestedModel) {
|
|
188
|
+
if (!this.currentModels || typeof this.currentModels !== 'object') this.currentModels = {};
|
|
189
|
+
this.currentModels[validation.name] = suggestedModel;
|
|
190
|
+
}
|
|
191
|
+
} catch (e) {
|
|
192
|
+
this.showMessage('添加失败', 'error');
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
getCurrentCodexAuthProfile() {
|
|
197
|
+
const list = Array.isArray(this.codexAuthProfiles) ? this.codexAuthProfiles : [];
|
|
198
|
+
return list.find((item) => !!(item && item.current)) || null;
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
providerPillState(provider) {
|
|
202
|
+
const configured = !!(provider && provider.hasKey);
|
|
203
|
+
return {
|
|
204
|
+
configured,
|
|
205
|
+
text: configured ? '已配置' : '未配置'
|
|
206
|
+
};
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
providerPillConfigured(provider) {
|
|
210
|
+
return this.providerPillState(provider).configured;
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
providerPillText(provider) {
|
|
214
|
+
return this.providerPillState(provider).text;
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
isReadOnlyProvider(providerOrName) {
|
|
218
|
+
if (!providerOrName) return false;
|
|
219
|
+
if (typeof providerOrName === 'object') {
|
|
220
|
+
return !!providerOrName.readOnly;
|
|
221
|
+
}
|
|
222
|
+
const name = String(providerOrName).trim();
|
|
223
|
+
if (!name) return false;
|
|
224
|
+
const target = (this.providersList || []).find((item) => item && item.name === name);
|
|
225
|
+
return !!(target && target.readOnly);
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
isNonDeletableProvider(providerOrName) {
|
|
229
|
+
if (!providerOrName) return false;
|
|
230
|
+
if (typeof providerOrName === 'object') {
|
|
231
|
+
return !!providerOrName.nonDeletable;
|
|
232
|
+
}
|
|
233
|
+
const name = String(providerOrName).trim();
|
|
234
|
+
if (!name) return false;
|
|
235
|
+
const target = (this.providersList || []).find((item) => item && item.name === name);
|
|
236
|
+
return !!(target && target.nonDeletable);
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
shouldShowProviderDelete(provider) {
|
|
240
|
+
return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
shouldShowProviderEdit(provider) {
|
|
244
|
+
return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
shouldAllowProviderShare(provider) {
|
|
248
|
+
return !this.isReadOnlyProvider(provider);
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
async deleteProvider(name) {
|
|
252
|
+
if (this.isNonDeletableProvider(name)) {
|
|
253
|
+
this.showMessage('该 provider 为保留项,不可删除', 'info');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
const res = await api('delete-provider', { name });
|
|
258
|
+
if (res.error) {
|
|
259
|
+
this.showMessage(res.error, 'error');
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// 本地更新:从列表中移除
|
|
264
|
+
this.providersList = this.providersList.filter(p => p.name !== name);
|
|
265
|
+
|
|
266
|
+
// 清理 currentModels
|
|
267
|
+
if (this.currentModels && this.currentModels[name]) {
|
|
268
|
+
delete this.currentModels[name];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (res.switched && res.provider) {
|
|
272
|
+
this.currentProvider = res.provider;
|
|
273
|
+
if (res.model) this.currentModel = res.model;
|
|
274
|
+
// 更新 current 标记
|
|
275
|
+
this.providersList = this.providersList.map(p => ({
|
|
276
|
+
...p,
|
|
277
|
+
current: p.name === res.provider
|
|
278
|
+
}));
|
|
279
|
+
this.showMessage(`已删除提供商,自动切换到 ${res.provider}${res.model ? ` / ${res.model}` : ''}`, 'success');
|
|
280
|
+
} else {
|
|
281
|
+
this.showMessage('操作成功', 'success');
|
|
282
|
+
}
|
|
283
|
+
} catch (_) {
|
|
284
|
+
this.showMessage('删除失败', 'error');
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
openCloneProviderModal(provider) {
|
|
289
|
+
this.newProvider = {
|
|
290
|
+
name: '',
|
|
291
|
+
url: normalizeProviderUrl(provider.url || ''),
|
|
292
|
+
key: '',
|
|
293
|
+
useTransform: !!(provider.codexmate_bridge || '').trim() || /\/bridge\/openai\//.test(provider.url || '')
|
|
294
|
+
};
|
|
295
|
+
this.showAddModal = true;
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
async openEditModal(provider) {
|
|
299
|
+
const requestId = Symbol('openEditModal');
|
|
300
|
+
this._openEditModalRequestId = requestId;
|
|
301
|
+
if (!this.shouldShowProviderEdit(provider)) {
|
|
302
|
+
this.showMessage('该 provider 为保留项,不可编辑', 'info');
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const isTransformProvider = (() => {
|
|
306
|
+
if (!provider || typeof provider !== 'object') return false;
|
|
307
|
+
const bridge = typeof provider.codexmate_bridge === 'string' ? provider.codexmate_bridge.trim() : '';
|
|
308
|
+
if (bridge === 'openai') return true;
|
|
309
|
+
const url = String(provider.url || '');
|
|
310
|
+
return url.includes('/bridge/openai/');
|
|
311
|
+
})();
|
|
312
|
+
this.editingProvider = {
|
|
313
|
+
name: provider.name,
|
|
314
|
+
url: normalizeProviderUrl(provider.url || ''),
|
|
315
|
+
key: '',
|
|
316
|
+
readOnly: !!provider.readOnly,
|
|
317
|
+
nonEditable: typeof provider.nonEditable === 'boolean'
|
|
318
|
+
? provider.nonEditable
|
|
319
|
+
: this.isNonDeletableProvider(provider),
|
|
320
|
+
useTransform: isTransformProvider
|
|
321
|
+
};
|
|
322
|
+
this.showEditModal = true;
|
|
323
|
+
|
|
324
|
+
if (isTransformProvider) {
|
|
325
|
+
try {
|
|
326
|
+
const res = await api('openai-bridge-get-provider', { name: provider.name });
|
|
327
|
+
if (
|
|
328
|
+
this._openEditModalRequestId === requestId
|
|
329
|
+
&& this.showEditModal
|
|
330
|
+
&& this.editingProvider
|
|
331
|
+
&& this.editingProvider.name === provider.name
|
|
332
|
+
&& res && !res.error
|
|
333
|
+
&& typeof res.baseUrl === 'string'
|
|
334
|
+
&& res.baseUrl.trim()
|
|
335
|
+
) {
|
|
336
|
+
this.editingProvider.url = normalizeProviderUrl(res.baseUrl);
|
|
337
|
+
}
|
|
338
|
+
} catch (_) {
|
|
339
|
+
// ignore
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
|
|
344
|
+
async updateProvider() {
|
|
345
|
+
if (this.editingProvider.readOnly || this.editingProvider.nonEditable) {
|
|
346
|
+
this.showMessage('该 provider 为保留项,不可编辑', 'error');
|
|
347
|
+
this.closeEditModal();
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
normalizeProviderDraftState(this.editingProvider);
|
|
351
|
+
const validation = getProviderValidationForContext(this, 'edit');
|
|
352
|
+
if (!validation.ok) {
|
|
353
|
+
return this.showMessage(validation.errors.name || validation.errors.url || 'URL 必填', 'error');
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const params = { name: validation.name, url: validation.url };
|
|
357
|
+
if (this.editingProvider && this.editingProvider.useTransform) {
|
|
358
|
+
params.useTransform = true;
|
|
359
|
+
}
|
|
360
|
+
if (typeof this.editingProvider.key === 'string' && this.editingProvider.key.trim()) {
|
|
361
|
+
params.key = this.editingProvider.key;
|
|
362
|
+
}
|
|
363
|
+
try {
|
|
364
|
+
const res = await api('update-provider', params);
|
|
365
|
+
if (res.error) {
|
|
366
|
+
this.showMessage(res.error, 'error');
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// 本地更新:更新列表中对应 provider 的 url 和 key
|
|
371
|
+
this.providersList = this.providersList.map(p => {
|
|
372
|
+
if (p.name === validation.name) {
|
|
373
|
+
return {
|
|
374
|
+
...p,
|
|
375
|
+
url: validation.url,
|
|
376
|
+
key: params.key ? maskKeyLocal(params.key) : p.key,
|
|
377
|
+
hasKey: params.key ? true : p.hasKey
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
return p;
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
this.closeEditModal();
|
|
384
|
+
this.showMessage('操作成功', 'success');
|
|
385
|
+
} catch (e) {
|
|
386
|
+
this.showMessage('更新失败', 'error');
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
|
|
390
|
+
closeEditModal() {
|
|
391
|
+
this.showEditModal = false;
|
|
392
|
+
this.editingProvider = { name: '', url: '', key: '', readOnly: false, nonEditable: false, useTransform: false };
|
|
393
|
+
},
|
|
394
|
+
|
|
395
|
+
async resetConfig() {
|
|
396
|
+
if (this.resetConfigLoading) return;
|
|
397
|
+
this.resetConfigLoading = true;
|
|
398
|
+
try {
|
|
399
|
+
const res = await api('reset-config');
|
|
400
|
+
if (res.error) {
|
|
401
|
+
this.showMessage(res.error, 'error');
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const backup = res.backupFile ? `(已备份: ${res.backupFile})` : '';
|
|
405
|
+
this.showMessage(`配置已重装${backup}`, 'success');
|
|
406
|
+
await this.loadAll();
|
|
407
|
+
} catch (e) {
|
|
408
|
+
this.showMessage('重装失败', 'error');
|
|
409
|
+
} finally {
|
|
410
|
+
this.resetConfigLoading = false;
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
|
|
414
|
+
async addModel() {
|
|
415
|
+
if (!this.newModelName || !this.newModelName.trim()) {
|
|
416
|
+
return this.showMessage('请输入模型', 'error');
|
|
417
|
+
}
|
|
418
|
+
try {
|
|
419
|
+
const modelName = this.newModelName.trim();
|
|
420
|
+
const res = await api('add-model', { model: modelName });
|
|
421
|
+
if (res.error) {
|
|
422
|
+
this.showMessage(res.error, 'error');
|
|
423
|
+
} else {
|
|
424
|
+
// 本地更新:在当前 provider 的 models 中追加
|
|
425
|
+
this.providersList = this.providersList.map(p => {
|
|
426
|
+
if (p.name === this.currentProvider) {
|
|
427
|
+
const exists = p.models.some(m => m.id === modelName);
|
|
428
|
+
if (!exists) {
|
|
429
|
+
return {
|
|
430
|
+
...p,
|
|
431
|
+
models: [...p.models, { id: modelName, name: modelName, cost: null, contextWindow: undefined, maxTokens: undefined }]
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return p;
|
|
436
|
+
});
|
|
437
|
+
this.showMessage('操作成功', 'success');
|
|
438
|
+
this.closeModelModal();
|
|
439
|
+
}
|
|
440
|
+
} catch (_) {
|
|
441
|
+
this.showMessage('新增模型失败', 'error');
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
|
|
445
|
+
async removeModel(model) {
|
|
446
|
+
try {
|
|
447
|
+
const res = await api('delete-model', { model });
|
|
448
|
+
if (res.error) {
|
|
449
|
+
this.showMessage(res.error, 'error');
|
|
450
|
+
} else {
|
|
451
|
+
// 本地更新:从当前 provider 的 models 中移除
|
|
452
|
+
this.providersList = this.providersList.map(p => {
|
|
453
|
+
if (p.name === this.currentProvider) {
|
|
454
|
+
return {
|
|
455
|
+
...p,
|
|
456
|
+
models: p.models.filter(m => m.id !== model)
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
return p;
|
|
460
|
+
});
|
|
461
|
+
this.showMessage('操作成功', 'success');
|
|
462
|
+
}
|
|
463
|
+
} catch (_) {
|
|
464
|
+
this.showMessage('删除模型失败', 'error');
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
|
|
468
|
+
closeAddModal() {
|
|
469
|
+
this.showAddModal = false;
|
|
470
|
+
this.newProvider = { name: '', url: '', key: '', useTransform: false, _suggestedModel: '' };
|
|
471
|
+
},
|
|
472
|
+
|
|
473
|
+
closeModelModal() {
|
|
474
|
+
this.showModelModal = false;
|
|
475
|
+
this.newModelName = '';
|
|
476
|
+
},
|
|
477
|
+
|
|
478
|
+
formatKey(key) {
|
|
479
|
+
if (!key) return '(未设置)';
|
|
480
|
+
if (key.length > 10) {
|
|
481
|
+
return key.substring(0, 3) + '****' + key.substring(key.length - 3);
|
|
482
|
+
}
|
|
483
|
+
return '****';
|
|
484
|
+
},
|
|
485
|
+
|
|
486
|
+
displayApiKey(configName) {
|
|
487
|
+
const config = this.claudeConfigs && this.claudeConfigs[configName]
|
|
488
|
+
? this.claudeConfigs[configName]
|
|
489
|
+
: null;
|
|
490
|
+
const key = config ? config.apiKey : '';
|
|
491
|
+
return this.formatKey(key);
|
|
492
|
+
},
|
|
493
|
+
|
|
494
|
+
async loadLocalBridgeExcluded() {
|
|
495
|
+
try {
|
|
496
|
+
const res = await api('local-bridge-get-excluded');
|
|
497
|
+
if (res && Array.isArray(res.excludedProviders)) {
|
|
498
|
+
this.localBridgeExcluded = res.excludedProviders;
|
|
499
|
+
}
|
|
500
|
+
} catch (e) { /* ignore */ }
|
|
501
|
+
},
|
|
502
|
+
|
|
503
|
+
async toggleLocalBridgeExcluded(providerName) {
|
|
504
|
+
const name = String(providerName || '').trim();
|
|
505
|
+
if (!name) return;
|
|
506
|
+
const idx = this.localBridgeExcluded.indexOf(name);
|
|
507
|
+
const next = [...this.localBridgeExcluded];
|
|
508
|
+
if (idx >= 0) {
|
|
509
|
+
next.splice(idx, 1);
|
|
510
|
+
} else {
|
|
511
|
+
next.push(name);
|
|
512
|
+
}
|
|
513
|
+
try {
|
|
514
|
+
const res = await api('local-bridge-set-excluded', { names: next });
|
|
515
|
+
if (res && !res.error) {
|
|
516
|
+
this.localBridgeExcluded = next;
|
|
517
|
+
}
|
|
518
|
+
} catch (e) { /* ignore */ }
|
|
519
|
+
},
|
|
520
|
+
|
|
521
|
+
isLocalBridgeExcluded(providerName) {
|
|
522
|
+
return this.localBridgeExcluded.indexOf(String(providerName || '').trim()) >= 0;
|
|
523
|
+
},
|
|
524
|
+
|
|
525
|
+
localBridgeCandidateProviders() {
|
|
526
|
+
return (this.providersList || []).filter(p => p && p.name !== 'local' && p.name !== 'codexmate-proxy' && p.codexmate_bridge !== 'local');
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
}
|