From 3f139da9f69920b2720df72f56c5f7a31c15b629 Mon Sep 17 00:00:00 2001 From: Amit Bora Date: Sat, 12 Apr 2025 19:46:27 +0000 Subject: [PATCH] feat: Update config feature to use options instead of string input - Replaced prompt-based string input with predefined options for modifying LLM behavior. - Users can now select from a list of options for more intuitive configuration. - Refactored the config logic to accommodate new options-based structure. Closes #36 --- src/definition/helper/userPreference.ts | 17 ++++- .../Element/IMultiStaticSelectElement.ts | 17 +++++ src/enum/modals/UserPreferenceModal.ts | 4 +- src/handlers/AIHandler.ts | 2 +- src/handlers/ExecuteViewSubmitHandler.ts | 8 +-- src/lib/ElementBuilder.ts | 63 +++++++++++++++++++ src/lib/Translation/locales/de.ts | 4 +- src/lib/Translation/locales/en.ts | 4 +- src/lib/Translation/locales/pl.ts | 4 +- src/lib/Translation/locales/pt.ts | 4 +- src/lib/Translation/locales/ru.ts | 4 +- src/modal/UserPreferenceModal.ts | 36 ++++++++--- src/storage/userPreferenceStorage.ts | 8 +-- 13 files changed, 144 insertions(+), 31 deletions(-) create mode 100644 src/definition/ui-kit/Element/IMultiStaticSelectElement.ts diff --git a/src/definition/helper/userPreference.ts b/src/definition/helper/userPreference.ts index 1f88b2b..743625e 100644 --- a/src/definition/helper/userPreference.ts +++ b/src/definition/helper/userPreference.ts @@ -20,12 +20,27 @@ export enum AIProviderEnum { SelfHosted = 'Self Hosted', } +export enum PromptOptionsEnum { + Professional = 'Professional', + Friendly = 'Friendly', + Supportive = 'Supportive', + Concise = 'Concise', + Detailed = 'Detailed', + Actionable = 'Actionable', + Persuasive = 'Persuasive', + Analytical = 'Analytical', + Neutral = 'Neutral', + Helpful = 'Helpful', +} + +export type PromptOptions = keyof typeof PromptOptionsEnum; + export interface IPreference { userId: string; language: Language; AIusagePreference: AIusagePreference; AIconfiguration: { - AIPrompt: string; + AIPromptOptions: PromptOptions[]; AIProvider: AIProviderType; selfHosted: { url: string; diff --git a/src/definition/ui-kit/Element/IMultiStaticSelectElement.ts b/src/definition/ui-kit/Element/IMultiStaticSelectElement.ts new file mode 100644 index 0000000..ea3fd28 --- /dev/null +++ b/src/definition/ui-kit/Element/IMultiStaticSelectElement.ts @@ -0,0 +1,17 @@ +import { MultiStaticSelectElement } from '@rocket.chat/ui-kit'; + +export type MultiStaticSelectElementParam = Pick< + MultiStaticSelectElement, + | 'options' + | 'optionGroups' + | 'initialOption' + | 'initialValue' + | 'dispatchActionConfig' +> & { placeholder: string }; + +export type MultiStaticSelectOptionsParam = Array<{ + text: string; + value: string; + description?: string; + url?: string; +}>; diff --git a/src/enum/modals/UserPreferenceModal.ts b/src/enum/modals/UserPreferenceModal.ts index 957b5db..c0a2593 100644 --- a/src/enum/modals/UserPreferenceModal.ts +++ b/src/enum/modals/UserPreferenceModal.ts @@ -20,8 +20,8 @@ export enum UserPreferenceModalEnum { GEMINI_API_KEY_BLOCK_ID = 'gemini-api-key-block-id', SELF_HOSTED_URL_ACTION_ID = 'self-hosted-url-action-id', SELF_HOSTED_URL_BLOCK_ID = 'self-hosted-url-block-id', - PROMPT_CONFIG_INPUT_BLOCK_ID = 'prompt-config-input-block-id', - PROMPT_CONFIG_INPUT_ACTION_ID = 'prompt-config-input-action-id', + PROMPT_CONFIG_OPTIONS_BLOCK_ID = 'prompt-config-options-block-id', + PROMPT_CONFIG_OPTIONS_ACTION_ID = 'prompt-config-options-action-id', SUBMIT_ACTION_ID = 'submit-set-user-preference-language-modal-action-id', SUBMIT_BLOCK_ID = 'submit-set-user-preference-language-modal-block-id', diff --git a/src/handlers/AIHandler.ts b/src/handlers/AIHandler.ts index e4ddf52..36a4285 100644 --- a/src/handlers/AIHandler.ts +++ b/src/handlers/AIHandler.ts @@ -64,7 +64,7 @@ class AIHandler { } private getPrompt(message: string, prompt: string): string { - return `Write a reply to this message: "${message}". ${this.userPreference.AIconfiguration.AIPrompt} and Use the following as a prompt or response reply: "${prompt}" and make sure you respond with just the reply without quotes.`; + return `Write a reply to this message: "${message}".Reply must be ${this.userPreference.AIconfiguration.AIPromptOptions} Use the as a prompt or response reply: "${prompt}" and make sure you respond with just the reply without quotes.`; } private async handleSelfHostedModel( diff --git a/src/handlers/ExecuteViewSubmitHandler.ts b/src/handlers/ExecuteViewSubmitHandler.ts index 53334e5..df171d9 100644 --- a/src/handlers/ExecuteViewSubmitHandler.ts +++ b/src/handlers/ExecuteViewSubmitHandler.ts @@ -210,10 +210,10 @@ export class ExecuteViewSubmitHandler { UserPreferenceModalEnum.SELF_HOSTED_URL_ACTION_ID ]; - const PromptConfigurationInput = + const PromptConfigurationOptions = view.state?.[ - UserPreferenceModalEnum.PROMPT_CONFIG_INPUT_BLOCK_ID - ]?.[UserPreferenceModalEnum.PROMPT_CONFIG_INPUT_ACTION_ID]; + UserPreferenceModalEnum.PROMPT_CONFIG_OPTIONS_BLOCK_ID + ]?.[UserPreferenceModalEnum.PROMPT_CONFIG_OPTIONS_ACTION_ID]; const userPreference = new UserPreferenceStorage( this.persistence, @@ -226,7 +226,7 @@ export class ExecuteViewSubmitHandler { language: languageInput, AIusagePreference: AIpreferenceInput, AIconfiguration: { - AIPrompt: PromptConfigurationInput, + AIPromptOptions: PromptConfigurationOptions, AIProvider: AIoptionInput, openAI: { apiKey: OpenAIAPIKeyInput, diff --git a/src/lib/ElementBuilder.ts b/src/lib/ElementBuilder.ts index 7fa0dbc..2c79466 100644 --- a/src/lib/ElementBuilder.ts +++ b/src/lib/ElementBuilder.ts @@ -12,12 +12,17 @@ import { PlainTextInputElement, Option, StaticSelectElement, + MultiStaticSelectElement, } from '@rocket.chat/ui-kit'; import { PlainTextInputParam } from '../definition/ui-kit/Element/IPlainTextInputElement'; import { StaticSelectElementParam, StaticSelectOptionsParam, } from '../definition/ui-kit/Element/IStaticSelectElement'; +import { + MultiStaticSelectElementParam, + MultiStaticSelectOptionsParam, +} from '../definition/ui-kit/Element/IMultiStaticSelectElement'; export class ElementBuilder implements IElementBuilder { constructor(private readonly appId: string) {} @@ -146,4 +151,62 @@ export class ElementBuilder implements IElementBuilder { }); return options; } + + public addMultiSelect( + param: MultiStaticSelectElementParam, + interaction: ElementInteractionParam, + ): MultiStaticSelectElement { + const { + placeholder, + options, + optionGroups, + initialOption, + initialValue, + dispatchActionConfig, + } = param; + const { blockId, actionId } = interaction; + const multiSelect: MultiStaticSelectElement = { + type: BlockElementType.MULTI_STATIC_SELECT, + placeholder: { + type: TextObjectType.PLAIN_TEXT, + text: placeholder, + }, + options, + optionGroups, + initialOption, + initialValue, + appId: this.appId, + blockId, + actionId, + dispatchActionConfig, + }; + return multiSelect; + } + + public createMultiSelectOptions( + param: MultiStaticSelectOptionsParam, + ): Array