Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(skills): unify skill imports from GitHub, links and files (#23456)

AmAzing-4056b7eafd52
diff --git a/locales/en-US/setting.json b/locales/en-US/setting.json
index e62a0c5ebf1..f08ac5eaf40 100644
--- a/locales/en-US/setting.json
+++ b/locales/en-US/setting.json
@@ -199,19 +199,41 @@
"agentSkillModal.contentPlaceholder": "Enter skill content in Markdown format...",
"agentSkillModal.description": "Description",
"agentSkillModal.descriptionPlaceholder": "Briefly describe this skill",
+ "agentSkillModal.done": "Done",
+ "agentSkillModal.file": "File",
+ "agentSkillModal.github.allSkills": "All skills ({{count}})",
+ "agentSkillModal.github.batchFailed": "Couldn’t import the selected skills. Try again or rescan the repository.",
+ "agentSkillModal.github.browseAll": "Browse all skills",
+ "agentSkillModal.github.change": "Change source",
+ "agentSkillModal.github.chooseMore": "Choose more skills",
"agentSkillModal.github.clear": "Clear selection",
- "agentSkillModal.github.collectionHint": "Enter a public GitHub repository or skill directory URL.",
+ "agentSkillModal.github.clearSearch": "Clear search",
+ "agentSkillModal.github.complete_one": "{{count}} skill is ready to use",
+ "agentSkillModal.github.complete_other": "{{count}} skills are ready to use",
"agentSkillModal.github.desc": "Paste the URL of a skill directory from a public GitHub repository. The directory must contain a SKILL.md file.",
"agentSkillModal.github.empty": "No SKILL.md found at this URL. Try another repository or directory.",
+ "agentSkillModal.github.example": "https://github.com/owner/repository",
"agentSkillModal.github.find": "Find skills",
"agentSkillModal.github.findFailed": "Couldn’t read this GitHub link. Check the URL and try again.",
+ "agentSkillModal.github.finding": "Finding skills…",
+ "agentSkillModal.github.hint": "Find skills in a public repository, then choose which to import.",
"agentSkillModal.github.importFailed": "Couldn’t import the selected skills. Find skills again, then retry.",
+ "agentSkillModal.github.importSelected_one": "Import {{count}} skill",
+ "agentSkillModal.github.importSelected_other": "Import {{count}} skills",
+ "agentSkillModal.github.importSelected_zero": "Import selected",
"agentSkillModal.github.install": "Import {{count}} ({{updates}} updates)",
+ "agentSkillModal.github.label": "Repository or folder URL",
"agentSkillModal.github.noMatch": "No matching skills",
+ "agentSkillModal.github.noneSelected": "No skills selected yet",
+ "agentSkillModal.github.refreshFailed": "The import finished, but the skill list couldn’t refresh.",
+ "agentSkillModal.github.rescan": "Scan again",
"agentSkillModal.github.retry": "Retry failed imports",
"agentSkillModal.github.sameName": "Choose one of the skills with this name.",
"agentSkillModal.github.search": "Search by name, description or path",
- "agentSkillModal.github.select": "Select all unambiguous matches",
+ "agentSkillModal.github.selectAvailable": "Select all available ({{count}})",
+ "agentSkillModal.github.selectFiltered": "Select matches ({{count}})",
+ "agentSkillModal.github.selectedSkills": "Selected ({{count}})",
+ "agentSkillModal.github.skillDetails": "Details for {{name}}",
"agentSkillModal.github.status.conflict": "Conflict · check the library and scan again",
"agentSkillModal.github.status.created": "Imported",
"agentSkillModal.github.status.failed": "Import failed",
@@ -223,17 +245,34 @@
"agentSkillModal.github.status.updated": "Updated",
"agentSkillModal.github.summary": "{{success}} imported or up to date · {{failed}} failed",
"agentSkillModal.github.title": "Import from GitHub",
- "agentSkillModal.github.urlPlaceholder": "https://github.com/username/repo/tree/main/skills/my-skill",
+ "agentSkillModal.github.updates_one": "Updates {{count}} installed skill",
+ "agentSkillModal.github.updates_other": "Updates {{count}} installed skills",
"agentSkillModal.importError": "Import failed: {{error}}",
"agentSkillModal.importSuccess": "Agent Skill imported successfully",
+ "agentSkillModal.importing": "Importing…",
+ "agentSkillModal.link": "Link",
+ "agentSkillModal.result.created": "Imported {{name}}",
+ "agentSkillModal.result.unchanged": "{{name}} is already up to date",
+ "agentSkillModal.result.updated": "Updated {{name}}",
+ "agentSkillModal.source": "Import source",
+ "agentSkillModal.sources": "From GitHub, a link, or a local file",
+ "agentSkillModal.title": "Import skill",
+ "agentSkillModal.upload.choose": "Choose a file or drag it here",
"agentSkillModal.upload.desc": "Upload a local .zip or .skill file to install.",
- "agentSkillModal.upload.dragText": "Drag and drop or click to upload",
+ "agentSkillModal.upload.failed": "Couldn’t import this package. Check its contents and try again.",
+ "agentSkillModal.upload.hint": "Include a SKILL.md file with a name and description in its YAML front matter.",
+ "agentSkillModal.upload.invalid": "Choose one .zip or .skill file.",
+ "agentSkillModal.upload.label": "Skill package",
+ "agentSkillModal.upload.replace": "{{size}} · Choose another file",
"agentSkillModal.upload.requirementSkillMd": "SKILL.md contains skill name and description in YAML format",
"agentSkillModal.upload.requirementZip": ".zip or .skill file with SKILL.md in root directory",
"agentSkillModal.upload.requirements": "File Requirements",
"agentSkillModal.upload.title": "Upload Skill",
"agentSkillModal.upload.uploading": "Uploading...",
- "agentSkillModal.url.desc": "Import a skill by providing a direct link to a SKILL.md file.",
+ "agentSkillModal.url.failed": "Couldn’t import this link. Check that the file is accessible and try again.",
+ "agentSkillModal.url.hint": "Use a direct link to a SKILL.md file or a skill package.",
+ "agentSkillModal.url.invalid": "Enter a complete URL starting with https:// or http://.",
+ "agentSkillModal.url.label": "Skill URL",
"agentSkillModal.url.title": "Import from URL",
"agentSkillModal.url.urlPlaceholder": "https://example.com/path/to/SKILL.md",
"agentSkillTag": "Agent Skill",
diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.json
index c592a803658..9f142969255 100644
--- a/locales/zh-CN/setting.json
+++ b/locales/zh-CN/setting.json
@@ -199,19 +199,41 @@
"agentSkillModal.contentPlaceholder": "输入 Markdown 格式的技能内容...",
"agentSkillModal.description": "描述",
"agentSkillModal.descriptionPlaceholder": "简要描述该技能",
+ "agentSkillModal.done": "完成",
+ "agentSkillModal.file": "文件",
+ "agentSkillModal.github.allSkills": "全部技能({{count}})",
+ "agentSkillModal.github.batchFailed": "未能导入所选技能。请重试,或重新扫描以查看仓库的最新状态。",
+ "agentSkillModal.github.browseAll": "查看全部技能",
+ "agentSkillModal.github.change": "更换来源",
+ "agentSkillModal.github.chooseMore": "继续选择技能",
"agentSkillModal.github.clear": "清空选择",
- "agentSkillModal.github.collectionHint": "输入公开 GitHub 仓库或技能目录的链接。",
+ "agentSkillModal.github.clearSearch": "清除搜索",
+ "agentSkillModal.github.complete_one": "{{count}} 个技能已就绪",
+ "agentSkillModal.github.complete_other": "{{count}} 个技能已就绪",
"agentSkillModal.github.desc": "粘贴公开 GitHub 仓库中技能目录的 URL,该目录下需包含 SKILL.md 文件。",
"agentSkillModal.github.empty": "此链接下没有找到 SKILL.md,请尝试其他仓库或目录。",
+ "agentSkillModal.github.example": "https://github.com/owner/repository",
"agentSkillModal.github.find": "查找技能",
"agentSkillModal.github.findFailed": "无法读取这个 GitHub 链接,请检查链接后重试。",
+ "agentSkillModal.github.finding": "正在查找技能…",
+ "agentSkillModal.github.hint": "查找公开仓库中的技能,然后选择要导入的项目。",
"agentSkillModal.github.importFailed": "未能导入所选技能,请重新查找后再试。",
+ "agentSkillModal.github.importSelected_one": "导入 {{count}} 个技能",
+ "agentSkillModal.github.importSelected_other": "导入 {{count}} 个技能",
+ "agentSkillModal.github.importSelected_zero": "导入所选技能",
"agentSkillModal.github.install": "导入 {{count}} 项(含 {{updates}} 项更新)",
+ "agentSkillModal.github.label": "仓库或文件夹链接",
"agentSkillModal.github.noMatch": "没有匹配的技能",
+ "agentSkillModal.github.noneSelected": "还没有选择技能",
+ "agentSkillModal.github.refreshFailed": "导入已完成,技能列表刷新失败。",
+ "agentSkillModal.github.rescan": "重新扫描",
"agentSkillModal.github.retry": "重试失败项",
"agentSkillModal.github.sameName": "同名技能只能选择一个。",
"agentSkillModal.github.search": "搜索名称、描述或路径",
- "agentSkillModal.github.select": "全选无重名的匹配项",
+ "agentSkillModal.github.selectAvailable": "全选可导入项({{count}})",
+ "agentSkillModal.github.selectFiltered": "全选匹配项({{count}})",
+ "agentSkillModal.github.selectedSkills": "已选({{count}})",
+ "agentSkillModal.github.skillDetails": "查看 {{name}} 的详情",
"agentSkillModal.github.status.conflict": "存在冲突,请检查技能库后重新查找",
"agentSkillModal.github.status.created": "已导入",
"agentSkillModal.github.status.failed": "导入失败",
@@ -223,17 +245,34 @@
"agentSkillModal.github.status.updated": "已更新",
"agentSkillModal.github.summary": "{{success}} 项已导入或已是最新,{{failed}} 项失败",
"agentSkillModal.github.title": "从 GitHub 导入",
- "agentSkillModal.github.urlPlaceholder": "https://github.com/username/repo/tree/main/skills/my-skill",
+ "agentSkillModal.github.updates_one": "将更新 {{count}} 个已安装的技能",
+ "agentSkillModal.github.updates_other": "将更新 {{count}} 个已安装的技能",
"agentSkillModal.importError": "导入失败:{{error}}",
"agentSkillModal.importSuccess": "Agent 技能导入成功",
+ "agentSkillModal.importing": "正在导入…",
+ "agentSkillModal.link": "链接",
+ "agentSkillModal.result.created": "已导入 {{name}}",
+ "agentSkillModal.result.unchanged": "{{name}} 已是最新版本",
+ "agentSkillModal.result.updated": "已更新 {{name}}",
+ "agentSkillModal.source": "导入来源",
+ "agentSkillModal.sources": "从 GitHub、链接或本地文件导入",
+ "agentSkillModal.title": "导入技能",
+ "agentSkillModal.upload.choose": "选择文件或将文件拖到此处",
"agentSkillModal.upload.desc": "上传本地 .zip 或 .skill 文件以安装技能。",
- "agentSkillModal.upload.dragText": "拖放或点击以上传",
+ "agentSkillModal.upload.failed": "未能导入技能包,请检查文件内容后重试。",
+ "agentSkillModal.upload.hint": "技能包需包含 SKILL.md,文件开头的 YAML 中需填写 name 和 description。",
+ "agentSkillModal.upload.invalid": "请选择一个 .zip 或 .skill 文件。",
+ "agentSkillModal.upload.label": "技能包",
+ "agentSkillModal.upload.replace": "{{size}} · 选择其他文件",
"agentSkillModal.upload.requirementSkillMd": "SKILL.md 包含以 YAML 格式编写的技能名称和描述",
"agentSkillModal.upload.requirementZip": "根目录下包含 SKILL.md 文件的 .zip 或 .skill 文件",
"agentSkillModal.upload.requirements": "文件要求",
"agentSkillModal.upload.title": "上传技能",
"agentSkillModal.upload.uploading": "上传中...",
- "agentSkillModal.url.desc": "通过提供 SKILL.md 文件的直接链接导入技能。",
+ "agentSkillModal.url.failed": "未能从链接导入,请确认文件可以访问后重试。",
+ "agentSkillModal.url.hint": "粘贴 SKILL.md 文件或技能包的直接链接。",
+ "agentSkillModal.url.invalid": "请输入以 https:// 或 http:// 开头的完整链接。",
+ "agentSkillModal.url.label": "技能链接",
"agentSkillModal.url.title": "从 URL 导入",
"agentSkillModal.url.urlPlaceholder": "https://example.com/path/to/SKILL.md",
"agentSkillTag": "Agent 技能",
diff --git a/packages/locales/src/default/setting.ts b/packages/locales/src/default/setting.ts
index 4296f734813..da94b155b3d 100644
--- a/packages/locales/src/default/setting.ts
+++ b/packages/locales/src/default/setting.ts
@@ -331,24 +331,47 @@ export default {
'agentSkillModal.contentPlaceholder': 'Enter skill content in Markdown format...',
'agentSkillModal.description': 'Description',
'agentSkillModal.descriptionPlaceholder': 'Briefly describe this skill',
+ 'agentSkillModal.done': 'Done',
+ 'agentSkillModal.file': 'File',
+ 'agentSkillModal.github.allSkills': 'All skills ({{count}})',
+ 'agentSkillModal.github.batchFailed':
+ 'Couldn’t import the selected skills. Try again or rescan the repository.',
+ 'agentSkillModal.github.browseAll': 'Browse all skills',
+ 'agentSkillModal.github.change': 'Change source',
+ 'agentSkillModal.github.chooseMore': 'Choose more skills',
+ 'agentSkillModal.github.clear': 'Clear selection',
+ 'agentSkillModal.github.clearSearch': 'Clear search',
+ 'agentSkillModal.github.complete_one': '{{count}} skill is ready to use',
+ 'agentSkillModal.github.complete_other': '{{count}} skills are ready to use',
'agentSkillModal.github.desc':
'Paste the URL of a skill directory from a public GitHub repository. The directory must contain a SKILL.md file.',
- 'agentSkillModal.github.clear': 'Clear selection',
- 'agentSkillModal.github.collectionHint':
- 'Enter a public GitHub repository or skill directory URL.',
'agentSkillModal.github.empty':
'No SKILL.md found at this URL. Try another repository or directory.',
+ 'agentSkillModal.github.example': 'https://github.com/owner/repository',
'agentSkillModal.github.find': 'Find skills',
'agentSkillModal.github.findFailed':
'Couldn’t read this GitHub link. Check the URL and try again.',
+ 'agentSkillModal.github.finding': 'Finding skills…',
+ 'agentSkillModal.github.hint': 'Find skills in a public repository, then choose which to import.',
'agentSkillModal.github.importFailed':
'Couldn’t import the selected skills. Find skills again, then retry.',
+ 'agentSkillModal.github.importSelected_one': 'Import {{count}} skill',
+ 'agentSkillModal.github.importSelected_other': 'Import {{count}} skills',
+ 'agentSkillModal.github.importSelected_zero': 'Import selected',
'agentSkillModal.github.install': 'Import {{count}} ({{updates}} updates)',
+ 'agentSkillModal.github.label': 'Repository or folder URL',
'agentSkillModal.github.noMatch': 'No matching skills',
+ 'agentSkillModal.github.noneSelected': 'No skills selected yet',
+ 'agentSkillModal.github.refreshFailed':
+ 'The import finished, but the skill list couldn’t refresh.',
+ 'agentSkillModal.github.rescan': 'Scan again',
'agentSkillModal.github.retry': 'Retry failed imports',
'agentSkillModal.github.sameName': 'Choose one of the skills with this name.',
'agentSkillModal.github.search': 'Search by name, description or path',
- 'agentSkillModal.github.select': 'Select all unambiguous matches',
+ 'agentSkillModal.github.selectAvailable': 'Select all available ({{count}})',
+ 'agentSkillModal.github.selectFiltered': 'Select matches ({{count}})',
+ 'agentSkillModal.github.selectedSkills': 'Selected ({{count}})',
+ 'agentSkillModal.github.skillDetails': 'Details for {{name}}',
'agentSkillModal.github.status.conflict': 'Conflict · check the library and scan again',
'agentSkillModal.github.status.created': 'Imported',
'agentSkillModal.github.status.failed': 'Import failed',
@@ -360,19 +383,38 @@ export default {
'agentSkillModal.github.status.updated': 'Updated',
'agentSkillModal.github.summary': '{{success}} imported or up to date · {{failed}} failed',
'agentSkillModal.github.title': 'Import from GitHub',
- 'agentSkillModal.github.urlPlaceholder':
- 'https://github.com/username/repo/tree/main/skills/my-skill',
+ 'agentSkillModal.github.updates_one': 'Updates {{count}} installed skill',
+ 'agentSkillModal.github.updates_other': 'Updates {{count}} installed skills',
'agentSkillModal.importError': 'Import failed: {{error}}',
'agentSkillModal.importSuccess': 'Agent Skill imported successfully',
+ 'agentSkillModal.importing': 'Importing…',
+ 'agentSkillModal.link': 'Link',
+ 'agentSkillModal.result.created': 'Imported {{name}}',
+ 'agentSkillModal.result.unchanged': '{{name}} is already up to date',
+ 'agentSkillModal.result.updated': 'Updated {{name}}',
+ 'agentSkillModal.source': 'Import source',
+ 'agentSkillModal.sources': 'From GitHub, a link, or a local file',
+ 'agentSkillModal.title': 'Import skill',
+ 'agentSkillModal.upload.choose': 'Choose a file or drag it here',
'agentSkillModal.upload.desc': 'Upload a local .zip or .skill file to install.',
- 'agentSkillModal.upload.dragText': 'Drag and drop or click to upload',
+ 'agentSkillModal.upload.failed':
+ 'Couldn’t import this package. Check its contents and try again.',
+ 'agentSkillModal.upload.hint':
+ 'Include a SKILL.md file with a name and description in its YAML front matter.',
+ 'agentSkillModal.upload.invalid': 'Choose one .zip or .skill file.',
+ 'agentSkillModal.upload.label': 'Skill package',
+ 'agentSkillModal.upload.replace': '{{size}} · Choose another file',
'agentSkillModal.upload.requirementSkillMd':
'SKILL.md contains skill name and description in YAML format',
'agentSkillModal.upload.requirementZip': '.zip or .skill file with SKILL.md in root directory',
'agentSkillModal.upload.requirements': 'File Requirements',
'agentSkillModal.upload.title': 'Upload Skill',
'agentSkillModal.upload.uploading': 'Uploading...',
- 'agentSkillModal.url.desc': 'Import a skill by providing a direct link to a SKILL.md file.',
+ 'agentSkillModal.url.failed':
+ 'Couldn’t import this link. Check that the file is accessible and try again.',
+ 'agentSkillModal.url.hint': 'Use a direct link to a SKILL.md file or a skill package.',
+ 'agentSkillModal.url.invalid': 'Enter a complete URL starting with https:// or http://.',
+ 'agentSkillModal.url.label': 'Skill URL',
'agentSkillModal.url.title': 'Import from URL',
'agentSkillModal.url.urlPlaceholder': 'https://example.com/path/to/SKILL.md',
'agentSkillTag': 'Agent Skill',
diff --git a/src/features/Settings/skill/features/LeftPanel.tsx b/src/features/Settings/skill/features/LeftPanel.tsx
index eab9d39029f..9038b8b6d76 100644
--- a/src/features/Settings/skill/features/LeftPanel.tsx
+++ b/src/features/Settings/skill/features/LeftPanel.tsx
@@ -1,18 +1,15 @@
'use client';
import { Button, DropdownMenu, Flexbox, Icon, SearchBar, Text, Tooltip } from '@lobehub/ui';
-import { GithubIcon } from '@lobehub/ui/icons';
import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
-import { ChevronDown, FileArchive, Grid2x2Plus, Link, Plus, Store } from 'lucide-react';
+import { ChevronDown, Grid2x2Plus, Import, Plus, Store } from 'lucide-react';
import { memo, useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { CustomConnectorModal } from '@/features/Connectors';
import { createSkillStoreModal } from '@/features/SkillStore';
-import { openImportFromGithubModal } from '@/features/SkillStore/SkillList/ImportFromGithubModal';
-import { openImportFromUrlModal } from '@/features/SkillStore/SkillList/ImportFromUrlModal';
-import { openUploadSkillModal } from '@/features/SkillStore/SkillList/UploadSkillModal';
+import { openSkillImportModal } from '@/features/SkillStore/SkillImportModal';
import { useConnectorManageable } from '@/hooks/useConnectorManagePolicy';
import { usePermission } from '@/hooks/usePermission';
@@ -141,28 +138,12 @@ const LeftPanel = memo<LeftPanelProps>(
...(!isConnectorView
? [
{
- desc: t('tab.importFromGithub.desc'),
+ desc: t('agentSkillModal.sources'),
disabled: !canCreate,
- icon: <Icon icon={GithubIcon} />,
- key: 'importGithub',
- label: t('tab.importFromGithub'),
- onClick: () => openImportFromGithubModal(),
- },
- {
- desc: t('tab.importFromUrl.desc'),
- disabled: !canCreate,
- icon: <Icon icon={Link} />,
- key: 'importUrl',
- label: t('tab.importFromUrl'),
- onClick: () => openImportFromUrlModal(),
- },
- {
- desc: t('tab.uploadZip.desc'),
- disabled: !canCreate,
- icon: <Icon icon={FileArchive} />,
- key: 'uploadZip',
- label: t('tab.uploadZip'),
- onClick: () => openUploadSkillModal(),
+ icon: <Icon icon={Import} />,
+ key: 'import',
+ label: t('agentSkillModal.title'),
+ onClick: openSkillImportModal,
},
]
: []),
@@ -264,54 +245,14 @@ const LeftPanel = memo<LeftPanelProps>(
</span>
</Tooltip>
) : (
- // Skill view: import a skill from a URL, GitHub, or a zip upload.
- <DropdownMenu
- nativeButton={false}
- placement="bottomRight"
- items={[
- {
- icon: <Icon icon={Link} />,
- key: 'importUrl',
- label: (
- <Flexbox gap={2}>
- <span>{t('tab.importFromUrl')}</span>
- <Text style={{ fontSize: 12 }} type="secondary">
- {t('tab.importFromUrl.desc')}
- </Text>
- </Flexbox>
- ),
- onClick: () => openImportFromUrlModal(),
- },
- {
- icon: <Icon icon={GithubIcon} />,
- key: 'importGithub',
- label: (
- <Flexbox gap={2}>
- <span>{t('tab.importFromGithub')}</span>
- <Text style={{ fontSize: 12 }} type="secondary">
- {t('tab.importFromGithub.desc')}
- </Text>
- </Flexbox>
- ),
- onClick: () => openImportFromGithubModal(),
- },
- {
- icon: <Icon icon={FileArchive} />,
- key: 'uploadZip',
- label: (
- <Flexbox gap={2}>
- <span>{t('tab.uploadZip')}</span>
- <Text style={{ fontSize: 12 }} type="secondary">
- {t('tab.uploadZip.desc')}
- </Text>
- </Flexbox>
- ),
- onClick: () => openUploadSkillModal(),
- },
- ]}
- >
- <Button aria-label={t('connectorMarket.add')} icon={Grid2x2Plus} size="small" />
- </DropdownMenu>
+ <Button
+ aria-label={t('agentSkillModal.title')}
+ disabled={!canCreate}
+ icon={Import}
+ size="small"
+ title={t('agentSkillModal.title')}
+ onClick={openSkillImportModal}
+ />
)}
<Button
aria-label={t('skillStore.title')}
diff --git a/src/features/SkillStore/SkillImportModal/GithubImport.tsx b/src/features/SkillStore/SkillImportModal/GithubImport.tsx
new file mode 100644
index 00000000000..7ab428695e0
--- /dev/null
+++ b/src/features/SkillStore/SkillImportModal/GithubImport.tsx
@@ -0,0 +1,241 @@
+import { Button, Flexbox, Icon, Input, Tag, Text, useModalContext } from '@lobehub/ui';
+import { GithubIcon } from '@lobehub/ui/icons';
+import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
+import * as stylex from '@stylexjs/stylex';
+import { CheckCircle2, CircleAlert } from 'lucide-react';
+import { useId } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import AsyncError from '@/components/AsyncError';
+
+import { GithubSkillPicker } from './GithubSkillPicker';
+import { canImportCandidate } from './githubSkillSelection';
+import type { useGithubSkillImport } from './useGithubSkillImport';
+
+const styles = stylex.create({
+ list: {
+ maxHeight: 'min(36dvh, 320px)',
+ overflowY: 'auto',
+ overscrollBehavior: 'contain',
+ borderWidth: 1,
+ borderStyle: 'solid',
+ borderColor: cssVar.colorBorderSecondary,
+ borderRadius: cssVar.borderRadiusLG,
+ },
+ row: {
+ paddingBlock: 10,
+ paddingInline: 12,
+ borderBlockEndWidth: { 'default': 1, ':last-child': 0 },
+ borderBlockEndStyle: 'solid',
+ borderBlockEndColor: cssVar.colorBorderSecondary,
+ },
+});
+
+export const GithubImport = ({ state }: { state: ReturnType<typeof useGithubSkillImport> }) => {
+ const { t } = useTranslation(['setting', 'common']);
+ const { close } = useModalContext();
+ const inputId = useId();
+ const {
+ canCreate,
+ candidates,
+ discover,
+ failure,
+ install,
+ loading,
+ pending,
+ refreshLibrary,
+ results,
+ scan,
+ selected,
+ setUrl,
+ url,
+ } = state;
+
+ const chosen = candidates.filter((item) => selected.includes(item.path));
+ const updates = chosen.filter((item) => item.status === 'update').length;
+ const finished = results.length > 0;
+ const outcomes = new Map(results.map((item) => [item.path, item.status]));
+ const remaining = candidates.some((item) => canImportCandidate(item) && !outcomes.has(item.path));
+ const failed = results.filter((item) => item.status === 'failed').map((item) => item.path);
+ const hasRetryableFailures = failed.length > 0;
+ const failureCount = results.filter((item) =>
+ ['failed', 'conflict', 'forbidden'].includes(item.status),
+ ).length;
+ const error = failure && (
+ <AsyncError
+ align="start"
+ details={failure.details}
+ retrying={loading}
+ variant="inline"
+ action={
+ scan && failure.stage !== 'refresh' ? (
+ <Button disabled={loading || !canCreate} size="small" type="text" onClick={discover}>
+ {t('agentSkillModal.github.rescan')}
+ </Button>
+ ) : undefined
+ }
+ title={t(
+ failure.stage === 'import'
+ ? 'agentSkillModal.github.batchFailed'
+ : `agentSkillModal.github.${failure.stage}Failed`,
+ )}
+ onRetry={failure.stage === 'refresh' ? refreshLibrary : undefined}
+ />
+ );
+
+ if (!scan)
+ return (
+ <Flexbox gap={20}>
+ <Flexbox gap={8}>
+ <label htmlFor={inputId}>
+ <Text strong as="span">
+ {t('agentSkillModal.github.label')}
+ </Text>
+ </label>
+ <Input
+ aria-describedby={inputId + '-hint'}
+ disabled={loading || !canCreate}
+ id={inputId}
+ placeholder={t('agentSkillModal.github.example')}
+ prefix={<Icon icon={GithubIcon} />}
+ value={url}
+ onChange={(event) => setUrl(event.target.value)}
+ onPressEnter={discover}
+ />
+ <Text fontSize={13} id={inputId + '-hint'} type="secondary">
+ {t('agentSkillModal.github.hint')}
+ </Text>
+ </Flexbox>
+ {error}
+ <Flexbox horizontal justify="flex-end">
+ <Button
+ disabled={!canCreate || !url.trim()}
+ loading={loading}
+ type="primary"
+ onClick={discover}
+ >
+ {t(loading ? 'agentSkillModal.github.finding' : 'agentSkillModal.github.find')}
+ </Button>
+ </Flexbox>
+ </Flexbox>
+ );
+
+ return (
+ <Flexbox gap={16}>
+ <Flexbox horizontal align="center" gap={8}>
+ <Icon icon={GithubIcon} />
+ <Text ellipsis={{ tooltip: true }} style={{ flex: 1, minWidth: 0 }} type="secondary">
+ {url.trim().replace(/^https?:\/\//i, '')}
+ </Text>
+ <Button
+ disabled={loading}
+ loading={pending === 'find'}
+ size="small"
+ onClick={() => setUrl(url)}
+ >
+ {t(
+ pending === 'find' ? 'agentSkillModal.github.finding' : 'agentSkillModal.github.change',
+ )}
+ </Button>
+ </Flexbox>
+ {error}
+ {finished ? (
+ <>
+ <Flexbox horizontal align="center" gap={8} role="status">
+ <Icon icon={failureCount ? CircleAlert : CheckCircle2} />
+ <Text strong>
+ {failureCount
+ ? t('agentSkillModal.github.summary', {
+ success: results.length - failureCount,
+ failed: failureCount,
+ })
+ : t('agentSkillModal.github.complete', { count: results.length })}
+ </Text>
+ </Flexbox>
+ <Flexbox {...stylex.props(styles.list)}>
+ {candidates
+ .filter((item) => outcomes.has(item.path))
+ .map((item) => (
+ <Flexbox gap={4} key={item.path} {...stylex.props(styles.row)}>
+ <Flexbox horizontal align="center" gap={8} justify="space-between" wrap="wrap">
+ <Text strong wordBreak="break-word">
+ {item.name}
+ </Text>
+ <Tag size="small" style={{ whiteSpace: 'normal' }}>
+ {t(`agentSkillModal.github.status.${outcomes.get(item.path)!}`)}
+ </Tag>
+ </Flexbox>
+ <Text fontSize={12} type="secondary" wordBreak="break-all">
+ {item.path || '/'}
+ </Text>
+ </Flexbox>
+ ))}
+ </Flexbox>
+ </>
+ ) : candidates.length ? (
+ <GithubSkillPicker state={state} />
+ ) : (
+ <Text role="status" type="secondary">
+ {t('agentSkillModal.github.empty')}
+ </Text>
+ )}
+ <Flexbox horizontal align="center" gap={8} justify="flex-end" wrap="wrap">
+ {finished ? (
+ <>
+ {(failureCount > failed.length || remaining) && (
+ <Button
+ disabled={!canCreate || loading}
+ loading={pending === 'find'}
+ onClick={discover}
+ >
+ {t(
+ failureCount > failed.length
+ ? 'agentSkillModal.github.rescan'
+ : 'agentSkillModal.github.chooseMore',
+ )}
+ </Button>
+ )}
+ <Button
+ disabled={loading || (hasRetryableFailures && !canCreate)}
+ loading={hasRetryableFailures && pending === 'import'}
+ type="primary"
+ onClick={hasRetryableFailures ? () => install(failed) : close}
+ >
+ {t(hasRetryableFailures ? 'agentSkillModal.github.retry' : 'agentSkillModal.done')}
+ </Button>
+ {hasRetryableFailures && (
+ <Button disabled={loading} onClick={close}>
+ {t('agentSkillModal.done')}
+ </Button>
+ )}
+ </>
+ ) : candidates.some(canImportCandidate) ? (
+ <>
+ {updates > 0 && (
+ <Text fontSize={13} type="secondary">
+ {t('agentSkillModal.github.updates', { count: updates })}
+ </Text>
+ )}
+ <Button
+ disabled={!canCreate || loading || !chosen.length}
+ loading={pending === 'import'}
+ type="primary"
+ onClick={() => install(selected)}
+ >
+ {t(
+ pending === 'import'
+ ? 'agentSkillModal.importing'
+ : 'agentSkillModal.github.importSelected',
+ {
+ count: chosen.length,
+ },
+ )}
+ </Button>
+ </>
+ ) : (
+ <Button onClick={close}>{t('common:close')}</Button>
+ )}
+ </Flexbox>
+ </Flexbox>
+ );
+};
diff --git a/src/features/SkillStore/SkillImportModal/GithubSkillPicker.tsx b/src/features/SkillStore/SkillImportModal/GithubSkillPicker.tsx
new file mode 100644
index 00000000000..0944c7a94bd
--- /dev/null
+++ b/src/features/SkillStore/SkillImportModal/GithubSkillPicker.tsx
@@ -0,0 +1,266 @@
+import type { GitHubSkillCandidate } from '@lobechat/types';
+import { ActionIcon, Button, Checkbox, Flexbox, Icon, Input, Tabs, Tag, Text } from '@lobehub/ui';
+import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
+import * as stylex from '@stylexjs/stylex';
+import { ChevronDown, ChevronUp, Search } from 'lucide-react';
+import { useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import {
+ canImportCandidate,
+ getGithubSkillChoices,
+ toggleGithubSkillPaths,
+} from './githubSkillSelection';
+import type { useGithubSkillImport } from './useGithubSkillImport';
+
+const styles = stylex.create({
+ frame: {
+ borderWidth: 1,
+ borderStyle: 'solid',
+ borderColor: cssVar.colorBorderSecondary,
+ borderRadius: cssVar.borderRadiusLG,
+ overflow: 'hidden',
+ },
+ toolbar: {
+ backgroundColor: cssVar.colorFillQuaternary,
+ paddingBlock: 6,
+ paddingInline: 12,
+ },
+ list: {
+ maxHeight: 'min(40dvh, 360px)',
+ overflowY: 'auto',
+ overscrollBehavior: 'contain',
+ },
+ row: {
+ borderBlockStartWidth: { 'default': 1, ':first-child': 0 },
+ borderBlockStartStyle: 'solid',
+ borderBlockStartColor: cssVar.colorBorderSecondary,
+ paddingInline: 12,
+ },
+ label: { flexGrow: 1, flexBasis: 0, minWidth: 0, paddingBlock: 9, minHeight: 46 },
+ text: { flexGrow: 1, minWidth: 0, whiteSpace: 'normal' },
+ choice: { backgroundColor: cssVar.colorFillQuaternary },
+ tabs: { marginBlockEnd: 0 },
+});
+
+interface CandidateRowProps {
+ checked: boolean;
+ collapsible: boolean;
+ disabled: boolean;
+ duplicate: boolean;
+ item: GitHubSkillCandidate;
+ onChange: (checked: boolean) => void;
+}
+
+const CandidateRow = ({
+ checked,
+ collapsible,
+ disabled,
+ duplicate,
+ item,
+ onChange,
+}: CandidateRowProps) => {
+ const { t } = useTranslation('setting');
+ const [expanded, setExpanded] = useState(false);
+ const showDetails = !collapsible || expanded;
+ const details = t('agentSkillModal.github.skillDetails', { name: item.name });
+ return (
+ <Flexbox
+ horizontal
+ align="center"
+ gap={4}
+ {...stylex.props(styles.row, checked && styles.choice)}
+ >
+ <Checkbox
+ aria-label={item.name + ' ' + (item.path || '/')}
+ checked={checked}
+ disabled={disabled}
+ classNames={{
+ text: stylex.props(styles.text).className,
+ wrapper: stylex.props(styles.label).className,
+ }}
+ onChange={onChange}
+ >
+ <Flexbox as="span" gap={2}>
+ <Flexbox horizontal align="center" as="span" gap={6} wrap="wrap">
+ <Text strong as="span" wordBreak="break-word">
+ {item.name}
+ </Text>
+ {(!collapsible || item.status !== 'new') && (
+ <Tag size="small" style={{ whiteSpace: 'normal' }}>
+ {t(`agentSkillModal.github.status.${item.status}`)}
+ </Tag>
+ )}
+ </Flexbox>
+ {item.description && (
+ <Text
+ as="span"
+ fontSize={13}
+ lineClamp={showDetails ? undefined : 1}
+ type="secondary"
+ wordBreak="break-word"
+ >
+ {item.description}
+ </Text>
+ )}
+ {(showDetails || duplicate) && (
+ <Text as="span" fontSize={12} type="secondary" wordBreak="break-all">
+ {item.path || '/'}
+ </Text>
+ )}
+ {duplicate && (
+ <Text as="span" fontSize={12} type="secondary">
+ {t('agentSkillModal.github.sameName')}
+ </Text>
+ )}
+ </Flexbox>
+ </Checkbox>
+ {collapsible && (
+ <ActionIcon
+ aria-expanded={expanded}
+ aria-label={details}
+ icon={expanded ? ChevronUp : ChevronDown}
+ size={{ blockSize: 44, size: 16 }}
+ title={details}
+ onClick={() => setExpanded(!expanded)}
+ />
+ )}
+ </Flexbox>
+ );
+};
+
+export const GithubSkillPicker = ({
+ state,
+}: {
+ state: ReturnType<typeof useGithubSkillImport>;
+}) => {
+ const { t } = useTranslation('setting');
+ const { candidates, canCreate, loading, query, selected, setQuery, setSelected } = state;
+ const [selectedOnly, setSelectedOnly] = useState(false);
+ const multiple = candidates.length > 1;
+ const { bulkPaths, checkedCount, duplicateNames, selectedNames, selectedPaths, visible } =
+ getGithubSkillChoices(candidates, selected, query, multiple && selectedOnly);
+ const allChecked = bulkPaths.length > 0 && checkedCount === bulkPaths.length;
+ const changeSelection = (paths: string[], checked: boolean) =>
+ setSelected((current) => toggleGithubSkillPaths(current, paths, checked));
+
+ const list = (
+ <Flexbox {...stylex.props(styles.frame)}>
+ {multiple && !selectedOnly && (
+ <Flexbox horizontal align="center" {...stylex.props(styles.toolbar)}>
+ <Checkbox
+ checked={allChecked}
+ disabled={!canCreate || loading || !bulkPaths.length}
+ indeterminate={checkedCount > 0 && !allChecked}
+ onChange={(checked) => changeSelection(bulkPaths, checked)}
+ >
+ {t(
+ query.trim()
+ ? 'agentSkillModal.github.selectFiltered'
+ : 'agentSkillModal.github.selectAvailable',
+ { count: bulkPaths.length },
+ )}
+ </Checkbox>
+ </Flexbox>
+ )}
+ {multiple && selectedOnly && selected.length > 0 && (
+ <Flexbox horizontal justify="flex-end" {...stylex.props(styles.toolbar)}>
+ <Button
+ disabled={loading || !canCreate}
+ size="small"
+ type="text"
+ onClick={() => setSelected([])}
+ >
+ {t('agentSkillModal.github.clear')}
+ </Button>
+ </Flexbox>
+ )}
+ {/* Reserve the collection viewport while filtering so the centered dialog
+ keeps the search field and import button in place. */}
+ <Flexbox
+ key={selectedOnly ? 'selected' : query}
+ {...stylex.props(styles.list)}
+ height={multiple ? candidates.length * 64 : undefined}
+ >
+ {visible.map((item) => {
+ const checked = selectedPaths.has(item.path);
+ const name = item.name.toLowerCase();
+ return (
+ <CandidateRow
+ checked={checked}
+ collapsible={multiple}
+ duplicate={canImportCandidate(item) && duplicateNames.has(name)}
+ item={item}
+ key={item.path}
+ disabled={
+ !canCreate ||
+ loading ||
+ !canImportCandidate(item) ||
+ (!checked && selectedNames.has(name))
+ }
+ onChange={(next) => changeSelection([item.path], next)}
+ />
+ );
+ })}
+ {!visible.length && (
+ <Flexbox align="center" gap={6} padding={20}>
+ <Text role="status" type="secondary">
+ {t(
+ selectedOnly
+ ? 'agentSkillModal.github.noneSelected'
+ : 'agentSkillModal.github.noMatch',
+ )}
+ </Text>
+ <Button
+ size="small"
+ type="text"
+ onClick={() => (selectedOnly ? setSelectedOnly(false) : setQuery(''))}
+ >
+ {t(
+ selectedOnly
+ ? 'agentSkillModal.github.browseAll'
+ : 'agentSkillModal.github.clearSearch',
+ )}
+ </Button>
+ </Flexbox>
+ )}
+ </Flexbox>
+ </Flexbox>
+ );
+
+ if (!multiple) return list;
+
+ return (
+ <Tabs
+ activeKey={selectedOnly ? 'selected' : 'all'}
+ classNames={{ list: stylex.props(styles.tabs).className }}
+ size="small"
+ variant="square"
+ items={[
+ {
+ key: 'all',
+ label: t('agentSkillModal.github.allSkills', { count: candidates.length }),
+ children: (
+ <Flexbox gap={8}>
+ <Input
+ allowClear
+ aria-label={t('agentSkillModal.github.search')}
+ placeholder={t('agentSkillModal.github.search')}
+ prefix={<Icon icon={Search} />}
+ value={query}
+ onChange={(event) => setQuery(event.target.value)}
+ />
+ {!selectedOnly && list}
+ </Flexbox>
+ ),
+ },
+ {
+ key: 'selected',
+ label: t('agentSkillModal.github.selectedSkills', { count: selected.length }),
+ children: selectedOnly && list,
+ },
+ ]}
+ onChange={(key) => setSelectedOnly(key === 'selected')}
+ />
+ );
+};
diff --git a/src/features/SkillStore/SkillImportModal/SingleSkillImport.tsx b/src/features/SkillStore/SkillImportModal/SingleSkillImport.tsx
new file mode 100644
index 00000000000..9da28e15b33
--- /dev/null
+++ b/src/features/SkillStore/SkillImportModal/SingleSkillImport.tsx
@@ -0,0 +1,190 @@
+import { formatSize } from '@lobechat/utils/format';
+import { Button, Flexbox, Icon, Input, Text, toast, Upload, useModalContext } from '@lobehub/ui';
+import { sha256 } from 'js-sha256';
+import { FileArchive, FileUp, Link } from 'lucide-react';
+import { useId, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import AsyncError from '@/components/AsyncError';
+import { lambdaClient } from '@/libs/trpc/client/lambda';
+import { uploadService } from '@/services/upload';
+import { useToolStore } from '@/store/tool';
+
+const uploadArchive = async (file: File) => {
+ const { data } = await uploadService.uploadFileToS3(file, { directory: 'skills' });
+ try {
+ const record = await lambdaClient.file.createFile.mutate({
+ fileType: file.type || 'application/zip',
+ hash: sha256(await file.arrayBuffer()),
+ metadata: {},
+ name: file.name,
+ size: file.size,
+ url: data.path,
+ });
+ return record.id;
+ } catch (error) {
+ await uploadService.releaseUpload(data.path);
+ throw error;
+ }
+};
+
+interface SingleSkillImportProps {
+ canCreate: boolean;
+ loading: boolean;
+ onLoadingChange: (loading: boolean) => void;
+ source: 'url' | 'file';
+}
+
+export const SingleSkillImport = ({
+ canCreate,
+ loading,
+ onLoadingChange,
+ source,
+}: SingleSkillImportProps) => {
+ const { t } = useTranslation('setting');
+ const { close } = useModalContext();
+ const inputId = useId();
+ const [url, setUrl] = useState('');
+ const [file, setFile] = useState<File>();
+ const [fileId, setFileId] = useState<string>();
+ const [invalidUrl, setInvalidUrl] = useState(false);
+ const [invalidFile, setInvalidFile] = useState(false);
+ const [error, setError] = useState<string>();
+ const fromUrl = useToolStore((s) => s.importAgentSkillFromUrl);
+ const fromZip = useToolStore((s) => s.importAgentSkillFromZip);
+ const isLink = source === 'url';
+ const ready = isLink ? !!url.trim() : !!file;
+
+ // Upload silently filters unsupported files before calling onFiles. Clear the
+ // previous selection so an accidental drop cannot import the wrong package.
+ const checkFileTypes = (files: FileList | null) => {
+ if (!files?.length || loading || !canCreate) return;
+ if (Array.from(files).some((entry) => /\.(zip|skill)$/i.test(entry.name))) return;
+ setFile(undefined);
+ setFileId(undefined);
+ setError(undefined);
+ setInvalidFile(true);
+ };
+
+ const submit = async () => {
+ if (!ready || loading || !canCreate) return;
+ if (
+ isLink &&
+ (!URL.canParse(url.trim()) || !['https:', 'http:'].includes(new URL(url.trim()).protocol))
+ ) {
+ setInvalidUrl(true);
+ return;
+ }
+ onLoadingChange(true);
+ setError(undefined);
+ try {
+ let result;
+ if (isLink) {
+ result = await fromUrl({ url: url.trim() });
+ } else if (file) {
+ const zipFileId = fileId ?? (await uploadArchive(file));
+ setFileId(zipFileId);
+ result = await fromZip({ zipFileId });
+ }
+ toast.success(
+ result
+ ? t(`agentSkillModal.result.${result.status}`, { name: result.skill.name })
+ : t('agentSkillModal.importSuccess'),
+ );
+ close();
+ } catch (err) {
+ setError(err instanceof Error ? err.message : String(err));
+ } finally {
+ onLoadingChange(false);
+ }
+ };
+
+ return (
+ <Flexbox gap={20}>
+ {isLink ? (
+ <Flexbox gap={8}>
+ <label htmlFor={inputId}>
+ <Text strong as="span">
+ {t('agentSkillModal.url.label')}
+ </Text>
+ </label>
+ <Input
+ aria-describedby={inputId + '-hint'}
+ aria-invalid={invalidUrl}
+ disabled={loading || !canCreate}
+ id={inputId}
+ placeholder={t('agentSkillModal.url.urlPlaceholder')}
+ prefix={<Icon icon={Link} />}
+ value={url}
+ onPressEnter={submit}
+ onChange={(event) => {
+ setUrl(event.target.value);
+ setInvalidUrl(false);
+ setError(undefined);
+ }}
+ />
+ <Text
+ fontSize={13}
+ id={inputId + '-hint'}
+ role={invalidUrl ? 'alert' : undefined}
+ type={invalidUrl ? 'danger' : 'secondary'}
+ >
+ {t(invalidUrl ? 'agentSkillModal.url.invalid' : 'agentSkillModal.url.hint')}
+ </Text>
+ </Flexbox>
+ ) : (
+ <Flexbox gap={8}>
+ <Text strong>{t('agentSkillModal.upload.label')}</Text>
+ <Upload
+ dragger
+ accept=".zip,.skill"
+ disabled={loading || !canCreate}
+ maxCount={1}
+ onDropCapture={(event) => checkFileTypes(event.dataTransfer.files)}
+ onChangeCapture={(event) => {
+ if (event.target instanceof HTMLInputElement) checkFileTypes(event.target.files);
+ }}
+ onFiles={([next]) => {
+ setInvalidFile(false);
+ setFile(next);
+ setFileId(undefined);
+ setError(undefined);
+ }}
+ >
+ <Flexbox align="center" gap={6} padding={12}>
+ <Icon icon={file ? FileArchive : FileUp} size={24} />
+ <Text strong align="center" wordBreak="break-word">
+ {file?.name ?? t('agentSkillModal.upload.choose')}
+ </Text>
+ <Text fontSize={13} type="secondary">
+ {file
+ ? t('agentSkillModal.upload.replace', { size: formatSize(file.size) })
+ : '.zip / .skill'}
+ </Text>
+ </Flexbox>
+ </Upload>
+ <Text
+ fontSize={13}
+ role={invalidFile ? 'alert' : undefined}
+ type={invalidFile ? 'danger' : 'secondary'}
+ >
+ {t(invalidFile ? 'agentSkillModal.upload.invalid' : 'agentSkillModal.upload.hint')}
+ </Text>
+ </Flexbox>
+ )}
+ {error && (
+ <AsyncError
+ align="start"
+ details={error}
+ title={t(isLink ? 'agentSkillModal.url.failed' : 'agentSkillModal.upload.failed')}
+ variant="inline"
+ />
+ )}
+ <Flexbox horizontal justify="flex-end">
+ <Button disabled={!canCreate || !ready} loading={loading} type="primary" onClick={submit}>
+ {t(loading ? 'agentSkillModal.importing' : 'agentSkillModal.title')}
+ </Button>
+ </Flexbox>
+ </Flexbox>
+ );
+};
diff --git a/src/features/SkillStore/SkillImportModal/githubSkillSelection.test.ts b/src/features/SkillStore/SkillImportModal/githubSkillSelection.test.ts
new file mode 100644
index 00000000000..74729e7fdcd
--- /dev/null
+++ b/src/features/SkillStore/SkillImportModal/githubSkillSelection.test.ts
@@ -0,0 +1,75 @@
+import type { GitHubSkillCandidate } from '@lobechat/types';
+import { describe, expect, it } from 'vitest';
+
+import { getGithubSkillChoices, toggleGithubSkillPaths } from './githubSkillSelection';
+
+const skill = (
+ path: string,
+ status: GitHubSkillCandidate['status'] = 'new',
+): GitHubSkillCandidate => ({
+ description: '',
+ name: path.split('/').at(-1)!,
+ path,
+ revision: null,
+ status,
+});
+
+const collection = [
+ skill('writing/draft'),
+ skill('writing/edit', 'update'),
+ skill('design/layout'),
+ skill('writing/style'),
+ skill('design/Style'),
+ skill('writing/installed', 'unchanged'),
+];
+
+describe('GitHub collection selection', () => {
+ it('selects or clears just the eligible matches and preserves manual and hidden choices', () => {
+ const selected = ['design/layout', 'writing/style', 'writing/edit'];
+ const { bulkPaths, checkedCount } = getGithubSkillChoices(
+ collection,
+ selected,
+ ' WRITING ',
+ false,
+ );
+ expect(bulkPaths).toEqual(['writing/draft', 'writing/edit']);
+ expect(checkedCount).toBe(1);
+
+ const all = toggleGithubSkillPaths(selected, bulkPaths, true);
+ expect(getGithubSkillChoices(collection, all, 'writing', false).checkedCount).toBe(2);
+ expect(toggleGithubSkillPaths(all, bulkPaths, false)).toEqual([
+ 'design/layout',
+ 'writing/style',
+ ]);
+ });
+
+ it('reviews all selected paths across searches, including same-name skills chosen manually', () => {
+ const selected = ['writing/style', 'design/layout'];
+ const review = getGithubSkillChoices(collection, selected, 'no matches', true);
+ expect(review.visible.map((item) => item.path)).toEqual(['design/layout', 'writing/style']);
+ expect(review.duplicateNames.has('style')).toBe(true);
+ expect(review.selectedNames.has('style')).toBe(true);
+ const remaining = toggleGithubSkillPaths(selected, ['writing/style'], false);
+ expect(
+ getGithubSkillChoices(collection, remaining, 'no matches', true).selectedNames.has('style'),
+ ).toBe(false);
+ expect(getGithubSkillChoices(collection, remaining, 'no matches', false).visible).toEqual([]);
+ });
+
+ it('keeps root paths selectable and excludes unavailable skills', () => {
+ const root = { ...skill('repo'), path: '', description: 'Root candidate' };
+ const choices = getGithubSkillChoices(
+ [
+ root,
+ skill('invalid', 'invalid'),
+ skill('conflict', 'conflict'),
+ skill('blocked', 'forbidden'),
+ ],
+ [],
+ '',
+ false,
+ );
+ expect(choices.bulkPaths).toEqual(['']);
+ expect(getGithubSkillChoices([root], [''], 'CANDIDATE', false).checkedCount).toBe(1);
+ });
+});
diff --git a/src/features/SkillStore/SkillImportModal/githubSkillSelection.ts b/src/features/SkillStore/SkillImportModal/githubSkillSelection.ts
new file mode 100644
index 00000000000..57a4c29368d
--- /dev/null
+++ b/src/features/SkillStore/SkillImportModal/githubSkillSelection.ts
@@ -0,0 +1,48 @@
+import type { GitHubSkillCandidate } from '@lobechat/types';
+
+export const canImportCandidate = ({ status }: GitHubSkillCandidate) =>
+ status === 'new' || status === 'update';
+
+export const getGithubSkillChoices = (
+ candidates: GitHubSkillCandidate[],
+ selected: string[],
+ query: string,
+ selectedOnly: boolean,
+) => {
+ const selectedPaths = new Set(selected);
+ const selectedNames = new Set<string>();
+ const eligibleNames = new Set<string>();
+ const duplicateNames = new Set<string>();
+
+ // Resolve collisions against the entire scan, including paths hidden by a search.
+ for (const item of candidates) {
+ const name = item.name.toLowerCase();
+ if (selectedPaths.has(item.path)) selectedNames.add(name);
+ if (!canImportCandidate(item)) continue;
+ if (eligibleNames.has(name)) duplicateNames.add(name);
+ eligibleNames.add(name);
+ }
+
+ const needle = query.trim().toLowerCase();
+ const visible = selectedOnly
+ ? candidates.filter((item) => selectedPaths.has(item.path))
+ : candidates.filter(({ name, description, path }) =>
+ [name, description, path].some((value) => value.toLowerCase().includes(needle)),
+ );
+
+ const bulkPaths = visible
+ .filter((item) => canImportCandidate(item) && !duplicateNames.has(item.name.toLowerCase()))
+ .map((item) => item.path);
+ const checkedCount = bulkPaths.filter((path) => selectedPaths.has(path)).length;
+
+ return { bulkPaths, checkedCount, duplicateNames, selectedNames, selectedPaths, visible };
+};
+
+export const toggleGithubSkillPaths = (selected: string[], paths: string[], checked: boolean) => {
+ const next = new Set(selected);
+ for (const path of paths) {
+ if (checked) next.add(path);
+ else next.delete(path);
+ }
+ return [...next];
+};
diff --git a/src/features/SkillStore/SkillImportModal/index.tsx b/src/features/SkillStore/SkillImportModal/index.tsx
new file mode 100644
index 00000000000..50fde22c349
--- /dev/null
+++ b/src/features/SkillStore/SkillImportModal/index.tsx
@@ -0,0 +1,63 @@
+'use client';
+
+import { createModal, Flexbox, Icon, Segmented, useModalContext } from '@lobehub/ui';
+import { GithubIcon } from '@lobehub/ui/icons';
+import { t } from 'i18next';
+import { FileArchive, Link } from 'lucide-react';
+import { Activity, useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { GithubImport } from './GithubImport';
+import { SingleSkillImport } from './SingleSkillImport';
+import { useGithubSkillImport } from './useGithubSkillImport';
+
+type Source = 'github' | 'url' | 'file';
+
+const SkillImportContent = () => {
+ const { t } = useTranslation('setting');
+ const { setCanDismissByClickOutside } = useModalContext();
+ const [source, setSource] = useState<Source>('github');
+ const github = useGithubSkillImport();
+ const [submitting, setSubmitting] = useState(false);
+ const busy = submitting || github.loading;
+
+ useEffect(() => {
+ setCanDismissByClickOutside(!busy);
+ }, [busy, setCanDismissByClickOutside]);
+
+ return (
+ <Flexbox gap={24}>
+ <div aria-label={t('agentSkillModal.source')} role="group">
+ <Segmented<Source>
+ block
+ disabled={busy}
+ value={source}
+ options={[
+ { icon: <Icon icon={GithubIcon} />, label: 'GitHub', value: 'github' },
+ { icon: <Icon icon={Link} />, label: t('agentSkillModal.link'), value: 'url' },
+ { icon: <Icon icon={FileArchive} />, label: t('agentSkillModal.file'), value: 'file' },
+ ]}
+ onChange={setSource}
+ />
+ </div>
+ {source === 'github' && <GithubImport state={github} />}
+ {(['url', 'file'] as const).map((method) => (
+ <Activity key={method} mode={source === method ? 'visible' : 'hidden'}>
+ <SingleSkillImport
+ canCreate={github.canCreate}
+ loading={submitting}
+ source={method}
+ onLoadingChange={setSubmitting}
+ />
+ </Activity>
+ ))}
+ </Flexbox>
+ );
+};
+
+export const openSkillImportModal = () =>
+ createModal({
+ content: <SkillImportContent />,
+ title: t('agentSkillModal.title', { ns: 'setting' }),
+ width: 'min(560px, calc(100vw - 24px))',
+ });
diff --git a/src/features/SkillStore/SkillList/useGithubSkillImport.test.ts b/src/features/SkillStore/SkillImportModal/useGithubSkillImport.test.ts
similarity index 84%
rename from src/features/SkillStore/SkillList/useGithubSkillImport.test.ts
rename to src/features/SkillStore/SkillImportModal/useGithubSkillImport.test.ts
index 5897b5e12ac..2cc4fe06405 100644
--- a/src/features/SkillStore/SkillList/useGithubSkillImport.test.ts
+++ b/src/features/SkillStore/SkillImportModal/useGithubSkillImport.test.ts
@@ -120,6 +120,22 @@ describe('useGithubSkillImport', () => {
expect(mocks.refresh).toHaveBeenCalledTimes(2);
});
+ it('keeps completed imports when refreshing the library fails and retries only the refresh', async () => {
+ mocks.discoverGitHubSkills.mockResolvedValue({ candidates: [demo], commit, scope: 'scope' });
+ mocks.importGitHubSkills.mockResolvedValue([{ path: demo.path, status: 'created' }]);
+ mocks.refresh.mockRejectedValueOnce(new Error('Offline'));
+
+ const { result } = await scanned();
+ await act(() => result.current.install([demo.path]));
+ expect(result.current.failure).toEqual({ details: 'Offline', stage: 'refresh' });
+ expect(result.current.results).toEqual([{ path: demo.path, status: 'created' }]);
+
+ await act(() => result.current.refreshLibrary());
+ expect(result.current.failure).toBeUndefined();
+ expect(mocks.importGitHubSkills).toHaveBeenCalledTimes(1);
+ expect(mocks.refresh).toHaveBeenCalledTimes(2);
+ });
+
it('drops the scan and the failure when the URL is edited', async () => {
mocks.discoverGitHubSkills.mockResolvedValue({ candidates: [demo], commit, scope: 'scope' });
diff --git a/src/features/SkillStore/SkillList/useGithubSkillImport.ts b/src/features/SkillStore/SkillImportModal/useGithubSkillImport.ts
similarity index 84%
rename from src/features/SkillStore/SkillList/useGithubSkillImport.ts
rename to src/features/SkillStore/SkillImportModal/useGithubSkillImport.ts
index 7a3a1804a44..c10092fcb84 100644
--- a/src/features/SkillStore/SkillList/useGithubSkillImport.ts
+++ b/src/features/SkillStore/SkillImportModal/useGithubSkillImport.ts
@@ -8,7 +8,7 @@ import { useToolStore } from '@/store/tool';
export interface GithubSkillImportFailure {
/** Raw message from the server, folded behind "Show details". */
details: string;
- stage: 'find' | 'import';
+ stage: 'find' | 'import' | 'refresh';
}
const detailsOf = (err: unknown) => (err instanceof Error ? err.message : String(err));
@@ -20,7 +20,8 @@ const detailsOf = (err: unknown) => (err instanceof Error ? err.message : String
export const useGithubSkillImport = () => {
const refresh = useToolStore((s) => s.refreshAgentSkills);
const { allowed: canCreate } = usePermission('create_content');
- const [loading, setLoading] = useState(false);
+ const [pending, setPending] = useState<GithubSkillImportFailure['stage']>();
+ const loading = !!pending;
const [failure, setFailure] = useState<GithubSkillImportFailure>();
const [url, setUrlValue] = useState('');
const [query, setQuery] = useState('');
@@ -40,7 +41,7 @@ export const useGithubSkillImport = () => {
const discover = async () => {
if (!canCreate || !url.trim() || loading) return;
- setLoading(true);
+ setPending('find');
setFailure(undefined);
try {
const next = await agentSkillService.discoverGitHubSkills(url.trim());
@@ -53,13 +54,25 @@ export const useGithubSkillImport = () => {
} catch (err) {
setFailure({ details: detailsOf(err), stage: 'find' });
} finally {
- setLoading(false);
+ setPending(undefined);
+ }
+ };
+
+ const refreshLibrary = async () => {
+ setPending('refresh');
+ setFailure(undefined);
+ try {
+ await refresh();
+ } catch (err) {
+ setFailure({ details: detailsOf(err), stage: 'refresh' });
+ } finally {
+ setPending(undefined);
}
};
const install = async (paths: string[]) => {
if (!canCreate || !scan || !paths.length || loading) return;
- setLoading(true);
+ setPending('import');
setFailure(undefined);
try {
const batch = await agentSkillService.importGitHubSkills({
@@ -72,12 +85,12 @@ export const useGithubSkillImport = () => {
});
setResults((prev) => [...prev.filter((item) => !paths.includes(item.path)), ...batch]);
setQuery('');
- await refresh();
} catch (err) {
setFailure({ details: detailsOf(err), stage: 'import' });
- } finally {
- setLoading(false);
+ setPending(undefined);
+ return;
}
+ await refreshLibrary();
};
return {
@@ -87,7 +100,9 @@ export const useGithubSkillImport = () => {
failure,
install,
loading,
+ pending,
query,
+ refreshLibrary,
results,
scan,
selected,
diff --git a/src/features/SkillStore/SkillList/AddSkillButton.tsx b/src/features/SkillStore/SkillList/AddSkillButton.tsx
index f958d407d9e..db8b6ba217b 100644
--- a/src/features/SkillStore/SkillList/AddSkillButton.tsx
+++ b/src/features/SkillStore/SkillList/AddSkillButton.tsx
@@ -1,24 +1,12 @@
-import { Button, DropdownMenu, Flexbox, Icon, Text } from '@lobehub/ui';
-import { GithubIcon } from '@lobehub/ui/icons';
-import { ChevronDown, FileArchive, Grid2x2Plus, Link, PenLine } from 'lucide-react';
-import { type ReactNode, useState } from 'react';
+import { Button, DropdownMenu, Icon } from '@lobehub/ui';
+import { ChevronDown, Grid2x2Plus, Import, PenLine } from 'lucide-react';
+import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { CustomConnectorModal } from '@/features/Connectors';
import { usePermission } from '@/hooks/usePermission';
-import { openImportFromGithubModal } from './ImportFromGithubModal';
-import { openImportFromUrlModal } from './ImportFromUrlModal';
-import { openUploadSkillModal } from './UploadSkillModal';
-
-const MenuLabel = ({ desc, title }: { desc: string; title: ReactNode }) => (
- <Flexbox gap={2}>
- <span>{title}</span>
- <Text style={{ fontSize: 12 }} type="secondary">
- {desc}
- </Text>
- </Flexbox>
-);
+import { openSkillImportModal } from '../SkillImportModal';
const AddSkillButton = () => {
const { t } = useTranslation('setting');
@@ -27,11 +15,7 @@ const AddSkillButton = () => {
const { allowed: canEdit } = usePermission('edit_own_content');
return (
- <div
- onClick={(e) => {
- e.stopPropagation();
- }}
- >
+ <>
<CustomConnectorModal open={showMcpModal} onClose={() => setMcpModal(false)} />
<DropdownMenu
nativeButton={false}
@@ -39,42 +23,19 @@ const AddSkillButton = () => {
items={[
{
disabled: !canCreate,
- icon: <Icon icon={Link} />,
- key: 'importUrl',
- label: <MenuLabel desc={t('tab.importFromUrl.desc')} title={t('tab.importFromUrl')} />,
- onClick: () => {
- if (!canCreate) return;
- openImportFromUrlModal();
- },
- },
- {
- disabled: !canCreate,
- icon: <Icon icon={GithubIcon} />,
- key: 'importGithub',
- label: (
- <MenuLabel desc={t('tab.importFromGithub.desc')} title={t('tab.importFromGithub')} />
- ),
- onClick: () => {
- if (!canCreate) return;
- openImportFromGithubModal();
- },
- },
- {
- disabled: !canCreate,
- icon: <Icon icon={FileArchive} />,
- key: 'uploadZip',
- label: <MenuLabel desc={t('tab.uploadZip.desc')} title={t('tab.uploadZip')} />,
- onClick: () => {
- if (!canCreate) return;
- openUploadSkillModal();
- },
+ desc: t('agentSkillModal.sources'),
+ icon: <Icon icon={Import} />,
+ key: 'import',
+ label: t('agentSkillModal.title'),
+ onClick: openSkillImportModal,
},
{ type: 'divider' as const },
{
disabled: !canCreate || !canEdit,
icon: <Icon icon={PenLine} />,
key: 'customMcp',
- label: <MenuLabel desc={t('tab.addCustomMcp.desc')} title={t('tab.addCustomMcp')} />,
+ desc: t('tab.addCustomMcp.desc'),
+ label: t('tab.addCustomMcp'),
onClick: () => {
if (!canCreate || !canEdit) return;
setMcpModal(true);
@@ -87,7 +48,7 @@ const AddSkillButton = () => {
<Icon icon={ChevronDown} size={14} />
</Button>
</DropdownMenu>
- </div>
+ </>
);
};
diff --git a/src/features/SkillStore/SkillList/ImportFromGithubModal.tsx b/src/features/SkillStore/SkillList/ImportFromGithubModal.tsx
deleted file mode 100644
index ef3e2c13059..00000000000
--- a/src/features/SkillStore/SkillList/ImportFromGithubModal.tsx
+++ /dev/null
@@ -1,235 +0,0 @@
-'use client';
-
-import type { GitHubSkillCandidate } from '@lobechat/types';
-import {
- Button,
- Checkbox,
- createModal,
- Flexbox,
- Input,
- type ModalInstance,
- Text,
- useModalContext,
-} from '@lobehub/ui';
-import { memo, useEffect } from 'react';
-import { useTranslation } from 'react-i18next';
-
-import AsyncError from '@/components/AsyncError';
-
-import { useGithubSkillImport } from './useGithubSkillImport';
-
-const eligible = (item: GitHubSkillCandidate) => item.status === 'new' || item.status === 'update';
-
-const ImportFromGithubContent = memo(() => {
- const { t } = useTranslation(['setting', 'common']);
- const { close, setCanDismissByClickOutside } = useModalContext();
- const {
- canCreate,
- candidates,
- discover,
- failure,
- install,
- loading,
- query,
- results,
- scan,
- selected,
- setQuery,
- setSelected,
- setUrl,
- url,
- } = useGithubSkillImport();
-
- useEffect(() => {
- setCanDismissByClickOutside(!loading);
- }, [loading, setCanDismissByClickOutside]);
-
- const chosen = candidates.filter((item) => selected.includes(item.path));
- const selectedNames = new Set(chosen.map((item) => item.name.toLowerCase()));
- const visible = candidates.filter(({ name, path, description }) =>
- [name, path, description].some((field) =>
- field.toLowerCase().includes(query.trim().toLowerCase()),
- ),
- );
- const finished = results.length > 0;
- const failed = results.filter((item) => item.status === 'failed').map((item) => item.path);
- const failureCount = results.filter((item) =>
- ['failed', 'conflict', 'forbidden'].includes(item.status),
- ).length;
- const duplicateNames = new Set<string>();
- const allNames = new Set<string>();
- for (const item of candidates.filter(eligible)) {
- const name = item.name.toLowerCase();
- if (allNames.has(name)) duplicateNames.add(name);
- allNames.add(name);
- }
- const bulk = visible.filter(
- (item) => eligible(item) && !duplicateNames.has(item.name.toLowerCase()),
- );
-
- return (
- <Flexbox gap={12}>
- <Text as="h4">{t('agentSkillModal.github.title')}</Text>
- {failure && (
- <AsyncError
- align="start"
- details={failure.details}
- variant="inline"
- title={t(
- failure.stage === 'find'
- ? 'agentSkillModal.github.findFailed'
- : 'agentSkillModal.github.importFailed',
- )}
- />
- )}
- <Input
- aria-label="GitHub URL"
- disabled={loading}
- placeholder={t('agentSkillModal.github.urlPlaceholder')}
- value={url}
- onChange={(event) => setUrl(event.target.value)}
- onPressEnter={discover}
- />
- {!scan && (
- <>
- <Text type="secondary">{t('agentSkillModal.github.collectionHint')}</Text>
- <Button
- disabled={!canCreate || !url.trim()}
- loading={loading}
- type="primary"
- onClick={discover}
- >
- {t('agentSkillModal.github.find')}
- </Button>
- </>
- )}
- {scan && (
- <>
- {finished && (
- <Text role="status">
- {t('agentSkillModal.github.summary', {
- success: results.length - failureCount,
- failed: failureCount,
- })}
- </Text>
- )}
- {!finished && candidates.length > 1 && (
- <>
- <Input
- aria-label={t('agentSkillModal.github.search')}
- placeholder={t('agentSkillModal.github.search')}
- value={query}
- onChange={(e) => setQuery(e.target.value)}
- />
- <Flexbox horizontal gap={8}>
- <Button
- disabled={loading || !bulk.length}
- size="small"
- onClick={() =>
- setSelected([...new Set([...selected, ...bulk.map((item) => item.path)])])
- }
- >
- {t('agentSkillModal.github.select')}
- </Button>
- <Button
- disabled={loading || !selected.length}
- size="small"
- onClick={() => setSelected([])}
- >
- {t('agentSkillModal.github.clear')}
- </Button>
- </Flexbox>
- </>
- )}
- <Flexbox gap={12} style={{ maxHeight: '45vh', overflowY: 'auto' }}>
- {!visible.length && (
- <Text>
- {t(
- candidates.length
- ? 'agentSkillModal.github.noMatch'
- : 'agentSkillModal.github.empty',
- )}
- </Text>
- )}
- {visible.map((item) => {
- const result = results.find((row) => row.path === item.path);
- if (finished && !result) return null;
- const checked = selected.includes(item.path);
- const duplicate = duplicateNames.has(item.name.toLowerCase());
- return (
- <Flexbox gap={2} key={item.path}>
- <Flexbox horizontal align="center" gap={8}>
- {!finished && (
- <Checkbox
- aria-label={item.name + ' ' + (item.path || '/')}
- checked={checked}
- disabled={
- loading ||
- !eligible(item) ||
- (!checked && selectedNames.has(item.name.toLowerCase()))
- }
- onChange={() =>
- setSelected(
- checked
- ? selected.filter((path) => path !== item.path)
- : [...selected, item.path],
- )
- }
- />
- )}
- <Text strong>{item.name}</Text>
- <Text type="secondary">
- {t(`agentSkillModal.github.status.${result?.status ?? item.status}`)}
- </Text>
- </Flexbox>
- <Text type="secondary">{item.path || '/'}</Text>
- {item.description && <Text>{item.description}</Text>}
- {duplicate && !finished && (
- <Text type="secondary">{t('agentSkillModal.github.sameName')}</Text>
- )}
- </Flexbox>
- );
- })}
- </Flexbox>
- {finished ? (
- <Flexbox horizontal gap={8}>
- <Button disabled={loading} onClick={discover}>
- {t('agentSkillModal.github.find')}
- </Button>
- {failed.length > 0 && (
- <Button loading={loading} onClick={() => install(failed)}>
- {t('agentSkillModal.github.retry')}
- </Button>
- )}
- <Button disabled={loading} onClick={close}>
- {t('common:close')}
- </Button>
- </Flexbox>
- ) : (
- <Button
- disabled={!canCreate || !chosen.length}
- loading={loading}
- type="primary"
- onClick={() => install(selected)}
- >
- {t('agentSkillModal.github.install', {
- count: chosen.length,
- updates: chosen.filter((item) => item.status === 'update').length,
- })}
- </Button>
- )}
- </>
- )}
- </Flexbox>
- );
-});
-
-ImportFromGithubContent.displayName = 'ImportFromGithubContent';
-
-export const openImportFromGithubModal = (): ModalInstance =>
- createModal({
- content: <ImportFromGithubContent />,
- footer: null,
- maskClosable: true,
- width: 520,
- });
diff --git a/src/features/SkillStore/SkillList/ImportFromUrlModal.tsx b/src/features/SkillStore/SkillList/ImportFromUrlModal.tsx
deleted file mode 100644
index ff316708b71..00000000000
--- a/src/features/SkillStore/SkillList/ImportFromUrlModal.tsx
+++ /dev/null
@@ -1,106 +0,0 @@
-'use client';
-
-import {
- Alert,
- Button,
- createModal,
- Flexbox,
- Icon,
- Input,
- type ModalInstance,
- Text,
- toast,
- useModalContext,
-} from '@lobehub/ui';
-import { ArrowLeftRight, Link, Sparkles } from 'lucide-react';
-import { memo, useEffect, useState } from 'react';
-import { useTranslation } from 'react-i18next';
-
-import { usePermission } from '@/hooks/usePermission';
-import { useToolStore } from '@/store/tool';
-
-const ImportFromUrlContent = memo(() => {
- const { t } = useTranslation(['setting', 'common']);
- const { close, setCanDismissByClickOutside } = useModalContext();
-
- const importAgentSkillFromUrl = useToolStore((s) => s.importAgentSkillFromUrl);
- const [loading, setLoading] = useState(false);
- const [error, setError] = useState<string | null>(null);
- const [url, setUrl] = useState('');
- const { allowed: canCreate } = usePermission('create_content');
-
- useEffect(() => {
- setCanDismissByClickOutside(!loading);
- }, [loading, setCanDismissByClickOutside]);
-
- const handleImport = async () => {
- const trimmed = url.trim();
- if (!canCreate || !trimmed) return;
-
- setLoading(true);
- setError(null);
-
- try {
- await importAgentSkillFromUrl({ url: trimmed });
- toast.success(t('agentSkillModal.importSuccess'));
- close();
- } catch (err: any) {
- setError(err?.message || String(err));
- } finally {
- setLoading(false);
- }
- };
-
- return (
- <Flexbox gap={16}>
- <Flexbox align="center" gap={16} padding={'16px 0'}>
- <Flexbox horizontal align="center" gap={8}>
- <Icon icon={Link} size={28} />
- <Icon
- icon={ArrowLeftRight}
- size={16}
- style={{ color: 'var(--lobe-color-text-tertiary)' }}
- />
- <Icon icon={Sparkles} size={28} />
- </Flexbox>
-
- <Flexbox align="center" gap={4}>
- <Text as={'h4'} style={{ margin: 0 }}>
- {t('agentSkillModal.url.title')}
- </Text>
- <Text type={'secondary'}>{t('agentSkillModal.url.desc')}</Text>
- </Flexbox>
- </Flexbox>
-
- {error && <Alert showIcon title={t('agentSkillModal.importError', { error })} type="error" />}
-
- <Flexbox gap={8}>
- <Text strong>URL</Text>
- <Input
- disabled={!canCreate}
- placeholder={t('agentSkillModal.url.urlPlaceholder')}
- value={url}
- onPressEnter={handleImport}
- onChange={(e) => {
- setUrl(e.target.value);
- if (error) setError(null);
- }}
- />
- </Flexbox>
-
- <Button block disabled={!canCreate} loading={loading} type="primary" onClick={handleImport}>
- {t('common:import')}
- </Button>
- </Flexbox>
- );
-});
-
-ImportFromUrlContent.displayName = 'ImportFromUrlContent';
-
-export const openImportFromUrlModal = (): ModalInstance =>
- createModal({
- content: <ImportFromUrlContent />,
- footer: null,
- maskClosable: true,
- width: 480,
- });
diff --git a/src/features/SkillStore/SkillList/UploadSkillModal.tsx b/src/features/SkillStore/SkillList/UploadSkillModal.tsx
deleted file mode 100644
index 51ce30a902b..00000000000
--- a/src/features/SkillStore/SkillList/UploadSkillModal.tsx
+++ /dev/null
@@ -1,148 +0,0 @@
-'use client';
-
-import {
- Alert,
- createModal,
- Flexbox,
- Icon,
- type ModalInstance,
- Spin,
- Text,
- toast,
- Upload,
- useModalContext,
-} from '@lobehub/ui';
-import { sha256 } from 'js-sha256';
-import { ArrowLeftRight, InboxIcon, Sparkles, Upload as UploadIcon } from 'lucide-react';
-import { memo, useEffect, useState } from 'react';
-import { useTranslation } from 'react-i18next';
-
-import { usePermission } from '@/hooks/usePermission';
-import { lambdaClient } from '@/libs/trpc/client/lambda';
-import { uploadService } from '@/services/upload';
-import { useToolStore } from '@/store/tool';
-
-const UploadSkillContent = memo(() => {
- const { t } = useTranslation(['setting', 'common']);
- const { close, setCanDismissByClickOutside } = useModalContext();
-
- const importAgentSkillFromZip = useToolStore((s) => s.importAgentSkillFromZip);
- const [loading, setLoading] = useState(false);
- const [error, setError] = useState<string | null>(null);
- const { allowed: canCreate } = usePermission('create_content');
-
- useEffect(() => {
- setCanDismissByClickOutside(!loading);
- }, [loading, setCanDismissByClickOutside]);
-
- const handleUploadFile = async (file: File) => {
- if (!canCreate) return;
- setLoading(true);
- setError(null);
- let uploadedPathname: string | undefined;
-
- try {
- const { data: metadata } = await uploadService.uploadFileToS3(file, {
- directory: 'skills',
- });
- uploadedPathname = metadata.path;
-
- const hash = sha256(await file.arrayBuffer());
-
- const result = await lambdaClient.file.createFile.mutate({
- fileType: file.type || 'application/zip',
- hash,
- metadata: {},
- name: file.name,
- size: file.size,
- url: metadata.path,
- });
- uploadedPathname = undefined;
-
- await importAgentSkillFromZip({ zipFileId: result.id });
- toast.success(t('agentSkillModal.importSuccess'));
- close();
- } catch (err: any) {
- if (uploadedPathname) await uploadService.releaseUpload(uploadedPathname);
- setError(err?.message || String(err));
- } finally {
- setLoading(false);
- }
- };
-
- return (
- <Flexbox gap={16}>
- <Flexbox align="center" gap={16} padding={'16px 0'}>
- <Flexbox horizontal align="center" gap={8}>
- <Icon icon={UploadIcon} size={28} />
- <Icon
- icon={ArrowLeftRight}
- size={16}
- style={{ color: 'var(--lobe-color-text-tertiary)' }}
- />
- <Icon icon={Sparkles} size={28} />
- </Flexbox>
-
- <Flexbox align="center" gap={4}>
- <Text as={'h4'} style={{ margin: 0 }}>
- {t('agentSkillModal.upload.title')}
- </Text>
- <Text type={'secondary'}>{t('agentSkillModal.upload.desc')}</Text>
- </Flexbox>
- </Flexbox>
-
- {error && <Alert showIcon title={t('agentSkillModal.importError', { error })} type="error" />}
-
- <Upload
- dragger
- accept=".zip,.skill"
- disabled={loading || !canCreate}
- onFiles={([file]) => void handleUploadFile(file)}
- >
- <Flexbox align="center" gap={8} padding={24}>
- {loading ? (
- <>
- <Spin />
- <Text type={'secondary'}>{t('agentSkillModal.upload.uploading')}</Text>
- </>
- ) : (
- <>
- <Icon
- icon={InboxIcon}
- size={48}
- style={{ color: 'var(--lobe-color-text-quaternary)' }}
- />
- <Text type={'secondary'}>{t('agentSkillModal.upload.dragText')}</Text>
- </>
- )}
- </Flexbox>
- </Upload>
-
- <Flexbox gap={8}>
- <Text strong>{t('agentSkillModal.upload.requirements')}</Text>
- <ul style={{ margin: 0, paddingLeft: 20 }}>
- <li>
- <Text as={'span'} type={'secondary'}>
- {t('agentSkillModal.upload.requirementZip')}
- </Text>
- </li>
- <li>
- <Text as={'span'} type={'secondary'}>
- {t('agentSkillModal.upload.requirementSkillMd')}
- </Text>
- </li>
- </ul>
- </Flexbox>
- </Flexbox>
- );
-});
-
-UploadSkillContent.displayName = 'UploadSkillContent';
-
-export const openUploadSkillModal = (): ModalInstance =>
- createModal({
- content: <UploadSkillContent />,
- footer: null,
- maskClosable: true,
- width: 480,
- });