feat: custom feedback plugin (#1365)
This commit is contained in:
parent
b500631a4d
commit
d057ba29f0
@ -69,8 +69,14 @@ const callbackMap: Record<`${FlowNodeTypeEnum}`, Function> = {
|
|||||||
[FlowNodeTypeEnum.globalVariable]: () => Promise.resolve()
|
[FlowNodeTypeEnum.globalVariable]: () => Promise.resolve()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type Props = ChatDispatchProps & {
|
||||||
|
runtimeNodes: RuntimeNodeItemType[];
|
||||||
|
runtimeEdges: RuntimeEdgeItemType[];
|
||||||
|
};
|
||||||
|
|
||||||
/* running */
|
/* running */
|
||||||
export async function dispatchWorkFlow({
|
export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowResponse> {
|
||||||
|
let {
|
||||||
res,
|
res,
|
||||||
runtimeNodes = [],
|
runtimeNodes = [],
|
||||||
runtimeEdges = [],
|
runtimeEdges = [],
|
||||||
@ -80,10 +86,8 @@ export async function dispatchWorkFlow({
|
|||||||
stream = false,
|
stream = false,
|
||||||
detail = false,
|
detail = false,
|
||||||
...props
|
...props
|
||||||
}: ChatDispatchProps & {
|
} = data;
|
||||||
runtimeNodes: RuntimeNodeItemType[];
|
|
||||||
runtimeEdges: RuntimeEdgeItemType[];
|
|
||||||
}): Promise<DispatchFlowResponse> {
|
|
||||||
// set sse response headers
|
// set sse response headers
|
||||||
if (stream && res) {
|
if (stream && res) {
|
||||||
res.setHeader('Content-Type', 'text/event-stream;charset=utf-8');
|
res.setHeader('Content-Type', 'text/event-stream;charset=utf-8');
|
||||||
@ -93,7 +97,7 @@ export async function dispatchWorkFlow({
|
|||||||
}
|
}
|
||||||
|
|
||||||
variables = {
|
variables = {
|
||||||
...getSystemVariable({ timezone: user.timezone }),
|
...getSystemVariable(data),
|
||||||
...variables
|
...variables
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -384,9 +388,19 @@ export function responseStatus({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* get system variable */
|
/* get system variable */
|
||||||
export function getSystemVariable({ timezone }: { timezone: string }) {
|
export function getSystemVariable({
|
||||||
|
user,
|
||||||
|
appId,
|
||||||
|
chatId,
|
||||||
|
responseChatItemId,
|
||||||
|
histories = []
|
||||||
|
}: Props) {
|
||||||
return {
|
return {
|
||||||
cTime: getSystemTime(timezone)
|
appId,
|
||||||
|
chatId,
|
||||||
|
responseChatItemId,
|
||||||
|
histories,
|
||||||
|
cTime: getSystemTime(user.timezone)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,336 +7,205 @@
|
|||||||
"showStatus": false,
|
"showStatus": false,
|
||||||
"isTool": false,
|
"isTool": false,
|
||||||
"weight": 0,
|
"weight": 0,
|
||||||
"modules": [
|
"nodes": [
|
||||||
{
|
{
|
||||||
"moduleId": "w90mfp",
|
"nodeId": "lmpb9v2lo2lk",
|
||||||
"name": "定义插件输入",
|
"name": "定义插件输入",
|
||||||
"flowType": "pluginInput",
|
"intro": "自定义配置外部输入,使用插件时,仅暴露自定义配置的输入",
|
||||||
|
"avatar": "/imgs/workflow/input.png",
|
||||||
|
"flowNodeType": "pluginInput",
|
||||||
"showStatus": false,
|
"showStatus": false,
|
||||||
"position": {
|
"position": {
|
||||||
"x": 515.1887815471657,
|
"x": 616.4226348688949,
|
||||||
"y": -169.04905809653783
|
"y": -165.05298493910115
|
||||||
},
|
},
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
"key": "defaultFeedback",
|
"key": "system_addInputParam",
|
||||||
"valueType": "string",
|
"valueType": "dynamic",
|
||||||
"label": "默认反馈内容",
|
"label": "动态外部数据",
|
||||||
"type": "textarea",
|
"renderTypeList": ["addInputParam"],
|
||||||
"required": false,
|
"required": false,
|
||||||
"description": "",
|
"description": "",
|
||||||
"edit": true,
|
"canEdit": true,
|
||||||
|
"value": "",
|
||||||
"editField": {
|
"editField": {
|
||||||
"key": true,
|
"key": true
|
||||||
"name": true,
|
|
||||||
"description": true,
|
|
||||||
"required": true,
|
|
||||||
"dataType": true,
|
|
||||||
"inputType": true
|
|
||||||
},
|
},
|
||||||
"connected": true
|
"dynamicParamDefaultValue": {
|
||||||
|
"inputType": "reference",
|
||||||
|
"valueType": "string",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "customFeedback",
|
"key": "反馈内容",
|
||||||
"valueType": "string",
|
"valueType": "string",
|
||||||
"label": "自定义反馈内容",
|
"label": "反馈内容",
|
||||||
"type": "target",
|
"renderTypeList": ["textarea"],
|
||||||
"required": false,
|
|
||||||
"description": "",
|
"description": "",
|
||||||
"edit": true,
|
"canEdit": true,
|
||||||
|
"value": "",
|
||||||
"editField": {
|
"editField": {
|
||||||
"key": true,
|
"key": true
|
||||||
"name": true,
|
|
||||||
"description": true,
|
|
||||||
"required": true,
|
|
||||||
"dataType": true,
|
|
||||||
"inputType": true
|
|
||||||
},
|
},
|
||||||
"connected": true
|
"maxLength": "",
|
||||||
|
"dynamicParamDefaultValue": {
|
||||||
|
"inputType": "reference",
|
||||||
|
"valueType": "string",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"key": "defaultFeedback",
|
"id": "ILc8GS7iU53M",
|
||||||
|
"key": "反馈内容",
|
||||||
"valueType": "string",
|
"valueType": "string",
|
||||||
"label": "默认反馈内容",
|
"label": "反馈内容",
|
||||||
"type": "source",
|
"type": "static"
|
||||||
"edit": true,
|
},
|
||||||
"targets": [
|
|
||||||
{
|
{
|
||||||
"moduleId": "49de3g",
|
"id": "2LCxDnOSculb",
|
||||||
"key": "defaultFeedback"
|
"key": "system_addInputParam",
|
||||||
|
"valueType": "dynamic",
|
||||||
|
"label": "动态外部数据",
|
||||||
|
"type": "static"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "customFeedback",
|
"nodeId": "i7uow4wj2wdp",
|
||||||
"valueType": "string",
|
"name": "定义插件输出",
|
||||||
"label": "自定义反馈内容",
|
"intro": "自定义配置外部输出,使用插件时,仅暴露自定义配置的输出",
|
||||||
"type": "source",
|
"avatar": "/imgs/workflow/output.png",
|
||||||
"edit": true,
|
"flowNodeType": "pluginOutput",
|
||||||
"targets": [
|
"showStatus": false,
|
||||||
{
|
"position": {
|
||||||
"moduleId": "49de3g",
|
"x": 1607.7142331269126,
|
||||||
"key": "customFeedback"
|
"y": -151.8669210746189
|
||||||
}
|
},
|
||||||
]
|
"inputs": [],
|
||||||
}
|
"outputs": []
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"moduleId": "49de3g",
|
"nodeId": "CRT7oIEU8v2P",
|
||||||
"name": "HTTP模块",
|
"name": "HTTP 请求",
|
||||||
"flowType": "httpRequest468",
|
"intro": "可以发出一个 HTTP 请求,实现更为复杂的操作(联网搜索、数据库查询等)",
|
||||||
|
"avatar": "/imgs/workflow/http.png",
|
||||||
|
"flowNodeType": "httpRequest468",
|
||||||
"showStatus": true,
|
"showStatus": true,
|
||||||
"position": {
|
"position": {
|
||||||
"x": 1086.8929621216014,
|
"x": 1070.8458389994719,
|
||||||
"y": -451.7550009773506
|
"y": -415.09022555407836
|
||||||
},
|
},
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
"key": "switch",
|
"key": "system_addInputParam",
|
||||||
"type": "target",
|
"renderTypeList": ["addInputParam"],
|
||||||
"label": "core.module.input.label.switch",
|
"valueType": "dynamic",
|
||||||
"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": "",
|
"label": "",
|
||||||
"required": false,
|
"required": false,
|
||||||
"showTargetInApp": false,
|
"description": "core.module.input.description.HTTP Dynamic Input",
|
||||||
"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.workflow.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": {
|
"editField": {
|
||||||
"key": true,
|
"key": true,
|
||||||
"name": true,
|
"valueType": true
|
||||||
"description": true,
|
|
||||||
"required": true,
|
|
||||||
"dataType": true
|
|
||||||
},
|
},
|
||||||
"connected": true,
|
"value": ["lmpb9v2lo2lk", "2LCxDnOSculb"]
|
||||||
"key": "defaultFeedback"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "customFeedback",
|
"key": "customFeedback",
|
||||||
"valueType": "string",
|
"valueType": "string",
|
||||||
"label": "customFeedback",
|
"label": "customFeedback",
|
||||||
"type": "target",
|
"renderTypeList": ["reference"],
|
||||||
"required": true,
|
|
||||||
"description": "",
|
"description": "",
|
||||||
"edit": true,
|
"canEdit": true,
|
||||||
"editField": {
|
"editField": {
|
||||||
"key": true,
|
"key": true,
|
||||||
"name": true,
|
"valueType": true
|
||||||
"description": true,
|
|
||||||
"required": true,
|
|
||||||
"dataType": true
|
|
||||||
},
|
},
|
||||||
"connected": true
|
"value": ["lmpb9v2lo2lk", "ILc8GS7iU53M"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "system_addInputParam",
|
"key": "system_httpMethod",
|
||||||
"type": "addInputParam",
|
"renderTypeList": ["custom"],
|
||||||
"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",
|
"valueType": "string",
|
||||||
|
"label": "",
|
||||||
|
"value": "POST",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"connected": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"outputs": [
|
|
||||||
{
|
{
|
||||||
"key": "finish",
|
"key": "system_httpReqUrl",
|
||||||
"label": "core.module.output.label.running done",
|
"renderTypeList": ["hidden"],
|
||||||
"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",
|
"valueType": "string",
|
||||||
"label": "response",
|
"label": "",
|
||||||
"description": "",
|
"description": "core.module.input.description.Http Request Url",
|
||||||
"edit": true,
|
"placeholder": "https://api.ai.com/getInventory",
|
||||||
"editField": {
|
"required": false,
|
||||||
"key": true,
|
"value": "/api/plugins/customFeedback"
|
||||||
"name": true,
|
|
||||||
"description": true,
|
|
||||||
"dataType": true
|
|
||||||
},
|
|
||||||
"targets": [
|
|
||||||
{
|
|
||||||
"moduleId": "s15f3v",
|
|
||||||
"key": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"key": "response"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"moduleId": "s15f3v",
|
"key": "system_httpHeader",
|
||||||
"name": "指定回复",
|
"renderTypeList": ["custom"],
|
||||||
"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",
|
"valueType": "any",
|
||||||
"showTargetInApp": true,
|
"value": [],
|
||||||
"showTargetInPlugin": true,
|
"label": "",
|
||||||
"connected": false
|
"description": "core.module.input.description.Http Request Header",
|
||||||
|
"placeholder": "core.module.input.description.Http Request Header",
|
||||||
|
"required": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "text",
|
"key": "system_httpParams",
|
||||||
"type": "textarea",
|
"renderTypeList": ["hidden"],
|
||||||
"valueType": "any",
|
"valueType": "any",
|
||||||
"label": "core.module.input.label.Response content",
|
"value": [],
|
||||||
"description": "core.module.input.description.Response content",
|
"label": "",
|
||||||
"placeholder": "core.module.input.description.Response content",
|
"required": false
|
||||||
"showTargetInApp": true,
|
},
|
||||||
"showTargetInPlugin": true,
|
{
|
||||||
"connected": true
|
"key": "system_httpJsonBody",
|
||||||
|
"renderTypeList": ["hidden"],
|
||||||
|
"valueType": "any",
|
||||||
|
"value": "{\r\n \"customFeedback\":\"{{customFeedback}}\",\r\n \"system_addInputParam\": {{system_addInputParam}}\r\n}",
|
||||||
|
"label": "",
|
||||||
|
"required": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"key": "finish",
|
"id": "system_addOutputParam",
|
||||||
"label": "core.module.output.label.running done",
|
"key": "system_addOutputParam",
|
||||||
"description": "core.module.output.description.running done",
|
"type": "dynamic",
|
||||||
"valueType": "boolean",
|
"valueType": "dynamic",
|
||||||
"type": "hidden",
|
"label": "",
|
||||||
"targets": []
|
"editField": {
|
||||||
|
"key": true,
|
||||||
|
"valueType": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "httpRawResponse",
|
||||||
|
"key": "httpRawResponse",
|
||||||
|
"label": "原始响应",
|
||||||
|
"description": "HTTP请求的原始响应。只能接受字符串或JSON类型响应数据。",
|
||||||
|
"valueType": "any",
|
||||||
|
"type": "static"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"edges": [
|
||||||
|
{
|
||||||
|
"source": "lmpb9v2lo2lk",
|
||||||
|
"target": "CRT7oIEU8v2P",
|
||||||
|
"sourceHandle": "lmpb9v2lo2lk-source-right",
|
||||||
|
"targetHandle": "CRT7oIEU8v2P-target-left"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source": "CRT7oIEU8v2P",
|
||||||
|
"target": "i7uow4wj2wdp",
|
||||||
|
"sourceHandle": "CRT7oIEU8v2P-source-right",
|
||||||
|
"targetHandle": "i7uow4wj2wdp-target-left"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,6 @@ export const pushChatUsage = ({
|
|||||||
addLog.info(`finish completions`, {
|
addLog.info(`finish completions`, {
|
||||||
source,
|
source,
|
||||||
teamId,
|
teamId,
|
||||||
tmbId,
|
|
||||||
totalPoints
|
totalPoints
|
||||||
});
|
});
|
||||||
return { totalPoints };
|
return { totalPoints };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user