MCPcopy
hub / github.com/FlowiseAI/Flowise / transformBracesWithColon

Function transformBracesWithColon

packages/components/src/utils.ts:275–295  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

273 * @returns The transformed string, where { ... } containing a colon has been replaced with {{ ... }}.
274 */
275export 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

Callers 13

initMethod · 0.90
initMethod · 0.90
initMethod · 0.90
initMethod · 0.90
prepareChatPromptFunction · 0.90
getSQLDBChainFunction · 0.90
initMethod · 0.90
initMethod · 0.90
initMethod · 0.90
prepareAgentFunction · 0.90
prepareAgentFunction · 0.90
prepareAgentFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected