Config describing the literal payload emitted by the node.
| 17 | |
| 18 | @dataclass |
| 19 | class LiteralNodeConfig(BaseConfig): |
| 20 | """Config describing the literal payload emitted by the node.""" |
| 21 | |
| 22 | content: str = "" |
| 23 | role: MessageRole = MessageRole.USER |
| 24 | |
| 25 | @classmethod |
| 26 | def from_dict(cls, data: Mapping[str, Any], *, path: str) -> "LiteralNodeConfig": |
| 27 | mapping = require_mapping(data, path) |
| 28 | content = require_str(mapping, "content", path) |
| 29 | if not content: |
| 30 | raise ConfigError("content cannot be empty", f"{path}.content") |
| 31 | |
| 32 | role_value = optional_str(mapping, "role", path) |
| 33 | role = MessageRole.USER |
| 34 | if role_value: |
| 35 | normalized = role_value.strip().lower() |
| 36 | if normalized not in (MessageRole.USER.value, MessageRole.ASSISTANT.value): |
| 37 | raise ConfigError("role must be 'user' or 'assistant'", f"{path}.role") |
| 38 | role = MessageRole(normalized) |
| 39 | |
| 40 | return cls(content=content, role=role, path=path) |
| 41 | |
| 42 | def validate(self) -> None: |
| 43 | if not self.content: |
| 44 | raise ConfigError("content cannot be empty", f"{self.path}.content") |
| 45 | if self.role not in (MessageRole.USER, MessageRole.ASSISTANT): |
| 46 | raise ConfigError("role must be 'user' or 'assistant'", f"{self.path}.role") |
| 47 | |
| 48 | FIELD_SPECS = { |
| 49 | "content": ConfigFieldSpec( |
| 50 | name="content", |
| 51 | display_name="Literal Content", |
| 52 | type_hint="text", |
| 53 | required=True, |
| 54 | description="Plain text emitted whenever the node executes.", |
| 55 | ), |
| 56 | "role": ConfigFieldSpec( |
| 57 | name="role", |
| 58 | display_name="Message Role", |
| 59 | type_hint="str", |
| 60 | required=False, |
| 61 | default=MessageRole.USER.value, |
| 62 | enum=[MessageRole.USER.value, MessageRole.ASSISTANT.value], |
| 63 | enum_options=[ |
| 64 | EnumOption(value=MessageRole.USER.value, label="user"), |
| 65 | EnumOption(value=MessageRole.ASSISTANT.value, label="assistant"), |
| 66 | ], |
| 67 | description="Select whether the literal message should appear as a user or assistant entry.", |
| 68 | ), |
| 69 | } |
nothing calls this directly
no test coverage detected