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): delete actions behind dialogs in agent runs view (#10915)

Ubbe7c2df24d7ccc
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/AgentActionsDropdown.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/AgentActionsDropdown.tsx
new file mode 100644
index 0000000000..0c8a1400c5
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/AgentActionsDropdown.tsx
@@ -0,0 +1,152 @@
+"use client";
+
+import React, { useState } from "react";
+import { Button } from "@/components/atoms/Button/Button";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from "@/components/molecules/DropdownMenu/DropdownMenu";
+import Link from "next/link";
+import {
+ FileArrowDownIcon,
+ PencilSimpleIcon,
+ TrashIcon,
+} from "@phosphor-icons/react";
+import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
+import { getV1GetGraphVersion } from "@/app/api/__generated__/endpoints/graphs/graphs";
+import { exportAsJSONFile } from "@/lib/utils";
+import { useToast } from "@/components/molecules/Toast/use-toast";
+import { Dialog } from "@/components/molecules/Dialog/Dialog";
+import { useRouter } from "next/navigation";
+import { useDeleteV2DeleteLibraryAgent } from "@/app/api/__generated__/endpoints/library/library";
+import { Text } from "@/components/atoms/Text/Text";
+
+interface Props {
+ agent: LibraryAgent;
+}
+
+export function AgentActionsDropdown({ agent }: Props) {
+ const { toast } = useToast();
+ const { mutateAsync: deleteAgent } = useDeleteV2DeleteLibraryAgent();
+ const router = useRouter();
+ const [isDeleting, setIsDeleting] = useState(false);
+ const [showDeleteDialog, setShowDeleteDialog] = useState(false);
+
+ async function handleDelete() {
+ if (!agent.id) return;
+
+ setIsDeleting(true);
+
+ try {
+ await deleteAgent({ libraryAgentId: agent.id });
+ toast({ title: "Agent deleted" });
+ setShowDeleteDialog(false);
+ router.push("/library");
+ } catch (error: unknown) {
+ toast({
+ title: "Failed to delete agent",
+ description:
+ error instanceof Error
+ ? error.message
+ : "An unexpected error occurred.",
+ variant: "destructive",
+ });
+ } finally {
+ setIsDeleting(false);
+ }
+ }
+
+ async function handleExport() {
+ try {
+ const res = await getV1GetGraphVersion(
+ agent.graph_id,
+ agent.graph_version,
+ { for_export: true },
+ );
+ if (res.status === 200) {
+ const filename = `${agent.name}_v${agent.graph_version}.json`;
+ exportAsJSONFile(res.data as any, filename);
+ toast({ title: "Agent exported" });
+ } else {
+ toast({ title: "Failed to export agent", variant: "destructive" });
+ }
+ } catch (e: any) {
+ toast({
+ title: "Failed to export agent",
+ description: e?.message,
+ variant: "destructive",
+ });
+ }
+ }
+
+ return (
+ <>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="secondary" size="small" className="min-w-fit">
+ •••
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem asChild>
+ <Link
+ href={`/build?flowID=${agent.graph_id}&flowVersion=${agent.graph_version}`}
+ target="_blank"
+ className="flex items-center gap-2"
+ >
+ <PencilSimpleIcon size={16} /> Edit agent
+ </Link>
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ onClick={handleExport}
+ className="flex items-center gap-2"
+ >
+ <FileArrowDownIcon size={16} /> Export agent to file
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ onClick={() => setShowDeleteDialog(true)}
+ className="flex items-center gap-2"
+ >
+ <TrashIcon size={16} /> Delete agent
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+
+ <Dialog
+ controlled={{
+ isOpen: showDeleteDialog,
+ set: setShowDeleteDialog,
+ }}
+ styling={{ maxWidth: "32rem" }}
+ title="Delete agent"
+ >
+ <Dialog.Content>
+ <div>
+ <Text variant="large">
+ Are you sure you want to delete this agent? This action cannot be
+ undone.
+ </Text>
+ <Dialog.Footer>
+ <Button
+ variant="secondary"
+ disabled={isDeleting}
+ onClick={() => setShowDeleteDialog(false)}
+ >
+ Cancel
+ </Button>
+ <Button
+ variant="destructive"
+ onClick={handleDelete}
+ loading={isDeleting}
+ >
+ Delete
+ </Button>
+ </Dialog.Footer>
+ </div>
+ </Dialog.Content>
+ </Dialog>
+ </>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/RunAgentModal.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/RunAgentModal.tsx
index e7618b83ba..23b8a83e64 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/RunAgentModal.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/RunAgentModal.tsx
@@ -8,9 +8,9 @@ import { useAgentRunModal } from "./useAgentRunModal";
import { ModalHeader } from "./components/ModalHeader/ModalHeader";
import { AgentCostSection } from "./components/AgentCostSection/AgentCostSection";
import { AgentSectionHeader } from "./components/AgentSectionHeader/AgentSectionHeader";
-import { DefaultRunView } from "./components/DefaultRunView/DefaultRunView";
+import { ModalRunSection } from "./components/ModalRunSection/DefaultRunView";
import { RunAgentModalContextProvider } from "./context";
-import { ScheduleView } from "./components/ScheduleView/ScheduleView";
+import { ModalScheduleSection } from "./components/ModalScheduleSection/ScheduleView";
import { AgentDetails } from "./components/AgentDetails/AgentDetails";
import { RunActions } from "./components/RunActions/RunActions";
import { ScheduleActions } from "./components/ScheduleActions/ScheduleActions";
@@ -155,7 +155,7 @@ export function RunAgentModal({ triggerSlot, agent }: Props) {
}
/>
<div>
- <DefaultRunView />
+ <ModalRunSection />
</div>
</>
</RunAgentModalContextProvider>
@@ -177,7 +177,7 @@ export function RunAgentModal({ triggerSlot, agent }: Props) {
Remove schedule
</Button>
</div>
- <ScheduleView
+ <ModalScheduleSection
scheduleName={scheduleName}
cronExpression={cronExpression}
recommendedScheduleCron={agent.recommended_schedule_cron}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/DefaultRunView/DefaultRunView.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalRunSection/DefaultRunView.tsx
similarity index 99%
rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/DefaultRunView/DefaultRunView.tsx
rename to autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalRunSection/DefaultRunView.tsx
index c6c1a6f407..844dad7959 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/DefaultRunView/DefaultRunView.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalRunSection/DefaultRunView.tsx
@@ -5,7 +5,7 @@ import { CredentialsInput } from "@/app/(platform)/library/agents/[id]/component
import { useRunAgentModalContext } from "../../context";
import { RunAgentInputs } from "../../../RunAgentInputs/RunAgentInputs";
-export function DefaultRunView() {
+export function ModalRunSection() {
const {
agent,
defaultRunType,
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/ScheduleView.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalScheduleSection/ScheduleView.tsx
similarity index 98%
rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/ScheduleView.tsx
rename to autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalScheduleSection/ScheduleView.tsx
index 2d6b97eb08..3db66a3d1c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/ScheduleView.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalScheduleSection/ScheduleView.tsx
@@ -14,7 +14,7 @@ interface Props {
onValidityChange?: (valid: boolean) => void;
}
-export function ScheduleView({
+export function ModalScheduleSection({
scheduleName,
cronExpression: _cronExpression,
recommendedScheduleCron,
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalScheduleSection/helpers.ts
similarity index 100%
rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/helpers.ts
rename to autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalScheduleSection/helpers.ts
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/useScheduleView.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalScheduleSection/useModalScheduleSection.ts
similarity index 95%
rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/useScheduleView.ts
rename to autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalScheduleSection/useModalScheduleSection.ts
index 274dda13bb..de52f43ac5 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/useScheduleView.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ModalScheduleSection/useModalScheduleSection.ts
@@ -1,12 +1,10 @@
import { useEffect, useMemo, useState } from "react";
-interface UseScheduleViewOptions {
+interface Args {
onCronExpressionChange: (expression: string) => void;
}
-export function useScheduleView({
- onCronExpressionChange,
-}: UseScheduleViewOptions) {
+export function useModalScheduleSection({ onCronExpressionChange }: Args) {
const repeatOptions = useMemo(
() => [
{ value: "daily", label: "Daily" },
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/RunDetailHeader.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/RunDetailHeader.tsx
index ccfd51d497..c9d2f1961c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/RunDetailHeader.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/RunDetailHeader.tsx
@@ -1,3 +1,4 @@
+import React from "react";
import { RunStatusBadge } from "../RunDetails/components/RunStatusBadge";
import { Text } from "@/components/atoms/Text/Text";
import { Button } from "@/components/atoms/Button/Button";
@@ -11,7 +12,8 @@ import { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
import moment from "moment";
import { GraphExecution } from "@/app/api/__generated__/models/graphExecution";
import { useRunDetailHeader } from "./useRunDetailHeader";
-import { AgentActions } from "./components/AgentActions";
+import { AgentActionsDropdown } from "../AgentActionsDropdown";
+import { Dialog } from "@/components/molecules/Dialog/Dialog";
type Props = {
agent: LibraryAgent;
@@ -29,15 +31,18 @@ export function RunDetailHeader({
onClearSelectedRun,
}: Props) {
const {
- stopRun,
canStop,
isStopping,
- deleteRun,
isDeleting,
- runAgain,
isRunningAgain,
openInBuilderHref,
+ showDeleteDialog,
+ handleStopRun,
+ handleRunAgain,
+ handleDeleteRun,
+ handleShowDeleteDialog,
} = useRunDetailHeader(agent.graph_id, run, onSelectRun, onClearSelectedRun);
+
return (
<div>
<div className="flex w-full items-center justify-between">
@@ -57,7 +62,7 @@ export function RunDetailHeader({
<Button
variant="secondary"
size="small"
- onClick={runAgain}
+ onClick={handleRunAgain}
loading={isRunningAgain}
>
<PlayIcon size={16} /> Run again
@@ -65,10 +70,9 @@ export function RunDetailHeader({
<Button
variant="secondary"
size="small"
- onClick={deleteRun}
- loading={isDeleting}
+ onClick={() => handleShowDeleteDialog(true)}
>
- <TrashIcon size={16} /> Delete run
+ <TrashIcon size={16} /> Delete
</Button>
{openInBuilderHref ? (
<Button
@@ -85,13 +89,13 @@ export function RunDetailHeader({
<Button
variant="destructive"
size="small"
- onClick={stopRun}
+ onClick={handleStopRun}
disabled={isStopping}
>
<StopIcon size={14} /> Stop run
</Button>
) : null}
- <AgentActions agent={agent} />
+ <AgentActionsDropdown agent={agent} />
</div>
) : null}
</div>
@@ -145,6 +149,40 @@ export function RunDetailHeader({
) : null}
</div>
</div>
+
+ <Dialog
+ controlled={{
+ isOpen: showDeleteDialog,
+ set: handleShowDeleteDialog,
+ }}
+ styling={{ maxWidth: "32rem" }}
+ title="Delete run"
+ >
+ <Dialog.Content>
+ <div>
+ <Text variant="large">
+ Are you sure you want to delete this run? This action cannot be
+ undone.
+ </Text>
+ <Dialog.Footer>
+ <Button
+ variant="secondary"
+ disabled={isDeleting}
+ onClick={() => handleShowDeleteDialog(false)}
+ >
+ Cancel
+ </Button>
+ <Button
+ variant="destructive"
+ onClick={handleDeleteRun}
+ loading={isDeleting}
+ >
+ Delete
+ </Button>
+ </Dialog.Footer>
+ </div>
+ </Dialog.Content>
+ </Dialog>
</div>
);
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/components/AgentActions.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/components/AgentActions.tsx
deleted file mode 100644
index 44e8698bb1..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/components/AgentActions.tsx
+++ /dev/null
@@ -1,111 +0,0 @@
-"use client";
-
-import React, { useCallback } from "react";
-import { Button } from "@/components/atoms/Button/Button";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "@/components/molecules/DropdownMenu/DropdownMenu";
-import Link from "next/link";
-import {
- FileArrowDownIcon,
- PencilSimpleIcon,
- TrashIcon,
-} from "@phosphor-icons/react";
-import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
-import { useRouter } from "next/navigation";
-import { useDeleteV2DeleteLibraryAgent } from "@/app/api/__generated__/endpoints/library/library";
-import { getV1GetGraphVersion } from "@/app/api/__generated__/endpoints/graphs/graphs";
-import { exportAsJSONFile } from "@/lib/utils";
-import { useToast } from "@/components/molecules/Toast/use-toast";
-
-interface AgentActionsProps {
- agent: LibraryAgent;
-}
-
-export function AgentActions({ agent }: AgentActionsProps) {
- const router = useRouter();
- const { toast } = useToast();
- const deleteMutation = useDeleteV2DeleteLibraryAgent();
-
- const handleExport = useCallback(async () => {
- try {
- const res = await getV1GetGraphVersion(
- agent.graph_id,
- agent.graph_version,
- { for_export: true },
- );
- if (res.status === 200) {
- const filename = `${agent.name}_v${agent.graph_version}.json`;
- exportAsJSONFile(res.data as any, filename);
- toast({ title: "Agent exported" });
- } else {
- toast({ title: "Failed to export agent", variant: "destructive" });
- }
- } catch (e: any) {
- toast({
- title: "Failed to export agent",
- description: e?.message,
- variant: "destructive",
- });
- }
- }, [agent.graph_id, agent.graph_version, agent.name, toast]);
-
- const handleDelete = useCallback(() => {
- if (!agent?.id) return;
- const confirmed = window.confirm(
- "Are you sure you want to delete this agent? This action cannot be undone.",
- );
- if (!confirmed) return;
- deleteMutation.mutate(
- { libraryAgentId: agent.id },
- {
- onSuccess: () => {
- toast({ title: "Agent deleted" });
- router.push("/library");
- },
- onError: (error: any) =>
- toast({
- title: "Failed to delete agent",
- description: error?.message,
- variant: "destructive",
- }),
- },
- );
- }, [agent.id, deleteMutation, router, toast]);
-
- return (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="secondary" size="small">
- •••
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem asChild>
- <Link
- href={`/build?flowID=${agent.graph_id}&flowVersion=${agent.graph_version}`}
- target="_blank"
- className="flex items-center gap-2"
- >
- <PencilSimpleIcon size={16} /> Edit agent
- </Link>
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={handleExport}
- className="flex items-center gap-2"
- >
- <FileArrowDownIcon size={16} /> Export agent to file
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={handleDelete}
- className="flex items-center gap-2"
- >
- <TrashIcon size={16} /> Delete agent
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- );
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/useRunDetailHeader.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/useRunDetailHeader.ts
index a1bca31d8b..942429b61b 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/useRunDetailHeader.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunDetailHeader/useRunDetailHeader.ts
@@ -9,6 +9,7 @@ import {
import { useDeleteV1DeleteGraphExecution } from "@/app/api/__generated__/endpoints/graphs/graphs";
import { usePostV1ExecuteGraphAgent } from "@/app/api/__generated__/endpoints/graphs/graphs";
import type { GraphExecution } from "@/app/api/__generated__/models/graphExecution";
+import { useState } from "react";
export function useRunDetailHeader(
agentGraphId: string,
@@ -19,92 +20,117 @@ export function useRunDetailHeader(
const queryClient = useQueryClient();
const { toast } = useToast();
- const stopMutation = usePostV1StopGraphExecution({
- mutation: {
- onSuccess: () => {
- toast({ title: "Run stopped" });
- queryClient.invalidateQueries({
- queryKey:
- getGetV1ListGraphExecutionsInfiniteQueryOptions(agentGraphId)
- .queryKey,
- });
- },
- onError: (error: any) => {
- toast({
- title: "Failed to stop run",
- description: error?.message || "An unexpected error occurred.",
- variant: "destructive",
- });
- },
- },
- });
-
- function stopRun() {
- if (!run) return;
- stopMutation.mutate({ graphId: run.graph_id, graphExecId: run.id });
- }
+ const [showDeleteDialog, setShowDeleteDialog] = useState(false);
const canStop = run?.status === "RUNNING" || run?.status === "QUEUED";
- // Delete run
- const deleteMutation = useDeleteV1DeleteGraphExecution({
- mutation: {
- onSuccess: () => {
- toast({ title: "Run deleted" });
- queryClient.invalidateQueries({
- queryKey:
- getGetV1ListGraphExecutionsInfiniteQueryOptions(agentGraphId)
- .queryKey,
- });
- if (onClearSelectedRun) onClearSelectedRun();
- },
- onError: (error: any) =>
- toast({
- title: "Failed to delete run",
- description: error?.message || "An unexpected error occurred.",
- variant: "destructive",
- }),
- },
- });
-
- function deleteRun() {
- if (!run) return;
- deleteMutation.mutate({ graphExecId: run.id });
+ const { mutateAsync: stopRun, isPending: isStopping } =
+ usePostV1StopGraphExecution();
+
+ const { mutateAsync: deleteRun, isPending: isDeleting } =
+ useDeleteV1DeleteGraphExecution();
+
+ const { mutateAsync: executeRun, isPending: isRunningAgain } =
+ usePostV1ExecuteGraphAgent();
+
+ async function handleDeleteRun() {
+ try {
+ await deleteRun({ graphExecId: run?.id ?? "" });
+
+ toast({ title: "Run deleted" });
+
+ await queryClient.refetchQueries({
+ queryKey:
+ getGetV1ListGraphExecutionsInfiniteQueryOptions(agentGraphId)
+ .queryKey,
+ });
+
+ if (onClearSelectedRun) onClearSelectedRun();
+
+ setShowDeleteDialog(false);
+ } catch (error: unknown) {
+ toast({
+ title: "Failed to delete run",
+ description:
+ error instanceof Error
+ ? error.message
+ : "An unexpected error occurred.",
+ variant: "destructive",
+ });
+ }
}
- // Run again (execute agent with previous inputs/credentials)
- const executeMutation = usePostV1ExecuteGraphAgent({
- mutation: {
- onSuccess: async (res) => {
- toast({ title: "Run started" });
- const newRunId = res?.status === 200 ? (res?.data?.id ?? "") : "";
-
- await queryClient.invalidateQueries({
- queryKey:
- getGetV1ListGraphExecutionsInfiniteQueryOptions(agentGraphId)
- .queryKey,
- });
- if (newRunId && onSelectRun) onSelectRun(newRunId);
- },
- onError: (error: any) =>
- toast({
- title: "Failed to start run",
- description: error?.message || "An unexpected error occurred.",
- variant: "destructive",
- }),
- },
- });
-
- function runAgain() {
- if (!run) return;
- executeMutation.mutate({
- graphId: run.graph_id,
- graphVersion: run.graph_version,
- data: {
- inputs: (run as any).inputs || {},
- credentials_inputs: (run as any).credential_inputs || {},
- },
- } as any);
+ async function handleStopRun() {
+ try {
+ await stopRun({
+ graphId: run?.graph_id ?? "",
+ graphExecId: run?.id ?? "",
+ });
+
+ toast({ title: "Run stopped" });
+
+ await queryClient.invalidateQueries({
+ queryKey:
+ getGetV1ListGraphExecutionsInfiniteQueryOptions(agentGraphId)
+ .queryKey,
+ });
+ } catch (error: unknown) {
+ toast({
+ title: "Failed to stop run",
+ description:
+ error instanceof Error
+ ? error.message
+ : "An unexpected error occurred.",
+ variant: "destructive",
+ });
+ }
+ }
+
+ async function handleRunAgain() {
+ if (!run) {
+ toast({
+ title: "Run not found",
+ description: "Run not found",
+ variant: "destructive",
+ });
+ return;
+ }
+
+ try {
+ toast({ title: "Run started" });
+
+ const res = await executeRun({
+ graphId: run.graph_id,
+ graphVersion: run.graph_version,
+ data: {
+ inputs: (run as any).inputs || {},
+ credentials_inputs: (run as any).credential_inputs || {},
+ },
+ });
+
+ const newRunId = res?.status === 200 ? (res?.data?.id ?? "") : "";
+
+ await queryClient.invalidateQueries({
+ queryKey:
+ getGetV1ListGraphExecutionsInfiniteQueryOptions(agentGraphId)
+ .queryKey,
+ });
+
+ if (newRunId && onSelectRun) onSelectRun(newRunId);
+ } catch (error: unknown) {
+ toast({
+ title: "Failed to start run",
+ description:
+ error instanceof Error
+ ? error.message
+ : "An unexpected error occurred.",
+ variant: "destructive",
+ });
+ }
+ }
+
+ function handleShowDeleteDialog(open: boolean) {
+ setShowDeleteDialog(open);
}
// Open in builder URL helper
@@ -113,13 +139,15 @@ export function useRunDetailHeader(
: undefined;
return {
- stopRun,
- canStop,
- isStopping: stopMutation.isPending,
- deleteRun,
- isDeleting: deleteMutation.isPending,
- runAgain,
- isRunningAgain: executeMutation.isPending,
openInBuilderHref,
+ showDeleteDialog,
+ canStop,
+ isStopping,
+ isDeleting,
+ isRunningAgain,
+ handleShowDeleteDialog,
+ handleDeleteRun,
+ handleStopRun,
+ handleRunAgain,
} as const;
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/ScheduleDetails.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/ScheduleDetails.tsx
index 9cd20aa6c2..851ce9cad9 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/ScheduleDetails.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/ScheduleDetails.tsx
@@ -13,22 +13,12 @@ import {
import { useScheduleDetails } from "./useScheduleDetails";
import { RunDetailCard } from "../RunDetailCard/RunDetailCard";
import { RunDetailHeader } from "../RunDetailHeader/RunDetailHeader";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "@/components/molecules/DropdownMenu/DropdownMenu";
-import { PencilSimpleIcon, ArrowSquareOut } from "@phosphor-icons/react";
-import Link from "next/link";
-import { useScheduleDetailHeader } from "../RunDetailHeader/useScheduleDetailHeader";
-import { DeleteScheduleButton } from "./components/DeleteScheduleButton/DeleteScheduleButton";
import { humanizeCronExpression } from "@/lib/cron-expression-utils";
import { useGetV1GetUserTimezone } from "@/app/api/__generated__/endpoints/auth/auth";
import { formatInTimezone, getTimezoneDisplayName } from "@/lib/timezone-utils";
import { Skeleton } from "@/components/ui/skeleton";
import { AgentInputsReadOnly } from "../AgentInputsReadOnly/AgentInputsReadOnly";
-import { Button } from "@/components/atoms/Button/Button";
+import { ScheduleActions } from "./components/ScheduleActions";
interface ScheduleDetailsProps {
agent: LibraryAgent;
@@ -104,14 +94,11 @@ export function ScheduleDetails({
/>
</div>
{schedule ? (
- <div className="flex items-center gap-2">
- <DeleteScheduleButton
- agent={agent}
- scheduleId={schedule.id}
- onDeleted={onClearSelectedRun}
- />
- <ScheduleActions agent={agent} scheduleId={schedule.id} />
- </div>
+ <ScheduleActions
+ agent={agent}
+ scheduleId={schedule.id}
+ onDeleted={onClearSelectedRun}
+ />
) : null}
</div>
</div>
@@ -199,50 +186,3 @@ export function ScheduleDetails({
</div>
);
}
-
-function ScheduleActions({
- agent,
- scheduleId,
-}: {
- agent: LibraryAgent;
- scheduleId: string;
-}) {
- const { openInBuilderHref } = useScheduleDetailHeader(
- agent.graph_id,
- scheduleId,
- agent.graph_version,
- );
- return (
- <div className="flex items-center gap-2">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="secondary" size="small">
- •••
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {openInBuilderHref ? (
- <DropdownMenuItem asChild>
- <Link
- href={openInBuilderHref}
- target="_blank"
- className="flex items-center gap-2"
- >
- <ArrowSquareOut size={14} /> Open in builder
- </Link>
- </DropdownMenuItem>
- ) : null}
- <DropdownMenuItem asChild>
- <Link
- href={`/build?flowID=${agent.graph_id}&flowVersion=${agent.graph_version}`}
- target="_blank"
- className="flex items-center gap-2"
- >
- <PencilSimpleIcon size={16} /> Edit agent
- </Link>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
- );
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/components/EditScheduleModal/useEditScheduleModal.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/components/EditScheduleModal/useEditScheduleModal.ts
index e198612c13..e58d9db21a 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/components/EditScheduleModal/useEditScheduleModal.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/components/EditScheduleModal/useEditScheduleModal.ts
@@ -7,7 +7,7 @@ import { getGetV1ListGraphExecutionsInfiniteQueryOptions } from "@/app/api/__gen
import {
parseCronToForm,
validateSchedule,
-} from "../../../RunAgentModal/components/ScheduleView/helpers";
+} from "../../../RunAgentModal/components/ModalScheduleSection/helpers";
import type { GraphExecutionJobInfo } from "@/app/api/__generated__/models/graphExecutionJobInfo";
import { useToast } from "@/components/molecules/Toast/use-toast";
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/components/ScheduleActions.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/components/ScheduleActions.tsx
new file mode 100644
index 0000000000..2e21ccc2b3
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/components/ScheduleActions.tsx
@@ -0,0 +1,119 @@
+import { useScheduleDetailHeader } from "../../RunDetailHeader/useScheduleDetailHeader";
+import { useDeleteV1DeleteExecutionSchedule } from "@/app/api/__generated__/endpoints/schedules/schedules";
+import { useToast } from "@/components/molecules/Toast/use-toast";
+import { useState } from "react";
+import { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
+import { Button } from "@/components/atoms/Button/Button";
+import { Text } from "@/components/atoms/Text/Text";
+import { Dialog } from "@/components/molecules/Dialog/Dialog";
+import {
+ ArrowSquareOut,
+ PencilSimpleIcon,
+ TrashIcon,
+} from "@phosphor-icons/react";
+
+type Props = {
+ agent: LibraryAgent;
+ scheduleId: string;
+ onDeleted?: () => void;
+};
+
+export function ScheduleActions({ agent, scheduleId, onDeleted }: Props) {
+ const { toast } = useToast();
+ const { mutateAsync: deleteSchedule } = useDeleteV1DeleteExecutionSchedule();
+ const [isDeleting, setIsDeleting] = useState(false);
+ const [showDeleteDialog, setShowDeleteDialog] = useState(false);
+
+ const { openInBuilderHref } = useScheduleDetailHeader(
+ agent.graph_id,
+ scheduleId,
+ agent.graph_version,
+ );
+
+ async function handleDelete() {
+ setIsDeleting(true);
+ try {
+ await deleteSchedule({ scheduleId });
+ toast({ title: "Schedule deleted" });
+ setShowDeleteDialog(false);
+ if (onDeleted) onDeleted();
+ } catch (error: unknown) {
+ toast({
+ title: "Failed to delete schedule",
+ description:
+ error instanceof Error
+ ? error.message
+ : "An unexpected error occurred.",
+ variant: "destructive",
+ });
+ } finally {
+ setIsDeleting(false);
+ }
+ }
+
+ return (
+ <>
+ <div className="flex items-center gap-2">
+ {openInBuilderHref && (
+ <Button
+ variant="secondary"
+ size="small"
+ as="NextLink"
+ href={openInBuilderHref}
+ >
+ <ArrowSquareOut size={14} /> Open in builder
+ </Button>
+ )}
+ <Button
+ variant="secondary"
+ size="small"
+ as="NextLink"
+ href={`/build?flowID=${agent.graph_id}&flowVersion=${agent.graph_version}`}
+ >
+ <PencilSimpleIcon size={16} /> Edit agent
+ </Button>
+ <Button
+ variant="secondary"
+ size="small"
+ onClick={() => setShowDeleteDialog(true)}
+ >
+ <TrashIcon size={16} /> Delete
+ </Button>
+ </div>
+
+ <Dialog
+ controlled={{
+ isOpen: showDeleteDialog,
+ set: setShowDeleteDialog,
+ }}
+ styling={{ maxWidth: "32rem" }}
+ title="Delete schedule"
+ >
+ <Dialog.Content>
+ <div>
+ <Text variant="large">
+ Are you sure you want to delete this schedule? This action cannot
+ be undone.
+ </Text>
+ <Dialog.Footer>
+ <Button
+ variant="secondary"
+ disabled={isDeleting}
+ onClick={() => setShowDeleteDialog(false)}
+ >
+ Cancel
+ </Button>
+ <Button
+ variant="destructive"
+ onClick={handleDelete}
+ loading={isDeleting}
+ >
+ Delete
+ </Button>
+ </Dialog.Footer>
+ </div>
+ </Dialog.Content>
+ </Dialog>
+ </>
+ );
+}
diff --git a/autogpt_platform/frontend/src/components/atoms/Button/helpers.ts b/autogpt_platform/frontend/src/components/atoms/Button/helpers.ts
index 80674c3acd..08c2932c59 100644
--- a/autogpt_platform/frontend/src/components/atoms/Button/helpers.ts
+++ b/autogpt_platform/frontend/src/components/atoms/Button/helpers.ts
@@ -3,7 +3,7 @@ import { LinkProps } from "next/link";
// Extended button variants based on our design system
export const extendedButtonVariants = cva(
- "inline-flex items-center justify-center whitespace-nowrap font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:pointer-events-none disabled:opacity-50 font-sans leading-snug border",
+ "inline-flex items-center justify-center whitespace-nowrap font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:pointer-events-none disabled:opacity-50 font-sans leading-snug border min-w-[7.7rem]",
{
variants: {
variant: {
@@ -17,12 +17,12 @@ export const extendedButtonVariants = cva(
"bg-transparent border-zinc-700 text-black hover:bg-zinc-100 hover:border-zinc-700 rounded-full disabled:border-zinc-200 disabled:text-zinc-200 disabled:opacity-1",
ghost:
"bg-transparent border-transparent text-black hover:bg-zinc-50 hover:border-zinc-50 rounded-full disabled:text-zinc-200 disabled:opacity-1",
- icon: "bg-white text-black border border-zinc-600 hover:bg-zinc-100 rounded-[96px] disabled:opacity-1",
+ icon: "bg-white text-black border border-zinc-600 hover:bg-zinc-100 rounded-[96px] disabled:opacity-1 min-w-0",
},
size: {
small: "px-3 py-2 text-sm gap-1.5 h-[2.25rem]",
- large: "min-w-20 px-4 py-3 text-sm gap-2",
- icon: "p-3",
+ large: "px-4 py-3 text-sm gap-2",
+ icon: "p-3 min-w-0",
},
},
defaultVariants: {
diff --git a/autogpt_platform/frontend/src/components/atoms/Button/helpers.tsx b/autogpt_platform/frontend/src/components/atoms/Button/helpers.tsx
deleted file mode 100644
index 80674c3acd..0000000000
--- a/autogpt_platform/frontend/src/components/atoms/Button/helpers.tsx
+++ /dev/null
@@ -1,55 +0,0 @@
-import { cva, VariantProps } from "class-variance-authority";
-import { LinkProps } from "next/link";
-
-// Extended button variants based on our design system
-export const extendedButtonVariants = cva(
- "inline-flex items-center justify-center whitespace-nowrap font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:pointer-events-none disabled:opacity-50 font-sans leading-snug border",
- {
- variants: {
- variant: {
- primary:
- "bg-zinc-800 border-zinc-800 text-white hover:bg-zinc-900 hover:border-zinc-900 rounded-full disabled:text-white disabled:bg-zinc-200 disabled:border-zinc-200 disabled:opacity-1",
- secondary:
- "bg-zinc-100 border-zinc-100 text-black hover:bg-zinc-300 hover:border-zinc-300 rounded-full disabled:text-zinc-300 disabled:bg-zinc-50 disabled:border-zinc-50 disabled:opacity-1",
- destructive:
- "bg-red-500 border-red-500 text-white hover:bg-red-600 hover:border-red-600 rounded-full disabled:text-white disabled:bg-zinc-200 disabled:border-zinc-200 disabled:opacity-1",
- outline:
- "bg-transparent border-zinc-700 text-black hover:bg-zinc-100 hover:border-zinc-700 rounded-full disabled:border-zinc-200 disabled:text-zinc-200 disabled:opacity-1",
- ghost:
- "bg-transparent border-transparent text-black hover:bg-zinc-50 hover:border-zinc-50 rounded-full disabled:text-zinc-200 disabled:opacity-1",
- icon: "bg-white text-black border border-zinc-600 hover:bg-zinc-100 rounded-[96px] disabled:opacity-1",
- },
- size: {
- small: "px-3 py-2 text-sm gap-1.5 h-[2.25rem]",
- large: "min-w-20 px-4 py-3 text-sm gap-2",
- icon: "p-3",
- },
- },
- defaultVariants: {
- variant: "primary",
- size: "large",
- },
- },
-);
-
-type BaseButtonProps = {
- loading?: boolean;
- leftIcon?: React.ReactNode;
- rightIcon?: React.ReactNode;
- asChild?: boolean;
-} & VariantProps<typeof extendedButtonVariants>;
-
-type ButtonAsButton = BaseButtonProps &
- React.ButtonHTMLAttributes<HTMLButtonElement> & {
- as?: "button";
- href?: never;
- };
-
-type ButtonAsLink = BaseButtonProps &
- Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof LinkProps> &
- LinkProps & {
- as: "NextLink";
- disabled?: boolean;
- };
-
-export type ButtonProps = ButtonAsButton | ButtonAsLink;