File size: 13,364 Bytes
dff1e71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Construct - Digital Person</title>
    <link rel="stylesheet" href="/login.css">
    <link rel="icon" type="image/svg+xml" href="/public/favicon.svg">
    <style>
        body.emergency-mode {
            background: #000 !important;
            color: #d4d4d4 !important;
            font-family: "Courier New", monospace !important;
        }
        .construct-container {
            display: none !important;
        }
        .emergency-container {
            display: block !important;
        }
    </style>
</head>
<body id="login-body">
    <div class="construct-container" id="construct-container">
        <div class="world-tree" id="world-tree"></div>
        <div class="round-table"></div>
        
        <form class="construct-form" method="POST" action="/login">
            <!-- Stage 1: Persona Display -->
            <div class="persona-display" id="persona-display">
                <div class="persona-avatar" id="persona-avatar">
                    <div class="avatar-placeholder"></div>
                </div>
                <h1 class="persona-name" id="persona-name">Construct</h1>
                <p class="persona-subtitle" id="persona-subtitle">Digital Person Instantiation</p>
            </div>
            
            <!-- Stage 2: Customization (Voice + Image Selection) -->
            <div class="customization-stage" id="customization-stage">
                <div class="customization-header">
                    <h2>Configure Your Self</h2>
                    <p class="stage-description">Choose your RSI (Residual Self Image) and voice manifest</p>
                </div>
                
                <!-- RSI Selection -->
                <div class="rsi-selection">
                    <label class="section-label">
                        <span class="section-icon">🖼️</span>
                        RSI Generation
                    </label>
                    <p class="section-help">Generate avatar from soul anchor using Flux/DALL-E, or upload custom image</p>
                    
                    <div class="rsi-options">
                        <label class="rsi-option">
                            <input type="radio" name="rsi_mode" value="generate" checked>
                            <div class="option-content">
                                <span class="option-title">Generate (Flux)</span>
                                <span class="option-desc">AI-generated from soul anchor</span>
                            </div>
                        </label>
                        
                        <label class="rsi-option">
                            <input type="radio" name="rsi_mode" value="upload">
                            <div class="option-content">
                                <span class="option-title">Upload Image</span>
                                <span class="option-desc">Custom avatar file</span>
                            </div>
                        </label>
                        
                        <label class="rsi-option">
                            <input type="radio" name="rsi_mode" value="skip">
                            <div class="option-content">
                                <span class="option-title">Skip for Now</span>
                                <span class="option-desc">Use default placeholder</span>
                            </div>
                        </label>
                    </div>
                    
                    <!-- Upload Input (hidden by default) -->
                    <div class="rsi-upload" id="rsi-upload" style="display: none;">
                        <input type="file" id="avatar-upload" accept="image/*">
                        <p class="upload-status" id="upload-status">No file selected</p>
                    </div>
                </div>
                
                <!-- Voice Selection -->
                <div class="voice-selection">
                    <label class="section-label">
                        <span class="section-icon">🎤</span>
                        Voice Manifest (Neutts-Air)
                    </label>
                    <p class="section-help">Select voice style tokens for TTS synthesis</p>
                    
                    <div class="voice-presets">
                        <label class="voice-option">
                            <input type="radio" name="voice_preset" value="generated" checked>
                            <div class="option-content">
                                <span class="option-title">Generated from Soul Anchor</span>
                                <span class="option-desc">Style tokens derived from persona</span>
                            </div>
                        </label>
                        
                        <label class="voice-option">
                            <input type="radio" name="voice_preset" value="minimal">
                            <div class="option-content">
                                <span class="option-title">Minimal</span>
                                <span class="option-desc">Sparse semantic compression</span>
                            </div>
                        </label>
                        
                        <label class="voice-option">
                            <input type="radio" name="voice_preset" value="expressive">
                            <div class="option-content">
                                <span class="option-title">Expressive</span>
                                <span class="option-desc">Full emotional range</span>
                            </div>
                        </label>
                        
                        <label class="voice-option">
                            <input type="radio" name="voice_preset" value="custom">
                            <div class="option-content">
                                <span class="option-title">Custom Tokens</span>
                                <span class="option-desc">Manual style tokens</span>
                            </div>
                        </label>
                    </div>
                    
                    <!-- Custom Tokens Input (hidden by default) -->
                    <div class="voice-custom" id="voice-custom" style="display: none;">
                        <label for="style-tokens">Style Tokens (comma-separated)</label>
                        <input type="text" id="style-tokens" placeholder="e.g., formality:casual, speed:fast, warmth:low">
                    </div>
                </div>
            </div>
            
            <!-- Stage 3: Login -->
            <div class="login-stage" id="login-stage">
                <div class="input-group">
                    <label for="username">Username</label>
                    <input type="text" id="username" name="username" required>
                </div>
                <div class="input-group">
                    <label for="password">Password</label>
                    <input type="password" id="password" name="password" required>
                </div>
                <button type="submit" class="btn-main" id="btn-submit">Initialize Session</button>
                <button type="button" class="btn-secondary" id="btn-back">← Back to Customization</button>
            </div>
            
            {% if error %}
                <p class="error">{{ error }}</p>
            {% endif %}
            
            {% if error %}
                <p class="error">{{ error }}</p>
            {% endif %}
        </form>
    </div>
    
    <script>
        // Stage management
        let currentStage = 'customization';
        
        const customizationStage = document.getElementById('customization-stage');
        const loginStage = document.getElementById('login-stage');
        const btnBack = document.getElementById('btn-back');
        
        // Load persona info
        fetch('/api/persona-info')
            .then(response => response.json())
            .then(data => {
                if (data.primary_name) {
                    document.getElementById('persona-name').textContent = data.primary_name;
                }
                if (data.archetype) {
                    document.getElementById('persona-subtitle').textContent = data.archetype;
                }
                if (data.avatar_path) {
                    const avatarEl = document.getElementById('persona-avatar');
                    avatarEl.innerHTML = `<img src="${data.avatar_path}" alt="${data.primary_name}" class="avatar-image">`;
                }
            })
            .catch(err => console.log('Using default Construct branding'));
        
        // RSI mode switching
        document.querySelectorAll('input[name="rsi_mode"]').forEach(radio => {
            radio.addEventListener('change', (e) => {
                const uploadDiv = document.getElementById('rsi-upload');
                uploadDiv.style.display = (e.target.value === 'upload') ? 'block' : 'none';
            });
        });
        
        // File upload handling
        document.getElementById('avatar-upload').addEventListener('change', (e) => {
            const file = e.target.files[0];
            const status = document.getElementById('upload-status');
            if (file) {
                status.textContent = `Selected: ${file.name}`;
                // Preview image
                const reader = new FileReader();
                reader.onload = (event) => {
                    const avatarEl = document.getElementById('persona-avatar');
                    avatarEl.innerHTML = `<img src="${event.target.result}" alt="Preview" class="avatar-image">`;
                };
                reader.readAsDataURL(file);
            } else {
                status.textContent = 'No file selected';
            }
        });
        
        // Voice preset switching
        document.querySelectorAll('input[name="voice_preset"]').forEach(radio => {
            radio.addEventListener('change', (e) => {
                const customDiv = document.getElementById('voice-custom');
                customDiv.style.display = (e.target.value === 'custom') ? 'block' : 'none';
            });
        });
        
        // Proceed to login button
        const btnContinue = document.createElement('button');
        btnContinue.textContent = 'Continue to Login →';
        btnContinue.className = 'btn-continue';
        btnContinue.type = 'button';
        customizationStage.appendChild(btnContinue);
        
        btnContinue.addEventListener('click', async () => {
            // Get RSI mode
            const rsiMode = document.querySelector('input[name="rsi_mode"]:checked').value;
            
            // Get voice preset
            const voicePreset = document.querySelector('input[name="voice_preset"]:checked').value;
            
            // Prepare customization data
            const formData = new FormData();
            formData.append('rsi_mode', rsiMode);
            formData.append('voice_preset', voicePreset);
            
            // If uploading RSI
            if (rsiMode === 'upload') {
                const fileInput = document.getElementById('avatar-upload');
                if (fileInput.files[0]) {
                    formData.append('rsi_upload', fileInput.files[0]);
                }
            }
            
            // If custom voice tokens
            if (voicePreset === 'custom') {
                const tokensInput = document.getElementById('style-tokens');
                if (tokensInput && tokensInput.value.trim()) {
                    formData.append('custom_tokens', tokensInput.value.trim());
                }
            }
            
            // Send customization data
            try {
                const response = await fetch('/api/persona-customize', {
                    method: 'POST',
                    body: formData
                });
                const result = await response.json();
                
                if (result.status === 'success') {
                    console.log('Customization saved:', result);
                    btnContinue.style.display = 'none';
                    currentStage = 'login';
                    customizationStage.style.display = 'none';
                    loginStage.style.display = 'block';
                    btnBack.style.display = 'inline-block';
                } else {
                    alert('Error saving customization: ' + (result.error || 'Unknown error'));
                }
            } catch (err) {
                console.error('Customization error:', err);
                alert('Failed to save customization');
            }
        });
        
        // Back button
        if (btnBack) {
            btnBack.addEventListener('click', () => {
                currentStage = 'customization';
                customizationStage.style.display = 'block';
                loginStage.style.display = 'none';
                btnBack.style.display = 'none';
                btnContinue.style.display = 'inline-block';
            });
        }
    </script>
</body>
</html>