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
e933dacb
authored
Jan 13, 2025
by
heheer
Committed by
GitHub
Jan 13, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
curl create plugin with inputs (#3573)
parent
cdf4f0e6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
18 deletions
+86
-18
packages/global/common/string/http.ts
+7
-1
projects/app/src/web/core/app/templates.ts
+79
-17
No files found.
packages/global/common/string/http.ts
View file @
e933dacb
...
@@ -27,12 +27,18 @@ export const parseCurl = (curlContent: string) => {
...
@@ -27,12 +27,18 @@ export const parseCurl = (curlContent: string) => {
type
:
'string'
type
:
'string'
}));
}));
const
newBody
=
JSON
.
stringify
(
parsed
.
data
,
null
,
2
);
const
newBody
=
JSON
.
stringify
(
parsed
.
data
,
null
,
2
);
const
bodyArray
=
Object
.
keys
(
parsed
.
data
||
{}).
map
((
key
)
=>
({
key
,
value
:
parsed
.
data
?.[
key
],
type
:
'string'
}));
return
{
return
{
url
:
parsed
.
url
,
url
:
parsed
.
url
,
method
:
methodMap
[
parsed
.
method
?.
toLowerCase
()
as
RequestMethod
]
||
'GET'
,
method
:
methodMap
[
parsed
.
method
?.
toLowerCase
()
as
RequestMethod
]
||
'GET'
,
params
:
newParams
,
params
:
newParams
,
headers
:
newHeaders
,
headers
:
newHeaders
,
body
:
newBody
body
:
newBody
,
bodyArray
};
};
};
};
projects/app/src/web/core/app/templates.ts
View file @
e933dacb
...
@@ -417,35 +417,82 @@ export const parsePluginFromCurlString = (
...
@@ -417,35 +417,82 @@ export const parsePluginFromCurlString = (
edges
:
AppSchema
[
'edges'
];
edges
:
AppSchema
[
'edges'
];
chatConfig
:
AppSchema
[
'chatConfig'
];
chatConfig
:
AppSchema
[
'chatConfig'
];
}
=>
{
}
=>
{
const
{
url
,
method
,
headers
,
body
}
=
parseCurl
(
curl
);
const
{
url
,
method
,
headers
,
body
,
params
,
bodyArray
}
=
parseCurl
(
curl
);
const
allInputs
=
Array
.
from
(
new
Map
([...
headers
,
...
params
,
...
bodyArray
].
map
((
item
)
=>
[
item
.
key
,
item
])).
values
()
);
const
formatInputs
=
allInputs
.
map
((
item
)
=>
{
const
valueType
=
item
.
value
===
null
?
'string'
:
typeof
item
.
value
;
return
{
renderTypeList
:
[
'reference'
],
selectedTypeIndex
:
0
,
valueType
,
canEdit
:
true
,
key
:
item
.
key
,
label
:
item
.
key
,
description
:
item
.
key
,
defaultValue
:
''
,
required
:
false
,
toolDescription
:
[
'string'
,
'number'
,
'boolean'
].
includes
(
valueType
)
?
item
.
key
:
''
};
});
const
formatOutputs
=
formatInputs
.
map
((
item
)
=>
({
id
:
item
.
key
,
key
:
item
.
key
,
label
:
item
.
key
,
valueType
:
item
.
valueType
,
type
:
'hidden'
}));
const
referenceHeaders
=
headers
.
map
((
item
)
=>
({
key
:
item
.
key
,
value
:
`{{$pluginInput.
${
item
.
key
}
$}}`
,
type
:
item
.
type
}));
const
referenceParams
=
params
.
map
((
item
)
=>
({
key
:
item
.
key
,
value
:
`{{$pluginInput.
${
item
.
key
}
$}}`
,
type
:
item
.
type
}));
const
referenceBody
=
Object
.
entries
(
JSON
.
parse
(
body
)).
reduce
(
(
acc
,
[
key
,
value
])
=>
{
acc
[
key
]
=
`{{$pluginInput.
${
key
}
$}}`
;
return
acc
;
},
{}
as
Record
<
string
,
any
>
);
const
referenceBodyStr
=
JSON
.
stringify
(
referenceBody
,
null
,
2
)
.
replace
(
/"{{
\$
/g
,
'{{$'
)
.
replace
(
/
\$
}}"/g
,
'$}}'
);
return
{
return
{
nodes
:
[
nodes
:
[
{
{
nodeId
:
'pluginInput'
,
nodeId
:
'pluginInput'
,
name
:
'workflow:template.plugin_start'
,
name
:
i18nT
(
'workflow:template.plugin_start'
)
,
intro
:
'workflow:intro_plugin_input'
,
intro
:
i18nT
(
'workflow:intro_plugin_input'
)
,
avatar
:
'core/workflow/template/workflowStart'
,
avatar
:
'core/workflow/template/workflowStart'
,
flowNodeType
:
'pluginInput'
,
flowNodeType
:
'pluginInput'
,
showStatus
:
false
,
showStatus
:
false
,
position
:
{
position
:
{
x
:
630.1191328382079
,
x
:
427.6554681270263
,
y
:
-
125.05298493910118
y
:
-
291.6987155252725
},
},
version
:
'481'
,
version
:
'481'
,
inputs
:
[]
,
inputs
:
formatInputs
,
outputs
:
[]
outputs
:
formatOutputs
},
},
{
{
nodeId
:
'pluginOutput'
,
nodeId
:
'pluginOutput'
,
name
:
'common:core.module.template.self_output'
,
name
:
i18nT
(
'common:core.module.template.self_output'
)
,
intro
:
'workflow:intro_custom_plugin_output'
,
intro
:
i18nT
(
'workflow:intro_custom_plugin_output'
)
,
avatar
:
'core/workflow/template/pluginOutput'
,
avatar
:
'core/workflow/template/pluginOutput'
,
flowNodeType
:
'pluginOutput'
,
flowNodeType
:
'pluginOutput'
,
showStatus
:
false
,
showStatus
:
false
,
position
:
{
position
:
{
x
:
1
776.334576378706
,
x
:
1
870.1072210870427
,
y
:
-
1
79.2671413906911
y
:
-
1
26.69871552527252
},
},
version
:
'481'
,
version
:
'481'
,
inputs
:
[
inputs
:
[
...
@@ -455,7 +502,7 @@ export const parsePluginFromCurlString = (
...
@@ -455,7 +502,7 @@ export const parsePluginFromCurlString = (
canEdit
:
true
,
canEdit
:
true
,
key
:
'result'
,
key
:
'result'
,
label
:
'result'
,
label
:
'result'
,
isToolOutput
:
fals
e
,
isToolOutput
:
tru
e
,
description
:
''
,
description
:
''
,
required
:
true
,
required
:
true
,
value
:
[
'vumlECDQTjeC'
,
'httpRawResponse'
]
value
:
[
'vumlECDQTjeC'
,
'httpRawResponse'
]
...
@@ -466,7 +513,7 @@ export const parsePluginFromCurlString = (
...
@@ -466,7 +513,7 @@ export const parsePluginFromCurlString = (
canEdit
:
true
,
canEdit
:
true
,
key
:
'error'
,
key
:
'error'
,
label
:
'error'
,
label
:
'error'
,
isToolOutput
:
fals
e
,
isToolOutput
:
tru
e
,
description
:
''
,
description
:
''
,
required
:
true
,
required
:
true
,
value
:
[
'vumlECDQTjeC'
,
'error'
]
value
:
[
'vumlECDQTjeC'
,
'error'
]
...
@@ -482,8 +529,8 @@ export const parsePluginFromCurlString = (
...
@@ -482,8 +529,8 @@ export const parsePluginFromCurlString = (
flowNodeType
:
'httpRequest468'
,
flowNodeType
:
'httpRequest468'
,
showStatus
:
true
,
showStatus
:
true
,
position
:
{
position
:
{
x
:
10
68.622669500162
8
,
x
:
10
49.441901264366
8
,
y
:
-
4
35.2671413906911
y
:
-
4
71.49748139163944
},
},
version
:
'481'
,
version
:
'481'
,
inputs
:
[
inputs
:
[
...
@@ -563,7 +610,7 @@ export const parsePluginFromCurlString = (
...
@@ -563,7 +610,7 @@ export const parsePluginFromCurlString = (
key
:
'system_httpHeader'
,
key
:
'system_httpHeader'
,
renderTypeList
:
[
'custom'
],
renderTypeList
:
[
'custom'
],
valueType
:
'any'
,
valueType
:
'any'
,
value
:
h
eaders
,
value
:
referenceH
eaders
,
label
:
''
,
label
:
''
,
description
:
description
:
'自定义请求头,请严格填入 JSON 字符串。\n1. 确保最后一个属性没有逗号\n2. 确保 key 包含双引号\n例如:{"Authorization":"Bearer xxx"}'
,
'自定义请求头,请严格填入 JSON 字符串。\n1. 确保最后一个属性没有逗号\n2. 确保 key 包含双引号\n例如:{"Authorization":"Bearer xxx"}'
,
...
@@ -577,6 +624,7 @@ export const parsePluginFromCurlString = (
...
@@ -577,6 +624,7 @@ export const parsePluginFromCurlString = (
key
:
'system_httpParams'
,
key
:
'system_httpParams'
,
renderTypeList
:
[
'hidden'
],
renderTypeList
:
[
'hidden'
],
valueType
:
'any'
,
valueType
:
'any'
,
value
:
referenceParams
,
description
:
description
:
'新的 HTTP 请求地址。如果出现两个“请求地址”,可以删除该模块重新加入,会拉取最新的模块配置。'
,
'新的 HTTP 请求地址。如果出现两个“请求地址”,可以删除该模块重新加入,会拉取最新的模块配置。'
,
label
:
''
,
label
:
''
,
...
@@ -590,7 +638,7 @@ export const parsePluginFromCurlString = (
...
@@ -590,7 +638,7 @@ export const parsePluginFromCurlString = (
key
:
'system_httpJsonBody'
,
key
:
'system_httpJsonBody'
,
renderTypeList
:
[
'hidden'
],
renderTypeList
:
[
'hidden'
],
valueType
:
'any'
,
valueType
:
'any'
,
value
:
body
,
value
:
referenceBodyStr
,
label
:
''
,
label
:
''
,
required
:
false
,
required
:
false
,
valueDesc
:
''
,
valueDesc
:
''
,
...
@@ -674,6 +722,20 @@ export const parsePluginFromCurlString = (
...
@@ -674,6 +722,20 @@ export const parsePluginFromCurlString = (
valueDesc
:
''
valueDesc
:
''
}
}
]
]
},
{
nodeId
:
'pluginConfig'
,
name
:
i18nT
(
'common:core.module.template.system_config'
),
intro
:
''
,
avatar
:
'core/workflow/template/systemConfig'
,
flowNodeType
:
FlowNodeTypeEnum
.
pluginConfig
,
position
:
{
x
:
-
88.12977161770735
,
y
:
-
235.2337531748973
},
version
:
'4811'
,
inputs
:
[],
outputs
:
[]
}
}
],
],
edges
:
[
edges
:
[
...
...
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