codexmate 0.0.40 → 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -156
- package/README.zh.md +168 -156
- package/cli/agents-files.js +230 -230
- package/cli/analytics-export-args.js +68 -68
- package/cli/archive-helpers.js +453 -453
- package/cli/auth-profiles.js +375 -375
- package/cli/builtin-proxy.js +2144 -2144
- package/cli/claude-proxy.js +1022 -1022
- package/cli/config-bootstrap.js +407 -407
- package/cli/config-health.js +454 -454
- package/cli/doctor-core.js +903 -903
- package/cli/import-skills-url.js +356 -356
- package/cli/local-bridge.js +556 -556
- package/cli/openai-bridge.js +1984 -1984
- package/cli/openclaw-config.js +629 -629
- package/cli/session-convert-args.js +69 -69
- package/cli/session-convert-io.js +82 -82
- package/cli/session-convert.js +150 -150
- package/cli/session-usage.concurrent.js +28 -28
- package/cli/session-usage.js +304 -304
- package/cli/session-usage.models.js +176 -176
- package/cli/skills.js +1141 -1141
- package/cli/update.js +171 -171
- package/cli/zip-commands.js +510 -510
- package/cli.js +16458 -16341
- package/lib/automation.js +404 -404
- package/lib/cli-file-utils.js +151 -151
- package/lib/cli-models-utils.js +440 -440
- package/lib/cli-network-utils.js +190 -190
- package/lib/cli-path-utils.js +85 -85
- package/lib/cli-session-utils.js +121 -121
- package/lib/cli-sessions.js +427 -427
- package/lib/cli-utils.js +155 -155
- package/lib/cli-webhook.js +154 -154
- package/lib/download-artifacts.js +92 -92
- package/lib/mcp-stdio.js +453 -453
- package/lib/task-orchestrator.js +869 -869
- package/lib/text-diff.js +303 -303
- package/lib/win-tray.js +119 -119
- package/lib/workflow-engine.js +340 -340
- package/package.json +77 -77
- package/plugins/README.md +20 -20
- package/plugins/README.zh-CN.md +20 -20
- package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
- package/plugins/prompt-templates/computed.mjs +311 -311
- package/plugins/prompt-templates/index.mjs +8 -8
- package/plugins/prompt-templates/manifest.mjs +18 -18
- package/plugins/prompt-templates/methods.mjs +553 -553
- package/plugins/prompt-templates/overview.mjs +91 -91
- package/plugins/prompt-templates/ownership.mjs +19 -19
- package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
- package/plugins/prompt-templates/storage.mjs +64 -64
- package/plugins/registry.mjs +16 -16
- package/web-ui/app.js +695 -695
- package/web-ui/index.html +37 -37
- package/web-ui/logic.agents-diff.mjs +386 -386
- package/web-ui/logic.claude.mjs +172 -172
- package/web-ui/logic.codex.mjs +69 -69
- package/web-ui/logic.mjs +5 -5
- package/web-ui/logic.runtime.mjs +128 -128
- package/web-ui/logic.session-convert.mjs +70 -70
- package/web-ui/logic.sessions.mjs +782 -782
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +252 -252
- package/web-ui/modules/app.computed.index.mjs +17 -17
- package/web-ui/modules/app.computed.main-tabs.mjs +214 -214
- package/web-ui/modules/app.computed.session.mjs +876 -876
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +651 -651
- package/web-ui/modules/app.methods.claude-config.mjs +412 -412
- package/web-ui/modules/app.methods.codex-config.mjs +869 -869
- package/web-ui/modules/app.methods.index.mjs +96 -96
- package/web-ui/modules/app.methods.install.mjs +205 -205
- package/web-ui/modules/app.methods.navigation.mjs +804 -804
- package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
- package/web-ui/modules/app.methods.openclaw-editing.mjs +420 -420
- package/web-ui/modules/app.methods.openclaw-persist.mjs +375 -375
- package/web-ui/modules/app.methods.providers.mjs +601 -601
- package/web-ui/modules/app.methods.runtime.mjs +420 -420
- package/web-ui/modules/app.methods.session-actions.mjs +591 -591
- package/web-ui/modules/app.methods.session-browser.mjs +1018 -1018
- package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
- package/web-ui/modules/app.methods.session-trash.mjs +468 -468
- package/web-ui/modules/app.methods.startup-claude.mjs +554 -554
- package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
- package/web-ui/modules/app.methods.tool-config-permissions.mjs +87 -87
- package/web-ui/modules/app.methods.webhook.mjs +87 -87
- package/web-ui/modules/config-mode.computed.mjs +124 -124
- package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
- package/web-ui/modules/i18n/locales/en.mjs +1140 -1140
- package/web-ui/modules/i18n/locales/ja.mjs +1130 -1130
- package/web-ui/modules/i18n/locales/vi.mjs +239 -239
- package/web-ui/modules/i18n/locales/zh.mjs +1143 -1143
- package/web-ui/modules/i18n.dict.mjs +14 -14
- package/web-ui/modules/i18n.mjs +111 -111
- package/web-ui/modules/plugins.computed.mjs +3 -3
- package/web-ui/modules/plugins.methods.mjs +3 -3
- package/web-ui/modules/plugins.storage.mjs +11 -11
- package/web-ui/modules/provider-url-display.mjs +17 -17
- package/web-ui/modules/sessions-filters-url.mjs +138 -138
- package/web-ui/modules/skills.computed.mjs +107 -107
- package/web-ui/modules/skills.methods.mjs +513 -513
- package/web-ui/partials/index/layout-footer.html +13 -13
- package/web-ui/partials/index/layout-header.html +478 -478
- package/web-ui/partials/index/modal-config-template-agents.html +185 -185
- package/web-ui/partials/index/modal-confirm-toast.html +32 -32
- package/web-ui/partials/index/modal-health-check.html +45 -45
- package/web-ui/partials/index/modal-openclaw-config.html +344 -344
- package/web-ui/partials/index/modal-skills.html +200 -200
- package/web-ui/partials/index/modal-webhook.html +42 -42
- package/web-ui/partials/index/modals-basic.html +263 -263
- package/web-ui/partials/index/panel-config-claude.html +187 -187
- package/web-ui/partials/index/panel-config-codex.html +205 -205
- package/web-ui/partials/index/panel-config-openclaw.html +89 -89
- package/web-ui/partials/index/panel-dashboard.html +171 -171
- package/web-ui/partials/index/panel-docs.html +114 -114
- package/web-ui/partials/index/panel-market.html +104 -104
- package/web-ui/partials/index/panel-orchestration.html +391 -391
- package/web-ui/partials/index/panel-plugins.html +253 -253
- package/web-ui/partials/index/panel-sessions.html +319 -319
- package/web-ui/partials/index/panel-settings.html +181 -181
- package/web-ui/partials/index/panel-trash.html +82 -82
- package/web-ui/partials/index/panel-usage.html +181 -181
- package/web-ui/res/json5.min.js +1 -1
- package/web-ui/res/vue.global.prod.js +13 -13
- package/web-ui/res/vue.runtime.global.prod.js +7 -7
- package/web-ui/res/web-ui-render.precompiled.js +7666 -7666
- package/web-ui/session-helpers.mjs +602 -602
- package/web-ui/source-bundle.cjs +305 -305
- package/web-ui/styles/base-theme.css +291 -291
- package/web-ui/styles/bridge-pool.css +266 -266
- package/web-ui/styles/controls-forms.css +532 -532
- package/web-ui/styles/dashboard.css +438 -438
- package/web-ui/styles/docs-panel.css +245 -245
- package/web-ui/styles/feedback.css +108 -108
- package/web-ui/styles/health-check-dialog.css +144 -144
- package/web-ui/styles/layout-shell.css +711 -711
- package/web-ui/styles/modals-core.css +499 -499
- package/web-ui/styles/navigation-panels.css +399 -399
- package/web-ui/styles/openclaw-structured.css +616 -616
- package/web-ui/styles/plugins-panel.css +564 -564
- package/web-ui/styles/responsive.css +501 -501
- package/web-ui/styles/sessions-list.css +683 -683
- package/web-ui/styles/sessions-preview.css +407 -407
- package/web-ui/styles/sessions-toolbar-trash.css +518 -518
- package/web-ui/styles/sessions-usage.css +849 -849
- package/web-ui/styles/settings-panel.css +419 -419
- package/web-ui/styles/skills-list.css +305 -305
- package/web-ui/styles/skills-market.css +723 -723
- package/web-ui/styles/task-orchestration.css +822 -822
- package/web-ui/styles/titles-cards.css +486 -486
- package/web-ui/styles/trash-panel.css +90 -90
- package/web-ui/styles/webhook.css +115 -115
- package/web-ui/styles.css +24 -24
- package/web-ui.html +17 -17
|
@@ -1,513 +1,513 @@
|
|
|
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
|
-
if (typeof this.saveNavState === 'function') this.saveNavState();
|
|
58
|
-
}
|
|
59
|
-
if (!refresh) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
return await this.loadSkillsMarketOverview({
|
|
63
|
-
forceRefresh: true,
|
|
64
|
-
silent
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
async openSkillsManager(options = {}) {
|
|
69
|
-
if (
|
|
70
|
-
this.skillsLoading
|
|
71
|
-
|| this.skillsDeleting
|
|
72
|
-
|| this.skillsScanningImports
|
|
73
|
-
|| this.skillsImporting
|
|
74
|
-
|| this.skillsZipImporting
|
|
75
|
-
|| this.skillsExporting
|
|
76
|
-
|| this.skillsMarketLoading
|
|
77
|
-
) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
let targetApp;
|
|
81
|
-
try {
|
|
82
|
-
targetApp = this.normalizeSkillsTargetApp(options && options.targetApp ? options.targetApp : this.skillsTargetApp);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
showUnsupportedSkillsTargetMessage(this, options && options.targetApp);
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const targetChanged = targetApp !== this.skillsTargetApp;
|
|
88
|
-
if (targetChanged) {
|
|
89
|
-
this.skillsTargetApp = targetApp;
|
|
90
|
-
this.resetSkillsTargetState();
|
|
91
|
-
} else {
|
|
92
|
-
this.skillsSelectedNames = [];
|
|
93
|
-
this.skillsKeyword = '';
|
|
94
|
-
this.skillsStatusFilter = 'all';
|
|
95
|
-
this.skillsImportSelectedKeys = [];
|
|
96
|
-
}
|
|
97
|
-
this.showSkillsModal = true;
|
|
98
|
-
await this.refreshSkillsList({ silent: false });
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
closeSkillsModal() {
|
|
102
|
-
const busy = !!(
|
|
103
|
-
this.skillsLoading
|
|
104
|
-
|| this.skillsDeleting
|
|
105
|
-
|| this.skillsScanningImports
|
|
106
|
-
|| this.skillsImporting
|
|
107
|
-
|| this.skillsZipImporting
|
|
108
|
-
|| this.skillsExporting
|
|
109
|
-
);
|
|
110
|
-
if (busy) return;
|
|
111
|
-
this.showSkillsModal = false;
|
|
112
|
-
this.skillsSelectedNames = [];
|
|
113
|
-
this.skillsImportSelectedKeys = [];
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
async refreshSkillsList(options = {}) {
|
|
117
|
-
this.skillsLoading = true;
|
|
118
|
-
try {
|
|
119
|
-
const res = await api('list-skills', {
|
|
120
|
-
targetApp: this.skillsTargetApp
|
|
121
|
-
});
|
|
122
|
-
if (res.error) {
|
|
123
|
-
this.skillsRootPath = '';
|
|
124
|
-
this.skillsList = [];
|
|
125
|
-
this.skillsSelectedNames = [];
|
|
126
|
-
this.showMessage(res.error, 'error');
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
const exists = res.exists !== false;
|
|
130
|
-
if (!exists) {
|
|
131
|
-
this.skillsRootPath = res.root || '';
|
|
132
|
-
this.skillsList = [];
|
|
133
|
-
this.skillsSelectedNames = [];
|
|
134
|
-
if (!options.silent) {
|
|
135
|
-
this.showMessage(`${this.skillsTargetLabel} skills 目录不存在,已按空列表显示`, 'info');
|
|
136
|
-
}
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
this.skillsRootPath = res.root || '';
|
|
140
|
-
this.skillsList = Array.isArray(res.items) ? res.items : [];
|
|
141
|
-
const currentNames = new Set((Array.isArray(this.skillsList) ? this.skillsList : [])
|
|
142
|
-
.map((item) => (item && typeof item.name === 'string' ? item.name.trim() : ''))
|
|
143
|
-
.filter(Boolean));
|
|
144
|
-
this.skillsSelectedNames = (Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : [])
|
|
145
|
-
.filter((name) => currentNames.has(name));
|
|
146
|
-
return true;
|
|
147
|
-
} catch (e) {
|
|
148
|
-
this.skillsRootPath = '';
|
|
149
|
-
this.skillsList = [];
|
|
150
|
-
this.skillsSelectedNames = [];
|
|
151
|
-
this.showMessage('加载 skills 失败', 'error');
|
|
152
|
-
return false;
|
|
153
|
-
} finally {
|
|
154
|
-
this.skillsLoading = false;
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
async loadSkillsMarketOverview(options = {}) {
|
|
159
|
-
if (this.skillsMarketLoading) return false;
|
|
160
|
-
const silent = !!(options && options.silent);
|
|
161
|
-
const forceRefresh = !!(options && options.forceRefresh);
|
|
162
|
-
this.skillsMarketLoading = true;
|
|
163
|
-
let localLoaded = this.skillsMarketLocalLoadedOnce === true;
|
|
164
|
-
let importLoaded = this.skillsMarketImportLoadedOnce === true;
|
|
165
|
-
try {
|
|
166
|
-
if (forceRefresh || !localLoaded) {
|
|
167
|
-
localLoaded = await this.refreshSkillsList({ silent });
|
|
168
|
-
this.skillsMarketLocalLoadedOnce = localLoaded;
|
|
169
|
-
}
|
|
170
|
-
if (forceRefresh || !importLoaded) {
|
|
171
|
-
importLoaded = await this.scanImportableSkills({ silent });
|
|
172
|
-
this.skillsMarketImportLoadedOnce = importLoaded;
|
|
173
|
-
}
|
|
174
|
-
return !!(localLoaded && importLoaded);
|
|
175
|
-
} finally {
|
|
176
|
-
this.skillsMarketLoading = false;
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
|
|
180
|
-
resetSkillsFilters() {
|
|
181
|
-
this.skillsKeyword = '';
|
|
182
|
-
this.skillsStatusFilter = 'all';
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
toggleAllSkillsSelection() {
|
|
186
|
-
const selectable = this.skillsSelectableNames;
|
|
187
|
-
if (this.skillsAllSelected) {
|
|
188
|
-
const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
|
|
189
|
-
selectable.forEach((name) => selectedSet.delete(name));
|
|
190
|
-
this.skillsSelectedNames = Array.from(selectedSet);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
|
|
194
|
-
selectable.forEach((name) => selectedSet.add(name));
|
|
195
|
-
this.skillsSelectedNames = Array.from(selectedSet);
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
buildSkillImportKey(item) {
|
|
199
|
-
const safe = item && typeof item === 'object' ? item : {};
|
|
200
|
-
const sourceApp = typeof safe.sourceApp === 'string' ? safe.sourceApp.trim().toLowerCase() : '';
|
|
201
|
-
const name = typeof safe.name === 'string' ? safe.name.trim() : '';
|
|
202
|
-
if (!sourceApp || !name) return '';
|
|
203
|
-
return `${sourceApp}:${name}`;
|
|
204
|
-
},
|
|
205
|
-
|
|
206
|
-
toggleAllSkillsImportSelection() {
|
|
207
|
-
const selectable = this.skillsImportSelectableKeys;
|
|
208
|
-
if (this.skillsImportAllSelected) {
|
|
209
|
-
this.skillsImportSelectedKeys = [];
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
this.skillsImportSelectedKeys = [...selectable];
|
|
213
|
-
},
|
|
214
|
-
|
|
215
|
-
async scanImportableSkills(options = {}) {
|
|
216
|
-
if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return false;
|
|
217
|
-
const silent = !!(options && options.silent);
|
|
218
|
-
this.skillsScanningImports = true;
|
|
219
|
-
try {
|
|
220
|
-
const res = await api('scan-unmanaged-skills', {
|
|
221
|
-
targetApp: this.skillsTargetApp
|
|
222
|
-
});
|
|
223
|
-
if (res.error) {
|
|
224
|
-
this.skillsImportList = [];
|
|
225
|
-
this.skillsImportSelectedKeys = [];
|
|
226
|
-
if (!silent) {
|
|
227
|
-
this.showMessage(res.error, 'error');
|
|
228
|
-
}
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
this.skillsImportList = Array.isArray(res.items) ? res.items : [];
|
|
232
|
-
const availableKeys = new Set(this.skillsImportSelectableKeys);
|
|
233
|
-
this.skillsImportSelectedKeys = (Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : [])
|
|
234
|
-
.filter((key) => availableKeys.has(key));
|
|
235
|
-
if (!silent && this.skillsImportList.length === 0) {
|
|
236
|
-
this.showMessage('未扫描到可导入 skill', 'info');
|
|
237
|
-
} else if (!silent) {
|
|
238
|
-
this.showMessage(`扫描到 ${this.skillsImportList.length} 个可导入 skill`, 'success');
|
|
239
|
-
}
|
|
240
|
-
return true;
|
|
241
|
-
} catch (e) {
|
|
242
|
-
this.skillsImportList = [];
|
|
243
|
-
this.skillsImportSelectedKeys = [];
|
|
244
|
-
if (!silent) {
|
|
245
|
-
this.showMessage('扫描可导入 skill 失败', 'error');
|
|
246
|
-
}
|
|
247
|
-
return false;
|
|
248
|
-
} finally {
|
|
249
|
-
this.skillsScanningImports = false;
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
async importSelectedSkills() {
|
|
254
|
-
if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return;
|
|
255
|
-
const selectedSet = new Set(Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : []);
|
|
256
|
-
const selectedItems = (Array.isArray(this.skillsImportList) ? this.skillsImportList : [])
|
|
257
|
-
.filter((item) => selectedSet.has(this.buildSkillImportKey(item)))
|
|
258
|
-
.map((item) => ({
|
|
259
|
-
name: item.name,
|
|
260
|
-
sourceApp: item.sourceApp
|
|
261
|
-
}));
|
|
262
|
-
if (!selectedItems.length) {
|
|
263
|
-
this.showMessage('请先选择要导入的 skill', 'error');
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
this.skillsImporting = true;
|
|
268
|
-
try {
|
|
269
|
-
const res = await api('import-skills', {
|
|
270
|
-
targetApp: this.skillsTargetApp,
|
|
271
|
-
items: selectedItems
|
|
272
|
-
});
|
|
273
|
-
if (res.error) {
|
|
274
|
-
this.showMessage(res.error, 'error');
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
const importedCount = Array.isArray(res.imported) ? res.imported.length : 0;
|
|
278
|
-
const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
|
|
279
|
-
if (failedCount > 0 && importedCount > 0) {
|
|
280
|
-
this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
|
|
281
|
-
} else if (failedCount > 0) {
|
|
282
|
-
const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
|
|
283
|
-
this.showMessage(first, 'error');
|
|
284
|
-
} else {
|
|
285
|
-
this.showMessage(`已导入 ${importedCount} 个 skill 到 ${this.skillsTargetLabel}`, 'success');
|
|
286
|
-
}
|
|
287
|
-
await this.refreshSkillsList({ silent: true });
|
|
288
|
-
} catch (e) {
|
|
289
|
-
this.showMessage('导入 skill 失败', 'error');
|
|
290
|
-
} finally {
|
|
291
|
-
this.skillsImporting = false;
|
|
292
|
-
await this.scanImportableSkills({ silent: true });
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
|
|
296
|
-
triggerSkillsZipImport() {
|
|
297
|
-
const input = this.$refs.skillsZipImportInput;
|
|
298
|
-
if (input) {
|
|
299
|
-
input.value = '';
|
|
300
|
-
input.click();
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
|
-
|
|
304
|
-
handleSkillsZipImportChange(event) {
|
|
305
|
-
const file = event && event.target && event.target.files ? event.target.files[0] : null;
|
|
306
|
-
if (file) {
|
|
307
|
-
void this.importSkillsFromZipFile(file);
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
|
|
311
|
-
resetSkillsZipImportInput() {
|
|
312
|
-
const el = this.$refs.skillsZipImportInput;
|
|
313
|
-
if (el) {
|
|
314
|
-
el.value = '';
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
|
|
318
|
-
async uploadSkillsZipStream(file) {
|
|
319
|
-
const fileName = (file && typeof file.name === 'string' && file.name.trim())
|
|
320
|
-
? file.name.trim()
|
|
321
|
-
: `${this.skillsTargetApp}-skills.zip`;
|
|
322
|
-
const response = await fetch(`/api/import-skills-zip?targetApp=${encodeURIComponent(this.skillsTargetApp)}`, {
|
|
323
|
-
method: 'POST',
|
|
324
|
-
headers: {
|
|
325
|
-
'x-codexmate-file-name': encodeURIComponent(fileName)
|
|
326
|
-
},
|
|
327
|
-
body: file
|
|
328
|
-
});
|
|
329
|
-
let payload = {};
|
|
330
|
-
try {
|
|
331
|
-
payload = await response.json();
|
|
332
|
-
} catch (_) {
|
|
333
|
-
payload = {
|
|
334
|
-
error: response.ok
|
|
335
|
-
? 'ZIP 导入响应无效'
|
|
336
|
-
: `上传失败(HTTP ${response.status})`
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
if (!response.ok && !payload.error) {
|
|
340
|
-
payload.error = `上传失败(HTTP ${response.status})`;
|
|
341
|
-
}
|
|
342
|
-
return payload;
|
|
343
|
-
},
|
|
344
|
-
|
|
345
|
-
async importSkillsFromZipFile(file) {
|
|
346
|
-
if (this.skillsDeleting || this.skillsScanningImports || this.skillsZipImporting || this.skillsImporting || this.skillsExporting) return;
|
|
347
|
-
const maxSize = 20 * 1024 * 1024;
|
|
348
|
-
if (file.size > maxSize) {
|
|
349
|
-
this.showMessage('ZIP 文件过大,限制 20MB', 'error');
|
|
350
|
-
this.resetSkillsZipImportInput();
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
this.skillsZipImporting = true;
|
|
354
|
-
try {
|
|
355
|
-
const res = await this.uploadSkillsZipStream(file);
|
|
356
|
-
if (res && res.error) {
|
|
357
|
-
this.showMessage(res.error, 'error');
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
const importedCount = Array.isArray(res && res.imported) ? res.imported.length : 0;
|
|
361
|
-
const failedCount = Array.isArray(res && res.failed) ? res.failed.length : 0;
|
|
362
|
-
if (failedCount > 0 && importedCount > 0) {
|
|
363
|
-
this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
|
|
364
|
-
} else if (failedCount > 0) {
|
|
365
|
-
const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
|
|
366
|
-
this.showMessage(first, 'error');
|
|
367
|
-
} else {
|
|
368
|
-
this.showMessage(`已导入 ${importedCount} 个 skill 到 ${this.skillsTargetLabel}`, 'success');
|
|
369
|
-
}
|
|
370
|
-
await this.refreshSkillsList({ silent: true });
|
|
371
|
-
} catch (e) {
|
|
372
|
-
this.showMessage('ZIP 导入失败', 'error');
|
|
373
|
-
} finally {
|
|
374
|
-
this.skillsZipImporting = false;
|
|
375
|
-
this.resetSkillsZipImportInput();
|
|
376
|
-
await this.scanImportableSkills({ silent: true });
|
|
377
|
-
}
|
|
378
|
-
},
|
|
379
|
-
|
|
380
|
-
async exportSelectedSkills() {
|
|
381
|
-
if (this.skillsDeleting || this.skillsExporting || this.skillsZipImporting || this.skillsImporting) return;
|
|
382
|
-
const selected = Array.isArray(this.skillsSelectedNames)
|
|
383
|
-
? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
|
|
384
|
-
: [];
|
|
385
|
-
if (!selected.length) {
|
|
386
|
-
this.showMessage('请先选择要导出的 skill', 'error');
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
this.skillsExporting = true;
|
|
390
|
-
try {
|
|
391
|
-
const res = await api('export-skills', {
|
|
392
|
-
targetApp: this.skillsTargetApp,
|
|
393
|
-
names: selected
|
|
394
|
-
});
|
|
395
|
-
if (res && res.error) {
|
|
396
|
-
this.showMessage(res.error, 'error');
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
if (!res || !res.fileName) {
|
|
400
|
-
this.showMessage('导出失败:未生成压缩包', 'error');
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
const exportedCount = Array.isArray(res.exported) ? res.exported.length : 0;
|
|
404
|
-
const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
|
|
405
|
-
const downloadUrl = typeof res.downloadPath === 'string' && res.downloadPath.trim()
|
|
406
|
-
? res.downloadPath.trim()
|
|
407
|
-
: `/download/${encodeURIComponent(res.fileName)}`;
|
|
408
|
-
const link = document.createElement('a');
|
|
409
|
-
link.href = downloadUrl;
|
|
410
|
-
link.download = res.fileName;
|
|
411
|
-
document.body.appendChild(link);
|
|
412
|
-
link.click();
|
|
413
|
-
document.body.removeChild(link);
|
|
414
|
-
if (failedCount > 0) {
|
|
415
|
-
this.showMessage(`已导出 ${exportedCount} 个,失败 ${failedCount} 个`, 'error');
|
|
416
|
-
} else {
|
|
417
|
-
this.showMessage(`已从 ${this.skillsTargetLabel} 导出 ${exportedCount} 个 skill`, 'success');
|
|
418
|
-
}
|
|
419
|
-
} catch (e) {
|
|
420
|
-
this.showMessage('导出 skill 失败', 'error');
|
|
421
|
-
} finally {
|
|
422
|
-
this.skillsExporting = false;
|
|
423
|
-
}
|
|
424
|
-
},
|
|
425
|
-
|
|
426
|
-
async deleteSelectedSkills() {
|
|
427
|
-
if (this.skillsDeleting || this.skillsZipImporting || this.skillsExporting || this.skillsImporting) return;
|
|
428
|
-
if (this.skillsScanningImports) {
|
|
429
|
-
this.showMessage('正在扫描导入源,请稍后再试', 'error');
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
const selected = Array.isArray(this.skillsSelectedNames)
|
|
433
|
-
? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
|
|
434
|
-
: [];
|
|
435
|
-
if (!selected.length) {
|
|
436
|
-
this.showMessage('请先选择要删除的 skill', 'error');
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
const confirmed = await this.requestConfirmDialog({
|
|
440
|
-
title: '删除 Skills',
|
|
441
|
-
message: `确认从 ${this.skillsTargetLabel} 删除 ${selected.length} 个 skill 吗?此操作不可撤销。`,
|
|
442
|
-
confirmText: '删除',
|
|
443
|
-
cancelText: '取消',
|
|
444
|
-
confirmDisabled: () => this.skillsDeleting || this.skillsScanningImports,
|
|
445
|
-
danger: true
|
|
446
|
-
});
|
|
447
|
-
if (!confirmed) {
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
this.skillsDeleting = true;
|
|
452
|
-
try {
|
|
453
|
-
const res = await api('delete-skills', {
|
|
454
|
-
targetApp: this.skillsTargetApp,
|
|
455
|
-
names: selected
|
|
456
|
-
});
|
|
457
|
-
if (res.error) {
|
|
458
|
-
this.showMessage(res.error, 'error');
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
const deletedCount = Array.isArray(res.deleted) ? res.deleted.length : 0;
|
|
463
|
-
const failedList = Array.isArray(res.failed) ? res.failed : [];
|
|
464
|
-
const failedCount = failedList.length;
|
|
465
|
-
if (failedCount > 0 && deletedCount > 0) {
|
|
466
|
-
this.showMessage(`已删除 ${deletedCount} 个,失败 ${failedCount} 个`, 'error');
|
|
467
|
-
} else if (failedCount > 0) {
|
|
468
|
-
const first = failedList[0] && failedList[0].error ? failedList[0].error : '删除失败';
|
|
469
|
-
this.showMessage(first, 'error');
|
|
470
|
-
} else {
|
|
471
|
-
this.showMessage(`已从 ${this.skillsTargetLabel} 删除 ${deletedCount} 个 skill`, 'success');
|
|
472
|
-
}
|
|
473
|
-
await this.refreshSkillsList({ silent: true });
|
|
474
|
-
} catch (e) {
|
|
475
|
-
this.showMessage('删除 skill 失败', 'error');
|
|
476
|
-
} finally {
|
|
477
|
-
this.skillsDeleting = false;
|
|
478
|
-
await this.scanImportableSkills({ silent: true });
|
|
479
|
-
}
|
|
480
|
-
},
|
|
481
|
-
|
|
482
|
-
openSkillsMenu() {
|
|
483
|
-
// Open skills manager modal as menu
|
|
484
|
-
this.openSkillsManager();
|
|
485
|
-
},
|
|
486
|
-
|
|
487
|
-
async importSingleSkill(skill) {
|
|
488
|
-
if (this.skillsImporting || this.skillsZipImporting) return;
|
|
489
|
-
const key = this.buildSkillImportKey(skill);
|
|
490
|
-
this.skillsImporting = true;
|
|
491
|
-
try {
|
|
492
|
-
const res = await api('import-skills', {
|
|
493
|
-
targetApp: this.skillsTargetApp,
|
|
494
|
-
items: [skill]
|
|
495
|
-
});
|
|
496
|
-
if (res && res.error) {
|
|
497
|
-
this.showMessage(res.error, 'error');
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
const imported = Array.isArray(res && res.imported) ? res.imported : [];
|
|
501
|
-
if (imported.length > 0) {
|
|
502
|
-
this.showMessage(`已导入 ${skill.displayName || skill.name}`, 'success');
|
|
503
|
-
await this.refreshSkillsList({ silent: true });
|
|
504
|
-
await this.scanImportableSkills({ silent: true });
|
|
505
|
-
}
|
|
506
|
-
} catch (e) {
|
|
507
|
-
this.showMessage('导入失败', 'error');
|
|
508
|
-
} finally {
|
|
509
|
-
this.skillsImporting = false;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
|
-
}
|
|
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
|
+
if (typeof this.saveNavState === 'function') this.saveNavState();
|
|
58
|
+
}
|
|
59
|
+
if (!refresh) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return await this.loadSkillsMarketOverview({
|
|
63
|
+
forceRefresh: true,
|
|
64
|
+
silent
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
async openSkillsManager(options = {}) {
|
|
69
|
+
if (
|
|
70
|
+
this.skillsLoading
|
|
71
|
+
|| this.skillsDeleting
|
|
72
|
+
|| this.skillsScanningImports
|
|
73
|
+
|| this.skillsImporting
|
|
74
|
+
|| this.skillsZipImporting
|
|
75
|
+
|| this.skillsExporting
|
|
76
|
+
|| this.skillsMarketLoading
|
|
77
|
+
) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
let targetApp;
|
|
81
|
+
try {
|
|
82
|
+
targetApp = this.normalizeSkillsTargetApp(options && options.targetApp ? options.targetApp : this.skillsTargetApp);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
showUnsupportedSkillsTargetMessage(this, options && options.targetApp);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
const targetChanged = targetApp !== this.skillsTargetApp;
|
|
88
|
+
if (targetChanged) {
|
|
89
|
+
this.skillsTargetApp = targetApp;
|
|
90
|
+
this.resetSkillsTargetState();
|
|
91
|
+
} else {
|
|
92
|
+
this.skillsSelectedNames = [];
|
|
93
|
+
this.skillsKeyword = '';
|
|
94
|
+
this.skillsStatusFilter = 'all';
|
|
95
|
+
this.skillsImportSelectedKeys = [];
|
|
96
|
+
}
|
|
97
|
+
this.showSkillsModal = true;
|
|
98
|
+
await this.refreshSkillsList({ silent: false });
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
closeSkillsModal() {
|
|
102
|
+
const busy = !!(
|
|
103
|
+
this.skillsLoading
|
|
104
|
+
|| this.skillsDeleting
|
|
105
|
+
|| this.skillsScanningImports
|
|
106
|
+
|| this.skillsImporting
|
|
107
|
+
|| this.skillsZipImporting
|
|
108
|
+
|| this.skillsExporting
|
|
109
|
+
);
|
|
110
|
+
if (busy) return;
|
|
111
|
+
this.showSkillsModal = false;
|
|
112
|
+
this.skillsSelectedNames = [];
|
|
113
|
+
this.skillsImportSelectedKeys = [];
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
async refreshSkillsList(options = {}) {
|
|
117
|
+
this.skillsLoading = true;
|
|
118
|
+
try {
|
|
119
|
+
const res = await api('list-skills', {
|
|
120
|
+
targetApp: this.skillsTargetApp
|
|
121
|
+
});
|
|
122
|
+
if (res.error) {
|
|
123
|
+
this.skillsRootPath = '';
|
|
124
|
+
this.skillsList = [];
|
|
125
|
+
this.skillsSelectedNames = [];
|
|
126
|
+
this.showMessage(res.error, 'error');
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
const exists = res.exists !== false;
|
|
130
|
+
if (!exists) {
|
|
131
|
+
this.skillsRootPath = res.root || '';
|
|
132
|
+
this.skillsList = [];
|
|
133
|
+
this.skillsSelectedNames = [];
|
|
134
|
+
if (!options.silent) {
|
|
135
|
+
this.showMessage(`${this.skillsTargetLabel} skills 目录不存在,已按空列表显示`, 'info');
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
this.skillsRootPath = res.root || '';
|
|
140
|
+
this.skillsList = Array.isArray(res.items) ? res.items : [];
|
|
141
|
+
const currentNames = new Set((Array.isArray(this.skillsList) ? this.skillsList : [])
|
|
142
|
+
.map((item) => (item && typeof item.name === 'string' ? item.name.trim() : ''))
|
|
143
|
+
.filter(Boolean));
|
|
144
|
+
this.skillsSelectedNames = (Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : [])
|
|
145
|
+
.filter((name) => currentNames.has(name));
|
|
146
|
+
return true;
|
|
147
|
+
} catch (e) {
|
|
148
|
+
this.skillsRootPath = '';
|
|
149
|
+
this.skillsList = [];
|
|
150
|
+
this.skillsSelectedNames = [];
|
|
151
|
+
this.showMessage('加载 skills 失败', 'error');
|
|
152
|
+
return false;
|
|
153
|
+
} finally {
|
|
154
|
+
this.skillsLoading = false;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
async loadSkillsMarketOverview(options = {}) {
|
|
159
|
+
if (this.skillsMarketLoading) return false;
|
|
160
|
+
const silent = !!(options && options.silent);
|
|
161
|
+
const forceRefresh = !!(options && options.forceRefresh);
|
|
162
|
+
this.skillsMarketLoading = true;
|
|
163
|
+
let localLoaded = this.skillsMarketLocalLoadedOnce === true;
|
|
164
|
+
let importLoaded = this.skillsMarketImportLoadedOnce === true;
|
|
165
|
+
try {
|
|
166
|
+
if (forceRefresh || !localLoaded) {
|
|
167
|
+
localLoaded = await this.refreshSkillsList({ silent });
|
|
168
|
+
this.skillsMarketLocalLoadedOnce = localLoaded;
|
|
169
|
+
}
|
|
170
|
+
if (forceRefresh || !importLoaded) {
|
|
171
|
+
importLoaded = await this.scanImportableSkills({ silent });
|
|
172
|
+
this.skillsMarketImportLoadedOnce = importLoaded;
|
|
173
|
+
}
|
|
174
|
+
return !!(localLoaded && importLoaded);
|
|
175
|
+
} finally {
|
|
176
|
+
this.skillsMarketLoading = false;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
resetSkillsFilters() {
|
|
181
|
+
this.skillsKeyword = '';
|
|
182
|
+
this.skillsStatusFilter = 'all';
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
toggleAllSkillsSelection() {
|
|
186
|
+
const selectable = this.skillsSelectableNames;
|
|
187
|
+
if (this.skillsAllSelected) {
|
|
188
|
+
const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
|
|
189
|
+
selectable.forEach((name) => selectedSet.delete(name));
|
|
190
|
+
this.skillsSelectedNames = Array.from(selectedSet);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
|
|
194
|
+
selectable.forEach((name) => selectedSet.add(name));
|
|
195
|
+
this.skillsSelectedNames = Array.from(selectedSet);
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
buildSkillImportKey(item) {
|
|
199
|
+
const safe = item && typeof item === 'object' ? item : {};
|
|
200
|
+
const sourceApp = typeof safe.sourceApp === 'string' ? safe.sourceApp.trim().toLowerCase() : '';
|
|
201
|
+
const name = typeof safe.name === 'string' ? safe.name.trim() : '';
|
|
202
|
+
if (!sourceApp || !name) return '';
|
|
203
|
+
return `${sourceApp}:${name}`;
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
toggleAllSkillsImportSelection() {
|
|
207
|
+
const selectable = this.skillsImportSelectableKeys;
|
|
208
|
+
if (this.skillsImportAllSelected) {
|
|
209
|
+
this.skillsImportSelectedKeys = [];
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
this.skillsImportSelectedKeys = [...selectable];
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
async scanImportableSkills(options = {}) {
|
|
216
|
+
if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return false;
|
|
217
|
+
const silent = !!(options && options.silent);
|
|
218
|
+
this.skillsScanningImports = true;
|
|
219
|
+
try {
|
|
220
|
+
const res = await api('scan-unmanaged-skills', {
|
|
221
|
+
targetApp: this.skillsTargetApp
|
|
222
|
+
});
|
|
223
|
+
if (res.error) {
|
|
224
|
+
this.skillsImportList = [];
|
|
225
|
+
this.skillsImportSelectedKeys = [];
|
|
226
|
+
if (!silent) {
|
|
227
|
+
this.showMessage(res.error, 'error');
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
this.skillsImportList = Array.isArray(res.items) ? res.items : [];
|
|
232
|
+
const availableKeys = new Set(this.skillsImportSelectableKeys);
|
|
233
|
+
this.skillsImportSelectedKeys = (Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : [])
|
|
234
|
+
.filter((key) => availableKeys.has(key));
|
|
235
|
+
if (!silent && this.skillsImportList.length === 0) {
|
|
236
|
+
this.showMessage('未扫描到可导入 skill', 'info');
|
|
237
|
+
} else if (!silent) {
|
|
238
|
+
this.showMessage(`扫描到 ${this.skillsImportList.length} 个可导入 skill`, 'success');
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
} catch (e) {
|
|
242
|
+
this.skillsImportList = [];
|
|
243
|
+
this.skillsImportSelectedKeys = [];
|
|
244
|
+
if (!silent) {
|
|
245
|
+
this.showMessage('扫描可导入 skill 失败', 'error');
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
} finally {
|
|
249
|
+
this.skillsScanningImports = false;
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
async importSelectedSkills() {
|
|
254
|
+
if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return;
|
|
255
|
+
const selectedSet = new Set(Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : []);
|
|
256
|
+
const selectedItems = (Array.isArray(this.skillsImportList) ? this.skillsImportList : [])
|
|
257
|
+
.filter((item) => selectedSet.has(this.buildSkillImportKey(item)))
|
|
258
|
+
.map((item) => ({
|
|
259
|
+
name: item.name,
|
|
260
|
+
sourceApp: item.sourceApp
|
|
261
|
+
}));
|
|
262
|
+
if (!selectedItems.length) {
|
|
263
|
+
this.showMessage('请先选择要导入的 skill', 'error');
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
this.skillsImporting = true;
|
|
268
|
+
try {
|
|
269
|
+
const res = await api('import-skills', {
|
|
270
|
+
targetApp: this.skillsTargetApp,
|
|
271
|
+
items: selectedItems
|
|
272
|
+
});
|
|
273
|
+
if (res.error) {
|
|
274
|
+
this.showMessage(res.error, 'error');
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const importedCount = Array.isArray(res.imported) ? res.imported.length : 0;
|
|
278
|
+
const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
|
|
279
|
+
if (failedCount > 0 && importedCount > 0) {
|
|
280
|
+
this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
|
|
281
|
+
} else if (failedCount > 0) {
|
|
282
|
+
const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
|
|
283
|
+
this.showMessage(first, 'error');
|
|
284
|
+
} else {
|
|
285
|
+
this.showMessage(`已导入 ${importedCount} 个 skill 到 ${this.skillsTargetLabel}`, 'success');
|
|
286
|
+
}
|
|
287
|
+
await this.refreshSkillsList({ silent: true });
|
|
288
|
+
} catch (e) {
|
|
289
|
+
this.showMessage('导入 skill 失败', 'error');
|
|
290
|
+
} finally {
|
|
291
|
+
this.skillsImporting = false;
|
|
292
|
+
await this.scanImportableSkills({ silent: true });
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
|
|
296
|
+
triggerSkillsZipImport() {
|
|
297
|
+
const input = this.$refs.skillsZipImportInput;
|
|
298
|
+
if (input) {
|
|
299
|
+
input.value = '';
|
|
300
|
+
input.click();
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
|
|
304
|
+
handleSkillsZipImportChange(event) {
|
|
305
|
+
const file = event && event.target && event.target.files ? event.target.files[0] : null;
|
|
306
|
+
if (file) {
|
|
307
|
+
void this.importSkillsFromZipFile(file);
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
resetSkillsZipImportInput() {
|
|
312
|
+
const el = this.$refs.skillsZipImportInput;
|
|
313
|
+
if (el) {
|
|
314
|
+
el.value = '';
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
|
|
318
|
+
async uploadSkillsZipStream(file) {
|
|
319
|
+
const fileName = (file && typeof file.name === 'string' && file.name.trim())
|
|
320
|
+
? file.name.trim()
|
|
321
|
+
: `${this.skillsTargetApp}-skills.zip`;
|
|
322
|
+
const response = await fetch(`/api/import-skills-zip?targetApp=${encodeURIComponent(this.skillsTargetApp)}`, {
|
|
323
|
+
method: 'POST',
|
|
324
|
+
headers: {
|
|
325
|
+
'x-codexmate-file-name': encodeURIComponent(fileName)
|
|
326
|
+
},
|
|
327
|
+
body: file
|
|
328
|
+
});
|
|
329
|
+
let payload = {};
|
|
330
|
+
try {
|
|
331
|
+
payload = await response.json();
|
|
332
|
+
} catch (_) {
|
|
333
|
+
payload = {
|
|
334
|
+
error: response.ok
|
|
335
|
+
? 'ZIP 导入响应无效'
|
|
336
|
+
: `上传失败(HTTP ${response.status})`
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
if (!response.ok && !payload.error) {
|
|
340
|
+
payload.error = `上传失败(HTTP ${response.status})`;
|
|
341
|
+
}
|
|
342
|
+
return payload;
|
|
343
|
+
},
|
|
344
|
+
|
|
345
|
+
async importSkillsFromZipFile(file) {
|
|
346
|
+
if (this.skillsDeleting || this.skillsScanningImports || this.skillsZipImporting || this.skillsImporting || this.skillsExporting) return;
|
|
347
|
+
const maxSize = 20 * 1024 * 1024;
|
|
348
|
+
if (file.size > maxSize) {
|
|
349
|
+
this.showMessage('ZIP 文件过大,限制 20MB', 'error');
|
|
350
|
+
this.resetSkillsZipImportInput();
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
this.skillsZipImporting = true;
|
|
354
|
+
try {
|
|
355
|
+
const res = await this.uploadSkillsZipStream(file);
|
|
356
|
+
if (res && res.error) {
|
|
357
|
+
this.showMessage(res.error, 'error');
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const importedCount = Array.isArray(res && res.imported) ? res.imported.length : 0;
|
|
361
|
+
const failedCount = Array.isArray(res && res.failed) ? res.failed.length : 0;
|
|
362
|
+
if (failedCount > 0 && importedCount > 0) {
|
|
363
|
+
this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
|
|
364
|
+
} else if (failedCount > 0) {
|
|
365
|
+
const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
|
|
366
|
+
this.showMessage(first, 'error');
|
|
367
|
+
} else {
|
|
368
|
+
this.showMessage(`已导入 ${importedCount} 个 skill 到 ${this.skillsTargetLabel}`, 'success');
|
|
369
|
+
}
|
|
370
|
+
await this.refreshSkillsList({ silent: true });
|
|
371
|
+
} catch (e) {
|
|
372
|
+
this.showMessage('ZIP 导入失败', 'error');
|
|
373
|
+
} finally {
|
|
374
|
+
this.skillsZipImporting = false;
|
|
375
|
+
this.resetSkillsZipImportInput();
|
|
376
|
+
await this.scanImportableSkills({ silent: true });
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
async exportSelectedSkills() {
|
|
381
|
+
if (this.skillsDeleting || this.skillsExporting || this.skillsZipImporting || this.skillsImporting) return;
|
|
382
|
+
const selected = Array.isArray(this.skillsSelectedNames)
|
|
383
|
+
? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
|
|
384
|
+
: [];
|
|
385
|
+
if (!selected.length) {
|
|
386
|
+
this.showMessage('请先选择要导出的 skill', 'error');
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
this.skillsExporting = true;
|
|
390
|
+
try {
|
|
391
|
+
const res = await api('export-skills', {
|
|
392
|
+
targetApp: this.skillsTargetApp,
|
|
393
|
+
names: selected
|
|
394
|
+
});
|
|
395
|
+
if (res && res.error) {
|
|
396
|
+
this.showMessage(res.error, 'error');
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (!res || !res.fileName) {
|
|
400
|
+
this.showMessage('导出失败:未生成压缩包', 'error');
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const exportedCount = Array.isArray(res.exported) ? res.exported.length : 0;
|
|
404
|
+
const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
|
|
405
|
+
const downloadUrl = typeof res.downloadPath === 'string' && res.downloadPath.trim()
|
|
406
|
+
? res.downloadPath.trim()
|
|
407
|
+
: `/download/${encodeURIComponent(res.fileName)}`;
|
|
408
|
+
const link = document.createElement('a');
|
|
409
|
+
link.href = downloadUrl;
|
|
410
|
+
link.download = res.fileName;
|
|
411
|
+
document.body.appendChild(link);
|
|
412
|
+
link.click();
|
|
413
|
+
document.body.removeChild(link);
|
|
414
|
+
if (failedCount > 0) {
|
|
415
|
+
this.showMessage(`已导出 ${exportedCount} 个,失败 ${failedCount} 个`, 'error');
|
|
416
|
+
} else {
|
|
417
|
+
this.showMessage(`已从 ${this.skillsTargetLabel} 导出 ${exportedCount} 个 skill`, 'success');
|
|
418
|
+
}
|
|
419
|
+
} catch (e) {
|
|
420
|
+
this.showMessage('导出 skill 失败', 'error');
|
|
421
|
+
} finally {
|
|
422
|
+
this.skillsExporting = false;
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
|
|
426
|
+
async deleteSelectedSkills() {
|
|
427
|
+
if (this.skillsDeleting || this.skillsZipImporting || this.skillsExporting || this.skillsImporting) return;
|
|
428
|
+
if (this.skillsScanningImports) {
|
|
429
|
+
this.showMessage('正在扫描导入源,请稍后再试', 'error');
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const selected = Array.isArray(this.skillsSelectedNames)
|
|
433
|
+
? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
|
|
434
|
+
: [];
|
|
435
|
+
if (!selected.length) {
|
|
436
|
+
this.showMessage('请先选择要删除的 skill', 'error');
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const confirmed = await this.requestConfirmDialog({
|
|
440
|
+
title: '删除 Skills',
|
|
441
|
+
message: `确认从 ${this.skillsTargetLabel} 删除 ${selected.length} 个 skill 吗?此操作不可撤销。`,
|
|
442
|
+
confirmText: '删除',
|
|
443
|
+
cancelText: '取消',
|
|
444
|
+
confirmDisabled: () => this.skillsDeleting || this.skillsScanningImports,
|
|
445
|
+
danger: true
|
|
446
|
+
});
|
|
447
|
+
if (!confirmed) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
this.skillsDeleting = true;
|
|
452
|
+
try {
|
|
453
|
+
const res = await api('delete-skills', {
|
|
454
|
+
targetApp: this.skillsTargetApp,
|
|
455
|
+
names: selected
|
|
456
|
+
});
|
|
457
|
+
if (res.error) {
|
|
458
|
+
this.showMessage(res.error, 'error');
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const deletedCount = Array.isArray(res.deleted) ? res.deleted.length : 0;
|
|
463
|
+
const failedList = Array.isArray(res.failed) ? res.failed : [];
|
|
464
|
+
const failedCount = failedList.length;
|
|
465
|
+
if (failedCount > 0 && deletedCount > 0) {
|
|
466
|
+
this.showMessage(`已删除 ${deletedCount} 个,失败 ${failedCount} 个`, 'error');
|
|
467
|
+
} else if (failedCount > 0) {
|
|
468
|
+
const first = failedList[0] && failedList[0].error ? failedList[0].error : '删除失败';
|
|
469
|
+
this.showMessage(first, 'error');
|
|
470
|
+
} else {
|
|
471
|
+
this.showMessage(`已从 ${this.skillsTargetLabel} 删除 ${deletedCount} 个 skill`, 'success');
|
|
472
|
+
}
|
|
473
|
+
await this.refreshSkillsList({ silent: true });
|
|
474
|
+
} catch (e) {
|
|
475
|
+
this.showMessage('删除 skill 失败', 'error');
|
|
476
|
+
} finally {
|
|
477
|
+
this.skillsDeleting = false;
|
|
478
|
+
await this.scanImportableSkills({ silent: true });
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
|
|
482
|
+
openSkillsMenu() {
|
|
483
|
+
// Open skills manager modal as menu
|
|
484
|
+
this.openSkillsManager();
|
|
485
|
+
},
|
|
486
|
+
|
|
487
|
+
async importSingleSkill(skill) {
|
|
488
|
+
if (this.skillsImporting || this.skillsZipImporting) return;
|
|
489
|
+
const key = this.buildSkillImportKey(skill);
|
|
490
|
+
this.skillsImporting = true;
|
|
491
|
+
try {
|
|
492
|
+
const res = await api('import-skills', {
|
|
493
|
+
targetApp: this.skillsTargetApp,
|
|
494
|
+
items: [skill]
|
|
495
|
+
});
|
|
496
|
+
if (res && res.error) {
|
|
497
|
+
this.showMessage(res.error, 'error');
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const imported = Array.isArray(res && res.imported) ? res.imported : [];
|
|
501
|
+
if (imported.length > 0) {
|
|
502
|
+
this.showMessage(`已导入 ${skill.displayName || skill.name}`, 'success');
|
|
503
|
+
await this.refreshSkillsList({ silent: true });
|
|
504
|
+
await this.scanImportableSkills({ silent: true });
|
|
505
|
+
}
|
|
506
|
+
} catch (e) {
|
|
507
|
+
this.showMessage('导入失败', 'error');
|
|
508
|
+
} finally {
|
|
509
|
+
this.skillsImporting = false;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
}
|