Skip to content

Commit 00f194a

Browse files
authored
Merge pull request #227 from nextcloud/fix/task-layout
feat: task layout design update
2 parents 41a72c1 + 899d6f6 commit 00f194a

7 files changed

Lines changed: 421 additions & 116 deletions

File tree

src/assistant.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,63 @@ export async function openAssistantForm({
137137
view.$on('load-task', (task) => {
138138
if (!view.loading) {
139139
console.debug('[assistant] loading task', task)
140+
cancelTaskPolling()
141+
140142
view.selectedTaskTypeId = task.type
141143
view.inputs = task.input
142144
view.outputs = task.status === TASK_STATUS_STRING.successful ? task.output : null
143145
view.selectedTaskId = task.id
144146
lastTask = task
147+
148+
if ([TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(task?.status)) {
149+
getTask(task.id).then(response => {
150+
const updatedTask = response.data?.ocs?.data?.task
151+
152+
if (![TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(updatedTask?.status)) {
153+
view.selectedTaskTypeId = updatedTask.type
154+
view.inputs = updatedTask.input
155+
view.outputs = updatedTask.status === TASK_STATUS_STRING.successful ? updatedTask.output : null
156+
view.selectedTaskId = updatedTask.id
157+
lastTask = updatedTask
158+
return
159+
}
160+
161+
view.loading = true
162+
view.showSyncTaskRunning = true
163+
view.progress = null
164+
view.expectedRuntime = (updatedTask?.completionExpectedAt - updatedTask?.scheduledAt) || null
165+
166+
const setProgress = (progress) => {
167+
view.progress = progress
168+
}
169+
pollTask(updatedTask.id, setProgress).then(finishedTask => {
170+
console.debug('pollTask.then', finishedTask)
171+
if (finishedTask.status === TASK_STATUS_STRING.successful) {
172+
view.outputs = finishedTask?.output
173+
view.selectedTaskId = finishedTask?.id
174+
} else if (finishedTask.status === TASK_STATUS_STRING.failed) {
175+
showError(t('assistant', 'Your task with ID {id} has failed', { id: finishedTask.id }))
176+
console.error('[assistant] Task failed', finishedTask)
177+
view.outputs = null
178+
}
179+
// resolve(finishedTask)
180+
view.loading = false
181+
view.showSyncTaskRunning = false
182+
}).catch(error => {
183+
console.debug('[assistant] poll error', error)
184+
})
185+
}).catch(error => {
186+
console.error(error)
187+
})
188+
}
145189
}
146190
})
191+
view.$on('new-task', () => {
192+
console.debug('[assistant] new task')
193+
view.outputs = null
194+
view.selectedTaskId = null
195+
lastTask = null
196+
})
147197
view.$on('background-notify', () => {
148198
cancelTaskPolling()
149199
view.showScheduleConfirmation = true
@@ -166,6 +216,7 @@ export async function openAssistantForm({
166216
view.$destroy()
167217
})
168218
view.$on('back-to-assistant', () => {
219+
cancelTaskPolling()
169220
view.showScheduleConfirmation = false
170221
view.showSyncTaskRunning = false
171222
view.loading = false
@@ -430,13 +481,63 @@ export async function openAssistantTask(task, { isInsideViewer = undefined, acti
430481
})
431482
view.$on('load-task', (task) => {
432483
if (!view.loading) {
484+
cancelTaskPolling()
485+
433486
view.selectedTaskTypeId = task.type
434487
view.inputs = task.input
435488
view.outputs = task.status === TASK_STATUS_STRING.successful ? task.output : null
436489
view.selectedTaskId = task.id
437490
lastTask = task
491+
492+
if ([TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(task?.status)) {
493+
getTask(task.id).then(response => {
494+
const updatedTask = response.data?.ocs?.data?.task
495+
496+
if (![TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(updatedTask?.status)) {
497+
view.selectedTaskTypeId = updatedTask.type
498+
view.inputs = updatedTask.input
499+
view.outputs = updatedTask.status === TASK_STATUS_STRING.successful ? updatedTask.output : null
500+
view.selectedTaskId = updatedTask.id
501+
lastTask = updatedTask
502+
return
503+
}
504+
505+
view.loading = true
506+
view.showSyncTaskRunning = true
507+
view.progress = null
508+
view.expectedRuntime = (updatedTask?.completionExpectedAt - updatedTask?.scheduledAt) || null
509+
510+
const setProgress = (progress) => {
511+
view.progress = progress
512+
}
513+
pollTask(updatedTask.id, setProgress).then(finishedTask => {
514+
console.debug('pollTask.then', finishedTask)
515+
if (finishedTask.status === TASK_STATUS_STRING.successful) {
516+
view.outputs = finishedTask?.output
517+
view.selectedTaskId = finishedTask?.id
518+
} else if (finishedTask.status === TASK_STATUS_STRING.failed) {
519+
showError(t('assistant', 'Your task with ID {id} has failed', { id: finishedTask.id }))
520+
console.error('[assistant] Task failed', finishedTask)
521+
view.outputs = null
522+
}
523+
// resolve(finishedTask)
524+
view.loading = false
525+
view.showSyncTaskRunning = false
526+
}).catch(error => {
527+
console.debug('[assistant] poll error', error)
528+
})
529+
}).catch(error => {
530+
console.error(error)
531+
})
532+
}
438533
}
439534
})
535+
view.$on('new-task', () => {
536+
console.debug('[assistant] new task')
537+
view.outputs = null
538+
view.selectedTaskId = null
539+
lastTask = null
540+
})
440541
view.$on('background-notify', () => {
441542
cancelTaskPolling()
442543
view.showScheduleConfirmation = true
@@ -457,6 +558,7 @@ export async function openAssistantTask(task, { isInsideViewer = undefined, acti
457558
view.$destroy()
458559
})
459560
view.$on('back-to-assistant', () => {
561+
cancelTaskPolling()
460562
view.showScheduleConfirmation = false
461563
view.showSyncTaskRunning = false
462564
view.loading = false

src/components/AssistantFormInputs.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
- SPDX-License-Identifier: AGPL-3.0-or-later
44
-->
55
<template>
6-
<ChattyLLMInputForm v-if="selectedTaskTypeId === 'chatty-llm'" class="chatty-inputs" />
7-
<ContextChatInputForm v-else-if="selectedTaskTypeId === 'context_chat:context_chat'"
6+
<ContextChatInputForm v-if="selectedTaskTypeId === 'context_chat:context_chat'"
87
:inputs="inputs"
98
:task-type="selectedTaskType"
109
@update:inputs="$emit('update:inputs', $event)" />
@@ -26,15 +25,13 @@
2625
</template>
2726

2827
<script>
29-
import ChattyLLMInputForm from './ChattyLLM/ChattyLLMInputForm.vue'
3028
import ContextChatInputForm from './ContextChat/ContextChatInputForm.vue'
3129
import TaskTypeFields from './fields/TaskTypeFields.vue'
3230
3331
export default {
3432
name: 'AssistantFormInputs',
3533
components: {
3634
ContextChatInputForm,
37-
ChattyLLMInputForm,
3835
TaskTypeFields,
3936
},
4037
props: {

0 commit comments

Comments
 (0)