Bugfix/Escape JSON in Prompt Message (#3901)

add fix to only get variables when there is no colon
This commit is contained in:
Henry Heng
2025-01-20 19:18:28 +00:00
committed by GitHub
parent 4c9d46d7e5
commit 4aa97b0c9a
16 changed files with 148 additions and 46 deletions
+26 -1
View File
@@ -271,7 +271,7 @@ export const getInputVariables = (paramValue: string): string[] => {
const variableStartIdx = variableStack[variableStack.length - 1].startIdx
const variableEndIdx = startIdx
const variableFullPath = returnVal.substring(variableStartIdx, variableEndIdx)
inputVariables.push(variableFullPath)
if (!variableFullPath.includes(':')) inputVariables.push(variableFullPath)
variableStack.pop()
}
startIdx += 1
@@ -279,6 +279,31 @@ export const getInputVariables = (paramValue: string): string[] => {
return inputVariables
}
/**
* Transform curly braces into double curly braces if the content includes a colon.
* @param input - The original string that may contain { ... } segments.
* @returns The transformed string, where { ... } containing a colon has been replaced with {{ ... }}.
*/
export const transformBracesWithColon = (input: string): string => {
// This regex will match anything of the form `{ ... }` (no nested braces).
// `[^{}]*` means: match any characters that are not `{` or `}` zero or more times.
const regex = /\{([^{}]*?)\}/g
return input.replace(regex, (match, groupContent) => {
// groupContent is the text inside the braces `{ ... }`.
if (groupContent.includes(':')) {
// If there's a colon in the content, we turn { ... } into {{ ... }}
// The match is the full string like: "{ answer: hello }"
// groupContent is the inner part like: " answer: hello "
return `{{${groupContent}}}`
} else {
// Otherwise, leave it as is
return match
}
})
}
/**
* Crawl all available urls given a domain url and limit
* @param {string} url