feat: add skill installer (#279)

* feat: add skill installer with install/uninstall and settings UI

* feat: refactor skill installer with extracted SkillLibraryList component

* feat: simplify SkillsEditor, extract SkillLibraryList

* feat: refactor skill installer components and add github utility
This commit is contained in:
Chris Scott authored and GitHub committed 2026-06-17 23:11:29 -04:00
1 parent 24d34f28a3
commit 6e80cdfb8c
24 files changed
+2381 -577

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { FetchError } from '@opencode-manager/shared'
import { settingsApi } from './settings'
describe('settingsApi', () => {
const fetchMock = vi.fn()
beforeEach(() => {
fetchMock.mockReset()
vi.stubGlobal('fetch', fetchMock)
})
afterEach(() => {
vi.unstubAllGlobals()
})
describe('installSkillFromGithub', () => {
it('posts JSON to skills install endpoint', async () => {
fetchMock.mockResolvedValue(
new Response(JSON.stringify({ skill: { name: 'teach' }, overwritten: false, sourceType: 'github', filesInstalled: ['SKILL.md'] }), { status: 200 }),
)
const result = await settingsApi.installSkillFromGithub({
sourceType: 'github',
url: 'https://github.com/user/repo/tree/main/teach',
scope: 'global',
})
expect(result.skill.name).toBe('teach')
const callUrl = fetchMock.mock.calls[0][0]
expect(callUrl).toEqual(expect.stringContaining('/api/settings/skills/install'))
const callOptions = fetchMock.mock.calls[0][1]
expect(callOptions.method).toBe('POST')
expect(callOptions.headers['Content-Type']).toBe('application/json')
const body = JSON.parse(callOptions.body)
expect(body.sourceType).toBe('github')
})
it('surfaces 409 conflict as FetchError', async () => {
fetchMock.mockResolvedValue(
new Response(JSON.stringify({ error: 'Skill "teach" already exists in global scope' }), { status: 409 }),
)
await expect(
settingsApi.installSkillFromGithub({
sourceType: 'github',
url: 'https://github.com/user/repo/tree/main/teach',
scope: 'global',
}),
).rejects.toThrow(FetchError)
await expect(
settingsApi.installSkillFromGithub({
sourceType: 'github',
url: 'https://github.com/user/repo/tree/main/teach',
scope: 'global',
}),
).rejects.toMatchObject({ statusCode: 409 })
})
})
describe('installSkillFromUpload', () => {
it('posts FormData manifest and files', async () => {
fetchMock.mockResolvedValue(
new Response(JSON.stringify({ skill: { name: 'teach' }, overwritten: false, sourceType: 'upload', filesInstalled: ['teach/SKILL.md'] }), { status: 200 }),
)
const file = new File(['# Teach Skill'], 'SKILL.md', { type: 'text/markdown' })
Object.defineProperty(file, 'webkitRelativePath', { value: 'teach/SKILL.md' })
const result = await settingsApi.installSkillFromUpload({ files: [file], scope: 'global' })
expect(result.sourceType).toBe('upload')
const callUrl = fetchMock.mock.calls[0][0]
expect(callUrl).toEqual(expect.stringContaining('/api/settings/skills/install'))
const callOptions = fetchMock.mock.calls[0][1]
expect(callOptions.method).toBe('POST')
expect(callOptions.headers?.hasOwnProperty).toBeFalsy()
const formData = callOptions.body as FormData
expect(formData.get('sourceType')).toBe('upload')
expect(formData.get('file0')).toBe(file)
const manifest = JSON.parse(formData.get('fileManifest') as string)
expect(manifest).toHaveLength(1)
expect(manifest[0].fieldName).toBe('file0')
expect(manifest[0].relativePath).toBe('teach/SKILL.md')
})
})
})
+39
View File
@@ -11,6 +11,8 @@ import type {
CreateSkillRequest,
UpdateSkillRequest,
SkillScope,
InstallSkillFromGithubRequest,
InstallSkillResponse,
} from './types/settings'
import { API_BASE_URL } from '@/config'
import { fetchWrapper, FetchError } from './fetchWrapper'
@@ -268,6 +270,43 @@ export const settingsApi = {
method: 'DELETE',
})
},
installSkillFromGithub: async (data: InstallSkillFromGithubRequest): Promise<InstallSkillResponse> => {
return fetchWrapper(`${API_BASE_URL}/api/settings/skills/install`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
},
installSkillFromUpload: async (data: {
files: File[]
scope: SkillScope
repoId?: number
overwrite?: boolean
}): Promise<InstallSkillResponse> => {
const formData = new FormData()
formData.append('sourceType', 'upload')
formData.append('scope', data.scope)
if (data.repoId !== undefined) formData.append('repoId', String(data.repoId))
if (data.overwrite !== undefined) formData.append('overwrite', String(data.overwrite))
const fileManifest: Array<{ fieldName: string; relativePath: string }> = []
data.files.forEach((file, index) => {
const fieldName = `file${index}`
const relativePath = file.webkitRelativePath || file.name
fileManifest.push({ fieldName, relativePath })
formData.append(fieldName, file)
})
formData.append('fileManifest', JSON.stringify(fileManifest))
return fetchWrapper(`${API_BASE_URL}/api/settings/skills/install`, {
method: 'POST',
body: formData,
})
},
}
export interface VersionInfo {
+3 -1
View File
@@ -15,10 +15,12 @@ import {
type CreateSkillRequest,
type UpdateSkillRequest,
type SkillScope,
type InstallSkillFromGithubRequest,
type InstallSkillResponse,
} from '@opencode-manager/shared'
import type { NotificationPreferences } from '@opencode-manager/shared/types'
export type { TTSConfig, STTConfig, OpenCodeConfigContent, ModelConfig, ProviderConfig, NotificationPreferences, SkillFileInfo, CreateSkillRequest, UpdateSkillRequest, SkillScope }
export type { TTSConfig, STTConfig, OpenCodeConfigContent, ModelConfig, ProviderConfig, NotificationPreferences, SkillFileInfo, CreateSkillRequest, UpdateSkillRequest, SkillScope, InstallSkillFromGithubRequest, InstallSkillResponse }
export { DEFAULT_TTS_CONFIG, DEFAULT_STT_CONFIG, DEFAULT_KEYBOARD_SHORTCUTS, DEFAULT_USER_PREFERENCES, DEFAULT_LEADER_KEY, BLOCKED_SERVER_ENV_KEYS, DEFAULT_SERVER_ENV_VARS }
export interface CustomCommand {