Skip to content

Self-improving AI Employees for everyone

feat(schema): Wave 6 - Pydantic Field hints carry displayOptions rules

trohitg08126b6f3db7
diff --git a/client/src/adapters/nodeSpecToDescription.ts b/client/src/adapters/nodeSpecToDescription.ts
index 21c9907d..cc35a988 100644
--- a/client/src/adapters/nodeSpecToDescription.ts
+++ b/client/src/adapters/nodeSpecToDescription.ts
@@ -57,8 +57,15 @@ interface JsonSchemaProperty {
anyOf?: JsonSchemaProperty[];
items?: JsonSchemaProperty;
additionalProperties?: boolean | JsonSchemaProperty;
- /** Editor hints lifted from Pydantic Field(json_schema_extra=...). */
+ /** Pydantic Field(json_schema_extra={"displayOptions": {...}}) lands
+ * at the property top-level, not under a uiHints wrapper. */
+ displayOptions?: Record<string, unknown>;
+ placeholder?: string;
+ validation?: unknown[];
+ /** Editor hints. Either top-level or nested under uiHints - the
+ * adapter reads both locations so Pydantic authors can use either. */
uiHints?: Record<string, unknown>;
+ [key: string]: unknown;
}
type InodeType = INodeProperties['type'];
@@ -124,34 +131,39 @@ function toInodeProperty(
...(prop.maximum !== undefined ? { maxValue: prop.maximum } : {}),
};
}
- // Lift Pydantic Field(json_schema_extra=...) hints. The shape mirrors
- // INodeProperties so most fields pass straight through; the few that
- // diverge (loadOptionsMethod -> typeOptions) are reshaped here.
- const hints = prop.uiHints;
- if (hints) {
- if (hints.displayOptions) {
- out.displayOptions = hints.displayOptions as INodeProperties['displayOptions'];
- }
- if (hints.placeholder) out.placeholder = hints.placeholder as string;
- if (hints.noDataExpression) out.noDataExpression = hints.noDataExpression as boolean;
- if (hints.validation) out.validation = hints.validation as INodeProperties['validation'];
- // typeOptions lifts: loadOptionsMethod, password, rows, editor, accept, etc.
- const typeOptionsKeys = [
- 'loadOptionsMethod', 'loadOptionsDependsOn',
- 'multipleValues', 'multipleValueButtonText',
- 'numberStepSize',
- 'password', 'rows',
- 'editor', 'editorLanguage',
- 'dynamicOptions', 'dependsOn',
- 'accept',
- ] as const;
- const lifted: Record<string, unknown> = {};
- for (const key of typeOptionsKeys) {
- if (hints[key] !== undefined) lifted[key] = hints[key];
- }
- if (Object.keys(lifted).length > 0) {
- out.typeOptions = { ...out.typeOptions, ...lifted } as INodeProperties['typeOptions'];
- }
+ // Lift Pydantic Field(json_schema_extra=...) hints. Pydantic merges
+ // json_schema_extra into the property top-level, but authors can also
+ // nest under ``uiHints: {...}`` for grouping - we read both locations.
+ const readHint = <T>(key: string): T | undefined =>
+ (prop as any)[key] !== undefined
+ ? ((prop as any)[key] as T)
+ : (prop.uiHints?.[key] as T | undefined);
+
+ const displayOptions = readHint<INodeProperties['displayOptions']>('displayOptions');
+ if (displayOptions) out.displayOptions = displayOptions;
+ const placeholder = readHint<string>('placeholder');
+ if (placeholder) out.placeholder = placeholder;
+ const noDataExpression = readHint<boolean>('noDataExpression');
+ if (noDataExpression) out.noDataExpression = noDataExpression;
+ const validation = readHint<INodeProperties['validation']>('validation');
+ if (validation) out.validation = validation;
+ // typeOptions lifts: loadOptionsMethod, password, rows, editor, accept, etc.
+ const typeOptionsKeys = [
+ 'loadOptionsMethod', 'loadOptionsDependsOn',
+ 'multipleValues', 'multipleValueButtonText',
+ 'numberStepSize',
+ 'password', 'rows',
+ 'editor', 'editorLanguage',
+ 'dynamicOptions', 'dependsOn',
+ 'accept',
+ ] as const;
+ const lifted: Record<string, unknown> = {};
+ for (const key of typeOptionsKeys) {
+ const v = readHint<unknown>(key);
+ if (v !== undefined) lifted[key] = v;
+ }
+ if (Object.keys(lifted).length > 0) {
+ out.typeOptions = { ...out.typeOptions, ...lifted } as INodeProperties['typeOptions'];
}
return out;
}
diff --git a/server/models/nodes.py b/server/models/nodes.py
index a47dfeef..e99c4fdf 100644
--- a/server/models/nodes.py
+++ b/server/models/nodes.py
@@ -241,8 +241,27 @@ class HttpRequestParams(BaseNodeParams):
url: str = ""
method: Literal["GET", "POST", "PUT", "DELETE", "PATCH"] = "GET"
headers: Dict[str, str] = Field(default_factory=dict)
- body: str = ""
+ body: str = Field(
+ default="",
+ json_schema_extra={"displayOptions": {"show": {"method": ["POST", "PUT", "PATCH"]}}},
+ )
timeout: int = Field(default=30, ge=1, le=300)
+ use_proxy: bool = Field(default=False, alias="useProxy")
+ proxy_country: str = Field(
+ default="",
+ alias="proxyCountry",
+ json_schema_extra={"displayOptions": {"show": {"use_proxy": [True]}}},
+ )
+ proxy_provider: str = Field(
+ default="",
+ alias="proxyProvider",
+ json_schema_extra={"displayOptions": {"show": {"use_proxy": [True]}}},
+ )
+ session_type: Literal["rotating", "sticky"] = Field(
+ default="rotating",
+ alias="sessionType",
+ json_schema_extra={"displayOptions": {"show": {"use_proxy": [True]}}},
+ )
class WebhookTriggerParams(BaseNodeParams):
@@ -336,16 +355,47 @@ class TelegramSendParams(BaseNodeParams):
"""Parameters for Telegram send message node."""
type: Literal["telegramSend"]
recipient_type: Literal["self", "chat_id"] = Field(default="self", alias="recipientType")
- chat_id: str = Field(default="", alias="chatId")
+ chat_id: str = Field(
+ default="",
+ alias="chatId",
+ json_schema_extra={"displayOptions": {"show": {"recipient_type": ["chat_id"]}}},
+ )
message_type: Literal["text", "photo", "document", "location", "contact"] = Field(default="text", alias="messageType")
- text: str = ""
- media_url: str = Field(default="", alias="mediaUrl")
- caption: str = ""
- latitude: Optional[float] = None
- longitude: Optional[float] = None
- phone: str = ""
- first_name: str = Field(default="", alias="firstName")
- last_name: str = Field(default="", alias="lastName")
+ text: str = Field(
+ default="",
+ json_schema_extra={"displayOptions": {"show": {"message_type": ["text"]}}},
+ )
+ media_url: str = Field(
+ default="",
+ alias="mediaUrl",
+ json_schema_extra={"displayOptions": {"show": {"message_type": ["photo", "document"]}}},
+ )
+ caption: str = Field(
+ default="",
+ json_schema_extra={"displayOptions": {"show": {"message_type": ["photo", "document"]}}},
+ )
+ latitude: Optional[float] = Field(
+ default=None,
+ json_schema_extra={"displayOptions": {"show": {"message_type": ["location"]}}},
+ )
+ longitude: Optional[float] = Field(
+ default=None,
+ json_schema_extra={"displayOptions": {"show": {"message_type": ["location"]}}},
+ )
+ phone: str = Field(
+ default="",
+ json_schema_extra={"displayOptions": {"show": {"message_type": ["contact"]}}},
+ )
+ first_name: str = Field(
+ default="",
+ alias="firstName",
+ json_schema_extra={"displayOptions": {"show": {"message_type": ["contact"]}}},
+ )
+ last_name: str = Field(
+ default="",
+ alias="lastName",
+ json_schema_extra={"displayOptions": {"show": {"message_type": ["contact"]}}},
+ )
parse_mode: Literal["Auto", "HTML", "Markdown", "MarkdownV2", "None"] = Field(default="Auto", alias="parseMode")
silent: bool = False
reply_to_message_id: Optional[int] = Field(default=None, alias="replyToMessageId")
@@ -355,12 +405,41 @@ class TwitterSendParams(BaseNodeParams):
"""Parameters for Twitter send/action node."""
type: Literal["twitterSend"]
action: Literal["tweet", "reply", "retweet", "like", "unlike", "delete"] = "tweet"
- text: str = ""
- tweet_id: str = Field(default="", alias="tweetId")
- media_urls: List[str] = Field(default_factory=list, alias="mediaUrls")
- include_poll: bool = Field(default=False, alias="includePoll")
- poll_options: List[str] = Field(default_factory=list, alias="pollOptions")
- poll_duration_minutes: int = Field(default=1440, alias="pollDurationMinutes", ge=5, le=10080)
+ text: str = Field(
+ default="",
+ json_schema_extra={"displayOptions": {"show": {"action": ["tweet", "reply", "quote"]}}},
+ )
+ tweet_id: str = Field(
+ default="",
+ alias="tweetId",
+ json_schema_extra={"displayOptions": {"show": {"action": ["reply", "retweet", "quote", "like", "unlike", "delete"]}}},
+ )
+ include_media: bool = Field(
+ default=False,
+ alias="includeMedia",
+ json_schema_extra={"displayOptions": {"show": {"action": ["tweet", "reply", "quote"]}}},
+ )
+ media_urls: List[str] = Field(
+ default_factory=list,
+ alias="mediaUrls",
+ json_schema_extra={"displayOptions": {"show": {"action": ["tweet", "reply", "quote"], "include_media": [True]}}},
+ )
+ include_poll: bool = Field(
+ default=False,
+ alias="includePoll",
+ json_schema_extra={"displayOptions": {"show": {"action": ["tweet"]}}},
+ )
+ poll_options: List[str] = Field(
+ default_factory=list,
+ alias="pollOptions",
+ json_schema_extra={"displayOptions": {"show": {"action": ["tweet"], "include_poll": [True]}}},
+ )
+ poll_duration_minutes: int = Field(
+ default=1440,
+ alias="pollDurationMinutes",
+ ge=5, le=10080,
+ json_schema_extra={"displayOptions": {"show": {"action": ["tweet"], "include_poll": [True]}}},
+ )
class TwitterSearchParams(BaseNodeParams):
@@ -379,9 +458,21 @@ class TwitterUserParams(BaseNodeParams):
"""Parameters for Twitter user lookup node."""
type: Literal["twitterUser"]
operation: Literal["me", "by_username", "by_id", "followers", "following"] = "me"
- username: str = ""
- user_id: str = Field(default="", alias="userId")
- max_results: int = Field(default=100, alias="maxResults", ge=1, le=1000)
+ username: str = Field(
+ default="",
+ json_schema_extra={"displayOptions": {"show": {"operation": ["by_username"]}}},
+ )
+ user_id: str = Field(
+ default="",
+ alias="userId",
+ json_schema_extra={"displayOptions": {"show": {"operation": ["by_id", "followers", "following"]}}},
+ )
+ max_results: int = Field(
+ default=100,
+ alias="maxResults",
+ ge=1, le=1000,
+ json_schema_extra={"displayOptions": {"show": {"operation": ["followers", "following"]}}},
+ )
class SocialReceiveParams(BaseNodeParams):
diff --git a/server/tests/test_node_spec.py b/server/tests/test_node_spec.py
index 67f1ac78..5657d8f1 100644
--- a/server/tests/test_node_spec.py
+++ b/server/tests/test_node_spec.py
@@ -416,3 +416,51 @@ class TestPhase5NodeGroups:
from services.node_spec import list_node_groups
for group, types in list_node_groups().items():
assert types == sorted(types), f"Group {group!r} not sorted: {types}"
+
+
+class TestDisplayOptionsEnrichment:
+ """Wave 6 Phase 6 enrichment: Pydantic Field(json_schema_extra=...)
+ hints are lifted into the adapter-visible schema so the frontend
+ panel renders conditional visibility correctly without the legacy
+ nodeDefinitions/* displayOptions declarations."""
+
+ def test_twitter_send_text_shown_for_tweet_actions(self):
+ # text field should carry displayOptions restricting it to
+ # tweet/reply/quote actions.
+ spec = get_node_spec("twitterSend")
+ text = spec["inputs"]["properties"]["text"]
+ rule = text.get("displayOptions", {}).get("show", {})
+ assert rule.get("action") == ["tweet", "reply", "quote"]
+
+ def test_twitter_send_tweet_id_shown_for_edit_actions(self):
+ spec = get_node_spec("twitterSend")
+ prop = spec["inputs"]["properties"]["tweetId"]
+ rule = prop.get("displayOptions", {}).get("show", {})
+ assert "reply" in rule.get("action", [])
+ assert "delete" in rule.get("action", [])
+
+ def test_twitter_user_username_shown_for_by_username(self):
+ spec = get_node_spec("twitterUser")
+ username = spec["inputs"]["properties"]["username"]
+ assert username["displayOptions"]["show"]["operation"] == ["by_username"]
+
+ def test_telegram_send_media_shown_for_photo_document(self):
+ spec = get_node_spec("telegramSend")
+ media_url = spec["inputs"]["properties"]["mediaUrl"]
+ assert media_url["displayOptions"]["show"]["message_type"] == ["photo", "document"]
+
+ def test_telegram_send_text_shown_for_text_type(self):
+ spec = get_node_spec("telegramSend")
+ text = spec["inputs"]["properties"]["text"]
+ assert text["displayOptions"]["show"]["message_type"] == ["text"]
+
+ def test_http_request_body_shown_for_post_put_patch(self):
+ spec = get_node_spec("httpRequest")
+ body = spec["inputs"]["properties"]["body"]
+ assert body["displayOptions"]["show"]["method"] == ["POST", "PUT", "PATCH"]
+
+ def test_http_request_proxy_fields_gated_on_use_proxy(self):
+ spec = get_node_spec("httpRequest")
+ for field in ["proxyCountry", "proxyProvider", "sessionType"]:
+ prop = spec["inputs"]["properties"][field]
+ assert prop["displayOptions"]["show"]["use_proxy"] == [True]