diff --git a/lib/Controller/ChattyLLMController.php b/lib/Controller/ChattyLLMController.php index 5b31199f..17bc6cc3 100644 --- a/lib/Controller/ChattyLLMController.php +++ b/lib/Controller/ChattyLLMController.php @@ -255,7 +255,7 @@ public function deleteSession(int $sessionId): JSONResponse { } try { - $this->deleteSessionTasks($this->userId, $sessionId); + // we don't delete the tasks $this->sessionMapper->deleteSession($this->userId, $sessionId); $this->messageMapper->deleteMessagesBySession($sessionId); return new JSONResponse(); @@ -265,27 +265,6 @@ public function deleteSession(int $sessionId): JSONResponse { } } - private function deleteSessionTasks(string $userId, int $sessionId): void { - $sessionExists = $this->sessionMapper->exists($this->userId, $sessionId); - if (!$sessionExists) { - return; - } - $messages = $this->messageMapper->getMessages($sessionId, 0, 0); - foreach ($messages as $message) { - $ocpTaskId = $message->getOcpTaskId(); - if ($ocpTaskId !== 0) { - try { - $task = $this->taskProcessingManager->getTask($ocpTaskId); - $this->taskProcessingManager->deleteTask($task); - } catch (\OCP\TaskProcessing\Exception\Exception) { - // silent failure here because: - // if the task is not found: all good nothing to delete - // if the task couldn't be deleted, it will be deleted by the task processing cleanup job later anyway - } - } - } - } - /** * Get chat sessions * @@ -493,18 +472,10 @@ public function deleteMessage(int $messageId, int $sessionId): JSONResponse { return new JSONResponse(['error' => $this->l10n->t('Session not found')], Http::STATUS_NOT_FOUND); } $message = $this->messageMapper->getMessageById($sessionId, $messageId); - $ocpTaskId = $message->getOcpTaskId(); + // do not delete the related task $this->messageMapper->deleteMessageById($sessionId, $messageId); - // delete the related task - if ($ocpTaskId !== 0) { - try { - $task = $this->taskProcessingManager->getTask($ocpTaskId); - $this->taskProcessingManager->deleteTask($task); - } catch (\OCP\TaskProcessing\Exception\Exception) { - } - } return new JSONResponse(); } catch (\OCP\DB\Exception|\RuntimeException $e) { $this->logger->warning('Failed to delete a chat message', ['exception' => $e]); @@ -688,8 +659,8 @@ public function regenerateForSession(int $sessionId, int $messageId): JSONRespon } $message = $this->messageMapper->getMessageById($sessionId, $messageId); - $ocpTaskId = $message->getOcpTaskId(); + // we don't delete the related task try { $this->messageMapper->deleteMessageById($sessionId, $messageId); } catch (\OCP\DB\Exception|\RuntimeException $e) { @@ -697,15 +668,6 @@ public function regenerateForSession(int $sessionId, int $messageId): JSONRespon return new JSONResponse(['error' => $this->l10n->t('Failed to delete the last message')], Http::STATUS_INTERNAL_SERVER_ERROR); } - // delete the related task - if ($ocpTaskId !== 0) { - try { - $task = $this->taskProcessingManager->getTask($ocpTaskId); - $this->taskProcessingManager->deleteTask($task); - } catch (\OCP\TaskProcessing\Exception\Exception) { - } - } - return $this->generateForSession($sessionId); } diff --git a/src/assistant.js b/src/assistant.js index af618102..f9ed4011 100644 --- a/src/assistant.js +++ b/src/assistant.js @@ -370,8 +370,8 @@ export async function setNotifyReady(taskId, enable) { export async function cancelTask(taskId) { const { default: axios } = await import('@nextcloud/axios') const { generateOcsUrl } = await import('@nextcloud/router') - const url = generateOcsUrl('taskprocessing/task/{taskId}', { taskId }) - return axios.delete(url, {}) + const url = generateOcsUrl('taskprocessing/tasks/{taskId}/cancel', { taskId }) + return axios.post(url, {}) } /**