From a7d2e14fb5582fb4177be333135eae97714fe264 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 5 Nov 2025 10:46:05 +0100 Subject: [PATCH 1/4] fix(chat-backend): reject new chat input messages longer than 64k chars in the backend Signed-off-by: Julien Veyssier --- lib/Controller/ChattyLLMController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Controller/ChattyLLMController.php b/lib/Controller/ChattyLLMController.php index 2af5b57f..304ad586 100644 --- a/lib/Controller/ChattyLLMController.php +++ b/lib/Controller/ChattyLLMController.php @@ -292,6 +292,9 @@ public function newMessage( if ($this->userId === null) { return new JSONResponse(['error' => $this->l10n->t('User not logged in')], Http::STATUS_UNAUTHORIZED); } + if (strlen($content) > 64_000) { + return new JSONResponse(['error' => $this->l10n->t('The new message is too long')], Http::STATUS_BAD_REQUEST); + } try { $sessionExists = $this->sessionMapper->exists($this->userId, $sessionId); From ba8a1bf7ca10f0066d280f63c2b03d528b4abb48 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 5 Nov 2025 11:19:11 +0100 Subject: [PATCH 2/4] fix(generic-form): limit the length of input text fields to 64k chars in the UI Signed-off-by: Julien Veyssier --- lib/Service/AssistantService.php | 5 +++++ src/components/AssistantTextProcessingForm.vue | 14 +++++++++++--- src/components/fields/ListOfTextsField.vue | 2 +- src/components/fields/TextInput.vue | 11 ++++++++++- src/constants.js | 2 ++ 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/Service/AssistantService.php b/lib/Service/AssistantService.php index 1998549f..cf4395e9 100644 --- a/lib/Service/AssistantService.php +++ b/lib/Service/AssistantService.php @@ -244,6 +244,11 @@ public function getAvailableTaskTypes(): array { 'id' => 'core:inputList', 'priority' => 0, 'inputShape' => [ + 'textList' => new ShapeDescriptor( + 'Input text list', + 'plop', + EShapeType::ListOfTexts, + ), 'fileList' => new ShapeDescriptor( 'Input file list', 'plop', diff --git a/src/components/AssistantTextProcessingForm.vue b/src/components/AssistantTextProcessingForm.vue index 765c3dcc..62375af7 100644 --- a/src/components/AssistantTextProcessingForm.vue +++ b/src/components/AssistantTextProcessingForm.vue @@ -152,7 +152,7 @@ import TaskList from './TaskList.vue' import TaskTypeSelect from './TaskTypeSelect.vue' import TranslateForm from './Translate/TranslateForm.vue' -import { SHAPE_TYPE_NAMES } from '../constants.js' +import { SHAPE_TYPE_NAMES, MAX_TEXT_INPUT_LENGTH } from '../constants.js' import axios from '@nextcloud/axios' import { generateOcsUrl, generateUrl } from '@nextcloud/router' @@ -330,7 +330,11 @@ export default { } const fieldType = taskType.inputShape[k].type const value = this.myInputs[k] - return ([SHAPE_TYPE_NAMES.Text, SHAPE_TYPE_NAMES.Enum].includes(fieldType) && typeof value === 'string' && !!value?.trim()) + return ([SHAPE_TYPE_NAMES.Text, SHAPE_TYPE_NAMES.Enum].includes(fieldType) + && typeof value === 'string' + && !!value?.trim() + // check that the input text is not too long for text fields + && (fieldType === SHAPE_TYPE_NAMES.Enum || value.trim().length <= MAX_TEXT_INPUT_LENGTH)) || ([ SHAPE_TYPE_NAMES.Number, SHAPE_TYPE_NAMES.File, @@ -338,7 +342,11 @@ export default { SHAPE_TYPE_NAMES.Audio, SHAPE_TYPE_NAMES.Video, ].includes(fieldType) && typeof value === 'number') - || (fieldType === SHAPE_TYPE_NAMES.ListOfTexts && typeof value === 'object' && !!value && value.every(v => typeof v === 'string')) + || (fieldType === SHAPE_TYPE_NAMES.ListOfTexts && typeof value === 'object' && !!value && value.every(v => { + return typeof v === 'string' + && !!v?.trim() + && v.trim().length <= MAX_TEXT_INPUT_LENGTH + })) || (fieldType === SHAPE_TYPE_NAMES.ListOfNumbers && typeof value === 'object' && !!value && value.every(v => typeof v === 'number')) || ([ SHAPE_TYPE_NAMES.ListOfFiles, diff --git a/src/components/fields/ListOfTextsField.vue b/src/components/fields/ListOfTextsField.vue index 096c0d50..aadace2b 100644 --- a/src/components/fields/ListOfTextsField.vue +++ b/src/components/fields/ListOfTextsField.vue @@ -137,7 +137,7 @@ export default { &--item { display: flex; gap: 4px; - align-items: center; + align-items: end; .text-input { flex-grow: 1; } diff --git a/src/components/fields/TextInput.vue b/src/components/fields/TextInput.vue index fb8bb980..8204978a 100644 --- a/src/components/fields/TextInput.vue +++ b/src/components/fields/TextInput.vue @@ -6,6 +6,7 @@
getFilePickerBuilder(t('assistant', 'Choose a text file')) .setMimeTypeFilter(VALID_TEXT_MIME_TYPES) @@ -123,6 +125,7 @@ export default { data() { return { copied: false, + maxLength: MAX_TEXT_INPUT_LENGTH, } }, @@ -136,6 +139,12 @@ export default { hasValue() { return this.formattedValue !== '' }, + limitLabel() { + const length = this.value?.length ?? 0 + return length > this.maxLength + ? t('assistant', 'Warning: The input text exceeds the maximum length of {limit} characters (currently {length}).', { length, limit: this.maxLength }) + : undefined + }, }, watch: { diff --git a/src/constants.js b/src/constants.js index b562c064..07d4c6aa 100644 --- a/src/constants.js +++ b/src/constants.js @@ -3,6 +3,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +export const MAX_TEXT_INPUT_LENGTH = 64_000 + export const TASK_STATUS_INT = { cancelled: 5, failed: 4, From 9d55276a976b15b054ee769da6d67f45e76da968 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 5 Nov 2025 11:36:04 +0100 Subject: [PATCH 3/4] fix(chat-ui): prevent submitting chat input messages longer than 64k chars in the UI Signed-off-by: Julien Veyssier --- lib/AppInfo/Application.php | 1 + lib/Controller/ChattyLLMController.php | 2 +- src/components/ChattyLLM/InputArea.vue | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d31f951d..ad3a9146 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -55,6 +55,7 @@ class Application extends App implements IBootstrap { public const CHAT_USER_INSTRUCTIONS = 'This is a conversation in a specific language between the user and you, Nextcloud Assistant. You are a kind, polite and helpful AI that helps the user to the best of its abilities. If you do not understand something, you will ask for clarification. Detect the language that the user is using. Make sure to use the same language in your response. Do not mention the language explicitly.'; public const CHAT_USER_INSTRUCTIONS_TITLE = 'Above is a chat session in a specific language between the user and you, Nextcloud Assistant. Generate a suitable title summarizing the conversation in the same language. Output only the title in plain text, nothing else.'; + public const MAX_TEXT_INPUT_LENGTH = 64_000; private IAppConfig $appConfig; private IManager $taskProcessingManager; diff --git a/lib/Controller/ChattyLLMController.php b/lib/Controller/ChattyLLMController.php index 304ad586..d359312a 100644 --- a/lib/Controller/ChattyLLMController.php +++ b/lib/Controller/ChattyLLMController.php @@ -292,7 +292,7 @@ public function newMessage( if ($this->userId === null) { return new JSONResponse(['error' => $this->l10n->t('User not logged in')], Http::STATUS_UNAUTHORIZED); } - if (strlen($content) > 64_000) { + if (strlen($content) > Application::MAX_TEXT_INPUT_LENGTH) { return new JSONResponse(['error' => $this->l10n->t('The new message is too long')], Http::STATUS_BAD_REQUEST); } diff --git a/src/components/ChattyLLM/InputArea.vue b/src/components/ChattyLLM/InputArea.vue index 5f24a732..ddb8533d 100644 --- a/src/components/ChattyLLM/InputArea.vue +++ b/src/components/ChattyLLM/InputArea.vue @@ -16,14 +16,14 @@ :multiline="isMobile" dir="auto" @update:model-value="$emit('update:chatContent', $event)" - @submit="$emit('submit', $event)" /> + @submit="onSubmitText" />
+ @click="onSubmitText"> @@ -50,6 +50,7 @@ import { generateOcsUrl } from '@nextcloud/router' import axios from '@nextcloud/axios' import { showError } from '@nextcloud/dialogs' import { loadState } from '@nextcloud/initial-state' +import { MAX_TEXT_INPUT_LENGTH } from '../../constants.js' /* maxlength calculation (just a rough estimate): @@ -112,6 +113,9 @@ export default { disabled() { return this.loading.llmGeneration || this.loading.olderMessages || this.loading.initialMessages || this.loading.titleGeneration || this.loading.newHumanMessage || this.loading.newSession }, + chatContentTooLong() { + return this.chatContent.length > MAX_TEXT_INPUT_LENGTH + }, }, mounted() { @@ -139,6 +143,11 @@ export default { console.error(error) }) }, + onSubmitText(e) { + if (!this.chatContentTooLong) { + this.$emit('submit', e) + } + }, }, } From 62595e460ee4af10643d142b543e7ee88ee70875 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Tue, 2 Dec 2025 12:48:36 +0100 Subject: [PATCH 4/4] add warning label when chat messages are too long, increase chat msg limit to 64K, break line in text input field length warning Signed-off-by: Julien Veyssier --- src/components/ChattyLLM/ChattyLLMInputForm.vue | 4 ++++ src/components/ChattyLLM/InputArea.vue | 2 +- src/components/fields/TextInput.vue | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/ChattyLLM/ChattyLLMInputForm.vue b/src/components/ChattyLLM/ChattyLLMInputForm.vue index 592ac86f..3dbcc2b3 100644 --- a/src/components/ChattyLLM/ChattyLLMInputForm.vue +++ b/src/components/ChattyLLM/ChattyLLMInputForm.vue @@ -128,6 +128,10 @@

{{ t('assistant', 'Output shown here is generated by AI. Make sure to always double-check.') }}

+

+ {{ t('assistant', 'Messages should not be longer than {maxLength} characters (currently {length}).', { maxLength: 64_000, length: chatContent.length }) }} +