add canSend flag

This commit is contained in:
Emily
2024-12-18 17:11:42 +01:00
parent 29bae329b4
commit 7082b88523

View File

@@ -23,6 +23,7 @@ const { data: chatsRemaining, refresh: reloadChatsRemaining } = useFetch(`/api/a
const currentText = ref<string>(""); const currentText = ref<string>("");
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
const canSend = ref<boolean>(false);
const currentChatId = ref<string>(""); const currentChatId = ref<string>("");
const currentChatMessages = ref<{ role: string, content: string, charts?: any[], tool_calls?: any }[]>([]); const currentChatMessages = ref<{ role: string, content: string, charts?: any[], tool_calls?: any }[]>([]);
@@ -108,6 +109,8 @@ async function sendMessage() {
try { try {
canSend.value = false;
const res = await $fetch<{ chat_id: string }>(`/api/ai/send_message`, { method: 'POST', body: JSON.stringify(body), headers: useComputedHeaders({ useSnapshotDates: false, custom: { 'Content-Type': 'application/json' } }).value }); const res = await $fetch<{ chat_id: string }>(`/api/ai/send_message`, { method: 'POST', body: JSON.stringify(body), headers: useComputedHeaders({ useSnapshotDates: false, custom: { 'Content-Type': 'application/json' } }).value });
currentChatId.value = res.chat_id; currentChatId.value = res.chat_id;
@@ -125,6 +128,8 @@ async function sendMessage() {
currentChatMessageDelta.value = status; currentChatMessageDelta.value = status;
}); });
canSend.value = true;
} catch (ex: any) { } catch (ex: any) {
if (ex.message.includes('CHAT_LIMIT_REACHED')) { if (ex.message.includes('CHAT_LIMIT_REACHED')) {
@@ -141,6 +146,10 @@ async function sendMessage() {
}); });
} }
currentChatMessages.value.push({ role: 'assistant', content: ex.message, });
canSend.value = true;
} }
@@ -153,7 +162,8 @@ async function openChat(chat_id?: string) {
if (!project.value) return; if (!project.value) return;
typer.stop(); typer.stop();
canSend.value = true;
currentChatMessages.value = []; currentChatMessages.value = [];
currentChatMessageDelta.value = ''; currentChatMessageDelta.value = '';