Archived
refactored workflow parameters to include a component property for the frontend, updated docs
This commit is contained in:
1 parent
59ff3365e9
commit
37e901bc30
4 files changed
+236
-52
No files matched your search
+40
-13
@@ -26,6 +26,7 @@ PRESERVE_PROPERTIES = {
|
||||
# Properties to update from Pydantic model
|
||||
UPDATE_PROPERTIES = {
|
||||
"type",
|
||||
"component", # NEW: explicit UI component
|
||||
"default",
|
||||
"required",
|
||||
"min",
|
||||
@@ -140,7 +141,7 @@ def get_model_params_schema(field_type: type) -> List[Dict[str, Any]]:
|
||||
elif field_annotation is bool:
|
||||
param["type"] = "bool"
|
||||
elif field_annotation is str:
|
||||
param["type"] = "text"
|
||||
param["type"] = "str"
|
||||
|
||||
# Get default
|
||||
if field_info.default is not None:
|
||||
@@ -176,7 +177,15 @@ def extract_field_schema(
|
||||
field_info: FieldInfo,
|
||||
field_type: type
|
||||
) -> Dict[str, Any]:
|
||||
"""Extract schema from a Pydantic field."""
|
||||
"""Extract schema from a Pydantic field.
|
||||
|
||||
Type inference rules:
|
||||
1. If has options_source -> type: enum (selection from list)
|
||||
2. If has params (model_with_params) -> type: object
|
||||
3. Otherwise infer from Python type (int, float, str, bool)
|
||||
|
||||
Component is optional - frontend falls back to generic rendering based on type.
|
||||
"""
|
||||
schema: Dict[str, Any] = {
|
||||
"name": field_name,
|
||||
"label": camel_to_title(field_name),
|
||||
@@ -191,8 +200,11 @@ def extract_field_schema(
|
||||
else:
|
||||
extra = dict(field_info.json_schema_extra)
|
||||
|
||||
# Get ui_type from extra, or infer from Python type
|
||||
ui_type = extra.pop("ui_type", None)
|
||||
# Extract component (NEW: explicit UI component key)
|
||||
component = extra.pop("component", None)
|
||||
|
||||
# Extract options_source early - needed for type inference
|
||||
options_source = extra.get("options_source")
|
||||
|
||||
# Handle List types
|
||||
origin = get_origin(field_type)
|
||||
@@ -203,15 +215,26 @@ def extract_field_schema(
|
||||
if args:
|
||||
inner_type = args[0]
|
||||
|
||||
# Check if it's a model with parameters
|
||||
# Infer type based on priority:
|
||||
# 1. model_with_params (has params)
|
||||
# 2. enum (has options_source)
|
||||
# 3. primitive type (int, float, str, bool)
|
||||
|
||||
if is_model_with_params(field_type):
|
||||
schema["type"] = "model_with_params"
|
||||
schema["options_source"] = infer_options_source(field_name, field_type)
|
||||
# Complex type with embedded parameters
|
||||
schema["type"] = "object"
|
||||
inferred_source = infer_options_source(field_name, field_type)
|
||||
if not options_source:
|
||||
schema["options_source"] = inferred_source
|
||||
# For model_with_params, use options_source as component if not specified
|
||||
if not component:
|
||||
component = inferred_source or field_name
|
||||
schema["params"] = get_model_params_schema(field_type)
|
||||
elif ui_type:
|
||||
schema["type"] = ui_type
|
||||
elif options_source:
|
||||
# Selection from a list of options
|
||||
schema["type"] = "enum"
|
||||
else:
|
||||
# Infer type from Python type
|
||||
# Primitive type - infer from Python type
|
||||
if inner_type is bool:
|
||||
schema["type"] = "bool"
|
||||
elif inner_type is int:
|
||||
@@ -219,11 +242,15 @@ def extract_field_schema(
|
||||
elif inner_type is float:
|
||||
schema["type"] = "float"
|
||||
elif inner_type is str:
|
||||
schema["type"] = "text"
|
||||
schema["type"] = "str"
|
||||
else:
|
||||
schema["type"] = "text" # Default fallback
|
||||
schema["type"] = "str" # Default fallback
|
||||
|
||||
# Copy extra properties (category, multiline, rows, options_source, etc.)
|
||||
# Add component if specified (optional UI hint)
|
||||
if component:
|
||||
schema["component"] = component
|
||||
|
||||
# Copy remaining extra properties (category, multiline, rows, options_source, etc.)
|
||||
for key, value in extra.items():
|
||||
schema[key] = value
|
||||
|
||||
|
||||
Reference in new issue
Block a user