Refactor inputs.py to add MessageInput and TextInput classes

This commit is contained in:
ogabrielluiz 2024-06-17 11:32:41 -03:00
commit c7a3624f21
2 changed files with 21 additions and 7 deletions

View file

@ -17,12 +17,12 @@ from .inputs import (
__all__ = [ __all__ = [
"SecretStrInput", "SecretStrInput",
"StrInput", "StrInput",
"IntInput", MultilineInput,
"FloatInput", NestedDictInput,
"BoolInput", PromptInput,
"NestedDictInput", SecretStrInput,
"DictInput", StrInput,
"DropdownInput", TextInput,
"FileInput", "FileInput",
"PromptInput", "PromptInput",
"MultilineInput", "MultilineInput",

View file

@ -40,8 +40,22 @@ class StrInput(BaseInputMixin, ListableInputMixin, DatabaseLoadMixin): # noqa:
"""Defines if the field will allow the user to open a text editor. Default is False.""" """Defines if the field will allow the user to open a text editor. Default is False."""
class MessageInput(StrInput):
input_types: list[str] = ["Message"]
@field_validator("value")
@classmethod
def validate_value(cls, v: Any, _info):
# If v is a instance of Message, then its fine
if isinstance(v, Message):
return v
if isinstance(v, str):
return Message(text=v)
raise ValueError(f"Invalid value type {type(v)}")
class TextInput(StrInput): class TextInput(StrInput):
input_types: list[str] = ["Data", "Message", "Text"] input_types: list[str] = ["Message"]
@field_validator("value") @field_validator("value")
@classmethod @classmethod