diff --git a/packages/global/common/error/code/app.ts b/packages/global/common/error/code/app.ts index 70573f83659..e3dfdcf3a8c 100644 --- a/packages/global/common/error/code/app.ts +++ b/packages/global/common/error/code/app.ts @@ -2,7 +2,7 @@ import { ErrType } from '../errorCode'; /* dataset: 502000 */ export enum AppErrEnum { - unExist = 'unExist', + unExist = 'appUnExist', unAuthApp = 'unAuthApp' } const appErrList = [ diff --git a/packages/global/common/error/code/openapi.ts b/packages/global/common/error/code/openapi.ts index 5737af63e05..c64f51b3251 100644 --- a/packages/global/common/error/code/openapi.ts +++ b/packages/global/common/error/code/openapi.ts @@ -2,8 +2,8 @@ import { ErrType } from '../errorCode'; /* dataset: 506000 */ export enum OpenApiErrEnum { - unExist = 'unExist', - unAuth = 'unAuth' + unExist = 'openapiUnExist', + unAuth = 'openapiUnAuth' } const errList = [ { diff --git a/packages/global/common/error/code/outLink.ts b/packages/global/common/error/code/outLink.ts index 81130e10f42..25ee6fab80d 100644 --- a/packages/global/common/error/code/outLink.ts +++ b/packages/global/common/error/code/outLink.ts @@ -2,7 +2,7 @@ import { ErrType } from '../errorCode'; /* dataset: 505000 */ export enum OutLinkErrEnum { - unExist = 'unExist', + unExist = 'outlinkUnExist', unAuthLink = 'unAuthLink', linkUnInvalid = 'linkUnInvalid', diff --git a/packages/global/common/error/code/plugin.ts b/packages/global/common/error/code/plugin.ts index d3ae672a86c..430f0d2a7d0 100644 --- a/packages/global/common/error/code/plugin.ts +++ b/packages/global/common/error/code/plugin.ts @@ -2,8 +2,8 @@ import { ErrType } from '../errorCode'; /* dataset: 507000 */ export enum PluginErrEnum { - unExist = 'unExist', - unAuth = 'unAuth' + unExist = 'pluginUnExist', + unAuth = 'pluginUnAuth' } const errList = [ { diff --git a/packages/global/core/workflow/template/system/variableUpdate/index.tsx b/packages/global/core/workflow/template/system/variableUpdate/index.tsx index 34ddd2a06d4..6867d98bba3 100644 --- a/packages/global/core/workflow/template/system/variableUpdate/index.tsx +++ b/packages/global/core/workflow/template/system/variableUpdate/index.tsx @@ -15,7 +15,7 @@ export const VariableUpdateNode: FlowNodeTemplateType = { targetHandle: getHandleConfig(true, true, true, true), avatar: '/imgs/workflow/variable.png', name: '变量更新', - intro: '可以更新指定节点的输出值和全局变量', + intro: '可以更新指定节点的输出值或更新全局变量', showStatus: true, isTool: false, inputs: [ diff --git a/packages/service/core/workflow/dispatch/index.ts b/packages/service/core/workflow/dispatch/index.ts index 3dc63cf59fd..bb4a78385ce 100644 --- a/packages/service/core/workflow/dispatch/index.ts +++ b/packages/service/core/workflow/dispatch/index.ts @@ -290,7 +290,7 @@ export async function dispatchWorkFlow(data: Props): Promise { if (runtimeNodeStatus[node.nodeId] !== 'wait') { - console.log(node.name); onChangeNode({ nodeId: node.nodeId, type: 'attr', diff --git a/projects/app/src/pages/api/core/chat/init.ts b/projects/app/src/pages/api/core/chat/init.ts index 902c9fb8ebc..08e3ff796c0 100644 --- a/projects/app/src/pages/api/core/chat/init.ts +++ b/projects/app/src/pages/api/core/chat/init.ts @@ -1,6 +1,5 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@fastgpt/service/common/response'; -import { connectToDatabase } from '@/service/mongo'; import { authApp } from '@fastgpt/service/support/permission/auth/app'; import { getGuideModule, replaceAppChatConfig } from '@fastgpt/global/core/workflow/utils'; import { getChatModelNameListByModules } from '@/service/core/app/workflow'; @@ -10,78 +9,73 @@ import { getChatItems } from '@fastgpt/service/core/chat/controller'; import { ChatErrEnum } from '@fastgpt/global/common/error/code/chat'; import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants'; import { getAppLatestVersion } from '@fastgpt/service/core/app/controller'; +import { NextAPI } from '@/service/middle/entry'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - try { - await connectToDatabase(); +async function handler( + req: NextApiRequest, + res: NextApiResponse +): Promise { + let { appId, chatId, loadCustomFeedbacks } = req.query as InitChatProps; - let { appId, chatId, loadCustomFeedbacks } = req.query as InitChatProps; + if (!appId) { + return jsonRes(res, { + code: 501, + message: "You don't have an app yet" + }); + } - if (!appId) { - return jsonRes(res, { - code: 501, - message: "You don't have an app yet" - }); - } + // auth app permission + const [{ app, tmbId }, chat] = await Promise.all([ + authApp({ + req, + authToken: true, + appId, + per: 'r' + }), + chatId ? MongoChat.findOne({ appId, chatId }) : undefined + ]); - // auth app permission - const [{ app, tmbId }, chat] = await Promise.all([ - authApp({ - req, - authToken: true, - appId, - per: 'r' - }), - chatId ? MongoChat.findOne({ appId, chatId }) : undefined - ]); + // auth chat permission + if (chat && !app.canWrite && String(tmbId) !== String(chat?.tmbId)) { + throw new Error(ChatErrEnum.unAuthChat); + } - // auth chat permission - if (chat && !app.canWrite && String(tmbId) !== String(chat?.tmbId)) { - throw new Error(ChatErrEnum.unAuthChat); - } + // get app and history + const [{ history }, { nodes }] = await Promise.all([ + getChatItems({ + appId, + chatId, + limit: 30, + field: `dataId obj value adminFeedback userBadFeedback userGoodFeedback ${ + DispatchNodeResponseKeyEnum.nodeResponse + } ${loadCustomFeedbacks ? 'customFeedbacks' : ''}` + }), + getAppLatestVersion(app._id, app) + ]); - // get app and history - const [{ history }, { nodes }] = await Promise.all([ - getChatItems({ - appId, - chatId, - limit: 30, - field: `dataId obj value adminFeedback userBadFeedback userGoodFeedback ${ - DispatchNodeResponseKeyEnum.nodeResponse - } ${loadCustomFeedbacks ? 'customFeedbacks' : ''}` + return { + chatId, + appId, + title: chat?.title || '新对话', + userAvatar: undefined, + variables: chat?.variables || {}, + history, + app: { + userGuideModule: replaceAppChatConfig({ + node: getGuideModule(nodes), + variableList: chat?.variableList, + welcomeText: chat?.welcomeText }), - getAppLatestVersion(app._id, app) - ]); - - jsonRes(res, { - data: { - chatId, - appId, - title: chat?.title || '新对话', - userAvatar: undefined, - variables: chat?.variables || {}, - history, - app: { - userGuideModule: replaceAppChatConfig({ - node: getGuideModule(nodes), - variableList: chat?.variableList, - welcomeText: chat?.welcomeText - }), - chatModels: getChatModelNameListByModules(nodes), - name: app.name, - avatar: app.avatar, - intro: app.intro - } - } - }); - } catch (err) { - jsonRes(res, { - code: 500, - error: err - }); - } + chatModels: getChatModelNameListByModules(nodes), + name: app.name, + avatar: app.avatar, + intro: app.intro + } + }; } +export default NextAPI(handler); + export const config = { api: { responseLimit: '10mb' diff --git a/projects/app/src/pages/api/core/workflow/debug.ts b/projects/app/src/pages/api/core/workflow/debug.ts index f0fef3ba3a4..e4749d8b5d0 100644 --- a/projects/app/src/pages/api/core/workflow/debug.ts +++ b/projects/app/src/pages/api/core/workflow/debug.ts @@ -1,6 +1,4 @@ import type { NextApiRequest, NextApiResponse } from 'next'; -import { connectToDatabase } from '@/service/mongo'; -import { jsonRes } from '@fastgpt/service/common/response'; import { pushChatUsage } from '@/service/support/wallet/usage/push'; import { UsageSourceEnum } from '@fastgpt/global/support/wallet/usage/constants'; import { authApp } from '@fastgpt/service/support/permission/auth/app'; @@ -9,8 +7,12 @@ import { authCert } from '@fastgpt/service/support/permission/auth/common'; import { getUserChatInfoAndAuthTeamPoints } from '@/service/support/permission/auth/team'; import { PostWorkflowDebugProps, PostWorkflowDebugResponse } from '@/global/core/workflow/api'; import { authPluginCrud } from '@fastgpt/service/support/permission/auth/plugin'; +import { NextAPI } from '@/service/middle/entry'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { +async function handler( + req: NextApiRequest, + res: NextApiResponse +): Promise { const { nodes = [], edges = [], @@ -18,72 +20,65 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) appId, pluginId } = req.body as PostWorkflowDebugProps; - try { - await connectToDatabase(); - if (!nodes) { - throw new Error('Prams Error'); - } - if (!Array.isArray(nodes)) { - throw new Error('Nodes is not array'); - } - if (!Array.isArray(edges)) { - throw new Error('Edges is not array'); - } - /* user auth */ - const [{ teamId, tmbId }] = await Promise.all([ - authCert({ - req, - authToken: true - }), - appId && authApp({ req, authToken: true, appId, per: 'r' }), - pluginId && authPluginCrud({ req, authToken: true, pluginId, per: 'r' }) - ]); + if (!nodes) { + throw new Error('Prams Error'); + } + if (!Array.isArray(nodes)) { + throw new Error('Nodes is not array'); + } + if (!Array.isArray(edges)) { + throw new Error('Edges is not array'); + } + + /* user auth */ + const [{ teamId, tmbId }] = await Promise.all([ + authCert({ + req, + authToken: true + }), + appId && authApp({ req, authToken: true, appId, per: 'r' }), + pluginId && authPluginCrud({ req, authToken: true, pluginId, per: 'r' }) + ]); - // auth balance - const { user } = await getUserChatInfoAndAuthTeamPoints(tmbId); + // auth balance + const { user } = await getUserChatInfoAndAuthTeamPoints(tmbId); - /* start process */ - const { flowUsages, flowResponses, debugResponse } = await dispatchWorkFlow({ - res, - mode: 'debug', - teamId, - tmbId, - user, - appId, - runtimeNodes: nodes, - runtimeEdges: edges, - variables, - query: [], - histories: [], - stream: false, - detail: true, - maxRunTimes: 200 - }); + /* start process */ + const { flowUsages, flowResponses, debugResponse } = await dispatchWorkFlow({ + res, + mode: 'debug', + teamId, + tmbId, + user, + appId, + runtimeNodes: nodes, + runtimeEdges: edges, + variables, + query: [], + histories: [], + stream: false, + detail: true, + maxRunTimes: 200 + }); - pushChatUsage({ - appName: '工作流Debug', - appId, - teamId, - tmbId, - source: UsageSourceEnum.fastgpt, - flowUsages - }); + pushChatUsage({ + appName: '工作流Debug', + appId, + teamId, + tmbId, + source: UsageSourceEnum.fastgpt, + flowUsages + }); - jsonRes(res, { - data: { - ...debugResponse, - flowResponses - } - }); - } catch (err: any) { - jsonRes(res, { - code: 500, - error: err - }); - } + return { + ...debugResponse, + flowResponses + }; } +export default NextAPI(handler); + export const config = { api: { bodyParser: { diff --git a/projects/app/src/pages/api/plugins/customFeedback/v2/index.ts b/projects/app/src/pages/api/plugins/customFeedback/v2/index.ts index c04c73b865e..afb97e6eb25 100644 --- a/projects/app/src/pages/api/plugins/customFeedback/v2/index.ts +++ b/projects/app/src/pages/api/plugins/customFeedback/v2/index.ts @@ -34,11 +34,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< if (!chatId || !chatItemId) { return res.json({ - [NodeOutputKeyEnum.answerText]: `\\n\\n**自动反馈调试**: "${customFeedback}"\\n\\n` + [NodeOutputKeyEnum.answerText]: `\\n\\n**自动反馈调试**: "${customFeedback}"\\n\\n`, + text: customFeedback }); } - return res.json({}); + res.json({ + text: customFeedback + }); } catch (err) { console.log(err); res.status(500).send(getErrText(err));