@spacex110/core 0.1.11 → 0.1.13
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/dist/index.d.ts +58 -0
- package/dist/index.js +1116 -1011
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +4 -4
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/channel-manager.ts +151 -0
- package/src/strategies.ts +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export declare class AIChannelManager {
|
|
|
4
4
|
private activeChannelId;
|
|
5
5
|
private storagePrefix;
|
|
6
6
|
private activeChannelKey;
|
|
7
|
+
private capabilityDefaultsKey;
|
|
8
|
+
private capabilityDefaults;
|
|
7
9
|
private proxyUrl?;
|
|
8
10
|
private listeners;
|
|
9
11
|
constructor(options?: ChannelManagerOptions);
|
|
@@ -18,6 +20,8 @@ export declare class AIChannelManager {
|
|
|
18
20
|
private saveChannel;
|
|
19
21
|
private deleteChannelFromStorage;
|
|
20
22
|
private saveActiveChannel;
|
|
23
|
+
private loadCapabilityDefaults;
|
|
24
|
+
private saveCapabilityDefaults;
|
|
21
25
|
/** 添加通道 */
|
|
22
26
|
addChannel(config: AIConfig, name?: string): Promise<ChannelConfig>;
|
|
23
27
|
/** 删除通道 */
|
|
@@ -46,6 +50,58 @@ export declare class AIChannelManager {
|
|
|
46
50
|
setActiveChannel(id: string): void;
|
|
47
51
|
/** 清除当前激活的通道 */
|
|
48
52
|
clearActiveChannel(): void;
|
|
53
|
+
/**
|
|
54
|
+
* 为指定能力类型设置默认通道
|
|
55
|
+
* 当调用 getChannelForCapability 时,优先返回此通道
|
|
56
|
+
*/
|
|
57
|
+
setDefaultForCapability(capability: ModelCapability, channelId: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* 获取指定能力类型的默认通道 ID
|
|
60
|
+
* 返回 undefined 表示未设置
|
|
61
|
+
*/
|
|
62
|
+
getDefaultForCapability(capability: ModelCapability): string | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* 清除指定能力类型的默认通道
|
|
65
|
+
*/
|
|
66
|
+
clearDefaultForCapability(capability: ModelCapability): void;
|
|
67
|
+
/**
|
|
68
|
+
* 获取所有能力类型的默认通道映射
|
|
69
|
+
* 返回 { capability: channelId } 的对象
|
|
70
|
+
*/
|
|
71
|
+
getAllCapabilityDefaults(): Record<string, string>;
|
|
72
|
+
/**
|
|
73
|
+
* 根据能力类型获取最适合的通道(带降级链)
|
|
74
|
+
*
|
|
75
|
+
* 降级链:
|
|
76
|
+
* 1. 该能力类型的显式默认通道
|
|
77
|
+
* 2. 具有该能力且最后使用时间最新的通道
|
|
78
|
+
* 3. 全局激活通道
|
|
79
|
+
* 4. 第一个可用通道
|
|
80
|
+
*/
|
|
81
|
+
getChannelForCapability(capability: ModelCapability): ChannelConfig | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* 使用指定能力类型的默认通道发送聊天请求
|
|
84
|
+
* 自动选择合适的通道,无需手动指定 channelId
|
|
85
|
+
*/
|
|
86
|
+
chatForCapability(capability: ModelCapability, message: string, options?: {
|
|
87
|
+
messages?: Array<{
|
|
88
|
+
role: string;
|
|
89
|
+
content: string;
|
|
90
|
+
}>;
|
|
91
|
+
maxTokens?: number;
|
|
92
|
+
}): Promise<ChatResult>;
|
|
93
|
+
/**
|
|
94
|
+
* 使用指定能力类型的默认通道发送流式聊天请求
|
|
95
|
+
*/
|
|
96
|
+
chatStreamForCapability(capability: ModelCapability, message: string, options?: {
|
|
97
|
+
messages?: Array<{
|
|
98
|
+
role: string;
|
|
99
|
+
content: string;
|
|
100
|
+
}>;
|
|
101
|
+
maxTokens?: number;
|
|
102
|
+
signal?: AbortSignal;
|
|
103
|
+
onDelta?: (full: string) => void;
|
|
104
|
+
}): Promise<ChatResult>;
|
|
49
105
|
/** 获取 Provider 的可用模型列表(动态获取 + 静态兜底) */
|
|
50
106
|
getProviderModels(providerId: string, apiKey?: string, baseUrl?: string): Promise<Model[]>;
|
|
51
107
|
/** 获取通道对应的 Provider 的模型列表 */
|
|
@@ -243,6 +299,8 @@ export declare interface ChannelManagerOptions {
|
|
|
243
299
|
storagePrefix?: string;
|
|
244
300
|
/** 当前激活通道的存储键 */
|
|
245
301
|
activeChannelKey?: string;
|
|
302
|
+
/** 能力默认通道的存储键 */
|
|
303
|
+
capabilityDefaultsKey?: string;
|
|
246
304
|
/** 后端代理地址(可选,用于解决 CORS 问题) */
|
|
247
305
|
proxyUrl?: string;
|
|
248
306
|
}
|