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
db1c27cd
authored
May 06, 2024
by
Archer
Committed by
GitHub
May 06, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: adapt v1 system plugin (#1366)
parent
88633376
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
1511 additions
and
22 deletions
+1511
-22
packages/service/core/plugin/type.d.ts
+1
-0
packages/service/core/workflow/dispatchV1/index.ts
+2
-2
packages/service/core/workflow/dispatchV1/plugin/run.ts
+50
-4
packages/service/core/workflow/dispatchV1/tools/answer.ts
+1
-1
projects/app/data/pluginTemplates/customFeedback.json
+1
-1
projects/app/data/pluginTemplates/textEditor.json
+1
-1
projects/app/data/pluginTemplates/v1/customFeedback.json
+342
-0
projects/app/data/pluginTemplates/v1/getCurrentTime.json
+195
-0
projects/app/data/pluginTemplates/v1/textEditor.json
+331
-0
projects/app/data/pluginTemplates/v1/tfSwitch.json
+369
-0
projects/app/src/pages/api/common/system/getInitData.ts
+30
-1
projects/app/src/pages/api/plugins/TFSwitch/index.ts
+72
-0
projects/app/src/pages/api/plugins/customFeedback/index.ts
+22
-9
projects/app/src/pages/api/plugins/customFeedback/v2/index.ts
+46
-0
projects/app/src/pages/api/plugins/textEditor/index.ts
+6
-3
projects/app/src/pages/api/plugins/textEditor/v2/index.ts
+42
-0
No files found.
packages/service/core/plugin/type.d.ts
View file @
db1c27cd
import
{
PluginTemplateType
}
from
'@fastgpt/global/core/plugin/type.d'
;
declare
global
{
var
communityPluginsV1
:
PluginTemplateType
[];
var
communityPlugins
:
PluginTemplateType
[];
}
packages/service/core/workflow/dispatchV1/index.ts
View file @
db1c27cd
...
...
@@ -279,7 +279,7 @@ export async function dispatchWorkFlowV1({
)?.
targets
?.
length
;
return
moduleOutput
(
module
,
{
[
NodeOutputKeyEnum
.
finish
]
:
true
,
finish
:
true
,
[
NodeOutputKeyEnum
.
userChatInput
]:
hasUserChatInputTarget
?
params
[
NodeOutputKeyEnum
.
userChatInput
]
:
undefined
,
...
...
@@ -295,7 +295,7 @@ export async function dispatchWorkFlowV1({
modules
.
forEach
((
item
)
=>
{
item
.
isEntry
=
false
;
});
// console.log(JSON.stringify(runningModules, null, 2));
initModules
.
map
((
module
)
=>
moduleInput
(
module
,
{
...
startParams
,
...
...
packages/service/core/workflow/dispatchV1/plugin/run.ts
View file @
db1c27cd
// @ts-nocheck
import
type
{
ModuleDispatchProps
}
from
'@fastgpt/global/core/workflow/type'
;
import
{
dispatchWorkFlowV1
}
from
'../index'
;
import
{
FlowNodeTypeEnum
}
from
'@fastgpt/global/core/workflow/node/constant'
;
import
{
NodeInputKeyEnum
}
from
'@fastgpt/global/core/workflow/constants'
;
import
{
FlowNodeTemplateTypeEnum
,
NodeInputKeyEnum
}
from
'@fastgpt/global/core/workflow/constants'
;
import
{
DispatchNodeResponseKeyEnum
}
from
'@fastgpt/global/core/workflow/runtime/constants'
;
import
{
getPluginRuntimeBy
Id
}
from
'../../../plugin/controller'
;
import
{
splitCombinePlugin
Id
}
from
'../../../plugin/controller'
;
import
{
authPluginCanUse
}
from
'../../../../support/permission/auth/plugin'
;
import
{
setEntryEntries
,
DYNAMIC_INPUT_KEY
}
from
'../utils'
;
import
{
DispatchNodeResultType
}
from
'@fastgpt/global/core/workflow/runtime/type'
;
import
{
PluginRuntimeType
,
PluginTemplateType
}
from
'@fastgpt/global/core/plugin/type'
;
import
{
PluginSourceEnum
}
from
'@fastgpt/global/core/plugin/constants'
;
import
{
MongoPlugin
}
from
'../../../plugin/schema'
;
type
RunPluginProps
=
ModuleDispatchProps
<
{
[
NodeInputKeyEnum
.
pluginId
]:
string
;
...
...
@@ -15,6 +22,45 @@ type RunPluginProps = ModuleDispatchProps<{
}
>
;
type
RunPluginResponse
=
DispatchNodeResultType
<
{}
>
;
const
getPluginTemplateById
=
async
(
id
:
string
):
Promise
<
PluginTemplateType
>
=>
{
const
{
source
,
pluginId
}
=
await
splitCombinePluginId
(
id
);
if
(
source
===
PluginSourceEnum
.
community
)
{
const
item
=
global
.
communityPluginsV1
?.
find
((
plugin
)
=>
plugin
.
id
===
pluginId
);
if
(
!
item
)
return
Promise
.
reject
(
'plugin not found'
);
return
item
;
}
if
(
source
===
PluginSourceEnum
.
personal
)
{
const
item
=
await
MongoPlugin
.
findById
(
id
).
lean
();
if
(
!
item
)
return
Promise
.
reject
(
'plugin not found'
);
return
{
id
:
String
(
item
.
_id
),
teamId
:
String
(
item
.
teamId
),
name
:
item
.
name
,
avatar
:
item
.
avatar
,
intro
:
item
.
intro
,
showStatus
:
true
,
source
:
PluginSourceEnum
.
personal
,
modules
:
item
.
modules
,
templateType
:
FlowNodeTemplateTypeEnum
.
personalPlugin
};
}
return
Promise
.
reject
(
'plugin not found'
);
};
const
getPluginRuntimeById
=
async
(
id
:
string
):
Promise
<
PluginRuntimeType
>
=>
{
const
plugin
=
await
getPluginTemplateById
(
id
);
return
{
teamId
:
plugin
.
teamId
,
name
:
plugin
.
name
,
avatar
:
plugin
.
avatar
,
showStatus
:
plugin
.
showStatus
,
modules
:
plugin
.
modules
};
};
export
const
dispatchRunPlugin
=
async
(
props
:
RunPluginProps
):
Promise
<
RunPluginResponse
>
=>
{
const
{
mode
,
...
...
@@ -31,7 +77,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
const
plugin
=
await
getPluginRuntimeById
(
pluginId
);
// concat dynamic inputs
const
inputModule
=
plugin
.
nod
es
.
find
((
item
)
=>
item
.
flowType
===
FlowNodeTypeEnum
.
pluginInput
);
const
inputModule
=
plugin
.
modul
es
.
find
((
item
)
=>
item
.
flowType
===
FlowNodeTypeEnum
.
pluginInput
);
if
(
!
inputModule
)
return
Promise
.
reject
(
'Plugin error, It has no set input.'
);
const
hasDynamicInput
=
inputModule
.
inputs
.
find
((
input
)
=>
input
.
key
===
DYNAMIC_INPUT_KEY
);
...
...
@@ -56,7 +102,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
const
{
flowResponses
,
flowUsages
,
assistantResponses
}
=
await
dispatchWorkFlowV1
({
...
props
,
modules
:
setEntryEntries
(
plugin
.
nod
es
).
map
((
module
)
=>
({
modules
:
setEntryEntries
(
plugin
.
modul
es
).
map
((
module
)
=>
({
...
module
,
showStatus
:
false
})),
...
...
packages/service/core/workflow/dispatchV1/tools/answer.ts
View file @
db1c27cd
...
...
@@ -32,6 +32,6 @@ export const dispatchAnswer = (props: Record<string, any>): AnswerResponse => {
}
return
{
[
NodeOutputKeyEnum
.
answerText
]:
formatText
[
NodeOutputKeyEnum
.
answerText
]:
`\n
${
formatText
}
`
};
};
projects/app/data/pluginTemplates/customFeedback.json
View file @
db1c27cd
...
...
@@ -142,7 +142,7 @@
"description"
:
"core.module.input.description.Http Request Url"
,
"placeholder"
:
"https://api.ai.com/getInventory"
,
"required"
:
false
,
"value"
:
"/api/plugins/customFeedback"
"value"
:
"/api/plugins/customFeedback
/v2
"
},
{
"key"
:
"system_httpHeader"
,
...
...
projects/app/data/pluginTemplates/textEditor.json
View file @
db1c27cd
...
...
@@ -167,7 +167,7 @@
"description"
:
"core.module.input.description.Http Request Url"
,
"placeholder"
:
"https://api.ai.com/getInventory"
,
"required"
:
false
,
"value"
:
"/api/plugins/textEditor"
"value"
:
"/api/plugins/textEditor
/v2
"
},
{
"key"
:
"system_httpHeader"
,
...
...
projects/app/data/pluginTemplates/v1/customFeedback.json
0 → 100644
View file @
db1c27cd
{
"author"
:
"FastGPT Team"
,
"templateType"
:
"other"
,
"name"
:
"自定义反馈"
,
"avatar"
:
"/imgs/module/customFeedback.svg"
,
"intro"
:
"该模块被触发时,会给当前的对话记录增加一条反馈。可用于自动记录对话效果等。"
,
"showStatus"
:
false
,
"isTool"
:
false
,
"weight"
:
0
,
"modules"
:
[
{
"moduleId"
:
"w90mfp"
,
"name"
:
"定义插件输入"
,
"flowType"
:
"pluginInput"
,
"showStatus"
:
false
,
"position"
:
{
"x"
:
515.1887815471657
,
"y"
:
-169.04905809653783
},
"inputs"
:
[
{
"key"
:
"defaultFeedback"
,
"valueType"
:
"string"
,
"label"
:
"默认反馈内容"
,
"type"
:
"textarea"
,
"required"
:
false
,
"description"
:
""
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
,
"inputType"
:
true
},
"connected"
:
true
},
{
"key"
:
"customFeedback"
,
"valueType"
:
"string"
,
"label"
:
"自定义反馈内容"
,
"type"
:
"target"
,
"required"
:
false
,
"description"
:
""
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
,
"inputType"
:
true
},
"connected"
:
true
}
],
"outputs"
:
[
{
"key"
:
"defaultFeedback"
,
"valueType"
:
"string"
,
"label"
:
"默认反馈内容"
,
"type"
:
"source"
,
"edit"
:
true
,
"targets"
:
[
{
"moduleId"
:
"49de3g"
,
"key"
:
"defaultFeedback"
}
]
},
{
"key"
:
"customFeedback"
,
"valueType"
:
"string"
,
"label"
:
"自定义反馈内容"
,
"type"
:
"source"
,
"edit"
:
true
,
"targets"
:
[
{
"moduleId"
:
"49de3g"
,
"key"
:
"customFeedback"
}
]
}
]
},
{
"moduleId"
:
"49de3g"
,
"name"
:
"HTTP模块"
,
"flowType"
:
"httpRequest468"
,
"showStatus"
:
true
,
"position"
:
{
"x"
:
1086.8929621216014
,
"y"
:
-451.7550009773506
},
"inputs"
:
[
{
"key"
:
"switch"
,
"type"
:
"target"
,
"label"
:
"core.module.input.label.switch"
,
"description"
:
"core.module.input.description.Trigger"
,
"valueType"
:
"any"
,
"showTargetInApp"
:
true
,
"showTargetInPlugin"
:
true
,
"connected"
:
false
},
{
"key"
:
"system_httpMethod"
,
"type"
:
"custom"
,
"valueType"
:
"string"
,
"label"
:
""
,
"value"
:
"POST"
,
"list"
:
[
{
"label"
:
"GET"
,
"value"
:
"GET"
},
{
"label"
:
"POST"
,
"value"
:
"POST"
}
],
"required"
:
true
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"connected"
:
false
},
{
"key"
:
"system_httpReqUrl"
,
"type"
:
"hidden"
,
"valueType"
:
"string"
,
"label"
:
""
,
"description"
:
"core.module.input.description.Http Request Url"
,
"placeholder"
:
"https://api.ai.com/getInventory"
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"value"
:
"/api/plugins/customFeedback"
,
"connected"
:
false
},
{
"key"
:
"system_httpHeader"
,
"type"
:
"custom"
,
"valueType"
:
"any"
,
"value"
:
""
,
"label"
:
""
,
"description"
:
"core.module.input.description.Http Request Header"
,
"placeholder"
:
"core.module.input.description.Http Request Header"
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"connected"
:
false
},
{
"key"
:
"system_httpParams"
,
"type"
:
"hidden"
,
"valueType"
:
"any"
,
"value"
:
[],
"label"
:
""
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"connected"
:
false
},
{
"key"
:
"system_httpJsonBody"
,
"type"
:
"hidden"
,
"valueType"
:
"any"
,
"value"
:
"{
\r\n
\"
appId
\"
:
\"
{{appId}}
\"
,
\r\n
\"
chatId
\"
:
\"
{{chatId}}
\"
,
\r\n
\"
responseChatItemId
\"
:
\"
{{responseChatItemId}}
\"
,
\r\n
\"
defaultFeedback
\"
:
\"
{{defaultFeedback}}
\"
,
\r\n
\"
customFeedback
\"
:
\"
{{customFeedback}}
\"\r\n
}"
,
"label"
:
""
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"connected"
:
false
},
{
"key"
:
"DYNAMIC_INPUT_KEY"
,
"type"
:
"target"
,
"valueType"
:
"any"
,
"label"
:
"core.module.inputType.dynamicTargetInput"
,
"description"
:
"core.module.input.description.dynamic input"
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
true
,
"hideInApp"
:
true
,
"connected"
:
false
},
{
"valueType"
:
"string"
,
"label"
:
"defaultFeedback"
,
"type"
:
"target"
,
"required"
:
true
,
"description"
:
""
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
},
"connected"
:
true
,
"key"
:
"defaultFeedback"
},
{
"key"
:
"customFeedback"
,
"valueType"
:
"string"
,
"label"
:
"customFeedback"
,
"type"
:
"target"
,
"required"
:
true
,
"description"
:
""
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
},
"connected"
:
true
},
{
"key"
:
"system_addInputParam"
,
"type"
:
"addInputParam"
,
"valueType"
:
"any"
,
"label"
:
""
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
},
"defaultEditField"
:
{
"label"
:
""
,
"key"
:
""
,
"description"
:
""
,
"inputType"
:
"target"
,
"valueType"
:
"string"
,
"required"
:
true
},
"connected"
:
false
}
],
"outputs"
:
[
{
"key"
:
"finish"
,
"label"
:
"core.module.output.label.running done"
,
"description"
:
"core.module.output.description.running done"
,
"valueType"
:
"boolean"
,
"type"
:
"hidden"
,
"targets"
:
[]
},
{
"key"
:
"system_addOutputParam"
,
"type"
:
"addOutputParam"
,
"valueType"
:
"any"
,
"label"
:
""
,
"targets"
:
[],
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"dataType"
:
true
},
"defaultEditField"
:
{
"label"
:
""
,
"key"
:
""
,
"description"
:
""
,
"outputType"
:
"source"
,
"valueType"
:
"string"
}
},
{
"type"
:
"source"
,
"valueType"
:
"string"
,
"label"
:
"response"
,
"description"
:
""
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"dataType"
:
true
},
"targets"
:
[
{
"moduleId"
:
"s15f3v"
,
"key"
:
"text"
}
],
"key"
:
"response"
}
]
},
{
"moduleId"
:
"s15f3v"
,
"name"
:
"指定回复"
,
"flowType"
:
"answerNode"
,
"position"
:
{
"x"
:
1705.6337348182756
,
"y"
:
-37.53826066726282
},
"inputs"
:
[
{
"key"
:
"switch"
,
"type"
:
"target"
,
"label"
:
"core.module.input.label.switch"
,
"description"
:
"core.module.input.description.Trigger"
,
"valueType"
:
"any"
,
"showTargetInApp"
:
true
,
"showTargetInPlugin"
:
true
,
"connected"
:
false
},
{
"key"
:
"text"
,
"type"
:
"textarea"
,
"valueType"
:
"any"
,
"label"
:
"core.module.input.label.Response content"
,
"description"
:
"core.module.input.description.Response content"
,
"placeholder"
:
"core.module.input.description.Response content"
,
"showTargetInApp"
:
true
,
"showTargetInPlugin"
:
true
,
"connected"
:
true
}
],
"outputs"
:
[
{
"key"
:
"finish"
,
"label"
:
"core.module.output.label.running done"
,
"description"
:
"core.module.output.description.running done"
,
"valueType"
:
"boolean"
,
"type"
:
"hidden"
,
"targets"
:
[]
}
]
}
]
}
projects/app/data/pluginTemplates/v1/getCurrentTime.json
0 → 100644
View file @
db1c27cd
{
"author"
:
"FastGPT Team"
,
"templateType"
:
"tools"
,
"name"
:
"获取当前时间"
,
"avatar"
:
"/imgs/module/getCurrentTime.svg"
,
"intro"
:
"获取用户当前时区的时间。"
,
"showStatus"
:
false
,
"isTool"
:
true
,
"weight"
:
10
,
"modules"
:
[
{
"moduleId"
:
"m8dupj"
,
"name"
:
"定义插件输入"
,
"intro"
:
"自定义配置外部输入,使用插件时,仅暴露自定义配置的输入"
,
"avatar"
:
"/imgs/module/input.png"
,
"flowType"
:
"pluginInput"
,
"showStatus"
:
false
,
"position"
:
{
"x"
:
187.94161749205568
,
"y"
:
179.78772129776746
},
"inputs"
:
[
{
"key"
:
"pluginStart"
,
"type"
:
"hidden"
,
"valueType"
:
"boolean"
,
"label"
:
"插件开始运行"
,
"description"
:
"插件开始运行时,会输出一个 True 的标识。有时候,插件不会有额外的的输入,为了顺利的进入下一个阶段,你可以将该值连接到下一个节点的触发器中。"
,
"showTargetInApp"
:
true
,
"showTargetInPlugin"
:
true
,
"connected"
:
true
}
],
"outputs"
:
[
{
"key"
:
"pluginStart"
,
"label"
:
"插件开始运行"
,
"type"
:
"source"
,
"valueType"
:
"boolean"
,
"targets"
:
[
{
"moduleId"
:
"cv13yt"
,
"key"
:
"switch"
}
]
}
]
},
{
"moduleId"
:
"bjsa7r"
,
"name"
:
"定义插件输出"
,
"intro"
:
"自定义配置外部输出,使用插件时,仅暴露自定义配置的输出"
,
"avatar"
:
"/imgs/module/output.png"
,
"flowType"
:
"pluginOutput"
,
"showStatus"
:
false
,
"position"
:
{
"x"
:
1176.9471084832217
,
"y"
:
138.94098316727695
},
"inputs"
:
[
{
"key"
:
"time"
,
"valueType"
:
"string"
,
"label"
:
"time"
,
"type"
:
"target"
,
"required"
:
true
,
"description"
:
""
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
false
,
"dataType"
:
true
,
"inputType"
:
false
},
"connected"
:
true
}
],
"outputs"
:
[
{
"key"
:
"time"
,
"valueType"
:
"string"
,
"label"
:
"time"
,
"type"
:
"source"
,
"edit"
:
true
,
"targets"
:
[]
}
]
},
{
"moduleId"
:
"cv13yt"
,
"name"
:
"文本加工"
,
"intro"
:
"可对固定或传入的文本进行加工后输出,非字符串类型数据最终会转成字符串类型。"
,
"avatar"
:
"/imgs/module/textEditor.svg"
,
"flowType"
:
"pluginModule"
,
"showStatus"
:
false
,
"position"
:
{
"x"
:
600.7190079155914
,
"y"
:
1.4754510232677944
},
"inputs"
:
[
{
"key"
:
"pluginId"
,
"type"
:
"hidden"
,
"label"
:
""
,
"value"
:
"community-textEditor"
,
"valueType"
:
"string"
,
"connected"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
},
{
"key"
:
"switch"
,
"type"
:
"triggerAndFinish"
,
"label"
:
""
,
"description"
:
"core.module.input.description.Trigger"
,
"valueType"
:
"any"
,
"showTargetInApp"
:
true
,
"showTargetInPlugin"
:
true
,
"connected"
:
true
},
{
"key"
:
"textarea"
,
"valueType"
:
"string"
,
"label"
:
"文本内容"
,
"type"
:
"textarea"
,
"required"
:
true
,
"description"
:
"可以通过 {{key}} 的方式引用传入的变量。变量仅支持字符串或数字。"
,
"edit"
:
false
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
,
"inputType"
:
true
},
"connected"
:
false
,
"placeholder"
:
"可以通过 {{key}} 的方式引用传入的变量。变量仅支持字符串或数字。"
,
"value"
:
"{{cTime}}"
},
{
"key"
:
"DYNAMIC_INPUT_KEY"
,
"valueType"
:
"any"
,
"label"
:
"需要加工的输入"
,
"type"
:
"addInputParam"
,
"required"
:
false
,
"description"
:
"可动态的添加字符串类型变量,在文本编辑中通过 {{key}} 使用变量。非字符串类型,会自动转成字符串类型。"
,
"edit"
:
false
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
,
"inputType"
:
false
},
"defaultEditField"
:
{
"label"
:
""
,
"key"
:
""
,
"description"
:
""
,
"inputType"
:
"target"
,
"valueType"
:
"string"
,
"required"
:
true
},
"connected"
:
false
}
],
"outputs"
:
[
{
"key"
:
"text"
,
"valueType"
:
"string"
,
"label"
:
"core.module.output.label.text"
,
"type"
:
"source"
,
"edit"
:
false
,
"targets"
:
[
{
"moduleId"
:
"bjsa7r"
,
"key"
:
"time"
}
]
},
{
"key"
:
"finish"
,
"label"
:
""
,
"description"
:
""
,
"valueType"
:
"boolean"
,
"type"
:
"hidden"
,
"targets"
:
[]
}
]
}
]
}
projects/app/data/pluginTemplates/v1/textEditor.json
0 → 100644
View file @
db1c27cd
{
"author"
:
"FastGPT Team"
,
"templateType"
:
"tools"
,
"name"
:
"文本加工"
,
"avatar"
:
"/imgs/module/textEditor.svg"
,
"intro"
:
"可对固定或传入的文本进行加工后输出,非字符串类型数据最终会转成字符串类型。"
,
"showStatus"
:
false
,
"isTool"
:
false
,
"weight"
:
100
,
"modules"
:
[
{
"moduleId"
:
"w90mfp"
,
"name"
:
"定义插件输入"
,
"flowType"
:
"pluginInput"
,
"showStatus"
:
false
,
"position"
:
{
"x"
:
616.4226348688949
,
"y"
:
-165.05298493910115
},
"inputs"
:
[
{
"key"
:
"textarea"
,
"valueType"
:
"string"
,
"label"
:
"文本内容"
,
"type"
:
"textarea"
,
"required"
:
true
,
"description"
:
"可以通过 {{key}} 的方式引用传入的变量。变量仅支持字符串或数字。"
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
,
"inputType"
:
true
},
"connected"
:
true
},
{
"key"
:
"DYNAMIC_INPUT_KEY"
,
"valueType"
:
"any"
,
"label"
:
"需要加工的输入"
,
"type"
:
"addInputParam"
,
"required"
:
false
,
"description"
:
"可动态的添加字符串类型变量,在文本编辑中通过 {{key}} 使用变量。非字符串类型,会自动转成字符串类型。"
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
,
"inputType"
:
false
},
"defaultEditField"
:
{
"label"
:
""
,
"key"
:
""
,
"description"
:
""
,
"inputType"
:
"target"
,
"valueType"
:
"string"
,
"required"
:
true
},
"connected"
:
true
}
],
"outputs"
:
[
{
"key"
:
"textarea"
,
"valueType"
:
"string"
,
"label"
:
"文本内容"
,
"type"
:
"source"
,
"edit"
:
true
,
"targets"
:
[
{
"moduleId"
:
"49de3g"
,
"key"
:
"text"
}
]
},
{
"key"
:
"DYNAMIC_INPUT_KEY"
,
"valueType"
:
"any"
,
"label"
:
"需要加工的输入"
,
"type"
:
"source"
,
"edit"
:
true
,
"targets"
:
[
{
"moduleId"
:
"49de3g"
,
"key"
:
"DYNAMIC_INPUT_KEY"
}
]
}
]
},
{
"moduleId"
:
"tze1ju"
,
"name"
:
"定义插件输出"
,
"flowType"
:
"pluginOutput"
,
"showStatus"
:
false
,
"position"
:
{
"x"
:
1607.7142331269126
,
"y"
:
-145.93201540017395
},
"inputs"
:
[
{
"key"
:
"text"
,
"valueType"
:
"string"
,
"label"
:
"core.module.output.label.text"
,
"type"
:
"target"
,
"required"
:
true
,
"description"
:
""
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
false
,
"dataType"
:
true
,
"inputType"
:
false
},
"connected"
:
true
}
],
"outputs"
:
[
{
"key"
:
"text"
,
"valueType"
:
"string"
,
"label"
:
"core.module.output.label.text"
,
"type"
:
"source"
,
"edit"
:
true
,
"targets"
:
[]
}
]
},
{
"moduleId"
:
"49de3g"
,
"name"
:
"HTTP模块"
,
"flowType"
:
"httpRequest468"
,
"showStatus"
:
true
,
"position"
:
{
"x"
:
1086.8929621216014
,
"y"
:
-451.7550009773506
},
"inputs"
:
[
{
"key"
:
"switch"
,
"type"
:
"target"
,
"label"
:
"core.module.input.label.switch"
,
"description"
:
"core.module.input.description.Trigger"
,
"valueType"
:
"any"
,
"showTargetInApp"
:
true
,
"showTargetInPlugin"
:
true
,
"connected"
:
false
},
{
"key"
:
"system_httpMethod"
,
"type"
:
"custom"
,
"valueType"
:
"string"
,
"label"
:
""
,
"value"
:
"POST"
,
"list"
:
[
{
"label"
:
"GET"
,
"value"
:
"GET"
},
{
"label"
:
"POST"
,
"value"
:
"POST"
}
],
"required"
:
true
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"connected"
:
false
},
{
"key"
:
"system_httpReqUrl"
,
"type"
:
"hidden"
,
"valueType"
:
"string"
,
"label"
:
""
,
"description"
:
"core.module.input.description.Http Request Url"
,
"placeholder"
:
"https://api.ai.com/getInventory"
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"value"
:
"/api/plugins/textEditor"
,
"connected"
:
false
},
{
"key"
:
"system_httpHeader"
,
"type"
:
"custom"
,
"valueType"
:
"any"
,
"value"
:
""
,
"label"
:
""
,
"description"
:
"core.module.input.description.Http Request Header"
,
"placeholder"
:
"core.module.input.description.Http Request Header"
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"connected"
:
false
},
{
"key"
:
"system_httpParams"
,
"type"
:
"hidden"
,
"valueType"
:
"any"
,
"value"
:
[],
"label"
:
""
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"connected"
:
false
},
{
"key"
:
"system_httpJsonBody"
,
"type"
:
"hidden"
,
"valueType"
:
"any"
,
"value"
:
"{
\r\n
\"
text
\"
:
\"
{{text}}
\"\r\n
}"
,
"label"
:
""
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"connected"
:
false
},
{
"key"
:
"DYNAMIC_INPUT_KEY"
,
"type"
:
"target"
,
"valueType"
:
"any"
,
"label"
:
"core.module.inputType.dynamicTargetInput"
,
"description"
:
"core.module.input.description.dynamic input"
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
true
,
"hideInApp"
:
true
,
"connected"
:
true
},
{
"key"
:
"text"
,
"valueType"
:
"string"
,
"label"
:
"text"
,
"type"
:
"target"
,
"required"
:
true
,
"description"
:
""
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
},
"connected"
:
true
},
{
"key"
:
"system_addInputParam"
,
"type"
:
"addInputParam"
,
"valueType"
:
"any"
,
"label"
:
""
,
"required"
:
false
,
"showTargetInApp"
:
false
,
"showTargetInPlugin"
:
false
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"required"
:
true
,
"dataType"
:
true
},
"defaultEditField"
:
{
"label"
:
""
,
"key"
:
""
,
"description"
:
""
,
"inputType"
:
"target"
,
"valueType"
:
"string"
,
"required"
:
true
},
"connected"
:
false
}
],
"outputs"
:
[
{
"key"
:
"finish"
,
"label"
:
"core.module.output.label.running done"
,
"description"
:
"core.module.output.description.running done"
,
"valueType"
:
"boolean"
,
"type"
:
"hidden"
,
"targets"
:
[]
},
{
"key"
:
"system_addOutputParam"
,
"type"
:
"addOutputParam"
,
"valueType"
:
"any"
,
"label"
:
""
,
"targets"
:
[],
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"dataType"
:
true
},
"defaultEditField"
:
{
"label"
:
""
,
"key"
:
""
,
"description"
:
""
,
"outputType"
:
"source"
,
"valueType"
:
"string"
}
},
{
"type"
:
"source"
,
"valueType"
:
"string"
,
"key"
:
"text"
,
"label"
:
"core.module.output.label.text"
,
"description"
:
""
,
"edit"
:
true
,
"editField"
:
{
"key"
:
true
,
"name"
:
true
,
"description"
:
true
,
"dataType"
:
true
},
"targets"
:
[
{
"moduleId"
:
"tze1ju"
,
"key"
:
"text"
}
]
}
]
}
]
}
projects/app/data/pluginTemplates/v1/tfSwitch.json
0 → 100644
View file @
db1c27cd
This diff is collapsed.
Click to expand it.
projects/app/src/pages/api/common/system/getInitData.ts
View file @
db1c27cd
...
...
@@ -63,7 +63,10 @@ export async function getInitConfig() {
initSystemConfig
(),
// getSimpleModeTemplates(),
getSystemVersion
(),
getSystemPlugin
()
getSystemPlugin
(),
// abandon
getSystemPluginV1
()
]);
console
.
log
({
...
...
@@ -164,3 +167,29 @@ function getSystemPlugin() {
global
.
communityPlugins
=
fileTemplates
;
}
function
getSystemPluginV1
()
{
if
(
global
.
communityPluginsV1
&&
global
.
communityPluginsV1
.
length
>
0
)
return
;
const
basePath
=
process
.
env
.
NODE_ENV
===
'development'
?
'data/pluginTemplates/v1'
:
'/app/data/pluginTemplates/v1'
;
// read data/pluginTemplates directory, get all json file
const
files
=
readdirSync
(
basePath
);
// filter json file
const
filterFiles
=
files
.
filter
((
item
)
=>
item
.
endsWith
(
'.json'
));
// read json file
const
fileTemplates
:
(
PluginTemplateType
&
{
weight
:
number
})[]
=
filterFiles
.
map
((
filename
)
=>
{
const
content
=
readFileSync
(
`
${
basePath
}
/
${
filename
}
`
,
'utf-8'
);
return
{
...
JSON
.
parse
(
content
),
id
:
`
${
PluginSourceEnum
.
community
}
-
${
filename
.
replace
(
'.json'
,
''
)}
`
,
source
:
PluginSourceEnum
.
community
};
});
fileTemplates
.
sort
((
a
,
b
)
=>
b
.
weight
-
a
.
weight
);
global
.
communityPluginsV1
=
fileTemplates
;
}
projects/app/src/pages/api/plugins/TFSwitch/index.ts
0 → 100644
View file @
db1c27cd
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
// @ts-ignore
import
type
{
HttpBodyType
}
from
'@fastgpt/global/core/module/api.d'
;
import
{
getErrText
}
from
'@fastgpt/global/common/error/utils'
;
import
{
authRequestFromLocal
}
from
'@fastgpt/service/support/permission/auth/common'
;
type
Props
=
HttpBodyType
<
{
input
:
string
;
rule
?:
string
;
}
>
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
const
{
input
,
rule
=
''
}
=
req
.
body
as
Props
;
await
authRequestFromLocal
({
req
});
const
result
=
(()
=>
{
if
(
typeof
input
===
'string'
)
{
const
defaultReg
:
any
[]
=
[
''
,
undefined
,
'undefined'
,
null
,
'null'
,
false
,
'false'
,
0
,
'0'
,
'none'
];
const
customReg
=
rule
.
split
(
'\n'
);
defaultReg
.
push
(...
customReg
);
return
!
defaultReg
.
find
((
item
)
=>
{
const
reg
=
typeof
item
===
'string'
?
stringToRegex
(
item
)
:
null
;
if
(
reg
)
{
return
reg
.
test
(
input
);
}
return
input
===
item
;
});
}
return
!!
input
;
})();
res
.
json
({
...(
result
?
{
true
:
true
}
:
{
false
:
false
})
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
status
(
500
).
send
(
getErrText
(
err
));
}
}
function
stringToRegex
(
str
:
string
)
{
const
regexFormat
=
/^
\/(
.+
)\/([
gimuy
]
*
)
$/
;
const
match
=
str
.
match
(
regexFormat
);
if
(
match
)
{
const
[,
pattern
,
flags
]
=
match
;
return
new
RegExp
(
pattern
,
flags
);
}
else
{
return
null
;
}
}
projects/app/src/pages/api/plugins/customFeedback/index.ts
View file @
db1c27cd
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
HttpBodyType
}
from
'@fastgpt/global/core/workflow/api.d'
;
//@ts-ignore
import
type
{
HttpBodyType
}
from
'@fastgpt/global/core/module/api.d'
;
import
{
getErrText
}
from
'@fastgpt/global/common/error/utils'
;
import
{
addCustomFeedbacks
}
from
'@fastgpt/service/core/chat/controller'
;
import
{
authRequestFromLocal
}
from
'@fastgpt/service/support/permission/auth/common'
;
import
{
NodeOutputKeyEnum
}
from
'@fastgpt/global/core/workflow/constants'
;
type
Props
=
HttpBodyType
<
{
appId
:
string
;
chatId
?:
string
;
responseChatItemId
?:
string
;
defaultFeedback
:
string
;
customFeedback
:
string
;
}
>
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
const
{
customFeedback
,
system_addInputParam
:
{
appId
,
chatId
,
responseChatItemId
:
chatItemId
}
appId
,
chatId
,
responseChatItemId
:
chatItemId
,
defaultFeedback
,
customFeedback
}
=
req
.
body
as
Props
;
await
authRequestFromLocal
({
req
});
if
(
!
customFeedback
)
{
return
res
.
json
({});
const
feedback
=
customFeedback
||
defaultFeedback
;
if
(
!
feedback
)
{
return
res
.
json
({
response
:
''
});
}
// wait the chat finish
...
...
@@ -28,17 +39,19 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
appId
,
chatId
,
chatItemId
,
feedbacks
:
[
customF
eedback
]
feedbacks
:
[
f
eedback
]
});
},
60000
);
if
(
!
chatId
||
!
chatItemId
)
{
return
res
.
json
({
[
NodeOutputKeyEnum
.
answerText
]:
`\\n\\n**自动反馈调试**: "
${
customFeedback
}
"
\\n\\n`
response
:
`\\n\\n**自动反馈调试**:
${
feedback
}
\\n\\n`
});
}
return
res
.
json
({});
return
res
.
json
({
response
:
''
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
status
(
500
).
send
(
getErrText
(
err
));
...
...
projects/app/src/pages/api/plugins/customFeedback/v2/index.ts
0 → 100644
View file @
db1c27cd
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
HttpBodyType
}
from
'@fastgpt/global/core/workflow/api.d'
;
import
{
getErrText
}
from
'@fastgpt/global/common/error/utils'
;
import
{
addCustomFeedbacks
}
from
'@fastgpt/service/core/chat/controller'
;
import
{
authRequestFromLocal
}
from
'@fastgpt/service/support/permission/auth/common'
;
import
{
NodeInputKeyEnum
,
NodeOutputKeyEnum
}
from
'@fastgpt/global/core/workflow/constants'
;
type
Props
=
HttpBodyType
<
{
customFeedback
:
string
;
}
>
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
const
{
customFeedback
,
[
NodeInputKeyEnum
.
addInputParam
]:
{
appId
,
chatId
,
responseChatItemId
:
chatItemId
}
}
=
req
.
body
as
Props
;
await
authRequestFromLocal
({
req
});
if
(
!
customFeedback
)
{
return
res
.
json
({});
}
// wait the chat finish
setTimeout
(()
=>
{
addCustomFeedbacks
({
appId
,
chatId
,
chatItemId
,
feedbacks
:
[
customFeedback
]
});
},
60000
);
if
(
!
chatId
||
!
chatItemId
)
{
return
res
.
json
({
[
NodeOutputKeyEnum
.
answerText
]:
`\\n\\n**自动反馈调试**: "
${
customFeedback
}
"\\n\\n`
});
}
return
res
.
json
({});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
status
(
500
).
send
(
getErrText
(
err
));
}
}
projects/app/src/pages/api/plugins/textEditor/index.ts
View file @
db1c27cd
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
HttpBodyType
}
from
'@fastgpt/global/core/workflow/api.d'
;
//@ts-ignore
import
type
{
HttpBodyType
}
from
'@fastgpt/global/core/module/api.d'
;
import
{
getErrText
}
from
'@fastgpt/global/common/error/utils'
;
import
{
replaceVariable
}
from
'@fastgpt/global/common/string/tools'
;
import
{
authRequestFromLocal
}
from
'@fastgpt/service/support/permission/auth/common'
;
import
{
NodeInputKeyEnum
}
from
'@fastgpt/global/core/workflow/constants'
;
type
Props
=
HttpBodyType
<
{
text
:
string
;
...
...
@@ -12,7 +12,10 @@ type Props = HttpBodyType<{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
const
{
text
,
[
NodeInputKeyEnum
.
addInputParam
]:
obj
}
=
req
.
body
as
Props
;
const
{
text
,
DYNAMIC_INPUT_KEY
:
{
...
obj
}
}
=
req
.
body
as
Props
;
await
authRequestFromLocal
({
req
});
...
...
projects/app/src/pages/api/plugins/textEditor/v2/index.ts
0 → 100644
View file @
db1c27cd
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
HttpBodyType
}
from
'@fastgpt/global/core/workflow/api.d'
;
import
{
getErrText
}
from
'@fastgpt/global/common/error/utils'
;
import
{
replaceVariable
}
from
'@fastgpt/global/common/string/tools'
;
import
{
authRequestFromLocal
}
from
'@fastgpt/service/support/permission/auth/common'
;
import
{
NodeInputKeyEnum
}
from
'@fastgpt/global/core/workflow/constants'
;
type
Props
=
HttpBodyType
<
{
text
:
string
;
[
key
:
string
]:
any
;
}
>
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
const
{
text
,
[
NodeInputKeyEnum
.
addInputParam
]:
obj
}
=
req
.
body
as
Props
;
await
authRequestFromLocal
({
req
});
// string all value
Object
.
keys
(
obj
).
forEach
((
key
)
=>
{
let
val
=
obj
[
key
];
if
(
typeof
val
===
'object'
)
{
val
=
JSON
.
stringify
(
val
);
}
else
if
(
typeof
val
===
'number'
)
{
val
=
String
(
val
);
}
else
if
(
typeof
val
===
'boolean'
)
{
val
=
val
?
'true'
:
'false'
;
}
obj
[
key
]
=
val
;
});
const
textResult
=
replaceVariable
(
text
,
obj
);
res
.
json
({
text
:
textResult
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
status
(
500
).
send
(
getErrText
(
err
));
}
}
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