diff --git a/site/src/pages/TaskPage/TaskApps.tsx b/site/src/pages/TaskPage/TaskApps.tsx index 7954447853c1e..44b2917986e50 100644 --- a/site/src/pages/TaskPage/TaskApps.tsx +++ b/site/src/pages/TaskPage/TaskApps.tsx @@ -33,11 +33,12 @@ export const TaskApps: FC = ({ task }) => { .filter((a) => !!a && a.slug !== AI_APP_CHAT_SLUG); const [activeAppId, setActiveAppId] = useState(() => { - const appId = task.workspace.latest_app_status?.app_id; - if (!appId) { - throw new Error("No active app found in task"); + // Use the first app in order instead of the most recently active app + const firstApp = apps[0]; + if (!firstApp) { + throw new Error("No apps found in task"); } - return appId; + return firstApp.id; }); const activeApp = apps.find((app) => app.id === activeAppId); diff --git a/site/src/pages/TasksPage/TasksPage.tsx b/site/src/pages/TasksPage/TasksPage.tsx index c12436c109996..88b37769f9730 100644 --- a/site/src/pages/TasksPage/TasksPage.tsx +++ b/site/src/pages/TasksPage/TasksPage.tsx @@ -39,6 +39,7 @@ import { Link as RouterLink } from "react-router-dom"; import TextareaAutosize from "react-textarea-autosize"; import { pageTitle } from "utils/page"; import { relativeTime } from "utils/time"; +import { AI_APP_CHAT_SLUG } from "../TaskPage/constants"; import { type UserOption, UsersCombobox } from "./UsersCombobox"; type TasksFilter = { @@ -328,11 +329,33 @@ const TasksTable: FC = ({ templates, filter }) => { tasks.map(({ workspace, prompt }) => { const templateDisplayName = workspace.template_display_name ?? workspace.template_name; - const status = workspace.latest_app_status; + + // Get all apps from all agents, excluding the chat UI app + const allApps = workspace.latest_build.resources + .flatMap((r) => r.agents) + .filter((a) => !!a) + .flatMap((a) => a.apps) + .filter((app) => app.slug !== AI_APP_CHAT_SLUG); + + // Use the first app in order instead of the most recently active app + const focusedApp = allApps[0]; + + // Find the agent that contains the focused app const agent = workspace.latest_build.resources .flatMap((r) => r.agents) - .find((a) => a?.id === status?.agent_id); - const app = agent?.apps.find((a) => a.id === status?.app_id); + .filter((a) => !!a) + .find((a) => a.apps.some((app) => app.id === focusedApp?.id)); + + // Create a status object for the focused app, or fall back to latest_app_status + const status = focusedApp + ? { + ...workspace.latest_app_status, + app_id: focusedApp.id, + agent_id: agent?.id || workspace.latest_app_status?.agent_id, + } + : workspace.latest_app_status; + + const app = focusedApp; return (