The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
chore: files changed app/src/components/assistant-ui/elements/scroll-anchor.aui.tsx,app/src/componen
Steven Enamakel971f98b2c0f5
diff --git a/app/src/components/assistant-ui/elements/scroll-anchor.aui.tsx b/app/src/components/assistant-ui/elements/scroll-anchor.aui.tsxindex 9a350b487e..b7d37f3a15 100644--- a/app/src/components/assistant-ui/elements/scroll-anchor.aui.tsx+++ b/app/src/components/assistant-ui/elements/scroll-anchor.aui.tsx@@ -7,20 +7,18 @@ import { ArrowDownIcon } from 'lucide-react';/*** Runtime scroll-anchor pill. The viewport owns visibility and the jump; the- * host can reclaim its streaming follower when the reader returns to the end.+ * library resumes following when the reader returns to the end.* Positioned above the composer so expanding its cards moves the pill with it.*/export function ScrollAnchor({label,- onJump,className,}: {label: string;- onJump?: () => void;className?: string;}) {return (- <ThreadPrimitive.ScrollToBottom asChild behavior="instant" onClick={onJump}>+ <ThreadPrimitive.ScrollToBottom asChild behavior="instant"><Buttondata-slot="scroll-anchor"data-analytics-id="chat-scroll-to-bottom"diff --git a/app/src/components/assistant-ui/thread.tsx b/app/src/components/assistant-ui/thread.tsxindex c37f2c6404..b577164640 100644--- a/app/src/components/assistant-ui/thread.tsx+++ b/app/src/components/assistant-ui/thread.tsx@@ -32,7 +32,6 @@ import {useAuiReloadCapability,} from '@/features/conversations/components/aui/auiThreadState';import { useT } from '@/lib/i18n/I18nContext';-import { useAuiThreadId } from '@/providers/AssistantUiRuntimeProvider';import { CHAT_ERROR_METADATA_KEY } from '@/store/threadSlice';import { fullTimestamp, relativeTime } from '@/utils/relativeTime';import { useActionBarReload, useMessageError } from '@assistant-ui/core/react';@@ -80,11 +79,9 @@ import {createContext,type FC,type PropsWithChildren,- type RefObject,useCallback,useContext,useEffect,- useLayoutEffect,useMemo,useRef,useState,@@ -431,16 +428,6 @@ const ThreadRoot: FC<{Composer: HostComposer,ConversationMap,} = useContext(ThreadComponentsContext);- const viewportRef = useRef<HTMLDivElement>(null);- const messageGroupRef = useRef<HTMLDivElement>(null);- // Everything the viewport scrolls over, which is MORE than the message group:- // the footer below it holds the follow-up suggestions, and those appear when- // a reply finishes. Observing only the messages misses that growth and leaves- // the transcript stranded short of the bottom at the end of every turn.- const scrollContentRef = useRef<HTMLDivElement>(null);-- const { claimScroll } = useFollowBottom(viewportRef, scrollContentRef);- useOpenThreadAtBottom(viewportRef, claimScroll);const { isDraggingFiles, dropHandlers } = useThreadFileDrop();return (@@ -454,22 +441,13 @@ const ThreadRoot: FC<{['--composer-padding' as string]: '8px',}}><ThreadPrimitive.Viewport- ref={viewportRef}- // The host follower below checks the reader's live distance from the- // bottom. Disable assistant-ui's unconditional run-start jump so it- // cannot override a reader who intentionally scrolled into history.- autoScroll={false}+ autoScroll+ turnAnchor="bottom"scrollToBottomOnRunStart={false}- // The host opens cached threads by their real id. Leaving the native- // initialize/switch triggers enabled plants a second pending scroll- // that can pull the reader down on a later content resize.- scrollToBottomOnInitialize={false}- scrollToBottomOnThreadSwitch={false}data-slot="aui_thread-viewport"className="relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth">{ConversationMap ? <ConversationMap /> : null}<div- ref={scrollContentRef}className={cn('mx-auto flex w-full max-w-(--thread-max-width) flex-1 flex-col px-4 pt-4',isEmpty && 'justify-center'@@ -493,25 +471,20 @@ const ThreadRoot: FC<{)}<div- ref={messageGroupRef}data-slot="aui_message-group"className="mb-14 flex flex-col gap-y-6 empty:hidden"><ThreadPrimitive.Messages>{() => <ThreadMessage />}</ThreadPrimitive.Messages><RunningStatusSlot /><TranscriptFooterSlot /></div>- <ThreadBottomFollower- viewportRef={viewportRef}- contentRef={messageGroupRef}- claimScroll={claimScroll}- />+<ThreadPrimitive.ViewportFooterclassName={cn('aui-thread-viewport-footer relative z-10 flex flex-col gap-4 overflow-visible bg-transparent pb-4 md:pb-6',!isEmpty && 'sticky bottom-0 mt-auto rounded-t-(--composer-radius)')}>- <ThreadScrollToBottom onJump={claimScroll} />+ <ThreadScrollToBottom /><ThreadFollowupSuggestions /><ConnectionStateBanner />{HostComposer ? (@@ -550,340 +523,6 @@ const ThreadRoot: FC<{);};-/**- * Opening a thread lands on its newest message.- *- * assistant-ui has two stock knobs for this and BOTH are inert here:- *- * - `scrollToBottomOnThreadSwitch` listens for `threads.selectionChanged`,- * which fires only when its `mainThreadId` changes. That id is- * `adapter.threadId ?? DEFAULT_THREAD_ID`, and `useOpenHumanExternalStore`- * returns no `threadId` — the real thread travels out-of-band through- * `AuiThreadIdContext` — so `mainThreadId` never leaves the default and the- * event never fires.- * - `scrollToBottomOnInitialize` latches on the first non-empty render and- * re-arms only while the thread has zero messages. `<AssistantUiChat>` is- * mounted without a `key`, so this viewport survives thread switches with- * that latch still set.- *- * The second one is why the defect is intermittent rather than total, and it- * is the case to keep in mind. `useOpenHumanExternalStore` reads- * `state.thread.messagesByThreadId[threadId]`, a cache cleared only on delete- * or sign-out, so a thread visited earlier this session hands its messages- * over on the very render the id changes: it never passes through the empty- * state that re-arms the latch, and the viewport keeps the PREVIOUS thread's- * `scrollTop`. A thread not yet cached does briefly read empty and therefore- * scrolls correctly even unfixed — so a fix checked only against a fresh- * thread looks right and fixes nothing.- *- * Hence: latch on the thread id rather than on emptiness. Nothing here is- * conditional on the reader's scroll position, unlike `ThreadBottomFollower`- * below — "don't yank the reader who scrolled up" is about a new turn arriving- * in the thread being read, and a scroll offset left over from a different- * thread is not a reading position worth restoring.- *- * This lives in `ThreadRoot`, which owns `viewportRef`, rather than in- * `ThreadBottomFollower`, which is handed it: a descendant's layout effect- * runs before its ancestor's ref is attached, so the follower sees- * `viewportRef.current === null` on the mount that matters and would burn the- * latch without scrolling.- */-function useOpenThreadAtBottom(- viewportRef: RefObject<HTMLDivElement | null>,- claimScroll: () => void-) {- const hasMessages = useAuiState(s => s.thread.messages.length > 0);- const threadId = useAuiThreadId();- // Which thread this viewport has already been dropped to the bottom for.- // `undefined` (nothing opened yet) is deliberately distinct from the- // `string | null` a thread id can be, so the initial value cannot collide- // with a genuine "no thread selected".- const openedThreadRef = useRef<string | null | undefined>(undefined);-- useLayoutEffect(() => {- // Wait for the transcript: on the uncached path the messages arrive a tick- // after the id changes, and a scroll issued against an empty viewport goes- // nowhere. Leaving the latch alone here is what lets that second pass run.- if (!hasMessages) return;- if (openedThreadRef.current === threadId) return;- const viewport = viewportRef.current;- if (!viewport) return;-- openedThreadRef.current = threadId;- // `behavior: 'instant'` overrides the viewport's `scroll-smooth` class:- // opening a thread should start at the bottom, not animate down through the- // entire history to get there.- viewport.scrollTo({ top: viewport.scrollHeight, behavior: 'instant' });- // Re-arm following for the NEW thread. `followRef` lives as long as this- // viewport, which outlives any one thread, so without this a reader who- // scrolled up in thread A carries that `false` into thread B — and if both- // threads sit at the same `scrollTop` (0 and 0 is the easy case) the open- // scroll produces no `scroll` event to re-enable it, so B never follows its- // own reply. Opening a thread is not a reader scrolling away from it.- claimScroll();- }, [claimScroll, hasMessages, threadId, viewportRef]);-}--const FOLLOW_BOTTOM_THRESHOLD_PX = 80;--/**- * How long after a scroll-capable input a falling `scrollTop` still counts as- * the reader moving. Generous enough for a wheel's momentum tail and a held- * key's repeat; far shorter than any gap between a gesture and an unrelated- * layout shift worth ignoring.- */-const USER_SCROLL_INTENT_WINDOW_MS = 1000;--/** Keys that scroll a focused scroller up (or anywhere — any of them is intent). */-const SCROLL_KEYS = new Set(['ArrowUp', 'ArrowDown', 'PageUp', 'PageDown', 'Home', 'End', ' ']);--/**- * Keep the newest content in view while the assistant streams.- *- * `ThreadBottomFollower` below cannot do this. It keys on- * `latestMessage.id`/`.role`, and a streaming reply is ONE message whose id- * never changes (`STREAMING_TAIL_ID`, `providers/assistantUiMessages.ts`) and- * whose role is `assistant` — so it neither passes that hook's `role ===- * 'user'` guard nor re-runs as tokens land. assistant-ui's own `autoScroll` is- * off here deliberately: its stick threshold is ~1px against this host's 80,- * and its run-start jump is unconditional, so enabling it would put two- * followers with different ideas of "at the bottom" on one viewport.- *- * So follow the content box rather than the message list. A `ResizeObserver`- * fires on every height change from any cause — tokens, markdown reflow, a- * code block, a tool timeline expanding, an image decoding — none of which the- * message identity reports.- *- * The reader stays in charge: `followRef` tracks their live distance from the- * bottom, so scrolling up into history stops the following, and scrolling back- * within `FOLLOW_BOTTOM_THRESHOLD_PX` resumes it. That is the contract the- * viewport comment states — never yank a reader who deliberately left the- * bottom — and it is enforced here rather than assumed.- *- * ## Pin-then-follow, and what that costs- *- * `ThreadBottomFollower` aligns a new USER message to the TOP of the viewport- * so the reply streams beneath it. For a reply taller than the viewport that- * alignment and this following are mutually exclusive: keep the question- * pinned and the answer streams below the fold — the reported defect — or- * follow the answer and the question eventually scrolls off the top.- *- * The choice made here is **pin at turn start, follow thereafter**, with the- * reader overriding both by scrolling away. The pin is an alignment for the- * moment a turn begins, not a claim on the whole turn, and every mainstream- * chat client resolves it the same way. This is a visible change to how a long- * reply reads, so it is recorded rather than left to be rediscovered.- *- * What a reader gives up: on a reply taller than the viewport, their own- * question scrolls off the top as the answer streams. What they get back is- * the answer being on screen while it arrives, which is the defect this fixes.- */-function useFollowBottom(- viewportRef: RefObject<HTMLDivElement | null>,- contentRef: RefObject<HTMLDivElement | null>-) {- // Starts true so a thread opens following; the first user scroll away from- // the bottom is what turns it off.- const followRef = useRef(true);- const lastScrollTopRef = useRef(0);- // `scrollHeight` as it stood when we last claimed a scroll. Growth up to this- // mark is growth we already knew about; only growth BEYOND it is new content- // worth following. `null` means no claim is outstanding.- const claimedHeightRef = useRef<number | null>(null);-- /**- * Declare a scroll as OURS, after performing it.- *- * Setting `followRef` alone is not enough and was the first thing I tried.- * A programmatic scroll is synchronous but its `scroll` event is not, so the- * listener runs AFTER the caller has re-armed the flag, sees a `scrollTop`- * lower than the stale baseline, and clears it again. Re-baselining here —- * while `scrollTop` already holds the post-scroll value — is what makes the- * later event a no-op instead.- */- const claimScroll = useCallback(() => {- const viewport = viewportRef.current;- if (!viewport) return;- lastScrollTopRef.current = viewport.scrollTop;- claimedHeightRef.current = viewport.scrollHeight;- followRef.current = true;- }, [viewportRef]);-- useEffect(() => {- const viewport = viewportRef.current;- const content = contentRef.current;- if (!viewport || !content) return;-- const distanceFromBottom = () =>- viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight;-- // Turning following ON needs only proximity to the bottom. Turning it OFF- // requires the reader to have moved UP, which is the part that matters:- //- // a growth-induced `scroll` event carries the reply's NEW `scrollHeight`- // against an unmoved `scrollTop`, so a bare proximity test would read "far- // from the bottom" and clear the flag for a reader who never moved —- // silently ending the follow this hook exists to provide. Requiring a- // decrease in `scrollTop` makes that impossible: content growth does not- // move it, scroll anchoring only ever moves it DOWN the document (it- // preserves the visual position when content is inserted above), and this- // hook's own `scrollTo` moves it to the maximum.- //- // `reasoning.tsx` solves the same problem by additionally requiring- // `scrollHeight` to be unchanged. That is right for a small preview box and- // wrong here: during a live stream the height changes on almost every- // event, so the reader's scroll away would be ignored and they would be- // dragged back down — breaking the "never yank a reader who left the- // bottom" contract. Keying on `scrollTop` alone holds in both cases.- lastScrollTopRef.current = viewport.scrollTop;-- // ...and the move up has to be the READER's. A falling `scrollTop` is not- // proof of that: a disclosure collapsing above the fold, content shrinking- // under a reply that swaps parts, and assistant-ui's `useScrollLock`- // (which writes the old `scrollTop` back on every scroll event while a- // disclosure animates) all lower it with nobody touching anything — and- // each used to switch following off mid-turn, leaving the reply streaming- // below the fold. So a decrease only counts within a short window after- // an input that can scroll: wheel, touch, a scroll key, or a press on the- // viewport itself (its scrollbar).- let userIntentAt = Number.NEGATIVE_INFINITY;- let scrollbarDragActive = false;- const markIntent = () => {- userIntentAt = window.performance.now();- };- const onKeyDown = (event: KeyboardEvent) => {- if (SCROLL_KEYS.has(event.key)) markIntent();- };- const onPointerDown = (event: PointerEvent) => {- if (event.target === viewport) {- scrollbarDragActive = true;- markIntent();- }- };- const clearScrollbarDrag = () => {- scrollbarDragActive = false;- };-- const onScroll = () => {- if (distanceFromBottom() <= FOLLOW_BOTTOM_THRESHOLD_PX) {- followRef.current = true;- } else if (- viewport.scrollTop < lastScrollTopRef.current &&- (scrollbarDragActive ||- window.performance.now() - userIntentAt <= USER_SCROLL_INTENT_WINDOW_MS)- ) {- followRef.current = false;- }- lastScrollTopRef.current = viewport.scrollTop;- };- viewport.addEventListener('scroll', onScroll, { passive: true });- viewport.addEventListener('wheel', markIntent, { passive: true });- viewport.addEventListener('touchmove', markIntent, { passive: true });- // Scroll keys are delivered to whatever has focus, not to the viewport.- const keyTarget = viewport.ownerDocument;- keyTarget.addEventListener('keydown', onKeyDown);- viewport.addEventListener('pointerdown', onPointerDown);- viewport.addEventListener('pointerup', clearScrollbarDrag);- viewport.addEventListener('pointercancel', clearScrollbarDrag);-- const observer = new ResizeObserver(() => {- // Read the flag; do NOT recompute the distance here. By the time this- // callback runs the content has already grown: `scrollHeight` is the new- // larger value while `scrollTop` has not moved, so a fresh measurement- // reads "far from the bottom" *because of the growth being reacted to*.- // Recomputing would decline to follow on the first token batch and never- // recover, which looks identical to the defect this hook fixes. The- // question is "was the reader at the bottom BEFORE this growth", and only- // a value captured before it can answer that.- //- // The flag is maintained by `onScroll` above, which only clears it on a- // genuine upward move by the reader — see the note there for why a bare- // proximity test would clear it on the growth being reacted to.- if (!followRef.current) return;- // Do not follow the growth that PROMPTED the claim.- //- // A new user message grows the content box, which queues a resize- // notification; `ThreadBottomFollower` then aligns that message to the- // top and claims the scroll. The queued callback runs afterwards, and- // following it would scroll straight to the bottom — erasing the- // alignment before it is ever painted, which makes the alignment- // pointless rather than merely short-lived.- //- // So a claim records the height it was made at, and growth up to that- // mark is ignored. The first growth BEYOND it is the reply arriving,- // which is what following is for; the mark is then dropped so the rest- // of the turn streams normally.- const claimedHeight = claimedHeightRef.current;- if (claimedHeight !== null) {- if (viewport.scrollHeight <= claimedHeight) return;- claimedHeightRef.current = null;- }- // `instant` overrides the viewport's `scroll-smooth`: a smooth animation- // per token would lag permanently behind the stream.- viewport.scrollTo({ top: viewport.scrollHeight, behavior: 'instant' });- });- observer.observe(content);-- return () => {- viewport.removeEventListener('scroll', onScroll);- viewport.removeEventListener('wheel', markIntent);- viewport.removeEventListener('touchmove', markIntent);- keyTarget.removeEventListener('keydown', onKeyDown);- viewport.removeEventListener('pointerdown', onPointerDown);- viewport.removeEventListener('pointerup', clearScrollbarDrag);- viewport.removeEventListener('pointercancel', clearScrollbarDrag);- observer.disconnect();- };- }, [contentRef, viewportRef]);-- return { followRef, claimScroll };-}--/**- * Align a new turn only for a reader who remains near the bottom. assistant-ui's- * run-start scroll is unconditional, which would pull a reader from older- * messages into every new turn.- */-const ThreadBottomFollower: FC<{- viewportRef: RefObject<HTMLDivElement | null>;- contentRef: RefObject<HTMLDivElement | null>;- claimScroll: () => void;-}> = ({ viewportRef, contentRef, claimScroll }) => {- const latestMessage = useAuiState(s => s.thread.messages.at(-1));-- useLayoutEffect(() => {- const viewport = viewportRef.current;- const distanceFromBottom = viewport- ? viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight- : Infinity;- if (latestMessage?.role !== 'user' || distanceFromBottom > FOLLOW_BOTTOM_THRESHOLD_PX) {- return;- }- const userMessages = contentRef.current?.querySelectorAll<HTMLElement>('[data-role="user"]');- // `behavior: 'instant'`, like the other two scrolls in this file, and for a- // second reason beyond overriding `scroll-smooth`: `claimScroll` below- // re-baselines from `viewport.scrollTop`, which is only correct if the move- // has already happened. A smooth alignment has NOT moved it by the time the- // next line runs, so the baseline would capture the pre-scroll position and- // the animation's own scroll events — a run of decreasing `scrollTop` —- // would read as the reader scrolling away, clearing the flag exactly when- // the reply starts. That failed intermittently rather than always, since a- // growth event landing between animation frames could re-arm it.- userMessages- ?.item(userMessages.length - 1)- ?.scrollIntoView({ block: 'start', behavior: 'instant' });- // This alignment scrolls UP whenever the reader was at the bottom — the new- // user message sits above the trailing `mb-14` and running-status slot, so- // bringing its top to the viewport top lowers `scrollTop`. To- // `useFollowBottom`'s listener that is indistinguishable from the reader- // scrolling away, and it would clear the follow flag at the exact moment- // the reply starts arriving. Re-arm: this scroll is ours, not theirs.- claimScroll();- }, [claimScroll, contentRef, latestMessage?.id, latestMessage?.role, viewportRef]);-- return null;-};-/*** The host's `RunningStatus`, gated on the thread actually running.*@@ -922,9 +561,9 @@ const ThreadMessage: FC = () => {return <AssistantMessageComponent />;};-const ThreadScrollToBottom: FC<{ onJump: () => void }> = ({ onJump }) => {+const ThreadScrollToBottom: FC = () => {const { t } = useT();- return <ScrollAnchor label={t('chat.message.scrollToBottom')} onJump={onJump} />;+ return <ScrollAnchor label={t('chat.message.scrollToBottom')} />;};const ThreadWelcome: FC = () => {diff --git a/app/src/providers/useOpenHumanExternalStore.ts b/app/src/providers/useOpenHumanExternalStore.tsindex b8655b7205..5308e7b91a 100644--- a/app/src/providers/useOpenHumanExternalStore.ts+++ b/app/src/providers/useOpenHumanExternalStore.ts@@ -868,9 +868,15 @@ export function useOpenHumanExternalStore(// support speech." That is the #5897 defect shape, and Reload already// sits in the same trap today.// No `dictation` key here — see the Web Speech note above this object.- adapters: { feedback: feedbackAdapter, speech: openHumanSpeechAdapter },+ adapters: {+ feedback: feedbackAdapter,+ speech: openHumanSpeechAdapter,+ // Native viewport and composer resets need the real conversation identity.+ threadList: { threadId: threadId ?? undefined },+ },}),[+ threadId,runtimeMessages,isRunning,isLoading,