|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { mkdir, writeFile } from "node:fs/promises"; |
| 4 | +import { join } from "node:path"; |
| 5 | + |
| 6 | +// Generate /.well-known/agent-skills/index.json for AI discovery as defined by Cloudflare |
| 7 | +// @see https://github.com/cloudflare/agent-skills-discovery-rfc |
| 8 | +// @see https://isitagentready.com/.well-known/agent-skills/agent-skills/SKILL.md |
| 9 | +// test: https://isitagentready.com/juno.build |
| 10 | + |
| 11 | +const TEMPLATE_SKILL_WITHOUT_DIGEST = { |
| 12 | + name: "juno", |
| 13 | + type: "skill-md", |
| 14 | + description: |
| 15 | + "Up-to-date knowledge about Juno's CLI, SDK, and serverless functions for AI coding agents.", |
| 16 | + url: "https://raw.githubusercontent.com/junobuild/skills/main/SKILL.md" |
| 17 | +}; |
| 18 | + |
| 19 | +const TEMPLATE = { |
| 20 | + $schema: "https://schemas.agentskills.io/discovery/0.2.0/schema.json", |
| 21 | + skills: [] |
| 22 | +}; |
| 23 | + |
| 24 | +const OUTPUT_DIR = join("static", ".well-known", "agent-skills"); |
| 25 | +const OUTPUT_FILE_PATH = join(OUTPUT_DIR, "index.json"); |
| 26 | + |
| 27 | +await mkdir(OUTPUT_DIR, { recursive: true }); |
| 28 | + |
| 29 | +const computeSkillSha256 = async () => { |
| 30 | + const response = await fetch( |
| 31 | + "https://raw.githubusercontent.com/junobuild/skills/main/SKILL.md" |
| 32 | + ); |
| 33 | + |
| 34 | + if (!response.ok) { |
| 35 | + throw new Error("Fetching the current SKILL.md failed!"); |
| 36 | + } |
| 37 | + |
| 38 | + const md = await response.text(); |
| 39 | + |
| 40 | + const encoder = new TextEncoder(); |
| 41 | + const hash = await crypto.subtle.digest("SHA-256", encoder.encode(md)); |
| 42 | + |
| 43 | + const sha256ToHex = (hashBuffer) => { |
| 44 | + const hashArray = Array.from(new Uint8Array(hashBuffer)); |
| 45 | + return hashArray.map((b) => b.toString(16).padStart(2, "0")).join(""); |
| 46 | + }; |
| 47 | + |
| 48 | + return sha256ToHex(hash); |
| 49 | +}; |
| 50 | + |
| 51 | +const sha256 = await computeSkillSha256(); |
| 52 | + |
| 53 | +const skill = { |
| 54 | + ...TEMPLATE_SKILL_WITHOUT_DIGEST, |
| 55 | + digest: `sha256:${sha256}` |
| 56 | +}; |
| 57 | + |
| 58 | +const json = { |
| 59 | + ...TEMPLATE, |
| 60 | + skills: [skill] |
| 61 | +}; |
| 62 | + |
| 63 | +await writeFile(OUTPUT_FILE_PATH, JSON.stringify(json, null, 2), "utf8"); |
0 commit comments