@adminforth/agent 2.2.1 → 2.2.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.
|
@@ -25,12 +25,14 @@ const props = withDefaults(defineProps<{
|
|
|
25
25
|
contentStyle?: Record<string, string>
|
|
26
26
|
scrollBarAutoHide?: boolean
|
|
27
27
|
scrollToBottomOnMount?: boolean
|
|
28
|
+
debugMode?: boolean
|
|
28
29
|
}>(), {
|
|
29
30
|
enabled: true,
|
|
30
31
|
threshold: 50,
|
|
31
32
|
behavior: 'instant',
|
|
32
33
|
scrollBarAutoHide: true,
|
|
33
|
-
scrollToBottomOnMount: true
|
|
34
|
+
scrollToBottomOnMount: true,
|
|
35
|
+
debugMode: false
|
|
34
36
|
})
|
|
35
37
|
|
|
36
38
|
const containerRef = ref<HTMLDivElement | null>(null)
|
|
@@ -104,11 +106,12 @@ function isNearBottom(customThreshold?: number): boolean {
|
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
function scrollToBottom(force = false): void {
|
|
107
|
-
console.log('scrollToBottom called with force:', force)
|
|
109
|
+
if (props.debugMode) console.log('scrollToBottom called with force:', force)
|
|
108
110
|
const container = containerRef.value?.scrollEl
|
|
109
111
|
if (!container) return
|
|
110
112
|
|
|
111
113
|
if (isUserScrolledUp.value && !force) return
|
|
114
|
+
if (props.debugMode) console.log('Scrolling to bottom...:', container.scrollHeight)
|
|
112
115
|
container.scrollTo({
|
|
113
116
|
top: container.scrollHeight,
|
|
114
117
|
behavior: props.behavior
|
|
@@ -208,7 +208,17 @@ function getHeightOfLastUserMessage() {
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
function getHeightOfLastAgentMessage() {
|
|
211
|
-
|
|
211
|
+
const lastUserIndex = props.messages.findLastIndex((message: IMessage) => message.role === 'user');
|
|
212
|
+
const lastAgentIndex = props.messages.findLastIndex((message: IMessage) => message.role === 'assistant');
|
|
213
|
+
// Only reserve spacer space for the current turn's answer, i.e. an assistant message that comes
|
|
214
|
+
// after the last user message. Right after a send the "Thinking" placeholder isn't pushed yet, so
|
|
215
|
+
// findLastIndex would return the previous turn's answer (which sits above the just-sent user
|
|
216
|
+
// message). Subtracting its height shrinks the spacer, making scrollToBottom stop short — and once
|
|
217
|
+
// the real placeholder arrives the spacer grows and the true bottom drops below where we scrolled.
|
|
218
|
+
if (lastAgentIndex <= lastUserIndex) {
|
|
219
|
+
return 0;
|
|
220
|
+
}
|
|
221
|
+
return messagesRefs.value[lastAgentIndex]?.clientHeight ?? 0;
|
|
212
222
|
}
|
|
213
223
|
|
|
214
224
|
function getScrollClientHeight() {
|
|
@@ -221,15 +231,14 @@ async function updateSpacerHeight() {
|
|
|
221
231
|
}
|
|
222
232
|
|
|
223
233
|
const clientHeight = getScrollClientHeight();
|
|
224
|
-
|
|
225
234
|
if (!clientHeight) {
|
|
226
235
|
return;
|
|
227
236
|
}
|
|
228
237
|
|
|
229
238
|
const lastUserMessageHeight = getHeightOfLastUserMessage();
|
|
230
239
|
const lastAgentMessageHeight = getHeightOfLastAgentMessage();
|
|
231
|
-
|
|
232
|
-
spacerHeight.value =
|
|
240
|
+
const newSpacerHeight = Math.max(0, clientHeight - (lastUserMessageHeight + MASK_HEIGHT + lastAgentMessageHeight));
|
|
241
|
+
spacerHeight.value = newSpacerHeight;
|
|
233
242
|
}
|
|
234
243
|
|
|
235
244
|
function scheduleSpacerHeightUpdate() {
|
|
@@ -310,8 +319,9 @@ async function handleSendMessage() {
|
|
|
310
319
|
|
|
311
320
|
if (clientHeight) {
|
|
312
321
|
showBottomSpacer.value = true;
|
|
322
|
+
await nextTick(); // render the just-sent user message + spacer before measuring their heights
|
|
313
323
|
await updateSpacerHeight();
|
|
314
|
-
await nextTick();
|
|
324
|
+
await nextTick(); // apply the computed spacer height before scrolling
|
|
315
325
|
scrollContainer.value?.scrollToBottom();
|
|
316
326
|
}
|
|
317
327
|
}
|