Skip to content

Commit

Permalink
refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
iceljc committed Oct 1, 2024
1 parent 0f51dac commit e1503bf
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@
refresh();
autoScrollLog = false;
window.addEventListener('message', async e => {
window.addEventListener('message', e => {
if (e.data.action === ChatAction.Logout) {
handleLogoutAction();
} else if (e.data.action === ChatAction.NewChat) {
await handleNewChatAction(e);
handleNewChatAction(e);
} else if (e.data.action === ChatAction.Chat) {
handleChatAction(e);
}
Expand All @@ -214,23 +214,25 @@
}
/** @param {any} e */
async function handleNewChatAction(e) {
function handleNewChatAction(e) {
if (!isCreatingNewConv && !isThinking && !isSendingMsg) {
isCreatingNewConv = true;
const conv = await createNewConversation();
isCreatingNewConv = false;
if (conv && !!e.data.text) {
isLoading = true;
sendChatMessage(e.data.text, e.data.data || null, conv.id).then(() => {
redirectToNewConversation(conv);
isLoading = false;
openFrame();
}).catch(() => {
isLoading = false;
openFrame();
});
}
createNewConversation().then(conv => {
isCreatingNewConv = false;
if (conv && !!e.data.text) {
isLoading = true;
sendChatMessage(e.data.text, e.data.data || null, conv.id).then(() => {
redirectToNewConversation(conv);
isLoading = false;
openFrame();
}).catch(() => {
isLoading = false;
openFrame();
});
}
}).catch(() => {
isCreatingNewConv = false;
});
}
}
Expand Down

0 comments on commit e1503bf

Please sign in to comment.