Skip to content

fix: use first app in order instead of latest_app_status for focus in tasks #18239

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions site/src/pages/TaskPage/TaskApps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ export const TaskApps: FC<TaskAppsProps> = ({ task }) => {
.filter((a) => !!a && a.slug !== AI_APP_CHAT_SLUG);

const [activeAppId, setActiveAppId] = useState<string>(() => {
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);
Expand Down
29 changes: 26 additions & 3 deletions site/src/pages/TasksPage/TasksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -328,11 +329,33 @@ const TasksTable: FC<TasksTableProps> = ({ 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 (
<TableRow key={workspace.id} className="relative" hover>
Expand Down
Loading