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(platform): load graph on new builder (#11141)

Abhimanyu Yadavcf6e724e99ef
diff --git a/autogpt_platform/backend/backend/server/v2/builder/db.py b/autogpt_platform/backend/backend/server/v2/builder/db.py
index 22cd3d1fc6..b8eecad424 100644
--- a/autogpt_platform/backend/backend/server/v2/builder/db.py
+++ b/autogpt_platform/backend/backend/server/v2/builder/db.py
@@ -118,6 +118,17 @@ def get_blocks(
)
+def get_block_by_id(block_id: str) -> BlockInfo | None:
+ """
+ Get a specific block by its ID.
+ """
+ for block_type in load_all_blocks().values():
+ block: Block[BlockSchema, BlockSchema] = block_type()
+ if block.id == block_id:
+ return block.get_info()
+ return None
+
+
def search_blocks(
include_blocks: bool = True,
include_integrations: bool = True,
diff --git a/autogpt_platform/backend/backend/server/v2/builder/routes.py b/autogpt_platform/backend/backend/server/v2/builder/routes.py
index e9859d2e98..ebc9fd5baf 100644
--- a/autogpt_platform/backend/backend/server/v2/builder/routes.py
+++ b/autogpt_platform/backend/backend/server/v2/builder/routes.py
@@ -110,6 +110,25 @@ async def get_blocks(
)
+ "/blocks/batch",
+ summary="Get specific blocks",
+ response_model=list[builder_model.BlockInfo],
+)
+async def get_specific_blocks(
+ block_ids: Annotated[list[str], fastapi.Query()],
+) -> list[builder_model.BlockInfo]:
+ """
+ Get specific blocks by their IDs.
+ """
+ blocks = []
+ for block_id in block_ids:
+ block = builder_db.get_block_by_id(block_id)
+ if block:
+ blocks.append(block)
+ return blocks
+
+
@router.get(
"/providers",
summary="Get Builder integration providers",
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/Flow.tsx
similarity index 67%
rename from autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow.tsx
rename to autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/Flow.tsx
index e980143259..19ff553e09 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/Flow.tsx
@@ -1,12 +1,12 @@
import { ReactFlow, Background, Controls } from "@xyflow/react";
-import { useNodeStore } from "../../stores/nodeStore";
-
-import NewControlPanel from "../NewBlockMenu/NewControlPanel/NewControlPanel";
+import NewControlPanel from "../../NewBlockMenu/NewControlPanel/NewControlPanel";
+import CustomEdge from "../edges/CustomEdge";
+import { useFlow } from "./useFlow";
import { useShallow } from "zustand/react/shallow";
+import { useNodeStore } from "../../../stores/nodeStore";
import { useMemo } from "react";
-import { CustomNode } from "./nodes/CustomNode";
-import { useCustomEdge } from "./edges/useCustomEdge";
-import CustomEdge from "./edges/CustomEdge";
+import { CustomNode } from "../nodes/CustomNode";
+import { useCustomEdge } from "../edges/useCustomEdge";
export const Flow = () => {
const nodes = useNodeStore(useShallow((state) => state.nodes));
@@ -16,6 +16,9 @@ export const Flow = () => {
const nodeTypes = useMemo(() => ({ custom: CustomNode }), []);
const { edges, onConnect, onEdgesChange } = useCustomEdge();
+ // We use this hook to load the graph and convert them into custom nodes and edges.
+ useFlow();
+
return (
<div className="flex h-full w-full dark:bg-slate-900">
<div className="relative flex-1">
@@ -27,6 +30,8 @@ export const Flow = () => {
onConnect={onConnect}
onEdgesChange={onEdgesChange}
edgeTypes={{ custom: CustomEdge }}
+ maxZoom={2}
+ minZoom={0.1}
>
<Background />
<Controls />
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/useFlow.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/useFlow.ts
new file mode 100644
index 0000000000..8df364100e
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/useFlow.ts
@@ -0,0 +1,69 @@
+import { useGetV2GetSpecificBlocks } from "@/app/api/__generated__/endpoints/default/default";
+import { useGetV1GetSpecificGraph } from "@/app/api/__generated__/endpoints/graphs/graphs";
+import { BlockInfo } from "@/app/api/__generated__/models/blockInfo";
+import { GraphModel } from "@/app/api/__generated__/models/graphModel";
+import { parseAsInteger, parseAsString, useQueryStates } from "nuqs";
+import { useNodeStore } from "../../../stores/nodeStore";
+import { useShallow } from "zustand/react/shallow";
+import { useEffect, useMemo } from "react";
+import { convertNodesPlusBlockInfoIntoCustomNodes } from "../../helper";
+import { useEdgeStore } from "../../../stores/edgeStore";
+
+export const useFlow = () => {
+ const addNodes = useNodeStore(useShallow((state) => state.addNodes));
+ const addLinks = useEdgeStore(useShallow((state) => state.addLinks));
+
+ const [{ flowID, flowVersion }] = useQueryStates({
+ flowID: parseAsString,
+ flowVersion: parseAsInteger,
+ });
+
+ const { data: graph } = useGetV1GetSpecificGraph(
+ flowID ?? "",
+ flowVersion !== null ? { version: flowVersion } : {},
+ {
+ query: {
+ select: (res) => res.data as GraphModel,
+ enabled: !!flowID,
+ },
+ },
+ );
+
+ const nodes = graph?.nodes;
+ const blockIds = nodes?.map((node) => node.block_id);
+
+ const { data: blocks } = useGetV2GetSpecificBlocks(
+ { block_ids: blockIds ?? [] },
+ {
+ query: {
+ select: (res) => res.data as BlockInfo[],
+ enabled: !!flowID && !!blockIds,
+ },
+ },
+ );
+
+ const customNodes = useMemo(() => {
+ if (!nodes || !blocks) return [];
+
+ return nodes.map((node) => {
+ const customNode = convertNodesPlusBlockInfoIntoCustomNodes(
+ node,
+ blocks?.find((block) => block.id === node.block_id) ??
+ ({} as BlockInfo),
+ );
+ return customNode;
+ });
+ }, [nodes, blocks]);
+
+ useEffect(() => {
+ if (customNodes.length > 0) {
+ addNodes(customNodes);
+ }
+
+ if (graph?.links) {
+ addLinks(graph.links);
+ }
+ }, [customNodes, addNodes, graph?.links]);
+
+ return {};
+};
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ArrayEditor/ArrayEditor.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ArrayEditor/ArrayEditor.tsx
index 3271edcf90..59ed0ee73c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ArrayEditor/ArrayEditor.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ArrayEditor/ArrayEditor.tsx
@@ -22,7 +22,7 @@ export const ArrayEditor = ({
onAddClick,
disabled,
readonly,
- id,
+ id: fieldId,
}: ArrayEditorProps) => {
const { isInputConnected } = useEdgeStore();
@@ -31,12 +31,12 @@ export const ArrayEditor = ({
<div className="flex items-center gap-2">
<div className="flex-1">
{items?.map((element) => {
- const fieldKey = generateHandleId(
- id,
+ const arrayFieldHandleId = generateHandleId(
+ fieldId,
[element.index.toString()],
HandleIdType.ARRAY,
);
- const isConnected = isInputConnected(nodeId, fieldKey);
+ const isConnected = isInputConnected(nodeId, fieldId);
return (
<div
key={element.key}
@@ -45,7 +45,7 @@ export const ArrayEditor = ({
<ArrayEditorContext.Provider
value={{
isArrayItem: true,
- fieldKey,
+ arrayFieldHandleId: arrayFieldHandleId,
isConnected,
}}
>
@@ -75,6 +75,7 @@ export const ArrayEditor = ({
{canAdd && !readonly && !disabled && (
<Button
type="button"
+ variant="secondary"
size="small"
onClick={onAddClick}
className="w-full"
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ArrayEditor/ArrayEditorContext.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ArrayEditor/ArrayEditorContext.tsx
index 0f3d465e0d..09fe11bc94 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ArrayEditor/ArrayEditorContext.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ArrayEditor/ArrayEditorContext.tsx
@@ -2,10 +2,10 @@ import { createContext } from "react";
export const ArrayEditorContext = createContext<{
isArrayItem: boolean;
- fieldKey: string;
+ arrayFieldHandleId: string;
isConnected: boolean;
}>({
isArrayItem: false,
- fieldKey: "",
+ arrayFieldHandleId: "",
isConnected: false,
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ObjectEditor/ObjectEditor.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ObjectEditor/ObjectEditor.tsx
index 6174ac1a83..6c3dd1e96c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ObjectEditor/ObjectEditor.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/components/ObjectEditor/ObjectEditor.tsx
@@ -7,7 +7,11 @@ import { Button } from "@/components/atoms/Button/Button";
import { Input } from "@/components/atoms/Input/Input";
import NodeHandle from "../../handlers/NodeHandle";
import { useEdgeStore } from "@/app/(platform)/build/stores/edgeStore";
-import { generateHandleId, HandleIdType } from "../../handlers/helpers";
+import {
+ generateHandleId,
+ HandleIdType,
+ parseKeyValueHandleId,
+} from "../../handlers/helpers";
export interface ObjectEditorProps {
id: string;
@@ -23,7 +27,7 @@ export interface ObjectEditorProps {
export const ObjectEditor = React.forwardRef<HTMLDivElement, ObjectEditorProps>(
(
{
- id,
+ id: parentFieldId,
value = {},
onChange,
placeholder = "Enter value",
@@ -34,6 +38,9 @@ export const ObjectEditor = React.forwardRef<HTMLDivElement, ObjectEditorProps>(
},
ref,
) => {
+ const getAllHandleIdsOfANode = useEdgeStore(
+ (state) => state.getAllHandleIdsOfANode,
+ );
const setProperty = (key: string, propertyValue: any) => {
if (!onChange) return;
@@ -72,44 +79,47 @@ export const ObjectEditor = React.forwardRef<HTMLDivElement, ObjectEditorProps>(
const { isInputConnected } = useEdgeStore();
+ const allHandleIdsOfANode = getAllHandleIdsOfANode(nodeId);
+ const allKeyValueHandleIdsOfANode = allHandleIdsOfANode.filter((handleId) =>
+ handleId.includes("_#_"),
+ );
+ allKeyValueHandleIdsOfANode.forEach((handleId) => {
+ const key = parseKeyValueHandleId(handleId, HandleIdType.KEY_VALUE);
+ if (!value[key]) {
+ value[key] = null;
+ }
+ });
+
return (
<div
ref={ref}
className={`flex flex-col gap-2 ${className || ""}`}
- id={id}
+ id={parentFieldId}
>
{Object.entries(value).map(([key, propertyValue], idx) => {
- const dynamicHandleId = generateHandleId(
- fieldKey,
+ const isDynamicPropertyConnected = isInputConnected(nodeId, fieldKey);
+ const handleId = generateHandleId(
+ parentFieldId,
[key],
HandleIdType.KEY_VALUE,
);
- const isDynamicPropertyConnected = isInputConnected(
- nodeId,
- dynamicHandleId,
- );
-
- console.log("dynamicHandleId", dynamicHandleId);
- console.log("key", key);
- console.log("fieldKey", fieldKey);
return (
<div key={idx} className="flex flex-col gap-2">
<div className="-ml-2 flex items-center gap-1">
<NodeHandle
- id={dynamicHandleId}
isConnected={isDynamicPropertyConnected}
+ handleId={handleId}
side="left"
/>
-
- <Text variant="small" className="text-gray-600">
+ <Text variant="small" className="!text-gray-500">
#{key.trim() === "" ? "" : key}
</Text>
<Text variant="small" className="!text-green-500">
(string)
</Text>
</div>
- {!isDynamicPropertyConnected && (
+ {!isDynamicPropertyConnected && propertyValue !== null && (
<div className="flex items-center gap-2">
<Input
hideLabel={true}
@@ -150,12 +160,13 @@ export const ObjectEditor = React.forwardRef<HTMLDivElement, ObjectEditorProps>(
<Button
type="button"
+ variant="secondary"
size="small"
onClick={addProperty}
- className="w-full"
+ className="w-fit"
disabled={hasEmptyKeys || disabled}
>
- <Plus className="mr-2 h-4 w-4" />
+ <Plus className="h-4 w-4" />
Add Property
</Button>
</div>
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/edges/CustomEdge.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/edges/CustomEdge.tsx
index ebfc8d97f6..5abb894dd4 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/edges/CustomEdge.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/edges/CustomEdge.tsx
@@ -42,7 +42,7 @@ const CustomEdge = ({
<EdgeLabelRenderer>
<Button
onClick={() => removeConnection(id)}
- className={`absolute z-10 h-fit min-w-0 p-1`}
+ className={`absolute h-fit min-w-0 p-1`}
variant="secondary"
style={{
transform: `translate(-50%, -50%) translate(${labelX}px, ${labelY}px)`,
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/handlers/NodeHandle.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/handlers/NodeHandle.tsx
index b0d72b4a62..4eb2437b65 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/handlers/NodeHandle.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/handlers/NodeHandle.tsx
@@ -2,20 +2,19 @@ import { CircleIcon } from "@phosphor-icons/react";
import { Handle, Position } from "@xyflow/react";
const NodeHandle = ({
- id,
+ handleId,
isConnected,
side,
}: {
- id: string;
+ handleId: string;
isConnected: boolean;
side: "left" | "right";
}) => {
- console.log("id", id);
return (
<Handle
type={side === "left" ? "target" : "source"}
position={side === "left" ? Position.Left : Position.Right}
- id={id}
+ id={handleId}
className={side === "left" ? "-ml-4 mr-2" : "-mr-2 ml-2"}
>
<div className="pointer-events-none">
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/handlers/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/handlers/helpers.ts
index 17b31b1b80..ecacc83146 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/handlers/helpers.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/handlers/helpers.ts
@@ -39,17 +39,17 @@ const sanitizeForHandleId = (str: string): string => {
};
export const generateHandleId = (
- mainKey: string,
+ fieldKey: string,
nestedValues: string[] = [],
type: HandleIdType = HandleIdType.SIMPLE,
): string => {
- if (!mainKey) return "";
+ if (!fieldKey) return "";
- mainKey = fromRjsfId(mainKey);
- mainKey = sanitizeForHandleId(mainKey);
+ fieldKey = fromRjsfId(fieldKey);
+ fieldKey = sanitizeForHandleId(fieldKey);
if (type === HandleIdType.SIMPLE || nestedValues.length === 0) {
- return mainKey;
+ return fieldKey;
}
const sanitizedNestedValues = nestedValues.map((value) =>
@@ -58,60 +58,31 @@ export const generateHandleId = (
switch (type) {
case HandleIdType.NESTED:
- return [mainKey, ...sanitizedNestedValues].join(".");
+ return [fieldKey, ...sanitizedNestedValues].join(".");
case HandleIdType.ARRAY:
- return [mainKey, ...sanitizedNestedValues].join("_$_");
+ return [fieldKey, ...sanitizedNestedValues].join("_$_");
case HandleIdType.KEY_VALUE:
- return [mainKey, ...sanitizedNestedValues].join("_#_");
+ return [fieldKey, ...sanitizedNestedValues].join("_#_");
default:
- return mainKey;
+ return fieldKey;
}
};
-export const parseHandleId = (
+export const parseKeyValueHandleId = (
handleId: string,
-): {
- mainKey: string;
- nestedValues: string[];
- type: HandleIdType;
-} => {
- if (!handleId) {
- return { mainKey: "", nestedValues: [], type: HandleIdType.SIMPLE };
- }
-
- if (handleId.includes("_#_")) {
- const parts = handleId.split("_#_");
- return {
- mainKey: parts[0],
- nestedValues: parts.slice(1),
- type: HandleIdType.KEY_VALUE,
- };
- }
-
- if (handleId.includes("_$_")) {
- const parts = handleId.split("_$_");
- return {
- mainKey: parts[0],
- nestedValues: parts.slice(1),
- type: HandleIdType.ARRAY,
- };
- }
-
- if (handleId.includes(".")) {
- const parts = handleId.split(".");
- return {
- mainKey: parts[0],
- nestedValues: parts.slice(1),
- type: HandleIdType.NESTED,
- };
+ type: HandleIdType,
+): string => {
+ if (type === HandleIdType.KEY_VALUE) {
+ return handleId.split("_#_")[1];
+ } else if (type === HandleIdType.ARRAY) {
+ return handleId.split("_$_")[1];
+ } else if (type === HandleIdType.NESTED) {
+ return handleId.split(".")[1];
+ } else if (type === HandleIdType.SIMPLE) {
+ return handleId.split("_")[1];
}
-
- return {
- mainKey: handleId,
- nestedValues: [],
- type: HandleIdType.SIMPLE,
- };
+ return "";
};
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode.tsx
index 8c42692f7a..b38f2ac9b5 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode.tsx
@@ -26,20 +26,20 @@ export type CustomNodeData = {
export type CustomNode = XYNode<CustomNodeData, "custom">;
export const CustomNode: React.FC<NodeProps<CustomNode>> = React.memo(
- ({ data, id, selected }) => {
+ ({ data, id: nodeId, selected }) => {
const showAdvanced = useNodeStore(
- (state) => state.nodeAdvancedStates[id] || false,
+ (state) => state.nodeAdvancedStates[nodeId] || false,
);
const setShowAdvanced = useNodeStore((state) => state.setShowAdvanced);
if (data.uiType === BlockUIType.NOTE) {
- return <StickyNoteBlock selected={selected} data={data} id={id} />;
+ return <StickyNoteBlock selected={selected} data={data} id={nodeId} />;
}
return (
<div
className={cn(
- "rounded-xl bg-gradient-to-br from-white to-slate-50/30 shadow-lg shadow-slate-900/5 ring-1 ring-slate-200/60 backdrop-blur-sm",
+ "z-12 rounded-xl bg-gradient-to-br from-white to-slate-50/30 shadow-lg shadow-slate-900/5 ring-1 ring-slate-200/60 backdrop-blur-sm",
selected && "shadow-2xl ring-2 ring-slate-200",
)}
>
@@ -49,7 +49,7 @@ export const CustomNode: React.FC<NodeProps<CustomNode>> = React.memo(
variant="large-semibold"
className="tracking-tight text-slate-800"
>
- {data.title} #{id}
+ {data.title}
</Text>
</div>
@@ -57,7 +57,7 @@ export const CustomNode: React.FC<NodeProps<CustomNode>> = React.memo(
<div className="bg-white/40 pb-6 pr-6">
<FormCreator
jsonSchema={preprocessInputSchema(data.inputSchema)}
- nodeId={id}
+ nodeId={nodeId}
uiType={data.uiType}
/>
</div>
@@ -68,13 +68,13 @@ export const CustomNode: React.FC<NodeProps<CustomNode>> = React.memo(
Advanced
</Text>
<Switch
- onCheckedChange={(checked) => setShowAdvanced(id, checked)}
+ onCheckedChange={(checked) => setShowAdvanced(nodeId, checked)}
checked={showAdvanced}
/>
</div>
{/* Output Handles */}
- <OutputHandler outputSchema={data.outputSchema} nodeId={id} />
+ <OutputHandler outputSchema={data.outputSchema} nodeId={nodeId} />
</div>
);
},
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/FormCreator.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/FormCreator.tsx
index 9786f3a596..2e9bbe73e5 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/FormCreator.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/FormCreator.tsx
@@ -20,10 +20,15 @@ export const FormCreator = React.memo(
uiType: BlockUIType;
}) => {
const updateNodeData = useNodeStore((state) => state.updateNodeData);
+ const getHardCodedValues = useNodeStore(
+ (state) => state.getHardCodedValues,
+ );
const handleChange = ({ formData }: any) => {
updateNodeData(nodeId, { hardcodedValues: formData });
};
+ const initialValues = getHardCodedValues(nodeId);
+
return (
<Form
schema={jsonSchema}
@@ -34,6 +39,7 @@ export const FormCreator = React.memo(
formContext={{ nodeId: nodeId, uiType: uiType }}
onChange={handleChange}
uiSchema={uiSchema}
+ formData={initialValues}
/>
);
},
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/OutputHandler.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/OutputHandler.tsx
index ca518d9f84..f0c574d932 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/OutputHandler.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/OutputHandler.tsx
@@ -13,6 +13,7 @@ import {
} from "@/components/atoms/Tooltip/BaseTooltip";
import { useEdgeStore } from "@/app/(platform)/build/stores/edgeStore";
import { getTypeDisplayInfo } from "./helpers";
+import { generateHandleId } from "../handlers/helpers";
export const OutputHandler = ({
outputSchema,
@@ -76,7 +77,12 @@ export const OutputHandler = ({
<Text variant="small" as="span" className={colorClass}>
({displayType})
</Text>
- <NodeHandle id={key} isConnected={isConnected} side="right" />
+
+ <NodeHandle
+ handleId={generateHandleId(key)}
+ isConnected={isConnected}
+ side="right"
+ />
</div>
) : null;
})}
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/AnyOfField/AnyOfField.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/AnyOfField/AnyOfField.tsx
index edbf8a3af2..3a7001272e 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/AnyOfField/AnyOfField.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/AnyOfField/AnyOfField.tsx
@@ -43,12 +43,12 @@ export const AnyOfField = ({
onBlur,
onFocus,
}: FieldProps) => {
- const fieldKey = generateHandleId(idSchema.$id ?? "");
+ const handleId = generateHandleId(idSchema.$id ?? "");
const updatedFormContexrt = { ...formContext, fromAnyOf: true };
const { nodeId } = updatedFormContexrt;
const { isInputConnected } = useEdgeStore();
- const isConnected = isInputConnected(nodeId, fieldKey);
+ const isConnected = isInputConnected(nodeId, handleId);
const {
isNullableType,
nonNull,
@@ -127,7 +127,11 @@ export const AnyOfField = ({
<div className="flex flex-col">
<div className="flex items-center justify-between gap-2">
<div className="-ml-2 flex items-center gap-1">
- <NodeHandle id={fieldKey} isConnected={isConnected} side="left" />
+ <NodeHandle
+ handleId={handleId}
+ isConnected={isConnected}
+ side="left"
+ />
<Text variant="body">
{name.charAt(0).toUpperCase() + name.slice(1)}
</Text>
@@ -151,7 +155,7 @@ export const AnyOfField = ({
return (
<div className="flex flex-col">
<div className="-mb-3 -ml-2 flex items-center gap-1">
- <NodeHandle id={fieldKey} isConnected={isConnected} side="left" />
+ <NodeHandle handleId={handleId} isConnected={isConnected} side="left" />
<Text variant="body">
{name.charAt(0).toUpperCase() + name.slice(1)}
</Text>
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/CredentialField/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/CredentialField/helpers.ts
index 8c02a864d9..1655577058 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/CredentialField/helpers.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/CredentialField/helpers.ts
@@ -25,7 +25,6 @@ export const filterCredentialsByProvider = (
};
export function toDisplayName(provider: string): string {
- console.log("provider", provider);
// Special cases that need manual handling
const specialCases: Record<string, string> = {
aiml_api: "AI/ML",
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/CredentialField/models/OAuthCredentialModal/useOAuthCredentialModal.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/CredentialField/models/OAuthCredentialModal/useOAuthCredentialModal.ts
index 5af6a970fa..cf82ebca70 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/CredentialField/models/OAuthCredentialModal/useOAuthCredentialModal.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/CredentialField/models/OAuthCredentialModal/useOAuthCredentialModal.ts
@@ -64,8 +64,7 @@ export const useOAuthCredentialModal = ({
error: oAuthCallbackError,
} = usePostV1ExchangeOauthCodeForTokens({
mutation: {
- onSuccess: (data) => {
- console.log("OAuth callback successful", data);
+ onSuccess: () => {
queryClient.invalidateQueries({
queryKey: getGetV1ListCredentialsQueryKey(),
});
@@ -116,7 +115,6 @@ export const useOAuthCredentialModal = ({
};
const handleMessage = async (e: MessageEvent<OAuthPopupResultMessage>) => {
- console.log("inside handleMessage");
console.debug("Message received:", e.data);
if (
typeof e.data != "object" ||
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/ObjectField.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/ObjectField.tsx
index 3557ee5365..ce6ae35331 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/ObjectField.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/fields/ObjectField.tsx
@@ -16,12 +16,13 @@ export const ObjectField = (props: FieldProps) => {
const DefaultObjectField = getDefaultRegistry().fields.ObjectField;
// Let the default field render for root or fixed-schema objects
- const isFreeForm =
- !schema.properties ||
- Object.keys(schema.properties).length === 0 ||
- schema.additionalProperties === true;
+ let isFreeForm = false;
+ if ("additionalProperties" in schema || !("properties" in schema)) {
+ isFreeForm = true;
+ }
if (idSchema?.$id === "root" || !isFreeForm) {
+ // TODO : We need to create better one
return <DefaultObjectField {...props} />;
}
@@ -30,7 +31,7 @@ export const ObjectField = (props: FieldProps) => {
return (
<ObjectEditor
- id={`${name}-input`}
+ id={idSchema?.$id ?? ""}
nodeId={nodeId}
fieldKey={fieldKey}
value={formData}
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/helpers.ts
index 984357ed31..5572426dc7 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/helpers.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/helpers.ts
@@ -46,7 +46,6 @@ export function mapJsonSchemaTypeToInputType(
) {
return InputType.MULTI_SELECT;
}
- console.log("schema", schema);
return InputType.ARRAY_EDITOR;
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/templates/FieldTemplate.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/templates/FieldTemplate.tsx
index da265e2da5..f05c4d546d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/templates/FieldTemplate.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/templates/FieldTemplate.tsx
@@ -23,7 +23,7 @@ import { cn } from "@/lib/utils";
import { BlockUIType } from "@/lib/autogpt-server-api";
const FieldTemplate: React.FC<FieldTemplateProps> = ({
- id,
+ id: fieldId,
label,
required,
description,
@@ -39,23 +39,22 @@ const FieldTemplate: React.FC<FieldTemplateProps> = ({
(state) => state.nodeAdvancedStates[nodeId] ?? false,
);
- const {
- isArrayItem,
- fieldKey: arrayFieldKey,
- isConnected: isArrayItemConnected,
- } = useContext(ArrayEditorContext);
+ const { isArrayItem, arrayFieldHandleId } = useContext(ArrayEditorContext);
- let fieldKey = generateHandleId(id);
- let isConnected = isInputConnected(nodeId, fieldKey);
- if (isArrayItem) {
- fieldKey = arrayFieldKey;
- isConnected = isArrayItemConnected;
- }
const isAnyOf = Array.isArray((schema as any)?.anyOf);
const isOneOf = Array.isArray((schema as any)?.oneOf);
const isCredential = isCredentialFieldSchema(schema);
const suppressHandle = isAnyOf || isOneOf;
+ let handleId = null;
+ if (!isArrayItem) {
+ handleId = generateHandleId(fieldId);
+ } else {
+ handleId = arrayFieldHandleId;
+ }
+
+ const isConnected = isInputConnected(nodeId, handleId);
+
if (!showAdvanced && schema.advanced === true && !isConnected) {
return null;
}
@@ -71,11 +70,15 @@ const FieldTemplate: React.FC<FieldTemplateProps> = ({
}
return (
- <div className="mt-4 w-[400px] space-y-1">
+ <div className="mt-4 w-[350px] space-y-1">
{label && schema.type && (
- <label htmlFor={id} className="flex items-center gap-1">
+ <label htmlFor={fieldId} className="flex items-center gap-1">
{!suppressHandle && !fromAnyOf && !isCredential && (
- <NodeHandle id={fieldKey} isConnected={isConnected} side="left" />
+ <NodeHandle
+ handleId={handleId}
+ isConnected={isConnected}
+ side="left"
+ />
)}
{!fromAnyOf && (
<Text
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/helper.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/helper.ts
index fb3f218fec..829755fcfb 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/helper.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/helper.ts
@@ -1,10 +1,15 @@
import { BlockInfo } from "@/app/api/__generated__/models/blockInfo";
-import { CustomNodeData } from "./FlowEditor/nodes/CustomNode";
+import { CustomNode, CustomNodeData } from "./FlowEditor/nodes/CustomNode";
import { BlockUIType } from "./types";
+import { NodeModel } from "@/app/api/__generated__/models/nodeModel";
+import { NodeModelMetadata } from "@/app/api/__generated__/models/nodeModelMetadata";
-export const convertBlockInfoIntoCustomNodeData = (block: BlockInfo) => {
+export const convertBlockInfoIntoCustomNodeData = (
+ block: BlockInfo,
+ hardcodedValues: Record<string, any> = {},
+) => {
const customNodeData: CustomNodeData = {
- hardcodedValues: {},
+ hardcodedValues: hardcodedValues,
title: block.name,
description: block.description,
inputSchema: block.inputSchema,
@@ -13,3 +18,35 @@ export const convertBlockInfoIntoCustomNodeData = (block: BlockInfo) => {
};
return customNodeData;
};
+
+export const convertNodesPlusBlockInfoIntoCustomNodes = (
+ node: NodeModel,
+ block: BlockInfo,
+) => {
+ const customNodeData = convertBlockInfoIntoCustomNodeData(
+ block,
+ node.input_default,
+ );
+ const customNode: CustomNode = {
+ id: node.id ?? "",
+ data: customNodeData,
+ type: "custom",
+ position: {
+ x:
+ (
+ (node.metadata as NodeModelMetadata).position as {
+ x: number;
+ y: number;
+ }
+ )?.x ?? 0,
+ y:
+ (
+ (node.metadata as NodeModelMetadata).position as {
+ x: number;
+ y: number;
+ }
+ )?.y ?? 0,
+ },
+ };
+ return customNode;
+};
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/page.tsx b/autogpt_platform/frontend/src/app/(platform)/build/page.tsx
index 6df571ef61..365d1a0c49 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/page.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/page.tsx
@@ -6,7 +6,7 @@ import FlowEditor from "@/app/(platform)/build/components/legacy-builder/Flow/Fl
import { GraphID } from "@/lib/autogpt-server-api/types";
import { useSearchParams } from "next/navigation";
import { useEffect } from "react";
-import { Flow } from "./components/FlowEditor/Flow";
+import { Flow } from "./components/FlowEditor/Flow/Flow";
import { BuilderViewTabs } from "./components/BuilderViewTabs/BuilderViewTabs";
import { useBuilderView } from "./components/BuilderViewTabs/useBuilderViewTabs";
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/stores/edgeStore.ts b/autogpt_platform/frontend/src/app/(platform)/build/stores/edgeStore.ts
index 6ee4e015a2..7a28b0ddf2 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/stores/edgeStore.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/stores/edgeStore.ts
@@ -1,5 +1,6 @@
import { create } from "zustand";
import { convertConnectionsToBackendLinks } from "../components/FlowEditor/edges/helpers";
+import { Link } from "@/app/api/__generated__/models/link";
export type Connection = {
edge_id: string;
@@ -22,6 +23,9 @@ type EdgeStore = {
getNodeConnections: (nodeId: string) => Connection[];
isInputConnected: (nodeId: string, handle: string) => boolean;
isOutputConnected: (nodeId: string, handle: string) => boolean;
+ addLinks: (links: Link[]) => void;
+
+ getAllHandleIdsOfANode: (nodeId: string) => string[];
};
function makeEdgeId(conn: Omit<Connection, "edge_id">) {
@@ -79,4 +83,20 @@ export const useEdgeStore = create<EdgeStore>((set, get) => ({
(c) => c.source === nodeId && c.sourceHandle === handle,
),
getBackendLinks: () => convertConnectionsToBackendLinks(get().connections),
+
+ addLinks: (links) =>
+ links.forEach((link) => {
+ get().addConnection({
+ edge_id: link.id ?? "",
+ source: link.source_id,
+ target: link.sink_id,
+ sourceHandle: link.source_name,
+ targetHandle: link.sink_name,
+ });
+ }),
+
+ getAllHandleIdsOfANode: (nodeId) =>
+ get()
+ .connections.filter((c) => c.target === nodeId)
+ .map((c) => c.targetHandle),
}));
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/stores/nodeStore.ts b/autogpt_platform/frontend/src/app/(platform)/build/stores/nodeStore.ts
index 8a028a5692..17822c8e03 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/stores/nodeStore.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/stores/nodeStore.ts
@@ -17,6 +17,8 @@ type NodeStore = {
toggleAdvanced: (nodeId: string) => void;
setShowAdvanced: (nodeId: string, show: boolean) => void;
getShowAdvanced: (nodeId: string) => boolean;
+ addNodes: (nodes: CustomNode[]) => void;
+ getHardCodedValues: (nodeId: string) => Record<string, any>;
};
export const useNodeStore = create<NodeStore>((set, get) => ({
@@ -72,4 +74,14 @@ export const useNodeStore = create<NodeStore>((set, get) => ({
})),
getShowAdvanced: (nodeId: string) =>
get().nodeAdvancedStates[nodeId] || false,
+ addNodes: (nodes: CustomNode[]) => {
+ nodes.forEach((node) => {
+ get().addNode(node);
+ });
+ },
+ getHardCodedValues: (nodeId: string) => {
+ return (
+ get().nodes.find((n) => n.id === nodeId)?.data?.hardcodedValues || {}
+ );
+ },
}));
diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/SearchBar/useSearchBar.ts b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/SearchBar/useSearchBar.ts
index e6d6b4837f..4945f8bed3 100644
--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/SearchBar/useSearchBar.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/SearchBar/useSearchBar.ts
@@ -8,7 +8,6 @@ export const useSearchbar = () => {
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
- console.log(searchQuery);
if (searchQuery.trim()) {
const encodedTerm = encodeURIComponent(searchQuery);
diff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.json
index 8584067eeb..744adf0944 100644
--- a/autogpt_platform/frontend/src/app/api/openapi.json
+++ b/autogpt_platform/frontend/src/app/api/openapi.json
@@ -3400,6 +3400,52 @@
}
}
},
+ "/api/builder/blocks/batch": {
+ "get": {
+ "tags": ["v2"],
+ "summary": "Get specific blocks",
+ "description": "Get specific blocks by their IDs.",
+ "operationId": "getV2Get specific blocks",
+ "security": [{ "HTTPBearerJWT": [] }],
+ "parameters": [
+ {
+ "name": "block_ids",
+ "in": "query",
+ "required": true,
+ "schema": {
+ "type": "array",
+ "items": { "type": "string" },
+ "title": "Block Ids"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Successful Response",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "array",
+ "items": { "$ref": "#/components/schemas/BlockInfo" },
+ "title": "Response Getv2Get Specific Blocks"
+ }
+ }
+ }
+ },
+ "422": {
+ "description": "Validation Error",
+ "content": {
+ "application/json": {
+ "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/HTTP401NotAuthenticatedError"
+ }
+ }
+ }
+ },
"/api/builder/providers": {
"get": {
"tags": ["v2"],