Skip to content

Commit 4ea0e2a

Browse files
committed
fix: improve AI error messages with role-aware notifications
1 parent 9e9bcd5 commit 4ea0e2a

10 files changed

Lines changed: 86 additions & 101 deletions

File tree

src/config/settings.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const settings: Array<ISetting> = [
1919
id: SettingEnum.AI_PROVIDER_OPTOIN_ID,
2020
type: SettingType.SELECT,
2121
packageValue: SettingEnum.SELF_HOSTED_MODEL,
22-
required: true,
22+
required: false,
2323
public: false,
2424
i18nLabel: 'Choose_AI_Provider_Label',
2525
i18nPlaceholder: 'Choose_AI_Provider_Placeholder',
@@ -42,7 +42,7 @@ export const settings: Array<ISetting> = [
4242
id: SettingEnum.SELF_HOSTED_MODEL_ADDRESS_ID,
4343
type: SettingType.STRING,
4444
packageValue: '',
45-
required: true,
45+
required: false,
4646
public: false,
4747
i18nLabel: 'Self_Hosted_AI_Model_URL_Label',
4848
i18nPlaceholder: 'Self_Hosted_AI_Model_URL_Placeholder',
@@ -51,7 +51,7 @@ export const settings: Array<ISetting> = [
5151
id: SettingEnum.OPEN_AI_API_KEY_ID,
5252
type: SettingType.PASSWORD,
5353
packageValue: '',
54-
required: true,
54+
required: false,
5555
public: false,
5656
i18nLabel: 'Open_AI_API_Key_Label',
5757
i18nPlaceholder: 'Open_AI_API_Key_Placeholder',
@@ -60,7 +60,7 @@ export const settings: Array<ISetting> = [
6060
id: SettingEnum.OPEN_AI_API_MODEL_ID,
6161
type: SettingType.STRING,
6262
packageValue: '',
63-
required: true,
63+
required: false,
6464
public: false,
6565
i18nLabel: 'Open_AI_Model',
6666
i18nPlaceholder: 'Open_AI_Model_Placeholder',
@@ -69,7 +69,7 @@ export const settings: Array<ISetting> = [
6969
id: SettingEnum.GEMINI_AI_API_KEY_ID,
7070
type: SettingType.PASSWORD,
7171
packageValue: '',
72-
required: true,
72+
required: false,
7373
public: false,
7474
i18nLabel: 'Gemini_API_Key_Label',
7575
i18nPlaceholder: 'Gemini_API_Key_Placeholder',

src/handlers/AIHandler.ts

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,26 @@ class AIHandler {
1717
private app: QuickRepliesApp,
1818
private http: IHttp,
1919
private userPreference: IPreference,
20+
private user: IUser,
2021
) {}
2122
private language = this.userPreference.language;
2223

24+
private getConfigError(provider: string): string {
25+
if (
26+
this.userPreference.AIusagePreference ===
27+
AIusagePreferenceEnum.Personal
28+
) {
29+
return t('AI_Not_Configured_Personal', this.language, {
30+
provider,
31+
});
32+
}
33+
return this.user.roles.includes('admin')
34+
? t('AI_Not_Configured_Admin_Self', this.language, { provider })
35+
: t('AI_Not_Configured_Workspace_User', this.language, {
36+
provider,
37+
});
38+
}
39+
2340
public async handleResponse(
2441
user: IUser,
2542
message: string,
@@ -52,11 +69,7 @@ class AIHandler {
5269
return this.handleGemini(user, message, prompt);
5370

5471
default:
55-
const errorMsg =
56-
this.userPreference.AIusagePreference ===
57-
AIusagePreferenceEnum.Personal
58-
? t('AI_Not_Configured_Personal', this.language)
59-
: t('AI_Not_Configured_Admin', this.language);
72+
const errorMsg = this.getConfigError('AI provider');
6073

6174
this.app.getLogger().log(errorMsg);
6275
return errorMsg;
@@ -77,20 +90,7 @@ class AIHandler {
7790

7891
if (!url) {
7992
this.app.getLogger().log('Self Hosted Model address not set.');
80-
if (
81-
this.userPreference.AIusagePreference ===
82-
AIusagePreferenceEnum.Personal
83-
) {
84-
return t(
85-
'AI_Self_Hosted_Model_Not_Configured',
86-
this.language,
87-
);
88-
} else {
89-
return t(
90-
'AI_Workspace_Model_Not_Configured',
91-
this.language,
92-
);
93-
}
93+
return this.getConfigError('Self Hosted Model URL');
9494
}
9595

9696
const requestBody = {
@@ -151,13 +151,7 @@ class AIHandler {
151151

152152
if (!openaikey || !openaimodel) {
153153
this.app.getLogger().log('OpenAI settings not set properly.');
154-
const errorMsg =
155-
this.userPreference.AIusagePreference ===
156-
AIusagePreferenceEnum.Personal
157-
? t('AI_OpenAI_Model_Not_Configured', this.language)
158-
: t('AI_Not_Configured_Admin', this.language);
159-
160-
return errorMsg;
154+
return this.getConfigError('OpenAI API key or model');
161155
}
162156

163157
const response: IHttpResponse = await this.http.post(
@@ -228,14 +222,7 @@ class AIHandler {
228222

229223
if (!geminiAPIkey) {
230224
this.app.getLogger().log('Gemini API key not set Properly');
231-
232-
const errorMsg =
233-
this.userPreference.AIusagePreference ===
234-
AIusagePreferenceEnum.Personal
235-
? t('AI_Gemini_Model_Not_Configured', this.language)
236-
: t('AI_Not_Configured_Admin', this.language);
237-
238-
return errorMsg;
225+
return this.getConfigError('Gemini API key');
239226
}
240227

241228
const response: IHttpResponse = await this.http.post(

src/handlers/ExecuteBlockActionHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ export class ExecuteBlockActionHandler {
257257
this.app,
258258
this.http,
259259
Preference,
260+
user,
260261
).handleResponse(user, message, prompt);
261262

262263
await aiStorage.updateResponse(response);

src/handlers/Handler.ts

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import { IReply } from '../definition/reply/IReply';
1616
import {
1717
sendDefaultNotification,
1818
sendHelperNotification,
19+
sendNotification,
1920
} from '../helper/notification';
2021
import { UserPreferenceModal } from '../modal/UserPreferenceModal';
21-
import { Language } from '../lib/Translation/translation';
22+
import { Language, t } from '../lib/Translation/translation';
2223
import { ReplyAIModal } from '../modal/AIreplyModal';
2324
import { AIstorage } from '../storage/AIStorage';
2425
import { UserPreferenceStorage } from '../storage/userPreferenceStorage';
@@ -173,37 +174,46 @@ export class Handler implements IHandler {
173174
'';
174175
const textMessage = Message.trim();
175176

176-
if (textMessage) {
177-
const aistorage = new AIstorage(
178-
this.persis,
179-
this.read.getPersistenceReader(),
180-
this.sender.id,
181-
);
182-
aistorage.updateMessage(textMessage);
183-
const modal = await ReplyAIModal(
184-
this.app,
185-
this.sender,
177+
if (!textMessage) {
178+
await sendNotification(
186179
this.read,
187-
this.persis,
188180
this.modify,
181+
this.sender,
189182
this.room,
190-
this.language,
191-
textMessage,
183+
{ message: t('AI_No_Message_Found', this.language) },
192184
);
185+
return;
186+
}
193187

194-
if (modal instanceof Error) {
195-
this.app.getLogger().error(modal.message);
196-
return;
197-
}
198-
199-
const triggerId = this.triggerId;
188+
const aistorage = new AIstorage(
189+
this.persis,
190+
this.read.getPersistenceReader(),
191+
this.sender.id,
192+
);
193+
aistorage.updateMessage(textMessage);
194+
const modal = await ReplyAIModal(
195+
this.app,
196+
this.sender,
197+
this.read,
198+
this.persis,
199+
this.modify,
200+
this.room,
201+
this.language,
202+
textMessage,
203+
);
200204

201-
if (triggerId) {
202-
await this.modify
203-
.getUiController()
204-
.openSurfaceView(modal, { triggerId }, this.sender);
205-
}
205+
if (modal instanceof Error) {
206+
this.app.getLogger().error(modal.message);
206207
return;
207208
}
209+
210+
const triggerId = this.triggerId;
211+
212+
if (triggerId) {
213+
await this.modify
214+
.getUiController()
215+
.openSurfaceView(modal, { triggerId }, this.sender);
216+
}
217+
return;
208218
}
209219
}

src/lib/Translation/locales/de.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ export const de = {
7979
Send_This_Text: "Diese Antwort senden",
8080
AI_Prompt_Options_Label: "AI-Eingabeaufforderungsoptionen",
8181
AI_Prompt_Options_Placeholder: "Wählen Sie AI-Konfigurationsoptionen",
82-
AI_Not_Configured_Personal: "AI ist nicht konfiguriert. Bitte überprüfen Sie Ihre Konfiguration, um diese Funktion zu nutzen.",
83-
AI_Not_Configured_Admin: "AI ist nicht konfiguriert. Bitte kontaktieren Sie Ihren Administrator, um diese Funktion zu nutzen.",
84-
AI_Self_Hosted_Model_Not_Configured: "Ihr selbst gehostetes Modell ist nicht richtig eingerichtet. Bitte überprüfen Sie Ihre Konfiguration",
85-
AI_OpenAI_Model_Not_Configured: "Ihr OpenAI-Modell ist nicht richtig eingerichtet. Bitte überprüfen Sie Ihre Konfiguration",
86-
AI_Gemini_Model_Not_Configured: "Ihr Gemini-Modell ist nicht richtig eingerichtet. Bitte überprüfen Sie Ihre Konfiguration",
87-
AI_Workspace_Model_Not_Configured: "Ihre Workspace-AI ist nicht richtig eingerichtet. Bitte kontaktieren Sie Ihren Administrator",
82+
AI_Not_Configured_Personal: "Ihr __provider__ ist nicht konfiguriert. Bitte richten Sie es mit `/quick config` ein.",
83+
AI_Not_Configured_Admin_Self: "Der __provider__ ist nicht konfiguriert. Bitte fügen Sie ihn in den App-Einstellungen hinzu.",
84+
AI_Not_Configured_Workspace_User: "Der __provider__ ist nicht konfiguriert. Bitte kontaktieren Sie Ihren Administrator.",
8885
AI_Something_Went_Wrong: "Etwas ist schiefgelaufen. Bitte versuchen Sie es später noch einmal.",
86+
AI_No_Message_Found: "Keine Nachricht in diesem Raum gefunden, um eine Antwort zu generieren. Bitte senden Sie zuerst eine Nachricht.",
8987
Refresh_Button_Text: "Aktualisieren"
9088

9189
}

src/lib/Translation/locales/en.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,9 @@ export const en = {
7979
Send_This_Text: "Send this reply",
8080
AI_Prompt_Options_Label : "AI Prompt Options",
8181
AI_Prompt_Options_Placeholder : "Select AI Configuration Options",
82-
AI_Not_Configured_Personal: "AI is not configured. Please Check your configuration to use this feature.",
83-
AI_Not_Configured_Admin: "AI is not configured. Please contact your administrator to use this feature.",
84-
AI_Self_Hosted_Model_Not_Configured: "Your Self Hosted Model is not set up properly. Please check your configuration",
85-
AI_OpenAI_Model_Not_Configured: "Your OpenAI Model is not set up properly. Please check your configuration",
86-
AI_Gemini_Model_Not_Configured: "Your Gemini Model is not set up properly. Please check your configuration",
87-
AI_Workspace_Model_Not_Configured: "Your Workspace AI is not set up properly. Please contact your administrator",
82+
AI_Not_Configured_Personal: "Your __provider__ is not configured. Please set it up using `/quick config`.",
83+
AI_Not_Configured_Admin_Self: "The __provider__ is not configured. Please add it in the app settings.",
84+
AI_Not_Configured_Workspace_User: "The __provider__ is not configured. Please contact your administrator.",
8885
AI_Something_Went_Wrong: "Something went wrong. Please try again later.",
86+
AI_No_Message_Found: "No message found in this room to generate a reply for. Please send a message first.",
8987
Refresh_Button_Text: "Refresh"};

src/lib/Translation/locales/pl.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ export const pl = {
7979
Send_This_Text: "Wyślij tę odpowiedź",
8080
AI_Prompt_Options_Label: "Opcje podpowiedzi AI",
8181
AI_Prompt_Options_Placeholder: "Wybierz Opcje konfiguracji AI",
82-
AI_Not_Configured_Personal: "AI nie jest skonfigurowane. Proszę sprawdzić swoją konfigurację, aby skorzystać z tej funkcji.",
83-
AI_Not_Configured_Admin: "AI nie jest skonfigurowane. Proszę skontaktować się z administratorem, aby skorzystać z tej funkcji.",
84-
AI_Self_Hosted_Model_Not_Configured: "Twój model hostowany lokalnie nie jest poprawnie skonfigurowany. Proszę sprawdzić swoją konfigurację",
85-
AI_OpenAI_Model_Not_Configured: "Twój model OpenAI nie jest poprawnie skonfigurowany. Proszę sprawdzić swoją konfigurację",
86-
AI_Gemini_Model_Not_Configured: "Twój model Gemini nie jest poprawnie skonfigurowany. Proszę sprawdzić swoją konfigurację",
87-
AI_Workspace_Model_Not_Configured: "Twoja AI w Workspace nie jest poprawnie skonfigurowana. Proszę skontaktować się z administratorem",
82+
AI_Not_Configured_Personal: "Twój __provider__ nie jest skonfigurowany. Proszę skonfigurować go używając `/quick config`.",
83+
AI_Not_Configured_Admin_Self: "__provider__ nie jest skonfigurowany. Proszę dodać go w ustawieniach aplikacji.",
84+
AI_Not_Configured_Workspace_User: "__provider__ nie jest skonfigurowany. Proszę skontaktować się z administratorem.",
8885
AI_Something_Went_Wrong: "Coś poszło nie tak. Proszę spróbować ponownie później.",
86+
AI_No_Message_Found: "Nie znaleziono wiadomości w tym pokoju do wygenerowania odpowiedzi. Proszę najpierw wysłać wiadomość.",
8987
Refresh_Button_Text: "Odśwież"
9088

9189
}

src/lib/Translation/locales/pt.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ export const pt = {
7979
Send_This_Text: "Enviar esta resposta",
8080
AI_Prompt_Options_Label: "Opções de prompt de IA",
8181
AI_Prompt_Options_Placeholder: "Selecione opções de configuração de IA",
82-
AI_Not_Configured_Personal: "IA não está configurada. Por favor, verifique sua configuração para usar este recurso.",
83-
AI_Not_Configured_Admin: "IA não está configurada. Por favor, entre em contato com o administrador para usar este recurso.",
84-
AI_Self_Hosted_Model_Not_Configured: "Seu Modelo Auto-Hospedado não está configurado corretamente. Por favor, verifique sua configuração",
85-
AI_OpenAI_Model_Not_Configured: "Seu Modelo OpenAI não está configurado corretamente. Por favor, verifique sua configuração",
86-
AI_Gemini_Model_Not_Configured: "Seu Modelo Gemini não está configurado corretamente. Por favor, verifique sua configuração",
87-
AI_Workspace_Model_Not_Configured: "Sua IA do Workspace não está configurada corretamente. Por favor, entre em contato com o administrador",
82+
AI_Not_Configured_Personal: "Seu __provider__ não está configurado. Por favor, configure-o usando `/quick config`.",
83+
AI_Not_Configured_Admin_Self: "O __provider__ não está configurado. Por favor, adicione-o nas configurações do app.",
84+
AI_Not_Configured_Workspace_User: "O __provider__ não está configurado. Por favor, entre em contato com o administrador.",
8885
AI_Something_Went_Wrong: "Algo deu errado. Por favor, tente novamente mais tarde.",
86+
AI_No_Message_Found: "Nenhuma mensagem encontrada nesta sala para gerar uma resposta. Por favor, envie uma mensagem primeiro.",
8987
Refresh_Button_Text: "Atualizar"
9088

9189
}

src/lib/Translation/locales/ru.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ export const ru = {
7979
Send_This_Text: "Отправить этот ответ",
8080
AI_Prompt_Options_Label: "Параметры подсказок ИИ",
8181
AI_Prompt_Options_Placeholder: "Выберите параметры конфигурации AI",
82-
AI_Not_Configured_Personal: "ИИ не настроен. Пожалуйста, проверьте свою конфигурацию, чтобы использовать эту функцию.",
83-
AI_Not_Configured_Admin: "ИИ не настроен. Пожалуйста, свяжитесь с администратором, чтобы использовать эту функцию.",
84-
AI_Self_Hosted_Model_Not_Configured: "Ваша собственная модель не настроена должным образом. Пожалуйста, проверьте свою конфигурацию",
85-
AI_OpenAI_Model_Not_Configured: "Ваша модель OpenAI не настроена должным образом. Пожалуйста, проверьте свою конфигурацию",
86-
AI_Gemini_Model_Not_Configured: "Ваша модель Gemini не настроена должным образом. Пожалуйста, проверьте свою конфигурацию",
87-
AI_Workspace_Model_Not_Configured: "Ваша AI в Workspace не настроена должным образом. Пожалуйста, свяжитесь с администратором",
82+
AI_Not_Configured_Personal: "Ваш __provider__ не настроен. Пожалуйста, настройте его с помощью `/quick config`.",
83+
AI_Not_Configured_Admin_Self: "__provider__ не настроен. Пожалуйста, добавьте его в настройках приложения.",
84+
AI_Not_Configured_Workspace_User: "__provider__ не настроен. Пожалуйста, свяжитесь с администратором.",
8885
AI_Something_Went_Wrong: "Что-то пошло не так. Пожалуйста, попробуйте позже.",
86+
AI_No_Message_Found: "Сообщение не найдено в этой комнате для генерации ответа. Пожалуйста, сначала отправьте сообщение.",
8987
Refresh_Button_Text: "Обновить"
9088

9189
}

src/lib/Translation/translation.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ export enum Language {
1515
}
1616

1717
export const ErrorKeys = [
18-
'AI_Not_Configured_Personal',
19-
'AI_Not_Configured_Admin',
20-
'AI_Self_Hosted_Model_Not_Configured',
21-
'AI_OpenAI_Model_Not_Configured',
22-
'AI_Gemini_Model_Not_Configured',
23-
'AI_Workspace_Model_Not_Configured',
24-
'AI_Something_Went_Wrong'
18+
'AI_Not_Configured_Personal',
19+
'AI_Not_Configured_Admin_Self',
20+
'AI_Not_Configured_Workspace_User',
21+
'AI_Something_Went_Wrong',
2522
] as TranslationKey[];
2623

2724
export const t = (key: TranslationKey, language: Language, params?: object) => {

0 commit comments

Comments
 (0)