| 1 | import { renderPromptTemplate, type PromptTemplateVars } from './render' |
| 2 | |
| 3 | export type PromptCatalog<PromptVarsById extends Record<string, PromptTemplateVars>> = { |
| 4 | render<I extends keyof PromptVarsById & string>(id: I, vars: PromptVarsById[I]): string |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Creates a catalog whose prompt id determines the allowed variable shape. |
| 9 | * Templates remain static strings; callers use a composer before this boundary |
| 10 | * when a prompt needs conditionals, arrays or JSON serialization. |
| 11 | */ |
| 12 | export const createPromptCatalog = <PromptVarsById extends Record<string, PromptTemplateVars>>( |
| 13 | templates: { [I in keyof PromptVarsById]: string } |
| 14 | ): PromptCatalog<PromptVarsById> => ({ |
| 15 | render<I extends keyof PromptVarsById & string>(id: I, vars: PromptVarsById[I]): string { |
| 16 | return renderPromptTemplate(templates[id], vars) |
| 17 | } |
| 18 | }) |
| 19 |