@chatbi-v/core 1.0.3 → 2.0.0

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
@@ -18,7 +18,7 @@ ChatBI 核心模块,提供插件管理、基础设施接口及通用 API 引
18
18
  ## 功能
19
19
 
20
20
  - **PluginManager**: 管理插件的注册和生命周期。
21
- - **ApiEngine**: 统一的 API 请求管理。
21
+ - **ApiEngine**: 统一的 API 请求管理。支持请求拦截器 (`ApiInterceptor`),且拦截器能力已覆盖普通请求 (`call`) 和流式请求 (`stream`)。
22
22
  - **Sandbox**: 提供插件运行时的样式和全局变量隔离。
23
23
 
24
24
  ## 使用方法
@@ -1,4 +1,4 @@
1
- import { ApiAdapter, ApiConfig, ApiEndpointConfig, RequestOptions } from '../ports/api-port';
1
+ import { ApiAdapter, ApiConfig, ApiEndpointConfig, ApiInterceptor, RequestOptions } from '../ports/api-port';
2
2
  /**
3
3
  * API 引擎核心类
4
4
  * @description 负责加载配置并执行请求,支持策略模式切换底层请求实现
@@ -6,7 +6,16 @@ import { ApiAdapter, ApiConfig, ApiEndpointConfig, RequestOptions } from '../por
6
6
  export declare class ApiEngine {
7
7
  private adapter;
8
8
  private config;
9
+ private interceptors;
9
10
  constructor(adapter?: ApiAdapter);
11
+ /**
12
+ * 注册拦截器
13
+ */
14
+ registerInterceptor(interceptor: ApiInterceptor): void;
15
+ /**
16
+ * 移除拦截器
17
+ */
18
+ unregisterInterceptor(interceptor: ApiInterceptor): void;
10
19
  /**
11
20
  * 切换请求适配器
12
21
  * @param adapter 新的适配器实例
@@ -37,5 +46,21 @@ export declare class ApiEngine {
37
46
  * @param options 请求选项
38
47
  */
39
48
  stream(module: string, action: string, data?: any, options?: RequestOptions): Promise<void>;
49
+ /**
50
+ * 准备请求配置,应用 URL 参数替换和拦截器
51
+ */
52
+ private prepareRequestConfig;
53
+ /**
54
+ * 判断是否为 BaseResponse
55
+ */
56
+ private isBaseResponse;
57
+ /**
58
+ * 严格判断是否为 AxiosResponse
59
+ */
60
+ private isAxiosResponse;
61
+ /**
62
+ * 创建拦截上下文
63
+ */
64
+ private createInterceptorContext;
40
65
  }
41
66
  export declare const apiEngine: ApiEngine;
@@ -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
+ };
@@ -17,6 +17,8 @@ interface PluginSlotProps {
17
17
  }, index: number) => React.ReactNode;
18
18
  /** 骨架屏组件 (当没有插件扩展时显示) */
19
19
  skeleton?: React.ReactNode;
20
+ /** 回退组件 (当没有插件扩展时显示,优先于 skeleton) */
21
+ fallback?: React.ReactNode;
20
22
  }
21
23
  export declare const PluginSlot: React.FC<PluginSlotProps>;
22
24
  export {};
@@ -2,7 +2,9 @@ import React from 'react';
2
2
  /**
3
3
  * 通用插槽骨架屏组件集合
4
4
  */
5
- export declare const SidebarIconSkeleton: React.FC;
5
+ export declare const SidebarIconSkeleton: React.FC<{
6
+ expanded?: boolean;
7
+ }>;
6
8
  export declare const StatusBarItemSkeleton: React.FC;
7
9
  export declare const AvatarSkeleton: React.FC;
8
10
  export declare const BlockSkeleton: React.FC<{
@@ -0,0 +1,8 @@
1
+ import {
2
+ ConfigManager,
3
+ configManager
4
+ } from "./chunk-G3OU7D3Y.mjs";
5
+ export {
6
+ ConfigManager,
7
+ configManager
8
+ };
@@ -7,3 +7,28 @@ export interface BaseResponse<T = any> {
7
7
  message: string;
8
8
  data: T;
9
9
  }
10
+ /**
11
+ * 场景接口
12
+ */
13
+ export interface Scene {
14
+ /** 场景唯一标识 */
15
+ id: string;
16
+ /** 场景名称 */
17
+ name: string;
18
+ /** 场景描述 */
19
+ description: string;
20
+ /** 场景代码 */
21
+ code: string;
22
+ /** 创建者 */
23
+ creator: string;
24
+ /** 创建时间 */
25
+ createTime: string;
26
+ /** 关联数据表数量 */
27
+ tableCount: number;
28
+ /** 关联知识库数量 */
29
+ kbCount: number;
30
+ /** 关联问答对数量 */
31
+ qaCount: number;
32
+ /** 场景封面图 */
33
+ cover?: string;
34
+ }
@@ -89,6 +89,16 @@ export declare class PluginManager {
89
89
  * @returns 配置值
90
90
  */
91
91
  getPluginConfig(pluginId: string, key: string): any;
92
+ /**
93
+ * 获取系统全局配置 (非插件特定配置)
94
+ * @param key 配置键 (如 title, version)
95
+ */
96
+ getSystemConfig(key: string): any;
97
+ /**
98
+ * 获取注册的服务
99
+ * @param name 服务名称
100
+ */
101
+ getService<T = any>(name: string): T | undefined;
92
102
  /**
93
103
  * 获取指定插槽的扩展
94
104
  * @param slot 插槽位置
@@ -7,6 +7,8 @@ export interface PluginLoaderOptions {
7
7
  pluginConfigs: Record<string, any>;
8
8
  /** 初始化的上下文服务 (如 api, events 等) */
9
9
  sharedContext?: Record<string, any>;
10
+ /** 系统级配置 (title, version 等) */
11
+ systemConfig?: Record<string, any>;
10
12
  /** 发现的基础 URL */
11
13
  baseUrl?: string;
12
14
  }