diff --git a/lib/Controller/AssistantController.php b/lib/Controller/AssistantController.php index 17fee784..66ad1c36 100644 --- a/lib/Controller/AssistantController.php +++ b/lib/Controller/AssistantController.php @@ -64,7 +64,10 @@ public function getAssistantStandalonePage(): TemplateResponse { $this->userId, '' ); - $this->initialStateService->provideInitialState('task', $task->jsonSerialize()); + $serializedTask = $task->jsonSerialize(); + // otherwise the task id is 0 and the default input shape values are not set + $serializedTask['id'] = null; + $this->initialStateService->provideInitialState('task', $serializedTask); return new TemplateResponse(Application::APP_ID, 'assistantPage'); } return new TemplateResponse('', '403', [], TemplateResponse::RENDER_AS_ERROR, Http::STATUS_FORBIDDEN); diff --git a/lib/Listener/BeforeTemplateRenderedListener.php b/lib/Listener/BeforeTemplateRenderedListener.php index 3f2714c6..193d1b28 100644 --- a/lib/Listener/BeforeTemplateRenderedListener.php +++ b/lib/Listener/BeforeTemplateRenderedListener.php @@ -53,6 +53,10 @@ public function handle(Event $event): void { $userAssistantEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'assistant_enabled', '1') === '1'; $assistantEnabled = $adminAssistantEnabled && $userAssistantEnabled; $this->initialStateService->provideInitialState('assistant-enabled', $assistantEnabled); + if ($assistantEnabled) { + $lastTargetLanguage = $this->config->getUserValue($this->userId, Application::APP_ID, 'last_target_language', ''); + $this->initialStateService->provideInitialState('last-target-language', $lastTargetLanguage); + } Util::addScript(Application::APP_ID, Application::APP_ID . '-main'); } } diff --git a/src/assistant.js b/src/assistant.js index 44ee47e5..176feca1 100644 --- a/src/assistant.js +++ b/src/assistant.js @@ -235,6 +235,9 @@ export async function scheduleTask(appId, customId, taskType, inputs) { const { default: axios } = await import('@nextcloud/axios') const { generateOcsUrl } = await import('@nextcloud/router') saveLastSelectedTaskType(taskType) + if (taskType === 'core:text2text:translate') { + saveLastTargetLanguage(inputs.target_language) + } const url = generateOcsUrl('taskprocessing/schedule') const params = { input: inputs, @@ -271,6 +274,21 @@ async function getLastSelectedTaskType() { return axios.get(url, req) } +async function saveLastTargetLanguage(targetLanguage) { + OCA.Assistant.last_target_language = targetLanguage + + const { default: axios } = await import('@nextcloud/axios') + const { generateUrl } = await import('@nextcloud/router') + + const req = { + values: { + last_target_language: targetLanguage, + }, + } + const url = generateUrl('/apps/assistant/config') + return axios.put(url, req) +} + /** * Check if we want to cancel a notification action click and handle it ourselves * diff --git a/src/components/AssistantTextProcessingForm.vue b/src/components/AssistantTextProcessingForm.vue index c5bf9501..81b052e7 100644 --- a/src/components/AssistantTextProcessingForm.vue +++ b/src/components/AssistantTextProcessingForm.vue @@ -365,6 +365,7 @@ export default { } else { this.parseTextFileInputs(taskType) } + // add placeholders taskTypes.forEach(tt => { if (tt.id === TEXT2TEXT_TASK_TYPE_ID && tt.inputShape.input) { @@ -383,6 +384,12 @@ export default { } else if (tt.id === 'core:contextwrite' && tt.inputShape.source_input && tt.inputShape.style_input) { tt.inputShape.style_input.placeholder = t('assistant', 'Shakespeare or an example of the style') tt.inputShape.source_input.placeholder = t('assistant', 'A description of what you need or some original content') + } else if (tt.id === 'core:text2text:translate') { + tt.inputShapeDefaults.origin_language = 'detect_language' + const defaultTargetLanguage = OCA.Assistant.last_target_language + if (defaultTargetLanguage) { + tt.inputShapeDefaults.target_language = defaultTargetLanguage + } } }) this.taskTypes = taskTypes diff --git a/src/main.js b/src/main.js index 21c1eaed..74594a6c 100644 --- a/src/main.js +++ b/src/main.js @@ -26,6 +26,7 @@ function init() { subscribe('notifications:action:execute', handleNotification) if (loadState('assistant', 'assistant-enabled')) { addAssistantMenuEntry() + OCA.Assistant.last_target_language = loadState('assistant', 'last-target-language') } } }