@chatbi-v/core 2.0.4 → 2.0.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/adapters/local-storage-adapter.d.ts +48 -0
- package/dist/adapters/scoped-storage-adapter.d.ts +45 -2
- package/dist/api/adapters/axios-adapter.d.ts +1 -1
- package/dist/api/engine.d.ts +22 -1
- package/dist/application/service-registry.d.ts +36 -13
- package/dist/components/PluginErrorBoundary.d.ts +23 -1
- package/dist/components/PluginSlot.d.ts +18 -7
- package/dist/components/SlotSkeletons.d.ts +15 -0
- package/dist/config-manager.d.ts +14 -10
- package/dist/domain/auto-loader.d.ts +19 -4
- package/dist/domain/models.d.ts +19 -11
- package/dist/domain/plugin-manager.d.ts +100 -44
- package/dist/domain/plugin-runtime.d.ts +40 -9
- package/dist/domain/plugin-sandbox.d.ts +15 -2
- package/dist/domain/storage-manager.d.ts +38 -10
- package/dist/hooks/use-plugin-loader.d.ts +20 -9
- package/dist/index.cjs +5 -5
- package/dist/index.mjs +5 -5
- package/dist/ports/api-port.d.ts +55 -26
- package/dist/ports/event-bus-port.d.ts +13 -11
- package/dist/ports/plugin-port.d.ts +97 -22
- package/dist/ports/storage-port.d.ts +22 -4
- package/dist/utils/logger.d.ts +22 -12
- package/package.json +5 -3
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 事件总线端口接口
|
|
3
|
+
* @description 定义应用内部事件通信的标准契约,支持发布订阅模式。
|
|
3
4
|
*/
|
|
4
5
|
export interface EventBusPort {
|
|
5
6
|
/**
|
|
6
7
|
* 订阅事件
|
|
7
|
-
* @param event 事件名称
|
|
8
|
-
* @param callback
|
|
9
|
-
* @returns
|
|
8
|
+
* @param event - 事件名称
|
|
9
|
+
* @param callback - 事件触发时的回调函数
|
|
10
|
+
* @returns 取消订阅的函数
|
|
10
11
|
*/
|
|
11
12
|
on(event: string, callback: (...args: any[]) => any): () => void;
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @param event 事件名称
|
|
15
|
-
* @param callback
|
|
14
|
+
* 取消订阅事件
|
|
15
|
+
* @param event - 事件名称
|
|
16
|
+
* @param callback - 之前注册的回调函数
|
|
16
17
|
*/
|
|
17
18
|
off(event: string, callback: (...args: any[]) => any): void;
|
|
18
19
|
/**
|
|
19
|
-
* 触发事件
|
|
20
|
-
* @param event 事件名称
|
|
21
|
-
* @param args
|
|
20
|
+
* 触发事件 (发布)
|
|
21
|
+
* @param event - 事件名称
|
|
22
|
+
* @param args - 传递给回调函数的参数列表
|
|
22
23
|
*/
|
|
23
24
|
emit(event: string, ...args: any[]): void;
|
|
24
25
|
/**
|
|
25
26
|
* 订阅一次性事件
|
|
26
|
-
* @
|
|
27
|
-
* @param
|
|
27
|
+
* @description 事件触发一次后会自动取消订阅
|
|
28
|
+
* @param event - 事件名称
|
|
29
|
+
* @param callback - 事件触发时的回调函数
|
|
28
30
|
*/
|
|
29
31
|
once(event: string, callback: (...args: any[]) => any): void;
|
|
30
32
|
}
|
|
@@ -34,34 +34,55 @@ export declare const Slot: {
|
|
|
34
34
|
export type SlotType = typeof Slot[keyof typeof Slot];
|
|
35
35
|
export type SlotPosition = SlotType | string;
|
|
36
36
|
/**
|
|
37
|
-
* 插件扩展 (
|
|
37
|
+
* 插件扩展 (插槽注入配置)
|
|
38
38
|
*/
|
|
39
39
|
export interface PluginExtension {
|
|
40
|
+
/** 插槽位置标识符 */
|
|
40
41
|
slot: SlotPosition;
|
|
42
|
+
/** 要注入的 React 组件 */
|
|
41
43
|
component: React.ComponentType<any>;
|
|
44
|
+
/** 排序权重,数值越小越靠前 */
|
|
42
45
|
order?: number;
|
|
43
|
-
/** @internal 插件 ID
|
|
46
|
+
/** @internal 插件 ID,由系统在加载时自动注入,用于溯源 */
|
|
44
47
|
_pluginId?: string;
|
|
48
|
+
/** 扩展的元数据信息 */
|
|
45
49
|
meta?: {
|
|
50
|
+
/** 显示图标 */
|
|
46
51
|
icon?: React.ReactNode;
|
|
52
|
+
/** 显示标签文本 */
|
|
47
53
|
label?: string;
|
|
54
|
+
/** 详细描述 */
|
|
48
55
|
description?: string;
|
|
56
|
+
/** 唯一标识符,用于某些特定插槽的索引 */
|
|
49
57
|
key?: string;
|
|
58
|
+
/** 允许其他自定义属性 */
|
|
50
59
|
[key: string]: any;
|
|
51
60
|
};
|
|
52
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* 插件配置项定义
|
|
64
|
+
*/
|
|
53
65
|
export interface PluginConfigItem {
|
|
66
|
+
/** 配置键名 */
|
|
54
67
|
key: string;
|
|
68
|
+
/** 配置类型 */
|
|
55
69
|
type: 'string' | 'number' | 'boolean' | 'select';
|
|
70
|
+
/** 配置显示的标签 */
|
|
56
71
|
label: string;
|
|
72
|
+
/** 配置描述信息 */
|
|
57
73
|
description?: string;
|
|
74
|
+
/** 默认值 */
|
|
58
75
|
default?: any;
|
|
76
|
+
/** 当类型为 select 时的选项列表 */
|
|
59
77
|
options?: {
|
|
60
78
|
label: string;
|
|
61
79
|
value: any;
|
|
62
80
|
}[];
|
|
81
|
+
/** 选择模式:支持多选或标签模式 (AntD 风格) */
|
|
63
82
|
mode?: 'multiple' | 'tags';
|
|
83
|
+
/** 最小值 (针对 number 类型) */
|
|
64
84
|
min?: number;
|
|
85
|
+
/** 最大值 (针对 number 类型) */
|
|
65
86
|
max?: number;
|
|
66
87
|
}
|
|
67
88
|
/**
|
|
@@ -91,81 +112,122 @@ export interface PluginCapabilities {
|
|
|
91
112
|
background?: boolean;
|
|
92
113
|
[key: string]: boolean | undefined;
|
|
93
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* 存储项数据结构定义 (Schema)
|
|
117
|
+
*/
|
|
94
118
|
export interface StorageItemSchema {
|
|
119
|
+
/** 存储键名 */
|
|
95
120
|
key: string;
|
|
121
|
+
/** 数据类型 */
|
|
96
122
|
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
123
|
+
/** 默认值 */
|
|
97
124
|
default?: any;
|
|
125
|
+
/** 描述信息 */
|
|
98
126
|
description?: string;
|
|
127
|
+
/**
|
|
128
|
+
* 作用域
|
|
129
|
+
* @description 'plugin' 表示仅当前插件可见(带插件 ID 前缀),'shared' 表示全局共享
|
|
130
|
+
*/
|
|
99
131
|
scope?: 'plugin' | 'shared';
|
|
100
132
|
}
|
|
101
133
|
/**
|
|
102
134
|
* 插件生命周期 Hooks
|
|
135
|
+
* @description 插件可以在不同的生命周期阶段执行特定的逻辑
|
|
103
136
|
*/
|
|
104
137
|
export interface PluginLifecycle {
|
|
105
138
|
/**
|
|
106
139
|
* 插件加载时调用
|
|
107
|
-
* @description
|
|
140
|
+
* @description 在插件被扫描并注入内核时触发。用于初始化内部状态、注册服务、设置拦截器等。此时 UI 尚未挂载。
|
|
141
|
+
* @param context - 插件上下文对象,提供核心能力的访问
|
|
108
142
|
*/
|
|
109
143
|
onLoad?: (context: PluginContext) => void | Promise<void>;
|
|
110
144
|
/**
|
|
111
145
|
* 插件挂载到 UI 时调用
|
|
146
|
+
* @description 当插件的 UI 组件(如有)被 React 挂载到 DOM 时触发。
|
|
147
|
+
* @param context - 插件上下文对象
|
|
112
148
|
*/
|
|
113
149
|
onMount?: (context: PluginContext) => void;
|
|
114
150
|
/**
|
|
115
151
|
* 插件从 UI 卸载时调用
|
|
152
|
+
* @description 当插件的 UI 组件被销毁时触发。用于清理定时器、取消订阅等。
|
|
153
|
+
* @param context - 插件上下文对象
|
|
116
154
|
*/
|
|
117
155
|
onUnmount?: (context: PluginContext) => void;
|
|
118
156
|
/**
|
|
119
157
|
* 插件配置发生变化时调用
|
|
158
|
+
* @description 当用户通过配置中心修改插件设置时触发。
|
|
159
|
+
* @param newConfig - 变更后的新配置对象
|
|
160
|
+
* @param oldConfig - 变更前的旧配置对象
|
|
120
161
|
*/
|
|
121
162
|
onConfigChange?: (newConfig: any, oldConfig: any) => void;
|
|
122
163
|
}
|
|
123
164
|
/**
|
|
124
165
|
* 插件上下文
|
|
125
|
-
* @description
|
|
166
|
+
* @description 传递给插件生命周期钩子的核心对象,是插件访问宿主环境能力的唯一入口。
|
|
126
167
|
*/
|
|
127
168
|
export interface PluginContext {
|
|
169
|
+
/** 当前插件的唯一标识符 */
|
|
128
170
|
pluginId: string;
|
|
171
|
+
/** API 请求能力入口 */
|
|
129
172
|
api: any;
|
|
173
|
+
/** 事件总线能力入口 */
|
|
130
174
|
events: EventBusPort;
|
|
175
|
+
/** 存储管理能力入口 */
|
|
131
176
|
storage: {
|
|
177
|
+
/** 获取插件私有存储数据 */
|
|
132
178
|
get: <T = any>(key: string) => T | null;
|
|
179
|
+
/** 设置插件私有存储数据 */
|
|
133
180
|
set: <T = any>(key: string, value: T) => void;
|
|
181
|
+
/** 移除插件私有存储数据 */
|
|
134
182
|
remove: (key: string) => void;
|
|
183
|
+
/** 全局共享存储访问 */
|
|
135
184
|
shared: {
|
|
185
|
+
/** 获取全局共享存储数据 */
|
|
136
186
|
get: <T = any>(key: string) => T | null;
|
|
187
|
+
/** 设置全局共享存储数据 */
|
|
137
188
|
set: <T = any>(key: string, value: T) => void;
|
|
189
|
+
/** 移除全局共享存储数据 */
|
|
138
190
|
remove: (key: string) => void;
|
|
139
191
|
};
|
|
140
192
|
};
|
|
193
|
+
/** 日志输出工具,自动携带插件 ID 前缀 */
|
|
141
194
|
logger: {
|
|
142
195
|
debug: (...args: any[]) => void;
|
|
143
196
|
info: (...args: any[]) => void;
|
|
144
197
|
warn: (...args: any[]) => void;
|
|
145
198
|
error: (...args: any[]) => void;
|
|
146
199
|
};
|
|
147
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* 访问其他插件提供的服务
|
|
202
|
+
* @param serviceName - 服务注册名称
|
|
203
|
+
* @returns 服务实例,如果不存在则返回 undefined
|
|
204
|
+
*/
|
|
148
205
|
getService: <T = any>(serviceName: string) => T | undefined;
|
|
149
|
-
/**
|
|
206
|
+
/**
|
|
207
|
+
* 注册当前插件的服务供他人使用
|
|
208
|
+
* @param serviceName - 唯一服务名称
|
|
209
|
+
* @param service - 服务实现对象
|
|
210
|
+
*/
|
|
150
211
|
registerService: (serviceName: string, service: any) => void;
|
|
151
|
-
/** 宿主环境 Window (
|
|
212
|
+
/** 宿主环境 Window 的代理对象 (用于沙箱隔离) */
|
|
152
213
|
window: WindowProxy;
|
|
153
214
|
}
|
|
154
215
|
/**
|
|
155
|
-
*
|
|
216
|
+
* 完整的插件对象定义
|
|
156
217
|
*/
|
|
157
218
|
export interface Plugin extends PluginLifecycle {
|
|
158
219
|
/**
|
|
159
|
-
*
|
|
160
|
-
* @description 必须与 metadata.id
|
|
220
|
+
* 插件唯一标识符
|
|
221
|
+
* @description 必须与 metadata.id 一致,通常为只读。
|
|
161
222
|
*/
|
|
162
223
|
readonly id: string;
|
|
224
|
+
/** 插件元数据配置 */
|
|
163
225
|
metadata: PluginMetadata;
|
|
164
|
-
/**
|
|
226
|
+
/** 插件提供的功能组件集合 (可选) */
|
|
165
227
|
components?: Record<string, React.ComponentType<any>>;
|
|
166
|
-
/**
|
|
228
|
+
/** 插件提供的工具函数集合 (可选) */
|
|
167
229
|
utils?: Record<string, any>;
|
|
168
|
-
/**
|
|
230
|
+
/** 插件的初始默认配置 (可选) */
|
|
169
231
|
defaultConfig?: Record<string, any>;
|
|
170
232
|
}
|
|
171
233
|
/**
|
|
@@ -192,36 +254,49 @@ export declare abstract class BasePlugin implements Plugin {
|
|
|
192
254
|
* @returns 完整的插件对象
|
|
193
255
|
*/
|
|
194
256
|
export declare function definePlugin(plugin: Omit<Plugin, 'id'>): Plugin;
|
|
257
|
+
/**
|
|
258
|
+
* 插件元数据定义
|
|
259
|
+
* @description 描述插件的静态属性,用于插件市场展示、权限校验和内核加载参考。
|
|
260
|
+
*/
|
|
195
261
|
export interface PluginMetadata {
|
|
262
|
+
/** 插件唯一 ID (推荐反向域名格式,如 com.company.plugin) */
|
|
196
263
|
id: string;
|
|
264
|
+
/** 插件显示名称 */
|
|
197
265
|
name: string;
|
|
266
|
+
/** 插件版本号 (符合 SemVer 规范) */
|
|
198
267
|
version: string;
|
|
268
|
+
/** 插件类型 */
|
|
199
269
|
type: PluginType;
|
|
270
|
+
/** 插件功能描述 */
|
|
200
271
|
description?: string;
|
|
272
|
+
/** 插件作者信息 */
|
|
201
273
|
author?: string;
|
|
274
|
+
/** 插件图标 (React 组件或图标名称) */
|
|
202
275
|
icon?: React.ReactNode;
|
|
203
276
|
/** 插件依赖的其他插件 ID 列表 */
|
|
204
277
|
dependencies?: string[];
|
|
205
|
-
/**
|
|
278
|
+
/** 路由配置集合,用于在主应用中注册页面 */
|
|
206
279
|
routes?: RouteConfig[];
|
|
207
|
-
/**
|
|
280
|
+
/** 插槽扩展集合,用于在主应用 UI 预留位注入组件 */
|
|
208
281
|
extensions?: PluginExtension[];
|
|
209
|
-
/** API
|
|
282
|
+
/** 插件所需调用的 API 接口配置 */
|
|
210
283
|
api?: ApiConfig;
|
|
211
|
-
/**
|
|
284
|
+
/** 插件行为能力声明 */
|
|
212
285
|
capabilities?: PluginCapabilities;
|
|
213
|
-
/**
|
|
286
|
+
/** 插件的可配置项定义 */
|
|
214
287
|
configuration?: PluginConfigItem[];
|
|
215
|
-
/**
|
|
288
|
+
/** 插件所需的存储结构定义 */
|
|
216
289
|
storage?: StorageItemSchema[];
|
|
217
290
|
/**
|
|
218
|
-
*
|
|
219
|
-
* @description
|
|
291
|
+
* 系统状态自动绑定
|
|
292
|
+
* @description 将插件的配置项自动同步到系统的全局状态中 (如主题色、身份认证等)
|
|
220
293
|
*/
|
|
221
294
|
systemStateBindings?: {
|
|
295
|
+
/** 插件配置中的键名 */
|
|
222
296
|
configKey: string;
|
|
297
|
+
/** 系统全局状态中的键名 */
|
|
223
298
|
stateKey: string;
|
|
224
|
-
/**
|
|
299
|
+
/** 预设的转换逻辑名称 */
|
|
225
300
|
transform?: 'theme-mode' | 'identity';
|
|
226
301
|
}[];
|
|
227
302
|
}
|
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 存储端口接口
|
|
3
|
-
* @description
|
|
3
|
+
* @description 定义数据持久化的标准契约,兼容 Web Storage API。
|
|
4
4
|
*/
|
|
5
5
|
export interface StoragePort {
|
|
6
|
+
/**
|
|
7
|
+
* 获取存储项
|
|
8
|
+
* @param key - 键名
|
|
9
|
+
* @returns 对应的值,如果不存在则返回 null
|
|
10
|
+
*/
|
|
6
11
|
getItem(key: string): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* 设置存储项
|
|
14
|
+
* @param key - 键名
|
|
15
|
+
* @param value - 键值 (字符串)
|
|
16
|
+
*/
|
|
7
17
|
setItem(key: string, value: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* 移除指定的存储项
|
|
20
|
+
* @param key - 键名
|
|
21
|
+
*/
|
|
8
22
|
removeItem(key: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* 清空所有存储项
|
|
25
|
+
*/
|
|
9
26
|
clear(): void;
|
|
10
27
|
/**
|
|
11
|
-
*
|
|
28
|
+
* 返回存储对象中当前存储的数据项总数
|
|
12
29
|
*/
|
|
13
30
|
readonly length: number;
|
|
14
31
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param index
|
|
32
|
+
* 根据索引返回存储中对应键的名称
|
|
33
|
+
* @param index - 数值索引
|
|
34
|
+
* @returns 键名,如果索引超出范围则返回 null
|
|
17
35
|
*/
|
|
18
36
|
key(index: number): string | null;
|
|
19
37
|
}
|
package/dist/utils/logger.d.ts
CHANGED
|
@@ -2,60 +2,70 @@
|
|
|
2
2
|
* 日志等级枚举
|
|
3
3
|
*/
|
|
4
4
|
export declare enum LogLevel {
|
|
5
|
+
/** 调试级别:输出最详尽的信息 */
|
|
5
6
|
DEBUG = 0,
|
|
7
|
+
/** 信息级别:输出重要的运行状态 */
|
|
6
8
|
INFO = 1,
|
|
9
|
+
/** 警告级别:输出潜在的问题,但不影响运行 */
|
|
7
10
|
WARN = 2,
|
|
11
|
+
/** 错误级别:输出严重的运行异常 */
|
|
8
12
|
ERROR = 3,
|
|
13
|
+
/** 禁用日志:不输出任何信息 */
|
|
9
14
|
NONE = 4
|
|
10
15
|
}
|
|
11
16
|
/**
|
|
12
17
|
* 日志工具类
|
|
13
|
-
* @description
|
|
18
|
+
* @description 核心工具类,提供统一的日志输出格式 `[Prefix] Message`。
|
|
19
|
+
* 支持通过 `LogLevel` 进行全局过滤,在生产环境下建议设置为 WARN 或以上。
|
|
14
20
|
*/
|
|
15
21
|
export declare class Logger {
|
|
16
|
-
/**
|
|
22
|
+
/** 全局静态日志等级,所有实例共享 */
|
|
17
23
|
private static level;
|
|
18
|
-
/**
|
|
24
|
+
/** 当前实例的业务模块前缀 */
|
|
19
25
|
private prefix;
|
|
20
26
|
/**
|
|
21
27
|
* 构造函数
|
|
22
|
-
* @param prefix
|
|
28
|
+
* @param prefix - 业务模块前缀,默认为 'App'
|
|
23
29
|
*/
|
|
24
30
|
constructor(prefix?: string);
|
|
25
31
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @param level
|
|
32
|
+
* 静态方法:设置全局日志输出等级
|
|
33
|
+
* @param level - 目标日志等级
|
|
28
34
|
*/
|
|
29
35
|
static setLevel(level: LogLevel): void;
|
|
30
36
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @returns
|
|
37
|
+
* 静态方法:获取当前全局日志等级
|
|
38
|
+
* @returns 当前生效的全局日志等级
|
|
33
39
|
*/
|
|
34
40
|
static getLevel(): LogLevel;
|
|
35
41
|
/**
|
|
36
42
|
* 打印 DEBUG 级别日志
|
|
43
|
+
* @description 仅在 LogLevel <= DEBUG 时输出
|
|
37
44
|
*/
|
|
38
45
|
get debug(): (...args: any[]) => void;
|
|
39
46
|
/**
|
|
40
47
|
* 打印 INFO 级别日志
|
|
48
|
+
* @description 仅在 LogLevel <= INFO 时输出
|
|
41
49
|
*/
|
|
42
50
|
get info(): (...args: any[]) => void;
|
|
43
51
|
/**
|
|
44
52
|
* 打印 WARN 级别日志
|
|
53
|
+
* @description 仅在 LogLevel <= WARN 时输出
|
|
45
54
|
*/
|
|
46
55
|
get warn(): (...args: any[]) => void;
|
|
47
56
|
/**
|
|
48
57
|
* 打印 ERROR 级别日志
|
|
58
|
+
* @description 仅在 LogLevel <= ERROR 时输出
|
|
49
59
|
*/
|
|
50
60
|
get error(): (...args: any[]) => void;
|
|
51
61
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @param label
|
|
54
|
-
* @param collapsed
|
|
62
|
+
* 开始一个日志控制台分组
|
|
63
|
+
* @param label - 分组显示的标签名
|
|
64
|
+
* @param collapsed - 是否默认折叠显示,默认为 false
|
|
55
65
|
*/
|
|
56
66
|
group(label: string, collapsed?: boolean): void;
|
|
57
67
|
/**
|
|
58
|
-
*
|
|
68
|
+
* 结束当前日志控制台分组
|
|
59
69
|
*/
|
|
60
70
|
get groupEnd(): () => void;
|
|
61
71
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatbi-v/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"main": "dist/index.cjs",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -26,10 +26,12 @@
|
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {},
|
|
28
28
|
"devDependencies": {
|
|
29
|
+
"@types/react": "^18.3.1",
|
|
30
|
+
"@types/react-dom": "^18.3.0",
|
|
29
31
|
"tsup": "^8.5.1",
|
|
30
32
|
"vite": "^5.4.21",
|
|
31
|
-
"@chatbi-v/
|
|
32
|
-
"@chatbi-v/
|
|
33
|
+
"@chatbi-v/cli": "2.0.5",
|
|
34
|
+
"@chatbi-v/tsconfig": "2.0.5"
|
|
33
35
|
},
|
|
34
36
|
"scripts": {
|
|
35
37
|
"build": "chatbi-cli build",
|