From dff27ab7a18f9d0a08d57e7b1ad569c81011ba87 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Tue, 4 Feb 2025 00:07:35 +0530 Subject: [PATCH 1/2] fix: input text and action button fix in context chat Signed-off-by: Anupam Kumar --- lib/Notification/Notifier.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index efe40277..e6448632 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -98,6 +98,9 @@ public function prepare(INotification $notification, string $languageCode): INot // Catch the custom copywriter task type built on top of the FreePrompt task type. $taskTypeName = $l->t('AI context writer'); $taskInput = $l->t('Writing style: %1$s; Source material: %2$s', [$params['inputs']['writingStyle'], $params['inputs']['sourceMaterial']]); + } elseif ($params['taskTypeId'] === 'context_chat:context_chat') { + $taskInput = $params['inputs']['prompt'] ?? null; + $taskTypeName = $l->t('Context Chat'); } else { $availableTaskTypes = $this->taskProcessingManager->getAvailableTaskTypes(); if (isset($availableTaskTypes[$params['taskTypeId']])) { From d6e63e35d8fff0c574e2c40880a98d6667bea995 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Tue, 4 Feb 2025 00:15:33 +0530 Subject: [PATCH 2/2] cleanup unused function, perhaps not even required Signed-off-by: Anupam Kumar --- lib/Notification/Notifier.php | 5 ++- lib/Service/AssistantService.php | 52 -------------------------------- 2 files changed, 4 insertions(+), 53 deletions(-) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index e6448632..f8a73df6 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -98,7 +98,10 @@ public function prepare(INotification $notification, string $languageCode): INot // Catch the custom copywriter task type built on top of the FreePrompt task type. $taskTypeName = $l->t('AI context writer'); $taskInput = $l->t('Writing style: %1$s; Source material: %2$s', [$params['inputs']['writingStyle'], $params['inputs']['sourceMaterial']]); - } elseif ($params['taskTypeId'] === 'context_chat:context_chat') { + } elseif ( + $params['taskTypeId'] === 'context_chat:context_chat' + || $params['taskTypeId'] === 'legacy:TextProcessing:OCA\ContextChat\TextProcessing\ContextChatTaskType' + ) { $taskInput = $params['inputs']['prompt'] ?? null; $taskTypeName = $l->t('Context Chat'); } else { diff --git a/lib/Service/AssistantService.php b/lib/Service/AssistantService.php index 1d3744e8..43dfe2b9 100644 --- a/lib/Service/AssistantService.php +++ b/lib/Service/AssistantService.php @@ -509,58 +509,6 @@ public function getOutputFilePreviewFile(string $userId, int $taskId, int $fileI return $this->previewService->getFilePreviewFile($taskOutputFile, $x, $y, $realMime ?: null); } - /** - * Sanitize inputs for storage based on the input type - * - * @param string $type - * @param array $inputs - * @return array - * @throws \Exception - */ - private function sanitizeInputs(string $type, array $inputs): array { - switch ($type) { - case 'copywriter': - { - // Sanitize the input array based on the allowed keys and making sure all inputs are strings: - $inputs = array_filter($inputs, function ($value, $key) { - return in_array($key, ['writingStyle', 'sourceMaterial']) && is_string($value); - }, ARRAY_FILTER_USE_BOTH); - - if (count($inputs) !== 2) { - throw new \Exception('Invalid input(s)'); - } - break; - } - case 'OCA\\ContextChat\\TextProcessing\\ContextChatTaskType': - { - if ((count($inputs) !== 1 && count($inputs) !== 4) - || !isset($inputs['prompt']) - || !is_string($inputs['prompt']) - ) { - throw new \Exception('Invalid input(s)'); - } - - if (count($inputs) === 4) { - if (!isset($inputs['scopeType']) || !is_string($inputs['scopeType']) - || !isset($inputs['scopeList']) || !is_array($inputs['scopeList']) - || !isset($inputs['scopeListMeta']) || !is_array($inputs['scopeListMeta'])) { - throw new \Exception('Invalid input(s)'); - } - } - - break; - } - default: - { - if (!is_string($inputs['prompt']) || count($inputs) !== 1) { - throw new \Exception('Invalid input(s)'); - } - break; - } - } - return $inputs; - } - /** * Parse text from file (if parsing the file type is supported) * @param string $userId