@eum-agent/skill-management 0.0.0-stage → 1.0.0

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 (4) hide show
  1. package/dist/index.js +3155 -0
  2. package/package.json +48 -3
  3. package/ui/ui.js +1804 -0
  4. package/README.md +0 -3
package/ui/ui.js ADDED
@@ -0,0 +1,1804 @@
1
+ import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ //#region src/tool-names.ts
4
+ /** Canonical names shared by tool registration and browser presentation. */
5
+ var TOOL_NAMES = [
6
+ "skill_read",
7
+ "skill_write",
8
+ "skill_install",
9
+ "skill_uninstall",
10
+ "skill_set_preload"
11
+ ];
12
+ //#endregion
13
+ //#region src/ui/metadata.ts
14
+ var CATALOGUES$1 = {
15
+ "en-US": {
16
+ section: "Built-in plugins",
17
+ group: "Skills",
18
+ skill_read: "Read skill",
19
+ skill_write: "Save skill",
20
+ skill_install: "Install skill",
21
+ skill_uninstall: "Uninstall skill",
22
+ skill_set_preload: "Set preloaded skills"
23
+ },
24
+ "zh-CN": {
25
+ section: "内置插件",
26
+ group: "技能",
27
+ skill_read: "读取技能",
28
+ skill_write: "保存技能",
29
+ skill_install: "安装技能",
30
+ skill_uninstall: "卸载技能",
31
+ skill_set_preload: "设置预加载技能"
32
+ }
33
+ };
34
+ var names = new Set(TOOL_NAMES);
35
+ /** Registers presentation facets with the same activation lifetime as the tools. */
36
+ function registerMetadata(ctx) {
37
+ ctx.i18n.register(CATALOGUES$1, "en-US");
38
+ ctx.i18n.contribute(Object.fromEntries(Object.entries(CATALOGUES$1).map(([language, catalogue]) => [language, Object.fromEntries([...names].map((tool) => [`transcript.actions.${tool}`, catalogue[tool] ?? tool]))])), "en-US");
39
+ ctx.slots.register("chat.tool.presentation", {
40
+ id: "tool-metadata",
41
+ describe: ({ call }) => {
42
+ if (!names.has(call.name)) return void 0;
43
+ const input = call.input !== null && typeof call.input === "object" ? call.input : {};
44
+ const summary = [
45
+ "path",
46
+ "url",
47
+ "query",
48
+ "command",
49
+ "skill",
50
+ "id",
51
+ "name",
52
+ "task",
53
+ "prompt"
54
+ ].flatMap((key) => typeof input[key] === "string" ? [input[key]] : []).slice(0, 2).join(" · ").replace(/\s+/g, " ").slice(0, 240);
55
+ return {
56
+ label: names.has(call.name) ? ctx.i18n.t(call.name) : call.name,
57
+ icon: "hammer",
58
+ summary
59
+ };
60
+ }
61
+ });
62
+ ctx.slots.register("shell.tools.group", {
63
+ id: "tool-groups",
64
+ describe: (tool) => {
65
+ if (tool.plugin !== ctx.plugin) return void 0;
66
+ return {
67
+ key: `plugin:${ctx.plugin}`,
68
+ label: ctx.i18n.t("group"),
69
+ source: ctx.plugin,
70
+ sectionLabel: ctx.i18n.t("section"),
71
+ sectionOrder: 1,
72
+ order: 3
73
+ };
74
+ }
75
+ });
76
+ }
77
+ /** Browser translations keyed by the product's supported language-region IDs. */
78
+ var CATALOGUES = {
79
+ "zh-CN": {
80
+ "skills.title": "技能设置",
81
+ "skills.directories": "技能目录",
82
+ "skills.enable": "启用 {{id}}",
83
+ "skills.column.enabled": "启用",
84
+ "skills.column.skill": "技能",
85
+ "skills.column.actions": "操作",
86
+ "skills.preloadDisabled": "请先启用此技能",
87
+ "skills.preloadOn": "已预加载:正文自动加入提示词。点击改为按需读取。",
88
+ "skills.preloadOff": "按需读取:需要时再加载正文。点击开启预加载。",
89
+ "skills.layer.global": "全局",
90
+ "skills.layer.agent": "智能体",
91
+ "skills.preload": "预载 {{id}}",
92
+ "skills.missing": "缺失",
93
+ "skills.missingHint": "已预载,但全局层和智能体层都找不到。",
94
+ "skills.unpreload": "取消预载",
95
+ "skills.failed": "无法读取的技能",
96
+ "skills.empty": "还没有技能",
97
+ "skills.emptyHint": "从技能站、GitHub 或本地目录安装,或把技能目录放进上面的目录里。",
98
+ "skills.install": "安装技能",
99
+ "skills.bulkActions": "批量操作",
100
+ "skills.enableAll": "全部启用",
101
+ "skills.disableAll": "全部禁用",
102
+ "skills.deleteAll": "全部删除",
103
+ "uninstall.allBody": "确定删除当前列表中的 {{count}} 个技能?技能目录及其文件将被删除,此操作不可撤销。",
104
+ "uninstall.allGlobal": "列表包含全局技能,删除后所有智能体均无法继续使用这些技能。",
105
+ "skills.uninstall": "卸载",
106
+ "skills.uninstallNamed": "卸载 {{id}}",
107
+ "skills.copyPath": "复制路径 {{path}}",
108
+ "skills.pathCopied": "已复制路径",
109
+ "skills.pathCopyFailed": "无法复制路径",
110
+ "skills.normalize": "转为标准",
111
+ "skills.normalizeNamed": "把 {{id}} 转为标准",
112
+ "skills.nonStandard": "不合规范",
113
+ "skills.saveFailed": "没能保存预载",
114
+ "skills.retry": "重试",
115
+ "skills.origin.clawhub": "ClawHub · {{name}}",
116
+ "skills.origin.tencent-skillhub": "腾讯 SkillHub · {{name}}",
117
+ "skills.origin.skills-sh": "skills.sh · {{name}}",
118
+ "skills.origin.github": "GitHub · {{name}}",
119
+ "skills.origin.local": "本地",
120
+ "skills.issue.syntax": "技能信息不是有效的 YAML",
121
+ "skills.issue.name-missing": "缺少 name 字段",
122
+ "skills.issue.name-mismatch": "name 字段({{detail}})与目录名称不一致",
123
+ "skills.issue.name-invalid": "name 字段({{detail}})不符合命名规范",
124
+ "skills.issue.dir-invalid": "目录名称 {{detail}} 不符合命名规范,需重命名",
125
+ "skills.issue.extra-field": "不支持的字段:{{detail}}",
126
+ "skills.issue.metadata-value": "metadata 字段 {{detail}} 的值必须为字符串",
127
+ "skills.issue.description-long": "说明超过 1024 个字符",
128
+ "skills.issue.compatibility-long": "compatibility 超过 500 个字符",
129
+ "skills.issue.field-type": "字段 {{detail}} 的类型不符合规范",
130
+ "install.title": "安装技能",
131
+ "install.queryPlaceholder": "搜索名称、用途或关键词",
132
+ "install.load": "读取",
133
+ "install.chooseDirectory": "选择目录",
134
+ "install.chooseArchive": "选择压缩包",
135
+ "install.selectAll": "全选",
136
+ "install.stars": "星标",
137
+ "install.downloads": "下载量",
138
+ "install.searchEmpty": "输入关键词搜索技能",
139
+ "install.localEmpty": "请选择目录或压缩包",
140
+ "install.githubEmpty": "输入 GitHub 仓库地址以读取技能",
141
+ "install.selectedCount": "已选择 {{count}} 项",
142
+ "install.skippedCount": "已跳过 {{count}} 个同名技能",
143
+ "install.list": "技能列表",
144
+ "install.close": "关闭",
145
+ "install.from": "安装来源",
146
+ "install.from.registry": "SkillHub",
147
+ "install.from.github": "GitHub",
148
+ "install.from.local": "本地文件",
149
+ "install.registry": "技能市场",
150
+ "install.registry.clawhub": "ClawHub",
151
+ "install.registry.tencent-skillhub": "腾讯 SkillHub",
152
+ "install.registry.skills-sh": "skills.sh",
153
+ "install.query": "搜索技能",
154
+ "install.search": "搜索",
155
+ "install.searching": "搜索中…",
156
+ "install.noResults": "没有找到相关技能",
157
+ "install.needsLogin": "需要登录,本版本暂不支持",
158
+ "install.githubUrl": "仓库地址",
159
+ "install.githubHelp": "如 https://github.com/owner/repo,可带 /tree/<分支>/<目录>",
160
+ "install.localKind": "来源类型",
161
+ "install.localKind.directory": "目录",
162
+ "install.localKind.zip": "ZIP 压缩包",
163
+ "install.localPath": "本地路径",
164
+ "install.next": "下一步",
165
+ "install.fetching": "正在读取技能信息…",
166
+ "install.back": "上一步",
167
+ "install.cancel": "取消",
168
+ "install.target": "安装范围",
169
+ "install.target.agent": "当前智能体",
170
+ "install.target.global": "所有智能体",
171
+ "install.sourceLabel": "安装来源",
172
+ "install.id": "技能标识",
173
+ "install.files": "{{count}} 个文件 · {{size}}",
174
+ "install.scripts": "脚本文件({{count}})",
175
+ "install.willNormalize": "格式规范化",
176
+ "install.normalizeHelp": "安装时将按 Agent Skills 规范整理 SKILL.md 的技能信息。",
177
+ "install.selection": "已选择 {{selected}} / {{total}} 个技能",
178
+ "install.conflict": "已有同名技能",
179
+ "install.conflict.replace": "替换现有技能",
180
+ "install.conflict.rename": "重命名",
181
+ "install.conflict.skip": "跳过",
182
+ "install.idInvalid": "技能标识仅支持小写字母、数字和单个连字符,最长 64 个字符",
183
+ "install.idTaken": "所选安装范围内已存在同名技能",
184
+ "install.cannot": "无法安装",
185
+ "install.nothing": "所选来源中未发现可安装的技能",
186
+ "install.confirm": "安装",
187
+ "install.installing": "正在安装…",
188
+ "install.done": "完成",
189
+ "install.installed": "已安装",
190
+ "install.skipped": "已跳过",
191
+ "install.installedToast": "已安装 {{count}} 个技能",
192
+ "install.pick": "安装 {{id}}",
193
+ "uninstall.title": "卸载技能",
194
+ "uninstall.body": "卸载 {{id}}({{layer}})?整个技能目录会被删除。",
195
+ "uninstall.global": "所有智能体都会失去这个技能。",
196
+ "uninstall.preloaded": "它在预加载里,卸载后会显示为缺失。",
197
+ "uninstall.confirm": "卸载",
198
+ "normalize.title": "转为标准",
199
+ "normalize.reasons": "不合规范之处",
200
+ "normalize.result": "改写后的 frontmatter",
201
+ "normalize.scope": "只改 frontmatter,正文与其他文件不动。",
202
+ "normalize.confirm": "转为标准",
203
+ "normalize.loading": "正在读取…",
204
+ "skills.loading": "正在加载…"
205
+ },
206
+ "en-US": {
207
+ "skills.title": "Skills",
208
+ "skills.directories": "Skill directories",
209
+ "skills.enable": "Enable {{id}}",
210
+ "skills.column.enabled": "Enabled",
211
+ "skills.column.skill": "Skill",
212
+ "skills.column.actions": "Actions",
213
+ "skills.preloadDisabled": "Enable this skill first",
214
+ "skills.preloadOn": "Preloaded into the prompt. Click to read on demand instead.",
215
+ "skills.preloadOff": "Read on demand. Click to preload into the prompt.",
216
+ "skills.layer.global": "Global",
217
+ "skills.layer.agent": "Agent",
218
+ "skills.preload": "Preload {{id}}",
219
+ "skills.missing": "Missing",
220
+ "skills.missingHint": "Preloaded, but neither the global nor the agent layer has it.",
221
+ "skills.unpreload": "Stop preloading",
222
+ "skills.failed": "Skills that cannot be read",
223
+ "skills.empty": "No skills yet",
224
+ "skills.emptyHint": "Install one from a skill site, GitHub or a local directory, or put a skill directory in one of the directories above.",
225
+ "skills.install": "Install skill",
226
+ "skills.bulkActions": "Bulk actions",
227
+ "skills.enableAll": "Enable all",
228
+ "skills.disableAll": "Disable all",
229
+ "skills.deleteAll": "Delete all",
230
+ "uninstall.allBody": "Delete all {{count}} skills in the current list? Their directories and files will be deleted. This cannot be undone.",
231
+ "uninstall.allGlobal": "The list includes global skills. Deleting them removes access for every agent.",
232
+ "skills.uninstall": "Uninstall",
233
+ "skills.uninstallNamed": "Uninstall {{id}}",
234
+ "skills.copyPath": "Copy path {{path}}",
235
+ "skills.pathCopied": "Path copied",
236
+ "skills.pathCopyFailed": "Could not copy the path",
237
+ "skills.normalize": "Make standard",
238
+ "skills.normalizeNamed": "Make {{id}} standard",
239
+ "skills.nonStandard": "Non-standard",
240
+ "skills.saveFailed": "Could not save the preload",
241
+ "skills.retry": "Retry",
242
+ "skills.origin.clawhub": "ClawHub · {{name}}",
243
+ "skills.origin.tencent-skillhub": "Tencent SkillHub · {{name}}",
244
+ "skills.origin.skills-sh": "skills.sh · {{name}}",
245
+ "skills.origin.github": "GitHub · {{name}}",
246
+ "skills.origin.local": "Local",
247
+ "skills.issue.syntax": "The frontmatter is not valid YAML",
248
+ "skills.issue.name-missing": "No name",
249
+ "skills.issue.name-mismatch": "The name ({{detail}}) differs from the directory",
250
+ "skills.issue.name-invalid": "The name ({{detail}}) breaks the naming rule",
251
+ "skills.issue.dir-invalid": "The directory name {{detail}} breaks the naming rule; rename it to be fully standard",
252
+ "skills.issue.extra-field": "A field outside the specification: {{detail}}",
253
+ "skills.issue.metadata-value": "metadata value {{detail}} is not a string",
254
+ "skills.issue.description-long": "The description is longer than 1024 characters",
255
+ "skills.issue.compatibility-long": "compatibility is longer than 500 characters",
256
+ "skills.issue.field-type": "The field {{detail}} has the wrong type",
257
+ "install.title": "Install skill",
258
+ "install.queryPlaceholder": "Search names, uses or keywords",
259
+ "install.load": "Load",
260
+ "install.chooseDirectory": "Choose directory",
261
+ "install.chooseArchive": "Choose archive",
262
+ "install.selectAll": "Select all",
263
+ "install.stars": "Stars",
264
+ "install.downloads": "Downloads",
265
+ "install.searchEmpty": "Enter keywords to search for skills",
266
+ "install.localEmpty": "Choose a directory or archive",
267
+ "install.githubEmpty": "Enter a GitHub repository URL to load skills",
268
+ "install.selectedCount": "{{count}} selected",
269
+ "install.skippedCount": "Skipped {{count}} existing skills",
270
+ "install.list": "Skill list",
271
+ "install.close": "Close",
272
+ "install.from": "Installation source",
273
+ "install.from.registry": "SkillHub",
274
+ "install.from.github": "GitHub",
275
+ "install.from.local": "Local files",
276
+ "install.registry": "Marketplace",
277
+ "install.registry.clawhub": "ClawHub",
278
+ "install.registry.tencent-skillhub": "Tencent SkillHub",
279
+ "install.registry.skills-sh": "skills.sh",
280
+ "install.query": "Search skills",
281
+ "install.search": "Search",
282
+ "install.searching": "Searching…",
283
+ "install.noResults": "No matching skills",
284
+ "install.needsLogin": "Needs sign-in, not supported yet",
285
+ "install.githubUrl": "Repository",
286
+ "install.githubHelp": "Like https://github.com/owner/repo, optionally /tree/<branch>/<directory>",
287
+ "install.localKind": "Kind",
288
+ "install.localKind.directory": "Directory",
289
+ "install.localKind.zip": "Zip file",
290
+ "install.localPath": "Path",
291
+ "install.next": "Next",
292
+ "install.fetching": "Fetching…",
293
+ "install.back": "Back",
294
+ "install.cancel": "Cancel",
295
+ "install.target": "Installation scope",
296
+ "install.target.agent": "Current agent",
297
+ "install.target.global": "All agents",
298
+ "install.sourceLabel": "Installation source",
299
+ "install.id": "Skill ID",
300
+ "install.files": "{{count}} files · {{size}}",
301
+ "install.scripts": "Script files ({{count}})",
302
+ "install.willNormalize": "Format normalization",
303
+ "install.normalizeHelp": "Installation formats the skill metadata in SKILL.md according to the Agent Skills specification.",
304
+ "install.selection": "{{selected}} of {{total}} skills selected",
305
+ "install.conflict": "A skill of this name exists",
306
+ "install.conflict.replace": "Replace",
307
+ "install.conflict.rename": "Rename",
308
+ "install.conflict.skip": "Skip",
309
+ "install.idInvalid": "Lowercase letters, digits and single hyphens, at most 64 characters",
310
+ "install.idTaken": "A skill with this ID already exists in the selected scope",
311
+ "install.cannot": "Cannot be installed",
312
+ "install.nothing": "No installable skills found in this source",
313
+ "install.confirm": "Install",
314
+ "install.installing": "Installing…",
315
+ "install.done": "Done",
316
+ "install.installed": "Installed",
317
+ "install.skipped": "Skipped",
318
+ "install.installedToast": "Installed {{count}} skills",
319
+ "install.pick": "Install {{id}}",
320
+ "uninstall.title": "Uninstall skill",
321
+ "uninstall.body": "Uninstall {{id}} ({{layer}})? The whole skill directory is deleted.",
322
+ "uninstall.global": "Every agent loses this skill.",
323
+ "uninstall.preloaded": "It is preloaded, and will show as missing.",
324
+ "uninstall.confirm": "Uninstall",
325
+ "normalize.title": "Make standard",
326
+ "normalize.reasons": "What departs from the specification",
327
+ "normalize.result": "The frontmatter it will write",
328
+ "normalize.scope": "Only the frontmatter changes; the body and every other file stay.",
329
+ "normalize.confirm": "Make standard",
330
+ "normalize.loading": "Reading…",
331
+ "skills.loading": "Loading…"
332
+ }
333
+ };
334
+ /** `{{name}}` placeholders filled from `values`. */
335
+ function fill(text, values) {
336
+ return text.replace(/\{\{(\w+)\}\}/g, (whole, key) => key in values ? String(values[key]) : whole);
337
+ }
338
+ //#endregion
339
+ //#region src/ui/shared.ts
340
+ /** Returns feature failures; the global dialog owns gateway connectivity and authentication. */
341
+ function failureText(_ctx, error) {
342
+ const failure = error?.failure;
343
+ if (failure === "offline" || failure === "authentication") return null;
344
+ return (error instanceof Error ? error.message : String(error)).replace(/^plugin "[^"]+" failed in \w+: /, "");
345
+ }
346
+ function formatBytes(bytes) {
347
+ if (bytes < 1024) return `${bytes} B`;
348
+ if (bytes < 1048576) return `${(bytes / 1024).toFixed(1)} KB`;
349
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
350
+ }
351
+ //#endregion
352
+ //#region src/ui/confirm.tsx
353
+ function UninstallDialog({ ctx, agentId, skill, preloaded, onClose, onDone }) {
354
+ const t = ctx.i18n.t;
355
+ const ui = ctx.ui;
356
+ const [pending, setPending] = useState(false);
357
+ const [failure, setFailure] = useState(null);
358
+ const running = useRef(false);
359
+ async function uninstall() {
360
+ if (running.current) return;
361
+ running.current = true;
362
+ setPending(true);
363
+ setFailure(null);
364
+ try {
365
+ await ctx.invoke("uninstall", {
366
+ agentId,
367
+ layer: skill.layer,
368
+ id: skill.id
369
+ });
370
+ onDone();
371
+ onClose();
372
+ } catch (error) {
373
+ setFailure(failureText(ctx, error));
374
+ } finally {
375
+ running.current = false;
376
+ setPending(false);
377
+ }
378
+ }
379
+ return /* @__PURE__ */ jsxs(ui.AlertDialog, {
380
+ open: true,
381
+ onOpenChange: (open) => {
382
+ if (!open && !pending) onClose();
383
+ },
384
+ title: t("uninstall.title"),
385
+ actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ui.Button, {
386
+ variant: "ghost",
387
+ disabled: pending,
388
+ onClick: onClose,
389
+ children: t("install.cancel")
390
+ }), /* @__PURE__ */ jsx(ui.Button, {
391
+ variant: "destructive",
392
+ disabled: pending,
393
+ loading: pending,
394
+ onClick: () => void uninstall(),
395
+ children: t("uninstall.confirm")
396
+ })] }),
397
+ children: [
398
+ /* @__PURE__ */ jsx("p", { children: fill(t("uninstall.body"), {
399
+ id: skill.id,
400
+ layer: t(`skills.layer.${skill.layer}`)
401
+ }) }),
402
+ skill.layer === "global" && /* @__PURE__ */ jsx("p", { children: t("uninstall.global") }),
403
+ preloaded && /* @__PURE__ */ jsx("p", { children: t("uninstall.preloaded") }),
404
+ failure !== null && /* @__PURE__ */ jsx("p", {
405
+ role: "alert",
406
+ className: "skl-error",
407
+ children: failure
408
+ })
409
+ ]
410
+ });
411
+ }
412
+ function NormalizeDialog({ ctx, agentId, skill, onClose, onDone }) {
413
+ const t = ctx.i18n.t;
414
+ const ui = ctx.ui;
415
+ const [preview, setPreview] = useState(null);
416
+ const [pending, setPending] = useState(false);
417
+ const [failure, setFailure] = useState(null);
418
+ const running = useRef(false);
419
+ useEffect(() => {
420
+ let live = true;
421
+ ctx.invoke("normalize", {
422
+ agentId,
423
+ layer: skill.layer,
424
+ id: skill.id,
425
+ dryRun: true
426
+ }).then((answer) => {
427
+ if (live) setPreview(answer);
428
+ }, (error) => {
429
+ if (live) setFailure(failureText(ctx, error));
430
+ });
431
+ return () => {
432
+ live = false;
433
+ };
434
+ }, [
435
+ ctx,
436
+ agentId,
437
+ skill.layer,
438
+ skill.id
439
+ ]);
440
+ async function normalize() {
441
+ if (running.current) return;
442
+ running.current = true;
443
+ setPending(true);
444
+ setFailure(null);
445
+ try {
446
+ await ctx.invoke("normalize", {
447
+ agentId,
448
+ layer: skill.layer,
449
+ id: skill.id
450
+ });
451
+ onDone();
452
+ onClose();
453
+ } catch (error) {
454
+ setFailure(failureText(ctx, error));
455
+ } finally {
456
+ running.current = false;
457
+ setPending(false);
458
+ }
459
+ }
460
+ return /* @__PURE__ */ jsxs(ui.AlertDialog, {
461
+ open: true,
462
+ onOpenChange: (open) => {
463
+ if (!open && !pending) onClose();
464
+ },
465
+ title: t("normalize.title"),
466
+ actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ui.Button, {
467
+ variant: "ghost",
468
+ disabled: pending,
469
+ onClick: onClose,
470
+ children: t("install.cancel")
471
+ }), /* @__PURE__ */ jsx(ui.Button, {
472
+ variant: "primary",
473
+ loading: pending,
474
+ disabled: pending || preview === null,
475
+ onClick: () => void normalize(),
476
+ children: t("normalize.confirm")
477
+ })] }),
478
+ children: [
479
+ /* @__PURE__ */ jsx("h4", {
480
+ className: "skl-subhead",
481
+ children: t("normalize.reasons")
482
+ }),
483
+ /* @__PURE__ */ jsx("ul", {
484
+ className: "skl-bullets",
485
+ children: skill.issues.map((issue) => /* @__PURE__ */ jsx("li", { children: issueText(ctx, issue) }, `${issue.code}:${issue.detail}`))
486
+ }),
487
+ preview === null && failure === null && /* @__PURE__ */ jsx("p", {
488
+ className: "skl-muted",
489
+ children: t("normalize.loading")
490
+ }),
491
+ preview !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
492
+ /* @__PURE__ */ jsx("h4", {
493
+ className: "skl-subhead",
494
+ children: t("normalize.result")
495
+ }),
496
+ /* @__PURE__ */ jsx("pre", {
497
+ className: "skl-mono skl-code",
498
+ children: preview.frontmatter
499
+ }),
500
+ /* @__PURE__ */ jsx("p", {
501
+ className: "skl-muted",
502
+ children: t("normalize.scope")
503
+ }),
504
+ preview.remaining.map((issue) => /* @__PURE__ */ jsx("p", {
505
+ className: "skl-warning",
506
+ children: issueText(ctx, issue)
507
+ }, issue.code))
508
+ ] }),
509
+ failure !== null && /* @__PURE__ */ jsx("p", {
510
+ role: "alert",
511
+ className: "skl-error",
512
+ children: failure
513
+ })
514
+ ]
515
+ });
516
+ }
517
+ /** Deletes a snapshot of the visible skills; retries include only unsuccessful items. */
518
+ function BulkUninstallDialog({ ctx, agentId, skills, onClose, onDone }) {
519
+ const ui = ctx.ui;
520
+ const t = ctx.i18n.t;
521
+ const [remaining, setRemaining] = useState(skills);
522
+ const [pending, setPending] = useState(false);
523
+ const [failures, setFailures] = useState([]);
524
+ const running = useRef(false);
525
+ async function uninstall() {
526
+ if (running.current) return;
527
+ running.current = true;
528
+ setPending(true);
529
+ setFailures([]);
530
+ const failed = [];
531
+ const messages = [];
532
+ try {
533
+ for (const skill of remaining) try {
534
+ await ctx.invoke("uninstall", {
535
+ agentId,
536
+ layer: skill.layer,
537
+ id: skill.id
538
+ });
539
+ } catch (error) {
540
+ failed.push(skill);
541
+ const reason = failureText(ctx, error);
542
+ if (reason !== null) messages.push(`${skill.id}: ${reason}`);
543
+ }
544
+ setRemaining(failed);
545
+ setFailures(messages);
546
+ onDone();
547
+ if (failed.length === 0) onClose();
548
+ } finally {
549
+ running.current = false;
550
+ setPending(false);
551
+ }
552
+ }
553
+ return /* @__PURE__ */ jsxs(ui.AlertDialog, {
554
+ open: true,
555
+ title: t("skills.deleteAll"),
556
+ onOpenChange: (open) => {
557
+ if (!open && !running.current) onClose();
558
+ },
559
+ actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ui.Button, {
560
+ variant: "ghost",
561
+ disabled: pending,
562
+ onClick: onClose,
563
+ children: t("install.cancel")
564
+ }), /* @__PURE__ */ jsx(ui.Button, {
565
+ variant: "destructive",
566
+ loading: pending,
567
+ disabled: pending || remaining.length === 0,
568
+ onClick: () => void uninstall(),
569
+ children: t(failures.length ? "skills.retry" : "skills.deleteAll")
570
+ })] }),
571
+ children: [
572
+ /* @__PURE__ */ jsx("p", { children: fill(t("uninstall.allBody"), { count: remaining.length }) }),
573
+ remaining.some((skill) => skill.layer === "global") && /* @__PURE__ */ jsx("p", { children: t("uninstall.allGlobal") }),
574
+ failures.length > 0 && /* @__PURE__ */ jsx("div", {
575
+ role: "alert",
576
+ className: "skl-error",
577
+ children: failures.map((message) => /* @__PURE__ */ jsx("p", { children: message }, message))
578
+ })
579
+ ]
580
+ });
581
+ }
582
+ //#endregion
583
+ //#region src/ui/wire.ts
584
+ /** The specification's name rule, as the host checks it. */
585
+ var SKILL_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
586
+ function isStandardName(name) {
587
+ return name.length <= 64 && SKILL_NAME.test(name);
588
+ }
589
+ //#endregion
590
+ //#region src/ui/install-dialog.tsx
591
+ var REGISTRIES = [
592
+ "clawhub",
593
+ "tencent-skillhub",
594
+ "skills-sh"
595
+ ];
596
+ var sourceKey = (result) => JSON.stringify(result.source);
597
+ /** Searches marketplaces and installs selected packages or skills from a local/GitHub tree. */
598
+ function InstallDialog({ ctx, agentId, onClose, onInstalled }) {
599
+ const t = ctx.i18n.t;
600
+ const ui = ctx.ui;
601
+ const toast = ui.useToast();
602
+ const [from, setFrom] = useState("local");
603
+ const [registry, setRegistry] = useState("clawhub");
604
+ const [query, setQuery] = useState("");
605
+ const [url, setUrl] = useState("");
606
+ const [path, setPath] = useState("");
607
+ const [layer, setLayer] = useState("agent");
608
+ const [results, setResults] = useState([]);
609
+ const [selected, setSelected] = useState(/* @__PURE__ */ new Map());
610
+ const [preview, setPreview] = useState(null);
611
+ const [picked, setPicked] = useState(/* @__PURE__ */ new Set());
612
+ const [ids, setIds] = useState(/* @__PURE__ */ new Map());
613
+ const [correction, setCorrection] = useState(null);
614
+ const [busy, setBusy] = useState(null);
615
+ const [failure, setFailure] = useState(null);
616
+ const [notice, setNotice] = useState(null);
617
+ const generation = useRef(0);
618
+ const alive = useRef(true);
619
+ const held = useRef(/* @__PURE__ */ new Set());
620
+ const installing = useRef(false);
621
+ function release(id) {
622
+ held.current.delete(id);
623
+ ctx.invoke("cancel", { previewId: id }).catch(() => {});
624
+ }
625
+ function reset() {
626
+ generation.current++;
627
+ for (const id of held.current) release(id);
628
+ setPreview(null);
629
+ setPicked(/* @__PURE__ */ new Set());
630
+ setIds(/* @__PURE__ */ new Map());
631
+ setCorrection(null);
632
+ setSelected(/* @__PURE__ */ new Map());
633
+ setResults([]);
634
+ setFailure(null);
635
+ setNotice(null);
636
+ setBusy(null);
637
+ }
638
+ useEffect(() => {
639
+ alive.current = true;
640
+ return () => {
641
+ alive.current = false;
642
+ generation.current++;
643
+ if (!installing.current) for (const id of held.current) release(id);
644
+ };
645
+ }, []);
646
+ useEffect(() => {
647
+ if (from !== "registry" || query.trim() === "") return;
648
+ const token = generation.current;
649
+ let active = true;
650
+ setBusy("search");
651
+ const timer = setTimeout(() => {
652
+ ctx.invoke("search", {
653
+ registry,
654
+ query: query.trim()
655
+ }).then((answer) => {
656
+ if (active && alive.current && token === generation.current) setResults(answer.results);
657
+ }).catch((error) => {
658
+ if (active && alive.current && token === generation.current) setFailure(failureText(ctx, error));
659
+ }).finally(() => {
660
+ if (active && alive.current && token === generation.current) setBusy(null);
661
+ });
662
+ }, 300);
663
+ return () => {
664
+ active = false;
665
+ clearTimeout(timer);
666
+ };
667
+ }, [
668
+ from,
669
+ registry,
670
+ query
671
+ ]);
672
+ async function load(source) {
673
+ reset();
674
+ const token = generation.current;
675
+ setBusy("fetch");
676
+ try {
677
+ const next = await ctx.invoke("preview", {
678
+ source,
679
+ agentId
680
+ });
681
+ if (!alive.current || token !== generation.current) {
682
+ release(next.previewId);
683
+ return;
684
+ }
685
+ held.current.add(next.previewId);
686
+ setPreview(next);
687
+ setPicked(new Set(next.candidates.map((item) => item.key)));
688
+ setIds(new Map(next.candidates.map((item) => [item.key, item.suggestedId])));
689
+ } catch (error) {
690
+ if (alive.current && token === generation.current) setFailure(failureText(ctx, error));
691
+ } finally {
692
+ if (alive.current && token === generation.current) setBusy(null);
693
+ }
694
+ }
695
+ const idOf = (key, suggestedId) => ids.get(key) ?? suggestedId;
696
+ const available = preview?.candidates.filter((item) => !(preview?.taken[layer] ?? []).includes(idOf(item.key, item.suggestedId))) ?? [];
697
+ const candidates = available.filter((item) => picked.has(item.key));
698
+ const invalidPick = candidates.some((item) => !isStandardName(idOf(item.key, item.suggestedId)));
699
+ const count = from === "registry" ? selected.size : candidates.length;
700
+ const locked = busy === "install";
701
+ const reading = busy === "search" || busy === "fetch";
702
+ async function install() {
703
+ if (count === 0 || invalidPick || installing.current || busy !== null) return;
704
+ installing.current = true;
705
+ setBusy("install");
706
+ setFailure(null);
707
+ setNotice(null);
708
+ let installed = 0;
709
+ let skipped = 0;
710
+ const errors = [];
711
+ const completed = /* @__PURE__ */ new Set();
712
+ let awaitingCorrection = false;
713
+ let retainedPreviewId = null;
714
+ const jobs = from === "registry" ? [...selected].map(([key, result]) => ({
715
+ key,
716
+ source: correction?.key === key ? correction.source : result.source
717
+ })) : [{
718
+ key: "tree",
719
+ source: null
720
+ }];
721
+ try {
722
+ for (const job of jobs) {
723
+ if (!alive.current) break;
724
+ let view = job.source === null || correction?.key === job.key ? preview : null;
725
+ try {
726
+ if (job.source !== null && view === null) {
727
+ view = await ctx.invoke("preview", {
728
+ source: job.source,
729
+ agentId
730
+ });
731
+ held.current.add(view.previewId);
732
+ }
733
+ if (view === null || !alive.current) continue;
734
+ if (job.source !== null && correction?.key !== job.key && view.candidates.some((item) => !isStandardName(item.suggestedId))) {
735
+ setPreview(view);
736
+ setPicked(new Set(view.candidates.map((item) => item.key)));
737
+ setIds(new Map(view.candidates.map((item) => [item.key, item.suggestedId])));
738
+ setCorrection({
739
+ key: job.key,
740
+ source: job.source
741
+ });
742
+ awaitingCorrection = true;
743
+ retainedPreviewId = view.previewId;
744
+ break;
745
+ }
746
+ const items = job.source === null || correction?.key === job.key ? candidates : view.candidates;
747
+ if (items.length === 0) {
748
+ if (correction?.key === job.key) {
749
+ completed.add(job.key);
750
+ setCorrection(null);
751
+ setPreview(null);
752
+ continue;
753
+ }
754
+ errors.push(...view.failures.map((item) => `${item.path}: ${item.reason}`));
755
+ if (view.failures.length === 0) errors.push(t("install.nothing"));
756
+ continue;
757
+ }
758
+ const answer = await ctx.invoke("install", {
759
+ previewId: view.previewId,
760
+ agentId,
761
+ layer,
762
+ picks: items.map((item) => ({
763
+ key: item.key,
764
+ id: job.source === null || correction?.key === job.key ? idOf(item.key, item.suggestedId) : item.suggestedId,
765
+ onConflict: "skip"
766
+ }))
767
+ });
768
+ installed += answer.installed.length;
769
+ skipped += answer.skipped.length;
770
+ errors.push(...answer.failed.map((item) => `${item.key}: ${item.reason}`));
771
+ errors.push(...view.failures.map((item) => `${item.path}: ${item.reason}`));
772
+ if (answer.failed.length === 0) {
773
+ completed.add(job.key);
774
+ held.current.delete(view.previewId);
775
+ }
776
+ if (job.source === null && alive.current) {
777
+ const done = new Set([...answer.installed, ...answer.skipped].map((item) => item.key));
778
+ setPicked((current) => new Set([...current].filter((key) => !done.has(key))));
779
+ if (answer.failed.length === 0 && view.failures.length > 0) {
780
+ setPreview(null);
781
+ const source = from === "local" ? {
782
+ kind: "local",
783
+ path
784
+ } : {
785
+ kind: "github",
786
+ url: url.trim()
787
+ };
788
+ const refreshed = await ctx.invoke("preview", {
789
+ source,
790
+ agentId
791
+ });
792
+ if (alive.current) {
793
+ held.current.add(refreshed.previewId);
794
+ setPreview(refreshed);
795
+ } else release(refreshed.previewId);
796
+ } else setPreview({
797
+ ...view,
798
+ taken: {
799
+ ...view.taken,
800
+ [layer]: [...view.taken[layer], ...answer.installed.map((item) => item.id)]
801
+ }
802
+ });
803
+ }
804
+ if (correction?.key === job.key && alive.current) {
805
+ if (answer.failed.length === 0) {
806
+ setCorrection(null);
807
+ setPreview(null);
808
+ setPicked(/* @__PURE__ */ new Set());
809
+ setIds(/* @__PURE__ */ new Map());
810
+ } else {
811
+ const done = new Set([...answer.installed, ...answer.skipped].map((item) => item.key));
812
+ setPicked((current) => new Set([...current].filter((key) => !done.has(key))));
813
+ setPreview({
814
+ ...view,
815
+ taken: {
816
+ ...view.taken,
817
+ [layer]: [...view.taken[layer], ...answer.installed.map((item) => item.id)]
818
+ }
819
+ });
820
+ retainedPreviewId = view.previewId;
821
+ awaitingCorrection = true;
822
+ break;
823
+ }
824
+ }
825
+ } catch (error) {
826
+ const reason = failureText(ctx, error);
827
+ if (reason !== null) errors.push(reason);
828
+ if (correction?.key === job.key && view !== null) {
829
+ retainedPreviewId = view.previewId;
830
+ awaitingCorrection = true;
831
+ break;
832
+ }
833
+ } finally {
834
+ if (view !== null && view.previewId !== retainedPreviewId && (job.source !== null || !alive.current)) release(view.previewId);
835
+ }
836
+ }
837
+ if (installed > 0) onInstalled();
838
+ if (!alive.current) return;
839
+ if (installed > 0) toast.add({
840
+ id: `skills-installed-${Date.now()}`,
841
+ tone: "success",
842
+ title: fill(t("install.installedToast"), { count: installed })
843
+ });
844
+ setSelected((current) => new Map([...current].filter(([key]) => !completed.has(key))));
845
+ if (errors.length > 0) setFailure(errors.join("\n"));
846
+ if (skipped > 0) setNotice(fill(t("install.skippedCount"), { count: skipped }));
847
+ if (errors.length === 0 && !awaitingCorrection) {
848
+ if (skipped > 0) toast.add({
849
+ id: `skills-skipped-${Date.now()}`,
850
+ title: fill(t("install.skippedCount"), { count: skipped })
851
+ });
852
+ onClose();
853
+ }
854
+ } finally {
855
+ installing.current = false;
856
+ if (!alive.current) for (const id of held.current) release(id);
857
+ else setBusy(null);
858
+ }
859
+ }
860
+ function close() {
861
+ if (!installing.current) onClose();
862
+ }
863
+ const visible = results.filter((item) => !item.needsLogin);
864
+ const all = from === "registry" && correction === null ? visible.length > 0 && visible.every((item) => selected.has(sourceKey(item))) : available.length > 0 && available.every((item) => picked.has(item.key));
865
+ const row = (label, content) => /* @__PURE__ */ jsxs("div", {
866
+ className: "skl-install-field",
867
+ children: [/* @__PURE__ */ jsx("span", {
868
+ className: "skl-install-label",
869
+ children: label
870
+ }), /* @__PURE__ */ jsx("div", {
871
+ className: "skl-field-control",
872
+ children: content
873
+ })]
874
+ });
875
+ return /* @__PURE__ */ jsx(ui.Dialog, {
876
+ open: true,
877
+ title: t("install.title"),
878
+ closeLabel: t("install.close"),
879
+ onOpenChange: (open) => {
880
+ if (!open) close();
881
+ },
882
+ children: /* @__PURE__ */ jsxs("div", {
883
+ className: "skl-dialog skl-install-dialog",
884
+ children: [
885
+ /* @__PURE__ */ jsxs("div", {
886
+ className: "skl-install-settings",
887
+ children: [
888
+ row(t("install.from"), /* @__PURE__ */ jsx(ui.Segmented, {
889
+ fullWidth: true,
890
+ disabled: locked,
891
+ label: t("install.from"),
892
+ value: from,
893
+ options: [
894
+ "local",
895
+ "github",
896
+ "registry"
897
+ ].map((value) => ({
898
+ value,
899
+ label: t(`install.from.${value}`)
900
+ })),
901
+ onSelect: (value) => {
902
+ reset();
903
+ setFrom(value);
904
+ setPath("");
905
+ }
906
+ })),
907
+ from === "registry" && row(t("install.registry"), /* @__PURE__ */ jsx(ui.Segmented, {
908
+ fullWidth: true,
909
+ disabled: locked,
910
+ label: t("install.registry"),
911
+ value: registry,
912
+ options: REGISTRIES.map((value) => ({
913
+ value,
914
+ label: t(`install.registry.${value}`)
915
+ })),
916
+ onSelect: (value) => {
917
+ reset();
918
+ setRegistry(value);
919
+ }
920
+ })),
921
+ row(t("install.target"), /* @__PURE__ */ jsx(ui.Segmented, {
922
+ fullWidth: true,
923
+ disabled: locked,
924
+ label: t("install.target"),
925
+ value: layer,
926
+ options: ["agent", "global"].map((value) => ({
927
+ value,
928
+ label: t(`install.target.${value}`)
929
+ })),
930
+ onSelect: (value) => setLayer(value)
931
+ })),
932
+ from === "registry" && row(t("install.query"), /* @__PURE__ */ jsxs("div", {
933
+ className: "skl-search-input",
934
+ children: [/* @__PURE__ */ jsx(ui.Icon, { name: "search" }), /* @__PURE__ */ jsx(ui.Input, {
935
+ autoFocus: true,
936
+ "aria-label": t("install.query"),
937
+ placeholder: t("install.queryPlaceholder"),
938
+ maxLength: 200,
939
+ disabled: locked,
940
+ value: query,
941
+ onChange: (event) => {
942
+ generation.current++;
943
+ setQuery(event.currentTarget.value);
944
+ setResults([]);
945
+ setFailure(null);
946
+ setBusy(event.currentTarget.value.trim() ? "search" : null);
947
+ }
948
+ })]
949
+ })),
950
+ from === "github" && row(t("install.githubUrl"), /* @__PURE__ */ jsxs("form", {
951
+ className: "skl-search",
952
+ onSubmit: (event) => {
953
+ event.preventDefault();
954
+ if (url.trim() && !locked) load({
955
+ kind: "github",
956
+ url: url.trim()
957
+ });
958
+ },
959
+ children: [/* @__PURE__ */ jsx(ui.Input, {
960
+ autoFocus: true,
961
+ "aria-label": t("install.githubUrl"),
962
+ disabled: locked,
963
+ placeholder: "https://github.com/owner/repository",
964
+ value: url,
965
+ onChange: (event) => {
966
+ reset();
967
+ setUrl(event.currentTarget.value);
968
+ }
969
+ }), /* @__PURE__ */ jsx(ui.Button, {
970
+ type: "submit",
971
+ variant: "secondary",
972
+ disabled: locked || busy === "fetch" || !url.trim(),
973
+ children: t("install.load")
974
+ })]
975
+ })),
976
+ from === "local" && row(t("install.from.local"), /* @__PURE__ */ jsxs("div", {
977
+ className: "skl-local-buttons",
978
+ children: [["directory", "file"].map((mode) => /* @__PURE__ */ jsx(ui.PathInput, {
979
+ buttonOnly: true,
980
+ browseLabel: t(mode === "directory" ? "install.chooseDirectory" : "install.chooseArchive"),
981
+ title: t(mode === "directory" ? "install.chooseDirectory" : "install.chooseArchive"),
982
+ mode,
983
+ value: path,
984
+ disabled: locked,
985
+ filters: mode === "file" ? [{
986
+ label: "ZIP",
987
+ extensions: ["zip"]
988
+ }] : void 0,
989
+ onValueChange: (value) => {
990
+ setPath(value);
991
+ load({
992
+ kind: "local",
993
+ path: value
994
+ });
995
+ }
996
+ }, mode)), path && /* @__PURE__ */ jsx("span", {
997
+ className: "skl-muted skl-local-path",
998
+ title: path,
999
+ children: path
1000
+ })]
1001
+ }))
1002
+ ]
1003
+ }),
1004
+ /* @__PURE__ */ jsxs("section", {
1005
+ className: "skl-install-scroll",
1006
+ tabIndex: 0,
1007
+ "aria-label": t("install.list"),
1008
+ "aria-busy": reading,
1009
+ children: [
1010
+ /* @__PURE__ */ jsxs("div", {
1011
+ className: "skl-results-heading",
1012
+ children: [/* @__PURE__ */ jsxs("strong", { children: [t("install.list"), reading ? "" : from === "registry" ? ` · ${results.length}` : preview ? ` · ${preview.candidates.length}` : ""] }), /* @__PURE__ */ jsxs("label", {
1013
+ className: "skl-select-all",
1014
+ children: [/* @__PURE__ */ jsx(ui.Checkbox, {
1015
+ "aria-label": t("install.selectAll"),
1016
+ disabled: busy !== null || (from === "registry" && correction === null ? visible.length === 0 : available.length === 0),
1017
+ checked: all,
1018
+ onChange: (event) => {
1019
+ const checked = event.currentTarget.checked;
1020
+ if (from === "registry" && correction === null) setSelected((current) => {
1021
+ const next = new Map(current);
1022
+ for (const item of visible) if (checked) next.set(sourceKey(item), item);
1023
+ else next.delete(sourceKey(item));
1024
+ return next;
1025
+ });
1026
+ else setPicked(new Set(checked ? available.map((item) => item.key) : []));
1027
+ }
1028
+ }), t("install.selectAll")]
1029
+ })]
1030
+ }),
1031
+ failure && /* @__PURE__ */ jsx("p", {
1032
+ role: "alert",
1033
+ className: "skl-error skl-install-error",
1034
+ children: failure
1035
+ }),
1036
+ notice && /* @__PURE__ */ jsx("p", {
1037
+ role: "status",
1038
+ className: "skl-muted",
1039
+ children: notice
1040
+ }),
1041
+ from === "registry" && correction === null && /* @__PURE__ */ jsx("div", {
1042
+ "data-slot": "install-results",
1043
+ children: /* @__PURE__ */ jsx(ui.DataTable, {
1044
+ ariaLabel: t("install.list"),
1045
+ items: results,
1046
+ loading: busy === "search",
1047
+ keyOf: sourceKey,
1048
+ labelOf: (result) => result.name,
1049
+ pagination: {
1050
+ pageSize: 10,
1051
+ pageSizeOptions: [
1052
+ 10,
1053
+ 20,
1054
+ 50
1055
+ ]
1056
+ },
1057
+ selection: {
1058
+ keys: new Set(selected.keys()),
1059
+ disabled: locked,
1060
+ disabledOf: (result) => result.needsLogin === true,
1061
+ onChange: (next) => setSelected((current) => {
1062
+ const updated = new Map([...current].filter(([key]) => next.has(key)));
1063
+ for (const result of results) {
1064
+ const key = sourceKey(result);
1065
+ if (next.has(key) && !result.needsLogin) updated.set(key, result);
1066
+ }
1067
+ return updated;
1068
+ })
1069
+ },
1070
+ columns: [{
1071
+ id: "skill",
1072
+ label: t("skills.column.skill"),
1073
+ render: (result) => /* @__PURE__ */ jsxs("span", {
1074
+ className: "skl-grow",
1075
+ children: [
1076
+ /* @__PURE__ */ jsx("strong", { children: result.name }),
1077
+ result.summary && /* @__PURE__ */ jsx("span", {
1078
+ className: "skl-description",
1079
+ children: result.summary
1080
+ }),
1081
+ /* @__PURE__ */ jsxs("span", {
1082
+ className: "skl-muted",
1083
+ children: [result.publisher, result.needsLogin && ` · ${t("install.needsLogin")}`]
1084
+ })
1085
+ ]
1086
+ })
1087
+ }, {
1088
+ id: "source",
1089
+ label: t("install.sourceLabel"),
1090
+ render: (result) => /* @__PURE__ */ jsxs("span", {
1091
+ className: "skl-result-meta",
1092
+ children: [result.version && /* @__PURE__ */ jsx("span", {
1093
+ className: "skl-mono",
1094
+ children: result.version
1095
+ }), /* @__PURE__ */ jsxs("span", {
1096
+ className: "skl-result-stats",
1097
+ children: [result.stars !== void 0 && /* @__PURE__ */ jsxs("span", {
1098
+ title: t("install.stars"),
1099
+ children: [/* @__PURE__ */ jsx(ui.Icon, { name: "star" }), result.stars.toLocaleString()]
1100
+ }), result.downloads !== void 0 && /* @__PURE__ */ jsxs("span", {
1101
+ title: t("install.downloads"),
1102
+ children: ["↓ ", result.downloads.toLocaleString()]
1103
+ })]
1104
+ })]
1105
+ })
1106
+ }],
1107
+ empty: /* @__PURE__ */ jsx(ui.EmptyState, {
1108
+ icon: "search",
1109
+ title: t(query.trim() ? "install.noResults" : "install.searchEmpty")
1110
+ })
1111
+ })
1112
+ }),
1113
+ (from !== "registry" || correction !== null) && /* @__PURE__ */ jsx(ui.DataTable, {
1114
+ ariaLabel: t("install.list"),
1115
+ items: preview?.candidates ?? [],
1116
+ loading: busy === "fetch",
1117
+ keyOf: (item) => item.key,
1118
+ labelOf: (item) => idOf(item.key, item.suggestedId) || item.key,
1119
+ searchOf: (item) => `${item.key} ${idOf(item.key, item.suggestedId)} ${item.description}`,
1120
+ pagination: {
1121
+ pageSize: 10,
1122
+ pageSizeOptions: [
1123
+ 10,
1124
+ 20,
1125
+ 50
1126
+ ]
1127
+ },
1128
+ selection: {
1129
+ keys: new Set(available.filter((item) => picked.has(item.key)).map((item) => item.key)),
1130
+ disabled: locked,
1131
+ disabledOf: (item) => (preview?.taken[layer] ?? []).includes(idOf(item.key, item.suggestedId)),
1132
+ onChange: (next) => setPicked((current) => /* @__PURE__ */ new Set([...[...current].filter((key) => !available.some((item) => item.key === key)), ...next]))
1133
+ },
1134
+ empty: /* @__PURE__ */ jsx(ui.EmptyState, {
1135
+ icon: from === "local" ? "folder" : "boxes",
1136
+ title: t(preview ? "install.nothing" : from === "local" ? "install.localEmpty" : "install.githubEmpty")
1137
+ }),
1138
+ columns: [{
1139
+ id: "skill",
1140
+ label: t("skills.column.skill"),
1141
+ render: (item) => {
1142
+ const id = idOf(item.key, item.suggestedId);
1143
+ const taken = (preview?.taken[layer] ?? []).includes(id);
1144
+ return /* @__PURE__ */ jsxs("span", {
1145
+ className: "skl-grow",
1146
+ "data-slot": "install-candidate",
1147
+ "data-disabled": taken,
1148
+ children: [
1149
+ /* @__PURE__ */ jsx("strong", { children: id || item.key }),
1150
+ /* @__PURE__ */ jsx("span", {
1151
+ className: "skl-description",
1152
+ children: item.description
1153
+ }),
1154
+ /* @__PURE__ */ jsxs("span", {
1155
+ className: "skl-muted",
1156
+ children: [
1157
+ item.key,
1158
+ " ·",
1159
+ " ",
1160
+ fill(t("install.files"), {
1161
+ count: item.files.length,
1162
+ size: formatBytes(item.bytes)
1163
+ })
1164
+ ]
1165
+ }),
1166
+ taken && /* @__PURE__ */ jsx(ui.Badge, {
1167
+ size: "sm",
1168
+ children: t("install.installed")
1169
+ })
1170
+ ]
1171
+ });
1172
+ }
1173
+ }, {
1174
+ id: "id",
1175
+ label: t("install.id"),
1176
+ render: (item) => {
1177
+ const id = idOf(item.key, item.suggestedId);
1178
+ return /* @__PURE__ */ jsxs("div", {
1179
+ className: "skl-id-editor",
1180
+ children: [
1181
+ /* @__PURE__ */ jsx("span", {
1182
+ className: "skl-muted",
1183
+ children: t("install.id")
1184
+ }),
1185
+ /* @__PURE__ */ jsx(ui.Input, {
1186
+ "aria-label": t("install.id"),
1187
+ maxLength: 64,
1188
+ disabled: locked,
1189
+ value: id,
1190
+ onChange: (event) => {
1191
+ const nextId = event.currentTarget.value;
1192
+ setIds((current) => new Map(current).set(item.key, nextId));
1193
+ }
1194
+ }),
1195
+ !isStandardName(id) && /* @__PURE__ */ jsx("span", {
1196
+ className: "skl-error",
1197
+ children: t("install.idInvalid")
1198
+ })
1199
+ ]
1200
+ });
1201
+ }
1202
+ }]
1203
+ }),
1204
+ preview?.failures.map((item) => /* @__PURE__ */ jsxs("p", {
1205
+ className: "skl-error",
1206
+ children: [
1207
+ item.path,
1208
+ ": ",
1209
+ item.reason
1210
+ ]
1211
+ }, item.path))
1212
+ ]
1213
+ }),
1214
+ /* @__PURE__ */ jsxs("div", {
1215
+ className: "skl-foot skl-install-footer",
1216
+ children: [
1217
+ /* @__PURE__ */ jsx("span", {
1218
+ className: "skl-muted skl-selection",
1219
+ "aria-live": "polite",
1220
+ children: count && !reading ? fill(t("install.selectedCount"), { count }) : t(`install.target.${layer}`)
1221
+ }),
1222
+ /* @__PURE__ */ jsx(ui.Button, {
1223
+ variant: "secondary",
1224
+ disabled: locked,
1225
+ onClick: close,
1226
+ children: t("install.cancel")
1227
+ }),
1228
+ /* @__PURE__ */ jsx(ui.Button, {
1229
+ variant: "primary",
1230
+ disabled: !count || invalidPick || busy !== null,
1231
+ onClick: () => void install(),
1232
+ children: locked ? t("install.installing") : `${t("install.confirm")}${count ? ` (${count})` : ""}`
1233
+ })
1234
+ ]
1235
+ })
1236
+ ]
1237
+ })
1238
+ });
1239
+ }
1240
+ //#endregion
1241
+ //#region src/ui/skills-tab.tsx
1242
+ function originText(ctx, origin) {
1243
+ const t = ctx.i18n.t;
1244
+ switch (origin.kind) {
1245
+ case "clawhub": {
1246
+ const name = `${origin.owner === void 0 ? "" : `${origin.owner}/`}${origin.slug}${origin.version === void 0 ? "" : ` · ${origin.version}`}`;
1247
+ return fill(t("skills.origin.clawhub"), { name });
1248
+ }
1249
+ case "tencent-skillhub": return fill(t("skills.origin.tencent-skillhub"), { name: `${origin.slug}${origin.version === void 0 ? "" : ` · ${origin.version}`}` });
1250
+ case "skills-sh": return fill(t("skills.origin.skills-sh"), { name: `${origin.repo}/${origin.skill}` });
1251
+ case "github": return fill(t("skills.origin.github"), { name: `${origin.repo}${origin.commit === void 0 ? "" : ` @ ${origin.commit.slice(0, 7)}`}` });
1252
+ case "local": return t("skills.origin.local");
1253
+ }
1254
+ }
1255
+ function issueText(ctx, issue) {
1256
+ return fill(ctx.i18n.t(`skills.issue.${issue.code}`), { detail: issue.detail });
1257
+ }
1258
+ function skillsTabFor(ctx) {
1259
+ return function SkillsTab({ agentId, editor }) {
1260
+ const t = ctx.i18n.t;
1261
+ const ui = ctx.ui;
1262
+ const host = useSyncExternalStore(ctx.host.subscribe, ctx.host.get);
1263
+ const toast = ui.useToast();
1264
+ async function copyPath(path) {
1265
+ try {
1266
+ await navigator.clipboard.writeText(path);
1267
+ toast.add({
1268
+ id: "skills.pathCopied",
1269
+ title: t("skills.pathCopied")
1270
+ });
1271
+ } catch {
1272
+ toast.add({
1273
+ id: "skills.pathCopyFailed",
1274
+ tone: "destructive",
1275
+ title: t("skills.pathCopyFailed")
1276
+ });
1277
+ }
1278
+ }
1279
+ const [catalog, setCatalog] = useState(null);
1280
+ const [readFailure, setReadFailure] = useState(null);
1281
+ const [loading, setLoading] = useState(true);
1282
+ const reading = useRef(false);
1283
+ const readAgain = useRef(false);
1284
+ const generation = useRef(0);
1285
+ const values = editor.read({
1286
+ skills: [],
1287
+ disabledSkills: []
1288
+ });
1289
+ const preloaded = values.skills;
1290
+ const disabledSkills = values.disabledSkills;
1291
+ const saving = editor.pending;
1292
+ const [installing, setInstalling] = useState(false);
1293
+ const [uninstalling, setUninstalling] = useState(null);
1294
+ const [bulkUninstalling, setBulkUninstalling] = useState(null);
1295
+ const [normalizing, setNormalizing] = useState(null);
1296
+ const load = useCallback(async () => {
1297
+ if (reading.current) {
1298
+ readAgain.current = true;
1299
+ return;
1300
+ }
1301
+ reading.current = true;
1302
+ setLoading(true);
1303
+ const version = generation.current;
1304
+ do {
1305
+ readAgain.current = false;
1306
+ try {
1307
+ const list = await ctx.invoke("list", { agentId });
1308
+ if (!ctx.signal.aborted && generation.current === version && !readAgain.current) {
1309
+ setCatalog(list);
1310
+ setReadFailure(null);
1311
+ }
1312
+ } catch (failure) {
1313
+ if (!ctx.signal.aborted && generation.current === version && !readAgain.current) setReadFailure(failureText(ctx, failure));
1314
+ }
1315
+ } while (!ctx.signal.aborted && generation.current === version && readAgain.current);
1316
+ if (generation.current === version) {
1317
+ reading.current = false;
1318
+ setLoading(false);
1319
+ }
1320
+ }, [agentId]);
1321
+ useEffect(() => {
1322
+ if (host.connection !== "online") return;
1323
+ reading.current = false;
1324
+ load();
1325
+ const offSkills = ctx.on("skillsChanged", () => void load());
1326
+ const offAgent = ctx.onCore("config.agentChanged", () => void load());
1327
+ return () => {
1328
+ generation.current++;
1329
+ offSkills();
1330
+ offAgent();
1331
+ };
1332
+ }, [load, host.connection]);
1333
+ const save = (skills, disabled = disabledSkills) => {
1334
+ editor.update({
1335
+ skills,
1336
+ disabledSkills: disabled
1337
+ });
1338
+ };
1339
+ const toggle = (id, on) => {
1340
+ const without = (preloaded ?? []).filter((one) => one !== id);
1341
+ save(on ? [...without, id] : without);
1342
+ };
1343
+ const enable = (id, on) => {
1344
+ const disabled = disabledSkills.filter((one) => one !== id);
1345
+ save(on ? preloaded ?? [] : (preloaded ?? []).filter((one) => one !== id), on ? disabled : [...disabled, id]);
1346
+ };
1347
+ const skills = catalog?.skills ?? [];
1348
+ const known = new Set(skills.map((one) => one.id));
1349
+ const missing = catalog && preloaded ? preloaded.filter((id) => !known.has(id)) : [];
1350
+ const enableAll = (on) => {
1351
+ save(on ? preloaded ?? [] : (preloaded ?? []).filter((id) => !known.has(id)), on ? disabledSkills.filter((id) => !known.has(id)) : [.../* @__PURE__ */ new Set([...disabledSkills, ...known])]);
1352
+ };
1353
+ return /* @__PURE__ */ jsxs("div", {
1354
+ className: "skl-tab",
1355
+ "data-slot": "skills-tab",
1356
+ children: [
1357
+ /* @__PURE__ */ jsxs("div", {
1358
+ className: "skl-head",
1359
+ children: [catalog && /* @__PURE__ */ jsx("ul", {
1360
+ "aria-label": t("skills.directories"),
1361
+ "data-slot": "skill-directories",
1362
+ className: "skl-directories",
1363
+ children: catalog.layers.map((layer) => /* @__PURE__ */ jsxs("li", {
1364
+ "data-slot": "skill-directory",
1365
+ className: "skl-directory",
1366
+ children: [/* @__PURE__ */ jsx(ui.Badge, {
1367
+ size: "sm",
1368
+ children: t(`skills.layer.${layer.layer}`)
1369
+ }), /* @__PURE__ */ jsx(ui.Button, {
1370
+ variant: "plain",
1371
+ type: "button",
1372
+ className: "skl-path skl-mono skl-muted",
1373
+ title: layer.directory,
1374
+ "aria-label": fill(t("skills.copyPath"), { path: layer.directory }),
1375
+ onClick: () => void copyPath(layer.directory),
1376
+ children: /* @__PURE__ */ jsx("span", {
1377
+ className: "skl-path-text",
1378
+ children: layer.directory
1379
+ })
1380
+ })]
1381
+ }, layer.layer))
1382
+ }), /* @__PURE__ */ jsx("div", {
1383
+ "data-slot": "skills-actions",
1384
+ className: "skl-actions",
1385
+ children: /* @__PURE__ */ jsx(ui.Button, {
1386
+ size: "sm",
1387
+ variant: "primary",
1388
+ icon: "plus",
1389
+ onClick: () => setInstalling(true),
1390
+ children: t("skills.install")
1391
+ })
1392
+ })]
1393
+ }),
1394
+ loading && catalog === null && /* @__PURE__ */ jsx("p", {
1395
+ role: "status",
1396
+ className: "skl-muted",
1397
+ children: t("skills.loading")
1398
+ }),
1399
+ readFailure !== null && /* @__PURE__ */ jsxs("div", {
1400
+ className: "skl-failure",
1401
+ role: "alert",
1402
+ children: [/* @__PURE__ */ jsx("span", {
1403
+ className: "skl-error",
1404
+ children: readFailure
1405
+ }), /* @__PURE__ */ jsx(ui.Button, {
1406
+ size: "sm",
1407
+ variant: "outline",
1408
+ icon: "refresh",
1409
+ disabled: loading,
1410
+ loading,
1411
+ onClick: () => void load(),
1412
+ children: t("skills.retry")
1413
+ })]
1414
+ }),
1415
+ /* @__PURE__ */ jsxs("div", {
1416
+ className: "skl-catalog",
1417
+ children: [
1418
+ skills.length > 0 && /* @__PURE__ */ jsxs("div", {
1419
+ className: "skl-list-header skl-muted",
1420
+ children: [
1421
+ /* @__PURE__ */ jsx("span", { children: t("skills.column.enabled") }),
1422
+ /* @__PURE__ */ jsx("span", { children: t("skills.column.skill") }),
1423
+ /* @__PURE__ */ jsx("span", { children: t("skills.column.actions") })
1424
+ ]
1425
+ }),
1426
+ /* @__PURE__ */ jsxs("section", {
1427
+ className: "skl-catalog-scroll",
1428
+ "aria-label": t("install.list"),
1429
+ tabIndex: 0,
1430
+ children: [
1431
+ catalog && skills.length === 0 && catalog.failed.length === 0 && /* @__PURE__ */ jsx(ui.EmptyState, {
1432
+ title: t("skills.empty"),
1433
+ description: t("skills.emptyHint")
1434
+ }),
1435
+ skills.length > 0 && /* @__PURE__ */ jsx("ul", {
1436
+ "data-slot": "skill-list",
1437
+ className: "skl-list",
1438
+ children: skills.map((skill) => /* @__PURE__ */ jsxs("li", {
1439
+ className: "skl-row",
1440
+ "data-slot": "skill-row",
1441
+ "data-disabled": disabledSkills.includes(skill.id),
1442
+ children: [
1443
+ /* @__PURE__ */ jsx(ui.Checkbox, {
1444
+ "aria-label": fill(t("skills.enable"), { id: skill.id }),
1445
+ checked: !disabledSkills.includes(skill.id),
1446
+ disabled: preloaded === null || saving,
1447
+ onChange: (event) => enable(skill.id, event.target.checked)
1448
+ }),
1449
+ /* @__PURE__ */ jsxs("span", {
1450
+ className: "skl-grow",
1451
+ children: [
1452
+ /* @__PURE__ */ jsxs("span", {
1453
+ className: "skl-line",
1454
+ children: [
1455
+ /* @__PURE__ */ jsx("span", {
1456
+ className: "skl-mono skl-id",
1457
+ children: skill.id
1458
+ }),
1459
+ /* @__PURE__ */ jsx(ui.Badge, {
1460
+ size: "sm",
1461
+ children: t(`skills.layer.${skill.layer}`)
1462
+ }),
1463
+ skill.issues.length > 0 && /* @__PURE__ */ jsx(ui.Tooltip, {
1464
+ content: skill.issues.map((issue) => issueText(ctx, issue)).join("\n"),
1465
+ children: /* @__PURE__ */ jsx("span", {
1466
+ "data-slot": "skill-nonstandard",
1467
+ children: /* @__PURE__ */ jsx(ui.Badge, {
1468
+ size: "sm",
1469
+ tone: "warning",
1470
+ variant: "soft",
1471
+ children: t("skills.nonStandard")
1472
+ })
1473
+ })
1474
+ }),
1475
+ skill.origin !== void 0 && /* @__PURE__ */ jsx("span", {
1476
+ className: "skl-muted skl-origin",
1477
+ "data-slot": "skill-origin",
1478
+ children: originText(ctx, skill.origin)
1479
+ })
1480
+ ]
1481
+ }),
1482
+ skill.description && /* @__PURE__ */ jsx("span", {
1483
+ className: "skl-description",
1484
+ children: skill.description
1485
+ }),
1486
+ /* @__PURE__ */ jsx("span", {
1487
+ className: "skl-row-actions",
1488
+ children: skill.issues.length > 0 && /* @__PURE__ */ jsx(ui.Button, {
1489
+ size: "sm",
1490
+ variant: "ghost",
1491
+ "aria-label": fill(t("skills.normalizeNamed"), { id: skill.id }),
1492
+ onClick: () => setNormalizing(skill),
1493
+ children: t("skills.normalize")
1494
+ })
1495
+ })
1496
+ ]
1497
+ }),
1498
+ /* @__PURE__ */ jsxs("span", {
1499
+ className: "skl-controls",
1500
+ children: [/* @__PURE__ */ jsx(ui.Tooltip, {
1501
+ content: t(disabledSkills.includes(skill.id) ? "skills.preloadDisabled" : preloaded?.includes(skill.id) ? "skills.preloadOn" : "skills.preloadOff"),
1502
+ children: /* @__PURE__ */ jsx(ui.Button, {
1503
+ size: "sm",
1504
+ variant: "ghost",
1505
+ className: "skl-preload",
1506
+ "aria-label": fill(t("skills.preload"), { id: skill.id }),
1507
+ "aria-pressed": preloaded?.includes(skill.id) === true,
1508
+ disabled: preloaded === null || saving || disabledSkills.includes(skill.id),
1509
+ onClick: () => toggle(skill.id, !preloaded?.includes(skill.id)),
1510
+ children: /* @__PURE__ */ jsx("svg", {
1511
+ viewBox: "0 0 24 24",
1512
+ width: "16",
1513
+ height: "16",
1514
+ fill: "none",
1515
+ stroke: "currentColor",
1516
+ strokeWidth: "1.6",
1517
+ strokeLinejoin: "round",
1518
+ "aria-hidden": "true",
1519
+ children: /* @__PURE__ */ jsx("path", { d: "m13 2-9 12h7l-1 8 10-13h-7l1-7Z" })
1520
+ })
1521
+ })
1522
+ }), /* @__PURE__ */ jsx("span", {
1523
+ className: "skl-row-actions",
1524
+ children: /* @__PURE__ */ jsx(ui.Tooltip, {
1525
+ content: t("skills.uninstall"),
1526
+ children: /* @__PURE__ */ jsx(ui.Button, {
1527
+ size: "sm",
1528
+ variant: "ghost",
1529
+ icon: "trash",
1530
+ className: "skl-uninstall",
1531
+ "aria-label": fill(t("skills.uninstallNamed"), { id: skill.id }),
1532
+ onClick: () => setUninstalling(skill)
1533
+ })
1534
+ })
1535
+ })]
1536
+ })
1537
+ ]
1538
+ }, skill.id))
1539
+ }),
1540
+ missing.length > 0 && /* @__PURE__ */ jsxs("section", {
1541
+ "aria-label": t("skills.missing"),
1542
+ "data-slot": "skill-missing",
1543
+ className: "skl-section",
1544
+ children: [/* @__PURE__ */ jsxs("header", { children: [/* @__PURE__ */ jsx("h4", { children: t("skills.missing") }), /* @__PURE__ */ jsx("p", {
1545
+ className: "skl-muted",
1546
+ children: t("skills.missingHint")
1547
+ })] }), /* @__PURE__ */ jsx("ul", {
1548
+ className: "skl-list",
1549
+ children: missing.map((id) => /* @__PURE__ */ jsxs("li", {
1550
+ className: "skl-row",
1551
+ children: [/* @__PURE__ */ jsx("span", {
1552
+ className: "skl-grow skl-mono skl-muted",
1553
+ children: id
1554
+ }), /* @__PURE__ */ jsx(ui.Button, {
1555
+ size: "sm",
1556
+ variant: "ghost",
1557
+ "aria-label": `${t("skills.unpreload")} ${id}`,
1558
+ disabled: saving,
1559
+ onClick: () => toggle(id, false),
1560
+ children: t("skills.unpreload")
1561
+ })]
1562
+ }, id))
1563
+ })]
1564
+ }),
1565
+ catalog && catalog.failed.length > 0 && /* @__PURE__ */ jsxs("section", {
1566
+ "aria-label": t("skills.failed"),
1567
+ "data-slot": "skill-failed",
1568
+ className: "skl-section",
1569
+ children: [/* @__PURE__ */ jsx("h4", { children: t("skills.failed") }), /* @__PURE__ */ jsx("ul", {
1570
+ className: "skl-list",
1571
+ children: catalog.failed.map((one) => /* @__PURE__ */ jsxs("li", {
1572
+ className: "skl-row skl-column",
1573
+ children: [/* @__PURE__ */ jsxs("span", {
1574
+ className: "skl-line",
1575
+ children: [/* @__PURE__ */ jsx("span", {
1576
+ className: "skl-mono",
1577
+ children: one.id
1578
+ }), /* @__PURE__ */ jsx(ui.Badge, {
1579
+ size: "sm",
1580
+ children: t(`skills.layer.${one.layer}`)
1581
+ })]
1582
+ }), /* @__PURE__ */ jsx("span", {
1583
+ className: "skl-error",
1584
+ children: one.reason
1585
+ })]
1586
+ }, `${one.layer}:${one.id}`))
1587
+ })]
1588
+ })
1589
+ ]
1590
+ }),
1591
+ skills.length > 0 && /* @__PURE__ */ jsxs("fieldset", {
1592
+ className: "skl-bulk-actions",
1593
+ "aria-label": t("skills.bulkActions"),
1594
+ children: [
1595
+ /* @__PURE__ */ jsx(ui.Button, {
1596
+ size: "sm",
1597
+ variant: "ghost",
1598
+ disabled: preloaded === null || saving || skills.every((skill) => !disabledSkills.includes(skill.id)),
1599
+ onClick: () => enableAll(true),
1600
+ children: t("skills.enableAll")
1601
+ }),
1602
+ /* @__PURE__ */ jsx(ui.Button, {
1603
+ size: "sm",
1604
+ variant: "ghost",
1605
+ disabled: preloaded === null || saving || skills.every((skill) => disabledSkills.includes(skill.id)),
1606
+ onClick: () => enableAll(false),
1607
+ children: t("skills.disableAll")
1608
+ }),
1609
+ /* @__PURE__ */ jsx(ui.Button, {
1610
+ size: "sm",
1611
+ variant: "ghost",
1612
+ icon: "trash",
1613
+ className: "skl-delete-all",
1614
+ disabled: saving,
1615
+ onClick: () => setBulkUninstalling([...skills]),
1616
+ children: t("skills.deleteAll")
1617
+ })
1618
+ ]
1619
+ })
1620
+ ]
1621
+ }),
1622
+ installing && /* @__PURE__ */ jsx(InstallDialog, {
1623
+ ctx,
1624
+ agentId,
1625
+ onClose: () => setInstalling(false),
1626
+ onInstalled: load
1627
+ }),
1628
+ uninstalling !== null && /* @__PURE__ */ jsx(UninstallDialog, {
1629
+ ctx,
1630
+ agentId,
1631
+ skill: uninstalling,
1632
+ preloaded: preloaded?.includes(uninstalling.id) === true,
1633
+ onClose: () => setUninstalling(null),
1634
+ onDone: load
1635
+ }),
1636
+ bulkUninstalling !== null && /* @__PURE__ */ jsx(BulkUninstallDialog, {
1637
+ ctx,
1638
+ agentId,
1639
+ skills: bulkUninstalling,
1640
+ onClose: () => setBulkUninstalling(null),
1641
+ onDone: load
1642
+ }),
1643
+ normalizing !== null && /* @__PURE__ */ jsx(NormalizeDialog, {
1644
+ ctx,
1645
+ agentId,
1646
+ skill: normalizing,
1647
+ onClose: () => setNormalizing(null),
1648
+ onDone: load
1649
+ })
1650
+ ]
1651
+ });
1652
+ };
1653
+ }
1654
+ //#endregion
1655
+ //#region src/ui/index.tsx
1656
+ var runtimeVersion = 5;
1657
+ var STYLES = `
1658
+ .skl-tab, .skl-form, .skl-dialog { display: flex; min-width: 0; flex-direction: column; gap: 1rem; font-size: .875rem; }
1659
+ .skl-tab { flex: 1; min-height: 0; overflow: hidden; }
1660
+ .skl-tab > .skl-head, .skl-tab > .skl-failure { flex: none; }
1661
+ .skl-catalog { display: flex; flex: 1; min-height: 0; flex-direction: column; overflow: hidden; }
1662
+ .skl-catalog > .skl-list-header, .skl-catalog > .skl-bulk-actions { flex: none; }
1663
+ .skl-catalog-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-gutter: stable; padding-inline: .25rem; }
1664
+ .skl-catalog-scroll:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; border-radius: var(--radius-control); }
1665
+ .skl-catalog-scroll > .skl-list, .skl-catalog-scroll .skl-section > .skl-list { margin-inline: 0; }
1666
+ .skl-catalog-scroll > .skl-section { margin-block-start: 1rem; }
1667
+ .skl-catalog-scroll > [data-slot=empty] { min-height: 100%; }
1668
+ .skl-catalog > .skl-list-header { margin-inline: 0; padding-inline: 1rem; overflow-y: hidden; scrollbar-gutter: stable; }
1669
+ .skl-bulk-actions { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; margin-block-start: .75rem; padding-block-start: .5rem; border-top: 1px solid var(--border); }
1670
+ .skl-bulk-actions .skl-delete-all { margin-inline-start: auto; color: var(--destructive); }
1671
+ .skl-head { display: flex; min-width: 0; align-items: flex-start; justify-content: space-between; gap: .75rem; }
1672
+ .skl-directories { display: grid; flex: 1; min-width: 0; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: .5rem .75rem; margin: 0; padding: 0; list-style: none; }
1673
+ .skl-directory { display: grid; grid-column: span 2; grid-template-columns: subgrid; align-items: center; }
1674
+ .skl-directory [data-slot=badge] { justify-self: start; }
1675
+ .skl-actions { display: flex; flex: none; align-items: center; gap: .5rem; margin-inline-start: auto; }
1676
+ .skl-mono { font-family: var(--font-mono, ui-monospace, monospace); font-size: .75rem; overflow-wrap: anywhere; }
1677
+ .skl-path { display: flex; min-width: 0; height: auto; justify-content: flex-start; padding: 0; text-align: start; cursor: copy; }
1678
+ .skl-path:hover { color: var(--foreground); }
1679
+ .skl-path-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1680
+ .skl-muted { margin: 0; color: var(--muted-foreground); font-size: .75rem; }
1681
+ .skl-error { margin: 0; color: var(--destructive); font-size: .75rem; overflow-wrap: anywhere; }
1682
+ .skl-warning { margin: 0; color: var(--warning); font-size: .75rem; }
1683
+ .skl-failure { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }
1684
+ .skl-list { display: flex; flex-direction: column; margin: 0 -.75rem; padding: 0; list-style: none; }
1685
+ .skl-row { position: relative; display: flex; min-width: 0; align-items: center; gap: .75rem; padding: .5rem .75rem; border-radius: var(--radius-control); }
1686
+ .skl-catalog [data-slot=skill-row], .skl-list-header { display: grid; grid-template-columns: 3rem minmax(0, 1fr) 4.25rem; align-items: center; gap: .75rem; }
1687
+ .skl-list-header { margin: 0 -.75rem; padding: 0 .75rem .5rem; border-bottom: 1px solid var(--border); }
1688
+ .skl-list-header > :first-child { text-align: center; }
1689
+ .skl-list-header > :last-child { text-align: right; }
1690
+ .skl-catalog [data-slot=skill-row] > :first-child { justify-self: center; }
1691
+ .skl-controls { display: flex; align-items: center; justify-content: flex-end; justify-self: end; gap: .25rem; }
1692
+ button.skl-uninstall { width: 2rem; padding: 0; }
1693
+ .skl-grow > .skl-row-actions:empty { display: none; }
1694
+ .skl-row:hover { background: var(--muted); }
1695
+ .skl-row[data-disabled=true] .skl-grow { opacity: .5; }
1696
+ button.skl-preload { flex: none; width: 2rem; padding: 0; color: var(--muted-foreground); }
1697
+ button.skl-preload[aria-pressed=true] { color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); }
1698
+ button.skl-preload[aria-pressed=true] svg { fill: currentColor; }
1699
+ .skl-column { flex-direction: column; align-items: stretch; gap: .125rem; }
1700
+ .skl-grow { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: .125rem; }
1701
+ .skl-line { display: flex; min-width: 0; flex-wrap: wrap; align-items: center; gap: .5rem; }
1702
+ .skl-id { color: var(--foreground); }
1703
+ .skl-origin { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1704
+ .skl-description { display: -webkit-box; overflow: hidden; color: var(--muted-foreground); font-size: .75rem; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
1705
+ .skl-row-actions { display: flex; flex: none; gap: .25rem; opacity: 0; transition: opacity 150ms ease; }
1706
+ .skl-row:is(:hover, :focus-within) .skl-row-actions { opacity: 1; }
1707
+ @media (hover: none) { .skl-row-actions { opacity: 1; } }
1708
+ .skl-section header { display: flex; flex-direction: column; gap: .125rem; padding: .375rem 0; }
1709
+ .skl-section h4, .skl-subhead { margin: 0; padding: .375rem 0; font-size: .875rem; font-weight: 500; }
1710
+ .skl-search { display: flex; gap: .5rem; }
1711
+ .skl-search > input { flex: 1; min-width: 0; }
1712
+ .skl-install-dialog { height: min(38rem, calc(100dvh - 8rem)); min-height: 0; overflow: hidden; }
1713
+ .skl-install-settings { display: flex; flex: none; flex-direction: column; gap: .875rem; padding-block-end: 1rem; border-bottom: 1px solid var(--border); }
1714
+ .skl-install-field { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr); gap: 1rem; align-items: center; }
1715
+ .skl-install-label { color: var(--foreground); font-size: .8125rem; }
1716
+ .skl-field-control { min-width: 0; }
1717
+ .skl-search-input { position: relative; }
1718
+ .skl-search-input > svg { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); width: 1rem; height: 1rem; color: var(--muted-foreground); pointer-events: none; }
1719
+ .skl-search-input > input { width: 100%; padding-inline-start: 2.25rem; }
1720
+ .skl-local-buttons { display: flex; flex-wrap: wrap; gap: .5rem; }
1721
+ .skl-local-path { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1722
+ .skl-install-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-gutter: stable; padding: .25rem; margin: -.25rem; }
1723
+ .skl-install-scroll:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; border-radius: var(--radius-control); }
1724
+ .skl-results-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 0 .25rem .75rem; font-size: .75rem; }
1725
+ .skl-results-heading strong { font-weight: 500; }
1726
+ .skl-select-all { display: flex; align-items: center; gap: .5rem; color: var(--muted-foreground); cursor: pointer; }
1727
+ .skl-results { display: flex; flex-direction: column; gap: .25rem; padding: 0; margin: 0; list-style: none; }
1728
+ .skl-results > li + li { border-top: 1px solid var(--border); }
1729
+ .skl-install-item { display: flex; align-items: center; gap: .75rem; padding: .875rem .5rem; min-width: 0; border-radius: var(--radius-control); cursor: pointer; }
1730
+ .skl-install-item:hover { background: var(--muted); }
1731
+ .skl-install-item[data-selected=true] { background: color-mix(in srgb, var(--primary) 7%, transparent); }
1732
+ .skl-install-item[data-disabled=true] { opacity: .55; cursor: default; }
1733
+ .skl-install-item strong { font-size: .8125rem; font-weight: 600; overflow-wrap: anywhere; }
1734
+ .skl-id-editor { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; font-size: .75rem; }
1735
+ .skl-id-editor input { width: min(100%, 16rem); }
1736
+ .skl-install-item .skl-description { -webkit-line-clamp: 1; margin-block: .125rem; }
1737
+ .skl-package-icon { display: grid; place-items: center; flex: none; width: 2.25rem; height: 2.25rem; border-radius: .5rem; border: 1px solid color-mix(in srgb, var(--primary) 15%, var(--border)); color: var(--primary); background: color-mix(in srgb, var(--primary) 5%, var(--background)); }
1738
+ .skl-package-icon svg { width: 1.125rem; height: 1.125rem; }
1739
+ .skl-result-meta { display: flex; flex: none; flex-direction: column; align-items: flex-end; gap: .5rem; max-width: 8rem; color: var(--muted-foreground); font-size: .6875rem; }
1740
+ .skl-result-meta .skl-mono { font-size: inherit; }
1741
+ .skl-result-stats { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
1742
+ .skl-result-stats > span { display: inline-flex; align-items: center; gap: .25rem; }
1743
+ .skl-result-stats svg { width: .75rem; height: .75rem; }
1744
+ .skl-install-empty { display: flex; min-height: 10rem; height: calc(100% - 2rem); flex-direction: column; justify-content: center; align-items: center; gap: .75rem; color: var(--muted-foreground); font-size: .8125rem; }
1745
+ .skl-install-empty > svg { width: 1.75rem; height: 1.75rem; }
1746
+ .skl-install-error { white-space: pre-wrap; margin-block-end: .75rem; }
1747
+ .skl-foot { display: flex; justify-content: flex-end; gap: .5rem; }
1748
+ .skl-install-footer { flex: none; align-items: center; padding-block-start: .875rem; border-top: 1px solid var(--border); }
1749
+ .skl-selection { margin-inline-end: auto; }
1750
+ @media (max-width: 540px) {
1751
+ .skl-install-field { grid-template-columns: minmax(0, 1fr); gap: .375rem; }
1752
+ .skl-install-settings { gap: .625rem; }
1753
+ .skl-package-icon { display: none; }
1754
+ .skl-install-item { gap: .5rem; }
1755
+ .skl-result-meta { max-width: 5rem; }
1756
+ }
1757
+ .skl-code { margin: 0; padding: .5rem .75rem; overflow-x: auto; border-radius: var(--radius-control); background: var(--muted); white-space: pre; }
1758
+ .skl-bullets { margin: 0; padding-inline-start: 1.25rem; font-size: .8125rem; list-style: disc; }
1759
+ `;
1760
+ var register = (ctx) => {
1761
+ ctx.slots.register("chat.composer.commands", {
1762
+ id: "skill-commands",
1763
+ namespace: "skill",
1764
+ errorLabel: "",
1765
+ label: () => ctx.i18n.t("skills.composerSource"),
1766
+ async commands(session) {
1767
+ return (await ctx.invoke("sessionSkills", session.sessionId === null ? {
1768
+ agentId: session.agentId,
1769
+ workspaceId: session.workspaceId
1770
+ } : { sessionId: session.sessionId })).loaded.map((skill) => ({
1771
+ kind: "expand",
1772
+ name: skill.id,
1773
+ description: skill.description,
1774
+ acceptsText: true,
1775
+ async expand(input, run) {
1776
+ const { body } = await ctx.invoke("readSkill", {
1777
+ ...run.sessionId === null ? {
1778
+ agentId: run.agentId,
1779
+ workspaceId: run.workspaceId
1780
+ } : { sessionId: run.sessionId },
1781
+ id: skill.id
1782
+ });
1783
+ return { text: input.text === "" ? body : `${body}\n\n${input.text}` };
1784
+ }
1785
+ }));
1786
+ }
1787
+ });
1788
+ ctx.i18n.register({
1789
+ "en-US": { "skills.composerSource": "Skills" },
1790
+ "zh-CN": { "skills.composerSource": "技能" }
1791
+ }, "en-US");
1792
+ registerMetadata(ctx);
1793
+ ctx.i18n.register(CATALOGUES, "en-US");
1794
+ ctx.styles.add(STYLES);
1795
+ ctx.slots.register("shell.agentEditor.tab", {
1796
+ id: "skills-tab",
1797
+ title: () => ctx.i18n.t("skills.title"),
1798
+ order: 10,
1799
+ className: "ag-tab-skills",
1800
+ component: skillsTabFor(ctx)
1801
+ });
1802
+ };
1803
+ //#endregion
1804
+ export { register, runtimeVersion };