Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/frontend/src/hooks/useAgentGraph.ts (TypeScript)

Code before:
          ) {
            return;
          }
          console.warn("Error", error);
          errorMessage = error.message || "Invalid input";
          if (path && error.message) {
            const key = path.slice(1);
            console.log("Error", key, error.message);
            setNestedProperty(
              errors,
              key,
              error.message[0].toUpperCase() + error.message.slice(1),
            );
          } else if (error.keyword === "required") {
            const key = error.params.missingProperty;
            setNestedProperty(errors, key, "This field is required");
          }
        });
      } 
      
      Object.entries(node.data.inputSchema.properties || {}).forEach(([key, schema]) => {
        if ('depends_on' in schema) {
          const dependencies = Array.isArray(schema.depends_on) ? schema.depends_on : [schema.depends_on];
          
          // Check if dependent field is set while required fields are empty
          const hasValue = inputData[key as keyof typeof inputData] && String(inputData[key as keyof typeof inputData]).length > 0;
          const missingDependencies = dependencies.filter(dep => !inputData[dep as keyof typeof inputData] || String(inputData[dep as keyof typeof inputData]).length === 0);
          
          if (hasValue && missingDependencies.length > 0) {
            errors[key] = `Requires ${missingDependencies.join(', ')} to be set`;
            errorMessage = `Field ${key} requires ${missingDependencies.join(', ')} to be set`;
          }
          
          // Check if required fields are set but dependent field is empty
          const hasAllDependencies = dependencies.every(dep => 
            inputData[dep as keyof typeof inputData] && 
            String(inputData[dep as keyof typeof inputData]).length > 0
          );
          if (hasAllDependencies && (!inputData[key as keyof typeof inputData] || String(inputData[key as keyof typeof inputData]).length === 0)) {
            errors[key] = `This field is required when ${dependencies.join(', ')} are set`;
            errorMessage = `${key} is required when ${dependencies.join(', ')} are set`;
          }
        }
      });


      // Set errors
      setNodes((nodes) => {
        return nodes.map((n) => {
          if (n.id === node.id) {
            return {

Review comment (suggestion):
- Does this take defaults into account?
- This check breaks when the value is `false`. 

```suggestion
          const mustHaveValue = inputSchema.required && key in inputSchema.required;
          const hasValue = schema.default != null || inputData[key] != null;
```

Code after:
          }
          console.warn("Error", error);
          errorMessage = error.message || "Invalid input";
          if (path && error.message) {
            const key = path.slice(1);
            console.log("Error", key, error.message);
            setNestedProperty(
              errors,
              key,
              error.message[0].toUpperCase() + error.message.slice(1),
            );
          } else if (error.keyword === "required") {
            const key = error.params.missingProperty;
            setNestedProperty(errors, key, "This field is required");
          }
        });
      }

      Object.entries(node.data.inputSchema.properties || {}).forEach(
        ([key, schema]) => {
          if (schema.depends_on) {
            const dependencies = schema.depends_on;

            // Check if dependent field has value
            const hasValue =
              inputData[key] != null ||
              ("default" in schema && schema.default != null);

            const mustHaveValue = node.data.inputSchema.required?.includes(key);

            // Check for missing dependencies when dependent field is present
            const missingDependencies = dependencies.filter(
              (dep) =>
                !inputData[dep as keyof typeof inputData] ||
                String(inputData[dep as keyof typeof inputData]).trim() === "",
            );

            if ((hasValue || mustHaveValue) && missingDependencies.length > 0) {
              setNestedProperty(
                errors,
                key,
                `Requires ${missingDependencies.join(", ")} to be set`,
              );
              errorMessage = `Field ${key} requires ${missingDependencies.join(", ")} to be set`;
            }

            // Check if field is required when dependencies are present
            const hasAllDependencies = dependencies.every(
              (dep) =>
                inputData[dep as keyof typeof inputData] &&
                String(inputData[dep as keyof typeof inputData]).trim() !== "",