Skip to content

Commit 6f13f98

Browse files
committed
feat(audio-chat): add personal setting to toggle autoplay, fix personal settings task type availability values
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 495ce20 commit 6f13f98

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

lib/Listener/BeforeTemplateRenderedListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function handle(Event $event): void {
6666
$indexingComplete = $this->appConfig->getValueInt('context_chat', 'last_indexed_time', 0) !== 0;
6767
$this->initialStateService->provideInitialState('contextChatIndexingComplete', $indexingComplete);
6868
$this->initialStateService->provideInitialState('contextAgentToolSources', $this->assistantService->informationSources);
69+
$autoplayAudioChat = $this->config->getUserValue($this->userId, Application::APP_ID, 'autoplay_audio_chat', '1') === '1';
70+
$this->initialStateService->provideInitialState('autoplayAudioChat', $autoplayAudioChat);
6971
}
7072
if (class_exists(\OCA\Viewer\Event\LoadViewer::class)) {
7173
$this->eventDispatcher->dispatchTyped(new \OCA\Viewer\Event\LoadViewer());

lib/Settings/Personal.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ public function getForm(): TemplateResponse {
3838

3939
$taskProcessingAvailable = $this->taskProcessingManager->hasProviders();
4040

41-
$freePromptTaskTypeAvailable = in_array(TextToText::ID, $availableTaskTypes);
42-
$speechToTextAvailable = in_array(AudioToText::ID, $availableTaskTypes);
43-
$textToImageAvailable = in_array(TextToImage::ID, $availableTaskTypes);
41+
$freePromptTaskTypeAvailable = array_key_exists(TextToText::ID, $availableTaskTypes);
42+
$speechToTextAvailable = array_key_exists(AudioToText::ID, $availableTaskTypes);
43+
$textToImageAvailable = array_key_exists(TextToImage::ID, $availableTaskTypes);
44+
45+
$audioChatAvailable = (class_exists('OCP\\TaskProcessing\\TaskTypes\\AudioToAudioChat') && array_key_exists(\OCP\TaskProcessing\TaskTypes\AudioToAudioChat::ID, $availableTaskTypes))
46+
|| (class_exists('OCP\\TaskProcessing\\TaskTypes\\ContextAgentAudioInteraction') && array_key_exists(\OCP\TaskProcessing\TaskTypes\ContextAgentAudioInteraction::ID, $availableTaskTypes));
47+
$autoplayAudioChat = $this->config->getUserValue($this->userId, Application::APP_ID, 'autoplay_audio_chat', '1') === '1';
4448

4549
$assistantAvailable = $taskProcessingAvailable && $this->appConfig->getValueString(Application::APP_ID, 'assistant_enabled', '1') === '1';
4650
$assistantEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'assistant_enabled', '1') === '1';
@@ -63,6 +67,8 @@ public function getForm(): TemplateResponse {
6367
'free_prompt_picker_enabled' => $freePromptPickerEnabled,
6468
'speech_to_text_picker_available' => $speechToTextPickerAvailable,
6569
'speech_to_text_picker_enabled' => $speechToTextPickerEnabled,
70+
'audio_chat_available' => $audioChatAvailable,
71+
'autoplay_audio_chat' => $autoplayAudioChat,
6672
];
6773
$this->initialStateService->provideInitialState('config', $userConfig);
6874

src/components/ChattyLLM/ChattyLLMInputForm.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ import AgencyConfirmation from './AgencyConfirmation.vue'
182182
import axios from '@nextcloud/axios'
183183
import { showError } from '@nextcloud/dialogs'
184184
import { generateUrl, generateOcsUrl } from '@nextcloud/router'
185+
import { loadState } from '@nextcloud/initial-state'
185186
import moment from 'moment'
186187
import { SHAPE_TYPE_NAMES } from '../../constants.js'
187188
@@ -250,6 +251,7 @@ export default {
250251
editingTitle: false,
251252
pollMessageGenerationTimerId: null,
252253
pollTitleGenerationTimerId: null,
254+
autoplayAudioChat: loadState('assistant', 'autoplayAudioChat', true),
253255
}
254256
},
255257
@@ -729,8 +731,10 @@ export default {
729731
) {
730732
this.updateLastHumanMessageContent()
731733
}
732-
// auto play fresh messages
733-
responseData.autoPlay = true
734+
if (this.autoplayAudioChat) {
735+
// auto play fresh messages
736+
responseData.autoPlay = true
737+
}
734738
resolve(responseData)
735739
} else {
736740
console.debug('Ignoring received message for session ' + sessionId + ' that is not selected anymore')

src/components/PersonalSettings.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
{{ t('assistant', 'Enable Nextcloud Assistant in header') }}
1717
</div>
1818
</NcCheckboxRadioSwitch>
19+
<NcCheckboxRadioSwitch v-if="state.audio_chat_available"
20+
:model-value="state.autoplay_audio_chat"
21+
@update:model-value="onCheckboxChanged($event, 'autoplay_audio_chat')">
22+
<div class="checkbox-text">
23+
{{ t('assistant', 'Auto-play audio chat responses') }}
24+
</div>
25+
</NcCheckboxRadioSwitch>
1926
<NcCheckboxRadioSwitch v-if="state.free_prompt_picker_available"
2027
:model-value="state.free_prompt_picker_enabled"
2128
@update:model-value="onCheckboxChanged($event, 'free_prompt_picker_enabled')">

0 commit comments

Comments
 (0)