have messages working but streaming still not fixed yet

Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
This commit is contained in:
Francisco Javier Arceo 2025-07-20 23:50:34 -04:00
parent fc3286be7e
commit f7c9651ca7
23 changed files with 4749 additions and 184 deletions

View file

@ -0,0 +1,39 @@
import { useLayoutEffect, useRef } from "react"
interface UseAutosizeTextAreaProps {
ref: React.RefObject<HTMLTextAreaElement | null>
maxHeight?: number
borderWidth?: number
dependencies: React.DependencyList
}
export function useAutosizeTextArea({
ref,
maxHeight = Number.MAX_SAFE_INTEGER,
borderWidth = 0,
dependencies,
}: UseAutosizeTextAreaProps) {
const originalHeight = useRef<number | null>(null)
useLayoutEffect(() => {
if (!ref.current) return
const currentRef = ref.current
const borderAdjustment = borderWidth * 2
if (originalHeight.current === null) {
originalHeight.current = currentRef.scrollHeight - borderAdjustment
}
currentRef.style.removeProperty("height")
const scrollHeight = currentRef.scrollHeight
// Make sure we don't go over maxHeight
const clampedToMax = Math.min(scrollHeight, maxHeight)
// Make sure we don't go less than the original height
const clampedToMin = Math.max(clampedToMax, originalHeight.current)
currentRef.style.height = `${clampedToMin + borderAdjustment}px`
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [maxHeight, ref, ...dependencies])
}