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 special handling for AGENT block type in form and output handlers (#11595)
Abhimanyu Yadave640d36265bf
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/CustomNode.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/CustomNode.tsxindex 974cbe3754..52068f3acb 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/CustomNode.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/CustomNode.tsx@@ -106,7 +106,11 @@ export const CustomNode: React.FC<NodeProps<CustomNode>> = React.memo(/><NodeAdvancedToggle nodeId={nodeId} />{data.uiType != BlockUIType.OUTPUT && (- <OutputHandler outputSchema={outputSchema} nodeId={nodeId} />+ <OutputHandler+ uiType={data.uiType}+ outputSchema={outputSchema}+ nodeId={nodeId}+ />)}<NodeDataRenderer 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.tsxindex 315a52f553..cfee0bf89f 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,17 +20,32 @@ export const FormCreator = React.memo(className?: string;}) => {const updateNodeData = useNodeStore((state) => state.updateNodeData);+const getHardCodedValues = useNodeStore((state) => state.getHardCodedValues,);+const handleChange = ({ formData }: any) => {if ("credentials" in formData && !formData.credentials?.id) {delete formData.credentials;}- updateNodeData(nodeId, { hardcodedValues: formData });++ const updatedValues =+ uiType === BlockUIType.AGENT+ ? {+ ...getHardCodedValues(nodeId),+ inputs: formData,+ }+ : formData;++ updateNodeData(nodeId, { hardcodedValues: updatedValues });};- const initialValues = getHardCodedValues(nodeId);+ const hardcodedValues = getHardCodedValues(nodeId);+ const initialValues =+ uiType === BlockUIType.AGENT+ ? (hardcodedValues.inputs ?? {})+ : hardcodedValues;return (<div className={className}>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.tsxindex 9c032ac20f..ab3b648ba9 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@@ -14,13 +14,16 @@ import {import { useEdgeStore } from "@/app/(platform)/build/stores/edgeStore";import { getTypeDisplayInfo } from "./helpers";import { generateHandleId } from "../handlers/helpers";+import { BlockUIType } from "../../types";export const OutputHandler = ({outputSchema,nodeId,+ uiType,}: {outputSchema: RJSFSchema;nodeId: string;+ uiType: BlockUIType;}) => {const { isOutputConnected } = useEdgeStore();const properties = outputSchema?.properties || {};@@ -79,7 +82,9 @@ export const OutputHandler = ({</Text><NodeHandle- handleId={generateHandleId(key)}+ handleId={+ uiType === BlockUIType.AGENT ? key : generateHandleId(key)+ }isConnected={isConnected}side="right"/>diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/useBlockMenuSearch.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/useBlockMenuSearch.tsindex 5e9007e617..3eb14d3ca9 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/useBlockMenuSearch.ts+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/useBlockMenuSearch.ts@@ -7,6 +7,7 @@ import { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";import { getV2GetSpecificAgent } from "@/app/api/__generated__/endpoints/store/store";import {getGetV2ListLibraryAgentsQueryKey,+ getV2GetLibraryAgent,usePostV2AddMarketplaceAgent,} from "@/app/api/__generated__/endpoints/library/library";import {@@ -151,7 +152,12 @@ export const useBlockMenuSearch = () => {});const libraryAgent = response.data as LibraryAgent;- addAgentToBuilder(libraryAgent);++ const { data: libraryAgentDetails } = await getV2GetLibraryAgent(+ libraryAgent.id,+ );++ addAgentToBuilder(libraryAgentDetails as LibraryAgent);toast({title: "Agent Added",diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/MarketplaceAgentsContent/useMarketplaceAgentsContent.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/MarketplaceAgentsContent/useMarketplaceAgentsContent.tsindex 8ca3fe30f5..ff9b70b79a 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/MarketplaceAgentsContent/useMarketplaceAgentsContent.ts+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/MarketplaceAgentsContent/useMarketplaceAgentsContent.ts@@ -1,6 +1,7 @@import { getGetV2GetBuilderItemCountsQueryKey } from "@/app/api/__generated__/endpoints/default/default";import {getGetV2ListLibraryAgentsQueryKey,+ getV2GetLibraryAgent,usePostV2AddMarketplaceAgent,} from "@/app/api/__generated__/endpoints/library/library";import {@@ -105,8 +106,16 @@ export const useMarketplaceAgentsContent = () => {},});+ // Here, libraryAgent has empty input and output schemas.+ // Not updating the endpoint because this endpoint is used elsewhere.+ // TODO: Create a new endpoint for builder specific to marketplace agents.const libraryAgent = response.data as LibraryAgent;- addAgentToBuilder(libraryAgent);++ const { data: libraryAgentDetails } = await getV2GetLibraryAgent(+ libraryAgent.id,+ );++ addAgentToBuilder(libraryAgentDetails as LibraryAgent);toast({title: "Agent Added",diff --git a/autogpt_platform/frontend/src/components/renderers/input-renderer/fields/AnyOfField/AnyOfField.tsx b/autogpt_platform/frontend/src/components/renderers/input-renderer/fields/AnyOfField/AnyOfField.tsxindex 7fb3d9c938..79fa15304d 100644--- a/autogpt_platform/frontend/src/components/renderers/input-renderer/fields/AnyOfField/AnyOfField.tsx+++ b/autogpt_platform/frontend/src/components/renderers/input-renderer/fields/AnyOfField/AnyOfField.tsx@@ -23,6 +23,7 @@ import {TooltipTrigger,} from "@/components/atoms/Tooltip/BaseTooltip";import { cn } from "@/lib/utils";+import { BlockUIType } from "@/app/(platform)/build/components/types";type TypeOption = {type: string;@@ -47,7 +48,14 @@ export const AnyOfField = ({onBlur,onFocus,}: FieldProps) => {- const handleId = generateHandleId(idSchema.$id ?? "");+ const handleId =+ formContext.uiType === BlockUIType.AGENT+ ? (idSchema.$id ?? "")+ .split("_")+ .filter((p) => p !== "root" && p !== "properties" && p.length > 0)+ .join("_") || ""+ : generateHandleId(idSchema.$id ?? "");+const updatedFormContexrt = { ...formContext, fromAnyOf: true };const { nodeId, showHandles = true } = updatedFormContexrt;diff --git a/autogpt_platform/frontend/src/components/renderers/input-renderer/templates/FieldTemplate.tsx b/autogpt_platform/frontend/src/components/renderers/input-renderer/templates/FieldTemplate.tsxindex a056782939..ebc8a1f038 100644--- a/autogpt_platform/frontend/src/components/renderers/input-renderer/templates/FieldTemplate.tsx+++ b/autogpt_platform/frontend/src/components/renderers/input-renderer/templates/FieldTemplate.tsx@@ -58,7 +58,15 @@ const FieldTemplate: React.FC<FieldTemplateProps> = ({let handleId = null;if (!isArrayItem) {- handleId = generateHandleId(fieldId);+ if (uiType === BlockUIType.AGENT) {+ const parts = fieldId.split("_");+ const filtered = parts.filter(+ (p) => p !== "root" && p !== "properties" && p.length > 0,+ );+ handleId = filtered.join("_") || "";+ } else {+ handleId = generateHandleId(fieldId);+ }} else {handleId = arrayFieldHandleId;}