/** * Utility types and functions for handling prompts with dynamic replacements and conditional sections. * This allows for type-safe string templates with placeholders that can be replaced with actual values. * The `createPromptTemplate` function helps create typed prompts with automatic extraction of replacement keys. * * @module promptBuilder * @example * // Example usage: * const PROMPTS = { * welcomeMessage: createPromptTemplate(` * Generate a welcome message for a user who has just started their auto tech check attempt on {{topicTitle}}. * {{#hasBonus}} * This topic includes bonus content: {{bonusContent}} * {{/hasBonus}} * * {{#valueAsCondition}} * This is a conditional section that will only appear if the value is truthy. * Value can be used inside the section: {{valueAsCondition}} * {{/valueAsCondition}} * * {{#!skipSection}} * This negative conditional section will only appear if skipSection is falsy. * {{/skipSection}} * `), * }; * * const instruction = PROMPTS.welcomeMessage({ * topicTitle: 'JavaScript Basics', * hasBonus: true, * bonusContent: 'Advanced debugging techniques', * }); * * // This will generate a prompt: * // "Generate a welcome message for a user who has just started their auto tech check attempt on JavaScript Basics. * // This topic includes bonus content: Advanced debugging techniques" */ type RegularValue = string | number; type ConditionalValue = RegularValue | boolean | undefined | null; type ExtractAllVariables = T extends `${string}{{${infer Key}}}${infer Rest}` ? Key extends `${infer CleanKey}` ? CleanKey | ExtractAllVariables : never : never; type ExtractSectionVariables = T extends `${string}{{#!${infer Key}}}${infer Rest}` ? Key | ExtractSectionVariables : T extends `${string}{{#${infer Key}}}${infer Rest}` ? Key | ExtractSectionVariables : never; type ExtractClosingTagVariables = T extends `${string}{{/${infer Key}}}${infer Rest}` ? Key | ExtractClosingTagVariables : never; type AllSectionVariables = ExtractSectionVariables | ExtractClosingTagVariables; type ExtractRegularVariables = ExtractAllVariables extends infer All ? All extends string ? All extends `#!${string}` | `#${string}` | `/${string}` ? never : All : never : never; type CreateVariableRecord = ExtractRegularVariables extends never ? AllSectionVariables extends never ? Record : Record, ConditionalValue> : AllSectionVariables extends never ? Record, RegularValue> : Omit, RegularValue>, AllSectionVariables> & Record, ConditionalValue>; type HasVariables = ExtractAllVariables extends never ? false : true; /** * Creates a prompt template function that can be used to generate prompts * with dynamic replacements and conditional sections. * @template T The type of the template string. Inferred from the provided template. * @param {T} template The template string with placeholders: * - for dynamic values (e.g., `{{topicTitle}}`) * - for conditional sections (e.g., `{{#section}}...{{/section}}`) * - for negative conditional sections (e.g., `{{#!section}}...{{/section}}`) * - for sections that use conditional variables as values (e.g., `{{#bonus}}...{{bonus}}...{{/bonus}}`) * @returns A function that takes the dynamic values and returns the generated prompt. */ export declare function createPromptTemplate(template: T): (...args: HasVariables extends false ? [] : [variables: CreateVariableRecord]) => string; export {};