Skip to content

Commit

Permalink
remove ref
Browse files Browse the repository at this point in the history
  • Loading branch information
aarushik93 committed Sep 9, 2024
1 parent 3b84a20 commit 2ae7c1c
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 385 deletions.
4 changes: 2 additions & 2 deletions rnd/autogpt_builder/src/app/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default function Error({
Oops, something went wrong!
</h1>
<p className="mt-4 text-muted-foreground">
We&apos;re sorry, but an unexpected error has occurred. Please try
again later or contact support if the issue persists.
We're sorry, but an unexpected error has occurred. Please try again
later or contact support if the issue persists.
</p>
<div className="mt-6 flex flex-row justify-center gap-4">
<Button onClick={reset} variant="outline">
Expand Down
85 changes: 41 additions & 44 deletions rnd/autogpt_builder/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import React, { useEffect, useState } from "react";

import AutoGPTServerAPI, {
GraphMeta,
Expand All @@ -22,57 +22,54 @@ const Monitor = () => {
const [selectedFlow, setSelectedFlow] = useState<GraphMeta | null>(null);
const [selectedRun, setSelectedRun] = useState<FlowRun | null>(null);

const api = useMemo(() => new AutoGPTServerAPI(), []);
const api = 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];
}),
);
}),
);
},
[api, flowRuns],
);
useEffect(() => fetchFlowsAndRuns(), []);
useEffect(() => {
const intervalId = setInterval(
() => flows.map((f) => refreshFlowRuns(f.id)),
5000,
);
return () => clearInterval(intervalId);
}, []);

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

useEffect(() => fetchFlowsAndRuns(), [fetchFlowsAndRuns]);
useEffect(() => {
const intervalId = setInterval(
() => flows.map((f) => refreshFlowRuns(f.id)),
5000,
function refreshFlowRuns(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];
}),
);
}),
);
return () => clearInterval(intervalId);
}, [flows, refreshFlowRuns]);
}

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 Down
43 changes: 20 additions & 23 deletions rnd/autogpt_builder/src/components/CustomEdge.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useContext, useEffect, useState } from "react";
import React, { useContext, useEffect, useState } from "react";
import {
BaseEdge,
EdgeLabelRenderer,
Expand Down Expand Up @@ -65,27 +65,24 @@ export function CustomEdge({
const beadDiameter = 12;
const deltaTime = 16;

const setTargetPositions = useCallback(
(beads: Bead[]) => {
const distanceBetween = Math.min(
(length - beadDiameter) / (beads.length + 1),
beadDiameter,
);

return beads.map((bead, index) => {
const distanceFromEnd = beadDiameter * 1.35;
const targetPosition = distanceBetween * index + distanceFromEnd;
const t = getTForDistance(-targetPosition);

return {
...bead,
t: visualizeBeads === "animate" ? bead.t : t,
targetT: t,
} as Bead;
});
},
[getTForDistance, length, visualizeBeads],
);
function setTargetPositions(beads: Bead[]) {
const distanceBetween = Math.min(
(length - beadDiameter) / (beads.length + 1),
beadDiameter,
);

return beads.map((bead, index) => {
const distanceFromEnd = beadDiameter * 1.35;
const targetPosition = distanceBetween * index + distanceFromEnd;
const t = getTForDistance(-targetPosition);

return {
...bead,
t: visualizeBeads === "animate" ? bead.t : t,
targetT: t,
} as Bead;
});
}

useEffect(() => {
if (data?.beadUp === 0 && data?.beadDown === 0) {
Expand Down Expand Up @@ -173,7 +170,7 @@ export function CustomEdge({
}, deltaTime);

return () => clearInterval(interval);
}, [data, setTargetPositions, visualizeBeads]);
}, [data]);

const middle = getPointForT(0.5);

Expand Down
2 changes: 1 addition & 1 deletion rnd/autogpt_builder/src/components/CustomNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function CustomNode({ data, id, width, height }: NodeProps<CustomNode>) {

useEffect(() => {
setIsAnyModalOpen?.(isModalOpen || isOutputModalOpen);
}, [isModalOpen, isOutputModalOpen, data, setIsAnyModalOpen]);
}, [isModalOpen, isOutputModalOpen, data]);

useEffect(() => {
isInitialSetup.current = false;
Expand Down
8 changes: 4 additions & 4 deletions rnd/autogpt_builder/src/components/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const FlowEditor: React.FC<{
localStorage.setItem("shepherd-tour", "yes");
}
}
}, [availableNodes, tutorialStarted, router, pathname]);
}, [availableNodes, tutorialStarted]);

useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
Expand Down Expand Up @@ -256,7 +256,7 @@ const FlowEditor: React.FC<{
}

const edgeColor = getTypeColor(
getOutputType(nodes, connection.source!, connection.sourceHandle!),
getOutputType(connection.source!, connection.sourceHandle!),
);
const sourceNode = getNode(connection.source!);
const newEdge: CustomEdge = {
Expand Down Expand Up @@ -295,7 +295,6 @@ const FlowEditor: React.FC<{
addEdges,
deleteElements,
clearNodesStatusAndOutput,
nodes,
edges,
formatEdgeID,
getOutputType,
Expand Down Expand Up @@ -378,7 +377,7 @@ const FlowEditor: React.FC<{
clearNodesStatusAndOutput();
}
},
[setNodes, clearNodesStatusAndOutput, setEdges],
[setNodes, clearNodesStatusAndOutput],
);

const getNextNodeId = useCallback(() => {
Expand Down Expand Up @@ -435,6 +434,7 @@ const FlowEditor: React.FC<{
nodeId,
availableNodes,
addNodes,
setNodes,
deleteElements,
clearNodesStatusAndOutput,
x,
Expand Down
6 changes: 3 additions & 3 deletions rnd/autogpt_builder/src/components/monitor/AgentFlowList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AutoGPTServerAPI, { GraphMeta } from "@/lib/autogpt-server-api";
import React, { useEffect, useMemo, useState } from "react";
import React, { useEffect, useState } from "react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import Link from "next/link";
Expand Down Expand Up @@ -45,10 +45,10 @@ export const AgentFlowList = ({
className?: string;
}) => {
const [templates, setTemplates] = useState<GraphMeta[]>([]);
const api = useMemo(() => new AutoGPTServerAPI(), []);
const api = new AutoGPTServerAPI();
useEffect(() => {
api.listTemplates().then((templates) => setTemplates(templates));
}, [api]);
}, []);

return (
<Card className={className}>
Expand Down
6 changes: 3 additions & 3 deletions rnd/autogpt_builder/src/components/monitor/FlowInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useState } from "react";
import React, { useEffect, useState } from "react";
import AutoGPTServerAPI, {
Graph,
GraphMeta,
Expand Down Expand Up @@ -28,7 +28,7 @@ export const FlowInfo: React.FC<
flowVersion?: number | "all";
}
> = ({ flow, flowRuns, flowVersion, ...props }) => {
const api = useMemo(() => new AutoGPTServerAPI(), []);
const api = new AutoGPTServerAPI();

const [flowVersions, setFlowVersions] = useState<Graph[] | null>(null);
const [selectedVersion, setSelectedFlowVersion] = useState(
Expand All @@ -41,7 +41,7 @@ export const FlowInfo: React.FC<

useEffect(() => {
api.getGraphAllVersions(flow.id).then((result) => setFlowVersions(result));
}, [flow.id, api]);
}, [flow.id]);

return (
<Card {...props}>
Expand Down
8 changes: 4 additions & 4 deletions rnd/autogpt_builder/src/components/node-input-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
BlockIONumberSubSchema,
BlockIOBooleanSubSchema,
} from "@/lib/autogpt-server-api/types";
import { FC, useCallback, useEffect, useState } from "react";
import { FC, useEffect, useState } from "react";
import { Button } from "./ui/button";
import { Switch } from "./ui/switch";
import {
Expand Down Expand Up @@ -296,7 +296,7 @@ const NodeKeyValueInput: FC<{
className,
displayName,
}) => {
const getPairValues = useCallback(() => {
const getPairValues = () => {
let defaultEntries = new Map<string, any>();

connections
Expand All @@ -311,15 +311,15 @@ const NodeKeyValueInput: FC<{
});

return Array.from(defaultEntries, ([key, value]) => ({ key, value }));
}, [connections, entries, schema.default, selfKey]);
};

const [keyValuePairs, setKeyValuePairs] = useState<
{ key: string; value: string | number | null }[]
>([]);

useEffect(
() => setKeyValuePairs(getPairValues()),
[connections, entries, schema.default, getPairValues],
[connections, entries, schema.default],
);

function updateKeyValuePairs(newPairs: typeof keyValuePairs) {
Expand Down
2 changes: 1 addition & 1 deletion rnd/autogpt_builder/src/components/ui/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
) {
ref.current.value = value;
}
}, [value, type, ref]);
}, [value, type]);
return (
<input
type={type}
Expand Down
Loading

0 comments on commit 2ae7c1c

Please sign in to comment.