codexmate 0.0.18 → 0.0.20

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 (73) hide show
  1. package/README.en.md +34 -17
  2. package/README.md +34 -25
  3. package/cli/config-health.js +338 -0
  4. package/cli.js +1570 -839
  5. package/lib/cli-models-utils.js +186 -27
  6. package/lib/cli-network-utils.js +117 -101
  7. package/package.json +8 -1
  8. package/web-ui/app.js +379 -5754
  9. package/web-ui/index.html +15 -2079
  10. package/web-ui/logic.agents-diff.mjs +386 -0
  11. package/web-ui/logic.claude.mjs +108 -0
  12. package/web-ui/logic.mjs +5 -793
  13. package/web-ui/logic.runtime.mjs +124 -0
  14. package/web-ui/logic.sessions.mjs +263 -0
  15. package/web-ui/modules/api.mjs +69 -0
  16. package/web-ui/modules/app.computed.dashboard.mjs +113 -0
  17. package/web-ui/modules/app.computed.index.mjs +13 -0
  18. package/web-ui/modules/app.computed.session.mjs +141 -0
  19. package/web-ui/modules/app.constants.mjs +15 -0
  20. package/web-ui/modules/app.methods.agents.mjs +493 -0
  21. package/web-ui/modules/app.methods.claude-config.mjs +174 -0
  22. package/web-ui/modules/app.methods.codex-config.mjs +640 -0
  23. package/web-ui/modules/app.methods.index.mjs +86 -0
  24. package/web-ui/modules/app.methods.install.mjs +157 -0
  25. package/web-ui/modules/app.methods.navigation.mjs +478 -0
  26. package/web-ui/modules/app.methods.openclaw-core.mjs +514 -0
  27. package/web-ui/modules/app.methods.openclaw-editing.mjs +337 -0
  28. package/web-ui/modules/app.methods.openclaw-persist.mjs +251 -0
  29. package/web-ui/modules/app.methods.providers.mjs +265 -0
  30. package/web-ui/modules/app.methods.runtime.mjs +323 -0
  31. package/web-ui/modules/app.methods.session-actions.mjs +457 -0
  32. package/web-ui/modules/app.methods.session-browser.mjs +435 -0
  33. package/web-ui/modules/app.methods.session-timeline.mjs +441 -0
  34. package/web-ui/modules/app.methods.session-trash.mjs +419 -0
  35. package/web-ui/modules/app.methods.startup-claude.mjs +406 -0
  36. package/web-ui/modules/config-mode.computed.mjs +1 -0
  37. package/web-ui/modules/skills.computed.mjs +26 -1
  38. package/web-ui/modules/skills.methods.mjs +154 -23
  39. package/web-ui/partials/index/layout-footer.html +69 -0
  40. package/web-ui/partials/index/layout-header.html +337 -0
  41. package/web-ui/partials/index/modal-config-template-agents.html +125 -0
  42. package/web-ui/partials/index/modal-confirm-toast.html +32 -0
  43. package/web-ui/partials/index/modal-health-check.html +72 -0
  44. package/web-ui/partials/index/modal-openclaw-config.html +275 -0
  45. package/web-ui/partials/index/modal-skills.html +184 -0
  46. package/web-ui/partials/index/modals-basic.html +196 -0
  47. package/web-ui/partials/index/panel-config-claude.html +100 -0
  48. package/web-ui/partials/index/panel-config-codex.html +237 -0
  49. package/web-ui/partials/index/panel-config-openclaw.html +84 -0
  50. package/web-ui/partials/index/panel-market.html +174 -0
  51. package/web-ui/partials/index/panel-sessions.html +387 -0
  52. package/web-ui/partials/index/panel-settings.html +166 -0
  53. package/web-ui/session-helpers.mjs +12 -0
  54. package/web-ui/source-bundle.cjs +233 -0
  55. package/web-ui/styles/base-theme.css +373 -0
  56. package/web-ui/styles/controls-forms.css +354 -0
  57. package/web-ui/styles/feedback.css +108 -0
  58. package/web-ui/styles/health-check-dialog.css +144 -0
  59. package/web-ui/styles/layout-shell.css +330 -0
  60. package/web-ui/styles/modals-core.css +449 -0
  61. package/web-ui/styles/navigation-panels.css +381 -0
  62. package/web-ui/styles/openclaw-structured.css +266 -0
  63. package/web-ui/styles/responsive.css +416 -0
  64. package/web-ui/styles/sessions-list.css +414 -0
  65. package/web-ui/styles/sessions-preview.css +405 -0
  66. package/web-ui/styles/sessions-toolbar-trash.css +243 -0
  67. package/web-ui/styles/sessions-usage.css +276 -0
  68. package/web-ui/styles/skills-list.css +298 -0
  69. package/web-ui/styles/skills-market.css +335 -0
  70. package/web-ui/styles/titles-cards.css +407 -0
  71. package/web-ui/styles.css +16 -4499
  72. package/doc/CHANGELOG.md +0 -32
  73. package/doc/CHANGELOG.zh-CN.md +0 -34
@@ -0,0 +1,514 @@
1
+ export function createOpenclawCoreMethods() {
2
+ return {
3
+ getOpenclawParser() {
4
+ const globalWindow = typeof window !== 'undefined' ? window : null;
5
+ if (globalWindow && globalWindow.JSON5
6
+ && typeof globalWindow.JSON5.parse === 'function'
7
+ && typeof globalWindow.JSON5.stringify === 'function') {
8
+ return {
9
+ parse: globalWindow.JSON5.parse,
10
+ stringify: globalWindow.JSON5.stringify
11
+ };
12
+ }
13
+ return {
14
+ parse: JSON.parse,
15
+ stringify: JSON.stringify
16
+ };
17
+ },
18
+
19
+ parseOpenclawContent(content, options = {}) {
20
+ const allowEmpty = !!options.allowEmpty;
21
+ const raw = typeof content === 'string' ? content.trim() : '';
22
+ if (!raw) {
23
+ if (allowEmpty) {
24
+ return { ok: true, data: {} };
25
+ }
26
+ return { ok: false, error: '配置内容为空' };
27
+ }
28
+ try {
29
+ const parser = this.getOpenclawParser();
30
+ const data = parser.parse(raw);
31
+ if (!data || typeof data !== 'object' || Array.isArray(data)) {
32
+ return { ok: false, error: '配置格式错误(根节点必须是对象)' };
33
+ }
34
+ return { ok: true, data };
35
+ } catch (e) {
36
+ return { ok: false, error: e.message || '解析失败' };
37
+ }
38
+ },
39
+
40
+ stringifyOpenclawConfig(data) {
41
+ const parser = this.getOpenclawParser();
42
+ try {
43
+ return parser.stringify(data, null, 2);
44
+ } catch (e) {
45
+ return JSON.stringify(data, null, 2);
46
+ }
47
+ },
48
+
49
+ resetOpenclawStructured() {
50
+ this.openclawStructured = {
51
+ agentPrimary: '',
52
+ agentFallbacks: [''],
53
+ workspace: '',
54
+ timeout: '',
55
+ contextTokens: '',
56
+ maxConcurrent: '',
57
+ envItems: [{ key: '', value: '', show: false }],
58
+ toolsProfile: 'default',
59
+ toolsAllow: [''],
60
+ toolsDeny: ['']
61
+ };
62
+ this.openclawAgentsList = [];
63
+ this.openclawProviders = [];
64
+ this.openclawMissingProviders = [];
65
+ },
66
+
67
+ getOpenclawQuickDefaults() {
68
+ return {
69
+ providerName: '',
70
+ baseUrl: '',
71
+ apiKey: '',
72
+ apiType: 'openai-responses',
73
+ modelId: '',
74
+ modelName: '',
75
+ contextWindow: '',
76
+ maxTokens: '',
77
+ setPrimary: true,
78
+ overrideProvider: true,
79
+ overrideModels: true,
80
+ showKey: false
81
+ };
82
+ },
83
+
84
+ resetOpenclawQuick() {
85
+ this.openclawQuick = this.getOpenclawQuickDefaults();
86
+ },
87
+
88
+ toggleOpenclawQuickKey() {
89
+ this.openclawQuick.showKey = !this.openclawQuick.showKey;
90
+ },
91
+
92
+ fillOpenclawQuickFromConfig(config) {
93
+ const defaults = this.getOpenclawQuickDefaults();
94
+ if (!config || typeof config !== 'object' || Array.isArray(config)) {
95
+ this.openclawQuick = defaults;
96
+ return;
97
+ }
98
+
99
+ const agentDefaults = config.agents && typeof config.agents === 'object' && !Array.isArray(config.agents)
100
+ && config.agents.defaults && typeof config.agents.defaults === 'object' && !Array.isArray(config.agents.defaults)
101
+ ? config.agents.defaults
102
+ : {};
103
+ const modelConfig = agentDefaults.model;
104
+ const legacyAgent = config.agent && typeof config.agent === 'object' && !Array.isArray(config.agent)
105
+ ? config.agent
106
+ : {};
107
+
108
+ let primaryRef = '';
109
+ if (modelConfig && typeof modelConfig === 'object' && !Array.isArray(modelConfig) && typeof modelConfig.primary === 'string') {
110
+ primaryRef = modelConfig.primary;
111
+ } else if (typeof modelConfig === 'string') {
112
+ primaryRef = modelConfig;
113
+ }
114
+ if (!primaryRef) {
115
+ if (typeof legacyAgent.model === 'string') {
116
+ primaryRef = legacyAgent.model;
117
+ } else if (legacyAgent.model && typeof legacyAgent.model === 'object' && typeof legacyAgent.model.primary === 'string') {
118
+ primaryRef = legacyAgent.model.primary;
119
+ }
120
+ }
121
+
122
+ let providerName = '';
123
+ let modelId = '';
124
+ if (primaryRef) {
125
+ const parts = primaryRef.split('/');
126
+ if (parts.length >= 2) {
127
+ providerName = parts.shift().trim();
128
+ modelId = parts.join('/').trim();
129
+ }
130
+ }
131
+
132
+ const providers = config.models && typeof config.models === 'object' && !Array.isArray(config.models)
133
+ && config.models.providers && typeof config.models.providers === 'object' && !Array.isArray(config.models.providers)
134
+ ? config.models.providers
135
+ : null;
136
+ let providerConfig = providerName && providers ? providers[providerName] : null;
137
+ if (!providerName && providers) {
138
+ const providerKeys = Object.keys(providers);
139
+ if (providerKeys.length === 1) {
140
+ providerName = providerKeys[0];
141
+ providerConfig = providers[providerName];
142
+ }
143
+ }
144
+
145
+ let modelEntry = null;
146
+ if (providerConfig && typeof providerConfig === 'object' && Array.isArray(providerConfig.models)) {
147
+ if (modelId) {
148
+ modelEntry = providerConfig.models.find(item => item && item.id === modelId);
149
+ }
150
+ if (!modelEntry && providerConfig.models.length === 1) {
151
+ modelEntry = providerConfig.models[0];
152
+ if (!modelId && modelEntry && typeof modelEntry.id === 'string') {
153
+ modelId = modelEntry.id;
154
+ }
155
+ }
156
+ }
157
+
158
+ const baseUrl = providerConfig && typeof providerConfig === 'object' && typeof providerConfig.baseUrl === 'string'
159
+ ? providerConfig.baseUrl
160
+ : '';
161
+ const apiKey = providerConfig && typeof providerConfig === 'object' && typeof providerConfig.apiKey === 'string'
162
+ ? providerConfig.apiKey
163
+ : '';
164
+ const apiType = providerConfig && typeof providerConfig === 'object' && typeof providerConfig.api === 'string'
165
+ ? providerConfig.api
166
+ : defaults.apiType;
167
+
168
+ this.openclawQuick = {
169
+ ...defaults,
170
+ providerName,
171
+ baseUrl,
172
+ apiKey,
173
+ apiType,
174
+ modelId: modelId || '',
175
+ modelName: modelEntry && typeof modelEntry.name === 'string' ? modelEntry.name : '',
176
+ contextWindow: modelEntry && typeof modelEntry.contextWindow === 'number'
177
+ ? String(modelEntry.contextWindow)
178
+ : '',
179
+ maxTokens: modelEntry && typeof modelEntry.maxTokens === 'number'
180
+ ? String(modelEntry.maxTokens)
181
+ : ''
182
+ };
183
+ },
184
+
185
+ syncOpenclawQuickFromText(options = {}) {
186
+ const silent = !!options.silent;
187
+ const parsed = this.parseOpenclawContent(this.openclawEditing.content, { allowEmpty: true });
188
+ if (!parsed.ok) {
189
+ this.resetOpenclawQuick();
190
+ if (!silent) {
191
+ this.showMessage('解析 OpenClaw 配置失败: ' + parsed.error, 'error');
192
+ }
193
+ return false;
194
+ }
195
+ this.fillOpenclawQuickFromConfig(parsed.data);
196
+ if (!silent) {
197
+ this.showMessage('已读取配置', 'success');
198
+ }
199
+ return true;
200
+ },
201
+
202
+ mergeOpenclawModelEntry(existing, incoming, overwrite = false) {
203
+ if (!existing || typeof existing !== 'object' || Array.isArray(existing)) {
204
+ return { ...incoming };
205
+ }
206
+ if (overwrite) {
207
+ return { ...incoming };
208
+ }
209
+ const merged = { ...existing };
210
+ for (const [key, value] of Object.entries(incoming || {})) {
211
+ if (merged[key] === undefined || merged[key] === null || merged[key] === '') {
212
+ merged[key] = value;
213
+ }
214
+ }
215
+ return merged;
216
+ },
217
+
218
+ fillOpenclawStructured(config) {
219
+ const defaults = config && config.agents && typeof config.agents === 'object' && !Array.isArray(config.agents)
220
+ && config.agents.defaults && typeof config.agents.defaults === 'object' && !Array.isArray(config.agents.defaults)
221
+ ? config.agents.defaults
222
+ : {};
223
+ const model = defaults.model && typeof defaults.model === 'object' && !Array.isArray(defaults.model)
224
+ ? defaults.model
225
+ : {};
226
+ const legacyAgent = config && config.agent && typeof config.agent === 'object' && !Array.isArray(config.agent)
227
+ ? config.agent
228
+ : {};
229
+ const fallbackSource = Array.isArray(model.fallbacks)
230
+ ? model.fallbacks
231
+ : (legacyAgent.model && typeof legacyAgent.model === 'object' && !Array.isArray(legacyAgent.model) && Array.isArray(legacyAgent.model.fallbacks)
232
+ ? legacyAgent.model.fallbacks
233
+ : []);
234
+ const fallbackList = fallbackSource
235
+ .filter(item => typeof item === 'string' && item.trim())
236
+ .map(item => item.trim());
237
+ const env = config && config.env && typeof config.env === 'object' && !Array.isArray(config.env)
238
+ ? config.env
239
+ : {};
240
+ const envItems = Object.entries(env).map(([key, value]) => ({
241
+ key,
242
+ value: value == null ? '' : String(value),
243
+ show: false
244
+ }));
245
+ const tools = config && config.tools && typeof config.tools === 'object' && !Array.isArray(config.tools)
246
+ ? config.tools
247
+ : {};
248
+
249
+ let primary = typeof model.primary === 'string' ? model.primary : '';
250
+ if (!primary) {
251
+ if (typeof legacyAgent.model === 'string') {
252
+ primary = legacyAgent.model;
253
+ } else if (legacyAgent.model && typeof legacyAgent.model === 'object' && typeof legacyAgent.model.primary === 'string') {
254
+ primary = legacyAgent.model.primary;
255
+ }
256
+ }
257
+
258
+ this.openclawStructured = {
259
+ agentPrimary: primary,
260
+ agentFallbacks: fallbackList.length ? fallbackList : [''],
261
+ workspace: typeof defaults.workspace === 'string' ? defaults.workspace : '',
262
+ timeout: typeof defaults.timeout === 'number' && Number.isFinite(defaults.timeout)
263
+ ? String(defaults.timeout)
264
+ : '',
265
+ contextTokens: typeof defaults.contextTokens === 'number' && Number.isFinite(defaults.contextTokens)
266
+ ? String(defaults.contextTokens)
267
+ : '',
268
+ maxConcurrent: typeof defaults.maxConcurrent === 'number' && Number.isFinite(defaults.maxConcurrent)
269
+ ? String(defaults.maxConcurrent)
270
+ : '',
271
+ envItems: envItems.length ? envItems : [{ key: '', value: '', show: false }],
272
+ toolsProfile: typeof tools.profile === 'string' && tools.profile.trim() ? tools.profile : 'default',
273
+ toolsAllow: Array.isArray(tools.allow) && tools.allow.length
274
+ ? tools.allow.filter(item => typeof item === 'string' && item.trim()).map(item => item.trim())
275
+ : [''],
276
+ toolsDeny: Array.isArray(tools.deny) && tools.deny.length
277
+ ? tools.deny.filter(item => typeof item === 'string' && item.trim()).map(item => item.trim())
278
+ : ['']
279
+ };
280
+ },
281
+
282
+ syncOpenclawStructuredFromText(options = {}) {
283
+ const silent = !!options.silent;
284
+ const parsed = this.parseOpenclawContent(this.openclawEditing.content, { allowEmpty: true });
285
+ if (!parsed.ok) {
286
+ this.resetOpenclawStructured();
287
+ this.resetOpenclawQuick();
288
+ if (!silent) {
289
+ this.showMessage('解析 OpenClaw 配置失败: ' + parsed.error, 'error');
290
+ }
291
+ return false;
292
+ }
293
+ this.fillOpenclawStructured(parsed.data);
294
+ this.fillOpenclawQuickFromConfig(parsed.data);
295
+ this.refreshOpenclawProviders(parsed.data);
296
+ this.refreshOpenclawAgentsList(parsed.data);
297
+ if (!silent) {
298
+ this.showMessage('已刷新配置', 'success');
299
+ }
300
+ return true;
301
+ },
302
+
303
+ getOpenclawActiveProviders(config) {
304
+ const active = new Set();
305
+ const addProvider = (ref) => {
306
+ if (typeof ref !== 'string') return;
307
+ const text = ref.trim();
308
+ if (!text) return;
309
+ const parts = text.split('/');
310
+ if (parts.length < 2) return;
311
+ const provider = parts[0].trim();
312
+ if (provider) active.add(provider);
313
+ };
314
+ const defaults = config && config.agents && config.agents.defaults
315
+ ? config.agents.defaults
316
+ : {};
317
+ const model = defaults && defaults.model;
318
+ if (model && typeof model === 'object' && !Array.isArray(model)) {
319
+ addProvider(model.primary);
320
+ if (Array.isArray(model.fallbacks)) {
321
+ for (const item of model.fallbacks) {
322
+ addProvider(item);
323
+ }
324
+ }
325
+ } else if (typeof model === 'string') {
326
+ addProvider(model);
327
+ }
328
+ const legacyAgent = config && config.agent && typeof config.agent === 'object' && !Array.isArray(config.agent)
329
+ ? config.agent
330
+ : {};
331
+ if (typeof legacyAgent.model === 'string') {
332
+ addProvider(legacyAgent.model);
333
+ } else if (legacyAgent.model && typeof legacyAgent.model === 'object' && !Array.isArray(legacyAgent.model)) {
334
+ addProvider(legacyAgent.model.primary);
335
+ if (Array.isArray(legacyAgent.model.fallbacks)) {
336
+ for (const item of legacyAgent.model.fallbacks) {
337
+ addProvider(item);
338
+ }
339
+ }
340
+ }
341
+ const modelsDefaults = config && config.models && config.models.defaults
342
+ ? config.models.defaults
343
+ : {};
344
+ if (modelsDefaults && typeof modelsDefaults.provider === 'string' && modelsDefaults.provider.trim()) {
345
+ active.add(modelsDefaults.provider.trim());
346
+ }
347
+ if (modelsDefaults && typeof modelsDefaults.model === 'string') {
348
+ addProvider(modelsDefaults.model);
349
+ }
350
+ return active;
351
+ },
352
+
353
+ maskProviderValue(value) {
354
+ const text = value == null ? '' : String(value);
355
+ if (!text) return '****';
356
+ if (text.length <= 6) return '****';
357
+ return `${text.slice(0, 3)}****${text.slice(-3)}`;
358
+ },
359
+
360
+ formatProviderValue(key, value) {
361
+ if (typeof value === 'undefined' || value === null) {
362
+ return '';
363
+ }
364
+ let text = '';
365
+ if (typeof value === 'string') {
366
+ text = value;
367
+ } else if (typeof value === 'number' || typeof value === 'boolean') {
368
+ text = String(value);
369
+ } else {
370
+ try {
371
+ text = JSON.stringify(value);
372
+ } catch (_) {
373
+ text = String(value);
374
+ }
375
+ }
376
+ if (!text) return '';
377
+ if (/key|token|secret|password/i.test(key)) {
378
+ return this.maskProviderValue(text);
379
+ }
380
+ if (text.length > 160) {
381
+ return `${text.slice(0, 157)}...`;
382
+ }
383
+ return text;
384
+ },
385
+
386
+ collectOpenclawProviders(source, providerMap, activeProviders, entries) {
387
+ if (!providerMap || typeof providerMap !== 'object' || Array.isArray(providerMap)) {
388
+ return;
389
+ }
390
+ const keys = Object.keys(providerMap).sort();
391
+ for (const key of keys) {
392
+ const value = providerMap[key];
393
+ const fields = [];
394
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
395
+ const fieldKeys = Object.keys(value).sort();
396
+ for (const fieldKey of fieldKeys) {
397
+ const fieldValue = this.formatProviderValue(fieldKey, value[fieldKey]);
398
+ if (fieldValue === '') continue;
399
+ fields.push({ key: fieldKey, value: fieldValue });
400
+ }
401
+ } else {
402
+ const fieldValue = this.formatProviderValue('value', value);
403
+ if (fieldValue !== '') {
404
+ fields.push({ key: 'value', value: fieldValue });
405
+ }
406
+ }
407
+ entries.push({
408
+ key,
409
+ source,
410
+ fields,
411
+ isActive: activeProviders.has(key)
412
+ });
413
+ }
414
+ },
415
+
416
+ refreshOpenclawProviders(config) {
417
+ const activeProviders = this.getOpenclawActiveProviders(config || {});
418
+ const entries = [];
419
+ const modelsProviders = config && config.models ? config.models.providers : null;
420
+ const rootProviders = config && config.providers ? config.providers : null;
421
+ this.collectOpenclawProviders('models.providers', modelsProviders, activeProviders, entries);
422
+ this.collectOpenclawProviders('providers', rootProviders, activeProviders, entries);
423
+ const existing = new Set(entries.map(item => item.key));
424
+ const missing = [];
425
+ for (const provider of activeProviders) {
426
+ if (!existing.has(provider)) {
427
+ missing.push(provider);
428
+ }
429
+ }
430
+ this.openclawProviders = entries;
431
+ this.openclawMissingProviders = missing;
432
+ },
433
+
434
+ refreshOpenclawAgentsList(config) {
435
+ const list = config && config.agents && typeof config.agents === 'object' && !Array.isArray(config.agents)
436
+ ? config.agents.list
437
+ : null;
438
+ if (!Array.isArray(list)) {
439
+ this.openclawAgentsList = [];
440
+ return;
441
+ }
442
+ const entries = [];
443
+ list.forEach((item, index) => {
444
+ if (!item || typeof item !== 'object') return;
445
+ const id = typeof item.id === 'string' && item.id.trim() ? item.id.trim() : `agent-${index + 1}`;
446
+ const identity = item.identity && typeof item.identity === 'object' && !Array.isArray(item.identity)
447
+ ? item.identity
448
+ : {};
449
+ const name = typeof identity.name === 'string' && identity.name.trim()
450
+ ? identity.name.trim()
451
+ : id;
452
+ entries.push({
453
+ key: `${id}-${index}`,
454
+ id,
455
+ name,
456
+ theme: typeof identity.theme === 'string' ? identity.theme : '',
457
+ emoji: typeof identity.emoji === 'string' ? identity.emoji : '',
458
+ avatar: typeof identity.avatar === 'string' ? identity.avatar : ''
459
+ });
460
+ });
461
+ this.openclawAgentsList = entries;
462
+ },
463
+
464
+ normalizeStringList(list) {
465
+ if (!Array.isArray(list)) return [];
466
+ const result = [];
467
+ const seen = new Set();
468
+ for (const item of list) {
469
+ const value = typeof item === 'string' ? item.trim() : String(item || '').trim();
470
+ if (!value) continue;
471
+ const key = value;
472
+ if (seen.has(key)) continue;
473
+ seen.add(key);
474
+ result.push(value);
475
+ }
476
+ return result;
477
+ },
478
+
479
+ normalizeEnvItems(items) {
480
+ if (!Array.isArray(items)) {
481
+ return { ok: true, items: {} };
482
+ }
483
+ const output = {};
484
+ const seen = new Set();
485
+ for (const item of items) {
486
+ const key = item && typeof item.key === 'string' ? item.key.trim() : '';
487
+ if (!key) continue;
488
+ if (seen.has(key)) {
489
+ return { ok: false, error: `环境变量重复: ${key}` };
490
+ }
491
+ seen.add(key);
492
+ const value = item && typeof item.value !== 'undefined' ? String(item.value) : '';
493
+ output[key] = value;
494
+ }
495
+ return { ok: true, items: output };
496
+ },
497
+
498
+ parseOptionalNumber(value, label) {
499
+ const text = typeof value === 'string'
500
+ ? value.trim()
501
+ : typeof value === 'number'
502
+ ? String(value).trim()
503
+ : String(value || '').trim();
504
+ if (!text) {
505
+ return { ok: true, value: null };
506
+ }
507
+ const num = Number(text);
508
+ if (!Number.isFinite(num) || num < 0) {
509
+ return { ok: false, error: `${label} 请输入有效数字` };
510
+ }
511
+ return { ok: true, value: num };
512
+ }
513
+ };
514
+ }