mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-01 03:48:24 +00:00
Plugin runtime (#2050)
* feat: plugin run (#1950) * feat: plugin run * fix * ui * fix * change user input type * fix * fix * temp * split out plugin chat * perf: chatbox * perf: chatbox * fix: plugin runtime (#2032) * fix: plugin runtime * fix * fix build * fix build * perf: chat send prompt * perf: chat log ux * perf: chatbox context and share page plugin runtime * perf: plugin run time config * fix: ts * feat: doc * perf: isPc check * perf: variable input render * feat: app search * fix: response box height * fix: phone ui * perf: lock * perf: plugin route * fix: chat (#2049) --------- Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { SseResponseEventEnum } from '@fastgpt/global/core/workflow/runtime/constants';
|
||||
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||
import type { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type.d';
|
||||
import type { StartChatFnProps } from '@/components/ChatBox/type.d';
|
||||
import type { StartChatFnProps } from '@/components/core/chat/ChatContainer/type';
|
||||
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
|
||||
import dayjs from 'dayjs';
|
||||
import {
|
||||
// refer to https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web
|
||||
EventStreamContentType,
|
||||
|
@@ -14,7 +14,7 @@ interface ConfigType {
|
||||
timeout?: number;
|
||||
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||
cancelToken?: AbortController;
|
||||
maxQuantity?: number;
|
||||
maxQuantity?: number; // The maximum number of simultaneous requests, usually used to cancel old requests
|
||||
withCredentials?: boolean;
|
||||
}
|
||||
interface ResponseDataType {
|
||||
@@ -31,20 +31,28 @@ const maxQuantityMap: Record<
|
||||
}
|
||||
> = {};
|
||||
|
||||
function requestStart({ url, maxQuantity }: { url: string; maxQuantity?: number }) {
|
||||
if (!maxQuantity) return;
|
||||
const item = maxQuantityMap[url];
|
||||
function checkMaxQuantity({ url, maxQuantity }: { url: string; maxQuantity?: number }) {
|
||||
if (maxQuantity) {
|
||||
const item = maxQuantityMap[url];
|
||||
const controller = new AbortController();
|
||||
|
||||
if (item) {
|
||||
if (item.amount >= maxQuantity && item.sign) {
|
||||
item.sign.abort();
|
||||
delete maxQuantityMap[url];
|
||||
if (item) {
|
||||
if (item.amount >= maxQuantity) {
|
||||
item.sign?.abort?.();
|
||||
maxQuantityMap[url] = {
|
||||
amount: 1,
|
||||
sign: controller
|
||||
};
|
||||
} else {
|
||||
item.amount++;
|
||||
}
|
||||
} else {
|
||||
maxQuantityMap[url] = {
|
||||
amount: 1,
|
||||
sign: controller
|
||||
};
|
||||
}
|
||||
} else {
|
||||
maxQuantityMap[url] = {
|
||||
amount: 1,
|
||||
sign: new AbortController()
|
||||
};
|
||||
return controller;
|
||||
}
|
||||
}
|
||||
function requestFinish({ url }: { url: string }) {
|
||||
@@ -148,7 +156,7 @@ function request(
|
||||
}
|
||||
}
|
||||
|
||||
requestStart({ url, maxQuantity });
|
||||
const controller = checkMaxQuantity({ url, maxQuantity });
|
||||
|
||||
return instance
|
||||
.request({
|
||||
@@ -157,7 +165,7 @@ function request(
|
||||
method,
|
||||
data: ['POST', 'PUT'].includes(method) ? data : null,
|
||||
params: !['POST', 'PUT'].includes(method) ? data : null,
|
||||
signal: cancelToken?.signal,
|
||||
signal: cancelToken?.signal ?? controller?.signal,
|
||||
withCredentials,
|
||||
...config // 用户自定义配置,可以覆盖前面的配置
|
||||
})
|
||||
|
@@ -25,10 +25,6 @@ type State = {
|
||||
setLoginStore: (e: LoginStoreType) => void;
|
||||
loading: boolean;
|
||||
setLoading: (val: boolean) => null;
|
||||
screenWidth: number;
|
||||
setScreenWidth: (val: number) => void;
|
||||
isPc?: boolean;
|
||||
initIsPc(val: boolean): void;
|
||||
gitStar: number;
|
||||
loadGitStar: () => Promise<void>;
|
||||
|
||||
@@ -76,21 +72,7 @@ export const useSystemStore = create<State>()(
|
||||
});
|
||||
return null;
|
||||
},
|
||||
screenWidth: 600,
|
||||
setScreenWidth(val: number) {
|
||||
set((state) => {
|
||||
state.screenWidth = val;
|
||||
state.isPc = val < 900 ? false : true;
|
||||
});
|
||||
},
|
||||
isPc: undefined,
|
||||
initIsPc(val: boolean) {
|
||||
if (get().isPc !== undefined) return;
|
||||
|
||||
set((state) => {
|
||||
state.isPc = val;
|
||||
});
|
||||
},
|
||||
gitStar: 9300,
|
||||
async loadGitStar() {
|
||||
try {
|
||||
|
@@ -8,7 +8,10 @@ import type { ListAppBody } from '@/pages/api/core/app/list';
|
||||
/**
|
||||
* 获取模型列表
|
||||
*/
|
||||
export const getMyApps = (data?: ListAppBody) => POST<AppListItemType[]>('/core/app/list', data);
|
||||
export const getMyApps = (data?: ListAppBody) =>
|
||||
POST<AppListItemType[]>('/core/app/list', data, {
|
||||
maxQuantity: 1
|
||||
});
|
||||
|
||||
/**
|
||||
* 创建一个模型
|
||||
|
@@ -7,6 +7,7 @@ import { ChatHistoryItemType } from '@fastgpt/global/core/chat/type';
|
||||
import { ClearHistoriesProps, DelHistoryProps, UpdateHistoryProps } from '@/global/core/chat/api';
|
||||
import { useDisclosure } from '@chakra-ui/react';
|
||||
import { useChatStore } from './storeChat';
|
||||
import { getNanoid } from '@fastgpt/global/common/string/tools';
|
||||
|
||||
type ChatContextValueType = {
|
||||
histories: ChatHistoryItemType[];
|
||||
@@ -66,7 +67,6 @@ const ChatContextProvider = ({
|
||||
}: ChatContextValueType & { children: ReactNode }) => {
|
||||
const router = useRouter();
|
||||
const { chatId = '' } = router.query as { chatId: string };
|
||||
const isSystemChat = router.pathname === '/chat';
|
||||
|
||||
const forbidLoadChat = useRef(false);
|
||||
|
||||
@@ -74,7 +74,7 @@ const ChatContextProvider = ({
|
||||
|
||||
const { setLastChatId } = useChatStore();
|
||||
const onChangeChatId = useCallback(
|
||||
(changeChatId = '', forbid = false) => {
|
||||
(changeChatId = getNanoid(), forbid = false) => {
|
||||
if (chatId !== changeChatId) {
|
||||
forbidLoadChat.current = forbid;
|
||||
setLastChatId(changeChatId);
|
||||
|
@@ -15,6 +15,7 @@ type State = {
|
||||
initUserInfo: () => Promise<UserType>;
|
||||
setUserInfo: (user: UserType | null) => void;
|
||||
updateUserInfo: (user: UserUpdateParams) => Promise<void>;
|
||||
|
||||
teamPlanStatus: FeTeamPlanStatusType | null;
|
||||
initTeamPlanStatus: () => Promise<any>;
|
||||
};
|
||||
@@ -68,6 +69,7 @@ export const useUserStore = create<State>()(
|
||||
return Promise.reject(error);
|
||||
}
|
||||
},
|
||||
// team
|
||||
teamPlanStatus: null,
|
||||
initTeamPlanStatus() {
|
||||
return getTeamPlanStatus().then((res) => {
|
||||
|
Reference in New Issue
Block a user