(template: string, params: PromptParams)
| 9 | } |
| 10 | |
| 11 | export const createPrompt = (template: string, params: PromptParams): string => { |
| 12 | return template.replace(/\${(.*?)}/g, (_, key) => { |
| 13 | if (key === "diagnosticText") { |
| 14 | return generateDiagnosticText(params["diagnostics"] as any[]) |
| 15 | // eslint-disable-next-line no-prototype-builtins |
| 16 | } else if (params.hasOwnProperty(key)) { |
| 17 | // Ensure the value is treated as a string for replacement |
| 18 | const value = params[key] |
| 19 | if (typeof value === "string") { |
| 20 | return value |
| 21 | } else { |
| 22 | // Convert non-string values to string for replacement |
| 23 | return String(value) |
| 24 | } |
| 25 | } else { |
| 26 | // If the placeholder key is not in params, replace with empty string |
| 27 | return "" |
| 28 | } |
| 29 | }) |
| 30 | } |
| 31 | |
| 32 | interface SupportPromptConfig { |
| 33 | template: string |
no test coverage detected