added method fixJsonBraces, see #551.
This commit is contained in:
parent
f2dc04b267
commit
8d8f8abaf3
1 changed files with 21 additions and 1 deletions
|
|
@ -592,8 +592,11 @@ export function hasSpecificIntegration(use, conntype){
|
||||||
return use && (conntype != null) && (conntype !== '');
|
return use && (conntype != null) && (conntype !== '');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractJsonObject(inputString) {
|
export function extractJsonObject(inputString, fixBraces = true) {
|
||||||
try {
|
try {
|
||||||
|
if (fixBraces) {
|
||||||
|
inputString = fixJsonBraces(inputString);
|
||||||
|
}
|
||||||
const jsonMatch = inputString.match(/\{[\s\S]*\}/);
|
const jsonMatch = inputString.match(/\{[\s\S]*\}/);
|
||||||
if (jsonMatch) {
|
if (jsonMatch) {
|
||||||
const jsonObject = JSON.parse(jsonMatch[0]);
|
const jsonObject = JSON.parse(jsonMatch[0]);
|
||||||
|
|
@ -611,6 +614,23 @@ export function extractJsonObject(inputString) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fixJsonBraces(inputString) {
|
||||||
|
let result = inputString.trim();
|
||||||
|
const hasOpen = result.startsWith("{");
|
||||||
|
const hasClose = result.endsWith("}");
|
||||||
|
|
||||||
|
if (hasClose && !hasOpen) {
|
||||||
|
return "{" + result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasOpen && !hasClose) {
|
||||||
|
return result + "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function isAPIKeyValue(id){
|
export function isAPIKeyValue(id){
|
||||||
return id=="chatgpt_api_key" || id=="openai_comp_api_key" || id=="google_gemini_api_key" || id=="anthropic_api_key";
|
return id=="chatgpt_api_key" || id=="openai_comp_api_key" || id=="google_gemini_api_key" || id=="anthropic_api_key";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue