(input: string)
| 273 | * @returns The transformed string, where { ... } containing a colon has been replaced with {{ ... }}. |
| 274 | */ |
| 275 | export const transformBracesWithColon = (input: string): string => { |
| 276 | // This regex uses negative lookbehind (?<!{) and negative lookahead (?!}) |
| 277 | // to ensure we only match single curly braces, not double ones. |
| 278 | // It will match a single { that's not preceded by another {, |
| 279 | // followed by any content without braces, then a single } that's not followed by another }. |
| 280 | const regex = /(?<!\{)\{([^{}]*?)\}(?!\})/g |
| 281 | |
| 282 | return input.replace(regex, (match, groupContent) => { |
| 283 | // groupContent is the text inside the braces `{ ... }`. |
| 284 | |
| 285 | if (groupContent.includes(':')) { |
| 286 | // If there's a colon in the content, we turn { ... } into {{ ... }} |
| 287 | // The match is the full string like: "{ answer: hello }" |
| 288 | // groupContent is the inner part like: " answer: hello " |
| 289 | return `{{${groupContent}}}` |
| 290 | } else { |
| 291 | // Otherwise, leave it as is |
| 292 | return match |
| 293 | } |
| 294 | }) |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Extracts text content from an AIMessageChunk, filtering out reasoning/thinking |
no outgoing calls
no test coverage detected