-
Notifications
You must be signed in to change notification settings - Fork 3
AP-25051: Add cancel button to Agent Chat Widget #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,6 +182,7 @@ export const useChatStore = defineStore("chat", () => { | |
| const lastMessage = shallowRef<Message | undefined>(); | ||
| const config = ref<Config | null>(null); // node settings that affect rendering | ||
| const isLoading = ref(false); // true if agent is currently responding to user message | ||
| const isInterrupted = ref(false); // true if agent is currently responding to cancellation | ||
| const chatItems = ref<ChatItem[]>([]); | ||
| const lastUserMessage = ref(""); | ||
| const jsonDataService = ref<JsonDataService | null>(null); | ||
|
|
@@ -357,6 +358,19 @@ export const useChatStore = defineStore("chat", () => { | |
| } | ||
| } | ||
|
|
||
| async function cancelAgent() { | ||
| try { | ||
| isInterrupted.value = true; | ||
| await jsonDataService.value?.data({ | ||
| method: "cancel_agent", | ||
| }); | ||
| } catch (error) { | ||
| isInterrupted.value = false; | ||
| consola.error("Chat Store: Failed to cancel agent:", error); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| async function postUserMessage(msg: string) { | ||
| try { | ||
| await jsonDataService.value?.data({ | ||
|
|
@@ -458,8 +472,8 @@ export const useChatStore = defineStore("chat", () => { | |
| const lastMessagesToDisplay = showToolCallsResults | ||
| ? msgs | ||
| : msgs.filter( | ||
| (msg) => !isToolMessage(msg) && !isAiMessageWithToolCalls(msg), | ||
| ); | ||
| (msg) => !isToolMessage(msg) && !isAiMessageWithToolCalls(msg), | ||
| ); | ||
| const activeTimeline = chatItems.value.findLast( | ||
| (item) => item.type === "timeline" && item.status === "active", | ||
| ) as Timeline | undefined; | ||
|
|
@@ -472,6 +486,7 @@ export const useChatStore = defineStore("chat", () => { | |
|
|
||
| function finishLoading(shallApplyViewData: boolean) { | ||
| isLoading.value = false; | ||
| isInterrupted.value = false; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My strategy was to check where we reset isLoading and to also reset isInterrupted there. But we should double-check if this covers all cases. |
||
| const viewData: ViewData = { | ||
| conversation: messagesToPersist, | ||
| config: toRaw(config.value!), | ||
|
|
@@ -495,6 +510,7 @@ export const useChatStore = defineStore("chat", () => { | |
| config.value = null; | ||
| chatItems.value = []; | ||
| isLoading.value = false; | ||
| isInterrupted.value = false; | ||
| lastUserMessage.value = ""; | ||
| jsonDataService.value = null; | ||
| initState.value = "idle"; | ||
|
|
@@ -507,6 +523,7 @@ export const useChatStore = defineStore("chat", () => { | |
| chatItems, | ||
| lastMessage, | ||
| isLoading, | ||
| isInterrupted, | ||
| lastUserMessage, | ||
| jsonDataService, | ||
| initState, | ||
|
|
@@ -532,5 +549,6 @@ export const useChatStore = defineStore("chat", () => { | |
| flushRequestQueue, | ||
| pollForNewMessages, | ||
| resetChat, | ||
| cancelAgent, | ||
| }; | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also separate this into two buttons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, it's ok