From 0311e5f3f39595adb2dab06eb437cf60b2358d50 Mon Sep 17 00:00:00 2001 From: arvinxx Date: Sun, 22 Oct 2023 13:24:31 +0800 Subject: [PATCH] :bug: fix: fix import --- src/ChatList/Item.tsx | 4 +- src/EditableMessageList/messageReducer.ts | 2 +- .../components/ChatList/Actions/Fallback.tsx | 3 +- .../components/ChatList/Actions/Function.tsx | 3 +- .../components/ChatList/Actions/User.tsx | 3 +- .../components/ChatList/Actions/index.ts | 2 +- .../components/ChatList/Extras/index.ts | 2 +- .../ChatList/Messages/Assistant.tsx | 2 +- .../components/ChatList/Messages/Default.tsx | 2 +- .../components/ChatList/Messages/index.ts | 2 +- src/ProChat/components/ChatList/index.tsx | 2 +- src/ProChat/index.tsx | 2 +- src/ProChat/store/action.ts | 2 +- src/ProChat/store/initialState.ts | 2 +- src/ProChat/store/reducers/message.test.ts | 2 +- src/ProChat/store/reducers/message.ts | 2 +- src/ProChat/store/selectors/chat.ts | 2 +- src/ProChat/types/chat.ts | 2 +- src/ProChat/utils/fetch.ts | 2 +- src/ProChat/utils/message.ts | 2 +- src/types/chatMessage.ts | 52 ------------------- src/types/index.ts | 2 +- src/{ProChat => }/types/message.ts | 5 ++ 23 files changed, 30 insertions(+), 74 deletions(-) delete mode 100644 src/types/chatMessage.ts rename src/{ProChat => }/types/message.ts (88%) diff --git a/src/ChatList/Item.tsx b/src/ChatList/Item.tsx index bdeb555c..0b28cbf8 100644 --- a/src/ChatList/Item.tsx +++ b/src/ChatList/Item.tsx @@ -4,8 +4,8 @@ import { FC, ReactNode, memo, useCallback, useMemo, useState } from 'react'; import { ActionEvent } from '@/ActionIconGroup'; import ChatItem, { type ChatItemProps } from '@/ChatItem'; -import { ChatMessage } from '@/types/chatMessage'; import { LLMRoleType } from '@/types/llm'; +import { ChatMessage } from '@/types/message'; import ActionsBar, { type ActionsBarProps } from './ActionsBar'; @@ -192,7 +192,7 @@ const Item = memo((props) => { return ( } - avatar={item.meta} + avatar={(item as any).meta} avatarAddon={groupNav} editing={editing} error={error} diff --git a/src/EditableMessageList/messageReducer.ts b/src/EditableMessageList/messageReducer.ts index 81d3951e..c1ac2e89 100644 --- a/src/EditableMessageList/messageReducer.ts +++ b/src/EditableMessageList/messageReducer.ts @@ -1,7 +1,7 @@ import { produce } from 'immer'; -import { ChatMessageError } from '@/types/chatMessage'; import { LLMMessage, LLMRoleType } from '@/types/llm'; +import { ChatMessageError } from '@/types/message'; export type MessageDispatch = | { message: LLMMessage; type: 'addMessage' } diff --git a/src/ProChat/components/ChatList/Actions/Fallback.tsx b/src/ProChat/components/ChatList/Actions/Fallback.tsx index d4ebc070..98e66f64 100644 --- a/src/ProChat/components/ChatList/Actions/Fallback.tsx +++ b/src/ProChat/components/ChatList/Actions/Fallback.tsx @@ -1,5 +1,6 @@ +import ActionIconGroup from '@/ActionIconGroup'; +import { RenderAction } from '@/ChatList'; import { useChatListActionsBar } from '@/hooks/useChatListActionsBar'; -import { ActionIconGroup, RenderAction } from '@lobehub/ui'; import { memo } from 'react'; export const DefaultActionsBar: RenderAction = memo(({ text, onActionClick }) => { diff --git a/src/ProChat/components/ChatList/Actions/Function.tsx b/src/ProChat/components/ChatList/Actions/Function.tsx index c8193f36..98d3fbbf 100644 --- a/src/ProChat/components/ChatList/Actions/Function.tsx +++ b/src/ProChat/components/ChatList/Actions/Function.tsx @@ -1,5 +1,6 @@ +import ActionIconGroup from '@/ActionIconGroup'; +import { RenderAction } from '@/ChatList'; import { useChatListActionsBar } from '@/hooks/useChatListActionsBar'; -import { ActionIconGroup, RenderAction } from '@lobehub/ui'; import { memo } from 'react'; export const FunctionActionsBar: RenderAction = memo(({ text, onActionClick }) => { diff --git a/src/ProChat/components/ChatList/Actions/User.tsx b/src/ProChat/components/ChatList/Actions/User.tsx index ab1788d0..b0b191c4 100644 --- a/src/ProChat/components/ChatList/Actions/User.tsx +++ b/src/ProChat/components/ChatList/Actions/User.tsx @@ -1,5 +1,6 @@ +import ActionIconGroup from '@/ActionIconGroup'; +import { RenderAction } from '@/ChatList'; import { useChatListActionsBar } from '@/hooks/useChatListActionsBar'; -import { ActionIconGroup, RenderAction } from '@lobehub/ui'; import { memo } from 'react'; export const UserActionsBar: RenderAction = memo(({ text, onActionClick }) => { diff --git a/src/ProChat/components/ChatList/Actions/index.ts b/src/ProChat/components/ChatList/Actions/index.ts index a87084cf..23d2c026 100644 --- a/src/ProChat/components/ChatList/Actions/index.ts +++ b/src/ProChat/components/ChatList/Actions/index.ts @@ -1,4 +1,4 @@ -import { ChatListProps } from '@lobehub/ui'; +import { ChatListProps } from '@/ChatList'; import { AssistantActionsBar } from './Assistant'; import { DefaultActionsBar } from './Fallback'; diff --git a/src/ProChat/components/ChatList/Extras/index.ts b/src/ProChat/components/ChatList/Extras/index.ts index 2b7fc63a..2bb03970 100644 --- a/src/ProChat/components/ChatList/Extras/index.ts +++ b/src/ProChat/components/ChatList/Extras/index.ts @@ -1,4 +1,4 @@ -import { ChatListProps } from '@lobehub/ui'; +import { ChatListProps } from '@/ChatList'; import { AssistantMessageExtra } from './Assistant'; import { UserMessageExtra } from './User'; diff --git a/src/ProChat/components/ChatList/Messages/Assistant.tsx b/src/ProChat/components/ChatList/Messages/Assistant.tsx index 1919c17c..44460804 100644 --- a/src/ProChat/components/ChatList/Messages/Assistant.tsx +++ b/src/ProChat/components/ChatList/Messages/Assistant.tsx @@ -1,4 +1,4 @@ -import { RenderMessage } from '@lobehub/ui'; +import { RenderMessage } from '@/ChatList'; import { memo } from 'react'; import { DefaultMessage } from './Default'; diff --git a/src/ProChat/components/ChatList/Messages/Default.tsx b/src/ProChat/components/ChatList/Messages/Default.tsx index f6c36519..7b747363 100644 --- a/src/ProChat/components/ChatList/Messages/Default.tsx +++ b/src/ProChat/components/ChatList/Messages/Default.tsx @@ -1,4 +1,4 @@ -import { RenderMessage } from '@lobehub/ui'; +import { RenderMessage } from '@/ChatList'; import { memo } from 'react'; import { LOADING_FLAT } from '@/ProChat/const/message'; diff --git a/src/ProChat/components/ChatList/Messages/index.ts b/src/ProChat/components/ChatList/Messages/index.ts index 7f4567f1..c24d4d61 100644 --- a/src/ProChat/components/ChatList/Messages/index.ts +++ b/src/ProChat/components/ChatList/Messages/index.ts @@ -1,4 +1,4 @@ -import { ChatListProps } from '@lobehub/ui'; +import { ChatListProps } from '@/ChatList'; import { AssistantMessage } from './Assistant'; import { DefaultMessage } from './Default'; diff --git a/src/ProChat/components/ChatList/index.tsx b/src/ProChat/components/ChatList/index.tsx index a35b8922..eda96780 100644 --- a/src/ProChat/components/ChatList/index.tsx +++ b/src/ProChat/components/ChatList/index.tsx @@ -1,4 +1,4 @@ -import { ChatList } from '@lobehub/ui'; +import ChatList from '@/ChatList'; import isEqual from 'fast-deep-equal'; import { memo } from 'react'; diff --git a/src/ProChat/index.tsx b/src/ProChat/index.tsx index 6def1c47..2d689594 100644 --- a/src/ProChat/index.tsx +++ b/src/ProChat/index.tsx @@ -1,2 +1,2 @@ +export * from '../types/message'; export { ProChat } from './container'; -export * from './types/message'; diff --git a/src/ProChat/store/action.ts b/src/ProChat/store/action.ts index 99a05fbf..762755a9 100644 --- a/src/ProChat/store/action.ts +++ b/src/ProChat/store/action.ts @@ -3,11 +3,11 @@ import { StateCreator } from 'zustand/vanilla'; import { LOADING_FLAT } from '@/ProChat/const/message'; import { ChatStore } from '@/ProChat/store/index'; -import { ChatMessage } from '@/ProChat/types/message'; import { fetchSSE } from '@/ProChat/utils/fetch'; import { isFunctionMessage } from '@/ProChat/utils/message'; import { setNamespace } from '@/ProChat/utils/storeDebug'; import { nanoid } from '@/ProChat/utils/uuid'; +import { ChatMessage } from '@/types/message'; import { initialModelConfig } from '@/ProChat/store/initialState'; import { ChatStreamPayload } from '@/ProChat/types/chat'; diff --git a/src/ProChat/store/initialState.ts b/src/ProChat/store/initialState.ts index f82d3971..785c0053 100644 --- a/src/ProChat/store/initialState.ts +++ b/src/ProChat/store/initialState.ts @@ -1,7 +1,7 @@ import { DEFAULT_AVATAR, DEFAULT_USER_AVATAR } from '@/ProChat/const/meta'; import { ModelConfig } from '@/ProChat/types/config'; -import { ChatMessage, ChatMessageMap } from '@/ProChat/types/message'; import { MetaData } from '@/ProChat/types/meta'; +import { ChatMessage, ChatMessageMap } from '@/types/message'; export type ChatRequest = (messages: ChatMessage[], config: ModelConfig) => Promise; diff --git a/src/ProChat/store/reducers/message.test.ts b/src/ProChat/store/reducers/message.test.ts index 08e0c9ff..6dda72b8 100644 --- a/src/ProChat/store/reducers/message.test.ts +++ b/src/ProChat/store/reducers/message.test.ts @@ -1,4 +1,4 @@ -import { ChatMessageMap } from '@/ProChat/types/message'; +import { ChatMessageMap } from '@/types/message'; import { MessageDispatch, messagesReducer } from './message'; diff --git a/src/ProChat/store/reducers/message.ts b/src/ProChat/store/reducers/message.ts index cd28acda..48fdb8eb 100644 --- a/src/ProChat/store/reducers/message.ts +++ b/src/ProChat/store/reducers/message.ts @@ -1,8 +1,8 @@ import { produce } from 'immer'; -import { ChatMessage, ChatMessageMap } from '@/ProChat/types/message'; import { nanoid } from '@/ProChat/utils/uuid'; import { LLMRoleType } from '@/types/llm'; +import { ChatMessage, ChatMessageMap } from '@/types/message'; import { MetaData } from '@/types/meta'; interface AddMessage { diff --git a/src/ProChat/store/selectors/chat.ts b/src/ProChat/store/selectors/chat.ts index 5c86b242..8b6bd9b1 100644 --- a/src/ProChat/store/selectors/chat.ts +++ b/src/ProChat/store/selectors/chat.ts @@ -1,4 +1,4 @@ -import { ChatMessage } from '@/ProChat/types/message'; +import { ChatMessage } from '@/types/message'; import { MetaData } from '@/ProChat/types/meta'; import { getSlicedMessagesWithConfig } from '../../utils/message'; diff --git a/src/ProChat/types/chat.ts b/src/ProChat/types/chat.ts index cc0fdfa3..009a69a9 100644 --- a/src/ProChat/types/chat.ts +++ b/src/ProChat/types/chat.ts @@ -1,5 +1,5 @@ -import { OpenAIFunctionCall } from '@/types/chatMessage'; import { LLMRoleType } from '@/types/llm'; +import { OpenAIFunctionCall } from '@/types/message'; export interface OpenAIChatMessage { /** diff --git a/src/ProChat/utils/fetch.ts b/src/ProChat/utils/fetch.ts index 8ca61545..22213d61 100644 --- a/src/ProChat/utils/fetch.ts +++ b/src/ProChat/utils/fetch.ts @@ -1,4 +1,4 @@ -import { ChatMessageError } from '@/types/chatMessage'; +import { ChatMessageError } from '../../types/message'; export const getMessageError = async (response: Response) => { let chatMessageError: ChatMessageError; diff --git a/src/ProChat/utils/message.ts b/src/ProChat/utils/message.ts index 6f1dcf89..ad46ce94 100644 --- a/src/ProChat/utils/message.ts +++ b/src/ProChat/utils/message.ts @@ -1,6 +1,6 @@ import { FUNCTION_MESSAGE_FLAG } from '@/ProChat/const/message'; import { ModelConfig } from '@/ProChat/types/config'; -import { ChatMessage } from '@/ProChat/types/message'; +import { ChatMessage } from '@/types/message'; export const isFunctionMessage = (content: string) => { return content.startsWith(FUNCTION_MESSAGE_FLAG); diff --git a/src/types/chatMessage.ts b/src/types/chatMessage.ts deleted file mode 100644 index 7d1cbdd0..00000000 --- a/src/types/chatMessage.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { PluginRequestPayload } from '@lobehub/chat-plugin-sdk'; - -import { ErrorType } from './error'; -import { LLMRoleType } from './llm'; -import { BaseDataModel } from './meta'; - -/** - * 聊天消息错误对象 - */ -export interface ChatMessageError { - body?: any; - message: string; - type: ErrorType; -} -export interface OpenAIFunctionCall { - arguments?: string; - name: string; -} - -export interface ChatMessage extends BaseDataModel { - /** - * @title 内容 - * @description 消息内容 - */ - content: string; - error?: any; - // 扩展字段 - extra?: any; - - /** - * replace with plugin - * @deprecated - */ - function_call?: OpenAIFunctionCall; - name?: string; - - parentId?: string; - - plugin?: PluginRequestPayload; - - // 引用 - quotaId?: string; - /** - * 角色 - * @description 消息发送者的角色 - */ - role: LLMRoleType; - /** - * 保存到主题的消息 - */ - topicId?: string; -} diff --git a/src/types/index.ts b/src/types/index.ts index e072d651..04ac9ea8 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,9 +1,9 @@ import { type HTMLAttributes } from 'react'; -export * from './chatMessage'; export * from './customStylish'; export * from './customToken'; export * from './llm'; +export * from './message'; export * from './meta'; export type DivProps = HTMLAttributes; diff --git a/src/ProChat/types/message.ts b/src/types/message.ts similarity index 88% rename from src/ProChat/types/message.ts rename to src/types/message.ts index 42c2869f..1e48971e 100644 --- a/src/ProChat/types/message.ts +++ b/src/types/message.ts @@ -31,3 +31,8 @@ export interface ChatMessage { } export type ChatMessageMap = Record; + +export interface OpenAIFunctionCall { + arguments?: string; + name: string; +}