Edit the artificial intelligence of the Mentact assistant
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { api } from '@/lib/api';
|
||||
import { formatMoney } from '@/lib/money';
|
||||
@@ -89,6 +89,10 @@ async function submitAsk(preset?: string) {
|
||||
const { data } = await api.post<AskMentoResponse>('/ai/ask', { question: q });
|
||||
askAnswer.value = data.answer;
|
||||
askSources.value = data.sources ?? [];
|
||||
await nextTick();
|
||||
document
|
||||
.getElementById('home-ai-assistant')
|
||||
?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||||
} catch (e) {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
||||
@@ -101,7 +105,18 @@ async function submitAsk(preset?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function onAskHotkey(e: KeyboardEvent) {
|
||||
if (!(e.metaKey || e.ctrlKey) || e.key.toLowerCase() !== 'k') return;
|
||||
const tag = (e.target as HTMLElement | null)?.tagName;
|
||||
if (tag === 'TEXTAREA' || (tag === 'INPUT' && (e.target as HTMLInputElement).id !== 'home-hero-ask')) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
document.getElementById('home-hero-ask')?.focus();
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
window.addEventListener('keydown', onAskHotkey);
|
||||
loading.value = true;
|
||||
try {
|
||||
const [homeRes, actRes, boardRes] = await Promise.all([
|
||||
@@ -120,6 +135,10 @@ onMounted(async () => {
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('keydown', onAskHotkey);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -129,6 +148,9 @@ onMounted(async () => {
|
||||
:first-name="firstName"
|
||||
:user-initial="userInitial"
|
||||
:alerts="home?.alerts ?? []"
|
||||
:asking="asking"
|
||||
:ask-answer="askAnswer"
|
||||
:ask-error="askError"
|
||||
v-model:ask-query="askQuery"
|
||||
@ask="submitAsk"
|
||||
/>
|
||||
@@ -152,6 +174,7 @@ onMounted(async () => {
|
||||
/>
|
||||
<HomeSourcesChart :sources="home?.sources ?? []" />
|
||||
<HomeAiAssistant
|
||||
id="home-ai-assistant"
|
||||
v-model:ask-query="askQuery"
|
||||
:asking="asking"
|
||||
:answer="askAnswer"
|
||||
|
||||
Reference in New Issue
Block a user