重构前端getNodeSchemaFields函数

This commit is contained in:
jingrow 2025-11-05 02:29:31 +08:00
parent 1338752e7a
commit 9c1b235bdc
2 changed files with 43 additions and 4 deletions

View File

@ -6,12 +6,11 @@ import { get_session_api_headers } from './auth'
// 获取节点Schema字段 // 获取节点Schema字段
export const getNodeSchemaFields = async (nodeType: string): Promise<any[]> => { export const getNodeSchemaFields = async (nodeType: string): Promise<any[]> => {
try { try {
const response = await axios.post( const response = await axios.get(
`/api/action/jingrow.ai.utils.jlocal.get_node_schema_fields`, `/jingrow/node/schema-fields/${encodeURIComponent(nodeType)}`,
{ node_type: nodeType },
{ headers: get_session_api_headers(), withCredentials: true } { headers: get_session_api_headers(), withCredentials: true }
) )
return response.data?.message || [] return response.data?.fields || []
} catch (error) { } catch (error) {
console.error('获取节点Schema字段失败:', error) console.error('获取节点Schema字段失败:', error)
return [] return []

View File

@ -196,6 +196,46 @@ async def get_node_schema(node_type: str):
raise HTTPException(status_code=500, detail=str(e)) raise HTTPException(status_code=500, detail=str(e))
@router.get("/jingrow/node/schema-fields/{node_type}")
async def get_node_schema_fields(node_type: str):
"""
获取指定节点类型的Schema字段列表
返回格式[{"name": "field_name", "label": "显示名称", "type": "字段类型", "description": "描述"}]
"""
try:
jingrow_root = get_jingrow_root()
nodes_root = jingrow_root / "ai" / "nodes"
json_file = nodes_root / node_type / f"{node_type}.json"
if not json_file.exists():
return {"success": True, "fields": []}
with open(json_file, "r", encoding="utf-8") as f:
data = json.load(f)
schema = dict(data)
schema.pop("metadata", None)
# 提取字段列表
fields = []
if schema.get("properties"):
for name, config in schema["properties"].items():
fields.append({
"name": name,
"label": config.get("title", name),
"type": config.get("type", "string"),
"description": config.get("description", "")
})
return {"success": True, "fields": fields}
except FileNotFoundError:
return {"success": True, "fields": []}
except Exception as e:
logger.error(f"获取节点字段失败: {str(e)}")
return {"success": True, "fields": []}
# ==================== 节点市场 API ==================== # ==================== 节点市场 API ====================
@router.get("/jingrow/node-marketplace") @router.get("/jingrow/node-marketplace")