@tombcato/ai-selector-core 0.1.1 → 0.1.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.
Files changed (47) hide show
  1. package/dist/index.d.ts +354 -13
  2. package/dist/index.js +784 -19
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.umd.js +2 -0
  5. package/dist/index.umd.js.map +1 -0
  6. package/package.json +6 -4
  7. package/dist/api.d.ts +0 -14
  8. package/dist/api.d.ts.map +0 -1
  9. package/dist/api.js +0 -139
  10. package/dist/api.js.map +0 -1
  11. package/dist/config.d.ts +0 -18
  12. package/dist/config.d.ts.map +0 -1
  13. package/dist/config.js +0 -85
  14. package/dist/config.js.map +0 -1
  15. package/dist/i18n.d.ts +0 -53
  16. package/dist/i18n.d.ts.map +0 -1
  17. package/dist/i18n.js +0 -51
  18. package/dist/i18n.js.map +0 -1
  19. package/dist/icons.d.ts +0 -10
  20. package/dist/icons.d.ts.map +0 -1
  21. package/dist/icons.js +0 -22
  22. package/dist/icons.js.map +0 -1
  23. package/dist/index.d.ts.map +0 -1
  24. package/dist/models.d.ts +0 -11
  25. package/dist/models.d.ts.map +0 -1
  26. package/dist/models.js +0 -199
  27. package/dist/models.js.map +0 -1
  28. package/dist/providers.d.ts +0 -42
  29. package/dist/providers.d.ts.map +0 -1
  30. package/dist/providers.js +0 -229
  31. package/dist/providers.js.map +0 -1
  32. package/dist/storage.d.ts +0 -31
  33. package/dist/storage.d.ts.map +0 -1
  34. package/dist/storage.js +0 -65
  35. package/dist/storage.js.map +0 -1
  36. package/dist/strategies.d.ts +0 -54
  37. package/dist/strategies.d.ts.map +0 -1
  38. package/dist/strategies.js +0 -184
  39. package/dist/strategies.js.map +0 -1
  40. package/dist/types.d.ts +0 -122
  41. package/dist/types.d.ts.map +0 -1
  42. package/dist/types.js +0 -6
  43. package/dist/types.js.map +0 -1
  44. package/dist/utils.d.ts +0 -2
  45. package/dist/utils.d.ts.map +0 -1
  46. package/dist/utils.js +0 -4
  47. package/dist/utils.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,13 +1,354 @@
1
- /**
2
- * AI Provider Selector - Core Package
3
- * Framework-agnostic logic for AI provider configuration
4
- */
5
- export * from './i18n';
6
- export type { Provider, Model, AIConfig, ApiFormat, TestConnectionOptions, TestConnectionResult, FetchModelsOptions, StorageAdapter, ProviderConfig, CustomProviderDefinition, AIConfigFormProps, ModelFetcher, FetcherParams, FetcherActionType, } from './types';
7
- export { PROVIDERS, PROVIDER_ID, type ProviderId, getProvider, getAllProviders, getProvidersByFormat } from './providers';
8
- export { STATIC_MODELS, getStaticModels } from './models';
9
- export { testConnection, fetchModels } from './api';
10
- export { localStorageAdapter, createConfigStorage } from './storage';
11
- export { resolveProviderConfig, getProviderFromConfig, type ResolvedConfig } from './config';
12
- export { type ProviderStrategy, strategyRegistry, getStrategy, sendDirectChat, testDirectConnection, type DirectChatOptions, type DirectChatResult, } from './strategies';
13
- //# sourceMappingURL=index.d.ts.map
1
+ export declare interface AIConfig {
2
+ providerId: string;
3
+ apiKey: string;
4
+ model: string;
5
+ modelName?: string;
6
+ baseUrl?: string;
7
+ }
8
+
9
+ /** AIConfigForm 组件的 Props */
10
+ export declare interface AIConfigFormProps {
11
+ /**
12
+ * 自定义请求处理器
13
+ * 用于接管获取模型列表和连通性测试的请求
14
+ * 如果提供此函数,proxyUrl 在这两种操作中将被忽略
15
+ */
16
+ modelFetcher?: ModelFetcher;
17
+ /** 后端代理地址(必需,除非提供了 modelFetcher) */
18
+ proxyUrl?: string;
19
+ /** Provider 配置(可选,默认使用全部内置 Providers) */
20
+ config?: ProviderConfig;
21
+ /** 初始配置(可选,用于编辑已有配置) */
22
+ initialConfig?: Partial<AIConfig>;
23
+ /** 表单标题 */
24
+ title?: string;
25
+ /** 是否显示配置预览区域 */
26
+ showPreview?: boolean;
27
+ /** 保存按钮文本 */
28
+ saveButtonText?: string;
29
+ /** 是否禁用整个表单 */
30
+ disabled?: boolean;
31
+ }
32
+
33
+ /**
34
+ * AI Provider Selector - Core Types
35
+ * Framework-agnostic type definitions
36
+ */
37
+ export declare type ApiFormat = 'openai' | 'anthropic' | 'gemini' | 'cohere';
38
+
39
+ export declare function createConfigStorage(adapter?: StorageAdapter, options?: StorageOptions): {
40
+ /**
41
+ * Save AI config
42
+ */
43
+ save(config: AIConfig): void;
44
+ /**
45
+ * Load AI config
46
+ */
47
+ load(): AIConfig | null;
48
+ /**
49
+ * Clear AI config
50
+ */
51
+ clear(): void;
52
+ };
53
+
54
+ /** 自定义 Provider 定义 */
55
+ export declare interface CustomProviderDefinition {
56
+ name: string;
57
+ baseUrl: string;
58
+ needsApiKey: boolean;
59
+ apiFormat: ApiFormat;
60
+ supportsModelsApi?: boolean;
61
+ icon?: string;
62
+ /** 静态模型列表(当不支持 /models API 时使用) */
63
+ models?: Model[];
64
+ }
65
+
66
+ /** 自定义 Provider 定义 */
67
+ export declare interface CustomProviderDefinition {
68
+ name: string;
69
+ baseUrl: string;
70
+ needsApiKey: boolean;
71
+ apiFormat: ApiFormat;
72
+ supportsModelsApi?: boolean;
73
+ icon?: string;
74
+ /** 静态模型列表(当不支持 /models API 时使用) */
75
+ models?: Model[];
76
+ }
77
+
78
+ export declare interface DirectChatOptions {
79
+ apiFormat: string;
80
+ baseUrl: string;
81
+ apiKey: string;
82
+ model: string;
83
+ messages: Array<{
84
+ role: string;
85
+ content: string;
86
+ }>;
87
+ maxTokens?: number;
88
+ }
89
+
90
+ export declare interface DirectChatResult {
91
+ success: boolean;
92
+ content?: string;
93
+ message?: string;
94
+ latencyMs?: number;
95
+ }
96
+
97
+ export declare type FetcherActionType = 'fetchModels' | 'checkConnection';
98
+
99
+ export declare interface FetcherParams {
100
+ type: FetcherActionType;
101
+ providerId: string;
102
+ baseUrl: string;
103
+ apiKey?: string;
104
+ modelId?: string;
105
+ }
106
+
107
+ /**
108
+ * Fetch available models from a provider
109
+ */
110
+ export declare function fetchModels(options: FetchModelsOptions): Promise<Model[]>;
111
+
112
+ export declare interface FetchModelsOptions {
113
+ provider: Provider;
114
+ apiKey?: string;
115
+ baseUrl?: string;
116
+ proxyUrl?: string;
117
+ fallbackToStatic?: boolean;
118
+ }
119
+
120
+ /**
121
+ * Get all providers as an array
122
+ */
123
+ export declare function getAllProviders(): Provider[];
124
+
125
+ /**
126
+ * Get a provider by ID
127
+ */
128
+ export declare function getProvider(id: string): Provider | undefined;
129
+
130
+ /**
131
+ * Get a single provider by ID from config
132
+ */
133
+ export declare function getProviderFromConfig(providerId: string, config?: ProviderConfig): Provider | null;
134
+
135
+ /**
136
+ * Get providers by API format
137
+ */
138
+ export declare function getProvidersByFormat(format: Provider['apiFormat']): Provider[];
139
+
140
+ /**
141
+ * Get static models for a provider
142
+ */
143
+ export declare function getStaticModels(providerId: string): Model[];
144
+
145
+ export declare function getStrategy(format: string): ProviderStrategy;
146
+
147
+ export declare const I18N: {
148
+ readonly zh: {
149
+ readonly save: "保存配置";
150
+ readonly saved: "保存成功";
151
+ readonly providerLabel: "Provider";
152
+ readonly modelLabel: "Model";
153
+ readonly selectProvider: "选择 Provider...";
154
+ readonly customBaseUrl: "自定义 Base URL";
155
+ readonly apiKeyLabel: "API Key";
156
+ readonly apiKeyPlaceholder: "输入 API Key...";
157
+ readonly testConnection: "测试模型连接";
158
+ readonly testing: "测试中...";
159
+ readonly testSuccess: "连接成功";
160
+ readonly testFailed: "测试连通性失败";
161
+ readonly selectModel: "选择 Model...";
162
+ readonly searchModel: "搜索或自定义模型...";
163
+ readonly useCustom: "使用自定义";
164
+ readonly noModels: "暂无模型数据";
165
+ readonly apiKeyTip: "输入 API Key 后可获取完整模型列表";
166
+ readonly fetchModelsFailed: "拉取模型列表失败,已使用离线模型列表";
167
+ readonly refreshingModels: "列表刷新中...";
168
+ readonly modelListUpdated: "模型列表已刷新";
169
+ readonly preview: "配置预览";
170
+ readonly unselected: "(未选择)";
171
+ };
172
+ readonly en: {
173
+ readonly save: "Save Config";
174
+ readonly saved: "Saved";
175
+ readonly providerLabel: "Provider";
176
+ readonly modelLabel: "Model";
177
+ readonly selectProvider: "Select Provider...";
178
+ readonly customBaseUrl: "Custom Base URL";
179
+ readonly apiKeyLabel: "API Key";
180
+ readonly apiKeyPlaceholder: "Enter API Key...";
181
+ readonly testConnection: "Test Model Connection";
182
+ readonly testing: "Testing...";
183
+ readonly testSuccess: "Connection Successful";
184
+ readonly testFailed: "Connection Failed";
185
+ readonly selectModel: "Select Model...";
186
+ readonly searchModel: "Search or custom models...";
187
+ readonly useCustom: "Use custom";
188
+ readonly noModels: "No models found";
189
+ readonly apiKeyTip: "Enter API Key to fetch full model list";
190
+ readonly fetchModelsFailed: "Failed to fetch model list, using offline models";
191
+ readonly refreshingModels: "Refreshing models...";
192
+ readonly modelListUpdated: "Model list updated";
193
+ readonly preview: "Config Preview";
194
+ readonly unselected: "(Unselected)";
195
+ };
196
+ };
197
+
198
+ export declare type I18NKeys = keyof typeof I18N['zh'];
199
+
200
+ export declare type Language = keyof typeof I18N;
201
+
202
+ /**
203
+ * Default localStorage adapter
204
+ */
205
+ export declare const localStorageAdapter: StorageAdapter;
206
+
207
+ export declare interface Model {
208
+ id: string;
209
+ name: string;
210
+ }
211
+
212
+ /**
213
+ * Custom fetcher for retrieving models and checking connection.
214
+ * If provided, this will bypass internal fetch logic.
215
+ *
216
+ * - type='fetchModels': returns Promise<Model[]>
217
+ * - type='checkConnection': returns Promise<{ success: boolean; latency?: number; message?: string }>
218
+ */
219
+ export declare type ModelFetcher = (params: FetcherParams) => Promise<any>;
220
+
221
+ export declare interface Provider {
222
+ id: string;
223
+ name: string;
224
+ baseUrl: string;
225
+ needsApiKey: boolean;
226
+ apiFormat: ApiFormat;
227
+ supportsModelsApi: boolean;
228
+ icon?: string;
229
+ }
230
+
231
+ export declare const PROVIDER_ID: {
232
+ readonly OPENAI: "openai";
233
+ readonly ANTHROPIC: "anthropic";
234
+ readonly GEMINI: "gemini";
235
+ readonly DEEPSEEK: "deepseek";
236
+ readonly OPENROUTER: "openrouter";
237
+ readonly GROQ: "groq";
238
+ readonly MISTRAL: "mistral";
239
+ readonly MOONSHOT: "moonshot";
240
+ readonly QWEN: "qwen";
241
+ readonly ZHIPU: "zhipu";
242
+ readonly SILICONFLOW: "siliconflow";
243
+ readonly XAI: "xai";
244
+ readonly TOGETHER: "together";
245
+ readonly FIREWORKS: "fireworks";
246
+ readonly DEEPINFRA: "deepinfra";
247
+ readonly PERPLEXITY: "perplexity";
248
+ readonly COHERE: "cohere";
249
+ readonly OLLAMA: "ollama";
250
+ readonly DOUBAO: "doubao";
251
+ readonly MINIMAX: "minimax";
252
+ };
253
+
254
+ /** Provider 配置 JSON */
255
+ export declare interface ProviderConfig {
256
+ /** 模式:default=内置+自定义,customOnly=只用自定义 */
257
+ mode: 'default' | 'customOnly';
258
+ /** 白名单:只显示这些内置 provider(仅 mode=default) */
259
+ include?: string[];
260
+ /** 黑名单:隐藏这些内置 provider(仅 mode=default) */
261
+ exclude?: string[];
262
+ /** 自定义 Providers */
263
+ custom?: Record<string, CustomProviderDefinition>;
264
+ }
265
+
266
+ export declare type ProviderId = typeof PROVIDER_ID[keyof typeof PROVIDER_ID];
267
+
268
+ export declare const PROVIDERS: Record<string, Provider>;
269
+
270
+ export declare interface ProviderStrategy {
271
+ format: string;
272
+ getModelsEndpoint?: (baseUrl: string, apiKey: string) => string;
273
+ parseModelsResponse?: (data: any) => Model[];
274
+ getChatEndpoint: (baseUrl: string, apiKey: string, model: string) => string;
275
+ buildChatPayload: (model: string, messages: Array<{
276
+ role: string;
277
+ content: string;
278
+ }>, maxTokens: number) => Record<string, unknown>;
279
+ parseChatResponse: (data: any) => string;
280
+ buildHeaders: (apiKey: string) => Record<string, string>;
281
+ }
282
+
283
+ export declare interface ResolvedConfig {
284
+ providers: Provider[];
285
+ getModels: (providerId: string) => Model[];
286
+ }
287
+
288
+ /**
289
+ * Resolve a ProviderConfig into usable providers and models
290
+ */
291
+ export declare function resolveProviderConfig(config?: ProviderConfig): ResolvedConfig;
292
+
293
+ /**
294
+ * 纯前端直连 AI 厂商进行聊天
295
+ * 注意: 这会将 API Key 暴露在浏览器中,仅适用于 Demo/测试场景
296
+ */
297
+ export declare function sendDirectChat(options: DirectChatOptions): Promise<DirectChatResult>;
298
+
299
+ export declare const STATIC_MODELS: Record<string, Model[]>;
300
+
301
+ export declare interface StorageAdapter {
302
+ get(key: string): string | null;
303
+ set(key: string, value: string): void;
304
+ remove(key: string): void;
305
+ }
306
+
307
+ /**
308
+ * Create a config storage instance
309
+ */
310
+ declare interface StorageOptions {
311
+ serialize?: (data: any) => string;
312
+ deserialize?: (data: string) => any;
313
+ }
314
+
315
+ export declare const strategyRegistry: Record<string, ProviderStrategy>;
316
+
317
+ /**
318
+ * Test connection to an AI provider
319
+ */
320
+ export declare function testConnection(options: TestConnectionOptions): Promise<TestConnectionResult>;
321
+
322
+ export declare interface TestConnectionOptions {
323
+ provider: Provider;
324
+ apiKey: string;
325
+ model?: string;
326
+ baseUrl?: string;
327
+ proxyUrl?: string;
328
+ }
329
+
330
+ declare interface TestConnectionOptions_2 {
331
+ apiFormat: string;
332
+ baseUrl: string;
333
+ apiKey: string;
334
+ model: string;
335
+ }
336
+
337
+ export declare interface TestConnectionResult {
338
+ success: boolean;
339
+ latencyMs?: number;
340
+ message?: string;
341
+ }
342
+
343
+ declare interface TestConnectionResult_2 {
344
+ success: boolean;
345
+ latencyMs?: number;
346
+ message?: string;
347
+ }
348
+
349
+ /**
350
+ * 测试 AI 厂商连接 (通过发送一个简单的聊天请求)
351
+ */
352
+ export declare function testDirectConnection(options: TestConnectionOptions_2): Promise<TestConnectionResult_2>;
353
+
354
+ export { }