Skip to content

Commit

Permalink
4.8 test fix (#1397)
Browse files Browse the repository at this point in the history
* adapt v1 chat init

* adapt v1 chat init

* adapt v1 chat init

* perf: message input line; fix: http request un stream

* perf: message input line; fix: http request un stream

* perf: message input line; fix: http request un stream

* perf: error tip
  • Loading branch information
c121914yu authored May 8, 2024
1 parent 3c6e5a6 commit 917e4e9
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 140 deletions.
2 changes: 1 addition & 1 deletion packages/global/common/error/code/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ErrType } from '../errorCode';

/* dataset: 502000 */
export enum AppErrEnum {
unExist = 'unExist',
unExist = 'appUnExist',
unAuthApp = 'unAuthApp'
}
const appErrList = [
Expand Down
4 changes: 2 additions & 2 deletions packages/global/common/error/code/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ErrType } from '../errorCode';

/* dataset: 506000 */
export enum OpenApiErrEnum {
unExist = 'unExist',
unAuth = 'unAuth'
unExist = 'openapiUnExist',
unAuth = 'openapiUnAuth'
}
const errList = [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/global/common/error/code/outLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ErrType } from '../errorCode';

/* dataset: 505000 */
export enum OutLinkErrEnum {
unExist = 'unExist',
unExist = 'outlinkUnExist',
unAuthLink = 'unAuthLink',
linkUnInvalid = 'linkUnInvalid',

Expand Down
4 changes: 2 additions & 2 deletions packages/global/common/error/code/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ErrType } from '../errorCode';

/* dataset: 507000 */
export enum PluginErrEnum {
unExist = 'unExist',
unAuth = 'unAuth'
unExist = 'pluginUnExist',
unAuth = 'pluginUnAuth'
}
const errList = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion packages/service/core/workflow/dispatch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
runtimeNodes,
runtimeEdges,
params,
mode: 'test'
mode: props.mode === 'debug' ? 'test' : props.mode
};

// run module
Expand Down
3 changes: 2 additions & 1 deletion packages/service/core/workflow/dispatch/tools/http468.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
detail,
appId,
chatId,
stream,
responseChatItemId,
variables,
node: { outputs },
Expand Down Expand Up @@ -132,7 +133,7 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
results[key] = valueTypeFormat(formatResponse[key], output.valueType);
}

if (typeof formatResponse[NodeOutputKeyEnum.answerText] === 'string') {
if (stream && typeof formatResponse[NodeOutputKeyEnum.answerText] === 'string') {
responseWrite({
res,
event: detail ? SseResponseEventEnum.fastAnswer : undefined,
Expand Down
24 changes: 23 additions & 1 deletion projects/app/data/pluginTemplates/customFeedback.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,22 @@
"x": 1607.7142331269126,
"y": -151.8669210746189
},
"inputs": [],
"inputs": [
{
"key": "text",
"valueType": "string",
"label": "text",
"renderTypeList": ["reference"],
"description": "",
"canEdit": true,
"editField": {
"key": true,
"description": true,
"valueType": true
},
"value": ["CRT7oIEU8v2P", "pYKS0LB9gAr3"]
}
],
"outputs": []
},
{
Expand Down Expand Up @@ -190,6 +205,13 @@
"description": "HTTP请求的原始响应。只能接受字符串或JSON类型响应数据。",
"valueType": "any",
"type": "static"
},
{
"id": "pYKS0LB9gAr3",
"type": "dynamic",
"key": "text",
"valueType": "string",
"label": "text"
}
]
}
Expand Down
9 changes: 8 additions & 1 deletion projects/app/src/components/ChatBox/MessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,16 @@ const MessageInput = ({
// enter send.(pc or iframe && enter and unPress shift)
const isEnter = e.keyCode === 13;
if (isEnter && TextareaDom.current && (e.ctrlKey || e.altKey)) {
TextareaDom.current.value += '\n';
// Add a new line
const index = TextareaDom.current.selectionStart;
const val = TextareaDom.current.value;
TextareaDom.current.value = `${val.slice(0, index)}\n${val.slice(index)}`;
TextareaDom.current.selectionStart = index + 1;
TextareaDom.current.selectionEnd = index + 1;

TextareaDom.current.style.height = textareaMinH;
TextareaDom.current.style.height = `${TextareaDom.current.scrollHeight}px`;

return;
}

Expand Down
1 change: 0 additions & 1 deletion projects/app/src/components/core/workflow/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ const WorkflowContextProvider = ({
// 3. Set entry node status to running
entryNodes.forEach((node) => {
if (runtimeNodeStatus[node.nodeId] !== 'wait') {
console.log(node.name);
onChangeNode({
nodeId: node.nodeId,
type: 'attr',
Expand Down
122 changes: 58 additions & 64 deletions projects/app/src/pages/api/core/chat/init.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<InitChatResponse | void> {
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<InitChatResponse>(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'
Expand Down
Loading

0 comments on commit 917e4e9

Please sign in to comment.