codexmate 0.0.29 → 0.0.31
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 -384
- package/cli/config-health.js +454 -338
- package/cli/doctor-core.js +903 -903
- package/cli/import-skills-url.js +356 -356
- package/cli/local-bridge.js +324 -0
- package/cli/openai-bridge.js +1653 -1576
- 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 +15778 -15340
- 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 +417 -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 +646 -639
- 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 +765 -765
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +248 -225
- 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 +999 -999
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +632 -632
- package/web-ui/modules/app.methods.claude-config.mjs +200 -200
- package/web-ui/modules/app.methods.codex-config.mjs +841 -892
- 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 -761
- 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 -493
- 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 +984 -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 +534 -533
- 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 +3174 -3131
- 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 -481
- package/web-ui/partials/index/layout-footer.html +13 -13
- package/web-ui/partials/index/layout-header.html +500 -500
- package/web-ui/partials/index/modal-config-template-agents.html +174 -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 +194 -194
- package/web-ui/partials/index/panel-config-codex.html +357 -323
- package/web-ui/partials/index/panel-config-codex.html.bak +337 -0
- package/web-ui/partials/index/panel-config-openclaw.html +83 -83
- package/web-ui/partials/index/panel-dashboard.html +219 -186
- package/web-ui/partials/index/panel-docs.html +147 -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 +302 -316
- package/web-ui/partials/index/panel-settings.html +190 -190
- package/web-ui/partials/index/panel-trash.html +88 -88
- package/web-ui/partials/index/panel-usage.html +371 -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 -576
- 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 +422 -422
- package/web-ui/styles/dashboard.css +406 -274
- package/web-ui/styles/docs-panel.css +271 -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 +626 -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 -523
- package/web-ui/styles/responsive.css +454 -454
- package/web-ui/styles/sessions-list.css +417 -419
- package/web-ui/styles/sessions-preview.css +407 -411
- package/web-ui/styles/sessions-toolbar-trash.css +348 -330
- package/web-ui/styles/sessions-usage.css +1040 -1040
- package/web-ui/styles/settings-panel.css +349 -349
- package/web-ui/styles/skills-list.css +305 -303
- package/web-ui/styles/skills-market.css +429 -406
- 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,533 +1,534 @@
|
|
|
1
|
-
import {
|
|
2
|
-
findDuplicateClaudeConfigName,
|
|
3
|
-
getClaudeModelCatalogForBaseUrl,
|
|
4
|
-
matchClaudeConfigFromSettings,
|
|
5
|
-
normalizeClaudeConfig,
|
|
6
|
-
normalizeClaudeSettingsEnv,
|
|
7
|
-
normalizeClaudeValue
|
|
8
|
-
} from '../logic.mjs';
|
|
9
|
-
|
|
10
|
-
export function createStartupClaudeMethods(options = {}) {
|
|
11
|
-
const {
|
|
12
|
-
api,
|
|
13
|
-
defaultModelContextWindow = 190000,
|
|
14
|
-
defaultModelAutoCompactTokenLimit = 185000
|
|
15
|
-
} = options;
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
async loadAll(options = {}) {
|
|
19
|
-
if (this._loadAllPromise) {
|
|
20
|
-
this._loadAllPendingOptions = options;
|
|
21
|
-
return this._loadAllPromise;
|
|
22
|
-
}
|
|
23
|
-
const preserveLoading = !!options.preserveLoading;
|
|
24
|
-
const run = async () => {
|
|
25
|
-
const configLoadTimeoutMs = 6000;
|
|
26
|
-
const withTimeout = async (promise, ms) => {
|
|
27
|
-
const timeoutMs = Number.isFinite(Number(ms)) ? Math.max(0, Number(ms)) : 0;
|
|
28
|
-
if (!timeoutMs) {
|
|
29
|
-
return promise;
|
|
30
|
-
}
|
|
31
|
-
let timer = null;
|
|
32
|
-
try {
|
|
33
|
-
return await Promise.race([
|
|
34
|
-
promise,
|
|
35
|
-
new Promise((_, reject) => {
|
|
36
|
-
timer = setTimeout(() => reject(new Error('timeout')), timeoutMs);
|
|
37
|
-
})
|
|
38
|
-
]);
|
|
39
|
-
} finally {
|
|
40
|
-
if (timer) {
|
|
41
|
-
clearTimeout(timer);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
if (!preserveLoading) {
|
|
46
|
-
this.loading = true;
|
|
47
|
-
}
|
|
48
|
-
this.initError = '';
|
|
49
|
-
const startedAt = Date.now();
|
|
50
|
-
const timeLeftMs = () => configLoadTimeoutMs - (Date.now() - startedAt);
|
|
51
|
-
try {
|
|
52
|
-
const statusRes = await withTimeout(api('status'), timeLeftMs());
|
|
53
|
-
if (statusRes && statusRes.error) {
|
|
54
|
-
this.initError = statusRes.error;
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
const listRes = await withTimeout(api('list'), timeLeftMs());
|
|
58
|
-
if (listRes && listRes.error) {
|
|
59
|
-
this.initError = listRes.error;
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
this.currentProvider = statusRes.provider;
|
|
63
|
-
this.currentModels = statusRes.currentModels && typeof statusRes.currentModels === 'object'
|
|
64
|
-
? { ...statusRes.currentModels }
|
|
65
|
-
: {};
|
|
66
|
-
const dictModelForCurrent = this.currentProvider
|
|
67
|
-
&& typeof this.currentModels[this.currentProvider] === 'string'
|
|
68
|
-
? this.currentModels[this.currentProvider].trim()
|
|
69
|
-
: '';
|
|
70
|
-
this.currentModel = dictModelForCurrent || statusRes.model;
|
|
71
|
-
try {
|
|
72
|
-
const installRes = await withTimeout(api('install-status'), Math.max(0, Math.min(1200, timeLeftMs())));
|
|
73
|
-
if (installRes && !installRes.error) {
|
|
74
|
-
const targets = Array.isArray(installRes.targets) ? installRes.targets : null;
|
|
75
|
-
if (targets) {
|
|
76
|
-
this.installStatusTargets = targets;
|
|
77
|
-
}
|
|
78
|
-
if (typeof installRes.packageManager === 'string' && typeof this.normalizeInstallPackageManager === 'function') {
|
|
79
|
-
this.installPackageManager = this.normalizeInstallPackageManager(installRes.packageManager);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} catch (_) {}
|
|
83
|
-
{
|
|
84
|
-
const tier = typeof statusRes.serviceTier === 'string'
|
|
85
|
-
? statusRes.serviceTier.trim().toLowerCase()
|
|
86
|
-
: '';
|
|
87
|
-
this.serviceTier = tier === 'fast' ? 'fast' : (tier ? 'standard' : 'fast');
|
|
88
|
-
}
|
|
89
|
-
{
|
|
90
|
-
const effort = typeof statusRes.modelReasoningEffort === 'string'
|
|
91
|
-
? statusRes.modelReasoningEffort.trim().toLowerCase()
|
|
92
|
-
: '';
|
|
93
|
-
const allowedReasoningEfforts = new Set(['low', 'medium', 'high', 'xhigh']);
|
|
94
|
-
this.modelReasoningEffort = allowedReasoningEfforts.has(effort) ? effort : 'medium';
|
|
95
|
-
}
|
|
96
|
-
{
|
|
97
|
-
const contextWindow = this.normalizePositiveIntegerInput(
|
|
98
|
-
statusRes.modelContextWindow,
|
|
99
|
-
'model_context_window',
|
|
100
|
-
defaultModelContextWindow
|
|
101
|
-
);
|
|
102
|
-
if (this.editingCodexBudgetField !== 'modelContextWindowInput') {
|
|
103
|
-
this.modelContextWindowInput = contextWindow.ok && contextWindow.text
|
|
104
|
-
? contextWindow.text
|
|
105
|
-
: String(defaultModelContextWindow);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
{
|
|
109
|
-
const autoCompactTokenLimit = this.normalizePositiveIntegerInput(
|
|
110
|
-
statusRes.modelAutoCompactTokenLimit,
|
|
111
|
-
'model_auto_compact_token_limit',
|
|
112
|
-
defaultModelAutoCompactTokenLimit
|
|
113
|
-
);
|
|
114
|
-
if (this.editingCodexBudgetField !== 'modelAutoCompactTokenLimitInput') {
|
|
115
|
-
this.modelAutoCompactTokenLimitInput = autoCompactTokenLimit.ok && autoCompactTokenLimit.text
|
|
116
|
-
? autoCompactTokenLimit.text
|
|
117
|
-
: String(defaultModelAutoCompactTokenLimit);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
this.providersList = listRes.providers;
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
Promise.resolve(this.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
this._loadAllPendingOptions
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
this.codexModelsRequestSeq
|
|
163
|
-
this.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this.
|
|
167
|
-
this.
|
|
168
|
-
this.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
this.
|
|
184
|
-
this.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
this.
|
|
190
|
-
this.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.
|
|
196
|
-
this.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this.
|
|
203
|
-
this.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
externalCredentialType
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
let
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
this.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
this.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
this._refreshClaudeSelectionPendingOptions
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
this.
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
this.
|
|
394
|
-
this.
|
|
395
|
-
this.
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const
|
|
406
|
-
this.claudeModelsRequestSeq
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
const
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
this.
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const
|
|
440
|
-
const
|
|
441
|
-
const
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
&&
|
|
445
|
-
&&
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
this.
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
this.
|
|
458
|
-
this.
|
|
459
|
-
this.
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
&& (
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
this.
|
|
488
|
-
this.
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
this.
|
|
495
|
-
this.
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
this.
|
|
501
|
-
this.
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
this.
|
|
509
|
-
this.
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
//
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
findDuplicateClaudeConfigName,
|
|
3
|
+
getClaudeModelCatalogForBaseUrl,
|
|
4
|
+
matchClaudeConfigFromSettings,
|
|
5
|
+
normalizeClaudeConfig,
|
|
6
|
+
normalizeClaudeSettingsEnv,
|
|
7
|
+
normalizeClaudeValue
|
|
8
|
+
} from '../logic.mjs';
|
|
9
|
+
|
|
10
|
+
export function createStartupClaudeMethods(options = {}) {
|
|
11
|
+
const {
|
|
12
|
+
api,
|
|
13
|
+
defaultModelContextWindow = 190000,
|
|
14
|
+
defaultModelAutoCompactTokenLimit = 185000
|
|
15
|
+
} = options;
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
async loadAll(options = {}) {
|
|
19
|
+
if (this._loadAllPromise) {
|
|
20
|
+
this._loadAllPendingOptions = options;
|
|
21
|
+
return this._loadAllPromise;
|
|
22
|
+
}
|
|
23
|
+
const preserveLoading = !!options.preserveLoading;
|
|
24
|
+
const run = async () => {
|
|
25
|
+
const configLoadTimeoutMs = 6000;
|
|
26
|
+
const withTimeout = async (promise, ms) => {
|
|
27
|
+
const timeoutMs = Number.isFinite(Number(ms)) ? Math.max(0, Number(ms)) : 0;
|
|
28
|
+
if (!timeoutMs) {
|
|
29
|
+
return promise;
|
|
30
|
+
}
|
|
31
|
+
let timer = null;
|
|
32
|
+
try {
|
|
33
|
+
return await Promise.race([
|
|
34
|
+
promise,
|
|
35
|
+
new Promise((_, reject) => {
|
|
36
|
+
timer = setTimeout(() => reject(new Error('timeout')), timeoutMs);
|
|
37
|
+
})
|
|
38
|
+
]);
|
|
39
|
+
} finally {
|
|
40
|
+
if (timer) {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
if (!preserveLoading) {
|
|
46
|
+
this.loading = true;
|
|
47
|
+
}
|
|
48
|
+
this.initError = '';
|
|
49
|
+
const startedAt = Date.now();
|
|
50
|
+
const timeLeftMs = () => configLoadTimeoutMs - (Date.now() - startedAt);
|
|
51
|
+
try {
|
|
52
|
+
const statusRes = await withTimeout(api('status'), timeLeftMs());
|
|
53
|
+
if (statusRes && statusRes.error) {
|
|
54
|
+
this.initError = statusRes.error;
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const listRes = await withTimeout(api('list'), timeLeftMs());
|
|
58
|
+
if (listRes && listRes.error) {
|
|
59
|
+
this.initError = listRes.error;
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
this.currentProvider = statusRes.provider;
|
|
63
|
+
this.currentModels = statusRes.currentModels && typeof statusRes.currentModels === 'object'
|
|
64
|
+
? { ...statusRes.currentModels }
|
|
65
|
+
: {};
|
|
66
|
+
const dictModelForCurrent = this.currentProvider
|
|
67
|
+
&& typeof this.currentModels[this.currentProvider] === 'string'
|
|
68
|
+
? this.currentModels[this.currentProvider].trim()
|
|
69
|
+
: '';
|
|
70
|
+
this.currentModel = dictModelForCurrent || statusRes.model;
|
|
71
|
+
try {
|
|
72
|
+
const installRes = await withTimeout(api('install-status'), Math.max(0, Math.min(1200, timeLeftMs())));
|
|
73
|
+
if (installRes && !installRes.error) {
|
|
74
|
+
const targets = Array.isArray(installRes.targets) ? installRes.targets : null;
|
|
75
|
+
if (targets) {
|
|
76
|
+
this.installStatusTargets = targets;
|
|
77
|
+
}
|
|
78
|
+
if (typeof installRes.packageManager === 'string' && typeof this.normalizeInstallPackageManager === 'function') {
|
|
79
|
+
this.installPackageManager = this.normalizeInstallPackageManager(installRes.packageManager);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (_) {}
|
|
83
|
+
{
|
|
84
|
+
const tier = typeof statusRes.serviceTier === 'string'
|
|
85
|
+
? statusRes.serviceTier.trim().toLowerCase()
|
|
86
|
+
: '';
|
|
87
|
+
this.serviceTier = tier === 'fast' ? 'fast' : (tier ? 'standard' : 'fast');
|
|
88
|
+
}
|
|
89
|
+
{
|
|
90
|
+
const effort = typeof statusRes.modelReasoningEffort === 'string'
|
|
91
|
+
? statusRes.modelReasoningEffort.trim().toLowerCase()
|
|
92
|
+
: '';
|
|
93
|
+
const allowedReasoningEfforts = new Set(['low', 'medium', 'high', 'xhigh']);
|
|
94
|
+
this.modelReasoningEffort = allowedReasoningEfforts.has(effort) ? effort : 'medium';
|
|
95
|
+
}
|
|
96
|
+
{
|
|
97
|
+
const contextWindow = this.normalizePositiveIntegerInput(
|
|
98
|
+
statusRes.modelContextWindow,
|
|
99
|
+
'model_context_window',
|
|
100
|
+
defaultModelContextWindow
|
|
101
|
+
);
|
|
102
|
+
if (this.editingCodexBudgetField !== 'modelContextWindowInput') {
|
|
103
|
+
this.modelContextWindowInput = contextWindow.ok && contextWindow.text
|
|
104
|
+
? contextWindow.text
|
|
105
|
+
: String(defaultModelContextWindow);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
{
|
|
109
|
+
const autoCompactTokenLimit = this.normalizePositiveIntegerInput(
|
|
110
|
+
statusRes.modelAutoCompactTokenLimit,
|
|
111
|
+
'model_auto_compact_token_limit',
|
|
112
|
+
defaultModelAutoCompactTokenLimit
|
|
113
|
+
);
|
|
114
|
+
if (this.editingCodexBudgetField !== 'modelAutoCompactTokenLimitInput') {
|
|
115
|
+
this.modelAutoCompactTokenLimitInput = autoCompactTokenLimit.ok && autoCompactTokenLimit.text
|
|
116
|
+
? autoCompactTokenLimit.text
|
|
117
|
+
: String(defaultModelAutoCompactTokenLimit);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
this.providersList = listRes.providers;
|
|
121
|
+
if (typeof this.loadLocalBridgeExcluded === 'function') { this.loadLocalBridgeExcluded(); }
|
|
122
|
+
if (statusRes.configReady === false) {
|
|
123
|
+
this.showMessage('配置已加载', 'info');
|
|
124
|
+
}
|
|
125
|
+
if (statusRes.initNotice) {
|
|
126
|
+
this.showMessage('配置就绪', 'info');
|
|
127
|
+
}
|
|
128
|
+
this.maybeShowStarPrompt();
|
|
129
|
+
return true;
|
|
130
|
+
} catch (e) {
|
|
131
|
+
this.initError = e && e.message === 'timeout'
|
|
132
|
+
? '读取配置超时'
|
|
133
|
+
: '连接失败: ' + (e && e.message ? e.message : '');
|
|
134
|
+
return false;
|
|
135
|
+
} finally {
|
|
136
|
+
if (!preserveLoading) {
|
|
137
|
+
this.loading = false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
this._loadAllPromise = run()
|
|
143
|
+
.finally(() => {
|
|
144
|
+
this._loadAllPromise = null;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const result = await this._loadAllPromise;
|
|
148
|
+
if (result) {
|
|
149
|
+
Promise.resolve(this.loadModelsForProvider(this.currentProvider)).catch(() => {});
|
|
150
|
+
Promise.resolve(this.loadCodexAuthProfiles()).catch(() => {});
|
|
151
|
+
}
|
|
152
|
+
const pending = this._loadAllPendingOptions;
|
|
153
|
+
this._loadAllPendingOptions = null;
|
|
154
|
+
if (pending) {
|
|
155
|
+
return this.loadAll(pending);
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
async loadModelsForProvider(providerName, options = {}) {
|
|
161
|
+
const targetProvider = typeof providerName === 'string' ? providerName.trim() : '';
|
|
162
|
+
const requestSeq = (Number(this.codexModelsRequestSeq) || 0) + 1;
|
|
163
|
+
this.codexModelsRequestSeq = requestSeq;
|
|
164
|
+
this.codexModelsLoading = true;
|
|
165
|
+
if (!targetProvider) {
|
|
166
|
+
this.models = [];
|
|
167
|
+
this.modelsSource = 'unlimited';
|
|
168
|
+
this.modelsHasCurrent = true;
|
|
169
|
+
this.codexModelsLoading = false;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const isLatestRequest = () => {
|
|
173
|
+
const currentProvider = typeof this.currentProvider === 'string' ? this.currentProvider.trim() : '';
|
|
174
|
+
return requestSeq === Number(this.codexModelsRequestSeq || 0)
|
|
175
|
+
&& (!currentProvider || currentProvider === targetProvider);
|
|
176
|
+
};
|
|
177
|
+
try {
|
|
178
|
+
const res = await api('models', { provider: targetProvider });
|
|
179
|
+
if (!isLatestRequest()) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (res.unlimited) {
|
|
183
|
+
this.models = [];
|
|
184
|
+
this.modelsSource = 'unlimited';
|
|
185
|
+
this.modelsHasCurrent = true;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (res.error) {
|
|
189
|
+
this.models = [];
|
|
190
|
+
this.modelsSource = 'error';
|
|
191
|
+
this.modelsHasCurrent = true;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const list = Array.isArray(res.models) ? res.models : [];
|
|
195
|
+
this.models = list;
|
|
196
|
+
this.modelsSource = res.source || 'remote';
|
|
197
|
+
this.modelsHasCurrent = !!this.currentModel && list.includes(this.currentModel);
|
|
198
|
+
} catch (_) {
|
|
199
|
+
if (!isLatestRequest()) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
this.models = [];
|
|
203
|
+
this.modelsSource = 'error';
|
|
204
|
+
this.modelsHasCurrent = true;
|
|
205
|
+
} finally {
|
|
206
|
+
if (requestSeq === Number(this.codexModelsRequestSeq || 0)) {
|
|
207
|
+
this.codexModelsLoading = false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
getCurrentClaudeConfig() {
|
|
213
|
+
if (!this.currentClaudeConfig) return null;
|
|
214
|
+
return this.claudeConfigs[this.currentClaudeConfig] || null;
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
normalizeClaudeValue,
|
|
218
|
+
|
|
219
|
+
normalizeClaudeConfig(config) {
|
|
220
|
+
return normalizeClaudeConfig(config);
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
normalizeClaudeSettingsEnv(env) {
|
|
224
|
+
return normalizeClaudeSettingsEnv(env);
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
matchClaudeConfigFromSettings(env) {
|
|
228
|
+
return matchClaudeConfigFromSettings(this.claudeConfigs, env);
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
findDuplicateClaudeConfigName(config) {
|
|
232
|
+
return findDuplicateClaudeConfigName(this.claudeConfigs, config);
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
mergeClaudeConfig(existing = {}, updates = {}) {
|
|
236
|
+
const previous = this.normalizeClaudeConfig(existing);
|
|
237
|
+
const next = this.normalizeClaudeConfig({ ...existing, ...updates });
|
|
238
|
+
const externalCredentialType = next.apiKey
|
|
239
|
+
? ''
|
|
240
|
+
: (next.externalCredentialType || previous.externalCredentialType || '');
|
|
241
|
+
return {
|
|
242
|
+
apiKey: next.apiKey,
|
|
243
|
+
baseUrl: next.baseUrl,
|
|
244
|
+
model: next.model || previous.model || 'glm-4.7',
|
|
245
|
+
hasKey: !!(next.apiKey || externalCredentialType),
|
|
246
|
+
externalCredentialType
|
|
247
|
+
};
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
buildClaudeImportedConfigName(baseUrl) {
|
|
251
|
+
const normalizedUrl = typeof baseUrl === 'string' ? baseUrl.trim() : '';
|
|
252
|
+
if (!normalizedUrl) return '导入配置';
|
|
253
|
+
try {
|
|
254
|
+
const parsed = new URL(normalizedUrl);
|
|
255
|
+
const host = typeof parsed.host === 'string' ? parsed.host.trim() : '';
|
|
256
|
+
if (host) return `导入-${host}`;
|
|
257
|
+
} catch (_) {}
|
|
258
|
+
return '导入配置';
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
ensureClaudeConfigFromSettings(env = {}) {
|
|
262
|
+
const normalized = this.normalizeClaudeSettingsEnv(env);
|
|
263
|
+
const hasCredential = !!(normalized.apiKey || normalized.authToken || normalized.useKey);
|
|
264
|
+
if (!normalized.baseUrl || !hasCredential) return '';
|
|
265
|
+
|
|
266
|
+
const duplicateName = this.findDuplicateClaudeConfigName(normalized);
|
|
267
|
+
if (duplicateName) return duplicateName;
|
|
268
|
+
|
|
269
|
+
const preferredName = this.buildClaudeImportedConfigName(normalized.baseUrl);
|
|
270
|
+
let candidateName = preferredName;
|
|
271
|
+
let suffix = 2;
|
|
272
|
+
const maxAttempts = 1000;
|
|
273
|
+
while (this.claudeConfigs[candidateName] && suffix <= maxAttempts) {
|
|
274
|
+
candidateName = `${preferredName}-${suffix}`;
|
|
275
|
+
suffix += 1;
|
|
276
|
+
}
|
|
277
|
+
if (this.claudeConfigs[candidateName]) {
|
|
278
|
+
return '';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
this.claudeConfigs[candidateName] = this.mergeClaudeConfig({}, normalized);
|
|
282
|
+
this.saveClaudeConfigs();
|
|
283
|
+
return candidateName;
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
async refreshClaudeSelectionFromSettings(options = {}) {
|
|
287
|
+
if (this._refreshClaudeSelectionPromise) {
|
|
288
|
+
this._refreshClaudeSelectionPendingOptions = options;
|
|
289
|
+
return this._refreshClaudeSelectionPromise;
|
|
290
|
+
}
|
|
291
|
+
const silent = !!options.silent;
|
|
292
|
+
const silentModelError = !!options.silentModelError || silent;
|
|
293
|
+
const run = async () => {
|
|
294
|
+
const configLoadTimeoutMs = 6000;
|
|
295
|
+
const withTimeout = async (promise, ms) => {
|
|
296
|
+
const timeoutMs = Number.isFinite(Number(ms)) ? Math.max(0, Number(ms)) : 0;
|
|
297
|
+
if (!timeoutMs) {
|
|
298
|
+
return promise;
|
|
299
|
+
}
|
|
300
|
+
let timer = null;
|
|
301
|
+
try {
|
|
302
|
+
return await Promise.race([
|
|
303
|
+
promise,
|
|
304
|
+
new Promise((_, reject) => {
|
|
305
|
+
timer = setTimeout(() => reject(new Error('timeout')), timeoutMs);
|
|
306
|
+
})
|
|
307
|
+
]);
|
|
308
|
+
} finally {
|
|
309
|
+
if (timer) {
|
|
310
|
+
clearTimeout(timer);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
try {
|
|
315
|
+
const res = await withTimeout(api('get-claude-settings'), configLoadTimeoutMs);
|
|
316
|
+
if (res && res.error) {
|
|
317
|
+
if (!silent) {
|
|
318
|
+
this.showMessage('读取配置失败', 'error');
|
|
319
|
+
}
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const matchName = this.matchClaudeConfigFromSettings((res && res.env) || {});
|
|
323
|
+
if (matchName) {
|
|
324
|
+
if (this.currentClaudeConfig !== matchName) {
|
|
325
|
+
this.currentClaudeConfig = matchName;
|
|
326
|
+
try { localStorage.setItem('currentClaudeConfig', matchName); } catch (_) {}
|
|
327
|
+
}
|
|
328
|
+
this.refreshClaudeModelContext({ silentError: silentModelError });
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const importedName = this.ensureClaudeConfigFromSettings((res && res.env) || {});
|
|
332
|
+
if (importedName) {
|
|
333
|
+
if (this.currentClaudeConfig !== importedName) {
|
|
334
|
+
this.currentClaudeConfig = importedName;
|
|
335
|
+
try { localStorage.setItem('currentClaudeConfig', importedName); } catch (_) {}
|
|
336
|
+
}
|
|
337
|
+
this.refreshClaudeModelContext({ silentError: silentModelError });
|
|
338
|
+
if (!silent) {
|
|
339
|
+
this.showMessage(`检测到外部 Claude 配置,已自动导入:${importedName}`, 'success');
|
|
340
|
+
}
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
{
|
|
344
|
+
const configNames = Object.keys(this.claudeConfigs || {});
|
|
345
|
+
const current = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
|
|
346
|
+
const fallback = current && this.claudeConfigs && this.claudeConfigs[current]
|
|
347
|
+
? current
|
|
348
|
+
: (configNames[0] || '');
|
|
349
|
+
if (!fallback) {
|
|
350
|
+
this.currentClaudeConfig = '';
|
|
351
|
+
try { localStorage.setItem('currentClaudeConfig', ''); } catch (_) {}
|
|
352
|
+
this.currentClaudeModel = '';
|
|
353
|
+
this.resetClaudeModelsState();
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (this.currentClaudeConfig !== fallback) {
|
|
357
|
+
this.currentClaudeConfig = fallback;
|
|
358
|
+
try { localStorage.setItem('currentClaudeConfig', fallback); } catch (_) {}
|
|
359
|
+
}
|
|
360
|
+
this.refreshClaudeModelContext({ silentError: silentModelError });
|
|
361
|
+
}
|
|
362
|
+
} catch (e) {
|
|
363
|
+
if (!silent) {
|
|
364
|
+
this.showMessage(e && e.message === 'timeout' ? '读取配置超时' : '读取配置失败', 'error');
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
this._refreshClaudeSelectionPromise = Promise.resolve(run())
|
|
370
|
+
.finally(() => {
|
|
371
|
+
this._refreshClaudeSelectionPromise = null;
|
|
372
|
+
});
|
|
373
|
+
await this._refreshClaudeSelectionPromise;
|
|
374
|
+
const pending = this._refreshClaudeSelectionPendingOptions;
|
|
375
|
+
this._refreshClaudeSelectionPendingOptions = null;
|
|
376
|
+
if (pending) {
|
|
377
|
+
return this.refreshClaudeSelectionFromSettings(pending);
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
syncClaudeModelFromConfig() {
|
|
382
|
+
const config = this.getCurrentClaudeConfig();
|
|
383
|
+
this.currentClaudeModel = config && config.model ? config.model : '';
|
|
384
|
+
this.claudeCustomModelDraft = this.currentClaudeModel;
|
|
385
|
+
},
|
|
386
|
+
|
|
387
|
+
refreshClaudeModelContext(options = {}) {
|
|
388
|
+
this.syncClaudeModelFromConfig();
|
|
389
|
+
return this.loadClaudeModels(options);
|
|
390
|
+
},
|
|
391
|
+
|
|
392
|
+
resetClaudeModelsState() {
|
|
393
|
+
this.claudeModels = [];
|
|
394
|
+
this.claudeModelsSource = 'idle';
|
|
395
|
+
this.claudeModelsHasCurrent = true;
|
|
396
|
+
this.claudeModelsLoading = false;
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
updateClaudeModelsCurrent() {
|
|
400
|
+
const currentModel = (this.currentClaudeModel || '').trim();
|
|
401
|
+
this.claudeModelsHasCurrent = !!currentModel && this.claudeModels.includes(currentModel);
|
|
402
|
+
},
|
|
403
|
+
|
|
404
|
+
async loadClaudeModels(options = {}) {
|
|
405
|
+
const config = this.getCurrentClaudeConfig();
|
|
406
|
+
const requestSeq = (Number(this.claudeModelsRequestSeq) || 0) + 1;
|
|
407
|
+
this.claudeModelsRequestSeq = requestSeq;
|
|
408
|
+
if (!config) {
|
|
409
|
+
this.resetClaudeModelsState();
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const currentConfigName = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
|
|
413
|
+
const baseUrl = (config.baseUrl || '').trim();
|
|
414
|
+
const apiKey = (config.apiKey || '').trim();
|
|
415
|
+
const externalCredentialType = typeof config.externalCredentialType === 'string'
|
|
416
|
+
? config.externalCredentialType.trim()
|
|
417
|
+
: '';
|
|
418
|
+
|
|
419
|
+
if (!baseUrl) {
|
|
420
|
+
this.resetClaudeModelsState();
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const localCatalog = getClaudeModelCatalogForBaseUrl(baseUrl);
|
|
424
|
+
if (!apiKey && externalCredentialType) {
|
|
425
|
+
this.claudeModels = localCatalog;
|
|
426
|
+
this.claudeModelsSource = localCatalog.length ? 'catalog' : 'unlimited';
|
|
427
|
+
if (localCatalog.length) {
|
|
428
|
+
this.updateClaudeModelsCurrent();
|
|
429
|
+
} else {
|
|
430
|
+
this.claudeModelsHasCurrent = true;
|
|
431
|
+
}
|
|
432
|
+
this.claudeModelsLoading = false;
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const cache = typeof globalThis !== 'undefined'
|
|
437
|
+
? (globalThis.__codexmateClaudeModelsCache || (globalThis.__codexmateClaudeModelsCache = new Map()))
|
|
438
|
+
: new Map();
|
|
439
|
+
const cacheKey = baseUrl;
|
|
440
|
+
const ttlMs = 2 * 60 * 1000;
|
|
441
|
+
const now = Date.now();
|
|
442
|
+
const cached = cache.get(cacheKey);
|
|
443
|
+
const cachedOk = cached
|
|
444
|
+
&& Number.isFinite(cached.ts)
|
|
445
|
+
&& now - cached.ts < ttlMs
|
|
446
|
+
&& Array.isArray(cached.models);
|
|
447
|
+
if (cachedOk) {
|
|
448
|
+
this.claudeModels = cached.models;
|
|
449
|
+
this.claudeModelsSource = cached.source || 'remote';
|
|
450
|
+
if (this.claudeModels.length) {
|
|
451
|
+
this.updateClaudeModelsCurrent();
|
|
452
|
+
} else {
|
|
453
|
+
this.claudeModelsHasCurrent = true;
|
|
454
|
+
}
|
|
455
|
+
this.claudeModelsLoading = false;
|
|
456
|
+
} else if (localCatalog.length) {
|
|
457
|
+
this.claudeModels = localCatalog;
|
|
458
|
+
this.claudeModelsSource = 'catalog';
|
|
459
|
+
this.updateClaudeModelsCurrent();
|
|
460
|
+
this.claudeModelsLoading = false;
|
|
461
|
+
}
|
|
462
|
+
const isLatestRequest = () => {
|
|
463
|
+
if (requestSeq !== Number(this.claudeModelsRequestSeq || 0)) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
const liveConfigName = typeof this.currentClaudeConfig === 'string' ? this.currentClaudeConfig.trim() : '';
|
|
467
|
+
if (currentConfigName && liveConfigName && liveConfigName !== currentConfigName) {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
const latestConfig = this.getCurrentClaudeConfig();
|
|
471
|
+
if (!latestConfig) {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
return (latestConfig.baseUrl || '').trim() === baseUrl
|
|
475
|
+
&& (latestConfig.apiKey || '').trim() === apiKey
|
|
476
|
+
&& (typeof latestConfig.externalCredentialType === 'string' ? latestConfig.externalCredentialType.trim() : '') === externalCredentialType;
|
|
477
|
+
};
|
|
478
|
+
if (cachedOk) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
try {
|
|
482
|
+
const res = await api('models-by-url', { baseUrl, apiKey });
|
|
483
|
+
if (!isLatestRequest()) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
if (res.unlimited) {
|
|
487
|
+
this.claudeModels = [];
|
|
488
|
+
this.claudeModelsSource = 'unlimited';
|
|
489
|
+
this.claudeModelsHasCurrent = true;
|
|
490
|
+
cache.set(cacheKey, { ts: Date.now(), models: [], source: 'unlimited' });
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (res.error) {
|
|
494
|
+
this.claudeModels = [];
|
|
495
|
+
this.claudeModelsSource = 'error';
|
|
496
|
+
this.claudeModelsHasCurrent = true;
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const list = Array.isArray(res.models) ? res.models : [];
|
|
500
|
+
this.claudeModels = list;
|
|
501
|
+
this.claudeModelsSource = res.source || 'remote';
|
|
502
|
+
this.updateClaudeModelsCurrent();
|
|
503
|
+
cache.set(cacheKey, { ts: Date.now(), models: list, source: this.claudeModelsSource });
|
|
504
|
+
} catch (_) {
|
|
505
|
+
if (!isLatestRequest()) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
this.claudeModels = [];
|
|
509
|
+
this.claudeModelsSource = 'error';
|
|
510
|
+
this.claudeModelsHasCurrent = true;
|
|
511
|
+
} finally {
|
|
512
|
+
if (requestSeq === Number(this.claudeModelsRequestSeq || 0)) {
|
|
513
|
+
this.claudeModelsLoading = false;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
|
|
518
|
+
openClaudeConfigModal() {
|
|
519
|
+
this.showClaudeConfigModal = true;
|
|
520
|
+
},
|
|
521
|
+
|
|
522
|
+
maybeShowStarPrompt() {
|
|
523
|
+
const storageKey = 'codexmateStarPrompted';
|
|
524
|
+
try {
|
|
525
|
+
if (!localStorage.getItem(storageKey)) {
|
|
526
|
+
localStorage.setItem(storageKey, '1');
|
|
527
|
+
}
|
|
528
|
+
} catch (_) {
|
|
529
|
+
// Ignore storage failures silently. The startup UI should not show
|
|
530
|
+
// promotional prompts or block normal configuration work.
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
}
|