Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Issue #328: Auto-scrolling in web-UI Update (#420)

Anish Karthike08259cf75b8
diff --git a/sweagent/frontend/src/Run.js b/sweagent/frontend/src/Run.js
index 97e10f29..d4ec9254 100644
--- a/sweagent/frontend/src/Run.js
+++ b/sweagent/frontend/src/Run.js
@@ -57,6 +57,9 @@ function Run() {
const agentFeedRef = useRef(null);
const envFeedRef = useRef(null);
const logsRef = useRef(null);
+ const isLogScrolled = useRef(false);
+ const isEnvScrolled = useRef(false);
+ const isAgentScrolled = useRef(false);
const [tabKey, setTabKey] = useState("problem");
@@ -154,8 +157,42 @@ function Run() {
}
};
+ const checkScrollPosition = (ref, scrollStateRef, offset = 0) => {
+ scrollStateRef.current =
+ ref.current.scrollTop + ref.current.clientHeight + offset <
+ ref.current.scrollHeight;
+ };
+
+ const scrollToBottom = (ref, scrollStateRef) => {
+ if (!scrollStateRef.current) {
+ ref.current.scrollTop = ref.current.scrollHeight;
+ }
+ };
+
+ const scrollDetectedLog = () =>
+ checkScrollPosition(logsRef, isLogScrolled, 58);
+ const scrollLog = () => scrollToBottom(logsRef, isLogScrolled);
+
+ const scrollDetectedEnv = () =>
+ checkScrollPosition(envFeedRef, isEnvScrolled);
+ const scrollEnv = () => scrollToBottom(envFeedRef, isEnvScrolled);
+
+ const scrollDetectedAgent = () =>
+ checkScrollPosition(agentFeedRef, isAgentScrolled);
+ const scrollAgent = () => scrollToBottom(agentFeedRef, isAgentScrolled);
+
// Use effect to listen to socket updates
React.useEffect(() => {
+ logsRef.current.addEventListener("scroll", scrollDetectedLog, {
+ passive: true,
+ });
+ envFeedRef.current.addEventListener("scroll", scrollDetectedEnv, {
+ passive: true,
+ });
+ agentFeedRef.current.addEventListener("scroll", scrollDetectedAgent, {
+ passive: true,
+ });
+
const handleUpdate = (data) => {
requeueStopComputeTimeout();
if (data.feed === "agent") {
@@ -168,6 +205,11 @@ function Run() {
step: data.thought_idx,
},
]);
+ if (envFeedRef.current) {
+ setTimeout(() => {
+ scrollEnv();
+ }, 100);
+ }
} else if (data.feed === "env") {
setEnvFeed((prevMessages) => [
...prevMessages,
@@ -178,11 +220,17 @@ function Run() {
step: data.thought_idx,
},
]);
+ if (agentFeedRef.current) {
+ setTimeout(() => {
+ scrollAgent();
+ }, 100);
+ }
}
- };
-
- const scrollLog = () => {
- logsRef.current.scrollTop = logsRef.current.scrollHeight;
+ return () => {
+ logsRef.current.removeEventListener("scroll", scrollDetectedLog);
+ envFeedRef.current.removeEventListener("scroll", scrollDetectedEnv);
+ agentFeedRef.current.removeEventListener("scroll", scrollDetectedAgent);
+ };
};
const handleUpdateBanner = (data) => {
diff --git a/sweagent/frontend/src/components/panels/AgentFeed.js b/sweagent/frontend/src/components/panels/AgentFeed.js
index c8309d91..70aff1c1 100644
--- a/sweagent/frontend/src/components/panels/AgentFeed.js
+++ b/sweagent/frontend/src/components/panels/AgentFeed.js
@@ -4,14 +4,6 @@ import MacBar from "../MacBar";
import editorLogo from "../../assets/panel_icons/editor.png";
import "../../static/agentFeed.css";
-function useScrollToBottom(feed, ref) {
- useEffect(() => {
- if (ref.current) {
- ref.current.scrollTop = ref.current.scrollHeight;
- }
- }, [feed, ref]);
-}
-
const AgentFeed = ({
feed,
highlightedStep,
@@ -19,8 +11,6 @@ const AgentFeed = ({
handleMouseLeave,
selfRef,
}) => {
- useScrollToBottom(feed, selfRef);
-
return (
<div id="agentFeed" className="agentFeed">
<MacBar title="Thoughts" logo={editorLogo} />
diff --git a/sweagent/frontend/src/components/panels/EnvFeed.js b/sweagent/frontend/src/components/panels/EnvFeed.js
index 0606dd7d..197f9eaa 100644
--- a/sweagent/frontend/src/components/panels/EnvFeed.js
+++ b/sweagent/frontend/src/components/panels/EnvFeed.js
@@ -5,14 +5,6 @@ import MacBar from "../MacBar";
import terminalLogo from "../../assets/panel_icons/terminal.png";
import "../../static/envFeed.css";
-function useScrollToBottom(feed, ref) {
- useEffect(() => {
- if (ref.current) {
- ref.current.scrollTop = ref.current.scrollHeight;
- }
- }, [feed, ref]);
-}
-
const EnvFeed = ({
feed,
highlightedStep,
@@ -20,8 +12,6 @@ const EnvFeed = ({
handleMouseLeave,
selfRef,
}) => {
- useScrollToBottom(feed, selfRef);
-
return (
<div id="envFeed" className="envFeed">
<MacBar title="Terminal" logo={terminalLogo} dark={false} />