@veltra/ai 2.0.0 → 2.1.1
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 +2 -2
- package/dist/chat/transports/openai.js +1 -1
- package/dist/chat/transports/openai.js.map +1 -1
- package/dist/chat/types.d.ts +37 -2
- package/dist/chat/use-chat.d.ts +23 -1
- package/dist/chat/use-chat.js +91 -10
- package/dist/chat/use-chat.js.map +1 -1
- package/dist/components/ai-chat/ai-chat.js +207 -46
- package/dist/components/ai-chat/ai-chat.js.map +1 -1
- package/dist/components/ai-chat/chat-input.js +37 -12
- 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 +69 -46
- package/dist/components/ai-chat/model-picker.js.map +1 -1
- 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 +4 -0
- package/dist/components/ai-chat/style.js +4 -0
- package/dist/components/ai-chat/style2.css +457 -74
- package/dist/components/ai-chat/tool-call.js +60 -26
- 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 +4 -2
- package/dist/index.js +2 -1
- package/dist/style.js +1 -0
- package/dist/types/ai-chat.d.ts +21 -7
- package/dist/types/ai-orb.d.ts +27 -0
- package/dist/types/index.d.ts +2 -1
- package/package.json +5 -5
- package/src/chat/__test__/use-chat.test.ts +266 -13
- package/src/chat/transports/__test__/openai.test.ts +78 -0
- package/src/chat/transports/openai.ts +2 -2
- package/src/chat/types.ts +37 -1
- package/src/chat/use-chat.ts +120 -11
- package/src/components/ai-chat/__test__/ai-chat.test.ts +628 -12
- package/src/components/ai-chat/ai-chat.vue +227 -31
- package/src/components/ai-chat/chat-input.vue +41 -11
- 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 +110 -59
- 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 +527 -74
- package/src/components/ai-chat/style.ts +4 -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/style.ts +1 -0
- package/src/tools/ask-question/__test__/ask-question.test.ts +1 -1
- package/src/types/ai-chat.ts +21 -6
- package/src/types/ai-orb.ts +27 -0
- package/src/types/index.ts +1 -0
|
@@ -1,37 +1,99 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
<div :class="cls.e('list-wrap')">
|
|
3
|
+
<UScroll
|
|
4
|
+
:class="cls.e('list')"
|
|
5
|
+
ref="scrollRef"
|
|
6
|
+
always
|
|
7
|
+
@scroll="handleScroll"
|
|
8
|
+
@wheel.passive="handleWheel"
|
|
9
|
+
>
|
|
10
|
+
<div v-if="!visibleMessages.length" :class="cls.e('welcome')">
|
|
11
|
+
<slot name="welcome">
|
|
12
|
+
<div :class="cls.e('welcome-inner')">
|
|
13
|
+
<UAiOrb :size="WELCOME_ORB_SIZE" @click="cycleWelcome" />
|
|
14
|
+
<!-- 快捷提问逐条展示在球右侧并自动轮换:点文案发送,点球立即换下一条。
|
|
15
|
+
固定锚点布局:球位置钉死不动,气泡只向右延展,避免轮换时水平瞬移 -->
|
|
16
|
+
<div v-if="welcomeItems.length" :class="cls.e('welcome-item-wrap')">
|
|
17
|
+
<Transition :name="cls.em('welcome', 'swap')" mode="out-in">
|
|
18
|
+
<button
|
|
19
|
+
v-if="currentWelcomeItem"
|
|
20
|
+
:key="welcomeIndex"
|
|
21
|
+
type="button"
|
|
22
|
+
:class="cls.e('welcome-item')"
|
|
23
|
+
@click="emit('welcome-click', currentWelcomeItem)"
|
|
24
|
+
>
|
|
25
|
+
{{ currentWelcomeItem }}
|
|
26
|
+
</button>
|
|
27
|
+
</Transition>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
</slot>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<MessageItem
|
|
34
|
+
v-for="(msg, index) in visibleMessages"
|
|
35
|
+
:key="msg.id"
|
|
36
|
+
:message="msg"
|
|
37
|
+
:is-last="index === visibleMessages.length - 1"
|
|
38
|
+
:renderer-props="rendererProps"
|
|
39
|
+
@respond="(id, approved) => emit('respond', id, approved)"
|
|
40
|
+
@regenerate="emit('regenerate')"
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
<!-- 工作状态统一指示:生成中在列表末尾展示活体球 + 文案;结束 / 失败停留片刻再隐藏 -->
|
|
44
|
+
<div v-if="running || finishing" :class="cls.e('working')">
|
|
45
|
+
<UAiOrb ref="workingOrb" :size="WORKING_ORB_SIZE" :status="workingOrbStatus" />
|
|
46
|
+
<span v-if="running" :class="[cls.e('working-text'), 'u-shine']">工作中…</span>
|
|
47
|
+
</div>
|
|
48
|
+
</UScroll>
|
|
49
|
+
|
|
50
|
+
<!-- 用户上翻浏览时悬浮入口:一键回到最新消息 -->
|
|
51
|
+
<Transition :name="cls.em('to-latest', 'fade')">
|
|
52
|
+
<button v-if="showToLatest" type="button" :class="cls.e('to-latest')" @click="scrollToLatest">
|
|
53
|
+
<UIcon><ArrowDown /></UIcon>
|
|
54
|
+
<span>最新消息</span>
|
|
55
|
+
</button>
|
|
56
|
+
</Transition>
|
|
57
|
+
</div>
|
|
17
58
|
</template>
|
|
18
59
|
|
|
19
60
|
<script lang="ts" setup>
|
|
20
|
-
import { UScroll } from '@veltra/desktop'
|
|
61
|
+
import { UIcon, UScroll } from '@veltra/desktop'
|
|
21
62
|
import type { ScrollPosition } from '@veltra/desktop'
|
|
63
|
+
import { ArrowDown } from '@veltra/icons/normal'
|
|
22
64
|
import { bem } from '@veltra/utils'
|
|
23
|
-
import {
|
|
65
|
+
import {
|
|
66
|
+
computed,
|
|
67
|
+
inject,
|
|
68
|
+
nextTick,
|
|
69
|
+
onBeforeUnmount,
|
|
70
|
+
ref,
|
|
71
|
+
shallowRef,
|
|
72
|
+
useTemplateRef,
|
|
73
|
+
watch
|
|
74
|
+
} from 'vue'
|
|
24
75
|
|
|
25
76
|
import type { ChatMessage } from '../../chat/types'
|
|
77
|
+
import type { AiOrbExposed, AiOrbReaction, AiOrbStatus } from '../../types/ai-orb'
|
|
78
|
+
import UAiOrb from '../ai-orb/ai-orb.vue'
|
|
26
79
|
import { AiChatDIKey } from './di'
|
|
27
80
|
import MessageItem from './message-item.vue'
|
|
28
81
|
|
|
29
82
|
defineOptions({ name: 'UAiChatMessageList' })
|
|
30
83
|
|
|
84
|
+
/** 欢迎区活体球直径(px) */
|
|
85
|
+
const WELCOME_ORB_SIZE = 64
|
|
86
|
+
/** 工作指示活体球直径(px) */
|
|
87
|
+
const WORKING_ORB_SIZE = 48
|
|
88
|
+
/** 生成结束 / 失败后工作球停留再隐藏 */
|
|
89
|
+
const WORKING_LINGER_MS = 2500
|
|
90
|
+
|
|
31
91
|
const props = defineProps<{
|
|
32
92
|
messages: ChatMessage[]
|
|
33
|
-
/**
|
|
34
|
-
welcome?: string
|
|
93
|
+
/** 空状态欢迎项;字符串按单项处理 */
|
|
94
|
+
welcome?: string | string[]
|
|
95
|
+
/** 是否生成中(控制底部工作状态指示) */
|
|
96
|
+
running?: boolean
|
|
35
97
|
/** 透传给 MarkdownRender 的属性 */
|
|
36
98
|
rendererProps?: Record<string, unknown>
|
|
37
99
|
}>()
|
|
@@ -39,6 +101,8 @@ const props = defineProps<{
|
|
|
39
101
|
const emit = defineEmits<{
|
|
40
102
|
(e: 'respond', toolCallId: string, approved: boolean): void
|
|
41
103
|
(e: 'regenerate'): void
|
|
104
|
+
/** 点击欢迎项(快捷提问) */
|
|
105
|
+
(e: 'welcome-click', text: string): void
|
|
42
106
|
}>()
|
|
43
107
|
|
|
44
108
|
defineSlots<{
|
|
@@ -52,12 +116,161 @@ const cls = di?.cls ?? bem('ai-chat')
|
|
|
52
116
|
/** tool 消息不单独渲染,其内容体现在工具卡片的结果区 */
|
|
53
117
|
const visibleMessages = computed(() => props.messages.filter((msg) => msg.role !== 'tool'))
|
|
54
118
|
|
|
119
|
+
const welcomeItems = computed(() => {
|
|
120
|
+
const welcome = props.welcome
|
|
121
|
+
if (!welcome) return []
|
|
122
|
+
return (Array.isArray(welcome) ? welcome : [welcome]).filter(Boolean)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
/** 欢迎语逐条轮换:当前展示项的下标 */
|
|
126
|
+
const welcomeIndex = ref(0)
|
|
127
|
+
|
|
128
|
+
/** 当前展示的欢迎语 */
|
|
129
|
+
const currentWelcomeItem = computed(() => {
|
|
130
|
+
const items = welcomeItems.value
|
|
131
|
+
return items.length ? items[welcomeIndex.value % items.length] : undefined
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
let welcomeTimer: ReturnType<typeof setInterval> | undefined
|
|
135
|
+
|
|
136
|
+
const stopWelcomeRotation = () => {
|
|
137
|
+
clearInterval(welcomeTimer)
|
|
138
|
+
welcomeTimer = undefined
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const startWelcomeRotation = () => {
|
|
142
|
+
stopWelcomeRotation()
|
|
143
|
+
if (welcomeItems.value.length > 1) {
|
|
144
|
+
welcomeTimer = setInterval(() => {
|
|
145
|
+
welcomeIndex.value += 1
|
|
146
|
+
}, 4000)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** 点击欢迎球:不等自动轮换,立即换下一条,并重置计时 */
|
|
151
|
+
const cycleWelcome = () => {
|
|
152
|
+
if (welcomeItems.value.length <= 1) return
|
|
153
|
+
welcomeIndex.value += 1
|
|
154
|
+
startWelcomeRotation()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 欢迎区展示期间自动轮换;出现消息后停止
|
|
158
|
+
watch(
|
|
159
|
+
() => [welcomeItems.value.length, visibleMessages.value.length] as const,
|
|
160
|
+
() => {
|
|
161
|
+
if (visibleMessages.value.length > 0) stopWelcomeRotation()
|
|
162
|
+
else startWelcomeRotation()
|
|
163
|
+
},
|
|
164
|
+
{ immediate: true }
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
onBeforeUnmount(stopWelcomeRotation)
|
|
168
|
+
|
|
169
|
+
const workingOrbRef = useTemplateRef<AiOrbExposed>('workingOrb')
|
|
170
|
+
|
|
171
|
+
/** 工具调用失败的 id 去重集合:同一次失败只播一次沮丧表情 */
|
|
172
|
+
const reactedToolErrorIds = new Set<string>()
|
|
173
|
+
|
|
174
|
+
const toolErrorIds = computed(() => {
|
|
175
|
+
const ids: string[] = []
|
|
176
|
+
for (const msg of props.messages) {
|
|
177
|
+
if (msg.role !== 'assistant' || !msg.toolCalls) continue
|
|
178
|
+
for (const call of msg.toolCalls) {
|
|
179
|
+
if (call.status === 'error') ids.push(call.id)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return ids
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
// 工具调用失败 → 工作球闭眼摇头(frustrated)
|
|
186
|
+
watch(toolErrorIds, (ids) => {
|
|
187
|
+
for (const id of ids) {
|
|
188
|
+
if (reactedToolErrorIds.has(id)) continue
|
|
189
|
+
reactedToolErrorIds.add(id)
|
|
190
|
+
workingOrbRef.value?.react('frustrated')
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
/** 回答完毕 / 失败后工作球短暂停留,播完表情再隐藏 */
|
|
195
|
+
const finishing = ref(false)
|
|
196
|
+
let finishTimer: ReturnType<typeof setTimeout> | undefined
|
|
197
|
+
|
|
198
|
+
const clearFinishing = () => {
|
|
199
|
+
clearTimeout(finishTimer)
|
|
200
|
+
finishing.value = false
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** 工作球状态:收尾停留 → idle;正文输出中 → speaking;其余生成阶段 → thinking */
|
|
204
|
+
const workingOrbStatus = computed<AiOrbStatus>(() => {
|
|
205
|
+
if (finishing.value) return 'idle'
|
|
206
|
+
const last = visibleMessages.value[visibleMessages.value.length - 1]
|
|
207
|
+
if (last?.role === 'assistant' && last.status === 'streaming' && last.content) {
|
|
208
|
+
return 'speaking'
|
|
209
|
+
}
|
|
210
|
+
return 'thinking'
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
watch(
|
|
214
|
+
() => props.running,
|
|
215
|
+
(running, prev) => {
|
|
216
|
+
if (running) {
|
|
217
|
+
// 新一轮生成开始:立即结束收尾停留
|
|
218
|
+
clearFinishing()
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
if (!prev) return
|
|
222
|
+
|
|
223
|
+
finishing.value = true
|
|
224
|
+
const last = visibleMessages.value[visibleMessages.value.length - 1]
|
|
225
|
+
let reaction: AiOrbReaction | undefined
|
|
226
|
+
if (last?.role === 'assistant') {
|
|
227
|
+
if (last.status === 'done') reaction = 'happy'
|
|
228
|
+
else if (last.status === 'error') reaction = 'frustrated'
|
|
229
|
+
}
|
|
230
|
+
if (reaction) {
|
|
231
|
+
nextTick(() => workingOrbRef.value?.react(reaction))
|
|
232
|
+
}
|
|
233
|
+
finishTimer = setTimeout(clearFinishing, WORKING_LINGER_MS)
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
onBeforeUnmount(clearFinishing)
|
|
238
|
+
|
|
55
239
|
const scrollRef = shallowRef<{ scrollTo: (position: ScrollPosition) => void }>()
|
|
56
240
|
/** 是否吸附底部(用户上翻浏览历史时取消吸附) */
|
|
57
241
|
const stickToBottom = ref(true)
|
|
242
|
+
/** 上一次滚动位置:用于区分用户上翻与自动吸底触发的 scroll 事件 */
|
|
243
|
+
let lastScrollY = 0
|
|
244
|
+
|
|
245
|
+
/** 上翻阅读时展示「最新消息」悬浮按钮 */
|
|
246
|
+
const showToLatest = computed(() => !stickToBottom.value && visibleMessages.value.length > 0)
|
|
58
247
|
|
|
59
248
|
const handleScroll = (position: Required<ScrollPosition>) => {
|
|
60
|
-
|
|
249
|
+
const atBottom = position.sh - position.ch - position.y < 60
|
|
250
|
+
if (atBottom) {
|
|
251
|
+
stickToBottom.value = true
|
|
252
|
+
} else if (position.y < lastScrollY) {
|
|
253
|
+
// 只有「向上滚」才算用户离开底部的意图:自动吸底的 scroll 事件可能滞后于
|
|
254
|
+
// 流式内容增长(sh 已变大、y 仍是旧底部),按位置判断会误判成未吸底
|
|
255
|
+
stickToBottom.value = false
|
|
256
|
+
}
|
|
257
|
+
lastScrollY = position.y
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* 用户向上滚动轮 = 明确的离开底部意图,立即取消吸附。
|
|
262
|
+
* 不能等 scroll 事件再按方向判断:流式期间每个 chunk 都会排一次吸底滚动,
|
|
263
|
+
* 滞后的 scrollTo 会把用户拉回底部并触发 atBottom 重新吸附,导致「上滚动不了」
|
|
264
|
+
*/
|
|
265
|
+
const handleWheel = (e: WheelEvent) => {
|
|
266
|
+
if (e.deltaY < 0) stickToBottom.value = false
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** 点击悬浮按钮:恢复吸附并回到底部 */
|
|
270
|
+
const scrollToLatest = async () => {
|
|
271
|
+
stickToBottom.value = true
|
|
272
|
+
await nextTick()
|
|
273
|
+
scrollRef.value?.scrollTo({ y: Number.MAX_SAFE_INTEGER })
|
|
61
274
|
}
|
|
62
275
|
|
|
63
276
|
// 消息数量或流式内容变化时,若处于吸附状态则滚动到底部
|
|
@@ -69,13 +282,40 @@ watch(
|
|
|
69
282
|
list.length,
|
|
70
283
|
last?.content.length ?? 0,
|
|
71
284
|
last?.reasoning?.length ?? 0,
|
|
72
|
-
last?.toolCalls?.length ?? 0
|
|
285
|
+
last?.toolCalls?.length ?? 0,
|
|
286
|
+
props.running
|
|
73
287
|
].join('|')
|
|
74
288
|
},
|
|
75
289
|
async () => {
|
|
290
|
+
// 用户刚发出消息时强制回到底部(无论之前是否在上翻)
|
|
291
|
+
const list = visibleMessages.value
|
|
292
|
+
if (list[list.length - 1]?.role === 'user') stickToBottom.value = true
|
|
293
|
+
if (!stickToBottom.value) return
|
|
294
|
+
await nextTick()
|
|
295
|
+
// 等待 DOM 更新期间用户可能已上滚,滚动前重新确认吸附状态,避免把用户拉回底部
|
|
296
|
+
if (!stickToBottom.value) return
|
|
297
|
+
scrollRef.value?.scrollTo({ y: Number.MAX_SAFE_INTEGER })
|
|
298
|
+
}
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
let trailingScrollTimer: ReturnType<typeof setTimeout> | undefined
|
|
302
|
+
|
|
303
|
+
// 生成收尾时动作区出现 / markdown 终态渲染 / 思考块折叠会再次改变高度,
|
|
304
|
+
// 同帧滚动可能够不到最终底部,追加一次延迟兜底滚动
|
|
305
|
+
watch(
|
|
306
|
+
() => props.running,
|
|
307
|
+
async (running) => {
|
|
308
|
+
if (running) return
|
|
309
|
+
clearTimeout(trailingScrollTimer)
|
|
76
310
|
if (!stickToBottom.value) return
|
|
77
311
|
await nextTick()
|
|
312
|
+
if (!stickToBottom.value) return
|
|
78
313
|
scrollRef.value?.scrollTo({ y: Number.MAX_SAFE_INTEGER })
|
|
314
|
+
trailingScrollTimer = setTimeout(() => {
|
|
315
|
+
if (stickToBottom.value) scrollRef.value?.scrollTo({ y: Number.MAX_SAFE_INTEGER })
|
|
316
|
+
}, 150)
|
|
79
317
|
}
|
|
80
318
|
)
|
|
319
|
+
|
|
320
|
+
onBeforeUnmount(() => clearTimeout(trailingScrollTimer))
|
|
81
321
|
</script>
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
<UDropdown
|
|
3
3
|
ref="dropdownRef"
|
|
4
4
|
trigger="click"
|
|
5
|
+
width="auto"
|
|
5
6
|
min-width="220px"
|
|
6
7
|
:content-class="cls.e('model-panel')"
|
|
8
|
+
@update:visible="handleVisibleChange"
|
|
7
9
|
>
|
|
8
10
|
<template #trigger>
|
|
9
11
|
<button type="button" :class="cls.e('model-trigger')">
|
|
@@ -20,60 +22,81 @@
|
|
|
20
22
|
</template>
|
|
21
23
|
|
|
22
24
|
<template #content>
|
|
23
|
-
<div
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
25
|
+
<div :class="cls.e('model-panel-list')">
|
|
26
|
+
<div
|
|
27
|
+
v-for="item in models"
|
|
28
|
+
:key="item.id"
|
|
29
|
+
:class="[cls.e('model-option'), bem.is('active', item.id === model)]"
|
|
30
|
+
>
|
|
31
|
+
<div :class="cls.e('model-option-main')" @click="handleSelectModel(item)">
|
|
32
|
+
<div :class="cls.e('model-option-head')">
|
|
33
|
+
<span :class="cls.e('model-option-name')">{{ item.label ?? item.id }}</span>
|
|
34
|
+
<span :class="cls.e('model-option-actions')">
|
|
35
|
+
<button
|
|
36
|
+
v-if="item.reasoningLevels?.length"
|
|
37
|
+
type="button"
|
|
38
|
+
:class="[
|
|
39
|
+
cls.e('model-option-reasoning'),
|
|
40
|
+
bem.is('expanded', expandedReasoningId === item.id)
|
|
41
|
+
]"
|
|
42
|
+
@click.stop="toggleReasoning(item)"
|
|
43
|
+
>
|
|
44
|
+
<span>{{ getReasoningLabel(item) }}</span>
|
|
45
|
+
<UIcon :class="cls.e('model-option-reasoning-arrow')">
|
|
46
|
+
<ArrowDown />
|
|
47
|
+
</UIcon>
|
|
48
|
+
</button>
|
|
49
|
+
<!-- 勾选槽位固定占位:未选中也保留位置,保证推理等级按钮跨行对齐 -->
|
|
50
|
+
<UIcon :class="[cls.e('model-option-check'), bem.is('hidden', item.id !== model)]">
|
|
51
|
+
<Check />
|
|
52
|
+
</UIcon>
|
|
53
|
+
</span>
|
|
54
|
+
</div>
|
|
55
|
+
<div v-if="item.description" :class="cls.e('model-option-desc')">
|
|
56
|
+
{{ item.description }}
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
53
59
|
|
|
54
|
-
<template v-if="reasoningExpanded">
|
|
55
60
|
<div
|
|
56
|
-
v-
|
|
57
|
-
:
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
v-if="item.reasoningLevels?.length"
|
|
62
|
+
:class="[
|
|
63
|
+
cls.e('reasoning-levels'),
|
|
64
|
+
bem.is('expanded', expandedReasoningId === item.id)
|
|
65
|
+
]"
|
|
60
66
|
>
|
|
61
|
-
<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
<div :class="cls.e('reasoning-levels-inner')">
|
|
68
|
+
<div
|
|
69
|
+
v-for="level in item.reasoningLevels"
|
|
70
|
+
:key="level.value"
|
|
71
|
+
:class="[
|
|
72
|
+
cls.e('reasoning-option'),
|
|
73
|
+
bem.is('active', isReasoningActive(item, level.value))
|
|
74
|
+
]"
|
|
75
|
+
@click="handleSelectReasoning(item, level.value)"
|
|
76
|
+
>
|
|
77
|
+
<span>{{ level.label }}</span>
|
|
78
|
+
<UIcon
|
|
79
|
+
:class="[
|
|
80
|
+
cls.e('model-option-check'),
|
|
81
|
+
bem.is('hidden', !isReasoningActive(item, level.value))
|
|
82
|
+
]"
|
|
83
|
+
>
|
|
84
|
+
<Check />
|
|
85
|
+
</UIcon>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
65
88
|
</div>
|
|
66
|
-
</
|
|
67
|
-
</
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
68
91
|
</template>
|
|
69
92
|
</UDropdown>
|
|
70
93
|
</template>
|
|
71
94
|
|
|
72
95
|
<script lang="ts" setup>
|
|
73
96
|
import { UDropdown, UIcon } from '@veltra/desktop'
|
|
74
|
-
import { ArrowDown,
|
|
97
|
+
import { ArrowDown, Check } from '@veltra/icons/normal'
|
|
75
98
|
import { bem } from '@veltra/utils'
|
|
76
|
-
import { computed, inject, nextTick,
|
|
99
|
+
import { computed, inject, nextTick, shallowRef, useTemplateRef } from 'vue'
|
|
77
100
|
|
|
78
101
|
import type { ChatModelOption } from '../../providers'
|
|
79
102
|
import { AiChatDIKey } from './di'
|
|
@@ -85,41 +108,69 @@ const props = defineProps<{
|
|
|
85
108
|
models: ChatModelOption[]
|
|
86
109
|
}>()
|
|
87
110
|
|
|
88
|
-
const model = defineModel<string>('model')
|
|
89
|
-
const reasoningLevel = defineModel<string>('reasoningLevel')
|
|
111
|
+
const model = defineModel<string | undefined>('model')
|
|
112
|
+
const reasoningLevel = defineModel<string | undefined>('reasoningLevel')
|
|
90
113
|
|
|
91
114
|
const di = inject(AiChatDIKey)
|
|
92
115
|
const cls = di?.cls ?? bem('ai-chat')
|
|
93
116
|
|
|
94
117
|
const dropdownRef = useTemplateRef('dropdownRef')
|
|
95
118
|
|
|
96
|
-
/**
|
|
97
|
-
const
|
|
119
|
+
/** 当前内联展开思考强度的模型 id(手风琴,同时只展开一个) */
|
|
120
|
+
const expandedReasoningId = shallowRef<string>()
|
|
98
121
|
|
|
99
122
|
const currentModel = computed(() => {
|
|
100
123
|
return props.models.find((m) => m.id === model.value)
|
|
101
124
|
})
|
|
102
125
|
|
|
103
|
-
const reasoningLevels = computed(() => currentModel.value?.reasoningLevels ?? [])
|
|
104
|
-
|
|
105
126
|
const currentReasoningLabel = computed(() => {
|
|
106
|
-
return
|
|
127
|
+
return currentModel.value?.reasoningLevels?.find((level) => level.value === reasoningLevel.value)
|
|
128
|
+
?.label
|
|
107
129
|
})
|
|
108
130
|
|
|
109
|
-
/**
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
131
|
+
/** 取模型默认推理等级:显式配置优先,缺省落到首个可选等级 */
|
|
132
|
+
const resolveDefaultReasoningLevel = (item: ChatModelOption) => {
|
|
133
|
+
const levels = item.reasoningLevels ?? []
|
|
134
|
+
if (!levels.length) return undefined
|
|
135
|
+
return (
|
|
136
|
+
levels.find((level) => level.value === item.defaultReasoningLevel)?.value ?? levels[0]?.value
|
|
137
|
+
)
|
|
113
138
|
}
|
|
114
139
|
|
|
115
|
-
/**
|
|
116
|
-
const
|
|
117
|
-
model.value
|
|
118
|
-
|
|
140
|
+
/** 胶囊文案:已选中模型展示当前推理等级,其余展示该模型的默认等级 */
|
|
141
|
+
const getReasoningLabel = (item: ChatModelOption) => {
|
|
142
|
+
if (item.id === model.value && currentReasoningLabel.value) {
|
|
143
|
+
return currentReasoningLabel.value
|
|
144
|
+
}
|
|
145
|
+
return item.reasoningLevels?.find((level) => level.value === resolveDefaultReasoningLevel(item))
|
|
146
|
+
?.label
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const isReasoningActive = (item: ChatModelOption, value: string) => {
|
|
150
|
+
return item.id === model.value && reasoningLevel.value === value
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 关闭时收起内联思考强度,下次打开仍从模型列表开始 */
|
|
154
|
+
const handleVisibleChange = (visible: boolean) => {
|
|
155
|
+
if (!visible) expandedReasoningId.value = undefined
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 点击模型主体:直接选中模型,并同步到该模型默认推理等级 */
|
|
159
|
+
const handleSelectModel = (item: ChatModelOption) => {
|
|
160
|
+
model.value = item.id
|
|
161
|
+
reasoningLevel.value = resolveDefaultReasoningLevel(item)
|
|
119
162
|
dropdownRef.value?.close()
|
|
120
163
|
}
|
|
121
164
|
|
|
122
|
-
|
|
165
|
+
/** 点击推理等级胶囊:内联展开/收起该模型的思考强度 */
|
|
166
|
+
const toggleReasoning = (item: ChatModelOption) => {
|
|
167
|
+
expandedReasoningId.value = expandedReasoningId.value === item.id ? undefined : item.id
|
|
168
|
+
nextTick(() => dropdownRef.value?.updateDropdown())
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** 选中思考强度:同时切到该等级所属模型,避免模型与推理等级错配 */
|
|
172
|
+
const handleSelectReasoning = (item: ChatModelOption, value: string) => {
|
|
173
|
+
model.value = item.id
|
|
123
174
|
reasoningLevel.value = value
|
|
124
175
|
dropdownRef.value?.close()
|
|
125
176
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div v-if="queue.length" :class="cls.e('queue')">
|
|
3
|
+
<div :class="cls.e('queue-head')">待发送队列 · {{ queue.length }}</div>
|
|
4
|
+
<div v-for="item in queue" :key="item.id" :class="cls.e('queue-item')">
|
|
5
|
+
<span :class="cls.e('queue-text')" :title="item.content">{{ item.content }}</span>
|
|
6
|
+
<span :class="cls.e('queue-actions')">
|
|
7
|
+
<button
|
|
8
|
+
type="button"
|
|
9
|
+
:class="[cls.e('queue-action'), cls.em('queue-action', 'primary')]"
|
|
10
|
+
title="中断当前会话,立即执行该条"
|
|
11
|
+
@click="emit('start-now', item.id)"
|
|
12
|
+
>
|
|
13
|
+
<UIcon><CaretRight /></UIcon>立即开始
|
|
14
|
+
</button>
|
|
15
|
+
<button
|
|
16
|
+
type="button"
|
|
17
|
+
:class="cls.e('queue-action')"
|
|
18
|
+
title="取回输入框编辑"
|
|
19
|
+
@click="emit('edit', item.id)"
|
|
20
|
+
>
|
|
21
|
+
<UIcon><EditPen /></UIcon>
|
|
22
|
+
</button>
|
|
23
|
+
<button
|
|
24
|
+
type="button"
|
|
25
|
+
:class="cls.e('queue-action')"
|
|
26
|
+
title="移出队列"
|
|
27
|
+
@click="emit('remove', item.id)"
|
|
28
|
+
>
|
|
29
|
+
<UIcon><Close /></UIcon>
|
|
30
|
+
</button>
|
|
31
|
+
</span>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script lang="ts" setup>
|
|
37
|
+
import { UIcon } from '@veltra/desktop'
|
|
38
|
+
import { CaretRight, Close, EditPen } from '@veltra/icons/normal'
|
|
39
|
+
import { bem } from '@veltra/utils'
|
|
40
|
+
import { inject } from 'vue'
|
|
41
|
+
|
|
42
|
+
import type { ChatQueuedMessage } from '../../chat/types'
|
|
43
|
+
import { AiChatDIKey } from './di'
|
|
44
|
+
|
|
45
|
+
defineOptions({ name: 'UAiChatQueueList' })
|
|
46
|
+
|
|
47
|
+
defineProps<{
|
|
48
|
+
/** 待发送队列(按执行顺序排列) */
|
|
49
|
+
queue: ChatQueuedMessage[]
|
|
50
|
+
}>()
|
|
51
|
+
|
|
52
|
+
const emit = defineEmits<{
|
|
53
|
+
/** 立即开始:中断当前会话并插队执行 */
|
|
54
|
+
(e: 'start-now', id: string): void
|
|
55
|
+
/** 编辑:取回输入框重新编辑 */
|
|
56
|
+
(e: 'edit', id: string): void
|
|
57
|
+
/** 移出队列 */
|
|
58
|
+
(e: 'remove', id: string): void
|
|
59
|
+
}>()
|
|
60
|
+
|
|
61
|
+
const di = inject(AiChatDIKey)
|
|
62
|
+
const cls = di?.cls ?? bem('ai-chat')
|
|
63
|
+
</script>
|