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.
fix(frontend): Fill defaults from schema to `hardcodedValues` in `CustomNode.tsx` (#9772)
Krzysztof Czerwinski0aeaaa7801ff
diff --git a/autogpt_platform/frontend/src/components/CustomNode.tsx b/autogpt_platform/frontend/src/components/CustomNode.tsxindex 948c2389b6..9735432d07 100644--- a/autogpt_platform/frontend/src/components/CustomNode.tsx+++ b/autogpt_platform/frontend/src/components/CustomNode.tsx@@ -147,14 +147,46 @@ export const CustomNode = React.memo(setIsAnyModalOpen?.(isModalOpen || isOutputModalOpen);}, [isModalOpen, isOutputModalOpen, data, setIsAnyModalOpen]);- useEffect(() => {- isInitialSetup.current = false;+ const fillDefaults = useCallback((obj: any, schema: any) => {+ // Iterate over the schema properties+ for (const key in schema.properties) {+ if (schema.properties.hasOwnProperty(key)) {+ const propertySchema = schema.properties[key];++ // If the property is not in the object, initialize it with the default value+ if (!obj.hasOwnProperty(key)) {+ if (propertySchema.default !== undefined) {+ obj[key] = propertySchema.default;+ } else if (propertySchema.type === "object") {+ // Recursively fill defaults for nested objects+ obj[key] = fillDefaults({}, propertySchema);+ } else if (propertySchema.type === "array") {+ // Recursively fill defaults for arrays+ obj[key] = fillDefaults([], propertySchema);+ }+ } else {+ // If the property exists, recursively fill defaults for nested objects/arrays+ if (propertySchema.type === "object") {+ obj[key] = fillDefaults(obj[key], propertySchema);+ } else if (propertySchema.type === "array") {+ obj[key] = fillDefaults(obj[key], propertySchema);+ }+ }+ }+ }++ return obj;}, []);const setHardcodedValues = (values: any) => {updateNodeData(id, { hardcodedValues: values });};+ useEffect(() => {+ isInitialSetup.current = false;+ setHardcodedValues(fillDefaults(data.hardcodedValues, data.inputSchema));+ }, []);+const setErrors = (errors: { [key: string]: string }) => {updateNodeData(id, { errors });};diff --git a/autogpt_platform/frontend/src/components/Flow.tsx b/autogpt_platform/frontend/src/components/Flow.tsxindex fa6571934c..9b62ac9507 100644--- a/autogpt_platform/frontend/src/components/Flow.tsx+++ b/autogpt_platform/frontend/src/components/Flow.tsx@@ -461,37 +461,6 @@ const FlowEditor: React.FC<{});}, [nodes, setViewport, x, y]);- const fillDefaults = useCallback((obj: any, schema: any) => {- // Iterate over the schema properties- for (const key in schema.properties) {- if (schema.properties.hasOwnProperty(key)) {- const propertySchema = schema.properties[key];-- // If the property is not in the object, initialize it with the default value- if (!obj.hasOwnProperty(key)) {- if (propertySchema.default !== undefined) {- obj[key] = propertySchema.default;- } else if (propertySchema.type === "object") {- // Recursively fill defaults for nested objects- obj[key] = fillDefaults({}, propertySchema);- } else if (propertySchema.type === "array") {- // Recursively fill defaults for arrays- obj[key] = fillDefaults([], propertySchema);- }- } else {- // If the property exists, recursively fill defaults for nested objects/arrays- if (propertySchema.type === "object") {- obj[key] = fillDefaults(obj[key], propertySchema);- } else if (propertySchema.type === "array") {- obj[key] = fillDefaults(obj[key], propertySchema);- }- }- }- }-- return obj;- }, []);-const addNode = useCallback((blockId: string, nodeType: string, hardcodedValues: any = {}) => {const nodeSchema = availableNodes.find((node) => node.id === blockId);@@ -538,10 +507,7 @@ const FlowEditor: React.FC<{categories: nodeSchema.categories,inputSchema: nodeSchema.inputSchema,outputSchema: nodeSchema.outputSchema,- hardcodedValues: {- ...fillDefaults({}, nodeSchema.inputSchema),- ...hardcodedValues,- },+ hardcodedValues: hardcodedValues,connections: [],isOutputOpen: false,block_id: blockId,