Skip to content

Commit 7803dd0

Browse files
committed
chore: add abort logic progress[1]
1 parent f075822 commit 7803dd0

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

custom/ChatSurface.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
</div>
171171
</div>
172172
<Button
173+
v-if="!agentStore.isResponseInProgress"
173174
class="absolute right-4 bottom-2 !p-0 h-9 w-9"
174175
@click="sendMessage"
175176
:disabled="!agentStore.trimmedUserMessage || agentStore.isResponseInProgress"
@@ -179,6 +180,15 @@
179180
text-white"
180181
/>
181182
</Button>
183+
<Button
184+
v-else
185+
class="absolute right-4 bottom-2 !p-0 h-9 w-9"
186+
@click="stopCurrentRequest"
187+
>
188+
<div
189+
class="w-3 h-3 bg-white rounded-sm"
190+
/>
191+
</Button>
182192
</div>
183193
</div>
184194
</div>
@@ -316,6 +326,10 @@ async function sendMessage() {
316326
conversationArea.value?.handleSendMessage();
317327
}
318328
329+
function stopCurrentRequest() {
330+
agentStore.abortCurrentChatRequest();
331+
}
332+
319333
function updateHeight() {
320334
dvh.value = Math.round(window.visualViewport?.height || window.innerHeight);
321335
}

custom/composables/useAgentStore.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ export const useAgentStore = defineStore('agent', () => {
252252

253253
}
254254

255+
function abortCurrentChatRequest() {
256+
currentChat.value?.stop();
257+
}
258+
255259
function clearPlaceholderAnimationTimer() {
256260
if (placeholderAnimationTimer !== null) {
257261
clearTimeout(placeholderAnimationTimer);
@@ -638,6 +642,7 @@ export const useAgentStore = defineStore('agent', () => {
638642
MAX_WIDTH,
639643
MIN_WIDTH,
640644
getLocalStorageItem,
641-
addDebugMessage
645+
addDebugMessage,
646+
abortCurrentChatRequest
642647
}
643648
})

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
420420
server.endpoint({
421421
method: 'POST',
422422
path: `/agent/response`,
423-
handler: async ({ body, query, headers, cookies, adminUser, response, requestUrl, _raw_express_res }) => {
423+
handler: async ({ body, query, headers, cookies, adminUser, response, requestUrl, _raw_express_res, abortSignal }) => {
424424
const res = _raw_express_res;
425425
const messageId = randomUUID();
426426
const prompt = body.message;

0 commit comments

Comments
 (0)