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__ = [
"SecretStrInput",
"StrInput",
"IntInput",
"FloatInput",
"BoolInput",
"NestedDictInput",
"DictInput",
"DropdownInput",
MultilineInput,
NestedDictInput,
PromptInput,
SecretStrInput,
StrInput,
TextInput,
"FileInput",
"PromptInput",
"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."""
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):
input_types: list[str] = ["Data", "Message", "Text"]
input_types: list[str] = ["Message"]
@field_validator("value")
@classmethod