18 lines
965 B
TypeScript
18 lines
965 B
TypeScript
/** Temporary world-file resolver until the models service supplies definitions. */
|
|
import { discoverAgents, parseFamilies } from '../core/agents.ts'
|
|
export async function discover(host: any, cwd = '/src/sausage') {
|
|
const root = '/src/sausage'
|
|
const families = parseFamilies(await host.fs.read(`${root}/agents/models.json`))
|
|
const models = host.models().getModels().map((model: any) => `${model.provider}/${model.id}`)
|
|
const files: {path:string; text:string}[] = []
|
|
for (const directory of [`${root}/agents`, `${cwd}/.sausage/agents`]) {
|
|
let entries
|
|
try { entries = await host.fs.list(directory) } catch (error) { if ((error as any).code === 'not_found') continue; throw error }
|
|
for (const entry of entries) if (entry.kind === 'file' && entry.name.endsWith('.md')) {
|
|
const path = `${directory}/${entry.name}`
|
|
files.push({path, text:await host.fs.read(path)})
|
|
}
|
|
}
|
|
return discoverAgents(files, root, cwd, families, models)
|
|
}
|