Skip to content

Commit

Permalink
feat: cancel tasks and dismiss summary
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy authored and backportbot[bot] committed Nov 22, 2024
1 parent a748428 commit 59d1386
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
57 changes: 51 additions & 6 deletions src/components/NewMessage/NewMessageChatSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,24 @@
class="chat-summary__message"
:class="{'chat-summary__message--collapsed': collapsed}">{{ chatSummaryMessage }}</p>
</template>

<div class="chat-summary__actions">
<NcButton v-if="loading"
class="chat-summary__action"
type="primary"
:disabled="cancelling"
@click="cancelSummary">
<template v-if="cancelling" #icon>
<NcLoadingIcon />
</template>
{{ t('spreed', 'Cancel') }}
</NcButton>
<NcButton v-else-if="chatSummaryMessage"
class="chat-summary__action"
type="primary"
@click="dismissSummary">
{{ t('spreed', 'Dismiss') }}
</NcButton>
</div>
</NcNoteCard>
</template>

Expand All @@ -51,7 +68,7 @@ import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'

import { useStore } from '../../composables/useStore.js'
import { TASK_PROCESSING } from '../../constants.js'
import { getTaskById } from '../../services/coreService.ts'
import { deleteTaskById, getTaskById } from '../../services/coreService.ts'
import { useChatExtrasStore } from '../../stores/chatExtras.js'
import type { TaskProcessingResponse, SummarizeChatTask } from '../../types/index.ts'
import CancelableRequest from '../../utils/cancelableRequest.js'
Expand All @@ -74,6 +91,7 @@ const collapsed = ref(true)
const isTextMoreThanOneLine = ref(false)

const loading = ref(true)
const cancelling = ref(false)

const store = useStore()
const chatExtrasStore = useChatExtrasStore()
Expand Down Expand Up @@ -159,11 +177,8 @@ async function getTask(token: string, request: TaskProcessingCancelableRequest['
case TASK_PROCESSING.STATUS.UNKNOWN:
case TASK_PROCESSING.STATUS.CANCELLED: {
// Task is likely failed, proceed to the next task
chatExtrasStore.storeChatSummary(token, task.fromMessageId, '')
showError(t('spreed', 'Error occurred during a summary generation'))
clearInterval(getTaskInterval)
getTaskInterval = undefined
checkScheduledTasks(token)
cancelSummary()
break
}
case TASK_PROCESSING.STATUS.SCHEDULED:
Expand All @@ -181,6 +196,29 @@ async function getTask(token: string, request: TaskProcessingCancelableRequest['
}
}

/**
*
*/
function dismissSummary() {
Object.values(cancelGetTask).forEach(cancelFn => cancelFn())
clearInterval(getTaskInterval)
getTaskInterval = undefined
chatExtrasStore.dismissChatSummary(token.value)
}

/**
*
*/
async function cancelSummary() {
cancelling.value = true
const taskQueue: ChatTask[] = chatExtrasStore.getChatSummaryTaskQueue(token.value)
for await (const task of taskQueue) {
await deleteTaskById(task.taskId)
}
cancelling.value = false
dismissSummary()
}

/**
*
*/
Expand Down Expand Up @@ -229,6 +267,13 @@ function setIsTextMoreThanOneLine() {
}
}

&__actions {
display: flex;
justify-content: flex-end;
gap: var(--default-grid-baseline);
z-index: 1;
}

&__button {
position: absolute !important;
top: var(--default-grid-baseline);
Expand Down
5 changes: 5 additions & 0 deletions src/services/coreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ const getTaskById = async function(id: number, options?: object): TaskProcessing
return axios.get(generateOcsUrl('taskprocessing/task/{id}', { id }), options)
}

const deleteTaskById = async function(id: number, options?: object): Promise<null> {
return axios.delete(generateOcsUrl('taskprocessing/task/{id}', { id }), options)
}

export {
autocompleteQuery,
getTaskById,
deleteTaskById,
}
6 changes: 6 additions & 0 deletions src/stores/chatExtras.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,11 @@ export const useChatExtrasStore = defineStore('chatExtras', {
Vue.set(this.chatSummary[token][fromMessageId], 'summary', summary)
}
},

dismissChatSummary(token) {
if (this.hasChatSummaryTaskRequested(token)) {
Vue.delete(this.chatSummary, token)
}
},
},
})

0 comments on commit 59d1386

Please sign in to comment.