- {agents.map((agent) => (
+ {myAgents.map((agent) => (
(null);
- const { data: myAgents, isLoading, error } = useGetV2GetMyAgents();
-
- const agents: Agent[] =
- (myAgents?.status === 200 &&
- myAgents.data.agents
- .map(
- (agent): Agent => ({
- name: agent.agent_name,
- id: agent.agent_id,
- version: agent.agent_version,
- lastEdited: agent.last_edited.toLocaleDateString(),
- imageSrc: agent.agent_image || "https://picsum.photos/300/200",
- description: agent.description || "",
- recommendedScheduleCron: agent.recommended_schedule_cron ?? null,
- }),
- )
- .sort(
- (a: Agent, b: Agent) =>
- new Date(b.lastEdited).getTime() - new Date(a.lastEdited).getTime(),
- )) ||
- [];
+ const {
+ data: _myAgents,
+ isLoading,
+ error,
+ } = useGetV2GetMyAgents(undefined, {
+ query: {
+ select: (res) =>
+ okData(res)
+ ?.agents.map(
+ (agent): Agent => ({
+ name: agent.agent_name,
+ id: agent.agent_id,
+ version: agent.agent_version,
+ lastEdited: agent.last_edited.toLocaleDateString(),
+ imageSrc: agent.agent_image || "https://picsum.photos/300/200",
+ description: agent.description || "",
+ recommendedScheduleCron: agent.recommended_schedule_cron ?? null,
+ }),
+ )
+ .sort(
+ (a: Agent, b: Agent) =>
+ new Date(b.lastEdited).getTime() -
+ new Date(a.lastEdited).getTime(),
+ ),
+ },
+ });
+ const myAgents = _myAgents ?? [];
const handleAgentClick = (
_: string,
@@ -70,7 +77,7 @@ export function useAgentSelectStep({
const handleNext = () => {
if (selectedAgentId && selectedAgentVersion) {
- const selectedAgent = agents.find(
+ const selectedAgent = myAgents.find(
(agent) => agent.id === selectedAgentId,
);
if (selectedAgent) {
@@ -86,7 +93,7 @@ export function useAgentSelectStep({
return {
// Data
- agents,
+ myAgents,
isLoading,
error,
// State
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 df8402906b..9dbd8aaf7e 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
@@ -4,6 +4,7 @@ import { useExecutionEvents } from "@/hooks/useExecutionEvents";
import { useLibraryAgents } from "@/hooks/useLibraryAgents/useLibraryAgents";
import type { GraphExecution } from "@/lib/autogpt-server-api/types";
import { useCallback, useEffect, useMemo, useState } from "react";
+import { okData } from "@/app/api/helpers";
import {
NotificationState,
categorizeExecutions,
@@ -26,7 +27,7 @@ export function useAgentActivityDropdown() {
isSuccess: executionsSuccess,
error: executionsError,
} = useGetV1ListAllExecutions({
- query: { select: (res) => (res.status === 200 ? res.data : null) },
+ query: { select: okData },
});
// Get all graph IDs from agentInfoMap
diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/NavbarView.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/NavbarView.tsx
index 49790547e4..863b9f601f 100644
--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/NavbarView.tsx
+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/NavbarView.tsx
@@ -7,6 +7,7 @@ import { useBreakpoint } from "@/lib/hooks/useBreakpoint";
import { useSupabase } from "@/lib/supabase/hooks/useSupabase";
import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
import { useMemo } from "react";
+import { okData } from "@/app/api/helpers";
import { getAccountMenuItems, loggedInLinks, loggedOutLinks } from "../helpers";
import { AccountMenu } from "./AccountMenu/AccountMenu";
import { AgentActivityDropdown } from "./AgentActivityDropdown/AgentActivityDropdown";
@@ -29,7 +30,7 @@ export function NavbarView({ isLoggedIn, previewBranchName }: NavbarViewProps) {
const { data: profile, isLoading: isProfileLoading } = useGetV2GetUserProfile(
{
query: {
- select: (res) => (res.status === 200 ? res.data : null),
+ select: okData,
enabled: isLoggedIn && !!user,
// Include user ID in query key to ensure cache invalidation when user changes
queryKey: ["/api/store/profile", user?.id],
diff --git a/autogpt_platform/frontend/src/components/organisms/FloatingReviewsPanel/FloatingReviewsPanel.tsx b/autogpt_platform/frontend/src/components/organisms/FloatingReviewsPanel/FloatingReviewsPanel.tsx
index 12014e50fe..2b04c0ed9a 100644
--- a/autogpt_platform/frontend/src/components/organisms/FloatingReviewsPanel/FloatingReviewsPanel.tsx
+++ b/autogpt_platform/frontend/src/components/organisms/FloatingReviewsPanel/FloatingReviewsPanel.tsx
@@ -7,6 +7,7 @@ import { cn } from "@/lib/utils";
import { Text } from "@/components/atoms/Text/Text";
import { useGetV1GetExecutionDetails } from "@/app/api/__generated__/endpoints/graphs/graphs";
import { AgentExecutionStatus } from "@/app/api/__generated__/models/agentExecutionStatus";
+import { okData } from "@/app/api/helpers";
import { useGraphStore } from "@/app/(platform)/build/stores/graphStore";
import { useShallow } from "zustand/react/shallow";
@@ -29,13 +30,11 @@ export function FloatingReviewsPanel({
{
query: {
enabled: !!(graphId && executionId),
+ select: okData,
},
},
);
- const executionStatus =
- executionDetails?.status === 200 ? executionDetails.data.status : undefined;
-
// Get graph execution status from the store (updated via WebSocket)
const graphExecutionStatus = useGraphStore(
useShallow((state) => state.graphExecutionStatus),
@@ -49,7 +48,7 @@ export function FloatingReviewsPanel({
if (executionId) {
refetch();
}
- }, [executionStatus, executionId, refetch]);
+ }, [executionDetails?.status, executionId, refetch]);
// Refetch when graph execution status changes to REVIEW
useEffect(() => {
@@ -62,7 +61,7 @@ export function FloatingReviewsPanel({
!executionId ||
(!isLoading &&
pendingReviews.length === 0 &&
- executionStatus !== AgentExecutionStatus.REVIEW)
+ executionDetails?.status !== AgentExecutionStatus.REVIEW)
) {
return null;
}
diff --git a/autogpt_platform/frontend/src/components/organisms/PendingReviewsList/PendingReviewsList.tsx b/autogpt_platform/frontend/src/components/organisms/PendingReviewsList/PendingReviewsList.tsx
index ddc9bab972..3253b0ee6d 100644
--- a/autogpt_platform/frontend/src/components/organisms/PendingReviewsList/PendingReviewsList.tsx
+++ b/autogpt_platform/frontend/src/components/organisms/PendingReviewsList/PendingReviewsList.tsx
@@ -44,8 +44,8 @@ export function PendingReviewsList({
const reviewActionMutation = usePostV2ProcessReviewAction({
mutation: {
- onSuccess: (data: any) => {
- if (data.status !== 200) {
+ onSuccess: (res) => {
+ if (res.status !== 200) {
toast({
title: "Failed to process reviews",
description: "Unexpected response from server",
@@ -54,18 +54,18 @@ export function PendingReviewsList({
return;
}
- const response = data.data;
+ const result = res.data;
- if (response.failed_count > 0) {
+ if (result.failed_count > 0) {
toast({
title: "Reviews partially processed",
- description: `${response.approved_count + response.rejected_count} succeeded, ${response.failed_count} failed. ${response.error || "Some reviews could not be processed."}`,
+ description: `${result.approved_count + result.rejected_count} succeeded, ${result.failed_count} failed. ${result.error || "Some reviews could not be processed."}`,
variant: "destructive",
});
} else {
toast({
title: "Reviews processed successfully",
- description: `${response.approved_count} approved, ${response.rejected_count} rejected`,
+ description: `${result.approved_count} approved, ${result.rejected_count} rejected`,
variant: "default",
});
}
diff --git a/autogpt_platform/frontend/src/hooks/useAgentSafeMode.ts b/autogpt_platform/frontend/src/hooks/useAgentSafeMode.ts
index 654ef858b6..07a2b33674 100644
--- a/autogpt_platform/frontend/src/hooks/useAgentSafeMode.ts
+++ b/autogpt_platform/frontend/src/hooks/useAgentSafeMode.ts
@@ -7,6 +7,7 @@ import {
import { useToast } from "@/components/molecules/Toast/use-toast";
import { GraphModel } from "@/app/api/__generated__/models/graphModel";
import { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
+import { okData } from "@/app/api/helpers";
import { useQueryClient } from "@tanstack/react-query";
import { Graph } from "@/lib/autogpt-server-api/types";
@@ -47,15 +48,19 @@ export function useAgentSafeMode(graph: GraphModel | LibraryAgent | Graph) {
const { data: libraryAgent, isLoading } = useGetV2GetLibraryAgentByGraphId(
graphId,
{},
- { query: { enabled: !isAgent && shouldShowToggle } },
+ {
+ query: {
+ enabled: !isAgent && shouldShowToggle,
+ select: okData,
+ },
+ },
);
const [localSafeMode, setLocalSafeMode] = useState(null);
useEffect(() => {
- if (!isAgent && libraryAgent?.status === 200) {
- const backendValue =
- libraryAgent.data?.settings?.human_in_the_loop_safe_mode;
+ if (!isAgent && libraryAgent) {
+ const backendValue = libraryAgent.settings?.human_in_the_loop_safe_mode;
if (backendValue !== undefined) {
setLocalSafeMode(backendValue);
}
diff --git a/autogpt_platform/frontend/src/hooks/usePendingReviews.ts b/autogpt_platform/frontend/src/hooks/usePendingReviews.ts
index 111b50a491..8257814fcf 100644
--- a/autogpt_platform/frontend/src/hooks/usePendingReviews.ts
+++ b/autogpt_platform/frontend/src/hooks/usePendingReviews.ts
@@ -2,12 +2,13 @@ import {
useGetV2GetPendingReviews,
useGetV2GetPendingReviewsForExecution,
} from "@/app/api/__generated__/endpoints/executions/executions";
+import { okData } from "@/app/api/helpers";
export function usePendingReviews() {
const query = useGetV2GetPendingReviews();
return {
- pendingReviews: (query.data?.status === 200 ? query.data.data : []) || [],
+ pendingReviews: okData(query.data) || [],
isLoading: query.isLoading,
error: query.error,
refetch: query.refetch,
@@ -18,7 +19,7 @@ export function usePendingReviewsForExecution(graphExecId: string) {
const query = useGetV2GetPendingReviewsForExecution(graphExecId);
return {
- pendingReviews: (query.data?.status === 200 ? query.data.data : []) || [],
+ pendingReviews: okData(query.data) || [],
isLoading: query.isLoading,
error: query.error,
refetch: query.refetch,
diff --git a/autogpt_platform/frontend/src/lib/hooks/useUserTimezone.ts b/autogpt_platform/frontend/src/lib/hooks/useUserTimezone.ts
new file mode 100644
index 0000000000..7d5cef3a04
--- /dev/null
+++ b/autogpt_platform/frontend/src/lib/hooks/useUserTimezone.ts
@@ -0,0 +1,8 @@
+import { okData } from "@/app/api/helpers";
+import { useGetV1GetUserTimezone } from "@/app/api/__generated__/endpoints/auth/auth";
+
+export function useUserTimezone(): "not-set" | string | undefined {
+ return useGetV1GetUserTimezone({
+ query: { select: (res) => okData(res)?.timezone },
+ }).data;
+}
diff --git a/autogpt_platform/frontend/src/lib/react-query/queryClient.ts b/autogpt_platform/frontend/src/lib/react-query/queryClient.ts
index 836c505c2f..512629e65b 100644
--- a/autogpt_platform/frontend/src/lib/react-query/queryClient.ts
+++ b/autogpt_platform/frontend/src/lib/react-query/queryClient.ts
@@ -21,6 +21,10 @@ function makeQueryClient() {
let browserQueryClient: QueryClient | undefined = undefined;
+/** Only for use *outside client component context*
+ * (so in server components, API helpers, etc.).
+ *
+ * In the context of client components, you should always use `useQueryClient()`. */
export function getQueryClient() {
if (isServer) {
// Server: create new client every time (so one user's data doesn't leak to another)