- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: display startup script logs while agent is starting#19530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Changes fromall commits
39ede8519c7b4f0c38cd1d7aad8766d30d02f0999af56a468199a13eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,28 @@ | ||
| import { API } from "api/api"; | ||
| import { getErrorDetail, getErrorMessage } from "api/errors"; | ||
| import { template as templateQueryOptions } from "api/queries/templates"; | ||
| import type { | ||
| Workspace, | ||
| WorkspaceAgent, | ||
| WorkspaceStatus, | ||
| } from "api/typesGenerated"; | ||
| import isChromatic from "chromatic/isChromatic"; | ||
| import { Button } from "components/Button/Button"; | ||
| import { Loader } from "components/Loader/Loader"; | ||
| import { Margins } from "components/Margins/Margins"; | ||
| import { ScrollArea } from "components/ScrollArea/ScrollArea"; | ||
| import { useWorkspaceBuildLogs } from "hooks/useWorkspaceBuildLogs"; | ||
| import { ArrowLeftIcon, RotateCcwIcon } from "lucide-react"; | ||
| import { AgentLogs } from "modules/resources/AgentLogs/AgentLogs"; | ||
| import { useAgentLogs } from "modules/resources/useAgentLogs"; | ||
| import { AI_PROMPT_PARAMETER_NAME, type Task } from "modules/tasks/tasks"; | ||
| import { WorkspaceBuildLogs } from "modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs"; | ||
| import { type FC, type ReactNode,useLayoutEffect, useRef } from "react"; | ||
| import { Helmet } from "react-helmet-async"; | ||
| import { useQuery } from "react-query"; | ||
| import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; | ||
| import { Link as RouterLink, useParams } from "react-router"; | ||
| import type { FixedSizeList } from "react-window"; | ||
| import { pageTitle } from "utils/page"; | ||
| import { | ||
| getActiveTransitionStats, | ||
| @@ -87,6 +94,7 @@ const TaskPage = () => { | ||
| } | ||
| let content: ReactNode = null; | ||
| const agent = selectAgent(task); | ||
| if (waitingStatuses.includes(task.workspace.latest_build.status)) { | ||
| content = <TaskBuildingWorkspace task={task} />; | ||
| @@ -132,6 +140,8 @@ const TaskPage = () => { | ||
| </div> | ||
| </Margins> | ||
| ); | ||
| } else if (agent && ["created", "starting"].includes(agent.lifecycle_state)) { | ||
| content = <TaskStartingAgent agent={agent} />; | ||
| } else { | ||
| content = ( | ||
| <PanelGroup autoSaveId="task" direction="horizontal"> | ||
| @@ -182,7 +192,7 @@ const TaskBuildingWorkspace: FC<TaskBuildingWorkspaceProps> = ({ task }) => { | ||
| const scrollAreaRef = useRef<HTMLDivElement>(null); | ||
| // biome-ignore lint/correctness/useExhaustiveDependencies: this effect should run when build logs change | ||
| useLayoutEffect(() => { | ||
| if (isChromatic()) { | ||
| return; | ||
| } | ||
| @@ -196,34 +206,86 @@ const TaskBuildingWorkspace: FC<TaskBuildingWorkspaceProps> = ({ task }) => { | ||
| }, [buildLogs]); | ||
| return ( | ||
| <section className="p-16 overflow-y-auto"> | ||
| <div className="flex justify-center items-center w-full"> | ||
| <div className="flex flex-col gap-6 items-center w-full"> | ||
| <header className="flex flex-col items-center text-center"> | ||
| <h3 className="m-0 font-medium text-content-primary text-xl"> | ||
| Starting your workspace | ||
| </h3> | ||
| <p className="text-content-secondary m-0"> | ||
| Your task will be running in a few moments | ||
| </p> | ||
| </header> | ||
| <div className="w-full max-w-screen-lg flex flex-col gap-4 overflow-hidden"> | ||
| <WorkspaceBuildProgress | ||
| workspace={task.workspace} | ||
| transitionStats={transitionStats} | ||
| variant="task" | ||
| /> | ||
| <ScrollArea | ||
| ref={scrollAreaRef} | ||
| className="h-96 border border-solid border-border rounded-lg" | ||
| > | ||
| <WorkspaceBuildLogs | ||
| sticky | ||
| className="border-0 rounded-none" | ||
| logs={buildLogs ?? []} | ||
| /> | ||
| </ScrollArea> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </section> | ||
| ); | ||
| }; | ||
| type TaskStartingAgentProps = { | ||
| agent: WorkspaceAgent; | ||
| }; | ||
| const TaskStartingAgent: FC<TaskStartingAgentProps> = ({ agent }) => { | ||
| const logs = useAgentLogs(agent, true); | ||
| const listRef = useRef<FixedSizeList>(null); | ||
| useLayoutEffect(() => { | ||
| if (listRef.current) { | ||
| listRef.current.scrollToItem(logs.length - 1, "end"); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Do you know what the scroll behavior is for the React Window component? As in, do you know if the scroll is instant, or if it does an animation? Because if it's instant, we could swap in ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. It is instant, and we can move to use | ||
| } | ||
| }, [logs]); | ||
| return ( | ||
| <section className="p-16 overflow-y-auto"> | ||
| <div className="flex justify-center items-center w-full"> | ||
| <div className="flex flex-col gap-8 items-center w-full"> | ||
| <header className="flex flex-col items-center text-center"> | ||
| <h3 className="m-0 font-medium text-content-primary text-xl"> | ||
| Running startup scripts | ||
| </h3> | ||
| <p className="text-content-secondary m-0"> | ||
| Your task will be running in a few moments | ||
| </p> | ||
| </header> | ||
| <div className="w-full max-w-screen-lg flex flex-col gap-4 overflow-hidden"> | ||
| <div className="h-96 border border-solid border-border rounded-lg"> | ||
| <AgentLogs | ||
| logs={logs.map((l) => ({ | ||
| id: l.id, | ||
| level: l.level, | ||
| output: l.output, | ||
| sourceId: l.source_id, | ||
| time: l.created_at, | ||
| }))} | ||
| sources={agent.log_sources} | ||
| height={96 * 4} | ||
| width="100%" | ||
| ref={listRef} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </section> | ||
| @@ -265,3 +327,11 @@ export const data = { | ||
| } satisfies Task; | ||
| }, | ||
| }; | ||
| function selectAgent(task: Task) { | ||
| const agents = task.workspace.latest_build.resources | ||
| .flatMap((r) => r.agents) | ||
| .filter((a) => !!a); | ||
| return agents.at(0); | ||
| } | ||
Uh oh!
There was an error while loading.Please reload this page.