@chatbi-v/vue 3.0.0 → 3.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.
- package/README.md +36 -0
- package/dist/core/src/adapters/AdapterInterface.d.ts +111 -0
- package/dist/core/src/adapters/AdapterRegistry.d.ts +88 -0
- package/dist/core/src/adapters/index.d.ts +7 -0
- package/dist/core/src/adapters/local-storage-adapter.d.ts +61 -0
- package/dist/core/src/adapters/scoped-storage-adapter.d.ts +61 -0
- package/dist/core/src/ai/function/index.d.ts +1 -0
- package/dist/core/src/ai/function/registry.d.ts +28 -0
- package/dist/core/src/ai/index.d.ts +8 -0
- package/dist/core/src/ai/providers/index.d.ts +2 -0
- package/dist/core/src/ai/providers/mock.d.ts +28 -0
- package/dist/core/src/ai/providers/openai.d.ts +17 -0
- package/dist/core/src/ai/session/index.d.ts +3 -0
- package/dist/core/src/ai/session/manager.d.ts +19 -0
- package/dist/core/src/ai/session/storage.d.ts +9 -0
- package/dist/core/src/ai/session/types.d.ts +14 -0
- package/dist/core/src/ai/store.d.ts +23 -0
- package/dist/core/src/ai/types.d.ts +57 -0
- package/dist/core/src/ai/utils.d.ts +7 -0
- package/dist/core/src/api/adapters/axios-adapter.d.ts +10 -0
- package/dist/core/src/api/engine.d.ts +101 -0
- package/dist/core/src/api/index.d.ts +5 -0
- package/dist/core/src/api/utils.d.ts +14 -0
- package/dist/core/src/application/service-registry.d.ts +57 -0
- package/dist/core/src/config-manager.d.ts +52 -0
- package/dist/core/src/dependency/ConflictResolver.d.ts +46 -0
- package/dist/core/src/dependency/CycleDetector.d.ts +47 -0
- package/dist/core/src/dependency/DependencyGraph.d.ts +85 -0
- package/dist/core/src/dependency/NpmRegistry.d.ts +78 -0
- package/dist/core/src/dependency/SharedDepsDetector.d.ts +49 -0
- package/dist/core/src/dependency/index.d.ts +9 -0
- package/dist/core/src/domain/auto-loader.d.ts +36 -0
- package/dist/core/src/domain/errors.d.ts +68 -0
- package/dist/core/src/domain/models.d.ts +42 -0
- package/dist/core/src/domain/performance/collector.d.ts +70 -0
- package/dist/core/src/domain/performance/index.d.ts +27 -0
- package/dist/core/src/domain/performance/lifecycle.d.ts +34 -0
- package/dist/core/src/domain/performance/storage.d.ts +79 -0
- package/dist/core/src/domain/performance/types.d.ts +67 -0
- package/dist/core/src/domain/plugin-manager.d.ts +327 -0
- package/dist/core/src/domain/plugin-runtime.d.ts +74 -0
- package/dist/core/src/domain/plugin-sandbox.d.ts +40 -0
- package/dist/core/src/domain/storage-manager.d.ts +81 -0
- package/dist/core/src/event-bus.d.ts +55 -0
- package/dist/core/src/feature-flag/FeatureRegistry.d.ts +75 -0
- package/dist/core/src/feature-flag/RuleEngine.d.ts +44 -0
- package/dist/core/src/feature-flag/index.d.ts +6 -0
- package/dist/core/src/index.d.ts +37 -0
- package/dist/core/src/manifest/ManifestValidator.d.ts +33 -0
- package/dist/core/src/manifest/ManifestWrapper.d.ts +23 -0
- package/dist/core/src/manifest/PluginManifest.d.ts +524 -0
- package/dist/core/src/manifest/index.d.ts +9 -0
- package/dist/core/src/ports/api-port.d.ts +136 -0
- package/dist/core/src/ports/event-bus-port.d.ts +32 -0
- package/dist/core/src/ports/plugin-port.d.ts +345 -0
- package/dist/core/src/ports/storage-port.d.ts +49 -0
- package/dist/core/src/remote/RemoteCache.d.ts +57 -0
- package/dist/core/src/remote/RemoteLoader.d.ts +85 -0
- package/dist/core/src/remote/RemotePluginSource.d.ts +88 -0
- package/dist/core/src/remote/RetryStrategy.d.ts +43 -0
- package/dist/core/src/remote/index.d.ts +8 -0
- package/dist/core/src/sandbox/proxy-sandbox.d.ts +74 -0
- package/dist/core/src/semver/SemverResolver.d.ts +79 -0
- package/dist/core/src/store.d.ts +30 -0
- package/dist/core/src/types/branded.d.ts +54 -0
- package/dist/core/src/types/index.d.ts +8 -0
- package/dist/core/src/types/template-literals.d.ts +58 -0
- package/dist/core/src/types/utils.d.ts +133 -0
- package/dist/core/src/utils/date.d.ts +32 -0
- package/dist/core/src/utils/index.d.ts +4 -0
- package/dist/core/src/utils/logger.d.ts +108 -0
- package/dist/core/src/utils/url.d.ts +16 -0
- package/dist/index.js +1899 -1842
- package/dist/index.umd.cjs +19 -19
- package/dist/vue/src/components/PluginErrorBoundary.vue.d.ts +20 -0
- package/dist/vue/src/components/PluginSlot.vue.d.ts +8 -0
- package/dist/vue/src/composables/useCoreStore.d.ts +9 -0
- package/dist/vue/src/composables/useService.d.ts +6 -0
- package/dist/vue/src/index.d.ts +18 -0
- package/package.json +10 -8
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @chatbi-v/vue
|
|
2
|
+
|
|
3
|
+
ChatBI-V Vue 3 适配器层,提供 Vue 3 组件与核心模块的桥接。
|
|
4
|
+
|
|
5
|
+
## 模块功能
|
|
6
|
+
|
|
7
|
+
- **Vue 3 集成**: 为 Vue 3 应用提供 ChatBI 核心能力
|
|
8
|
+
- **组合式 API**: 使用 Vue 3 Composition API 设计
|
|
9
|
+
- **类型支持**: 完整的 TypeScript 类型推导
|
|
10
|
+
|
|
11
|
+
## 安装
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @chatbi-v/vue
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 使用
|
|
18
|
+
|
|
19
|
+
```vue
|
|
20
|
+
<script setup>
|
|
21
|
+
import { usePlugin, useTheme } from '@chatbi-v/vue';
|
|
22
|
+
|
|
23
|
+
const { plugin } = usePlugin('my-plugin');
|
|
24
|
+
const { tokens } = useTheme();
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div>{{ plugin?.name }}</div>
|
|
29
|
+
</template>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API
|
|
33
|
+
|
|
34
|
+
- `usePlugin(id)` - 获取插件实例
|
|
35
|
+
- `useTheme()` - 获取主题 Token
|
|
36
|
+
- `useFeature(featureId)` - 获取功能状态
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file AdapterInterface.ts
|
|
3
|
+
* @description UI 适配器接口定义,提供统一的适配器契约
|
|
4
|
+
* @author ChatBI Team
|
|
5
|
+
*/
|
|
6
|
+
interface DesignSystemTokens {
|
|
7
|
+
meta: {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
mode: 'light' | 'dark' | 'system';
|
|
12
|
+
};
|
|
13
|
+
primitives: Record<string, any>;
|
|
14
|
+
semantics: Record<string, any>;
|
|
15
|
+
semanticsDark?: Record<string, any>;
|
|
16
|
+
components: Record<string, any>;
|
|
17
|
+
componentsDark?: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* UI 适配器接口
|
|
21
|
+
* 定义所有 UI 库适配器必须实现的契约
|
|
22
|
+
*/
|
|
23
|
+
export interface UIAdapter {
|
|
24
|
+
/** 适配器唯一标识符 */
|
|
25
|
+
readonly id: string;
|
|
26
|
+
/** 适配器显示名称 */
|
|
27
|
+
readonly name: string;
|
|
28
|
+
/** 适配器版本 */
|
|
29
|
+
readonly version: string;
|
|
30
|
+
/** 目标 UI 库标识 (如: 'antd', 'mui', 'chakra') */
|
|
31
|
+
readonly targetLibrary: string;
|
|
32
|
+
/** 兼容的 UI 库版本 */
|
|
33
|
+
readonly compatibleVersion?: string;
|
|
34
|
+
/**
|
|
35
|
+
* 将 DesignSystem 转换为目标 UI 库的主题配置
|
|
36
|
+
* @param tokens 设计系统 Token
|
|
37
|
+
* @param options 转换选项
|
|
38
|
+
* @returns 目标 UI 库的主题配置对象
|
|
39
|
+
*/
|
|
40
|
+
transform(tokens: DesignSystemTokens, options?: TransformOptions): any;
|
|
41
|
+
/**
|
|
42
|
+
* 应用主题到目标 UI 库
|
|
43
|
+
* @param theme 转换后的主题配置
|
|
44
|
+
*/
|
|
45
|
+
apply(theme: any): void;
|
|
46
|
+
/**
|
|
47
|
+
* 移除已应用的主题
|
|
48
|
+
*/
|
|
49
|
+
remove(): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Token 转换选项
|
|
53
|
+
*/
|
|
54
|
+
export interface TransformOptions {
|
|
55
|
+
/** 颜色方案 */
|
|
56
|
+
colorScheme?: 'light' | 'dark';
|
|
57
|
+
/** 组件级别覆盖配置 */
|
|
58
|
+
componentOverrides?: Record<string, any>;
|
|
59
|
+
/** CSS 变量前缀 */
|
|
60
|
+
prefix?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 适配器工厂函数类型
|
|
64
|
+
*/
|
|
65
|
+
export interface AdapterFactory {
|
|
66
|
+
/** 创建适配器实例 */
|
|
67
|
+
create(config?: any): UIAdapter;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 适配器状态类型
|
|
71
|
+
*/
|
|
72
|
+
export type AdapterStatus = 'registered' | 'active' | 'inactive' | 'error';
|
|
73
|
+
/**
|
|
74
|
+
* 适配器运行时状态
|
|
75
|
+
*/
|
|
76
|
+
export interface AdapterState {
|
|
77
|
+
/** 适配器实例 */
|
|
78
|
+
adapter: UIAdapter;
|
|
79
|
+
/** 当前状态 */
|
|
80
|
+
status: AdapterStatus;
|
|
81
|
+
/** 错误信息 (仅在 error 状态时有效) */
|
|
82
|
+
error?: Error;
|
|
83
|
+
/** 注册时间 */
|
|
84
|
+
registeredAt: Date;
|
|
85
|
+
/** 激活时间 */
|
|
86
|
+
activatedAt?: Date;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 适配器抽象基类
|
|
90
|
+
* 提供通用的适配器实现模板
|
|
91
|
+
*/
|
|
92
|
+
export declare abstract class BaseAdapter implements UIAdapter {
|
|
93
|
+
abstract readonly id: string;
|
|
94
|
+
abstract readonly name: string;
|
|
95
|
+
abstract readonly version: string;
|
|
96
|
+
abstract readonly targetLibrary: string;
|
|
97
|
+
/**
|
|
98
|
+
* 模板方法 - 三层变换默认实现
|
|
99
|
+
* primitives -> semantics -> component tokens
|
|
100
|
+
*/
|
|
101
|
+
protected transformTokens(tokens: DesignSystemTokens, options?: TransformOptions): any;
|
|
102
|
+
/**
|
|
103
|
+
* 将语义 Token 转换为组件级别配置
|
|
104
|
+
* 由子类实现具体转换逻辑
|
|
105
|
+
*/
|
|
106
|
+
protected semanticsToComponents(semantics: any, options?: TransformOptions): any;
|
|
107
|
+
transform(tokens: DesignSystemTokens, options?: TransformOptions): any;
|
|
108
|
+
abstract apply(theme: any): void;
|
|
109
|
+
abstract remove(): void;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file AdapterRegistry.ts
|
|
3
|
+
* @description 适配器注册发现机制,管理 UI 适配器的注册、激活和查询
|
|
4
|
+
* @author ChatBI Team
|
|
5
|
+
*/
|
|
6
|
+
import type { AdapterState, TransformOptions, UIAdapter } from './AdapterInterface';
|
|
7
|
+
/**
|
|
8
|
+
* 适配器注册表
|
|
9
|
+
* 提供适配器的注册、注销、激活和查询功能
|
|
10
|
+
*/
|
|
11
|
+
export declare class AdapterRegistry {
|
|
12
|
+
private adapters;
|
|
13
|
+
private states;
|
|
14
|
+
private activeAdapterId;
|
|
15
|
+
private currentTokens;
|
|
16
|
+
/**
|
|
17
|
+
* 注册适配器
|
|
18
|
+
* @param adapter 要注册的 UIAdapter 实例
|
|
19
|
+
*/
|
|
20
|
+
register(adapter: UIAdapter): void;
|
|
21
|
+
/**
|
|
22
|
+
* 注销适配器
|
|
23
|
+
* @param adapterId 要注销的适配器 ID
|
|
24
|
+
* @returns 是否成功注销
|
|
25
|
+
*/
|
|
26
|
+
unregister(adapterId: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* 获取指定适配器
|
|
29
|
+
* @param adapterId 适配器 ID
|
|
30
|
+
* @returns 适配器实例或 undefined
|
|
31
|
+
*/
|
|
32
|
+
get(adapterId: string): UIAdapter | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* 获取所有已注册的适配器
|
|
35
|
+
* @returns 所有适配器实例数组
|
|
36
|
+
*/
|
|
37
|
+
getAll(): UIAdapter[];
|
|
38
|
+
/**
|
|
39
|
+
* 获取所有适配器状态
|
|
40
|
+
* @returns 所有适配器状态数组
|
|
41
|
+
*/
|
|
42
|
+
getAllStates(): AdapterState[];
|
|
43
|
+
/**
|
|
44
|
+
* 设置活跃适配器
|
|
45
|
+
* @param adapterId 要激活的适配器 ID
|
|
46
|
+
* @returns 是否成功激活
|
|
47
|
+
*/
|
|
48
|
+
setActive(adapterId: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 获取当前活跃适配器
|
|
51
|
+
* @returns 活跃适配器实例或 undefined
|
|
52
|
+
*/
|
|
53
|
+
getActive(): UIAdapter | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* 使用当前活跃适配器转换 Token
|
|
56
|
+
* @param tokens DesignSystem Token
|
|
57
|
+
* @param options 转换选项
|
|
58
|
+
* @returns 转换后的主题配置
|
|
59
|
+
*/
|
|
60
|
+
transform(tokens: any, options?: TransformOptions): any;
|
|
61
|
+
/**
|
|
62
|
+
* 检查是否支持指定目标库
|
|
63
|
+
* @param targetLibrary 目标库标识
|
|
64
|
+
* @returns 是否支持
|
|
65
|
+
*/
|
|
66
|
+
supports(targetLibrary: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 获取支持指定目标库的所有适配器
|
|
69
|
+
* @param targetLibrary 目标库标识
|
|
70
|
+
* @returns 适配器数组
|
|
71
|
+
*/
|
|
72
|
+
getAdaptersForTarget(targetLibrary: string): UIAdapter[];
|
|
73
|
+
/**
|
|
74
|
+
* 设置当前 DesignSystem Token
|
|
75
|
+
* @param tokens DesignSystem 实例
|
|
76
|
+
*/
|
|
77
|
+
setTokens(tokens: any): void;
|
|
78
|
+
/**
|
|
79
|
+
* 获取当前 DesignSystem Token
|
|
80
|
+
* @returns 当前 Token
|
|
81
|
+
*/
|
|
82
|
+
getTokens(): any;
|
|
83
|
+
/**
|
|
84
|
+
* 内部方法 - 更新适配器状态
|
|
85
|
+
*/
|
|
86
|
+
private updateState;
|
|
87
|
+
}
|
|
88
|
+
export declare const adapterRegistry: AdapterRegistry;
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ToolRegistry } from './registry';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AITool } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 工具注册表
|
|
4
|
+
* 管理 AI 函数的注册和执行
|
|
5
|
+
*/
|
|
6
|
+
export declare class ToolRegistry {
|
|
7
|
+
private tools;
|
|
8
|
+
/**
|
|
9
|
+
* 注册工具
|
|
10
|
+
*/
|
|
11
|
+
register(tool: AITool): void;
|
|
12
|
+
/**
|
|
13
|
+
* 注销工具
|
|
14
|
+
*/
|
|
15
|
+
unregister(name: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* 获取工具
|
|
18
|
+
*/
|
|
19
|
+
get(name: string): AITool | null;
|
|
20
|
+
/**
|
|
21
|
+
* 列出所有工具
|
|
22
|
+
*/
|
|
23
|
+
list(): AITool[];
|
|
24
|
+
/**
|
|
25
|
+
* 执行工具
|
|
26
|
+
*/
|
|
27
|
+
execute(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AIChunk, AIMessage, AIProvider, AITool, ChatOptions, FunctionCallResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Mock AI Provider
|
|
4
|
+
* 用于演示和测试环境,返回预设的智能回复
|
|
5
|
+
*/
|
|
6
|
+
export declare class MockAIProvider implements AIProvider {
|
|
7
|
+
private responses;
|
|
8
|
+
/**
|
|
9
|
+
* 生成回复
|
|
10
|
+
*/
|
|
11
|
+
private generateResponse;
|
|
12
|
+
/**
|
|
13
|
+
* 生成唯一 ID
|
|
14
|
+
*/
|
|
15
|
+
private generateId;
|
|
16
|
+
/**
|
|
17
|
+
* 聊天(非流式)
|
|
18
|
+
*/
|
|
19
|
+
chat(messages: AIMessage[], options?: ChatOptions): Promise<AIMessage>;
|
|
20
|
+
/**
|
|
21
|
+
* 流式响应
|
|
22
|
+
*/
|
|
23
|
+
stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable<AIChunk>;
|
|
24
|
+
/**
|
|
25
|
+
* 函数调用
|
|
26
|
+
*/
|
|
27
|
+
functionCall(messages: AIMessage[], tools: AITool[], options?: ChatOptions): Promise<FunctionCallResult>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AIChunk, AIMessage, AIProvider, ChatOptions, FunctionCallResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* OpenAI Provider 实现
|
|
4
|
+
* 支持 chat、stream、functionCall 方法
|
|
5
|
+
*/
|
|
6
|
+
export declare class OpenAIProvider implements AIProvider {
|
|
7
|
+
private client;
|
|
8
|
+
private defaultOptions;
|
|
9
|
+
constructor(apiKey: string, defaultOptions?: ChatOptions);
|
|
10
|
+
chat(messages: AIMessage[], options?: ChatOptions): Promise<AIMessage>;
|
|
11
|
+
stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable<AIChunk>;
|
|
12
|
+
functionCall(messages: AIMessage[], tools: import('../types').AITool[], options?: ChatOptions): Promise<FunctionCallResult>;
|
|
13
|
+
private toOpenAIMessages;
|
|
14
|
+
private toOpenAITools;
|
|
15
|
+
private fromOpenAIMessage;
|
|
16
|
+
private fromOpenAIToolCall;
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AIMessage, Session } from '../types';
|
|
2
|
+
import { SessionManagerInterface, SessionStorage } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* 会话管理器
|
|
5
|
+
* 提供会话的创建、查询、删除、消息管理等功能
|
|
6
|
+
*/
|
|
7
|
+
export declare class SessionManager implements SessionManagerInterface {
|
|
8
|
+
private sessions;
|
|
9
|
+
private storage?;
|
|
10
|
+
constructor(storage?: SessionStorage);
|
|
11
|
+
createSession(name?: string): Session;
|
|
12
|
+
getSession(id: string): Session | null;
|
|
13
|
+
listSessions(): Session[];
|
|
14
|
+
deleteSession(id: string): void;
|
|
15
|
+
addMessage(sessionId: string, message: AIMessage): void;
|
|
16
|
+
clearMessages(sessionId: string): void;
|
|
17
|
+
private loadFromStorage;
|
|
18
|
+
private saveToStorage;
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AIMessage, Session as AISession } from '../types';
|
|
2
|
+
export type { AISession as Session };
|
|
3
|
+
export interface SessionStorage {
|
|
4
|
+
save(sessions: AISession[]): void;
|
|
5
|
+
load(): AISession[];
|
|
6
|
+
}
|
|
7
|
+
export interface SessionManagerInterface {
|
|
8
|
+
createSession(name?: string): AISession;
|
|
9
|
+
getSession(id: string): AISession | null;
|
|
10
|
+
listSessions(): AISession[];
|
|
11
|
+
deleteSession(id: string): void;
|
|
12
|
+
addMessage(sessionId: string, message: AIMessage): void;
|
|
13
|
+
clearMessages(sessionId: string): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ToolRegistry } from './function/registry';
|
|
2
|
+
import { SessionManager } from './session/manager';
|
|
3
|
+
import { AIMessage, AIProvider, AITool, Session } from './types';
|
|
4
|
+
interface AIState {
|
|
5
|
+
provider: AIProvider | null;
|
|
6
|
+
setProvider: (provider: AIProvider) => void;
|
|
7
|
+
sessions: Session[];
|
|
8
|
+
currentSessionId: string | null;
|
|
9
|
+
sessionManager: SessionManager;
|
|
10
|
+
toolRegistry: ToolRegistry;
|
|
11
|
+
createSession: (name?: string) => Session;
|
|
12
|
+
selectSession: (id: string) => void;
|
|
13
|
+
deleteSession: (id: string) => void;
|
|
14
|
+
addMessage: (message: AIMessage) => void;
|
|
15
|
+
registerTool: (tool: AITool) => void;
|
|
16
|
+
unregisterTool: (name: string) => void;
|
|
17
|
+
sendMessage: (content: string) => Promise<void>;
|
|
18
|
+
clearCurrentSession: () => void;
|
|
19
|
+
streamMessage: (content: string, onChunk: (chunk: string) => void) => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare const aiStore: import("zustand/vanilla").StoreApi<AIState>;
|
|
22
|
+
export declare function createAIStore(apiKey: string, defaultModel?: string): void;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI 能力抽象层类型定义
|
|
3
|
+
*/
|
|
4
|
+
export interface AIMessage {
|
|
5
|
+
id: string;
|
|
6
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
7
|
+
content: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
toolCallId?: string;
|
|
10
|
+
toolCalls?: ToolCall[];
|
|
11
|
+
createdAt?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ToolCall {
|
|
14
|
+
id: string;
|
|
15
|
+
type: 'function';
|
|
16
|
+
function: {
|
|
17
|
+
name: string;
|
|
18
|
+
arguments: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface ChatOptions {
|
|
22
|
+
model?: string;
|
|
23
|
+
temperature?: number;
|
|
24
|
+
maxTokens?: number;
|
|
25
|
+
tools?: AITool[];
|
|
26
|
+
stream?: boolean;
|
|
27
|
+
systemPrompt?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface AIProvider {
|
|
30
|
+
chat(messages: AIMessage[], options?: ChatOptions): Promise<AIMessage>;
|
|
31
|
+
stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable<AIChunk>;
|
|
32
|
+
functionCall(messages: AIMessage[], tools: AITool[], options?: ChatOptions): Promise<FunctionCallResult>;
|
|
33
|
+
}
|
|
34
|
+
export interface AIChunk {
|
|
35
|
+
type: 'content' | 'tool-call' | 'done' | 'error';
|
|
36
|
+
content?: string;
|
|
37
|
+
toolCall?: ToolCall;
|
|
38
|
+
error?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface FunctionCallResult {
|
|
41
|
+
message: AIMessage;
|
|
42
|
+
toolCalls: ToolCall[];
|
|
43
|
+
}
|
|
44
|
+
export interface Session {
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
messages: AIMessage[];
|
|
48
|
+
createdAt: number;
|
|
49
|
+
updatedAt: number;
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
export interface AITool {
|
|
53
|
+
name: string;
|
|
54
|
+
description: string;
|
|
55
|
+
parameters: Record<string, unknown>;
|
|
56
|
+
execute: (args: Record<string, unknown>) => Promise<unknown>;
|
|
57
|
+
}
|
|
@@ -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
|
+
}
|