Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More
TypeScript aiai-agentsai-memoryanthropicartificial-intelligencechromadbclaudeclaude-agent-sdkclaude-agentsclaude-codeclaude-code-pluginclaude-skillsembeddingslong-term-memorymem0memory-engineopenmemoryragsqlitesupermemory
import React, { useState, useEffect } from 'react';
import { useI18n } from '../../i18n';
import { ArrowUpIcon } from './icons';
interface ScrollToTopProps {
targetRef: React.RefObject<HTMLDivElement | null>;
/** Scrolls the list to its start; a windowed list passes its own, which stays on course while rows are measured. */
onTop?: () => void;
}
// The page heading, tabs and toolbar are about 300px tall at 1440; past that the top of the list is out of view.
const SHOW_AFTER_PX = 300;
/** Smooth, unless the reader asked the system for reduced motion. */
export function scrollBehaviorForReader(): ScrollBehavior {
const reduce = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
return reduce ? 'auto' : 'smooth';
}
/** Scrolls without animation when the reader asked the system for reduced motion. */
export function scrollToStart(target: HTMLElement): void {
target.scrollTo({ top: 0, behavior: scrollBehaviorForReader() });
}
/**
* A round Top button at the window's foot on a wide window; the bar pinned over the list has its own Top at every
* width, and below 1280px it is the only one (viewer-template.html, the timeline block).
*/
export function ScrollToTop({ targetRef, onTop }: ScrollToTopProps) {
const { t } = useI18n();
const [isVisible, setIsVisible] = useState(false);
useEffect(() => {
const target = targetRef.current;
if (!target) return;
const handleScroll = () => setIsVisible(target.scrollTop > SHOW_AFTER_PX);
target.addEventListener('scroll', handleScroll, { passive: true });
return () => target.removeEventListener('scroll', handleScroll);
}, [targetRef]);
if (!isVisible) return null;
return (
<button
type="button"
onClick={() => {
if (onTop) onTop();
else if (targetRef.current) scrollToStart(targetRef.current);
}}
className="mem-totop"
aria-label={t('Scroll to top')}
title={t('Scroll to top')}
>
<ArrowUpIcon size={20} />
</button>
);
}