@veltra/ai 1.4.0 → 2.1.0
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/chat/index.d.ts +3 -3
- package/dist/chat/transports/index.d.ts +2 -2
- package/dist/chat/transports/openai.d.ts +16 -12
- package/dist/chat/transports/openai.js +56 -15
- package/dist/chat/transports/openai.js.map +1 -1
- package/dist/chat/types.d.ts +41 -2
- package/dist/chat/use-chat.d.ts +26 -1
- package/dist/chat/use-chat.js +132 -13
- package/dist/chat/use-chat.js.map +1 -1
- package/dist/components/ai-chat/ai-chat.js +222 -41
- package/dist/components/ai-chat/ai-chat.js.map +1 -1
- package/dist/components/ai-chat/ask-question.js +2 -2
- package/dist/components/ai-chat/ask-question.js.map +1 -1
- package/dist/components/ai-chat/chat-input.js +81 -44
- package/dist/components/ai-chat/chat-input.js.map +1 -1
- package/dist/components/ai-chat/di.js.map +1 -1
- package/dist/components/ai-chat/message-item.js +101 -23
- package/dist/components/ai-chat/message-item.js.map +1 -1
- package/dist/components/ai-chat/message-list.js +217 -32
- package/dist/components/ai-chat/message-list.js.map +1 -1
- package/dist/components/ai-chat/model-picker.js +140 -0
- package/dist/components/ai-chat/model-picker.js.map +1 -0
- package/dist/components/ai-chat/queue-list.js +70 -0
- package/dist/components/ai-chat/queue-list.js.map +1 -0
- package/dist/components/ai-chat/side-panel.js +96 -0
- package/dist/components/ai-chat/side-panel.js.map +1 -0
- package/dist/components/ai-chat/style.d.ts +6 -0
- package/dist/components/ai-chat/style.js +6 -0
- package/dist/components/ai-chat/style2.css +552 -41
- package/dist/components/ai-chat/tool-call.js +61 -27
- package/dist/components/ai-chat/tool-call.js.map +1 -1
- package/dist/components/ai-orb/ai-orb.js +94 -0
- package/dist/components/ai-orb/ai-orb.js.map +1 -0
- package/dist/components/ai-orb/orb-renderer.js +411 -0
- package/dist/components/ai-orb/orb-renderer.js.map +1 -0
- package/dist/components/ai-orb/style.d.ts +1 -0
- package/dist/components/ai-orb/style.js +1 -0
- package/dist/components/ai-orb/style2.css +23 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.js +2 -2
- package/dist/providers/types.d.ts +47 -0
- package/dist/style.js +1 -0
- package/dist/tools/ask-question/ask-question.d.ts +2 -17
- package/dist/tools/ask-question/index.d.ts +2 -2
- package/dist/tools/index.d.ts +3 -2
- package/dist/tools/index.js +10 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types/ai-chat.d.ts +35 -7
- package/dist/types/ai-orb.d.ts +27 -0
- package/dist/types/index.d.ts +2 -1
- package/package.json +8 -8
- package/src/chat/__test__/use-chat.test.ts +295 -9
- package/src/chat/transports/__test__/openai.test.ts +317 -0
- package/src/chat/transports/openai.ts +88 -26
- package/src/chat/types.ts +41 -1
- package/src/chat/use-chat.ts +177 -14
- package/src/components/ai-chat/__test__/ai-chat.test.ts +690 -12
- package/src/components/ai-chat/ai-chat.vue +241 -31
- package/src/components/ai-chat/chat-input.vue +78 -31
- package/src/components/ai-chat/di.ts +2 -0
- package/src/components/ai-chat/message-item.vue +98 -11
- package/src/components/ai-chat/message-list.vue +261 -21
- package/src/components/ai-chat/model-picker.vue +177 -0
- package/src/components/ai-chat/queue-list.vue +63 -0
- package/src/components/ai-chat/side-panel.vue +76 -0
- package/src/components/ai-chat/style.scss +621 -43
- package/src/components/ai-chat/style.ts +6 -0
- package/src/components/ai-chat/tool-call.vue +86 -42
- package/src/components/ai-orb/__test__/ai-orb.test.ts +251 -0
- package/src/components/ai-orb/ai-orb.vue +107 -0
- package/src/components/ai-orb/index.ts +1 -0
- package/src/components/ai-orb/orb-renderer.ts +505 -0
- package/src/components/ai-orb/style.scss +10 -0
- package/src/components/ai-orb/style.ts +1 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +8 -1
- package/src/providers/index.ts +1 -0
- package/src/providers/types.ts +46 -0
- package/src/style.ts +1 -0
- package/src/tools/ask-question/__test__/ask-question.test.ts +4 -4
- package/src/tools/index.ts +14 -1
- package/src/types/ai-chat.ts +35 -6
- package/src/types/ai-orb.ts +27 -0
- package/src/types/index.ts +1 -0
- package/dist/components/ai-chat/ai-chat.vue.d.ts +0 -36
- package/dist/components/ai-chat/index.d.ts +0 -2
- package/dist/components/index.d.ts +0 -3
package/src/types/ai-chat.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { DeconstructValue } from '@veltra/utils'
|
|
2
|
+
import type { Ref } from 'vue'
|
|
2
3
|
|
|
3
4
|
import type {
|
|
4
5
|
ChatAttachment,
|
|
5
6
|
ChatMessage,
|
|
7
|
+
ChatQueuedMessage,
|
|
6
8
|
ChatTool,
|
|
7
9
|
ChatToolCall,
|
|
8
10
|
ChatTransport
|
|
9
11
|
} from '../chat/types'
|
|
12
|
+
import type { ChatModelOption } from '../providers'
|
|
10
13
|
|
|
11
14
|
export interface AiChatProps {
|
|
12
15
|
/** 传输层(必填),可使用导出的 createOpenAITransport() 创建 */
|
|
@@ -15,10 +18,24 @@ export interface AiChatProps {
|
|
|
15
18
|
tools?: ChatTool[]
|
|
16
19
|
/** 系统提示词 */
|
|
17
20
|
systemPrompt?: string
|
|
21
|
+
/**
|
|
22
|
+
* 单次发送允许的最大生成轮次(一轮 = 一次模型生成 + 可能的工具执行),默认 10。
|
|
23
|
+
* 模型持续调用工具不收敛时,达到上限即停止继续请求并发出 finish,防止失控循环。
|
|
24
|
+
*/
|
|
25
|
+
maxToolRounds?: number
|
|
18
26
|
/** 消息列表,支持 v-model:messages 受控 */
|
|
19
27
|
messages?: ChatMessage[]
|
|
20
|
-
/**
|
|
21
|
-
|
|
28
|
+
/**
|
|
29
|
+
* 可选模型列表;有值则在输入栏展示模型选择器。
|
|
30
|
+
* 可从 createOpenAITransport() 返回值的 `.models` 直接传入。
|
|
31
|
+
*/
|
|
32
|
+
models?: ChatModelOption[]
|
|
33
|
+
/** 当前模型 id,支持 v-model:model */
|
|
34
|
+
model?: string
|
|
35
|
+
/** 当前推理等级,支持 v-model:reasoning-level */
|
|
36
|
+
reasoningLevel?: string
|
|
37
|
+
/** 空状态欢迎项(快捷提问,点击即发送);字符串按单项处理 */
|
|
38
|
+
welcome?: string | string[]
|
|
22
39
|
/** 输入框占位文本 */
|
|
23
40
|
placeholder?: string
|
|
24
41
|
/** 附件 accept 类型,默认 image/* */
|
|
@@ -32,9 +49,13 @@ export interface AiChatProps {
|
|
|
32
49
|
export interface AiChatEmits {
|
|
33
50
|
/** 消息列表变化 */
|
|
34
51
|
(e: 'update:messages', messages: ChatMessage[]): void
|
|
52
|
+
/** 当前模型变化 */
|
|
53
|
+
(e: 'update:model', model: string | undefined): void
|
|
54
|
+
/** 当前推理等级变化 */
|
|
55
|
+
(e: 'update:reasoningLevel', reasoningLevel: string | undefined): void
|
|
35
56
|
/** 用户发送消息 */
|
|
36
57
|
(e: 'send', message: ChatMessage): void
|
|
37
|
-
/**
|
|
58
|
+
/** 一轮对话完成(无更多工具调用、命中 terminal 工具或达到 maxToolRounds 上限) */
|
|
38
59
|
(e: 'finish', message: ChatMessage): void
|
|
39
60
|
/** 对话出错 */
|
|
40
61
|
(e: 'error', error: Error): void
|
|
@@ -43,14 +64,22 @@ export interface AiChatEmits {
|
|
|
43
64
|
}
|
|
44
65
|
|
|
45
66
|
export interface _AiChatExposed {
|
|
46
|
-
/**
|
|
67
|
+
/** 发送一条用户消息(会话进行中时进入待发送队列) */
|
|
47
68
|
send: (content: string, attachments?: ChatAttachment[]) => void
|
|
48
|
-
/**
|
|
69
|
+
/** 中断当前生成(保留待发送队列) */
|
|
49
70
|
abort: () => void
|
|
50
71
|
/** 重新生成最后一条 assistant 回复 */
|
|
51
72
|
regenerate: () => void
|
|
52
|
-
/**
|
|
73
|
+
/** 清空消息与待发送队列 */
|
|
53
74
|
clear: () => void
|
|
75
|
+
/** 待发送消息队列(会话进行中提交的消息按序排队,收尾后 FIFO 自动接续) */
|
|
76
|
+
queue: Ref<ChatQueuedMessage[]>
|
|
77
|
+
/** 立即执行队列中的某条:中断当前会话并插队为下一条 */
|
|
78
|
+
startQueued: (id: string) => void
|
|
79
|
+
/** 从队列移除某条(返回被移除项) */
|
|
80
|
+
removeQueued: (id: string) => ChatQueuedMessage | undefined
|
|
81
|
+
/** 向队列插入一条消息(beforeId 插到某条之前,缺省追加尾部;空闲时自动消耗队首) */
|
|
82
|
+
enqueue: (content: string, attachments?: ChatAttachment[], beforeId?: string) => ChatQueuedMessage
|
|
54
83
|
}
|
|
55
84
|
|
|
56
85
|
export type AiChatExposed = DeconstructValue<_AiChatExposed>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** 活体球生命状态:驱动常态动画(平静 / 思考 / 输出) */
|
|
2
|
+
export type AiOrbStatus = 'idle' | 'thinking' | 'speaking'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 瞬时表情:播放约 1-2s 后自动回到 status 驱动的常态。
|
|
6
|
+
* - happy:成功 / 回答完毕 —— 先睁大眼睛,再弯眼大笑 + 点头
|
|
7
|
+
* - shock:惊讶 —— 睁大眼睛 + 小嘴微张 + 轻微后仰
|
|
8
|
+
* - frustrated:受挫(如工具调用失败)—— 闭紧眼睛 + 摇头 + 嘴角下撇
|
|
9
|
+
*/
|
|
10
|
+
export type AiOrbReaction = 'happy' | 'shock' | 'frustrated'
|
|
11
|
+
|
|
12
|
+
export interface AiOrbProps {
|
|
13
|
+
/** 球体直径(px),默认 48 */
|
|
14
|
+
size?: number
|
|
15
|
+
/** 生命状态,默认 idle */
|
|
16
|
+
status?: AiOrbStatus
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AiOrbEmits {
|
|
20
|
+
/** 点击球体(球体同时会做 Q 弹反馈) */
|
|
21
|
+
(e: 'click'): void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AiOrbExposed {
|
|
25
|
+
/** 播放一次瞬时表情(对应阶段性事件,如回答完毕 / 工具调用失败) */
|
|
26
|
+
react: (reaction: AiOrbReaction) => void
|
|
27
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ChatMessage, ChatToolCall } from "../../chat/types.js";
|
|
2
|
-
import { AiChatProps, _AiChatExposed } from "../../types/ai-chat.js";
|
|
3
|
-
import "../../types/index.js";
|
|
4
|
-
import "../../index.js";
|
|
5
|
-
//#region src/components/ai-chat/ai-chat.vue.d.ts
|
|
6
|
-
type __VLS_Slots = {
|
|
7
|
-
/** 空状态欢迎区插槽 */
|
|
8
|
-
welcome(): any;
|
|
9
|
-
/** 按工具名自定义工具结果展示,如 tool-getWeather */
|
|
10
|
-
[name: `tool-${string}`]: (scope: {
|
|
11
|
-
toolCall: ChatToolCall;
|
|
12
|
-
}) => any;
|
|
13
|
-
};
|
|
14
|
-
declare const __VLS_base: import("vue").DefineComponent<AiChatProps, _AiChatExposed, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
15
|
-
"update:messages": (messages: ChatMessage[]) => any;
|
|
16
|
-
send: (message: ChatMessage) => any;
|
|
17
|
-
finish: (message: ChatMessage) => any;
|
|
18
|
-
error: (error: Error) => any;
|
|
19
|
-
"tool-call": (toolCall: ChatToolCall) => any;
|
|
20
|
-
}, string, import("vue").PublicProps, Readonly<AiChatProps> & Readonly<{
|
|
21
|
-
"onUpdate:messages"?: ((messages: ChatMessage[]) => any) | undefined;
|
|
22
|
-
onSend?: ((message: ChatMessage) => any) | undefined;
|
|
23
|
-
onFinish?: ((message: ChatMessage) => any) | undefined;
|
|
24
|
-
onError?: ((error: Error) => any) | undefined;
|
|
25
|
-
"onTool-call"?: ((toolCall: ChatToolCall) => any) | undefined;
|
|
26
|
-
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
27
|
-
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
28
|
-
declare const _default: typeof __VLS_export;
|
|
29
|
-
type __VLS_WithSlots<T, S> = T & {
|
|
30
|
-
new (): {
|
|
31
|
-
$slots: S;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
//#endregion
|
|
35
|
-
export { _default as default };
|
|
36
|
-
//# sourceMappingURL=ai-chat.vue.d.ts.map
|