brand GraphExecution.execution_id and Schedule.id

This commit is contained in:
Reinier van der Leer
2025-02-26 17:06:22 +01:00
parent e982fe99ac
commit 612461fe22
10 changed files with 82 additions and 50 deletions

View File

@@ -5,10 +5,12 @@ import { useParams, useRouter } from "next/navigation";
import { useBackendAPI } from "@/lib/autogpt-server-api/context";
import {
GraphExecution,
GraphExecutionID,
GraphExecutionMeta,
GraphID,
GraphMeta,
Schedule,
ScheduleID,
} from "@/lib/autogpt-server-api";
import AgentRunDraftView from "@/components/agents/agent-run-draft-view";
@@ -21,13 +23,15 @@ export default function AgentRunsPage(): React.ReactElement {
const router = useRouter();
const api = useBackendAPI();
// ============================ STATE =============================
const [agent, setAgent] = useState<GraphMeta | null>(null);
const [agentRuns, setAgentRuns] = useState<GraphExecutionMeta[]>([]);
const [schedules, setSchedules] = useState<Schedule[]>([]);
const [selectedView, selectView] = useState<{
type: "run" | "schedule";
id?: string;
}>({ type: "run" });
const [selectedView, selectView] = useState<
| { type: "run"; id?: GraphExecutionID }
| { type: "schedule"; id: ScheduleID }
>({ type: "run" });
const [selectedRun, setSelectedRun] = useState<
GraphExecution | GraphExecutionMeta | null
>(null);
@@ -40,7 +44,7 @@ export default function AgentRunsPage(): React.ReactElement {
selectView({ type: "run" });
}, []);
const selectRun = useCallback((id: string) => {
const selectRun = useCallback((id: GraphExecutionID) => {
selectView({ type: "run", id });
}, []);
@@ -107,7 +111,7 @@ export default function AgentRunsPage(): React.ReactElement {
// =========================== ACTIONS ============================
const deleteRun = useCallback(
async (graphExecID: string) => {
async (graphExecID: GraphExecutionID) => {
await api.deleteGraphExecution(graphExecID);
setAgentRuns(agentRuns.filter((r) => r.execution_id !== graphExecID));
},
@@ -115,7 +119,7 @@ export default function AgentRunsPage(): React.ReactElement {
);
const deleteSchedule = useCallback(
async (scheduleID: string) => {
async (scheduleID: ScheduleID) => {
const removedSchedule = await api.deleteSchedule(scheduleID);
setSchedules(schedules.filter((s) => s.id !== removedSchedule.id));
},

View File

@@ -5,6 +5,7 @@ import {
GraphExecutionMeta,
Schedule,
LibraryAgent,
ScheduleID,
} from "@/lib/autogpt-server-api";
import { Card } from "@/components/ui/card";
@@ -35,7 +36,7 @@ const Monitor = () => {
}, [api]);
const removeSchedule = useCallback(
async (scheduleId: string) => {
async (scheduleId: ScheduleID) => {
const removedSchedule = await api.deleteSchedule(scheduleId);
setSchedules(schedules.filter((s) => s.id !== removedSchedule.id));
},

View File

@@ -26,7 +26,12 @@ import {
import "@xyflow/react/dist/style.css";
import { CustomNode } from "./CustomNode";
import "./flow.css";
import { BlockUIType, formatEdgeID, GraphID } from "@/lib/autogpt-server-api";
import {
BlockUIType,
formatEdgeID,
GraphExecutionID,
GraphID,
} from "@/lib/autogpt-server-api";
import { getTypeColor, findNewlyAddedBlockCoordinates } from "@/lib/utils";
import { history } from "./history";
import { CustomEdge } from "./CustomEdge";
@@ -86,7 +91,9 @@ const FlowEditor: React.FC<{
const [visualizeBeads, setVisualizeBeads] = useState<
"no" | "static" | "animate"
>("animate");
const [flowExecutionID, setFlowExecutionID] = useState<string | undefined>();
const [flowExecutionID, setFlowExecutionID] = useState<
GraphExecutionID | undefined
>();
const {
agentName,
setAgentName,
@@ -164,7 +171,9 @@ const FlowEditor: React.FC<{
if (params.get("open_scheduling") === "true") {
setOpenCron(true);
}
setFlowExecutionID(params.get("flowExecutionID") || undefined);
setFlowExecutionID(
(params.get("flowExecutionID") as GraphExecutionID) || undefined,
);
}, [params]);
useEffect(() => {

View File

@@ -2,7 +2,7 @@
import React, { useCallback, useMemo, useState } from "react";
import { useBackendAPI } from "@/lib/autogpt-server-api/context";
import { GraphMeta } from "@/lib/autogpt-server-api";
import { GraphExecutionID, GraphMeta } from "@/lib/autogpt-server-api";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button, ButtonProps } from "@/components/agptui/Button";
@@ -14,7 +14,7 @@ export default function AgentRunDraftView({
agentActions,
}: {
agent: GraphMeta;
onRun: (runID: string) => void;
onRun: (runID: GraphExecutionID) => void;
agentActions: { label: string; callback: () => void }[];
}): React.ReactNode {
const api = useBackendAPI();

View File

@@ -4,9 +4,11 @@ import { Plus } from "lucide-react";
import { cn } from "@/lib/utils";
import {
GraphExecutionID,
GraphExecutionMeta,
GraphMeta,
Schedule,
ScheduleID,
} from "@/lib/autogpt-server-api";
import { ScrollArea } from "@/components/ui/scroll-area";
@@ -21,10 +23,11 @@ interface AgentRunsSelectorListProps {
agentRuns: GraphExecutionMeta[];
schedules: Schedule[];
selectedView: { type: "run" | "schedule"; id?: string };
onSelectRun: (id: string) => void;
onSelectRun: (id: GraphExecutionID) => void;
onSelectSchedule: (schedule: Schedule) => void;
onSelectDraftNewRun: () => void;
onDeleteSchedule: (id: string) => void;
onDeleteRun: (id: GraphExecutionID) => void;
onDeleteSchedule: (id: ScheduleID) => void;
className?: string;
}

View File

@@ -1,7 +1,11 @@
"use client";
import React, { useCallback, useMemo } from "react";
import { BlockIOSubType, GraphMeta, Schedule } from "@/lib/autogpt-server-api";
import {
GraphExecutionID,
GraphMeta,
Schedule,
} from "@/lib/autogpt-server-api";
import { useBackendAPI } from "@/lib/autogpt-server-api/context";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
@@ -17,7 +21,7 @@ export default function AgentScheduleDetailsView({
}: {
agent: GraphMeta;
schedule: Schedule;
onForcedRun: (runID: string) => void;
onForcedRun: (runID: GraphExecutionID) => void;
agentActions: { label: string; callback: () => void }[];
}): React.ReactNode {
const api = useBackendAPI();

View File

@@ -1,4 +1,4 @@
import { LibraryAgent, Schedule } from "@/lib/autogpt-server-api";
import { LibraryAgent, Schedule, ScheduleID } from "@/lib/autogpt-server-api";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import {
@@ -36,7 +36,7 @@ import { Label } from "../ui/label";
interface SchedulesTableProps {
schedules: Schedule[];
agents: LibraryAgent[];
onRemoveSchedule: (scheduleId: string, enabled: boolean) => void;
onRemoveSchedule: (scheduleId: ScheduleID, enabled: boolean) => void;
sortColumn: keyof Schedule;
sortDirection: "asc" | "desc";
onSort: (column: keyof Schedule) => void;
@@ -73,7 +73,7 @@ export const SchedulesTable = ({
return String(bValue).localeCompare(String(aValue));
});
const handleToggleSchedule = (scheduleId: string, enabled: boolean) => {
const handleToggleSchedule = (scheduleId: ScheduleID, enabled: boolean) => {
onRemoveSchedule(scheduleId, enabled);
if (!enabled) {
toast({

View File

@@ -6,6 +6,7 @@ import BackendAPI, {
BlockUIType,
formatEdgeID,
Graph,
GraphExecutionID,
GraphID,
NodeExecutionResult,
} from "@/lib/autogpt-server-api";
@@ -29,7 +30,7 @@ const ajv = new Ajv({ strict: false, allErrors: true });
export default function useAgentGraph(
flowID?: GraphID,
flowVersion?: number,
flowExecutionID?: string,
flowExecutionID?: GraphExecutionID,
passDataToBeads?: boolean,
) {
const { toast } = useToast();
@@ -65,7 +66,7 @@ export default function useAgentGraph(
| {
request: "run" | "stop";
state: "running" | "stopping" | "error";
activeExecutionID?: string;
activeExecutionID?: GraphExecutionID;
}
>({
request: "none",

View File

@@ -17,10 +17,13 @@ import {
Graph,
GraphCreatable,
GraphExecution,
GraphExecutionID,
GraphExecutionMeta,
GraphID,
GraphMeta,
GraphUpdateable,
LibraryAgent,
LibraryAgentID,
LibraryAgentPreset,
LibraryAgentPresetResponse,
LibraryAgentResponse,
@@ -33,6 +36,7 @@ import {
RefundRequest,
Schedule,
ScheduleCreatable,
ScheduleID,
StoreAgentDetails,
StoreAgentsResponse,
StoreReview,
@@ -167,7 +171,7 @@ export default class BackendAPI {
}
getGraph(
id: string,
id: GraphID,
version?: number,
hide_credentials?: boolean,
): Promise<Graph> {
@@ -181,7 +185,7 @@ export default class BackendAPI {
return this._get(`/graphs/${id}`, query);
}
getGraphAllVersions(id: string): Promise<Graph[]> {
getGraphAllVersions(id: GraphID): Promise<Graph[]> {
return this._get(`/graphs/${id}/versions`);
}
@@ -191,25 +195,25 @@ export default class BackendAPI {
return this._request("POST", "/graphs", requestBody);
}
updateGraph(id: string, graph: GraphUpdateable): Promise<Graph> {
updateGraph(id: GraphID, graph: GraphUpdateable): Promise<Graph> {
return this._request("PUT", `/graphs/${id}`, graph);
}
deleteGraph(id: string): Promise<void> {
deleteGraph(id: GraphID): Promise<void> {
return this._request("DELETE", `/graphs/${id}`);
}
setGraphActiveVersion(id: string, version: number): Promise<Graph> {
setGraphActiveVersion(id: GraphID, version: number): Promise<Graph> {
return this._request("PUT", `/graphs/${id}/versions/active`, {
active_graph_version: version,
});
}
executeGraph(
id: string,
id: GraphID,
version: number,
inputData: { [key: string]: any } = {},
): Promise<{ graph_exec_id: string }> {
): Promise<{ graph_exec_id: GraphExecutionID }> {
return this._request("POST", `/graphs/${id}/execute/${version}`, inputData);
}
@@ -217,13 +221,13 @@ export default class BackendAPI {
return this._get(`/executions`);
}
getGraphExecutions(graphID: string): Promise<GraphExecutionMeta[]> {
getGraphExecutions(graphID: GraphID): Promise<GraphExecutionMeta[]> {
return this._get(`/graphs/${graphID}/executions`);
}
async getGraphExecutionInfo(
graphID: string,
runID: string,
graphID: GraphID,
runID: GraphExecutionID,
): Promise<GraphExecution> {
const result = await this._get(`/graphs/${graphID}/executions/${runID}`);
result.node_executions = result.node_executions.map(
@@ -233,8 +237,8 @@ export default class BackendAPI {
}
async stopGraphExecution(
graphID: string,
runID: string,
graphID: GraphID,
runID: GraphExecutionID,
): Promise<GraphExecution> {
const result = await this._request(
"POST",
@@ -246,7 +250,7 @@ export default class BackendAPI {
return result;
}
async deleteGraphExecution(runID: string): Promise<void> {
async deleteGraphExecution(runID: GraphExecutionID): Promise<void> {
await this._request("DELETE", `/executions/${runID}`);
}
@@ -504,7 +508,7 @@ export default class BackendAPI {
}
async updateLibraryAgent(
libraryAgentId: string,
libraryAgentId: LibraryAgentID,
params: {
auto_update_version?: boolean;
is_favorite?: boolean;
@@ -545,7 +549,7 @@ export default class BackendAPI {
executeLibraryAgentPreset(
presetId: string,
graphId: string,
graphId: GraphID,
graphVersion: number,
nodeInput: { [key: string]: any },
): Promise<{ id: string }> {
@@ -556,13 +560,7 @@ export default class BackendAPI {
});
}
///////////////////////////////////////////
/////////// INTERNAL FUNCTIONS ////////////
//////////////////////////////??///////////
private _get(path: string, query?: Record<string, any>) {
return this._request("GET", path, query);
}
/////////////////////// SCHEDULES ////////////////////////
async createSchedule(schedule: ScheduleCreatable): Promise<Schedule> {
return this._request("POST", `/schedules`, schedule).then(
@@ -570,7 +568,7 @@ export default class BackendAPI {
);
}
async deleteSchedule(scheduleId: string): Promise<{ id: string }> {
async deleteSchedule(scheduleId: ScheduleID): Promise<{ id: string }> {
return this._request("DELETE", `/schedules/${scheduleId}`);
}
@@ -580,6 +578,14 @@ export default class BackendAPI {
);
}
///////////////////////////////////////////
/////////// INTERNAL FUNCTIONS ////////////
//////////////////////////////??///////////
private _get(path: string, query?: Record<string, any>) {
return this._request("GET", path, query);
}
private async _uploadFile(path: string, file: File): Promise<string> {
// Get session with retry logic
let token = "no-token-found";

View File

@@ -218,7 +218,7 @@ export type LinkCreatable = Omit<Link, "id" | "is_static"> & {
/* Mirror of backend/data/graph.py:GraphExecutionMeta */
export type GraphExecutionMeta = {
execution_id: string;
execution_id: GraphExecutionID;
started_at: number;
ended_at: number;
duration: number;
@@ -229,6 +229,8 @@ export type GraphExecutionMeta = {
preset_id?: string;
};
export type GraphExecutionID = Brand<string, "GraphExecutionID">;
/* Mirror of backend/data/graph.py:GraphExecution */
export type GraphExecution = GraphExecutionMeta & {
inputs: Record<string, any>;
@@ -286,7 +288,7 @@ export type GraphCreatable = Omit<GraphUpdateable, "id"> & { id?: string };
export type NodeExecutionResult = {
graph_id: GraphID;
graph_version: number;
graph_exec_id: string;
graph_exec_id: GraphExecutionID;
node_exec_id: string;
node_id: string;
block_id: string;
@@ -623,7 +625,7 @@ export type ProfileDetails = {
};
export type Schedule = {
id: string;
id: ScheduleID;
name: string;
cron: string;
user_id: string;
@@ -633,6 +635,8 @@ export type Schedule = {
next_run_time: Date;
};
export type ScheduleID = Brand<string, "ScheduleID">;
export type ScheduleCreatable = {
cron: string;
graph_id: GraphID;
@@ -641,7 +645,7 @@ export type ScheduleCreatable = {
};
export type MyAgent = {
agent_id: string;
agent_id: GraphID;
agent_version: number;
agent_name: string;
last_edited: string;
@@ -705,7 +709,7 @@ export interface CreditTransaction {
balance: number;
description: string;
usage_graph_id: GraphID;
usage_execution_id: string;
usage_execution_id: GraphExecutionID;
usage_node_count: number;
usage_starting_time: Date;
}