diff --git a/waspc/src/Wasp/AI/GenerateNewProject.hs b/waspc/src/Wasp/AI/GenerateNewProject.hs index 3250770213..b2759c44d4 100644 --- a/waspc/src/Wasp/AI/GenerateNewProject.hs +++ b/waspc/src/Wasp/AI/GenerateNewProject.hs @@ -76,11 +76,8 @@ generateNewProject newProjectDetails waspProjectSkeletonFiles = do writeToLog "Fixing any mistakes in pages..." forM_ (getPageComponentPath <$> pages) $ \pageFp -> do - fixPageComponent newProjectDetails waspFilePath pageFp + fixPageComponent newProjectDetails waspFilePath pageFp actions queries writeToLog $ T.pack $ "Fixed '" <> pageFp <> "' page." - -- forM_ getPageComponentPath pages $ \pageFp -> do - -- fixPageComponent newProjectDetails waspFilePath pageFp - -- writeToLog $ T.pack $ "Fixed '" <> pageFp <> "' page." writeToLog "Pages fixed." (promptTokensUsed, completionTokensUsed) <- getTotalTokensUsage diff --git a/waspc/src/Wasp/AI/GenerateNewProject/OperationsJsFile.hs b/waspc/src/Wasp/AI/GenerateNewProject/OperationsJsFile.hs index b63ceb0c85..c7e5fafd77 100644 --- a/waspc/src/Wasp/AI/GenerateNewProject/OperationsJsFile.hs +++ b/waspc/src/Wasp/AI/GenerateNewProject/OperationsJsFile.hs @@ -75,6 +75,11 @@ fixOperationsJsFile newProjectDetails waspFilePath opJsFilePath = do - There might be some invalid JS syntax -> fix it if there is any. - If there is some obvious refactoring that could improve code quality, go for it. + - Use the "arg" variable to get the arguments of the operation. + For example, if the operation is "createTask", then you can get the arguments like this: + ```js + const { name, description } = arg; + ``` With this in mind, generate a new, fixed NodeJS file with operations (${opJsFilePathText}). Do actual fixes, don't leave comments with "TODO"! diff --git a/waspc/src/Wasp/AI/GenerateNewProject/Page.hs b/waspc/src/Wasp/AI/GenerateNewProject/Page.hs index af59fb4ac9..d6c8cb7207 100644 --- a/waspc/src/Wasp/AI/GenerateNewProject/Page.hs +++ b/waspc/src/Wasp/AI/GenerateNewProject/Page.hs @@ -4,6 +4,7 @@ module Wasp.AI.GenerateNewProject.Page ( generateAndWritePage, pageDocPrompt, getPageComponentPath, + operationInfo, Page (..), ) where diff --git a/waspc/src/Wasp/AI/GenerateNewProject/PageComponentFile.hs b/waspc/src/Wasp/AI/GenerateNewProject/PageComponentFile.hs index 51705f136d..f372fc94cd 100644 --- a/waspc/src/Wasp/AI/GenerateNewProject/PageComponentFile.hs +++ b/waspc/src/Wasp/AI/GenerateNewProject/PageComponentFile.hs @@ -19,11 +19,12 @@ import Wasp.AI.GenerateNewProject.Common ) import Wasp.AI.GenerateNewProject.Common.Prompts (appDescriptionBlock) import qualified Wasp.AI.GenerateNewProject.Common.Prompts as Prompts -import Wasp.AI.GenerateNewProject.Page (pageDocPrompt) +import Wasp.AI.GenerateNewProject.Operation (Operation) +import Wasp.AI.GenerateNewProject.Page (operationInfo, pageDocPrompt) import Wasp.AI.OpenAI.ChatGPT (ChatMessage (..), ChatRole (..)) -fixPageComponent :: NewProjectDetails -> FilePath -> FilePath -> CodeAgent () -fixPageComponent newProjectDetails waspFilePath pageComponentPath = do +fixPageComponent :: NewProjectDetails -> FilePath -> FilePath -> [Operation] -> [Operation] -> CodeAgent () +fixPageComponent newProjectDetails waspFilePath pageComponentPath actions queries = do currentWaspFileContent <- fromMaybe (error "couldn't find wasp file") <$> getFile waspFilePath currentPageComponentContent <- fromMaybe (error "couldn't find page file to fix") <$> getFile pageComponentPath fixedPageComponent <- @@ -34,6 +35,9 @@ fixPageComponent newProjectDetails waspFilePath pageComponentPath = do ] writeToFile pageComponentPath (const $ pageComponentImpl fixedPageComponent) where + actionsInfo = T.intercalate "\n" $ (" - " <>) . operationInfo <$> actions + queriesInfo = T.intercalate "\n" $ (" - " <>) . operationInfo <$> queries + fixPageComponentPrompt currentWaspFileContent currentPageContent = [trimming| ${basicWaspLangInfoPrompt} @@ -60,16 +64,21 @@ fixPageComponent newProjectDetails waspFilePath pageComponentPath = do The NodeJS file with operations likely has some mistakes: let's fix it! Some common mistakes to look for: - - "TODO" comments or "..." that should be replaced with actual implementation. - Fix these by replacing them with actual implementation. - - Duplicate imports. If there are any, make sure to remove them. - - There might be some invalid JS or JSX syntax -> fix it if there is any. - - If there is some obvious refactoring that could improve code quality, go for it. - - Make sure to use valid queries and actions that are defined in the Wasp file. + - Make sure to use only queries and actions that are defined in the Wasp file (listed below) - You should import queries from "@wasp/queries/{queryName}" like import getTask from '@wasp/queries/getTasks'; - You should import actions from "@wasp/actions/{actionName}" like import createTask from '@wasp/actions/createTask'; - Use Tailwind CSS to style the page if you didn't. - Use component from "react-router-dom" to link to other pages where needed. + - "TODO" comments or "..." that should be replaced with actual implementation. + Fix these by replacing them with actual implementation. + - Duplicate imports. If there are any, make sure to remove them. + - There might be some invalid JS or JSX syntax -> fix it if there is any. + + Actions: + ${actionsInfo} + + Queries: + ${queriesInfo} With this in mind, generate a new, fixed React component (${pageComponentPathText}). Do actual fixes, don't leave comments with "TODO"! diff --git a/waspc/src/Wasp/AI/GenerateNewProject/WaspFile.hs b/waspc/src/Wasp/AI/GenerateNewProject/WaspFile.hs index 71d2555489..aba3705105 100644 --- a/waspc/src/Wasp/AI/GenerateNewProject/WaspFile.hs +++ b/waspc/src/Wasp/AI/GenerateNewProject/WaspFile.hs @@ -95,8 +95,26 @@ fixWaspFile newProjectDetails waspFilePath = do - Value of `fn:` field in `query` or `action` not having correct import syntax, for example it might have invalid syntax, e.g. `fn: @server/actions.js`. Fix these by replacing it with correct syntax, e.g. `fn: import { actionName } from "@server/actions.js"`. - - Entities having a reference to another entity but that entity doesn't have a reference back to it. - Fix these by adding a reference back to the entity that is referenced. + - If two entities are in a relation, make sure that they both have a field that references the other entity. + - If an entity has a field that references another entity (e.g. location), make sure to include @relation directive on that field. + - If an entity references another entity, make sure the ID field (e.g. locationId) of the referenced entity is also included. + + ``` + entity Location {=psl + id Int @id @default(autoincrement()) + latitude Float + longitude Float + weathers Weather[] + psl=} + + entity Weather {=psl + id Int @id @default(autoincrement()) + temperature Float + description String + location Location @relation(fields: [locationId], references: [id]) + locationId Int + psl=} + ``` With this in mind, generate a new, fixed wasp file. Do actual fixes, don't leave comments with "TODO"!