(
props: ParentProps<{
sessionID: string
messageID: string
classes?: {
root?: string
content?: string
container?: string
}
}>,
)
| 22 | import { DateTime, DurationUnit, Interval } from "luxon" |
| 23 | |
| 24 | export function SessionTurn( |
| 25 | props: ParentProps<{ |
| 26 | sessionID: string |
| 27 | messageID: string |
| 28 | classes?: { |
| 29 | root?: string |
| 30 | content?: string |
| 31 | container?: string |
| 32 | } |
| 33 | }>, |
| 34 | ) { |
| 35 | const data = useData() |
| 36 | const diffComponent = useDiffComponent() |
| 37 | const messages = createMemo(() => (props.sessionID ? (data.store.message[props.sessionID] ?? []) : [])) |
| 38 | const userMessages = createMemo(() => |
| 39 | messages() |
| 40 | .filter((m) => m.role === "user") |
| 41 | .sort((a, b) => a.id.localeCompare(b.id)), |
| 42 | ) |
| 43 | const message = createMemo(() => userMessages()?.find((m) => m.id === props.messageID)) |
| 44 | const status = createMemo( |
| 45 | () => |
| 46 | data.store.session_status[props.sessionID] ?? { |
| 47 | type: "idle", |
| 48 | }, |
| 49 | ) |
| 50 | const working = createMemo(() => status()?.type !== "idle") |
| 51 | |
| 52 | let scrollRef: HTMLDivElement | undefined |
| 53 | const [state, setState] = createStore({ |
| 54 | contentRef: undefined as HTMLDivElement | undefined, |
| 55 | stickyTitleRef: undefined as HTMLDivElement | undefined, |
| 56 | stickyTriggerRef: undefined as HTMLDivElement | undefined, |
| 57 | userScrolled: false, |
| 58 | stickyHeaderHeight: 0, |
| 59 | scrollY: 0, |
| 60 | autoScrolling: false, |
| 61 | }) |
| 62 | |
| 63 | function handleScroll() { |
| 64 | if (!scrollRef) return |
| 65 | setState("scrollY", scrollRef.scrollTop) |
| 66 | if (state.autoScrolling) return |
| 67 | const { scrollTop, scrollHeight, clientHeight } = scrollRef |
| 68 | const atBottom = scrollHeight - scrollTop - clientHeight < 50 |
| 69 | if (!atBottom && working()) { |
| 70 | setState("userScrolled", true) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | function handleInteraction() { |
| 75 | if (working()) { |
| 76 | setState("userScrolled", true) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | function scrollToBottom() { |
| 81 | if (!scrollRef || state.userScrolled || !working() || state.autoScrolling) return |
nothing calls this directly
no test coverage detected