(content: string, filePath: string)
| 8 | import type { AssistantConfig } from './types' |
| 9 | |
| 10 | export function parseAssistantFile(content: string, filePath: string): AssistantConfig | null { |
| 11 | try { |
| 12 | const { data: fm, content: body } = matter(content) |
| 13 | |
| 14 | const id = fm.id ?? path.basename(filePath, '.md') |
| 15 | const name = fm.name |
| 16 | if (!name) return null |
| 17 | |
| 18 | return { |
| 19 | id, |
| 20 | name, |
| 21 | systemPrompt: body.trim(), |
| 22 | presetQuestions: parseStringArray(fm.presetQuestions), |
| 23 | allowedBuiltinTools: normalizeBuiltinToolNames(parseStringArray(fm.allowedBuiltinTools)), |
| 24 | builtinId: typeof fm.builtinId === 'string' ? fm.builtinId : undefined, |
| 25 | applicableChatTypes: parseChatTypes(fm.applicableChatTypes), |
| 26 | supportedLocales: parseStringArray(fm.supportedLocales), |
| 27 | } |
| 28 | } catch { |
| 29 | return null |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | export function serializeAssistant(config: AssistantConfig): string { |
| 34 | const fm: Record<string, unknown> = { |
no test coverage detected