Commit 8ba339e7 by Archer Committed by GitHub

Perf webhook (#3406)

* perf: plugin webhook

* perf: plugin webhook
parent 8e9c0306
...@@ -866,6 +866,8 @@ curl --location --request DELETE 'http://localhost:3000/api/core/chat/delHistory ...@@ -866,6 +866,8 @@ curl --location --request DELETE 'http://localhost:3000/api/core/chat/delHistory
### 清空所有历史记录 ### 清空所有历史记录
仅会情况通过 API Key 创建的对话历史记录,不会清空在线使用、分享链接等其他来源的对话历史记录。
{{< tabs tabTotal="3" >}} {{< tabs tabTotal="3" >}}
{{< tab tabName="请求示例" >}} {{< tab tabName="请求示例" >}}
{{< markdownify >}} {{< markdownify >}}
......
...@@ -13,9 +13,11 @@ weight: 808 ...@@ -13,9 +13,11 @@ weight: 808
1. 1.
2. 新增 - 商业版支持 API 知识库和链接集合定时同步。 2. 新增 - 商业版支持 API 知识库和链接集合定时同步。
3. 新增 - 猜你想问支持选择模型和自定义提示词。 3. 新增 - 猜你想问支持选择模型和自定义提示词。
4. 优化 - 工作流/简易模式变量初始化代码,去除监听初始化,避免因渲染顺序不一致导致的失败。 4. 新增 - 钉钉和企微机器人 webhook 插件。
5. 修复 - 无法自动切换默认语言。增加分享链接,强制执行一次切换默认语言。 5. 新增 - sandbox 新增 createHmac 加密全局方法。
6. 修复 - 数组选择器自动兼容 4.8.13 以前的数据。 6. 优化 - 工作流/简易模式变量初始化代码,去除监听初始化,避免因渲染顺序不一致导致的失败。
7. 修复 - 站点同步知识库,链接同步时未使用选择器。 7. 修复 - 无法自动切换默认语言。增加分享链接,强制执行一次切换默认语言。
8. 修复 - 简易模式转工作流,没有把系统配置项转化。 8. 修复 - 数组选择器自动兼容 4.8.13 以前的数据。
9. 修复 - 插件独立运行,变量初始值未赋上。 9. 修复 - 站点同步知识库,链接同步时未使用选择器。
\ No newline at end of file 10. 修复 - 简易模式转工作流,没有把系统配置项转化。
11. 修复 - 插件独立运行,变量初始值未赋上。
\ No newline at end of file
...@@ -84,4 +84,18 @@ function main({input}){ ...@@ -84,4 +84,18 @@ function main({input}){
} }
``` ```
![alt text](/imgs/image-2.png) ![alt text](/imgs/image-2.png)
\ No newline at end of file
### createHmac 加密
与 node 中 crypto 的 createHmac 方法一致。
```js
function main({secret}){
const {sign,timestamp} = createHmac('sha256',secret)
return {
sign,timestamp
}
}
```
\ No newline at end of file
...@@ -5,7 +5,15 @@ import { cloneDeep } from 'lodash'; ...@@ -5,7 +5,15 @@ import { cloneDeep } from 'lodash';
import { WorkerNameEnum, runWorker } from '@fastgpt/service/worker/utils'; import { WorkerNameEnum, runWorker } from '@fastgpt/service/worker/utils';
// Run in main thread // Run in main thread
const staticPluginList = ['getTime', 'fetchUrl', 'feishu', 'google', 'bing']; const staticPluginList = [
'getTime',
'fetchUrl',
'feishu',
'DingTalkWebhook',
'WeWorkWebhook',
'google',
'bing'
];
// Run in worker thread (Have npm packages) // Run in worker thread (Have npm packages)
const packagePluginList = [ const packagePluginList = [
'mathExprVal', 'mathExprVal',
......
{ {
"author": "", "author": "",
"version": "4816", "version": "4816",
"name": "企业微信机器人 webhook", "name": "企业微信 webhook",
"avatar": "/appMarketTemplates/plugin-wework/avatar.svg", "avatar": "plugins/qiwei",
"intro": "向企业微信机器人发起 webhook 请求。", "intro": "向企业微信机器人发起 webhook 请求。只能内部群使用。",
"courseUrl": "https://developer.work.weixin.qq.com/document/path/91770", "courseUrl": "https://developer.work.weixin.qq.com/document/path/91770",
"showStatus": false, "showStatus": false,
"weight": 10, "weight": 10,
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
"flowNodeType": "pluginInput", "flowNodeType": "pluginInput",
"showStatus": false, "showStatus": false,
"position": { "position": {
"x": 535.7465806305546, "x": 537.6357458754286,
"y": -201.26482361861054 "y": -201.26482361861054
}, },
"version": "481", "version": "481",
...@@ -49,9 +49,9 @@ ...@@ -49,9 +49,9 @@
"key": "发送的消息", "key": "发送的消息",
"valueType": "string", "valueType": "string",
"label": "发送的消息", "label": "发送的消息",
"renderTypeList": ["reference"], "renderTypeList": ["input", "reference"],
"required": true, "required": true,
"description": "", "description": "发送的消息",
"canEdit": true, "canEdit": true,
"value": "", "value": "",
"editField": { "editField": {
...@@ -61,7 +61,10 @@ ...@@ -61,7 +61,10 @@
"inputType": "reference", "inputType": "reference",
"valueType": "string", "valueType": "string",
"required": true "required": true
} },
"list": [],
"defaultValue": "",
"toolDescription": "发送的消息"
} }
], ],
"outputs": [ "outputs": [
...@@ -354,6 +357,30 @@ ...@@ -354,6 +357,30 @@
"sourceHandle": "rKBYGQuYefae-source-right", "sourceHandle": "rKBYGQuYefae-source-right",
"targetHandle": "pluginOutput-target-left" "targetHandle": "pluginOutput-target-left"
} }
] ],
"chatConfig": {
"welcomeText": "",
"variables": [],
"questionGuide": false,
"ttsConfig": {
"type": "web"
},
"whisperConfig": {
"open": false,
"autoSend": false,
"autoTTSResponse": false
},
"chatInputGuide": {
"open": false,
"textList": [],
"customUrl": ""
},
"instruction": "",
"autoExecute": {
"open": false,
"defaultPrompt": ""
},
"_id": "6710a5619c45325525326719"
}
} }
} }
{ {
"author": "", "author": "",
"version": "488", "version": "488",
"name": "飞书机器人 webhook", "name": "飞书 webhook",
"avatar": "/appMarketTemplates/plugin-feishu/avatar.svg", "avatar": "/appMarketTemplates/plugin-feishu/avatar.svg",
"intro": "向飞书机器人发起 webhook 请求。", "intro": "向飞书机器人发起 webhook 请求。",
"courseUrl": "https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot#f62e72d5", "courseUrl": "https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot#f62e72d5",
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
"version": "481", "version": "481",
"inputs": [ "inputs": [
{ {
"renderTypeList": ["reference"], "renderTypeList": ["input", "reference"],
"selectedTypeIndex": 0, "selectedTypeIndex": 0,
"valueType": "string", "valueType": "string",
"canEdit": true, "canEdit": true,
...@@ -35,7 +35,9 @@ ...@@ -35,7 +35,9 @@
"label": "content", "label": "content",
"description": "需要发送的消息", "description": "需要发送的消息",
"required": true, "required": true,
"toolDescription": "需要发送的消息" "toolDescription": "需要发送的消息",
"list": [],
"defaultValue": ""
}, },
{ {
"renderTypeList": ["input"], "renderTypeList": ["input"],
...@@ -46,7 +48,8 @@ ...@@ -46,7 +48,8 @@
"label": "hook_url", "label": "hook_url",
"description": "飞书机器人地址", "description": "飞书机器人地址",
"required": true, "required": true,
"defaultValue": "" "defaultValue": "",
"list": []
} }
], ],
"outputs": [ "outputs": [
...@@ -508,6 +511,30 @@ ...@@ -508,6 +511,30 @@
"sourceHandle": "qcJpBBVtXsGd-source-right", "sourceHandle": "qcJpBBVtXsGd-source-right",
"targetHandle": "vzreK6vHrPvZ-target-left" "targetHandle": "vzreK6vHrPvZ-target-left"
} }
] ],
"chatConfig": {
"welcomeText": "",
"variables": [],
"questionGuide": false,
"ttsConfig": {
"type": "web"
},
"whisperConfig": {
"open": false,
"autoSend": false,
"autoTTSResponse": false
},
"chatInputGuide": {
"open": false,
"textList": [],
"customUrl": ""
},
"instruction": "",
"autoExecute": {
"open": false,
"defaultPrompt": ""
},
"_id": "6710a5619c45325525326719"
}
} }
} }
...@@ -341,7 +341,9 @@ export const iconPaths = { ...@@ -341,7 +341,9 @@ export const iconPaths = {
'phoneTabbar/me': () => import('./icons/phoneTabbar/me.svg'), 'phoneTabbar/me': () => import('./icons/phoneTabbar/me.svg'),
'phoneTabbar/tool': () => import('./icons/phoneTabbar/tool.svg'), 'phoneTabbar/tool': () => import('./icons/phoneTabbar/tool.svg'),
'phoneTabbar/toolFill': () => import('./icons/phoneTabbar/toolFill.svg'), 'phoneTabbar/toolFill': () => import('./icons/phoneTabbar/toolFill.svg'),
'plugins/dingding': () => import('./icons/plugins/dingding.svg'),
'plugins/doc2x': () => import('./icons/plugins/doc2x.svg'), 'plugins/doc2x': () => import('./icons/plugins/doc2x.svg'),
'plugins/qiwei': () => import('./icons/plugins/qiwei.svg'),
'plugins/textEditor': () => import('./icons/plugins/textEditor.svg'), 'plugins/textEditor': () => import('./icons/plugins/textEditor.svg'),
point: () => import('./icons/point.svg'), point: () => import('./icons/point.svg'),
preview: () => import('./icons/preview.svg'), preview: () => import('./icons/preview.svg'),
......
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1734061835557" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4251" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M512.003 79C272.855 79 79 272.855 79 512.003 79 751.145 272.855 945 512.003 945 751.145 945 945 751.145 945 512.003 945 272.855 751.145 79 512.003 79z m200.075 375.014c-0.867 3.764-3.117 9.347-6.234 16.012h0.087l-0.347 0.648c-18.183 38.86-65.631 115.108-65.631 115.108l-0.215-0.52-13.856 24.147h66.8L565.063 779l29.002-115.368h-52.598l18.27-76.29c-14.76 3.55-32.253 8.436-52.945 15.1 0 0-27.967 16.36-80.607-31.5 0 0-35.501-31.29-14.891-39.078 8.744-3.33 42.466-7.573 69.004-11.122 35.93-4.845 57.965-7.441 57.965-7.441s-110.607 1.643-136.841-2.468c-26.237-4.11-59.525-47.905-66.626-86.377 0 0-10.953-21.117 23.595-11.122 34.547 10 177.535 38.95 177.535 38.95s-185.933-56.992-198.36-70.929c-12.381-13.846-36.406-75.902-33.289-113.981 0 0 1.343-9.521 11.127-6.926 0 0 137.49 62.75 231.475 97.152 94.028 34.403 175.76 51.885 165.2 96.414z" fill="#3AA2EB" p-id="4252"></path></svg>
\ No newline at end of file
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1734061855126" class="icon" viewBox="0 0 1219 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5425" xmlns:xlink="http://www.w3.org/1999/xlink" width="238.0859375" height="200"><path d="M966.168 275.578a429.202 429.202 0 0 0-77.41-110.397c-80.822-83.944-193.95-138.02-318.61-152.26a583.655 583.655 0 0 0-65.926-3.827c-20.284 0-41.545 1.195-63.097 3.584C316.05 26.258 202.265 80.19 120.856 164.06a429.641 429.641 0 0 0-77.824 110.227A385.829 385.829 0 0 0 3.048 445.074c0 76.313 23.113 151.382 66.803 217.356 22.138 33.427 58.344 75.484 91.673 105.204l-15.068 118.833c-0.585 1.585-1.194 3.17-1.584 4.9-0.415 1.61-0.488 3.195-0.634 4.804-0.098 1.194-0.415 2.389-0.415 3.584 0 1.316 0.317 2.608 0.415 3.9a38.522 38.522 0 0 0 38.205 34.865c6.973 0 13.41-2.023 19.017-5.217l0.585-0.39c0.78-0.39 1.658-0.878 2.438-1.39l35.962-18.14 107.081-54.052a550.687 550.687 0 0 0 93.574 18.09 576.123 576.123 0 0 0 128.975-0.39 559.47 559.47 0 0 0 126.343-29.622 69.973 69.973 0 0 1-47.446-73.192 468.114 468.114 0 0 1-89.575 19.261 482.987 482.987 0 0 1-108.106 0.317c-3.584-0.39-7.265-0.975-10.922-1.463a475.404 475.404 0 0 1-70.851-14.994 48.299 48.299 0 0 0-14.726-2.268c-7.973 0-15.604 2.073-23.406 6.096-1.048 0.61-2 1.048-3.048 1.609l-87.942 52.053-3.852 2.292c-1.877 1.195-2.999 1.585-3.998 1.585a5.973 5.973 0 0 1-5.803-6.071l3.389-13.775 3.803-14.97 6.461-24.527 7.07-27.405c4.877-15.189-0.487-31.792-13.287-41.252a394.679 394.679 0 0 1-36.742-31.037 362.57 362.57 0 0 1-52.15-61.928c-34.622-52.224-52.859-111.494-52.859-171.447 0-46.494 10.582-91.745 31.452-134.436a344.795 344.795 0 0 1 62.488-88.26c66.877-69.022 160.987-113.322 264.948-124.635 18.042-1.999 35.84-2.974 52.858-2.974 17.92 0 36.474 1.073 55.247 3.17 103.521 11.824 197.071 56.32 263.436 125.342a344.21 344.21 0 0 1 62.098 88.478c20.359 41.448 30.964 87.04 31.037 133.267 0 4.803-0.317 9.606-0.536 14.384a69.34 69.34 0 0 1 85.577 9.997c1.22 1.194 2.121 2.51 3.17 3.754a360.28 360.28 0 0 0 1.219-29.574 385.829 385.829 0 0 0-39.254-169.326" fill="#0082F0" p-id="5426"></path><path d="M961.39 884.59a67.462 67.462 0 0 0-8.339-1.39 213.87 213.87 0 0 1-119.32-66.706 16.579 16.579 0 0 0-28.062 9.533 16.725 16.725 0 0 0 6.826 16.042l4.755 4.779a215.503 215.503 0 0 1 58.806 110.25 69.778 69.778 0 0 0 51.737 63.318 69.51 69.51 0 0 0 67.096-18.164 70.217 70.217 0 0 0 17.725-68.778 69.925 69.925 0 0 0-51.322-48.957" fill="#FB6500" p-id="5427"></path><path d="M1192.058 705.853a69.486 69.486 0 0 0-72.607-16.506 69.851 69.851 0 0 0-46.03 58.685 215.381 215.381 0 0 1-66.366 119.71 16.823 16.823 0 0 0 9.265 28.892 16.701 16.701 0 0 0 16.213-7.558l4.706-4.803a213.821 213.821 0 0 1 109.787-59.1 69.949 69.949 0 0 0 63.098-52.004 70.217 70.217 0 0 0-18.066-67.414" fill="#0082F0" p-id="5428"></path><path d="M896.902 507.928a70.217 70.217 0 0 0-16.36 72.802 69.876 69.876 0 0 0 58.32 46.3 213.821 213.821 0 0 1 119.271 66.681 16.677 16.677 0 0 0 28.477-9.484 16.798 16.798 0 0 0-7.216-16.189 215.479 215.479 0 0 1-63.684-115.03 69.778 69.778 0 0 0-51.638-63.317 69.51 69.51 0 0 0-67.17 18.14" fill="#2DBC00" p-id="5429"></path><path d="M817.81 766.464l0.585-4.242a215.576 215.576 0 0 1 66.414-119.833 16.823 16.823 0 0 0-9.24-28.891 16.701 16.701 0 0 0-16.238 7.558 213.797 213.797 0 0 1-114.493 63.927 69.949 69.949 0 0 0-63.098 52.004 70.217 70.217 0 0 0 18.066 67.414 69.486 69.486 0 0 0 70.486 17.066 69.827 69.827 0 0 0 47.445-55.003" fill="#FFCC00" p-id="5430"></path></svg>
\ No newline at end of file
...@@ -48,6 +48,13 @@ async function handler(req: ApiRequestProps<{}, ClearHistoriesProps>, res: NextA ...@@ -48,6 +48,13 @@ async function handler(req: ApiRequestProps<{}, ClearHistoriesProps>, res: NextA
source: ChatSourceEnum.online source: ChatSourceEnum.online
}; };
} }
if (authType === 'apikey') {
return {
teamId: chatTeamId,
appId,
source: ChatSourceEnum.api
};
}
return Promise.reject('Param are error'); return Promise.reject('Param are error');
})(); })();
......
...@@ -73,7 +73,7 @@ const WorkflowStatusContextProvider = ({ children }: { children: ReactNode }) => ...@@ -73,7 +73,7 @@ const WorkflowStatusContextProvider = ({ children }: { children: ReactNode }) =>
if (isSaved || !leaveSaveSign.current) return; if (isSaved || !leaveSaveSign.current) return;
console.log('Leave auto save'); console.log('Leave auto save');
const data = flowData2StoreData(); const data = flowData2StoreData();
if (!data) return; if (!data || data.nodes.length === 0) return;
await onSaveApp({ await onSaveApp({
...data, ...data,
isPublish: false, isPublish: false,
......
...@@ -24,13 +24,14 @@ ...@@ -24,13 +24,14 @@
"@nestjs/core": "^10.0.0", "@nestjs/core": "^10.0.0",
"@nestjs/platform-fastify": "^10.3.8", "@nestjs/platform-fastify": "^10.3.8",
"@nestjs/swagger": "^7.3.1", "@nestjs/swagger": "^7.3.1",
"fastify": "^4.27.0", "crypto": "^1.0.1",
"dayjs": "^1.11.7", "dayjs": "^1.11.7",
"fastify": "^4.27.0",
"isolated-vm": "^4.7.2", "isolated-vm": "^4.7.2",
"tiktoken": "1.0.17",
"node-gyp": "^10.1.0", "node-gyp": "^10.1.0",
"reflect-metadata": "^0.2.0", "reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1" "rxjs": "^7.8.1",
"tiktoken": "1.0.17"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^10.0.0", "@nestjs/cli": "^10.0.0",
......
import * as crypto from 'crypto';
import * as querystring from 'querystring';
export const createHmac = (algorithm: string, secret: string) => {
const timestamp = Date.now().toString();
const stringToSign = `${timestamp}\n${secret}`;
// 创建 HMAC
const hmac = crypto.createHmac(algorithm, secret);
hmac.update(stringToSign, 'utf8');
const signData = hmac.digest();
const sign = querystring.escape(Buffer.from(signData).toString('base64'));
return {
timestamp,
sign
};
};
import { RunCodeDto, RunCodeResponse } from 'src/sandbox/dto/create-sandbox.dto'; import { RunCodeDto, RunCodeResponse } from 'src/sandbox/dto/create-sandbox.dto';
import IsolatedVM, { ExternalCopy, Isolate, Reference } from 'isolated-vm'; import IsolatedVM, { ExternalCopy, Isolate, Reference } from 'isolated-vm';
import { countToken } from './jsFn/tiktoken'; import { countToken } from './jsFn/tiktoken';
import { timeDelay } from './jsFn/delay'; import { timeDelay } from './jsFn/delay';
import { strToBase64 } from './jsFn/str2Base64'; import { strToBase64 } from './jsFn/str2Base64';
import { createHmac } from './jsFn/crypto';
const CustomLogStr = 'CUSTOM_LOG'; const CustomLogStr = 'CUSTOM_LOG';
...@@ -42,7 +44,8 @@ function registerSystemFn(jail: IsolatedVM.Reference<Record<string | number | sy ...@@ -42,7 +44,8 @@ function registerSystemFn(jail: IsolatedVM.Reference<Record<string | number | sy
return Promise.all([ return Promise.all([
jail.set('global_delay', new Reference(timeDelay)), jail.set('global_delay', new Reference(timeDelay)),
jail.set('countToken', countToken), jail.set('countToken', countToken),
jail.set('strToBase64', strToBase64) jail.set('strToBase64', strToBase64),
jail.set('createHmac', createHmac)
]); ]);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment