codexmate 0.0.21 → 0.0.22

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 (114) hide show
  1. package/README.md +389 -284
  2. package/README.zh.md +321 -0
  3. package/cli/agents-files.js +224 -162
  4. package/cli/archive-helpers.js +446 -446
  5. package/cli/auth-profiles.js +359 -359
  6. package/cli/builtin-proxy.js +1044 -580
  7. package/cli/claude-proxy.js +998 -998
  8. package/cli/config-bootstrap.js +384 -384
  9. package/cli/config-health.js +338 -338
  10. package/cli/openai-bridge.js +950 -0
  11. package/cli/openclaw-config.js +629 -629
  12. package/cli/session-usage.concurrent.js +28 -0
  13. package/cli/session-usage.js +112 -0
  14. package/cli/session-usage.models.js +176 -0
  15. package/cli/skills.js +1141 -1141
  16. package/cli/zip-commands.js +510 -510
  17. package/cli.js +13214 -13129
  18. package/lib/cli-file-utils.js +151 -151
  19. package/lib/cli-models-utils.js +419 -419
  20. package/lib/cli-network-utils.js +164 -164
  21. package/lib/cli-path-utils.js +69 -69
  22. package/lib/cli-session-utils.js +121 -121
  23. package/lib/cli-sessions.js +386 -386
  24. package/lib/cli-utils.js +155 -155
  25. package/lib/download-artifacts.js +77 -77
  26. package/lib/mcp-stdio.js +440 -440
  27. package/lib/task-orchestrator.js +869 -869
  28. package/lib/text-diff.js +303 -303
  29. package/lib/workflow-engine.js +340 -340
  30. package/package.json +74 -74
  31. package/res/json5.min.js +1 -1
  32. package/res/logo.png +0 -0
  33. package/res/vue.global.prod.js +13 -13
  34. package/web-ui/app.js +575 -530
  35. package/web-ui/index.html +34 -33
  36. package/web-ui/logic.agents-diff.mjs +386 -386
  37. package/web-ui/logic.claude.mjs +168 -168
  38. package/web-ui/logic.mjs +5 -5
  39. package/web-ui/logic.runtime.mjs +128 -124
  40. package/web-ui/logic.sessions.mjs +614 -581
  41. package/web-ui/modules/api.mjs +90 -90
  42. package/web-ui/modules/app.computed.dashboard.mjs +126 -113
  43. package/web-ui/modules/app.computed.index.mjs +17 -15
  44. package/web-ui/modules/app.computed.main-tabs.mjs +198 -195
  45. package/web-ui/modules/app.computed.session.mjs +653 -507
  46. package/web-ui/modules/app.constants.mjs +15 -15
  47. package/web-ui/modules/app.methods.agents.mjs +544 -493
  48. package/web-ui/modules/app.methods.claude-config.mjs +174 -174
  49. package/web-ui/modules/app.methods.codex-config.mjs +795 -640
  50. package/web-ui/modules/app.methods.index.mjs +92 -88
  51. package/web-ui/modules/app.methods.install.mjs +161 -149
  52. package/web-ui/modules/app.methods.navigation.mjs +619 -619
  53. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  54. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  55. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  56. package/web-ui/modules/app.methods.providers.mjs +404 -363
  57. package/web-ui/modules/app.methods.runtime.mjs +323 -323
  58. package/web-ui/modules/app.methods.session-actions.mjs +537 -520
  59. package/web-ui/modules/app.methods.session-browser.mjs +626 -626
  60. package/web-ui/modules/app.methods.session-timeline.mjs +448 -448
  61. package/web-ui/modules/app.methods.session-trash.mjs +422 -422
  62. package/web-ui/modules/app.methods.startup-claude.mjs +405 -412
  63. package/web-ui/modules/app.methods.task-orchestration.mjs +471 -471
  64. package/web-ui/modules/config-mode.computed.mjs +126 -126
  65. package/web-ui/modules/config-template-confirm-pref.mjs +33 -0
  66. package/web-ui/modules/i18n.mjs +1609 -0
  67. package/web-ui/modules/plugins.computed.mjs +220 -0
  68. package/web-ui/modules/plugins.methods.mjs +620 -0
  69. package/web-ui/modules/plugins.storage.mjs +37 -0
  70. package/web-ui/modules/skills.computed.mjs +107 -107
  71. package/web-ui/modules/skills.methods.mjs +481 -481
  72. package/web-ui/partials/index/layout-footer.html +13 -13
  73. package/web-ui/partials/index/layout-header.html +461 -402
  74. package/web-ui/partials/index/modal-config-template-agents.html +175 -125
  75. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  76. package/web-ui/partials/index/modal-health-check.html +72 -72
  77. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  78. package/web-ui/partials/index/modal-skills.html +200 -184
  79. package/web-ui/partials/index/modals-basic.html +165 -156
  80. package/web-ui/partials/index/panel-config-claude.html +138 -126
  81. package/web-ui/partials/index/panel-config-codex.html +234 -237
  82. package/web-ui/partials/index/panel-config-openclaw.html +78 -78
  83. package/web-ui/partials/index/panel-docs.html +147 -130
  84. package/web-ui/partials/index/panel-market.html +174 -174
  85. package/web-ui/partials/index/panel-orchestration.html +397 -397
  86. package/web-ui/partials/index/panel-plugins.html +243 -0
  87. package/web-ui/partials/index/panel-sessions.html +292 -292
  88. package/web-ui/partials/index/panel-settings.html +258 -190
  89. package/web-ui/partials/index/panel-usage.html +353 -213
  90. package/web-ui/session-helpers.mjs +573 -559
  91. package/web-ui/source-bundle.cjs +233 -233
  92. package/web-ui/styles/base-theme.css +264 -271
  93. package/web-ui/styles/controls-forms.css +362 -360
  94. package/web-ui/styles/docs-panel.css +247 -182
  95. package/web-ui/styles/feedback.css +108 -108
  96. package/web-ui/styles/health-check-dialog.css +144 -144
  97. package/web-ui/styles/layout-shell.css +596 -376
  98. package/web-ui/styles/modals-core.css +464 -464
  99. package/web-ui/styles/navigation-panels.css +382 -348
  100. package/web-ui/styles/openclaw-structured.css +266 -266
  101. package/web-ui/styles/plugins-panel.css +518 -0
  102. package/web-ui/styles/responsive.css +456 -450
  103. package/web-ui/styles/sessions-list.css +400 -400
  104. package/web-ui/styles/sessions-preview.css +411 -411
  105. package/web-ui/styles/sessions-toolbar-trash.css +268 -243
  106. package/web-ui/styles/sessions-usage.css +851 -628
  107. package/web-ui/styles/settings-panel.css +166 -0
  108. package/web-ui/styles/skills-list.css +303 -296
  109. package/web-ui/styles/skills-market.css +396 -335
  110. package/web-ui/styles/task-orchestration.css +776 -776
  111. package/web-ui/styles/titles-cards.css +408 -408
  112. package/web-ui/styles.css +20 -18
  113. package/web-ui.html +17 -17
  114. package/README.en.md +0 -349
@@ -1,481 +1,481 @@
1
- function createUnsupportedSkillsTargetAppError(app) {
2
- return new Error(`Unsupported skills target app: ${String(app)}`);
3
- }
4
-
5
- function showUnsupportedSkillsTargetMessage(vm, app) {
6
- vm.showMessage(`不支持的 Skills 安装目标:${String(app)}`, 'error');
7
- }
8
-
9
- export function createSkillsMethods({ api }) {
10
- return {
11
- normalizeSkillsTargetApp(app) {
12
- if (app == null) {
13
- return 'codex';
14
- }
15
- if (app === 'codex' || app === 'claude') {
16
- return app;
17
- }
18
- throw createUnsupportedSkillsTargetAppError(app);
19
- },
20
-
21
- resetSkillsTargetState() {
22
- this.skillsSelectedNames = [];
23
- this.skillsKeyword = '';
24
- this.skillsStatusFilter = 'all';
25
- this.skillsRootPath = '';
26
- this.skillsList = [];
27
- this.skillsImportList = [];
28
- this.skillsImportSelectedKeys = [];
29
- this.skillsMarketLocalLoadedOnce = false;
30
- this.skillsMarketImportLoadedOnce = false;
31
- },
32
-
33
- async setSkillsTargetApp(app, options = {}) {
34
- if (
35
- this.skillsLoading
36
- || this.skillsDeleting
37
- || this.skillsScanningImports
38
- || this.skillsImporting
39
- || this.skillsZipImporting
40
- || this.skillsExporting
41
- || this.skillsMarketLoading
42
- ) {
43
- return false;
44
- }
45
- let nextTarget;
46
- try {
47
- nextTarget = this.normalizeSkillsTargetApp(app);
48
- } catch (error) {
49
- showUnsupportedSkillsTargetMessage(this, app);
50
- return false;
51
- }
52
- const refresh = !(options && options.refresh === false);
53
- const silent = !!(options && options.silent);
54
- if (nextTarget !== this.skillsTargetApp) {
55
- this.skillsTargetApp = nextTarget;
56
- this.resetSkillsTargetState();
57
- }
58
- if (!refresh) {
59
- return true;
60
- }
61
- return await this.loadSkillsMarketOverview({
62
- forceRefresh: true,
63
- silent
64
- });
65
- },
66
-
67
- async openSkillsManager(options = {}) {
68
- if (
69
- this.skillsLoading
70
- || this.skillsDeleting
71
- || this.skillsScanningImports
72
- || this.skillsImporting
73
- || this.skillsZipImporting
74
- || this.skillsExporting
75
- || this.skillsMarketLoading
76
- ) {
77
- return false;
78
- }
79
- let targetApp;
80
- try {
81
- targetApp = this.normalizeSkillsTargetApp(options && options.targetApp ? options.targetApp : this.skillsTargetApp);
82
- } catch (error) {
83
- showUnsupportedSkillsTargetMessage(this, options && options.targetApp);
84
- return false;
85
- }
86
- const targetChanged = targetApp !== this.skillsTargetApp;
87
- if (targetChanged) {
88
- this.skillsTargetApp = targetApp;
89
- this.resetSkillsTargetState();
90
- } else {
91
- this.skillsSelectedNames = [];
92
- this.skillsKeyword = '';
93
- this.skillsStatusFilter = 'all';
94
- this.skillsImportSelectedKeys = [];
95
- }
96
- this.showSkillsModal = true;
97
- await this.refreshSkillsList({ silent: false });
98
- },
99
-
100
- closeSkillsModal() {
101
- const busy = !!(
102
- this.skillsLoading
103
- || this.skillsDeleting
104
- || this.skillsScanningImports
105
- || this.skillsImporting
106
- || this.skillsZipImporting
107
- || this.skillsExporting
108
- );
109
- if (busy) return;
110
- this.showSkillsModal = false;
111
- this.skillsSelectedNames = [];
112
- this.skillsImportSelectedKeys = [];
113
- },
114
-
115
- async refreshSkillsList(options = {}) {
116
- this.skillsLoading = true;
117
- try {
118
- const res = await api('list-skills', {
119
- targetApp: this.skillsTargetApp
120
- });
121
- if (res.error) {
122
- this.skillsRootPath = '';
123
- this.skillsList = [];
124
- this.skillsSelectedNames = [];
125
- this.showMessage(res.error, 'error');
126
- return false;
127
- }
128
- const exists = res.exists !== false;
129
- if (!exists) {
130
- this.skillsRootPath = res.root || '';
131
- this.skillsList = [];
132
- this.skillsSelectedNames = [];
133
- if (!options.silent) {
134
- this.showMessage(`${this.skillsTargetLabel} skills 目录不存在,已按空列表显示`, 'info');
135
- }
136
- return true;
137
- }
138
- this.skillsRootPath = res.root || '';
139
- this.skillsList = Array.isArray(res.items) ? res.items : [];
140
- const currentNames = new Set((Array.isArray(this.skillsList) ? this.skillsList : [])
141
- .map((item) => (item && typeof item.name === 'string' ? item.name.trim() : ''))
142
- .filter(Boolean));
143
- this.skillsSelectedNames = (Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : [])
144
- .filter((name) => currentNames.has(name));
145
- return true;
146
- } catch (e) {
147
- this.skillsRootPath = '';
148
- this.skillsList = [];
149
- this.skillsSelectedNames = [];
150
- this.showMessage('加载 skills 失败', 'error');
151
- return false;
152
- } finally {
153
- this.skillsLoading = false;
154
- }
155
- },
156
-
157
- async loadSkillsMarketOverview(options = {}) {
158
- if (this.skillsMarketLoading) return false;
159
- const silent = !!(options && options.silent);
160
- const forceRefresh = !!(options && options.forceRefresh);
161
- this.skillsMarketLoading = true;
162
- let localLoaded = this.skillsMarketLocalLoadedOnce === true;
163
- let importLoaded = this.skillsMarketImportLoadedOnce === true;
164
- try {
165
- if (forceRefresh || !localLoaded) {
166
- localLoaded = await this.refreshSkillsList({ silent });
167
- this.skillsMarketLocalLoadedOnce = localLoaded;
168
- }
169
- if (forceRefresh || !importLoaded) {
170
- importLoaded = await this.scanImportableSkills({ silent });
171
- this.skillsMarketImportLoadedOnce = importLoaded;
172
- }
173
- return !!(localLoaded && importLoaded);
174
- } finally {
175
- this.skillsMarketLoading = false;
176
- }
177
- },
178
-
179
- resetSkillsFilters() {
180
- this.skillsKeyword = '';
181
- this.skillsStatusFilter = 'all';
182
- },
183
-
184
- toggleAllSkillsSelection() {
185
- const selectable = this.skillsSelectableNames;
186
- if (this.skillsAllSelected) {
187
- const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
188
- selectable.forEach((name) => selectedSet.delete(name));
189
- this.skillsSelectedNames = Array.from(selectedSet);
190
- return;
191
- }
192
- const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
193
- selectable.forEach((name) => selectedSet.add(name));
194
- this.skillsSelectedNames = Array.from(selectedSet);
195
- },
196
-
197
- buildSkillImportKey(item) {
198
- const safe = item && typeof item === 'object' ? item : {};
199
- const sourceApp = typeof safe.sourceApp === 'string' ? safe.sourceApp.trim().toLowerCase() : '';
200
- const name = typeof safe.name === 'string' ? safe.name.trim() : '';
201
- if (!sourceApp || !name) return '';
202
- return `${sourceApp}:${name}`;
203
- },
204
-
205
- toggleAllSkillsImportSelection() {
206
- const selectable = this.skillsImportSelectableKeys;
207
- if (this.skillsImportAllSelected) {
208
- this.skillsImportSelectedKeys = [];
209
- return;
210
- }
211
- this.skillsImportSelectedKeys = [...selectable];
212
- },
213
-
214
- async scanImportableSkills(options = {}) {
215
- if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return false;
216
- const silent = !!(options && options.silent);
217
- this.skillsScanningImports = true;
218
- try {
219
- const res = await api('scan-unmanaged-skills', {
220
- targetApp: this.skillsTargetApp
221
- });
222
- if (res.error) {
223
- this.skillsImportList = [];
224
- this.skillsImportSelectedKeys = [];
225
- if (!silent) {
226
- this.showMessage(res.error, 'error');
227
- }
228
- return false;
229
- }
230
- this.skillsImportList = Array.isArray(res.items) ? res.items : [];
231
- const availableKeys = new Set(this.skillsImportSelectableKeys);
232
- this.skillsImportSelectedKeys = (Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : [])
233
- .filter((key) => availableKeys.has(key));
234
- if (!silent && this.skillsImportList.length === 0) {
235
- this.showMessage('未扫描到可导入 skill', 'info');
236
- } else if (!silent) {
237
- this.showMessage(`扫描到 ${this.skillsImportList.length} 个可导入 skill`, 'success');
238
- }
239
- return true;
240
- } catch (e) {
241
- this.skillsImportList = [];
242
- this.skillsImportSelectedKeys = [];
243
- if (!silent) {
244
- this.showMessage('扫描可导入 skill 失败', 'error');
245
- }
246
- return false;
247
- } finally {
248
- this.skillsScanningImports = false;
249
- }
250
- },
251
-
252
- async importSelectedSkills() {
253
- if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return;
254
- const selectedSet = new Set(Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : []);
255
- const selectedItems = (Array.isArray(this.skillsImportList) ? this.skillsImportList : [])
256
- .filter((item) => selectedSet.has(this.buildSkillImportKey(item)))
257
- .map((item) => ({
258
- name: item.name,
259
- sourceApp: item.sourceApp
260
- }));
261
- if (!selectedItems.length) {
262
- this.showMessage('请先选择要导入的 skill', 'error');
263
- return;
264
- }
265
-
266
- this.skillsImporting = true;
267
- try {
268
- const res = await api('import-skills', {
269
- targetApp: this.skillsTargetApp,
270
- items: selectedItems
271
- });
272
- if (res.error) {
273
- this.showMessage(res.error, 'error');
274
- return;
275
- }
276
- const importedCount = Array.isArray(res.imported) ? res.imported.length : 0;
277
- const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
278
- if (failedCount > 0 && importedCount > 0) {
279
- this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
280
- } else if (failedCount > 0) {
281
- const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
282
- this.showMessage(first, 'error');
283
- } else {
284
- this.showMessage(`已导入 ${importedCount} 个 skill 到 ${this.skillsTargetLabel}`, 'success');
285
- }
286
- await this.refreshSkillsList({ silent: true });
287
- } catch (e) {
288
- this.showMessage('导入 skill 失败', 'error');
289
- } finally {
290
- this.skillsImporting = false;
291
- await this.scanImportableSkills({ silent: true });
292
- }
293
- },
294
-
295
- triggerSkillsZipImport() {
296
- const input = this.$refs.skillsZipImportInput;
297
- if (input) {
298
- input.value = '';
299
- input.click();
300
- }
301
- },
302
-
303
- handleSkillsZipImportChange(event) {
304
- const file = event && event.target && event.target.files ? event.target.files[0] : null;
305
- if (file) {
306
- void this.importSkillsFromZipFile(file);
307
- }
308
- },
309
-
310
- resetSkillsZipImportInput() {
311
- const el = this.$refs.skillsZipImportInput;
312
- if (el) {
313
- el.value = '';
314
- }
315
- },
316
-
317
- async uploadSkillsZipStream(file) {
318
- const fileName = (file && typeof file.name === 'string' && file.name.trim())
319
- ? file.name.trim()
320
- : `${this.skillsTargetApp}-skills.zip`;
321
- const response = await fetch(`/api/import-skills-zip?targetApp=${encodeURIComponent(this.skillsTargetApp)}`, {
322
- method: 'POST',
323
- headers: {
324
- 'x-codexmate-file-name': encodeURIComponent(fileName)
325
- },
326
- body: file
327
- });
328
- let payload = {};
329
- try {
330
- payload = await response.json();
331
- } catch (_) {
332
- payload = {
333
- error: response.ok
334
- ? 'ZIP 导入响应无效'
335
- : `上传失败(HTTP ${response.status})`
336
- };
337
- }
338
- if (!response.ok && !payload.error) {
339
- payload.error = `上传失败(HTTP ${response.status})`;
340
- }
341
- return payload;
342
- },
343
-
344
- async importSkillsFromZipFile(file) {
345
- if (this.skillsDeleting || this.skillsScanningImports || this.skillsZipImporting || this.skillsImporting || this.skillsExporting) return;
346
- const maxSize = 20 * 1024 * 1024;
347
- if (file.size > maxSize) {
348
- this.showMessage('ZIP 文件过大,限制 20MB', 'error');
349
- this.resetSkillsZipImportInput();
350
- return;
351
- }
352
- this.skillsZipImporting = true;
353
- try {
354
- const res = await this.uploadSkillsZipStream(file);
355
- if (res && res.error) {
356
- this.showMessage(res.error, 'error');
357
- return;
358
- }
359
- const importedCount = Array.isArray(res && res.imported) ? res.imported.length : 0;
360
- const failedCount = Array.isArray(res && res.failed) ? res.failed.length : 0;
361
- if (failedCount > 0 && importedCount > 0) {
362
- this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
363
- } else if (failedCount > 0) {
364
- const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
365
- this.showMessage(first, 'error');
366
- } else {
367
- this.showMessage(`已导入 ${importedCount} 个 skill 到 ${this.skillsTargetLabel}`, 'success');
368
- }
369
- await this.refreshSkillsList({ silent: true });
370
- } catch (e) {
371
- this.showMessage('ZIP 导入失败', 'error');
372
- } finally {
373
- this.skillsZipImporting = false;
374
- this.resetSkillsZipImportInput();
375
- await this.scanImportableSkills({ silent: true });
376
- }
377
- },
378
-
379
- async exportSelectedSkills() {
380
- if (this.skillsDeleting || this.skillsExporting || this.skillsZipImporting || this.skillsImporting) return;
381
- const selected = Array.isArray(this.skillsSelectedNames)
382
- ? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
383
- : [];
384
- if (!selected.length) {
385
- this.showMessage('请先选择要导出的 skill', 'error');
386
- return;
387
- }
388
- this.skillsExporting = true;
389
- try {
390
- const res = await api('export-skills', {
391
- targetApp: this.skillsTargetApp,
392
- names: selected
393
- });
394
- if (res && res.error) {
395
- this.showMessage(res.error, 'error');
396
- return;
397
- }
398
- if (!res || !res.fileName) {
399
- this.showMessage('导出失败:未生成压缩包', 'error');
400
- return;
401
- }
402
- const exportedCount = Array.isArray(res.exported) ? res.exported.length : 0;
403
- const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
404
- const downloadUrl = typeof res.downloadPath === 'string' && res.downloadPath.trim()
405
- ? res.downloadPath.trim()
406
- : `/download/${encodeURIComponent(res.fileName)}`;
407
- const link = document.createElement('a');
408
- link.href = downloadUrl;
409
- link.download = res.fileName;
410
- document.body.appendChild(link);
411
- link.click();
412
- document.body.removeChild(link);
413
- if (failedCount > 0) {
414
- this.showMessage(`已导出 ${exportedCount} 个,失败 ${failedCount} 个`, 'error');
415
- } else {
416
- this.showMessage(`已从 ${this.skillsTargetLabel} 导出 ${exportedCount} 个 skill`, 'success');
417
- }
418
- } catch (e) {
419
- this.showMessage('导出 skill 失败', 'error');
420
- } finally {
421
- this.skillsExporting = false;
422
- }
423
- },
424
-
425
- async deleteSelectedSkills() {
426
- if (this.skillsDeleting || this.skillsZipImporting || this.skillsExporting || this.skillsImporting) return;
427
- if (this.skillsScanningImports) {
428
- this.showMessage('正在扫描导入源,请稍后再试', 'error');
429
- return;
430
- }
431
- const selected = Array.isArray(this.skillsSelectedNames)
432
- ? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
433
- : [];
434
- if (!selected.length) {
435
- this.showMessage('请先选择要删除的 skill', 'error');
436
- return;
437
- }
438
- const confirmed = await this.requestConfirmDialog({
439
- title: '删除 Skills',
440
- message: `确认从 ${this.skillsTargetLabel} 删除 ${selected.length} 个 skill 吗?此操作不可撤销。`,
441
- confirmText: '删除',
442
- cancelText: '取消',
443
- confirmDisabled: () => this.skillsDeleting || this.skillsScanningImports,
444
- danger: true
445
- });
446
- if (!confirmed) {
447
- return;
448
- }
449
-
450
- this.skillsDeleting = true;
451
- try {
452
- const res = await api('delete-skills', {
453
- targetApp: this.skillsTargetApp,
454
- names: selected
455
- });
456
- if (res.error) {
457
- this.showMessage(res.error, 'error');
458
- return;
459
- }
460
-
461
- const deletedCount = Array.isArray(res.deleted) ? res.deleted.length : 0;
462
- const failedList = Array.isArray(res.failed) ? res.failed : [];
463
- const failedCount = failedList.length;
464
- if (failedCount > 0 && deletedCount > 0) {
465
- this.showMessage(`已删除 ${deletedCount} 个,失败 ${failedCount} 个`, 'error');
466
- } else if (failedCount > 0) {
467
- const first = failedList[0] && failedList[0].error ? failedList[0].error : '删除失败';
468
- this.showMessage(first, 'error');
469
- } else {
470
- this.showMessage(`已从 ${this.skillsTargetLabel} 删除 ${deletedCount} 个 skill`, 'success');
471
- }
472
- await this.refreshSkillsList({ silent: true });
473
- } catch (e) {
474
- this.showMessage('删除 skill 失败', 'error');
475
- } finally {
476
- this.skillsDeleting = false;
477
- await this.scanImportableSkills({ silent: true });
478
- }
479
- }
480
- };
481
- }
1
+ function createUnsupportedSkillsTargetAppError(app) {
2
+ return new Error(`Unsupported skills target app: ${String(app)}`);
3
+ }
4
+
5
+ function showUnsupportedSkillsTargetMessage(vm, app) {
6
+ vm.showMessage(`不支持的 Skills 安装目标:${String(app)}`, 'error');
7
+ }
8
+
9
+ export function createSkillsMethods({ api }) {
10
+ return {
11
+ normalizeSkillsTargetApp(app) {
12
+ if (app == null) {
13
+ return 'codex';
14
+ }
15
+ if (app === 'codex' || app === 'claude') {
16
+ return app;
17
+ }
18
+ throw createUnsupportedSkillsTargetAppError(app);
19
+ },
20
+
21
+ resetSkillsTargetState() {
22
+ this.skillsSelectedNames = [];
23
+ this.skillsKeyword = '';
24
+ this.skillsStatusFilter = 'all';
25
+ this.skillsRootPath = '';
26
+ this.skillsList = [];
27
+ this.skillsImportList = [];
28
+ this.skillsImportSelectedKeys = [];
29
+ this.skillsMarketLocalLoadedOnce = false;
30
+ this.skillsMarketImportLoadedOnce = false;
31
+ },
32
+
33
+ async setSkillsTargetApp(app, options = {}) {
34
+ if (
35
+ this.skillsLoading
36
+ || this.skillsDeleting
37
+ || this.skillsScanningImports
38
+ || this.skillsImporting
39
+ || this.skillsZipImporting
40
+ || this.skillsExporting
41
+ || this.skillsMarketLoading
42
+ ) {
43
+ return false;
44
+ }
45
+ let nextTarget;
46
+ try {
47
+ nextTarget = this.normalizeSkillsTargetApp(app);
48
+ } catch (error) {
49
+ showUnsupportedSkillsTargetMessage(this, app);
50
+ return false;
51
+ }
52
+ const refresh = !(options && options.refresh === false);
53
+ const silent = !!(options && options.silent);
54
+ if (nextTarget !== this.skillsTargetApp) {
55
+ this.skillsTargetApp = nextTarget;
56
+ this.resetSkillsTargetState();
57
+ }
58
+ if (!refresh) {
59
+ return true;
60
+ }
61
+ return await this.loadSkillsMarketOverview({
62
+ forceRefresh: true,
63
+ silent
64
+ });
65
+ },
66
+
67
+ async openSkillsManager(options = {}) {
68
+ if (
69
+ this.skillsLoading
70
+ || this.skillsDeleting
71
+ || this.skillsScanningImports
72
+ || this.skillsImporting
73
+ || this.skillsZipImporting
74
+ || this.skillsExporting
75
+ || this.skillsMarketLoading
76
+ ) {
77
+ return false;
78
+ }
79
+ let targetApp;
80
+ try {
81
+ targetApp = this.normalizeSkillsTargetApp(options && options.targetApp ? options.targetApp : this.skillsTargetApp);
82
+ } catch (error) {
83
+ showUnsupportedSkillsTargetMessage(this, options && options.targetApp);
84
+ return false;
85
+ }
86
+ const targetChanged = targetApp !== this.skillsTargetApp;
87
+ if (targetChanged) {
88
+ this.skillsTargetApp = targetApp;
89
+ this.resetSkillsTargetState();
90
+ } else {
91
+ this.skillsSelectedNames = [];
92
+ this.skillsKeyword = '';
93
+ this.skillsStatusFilter = 'all';
94
+ this.skillsImportSelectedKeys = [];
95
+ }
96
+ this.showSkillsModal = true;
97
+ await this.refreshSkillsList({ silent: false });
98
+ },
99
+
100
+ closeSkillsModal() {
101
+ const busy = !!(
102
+ this.skillsLoading
103
+ || this.skillsDeleting
104
+ || this.skillsScanningImports
105
+ || this.skillsImporting
106
+ || this.skillsZipImporting
107
+ || this.skillsExporting
108
+ );
109
+ if (busy) return;
110
+ this.showSkillsModal = false;
111
+ this.skillsSelectedNames = [];
112
+ this.skillsImportSelectedKeys = [];
113
+ },
114
+
115
+ async refreshSkillsList(options = {}) {
116
+ this.skillsLoading = true;
117
+ try {
118
+ const res = await api('list-skills', {
119
+ targetApp: this.skillsTargetApp
120
+ });
121
+ if (res.error) {
122
+ this.skillsRootPath = '';
123
+ this.skillsList = [];
124
+ this.skillsSelectedNames = [];
125
+ this.showMessage(res.error, 'error');
126
+ return false;
127
+ }
128
+ const exists = res.exists !== false;
129
+ if (!exists) {
130
+ this.skillsRootPath = res.root || '';
131
+ this.skillsList = [];
132
+ this.skillsSelectedNames = [];
133
+ if (!options.silent) {
134
+ this.showMessage(`${this.skillsTargetLabel} skills 目录不存在,已按空列表显示`, 'info');
135
+ }
136
+ return true;
137
+ }
138
+ this.skillsRootPath = res.root || '';
139
+ this.skillsList = Array.isArray(res.items) ? res.items : [];
140
+ const currentNames = new Set((Array.isArray(this.skillsList) ? this.skillsList : [])
141
+ .map((item) => (item && typeof item.name === 'string' ? item.name.trim() : ''))
142
+ .filter(Boolean));
143
+ this.skillsSelectedNames = (Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : [])
144
+ .filter((name) => currentNames.has(name));
145
+ return true;
146
+ } catch (e) {
147
+ this.skillsRootPath = '';
148
+ this.skillsList = [];
149
+ this.skillsSelectedNames = [];
150
+ this.showMessage('加载 skills 失败', 'error');
151
+ return false;
152
+ } finally {
153
+ this.skillsLoading = false;
154
+ }
155
+ },
156
+
157
+ async loadSkillsMarketOverview(options = {}) {
158
+ if (this.skillsMarketLoading) return false;
159
+ const silent = !!(options && options.silent);
160
+ const forceRefresh = !!(options && options.forceRefresh);
161
+ this.skillsMarketLoading = true;
162
+ let localLoaded = this.skillsMarketLocalLoadedOnce === true;
163
+ let importLoaded = this.skillsMarketImportLoadedOnce === true;
164
+ try {
165
+ if (forceRefresh || !localLoaded) {
166
+ localLoaded = await this.refreshSkillsList({ silent });
167
+ this.skillsMarketLocalLoadedOnce = localLoaded;
168
+ }
169
+ if (forceRefresh || !importLoaded) {
170
+ importLoaded = await this.scanImportableSkills({ silent });
171
+ this.skillsMarketImportLoadedOnce = importLoaded;
172
+ }
173
+ return !!(localLoaded && importLoaded);
174
+ } finally {
175
+ this.skillsMarketLoading = false;
176
+ }
177
+ },
178
+
179
+ resetSkillsFilters() {
180
+ this.skillsKeyword = '';
181
+ this.skillsStatusFilter = 'all';
182
+ },
183
+
184
+ toggleAllSkillsSelection() {
185
+ const selectable = this.skillsSelectableNames;
186
+ if (this.skillsAllSelected) {
187
+ const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
188
+ selectable.forEach((name) => selectedSet.delete(name));
189
+ this.skillsSelectedNames = Array.from(selectedSet);
190
+ return;
191
+ }
192
+ const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
193
+ selectable.forEach((name) => selectedSet.add(name));
194
+ this.skillsSelectedNames = Array.from(selectedSet);
195
+ },
196
+
197
+ buildSkillImportKey(item) {
198
+ const safe = item && typeof item === 'object' ? item : {};
199
+ const sourceApp = typeof safe.sourceApp === 'string' ? safe.sourceApp.trim().toLowerCase() : '';
200
+ const name = typeof safe.name === 'string' ? safe.name.trim() : '';
201
+ if (!sourceApp || !name) return '';
202
+ return `${sourceApp}:${name}`;
203
+ },
204
+
205
+ toggleAllSkillsImportSelection() {
206
+ const selectable = this.skillsImportSelectableKeys;
207
+ if (this.skillsImportAllSelected) {
208
+ this.skillsImportSelectedKeys = [];
209
+ return;
210
+ }
211
+ this.skillsImportSelectedKeys = [...selectable];
212
+ },
213
+
214
+ async scanImportableSkills(options = {}) {
215
+ if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return false;
216
+ const silent = !!(options && options.silent);
217
+ this.skillsScanningImports = true;
218
+ try {
219
+ const res = await api('scan-unmanaged-skills', {
220
+ targetApp: this.skillsTargetApp
221
+ });
222
+ if (res.error) {
223
+ this.skillsImportList = [];
224
+ this.skillsImportSelectedKeys = [];
225
+ if (!silent) {
226
+ this.showMessage(res.error, 'error');
227
+ }
228
+ return false;
229
+ }
230
+ this.skillsImportList = Array.isArray(res.items) ? res.items : [];
231
+ const availableKeys = new Set(this.skillsImportSelectableKeys);
232
+ this.skillsImportSelectedKeys = (Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : [])
233
+ .filter((key) => availableKeys.has(key));
234
+ if (!silent && this.skillsImportList.length === 0) {
235
+ this.showMessage('未扫描到可导入 skill', 'info');
236
+ } else if (!silent) {
237
+ this.showMessage(`扫描到 ${this.skillsImportList.length} 个可导入 skill`, 'success');
238
+ }
239
+ return true;
240
+ } catch (e) {
241
+ this.skillsImportList = [];
242
+ this.skillsImportSelectedKeys = [];
243
+ if (!silent) {
244
+ this.showMessage('扫描可导入 skill 失败', 'error');
245
+ }
246
+ return false;
247
+ } finally {
248
+ this.skillsScanningImports = false;
249
+ }
250
+ },
251
+
252
+ async importSelectedSkills() {
253
+ if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return;
254
+ const selectedSet = new Set(Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : []);
255
+ const selectedItems = (Array.isArray(this.skillsImportList) ? this.skillsImportList : [])
256
+ .filter((item) => selectedSet.has(this.buildSkillImportKey(item)))
257
+ .map((item) => ({
258
+ name: item.name,
259
+ sourceApp: item.sourceApp
260
+ }));
261
+ if (!selectedItems.length) {
262
+ this.showMessage('请先选择要导入的 skill', 'error');
263
+ return;
264
+ }
265
+
266
+ this.skillsImporting = true;
267
+ try {
268
+ const res = await api('import-skills', {
269
+ targetApp: this.skillsTargetApp,
270
+ items: selectedItems
271
+ });
272
+ if (res.error) {
273
+ this.showMessage(res.error, 'error');
274
+ return;
275
+ }
276
+ const importedCount = Array.isArray(res.imported) ? res.imported.length : 0;
277
+ const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
278
+ if (failedCount > 0 && importedCount > 0) {
279
+ this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
280
+ } else if (failedCount > 0) {
281
+ const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
282
+ this.showMessage(first, 'error');
283
+ } else {
284
+ this.showMessage(`已导入 ${importedCount} 个 skill 到 ${this.skillsTargetLabel}`, 'success');
285
+ }
286
+ await this.refreshSkillsList({ silent: true });
287
+ } catch (e) {
288
+ this.showMessage('导入 skill 失败', 'error');
289
+ } finally {
290
+ this.skillsImporting = false;
291
+ await this.scanImportableSkills({ silent: true });
292
+ }
293
+ },
294
+
295
+ triggerSkillsZipImport() {
296
+ const input = this.$refs.skillsZipImportInput;
297
+ if (input) {
298
+ input.value = '';
299
+ input.click();
300
+ }
301
+ },
302
+
303
+ handleSkillsZipImportChange(event) {
304
+ const file = event && event.target && event.target.files ? event.target.files[0] : null;
305
+ if (file) {
306
+ void this.importSkillsFromZipFile(file);
307
+ }
308
+ },
309
+
310
+ resetSkillsZipImportInput() {
311
+ const el = this.$refs.skillsZipImportInput;
312
+ if (el) {
313
+ el.value = '';
314
+ }
315
+ },
316
+
317
+ async uploadSkillsZipStream(file) {
318
+ const fileName = (file && typeof file.name === 'string' && file.name.trim())
319
+ ? file.name.trim()
320
+ : `${this.skillsTargetApp}-skills.zip`;
321
+ const response = await fetch(`/api/import-skills-zip?targetApp=${encodeURIComponent(this.skillsTargetApp)}`, {
322
+ method: 'POST',
323
+ headers: {
324
+ 'x-codexmate-file-name': encodeURIComponent(fileName)
325
+ },
326
+ body: file
327
+ });
328
+ let payload = {};
329
+ try {
330
+ payload = await response.json();
331
+ } catch (_) {
332
+ payload = {
333
+ error: response.ok
334
+ ? 'ZIP 导入响应无效'
335
+ : `上传失败(HTTP ${response.status})`
336
+ };
337
+ }
338
+ if (!response.ok && !payload.error) {
339
+ payload.error = `上传失败(HTTP ${response.status})`;
340
+ }
341
+ return payload;
342
+ },
343
+
344
+ async importSkillsFromZipFile(file) {
345
+ if (this.skillsDeleting || this.skillsScanningImports || this.skillsZipImporting || this.skillsImporting || this.skillsExporting) return;
346
+ const maxSize = 20 * 1024 * 1024;
347
+ if (file.size > maxSize) {
348
+ this.showMessage('ZIP 文件过大,限制 20MB', 'error');
349
+ this.resetSkillsZipImportInput();
350
+ return;
351
+ }
352
+ this.skillsZipImporting = true;
353
+ try {
354
+ const res = await this.uploadSkillsZipStream(file);
355
+ if (res && res.error) {
356
+ this.showMessage(res.error, 'error');
357
+ return;
358
+ }
359
+ const importedCount = Array.isArray(res && res.imported) ? res.imported.length : 0;
360
+ const failedCount = Array.isArray(res && res.failed) ? res.failed.length : 0;
361
+ if (failedCount > 0 && importedCount > 0) {
362
+ this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
363
+ } else if (failedCount > 0) {
364
+ const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
365
+ this.showMessage(first, 'error');
366
+ } else {
367
+ this.showMessage(`已导入 ${importedCount} 个 skill 到 ${this.skillsTargetLabel}`, 'success');
368
+ }
369
+ await this.refreshSkillsList({ silent: true });
370
+ } catch (e) {
371
+ this.showMessage('ZIP 导入失败', 'error');
372
+ } finally {
373
+ this.skillsZipImporting = false;
374
+ this.resetSkillsZipImportInput();
375
+ await this.scanImportableSkills({ silent: true });
376
+ }
377
+ },
378
+
379
+ async exportSelectedSkills() {
380
+ if (this.skillsDeleting || this.skillsExporting || this.skillsZipImporting || this.skillsImporting) return;
381
+ const selected = Array.isArray(this.skillsSelectedNames)
382
+ ? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
383
+ : [];
384
+ if (!selected.length) {
385
+ this.showMessage('请先选择要导出的 skill', 'error');
386
+ return;
387
+ }
388
+ this.skillsExporting = true;
389
+ try {
390
+ const res = await api('export-skills', {
391
+ targetApp: this.skillsTargetApp,
392
+ names: selected
393
+ });
394
+ if (res && res.error) {
395
+ this.showMessage(res.error, 'error');
396
+ return;
397
+ }
398
+ if (!res || !res.fileName) {
399
+ this.showMessage('导出失败:未生成压缩包', 'error');
400
+ return;
401
+ }
402
+ const exportedCount = Array.isArray(res.exported) ? res.exported.length : 0;
403
+ const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
404
+ const downloadUrl = typeof res.downloadPath === 'string' && res.downloadPath.trim()
405
+ ? res.downloadPath.trim()
406
+ : `/download/${encodeURIComponent(res.fileName)}`;
407
+ const link = document.createElement('a');
408
+ link.href = downloadUrl;
409
+ link.download = res.fileName;
410
+ document.body.appendChild(link);
411
+ link.click();
412
+ document.body.removeChild(link);
413
+ if (failedCount > 0) {
414
+ this.showMessage(`已导出 ${exportedCount} 个,失败 ${failedCount} 个`, 'error');
415
+ } else {
416
+ this.showMessage(`已从 ${this.skillsTargetLabel} 导出 ${exportedCount} 个 skill`, 'success');
417
+ }
418
+ } catch (e) {
419
+ this.showMessage('导出 skill 失败', 'error');
420
+ } finally {
421
+ this.skillsExporting = false;
422
+ }
423
+ },
424
+
425
+ async deleteSelectedSkills() {
426
+ if (this.skillsDeleting || this.skillsZipImporting || this.skillsExporting || this.skillsImporting) return;
427
+ if (this.skillsScanningImports) {
428
+ this.showMessage('正在扫描导入源,请稍后再试', 'error');
429
+ return;
430
+ }
431
+ const selected = Array.isArray(this.skillsSelectedNames)
432
+ ? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
433
+ : [];
434
+ if (!selected.length) {
435
+ this.showMessage('请先选择要删除的 skill', 'error');
436
+ return;
437
+ }
438
+ const confirmed = await this.requestConfirmDialog({
439
+ title: '删除 Skills',
440
+ message: `确认从 ${this.skillsTargetLabel} 删除 ${selected.length} 个 skill 吗?此操作不可撤销。`,
441
+ confirmText: '删除',
442
+ cancelText: '取消',
443
+ confirmDisabled: () => this.skillsDeleting || this.skillsScanningImports,
444
+ danger: true
445
+ });
446
+ if (!confirmed) {
447
+ return;
448
+ }
449
+
450
+ this.skillsDeleting = true;
451
+ try {
452
+ const res = await api('delete-skills', {
453
+ targetApp: this.skillsTargetApp,
454
+ names: selected
455
+ });
456
+ if (res.error) {
457
+ this.showMessage(res.error, 'error');
458
+ return;
459
+ }
460
+
461
+ const deletedCount = Array.isArray(res.deleted) ? res.deleted.length : 0;
462
+ const failedList = Array.isArray(res.failed) ? res.failed : [];
463
+ const failedCount = failedList.length;
464
+ if (failedCount > 0 && deletedCount > 0) {
465
+ this.showMessage(`已删除 ${deletedCount} 个,失败 ${failedCount} 个`, 'error');
466
+ } else if (failedCount > 0) {
467
+ const first = failedList[0] && failedList[0].error ? failedList[0].error : '删除失败';
468
+ this.showMessage(first, 'error');
469
+ } else {
470
+ this.showMessage(`已从 ${this.skillsTargetLabel} 删除 ${deletedCount} 个 skill`, 'success');
471
+ }
472
+ await this.refreshSkillsList({ silent: true });
473
+ } catch (e) {
474
+ this.showMessage('删除 skill 失败', 'error');
475
+ } finally {
476
+ this.skillsDeleting = false;
477
+ await this.scanImportableSkills({ silent: true });
478
+ }
479
+ }
480
+ };
481
+ }