feat:节点合并
This commit is contained in:
@@ -39,7 +39,8 @@ def panel_setters(groups: list[FieldGroup]) -> list[dict]:
|
||||
props = {}
|
||||
if field.options:
|
||||
props["options"] = [
|
||||
{"label": option.label, "value": option.value} for option in field.options
|
||||
{"label": option.label, "value": option.value}
|
||||
for option in field.options
|
||||
]
|
||||
setter = {
|
||||
"type": PANEL_CONTROLS[field.value_type],
|
||||
@@ -64,7 +65,9 @@ def frontend_catalog(catalog: ComponentCatalog) -> dict:
|
||||
# ---- 字段查询:MCP 工具、动作提示词和动作校验共用同一套逻辑 ----
|
||||
|
||||
|
||||
def find_material(catalog: ComponentCatalog, component_type: str) -> ComponentDefinition:
|
||||
def find_material(
|
||||
catalog: ComponentCatalog, component_type: str
|
||||
) -> ComponentDefinition:
|
||||
"""按节点 type 找物料;找不到或对应多个物料时报错,不猜测"""
|
||||
matches = [item for item in catalog.components if item.type == component_type]
|
||||
if len(matches) != 1:
|
||||
@@ -74,6 +77,27 @@ def find_material(catalog: ComponentCatalog, component_type: str) -> ComponentDe
|
||||
return matches[0]
|
||||
|
||||
|
||||
def material_payload(component: ComponentDefinition) -> dict:
|
||||
"""给模型看的物料配置:完整默认 schema 及使用说明,字段定义由字段查询按需提供"""
|
||||
return component.model_dump(mode="json", by_alias=True, exclude={"field_groups"})
|
||||
|
||||
|
||||
def get_materials(catalog: ComponentCatalog, component_types: list[str]) -> dict:
|
||||
"""指定类型的物料默认配置,同一类型的多个预设全部返回"""
|
||||
known = {item.type for item in catalog.components}
|
||||
if unknown := [item for item in component_types if item not in known]:
|
||||
raise ValueError(
|
||||
f"没有对应的物料类型 {unknown},可用类型:{'、'.join(sorted(known))}"
|
||||
)
|
||||
types = set(component_types)
|
||||
return {
|
||||
"catalog_version": catalog.version,
|
||||
"materials": [
|
||||
material_payload(item) for item in catalog.components if item.type in types
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def describe_field(
|
||||
component: ComponentDefinition, group: FieldGroup, field: MaterialField
|
||||
) -> dict:
|
||||
@@ -174,7 +198,9 @@ def search_fields(
|
||||
}
|
||||
|
||||
|
||||
def check_update_field(catalog: ComponentCatalog | None, node_type: str, action) -> None:
|
||||
def check_update_field(
|
||||
catalog: ComponentCatalog | None, node_type: str, action
|
||||
) -> None:
|
||||
"""update 只能修改字段定义中的可编辑字段,值须符合字段类型和取值约束
|
||||
|
||||
不合法时抛 ValueError,路径不存在时附上可能对应的字段供修正参考
|
||||
|
||||
Reference in New Issue
Block a user