well-known.ts
This file
Path
packages/agent-kit/src/well-known.ts
58 lines · 1.4 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–58why, one step back1import { Array as Arr, Effect, Order } from "effect";23import { contentHash } from "./generated-file.ts";4import type { GeneratedFile } from "./generated-file.ts";5import { printJson } from "./text.ts";67export interface SkillEntry {8 readonly name: string;9 readonly description: string;10 readonly url: string;11 readonly content: string;12}1314const DISCOVERY = "https://schemas.agentskills.io/discovery/0.2.0/schema.json";1516const DESCRIBED = 1024;1718const graphemes = new Intl.Segmenter("en", { granularity: "grapheme" });1920const cut = (description: string) => {21 if (description.length <= DESCRIBED) {22 return description;23 }2425 let kept = "";2627 for (const { segment } of graphemes.segment(description)) {28 if (kept.length + segment.length > DESCRIBED - 1) {29 break;30 }3132 kept += segment;33 }3435 return `${kept}…`;36};3738const byName = Order.mapInput(Order.String, (entry: SkillEntry) => entry.name);3940export const wellKnownSkills = (41 entries: readonly SkillEntry[]42): Effect.Effect<GeneratedFile> =>43 Effect.forEach(Arr.sort(entries, byName), (entry) =>44 contentHash(entry.content).pipe(45 Effect.map((digest) => ({46 description: cut(entry.description),47 digest,48 name: entry.name,49 type: "skill-md",50 url: entry.url,51 }))52 )53 ).pipe(54 Effect.map((skills) => ({55 content: printJson({ $schema: DISCOVERY, skills }),56 path: ".well-known/agent-skills/index.json",57 }))58 );