bootstrap.js 863 Bytes
/**
 * bootstrap.js — 代理到 @mas/plugin-bootstrap
 *
 * openclawRoot 统一指向 @mas/openclaw-dist 包
 * 
 * 注意: resolveOpenclawDist 延迟到 bootstrapPlugins() 被真正调用时才执行,
 * 避免在未安装 @mas/openclaw-dist 时导致服务器启动崩溃。
 */

let _bootstrap = null;
let _resolveOpenclawDist = null;
let _openclawRoot = null;

function ensureLoaded() {
  if (_bootstrap) return;
  const pkg = require('@mas/plugin-bootstrap');
  _bootstrap = pkg.bootstrapPlugins;
  _resolveOpenclawDist = pkg.resolveOpenclawDist;
}

async function bootstrapPlugins(config) {
  ensureLoaded();
  if (!_openclawRoot && !config.openclawRoot) {
    _openclawRoot = _resolveOpenclawDist(__dirname);
  }
  return _bootstrap({
    ...config,
    openclawRoot: config.openclawRoot || _openclawRoot,
  });
}

module.exports = { bootstrapPlugins };