Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions src/__tests__/api-clients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,132 @@ describe('Auxiliary API clients', () => {
);
});

it('SkillsClient CRUD methods map to the correct endpoints', async () => {
const installedSkill = {
name: 'my-skill',
version: '1.0.0',
description: 'A test skill',
enabled: true,
source: '/tmp/my-skill',
installed_at: '2026-05-12T12:00:00Z',
install_path: '/home/.openhands/skills/installed/my-skill',
};
const installedList = { skills: [{ name: 'my-skill', version: '1.0.0', enabled: true }] };
const toggleResponse = { name: 'my-skill', enabled: false };
const uninstallResponse = { message: "Skill 'my-skill' uninstalled" };
const refreshResponse = {
message: "Skill 'my-skill' updated",
skill: { name: 'my-skill', version: '1.0.0', enabled: true },
};
const marketplaceResponse = {
skills: [
{ name: 'my-skill', description: 'desc', source: 'github:org/repo', installed: false },
],
};

const responses = [
installedSkill,
installedList,
installedSkill,
toggleResponse,
uninstallResponse,
refreshResponse,
marketplaceResponse,
];
global.fetch = jest.fn().mockImplementation(() => {
const body = responses.shift();
return Promise.resolve(
new Response(JSON.stringify(body), {
status: 200,
headers: { 'content-type': 'application/json' },
})
);
}) as typeof fetch;

const client = new SkillsClient({ host: 'http://example.com' });

const installed = await client.installSkill({ source: '/tmp/my-skill', force: false });
expect(installed.name).toBe('my-skill');
expect(installed.enabled).toBe(true);

const list = await client.listInstalledSkills();
expect(list.skills).toHaveLength(1);
expect(list.skills[0].name).toBe('my-skill');

const got = await client.getInstalledSkill('my-skill');
expect(got.name).toBe('my-skill');

const toggled = await client.toggleSkill('my-skill', false);
expect(toggled.enabled).toBe(false);

const uninstalled = await client.uninstallSkill('my-skill');
expect(uninstalled.message).toContain('uninstalled');

const refreshed = await client.refreshSkill('my-skill');
expect(refreshed.message).toContain('updated');
expect(refreshed.skill.name).toBe('my-skill');

const marketplace = await client.getMarketplace();
expect(marketplace.skills).toHaveLength(1);
expect(marketplace.skills[0].installed).toBe(false);

expect(global.fetch).toHaveBeenNthCalledWith(
1,
'http://example.com/api/skills/install',
expect.objectContaining({
method: 'POST',
body: JSON.stringify({ source: '/tmp/my-skill', force: false }),
})
);
expect(global.fetch).toHaveBeenNthCalledWith(
2,
'http://example.com/api/skills/installed',
expect.objectContaining({ method: 'GET' })
);
expect(global.fetch).toHaveBeenNthCalledWith(
3,
'http://example.com/api/skills/installed/my-skill',
expect.objectContaining({ method: 'GET' })
);
expect(global.fetch).toHaveBeenNthCalledWith(
4,
'http://example.com/api/skills/installed/my-skill',
expect.objectContaining({ method: 'PATCH', body: JSON.stringify({ enabled: false }) })
);
expect(global.fetch).toHaveBeenNthCalledWith(
5,
'http://example.com/api/skills/installed/my-skill',
expect.objectContaining({ method: 'DELETE' })
);
expect(global.fetch).toHaveBeenNthCalledWith(
6,
'http://example.com/api/skills/installed/my-skill/update',
expect.objectContaining({ method: 'POST' })
);
expect(global.fetch).toHaveBeenNthCalledWith(
7,
'http://example.com/api/skills/marketplace',
expect.objectContaining({ method: 'GET' })
);
});

it('SkillsClient percent-encodes skill names with special characters', async () => {
global.fetch = jest.fn().mockResolvedValue(
new Response(JSON.stringify({ name: 'my skill', enabled: true }), {
status: 200,
headers: { 'content-type': 'application/json' },
})
) as typeof fetch;

const client = new SkillsClient({ host: 'http://example.com' });
await client.getInstalledSkill('my skill');

expect(global.fetch).toHaveBeenCalledWith(
'http://example.com/api/skills/installed/my%20skill',
expect.objectContaining({ method: 'GET' })
);
});

it('BashClient.startCommand normalizes string requests', async () => {
global.fetch = jest.fn().mockResolvedValue(
new Response(
Expand Down
57 changes: 56 additions & 1 deletion src/client/skills-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { HttpClient } from './http-client';
import { SkillsRequest, SkillsResponse, SyncResponse } from '../models/api';
import type {
InstallSkillRequest,
InstalledSkillInfo,
InstalledSkillsResponse,
MarketplaceResponse,
RefreshSkillResponse,
SkillActionResponse,
SkillsRequest,
SkillsResponse,
SyncResponse,
ToggleSkillResponse,
} from '../models/api';

export interface SkillsClientOptions {
host: string;
Expand Down Expand Up @@ -32,6 +43,50 @@ export class SkillsClient {
return response.data;
}

async installSkill(request: InstallSkillRequest): Promise<InstalledSkillInfo> {
const response = await this.client.post<InstalledSkillInfo>('/api/skills/install', request);
return response.data;
}

async listInstalledSkills(): Promise<InstalledSkillsResponse> {
const response = await this.client.get<InstalledSkillsResponse>('/api/skills/installed');
return response.data;
}

async getInstalledSkill(skillName: string): Promise<InstalledSkillInfo> {
const response = await this.client.get<InstalledSkillInfo>(
`/api/skills/installed/${encodeURIComponent(skillName)}`
);
return response.data;
}

async toggleSkill(skillName: string, enabled: boolean): Promise<ToggleSkillResponse> {
const response = await this.client.patch<ToggleSkillResponse>(
`/api/skills/installed/${encodeURIComponent(skillName)}`,
{ enabled }
);
return response.data;
}

async uninstallSkill(skillName: string): Promise<SkillActionResponse> {
const response = await this.client.delete<SkillActionResponse>(
`/api/skills/installed/${encodeURIComponent(skillName)}`
);
return response.data;
}

async refreshSkill(skillName: string): Promise<RefreshSkillResponse> {
const response = await this.client.post<RefreshSkillResponse>(
`/api/skills/installed/${encodeURIComponent(skillName)}/update`
);
return response.data;
}

async getMarketplace(): Promise<MarketplaceResponse> {
const response = await this.client.get<MarketplaceResponse>('/api/skills/marketplace');
return response.data;
}

close(): void {
this.client.close();
}
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ export type {
SkillInfo,
SkillsResponse,
SyncResponse,
InstallSkillRequest,
InstalledSkillInfo,
InstalledSkillSummary,
InstalledSkillsResponse,
ToggleSkillResponse,
SkillActionResponse,
RefreshSkillResponse,
MarketplaceSkill,
MarketplaceResponse,
DesktopUrlResponse,
VSCodeUrlResponse,
VSCodeStatusResponse,
Expand Down
52 changes: 52 additions & 0 deletions src/models/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,58 @@ export interface SyncResponse {
message: string;
}

export interface InstallSkillRequest {
source: string;
force?: boolean;
ref?: string | null;
repo_path?: string | null;
}

export interface InstalledSkillInfo {
name: string;
version?: string | null;
description?: string | null;
enabled: boolean;
source?: string | null;
installed_at?: string | null;
install_path?: string | null;
}

export interface InstalledSkillSummary {
name: string;
version?: string | null;
enabled: boolean;
}

export interface InstalledSkillsResponse {
skills: InstalledSkillSummary[];
}

export interface ToggleSkillResponse {
name: string;
enabled: boolean;
}

export interface SkillActionResponse {
message: string;
}

export interface RefreshSkillResponse {
message: string;
skill: InstalledSkillSummary;
}

export interface MarketplaceSkill {
name: string;
description: string;
source: string;
installed: boolean;
}

export interface MarketplaceResponse {
skills: MarketplaceSkill[];
}

export interface DesktopUrlResponse {
url: string | null;
}
Expand Down
Loading