Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rnd): Added updated graph meta to include runs #8088

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
21d8ab7
Added updated graph meta to include runs
Swiftyos Sep 18, 2024
b788534
Merge branch 'master' into swiftyos/secrt-871-monitor-page-crashing-o…
Swiftyos Sep 19, 2024
0967233
push logic server side
Swiftyos Sep 19, 2024
8ebf606
include runs for the monitor page load
Swiftyos Sep 19, 2024
0144b90
remove extra white space
Swiftyos Sep 19, 2024
e11a329
correct db query
Swiftyos Sep 19, 2024
419cdb9
fixed conversion
Swiftyos Sep 19, 2024
5c4f2e5
fix linting
Swiftyos Sep 19, 2024
cd4e20a
pr changes
Swiftyos Sep 19, 2024
f3fd0d0
fmt
Swiftyos Sep 19, 2024
59524ad
Merge branch 'master' of github.com:Significant-Gravitas/AutoGPT into…
majdyz Sep 19, 2024
c9d2c8d
Add flexible date getTime parsing
majdyz Sep 19, 2024
e800cb2
Merge remote-tracking branch 'origin/swiftyos/secrt-871-monitor-page-…
majdyz Sep 19, 2024
852eef9
disable sentry when running in dev
Swiftyos Sep 20, 2024
a6c6af9
Split out GraphMeta types to GraphMeta and GraphMetaWithRunds
Swiftyos Sep 20, 2024
678360c
cleared out build stuff in pyproject.toml
Swiftyos Sep 20, 2024
9434634
Update rnd/autogpt_builder/src/lib/autogpt-server-api/types.ts
Swiftyos Sep 20, 2024
27b3922
pr fixes
Swiftyos Sep 20, 2024
d912a96
Merge branch 'master' of github.com:Significant-Gravitas/AutoGPT into…
majdyz Sep 20, 2024
c8b602c
Merge branch 'swiftyos/secrt-871-monitor-page-crashing-on-due-to-numb…
majdyz Sep 20, 2024
7c41f85
lint fix
majdyz Sep 20, 2024
5c811a7
Revert added file
majdyz Sep 20, 2024
c388385
Merge branch 'master' into swiftyos/secrt-871-monitor-page-crashing-o…
Swiftyos Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rnd/autogpt_builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "export NODE_ENV=development && next dev",
"dev:test": "export NODE_ENV=test && next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
Expand Down
2 changes: 2 additions & 0 deletions rnd/autogpt_builder/sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",

enabled: process.env.NODE_ENV !== "development",

// Add optional integrations for additional features
integrations: [
Sentry.replayIntegration(),
Expand Down
2 changes: 2 additions & 0 deletions rnd/autogpt_builder/sentry.edge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",

Swiftyos marked this conversation as resolved.
Show resolved Hide resolved
enabled: process.env.NODE_ENV !== "development",

// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,

Expand Down
2 changes: 2 additions & 0 deletions rnd/autogpt_builder/sentry.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",

enabled: process.env.NODE_ENV !== "development",

// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,

Expand Down
135 changes: 38 additions & 97 deletions rnd/autogpt_builder/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import React, { useCallback, useEffect, useMemo, useState } from "react";

import AutoGPTServerAPI, {
GraphMeta,
NodeExecutionResult,
GraphMetaWithRuns,
ExecutionMeta,
} from "@/lib/autogpt-server-api";

import { Card } from "@/components/ui/card";
Expand All @@ -17,62 +17,37 @@ import {
} from "@/components/monitor";

const Monitor = () => {
const [flows, setFlows] = useState<GraphMeta[]>([]);
const [flows, setFlows] = useState<GraphMetaWithRuns[]>([]);
const [flowRuns, setFlowRuns] = useState<FlowRun[]>([]);
const [selectedFlow, setSelectedFlow] = useState<GraphMeta | null>(null);
const [selectedFlow, setSelectedFlow] = useState<GraphMetaWithRuns | null>(
null,
);
const [selectedRun, setSelectedRun] = useState<FlowRun | null>(null);

const api = useMemo(() => new AutoGPTServerAPI(), []);

const refreshFlowRuns = useCallback(
(flowID: string) => {
// Fetch flow run IDs
api.listGraphRunIDs(flowID).then((runIDs) =>
runIDs.map((runID) => {
let run;
if (
(run = flowRuns.find((fr) => fr.id == runID)) &&
!["waiting", "running"].includes(run.status)
) {
return;
}

// Fetch flow run
api.getGraphExecutionInfo(flowID, runID).then((execInfo) =>
setFlowRuns((flowRuns) => {
if (execInfo.length == 0) return flowRuns;

const flowRunIndex = flowRuns.findIndex((fr) => fr.id == runID);
const flowRun = flowRunFromNodeExecutionResults(execInfo);
if (flowRunIndex > -1) {
flowRuns.splice(flowRunIndex, 1, flowRun);
} else {
flowRuns.push(flowRun);
}
return [...flowRuns];
}),
);
}),
const fetchAgents = useCallback(() => {
api.listGraphsWithRuns().then((agent) => {
setFlows(agent);
const flowRuns = agent.flatMap((graph) =>
graph.executions != null
? graph.executions.map((execution) =>
flowRunFromExecutionMeta(graph, execution),
)
: [],
);
},
[api, flowRuns],
);

const fetchFlowsAndRuns = useCallback(() => {
api.listGraphs().then((flows) => {
setFlows(flows);
flows.map((flow) => refreshFlowRuns(flow.id));
setFlowRuns(flowRuns);
});
}, [api, refreshFlowRuns]);
}, [api]);

useEffect(() => fetchFlowsAndRuns(), [fetchFlowsAndRuns]);
useEffect(() => {
const intervalId = setInterval(
() => flows.map((f) => refreshFlowRuns(f.id)),
5000,
);
fetchAgents();
}, [api, fetchAgents]);

useEffect(() => {
const intervalId = setInterval(() => fetchAgents(), 5000);
return () => clearInterval(intervalId);
}, [flows, refreshFlowRuns]);
}, [fetchAgents, flows]);

const column1 = "md:col-span-2 xl:col-span-3 xxl:col-span-2";
const column2 = "md:col-span-3 lg:col-span-2 xl:col-span-3 space-y-4";
Expand All @@ -87,7 +62,9 @@ const Monitor = () => {
selectedFlow={selectedFlow}
onSelectFlow={(f) => {
setSelectedRun(null);
setSelectedFlow(f.id == selectedFlow?.id ? null : f);
setSelectedFlow(
f.id == selectedFlow?.id ? null : (f as GraphMetaWithRuns),
);
}}
/>
<FlowRunsList
Expand Down Expand Up @@ -123,56 +100,20 @@ const Monitor = () => {
);
};

function flowRunFromNodeExecutionResults(
nodeExecutionResults: NodeExecutionResult[],
function flowRunFromExecutionMeta(
graphMeta: GraphMetaWithRuns,
executionMeta: ExecutionMeta,
): FlowRun {
// Determine overall status
let status: "running" | "waiting" | "success" | "failed" = "success";
for (const execution of nodeExecutionResults) {
if (execution.status === "FAILED") {
status = "failed";
break;
} else if (["QUEUED", "RUNNING"].includes(execution.status)) {
status = "running";
break;
} else if (execution.status === "INCOMPLETE") {
status = "waiting";
}
}

// Determine aggregate startTime, endTime, and totalRunTime
const now = Date.now();
const startTime = Math.min(
...nodeExecutionResults.map((ner) => ner.add_time.getTime()),
now,
);
const endTime = ["success", "failed"].includes(status)
? Math.max(
...nodeExecutionResults.map((ner) => ner.end_time?.getTime() || 0),
startTime,
)
: now;
const duration = (endTime - startTime) / 1000; // Convert to seconds
const totalRunTime =
nodeExecutionResults.reduce(
(cum, node) =>
cum +
((node.end_time?.getTime() ?? now) -
(node.start_time?.getTime() ?? now)),
0,
) / 1000;

return {
id: nodeExecutionResults[0].graph_exec_id,
graphID: nodeExecutionResults[0].graph_id,
graphVersion: nodeExecutionResults[0].graph_version,
status,
startTime,
endTime,
duration,
totalRunTime,
nodeExecutionResults: nodeExecutionResults,
};
id: executionMeta.execution_id,
graphID: graphMeta.id,
graphVersion: graphMeta.version,
status: executionMeta.status,
startTime: executionMeta.started_at,
endTime: executionMeta.ended_at,
duration: executionMeta.duration,
totalRunTime: executionMeta.total_run_time,
} as FlowRun;
}

export default Monitor;
34 changes: 33 additions & 1 deletion rnd/autogpt_builder/src/lib/autogpt-server-api/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
GraphCreatable,
GraphUpdateable,
GraphMeta,
GraphMetaWithRuns,
GraphExecuteResponse,
ExecutionMeta,
NodeExecutionResult,
User,
AnalyticsMetrics,
Expand Down Expand Up @@ -45,7 +47,12 @@ export default class BaseAutoGPTServerAPI {
}

async listGraphs(): Promise<GraphMeta[]> {
return this._get("/graphs");
return this._get(`/graphs`);
}

async listGraphsWithRuns(): Promise<GraphMetaWithRuns[]> {
let graphs = await this._get(`/graphs?with_runs=true`);
return graphs.map(parseGraphMetaWithRuns);
}

async listTemplates(): Promise<GraphMeta[]> {
Expand Down Expand Up @@ -319,3 +326,28 @@ function parseNodeExecutionResultTimestamps(result: any): NodeExecutionResult {
end_time: result.end_time ? new Date(result.end_time) : undefined,
};
}

function parseGraphMetaWithRuns(result: any): GraphMetaWithRuns {
return {
...result,
executions: result.executions.map(parseExecutionMetaTimestamps),
};
}

function parseExecutionMetaTimestamps(result: any): ExecutionMeta {
let status: "running" | "waiting" | "success" | "failed" = "success";
if (result.status === "FAILED") {
status = "failed";
} else if (["QUEUED", "RUNNING"].includes(result.status)) {
status = "running";
} else if (result.status === "INCOMPLETE") {
status = "waiting";
}

return {
...result,
status,
started_at: new Date(result.started_at).getTime(),
ended_at: result.ended_at ? new Date(result.ended_at).getTime() : undefined,
};
}
14 changes: 14 additions & 0 deletions rnd/autogpt_builder/src/lib/autogpt-server-api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ export type LinkCreatable = Omit<Link, "id" | "is_static"> & {
id?: string;
};

/* Mirror of autogpt_server/data/graph.py:ExecutionMeta */
export type ExecutionMeta = {
execution_id: string;
started_at: number;
ended_at: number;
duration: number;
total_run_time: number;
status: "running" | "waiting" | "success" | "failed";
};

/* Mirror of autogpt_server/data/graph.py:GraphMeta */
export type GraphMeta = {
id: string;
Expand All @@ -150,6 +160,10 @@ export type GraphMeta = {
description: string;
};

export type GraphMetaWithRuns = GraphMeta & {
executions: ExecutionMeta[];
};

/* Mirror of autogpt_server/data/graph.py:Graph */
export type Graph = GraphMeta & {
nodes: Array<Node>;
Expand Down
Loading
Loading