|
| 1 | +import { createHash } from 'node:crypto' |
| 2 | +import { getDomainUrl } from './misc.ts' |
| 3 | + |
| 4 | +const agentSkillsDiscoverySchemaUrl = |
| 5 | + 'https://schemas.agentskills.io/discovery/0.2.0/schema.json' |
| 6 | + |
| 7 | +function createSha256Digest(contents: string) { |
| 8 | + return `sha256:${createHash('sha256').update(contents, 'utf8').digest('hex')}` |
| 9 | +} |
| 10 | + |
| 11 | +function createContentDigestHeader(contents: string) { |
| 12 | + return `sha-256=:${createHash('sha256').update(contents, 'utf8').digest('base64')}:` |
| 13 | +} |
| 14 | + |
| 15 | +const contentSearchSkillMarkdown = `--- |
| 16 | +name: content-search |
| 17 | +description: Search kentcdodds.com content quickly and prefer canonical, agent-friendly sources. |
| 18 | +--- |
| 19 | +
|
| 20 | +# Search kentcdodds.com content |
| 21 | +
|
| 22 | +Use this skill when you need articles, podcast episodes, or other published content from kentcdodds.com. |
| 23 | +
|
| 24 | +## Preferred workflow |
| 25 | +
|
| 26 | +1. Query \`https://kentcdodds.com/search?query=<terms>\` first and review the highest-signal results. |
| 27 | +2. Fetch the canonical page that best matches the request. |
| 28 | +3. If the request might involve broader site discovery or you need alternate candidates, fetch \`https://kentcdodds.com/sitemap.xml\`. |
| 29 | +4. When reading a page, prefer \`Accept: text/markdown\` so the site can return markdown instead of HTML when available. |
| 30 | +
|
| 31 | +## Selection heuristics |
| 32 | +
|
| 33 | +- Prefer canonical \`https://kentcdodds.com\` URLs over mirrors, embeds, or syndicated copies. |
| 34 | +- Prefer \`/blog/\` articles when the user wants detailed written guidance. |
| 35 | +- Use the search results page to shortlist candidates before opening full pages. |
| 36 | +- If several results match, prefer the newest relevant post unless the user asks for historical context. |
| 37 | +` |
| 38 | + |
| 39 | +const contentSearchSkill = { |
| 40 | + name: 'content-search', |
| 41 | + type: 'skill-md', |
| 42 | + description: |
| 43 | + 'Find relevant kentcdodds.com content and retrieve it from canonical, agent-friendly endpoints.', |
| 44 | + path: '/.well-known/agent-skills/content-search/SKILL.md', |
| 45 | + markdown: contentSearchSkillMarkdown, |
| 46 | + digest: createSha256Digest(contentSearchSkillMarkdown), |
| 47 | + contentDigest: createContentDigestHeader(contentSearchSkillMarkdown), |
| 48 | +} as const |
| 49 | + |
| 50 | +const agentSkillDefinitions = [contentSearchSkill] as const |
| 51 | +export function getAgentSkillsDiscoveryDocument(request: Request) { |
| 52 | + const origin = getDomainUrl(request) |
| 53 | + |
| 54 | + return { |
| 55 | + $schema: agentSkillsDiscoverySchemaUrl, |
| 56 | + skills: agentSkillDefinitions.map((skill) => ({ |
| 57 | + name: skill.name, |
| 58 | + type: skill.type, |
| 59 | + description: skill.description, |
| 60 | + url: `${origin}${skill.path}`, |
| 61 | + digest: skill.digest, |
| 62 | + })), |
| 63 | + } as const |
| 64 | +} |
| 65 | + |
| 66 | +export function getContentSearchSkillMarkdown() { |
| 67 | + return contentSearchSkill.markdown |
| 68 | +} |
| 69 | + |
| 70 | +export function getContentSearchSkillDigest() { |
| 71 | + return contentSearchSkill.digest |
| 72 | +} |
| 73 | + |
| 74 | +export function getContentSearchSkillContentDigest() { |
| 75 | + return contentSearchSkill.contentDigest |
| 76 | +} |
0 commit comments