@opentiny/tiny-robot-kit 0.4.2-alpha.2 → 0.4.2-alpha.4
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/chunk-6JEZBNBO.mjs +5 -0
- package/dist/chunk-ZO2ZONVX.mjs +1 -0
- package/dist/core.d.mts +142 -0
- package/dist/core.d.ts +142 -0
- package/dist/core.js +6 -0
- package/dist/core.mjs +2 -0
- package/dist/index.d.mts +63 -244
- package/dist/index.d.ts +63 -244
- package/dist/index.js +7 -3
- package/dist/index.mjs +3 -3
- package/dist/node.d.mts +14 -0
- package/dist/node.d.ts +14 -0
- package/dist/node.js +1 -0
- package/dist/node.mjs +1 -0
- package/dist/skillPlugin-4pC5SvPk.d.mts +548 -0
- package/dist/skillPlugin-D6X-p9fQ.d.ts +548 -0
- package/dist/types-ChCZ8jKB.d.mts +70 -0
- package/dist/types-ChCZ8jKB.d.ts +70 -0
- package/package.json +30 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,215 +1,8 @@
|
|
|
1
|
+
import { a as AIModelConfig, f as ChatCompletionRequest, g as ChatCompletionResponse, W as StreamHandler, B as BaseModelProvider, p as ChatMessage, M as MaybePromise, X as ToolCall, N as SkillCommandRequest, O as SkillCommandResult, T as SkillPluginState, $ as ToolSource, _ as ToolProviderItem } from './skillPlugin-4pC5SvPk.mjs';
|
|
2
|
+
export { A as AIAdapterError, b as AIProvider, C as ChatCompletionOptions, h as ChatCompletionResponseChoice, i as ChatCompletionResponseMessage, j as ChatCompletionResponseUsage, k as ChatCompletionStreamResponse, l as ChatCompletionStreamResponseChoice, m as ChatCompletionStreamResponseDelta, n as ChatHistory, E as ErrorType, u as MessageMetadata, x as MessageRole, V as StreamEventType } from './skillPlugin-4pC5SvPk.mjs';
|
|
1
3
|
import { Ref, ComputedRef } from 'vue';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* 模型Provider基类
|
|
5
|
-
*/
|
|
6
|
-
declare abstract class BaseModelProvider {
|
|
7
|
-
protected config: AIModelConfig;
|
|
8
|
-
/**
|
|
9
|
-
* @param config AI模型配置
|
|
10
|
-
*/
|
|
11
|
-
constructor(config: AIModelConfig);
|
|
12
|
-
/**
|
|
13
|
-
* 发送聊天请求并获取响应
|
|
14
|
-
* @param request 聊天请求参数
|
|
15
|
-
* @returns 聊天响应
|
|
16
|
-
*/
|
|
17
|
-
abstract chat(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
18
|
-
/**
|
|
19
|
-
* 发送流式聊天请求并通过处理器处理响应
|
|
20
|
-
* @param request 聊天请求参数
|
|
21
|
-
* @param handler 流式响应处理器
|
|
22
|
-
*/
|
|
23
|
-
abstract chatStream(request: ChatCompletionRequest, handler: StreamHandler): Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* 更新配置
|
|
26
|
-
* @param config 新的AI模型配置
|
|
27
|
-
*/
|
|
28
|
-
updateConfig(config: AIModelConfig): void;
|
|
29
|
-
/**
|
|
30
|
-
* 获取当前配置
|
|
31
|
-
* @returns AI模型配置
|
|
32
|
-
*/
|
|
33
|
-
getConfig(): AIModelConfig;
|
|
34
|
-
/**
|
|
35
|
-
* 验证请求参数
|
|
36
|
-
* @param request 聊天请求参数
|
|
37
|
-
*/
|
|
38
|
-
protected validateRequest(request: ChatCompletionRequest): void;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
42
|
-
/**
|
|
43
|
-
* 消息角色类型
|
|
44
|
-
*/
|
|
45
|
-
type MessageRole = 'system' | 'user' | 'assistant';
|
|
46
|
-
interface ToolCall {
|
|
47
|
-
index: number;
|
|
48
|
-
id: string;
|
|
49
|
-
type: 'function';
|
|
50
|
-
function: {
|
|
51
|
-
name: string;
|
|
52
|
-
arguments: string;
|
|
53
|
-
result?: string;
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
interface MessageMetadata {
|
|
57
|
-
createdAt?: number;
|
|
58
|
-
updatedAt?: number;
|
|
59
|
-
id?: string;
|
|
60
|
-
model?: string;
|
|
61
|
-
[key: string]: any;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* 聊天消息接口
|
|
65
|
-
*/
|
|
66
|
-
interface ChatMessage {
|
|
67
|
-
role: string;
|
|
68
|
-
content: string;
|
|
69
|
-
reasoning_content?: string;
|
|
70
|
-
metadata?: MessageMetadata;
|
|
71
|
-
tool_calls?: ToolCall[];
|
|
72
|
-
tool_call_id?: string;
|
|
73
|
-
[key: string]: any;
|
|
74
|
-
[key: symbol]: any;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* 聊天历史记录
|
|
78
|
-
*/
|
|
79
|
-
type ChatHistory = ChatMessage[];
|
|
80
|
-
/**
|
|
81
|
-
* 聊天完成请求选项
|
|
82
|
-
*/
|
|
83
|
-
interface ChatCompletionOptions {
|
|
84
|
-
model?: string;
|
|
85
|
-
temperature?: number;
|
|
86
|
-
top_p?: number;
|
|
87
|
-
n?: number;
|
|
88
|
-
stream?: boolean;
|
|
89
|
-
max_tokens?: number;
|
|
90
|
-
signal?: AbortSignal;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* 聊天完成请求参数
|
|
94
|
-
*/
|
|
95
|
-
interface ChatCompletionRequest {
|
|
96
|
-
messages: ChatMessage[];
|
|
97
|
-
options?: ChatCompletionOptions;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* 聊天完成响应消息
|
|
101
|
-
*/
|
|
102
|
-
interface ChatCompletionResponseMessage {
|
|
103
|
-
role: MessageRole;
|
|
104
|
-
content: string;
|
|
105
|
-
[x: string]: unknown;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* 聊天完成响应选择
|
|
109
|
-
*/
|
|
110
|
-
interface ChatCompletionResponseChoice {
|
|
111
|
-
index: number;
|
|
112
|
-
message: ChatCompletionResponseMessage;
|
|
113
|
-
finish_reason: string;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* 聊天完成响应使用情况
|
|
117
|
-
*/
|
|
118
|
-
interface ChatCompletionResponseUsage {
|
|
119
|
-
prompt_tokens: number;
|
|
120
|
-
completion_tokens: number;
|
|
121
|
-
total_tokens: number;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* 聊天完成响应
|
|
125
|
-
*/
|
|
126
|
-
interface ChatCompletionResponse {
|
|
127
|
-
id: string;
|
|
128
|
-
object: string;
|
|
129
|
-
created: number;
|
|
130
|
-
model: string;
|
|
131
|
-
choices: ChatCompletionResponseChoice[];
|
|
132
|
-
usage: ChatCompletionResponseUsage;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* 流式聊天完成响应增量
|
|
136
|
-
*/
|
|
137
|
-
interface ChatCompletionStreamResponseDelta {
|
|
138
|
-
content?: string;
|
|
139
|
-
role?: MessageRole;
|
|
140
|
-
[x: string]: unknown;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* 流式聊天完成响应选择
|
|
144
|
-
*/
|
|
145
|
-
interface ChatCompletionStreamResponseChoice {
|
|
146
|
-
index: number;
|
|
147
|
-
delta: ChatCompletionStreamResponseDelta;
|
|
148
|
-
finish_reason: string | null;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* 流式聊天完成响应
|
|
152
|
-
*/
|
|
153
|
-
interface ChatCompletionStreamResponse {
|
|
154
|
-
id: string;
|
|
155
|
-
object: string;
|
|
156
|
-
created: number;
|
|
157
|
-
model: string;
|
|
158
|
-
choices: ChatCompletionStreamResponseChoice[];
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* AI模型提供商类型
|
|
162
|
-
*/
|
|
163
|
-
type AIProvider = 'openai' | 'deepseek' | 'custom';
|
|
164
|
-
/**
|
|
165
|
-
* AI模型配置接口
|
|
166
|
-
*/
|
|
167
|
-
interface AIModelConfig {
|
|
168
|
-
provider: AIProvider;
|
|
169
|
-
providerImplementation?: BaseModelProvider;
|
|
170
|
-
apiKey?: string;
|
|
171
|
-
apiUrl?: string;
|
|
172
|
-
apiVersion?: string;
|
|
173
|
-
defaultModel?: string;
|
|
174
|
-
defaultOptions?: ChatCompletionOptions;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* 错误类型
|
|
178
|
-
*/
|
|
179
|
-
declare enum ErrorType {
|
|
180
|
-
NETWORK_ERROR = "network_error",
|
|
181
|
-
AUTHENTICATION_ERROR = "authentication_error",
|
|
182
|
-
RATE_LIMIT_ERROR = "rate_limit_error",
|
|
183
|
-
SERVER_ERROR = "server_error",
|
|
184
|
-
MODEL_ERROR = "model_error",
|
|
185
|
-
TIMEOUT_ERROR = "timeout_error",
|
|
186
|
-
UNKNOWN_ERROR = "unknown_error"
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* AI适配器错误
|
|
190
|
-
*/
|
|
191
|
-
interface AIAdapterError {
|
|
192
|
-
type: ErrorType;
|
|
193
|
-
message: string;
|
|
194
|
-
statusCode?: number;
|
|
195
|
-
originalError?: object;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* 流式响应事件类型
|
|
199
|
-
*/
|
|
200
|
-
declare enum StreamEventType {
|
|
201
|
-
DATA = "data",
|
|
202
|
-
ERROR = "error",
|
|
203
|
-
DONE = "done"
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* 流式响应处理器
|
|
207
|
-
*/
|
|
208
|
-
interface StreamHandler {
|
|
209
|
-
onData: (data: ChatCompletionStreamResponse) => void;
|
|
210
|
-
onError: (error: AIAdapterError) => void;
|
|
211
|
-
onDone: (finishReason?: string) => void;
|
|
212
|
-
}
|
|
4
|
+
import { S as SkillDefinition } from './types-ChCZ8jKB.mjs';
|
|
5
|
+
import 'openai/resources';
|
|
213
6
|
|
|
214
7
|
/**
|
|
215
8
|
* AI客户端类
|
|
@@ -353,6 +146,7 @@ interface ChatCompletion {
|
|
|
353
146
|
choices: CompletionChoice[];
|
|
354
147
|
usage?: Usage;
|
|
355
148
|
}
|
|
149
|
+
type ResponseProvider<T = ChatCompletion> = (requestBody: MessageRequestBody, abortSignal: AbortSignal) => Promise<T> | AsyncGenerator<T> | Promise<AsyncGenerator<T>>;
|
|
356
150
|
interface UseMessageOptions {
|
|
357
151
|
initialMessages?: ChatMessage[];
|
|
358
152
|
/**
|
|
@@ -366,7 +160,7 @@ interface UseMessageOptions {
|
|
|
366
160
|
*/
|
|
367
161
|
requestMessageFieldsExclude?: string[];
|
|
368
162
|
plugins?: UseMessagePlugin[];
|
|
369
|
-
responseProvider:
|
|
163
|
+
responseProvider: ResponseProvider;
|
|
370
164
|
/**
|
|
371
165
|
* 全局的数据块处理钩子,在接收到每个响应数据块时触发。
|
|
372
166
|
* 注意:此钩子与插件中的 onCompletionChunk 有区别。
|
|
@@ -664,48 +458,82 @@ declare function sseStreamToGenerator<T = any>(response: Response, options?: {
|
|
|
664
458
|
|
|
665
459
|
declare const useConversation: (options: UseConversationOptions) => UseConversationReturn;
|
|
666
460
|
|
|
667
|
-
declare const fallbackRolePlugin: (options?: UseMessagePlugin & {
|
|
668
|
-
fallbackRole?: string;
|
|
669
|
-
}) => UseMessagePlugin;
|
|
670
|
-
|
|
671
461
|
declare const lengthPlugin: (options?: UseMessagePlugin & {
|
|
672
462
|
continueContent?: string;
|
|
673
463
|
}) => UseMessagePlugin;
|
|
674
464
|
|
|
465
|
+
type VueSkillSource = SkillDefinition[] | undefined;
|
|
466
|
+
type VueSkillSourceRef = VueSkillSource | Ref<VueSkillSource> | ComputedRef<VueSkillSource>;
|
|
467
|
+
type UseMessageSkillPluginOptions = UseMessagePlugin & {
|
|
468
|
+
/**
|
|
469
|
+
* 当前请求要使用的 skills。支持普通数组、ref 或 computed。
|
|
470
|
+
*/
|
|
471
|
+
skills?: VueSkillSourceRef;
|
|
472
|
+
/**
|
|
473
|
+
* 动态返回当前请求要使用的 skills。
|
|
474
|
+
*/
|
|
475
|
+
getSkills?: (context: BasePluginContext) => MaybePromise<VueSkillSourceRef>;
|
|
476
|
+
/**
|
|
477
|
+
* 执行模型为某个 skill 规划的后端命令。
|
|
478
|
+
*
|
|
479
|
+
* @experimental 该 API 仍在设计和验证中,命令协议、返回结构和安全边界后续可能调整。
|
|
480
|
+
*/
|
|
481
|
+
executeSkillCommand?: (request: SkillCommandRequest, context: BasePluginContext) => MaybePromise<SkillCommandResult>;
|
|
482
|
+
/**
|
|
483
|
+
* skills 解析并转换为插件状态后触发。
|
|
484
|
+
*/
|
|
485
|
+
onSkillsResolved?: (state: SkillPluginState, context: BasePluginContext) => MaybePromise<void>;
|
|
486
|
+
};
|
|
487
|
+
declare const skillPlugin: (options: UseMessageSkillPluginOptions) => UseMessagePlugin;
|
|
488
|
+
|
|
675
489
|
declare const thinkingPlugin: (options?: UseMessagePlugin) => UseMessagePlugin;
|
|
676
490
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
491
|
+
interface UseMessageToolActionContext extends BasePluginContext {
|
|
492
|
+
assistantMessage: ChatMessage;
|
|
493
|
+
/**
|
|
494
|
+
* 当前工具的来源。
|
|
495
|
+
*/
|
|
496
|
+
toolSource?: ToolSource;
|
|
497
|
+
/**
|
|
498
|
+
* @deprecated use `assistantMessage` instead
|
|
499
|
+
*/
|
|
500
|
+
currentMessage: ChatMessage;
|
|
501
|
+
}
|
|
502
|
+
interface UseMessageCallToolContext extends UseMessageToolActionContext {
|
|
503
|
+
toolMessage: ChatMessage;
|
|
504
|
+
}
|
|
505
|
+
interface UseMessageToolCallContext extends BasePluginContext {
|
|
506
|
+
assistantMessage: ChatMessage;
|
|
507
|
+
/**
|
|
508
|
+
* 当前工具的来源。
|
|
509
|
+
*/
|
|
510
|
+
toolSource: ToolSource;
|
|
511
|
+
/**
|
|
512
|
+
* @deprecated use `assistantMessage` instead
|
|
513
|
+
*/
|
|
514
|
+
primaryMessage: ChatMessage;
|
|
515
|
+
toolMessage: ChatMessage;
|
|
516
|
+
}
|
|
682
517
|
declare const toolPlugin: (options: UseMessagePlugin & {
|
|
683
518
|
/**
|
|
684
519
|
* 获取工具列表的函数。
|
|
685
520
|
*/
|
|
686
|
-
getTools: () => Promise<
|
|
521
|
+
getTools: (context: BasePluginContext) => Promise<ToolProviderItem[]>;
|
|
687
522
|
/**
|
|
688
523
|
* 在处理包含 tool_calls 的响应前调用。
|
|
689
524
|
*/
|
|
690
|
-
beforeCallTools?: (toolCalls: ToolCall[], context:
|
|
691
|
-
currentMessage: ChatMessage;
|
|
692
|
-
}) => Promise<void>;
|
|
525
|
+
beforeCallTools?: (toolCalls: ToolCall[], context: UseMessageToolActionContext) => Promise<void>;
|
|
693
526
|
/**
|
|
694
527
|
* 执行单个工具调用并返回其文本结果的函数。
|
|
695
528
|
*/
|
|
696
|
-
callTool: (toolCall: ToolCall, context:
|
|
697
|
-
currentMessage: ChatMessage;
|
|
698
|
-
}) => Promise<string | Record<string, any>> | AsyncGenerator<string | Record<string, any>>;
|
|
529
|
+
callTool: (toolCall: ToolCall, context: UseMessageCallToolContext) => Promise<string | Record<string, any>> | AsyncGenerator<string | Record<string, any>>;
|
|
699
530
|
/**
|
|
700
531
|
* 工具调用开始时的回调函数。
|
|
701
532
|
* 触发时机:工具消息已创建并追加后,调用 callTool 之前触发。
|
|
702
533
|
* @param toolCall - 工具调用对象
|
|
703
534
|
* @param context - 插件上下文,包含当前工具消息
|
|
704
535
|
*/
|
|
705
|
-
onToolCallStart?: (toolCall: ToolCall, context:
|
|
706
|
-
primaryMessage: ChatMessage;
|
|
707
|
-
toolMessage: ChatMessage;
|
|
708
|
-
}) => void;
|
|
536
|
+
onToolCallStart?: (toolCall: ToolCall, context: UseMessageToolCallContext) => void;
|
|
709
537
|
/**
|
|
710
538
|
* 工具调用结束时的回调函数。
|
|
711
539
|
* 触发时机:工具调用完成(成功、失败或取消)时触发。
|
|
@@ -714,9 +542,7 @@ declare const toolPlugin: (options: UseMessagePlugin & {
|
|
|
714
542
|
* @param context.status - 工具调用状态:'success' | 'failed' | 'cancelled'
|
|
715
543
|
* @param context.error - 当状态为 'failed' 或 'cancelled' 时,可能包含错误信息
|
|
716
544
|
*/
|
|
717
|
-
onToolCallEnd?: (toolCall: ToolCall, context:
|
|
718
|
-
primaryMessage: ChatMessage;
|
|
719
|
-
toolMessage: ChatMessage;
|
|
545
|
+
onToolCallEnd?: (toolCall: ToolCall, context: UseMessageToolCallContext & {
|
|
720
546
|
status: "success" | "failed" | "cancelled";
|
|
721
547
|
error?: Error;
|
|
722
548
|
}) => void;
|
|
@@ -729,20 +555,13 @@ declare const toolPlugin: (options: UseMessagePlugin & {
|
|
|
729
555
|
*/
|
|
730
556
|
toolCallFailedContent?: string;
|
|
731
557
|
/**
|
|
732
|
-
*
|
|
558
|
+
* 是否在请求前自动补充缺失的 tool 消息。
|
|
733
559
|
* 当 assistant 响应了 tool_calls 但未追加对应的 tool 消息时,
|
|
734
560
|
* 插件将自动补充"工具调用已取消"的 tool 消息。默认:false。
|
|
735
561
|
*/
|
|
736
562
|
autoFillMissingToolMessages?: boolean;
|
|
737
|
-
/**
|
|
738
|
-
* 是否在下一轮对话中,排除包含 tool_calls 的 assistant 消息和对应的 tool 消息,只保留结果。
|
|
739
|
-
* - 当为 `true` 时,这些消息会被标记为不发送,不会包含在下一次请求的 messages 中。
|
|
740
|
-
* - 当为 `'remove'` 时,这些消息会直接从 messages 数组中移除。
|
|
741
|
-
* 默认:false。
|
|
742
|
-
*/
|
|
743
|
-
excludeToolMessagesNextTurn?: boolean | typeof EXCLUDE_MODE_REMOVE;
|
|
744
563
|
}) => UseMessagePlugin;
|
|
745
564
|
|
|
746
565
|
declare const useMessage: (options: UseMessageOptions) => UseMessageReturn;
|
|
747
566
|
|
|
748
|
-
export {
|
|
567
|
+
export { AIClient, AIModelConfig, BaseModelProvider, type BasePluginContext, type ChatCompletion, ChatCompletionRequest, ChatCompletionResponse, ChatMessage, type Choice, type CompletionChoice, type Conversation, type ConversationInfo, type ConversationStorageStrategy, type DeltaChoice, type IndexedDBConfig, IndexedDBStrategy, type LocalStorageConfig, LocalStorageStrategy, MaybePromise, type MessageRequestBody, OpenAIProvider, type RequestProcessingState, type RequestState, type ResponseProvider, StreamHandler, type Tool, ToolCall, type Usage, type UseConversationOptions, type UseConversationReturn, type UseMessageCallToolContext, type UseMessageOptions, type UseMessagePlugin, type UseMessageReturn, type UseMessageSkillPluginOptions, type UseMessageToolActionContext, type UseMessageToolCallContext, type VueSkillSource, type VueSkillSourceRef, extractTextFromResponse, formatMessages, handleSSEStream, indexedDBStorageStrategyFactory, lengthPlugin, localStorageStrategyFactory, skillPlugin, sseStreamToGenerator, thinkingPlugin, toolPlugin, useConversation, useMessage };
|