@chatbi-v/core 2.0.5 → 2.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.
Files changed (41) hide show
  1. package/dist/chunk-4AJ6VW5G.mjs +50 -0
  2. package/dist/config-manager-F3GYW4BE.mjs +8 -0
  3. package/dist/index.js +2805 -0
  4. package/dist/index.mjs +2658 -7
  5. package/package.json +3 -3
  6. package/dist/adapters/local-storage-adapter.d.ts +0 -61
  7. package/dist/adapters/scoped-storage-adapter.d.ts +0 -61
  8. package/dist/api/adapters/axios-adapter.d.ts +0 -10
  9. package/dist/api/engine.d.ts +0 -87
  10. package/dist/api/index.d.ts +0 -6
  11. package/dist/api/utils.d.ts +0 -14
  12. package/dist/api-context.d.ts +0 -8
  13. package/dist/application/service-registry.d.ts +0 -57
  14. package/dist/chunk-O74KYN5N.mjs +0 -1
  15. package/dist/components/PluginErrorBoundary.d.ts +0 -44
  16. package/dist/components/PluginSlot.d.ts +0 -35
  17. package/dist/components/SlotSkeletons.d.ts +0 -27
  18. package/dist/config-manager-LQITPSUA.mjs +0 -1
  19. package/dist/config-manager.d.ts +0 -34
  20. package/dist/domain/auto-loader.d.ts +0 -36
  21. package/dist/domain/models.d.ts +0 -42
  22. package/dist/domain/plugin-manager.d.ts +0 -215
  23. package/dist/domain/plugin-runtime.d.ts +0 -70
  24. package/dist/domain/plugin-sandbox.d.ts +0 -40
  25. package/dist/domain/storage-manager.d.ts +0 -74
  26. package/dist/event-bus.d.ts +0 -38
  27. package/dist/hooks/use-plugin-loader.d.ts +0 -35
  28. package/dist/hooks/use-storage-state.d.ts +0 -15
  29. package/dist/index.cjs +0 -12
  30. package/dist/index.d.ts +0 -30
  31. package/dist/plugin-context.d.ts +0 -8
  32. package/dist/ports/api-port.d.ts +0 -132
  33. package/dist/ports/event-bus-port.d.ts +0 -32
  34. package/dist/ports/plugin-port.d.ts +0 -302
  35. package/dist/ports/storage-port.d.ts +0 -37
  36. package/dist/sandbox/proxy-sandbox.d.ts +0 -45
  37. package/dist/sandbox/style-isolation.d.ts +0 -13
  38. package/dist/utils/date.d.ts +0 -32
  39. package/dist/utils/index.d.ts +0 -4
  40. package/dist/utils/logger.d.ts +0 -79
  41. package/dist/utils/url.d.ts +0 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatbi-v/core",
3
- "version": "2.0.5",
3
+ "version": "2.1.1",
4
4
  "main": "dist/index.cjs",
5
5
  "files": [
6
6
  "dist"
@@ -30,8 +30,8 @@
30
30
  "@types/react-dom": "^18.3.0",
31
31
  "tsup": "^8.5.1",
32
32
  "vite": "^5.4.21",
33
- "@chatbi-v/cli": "2.0.5",
34
- "@chatbi-v/tsconfig": "2.0.5"
33
+ "@chatbi-v/cli": "2.1.1",
34
+ "@chatbi-v/config": "2.1.1"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "chatbi-cli build",
@@ -1,61 +0,0 @@
1
- import { StoragePort } from '../ports/storage-port';
2
- /**
3
- * 浏览器本地存储 (LocalStorage) 适配器
4
- * @description 实现 `StoragePort` 接口,封装了对原生 `localStorage` 的访问。
5
- * 支持可选的命名空间前缀隔离,确保在同一个域下不同模块的数据互不干扰。
6
- */
7
- export declare class LocalStorageAdapter implements StoragePort {
8
- /** 命名空间前缀,所有存入的键名都会自动添加此前缀 */
9
- private prefix;
10
- /**
11
- * 初始化适配器
12
- * @param prefix - 可选的命名空间前缀(如 'chatbi'),默认为空字符串
13
- */
14
- constructor(prefix?: string);
15
- /**
16
- * 内部方法:计算实际存储的键名
17
- * @param key - 业务层传入的原始键名
18
- * @returns 拼接前缀后的物理键名
19
- */
20
- private getKey;
21
- /**
22
- * 内部方法:从物理键名还原业务键名
23
- * @param namespacedKey - 物理存储中的完整键名
24
- * @returns 还原后的原始键名,若前缀不匹配则返回 null
25
- */
26
- private getOriginalKey;
27
- /**
28
- * 读取存储项
29
- * @param key - 原始键名
30
- * @returns 存储的字符串内容,不存在则返回 null
31
- */
32
- getItem(key: string): string | null;
33
- /**
34
- * 写入存储项
35
- * @param key - 原始键名
36
- * @param value - 待存储的字符串值
37
- */
38
- setItem(key: string, value: string): void;
39
- /**
40
- * 移除特定的存储项
41
- * @param key - 原始键名
42
- */
43
- removeItem(key: string): void;
44
- /**
45
- * 清空存储空间
46
- * @description
47
- * - 若定义了前缀:仅删除以该前缀开头的键名,不影响其他数据。
48
- * - 若未定义前缀:调用原生 `localStorage.clear()` 清空所有数据。
49
- */
50
- clear(): void;
51
- /**
52
- * 返回当前命名空间下的存储项总数
53
- */
54
- get length(): number;
55
- /**
56
- * 根据索引获取对应的原始键名
57
- * @param index - 索引位置
58
- * @returns 对应的业务键名,不存在则返回 null
59
- */
60
- key(index: number): string | null;
61
- }
@@ -1,61 +0,0 @@
1
- import { StoragePort } from '../ports/storage-port';
2
- /**
3
- * 作用域存储适配器 (ScopedStorageAdapter)
4
- * @description 采用装饰器模式实现。它包装一个现有的 `StoragePort` 实例,
5
- * 并为所有存储操作透明地注入一个前缀(命名空间),从而实现逻辑上的存储隔离。
6
- * 常用于为插件分配独立的存储空间,而无需修改插件代码。
7
- */
8
- export declare class ScopedStorageAdapter implements StoragePort {
9
- private underlyingStorage;
10
- private prefix;
11
- /**
12
- * 初始化作用域适配器
13
- * @param underlyingStorage - 被装饰的底层存储适配器实例
14
- * @param prefix - 用于隔离的作用域前缀字符串
15
- */
16
- constructor(underlyingStorage: StoragePort, prefix: string);
17
- /**
18
- * 内部方法:计算实际存储的键名
19
- * @param key - 业务层传入的原始键名
20
- * @returns 拼接前缀后的物理键名
21
- */
22
- private getKey;
23
- /**
24
- * 内部方法:从物理键名还原业务键名
25
- * @param namespacedKey - 物理存储中的完整键名
26
- * @returns 还原后的原始键名,若前缀不匹配则返回 null
27
- */
28
- private getOriginalKey;
29
- /**
30
- * 读取当前作用域下的存储项
31
- * @param key - 原始键名
32
- * @returns 字符串内容,不存在则返回 null
33
- */
34
- getItem(key: string): string | null;
35
- /**
36
- * 写入当前作用域下的存储项
37
- * @param key - 原始键名
38
- * @param value - 字符串内容
39
- */
40
- setItem(key: string, value: string): void;
41
- /**
42
- * 移除当前作用域下的特定存储项
43
- * @param key - 原始键名
44
- */
45
- removeItem(key: string): void;
46
- /**
47
- * 清空当前作用域下的所有存储项
48
- * @description 仅删除匹配当前前缀的键值对,不会影响底层存储中的其他数据。
49
- */
50
- clear(): void;
51
- /**
52
- * 返回当前作用域下的存储项总数
53
- */
54
- get length(): number;
55
- /**
56
- * 根据索引获取当前作用域下的原始键名
57
- * @param index - 索引位置
58
- * @returns 对应的业务键名,不存在则返回 null
59
- */
60
- key(index: number): string | null;
61
- }
@@ -1,10 +0,0 @@
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
- }
@@ -1,87 +0,0 @@
1
- import { ApiAdapter, ApiConfig, ApiEndpointConfig, ApiInterceptor, RequestOptions } from '../ports/api-port';
2
- /**
3
- * API 引擎核心类
4
- * @description 负责加载配置并执行请求,支持策略模式切换底层请求实现
5
- */
6
- export declare class ApiEngine {
7
- private adapter;
8
- private config;
9
- private interceptors;
10
- constructor(adapter?: ApiAdapter);
11
- /**
12
- * 注册拦截器
13
- */
14
- registerInterceptor(interceptor: ApiInterceptor): void;
15
- /**
16
- * 移除拦截器
17
- */
18
- unregisterInterceptor(interceptor: ApiInterceptor): void;
19
- /**
20
- * 切换请求适配器
21
- * @param adapter 新的适配器实例
22
- */
23
- useAdapter(adapter: ApiAdapter): void;
24
- /**
25
- * 注册 API 配置
26
- * @param config 配置对象
27
- */
28
- register(config: ApiConfig): void;
29
- /**
30
- * 获取接口配置
31
- */
32
- getEndpoint(module: string, action: string): ApiEndpointConfig | undefined;
33
- /**
34
- * 发起 API 请求
35
- * @param module 模块名
36
- * @param action 动作名
37
- * @param data 请求数据 (Body 或 Query)
38
- * @param options 请求选项
39
- */
40
- call<T = any>(module: string, action: string, data?: any, options?: RequestOptions): Promise<T>;
41
- /**
42
- * 发起流式请求
43
- * @param module 模块名
44
- * @param action 动作名
45
- * @param data 请求数据
46
- * @param options 请求选项
47
- */
48
- stream(module: string, action: string, data?: any, options?: RequestOptions): Promise<void>;
49
- /**
50
- * 准备请求配置,应用 URL 参数替换和请求拦截器
51
- */
52
- private prepareRequestConfig;
53
- /**
54
- * 应用所有请求拦截器
55
- */
56
- private applyRequestInterceptors;
57
- /**
58
- * 应用所有响应拦截器
59
- * @returns 是否被劫持
60
- */
61
- private applyResponseInterceptors;
62
- /**
63
- * 检查 HTTP 状态码
64
- */
65
- private checkHttpStatus;
66
- /**
67
- * 提取响应数据
68
- */
69
- private extractResponseData;
70
- /**
71
- * 处理业务错误
72
- */
73
- private handleBusinessError;
74
- /**
75
- * 判断是否为 BaseResponse
76
- */
77
- private isBaseResponse;
78
- /**
79
- * 严格判断是否为 AxiosResponse
80
- */
81
- private isAxiosResponse;
82
- /**
83
- * 创建拦截上下文
84
- */
85
- private createInterceptorContext;
86
- }
87
- export declare const apiEngine: ApiEngine;
@@ -1,6 +0,0 @@
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';
@@ -1,14 +0,0 @@
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;
@@ -1,8 +0,0 @@
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;
@@ -1,57 +0,0 @@
1
- /**
2
- * 服务注册中心 (Service Registry)
3
- * @description 核心应用层服务,作为微内核架构中的“中枢调度员”。
4
- * 主要职责:
5
- * 1. 服务解耦:允许插件将其内部功能暴露为“服务”,而无需与其他插件产生物理依赖。
6
- * 2. 动态发现:提供按名称查找服务的能力,支持服务热插拔。
7
- * 3. 依赖协调:通过 `waitFor` 机制解决插件间由于加载顺序导致的初始化依赖问题。
8
- *
9
- * 建议的服务命名规范: `pluginId.serviceName` (例如: `auth.sessionService`)
10
- */
11
- export declare class ServiceRegistry {
12
- /** 存储已注册服务的 Map 对象 */
13
- private services;
14
- /** 存储正在等待特定服务的监听器集合 */
15
- private listeners;
16
- /**
17
- * 注册一个服务实现
18
- * @param name - 唯一的服务名称
19
- * @param service - 服务实例或对象
20
- */
21
- register(name: string, service: any): void;
22
- /**
23
- * 同步获取服务实例
24
- * @template T - 服务类型的泛型
25
- * @param name - 服务名称
26
- * @returns 服务实例,若不存在则返回 undefined
27
- */
28
- get<T = any>(name: string): T | undefined;
29
- /**
30
- * 异步等待并获取服务
31
- * @description 如果服务尚未注册,将返回一个 Promise,直到该服务被注册时 resolve。
32
- * 支持设置超时时间,防止因插件加载失败导致的永久挂起。
33
- *
34
- * @template T - 服务类型的泛型
35
- * @param name - 待等待的服务名称
36
- * @param timeout - 超时时间 (毫秒),默认 10000ms (10秒)。若为 0 则永不超时。
37
- * @returns 包含服务实例的 Promise
38
- * @throws {Error} 若在规定时间内服务未注册,则抛出超时异常。
39
- */
40
- waitFor<T = any>(name: string, timeout?: number): Promise<T>;
41
- /**
42
- * 检查服务是否已注册
43
- * @param name - 服务名称
44
- */
45
- has(name: string): boolean;
46
- /**
47
- * 注销特定的服务
48
- * @param name - 服务名称
49
- */
50
- unregister(name: string): void;
51
- /**
52
- * 清除所有已注册的服务和监听器
53
- * @description 通常仅在系统重置或大型热更新时使用。
54
- */
55
- clear(): void;
56
- }
57
- export declare const serviceRegistry: ServiceRegistry;
@@ -1 +0,0 @@
1
- var s=class{config=new Map;set(t,e){this.config.set(t,e)}get(t){return this.config.get(t)}merge(t){Object.keys(t).forEach(e=>{let i=this.config.get(e),n=t[e];i&&typeof i=="object"&&n&&typeof n=="object"?this.config.set(e,{...i,...n}):this.config.set(e,n)})}getAll(){return Object.fromEntries(this.config)}},c=new s;export{s as a,c as b};
@@ -1,44 +0,0 @@
1
- import React, { Component, ErrorInfo, ReactNode } from 'react';
2
- /** 插件错误边界组件属性 */
3
- interface Props {
4
- /** 发生错误的插件 ID */
5
- pluginId?: string;
6
- /** 错误发生时的降级 UI */
7
- fallback?: ReactNode;
8
- /** 子组件内容 */
9
- children: ReactNode;
10
- /** 是否静默模式,开启后不显示任何错误 UI,仅记录日志 */
11
- silent?: boolean;
12
- }
13
- /** 插件错误边界组件状态 */
14
- interface State {
15
- /** 是否捕获到错误 */
16
- hasError: boolean;
17
- /** 捕获到的错误对象 */
18
- error: Error | null;
19
- }
20
- /**
21
- * 插件错误边界组件
22
- * @description 核心组件,用于捕获子组件渲染过程中的 JavaScript 错误,记录日志并显示降级 UI。
23
- * 确保单个插件的运行异常不会导致整个主应用或其他插件崩溃。
24
- */
25
- export declare class PluginErrorBoundary extends Component<Props, State> {
26
- constructor(props: Props);
27
- /**
28
- * 从错误中派生状态
29
- * @param error - 捕获到的错误
30
- */
31
- static getDerivedStateFromError(error: Error): State;
32
- /**
33
- * 捕获到错误后的回调
34
- * @param error - 错误对象
35
- * @param errorInfo - 错误堆栈信息
36
- */
37
- componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
38
- /**
39
- * 重置错误状态,尝试重新渲染
40
- */
41
- handleRetry: () => void;
42
- render(): string | number | boolean | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
43
- }
44
- export {};
@@ -1,35 +0,0 @@
1
- import React from 'react';
2
- import type { PluginExtension, SlotPosition } from '../api';
3
- /** 插件插槽组件属性 */
4
- interface PluginSlotProps {
5
- /** 插槽位置标识,决定渲染哪些插件扩展 */
6
- slot: SlotPosition;
7
- /** 传递给扩展组件的 Props 对象 */
8
- props?: Record<string, any>;
9
- /** 自定义容器类名 (Tailwind CSS) */
10
- className?: string;
11
- /** 自定义容器内联样式 */
12
- style?: React.CSSProperties;
13
- /**
14
- * 自定义渲染函数
15
- * @param item - 包含 key、组件和扩展元信息的对象
16
- * @param index - 索引位置
17
- */
18
- renderItem?: (item: {
19
- key: string;
20
- component: React.ReactNode;
21
- extension: PluginExtension;
22
- }, index: number) => React.ReactNode;
23
- /** 骨架屏组件,当插槽内无插件扩展时显示的占位 UI */
24
- skeleton?: React.ReactNode;
25
- /** 回退组件,当插槽内无插件扩展时显示的 UI,优先级高于 skeleton */
26
- fallback?: React.ReactNode;
27
- }
28
- /**
29
- * 插件插槽组件
30
- * @description UI 层的核心组件,用于在应用中声明一个“插槽”。
31
- * 它会自动根据 slot 标识从 PluginManager 中获取所有注册的插件扩展组件并按顺序渲染。
32
- * 支持订阅插件变更,实现动态热插拔。
33
- */
34
- export declare const PluginSlot: React.FC<PluginSlotProps>;
35
- export {};
@@ -1,27 +0,0 @@
1
- import React from 'react';
2
- /**
3
- * 通用插槽骨架屏组件集合
4
- * @description 提供一组预定义的骨架屏 UI,用于在插件加载或插槽内容未准备好时提供更好的用户体验。
5
- */
6
- /**
7
- * 侧边栏图标骨架屏
8
- * @param expanded - 是否处于展开状态
9
- */
10
- export declare const SidebarIconSkeleton: React.FC<{
11
- expanded?: boolean;
12
- }>;
13
- /**
14
- * 状态栏项骨架屏
15
- */
16
- export declare const StatusBarItemSkeleton: React.FC;
17
- /**
18
- * 头像骨架屏
19
- */
20
- export declare const AvatarSkeleton: React.FC;
21
- /**
22
- * 通用块级骨架屏
23
- * @param className - 自定义类名
24
- */
25
- export declare const BlockSkeleton: React.FC<{
26
- className?: string;
27
- }>;
@@ -1 +0,0 @@
1
- import{a,b}from"./chunk-O74KYN5N.mjs";export{a as ConfigManager,b as configManager};
@@ -1,34 +0,0 @@
1
- /**
2
- * 配置管理器
3
- * @description 核心工具类,负责管理应用的全局系统配置以及各插件的初始化业务配置。
4
- * 配置数据通常在应用启动时通过 `usePluginLoader` 注入,并作为插件运行时的取值回退来源。
5
- */
6
- export declare class ConfigManager {
7
- /** 内部存储配置的 Map 对象 */
8
- private config;
9
- /**
10
- * 设置特定的配置项
11
- * @param key - 配置键名(如 'system' 或插件 ID)
12
- * @param value - 配置内容对象
13
- */
14
- set(key: string, value: any): void;
15
- /**
16
- * 获取指定的配置项
17
- * @param key - 配置键名
18
- * @returns 配置内容,若不存在则返回 undefined
19
- */
20
- get(key: string): any;
21
- /**
22
- * 批量合并配置对象
23
- * @description 对顶层属性进行浅合并,若属性值为对象则进行一层深度的合并。
24
- * @param config - 待合并的配置对象映射
25
- */
26
- merge(config: Record<string, any>): void;
27
- /**
28
- * 获取当前存储的所有配置快照
29
- * @returns 包含所有配置的普通对象
30
- */
31
- getAll(): Record<string, any>;
32
- }
33
- /** 全局配置管理器单例 */
34
- export declare const configManager: ConfigManager;
@@ -1,36 +0,0 @@
1
- /**
2
- * 插件注册表接口
3
- * @description 键为插件 ID,值为一个返回插件定义的异步加载函数。
4
- */
5
- export interface PluginRegistry {
6
- [pluginId: string]: () => Promise<any>;
7
- }
8
- /**
9
- * 插件自动发现规则
10
- */
11
- export interface DiscoveryRule {
12
- /**
13
- * 路径匹配标识。
14
- * @example 'plugins' 或 '@chatbi-plugins'
15
- */
16
- pathSegment: string;
17
- /**
18
- * 生成插件 ID 时的前缀。
19
- * @example '@chatbi-v/plugin',最终生成如 '@chatbi-v/plugin-demo'
20
- */
21
- idPrefix: string;
22
- }
23
- /**
24
- * 解析插件注册表
25
- * @description 核心逻辑:将 Vite 的 `import.meta.glob` 结果映射为标准的插件注册表。
26
- * 它会根据预定义的路径匹配规则,从文件路径中提取插件目录名,并拼接前缀生成唯一的插件 ID。
27
- *
28
- * @param options - 包含待处理模块和匹配规则的选项对象
29
- * @returns 解析后的 PluginRegistry 对象
30
- */
31
- export declare const resolvePluginRegistry: (options: {
32
- /** 原始模块映射 (来自 Vite glob) */
33
- modules: Record<string, () => Promise<any>>;
34
- /** 自定义发现规则 (可选) */
35
- rules?: DiscoveryRule[];
36
- }) => PluginRegistry;
@@ -1,42 +0,0 @@
1
- /**
2
- * 成功状态码
3
- */
4
- export declare const SUCCESS_CODE = "000000";
5
- /**
6
- * 基础 API 响应接口
7
- * @template T 响应数据的类型
8
- */
9
- export interface BaseResponse<T = any> {
10
- /** 业务状态码 */
11
- code: string | number;
12
- /** 响应消息提示 */
13
- message: string;
14
- /** 业务响应数据主体 */
15
- data: T;
16
- }
17
- /**
18
- * 业务场景实体接口
19
- * @description 描述系统中的业务分析场景
20
- */
21
- export interface Scene {
22
- /** 场景唯一标识符 */
23
- id: string;
24
- /** 场景名称 */
25
- name: string;
26
- /** 场景详细描述 */
27
- description: string;
28
- /** 场景内部代码/标识 */
29
- code: string;
30
- /** 场景创建者 ID 或名称 */
31
- creator: string;
32
- /** 创建时间字符串 (ISO 格式) */
33
- createTime: string;
34
- /** 该场景关联的物理数据表数量 */
35
- tableCount: number;
36
- /** 该场景关联的知识库数量 */
37
- kbCount: number;
38
- /** 该场景关联的预设问答对数量 */
39
- qaCount: number;
40
- /** 场景封面图 URL (可选) */
41
- cover?: string;
42
- }