codexmate 0.0.24 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +416 -391
  2. package/README.zh.md +349 -324
  3. package/cli/agents-files.js +224 -224
  4. package/cli/archive-helpers.js +446 -446
  5. package/cli/auth-profiles.js +375 -375
  6. package/cli/builtin-proxy.js +1079 -1044
  7. package/cli/claude-proxy.js +1022 -998
  8. package/cli/config-bootstrap.js +384 -384
  9. package/cli/config-health.js +338 -338
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -334
  12. package/cli/openai-bridge.js +997 -950
  13. package/cli/openclaw-config.js +629 -629
  14. package/cli/session-convert-args.js +65 -0
  15. package/cli/session-convert-io.js +82 -0
  16. package/cli/session-convert.js +43 -0
  17. package/cli/session-usage.concurrent.js +28 -28
  18. package/cli/session-usage.js +118 -112
  19. package/cli/session-usage.models.js +176 -176
  20. package/cli/skills.js +1141 -1141
  21. package/cli/zip-commands.js +510 -510
  22. package/cli.js +15218 -13310
  23. package/lib/automation.js +404 -0
  24. package/lib/cli-file-utils.js +151 -151
  25. package/lib/cli-models-utils.js +379 -379
  26. package/lib/cli-network-utils.js +190 -190
  27. package/lib/cli-path-utils.js +85 -69
  28. package/lib/cli-session-utils.js +121 -121
  29. package/lib/cli-sessions.js +417 -386
  30. package/lib/cli-utils.js +155 -155
  31. package/lib/download-artifacts.js +92 -77
  32. package/lib/mcp-stdio.js +453 -440
  33. package/lib/task-orchestrator.js +869 -869
  34. package/lib/text-diff.js +303 -303
  35. package/lib/workflow-engine.js +340 -340
  36. package/package.json +74 -77
  37. package/plugins/README.md +20 -20
  38. package/plugins/README.zh-CN.md +20 -20
  39. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  40. package/plugins/prompt-templates/computed.mjs +253 -253
  41. package/plugins/prompt-templates/index.mjs +8 -8
  42. package/plugins/prompt-templates/manifest.mjs +15 -15
  43. package/plugins/prompt-templates/methods.mjs +619 -619
  44. package/plugins/prompt-templates/overview.mjs +90 -90
  45. package/plugins/prompt-templates/ownership.mjs +19 -19
  46. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  47. package/plugins/prompt-templates/storage.mjs +64 -64
  48. package/plugins/registry.mjs +16 -16
  49. package/web-ui/app.js +625 -609
  50. package/web-ui/index.html +35 -35
  51. package/web-ui/logic.agents-diff.mjs +386 -386
  52. package/web-ui/logic.claude.mjs +168 -168
  53. package/web-ui/logic.mjs +5 -5
  54. package/web-ui/logic.runtime.mjs +128 -128
  55. package/web-ui/logic.session-convert.mjs +70 -0
  56. package/web-ui/logic.sessions.mjs +709 -614
  57. package/web-ui/modules/api.mjs +90 -90
  58. package/web-ui/modules/app.computed.dashboard.mjs +171 -126
  59. package/web-ui/modules/app.computed.index.mjs +17 -17
  60. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  61. package/web-ui/modules/app.computed.session.mjs +946 -653
  62. package/web-ui/modules/app.constants.mjs +15 -15
  63. package/web-ui/modules/app.methods.agents.mjs +632 -632
  64. package/web-ui/modules/app.methods.claude-config.mjs +179 -174
  65. package/web-ui/modules/app.methods.codex-config.mjs +860 -784
  66. package/web-ui/modules/app.methods.index.mjs +92 -92
  67. package/web-ui/modules/app.methods.install.mjs +205 -177
  68. package/web-ui/modules/app.methods.navigation.mjs +743 -695
  69. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  70. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  71. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  72. package/web-ui/modules/app.methods.providers.mjs +404 -404
  73. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  74. package/web-ui/modules/app.methods.session-actions.mjs +596 -537
  75. package/web-ui/modules/app.methods.session-browser.mjs +985 -698
  76. package/web-ui/modules/app.methods.session-timeline.mjs +479 -448
  77. package/web-ui/modules/app.methods.session-trash.mjs +424 -422
  78. package/web-ui/modules/app.methods.startup-claude.mjs +522 -417
  79. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  80. package/web-ui/modules/config-mode.computed.mjs +124 -124
  81. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  82. package/web-ui/modules/i18n.dict.mjs +2113 -2039
  83. package/web-ui/modules/i18n.mjs +56 -56
  84. package/web-ui/modules/plugins.computed.mjs +3 -3
  85. package/web-ui/modules/plugins.methods.mjs +3 -3
  86. package/web-ui/modules/plugins.storage.mjs +11 -11
  87. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  88. package/web-ui/modules/skills.computed.mjs +107 -107
  89. package/web-ui/modules/skills.methods.mjs +481 -481
  90. package/web-ui/partials/index/layout-footer.html +13 -13
  91. package/web-ui/partials/index/layout-header.html +475 -465
  92. package/web-ui/partials/index/modal-config-template-agents.html +174 -174
  93. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  94. package/web-ui/partials/index/modal-health-check.html +45 -45
  95. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  96. package/web-ui/partials/index/modal-skills.html +200 -200
  97. package/web-ui/partials/index/modals-basic.html +165 -165
  98. package/web-ui/partials/index/panel-config-claude.html +184 -179
  99. package/web-ui/partials/index/panel-config-codex.html +283 -283
  100. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  101. package/web-ui/partials/index/panel-dashboard.html +186 -186
  102. package/web-ui/partials/index/panel-docs.html +147 -147
  103. package/web-ui/partials/index/panel-market.html +177 -177
  104. package/web-ui/partials/index/panel-orchestration.html +391 -391
  105. package/web-ui/partials/index/panel-plugins.html +279 -279
  106. package/web-ui/partials/index/panel-sessions.html +326 -301
  107. package/web-ui/partials/index/panel-settings.html +258 -258
  108. package/web-ui/partials/index/panel-usage.html +342 -354
  109. package/{res → web-ui/res}/json5.min.js +1 -1
  110. package/{res → web-ui/res}/vue.global.prod.js +13 -13
  111. package/web-ui/session-helpers.mjs +576 -573
  112. package/web-ui/source-bundle.cjs +233 -233
  113. package/web-ui/styles/base-theme.css +268 -264
  114. package/web-ui/styles/controls-forms.css +423 -376
  115. package/web-ui/styles/dashboard.css +274 -274
  116. package/web-ui/styles/docs-panel.css +247 -247
  117. package/web-ui/styles/feedback.css +108 -108
  118. package/web-ui/styles/health-check-dialog.css +144 -144
  119. package/web-ui/styles/layout-shell.css +603 -602
  120. package/web-ui/styles/modals-core.css +464 -464
  121. package/web-ui/styles/navigation-panels.css +390 -390
  122. package/web-ui/styles/openclaw-structured.css +266 -266
  123. package/web-ui/styles/plugins-panel.css +523 -523
  124. package/web-ui/styles/responsive.css +454 -456
  125. package/web-ui/styles/sessions-list.css +415 -400
  126. package/web-ui/styles/sessions-preview.css +411 -411
  127. package/web-ui/styles/sessions-toolbar-trash.css +330 -268
  128. package/web-ui/styles/sessions-usage.css +945 -888
  129. package/web-ui/styles/settings-panel.css +166 -166
  130. package/web-ui/styles/skills-list.css +303 -303
  131. package/web-ui/styles/skills-market.css +406 -406
  132. package/web-ui/styles/task-orchestration.css +822 -822
  133. package/web-ui/styles/titles-cards.css +408 -408
  134. package/web-ui/styles.css +21 -21
  135. package/web-ui.html +17 -17
  136. /package/{res → web-ui/res}/logo-pack.webp +0 -0
@@ -1,404 +1,404 @@
1
- const PROVIDER_NAME_PATTERN = /^[a-zA-Z0-9._-]+$/;
2
- const RESERVED_PROXY_PROVIDER_NAME = 'codexmate-proxy';
3
-
4
- function normalizeText(value) {
5
- return typeof value === 'string' ? value.trim() : '';
6
- }
7
-
8
- function normalizeProviderUrl(value) {
9
- return normalizeText(value).replace(/\/+$/g, '');
10
- }
11
-
12
- function isValidHttpUrl(value) {
13
- if (!value) return false;
14
- try {
15
- const parsed = new URL(value);
16
- return parsed.protocol === 'http:' || parsed.protocol === 'https:';
17
- } catch (_) {
18
- return false;
19
- }
20
- }
21
-
22
- function isReservedProviderCreationNameInput(name) {
23
- const normalized = normalizeText(name).toLowerCase();
24
- return normalized === RESERVED_PROXY_PROVIDER_NAME;
25
- }
26
-
27
- function isValidProviderNameInputValue(name) {
28
- return PROVIDER_NAME_PATTERN.test(normalizeText(name));
29
- }
30
-
31
- function isValidProviderUrlInputValue(url) {
32
- return isValidHttpUrl(normalizeProviderUrl(url));
33
- }
34
-
35
- function findProviderByName(list, name) {
36
- const target = normalizeText(name);
37
- if (!target) return null;
38
- return (Array.isArray(list) ? list : []).find((item) => item && normalizeText(item.name) === target) || null;
39
- }
40
-
41
- function normalizeProviderDraftState(target) {
42
- if (!target || typeof target !== 'object') return;
43
- if (typeof target.name === 'string') {
44
- target.name = target.name.trim();
45
- }
46
- if (typeof target.url === 'string') {
47
- target.url = normalizeProviderUrl(target.url);
48
- }
49
- }
50
-
51
- function getProviderValidationForContext(vm, mode = 'add') {
52
- const draft = mode === 'edit' ? vm.editingProvider : vm.newProvider;
53
- const editingName = mode === 'edit' ? normalizeText(draft && draft.name) : '';
54
- const name = normalizeText(draft && draft.name);
55
- const url = normalizeProviderUrl(draft && draft.url);
56
- const errors = {
57
- name: '',
58
- url: ''
59
- };
60
-
61
- if (mode === 'add') {
62
- if (!name) {
63
- errors.name = '名称不能为空';
64
- } else if (!isValidProviderNameInputValue(name)) {
65
- errors.name = '名称仅支持字母/数字/._-';
66
- } else if (isReservedProviderCreationNameInput(name)) {
67
- errors.name = 'codexmate-proxy 为保留名称,不可手动添加';
68
- } else if (findProviderByName(vm.providersList, name)) {
69
- errors.name = '名称已存在';
70
- }
71
- } else if (!editingName) {
72
- errors.name = '提供商名称不能为空';
73
- }
74
-
75
- if (!url) {
76
- errors.url = 'URL 必填';
77
- } else if (!isValidProviderUrlInputValue(url)) {
78
- errors.url = 'URL 仅支持 http/https';
79
- }
80
-
81
- return {
82
- mode,
83
- name,
84
- url,
85
- errors,
86
- ok: !errors.name && !errors.url
87
- };
88
- }
89
-
90
- function canSubmitProviderForContext(vm, mode = 'add') {
91
- if (mode === 'edit' && vm.editingProvider && (vm.editingProvider.readOnly || vm.editingProvider.nonEditable)) {
92
- return false;
93
- }
94
- return getProviderValidationForContext(vm, mode).ok;
95
- }
96
-
97
- export function createProvidersMethods(options = {}) {
98
- const { api } = options;
99
-
100
- return {
101
- normalizeProviderDraft(mode = 'add') {
102
- normalizeProviderDraftState(mode === 'edit' ? this.editingProvider : this.newProvider);
103
- },
104
-
105
- isReservedProviderCreationName(name) {
106
- return isReservedProviderCreationNameInput(name);
107
- },
108
-
109
- isValidProviderNameInput(name) {
110
- return isValidProviderNameInputValue(name);
111
- },
112
-
113
- isValidProviderUrlInput(url) {
114
- return isValidProviderUrlInputValue(url);
115
- },
116
-
117
- findProviderByName(name) {
118
- return findProviderByName(this.providersList, name);
119
- },
120
-
121
- getProviderValidation(mode = 'add') {
122
- return getProviderValidationForContext(this, mode);
123
- },
124
-
125
- providerFieldError(mode, fieldName) {
126
- const validation = getProviderValidationForContext(this, mode);
127
- return validation && validation.errors && typeof validation.errors[fieldName] === 'string'
128
- ? validation.errors[fieldName]
129
- : '';
130
- },
131
-
132
- canSubmitProvider(mode = 'add') {
133
- return canSubmitProviderForContext(this, mode);
134
- },
135
-
136
- async addProvider() {
137
- normalizeProviderDraftState(this.newProvider);
138
- const validation = getProviderValidationForContext(this, 'add');
139
- if (!validation.ok) {
140
- return this.showMessage(validation.errors.name || validation.errors.url || '名称和URL必填', 'error');
141
- }
142
-
143
- try {
144
- const payload = {
145
- name: validation.name,
146
- url: validation.url,
147
- key: this.newProvider.key || ''
148
- };
149
- if (this.newProvider && this.newProvider.useTransform) {
150
- payload.useTransform = true;
151
- }
152
- const res = await api('add-provider', payload);
153
- if (res.error) {
154
- this.showMessage(res.error, 'error');
155
- return;
156
- }
157
-
158
- this.showMessage('操作成功', 'success');
159
- this.closeAddModal();
160
- await this.loadAll();
161
- } catch (e) {
162
- this.showMessage('添加失败', 'error');
163
- }
164
- },
165
-
166
- getCurrentCodexAuthProfile() {
167
- const list = Array.isArray(this.codexAuthProfiles) ? this.codexAuthProfiles : [];
168
- return list.find((item) => !!(item && item.current)) || null;
169
- },
170
-
171
- providerPillState(provider) {
172
- const configured = !!(provider && provider.hasKey);
173
- return {
174
- configured,
175
- text: configured ? '已配置' : '未配置'
176
- };
177
- },
178
-
179
- providerPillConfigured(provider) {
180
- return this.providerPillState(provider).configured;
181
- },
182
-
183
- providerPillText(provider) {
184
- return this.providerPillState(provider).text;
185
- },
186
-
187
- isReadOnlyProvider(providerOrName) {
188
- if (!providerOrName) return false;
189
- if (typeof providerOrName === 'object') {
190
- return !!providerOrName.readOnly;
191
- }
192
- const name = String(providerOrName).trim();
193
- if (!name) return false;
194
- const target = (this.providersList || []).find((item) => item && item.name === name);
195
- return !!(target && target.readOnly);
196
- },
197
-
198
- isNonDeletableProvider(providerOrName) {
199
- if (!providerOrName) return false;
200
- if (typeof providerOrName === 'object') {
201
- return !!providerOrName.nonDeletable;
202
- }
203
- const name = String(providerOrName).trim();
204
- if (!name) return false;
205
- const target = (this.providersList || []).find((item) => item && item.name === name);
206
- return !!(target && target.nonDeletable);
207
- },
208
-
209
- shouldShowProviderDelete(provider) {
210
- return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
211
- },
212
-
213
- shouldShowProviderEdit(provider) {
214
- return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
215
- },
216
-
217
- shouldAllowProviderShare(provider) {
218
- return !this.isReadOnlyProvider(provider);
219
- },
220
-
221
- async deleteProvider(name) {
222
- if (this.isNonDeletableProvider(name)) {
223
- this.showMessage('该 provider 为保留项,不可删除', 'info');
224
- return;
225
- }
226
- try {
227
- const res = await api('delete-provider', { name });
228
- if (res.error) {
229
- this.showMessage(res.error, 'error');
230
- return;
231
- }
232
- if (res.switched && res.provider) {
233
- this.showMessage(`已删除提供商,自动切换到 ${res.provider}${res.model ? ` / ${res.model}` : ''}`, 'success');
234
- } else {
235
- this.showMessage('操作成功', 'success');
236
- }
237
- await this.loadAll();
238
- } catch (_) {
239
- this.showMessage('删除失败', 'error');
240
- }
241
- },
242
-
243
- async openEditModal(provider) {
244
- const requestId = Symbol('openEditModal');
245
- this._openEditModalRequestId = requestId;
246
- if (!this.shouldShowProviderEdit(provider)) {
247
- this.showMessage('该 provider 为保留项,不可编辑', 'info');
248
- return;
249
- }
250
- const isTransformProvider = (() => {
251
- if (!provider || typeof provider !== 'object') return false;
252
- const bridge = typeof provider.codexmate_bridge === 'string' ? provider.codexmate_bridge.trim() : '';
253
- if (bridge === 'openai') return true;
254
- const url = String(provider.url || '');
255
- return url.includes('/bridge/openai/');
256
- })();
257
- this.editingProvider = {
258
- name: provider.name,
259
- url: normalizeProviderUrl(provider.url || ''),
260
- key: '',
261
- readOnly: !!provider.readOnly,
262
- nonEditable: typeof provider.nonEditable === 'boolean'
263
- ? provider.nonEditable
264
- : this.isNonDeletableProvider(provider),
265
- useTransform: isTransformProvider
266
- };
267
- this.showEditModal = true;
268
-
269
- if (isTransformProvider) {
270
- try {
271
- const res = await api('openai-bridge-get-provider', { name: provider.name });
272
- if (
273
- this._openEditModalRequestId === requestId
274
- && this.showEditModal
275
- && this.editingProvider
276
- && this.editingProvider.name === provider.name
277
- && res && !res.error
278
- && typeof res.baseUrl === 'string'
279
- && res.baseUrl.trim()
280
- ) {
281
- this.editingProvider.url = normalizeProviderUrl(res.baseUrl);
282
- }
283
- } catch (_) {
284
- // ignore
285
- }
286
- }
287
- },
288
-
289
- async updateProvider() {
290
- if (this.editingProvider.readOnly || this.editingProvider.nonEditable) {
291
- this.showMessage('该 provider 为保留项,不可编辑', 'error');
292
- this.closeEditModal();
293
- return;
294
- }
295
- normalizeProviderDraftState(this.editingProvider);
296
- const validation = getProviderValidationForContext(this, 'edit');
297
- if (!validation.ok) {
298
- return this.showMessage(validation.errors.name || validation.errors.url || 'URL 必填', 'error');
299
- }
300
-
301
- const params = { name: validation.name, url: validation.url };
302
- if (this.editingProvider && this.editingProvider.useTransform) {
303
- params.useTransform = true;
304
- }
305
- if (typeof this.editingProvider.key === 'string' && this.editingProvider.key.trim()) {
306
- params.key = this.editingProvider.key;
307
- }
308
- try {
309
- const res = await api('update-provider', params);
310
- if (res.error) {
311
- this.showMessage(res.error, 'error');
312
- return;
313
- }
314
- this.closeEditModal();
315
- this.showMessage('操作成功', 'success');
316
- await this.loadAll();
317
- } catch (e) {
318
- this.showMessage('更新失败', 'error');
319
- }
320
- },
321
-
322
- closeEditModal() {
323
- this.showEditModal = false;
324
- this.editingProvider = { name: '', url: '', key: '', readOnly: false, nonEditable: false, useTransform: false };
325
- },
326
-
327
- async resetConfig() {
328
- if (this.resetConfigLoading) return;
329
- this.resetConfigLoading = true;
330
- try {
331
- const res = await api('reset-config');
332
- if (res.error) {
333
- this.showMessage(res.error, 'error');
334
- return;
335
- }
336
- const backup = res.backupFile ? `(已备份: ${res.backupFile})` : '';
337
- this.showMessage(`配置已重装${backup}`, 'success');
338
- await this.loadAll();
339
- } catch (e) {
340
- this.showMessage('重装失败', 'error');
341
- } finally {
342
- this.resetConfigLoading = false;
343
- }
344
- },
345
-
346
- async addModel() {
347
- if (!this.newModelName || !this.newModelName.trim()) {
348
- return this.showMessage('请输入模型', 'error');
349
- }
350
- try {
351
- const res = await api('add-model', { model: this.newModelName.trim() });
352
- if (res.error) {
353
- this.showMessage(res.error, 'error');
354
- } else {
355
- this.showMessage('操作成功', 'success');
356
- this.closeModelModal();
357
- await this.loadAll();
358
- }
359
- } catch (_) {
360
- this.showMessage('新增模型失败', 'error');
361
- }
362
- },
363
-
364
- async removeModel(model) {
365
- try {
366
- const res = await api('delete-model', { model });
367
- if (res.error) {
368
- this.showMessage(res.error, 'error');
369
- } else {
370
- this.showMessage('操作成功', 'success');
371
- await this.loadAll();
372
- }
373
- } catch (_) {
374
- this.showMessage('删除模型失败', 'error');
375
- }
376
- },
377
-
378
- closeAddModal() {
379
- this.showAddModal = false;
380
- this.newProvider = { name: '', url: '', key: '', useTransform: false };
381
- },
382
-
383
- closeModelModal() {
384
- this.showModelModal = false;
385
- this.newModelName = '';
386
- },
387
-
388
- formatKey(key) {
389
- if (!key) return '(未设置)';
390
- if (key.length > 10) {
391
- return key.substring(0, 3) + '****' + key.substring(key.length - 3);
392
- }
393
- return '****';
394
- },
395
-
396
- displayApiKey(configName) {
397
- const config = this.claudeConfigs && this.claudeConfigs[configName]
398
- ? this.claudeConfigs[configName]
399
- : null;
400
- const key = config ? config.apiKey : '';
401
- return this.formatKey(key);
402
- }
403
- };
404
- }
1
+ const PROVIDER_NAME_PATTERN = /^[a-zA-Z0-9._-]+$/;
2
+ const RESERVED_PROXY_PROVIDER_NAME = 'codexmate-proxy';
3
+
4
+ function normalizeText(value) {
5
+ return typeof value === 'string' ? value.trim() : '';
6
+ }
7
+
8
+ function normalizeProviderUrl(value) {
9
+ return normalizeText(value).replace(/\/+$/g, '');
10
+ }
11
+
12
+ function isValidHttpUrl(value) {
13
+ if (!value) return false;
14
+ try {
15
+ const parsed = new URL(value);
16
+ return parsed.protocol === 'http:' || parsed.protocol === 'https:';
17
+ } catch (_) {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ function isReservedProviderCreationNameInput(name) {
23
+ const normalized = normalizeText(name).toLowerCase();
24
+ return normalized === RESERVED_PROXY_PROVIDER_NAME;
25
+ }
26
+
27
+ function isValidProviderNameInputValue(name) {
28
+ return PROVIDER_NAME_PATTERN.test(normalizeText(name));
29
+ }
30
+
31
+ function isValidProviderUrlInputValue(url) {
32
+ return isValidHttpUrl(normalizeProviderUrl(url));
33
+ }
34
+
35
+ function findProviderByName(list, name) {
36
+ const target = normalizeText(name);
37
+ if (!target) return null;
38
+ return (Array.isArray(list) ? list : []).find((item) => item && normalizeText(item.name) === target) || null;
39
+ }
40
+
41
+ function normalizeProviderDraftState(target) {
42
+ if (!target || typeof target !== 'object') return;
43
+ if (typeof target.name === 'string') {
44
+ target.name = target.name.trim();
45
+ }
46
+ if (typeof target.url === 'string') {
47
+ target.url = normalizeProviderUrl(target.url);
48
+ }
49
+ }
50
+
51
+ function getProviderValidationForContext(vm, mode = 'add') {
52
+ const draft = mode === 'edit' ? vm.editingProvider : vm.newProvider;
53
+ const editingName = mode === 'edit' ? normalizeText(draft && draft.name) : '';
54
+ const name = normalizeText(draft && draft.name);
55
+ const url = normalizeProviderUrl(draft && draft.url);
56
+ const errors = {
57
+ name: '',
58
+ url: ''
59
+ };
60
+
61
+ if (mode === 'add') {
62
+ if (!name) {
63
+ errors.name = '名称不能为空';
64
+ } else if (!isValidProviderNameInputValue(name)) {
65
+ errors.name = '名称仅支持字母/数字/._-';
66
+ } else if (isReservedProviderCreationNameInput(name)) {
67
+ errors.name = 'codexmate-proxy 为保留名称,不可手动添加';
68
+ } else if (findProviderByName(vm.providersList, name)) {
69
+ errors.name = '名称已存在';
70
+ }
71
+ } else if (!editingName) {
72
+ errors.name = '提供商名称不能为空';
73
+ }
74
+
75
+ if (!url) {
76
+ errors.url = 'URL 必填';
77
+ } else if (!isValidProviderUrlInputValue(url)) {
78
+ errors.url = 'URL 仅支持 http/https';
79
+ }
80
+
81
+ return {
82
+ mode,
83
+ name,
84
+ url,
85
+ errors,
86
+ ok: !errors.name && !errors.url
87
+ };
88
+ }
89
+
90
+ function canSubmitProviderForContext(vm, mode = 'add') {
91
+ if (mode === 'edit' && vm.editingProvider && (vm.editingProvider.readOnly || vm.editingProvider.nonEditable)) {
92
+ return false;
93
+ }
94
+ return getProviderValidationForContext(vm, mode).ok;
95
+ }
96
+
97
+ export function createProvidersMethods(options = {}) {
98
+ const { api } = options;
99
+
100
+ return {
101
+ normalizeProviderDraft(mode = 'add') {
102
+ normalizeProviderDraftState(mode === 'edit' ? this.editingProvider : this.newProvider);
103
+ },
104
+
105
+ isReservedProviderCreationName(name) {
106
+ return isReservedProviderCreationNameInput(name);
107
+ },
108
+
109
+ isValidProviderNameInput(name) {
110
+ return isValidProviderNameInputValue(name);
111
+ },
112
+
113
+ isValidProviderUrlInput(url) {
114
+ return isValidProviderUrlInputValue(url);
115
+ },
116
+
117
+ findProviderByName(name) {
118
+ return findProviderByName(this.providersList, name);
119
+ },
120
+
121
+ getProviderValidation(mode = 'add') {
122
+ return getProviderValidationForContext(this, mode);
123
+ },
124
+
125
+ providerFieldError(mode, fieldName) {
126
+ const validation = getProviderValidationForContext(this, mode);
127
+ return validation && validation.errors && typeof validation.errors[fieldName] === 'string'
128
+ ? validation.errors[fieldName]
129
+ : '';
130
+ },
131
+
132
+ canSubmitProvider(mode = 'add') {
133
+ return canSubmitProviderForContext(this, mode);
134
+ },
135
+
136
+ async addProvider() {
137
+ normalizeProviderDraftState(this.newProvider);
138
+ const validation = getProviderValidationForContext(this, 'add');
139
+ if (!validation.ok) {
140
+ return this.showMessage(validation.errors.name || validation.errors.url || '名称和URL必填', 'error');
141
+ }
142
+
143
+ try {
144
+ const payload = {
145
+ name: validation.name,
146
+ url: validation.url,
147
+ key: this.newProvider.key || ''
148
+ };
149
+ if (this.newProvider && this.newProvider.useTransform) {
150
+ payload.useTransform = true;
151
+ }
152
+ const res = await api('add-provider', payload);
153
+ if (res.error) {
154
+ this.showMessage(res.error, 'error');
155
+ return;
156
+ }
157
+
158
+ this.showMessage('操作成功', 'success');
159
+ this.closeAddModal();
160
+ await this.loadAll();
161
+ } catch (e) {
162
+ this.showMessage('添加失败', 'error');
163
+ }
164
+ },
165
+
166
+ getCurrentCodexAuthProfile() {
167
+ const list = Array.isArray(this.codexAuthProfiles) ? this.codexAuthProfiles : [];
168
+ return list.find((item) => !!(item && item.current)) || null;
169
+ },
170
+
171
+ providerPillState(provider) {
172
+ const configured = !!(provider && provider.hasKey);
173
+ return {
174
+ configured,
175
+ text: configured ? '已配置' : '未配置'
176
+ };
177
+ },
178
+
179
+ providerPillConfigured(provider) {
180
+ return this.providerPillState(provider).configured;
181
+ },
182
+
183
+ providerPillText(provider) {
184
+ return this.providerPillState(provider).text;
185
+ },
186
+
187
+ isReadOnlyProvider(providerOrName) {
188
+ if (!providerOrName) return false;
189
+ if (typeof providerOrName === 'object') {
190
+ return !!providerOrName.readOnly;
191
+ }
192
+ const name = String(providerOrName).trim();
193
+ if (!name) return false;
194
+ const target = (this.providersList || []).find((item) => item && item.name === name);
195
+ return !!(target && target.readOnly);
196
+ },
197
+
198
+ isNonDeletableProvider(providerOrName) {
199
+ if (!providerOrName) return false;
200
+ if (typeof providerOrName === 'object') {
201
+ return !!providerOrName.nonDeletable;
202
+ }
203
+ const name = String(providerOrName).trim();
204
+ if (!name) return false;
205
+ const target = (this.providersList || []).find((item) => item && item.name === name);
206
+ return !!(target && target.nonDeletable);
207
+ },
208
+
209
+ shouldShowProviderDelete(provider) {
210
+ return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
211
+ },
212
+
213
+ shouldShowProviderEdit(provider) {
214
+ return !this.isReadOnlyProvider(provider) && !this.isNonDeletableProvider(provider);
215
+ },
216
+
217
+ shouldAllowProviderShare(provider) {
218
+ return !this.isReadOnlyProvider(provider);
219
+ },
220
+
221
+ async deleteProvider(name) {
222
+ if (this.isNonDeletableProvider(name)) {
223
+ this.showMessage('该 provider 为保留项,不可删除', 'info');
224
+ return;
225
+ }
226
+ try {
227
+ const res = await api('delete-provider', { name });
228
+ if (res.error) {
229
+ this.showMessage(res.error, 'error');
230
+ return;
231
+ }
232
+ if (res.switched && res.provider) {
233
+ this.showMessage(`已删除提供商,自动切换到 ${res.provider}${res.model ? ` / ${res.model}` : ''}`, 'success');
234
+ } else {
235
+ this.showMessage('操作成功', 'success');
236
+ }
237
+ await this.loadAll();
238
+ } catch (_) {
239
+ this.showMessage('删除失败', 'error');
240
+ }
241
+ },
242
+
243
+ async openEditModal(provider) {
244
+ const requestId = Symbol('openEditModal');
245
+ this._openEditModalRequestId = requestId;
246
+ if (!this.shouldShowProviderEdit(provider)) {
247
+ this.showMessage('该 provider 为保留项,不可编辑', 'info');
248
+ return;
249
+ }
250
+ const isTransformProvider = (() => {
251
+ if (!provider || typeof provider !== 'object') return false;
252
+ const bridge = typeof provider.codexmate_bridge === 'string' ? provider.codexmate_bridge.trim() : '';
253
+ if (bridge === 'openai') return true;
254
+ const url = String(provider.url || '');
255
+ return url.includes('/bridge/openai/');
256
+ })();
257
+ this.editingProvider = {
258
+ name: provider.name,
259
+ url: normalizeProviderUrl(provider.url || ''),
260
+ key: '',
261
+ readOnly: !!provider.readOnly,
262
+ nonEditable: typeof provider.nonEditable === 'boolean'
263
+ ? provider.nonEditable
264
+ : this.isNonDeletableProvider(provider),
265
+ useTransform: isTransformProvider
266
+ };
267
+ this.showEditModal = true;
268
+
269
+ if (isTransformProvider) {
270
+ try {
271
+ const res = await api('openai-bridge-get-provider', { name: provider.name });
272
+ if (
273
+ this._openEditModalRequestId === requestId
274
+ && this.showEditModal
275
+ && this.editingProvider
276
+ && this.editingProvider.name === provider.name
277
+ && res && !res.error
278
+ && typeof res.baseUrl === 'string'
279
+ && res.baseUrl.trim()
280
+ ) {
281
+ this.editingProvider.url = normalizeProviderUrl(res.baseUrl);
282
+ }
283
+ } catch (_) {
284
+ // ignore
285
+ }
286
+ }
287
+ },
288
+
289
+ async updateProvider() {
290
+ if (this.editingProvider.readOnly || this.editingProvider.nonEditable) {
291
+ this.showMessage('该 provider 为保留项,不可编辑', 'error');
292
+ this.closeEditModal();
293
+ return;
294
+ }
295
+ normalizeProviderDraftState(this.editingProvider);
296
+ const validation = getProviderValidationForContext(this, 'edit');
297
+ if (!validation.ok) {
298
+ return this.showMessage(validation.errors.name || validation.errors.url || 'URL 必填', 'error');
299
+ }
300
+
301
+ const params = { name: validation.name, url: validation.url };
302
+ if (this.editingProvider && this.editingProvider.useTransform) {
303
+ params.useTransform = true;
304
+ }
305
+ if (typeof this.editingProvider.key === 'string' && this.editingProvider.key.trim()) {
306
+ params.key = this.editingProvider.key;
307
+ }
308
+ try {
309
+ const res = await api('update-provider', params);
310
+ if (res.error) {
311
+ this.showMessage(res.error, 'error');
312
+ return;
313
+ }
314
+ this.closeEditModal();
315
+ this.showMessage('操作成功', 'success');
316
+ await this.loadAll();
317
+ } catch (e) {
318
+ this.showMessage('更新失败', 'error');
319
+ }
320
+ },
321
+
322
+ closeEditModal() {
323
+ this.showEditModal = false;
324
+ this.editingProvider = { name: '', url: '', key: '', readOnly: false, nonEditable: false, useTransform: false };
325
+ },
326
+
327
+ async resetConfig() {
328
+ if (this.resetConfigLoading) return;
329
+ this.resetConfigLoading = true;
330
+ try {
331
+ const res = await api('reset-config');
332
+ if (res.error) {
333
+ this.showMessage(res.error, 'error');
334
+ return;
335
+ }
336
+ const backup = res.backupFile ? `(已备份: ${res.backupFile})` : '';
337
+ this.showMessage(`配置已重装${backup}`, 'success');
338
+ await this.loadAll();
339
+ } catch (e) {
340
+ this.showMessage('重装失败', 'error');
341
+ } finally {
342
+ this.resetConfigLoading = false;
343
+ }
344
+ },
345
+
346
+ async addModel() {
347
+ if (!this.newModelName || !this.newModelName.trim()) {
348
+ return this.showMessage('请输入模型', 'error');
349
+ }
350
+ try {
351
+ const res = await api('add-model', { model: this.newModelName.trim() });
352
+ if (res.error) {
353
+ this.showMessage(res.error, 'error');
354
+ } else {
355
+ this.showMessage('操作成功', 'success');
356
+ this.closeModelModal();
357
+ await this.loadAll();
358
+ }
359
+ } catch (_) {
360
+ this.showMessage('新增模型失败', 'error');
361
+ }
362
+ },
363
+
364
+ async removeModel(model) {
365
+ try {
366
+ const res = await api('delete-model', { model });
367
+ if (res.error) {
368
+ this.showMessage(res.error, 'error');
369
+ } else {
370
+ this.showMessage('操作成功', 'success');
371
+ await this.loadAll();
372
+ }
373
+ } catch (_) {
374
+ this.showMessage('删除模型失败', 'error');
375
+ }
376
+ },
377
+
378
+ closeAddModal() {
379
+ this.showAddModal = false;
380
+ this.newProvider = { name: '', url: '', key: '', useTransform: false };
381
+ },
382
+
383
+ closeModelModal() {
384
+ this.showModelModal = false;
385
+ this.newModelName = '';
386
+ },
387
+
388
+ formatKey(key) {
389
+ if (!key) return '(未设置)';
390
+ if (key.length > 10) {
391
+ return key.substring(0, 3) + '****' + key.substring(key.length - 3);
392
+ }
393
+ return '****';
394
+ },
395
+
396
+ displayApiKey(configName) {
397
+ const config = this.claudeConfigs && this.claudeConfigs[configName]
398
+ ? this.claudeConfigs[configName]
399
+ : null;
400
+ const key = config ? config.apiKey : '';
401
+ return this.formatKey(key);
402
+ }
403
+ };
404
+ }