| 27 | server = Bun.serve({ |
| 28 | port: 0, |
| 29 | async fetch(req) { |
| 30 | const url = new URL(req.url) |
| 31 | |
| 32 | if (url.pathname === "/mutable/index.json") { |
| 33 | return Response.json({ skills: [{ name: "mutable", version: mutableVersion, files: mutableFiles }] }) |
| 34 | } |
| 35 | if (url.pathname === "/mutable/mutable/SKILL.md") { |
| 36 | mutableDownloadCount++ |
| 37 | return new Response(mutableContent) |
| 38 | } |
| 39 | if (url.pathname === "/mutable/mutable/old.md") return new Response("old reference") |
| 40 | |
| 41 | // route /.well-known/skills/* to the fixture directory |
| 42 | if (url.pathname.startsWith("/.well-known/skills/")) { |
| 43 | const filePath = url.pathname.replace("/.well-known/skills/", "") |
| 44 | const fullPath = path.join(fixturePath, filePath) |
| 45 | |
| 46 | if (await Filesystem.exists(fullPath)) { |
| 47 | if (!fullPath.endsWith("index.json")) { |
| 48 | downloadCount++ |
| 49 | } |
| 50 | return new Response(Bun.file(fullPath)) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return new Response("Not Found", { status: 404 }) |
| 55 | }, |
| 56 | }) |
| 57 | |
| 58 | CLOUDFLARE_SKILLS_URL = `http://localhost:${server.port}/.well-known/skills/` |