MCPcopy Create free account
hub / github.com/arctic-cli/interface / SessionTurn

Function SessionTurn

packages/ui/src/components/session-turn.tsx:24–462  ·  view source on GitHub ↗
(
  props: ParentProps<{
    sessionID: string
    messageID: string
    classes?: {
      root?: string
      content?: string
      container?: string
    }
  }>,
)

Source from the content-addressed store, hash-verified

22import { DateTime, DurationUnit, Interval } from "luxon"
23
24export 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

Callers

nothing calls this directly

Calls 9

useDiffComponentFunction · 0.90
getDirectoryFunction · 0.90
getFilenameFunction · 0.90
checksumFunction · 0.90
scrollToBottomFunction · 0.85
durationFunction · 0.70
statusFunction · 0.50
messageFunction · 0.50
errorFunction · 0.50

Tested by

no test coverage detected