File size: 30,918 Bytes
b81c229
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI Dev Assistant Pro</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <style>
        .code-editor {
            font-family: 'Fira Code', monospace;
            font-size: 14px;
            line-height: 1.5;
        }
        .terminal {
            font-family: 'Fira Code', monospace;
            background-color: #1e1e1e;
            color: #f8f8f2;
        }
        .model-selector.active {
            border-color: #3b82f6;
            background-color: rgba(59, 130, 246, 0.1);
        }
        .response-area {
            max-height: 400px;
            overflow-y: auto;
        }
        .tab-active {
            border-bottom: 2px solid #3b82f6;
            color: #3b82f6;
        }
        .loading-dots:after {
            content: '.';
            animation: dots 1.5s steps(5, end) infinite;
        }
        @keyframes dots {
            0%, 20% { content: '.'; }
            40% { content: '..'; }
            60% { content: '...'; }
            80%, 100% { content: ''; }
        }
    </style>
</head>
<body class="bg-gray-50 text-gray-900">
    <div class="container mx-auto px-4 py-8">
        <!-- Header -->
        <header class="mb-8">
            <div class="flex justify-between items-center">
                <h1 class="text-3xl font-bold text-blue-600 flex items-center">
                    <i class="fas fa-robot mr-3"></i> AI Dev Assistant Pro
                </h1>
                <div class="flex space-x-4">
                    <button id="settings-btn" class="px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-lg">
                        <i class="fas fa-cog"></i> Settings
                    </button>
                    <button id="docs-btn" class="px-4 py-2 bg-blue-100 hover:bg-blue-200 text-blue-700 rounded-lg">
                        <i class="fas fa-book"></i> Documentation
                    </button>
                </div>
            </div>
            <p class="text-gray-600 mt-2">Your all-in-one AI development environment with macOS integration</p>
        </header>

        <!-- Main Content -->
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
            <!-- Left Panel - Input and Controls -->
            <div class="lg:col-span-2 space-y-6">
                <!-- Model Selection -->
                <div class="bg-white rounded-xl shadow p-6">
                    <h2 class="text-xl font-semibold mb-4">Select AI Model</h2>
                    <div class="grid grid-cols-2 md:grid-cols-4 gap-3">
                        <div class="model-selector p-3 border rounded-lg cursor-pointer active" data-model="gpt-4.1">
                            <div class="font-medium">GPT-4.1</div>
                            <div class="text-sm text-gray-500">Azure</div>
                        </div>
                        <div class="model-selector p-3 border rounded-lg cursor-pointer" data-model="grok-3">
                            <div class="font-medium">Grok-3</div>
                            <div class="text-sm text-gray-500">Azure</div>
                        </div>
                        <div class="model-selector p-3 border rounded-lg cursor-pointer" data-model="deepseek">
                            <div class="font-medium">DeepSeek</div>
                            <div class="text-sm text-gray-500">Azure</div>
                        </div>
                        <div class="model-selector p-3 border rounded-lg cursor-pointer" data-model="o3-mini">
                            <div class="font-medium">O3-Mini</div>
                            <div class="text-sm text-gray-500">Azure</div>
                        </div>
                    </div>
                </div>

                <!-- Prompt Input -->
                <div class="bg-white rounded-xl shadow">
                    <div class="p-4 border-b">
                        <div class="flex space-x-4">
                            <div class="tab tab-active" data-tab="prompt">Prompt</div>
                            <div class="tab" data-tab="system">System Instructions</div>
                            <div class="tab" data-tab="files">File Context</div>
                        </div>
                    </div>
                    <div class="p-4">
                        <div id="prompt-tab" class="tab-content active">
                            <textarea id="prompt-input" class="w-full h-40 p-3 border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="Enter your prompt here..."></textarea>
                        </div>
                        <div id="system-tab" class="tab-content hidden">
                            <textarea id="system-input" class="w-full h-40 p-3 border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="Enter system instructions...">You are an expert AI developer assistant specialized in generating high-quality code, debugging, and creating complete applications. Follow these guidelines:

1. For code generation tasks, always:
   - Use the most appropriate programming language
   - Include comprehensive comments
   - Implement error handling
   - Follow best practices for the language/framework

2. For macOS automation:
   - Use AppleScript for simple tasks
   - Use Swift for more complex automation
   - Include proper permissions handling
   - Provide clear instructions for setup

3. For Azure AI API usage:
   - Include proper authentication
   - Implement retry logic
   - Handle rate limiting
   - Process responses efficiently

4. Always:
   - Be concise but thorough
   - Provide complete implementations
   - Suggest optimizations
   - Offer alternative approaches when relevant</textarea>
                        </div>
                        <div id="files-tab" class="tab-content hidden">
                            <div class="mb-4">
                                <input type="file" id="file-upload" class="hidden" multiple>
                                <button id="upload-btn" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">
                                    <i class="fas fa-upload mr-2"></i>Upload Files
                                </button>
                                <span id="file-count" class="ml-2 text-sm text-gray-500">No files selected</span>
                            </div>
                            <div id="file-preview" class="border rounded-lg p-3 h-40 overflow-y-auto bg-gray-50">
                                <p class="text-gray-500 text-center">Uploaded files will appear here</p>
                            </div>
                        </div>
                    </div>
                    <div class="p-4 border-t flex justify-between">
                        <div class="flex space-x-3">
                            <button id="macos-btn" class="px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-lg">
                                <i class="fab fa-apple mr-2"></i> macOS Control
                            </button>
                            <button id="code-btn" class="px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-lg">
                                <i class="fas fa-code mr-2"></i> Generate Code
                            </button>
                            <button id="app-btn" class="px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-lg">
                                <i class="fas fa-cubes mr-2"></i> Create App
                            </button>
                        </div>
                        <button id="submit-btn" class="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">
                            <i class="fas fa-paper-plane mr-2"></i> Submit
                        </button>
                    </div>
                </div>

                <!-- Response Area -->
                <div class="bg-white rounded-xl shadow p-6">
                    <h2 class="text-xl font-semibold mb-4">AI Response</h2>
                    <div id="response-area" class="response-area min-h-40 p-4 border rounded-lg bg-gray-50">
                        <p class="text-gray-500 text-center">Response will appear here</p>
                    </div>
                    <div id="loading-indicator" class="hidden mt-4 text-center text-blue-600">
                        <p class="loading-dots">Processing</p>
                    </div>
                </div>
            </div>

            <!-- Right Panel - Code Editor and Terminal -->
            <div class="space-y-6">
                <!-- Code Editor -->
                <div class="bg-white rounded-xl shadow p-6">
                    <div class="flex justify-between items-center mb-4">
                        <h2 class="text-xl font-semibold">Code Editor</h2>
                        <div class="flex space-x-2">
                            <button id="copy-code-btn" class="p-2 text-gray-600 hover:text-blue-600">
                                <i class="fas fa-copy"></i>
                            </button>
                            <button id="run-code-btn" class="p-2 text-gray-600 hover:text-green-600">
                                <i class="fas fa-play"></i>
                            </button>
                            <button id="save-code-btn" class="p-2 text-gray-600 hover:text-blue-600">
                                <i class="fas fa-save"></i>
                            </button>
                        </div>
                    </div>
                    <div class="relative">
                        <select id="language-select" class="absolute right-0 top-0 z-10 bg-gray-100 border rounded p-1 text-sm">
                            <option value="javascript">JavaScript</option>
                            <option value="python">Python</option>
                            <option value="html">HTML</option>
                            <option value="css">CSS</option>
                            <option value="swift">Swift</option>
                            <option value="applescript">AppleScript</option>
                        </select>
                        <textarea id="code-editor" class="code-editor w-full h-64 p-3 border rounded-lg bg-gray-900 text-gray-100"></textarea>
                    </div>
                </div>

                <!-- Terminal -->
                <div class="bg-white rounded-xl shadow p-6">
                    <h2 class="text-xl font-semibold mb-4">Terminal</h2>
                    <div id="terminal" class="terminal w-full h-40 p-3 rounded-lg overflow-y-auto">
                        <div class="mb-2">
                            <span class="text-green-400">user@macos</span>
                            <span class="text-blue-400"> ~ </span>
                            <span class="text-white">$</span>
                            <span id="terminal-prompt" class="ml-2"></span>
                        </div>
                        <div id="terminal-output"></div>
                    </div>
                    <div class="mt-3 flex">
                        <input id="terminal-input" type="text" class="flex-1 px-3 py-1 border rounded-l-lg focus:outline-none" placeholder="Enter command...">
                        <button id="terminal-submit" class="px-4 py-1 bg-blue-600 text-white rounded-r-lg hover:bg-blue-700">
                            <i class="fas fa-arrow-right"></i>
                        </button>
                    </div>
                </div>

                <!-- API Status -->
                <div class="bg-white rounded-xl shadow p-6">
                    <h2 class="text-xl font-semibold mb-4">API Status</h2>
                    <div class="space-y-3">
                        <div class="flex items-center">
                            <div class="w-3 h-3 rounded-full bg-green-500 mr-2"></div>
                            <span>OpenAI API: Connected</span>
                        </div>
                        <div class="flex items-center">
                            <div class="w-3 h-3 rounded-full bg-green-500 mr-2"></div>
                            <span>Azure AI: Connected</span>
                        </div>
                        <div class="flex items-center">
                            <div class="w-3 h-3 rounded-full bg-green-500 mr-2"></div>
                            <span>macOS Bridge: Active</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- macOS Control Modal -->
    <div id="macos-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
        <div class="bg-white rounded-xl shadow-lg w-full max-w-2xl">
            <div class="p-4 border-b flex justify-between items-center">
                <h3 class="text-lg font-semibold">macOS Control Panel</h3>
                <button id="close-macos-modal" class="text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="p-6">
                <div class="grid grid-cols-2 gap-4 mb-6">
                    <div class="p-4 border rounded-lg hover:bg-gray-50 cursor-pointer">
                        <div class="text-blue-600 mb-2">
                            <i class="fas fa-folder-open text-2xl"></i>
                        </div>
                        <h4 class="font-medium">File Operations</h4>
                        <p class="text-sm text-gray-500">Create, move, delete files</p>
                    </div>
                    <div class="p-4 border rounded-lg hover:bg-gray-50 cursor-pointer">
                        <div class="text-blue-600 mb-2">
                            <i class="fas fa-window-maximize text-2xl"></i>
                        </div>
                        <h4 class="font-medium">Window Control</h4>
                        <p class="text-sm text-gray-500">Manage application windows</p>
                    </div>
                    <div class="p-4 border rounded-lg hover:bg-gray-50 cursor-pointer">
                        <div class="text-blue-600 mb-2">
                            <i class="fas fa-network-wired text-2xl"></i>
                        </div>
                        <h4 class="font-medium">System Info</h4>
                        <p class="text-sm text-gray-500">Get hardware/software details</p>
                    </div>
                    <div class="p-4 border rounded-lg hover:bg-gray-50 cursor-pointer">
                        <div class="text-blue-600 mb-2">
                            <i class="fas fa-robot text-2xl"></i>
                        </div>
                        <h4 class="font-medium">Automation</h4>
                        <p class="text-sm text-gray-500">Create workflows</p>
                    </div>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Custom AppleScript</label>
                    <textarea id="applescript-input" class="w-full h-32 p-3 border rounded-lg" placeholder="tell application \"Finder\" to..."></textarea>
                    <div class="mt-3 flex justify-end space-x-3">
                        <button id="cancel-applescript" class="px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-lg">
                            Cancel
                        </button>
                        <button id="run-applescript" class="px-4 py-2 bg-blue-600 text-white hover:bg-blue-700 rounded-lg">
                            Run Script
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // DOM Elements
        const modelSelectors = document.querySelectorAll('.model-selector');
        const tabs = document.querySelectorAll('.tab');
        const tabContents = document.querySelectorAll('.tab-content');
        const promptInput = document.getElementById('prompt-input');
        const systemInput = document.getElementById('system-input');
        const submitBtn = document.getElementById('submit-btn');
        const responseArea = document.getElementById('response-area');
        const loadingIndicator = document.getElementById('loading-indicator');
        const codeEditor = document.getElementById('code-editor');
        const languageSelect = document.getElementById('language-select');
        const copyCodeBtn = document.getElementById('copy-code-btn');
        const runCodeBtn = document.getElementById('run-code-btn');
        const saveCodeBtn = document.getElementById('save-code-btn');
        const terminalInput = document.getElementById('terminal-input');
        const terminalSubmit = document.getElementById('terminal-submit');
        const terminalOutput = document.getElementById('terminal-output');
        const terminalPrompt = document.getElementById('terminal-prompt');
        const macosBtn = document.getElementById('macos-btn');
        const macosModal = document.getElementById('macos-modal');
        const closeMacosModal = document.getElementById('close-macos-modal');
        const applescriptInput = document.getElementById('applescript-input');
        const runApplescript = document.getElementById('run-applescript');
        const cancelApplescript = document.getElementById('cancel-applescript');
        const uploadBtn = document.getElementById('upload-btn');
        const fileUpload = document.getElementById('file-upload');
        const filePreview = document.getElementById('file-preview');
        const fileCount = document.getElementById('file-count');
        const codeBtn = document.getElementById('code-btn');
        const appBtn = document.getElementById('app-btn');

        // Current state
        let currentModel = 'gpt-4.1';
        let uploadedFiles = [];
        let isProcessing = false;

        // API Configuration
        const apiConfig = {
            'gpt-4.1': {
                endpoint: 'https://maste-m2sgu57w-eastus2.openai.azure.com/openai/deployments/gpt-4.1/chat/completions?api-version=2025-01-01-preview',
                key: '1bcdac56c7d54513844c0b0d7c7c079e'
            },
            'grok-3': {
                endpoint: 'https://ai-huroaiai970351299673.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview',
                key: 'GgTqsvTU1GpxmIHeaRbzctxdivLvdlOGLRl6F37oUFnu09JKyGPLJQQJ99BBACHYHv6XJ3w3AAAAACOGWLsV'
            },
            'deepseek': {
                endpoint: 'https://ai-huroaiai970351299673.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview',
                key: 'GgTqsvTU1GpxmIHeaRbzctxdivLvdlOGLRl6F37oUFnu09JKyGPLJQQJ99BBACHYHv6XJ3w3AAAAACOGWLsV'
            },
            'o3-mini': {
                endpoint: 'https://ai-huroaiai970351299673.openai.azure.com/openai/deployments/o3-mini/chat/completions?api-version=2025-01-01-preview',
                key: 'GgTqsvTU1GpxmIHeaRbzctxdivLvdlOGLRl6F37oUFnu09JKyGPLJQQJ99BBACHYHv6XJ3w3AAAAACOGWLsV'
            },
            'openai': {
                endpoint: 'https://api.openai.com/v1/chat/completions',
                key: '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'
            }
        };

        // Event Listeners
        modelSelectors.forEach(selector => {
            selector.addEventListener('click', () => {
                modelSelectors.forEach(s => s.classList.remove('active'));
                selector.classList.add('active');
                currentModel = selector.dataset.model;
            });
        });

        tabs.forEach(tab => {
            tab.addEventListener('click', () => {
                tabs.forEach(t => t.classList.remove('tab-active'));
                tab.classList.add('tab-active');
                
                const tabName = tab.dataset.tab;
                tabContents.forEach(content => {
                    content.classList.add('hidden');
                    if (content.id === `${tabName}-tab`) {
                        content.classList.remove('hidden');
                    }
                });
            });
        });

        submitBtn.addEventListener('click', handleSubmit);
        codeBtn.addEventListener('click', () => {
            promptInput.value = "Generate complete, production-ready code for: " + (promptInput.value || "a web application with modern UI");
            document.querySelector('.tab').click();
        });
        appBtn.addEventListener('click', () => {
            promptInput.value = "Create a complete application with all necessary files for: " + (promptInput.value || "a task management tool");
            document.querySelector('.tab').click();
        });

        macosBtn.addEventListener('click', () => {
            macosModal.classList.remove('hidden');
        });

        closeMacosModal.addEventListener('click', () => {
            macosModal.classList.add('hidden');
        });

        runApplescript.addEventListener('click', () => {
            const script = applescriptInput.value;
            if (script.trim()) {
                runTerminalCommand(`osascript -e '${script}'`);
                macosModal.classList.add('hidden');
            }
        });

        cancelApplescript.addEventListener('click', () => {
            macosModal.classList.add('hidden');
        });

        uploadBtn.addEventListener('click', () => {
            fileUpload.click();
        });

        fileUpload.addEventListener('change', handleFileUpload);

        copyCodeBtn.addEventListener('click', () => {
            navigator.clipboard.writeText(codeEditor.value);
            showTerminalMessage('Code copied to clipboard!');
        });

        runCodeBtn.addEventListener('click', () => {
            const code = codeEditor.value;
            const language = languageSelect.value;
            
            if (code.trim()) {
                showTerminalMessage(`Running ${language} code...`);
                // In a real app, this would execute the code in a sandbox
                setTimeout(() => {
                    showTerminalMessage('Code execution complete.');
                    showTerminalMessage('Output would appear here in a real implementation.');
                }, 1000);
            }
        });

        saveCodeBtn.addEventListener('click', () => {
            const code = codeEditor.value;
            if (code.trim()) {
                const blob = new Blob([code], { type: 'text/plain' });
                const url = URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = `code.${languageSelect.value}`;
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
                URL.revokeObjectURL(url);
                showTerminalMessage(`Code saved as code.${languageSelect.value}`);
            }
        });

        terminalSubmit.addEventListener('click', () => {
            const command = terminalInput.value.trim();
            if (command) {
                runTerminalCommand(command);
                terminalInput.value = '';
            }
        });

        terminalInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') {
                const command = terminalInput.value.trim();
                if (command) {
                    runTerminalCommand(command);
                    terminalInput.value = '';
                }
            }
        });

        // Functions
        function handleSubmit() {
            if (isProcessing) return;
            
            const prompt = promptInput.value.trim();
            const system = systemInput.value.trim();
            
            if (!prompt) {
                showTerminalMessage('Please enter a prompt');
                return;
            }
            
            isProcessing = true;
            loadingIndicator.classList.remove('hidden');
            responseArea.innerHTML = '<p class="text-gray-500 text-center">Processing your request...</p>';
            
            // Simulate API call (in a real app, this would be an actual API call)
            setTimeout(() => {
                generateResponse(prompt, system);
                isProcessing = false;
                loadingIndicator.classList.add('hidden');
            }, 2000);
        }

        function generateResponse(prompt, system) {
            // This is a simulation - in a real app, you would call the actual API
            const responses = {
                code: `Here's the complete code you requested:

\`\`\`${languageSelect.value}
// ${prompt}
function main() {
    // Implementation goes here
    console.log("Hello, World!");
    
    // Error handling
    try {
        // Critical operations
    } catch (error) {
        console.error("Error:", error);
    }
}

// Run the main function
main();
\`\`\`

Key features:
- Proper error handling
- Clean code structure
- Comprehensive comments
- Follows best practices`,
                app: `I'll create a complete application structure for you:

Project Structure:
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.${languageSelect.value} - Main application entry point
β”‚   β”œβ”€β”€ components/ - Reusable UI components
β”‚   β”œβ”€β”€ utils/ - Utility functions
β”‚   └── styles/ - CSS/Styles
β”œβ”€β”€ public/ - Static assets
β”œβ”€β”€ package.json - Project configuration
└── README.md - Documentation

Would you like me to generate each of these files?`,
                default: `Here's the information you requested about "${prompt}":

1. Overview: This is a comprehensive response generated by the ${currentModel} model.
2. Implementation Details: 
   - First approach: Using standard libraries
   - Alternative approach: Using modern frameworks
3. Recommendations:
   - Best practice: Follow industry standards
   - Optimization: Consider performance implications

Let me know if you'd like me to elaborate on any specific aspect.`
            };
            
            let response;
            if (prompt.toLowerCase().includes('generate code') || prompt.toLowerCase().includes('create code')) {
                response = responses.code;
            } else if (prompt.toLowerCase().includes('create app') || prompt.toLowerCase().includes('build application')) {
                response = responses.app;
            } else {
                response = responses.default;
            }
            
            // Update code editor if code was generated
            if (response.includes('```')) {
                const codeMatch = response.match(/```[\w-]*\n([\s\S]*?)\n```/);
                if (codeMatch && codeMatch[1]) {
                    codeEditor.value = codeMatch[1];
                }
            }
            
            responseArea.innerHTML = marked.parse(response);
        }

        function runTerminalCommand(command) {
            const promptLine = document.createElement('div');
            promptLine.className = 'mb-2';
            promptLine.innerHTML = `
                <span class="text-green-400">user@macos</span>
                <span class="text-blue-400"> ~ </span>
                <span class="text-white">$</span>
                <span class="ml-2">${command}</span>
            `;
            terminalOutput.appendChild(promptLine);
            
            // Simulate command output
            const output = simulateCommandOutput(command);
            const outputLine = document.createElement('div');
            outputLine.className = 'mb-4 text-gray-300';
            outputLine.textContent = output;
            terminalOutput.appendChild(outputLine);
            
            // Scroll to bottom
            terminalOutput.scrollTop = terminalOutput.scrollHeight;
        }

        function simulateCommandOutput(command) {
            if (command.startsWith('ls')) {
                return 'Applications    Documents    Downloads\nPictures       Music        Desktop';
            } else if (command.startsWith('pwd')) {
                return '/Users/user';
            } else if (command.includes('osascript')) {
                return 'AppleScript executed successfully';
            } else {
                return `${command}: command output would appear here in a real terminal`;
            }
        }

        function showTerminalMessage(message) {
            const messageLine = document.createElement('div');
            messageLine.className = 'mb-2 text-gray-300';
            messageLine.textContent = message;
            terminalOutput.appendChild(messageLine);
            terminalOutput.scrollTop = terminalOutput.scrollHeight;
        }

        function handleFileUpload(e) {
            const files = Array.from(e.target.files);
            if (files.length === 0) return;
            
            uploadedFiles = files;
            fileCount.textContent = `${files.length} file(s) selected`;
            
            filePreview.innerHTML = '';
            files.forEach(file => {
                const fileElement = document.createElement('div');
                fileElement.className = 'flex items-center p-2 border-b last:border-b-0';
                fileElement.innerHTML = `
                    <i class="fas fa-file-alt text-gray-500 mr-3"></i>
                    <div>
                        <div class="font-medium">${file.name}</div>
                        <div class="text-sm text-gray-500">${(file.size / 1024).toFixed(1)} KB</div>
                    </div>
                `;
                filePreview.appendChild(fileElement);
            });
        }

        // Initialize
        showTerminalMessage('System ready. Enter commands or use the AI assistant.');
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=tommytracx/test" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>