64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { getBackendBaseURL } from "@/core/config";
|
|
import { apiFetch } from "@/core/api";
|
|
|
|
import type { Skill } from "./type";
|
|
|
|
export async function loadSkills() {
|
|
const skills = await apiFetch(`${getBackendBaseURL()}/api/skills`);
|
|
const json = await skills.json();
|
|
return json.skills as Skill[];
|
|
}
|
|
|
|
export async function enableSkill(skillName: string, enabled: boolean) {
|
|
const response = await apiFetch(
|
|
`${getBackendBaseURL()}/api/skills/${skillName}`,
|
|
{
|
|
method: "PUT",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
enabled,
|
|
}),
|
|
},
|
|
);
|
|
return response.json();
|
|
}
|
|
|
|
export interface InstallSkillRequest {
|
|
thread_id: string;
|
|
path: string;
|
|
}
|
|
|
|
export interface InstallSkillResponse {
|
|
success: boolean;
|
|
skill_name: string;
|
|
message: string;
|
|
}
|
|
|
|
export async function installSkill(
|
|
request: InstallSkillRequest,
|
|
): Promise<InstallSkillResponse> {
|
|
const response = await apiFetch(`${getBackendBaseURL()}/api/skills/install`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(request),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
// Handle HTTP error responses (4xx, 5xx)
|
|
const errorData = await response.json().catch(() => ({}));
|
|
const errorMessage =
|
|
errorData.detail ?? `HTTP ${response.status}: ${response.statusText}`;
|
|
return {
|
|
success: false,
|
|
skill_name: "",
|
|
message: errorMessage,
|
|
};
|
|
}
|
|
|
|
return response.json();
|
|
}
|