File size: 1,968 Bytes
cce8120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
set -euo pipefail

echo "[1/10] Creating AI workspace..."

mkdir -p services/ai
mkdir -p hooks

cat > services/ai/client.js <<'EOC'
import api from "../api";

export async function sendPrompt(prompt, projectId = null) {
    const { data } = await api.post("/api/ai/chat", {
        prompt,
        project_id: projectId
    });
    return data;
}

export async function streamPrompt(prompt, projectId = null) {
    const { data } = await api.post("/api/ai/chat/stream", {
        prompt,
        project_id: projectId
    });
    return data;
}

export async function generateCode(prompt, language = "javascript") {
    const { data } = await api.post("/api/ai/generate", {
        prompt,
        language
    });
    return data;
}

export async function explainCode(code) {
    const { data } = await api.post("/api/ai/explain", {
        code
    });
    return data;
}

export async function fixCode(code) {
    const { data } = await api.post("/api/ai/fix", {
        code
    });
    return data;
}
EOC

cat > hooks/useAI.js <<'EOC'
"use client";

import { useState } from "react";
import * as ai from "../services/ai/client";

export default function useAI(){

    const [loading,setLoading]=useState(false);

    async function ask(prompt,projectId){
        setLoading(true);
        try{
            return await ai.sendPrompt(prompt,projectId);
        }finally{
            setLoading(false);
        }
    }

    return {
        loading,
        ask,
        generateCode:ai.generateCode,
        explainCode:ai.explainCode,
        fixCode:ai.fixCode
    };
}
EOC

echo "[2/10] Installing dependencies..."
npm install

echo "[3/10] Production build..."
npm run build >/dev/null

echo "[4/10] Verify..."
test -f services/ai/client.js
test -f hooks/useAI.js

echo "[5/10] AI client installed."
echo "[6/10] Hooks installed."
echo "[7/10] Frontend verified."
echo "[8/10] Build verified."
echo "[9/10] Ready."
echo "[10/10] Complete."