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.

🐛 fix: skill import url and github address problem (#13261)

Rdmclin22c657670fe26
diff --git a/locales/en-US/setting.json b/locales/en-US/setting.json
index 39cbcb39ced..6a7cd572327 100644
--- a/locales/en-US/setting.json
+++ b/locales/en-US/setting.json
@@ -164,9 +164,9 @@
"agentSkillModal.contentPlaceholder": "Enter skill content in Markdown format...",
"agentSkillModal.description": "Description",
"agentSkillModal.descriptionPlaceholder": "Briefly describe this skill",
- "agentSkillModal.github.desc": "Import skills directly from a public GitHub repository.",
+ "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.title": "Import from GitHub",
- "agentSkillModal.github.urlPlaceholder": "https://github.com/username/repo",
+ "agentSkillModal.github.urlPlaceholder": "https://github.com/username/repo/tree/main/skills/my-skill",
"agentSkillModal.importError": "Import failed: {{error}}",
"agentSkillModal.importSuccess": "Agent Skill imported successfully",
"agentSkillModal.upload.desc": "Upload a local .zip or .skill file to install.",
diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.json
index f9e7e0df269..162ade7a81d 100644
--- a/locales/zh-CN/setting.json
+++ b/locales/zh-CN/setting.json
@@ -164,9 +164,9 @@
"agentSkillModal.contentPlaceholder": "输入 Markdown 格式的技能内容...",
"agentSkillModal.description": "描述",
"agentSkillModal.descriptionPlaceholder": "简要描述该技能",
- "agentSkillModal.github.desc": "直接从公开的 GitHub 仓库中导入技能。",
+ "agentSkillModal.github.desc": "粘贴公开 GitHub 仓库中技能目录的 URL,该目录下需包含 SKILL.md 文件。",
"agentSkillModal.github.title": "从 GitHub 导入",
- "agentSkillModal.github.urlPlaceholder": "https://github.com/username/repo",
+ "agentSkillModal.github.urlPlaceholder": "https://github.com/username/repo/tree/main/skills/my-skill",
"agentSkillModal.importError": "导入失败:{{error}}",
"agentSkillModal.importSuccess": "Agent 技能导入成功",
"agentSkillModal.upload.desc": "上传本地 .zip 或 .skill 文件以安装技能。",
diff --git a/packages/database/src/models/file.ts b/packages/database/src/models/file.ts
index 55559b42833..6eb37046c97 100644
--- a/packages/database/src/models/file.ts
+++ b/packages/database/src/models/file.ts
@@ -90,6 +90,13 @@ export class FileModel {
return this.db.insert(globalFiles).values(file).returning();
};
+ updateGlobalFile = async (
+ hashId: string,
+ data: Partial<Pick<NewGlobalFile, 'metadata' | 'url'>>,
+ ) => {
+ return this.db.update(globalFiles).set(data).where(eq(globalFiles.hashId, hashId));
+ };
+
checkHash = async (hash: string) => {
const item = await this.db.query.globalFiles.findFirst({
where: eq(globalFiles.hashId, hash),
diff --git a/src/features/AgentSkillDetail/ContentViewer.tsx b/src/features/AgentSkillDetail/ContentViewer.tsx
index 32efb791cf6..aaa83025c88 100644
--- a/src/features/AgentSkillDetail/ContentViewer.tsx
+++ b/src/features/AgentSkillDetail/ContentViewer.tsx
@@ -157,7 +157,8 @@ const isMarkdownFile = (path: string) => {
return ext === 'md' || ext === 'mdx';
};
-const parseFrontmatter = (content: string): { body: string; frontmatter?: string } => {
+const parseFrontmatter = (content?: string): { body: string; frontmatter?: string } => {
+ if (!content) return { body: '' };
const match = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
if (!match) return { body: content };
return { body: match[2], frontmatter: match[1] };
diff --git a/src/features/SkillStore/SkillList/ImportFromGithubModal.tsx b/src/features/SkillStore/SkillList/ImportFromGithubModal.tsx
index 8d71bfcd259..688092a522b 100644
--- a/src/features/SkillStore/SkillList/ImportFromGithubModal.tsx
+++ b/src/features/SkillStore/SkillList/ImportFromGithubModal.tsx
@@ -62,7 +62,9 @@ const ImportFromGithubModal = memo<ImportFromGithubModalProps>(({ open, onOpenCh
<Typography.Title level={4} style={{ margin: 0 }}>
{t('agentSkillModal.github.title')}
</Typography.Title>
- <Typography.Text type="secondary">{t('agentSkillModal.github.desc')}</Typography.Text>
+ <Typography.Text style={{ textAlign: 'center' }} type="secondary">
+ {t('agentSkillModal.github.desc')}
+ </Typography.Text>
</Flexbox>
</Flexbox>
diff --git a/src/locales/default/setting.ts b/src/locales/default/setting.ts
index 153bbdb6833..5448bd9579b 100644
--- a/src/locales/default/setting.ts
+++ b/src/locales/default/setting.ts
@@ -158,9 +158,11 @@ export default {
'agentSkillModal.contentPlaceholder': 'Enter skill content in Markdown format...',
'agentSkillModal.description': 'Description',
'agentSkillModal.descriptionPlaceholder': 'Briefly describe this skill',
- 'agentSkillModal.github.desc': 'Import skills directly from a public GitHub repository.',
+ '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.title': 'Import from GitHub',
- 'agentSkillModal.github.urlPlaceholder': 'https://github.com/username/repo',
+ 'agentSkillModal.github.urlPlaceholder':
+ 'https://github.com/username/repo/tree/main/skills/my-skill',
'agentSkillModal.importError': 'Import failed: {{error}}',
'agentSkillModal.importSuccess': 'Agent Skill imported successfully',
'agentSkillModal.upload.desc': 'Upload a local .zip or .skill file to install.',
diff --git a/src/server/modules/GitHub/index.test.ts b/src/server/modules/GitHub/index.test.ts
index 8ff5481ca2d..ff6822cbb6e 100644
--- a/src/server/modules/GitHub/index.test.ts
+++ b/src/server/modules/GitHub/index.test.ts
@@ -79,6 +79,40 @@ describe('GitHub', () => {
expect(result.path).toBeUndefined();
});
+ it('should parse /blob/ URL and strip file name to get directory path', () => {
+ const result = gh.parseRepoUrl(
+ 'https://github.com/kepano/obsidian-skills/blob/main/skills/json-canvas/SKILL.md',
+ );
+ expect(result).toEqual({
+ branch: 'main',
+ owner: 'kepano',
+ path: 'skills/json-canvas',
+ repo: 'obsidian-skills',
+ });
+ });
+
+ it('should parse /blob/ URL pointing to a file at repo root (no subdirectory)', () => {
+ const result = gh.parseRepoUrl('https://github.com/owner/repo/blob/main/SKILL.md');
+ expect(result).toEqual({
+ branch: 'main',
+ owner: 'owner',
+ repo: 'repo',
+ });
+ expect(result.path).toBeUndefined();
+ });
+
+ it('should parse /blob/ URL with nested path', () => {
+ const result = gh.parseRepoUrl(
+ 'https://github.com/anthropics/skills/blob/main/skills/pptx/SKILL.md',
+ );
+ expect(result).toEqual({
+ branch: 'main',
+ owner: 'anthropics',
+ path: 'skills/pptx',
+ repo: 'skills',
+ });
+ });
+
it('should parse GitHub URL without protocol', () => {
const result = gh.parseRepoUrl('github.com/lobehub/lobe-chat');
expect(result).toEqual({
diff --git a/src/server/modules/GitHub/index.ts b/src/server/modules/GitHub/index.ts
index 582ca8d2b79..0c76c9d5c54 100644
--- a/src/server/modules/GitHub/index.ts
+++ b/src/server/modules/GitHub/index.ts
@@ -30,9 +30,13 @@ export class GitHub {
* - https://github.com/owner/repo
* - https://github.com/owner/repo/tree/branch
* - https://github.com/owner/repo/tree/branch/path/to/dir
+ * - https://github.com/owner/repo/blob/branch/path/to/file.md
* - github.com/owner/repo
* - owner/repo (shorthand)
* - https://github.com/owner/repo.git
+ *
+ * When a /blob/ URL pointing to a file is provided, the file name is stripped
+ * and the parent directory is used as the path.
*/
parseRepoUrl(url: string, defaultBranch = 'main'): GitHubRepoInfo {
log('parseRepoUrl: input url=%s, defaultBranch=%s', url, defaultBranch);
@@ -46,9 +50,9 @@ export class GitHub {
}
// Handle full URL formats
- // Capture: owner, repo, branch, and optional path after branch
+ // Capture: owner, repo, type (tree/blob), branch, and optional path after branch
const match = url.match(
- /(?:https?:\/\/)?github\.com\/([^/]+)\/([^/]+)(?:\/tree\/([^/]+)(?:\/(.+))?)?$/,
+ /^(?:https?:\/\/)?github\.com\/([^/]+)\/([^/]+)(?:\/(tree|blob)\/([^/]+)(?:\/(.+))?)?$/,
);
if (!match) {
@@ -56,16 +60,29 @@ export class GitHub {
throw new GitHubParseError(`Invalid GitHub URL format: ${url}`);
}
- const [, owner, repo, branch, path] = match;
+ const [, owner, repo, urlType, branch, rawPath] = match;
const result: GitHubRepoInfo = {
branch: branch || defaultBranch,
owner,
repo: repo.replace(/\.git$/, ''),
};
- // Add path if it exists (subdirectory within the repo)
- if (path) {
- result.path = path;
+ // Process path: for /blob/ URLs pointing to a file, strip the file name to get the directory
+ if (rawPath) {
+ let path = rawPath;
+ if (urlType === 'blob') {
+ // Strip trailing file name (e.g. "skills/json-canvas/SKILL.md" -> "skills/json-canvas")
+ const lastSlash = path.lastIndexOf('/');
+ if (lastSlash > 0) {
+ path = path.slice(0, lastSlash);
+ } else {
+ // The path is just a file at the repo root, no subdirectory
+ path = '';
+ }
+ }
+ if (path) {
+ result.path = path;
+ }
}
log('parseRepoUrl: matched full URL format, result=%o', result);
diff --git a/src/server/services/file/__tests__/index.test.ts b/src/server/services/file/__tests__/index.test.ts
index a3d36c4481e..98c638d9c61 100644
--- a/src/server/services/file/__tests__/index.test.ts
+++ b/src/server/services/file/__tests__/index.test.ts
@@ -53,6 +53,7 @@ describe('FileService', () => {
mockFileModel = {
findById: vi.fn(),
delete: vi.fn(),
+ updateGlobalFile: vi.fn(),
};
mockTempManager = {
writeTempFile: vi.fn(),
@@ -375,8 +376,8 @@ describe('FileService', () => {
});
});
- it('should not create global file when hash already exists', async () => {
- mockFileModel.checkHash.mockResolvedValue({ isExist: true });
+ it('should not create global file when hash already exists with same url', async () => {
+ mockFileModel.checkHash.mockResolvedValue({ isExist: true, url: 'some/path.txt' });
const result = await service.createGlobalFile({
fileHash: 'existing-hash',
@@ -387,6 +388,26 @@ describe('FileService', () => {
expect(result).toEqual({ fileHash: 'existing-hash' });
expect(mockFileModel.createGlobalFile).not.toHaveBeenCalled();
+ expect(mockFileModel.updateGlobalFile).not.toHaveBeenCalled();
+ });
+
+ it('should update url when hash exists but url changed', async () => {
+ mockFileModel.checkHash.mockResolvedValue({ isExist: true, url: 'old/path.txt' });
+
+ const result = await service.createGlobalFile({
+ fileHash: 'existing-hash',
+ fileType: 'text/plain',
+ metadata: { dirname: 'new', filename: 'path.txt', path: 'new/path.txt' },
+ size: 100,
+ url: 'new/path.txt',
+ });
+
+ expect(result).toEqual({ fileHash: 'existing-hash' });
+ expect(mockFileModel.createGlobalFile).not.toHaveBeenCalled();
+ expect(mockFileModel.updateGlobalFile).toHaveBeenCalledWith('existing-hash', {
+ metadata: { dirname: 'new', filename: 'path.txt', path: 'new/path.txt' },
+ url: 'new/path.txt',
+ });
});
it('should work without metadata', async () => {
diff --git a/src/server/services/file/index.ts b/src/server/services/file/index.ts
index 36d3bd8bb03..86d2b7b3a11 100644
--- a/src/server/services/file/index.ts
+++ b/src/server/services/file/index.ts
@@ -184,10 +184,10 @@ export class FileService {
url: string;
}): Promise<{ fileHash: string }> {
// Check if hash already exists
- const { isExist } = await this.fileModel.checkHash(params.fileHash);
+ const existing = await this.fileModel.checkHash(params.fileHash);
- // Only create if not exists
- if (!isExist) {
+ if (!existing.isExist) {
+ // Create new record
await this.fileModel.createGlobalFile({
creator: this.userId,
fileType: params.fileType,
@@ -196,6 +196,12 @@ export class FileService {
size: params.size,
url: params.url,
});
+ } else if (existing.url !== params.url) {
+ // Hash exists but URL changed (file re-uploaded to different S3 path) — update URL
+ await this.fileModel.updateGlobalFile(params.fileHash, {
+ metadata: params.metadata,
+ url: params.url,
+ });
}
return { fileHash: params.fileHash };
diff --git a/src/server/services/skill/importer.ts b/src/server/services/skill/importer.ts
index 8e001ca436a..067645a8770 100644
--- a/src/server/services/skill/importer.ts
+++ b/src/server/services/skill/importer.ts
@@ -193,8 +193,9 @@ export class SkillImporter {
log('importFromGitHub: identifier=%s', identifier);
// 5. Check for existing skill with same zipHash (deduplication)
+ // Also re-import if content is missing (e.g. from a previous buggy import)
const existing = await this.skillModel.findByIdentifier(identifier);
- if (existing && existing.zipFileHash === zipHash) {
+ if (existing && existing.zipFileHash === zipHash && existing.content != null) {
log(
'importFromGitHub: skill unchanged (same zipHash=%s), skipping update id=%s',
zipHash,
@@ -294,6 +295,18 @@ export class SkillImporter {
throw new SkillImportError('Invalid URL format', 'INVALID_URL');
}
+ // 1.5. Detect GitHub repo/tree/blob URLs and delegate to importFromGitHub for full directory support
+ // Only delegate URLs that parseRepoUrl can handle (owner/repo, tree, blob patterns).
+ // Let direct download URLs (e.g. /archive/*.zip, /releases/download/*) fall through
+ // to the generic fetch logic below which handles ZIP files correctly.
+ if (
+ url.hostname === 'github.com' &&
+ /^\/[^/]+\/[^/]+(?:\/(?:tree|blob)\/.+)?$/.test(url.pathname.replace(/\/+$/, ''))
+ ) {
+ log('importFromUrl: detected GitHub repo URL, delegating to importFromGitHub');
+ return this.importFromGitHub({ gitUrl: input.url });
+ }
+
// 2. Fetch content (auto-detect SKILL.md or ZIP)
let manifest: SkillManifest;
let skillContent: string;