Skip to content

Commit 255b33d

Browse files
je crois que c tj pas bon, eft faut genre que le site detect la résoluti
1 parent 0cfee6f commit 255b33d

7 files changed

Lines changed: 252 additions & 126 deletions

File tree

src/ai/dev.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import '@/ai/flows/generate-project-ideas.ts';
66
import '@/ai/flows/summarize-project-documentation.ts';
77
// import '@/ai/flows/flag-api-key-risks.ts'; // Removed
88
import '@/ai/flows/generate-document-content.ts';
9-
import '@/ai/flows/generate-project-scaffold.ts'; // Added new flow
10-
9+
import '@/ai/flows/generate-project-scaffold.ts';
10+
import '@/ai/flows/edit-file-content-ai.ts'; // Added new flow
1111

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
'use server';
3+
/**
4+
* @fileOverview AI agent for editing file content.
5+
*
6+
* - editFileContentWithAI - A function that modifies existing file content based on a user prompt.
7+
* - EditFileContentAIInput - The input type for the editFileContentWithAI function.
8+
* - EditFileContentAIOutput - The return type for the editFileContentWithAI function.
9+
*/
10+
11+
import {ai} from '@/ai/genkit';
12+
import {z} from 'genkit';
13+
14+
export const EditFileContentAIInputSchema = z.object({
15+
currentContent: z.string().describe('The current content of the file.'),
16+
userPrompt: z.string().describe('A prompt from the user describing the desired changes.'),
17+
});
18+
export type EditFileContentAIInput = z.infer<typeof EditFileContentAIInputSchema>;
19+
20+
export const EditFileContentAIOutputSchema = z.object({
21+
newContent: z
22+
.string()
23+
.describe('The complete, new content of the file after applying the edits.'),
24+
});
25+
export type EditFileContentAIOutput = z.infer<typeof EditFileContentAIOutputSchema>;
26+
27+
export async function editFileContentWithAI(
28+
input: EditFileContentAIInput
29+
): Promise<EditFileContentAIOutput> {
30+
return editFileContentAIFlow(input);
31+
}
32+
33+
const prompt = ai.definePrompt({
34+
name: 'editFileContentAIPrompt',
35+
input: {schema: EditFileContentAIInputSchema},
36+
output: {schema: EditFileContentAIOutputSchema},
37+
prompt: `You are an expert code and text editor.
38+
The user will provide you with the current content of a file and a prompt describing the changes they want to make.
39+
Your task is to return the ENTIRE new content of the file with the requested changes applied.
40+
Do not just provide the changes or a diff. Provide the complete, final file content.
41+
42+
Current File Content:
43+
\`\`\`
44+
{{{currentContent}}}
45+
\`\`\`
46+
47+
User's Edit Request: {{{userPrompt}}}
48+
49+
Return the new, complete file content below:
50+
`,
51+
});
52+
53+
const editFileContentAIFlow = ai.defineFlow(
54+
{
55+
name: 'editFileContentAIFlow',
56+
inputSchema: EditFileContentAIInputSchema,
57+
outputSchema: EditFileContentAIOutputSchema,
58+
},
59+
async input => {
60+
const {output} = await prompt(input);
61+
if (!output || !output.newContent) {
62+
// Fallback or error handling if AI doesn't return expected output
63+
console.error("AI did not return the expected new content for file editing.");
64+
// Optionally, return original content or throw an error
65+
return { newContent: input.currentContent };
66+
}
67+
return output;
68+
}
69+
);

src/app/(app)/profile/page.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
import { useAuth } from '@/hooks/useAuth';
55
import { Card, CardContent, CardDescription, CardHeader, CardTitle, CardFooter } from '@/components/ui/card';
66
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
7-
import { User as UserIcon, Mail, Shield, Edit3, Image as ImageIcon, Github, Link2, PowerOff, ExternalLink, MessageSquare } from 'lucide-react';
7+
import { User as UserIcon, Mail, Shield, Edit3, Image as ImageIcon, Github, Link2, PowerOff, ExternalLink, MessageSquare, Loader2 } from 'lucide-react'; // Added Loader2
88
import { Skeleton } from '@/components/ui/skeleton';
99
import { Button } from '@/components/ui/button';
1010
import { Input } from '@/components/ui/input';
1111
import { Label } from '@/components/ui/label';
1212
import { useForm } from 'react-hook-form';
1313
import { zodResolver } from '@hookform/resolvers/zod';
1414
import * as z from 'zod';
15-
import { useEffect, useState, useActionState, startTransition as ReactStartTransition } from 'react';
15+
import { useEffect, useState, useActionState, startTransition } from 'react'; // Corrected import
1616
import { useToast } from '@/hooks/use-toast';
1717
import * as authService from '@/lib/authService';
18-
import { fetchUserGithubOAuthTokenAction, disconnectGithubAction, fetchGithubUserDetailsAction } from '@/app/(app)/projects/[id]/actions'; // Re-using from project actions for now
18+
import { fetchUserGithubOAuthTokenAction, disconnectGithubAction, fetchGithubUserDetailsAction } from '@/app/(app)/projects/[id]/actions';
1919
import { useRouter } from 'next/navigation';
2020
import Link from 'next/link';
2121

@@ -89,7 +89,7 @@ export default function ProfilePage() {
8989

9090
useEffect(() => {
9191
if (!isDisconnectPending && disconnectState) {
92-
if (disconnectState.success) {
92+
if (disconnectState.success && disconnectState.message) { // Check for message
9393
toast({ title: "Success", description: disconnectState.message });
9494
setGithubToken(null);
9595
setGithubUserDetails(null);
@@ -172,7 +172,7 @@ export default function ProfilePage() {
172172

173173
const handleDisconnectGitHub = () => {
174174
const dummyFormData = new FormData(); // useActionState requires FormData
175-
ReactStartTransition(() => {
175+
startTransition(() => { // Corrected usage
176176
disconnectFormAction(dummyFormData);
177177
});
178178
};

src/app/(app)/projects/[id]/actions.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { auth } from '@/lib/authEdge';
4040
import { Octokit } from 'octokit';
4141
import { Buffer } from 'buffer';
4242
import { generateProjectScaffold, type GenerateProjectScaffoldInput, type GenerateProjectScaffoldOutput } from '@/ai/flows/generate-project-scaffold';
43+
import { editFileContentWithAI, type EditFileContentAIInput, type EditFileContentAIOutput } from '@/ai/flows/edit-file-content-ai';
4344

4445

4546
export async function fetchProjectAction(uuid: string | undefined): Promise<Project | null> {
@@ -1213,7 +1214,7 @@ export async function fetchGithubUserDetailsAction(targetUserUuid?: string): Pro
12131214
}
12141215

12151216

1216-
export async function disconnectGithubAction(formData?: FormData): Promise<{ success: boolean; error?: string; message?: string }> {
1217+
export async function disconnectGithubAction(prevState: { success: boolean; error?: string; message?: string }, formData: FormData): Promise<{ success: boolean; error?: string; message?: string }> {
12171218
const session = await auth();
12181219
if (!session?.user?.uuid) {
12191220
return { success: false, error: "Authentication required." };
@@ -1762,3 +1763,33 @@ export async function generateProjectFilesWithAIAction(
17621763
return { error: `AI Generation Failed: ${error.message || "An unexpected error occurred."}` };
17631764
}
17641765
}
1766+
1767+
export async function editFileWithAIAction(
1768+
projectUuid: string,
1769+
currentContent: string,
1770+
userPrompt: string
1771+
): Promise<EditFileContentAIOutput | { error: string }> {
1772+
const session = await auth();
1773+
if (!session?.user?.uuid) {
1774+
return { error: "Authentication required." };
1775+
}
1776+
1777+
const project = await dbGetProjectByUuid(projectUuid);
1778+
if (!project || !project.githubRepoName) {
1779+
return { error: "Project not found or not linked to GitHub." };
1780+
}
1781+
1782+
const userRole = await dbGetProjectMemberRole(projectUuid, session.user.uuid);
1783+
if (!userRole || !['owner', 'co-owner', 'editor'].includes(userRole)) {
1784+
return { error: "You do not have permission to edit files in this project using AI." };
1785+
}
1786+
1787+
try {
1788+
const aiInput: EditFileContentAIInput = { currentContent, userPrompt };
1789+
const aiOutput = await editFileContentWithAI(aiInput);
1790+
return aiOutput;
1791+
} catch (error: any) {
1792+
console.error("Error editing file with AI:", error);
1793+
return { error: `AI file editing failed: ${error.message || "An unexpected error occurred."}` };
1794+
}
1795+
}

0 commit comments

Comments
 (0)