+32
-33
lines changedFilter options
+32
-33
lines changed Original file line number Diff line number Diff line change
@@ -97,58 +97,50 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
97
97
}
98
98
99
99
// 4.3 字符串转对象
100
-
if (
101
-
(type === WorkflowIOValueTypeEnum.object || type.startsWith('array')) &&
102
-
typeof value === 'string' &&
103
-
value.trim()
104
-
) {
105
-
const trimmedValue = value.trim();
106
-
const isJsonString = isObjectString(trimmedValue);
107
-
108
-
if (isJsonString) {
100
+
if (type === WorkflowIOValueTypeEnum.object) {
101
+
if (isObjectString(value)) {
102
+
const trimmedValue = value.trim();
109
103
try {
110
-
const parsed = json5.parse(trimmedValue);
111
-
// 检测解析结果与目标类型是否一致
112
-
if (type.startsWith('array') && Array.isArray(parsed)) return parsed;
113
-
if (type === WorkflowIOValueTypeEnum.object && typeof parsed === 'object') return parsed;
104
+
return json5.parse(trimmedValue);
114
105
} catch (error) {}
115
106
}
107
+
return {};
116
108
}
117
109
118
110
// 4.4 数组类型(这里 value 不是数组类型)(TODO: 嵌套数据类型转化)
119
111
if (type.startsWith('array')) {
112
+
if (isObjectString(value)) {
113
+
try {
114
+
return json5.parse(value);
115
+
} catch (error) {}
116
+
}
120
117
return [value];
121
118
}
122
119
123
120
// 4.5 特殊类型处理
124
121
if (
125
-
[WorkflowIOValueTypeEnum.datasetQuote, WorkflowIOValueTypeEnum.selectDataset].includes(type)
122
+
[
123
+
WorkflowIOValueTypeEnum.datasetQuote,
124
+
WorkflowIOValueTypeEnum.selectDataset,
125
+
WorkflowIOValueTypeEnum.selectApp
126
+
].includes(type)
126
127
) {
127
128
if (isObjectString(value)) {
128
129
try {
129
130
return json5.parse(value);
130
-
} catch (error) {
131
-
return [];
132
-
}
131
+
} catch (error) {}
133
132
}
134
133
return [];
135
134
}
136
-
if (
137
-
[WorkflowIOValueTypeEnum.selectApp, WorkflowIOValueTypeEnum.object].includes(type) &&
138
-
typeof value === 'string'
139
-
) {
135
+
136
+
// Invalid history type
137
+
if (type === WorkflowIOValueTypeEnum.chatHistory) {
140
138
if (isObjectString(value)) {
141
139
try {
142
140
return json5.parse(value);
143
-
} catch (error) {
144
-
return {};
145
-
}
141
+
} catch (error) {}
146
142
}
147
-
return {};
148
-
}
149
-
// Invalid history type
150
-
if (type === WorkflowIOValueTypeEnum.chatHistory) {
151
-
return 0;
143
+
return [];
152
144
}
153
145
154
146
// 5. 默认返回原值
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ export const dispatchUpdateVariable = async (props: Props): Promise<Response> =>
58
58
variables
59
59
})
60
60
: item.value?.[1];
61
+
61
62
return valueTypeFormat(val, item.valueType);
62
63
} else {
63
64
return getReferenceVariableValue({
Original file line number Diff line number Diff line change
@@ -97,7 +97,13 @@ const PromptEditor = ({
97
97
/>
98
98
)}
99
99
</Box>
100
-
<MyModal isOpen={isOpen} onClose={onClose} iconSrc="modal/edit" title={title} w={'full'}>
100
+
<MyModal
101
+
isOpen={isOpen}
102
+
onClose={onClose}
103
+
iconSrc="modal/edit"
104
+
title={title || t('common:Edit')}
105
+
w={'full'}
106
+
>
101
107
<ModalBody>
102
108
<Editor
103
109
minH={400}
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ describe('valueTypeFormat', () => {
48
48
{
49
49
value: 'false',
50
50
type: WorkflowIOValueTypeEnum.selectApp,
51
-
result: {}
51
+
result: []
52
52
},
53
53
{
54
54
value: 'false',
@@ -171,7 +171,7 @@ describe('valueTypeFormat', () => {
171
171
{
172
172
value: true,
173
173
type: WorkflowIOValueTypeEnum.object,
174
-
result: true
174
+
result: {}
175
175
}
176
176
];
177
177
boolTestList.forEach((item, index) => {
@@ -263,7 +263,7 @@ describe('valueTypeFormat', () => {
263
263
{
264
264
value: '1',
265
265
type: WorkflowIOValueTypeEnum.chatHistory,
266
-
result: 0
266
+
result: []
267
267
}
268
268
];
269
269
chatHistoryTestList.forEach((item, index) => {
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4