Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): agent activity sometimes broken links (#10480)

Ubbe7373b472de6b
diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/components/ActivityItem.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/components/ActivityItem.tsx
index 20cd4ee7f5..d5820ae035 100644
--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/components/ActivityItem.tsx
+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/components/ActivityItem.tsx
@@ -80,11 +80,15 @@ export function ActivityItem({ execution }: Props) {
}
const agentId = execution.library_agent_id || execution.graph_id;
+ const linkUrl = `/library/agents/${agentId}?executionId=${execution.id}`;
+ const withLibraryId = !!execution.library_agent_id;
+
+ if (!withLibraryId) return null;
return (
<Link
className="block cursor-pointer border-b border-slate-50 px-2 py-3 transition-colors last:border-b-0 hover:bg-lightGrey"
- href={`/library/agents/${agentId}?executionId=${execution.id}`}
+ href={linkUrl}
role="button"
>
{/* Icon + Agent Name */}
diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/helpers.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/helpers.tsx
index 00ea8183bd..74bfc05886 100644
--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/helpers.tsx
+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/helpers.tsx
@@ -99,9 +99,14 @@ export function createAgentInfoMap(
>();
agents.forEach((agent) => {
+ // Ensure we have valid agent data
+ const agentName =
+ agent.agent_name || `Agent ${agent.agent_id?.slice(0, 8)}`;
+ const agentDescription = agent.description || "";
+
agentMap.set(agent.agent_id, {
- name: agent.agent_name,
- description: agent.description,
+ name: agentName,
+ description: agentDescription,
library_agent_id: undefined, // MyAgent doesn't have library_agent_id
});
});
diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/useAgentActivityDropdown.ts b/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/useAgentActivityDropdown.ts
index 2f075b4990..8f734aa0ba 100644
--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/useAgentActivityDropdown.ts
+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AgentActivityDropdown/useAgentActivityDropdown.ts
@@ -2,8 +2,11 @@ import { useGetV1GetAllExecutions } from "@/app/api/__generated__/endpoints/grap
import { useGetV2GetMyAgents } from "@/app/api/__generated__/endpoints/store/store";
import { useGetV2ListLibraryAgents } from "@/app/api/__generated__/endpoints/library/library";
import { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
+import { LibraryAgentResponse } from "@/app/api/__generated__/models/libraryAgentResponse";
+import { MyAgentsResponse } from "@/app/api/__generated__/models/myAgentsResponse";
+import { MyAgent } from "@/app/api/__generated__/models/myAgent";
import BackendAPI from "@/lib/autogpt-server-api/client";
-import type { GraphExecution } from "@/lib/autogpt-server-api/types";
+import type { GraphExecution, GraphID } from "@/lib/autogpt-server-api/types";
import { useCallback, useEffect, useState } from "react";
import {
NotificationState,
@@ -70,29 +73,27 @@ export function useAgentActivityDropdown() {
// Update agent info map when both agent data sources change
useEffect(() => {
- if (
- myAgentsResponse?.data &&
- "agents" in myAgentsResponse.data &&
- myAgentsResponse?.data?.agents &&
- libraryAgentsResponse?.data &&
- "agents" in libraryAgentsResponse.data
- ) {
- const agentMap = createAgentInfoMap(myAgentsResponse.data.agents);
-
- // Add library agent ID mapping
- libraryAgentsResponse.data.agents.forEach(
- (libraryAgent: LibraryAgent) => {
- const existingInfo = agentMap.get(libraryAgent.graph_id);
- if (existingInfo) {
- agentMap.set(libraryAgent.graph_id, {
- ...existingInfo,
- library_agent_id: libraryAgent.id,
- });
+ if (myAgentsResponse?.data && libraryAgentsResponse?.data) {
+ const myAgents = myAgentsResponse.data as MyAgentsResponse;
+ const libraryAgents = libraryAgentsResponse.data as LibraryAgentResponse;
+
+ if (myAgents?.agents && libraryAgents?.agents) {
+ const agentMap = createAgentInfoMap(myAgents.agents);
+
+ libraryAgents.agents.forEach((libraryAgent: LibraryAgent) => {
+ if (libraryAgent.graph_id && libraryAgent.id) {
+ const existingInfo = agentMap.get(libraryAgent.graph_id);
+ if (existingInfo) {
+ agentMap.set(libraryAgent.graph_id, {
+ ...existingInfo,
+ library_agent_id: libraryAgent.id,
+ });
+ }
}
- },
- );
+ });
- setAgentInfoMap(agentMap);
+ setAgentInfoMap(agentMap);
+ }
}
}, [myAgentsResponse, libraryAgentsResponse]);
@@ -127,18 +128,21 @@ export function useAgentActivityDropdown() {
const connectHandler = api.onWebSocketConnect(() => {
setIsConnected(true);
- // Subscribe to graph executions for all user agents
- if (myAgentsResponse?.data && "agents" in myAgentsResponse.data) {
- myAgentsResponse.data.agents.forEach((agent) => {
- api
- .subscribeToGraphExecutions(agent.agent_id as any)
- .catch((error) => {
- console.error(
- `[AgentNotifications] Failed to subscribe to graph ${agent.agent_id}:`,
- error,
- );
- });
- });
+ if (myAgentsResponse?.data) {
+ const myAgents = myAgentsResponse.data as MyAgentsResponse;
+
+ if (myAgents?.agents) {
+ myAgents.agents.forEach((agent: MyAgent) => {
+ api
+ .subscribeToGraphExecutions(agent.agent_id as GraphID)
+ .catch((error) => {
+ console.error(
+ `[AgentNotifications] Failed to subscribe to graph ${agent.agent_id}:`,
+ error,
+ );
+ });
+ });
+ }
}
});