@chatbi-v/vue 3.0.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/dist/core/src/adapters/AdapterInterface.d.ts +111 -0
- package/dist/core/src/adapters/AdapterRegistry.d.ts +88 -0
- package/dist/core/src/adapters/index.d.ts +7 -0
- package/dist/core/src/adapters/local-storage-adapter.d.ts +61 -0
- package/dist/core/src/adapters/scoped-storage-adapter.d.ts +61 -0
- package/dist/core/src/ai/function/index.d.ts +1 -0
- package/dist/core/src/ai/function/registry.d.ts +28 -0
- package/dist/core/src/ai/index.d.ts +8 -0
- package/dist/core/src/ai/providers/index.d.ts +2 -0
- package/dist/core/src/ai/providers/mock.d.ts +28 -0
- package/dist/core/src/ai/providers/openai.d.ts +17 -0
- package/dist/core/src/ai/session/index.d.ts +3 -0
- package/dist/core/src/ai/session/manager.d.ts +19 -0
- package/dist/core/src/ai/session/storage.d.ts +9 -0
- package/dist/core/src/ai/session/types.d.ts +14 -0
- package/dist/core/src/ai/store.d.ts +23 -0
- package/dist/core/src/ai/types.d.ts +57 -0
- package/dist/core/src/ai/utils.d.ts +7 -0
- package/dist/core/src/api/adapters/axios-adapter.d.ts +10 -0
- package/dist/core/src/api/engine.d.ts +101 -0
- package/dist/core/src/api/index.d.ts +5 -0
- package/dist/core/src/api/utils.d.ts +14 -0
- package/dist/core/src/application/service-registry.d.ts +57 -0
- package/dist/core/src/config-manager.d.ts +52 -0
- package/dist/core/src/dependency/ConflictResolver.d.ts +46 -0
- package/dist/core/src/dependency/CycleDetector.d.ts +47 -0
- package/dist/core/src/dependency/DependencyGraph.d.ts +85 -0
- package/dist/core/src/dependency/NpmRegistry.d.ts +78 -0
- package/dist/core/src/dependency/SharedDepsDetector.d.ts +49 -0
- package/dist/core/src/dependency/index.d.ts +9 -0
- package/dist/core/src/domain/auto-loader.d.ts +36 -0
- package/dist/core/src/domain/errors.d.ts +68 -0
- package/dist/core/src/domain/models.d.ts +42 -0
- package/dist/core/src/domain/performance/collector.d.ts +70 -0
- package/dist/core/src/domain/performance/index.d.ts +27 -0
- package/dist/core/src/domain/performance/lifecycle.d.ts +34 -0
- package/dist/core/src/domain/performance/storage.d.ts +79 -0
- package/dist/core/src/domain/performance/types.d.ts +67 -0
- package/dist/core/src/domain/plugin-manager.d.ts +327 -0
- package/dist/core/src/domain/plugin-runtime.d.ts +74 -0
- package/dist/core/src/domain/plugin-sandbox.d.ts +40 -0
- package/dist/core/src/domain/storage-manager.d.ts +81 -0
- package/dist/core/src/event-bus.d.ts +55 -0
- package/dist/core/src/feature-flag/FeatureRegistry.d.ts +75 -0
- package/dist/core/src/feature-flag/RuleEngine.d.ts +44 -0
- package/dist/core/src/feature-flag/index.d.ts +6 -0
- package/dist/core/src/index.d.ts +37 -0
- package/dist/core/src/manifest/ManifestValidator.d.ts +33 -0
- package/dist/core/src/manifest/ManifestWrapper.d.ts +23 -0
- package/dist/core/src/manifest/PluginManifest.d.ts +524 -0
- package/dist/core/src/manifest/index.d.ts +9 -0
- package/dist/core/src/ports/api-port.d.ts +136 -0
- package/dist/core/src/ports/event-bus-port.d.ts +32 -0
- package/dist/core/src/ports/plugin-port.d.ts +345 -0
- package/dist/core/src/ports/storage-port.d.ts +49 -0
- package/dist/core/src/remote/RemoteCache.d.ts +57 -0
- package/dist/core/src/remote/RemoteLoader.d.ts +85 -0
- package/dist/core/src/remote/RemotePluginSource.d.ts +88 -0
- package/dist/core/src/remote/RetryStrategy.d.ts +43 -0
- package/dist/core/src/remote/index.d.ts +8 -0
- package/dist/core/src/sandbox/proxy-sandbox.d.ts +74 -0
- package/dist/core/src/semver/SemverResolver.d.ts +79 -0
- package/dist/core/src/store.d.ts +30 -0
- package/dist/core/src/types/branded.d.ts +54 -0
- package/dist/core/src/types/index.d.ts +8 -0
- package/dist/core/src/types/template-literals.d.ts +58 -0
- package/dist/core/src/types/utils.d.ts +133 -0
- package/dist/core/src/utils/date.d.ts +32 -0
- package/dist/core/src/utils/index.d.ts +4 -0
- package/dist/core/src/utils/logger.d.ts +108 -0
- package/dist/core/src/utils/url.d.ts +16 -0
- package/dist/index.js +1899 -1842
- package/dist/index.umd.cjs +19 -19
- package/dist/vue/src/components/PluginErrorBoundary.vue.d.ts +20 -0
- package/dist/vue/src/components/PluginSlot.vue.d.ts +8 -0
- package/dist/vue/src/composables/useCoreStore.d.ts +9 -0
- package/dist/vue/src/composables/useService.d.ts +6 -0
- package/dist/vue/src/index.d.ts +18 -0
- package/package.json +10 -8
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { PLUGIN_TYPES, type PluginManifest, type PluginType } from '../manifest/PluginManifest';
|
|
2
|
+
import { isPluginId, type PluginId } from '../types/branded';
|
|
3
|
+
export { isPluginId };
|
|
4
|
+
export type { PluginId };
|
|
5
|
+
import { ApiAdapter, ApiConfig } from './api-port';
|
|
6
|
+
import { EventBusPort } from './event-bus-port';
|
|
7
|
+
import { TypedStorage } from './storage-port';
|
|
8
|
+
/**
|
|
9
|
+
* API 端口接口
|
|
10
|
+
* @description 插件使用 API 能力的入口,包含请求适配器和 API 配置注册功能
|
|
11
|
+
*/
|
|
12
|
+
export interface ApiPort extends ApiAdapter {
|
|
13
|
+
/**
|
|
14
|
+
* 注册 API 配置
|
|
15
|
+
* @param config - API 配置对象
|
|
16
|
+
*/
|
|
17
|
+
register?: (config: ApiConfig) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 插件类型定义
|
|
21
|
+
*/
|
|
22
|
+
export { PLUGIN_TYPES };
|
|
23
|
+
export type { PluginType };
|
|
24
|
+
/**
|
|
25
|
+
* 路由配置
|
|
26
|
+
*/
|
|
27
|
+
export interface RouteConfig {
|
|
28
|
+
path: string;
|
|
29
|
+
component: any;
|
|
30
|
+
meta?: Record<string, any>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 插件插槽位置
|
|
34
|
+
* @description 定义插件可以注入 UI 的标准位置
|
|
35
|
+
*/
|
|
36
|
+
export declare const Slot: {
|
|
37
|
+
readonly Sidebar: "sidebar";
|
|
38
|
+
readonly SidebarPanel: "sidebar-panel";
|
|
39
|
+
readonly Header: "header";
|
|
40
|
+
readonly StatusBar: "status-bar";
|
|
41
|
+
readonly Settings: "settings";
|
|
42
|
+
readonly MessageRenderer: "message-renderer";
|
|
43
|
+
readonly MessageContentRenderer: "message-content-renderer";
|
|
44
|
+
readonly SidebarSystem: "sidebar-system";
|
|
45
|
+
readonly SidebarBottom: "sidebar-bottom";
|
|
46
|
+
readonly RootLayout: "root-layout";
|
|
47
|
+
readonly Custom: "custom";
|
|
48
|
+
};
|
|
49
|
+
export type SlotType = (typeof Slot)[keyof typeof Slot];
|
|
50
|
+
export type SlotPosition = SlotType | string;
|
|
51
|
+
/**
|
|
52
|
+
* 插件扩展 (插槽注入配置)
|
|
53
|
+
*/
|
|
54
|
+
export interface PluginExtension {
|
|
55
|
+
/** 插槽位置标识符 */
|
|
56
|
+
slot: SlotPosition;
|
|
57
|
+
/** 要注入的 React 等框架组件 */
|
|
58
|
+
component: any;
|
|
59
|
+
/** 排序权重,数值越小越靠前 */
|
|
60
|
+
order?: number;
|
|
61
|
+
/** @internal 插件 ID,由系统在加载时自动注入,用于溯源 */
|
|
62
|
+
_pluginId?: string;
|
|
63
|
+
/** 扩展的元数据信息 */
|
|
64
|
+
meta?: {
|
|
65
|
+
/** 显示图标 */
|
|
66
|
+
icon?: any;
|
|
67
|
+
/** 显示标签文本 */
|
|
68
|
+
label?: string;
|
|
69
|
+
/** 详细描述 */
|
|
70
|
+
description?: string;
|
|
71
|
+
/** 唯一标识符,用于某些特定插槽的索引 */
|
|
72
|
+
key?: string;
|
|
73
|
+
/** 允许其他自定义属性 */
|
|
74
|
+
[key: string]: any;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 插件配置项定义
|
|
79
|
+
*/
|
|
80
|
+
export interface PluginConfigItem {
|
|
81
|
+
/** 配置键名 */
|
|
82
|
+
key: string;
|
|
83
|
+
/** 配置类型 */
|
|
84
|
+
type: 'string' | 'number' | 'boolean' | 'select';
|
|
85
|
+
/** 配置显示的标签 */
|
|
86
|
+
label: string;
|
|
87
|
+
/** 配置描述信息 */
|
|
88
|
+
description?: string;
|
|
89
|
+
/** 默认值 */
|
|
90
|
+
default?: any;
|
|
91
|
+
/** 当类型为 select 时的选项列表 */
|
|
92
|
+
options?: {
|
|
93
|
+
label: string;
|
|
94
|
+
value: any;
|
|
95
|
+
}[];
|
|
96
|
+
/** 选择模式:支持多选或标签模式 (AntD 风格) */
|
|
97
|
+
mode?: 'multiple' | 'tags';
|
|
98
|
+
/** 最小值 (针对 number 类型) */
|
|
99
|
+
min?: number;
|
|
100
|
+
/** 最大值 (针对 number 类型) */
|
|
101
|
+
max?: number;
|
|
102
|
+
/**
|
|
103
|
+
* 是否为私有配置
|
|
104
|
+
* @description 如果为 true,则该配置不会通过自动配置服务暴露给其他插件
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
private?: boolean;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 插件能力定义 (Behavioral Capabilities)
|
|
111
|
+
* @description 定义插件的行为特征。注意:路由(routes)和扩展(extensions)属于结构化能力,直接通过 metadata 字段声明,不在此列。
|
|
112
|
+
*/
|
|
113
|
+
export interface PluginCapabilities {
|
|
114
|
+
/**
|
|
115
|
+
* 是否支持配置设置
|
|
116
|
+
* @default false (如果 metadata.configuration 存在,则可能被隐式视为 true,建议显式声明)
|
|
117
|
+
*/
|
|
118
|
+
configurable?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* 是否可嵌入其他页面
|
|
121
|
+
* @description 声明该插件是否可以作为 Widget 被其他插件引用
|
|
122
|
+
*/
|
|
123
|
+
embeddable?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* 是否支持多实例
|
|
126
|
+
* @description 默认为 false (单例)。如果在聊天窗口中每个会话都需要独立状态,则设为 true
|
|
127
|
+
*/
|
|
128
|
+
multiInstance?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* 是否需要后台运行
|
|
131
|
+
* @description 如果为 true,即使 UI 不可见,插件也不会被卸载
|
|
132
|
+
*/
|
|
133
|
+
background?: boolean;
|
|
134
|
+
[key: string]: boolean | undefined;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 存储项数据结构定义 (Schema)
|
|
138
|
+
*/
|
|
139
|
+
export interface StorageItemSchema {
|
|
140
|
+
/** 存储键名 */
|
|
141
|
+
key: string;
|
|
142
|
+
/** 数据类型 */
|
|
143
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
144
|
+
/** 默认值 */
|
|
145
|
+
default?: any;
|
|
146
|
+
/** 描述信息 */
|
|
147
|
+
description?: string;
|
|
148
|
+
/**
|
|
149
|
+
* 作用域
|
|
150
|
+
* @description 'plugin' 表示仅当前插件可见(带插件 ID 前缀),'shared' 表示全局共享
|
|
151
|
+
*/
|
|
152
|
+
scope?: 'plugin' | 'shared';
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 插件存储接口
|
|
156
|
+
* @description 包含私有存储和共享存储访问能力
|
|
157
|
+
*/
|
|
158
|
+
export interface PluginStorage extends TypedStorage {
|
|
159
|
+
/** 获取插件私有存储数据 */
|
|
160
|
+
get: TypedStorage['get'];
|
|
161
|
+
/** 设置插件私有存储数据 */
|
|
162
|
+
set: TypedStorage['set'];
|
|
163
|
+
/** 移除插件私有存储数据 */
|
|
164
|
+
remove: TypedStorage['remove'];
|
|
165
|
+
/** 全局共享存储访问 */
|
|
166
|
+
shared: TypedStorage & {
|
|
167
|
+
/** 获取全局共享存储数据 */
|
|
168
|
+
get: TypedStorage['get'];
|
|
169
|
+
/** 设置全局共享存储数据 */
|
|
170
|
+
set: TypedStorage['set'];
|
|
171
|
+
/** 移除全局共享存储数据 */
|
|
172
|
+
remove: TypedStorage['remove'];
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 插件生命周期 Hooks
|
|
177
|
+
* @description 插件可以在不同的生命周期阶段执行特定的逻辑
|
|
178
|
+
* @template T - 插件清单类型,默认为 PluginManifest
|
|
179
|
+
*/
|
|
180
|
+
export interface PluginLifecycle<T extends PluginManifest = PluginManifest> {
|
|
181
|
+
/**
|
|
182
|
+
* 插件加载时调用
|
|
183
|
+
* @description 在插件被扫描并注入内核时触发。用于初始化内部状态、注册服务、设置拦截器等。此时 UI 尚未挂载。
|
|
184
|
+
* @param context - 插件上下文对象,提供核心能力的访问
|
|
185
|
+
*/
|
|
186
|
+
onLoad?: (context: PluginContext<T>) => void | Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* 插件挂载到 UI 时调用
|
|
189
|
+
* @description 当插件的 UI 组件(如有)被 React 挂载到 DOM 时触发。
|
|
190
|
+
* @param context - 插件上下文对象
|
|
191
|
+
*/
|
|
192
|
+
onMount?: (context: PluginContext<T>) => void;
|
|
193
|
+
/**
|
|
194
|
+
* 插件从 UI 卸载时调用
|
|
195
|
+
* @description 当插件的 UI 组件被销毁时触发。用于清理定时器、取消订阅等。
|
|
196
|
+
* @param context - 插件上下文对象
|
|
197
|
+
*/
|
|
198
|
+
onUnmount?: (context: PluginContext<T>) => void;
|
|
199
|
+
/**
|
|
200
|
+
* 插件配置发生变化时调用
|
|
201
|
+
* @description 当用户通过配置中心修改插件设置时触发。
|
|
202
|
+
* @param newConfig - 变更后的新配置对象
|
|
203
|
+
* @param oldConfig - 变更前的旧配置对象
|
|
204
|
+
*/
|
|
205
|
+
onConfigChange?: (newConfig: any, oldConfig: any) => void;
|
|
206
|
+
/**
|
|
207
|
+
* 插件错误处理
|
|
208
|
+
* @description 当插件发生错误时触发,用于统一错误处理和日志记录
|
|
209
|
+
* @param error - 错误对象
|
|
210
|
+
* @param context - 插件上下文对象
|
|
211
|
+
*/
|
|
212
|
+
onError?: (error: Error, context: PluginContext<T>) => void;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 插件上下文
|
|
216
|
+
* @description 传递给插件生命周期钩子的核心对象,是插件访问宿主环境能力的唯一入口。
|
|
217
|
+
* @template T - 插件清单类型,默认为 PluginManifest
|
|
218
|
+
*/
|
|
219
|
+
export interface PluginContext<T extends PluginManifest = PluginManifest> {
|
|
220
|
+
/** 当前插件的唯一标识符 */
|
|
221
|
+
pluginId: PluginId;
|
|
222
|
+
/** 插件清单 */
|
|
223
|
+
manifest: T;
|
|
224
|
+
/** API 请求能力入口 */
|
|
225
|
+
api: ApiPort;
|
|
226
|
+
/** 事件总线能力入口 */
|
|
227
|
+
events: EventBusPort;
|
|
228
|
+
/** 存储管理能力入口 */
|
|
229
|
+
storage: PluginStorage;
|
|
230
|
+
/** 日志输出工具,自动携带插件 ID 前缀 */
|
|
231
|
+
logger: {
|
|
232
|
+
debug: (...args: any[]) => void;
|
|
233
|
+
info: (...args: any[]) => void;
|
|
234
|
+
warn: (...args: any[]) => void;
|
|
235
|
+
error: (...args: any[]) => void;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* 访问其他插件提供的服务
|
|
239
|
+
* @param serviceName - 服务注册名称
|
|
240
|
+
* @returns 服务实例,如果不存在则返回 undefined
|
|
241
|
+
*/
|
|
242
|
+
getService: <T = unknown>(serviceName: string) => T | undefined;
|
|
243
|
+
/**
|
|
244
|
+
* 注册当前插件的服务供他人使用
|
|
245
|
+
* @param serviceName - 唯一服务名称
|
|
246
|
+
* @param service - 服务实现对象
|
|
247
|
+
*/
|
|
248
|
+
registerService: <T = unknown>(serviceName: string, service: T) => void;
|
|
249
|
+
/** 宿主环境 Window 的代理对象 (用于沙箱隔离) */
|
|
250
|
+
window: WindowProxy;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* 完整的插件对象定义
|
|
254
|
+
*/
|
|
255
|
+
export interface Plugin extends PluginLifecycle {
|
|
256
|
+
/**
|
|
257
|
+
* 插件唯一标识符
|
|
258
|
+
* @description 必须与 metadata.id 一致,通常为只读。
|
|
259
|
+
*/
|
|
260
|
+
readonly id: string;
|
|
261
|
+
/** 插件元数据配置 */
|
|
262
|
+
metadata: PluginMetadata;
|
|
263
|
+
/** 插件提供的功能组件集合 (可选) */
|
|
264
|
+
components?: Record<string, any>;
|
|
265
|
+
/** 插件提供的工具函数集合 (可选) */
|
|
266
|
+
utils?: Record<string, any>;
|
|
267
|
+
/** 插件的初始默认配置 (可选) */
|
|
268
|
+
defaultConfig?: Record<string, any>;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* 插件基础类
|
|
272
|
+
* @deprecated 建议统一使用工厂模式 definePlugin() 定义插件,以消除类与对象定义的歧义。
|
|
273
|
+
* @description 解决插件定义时 id 与 metadata.id 重复定义的问题,并提供基础生命周期管理
|
|
274
|
+
*/
|
|
275
|
+
export declare abstract class BasePlugin implements Plugin {
|
|
276
|
+
abstract metadata: PluginMetadata;
|
|
277
|
+
/**
|
|
278
|
+
* 插件 ID
|
|
279
|
+
* @description 自动从 metadata.id 获取
|
|
280
|
+
*/
|
|
281
|
+
get id(): string;
|
|
282
|
+
onLoad?(context: PluginContext): void | Promise<void>;
|
|
283
|
+
onMount?(context: PluginContext): void;
|
|
284
|
+
onUnmount?(context: PluginContext): void;
|
|
285
|
+
onConfigChange?(newConfig: any, oldConfig: any): void;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* 辅助函数:定义插件并自动从 metadata.id 注入顶级 id
|
|
289
|
+
* @description 解决插件定义时 id 与 metadata.id 重复定义的问题,提高代码优雅度
|
|
290
|
+
* @param plugin 插件定义(不包含顶级 id)
|
|
291
|
+
* @returns 完整的插件对象
|
|
292
|
+
*/
|
|
293
|
+
export declare function definePlugin(plugin: Omit<Plugin, 'id'>): Plugin;
|
|
294
|
+
/**
|
|
295
|
+
* 插件元数据定义
|
|
296
|
+
* @description 描述插件的静态属性,用于插件市场展示、权限校验和内核加载参考。
|
|
297
|
+
*/
|
|
298
|
+
export interface PluginMetadata {
|
|
299
|
+
/** 插件唯一 ID (推荐反向域名格式,如 com.company.plugin) */
|
|
300
|
+
id: string;
|
|
301
|
+
/** 插件显示名称 */
|
|
302
|
+
name: string;
|
|
303
|
+
/** 插件版本号 (符合 SemVer 规范) */
|
|
304
|
+
version: string;
|
|
305
|
+
/** 插件类型 */
|
|
306
|
+
type: PluginType;
|
|
307
|
+
/** 插件功能描述 */
|
|
308
|
+
description?: string;
|
|
309
|
+
/** 插件作者信息 */
|
|
310
|
+
author?: string;
|
|
311
|
+
/** 插件图标 */
|
|
312
|
+
icon?: any;
|
|
313
|
+
/** 插件依赖的其他插件 ID 列表 */
|
|
314
|
+
dependencies?: string[];
|
|
315
|
+
/** 路由配置集合,用于在主应用中注册页面 */
|
|
316
|
+
routes?: RouteConfig[];
|
|
317
|
+
/** 插槽扩展集合,用于在主应用 UI 预留位注入组件 */
|
|
318
|
+
extensions?: PluginExtension[];
|
|
319
|
+
/** 插件所需调用的 API 接口配置 */
|
|
320
|
+
api?: ApiConfig;
|
|
321
|
+
/** 插件行为能力声明 */
|
|
322
|
+
capabilities?: PluginCapabilities;
|
|
323
|
+
/** 插件的可配置项定义 */
|
|
324
|
+
configuration?: PluginConfigItem[];
|
|
325
|
+
/** 插件所需的存储结构定义 */
|
|
326
|
+
storage?: StorageItemSchema[];
|
|
327
|
+
/**
|
|
328
|
+
* 插件优先级
|
|
329
|
+
* @description 数值越小优先级越高,用于插件加载顺序和插槽渲染顺序
|
|
330
|
+
* @default 100
|
|
331
|
+
*/
|
|
332
|
+
priority?: number;
|
|
333
|
+
/**
|
|
334
|
+
* 系统状态自动绑定
|
|
335
|
+
* @description 将插件的配置项自动同步到系统的全局状态中 (如主题色、身份认证等)
|
|
336
|
+
*/
|
|
337
|
+
systemStateBindings?: {
|
|
338
|
+
/** 插件配置中的键名 */
|
|
339
|
+
configKey: string;
|
|
340
|
+
/** 系统全局状态中的键名 */
|
|
341
|
+
stateKey: string;
|
|
342
|
+
/** 预设的转换逻辑名称 */
|
|
343
|
+
transform?: 'theme-mode' | 'identity';
|
|
344
|
+
}[];
|
|
345
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 存储端口接口
|
|
3
|
+
* @description 定义数据持久化的标准契约,兼容 Web Storage API。
|
|
4
|
+
*/
|
|
5
|
+
export interface StoragePort {
|
|
6
|
+
/**
|
|
7
|
+
* 获取存储项
|
|
8
|
+
* @param key - 键名
|
|
9
|
+
* @returns 对应的值,如果不存在则返回 null
|
|
10
|
+
*/
|
|
11
|
+
getItem(key: string): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* 设置存储项
|
|
14
|
+
* @param key - 键名
|
|
15
|
+
* @param value - 键值 (字符串)
|
|
16
|
+
*/
|
|
17
|
+
setItem(key: string, value: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* 移除指定的存储项
|
|
20
|
+
* @param key - 键名
|
|
21
|
+
*/
|
|
22
|
+
removeItem(key: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* 清空所有存储项
|
|
25
|
+
*/
|
|
26
|
+
clear(): void;
|
|
27
|
+
/**
|
|
28
|
+
* 返回存储对象中当前存储的数据项总数
|
|
29
|
+
*/
|
|
30
|
+
readonly length: number;
|
|
31
|
+
/**
|
|
32
|
+
* 根据索引返回存储中对应键的名称
|
|
33
|
+
* @param index - 数值索引
|
|
34
|
+
* @returns 键名,如果索引超出范围则返回 null
|
|
35
|
+
*/
|
|
36
|
+
key(index: number): string | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 类型化存储接口
|
|
40
|
+
* @description 提供泛型支持的存储访问能力,自动处理序列化
|
|
41
|
+
*/
|
|
42
|
+
export interface TypedStorage {
|
|
43
|
+
/** 获取存储数据 */
|
|
44
|
+
get: <T = any>(key: string) => T | null;
|
|
45
|
+
/** 设置存储数据 */
|
|
46
|
+
set: <T = any>(key: string, value: T) => void;
|
|
47
|
+
/** 移除存储数据 */
|
|
48
|
+
remove: (key: string) => void;
|
|
49
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { CacheEntry, CacheOptions } from './RemotePluginSource.js';
|
|
2
|
+
/**
|
|
3
|
+
* 远程缓存管理器
|
|
4
|
+
* @description 管理远程插件Manifest的缓存,支持TTL和大小限制
|
|
5
|
+
*/
|
|
6
|
+
export declare class RemoteCache<T = any> {
|
|
7
|
+
private cache;
|
|
8
|
+
private defaultTtl;
|
|
9
|
+
/**
|
|
10
|
+
* 创建远程缓存管理器
|
|
11
|
+
* @param options 缓存配置选项
|
|
12
|
+
*/
|
|
13
|
+
constructor(options?: CacheOptions);
|
|
14
|
+
/**
|
|
15
|
+
* 获取缓存条目
|
|
16
|
+
* @param key 缓存键
|
|
17
|
+
* @returns 缓存条目,如果不存在或已过期返回 undefined
|
|
18
|
+
*/
|
|
19
|
+
get(key: string): CacheEntry<T> | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* 设置缓存条目
|
|
22
|
+
* @param key 缓存键
|
|
23
|
+
* @param data 要缓存的数据
|
|
24
|
+
* @param ttl 自定义 TTL (毫秒),使用默认 TTL 如果未指定
|
|
25
|
+
*/
|
|
26
|
+
set(key: string, data: T, ttl?: number): void;
|
|
27
|
+
/**
|
|
28
|
+
* 删除缓存条目
|
|
29
|
+
* @param key 缓存键
|
|
30
|
+
* @returns 是否成功删除
|
|
31
|
+
*/
|
|
32
|
+
delete(key: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* 清空所有缓存
|
|
35
|
+
*/
|
|
36
|
+
clear(): void;
|
|
37
|
+
/**
|
|
38
|
+
* 检查缓存键是否存在
|
|
39
|
+
* @param key 缓存键
|
|
40
|
+
*/
|
|
41
|
+
has(key: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* 获取缓存条目数量
|
|
44
|
+
*/
|
|
45
|
+
size(): number;
|
|
46
|
+
/**
|
|
47
|
+
* 获取缓存条目的元数据(不触发访问时间更新)
|
|
48
|
+
* @param key 缓存键
|
|
49
|
+
*/
|
|
50
|
+
getMetadata(key: string): CacheEntry<T> | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* 更新缓存 TTL
|
|
53
|
+
* @param key 缓存键
|
|
54
|
+
* @param ttl 新 TTL (毫秒)
|
|
55
|
+
*/
|
|
56
|
+
updateTTL(key: string, ttl: number): boolean;
|
|
57
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { PluginManifest } from '../manifest/PluginManifest.js';
|
|
2
|
+
import type { LoadResult, RemotePluginSource, RemoteSourceOptions } from './RemotePluginSource.js';
|
|
3
|
+
/**
|
|
4
|
+
* 远程插件加载器
|
|
5
|
+
* @description 管理远程插件源的添加、移除和 Manifest 加载
|
|
6
|
+
*/
|
|
7
|
+
export declare class RemoteLoader {
|
|
8
|
+
private sources;
|
|
9
|
+
private cache;
|
|
10
|
+
private retryStrategy;
|
|
11
|
+
private options;
|
|
12
|
+
/**
|
|
13
|
+
* 创建远程加载器
|
|
14
|
+
* @param options 远程源配置选项
|
|
15
|
+
*/
|
|
16
|
+
constructor(options?: RemoteSourceOptions);
|
|
17
|
+
/**
|
|
18
|
+
* 添加远程插件源
|
|
19
|
+
* @param source 远程插件源
|
|
20
|
+
*/
|
|
21
|
+
addSource(source: RemotePluginSource): void;
|
|
22
|
+
/**
|
|
23
|
+
* 移除远程插件源
|
|
24
|
+
* @param sourceId 插件源 ID
|
|
25
|
+
* @returns 是否成功移除
|
|
26
|
+
*/
|
|
27
|
+
removeSource(sourceId: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* 获取所有远程插件源
|
|
30
|
+
* @returns 远程插件源列表
|
|
31
|
+
*/
|
|
32
|
+
getSources(): RemotePluginSource[];
|
|
33
|
+
/**
|
|
34
|
+
* 获取指定远程插件源
|
|
35
|
+
* @param sourceId 插件源 ID
|
|
36
|
+
*/
|
|
37
|
+
getSource(sourceId: string): RemotePluginSource | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* 启用/禁用远程插件源
|
|
40
|
+
* @param sourceId 插件源 ID
|
|
41
|
+
* @param enabled 是否启用
|
|
42
|
+
*/
|
|
43
|
+
setSourceEnabled(sourceId: string, enabled: boolean): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 从远程加载插件 Manifest
|
|
46
|
+
* @param sourceId 插件源 ID
|
|
47
|
+
* @returns 加载结果
|
|
48
|
+
*/
|
|
49
|
+
loadManifest<T = PluginManifest>(sourceId: string): Promise<LoadResult<T>>;
|
|
50
|
+
/**
|
|
51
|
+
* 带重试的请求
|
|
52
|
+
* @param url 请求 URL
|
|
53
|
+
* @param attempt 当前尝试次数
|
|
54
|
+
* @returns 响应数据
|
|
55
|
+
*/
|
|
56
|
+
private fetchWithRetry;
|
|
57
|
+
/**
|
|
58
|
+
* 处理加载错误
|
|
59
|
+
* @param error 错误对象
|
|
60
|
+
* @returns 错误结果
|
|
61
|
+
*/
|
|
62
|
+
private handleLoadError;
|
|
63
|
+
/**
|
|
64
|
+
* 创建错误结果
|
|
65
|
+
* @param code 错误代码
|
|
66
|
+
* @param message 错误消息
|
|
67
|
+
* @param retryable 是否可重试
|
|
68
|
+
* @returns 错误结果
|
|
69
|
+
*/
|
|
70
|
+
private createErrorResult;
|
|
71
|
+
/**
|
|
72
|
+
* 清除缓存
|
|
73
|
+
* @param sourceId 可选,指定源 ID(只清除该源的缓存)
|
|
74
|
+
*/
|
|
75
|
+
clearCache(sourceId?: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* 获取缓存大小
|
|
78
|
+
*/
|
|
79
|
+
getCacheSize(): number;
|
|
80
|
+
/**
|
|
81
|
+
* 睡眠
|
|
82
|
+
* @param ms 毫秒数
|
|
83
|
+
*/
|
|
84
|
+
private sleep;
|
|
85
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote Plugin Source 类型定义
|
|
3
|
+
* @description 定义远程插件源接口和配置选项
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 远程插件源
|
|
7
|
+
* @description 表示一个远程插件仓库地址
|
|
8
|
+
*/
|
|
9
|
+
export interface RemotePluginSource {
|
|
10
|
+
/** 唯一标识符 */
|
|
11
|
+
id: string;
|
|
12
|
+
/** 显示名称 */
|
|
13
|
+
name: string;
|
|
14
|
+
/** plugin.json URL */
|
|
15
|
+
url: string;
|
|
16
|
+
/** 是否启用 */
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 缓存配置选项
|
|
21
|
+
*/
|
|
22
|
+
export interface CacheOptions {
|
|
23
|
+
/** 缓存 TTL (毫秒),默认 5 分钟 */
|
|
24
|
+
ttl: number;
|
|
25
|
+
/** 最大缓存条目数 */
|
|
26
|
+
maxSize?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 重试配置选项
|
|
30
|
+
*/
|
|
31
|
+
export interface RetryOptions {
|
|
32
|
+
/** 最大重试次数 */
|
|
33
|
+
maxRetries: number;
|
|
34
|
+
/** 重试延迟 (毫秒) */
|
|
35
|
+
retryDelay: number;
|
|
36
|
+
/** 自定义重试条件 */
|
|
37
|
+
retryCondition?: (error: any) => boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 远程源配置选项
|
|
41
|
+
*/
|
|
42
|
+
export interface RemoteSourceOptions {
|
|
43
|
+
/** 请求超时 (毫秒) */
|
|
44
|
+
timeout?: number;
|
|
45
|
+
/** 重试配置 */
|
|
46
|
+
retry?: RetryOptions;
|
|
47
|
+
/** 缓存配置 */
|
|
48
|
+
cache?: CacheOptions;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 缓存条目元数据
|
|
52
|
+
*/
|
|
53
|
+
export interface CacheEntry<T = any> {
|
|
54
|
+
/** 缓存数据 */
|
|
55
|
+
data: T;
|
|
56
|
+
/** 创建时间戳 */
|
|
57
|
+
createdAt: number;
|
|
58
|
+
/** 最后访问时间戳 */
|
|
59
|
+
lastAccessedAt: number;
|
|
60
|
+
/** 过期时间戳 */
|
|
61
|
+
expiresAt: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 加载结果
|
|
65
|
+
*/
|
|
66
|
+
export interface LoadResult<T = any> {
|
|
67
|
+
/** 是否成功 */
|
|
68
|
+
success: boolean;
|
|
69
|
+
/** 加载的数据 */
|
|
70
|
+
data?: T;
|
|
71
|
+
/** 加载错误 */
|
|
72
|
+
error?: LoadError;
|
|
73
|
+
/** 是否来自缓存 */
|
|
74
|
+
fromCache?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 加载错误
|
|
78
|
+
*/
|
|
79
|
+
export interface LoadError {
|
|
80
|
+
/** 错误代码 */
|
|
81
|
+
code: 'NETWORK' | 'TIMEOUT' | 'PARSE' | 'NOT_FOUND' | 'CACHE_ERROR' | 'VALIDATION_ERROR';
|
|
82
|
+
/** 错误消息 */
|
|
83
|
+
message: string;
|
|
84
|
+
/** 是否可重试 */
|
|
85
|
+
retryable: boolean;
|
|
86
|
+
/** 原始错误 */
|
|
87
|
+
originalError?: any;
|
|
88
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry Strategy 实现
|
|
3
|
+
* @description 提供重试延迟计算和错误判断逻辑
|
|
4
|
+
*/
|
|
5
|
+
import type { RetryOptions } from './RemotePluginSource.js';
|
|
6
|
+
/**
|
|
7
|
+
* 重试策略类
|
|
8
|
+
* @description 计算重试延迟、判断错误是否可重试
|
|
9
|
+
*/
|
|
10
|
+
export declare class RetryStrategy {
|
|
11
|
+
private defaultOptions;
|
|
12
|
+
/**
|
|
13
|
+
* 创建重试策略
|
|
14
|
+
* @param options 重试配置选项
|
|
15
|
+
*/
|
|
16
|
+
constructor(options?: RetryOptions);
|
|
17
|
+
/**
|
|
18
|
+
* 计算重试延迟(指数退避)
|
|
19
|
+
* @param attempt 当前尝试次数 (从 1 开始)
|
|
20
|
+
* @returns 延迟毫秒数
|
|
21
|
+
*/
|
|
22
|
+
calculateDelay(attempt: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* 判断错误是否可重试
|
|
25
|
+
* @param error 错误对象
|
|
26
|
+
* @returns 是否可重试
|
|
27
|
+
*/
|
|
28
|
+
isRetryable(error: any): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* 默认重试条件判断
|
|
31
|
+
* @param error 错误对象
|
|
32
|
+
* @returns 是否可重试
|
|
33
|
+
*/
|
|
34
|
+
private defaultRetryCondition;
|
|
35
|
+
/**
|
|
36
|
+
* 获取最大重试次数
|
|
37
|
+
*/
|
|
38
|
+
getMaxRetries(): number;
|
|
39
|
+
/**
|
|
40
|
+
* 获取基础重试延迟
|
|
41
|
+
*/
|
|
42
|
+
getBaseDelay(): number;
|
|
43
|
+
}
|