diff --git a/src/components/chat/Sidebar.vue b/src/components/chat/Sidebar.vue index 3aa6fead..cb2a8049 100644 --- a/src/components/chat/Sidebar.vue +++ b/src/components/chat/Sidebar.vue @@ -64,12 +64,21 @@ import { defineComponent } from 'vue'; import { ElSkeleton, ElInput } from 'element-plus'; import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; import { ROUTE_CHAT_CONVERSATION } from '@/router/constants'; -import { apiUsageOperator, IApplication, chatOperator } from '@/operators'; +import { apiUsageOperator, IApplication, chatOperator, applicationOperator } from '@/operators'; import { IChatConversation } from '@/operators/chat/models'; +import { + CHAT_MODEL_CHATGPT, + CHAT_MODEL_CHATGPT4, + CHAT_MODEL_CHATGPT4_BROWSING, + CHAT_MODEL_CHATGPT_16K, + CHAT_MODEL_CHATGPT_BROWSING +} from '@/operators'; interface IData { + initializing: boolean; loading: boolean; conversations: IChatConversation[] | undefined; + applications: IApplication[] | undefined; } export default defineComponent({ @@ -79,45 +88,61 @@ export default defineComponent({ FontAwesomeIcon, ElSkeleton }, - props: { - applications: { - type: Object as () => IApplication[], - required: true - } - }, + props: {}, emits: ['click'], data(): IData { return { + initializing: false, loading: false, - conversations: undefined + conversations: undefined, + applications: undefined }; }, watch: { applications(val) { if (val) { - this.onFetchAllConversations(); + this.onFetchConversations(); } } }, - mounted() {}, + async mounted() { + await this.onFetchApplications(); + await this.onFetchConversations(); + }, methods: { + async onFetchApplications() { + this.initializing = true; + const { data: applications } = await applicationOperator.getAll({ + user_id: this.$store.state.user.id, + api_id: [ + CHAT_MODEL_CHATGPT.apiId, + CHAT_MODEL_CHATGPT_16K.apiId, + CHAT_MODEL_CHATGPT_BROWSING.apiId, + CHAT_MODEL_CHATGPT4.apiId, + CHAT_MODEL_CHATGPT4_BROWSING.apiId + ] + }); + this.initializing = false; + this.applications = applications?.items; + }, async onConfirm(conversation: IChatConversation) { if (conversation?.deleting) { await chatOperator.deleteConversation(conversation.id); - await this.onFetchAllConversations(); + await this.onFetchConversations(); } else if (conversation?.editing) { await chatOperator.updateConversation(conversation); - this.onFetchAllConversations(); + this.onFetchConversations(); } else { conversation.editing = true; } }, - async onFetchAllConversations() { + async onFetchConversations() { this.loading = true; const { data: { items: apiUsages } } = await apiUsageOperator.getAll({ user_id: this.$store.state.user.id, + // @ts-ignore application_id: this.applications?.map((application) => application.id), offset: 0, limit: 30, diff --git a/src/components/common/LeftNavigator.vue b/src/components/common/LeftNavigator.vue deleted file mode 100644 index d944f9b1..00000000 --- a/src/components/common/LeftNavigator.vue +++ /dev/null @@ -1,116 +0,0 @@ - - - - - diff --git a/src/components/common/NavigatorItem.vue b/src/components/common/NavigatorItem.vue deleted file mode 100644 index 4476b43b..00000000 --- a/src/components/common/NavigatorItem.vue +++ /dev/null @@ -1,59 +0,0 @@ - - - - - diff --git a/src/layouts/Chat.vue b/src/layouts/Chat.vue new file mode 100644 index 00000000..fde47bd7 --- /dev/null +++ b/src/layouts/Chat.vue @@ -0,0 +1,54 @@ + + + + + diff --git a/src/layouts/Conversation.vue b/src/layouts/Conversation.vue deleted file mode 100644 index a5025f11..00000000 --- a/src/layouts/Conversation.vue +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - diff --git a/src/pages/chat/Conversation.vue b/src/pages/chat/Conversation.vue index ad16ea77..14bd0c3c 100644 --- a/src/pages/chat/Conversation.vue +++ b/src/pages/chat/Conversation.vue @@ -1,24 +1,21 @@ @@ -47,12 +44,11 @@ import ModelSelector from '@/components/chat/ModelSelector.vue'; import { ERROR_CODE_CANCELED, ERROR_CODE_UNKNOWN } from '@/constants/errorCode'; import ApiStatus from '@/components/common/ApiStatus.vue'; import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW } from '@/router'; -import Sidebar from '@/components/chat/Sidebar.vue'; export interface IData { messages: IChatMessage[]; model: IChatModel; - applications: IApplication[]; + applications: IApplication[] | undefined; question: ''; initializing: boolean; applied: boolean | undefined; @@ -64,8 +60,7 @@ export default defineComponent({ InputBox, ModelSelector, Message, - ApiStatus, - Sidebar + ApiStatus }, data(): IData { return { @@ -73,7 +68,7 @@ export default defineComponent({ question: '', initializing: false, applied: undefined, - applications: [], + applications: undefined, messages: [] }; }, @@ -82,11 +77,17 @@ export default defineComponent({ return this.$route.params.id?.toString(); }, application() { - return this.applications.find((application) => application.api?.id === this.model.apiId); + return this.applications?.find((application) => application.api?.id === this.model.apiId); + } + }, + watch: { + conversationId(val) { + if (val) { + this.onFetchHistory(val); + } } }, async mounted() { - console.log('mounted'); await this.onFetchApplications(); await this.onFetchHistory(); }, @@ -203,44 +204,28 @@ export default defineComponent({