@chatbi-v/core 2.1.10 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,644 +1,678 @@
1
- import React, { Component, ReactNode, ErrorInfo } from 'react';
2
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ import { S as StoragePort, a as StorageItemSchema, P as Plugin, b as PluginContext, c as PluginManifest, d as PluginCapabilities, e as SlotPosition, f as PluginExtension, R as RouteConfig, A as ApiAdapter, g as ApiRequestConfig, h as StreamCallbacks, i as ApiEndpointConfig, j as ApiInterceptor, k as ApiConfig, l as RequestOptions, D as Dependency } from './plugin-port-CHRPxDOi.cjs';
2
+ export { F as ApiPort, y as ApiResponseContext, M as BasePlugin, Q as Command, U as CommandHandler, V as CommandType, W as Compatibility, a4 as EXTENSION_TYPES, X as Entry, E as ErrorStrategy, z as EventBusPort, Y as Extension, Z as ExtensionType, _ as HookType, H as HttpMethod, $ as OnActivateHandler, a0 as OnDeactivateHandler, a1 as OnErrorHandler, B as PLUGIN_TYPES, m as Permission, n as PermissionAction, o as PermissionScope, p as PermissionType, J as PluginConfigItem, u as PluginId, v as PluginIdSchema, L as PluginLifecycle, a3 as PluginManifestSchema, O as PluginMetadata, K as PluginStorage, C as PluginType, a5 as RENDER_MODES, a2 as RenderMode, G as Slot, w as SlotKey, x as SlotKeySchema, I as SlotType, T as TypedStorage, q as createPluginId, r as createSlotKey, N as definePlugin, s as isPluginId, t as isSlotKey } from './plugin-port-CHRPxDOi.cjs';
3
+ import { z } from 'zod';
4
+ import * as zustand_vanilla from 'zustand/vanilla';
5
+ import * as zustand_middleware from 'zustand/middleware';
6
+ export { ValidationResult, assertManifest, extractManifestFromPlugin, normalizePluginManifest, validateManifest } from './manifest/index.cjs';
7
+ export { AdapterFactory, AdapterRegistry, AdapterState, AdapterStatus, BaseAdapter, TransformOptions, UIAdapter, adapterRegistry } from './adapters/index.cjs';
3
8
  import dayjs from 'dayjs';
4
9
 
5
10
  /**
6
- * HTTP 请求方法
11
+ * @file template-literals.ts
12
+ * @description 模板字面量类型 - 用于精确类型检查
7
13
  */
8
- type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
14
+
9
15
  /**
10
- * 错误处理策略
16
+ * SemVer 版本号类型
17
+ * @description 匹配符合 SemVer 规范 (^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9.-]+)?$) 的版本号
18
+ * 支持如 1.0.0, 1.2.3-beta.1, 2.0.0-alpha+001 等格式
11
19
  */
12
- type ErrorStrategy = 'reject' | 'resolve' | 'silent';
20
+ type SemVer = string & {
21
+ __semver: 'SemVer';
22
+ };
13
23
  /**
14
- * API 接口端点配置
24
+ * RoutePath 路由路径类型
25
+ * @description 以 / 开头的路由路径
15
26
  */
16
- interface ApiEndpointConfig {
17
- /** 接口路径 (支持 :param 语法) */
18
- url: string;
19
- /** 请求方法 */
20
- method: HttpMethod;
21
- /** 接口描述 */
22
- desc?: string;
23
- /** Mock 响应数据结构定义 */
24
- responseSchema?: any;
25
- /** 错误处理策略 */
26
- errorStrategy?: ErrorStrategy;
27
- }
27
+ type RoutePath = string & {
28
+ __routePath: 'RoutePath';
29
+ };
30
+
28
31
  /**
29
- * API 请求配置
32
+ * SemVer 的 Zod 验证 Schema
30
33
  */
31
- interface ApiRequestConfig {
32
- /** 请求 URL */
33
- url: string;
34
- /** 请求方法 */
35
- method: HttpMethod;
36
- /** 请求体数据 (POST/PUT 等) */
37
- data?: any;
38
- /** 查询参数 (GET 等) */
39
- params?: any;
40
- /** 请求头 */
41
- headers?: any;
42
- /** 用于取消请求的信号对象 */
43
- signal?: AbortSignal;
44
- }
34
+ declare const SemVerSchema: z.ZodString;
45
35
  /**
46
- * 流式响应回调函数接口
36
+ * RoutePath 的 Zod 验证 Schema
47
37
  */
48
- interface StreamCallbacks {
49
- /** 收到消息片段时的回调 */
50
- onMessage?: (data: any) => void;
51
- /** 发生错误时的回调 */
52
- onError?: (error: any) => void;
53
- /** 请求完成时的回调 */
54
- onFinish?: () => void;
55
- /** 收到 HTTP 响应头部信息的回调,返回 true 表示劫持并中止流 */
56
- onResponse?: (response: any) => Promise<boolean> | boolean;
57
- }
38
+ declare const RoutePathSchema: z.ZodString;
58
39
  /**
59
- * API 适配器端口接口
60
- * @description 所有底层请求引擎(如 Fetch, Axios, Mock)都必须实现此接口,以确保内核对具体通信库的解耦。
40
+ * 创建类型安全的 SemVer 版本号
41
+ * @param version - 版本号字符串
42
+ * @returns 带类型标记的 SemVer 类型
61
43
  */
62
- interface ApiAdapter {
63
- /**
64
- * 发起普通 HTTP 请求
65
- * @param config - 请求配置
66
- * @param endpointConfig - 接口端点定义的元数据配置
67
- * @returns 响应数据的 Promise
68
- */
69
- request<T = any>(config: ApiRequestConfig, endpointConfig?: ApiEndpointConfig): Promise<T>;
70
- /**
71
- * 发起流式请求 (SSE 或 Chunked Transfer)
72
- * @param config - 请求配置
73
- * @param callbacks - 流式处理的回调函数集合
74
- * @param endpointConfig - 接口端点定义的元数据配置
75
- */
76
- stream?(config: ApiRequestConfig, callbacks: StreamCallbacks, endpointConfig?: ApiEndpointConfig): Promise<void>;
77
- }
44
+ declare function createSemVer(version: string): SemVer;
78
45
  /**
79
- * API 配置集合 (按模块和动作分组)
46
+ * 创建类型安全的 RoutePath 路由路径
47
+ * @param path - 路由路径字符串
48
+ * @returns 带类型标记的 RoutePath 类型
80
49
  */
81
- interface ApiConfig {
82
- /** 模块名称 */
83
- [module: string]: {
84
- /** 动作/接口名称 */
85
- [action: string]: ApiEndpointConfig;
86
- };
87
- }
50
+ declare function createRoutePath(path: string): RoutePath;
88
51
  /**
89
- * 业务侧发起请求时的选项
52
+ * 类型守卫:检查是否为有效的 SemVer
53
+ * @param value - 要检查的值
54
+ * @returns 是否为 SemVer 类型
90
55
  */
91
- interface RequestOptions extends Partial<ApiRequestConfig> {
92
- /** 是否跳过全局错误处理逻辑 */
93
- skipErrorHandler?: boolean;
94
- /** 路径参数集合 (将替换 url 中的 :param 占位符) */
95
- params?: any;
96
- /** 流式响应:收到数据片段的回调 */
97
- onMessage?: (data: any) => void;
98
- /** 流式响应:发生错误的回调 */
99
- onError?: (error: any) => void;
100
- /** 流式响应:正常结束的回调 */
101
- onFinish?: () => void;
102
- /** 允许透传其他底层适配器所需的属性 (例如 axios 的特定配置) */
103
- [key: string]: any;
104
- }
56
+ declare function isSemVer(value: unknown): value is SemVer;
57
+ /**
58
+ * 类型守卫:检查是否为有效的 RoutePath
59
+ * @param value - 要检查的值
60
+ * @returns 是否为 RoutePath 类型
61
+ */
62
+ declare function isRoutePath(value: unknown): value is RoutePath;
63
+
64
+ /**
65
+ * 深度只读类型
66
+ * @description 递归将所有属性(包括嵌套对象和数组)设为只读
67
+ * @example
68
+ * type ReadonlyPluginConfig = DeepReadonly<PluginConfig>;
69
+ * // 所有嵌套属性都变为 readonly
70
+ */
71
+ type DeepReadonly<T> = {
72
+ readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
73
+ };
105
74
  /**
106
- * API 响应拦截上下文对象
75
+ * 配置项定义
107
76
  */
108
- interface ApiResponseContext {
109
- /** 原始响应对象 (例如 AxiosResponse 或 Fetch Response) */
110
- response: any;
111
- /** HTTP 响应状态码 */
112
- status: number;
113
- /** 响应头集合 */
114
- headers: Record<string, string>;
115
- /** 解析后的业务数据体 */
116
- data: any;
117
- /** 对应的原始请求配置 */
118
- config: ApiRequestConfig;
77
+ interface ConfigItemDefinition {
78
+ key: string;
79
+ type: 'string' | 'number' | 'boolean' | 'select';
80
+ label: string;
81
+ description?: string;
82
+ default?: unknown;
83
+ options?: Array<{
84
+ label: string;
85
+ value: unknown;
86
+ }>;
119
87
  }
120
88
  /**
121
- * API 拦截器定义
89
+ * 安全的插件配置类型
90
+ * @description 根据插件的 configuration 定义生成运行时配置类型
91
+ * @example
92
+ * interface MyPluginConfig {
93
+ * apiKey: string;
94
+ * maxResults: number;
95
+ * }
96
+ * type SafeConfig = SafePluginConfig<{ apiKey: string; maxResults: number }>;
97
+ */
98
+ type SafePluginConfig<T extends ConfigItemDefinition[]> = {
99
+ [K in T[number] as K['key']]: K['default'];
100
+ };
101
+ /**
102
+ * Plugin Manifest 类型
103
+ * @description 从 Zod Schema 推断出的插件清单类型
104
+ */
105
+ type PluginManifestType = {
106
+ id: string;
107
+ version: string;
108
+ name: string;
109
+ entry: string | {
110
+ url: string;
111
+ shareScope?: string;
112
+ };
113
+ type?: 'business' | 'functional' | 'view' | 'theme' | 'renderer' | 'system';
114
+ description?: string;
115
+ author?: string;
116
+ icon?: string;
117
+ compatibility?: {
118
+ minVersion?: string;
119
+ maxVersion?: string;
120
+ supportedVersions?: string[];
121
+ };
122
+ dependencies?: Array<{
123
+ id: string;
124
+ version: string;
125
+ optional?: boolean;
126
+ }>;
127
+ extensions?: Array<{
128
+ name: string;
129
+ type: 'slot' | 'hook' | 'command' | 'service';
130
+ description?: string;
131
+ slot?: string;
132
+ config?: Record<string, unknown>;
133
+ renderMode?: 'replace' | 'append' | 'prepend';
134
+ condition?: Record<string, unknown>;
135
+ }>;
136
+ capabilities?: Record<string, boolean>;
137
+ configuration?: ConfigItemDefinition[];
138
+ storage?: unknown[];
139
+ routes?: Array<{
140
+ path: string;
141
+ }>;
142
+ permissions?: Array<{
143
+ action: 'read' | 'write' | 'execute' | 'admin';
144
+ scope: 'plugin' | 'global' | 'user';
145
+ resource: string;
146
+ }>;
147
+ priority?: number;
148
+ };
149
+ /**
150
+ * 类型守卫: 检查值是否为有效的 PluginManifest
151
+ * @param value - 要检查的值
152
+ * @returns 如果值符合 PluginManifestSchema 则返回 true
153
+ * @example
154
+ * if (isPluginManifest(data)) {
155
+ * console.log(data.name); // TypeScript 知道这是有效的 PluginManifest
156
+ * }
157
+ */
158
+ declare function isPluginManifest(value: unknown): value is PluginManifestType;
159
+
160
+ /**
161
+ * 服务注册中心 (Service Registry)
162
+ * @description 核心应用层服务,作为微内核架构中的“中枢调度员”。
163
+ * 主要职责:
164
+ * 1. 服务解耦:允许插件将其内部功能暴露为“服务”,而无需与其他插件产生物理依赖。
165
+ * 2. 动态发现:提供按名称查找服务的能力,支持服务热插拔。
166
+ * 3. 依赖协调:通过 `waitFor` 机制解决插件间由于加载顺序导致的初始化依赖问题。
167
+ *
168
+ * 建议的服务命名规范: `pluginId.serviceName` (例如: `auth.sessionService`)
122
169
  */
123
- interface ApiInterceptor {
170
+ declare class ServiceRegistry {
171
+ /** 存储已注册服务的 Map 对象 */
172
+ private services;
173
+ /** 存储正在等待特定服务的监听器集合 */
174
+ private listeners;
124
175
  /**
125
- * 请求发送前的拦截逻辑
126
- * @param config - 原始请求配置
127
- * @returns 修改后的请求配置,或其 Promise
176
+ * 注册一个服务实现
177
+ * @param name - 唯一的服务名称
178
+ * @param service - 服务实例或对象
128
179
  */
129
- interceptRequest?: (config: ApiRequestConfig) => ApiRequestConfig | Promise<ApiRequestConfig>;
180
+ register(name: string, service: any): void;
130
181
  /**
131
- * 响应接收后的拦截逻辑
132
- * @param context - 响应上下文信息
133
- * @returns 如果返回 true,表示该拦截器已接管并处理了响应,后续拦截器及业务回调将不再触发
182
+ * 同步获取服务实例
183
+ * @template T - 服务类型的泛型
184
+ * @param name - 服务名称
185
+ * @returns 服务实例,若不存在则返回 undefined
134
186
  */
135
- interceptResponse?: (context: ApiResponseContext) => boolean | Promise<boolean>;
136
- }
137
-
138
- /**
139
- * 事件总线端口接口
140
- * @description 定义应用内部事件通信的标准契约,支持发布订阅模式。
141
- */
142
- interface EventBusPort {
187
+ get<T = any>(name: string): T | undefined;
143
188
  /**
144
- * 订阅事件
145
- * @param event - 事件名称
146
- * @param callback - 事件触发时的回调函数
147
- * @returns 取消订阅的函数
189
+ * 异步等待并获取服务
190
+ * @description 如果服务尚未注册,将返回一个 Promise,直到该服务被注册时 resolve。
191
+ * 支持设置超时时间,防止因插件加载失败导致的永久挂起。
192
+ *
193
+ * @template T - 服务类型的泛型
194
+ * @param name - 待等待的服务名称
195
+ * @param timeout - 超时时间 (毫秒),默认 10000ms (10秒)。若为 0 则永不超时。
196
+ * @returns 包含服务实例的 Promise
197
+ * @throws {Error} 若在规定时间内服务未注册,则抛出超时异常。
148
198
  */
149
- on(event: string, callback: (...args: any[]) => any): () => void;
199
+ waitFor<T = any>(name: string, timeout?: number): Promise<T>;
150
200
  /**
151
- * 取消订阅事件
152
- * @param event - 事件名称
153
- * @param callback - 之前注册的回调函数
201
+ * 检查服务是否已注册
202
+ * @param name - 服务名称
154
203
  */
155
- off(event: string, callback: (...args: any[]) => any): void;
204
+ has(name: string): boolean;
156
205
  /**
157
- * 触发事件 (发布)
158
- * @param event - 事件名称
159
- * @param args - 传递给回调函数的参数列表
206
+ * 注销特定的服务
207
+ * @param name - 服务名称
160
208
  */
161
- emit(event: string, ...args: any[]): void;
209
+ unregister(name: string): void;
162
210
  /**
163
- * 订阅一次性事件
164
- * @description 事件触发一次后会自动取消订阅
165
- * @param event - 事件名称
166
- * @param callback - 事件触发时的回调函数
211
+ * 清除所有已注册的服务和监听器
212
+ * @description 通常仅在系统重置或大型热更新时使用。
167
213
  */
168
- once(event: string, callback: (...args: any[]) => any): void;
214
+ clear(): void;
169
215
  }
216
+ declare const serviceRegistry: ServiceRegistry;
170
217
 
171
218
  /**
172
- * 存储端口接口
173
- * @description 定义数据持久化的标准契约,兼容 Web Storage API。
219
+ * 配置管理器
220
+ * @description 核心工具类,负责管理应用的全局系统配置以及各插件的初始化业务配置。
221
+ * 配置数据通常在应用启动时通过 `usePluginLoader` 注入,并作为插件运行时的取值回退来源。
174
222
  */
175
- interface StoragePort {
223
+ declare class ConfigManager<T = Record<string, unknown>> {
224
+ /** 内部存储配置的 Map 对象 */
225
+ private config;
176
226
  /**
177
- * 获取存储项
178
- * @param key - 键名
179
- * @returns 对应的值,如果不存在则返回 null
227
+ * 设置特定的配置项
228
+ * @param key - 配置键名(如 'system' 或插件 ID)
229
+ * @param value - 配置内容对象
180
230
  */
181
- getItem(key: string): string | null;
231
+ set<K extends keyof T>(key: K, value: T[K]): void;
232
+ set(key: string, value: unknown): void;
182
233
  /**
183
- * 设置存储项
184
- * @param key - 键名
185
- * @param value - 键值 (字符串)
234
+ * 获取指定的配置项
235
+ * @param key - 配置键名
236
+ * @returns 配置内容,若不存在则返回 undefined
186
237
  */
187
- setItem(key: string, value: string): void;
238
+ get<K extends keyof T>(key: K): T[K] | undefined;
239
+ get(key: string): unknown;
188
240
  /**
189
- * 移除指定的存储项
190
- * @param key - 键名
241
+ * 深度合并配置对象
242
+ * @description 对配置进行深度合并,嵌套对象会被递归合并而非完全覆盖。
243
+ * @param config - 待合并的配置对象映射
191
244
  */
192
- removeItem(key: string): void;
245
+ merge(config: Partial<T> & Record<string, unknown>): void;
193
246
  /**
194
- * 清空所有存储项
247
+ * 深度合并两个对象
195
248
  */
196
- clear(): void;
249
+ private deepMerge;
250
+ /**
251
+ * 获取当前存储的所有配置快照
252
+ * @returns 包含所有配置的普通对象
253
+ */
254
+ getAll(): T;
197
255
  /**
198
- * 返回存储对象中当前存储的数据项总数
256
+ * 检查配置项是否存在
199
257
  */
200
- readonly length: number;
258
+ has(key: string): boolean;
201
259
  /**
202
- * 根据索引返回存储中对应键的名称
203
- * @param index - 数值索引
204
- * @returns 键名,如果索引超出范围则返回 null
260
+ * 删除指定配置项
205
261
  */
206
- key(index: number): string | null;
207
- }
208
- /**
209
- * 类型化存储接口
210
- * @description 提供泛型支持的存储访问能力,自动处理序列化
211
- */
212
- interface TypedStorage {
213
- /** 获取存储数据 */
214
- get: <T = any>(key: string) => T | null;
215
- /** 设置存储数据 */
216
- set: <T = any>(key: string, value: T) => void;
217
- /** 移除存储数据 */
218
- remove: (key: string) => void;
262
+ delete(key: string): boolean;
263
+ /**
264
+ * 清空所有配置
265
+ */
266
+ clear(): void;
219
267
  }
268
+ /** 全局配置管理器单例 */
269
+ declare const configManager: ConfigManager<Record<string, unknown>>;
220
270
 
221
271
  /**
222
- * 插件类型定义
223
- */
224
- declare const PLUGIN_TYPES: readonly ["business", "functional", "view", "theme", "renderer", "system"];
225
- type PluginType = typeof PLUGIN_TYPES[number];
226
- /**
227
- * 路由配置
272
+ * AI 能力抽象层类型定义
228
273
  */
229
- interface RouteConfig {
230
- path: string;
231
- component: React.ComponentType<any>;
232
- meta?: Record<string, any>;
274
+ interface AIMessage {
275
+ id: string;
276
+ role: 'user' | 'assistant' | 'system' | 'tool';
277
+ content: string;
278
+ name?: string;
279
+ toolCallId?: string;
280
+ toolCalls?: ToolCall[];
281
+ createdAt?: number;
233
282
  }
234
- /**
235
- * 插件插槽位置
236
- * @description 定义插件可以注入 UI 的标准位置
237
- */
238
- declare const Slot: {
239
- readonly Sidebar: "sidebar";
240
- readonly SidebarPanel: "sidebar-panel";
241
- readonly Header: "header";
242
- readonly StatusBar: "status-bar";
243
- readonly Settings: "settings";
244
- readonly MessageRenderer: "message-renderer";
245
- readonly MessageContentRenderer: "message-content-renderer";
246
- readonly SidebarSystem: "sidebar-system";
247
- readonly SidebarBottom: "sidebar-bottom";
248
- readonly RootLayout: "root-layout";
249
- readonly Custom: "custom";
250
- };
251
- type SlotType = typeof Slot[keyof typeof Slot];
252
- type SlotPosition = SlotType | string;
253
- /**
254
- * 插件扩展 (插槽注入配置)
255
- */
256
- interface PluginExtension {
257
- /** 插槽位置标识符 */
258
- slot: SlotPosition;
259
- /** 要注入的 React 组件 */
260
- component: React.ComponentType<any>;
261
- /** 排序权重,数值越小越靠前 */
262
- order?: number;
263
- /** @internal 插件 ID,由系统在加载时自动注入,用于溯源 */
264
- _pluginId?: string;
265
- /** 扩展的元数据信息 */
266
- meta?: {
267
- /** 显示图标 */
268
- icon?: React.ReactNode;
269
- /** 显示标签文本 */
270
- label?: string;
271
- /** 详细描述 */
272
- description?: string;
273
- /** 唯一标识符,用于某些特定插槽的索引 */
274
- key?: string;
275
- /** 允许其他自定义属性 */
276
- [key: string]: any;
283
+ interface ToolCall {
284
+ id: string;
285
+ type: 'function';
286
+ function: {
287
+ name: string;
288
+ arguments: string;
277
289
  };
278
290
  }
279
- /**
280
- * 插件配置项定义
281
- */
282
- interface PluginConfigItem {
283
- /** 配置键名 */
284
- key: string;
285
- /** 配置类型 */
286
- type: 'string' | 'number' | 'boolean' | 'select';
287
- /** 配置显示的标签 */
288
- label: string;
289
- /** 配置描述信息 */
290
- description?: string;
291
- /** 默认值 */
292
- default?: any;
293
- /** 当类型为 select 时的选项列表 */
294
- options?: {
295
- label: string;
296
- value: any;
297
- }[];
298
- /** 选择模式:支持多选或标签模式 (AntD 风格) */
299
- mode?: 'multiple' | 'tags';
300
- /** 最小值 (针对 number 类型) */
301
- min?: number;
302
- /** 最大值 (针对 number 类型) */
303
- max?: number;
304
- /**
305
- * 是否为私有配置
306
- * @description 如果为 true,则该配置不会通过自动配置服务暴露给其他插件
307
- * @default false
308
- */
309
- private?: boolean;
291
+ interface ChatOptions {
292
+ model?: string;
293
+ temperature?: number;
294
+ maxTokens?: number;
295
+ tools?: AITool[];
296
+ stream?: boolean;
297
+ systemPrompt?: string;
298
+ }
299
+ interface AIProvider {
300
+ chat(messages: AIMessage[], options?: ChatOptions): Promise<AIMessage>;
301
+ stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable<AIChunk>;
302
+ functionCall(messages: AIMessage[], tools: AITool[], options?: ChatOptions): Promise<FunctionCallResult>;
303
+ }
304
+ interface AIChunk {
305
+ type: 'content' | 'tool-call' | 'done' | 'error';
306
+ content?: string;
307
+ toolCall?: ToolCall;
308
+ error?: string;
309
+ }
310
+ interface FunctionCallResult {
311
+ message: AIMessage;
312
+ toolCalls: ToolCall[];
313
+ }
314
+ interface Session {
315
+ id: string;
316
+ name: string;
317
+ messages: AIMessage[];
318
+ createdAt: number;
319
+ updatedAt: number;
320
+ metadata?: Record<string, unknown>;
321
+ }
322
+ interface AITool {
323
+ name: string;
324
+ description: string;
325
+ parameters: Record<string, unknown>;
326
+ execute: (args: Record<string, unknown>) => Promise<unknown>;
310
327
  }
328
+
311
329
  /**
312
- * 插件能力定义 (Behavioral Capabilities)
313
- * @description 定义插件的行为特征。注意:路由(routes)和扩展(extensions)属于结构化能力,直接通过 metadata 字段声明,不在此列。
330
+ * 工具注册表
331
+ * 管理 AI 函数的注册和执行
314
332
  */
315
- interface PluginCapabilities {
333
+ declare class ToolRegistry {
334
+ private tools;
316
335
  /**
317
- * 是否支持配置设置
318
- * @default false (如果 metadata.configuration 存在,则可能被隐式视为 true,建议显式声明)
336
+ * 注册工具
319
337
  */
320
- configurable?: boolean;
338
+ register(tool: AITool): void;
321
339
  /**
322
- * 是否可嵌入其他页面
323
- * @description 声明该插件是否可以作为 Widget 被其他插件引用
340
+ * 注销工具
324
341
  */
325
- embeddable?: boolean;
342
+ unregister(name: string): void;
326
343
  /**
327
- * 是否支持多实例
328
- * @description 默认为 false (单例)。如果在聊天窗口中每个会话都需要独立状态,则设为 true
344
+ * 获取工具
329
345
  */
330
- multiInstance?: boolean;
346
+ get(name: string): AITool | null;
331
347
  /**
332
- * 是否需要后台运行
333
- * @description 如果为 true,即使 UI 不可见,插件也不会被卸载
348
+ * 列出所有工具
334
349
  */
335
- background?: boolean;
336
- [key: string]: boolean | undefined;
337
- }
338
- /**
339
- * 存储项数据结构定义 (Schema)
340
- */
341
- interface StorageItemSchema {
342
- /** 存储键名 */
343
- key: string;
344
- /** 数据类型 */
345
- type: 'string' | 'number' | 'boolean' | 'object' | 'array';
346
- /** 默认值 */
347
- default?: any;
348
- /** 描述信息 */
349
- description?: string;
350
+ list(): AITool[];
350
351
  /**
351
- * 作用域
352
- * @description 'plugin' 表示仅当前插件可见(带插件 ID 前缀),'shared' 表示全局共享
353
- */
354
- scope?: 'plugin' | 'shared';
355
- }
356
- /**
357
- * 插件存储接口
358
- * @description 包含私有存储和共享存储访问能力
359
- */
360
- interface PluginStorage extends TypedStorage {
361
- /** 获取插件私有存储数据 */
362
- get: TypedStorage['get'];
363
- /** 设置插件私有存储数据 */
364
- set: TypedStorage['set'];
365
- /** 移除插件私有存储数据 */
366
- remove: TypedStorage['remove'];
367
- /** 全局共享存储访问 */
368
- shared: TypedStorage & {
369
- /** 获取全局共享存储数据 */
370
- get: TypedStorage['get'];
371
- /** 设置全局共享存储数据 */
372
- set: TypedStorage['set'];
373
- /** 移除全局共享存储数据 */
374
- remove: TypedStorage['remove'];
375
- };
352
+ * 执行工具
353
+ */
354
+ execute(name: string, args: Record<string, unknown>): Promise<unknown>;
376
355
  }
356
+
377
357
  /**
378
- * 插件生命周期 Hooks
379
- * @description 插件可以在不同的生命周期阶段执行特定的逻辑
358
+ * Mock AI Provider
359
+ * 用于演示和测试环境,返回预设的智能回复
380
360
  */
381
- interface PluginLifecycle {
382
- /**
383
- * 插件加载时调用
384
- * @description 在插件被扫描并注入内核时触发。用于初始化内部状态、注册服务、设置拦截器等。此时 UI 尚未挂载。
385
- * @param context - 插件上下文对象,提供核心能力的访问
386
- */
387
- onLoad?: (context: PluginContext) => void | Promise<void>;
361
+ declare class MockAIProvider implements AIProvider {
362
+ private responses;
388
363
  /**
389
- * 插件挂载到 UI 时调用
390
- * @description 当插件的 UI 组件(如有)被 React 挂载到 DOM 时触发。
391
- * @param context - 插件上下文对象
364
+ * 生成回复
392
365
  */
393
- onMount?: (context: PluginContext) => void;
366
+ private generateResponse;
394
367
  /**
395
- * 插件从 UI 卸载时调用
396
- * @description 当插件的 UI 组件被销毁时触发。用于清理定时器、取消订阅等。
397
- * @param context - 插件上下文对象
368
+ * 生成唯一 ID
398
369
  */
399
- onUnmount?: (context: PluginContext) => void;
370
+ private generateId;
400
371
  /**
401
- * 插件配置发生变化时调用
402
- * @description 当用户通过配置中心修改插件设置时触发。
403
- * @param newConfig - 变更后的新配置对象
404
- * @param oldConfig - 变更前的旧配置对象
372
+ * 聊天(非流式)
405
373
  */
406
- onConfigChange?: (newConfig: any, oldConfig: any) => void;
407
- }
408
- /**
409
- * 插件上下文
410
- * @description 传递给插件生命周期钩子的核心对象,是插件访问宿主环境能力的唯一入口。
411
- */
412
- interface PluginContext {
413
- /** 当前插件的唯一标识符 */
414
- pluginId: string;
415
- /** API 请求能力入口 */
416
- api: any;
417
- /** 事件总线能力入口 */
418
- events: EventBusPort;
419
- /** 存储管理能力入口 */
420
- storage: PluginStorage;
421
- /** 日志输出工具,自动携带插件 ID 前缀 */
422
- logger: {
423
- debug: (...args: any[]) => void;
424
- info: (...args: any[]) => void;
425
- warn: (...args: any[]) => void;
426
- error: (...args: any[]) => void;
427
- };
374
+ chat(messages: AIMessage[], options?: ChatOptions): Promise<AIMessage>;
428
375
  /**
429
- * 访问其他插件提供的服务
430
- * @param serviceName - 服务注册名称
431
- * @returns 服务实例,如果不存在则返回 undefined
376
+ * 流式响应
432
377
  */
433
- getService: <T = any>(serviceName: string) => T | undefined;
378
+ stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable<AIChunk>;
434
379
  /**
435
- * 注册当前插件的服务供他人使用
436
- * @param serviceName - 唯一服务名称
437
- * @param service - 服务实现对象
380
+ * 函数调用
438
381
  */
439
- registerService: (serviceName: string, service: any) => void;
440
- /** 宿主环境 Window 的代理对象 (用于沙箱隔离) */
441
- window: WindowProxy;
382
+ functionCall(messages: AIMessage[], tools: AITool[], options?: ChatOptions): Promise<FunctionCallResult>;
442
383
  }
384
+
443
385
  /**
444
- * 完整的插件对象定义
386
+ * OpenAI Provider 实现
387
+ * 支持 chat、stream、functionCall 方法
445
388
  */
446
- interface Plugin extends PluginLifecycle {
447
- /**
448
- * 插件唯一标识符
449
- * @description 必须与 metadata.id 一致,通常为只读。
450
- */
451
- readonly id: string;
452
- /** 插件元数据配置 */
453
- metadata: PluginMetadata;
454
- /** 插件提供的功能组件集合 (可选) */
455
- components?: Record<string, React.ComponentType<any>>;
456
- /** 插件提供的工具函数集合 (可选) */
457
- utils?: Record<string, any>;
458
- /** 插件的初始默认配置 (可选) */
459
- defaultConfig?: Record<string, any>;
389
+ declare class OpenAIProvider implements AIProvider {
390
+ private client;
391
+ private defaultOptions;
392
+ constructor(apiKey: string, defaultOptions?: ChatOptions);
393
+ chat(messages: AIMessage[], options?: ChatOptions): Promise<AIMessage>;
394
+ stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable<AIChunk>;
395
+ functionCall(messages: AIMessage[], tools: AITool[], options?: ChatOptions): Promise<FunctionCallResult>;
396
+ private toOpenAIMessages;
397
+ private toOpenAITools;
398
+ private fromOpenAIMessage;
399
+ private fromOpenAIToolCall;
460
400
  }
461
- /**
462
- * 插件基础类
463
- * @deprecated 建议统一使用工厂模式 definePlugin() 定义插件,以消除类与对象定义的歧义。
464
- * @description 解决插件定义时 id 与 metadata.id 重复定义的问题,并提供基础生命周期管理
465
- */
466
- declare abstract class BasePlugin implements Plugin {
467
- abstract metadata: PluginMetadata;
468
- /**
469
- * 插件 ID
470
- * @description 自动从 metadata.id 获取
471
- */
472
- get id(): string;
473
- onLoad?(context: PluginContext): void | Promise<void>;
474
- onMount?(context: PluginContext): void;
475
- onUnmount?(context: PluginContext): void;
476
- onConfigChange?(newConfig: any, oldConfig: any): void;
401
+
402
+ interface SessionStorage {
403
+ save(sessions: Session[]): void;
404
+ load(): Session[];
477
405
  }
406
+ interface SessionManagerInterface {
407
+ createSession(name?: string): Session;
408
+ getSession(id: string): Session | null;
409
+ listSessions(): Session[];
410
+ deleteSession(id: string): void;
411
+ addMessage(sessionId: string, message: AIMessage): void;
412
+ clearMessages(sessionId: string): void;
413
+ }
414
+
478
415
  /**
479
- * 辅助函数:定义插件并自动从 metadata.id 注入顶级 id
480
- * @description 解决插件定义时 id 与 metadata.id 重复定义的问题,提高代码优雅度
481
- * @param plugin 插件定义(不包含顶级 id)
482
- * @returns 完整的插件对象
483
- */
484
- declare function definePlugin(plugin: Omit<Plugin, 'id'>): Plugin;
416
+ * 会话管理器
417
+ * 提供会话的创建、查询、删除、消息管理等功能
418
+ */
419
+ declare class SessionManager implements SessionManagerInterface {
420
+ private sessions;
421
+ private storage?;
422
+ constructor(storage?: SessionStorage);
423
+ createSession(name?: string): Session;
424
+ getSession(id: string): Session | null;
425
+ listSessions(): Session[];
426
+ deleteSession(id: string): void;
427
+ addMessage(sessionId: string, message: AIMessage): void;
428
+ clearMessages(sessionId: string): void;
429
+ private loadFromStorage;
430
+ private saveToStorage;
431
+ }
432
+
485
433
  /**
486
- * 插件元数据定义
487
- * @description 描述插件的静态属性,用于插件市场展示、权限校验和内核加载参考。
434
+ * LocalStorage 适配器,用于会话持久化
435
+ * 注意:仅在浏览器环境可用
488
436
  */
489
- interface PluginMetadata {
490
- /** 插件唯一 ID (推荐反向域名格式,如 com.company.plugin) */
491
- id: string;
492
- /** 插件显示名称 */
493
- name: string;
494
- /** 插件版本号 (符合 SemVer 规范) */
495
- version: string;
496
- /** 插件类型 */
497
- type: PluginType;
498
- /** 插件功能描述 */
499
- description?: string;
500
- /** 插件作者信息 */
501
- author?: string;
502
- /** 插件图标 (React 组件或图标名称) */
503
- icon?: React.ReactNode;
504
- /** 插件依赖的其他插件 ID 列表 */
505
- dependencies?: string[];
506
- /** 路由配置集合,用于在主应用中注册页面 */
507
- routes?: RouteConfig[];
508
- /** 插槽扩展集合,用于在主应用 UI 预留位注入组件 */
509
- extensions?: PluginExtension[];
510
- /** 插件所需调用的 API 接口配置 */
511
- api?: ApiConfig;
512
- /** 插件行为能力声明 */
513
- capabilities?: PluginCapabilities;
514
- /** 插件的可配置项定义 */
515
- configuration?: PluginConfigItem[];
516
- /** 插件所需的存储结构定义 */
517
- storage?: StorageItemSchema[];
518
- /**
519
- * 系统状态自动绑定
520
- * @description 将插件的配置项自动同步到系统的全局状态中 (如主题色、身份认证等)
521
- */
522
- systemStateBindings?: {
523
- /** 插件配置中的键名 */
524
- configKey: string;
525
- /** 系统全局状态中的键名 */
526
- stateKey: string;
527
- /** 预设的转换逻辑名称 */
528
- transform?: 'theme-mode' | 'identity';
529
- }[];
437
+ declare class SessionLocalStorageAdapter implements SessionStorage {
438
+ save(sessions: Session[]): void;
439
+ load(): Session[];
530
440
  }
531
441
 
442
+ interface AIState {
443
+ provider: AIProvider | null;
444
+ setProvider: (provider: AIProvider) => void;
445
+ sessions: Session[];
446
+ currentSessionId: string | null;
447
+ sessionManager: SessionManager;
448
+ toolRegistry: ToolRegistry;
449
+ createSession: (name?: string) => Session;
450
+ selectSession: (id: string) => void;
451
+ deleteSession: (id: string) => void;
452
+ addMessage: (message: AIMessage) => void;
453
+ registerTool: (tool: AITool) => void;
454
+ unregisterTool: (name: string) => void;
455
+ sendMessage: (content: string) => Promise<void>;
456
+ clearCurrentSession: () => void;
457
+ streamMessage: (content: string, onChunk: (chunk: string) => void) => Promise<void>;
458
+ }
459
+ declare const aiStore: zustand_vanilla.StoreApi<AIState>;
460
+ declare function createAIStore(apiKey: string, defaultModel?: string): void;
461
+
532
462
  /**
533
- * 基于 Axios 的默认请求适配器
463
+ * 插件注册表接口
464
+ * @description 键为插件 ID,值为一个返回插件定义的异步加载函数。
534
465
  */
535
- declare class AxiosAdapter implements ApiAdapter {
536
- private client;
537
- constructor(baseURL?: string, timeout?: number);
538
- request<T = any>(config: ApiRequestConfig): Promise<T>;
539
- stream(config: ApiRequestConfig, callbacks: StreamCallbacks, _endpointConfig?: ApiEndpointConfig): Promise<void>;
466
+ interface PluginRegistry {
467
+ [pluginId: string]: () => Promise<any>;
540
468
  }
541
-
542
469
  /**
543
- * API 引擎核心类
544
- * @description 负责加载配置并执行请求,支持策略模式切换底层请求实现
470
+ * 插件自动发现规则
545
471
  */
546
- declare class ApiEngine {
547
- private adapter;
548
- private config;
549
- private interceptors;
550
- constructor(adapter?: ApiAdapter);
551
- /**
552
- * 注册拦截器
553
- */
554
- registerInterceptor(interceptor: ApiInterceptor): void;
555
- /**
556
- * 移除拦截器
557
- */
558
- unregisterInterceptor(interceptor: ApiInterceptor): void;
559
- /**
560
- * 切换请求适配器
561
- * @param adapter 新的适配器实例
562
- */
563
- useAdapter(adapter: ApiAdapter): void;
564
- /**
565
- * 注册 API 配置
566
- * @param config 配置对象
567
- */
568
- register(config: ApiConfig): void;
569
- /**
570
- * 获取接口配置
571
- */
572
- getEndpoint(module: string, action: string): ApiEndpointConfig | undefined;
573
- /**
574
- * 发起 API 请求
575
- * @param module 模块名
576
- * @param action 动作名
577
- * @param data 请求数据 (Body 或 Query)
578
- * @param options 请求选项
579
- */
580
- call<T = any>(module: string, action: string, data?: any, options?: RequestOptions): Promise<T>;
581
- /**
582
- * 发起流式请求
583
- * @param module 模块名
584
- * @param action 动作名
585
- * @param data 请求数据
586
- * @param options 请求选项
587
- */
588
- stream(module: string, action: string, data?: any, options?: RequestOptions): Promise<void>;
472
+ interface DiscoveryRule {
589
473
  /**
590
- * 准备请求配置,应用 URL 参数替换和请求拦截器
474
+ * 路径匹配标识。
475
+ * @example 'plugins' 或 '@chatbi-plugins'
591
476
  */
592
- private prepareRequestConfig;
477
+ pathSegment: string;
593
478
  /**
594
- * 应用所有请求拦截器
479
+ * 生成插件 ID 时的前缀。
480
+ * @example '@chatbi-v/plugin',最终生成如 '@chatbi-v/plugin-demo'
595
481
  */
596
- private applyRequestInterceptors;
597
- /**
598
- * 应用所有响应拦截器
599
- * @returns 是否被劫持
482
+ idPrefix: string;
483
+ }
484
+ /**
485
+ * 解析插件注册表
486
+ * @description 核心逻辑:将 Vite 的 `import.meta.glob` 结果映射为标准的插件注册表。
487
+ * 它会根据预定义的路径匹配规则,从文件路径中提取插件目录名,并拼接前缀生成唯一的插件 ID。
488
+ *
489
+ * @param options - 包含待处理模块和匹配规则的选项对象
490
+ * @returns 解析后的 PluginRegistry 对象
491
+ */
492
+ declare const resolvePluginRegistry: (options: {
493
+ /** 原始模块映射 (来自 Vite glob) */
494
+ modules: Record<string, () => Promise<any>>;
495
+ /** 自定义发现规则 (可选) */
496
+ rules?: DiscoveryRule[];
497
+ }) => PluginRegistry;
498
+
499
+ /**
500
+ * 日志等级枚举
501
+ */
502
+ declare enum LogLevel {
503
+ /** 调试级别:输出最详尽的信息 */
504
+ DEBUG = 0,
505
+ /** 信息级别:输出重要的运行状态 */
506
+ INFO = 1,
507
+ /** 警告级别:输出潜在的问题,但不影响运行 */
508
+ WARN = 2,
509
+ /** 错误级别:输出严重的运行异常 */
510
+ ERROR = 3,
511
+ /** 禁用日志:不输出任何信息 */
512
+ NONE = 4
513
+ }
514
+ /**
515
+ * 日志工具类
516
+ * @description 核心工具类,提供统一的日志输出格式 `[Prefix] Message`。
517
+ * 支持通过 `LogLevel` 进行全局过滤。
518
+ * 支持日志缓冲和自动分组,以减少控制台噪音。
519
+ * 支持浏览器端 CSS 样式和 Node.js 端 ANSI 颜色。
520
+ */
521
+ declare class Logger {
522
+ /** 全局静态日志等级,所有实例共享 */
523
+ private static level;
524
+ /** 日志缓冲区 */
525
+ private static buffer;
526
+ /** 缓冲输出防抖定时器 */
527
+ private static flushTimer;
528
+ /** 缓冲时间窗口 (ms) */
529
+ private static FLUSH_INTERVAL;
530
+ /** 是否启用缓冲模式 */
531
+ private static bufferEnabled;
532
+ /** 是否为浏览器环境 */
533
+ private static isBrowser;
534
+ /** 当前实例的业务模块前缀 */
535
+ private prefix;
536
+ /** 实例特定的颜色 */
537
+ private color;
538
+ /**
539
+ * 构造函数
540
+ * @param prefix - 业务模块前缀,默认为 'App'
600
541
  */
601
- private applyResponseInterceptors;
542
+ constructor(prefix?: string);
602
543
  /**
603
- * 检查 HTTP 状态码
544
+ * 静态方法:设置全局日志输出等级
545
+ * @param level - 目标日志等级
604
546
  */
605
- private checkHttpStatus;
547
+ static setLevel(level: LogLevel): void;
606
548
  /**
607
- * 提取响应数据
549
+ * 静态方法:启用或禁用日志缓冲
550
+ * @param enabled - 是否启用
608
551
  */
609
- private extractResponseData;
552
+ static setBufferEnabled(enabled: boolean): void;
610
553
  /**
611
- * 处理业务错误
554
+ * 静态方法:获取当前全局日志等级
555
+ * @returns 当前生效的全局日志等级
612
556
  */
613
- private handleBusinessError;
557
+ static getLevel(): LogLevel;
614
558
  /**
615
- * 判断是否为 BaseResponse
559
+ * 格式化输出前缀
616
560
  */
617
- private isBaseResponse;
561
+ private getFormattedPrefix;
618
562
  /**
619
- * 严格判断是否为 AxiosResponse
563
+ * 生成分组标题参数
620
564
  */
621
- private isAxiosResponse;
565
+ private static getGroupTitleArgs;
622
566
  /**
623
- * 创建拦截上下文
567
+ * 内部方法:将日志推入缓冲区或直接输出
624
568
  */
625
- private createInterceptorContext;
569
+ private log;
570
+ /**
571
+ * 静态方法:刷新缓冲区,分组输出日志
572
+ */
573
+ static flush(): void;
574
+ /**
575
+ * 打印 DEBUG 级别日志
576
+ */
577
+ debug(...args: any[]): void;
578
+ /**
579
+ * 打印 INFO 级别日志
580
+ */
581
+ info(...args: any[]): void;
582
+ /**
583
+ * 打印 WARN 级别日志
584
+ */
585
+ warn(...args: any[]): void;
586
+ /**
587
+ * 打印 ERROR 级别日志
588
+ */
589
+ error(...args: any[]): void;
590
+ /**
591
+ * 开始一个日志控制台分组
592
+ */
593
+ group(label: string, collapsed?: boolean): void;
594
+ /**
595
+ * 结束当前日志控制台分组
596
+ */
597
+ groupEnd(): void;
626
598
  }
627
- declare const apiEngine: ApiEngine;
599
+ /** 默认 Logger 实例 */
600
+ declare const logger: Logger;
601
+ /**
602
+ * 创建带特定前缀的 Logger 实例
603
+ * @param prefix 日志前缀
604
+ * @returns Logger 实例
605
+ */
606
+ declare const createLogger: (prefix: string) => Logger;
628
607
 
629
608
  /**
630
- * 自动检测是否处于 Mock 模式
609
+ * @file errors.ts
610
+ * @description Core 层统一错误处理定义
631
611
  */
632
- declare function isMockMode(): boolean;
612
+
633
613
  /**
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
614
+ * 核心错误码枚举
615
+ */
616
+ declare enum CoreErrorCode {
617
+ UNKNOWN = "1000",
618
+ NOT_FOUND = "1001",
619
+ INVALID_PARAMS = "1002",
620
+ TIMEOUT = "1003",
621
+ PLUGIN_NOT_FOUND = "2001",
622
+ PLUGIN_LOAD_FAILED = "2002",
623
+ PLUGIN_MOUNT_FAILED = "2003",
624
+ PLUGIN_UNMOUNT_FAILED = "2004",
625
+ PLUGIN_DEPENDENCY_MISSING = "2005",
626
+ PLUGIN_CIRCULAR_DEPENDENCY = "2006",
627
+ PLUGIN_INIT_FAILED = "2007",
628
+ STORAGE_READ_FAILED = "3001",
629
+ STORAGE_WRITE_FAILED = "3002",
630
+ STORAGE_SCHEMA_VIOLATION = "3003",
631
+ STORAGE_QUOTA_EXCEEDED = "3004",
632
+ API_REQUEST_FAILED = "4001",
633
+ API_RESPONSE_INVALID = "4002",
634
+ API_NETWORK_ERROR = "4003",
635
+ API_TIMEOUT = "4004",
636
+ API_UNAUTHORIZED = "4005",
637
+ SANDBOX_EVAL_FAILED = "5001",
638
+ SANDBOX_ISOLATION_BREACHED = "5002",
639
+ SANDBOX_MEMORY_LIMIT = "5003",
640
+ SERVICE_NOT_FOUND = "6001",
641
+ SERVICE_REGISTER_FAILED = "6002",
642
+ SERVICE_WAIT_TIMEOUT = "6003"
643
+ }
644
+ /**
645
+ * 错误处理策略
640
646
  */
641
- declare function resolveApiModules(definitionsMap: Record<string, any>, mocksMap?: Record<string, any>): ApiConfig;
647
+ declare enum CoreErrorStrategy {
648
+ THROW = "throw",// 抛出异常
649
+ RESOLVE = "resolve",// 返回默认值
650
+ REJECT = "reject",// 返回 Promise reject
651
+ SILENT = "silent"
652
+ }
653
+ /**
654
+ * 错误处理选项
655
+ */
656
+ interface ErrorHandlerOptions {
657
+ code: CoreErrorCode;
658
+ strategy: CoreErrorStrategy;
659
+ defaultValue?: any;
660
+ logger?: ReturnType<typeof createLogger>;
661
+ context?: Record<string, any>;
662
+ }
663
+ /**
664
+ * 核心错误类
665
+ */
666
+ declare class CoreError extends Error {
667
+ readonly code: CoreErrorCode;
668
+ readonly originalError?: Error;
669
+ readonly context?: Record<string, any>;
670
+ constructor(code: CoreErrorCode, message: string, originalError?: Error, context?: Record<string, any>);
671
+ }
672
+ /**
673
+ * 统一错误处理函数
674
+ */
675
+ declare function handleError(error: unknown, options: ErrorHandlerOptions): any;
642
676
 
643
677
  /**
644
678
  * 成功状态码
@@ -683,254 +717,444 @@ interface Scene {
683
717
  cover?: string;
684
718
  }
685
719
 
686
- interface ApiProviderProps {
687
- api: ApiEngine;
688
- children: React.ReactNode;
720
+ /**
721
+ * @file performance/types.ts
722
+ * @description 性能监测数据类型定义
723
+ * @author ChatBI Team
724
+ */
725
+ /**
726
+ * 插件生命周期阶段
727
+ */
728
+ type LifecyclePhase = 'load' | 'mount' | 'unmount';
729
+ /**
730
+ * 生命周期性能指标
731
+ * 记录插件 load/mount/unmount 阶段的执行耗时
732
+ */
733
+ interface LifecycleMetric {
734
+ /** 插件 ID */
735
+ pluginId: string;
736
+ /** 生命周期阶段 */
737
+ phase: LifecyclePhase;
738
+ /** 执行耗时(毫秒) */
739
+ duration: number;
740
+ /** 时间戳 */
741
+ timestamp: number;
742
+ /** 是否成功 */
743
+ success: boolean;
744
+ /** 错误信息(仅在 success 为 false 时存在) */
745
+ error?: string;
746
+ }
747
+ /**
748
+ * 运行时性能指标
749
+ * 记录插件运行期间的内存、帧率等数据
750
+ */
751
+ interface RuntimeMetric {
752
+ /** 插件 ID */
753
+ pluginId: string;
754
+ /** 时间戳 */
755
+ timestamp: number;
756
+ /** 内存使用量(字节) */
757
+ memory?: number;
758
+ /** 帧率 */
759
+ fps?: number;
760
+ /** API 调用次数 */
761
+ apiCalls?: number;
762
+ }
763
+ /**
764
+ * 性能数据集合
765
+ */
766
+ interface PerformanceData {
767
+ /** 生命周期指标集合 */
768
+ lifecycle: LifecycleMetric[];
769
+ /** 运行时采样数据集合 */
770
+ samples: RuntimeMetric[];
771
+ }
772
+ /**
773
+ * 性能监测配置
774
+ */
775
+ interface PerformanceSettings {
776
+ /** 生命周期记录最大条数(默认 1000) */
777
+ maxLifecycleRecords: number;
778
+ /** 运行时采样最大条数(默认 500) */
779
+ maxRuntimeSamples: number;
780
+ /** 采样率(0-1 之间) */
781
+ sampleRate: number;
689
782
  }
690
- declare const ApiProvider: React.FC<ApiProviderProps>;
691
- declare const useApi: () => ApiEngine;
783
+ /**
784
+ * 默认性能监测配置
785
+ */
786
+ declare const DEFAULT_PERFORMANCE_SETTINGS: PerformanceSettings;
692
787
 
693
788
  /**
694
- * 服务注册中心 (Service Registry)
695
- * @description 核心应用层服务,作为微内核架构中的“中枢调度员”。
696
- * 主要职责:
697
- * 1. 服务解耦:允许插件将其内部功能暴露为“服务”,而无需与其他插件产生物理依赖。
698
- * 2. 动态发现:提供按名称查找服务的能力,支持服务热插拔。
699
- * 3. 依赖协调:通过 `waitFor` 机制解决插件间由于加载顺序导致的初始化依赖问题。
700
- *
701
- * 建议的服务命名规范: `pluginId.serviceName` (例如: `auth.sessionService`)
789
+ * 核心领域服务:存储管理器
790
+ * @description 统一管理应用内所有的持久化存储资源。
791
+ * 核心功能:
792
+ * 1. 作用域隔离:通过前缀划分 `plugin`、`shared` 和 `system` 三个层级的存储空间。
793
+ * 2. Schema 校验:支持注册存储描述,规范数据存取,避免键名冲突。
794
+ * 3. 默认值与配置回退:支持从 Schema 默认值或 ConfigManager 中回退取值。
795
+ * 4. LRU 缓存:使用 LRU 策略管理内存缓存,防止无限增长。
702
796
  */
703
- declare class ServiceRegistry {
704
- /** 存储已注册服务的 Map 对象 */
705
- private services;
706
- /** 存储正在等待特定服务的监听器集合 */
707
- private listeners;
797
+ declare class StorageManager {
798
+ /** 底层物理存储驱动 */
799
+ private baseStorage;
800
+ /** 插件 ID 与存储描述定义的映射关系 */
801
+ private schemas;
802
+ /** LRU 内存缓存,减少 JSON 序列化和物理 IO 开销 */
803
+ private memoryCache;
708
804
  /**
709
- * 注册一个服务实现
710
- * @param name - 唯一的服务名称
711
- * @param service - 服务实例或对象
805
+ * 初始化存储管理器
806
+ * @param baseStorage - 符合 StoragePort 接口的物理存储驱动(如 LocalStorageAdapter)
712
807
  */
713
- register(name: string, service: any): void;
808
+ constructor(baseStorage: StoragePort);
714
809
  /**
715
- * 同步获取服务实例
716
- * @template T - 服务类型的泛型
717
- * @param name - 服务名称
718
- * @returns 服务实例,若不存在则返回 undefined
810
+ * 注册插件的存储 Schema
811
+ * @param pluginId - 插件 ID
812
+ * @param schema - 存储项定义列表
719
813
  */
720
- get<T = any>(name: string): T | undefined;
814
+ registerSchema(pluginId: string, schema: StorageItemSchema[]): void;
721
815
  /**
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} 若在规定时间内服务未注册,则抛出超时异常。
816
+ * 删除插件的所有存储数据
817
+ * @description 包括插件私有存储、上下文存储、注册 Schema 及内存缓存
818
+ * @param pluginId - 插件 ID
731
819
  */
732
- waitFor<T = any>(name: string, timeout?: number): Promise<T>;
820
+ deletePluginStorage(pluginId: string): void;
733
821
  /**
734
- * 检查服务是否已注册
735
- * @param name - 服务名称
822
+ * 内部校验方法:检查键名是否在 Schema 中声明
823
+ * @param pluginId - 插件 ID
824
+ * @param key - 待校验的键名
825
+ * @param scope - 目标作用域
736
826
  */
737
- has(name: string): boolean;
827
+ private validateKey;
738
828
  /**
739
- * 注销特定的服务
740
- * @param name - 服务名称
829
+ * 获取插件私有存储适配器
830
+ * @param pluginId - 插件 ID
831
+ * @returns 自动添加 `plugin:{id}:` 前缀的存储接口
741
832
  */
742
- unregister(name: string): void;
833
+ getPluginStorage(pluginId: string): StoragePort;
743
834
  /**
744
- * 清除所有已注册的服务和监听器
745
- * @description 通常仅在系统重置或大型热更新时使用。
835
+ * 获取全局共享存储适配器
836
+ * @returns 自动添加 `shared:` 前缀的存储接口
746
837
  */
747
- clear(): void;
748
- }
749
- declare const serviceRegistry: ServiceRegistry;
750
-
751
- /**
752
- * 配置管理器
753
- * @description 核心工具类,负责管理应用的全局系统配置以及各插件的初始化业务配置。
754
- * 配置数据通常在应用启动时通过 `usePluginLoader` 注入,并作为插件运行时的取值回退来源。
755
- */
756
- declare class ConfigManager {
757
- /** 内部存储配置的 Map 对象 */
758
- private config;
838
+ getSharedStorage(): StoragePort;
759
839
  /**
760
- * 设置特定的配置项
761
- * @param key - 配置键名(如 'system' 或插件 ID)
762
- * @param value - 配置内容对象
840
+ * 获取系统内部存储适配器
841
+ * @returns 自动添加 `system:` 前缀的存储接口
763
842
  */
764
- set(key: string, value: any): void;
843
+ getSystemStorage(): StoragePort;
765
844
  /**
766
- * 获取指定的配置项
767
- * @param key - 配置键名
768
- * @returns 配置内容,若不存在则返回 undefined
845
+ * 创建插件沙箱使用的复合存储对象
846
+ * @description 返回的对象封装了对私有存储和共享存储的操作。
847
+ * 特性:
848
+ * - 内存级 LRU 缓存:极大提升高频读写性能。
849
+ * - 自动序列化/反序列化 JSON。
850
+ * - 自动校验 Schema。
851
+ * - 取值回退逻辑:持久化存储 -> ConfigManager -> Schema 默认值。
852
+ *
853
+ * @param pluginId - 插件 ID
854
+ * @returns 包含 get/set/remove 及 shared 子对象的复合接口
769
855
  */
770
- get(key: string): any;
856
+ getContextStorage(pluginId: string): {
857
+ shared: {
858
+ get: <T = any>(key: string) => T | null;
859
+ set: <T = any>(key: string, value: T) => void;
860
+ remove: (key: string) => void;
861
+ };
862
+ get: <T = any>(key: string) => T | null;
863
+ set: <T = any>(key: string, value: T) => void;
864
+ remove: (key: string) => void;
865
+ };
866
+ }
867
+
868
+ /**
869
+ * 性能数据存储层
870
+ * @description 负责性能数据的持久化,支持生命周期指标和运行时采样数据的存储与查询
871
+ */
872
+ declare class PerformanceStorage {
873
+ private storageManager;
874
+ private systemStorage;
875
+ private settings;
876
+ private lifecycleCache;
877
+ private runtimeCache;
878
+ private readonly LIFECYCLE_KEY;
879
+ private readonly RUNTIME_KEY;
771
880
  /**
772
- * 批量合并配置对象
773
- * @description 对顶层属性进行浅合并,若属性值为对象则进行一层深度的合并。
774
- * @param config - 待合并的配置对象映射
881
+ * 构造函数
882
+ * @param storageManager - 存储管理器实例
883
+ * @param settings - 性能设置(可选,默认使用 DEFAULT_PERFORMANCE_SETTINGS)
775
884
  */
776
- merge(config: Record<string, any>): void;
885
+ constructor(storageManager: StorageManager, settings?: PerformanceSettings);
777
886
  /**
778
- * 获取当前存储的所有配置快照
779
- * @returns 包含所有配置的普通对象
887
+ * 从持久化存储加载数据到内存缓存
780
888
  */
781
- getAll(): Record<string, any>;
782
- }
783
- /** 全局配置管理器单例 */
784
- declare const configManager: ConfigManager;
785
-
786
- /** 插件错误边界组件属性 */
787
- interface Props {
788
- /** 发生错误的插件 ID */
789
- pluginId?: string;
790
- /** 错误发生时的降级 UI */
791
- fallback?: ReactNode;
792
- /** 子组件内容 */
793
- children: ReactNode;
794
- /** 是否静默模式,开启后不显示任何错误 UI,仅记录日志 */
795
- silent?: boolean;
796
- }
797
- /** 插件错误边界组件状态 */
798
- interface State {
799
- /** 是否捕获到错误 */
800
- hasError: boolean;
801
- /** 捕获到的错误对象 */
802
- error: Error | null;
803
- }
804
- /**
805
- * 插件错误边界组件
806
- * @description 核心组件,用于捕获子组件渲染过程中的 JavaScript 错误,记录日志并显示降级 UI。
807
- * 确保单个插件的运行异常不会导致整个主应用或其他插件崩溃。
808
- */
809
- declare class PluginErrorBoundary extends Component<Props, State> {
810
- constructor(props: Props);
811
- /**
812
- * 从错误中派生状态
813
- * @param error - 捕获到的错误
814
- */
815
- static getDerivedStateFromError(error: any): State;
816
- /**
817
- * 捕获到错误后的回调
818
- * @param error - 错误对象
819
- * @param errorInfo - 错误堆栈信息
889
+ private loadFromStorage;
890
+ /**
891
+ * 保存生命周期指标
892
+ * @param metric - 生命周期指标
820
893
  */
821
- componentDidCatch(error: any, errorInfo: ErrorInfo): void;
894
+ saveLifecycleMetric(metric: LifecycleMetric): void;
822
895
  /**
823
- * 重置错误状态,尝试重新渲染
896
+ * 保存运行时指标
897
+ * @param metric - 运行时指标
824
898
  */
825
- handleRetry: () => void;
826
- render(): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined;
827
- }
828
-
829
- /** 插件插槽组件属性 */
830
- interface PluginSlotProps {
831
- /** 插槽位置标识,决定渲染哪些插件扩展 */
832
- slot: SlotPosition;
833
- /** 传递给扩展组件的 Props 对象 */
834
- props?: Record<string, any>;
835
- /** 自定义容器类名 (Tailwind CSS) */
836
- className?: string;
837
- /** 自定义容器内联样式 */
838
- style?: React.CSSProperties;
839
- /**
840
- * 自定义渲染函数
841
- * @param item - 包含 key、组件和扩展元信息的对象
842
- * @param index - 索引位置
899
+ saveRuntimeMetric(metric: RuntimeMetric): void;
900
+ /**
901
+ * 保存指标(通用方法,自动识别类型)
902
+ * @param metric - 指标数据
903
+ */
904
+ saveMetric(metric: LifecycleMetric | RuntimeMetric): void;
905
+ /**
906
+ * 强制执行生命周期数据上限(FIFO)
907
+ */
908
+ private enforceLifecycleLimit;
909
+ /**
910
+ * 强制执行运行时数据上限(FIFO)
911
+ */
912
+ private enforceRuntimeLimit;
913
+ /**
914
+ * 持久化生命周期数据
915
+ */
916
+ private persistLifecycle;
917
+ /**
918
+ * 持久化运行时数据
919
+ */
920
+ private persistRuntime;
921
+ /**
922
+ * 获取生命周期指标
923
+ * @param pluginId - 插件 ID(可选,不传则返回所有)
924
+ */
925
+ getLifecycleMetrics(pluginId?: string): LifecycleMetric[];
926
+ /**
927
+ * 获取运行时指标
928
+ * @param pluginId - 插件 ID(可选,不传则返回所有)
929
+ */
930
+ getRuntimeMetrics(pluginId?: string): RuntimeMetric[];
931
+ /**
932
+ * 清除性能数据
933
+ * @param pluginId - 插件 ID(可选,不传则清除所有)
934
+ */
935
+ clearMetrics(pluginId?: string): void;
936
+ /**
937
+ * 获取所有性能数据
938
+ */
939
+ getAllData(): PerformanceData;
940
+ /**
941
+ * 获取指定插件的性能数据
843
942
  */
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;
943
+ getPluginData(pluginId: string): PerformanceData;
853
944
  }
854
- /**
855
- * 插件插槽组件
856
- * @description UI 层的核心组件,用于在应用中声明一个“插槽”。
857
- * 它会自动根据 slot 标识从 PluginManager 中获取所有注册的插件扩展组件并按顺序渲染。
858
- * 支持订阅插件变更,实现动态热插拔。
859
- */
860
- declare const PluginSlot: React.FC<PluginSlotProps>;
861
945
 
862
946
  /**
863
- * 通用插槽骨架屏组件集合
864
- * @description 提供一组预定义的骨架屏 UI,用于在插件加载或插槽内容未准备好时提供更好的用户体验。
865
- */
866
- /**
867
- * 侧边栏图标骨架屏
868
- * @param expanded - 是否处于展开状态
869
- */
870
- declare const SidebarIconSkeleton: React.FC<{
871
- expanded?: boolean;
872
- }>;
873
- /**
874
- * 状态栏项骨架屏
875
- */
876
- declare const StatusBarItemSkeleton: React.FC;
877
- /**
878
- * 头像骨架屏
947
+ * 性能计时器
948
+ * @description 用于测量代码块执行耗时,自动计算 duration 并保存到存储
879
949
  */
880
- declare const AvatarSkeleton: React.FC;
950
+ declare class PerformanceTimer {
951
+ private startTime;
952
+ private phase;
953
+ private pluginId;
954
+ private storage;
955
+ /**
956
+ * 构造函数
957
+ * @param phase - 生命周期阶段
958
+ * @param pluginId - 插件 ID
959
+ * @param storage - 性能存储实例
960
+ */
961
+ constructor(phase: LifecyclePhase, pluginId: string, storage: PerformanceStorage);
962
+ /**
963
+ * 开始计时
964
+ */
965
+ start(): void;
966
+ /**
967
+ * 结束计时并保存结果
968
+ * @param success - 是否成功
969
+ * @param error - 错误信息(可选)
970
+ */
971
+ end(success: boolean, error?: string): void;
972
+ }
881
973
  /**
882
- * 通用块级骨架屏
883
- * @param className - 自定义类名
974
+ * 性能数据采集器
975
+ * @description 负责性能数据的采集和记录,提供计时器创建和运行时指标记录功能
884
976
  */
885
- declare const BlockSkeleton: React.FC<{
886
- className?: string;
887
- }>;
977
+ declare class PerformanceCollector {
978
+ private storage;
979
+ /**
980
+ * 构造函数
981
+ * @param storage - 性能存储实例
982
+ */
983
+ constructor(storage: PerformanceStorage);
984
+ /**
985
+ * 开始测量指定生命周期阶段
986
+ * @param phase - 生命周期阶段
987
+ * @param pluginId - 插件 ID
988
+ * @returns PerformanceTimer 实例
989
+ */
990
+ startMeasure(phase: LifecyclePhase, pluginId: string): PerformanceTimer;
991
+ /**
992
+ * 记录运行时指标
993
+ * @param metric - 运行时指标(不包含 timestamp)
994
+ */
995
+ recordRuntimeMetric(metric: Omit<RuntimeMetric, 'timestamp'>): void;
996
+ /**
997
+ * 获取性能指标
998
+ * @param pluginId - 插件 ID(可选,不传则返回所有)
999
+ */
1000
+ getMetrics(pluginId?: string): {
1001
+ lifecycle: LifecycleMetric[];
1002
+ runtime: RuntimeMetric[];
1003
+ };
1004
+ /**
1005
+ * 清除性能数据
1006
+ * @param pluginId - 插件 ID(可选,不传则清除所有)
1007
+ */
1008
+ clearMetrics(pluginId?: string): void;
1009
+ /**
1010
+ * 获取存储实例(供外部使用)
1011
+ */
1012
+ getStorage(): PerformanceStorage;
1013
+ }
1014
+
888
1015
  /**
889
- * 自动根据插槽位置匹配骨架屏
1016
+ * @file plugin-runtime.ts
1017
+ * @description 插件运行时,封装单个插件的生命周期(load/mount/unmount)、沙箱环境和隔离上下文
1018
+ * @author ChatBI Team
890
1019
  */
891
- declare const SlotSkeletons: React.FC<{
892
- slot: string;
893
- expanded?: boolean;
894
- }>;
895
1020
 
896
1021
  /**
897
- * 插件注册表接口
898
- * @description 键为插件 ID,值为一个返回插件定义的异步加载函数。
1022
+ * 插件运行时类
1023
+ * @description 为单个插件提供独立的运行环境,负责管理其生命周期、初始化沙箱环境并组装上下文对象。
899
1024
  */
900
- interface PluginRegistry {
901
- [pluginId: string]: () => Promise<any>;
1025
+ declare class PluginRuntime {
1026
+ /** 插件定义对象 */
1027
+ plugin: Plugin;
1028
+ /** 传递给插件的上下文对象 */
1029
+ context: PluginContext;
1030
+ /** 存储沙箱隔离设施 */
1031
+ private storageSandbox;
1032
+ /** Window/全局对象沙箱隔离设施 */
1033
+ private windowSandbox;
1034
+ /** 是否已完成加载阶段 */
1035
+ private isLoaded;
1036
+ /** 是否已完成挂载阶段 */
1037
+ private isMounted;
1038
+ /** 运行时捕获的错误信息 */
1039
+ private error;
1040
+ /**
1041
+ * 构造函数
1042
+ * @param plugin - 插件定义对象
1043
+ * @param sharedContext - 来自内核的共享上下文资源 (如 API 引擎、事件总线)
1044
+ * @param storageManager - 全局存储管理器
1045
+ */
1046
+ constructor(plugin: Plugin, sharedContext: Record<string, any>, storageManager: StorageManager);
1047
+ /**
1048
+ * 检查插件是否已完成加载
1049
+ */
1050
+ isLoadedStatus(): boolean;
1051
+ /**
1052
+ * 执行插件的加载逻辑 (onLoad)
1053
+ * @description 此阶段会自动注册插件声明的 API 配置,并调用插件的 onLoad 钩子。
1054
+ * 用于执行非 UI 的初始化逻辑,如注册服务、拦截器等。
1055
+ */
1056
+ load(): Promise<void>;
1057
+ /**
1058
+ * 执行插件的挂载逻辑 (onMount)
1059
+ * @description 此阶段会激活 Window 沙箱并调用插件的 onMount 钩子。
1060
+ * 此时插件的 UI 组件(如有)即将或已经进入 DOM。
1061
+ */
1062
+ mount(): Promise<void>;
1063
+ /**
1064
+ * 执行插件的卸载逻辑 (onUnmount)
1065
+ * @description 调用插件的 onUnmount 钩子并停用沙箱。
1066
+ */
1067
+ unmount(): Promise<void>;
1068
+ /**
1069
+ * 彻底销毁插件实例
1070
+ * @description 卸载插件并重置加载状态。
1071
+ */
1072
+ destroy(): Promise<void>;
1073
+ /**
1074
+ * 设置运行时错误 (内部使用)
1075
+ * @internal
1076
+ */
1077
+ _setError(error: Error | null): void;
1078
+ /**
1079
+ * 获取插件运行时错误
1080
+ */
1081
+ getError(): Error | null;
1082
+ /**
1083
+ * 获取插件当前运行状态
1084
+ * @returns 'error' | 'mounted' | 'loaded' | 'initial'
1085
+ */
1086
+ get status(): "error" | "mounted" | "loaded" | "initial";
902
1087
  }
1088
+
903
1089
  /**
904
- * 插件自动发现规则
1090
+ * 生命周期监测器(装饰器模式)
1091
+ * @description 通过代理模式包装 PluginRuntime,在生命周期各阶段自动记录耗时
905
1092
  */
906
- interface DiscoveryRule {
1093
+ declare class LifecycleMonitor {
1094
+ private runtime;
1095
+ private collector;
907
1096
  /**
908
- * 路径匹配标识。
909
- * @example 'plugins' '@chatbi-plugins'
1097
+ * 构造函数
1098
+ * @param runtime - 插件运行时实例
1099
+ * @param collector - 性能采集器实例
910
1100
  */
911
- pathSegment: string;
1101
+ constructor(runtime: PluginRuntime, collector: PerformanceCollector);
912
1102
  /**
913
- * 生成插件 ID 时的前缀。
914
- * @example '@chatbi-v/plugin',最终生成如 '@chatbi-v/plugin-demo'
1103
+ * 包装插件运行时,返回代理对象
1104
+ * @returns 包装后的运行时对象
915
1105
  */
916
- idPrefix: string;
1106
+ wrap(): PluginRuntime;
1107
+ /**
1108
+ * 包装指定方法,在执行前后记录耗时
1109
+ * @param phase - 生命周期阶段
1110
+ * @param originalMethod - 原始方法
1111
+ */
1112
+ private wrapMethod;
917
1113
  }
918
1114
  /**
919
- * 解析插件注册表
920
- * @description 核心逻辑:将 Vite 的 `import.meta.glob` 结果映射为标准的插件注册表。
921
- * 它会根据预定义的路径匹配规则,从文件路径中提取插件目录名,并拼接前缀生成唯一的插件 ID。
922
- *
923
- * @param options - 包含待处理模块和匹配规则的选项对象
924
- * @returns 解析后的 PluginRegistry 对象
1115
+ * 创建生命周期监测器
1116
+ * @param runtime - 插件运行时实例
1117
+ * @param collector - 性能采集器实例
1118
+ * @returns LifecycleMonitor 实例
925
1119
  */
926
- declare const resolvePluginRegistry: (options: {
927
- /** 原始模块映射 (来自 Vite glob) */
928
- modules: Record<string, () => Promise<any>>;
929
- /** 自定义发现规则 (可选) */
930
- rules?: DiscoveryRule[];
931
- }) => PluginRegistry;
1120
+ declare function createLifecycleMonitor(runtime: PluginRuntime, collector: PerformanceCollector): LifecycleMonitor;
1121
+
1122
+ /**
1123
+ * @file performance/index.ts
1124
+ * @description 性能监测模块统一导出
1125
+ * @author ChatBI Team
1126
+ */
1127
+
1128
+ /**
1129
+ * 性能监测系统工厂函数
1130
+ * @param storageManager - 存储管理器实例
1131
+ * @param settings - 性能设置(可选)
1132
+ * @returns 包含 collector, storage, monitor 的对象
1133
+ */
1134
+ declare function createPerformanceMonitor(storageManager: StorageManager, settings?: PerformanceSettings): {
1135
+ collector: PerformanceCollector;
1136
+ storage: PerformanceStorage;
1137
+ createMonitor: (runtime: any) => LifecycleMonitor;
1138
+ };
932
1139
 
933
- type EventCallback = (...args: any[]) => any;
1140
+ declare const PluginEvents: {
1141
+ readonly LOAD: "plugin:load";
1142
+ readonly LOADED: "plugin:loaded";
1143
+ readonly MOUNT: "plugin:mount";
1144
+ readonly MOUNTED: "plugin:mounted";
1145
+ readonly UNMOUNT: "plugin:unmount";
1146
+ readonly LOAD_FAILED: "plugin:load-failed";
1147
+ readonly MOUNT_FAILED: "plugin:mount-failed";
1148
+ };
1149
+ declare const ConfigEvents: {
1150
+ readonly CHANGE: "config:change";
1151
+ };
1152
+ /**
1153
+ * 事件回调函数类型
1154
+ * @param T 事件参数类型元组
1155
+ * @returns void
1156
+ */
1157
+ type EventCallback<T extends unknown[] = unknown[]> = (...args: T) => void;
934
1158
  /**
935
1159
  * 事件总线接口
936
1160
  */
@@ -941,170 +1165,157 @@ interface EventBus {
941
1165
  * @param callback 回调函数
942
1166
  * @returns 取消订阅函数
943
1167
  */
944
- on(event: string, callback: EventCallback): () => void;
1168
+ on<T extends unknown[]>(event: string, callback: EventCallback<T>): () => void;
945
1169
  /**
946
1170
  * 取消订阅
947
1171
  * @param event 事件名称
948
1172
  * @param callback 回调函数
949
1173
  */
950
- off(event: string, callback: EventCallback): void;
1174
+ off<T extends unknown[]>(event: string, callback: EventCallback<T>): void;
951
1175
  /**
952
1176
  * 触发事件
953
1177
  * @param event 事件名称
954
1178
  * @param args 事件参数
955
1179
  */
956
- emit(event: string, ...args: any[]): void;
1180
+ emit<T extends unknown[]>(event: string, ...args: T): void;
957
1181
  /**
958
1182
  * 订阅一次性事件
959
1183
  * @param event 事件名称
960
1184
  * @param callback 回调函数
961
1185
  */
962
- once(event: string, callback: EventCallback): void;
1186
+ once<T extends unknown[]>(event: string, callback: EventCallback<T>): void;
963
1187
  }
964
1188
  declare class DefaultEventBus implements EventBus {
965
1189
  private listeners;
966
- on(event: string, callback: EventCallback): () => void;
967
- off(event: string, callback: EventCallback): void;
968
- emit(event: string, ...args: any[]): void;
969
- once(event: string, callback: EventCallback): void;
1190
+ on<T extends unknown[]>(event: string, callback: EventCallback<T>): () => void;
1191
+ off<T extends unknown[]>(event: string, callback: EventCallback<T>): void;
1192
+ emit<T extends unknown[]>(event: string, ...args: T): void;
1193
+ once<T extends unknown[]>(event: string, callback: EventCallback<T>): void;
970
1194
  }
971
1195
 
972
1196
  /**
973
- * 核心领域服务:存储管理器
974
- * @description 统一管理应用内所有的持久化存储资源。
975
- * 核心功能:
976
- * 1. 作用域隔离:通过前缀划分 `plugin`、`shared` 和 `system` 三个层级的存储空间。
977
- * 2. Schema 校验:支持注册存储描述,规范数据存取,避免键名冲突。
978
- * 3. 默认值与配置回退:支持从 Schema 默认值或 ConfigManager 中回退取值。
1197
+ * 插件错误分类
1198
+ */
1199
+ declare enum PluginErrorType {
1200
+ /** 可恢复错误:网络波动、超时等,可以重试 */
1201
+ RECOVERABLE = "recoverable",
1202
+ /** 致命错误:语法错误、循环依赖等,无法通过重试恢复 */
1203
+ FATAL = "fatal",
1204
+ /** 配置错误:插件配置无效 */
1205
+ CONFIG = "config",
1206
+ /** 依赖错误:依赖插件不存在或版本不匹配 */
1207
+ DEPENDENCY = "dependency"
1208
+ }
1209
+ /**
1210
+ * 插件错误
979
1211
  */
980
- declare class StorageManager {
981
- /** 底层物理存储驱动 */
982
- private baseStorage;
983
- /** 插件 ID 与存储描述定义的映射关系 */
984
- private schemas;
985
- /** 内存缓存,减少 JSON 序列化和物理 IO 开销 */
986
- private memoryCache;
1212
+ declare class PluginError extends Error {
1213
+ pluginId: string;
1214
+ type: PluginErrorType;
1215
+ originalError?: Error | undefined;
1216
+ retryCount: number;
1217
+ constructor(pluginId: string, type: PluginErrorType, message: string, originalError?: Error | undefined, retryCount?: number);
1218
+ }
1219
+ /**
1220
+ * 插件管理器
1221
+ * @description 核心领域服务,负责插件的完整生命周期管理,包括扫描、注册、配置合并、状态切换及依赖解析。
1222
+ */
1223
+ declare class PluginManager {
1224
+ /** 全局事件总线,用于插件间及插件与内核间的异步通信 */
1225
+ readonly eventBus: DefaultEventBus;
1226
+ /** 存储管理服务,负责插件私有存储和系统级状态的持久化 */
1227
+ private storageManager;
1228
+ /** 插件 ID 到运行时实例的映射表 */
1229
+ private runtimes;
1230
+ /** 插件 ID 到原始插件定义对象的映射表 */
1231
+ private plugins;
1232
+ /** 收集到的所有插件路由配置 */
1233
+ private routes;
1234
+ /** 收集到的所有插件扩展点配置,按插槽位置分组 */
1235
+ private extensions;
1236
+ /** 插件的启用状态和排序信息的内存缓存 */
1237
+ private pluginStates;
1238
+ /** 扩展点缓存,避免重复计算 */
1239
+ private memoizedExtensions;
1240
+ /** 路由缓存 */
1241
+ private memoizedRoutes;
1242
+ /** 传递给插件的共享上下文缓存 */
1243
+ private sharedContext;
1244
+ /** 收集到的插件工具函数集合 */
1245
+ private utils;
1246
+ /** 插件强制启用标记(系统插件不可禁用) */
1247
+ private pluginForces;
1248
+ /** 插件懒加载标记 */
1249
+ private pluginLazyInit;
1250
+ /** 插件默认启用状态 */
1251
+ private pluginDefaultEnabled;
1252
+ /** 是否正在初始化插件中,防止重入导致多次加载 */
1253
+ private isInitializing;
987
1254
  /**
988
- * 初始化存储管理器
989
- * @param baseStorage - 符合 StoragePort 接口的物理存储驱动(如 LocalStorageAdapter)
1255
+ * 构造函数
1256
+ * @param storage - 底层存储适配器
990
1257
  */
991
- constructor(baseStorage: StoragePort);
1258
+ constructor(storage: StoragePort);
992
1259
  /**
993
- * 注册插件的存储 Schema
994
- * @param pluginId - 插件 ID
995
- * @param schema - 存储项定义列表
1260
+ * 从持久化存储中恢复插件状态 (启用/禁用、排序等)
996
1261
  */
997
- registerSchema(pluginId: string, schema: StorageItemSchema[]): void;
1262
+ private loadStates;
998
1263
  /**
999
- * 内部校验方法:检查键名是否在 Schema 中声明
1000
- * @param pluginId - 插件 ID
1001
- * @param key - 待校验的键名
1002
- * @param scope - 目标作用域
1264
+ * 将当前的插件状态持久化到存储中
1003
1265
  */
1004
- private validateKey;
1266
+ private saveStates;
1005
1267
  /**
1006
- * 获取插件私有存储适配器
1007
- * @param pluginId - 插件 ID
1008
- * @returns 自动添加 `plugin:{id}:` 前缀的存储接口
1268
+ * 订阅插件状态变更
1269
+ * @param listener 回调函数,当插件状态变更时被调用
1270
+ * @returns 取消订阅的函数
1009
1271
  */
1010
- getPluginStorage(pluginId: string): StoragePort;
1272
+ subscribe(listener: () => void): () => void;
1011
1273
  /**
1012
- * 获取全局共享存储适配器
1013
- * @returns 自动添加 `shared:` 前缀的存储接口
1274
+ * 订阅路由变更
1275
+ * @param listener 回调函数,当路由变更时被调用
1276
+ * @returns 取消订阅的函数
1014
1277
  */
1015
- getSharedStorage(): StoragePort;
1278
+ subscribeToRoutes(listener: () => void): () => void;
1016
1279
  /**
1017
- * 获取系统内部存储适配器
1018
- * @returns 自动添加 `system:` 前缀的存储接口
1280
+ * 获取存储管理器实例
1281
+ * @returns StorageManager 实例
1019
1282
  */
1020
- getSystemStorage(): StoragePort;
1283
+ getStorageManager(): StorageManager;
1021
1284
  /**
1022
- * 创建插件沙箱使用的复合存储对象
1023
- * @description 返回的对象封装了对私有存储和共享存储的操作。
1024
- * 特性:
1025
- * - 内存级 LRU 缓存:极大提升高频读写性能。
1026
- * - 自动序列化/反序列化 JSON。
1027
- * - 自动校验 Schema。
1028
- * - 取值回退逻辑:持久化存储 -> ConfigManager -> Schema 默认值。
1029
- *
1030
- * @param pluginId - 插件 ID
1031
- * @returns 包含 get/set/remove 及 shared 子对象的复合接口
1285
+ * 用于调度状态更新的函数,可由外部宿主环境(如 React)注入
1032
1286
  */
1033
- getContextStorage(pluginId: string): {
1034
- shared: {
1035
- get: <T = any>(key: string) => T | null;
1036
- set: <T = any>(key: string, value: T) => void;
1037
- remove: (key: string) => void;
1038
- };
1039
- get: <T = any>(key: string) => T | null;
1040
- set: <T = any>(key: string, value: T) => void;
1041
- remove: (key: string) => void;
1042
- };
1043
- }
1044
-
1045
- /**
1046
- * 插件管理器
1047
- * @description 核心领域服务,负责插件的完整生命周期管理,包括扫描、注册、配置合并、状态切换及依赖解析。
1048
- */
1049
- declare class PluginManager {
1050
- /** 全局事件总线,用于插件间及插件与内核间的异步通信 */
1051
- readonly eventBus: DefaultEventBus;
1052
- /** 存储管理服务,负责插件私有存储和系统级状态的持久化 */
1053
- private storageManager;
1054
- /** 插件 ID 到运行时实例的映射表 */
1055
- private runtimes;
1056
- /** 插件 ID 到原始插件定义对象的映射表 */
1057
- private plugins;
1058
- /** 收集到的所有插件路由配置 */
1059
- private routes;
1060
- /** 收集到的所有插件扩展点配置,按插槽位置分组 */
1061
- private extensions;
1062
- /** 插件的启用状态和排序信息的内存缓存 */
1063
- private pluginStates;
1064
- /** 状态变更监听器集合,支持按插槽过滤 */
1065
- private listeners;
1066
- /** 按插槽位置存储的监听器,用于精确通知 */
1067
- private slotListeners;
1068
- /** 扩展点缓存,避免重复计算 */
1069
- private memoizedExtensions;
1070
- /** 路由缓存 */
1071
- private memoizedRoutes;
1072
- /** 传递给插件的共享上下文缓存 */
1073
- private sharedContext;
1074
- /** 收集到的插件工具函数集合 */
1075
- private utils;
1076
- /** 是否正在初始化插件中,防止重入导致多次加载 */
1077
- private isInitializing;
1287
+ private stateUpdateScheduler;
1078
1288
  /**
1079
- * 构造函数
1080
- * @param storage - 底层存储适配器
1289
+ * 注入状态更新调度器
1081
1290
  */
1082
- constructor(storage: StoragePort);
1291
+ setUpdateScheduler(scheduler: (callback: () => void) => void): void;
1083
1292
  /**
1084
- * 从持久化存储中恢复插件状态 (启用/禁用、排序等)
1293
+ * 触发状态变更通知
1294
+ * @description 统一使用 Zustand Store 进行状态管理,EventBus 仅用于一次性事件
1295
+ * @param affectedSlot - (可选) 受影响的插槽位置
1085
1296
  */
1086
- private loadStates;
1297
+ private notify;
1087
1298
  /**
1088
- * 将当前的插件状态持久化到存储中
1299
+ * 获取指定插件
1300
+ * @param pluginId 插件 ID
1089
1301
  */
1090
- private saveStates;
1302
+ getPlugin(pluginId: string): Plugin | undefined;
1091
1303
  /**
1092
- * 订阅插件状态的变更通知
1093
- * @param listener - 变更时的回调函数
1094
- * @param slot - (可选) 指定监听的插槽位置,若提供则仅在该插槽受影响时通知
1095
- * @returns 取消订阅的函数
1304
+ * 检查插件是否已注册
1305
+ * @param pluginId - 插件 ID
1096
1306
  */
1097
- subscribe(listener: () => void, slot?: SlotPosition | string): () => void;
1307
+ hasPlugin(pluginId: string): boolean;
1098
1308
  /**
1099
- * 获取存储管理器实例
1100
- * @returns StorageManager 实例
1309
+ * 获取指定插件的运行时实例
1310
+ * @param pluginId 插件 ID
1311
+ * @returns 插件运行时实例,如果不存在则返回 undefined
1101
1312
  */
1102
- getStorageManager(): StorageManager;
1313
+ getPluginRuntime(pluginId: string): PluginRuntime | undefined;
1103
1314
  /**
1104
- * 触发状态变更通知
1105
- * @param affectedSlot - (可选) 受影响的插槽位置
1315
+ * 激活插件
1316
+ * @param pluginId - 插件 ID
1106
1317
  */
1107
- private notify;
1318
+ activate(pluginId: string): Promise<void>;
1108
1319
  /**
1109
1320
  * 获取所有已注册的插件列表
1110
1321
  * @description 结果会根据插件类型优先级和用户自定义排序进行排序
@@ -1126,6 +1337,18 @@ declare class PluginManager {
1126
1337
  * @returns 是否启用
1127
1338
  */
1128
1339
  isPluginEnabled(pluginId: string): boolean;
1340
+ /**
1341
+ * 检查插件是否可禁用
1342
+ * @param pluginId - 插件 ID
1343
+ * @returns 是否可禁用
1344
+ */
1345
+ canDisablePlugin(pluginId: string): boolean;
1346
+ /**
1347
+ * 检查插件是否应默认启用
1348
+ * @param pluginId - 插件 ID
1349
+ * @returns 是否默认启用
1350
+ */
1351
+ shouldEnableByDefault(pluginId: string): boolean;
1129
1352
  /**
1130
1353
  * 切换插件的启用/禁用状态
1131
1354
  * @description 禁用插件会立即触发其卸载生命周期并销毁运行时。
@@ -1133,6 +1356,21 @@ declare class PluginManager {
1133
1356
  * @param enabled - 目标状态
1134
1357
  */
1135
1358
  togglePlugin(pluginId: string, enabled: boolean): void;
1359
+ /**
1360
+ * 删除插件及其所有关联状态
1361
+ * @description 完整清理流程:禁用 -> 卸载运行时 -> 清理存储 -> 清理配置 -> 清理状态 -> 通知
1362
+ * @param pluginId - 插件 ID
1363
+ * @param cleanupStorage - 是否清理存储(默认 true)
1364
+ */
1365
+ deletePlugin(pluginId: string, cleanupStorage?: boolean): Promise<void>;
1366
+ /**
1367
+ * 更新插件元数据和包地址
1368
+ * @description 更新流程:禁用旧版本 -> 卸载 -> 更新元数据 -> 重新加载并激活
1369
+ * @param pluginId - 插件 ID
1370
+ * @param newManifest - 新的插件清单
1371
+ * @param newBundleUrl - 新的包地址(可选,如果不改变则传 undefined)
1372
+ */
1373
+ updatePlugin(pluginId: string, newManifest: Partial<PluginManifest>, newBundleUrl?: string): Promise<void>;
1136
1374
  /**
1137
1375
  * 设置插件的显示排序权重
1138
1376
  * @param pluginId - 插件 ID
@@ -1221,6 +1459,14 @@ declare class PluginManager {
1221
1459
  * @param autoMount 是否自动挂载所有插件 (默认为 false,启用按需加载模式)
1222
1460
  */
1223
1461
  initPlugins(sharedContext?: Record<string, any>, autoMount?: boolean): Promise<void>;
1462
+ /**
1463
+ * 带重试机制的插件加载
1464
+ */
1465
+ private loadPluginWithRetry;
1466
+ /**
1467
+ * 带重试机制的插件挂载
1468
+ */
1469
+ private mountPluginWithRetry;
1224
1470
  /**
1225
1471
  * 获取排序后的插件 ID 列表 (处理依赖)
1226
1472
  */
@@ -1252,83 +1498,18 @@ declare class PluginManager {
1252
1498
  private handleFunctionalPlugin;
1253
1499
  private handleViewPlugin;
1254
1500
  private handleThemePlugin;
1501
+ private handleRendererPlugin;
1255
1502
  private handleSystemPlugin;
1503
+ /**
1504
+ * 注册插件默认配置
1505
+ */
1506
+ private registerDefaultConfig;
1256
1507
  }
1257
1508
  /**
1258
1509
  * 全局插件管理器实例
1259
1510
  */
1260
1511
  declare const pluginManager: PluginManager;
1261
1512
 
1262
- /**
1263
- * @file plugin-runtime.ts
1264
- * @description 插件运行时,封装单个插件的生命周期(load/mount/unmount)、沙箱环境和隔离上下文
1265
- * @author ChatBI Team
1266
- */
1267
-
1268
- /**
1269
- * 插件运行时类
1270
- * @description 为单个插件提供独立的运行环境,负责管理其生命周期、初始化沙箱环境并组装上下文对象。
1271
- */
1272
- declare class PluginRuntime {
1273
- /** 插件定义对象 */
1274
- plugin: Plugin;
1275
- /** 传递给插件的上下文对象 */
1276
- context: PluginContext;
1277
- /** 存储沙箱隔离设施 */
1278
- private storageSandbox;
1279
- /** Window/全局对象沙箱隔离设施 */
1280
- private windowSandbox;
1281
- /** 是否已完成加载阶段 */
1282
- private isLoaded;
1283
- /** 是否已完成挂载阶段 */
1284
- private isMounted;
1285
- /** 运行时捕获的错误信息 */
1286
- private error;
1287
- /**
1288
- * 构造函数
1289
- * @param plugin - 插件定义对象
1290
- * @param sharedContext - 来自内核的共享上下文资源 (如 API 引擎、事件总线)
1291
- * @param storageManager - 全局存储管理器
1292
- */
1293
- constructor(plugin: Plugin, sharedContext: Record<string, any>, storageManager: StorageManager);
1294
- /**
1295
- * 执行插件的加载逻辑 (onLoad)
1296
- * @description 此阶段会自动注册插件声明的 API 配置,并调用插件的 onLoad 钩子。
1297
- * 用于执行非 UI 的初始化逻辑,如注册服务、拦截器等。
1298
- */
1299
- load(): Promise<void>;
1300
- /**
1301
- * 执行插件的挂载逻辑 (onMount)
1302
- * @description 此阶段会激活 Window 沙箱并调用插件的 onMount 钩子。
1303
- * 此时插件的 UI 组件(如有)即将或已经进入 DOM。
1304
- */
1305
- mount(): Promise<void>;
1306
- /**
1307
- * 执行插件的卸载逻辑 (onUnmount)
1308
- * @description 调用插件的 onUnmount 钩子并停用沙箱。
1309
- */
1310
- unmount(): Promise<void>;
1311
- /**
1312
- * 彻底销毁插件实例
1313
- * @description 卸载插件并重置加载状态。
1314
- */
1315
- destroy(): Promise<void>;
1316
- /**
1317
- * 设置运行时错误 (内部使用)
1318
- * @internal
1319
- */
1320
- _setError(error: Error | null): void;
1321
- /**
1322
- * 获取插件运行时错误
1323
- */
1324
- getError(): Error | null;
1325
- /**
1326
- * 获取插件当前运行状态
1327
- * @returns 'error' | 'mounted' | 'loaded' | 'initial'
1328
- */
1329
- get status(): "error" | "mounted" | "loaded" | "initial";
1330
- }
1331
-
1332
1513
  /**
1333
1514
  * 插件隔离沙箱
1334
1515
  * @description 核心领域服务,为每个插件实例创建独立的运行上下文。
@@ -1369,6 +1550,147 @@ declare class PluginSandbox {
1369
1550
  get logger(): Logger;
1370
1551
  }
1371
1552
 
1553
+ /** 特性规则类型 */
1554
+ type RuleType = 'environment' | 'user' | 'percentage';
1555
+ /** 特性规则 */
1556
+ interface FeatureRule {
1557
+ type: RuleType;
1558
+ condition: string;
1559
+ value?: string | number;
1560
+ }
1561
+ /** 特性配置 */
1562
+ interface FeatureConfig {
1563
+ enabled: boolean;
1564
+ rules: FeatureRule[];
1565
+ namespace: string;
1566
+ description?: string;
1567
+ }
1568
+ /** 迁移警告 */
1569
+ interface MigrationWarning {
1570
+ pluginId: string;
1571
+ currentVersion: string;
1572
+ targetVersion: string;
1573
+ steps: string[];
1574
+ }
1575
+ /** 废弃信息 */
1576
+ interface DeprecationInfo {
1577
+ deprecatedIn: string;
1578
+ willRemoveIn: string;
1579
+ message: string;
1580
+ }
1581
+ /** 废弃警告 */
1582
+ interface DeprecationWarning {
1583
+ feature: string;
1584
+ info: DeprecationInfo;
1585
+ }
1586
+ declare const FEATURE_NAMESPACE_PREFIX = "chatbi:feature:";
1587
+ declare const STORAGE_KEY = "chatbi:feature:store";
1588
+ interface FeatureRegistryState {
1589
+ features: Record<string, FeatureConfig>;
1590
+ migrationPaths: Record<string, {
1591
+ toVersion: string;
1592
+ steps: string[];
1593
+ }>;
1594
+ deprecatedFeatures: Record<string, DeprecationInfo>;
1595
+ setFeature: (name: string, config: Partial<FeatureConfig>) => void;
1596
+ getFeature: (name: string) => FeatureConfig | undefined;
1597
+ removeFeature: (name: string) => void;
1598
+ isEnabled: (name: string, context?: {
1599
+ userId?: string;
1600
+ env?: string;
1601
+ }) => boolean;
1602
+ addMigrationPath: (fromVersion: string, toVersion: string, steps: string[]) => void;
1603
+ checkMigration: (plugins: PluginManifest[]) => MigrationWarning[];
1604
+ registerDeprecation: (feature: string, info: DeprecationInfo) => void;
1605
+ checkDeprecations: (features?: string[]) => DeprecationWarning[];
1606
+ }
1607
+ declare function simpleHash$1(str: string): number;
1608
+ declare function evaluateRules$1(rules: FeatureRule[], context: {
1609
+ userId?: string;
1610
+ env?: string;
1611
+ }): boolean;
1612
+ declare const featureFlagsStore: Omit<zustand_vanilla.StoreApi<FeatureRegistryState>, "setState" | "persist"> & {
1613
+ setState(partial: FeatureRegistryState | Partial<FeatureRegistryState> | ((state: FeatureRegistryState) => FeatureRegistryState | Partial<FeatureRegistryState>), replace?: false | undefined): unknown;
1614
+ setState(state: FeatureRegistryState | ((state: FeatureRegistryState) => FeatureRegistryState), replace: true): unknown;
1615
+ persist: {
1616
+ setOptions: (options: Partial<zustand_middleware.PersistOptions<FeatureRegistryState, unknown, unknown>>) => void;
1617
+ clearStorage: () => void;
1618
+ rehydrate: () => Promise<void> | void;
1619
+ hasHydrated: () => boolean;
1620
+ onHydrate: (fn: (state: FeatureRegistryState) => void) => () => void;
1621
+ onFinishHydration: (fn: (state: FeatureRegistryState) => void) => () => void;
1622
+ getOptions: () => Partial<zustand_middleware.PersistOptions<FeatureRegistryState, unknown, unknown>>;
1623
+ };
1624
+ };
1625
+
1626
+ /**
1627
+ * 规则引擎
1628
+ * @description 提供特性规则的评估能力,支持环境、用户和百分比规则
1629
+ */
1630
+
1631
+ declare function simpleHash(str: string): number;
1632
+ /** 规则评估上下文 */
1633
+ interface RuleContext {
1634
+ userId?: string;
1635
+ env?: string;
1636
+ [key: string]: string | undefined;
1637
+ }
1638
+ /**
1639
+ * 评估规则列表
1640
+ * @param rules 规则数组
1641
+ * @param context 评估上下文
1642
+ * @returns 任意规则匹配返回 true,否则返回 false
1643
+ */
1644
+ declare function evaluateRules(rules: FeatureRule[], context: RuleContext): boolean;
1645
+ /**
1646
+ * 评估单条规则
1647
+ * @param rule 规则
1648
+ * @param context 评估上下文
1649
+ * @returns 规则是否匹配
1650
+ */
1651
+ declare function evaluateRule(rule: FeatureRule, context: RuleContext): boolean;
1652
+ /**
1653
+ * 创建百分比规则
1654
+ * @param percentage 百分比值 (0-100)
1655
+ * @returns 百分比规则
1656
+ */
1657
+ declare function createPercentageRule(percentage: number): FeatureRule;
1658
+ /**
1659
+ * 创环境规则
1660
+ * @param env 环境名称
1661
+ * @returns 环境规则
1662
+ */
1663
+ declare function createEnvironmentRule(env: string): FeatureRule;
1664
+ /**
1665
+ * 创建用户规则
1666
+ * @param userId 用户 ID
1667
+ * @returns 用户规则
1668
+ */
1669
+ declare function createUserRule(userId: string): FeatureRule;
1670
+
1671
+ /**
1672
+ * 核心状态 Store 接口
1673
+ */
1674
+ interface CoreState {
1675
+ /** 插件列表变更版本号,用于触发插件管理器的列表更新 */
1676
+ pluginVersion: number;
1677
+ /** 扩展点变更版本号(按插槽),用于实现插槽级别的精确更新 */
1678
+ slotVersions: Record<string, number>;
1679
+ /** 路由变更版本号 */
1680
+ routeVersion: number;
1681
+ /** 触发全局插件列表更新 */
1682
+ notifyPluginsChanged: () => void;
1683
+ /** 触发特定插槽的更新 */
1684
+ notifySlotChanged: (slot: SlotPosition | string) => void;
1685
+ /** 触发路由配置更新 */
1686
+ notifyRoutesChanged: () => void;
1687
+ }
1688
+ /**
1689
+ * 创建 Vanilla Store 实例
1690
+ */
1691
+ declare const coreStore: zustand_vanilla.StoreApi<CoreState>;
1692
+ declare const coreStoreApi: zustand_vanilla.StoreApi<CoreState>;
1693
+
1372
1694
  /**
1373
1695
  * 浏览器本地存储 (LocalStorage) 适配器
1374
1696
  * @description 实现 `StoragePort` 接口,封装了对原生 `localStorage` 的访问。
@@ -1417,342 +1739,908 @@ declare class LocalStorageAdapter implements StoragePort {
1417
1739
  * - 若定义了前缀:仅删除以该前缀开头的键名,不影响其他数据。
1418
1740
  * - 若未定义前缀:调用原生 `localStorage.clear()` 清空所有数据。
1419
1741
  */
1420
- clear(): void;
1742
+ clear(): void;
1743
+ /**
1744
+ * 返回当前命名空间下的存储项总数
1745
+ */
1746
+ get length(): number;
1747
+ /**
1748
+ * 根据索引获取对应的原始键名
1749
+ * @param index - 索引位置
1750
+ * @returns 对应的业务键名,不存在则返回 null
1751
+ */
1752
+ key(index: number): string | null;
1753
+ }
1754
+
1755
+ /**
1756
+ * 作用域存储适配器 (ScopedStorageAdapter)
1757
+ * @description 采用装饰器模式实现。它包装一个现有的 `StoragePort` 实例,
1758
+ * 并为所有存储操作透明地注入一个前缀(命名空间),从而实现逻辑上的存储隔离。
1759
+ * 常用于为插件分配独立的存储空间,而无需修改插件代码。
1760
+ */
1761
+ declare class ScopedStorageAdapter implements StoragePort {
1762
+ private underlyingStorage;
1763
+ private prefix;
1764
+ /**
1765
+ * 初始化作用域适配器
1766
+ * @param underlyingStorage - 被装饰的底层存储适配器实例
1767
+ * @param prefix - 用于隔离的作用域前缀字符串
1768
+ */
1769
+ constructor(underlyingStorage: StoragePort, prefix: string);
1770
+ /**
1771
+ * 内部方法:计算实际存储的键名
1772
+ * @param key - 业务层传入的原始键名
1773
+ * @returns 拼接前缀后的物理键名
1774
+ */
1775
+ private getKey;
1776
+ /**
1777
+ * 内部方法:从物理键名还原业务键名
1778
+ * @param namespacedKey - 物理存储中的完整键名
1779
+ * @returns 还原后的原始键名,若前缀不匹配则返回 null
1780
+ */
1781
+ private getOriginalKey;
1782
+ /**
1783
+ * 读取当前作用域下的存储项
1784
+ * @param key - 原始键名
1785
+ * @returns 字符串内容,不存在则返回 null
1786
+ */
1787
+ getItem(key: string): string | null;
1788
+ /**
1789
+ * 写入当前作用域下的存储项
1790
+ * @param key - 原始键名
1791
+ * @param value - 字符串内容
1792
+ */
1793
+ setItem(key: string, value: string): void;
1794
+ /**
1795
+ * 移除当前作用域下的特定存储项
1796
+ * @param key - 原始键名
1797
+ */
1798
+ removeItem(key: string): void;
1799
+ /**
1800
+ * 清空当前作用域下的所有存储项
1801
+ * @description 仅删除匹配当前前缀的键值对,不会影响底层存储中的其他数据。
1802
+ */
1803
+ clear(): void;
1804
+ /**
1805
+ * 返回当前作用域下的存储项总数
1806
+ */
1807
+ get length(): number;
1808
+ /**
1809
+ * 根据索引获取当前作用域下的原始键名
1810
+ * @param index - 索引位置
1811
+ * @returns 对应的业务键名,不存在则返回 null
1812
+ */
1813
+ key(index: number): string | null;
1814
+ }
1815
+
1816
+ /**
1817
+ * 基于 Axios 的默认请求适配器
1818
+ */
1819
+ declare class AxiosAdapter implements ApiAdapter {
1820
+ private client;
1821
+ constructor(baseURL?: string, timeout?: number);
1822
+ request<T = any>(config: ApiRequestConfig): Promise<T>;
1823
+ stream(config: ApiRequestConfig, callbacks: StreamCallbacks, _endpointConfig?: ApiEndpointConfig): Promise<void>;
1824
+ }
1825
+
1826
+ /**
1827
+ * API 引擎核心类
1828
+ * @description 负责加载配置并执行请求,支持策略模式切换底层请求实现
1829
+ */
1830
+ declare class ApiEngine {
1831
+ private adapter;
1832
+ private config;
1833
+ private interceptors;
1834
+ /** 可配置的成功码 */
1835
+ private successCodes;
1836
+ constructor(adapter?: ApiAdapter);
1837
+ /**
1838
+ * 注册拦截器
1839
+ */
1840
+ registerInterceptor(interceptor: ApiInterceptor): void;
1841
+ /**
1842
+ * 移除拦截器
1843
+ */
1844
+ unregisterInterceptor(interceptor: ApiInterceptor): void;
1845
+ /**
1846
+ * 设置成功码
1847
+ */
1848
+ setSuccessCodes(codes: string[]): void;
1849
+ /**
1850
+ * 切换请求适配器
1851
+ * @param adapter 新的适配器实例
1852
+ */
1853
+ useAdapter(adapter: ApiAdapter): void;
1854
+ /**
1855
+ * 注册 API 配置
1856
+ * @param config 配置对象
1857
+ */
1858
+ register(config: ApiConfig): void;
1859
+ /**
1860
+ * 获取接口配置
1861
+ */
1862
+ getEndpoint(module: string, action: string): ApiEndpointConfig | undefined;
1863
+ /**
1864
+ * 发起 API 请求
1865
+ * @param module 模块名
1866
+ * @param action 动作名
1867
+ * @param data 请求数据 (Body 或 Query)
1868
+ * @param options 请求选项
1869
+ */
1870
+ call<T = any>(module: string, action: string, data?: any, options?: RequestOptions): Promise<T>;
1871
+ /**
1872
+ * 发起流式请求
1873
+ * @param module 模块名
1874
+ * @param action 动作名
1875
+ * @param data 请求数据
1876
+ * @param options 请求选项
1877
+ */
1878
+ stream(module: string, action: string, data?: any, options?: RequestOptions): Promise<void>;
1879
+ /**
1880
+ * 准备请求配置,应用 URL 参数替换和请求拦截器
1881
+ */
1882
+ private prepareRequestConfig;
1883
+ /**
1884
+ * 应用所有请求拦截器
1885
+ */
1886
+ private applyRequestInterceptors;
1887
+ /**
1888
+ * 应用所有响应拦截器
1889
+ * @returns 是否被劫持
1890
+ */
1891
+ private applyResponseInterceptors;
1892
+ /**
1893
+ * 检查 HTTP 状态码
1894
+ */
1895
+ private checkHttpStatus;
1896
+ /**
1897
+ * 提取响应数据
1898
+ */
1899
+ private extractResponseData;
1900
+ /**
1901
+ * 处理业务错误
1902
+ */
1903
+ private handleBusinessError;
1904
+ /**
1905
+ * 检查响应是否成功
1906
+ */
1907
+ protected isSuccess(response: any): boolean;
1908
+ /**
1909
+ * 处理响应错误
1910
+ */
1911
+ protected handleResponseError(response: any, context: any): void;
1912
+ /**
1913
+ * 判断是否为 BaseResponse
1914
+ */
1915
+ private isBaseResponse;
1916
+ /**
1917
+ * 严格判断是否为 AxiosResponse
1918
+ */
1919
+ private isAxiosResponse;
1920
+ /**
1921
+ * 创建拦截上下文
1922
+ */
1923
+ private createInterceptorContext;
1924
+ }
1925
+ declare const apiEngine: ApiEngine;
1926
+
1927
+ /**
1928
+ * 自动检测是否处于 Mock 模式
1929
+ */
1930
+ declare function isMockMode(): boolean;
1931
+ /**
1932
+ * 从文件模块映射中解析 API 配置
1933
+ * @description 配合 Vite 的 import.meta.glob 使用,自动匹配定义文件和 Mock 文件
1934
+ * @param definitionsMap API 定义文件映射 (import.meta.glob('./modules/*.ts', { eager: true }))
1935
+ * @param mocksMap Mock 文件映射 (import.meta.glob('./modules/*.mock.ts', { eager: true }))
1936
+ * @param useMock 是否启用 Mock (如果不传,将自动调用 isMockMode())
1937
+ * @returns 合并后的 ApiConfig
1938
+ */
1939
+ declare function resolveApiModules(definitionsMap: Record<string, any>, mocksMap?: Record<string, any>): ApiConfig;
1940
+
1941
+ /**
1942
+ * 沙箱选项
1943
+ */
1944
+ interface SandboxOptions {
1945
+ /** 严格模式:启用所有安全限制 */
1946
+ strict?: boolean;
1947
+ /** 自定义白名单 */
1948
+ customWhitelist?: Record<string, boolean>;
1949
+ /** 是否允许 DOM 访问 */
1950
+ allowDOM?: boolean;
1951
+ /** 是否允许网络请求 */
1952
+ allowNetwork?: boolean;
1953
+ }
1954
+ /**
1955
+ * ProxySandbox 类
1956
+ * @description 基于 Proxy 的 JS 沙箱实现,模拟独立的 Window 环境
1957
+ */
1958
+ declare class ProxySandbox {
1959
+ /** 沙箱名称 */
1960
+ name: string;
1961
+ /** 代理后的 Window 对象 */
1962
+ proxy: WindowProxy;
1963
+ /** 沙箱是否激活 */
1964
+ running: boolean;
1965
+ /** 沙箱选项 */
1966
+ private options;
1967
+ /** 记录新增/修改的全局变量 */
1968
+ private updatedValueSet;
1969
+ /** 绑定函数的缓存池,避免重复 bind 带来的性能开销 */
1970
+ private boundFunctionCache;
1971
+ /** 副作用记录池 */
1972
+ private effectPool;
1973
+ /** 真实的 Window 对象 */
1974
+ private globalContext;
1975
+ /** 白名单全局变量(允许透传访问真实 Window) */
1976
+ private static globalWhitelist;
1977
+ constructor(name: string, options?: SandboxOptions, globalContext?: Window & typeof globalThis);
1978
+ /**
1979
+ * 激活沙箱
1980
+ */
1981
+ active(): void;
1982
+ /**
1983
+ * 销毁沙箱
1984
+ */
1985
+ inactive(): void;
1986
+ /**
1987
+ * 获取缓存的绑定函数,避免重复 bind
1988
+ */
1989
+ getBoundFunction(fn: Function, context: Window): Function;
1990
+ /**
1991
+ * 获取当前缓存大小(用于监控和调试)
1992
+ */
1993
+ getCacheSize(): number;
1994
+ /**
1995
+ * 在沙箱中执行代码
1996
+ * @param code JS 代码字符串
1997
+ * @param options 执行选项
1998
+ * @returns 执行结果
1999
+ * @description 使用 IIFE 模式执行代码,替代已废弃的 with 语句
2000
+ */
2001
+ eval(code: string, options?: {
2002
+ useStrict?: boolean;
2003
+ }): any;
2004
+ /**
2005
+ * 创建伪造的 Window 对象
2006
+ */
2007
+ private createFakeWindow;
2008
+ private isConstructor;
2009
+ private isNativeFunction;
2010
+ /**
2011
+ * 劫持全局副作用 API
2012
+ */
2013
+ private patchGlobalEffects;
2014
+ }
2015
+
2016
+ /**
2017
+ * 日期时间格式化工具类
2018
+ */
2019
+ declare const dateUtils: {
2020
+ /**
2021
+ * 格式化日期为 YYYY-MM-DD
2022
+ */
2023
+ formatDate(date?: dayjs.ConfigType): string;
2024
+ /**
2025
+ * 格式化时间为 HH:mm:ss
2026
+ */
2027
+ formatTime(date?: dayjs.ConfigType): string;
2028
+ /**
2029
+ * 格式化日期时间为 YYYY-MM-DD HH:mm:ss
2030
+ */
2031
+ formatDateTime(date?: dayjs.ConfigType): string;
2032
+ /**
2033
+ * 获取当前时间戳(毫秒)
2034
+ */
2035
+ now(): number;
2036
+ /**
2037
+ * 获取相对时间(例如:几分钟前)
2038
+ */
2039
+ fromNow(date: dayjs.ConfigType): string;
2040
+ /**
2041
+ * 原始 dayjs 对象,用于更复杂的场景
2042
+ */
2043
+ dayjs: typeof dayjs;
2044
+ };
2045
+
2046
+ type KeepStrategy = 'first' | 'last' | 'search' | 'hash';
2047
+ /**
2048
+ * 把当前地址中所有出现的参数合并成一份。
2049
+ * 重复 key 的处理策略:
2050
+ * - 'first' : 按出现顺序,第一次的值生效
2051
+ * - 'last' : 按出现顺序,最后一次的值生效(默认,最直观)
2052
+ * - 'search' : 只要 search 里出现过,就用 search 的
2053
+ * - 'hash' : 只要 hash 里出现过,就用 hash 的
2054
+ */
2055
+ declare function normalizeParams(strategy?: KeepStrategy): URLSearchParams;
2056
+ /**
2057
+ * 清除 URL 中的特定参数并返回新的 URL
2058
+ * @description 同时处理 search 和 hash 中的参数
2059
+ */
2060
+ declare function cleanUrlParams(keysToRemove: string[]): string;
2061
+
2062
+ declare const version = "1.0.0";
2063
+
2064
+ /**
2065
+ * Remote Plugin Source 类型定义
2066
+ * @description 定义远程插件源接口和配置选项
2067
+ */
2068
+ /**
2069
+ * 远程插件源
2070
+ * @description 表示一个远程插件仓库地址
2071
+ */
2072
+ interface RemotePluginSource {
2073
+ /** 唯一标识符 */
2074
+ id: string;
2075
+ /** 显示名称 */
2076
+ name: string;
2077
+ /** plugin.json URL */
2078
+ url: string;
2079
+ /** 是否启用 */
2080
+ enabled?: boolean;
2081
+ }
2082
+ /**
2083
+ * 缓存配置选项
2084
+ */
2085
+ interface CacheOptions {
2086
+ /** 缓存 TTL (毫秒),默认 5 分钟 */
2087
+ ttl: number;
2088
+ /** 最大缓存条目数 */
2089
+ maxSize?: number;
2090
+ }
2091
+ /**
2092
+ * 重试配置选项
2093
+ */
2094
+ interface RetryOptions {
2095
+ /** 最大重试次数 */
2096
+ maxRetries: number;
2097
+ /** 重试延迟 (毫秒) */
2098
+ retryDelay: number;
2099
+ /** 自定义重试条件 */
2100
+ retryCondition?: (error: any) => boolean;
2101
+ }
2102
+ /**
2103
+ * 远程源配置选项
2104
+ */
2105
+ interface RemoteSourceOptions {
2106
+ /** 请求超时 (毫秒) */
2107
+ timeout?: number;
2108
+ /** 重试配置 */
2109
+ retry?: RetryOptions;
2110
+ /** 缓存配置 */
2111
+ cache?: CacheOptions;
2112
+ }
2113
+ /**
2114
+ * 缓存条目元数据
2115
+ */
2116
+ interface CacheEntry<T = any> {
2117
+ /** 缓存数据 */
2118
+ data: T;
2119
+ /** 创建时间戳 */
2120
+ createdAt: number;
2121
+ /** 最后访问时间戳 */
2122
+ lastAccessedAt: number;
2123
+ /** 过期时间戳 */
2124
+ expiresAt: number;
2125
+ }
2126
+ /**
2127
+ * 加载结果
2128
+ */
2129
+ interface LoadResult<T = any> {
2130
+ /** 是否成功 */
2131
+ success: boolean;
2132
+ /** 加载的数据 */
2133
+ data?: T;
2134
+ /** 加载错误 */
2135
+ error?: LoadError;
2136
+ /** 是否来自缓存 */
2137
+ fromCache?: boolean;
2138
+ }
2139
+ /**
2140
+ * 加载错误
2141
+ */
2142
+ interface LoadError {
2143
+ /** 错误代码 */
2144
+ code: 'NETWORK' | 'TIMEOUT' | 'PARSE' | 'NOT_FOUND' | 'CACHE_ERROR' | 'VALIDATION_ERROR';
2145
+ /** 错误消息 */
2146
+ message: string;
2147
+ /** 是否可重试 */
2148
+ retryable: boolean;
2149
+ /** 原始错误 */
2150
+ originalError?: any;
2151
+ }
2152
+
2153
+ /**
2154
+ * 远程缓存管理器
2155
+ * @description 管理远程插件Manifest的缓存,支持TTL和大小限制
2156
+ */
2157
+ declare class RemoteCache<T = any> {
2158
+ private cache;
2159
+ private defaultTtl;
2160
+ /**
2161
+ * 创建远程缓存管理器
2162
+ * @param options 缓存配置选项
2163
+ */
2164
+ constructor(options?: CacheOptions);
2165
+ /**
2166
+ * 获取缓存条目
2167
+ * @param key 缓存键
2168
+ * @returns 缓存条目,如果不存在或已过期返回 undefined
2169
+ */
2170
+ get(key: string): CacheEntry<T> | undefined;
2171
+ /**
2172
+ * 设置缓存条目
2173
+ * @param key 缓存键
2174
+ * @param data 要缓存的数据
2175
+ * @param ttl 自定义 TTL (毫秒),使用默认 TTL 如果未指定
2176
+ */
2177
+ set(key: string, data: T, ttl?: number): void;
2178
+ /**
2179
+ * 删除缓存条目
2180
+ * @param key 缓存键
2181
+ * @returns 是否成功删除
2182
+ */
2183
+ delete(key: string): boolean;
2184
+ /**
2185
+ * 清空所有缓存
2186
+ */
2187
+ clear(): void;
2188
+ /**
2189
+ * 检查缓存键是否存在
2190
+ * @param key 缓存键
2191
+ */
2192
+ has(key: string): boolean;
1421
2193
  /**
1422
- * 返回当前命名空间下的存储项总数
2194
+ * 获取缓存条目数量
1423
2195
  */
1424
- get length(): number;
2196
+ size(): number;
1425
2197
  /**
1426
- * 根据索引获取对应的原始键名
1427
- * @param index - 索引位置
1428
- * @returns 对应的业务键名,不存在则返回 null
2198
+ * 获取缓存条目的元数据(不触发访问时间更新)
2199
+ * @param key 缓存键
1429
2200
  */
1430
- key(index: number): string | null;
2201
+ getMetadata(key: string): CacheEntry<T> | undefined;
2202
+ /**
2203
+ * 更新缓存 TTL
2204
+ * @param key 缓存键
2205
+ * @param ttl 新 TTL (毫秒)
2206
+ */
2207
+ updateTTL(key: string, ttl: number): boolean;
1431
2208
  }
1432
2209
 
1433
2210
  /**
1434
- * 作用域存储适配器 (ScopedStorageAdapter)
1435
- * @description 采用装饰器模式实现。它包装一个现有的 `StoragePort` 实例,
1436
- * 并为所有存储操作透明地注入一个前缀(命名空间),从而实现逻辑上的存储隔离。
1437
- * 常用于为插件分配独立的存储空间,而无需修改插件代码。
2211
+ * 远程插件加载器
2212
+ * @description 管理远程插件源的添加、移除和 Manifest 加载
1438
2213
  */
1439
- declare class ScopedStorageAdapter implements StoragePort {
1440
- private underlyingStorage;
1441
- private prefix;
2214
+ declare class RemoteLoader {
2215
+ private sources;
2216
+ private cache;
2217
+ private retryStrategy;
2218
+ private options;
1442
2219
  /**
1443
- * 初始化作用域适配器
1444
- * @param underlyingStorage - 被装饰的底层存储适配器实例
1445
- * @param prefix - 用于隔离的作用域前缀字符串
2220
+ * 创建远程加载器
2221
+ * @param options 远程源配置选项
1446
2222
  */
1447
- constructor(underlyingStorage: StoragePort, prefix: string);
2223
+ constructor(options?: RemoteSourceOptions);
1448
2224
  /**
1449
- * 内部方法:计算实际存储的键名
1450
- * @param key - 业务层传入的原始键名
1451
- * @returns 拼接前缀后的物理键名
2225
+ * 添加远程插件源
2226
+ * @param source 远程插件源
1452
2227
  */
1453
- private getKey;
2228
+ addSource(source: RemotePluginSource): void;
1454
2229
  /**
1455
- * 内部方法:从物理键名还原业务键名
1456
- * @param namespacedKey - 物理存储中的完整键名
1457
- * @returns 还原后的原始键名,若前缀不匹配则返回 null
2230
+ * 移除远程插件源
2231
+ * @param sourceId 插件源 ID
2232
+ * @returns 是否成功移除
1458
2233
  */
1459
- private getOriginalKey;
2234
+ removeSource(sourceId: string): boolean;
1460
2235
  /**
1461
- * 读取当前作用域下的存储项
1462
- * @param key - 原始键名
1463
- * @returns 字符串内容,不存在则返回 null
2236
+ * 获取所有远程插件源
2237
+ * @returns 远程插件源列表
1464
2238
  */
1465
- getItem(key: string): string | null;
2239
+ getSources(): RemotePluginSource[];
1466
2240
  /**
1467
- * 写入当前作用域下的存储项
1468
- * @param key - 原始键名
1469
- * @param value - 字符串内容
2241
+ * 获取指定远程插件源
2242
+ * @param sourceId 插件源 ID
1470
2243
  */
1471
- setItem(key: string, value: string): void;
2244
+ getSource(sourceId: string): RemotePluginSource | undefined;
1472
2245
  /**
1473
- * 移除当前作用域下的特定存储项
1474
- * @param key - 原始键名
2246
+ * 启用/禁用远程插件源
2247
+ * @param sourceId 插件源 ID
2248
+ * @param enabled 是否启用
1475
2249
  */
1476
- removeItem(key: string): void;
2250
+ setSourceEnabled(sourceId: string, enabled: boolean): boolean;
1477
2251
  /**
1478
- * 清空当前作用域下的所有存储项
1479
- * @description 仅删除匹配当前前缀的键值对,不会影响底层存储中的其他数据。
2252
+ * 从远程加载插件 Manifest
2253
+ * @param sourceId 插件源 ID
2254
+ * @returns 加载结果
1480
2255
  */
1481
- clear(): void;
2256
+ loadManifest<T = PluginManifest>(sourceId: string): Promise<LoadResult<T>>;
1482
2257
  /**
1483
- * 返回当前作用域下的存储项总数
2258
+ * 带重试的请求
2259
+ * @param url 请求 URL
2260
+ * @param attempt 当前尝试次数
2261
+ * @returns 响应数据
1484
2262
  */
1485
- get length(): number;
2263
+ private fetchWithRetry;
1486
2264
  /**
1487
- * 根据索引获取当前作用域下的原始键名
1488
- * @param index - 索引位置
1489
- * @returns 对应的业务键名,不存在则返回 null
2265
+ * 处理加载错误
2266
+ * @param error 错误对象
2267
+ * @returns 错误结果
1490
2268
  */
1491
- key(index: number): string | null;
2269
+ private handleLoadError;
2270
+ /**
2271
+ * 创建错误结果
2272
+ * @param code 错误代码
2273
+ * @param message 错误消息
2274
+ * @param retryable 是否可重试
2275
+ * @returns 错误结果
2276
+ */
2277
+ private createErrorResult;
2278
+ /**
2279
+ * 清除缓存
2280
+ * @param sourceId 可选,指定源 ID(只清除该源的缓存)
2281
+ */
2282
+ clearCache(sourceId?: string): void;
2283
+ /**
2284
+ * 获取缓存大小
2285
+ */
2286
+ getCacheSize(): number;
2287
+ /**
2288
+ * 睡眠
2289
+ * @param ms 毫秒数
2290
+ */
2291
+ private sleep;
1492
2292
  }
1493
2293
 
1494
- interface PluginProviderProps {
1495
- manager: PluginManager;
1496
- children: React.ReactNode;
1497
- }
1498
- declare const PluginProvider: React.FC<PluginProviderProps>;
1499
- declare const usePluginManager: () => PluginManager;
2294
+ /**
2295
+ * Retry Strategy 实现
2296
+ * @description 提供重试延迟计算和错误判断逻辑
2297
+ */
1500
2298
 
1501
2299
  /**
1502
- * ProxySandbox 类
1503
- * @description 基于 Proxy 的 JS 沙箱实现,模拟独立的 Window 环境
2300
+ * 重试策略类
2301
+ * @description 计算重试延迟、判断错误是否可重试
1504
2302
  */
1505
- declare class ProxySandbox {
1506
- /** 沙箱名称 */
1507
- name: string;
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);
2303
+ declare class RetryStrategy {
2304
+ private defaultOptions;
1523
2305
  /**
1524
- * 激活沙箱
2306
+ * 创建重试策略
2307
+ * @param options 重试配置选项
1525
2308
  */
1526
- active(): void;
2309
+ constructor(options?: RetryOptions);
1527
2310
  /**
1528
- * 销毁沙箱
2311
+ * 计算重试延迟(指数退避)
2312
+ * @param attempt 当前尝试次数 (从 1 开始)
2313
+ * @returns 延迟毫秒数
1529
2314
  */
1530
- inactive(): void;
2315
+ calculateDelay(attempt: number): number;
1531
2316
  /**
1532
- * 在沙箱中执行代码
1533
- * @param code JS 代码字符串
1534
- * @returns 执行结果
2317
+ * 判断错误是否可重试
2318
+ * @param error 错误对象
2319
+ * @returns 是否可重试
1535
2320
  */
1536
- eval(code: string): any;
2321
+ isRetryable(error: any): boolean;
1537
2322
  /**
1538
- * 创建伪造的 Window 对象
2323
+ * 默认重试条件判断
2324
+ * @param error 错误对象
2325
+ * @returns 是否可重试
1539
2326
  */
1540
- private createFakeWindow;
1541
- private isConstructor;
1542
- private isNativeFunction;
2327
+ private defaultRetryCondition;
1543
2328
  /**
1544
- * 劫持全局副作用 API
2329
+ * 获取最大重试次数
1545
2330
  */
1546
- private patchGlobalEffects;
2331
+ getMaxRetries(): number;
2332
+ /**
2333
+ * 获取基础重试延迟
2334
+ */
2335
+ getBaseDelay(): number;
1547
2336
  }
1548
2337
 
2338
+ /** 插件依赖输入 */
2339
+ interface PluginDependencyInput {
2340
+ id: string;
2341
+ dependencies: Dependency[];
2342
+ }
2343
+ /** 共享依赖检测结果 */
2344
+ interface SharedDependencyResult {
2345
+ /** 包 ID */
2346
+ packageId: string;
2347
+ /** 请求的版本列表 */
2348
+ requestedVersions: string[];
2349
+ /** 解析后的版本 */
2350
+ resolvedVersion: string;
2351
+ /** 请求者列表 */
2352
+ requestedBy: string[];
2353
+ /** 是否有冲突 */
2354
+ hasConflict: boolean;
2355
+ }
1549
2356
  /**
1550
- * 日期时间格式化工具类
2357
+ * 共享依赖检测器
2358
+ * @description 识别多个插件共享的 npm 包,检查版本冲突,使用最高版本策略解决
1551
2359
  */
1552
- declare const dateUtils: {
2360
+ declare class SharedDepsDetector {
1553
2361
  /**
1554
- * 格式化日期为 YYYY-MM-DD
2362
+ * 检测共享依赖
2363
+ * @param plugins 插件列表
2364
+ * @returns 共享依赖检测结果
1555
2365
  */
1556
- formatDate(date?: dayjs.ConfigType): string;
2366
+ detect(plugins: PluginDependencyInput[]): SharedDependencyResult[];
1557
2367
  /**
1558
- * 格式化时间为 HH:mm:ss
2368
+ * 检查版本是否冲突
2369
+ * @param versions 版本列表
2370
+ * @returns 是否有冲突
1559
2371
  */
1560
- formatTime(date?: dayjs.ConfigType): string;
2372
+ private checkConflict;
1561
2373
  /**
1562
- * 格式化日期时间为 YYYY-MM-DD HH:mm:ss
2374
+ * 最高版本策略
2375
+ * @param versions 版本列表
2376
+ * @returns 最高兼容版本
1563
2377
  */
1564
- formatDateTime(date?: dayjs.ConfigType): string;
2378
+ resolveHighest(versions: string[]): string;
1565
2379
  /**
1566
- * 获取当前时间戳(毫秒)
2380
+ * 最低版本策略
2381
+ * @param versions 版本列表
2382
+ * @returns 最低兼容版本
1567
2383
  */
1568
- now(): number;
2384
+ resolveLowest(versions: string[]): string;
2385
+ }
2386
+
2387
+ /** 冲突解决结果 */
2388
+ interface ConflictResolution {
2389
+ /** 包 ID */
2390
+ packageId: string;
2391
+ /** 请求的版本列表 */
2392
+ requestedVersions: string[];
2393
+ /** 解析后的版本 */
2394
+ resolvedVersion: string;
2395
+ /** 解决策略 */
2396
+ strategy: 'highest' | 'lowest' | 'user-selected';
2397
+ /** 请求者列表 */
2398
+ requestedBy: string[];
2399
+ }
2400
+ /**
2401
+ * 版本冲突解决器
2402
+ * @description 使用最高版本策略 (默认) 解决版本冲突
2403
+ */
2404
+ declare class ConflictResolver {
1569
2405
  /**
1570
- * 获取相对时间(例如:几分钟前)
2406
+ * 解决版本冲突
2407
+ * @param deps 共享依赖检测结果
2408
+ * @param strategy 解决策略,默认 highest
2409
+ * @returns 冲突解决结果
1571
2410
  */
1572
- fromNow(date: dayjs.ConfigType): string;
2411
+ resolve(deps: SharedDependencyResult[], strategy?: 'highest' | 'lowest'): ConflictResolution[];
1573
2412
  /**
1574
- * 原始 dayjs 对象,用于更复杂的场景
2413
+ * 使用最高版本策略解决
2414
+ * @param dep 共享依赖
2415
+ * @returns 解决的版本
1575
2416
  */
1576
- dayjs: typeof dayjs;
1577
- };
2417
+ resolveHighest(dep: SharedDependencyResult): string;
2418
+ /**
2419
+ * 使用最低版本策略解决
2420
+ * @param dep 共享依赖
2421
+ * @returns 解决的版本
2422
+ */
2423
+ resolveLowest(dep: SharedDependencyResult): string;
2424
+ /**
2425
+ * 使用 maxSatisfying 解析版本范围
2426
+ * @param range 版本范围
2427
+ * @param versions 可用版本列表
2428
+ * @returns 满足范围的最高版本
2429
+ */
2430
+ resolveWithRange(range: string, versions: string[]): string | null;
2431
+ }
1578
2432
 
1579
2433
  /**
1580
- * 日志等级枚举
2434
+ * 循环依赖检测
2435
+ * @description 使用 DFS 检测插件依赖中的循环引用,生成警告日志
1581
2436
  */
1582
- declare enum LogLevel {
1583
- /** 调试级别:输出最详尽的信息 */
1584
- DEBUG = 0,
1585
- /** 信息级别:输出重要的运行状态 */
1586
- INFO = 1,
1587
- /** 警告级别:输出潜在的问题,但不影响运行 */
1588
- WARN = 2,
1589
- /** 错误级别:输出严重的运行异常 */
1590
- ERROR = 3,
1591
- /** 禁用日志:不输出任何信息 */
1592
- NONE = 4
2437
+
2438
+ /** 插件依赖输入 */
2439
+ interface CycleDetectorInput {
2440
+ id: string;
2441
+ dependencies: Dependency[];
2442
+ }
2443
+ /** 循环警告 */
2444
+ interface CycleWarning {
2445
+ /** 循环路径 */
2446
+ cycle: string[];
2447
+ /** 完整路径 */
2448
+ path: string[];
1593
2449
  }
1594
2450
  /**
1595
- * 日志工具类
1596
- * @description 核心工具类,提供统一的日志输出格式 `[Prefix] Message`。
1597
- * 支持通过 `LogLevel` 进行全局过滤。
1598
- * 支持日志缓冲和自动分组,以减少控制台噪音。
1599
- * 支持浏览器端 CSS 样式和 Node.js 端 ANSI 颜色。
2451
+ * 循环依赖检测器
2452
+ * @description 使用 DFS 检测循环依赖,生成警告但不阻断加载
1600
2453
  */
1601
- declare class Logger {
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;
2454
+ declare class CycleDetector {
1618
2455
  /**
1619
- * 构造函数
1620
- * @param prefix - 业务模块前缀,默认为 'App'
2456
+ * 检测循环依赖
2457
+ * @param plugins 插件列表
2458
+ * @returns 循环警告列表
1621
2459
  */
1622
- constructor(prefix?: string);
2460
+ detect(plugins: CycleDetectorInput[]): CycleWarning[];
1623
2461
  /**
1624
- * 静态方法:设置全局日志输出等级
1625
- * @param level - 目标日志等级
2462
+ * 从依赖图检测循环
2463
+ * @param graph 依赖图
2464
+ * @returns 循环警告列表
1626
2465
  */
1627
- static setLevel(level: LogLevel): void;
2466
+ detectFromGraph(graph: Map<string, string[]>): CycleWarning[];
1628
2467
  /**
1629
- * 静态方法:启用或禁用日志缓冲
1630
- * @param enabled - 是否启用
2468
+ * 生成循环警告消息
2469
+ * @param warning 循环警告
2470
+ * @returns 警告消息
1631
2471
  */
1632
- static setBufferEnabled(enabled: boolean): void;
2472
+ formatWarning(warning: CycleWarning): string;
1633
2473
  /**
1634
- * 静态方法:获取当前全局日志等级
1635
- * @returns 当前生效的全局日志等级
2474
+ * 格式化所有警告
2475
+ * @param warnings 循环警告列表
2476
+ * @returns 警告消息列表
1636
2477
  */
1637
- static getLevel(): LogLevel;
2478
+ formatWarnings(warnings: CycleWarning[]): string[];
2479
+ }
2480
+
2481
+ /**
2482
+ * 依赖图构建器
2483
+ * @description 提供插件依赖拓扑构建、依赖查询功能
2484
+ */
2485
+ /** 依赖节点 */
2486
+ interface DependencyNode {
2487
+ /** 节点 ID (插件或包名) */
2488
+ id: string;
2489
+ /** 直接依赖列表 */
2490
+ dependencies: string[];
2491
+ /** 版本 */
2492
+ version: string;
2493
+ }
2494
+ /** 依赖边 */
2495
+ interface DependencyEdge {
2496
+ from: string;
2497
+ to: string;
2498
+ }
2499
+ /**
2500
+ * 依赖图
2501
+ * @description 构建和管理插件依赖拓扑
2502
+ */
2503
+ declare class DependencyGraph {
2504
+ private nodes;
2505
+ private edges;
1638
2506
  /**
1639
- * 格式化输出前缀
2507
+ * 添加依赖节点
2508
+ * @param node 依赖节点
1640
2509
  */
1641
- private getFormattedPrefix;
2510
+ addNode(node: DependencyNode): void;
1642
2511
  /**
1643
- * 生成分组标题参数
2512
+ * 添加依赖边
2513
+ * @param from 依赖者 ID
2514
+ * @param to 被依赖者 ID
1644
2515
  */
1645
- private static getGroupTitleArgs;
2516
+ addEdge(from: string, to: string): void;
1646
2517
  /**
1647
- * 内部方法:将日志推入缓冲区或直接输出
2518
+ * 获取依赖指定包的所有插件
2519
+ * @param packageId 包 ID
2520
+ * @returns 依赖该包的插件列表
1648
2521
  */
1649
- private log;
2522
+ getDependents(packageId: string): string[];
1650
2523
  /**
1651
- * 静态方法:刷新缓冲区,分组输出日志
2524
+ * 获取指定插件的所有依赖
2525
+ * @param pluginId 插件 ID
2526
+ * @returns 依赖列表
1652
2527
  */
1653
- static flush(): void;
2528
+ getDependencies(pluginId: string): string[];
1654
2529
  /**
1655
- * 打印 DEBUG 级别日志
2530
+ * 获取完整依赖图
2531
+ * @returns 节点 ID 到依赖列表的映射
1656
2532
  */
1657
- debug(...args: any[]): void;
2533
+ getGraph(): Map<string, string[]>;
1658
2534
  /**
1659
- * 打印 INFO 级别日志
2535
+ * 获取所有节点
2536
+ * @returns 节点列表
1660
2537
  */
1661
- info(...args: any[]): void;
2538
+ getNodes(): DependencyNode[];
1662
2539
  /**
1663
- * 打印 WARN 级别日志
2540
+ * 获取所有边
2541
+ * @returns 边列表
1664
2542
  */
1665
- warn(...args: any[]): void;
2543
+ getEdges(): DependencyEdge[];
1666
2544
  /**
1667
- * 打印 ERROR 级别日志
2545
+ * 检查节点是否存在
2546
+ * @param id 节点 ID
2547
+ * @returns 是否存在
1668
2548
  */
1669
- error(...args: any[]): void;
2549
+ hasNode(id: string): boolean;
1670
2550
  /**
1671
- * 开始一个日志控制台分组
2551
+ * 获取节点
2552
+ * @param id 节点 ID
2553
+ * @returns 节点,不存在返回 undefined
1672
2554
  */
1673
- group(label: string, collapsed?: boolean): void;
2555
+ getNode(id: string): DependencyNode | undefined;
1674
2556
  /**
1675
- * 结束当前日志控制台分组
2557
+ * 清空图
1676
2558
  */
1677
- groupEnd(): void;
2559
+ clear(): void;
2560
+ /**
2561
+ * 获取图的大小
2562
+ * @returns 节点数量
2563
+ */
2564
+ size(): number;
1678
2565
  }
1679
- /** 默认 Logger 实例 */
1680
- declare const logger: Logger;
1681
- /**
1682
- * 创建带特定前缀的 Logger 实例
1683
- * @param prefix 日志前缀
1684
- * @returns Logger 实例
1685
- */
1686
- declare const createLogger: (prefix: string) => Logger;
1687
-
1688
- type KeepStrategy = 'first' | 'last' | 'search' | 'hash';
1689
- /**
1690
- * 把当前地址中所有出现的参数合并成一份。
1691
- * 重复 key 的处理策略:
1692
- * - 'first' : 按出现顺序,第一次的值生效
1693
- * - 'last' : 按出现顺序,最后一次的值生效(默认,最直观)
1694
- * - 'search' : 只要 search 里出现过,就用 search 的
1695
- * - 'hash' : 只要 hash 里出现过,就用 hash 的
1696
- */
1697
- declare function normalizeParams(strategy?: KeepStrategy): URLSearchParams;
1698
- /**
1699
- * 清除 URL 中的特定参数并返回新的 URL
1700
- * @description 同时处理 search 和 hash 中的参数
1701
- */
1702
- declare function cleanUrlParams(keysToRemove: string[]): string;
1703
-
1704
- declare const version = "1.0.0";
1705
-
1706
- /** 插件加载 Hook 的配置选项 */
1707
- interface PluginLoaderOptions {
1708
- /** 插件发现规则,定义如何从模块列表中识别插件 */
1709
- discoveryRules?: any[];
1710
- /** 插件模块映射,通常由 Vite 的 `import.meta.glob` 生成,键为路径,值为加载函数 */
1711
- modules?: Record<string, () => Promise<any>>;
1712
- /** 预注册的插件注册表,用于手动指定插件加载逻辑,优先级高于自动发现 */
1713
- registry?: Record<string, () => Promise<any>>;
1714
- /** 插件的业务配置映射,键为插件 ID */
1715
- pluginConfigs: Record<string, any>;
1716
- /** 初始化的共享上下文服务,将注入到每个插件的 onLoad 中 */
1717
- sharedContext?: Record<string, any>;
1718
- /** 系统级全局配置,如标题、版本号、Logo 等 */
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: 插件状态版本号,用于强制触发依赖插件状态的组件重渲染
1736
- */
1737
- declare const usePluginLoader: (options: PluginLoaderOptions) => {
1738
- pluginsLoaded: boolean;
1739
- pluginVersion: number;
1740
- };
1741
2566
 
2567
+ /** npm 包元数据 */
2568
+ interface NpmPackageMeta {
2569
+ name: string;
2570
+ versions: Record<string, unknown>;
2571
+ 'dist-tags': Record<string, string>;
2572
+ time?: Record<string, string>;
2573
+ }
2574
+ /** 版本信息 */
2575
+ interface VersionInfo {
2576
+ version: string;
2577
+ date?: string;
2578
+ deprecated?: boolean;
2579
+ }
1742
2580
  /**
1743
- * Hook 配置选项
2581
+ * NPM Registry 客户端
2582
+ * @description 集成 npm Registry API,支持包元数据查询、版本解析和缓存
1744
2583
  */
1745
- interface UseStorageStateOptions<T> {
1746
- defaultValue?: T;
1747
- scope?: 'plugin' | 'shared';
2584
+ declare class NpmRegistry {
2585
+ private client;
2586
+ private cache;
2587
+ /**
2588
+ * 创建 NPM Registry 客户端
2589
+ * @param baseUrl Registry 基础 URL,默认 https://registry.npmjs.org
2590
+ */
2591
+ constructor(baseUrl?: string);
2592
+ /**
2593
+ * 获取包元数据
2594
+ * @param packageName 包名
2595
+ * @param useCache 是否使用缓存,默认 true
2596
+ * @returns 包元数据,不存在返回 null
2597
+ */
2598
+ getPackageMeta(packageName: string, useCache?: boolean): Promise<NpmPackageMeta | null>;
2599
+ /**
2600
+ * 获取包的所有版本
2601
+ * @param packageName 包名
2602
+ * @returns 版本列表
2603
+ */
2604
+ getVersions(packageName: string): Promise<string[]>;
2605
+ /**
2606
+ * 获取包的最新版本
2607
+ * @param packageName 包名
2608
+ * @returns 最新版本,不存在返回 null
2609
+ */
2610
+ getLatestVersion(packageName: string): Promise<string | null>;
2611
+ /**
2612
+ * 从版本范围解析最佳版本
2613
+ * @param packageName 包名
2614
+ * @param range 版本范围 (如 ^1.0.0, >=1.0.0)
2615
+ * @returns 满足范围的最高版本,不存在返回 null
2616
+ */
2617
+ resolveVersion(packageName: string, range: string): Promise<string | null>;
2618
+ /**
2619
+ * 获取指定版本的详细信息
2620
+ * @param packageName 包名
2621
+ * @param version 版本号
2622
+ * @returns 版本信息,不存在返回 null
2623
+ */
2624
+ getVersionInfo(packageName: string, version: string): Promise<VersionInfo | null>;
2625
+ /**
2626
+ * 批量解析依赖
2627
+ * @param dependencies 依赖列表 [{ id, version }]
2628
+ * @returns 包名到解析后版本的映射
2629
+ */
2630
+ resolveDependencies(dependencies: Array<{
2631
+ id: string;
2632
+ version: string;
2633
+ }>): Promise<Map<string, string>>;
2634
+ /**
2635
+ * 清除缓存
2636
+ * @param packageName 包名,不提供则清除所有缓存
2637
+ */
2638
+ clearCache(packageName?: string): void;
1748
2639
  }
1749
2640
  /**
1750
- * 统一存储状态 Hook
1751
- * @description 提供与 StorageManager 和 Schema Registry 集成的持久化状态 Hook。
1752
- * @param pluginId 定义该 Key 的插件 ID
1753
- * @param key 存储键名 (必须在 Schema 中注册)
1754
- * @param options 配置项,包含默认值和作用域
2641
+ * 获取默认 Registry 实例
2642
+ * @returns 默认 NpmRegistry 实例
1755
2643
  */
1756
- declare function useStorageState<T>(pluginId: string, key: string, options?: UseStorageStateOptions<T>): [T, (value: T | ((val: T) => T)) => void];
2644
+ declare function getDefaultRegistry(): NpmRegistry;
1757
2645
 
1758
- export { type ApiAdapter, type ApiConfig, type ApiEndpointConfig, ApiEngine, type ApiInterceptor, ApiProvider, type ApiProviderProps, type ApiRequestConfig, type ApiResponseContext, AvatarSkeleton, AxiosAdapter, BasePlugin, type BaseResponse, BlockSkeleton, ConfigManager, DefaultEventBus, type DiscoveryRule, type ErrorStrategy, type EventBus, type EventBusPort, type EventCallback, type HttpMethod, LocalStorageAdapter, LogLevel, Logger, PLUGIN_TYPES, type Plugin, type PluginCapabilities, type PluginConfigItem, type PluginContext, PluginErrorBoundary, type PluginExtension, type PluginLifecycle, type PluginLoaderOptions, PluginManager, type PluginMetadata, PluginProvider, type PluginProviderProps, type PluginRegistry, PluginRuntime, PluginSandbox, PluginSlot, type PluginStorage, type PluginType, ProxySandbox, type RequestOptions, type RouteConfig, SUCCESS_CODE, type Scene, ScopedStorageAdapter, ServiceRegistry, SidebarIconSkeleton, Slot, type SlotPosition, SlotSkeletons, type SlotType, StatusBarItemSkeleton, type StorageItemSchema, StorageManager, type StoragePort, type StreamCallbacks, type TypedStorage, type UseStorageStateOptions, apiEngine, cleanUrlParams, configManager, createLogger, dateUtils, definePlugin, isMockMode, logger, normalizeParams, pluginManager, resolveApiModules, resolvePluginRegistry, serviceRegistry, useApi, usePluginLoader, usePluginManager, useStorageState, version };
2646
+ export { type AIChunk, type AIMessage, type AIProvider, type AITool, ApiAdapter, ApiConfig, ApiEndpointConfig, ApiEngine, ApiInterceptor, ApiRequestConfig, AxiosAdapter, type BaseResponse, type CacheEntry, type CacheOptions, type ChatOptions, ConfigEvents, type ConfigItemDefinition, ConfigManager, type ConflictResolution, ConflictResolver, CoreError, CoreErrorCode, CoreErrorStrategy, type CoreState, CycleDetector, type CycleDetectorInput, type CycleWarning, DEFAULT_PERFORMANCE_SETTINGS, type DeepReadonly, DefaultEventBus, Dependency, type DependencyEdge, DependencyGraph, type DependencyNode, type DeprecationInfo, type DeprecationWarning, type DiscoveryRule, type ErrorHandlerOptions, type EventBus, type EventCallback, FEATURE_NAMESPACE_PREFIX, type FeatureConfig, type FeatureRegistryState, type FeatureRule, type FunctionCallResult, type LifecycleMetric, LifecycleMonitor, type LifecyclePhase, type LoadError, type LoadResult, LocalStorageAdapter, LogLevel, Logger, type MigrationWarning, MockAIProvider, type NpmPackageMeta, NpmRegistry, OpenAIProvider, PerformanceCollector, type PerformanceData, type PerformanceSettings, PerformanceStorage, PerformanceTimer, Plugin, PluginCapabilities, PluginContext, type PluginDependencyInput, PluginError, PluginErrorType, PluginEvents, PluginExtension, PluginManager, PluginManifest, type PluginManifestType, type PluginRegistry, PluginRuntime, PluginSandbox, ProxySandbox, RemoteCache, RemoteLoader, type RemotePluginSource, type RemoteSourceOptions, RequestOptions, type RetryOptions, RetryStrategy, 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, SlotPosition, StorageItemSchema, StorageManager, StoragePort, StreamCallbacks, type ToolCall, ToolRegistry, type VersionInfo, aiStore, apiEngine, cleanUrlParams, configManager, coreStore, coreStoreApi, createAIStore, createEnvironmentRule, createLifecycleMonitor, createLogger, createPercentageRule, createPerformanceMonitor, createRoutePath, createSemVer, createUserRule, dateUtils, evaluateRules as evaluateFeatureRules, evaluateRule, evaluateRules$1 as evaluateRules, featureFlagsStore, getDefaultRegistry, handleError, simpleHash as hashString, isMockMode, isPluginManifest, isRoutePath, isSemVer, logger, normalizeParams, pluginManager, resolveApiModules, resolvePluginRegistry, serviceRegistry, simpleHash$1 as simpleHash, version };