diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 555f319de..648153894 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -4359,5 +4359,6 @@ "enterPrompt": "Please enter a system prompt", "selectBotLanguage": "Select bot language", "chooseVoice": "Choose a voice", - "enterLanguageLevel": "Please enter a language level" + "enterLanguageLevel": "Please enter a language level", + "enterDiscussionTopic": "Please enter a discussion topic" } \ No newline at end of file diff --git a/lib/pages/new_group/new_group.dart b/lib/pages/new_group/new_group.dart index 3d8301ec5..5d6a17012 100644 --- a/lib/pages/new_group/new_group.dart +++ b/lib/pages/new_group/new_group.dart @@ -106,6 +106,20 @@ class NewGroupController extends State { // #Pangea // validate init bot options + if (addConversationBotKey.currentState?.formKey.currentState != null) { + final isValid = addConversationBotKey + .currentState!.formKey.currentState! + .validate(); + if (isValid == false) { + setState(() { + error = L10n.of(context)! + .conversationBotCustomZone_customSystemPromptEmptyError; + loading = false; + }); + return; + } + } + addConversationBotKey.currentState?.updateAllBotOptions(); final addBot = addConversationBotKey.currentState?.addBot ?? false; if (addBot) { final botOptions = addConversationBotKey.currentState!.botOptions; diff --git a/lib/pangea/widgets/conversation_bot/conversation_bot_mode_dynamic_zone.dart b/lib/pangea/widgets/conversation_bot/conversation_bot_mode_dynamic_zone.dart index 76aec7d62..dc1997a20 100644 --- a/lib/pangea/widgets/conversation_bot/conversation_bot_mode_dynamic_zone.dart +++ b/lib/pangea/widgets/conversation_bot/conversation_bot_mode_dynamic_zone.dart @@ -29,6 +29,9 @@ class ConversationBotModeDynamicZone extends StatelessWidget { .conversationBotDiscussionZone_discussionTopicPlaceholder, ), controller: discussionTopicController, + validator: (value) => value == null || value.isEmpty + ? L10n.of(context)!.enterDiscussionTopic + : null, ), const SizedBox(height: 12), TextFormField( diff --git a/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart b/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart index 3a8cc53ff..963949a78 100644 --- a/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart +++ b/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart @@ -99,6 +99,12 @@ class ConversationBotSettingsState extends State { ); } + void updateAllBotOptions() { + botOptions.discussionTopic = discussionTopicController.text; + botOptions.discussionKeywords = discussionKeywordsController.text; + botOptions.customSystemPrompt = customSystemPromptController.text; + } + Future showBotOptionsDialog() async { if (isCreating) return; final bool? confirm = await showDialog( @@ -135,10 +141,7 @@ class ConversationBotSettingsState extends State { ); if (confirm == true) { - botOptions.discussionTopic = discussionTopicController.text; - botOptions.discussionKeywords = discussionKeywordsController.text; - botOptions.customSystemPrompt = customSystemPromptController.text; - + updateAllBotOptions(); updateBotOption(() => botOptions = botOptions); final bool isBotRoomMember = await widget.room?.botIsInRoom ?? false; @@ -241,12 +244,34 @@ class ConversationBotSettingsState extends State { onTap: showBotOptionsDialog, ), if (isCreating && addBot) - ConversationBotSettingsForm( - botOptions: botOptions, - formKey: formKey, - discussionKeywordsController: discussionKeywordsController, - discussionTopicController: discussionTopicController, - customSystemPromptController: customSystemPromptController, + Padding( + padding: const EdgeInsets.all(16), + child: Column( + children: [ + Align( + alignment: Alignment.centerLeft, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 12), + child: Text( + L10n.of(context)!.botConfig, + style: Theme.of(context).textTheme.titleLarge, + ), + ), + ), + Form( + key: formKey, + child: ConversationBotSettingsForm( + botOptions: botOptions, + formKey: formKey, + discussionKeywordsController: + discussionKeywordsController, + discussionTopicController: discussionTopicController, + customSystemPromptController: + customSystemPromptController, + ), + ), + ], + ), ), ], ), diff --git a/lib/pangea/widgets/conversation_bot/conversation_bot_settings_form.dart b/lib/pangea/widgets/conversation_bot/conversation_bot_settings_form.dart index fb482ab1c..5447b67bb 100644 --- a/lib/pangea/widgets/conversation_bot/conversation_bot_settings_form.dart +++ b/lib/pangea/widgets/conversation_bot/conversation_bot_settings_form.dart @@ -95,7 +95,7 @@ class ConversationBotSettingsFormState validator: (value) => value == null ? L10n.of(context)!.enterLanguageLevel : null, ), - const SizedBox(height: 20), + const SizedBox(height: 12), Align( alignment: Alignment.centerLeft, child: Padding( @@ -106,7 +106,6 @@ class ConversationBotSettingsFormState ), ), ), - const SizedBox(height: 12), ConversationBotModeSelect( initialMode: botOptions.mode, onChanged: (String? mode) => {