codexmate 0.0.41 → 0.0.43
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 +168 -168
- package/README.zh.md +168 -168
- package/cli/agents-files.js +230 -230
- package/cli/analytics-export-args.js +68 -68
- package/cli/archive-helpers.js +453 -453
- package/cli/auth-profiles.js +375 -375
- package/cli/builtin-proxy.js +2144 -2144
- package/cli/claude-proxy.js +1022 -1022
- package/cli/config-bootstrap.js +407 -407
- 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 +556 -556
- package/cli/openai-bridge.js +1984 -1984
- package/cli/openclaw-config.js +629 -629
- package/cli/session-convert-args.js +69 -69
- package/cli/session-convert-io.js +82 -82
- package/cli/session-convert.js +150 -150
- package/cli/session-usage.concurrent.js +28 -28
- package/cli/session-usage.js +304 -304
- package/cli/session-usage.models.js +176 -176
- package/cli/skills.js +1141 -1141
- package/cli/update.js +171 -171
- package/cli/zip-commands.js +510 -510
- package/cli.js +16495 -16458
- 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 +427 -427
- package/lib/cli-utils.js +155 -155
- package/lib/cli-webhook.js +154 -154
- 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/win-tray.js +119 -119
- package/lib/workflow-engine.js +340 -340
- package/package.json +77 -77
- 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 +311 -311
- package/plugins/prompt-templates/index.mjs +8 -8
- package/plugins/prompt-templates/manifest.mjs +18 -18
- 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 +705 -695
- package/web-ui/index.html +37 -37
- package/web-ui/logic.agents-diff.mjs +386 -386
- package/web-ui/logic.claude.mjs +172 -172
- 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 +782 -782
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +252 -252
- package/web-ui/modules/app.computed.index.mjs +17 -17
- package/web-ui/modules/app.computed.main-tabs.mjs +214 -214
- package/web-ui/modules/app.computed.session.mjs +876 -876
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +651 -651
- package/web-ui/modules/app.methods.claude-config.mjs +412 -412
- package/web-ui/modules/app.methods.codex-config.mjs +869 -869
- package/web-ui/modules/app.methods.index.mjs +96 -96
- package/web-ui/modules/app.methods.install.mjs +205 -205
- package/web-ui/modules/app.methods.navigation.mjs +804 -804
- package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
- package/web-ui/modules/app.methods.openclaw-editing.mjs +420 -420
- package/web-ui/modules/app.methods.openclaw-persist.mjs +375 -375
- package/web-ui/modules/app.methods.providers.mjs +602 -601
- package/web-ui/modules/app.methods.runtime.mjs +426 -420
- package/web-ui/modules/app.methods.session-actions.mjs +617 -591
- package/web-ui/modules/app.methods.session-browser.mjs +1018 -1018
- package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
- package/web-ui/modules/app.methods.session-trash.mjs +468 -468
- package/web-ui/modules/app.methods.startup-claude.mjs +557 -554
- package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
- package/web-ui/modules/app.methods.tool-config-permissions.mjs +90 -87
- package/web-ui/modules/app.methods.webhook.mjs +87 -87
- 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/locales/en.mjs +1187 -1140
- package/web-ui/modules/i18n/locales/ja.mjs +1178 -1130
- package/web-ui/modules/i18n/locales/vi.mjs +294 -239
- package/web-ui/modules/i18n/locales/zh.mjs +1190 -1143
- package/web-ui/modules/i18n.dict.mjs +14 -14
- package/web-ui/modules/i18n.mjs +111 -111
- 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 +138 -138
- package/web-ui/modules/skills.computed.mjs +107 -107
- package/web-ui/modules/skills.methods.mjs +513 -513
- package/web-ui/partials/index/layout-footer.html +13 -13
- package/web-ui/partials/index/layout-header.html +478 -478
- package/web-ui/partials/index/modal-config-template-agents.html +185 -185
- 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 +344 -344
- package/web-ui/partials/index/modal-skills.html +200 -200
- package/web-ui/partials/index/modal-webhook.html +42 -42
- package/web-ui/partials/index/modals-basic.html +263 -263
- package/web-ui/partials/index/panel-config-claude.html +187 -187
- package/web-ui/partials/index/panel-config-codex.html +205 -205
- package/web-ui/partials/index/panel-config-openclaw.html +89 -89
- package/web-ui/partials/index/panel-dashboard.html +171 -171
- package/web-ui/partials/index/panel-docs.html +114 -114
- package/web-ui/partials/index/panel-market.html +104 -104
- 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 +325 -319
- package/web-ui/partials/index/panel-settings.html +181 -181
- package/web-ui/partials/index/panel-trash.html +82 -82
- package/web-ui/partials/index/panel-usage.html +181 -181
- package/web-ui/res/json5.min.js +1 -1
- package/web-ui/res/vue.global.prod.js +13 -13
- package/web-ui/res/vue.runtime.global.prod.js +7 -7
- package/web-ui/res/web-ui-render.precompiled.js +7671 -7666
- package/web-ui/session-helpers.mjs +602 -602
- package/web-ui/source-bundle.cjs +305 -305
- package/web-ui/styles/base-theme.css +291 -291
- package/web-ui/styles/bridge-pool.css +266 -266
- package/web-ui/styles/controls-forms.css +532 -532
- package/web-ui/styles/dashboard.css +438 -438
- package/web-ui/styles/docs-panel.css +245 -245
- 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 +711 -711
- package/web-ui/styles/modals-core.css +499 -499
- package/web-ui/styles/navigation-panels.css +399 -399
- package/web-ui/styles/openclaw-structured.css +616 -616
- package/web-ui/styles/plugins-panel.css +564 -564
- package/web-ui/styles/responsive.css +501 -501
- package/web-ui/styles/sessions-list.css +683 -683
- package/web-ui/styles/sessions-preview.css +407 -407
- package/web-ui/styles/sessions-toolbar-trash.css +518 -518
- package/web-ui/styles/sessions-usage.css +849 -849
- package/web-ui/styles/settings-panel.css +419 -419
- package/web-ui/styles/skills-list.css +305 -305
- package/web-ui/styles/skills-market.css +723 -723
- package/web-ui/styles/task-orchestration.css +822 -822
- package/web-ui/styles/titles-cards.css +492 -486
- package/web-ui/styles/trash-panel.css +90 -90
- package/web-ui/styles/webhook.css +115 -115
- package/web-ui/styles.css +24 -24
- package/web-ui.html +17 -17
|
@@ -1,601 +1,602 @@
|
|
|
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
|
-
if (typeof target.model === 'string') {
|
|
51
|
-
target.model = target.model.trim();
|
|
52
|
-
}
|
|
53
|
-
if (typeof target.key === 'string') {
|
|
54
|
-
target.key = target.key.trim();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function maskKeyLocal(key) {
|
|
59
|
-
if (!key) return '';
|
|
60
|
-
if (key.length <= 8) return '****';
|
|
61
|
-
return key.substring(0, 4) + '...' + key.substring(key.length - 4);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function maskKeyForEdit(key) {
|
|
65
|
-
if (!key) return '';
|
|
66
|
-
if (key.length <= 12) return key.substring(0, 4) + '...' + key.substring(key.length - 4);
|
|
67
|
-
return key.substring(0, 8) + '...' + key.substring(key.length - 4);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function getProviderValidationForContext(vm, mode = 'add') {
|
|
71
|
-
const draft = mode === 'edit' ? vm.editingProvider : vm.newProvider;
|
|
72
|
-
const editingName = mode === 'edit' ? normalizeText(draft && draft.name) : '';
|
|
73
|
-
const name = normalizeText(draft && draft.name);
|
|
74
|
-
const url = normalizeProviderUrl(draft && draft.url);
|
|
75
|
-
const model = normalizeText(draft && draft.model);
|
|
76
|
-
const key = normalizeText(draft && draft.key);
|
|
77
|
-
const errors = {
|
|
78
|
-
name: '',
|
|
79
|
-
url: '',
|
|
80
|
-
key: '',
|
|
81
|
-
model: ''
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
if (mode === 'add') {
|
|
85
|
-
if (!name) {
|
|
86
|
-
errors.name = '名称不能为空';
|
|
87
|
-
} else if (!isValidProviderNameInputValue(name)) {
|
|
88
|
-
errors.name = '名称仅支持字母/数字/._-';
|
|
89
|
-
} else if (isReservedProviderCreationNameInput(name)) {
|
|
90
|
-
errors.name = 'codexmate-proxy 为保留名称,不可手动添加';
|
|
91
|
-
} else if (findProviderByName(vm.providersList, name)) {
|
|
92
|
-
errors.name = '名称已存在';
|
|
93
|
-
}
|
|
94
|
-
} else if (!editingName) {
|
|
95
|
-
errors.name = '提供商名称不能为空';
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!url) {
|
|
99
|
-
errors.url = 'URL 必填';
|
|
100
|
-
} else if (!isValidProviderUrlInputValue(url)) {
|
|
101
|
-
errors.url = 'URL 仅支持 http/https';
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (mode === 'add' && !key) {
|
|
105
|
-
errors.key = 'API Key 必填';
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (mode === 'add' && !model) {
|
|
109
|
-
errors.model = '模型名称必填';
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
mode,
|
|
114
|
-
name,
|
|
115
|
-
url,
|
|
116
|
-
key,
|
|
117
|
-
model,
|
|
118
|
-
errors,
|
|
119
|
-
ok: !errors.name && !errors.url && !errors.key && !errors.model
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function canSubmitProviderForContext(vm, mode = 'add') {
|
|
124
|
-
if (mode === 'edit' && vm.editingProvider && (vm.editingProvider.readOnly || vm.editingProvider.nonEditable)) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return getProviderValidationForContext(vm, mode).ok;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function createProvidersMethods(options = {}) {
|
|
131
|
-
const { api } = options;
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
normalizeProviderDraft(mode = 'add') {
|
|
135
|
-
normalizeProviderDraftState(mode === 'edit' ? this.editingProvider : this.newProvider);
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
isReservedProviderCreationName(name) {
|
|
139
|
-
return isReservedProviderCreationNameInput(name);
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
isValidProviderNameInput(name) {
|
|
143
|
-
return isValidProviderNameInputValue(name);
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
isValidProviderUrlInput(url) {
|
|
147
|
-
return isValidProviderUrlInputValue(url);
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
findProviderByName(name) {
|
|
151
|
-
return findProviderByName(this.providersList, name);
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
getProviderValidation(mode = 'add') {
|
|
155
|
-
return getProviderValidationForContext(this, mode);
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
providerFieldError(mode, fieldName) {
|
|
159
|
-
const validation = getProviderValidationForContext(this, mode);
|
|
160
|
-
return validation && validation.errors && typeof validation.errors[fieldName] === 'string'
|
|
161
|
-
? validation.errors[fieldName]
|
|
162
|
-
: '';
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
canSubmitProvider(mode = 'add') {
|
|
166
|
-
return canSubmitProviderForContext(this, mode);
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
async addProvider() {
|
|
170
|
-
normalizeProviderDraftState(this.newProvider);
|
|
171
|
-
const validation = getProviderValidationForContext(this, 'add');
|
|
172
|
-
if (!validation.ok) {
|
|
173
|
-
return this.showMessage(validation.errors.name || validation.errors.url || validation.errors.key || validation.errors.model || '
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
const payload = {
|
|
178
|
-
name: validation.name,
|
|
179
|
-
url: validation.url,
|
|
180
|
-
key: validation.key,
|
|
181
|
-
model: validation.model
|
|
182
|
-
};
|
|
183
|
-
if (this.newProvider && this.newProvider.useTransform) {
|
|
184
|
-
payload.useTransform = true;
|
|
185
|
-
}
|
|
186
|
-
const suggestedModel = validation.model;
|
|
187
|
-
const res = await api('add-provider', payload);
|
|
188
|
-
if (res.error) {
|
|
189
|
-
this.showMessage(res.error, 'error');
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// 本地更新:构造新 provider 对象并追加到列表
|
|
194
|
-
const newProvider = {
|
|
195
|
-
name: validation.name,
|
|
196
|
-
url: validation.url,
|
|
197
|
-
upstreamUrl: '',
|
|
198
|
-
codexmate_bridge: payload.useTransform ? 'openai' : '',
|
|
199
|
-
key: maskKeyLocal(payload.key),
|
|
200
|
-
hasKey: !!payload.key,
|
|
201
|
-
models: suggestedModel ? [{ id: suggestedModel, name: suggestedModel, cost: null, contextWindow: undefined, maxTokens: undefined }] : [],
|
|
202
|
-
current: false,
|
|
203
|
-
readOnly: false,
|
|
204
|
-
nonDeletable: false,
|
|
205
|
-
nonEditable: false
|
|
206
|
-
};
|
|
207
|
-
this.providersList = [...this.providersList, newProvider];
|
|
208
|
-
|
|
209
|
-
this.showMessage('
|
|
210
|
-
this.closeAddModal();
|
|
211
|
-
|
|
212
|
-
if (suggestedModel) {
|
|
213
|
-
if (!this.currentModels || typeof this.currentModels !== 'object') this.currentModels = {};
|
|
214
|
-
this.currentModels[validation.name] = suggestedModel;
|
|
215
|
-
}
|
|
216
|
-
} catch (e) {
|
|
217
|
-
this.showMessage('
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
getCurrentCodexAuthProfile() {
|
|
222
|
-
const list = Array.isArray(this.codexAuthProfiles) ? this.codexAuthProfiles : [];
|
|
223
|
-
return list.find((item) => !!(item && item.current)) || null;
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
providerPillState(provider) {
|
|
227
|
-
const configured = !!(provider && provider.hasKey);
|
|
228
|
-
return {
|
|
229
|
-
configured,
|
|
230
|
-
text: configured ? this.t('common.configured') : this.t('common.notConfigured')
|
|
231
|
-
};
|
|
232
|
-
},
|
|
233
|
-
|
|
234
|
-
providerPillConfigured(provider) {
|
|
235
|
-
return this.providerPillState(provider).configured;
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
providerPillText(provider) {
|
|
239
|
-
return this.providerPillState(provider).text;
|
|
240
|
-
},
|
|
241
|
-
|
|
242
|
-
isReadOnlyProvider(providerOrName) {
|
|
243
|
-
if (!providerOrName) return false;
|
|
244
|
-
if (typeof providerOrName === 'object') {
|
|
245
|
-
return !!providerOrName.readOnly;
|
|
246
|
-
}
|
|
247
|
-
const name = String(providerOrName).trim();
|
|
248
|
-
if (!name) return false;
|
|
249
|
-
const target = (this.providersList || []).find((item) => item && item.name === name);
|
|
250
|
-
return !!(target && target.readOnly);
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
isNonDeletableProvider(providerOrName) {
|
|
254
|
-
if (!providerOrName) return false;
|
|
255
|
-
if (typeof providerOrName === 'object') {
|
|
256
|
-
return !!providerOrName.nonDeletable;
|
|
257
|
-
}
|
|
258
|
-
const name = String(providerOrName).trim();
|
|
259
|
-
if (!name) return false;
|
|
260
|
-
const target = (this.providersList || []).find((item) => item && item.name === name);
|
|
261
|
-
return !!(target && target.nonDeletable);
|
|
262
|
-
},
|
|
263
|
-
|
|
264
|
-
shouldShowProviderDelete(provider) {
|
|
265
|
-
return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
shouldShowProviderEdit(provider) {
|
|
269
|
-
return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
|
|
270
|
-
},
|
|
271
|
-
|
|
272
|
-
shouldAllowProviderShare(provider) {
|
|
273
|
-
return !this.isReadOnlyProvider(provider);
|
|
274
|
-
},
|
|
275
|
-
|
|
276
|
-
async deleteProvider(name) {
|
|
277
|
-
if (this.isNonDeletableProvider(name)) {
|
|
278
|
-
this.showMessage('
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
try {
|
|
282
|
-
const res = await api('delete-provider', { name });
|
|
283
|
-
if (res.error) {
|
|
284
|
-
this.showMessage(res.error, 'error');
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// 本地更新:从列表中移除
|
|
289
|
-
this.providersList = this.providersList.filter(p => p.name !== name);
|
|
290
|
-
|
|
291
|
-
// 清理 currentModels
|
|
292
|
-
if (this.currentModels && this.currentModels[name]) {
|
|
293
|
-
delete this.currentModels[name];
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (res.switched && res.provider) {
|
|
297
|
-
this.currentProvider = res.provider;
|
|
298
|
-
if (res.model) this.currentModel = res.model;
|
|
299
|
-
// 更新 current 标记
|
|
300
|
-
this.providersList = this.providersList.map(p => ({
|
|
301
|
-
...p,
|
|
302
|
-
current: p.name === res.provider
|
|
303
|
-
}));
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
this.
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
this.
|
|
355
|
-
this.
|
|
356
|
-
this.
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
&& this.
|
|
365
|
-
&& this.editingProvider
|
|
366
|
-
&&
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
this.
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
&& this.
|
|
386
|
-
&& this.editingProvider
|
|
387
|
-
&&
|
|
388
|
-
&&
|
|
389
|
-
&& res.baseUrl
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
this.
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
this.
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
this.
|
|
453
|
-
this.
|
|
454
|
-
this.
|
|
455
|
-
this.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
this.resetConfigLoading
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
this.
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
this.
|
|
538
|
-
this.
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
this.
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
if (key
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}
|
|
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
|
+
if (typeof target.model === 'string') {
|
|
51
|
+
target.model = target.model.trim();
|
|
52
|
+
}
|
|
53
|
+
if (typeof target.key === 'string') {
|
|
54
|
+
target.key = target.key.trim();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function maskKeyLocal(key) {
|
|
59
|
+
if (!key) return '';
|
|
60
|
+
if (key.length <= 8) return '****';
|
|
61
|
+
return key.substring(0, 4) + '...' + key.substring(key.length - 4);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function maskKeyForEdit(key) {
|
|
65
|
+
if (!key) return '';
|
|
66
|
+
if (key.length <= 12) return key.substring(0, 4) + '...' + key.substring(key.length - 4);
|
|
67
|
+
return key.substring(0, 8) + '...' + key.substring(key.length - 4);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getProviderValidationForContext(vm, mode = 'add') {
|
|
71
|
+
const draft = mode === 'edit' ? vm.editingProvider : vm.newProvider;
|
|
72
|
+
const editingName = mode === 'edit' ? normalizeText(draft && draft.name) : '';
|
|
73
|
+
const name = normalizeText(draft && draft.name);
|
|
74
|
+
const url = normalizeProviderUrl(draft && draft.url);
|
|
75
|
+
const model = normalizeText(draft && draft.model);
|
|
76
|
+
const key = normalizeText(draft && draft.key);
|
|
77
|
+
const errors = {
|
|
78
|
+
name: '',
|
|
79
|
+
url: '',
|
|
80
|
+
key: '',
|
|
81
|
+
model: ''
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
if (mode === 'add') {
|
|
85
|
+
if (!name) {
|
|
86
|
+
errors.name = '名称不能为空';
|
|
87
|
+
} else if (!isValidProviderNameInputValue(name)) {
|
|
88
|
+
errors.name = '名称仅支持字母/数字/._-';
|
|
89
|
+
} else if (isReservedProviderCreationNameInput(name)) {
|
|
90
|
+
errors.name = 'codexmate-proxy 为保留名称,不可手动添加';
|
|
91
|
+
} else if (findProviderByName(vm.providersList, name)) {
|
|
92
|
+
errors.name = '名称已存在';
|
|
93
|
+
}
|
|
94
|
+
} else if (!editingName) {
|
|
95
|
+
errors.name = '提供商名称不能为空';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!url) {
|
|
99
|
+
errors.url = 'URL 必填';
|
|
100
|
+
} else if (!isValidProviderUrlInputValue(url)) {
|
|
101
|
+
errors.url = 'URL 仅支持 http/https';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (mode === 'add' && !key) {
|
|
105
|
+
errors.key = 'API Key 必填';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (mode === 'add' && !model) {
|
|
109
|
+
errors.model = '模型名称必填';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
mode,
|
|
114
|
+
name,
|
|
115
|
+
url,
|
|
116
|
+
key,
|
|
117
|
+
model,
|
|
118
|
+
errors,
|
|
119
|
+
ok: !errors.name && !errors.url && !errors.key && !errors.model
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function canSubmitProviderForContext(vm, mode = 'add') {
|
|
124
|
+
if (mode === 'edit' && vm.editingProvider && (vm.editingProvider.readOnly || vm.editingProvider.nonEditable)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return getProviderValidationForContext(vm, mode).ok;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function createProvidersMethods(options = {}) {
|
|
131
|
+
const { api } = options;
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
normalizeProviderDraft(mode = 'add') {
|
|
135
|
+
normalizeProviderDraftState(mode === 'edit' ? this.editingProvider : this.newProvider);
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
isReservedProviderCreationName(name) {
|
|
139
|
+
return isReservedProviderCreationNameInput(name);
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
isValidProviderNameInput(name) {
|
|
143
|
+
return isValidProviderNameInputValue(name);
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
isValidProviderUrlInput(url) {
|
|
147
|
+
return isValidProviderUrlInputValue(url);
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
findProviderByName(name) {
|
|
151
|
+
return findProviderByName(this.providersList, name);
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
getProviderValidation(mode = 'add') {
|
|
155
|
+
return getProviderValidationForContext(this, mode);
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
providerFieldError(mode, fieldName) {
|
|
159
|
+
const validation = getProviderValidationForContext(this, mode);
|
|
160
|
+
return validation && validation.errors && typeof validation.errors[fieldName] === 'string'
|
|
161
|
+
? validation.errors[fieldName]
|
|
162
|
+
: '';
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
canSubmitProvider(mode = 'add') {
|
|
166
|
+
return canSubmitProviderForContext(this, mode);
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
async addProvider() {
|
|
170
|
+
normalizeProviderDraftState(this.newProvider);
|
|
171
|
+
const validation = getProviderValidationForContext(this, 'add');
|
|
172
|
+
if (!validation.ok) {
|
|
173
|
+
return this.showMessage(validation.errors.name || validation.errors.url || validation.errors.key || validation.errors.model || this.t('toast.provider.fieldsRequired'), 'error');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
const payload = {
|
|
178
|
+
name: validation.name,
|
|
179
|
+
url: validation.url,
|
|
180
|
+
key: validation.key,
|
|
181
|
+
model: validation.model
|
|
182
|
+
};
|
|
183
|
+
if (this.newProvider && this.newProvider.useTransform) {
|
|
184
|
+
payload.useTransform = true;
|
|
185
|
+
}
|
|
186
|
+
const suggestedModel = validation.model;
|
|
187
|
+
const res = await api('add-provider', payload);
|
|
188
|
+
if (res.error) {
|
|
189
|
+
this.showMessage(res.error, 'error');
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 本地更新:构造新 provider 对象并追加到列表
|
|
194
|
+
const newProvider = {
|
|
195
|
+
name: validation.name,
|
|
196
|
+
url: validation.url,
|
|
197
|
+
upstreamUrl: '',
|
|
198
|
+
codexmate_bridge: payload.useTransform ? 'openai' : '',
|
|
199
|
+
key: maskKeyLocal(payload.key),
|
|
200
|
+
hasKey: !!payload.key,
|
|
201
|
+
models: suggestedModel ? [{ id: suggestedModel, name: suggestedModel, cost: null, contextWindow: undefined, maxTokens: undefined }] : [],
|
|
202
|
+
current: false,
|
|
203
|
+
readOnly: false,
|
|
204
|
+
nonDeletable: false,
|
|
205
|
+
nonEditable: false
|
|
206
|
+
};
|
|
207
|
+
this.providersList = [...this.providersList, newProvider];
|
|
208
|
+
|
|
209
|
+
this.showMessage(this.t('toast.operation.success'), 'success');
|
|
210
|
+
this.closeAddModal();
|
|
211
|
+
|
|
212
|
+
if (suggestedModel) {
|
|
213
|
+
if (!this.currentModels || typeof this.currentModels !== 'object') this.currentModels = {};
|
|
214
|
+
this.currentModels[validation.name] = suggestedModel;
|
|
215
|
+
}
|
|
216
|
+
} catch (e) {
|
|
217
|
+
this.showMessage(this.t('toast.provider.addFail'), 'error');
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
getCurrentCodexAuthProfile() {
|
|
222
|
+
const list = Array.isArray(this.codexAuthProfiles) ? this.codexAuthProfiles : [];
|
|
223
|
+
return list.find((item) => !!(item && item.current)) || null;
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
providerPillState(provider) {
|
|
227
|
+
const configured = !!(provider && provider.hasKey);
|
|
228
|
+
return {
|
|
229
|
+
configured,
|
|
230
|
+
text: configured ? this.t('common.configured') : this.t('common.notConfigured')
|
|
231
|
+
};
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
providerPillConfigured(provider) {
|
|
235
|
+
return this.providerPillState(provider).configured;
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
providerPillText(provider) {
|
|
239
|
+
return this.providerPillState(provider).text;
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
isReadOnlyProvider(providerOrName) {
|
|
243
|
+
if (!providerOrName) return false;
|
|
244
|
+
if (typeof providerOrName === 'object') {
|
|
245
|
+
return !!providerOrName.readOnly;
|
|
246
|
+
}
|
|
247
|
+
const name = String(providerOrName).trim();
|
|
248
|
+
if (!name) return false;
|
|
249
|
+
const target = (this.providersList || []).find((item) => item && item.name === name);
|
|
250
|
+
return !!(target && target.readOnly);
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
isNonDeletableProvider(providerOrName) {
|
|
254
|
+
if (!providerOrName) return false;
|
|
255
|
+
if (typeof providerOrName === 'object') {
|
|
256
|
+
return !!providerOrName.nonDeletable;
|
|
257
|
+
}
|
|
258
|
+
const name = String(providerOrName).trim();
|
|
259
|
+
if (!name) return false;
|
|
260
|
+
const target = (this.providersList || []).find((item) => item && item.name === name);
|
|
261
|
+
return !!(target && target.nonDeletable);
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
shouldShowProviderDelete(provider) {
|
|
265
|
+
return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
shouldShowProviderEdit(provider) {
|
|
269
|
+
return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
shouldAllowProviderShare(provider) {
|
|
273
|
+
return !this.isReadOnlyProvider(provider);
|
|
274
|
+
},
|
|
275
|
+
|
|
276
|
+
async deleteProvider(name) {
|
|
277
|
+
if (this.isNonDeletableProvider(name)) {
|
|
278
|
+
this.showMessage(this.t('toast.provider.notDeletable'), 'info');
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
const res = await api('delete-provider', { name });
|
|
283
|
+
if (res.error) {
|
|
284
|
+
this.showMessage(res.error, 'error');
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// 本地更新:从列表中移除
|
|
289
|
+
this.providersList = this.providersList.filter(p => p.name !== name);
|
|
290
|
+
|
|
291
|
+
// 清理 currentModels
|
|
292
|
+
if (this.currentModels && this.currentModels[name]) {
|
|
293
|
+
delete this.currentModels[name];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (res.switched && res.provider) {
|
|
297
|
+
this.currentProvider = res.provider;
|
|
298
|
+
if (res.model) this.currentModel = res.model;
|
|
299
|
+
// 更新 current 标记
|
|
300
|
+
this.providersList = this.providersList.map(p => ({
|
|
301
|
+
...p,
|
|
302
|
+
current: p.name === res.provider
|
|
303
|
+
}));
|
|
304
|
+
const modelSuffix = res.model ? ` / ${res.model}` : '';
|
|
305
|
+
this.showMessage(this.t('toast.provider.deletedAndSwitched', { provider: res.provider, model: modelSuffix }), 'success');
|
|
306
|
+
} else {
|
|
307
|
+
this.showMessage(this.t('toast.operation.success'), 'success');
|
|
308
|
+
}
|
|
309
|
+
} catch (_) {
|
|
310
|
+
this.showMessage(this.t('toast.delete.fail'), 'error');
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
openCloneProviderModal(provider) {
|
|
315
|
+
const isTransform = !!(provider.codexmate_bridge || '').trim() || /\/bridge\/openai\//.test(provider.url || '');
|
|
316
|
+
const cloneUrl = isTransform && provider.upstreamUrl
|
|
317
|
+
? normalizeProviderUrl(provider.upstreamUrl)
|
|
318
|
+
: normalizeProviderUrl(provider.url || '');
|
|
319
|
+
this.newProvider = {
|
|
320
|
+
name: '',
|
|
321
|
+
url: cloneUrl,
|
|
322
|
+
key: '',
|
|
323
|
+
model: '',
|
|
324
|
+
useTransform: isTransform
|
|
325
|
+
};
|
|
326
|
+
this.showAddProviderKey = false;
|
|
327
|
+
this.showAddModal = true;
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
async openEditModal(provider) {
|
|
331
|
+
const requestId = Symbol('openEditModal');
|
|
332
|
+
this._openEditModalRequestId = requestId;
|
|
333
|
+
if (!this.shouldShowProviderEdit(provider)) {
|
|
334
|
+
this.showMessage(this.t('toast.provider.notEditable'), 'info');
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const isTransformProvider = (() => {
|
|
338
|
+
if (!provider || typeof provider !== 'object') return false;
|
|
339
|
+
const bridge = typeof provider.codexmate_bridge === 'string' ? provider.codexmate_bridge.trim() : '';
|
|
340
|
+
if (bridge === 'openai') return true;
|
|
341
|
+
const url = String(provider.url || '');
|
|
342
|
+
return url.includes('/bridge/openai/');
|
|
343
|
+
})();
|
|
344
|
+
this.editingProvider = {
|
|
345
|
+
name: provider.name,
|
|
346
|
+
url: normalizeProviderUrl(provider.url || ''),
|
|
347
|
+
key: maskKeyForEdit(provider.key || ''),
|
|
348
|
+
readOnly: !!provider.readOnly,
|
|
349
|
+
nonEditable: typeof provider.nonEditable === 'boolean'
|
|
350
|
+
? provider.nonEditable
|
|
351
|
+
: this.isNonDeletableProvider(provider),
|
|
352
|
+
useTransform: isTransformProvider
|
|
353
|
+
};
|
|
354
|
+
this._editProviderOriginalKey = '';
|
|
355
|
+
this._editProviderRealKeyLoaded = false;
|
|
356
|
+
this.showEditProviderKey = false;
|
|
357
|
+
this.showEditModal = true;
|
|
358
|
+
|
|
359
|
+
// 后台加载真实密钥
|
|
360
|
+
try {
|
|
361
|
+
const res = await api('get-provider-key', { name: provider.name });
|
|
362
|
+
if (
|
|
363
|
+
this._openEditModalRequestId === requestId
|
|
364
|
+
&& this.showEditModal
|
|
365
|
+
&& this.editingProvider
|
|
366
|
+
&& this.editingProvider.name === provider.name
|
|
367
|
+
&& res && !res.error
|
|
368
|
+
) {
|
|
369
|
+
this._editProviderOriginalKey = typeof res.key === 'string' ? res.key : '';
|
|
370
|
+
this._editProviderRealKeyLoaded = true;
|
|
371
|
+
// 如果用户未修改输入框,替换为真实密钥
|
|
372
|
+
if (this.editingProvider.key === maskKeyForEdit(provider.key || '')) {
|
|
373
|
+
this.editingProvider.key = this._editProviderOriginalKey;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
} catch (_) {
|
|
377
|
+
// ignore
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (isTransformProvider) {
|
|
381
|
+
try {
|
|
382
|
+
const res = await api('openai-bridge-get-provider', { name: provider.name });
|
|
383
|
+
if (
|
|
384
|
+
this._openEditModalRequestId === requestId
|
|
385
|
+
&& this.showEditModal
|
|
386
|
+
&& this.editingProvider
|
|
387
|
+
&& this.editingProvider.name === provider.name
|
|
388
|
+
&& res && !res.error
|
|
389
|
+
&& typeof res.baseUrl === 'string'
|
|
390
|
+
&& res.baseUrl.trim()
|
|
391
|
+
) {
|
|
392
|
+
this.editingProvider.url = normalizeProviderUrl(res.baseUrl);
|
|
393
|
+
}
|
|
394
|
+
} catch (_) {
|
|
395
|
+
// ignore
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
|
|
400
|
+
async updateProvider() {
|
|
401
|
+
if (this.editingProvider.readOnly || this.editingProvider.nonEditable) {
|
|
402
|
+
this.showMessage(this.t('toast.provider.notEditable'), 'error');
|
|
403
|
+
this.closeEditModal();
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
normalizeProviderDraftState(this.editingProvider);
|
|
407
|
+
const validation = getProviderValidationForContext(this, 'edit');
|
|
408
|
+
if (!validation.ok) {
|
|
409
|
+
return this.showMessage(validation.errors.name || validation.errors.url || this.t('toast.provider.urlRequired'), 'error');
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const params = { name: validation.name, url: validation.url };
|
|
413
|
+
if (this.editingProvider && this.editingProvider.useTransform) {
|
|
414
|
+
params.useTransform = true;
|
|
415
|
+
}
|
|
416
|
+
if (this._editProviderRealKeyLoaded) {
|
|
417
|
+
const currentKey = typeof this.editingProvider.key === 'string' ? this.editingProvider.key : '';
|
|
418
|
+
const originalKey = typeof this._editProviderOriginalKey === 'string' ? this._editProviderOriginalKey : '';
|
|
419
|
+
if (currentKey !== originalKey) {
|
|
420
|
+
params.key = currentKey;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
const res = await api('update-provider', params);
|
|
425
|
+
if (res.error) {
|
|
426
|
+
this.showMessage(res.error, 'error');
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// 本地更新:更新列表中对应 provider 的 url 和 key
|
|
431
|
+
this.providersList = this.providersList.map(p => {
|
|
432
|
+
if (p.name === validation.name) {
|
|
433
|
+
const keyUpdated = typeof params.key === 'string';
|
|
434
|
+
return {
|
|
435
|
+
...p,
|
|
436
|
+
url: validation.url,
|
|
437
|
+
key: keyUpdated ? maskKeyLocal(params.key) : p.key,
|
|
438
|
+
hasKey: keyUpdated ? !!params.key : p.hasKey
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
return p;
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
this.closeEditModal();
|
|
445
|
+
this.showMessage(this.t('toast.operation.success'), 'success');
|
|
446
|
+
} catch (e) {
|
|
447
|
+
this.showMessage(this.t('toast.provider.updateFail'), 'error');
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
|
|
451
|
+
closeEditModal() {
|
|
452
|
+
this.showEditModal = false;
|
|
453
|
+
this.showEditProviderKey = false;
|
|
454
|
+
this._editProviderOriginalKey = '';
|
|
455
|
+
this._editProviderRealKeyLoaded = false;
|
|
456
|
+
this.editingProvider = { name: '', url: '', key: '', readOnly: false, nonEditable: false, useTransform: false };
|
|
457
|
+
},
|
|
458
|
+
|
|
459
|
+
toggleEditProviderKey() {
|
|
460
|
+
this.showEditProviderKey = !this.showEditProviderKey;
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
async resetConfig() {
|
|
464
|
+
if (this.resetConfigLoading) return;
|
|
465
|
+
this.resetConfigLoading = true;
|
|
466
|
+
try {
|
|
467
|
+
const res = await api('reset-config');
|
|
468
|
+
if (res.error) {
|
|
469
|
+
this.showMessage(res.error, 'error');
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
const backup = res.backupFile ? `(已备份: ${res.backupFile})` : '';
|
|
473
|
+
this.showMessage(this.t('toast.provider.resetSuccess', { backup }), 'success');
|
|
474
|
+
await this.loadAll();
|
|
475
|
+
} catch (e) {
|
|
476
|
+
this.showMessage(this.t('toast.provider.resetFail'), 'error');
|
|
477
|
+
} finally {
|
|
478
|
+
this.resetConfigLoading = false;
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
|
|
482
|
+
async addModel() {
|
|
483
|
+
if (!this.newModelName || !this.newModelName.trim()) {
|
|
484
|
+
return this.showMessage('请输入模型', 'error');
|
|
485
|
+
}
|
|
486
|
+
try {
|
|
487
|
+
const modelName = this.newModelName.trim();
|
|
488
|
+
const res = await api('add-model', { model: modelName });
|
|
489
|
+
if (res.error) {
|
|
490
|
+
this.showMessage(res.error, 'error');
|
|
491
|
+
} else {
|
|
492
|
+
// 本地更新:在当前 provider 的 models 中追加
|
|
493
|
+
this.providersList = this.providersList.map(p => {
|
|
494
|
+
if (p.name === this.currentProvider) {
|
|
495
|
+
const exists = p.models.some(m => m.id === modelName);
|
|
496
|
+
if (!exists) {
|
|
497
|
+
return {
|
|
498
|
+
...p,
|
|
499
|
+
models: [...p.models, { id: modelName, name: modelName, cost: null, contextWindow: undefined, maxTokens: undefined }]
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return p;
|
|
504
|
+
});
|
|
505
|
+
this.showMessage(this.t('toast.operation.success'), 'success');
|
|
506
|
+
this.closeModelModal();
|
|
507
|
+
}
|
|
508
|
+
} catch (_) {
|
|
509
|
+
this.showMessage('新增模型失败', 'error');
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
|
|
513
|
+
async removeModel(model) {
|
|
514
|
+
try {
|
|
515
|
+
const res = await api('delete-model', { model });
|
|
516
|
+
if (res.error) {
|
|
517
|
+
this.showMessage(res.error, 'error');
|
|
518
|
+
} else {
|
|
519
|
+
// 本地更新:从当前 provider 的 models 中移除
|
|
520
|
+
this.providersList = this.providersList.map(p => {
|
|
521
|
+
if (p.name === this.currentProvider) {
|
|
522
|
+
return {
|
|
523
|
+
...p,
|
|
524
|
+
models: p.models.filter(m => m.id !== model)
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
return p;
|
|
528
|
+
});
|
|
529
|
+
this.showMessage(this.t('toast.operation.success'), 'success');
|
|
530
|
+
}
|
|
531
|
+
} catch (_) {
|
|
532
|
+
this.showMessage('删除模型失败', 'error');
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
|
|
536
|
+
closeAddModal() {
|
|
537
|
+
this.showAddModal = false;
|
|
538
|
+
this.showAddProviderKey = false;
|
|
539
|
+
this.newProvider = { name: '', url: '', key: '', model: '', useTransform: false };
|
|
540
|
+
},
|
|
541
|
+
|
|
542
|
+
toggleAddProviderKey() {
|
|
543
|
+
this.showAddProviderKey = !this.showAddProviderKey;
|
|
544
|
+
},
|
|
545
|
+
|
|
546
|
+
closeModelModal() {
|
|
547
|
+
this.showModelModal = false;
|
|
548
|
+
this.newModelName = '';
|
|
549
|
+
},
|
|
550
|
+
|
|
551
|
+
formatKey(key) {
|
|
552
|
+
if (!key) return '(未设置)';
|
|
553
|
+
if (key.length > 10) {
|
|
554
|
+
return key.substring(0, 3) + '****' + key.substring(key.length - 3);
|
|
555
|
+
}
|
|
556
|
+
return '****';
|
|
557
|
+
},
|
|
558
|
+
|
|
559
|
+
displayApiKey(configName) {
|
|
560
|
+
const config = this.claudeConfigs && this.claudeConfigs[configName]
|
|
561
|
+
? this.claudeConfigs[configName]
|
|
562
|
+
: null;
|
|
563
|
+
const key = config ? config.apiKey : '';
|
|
564
|
+
return this.formatKey(key);
|
|
565
|
+
},
|
|
566
|
+
|
|
567
|
+
async loadLocalBridgeExcluded() {
|
|
568
|
+
try {
|
|
569
|
+
const res = await api('local-bridge-get-excluded');
|
|
570
|
+
if (res && Array.isArray(res.excludedProviders)) {
|
|
571
|
+
this.localBridgeExcluded = res.excludedProviders;
|
|
572
|
+
}
|
|
573
|
+
} catch (e) { /* ignore */ }
|
|
574
|
+
},
|
|
575
|
+
|
|
576
|
+
async toggleLocalBridgeExcluded(providerName) {
|
|
577
|
+
const name = String(providerName || '').trim();
|
|
578
|
+
if (!name) return;
|
|
579
|
+
const idx = this.localBridgeExcluded.indexOf(name);
|
|
580
|
+
const next = [...this.localBridgeExcluded];
|
|
581
|
+
if (idx >= 0) {
|
|
582
|
+
next.splice(idx, 1);
|
|
583
|
+
} else {
|
|
584
|
+
next.push(name);
|
|
585
|
+
}
|
|
586
|
+
try {
|
|
587
|
+
const res = await api('local-bridge-set-excluded', { names: next });
|
|
588
|
+
if (res && !res.error) {
|
|
589
|
+
this.localBridgeExcluded = next;
|
|
590
|
+
}
|
|
591
|
+
} catch (e) { /* ignore */ }
|
|
592
|
+
},
|
|
593
|
+
|
|
594
|
+
isLocalBridgeExcluded(providerName) {
|
|
595
|
+
return this.localBridgeExcluded.indexOf(String(providerName || '').trim()) >= 0;
|
|
596
|
+
},
|
|
597
|
+
|
|
598
|
+
localBridgeCandidateProviders() {
|
|
599
|
+
return (this.providersList || []).filter(p => p && p.name !== 'local' && p.name !== 'codexmate-proxy' && p.codexmate_bridge !== 'local');
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
}
|