diff --git a/app.vue b/app.vue
index d926bd7..6613179 100644
--- a/app.vue
+++ b/app.vue
@@ -1,8 +1,6 @@
-
+
-
-
-
-
+
+
\ No newline at end of file
diff --git a/components/Conversation.vue b/components/Conversation.vue
index 2fcb0c5..689ec6c 100644
--- a/components/Conversation.vue
+++ b/components/Conversation.vue
@@ -25,8 +25,6 @@ const processMessageQueue = () => {
}
isProcessingQueue = true
const nextMessage = messageQueue.shift()
- console.log(runtimeConfig.public.typewriter)
- // console.log(process.env.NUXT_PUBLIC_TYPEWRITER)
if (runtimeConfig.public.typewriter) {
let wordIndex = 0;
const intervalId = setInterval(() => {
@@ -111,7 +109,7 @@ const fetchReply = async (message) => {
if (event === 'done') {
abortFetch()
props.conversation.messages[props.conversation.messages.length - 1].id = data.messageId
- if (!props.conversation.topic || props.conversation.topic === '') {
+ if (!props.conversation.id) {
props.conversation.id = data.conversationId
genTitle(props.conversation.id)
}
@@ -139,12 +137,6 @@ const scrollChatWindow = () => {
grab.value.scrollIntoView({behavior: 'smooth'})
}
-const checkOrAddConversation = () => {
- if (props.conversation.messages.length === 0) {
- props.conversation.messages.push({id: null, is_bot: true, message: ''})
- }
-}
-
const send = (message) => {
fetchingResponse.value = true
if (props.conversation.messages.length === 0) {
diff --git a/components/NavigationDrawer.vue b/components/NavigationDrawer.vue
new file mode 100644
index 0000000..dcf4d8c
--- /dev/null
+++ b/components/NavigationDrawer.vue
@@ -0,0 +1,338 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ (conversation.topic && conversation.topic !== '') ? conversation.topic : $t('defaultConversationTitle') }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Are you sure you want to delete all conversations?
+
+ This will be a permanent deletion and cannot be retrieved once deleted. Please proceed with caution.
+
+
+
+ Cancel deletion
+
+
+ Confirm deletion
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ theme.title }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/composables/fetch.js b/composables/fetch.js
index 558a521..ca9d7f9 100644
--- a/composables/fetch.js
+++ b/composables/fetch.js
@@ -2,6 +2,7 @@ export const useMyFetch = (url, options = {}) => {
let defaultOptions = {
headers: {
Accept: 'application/json',
+ 'Content-Type': 'application/json',
}
}
if (process.server) {
diff --git a/composables/states.js b/composables/states.js
index 1af12d9..629a650 100644
--- a/composables/states.js
+++ b/composables/states.js
@@ -5,10 +5,10 @@ export const useCurrentModel = () => useState('currentModel', () => getCurrentMo
export const useApiKey = () => useState('apiKey', () => getStoredApiKey())
-export const useConversation = () => useState('conversation', () => getDefaultConversationData())
-
export const useConversations = () => useState('conversations', () => [])
export const useSettings = () => useState('settings', () => getSystemSettings())
-export const useUser = () => useState('user', () => null)
\ No newline at end of file
+export const useUser = () => useState('user', () => null)
+
+export const useDrawer = () => useState('drawer', () => false)
\ No newline at end of file
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index 79f830b..74844de 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -5,6 +5,7 @@ services:
build: .
environment:
SERVER_DOMAIN: ${SERVER_DOMAIN:-http://web-server}
+ NUXT_PUBLIC_TYPEWRITER: false
ports:
- '${CLIENT_PORT:-80}:80'
networks:
diff --git a/layouts/default.vue b/layouts/default.vue
index aff834e..bd80e69 100644
--- a/layouts/default.vue
+++ b/layouts/default.vue
@@ -1,382 +1,8 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ (conversation.topic && conversation.topic !== '') ? conversation.topic : $t('defaultConversationTitle') }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Are you sure you want to delete all conversations?
-
- This will be a permanent deletion and cannot be retrieved once deleted. Please proceed with caution.
-
-
-
- Cancel deletion
-
-
- Confirm deletion
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ theme.title }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ navTitle }}
-
-
-
-
-
- {{ $t('newConversation') }}
-
-
-
-
-
-
-
-
+
+
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/nuxt.config.ts b/nuxt.config.ts
index 0b814dc..e14d24f 100644
--- a/nuxt.config.ts
+++ b/nuxt.config.ts
@@ -68,14 +68,5 @@ export default defineNuxtConfig({
vueI18n: {
fallbackLocale: 'en',
},
- },
- // nitro: {
- // devProxy: {
- // "/api": {
- // target: process.env.NUXT_DEV_SERVER ?? 'http://localhost:8000/api',
- // changeOrigin: true,
- // }
- //
- // }
- // },
+ }
})
diff --git a/pages/index.vue b/pages/index.vue
index 5df1d30..69de168 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -4,8 +4,11 @@ definePageMeta({
path: '/:id?',
keepalive: true
})
+
+const { $i18n } = useNuxtApp()
+const runtimeConfig = useRuntimeConfig()
+const drawer = useDrawer()
const route = useRoute()
-const currentConversation = useConversation()
const conversation = ref(getDefaultConversationData())
const loadConversation = async () => {
@@ -22,31 +25,67 @@ const loadMessage = async () => {
}
}
-const updateCurrentConversation = () => {
- currentConversation.value = Object.assign({}, conversation.value)
+const createNewConversation = () => {
+ if (route.path !== '/') {
+ return navigateTo('/?new')
+ }
+ conversation.value = Object.assign(getDefaultConversationData(), {
+ topic: $i18n.t('newConversation')
+ })
}
+
onMounted(async () => {
if (route.params.id) {
conversation.value.loadingMessages = true
await loadConversation()
await loadMessage()
conversation.value.loadingMessages = false
- updateCurrentConversation()
- } else {
- watch(currentConversation, (val) => {
- conversation.value = Object.assign({}, val)
- })
}
})
+
+const navTitle = computed(() => {
+ if (conversation.value && conversation.value.topic !== null) {
+ return conversation.value.topic === '' ? $i18n.t('defaultConversationTitle') : conversation.value.topic
+ }
+ return runtimeConfig.public.appName
+})
+
onActivated(async () => {
- updateCurrentConversation()
+ if (route.path === '/' && route.query.new !== undefined) {
+ createNewConversation()
+ }
})
-
-
+
+
+
+ {{ navTitle }}
+
+
+
+
+
+ {{ $t('newConversation') }}
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/server/middleware/apiProxy.ts b/server/middleware/apiProxy.ts
index 4a0c4e6..623ba68 100644
--- a/server/middleware/apiProxy.ts
+++ b/server/middleware/apiProxy.ts
@@ -1,10 +1,34 @@
-import { createProxyMiddleware, Filter, Options, RequestHandler } from 'http-proxy-middleware'
-export default defineEventHandler((event) => {
+import {getRequestURL} from "h3";
+
+const PayloadMethods = new Set(["PATCH", "POST", "PUT", "DELETE"]);
+
+export default defineEventHandler(async (event) => {
// @ts-ignore
if (event.node.req.url.startsWith('/api/')) {
- return proxyRequest(
- event,
- (process.env.SERVER_DOMAIN || 'http://localhost:8000') + event.node.req.url
- )
+ // TODO: fix fetch failed
+ const target = (process.env.SERVER_DOMAIN || 'http://localhost:8000') + event.node.req.url
+ // Method
+ const method = getMethod(event)
+ // Body
+ let body;
+ if (PayloadMethods.has(method)) {
+ body = await readRawBody(event).catch(() => undefined);
+ }
+ // Headers
+ const headers = getProxyRequestHeaders(event);
+
+ if (method === 'DELETE') {
+ delete headers['content-length']
+ }
+
+ return sendProxy(event, target, {
+ sendStream: event.node.req.url === '/api/conversation/',
+ fetchOptions: {
+ headers,
+ method,
+ body,
+ },
+ });
+
}
})
diff --git a/utils/helper.js b/utils/helper.js
index 3de8922..85a8719 100644
--- a/utils/helper.js
+++ b/utils/helper.js
@@ -17,19 +17,6 @@ export const getConversations = async () => {
return []
}
-export const createNewConversation = () => {
- const route = useRoute()
- const { $i18n } = useNuxtApp()
- const currentConversation = useConversation()
- currentConversation.value = Object.assign(getDefaultConversationData(), {
- topic: $i18n.t('newConversation')
- })
- if (route.path !== '/') {
- return navigateTo('/')
- }
-}
-
-
export const addConversation = (conversation) => {
const conversations = useConversations()
conversations.value = [conversation, ...conversations.value]
@@ -46,17 +33,12 @@ export const genTitle = async (conversationId) => {
}
})
if (!error.value) {
- const route = useRoute()
const conversations = useConversations()
- const currentConversation = useConversation()
let index = conversations.value.findIndex(item => item.id === conversationId)
if (index === -1) {
index = 0
}
conversations.value[index].topic = data.value.title
- if (route.path === '/') {
- currentConversation.value.topic = data.value.title
- }
return data.value.title
}
return null