Mirrored from https://github.com/Camo67/OCIU-npo.git
Synced Nov 21, 06:00 UTC
fix/ociu-hero-navigation-20261109
| 1 | import React, { useState } from 'react'; |
| 2 | import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; |
| 3 | import { Button } from "@/components/ui/button"; |
| 4 | import { Input } from "@/components/ui/input"; |
| 5 | import { Box, Wrench, Lightbulb, CheckSquare } from "lucide-react"; |
| 6 | import { toast } from "sonner"; |
| 7 | |
| 8 | export const AIBuilder = () => { |
| 9 | const [idea, setIdea] = useState(""); |
| 10 | const [isBuilding, setIsBuilding] = useState(false); |
| 11 | const [blueprint, setBlueprint] = useState<string | null>(null); |
| 12 | |
| 13 | const handleBuildIdea = async () => { |
| 14 | if (!idea) { |
| 15 | toast.error("Please describe your idea"); |
| 16 | return; |
| 17 | } |
| 18 | setIsBuilding(true); |
| 19 | try { |
| 20 | const response = await fetch('http://localhost:8000/api/agent/code', { |
| 21 | method: 'POST', |
| 22 | headers: { 'Content-Type': 'application/json' }, |
| 23 | body: JSON.stringify({ prompt: `Build a plan and app structure for: ${idea}` }), |
| 24 | }); |
| 25 | const data = await response.json(); |
| 26 | setBlueprint(data.output); |
| 27 | toast.success("AI Blueprint generated!"); |
| 28 | } catch (error) { |
| 29 | toast.error("Failed to build idea"); |
| 30 | } finally { |
| 31 | setIsBuilding(false); |
| 32 | } |
| 33 | }; |
| 34 | |
| 35 | return ( |
| 36 | <Card className="border-growth/50 bg-growth/5"> |
| 37 | <CardHeader> |
| 38 | <CardTitle className="flex items-center gap-2"> |
| 39 | <Box className="text-growth" /> |
| 40 | OCIU AI Builder |
| 41 | </CardTitle> |
| 42 | <p className="text-sm text-muted-foreground">Turn your ideas into tools, workflows, or apps.</p> |
| 43 | </CardHeader> |
| 44 | <CardContent className="space-y-4"> |
| 45 | <div className="space-y-2"> |
| 46 | <div className="flex items-center gap-2 text-xs font-medium text-growth mb-1"> |
| 47 | <Lightbulb size={14} /> What do you want to build? |
| 48 | </div> |
| 49 | <Input |
| 50 | placeholder="e.g. A community garden scheduling tool" |
| 51 | value={idea} |
| 52 | onChange={(e) => setIdea(e.target.value)} |
| 53 | /> |
| 54 | <Button |
| 55 | onClick={handleBuildIdea} |
| 56 | disabled={isBuilding} |
| 57 | className="w-full bg-growth hover:bg-growth/80 text-white" |
| 58 | > |
| 59 | {isBuilding ? "Analyzing Idea..." : "Generate Build Plan"} |
| 60 | </Button> |
| 61 | </div> |
| 62 | |
| 63 | {blueprint && ( |
| 64 | <div className="mt-4 p-4 bg-background border rounded-md space-y-4"> |
| 65 | <h4 className="font-bold text-sm flex items-center gap-2"> |
| 66 | <CheckSquare size={14} className="text-growth" /> Step-by-Step Build Guide |
| 67 | </h4> |
| 68 | <div className="text-xs font-mono whitespace-pre-wrap max-h-48 overflow-y-auto p-2 bg-muted rounded"> |
| 69 | {blueprint} |
| 70 | </div> |
| 71 | <Button size="sm" variant="outline" className="w-full text-xs"> |
| 72 | <Wrench size={12} className="mr-2" /> Add to My Portfolio |
| 73 | </Button> |
| 74 | </div> |
| 75 | )} |
| 76 | </CardContent> |
| 77 | </Card> |
| 78 | ); |
| 79 | }; |