fix(agent-skills): use res.text() for text/markdown endpoint (GAP-1 critical bug)

The /api/agent-skills/[id]/raw endpoint returns text/markdown (plain string),
not a JSON envelope. The client was incorrectly calling res.json() and
unpacking a non-existent `body` field, causing all preview panes to show
empty content. Switch to res.text() and update the test mock to match.
This commit is contained in:
diegosouzapw
2026-05-28 01:53:59 -03:00
parent 5c79c1a32d
commit 4797c08018
2 changed files with 4 additions and 4 deletions

View File

@@ -95,8 +95,8 @@ export function AgentSkillsPageClient(): JSX.Element {
try {
const res = await fetch(`/api/agent-skills/${id}/raw`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const json = (await res.json()) as { body: string };
setMarkdownCache((prev) => new Map(prev).set(id, json.body ?? ""));
const body = await res.text();
setMarkdownCache((prev) => new Map(prev).set(id, body));
} catch {
setMarkdownCache((prev) => {
const next = new Map(prev);

View File

@@ -106,9 +106,9 @@ function mockFetch(skills: AgentSkill[], coverage: SkillCoverage, rawMarkdown =
});
}
if (/\/api\/agent-skills\/.+\/raw/.test(urlStr)) {
return new Response(JSON.stringify({ body: rawMarkdown }), {
return new Response(rawMarkdown, {
status: 200,
headers: { "Content-Type": "application/json" },
headers: { "Content-Type": "text/markdown; charset=utf-8" },
});
}
return new Response(JSON.stringify({}), { status: 404 });