From 41e234c6d0f7f0e8cfb137ef1a4d9c9c9eea7d06 Mon Sep 17 00:00:00 2001
From: Adam <2363879+adamdotdevin@users.noreply.github.com>
Date: Fri, 12 Dec 2025 14:32:18 -0600
Subject: fix: desktop layout
---
packages/ui/src/components/session-turn.tsx | 593 +++++++++++++++-------------
1 file changed, 317 insertions(+), 276 deletions(-)
(limited to 'packages/ui/src')
diff --git a/packages/ui/src/components/session-turn.tsx b/packages/ui/src/components/session-turn.tsx
index 8612fc0b6..f57a0509b 100644
--- a/packages/ui/src/components/session-turn.tsx
+++ b/packages/ui/src/components/session-turn.tsx
@@ -3,7 +3,19 @@ import { useData } from "../context"
import { useDiffComponent } from "../context/diff"
import { getDirectory, getFilename } from "@opencode-ai/util/path"
import { checksum } from "@opencode-ai/util/encode"
-import { createEffect, createMemo, For, Match, onCleanup, ParentProps, Show, Switch } from "solid-js"
+import {
+ createEffect,
+ createMemo,
+ createSignal,
+ For,
+ Match,
+ onCleanup,
+ onMount,
+ ParentProps,
+ Show,
+ Switch,
+} from "solid-js"
+import { createResizeObserver } from "@solid-primitives/resize-observer"
import { DiffChanges } from "./diff-changes"
import { Typewriter } from "./typewriter"
import { Message } from "./message-part"
@@ -48,304 +60,333 @@ export function SessionTurn(
)
const working = createMemo(() => status()?.type !== "idle")
+ let scrollRef: HTMLDivElement | undefined
+ let contentRef: HTMLDivElement | undefined
+ const [userScrolled, setUserScrolled] = createSignal(false)
+
+ function handleScroll() {
+ if (!scrollRef) return
+ const { scrollTop, scrollHeight, clientHeight } = scrollRef
+ const atBottom = scrollHeight - scrollTop - clientHeight < 50
+ if (!atBottom && working()) {
+ setUserScrolled(true)
+ }
+ }
+
+ createEffect(() => {
+ if (!working()) {
+ setUserScrolled(false)
+ }
+ })
+
+ onMount(() => {
+ if (!contentRef) return
+ createResizeObserver(contentRef, () => {
+ if (!scrollRef || userScrolled() || !working()) return
+ scrollRef.scrollTop = scrollRef.scrollHeight
+ })
+ })
+
return (
-
-
- {(message) => {
- const assistantMessages = createMemo(() => {
- return messages()?.filter(
- (m) => m.role === "assistant" && m.parentID == message().id,
- ) as AssistantMessage[]
- })
- const lastAssistantMessage = createMemo(() => assistantMessages()?.at(-1))
- const assistantMessageParts = createMemo(() => assistantMessages()?.flatMap((m) => data.store.part[m.id]))
- const error = createMemo(() => assistantMessages().find((m) => m?.error)?.error)
- const parts = createMemo(() => data.store.part[message().id])
- const lastTextPart = createMemo(() =>
- assistantMessageParts()
- .filter((p) => p?.type === "text")
- ?.at(-1),
- )
- const summary = createMemo(() => message().summary?.body ?? lastTextPart()?.text)
- const lastTextPartShown = createMemo(
- () => !message().summary?.body && (lastTextPart()?.text?.length ?? 0) > 0,
- )
+
+
+
+ {(message) => {
+ const assistantMessages = createMemo(() => {
+ return messages()?.filter(
+ (m) => m.role === "assistant" && m.parentID == message().id,
+ ) as AssistantMessage[]
+ })
+ const lastAssistantMessage = createMemo(() => assistantMessages()?.at(-1))
+ const assistantMessageParts = createMemo(() => assistantMessages()?.flatMap((m) => data.store.part[m.id]))
+ const error = createMemo(() => assistantMessages().find((m) => m?.error)?.error)
+ const parts = createMemo(() => data.store.part[message().id])
+ const lastTextPart = createMemo(() =>
+ assistantMessageParts()
+ .filter((p) => p?.type === "text")
+ ?.at(-1),
+ )
+ const summary = createMemo(() => message().summary?.body ?? lastTextPart()?.text)
+ const lastTextPartShown = createMemo(
+ () => !message().summary?.body && (lastTextPart()?.text?.length ?? 0) > 0,
+ )
- const assistantParts = createMemo(() => assistantMessages().flatMap((m) => data.store.part[m.id]))
- const currentTask = createMemo(
- () =>
- assistantParts().findLast(
- (p) =>
- p &&
- p.type === "tool" &&
- p.tool === "task" &&
- p.state &&
- "metadata" in p.state &&
- p.state.metadata &&
- p.state.metadata.sessionId &&
- p.state.status === "running",
- ) as ToolPart,
- )
- const resolvedParts = createMemo(() => {
- let resolved = assistantParts()
- const task = currentTask()
- if (task && task.state && "metadata" in task.state && task.state.metadata?.sessionId) {
- const messages = data.store.message[task.state.metadata.sessionId as string]?.filter(
- (m) => m.role === "assistant",
- )
- resolved = messages?.flatMap((m) => data.store.part[m.id]) ?? assistantParts()
- }
- return resolved
- })
- const lastPart = createMemo(() => resolvedParts().slice(-1)?.at(0))
- const rawStatus = createMemo(() => {
- const last = lastPart()
- if (!last) return undefined
+ const assistantParts = createMemo(() => assistantMessages().flatMap((m) => data.store.part[m.id]))
+ const currentTask = createMemo(
+ () =>
+ assistantParts().findLast(
+ (p) =>
+ p &&
+ p.type === "tool" &&
+ p.tool === "task" &&
+ p.state &&
+ "metadata" in p.state &&
+ p.state.metadata &&
+ p.state.metadata.sessionId &&
+ p.state.status === "running",
+ ) as ToolPart,
+ )
+ const resolvedParts = createMemo(() => {
+ let resolved = assistantParts()
+ const task = currentTask()
+ if (task && task.state && "metadata" in task.state && task.state.metadata?.sessionId) {
+ const messages = data.store.message[task.state.metadata.sessionId as string]?.filter(
+ (m) => m.role === "assistant",
+ )
+ resolved = messages?.flatMap((m) => data.store.part[m.id]) ?? assistantParts()
+ }
+ return resolved
+ })
+ const lastPart = createMemo(() => resolvedParts().slice(-1)?.at(0))
+ const rawStatus = createMemo(() => {
+ const last = lastPart()
+ if (!last) return undefined
- if (last.type === "tool") {
- switch (last.tool) {
- case "task":
- return "Delegating work"
- case "todowrite":
- case "todoread":
- return "Planning next steps"
- case "read":
- return "Gathering context"
- case "list":
- case "grep":
- case "glob":
- return "Searching the codebase"
- case "webfetch":
- return "Searching the web"
- case "edit":
- case "write":
- return "Making edits"
- case "bash":
- return "Running commands"
- default:
- break
+ if (last.type === "tool") {
+ switch (last.tool) {
+ case "task":
+ return "Delegating work"
+ case "todowrite":
+ case "todoread":
+ return "Planning next steps"
+ case "read":
+ return "Gathering context"
+ case "list":
+ case "grep":
+ case "glob":
+ return "Searching the codebase"
+ case "webfetch":
+ return "Searching the web"
+ case "edit":
+ case "write":
+ return "Making edits"
+ case "bash":
+ return "Running commands"
+ default:
+ break
+ }
+ } else if (last.type === "reasoning") {
+ return "Thinking"
+ } else if (last.type === "text") {
+ return "Gathering thoughts"
}
- } else if (last.type === "reasoning") {
- return "Thinking"
- } else if (last.type === "text") {
- return "Gathering thoughts"
- }
- return undefined
- })
+ return undefined
+ })
- function duration() {
- const completed = lastAssistantMessage()?.time.completed
- const from = DateTime.fromMillis(message()!.time.created)
- const to = completed ? DateTime.fromMillis(completed) : DateTime.now()
- const interval = Interval.fromDateTimes(from, to)
- const unit: DurationUnit[] = interval.length("seconds") > 60 ? ["minutes", "seconds"] : ["seconds"]
+ function duration() {
+ const completed = lastAssistantMessage()?.time.completed
+ const from = DateTime.fromMillis(message()!.time.created)
+ const to = completed ? DateTime.fromMillis(completed) : DateTime.now()
+ const interval = Interval.fromDateTimes(from, to)
+ const unit: DurationUnit[] = interval.length("seconds") > 60 ? ["minutes", "seconds"] : ["seconds"]
- return interval.toDuration(unit).normalize().toHuman({
- notation: "compact",
- unitDisplay: "narrow",
- compactDisplay: "short",
- showZeros: false,
- })
- }
+ return interval.toDuration(unit).normalize().toHuman({
+ notation: "compact",
+ unitDisplay: "narrow",
+ compactDisplay: "short",
+ showZeros: false,
+ })
+ }
- const [store, setStore] = createStore({
- status: rawStatus(),
- detailsExpanded: true,
- duration: duration(),
- })
+ const [store, setStore] = createStore({
+ status: rawStatus(),
+ detailsExpanded: true,
+ duration: duration(),
+ })
- createEffect(() => {
- const timer = setInterval(() => {
- setStore("duration", duration())
- }, 1000)
- onCleanup(() => clearInterval(timer))
- })
+ createEffect(() => {
+ const timer = setInterval(() => {
+ setStore("duration", duration())
+ }, 1000)
+ onCleanup(() => clearInterval(timer))
+ })
- let lastStatusChange = Date.now()
- let statusTimeout: number | undefined
- createEffect(() => {
- const newStatus = rawStatus()
- if (newStatus === store.status || !newStatus) return
+ let lastStatusChange = Date.now()
+ let statusTimeout: number | undefined
+ createEffect(() => {
+ const newStatus = rawStatus()
+ if (newStatus === store.status || !newStatus) return
- const timeSinceLastChange = Date.now() - lastStatusChange
+ const timeSinceLastChange = Date.now() - lastStatusChange
- if (timeSinceLastChange >= 2500) {
- setStore("status", newStatus)
- lastStatusChange = Date.now()
- if (statusTimeout) {
- clearTimeout(statusTimeout)
- statusTimeout = undefined
- }
- } else {
- if (statusTimeout) clearTimeout(statusTimeout)
- statusTimeout = setTimeout(() => {
- setStore("status", rawStatus())
+ if (timeSinceLastChange >= 2500) {
+ setStore("status", newStatus)
lastStatusChange = Date.now()
- statusTimeout = undefined
- }, 2500 - timeSinceLastChange) as unknown as number
- }
- })
+ if (statusTimeout) {
+ clearTimeout(statusTimeout)
+ statusTimeout = undefined
+ }
+ } else {
+ if (statusTimeout) clearTimeout(statusTimeout)
+ statusTimeout = setTimeout(() => {
+ setStore("status", rawStatus())
+ lastStatusChange = Date.now()
+ statusTimeout = undefined
+ }, 2500 - timeSinceLastChange) as unknown as number
+ }
+ })
- return (
-
- {/* Title */}
-
-
-
-
-
-
-
- {message().summary?.title}
-
-
+ return (
+
+ {/* Title */}
+
+
+
+
+
+
+
+ {message().summary?.title}
+
+
+
-
-
-
-
- {/* Response */}
-
- setStore("detailsExpanded", open)}
- data-slot="session-turn-collapsible"
- >
-
+
+
+ {/* Response */}
+
+
setStore("detailsExpanded", open)}
+ data-slot="session-turn-collapsible"
>
-
-
-
-
- {store.status ?? "Considering next steps..."}
- Hide steps
- Show steps
-
- ·
- {store.duration}
-
-
-
-
-
- {(assistantMessage) => {
- const parts = createMemo(() => data.store.part[assistantMessage.id] ?? [])
- const last = createMemo(() =>
- parts()
- .filter((p) => p?.type === "text")
- .at(-1),
- )
- return (
-
-
- p?.id !== last()?.id)}
- />
-
-
-
-
-
- )
- }}
-
-
-
- {error()?.data?.message as string}
-
+
+
+
-
-
-
-
- {/* Summary */}
-
-
-
-
- Summary
- Response
+ {store.status ?? "Considering next steps..."}
+ Hide steps
+ Show steps
-
-
- {(summary) => (
-
- )}
-
-
-
-
- {(diff) => (
-
-
-
-
-
-
·
+ {store.duration}
+
+
+
+
+
+ {(assistantMessage) => {
+ const parts = createMemo(() => data.store.part[assistantMessage.id] ?? [])
+ const last = createMemo(() =>
+ parts()
+ .filter((p) => p?.type === "text")
+ .at(-1),
+ )
+ return (
+
+
+ p?.id !== last()?.id)}
/>
-
-
- {getDirectory(diff.file)}
-
- {getFilename(diff.file)}
+
+
+
+
+
+ )
+ }}
+
+
+
+ {error()?.data?.message as string}
+
+
+
+
+
+
+ {/* Summary */}
+
+
+
+
+
+ Summary
+ Response
+
+
+
+ {(summary) => (
+
+ )}
+
+
+
+
+ {(diff) => (
+
+
+
+
+
+
+
+
+ {getDirectory(diff.file)}
+
+ {getFilename(diff.file)}
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
- )}
-
-
-
-
-
-
- {error()?.data?.message as string}
-
-
-
- )
- }}
-
- {props.children}
+
+
+
+
+
+
+ )}
+
+
+
+
+
+
+ {error()?.data?.message as string}
+
+
+
+ )
+ }}
+
+ {props.children}
+
)
--
cgit v1.2.3