update get_node_schema

This commit is contained in:
jingrow 2026-03-12 20:40:20 +08:00
parent 77d7906664
commit 1c39ef2efe
2 changed files with 83 additions and 3 deletions

View File

@ -9,7 +9,7 @@ import { api } from '@/shared/api/common'
export async function loadNodeSchema(nodeType) {
try {
// 使用 Jingrow RPC 调用后端 whitelist 函数
const res = await api.call('jingrow.ai.pagetype.ai_node.ai_node.get_node_schema', {
const res = await api.call('jingrow.ai.utils.jlocal.get_node_schema', {
node_type: nodeType
})

View File

@ -5,11 +5,16 @@
jlocal 相关白名单函数 - 转发到 SaaS
"""
import jingrow
import requests
import json
import logging
import requests
from fastapi import HTTPException
from pathlib import Path
import jingrow
from jingrow.config import Config
from jingrow.utils.auth import get_request_session_cookie
from jingrow.utils.path import get_jingrow_root
logger = logging.getLogger(__name__)
@ -29,3 +34,78 @@ def get_user_pagetype_permissions(**kwargs):
return resp.json().get("message", {})
logger.error(f"[get_user_pagetype_permissions] SaaS error: {resp.status_code} - {resp.text[:200]}")
return {}
@jingrow.whitelist()
def get_all_node_metadata():
"""
获取所有节点的元数据用于流程编排界面
"""
try:
jingrow_root = get_jingrow_root()
nodes_root = jingrow_root / "ai" / "nodes"
if not nodes_root.exists():
return {"success": True, "data": {}}
metadata_map = {}
for node_dir in nodes_root.iterdir():
if not node_dir.is_dir():
continue
json_file = node_dir / f"{node_dir.name}.json"
if not json_file.exists():
continue
try:
with open(json_file, "r", encoding="utf-8") as f:
data = json.load(f)
metadata = data.get("metadata") or {}
node_type = metadata.get("type")
if not node_type:
continue
metadata_map[node_type] = {
"type": node_type,
"label": metadata.get("label") or node_type,
"icon": metadata.get("icon") or "fa-cube",
"color": metadata.get("color") or "#6b7280",
"description": metadata.get("description") or "",
"group": metadata.get("group") or "其他",
"component_type": metadata.get("component_type") or "GenericNode"
}
except Exception:
continue
return {"success": True, "data": metadata_map}
except Exception as e:
return {"success": False, "error": str(e), "data": {}}
@jingrow.whitelist()
def get_node_schema(node_type: str = None):
"""
获取指定节点类型的Schema配置
"""
try:
if not node_type:
return {"success": False, "error": "node_type is required"}
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": False, "error": f"Node type {node_type} not found"}
with open(json_file, "r", encoding="utf-8") as f:
data = json.load(f)
schema = dict(data)
schema.pop("metadata", None)
return {"success": True, "data": schema}
except Exception as e:
return {"success": False, "error": str(e)}