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.

feat(frontend): add "Run now" button to schedule view (#12388)

Ubbefa04fb41d87d
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/NewAgentLibraryView.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/NewAgentLibraryView.tsx
index 090e6cb9c6..643788111f 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/NewAgentLibraryView.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/NewAgentLibraryView.tsx
@@ -209,6 +209,7 @@ export function NewAgentLibraryView() {
agent={agent}
scheduleId={activeItem}
onScheduleDeleted={handleScheduleDeleted}
+ onSelectRun={(id) => handleSelectRun(id, "runs")}
banner={renderMarketplaceUpdateBanner()}
/>
) : activeTab === "templates" ? (
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/SelectedScheduleView.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/SelectedScheduleView.tsx
index 613da5bc6f..14f9f6cf11 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/SelectedScheduleView.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/SelectedScheduleView.tsx
@@ -20,6 +20,7 @@ interface Props {
agent: LibraryAgent;
scheduleId: string;
onScheduleDeleted?: (deletedScheduleId: string) => void;
+ onSelectRun?: (id: string) => void;
banner?: React.ReactNode;
}
@@ -27,6 +28,7 @@ export function SelectedScheduleView({
agent,
scheduleId,
onScheduleDeleted,
+ onSelectRun,
banner,
}: Props) {
const { schedule, isLoading, error } = useSelectedScheduleView(
@@ -89,7 +91,9 @@ export function SelectedScheduleView({
<SelectedScheduleActions
agent={agent}
scheduleId={schedule.id}
+ schedule={schedule}
onDeleted={() => onScheduleDeleted?.(schedule.id)}
+ onSelectRun={onSelectRun}
/>
</div>
) : null}
@@ -168,7 +172,9 @@ export function SelectedScheduleView({
<SelectedScheduleActions
agent={agent}
scheduleId={schedule.id}
+ schedule={schedule}
onDeleted={() => onScheduleDeleted?.(schedule.id)}
+ onSelectRun={onSelectRun}
/>
</div>
) : null}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/SelectedScheduleActions.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/SelectedScheduleActions.tsx
index 9088cb112b..41cf20a1e9 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/SelectedScheduleActions.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/SelectedScheduleActions.tsx
@@ -1,11 +1,12 @@
"use client";
-import { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
+import type { GraphExecutionJobInfo } from "@/app/api/__generated__/models/graphExecutionJobInfo";
+import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
import { Button } from "@/components/atoms/Button/Button";
import { LoadingSpinner } from "@/components/atoms/LoadingSpinner/LoadingSpinner";
import { Text } from "@/components/atoms/Text/Text";
import { Dialog } from "@/components/molecules/Dialog/Dialog";
-import { EyeIcon, TrashIcon } from "@phosphor-icons/react";
+import { EyeIcon, Play, TrashIcon } from "@phosphor-icons/react";
import { AgentActionsDropdown } from "../../../AgentActionsDropdown";
import { SelectedActionsWrap } from "../../../SelectedActionsWrap";
import { useSelectedScheduleActions } from "./useSelectedScheduleActions";
@@ -13,13 +14,17 @@ import { useSelectedScheduleActions } from "./useSelectedScheduleActions";
type Props = {
agent: LibraryAgent;
scheduleId: string;
+ schedule?: GraphExecutionJobInfo;
onDeleted?: () => void;
+ onSelectRun?: (id: string) => void;
};
export function SelectedScheduleActions({
agent,
scheduleId,
+ schedule,
onDeleted,
+ onSelectRun,
}: Props) {
const {
openInBuilderHref,
@@ -27,11 +32,32 @@ export function SelectedScheduleActions({
setShowDeleteDialog,
handleDelete,
isDeleting,
- } = useSelectedScheduleActions({ agent, scheduleId, onDeleted });
+ handleRunNow,
+ isRunning,
+ } = useSelectedScheduleActions({
+ agent,
+ scheduleId,
+ schedule,
+ onDeleted,
+ onSelectRun,
+ });
return (
<>
<SelectedActionsWrap>
+ <Button
+ variant="icon"
+ size="icon"
+ aria-label="Run now"
+ onClick={handleRunNow}
+ disabled={isRunning || !schedule}
+ >
+ {isRunning ? (
+ <LoadingSpinner size="small" />
+ ) : (
+ <Play weight="bold" size={18} className="text-zinc-700" />
+ )}
+ </Button>
{openInBuilderHref && (
<Button
variant="icon"
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.ts
index 94f2e964fe..7b43ed16fc 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.ts
@@ -1,10 +1,16 @@
"use client";
+import {
+ getGetV1ListGraphExecutionsQueryKey,
+ usePostV1ExecuteGraphAgent,
+} from "@/app/api/__generated__/endpoints/graphs/graphs";
import {
getGetV1ListExecutionSchedulesForAGraphQueryOptions,
useDeleteV1DeleteExecutionSchedule,
} from "@/app/api/__generated__/endpoints/schedules/schedules";
-import { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
+import type { GraphExecutionJobInfo } from "@/app/api/__generated__/models/graphExecutionJobInfo";
+import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
+import { okData } from "@/app/api/helpers";
import { useToast } from "@/components/molecules/Toast/use-toast";
import { useQueryClient } from "@tanstack/react-query";
import { useState } from "react";
@@ -12,13 +18,17 @@ import { useState } from "react";
interface UseSelectedScheduleActionsProps {
agent: LibraryAgent;
scheduleId: string;
+ schedule?: GraphExecutionJobInfo;
onDeleted?: () => void;
+ onSelectRun?: (id: string) => void;
}
export function useSelectedScheduleActions({
agent,
scheduleId,
+ schedule,
onDeleted,
+ onSelectRun,
}: UseSelectedScheduleActionsProps) {
const { toast } = useToast();
const queryClient = useQueryClient();
@@ -50,11 +60,58 @@ export function useSelectedScheduleActions({
},
});
+ const { mutateAsync: executeAgent, isPending: isRunning } =
+ usePostV1ExecuteGraphAgent();
+
function handleDelete() {
if (!scheduleId) return;
deleteMutation.mutate({ scheduleId });
}
+ async function handleRunNow() {
+ if (!schedule) {
+ toast({
+ title: "Schedule not loaded",
+ description: "Please wait for the schedule to load.",
+ variant: "destructive",
+ });
+ return;
+ }
+
+ try {
+ toast({ title: "Run started" });
+
+ const res = await executeAgent({
+ graphId: schedule.graph_id,
+ graphVersion: schedule.graph_version,
+ data: {
+ inputs: schedule.input_data || {},
+ credentials_inputs: schedule.input_credentials || {},
+ source: "library",
+ },
+ });
+
+ const newRunID = okData(res)?.id;
+
+ await queryClient.invalidateQueries({
+ queryKey: getGetV1ListGraphExecutionsQueryKey(agent.graph_id),
+ });
+
+ 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",
+ });
+ }
+ }
+
const openInBuilderHref = `/build?flowID=${agent.graph_id}&flowVersion=${agent.graph_version}`;
return {
@@ -63,5 +120,7 @@ export function useSelectedScheduleActions({
setShowDeleteDialog,
handleDelete,
isDeleting: deleteMutation.isPending,
+ handleRunNow,
+ isRunning,
};
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/SidebarRunsList.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/SidebarRunsList.tsx
index 7a164f89dc..8a1abe2c87 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/SidebarRunsList.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/SidebarRunsList.tsx
@@ -186,6 +186,7 @@ export function SidebarRunsList({
selected={selectedRunId === s.id}
onClick={() => onSelectRun(s.id, "scheduled")}
onDeleted={() => onScheduleDeleted?.(s.id)}
+ onRunCreated={(runID) => onSelectRun(runID, "runs")}
/>
</div>
))
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.tsx
index ec3e593887..2355c179bd 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.tsx
@@ -1,11 +1,16 @@
"use client";
+import {
+ getGetV1ListGraphExecutionsQueryKey,
+ usePostV1ExecuteGraphAgent,
+} from "@/app/api/__generated__/endpoints/graphs/graphs";
import {
getGetV1ListExecutionSchedulesForAGraphQueryOptions,
useDeleteV1DeleteExecutionSchedule,
} from "@/app/api/__generated__/endpoints/schedules/schedules";
import type { GraphExecutionJobInfo } from "@/app/api/__generated__/models/graphExecutionJobInfo";
import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
+import { okData } from "@/app/api/helpers";
import { Button } from "@/components/atoms/Button/Button";
import { Text } from "@/components/atoms/Text/Text";
import { Dialog } from "@/components/molecules/Dialog/Dialog";
@@ -13,6 +18,7 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
+ DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/molecules/DropdownMenu/DropdownMenu";
import { useToast } from "@/components/molecules/Toast/use-toast";
@@ -24,9 +30,15 @@ interface Props {
agent: LibraryAgent;
schedule: GraphExecutionJobInfo;
onDeleted?: () => void;
+ onRunCreated?: (runID: string) => void;
}
-export function ScheduleActionsDropdown({ agent, schedule, onDeleted }: Props) {
+export function ScheduleActionsDropdown({
+ agent,
+ schedule,
+ onDeleted,
+ onRunCreated,
+}: Props) {
const { toast } = useToast();
const queryClient = useQueryClient();
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
@@ -34,6 +46,9 @@ export function ScheduleActionsDropdown({ agent, schedule, onDeleted }: Props) {
const { mutateAsync: deleteSchedule, isPending: isDeleting } =
useDeleteV1DeleteExecutionSchedule();
+ const { mutateAsync: executeAgent, isPending: isRunning } =
+ usePostV1ExecuteGraphAgent();
+
async function handleDelete() {
try {
await deleteSchedule({ scheduleId: schedule.id });
@@ -60,6 +75,43 @@ export function ScheduleActionsDropdown({ agent, schedule, onDeleted }: Props) {
}
}
+ async function handleRunNow(e: React.MouseEvent) {
+ e.stopPropagation();
+
+ try {
+ toast({ title: "Run started" });
+
+ const res = await executeAgent({
+ graphId: schedule.graph_id,
+ graphVersion: schedule.graph_version,
+ data: {
+ inputs: schedule.input_data || {},
+ credentials_inputs: schedule.input_credentials || {},
+ source: "library",
+ },
+ });
+
+ const newRunID = okData(res)?.id;
+
+ await queryClient.invalidateQueries({
+ queryKey: getGetV1ListGraphExecutionsQueryKey(agent.graph_id),
+ });
+
+ if (newRunID) {
+ onRunCreated?.(newRunID);
+ }
+ } catch (error: unknown) {
+ toast({
+ title: "Failed to start run",
+ description:
+ error instanceof Error
+ ? error.message
+ : "An unexpected error occurred.",
+ variant: "destructive",
+ });
+ }
+ }
+
return (
<>
<DropdownMenu>
@@ -73,6 +125,14 @@ export function ScheduleActionsDropdown({ agent, schedule, onDeleted }: Props) {
</button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
+ <DropdownMenuItem
+ onClick={handleRunNow}
+ disabled={isRunning}
+ className="flex items-center gap-2"
+ >
+ {isRunning ? "Running..." : "Run now"}
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation();
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleListItem.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleListItem.tsx
index 8815069011..bde6874120 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleListItem.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleListItem.tsx
@@ -14,6 +14,7 @@ interface Props {
selected?: boolean;
onClick?: () => void;
onDeleted?: () => void;
+ onRunCreated?: (runID: string) => void;
}
export function ScheduleListItem({
@@ -22,6 +23,7 @@ export function ScheduleListItem({
selected,
onClick,
onDeleted,
+ onRunCreated,
}: Props) {
return (
<SidebarItemCard
@@ -46,6 +48,7 @@ export function ScheduleListItem({
agent={agent}
schedule={schedule}
onDeleted={onDeleted}
+ onRunCreated={onRunCreated}
/>
}
/>