@chatbi-v/core 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/chunk-QET56C3T.mjs +51 -0
  2. package/dist/chunk-QET56C3T.mjs.map +1 -0
  3. package/dist/config-manager-3TKURRUT.mjs +9 -0
  4. package/dist/config-manager-3TKURRUT.mjs.map +1 -0
  5. package/dist/index.d.mts +1748 -0
  6. package/dist/index.d.ts +1745 -27
  7. package/dist/index.js +2833 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/index.mjs +2685 -7
  10. package/dist/index.mjs.map +1 -0
  11. package/package.json +3 -3
  12. package/dist/adapters/local-storage-adapter.d.ts +0 -61
  13. package/dist/adapters/scoped-storage-adapter.d.ts +0 -61
  14. package/dist/api/adapters/axios-adapter.d.ts +0 -10
  15. package/dist/api/engine.d.ts +0 -87
  16. package/dist/api/index.d.ts +0 -6
  17. package/dist/api/utils.d.ts +0 -14
  18. package/dist/api-context.d.ts +0 -8
  19. package/dist/application/service-registry.d.ts +0 -57
  20. package/dist/chunk-O74KYN5N.mjs +0 -1
  21. package/dist/components/PluginErrorBoundary.d.ts +0 -44
  22. package/dist/components/PluginSlot.d.ts +0 -35
  23. package/dist/components/SlotSkeletons.d.ts +0 -27
  24. package/dist/config-manager-LQITPSUA.mjs +0 -1
  25. package/dist/config-manager.d.ts +0 -34
  26. package/dist/domain/auto-loader.d.ts +0 -36
  27. package/dist/domain/models.d.ts +0 -42
  28. package/dist/domain/plugin-manager.d.ts +0 -215
  29. package/dist/domain/plugin-runtime.d.ts +0 -70
  30. package/dist/domain/plugin-sandbox.d.ts +0 -40
  31. package/dist/domain/storage-manager.d.ts +0 -74
  32. package/dist/event-bus.d.ts +0 -38
  33. package/dist/hooks/use-plugin-loader.d.ts +0 -35
  34. package/dist/hooks/use-storage-state.d.ts +0 -15
  35. package/dist/index.cjs +0 -12
  36. package/dist/plugin-context.d.ts +0 -8
  37. package/dist/ports/api-port.d.ts +0 -132
  38. package/dist/ports/event-bus-port.d.ts +0 -32
  39. package/dist/ports/plugin-port.d.ts +0 -308
  40. package/dist/ports/storage-port.d.ts +0 -49
  41. package/dist/sandbox/proxy-sandbox.d.ts +0 -45
  42. package/dist/sandbox/style-isolation.d.ts +0 -13
  43. package/dist/utils/date.d.ts +0 -32
  44. package/dist/utils/index.d.ts +0 -4
  45. package/dist/utils/logger.d.ts +0 -79
  46. package/dist/utils/url.d.ts +0 -16
@@ -1,308 +0,0 @@
1
- import React from 'react';
2
- import { ApiConfig } from './api-port';
3
- import { EventBusPort } from './event-bus-port';
4
- import { TypedStorage } from './storage-port';
5
- /**
6
- * 插件类型定义
7
- */
8
- export declare const PLUGIN_TYPES: readonly ["business", "functional", "view", "theme", "renderer", "system"];
9
- export type PluginType = typeof PLUGIN_TYPES[number];
10
- /**
11
- * 路由配置
12
- */
13
- export interface RouteConfig {
14
- path: string;
15
- component: React.ComponentType<any>;
16
- meta?: Record<string, any>;
17
- }
18
- /**
19
- * 插件插槽位置
20
- * @description 定义插件可以注入 UI 的标准位置
21
- */
22
- export declare const Slot: {
23
- readonly Sidebar: "sidebar";
24
- readonly SidebarPanel: "sidebar-panel";
25
- readonly Header: "header";
26
- readonly StatusBar: "status-bar";
27
- readonly Settings: "settings";
28
- readonly MessageRenderer: "message-renderer";
29
- readonly MessageContentRenderer: "message-content-renderer";
30
- readonly SidebarSystem: "sidebar-system";
31
- readonly SidebarBottom: "sidebar-bottom";
32
- readonly RootLayout: "root-layout";
33
- readonly Custom: "custom";
34
- };
35
- export type SlotType = typeof Slot[keyof typeof Slot];
36
- export type SlotPosition = SlotType | string;
37
- /**
38
- * 插件扩展 (插槽注入配置)
39
- */
40
- export interface PluginExtension {
41
- /** 插槽位置标识符 */
42
- slot: SlotPosition;
43
- /** 要注入的 React 组件 */
44
- component: React.ComponentType<any>;
45
- /** 排序权重,数值越小越靠前 */
46
- order?: number;
47
- /** @internal 插件 ID,由系统在加载时自动注入,用于溯源 */
48
- _pluginId?: string;
49
- /** 扩展的元数据信息 */
50
- meta?: {
51
- /** 显示图标 */
52
- icon?: React.ReactNode;
53
- /** 显示标签文本 */
54
- label?: string;
55
- /** 详细描述 */
56
- description?: string;
57
- /** 唯一标识符,用于某些特定插槽的索引 */
58
- key?: string;
59
- /** 允许其他自定义属性 */
60
- [key: string]: any;
61
- };
62
- }
63
- /**
64
- * 插件配置项定义
65
- */
66
- export interface PluginConfigItem {
67
- /** 配置键名 */
68
- key: string;
69
- /** 配置类型 */
70
- type: 'string' | 'number' | 'boolean' | 'select';
71
- /** 配置显示的标签 */
72
- label: string;
73
- /** 配置描述信息 */
74
- description?: string;
75
- /** 默认值 */
76
- default?: any;
77
- /** 当类型为 select 时的选项列表 */
78
- options?: {
79
- label: string;
80
- value: any;
81
- }[];
82
- /** 选择模式:支持多选或标签模式 (AntD 风格) */
83
- mode?: 'multiple' | 'tags';
84
- /** 最小值 (针对 number 类型) */
85
- min?: number;
86
- /** 最大值 (针对 number 类型) */
87
- max?: number;
88
- }
89
- /**
90
- * 插件能力定义 (Behavioral Capabilities)
91
- * @description 定义插件的行为特征。注意:路由(routes)和扩展(extensions)属于结构化能力,直接通过 metadata 字段声明,不在此列。
92
- */
93
- export interface PluginCapabilities {
94
- /**
95
- * 是否支持配置设置
96
- * @default false (如果 metadata.configuration 存在,则可能被隐式视为 true,建议显式声明)
97
- */
98
- configurable?: boolean;
99
- /**
100
- * 是否可嵌入其他页面
101
- * @description 声明该插件是否可以作为 Widget 被其他插件引用
102
- */
103
- embeddable?: boolean;
104
- /**
105
- * 是否支持多实例
106
- * @description 默认为 false (单例)。如果在聊天窗口中每个会话都需要独立状态,则设为 true
107
- */
108
- multiInstance?: boolean;
109
- /**
110
- * 是否需要后台运行
111
- * @description 如果为 true,即使 UI 不可见,插件也不会被卸载
112
- */
113
- background?: boolean;
114
- [key: string]: boolean | undefined;
115
- }
116
- /**
117
- * 存储项数据结构定义 (Schema)
118
- */
119
- export interface StorageItemSchema {
120
- /** 存储键名 */
121
- key: string;
122
- /** 数据类型 */
123
- type: 'string' | 'number' | 'boolean' | 'object' | 'array';
124
- /** 默认值 */
125
- default?: any;
126
- /** 描述信息 */
127
- description?: string;
128
- /**
129
- * 作用域
130
- * @description 'plugin' 表示仅当前插件可见(带插件 ID 前缀),'shared' 表示全局共享
131
- */
132
- scope?: 'plugin' | 'shared';
133
- }
134
- /**
135
- * 插件存储接口
136
- * @description 包含私有存储和共享存储访问能力
137
- */
138
- export interface PluginStorage extends TypedStorage {
139
- /** 获取插件私有存储数据 */
140
- get: TypedStorage['get'];
141
- /** 设置插件私有存储数据 */
142
- set: TypedStorage['set'];
143
- /** 移除插件私有存储数据 */
144
- remove: TypedStorage['remove'];
145
- /** 全局共享存储访问 */
146
- shared: TypedStorage & {
147
- /** 获取全局共享存储数据 */
148
- get: TypedStorage['get'];
149
- /** 设置全局共享存储数据 */
150
- set: TypedStorage['set'];
151
- /** 移除全局共享存储数据 */
152
- remove: TypedStorage['remove'];
153
- };
154
- }
155
- /**
156
- * 插件生命周期 Hooks
157
- * @description 插件可以在不同的生命周期阶段执行特定的逻辑
158
- */
159
- export interface PluginLifecycle {
160
- /**
161
- * 插件加载时调用
162
- * @description 在插件被扫描并注入内核时触发。用于初始化内部状态、注册服务、设置拦截器等。此时 UI 尚未挂载。
163
- * @param context - 插件上下文对象,提供核心能力的访问
164
- */
165
- onLoad?: (context: PluginContext) => void | Promise<void>;
166
- /**
167
- * 插件挂载到 UI 时调用
168
- * @description 当插件的 UI 组件(如有)被 React 挂载到 DOM 时触发。
169
- * @param context - 插件上下文对象
170
- */
171
- onMount?: (context: PluginContext) => void;
172
- /**
173
- * 插件从 UI 卸载时调用
174
- * @description 当插件的 UI 组件被销毁时触发。用于清理定时器、取消订阅等。
175
- * @param context - 插件上下文对象
176
- */
177
- onUnmount?: (context: PluginContext) => void;
178
- /**
179
- * 插件配置发生变化时调用
180
- * @description 当用户通过配置中心修改插件设置时触发。
181
- * @param newConfig - 变更后的新配置对象
182
- * @param oldConfig - 变更前的旧配置对象
183
- */
184
- onConfigChange?: (newConfig: any, oldConfig: any) => void;
185
- }
186
- /**
187
- * 插件上下文
188
- * @description 传递给插件生命周期钩子的核心对象,是插件访问宿主环境能力的唯一入口。
189
- */
190
- export interface PluginContext {
191
- /** 当前插件的唯一标识符 */
192
- pluginId: string;
193
- /** API 请求能力入口 */
194
- api: any;
195
- /** 事件总线能力入口 */
196
- events: EventBusPort;
197
- /** 存储管理能力入口 */
198
- storage: PluginStorage;
199
- /** 日志输出工具,自动携带插件 ID 前缀 */
200
- logger: {
201
- debug: (...args: any[]) => void;
202
- info: (...args: any[]) => void;
203
- warn: (...args: any[]) => void;
204
- error: (...args: any[]) => void;
205
- };
206
- /**
207
- * 访问其他插件提供的服务
208
- * @param serviceName - 服务注册名称
209
- * @returns 服务实例,如果不存在则返回 undefined
210
- */
211
- getService: <T = any>(serviceName: string) => T | undefined;
212
- /**
213
- * 注册当前插件的服务供他人使用
214
- * @param serviceName - 唯一服务名称
215
- * @param service - 服务实现对象
216
- */
217
- registerService: (serviceName: string, service: any) => void;
218
- /** 宿主环境 Window 的代理对象 (用于沙箱隔离) */
219
- window: WindowProxy;
220
- }
221
- /**
222
- * 完整的插件对象定义
223
- */
224
- export interface Plugin extends PluginLifecycle {
225
- /**
226
- * 插件唯一标识符
227
- * @description 必须与 metadata.id 一致,通常为只读。
228
- */
229
- readonly id: string;
230
- /** 插件元数据配置 */
231
- metadata: PluginMetadata;
232
- /** 插件提供的功能组件集合 (可选) */
233
- components?: Record<string, React.ComponentType<any>>;
234
- /** 插件提供的工具函数集合 (可选) */
235
- utils?: Record<string, any>;
236
- /** 插件的初始默认配置 (可选) */
237
- defaultConfig?: Record<string, any>;
238
- }
239
- /**
240
- * 插件基础类
241
- * @deprecated 建议统一使用工厂模式 definePlugin() 定义插件,以消除类与对象定义的歧义。
242
- * @description 解决插件定义时 id 与 metadata.id 重复定义的问题,并提供基础生命周期管理
243
- */
244
- export declare abstract class BasePlugin implements Plugin {
245
- abstract metadata: PluginMetadata;
246
- /**
247
- * 插件 ID
248
- * @description 自动从 metadata.id 获取
249
- */
250
- get id(): string;
251
- onLoad?(context: PluginContext): void | Promise<void>;
252
- onMount?(context: PluginContext): void;
253
- onUnmount?(context: PluginContext): void;
254
- onConfigChange?(newConfig: any, oldConfig: any): void;
255
- }
256
- /**
257
- * 辅助函数:定义插件并自动从 metadata.id 注入顶级 id
258
- * @description 解决插件定义时 id 与 metadata.id 重复定义的问题,提高代码优雅度
259
- * @param plugin 插件定义(不包含顶级 id)
260
- * @returns 完整的插件对象
261
- */
262
- export declare function definePlugin(plugin: Omit<Plugin, 'id'>): Plugin;
263
- /**
264
- * 插件元数据定义
265
- * @description 描述插件的静态属性,用于插件市场展示、权限校验和内核加载参考。
266
- */
267
- export interface PluginMetadata {
268
- /** 插件唯一 ID (推荐反向域名格式,如 com.company.plugin) */
269
- id: string;
270
- /** 插件显示名称 */
271
- name: string;
272
- /** 插件版本号 (符合 SemVer 规范) */
273
- version: string;
274
- /** 插件类型 */
275
- type: PluginType;
276
- /** 插件功能描述 */
277
- description?: string;
278
- /** 插件作者信息 */
279
- author?: string;
280
- /** 插件图标 (React 组件或图标名称) */
281
- icon?: React.ReactNode;
282
- /** 插件依赖的其他插件 ID 列表 */
283
- dependencies?: string[];
284
- /** 路由配置集合,用于在主应用中注册页面 */
285
- routes?: RouteConfig[];
286
- /** 插槽扩展集合,用于在主应用 UI 预留位注入组件 */
287
- extensions?: PluginExtension[];
288
- /** 插件所需调用的 API 接口配置 */
289
- api?: ApiConfig;
290
- /** 插件行为能力声明 */
291
- capabilities?: PluginCapabilities;
292
- /** 插件的可配置项定义 */
293
- configuration?: PluginConfigItem[];
294
- /** 插件所需的存储结构定义 */
295
- storage?: StorageItemSchema[];
296
- /**
297
- * 系统状态自动绑定
298
- * @description 将插件的配置项自动同步到系统的全局状态中 (如主题色、身份认证等)
299
- */
300
- systemStateBindings?: {
301
- /** 插件配置中的键名 */
302
- configKey: string;
303
- /** 系统全局状态中的键名 */
304
- stateKey: string;
305
- /** 预设的转换逻辑名称 */
306
- transform?: 'theme-mode' | 'identity';
307
- }[];
308
- }
@@ -1,49 +0,0 @@
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
- }
@@ -1,45 +0,0 @@
1
- /**
2
- * ProxySandbox 类
3
- * @description 基于 Proxy 的 JS 沙箱实现,模拟独立的 Window 环境
4
- */
5
- export declare class ProxySandbox {
6
- /** 沙箱名称 */
7
- name: string;
8
- /** 代理后的 Window 对象 */
9
- proxy: WindowProxy;
10
- /** 沙箱是否激活 */
11
- running: boolean;
12
- /** 记录新增/修改的全局变量 */
13
- private updatedValueSet;
14
- /** 副作用记录池 */
15
- private effectPool;
16
- /** 真实的 Window 对象 */
17
- private globalContext;
18
- /** 白名单全局变量(允许透传访问真实 Window) */
19
- private static globalWhitelist;
20
- constructor(name: string, globalContext?: Window & typeof globalThis);
21
- /**
22
- * 激活沙箱
23
- */
24
- active(): void;
25
- /**
26
- * 销毁沙箱
27
- */
28
- inactive(): void;
29
- /**
30
- * 在沙箱中执行代码
31
- * @param code JS 代码字符串
32
- * @returns 执行结果
33
- */
34
- eval(code: string): any;
35
- /**
36
- * 创建伪造的 Window 对象
37
- */
38
- private createFakeWindow;
39
- private isConstructor;
40
- private isNativeFunction;
41
- /**
42
- * 劫持全局副作用 API
43
- */
44
- private patchGlobalEffects;
45
- }
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- interface SandboxContainerProps {
3
- children?: React.ReactNode;
4
- name: string;
5
- className?: string;
6
- style?: React.CSSProperties;
7
- }
8
- /**
9
- * 样式隔离容器
10
- * @description 使用 Shadow DOM 实现完全的样式隔离
11
- */
12
- export declare const SandboxContainer: React.FC<SandboxContainerProps>;
13
- export {};
@@ -1,32 +0,0 @@
1
- import dayjs from 'dayjs';
2
- import 'dayjs/locale/zh-cn';
3
- /**
4
- * 日期时间格式化工具类
5
- */
6
- export declare const dateUtils: {
7
- /**
8
- * 格式化日期为 YYYY-MM-DD
9
- */
10
- formatDate(date?: dayjs.ConfigType): string;
11
- /**
12
- * 格式化时间为 HH:mm:ss
13
- */
14
- formatTime(date?: dayjs.ConfigType): string;
15
- /**
16
- * 格式化日期时间为 YYYY-MM-DD HH:mm:ss
17
- */
18
- formatDateTime(date?: dayjs.ConfigType): string;
19
- /**
20
- * 获取当前时间戳(毫秒)
21
- */
22
- now(): number;
23
- /**
24
- * 获取相对时间(例如:几分钟前)
25
- */
26
- fromNow(date: dayjs.ConfigType): string;
27
- /**
28
- * 原始 dayjs 对象,用于更复杂的场景
29
- */
30
- dayjs: typeof dayjs;
31
- };
32
- export default dateUtils;
@@ -1,4 +0,0 @@
1
- export * from './logger';
2
- export * from './date';
3
- export * from './url';
4
- export declare const version = "1.0.0";
@@ -1,79 +0,0 @@
1
- /**
2
- * 日志等级枚举
3
- */
4
- export declare enum LogLevel {
5
- /** 调试级别:输出最详尽的信息 */
6
- DEBUG = 0,
7
- /** 信息级别:输出重要的运行状态 */
8
- INFO = 1,
9
- /** 警告级别:输出潜在的问题,但不影响运行 */
10
- WARN = 2,
11
- /** 错误级别:输出严重的运行异常 */
12
- ERROR = 3,
13
- /** 禁用日志:不输出任何信息 */
14
- NONE = 4
15
- }
16
- /**
17
- * 日志工具类
18
- * @description 核心工具类,提供统一的日志输出格式 `[Prefix] Message`。
19
- * 支持通过 `LogLevel` 进行全局过滤,在生产环境下建议设置为 WARN 或以上。
20
- */
21
- export declare class Logger {
22
- /** 全局静态日志等级,所有实例共享 */
23
- private static level;
24
- /** 当前实例的业务模块前缀 */
25
- private prefix;
26
- /**
27
- * 构造函数
28
- * @param prefix - 业务模块前缀,默认为 'App'
29
- */
30
- constructor(prefix?: string);
31
- /**
32
- * 静态方法:设置全局日志输出等级
33
- * @param level - 目标日志等级
34
- */
35
- static setLevel(level: LogLevel): void;
36
- /**
37
- * 静态方法:获取当前全局日志等级
38
- * @returns 当前生效的全局日志等级
39
- */
40
- static getLevel(): LogLevel;
41
- /**
42
- * 打印 DEBUG 级别日志
43
- * @description 仅在 LogLevel <= DEBUG 时输出
44
- */
45
- get debug(): (...args: any[]) => void;
46
- /**
47
- * 打印 INFO 级别日志
48
- * @description 仅在 LogLevel <= INFO 时输出
49
- */
50
- get info(): (...args: any[]) => void;
51
- /**
52
- * 打印 WARN 级别日志
53
- * @description 仅在 LogLevel <= WARN 时输出
54
- */
55
- get warn(): (...args: any[]) => void;
56
- /**
57
- * 打印 ERROR 级别日志
58
- * @description 仅在 LogLevel <= ERROR 时输出
59
- */
60
- get error(): (...args: any[]) => void;
61
- /**
62
- * 开始一个日志控制台分组
63
- * @param label - 分组显示的标签名
64
- * @param collapsed - 是否默认折叠显示,默认为 false
65
- */
66
- group(label: string, collapsed?: boolean): void;
67
- /**
68
- * 结束当前日志控制台分组
69
- */
70
- get groupEnd(): () => void;
71
- }
72
- /** 默认 Logger 实例 */
73
- export declare const logger: Logger;
74
- /**
75
- * 创建带特定前缀的 Logger 实例
76
- * @param prefix 日志前缀
77
- * @returns Logger 实例
78
- */
79
- export declare const createLogger: (prefix: string) => Logger;
@@ -1,16 +0,0 @@
1
- type KeepStrategy = 'first' | 'last' | 'search' | 'hash';
2
- /**
3
- * 把当前地址中所有出现的参数合并成一份。
4
- * 重复 key 的处理策略:
5
- * - 'first' : 按出现顺序,第一次的值生效
6
- * - 'last' : 按出现顺序,最后一次的值生效(默认,最直观)
7
- * - 'search' : 只要 search 里出现过,就用 search 的
8
- * - 'hash' : 只要 hash 里出现过,就用 hash 的
9
- */
10
- export declare function normalizeParams(strategy?: KeepStrategy): URLSearchParams;
11
- /**
12
- * 清除 URL 中的特定参数并返回新的 URL
13
- * @description 同时处理 search 和 hash 中的参数
14
- */
15
- export declare function cleanUrlParams(keysToRemove: string[]): string;
16
- export {};