/**
 * 通用Schema加载函数
 * @param {string} nodeType - 节点类型
 * @returns {Promise<Object>} Schema配置对象
 */

const LOCAL_NODE_SCHEMAS_NEW = import.meta.glob('../../../../../../apps/jingrow/jingrow/ai/pagetype/local_ai_agent/nodes/*/*.json', { eager: true });

function loadLocalSchemaByConvention(nodeType) {
  try {
    const suffix = `/${nodeType}/${nodeType}.json`;
    for (const path of Object.keys(LOCAL_NODE_SCHEMAS_NEW)) {
      if (path.endsWith(suffix)) {
        const mod = LOCAL_NODE_SCHEMAS_NEW[path];
        const data = mod?.default || mod;
        if (data && data.properties) return data;
      }
    }
  } catch (_) {}
  return null;
}


export async function loadNodeSchema(nodeType) {
  try {
    const localByPath = loadLocalSchemaByConvention(nodeType);
    return localByPath || {};
  } catch (error) {
    throw error;
  }
}

/**
 * 创建针对特定节点类型的Schema加载器
 * @param {string} nodeType - 节点类型
 * @returns {Function} 异步加载函数
 */
export function createSchemaLoader(nodeType) {
  return () => loadNodeSchema(nodeType);
} 