@chatbi-v/core 2.1.2 → 2.1.3

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
@@ -1073,6 +1073,8 @@ declare class PluginManager {
1073
1073
  private sharedContext;
1074
1074
  /** 收集到的插件工具函数集合 */
1075
1075
  private utils;
1076
+ /** 是否正在初始化插件中,防止重入导致多次加载 */
1077
+ private isInitializing;
1076
1078
  /**
1077
1079
  * 构造函数
1078
1080
  * @param storage - 底层存储适配器
package/dist/index.d.ts CHANGED
@@ -1073,6 +1073,8 @@ declare class PluginManager {
1073
1073
  private sharedContext;
1074
1074
  /** 收集到的插件工具函数集合 */
1075
1075
  private utils;
1076
+ /** 是否正在初始化插件中,防止重入导致多次加载 */
1077
+ private isInitializing;
1076
1078
  /**
1077
1079
  * 构造函数
1078
1080
  * @param storage - 底层存储适配器
package/dist/index.js CHANGED
@@ -1382,6 +1382,8 @@ var PluginManager = class {
1382
1382
  sharedContext = null;
1383
1383
  /** 收集到的插件工具函数集合 */
1384
1384
  utils = {};
1385
+ /** 是否正在初始化插件中,防止重入导致多次加载 */
1386
+ isInitializing = false;
1385
1387
  /**
1386
1388
  * 构造函数
1387
1389
  * @param storage - 底层存储适配器
@@ -1784,58 +1786,68 @@ var PluginManager = class {
1784
1786
  * @param sharedContext 共享上下文
1785
1787
  */
1786
1788
  async initPlugins(sharedContext = {}) {
1787
- this.sharedContext = {
1788
- ...sharedContext,
1789
- events: this.eventBus
1790
- };
1791
- this.plugins.forEach((plugin) => {
1792
- if (!this.isPluginEnabled(plugin.id)) return;
1793
- if (!this.runtimes.has(plugin.id)) {
1794
- const runtime = new PluginRuntime(plugin, this.sharedContext, this.storageManager);
1795
- this.runtimes.set(plugin.id, runtime);
1796
- }
1797
- });
1798
- const sortedPluginIds = this.getSortedPluginIds();
1799
- const missingDeps = /* @__PURE__ */ new Map();
1800
- const idsToLoad = new Set(sortedPluginIds);
1801
- for (const id of sortedPluginIds) {
1802
- const plugin = this.plugins.get(id);
1803
- if (plugin?.metadata.dependencies) {
1804
- const missing = plugin.metadata.dependencies.filter((depId) => !this.runtimes.has(depId));
1805
- if (missing.length > 0) {
1806
- missingDeps.set(id, missing);
1807
- idsToLoad.delete(id);
1808
- this.runtimes.delete(id);
1809
- }
1810
- }
1789
+ if (this.isInitializing) {
1790
+ logger6.warn("PluginManager is already initializing, skipping...");
1791
+ return;
1811
1792
  }
1812
- if (missingDeps.size > 0) {
1813
- missingDeps.forEach((deps, id) => {
1814
- logger6.error(`\u63D2\u4EF6 ${id} \u65E0\u6CD5\u52A0\u8F7D\uFF0C\u7F3A\u5931\u4F9D\u8D56: ${deps.join(", ")}`);
1793
+ this.isInitializing = true;
1794
+ try {
1795
+ this.sharedContext = {
1796
+ ...sharedContext,
1797
+ events: this.eventBus
1798
+ };
1799
+ this.plugins.forEach((plugin) => {
1800
+ if (!this.isPluginEnabled(plugin.id)) return;
1801
+ if (!this.runtimes.has(plugin.id)) {
1802
+ const runtime = new PluginRuntime(plugin, this.sharedContext, this.storageManager);
1803
+ this.runtimes.set(plugin.id, runtime);
1804
+ }
1815
1805
  });
1816
- }
1817
- for (const id of sortedPluginIds) {
1818
- if (!idsToLoad.has(id)) continue;
1819
- const runtime = this.runtimes.get(id);
1820
- if (runtime) {
1821
- try {
1822
- logger6.info(`[PluginManager] invoking onLoad for ${id}`);
1823
- await runtime.load();
1824
- logger6.info(`[PluginManager] onLoad completed for ${id}`);
1825
- } catch (e) {
1826
- logger6.error(`\u63D2\u4EF6 ${id} \u52A0\u8F7D\u5931\u8D25:`, e);
1806
+ const sortedPluginIds = this.getSortedPluginIds();
1807
+ const missingDeps = /* @__PURE__ */ new Map();
1808
+ const idsToLoad = new Set(sortedPluginIds);
1809
+ for (const id of sortedPluginIds) {
1810
+ const plugin = this.plugins.get(id);
1811
+ if (plugin?.metadata.dependencies) {
1812
+ const missing = plugin.metadata.dependencies.filter((depId) => !this.runtimes.has(depId));
1813
+ if (missing.length > 0) {
1814
+ missingDeps.set(id, missing);
1815
+ idsToLoad.delete(id);
1816
+ this.runtimes.delete(id);
1817
+ }
1827
1818
  }
1828
1819
  }
1829
- }
1830
- for (const id of sortedPluginIds) {
1831
- const runtime = this.runtimes.get(id);
1832
- if (runtime) {
1833
- try {
1834
- await runtime.mount();
1835
- } catch (e) {
1836
- logger6.error(`\u63D2\u4EF6 ${id} \u6302\u8F7D\u5931\u8D25:`, e);
1820
+ if (missingDeps.size > 0) {
1821
+ missingDeps.forEach((deps, id) => {
1822
+ logger6.error(`\u63D2\u4EF6 ${id} \u65E0\u6CD5\u52A0\u8F7D\uFF0C\u7F3A\u5931\u4F9D\u8D56: ${deps.join(", ")}`);
1823
+ });
1824
+ }
1825
+ for (const id of sortedPluginIds) {
1826
+ if (!idsToLoad.has(id)) continue;
1827
+ const runtime = this.runtimes.get(id);
1828
+ if (runtime && runtime.status === "initial") {
1829
+ try {
1830
+ logger6.info(`[PluginManager] invoking onLoad for ${id}`);
1831
+ await runtime.load();
1832
+ logger6.info(`[PluginManager] onLoad completed for ${id}`);
1833
+ } catch (e) {
1834
+ logger6.error(`\u63D2\u4EF6 ${id} \u52A0\u8F7D\u5931\u8D25:`, e);
1835
+ }
1837
1836
  }
1838
1837
  }
1838
+ for (const id of sortedPluginIds) {
1839
+ if (!idsToLoad.has(id)) continue;
1840
+ const runtime = this.runtimes.get(id);
1841
+ if (runtime && (runtime.status === "loaded" || runtime.status === "initial")) {
1842
+ try {
1843
+ await runtime.mount();
1844
+ } catch (e) {
1845
+ logger6.error(`\u63D2\u4EF6 ${id} \u6302\u8F7D\u5931\u8D25:`, e);
1846
+ }
1847
+ }
1848
+ }
1849
+ } finally {
1850
+ this.isInitializing = false;
1839
1851
  }
1840
1852
  }
1841
1853
  /**