@chatbi-v/vue 3.0.0 → 3.1.1
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/README.md +36 -0
- package/dist/core/src/adapters/AdapterInterface.d.ts +111 -0
- package/dist/core/src/adapters/AdapterRegistry.d.ts +88 -0
- package/dist/core/src/adapters/index.d.ts +7 -0
- package/dist/core/src/adapters/local-storage-adapter.d.ts +61 -0
- package/dist/core/src/adapters/scoped-storage-adapter.d.ts +61 -0
- package/dist/core/src/ai/function/index.d.ts +1 -0
- package/dist/core/src/ai/function/registry.d.ts +28 -0
- package/dist/core/src/ai/index.d.ts +8 -0
- package/dist/core/src/ai/providers/index.d.ts +2 -0
- package/dist/core/src/ai/providers/mock.d.ts +28 -0
- package/dist/core/src/ai/providers/openai.d.ts +17 -0
- package/dist/core/src/ai/session/index.d.ts +3 -0
- package/dist/core/src/ai/session/manager.d.ts +19 -0
- package/dist/core/src/ai/session/storage.d.ts +9 -0
- package/dist/core/src/ai/session/types.d.ts +14 -0
- package/dist/core/src/ai/store.d.ts +23 -0
- package/dist/core/src/ai/types.d.ts +57 -0
- package/dist/core/src/ai/utils.d.ts +7 -0
- package/dist/core/src/api/adapters/axios-adapter.d.ts +10 -0
- package/dist/core/src/api/engine.d.ts +101 -0
- package/dist/core/src/api/index.d.ts +5 -0
- package/dist/core/src/api/utils.d.ts +14 -0
- package/dist/core/src/application/service-registry.d.ts +57 -0
- package/dist/core/src/config-manager.d.ts +52 -0
- package/dist/core/src/dependency/ConflictResolver.d.ts +46 -0
- package/dist/core/src/dependency/CycleDetector.d.ts +47 -0
- package/dist/core/src/dependency/DependencyGraph.d.ts +85 -0
- package/dist/core/src/dependency/NpmRegistry.d.ts +78 -0
- package/dist/core/src/dependency/SharedDepsDetector.d.ts +49 -0
- package/dist/core/src/dependency/index.d.ts +9 -0
- package/dist/core/src/domain/auto-loader.d.ts +36 -0
- package/dist/core/src/domain/errors.d.ts +68 -0
- package/dist/core/src/domain/models.d.ts +42 -0
- package/dist/core/src/domain/performance/collector.d.ts +70 -0
- package/dist/core/src/domain/performance/index.d.ts +27 -0
- package/dist/core/src/domain/performance/lifecycle.d.ts +34 -0
- package/dist/core/src/domain/performance/storage.d.ts +79 -0
- package/dist/core/src/domain/performance/types.d.ts +67 -0
- package/dist/core/src/domain/plugin-manager.d.ts +327 -0
- package/dist/core/src/domain/plugin-runtime.d.ts +74 -0
- package/dist/core/src/domain/plugin-sandbox.d.ts +40 -0
- package/dist/core/src/domain/storage-manager.d.ts +81 -0
- package/dist/core/src/event-bus.d.ts +55 -0
- package/dist/core/src/feature-flag/FeatureRegistry.d.ts +75 -0
- package/dist/core/src/feature-flag/RuleEngine.d.ts +44 -0
- package/dist/core/src/feature-flag/index.d.ts +6 -0
- package/dist/core/src/index.d.ts +37 -0
- package/dist/core/src/manifest/ManifestValidator.d.ts +33 -0
- package/dist/core/src/manifest/ManifestWrapper.d.ts +23 -0
- package/dist/core/src/manifest/PluginManifest.d.ts +524 -0
- package/dist/core/src/manifest/index.d.ts +9 -0
- package/dist/core/src/ports/api-port.d.ts +136 -0
- package/dist/core/src/ports/event-bus-port.d.ts +32 -0
- package/dist/core/src/ports/plugin-port.d.ts +345 -0
- package/dist/core/src/ports/storage-port.d.ts +49 -0
- package/dist/core/src/remote/RemoteCache.d.ts +57 -0
- package/dist/core/src/remote/RemoteLoader.d.ts +85 -0
- package/dist/core/src/remote/RemotePluginSource.d.ts +88 -0
- package/dist/core/src/remote/RetryStrategy.d.ts +43 -0
- package/dist/core/src/remote/index.d.ts +8 -0
- package/dist/core/src/sandbox/proxy-sandbox.d.ts +74 -0
- package/dist/core/src/semver/SemverResolver.d.ts +79 -0
- package/dist/core/src/store.d.ts +30 -0
- package/dist/core/src/types/branded.d.ts +54 -0
- package/dist/core/src/types/index.d.ts +8 -0
- package/dist/core/src/types/template-literals.d.ts +58 -0
- package/dist/core/src/types/utils.d.ts +133 -0
- package/dist/core/src/utils/date.d.ts +32 -0
- package/dist/core/src/utils/index.d.ts +4 -0
- package/dist/core/src/utils/logger.d.ts +108 -0
- package/dist/core/src/utils/url.d.ts +16 -0
- package/dist/index.js +1899 -1842
- package/dist/index.umd.cjs +19 -19
- package/dist/vue/src/components/PluginErrorBoundary.vue.d.ts +20 -0
- package/dist/vue/src/components/PluginSlot.vue.d.ts +8 -0
- package/dist/vue/src/composables/useCoreStore.d.ts +9 -0
- package/dist/vue/src/composables/useService.d.ts +6 -0
- package/dist/vue/src/index.d.ts +18 -0
- package/package.json +10 -8
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 成功状态码
|
|
3
|
+
*/
|
|
4
|
+
export declare const SUCCESS_CODE = "000000";
|
|
5
|
+
/**
|
|
6
|
+
* 基础 API 响应接口
|
|
7
|
+
* @template T 响应数据的类型
|
|
8
|
+
*/
|
|
9
|
+
export interface BaseResponse<T = any> {
|
|
10
|
+
/** 业务状态码 */
|
|
11
|
+
code: string | number;
|
|
12
|
+
/** 响应消息提示 */
|
|
13
|
+
message: string;
|
|
14
|
+
/** 业务响应数据主体 */
|
|
15
|
+
data: T;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 业务场景实体接口
|
|
19
|
+
* @description 描述系统中的业务分析场景
|
|
20
|
+
*/
|
|
21
|
+
export interface Scene {
|
|
22
|
+
/** 场景唯一标识符 */
|
|
23
|
+
id: string;
|
|
24
|
+
/** 场景名称 */
|
|
25
|
+
name: string;
|
|
26
|
+
/** 场景详细描述 */
|
|
27
|
+
description: string;
|
|
28
|
+
/** 场景内部代码/标识 */
|
|
29
|
+
code: string;
|
|
30
|
+
/** 场景创建者 ID 或名称 */
|
|
31
|
+
creator: string;
|
|
32
|
+
/** 创建时间字符串 (ISO 格式) */
|
|
33
|
+
createTime: string;
|
|
34
|
+
/** 该场景关联的物理数据表数量 */
|
|
35
|
+
tableCount: number;
|
|
36
|
+
/** 该场景关联的知识库数量 */
|
|
37
|
+
kbCount: number;
|
|
38
|
+
/** 该场景关联的预设问答对数量 */
|
|
39
|
+
qaCount: number;
|
|
40
|
+
/** 场景封面图 URL (可选) */
|
|
41
|
+
cover?: string;
|
|
42
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { PerformanceStorage } from './storage';
|
|
2
|
+
import type { LifecycleMetric, LifecyclePhase, RuntimeMetric } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* 性能计时器
|
|
5
|
+
* @description 用于测量代码块执行耗时,自动计算 duration 并保存到存储
|
|
6
|
+
*/
|
|
7
|
+
export declare class PerformanceTimer {
|
|
8
|
+
private startTime;
|
|
9
|
+
private phase;
|
|
10
|
+
private pluginId;
|
|
11
|
+
private storage;
|
|
12
|
+
/**
|
|
13
|
+
* 构造函数
|
|
14
|
+
* @param phase - 生命周期阶段
|
|
15
|
+
* @param pluginId - 插件 ID
|
|
16
|
+
* @param storage - 性能存储实例
|
|
17
|
+
*/
|
|
18
|
+
constructor(phase: LifecyclePhase, pluginId: string, storage: PerformanceStorage);
|
|
19
|
+
/**
|
|
20
|
+
* 开始计时
|
|
21
|
+
*/
|
|
22
|
+
start(): void;
|
|
23
|
+
/**
|
|
24
|
+
* 结束计时并保存结果
|
|
25
|
+
* @param success - 是否成功
|
|
26
|
+
* @param error - 错误信息(可选)
|
|
27
|
+
*/
|
|
28
|
+
end(success: boolean, error?: string): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 性能数据采集器
|
|
32
|
+
* @description 负责性能数据的采集和记录,提供计时器创建和运行时指标记录功能
|
|
33
|
+
*/
|
|
34
|
+
export declare class PerformanceCollector {
|
|
35
|
+
private storage;
|
|
36
|
+
/**
|
|
37
|
+
* 构造函数
|
|
38
|
+
* @param storage - 性能存储实例
|
|
39
|
+
*/
|
|
40
|
+
constructor(storage: PerformanceStorage);
|
|
41
|
+
/**
|
|
42
|
+
* 开始测量指定生命周期阶段
|
|
43
|
+
* @param phase - 生命周期阶段
|
|
44
|
+
* @param pluginId - 插件 ID
|
|
45
|
+
* @returns PerformanceTimer 实例
|
|
46
|
+
*/
|
|
47
|
+
startMeasure(phase: LifecyclePhase, pluginId: string): PerformanceTimer;
|
|
48
|
+
/**
|
|
49
|
+
* 记录运行时指标
|
|
50
|
+
* @param metric - 运行时指标(不包含 timestamp)
|
|
51
|
+
*/
|
|
52
|
+
recordRuntimeMetric(metric: Omit<RuntimeMetric, 'timestamp'>): void;
|
|
53
|
+
/**
|
|
54
|
+
* 获取性能指标
|
|
55
|
+
* @param pluginId - 插件 ID(可选,不传则返回所有)
|
|
56
|
+
*/
|
|
57
|
+
getMetrics(pluginId?: string): {
|
|
58
|
+
lifecycle: LifecycleMetric[];
|
|
59
|
+
runtime: RuntimeMetric[];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* 清除性能数据
|
|
63
|
+
* @param pluginId - 插件 ID(可选,不传则清除所有)
|
|
64
|
+
*/
|
|
65
|
+
clearMetrics(pluginId?: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* 获取存储实例(供外部使用)
|
|
68
|
+
*/
|
|
69
|
+
getStorage(): PerformanceStorage;
|
|
70
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file performance/index.ts
|
|
3
|
+
* @description 性能监测模块统一导出
|
|
4
|
+
* @author ChatBI Team
|
|
5
|
+
*/
|
|
6
|
+
export type { LifecycleMetric, LifecyclePhase, PerformanceData, PerformanceSettings, RuntimeMetric, } from './types';
|
|
7
|
+
export { DEFAULT_PERFORMANCE_SETTINGS } from './types';
|
|
8
|
+
export { PerformanceCollector } from './collector';
|
|
9
|
+
export { PerformanceTimer } from './collector';
|
|
10
|
+
export { createLifecycleMonitor, LifecycleMonitor } from './lifecycle';
|
|
11
|
+
export { PerformanceStorage } from './storage';
|
|
12
|
+
import type { StorageManager } from '../storage-manager';
|
|
13
|
+
import { PerformanceCollector } from './collector';
|
|
14
|
+
import { LifecycleMonitor } from './lifecycle';
|
|
15
|
+
import { PerformanceStorage } from './storage';
|
|
16
|
+
import type { PerformanceSettings } from './types';
|
|
17
|
+
/**
|
|
18
|
+
* 性能监测系统工厂函数
|
|
19
|
+
* @param storageManager - 存储管理器实例
|
|
20
|
+
* @param settings - 性能设置(可选)
|
|
21
|
+
* @returns 包含 collector, storage, monitor 的对象
|
|
22
|
+
*/
|
|
23
|
+
export declare function createPerformanceMonitor(storageManager: StorageManager, settings?: PerformanceSettings): {
|
|
24
|
+
collector: PerformanceCollector;
|
|
25
|
+
storage: PerformanceStorage;
|
|
26
|
+
createMonitor: (runtime: any) => LifecycleMonitor;
|
|
27
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PluginRuntime } from '../plugin-runtime';
|
|
2
|
+
import { PerformanceCollector } from './collector';
|
|
3
|
+
/**
|
|
4
|
+
* 生命周期监测器(装饰器模式)
|
|
5
|
+
* @description 通过代理模式包装 PluginRuntime,在生命周期各阶段自动记录耗时
|
|
6
|
+
*/
|
|
7
|
+
export declare class LifecycleMonitor {
|
|
8
|
+
private runtime;
|
|
9
|
+
private collector;
|
|
10
|
+
/**
|
|
11
|
+
* 构造函数
|
|
12
|
+
* @param runtime - 插件运行时实例
|
|
13
|
+
* @param collector - 性能采集器实例
|
|
14
|
+
*/
|
|
15
|
+
constructor(runtime: PluginRuntime, collector: PerformanceCollector);
|
|
16
|
+
/**
|
|
17
|
+
* 包装插件运行时,返回代理对象
|
|
18
|
+
* @returns 包装后的运行时对象
|
|
19
|
+
*/
|
|
20
|
+
wrap(): PluginRuntime;
|
|
21
|
+
/**
|
|
22
|
+
* 包装指定方法,在执行前后记录耗时
|
|
23
|
+
* @param phase - 生命周期阶段
|
|
24
|
+
* @param originalMethod - 原始方法
|
|
25
|
+
*/
|
|
26
|
+
private wrapMethod;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 创建生命周期监测器
|
|
30
|
+
* @param runtime - 插件运行时实例
|
|
31
|
+
* @param collector - 性能采集器实例
|
|
32
|
+
* @returns LifecycleMonitor 实例
|
|
33
|
+
*/
|
|
34
|
+
export declare function createLifecycleMonitor(runtime: PluginRuntime, collector: PerformanceCollector): LifecycleMonitor;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { StorageManager } from '../storage-manager';
|
|
2
|
+
import type { LifecycleMetric, PerformanceData, PerformanceSettings, RuntimeMetric } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* 性能数据存储层
|
|
5
|
+
* @description 负责性能数据的持久化,支持生命周期指标和运行时采样数据的存储与查询
|
|
6
|
+
*/
|
|
7
|
+
export declare class PerformanceStorage {
|
|
8
|
+
private storageManager;
|
|
9
|
+
private systemStorage;
|
|
10
|
+
private settings;
|
|
11
|
+
private lifecycleCache;
|
|
12
|
+
private runtimeCache;
|
|
13
|
+
private readonly LIFECYCLE_KEY;
|
|
14
|
+
private readonly RUNTIME_KEY;
|
|
15
|
+
/**
|
|
16
|
+
* 构造函数
|
|
17
|
+
* @param storageManager - 存储管理器实例
|
|
18
|
+
* @param settings - 性能设置(可选,默认使用 DEFAULT_PERFORMANCE_SETTINGS)
|
|
19
|
+
*/
|
|
20
|
+
constructor(storageManager: StorageManager, settings?: PerformanceSettings);
|
|
21
|
+
/**
|
|
22
|
+
* 从持久化存储加载数据到内存缓存
|
|
23
|
+
*/
|
|
24
|
+
private loadFromStorage;
|
|
25
|
+
/**
|
|
26
|
+
* 保存生命周期指标
|
|
27
|
+
* @param metric - 生命周期指标
|
|
28
|
+
*/
|
|
29
|
+
saveLifecycleMetric(metric: LifecycleMetric): void;
|
|
30
|
+
/**
|
|
31
|
+
* 保存运行时指标
|
|
32
|
+
* @param metric - 运行时指标
|
|
33
|
+
*/
|
|
34
|
+
saveRuntimeMetric(metric: RuntimeMetric): void;
|
|
35
|
+
/**
|
|
36
|
+
* 保存指标(通用方法,自动识别类型)
|
|
37
|
+
* @param metric - 指标数据
|
|
38
|
+
*/
|
|
39
|
+
saveMetric(metric: LifecycleMetric | RuntimeMetric): void;
|
|
40
|
+
/**
|
|
41
|
+
* 强制执行生命周期数据上限(FIFO)
|
|
42
|
+
*/
|
|
43
|
+
private enforceLifecycleLimit;
|
|
44
|
+
/**
|
|
45
|
+
* 强制执行运行时数据上限(FIFO)
|
|
46
|
+
*/
|
|
47
|
+
private enforceRuntimeLimit;
|
|
48
|
+
/**
|
|
49
|
+
* 持久化生命周期数据
|
|
50
|
+
*/
|
|
51
|
+
private persistLifecycle;
|
|
52
|
+
/**
|
|
53
|
+
* 持久化运行时数据
|
|
54
|
+
*/
|
|
55
|
+
private persistRuntime;
|
|
56
|
+
/**
|
|
57
|
+
* 获取生命周期指标
|
|
58
|
+
* @param pluginId - 插件 ID(可选,不传则返回所有)
|
|
59
|
+
*/
|
|
60
|
+
getLifecycleMetrics(pluginId?: string): LifecycleMetric[];
|
|
61
|
+
/**
|
|
62
|
+
* 获取运行时指标
|
|
63
|
+
* @param pluginId - 插件 ID(可选,不传则返回所有)
|
|
64
|
+
*/
|
|
65
|
+
getRuntimeMetrics(pluginId?: string): RuntimeMetric[];
|
|
66
|
+
/**
|
|
67
|
+
* 清除性能数据
|
|
68
|
+
* @param pluginId - 插件 ID(可选,不传则清除所有)
|
|
69
|
+
*/
|
|
70
|
+
clearMetrics(pluginId?: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* 获取所有性能数据
|
|
73
|
+
*/
|
|
74
|
+
getAllData(): PerformanceData;
|
|
75
|
+
/**
|
|
76
|
+
* 获取指定插件的性能数据
|
|
77
|
+
*/
|
|
78
|
+
getPluginData(pluginId: string): PerformanceData;
|
|
79
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file performance/types.ts
|
|
3
|
+
* @description 性能监测数据类型定义
|
|
4
|
+
* @author ChatBI Team
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 插件生命周期阶段
|
|
8
|
+
*/
|
|
9
|
+
export type LifecyclePhase = 'load' | 'mount' | 'unmount';
|
|
10
|
+
/**
|
|
11
|
+
* 生命周期性能指标
|
|
12
|
+
* 记录插件 load/mount/unmount 阶段的执行耗时
|
|
13
|
+
*/
|
|
14
|
+
export interface LifecycleMetric {
|
|
15
|
+
/** 插件 ID */
|
|
16
|
+
pluginId: string;
|
|
17
|
+
/** 生命周期阶段 */
|
|
18
|
+
phase: LifecyclePhase;
|
|
19
|
+
/** 执行耗时(毫秒) */
|
|
20
|
+
duration: number;
|
|
21
|
+
/** 时间戳 */
|
|
22
|
+
timestamp: number;
|
|
23
|
+
/** 是否成功 */
|
|
24
|
+
success: boolean;
|
|
25
|
+
/** 错误信息(仅在 success 为 false 时存在) */
|
|
26
|
+
error?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 运行时性能指标
|
|
30
|
+
* 记录插件运行期间的内存、帧率等数据
|
|
31
|
+
*/
|
|
32
|
+
export interface RuntimeMetric {
|
|
33
|
+
/** 插件 ID */
|
|
34
|
+
pluginId: string;
|
|
35
|
+
/** 时间戳 */
|
|
36
|
+
timestamp: number;
|
|
37
|
+
/** 内存使用量(字节) */
|
|
38
|
+
memory?: number;
|
|
39
|
+
/** 帧率 */
|
|
40
|
+
fps?: number;
|
|
41
|
+
/** API 调用次数 */
|
|
42
|
+
apiCalls?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 性能数据集合
|
|
46
|
+
*/
|
|
47
|
+
export interface PerformanceData {
|
|
48
|
+
/** 生命周期指标集合 */
|
|
49
|
+
lifecycle: LifecycleMetric[];
|
|
50
|
+
/** 运行时采样数据集合 */
|
|
51
|
+
samples: RuntimeMetric[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 性能监测配置
|
|
55
|
+
*/
|
|
56
|
+
export interface PerformanceSettings {
|
|
57
|
+
/** 生命周期记录最大条数(默认 1000) */
|
|
58
|
+
maxLifecycleRecords: number;
|
|
59
|
+
/** 运行时采样最大条数(默认 500) */
|
|
60
|
+
maxRuntimeSamples: number;
|
|
61
|
+
/** 采样率(0-1 之间) */
|
|
62
|
+
sampleRate: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 默认性能监测配置
|
|
66
|
+
*/
|
|
67
|
+
export declare const DEFAULT_PERFORMANCE_SETTINGS: PerformanceSettings;
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file plugin-manager.ts
|
|
3
|
+
* @description 插件管理器,负责插件的注册、生命周期管理、状态持久化及扩展点收集
|
|
4
|
+
* @author ChatBI Team
|
|
5
|
+
*/
|
|
6
|
+
import { DefaultEventBus } from '../event-bus';
|
|
7
|
+
import type { PluginManifest } from '../manifest/PluginManifest';
|
|
8
|
+
import { Plugin, PluginExtension, RouteConfig, SlotPosition } from '../ports/plugin-port';
|
|
9
|
+
import { StoragePort } from '../ports/storage-port';
|
|
10
|
+
import { PluginRuntime } from './plugin-runtime';
|
|
11
|
+
import { StorageManager } from './storage-manager';
|
|
12
|
+
/**
|
|
13
|
+
* 插件错误分类
|
|
14
|
+
*/
|
|
15
|
+
export declare enum PluginErrorType {
|
|
16
|
+
/** 可恢复错误:网络波动、超时等,可以重试 */
|
|
17
|
+
RECOVERABLE = "recoverable",
|
|
18
|
+
/** 致命错误:语法错误、循环依赖等,无法通过重试恢复 */
|
|
19
|
+
FATAL = "fatal",
|
|
20
|
+
/** 配置错误:插件配置无效 */
|
|
21
|
+
CONFIG = "config",
|
|
22
|
+
/** 依赖错误:依赖插件不存在或版本不匹配 */
|
|
23
|
+
DEPENDENCY = "dependency"
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 插件错误
|
|
27
|
+
*/
|
|
28
|
+
export declare class PluginError extends Error {
|
|
29
|
+
pluginId: string;
|
|
30
|
+
type: PluginErrorType;
|
|
31
|
+
originalError?: Error;
|
|
32
|
+
retryCount: number;
|
|
33
|
+
constructor(pluginId: string, type: PluginErrorType, message: string, originalError?: Error, retryCount?: number);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 插件管理器
|
|
37
|
+
* @description 核心领域服务,负责插件的完整生命周期管理,包括扫描、注册、配置合并、状态切换及依赖解析。
|
|
38
|
+
*/
|
|
39
|
+
export declare class PluginManager {
|
|
40
|
+
/** 全局事件总线,用于插件间及插件与内核间的异步通信 */
|
|
41
|
+
readonly eventBus: DefaultEventBus;
|
|
42
|
+
/** 存储管理服务,负责插件私有存储和系统级状态的持久化 */
|
|
43
|
+
private storageManager;
|
|
44
|
+
/** 插件 ID 到运行时实例的映射表 */
|
|
45
|
+
private runtimes;
|
|
46
|
+
/** 插件 ID 到原始插件定义对象的映射表 */
|
|
47
|
+
private plugins;
|
|
48
|
+
/** 收集到的所有插件路由配置 */
|
|
49
|
+
private routes;
|
|
50
|
+
/** 收集到的所有插件扩展点配置,按插槽位置分组 */
|
|
51
|
+
private extensions;
|
|
52
|
+
/** 插件的启用状态和排序信息的内存缓存 */
|
|
53
|
+
private pluginStates;
|
|
54
|
+
/** 扩展点缓存,避免重复计算 */
|
|
55
|
+
private memoizedExtensions;
|
|
56
|
+
/** 路由缓存 */
|
|
57
|
+
private memoizedRoutes;
|
|
58
|
+
/** 传递给插件的共享上下文缓存 */
|
|
59
|
+
private sharedContext;
|
|
60
|
+
/** 收集到的插件工具函数集合 */
|
|
61
|
+
private utils;
|
|
62
|
+
/** 插件强制启用标记(系统插件不可禁用) */
|
|
63
|
+
private pluginForces;
|
|
64
|
+
/** 插件懒加载标记 */
|
|
65
|
+
private pluginLazyInit;
|
|
66
|
+
/** 插件默认启用状态 */
|
|
67
|
+
private pluginDefaultEnabled;
|
|
68
|
+
/** 是否正在初始化插件中,防止重入导致多次加载 */
|
|
69
|
+
private isInitializing;
|
|
70
|
+
/**
|
|
71
|
+
* 构造函数
|
|
72
|
+
* @param storage - 底层存储适配器
|
|
73
|
+
*/
|
|
74
|
+
constructor(storage: StoragePort);
|
|
75
|
+
/**
|
|
76
|
+
* 从持久化存储中恢复插件状态 (启用/禁用、排序等)
|
|
77
|
+
*/
|
|
78
|
+
private loadStates;
|
|
79
|
+
/**
|
|
80
|
+
* 将当前的插件状态持久化到存储中
|
|
81
|
+
*/
|
|
82
|
+
private saveStates;
|
|
83
|
+
/**
|
|
84
|
+
* 订阅插件状态变更
|
|
85
|
+
* @param listener 回调函数,当插件状态变更时被调用
|
|
86
|
+
* @returns 取消订阅的函数
|
|
87
|
+
*/
|
|
88
|
+
subscribe(listener: () => void): () => void;
|
|
89
|
+
/**
|
|
90
|
+
* 订阅路由变更
|
|
91
|
+
* @param listener 回调函数,当路由变更时被调用
|
|
92
|
+
* @returns 取消订阅的函数
|
|
93
|
+
*/
|
|
94
|
+
subscribeToRoutes(listener: () => void): () => void;
|
|
95
|
+
/**
|
|
96
|
+
* 获取存储管理器实例
|
|
97
|
+
* @returns StorageManager 实例
|
|
98
|
+
*/
|
|
99
|
+
getStorageManager(): StorageManager;
|
|
100
|
+
/**
|
|
101
|
+
* 用于调度状态更新的函数,可由外部宿主环境(如 React)注入
|
|
102
|
+
*/
|
|
103
|
+
private stateUpdateScheduler;
|
|
104
|
+
/**
|
|
105
|
+
* 注入状态更新调度器
|
|
106
|
+
*/
|
|
107
|
+
setUpdateScheduler(scheduler: (callback: () => void) => void): void;
|
|
108
|
+
/**
|
|
109
|
+
* 触发状态变更通知
|
|
110
|
+
* @description 统一使用 Zustand Store 进行状态管理,EventBus 仅用于一次性事件
|
|
111
|
+
* @param affectedSlot - (可选) 受影响的插槽位置
|
|
112
|
+
*/
|
|
113
|
+
private notify;
|
|
114
|
+
/**
|
|
115
|
+
* 获取指定插件
|
|
116
|
+
* @param pluginId 插件 ID
|
|
117
|
+
*/
|
|
118
|
+
getPlugin(pluginId: string): Plugin | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* 检查插件是否已注册
|
|
121
|
+
* @param pluginId - 插件 ID
|
|
122
|
+
*/
|
|
123
|
+
hasPlugin(pluginId: string): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* 获取指定插件的运行时实例
|
|
126
|
+
* @param pluginId 插件 ID
|
|
127
|
+
* @returns 插件运行时实例,如果不存在则返回 undefined
|
|
128
|
+
*/
|
|
129
|
+
getPluginRuntime(pluginId: string): PluginRuntime | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* 激活插件
|
|
132
|
+
* @param pluginId - 插件 ID
|
|
133
|
+
*/
|
|
134
|
+
activate(pluginId: string): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* 获取所有已注册的插件列表
|
|
137
|
+
* @description 结果会根据插件类型优先级和用户自定义排序进行排序
|
|
138
|
+
* @returns 排序后的插件数组
|
|
139
|
+
*/
|
|
140
|
+
getPlugins(): Plugin[];
|
|
141
|
+
/**
|
|
142
|
+
* 获取指定插件的状态信息
|
|
143
|
+
* @param pluginId - 插件 ID
|
|
144
|
+
* @returns 包含启用状态和排序值的对象
|
|
145
|
+
*/
|
|
146
|
+
getPluginState(pluginId: string): {
|
|
147
|
+
enabled: boolean;
|
|
148
|
+
order: number;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* 检查指定插件是否处于启用状态
|
|
152
|
+
* @param pluginId - 插件 ID
|
|
153
|
+
* @returns 是否启用
|
|
154
|
+
*/
|
|
155
|
+
isPluginEnabled(pluginId: string): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* 检查插件是否可禁用
|
|
158
|
+
* @param pluginId - 插件 ID
|
|
159
|
+
* @returns 是否可禁用
|
|
160
|
+
*/
|
|
161
|
+
canDisablePlugin(pluginId: string): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* 检查插件是否应默认启用
|
|
164
|
+
* @param pluginId - 插件 ID
|
|
165
|
+
* @returns 是否默认启用
|
|
166
|
+
*/
|
|
167
|
+
shouldEnableByDefault(pluginId: string): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* 切换插件的启用/禁用状态
|
|
170
|
+
* @description 禁用插件会立即触发其卸载生命周期并销毁运行时。
|
|
171
|
+
* @param pluginId - 插件 ID
|
|
172
|
+
* @param enabled - 目标状态
|
|
173
|
+
*/
|
|
174
|
+
togglePlugin(pluginId: string, enabled: boolean): void;
|
|
175
|
+
/**
|
|
176
|
+
* 删除插件及其所有关联状态
|
|
177
|
+
* @description 完整清理流程:禁用 -> 卸载运行时 -> 清理存储 -> 清理配置 -> 清理状态 -> 通知
|
|
178
|
+
* @param pluginId - 插件 ID
|
|
179
|
+
* @param cleanupStorage - 是否清理存储(默认 true)
|
|
180
|
+
*/
|
|
181
|
+
deletePlugin(pluginId: string, cleanupStorage?: boolean): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* 更新插件元数据和包地址
|
|
184
|
+
* @description 更新流程:禁用旧版本 -> 卸载 -> 更新元数据 -> 重新加载并激活
|
|
185
|
+
* @param pluginId - 插件 ID
|
|
186
|
+
* @param newManifest - 新的插件清单
|
|
187
|
+
* @param newBundleUrl - 新的包地址(可选,如果不改变则传 undefined)
|
|
188
|
+
*/
|
|
189
|
+
updatePlugin(pluginId: string, newManifest: Partial<PluginManifest>, newBundleUrl?: string): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* 设置插件的显示排序权重
|
|
192
|
+
* @param pluginId - 插件 ID
|
|
193
|
+
* @param order - 排序权重值
|
|
194
|
+
*/
|
|
195
|
+
setPluginOrder(pluginId: string, order: number): void;
|
|
196
|
+
/**
|
|
197
|
+
* 获取指定插件的运行时状态
|
|
198
|
+
* @param pluginId - 插件 ID
|
|
199
|
+
* @returns 'error' | 'mounted' | 'loaded' | 'initial'
|
|
200
|
+
*/
|
|
201
|
+
getPluginRuntimeStatus(pluginId: string): "error" | "mounted" | "loaded" | "initial";
|
|
202
|
+
/**
|
|
203
|
+
* 获取指定插件的运行时错误
|
|
204
|
+
* @param pluginId - 插件 ID
|
|
205
|
+
* @returns Error 对象或 null
|
|
206
|
+
*/
|
|
207
|
+
getPluginError(pluginId: string): Error;
|
|
208
|
+
/**
|
|
209
|
+
* 报告插件运行时错误 (通常由 ErrorBoundary 调用)
|
|
210
|
+
* @param pluginId - 插件 ID
|
|
211
|
+
* @param error - 错误对象
|
|
212
|
+
*/
|
|
213
|
+
reportPluginError(pluginId: string, error: Error): void;
|
|
214
|
+
/**
|
|
215
|
+
* 获取插件的完整能力声明
|
|
216
|
+
* @param pluginId - 插件 ID
|
|
217
|
+
* @returns 能力对象
|
|
218
|
+
*/
|
|
219
|
+
getUnifiedCapabilities(pluginId: string): import("src").PluginCapabilities;
|
|
220
|
+
/**
|
|
221
|
+
* 更新指定插件的某项配置
|
|
222
|
+
* @description 该操作会同步更新内存中的配置、持久化到存储并触发全局事件通知。
|
|
223
|
+
* @param pluginId - 插件 ID
|
|
224
|
+
* @param key - 配置键名
|
|
225
|
+
* @param value - 新的配置值
|
|
226
|
+
*/
|
|
227
|
+
updatePluginConfig(pluginId: string, key: string, value: any): void;
|
|
228
|
+
/**
|
|
229
|
+
* 获取指定插件的某项配置值
|
|
230
|
+
* @param pluginId - 插件 ID
|
|
231
|
+
* @param key - 配置键名
|
|
232
|
+
* @returns 配置值
|
|
233
|
+
*/
|
|
234
|
+
getPluginConfig(pluginId: string, key: string): any;
|
|
235
|
+
/**
|
|
236
|
+
* 获取系统全局配置 (非插件特定)
|
|
237
|
+
* @param key - 系统配置键名
|
|
238
|
+
* @returns 配置值
|
|
239
|
+
*/
|
|
240
|
+
getSystemConfig(key: string): any;
|
|
241
|
+
/**
|
|
242
|
+
* 获取由插件注册的服务实例
|
|
243
|
+
* @template T 服务接口类型
|
|
244
|
+
* @param name - 服务注册名称
|
|
245
|
+
* @returns 服务实例或 undefined
|
|
246
|
+
*/
|
|
247
|
+
getService<T = any>(name: string): T | undefined;
|
|
248
|
+
/**
|
|
249
|
+
* 获取指定插槽位置的所有已启用插件的扩展
|
|
250
|
+
* @param slot - 插槽位置标识
|
|
251
|
+
* @returns 排序后的扩展配置数组
|
|
252
|
+
*/
|
|
253
|
+
getExtensions(slot: SlotPosition | string): PluginExtension[];
|
|
254
|
+
/**
|
|
255
|
+
* 获取所有已启用插件注册的路由配置
|
|
256
|
+
* @returns 增强后的路由配置数组
|
|
257
|
+
*/
|
|
258
|
+
getRoutes(): RouteConfig[];
|
|
259
|
+
/**
|
|
260
|
+
* 注册一个新插件到管理器中
|
|
261
|
+
* @description 此阶段会执行元数据校验、存储 Schema 注册、配置合并及扩展点收集。
|
|
262
|
+
* @param plugin - 插件对象
|
|
263
|
+
* @param notify - 是否在注册完成后触发状态变更通知
|
|
264
|
+
*/
|
|
265
|
+
register(plugin: Plugin, notify?: boolean): void;
|
|
266
|
+
/**
|
|
267
|
+
* 手动挂载指定插件(支持按需加载)
|
|
268
|
+
* @description 如果插件依赖尚未挂载,会递归挂载所有依赖
|
|
269
|
+
* @param pluginId 插件 ID
|
|
270
|
+
*/
|
|
271
|
+
mountPlugin(pluginId: string): Promise<void>;
|
|
272
|
+
/**
|
|
273
|
+
* 初始化所有插件
|
|
274
|
+
* @param sharedContext 共享上下文
|
|
275
|
+
* @param autoMount 是否自动挂载所有插件 (默认为 false,启用按需加载模式)
|
|
276
|
+
*/
|
|
277
|
+
initPlugins(sharedContext?: Record<string, any>, autoMount?: boolean): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* 带重试机制的插件加载
|
|
280
|
+
*/
|
|
281
|
+
private loadPluginWithRetry;
|
|
282
|
+
/**
|
|
283
|
+
* 带重试机制的插件挂载
|
|
284
|
+
*/
|
|
285
|
+
private mountPluginWithRetry;
|
|
286
|
+
/**
|
|
287
|
+
* 获取排序后的插件 ID 列表 (处理依赖)
|
|
288
|
+
*/
|
|
289
|
+
private getSortedPluginIds;
|
|
290
|
+
/**
|
|
291
|
+
* 加载插件列表
|
|
292
|
+
* @param configs 插件配置
|
|
293
|
+
* @param registry 插件注册表 (动态导入函数)
|
|
294
|
+
* @param notify 是否在加载完成后触发通知,默认为 true
|
|
295
|
+
*/
|
|
296
|
+
loadPlugins(configs: Record<string, any>, registry: Record<string, () => Promise<any>>, notify?: boolean): Promise<void>;
|
|
297
|
+
/**
|
|
298
|
+
* 加载远程插件
|
|
299
|
+
* @param pluginId 插件 ID
|
|
300
|
+
* @param url 远程 URL
|
|
301
|
+
* @param config 插件配置
|
|
302
|
+
*/
|
|
303
|
+
loadRemotePlugin(pluginId: string, url: string, config: any): Promise<Plugin | null>;
|
|
304
|
+
/**
|
|
305
|
+
* IIFE 模式加载插件
|
|
306
|
+
*/
|
|
307
|
+
private loadIIFEPlugin;
|
|
308
|
+
/**
|
|
309
|
+
* 实例化插件
|
|
310
|
+
*/
|
|
311
|
+
private instantiatePlugin;
|
|
312
|
+
private validatePlugin;
|
|
313
|
+
private handleBusinessPlugin;
|
|
314
|
+
private handleFunctionalPlugin;
|
|
315
|
+
private handleViewPlugin;
|
|
316
|
+
private handleThemePlugin;
|
|
317
|
+
private handleRendererPlugin;
|
|
318
|
+
private handleSystemPlugin;
|
|
319
|
+
/**
|
|
320
|
+
* 注册插件默认配置
|
|
321
|
+
*/
|
|
322
|
+
private registerDefaultConfig;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* 全局插件管理器实例
|
|
326
|
+
*/
|
|
327
|
+
export declare const pluginManager: PluginManager;
|