import { kody } from 'kody:runtime'
type SkillsExport = (input: Record<string, unknown>) => Promise<unknown>
export async function loadSkillsExport(
exportName: 'skill-list' | 'skill-get',
): Promise<SkillsExport> {
const packages = await kody.packageList({})
const skills = packages.packages.find(pkg => pkg.kody_id === 'skills')
if (!skills) {
throw new Error(
'Skills package not found. Fork and publish the skills Listing with kody.id \"skills\".',
)
}
const specifier = `kody:${skills.name}/${exportName}`
const module = await import(specifier)
if (typeof module.default !== 'function') {
throw new Error(`Skills export ${exportName} is not callable.`)
}
return module.default as SkillsExport
}