Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
593c816c
authored
Jul 18, 2025
by
Archer
Committed by
GitHub
Jul 18, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: value type checker (#5255)
* perf: value type checker * fix: ts
parent
6f75c1b8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
33 deletions
+32
-33
packages/global/core/workflow/runtime/utils.ts
+21
-29
packages/service/core/workflow/dispatch/tools/runUpdateVar.ts
+1
-0
packages/web/components/common/Textarea/PromptEditor/index.tsx
+7
-1
test/cases/service/core/app/workflow/dispatch/utils.test.ts
+3
-3
No files found.
packages/global/core/workflow/runtime/utils.ts
View file @
593c816c
...
@@ -97,58 +97,50 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
...
@@ -97,58 +97,50 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
}
}
// 4.3 字符串转对象
// 4.3 字符串转对象
if
(
if
(
type
===
WorkflowIOValueTypeEnum
.
object
)
{
(
type
===
WorkflowIOValueTypeEnum
.
object
||
type
.
startsWith
(
'array'
))
&&
if
(
isObjectString
(
value
))
{
typeof
value
===
'string'
&&
const
trimmedValue
=
value
.
trim
();
value
.
trim
()
)
{
const
trimmedValue
=
value
.
trim
();
const
isJsonString
=
isObjectString
(
trimmedValue
);
if
(
isJsonString
)
{
try
{
try
{
const
parsed
=
json5
.
parse
(
trimmedValue
);
return
json5
.
parse
(
trimmedValue
);
// 检测解析结果与目标类型是否一致
if
(
type
.
startsWith
(
'array'
)
&&
Array
.
isArray
(
parsed
))
return
parsed
;
if
(
type
===
WorkflowIOValueTypeEnum
.
object
&&
typeof
parsed
===
'object'
)
return
parsed
;
}
catch
(
error
)
{}
}
catch
(
error
)
{}
}
}
return
{};
}
}
// 4.4 数组类型(这里 value 不是数组类型)(TODO: 嵌套数据类型转化)
// 4.4 数组类型(这里 value 不是数组类型)(TODO: 嵌套数据类型转化)
if
(
type
.
startsWith
(
'array'
))
{
if
(
type
.
startsWith
(
'array'
))
{
if
(
isObjectString
(
value
))
{
try
{
return
json5
.
parse
(
value
);
}
catch
(
error
)
{}
}
return
[
value
];
return
[
value
];
}
}
// 4.5 特殊类型处理
// 4.5 特殊类型处理
if
(
if
(
[
WorkflowIOValueTypeEnum
.
datasetQuote
,
WorkflowIOValueTypeEnum
.
selectDataset
].
includes
(
type
)
[
WorkflowIOValueTypeEnum
.
datasetQuote
,
WorkflowIOValueTypeEnum
.
selectDataset
,
WorkflowIOValueTypeEnum
.
selectApp
].
includes
(
type
)
)
{
)
{
if
(
isObjectString
(
value
))
{
if
(
isObjectString
(
value
))
{
try
{
try
{
return
json5
.
parse
(
value
);
return
json5
.
parse
(
value
);
}
catch
(
error
)
{
}
catch
(
error
)
{}
return
[];
}
}
}
return
[];
return
[];
}
}
if
(
[
WorkflowIOValueTypeEnum
.
selectApp
,
WorkflowIOValueTypeEnum
.
object
].
includes
(
type
)
&&
// Invalid history type
typeof
value
===
'string'
if
(
type
===
WorkflowIOValueTypeEnum
.
chatHistory
)
{
)
{
if
(
isObjectString
(
value
))
{
if
(
isObjectString
(
value
))
{
try
{
try
{
return
json5
.
parse
(
value
);
return
json5
.
parse
(
value
);
}
catch
(
error
)
{
}
catch
(
error
)
{}
return
{};
}
}
}
return
{};
return
[];
}
// Invalid history type
if
(
type
===
WorkflowIOValueTypeEnum
.
chatHistory
)
{
return
0
;
}
}
// 5. 默认返回原值
// 5. 默认返回原值
...
...
packages/service/core/workflow/dispatch/tools/runUpdateVar.ts
View file @
593c816c
...
@@ -58,6 +58,7 @@ export const dispatchUpdateVariable = async (props: Props): Promise<Response> =>
...
@@ -58,6 +58,7 @@ export const dispatchUpdateVariable = async (props: Props): Promise<Response> =>
variables
variables
})
})
:
item
.
value
?.[
1
];
:
item
.
value
?.[
1
];
return
valueTypeFormat
(
val
,
item
.
valueType
);
return
valueTypeFormat
(
val
,
item
.
valueType
);
}
else
{
}
else
{
return
getReferenceVariableValue
({
return
getReferenceVariableValue
({
...
...
packages/web/components/common/Textarea/PromptEditor/index.tsx
View file @
593c816c
...
@@ -97,7 +97,13 @@ const PromptEditor = ({
...
@@ -97,7 +97,13 @@ const PromptEditor = ({
/>
/>
)
}
)
}
</
Box
>
</
Box
>
<
MyModal
isOpen=
{
isOpen
}
onClose=
{
onClose
}
iconSrc=
"modal/edit"
title=
{
title
}
w=
{
'full'
}
>
<
MyModal
isOpen=
{
isOpen
}
onClose=
{
onClose
}
iconSrc=
"modal/edit"
title=
{
title
||
t
(
'common:Edit'
)
}
w=
{
'full'
}
>
<
ModalBody
>
<
ModalBody
>
<
Editor
<
Editor
minH=
{
400
}
minH=
{
400
}
...
...
test/cases/service/core/app/workflow/dispatch/utils.test.ts
View file @
593c816c
...
@@ -48,7 +48,7 @@ describe('valueTypeFormat', () => {
...
@@ -48,7 +48,7 @@ describe('valueTypeFormat', () => {
{
{
value
:
'false'
,
value
:
'false'
,
type
:
WorkflowIOValueTypeEnum
.
selectApp
,
type
:
WorkflowIOValueTypeEnum
.
selectApp
,
result
:
{}
result
:
[]
},
},
{
{
value
:
'false'
,
value
:
'false'
,
...
@@ -171,7 +171,7 @@ describe('valueTypeFormat', () => {
...
@@ -171,7 +171,7 @@ describe('valueTypeFormat', () => {
{
{
value
:
true
,
value
:
true
,
type
:
WorkflowIOValueTypeEnum
.
object
,
type
:
WorkflowIOValueTypeEnum
.
object
,
result
:
true
result
:
{}
}
}
];
];
boolTestList
.
forEach
((
item
,
index
)
=>
{
boolTestList
.
forEach
((
item
,
index
)
=>
{
...
@@ -263,7 +263,7 @@ describe('valueTypeFormat', () => {
...
@@ -263,7 +263,7 @@ describe('valueTypeFormat', () => {
{
{
value
:
'1'
,
value
:
'1'
,
type
:
WorkflowIOValueTypeEnum
.
chatHistory
,
type
:
WorkflowIOValueTypeEnum
.
chatHistory
,
result
:
0
result
:
[]
}
}
];
];
chatHistoryTestList
.
forEach
((
item
,
index
)
=>
{
chatHistoryTestList
.
forEach
((
item
,
index
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment