Skip to content

Commit e8e94e6

Browse files
committed
[BACKEND - FIXED GEMINI ERROR] | fixed the gemini error and adjusted the controllers
1 parent a9ce34e commit e8e94e6

9 files changed

Lines changed: 78 additions & 79 deletions

File tree

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bun format

apps/client/src/components/Project/Editor.tsx

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,28 @@ export default function Editor({
2323

2424
if (Object.keys(files).length > 0) {
2525
const timeout = setTimeout(() => {
26-
console.log(githubUrl);
27-
console.log(githubUrl.replace("https://api.github.com/repos/", ""));
28-
console.log(
29-
githubUrl
30-
.replace("https://api.github.com/repos/", "")
31-
.replace(".git", "")
32-
);
33-
sdk
34-
.embedGithubProject(
35-
containerRef.current!,
36-
githubUrl
37-
.replace("https://api.github.com/repos/", "")
38-
.replace(".git", "")
39-
)
40-
.then((vm) => {
41-
if (!cancelled) {
42-
setIsLoaded(true);
43-
vmRef.current = vm;
44-
}
45-
})
46-
.catch((err) => {
47-
console.error("StackBlitz embed error:", err);
48-
49-
// Set error state
50-
setError(err?.message || "Failed to load StackBlitz");
26+
// sdk
27+
// .embedGithubProject(
28+
// containerRef.current!,
29+
// githubUrl
30+
// .replace("https://api.github.com/repos/", "")
31+
// .replace(".git", "")
32+
// )
33+
// .then((vm) => {
34+
// if (!cancelled) {
35+
// setIsLoaded(true);
36+
// vmRef.current = vm;
37+
// }
38+
// })
39+
// .catch((err) => {
40+
// console.error("StackBlitz embed error:", err);
5141

42+
// // Set error state
43+
// setError(err?.message || "Failed to load StackBlitz");
44+
// })
5245
// Optional fallback: embed a custom project if GitHub embed fails
5346
// Uncomment if you want fallback
54-
/*
47+
5548
sdk.embedProject(
5649
containerRef.current!,
5750
{
@@ -77,9 +70,9 @@ export default function Editor({
7770
console.error("Fallback embed error:", fallbackErr);
7871
setError(fallbackErr?.message || "Failed to load StackBlitz fallback");
7972
});
80-
*/
81-
});
82-
}, 300);
73+
74+
// });
75+
}, 1000);
8376

8477
return () => {
8578
cancelled = true;

apps/server/controller/AiFeatures.controllers.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
generateFileStructurePrompt,
77
generateSDDDocument,
88
} from "../utils/prompt";
9+
import {parse} from 'yaml';
910

1011
class GeminiAiFeatures {
1112
availableKey: string;
@@ -41,23 +42,20 @@ class GeminiAiFeatures {
4142
const response = await this.jsonModel.models.generateContent({
4243
model: "gemini-2.0-flash",
4344
contents: prompt,
44-
config: {
45-
responseMimeType: "application/json",
46-
responseSchema: {
47-
type: Type.ARRAY,
48-
items: {
49-
type: Type.OBJECT,
50-
properties: {
51-
path: { type: Type.STRING },
52-
content: { type: Type.STRING },
53-
},
54-
required: ["path", "content"],
55-
},
56-
},
57-
},
5845
});
5946

60-
return response.text;
47+
console.log(response.text);
48+
console.log("_______________________");
49+
const parsedText = response.text.replace('```yaml',"").replace("```","")
50+
// TODO: use a json to yaml converter inorder to get the repsonse is json and return the project_dir object value
51+
// inside of an array
52+
const parsedObject = parse(parsedText);
53+
console.log(parsedObject);
54+
console.log("_______________________");
55+
56+
console.log(parsedObject.project_dir);
57+
58+
return parsedObject.project_dir;
6159
}
6260

6361
async getResponseText(

apps/server/controller/project.controllers.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,30 @@ class ProjectController {
2121

2222
const githubToken =
2323
dbUser.githubToken || "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";
24-
const createRepository = await new githubController(
25-
githubToken
26-
).createRepository(name, description);
27-
28-
if (!createRepository) {
29-
throw new Error("Error in creating repository");
30-
}
31-
24+
3225
const generatedPrompt =
3326
await gptFeaturesControllers.enhanceUserGivenDescription(description);
27+
28+
console.log("generated prompt is : ",generatedPrompt);
29+
3430
if (!generatedPrompt) {
3531
throw new Error("Couln't generate SRS");
3632
}
3733

3834
const generatedFileStructure =
39-
await gptFeaturesControllers.generateProjectFolderStructure(
35+
await AiFeaturesControllers.generateProjectFileStructure(
4036
generatedPrompt
4137
);
38+
39+
console.log("generated prompt is : ",generatedPrompt);
4240
if (!generatedFileStructure) {
4341
throw new Error("error in creating folder structure for your project");
4442
}
4543

46-
let createdFileStructure = JSON.parse(generatedFileStructure);
44+
let createdFileStructure = generatedFileStructure;
4745
const createFileSystem: Record<string, string> = {};
4846

49-
if (Object.keys(createdFileStructure).length > 0) {
47+
if (createdFileStructure.length > 0) {
5048
for (const file in createdFileStructure) {
5149
if (
5250
createdFileStructure[file].path &&
@@ -65,12 +63,21 @@ class ProjectController {
6563
}
6664
}
6765
}
68-
66+
console.log(createdFileStructure);
67+
6968
const getSDD = await AiFeaturesControllers.generateSDD(
7069
generatedPrompt,
7170
JSON.stringify(createFileSystem)
7271
);
7372

73+
const createRepository = await new githubController(
74+
githubToken
75+
).createRepository(name, description);
76+
77+
if (!createRepository) {
78+
throw new Error("Error in creating repository");
79+
}
80+
7481
const createdProject = await prisma.project.create({
7582
data: {
7683
name,

apps/server/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@google/genai": "^1.9.0",
2626
"@google/generative-ai": "^0.24.1",
2727
"@octodock/octolog": "workspace:*",
28+
"@octodock/prisma": "*",
2829
"@types/jsonwebtoken": "^9.0.10",
2930
"@types/passport": "^1.0.17",
3031
"apollo-server-express": "^3.13.0",
@@ -54,7 +55,7 @@
5455
"passport-github2": "^0.1.12",
5556
"prisma": "^6.11.0",
5657
"tsup": "^8.5.0",
57-
"zod": "^4.0.5",
58-
"@octodock/prisma": "*"
58+
"yaml": "^2.8.1",
59+
"zod": "^4.0.5"
5960
}
6061
}

apps/server/utils/keymanager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ class GeminiKeyManager {
7171

7272
// Initialize the GeminiKeyManager with API keys
7373
const keyManager = new GeminiKeyManager([
74+
"AIzaSyBninrss6yavN9W4amrNB9Fj4mfPZZZ-3Y",
7475
"AIzaSyA7c-oXClHSPlb26klR7H66KxjV7J_dobw",
75-
"AIzaSyCWiWcnKPRQo0m-O7RXa1HRQpjMOx3RXC4",
7676
"AIzaSyC5N_RPX7j3TnTZpOpqeWt12zyxjGnPjIU",
77-
"AIzaSyBninrss6yavN9W4amrNB9Fj4mfPZZZ-3Y"
77+
"AIzaSyCWiWcnKPRQo0m-O7RXa1HRQpjMOx3RXC4",
7878
]);
7979

8080
export default keyManager;

apps/server/utils/prompt.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,20 @@ You are given a Software Requirements Specification (SRS) document.
8888
8989
Your task is to return a realistic and production-grade backend project file structure that implements the described system, using best practices for a Node.js or python or springboot backend project.
9090
91-
### Output Format
91+
### Output Format YAML
9292
9393
Respond with **only** a JavaScript or django or springboot array of file paths, like this:
9494
95-
[
96-
'src/index.js',
97-
'src/database.js',
98-
'src/routes.js',
99-
'src/controller.js',
100-
'src/model.js',
101-
]
95+
project_dir
96+
- 'src/index.js',
97+
- 'src/database.js',
98+
- 'src/routes.js',
99+
- 'src/controller.js',
100+
- 'src/model.js',
102101
103102
### Rules
104-
105-
- The array should contain full relative paths to each file.
103+
- The yaml should contain full relative paths to each file.
104+
- follow the strict yaml format and nothing more
106105
- Include meaningful folders and subfolders (e.g. src, routes, controllers, models, middleware, utils).
107106
- Follow best practices for organizing a scalable Node.js or django backend.
108107
- Do **not** include folder names as objects — just file paths as strings.

bun.lock

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"dev": "turbo run dev",
77
"lint": "turbo run lint",
88
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
9-
"check-types": "turbo run check-types"
9+
"check-types": "turbo run check-types",
10+
"prepare": "husky"
1011
},
1112
"devDependencies": {
13+
"husky": "^9.1.7",
1214
"prettier": "^3.6.0",
1315
"turbo": "^2.5.4",
1416
"typescript": "5.8.2"

0 commit comments

Comments
 (0)