| |
| |
|
|
| import { stringify as yamlStringify } from "yaml"; |
| import type { Skill, Step } from "./skill.ts"; |
|
|
| export interface SkillBundle { |
| skill_md: string; |
| manifest_json: string; |
| actions_toon: string; |
| } |
|
|
| export const TOON_HEADER_ACTIONS = "@meeseeks/v0.1 actions"; |
|
|
| export function exportSkill(skill: Skill): SkillBundle { |
| return { |
| skill_md: renderSkillMd(skill), |
| manifest_json: renderManifestJson(skill), |
| actions_toon: renderActionsToon(skill), |
| }; |
| } |
|
|
| function renderSkillMd(s: Skill): string { |
| const params = s.inputs.map((i) => ` - name: ${i}\n required: true`).join("\n"); |
| const preconds = s.preconditions.map((p) => `- ${p}`).join("\n"); |
| const steps = s.steps.map((st, i) => `${i + 1}. ${st.instruction}`).join("\n"); |
| const verify = s.steps.map((st) => `- ${st.successCheck}`).join("\n"); |
| return [ |
| "---", |
| `name: ${s.name}`, |
| `description: ${s.intent}`, |
| `domain: ${s.meta.domain}`, |
| `version: ${s.schemaVersion}`, |
| "parameters:", |
| params, |
| "---", |
| "", |
| "# When to use", |
| s.intent, |
| "", |
| "# Preconditions", |
| preconds, |
| "", |
| "# Steps", |
| steps, |
| "", |
| "# Verification", |
| verify, |
| "", |
| ].join("\n"); |
| } |
|
|
| function renderManifestJson(s: Skill): string { |
| const grounding = s.steps.map((st) => ({ |
| step_id: st.id, |
| description: st.target.description, |
| bbox: st.target.bbox ?? null, |
| ax_role: st.target.ax_role ?? null, |
| ax_name: st.target.ax_name ?? null, |
| success_check: st.successCheck, |
| fallback: st.fallback ?? null, |
| })); |
| const manifest = { |
| schema: "meeseeks/v0.1", |
| name: s.name, |
| description: s.intent, |
| domain: s.meta.domain, |
| parameters: s.inputs, |
| preconditions: s.preconditions, |
| redacted: s.meta.redacted, |
| placeholders: s.meta.placeholders, |
| meeseeks: { grounding }, |
| extensions: s.extensions ?? {}, |
| }; |
| return JSON.stringify(manifest, null, 2); |
| } |
|
|
| function renderActionsToon(s: Skill): string { |
| const body = { |
| name: s.name, |
| intent: s.intent, |
| schema_version: s.schemaVersion, |
| steps: s.steps.map((st) => stepToToon(st)), |
| }; |
| return TOON_HEADER_ACTIONS + "\n" + yamlStringify(body); |
| } |
|
|
| function stepToToon(st: Step) { |
| return { |
| id: st.id, |
| action: st.action, |
| instruction: st.instruction, |
| target_description: st.target.description, |
| }; |
| } |
|
|