@chatbi-v/core 1.0.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 (38) hide show
  1. package/README.md +36 -0
  2. package/dist/adapters/local-storage-adapter.d.ts +13 -0
  3. package/dist/adapters/scoped-storage-adapter.d.ts +18 -0
  4. package/dist/api/adapters/axios-adapter.d.ts +10 -0
  5. package/dist/api/engine.d.ts +41 -0
  6. package/dist/api/index.d.ts +6 -0
  7. package/dist/api/utils.d.ts +14 -0
  8. package/dist/api-context.d.ts +8 -0
  9. package/dist/application/service-registry.d.ts +34 -0
  10. package/dist/components/PluginErrorBoundary.d.ts +22 -0
  11. package/dist/components/PluginSlot.d.ts +22 -0
  12. package/dist/components/SlotSkeletons.d.ts +10 -0
  13. package/dist/config-manager.d.ts +30 -0
  14. package/dist/domain/auto-loader.d.ts +37 -0
  15. package/dist/domain/models.d.ts +9 -0
  16. package/dist/domain/plugin-manager.d.ts +143 -0
  17. package/dist/domain/plugin-runtime.d.ts +34 -0
  18. package/dist/domain/plugin-sandbox.d.ts +27 -0
  19. package/dist/domain/storage-manager.d.ts +46 -0
  20. package/dist/event-bus.d.ts +38 -0
  21. package/dist/hooks/use-plugin-loader.d.ts +20 -0
  22. package/dist/hooks/use-storage-state.d.ts +15 -0
  23. package/dist/index.cjs +2265 -0
  24. package/dist/index.d.ts +24 -0
  25. package/dist/index.mjs +2210 -0
  26. package/dist/plugin-context.d.ts +8 -0
  27. package/dist/ports/api-port.d.ts +71 -0
  28. package/dist/ports/event-bus-port.d.ts +30 -0
  29. package/dist/ports/plugin-port.d.ts +192 -0
  30. package/dist/ports/storage-port.d.ts +19 -0
  31. package/dist/sandbox/proxy-sandbox.d.ts +45 -0
  32. package/dist/sandbox/style-isolation.d.ts +13 -0
  33. package/dist/testing/plugin-contract.d.ts +6 -0
  34. package/dist/utils/date.d.ts +32 -0
  35. package/dist/utils/index.d.ts +4 -0
  36. package/dist/utils/logger.d.ts +69 -0
  37. package/dist/utils/stream-parser.d.ts +26 -0
  38. package/package.json +39 -0
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @chatbi-v/core
2
+
3
+ ChatBI 核心模块,提供插件管理、基础设施接口及通用 API 引擎。
4
+
5
+ ## 架构原则 (Architecture Principles)
6
+
7
+ - **业务无关性 (Business Agnostic)**: `core` 包禁止包含任何具体的业务模型、业务逻辑或业务常量。
8
+ - **共享契约 (Shared Contract)**: `core` 只定义通用的技术契约(如 `Plugin`, `StoragePort`, `ApiAdapter`)。
9
+ - **插件驱动 (Plugin Driven)**: 所有的业务逻辑应由插件实现。
10
+
11
+ ## 目录结构
12
+
13
+ - `adapters/`: 基础设施的具体实现(如 LocalStorage, Axios)。
14
+ - `api/`: 通用 API 请求引擎。
15
+ - `domain/`: 核心领域逻辑(插件管理器、运行时、沙箱)。
16
+ - `ports/`: 核心接口定义(端口)。
17
+
18
+ ## 功能
19
+
20
+ - **PluginManager**: 管理插件的注册和生命周期。
21
+ - **ApiEngine**: 统一的 API 请求管理。
22
+ - **Sandbox**: 提供插件运行时的样式和全局变量隔离。
23
+
24
+ ## 使用方法
25
+
26
+ ```typescript
27
+ import { pluginManager } from '@chatbi/core';
28
+
29
+ // 注册插件
30
+ pluginManager.register({
31
+ id: 'my-plugin',
32
+ init: (context) => {
33
+ console.log('Plugin initialized');
34
+ },
35
+ });
36
+ ```
@@ -0,0 +1,13 @@
1
+ import { StoragePort } from '../ports/storage-port';
2
+ export declare class LocalStorageAdapter implements StoragePort {
3
+ private prefix;
4
+ constructor(prefix?: string);
5
+ private getKey;
6
+ private getOriginalKey;
7
+ getItem(key: string): string | null;
8
+ setItem(key: string, value: string): void;
9
+ removeItem(key: string): void;
10
+ clear(): void;
11
+ get length(): number;
12
+ key(index: number): string | null;
13
+ }
@@ -0,0 +1,18 @@
1
+ import { StoragePort } from '../ports/storage-port';
2
+ /**
3
+ * 作用域存储适配器
4
+ * 包装现有的 StoragePort 并为所有键应用命名空间前缀。
5
+ */
6
+ export declare class ScopedStorageAdapter implements StoragePort {
7
+ private underlyingStorage;
8
+ private prefix;
9
+ constructor(underlyingStorage: StoragePort, prefix: string);
10
+ private getKey;
11
+ private getOriginalKey;
12
+ getItem(key: string): string | null;
13
+ setItem(key: string, value: string): void;
14
+ removeItem(key: string): void;
15
+ clear(): void;
16
+ get length(): number;
17
+ key(index: number): string | null;
18
+ }
@@ -0,0 +1,10 @@
1
+ import { ApiAdapter, ApiEndpointConfig, ApiRequestConfig, StreamCallbacks } from '../../ports/api-port';
2
+ /**
3
+ * 基于 Axios 的默认请求适配器
4
+ */
5
+ export declare class AxiosAdapter implements ApiAdapter {
6
+ private client;
7
+ constructor(baseURL?: string, timeout?: number);
8
+ request<T = any>(config: ApiRequestConfig): Promise<T>;
9
+ stream(config: ApiRequestConfig, callbacks: StreamCallbacks, endpointConfig?: ApiEndpointConfig): Promise<void>;
10
+ }
@@ -0,0 +1,41 @@
1
+ import { ApiAdapter, ApiConfig, ApiEndpointConfig, RequestOptions } from '../ports/api-port';
2
+ /**
3
+ * API 引擎核心类
4
+ * @description 负责加载配置并执行请求,支持策略模式切换底层请求实现
5
+ */
6
+ export declare class ApiEngine {
7
+ private adapter;
8
+ private config;
9
+ constructor(adapter?: ApiAdapter);
10
+ /**
11
+ * 切换请求适配器
12
+ * @param adapter 新的适配器实例
13
+ */
14
+ useAdapter(adapter: ApiAdapter): void;
15
+ /**
16
+ * 注册 API 配置
17
+ * @param config 配置对象
18
+ */
19
+ register(config: ApiConfig): void;
20
+ /**
21
+ * 获取接口配置
22
+ */
23
+ getEndpoint(module: string, action: string): ApiEndpointConfig | undefined;
24
+ /**
25
+ * 发起 API 请求
26
+ * @param module 模块名
27
+ * @param action 动作名
28
+ * @param data 请求数据 (Body 或 Query)
29
+ * @param options 请求选项
30
+ */
31
+ call<T = any>(module: string, action: string, data?: any, options?: RequestOptions): Promise<T>;
32
+ /**
33
+ * 发起流式请求
34
+ * @param module 模块名
35
+ * @param action 动作名
36
+ * @param data 请求数据
37
+ * @param options 请求选项
38
+ */
39
+ stream(module: string, action: string, data?: any, options?: RequestOptions): Promise<void>;
40
+ }
41
+ export declare const apiEngine: ApiEngine;
@@ -0,0 +1,6 @@
1
+ export * from './adapters/axios-adapter';
2
+ export * from './engine';
3
+ export * from './utils';
4
+ export * from '../domain/models';
5
+ export * from '../ports/api-port';
6
+ export * from '../ports/plugin-port';
@@ -0,0 +1,14 @@
1
+ import { ApiConfig } from '../ports/api-port';
2
+ /**
3
+ * 自动检测是否处于 Mock 模式
4
+ */
5
+ export declare function isMockMode(): boolean;
6
+ /**
7
+ * 从文件模块映射中解析 API 配置
8
+ * @description 配合 Vite 的 import.meta.glob 使用,自动匹配定义文件和 Mock 文件
9
+ * @param definitionsMap API 定义文件映射 (import.meta.glob('./modules/*.ts', { eager: true }))
10
+ * @param mocksMap Mock 文件映射 (import.meta.glob('./modules/*.mock.ts', { eager: true }))
11
+ * @param useMock 是否启用 Mock (如果不传,将自动调用 isMockMode())
12
+ * @returns 合并后的 ApiConfig
13
+ */
14
+ export declare function resolveApiModules(definitionsMap: Record<string, any>, mocksMap?: Record<string, any>): ApiConfig;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { ApiEngine } from './api';
3
+ export interface ApiProviderProps {
4
+ api: ApiEngine;
5
+ children: React.ReactNode;
6
+ }
7
+ export declare const ApiProvider: React.FC<ApiProviderProps>;
8
+ export declare const useApi: () => ApiEngine;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 服务注册中心
3
+ * @description 实现插件间的解耦通信。插件可以注册服务,其他插件可以通过名称获取服务。
4
+ */
5
+ export declare class ServiceRegistry {
6
+ private services;
7
+ private listeners;
8
+ /**
9
+ * 注册服务
10
+ * @param name 服务名称 (建议格式: pluginId.serviceName)
11
+ * @param service 服务实现
12
+ */
13
+ register(name: string, service: any): void;
14
+ /**
15
+ * 获取服务
16
+ * @param name 服务名称
17
+ */
18
+ get<T = any>(name: string): T | undefined;
19
+ /**
20
+ * 异步获取服务 (如果尚未注册则等待)
21
+ * @param name 服务名称
22
+ */
23
+ waitFor<T = any>(name: string): Promise<T>;
24
+ /**
25
+ * 注销服务
26
+ * @param name 服务名称
27
+ */
28
+ unregister(name: string): void;
29
+ /**
30
+ * 清除所有服务 (通常在系统重置时使用)
31
+ */
32
+ clear(): void;
33
+ }
34
+ export declare const serviceRegistry: ServiceRegistry;
@@ -0,0 +1,22 @@
1
+ import React, { Component, ErrorInfo, ReactNode } from 'react';
2
+ interface Props {
3
+ pluginId?: string;
4
+ fallback?: ReactNode;
5
+ children: ReactNode;
6
+ }
7
+ interface State {
8
+ hasError: boolean;
9
+ error: Error | null;
10
+ }
11
+ /**
12
+ * 插件错误边界组件
13
+ * @description 捕获子组件错误,防止单个插件崩溃导致整个应用崩溃
14
+ */
15
+ export declare class PluginErrorBoundary extends Component<Props, State> {
16
+ constructor(props: Props);
17
+ static getDerivedStateFromError(error: Error): State;
18
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
19
+ handleRetry: () => void;
20
+ render(): string | number | boolean | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
21
+ }
22
+ export {};
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import type { PluginExtension, SlotPosition } from '../api';
3
+ interface PluginSlotProps {
4
+ /** 插槽位置标识 */
5
+ slot: SlotPosition;
6
+ /** 传递给扩展组件的 Props */
7
+ props?: Record<string, any>;
8
+ /** 自定义容器类名 */
9
+ className?: string;
10
+ /** 自定义容器样式 */
11
+ style?: React.CSSProperties;
12
+ /** 渲染器自定义 (可选) */
13
+ renderItem?: (item: {
14
+ key: string;
15
+ component: React.ReactNode;
16
+ extension: PluginExtension;
17
+ }, index: number) => React.ReactNode;
18
+ /** 骨架屏组件 (当没有插件扩展时显示) */
19
+ skeleton?: React.ReactNode;
20
+ }
21
+ export declare const PluginSlot: React.FC<PluginSlotProps>;
22
+ export {};
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ /**
3
+ * 通用插槽骨架屏组件集合
4
+ */
5
+ export declare const SidebarIconSkeleton: React.FC;
6
+ export declare const StatusBarItemSkeleton: React.FC;
7
+ export declare const AvatarSkeleton: React.FC;
8
+ export declare const BlockSkeleton: React.FC<{
9
+ className?: string;
10
+ }>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 配置管理器
3
+ * @description 负责管理应用的全局配置和插件配置
4
+ */
5
+ export declare class ConfigManager {
6
+ /** 存储配置的 Map */
7
+ private config;
8
+ /**
9
+ * 设置配置项
10
+ * @param key 配置键
11
+ * @param value 配置值
12
+ */
13
+ set(key: string, value: any): void;
14
+ /**
15
+ * 获取配置项
16
+ * @param key 配置键
17
+ */
18
+ get(key: string): any;
19
+ /**
20
+ * 合并配置
21
+ * @param config 配置对象
22
+ */
23
+ merge(config: Record<string, any>): void;
24
+ /**
25
+ * 获取所有配置
26
+ */
27
+ getAll(): Record<string, any>;
28
+ }
29
+ /** 全局配置管理器单例 */
30
+ export declare const configManager: ConfigManager;
@@ -0,0 +1,37 @@
1
+ export interface PluginRegistry {
2
+ [pluginId: string]: () => Promise<any>;
3
+ }
4
+ export interface DiscoveryRule {
5
+ /**
6
+ * 插件发现的 Glob 模式 (例如: '@chatbi-plugins/*\/src/index.{ts,tsx}')
7
+ */
8
+ pattern: string;
9
+ /**
10
+ * 路径标识部分(用于从绝对路径中提取 ID,例如 'packages/plugins')
11
+ */
12
+ pathSegment: string;
13
+ /**
14
+ * 生成插件 ID 时的前缀
15
+ */
16
+ idPrefix: string;
17
+ /**
18
+ * 可选的别名映射
19
+ */
20
+ alias?: string;
21
+ }
22
+ /**
23
+ * 自动发现并解析插件
24
+ * @description 将 Vite 的 glob 导入结果解析为符合 PluginManager 要求的注册表
25
+ */
26
+ export declare const resolvePluginRegistry: (options: {
27
+ modules: Record<string, () => Promise<any>>;
28
+ baseUrl: string;
29
+ rules: DiscoveryRule[];
30
+ }) => PluginRegistry;
31
+ /**
32
+ * 核心插件发现方法
33
+ * @description 该方法应在应用层被调用,但逻辑集成在 core 中。
34
+ * 注意:由于 Vite import.meta.glob 必须使用字面量的限制,
35
+ * 这里使用一个覆盖范围合理的模式,并通过 rules 进行精确匹配。
36
+ */
37
+ export declare const discoverPlugins: (rules: DiscoveryRule[], baseUrl: string) => PluginRegistry;
@@ -0,0 +1,9 @@
1
+ export declare const SUCCESS_CODE = "000000";
2
+ /**
3
+ * 基础响应接口
4
+ */
5
+ export interface BaseResponse<T = any> {
6
+ code: string | number;
7
+ message: string;
8
+ data: T;
9
+ }
@@ -0,0 +1,143 @@
1
+ import { DefaultEventBus } from '../event-bus';
2
+ import { Plugin, PluginExtension, RouteConfig, SlotPosition } from '../ports/plugin-port';
3
+ import { StoragePort } from '../ports/storage-port';
4
+ import { StorageManager } from './storage-manager';
5
+ /**
6
+ * 插件管理器
7
+ * @description 负责插件的加载、注册和生命周期管理
8
+ */
9
+ export declare class PluginManager {
10
+ /** 全局事件总线 */
11
+ readonly eventBus: DefaultEventBus;
12
+ /** 存储接口 */
13
+ private storageManager;
14
+ /** 所有插件运行时实例 */
15
+ private runtimes;
16
+ /** 所有注册的插件(原始数据) */
17
+ private plugins;
18
+ /** 收集的路由 */
19
+ private routes;
20
+ /** 收集的扩展点 */
21
+ private extensions;
22
+ /** 插件状态管理(启用/禁用、排序) */
23
+ private pluginStates;
24
+ /** 状态变更监听器 */
25
+ private listeners;
26
+ /** 共享上下文缓存 */
27
+ private sharedContext;
28
+ /** 收集的工具函数 */
29
+ private utils;
30
+ constructor(storage: StoragePort);
31
+ private loadStates;
32
+ private saveStates;
33
+ /**
34
+ * 订阅插件状态变更
35
+ * @param listener 监听函数
36
+ * @returns 取消订阅函数
37
+ */
38
+ subscribe(listener: () => void): () => void;
39
+ getStorageManager(): StorageManager;
40
+ /**
41
+ * 触发状态变更通知
42
+ */
43
+ private notify;
44
+ /**
45
+ * 获取所有已注册的插件
46
+ */
47
+ getPlugins(): Plugin[];
48
+ /**
49
+ * 获取插件状态
50
+ * @param pluginId 插件 ID
51
+ */
52
+ getPluginState(pluginId: string): {
53
+ enabled: boolean;
54
+ order: number;
55
+ };
56
+ /**
57
+ * 检查插件是否启用
58
+ * @param pluginId 插件 ID
59
+ */
60
+ isPluginEnabled(pluginId: string): boolean;
61
+ /**
62
+ * 切换插件启用状态
63
+ * @param pluginId 插件 ID
64
+ * @param enabled 是否启用
65
+ */
66
+ togglePlugin(pluginId: string, enabled: boolean): void;
67
+ /**
68
+ * 设置插件排序
69
+ * @param pluginId 插件 ID
70
+ * @param order 排序值
71
+ */
72
+ setPluginOrder(pluginId: string, order: number): void;
73
+ /**
74
+ * 获取插件的统一能力描述
75
+ * @param pluginId 插件 ID
76
+ */
77
+ getUnifiedCapabilities(pluginId: string): import("..").PluginCapabilities;
78
+ /**
79
+ * 更新插件配置
80
+ * @param pluginId 插件 ID
81
+ * @param key 配置项 Key
82
+ * @param value 配置值
83
+ */
84
+ updatePluginConfig(pluginId: string, key: string, value: any): void;
85
+ /**
86
+ * 获取插件配置
87
+ * @param pluginId 插件 ID
88
+ * @param key 配置键
89
+ * @returns 配置值
90
+ */
91
+ getPluginConfig(pluginId: string, key: string): any;
92
+ /**
93
+ * 获取指定插槽的扩展
94
+ * @param slot 插槽位置
95
+ */
96
+ getExtensions(slot: SlotPosition | string): PluginExtension[];
97
+ /**
98
+ * 获取所有收集到的路由
99
+ */
100
+ getRoutes(): RouteConfig[];
101
+ /**
102
+ * 注册插件
103
+ * @param plugin 插件实例
104
+ * @param notify 是否触发状态变更通知
105
+ */
106
+ register(plugin: Plugin, notify?: boolean): void;
107
+ /**
108
+ * 初始化所有插件
109
+ * @param sharedContext 共享上下文
110
+ */
111
+ initPlugins(sharedContext?: Record<string, any>): Promise<void>;
112
+ /**
113
+ * 获取排序后的插件 ID 列表 (处理依赖)
114
+ */
115
+ private getSortedPluginIds;
116
+ /**
117
+ * 加载插件列表
118
+ * @param configs 插件配置
119
+ * @param registry 插件注册表 (动态导入函数)
120
+ */
121
+ loadPlugins(configs: Record<string, any>, registry: Record<string, () => Promise<any>>): Promise<void>;
122
+ /**
123
+ * 加载远程插件
124
+ * @param pluginId 插件 ID
125
+ * @param url 远程 URL
126
+ * @param config 插件配置
127
+ */
128
+ loadRemotePlugin(pluginId: string, url: string, config: any): Promise<Plugin | null>;
129
+ /**
130
+ * 实例化插件
131
+ */
132
+ private instantiatePlugin;
133
+ private validatePlugin;
134
+ private handleBusinessPlugin;
135
+ private handleFunctionalPlugin;
136
+ private handleViewPlugin;
137
+ private handleThemePlugin;
138
+ private handleSystemPlugin;
139
+ }
140
+ /**
141
+ * 全局插件管理器实例
142
+ */
143
+ export declare const pluginManager: PluginManager;
@@ -0,0 +1,34 @@
1
+ import { Plugin, PluginContext } from '../ports/plugin-port';
2
+ import { StorageManager } from './storage-manager';
3
+ /**
4
+ * 插件运行时
5
+ * @description 封装单个插件的生命周期、沙箱和状态
6
+ */
7
+ export declare class PluginRuntime {
8
+ plugin: Plugin;
9
+ context: PluginContext;
10
+ private storageSandbox;
11
+ private windowSandbox;
12
+ private isLoaded;
13
+ private isMounted;
14
+ constructor(plugin: Plugin, sharedContext: Record<string, any>, storageManager: StorageManager);
15
+ /**
16
+ * 加载插件 (onLoad)
17
+ * @description 注册服务、初始化非 UI 逻辑
18
+ */
19
+ load(): Promise<void>;
20
+ /**
21
+ * 挂载插件 (onMount)
22
+ * @description 激活沙箱、处理 UI 相关的副作用
23
+ */
24
+ mount(): Promise<void>;
25
+ /**
26
+ * 卸载插件 (onUnmount)
27
+ */
28
+ unmount(): Promise<void>;
29
+ /**
30
+ * 销毁插件 (完全移除)
31
+ */
32
+ destroy(): Promise<void>;
33
+ get status(): "mounted" | "loaded" | "initial";
34
+ }
@@ -0,0 +1,27 @@
1
+ import { StorageManager } from './storage-manager';
2
+ /**
3
+ * 插件沙箱
4
+ * @description 为插件提供隔离的运行时环境
5
+ */
6
+ export declare class PluginSandbox {
7
+ private pluginId;
8
+ private storageManager;
9
+ constructor(pluginId: string, storageManager: StorageManager);
10
+ /**
11
+ * 获取隔离的存储接口
12
+ */
13
+ get storage(): {
14
+ shared: {
15
+ get: <T = any>(key: string) => T | null;
16
+ set: <T = any>(key: string, value: T) => void;
17
+ remove: (key: string) => void;
18
+ };
19
+ get: <T = any>(key: string) => T | null;
20
+ set: <T = any>(key: string, value: T) => void;
21
+ remove: (key: string) => void;
22
+ };
23
+ /**
24
+ * 获取隔离的日志接口
25
+ */
26
+ get logger(): import("..").Logger;
27
+ }
@@ -0,0 +1,46 @@
1
+ import { StorageItemSchema } from '../ports/plugin-port';
2
+ import { StoragePort } from '../ports/storage-port';
3
+ /**
4
+ * 存储管理器
5
+ * @description 统一管理系统、插件和共享存储
6
+ */
7
+ export declare class StorageManager {
8
+ private baseStorage;
9
+ private schemas;
10
+ constructor(baseStorage: StoragePort);
11
+ /**
12
+ * 注册插件存储 Schema
13
+ */
14
+ registerSchema(pluginId: string, schema: StorageItemSchema[]): void;
15
+ /**
16
+ * 验证 Key 是否符合 Schema 定义 (仅在开发环境或严格模式下警告)
17
+ */
18
+ private validateKey;
19
+ /**
20
+ * 获取插件专用存储适配器
21
+ * @param pluginId 插件 ID
22
+ */
23
+ getPluginStorage(pluginId: string): StoragePort;
24
+ /**
25
+ * 获取共享存储适配器
26
+ */
27
+ getSharedStorage(): StoragePort;
28
+ /**
29
+ * 获取系统存储适配器
30
+ */
31
+ getSystemStorage(): StoragePort;
32
+ /**
33
+ * 获取插件上下文中的 storage 对象 (包含类型转换辅助方法)
34
+ * @param pluginId 插件 ID
35
+ */
36
+ getContextStorage(pluginId: string): {
37
+ shared: {
38
+ get: <T = any>(key: string) => T | null;
39
+ set: <T = any>(key: string, value: T) => void;
40
+ remove: (key: string) => void;
41
+ };
42
+ get: <T = any>(key: string) => T | null;
43
+ set: <T = any>(key: string, value: T) => void;
44
+ remove: (key: string) => void;
45
+ };
46
+ }
@@ -0,0 +1,38 @@
1
+ export type EventCallback = (...args: any[]) => any;
2
+ /**
3
+ * 事件总线接口
4
+ */
5
+ export interface EventBus {
6
+ /**
7
+ * 订阅事件
8
+ * @param event 事件名称
9
+ * @param callback 回调函数
10
+ * @returns 取消订阅函数
11
+ */
12
+ on(event: string, callback: EventCallback): () => void;
13
+ /**
14
+ * 取消订阅
15
+ * @param event 事件名称
16
+ * @param callback 回调函数
17
+ */
18
+ off(event: string, callback: EventCallback): void;
19
+ /**
20
+ * 触发事件
21
+ * @param event 事件名称
22
+ * @param args 事件参数
23
+ */
24
+ emit(event: string, ...args: any[]): void;
25
+ /**
26
+ * 订阅一次性事件
27
+ * @param event 事件名称
28
+ * @param callback 回调函数
29
+ */
30
+ once(event: string, callback: EventCallback): void;
31
+ }
32
+ export declare class DefaultEventBus implements EventBus {
33
+ private listeners;
34
+ on(event: string, callback: EventCallback): () => void;
35
+ off(event: string, callback: EventCallback): void;
36
+ emit(event: string, ...args: any[]): void;
37
+ once(event: string, callback: EventCallback): void;
38
+ }
@@ -0,0 +1,20 @@
1
+ export interface PluginLoaderOptions {
2
+ /** 插件发现规则 */
3
+ discoveryRules?: any[];
4
+ /** 预注册的插件注册表 (可选,用于离线或手动加载) */
5
+ registry?: Record<string, () => Promise<any>>;
6
+ /** 插件配置映射 */
7
+ pluginConfigs: Record<string, any>;
8
+ /** 初始化的上下文服务 (如 api, events 等) */
9
+ sharedContext?: Record<string, any>;
10
+ /** 发现的基础 URL */
11
+ baseUrl?: string;
12
+ }
13
+ /**
14
+ * 通用插件加载 Hook
15
+ * @description 负责插件的自动发现、加载、初始化和状态订阅
16
+ */
17
+ export declare const usePluginLoader: (options: PluginLoaderOptions) => {
18
+ pluginsLoaded: boolean;
19
+ pluginVersion: number;
20
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Hook options
3
+ */
4
+ export interface UseStorageStateOptions<T> {
5
+ defaultValue?: T;
6
+ scope?: 'plugin' | 'shared';
7
+ }
8
+ /**
9
+ * Unified Storage State Hook
10
+ * @description Provides a persistent state hook that integrates with the StorageManager and Schema Registry.
11
+ * @param pluginId The plugin ID defining the key
12
+ * @param key The storage key (must be registered in schema)
13
+ * @param options Options including default value and scope
14
+ */
15
+ export declare function useStorageState<T>(pluginId: string, key: string, options?: UseStorageStateOptions<T>): [T, (value: T | ((val: T) => T)) => void];