@chatbi-v/core 2.0.1 → 2.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.
package/README.md CHANGED
@@ -2,35 +2,60 @@
2
2
 
3
3
  ChatBI 核心模块,提供插件管理、基础设施接口及通用 API 引擎。
4
4
 
5
- ## 架构原则 (Architecture Principles)
5
+ ## 模块功能说明
6
6
 
7
- - **业务无关性 (Business Agnostic)**: `core` 包禁止包含任何具体的业务模型、业务逻辑或业务常量。
8
- - **共享契约 (Shared Contract)**: `core` 只定义通用的技术契约(如 `Plugin`, `StoragePort`, `ApiAdapter`)。
9
- - **插件驱动 (Plugin Driven)**: 所有的业务逻辑应由插件实现。
7
+ - **微内核架构**: 实现插件的注册、生命周期管理与隔离。
8
+ - **领域驱动设计**: 严格区分领域逻辑 (`domain`)、外部接口 (`ports`) 和具体实现 (`adapters`)。
9
+ - **API 引擎**: 统一的 API 请求管理,支持同步、流式请求及拦截器。
10
+ - **存储管理**: 提供隔离的存储适配器,确保插件数据互不干扰。
10
11
 
11
- ## 目录结构
12
+ ## 安装和使用方法
12
13
 
13
- - `adapters/`: 基础设施的具体实现(如 LocalStorage, Axios)。
14
- - `api/`: 通用 API 请求引擎。
15
- - `domain/`: 核心领域逻辑(插件管理器、运行时、沙箱)。
16
- - `ports/`: 核心接口定义(端口)。
17
-
18
- ## 功能
14
+ ### 安装
19
15
 
20
- - **PluginManager**: 管理插件的注册和生命周期。
21
- - **ApiEngine**: 统一的 API 请求管理。支持请求拦截器 (`ApiInterceptor`),且拦截器能力已覆盖普通请求 (`call`) 和流式请求 (`stream`)。
22
- - **Sandbox**: 提供插件运行时的样式和全局变量隔离。
16
+ ```bash
17
+ pnpm add @chatbi-v/core
18
+ ```
23
19
 
24
- ## 使用方法
20
+ ### 使用示例
25
21
 
26
22
  ```typescript
27
- import { pluginManager } from '@chatbi/core';
23
+ import { PluginManager, LocalStorageAdapter } from '@chatbi-v/core';
24
+
25
+ // 初始化插件管理器
26
+ const storage = new LocalStorageAdapter();
27
+ const pluginManager = new PluginManager(storage);
28
28
 
29
- // 注册插件
29
+ // 注册并初始化插件
30
30
  pluginManager.register({
31
31
  id: 'my-plugin',
32
- init: (context) => {
33
- console.log('Plugin initialized');
34
- },
32
+ metadata: { name: 'My Plugin', type: 'business' },
33
+ onLoad: async (context) => {
34
+ console.log('Plugin loaded', context.pluginId);
35
+ }
35
36
  });
36
37
  ```
38
+
39
+ ## API 文档链接
40
+
41
+ 详细 API 文档请参考 [docs/index.html](https://github.com/your-repo/docs/index.html) 或运行 `npm run docs:dev` 本地查看。
42
+
43
+ ## 开发注意事项
44
+
45
+ - **禁止引入 UI 框架**: 本模块为纯逻辑层,不得包含 React/AntD 等 UI 依赖。
46
+ - **禁止反向依赖**: `core` 不得依赖 `plugins` 或 `apps` 中的任何代码。
47
+ - **类型安全**: 优先使用 `ports` 中定义的接口。
48
+
49
+ ## 架构原则 (Architecture Principles)
50
+
51
+ - **业务无关性 (Business Agnostic)**: `core` 包禁止包含任何具体的业务模型、业务逻辑或业务常量。
52
+ - **共享契约 (Shared Contract)**: `core` 只定义通用的技术契约(如 `Plugin`, `StoragePort`, `ApiAdapter`)。
53
+ - **插件驱动 (Plugin Driven)**: 所有的业务逻辑应由插件实现。
54
+
55
+ ## 目录结构
56
+
57
+ - `adapters/`: 基础设施的具体实现(如 LocalStorage, Axios)。
58
+ - `api/`: 通用 API 请求引擎。
59
+ - `domain/`: 核心领域逻辑(插件管理器、运行时、沙箱)。
60
+ - `ports/`: 核心接口定义(端口)。
61
+ - `utils/`: 通用工具函数。
@@ -0,0 +1,47 @@
1
+ // src/config-manager.ts
2
+ var ConfigManager = class {
3
+ /** 存储配置的 Map */
4
+ config = /* @__PURE__ */ new Map();
5
+ /**
6
+ * 设置配置项
7
+ * @param key 配置键
8
+ * @param value 配置值
9
+ */
10
+ set(key, value) {
11
+ this.config.set(key, value);
12
+ }
13
+ /**
14
+ * 获取配置项
15
+ * @param key 配置键
16
+ */
17
+ get(key) {
18
+ return this.config.get(key);
19
+ }
20
+ /**
21
+ * 合并配置
22
+ * @param config 配置对象
23
+ */
24
+ merge(config) {
25
+ Object.keys(config).forEach((key) => {
26
+ const existing = this.config.get(key);
27
+ const incoming = config[key];
28
+ if (existing && typeof existing === "object" && incoming && typeof incoming === "object") {
29
+ this.config.set(key, { ...existing, ...incoming });
30
+ } else {
31
+ this.config.set(key, incoming);
32
+ }
33
+ });
34
+ }
35
+ /**
36
+ * 获取所有配置
37
+ */
38
+ getAll() {
39
+ return Object.fromEntries(this.config);
40
+ }
41
+ };
42
+ var configManager = new ConfigManager();
43
+
44
+ export {
45
+ ConfigManager,
46
+ configManager
47
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ConfigManager,
3
3
  configManager
4
- } from "./chunk-IOE2RMEZ.mjs";
4
+ } from "./chunk-G3OU7D3Y.mjs";
5
5
  export {
6
6
  ConfigManager,
7
7
  configManager
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file plugin-manager.ts
3
+ * @description 插件管理器,负责插件的注册、生命周期管理、状态持久化及扩展点收集
4
+ * @author ChatBI Team
5
+ */
1
6
  import { DefaultEventBus } from '../event-bus';
2
7
  import { Plugin, PluginExtension, RouteConfig, SlotPosition } from '../ports/plugin-port';
3
8
  import { StoragePort } from '../ports/storage-port';
@@ -133,6 +138,10 @@ export declare class PluginManager {
133
138
  * @param config 插件配置
134
139
  */
135
140
  loadRemotePlugin(pluginId: string, url: string, config: any): Promise<Plugin | null>;
141
+ /**
142
+ * IIFE 模式加载插件
143
+ */
144
+ private loadIIFEPlugin;
136
145
  /**
137
146
  * 实例化插件
138
147
  */
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file plugin-runtime.ts
3
+ * @description 插件运行时,封装单个插件的生命周期(load/mount/unmount)、沙箱环境和隔离上下文
4
+ * @author ChatBI Team
5
+ */
1
6
  import { Plugin, PluginContext } from '../ports/plugin-port';
2
7
  import { StorageManager } from './storage-manager';
3
8
  /**
package/dist/index.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file index.ts
3
+ * @description Core 模块入口文件,导出所有公共 API、领域逻辑、组件和 Hooks
4
+ * @author ChatBI Team
5
+ */
1
6
  export * from './ports/api-port';
2
7
  export * from './ports/event-bus-port';
3
8
  export * from './ports/plugin-port';
@@ -19,6 +24,7 @@ export * from './adapters/scoped-storage-adapter';
19
24
  export * from './event-bus';
20
25
  export * from './plugin-context';
21
26
  export * from './api';
27
+ export * from './sandbox/proxy-sandbox';
22
28
  export * from './utils';
23
29
  export * from './hooks/use-storage-state';
24
30
  export * from './hooks/use-plugin-loader';