@chatbi-v/core 2.1.0 → 2.1.2
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/chunk-QET56C3T.mjs +51 -0
- package/dist/chunk-QET56C3T.mjs.map +1 -0
- package/dist/config-manager-3TKURRUT.mjs +9 -0
- package/dist/config-manager-3TKURRUT.mjs.map +1 -0
- package/dist/index.d.mts +1748 -0
- package/dist/index.d.ts +1745 -27
- package/dist/index.js +2833 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2685 -7
- package/dist/index.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/adapters/local-storage-adapter.d.ts +0 -61
- package/dist/adapters/scoped-storage-adapter.d.ts +0 -61
- package/dist/api/adapters/axios-adapter.d.ts +0 -10
- package/dist/api/engine.d.ts +0 -87
- package/dist/api/index.d.ts +0 -6
- package/dist/api/utils.d.ts +0 -14
- package/dist/api-context.d.ts +0 -8
- package/dist/application/service-registry.d.ts +0 -57
- package/dist/chunk-O74KYN5N.mjs +0 -1
- package/dist/components/PluginErrorBoundary.d.ts +0 -44
- package/dist/components/PluginSlot.d.ts +0 -35
- package/dist/components/SlotSkeletons.d.ts +0 -27
- package/dist/config-manager-LQITPSUA.mjs +0 -1
- package/dist/config-manager.d.ts +0 -34
- package/dist/domain/auto-loader.d.ts +0 -36
- package/dist/domain/models.d.ts +0 -42
- package/dist/domain/plugin-manager.d.ts +0 -215
- package/dist/domain/plugin-runtime.d.ts +0 -70
- package/dist/domain/plugin-sandbox.d.ts +0 -40
- package/dist/domain/storage-manager.d.ts +0 -74
- package/dist/event-bus.d.ts +0 -38
- package/dist/hooks/use-plugin-loader.d.ts +0 -35
- package/dist/hooks/use-storage-state.d.ts +0 -15
- package/dist/index.cjs +0 -12
- package/dist/plugin-context.d.ts +0 -8
- package/dist/ports/api-port.d.ts +0 -132
- package/dist/ports/event-bus-port.d.ts +0 -32
- package/dist/ports/plugin-port.d.ts +0 -308
- package/dist/ports/storage-port.d.ts +0 -49
- package/dist/sandbox/proxy-sandbox.d.ts +0 -45
- package/dist/sandbox/style-isolation.d.ts +0 -13
- package/dist/utils/date.d.ts +0 -32
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/logger.d.ts +0 -79
- package/dist/utils/url.d.ts +0 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,1748 @@
|
|
|
1
|
+
import React, { Component, ReactNode, ErrorInfo } from 'react';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
6
|
+
* HTTP 请求方法
|
|
7
|
+
*/
|
|
8
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
9
|
+
/**
|
|
10
|
+
* 错误处理策略
|
|
11
|
+
*/
|
|
12
|
+
type ErrorStrategy = 'reject' | 'resolve' | 'silent';
|
|
13
|
+
/**
|
|
14
|
+
* API 接口端点配置
|
|
15
|
+
*/
|
|
16
|
+
interface ApiEndpointConfig {
|
|
17
|
+
/** 接口路径 (支持 :param 语法) */
|
|
18
|
+
url: string;
|
|
19
|
+
/** 请求方法 */
|
|
20
|
+
method: HttpMethod;
|
|
21
|
+
/** 接口描述 */
|
|
22
|
+
desc?: string;
|
|
23
|
+
/** Mock 响应数据结构定义 */
|
|
24
|
+
responseSchema?: any;
|
|
25
|
+
/** 错误处理策略 */
|
|
26
|
+
errorStrategy?: ErrorStrategy;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* API 请求配置
|
|
30
|
+
*/
|
|
31
|
+
interface ApiRequestConfig {
|
|
32
|
+
/** 请求 URL */
|
|
33
|
+
url: string;
|
|
34
|
+
/** 请求方法 */
|
|
35
|
+
method: HttpMethod;
|
|
36
|
+
/** 请求体数据 (POST/PUT 等) */
|
|
37
|
+
data?: any;
|
|
38
|
+
/** 查询参数 (GET 等) */
|
|
39
|
+
params?: any;
|
|
40
|
+
/** 请求头 */
|
|
41
|
+
headers?: any;
|
|
42
|
+
/** 用于取消请求的信号对象 */
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 流式响应回调函数接口
|
|
47
|
+
*/
|
|
48
|
+
interface StreamCallbacks {
|
|
49
|
+
/** 收到消息片段时的回调 */
|
|
50
|
+
onMessage?: (data: any) => void;
|
|
51
|
+
/** 发生错误时的回调 */
|
|
52
|
+
onError?: (error: any) => void;
|
|
53
|
+
/** 请求完成时的回调 */
|
|
54
|
+
onFinish?: () => void;
|
|
55
|
+
/** 收到 HTTP 响应头部信息的回调,返回 true 表示劫持并中止流 */
|
|
56
|
+
onResponse?: (response: any) => Promise<boolean> | boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* API 适配器端口接口
|
|
60
|
+
* @description 所有底层请求引擎(如 Fetch, Axios, Mock)都必须实现此接口,以确保内核对具体通信库的解耦。
|
|
61
|
+
*/
|
|
62
|
+
interface ApiAdapter {
|
|
63
|
+
/**
|
|
64
|
+
* 发起普通 HTTP 请求
|
|
65
|
+
* @param config - 请求配置
|
|
66
|
+
* @param endpointConfig - 接口端点定义的元数据配置
|
|
67
|
+
* @returns 响应数据的 Promise
|
|
68
|
+
*/
|
|
69
|
+
request<T = any>(config: ApiRequestConfig, endpointConfig?: ApiEndpointConfig): Promise<T>;
|
|
70
|
+
/**
|
|
71
|
+
* 发起流式请求 (SSE 或 Chunked Transfer)
|
|
72
|
+
* @param config - 请求配置
|
|
73
|
+
* @param callbacks - 流式处理的回调函数集合
|
|
74
|
+
* @param endpointConfig - 接口端点定义的元数据配置
|
|
75
|
+
*/
|
|
76
|
+
stream?(config: ApiRequestConfig, callbacks: StreamCallbacks, endpointConfig?: ApiEndpointConfig): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* API 配置集合 (按模块和动作分组)
|
|
80
|
+
*/
|
|
81
|
+
interface ApiConfig {
|
|
82
|
+
/** 模块名称 */
|
|
83
|
+
[module: string]: {
|
|
84
|
+
/** 动作/接口名称 */
|
|
85
|
+
[action: string]: ApiEndpointConfig;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 业务侧发起请求时的选项
|
|
90
|
+
*/
|
|
91
|
+
interface RequestOptions extends Partial<ApiRequestConfig> {
|
|
92
|
+
/** 是否跳过全局错误处理逻辑 */
|
|
93
|
+
skipErrorHandler?: boolean;
|
|
94
|
+
/** 路径参数集合 (将替换 url 中的 :param 占位符) */
|
|
95
|
+
params?: any;
|
|
96
|
+
/** 流式响应:收到数据片段的回调 */
|
|
97
|
+
onMessage?: (data: any) => void;
|
|
98
|
+
/** 流式响应:发生错误的回调 */
|
|
99
|
+
onError?: (error: any) => void;
|
|
100
|
+
/** 流式响应:正常结束的回调 */
|
|
101
|
+
onFinish?: () => void;
|
|
102
|
+
/** 允许透传其他底层适配器所需的属性 (例如 axios 的特定配置) */
|
|
103
|
+
[key: string]: any;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* API 响应拦截上下文对象
|
|
107
|
+
*/
|
|
108
|
+
interface ApiResponseContext {
|
|
109
|
+
/** 原始响应对象 (例如 AxiosResponse 或 Fetch Response) */
|
|
110
|
+
response: any;
|
|
111
|
+
/** HTTP 响应状态码 */
|
|
112
|
+
status: number;
|
|
113
|
+
/** 响应头集合 */
|
|
114
|
+
headers: Record<string, string>;
|
|
115
|
+
/** 解析后的业务数据体 */
|
|
116
|
+
data: any;
|
|
117
|
+
/** 对应的原始请求配置 */
|
|
118
|
+
config: ApiRequestConfig;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* API 拦截器定义
|
|
122
|
+
*/
|
|
123
|
+
interface ApiInterceptor {
|
|
124
|
+
/**
|
|
125
|
+
* 请求发送前的拦截逻辑
|
|
126
|
+
* @param config - 原始请求配置
|
|
127
|
+
* @returns 修改后的请求配置,或其 Promise
|
|
128
|
+
*/
|
|
129
|
+
interceptRequest?: (config: ApiRequestConfig) => ApiRequestConfig | Promise<ApiRequestConfig>;
|
|
130
|
+
/**
|
|
131
|
+
* 响应接收后的拦截逻辑
|
|
132
|
+
* @param context - 响应上下文信息
|
|
133
|
+
* @returns 如果返回 true,表示该拦截器已接管并处理了响应,后续拦截器及业务回调将不再触发
|
|
134
|
+
*/
|
|
135
|
+
interceptResponse?: (context: ApiResponseContext) => boolean | Promise<boolean>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 事件总线端口接口
|
|
140
|
+
* @description 定义应用内部事件通信的标准契约,支持发布订阅模式。
|
|
141
|
+
*/
|
|
142
|
+
interface EventBusPort {
|
|
143
|
+
/**
|
|
144
|
+
* 订阅事件
|
|
145
|
+
* @param event - 事件名称
|
|
146
|
+
* @param callback - 事件触发时的回调函数
|
|
147
|
+
* @returns 取消订阅的函数
|
|
148
|
+
*/
|
|
149
|
+
on(event: string, callback: (...args: any[]) => any): () => void;
|
|
150
|
+
/**
|
|
151
|
+
* 取消订阅事件
|
|
152
|
+
* @param event - 事件名称
|
|
153
|
+
* @param callback - 之前注册的回调函数
|
|
154
|
+
*/
|
|
155
|
+
off(event: string, callback: (...args: any[]) => any): void;
|
|
156
|
+
/**
|
|
157
|
+
* 触发事件 (发布)
|
|
158
|
+
* @param event - 事件名称
|
|
159
|
+
* @param args - 传递给回调函数的参数列表
|
|
160
|
+
*/
|
|
161
|
+
emit(event: string, ...args: any[]): void;
|
|
162
|
+
/**
|
|
163
|
+
* 订阅一次性事件
|
|
164
|
+
* @description 事件触发一次后会自动取消订阅
|
|
165
|
+
* @param event - 事件名称
|
|
166
|
+
* @param callback - 事件触发时的回调函数
|
|
167
|
+
*/
|
|
168
|
+
once(event: string, callback: (...args: any[]) => any): void;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 存储端口接口
|
|
173
|
+
* @description 定义数据持久化的标准契约,兼容 Web Storage API。
|
|
174
|
+
*/
|
|
175
|
+
interface StoragePort {
|
|
176
|
+
/**
|
|
177
|
+
* 获取存储项
|
|
178
|
+
* @param key - 键名
|
|
179
|
+
* @returns 对应的值,如果不存在则返回 null
|
|
180
|
+
*/
|
|
181
|
+
getItem(key: string): string | null;
|
|
182
|
+
/**
|
|
183
|
+
* 设置存储项
|
|
184
|
+
* @param key - 键名
|
|
185
|
+
* @param value - 键值 (字符串)
|
|
186
|
+
*/
|
|
187
|
+
setItem(key: string, value: string): void;
|
|
188
|
+
/**
|
|
189
|
+
* 移除指定的存储项
|
|
190
|
+
* @param key - 键名
|
|
191
|
+
*/
|
|
192
|
+
removeItem(key: string): void;
|
|
193
|
+
/**
|
|
194
|
+
* 清空所有存储项
|
|
195
|
+
*/
|
|
196
|
+
clear(): void;
|
|
197
|
+
/**
|
|
198
|
+
* 返回存储对象中当前存储的数据项总数
|
|
199
|
+
*/
|
|
200
|
+
readonly length: number;
|
|
201
|
+
/**
|
|
202
|
+
* 根据索引返回存储中对应键的名称
|
|
203
|
+
* @param index - 数值索引
|
|
204
|
+
* @returns 键名,如果索引超出范围则返回 null
|
|
205
|
+
*/
|
|
206
|
+
key(index: number): string | null;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 类型化存储接口
|
|
210
|
+
* @description 提供泛型支持的存储访问能力,自动处理序列化
|
|
211
|
+
*/
|
|
212
|
+
interface TypedStorage {
|
|
213
|
+
/** 获取存储数据 */
|
|
214
|
+
get: <T = any>(key: string) => T | null;
|
|
215
|
+
/** 设置存储数据 */
|
|
216
|
+
set: <T = any>(key: string, value: T) => void;
|
|
217
|
+
/** 移除存储数据 */
|
|
218
|
+
remove: (key: string) => void;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 插件类型定义
|
|
223
|
+
*/
|
|
224
|
+
declare const PLUGIN_TYPES: readonly ["business", "functional", "view", "theme", "renderer", "system"];
|
|
225
|
+
type PluginType = typeof PLUGIN_TYPES[number];
|
|
226
|
+
/**
|
|
227
|
+
* 路由配置
|
|
228
|
+
*/
|
|
229
|
+
interface RouteConfig {
|
|
230
|
+
path: string;
|
|
231
|
+
component: React.ComponentType<any>;
|
|
232
|
+
meta?: Record<string, any>;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* 插件插槽位置
|
|
236
|
+
* @description 定义插件可以注入 UI 的标准位置
|
|
237
|
+
*/
|
|
238
|
+
declare const Slot: {
|
|
239
|
+
readonly Sidebar: "sidebar";
|
|
240
|
+
readonly SidebarPanel: "sidebar-panel";
|
|
241
|
+
readonly Header: "header";
|
|
242
|
+
readonly StatusBar: "status-bar";
|
|
243
|
+
readonly Settings: "settings";
|
|
244
|
+
readonly MessageRenderer: "message-renderer";
|
|
245
|
+
readonly MessageContentRenderer: "message-content-renderer";
|
|
246
|
+
readonly SidebarSystem: "sidebar-system";
|
|
247
|
+
readonly SidebarBottom: "sidebar-bottom";
|
|
248
|
+
readonly RootLayout: "root-layout";
|
|
249
|
+
readonly Custom: "custom";
|
|
250
|
+
};
|
|
251
|
+
type SlotType = typeof Slot[keyof typeof Slot];
|
|
252
|
+
type SlotPosition = SlotType | string;
|
|
253
|
+
/**
|
|
254
|
+
* 插件扩展 (插槽注入配置)
|
|
255
|
+
*/
|
|
256
|
+
interface PluginExtension {
|
|
257
|
+
/** 插槽位置标识符 */
|
|
258
|
+
slot: SlotPosition;
|
|
259
|
+
/** 要注入的 React 组件 */
|
|
260
|
+
component: React.ComponentType<any>;
|
|
261
|
+
/** 排序权重,数值越小越靠前 */
|
|
262
|
+
order?: number;
|
|
263
|
+
/** @internal 插件 ID,由系统在加载时自动注入,用于溯源 */
|
|
264
|
+
_pluginId?: string;
|
|
265
|
+
/** 扩展的元数据信息 */
|
|
266
|
+
meta?: {
|
|
267
|
+
/** 显示图标 */
|
|
268
|
+
icon?: React.ReactNode;
|
|
269
|
+
/** 显示标签文本 */
|
|
270
|
+
label?: string;
|
|
271
|
+
/** 详细描述 */
|
|
272
|
+
description?: string;
|
|
273
|
+
/** 唯一标识符,用于某些特定插槽的索引 */
|
|
274
|
+
key?: string;
|
|
275
|
+
/** 允许其他自定义属性 */
|
|
276
|
+
[key: string]: any;
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* 插件配置项定义
|
|
281
|
+
*/
|
|
282
|
+
interface PluginConfigItem {
|
|
283
|
+
/** 配置键名 */
|
|
284
|
+
key: string;
|
|
285
|
+
/** 配置类型 */
|
|
286
|
+
type: 'string' | 'number' | 'boolean' | 'select';
|
|
287
|
+
/** 配置显示的标签 */
|
|
288
|
+
label: string;
|
|
289
|
+
/** 配置描述信息 */
|
|
290
|
+
description?: string;
|
|
291
|
+
/** 默认值 */
|
|
292
|
+
default?: any;
|
|
293
|
+
/** 当类型为 select 时的选项列表 */
|
|
294
|
+
options?: {
|
|
295
|
+
label: string;
|
|
296
|
+
value: any;
|
|
297
|
+
}[];
|
|
298
|
+
/** 选择模式:支持多选或标签模式 (AntD 风格) */
|
|
299
|
+
mode?: 'multiple' | 'tags';
|
|
300
|
+
/** 最小值 (针对 number 类型) */
|
|
301
|
+
min?: number;
|
|
302
|
+
/** 最大值 (针对 number 类型) */
|
|
303
|
+
max?: number;
|
|
304
|
+
/**
|
|
305
|
+
* 是否为私有配置
|
|
306
|
+
* @description 如果为 true,则该配置不会通过自动配置服务暴露给其他插件
|
|
307
|
+
* @default false
|
|
308
|
+
*/
|
|
309
|
+
private?: boolean;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* 插件能力定义 (Behavioral Capabilities)
|
|
313
|
+
* @description 定义插件的行为特征。注意:路由(routes)和扩展(extensions)属于结构化能力,直接通过 metadata 字段声明,不在此列。
|
|
314
|
+
*/
|
|
315
|
+
interface PluginCapabilities {
|
|
316
|
+
/**
|
|
317
|
+
* 是否支持配置设置
|
|
318
|
+
* @default false (如果 metadata.configuration 存在,则可能被隐式视为 true,建议显式声明)
|
|
319
|
+
*/
|
|
320
|
+
configurable?: boolean;
|
|
321
|
+
/**
|
|
322
|
+
* 是否可嵌入其他页面
|
|
323
|
+
* @description 声明该插件是否可以作为 Widget 被其他插件引用
|
|
324
|
+
*/
|
|
325
|
+
embeddable?: boolean;
|
|
326
|
+
/**
|
|
327
|
+
* 是否支持多实例
|
|
328
|
+
* @description 默认为 false (单例)。如果在聊天窗口中每个会话都需要独立状态,则设为 true
|
|
329
|
+
*/
|
|
330
|
+
multiInstance?: boolean;
|
|
331
|
+
/**
|
|
332
|
+
* 是否需要后台运行
|
|
333
|
+
* @description 如果为 true,即使 UI 不可见,插件也不会被卸载
|
|
334
|
+
*/
|
|
335
|
+
background?: boolean;
|
|
336
|
+
[key: string]: boolean | undefined;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* 存储项数据结构定义 (Schema)
|
|
340
|
+
*/
|
|
341
|
+
interface StorageItemSchema {
|
|
342
|
+
/** 存储键名 */
|
|
343
|
+
key: string;
|
|
344
|
+
/** 数据类型 */
|
|
345
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
346
|
+
/** 默认值 */
|
|
347
|
+
default?: any;
|
|
348
|
+
/** 描述信息 */
|
|
349
|
+
description?: string;
|
|
350
|
+
/**
|
|
351
|
+
* 作用域
|
|
352
|
+
* @description 'plugin' 表示仅当前插件可见(带插件 ID 前缀),'shared' 表示全局共享
|
|
353
|
+
*/
|
|
354
|
+
scope?: 'plugin' | 'shared';
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* 插件存储接口
|
|
358
|
+
* @description 包含私有存储和共享存储访问能力
|
|
359
|
+
*/
|
|
360
|
+
interface PluginStorage extends TypedStorage {
|
|
361
|
+
/** 获取插件私有存储数据 */
|
|
362
|
+
get: TypedStorage['get'];
|
|
363
|
+
/** 设置插件私有存储数据 */
|
|
364
|
+
set: TypedStorage['set'];
|
|
365
|
+
/** 移除插件私有存储数据 */
|
|
366
|
+
remove: TypedStorage['remove'];
|
|
367
|
+
/** 全局共享存储访问 */
|
|
368
|
+
shared: TypedStorage & {
|
|
369
|
+
/** 获取全局共享存储数据 */
|
|
370
|
+
get: TypedStorage['get'];
|
|
371
|
+
/** 设置全局共享存储数据 */
|
|
372
|
+
set: TypedStorage['set'];
|
|
373
|
+
/** 移除全局共享存储数据 */
|
|
374
|
+
remove: TypedStorage['remove'];
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* 插件生命周期 Hooks
|
|
379
|
+
* @description 插件可以在不同的生命周期阶段执行特定的逻辑
|
|
380
|
+
*/
|
|
381
|
+
interface PluginLifecycle {
|
|
382
|
+
/**
|
|
383
|
+
* 插件加载时调用
|
|
384
|
+
* @description 在插件被扫描并注入内核时触发。用于初始化内部状态、注册服务、设置拦截器等。此时 UI 尚未挂载。
|
|
385
|
+
* @param context - 插件上下文对象,提供核心能力的访问
|
|
386
|
+
*/
|
|
387
|
+
onLoad?: (context: PluginContext) => void | Promise<void>;
|
|
388
|
+
/**
|
|
389
|
+
* 插件挂载到 UI 时调用
|
|
390
|
+
* @description 当插件的 UI 组件(如有)被 React 挂载到 DOM 时触发。
|
|
391
|
+
* @param context - 插件上下文对象
|
|
392
|
+
*/
|
|
393
|
+
onMount?: (context: PluginContext) => void;
|
|
394
|
+
/**
|
|
395
|
+
* 插件从 UI 卸载时调用
|
|
396
|
+
* @description 当插件的 UI 组件被销毁时触发。用于清理定时器、取消订阅等。
|
|
397
|
+
* @param context - 插件上下文对象
|
|
398
|
+
*/
|
|
399
|
+
onUnmount?: (context: PluginContext) => void;
|
|
400
|
+
/**
|
|
401
|
+
* 插件配置发生变化时调用
|
|
402
|
+
* @description 当用户通过配置中心修改插件设置时触发。
|
|
403
|
+
* @param newConfig - 变更后的新配置对象
|
|
404
|
+
* @param oldConfig - 变更前的旧配置对象
|
|
405
|
+
*/
|
|
406
|
+
onConfigChange?: (newConfig: any, oldConfig: any) => void;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* 插件上下文
|
|
410
|
+
* @description 传递给插件生命周期钩子的核心对象,是插件访问宿主环境能力的唯一入口。
|
|
411
|
+
*/
|
|
412
|
+
interface PluginContext {
|
|
413
|
+
/** 当前插件的唯一标识符 */
|
|
414
|
+
pluginId: string;
|
|
415
|
+
/** API 请求能力入口 */
|
|
416
|
+
api: any;
|
|
417
|
+
/** 事件总线能力入口 */
|
|
418
|
+
events: EventBusPort;
|
|
419
|
+
/** 存储管理能力入口 */
|
|
420
|
+
storage: PluginStorage;
|
|
421
|
+
/** 日志输出工具,自动携带插件 ID 前缀 */
|
|
422
|
+
logger: {
|
|
423
|
+
debug: (...args: any[]) => void;
|
|
424
|
+
info: (...args: any[]) => void;
|
|
425
|
+
warn: (...args: any[]) => void;
|
|
426
|
+
error: (...args: any[]) => void;
|
|
427
|
+
};
|
|
428
|
+
/**
|
|
429
|
+
* 访问其他插件提供的服务
|
|
430
|
+
* @param serviceName - 服务注册名称
|
|
431
|
+
* @returns 服务实例,如果不存在则返回 undefined
|
|
432
|
+
*/
|
|
433
|
+
getService: <T = any>(serviceName: string) => T | undefined;
|
|
434
|
+
/**
|
|
435
|
+
* 注册当前插件的服务供他人使用
|
|
436
|
+
* @param serviceName - 唯一服务名称
|
|
437
|
+
* @param service - 服务实现对象
|
|
438
|
+
*/
|
|
439
|
+
registerService: (serviceName: string, service: any) => void;
|
|
440
|
+
/** 宿主环境 Window 的代理对象 (用于沙箱隔离) */
|
|
441
|
+
window: WindowProxy;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* 完整的插件对象定义
|
|
445
|
+
*/
|
|
446
|
+
interface Plugin extends PluginLifecycle {
|
|
447
|
+
/**
|
|
448
|
+
* 插件唯一标识符
|
|
449
|
+
* @description 必须与 metadata.id 一致,通常为只读。
|
|
450
|
+
*/
|
|
451
|
+
readonly id: string;
|
|
452
|
+
/** 插件元数据配置 */
|
|
453
|
+
metadata: PluginMetadata;
|
|
454
|
+
/** 插件提供的功能组件集合 (可选) */
|
|
455
|
+
components?: Record<string, React.ComponentType<any>>;
|
|
456
|
+
/** 插件提供的工具函数集合 (可选) */
|
|
457
|
+
utils?: Record<string, any>;
|
|
458
|
+
/** 插件的初始默认配置 (可选) */
|
|
459
|
+
defaultConfig?: Record<string, any>;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* 插件基础类
|
|
463
|
+
* @deprecated 建议统一使用工厂模式 definePlugin() 定义插件,以消除类与对象定义的歧义。
|
|
464
|
+
* @description 解决插件定义时 id 与 metadata.id 重复定义的问题,并提供基础生命周期管理
|
|
465
|
+
*/
|
|
466
|
+
declare abstract class BasePlugin implements Plugin {
|
|
467
|
+
abstract metadata: PluginMetadata;
|
|
468
|
+
/**
|
|
469
|
+
* 插件 ID
|
|
470
|
+
* @description 自动从 metadata.id 获取
|
|
471
|
+
*/
|
|
472
|
+
get id(): string;
|
|
473
|
+
onLoad?(context: PluginContext): void | Promise<void>;
|
|
474
|
+
onMount?(context: PluginContext): void;
|
|
475
|
+
onUnmount?(context: PluginContext): void;
|
|
476
|
+
onConfigChange?(newConfig: any, oldConfig: any): void;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* 辅助函数:定义插件并自动从 metadata.id 注入顶级 id
|
|
480
|
+
* @description 解决插件定义时 id 与 metadata.id 重复定义的问题,提高代码优雅度
|
|
481
|
+
* @param plugin 插件定义(不包含顶级 id)
|
|
482
|
+
* @returns 完整的插件对象
|
|
483
|
+
*/
|
|
484
|
+
declare function definePlugin(plugin: Omit<Plugin, 'id'>): Plugin;
|
|
485
|
+
/**
|
|
486
|
+
* 插件元数据定义
|
|
487
|
+
* @description 描述插件的静态属性,用于插件市场展示、权限校验和内核加载参考。
|
|
488
|
+
*/
|
|
489
|
+
interface PluginMetadata {
|
|
490
|
+
/** 插件唯一 ID (推荐反向域名格式,如 com.company.plugin) */
|
|
491
|
+
id: string;
|
|
492
|
+
/** 插件显示名称 */
|
|
493
|
+
name: string;
|
|
494
|
+
/** 插件版本号 (符合 SemVer 规范) */
|
|
495
|
+
version: string;
|
|
496
|
+
/** 插件类型 */
|
|
497
|
+
type: PluginType;
|
|
498
|
+
/** 插件功能描述 */
|
|
499
|
+
description?: string;
|
|
500
|
+
/** 插件作者信息 */
|
|
501
|
+
author?: string;
|
|
502
|
+
/** 插件图标 (React 组件或图标名称) */
|
|
503
|
+
icon?: React.ReactNode;
|
|
504
|
+
/** 插件依赖的其他插件 ID 列表 */
|
|
505
|
+
dependencies?: string[];
|
|
506
|
+
/** 路由配置集合,用于在主应用中注册页面 */
|
|
507
|
+
routes?: RouteConfig[];
|
|
508
|
+
/** 插槽扩展集合,用于在主应用 UI 预留位注入组件 */
|
|
509
|
+
extensions?: PluginExtension[];
|
|
510
|
+
/** 插件所需调用的 API 接口配置 */
|
|
511
|
+
api?: ApiConfig;
|
|
512
|
+
/** 插件行为能力声明 */
|
|
513
|
+
capabilities?: PluginCapabilities;
|
|
514
|
+
/** 插件的可配置项定义 */
|
|
515
|
+
configuration?: PluginConfigItem[];
|
|
516
|
+
/** 插件所需的存储结构定义 */
|
|
517
|
+
storage?: StorageItemSchema[];
|
|
518
|
+
/**
|
|
519
|
+
* 系统状态自动绑定
|
|
520
|
+
* @description 将插件的配置项自动同步到系统的全局状态中 (如主题色、身份认证等)
|
|
521
|
+
*/
|
|
522
|
+
systemStateBindings?: {
|
|
523
|
+
/** 插件配置中的键名 */
|
|
524
|
+
configKey: string;
|
|
525
|
+
/** 系统全局状态中的键名 */
|
|
526
|
+
stateKey: string;
|
|
527
|
+
/** 预设的转换逻辑名称 */
|
|
528
|
+
transform?: 'theme-mode' | 'identity';
|
|
529
|
+
}[];
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* 服务注册中心 (Service Registry)
|
|
534
|
+
* @description 核心应用层服务,作为微内核架构中的“中枢调度员”。
|
|
535
|
+
* 主要职责:
|
|
536
|
+
* 1. 服务解耦:允许插件将其内部功能暴露为“服务”,而无需与其他插件产生物理依赖。
|
|
537
|
+
* 2. 动态发现:提供按名称查找服务的能力,支持服务热插拔。
|
|
538
|
+
* 3. 依赖协调:通过 `waitFor` 机制解决插件间由于加载顺序导致的初始化依赖问题。
|
|
539
|
+
*
|
|
540
|
+
* 建议的服务命名规范: `pluginId.serviceName` (例如: `auth.sessionService`)
|
|
541
|
+
*/
|
|
542
|
+
declare class ServiceRegistry {
|
|
543
|
+
/** 存储已注册服务的 Map 对象 */
|
|
544
|
+
private services;
|
|
545
|
+
/** 存储正在等待特定服务的监听器集合 */
|
|
546
|
+
private listeners;
|
|
547
|
+
/**
|
|
548
|
+
* 注册一个服务实现
|
|
549
|
+
* @param name - 唯一的服务名称
|
|
550
|
+
* @param service - 服务实例或对象
|
|
551
|
+
*/
|
|
552
|
+
register(name: string, service: any): void;
|
|
553
|
+
/**
|
|
554
|
+
* 同步获取服务实例
|
|
555
|
+
* @template T - 服务类型的泛型
|
|
556
|
+
* @param name - 服务名称
|
|
557
|
+
* @returns 服务实例,若不存在则返回 undefined
|
|
558
|
+
*/
|
|
559
|
+
get<T = any>(name: string): T | undefined;
|
|
560
|
+
/**
|
|
561
|
+
* 异步等待并获取服务
|
|
562
|
+
* @description 如果服务尚未注册,将返回一个 Promise,直到该服务被注册时 resolve。
|
|
563
|
+
* 支持设置超时时间,防止因插件加载失败导致的永久挂起。
|
|
564
|
+
*
|
|
565
|
+
* @template T - 服务类型的泛型
|
|
566
|
+
* @param name - 待等待的服务名称
|
|
567
|
+
* @param timeout - 超时时间 (毫秒),默认 10000ms (10秒)。若为 0 则永不超时。
|
|
568
|
+
* @returns 包含服务实例的 Promise
|
|
569
|
+
* @throws {Error} 若在规定时间内服务未注册,则抛出超时异常。
|
|
570
|
+
*/
|
|
571
|
+
waitFor<T = any>(name: string, timeout?: number): Promise<T>;
|
|
572
|
+
/**
|
|
573
|
+
* 检查服务是否已注册
|
|
574
|
+
* @param name - 服务名称
|
|
575
|
+
*/
|
|
576
|
+
has(name: string): boolean;
|
|
577
|
+
/**
|
|
578
|
+
* 注销特定的服务
|
|
579
|
+
* @param name - 服务名称
|
|
580
|
+
*/
|
|
581
|
+
unregister(name: string): void;
|
|
582
|
+
/**
|
|
583
|
+
* 清除所有已注册的服务和监听器
|
|
584
|
+
* @description 通常仅在系统重置或大型热更新时使用。
|
|
585
|
+
*/
|
|
586
|
+
clear(): void;
|
|
587
|
+
}
|
|
588
|
+
declare const serviceRegistry: ServiceRegistry;
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* 基于 Axios 的默认请求适配器
|
|
592
|
+
*/
|
|
593
|
+
declare class AxiosAdapter implements ApiAdapter {
|
|
594
|
+
private client;
|
|
595
|
+
constructor(baseURL?: string, timeout?: number);
|
|
596
|
+
request<T = any>(config: ApiRequestConfig): Promise<T>;
|
|
597
|
+
stream(config: ApiRequestConfig, callbacks: StreamCallbacks, _endpointConfig?: ApiEndpointConfig): Promise<void>;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* API 引擎核心类
|
|
602
|
+
* @description 负责加载配置并执行请求,支持策略模式切换底层请求实现
|
|
603
|
+
*/
|
|
604
|
+
declare class ApiEngine {
|
|
605
|
+
private adapter;
|
|
606
|
+
private config;
|
|
607
|
+
private interceptors;
|
|
608
|
+
constructor(adapter?: ApiAdapter);
|
|
609
|
+
/**
|
|
610
|
+
* 注册拦截器
|
|
611
|
+
*/
|
|
612
|
+
registerInterceptor(interceptor: ApiInterceptor): void;
|
|
613
|
+
/**
|
|
614
|
+
* 移除拦截器
|
|
615
|
+
*/
|
|
616
|
+
unregisterInterceptor(interceptor: ApiInterceptor): void;
|
|
617
|
+
/**
|
|
618
|
+
* 切换请求适配器
|
|
619
|
+
* @param adapter 新的适配器实例
|
|
620
|
+
*/
|
|
621
|
+
useAdapter(adapter: ApiAdapter): void;
|
|
622
|
+
/**
|
|
623
|
+
* 注册 API 配置
|
|
624
|
+
* @param config 配置对象
|
|
625
|
+
*/
|
|
626
|
+
register(config: ApiConfig): void;
|
|
627
|
+
/**
|
|
628
|
+
* 获取接口配置
|
|
629
|
+
*/
|
|
630
|
+
getEndpoint(module: string, action: string): ApiEndpointConfig | undefined;
|
|
631
|
+
/**
|
|
632
|
+
* 发起 API 请求
|
|
633
|
+
* @param module 模块名
|
|
634
|
+
* @param action 动作名
|
|
635
|
+
* @param data 请求数据 (Body 或 Query)
|
|
636
|
+
* @param options 请求选项
|
|
637
|
+
*/
|
|
638
|
+
call<T = any>(module: string, action: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
639
|
+
/**
|
|
640
|
+
* 发起流式请求
|
|
641
|
+
* @param module 模块名
|
|
642
|
+
* @param action 动作名
|
|
643
|
+
* @param data 请求数据
|
|
644
|
+
* @param options 请求选项
|
|
645
|
+
*/
|
|
646
|
+
stream(module: string, action: string, data?: any, options?: RequestOptions): Promise<void>;
|
|
647
|
+
/**
|
|
648
|
+
* 准备请求配置,应用 URL 参数替换和请求拦截器
|
|
649
|
+
*/
|
|
650
|
+
private prepareRequestConfig;
|
|
651
|
+
/**
|
|
652
|
+
* 应用所有请求拦截器
|
|
653
|
+
*/
|
|
654
|
+
private applyRequestInterceptors;
|
|
655
|
+
/**
|
|
656
|
+
* 应用所有响应拦截器
|
|
657
|
+
* @returns 是否被劫持
|
|
658
|
+
*/
|
|
659
|
+
private applyResponseInterceptors;
|
|
660
|
+
/**
|
|
661
|
+
* 检查 HTTP 状态码
|
|
662
|
+
*/
|
|
663
|
+
private checkHttpStatus;
|
|
664
|
+
/**
|
|
665
|
+
* 提取响应数据
|
|
666
|
+
*/
|
|
667
|
+
private extractResponseData;
|
|
668
|
+
/**
|
|
669
|
+
* 处理业务错误
|
|
670
|
+
*/
|
|
671
|
+
private handleBusinessError;
|
|
672
|
+
/**
|
|
673
|
+
* 判断是否为 BaseResponse
|
|
674
|
+
*/
|
|
675
|
+
private isBaseResponse;
|
|
676
|
+
/**
|
|
677
|
+
* 严格判断是否为 AxiosResponse
|
|
678
|
+
*/
|
|
679
|
+
private isAxiosResponse;
|
|
680
|
+
/**
|
|
681
|
+
* 创建拦截上下文
|
|
682
|
+
*/
|
|
683
|
+
private createInterceptorContext;
|
|
684
|
+
}
|
|
685
|
+
declare const apiEngine: ApiEngine;
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* 自动检测是否处于 Mock 模式
|
|
689
|
+
*/
|
|
690
|
+
declare function isMockMode(): boolean;
|
|
691
|
+
/**
|
|
692
|
+
* 从文件模块映射中解析 API 配置
|
|
693
|
+
* @description 配合 Vite 的 import.meta.glob 使用,自动匹配定义文件和 Mock 文件
|
|
694
|
+
* @param definitionsMap API 定义文件映射 (import.meta.glob('./modules/*.ts', { eager: true }))
|
|
695
|
+
* @param mocksMap Mock 文件映射 (import.meta.glob('./modules/*.mock.ts', { eager: true }))
|
|
696
|
+
* @param useMock 是否启用 Mock (如果不传,将自动调用 isMockMode())
|
|
697
|
+
* @returns 合并后的 ApiConfig
|
|
698
|
+
*/
|
|
699
|
+
declare function resolveApiModules(definitionsMap: Record<string, any>, mocksMap?: Record<string, any>): ApiConfig;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* 成功状态码
|
|
703
|
+
*/
|
|
704
|
+
declare const SUCCESS_CODE = "000000";
|
|
705
|
+
/**
|
|
706
|
+
* 基础 API 响应接口
|
|
707
|
+
* @template T 响应数据的类型
|
|
708
|
+
*/
|
|
709
|
+
interface BaseResponse<T = any> {
|
|
710
|
+
/** 业务状态码 */
|
|
711
|
+
code: string | number;
|
|
712
|
+
/** 响应消息提示 */
|
|
713
|
+
message: string;
|
|
714
|
+
/** 业务响应数据主体 */
|
|
715
|
+
data: T;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* 业务场景实体接口
|
|
719
|
+
* @description 描述系统中的业务分析场景
|
|
720
|
+
*/
|
|
721
|
+
interface Scene {
|
|
722
|
+
/** 场景唯一标识符 */
|
|
723
|
+
id: string;
|
|
724
|
+
/** 场景名称 */
|
|
725
|
+
name: string;
|
|
726
|
+
/** 场景详细描述 */
|
|
727
|
+
description: string;
|
|
728
|
+
/** 场景内部代码/标识 */
|
|
729
|
+
code: string;
|
|
730
|
+
/** 场景创建者 ID 或名称 */
|
|
731
|
+
creator: string;
|
|
732
|
+
/** 创建时间字符串 (ISO 格式) */
|
|
733
|
+
createTime: string;
|
|
734
|
+
/** 该场景关联的物理数据表数量 */
|
|
735
|
+
tableCount: number;
|
|
736
|
+
/** 该场景关联的知识库数量 */
|
|
737
|
+
kbCount: number;
|
|
738
|
+
/** 该场景关联的预设问答对数量 */
|
|
739
|
+
qaCount: number;
|
|
740
|
+
/** 场景封面图 URL (可选) */
|
|
741
|
+
cover?: string;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
interface ApiProviderProps {
|
|
745
|
+
api: ApiEngine;
|
|
746
|
+
children: React.ReactNode;
|
|
747
|
+
}
|
|
748
|
+
declare const ApiProvider: React.FC<ApiProviderProps>;
|
|
749
|
+
declare const useApi: () => ApiEngine;
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* 配置管理器
|
|
753
|
+
* @description 核心工具类,负责管理应用的全局系统配置以及各插件的初始化业务配置。
|
|
754
|
+
* 配置数据通常在应用启动时通过 `usePluginLoader` 注入,并作为插件运行时的取值回退来源。
|
|
755
|
+
*/
|
|
756
|
+
declare class ConfigManager {
|
|
757
|
+
/** 内部存储配置的 Map 对象 */
|
|
758
|
+
private config;
|
|
759
|
+
/**
|
|
760
|
+
* 设置特定的配置项
|
|
761
|
+
* @param key - 配置键名(如 'system' 或插件 ID)
|
|
762
|
+
* @param value - 配置内容对象
|
|
763
|
+
*/
|
|
764
|
+
set(key: string, value: any): void;
|
|
765
|
+
/**
|
|
766
|
+
* 获取指定的配置项
|
|
767
|
+
* @param key - 配置键名
|
|
768
|
+
* @returns 配置内容,若不存在则返回 undefined
|
|
769
|
+
*/
|
|
770
|
+
get(key: string): any;
|
|
771
|
+
/**
|
|
772
|
+
* 批量合并配置对象
|
|
773
|
+
* @description 对顶层属性进行浅合并,若属性值为对象则进行一层深度的合并。
|
|
774
|
+
* @param config - 待合并的配置对象映射
|
|
775
|
+
*/
|
|
776
|
+
merge(config: Record<string, any>): void;
|
|
777
|
+
/**
|
|
778
|
+
* 获取当前存储的所有配置快照
|
|
779
|
+
* @returns 包含所有配置的普通对象
|
|
780
|
+
*/
|
|
781
|
+
getAll(): Record<string, any>;
|
|
782
|
+
}
|
|
783
|
+
/** 全局配置管理器单例 */
|
|
784
|
+
declare const configManager: ConfigManager;
|
|
785
|
+
|
|
786
|
+
/** 插件错误边界组件属性 */
|
|
787
|
+
interface Props {
|
|
788
|
+
/** 发生错误的插件 ID */
|
|
789
|
+
pluginId?: string;
|
|
790
|
+
/** 错误发生时的降级 UI */
|
|
791
|
+
fallback?: ReactNode;
|
|
792
|
+
/** 子组件内容 */
|
|
793
|
+
children: ReactNode;
|
|
794
|
+
/** 是否静默模式,开启后不显示任何错误 UI,仅记录日志 */
|
|
795
|
+
silent?: boolean;
|
|
796
|
+
}
|
|
797
|
+
/** 插件错误边界组件状态 */
|
|
798
|
+
interface State {
|
|
799
|
+
/** 是否捕获到错误 */
|
|
800
|
+
hasError: boolean;
|
|
801
|
+
/** 捕获到的错误对象 */
|
|
802
|
+
error: Error | null;
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* 插件错误边界组件
|
|
806
|
+
* @description 核心组件,用于捕获子组件渲染过程中的 JavaScript 错误,记录日志并显示降级 UI。
|
|
807
|
+
* 确保单个插件的运行异常不会导致整个主应用或其他插件崩溃。
|
|
808
|
+
*/
|
|
809
|
+
declare class PluginErrorBoundary extends Component<Props, State> {
|
|
810
|
+
constructor(props: Props);
|
|
811
|
+
/**
|
|
812
|
+
* 从错误中派生状态
|
|
813
|
+
* @param error - 捕获到的错误
|
|
814
|
+
*/
|
|
815
|
+
static getDerivedStateFromError(error: any): State;
|
|
816
|
+
/**
|
|
817
|
+
* 捕获到错误后的回调
|
|
818
|
+
* @param error - 错误对象
|
|
819
|
+
* @param errorInfo - 错误堆栈信息
|
|
820
|
+
*/
|
|
821
|
+
componentDidCatch(error: any, errorInfo: ErrorInfo): void;
|
|
822
|
+
/**
|
|
823
|
+
* 重置错误状态,尝试重新渲染
|
|
824
|
+
*/
|
|
825
|
+
handleRetry: () => void;
|
|
826
|
+
render(): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/** 插件插槽组件属性 */
|
|
830
|
+
interface PluginSlotProps {
|
|
831
|
+
/** 插槽位置标识,决定渲染哪些插件扩展 */
|
|
832
|
+
slot: SlotPosition;
|
|
833
|
+
/** 传递给扩展组件的 Props 对象 */
|
|
834
|
+
props?: Record<string, any>;
|
|
835
|
+
/** 自定义容器类名 (Tailwind CSS) */
|
|
836
|
+
className?: string;
|
|
837
|
+
/** 自定义容器内联样式 */
|
|
838
|
+
style?: React.CSSProperties;
|
|
839
|
+
/**
|
|
840
|
+
* 自定义渲染函数
|
|
841
|
+
* @param item - 包含 key、组件和扩展元信息的对象
|
|
842
|
+
* @param index - 索引位置
|
|
843
|
+
*/
|
|
844
|
+
renderItem?: (item: {
|
|
845
|
+
key: string;
|
|
846
|
+
component: React.ReactNode;
|
|
847
|
+
extension: PluginExtension;
|
|
848
|
+
}, index: number) => React.ReactNode;
|
|
849
|
+
/** 骨架屏组件,当插槽内无插件扩展时显示的占位 UI */
|
|
850
|
+
skeleton?: React.ReactNode;
|
|
851
|
+
/** 回退组件,当插槽内无插件扩展时显示的 UI,优先级高于 skeleton */
|
|
852
|
+
fallback?: React.ReactNode;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* 插件插槽组件
|
|
856
|
+
* @description UI 层的核心组件,用于在应用中声明一个“插槽”。
|
|
857
|
+
* 它会自动根据 slot 标识从 PluginManager 中获取所有注册的插件扩展组件并按顺序渲染。
|
|
858
|
+
* 支持订阅插件变更,实现动态热插拔。
|
|
859
|
+
*/
|
|
860
|
+
declare const PluginSlot: React.FC<PluginSlotProps>;
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* 通用插槽骨架屏组件集合
|
|
864
|
+
* @description 提供一组预定义的骨架屏 UI,用于在插件加载或插槽内容未准备好时提供更好的用户体验。
|
|
865
|
+
*/
|
|
866
|
+
/**
|
|
867
|
+
* 侧边栏图标骨架屏
|
|
868
|
+
* @param expanded - 是否处于展开状态
|
|
869
|
+
*/
|
|
870
|
+
declare const SidebarIconSkeleton: React.FC<{
|
|
871
|
+
expanded?: boolean;
|
|
872
|
+
}>;
|
|
873
|
+
/**
|
|
874
|
+
* 状态栏项骨架屏
|
|
875
|
+
*/
|
|
876
|
+
declare const StatusBarItemSkeleton: React.FC;
|
|
877
|
+
/**
|
|
878
|
+
* 头像骨架屏
|
|
879
|
+
*/
|
|
880
|
+
declare const AvatarSkeleton: React.FC;
|
|
881
|
+
/**
|
|
882
|
+
* 通用块级骨架屏
|
|
883
|
+
* @param className - 自定义类名
|
|
884
|
+
*/
|
|
885
|
+
declare const BlockSkeleton: React.FC<{
|
|
886
|
+
className?: string;
|
|
887
|
+
}>;
|
|
888
|
+
/**
|
|
889
|
+
* 自动根据插槽位置匹配骨架屏
|
|
890
|
+
*/
|
|
891
|
+
declare const SlotSkeletons: React.FC<{
|
|
892
|
+
slot: string;
|
|
893
|
+
expanded?: boolean;
|
|
894
|
+
}>;
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* 插件注册表接口
|
|
898
|
+
* @description 键为插件 ID,值为一个返回插件定义的异步加载函数。
|
|
899
|
+
*/
|
|
900
|
+
interface PluginRegistry {
|
|
901
|
+
[pluginId: string]: () => Promise<any>;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* 插件自动发现规则
|
|
905
|
+
*/
|
|
906
|
+
interface DiscoveryRule {
|
|
907
|
+
/**
|
|
908
|
+
* 路径匹配标识。
|
|
909
|
+
* @example 'plugins' 或 '@chatbi-plugins'
|
|
910
|
+
*/
|
|
911
|
+
pathSegment: string;
|
|
912
|
+
/**
|
|
913
|
+
* 生成插件 ID 时的前缀。
|
|
914
|
+
* @example '@chatbi-v/plugin',最终生成如 '@chatbi-v/plugin-demo'
|
|
915
|
+
*/
|
|
916
|
+
idPrefix: string;
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* 解析插件注册表
|
|
920
|
+
* @description 核心逻辑:将 Vite 的 `import.meta.glob` 结果映射为标准的插件注册表。
|
|
921
|
+
* 它会根据预定义的路径匹配规则,从文件路径中提取插件目录名,并拼接前缀生成唯一的插件 ID。
|
|
922
|
+
*
|
|
923
|
+
* @param options - 包含待处理模块和匹配规则的选项对象
|
|
924
|
+
* @returns 解析后的 PluginRegistry 对象
|
|
925
|
+
*/
|
|
926
|
+
declare const resolvePluginRegistry: (options: {
|
|
927
|
+
/** 原始模块映射 (来自 Vite glob) */
|
|
928
|
+
modules: Record<string, () => Promise<any>>;
|
|
929
|
+
/** 自定义发现规则 (可选) */
|
|
930
|
+
rules?: DiscoveryRule[];
|
|
931
|
+
}) => PluginRegistry;
|
|
932
|
+
|
|
933
|
+
type EventCallback = (...args: any[]) => any;
|
|
934
|
+
/**
|
|
935
|
+
* 事件总线接口
|
|
936
|
+
*/
|
|
937
|
+
interface EventBus {
|
|
938
|
+
/**
|
|
939
|
+
* 订阅事件
|
|
940
|
+
* @param event 事件名称
|
|
941
|
+
* @param callback 回调函数
|
|
942
|
+
* @returns 取消订阅函数
|
|
943
|
+
*/
|
|
944
|
+
on(event: string, callback: EventCallback): () => void;
|
|
945
|
+
/**
|
|
946
|
+
* 取消订阅
|
|
947
|
+
* @param event 事件名称
|
|
948
|
+
* @param callback 回调函数
|
|
949
|
+
*/
|
|
950
|
+
off(event: string, callback: EventCallback): void;
|
|
951
|
+
/**
|
|
952
|
+
* 触发事件
|
|
953
|
+
* @param event 事件名称
|
|
954
|
+
* @param args 事件参数
|
|
955
|
+
*/
|
|
956
|
+
emit(event: string, ...args: any[]): void;
|
|
957
|
+
/**
|
|
958
|
+
* 订阅一次性事件
|
|
959
|
+
* @param event 事件名称
|
|
960
|
+
* @param callback 回调函数
|
|
961
|
+
*/
|
|
962
|
+
once(event: string, callback: EventCallback): void;
|
|
963
|
+
}
|
|
964
|
+
declare class DefaultEventBus implements EventBus {
|
|
965
|
+
private listeners;
|
|
966
|
+
on(event: string, callback: EventCallback): () => void;
|
|
967
|
+
off(event: string, callback: EventCallback): void;
|
|
968
|
+
emit(event: string, ...args: any[]): void;
|
|
969
|
+
once(event: string, callback: EventCallback): void;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* 核心领域服务:存储管理器
|
|
974
|
+
* @description 统一管理应用内所有的持久化存储资源。
|
|
975
|
+
* 核心功能:
|
|
976
|
+
* 1. 作用域隔离:通过前缀划分 `plugin`、`shared` 和 `system` 三个层级的存储空间。
|
|
977
|
+
* 2. Schema 校验:支持注册存储描述,规范数据存取,避免键名冲突。
|
|
978
|
+
* 3. 默认值与配置回退:支持从 Schema 默认值或 ConfigManager 中回退取值。
|
|
979
|
+
*/
|
|
980
|
+
declare class StorageManager {
|
|
981
|
+
/** 底层物理存储驱动 */
|
|
982
|
+
private baseStorage;
|
|
983
|
+
/** 插件 ID 与存储描述定义的映射关系 */
|
|
984
|
+
private schemas;
|
|
985
|
+
/** 内存缓存,减少 JSON 序列化和物理 IO 开销 */
|
|
986
|
+
private memoryCache;
|
|
987
|
+
/**
|
|
988
|
+
* 初始化存储管理器
|
|
989
|
+
* @param baseStorage - 符合 StoragePort 接口的物理存储驱动(如 LocalStorageAdapter)
|
|
990
|
+
*/
|
|
991
|
+
constructor(baseStorage: StoragePort);
|
|
992
|
+
/**
|
|
993
|
+
* 注册插件的存储 Schema
|
|
994
|
+
* @param pluginId - 插件 ID
|
|
995
|
+
* @param schema - 存储项定义列表
|
|
996
|
+
*/
|
|
997
|
+
registerSchema(pluginId: string, schema: StorageItemSchema[]): void;
|
|
998
|
+
/**
|
|
999
|
+
* 内部校验方法:检查键名是否在 Schema 中声明
|
|
1000
|
+
* @param pluginId - 插件 ID
|
|
1001
|
+
* @param key - 待校验的键名
|
|
1002
|
+
* @param scope - 目标作用域
|
|
1003
|
+
*/
|
|
1004
|
+
private validateKey;
|
|
1005
|
+
/**
|
|
1006
|
+
* 获取插件私有存储适配器
|
|
1007
|
+
* @param pluginId - 插件 ID
|
|
1008
|
+
* @returns 自动添加 `plugin:{id}:` 前缀的存储接口
|
|
1009
|
+
*/
|
|
1010
|
+
getPluginStorage(pluginId: string): StoragePort;
|
|
1011
|
+
/**
|
|
1012
|
+
* 获取全局共享存储适配器
|
|
1013
|
+
* @returns 自动添加 `shared:` 前缀的存储接口
|
|
1014
|
+
*/
|
|
1015
|
+
getSharedStorage(): StoragePort;
|
|
1016
|
+
/**
|
|
1017
|
+
* 获取系统内部存储适配器
|
|
1018
|
+
* @returns 自动添加 `system:` 前缀的存储接口
|
|
1019
|
+
*/
|
|
1020
|
+
getSystemStorage(): StoragePort;
|
|
1021
|
+
/**
|
|
1022
|
+
* 创建插件沙箱使用的复合存储对象
|
|
1023
|
+
* @description 返回的对象封装了对私有存储和共享存储的操作。
|
|
1024
|
+
* 特性:
|
|
1025
|
+
* - 内存级 LRU 缓存:极大提升高频读写性能。
|
|
1026
|
+
* - 自动序列化/反序列化 JSON。
|
|
1027
|
+
* - 自动校验 Schema。
|
|
1028
|
+
* - 取值回退逻辑:持久化存储 -> ConfigManager -> Schema 默认值。
|
|
1029
|
+
*
|
|
1030
|
+
* @param pluginId - 插件 ID
|
|
1031
|
+
* @returns 包含 get/set/remove 及 shared 子对象的复合接口
|
|
1032
|
+
*/
|
|
1033
|
+
getContextStorage(pluginId: string): {
|
|
1034
|
+
shared: {
|
|
1035
|
+
get: <T = any>(key: string) => T | null;
|
|
1036
|
+
set: <T = any>(key: string, value: T) => void;
|
|
1037
|
+
remove: (key: string) => void;
|
|
1038
|
+
};
|
|
1039
|
+
get: <T = any>(key: string) => T | null;
|
|
1040
|
+
set: <T = any>(key: string, value: T) => void;
|
|
1041
|
+
remove: (key: string) => void;
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* 插件管理器
|
|
1047
|
+
* @description 核心领域服务,负责插件的完整生命周期管理,包括扫描、注册、配置合并、状态切换及依赖解析。
|
|
1048
|
+
*/
|
|
1049
|
+
declare class PluginManager {
|
|
1050
|
+
/** 全局事件总线,用于插件间及插件与内核间的异步通信 */
|
|
1051
|
+
readonly eventBus: DefaultEventBus;
|
|
1052
|
+
/** 存储管理服务,负责插件私有存储和系统级状态的持久化 */
|
|
1053
|
+
private storageManager;
|
|
1054
|
+
/** 插件 ID 到运行时实例的映射表 */
|
|
1055
|
+
private runtimes;
|
|
1056
|
+
/** 插件 ID 到原始插件定义对象的映射表 */
|
|
1057
|
+
private plugins;
|
|
1058
|
+
/** 收集到的所有插件路由配置 */
|
|
1059
|
+
private routes;
|
|
1060
|
+
/** 收集到的所有插件扩展点配置,按插槽位置分组 */
|
|
1061
|
+
private extensions;
|
|
1062
|
+
/** 插件的启用状态和排序信息的内存缓存 */
|
|
1063
|
+
private pluginStates;
|
|
1064
|
+
/** 状态变更监听器集合,支持按插槽过滤 */
|
|
1065
|
+
private listeners;
|
|
1066
|
+
/** 按插槽位置存储的监听器,用于精确通知 */
|
|
1067
|
+
private slotListeners;
|
|
1068
|
+
/** 扩展点缓存,避免重复计算 */
|
|
1069
|
+
private memoizedExtensions;
|
|
1070
|
+
/** 路由缓存 */
|
|
1071
|
+
private memoizedRoutes;
|
|
1072
|
+
/** 传递给插件的共享上下文缓存 */
|
|
1073
|
+
private sharedContext;
|
|
1074
|
+
/** 收集到的插件工具函数集合 */
|
|
1075
|
+
private utils;
|
|
1076
|
+
/**
|
|
1077
|
+
* 构造函数
|
|
1078
|
+
* @param storage - 底层存储适配器
|
|
1079
|
+
*/
|
|
1080
|
+
constructor(storage: StoragePort);
|
|
1081
|
+
/**
|
|
1082
|
+
* 从持久化存储中恢复插件状态 (启用/禁用、排序等)
|
|
1083
|
+
*/
|
|
1084
|
+
private loadStates;
|
|
1085
|
+
/**
|
|
1086
|
+
* 将当前的插件状态持久化到存储中
|
|
1087
|
+
*/
|
|
1088
|
+
private saveStates;
|
|
1089
|
+
/**
|
|
1090
|
+
* 订阅插件状态的变更通知
|
|
1091
|
+
* @param listener - 变更时的回调函数
|
|
1092
|
+
* @param slot - (可选) 指定监听的插槽位置,若提供则仅在该插槽受影响时通知
|
|
1093
|
+
* @returns 取消订阅的函数
|
|
1094
|
+
*/
|
|
1095
|
+
subscribe(listener: () => void, slot?: SlotPosition | string): () => void;
|
|
1096
|
+
/**
|
|
1097
|
+
* 获取存储管理器实例
|
|
1098
|
+
* @returns StorageManager 实例
|
|
1099
|
+
*/
|
|
1100
|
+
getStorageManager(): StorageManager;
|
|
1101
|
+
/**
|
|
1102
|
+
* 触发状态变更通知
|
|
1103
|
+
* @param affectedSlot - (可选) 受影响的插槽位置
|
|
1104
|
+
*/
|
|
1105
|
+
private notify;
|
|
1106
|
+
/**
|
|
1107
|
+
* 获取所有已注册的插件列表
|
|
1108
|
+
* @description 结果会根据插件类型优先级和用户自定义排序进行排序
|
|
1109
|
+
* @returns 排序后的插件数组
|
|
1110
|
+
*/
|
|
1111
|
+
getPlugins(): Plugin[];
|
|
1112
|
+
/**
|
|
1113
|
+
* 获取指定插件的状态信息
|
|
1114
|
+
* @param pluginId - 插件 ID
|
|
1115
|
+
* @returns 包含启用状态和排序值的对象
|
|
1116
|
+
*/
|
|
1117
|
+
getPluginState(pluginId: string): {
|
|
1118
|
+
enabled: boolean;
|
|
1119
|
+
order: number;
|
|
1120
|
+
};
|
|
1121
|
+
/**
|
|
1122
|
+
* 检查指定插件是否处于启用状态
|
|
1123
|
+
* @param pluginId - 插件 ID
|
|
1124
|
+
* @returns 是否启用
|
|
1125
|
+
*/
|
|
1126
|
+
isPluginEnabled(pluginId: string): boolean;
|
|
1127
|
+
/**
|
|
1128
|
+
* 切换插件的启用/禁用状态
|
|
1129
|
+
* @description 禁用插件会立即触发其卸载生命周期并销毁运行时。
|
|
1130
|
+
* @param pluginId - 插件 ID
|
|
1131
|
+
* @param enabled - 目标状态
|
|
1132
|
+
*/
|
|
1133
|
+
togglePlugin(pluginId: string, enabled: boolean): void;
|
|
1134
|
+
/**
|
|
1135
|
+
* 设置插件的显示排序权重
|
|
1136
|
+
* @param pluginId - 插件 ID
|
|
1137
|
+
* @param order - 排序权重值
|
|
1138
|
+
*/
|
|
1139
|
+
setPluginOrder(pluginId: string, order: number): void;
|
|
1140
|
+
/**
|
|
1141
|
+
* 获取指定插件的运行时状态
|
|
1142
|
+
* @param pluginId - 插件 ID
|
|
1143
|
+
* @returns 'error' | 'mounted' | 'loaded' | 'initial'
|
|
1144
|
+
*/
|
|
1145
|
+
getPluginRuntimeStatus(pluginId: string): "error" | "mounted" | "loaded" | "initial";
|
|
1146
|
+
/**
|
|
1147
|
+
* 获取指定插件的运行时错误
|
|
1148
|
+
* @param pluginId - 插件 ID
|
|
1149
|
+
* @returns Error 对象或 null
|
|
1150
|
+
*/
|
|
1151
|
+
getPluginError(pluginId: string): Error | null;
|
|
1152
|
+
/**
|
|
1153
|
+
* 报告插件运行时错误 (通常由 ErrorBoundary 调用)
|
|
1154
|
+
* @param pluginId - 插件 ID
|
|
1155
|
+
* @param error - 错误对象
|
|
1156
|
+
*/
|
|
1157
|
+
reportPluginError(pluginId: string, error: Error): void;
|
|
1158
|
+
/**
|
|
1159
|
+
* 获取插件的完整能力声明
|
|
1160
|
+
* @param pluginId - 插件 ID
|
|
1161
|
+
* @returns 能力对象
|
|
1162
|
+
*/
|
|
1163
|
+
getUnifiedCapabilities(pluginId: string): PluginCapabilities;
|
|
1164
|
+
/**
|
|
1165
|
+
* 更新指定插件的某项配置
|
|
1166
|
+
* @description 该操作会同步更新内存中的配置、持久化到存储并触发全局事件通知。
|
|
1167
|
+
* @param pluginId - 插件 ID
|
|
1168
|
+
* @param key - 配置键名
|
|
1169
|
+
* @param value - 新的配置值
|
|
1170
|
+
*/
|
|
1171
|
+
updatePluginConfig(pluginId: string, key: string, value: any): void;
|
|
1172
|
+
/**
|
|
1173
|
+
* 获取指定插件的某项配置值
|
|
1174
|
+
* @param pluginId - 插件 ID
|
|
1175
|
+
* @param key - 配置键名
|
|
1176
|
+
* @returns 配置值
|
|
1177
|
+
*/
|
|
1178
|
+
getPluginConfig(pluginId: string, key: string): any;
|
|
1179
|
+
/**
|
|
1180
|
+
* 获取系统全局配置 (非插件特定)
|
|
1181
|
+
* @param key - 系统配置键名
|
|
1182
|
+
* @returns 配置值
|
|
1183
|
+
*/
|
|
1184
|
+
getSystemConfig(key: string): any;
|
|
1185
|
+
/**
|
|
1186
|
+
* 获取由插件注册的服务实例
|
|
1187
|
+
* @template T 服务接口类型
|
|
1188
|
+
* @param name - 服务注册名称
|
|
1189
|
+
* @returns 服务实例或 undefined
|
|
1190
|
+
*/
|
|
1191
|
+
getService<T = any>(name: string): T | undefined;
|
|
1192
|
+
/**
|
|
1193
|
+
* 获取指定插槽位置的所有已启用插件的扩展
|
|
1194
|
+
* @param slot - 插槽位置标识
|
|
1195
|
+
* @returns 排序后的扩展配置数组
|
|
1196
|
+
*/
|
|
1197
|
+
getExtensions(slot: SlotPosition | string): PluginExtension[];
|
|
1198
|
+
/**
|
|
1199
|
+
* 获取所有已启用插件注册的路由配置
|
|
1200
|
+
* @returns 增强后的路由配置数组
|
|
1201
|
+
*/
|
|
1202
|
+
getRoutes(): RouteConfig[];
|
|
1203
|
+
/**
|
|
1204
|
+
* 注册一个新插件到管理器中
|
|
1205
|
+
* @description 此阶段会执行元数据校验、存储 Schema 注册、配置合并及扩展点收集。
|
|
1206
|
+
* @param plugin - 插件对象
|
|
1207
|
+
* @param notify - 是否在注册完成后触发状态变更通知
|
|
1208
|
+
*/
|
|
1209
|
+
register(plugin: Plugin, notify?: boolean): void;
|
|
1210
|
+
/**
|
|
1211
|
+
* 初始化所有插件
|
|
1212
|
+
* @param sharedContext 共享上下文
|
|
1213
|
+
*/
|
|
1214
|
+
initPlugins(sharedContext?: Record<string, any>): Promise<void>;
|
|
1215
|
+
/**
|
|
1216
|
+
* 获取排序后的插件 ID 列表 (处理依赖)
|
|
1217
|
+
*/
|
|
1218
|
+
private getSortedPluginIds;
|
|
1219
|
+
/**
|
|
1220
|
+
* 加载插件列表
|
|
1221
|
+
* @param configs 插件配置
|
|
1222
|
+
* @param registry 插件注册表 (动态导入函数)
|
|
1223
|
+
*/
|
|
1224
|
+
loadPlugins(configs: Record<string, any>, registry: Record<string, () => Promise<any>>): Promise<void>;
|
|
1225
|
+
/**
|
|
1226
|
+
* 加载远程插件
|
|
1227
|
+
* @param pluginId 插件 ID
|
|
1228
|
+
* @param url 远程 URL
|
|
1229
|
+
* @param config 插件配置
|
|
1230
|
+
*/
|
|
1231
|
+
loadRemotePlugin(pluginId: string, url: string, config: any): Promise<Plugin | null>;
|
|
1232
|
+
/**
|
|
1233
|
+
* IIFE 模式加载插件
|
|
1234
|
+
*/
|
|
1235
|
+
private loadIIFEPlugin;
|
|
1236
|
+
/**
|
|
1237
|
+
* 实例化插件
|
|
1238
|
+
*/
|
|
1239
|
+
private instantiatePlugin;
|
|
1240
|
+
private validatePlugin;
|
|
1241
|
+
private handleBusinessPlugin;
|
|
1242
|
+
private handleFunctionalPlugin;
|
|
1243
|
+
private handleViewPlugin;
|
|
1244
|
+
private handleThemePlugin;
|
|
1245
|
+
private handleSystemPlugin;
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* 全局插件管理器实例
|
|
1249
|
+
*/
|
|
1250
|
+
declare const pluginManager: PluginManager;
|
|
1251
|
+
|
|
1252
|
+
/**
|
|
1253
|
+
* @file plugin-runtime.ts
|
|
1254
|
+
* @description 插件运行时,封装单个插件的生命周期(load/mount/unmount)、沙箱环境和隔离上下文
|
|
4
1255
|
* @author ChatBI Team
|
|
5
1256
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* 插件运行时类
|
|
1260
|
+
* @description 为单个插件提供独立的运行环境,负责管理其生命周期、初始化沙箱环境并组装上下文对象。
|
|
1261
|
+
*/
|
|
1262
|
+
declare class PluginRuntime {
|
|
1263
|
+
/** 插件定义对象 */
|
|
1264
|
+
plugin: Plugin;
|
|
1265
|
+
/** 传递给插件的上下文对象 */
|
|
1266
|
+
context: PluginContext;
|
|
1267
|
+
/** 存储沙箱隔离设施 */
|
|
1268
|
+
private storageSandbox;
|
|
1269
|
+
/** Window/全局对象沙箱隔离设施 */
|
|
1270
|
+
private windowSandbox;
|
|
1271
|
+
/** 是否已完成加载阶段 */
|
|
1272
|
+
private isLoaded;
|
|
1273
|
+
/** 是否已完成挂载阶段 */
|
|
1274
|
+
private isMounted;
|
|
1275
|
+
/** 运行时捕获的错误信息 */
|
|
1276
|
+
private error;
|
|
1277
|
+
/**
|
|
1278
|
+
* 构造函数
|
|
1279
|
+
* @param plugin - 插件定义对象
|
|
1280
|
+
* @param sharedContext - 来自内核的共享上下文资源 (如 API 引擎、事件总线)
|
|
1281
|
+
* @param storageManager - 全局存储管理器
|
|
1282
|
+
*/
|
|
1283
|
+
constructor(plugin: Plugin, sharedContext: Record<string, any>, storageManager: StorageManager);
|
|
1284
|
+
/**
|
|
1285
|
+
* 执行插件的加载逻辑 (onLoad)
|
|
1286
|
+
* @description 此阶段会自动注册插件声明的 API 配置,并调用插件的 onLoad 钩子。
|
|
1287
|
+
* 用于执行非 UI 的初始化逻辑,如注册服务、拦截器等。
|
|
1288
|
+
*/
|
|
1289
|
+
load(): Promise<void>;
|
|
1290
|
+
/**
|
|
1291
|
+
* 执行插件的挂载逻辑 (onMount)
|
|
1292
|
+
* @description 此阶段会激活 Window 沙箱并调用插件的 onMount 钩子。
|
|
1293
|
+
* 此时插件的 UI 组件(如有)即将或已经进入 DOM。
|
|
1294
|
+
*/
|
|
1295
|
+
mount(): Promise<void>;
|
|
1296
|
+
/**
|
|
1297
|
+
* 执行插件的卸载逻辑 (onUnmount)
|
|
1298
|
+
* @description 调用插件的 onUnmount 钩子并停用沙箱。
|
|
1299
|
+
*/
|
|
1300
|
+
unmount(): Promise<void>;
|
|
1301
|
+
/**
|
|
1302
|
+
* 彻底销毁插件实例
|
|
1303
|
+
* @description 卸载插件并重置加载状态。
|
|
1304
|
+
*/
|
|
1305
|
+
destroy(): Promise<void>;
|
|
1306
|
+
/**
|
|
1307
|
+
* 设置运行时错误 (内部使用)
|
|
1308
|
+
* @internal
|
|
1309
|
+
*/
|
|
1310
|
+
_setError(error: Error | null): void;
|
|
1311
|
+
/**
|
|
1312
|
+
* 获取插件运行时错误
|
|
1313
|
+
*/
|
|
1314
|
+
getError(): Error | null;
|
|
1315
|
+
/**
|
|
1316
|
+
* 获取插件当前运行状态
|
|
1317
|
+
* @returns 'error' | 'mounted' | 'loaded' | 'initial'
|
|
1318
|
+
*/
|
|
1319
|
+
get status(): "error" | "mounted" | "loaded" | "initial";
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* 插件隔离沙箱
|
|
1324
|
+
* @description 核心领域服务,为每个插件实例创建独立的运行上下文。
|
|
1325
|
+
* 它是插件与系统核心之间的“中间层”,确保插件只能访问其权限范围内的资源。
|
|
1326
|
+
* 主要职责:
|
|
1327
|
+
* 1. 存储隔离:确保插件只能读写属于自己的 LocalStorage 命名空间。
|
|
1328
|
+
* 2. 日志隔离:为插件提供带有自身 ID 前缀的日志输出,方便调试。
|
|
1329
|
+
*/
|
|
1330
|
+
declare class PluginSandbox {
|
|
1331
|
+
/** 关联的插件唯一标识 */
|
|
1332
|
+
private pluginId;
|
|
1333
|
+
/** 系统全局存储管理器 */
|
|
1334
|
+
private storageManager;
|
|
1335
|
+
/**
|
|
1336
|
+
* 构造插件沙箱
|
|
1337
|
+
* @param pluginId - 插件 ID
|
|
1338
|
+
* @param storageManager - 系统存储管理器实例
|
|
1339
|
+
*/
|
|
1340
|
+
constructor(pluginId: string, storageManager: StorageManager);
|
|
1341
|
+
/**
|
|
1342
|
+
* 获取隔离的存储接口
|
|
1343
|
+
* @description 返回一个受限的 StoragePort,所有操作都会自动带上插件 ID 前缀。
|
|
1344
|
+
*/
|
|
1345
|
+
get storage(): {
|
|
1346
|
+
shared: {
|
|
1347
|
+
get: <T = any>(key: string) => T | null;
|
|
1348
|
+
set: <T = any>(key: string, value: T) => void;
|
|
1349
|
+
remove: (key: string) => void;
|
|
1350
|
+
};
|
|
1351
|
+
get: <T = any>(key: string) => T | null;
|
|
1352
|
+
set: <T = any>(key: string, value: T) => void;
|
|
1353
|
+
remove: (key: string) => void;
|
|
1354
|
+
};
|
|
1355
|
+
/**
|
|
1356
|
+
* 获取隔离的日志接口
|
|
1357
|
+
* @description 返回一个带插件 ID 前缀的 Logger 实例。
|
|
1358
|
+
*/
|
|
1359
|
+
get logger(): Logger;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* 浏览器本地存储 (LocalStorage) 适配器
|
|
1364
|
+
* @description 实现 `StoragePort` 接口,封装了对原生 `localStorage` 的访问。
|
|
1365
|
+
* 支持可选的命名空间前缀隔离,确保在同一个域下不同模块的数据互不干扰。
|
|
1366
|
+
*/
|
|
1367
|
+
declare class LocalStorageAdapter implements StoragePort {
|
|
1368
|
+
/** 命名空间前缀,所有存入的键名都会自动添加此前缀 */
|
|
1369
|
+
private prefix;
|
|
1370
|
+
/**
|
|
1371
|
+
* 初始化适配器
|
|
1372
|
+
* @param prefix - 可选的命名空间前缀(如 'chatbi'),默认为空字符串
|
|
1373
|
+
*/
|
|
1374
|
+
constructor(prefix?: string);
|
|
1375
|
+
/**
|
|
1376
|
+
* 内部方法:计算实际存储的键名
|
|
1377
|
+
* @param key - 业务层传入的原始键名
|
|
1378
|
+
* @returns 拼接前缀后的物理键名
|
|
1379
|
+
*/
|
|
1380
|
+
private getKey;
|
|
1381
|
+
/**
|
|
1382
|
+
* 内部方法:从物理键名还原业务键名
|
|
1383
|
+
* @param namespacedKey - 物理存储中的完整键名
|
|
1384
|
+
* @returns 还原后的原始键名,若前缀不匹配则返回 null
|
|
1385
|
+
*/
|
|
1386
|
+
private getOriginalKey;
|
|
1387
|
+
/**
|
|
1388
|
+
* 读取存储项
|
|
1389
|
+
* @param key - 原始键名
|
|
1390
|
+
* @returns 存储的字符串内容,不存在则返回 null
|
|
1391
|
+
*/
|
|
1392
|
+
getItem(key: string): string | null;
|
|
1393
|
+
/**
|
|
1394
|
+
* 写入存储项
|
|
1395
|
+
* @param key - 原始键名
|
|
1396
|
+
* @param value - 待存储的字符串值
|
|
1397
|
+
*/
|
|
1398
|
+
setItem(key: string, value: string): void;
|
|
1399
|
+
/**
|
|
1400
|
+
* 移除特定的存储项
|
|
1401
|
+
* @param key - 原始键名
|
|
1402
|
+
*/
|
|
1403
|
+
removeItem(key: string): void;
|
|
1404
|
+
/**
|
|
1405
|
+
* 清空存储空间
|
|
1406
|
+
* @description
|
|
1407
|
+
* - 若定义了前缀:仅删除以该前缀开头的键名,不影响其他数据。
|
|
1408
|
+
* - 若未定义前缀:调用原生 `localStorage.clear()` 清空所有数据。
|
|
1409
|
+
*/
|
|
1410
|
+
clear(): void;
|
|
1411
|
+
/**
|
|
1412
|
+
* 返回当前命名空间下的存储项总数
|
|
1413
|
+
*/
|
|
1414
|
+
get length(): number;
|
|
1415
|
+
/**
|
|
1416
|
+
* 根据索引获取对应的原始键名
|
|
1417
|
+
* @param index - 索引位置
|
|
1418
|
+
* @returns 对应的业务键名,不存在则返回 null
|
|
1419
|
+
*/
|
|
1420
|
+
key(index: number): string | null;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
/**
|
|
1424
|
+
* 作用域存储适配器 (ScopedStorageAdapter)
|
|
1425
|
+
* @description 采用装饰器模式实现。它包装一个现有的 `StoragePort` 实例,
|
|
1426
|
+
* 并为所有存储操作透明地注入一个前缀(命名空间),从而实现逻辑上的存储隔离。
|
|
1427
|
+
* 常用于为插件分配独立的存储空间,而无需修改插件代码。
|
|
1428
|
+
*/
|
|
1429
|
+
declare class ScopedStorageAdapter implements StoragePort {
|
|
1430
|
+
private underlyingStorage;
|
|
1431
|
+
private prefix;
|
|
1432
|
+
/**
|
|
1433
|
+
* 初始化作用域适配器
|
|
1434
|
+
* @param underlyingStorage - 被装饰的底层存储适配器实例
|
|
1435
|
+
* @param prefix - 用于隔离的作用域前缀字符串
|
|
1436
|
+
*/
|
|
1437
|
+
constructor(underlyingStorage: StoragePort, prefix: string);
|
|
1438
|
+
/**
|
|
1439
|
+
* 内部方法:计算实际存储的键名
|
|
1440
|
+
* @param key - 业务层传入的原始键名
|
|
1441
|
+
* @returns 拼接前缀后的物理键名
|
|
1442
|
+
*/
|
|
1443
|
+
private getKey;
|
|
1444
|
+
/**
|
|
1445
|
+
* 内部方法:从物理键名还原业务键名
|
|
1446
|
+
* @param namespacedKey - 物理存储中的完整键名
|
|
1447
|
+
* @returns 还原后的原始键名,若前缀不匹配则返回 null
|
|
1448
|
+
*/
|
|
1449
|
+
private getOriginalKey;
|
|
1450
|
+
/**
|
|
1451
|
+
* 读取当前作用域下的存储项
|
|
1452
|
+
* @param key - 原始键名
|
|
1453
|
+
* @returns 字符串内容,不存在则返回 null
|
|
1454
|
+
*/
|
|
1455
|
+
getItem(key: string): string | null;
|
|
1456
|
+
/**
|
|
1457
|
+
* 写入当前作用域下的存储项
|
|
1458
|
+
* @param key - 原始键名
|
|
1459
|
+
* @param value - 字符串内容
|
|
1460
|
+
*/
|
|
1461
|
+
setItem(key: string, value: string): void;
|
|
1462
|
+
/**
|
|
1463
|
+
* 移除当前作用域下的特定存储项
|
|
1464
|
+
* @param key - 原始键名
|
|
1465
|
+
*/
|
|
1466
|
+
removeItem(key: string): void;
|
|
1467
|
+
/**
|
|
1468
|
+
* 清空当前作用域下的所有存储项
|
|
1469
|
+
* @description 仅删除匹配当前前缀的键值对,不会影响底层存储中的其他数据。
|
|
1470
|
+
*/
|
|
1471
|
+
clear(): void;
|
|
1472
|
+
/**
|
|
1473
|
+
* 返回当前作用域下的存储项总数
|
|
1474
|
+
*/
|
|
1475
|
+
get length(): number;
|
|
1476
|
+
/**
|
|
1477
|
+
* 根据索引获取当前作用域下的原始键名
|
|
1478
|
+
* @param index - 索引位置
|
|
1479
|
+
* @returns 对应的业务键名,不存在则返回 null
|
|
1480
|
+
*/
|
|
1481
|
+
key(index: number): string | null;
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
interface PluginProviderProps {
|
|
1485
|
+
manager: PluginManager;
|
|
1486
|
+
children: React.ReactNode;
|
|
1487
|
+
}
|
|
1488
|
+
declare const PluginProvider: React.FC<PluginProviderProps>;
|
|
1489
|
+
declare const usePluginManager: () => PluginManager;
|
|
1490
|
+
|
|
1491
|
+
/**
|
|
1492
|
+
* ProxySandbox 类
|
|
1493
|
+
* @description 基于 Proxy 的 JS 沙箱实现,模拟独立的 Window 环境
|
|
1494
|
+
*/
|
|
1495
|
+
declare class ProxySandbox {
|
|
1496
|
+
/** 沙箱名称 */
|
|
1497
|
+
name: string;
|
|
1498
|
+
/** 代理后的 Window 对象 */
|
|
1499
|
+
proxy: WindowProxy;
|
|
1500
|
+
/** 沙箱是否激活 */
|
|
1501
|
+
running: boolean;
|
|
1502
|
+
/** 记录新增/修改的全局变量 */
|
|
1503
|
+
private updatedValueSet;
|
|
1504
|
+
/** 绑定函数的缓存池,避免重复 bind 带来的性能开销 */
|
|
1505
|
+
private boundFunctionCache;
|
|
1506
|
+
/** 副作用记录池 */
|
|
1507
|
+
private effectPool;
|
|
1508
|
+
/** 真实的 Window 对象 */
|
|
1509
|
+
private globalContext;
|
|
1510
|
+
/** 白名单全局变量(允许透传访问真实 Window) */
|
|
1511
|
+
private static globalWhitelist;
|
|
1512
|
+
constructor(name: string, globalContext?: Window & typeof globalThis);
|
|
1513
|
+
/**
|
|
1514
|
+
* 激活沙箱
|
|
1515
|
+
*/
|
|
1516
|
+
active(): void;
|
|
1517
|
+
/**
|
|
1518
|
+
* 销毁沙箱
|
|
1519
|
+
*/
|
|
1520
|
+
inactive(): void;
|
|
1521
|
+
/**
|
|
1522
|
+
* 在沙箱中执行代码
|
|
1523
|
+
* @param code JS 代码字符串
|
|
1524
|
+
* @returns 执行结果
|
|
1525
|
+
*/
|
|
1526
|
+
eval(code: string): any;
|
|
1527
|
+
/**
|
|
1528
|
+
* 创建伪造的 Window 对象
|
|
1529
|
+
*/
|
|
1530
|
+
private createFakeWindow;
|
|
1531
|
+
private isConstructor;
|
|
1532
|
+
private isNativeFunction;
|
|
1533
|
+
/**
|
|
1534
|
+
* 劫持全局副作用 API
|
|
1535
|
+
*/
|
|
1536
|
+
private patchGlobalEffects;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
/**
|
|
1540
|
+
* 日志等级枚举
|
|
1541
|
+
*/
|
|
1542
|
+
declare enum LogLevel {
|
|
1543
|
+
/** 调试级别:输出最详尽的信息 */
|
|
1544
|
+
DEBUG = 0,
|
|
1545
|
+
/** 信息级别:输出重要的运行状态 */
|
|
1546
|
+
INFO = 1,
|
|
1547
|
+
/** 警告级别:输出潜在的问题,但不影响运行 */
|
|
1548
|
+
WARN = 2,
|
|
1549
|
+
/** 错误级别:输出严重的运行异常 */
|
|
1550
|
+
ERROR = 3,
|
|
1551
|
+
/** 禁用日志:不输出任何信息 */
|
|
1552
|
+
NONE = 4
|
|
1553
|
+
}
|
|
1554
|
+
/**
|
|
1555
|
+
* 日志工具类
|
|
1556
|
+
* @description 核心工具类,提供统一的日志输出格式 `[Prefix] Message`。
|
|
1557
|
+
* 支持通过 `LogLevel` 进行全局过滤。
|
|
1558
|
+
* 支持日志缓冲和自动分组,以减少控制台噪音。
|
|
1559
|
+
* 支持浏览器端 CSS 样式和 Node.js 端 ANSI 颜色。
|
|
1560
|
+
*/
|
|
1561
|
+
declare class Logger {
|
|
1562
|
+
/** 全局静态日志等级,所有实例共享 */
|
|
1563
|
+
private static level;
|
|
1564
|
+
/** 日志缓冲区 */
|
|
1565
|
+
private static buffer;
|
|
1566
|
+
/** 缓冲输出防抖定时器 */
|
|
1567
|
+
private static flushTimer;
|
|
1568
|
+
/** 缓冲时间窗口 (ms) */
|
|
1569
|
+
private static FLUSH_INTERVAL;
|
|
1570
|
+
/** 是否启用缓冲模式 */
|
|
1571
|
+
private static bufferEnabled;
|
|
1572
|
+
/** 是否为浏览器环境 */
|
|
1573
|
+
private static isBrowser;
|
|
1574
|
+
/** 当前实例的业务模块前缀 */
|
|
1575
|
+
private prefix;
|
|
1576
|
+
/** 实例特定的颜色 */
|
|
1577
|
+
private color;
|
|
1578
|
+
/**
|
|
1579
|
+
* 构造函数
|
|
1580
|
+
* @param prefix - 业务模块前缀,默认为 'App'
|
|
1581
|
+
*/
|
|
1582
|
+
constructor(prefix?: string);
|
|
1583
|
+
/**
|
|
1584
|
+
* 静态方法:设置全局日志输出等级
|
|
1585
|
+
* @param level - 目标日志等级
|
|
1586
|
+
*/
|
|
1587
|
+
static setLevel(level: LogLevel): void;
|
|
1588
|
+
/**
|
|
1589
|
+
* 静态方法:启用或禁用日志缓冲
|
|
1590
|
+
* @param enabled - 是否启用
|
|
1591
|
+
*/
|
|
1592
|
+
static setBufferEnabled(enabled: boolean): void;
|
|
1593
|
+
/**
|
|
1594
|
+
* 静态方法:获取当前全局日志等级
|
|
1595
|
+
* @returns 当前生效的全局日志等级
|
|
1596
|
+
*/
|
|
1597
|
+
static getLevel(): LogLevel;
|
|
1598
|
+
/**
|
|
1599
|
+
* 格式化输出前缀
|
|
1600
|
+
*/
|
|
1601
|
+
private getFormattedPrefix;
|
|
1602
|
+
/**
|
|
1603
|
+
* 生成分组标题参数
|
|
1604
|
+
*/
|
|
1605
|
+
private static getGroupTitleArgs;
|
|
1606
|
+
/**
|
|
1607
|
+
* 内部方法:将日志推入缓冲区或直接输出
|
|
1608
|
+
*/
|
|
1609
|
+
private log;
|
|
1610
|
+
/**
|
|
1611
|
+
* 静态方法:刷新缓冲区,分组输出日志
|
|
1612
|
+
*/
|
|
1613
|
+
static flush(): void;
|
|
1614
|
+
/**
|
|
1615
|
+
* 打印 DEBUG 级别日志
|
|
1616
|
+
*/
|
|
1617
|
+
debug(...args: any[]): void;
|
|
1618
|
+
/**
|
|
1619
|
+
* 打印 INFO 级别日志
|
|
1620
|
+
*/
|
|
1621
|
+
info(...args: any[]): void;
|
|
1622
|
+
/**
|
|
1623
|
+
* 打印 WARN 级别日志
|
|
1624
|
+
*/
|
|
1625
|
+
warn(...args: any[]): void;
|
|
1626
|
+
/**
|
|
1627
|
+
* 打印 ERROR 级别日志
|
|
1628
|
+
*/
|
|
1629
|
+
error(...args: any[]): void;
|
|
1630
|
+
/**
|
|
1631
|
+
* 开始一个日志控制台分组
|
|
1632
|
+
*/
|
|
1633
|
+
group(label: string, collapsed?: boolean): void;
|
|
1634
|
+
/**
|
|
1635
|
+
* 结束当前日志控制台分组
|
|
1636
|
+
*/
|
|
1637
|
+
groupEnd(): void;
|
|
1638
|
+
}
|
|
1639
|
+
/** 默认 Logger 实例 */
|
|
1640
|
+
declare const logger: Logger;
|
|
1641
|
+
/**
|
|
1642
|
+
* 创建带特定前缀的 Logger 实例
|
|
1643
|
+
* @param prefix 日志前缀
|
|
1644
|
+
* @returns Logger 实例
|
|
1645
|
+
*/
|
|
1646
|
+
declare const createLogger: (prefix: string) => Logger;
|
|
1647
|
+
|
|
1648
|
+
/**
|
|
1649
|
+
* 日期时间格式化工具类
|
|
1650
|
+
*/
|
|
1651
|
+
declare const dateUtils: {
|
|
1652
|
+
/**
|
|
1653
|
+
* 格式化日期为 YYYY-MM-DD
|
|
1654
|
+
*/
|
|
1655
|
+
formatDate(date?: dayjs.ConfigType): string;
|
|
1656
|
+
/**
|
|
1657
|
+
* 格式化时间为 HH:mm:ss
|
|
1658
|
+
*/
|
|
1659
|
+
formatTime(date?: dayjs.ConfigType): string;
|
|
1660
|
+
/**
|
|
1661
|
+
* 格式化日期时间为 YYYY-MM-DD HH:mm:ss
|
|
1662
|
+
*/
|
|
1663
|
+
formatDateTime(date?: dayjs.ConfigType): string;
|
|
1664
|
+
/**
|
|
1665
|
+
* 获取当前时间戳(毫秒)
|
|
1666
|
+
*/
|
|
1667
|
+
now(): number;
|
|
1668
|
+
/**
|
|
1669
|
+
* 获取相对时间(例如:几分钟前)
|
|
1670
|
+
*/
|
|
1671
|
+
fromNow(date: dayjs.ConfigType): string;
|
|
1672
|
+
/**
|
|
1673
|
+
* 原始 dayjs 对象,用于更复杂的场景
|
|
1674
|
+
*/
|
|
1675
|
+
dayjs: typeof dayjs;
|
|
1676
|
+
};
|
|
1677
|
+
|
|
1678
|
+
type KeepStrategy = 'first' | 'last' | 'search' | 'hash';
|
|
1679
|
+
/**
|
|
1680
|
+
* 把当前地址中所有出现的参数合并成一份。
|
|
1681
|
+
* 重复 key 的处理策略:
|
|
1682
|
+
* - 'first' : 按出现顺序,第一次的值生效
|
|
1683
|
+
* - 'last' : 按出现顺序,最后一次的值生效(默认,最直观)
|
|
1684
|
+
* - 'search' : 只要 search 里出现过,就用 search 的
|
|
1685
|
+
* - 'hash' : 只要 hash 里出现过,就用 hash 的
|
|
1686
|
+
*/
|
|
1687
|
+
declare function normalizeParams(strategy?: KeepStrategy): URLSearchParams;
|
|
1688
|
+
/**
|
|
1689
|
+
* 清除 URL 中的特定参数并返回新的 URL
|
|
1690
|
+
* @description 同时处理 search 和 hash 中的参数
|
|
1691
|
+
*/
|
|
1692
|
+
declare function cleanUrlParams(keysToRemove: string[]): string;
|
|
1693
|
+
|
|
1694
|
+
declare const version = "1.0.0";
|
|
1695
|
+
|
|
1696
|
+
/**
|
|
1697
|
+
* Hook 配置选项
|
|
1698
|
+
*/
|
|
1699
|
+
interface UseStorageStateOptions<T> {
|
|
1700
|
+
defaultValue?: T;
|
|
1701
|
+
scope?: 'plugin' | 'shared';
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* 统一存储状态 Hook
|
|
1705
|
+
* @description 提供与 StorageManager 和 Schema Registry 集成的持久化状态 Hook。
|
|
1706
|
+
* @param pluginId 定义该 Key 的插件 ID
|
|
1707
|
+
* @param key 存储键名 (必须在 Schema 中注册)
|
|
1708
|
+
* @param options 配置项,包含默认值和作用域
|
|
1709
|
+
*/
|
|
1710
|
+
declare function useStorageState<T>(pluginId: string, key: string, options?: UseStorageStateOptions<T>): [T, (value: T | ((val: T) => T)) => void];
|
|
1711
|
+
|
|
1712
|
+
/** 插件加载 Hook 的配置选项 */
|
|
1713
|
+
interface PluginLoaderOptions {
|
|
1714
|
+
/** 插件发现规则,定义如何从模块列表中识别插件 */
|
|
1715
|
+
discoveryRules?: any[];
|
|
1716
|
+
/** 插件模块映射,通常由 Vite 的 `import.meta.glob` 生成,键为路径,值为加载函数 */
|
|
1717
|
+
modules?: Record<string, () => Promise<any>>;
|
|
1718
|
+
/** 预注册的插件注册表,用于手动指定插件加载逻辑,优先级高于自动发现 */
|
|
1719
|
+
registry?: Record<string, () => Promise<any>>;
|
|
1720
|
+
/** 插件的业务配置映射,键为插件 ID */
|
|
1721
|
+
pluginConfigs: Record<string, any>;
|
|
1722
|
+
/** 初始化的共享上下文服务,将注入到每个插件的 onLoad 中 */
|
|
1723
|
+
sharedContext?: Record<string, any>;
|
|
1724
|
+
/** 系统级全局配置,如标题、版本号、Logo 等 */
|
|
1725
|
+
systemConfig?: Record<string, any>;
|
|
1726
|
+
/** 资源发现的基础 URL,默认为当前 window.location.origin */
|
|
1727
|
+
baseUrl?: string;
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* 核心 Hook:通用插件加载器
|
|
1731
|
+
* @description 负责应用启动时的插件全生命周期管理:
|
|
1732
|
+
* 1. 自动发现:解析 modules 并根据规则识别插件。
|
|
1733
|
+
* 2. 注册:将插件信息录入 PluginManager。
|
|
1734
|
+
* 3. 加载:调用插件的加载逻辑 (onLoad)。
|
|
1735
|
+
* 4. 初始化:调用插件的挂载逻辑 (onMount)。
|
|
1736
|
+
* 5. 响应式更新:订阅插件状态变更并触发 UI 刷新。
|
|
1737
|
+
*
|
|
1738
|
+
* @param options - 加载配置项
|
|
1739
|
+
* @returns { pluginsLoaded: boolean, pluginVersion: number }
|
|
1740
|
+
* - pluginsLoaded: 插件是否已全部完成初始化
|
|
1741
|
+
* - pluginVersion: 插件状态版本号,用于强制触发依赖插件状态的组件重渲染
|
|
1742
|
+
*/
|
|
1743
|
+
declare const usePluginLoader: (options: PluginLoaderOptions) => {
|
|
1744
|
+
pluginsLoaded: boolean;
|
|
1745
|
+
pluginVersion: number;
|
|
1746
|
+
};
|
|
1747
|
+
|
|
1748
|
+
export { type ApiAdapter, type ApiConfig, type ApiEndpointConfig, ApiEngine, type ApiInterceptor, ApiProvider, type ApiProviderProps, type ApiRequestConfig, type ApiResponseContext, AvatarSkeleton, AxiosAdapter, BasePlugin, type BaseResponse, BlockSkeleton, ConfigManager, DefaultEventBus, type DiscoveryRule, type ErrorStrategy, type EventBus, type EventBusPort, type EventCallback, type HttpMethod, LocalStorageAdapter, LogLevel, Logger, PLUGIN_TYPES, type Plugin, type PluginCapabilities, type PluginConfigItem, type PluginContext, PluginErrorBoundary, type PluginExtension, type PluginLifecycle, type PluginLoaderOptions, PluginManager, type PluginMetadata, PluginProvider, type PluginProviderProps, type PluginRegistry, PluginRuntime, PluginSandbox, PluginSlot, type PluginStorage, type PluginType, ProxySandbox, type RequestOptions, type RouteConfig, SUCCESS_CODE, type Scene, ScopedStorageAdapter, ServiceRegistry, SidebarIconSkeleton, Slot, type SlotPosition, SlotSkeletons, type SlotType, StatusBarItemSkeleton, type StorageItemSchema, StorageManager, type StoragePort, type StreamCallbacks, type TypedStorage, type UseStorageStateOptions, apiEngine, cleanUrlParams, configManager, createLogger, dateUtils, definePlugin, isMockMode, logger, normalizeParams, pluginManager, resolveApiModules, resolvePluginRegistry, serviceRegistry, useApi, usePluginLoader, usePluginManager, useStorageState, version };
|