fix: charts plugins (#3530)

This commit is contained in:
Archer
2025-01-05 14:41:34 +08:00
committed by GitHub
parent e5735fddd1
commit 72ed72e595
8 changed files with 52 additions and 170 deletions

View File

@@ -25,17 +25,22 @@ export const simpleText = (text = '') => {
return text;
};
/*
replace {{variable}} to value
*/
export const valToStr = (val: any) => {
if (val === undefined) return 'undefined';
if (val === null) return 'null';
if (typeof val === 'object') return JSON.stringify(val);
return String(val);
};
// replace {{variable}} to value
export function replaceVariable(text: any, obj: Record<string, string | number>) {
if (typeof text !== 'string') return text;
for (const key in obj) {
const val = obj[key];
const formatVal = typeof val === 'object' ? JSON.stringify(val) : String(val);
text = text.replace(new RegExp(`{{(${key})}}`, 'g'), formatVal);
const formatVal = valToStr(val);
text = text.replace(new RegExp(`{{(${key})}}`, 'g'), () => formatVal);
}
return text || '';
}

View File

@@ -9,7 +9,7 @@ import { isValidReferenceValueFormat } from '../utils';
import { FlowNodeOutputItemType, ReferenceValueType } from '../type/io';
import { ChatItemType, NodeOutputItemType } from '../../../core/chat/type';
import { ChatItemValueTypeEnum, ChatRoleEnum } from '../../../core/chat/constants';
import { replaceVariable } from '../../../common/string/tools';
import { replaceVariable, valToStr } from '../../../common/string/tools';
export const getMaxHistoryLimitFromNodes = (nodes: StoreNodeItemType[]): number => {
let limit = 10;
@@ -343,11 +343,7 @@ export function replaceEditorVariable({
if (input) return getReferenceVariableValue({ value: input.value, nodes, variables });
})();
const formatVal = (() => {
if (variableVal === undefined) return 'undefined';
if (variableVal === null) return 'null';
return typeof variableVal === 'object' ? JSON.stringify(variableVal) : String(variableVal);
})();
const formatVal = valToStr(variableVal);
const regex = new RegExp(`\\{\\{\\$(${nodeId}\\.${id})\\$\\}\\}`, 'g');
text = text.replace(regex, () => formatVal);

View File

@@ -13,6 +13,7 @@
"next": "14.2.5",
"openai": "4.61.0",
"openapi-types": "^12.1.3",
"json5": "^2.2.3",
"timezones-list": "^3.0.2"
},
"devDependencies": {