-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
440 lines (371 loc) · 13.6 KB
/
index.html
File metadata and controls
440 lines (371 loc) · 13.6 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zava AI Shopping Assistant</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.chat-container {
width: 90%;
max-width: 800px;
height: 90vh;
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
display: flex;
flex-direction: column;
overflow: hidden;
}
.chat-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
text-align: center;
}
.chat-header h1 {
font-size: 24px;
margin-bottom: 5px;
}
.chat-header p {
font-size: 14px;
opacity: 0.9;
}
.chat-messages {
flex: 1;
overflow-y: auto;
padding: 20px;
background: #f7f7f7;
}
.message {
margin-bottom: 15px;
display: flex;
flex-direction: column;
animation: fadeIn 0.3s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.message.user {
align-items: flex-end;
}
.message.assistant {
align-items: flex-start;
}
.agent-badge {
font-size: 11px;
font-weight: 600;
color: #667eea;
padding: 4px 10px;
background: rgba(102, 126, 234, 0.1);
border-radius: 12px;
width: fit-content;
margin-bottom: 5px;
}
.message-content {
max-width: 70%;
padding: 12px 16px;
border-radius: 18px;
word-wrap: break-word;
}
.message.user .message-content {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.message.assistant .message-content {
background: white;
color: #333;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
line-height: 1.6;
}
/* Markdown formatting */
.message-content h1, .message-content h2, .message-content h3 {
margin-top: 12px;
margin-bottom: 8px;
font-weight: 600;
}
.message-content h1 { font-size: 1.4em; }
.message-content h2 { font-size: 1.2em; }
.message-content h3 { font-size: 1.1em; }
.message-content p {
margin-bottom: 10px;
}
.message-content ul, .message-content ol {
margin-left: 20px;
margin-bottom: 10px;
}
.message-content li {
margin-bottom: 5px;
}
.message-content strong {
font-weight: 600;
}
.message-content em {
font-style: italic;
}
.message-content code {
background: #f5f5f5;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
font-size: 0.9em;
}
.message-content pre {
background: #f5f5f5;
padding: 10px;
border-radius: 5px;
overflow-x: auto;
margin-bottom: 10px;
}
.message-content pre code {
background: none;
padding: 0;
}
.message.system .message-content {
background: #fff3cd;
color: #856404;
max-width: 100%;
text-align: center;
}
.chat-input-container {
padding: 20px;
background: white;
border-top: 1px solid #e0e0e0;
display: flex;
gap: 10px;
}
#messageInput {
flex: 1;
padding: 12px 16px;
border: 2px solid #e0e0e0;
border-radius: 25px;
font-size: 14px;
outline: none;
transition: border-color 0.3s;
}
#messageInput:focus {
border-color: #667eea;
}
#sendButton {
padding: 12px 30px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 25px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s;
}
#sendButton:hover {
transform: scale(1.05);
}
#sendButton:active {
transform: scale(0.95);
}
#sendButton:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.typing-indicator {
display: none;
padding: 12px 16px;
background: white;
border-radius: 18px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
width: fit-content;
}
.typing-indicator.active {
display: block;
}
.typing-indicator span {
height: 8px;
width: 8px;
background: #667eea;
border-radius: 50%;
display: inline-block;
margin: 0 2px;
animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) {
animation-delay: 0.2s;
}
.typing-indicator span:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes typing {
0%, 60%, 100% { transform: translateY(0); }
30% { transform: translateY(-10px); }
}
</style>
<!-- Markdown rendering library -->
<script src="https://cdn.jsdelivr.net/npm/marked@11.1.1/marked.min.js"></script>
</head>
<body>
<div class="chat-container">
<div class="chat-header">
<h1>🏠 Zava AI Shopping Assistant</h1>
<p>Your DIY Project Helper</p>
</div>
<div class="chat-messages" id="chatMessages">
<div class="message system">
<div class="message-content">
Welcome to Zava! I'm here to help you with your DIY projects. Ask me about our products, get recommendations, or find store locations.
</div>
</div>
</div>
<div class="chat-input-container">
<input type="text" id="messageInput" placeholder="Ask about paints, tools, or DIY tips..." />
<button id="sendButton">Send</button>
</div>
</div>
<script>
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const ws = new WebSocket(`${protocol}//${window.location.host}/ws`);
const messagesContainer = document.getElementById('chatMessages');
const messageInput = document.getElementById('messageInput');
const sendButton = document.getElementById('sendButton');
let typingIndicator = null;
ws.onopen = () => {
console.log('WebSocket connected');
addSystemMessage('Connected to Zava Assistant');
};
ws.onclose = () => {
console.log('WebSocket disconnected');
addSystemMessage('Disconnected from server');
};
ws.onerror = (error) => {
console.error('WebSocket error:', error);
addSystemMessage('Connection error occurred');
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
removeTypingIndicator();
if (data.answer) {
const agentName = getAgentDisplayName(data.agent);
const cleaned = sanitizeAssistantText(data.answer);
addMessage(cleaned, 'assistant', agentName, data.image_url);
}
if (data.error) {
addSystemMessage(`Error: ${data.error}`);
}
};
function getAgentDisplayName(agent) {
const agentNames = {
'cora': '🏠 Cora',
'interior_design': '🎨 Design Specialist',
'inventory': '📦 Inventory Manager',
'customer_loyalty': '🎁 Rewards Specialist',
'cart': '🛒 Cart Manager',
'single': '🤖 Assistant'
};
return agentNames[agent] || '🤖 Assistant';
}
function addMessage(text, type, agentName = null, imageUrl = null) {
const messageDiv = document.createElement('div');
messageDiv.className = `message ${type}`;
// Add agent badge for assistant messages
if (type === 'assistant' && agentName) {
const agentBadge = document.createElement('div');
agentBadge.className = 'agent-badge';
agentBadge.textContent = agentName;
messageDiv.appendChild(agentBadge);
}
const contentDiv = document.createElement('div');
contentDiv.className = 'message-content';
// Render markdown for assistant messages, plain text for user messages
if (type === 'assistant') {
contentDiv.innerHTML = marked.parse(text);
// Add image if provided
if (imageUrl) {
const imageContainer = document.createElement('div');
imageContainer.style.marginTop = '10px';
const img = document.createElement('img');
img.src = imageUrl;
img.alt = 'Generated visualization';
img.style.maxWidth = '100%';
img.style.borderRadius = '8px';
img.style.boxShadow = '0 2px 8px rgba(0,0,0,0.1)';
img.style.cursor = 'pointer';
img.onclick = () => window.open(imageUrl, '_blank');
imageContainer.appendChild(img);
contentDiv.appendChild(imageContainer);
}
} else {
contentDiv.textContent = text;
}
messageDiv.appendChild(contentDiv);
messagesContainer.appendChild(messageDiv);
messagesContainer.scrollTop = messagesContainer.scrollHeight;
}
function addSystemMessage(text) {
const messageDiv = document.createElement('div');
messageDiv.className = 'message system';
const contentDiv = document.createElement('div');
contentDiv.className = 'message-content';
contentDiv.textContent = text;
messageDiv.appendChild(contentDiv);
messagesContainer.appendChild(messageDiv);
messagesContainer.scrollTop = messagesContainer.scrollHeight;
}
function showTypingIndicator() {
typingIndicator = document.createElement('div');
typingIndicator.className = 'message assistant';
const indicator = document.createElement('div');
indicator.className = 'typing-indicator active';
indicator.innerHTML = '<span></span><span></span><span></span>';
typingIndicator.appendChild(indicator);
messagesContainer.appendChild(typingIndicator);
messagesContainer.scrollTop = messagesContainer.scrollHeight;
}
function removeTypingIndicator() {
if (typingIndicator) {
typingIndicator.remove();
typingIndicator = null;
}
}
function sendMessage() {
const message = messageInput.value.trim();
if (!message || ws.readyState !== WebSocket.OPEN) return;
addMessage(message, 'user');
ws.send(message);
messageInput.value = '';
showTypingIndicator();
}
function sanitizeAssistantText(text) {
if (!text) return '';
const trimmed = text.trim();
if (trimmed.startsWith('{') && trimmed.includes('"answer"')) {
try {
const obj = JSON.parse(trimmed);
if (typeof obj.answer === 'string') {
return obj.answer.trim();
}
} catch (e) {
// ignore
}
}
return trimmed;
}
sendButton.addEventListener('click', sendMessage);
messageInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
sendMessage();
}
});
</script>
</body>
</html>