Aichatbot12321 commited on
Commit
a32d2df
Β·
verified Β·
1 Parent(s): e3841c0

Create coding.html

Browse files
Files changed (1) hide show
  1. coding.html +238 -0
coding.html ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6
+ <title>AI CODER - AI PRO SUITE</title>
7
+
8
+ <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
9
+
10
+ <!-- JSZip for generating ZIP files directly in the browser -->
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
12
+ <script src="https://cdn.jsdelivr.net/npm/marked@4.3.0/marked.min.js"></script>
13
+
14
+ <style>
15
+ :root {
16
+ --app-bg: #f8fafc;
17
+ --bg-surface: #ffffff;
18
+ --border-light: #e2e8f0;
19
+ --primary: #3b82f6;
20
+ --primary-glow: rgba(59, 130, 246, 0.2);
21
+ --text-main: #1e293b;
22
+ --text-muted: #64748b;
23
+ --input-bg: #f1f5f9;
24
+ --success: #10b981;
25
+ }
26
+
27
+ body { background: var(--app-bg); font-family: 'Poppins', sans-serif; margin: 0; padding: 0; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
28
+
29
+ .topbar { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; background: var(--bg-surface); border-bottom: 1px solid var(--border-light); box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
30
+ .app-title { font-size: 20px; font-weight: bold; color: var(--text-main); letter-spacing: 1px; }
31
+
32
+ .main-container { flex: 1; display: flex; flex-direction: column; padding: 20px; overflow-y: auto; align-items: center; }
33
+
34
+ .builder-box { width: 100%; max-width: 800px; background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: 16px; padding: 25px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); }
35
+
36
+ .input-group { display: flex; gap: 10px; margin-bottom: 20px; }
37
+ .input-group input { flex: 1; padding: 15px; border-radius: 12px; border: 2px solid var(--border-light); background: var(--input-bg); font-family: 'Poppins', sans-serif; font-size: 15px; outline: none; transition: 0.3s; }
38
+ .input-group input:focus { border-color: var(--primary); }
39
+ .input-group button { padding: 15px 25px; border-radius: 12px; border: none; background: var(--primary); color: white; font-weight: bold; font-size: 15px; cursor: pointer; transition: 0.3s; }
40
+ .input-group button:hover { background: #2563eb; transform: translateY(-2px); }
41
+ .input-group button:disabled { background: var(--text-muted); cursor: not-allowed; transform: none; }
42
+
43
+ .terminal { background: #0f172a; border-radius: 12px; padding: 20px; color: #38bdf8; font-family: monospace; font-size: 13px; height: 350px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; box-shadow: inset 0 4px 15px rgba(0,0,0,0.5); }
44
+ .log-line { margin: 0; line-height: 1.5; }
45
+ .log-line.api5 { color: #f472b6; } /* Pink */
46
+ .log-line.api4 { color: #a78bfa; } /* Purple */
47
+ .log-line.api3 { color: #38bdf8; } /* Blue */
48
+ .log-line.api2 { color: #4ade80; } /* Green */
49
+ .log-line.api1 { color: #fbbf24; } /* Yellow */
50
+ .log-line.success { color: #10b981; font-weight: bold; }
51
+ .log-line.error { color: #ef4444; font-weight: bold; }
52
+
53
+ #downloadZipBtn { display: none; width: 100%; margin-top: 20px; padding: 15px; border-radius: 12px; border: none; background: var(--success); color: white; font-weight: 800; font-size: 16px; cursor: pointer; text-align: center; box-shadow: 0 5px 15px rgba(16,185,129,0.3); transition: 0.3s; }
54
+ #downloadZipBtn:hover { transform: scale(1.02); }
55
+
56
+ /* Loader */
57
+ .spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: #fff; animation: spin 1s ease-in-out infinite; margin-right: 8px; vertical-align: middle; }
58
+ @keyframes spin { to { transform: rotate(360deg); } }
59
+ </style>
60
+ </head>
61
+ <body>
62
+
63
+ <div class="topbar">
64
+ <button onclick="window.location.href='index.html'" style="background:none; border:none; font-size:24px; cursor:pointer;">🏠</button>
65
+ <div class="app-title">πŸ’» AI AUTONOMOUS CODER</div>
66
+ <div style="width:24px;"></div>
67
+ </div>
68
+
69
+ <div class="main-container">
70
+ <div class="builder-box">
71
+ <h2 style="margin-top:0; color:var(--text-main);">Build a Project</h2>
72
+ <p style="color:var(--text-muted); font-size:14px; margin-bottom:20px;">Describe what you want to build (e.g. "make me an edge extension"). The AI will brainstorm, draft, and structure the code across 5 API layers.</p>
73
+
74
+ <div class="input-group">
75
+ <input type="text" id="projectPrompt" placeholder="e.g. Make a snake game using HTML, CSS, JS...">
76
+ <button id="buildBtn" onclick="startBuildProcess()">Build Project</button>
77
+ </div>
78
+
79
+ <div class="terminal" id="terminalLog">
80
+ <div class="log-line">System ready. Waiting for project prompt...</div>
81
+ </div>
82
+
83
+ <button id="downloadZipBtn" onclick="downloadProjectZip()">πŸ“₯ Download Project as ZIP</button>
84
+ </div>
85
+ </div>
86
+
87
+ <script>
88
+ let currentZipBlob = null;
89
+ let projectName = "AI_Project";
90
+
91
+ function appendLog(message, cssClass = "") {
92
+ const terminal = document.getElementById("terminalLog");
93
+ const time = new Date().toLocaleTimeString();
94
+ terminal.insertAdjacentHTML('beforeend', `<div class="log-line ${cssClass}">[${time}] ${message}</div>`);
95
+ terminal.scrollTop = terminal.scrollHeight;
96
+ }
97
+
98
+ async function callAI(userPrompt, sysPrompt, apiLevel) {
99
+ const response = await fetch("/api/other", {
100
+ method: "POST",
101
+ headers: { "Content-Type": "application/json" },
102
+ body: JSON.stringify({
103
+ userPrompt: userPrompt,
104
+ systemPrompt: sysPrompt,
105
+ providerOverride: apiLevel
106
+ })
107
+ });
108
+
109
+ if (!response.ok) throw new Error(`API ${apiLevel} failed to respond.`);
110
+ const data = await response.json();
111
+ return data.text || data.response || data.choices?.[0]?.message?.content || "";
112
+ }
113
+
114
+ async function startBuildProcess() {
115
+ const prompt = document.getElementById("projectPrompt").value.trim();
116
+ if (!prompt) return alert("Please enter a project description.");
117
+
118
+ projectName = prompt.split(" ").slice(0, 3).join("_").replace(/[^a-zA-Z0-9_]/g, '') || "AI_Project";
119
+
120
+ const btn = document.getElementById("buildBtn");
121
+ const downloadBtn = document.getElementById("downloadZipBtn");
122
+
123
+ btn.disabled = true;
124
+ btn.innerHTML = `<span class="spinner"></span> Building...`;
125
+ document.getElementById("terminalLog").innerHTML = "";
126
+ downloadBtn.style.display = "none";
127
+ currentZipBlob = null;
128
+
129
+ try {
130
+ // ==========================================
131
+ // LAYER 5: BRAINSTORMING & ARCHITECTURE
132
+ // ==========================================
133
+ appendLog("Initiating API 5: Brainstorming architecture and file structure...", "api5");
134
+ const idea = await callAI(
135
+ prompt,
136
+ "You are a Lead Software Architect. Outline the exact files needed, folder structure, and the core logic required to build the user's request. Be highly detailed but concise.",
137
+ "API 5"
138
+ );
139
+ appendLog("βœ“ API 5 completed architecture blueprint.", "api5");
140
+
141
+ // ==========================================
142
+ // LAYER 4: DRAFTING CORE LOGIC
143
+ // ==========================================
144
+ appendLog("Initiating API 4: Drafting core logic based on blueprint...", "api4");
145
+ const logicDraft = await callAI(
146
+ "Blueprint: " + idea,
147
+ "You are a Senior Developer. Based on the provided blueprint, write the actual code logic for the main components. Do not worry about JSON formatting yet, just write good code.",
148
+ "API 4"
149
+ );
150
+ appendLog("βœ“ API 4 completed code drafting.", "api4");
151
+
152
+ // ==========================================
153
+ // LAYER 3: REFINING AND OPTIMIZING
154
+ // ==========================================
155
+ appendLog("Initiating API 3: Refining code and connecting components...", "api3");
156
+ const refinedCode = await callAI(
157
+ "Drafted Code: " + logicDraft,
158
+ "You are an Optimization Engineer. Refine the provided code, ensure variables match, components connect properly, and fix any obvious bugs.",
159
+ "API 3"
160
+ );
161
+ appendLog("βœ“ API 3 completed refinement.", "api3");
162
+
163
+ // ==========================================
164
+ // LAYER 2: STRUCTURING FOR EXPORT
165
+ // ==========================================
166
+ appendLog("Initiating API 2: Preparing file paths and formatting...", "api2");
167
+ const structure = await callAI(
168
+ "Refined Code: " + refinedCode,
169
+ "You are a DevOps Engineer. Organize the provided code into exact file paths (e.g., 'index.html', 'js/app.js', 'css/style.css'). Present them clearly so the final system can parse them.",
170
+ "API 2"
171
+ );
172
+ appendLog("βœ“ API 2 organized file system.", "api2");
173
+
174
+ // ==========================================
175
+ // LAYER 1: STRICT JSON GENERATION
176
+ // ==========================================
177
+ appendLog("Initiating API 1: Formatting into strict JSON payload for ZIP compiler...", "api1");
178
+ let jsonPayloadStr = await callAI(
179
+ "Structured Code: " + structure,
180
+ `You are a strict JSON compiler. You MUST return ONLY a raw JSON array representing the files. NO MARKDOWN. NO BACKTICKS. NO EXPLANATIONS.
181
+ Format exactly like this:
182
+ [
183
+ { "path": "index.html", "content": "<html>...</html>" },
184
+ { "path": "manifest.json", "content": "{ \\"name\\": \\"Ext\\" }" }
185
+ ]`,
186
+ "API 1"
187
+ );
188
+
189
+ // Clean the JSON string if the model accidentally included markdown
190
+ jsonPayloadStr = jsonPayloadStr.replace(/```json/gi, '').replace(/```/gi, '').trim();
191
+
192
+ let filesArray;
193
+ try {
194
+ filesArray = JSON.parse(jsonPayloadStr);
195
+ } catch (jsonErr) {
196
+ throw new Error("API 1 failed to return valid JSON. Aborting.");
197
+ }
198
+
199
+ appendLog(`βœ“ API 1 successfully compiled ${filesArray.length} files.`, "api1");
200
+
201
+ // ==========================================
202
+ // ZIP GENERATION (CLIENT-SIDE)
203
+ // ==========================================
204
+ appendLog("Compiling files into ZIP archive...", "success");
205
+ const zip = new JSZip();
206
+
207
+ filesArray.forEach(fileObj => {
208
+ zip.file(fileObj.path, fileObj.content);
209
+ appendLog(` -> Created: ${fileObj.path}`);
210
+ });
211
+
212
+ currentZipBlob = await zip.generateAsync({ type: "blob" });
213
+
214
+ appendLog("βœ… Project successfully built and zipped!", "success");
215
+ downloadBtn.style.display = "block";
216
+
217
+ } catch (error) {
218
+ appendLog(`❌ BUILD FAILED: ${error.message}`, "error");
219
+ } finally {
220
+ btn.disabled = false;
221
+ btn.innerHTML = "Build Project";
222
+ }
223
+ }
224
+
225
+ function downloadProjectZip() {
226
+ if (!currentZipBlob) return;
227
+ const url = URL.createObjectURL(currentZipBlob);
228
+ const a = document.createElement("a");
229
+ a.href = url;
230
+ a.download = `${projectName}.zip`;
231
+ document.body.appendChild(a);
232
+ a.click();
233
+ document.body.removeChild(a);
234
+ setTimeout(() => URL.revokeObjectURL(url), 10000);
235
+ }
236
+ </script>
237
+ </body>
238
+ </html>