@chatbi-v/core 2.1.2 → 2.1.4
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 +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +65 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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 - 底层存储适配器
|
|
@@ -1220,8 +1222,9 @@ declare class PluginManager {
|
|
|
1220
1222
|
* 加载插件列表
|
|
1221
1223
|
* @param configs 插件配置
|
|
1222
1224
|
* @param registry 插件注册表 (动态导入函数)
|
|
1225
|
+
* @param notify 是否在加载完成后触发通知,默认为 true
|
|
1223
1226
|
*/
|
|
1224
|
-
loadPlugins(configs: Record<string, any>, registry: Record<string, () => Promise<any
|
|
1227
|
+
loadPlugins(configs: Record<string, any>, registry: Record<string, () => Promise<any>>, notify?: boolean): Promise<void>;
|
|
1225
1228
|
/**
|
|
1226
1229
|
* 加载远程插件
|
|
1227
1230
|
* @param pluginId 插件 ID
|
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 - 底层存储适配器
|
|
@@ -1220,8 +1222,9 @@ declare class PluginManager {
|
|
|
1220
1222
|
* 加载插件列表
|
|
1221
1223
|
* @param configs 插件配置
|
|
1222
1224
|
* @param registry 插件注册表 (动态导入函数)
|
|
1225
|
+
* @param notify 是否在加载完成后触发通知,默认为 true
|
|
1223
1226
|
*/
|
|
1224
|
-
loadPlugins(configs: Record<string, any>, registry: Record<string, () => Promise<any
|
|
1227
|
+
loadPlugins(configs: Record<string, any>, registry: Record<string, () => Promise<any>>, notify?: boolean): Promise<void>;
|
|
1225
1228
|
/**
|
|
1226
1229
|
* 加载远程插件
|
|
1227
1230
|
* @param pluginId 插件 ID
|
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,69 @@ var PluginManager = class {
|
|
|
1784
1786
|
* @param sharedContext 共享上下文
|
|
1785
1787
|
*/
|
|
1786
1788
|
async initPlugins(sharedContext = {}) {
|
|
1787
|
-
this.
|
|
1788
|
-
...
|
|
1789
|
-
|
|
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
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
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
|
-
|
|
1818
|
-
|
|
1819
|
-
const
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
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
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
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
|
+
}
|
|
1836
|
+
}
|
|
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
|
+
}
|
|
1837
1847
|
}
|
|
1838
1848
|
}
|
|
1849
|
+
} finally {
|
|
1850
|
+
this.isInitializing = false;
|
|
1851
|
+
this.notify();
|
|
1839
1852
|
}
|
|
1840
1853
|
}
|
|
1841
1854
|
/**
|
|
@@ -1882,8 +1895,9 @@ var PluginManager = class {
|
|
|
1882
1895
|
* 加载插件列表
|
|
1883
1896
|
* @param configs 插件配置
|
|
1884
1897
|
* @param registry 插件注册表 (动态导入函数)
|
|
1898
|
+
* @param notify 是否在加载完成后触发通知,默认为 true
|
|
1885
1899
|
*/
|
|
1886
|
-
async loadPlugins(configs, registry) {
|
|
1900
|
+
async loadPlugins(configs, registry, notify = true) {
|
|
1887
1901
|
logger6.info("\u5F00\u59CB\u52A0\u8F7D\u63D2\u4EF6...");
|
|
1888
1902
|
const localLoadPromises = Object.entries(registry).map(async ([registryId, importFn]) => {
|
|
1889
1903
|
try {
|
|
@@ -1917,7 +1931,9 @@ var PluginManager = class {
|
|
|
1917
1931
|
this.register(plugin, false);
|
|
1918
1932
|
}
|
|
1919
1933
|
});
|
|
1920
|
-
|
|
1934
|
+
if (notify) {
|
|
1935
|
+
this.notify();
|
|
1936
|
+
}
|
|
1921
1937
|
logger6.info(`\u63D2\u4EF6\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171\u52A0\u8F7D ${this.plugins.size} \u4E2A\u63D2\u4EF6`);
|
|
1922
1938
|
}
|
|
1923
1939
|
/**
|
|
@@ -2762,7 +2778,7 @@ var usePluginLoader = (options) => {
|
|
|
2762
2778
|
const { configManager: configManager2 } = await Promise.resolve().then(() => (init_config_manager(), config_manager_exports));
|
|
2763
2779
|
configManager2.set("system", options.systemConfig);
|
|
2764
2780
|
}
|
|
2765
|
-
await pluginManager.loadPlugins(pluginConfigs, finalRegistry);
|
|
2781
|
+
await pluginManager.loadPlugins(pluginConfigs, finalRegistry, false);
|
|
2766
2782
|
await pluginManager.initPlugins(sharedContext);
|
|
2767
2783
|
setPluginsLoaded(true);
|
|
2768
2784
|
logger10.info("Plugins loaded successfully");
|