Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

feat(agent-skills): add REST GET endpoints (list, get, raw, coverage)

diegosouzapwd1160120c000
diff --git a/src/app/api/agent-skills/[id]/raw/route.ts b/src/app/api/agent-skills/[id]/raw/route.ts
new file mode 100644
index 0000000000..57822203b0
--- /dev/null
+++ b/src/app/api/agent-skills/[id]/raw/route.ts
@@ -0,0 +1,73 @@
+/**
+ * GET /api/agent-skills/[id]/raw
+ *
+ * Returns the raw SKILL.md content for a given skill as text/markdown.
+ * Resolution order: local filesystem → GitHub raw URL (1-hour cache).
+ *
+ * Response: text/markdown; charset=utf-8
+ * 404 if skill not found in catalog.
+ * 502 if upstream GitHub fetch fails.
+ */
+import { buildErrorBody } from "@omniroute/open-sse/utils/error.ts";
+import { getSkillById, fetchSkillMarkdown } from "@/lib/agentSkills/catalog";
+
+export const dynamic = "force-dynamic";
+
+export async function GET(
+ _request: Request,
+ { params }: { params: Promise<{ id: string }> },
+) {
+ try {
+ const { id } = await params;
+
+ if (!id || typeof id !== "string") {
+ return new Response(JSON.stringify(buildErrorBody(400, "Missing skill id")), {
+ status: 400,
+ headers: { "Content-Type": "application/json" },
+ });
+ }
+
+ // Validate the skill exists in catalog before attempting fetch
+ const skill = getSkillById(id);
+ if (!skill) {
+ return new Response(JSON.stringify(buildErrorBody(404, `Skill not found: ${id}`)), {
+ status: 404,
+ headers: { "Content-Type": "application/json" },
+ });
+ }
+
+ const markdown = await fetchSkillMarkdown(id);
+
+ // Return the full markdown content (frontmatter + body reconstructed)
+ const content =
+ markdown.frontmatter.name
+ ? `---\nname: ${markdown.frontmatter.name}\ndescription: ${markdown.frontmatter.description}\n---\n${markdown.body}`
+ : markdown.body;
+
+ return new Response(content, {
+ status: 200,
+ headers: {
+ "Content-Type": "text/markdown; charset=utf-8",
+ "Cache-Control": "public, max-age=3600",
+ "X-Skill-Source": markdown.source,
+ "X-Skill-Fetched-At": markdown.fetchedAt,
+ },
+ });
+ } catch (error) {
+ const message = error instanceof Error ? error.message : "Failed to fetch skill markdown";
+
+ // Distinguish GitHub upstream failures (502) from internal errors (500)
+ if (message.includes("GitHub raw fetch failed")) {
+ return new Response(
+ JSON.stringify(buildErrorBody(502, "Upstream fetch failed — try again later")),
+ { status: 502, headers: { "Content-Type": "application/json" } },
+ );
+ }
+
+ console.error("[API] GET /api/agent-skills/[id]/raw error:", error);
+ return new Response(JSON.stringify(buildErrorBody(500, "Failed to fetch skill content")), {
+ status: 500,
+ headers: { "Content-Type": "application/json" },
+ });
+ }
+}
diff --git a/src/app/api/agent-skills/[id]/route.ts b/src/app/api/agent-skills/[id]/route.ts
new file mode 100644
index 0000000000..909649671a
--- /dev/null
+++ b/src/app/api/agent-skills/[id]/route.ts
@@ -0,0 +1,37 @@
+/**
+ * GET /api/agent-skills/[id]
+ *
+ * Returns a single AgentSkill by its canonical ID.
+ *
+ * Response: AgentSkill
+ * 404 if skill not found in catalog.
+ */
+import { NextResponse } from "next/server";
+
+import { buildErrorBody } from "@omniroute/open-sse/utils/error.ts";
+import { getSkillById } from "@/lib/agentSkills/catalog";
+
+export const dynamic = "force-dynamic";
+
+export async function GET(
+ _request: Request,
+ { params }: { params: Promise<{ id: string }> },
+) {
+ try {
+ const { id } = await params;
+
+ if (!id || typeof id !== "string") {
+ return NextResponse.json(buildErrorBody(400, "Missing skill id"), { status: 400 });
+ }
+
+ const skill = getSkillById(id);
+ if (!skill) {
+ return NextResponse.json(buildErrorBody(404, `Skill not found: ${id}`), { status: 404 });
+ }
+
+ return NextResponse.json(skill);
+ } catch (error) {
+ console.error("[API] GET /api/agent-skills/[id] error:", error);
+ return NextResponse.json(buildErrorBody(500, "Failed to load skill"), { status: 500 });
+ }
+}
diff --git a/src/app/api/agent-skills/coverage/route.ts b/src/app/api/agent-skills/coverage/route.ts
new file mode 100644
index 0000000000..490aa98e0c
--- /dev/null
+++ b/src/app/api/agent-skills/coverage/route.ts
@@ -0,0 +1,25 @@
+/**
+ * GET /api/agent-skills/coverage
+ *
+ * Returns SkillCoverage: how many skills have a SKILL.md on filesystem vs catalog total.
+ *
+ * Response: SkillCoverage
+ */
+import { NextResponse } from "next/server";
+
+import { buildErrorBody } from "@omniroute/open-sse/utils/error.ts";
+import { computeCoverage } from "@/lib/agentSkills/catalog";
+
+export const dynamic = "force-dynamic";
+
+export async function GET() {
+ try {
+ const coverage = computeCoverage();
+ return NextResponse.json(coverage);
+ } catch (error) {
+ console.error("[API] GET /api/agent-skills/coverage error:", error);
+ return NextResponse.json(buildErrorBody(500, "Failed to compute skill coverage"), {
+ status: 500,
+ });
+ }
+}
diff --git a/src/app/api/agent-skills/route.ts b/src/app/api/agent-skills/route.ts
new file mode 100644
index 0000000000..4652f2cf3d
--- /dev/null
+++ b/src/app/api/agent-skills/route.ts
@@ -0,0 +1,47 @@
+/**
+ * GET /api/agent-skills
+ *
+ * Returns the full Agent Skills catalog with optional filtering by category or area.
+ *
+ * Query params:
+ * - category?: "api" | "cli"
+ * - area?: string
+ *
+ * Response: { skills: AgentSkill[], count: number, coverage: SkillCoverage }
+ */
+import { NextResponse } from "next/server";
+
+import { buildErrorBody } from "@omniroute/open-sse/utils/error.ts";
+import { ListQuerySchema } from "@/lib/agentSkills/schemas";
+import { filterCatalog, computeCoverage } from "@/lib/agentSkills/catalog";
+
+// Catalog reads filesystem on demand — disable static caching
+export const dynamic = "force-dynamic";
+
+export async function GET(request: Request) {
+ try {
+ const { searchParams } = new URL(request.url);
+
+ const parsed = ListQuerySchema.safeParse({
+ category: searchParams.get("category") ?? undefined,
+ area: searchParams.get("area") ?? undefined,
+ });
+
+ if (!parsed.success) {
+ return NextResponse.json(
+ buildErrorBody(400, parsed.error.issues[0]?.message ?? "Invalid query parameters"),
+ { status: 400 },
+ );
+ }
+
+ const skills = filterCatalog(parsed.data);
+ const coverage = computeCoverage();
+
+ return NextResponse.json({ skills, count: skills.length, coverage });
+ } catch (error) {
+ console.error("[API] GET /api/agent-skills error:", error);
+ return NextResponse.json(buildErrorBody(500, "Failed to load agent skills catalog"), {
+ status: 500,
+ });
+ }
+}