@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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +58 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1240,6 +1240,8 @@ var PluginManager = class {
|
|
|
1240
1240
|
sharedContext = null;
|
|
1241
1241
|
/** 收集到的插件工具函数集合 */
|
|
1242
1242
|
utils = {};
|
|
1243
|
+
/** 是否正在初始化插件中,防止重入导致多次加载 */
|
|
1244
|
+
isInitializing = false;
|
|
1243
1245
|
/**
|
|
1244
1246
|
* 构造函数
|
|
1245
1247
|
* @param storage - 底层存储适配器
|
|
@@ -1642,58 +1644,68 @@ var PluginManager = class {
|
|
|
1642
1644
|
* @param sharedContext 共享上下文
|
|
1643
1645
|
*/
|
|
1644
1646
|
async initPlugins(sharedContext = {}) {
|
|
1645
|
-
this.
|
|
1646
|
-
...
|
|
1647
|
-
|
|
1648
|
-
};
|
|
1649
|
-
this.plugins.forEach((plugin) => {
|
|
1650
|
-
if (!this.isPluginEnabled(plugin.id)) return;
|
|
1651
|
-
if (!this.runtimes.has(plugin.id)) {
|
|
1652
|
-
const runtime = new PluginRuntime(plugin, this.sharedContext, this.storageManager);
|
|
1653
|
-
this.runtimes.set(plugin.id, runtime);
|
|
1654
|
-
}
|
|
1655
|
-
});
|
|
1656
|
-
const sortedPluginIds = this.getSortedPluginIds();
|
|
1657
|
-
const missingDeps = /* @__PURE__ */ new Map();
|
|
1658
|
-
const idsToLoad = new Set(sortedPluginIds);
|
|
1659
|
-
for (const id of sortedPluginIds) {
|
|
1660
|
-
const plugin = this.plugins.get(id);
|
|
1661
|
-
if (plugin?.metadata.dependencies) {
|
|
1662
|
-
const missing = plugin.metadata.dependencies.filter((depId) => !this.runtimes.has(depId));
|
|
1663
|
-
if (missing.length > 0) {
|
|
1664
|
-
missingDeps.set(id, missing);
|
|
1665
|
-
idsToLoad.delete(id);
|
|
1666
|
-
this.runtimes.delete(id);
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1647
|
+
if (this.isInitializing) {
|
|
1648
|
+
logger6.warn("PluginManager is already initializing, skipping...");
|
|
1649
|
+
return;
|
|
1669
1650
|
}
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1651
|
+
this.isInitializing = true;
|
|
1652
|
+
try {
|
|
1653
|
+
this.sharedContext = {
|
|
1654
|
+
...sharedContext,
|
|
1655
|
+
events: this.eventBus
|
|
1656
|
+
};
|
|
1657
|
+
this.plugins.forEach((plugin) => {
|
|
1658
|
+
if (!this.isPluginEnabled(plugin.id)) return;
|
|
1659
|
+
if (!this.runtimes.has(plugin.id)) {
|
|
1660
|
+
const runtime = new PluginRuntime(plugin, this.sharedContext, this.storageManager);
|
|
1661
|
+
this.runtimes.set(plugin.id, runtime);
|
|
1662
|
+
}
|
|
1673
1663
|
});
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
const
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1664
|
+
const sortedPluginIds = this.getSortedPluginIds();
|
|
1665
|
+
const missingDeps = /* @__PURE__ */ new Map();
|
|
1666
|
+
const idsToLoad = new Set(sortedPluginIds);
|
|
1667
|
+
for (const id of sortedPluginIds) {
|
|
1668
|
+
const plugin = this.plugins.get(id);
|
|
1669
|
+
if (plugin?.metadata.dependencies) {
|
|
1670
|
+
const missing = plugin.metadata.dependencies.filter((depId) => !this.runtimes.has(depId));
|
|
1671
|
+
if (missing.length > 0) {
|
|
1672
|
+
missingDeps.set(id, missing);
|
|
1673
|
+
idsToLoad.delete(id);
|
|
1674
|
+
this.runtimes.delete(id);
|
|
1675
|
+
}
|
|
1685
1676
|
}
|
|
1686
1677
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1678
|
+
if (missingDeps.size > 0) {
|
|
1679
|
+
missingDeps.forEach((deps, id) => {
|
|
1680
|
+
logger6.error(`\u63D2\u4EF6 ${id} \u65E0\u6CD5\u52A0\u8F7D\uFF0C\u7F3A\u5931\u4F9D\u8D56: ${deps.join(", ")}`);
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
for (const id of sortedPluginIds) {
|
|
1684
|
+
if (!idsToLoad.has(id)) continue;
|
|
1685
|
+
const runtime = this.runtimes.get(id);
|
|
1686
|
+
if (runtime && runtime.status === "initial") {
|
|
1687
|
+
try {
|
|
1688
|
+
logger6.info(`[PluginManager] invoking onLoad for ${id}`);
|
|
1689
|
+
await runtime.load();
|
|
1690
|
+
logger6.info(`[PluginManager] onLoad completed for ${id}`);
|
|
1691
|
+
} catch (e) {
|
|
1692
|
+
logger6.error(`\u63D2\u4EF6 ${id} \u52A0\u8F7D\u5931\u8D25:`, e);
|
|
1693
|
+
}
|
|
1695
1694
|
}
|
|
1696
1695
|
}
|
|
1696
|
+
for (const id of sortedPluginIds) {
|
|
1697
|
+
if (!idsToLoad.has(id)) continue;
|
|
1698
|
+
const runtime = this.runtimes.get(id);
|
|
1699
|
+
if (runtime && (runtime.status === "loaded" || runtime.status === "initial")) {
|
|
1700
|
+
try {
|
|
1701
|
+
await runtime.mount();
|
|
1702
|
+
} catch (e) {
|
|
1703
|
+
logger6.error(`\u63D2\u4EF6 ${id} \u6302\u8F7D\u5931\u8D25:`, e);
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
} finally {
|
|
1708
|
+
this.isInitializing = false;
|
|
1697
1709
|
}
|
|
1698
1710
|
}
|
|
1699
1711
|
/**
|