2023-11-29 03:13:55 -08:00
|
|
|
<script setup lang="ts">
|
2024-01-09 07:37:05 -08:00
|
|
|
import { nextTick, onMounted } from 'vue';
|
2024-01-09 03:11:39 -08:00
|
|
|
import Layout from '@n8n/chat/components/Layout.vue';
|
|
|
|
import GetStarted from '@n8n/chat/components/GetStarted.vue';
|
|
|
|
import GetStartedFooter from '@n8n/chat/components/GetStartedFooter.vue';
|
|
|
|
import MessagesList from '@n8n/chat/components/MessagesList.vue';
|
|
|
|
import Input from '@n8n/chat/components/Input.vue';
|
|
|
|
import { useI18n, useChat, useOptions } from '@n8n/chat/composables';
|
|
|
|
import { chatEventBus } from '@n8n/chat/event-buses';
|
2023-11-29 03:13:55 -08:00
|
|
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
const chatStore = useChat();
|
|
|
|
|
|
|
|
const { messages, currentSessionId } = chatStore;
|
2024-01-09 03:11:39 -08:00
|
|
|
const { options } = useOptions();
|
2023-11-29 03:13:55 -08:00
|
|
|
|
2024-01-09 03:11:39 -08:00
|
|
|
async function getStarted() {
|
|
|
|
void chatStore.startNewSession();
|
2023-11-29 03:13:55 -08:00
|
|
|
void nextTick(() => {
|
|
|
|
chatEventBus.emit('scrollToBottom');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-09 03:11:39 -08:00
|
|
|
async function initialize() {
|
|
|
|
await chatStore.loadPreviousSession();
|
2023-11-29 03:13:55 -08:00
|
|
|
void nextTick(() => {
|
|
|
|
chatEventBus.emit('scrollToBottom');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-09 03:11:39 -08:00
|
|
|
onMounted(async () => {
|
|
|
|
await initialize();
|
|
|
|
if (!options.showWelcomeScreen && !currentSessionId.value) {
|
|
|
|
await getStarted();
|
|
|
|
}
|
2023-11-29 03:13:55 -08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<Layout class="chat-wrapper">
|
2024-01-09 03:11:39 -08:00
|
|
|
<template #header>
|
2023-11-29 03:13:55 -08:00
|
|
|
<h1>{{ t('title') }}</h1>
|
|
|
|
<p>{{ t('subtitle') }}</p>
|
|
|
|
</template>
|
2024-01-09 03:11:39 -08:00
|
|
|
<GetStarted v-if="!currentSessionId && options.showWelcomeScreen" @click:button="getStarted" />
|
2023-11-29 03:13:55 -08:00
|
|
|
<MessagesList v-else :messages="messages" />
|
|
|
|
<template #footer>
|
|
|
|
<Input v-if="currentSessionId" />
|
|
|
|
<GetStartedFooter v-else />
|
|
|
|
</template>
|
|
|
|
</Layout>
|
|
|
|
</template>
|