* Substitute variables in the prompt template using {{variable}} syntax
( template: string, variables: Record<string, string>, )
| 199 | * Substitute variables in the prompt template using {{variable}} syntax |
| 200 | */ |
| 201 | function substituteVariables( |
| 202 | template: string, |
| 203 | variables: Record<string, string>, |
| 204 | ): string { |
| 205 | // Single-pass replacement avoids two bugs: (1) $ backreference corruption |
| 206 | // (replacer fn treats $ literally), and (2) double-substitution when user |
| 207 | // content happens to contain {{varName}} matching a later variable. |
| 208 | return template.replace(/\{\{(\w+)\}\}/g, (match, key: string) => |
| 209 | Object.prototype.hasOwnProperty.call(variables, key) |
| 210 | ? variables[key]! |
| 211 | : match, |
| 212 | ) |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Check if the session memory content is essentially empty (matches the template). |
no outgoing calls
no test coverage detected