@kevisual/ai 0.0.12 → 0.0.14
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/ai-provider-browser.d.ts +93 -13
- package/dist/ai-provider-browser.js +1672 -1549
- package/dist/ai-provider.d.ts +93 -13
- package/dist/ai-provider.js +136 -13
- package/package.json +9 -9
- package/src/provider/chat-adapter/kimi.ts +10 -0
- package/src/provider/chat-adapter/zhipu.ts +10 -0
- package/src/provider/chat.ts +6 -0
- package/src/provider/core/chat.ts +3 -27
- package/src/provider/core/utils/index.ts +192 -0
- package/src/provider/index.ts +2 -0
- package/src/provider/utils/chunk.ts +0 -86
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as openai_resources_index_mjs from 'openai/resources/index.mjs';
|
|
2
2
|
import OpenAI, { OpenAI as OpenAI$1 } from 'openai';
|
|
3
3
|
import * as openai_resources_embeddings_mjs from 'openai/resources/embeddings.mjs';
|
|
4
|
-
import
|
|
4
|
+
import * as _kevisual_permission from '@kevisual/permission';
|
|
5
|
+
import { Permission } from '@kevisual/permission';
|
|
5
6
|
|
|
6
7
|
type ChatMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
|
7
8
|
type ChatMessageOptions = Partial<OpenAI.Chat.Completions.ChatCompletionCreateParams> & {
|
|
@@ -34,6 +35,77 @@ interface BaseChatUsageInterface {
|
|
|
34
35
|
}
|
|
35
36
|
type ChatStream = AsyncGenerator<ChatMessageComplete, void, unknown>;
|
|
36
37
|
|
|
38
|
+
declare class AIUtils {
|
|
39
|
+
/**
|
|
40
|
+
* 从 Markdown 代码块中提取 JSON
|
|
41
|
+
* @param str 包含 JSON 的字符串
|
|
42
|
+
* @returns 解析后的对象或 null
|
|
43
|
+
*/
|
|
44
|
+
extractJsonFromMarkdown(str: string): any | null;
|
|
45
|
+
/**
|
|
46
|
+
* 从 Markdown 代码块中提取代码
|
|
47
|
+
* @param str Markdown 字符串
|
|
48
|
+
* @param language 语言类型,不指定则返回所有代码块
|
|
49
|
+
* @returns 提取的代码字符串或数组
|
|
50
|
+
*/
|
|
51
|
+
extractCodeFromMarkdown(str: string, language?: string): string | string[] | null;
|
|
52
|
+
/**
|
|
53
|
+
* 清理 AI 响应中的多余空白和格式
|
|
54
|
+
* @param str 原始字符串
|
|
55
|
+
* @returns 清理后的字符串
|
|
56
|
+
*/
|
|
57
|
+
cleanResponse(str: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* 从 AI 响应中提取标签
|
|
60
|
+
* @param str 响应字符串
|
|
61
|
+
* @returns 标签数组
|
|
62
|
+
*/
|
|
63
|
+
extractTags(str: string): string[];
|
|
64
|
+
/**
|
|
65
|
+
* 从文本中提取 URL
|
|
66
|
+
* @param str 文本字符串
|
|
67
|
+
* @returns URL 数组
|
|
68
|
+
*/
|
|
69
|
+
extractUrls(str: string): string[];
|
|
70
|
+
/**
|
|
71
|
+
* 分割长文本为指定 token 数量的块
|
|
72
|
+
* @param text 原始文本
|
|
73
|
+
* @param maxTokens 每块最大 token 数(粗略估算:1 token ≈ 4 字符)
|
|
74
|
+
* @returns 文本块数组
|
|
75
|
+
*/
|
|
76
|
+
chunkText(text: string, maxTokens?: number): string[];
|
|
77
|
+
/**
|
|
78
|
+
* 移除 AI 响应中的思考过程(thinking 标签)
|
|
79
|
+
* @param str 响应字符串
|
|
80
|
+
* @returns 清理后的字符串
|
|
81
|
+
*/
|
|
82
|
+
removeThinkingTags(str: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* 转义特殊字符用于 AI 提示词
|
|
85
|
+
* @param str 原始字符串
|
|
86
|
+
* @returns 转义后的字符串
|
|
87
|
+
*/
|
|
88
|
+
escapeForPrompt(str: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* 统计文本的大致 token 数量
|
|
91
|
+
* @param text 文本
|
|
92
|
+
* @returns 估算的 token 数量
|
|
93
|
+
*/
|
|
94
|
+
estimateTokens(text: string): number;
|
|
95
|
+
/**
|
|
96
|
+
* 从响应中提取结构化数据(key: value 格式)
|
|
97
|
+
* @param str 响应字符串
|
|
98
|
+
* @returns 键值对对象
|
|
99
|
+
*/
|
|
100
|
+
extractKeyValuePairs(str: string): Record<string, string>;
|
|
101
|
+
/**
|
|
102
|
+
* 验证 AI 响应是否完整(检查截断)
|
|
103
|
+
* @param str 响应字符串
|
|
104
|
+
* @returns 是否完整
|
|
105
|
+
*/
|
|
106
|
+
isResponseComplete(str: string): boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
37
109
|
type BaseChatOptions<T = Record<string, any>> = {
|
|
38
110
|
/**
|
|
39
111
|
* 默认baseURL
|
|
@@ -56,7 +128,6 @@ type BaseChatOptions<T = Record<string, any>> = {
|
|
|
56
128
|
*/
|
|
57
129
|
stream?: boolean;
|
|
58
130
|
} & T;
|
|
59
|
-
declare const getIsBrowser: () => boolean;
|
|
60
131
|
declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
61
132
|
/**
|
|
62
133
|
* 默认baseURL
|
|
@@ -70,18 +141,11 @@ declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
|
70
141
|
* 默认apiKey
|
|
71
142
|
*/
|
|
72
143
|
apiKey: string;
|
|
73
|
-
/**
|
|
74
|
-
* 是否在浏览器中使用
|
|
75
|
-
*/
|
|
76
|
-
isBrowser: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* openai实例
|
|
79
|
-
*/
|
|
80
|
-
openai: OpenAI$1;
|
|
81
144
|
prompt_tokens: number;
|
|
82
145
|
total_tokens: number;
|
|
83
146
|
completion_tokens: number;
|
|
84
147
|
responseText: string;
|
|
148
|
+
utils: typeof AIUtils;
|
|
85
149
|
constructor(options: BaseChatOptions);
|
|
86
150
|
post(url?: string, opts?: {
|
|
87
151
|
headers?: Record<string, string>;
|
|
@@ -217,6 +281,18 @@ declare class BailianChat extends BaseChat {
|
|
|
217
281
|
constructor(options: BailianOptions);
|
|
218
282
|
}
|
|
219
283
|
|
|
284
|
+
type ZhipuOptions = Partial<BaseChatOptions>;
|
|
285
|
+
declare class Zhipu extends BaseChat {
|
|
286
|
+
static BASE_URL: string;
|
|
287
|
+
constructor(options: ZhipuOptions);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
type KimiOptions = Partial<BaseChatOptions>;
|
|
291
|
+
declare class Kimi extends BaseChat {
|
|
292
|
+
static BASE_URL: string;
|
|
293
|
+
constructor(options: KimiOptions);
|
|
294
|
+
}
|
|
295
|
+
|
|
220
296
|
declare const OllamaProvider: typeof Ollama;
|
|
221
297
|
declare const SiliconFlowProvider: typeof SiliconFlow;
|
|
222
298
|
declare const CustomProvider: typeof Custom;
|
|
@@ -224,6 +300,8 @@ declare const VolcesProvider: typeof Volces;
|
|
|
224
300
|
declare const DeepSeekProvider: typeof DeepSeek;
|
|
225
301
|
declare const ModelScopeProvider: typeof ModelScope;
|
|
226
302
|
declare const BailianProvider: typeof BailianChat;
|
|
303
|
+
declare const ZhipuProvider: typeof Zhipu;
|
|
304
|
+
declare const KimiProvider: typeof Kimi;
|
|
227
305
|
declare const ChatProviderMap: {
|
|
228
306
|
Ollama: typeof Ollama;
|
|
229
307
|
SiliconFlow: typeof SiliconFlow;
|
|
@@ -233,6 +311,8 @@ declare const ChatProviderMap: {
|
|
|
233
311
|
ModelScope: typeof ModelScope;
|
|
234
312
|
BaseChat: typeof BaseChat;
|
|
235
313
|
Bailian: typeof BailianChat;
|
|
314
|
+
Zhipu: typeof Zhipu;
|
|
315
|
+
Kimi: typeof Kimi;
|
|
236
316
|
};
|
|
237
317
|
type ProviderManagerConfig = {
|
|
238
318
|
provider: string;
|
|
@@ -352,7 +432,7 @@ type AIConfig = {
|
|
|
352
432
|
description?: string;
|
|
353
433
|
models: AIModel[];
|
|
354
434
|
secretKeys: SecretKey[];
|
|
355
|
-
permission?: Permission
|
|
435
|
+
permission?: Permission;
|
|
356
436
|
filter?: {
|
|
357
437
|
objectKey: string;
|
|
358
438
|
type: 'array' | 'object';
|
|
@@ -437,7 +517,7 @@ declare class AIConfigParser {
|
|
|
437
517
|
title?: string;
|
|
438
518
|
description?: string;
|
|
439
519
|
models?: AIModel[];
|
|
440
|
-
permission?: Permission;
|
|
520
|
+
permission?: _kevisual_permission.Permission;
|
|
441
521
|
filter?: {
|
|
442
522
|
objectKey: string;
|
|
443
523
|
type: "array" | "object";
|
|
@@ -447,5 +527,5 @@ declare class AIConfigParser {
|
|
|
447
527
|
};
|
|
448
528
|
}
|
|
449
529
|
|
|
450
|
-
export { AIConfigParser, BailianProvider, BaseChat, ChatProviderMap, CustomProvider, DeepSeekProvider, KnowledgeBase, ModelScopeProvider, OllamaProvider, ProviderManager, SiliconFlowKnowledge, SiliconFlowProvider, VolcesProvider, decryptAES, encryptAES,
|
|
530
|
+
export { AIConfigParser, AIUtils, BailianProvider, BaseChat, ChatProviderMap, CustomProvider, DeepSeekProvider, KimiProvider, KnowledgeBase, ModelScopeProvider, OllamaProvider, ProviderManager, SiliconFlowKnowledge, SiliconFlowProvider, VolcesProvider, ZhipuProvider, decryptAES, encryptAES, readStream };
|
|
451
531
|
export type { AIConfig, AIModel, BaseChatInterface, BaseChatOptions, BaseChatUsageInterface, ChatMessage, ChatMessageComplete, ChatMessageOptions, ChatMessageStream, ChatStream, EmbeddingMessage, EmbeddingMessageComplete, GetProviderOpts, KnowledgeOptions, ProviderResult, RerankOptions, SecretKey };
|