@chatbi-v/core 2.1.9 → 3.0.0
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/adapter/index.cjs +208 -0
- package/dist/adapter/index.d.cts +201 -0
- package/dist/adapter/index.d.ts +201 -0
- package/dist/adapter/index.mjs +10 -0
- package/dist/chunk-BOR237QK.mjs +180 -0
- package/dist/index.cjs +4725 -1980
- package/dist/index.d.cts +2824 -808
- package/dist/index.d.ts +2824 -808
- package/dist/index.mjs +5348 -0
- package/package.json +19 -11
- package/dist/chunk-WCD7UAPU.js +0 -50
- package/dist/config-manager-LIF5OXKM.js +0 -8
- package/dist/index.js +0 -2765
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,543 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as zustand from 'zustand';
|
|
3
|
+
import * as zustand_middleware from 'zustand/middleware';
|
|
4
|
+
export { AdapterFactory, AdapterRegistry, AdapterState, AdapterStatus, BaseAdapter, TransformOptions, UIAdapter, adapterRegistry } from './adapter/index.cjs';
|
|
3
5
|
import dayjs from 'dayjs';
|
|
4
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @file branded.ts
|
|
9
|
+
* @description 品牌类型 (Branded Types) - 用于创建防错的标识符类型
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 创建品牌类型的工具类型
|
|
14
|
+
* @description 使用 string literal type 作为 Brand,实现编译时类型区分
|
|
15
|
+
*/
|
|
16
|
+
type brand<T, Brand extends string> = T & {
|
|
17
|
+
__brand: Brand;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* PluginId 品牌类型
|
|
21
|
+
* @description 用于标识插件的唯一 ID,通过编译时类型防止字符串类型混淆
|
|
22
|
+
*/
|
|
23
|
+
type PluginId = brand<string, 'PluginId'>;
|
|
24
|
+
/**
|
|
25
|
+
* SlotKey 品牌类型
|
|
26
|
+
* @description 用于标识插槽位置的唯一键,通过编译时类型防止字符串类型混淆
|
|
27
|
+
*/
|
|
28
|
+
type SlotKey = brand<string, 'SlotKey'>;
|
|
29
|
+
/**
|
|
30
|
+
* PluginId 的 Zod 验证 Schema
|
|
31
|
+
*/
|
|
32
|
+
declare const PluginIdSchema: z.ZodString;
|
|
33
|
+
/**
|
|
34
|
+
* SlotKey 的 Zod 验证 Schema
|
|
35
|
+
*/
|
|
36
|
+
declare const SlotKeySchema: z.ZodString;
|
|
37
|
+
/**
|
|
38
|
+
* 创建类型安全的 PluginId
|
|
39
|
+
* @param id - 插件 ID 字符串
|
|
40
|
+
* @returns 带品牌标记的 PluginId 类型
|
|
41
|
+
*/
|
|
42
|
+
declare function createPluginId(id: string): PluginId;
|
|
43
|
+
/**
|
|
44
|
+
* 创建类型安全的 SlotKey
|
|
45
|
+
* @param key - 插槽键字符串
|
|
46
|
+
* @returns 带品牌标记的 SlotKey 类型
|
|
47
|
+
*/
|
|
48
|
+
declare function createSlotKey(key: string): SlotKey;
|
|
49
|
+
/**
|
|
50
|
+
* 类型守卫:检查是否为有效的 PluginId
|
|
51
|
+
* @param value - 要检查的值
|
|
52
|
+
* @returns 是否为 PluginId 类型
|
|
53
|
+
*/
|
|
54
|
+
declare function isPluginId(value: unknown): value is PluginId;
|
|
55
|
+
/**
|
|
56
|
+
* 类型守卫:检查是否为有效的 SlotKey
|
|
57
|
+
* @param value - 要检查的值
|
|
58
|
+
* @returns 是否为 SlotKey 类型
|
|
59
|
+
*/
|
|
60
|
+
declare function isSlotKey(value: unknown): value is SlotKey;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Plugin Manifest Schema 定义
|
|
64
|
+
* @description 使用 Zod 定义声明式插件元数据 Schema,支持扩展点声明
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/** 扩展点类型 */
|
|
68
|
+
declare const EXTENSION_TYPES: readonly ["slot", "hook", "command", "service"];
|
|
69
|
+
type ExtensionType = typeof EXTENSION_TYPES[number];
|
|
70
|
+
/**
|
|
71
|
+
* 扩展点渲染模式
|
|
72
|
+
* @description 定义插槽内容的渲染方式
|
|
73
|
+
*/
|
|
74
|
+
declare const RENDER_MODES: readonly ["replace", "append", "prepend"];
|
|
75
|
+
type RenderMode = typeof RENDER_MODES[number];
|
|
76
|
+
/**
|
|
77
|
+
* 扩展点 Schema
|
|
78
|
+
* @description 定义插件提供的扩展能力
|
|
79
|
+
*/
|
|
80
|
+
declare const ExtensionSchema: z.ZodObject<{
|
|
81
|
+
/** 扩展点名称/标识符 */
|
|
82
|
+
name: z.ZodString;
|
|
83
|
+
/** 扩展点类型 */
|
|
84
|
+
type: z.ZodEnum<["slot", "hook", "command", "service"]>;
|
|
85
|
+
/** 扩展点描述 */
|
|
86
|
+
description: z.ZodOptional<z.ZodString>;
|
|
87
|
+
/** 对于 slot 类型,指定插槽位置 */
|
|
88
|
+
slot: z.ZodOptional<z.ZodString>;
|
|
89
|
+
/** 扩展点的配置选项 */
|
|
90
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
91
|
+
/**
|
|
92
|
+
* 渲染模式
|
|
93
|
+
* @description 定义插槽内容的渲染方式:replace(替换)、append(追加)、prepend(前置)
|
|
94
|
+
*/
|
|
95
|
+
renderMode: z.ZodOptional<z.ZodEnum<["replace", "append", "prepend"]>>;
|
|
96
|
+
/**
|
|
97
|
+
* 条件渲染配置
|
|
98
|
+
* @description 用于条件渲染,如 requiresAuth: true 表示需要认证
|
|
99
|
+
*/
|
|
100
|
+
condition: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
101
|
+
}, "strip", z.ZodTypeAny, {
|
|
102
|
+
name: string;
|
|
103
|
+
type: "slot" | "hook" | "command" | "service";
|
|
104
|
+
slot?: string | undefined;
|
|
105
|
+
description?: string | undefined;
|
|
106
|
+
config?: Record<string, any> | undefined;
|
|
107
|
+
renderMode?: "replace" | "append" | "prepend" | undefined;
|
|
108
|
+
condition?: Record<string, any> | undefined;
|
|
109
|
+
}, {
|
|
110
|
+
name: string;
|
|
111
|
+
type: "slot" | "hook" | "command" | "service";
|
|
112
|
+
slot?: string | undefined;
|
|
113
|
+
description?: string | undefined;
|
|
114
|
+
config?: Record<string, any> | undefined;
|
|
115
|
+
renderMode?: "replace" | "append" | "prepend" | undefined;
|
|
116
|
+
condition?: Record<string, any> | undefined;
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* 依赖项 Schema
|
|
120
|
+
* @description 定义插件依赖的其他插件
|
|
121
|
+
*/
|
|
122
|
+
declare const DependencySchema: z.ZodObject<{
|
|
123
|
+
/** 依赖插件 ID */
|
|
124
|
+
id: z.ZodString;
|
|
125
|
+
/** 依赖版本范围 (SemVer) */
|
|
126
|
+
version: z.ZodString;
|
|
127
|
+
/** 是否为可选依赖 */
|
|
128
|
+
optional: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
129
|
+
}, "strip", z.ZodTypeAny, {
|
|
130
|
+
id: string;
|
|
131
|
+
version: string;
|
|
132
|
+
optional: boolean;
|
|
133
|
+
}, {
|
|
134
|
+
id: string;
|
|
135
|
+
version: string;
|
|
136
|
+
optional?: boolean | undefined;
|
|
137
|
+
}>;
|
|
138
|
+
/** 插件类型 */
|
|
139
|
+
declare const PLUGIN_TYPES: readonly ["business", "functional", "view", "theme", "renderer", "system"];
|
|
140
|
+
type PluginType = typeof PLUGIN_TYPES[number];
|
|
141
|
+
/**
|
|
142
|
+
* 入口点 Schema
|
|
143
|
+
* @description 定义插件入口文件位置
|
|
144
|
+
*/
|
|
145
|
+
declare const EntrySchema: z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
146
|
+
/** 入口文件 URL */
|
|
147
|
+
url: z.ZodString;
|
|
148
|
+
/** 共享作用域 (用于模块联邦) */
|
|
149
|
+
shareScope: z.ZodOptional<z.ZodString>;
|
|
150
|
+
}, "strip", z.ZodTypeAny, {
|
|
151
|
+
url: string;
|
|
152
|
+
shareScope?: string | undefined;
|
|
153
|
+
}, {
|
|
154
|
+
url: string;
|
|
155
|
+
shareScope?: string | undefined;
|
|
156
|
+
}>]>;
|
|
157
|
+
/**
|
|
158
|
+
* 兼容性 Schema
|
|
159
|
+
* @description 定义插件兼容的宿主环境版本
|
|
160
|
+
*/
|
|
161
|
+
declare const CompatibilitySchema: z.ZodObject<{
|
|
162
|
+
/** 最低宿主版本 */
|
|
163
|
+
minVersion: z.ZodOptional<z.ZodString>;
|
|
164
|
+
/** 最高宿主版本 */
|
|
165
|
+
maxVersion: z.ZodOptional<z.ZodString>;
|
|
166
|
+
/** 兼容的宿主版本列表 */
|
|
167
|
+
supportedVersions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
168
|
+
}, "strip", z.ZodTypeAny, {
|
|
169
|
+
minVersion?: string | undefined;
|
|
170
|
+
maxVersion?: string | undefined;
|
|
171
|
+
supportedVersions?: string[] | undefined;
|
|
172
|
+
}, {
|
|
173
|
+
minVersion?: string | undefined;
|
|
174
|
+
maxVersion?: string | undefined;
|
|
175
|
+
supportedVersions?: string[] | undefined;
|
|
176
|
+
}>;
|
|
177
|
+
/** 权限动作类型 */
|
|
178
|
+
declare const PERMISSION_ACTIONS: readonly ["read", "write", "execute", "admin"];
|
|
179
|
+
type PermissionAction = typeof PERMISSION_ACTIONS[number];
|
|
180
|
+
/** 权限作用域类型 */
|
|
181
|
+
declare const PERMISSION_SCOPES: readonly ["plugin", "global", "user"];
|
|
182
|
+
type PermissionScope = typeof PERMISSION_SCOPES[number];
|
|
183
|
+
/**
|
|
184
|
+
* Plugin Manifest Schema - 声明式插件元数据
|
|
185
|
+
* @description 定义插件的静态属性,用于插件市场展示、权限校验和内核加载
|
|
186
|
+
*/
|
|
187
|
+
declare const PluginManifestSchema: z.ZodObject<{
|
|
188
|
+
/** 插件唯一 ID (推荐反向域名格式) */
|
|
189
|
+
id: z.ZodString;
|
|
190
|
+
/** 插件版本号 (SemVer) */
|
|
191
|
+
version: z.ZodEffects<z.ZodString, string, string>;
|
|
192
|
+
/** 插件显示名称 */
|
|
193
|
+
name: z.ZodString;
|
|
194
|
+
/** 插件入口 */
|
|
195
|
+
entry: z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
196
|
+
/** 入口文件 URL */
|
|
197
|
+
url: z.ZodString;
|
|
198
|
+
/** 共享作用域 (用于模块联邦) */
|
|
199
|
+
shareScope: z.ZodOptional<z.ZodString>;
|
|
200
|
+
}, "strip", z.ZodTypeAny, {
|
|
201
|
+
url: string;
|
|
202
|
+
shareScope?: string | undefined;
|
|
203
|
+
}, {
|
|
204
|
+
url: string;
|
|
205
|
+
shareScope?: string | undefined;
|
|
206
|
+
}>]>;
|
|
207
|
+
/** 插件类型 */
|
|
208
|
+
type: z.ZodDefault<z.ZodOptional<z.ZodEnum<["business", "functional", "view", "theme", "renderer", "system"]>>>;
|
|
209
|
+
/** 插件功能描述 */
|
|
210
|
+
description: z.ZodOptional<z.ZodString>;
|
|
211
|
+
/** 插件作者 */
|
|
212
|
+
author: z.ZodOptional<z.ZodString>;
|
|
213
|
+
/** 插件图标 */
|
|
214
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
215
|
+
/** 兼容性要求 */
|
|
216
|
+
compatibility: z.ZodOptional<z.ZodObject<{
|
|
217
|
+
/** 最低宿主版本 */
|
|
218
|
+
minVersion: z.ZodOptional<z.ZodString>;
|
|
219
|
+
/** 最高宿主版本 */
|
|
220
|
+
maxVersion: z.ZodOptional<z.ZodString>;
|
|
221
|
+
/** 兼容的宿主版本列表 */
|
|
222
|
+
supportedVersions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
223
|
+
}, "strip", z.ZodTypeAny, {
|
|
224
|
+
minVersion?: string | undefined;
|
|
225
|
+
maxVersion?: string | undefined;
|
|
226
|
+
supportedVersions?: string[] | undefined;
|
|
227
|
+
}, {
|
|
228
|
+
minVersion?: string | undefined;
|
|
229
|
+
maxVersion?: string | undefined;
|
|
230
|
+
supportedVersions?: string[] | undefined;
|
|
231
|
+
}>>;
|
|
232
|
+
/** 插件依赖 */
|
|
233
|
+
dependencies: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
234
|
+
/** 依赖插件 ID */
|
|
235
|
+
id: z.ZodString;
|
|
236
|
+
/** 依赖版本范围 (SemVer) */
|
|
237
|
+
version: z.ZodString;
|
|
238
|
+
/** 是否为可选依赖 */
|
|
239
|
+
optional: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
240
|
+
}, "strip", z.ZodTypeAny, {
|
|
241
|
+
id: string;
|
|
242
|
+
version: string;
|
|
243
|
+
optional: boolean;
|
|
244
|
+
}, {
|
|
245
|
+
id: string;
|
|
246
|
+
version: string;
|
|
247
|
+
optional?: boolean | undefined;
|
|
248
|
+
}>, "many">>>;
|
|
249
|
+
/** 扩展点声明 */
|
|
250
|
+
extensions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
251
|
+
/** 扩展点名称/标识符 */
|
|
252
|
+
name: z.ZodString;
|
|
253
|
+
/** 扩展点类型 */
|
|
254
|
+
type: z.ZodEnum<["slot", "hook", "command", "service"]>;
|
|
255
|
+
/** 扩展点描述 */
|
|
256
|
+
description: z.ZodOptional<z.ZodString>;
|
|
257
|
+
/** 对于 slot 类型,指定插槽位置 */
|
|
258
|
+
slot: z.ZodOptional<z.ZodString>;
|
|
259
|
+
/** 扩展点的配置选项 */
|
|
260
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
261
|
+
/**
|
|
262
|
+
* 渲染模式
|
|
263
|
+
* @description 定义插槽内容的渲染方式:replace(替换)、append(追加)、prepend(前置)
|
|
264
|
+
*/
|
|
265
|
+
renderMode: z.ZodOptional<z.ZodEnum<["replace", "append", "prepend"]>>;
|
|
266
|
+
/**
|
|
267
|
+
* 条件渲染配置
|
|
268
|
+
* @description 用于条件渲染,如 requiresAuth: true 表示需要认证
|
|
269
|
+
*/
|
|
270
|
+
condition: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
271
|
+
}, "strip", z.ZodTypeAny, {
|
|
272
|
+
name: string;
|
|
273
|
+
type: "slot" | "hook" | "command" | "service";
|
|
274
|
+
slot?: string | undefined;
|
|
275
|
+
description?: string | undefined;
|
|
276
|
+
config?: Record<string, any> | undefined;
|
|
277
|
+
renderMode?: "replace" | "append" | "prepend" | undefined;
|
|
278
|
+
condition?: Record<string, any> | undefined;
|
|
279
|
+
}, {
|
|
280
|
+
name: string;
|
|
281
|
+
type: "slot" | "hook" | "command" | "service";
|
|
282
|
+
slot?: string | undefined;
|
|
283
|
+
description?: string | undefined;
|
|
284
|
+
config?: Record<string, any> | undefined;
|
|
285
|
+
renderMode?: "replace" | "append" | "prepend" | undefined;
|
|
286
|
+
condition?: Record<string, any> | undefined;
|
|
287
|
+
}>, "many">>>;
|
|
288
|
+
/** 能力声明 */
|
|
289
|
+
capabilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
290
|
+
/** 配置项定义 */
|
|
291
|
+
configuration: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
292
|
+
key: z.ZodString;
|
|
293
|
+
type: z.ZodEnum<["string", "number", "boolean", "select"]>;
|
|
294
|
+
label: z.ZodString;
|
|
295
|
+
description: z.ZodOptional<z.ZodString>;
|
|
296
|
+
default: z.ZodOptional<z.ZodAny>;
|
|
297
|
+
options: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
298
|
+
label: z.ZodString;
|
|
299
|
+
value: z.ZodAny;
|
|
300
|
+
}, "strip", z.ZodTypeAny, {
|
|
301
|
+
label: string;
|
|
302
|
+
value?: any;
|
|
303
|
+
}, {
|
|
304
|
+
label: string;
|
|
305
|
+
value?: any;
|
|
306
|
+
}>, "many">>;
|
|
307
|
+
}, "strip", z.ZodTypeAny, {
|
|
308
|
+
type: "string" | "number" | "boolean" | "select";
|
|
309
|
+
key: string;
|
|
310
|
+
label: string;
|
|
311
|
+
options?: {
|
|
312
|
+
label: string;
|
|
313
|
+
value?: any;
|
|
314
|
+
}[] | undefined;
|
|
315
|
+
description?: string | undefined;
|
|
316
|
+
default?: any;
|
|
317
|
+
}, {
|
|
318
|
+
type: "string" | "number" | "boolean" | "select";
|
|
319
|
+
key: string;
|
|
320
|
+
label: string;
|
|
321
|
+
options?: {
|
|
322
|
+
label: string;
|
|
323
|
+
value?: any;
|
|
324
|
+
}[] | undefined;
|
|
325
|
+
description?: string | undefined;
|
|
326
|
+
default?: any;
|
|
327
|
+
}>, "many">>;
|
|
328
|
+
/** 存储定义 */
|
|
329
|
+
storage: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
330
|
+
/** 路由定义 (仅供展示,实际路由在运行时注册) */
|
|
331
|
+
routes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
332
|
+
path: z.ZodString;
|
|
333
|
+
}, "strip", z.ZodTypeAny, {
|
|
334
|
+
path: string;
|
|
335
|
+
}, {
|
|
336
|
+
path: string;
|
|
337
|
+
}>, "many">>;
|
|
338
|
+
/** 权限声明 */
|
|
339
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
340
|
+
action: z.ZodEnum<["read", "write", "execute", "admin"]>;
|
|
341
|
+
scope: z.ZodEnum<["plugin", "global", "user"]>;
|
|
342
|
+
resource: z.ZodString;
|
|
343
|
+
}, "strip", z.ZodTypeAny, {
|
|
344
|
+
action: "read" | "write" | "execute" | "admin";
|
|
345
|
+
scope: "plugin" | "global" | "user";
|
|
346
|
+
resource: string;
|
|
347
|
+
}, {
|
|
348
|
+
action: "read" | "write" | "execute" | "admin";
|
|
349
|
+
scope: "plugin" | "global" | "user";
|
|
350
|
+
resource: string;
|
|
351
|
+
}>, "many">>;
|
|
352
|
+
/** 插件优先级 */
|
|
353
|
+
priority: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
354
|
+
}, "strip", z.ZodTypeAny, {
|
|
355
|
+
name: string;
|
|
356
|
+
type: "business" | "functional" | "view" | "theme" | "renderer" | "system";
|
|
357
|
+
id: string;
|
|
358
|
+
version: string;
|
|
359
|
+
entry: string | {
|
|
360
|
+
url: string;
|
|
361
|
+
shareScope?: string | undefined;
|
|
362
|
+
};
|
|
363
|
+
dependencies: {
|
|
364
|
+
id: string;
|
|
365
|
+
version: string;
|
|
366
|
+
optional: boolean;
|
|
367
|
+
}[];
|
|
368
|
+
extensions: {
|
|
369
|
+
name: string;
|
|
370
|
+
type: "slot" | "hook" | "command" | "service";
|
|
371
|
+
slot?: string | undefined;
|
|
372
|
+
description?: string | undefined;
|
|
373
|
+
config?: Record<string, any> | undefined;
|
|
374
|
+
renderMode?: "replace" | "append" | "prepend" | undefined;
|
|
375
|
+
condition?: Record<string, any> | undefined;
|
|
376
|
+
}[];
|
|
377
|
+
priority: number;
|
|
378
|
+
description?: string | undefined;
|
|
379
|
+
author?: string | undefined;
|
|
380
|
+
icon?: string | undefined;
|
|
381
|
+
compatibility?: {
|
|
382
|
+
minVersion?: string | undefined;
|
|
383
|
+
maxVersion?: string | undefined;
|
|
384
|
+
supportedVersions?: string[] | undefined;
|
|
385
|
+
} | undefined;
|
|
386
|
+
capabilities?: Record<string, boolean> | undefined;
|
|
387
|
+
configuration?: {
|
|
388
|
+
type: "string" | "number" | "boolean" | "select";
|
|
389
|
+
key: string;
|
|
390
|
+
label: string;
|
|
391
|
+
options?: {
|
|
392
|
+
label: string;
|
|
393
|
+
value?: any;
|
|
394
|
+
}[] | undefined;
|
|
395
|
+
description?: string | undefined;
|
|
396
|
+
default?: any;
|
|
397
|
+
}[] | undefined;
|
|
398
|
+
storage?: any[] | undefined;
|
|
399
|
+
routes?: {
|
|
400
|
+
path: string;
|
|
401
|
+
}[] | undefined;
|
|
402
|
+
permissions?: {
|
|
403
|
+
action: "read" | "write" | "execute" | "admin";
|
|
404
|
+
scope: "plugin" | "global" | "user";
|
|
405
|
+
resource: string;
|
|
406
|
+
}[] | undefined;
|
|
407
|
+
}, {
|
|
408
|
+
name: string;
|
|
409
|
+
id: string;
|
|
410
|
+
version: string;
|
|
411
|
+
entry: string | {
|
|
412
|
+
url: string;
|
|
413
|
+
shareScope?: string | undefined;
|
|
414
|
+
};
|
|
415
|
+
type?: "business" | "functional" | "view" | "theme" | "renderer" | "system" | undefined;
|
|
416
|
+
description?: string | undefined;
|
|
417
|
+
author?: string | undefined;
|
|
418
|
+
icon?: string | undefined;
|
|
419
|
+
compatibility?: {
|
|
420
|
+
minVersion?: string | undefined;
|
|
421
|
+
maxVersion?: string | undefined;
|
|
422
|
+
supportedVersions?: string[] | undefined;
|
|
423
|
+
} | undefined;
|
|
424
|
+
dependencies?: {
|
|
425
|
+
id: string;
|
|
426
|
+
version: string;
|
|
427
|
+
optional?: boolean | undefined;
|
|
428
|
+
}[] | undefined;
|
|
429
|
+
extensions?: {
|
|
430
|
+
name: string;
|
|
431
|
+
type: "slot" | "hook" | "command" | "service";
|
|
432
|
+
slot?: string | undefined;
|
|
433
|
+
description?: string | undefined;
|
|
434
|
+
config?: Record<string, any> | undefined;
|
|
435
|
+
renderMode?: "replace" | "append" | "prepend" | undefined;
|
|
436
|
+
condition?: Record<string, any> | undefined;
|
|
437
|
+
}[] | undefined;
|
|
438
|
+
capabilities?: Record<string, boolean> | undefined;
|
|
439
|
+
configuration?: {
|
|
440
|
+
type: "string" | "number" | "boolean" | "select";
|
|
441
|
+
key: string;
|
|
442
|
+
label: string;
|
|
443
|
+
options?: {
|
|
444
|
+
label: string;
|
|
445
|
+
value?: any;
|
|
446
|
+
}[] | undefined;
|
|
447
|
+
description?: string | undefined;
|
|
448
|
+
default?: any;
|
|
449
|
+
}[] | undefined;
|
|
450
|
+
storage?: any[] | undefined;
|
|
451
|
+
routes?: {
|
|
452
|
+
path: string;
|
|
453
|
+
}[] | undefined;
|
|
454
|
+
permissions?: {
|
|
455
|
+
action: "read" | "write" | "execute" | "admin";
|
|
456
|
+
scope: "plugin" | "global" | "user";
|
|
457
|
+
resource: string;
|
|
458
|
+
}[] | undefined;
|
|
459
|
+
priority?: number | undefined;
|
|
460
|
+
}>;
|
|
461
|
+
type PluginManifest = z.infer<typeof PluginManifestSchema>;
|
|
462
|
+
type Extension = z.infer<typeof ExtensionSchema>;
|
|
463
|
+
type Dependency = z.infer<typeof DependencySchema>;
|
|
464
|
+
type Entry = z.infer<typeof EntrySchema>;
|
|
465
|
+
type Compatibility = z.infer<typeof CompatibilitySchema>;
|
|
466
|
+
/**
|
|
467
|
+
* 权限定义
|
|
468
|
+
* @description 定义插件需要的权限声明
|
|
469
|
+
*/
|
|
470
|
+
interface Permission {
|
|
471
|
+
/** 权限动作 */
|
|
472
|
+
action: PermissionAction;
|
|
473
|
+
/** 权限作用域 */
|
|
474
|
+
scope: PermissionScope;
|
|
475
|
+
/** 权限资源标识 */
|
|
476
|
+
resource: string;
|
|
477
|
+
}
|
|
478
|
+
/** 权限类型 - 权限声明数组 */
|
|
479
|
+
type PermissionType = Permission[];
|
|
480
|
+
/**
|
|
481
|
+
* 命令处理器类型
|
|
482
|
+
*/
|
|
483
|
+
type CommandHandler = (payload?: any) => void | Promise<void>;
|
|
484
|
+
/**
|
|
485
|
+
* 命令定义
|
|
486
|
+
* @description 定义插件可以注册的命令
|
|
487
|
+
*/
|
|
488
|
+
interface Command {
|
|
489
|
+
/** 命令唯一标识符 */
|
|
490
|
+
id: string;
|
|
491
|
+
/** 命令显示名称 */
|
|
492
|
+
name: string;
|
|
493
|
+
/** 命令描述 */
|
|
494
|
+
description?: string;
|
|
495
|
+
/** 命令参数 Schema */
|
|
496
|
+
payloadSchema?: z.ZodType<any>;
|
|
497
|
+
/** 命令处理函数 */
|
|
498
|
+
handler: CommandHandler;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* 命令类型 (TypeScript 类型)
|
|
502
|
+
*/
|
|
503
|
+
type CommandType = Command;
|
|
504
|
+
/**
|
|
505
|
+
* 插件激活钩子
|
|
506
|
+
* @description 插件被激活时调用
|
|
507
|
+
*/
|
|
508
|
+
type OnActivateHandler = (context: PluginContext) => void | Promise<void>;
|
|
509
|
+
/**
|
|
510
|
+
* 插件停用钩子
|
|
511
|
+
* @description 插件被停用时调用
|
|
512
|
+
*/
|
|
513
|
+
type OnDeactivateHandler = (context: PluginContext) => void | Promise<void>;
|
|
514
|
+
/**
|
|
515
|
+
* 插件错误处理钩子
|
|
516
|
+
* @description 插件发生错误时调用
|
|
517
|
+
*/
|
|
518
|
+
type OnErrorHandler = (error: Error, context: PluginContext) => void;
|
|
519
|
+
/**
|
|
520
|
+
* 扩展的生命周期钩子类型
|
|
521
|
+
* @description 扩展插件生命周期管理
|
|
522
|
+
*/
|
|
523
|
+
interface HookType {
|
|
524
|
+
/**
|
|
525
|
+
* 插件激活时
|
|
526
|
+
* @description 插件被激活/启用时触发
|
|
527
|
+
*/
|
|
528
|
+
onActivate?: OnActivateHandler;
|
|
529
|
+
/**
|
|
530
|
+
* 插件停用时
|
|
531
|
+
* @description 插件被停用/禁用时触发
|
|
532
|
+
*/
|
|
533
|
+
onDeactivate?: OnDeactivateHandler;
|
|
534
|
+
/**
|
|
535
|
+
* 插件错误处理
|
|
536
|
+
* @description 插件发生错误时触发
|
|
537
|
+
*/
|
|
538
|
+
onError?: OnErrorHandler;
|
|
539
|
+
}
|
|
540
|
+
|
|
5
541
|
/**
|
|
6
542
|
* HTTP 请求方法
|
|
7
543
|
*/
|
|
@@ -24,6 +560,8 @@ interface ApiEndpointConfig {
|
|
|
24
560
|
responseSchema?: any;
|
|
25
561
|
/** 错误处理策略 */
|
|
26
562
|
errorStrategy?: ErrorStrategy;
|
|
563
|
+
/** 是否携带凭据 (跨域配置) */
|
|
564
|
+
withCredentials?: boolean;
|
|
27
565
|
}
|
|
28
566
|
/**
|
|
29
567
|
* API 请求配置
|
|
@@ -41,6 +579,8 @@ interface ApiRequestConfig {
|
|
|
41
579
|
headers?: any;
|
|
42
580
|
/** 用于取消请求的信号对象 */
|
|
43
581
|
signal?: AbortSignal;
|
|
582
|
+
/** 是否携带凭据 (跨域配置) */
|
|
583
|
+
withCredentials?: boolean;
|
|
44
584
|
}
|
|
45
585
|
/**
|
|
46
586
|
* 流式响应回调函数接口
|
|
@@ -146,26 +686,26 @@ interface EventBusPort {
|
|
|
146
686
|
* @param callback - 事件触发时的回调函数
|
|
147
687
|
* @returns 取消订阅的函数
|
|
148
688
|
*/
|
|
149
|
-
on(event: string, callback: (...args:
|
|
689
|
+
on(event: string, callback: (...args: unknown[]) => unknown): () => void;
|
|
150
690
|
/**
|
|
151
691
|
* 取消订阅事件
|
|
152
692
|
* @param event - 事件名称
|
|
153
693
|
* @param callback - 之前注册的回调函数
|
|
154
694
|
*/
|
|
155
|
-
off(event: string, callback: (...args:
|
|
695
|
+
off(event: string, callback: (...args: unknown[]) => unknown): void;
|
|
156
696
|
/**
|
|
157
697
|
* 触发事件 (发布)
|
|
158
698
|
* @param event - 事件名称
|
|
159
699
|
* @param args - 传递给回调函数的参数列表
|
|
160
700
|
*/
|
|
161
|
-
emit(event: string, ...args:
|
|
701
|
+
emit(event: string, ...args: unknown[]): void;
|
|
162
702
|
/**
|
|
163
703
|
* 订阅一次性事件
|
|
164
704
|
* @description 事件触发一次后会自动取消订阅
|
|
165
705
|
* @param event - 事件名称
|
|
166
706
|
* @param callback - 事件触发时的回调函数
|
|
167
707
|
*/
|
|
168
|
-
once(event: string, callback: (...args:
|
|
708
|
+
once(event: string, callback: (...args: unknown[]) => unknown): void;
|
|
169
709
|
}
|
|
170
710
|
|
|
171
711
|
/**
|
|
@@ -219,16 +759,23 @@ interface TypedStorage {
|
|
|
219
759
|
}
|
|
220
760
|
|
|
221
761
|
/**
|
|
222
|
-
*
|
|
762
|
+
* API 端口接口
|
|
763
|
+
* @description 插件使用 API 能力的入口,包含请求适配器和 API 配置注册功能
|
|
223
764
|
*/
|
|
224
|
-
|
|
225
|
-
|
|
765
|
+
interface ApiPort extends ApiAdapter {
|
|
766
|
+
/**
|
|
767
|
+
* 注册 API 配置
|
|
768
|
+
* @param config - API 配置对象
|
|
769
|
+
*/
|
|
770
|
+
register?: (config: ApiConfig) => void;
|
|
771
|
+
}
|
|
772
|
+
|
|
226
773
|
/**
|
|
227
774
|
* 路由配置
|
|
228
775
|
*/
|
|
229
776
|
interface RouteConfig {
|
|
230
777
|
path: string;
|
|
231
|
-
component:
|
|
778
|
+
component: any;
|
|
232
779
|
meta?: Record<string, any>;
|
|
233
780
|
}
|
|
234
781
|
/**
|
|
@@ -256,8 +803,8 @@ type SlotPosition = SlotType | string;
|
|
|
256
803
|
interface PluginExtension {
|
|
257
804
|
/** 插槽位置标识符 */
|
|
258
805
|
slot: SlotPosition;
|
|
259
|
-
/** 要注入的 React
|
|
260
|
-
component:
|
|
806
|
+
/** 要注入的 React 等框架组件 */
|
|
807
|
+
component: any;
|
|
261
808
|
/** 排序权重,数值越小越靠前 */
|
|
262
809
|
order?: number;
|
|
263
810
|
/** @internal 插件 ID,由系统在加载时自动注入,用于溯源 */
|
|
@@ -265,7 +812,7 @@ interface PluginExtension {
|
|
|
265
812
|
/** 扩展的元数据信息 */
|
|
266
813
|
meta?: {
|
|
267
814
|
/** 显示图标 */
|
|
268
|
-
icon?:
|
|
815
|
+
icon?: any;
|
|
269
816
|
/** 显示标签文本 */
|
|
270
817
|
label?: string;
|
|
271
818
|
/** 详细描述 */
|
|
@@ -377,26 +924,27 @@ interface PluginStorage extends TypedStorage {
|
|
|
377
924
|
/**
|
|
378
925
|
* 插件生命周期 Hooks
|
|
379
926
|
* @description 插件可以在不同的生命周期阶段执行特定的逻辑
|
|
927
|
+
* @template T - 插件清单类型,默认为 PluginManifest
|
|
380
928
|
*/
|
|
381
|
-
interface PluginLifecycle {
|
|
929
|
+
interface PluginLifecycle<T extends PluginManifest = PluginManifest> {
|
|
382
930
|
/**
|
|
383
931
|
* 插件加载时调用
|
|
384
932
|
* @description 在插件被扫描并注入内核时触发。用于初始化内部状态、注册服务、设置拦截器等。此时 UI 尚未挂载。
|
|
385
933
|
* @param context - 插件上下文对象,提供核心能力的访问
|
|
386
934
|
*/
|
|
387
|
-
onLoad?: (context: PluginContext) => void | Promise<void>;
|
|
935
|
+
onLoad?: (context: PluginContext<T>) => void | Promise<void>;
|
|
388
936
|
/**
|
|
389
937
|
* 插件挂载到 UI 时调用
|
|
390
938
|
* @description 当插件的 UI 组件(如有)被 React 挂载到 DOM 时触发。
|
|
391
939
|
* @param context - 插件上下文对象
|
|
392
940
|
*/
|
|
393
|
-
onMount?: (context: PluginContext) => void;
|
|
941
|
+
onMount?: (context: PluginContext<T>) => void;
|
|
394
942
|
/**
|
|
395
943
|
* 插件从 UI 卸载时调用
|
|
396
944
|
* @description 当插件的 UI 组件被销毁时触发。用于清理定时器、取消订阅等。
|
|
397
945
|
* @param context - 插件上下文对象
|
|
398
946
|
*/
|
|
399
|
-
onUnmount?: (context: PluginContext) => void;
|
|
947
|
+
onUnmount?: (context: PluginContext<T>) => void;
|
|
400
948
|
/**
|
|
401
949
|
* 插件配置发生变化时调用
|
|
402
950
|
* @description 当用户通过配置中心修改插件设置时触发。
|
|
@@ -404,16 +952,26 @@ interface PluginLifecycle {
|
|
|
404
952
|
* @param oldConfig - 变更前的旧配置对象
|
|
405
953
|
*/
|
|
406
954
|
onConfigChange?: (newConfig: any, oldConfig: any) => void;
|
|
955
|
+
/**
|
|
956
|
+
* 插件错误处理
|
|
957
|
+
* @description 当插件发生错误时触发,用于统一错误处理和日志记录
|
|
958
|
+
* @param error - 错误对象
|
|
959
|
+
* @param context - 插件上下文对象
|
|
960
|
+
*/
|
|
961
|
+
onError?: (error: Error, context: PluginContext<T>) => void;
|
|
407
962
|
}
|
|
408
963
|
/**
|
|
409
964
|
* 插件上下文
|
|
410
965
|
* @description 传递给插件生命周期钩子的核心对象,是插件访问宿主环境能力的唯一入口。
|
|
966
|
+
* @template T - 插件清单类型,默认为 PluginManifest
|
|
411
967
|
*/
|
|
412
|
-
interface PluginContext {
|
|
968
|
+
interface PluginContext<T extends PluginManifest = PluginManifest> {
|
|
413
969
|
/** 当前插件的唯一标识符 */
|
|
414
|
-
pluginId:
|
|
970
|
+
pluginId: PluginId;
|
|
971
|
+
/** 插件清单 */
|
|
972
|
+
manifest: T;
|
|
415
973
|
/** API 请求能力入口 */
|
|
416
|
-
api:
|
|
974
|
+
api: ApiPort;
|
|
417
975
|
/** 事件总线能力入口 */
|
|
418
976
|
events: EventBusPort;
|
|
419
977
|
/** 存储管理能力入口 */
|
|
@@ -430,13 +988,13 @@ interface PluginContext {
|
|
|
430
988
|
* @param serviceName - 服务注册名称
|
|
431
989
|
* @returns 服务实例,如果不存在则返回 undefined
|
|
432
990
|
*/
|
|
433
|
-
getService: <T =
|
|
991
|
+
getService: <T = unknown>(serviceName: string) => T | undefined;
|
|
434
992
|
/**
|
|
435
993
|
* 注册当前插件的服务供他人使用
|
|
436
994
|
* @param serviceName - 唯一服务名称
|
|
437
995
|
* @param service - 服务实现对象
|
|
438
996
|
*/
|
|
439
|
-
registerService: (serviceName: string, service:
|
|
997
|
+
registerService: <T = unknown>(serviceName: string, service: T) => void;
|
|
440
998
|
/** 宿主环境 Window 的代理对象 (用于沙箱隔离) */
|
|
441
999
|
window: WindowProxy;
|
|
442
1000
|
}
|
|
@@ -452,7 +1010,7 @@ interface Plugin extends PluginLifecycle {
|
|
|
452
1010
|
/** 插件元数据配置 */
|
|
453
1011
|
metadata: PluginMetadata;
|
|
454
1012
|
/** 插件提供的功能组件集合 (可选) */
|
|
455
|
-
components?: Record<string,
|
|
1013
|
+
components?: Record<string, any>;
|
|
456
1014
|
/** 插件提供的工具函数集合 (可选) */
|
|
457
1015
|
utils?: Record<string, any>;
|
|
458
1016
|
/** 插件的初始默认配置 (可选) */
|
|
@@ -499,8 +1057,8 @@ interface PluginMetadata {
|
|
|
499
1057
|
description?: string;
|
|
500
1058
|
/** 插件作者信息 */
|
|
501
1059
|
author?: string;
|
|
502
|
-
/** 插件图标
|
|
503
|
-
icon?:
|
|
1060
|
+
/** 插件图标 */
|
|
1061
|
+
icon?: any;
|
|
504
1062
|
/** 插件依赖的其他插件 ID 列表 */
|
|
505
1063
|
dependencies?: string[];
|
|
506
1064
|
/** 路由配置集合,用于在主应用中注册页面 */
|
|
@@ -515,6 +1073,12 @@ interface PluginMetadata {
|
|
|
515
1073
|
configuration?: PluginConfigItem[];
|
|
516
1074
|
/** 插件所需的存储结构定义 */
|
|
517
1075
|
storage?: StorageItemSchema[];
|
|
1076
|
+
/**
|
|
1077
|
+
* 插件优先级
|
|
1078
|
+
* @description 数值越小优先级越高,用于插件加载顺序和插槽渲染顺序
|
|
1079
|
+
* @default 100
|
|
1080
|
+
*/
|
|
1081
|
+
priority?: number;
|
|
518
1082
|
/**
|
|
519
1083
|
* 系统状态自动绑定
|
|
520
1084
|
* @description 将插件的配置项自动同步到系统的全局状态中 (如主题色、身份认证等)
|
|
@@ -530,368 +1094,456 @@ interface PluginMetadata {
|
|
|
530
1094
|
}
|
|
531
1095
|
|
|
532
1096
|
/**
|
|
533
|
-
*
|
|
1097
|
+
* @file template-literals.ts
|
|
1098
|
+
* @description 模板字面量类型 - 用于精确类型检查
|
|
534
1099
|
*/
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* SemVer 版本号类型
|
|
1103
|
+
* @description 匹配符合 SemVer 规范 (^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9.-]+)?$) 的版本号
|
|
1104
|
+
* 支持如 1.0.0, 1.2.3-beta.1, 2.0.0-alpha+001 等格式
|
|
1105
|
+
*/
|
|
1106
|
+
type SemVer = string & {
|
|
1107
|
+
__semver: 'SemVer';
|
|
1108
|
+
};
|
|
1109
|
+
/**
|
|
1110
|
+
* RoutePath 路由路径类型
|
|
1111
|
+
* @description 以 / 开头的路由路径
|
|
1112
|
+
*/
|
|
1113
|
+
type RoutePath = string & {
|
|
1114
|
+
__routePath: 'RoutePath';
|
|
1115
|
+
};
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* SemVer 的 Zod 验证 Schema
|
|
1119
|
+
*/
|
|
1120
|
+
declare const SemVerSchema: z.ZodString;
|
|
1121
|
+
/**
|
|
1122
|
+
* RoutePath 的 Zod 验证 Schema
|
|
1123
|
+
*/
|
|
1124
|
+
declare const RoutePathSchema: z.ZodString;
|
|
1125
|
+
/**
|
|
1126
|
+
* 创建类型安全的 SemVer 版本号
|
|
1127
|
+
* @param version - 版本号字符串
|
|
1128
|
+
* @returns 带类型标记的 SemVer 类型
|
|
1129
|
+
*/
|
|
1130
|
+
declare function createSemVer(version: string): SemVer;
|
|
1131
|
+
/**
|
|
1132
|
+
* 创建类型安全的 RoutePath 路由路径
|
|
1133
|
+
* @param path - 路由路径字符串
|
|
1134
|
+
* @returns 带类型标记的 RoutePath 类型
|
|
1135
|
+
*/
|
|
1136
|
+
declare function createRoutePath(path: string): RoutePath;
|
|
1137
|
+
/**
|
|
1138
|
+
* 类型守卫:检查是否为有效的 SemVer
|
|
1139
|
+
* @param value - 要检查的值
|
|
1140
|
+
* @returns 是否为 SemVer 类型
|
|
1141
|
+
*/
|
|
1142
|
+
declare function isSemVer(value: unknown): value is SemVer;
|
|
1143
|
+
/**
|
|
1144
|
+
* 类型守卫:检查是否为有效的 RoutePath
|
|
1145
|
+
* @param value - 要检查的值
|
|
1146
|
+
* @returns 是否为 RoutePath 类型
|
|
1147
|
+
*/
|
|
1148
|
+
declare function isRoutePath(value: unknown): value is RoutePath;
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* 深度只读类型
|
|
1152
|
+
* @description 递归将所有属性(包括嵌套对象和数组)设为只读
|
|
1153
|
+
* @example
|
|
1154
|
+
* type ReadonlyPluginConfig = DeepReadonly<PluginConfig>;
|
|
1155
|
+
* // 所有嵌套属性都变为 readonly
|
|
1156
|
+
*/
|
|
1157
|
+
type DeepReadonly<T> = {
|
|
1158
|
+
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
|
|
1159
|
+
};
|
|
1160
|
+
/**
|
|
1161
|
+
* 配置项定义
|
|
1162
|
+
*/
|
|
1163
|
+
interface ConfigItemDefinition {
|
|
1164
|
+
key: string;
|
|
1165
|
+
type: 'string' | 'number' | 'boolean' | 'select';
|
|
1166
|
+
label: string;
|
|
1167
|
+
description?: string;
|
|
1168
|
+
default?: unknown;
|
|
1169
|
+
options?: Array<{
|
|
1170
|
+
label: string;
|
|
1171
|
+
value: unknown;
|
|
1172
|
+
}>;
|
|
540
1173
|
}
|
|
1174
|
+
/**
|
|
1175
|
+
* 安全的插件配置类型
|
|
1176
|
+
* @description 根据插件的 configuration 定义生成运行时配置类型
|
|
1177
|
+
* @example
|
|
1178
|
+
* interface MyPluginConfig {
|
|
1179
|
+
* apiKey: string;
|
|
1180
|
+
* maxResults: number;
|
|
1181
|
+
* }
|
|
1182
|
+
* type SafeConfig = SafePluginConfig<{ apiKey: string; maxResults: number }>;
|
|
1183
|
+
*/
|
|
1184
|
+
type SafePluginConfig<T extends ConfigItemDefinition[]> = {
|
|
1185
|
+
[K in T[number] as K['key']]: K['default'];
|
|
1186
|
+
};
|
|
1187
|
+
/**
|
|
1188
|
+
* Plugin Manifest 类型
|
|
1189
|
+
* @description 从 Zod Schema 推断出的插件清单类型
|
|
1190
|
+
*/
|
|
1191
|
+
type PluginManifestType = {
|
|
1192
|
+
id: string;
|
|
1193
|
+
version: string;
|
|
1194
|
+
name: string;
|
|
1195
|
+
entry: string | {
|
|
1196
|
+
url: string;
|
|
1197
|
+
shareScope?: string;
|
|
1198
|
+
};
|
|
1199
|
+
type?: 'business' | 'functional' | 'view' | 'theme' | 'renderer' | 'system';
|
|
1200
|
+
description?: string;
|
|
1201
|
+
author?: string;
|
|
1202
|
+
icon?: string;
|
|
1203
|
+
compatibility?: {
|
|
1204
|
+
minVersion?: string;
|
|
1205
|
+
maxVersion?: string;
|
|
1206
|
+
supportedVersions?: string[];
|
|
1207
|
+
};
|
|
1208
|
+
dependencies?: Array<{
|
|
1209
|
+
id: string;
|
|
1210
|
+
version: string;
|
|
1211
|
+
optional?: boolean;
|
|
1212
|
+
}>;
|
|
1213
|
+
extensions?: Array<{
|
|
1214
|
+
name: string;
|
|
1215
|
+
type: 'slot' | 'hook' | 'command' | 'service';
|
|
1216
|
+
description?: string;
|
|
1217
|
+
slot?: string;
|
|
1218
|
+
config?: Record<string, unknown>;
|
|
1219
|
+
renderMode?: 'replace' | 'append' | 'prepend';
|
|
1220
|
+
condition?: Record<string, unknown>;
|
|
1221
|
+
}>;
|
|
1222
|
+
capabilities?: Record<string, boolean>;
|
|
1223
|
+
configuration?: ConfigItemDefinition[];
|
|
1224
|
+
storage?: unknown[];
|
|
1225
|
+
routes?: Array<{
|
|
1226
|
+
path: string;
|
|
1227
|
+
}>;
|
|
1228
|
+
permissions?: Array<{
|
|
1229
|
+
action: 'read' | 'write' | 'execute' | 'admin';
|
|
1230
|
+
scope: 'plugin' | 'global' | 'user';
|
|
1231
|
+
resource: string;
|
|
1232
|
+
}>;
|
|
1233
|
+
priority?: number;
|
|
1234
|
+
};
|
|
1235
|
+
/**
|
|
1236
|
+
* 类型守卫: 检查值是否为有效的 PluginManifest
|
|
1237
|
+
* @param value - 要检查的值
|
|
1238
|
+
* @returns 如果值符合 PluginManifestSchema 则返回 true
|
|
1239
|
+
* @example
|
|
1240
|
+
* if (isPluginManifest(data)) {
|
|
1241
|
+
* console.log(data.name); // TypeScript 知道这是有效的 PluginManifest
|
|
1242
|
+
* }
|
|
1243
|
+
*/
|
|
1244
|
+
declare function isPluginManifest(value: unknown): value is PluginManifestType;
|
|
541
1245
|
|
|
542
1246
|
/**
|
|
543
|
-
*
|
|
544
|
-
* @description
|
|
1247
|
+
* 服务注册中心 (Service Registry)
|
|
1248
|
+
* @description 核心应用层服务,作为微内核架构中的“中枢调度员”。
|
|
1249
|
+
* 主要职责:
|
|
1250
|
+
* 1. 服务解耦:允许插件将其内部功能暴露为“服务”,而无需与其他插件产生物理依赖。
|
|
1251
|
+
* 2. 动态发现:提供按名称查找服务的能力,支持服务热插拔。
|
|
1252
|
+
* 3. 依赖协调:通过 `waitFor` 机制解决插件间由于加载顺序导致的初始化依赖问题。
|
|
1253
|
+
*
|
|
1254
|
+
* 建议的服务命名规范: `pluginId.serviceName` (例如: `auth.sessionService`)
|
|
545
1255
|
*/
|
|
546
|
-
declare class
|
|
547
|
-
|
|
548
|
-
private
|
|
549
|
-
|
|
550
|
-
|
|
1256
|
+
declare class ServiceRegistry {
|
|
1257
|
+
/** 存储已注册服务的 Map 对象 */
|
|
1258
|
+
private services;
|
|
1259
|
+
/** 存储正在等待特定服务的监听器集合 */
|
|
1260
|
+
private listeners;
|
|
551
1261
|
/**
|
|
552
|
-
*
|
|
1262
|
+
* 注册一个服务实现
|
|
1263
|
+
* @param name - 唯一的服务名称
|
|
1264
|
+
* @param service - 服务实例或对象
|
|
553
1265
|
*/
|
|
554
|
-
|
|
1266
|
+
register(name: string, service: any): void;
|
|
555
1267
|
/**
|
|
556
|
-
*
|
|
1268
|
+
* 同步获取服务实例
|
|
1269
|
+
* @template T - 服务类型的泛型
|
|
1270
|
+
* @param name - 服务名称
|
|
1271
|
+
* @returns 服务实例,若不存在则返回 undefined
|
|
557
1272
|
*/
|
|
558
|
-
|
|
1273
|
+
get<T = any>(name: string): T | undefined;
|
|
559
1274
|
/**
|
|
560
|
-
*
|
|
561
|
-
* @
|
|
1275
|
+
* 异步等待并获取服务
|
|
1276
|
+
* @description 如果服务尚未注册,将返回一个 Promise,直到该服务被注册时 resolve。
|
|
1277
|
+
* 支持设置超时时间,防止因插件加载失败导致的永久挂起。
|
|
1278
|
+
*
|
|
1279
|
+
* @template T - 服务类型的泛型
|
|
1280
|
+
* @param name - 待等待的服务名称
|
|
1281
|
+
* @param timeout - 超时时间 (毫秒),默认 10000ms (10秒)。若为 0 则永不超时。
|
|
1282
|
+
* @returns 包含服务实例的 Promise
|
|
1283
|
+
* @throws {Error} 若在规定时间内服务未注册,则抛出超时异常。
|
|
562
1284
|
*/
|
|
563
|
-
|
|
1285
|
+
waitFor<T = any>(name: string, timeout?: number): Promise<T>;
|
|
564
1286
|
/**
|
|
565
|
-
*
|
|
566
|
-
* @param
|
|
1287
|
+
* 检查服务是否已注册
|
|
1288
|
+
* @param name - 服务名称
|
|
567
1289
|
*/
|
|
568
|
-
|
|
1290
|
+
has(name: string): boolean;
|
|
569
1291
|
/**
|
|
570
|
-
*
|
|
1292
|
+
* 注销特定的服务
|
|
1293
|
+
* @param name - 服务名称
|
|
571
1294
|
*/
|
|
572
|
-
|
|
1295
|
+
unregister(name: string): void;
|
|
573
1296
|
/**
|
|
574
|
-
*
|
|
575
|
-
* @
|
|
576
|
-
* @param action 动作名
|
|
577
|
-
* @param data 请求数据 (Body 或 Query)
|
|
578
|
-
* @param options 请求选项
|
|
1297
|
+
* 清除所有已注册的服务和监听器
|
|
1298
|
+
* @description 通常仅在系统重置或大型热更新时使用。
|
|
579
1299
|
*/
|
|
580
|
-
|
|
1300
|
+
clear(): void;
|
|
1301
|
+
}
|
|
1302
|
+
declare const serviceRegistry: ServiceRegistry;
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* 配置管理器
|
|
1306
|
+
* @description 核心工具类,负责管理应用的全局系统配置以及各插件的初始化业务配置。
|
|
1307
|
+
* 配置数据通常在应用启动时通过 `usePluginLoader` 注入,并作为插件运行时的取值回退来源。
|
|
1308
|
+
*/
|
|
1309
|
+
declare class ConfigManager<T = Record<string, unknown>> {
|
|
1310
|
+
/** 内部存储配置的 Map 对象 */
|
|
1311
|
+
private config;
|
|
581
1312
|
/**
|
|
582
|
-
*
|
|
583
|
-
* @param
|
|
584
|
-
* @param
|
|
585
|
-
* @param data 请求数据
|
|
586
|
-
* @param options 请求选项
|
|
1313
|
+
* 设置特定的配置项
|
|
1314
|
+
* @param key - 配置键名(如 'system' 或插件 ID)
|
|
1315
|
+
* @param value - 配置内容对象
|
|
587
1316
|
*/
|
|
588
|
-
|
|
1317
|
+
set<K extends keyof T>(key: K, value: T[K]): void;
|
|
1318
|
+
set(key: string, value: unknown): void;
|
|
589
1319
|
/**
|
|
590
|
-
*
|
|
1320
|
+
* 获取指定的配置项
|
|
1321
|
+
* @param key - 配置键名
|
|
1322
|
+
* @returns 配置内容,若不存在则返回 undefined
|
|
591
1323
|
*/
|
|
592
|
-
|
|
1324
|
+
get<K extends keyof T>(key: K): T[K] | undefined;
|
|
1325
|
+
get(key: string): unknown;
|
|
593
1326
|
/**
|
|
594
|
-
*
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
* 应用所有响应拦截器
|
|
599
|
-
* @returns 是否被劫持
|
|
600
|
-
*/
|
|
601
|
-
private applyResponseInterceptors;
|
|
602
|
-
/**
|
|
603
|
-
* 检查 HTTP 状态码
|
|
1327
|
+
* 深度合并配置对象
|
|
1328
|
+
* @description 对配置进行深度合并,嵌套对象会被递归合并而非完全覆盖。
|
|
1329
|
+
* @param config - 待合并的配置对象映射
|
|
604
1330
|
*/
|
|
605
|
-
|
|
1331
|
+
merge(config: Partial<T> & Record<string, unknown>): void;
|
|
606
1332
|
/**
|
|
607
|
-
*
|
|
1333
|
+
* 深度合并两个对象
|
|
608
1334
|
*/
|
|
609
|
-
private
|
|
1335
|
+
private deepMerge;
|
|
610
1336
|
/**
|
|
611
|
-
*
|
|
1337
|
+
* 获取当前存储的所有配置快照
|
|
1338
|
+
* @returns 包含所有配置的普通对象
|
|
612
1339
|
*/
|
|
613
|
-
|
|
1340
|
+
getAll(): T;
|
|
614
1341
|
/**
|
|
615
|
-
*
|
|
1342
|
+
* 检查配置项是否存在
|
|
616
1343
|
*/
|
|
617
|
-
|
|
1344
|
+
has(key: string): boolean;
|
|
618
1345
|
/**
|
|
619
|
-
*
|
|
1346
|
+
* 删除指定配置项
|
|
620
1347
|
*/
|
|
621
|
-
|
|
1348
|
+
delete(key: string): boolean;
|
|
622
1349
|
/**
|
|
623
|
-
*
|
|
1350
|
+
* 清空所有配置
|
|
624
1351
|
*/
|
|
625
|
-
|
|
1352
|
+
clear(): void;
|
|
626
1353
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
/**
|
|
630
|
-
* 自动检测是否处于 Mock 模式
|
|
631
|
-
*/
|
|
632
|
-
declare function isMockMode(): boolean;
|
|
633
|
-
/**
|
|
634
|
-
* 从文件模块映射中解析 API 配置
|
|
635
|
-
* @description 配合 Vite 的 import.meta.glob 使用,自动匹配定义文件和 Mock 文件
|
|
636
|
-
* @param definitionsMap API 定义文件映射 (import.meta.glob('./modules/*.ts', { eager: true }))
|
|
637
|
-
* @param mocksMap Mock 文件映射 (import.meta.glob('./modules/*.mock.ts', { eager: true }))
|
|
638
|
-
* @param useMock 是否启用 Mock (如果不传,将自动调用 isMockMode())
|
|
639
|
-
* @returns 合并后的 ApiConfig
|
|
640
|
-
*/
|
|
641
|
-
declare function resolveApiModules(definitionsMap: Record<string, any>, mocksMap?: Record<string, any>): ApiConfig;
|
|
1354
|
+
/** 全局配置管理器单例 */
|
|
1355
|
+
declare const configManager: ConfigManager<Record<string, unknown>>;
|
|
642
1356
|
|
|
643
1357
|
/**
|
|
644
|
-
*
|
|
645
|
-
*/
|
|
646
|
-
declare const SUCCESS_CODE = "000000";
|
|
647
|
-
/**
|
|
648
|
-
* 基础 API 响应接口
|
|
649
|
-
* @template T 响应数据的类型
|
|
1358
|
+
* AI 能力抽象层类型定义
|
|
650
1359
|
*/
|
|
651
|
-
interface
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
1360
|
+
interface AIMessage {
|
|
1361
|
+
id: string;
|
|
1362
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
1363
|
+
content: string;
|
|
1364
|
+
name?: string;
|
|
1365
|
+
toolCallId?: string;
|
|
1366
|
+
toolCalls?: ToolCall[];
|
|
1367
|
+
createdAt?: number;
|
|
658
1368
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
1369
|
+
interface ToolCall {
|
|
1370
|
+
id: string;
|
|
1371
|
+
type: 'function';
|
|
1372
|
+
function: {
|
|
1373
|
+
name: string;
|
|
1374
|
+
arguments: string;
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
interface ChatOptions {
|
|
1378
|
+
model?: string;
|
|
1379
|
+
temperature?: number;
|
|
1380
|
+
maxTokens?: number;
|
|
1381
|
+
tools?: AITool[];
|
|
1382
|
+
stream?: boolean;
|
|
1383
|
+
systemPrompt?: string;
|
|
1384
|
+
}
|
|
1385
|
+
interface AIProvider {
|
|
1386
|
+
chat(messages: AIMessage[], options?: ChatOptions): Promise<AIMessage>;
|
|
1387
|
+
stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable<AIChunk>;
|
|
1388
|
+
functionCall(messages: AIMessage[], tools: AITool[], options?: ChatOptions): Promise<FunctionCallResult>;
|
|
1389
|
+
}
|
|
1390
|
+
interface AIChunk {
|
|
1391
|
+
type: 'content' | 'tool-call' | 'done' | 'error';
|
|
1392
|
+
content?: string;
|
|
1393
|
+
toolCall?: ToolCall;
|
|
1394
|
+
error?: string;
|
|
1395
|
+
}
|
|
1396
|
+
interface FunctionCallResult {
|
|
1397
|
+
message: AIMessage;
|
|
1398
|
+
toolCalls: ToolCall[];
|
|
1399
|
+
}
|
|
1400
|
+
interface Session {
|
|
665
1401
|
id: string;
|
|
666
|
-
/** 场景名称 */
|
|
667
1402
|
name: string;
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
/** 场景创建者 ID 或名称 */
|
|
673
|
-
creator: string;
|
|
674
|
-
/** 创建时间字符串 (ISO 格式) */
|
|
675
|
-
createTime: string;
|
|
676
|
-
/** 该场景关联的物理数据表数量 */
|
|
677
|
-
tableCount: number;
|
|
678
|
-
/** 该场景关联的知识库数量 */
|
|
679
|
-
kbCount: number;
|
|
680
|
-
/** 该场景关联的预设问答对数量 */
|
|
681
|
-
qaCount: number;
|
|
682
|
-
/** 场景封面图 URL (可选) */
|
|
683
|
-
cover?: string;
|
|
1403
|
+
messages: AIMessage[];
|
|
1404
|
+
createdAt: number;
|
|
1405
|
+
updatedAt: number;
|
|
1406
|
+
metadata?: Record<string, unknown>;
|
|
684
1407
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
1408
|
+
interface AITool {
|
|
1409
|
+
name: string;
|
|
1410
|
+
description: string;
|
|
1411
|
+
parameters: Record<string, unknown>;
|
|
1412
|
+
execute: (args: Record<string, unknown>) => Promise<unknown>;
|
|
689
1413
|
}
|
|
690
|
-
declare const ApiProvider: React.FC<ApiProviderProps>;
|
|
691
|
-
declare const useApi: () => ApiEngine;
|
|
692
1414
|
|
|
693
1415
|
/**
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
* 主要职责:
|
|
697
|
-
* 1. 服务解耦:允许插件将其内部功能暴露为“服务”,而无需与其他插件产生物理依赖。
|
|
698
|
-
* 2. 动态发现:提供按名称查找服务的能力,支持服务热插拔。
|
|
699
|
-
* 3. 依赖协调:通过 `waitFor` 机制解决插件间由于加载顺序导致的初始化依赖问题。
|
|
700
|
-
*
|
|
701
|
-
* 建议的服务命名规范: `pluginId.serviceName` (例如: `auth.sessionService`)
|
|
1416
|
+
* 工具注册表
|
|
1417
|
+
* 管理 AI 函数的注册和执行
|
|
702
1418
|
*/
|
|
703
|
-
declare class
|
|
704
|
-
|
|
705
|
-
private services;
|
|
706
|
-
/** 存储正在等待特定服务的监听器集合 */
|
|
707
|
-
private listeners;
|
|
708
|
-
/**
|
|
709
|
-
* 注册一个服务实现
|
|
710
|
-
* @param name - 唯一的服务名称
|
|
711
|
-
* @param service - 服务实例或对象
|
|
712
|
-
*/
|
|
713
|
-
register(name: string, service: any): void;
|
|
1419
|
+
declare class ToolRegistry {
|
|
1420
|
+
private tools;
|
|
714
1421
|
/**
|
|
715
|
-
*
|
|
716
|
-
* @template T - 服务类型的泛型
|
|
717
|
-
* @param name - 服务名称
|
|
718
|
-
* @returns 服务实例,若不存在则返回 undefined
|
|
1422
|
+
* 注册工具
|
|
719
1423
|
*/
|
|
720
|
-
|
|
1424
|
+
register(tool: AITool): void;
|
|
721
1425
|
/**
|
|
722
|
-
*
|
|
723
|
-
* @description 如果服务尚未注册,将返回一个 Promise,直到该服务被注册时 resolve。
|
|
724
|
-
* 支持设置超时时间,防止因插件加载失败导致的永久挂起。
|
|
725
|
-
*
|
|
726
|
-
* @template T - 服务类型的泛型
|
|
727
|
-
* @param name - 待等待的服务名称
|
|
728
|
-
* @param timeout - 超时时间 (毫秒),默认 10000ms (10秒)。若为 0 则永不超时。
|
|
729
|
-
* @returns 包含服务实例的 Promise
|
|
730
|
-
* @throws {Error} 若在规定时间内服务未注册,则抛出超时异常。
|
|
1426
|
+
* 注销工具
|
|
731
1427
|
*/
|
|
732
|
-
|
|
1428
|
+
unregister(name: string): void;
|
|
733
1429
|
/**
|
|
734
|
-
*
|
|
735
|
-
* @param name - 服务名称
|
|
1430
|
+
* 获取工具
|
|
736
1431
|
*/
|
|
737
|
-
|
|
1432
|
+
get(name: string): AITool | null;
|
|
738
1433
|
/**
|
|
739
|
-
*
|
|
740
|
-
* @param name - 服务名称
|
|
1434
|
+
* 列出所有工具
|
|
741
1435
|
*/
|
|
742
|
-
|
|
1436
|
+
list(): AITool[];
|
|
743
1437
|
/**
|
|
744
|
-
*
|
|
745
|
-
* @description 通常仅在系统重置或大型热更新时使用。
|
|
1438
|
+
* 执行工具
|
|
746
1439
|
*/
|
|
747
|
-
|
|
1440
|
+
execute(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
748
1441
|
}
|
|
749
|
-
declare const serviceRegistry: ServiceRegistry;
|
|
750
1442
|
|
|
751
1443
|
/**
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
* 配置数据通常在应用启动时通过 `usePluginLoader` 注入,并作为插件运行时的取值回退来源。
|
|
1444
|
+
* Mock AI Provider
|
|
1445
|
+
* 用于演示和测试环境,返回预设的智能回复
|
|
755
1446
|
*/
|
|
756
|
-
declare class
|
|
757
|
-
|
|
758
|
-
private config;
|
|
1447
|
+
declare class MockAIProvider implements AIProvider {
|
|
1448
|
+
private responses;
|
|
759
1449
|
/**
|
|
760
|
-
*
|
|
761
|
-
* @param key - 配置键名(如 'system' 或插件 ID)
|
|
762
|
-
* @param value - 配置内容对象
|
|
1450
|
+
* 生成回复
|
|
763
1451
|
*/
|
|
764
|
-
|
|
1452
|
+
private generateResponse;
|
|
765
1453
|
/**
|
|
766
|
-
*
|
|
767
|
-
* @param key - 配置键名
|
|
768
|
-
* @returns 配置内容,若不存在则返回 undefined
|
|
1454
|
+
* 生成唯一 ID
|
|
769
1455
|
*/
|
|
770
|
-
|
|
1456
|
+
private generateId;
|
|
771
1457
|
/**
|
|
772
|
-
*
|
|
773
|
-
* @description 对顶层属性进行浅合并,若属性值为对象则进行一层深度的合并。
|
|
774
|
-
* @param config - 待合并的配置对象映射
|
|
1458
|
+
* 聊天(非流式)
|
|
775
1459
|
*/
|
|
776
|
-
|
|
1460
|
+
chat(messages: AIMessage[], options?: ChatOptions): Promise<AIMessage>;
|
|
777
1461
|
/**
|
|
778
|
-
*
|
|
779
|
-
|
|
1462
|
+
* 流式响应
|
|
1463
|
+
*/
|
|
1464
|
+
stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable<AIChunk>;
|
|
1465
|
+
/**
|
|
1466
|
+
* 函数调用
|
|
780
1467
|
*/
|
|
781
|
-
|
|
1468
|
+
functionCall(messages: AIMessage[], tools: AITool[], options?: ChatOptions): Promise<FunctionCallResult>;
|
|
782
1469
|
}
|
|
783
|
-
/** 全局配置管理器单例 */
|
|
784
|
-
declare const configManager: ConfigManager;
|
|
785
1470
|
|
|
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
1471
|
/**
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
* 确保单个插件的运行异常不会导致整个主应用或其他插件崩溃。
|
|
1472
|
+
* OpenAI Provider 实现
|
|
1473
|
+
* 支持 chat、stream、functionCall 方法
|
|
808
1474
|
*/
|
|
809
|
-
declare class
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
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;
|
|
1475
|
+
declare class OpenAIProvider implements AIProvider {
|
|
1476
|
+
private client;
|
|
1477
|
+
private defaultOptions;
|
|
1478
|
+
constructor(apiKey: string, defaultOptions?: ChatOptions);
|
|
1479
|
+
chat(messages: AIMessage[], options?: ChatOptions): Promise<AIMessage>;
|
|
1480
|
+
stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable<AIChunk>;
|
|
1481
|
+
functionCall(messages: AIMessage[], tools: AITool[], options?: ChatOptions): Promise<FunctionCallResult>;
|
|
1482
|
+
private toOpenAIMessages;
|
|
1483
|
+
private toOpenAITools;
|
|
1484
|
+
private fromOpenAIMessage;
|
|
1485
|
+
private fromOpenAIToolCall;
|
|
827
1486
|
}
|
|
828
1487
|
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
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;
|
|
1488
|
+
interface SessionStorage {
|
|
1489
|
+
save(sessions: Session[]): void;
|
|
1490
|
+
load(): Session[];
|
|
1491
|
+
}
|
|
1492
|
+
interface SessionManagerInterface {
|
|
1493
|
+
createSession(name?: string): Session;
|
|
1494
|
+
getSession(id: string): Session | null;
|
|
1495
|
+
listSessions(): Session[];
|
|
1496
|
+
deleteSession(id: string): void;
|
|
1497
|
+
addMessage(sessionId: string, message: AIMessage): void;
|
|
1498
|
+
clearMessages(sessionId: string): void;
|
|
853
1499
|
}
|
|
854
|
-
/**
|
|
855
|
-
* 插件插槽组件
|
|
856
|
-
* @description UI 层的核心组件,用于在应用中声明一个“插槽”。
|
|
857
|
-
* 它会自动根据 slot 标识从 PluginManager 中获取所有注册的插件扩展组件并按顺序渲染。
|
|
858
|
-
* 支持订阅插件变更,实现动态热插拔。
|
|
859
|
-
*/
|
|
860
|
-
declare const PluginSlot: React.FC<PluginSlotProps>;
|
|
861
1500
|
|
|
862
1501
|
/**
|
|
863
|
-
*
|
|
864
|
-
*
|
|
865
|
-
*/
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
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
|
-
}>;
|
|
1502
|
+
* 会话管理器
|
|
1503
|
+
* 提供会话的创建、查询、删除、消息管理等功能
|
|
1504
|
+
*/
|
|
1505
|
+
declare class SessionManager implements SessionManagerInterface {
|
|
1506
|
+
private sessions;
|
|
1507
|
+
private storage?;
|
|
1508
|
+
constructor(storage?: SessionStorage);
|
|
1509
|
+
createSession(name?: string): Session;
|
|
1510
|
+
getSession(id: string): Session | null;
|
|
1511
|
+
listSessions(): Session[];
|
|
1512
|
+
deleteSession(id: string): void;
|
|
1513
|
+
addMessage(sessionId: string, message: AIMessage): void;
|
|
1514
|
+
clearMessages(sessionId: string): void;
|
|
1515
|
+
private loadFromStorage;
|
|
1516
|
+
private saveToStorage;
|
|
1517
|
+
}
|
|
1518
|
+
|
|
888
1519
|
/**
|
|
889
|
-
*
|
|
1520
|
+
* LocalStorage 适配器,用于会话持久化
|
|
1521
|
+
* 注意:仅在浏览器环境可用
|
|
890
1522
|
*/
|
|
891
|
-
declare
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
}
|
|
1523
|
+
declare class SessionLocalStorageAdapter implements SessionStorage {
|
|
1524
|
+
save(sessions: Session[]): void;
|
|
1525
|
+
load(): Session[];
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
interface AIState {
|
|
1529
|
+
provider: AIProvider | null;
|
|
1530
|
+
setProvider: (provider: AIProvider) => void;
|
|
1531
|
+
sessions: Session[];
|
|
1532
|
+
currentSessionId: string | null;
|
|
1533
|
+
sessionManager: SessionManager;
|
|
1534
|
+
toolRegistry: ToolRegistry;
|
|
1535
|
+
createSession: (name?: string) => Session;
|
|
1536
|
+
selectSession: (id: string) => void;
|
|
1537
|
+
deleteSession: (id: string) => void;
|
|
1538
|
+
addMessage: (message: AIMessage) => void;
|
|
1539
|
+
registerTool: (tool: AITool) => void;
|
|
1540
|
+
unregisterTool: (name: string) => void;
|
|
1541
|
+
sendMessage: (content: string) => Promise<void>;
|
|
1542
|
+
clearCurrentSession: () => void;
|
|
1543
|
+
streamMessage: (content: string, onChunk: (chunk: string) => void) => Promise<void>;
|
|
1544
|
+
}
|
|
1545
|
+
declare const useAIStore: zustand.UseBoundStore<zustand.StoreApi<AIState>>;
|
|
1546
|
+
declare function createAIStore(apiKey: string, defaultModel?: string): void;
|
|
895
1547
|
|
|
896
1548
|
/**
|
|
897
1549
|
* 插件注册表接口
|
|
@@ -930,59 +1582,310 @@ declare const resolvePluginRegistry: (options: {
|
|
|
930
1582
|
rules?: DiscoveryRule[];
|
|
931
1583
|
}) => PluginRegistry;
|
|
932
1584
|
|
|
933
|
-
type EventCallback = (...args: any[]) => any;
|
|
934
1585
|
/**
|
|
935
|
-
*
|
|
1586
|
+
* 日志等级枚举
|
|
936
1587
|
*/
|
|
937
|
-
|
|
1588
|
+
declare enum LogLevel {
|
|
1589
|
+
/** 调试级别:输出最详尽的信息 */
|
|
1590
|
+
DEBUG = 0,
|
|
1591
|
+
/** 信息级别:输出重要的运行状态 */
|
|
1592
|
+
INFO = 1,
|
|
1593
|
+
/** 警告级别:输出潜在的问题,但不影响运行 */
|
|
1594
|
+
WARN = 2,
|
|
1595
|
+
/** 错误级别:输出严重的运行异常 */
|
|
1596
|
+
ERROR = 3,
|
|
1597
|
+
/** 禁用日志:不输出任何信息 */
|
|
1598
|
+
NONE = 4
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* 日志工具类
|
|
1602
|
+
* @description 核心工具类,提供统一的日志输出格式 `[Prefix] Message`。
|
|
1603
|
+
* 支持通过 `LogLevel` 进行全局过滤。
|
|
1604
|
+
* 支持日志缓冲和自动分组,以减少控制台噪音。
|
|
1605
|
+
* 支持浏览器端 CSS 样式和 Node.js 端 ANSI 颜色。
|
|
1606
|
+
*/
|
|
1607
|
+
declare class Logger {
|
|
1608
|
+
/** 全局静态日志等级,所有实例共享 */
|
|
1609
|
+
private static level;
|
|
1610
|
+
/** 日志缓冲区 */
|
|
1611
|
+
private static buffer;
|
|
1612
|
+
/** 缓冲输出防抖定时器 */
|
|
1613
|
+
private static flushTimer;
|
|
1614
|
+
/** 缓冲时间窗口 (ms) */
|
|
1615
|
+
private static FLUSH_INTERVAL;
|
|
1616
|
+
/** 是否启用缓冲模式 */
|
|
1617
|
+
private static bufferEnabled;
|
|
1618
|
+
/** 是否为浏览器环境 */
|
|
1619
|
+
private static isBrowser;
|
|
1620
|
+
/** 当前实例的业务模块前缀 */
|
|
1621
|
+
private prefix;
|
|
1622
|
+
/** 实例特定的颜色 */
|
|
1623
|
+
private color;
|
|
938
1624
|
/**
|
|
939
|
-
*
|
|
940
|
-
* @param
|
|
941
|
-
* @param callback 回调函数
|
|
942
|
-
* @returns 取消订阅函数
|
|
1625
|
+
* 构造函数
|
|
1626
|
+
* @param prefix - 业务模块前缀,默认为 'App'
|
|
943
1627
|
*/
|
|
944
|
-
|
|
1628
|
+
constructor(prefix?: string);
|
|
945
1629
|
/**
|
|
946
|
-
*
|
|
947
|
-
* @param
|
|
948
|
-
* @param callback 回调函数
|
|
1630
|
+
* 静态方法:设置全局日志输出等级
|
|
1631
|
+
* @param level - 目标日志等级
|
|
949
1632
|
*/
|
|
950
|
-
|
|
1633
|
+
static setLevel(level: LogLevel): void;
|
|
951
1634
|
/**
|
|
952
|
-
*
|
|
953
|
-
* @param
|
|
954
|
-
* @param args 事件参数
|
|
1635
|
+
* 静态方法:启用或禁用日志缓冲
|
|
1636
|
+
* @param enabled - 是否启用
|
|
955
1637
|
*/
|
|
956
|
-
|
|
1638
|
+
static setBufferEnabled(enabled: boolean): void;
|
|
957
1639
|
/**
|
|
958
|
-
*
|
|
959
|
-
* @
|
|
960
|
-
* @param callback 回调函数
|
|
1640
|
+
* 静态方法:获取当前全局日志等级
|
|
1641
|
+
* @returns 当前生效的全局日志等级
|
|
961
1642
|
*/
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1643
|
+
static getLevel(): LogLevel;
|
|
1644
|
+
/**
|
|
1645
|
+
* 格式化输出前缀
|
|
1646
|
+
*/
|
|
1647
|
+
private getFormattedPrefix;
|
|
1648
|
+
/**
|
|
1649
|
+
* 生成分组标题参数
|
|
1650
|
+
*/
|
|
1651
|
+
private static getGroupTitleArgs;
|
|
1652
|
+
/**
|
|
1653
|
+
* 内部方法:将日志推入缓冲区或直接输出
|
|
1654
|
+
*/
|
|
1655
|
+
private log;
|
|
1656
|
+
/**
|
|
1657
|
+
* 静态方法:刷新缓冲区,分组输出日志
|
|
1658
|
+
*/
|
|
1659
|
+
static flush(): void;
|
|
1660
|
+
/**
|
|
1661
|
+
* 打印 DEBUG 级别日志
|
|
1662
|
+
*/
|
|
1663
|
+
debug(...args: any[]): void;
|
|
1664
|
+
/**
|
|
1665
|
+
* 打印 INFO 级别日志
|
|
1666
|
+
*/
|
|
1667
|
+
info(...args: any[]): void;
|
|
1668
|
+
/**
|
|
1669
|
+
* 打印 WARN 级别日志
|
|
1670
|
+
*/
|
|
1671
|
+
warn(...args: any[]): void;
|
|
1672
|
+
/**
|
|
1673
|
+
* 打印 ERROR 级别日志
|
|
1674
|
+
*/
|
|
1675
|
+
error(...args: any[]): void;
|
|
1676
|
+
/**
|
|
1677
|
+
* 开始一个日志控制台分组
|
|
1678
|
+
*/
|
|
1679
|
+
group(label: string, collapsed?: boolean): void;
|
|
1680
|
+
/**
|
|
1681
|
+
* 结束当前日志控制台分组
|
|
1682
|
+
*/
|
|
1683
|
+
groupEnd(): void;
|
|
1684
|
+
}
|
|
1685
|
+
/** 默认 Logger 实例 */
|
|
1686
|
+
declare const logger: Logger;
|
|
1687
|
+
/**
|
|
1688
|
+
* 创建带特定前缀的 Logger 实例
|
|
1689
|
+
* @param prefix 日志前缀
|
|
1690
|
+
* @returns Logger 实例
|
|
1691
|
+
*/
|
|
1692
|
+
declare const createLogger: (prefix: string) => Logger;
|
|
1693
|
+
|
|
1694
|
+
/**
|
|
1695
|
+
* @file errors.ts
|
|
1696
|
+
* @description Core 层统一错误处理定义
|
|
1697
|
+
*/
|
|
1698
|
+
|
|
1699
|
+
/**
|
|
1700
|
+
* 核心错误码枚举
|
|
1701
|
+
*/
|
|
1702
|
+
declare enum CoreErrorCode {
|
|
1703
|
+
UNKNOWN = "1000",
|
|
1704
|
+
NOT_FOUND = "1001",
|
|
1705
|
+
INVALID_PARAMS = "1002",
|
|
1706
|
+
TIMEOUT = "1003",
|
|
1707
|
+
PLUGIN_NOT_FOUND = "2001",
|
|
1708
|
+
PLUGIN_LOAD_FAILED = "2002",
|
|
1709
|
+
PLUGIN_MOUNT_FAILED = "2003",
|
|
1710
|
+
PLUGIN_UNMOUNT_FAILED = "2004",
|
|
1711
|
+
PLUGIN_DEPENDENCY_MISSING = "2005",
|
|
1712
|
+
PLUGIN_CIRCULAR_DEPENDENCY = "2006",
|
|
1713
|
+
PLUGIN_INIT_FAILED = "2007",
|
|
1714
|
+
STORAGE_READ_FAILED = "3001",
|
|
1715
|
+
STORAGE_WRITE_FAILED = "3002",
|
|
1716
|
+
STORAGE_SCHEMA_VIOLATION = "3003",
|
|
1717
|
+
STORAGE_QUOTA_EXCEEDED = "3004",
|
|
1718
|
+
API_REQUEST_FAILED = "4001",
|
|
1719
|
+
API_RESPONSE_INVALID = "4002",
|
|
1720
|
+
API_NETWORK_ERROR = "4003",
|
|
1721
|
+
API_TIMEOUT = "4004",
|
|
1722
|
+
API_UNAUTHORIZED = "4005",
|
|
1723
|
+
SANDBOX_EVAL_FAILED = "5001",
|
|
1724
|
+
SANDBOX_ISOLATION_BREACHED = "5002",
|
|
1725
|
+
SANDBOX_MEMORY_LIMIT = "5003",
|
|
1726
|
+
SERVICE_NOT_FOUND = "6001",
|
|
1727
|
+
SERVICE_REGISTER_FAILED = "6002",
|
|
1728
|
+
SERVICE_WAIT_TIMEOUT = "6003"
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* 错误处理策略
|
|
1732
|
+
*/
|
|
1733
|
+
declare enum CoreErrorStrategy {
|
|
1734
|
+
THROW = "throw",// 抛出异常
|
|
1735
|
+
RESOLVE = "resolve",// 返回默认值
|
|
1736
|
+
REJECT = "reject",// 返回 Promise reject
|
|
1737
|
+
SILENT = "silent"
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* 错误处理选项
|
|
1741
|
+
*/
|
|
1742
|
+
interface ErrorHandlerOptions {
|
|
1743
|
+
code: CoreErrorCode;
|
|
1744
|
+
strategy: CoreErrorStrategy;
|
|
1745
|
+
defaultValue?: any;
|
|
1746
|
+
logger?: ReturnType<typeof createLogger>;
|
|
1747
|
+
context?: Record<string, any>;
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* 核心错误类
|
|
1751
|
+
*/
|
|
1752
|
+
declare class CoreError extends Error {
|
|
1753
|
+
readonly code: CoreErrorCode;
|
|
1754
|
+
readonly originalError?: Error;
|
|
1755
|
+
readonly context?: Record<string, any>;
|
|
1756
|
+
constructor(code: CoreErrorCode, message: string, originalError?: Error, context?: Record<string, any>);
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* 统一错误处理函数
|
|
1760
|
+
*/
|
|
1761
|
+
declare function handleError(error: unknown, options: ErrorHandlerOptions): any;
|
|
1762
|
+
|
|
1763
|
+
/**
|
|
1764
|
+
* 成功状态码
|
|
1765
|
+
*/
|
|
1766
|
+
declare const SUCCESS_CODE = "000000";
|
|
1767
|
+
/**
|
|
1768
|
+
* 基础 API 响应接口
|
|
1769
|
+
* @template T 响应数据的类型
|
|
1770
|
+
*/
|
|
1771
|
+
interface BaseResponse<T = any> {
|
|
1772
|
+
/** 业务状态码 */
|
|
1773
|
+
code: string | number;
|
|
1774
|
+
/** 响应消息提示 */
|
|
1775
|
+
message: string;
|
|
1776
|
+
/** 业务响应数据主体 */
|
|
1777
|
+
data: T;
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* 业务场景实体接口
|
|
1781
|
+
* @description 描述系统中的业务分析场景
|
|
1782
|
+
*/
|
|
1783
|
+
interface Scene {
|
|
1784
|
+
/** 场景唯一标识符 */
|
|
1785
|
+
id: string;
|
|
1786
|
+
/** 场景名称 */
|
|
1787
|
+
name: string;
|
|
1788
|
+
/** 场景详细描述 */
|
|
1789
|
+
description: string;
|
|
1790
|
+
/** 场景内部代码/标识 */
|
|
1791
|
+
code: string;
|
|
1792
|
+
/** 场景创建者 ID 或名称 */
|
|
1793
|
+
creator: string;
|
|
1794
|
+
/** 创建时间字符串 (ISO 格式) */
|
|
1795
|
+
createTime: string;
|
|
1796
|
+
/** 该场景关联的物理数据表数量 */
|
|
1797
|
+
tableCount: number;
|
|
1798
|
+
/** 该场景关联的知识库数量 */
|
|
1799
|
+
kbCount: number;
|
|
1800
|
+
/** 该场景关联的预设问答对数量 */
|
|
1801
|
+
qaCount: number;
|
|
1802
|
+
/** 场景封面图 URL (可选) */
|
|
1803
|
+
cover?: string;
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
/**
|
|
1807
|
+
* @file performance/types.ts
|
|
1808
|
+
* @description 性能监测数据类型定义
|
|
1809
|
+
* @author ChatBI Team
|
|
1810
|
+
*/
|
|
1811
|
+
/**
|
|
1812
|
+
* 插件生命周期阶段
|
|
1813
|
+
*/
|
|
1814
|
+
type LifecyclePhase = 'load' | 'mount' | 'unmount';
|
|
1815
|
+
/**
|
|
1816
|
+
* 生命周期性能指标
|
|
1817
|
+
* 记录插件 load/mount/unmount 阶段的执行耗时
|
|
1818
|
+
*/
|
|
1819
|
+
interface LifecycleMetric {
|
|
1820
|
+
/** 插件 ID */
|
|
1821
|
+
pluginId: string;
|
|
1822
|
+
/** 生命周期阶段 */
|
|
1823
|
+
phase: LifecyclePhase;
|
|
1824
|
+
/** 执行耗时(毫秒) */
|
|
1825
|
+
duration: number;
|
|
1826
|
+
/** 时间戳 */
|
|
1827
|
+
timestamp: number;
|
|
1828
|
+
/** 是否成功 */
|
|
1829
|
+
success: boolean;
|
|
1830
|
+
/** 错误信息(仅在 success 为 false 时存在) */
|
|
1831
|
+
error?: string;
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* 运行时性能指标
|
|
1835
|
+
* 记录插件运行期间的内存、帧率等数据
|
|
1836
|
+
*/
|
|
1837
|
+
interface RuntimeMetric {
|
|
1838
|
+
/** 插件 ID */
|
|
1839
|
+
pluginId: string;
|
|
1840
|
+
/** 时间戳 */
|
|
1841
|
+
timestamp: number;
|
|
1842
|
+
/** 内存使用量(字节) */
|
|
1843
|
+
memory?: number;
|
|
1844
|
+
/** 帧率 */
|
|
1845
|
+
fps?: number;
|
|
1846
|
+
/** API 调用次数 */
|
|
1847
|
+
apiCalls?: number;
|
|
1848
|
+
}
|
|
1849
|
+
/**
|
|
1850
|
+
* 性能数据集合
|
|
1851
|
+
*/
|
|
1852
|
+
interface PerformanceData {
|
|
1853
|
+
/** 生命周期指标集合 */
|
|
1854
|
+
lifecycle: LifecycleMetric[];
|
|
1855
|
+
/** 运行时采样数据集合 */
|
|
1856
|
+
samples: RuntimeMetric[];
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* 性能监测配置
|
|
1860
|
+
*/
|
|
1861
|
+
interface PerformanceSettings {
|
|
1862
|
+
/** 生命周期记录最大条数(默认 1000) */
|
|
1863
|
+
maxLifecycleRecords: number;
|
|
1864
|
+
/** 运行时采样最大条数(默认 500) */
|
|
1865
|
+
maxRuntimeSamples: number;
|
|
1866
|
+
/** 采样率(0-1 之间) */
|
|
1867
|
+
sampleRate: number;
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* 默认性能监测配置
|
|
1871
|
+
*/
|
|
1872
|
+
declare const DEFAULT_PERFORMANCE_SETTINGS: PerformanceSettings;
|
|
1873
|
+
|
|
1874
|
+
/**
|
|
1875
|
+
* 核心领域服务:存储管理器
|
|
1876
|
+
* @description 统一管理应用内所有的持久化存储资源。
|
|
1877
|
+
* 核心功能:
|
|
1878
|
+
* 1. 作用域隔离:通过前缀划分 `plugin`、`shared` 和 `system` 三个层级的存储空间。
|
|
977
1879
|
* 2. Schema 校验:支持注册存储描述,规范数据存取,避免键名冲突。
|
|
978
1880
|
* 3. 默认值与配置回退:支持从 Schema 默认值或 ConfigManager 中回退取值。
|
|
1881
|
+
* 4. LRU 缓存:使用 LRU 策略管理内存缓存,防止无限增长。
|
|
979
1882
|
*/
|
|
980
1883
|
declare class StorageManager {
|
|
981
1884
|
/** 底层物理存储驱动 */
|
|
982
1885
|
private baseStorage;
|
|
983
1886
|
/** 插件 ID 与存储描述定义的映射关系 */
|
|
984
1887
|
private schemas;
|
|
985
|
-
/** 内存缓存,减少 JSON 序列化和物理 IO 开销 */
|
|
1888
|
+
/** LRU 内存缓存,减少 JSON 序列化和物理 IO 开销 */
|
|
986
1889
|
private memoryCache;
|
|
987
1890
|
/**
|
|
988
1891
|
* 初始化存储管理器
|
|
@@ -1043,221 +1946,151 @@ declare class StorageManager {
|
|
|
1043
1946
|
}
|
|
1044
1947
|
|
|
1045
1948
|
/**
|
|
1046
|
-
*
|
|
1047
|
-
* @description
|
|
1949
|
+
* 性能数据存储层
|
|
1950
|
+
* @description 负责性能数据的持久化,支持生命周期指标和运行时采样数据的存储与查询
|
|
1048
1951
|
*/
|
|
1049
|
-
declare class
|
|
1050
|
-
/** 全局事件总线,用于插件间及插件与内核间的异步通信 */
|
|
1051
|
-
readonly eventBus: DefaultEventBus;
|
|
1052
|
-
/** 存储管理服务,负责插件私有存储和系统级状态的持久化 */
|
|
1952
|
+
declare class PerformanceStorage {
|
|
1053
1953
|
private storageManager;
|
|
1054
|
-
|
|
1055
|
-
private
|
|
1056
|
-
|
|
1057
|
-
private
|
|
1058
|
-
|
|
1059
|
-
private
|
|
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
|
-
private isInitializing;
|
|
1954
|
+
private systemStorage;
|
|
1955
|
+
private settings;
|
|
1956
|
+
private lifecycleCache;
|
|
1957
|
+
private runtimeCache;
|
|
1958
|
+
private readonly LIFECYCLE_KEY;
|
|
1959
|
+
private readonly RUNTIME_KEY;
|
|
1078
1960
|
/**
|
|
1079
1961
|
* 构造函数
|
|
1080
|
-
* @param
|
|
1962
|
+
* @param storageManager - 存储管理器实例
|
|
1963
|
+
* @param settings - 性能设置(可选,默认使用 DEFAULT_PERFORMANCE_SETTINGS)
|
|
1081
1964
|
*/
|
|
1082
|
-
constructor(
|
|
1965
|
+
constructor(storageManager: StorageManager, settings?: PerformanceSettings);
|
|
1083
1966
|
/**
|
|
1084
|
-
*
|
|
1967
|
+
* 从持久化存储加载数据到内存缓存
|
|
1085
1968
|
*/
|
|
1086
|
-
private
|
|
1969
|
+
private loadFromStorage;
|
|
1087
1970
|
/**
|
|
1088
|
-
*
|
|
1971
|
+
* 保存生命周期指标
|
|
1972
|
+
* @param metric - 生命周期指标
|
|
1089
1973
|
*/
|
|
1090
|
-
|
|
1974
|
+
saveLifecycleMetric(metric: LifecycleMetric): void;
|
|
1091
1975
|
/**
|
|
1092
|
-
*
|
|
1093
|
-
* @param
|
|
1094
|
-
* @param slot - (可选) 指定监听的插槽位置,若提供则仅在该插槽受影响时通知
|
|
1095
|
-
* @returns 取消订阅的函数
|
|
1976
|
+
* 保存运行时指标
|
|
1977
|
+
* @param metric - 运行时指标
|
|
1096
1978
|
*/
|
|
1097
|
-
|
|
1979
|
+
saveRuntimeMetric(metric: RuntimeMetric): void;
|
|
1098
1980
|
/**
|
|
1099
|
-
*
|
|
1100
|
-
* @
|
|
1981
|
+
* 保存指标(通用方法,自动识别类型)
|
|
1982
|
+
* @param metric - 指标数据
|
|
1101
1983
|
*/
|
|
1102
|
-
|
|
1984
|
+
saveMetric(metric: LifecycleMetric | RuntimeMetric): void;
|
|
1103
1985
|
/**
|
|
1104
|
-
*
|
|
1105
|
-
* @param affectedSlot - (可选) 受影响的插槽位置
|
|
1986
|
+
* 强制执行生命周期数据上限(FIFO)
|
|
1106
1987
|
*/
|
|
1107
|
-
private
|
|
1988
|
+
private enforceLifecycleLimit;
|
|
1108
1989
|
/**
|
|
1109
|
-
*
|
|
1110
|
-
* @description 结果会根据插件类型优先级和用户自定义排序进行排序
|
|
1111
|
-
* @returns 排序后的插件数组
|
|
1990
|
+
* 强制执行运行时数据上限(FIFO)
|
|
1112
1991
|
*/
|
|
1113
|
-
|
|
1992
|
+
private enforceRuntimeLimit;
|
|
1114
1993
|
/**
|
|
1115
|
-
*
|
|
1116
|
-
* @param pluginId - 插件 ID
|
|
1117
|
-
* @returns 包含启用状态和排序值的对象
|
|
1994
|
+
* 持久化生命周期数据
|
|
1118
1995
|
*/
|
|
1119
|
-
|
|
1120
|
-
enabled: boolean;
|
|
1121
|
-
order: number;
|
|
1122
|
-
};
|
|
1996
|
+
private persistLifecycle;
|
|
1123
1997
|
/**
|
|
1124
|
-
*
|
|
1125
|
-
* @param pluginId - 插件 ID
|
|
1126
|
-
* @returns 是否启用
|
|
1998
|
+
* 持久化运行时数据
|
|
1127
1999
|
*/
|
|
1128
|
-
|
|
2000
|
+
private persistRuntime;
|
|
1129
2001
|
/**
|
|
1130
|
-
*
|
|
1131
|
-
* @
|
|
1132
|
-
* @param pluginId - 插件 ID
|
|
1133
|
-
* @param enabled - 目标状态
|
|
2002
|
+
* 获取生命周期指标
|
|
2003
|
+
* @param pluginId - 插件 ID(可选,不传则返回所有)
|
|
1134
2004
|
*/
|
|
1135
|
-
|
|
2005
|
+
getLifecycleMetrics(pluginId?: string): LifecycleMetric[];
|
|
1136
2006
|
/**
|
|
1137
|
-
*
|
|
1138
|
-
* @param pluginId - 插件 ID
|
|
1139
|
-
* @param order - 排序权重值
|
|
2007
|
+
* 获取运行时指标
|
|
2008
|
+
* @param pluginId - 插件 ID(可选,不传则返回所有)
|
|
1140
2009
|
*/
|
|
1141
|
-
|
|
2010
|
+
getRuntimeMetrics(pluginId?: string): RuntimeMetric[];
|
|
1142
2011
|
/**
|
|
1143
|
-
*
|
|
1144
|
-
* @param pluginId - 插件 ID
|
|
1145
|
-
* @returns 'error' | 'mounted' | 'loaded' | 'initial'
|
|
2012
|
+
* 清除性能数据
|
|
2013
|
+
* @param pluginId - 插件 ID(可选,不传则清除所有)
|
|
1146
2014
|
*/
|
|
1147
|
-
|
|
2015
|
+
clearMetrics(pluginId?: string): void;
|
|
1148
2016
|
/**
|
|
1149
|
-
*
|
|
1150
|
-
* @param pluginId - 插件 ID
|
|
1151
|
-
* @returns Error 对象或 null
|
|
2017
|
+
* 获取所有性能数据
|
|
1152
2018
|
*/
|
|
1153
|
-
|
|
2019
|
+
getAllData(): PerformanceData;
|
|
1154
2020
|
/**
|
|
1155
|
-
*
|
|
1156
|
-
* @param pluginId - 插件 ID
|
|
1157
|
-
* @param error - 错误对象
|
|
2021
|
+
* 获取指定插件的性能数据
|
|
1158
2022
|
*/
|
|
1159
|
-
|
|
2023
|
+
getPluginData(pluginId: string): PerformanceData;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
/**
|
|
2027
|
+
* 性能计时器
|
|
2028
|
+
* @description 用于测量代码块执行耗时,自动计算 duration 并保存到存储
|
|
2029
|
+
*/
|
|
2030
|
+
declare class PerformanceTimer {
|
|
2031
|
+
private startTime;
|
|
2032
|
+
private phase;
|
|
2033
|
+
private pluginId;
|
|
2034
|
+
private storage;
|
|
1160
2035
|
/**
|
|
1161
|
-
*
|
|
2036
|
+
* 构造函数
|
|
2037
|
+
* @param phase - 生命周期阶段
|
|
1162
2038
|
* @param pluginId - 插件 ID
|
|
1163
|
-
* @
|
|
2039
|
+
* @param storage - 性能存储实例
|
|
1164
2040
|
*/
|
|
1165
|
-
|
|
2041
|
+
constructor(phase: LifecyclePhase, pluginId: string, storage: PerformanceStorage);
|
|
1166
2042
|
/**
|
|
1167
|
-
*
|
|
1168
|
-
* @description 该操作会同步更新内存中的配置、持久化到存储并触发全局事件通知。
|
|
1169
|
-
* @param pluginId - 插件 ID
|
|
1170
|
-
* @param key - 配置键名
|
|
1171
|
-
* @param value - 新的配置值
|
|
2043
|
+
* 开始计时
|
|
1172
2044
|
*/
|
|
1173
|
-
|
|
2045
|
+
start(): void;
|
|
1174
2046
|
/**
|
|
1175
|
-
*
|
|
1176
|
-
* @param
|
|
1177
|
-
* @param
|
|
1178
|
-
* @returns 配置值
|
|
2047
|
+
* 结束计时并保存结果
|
|
2048
|
+
* @param success - 是否成功
|
|
2049
|
+
* @param error - 错误信息(可选)
|
|
1179
2050
|
*/
|
|
1180
|
-
|
|
2051
|
+
end(success: boolean, error?: string): void;
|
|
2052
|
+
}
|
|
2053
|
+
/**
|
|
2054
|
+
* 性能数据采集器
|
|
2055
|
+
* @description 负责性能数据的采集和记录,提供计时器创建和运行时指标记录功能
|
|
2056
|
+
*/
|
|
2057
|
+
declare class PerformanceCollector {
|
|
2058
|
+
private storage;
|
|
1181
2059
|
/**
|
|
1182
|
-
*
|
|
1183
|
-
* @param
|
|
1184
|
-
* @returns 配置值
|
|
2060
|
+
* 构造函数
|
|
2061
|
+
* @param storage - 性能存储实例
|
|
1185
2062
|
*/
|
|
1186
|
-
|
|
2063
|
+
constructor(storage: PerformanceStorage);
|
|
1187
2064
|
/**
|
|
1188
|
-
*
|
|
1189
|
-
* @
|
|
1190
|
-
* @param
|
|
1191
|
-
* @returns
|
|
2065
|
+
* 开始测量指定生命周期阶段
|
|
2066
|
+
* @param phase - 生命周期阶段
|
|
2067
|
+
* @param pluginId - 插件 ID
|
|
2068
|
+
* @returns PerformanceTimer 实例
|
|
1192
2069
|
*/
|
|
1193
|
-
|
|
2070
|
+
startMeasure(phase: LifecyclePhase, pluginId: string): PerformanceTimer;
|
|
1194
2071
|
/**
|
|
1195
|
-
*
|
|
1196
|
-
* @param
|
|
1197
|
-
* @returns 排序后的扩展配置数组
|
|
2072
|
+
* 记录运行时指标
|
|
2073
|
+
* @param metric - 运行时指标(不包含 timestamp)
|
|
1198
2074
|
*/
|
|
1199
|
-
|
|
2075
|
+
recordRuntimeMetric(metric: Omit<RuntimeMetric, 'timestamp'>): void;
|
|
1200
2076
|
/**
|
|
1201
|
-
*
|
|
1202
|
-
* @
|
|
2077
|
+
* 获取性能指标
|
|
2078
|
+
* @param pluginId - 插件 ID(可选,不传则返回所有)
|
|
1203
2079
|
*/
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
* @param plugin - 插件对象
|
|
1209
|
-
* @param notify - 是否在注册完成后触发状态变更通知
|
|
1210
|
-
*/
|
|
1211
|
-
register(plugin: Plugin, notify?: boolean): void;
|
|
1212
|
-
/**
|
|
1213
|
-
* 手动挂载指定插件(支持按需加载)
|
|
1214
|
-
* @description 如果插件依赖尚未挂载,会递归挂载所有依赖
|
|
1215
|
-
* @param pluginId 插件 ID
|
|
1216
|
-
*/
|
|
1217
|
-
mountPlugin(pluginId: string): Promise<void>;
|
|
1218
|
-
/**
|
|
1219
|
-
* 初始化所有插件
|
|
1220
|
-
* @param sharedContext 共享上下文
|
|
1221
|
-
* @param autoMount 是否自动挂载所有插件 (默认为 false,启用按需加载模式)
|
|
1222
|
-
*/
|
|
1223
|
-
initPlugins(sharedContext?: Record<string, any>, autoMount?: boolean): Promise<void>;
|
|
1224
|
-
/**
|
|
1225
|
-
* 获取排序后的插件 ID 列表 (处理依赖)
|
|
1226
|
-
*/
|
|
1227
|
-
private getSortedPluginIds;
|
|
1228
|
-
/**
|
|
1229
|
-
* 加载插件列表
|
|
1230
|
-
* @param configs 插件配置
|
|
1231
|
-
* @param registry 插件注册表 (动态导入函数)
|
|
1232
|
-
* @param notify 是否在加载完成后触发通知,默认为 true
|
|
1233
|
-
*/
|
|
1234
|
-
loadPlugins(configs: Record<string, any>, registry: Record<string, () => Promise<any>>, notify?: boolean): Promise<void>;
|
|
1235
|
-
/**
|
|
1236
|
-
* 加载远程插件
|
|
1237
|
-
* @param pluginId 插件 ID
|
|
1238
|
-
* @param url 远程 URL
|
|
1239
|
-
* @param config 插件配置
|
|
1240
|
-
*/
|
|
1241
|
-
loadRemotePlugin(pluginId: string, url: string, config: any): Promise<Plugin | null>;
|
|
2080
|
+
getMetrics(pluginId?: string): {
|
|
2081
|
+
lifecycle: LifecycleMetric[];
|
|
2082
|
+
runtime: RuntimeMetric[];
|
|
2083
|
+
};
|
|
1242
2084
|
/**
|
|
1243
|
-
*
|
|
2085
|
+
* 清除性能数据
|
|
2086
|
+
* @param pluginId - 插件 ID(可选,不传则清除所有)
|
|
1244
2087
|
*/
|
|
1245
|
-
|
|
2088
|
+
clearMetrics(pluginId?: string): void;
|
|
1246
2089
|
/**
|
|
1247
|
-
*
|
|
2090
|
+
* 获取存储实例(供外部使用)
|
|
1248
2091
|
*/
|
|
1249
|
-
|
|
1250
|
-
private validatePlugin;
|
|
1251
|
-
private handleBusinessPlugin;
|
|
1252
|
-
private handleFunctionalPlugin;
|
|
1253
|
-
private handleViewPlugin;
|
|
1254
|
-
private handleThemePlugin;
|
|
1255
|
-
private handleSystemPlugin;
|
|
2092
|
+
getStorage(): PerformanceStorage;
|
|
1256
2093
|
}
|
|
1257
|
-
/**
|
|
1258
|
-
* 全局插件管理器实例
|
|
1259
|
-
*/
|
|
1260
|
-
declare const pluginManager: PluginManager;
|
|
1261
2094
|
|
|
1262
2095
|
/**
|
|
1263
2096
|
* @file plugin-runtime.ts
|
|
@@ -1291,6 +2124,10 @@ declare class PluginRuntime {
|
|
|
1291
2124
|
* @param storageManager - 全局存储管理器
|
|
1292
2125
|
*/
|
|
1293
2126
|
constructor(plugin: Plugin, sharedContext: Record<string, any>, storageManager: StorageManager);
|
|
2127
|
+
/**
|
|
2128
|
+
* 检查插件是否已完成加载
|
|
2129
|
+
*/
|
|
2130
|
+
isLoadedStatus(): boolean;
|
|
1294
2131
|
/**
|
|
1295
2132
|
* 执行插件的加载逻辑 (onLoad)
|
|
1296
2133
|
* @description 此阶段会自动注册插件声明的 API 配置,并调用插件的 onLoad 钩子。
|
|
@@ -1330,429 +2167,1608 @@ declare class PluginRuntime {
|
|
|
1330
2167
|
}
|
|
1331
2168
|
|
|
1332
2169
|
/**
|
|
1333
|
-
*
|
|
1334
|
-
* @description
|
|
1335
|
-
* 它是插件与系统核心之间的“中间层”,确保插件只能访问其权限范围内的资源。
|
|
1336
|
-
* 主要职责:
|
|
1337
|
-
* 1. 存储隔离:确保插件只能读写属于自己的 LocalStorage 命名空间。
|
|
1338
|
-
* 2. 日志隔离:为插件提供带有自身 ID 前缀的日志输出,方便调试。
|
|
2170
|
+
* 生命周期监测器(装饰器模式)
|
|
2171
|
+
* @description 通过代理模式包装 PluginRuntime,在生命周期各阶段自动记录耗时
|
|
1339
2172
|
*/
|
|
1340
|
-
declare class
|
|
1341
|
-
|
|
1342
|
-
private
|
|
1343
|
-
/** 系统全局存储管理器 */
|
|
1344
|
-
private storageManager;
|
|
2173
|
+
declare class LifecycleMonitor {
|
|
2174
|
+
private runtime;
|
|
2175
|
+
private collector;
|
|
1345
2176
|
/**
|
|
1346
|
-
*
|
|
1347
|
-
* @param
|
|
1348
|
-
* @param
|
|
2177
|
+
* 构造函数
|
|
2178
|
+
* @param runtime - 插件运行时实例
|
|
2179
|
+
* @param collector - 性能采集器实例
|
|
1349
2180
|
*/
|
|
1350
|
-
constructor(
|
|
2181
|
+
constructor(runtime: PluginRuntime, collector: PerformanceCollector);
|
|
1351
2182
|
/**
|
|
1352
|
-
*
|
|
1353
|
-
* @
|
|
2183
|
+
* 包装插件运行时,返回代理对象
|
|
2184
|
+
* @returns 包装后的运行时对象
|
|
1354
2185
|
*/
|
|
1355
|
-
|
|
1356
|
-
shared: {
|
|
1357
|
-
get: <T = any>(key: string) => T | null;
|
|
1358
|
-
set: <T = any>(key: string, value: T) => void;
|
|
1359
|
-
remove: (key: string) => void;
|
|
1360
|
-
};
|
|
1361
|
-
get: <T = any>(key: string) => T | null;
|
|
1362
|
-
set: <T = any>(key: string, value: T) => void;
|
|
1363
|
-
remove: (key: string) => void;
|
|
1364
|
-
};
|
|
2186
|
+
wrap(): PluginRuntime;
|
|
1365
2187
|
/**
|
|
1366
|
-
*
|
|
1367
|
-
* @
|
|
2188
|
+
* 包装指定方法,在执行前后记录耗时
|
|
2189
|
+
* @param phase - 生命周期阶段
|
|
2190
|
+
* @param originalMethod - 原始方法
|
|
1368
2191
|
*/
|
|
1369
|
-
|
|
2192
|
+
private wrapMethod;
|
|
1370
2193
|
}
|
|
2194
|
+
/**
|
|
2195
|
+
* 创建生命周期监测器
|
|
2196
|
+
* @param runtime - 插件运行时实例
|
|
2197
|
+
* @param collector - 性能采集器实例
|
|
2198
|
+
* @returns LifecycleMonitor 实例
|
|
2199
|
+
*/
|
|
2200
|
+
declare function createLifecycleMonitor(runtime: PluginRuntime, collector: PerformanceCollector): LifecycleMonitor;
|
|
1371
2201
|
|
|
1372
2202
|
/**
|
|
1373
|
-
*
|
|
1374
|
-
* @description
|
|
1375
|
-
*
|
|
2203
|
+
* @file performance/index.ts
|
|
2204
|
+
* @description 性能监测模块统一导出
|
|
2205
|
+
* @author ChatBI Team
|
|
1376
2206
|
*/
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
2207
|
+
|
|
2208
|
+
/**
|
|
2209
|
+
* 性能监测系统工厂函数
|
|
2210
|
+
* @param storageManager - 存储管理器实例
|
|
2211
|
+
* @param settings - 性能设置(可选)
|
|
2212
|
+
* @returns 包含 collector, storage, monitor 的对象
|
|
2213
|
+
*/
|
|
2214
|
+
declare function createPerformanceMonitor(storageManager: StorageManager, settings?: PerformanceSettings): {
|
|
2215
|
+
collector: PerformanceCollector;
|
|
2216
|
+
storage: PerformanceStorage;
|
|
2217
|
+
createMonitor: (runtime: any) => LifecycleMonitor;
|
|
2218
|
+
};
|
|
2219
|
+
|
|
2220
|
+
declare const PluginEvents: {
|
|
2221
|
+
readonly LOAD: "plugin:load";
|
|
2222
|
+
readonly LOADED: "plugin:loaded";
|
|
2223
|
+
readonly MOUNT: "plugin:mount";
|
|
2224
|
+
readonly MOUNTED: "plugin:mounted";
|
|
2225
|
+
readonly UNMOUNT: "plugin:unmount";
|
|
2226
|
+
readonly LOAD_FAILED: "plugin:load-failed";
|
|
2227
|
+
readonly MOUNT_FAILED: "plugin:mount-failed";
|
|
2228
|
+
};
|
|
2229
|
+
declare const ConfigEvents: {
|
|
2230
|
+
readonly CHANGE: "config:change";
|
|
2231
|
+
};
|
|
2232
|
+
/**
|
|
2233
|
+
* 事件回调函数类型
|
|
2234
|
+
* @param T 事件参数类型元组
|
|
2235
|
+
* @returns void
|
|
2236
|
+
*/
|
|
2237
|
+
type EventCallback<T extends unknown[] = unknown[]> = (...args: T) => void;
|
|
2238
|
+
/**
|
|
2239
|
+
* 事件总线接口
|
|
2240
|
+
*/
|
|
2241
|
+
interface EventBus {
|
|
1380
2242
|
/**
|
|
1381
|
-
*
|
|
1382
|
-
* @param
|
|
2243
|
+
* 订阅事件
|
|
2244
|
+
* @param event 事件名称
|
|
2245
|
+
* @param callback 回调函数
|
|
2246
|
+
* @returns 取消订阅函数
|
|
1383
2247
|
*/
|
|
1384
|
-
|
|
2248
|
+
on<T extends unknown[]>(event: string, callback: EventCallback<T>): () => void;
|
|
1385
2249
|
/**
|
|
1386
|
-
*
|
|
1387
|
-
* @param
|
|
1388
|
-
* @
|
|
2250
|
+
* 取消订阅
|
|
2251
|
+
* @param event 事件名称
|
|
2252
|
+
* @param callback 回调函数
|
|
1389
2253
|
*/
|
|
1390
|
-
|
|
2254
|
+
off<T extends unknown[]>(event: string, callback: EventCallback<T>): void;
|
|
1391
2255
|
/**
|
|
1392
|
-
*
|
|
1393
|
-
* @param
|
|
1394
|
-
* @
|
|
2256
|
+
* 触发事件
|
|
2257
|
+
* @param event 事件名称
|
|
2258
|
+
* @param args 事件参数
|
|
1395
2259
|
*/
|
|
1396
|
-
|
|
2260
|
+
emit<T extends unknown[]>(event: string, ...args: T): void;
|
|
1397
2261
|
/**
|
|
1398
|
-
*
|
|
1399
|
-
* @param
|
|
1400
|
-
* @
|
|
2262
|
+
* 订阅一次性事件
|
|
2263
|
+
* @param event 事件名称
|
|
2264
|
+
* @param callback 回调函数
|
|
1401
2265
|
*/
|
|
1402
|
-
|
|
2266
|
+
once<T extends unknown[]>(event: string, callback: EventCallback<T>): void;
|
|
2267
|
+
}
|
|
2268
|
+
declare class DefaultEventBus implements EventBus {
|
|
2269
|
+
private listeners;
|
|
2270
|
+
on<T extends unknown[]>(event: string, callback: EventCallback<T>): () => void;
|
|
2271
|
+
off<T extends unknown[]>(event: string, callback: EventCallback<T>): void;
|
|
2272
|
+
emit<T extends unknown[]>(event: string, ...args: T): void;
|
|
2273
|
+
once<T extends unknown[]>(event: string, callback: EventCallback<T>): void;
|
|
2274
|
+
}
|
|
2275
|
+
|
|
2276
|
+
/**
|
|
2277
|
+
* 插件错误分类
|
|
2278
|
+
*/
|
|
2279
|
+
declare enum PluginErrorType {
|
|
2280
|
+
/** 可恢复错误:网络波动、超时等,可以重试 */
|
|
2281
|
+
RECOVERABLE = "recoverable",
|
|
2282
|
+
/** 致命错误:语法错误、循环依赖等,无法通过重试恢复 */
|
|
2283
|
+
FATAL = "fatal",
|
|
2284
|
+
/** 配置错误:插件配置无效 */
|
|
2285
|
+
CONFIG = "config",
|
|
2286
|
+
/** 依赖错误:依赖插件不存在或版本不匹配 */
|
|
2287
|
+
DEPENDENCY = "dependency"
|
|
2288
|
+
}
|
|
2289
|
+
/**
|
|
2290
|
+
* 插件错误
|
|
2291
|
+
*/
|
|
2292
|
+
declare class PluginError extends Error {
|
|
2293
|
+
pluginId: string;
|
|
2294
|
+
type: PluginErrorType;
|
|
2295
|
+
originalError?: Error | undefined;
|
|
2296
|
+
retryCount: number;
|
|
2297
|
+
constructor(pluginId: string, type: PluginErrorType, message: string, originalError?: Error | undefined, retryCount?: number);
|
|
2298
|
+
}
|
|
2299
|
+
/**
|
|
2300
|
+
* 插件管理器
|
|
2301
|
+
* @description 核心领域服务,负责插件的完整生命周期管理,包括扫描、注册、配置合并、状态切换及依赖解析。
|
|
2302
|
+
*/
|
|
2303
|
+
declare class PluginManager {
|
|
2304
|
+
/** 全局事件总线,用于插件间及插件与内核间的异步通信 */
|
|
2305
|
+
readonly eventBus: DefaultEventBus;
|
|
2306
|
+
/** 存储管理服务,负责插件私有存储和系统级状态的持久化 */
|
|
2307
|
+
private storageManager;
|
|
2308
|
+
/** 插件 ID 到运行时实例的映射表 */
|
|
2309
|
+
private runtimes;
|
|
2310
|
+
/** 插件 ID 到原始插件定义对象的映射表 */
|
|
2311
|
+
private plugins;
|
|
2312
|
+
/** 收集到的所有插件路由配置 */
|
|
2313
|
+
private routes;
|
|
2314
|
+
/** 收集到的所有插件扩展点配置,按插槽位置分组 */
|
|
2315
|
+
private extensions;
|
|
2316
|
+
/** 插件的启用状态和排序信息的内存缓存 */
|
|
2317
|
+
private pluginStates;
|
|
2318
|
+
/** 扩展点缓存,避免重复计算 */
|
|
2319
|
+
private memoizedExtensions;
|
|
2320
|
+
/** 路由缓存 */
|
|
2321
|
+
private memoizedRoutes;
|
|
2322
|
+
/** 传递给插件的共享上下文缓存 */
|
|
2323
|
+
private sharedContext;
|
|
2324
|
+
/** 收集到的插件工具函数集合 */
|
|
2325
|
+
private utils;
|
|
2326
|
+
/** 插件强制启用标记(系统插件不可禁用) */
|
|
2327
|
+
private pluginForces;
|
|
2328
|
+
/** 插件懒加载标记 */
|
|
2329
|
+
private pluginLazyInit;
|
|
2330
|
+
/** 插件默认启用状态 */
|
|
2331
|
+
private pluginDefaultEnabled;
|
|
2332
|
+
/** 是否正在初始化插件中,防止重入导致多次加载 */
|
|
2333
|
+
private isInitializing;
|
|
1403
2334
|
/**
|
|
1404
|
-
*
|
|
1405
|
-
* @param
|
|
1406
|
-
* @param value - 待存储的字符串值
|
|
2335
|
+
* 构造函数
|
|
2336
|
+
* @param storage - 底层存储适配器
|
|
1407
2337
|
*/
|
|
1408
|
-
|
|
2338
|
+
constructor(storage: StoragePort);
|
|
1409
2339
|
/**
|
|
1410
|
-
*
|
|
1411
|
-
* @param key - 原始键名
|
|
2340
|
+
* 从持久化存储中恢复插件状态 (启用/禁用、排序等)
|
|
1412
2341
|
*/
|
|
1413
|
-
|
|
2342
|
+
private loadStates;
|
|
1414
2343
|
/**
|
|
1415
|
-
*
|
|
1416
|
-
* @description
|
|
1417
|
-
* - 若定义了前缀:仅删除以该前缀开头的键名,不影响其他数据。
|
|
1418
|
-
* - 若未定义前缀:调用原生 `localStorage.clear()` 清空所有数据。
|
|
2344
|
+
* 将当前的插件状态持久化到存储中
|
|
1419
2345
|
*/
|
|
1420
|
-
|
|
2346
|
+
private saveStates;
|
|
1421
2347
|
/**
|
|
1422
|
-
*
|
|
2348
|
+
* 订阅插件状态变更
|
|
2349
|
+
* @param listener 回调函数,当插件状态变更时被调用
|
|
2350
|
+
* @returns 取消订阅的函数
|
|
1423
2351
|
*/
|
|
1424
|
-
|
|
2352
|
+
subscribe(listener: () => void): () => void;
|
|
1425
2353
|
/**
|
|
1426
|
-
*
|
|
1427
|
-
* @param
|
|
1428
|
-
* @returns
|
|
2354
|
+
* 订阅路由变更
|
|
2355
|
+
* @param listener 回调函数,当路由变更时被调用
|
|
2356
|
+
* @returns 取消订阅的函数
|
|
1429
2357
|
*/
|
|
1430
|
-
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
/**
|
|
1434
|
-
* 作用域存储适配器 (ScopedStorageAdapter)
|
|
1435
|
-
* @description 采用装饰器模式实现。它包装一个现有的 `StoragePort` 实例,
|
|
1436
|
-
* 并为所有存储操作透明地注入一个前缀(命名空间),从而实现逻辑上的存储隔离。
|
|
1437
|
-
* 常用于为插件分配独立的存储空间,而无需修改插件代码。
|
|
1438
|
-
*/
|
|
1439
|
-
declare class ScopedStorageAdapter implements StoragePort {
|
|
1440
|
-
private underlyingStorage;
|
|
1441
|
-
private prefix;
|
|
2358
|
+
subscribeToRoutes(listener: () => void): () => void;
|
|
1442
2359
|
/**
|
|
1443
|
-
*
|
|
1444
|
-
* @
|
|
1445
|
-
* @param prefix - 用于隔离的作用域前缀字符串
|
|
2360
|
+
* 获取存储管理器实例
|
|
2361
|
+
* @returns StorageManager 实例
|
|
1446
2362
|
*/
|
|
1447
|
-
|
|
2363
|
+
getStorageManager(): StorageManager;
|
|
1448
2364
|
/**
|
|
1449
|
-
*
|
|
1450
|
-
* @param key - 业务层传入的原始键名
|
|
1451
|
-
* @returns 拼接前缀后的物理键名
|
|
2365
|
+
* 用于调度状态更新的函数,可由外部宿主环境(如 React)注入
|
|
1452
2366
|
*/
|
|
1453
|
-
private
|
|
2367
|
+
private stateUpdateScheduler;
|
|
1454
2368
|
/**
|
|
1455
|
-
*
|
|
1456
|
-
* @param namespacedKey - 物理存储中的完整键名
|
|
1457
|
-
* @returns 还原后的原始键名,若前缀不匹配则返回 null
|
|
2369
|
+
* 注入状态更新调度器
|
|
1458
2370
|
*/
|
|
1459
|
-
|
|
2371
|
+
setUpdateScheduler(scheduler: (callback: () => void) => void): void;
|
|
1460
2372
|
/**
|
|
1461
|
-
*
|
|
1462
|
-
* @
|
|
1463
|
-
* @
|
|
2373
|
+
* 触发状态变更通知
|
|
2374
|
+
* @description 统一使用 Zustand Store 进行状态管理,EventBus 仅用于一次性事件
|
|
2375
|
+
* @param affectedSlot - (可选) 受影响的插槽位置
|
|
1464
2376
|
*/
|
|
1465
|
-
|
|
2377
|
+
private notify;
|
|
1466
2378
|
/**
|
|
1467
|
-
*
|
|
1468
|
-
* @param
|
|
1469
|
-
* @param value - 字符串内容
|
|
2379
|
+
* 获取指定插件
|
|
2380
|
+
* @param pluginId 插件 ID
|
|
1470
2381
|
*/
|
|
1471
|
-
|
|
2382
|
+
getPlugin(pluginId: string): Plugin | undefined;
|
|
1472
2383
|
/**
|
|
1473
|
-
*
|
|
1474
|
-
* @param
|
|
2384
|
+
* 检查插件是否已注册
|
|
2385
|
+
* @param pluginId - 插件 ID
|
|
1475
2386
|
*/
|
|
1476
|
-
|
|
2387
|
+
hasPlugin(pluginId: string): boolean;
|
|
1477
2388
|
/**
|
|
1478
|
-
*
|
|
1479
|
-
* @
|
|
2389
|
+
* 获取指定插件的运行时实例
|
|
2390
|
+
* @param pluginId 插件 ID
|
|
2391
|
+
* @returns 插件运行时实例,如果不存在则返回 undefined
|
|
1480
2392
|
*/
|
|
1481
|
-
|
|
2393
|
+
getPluginRuntime(pluginId: string): PluginRuntime | undefined;
|
|
1482
2394
|
/**
|
|
1483
|
-
*
|
|
2395
|
+
* 激活插件
|
|
2396
|
+
* @param pluginId - 插件 ID
|
|
1484
2397
|
*/
|
|
1485
|
-
|
|
2398
|
+
activate(pluginId: string): Promise<void>;
|
|
1486
2399
|
/**
|
|
1487
|
-
*
|
|
1488
|
-
* @
|
|
1489
|
-
* @returns
|
|
1490
|
-
*/
|
|
1491
|
-
|
|
2400
|
+
* 获取所有已注册的插件列表
|
|
2401
|
+
* @description 结果会根据插件类型优先级和用户自定义排序进行排序
|
|
2402
|
+
* @returns 排序后的插件数组
|
|
2403
|
+
*/
|
|
2404
|
+
getPlugins(): Plugin[];
|
|
2405
|
+
/**
|
|
2406
|
+
* 获取指定插件的状态信息
|
|
2407
|
+
* @param pluginId - 插件 ID
|
|
2408
|
+
* @returns 包含启用状态和排序值的对象
|
|
2409
|
+
*/
|
|
2410
|
+
getPluginState(pluginId: string): {
|
|
2411
|
+
enabled: boolean;
|
|
2412
|
+
order: number;
|
|
2413
|
+
};
|
|
2414
|
+
/**
|
|
2415
|
+
* 检查指定插件是否处于启用状态
|
|
2416
|
+
* @param pluginId - 插件 ID
|
|
2417
|
+
* @returns 是否启用
|
|
2418
|
+
*/
|
|
2419
|
+
isPluginEnabled(pluginId: string): boolean;
|
|
2420
|
+
/**
|
|
2421
|
+
* 检查插件是否可禁用
|
|
2422
|
+
* @param pluginId - 插件 ID
|
|
2423
|
+
* @returns 是否可禁用
|
|
2424
|
+
*/
|
|
2425
|
+
canDisablePlugin(pluginId: string): boolean;
|
|
2426
|
+
/**
|
|
2427
|
+
* 检查插件是否应默认启用
|
|
2428
|
+
* @param pluginId - 插件 ID
|
|
2429
|
+
* @returns 是否默认启用
|
|
2430
|
+
*/
|
|
2431
|
+
shouldEnableByDefault(pluginId: string): boolean;
|
|
2432
|
+
/**
|
|
2433
|
+
* 切换插件的启用/禁用状态
|
|
2434
|
+
* @description 禁用插件会立即触发其卸载生命周期并销毁运行时。
|
|
2435
|
+
* @param pluginId - 插件 ID
|
|
2436
|
+
* @param enabled - 目标状态
|
|
2437
|
+
*/
|
|
2438
|
+
togglePlugin(pluginId: string, enabled: boolean): void;
|
|
2439
|
+
/**
|
|
2440
|
+
* 设置插件的显示排序权重
|
|
2441
|
+
* @param pluginId - 插件 ID
|
|
2442
|
+
* @param order - 排序权重值
|
|
2443
|
+
*/
|
|
2444
|
+
setPluginOrder(pluginId: string, order: number): void;
|
|
2445
|
+
/**
|
|
2446
|
+
* 获取指定插件的运行时状态
|
|
2447
|
+
* @param pluginId - 插件 ID
|
|
2448
|
+
* @returns 'error' | 'mounted' | 'loaded' | 'initial'
|
|
2449
|
+
*/
|
|
2450
|
+
getPluginRuntimeStatus(pluginId: string): "error" | "mounted" | "loaded" | "initial";
|
|
2451
|
+
/**
|
|
2452
|
+
* 获取指定插件的运行时错误
|
|
2453
|
+
* @param pluginId - 插件 ID
|
|
2454
|
+
* @returns Error 对象或 null
|
|
2455
|
+
*/
|
|
2456
|
+
getPluginError(pluginId: string): Error | null;
|
|
2457
|
+
/**
|
|
2458
|
+
* 报告插件运行时错误 (通常由 ErrorBoundary 调用)
|
|
2459
|
+
* @param pluginId - 插件 ID
|
|
2460
|
+
* @param error - 错误对象
|
|
2461
|
+
*/
|
|
2462
|
+
reportPluginError(pluginId: string, error: Error): void;
|
|
2463
|
+
/**
|
|
2464
|
+
* 获取插件的完整能力声明
|
|
2465
|
+
* @param pluginId - 插件 ID
|
|
2466
|
+
* @returns 能力对象
|
|
2467
|
+
*/
|
|
2468
|
+
getUnifiedCapabilities(pluginId: string): PluginCapabilities;
|
|
2469
|
+
/**
|
|
2470
|
+
* 更新指定插件的某项配置
|
|
2471
|
+
* @description 该操作会同步更新内存中的配置、持久化到存储并触发全局事件通知。
|
|
2472
|
+
* @param pluginId - 插件 ID
|
|
2473
|
+
* @param key - 配置键名
|
|
2474
|
+
* @param value - 新的配置值
|
|
2475
|
+
*/
|
|
2476
|
+
updatePluginConfig(pluginId: string, key: string, value: any): void;
|
|
2477
|
+
/**
|
|
2478
|
+
* 获取指定插件的某项配置值
|
|
2479
|
+
* @param pluginId - 插件 ID
|
|
2480
|
+
* @param key - 配置键名
|
|
2481
|
+
* @returns 配置值
|
|
2482
|
+
*/
|
|
2483
|
+
getPluginConfig(pluginId: string, key: string): any;
|
|
2484
|
+
/**
|
|
2485
|
+
* 获取系统全局配置 (非插件特定)
|
|
2486
|
+
* @param key - 系统配置键名
|
|
2487
|
+
* @returns 配置值
|
|
2488
|
+
*/
|
|
2489
|
+
getSystemConfig(key: string): any;
|
|
2490
|
+
/**
|
|
2491
|
+
* 获取由插件注册的服务实例
|
|
2492
|
+
* @template T 服务接口类型
|
|
2493
|
+
* @param name - 服务注册名称
|
|
2494
|
+
* @returns 服务实例或 undefined
|
|
2495
|
+
*/
|
|
2496
|
+
getService<T = any>(name: string): T | undefined;
|
|
2497
|
+
/**
|
|
2498
|
+
* 获取指定插槽位置的所有已启用插件的扩展
|
|
2499
|
+
* @param slot - 插槽位置标识
|
|
2500
|
+
* @returns 排序后的扩展配置数组
|
|
2501
|
+
*/
|
|
2502
|
+
getExtensions(slot: SlotPosition | string): PluginExtension[];
|
|
2503
|
+
/**
|
|
2504
|
+
* 获取所有已启用插件注册的路由配置
|
|
2505
|
+
* @returns 增强后的路由配置数组
|
|
2506
|
+
*/
|
|
2507
|
+
getRoutes(): RouteConfig[];
|
|
2508
|
+
/**
|
|
2509
|
+
* 注册一个新插件到管理器中
|
|
2510
|
+
* @description 此阶段会执行元数据校验、存储 Schema 注册、配置合并及扩展点收集。
|
|
2511
|
+
* @param plugin - 插件对象
|
|
2512
|
+
* @param notify - 是否在注册完成后触发状态变更通知
|
|
2513
|
+
*/
|
|
2514
|
+
register(plugin: Plugin, notify?: boolean): void;
|
|
2515
|
+
/**
|
|
2516
|
+
* 手动挂载指定插件(支持按需加载)
|
|
2517
|
+
* @description 如果插件依赖尚未挂载,会递归挂载所有依赖
|
|
2518
|
+
* @param pluginId 插件 ID
|
|
2519
|
+
*/
|
|
2520
|
+
mountPlugin(pluginId: string): Promise<void>;
|
|
2521
|
+
/**
|
|
2522
|
+
* 初始化所有插件
|
|
2523
|
+
* @param sharedContext 共享上下文
|
|
2524
|
+
* @param autoMount 是否自动挂载所有插件 (默认为 false,启用按需加载模式)
|
|
2525
|
+
*/
|
|
2526
|
+
initPlugins(sharedContext?: Record<string, any>, autoMount?: boolean): Promise<void>;
|
|
2527
|
+
/**
|
|
2528
|
+
* 带重试机制的插件加载
|
|
2529
|
+
*/
|
|
2530
|
+
private loadPluginWithRetry;
|
|
2531
|
+
/**
|
|
2532
|
+
* 带重试机制的插件挂载
|
|
2533
|
+
*/
|
|
2534
|
+
private mountPluginWithRetry;
|
|
2535
|
+
/**
|
|
2536
|
+
* 获取排序后的插件 ID 列表 (处理依赖)
|
|
2537
|
+
*/
|
|
2538
|
+
private getSortedPluginIds;
|
|
2539
|
+
/**
|
|
2540
|
+
* 加载插件列表
|
|
2541
|
+
* @param configs 插件配置
|
|
2542
|
+
* @param registry 插件注册表 (动态导入函数)
|
|
2543
|
+
* @param notify 是否在加载完成后触发通知,默认为 true
|
|
2544
|
+
*/
|
|
2545
|
+
loadPlugins(configs: Record<string, any>, registry: Record<string, () => Promise<any>>, notify?: boolean): Promise<void>;
|
|
2546
|
+
/**
|
|
2547
|
+
* 加载远程插件
|
|
2548
|
+
* @param pluginId 插件 ID
|
|
2549
|
+
* @param url 远程 URL
|
|
2550
|
+
* @param config 插件配置
|
|
2551
|
+
*/
|
|
2552
|
+
loadRemotePlugin(pluginId: string, url: string, config: any): Promise<Plugin | null>;
|
|
2553
|
+
/**
|
|
2554
|
+
* IIFE 模式加载插件
|
|
2555
|
+
*/
|
|
2556
|
+
private loadIIFEPlugin;
|
|
2557
|
+
/**
|
|
2558
|
+
* 实例化插件
|
|
2559
|
+
*/
|
|
2560
|
+
private instantiatePlugin;
|
|
2561
|
+
private validatePlugin;
|
|
2562
|
+
private handleBusinessPlugin;
|
|
2563
|
+
private handleFunctionalPlugin;
|
|
2564
|
+
private handleViewPlugin;
|
|
2565
|
+
private handleThemePlugin;
|
|
2566
|
+
private handleRendererPlugin;
|
|
2567
|
+
private handleSystemPlugin;
|
|
2568
|
+
/**
|
|
2569
|
+
* 注册插件默认配置
|
|
2570
|
+
*/
|
|
2571
|
+
private registerDefaultConfig;
|
|
2572
|
+
}
|
|
2573
|
+
/**
|
|
2574
|
+
* 全局插件管理器实例
|
|
2575
|
+
*/
|
|
2576
|
+
declare const pluginManager: PluginManager;
|
|
2577
|
+
|
|
2578
|
+
/**
|
|
2579
|
+
* 插件隔离沙箱
|
|
2580
|
+
* @description 核心领域服务,为每个插件实例创建独立的运行上下文。
|
|
2581
|
+
* 它是插件与系统核心之间的“中间层”,确保插件只能访问其权限范围内的资源。
|
|
2582
|
+
* 主要职责:
|
|
2583
|
+
* 1. 存储隔离:确保插件只能读写属于自己的 LocalStorage 命名空间。
|
|
2584
|
+
* 2. 日志隔离:为插件提供带有自身 ID 前缀的日志输出,方便调试。
|
|
2585
|
+
*/
|
|
2586
|
+
declare class PluginSandbox {
|
|
2587
|
+
/** 关联的插件唯一标识 */
|
|
2588
|
+
private pluginId;
|
|
2589
|
+
/** 系统全局存储管理器 */
|
|
2590
|
+
private storageManager;
|
|
2591
|
+
/**
|
|
2592
|
+
* 构造插件沙箱
|
|
2593
|
+
* @param pluginId - 插件 ID
|
|
2594
|
+
* @param storageManager - 系统存储管理器实例
|
|
2595
|
+
*/
|
|
2596
|
+
constructor(pluginId: string, storageManager: StorageManager);
|
|
2597
|
+
/**
|
|
2598
|
+
* 获取隔离的存储接口
|
|
2599
|
+
* @description 返回一个受限的 StoragePort,所有操作都会自动带上插件 ID 前缀。
|
|
2600
|
+
*/
|
|
2601
|
+
get storage(): {
|
|
2602
|
+
shared: {
|
|
2603
|
+
get: <T = any>(key: string) => T | null;
|
|
2604
|
+
set: <T = any>(key: string, value: T) => void;
|
|
2605
|
+
remove: (key: string) => void;
|
|
2606
|
+
};
|
|
2607
|
+
get: <T = any>(key: string) => T | null;
|
|
2608
|
+
set: <T = any>(key: string, value: T) => void;
|
|
2609
|
+
remove: (key: string) => void;
|
|
2610
|
+
};
|
|
2611
|
+
/**
|
|
2612
|
+
* 获取隔离的日志接口
|
|
2613
|
+
* @description 返回一个带插件 ID 前缀的 Logger 实例。
|
|
2614
|
+
*/
|
|
2615
|
+
get logger(): Logger;
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
/** 特性规则类型 */
|
|
2619
|
+
type RuleType = 'environment' | 'user' | 'percentage';
|
|
2620
|
+
/** 特性规则 */
|
|
2621
|
+
interface FeatureRule {
|
|
2622
|
+
type: RuleType;
|
|
2623
|
+
condition: string;
|
|
2624
|
+
value?: string | number;
|
|
2625
|
+
}
|
|
2626
|
+
/** 特性配置 */
|
|
2627
|
+
interface FeatureConfig {
|
|
2628
|
+
enabled: boolean;
|
|
2629
|
+
rules: FeatureRule[];
|
|
2630
|
+
namespace: string;
|
|
2631
|
+
description?: string;
|
|
2632
|
+
}
|
|
2633
|
+
/** 迁移警告 */
|
|
2634
|
+
interface MigrationWarning {
|
|
2635
|
+
pluginId: string;
|
|
2636
|
+
currentVersion: string;
|
|
2637
|
+
targetVersion: string;
|
|
2638
|
+
steps: string[];
|
|
2639
|
+
}
|
|
2640
|
+
/** 废弃信息 */
|
|
2641
|
+
interface DeprecationInfo {
|
|
2642
|
+
deprecatedIn: string;
|
|
2643
|
+
willRemoveIn: string;
|
|
2644
|
+
message: string;
|
|
2645
|
+
}
|
|
2646
|
+
/** 废弃警告 */
|
|
2647
|
+
interface DeprecationWarning {
|
|
2648
|
+
feature: string;
|
|
2649
|
+
info: DeprecationInfo;
|
|
2650
|
+
}
|
|
2651
|
+
declare const FEATURE_NAMESPACE_PREFIX = "chatbi:feature:";
|
|
2652
|
+
declare const STORAGE_KEY = "chatbi:feature:store";
|
|
2653
|
+
interface FeatureRegistryState {
|
|
2654
|
+
features: Record<string, FeatureConfig>;
|
|
2655
|
+
migrationPaths: Record<string, {
|
|
2656
|
+
toVersion: string;
|
|
2657
|
+
steps: string[];
|
|
2658
|
+
}>;
|
|
2659
|
+
deprecatedFeatures: Record<string, DeprecationInfo>;
|
|
2660
|
+
setFeature: (name: string, config: Partial<FeatureConfig>) => void;
|
|
2661
|
+
getFeature: (name: string) => FeatureConfig | undefined;
|
|
2662
|
+
removeFeature: (name: string) => void;
|
|
2663
|
+
isEnabled: (name: string, context?: {
|
|
2664
|
+
userId?: string;
|
|
2665
|
+
env?: string;
|
|
2666
|
+
}) => boolean;
|
|
2667
|
+
addMigrationPath: (fromVersion: string, toVersion: string, steps: string[]) => void;
|
|
2668
|
+
checkMigration: (plugins: PluginManifest[]) => MigrationWarning[];
|
|
2669
|
+
registerDeprecation: (feature: string, info: DeprecationInfo) => void;
|
|
2670
|
+
checkDeprecations: (features?: string[]) => DeprecationWarning[];
|
|
2671
|
+
}
|
|
2672
|
+
declare function simpleHash$1(str: string): number;
|
|
2673
|
+
declare function evaluateRules$1(rules: FeatureRule[], context: {
|
|
2674
|
+
userId?: string;
|
|
2675
|
+
env?: string;
|
|
2676
|
+
}): boolean;
|
|
2677
|
+
declare const useFeatureFlags: zustand.UseBoundStore<Omit<zustand.StoreApi<FeatureRegistryState>, "setState" | "persist"> & {
|
|
2678
|
+
setState(partial: FeatureRegistryState | Partial<FeatureRegistryState> | ((state: FeatureRegistryState) => FeatureRegistryState | Partial<FeatureRegistryState>), replace?: false | undefined): unknown;
|
|
2679
|
+
setState(state: FeatureRegistryState | ((state: FeatureRegistryState) => FeatureRegistryState), replace: true): unknown;
|
|
2680
|
+
persist: {
|
|
2681
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<FeatureRegistryState, unknown, unknown>>) => void;
|
|
2682
|
+
clearStorage: () => void;
|
|
2683
|
+
rehydrate: () => Promise<void> | void;
|
|
2684
|
+
hasHydrated: () => boolean;
|
|
2685
|
+
onHydrate: (fn: (state: FeatureRegistryState) => void) => () => void;
|
|
2686
|
+
onFinishHydration: (fn: (state: FeatureRegistryState) => void) => () => void;
|
|
2687
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<FeatureRegistryState, unknown, unknown>>;
|
|
2688
|
+
};
|
|
2689
|
+
}>;
|
|
2690
|
+
|
|
2691
|
+
/**
|
|
2692
|
+
* 规则引擎
|
|
2693
|
+
* @description 提供特性规则的评估能力,支持环境、用户和百分比规则
|
|
2694
|
+
*/
|
|
2695
|
+
|
|
2696
|
+
declare function simpleHash(str: string): number;
|
|
2697
|
+
/** 规则评估上下文 */
|
|
2698
|
+
interface RuleContext {
|
|
2699
|
+
userId?: string;
|
|
2700
|
+
env?: string;
|
|
2701
|
+
[key: string]: string | undefined;
|
|
2702
|
+
}
|
|
2703
|
+
/**
|
|
2704
|
+
* 评估规则列表
|
|
2705
|
+
* @param rules 规则数组
|
|
2706
|
+
* @param context 评估上下文
|
|
2707
|
+
* @returns 任意规则匹配返回 true,否则返回 false
|
|
2708
|
+
*/
|
|
2709
|
+
declare function evaluateRules(rules: FeatureRule[], context: RuleContext): boolean;
|
|
2710
|
+
/**
|
|
2711
|
+
* 评估单条规则
|
|
2712
|
+
* @param rule 规则
|
|
2713
|
+
* @param context 评估上下文
|
|
2714
|
+
* @returns 规则是否匹配
|
|
2715
|
+
*/
|
|
2716
|
+
declare function evaluateRule(rule: FeatureRule, context: RuleContext): boolean;
|
|
2717
|
+
/**
|
|
2718
|
+
* 创建百分比规则
|
|
2719
|
+
* @param percentage 百分比值 (0-100)
|
|
2720
|
+
* @returns 百分比规则
|
|
2721
|
+
*/
|
|
2722
|
+
declare function createPercentageRule(percentage: number): FeatureRule;
|
|
2723
|
+
/**
|
|
2724
|
+
* 创环境规则
|
|
2725
|
+
* @param env 环境名称
|
|
2726
|
+
* @returns 环境规则
|
|
2727
|
+
*/
|
|
2728
|
+
declare function createEnvironmentRule(env: string): FeatureRule;
|
|
2729
|
+
/**
|
|
2730
|
+
* 创建用户规则
|
|
2731
|
+
* @param userId 用户 ID
|
|
2732
|
+
* @returns 用户规则
|
|
2733
|
+
*/
|
|
2734
|
+
declare function createUserRule(userId: string): FeatureRule;
|
|
2735
|
+
|
|
2736
|
+
interface UseFeatureResult {
|
|
2737
|
+
isEnabled: boolean;
|
|
2738
|
+
config: FeatureConfig | undefined;
|
|
2739
|
+
}
|
|
2740
|
+
/**
|
|
2741
|
+
* 特性门控 Hook
|
|
2742
|
+
* @param flagName 特性名称
|
|
2743
|
+
* @param context 评估上下文
|
|
2744
|
+
* @returns 特性状态和配置
|
|
2745
|
+
*/
|
|
2746
|
+
declare function useFeature(flagName: string, context?: RuleContext): UseFeatureResult;
|
|
2747
|
+
|
|
2748
|
+
/**
|
|
2749
|
+
* 验证结果类型
|
|
2750
|
+
*/
|
|
2751
|
+
interface ValidationResult {
|
|
2752
|
+
/** 是否有效 */
|
|
2753
|
+
valid: boolean;
|
|
2754
|
+
/** 验证通过时的数据 */
|
|
2755
|
+
data?: PluginManifest;
|
|
2756
|
+
/** 验证失败时的错误 */
|
|
2757
|
+
errors?: {
|
|
2758
|
+
/** 错误消息 */
|
|
2759
|
+
message: string;
|
|
2760
|
+
/** 错误路径 */
|
|
2761
|
+
path: string[];
|
|
2762
|
+
/** 具体错误类型 */
|
|
2763
|
+
type: string;
|
|
2764
|
+
}[];
|
|
2765
|
+
}
|
|
2766
|
+
/**
|
|
2767
|
+
* 验证 Manifest
|
|
2768
|
+
* @param raw - 待验证的原始数据
|
|
2769
|
+
* @returns 验证结果
|
|
2770
|
+
*/
|
|
2771
|
+
declare function validateManifest(raw: unknown): ValidationResult;
|
|
2772
|
+
/**
|
|
2773
|
+
* 验证 Manifest 并抛出错误
|
|
2774
|
+
* @param raw - 待验证的原始数据
|
|
2775
|
+
* @returns 验证通过的 Manifest 数据
|
|
2776
|
+
* @throws ZodError 当验证失败时
|
|
2777
|
+
*/
|
|
2778
|
+
declare function assertManifest(raw: unknown): PluginManifest;
|
|
2779
|
+
|
|
2780
|
+
/**
|
|
2781
|
+
* Manifest 向后兼容包装器
|
|
2782
|
+
* @description 支持旧版 definePlugin 格式自动转换为 Manifest 格式
|
|
2783
|
+
*/
|
|
2784
|
+
|
|
2785
|
+
/**
|
|
2786
|
+
* 从 Plugin 对象提取 Manifest
|
|
2787
|
+
* @param plugin - 插件对象
|
|
2788
|
+
* @returns 提取的 Manifest 对象
|
|
2789
|
+
*/
|
|
2790
|
+
declare function extractManifestFromPlugin(plugin: Plugin | Record<string, unknown>): Partial<PluginManifest>;
|
|
2791
|
+
/**
|
|
2792
|
+
* 规范化插件 Manifest
|
|
2793
|
+
* @param input - Plugin 对象、definePlugin 结果或纯对象
|
|
2794
|
+
* @returns 规范化后的 Manifest
|
|
2795
|
+
* @throws 当输入无效且无法转换时
|
|
2796
|
+
*/
|
|
2797
|
+
declare function normalizePluginManifest(input: Plugin | Record<string, unknown> | unknown): ValidationResult;
|
|
2798
|
+
|
|
2799
|
+
/**
|
|
2800
|
+
* 核心状态 Store 接口
|
|
2801
|
+
*/
|
|
2802
|
+
interface CoreState {
|
|
2803
|
+
/** 插件列表变更版本号,用于触发插件管理器的列表更新 */
|
|
2804
|
+
pluginVersion: number;
|
|
2805
|
+
/** 扩展点变更版本号(按插槽),用于实现插槽级别的精确更新 */
|
|
2806
|
+
slotVersions: Record<string, number>;
|
|
2807
|
+
/** 路由变更版本号 */
|
|
2808
|
+
routeVersion: number;
|
|
2809
|
+
/** 触发全局插件列表更新 */
|
|
2810
|
+
notifyPluginsChanged: () => void;
|
|
2811
|
+
/** 触发特定插槽的更新 */
|
|
2812
|
+
notifySlotChanged: (slot: SlotPosition | string) => void;
|
|
2813
|
+
/** 触发路由配置更新 */
|
|
2814
|
+
notifyRoutesChanged: () => void;
|
|
2815
|
+
}
|
|
2816
|
+
/**
|
|
2817
|
+
* 创建 Vanilla Store 实例
|
|
2818
|
+
*/
|
|
2819
|
+
declare const coreStore: zustand.StoreApi<CoreState>;
|
|
2820
|
+
declare const coreStoreApi: zustand.StoreApi<CoreState>;
|
|
2821
|
+
|
|
2822
|
+
/**
|
|
2823
|
+
* 浏览器本地存储 (LocalStorage) 适配器
|
|
2824
|
+
* @description 实现 `StoragePort` 接口,封装了对原生 `localStorage` 的访问。
|
|
2825
|
+
* 支持可选的命名空间前缀隔离,确保在同一个域下不同模块的数据互不干扰。
|
|
2826
|
+
*/
|
|
2827
|
+
declare class LocalStorageAdapter implements StoragePort {
|
|
2828
|
+
/** 命名空间前缀,所有存入的键名都会自动添加此前缀 */
|
|
2829
|
+
private prefix;
|
|
2830
|
+
/**
|
|
2831
|
+
* 初始化适配器
|
|
2832
|
+
* @param prefix - 可选的命名空间前缀(如 'chatbi'),默认为空字符串
|
|
2833
|
+
*/
|
|
2834
|
+
constructor(prefix?: string);
|
|
2835
|
+
/**
|
|
2836
|
+
* 内部方法:计算实际存储的键名
|
|
2837
|
+
* @param key - 业务层传入的原始键名
|
|
2838
|
+
* @returns 拼接前缀后的物理键名
|
|
2839
|
+
*/
|
|
2840
|
+
private getKey;
|
|
2841
|
+
/**
|
|
2842
|
+
* 内部方法:从物理键名还原业务键名
|
|
2843
|
+
* @param namespacedKey - 物理存储中的完整键名
|
|
2844
|
+
* @returns 还原后的原始键名,若前缀不匹配则返回 null
|
|
2845
|
+
*/
|
|
2846
|
+
private getOriginalKey;
|
|
2847
|
+
/**
|
|
2848
|
+
* 读取存储项
|
|
2849
|
+
* @param key - 原始键名
|
|
2850
|
+
* @returns 存储的字符串内容,不存在则返回 null
|
|
2851
|
+
*/
|
|
2852
|
+
getItem(key: string): string | null;
|
|
2853
|
+
/**
|
|
2854
|
+
* 写入存储项
|
|
2855
|
+
* @param key - 原始键名
|
|
2856
|
+
* @param value - 待存储的字符串值
|
|
2857
|
+
*/
|
|
2858
|
+
setItem(key: string, value: string): void;
|
|
2859
|
+
/**
|
|
2860
|
+
* 移除特定的存储项
|
|
2861
|
+
* @param key - 原始键名
|
|
2862
|
+
*/
|
|
2863
|
+
removeItem(key: string): void;
|
|
2864
|
+
/**
|
|
2865
|
+
* 清空存储空间
|
|
2866
|
+
* @description
|
|
2867
|
+
* - 若定义了前缀:仅删除以该前缀开头的键名,不影响其他数据。
|
|
2868
|
+
* - 若未定义前缀:调用原生 `localStorage.clear()` 清空所有数据。
|
|
2869
|
+
*/
|
|
2870
|
+
clear(): void;
|
|
2871
|
+
/**
|
|
2872
|
+
* 返回当前命名空间下的存储项总数
|
|
2873
|
+
*/
|
|
2874
|
+
get length(): number;
|
|
2875
|
+
/**
|
|
2876
|
+
* 根据索引获取对应的原始键名
|
|
2877
|
+
* @param index - 索引位置
|
|
2878
|
+
* @returns 对应的业务键名,不存在则返回 null
|
|
2879
|
+
*/
|
|
2880
|
+
key(index: number): string | null;
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
/**
|
|
2884
|
+
* 作用域存储适配器 (ScopedStorageAdapter)
|
|
2885
|
+
* @description 采用装饰器模式实现。它包装一个现有的 `StoragePort` 实例,
|
|
2886
|
+
* 并为所有存储操作透明地注入一个前缀(命名空间),从而实现逻辑上的存储隔离。
|
|
2887
|
+
* 常用于为插件分配独立的存储空间,而无需修改插件代码。
|
|
2888
|
+
*/
|
|
2889
|
+
declare class ScopedStorageAdapter implements StoragePort {
|
|
2890
|
+
private underlyingStorage;
|
|
2891
|
+
private prefix;
|
|
2892
|
+
/**
|
|
2893
|
+
* 初始化作用域适配器
|
|
2894
|
+
* @param underlyingStorage - 被装饰的底层存储适配器实例
|
|
2895
|
+
* @param prefix - 用于隔离的作用域前缀字符串
|
|
2896
|
+
*/
|
|
2897
|
+
constructor(underlyingStorage: StoragePort, prefix: string);
|
|
2898
|
+
/**
|
|
2899
|
+
* 内部方法:计算实际存储的键名
|
|
2900
|
+
* @param key - 业务层传入的原始键名
|
|
2901
|
+
* @returns 拼接前缀后的物理键名
|
|
2902
|
+
*/
|
|
2903
|
+
private getKey;
|
|
2904
|
+
/**
|
|
2905
|
+
* 内部方法:从物理键名还原业务键名
|
|
2906
|
+
* @param namespacedKey - 物理存储中的完整键名
|
|
2907
|
+
* @returns 还原后的原始键名,若前缀不匹配则返回 null
|
|
2908
|
+
*/
|
|
2909
|
+
private getOriginalKey;
|
|
2910
|
+
/**
|
|
2911
|
+
* 读取当前作用域下的存储项
|
|
2912
|
+
* @param key - 原始键名
|
|
2913
|
+
* @returns 字符串内容,不存在则返回 null
|
|
2914
|
+
*/
|
|
2915
|
+
getItem(key: string): string | null;
|
|
2916
|
+
/**
|
|
2917
|
+
* 写入当前作用域下的存储项
|
|
2918
|
+
* @param key - 原始键名
|
|
2919
|
+
* @param value - 字符串内容
|
|
2920
|
+
*/
|
|
2921
|
+
setItem(key: string, value: string): void;
|
|
2922
|
+
/**
|
|
2923
|
+
* 移除当前作用域下的特定存储项
|
|
2924
|
+
* @param key - 原始键名
|
|
2925
|
+
*/
|
|
2926
|
+
removeItem(key: string): void;
|
|
2927
|
+
/**
|
|
2928
|
+
* 清空当前作用域下的所有存储项
|
|
2929
|
+
* @description 仅删除匹配当前前缀的键值对,不会影响底层存储中的其他数据。
|
|
2930
|
+
*/
|
|
2931
|
+
clear(): void;
|
|
2932
|
+
/**
|
|
2933
|
+
* 返回当前作用域下的存储项总数
|
|
2934
|
+
*/
|
|
2935
|
+
get length(): number;
|
|
2936
|
+
/**
|
|
2937
|
+
* 根据索引获取当前作用域下的原始键名
|
|
2938
|
+
* @param index - 索引位置
|
|
2939
|
+
* @returns 对应的业务键名,不存在则返回 null
|
|
2940
|
+
*/
|
|
2941
|
+
key(index: number): string | null;
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2944
|
+
/**
|
|
2945
|
+
* 基于 Axios 的默认请求适配器
|
|
2946
|
+
*/
|
|
2947
|
+
declare class AxiosAdapter implements ApiAdapter {
|
|
2948
|
+
private client;
|
|
2949
|
+
constructor(baseURL?: string, timeout?: number);
|
|
2950
|
+
request<T = any>(config: ApiRequestConfig): Promise<T>;
|
|
2951
|
+
stream(config: ApiRequestConfig, callbacks: StreamCallbacks, _endpointConfig?: ApiEndpointConfig): Promise<void>;
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
/**
|
|
2955
|
+
* API 引擎核心类
|
|
2956
|
+
* @description 负责加载配置并执行请求,支持策略模式切换底层请求实现
|
|
2957
|
+
*/
|
|
2958
|
+
declare class ApiEngine {
|
|
2959
|
+
private adapter;
|
|
2960
|
+
private config;
|
|
2961
|
+
private interceptors;
|
|
2962
|
+
/** 可配置的成功码 */
|
|
2963
|
+
private successCodes;
|
|
2964
|
+
constructor(adapter?: ApiAdapter);
|
|
2965
|
+
/**
|
|
2966
|
+
* 注册拦截器
|
|
2967
|
+
*/
|
|
2968
|
+
registerInterceptor(interceptor: ApiInterceptor): void;
|
|
2969
|
+
/**
|
|
2970
|
+
* 移除拦截器
|
|
2971
|
+
*/
|
|
2972
|
+
unregisterInterceptor(interceptor: ApiInterceptor): void;
|
|
2973
|
+
/**
|
|
2974
|
+
* 设置成功码
|
|
2975
|
+
*/
|
|
2976
|
+
setSuccessCodes(codes: string[]): void;
|
|
2977
|
+
/**
|
|
2978
|
+
* 切换请求适配器
|
|
2979
|
+
* @param adapter 新的适配器实例
|
|
2980
|
+
*/
|
|
2981
|
+
useAdapter(adapter: ApiAdapter): void;
|
|
2982
|
+
/**
|
|
2983
|
+
* 注册 API 配置
|
|
2984
|
+
* @param config 配置对象
|
|
2985
|
+
*/
|
|
2986
|
+
register(config: ApiConfig): void;
|
|
2987
|
+
/**
|
|
2988
|
+
* 获取接口配置
|
|
2989
|
+
*/
|
|
2990
|
+
getEndpoint(module: string, action: string): ApiEndpointConfig | undefined;
|
|
2991
|
+
/**
|
|
2992
|
+
* 发起 API 请求
|
|
2993
|
+
* @param module 模块名
|
|
2994
|
+
* @param action 动作名
|
|
2995
|
+
* @param data 请求数据 (Body 或 Query)
|
|
2996
|
+
* @param options 请求选项
|
|
2997
|
+
*/
|
|
2998
|
+
call<T = any>(module: string, action: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
2999
|
+
/**
|
|
3000
|
+
* 发起流式请求
|
|
3001
|
+
* @param module 模块名
|
|
3002
|
+
* @param action 动作名
|
|
3003
|
+
* @param data 请求数据
|
|
3004
|
+
* @param options 请求选项
|
|
3005
|
+
*/
|
|
3006
|
+
stream(module: string, action: string, data?: any, options?: RequestOptions): Promise<void>;
|
|
3007
|
+
/**
|
|
3008
|
+
* 准备请求配置,应用 URL 参数替换和请求拦截器
|
|
3009
|
+
*/
|
|
3010
|
+
private prepareRequestConfig;
|
|
3011
|
+
/**
|
|
3012
|
+
* 应用所有请求拦截器
|
|
3013
|
+
*/
|
|
3014
|
+
private applyRequestInterceptors;
|
|
3015
|
+
/**
|
|
3016
|
+
* 应用所有响应拦截器
|
|
3017
|
+
* @returns 是否被劫持
|
|
3018
|
+
*/
|
|
3019
|
+
private applyResponseInterceptors;
|
|
3020
|
+
/**
|
|
3021
|
+
* 检查 HTTP 状态码
|
|
3022
|
+
*/
|
|
3023
|
+
private checkHttpStatus;
|
|
3024
|
+
/**
|
|
3025
|
+
* 提取响应数据
|
|
3026
|
+
*/
|
|
3027
|
+
private extractResponseData;
|
|
3028
|
+
/**
|
|
3029
|
+
* 处理业务错误
|
|
3030
|
+
*/
|
|
3031
|
+
private handleBusinessError;
|
|
3032
|
+
/**
|
|
3033
|
+
* 检查响应是否成功
|
|
3034
|
+
*/
|
|
3035
|
+
protected isSuccess(response: any): boolean;
|
|
3036
|
+
/**
|
|
3037
|
+
* 处理响应错误
|
|
3038
|
+
*/
|
|
3039
|
+
protected handleResponseError(response: any, context: any): void;
|
|
3040
|
+
/**
|
|
3041
|
+
* 判断是否为 BaseResponse
|
|
3042
|
+
*/
|
|
3043
|
+
private isBaseResponse;
|
|
3044
|
+
/**
|
|
3045
|
+
* 严格判断是否为 AxiosResponse
|
|
3046
|
+
*/
|
|
3047
|
+
private isAxiosResponse;
|
|
3048
|
+
/**
|
|
3049
|
+
* 创建拦截上下文
|
|
3050
|
+
*/
|
|
3051
|
+
private createInterceptorContext;
|
|
3052
|
+
}
|
|
3053
|
+
declare const apiEngine: ApiEngine;
|
|
3054
|
+
|
|
3055
|
+
/**
|
|
3056
|
+
* 自动检测是否处于 Mock 模式
|
|
3057
|
+
*/
|
|
3058
|
+
declare function isMockMode(): boolean;
|
|
3059
|
+
/**
|
|
3060
|
+
* 从文件模块映射中解析 API 配置
|
|
3061
|
+
* @description 配合 Vite 的 import.meta.glob 使用,自动匹配定义文件和 Mock 文件
|
|
3062
|
+
* @param definitionsMap API 定义文件映射 (import.meta.glob('./modules/*.ts', { eager: true }))
|
|
3063
|
+
* @param mocksMap Mock 文件映射 (import.meta.glob('./modules/*.mock.ts', { eager: true }))
|
|
3064
|
+
* @param useMock 是否启用 Mock (如果不传,将自动调用 isMockMode())
|
|
3065
|
+
* @returns 合并后的 ApiConfig
|
|
3066
|
+
*/
|
|
3067
|
+
declare function resolveApiModules(definitionsMap: Record<string, any>, mocksMap?: Record<string, any>): ApiConfig;
|
|
3068
|
+
|
|
3069
|
+
/**
|
|
3070
|
+
* 沙箱选项
|
|
3071
|
+
*/
|
|
3072
|
+
interface SandboxOptions {
|
|
3073
|
+
/** 严格模式:启用所有安全限制 */
|
|
3074
|
+
strict?: boolean;
|
|
3075
|
+
/** 自定义白名单 */
|
|
3076
|
+
customWhitelist?: Record<string, boolean>;
|
|
3077
|
+
/** 是否允许 DOM 访问 */
|
|
3078
|
+
allowDOM?: boolean;
|
|
3079
|
+
/** 是否允许网络请求 */
|
|
3080
|
+
allowNetwork?: boolean;
|
|
3081
|
+
}
|
|
3082
|
+
/**
|
|
3083
|
+
* ProxySandbox 类
|
|
3084
|
+
* @description 基于 Proxy 的 JS 沙箱实现,模拟独立的 Window 环境
|
|
3085
|
+
*/
|
|
3086
|
+
declare class ProxySandbox {
|
|
3087
|
+
/** 沙箱名称 */
|
|
3088
|
+
name: string;
|
|
3089
|
+
/** 代理后的 Window 对象 */
|
|
3090
|
+
proxy: WindowProxy;
|
|
3091
|
+
/** 沙箱是否激活 */
|
|
3092
|
+
running: boolean;
|
|
3093
|
+
/** 沙箱选项 */
|
|
3094
|
+
private options;
|
|
3095
|
+
/** 记录新增/修改的全局变量 */
|
|
3096
|
+
private updatedValueSet;
|
|
3097
|
+
/** 绑定函数的缓存池,避免重复 bind 带来的性能开销 */
|
|
3098
|
+
private boundFunctionCache;
|
|
3099
|
+
/** 副作用记录池 */
|
|
3100
|
+
private effectPool;
|
|
3101
|
+
/** 真实的 Window 对象 */
|
|
3102
|
+
private globalContext;
|
|
3103
|
+
/** 白名单全局变量(允许透传访问真实 Window) */
|
|
3104
|
+
private static globalWhitelist;
|
|
3105
|
+
constructor(name: string, options?: SandboxOptions, globalContext?: Window & typeof globalThis);
|
|
3106
|
+
/**
|
|
3107
|
+
* 激活沙箱
|
|
3108
|
+
*/
|
|
3109
|
+
active(): void;
|
|
3110
|
+
/**
|
|
3111
|
+
* 销毁沙箱
|
|
3112
|
+
*/
|
|
3113
|
+
inactive(): void;
|
|
3114
|
+
/**
|
|
3115
|
+
* 获取缓存的绑定函数,避免重复 bind
|
|
3116
|
+
*/
|
|
3117
|
+
getBoundFunction(fn: Function, context: Window): Function;
|
|
3118
|
+
/**
|
|
3119
|
+
* 获取当前缓存大小(用于监控和调试)
|
|
3120
|
+
*/
|
|
3121
|
+
getCacheSize(): number;
|
|
3122
|
+
/**
|
|
3123
|
+
* 在沙箱中执行代码
|
|
3124
|
+
* @param code JS 代码字符串
|
|
3125
|
+
* @param options 执行选项
|
|
3126
|
+
* @returns 执行结果
|
|
3127
|
+
* @description 使用 IIFE 模式执行代码,替代已废弃的 with 语句
|
|
3128
|
+
*/
|
|
3129
|
+
eval(code: string, options?: {
|
|
3130
|
+
useStrict?: boolean;
|
|
3131
|
+
}): any;
|
|
3132
|
+
/**
|
|
3133
|
+
* 创建伪造的 Window 对象
|
|
3134
|
+
*/
|
|
3135
|
+
private createFakeWindow;
|
|
3136
|
+
private isConstructor;
|
|
3137
|
+
private isNativeFunction;
|
|
3138
|
+
/**
|
|
3139
|
+
* 劫持全局副作用 API
|
|
3140
|
+
*/
|
|
3141
|
+
private patchGlobalEffects;
|
|
3142
|
+
}
|
|
3143
|
+
|
|
3144
|
+
/**
|
|
3145
|
+
* 日期时间格式化工具类
|
|
3146
|
+
*/
|
|
3147
|
+
declare const dateUtils: {
|
|
3148
|
+
/**
|
|
3149
|
+
* 格式化日期为 YYYY-MM-DD
|
|
3150
|
+
*/
|
|
3151
|
+
formatDate(date?: dayjs.ConfigType): string;
|
|
3152
|
+
/**
|
|
3153
|
+
* 格式化时间为 HH:mm:ss
|
|
3154
|
+
*/
|
|
3155
|
+
formatTime(date?: dayjs.ConfigType): string;
|
|
3156
|
+
/**
|
|
3157
|
+
* 格式化日期时间为 YYYY-MM-DD HH:mm:ss
|
|
3158
|
+
*/
|
|
3159
|
+
formatDateTime(date?: dayjs.ConfigType): string;
|
|
3160
|
+
/**
|
|
3161
|
+
* 获取当前时间戳(毫秒)
|
|
3162
|
+
*/
|
|
3163
|
+
now(): number;
|
|
3164
|
+
/**
|
|
3165
|
+
* 获取相对时间(例如:几分钟前)
|
|
3166
|
+
*/
|
|
3167
|
+
fromNow(date: dayjs.ConfigType): string;
|
|
3168
|
+
/**
|
|
3169
|
+
* 原始 dayjs 对象,用于更复杂的场景
|
|
3170
|
+
*/
|
|
3171
|
+
dayjs: typeof dayjs;
|
|
3172
|
+
};
|
|
3173
|
+
|
|
3174
|
+
type KeepStrategy = 'first' | 'last' | 'search' | 'hash';
|
|
3175
|
+
/**
|
|
3176
|
+
* 把当前地址中所有出现的参数合并成一份。
|
|
3177
|
+
* 重复 key 的处理策略:
|
|
3178
|
+
* - 'first' : 按出现顺序,第一次的值生效
|
|
3179
|
+
* - 'last' : 按出现顺序,最后一次的值生效(默认,最直观)
|
|
3180
|
+
* - 'search' : 只要 search 里出现过,就用 search 的
|
|
3181
|
+
* - 'hash' : 只要 hash 里出现过,就用 hash 的
|
|
3182
|
+
*/
|
|
3183
|
+
declare function normalizeParams(strategy?: KeepStrategy): URLSearchParams;
|
|
3184
|
+
/**
|
|
3185
|
+
* 清除 URL 中的特定参数并返回新的 URL
|
|
3186
|
+
* @description 同时处理 search 和 hash 中的参数
|
|
3187
|
+
*/
|
|
3188
|
+
declare function cleanUrlParams(keysToRemove: string[]): string;
|
|
3189
|
+
|
|
3190
|
+
declare const version = "1.0.0";
|
|
3191
|
+
|
|
3192
|
+
/**
|
|
3193
|
+
* Remote Plugin Source 类型定义
|
|
3194
|
+
* @description 定义远程插件源接口和配置选项
|
|
3195
|
+
*/
|
|
3196
|
+
/**
|
|
3197
|
+
* 远程插件源
|
|
3198
|
+
* @description 表示一个远程插件仓库地址
|
|
3199
|
+
*/
|
|
3200
|
+
interface RemotePluginSource {
|
|
3201
|
+
/** 唯一标识符 */
|
|
3202
|
+
id: string;
|
|
3203
|
+
/** 显示名称 */
|
|
3204
|
+
name: string;
|
|
3205
|
+
/** plugin.json URL */
|
|
3206
|
+
url: string;
|
|
3207
|
+
/** 是否启用 */
|
|
3208
|
+
enabled?: boolean;
|
|
3209
|
+
}
|
|
3210
|
+
/**
|
|
3211
|
+
* 缓存配置选项
|
|
3212
|
+
*/
|
|
3213
|
+
interface CacheOptions {
|
|
3214
|
+
/** 缓存 TTL (毫秒),默认 5 分钟 */
|
|
3215
|
+
ttl: number;
|
|
3216
|
+
/** 最大缓存条目数 */
|
|
3217
|
+
maxSize?: number;
|
|
1492
3218
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
3219
|
+
/**
|
|
3220
|
+
* 重试配置选项
|
|
3221
|
+
*/
|
|
3222
|
+
interface RetryOptions {
|
|
3223
|
+
/** 最大重试次数 */
|
|
3224
|
+
maxRetries: number;
|
|
3225
|
+
/** 重试延迟 (毫秒) */
|
|
3226
|
+
retryDelay: number;
|
|
3227
|
+
/** 自定义重试条件 */
|
|
3228
|
+
retryCondition?: (error: any) => boolean;
|
|
3229
|
+
}
|
|
3230
|
+
/**
|
|
3231
|
+
* 远程源配置选项
|
|
3232
|
+
*/
|
|
3233
|
+
interface RemoteSourceOptions {
|
|
3234
|
+
/** 请求超时 (毫秒) */
|
|
3235
|
+
timeout?: number;
|
|
3236
|
+
/** 重试配置 */
|
|
3237
|
+
retry?: RetryOptions;
|
|
3238
|
+
/** 缓存配置 */
|
|
3239
|
+
cache?: CacheOptions;
|
|
3240
|
+
}
|
|
3241
|
+
/**
|
|
3242
|
+
* 缓存条目元数据
|
|
3243
|
+
*/
|
|
3244
|
+
interface CacheEntry<T = any> {
|
|
3245
|
+
/** 缓存数据 */
|
|
3246
|
+
data: T;
|
|
3247
|
+
/** 创建时间戳 */
|
|
3248
|
+
createdAt: number;
|
|
3249
|
+
/** 最后访问时间戳 */
|
|
3250
|
+
lastAccessedAt: number;
|
|
3251
|
+
/** 过期时间戳 */
|
|
3252
|
+
expiresAt: number;
|
|
3253
|
+
}
|
|
3254
|
+
/**
|
|
3255
|
+
* 加载结果
|
|
3256
|
+
*/
|
|
3257
|
+
interface LoadResult<T = any> {
|
|
3258
|
+
/** 是否成功 */
|
|
3259
|
+
success: boolean;
|
|
3260
|
+
/** 加载的数据 */
|
|
3261
|
+
data?: T;
|
|
3262
|
+
/** 加载错误 */
|
|
3263
|
+
error?: LoadError;
|
|
3264
|
+
/** 是否来自缓存 */
|
|
3265
|
+
fromCache?: boolean;
|
|
3266
|
+
}
|
|
3267
|
+
/**
|
|
3268
|
+
* 加载错误
|
|
3269
|
+
*/
|
|
3270
|
+
interface LoadError {
|
|
3271
|
+
/** 错误代码 */
|
|
3272
|
+
code: 'NETWORK' | 'TIMEOUT' | 'PARSE' | 'NOT_FOUND' | 'CACHE_ERROR' | 'VALIDATION_ERROR';
|
|
3273
|
+
/** 错误消息 */
|
|
3274
|
+
message: string;
|
|
3275
|
+
/** 是否可重试 */
|
|
3276
|
+
retryable: boolean;
|
|
3277
|
+
/** 原始错误 */
|
|
3278
|
+
originalError?: any;
|
|
1497
3279
|
}
|
|
1498
|
-
declare const PluginProvider: React.FC<PluginProviderProps>;
|
|
1499
|
-
declare const usePluginManager: () => PluginManager;
|
|
1500
3280
|
|
|
1501
3281
|
/**
|
|
1502
|
-
*
|
|
1503
|
-
* @description
|
|
3282
|
+
* 远程缓存管理器
|
|
3283
|
+
* @description 管理远程插件Manifest的缓存,支持TTL和大小限制
|
|
1504
3284
|
*/
|
|
1505
|
-
declare class
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
/** 代理后的 Window 对象 */
|
|
1509
|
-
proxy: WindowProxy;
|
|
1510
|
-
/** 沙箱是否激活 */
|
|
1511
|
-
running: boolean;
|
|
1512
|
-
/** 记录新增/修改的全局变量 */
|
|
1513
|
-
private updatedValueSet;
|
|
1514
|
-
/** 绑定函数的缓存池,避免重复 bind 带来的性能开销 */
|
|
1515
|
-
private boundFunctionCache;
|
|
1516
|
-
/** 副作用记录池 */
|
|
1517
|
-
private effectPool;
|
|
1518
|
-
/** 真实的 Window 对象 */
|
|
1519
|
-
private globalContext;
|
|
1520
|
-
/** 白名单全局变量(允许透传访问真实 Window) */
|
|
1521
|
-
private static globalWhitelist;
|
|
1522
|
-
constructor(name: string, globalContext?: Window & typeof globalThis);
|
|
3285
|
+
declare class RemoteCache<T = any> {
|
|
3286
|
+
private cache;
|
|
3287
|
+
private defaultTtl;
|
|
1523
3288
|
/**
|
|
1524
|
-
*
|
|
3289
|
+
* 创建远程缓存管理器
|
|
3290
|
+
* @param options 缓存配置选项
|
|
1525
3291
|
*/
|
|
1526
|
-
|
|
3292
|
+
constructor(options?: CacheOptions);
|
|
1527
3293
|
/**
|
|
1528
|
-
*
|
|
3294
|
+
* 获取缓存条目
|
|
3295
|
+
* @param key 缓存键
|
|
3296
|
+
* @returns 缓存条目,如果不存在或已过期返回 undefined
|
|
1529
3297
|
*/
|
|
1530
|
-
|
|
3298
|
+
get(key: string): CacheEntry<T> | undefined;
|
|
1531
3299
|
/**
|
|
1532
|
-
*
|
|
1533
|
-
* @param
|
|
1534
|
-
* @
|
|
3300
|
+
* 设置缓存条目
|
|
3301
|
+
* @param key 缓存键
|
|
3302
|
+
* @param data 要缓存的数据
|
|
3303
|
+
* @param ttl 自定义 TTL (毫秒),使用默认 TTL 如果未指定
|
|
1535
3304
|
*/
|
|
1536
|
-
|
|
3305
|
+
set(key: string, data: T, ttl?: number): void;
|
|
1537
3306
|
/**
|
|
1538
|
-
*
|
|
3307
|
+
* 删除缓存条目
|
|
3308
|
+
* @param key 缓存键
|
|
3309
|
+
* @returns 是否成功删除
|
|
1539
3310
|
*/
|
|
1540
|
-
|
|
1541
|
-
private isConstructor;
|
|
1542
|
-
private isNativeFunction;
|
|
3311
|
+
delete(key: string): boolean;
|
|
1543
3312
|
/**
|
|
1544
|
-
*
|
|
3313
|
+
* 清空所有缓存
|
|
1545
3314
|
*/
|
|
1546
|
-
|
|
3315
|
+
clear(): void;
|
|
3316
|
+
/**
|
|
3317
|
+
* 检查缓存键是否存在
|
|
3318
|
+
* @param key 缓存键
|
|
3319
|
+
*/
|
|
3320
|
+
has(key: string): boolean;
|
|
3321
|
+
/**
|
|
3322
|
+
* 获取缓存条目数量
|
|
3323
|
+
*/
|
|
3324
|
+
size(): number;
|
|
3325
|
+
/**
|
|
3326
|
+
* 获取缓存条目的元数据(不触发访问时间更新)
|
|
3327
|
+
* @param key 缓存键
|
|
3328
|
+
*/
|
|
3329
|
+
getMetadata(key: string): CacheEntry<T> | undefined;
|
|
3330
|
+
/**
|
|
3331
|
+
* 更新缓存 TTL
|
|
3332
|
+
* @param key 缓存键
|
|
3333
|
+
* @param ttl 新 TTL (毫秒)
|
|
3334
|
+
*/
|
|
3335
|
+
updateTTL(key: string, ttl: number): boolean;
|
|
1547
3336
|
}
|
|
1548
3337
|
|
|
1549
3338
|
/**
|
|
1550
|
-
*
|
|
3339
|
+
* 远程插件加载器
|
|
3340
|
+
* @description 管理远程插件源的添加、移除和 Manifest 加载
|
|
1551
3341
|
*/
|
|
1552
|
-
declare
|
|
3342
|
+
declare class RemoteLoader {
|
|
3343
|
+
private sources;
|
|
3344
|
+
private cache;
|
|
3345
|
+
private retryStrategy;
|
|
3346
|
+
private options;
|
|
1553
3347
|
/**
|
|
1554
|
-
*
|
|
3348
|
+
* 创建远程加载器
|
|
3349
|
+
* @param options 远程源配置选项
|
|
1555
3350
|
*/
|
|
1556
|
-
|
|
3351
|
+
constructor(options?: RemoteSourceOptions);
|
|
1557
3352
|
/**
|
|
1558
|
-
*
|
|
3353
|
+
* 添加远程插件源
|
|
3354
|
+
* @param source 远程插件源
|
|
1559
3355
|
*/
|
|
1560
|
-
|
|
3356
|
+
addSource(source: RemotePluginSource): void;
|
|
1561
3357
|
/**
|
|
1562
|
-
*
|
|
3358
|
+
* 移除远程插件源
|
|
3359
|
+
* @param sourceId 插件源 ID
|
|
3360
|
+
* @returns 是否成功移除
|
|
1563
3361
|
*/
|
|
1564
|
-
|
|
3362
|
+
removeSource(sourceId: string): boolean;
|
|
1565
3363
|
/**
|
|
1566
|
-
*
|
|
3364
|
+
* 获取所有远程插件源
|
|
3365
|
+
* @returns 远程插件源列表
|
|
1567
3366
|
*/
|
|
1568
|
-
|
|
3367
|
+
getSources(): RemotePluginSource[];
|
|
1569
3368
|
/**
|
|
1570
|
-
*
|
|
3369
|
+
* 获取指定远程插件源
|
|
3370
|
+
* @param sourceId 插件源 ID
|
|
1571
3371
|
*/
|
|
1572
|
-
|
|
3372
|
+
getSource(sourceId: string): RemotePluginSource | undefined;
|
|
1573
3373
|
/**
|
|
1574
|
-
*
|
|
3374
|
+
* 启用/禁用远程插件源
|
|
3375
|
+
* @param sourceId 插件源 ID
|
|
3376
|
+
* @param enabled 是否启用
|
|
1575
3377
|
*/
|
|
1576
|
-
|
|
1577
|
-
|
|
3378
|
+
setSourceEnabled(sourceId: string, enabled: boolean): boolean;
|
|
3379
|
+
/**
|
|
3380
|
+
* 从远程加载插件 Manifest
|
|
3381
|
+
* @param sourceId 插件源 ID
|
|
3382
|
+
* @returns 加载结果
|
|
3383
|
+
*/
|
|
3384
|
+
loadManifest<T = PluginManifest>(sourceId: string): Promise<LoadResult<T>>;
|
|
3385
|
+
/**
|
|
3386
|
+
* 带重试的请求
|
|
3387
|
+
* @param url 请求 URL
|
|
3388
|
+
* @param attempt 当前尝试次数
|
|
3389
|
+
* @returns 响应数据
|
|
3390
|
+
*/
|
|
3391
|
+
private fetchWithRetry;
|
|
3392
|
+
/**
|
|
3393
|
+
* 处理加载错误
|
|
3394
|
+
* @param error 错误对象
|
|
3395
|
+
* @returns 错误结果
|
|
3396
|
+
*/
|
|
3397
|
+
private handleLoadError;
|
|
3398
|
+
/**
|
|
3399
|
+
* 创建错误结果
|
|
3400
|
+
* @param code 错误代码
|
|
3401
|
+
* @param message 错误消息
|
|
3402
|
+
* @param retryable 是否可重试
|
|
3403
|
+
* @returns 错误结果
|
|
3404
|
+
*/
|
|
3405
|
+
private createErrorResult;
|
|
3406
|
+
/**
|
|
3407
|
+
* 清除缓存
|
|
3408
|
+
* @param sourceId 可选,指定源 ID(只清除该源的缓存)
|
|
3409
|
+
*/
|
|
3410
|
+
clearCache(sourceId?: string): void;
|
|
3411
|
+
/**
|
|
3412
|
+
* 获取缓存大小
|
|
3413
|
+
*/
|
|
3414
|
+
getCacheSize(): number;
|
|
3415
|
+
/**
|
|
3416
|
+
* 睡眠
|
|
3417
|
+
* @param ms 毫秒数
|
|
3418
|
+
*/
|
|
3419
|
+
private sleep;
|
|
3420
|
+
}
|
|
1578
3421
|
|
|
1579
3422
|
/**
|
|
1580
|
-
*
|
|
3423
|
+
* Retry Strategy 实现
|
|
3424
|
+
* @description 提供重试延迟计算和错误判断逻辑
|
|
1581
3425
|
*/
|
|
1582
|
-
|
|
1583
|
-
/** 调试级别:输出最详尽的信息 */
|
|
1584
|
-
DEBUG = 0,
|
|
1585
|
-
/** 信息级别:输出重要的运行状态 */
|
|
1586
|
-
INFO = 1,
|
|
1587
|
-
/** 警告级别:输出潜在的问题,但不影响运行 */
|
|
1588
|
-
WARN = 2,
|
|
1589
|
-
/** 错误级别:输出严重的运行异常 */
|
|
1590
|
-
ERROR = 3,
|
|
1591
|
-
/** 禁用日志:不输出任何信息 */
|
|
1592
|
-
NONE = 4
|
|
1593
|
-
}
|
|
3426
|
+
|
|
1594
3427
|
/**
|
|
1595
|
-
*
|
|
1596
|
-
* @description
|
|
1597
|
-
* 支持通过 `LogLevel` 进行全局过滤。
|
|
1598
|
-
* 支持日志缓冲和自动分组,以减少控制台噪音。
|
|
1599
|
-
* 支持浏览器端 CSS 样式和 Node.js 端 ANSI 颜色。
|
|
3428
|
+
* 重试策略类
|
|
3429
|
+
* @description 计算重试延迟、判断错误是否可重试
|
|
1600
3430
|
*/
|
|
1601
|
-
declare class
|
|
1602
|
-
|
|
1603
|
-
private static level;
|
|
1604
|
-
/** 日志缓冲区 */
|
|
1605
|
-
private static buffer;
|
|
1606
|
-
/** 缓冲输出防抖定时器 */
|
|
1607
|
-
private static flushTimer;
|
|
1608
|
-
/** 缓冲时间窗口 (ms) */
|
|
1609
|
-
private static FLUSH_INTERVAL;
|
|
1610
|
-
/** 是否启用缓冲模式 */
|
|
1611
|
-
private static bufferEnabled;
|
|
1612
|
-
/** 是否为浏览器环境 */
|
|
1613
|
-
private static isBrowser;
|
|
1614
|
-
/** 当前实例的业务模块前缀 */
|
|
1615
|
-
private prefix;
|
|
1616
|
-
/** 实例特定的颜色 */
|
|
1617
|
-
private color;
|
|
3431
|
+
declare class RetryStrategy {
|
|
3432
|
+
private defaultOptions;
|
|
1618
3433
|
/**
|
|
1619
|
-
*
|
|
1620
|
-
* @param
|
|
3434
|
+
* 创建重试策略
|
|
3435
|
+
* @param options 重试配置选项
|
|
1621
3436
|
*/
|
|
1622
|
-
constructor(
|
|
3437
|
+
constructor(options?: RetryOptions);
|
|
1623
3438
|
/**
|
|
1624
|
-
*
|
|
1625
|
-
* @param
|
|
3439
|
+
* 计算重试延迟(指数退避)
|
|
3440
|
+
* @param attempt 当前尝试次数 (从 1 开始)
|
|
3441
|
+
* @returns 延迟毫秒数
|
|
1626
3442
|
*/
|
|
1627
|
-
|
|
3443
|
+
calculateDelay(attempt: number): number;
|
|
1628
3444
|
/**
|
|
1629
|
-
*
|
|
1630
|
-
* @param
|
|
3445
|
+
* 判断错误是否可重试
|
|
3446
|
+
* @param error 错误对象
|
|
3447
|
+
* @returns 是否可重试
|
|
1631
3448
|
*/
|
|
1632
|
-
|
|
3449
|
+
isRetryable(error: any): boolean;
|
|
1633
3450
|
/**
|
|
1634
|
-
*
|
|
1635
|
-
* @
|
|
3451
|
+
* 默认重试条件判断
|
|
3452
|
+
* @param error 错误对象
|
|
3453
|
+
* @returns 是否可重试
|
|
1636
3454
|
*/
|
|
1637
|
-
|
|
3455
|
+
private defaultRetryCondition;
|
|
1638
3456
|
/**
|
|
1639
|
-
*
|
|
3457
|
+
* 获取最大重试次数
|
|
1640
3458
|
*/
|
|
1641
|
-
|
|
3459
|
+
getMaxRetries(): number;
|
|
1642
3460
|
/**
|
|
1643
|
-
*
|
|
3461
|
+
* 获取基础重试延迟
|
|
1644
3462
|
*/
|
|
1645
|
-
|
|
3463
|
+
getBaseDelay(): number;
|
|
3464
|
+
}
|
|
3465
|
+
|
|
3466
|
+
/** 插件依赖输入 */
|
|
3467
|
+
interface PluginDependencyInput {
|
|
3468
|
+
id: string;
|
|
3469
|
+
dependencies: Dependency[];
|
|
3470
|
+
}
|
|
3471
|
+
/** 共享依赖检测结果 */
|
|
3472
|
+
interface SharedDependencyResult {
|
|
3473
|
+
/** 包 ID */
|
|
3474
|
+
packageId: string;
|
|
3475
|
+
/** 请求的版本列表 */
|
|
3476
|
+
requestedVersions: string[];
|
|
3477
|
+
/** 解析后的版本 */
|
|
3478
|
+
resolvedVersion: string;
|
|
3479
|
+
/** 请求者列表 */
|
|
3480
|
+
requestedBy: string[];
|
|
3481
|
+
/** 是否有冲突 */
|
|
3482
|
+
hasConflict: boolean;
|
|
3483
|
+
}
|
|
3484
|
+
/**
|
|
3485
|
+
* 共享依赖检测器
|
|
3486
|
+
* @description 识别多个插件共享的 npm 包,检查版本冲突,使用最高版本策略解决
|
|
3487
|
+
*/
|
|
3488
|
+
declare class SharedDepsDetector {
|
|
1646
3489
|
/**
|
|
1647
|
-
*
|
|
3490
|
+
* 检测共享依赖
|
|
3491
|
+
* @param plugins 插件列表
|
|
3492
|
+
* @returns 共享依赖检测结果
|
|
1648
3493
|
*/
|
|
1649
|
-
|
|
3494
|
+
detect(plugins: PluginDependencyInput[]): SharedDependencyResult[];
|
|
1650
3495
|
/**
|
|
1651
|
-
*
|
|
3496
|
+
* 检查版本是否冲突
|
|
3497
|
+
* @param versions 版本列表
|
|
3498
|
+
* @returns 是否有冲突
|
|
1652
3499
|
*/
|
|
1653
|
-
|
|
3500
|
+
private checkConflict;
|
|
1654
3501
|
/**
|
|
1655
|
-
*
|
|
3502
|
+
* 最高版本策略
|
|
3503
|
+
* @param versions 版本列表
|
|
3504
|
+
* @returns 最高兼容版本
|
|
1656
3505
|
*/
|
|
1657
|
-
|
|
3506
|
+
resolveHighest(versions: string[]): string;
|
|
1658
3507
|
/**
|
|
1659
|
-
*
|
|
3508
|
+
* 最低版本策略
|
|
3509
|
+
* @param versions 版本列表
|
|
3510
|
+
* @returns 最低兼容版本
|
|
1660
3511
|
*/
|
|
1661
|
-
|
|
3512
|
+
resolveLowest(versions: string[]): string;
|
|
3513
|
+
}
|
|
3514
|
+
|
|
3515
|
+
/** 冲突解决结果 */
|
|
3516
|
+
interface ConflictResolution {
|
|
3517
|
+
/** 包 ID */
|
|
3518
|
+
packageId: string;
|
|
3519
|
+
/** 请求的版本列表 */
|
|
3520
|
+
requestedVersions: string[];
|
|
3521
|
+
/** 解析后的版本 */
|
|
3522
|
+
resolvedVersion: string;
|
|
3523
|
+
/** 解决策略 */
|
|
3524
|
+
strategy: 'highest' | 'lowest' | 'user-selected';
|
|
3525
|
+
/** 请求者列表 */
|
|
3526
|
+
requestedBy: string[];
|
|
3527
|
+
}
|
|
3528
|
+
/**
|
|
3529
|
+
* 版本冲突解决器
|
|
3530
|
+
* @description 使用最高版本策略 (默认) 解决版本冲突
|
|
3531
|
+
*/
|
|
3532
|
+
declare class ConflictResolver {
|
|
1662
3533
|
/**
|
|
1663
|
-
*
|
|
3534
|
+
* 解决版本冲突
|
|
3535
|
+
* @param deps 共享依赖检测结果
|
|
3536
|
+
* @param strategy 解决策略,默认 highest
|
|
3537
|
+
* @returns 冲突解决结果
|
|
1664
3538
|
*/
|
|
1665
|
-
|
|
3539
|
+
resolve(deps: SharedDependencyResult[], strategy?: 'highest' | 'lowest'): ConflictResolution[];
|
|
1666
3540
|
/**
|
|
1667
|
-
*
|
|
3541
|
+
* 使用最高版本策略解决
|
|
3542
|
+
* @param dep 共享依赖
|
|
3543
|
+
* @returns 解决的版本
|
|
1668
3544
|
*/
|
|
1669
|
-
|
|
3545
|
+
resolveHighest(dep: SharedDependencyResult): string;
|
|
1670
3546
|
/**
|
|
1671
|
-
*
|
|
3547
|
+
* 使用最低版本策略解决
|
|
3548
|
+
* @param dep 共享依赖
|
|
3549
|
+
* @returns 解决的版本
|
|
1672
3550
|
*/
|
|
1673
|
-
|
|
3551
|
+
resolveLowest(dep: SharedDependencyResult): string;
|
|
1674
3552
|
/**
|
|
1675
|
-
*
|
|
3553
|
+
* 使用 maxSatisfying 解析版本范围
|
|
3554
|
+
* @param range 版本范围
|
|
3555
|
+
* @param versions 可用版本列表
|
|
3556
|
+
* @returns 满足范围的最高版本
|
|
1676
3557
|
*/
|
|
1677
|
-
|
|
3558
|
+
resolveWithRange(range: string, versions: string[]): string | null;
|
|
1678
3559
|
}
|
|
1679
|
-
|
|
1680
|
-
declare const logger: Logger;
|
|
3560
|
+
|
|
1681
3561
|
/**
|
|
1682
|
-
*
|
|
1683
|
-
* @
|
|
1684
|
-
* @returns Logger 实例
|
|
3562
|
+
* 循环依赖检测
|
|
3563
|
+
* @description 使用 DFS 检测插件依赖中的循环引用,生成警告日志
|
|
1685
3564
|
*/
|
|
1686
|
-
declare const createLogger: (prefix: string) => Logger;
|
|
1687
3565
|
|
|
1688
|
-
|
|
3566
|
+
/** 插件依赖输入 */
|
|
3567
|
+
interface CycleDetectorInput {
|
|
3568
|
+
id: string;
|
|
3569
|
+
dependencies: Dependency[];
|
|
3570
|
+
}
|
|
3571
|
+
/** 循环警告 */
|
|
3572
|
+
interface CycleWarning {
|
|
3573
|
+
/** 循环路径 */
|
|
3574
|
+
cycle: string[];
|
|
3575
|
+
/** 完整路径 */
|
|
3576
|
+
path: string[];
|
|
3577
|
+
}
|
|
1689
3578
|
/**
|
|
1690
|
-
*
|
|
1691
|
-
*
|
|
1692
|
-
* - 'first' : 按出现顺序,第一次的值生效
|
|
1693
|
-
* - 'last' : 按出现顺序,最后一次的值生效(默认,最直观)
|
|
1694
|
-
* - 'search' : 只要 search 里出现过,就用 search 的
|
|
1695
|
-
* - 'hash' : 只要 hash 里出现过,就用 hash 的
|
|
3579
|
+
* 循环依赖检测器
|
|
3580
|
+
* @description 使用 DFS 检测循环依赖,生成警告但不阻断加载
|
|
1696
3581
|
*/
|
|
1697
|
-
declare
|
|
3582
|
+
declare class CycleDetector {
|
|
3583
|
+
/**
|
|
3584
|
+
* 检测循环依赖
|
|
3585
|
+
* @param plugins 插件列表
|
|
3586
|
+
* @returns 循环警告列表
|
|
3587
|
+
*/
|
|
3588
|
+
detect(plugins: CycleDetectorInput[]): CycleWarning[];
|
|
3589
|
+
/**
|
|
3590
|
+
* 从依赖图检测循环
|
|
3591
|
+
* @param graph 依赖图
|
|
3592
|
+
* @returns 循环警告列表
|
|
3593
|
+
*/
|
|
3594
|
+
detectFromGraph(graph: Map<string, string[]>): CycleWarning[];
|
|
3595
|
+
/**
|
|
3596
|
+
* 生成循环警告消息
|
|
3597
|
+
* @param warning 循环警告
|
|
3598
|
+
* @returns 警告消息
|
|
3599
|
+
*/
|
|
3600
|
+
formatWarning(warning: CycleWarning): string;
|
|
3601
|
+
/**
|
|
3602
|
+
* 格式化所有警告
|
|
3603
|
+
* @param warnings 循环警告列表
|
|
3604
|
+
* @returns 警告消息列表
|
|
3605
|
+
*/
|
|
3606
|
+
formatWarnings(warnings: CycleWarning[]): string[];
|
|
3607
|
+
}
|
|
3608
|
+
|
|
1698
3609
|
/**
|
|
1699
|
-
*
|
|
1700
|
-
* @description
|
|
3610
|
+
* 依赖图构建器
|
|
3611
|
+
* @description 提供插件依赖拓扑构建、依赖查询功能
|
|
1701
3612
|
*/
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
/**
|
|
1707
|
-
|
|
1708
|
-
/**
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
systemConfig?: Record<string, any>;
|
|
1720
|
-
/** 资源发现的基础 URL,默认为当前 window.location.origin */
|
|
1721
|
-
baseUrl?: string;
|
|
1722
|
-
}
|
|
1723
|
-
/**
|
|
1724
|
-
* 核心 Hook:通用插件加载器
|
|
1725
|
-
* @description 负责应用启动时的插件全生命周期管理:
|
|
1726
|
-
* 1. 自动发现:解析 modules 并根据规则识别插件。
|
|
1727
|
-
* 2. 注册:将插件信息录入 PluginManager。
|
|
1728
|
-
* 3. 加载:调用插件的加载逻辑 (onLoad)。
|
|
1729
|
-
* 4. 初始化:调用插件的挂载逻辑 (onMount)。
|
|
1730
|
-
* 5. 响应式更新:订阅插件状态变更并触发 UI 刷新。
|
|
1731
|
-
*
|
|
1732
|
-
* @param options - 加载配置项
|
|
1733
|
-
* @returns { pluginsLoaded: boolean, pluginVersion: number }
|
|
1734
|
-
* - pluginsLoaded: 插件是否已全部完成初始化
|
|
1735
|
-
* - pluginVersion: 插件状态版本号,用于强制触发依赖插件状态的组件重渲染
|
|
3613
|
+
/** 依赖节点 */
|
|
3614
|
+
interface DependencyNode {
|
|
3615
|
+
/** 节点 ID (插件或包名) */
|
|
3616
|
+
id: string;
|
|
3617
|
+
/** 直接依赖列表 */
|
|
3618
|
+
dependencies: string[];
|
|
3619
|
+
/** 版本 */
|
|
3620
|
+
version: string;
|
|
3621
|
+
}
|
|
3622
|
+
/** 依赖边 */
|
|
3623
|
+
interface DependencyEdge {
|
|
3624
|
+
from: string;
|
|
3625
|
+
to: string;
|
|
3626
|
+
}
|
|
3627
|
+
/**
|
|
3628
|
+
* 依赖图
|
|
3629
|
+
* @description 构建和管理插件依赖拓扑
|
|
1736
3630
|
*/
|
|
1737
|
-
declare
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
3631
|
+
declare class DependencyGraph {
|
|
3632
|
+
private nodes;
|
|
3633
|
+
private edges;
|
|
3634
|
+
/**
|
|
3635
|
+
* 添加依赖节点
|
|
3636
|
+
* @param node 依赖节点
|
|
3637
|
+
*/
|
|
3638
|
+
addNode(node: DependencyNode): void;
|
|
3639
|
+
/**
|
|
3640
|
+
* 添加依赖边
|
|
3641
|
+
* @param from 依赖者 ID
|
|
3642
|
+
* @param to 被依赖者 ID
|
|
3643
|
+
*/
|
|
3644
|
+
addEdge(from: string, to: string): void;
|
|
3645
|
+
/**
|
|
3646
|
+
* 获取依赖指定包的所有插件
|
|
3647
|
+
* @param packageId 包 ID
|
|
3648
|
+
* @returns 依赖该包的插件列表
|
|
3649
|
+
*/
|
|
3650
|
+
getDependents(packageId: string): string[];
|
|
3651
|
+
/**
|
|
3652
|
+
* 获取指定插件的所有依赖
|
|
3653
|
+
* @param pluginId 插件 ID
|
|
3654
|
+
* @returns 依赖列表
|
|
3655
|
+
*/
|
|
3656
|
+
getDependencies(pluginId: string): string[];
|
|
3657
|
+
/**
|
|
3658
|
+
* 获取完整依赖图
|
|
3659
|
+
* @returns 节点 ID 到依赖列表的映射
|
|
3660
|
+
*/
|
|
3661
|
+
getGraph(): Map<string, string[]>;
|
|
3662
|
+
/**
|
|
3663
|
+
* 获取所有节点
|
|
3664
|
+
* @returns 节点列表
|
|
3665
|
+
*/
|
|
3666
|
+
getNodes(): DependencyNode[];
|
|
3667
|
+
/**
|
|
3668
|
+
* 获取所有边
|
|
3669
|
+
* @returns 边列表
|
|
3670
|
+
*/
|
|
3671
|
+
getEdges(): DependencyEdge[];
|
|
3672
|
+
/**
|
|
3673
|
+
* 检查节点是否存在
|
|
3674
|
+
* @param id 节点 ID
|
|
3675
|
+
* @returns 是否存在
|
|
3676
|
+
*/
|
|
3677
|
+
hasNode(id: string): boolean;
|
|
3678
|
+
/**
|
|
3679
|
+
* 获取节点
|
|
3680
|
+
* @param id 节点 ID
|
|
3681
|
+
* @returns 节点,不存在返回 undefined
|
|
3682
|
+
*/
|
|
3683
|
+
getNode(id: string): DependencyNode | undefined;
|
|
3684
|
+
/**
|
|
3685
|
+
* 清空图
|
|
3686
|
+
*/
|
|
3687
|
+
clear(): void;
|
|
3688
|
+
/**
|
|
3689
|
+
* 获取图的大小
|
|
3690
|
+
* @returns 节点数量
|
|
3691
|
+
*/
|
|
3692
|
+
size(): number;
|
|
3693
|
+
}
|
|
1741
3694
|
|
|
3695
|
+
/** npm 包元数据 */
|
|
3696
|
+
interface NpmPackageMeta {
|
|
3697
|
+
name: string;
|
|
3698
|
+
versions: Record<string, unknown>;
|
|
3699
|
+
'dist-tags': Record<string, string>;
|
|
3700
|
+
time?: Record<string, string>;
|
|
3701
|
+
}
|
|
3702
|
+
/** 版本信息 */
|
|
3703
|
+
interface VersionInfo {
|
|
3704
|
+
version: string;
|
|
3705
|
+
date?: string;
|
|
3706
|
+
deprecated?: boolean;
|
|
3707
|
+
}
|
|
1742
3708
|
/**
|
|
1743
|
-
*
|
|
3709
|
+
* NPM Registry 客户端
|
|
3710
|
+
* @description 集成 npm Registry API,支持包元数据查询、版本解析和缓存
|
|
1744
3711
|
*/
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
3712
|
+
declare class NpmRegistry {
|
|
3713
|
+
private client;
|
|
3714
|
+
private cache;
|
|
3715
|
+
/**
|
|
3716
|
+
* 创建 NPM Registry 客户端
|
|
3717
|
+
* @param baseUrl Registry 基础 URL,默认 https://registry.npmjs.org
|
|
3718
|
+
*/
|
|
3719
|
+
constructor(baseUrl?: string);
|
|
3720
|
+
/**
|
|
3721
|
+
* 获取包元数据
|
|
3722
|
+
* @param packageName 包名
|
|
3723
|
+
* @param useCache 是否使用缓存,默认 true
|
|
3724
|
+
* @returns 包元数据,不存在返回 null
|
|
3725
|
+
*/
|
|
3726
|
+
getPackageMeta(packageName: string, useCache?: boolean): Promise<NpmPackageMeta | null>;
|
|
3727
|
+
/**
|
|
3728
|
+
* 获取包的所有版本
|
|
3729
|
+
* @param packageName 包名
|
|
3730
|
+
* @returns 版本列表
|
|
3731
|
+
*/
|
|
3732
|
+
getVersions(packageName: string): Promise<string[]>;
|
|
3733
|
+
/**
|
|
3734
|
+
* 获取包的最新版本
|
|
3735
|
+
* @param packageName 包名
|
|
3736
|
+
* @returns 最新版本,不存在返回 null
|
|
3737
|
+
*/
|
|
3738
|
+
getLatestVersion(packageName: string): Promise<string | null>;
|
|
3739
|
+
/**
|
|
3740
|
+
* 从版本范围解析最佳版本
|
|
3741
|
+
* @param packageName 包名
|
|
3742
|
+
* @param range 版本范围 (如 ^1.0.0, >=1.0.0)
|
|
3743
|
+
* @returns 满足范围的最高版本,不存在返回 null
|
|
3744
|
+
*/
|
|
3745
|
+
resolveVersion(packageName: string, range: string): Promise<string | null>;
|
|
3746
|
+
/**
|
|
3747
|
+
* 获取指定版本的详细信息
|
|
3748
|
+
* @param packageName 包名
|
|
3749
|
+
* @param version 版本号
|
|
3750
|
+
* @returns 版本信息,不存在返回 null
|
|
3751
|
+
*/
|
|
3752
|
+
getVersionInfo(packageName: string, version: string): Promise<VersionInfo | null>;
|
|
3753
|
+
/**
|
|
3754
|
+
* 批量解析依赖
|
|
3755
|
+
* @param dependencies 依赖列表 [{ id, version }]
|
|
3756
|
+
* @returns 包名到解析后版本的映射
|
|
3757
|
+
*/
|
|
3758
|
+
resolveDependencies(dependencies: Array<{
|
|
3759
|
+
id: string;
|
|
3760
|
+
version: string;
|
|
3761
|
+
}>): Promise<Map<string, string>>;
|
|
3762
|
+
/**
|
|
3763
|
+
* 清除缓存
|
|
3764
|
+
* @param packageName 包名,不提供则清除所有缓存
|
|
3765
|
+
*/
|
|
3766
|
+
clearCache(packageName?: string): void;
|
|
1748
3767
|
}
|
|
1749
3768
|
/**
|
|
1750
|
-
*
|
|
1751
|
-
* @
|
|
1752
|
-
* @param pluginId 定义该 Key 的插件 ID
|
|
1753
|
-
* @param key 存储键名 (必须在 Schema 中注册)
|
|
1754
|
-
* @param options 配置项,包含默认值和作用域
|
|
3769
|
+
* 获取默认 Registry 实例
|
|
3770
|
+
* @returns 默认 NpmRegistry 实例
|
|
1755
3771
|
*/
|
|
1756
|
-
declare function
|
|
3772
|
+
declare function getDefaultRegistry(): NpmRegistry;
|
|
1757
3773
|
|
|
1758
|
-
export { type ApiAdapter, type ApiConfig, type ApiEndpointConfig, ApiEngine, type ApiInterceptor,
|
|
3774
|
+
export { type AIChunk, type AIMessage, type AIProvider, type AITool, type ApiAdapter, type ApiConfig, type ApiEndpointConfig, ApiEngine, type ApiInterceptor, type ApiPort, type ApiRequestConfig, type ApiResponseContext, AxiosAdapter, BasePlugin, type BaseResponse, type CacheEntry, type CacheOptions, type ChatOptions, type Command, type CommandHandler, type CommandType, type Compatibility, ConfigEvents, type ConfigItemDefinition, ConfigManager, type ConflictResolution, ConflictResolver, CoreError, CoreErrorCode, CoreErrorStrategy, type CoreState, CycleDetector, type CycleDetectorInput, type CycleWarning, DEFAULT_PERFORMANCE_SETTINGS, type DeepReadonly, DefaultEventBus, type Dependency, type DependencyEdge, DependencyGraph, type DependencyNode, type DeprecationInfo, type DeprecationWarning, type DiscoveryRule, EXTENSION_TYPES, type Entry, type ErrorHandlerOptions, type ErrorStrategy, type EventBus, type EventBusPort, type EventCallback, type Extension, type ExtensionType, FEATURE_NAMESPACE_PREFIX, type FeatureConfig, type RuleContext as FeatureContext, type FeatureRegistryState, type FeatureRule, type FunctionCallResult, type HookType, type HttpMethod, type LifecycleMetric, LifecycleMonitor, type LifecyclePhase, type LoadError, type LoadResult, LocalStorageAdapter, LogLevel, Logger, type MigrationWarning, MockAIProvider, type NpmPackageMeta, NpmRegistry, type OnActivateHandler, type OnDeactivateHandler, type OnErrorHandler, OpenAIProvider, PLUGIN_TYPES, PerformanceCollector, type PerformanceData, type PerformanceSettings, PerformanceStorage, PerformanceTimer, type Permission, type PermissionAction, type PermissionScope, type PermissionType, type Plugin, type PluginCapabilities, type PluginConfigItem, type PluginContext, type PluginDependencyInput, PluginError, PluginErrorType, PluginEvents, type PluginExtension, type PluginId, PluginIdSchema, type PluginLifecycle, PluginManager, type PluginManifest, PluginManifestSchema, type PluginManifestType, type PluginMetadata, type PluginRegistry, PluginRuntime, PluginSandbox, type PluginStorage, type PluginType, ProxySandbox, RENDER_MODES, RemoteCache, RemoteLoader, type RemotePluginSource, type RemoteSourceOptions, type RenderMode, type RequestOptions, type RetryOptions, RetryStrategy, type RouteConfig, type RoutePath, RoutePathSchema, type RuleContext, type RuleType, type RuntimeMetric, STORAGE_KEY, SUCCESS_CODE, type SafePluginConfig, type SandboxOptions, type Scene, ScopedStorageAdapter, type SemVer, SemVerSchema, ServiceRegistry, type Session, SessionLocalStorageAdapter, SessionManager, type SessionManagerInterface, type SessionStorage, type SharedDependencyResult, SharedDepsDetector, Slot, type SlotKey, SlotKeySchema, type SlotPosition, type SlotType, type StorageItemSchema, StorageManager, type StoragePort, type StreamCallbacks, type ToolCall, ToolRegistry, type TypedStorage, type UseFeatureResult, type ValidationResult, type VersionInfo, apiEngine, assertManifest, cleanUrlParams, configManager, coreStore, coreStoreApi, createAIStore, createEnvironmentRule, createLifecycleMonitor, createLogger, createPercentageRule, createPerformanceMonitor, createPluginId, createRoutePath, createSemVer, createSlotKey, createUserRule, dateUtils, definePlugin, evaluateRules as evaluateFeatureRules, evaluateRule, evaluateRules$1 as evaluateRules, extractManifestFromPlugin, getDefaultRegistry, handleError, simpleHash as hashString, isMockMode, isPluginId, isPluginManifest, isRoutePath, isSemVer, isSlotKey, logger, normalizeParams, normalizePluginManifest, pluginManager, resolveApiModules, resolvePluginRegistry, serviceRegistry, simpleHash$1 as simpleHash, useAIStore, useFeature, useFeatureFlags, validateManifest, version };
|