opencode-patches/skill_group.ts

68 lines
2.7 KiB
TypeScript
Raw Normal View History

import { Schema } from "effect"
import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
import { Authorization } from "../middleware/authorization"
import { InstanceContextMiddleware } from "../middleware/instance-context"
import { WorkspaceRoutingMiddleware, WorkspaceRoutingQuery } from "../middleware/workspace-routing"
import { described } from "./metadata"
const root = "/skill"
export const SkillInfo = Schema.Struct({
name: Schema.String,
description: Schema.optional(Schema.String),
location: Schema.String,
content: Schema.String,
})
export const SkillApi = HttpApi.make("skill")
.add(
HttpApiGroup.make("skill")
.add(
HttpApiEndpoint.get("list", root, {
query: WorkspaceRoutingQuery,
success: described(Schema.Array(SkillInfo), "List of installed skills"),
}).annotateMerge(
OpenApi.annotations({ identifier: "skill.list", summary: "List all installed skills" }),
),
HttpApiEndpoint.post("install", `${root}/install`, {
query: WorkspaceRoutingQuery,
payload: Schema.Struct({ url: Schema.String }),
success: described(SkillInfo, "Installed skill"),
error: HttpApiError.BadRequest,
}).annotateMerge(
OpenApi.annotations({ identifier: "skill.install", summary: "Install skill from URL or owner/repo" }),
),
HttpApiEndpoint.post("upload", `${root}/upload`, {
query: WorkspaceRoutingQuery,
payload: Schema.Struct({ name: Schema.String, content: Schema.String }),
success: described(SkillInfo, "Uploaded skill"),
error: HttpApiError.BadRequest,
}).annotateMerge(
OpenApi.annotations({ identifier: "skill.upload", summary: "Upload a SKILL.md file directly" }),
),
HttpApiEndpoint.del("remove", `${root}/:name`, {
query: WorkspaceRoutingQuery,
success: described(Schema.Literal(true), "Skill removed"),
error: HttpApiError.NotFound,
}).annotateMerge(
OpenApi.annotations({ identifier: "skill.remove", summary: "Remove an installed skill" }),
),
)
.annotateMerge(
OpenApi.annotations({
title: "skill",
description: "Skills management: list, install, upload, and remove SKILL.md files.",
}),
)
.middleware(InstanceContextMiddleware)
.middleware(WorkspaceRoutingMiddleware)
.middleware(Authorization),
)
.annotateMerge(
OpenApi.annotations({
title: "opencode experimental HttpApi",
version: "0.0.1",
description: "Experimental HttpApi surface for selected instance routes.",
}),
)