@chatbi-v/core 2.1.4 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1209,11 +1209,18 @@ declare class PluginManager {
1209
1209
  * @param notify - 是否在注册完成后触发状态变更通知
1210
1210
  */
1211
1211
  register(plugin: Plugin, notify?: boolean): void;
1212
+ /**
1213
+ * 手动挂载指定插件(支持按需加载)
1214
+ * @description 如果插件依赖尚未挂载,会递归挂载所有依赖
1215
+ * @param pluginId 插件 ID
1216
+ */
1217
+ mountPlugin(pluginId: string): Promise<void>;
1212
1218
  /**
1213
1219
  * 初始化所有插件
1214
1220
  * @param sharedContext 共享上下文
1221
+ * @param autoMount 是否自动挂载所有插件 (默认为 false,启用按需加载模式)
1215
1222
  */
1216
- initPlugins(sharedContext?: Record<string, any>): Promise<void>;
1223
+ initPlugins(sharedContext?: Record<string, any>, autoMount?: boolean): Promise<void>;
1217
1224
  /**
1218
1225
  * 获取排序后的插件 ID 列表 (处理依赖)
1219
1226
  */
package/dist/index.d.ts CHANGED
@@ -1209,11 +1209,18 @@ declare class PluginManager {
1209
1209
  * @param notify - 是否在注册完成后触发状态变更通知
1210
1210
  */
1211
1211
  register(plugin: Plugin, notify?: boolean): void;
1212
+ /**
1213
+ * 手动挂载指定插件(支持按需加载)
1214
+ * @description 如果插件依赖尚未挂载,会递归挂载所有依赖
1215
+ * @param pluginId 插件 ID
1216
+ */
1217
+ mountPlugin(pluginId: string): Promise<void>;
1212
1218
  /**
1213
1219
  * 初始化所有插件
1214
1220
  * @param sharedContext 共享上下文
1221
+ * @param autoMount 是否自动挂载所有插件 (默认为 false,启用按需加载模式)
1215
1222
  */
1216
- initPlugins(sharedContext?: Record<string, any>): Promise<void>;
1223
+ initPlugins(sharedContext?: Record<string, any>, autoMount?: boolean): Promise<void>;
1217
1224
  /**
1218
1225
  * 获取排序后的插件 ID 列表 (处理依赖)
1219
1226
  */
package/dist/index.js CHANGED
@@ -1781,11 +1781,53 @@ var PluginManager = class {
1781
1781
  this.notify();
1782
1782
  }
1783
1783
  }
1784
+ /**
1785
+ * 手动挂载指定插件(支持按需加载)
1786
+ * @description 如果插件依赖尚未挂载,会递归挂载所有依赖
1787
+ * @param pluginId 插件 ID
1788
+ */
1789
+ async mountPlugin(pluginId) {
1790
+ const runtime = this.runtimes.get(pluginId);
1791
+ if (!runtime) {
1792
+ const msg = `\u5C1D\u8BD5\u6302\u8F7D\u4E0D\u5B58\u5728\u6216\u672A\u521D\u59CB\u5316\u7684\u63D2\u4EF6: ${pluginId}`;
1793
+ logger6.warn(msg);
1794
+ throw new Error(msg);
1795
+ }
1796
+ if (runtime.status === "mounted") return;
1797
+ const plugin = this.plugins.get(pluginId);
1798
+ if (plugin?.metadata.dependencies) {
1799
+ for (const depId of plugin.metadata.dependencies) {
1800
+ if (!this.runtimes.has(depId)) {
1801
+ logger6.error(`\u63D2\u4EF6 ${pluginId} \u4F9D\u8D56\u7F3A\u5931: ${depId}`);
1802
+ throw new Error(`Dependency ${depId} missing for ${pluginId}`);
1803
+ }
1804
+ await this.mountPlugin(depId);
1805
+ }
1806
+ }
1807
+ if (runtime.status === "initial") {
1808
+ try {
1809
+ await runtime.load();
1810
+ } catch (e) {
1811
+ logger6.error(`\u63D2\u4EF6 ${pluginId} load \u5931\u8D25:`, e);
1812
+ throw e;
1813
+ }
1814
+ }
1815
+ if (runtime.status === "loaded") {
1816
+ try {
1817
+ await runtime.mount();
1818
+ this.notify();
1819
+ } catch (e) {
1820
+ logger6.error(`\u63D2\u4EF6 ${pluginId} \u6302\u8F7D\u5931\u8D25:`, e);
1821
+ throw e;
1822
+ }
1823
+ }
1824
+ }
1784
1825
  /**
1785
1826
  * 初始化所有插件
1786
1827
  * @param sharedContext 共享上下文
1828
+ * @param autoMount 是否自动挂载所有插件 (默认为 false,启用按需加载模式)
1787
1829
  */
1788
- async initPlugins(sharedContext = {}) {
1830
+ async initPlugins(sharedContext = {}, autoMount = false) {
1789
1831
  if (this.isInitializing) {
1790
1832
  logger6.warn("PluginManager is already initializing, skipping...");
1791
1833
  return;
@@ -1837,6 +1879,9 @@ var PluginManager = class {
1837
1879
  }
1838
1880
  for (const id of sortedPluginIds) {
1839
1881
  if (!idsToLoad.has(id)) continue;
1882
+ const plugin = this.plugins.get(id);
1883
+ const shouldMount = autoMount || plugin && ["system", "theme"].includes(plugin.metadata.type);
1884
+ if (!shouldMount) continue;
1840
1885
  const runtime = this.runtimes.get(id);
1841
1886
  if (runtime && (runtime.status === "loaded" || runtime.status === "initial")) {
1842
1887
  try {
@@ -2123,6 +2168,17 @@ var SlotSkeletons = ({ slot, expanded }) => {
2123
2168
 
2124
2169
  // src/components/PluginSlot.tsx
2125
2170
  var import_jsx_runtime4 = require("react/jsx-runtime");
2171
+ var ExtensionLoader = ({ pluginId, component: Component2, props }) => {
2172
+ const status = pluginManager.getPluginRuntimeStatus(pluginId);
2173
+ if (status !== "mounted") {
2174
+ const error = pluginManager.getPluginError(pluginId);
2175
+ if (error) {
2176
+ throw error;
2177
+ }
2178
+ throw pluginManager.mountPlugin(pluginId);
2179
+ }
2180
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Component2, { ...props });
2181
+ };
2126
2182
  var PluginSlot = ({
2127
2183
  slot,
2128
2184
  props = {},
@@ -2135,7 +2191,9 @@ var PluginSlot = ({
2135
2191
  const [, forceUpdate] = (0, import_react4.useState)({});
2136
2192
  (0, import_react4.useEffect)(() => {
2137
2193
  const unsubscribe = pluginManager.subscribe(() => {
2138
- forceUpdate({});
2194
+ (0, import_react4.startTransition)(() => {
2195
+ forceUpdate({});
2196
+ });
2139
2197
  }, slot);
2140
2198
  return unsubscribe;
2141
2199
  }, [slot]);
@@ -2156,7 +2214,14 @@ var PluginSlot = ({
2156
2214
  return {
2157
2215
  key,
2158
2216
  extension: ext,
2159
- component: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PluginErrorBoundary, { pluginId: ext._pluginId, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react4.Suspense, { fallback: skeleton || /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotSkeletons, { slot }), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Component2, { ...mergedProps }) }) }, key)
2217
+ component: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PluginErrorBoundary, { pluginId: ext._pluginId, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react4.Suspense, { fallback: skeleton || /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotSkeletons, { slot }), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2218
+ ExtensionLoader,
2219
+ {
2220
+ pluginId: ext._pluginId || "",
2221
+ component: Component2,
2222
+ props: mergedProps
2223
+ }
2224
+ ) }) }, key)
2160
2225
  };
2161
2226
  });
2162
2227
  }, [extensions, mergedProps]);
@@ -2779,9 +2844,9 @@ var usePluginLoader = (options) => {
2779
2844
  configManager2.set("system", options.systemConfig);
2780
2845
  }
2781
2846
  await pluginManager.loadPlugins(pluginConfigs, finalRegistry, false);
2782
- await pluginManager.initPlugins(sharedContext);
2847
+ await pluginManager.initPlugins(sharedContext, false);
2783
2848
  setPluginsLoaded(true);
2784
- logger10.info("Plugins loaded successfully");
2849
+ logger10.info("Plugins loaded successfully (Lazy Mode)");
2785
2850
  } catch (error) {
2786
2851
  logger10.error("Failed to load plugins:", error);
2787
2852
  } finally {
@@ -2789,14 +2854,9 @@ var usePluginLoader = (options) => {
2789
2854
  }
2790
2855
  };
2791
2856
  load();
2792
- return () => {
2793
- unsubscribe();
2794
- };
2857
+ return unsubscribe;
2795
2858
  }, []);
2796
- return {
2797
- pluginsLoaded,
2798
- pluginVersion
2799
- };
2859
+ return { pluginsLoaded, pluginVersion };
2800
2860
  };
2801
2861
  // Annotate the CommonJS export names for ESM import in node:
2802
2862
  0 && (module.exports = {