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

Code before:
          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 &&
                String(inputData[key]).trim() !== "") ||
              (schema.default != null && String(schema.default).trim() !== "");

            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() !== "",
            );

Review comment (refactor):
Please remove this string conversion. The not-null check is enough, right?

Code after:
            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() !== "",
            );

            if (hasAllDependencies && !hasValue) {
              setNestedProperty(