From 0e439e76af654aa0bfd89d29e8697fc884cfbc04 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 5 Nov 2025 13:11:58 +0100 Subject: [PATCH 1/6] fix(sticker-picker): always register the sticker task type and provider and reference provider, rely on the listener to conditionally inject the sticker reference script Signed-off-by: Julien Veyssier --- lib/AppInfo/Application.php | 15 ++++++++++----- lib/Listener/Text2Image/Text2StickerListener.php | 8 ++++++-- lib/Reference/Text2StickerProvider.php | 2 -- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 0c7e677cc..d31f951d8 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -45,6 +45,7 @@ use OCP\Security\CSP\AddContentSecurityPolicyEvent; use OCP\TaskProcessing\Events\TaskFailedEvent; use OCP\TaskProcessing\Events\TaskSuccessfulEvent; +use OCP\TaskProcessing\IManager; class Application extends App implements IBootstrap { @@ -56,11 +57,14 @@ class Application extends App implements IBootstrap { 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.'; private IAppConfig $appConfig; + private IManager $taskProcessingManager; + public function __construct(array $urlParams = []) { parent::__construct(self::APP_ID, $urlParams); $container = $this->getContainer(); $this->appConfig = $container->get(IAppConfig::class); + $this->taskProcessingManager = $container->get(IManager::class); } public function register(IRegistrationContext $context): void { @@ -69,7 +73,6 @@ public function register(IRegistrationContext $context): void { $context->registerCapability(Capabilities::class); $context->registerReferenceProvider(Text2ImageReferenceProvider::class); - $context->registerReferenceProvider(Text2StickerProvider::class); $context->registerReferenceProvider(FreePromptReferenceProvider::class); $context->registerReferenceProvider(SpeechToTextReferenceProvider::class); $context->registerReferenceProvider(TaskOutputFileReferenceProvider::class); @@ -101,10 +104,12 @@ public function register(IRegistrationContext $context): void { if (class_exists('OCP\\TaskProcessing\\TaskTypes\\ContextAgentAudioInteraction')) { $context->registerTaskProcessingProvider(ContextAgentAudioInteractionProvider::class); } - if ($this->appConfig->getValueString(Application::APP_ID, 'text_to_sticker_picker_enabled', '1') === '1') { - $context->registerTaskProcessingTaskType(TextToStickerTaskType::class); - $context->registerTaskProcessingProvider(TextToStickerProvider::class); - } + + // TODO use this when we drop NC <= 31 + // if (in_array(TextToImage::ID, $this->taskProcessingManager->getAvailableTaskTypeIds(), true)) { + $context->registerTaskProcessingTaskType(TextToStickerTaskType::class); + $context->registerTaskProcessingProvider(TextToStickerProvider::class); + $context->registerReferenceProvider(Text2StickerProvider::class); } public function boot(IBootContext $context): void { diff --git a/lib/Listener/Text2Image/Text2StickerListener.php b/lib/Listener/Text2Image/Text2StickerListener.php index bc7be5622..28d00fd5b 100644 --- a/lib/Listener/Text2Image/Text2StickerListener.php +++ b/lib/Listener/Text2Image/Text2StickerListener.php @@ -8,6 +8,7 @@ namespace OCA\Assistant\Listener\Text2Image; use OCA\Assistant\AppInfo\Application; +use OCA\Assistant\TaskProcessing\TextToStickerTaskType; use OCP\Collaboration\Reference\RenderReferenceEvent; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; @@ -38,10 +39,13 @@ public function handle(Event $event): void { if ($this->appConfig->getValueString(Application::APP_ID, 'text_to_sticker_picker_enabled', '1') === '1' && $this->config->getUserValue($this->userId, Application::APP_ID, 'text_to_sticker_picker_enabled', '1') === '1') { - // Double check that at least one provider is registered + // Double check that all necessary task types are available + // For some reason, taskProcessingManager->getAvailableTaskTypeIds does not return all the task types here + // most likely because all providers are not registered when RenderReferenceEvent is fired $availableTaskTypes = $this->taskProcessingManager->getAvailableTaskTypes(); $textToImageAvailable = array_key_exists(TextToImage::ID, $availableTaskTypes); - if ($textToImageAvailable) { + $textToStickerAvailable = array_key_exists(TextToStickerTaskType::ID, $availableTaskTypes); + if ($textToImageAvailable && $textToStickerAvailable) { Util::addScript(Application::APP_ID, Application::APP_ID . '-stickerGeneration'); } } diff --git a/lib/Reference/Text2StickerProvider.php b/lib/Reference/Text2StickerProvider.php index e23230ceb..c4006f554 100644 --- a/lib/Reference/Text2StickerProvider.php +++ b/lib/Reference/Text2StickerProvider.php @@ -89,6 +89,4 @@ public function getCacheKey(string $referenceId): ?string { public function invalidateUserCache(string $userId): void { $this->referenceManager->invalidateCache($userId); } - - } From 127ef72c2caa7f0a2d9384ec444dba119f9d77f1 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 5 Nov 2025 16:58:48 +0100 Subject: [PATCH 2/6] fix(sticker-picker): fix personal settings Signed-off-by: Julien Veyssier --- src/components/PersonalSettings.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/PersonalSettings.vue b/src/components/PersonalSettings.vue index da51709d8..3efd101b7 100644 --- a/src/components/PersonalSettings.vue +++ b/src/components/PersonalSettings.vue @@ -39,7 +39,7 @@ + @update:model-value="onCheckboxChanged($event, 'text_to_sticker_picker_enabled')">
{{ t('assistant', 'Enable AI sticker generation in smart picker') }}
From 7901a3e38812ab22eb25aee8d0d322ac6352f75b Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 5 Nov 2025 17:10:16 +0100 Subject: [PATCH 3/6] fix(sticker-picker): fix admin settings, do not edit the value automatically Signed-off-by: Julien Veyssier --- lib/Settings/Admin.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index b410b5afa..76f66e51d 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -42,11 +42,9 @@ public function getForm(): TemplateResponse { $freePromptPickerEnabled = $this->appConfig->getValueString(Application::APP_ID, 'free_prompt_picker_enabled', '1') === '1'; $textToImagePickerEnabled = $this->appConfig->getValueString(Application::APP_ID, 'text_to_image_picker_enabled', '1') === '1'; + // if we can't generate images, let's assume the sticker picker is disabled + // but when image generation will be available again, we have kept the value set by the admin $textToStickerPickerEnabled = $this->appConfig->getValueString(Application::APP_ID, 'text_to_sticker_picker_enabled', '1') === '1'; - if ($textToStickerPickerEnabled && !$textToImageAvailable) { - $this->appConfig->setValueString(Application::APP_ID, 'text_to_sticker_picker_enabled', '0'); - $textToStickerPickerEnabled = false; - } $speechToTextEnabled = $this->appConfig->getValueString(Application::APP_ID, 'speech_to_text_picker_enabled', '1') === '1'; $chattyLLMUserInstructions = $this->appConfig->getValueString(Application::APP_ID, 'chat_user_instructions', Application::CHAT_USER_INSTRUCTIONS) ?: Application::CHAT_USER_INSTRUCTIONS; From e74f6945dec3f70b16b360b3c86463abec7aad59 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 5 Nov 2025 17:23:52 +0100 Subject: [PATCH 4/6] fix(pickers): fix admin settings, improve warning messages Signed-off-by: Julien Veyssier --- src/components/AdminSettings.vue | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index 1ed8e0db5..e90e952ec 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -21,7 +21,7 @@ {{ t('assistant', 'Enable Nextcloud Assistant in header') }}
- + {{ t('assistant', 'To be able to use this feature, please install at least one AI task processing provider.') }}
- {{ t('assistant', 'To enable this feature, please install an AI task processing provider for the free prompt task type:') }} + {{ t('assistant', 'To enable text generation in the smart picker, please install an AI task processing provider for the "Free text to text prompt" task type:') }}
- +
- {{ t('assistant', 'To enable this feature, please install a text-to-image provider:') }} + {{ t('assistant', 'To enable the sticker generation picker or the image generation picker, please install and enable a "Generate image" provider:') }}
- +
- {{ t('assistant', 'To enable this feature, please install a speech-to-text provider:') }} + {{ t('assistant', 'To enable speech-to-text in the smart picker, please install and enable a "Transcribe audio" provider:') }}
  • Local Speech-To-Text Whisper
  • From 46583c7ee84029d151c07e26e71a3cb78b91ab9c Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 5 Nov 2025 17:32:44 +0100 Subject: [PATCH 5/6] fix(picker-generation): make sticker generation tasks fail if image generation is not available Signed-off-by: Julien Veyssier --- lib/TaskProcessing/TextToStickerProvider.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/TaskProcessing/TextToStickerProvider.php b/lib/TaskProcessing/TextToStickerProvider.php index 77bfc5d70..ce33b578b 100644 --- a/lib/TaskProcessing/TextToStickerProvider.php +++ b/lib/TaskProcessing/TextToStickerProvider.php @@ -13,6 +13,7 @@ use OCA\Assistant\AppInfo\Application; use OCA\Assistant\Service\TaskProcessingService; use OCP\IL10N; +use OCP\TaskProcessing\IManager; use OCP\TaskProcessing\ISynchronousProvider; use OCP\TaskProcessing\Task; use OCP\TaskProcessing\TaskTypes\TextToImage; @@ -24,6 +25,7 @@ class TextToStickerProvider implements ISynchronousProvider { public function __construct( private IL10N $l, private TaskProcessingService $taskProcessingService, + private IManager $taskProcessingManager, private LoggerInterface $logger, ) { } @@ -83,6 +85,11 @@ public function process(?string $userId, array $input, callable $reportProgress) } $input = $input['input']; + $availableTaskTypes = $this->taskProcessingManager->getAvailableTaskTypes(); + if (!array_key_exists(TextToImage::ID, $availableTaskTypes)) { + throw new RuntimeException('Text to image task type not available'); + } + // Generate Image with custom prompt try { $task = new Task( From a6bdc159d23413549d07073d86f369c5de09742d Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 5 Nov 2025 17:33:24 +0100 Subject: [PATCH 6/6] fix(picker-generation): add admin setting warning if sticker generation is enabled while image generation is not available Signed-off-by: Julien Veyssier --- lib/Settings/Admin.php | 3 +++ src/components/AdminSettings.vue | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 76f66e51d..e0df7ee80 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -8,6 +8,7 @@ namespace OCA\Assistant\Settings; use OCA\Assistant\AppInfo\Application; +use OCA\Assistant\TaskProcessing\TextToStickerTaskType; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; use OCP\IAppConfig; @@ -37,6 +38,7 @@ public function getForm(): TemplateResponse { $freePromptTaskTypeAvailable = array_key_exists(TextToText::ID, $availableTaskTypes); $speechToTextAvailable = array_key_exists(AudioToText::ID, $availableTaskTypes); $textToImageAvailable = array_key_exists(TextToImage::ID, $availableTaskTypes); + $textToStickerAvailable = array_key_exists(TextToStickerTaskType::ID, $availableTaskTypes); $assistantEnabled = $this->appConfig->getValueString(Application::APP_ID, 'assistant_enabled', '1') === '1'; @@ -55,6 +57,7 @@ public function getForm(): TemplateResponse { 'text_processing_available' => $taskProcessingAvailable, 'assistant_enabled' => $assistantEnabled, 'text_to_image_picker_available' => $textToImageAvailable, + 'text_to_sticker_available' => $textToStickerAvailable, 'text_to_image_picker_enabled' => $textToImagePickerEnabled, 'text_to_sticker_picker_enabled' => $textToStickerPickerEnabled, 'free_prompt_task_type_available' => $freePromptTaskTypeAvailable, diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index e90e952ec..86121e07f 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -9,6 +9,9 @@ {{ t('assistant', 'Nextcloud Assistant') }}

    {{ t('assistant', 'Find more details on how to set up Assistant and recommended backends in the Administration documentation.') }}

    + + {{ t('assistant', 'The sticker generation feature won`t work without being able to generate images. Please install and enable a "Generate image" provider or disable the "Generate sticker" task type.') }} +