-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.html
More file actions
350 lines (298 loc) · 10.2 KB
/
agent.html
File metadata and controls
350 lines (298 loc) · 10.2 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
<!doctype html>
<html lang="uk">
<head>
<base href="https://vaagenim-cardsharp.github.io/Website/">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Support — Agent Console</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;600;700;800&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0b0b10;
--card: rgba(255, 255, 255, .04);
--brd: rgba(255, 255, 255, .08);
--txt: #e8e8f0;
--sub: #a1a1b3;
--g1: #ff4ecd;
--g2: #6a8cff;
}
* {
box-sizing: border-box
}
body {
margin: 0;
background: var(--bg);
color: var(--txt);
font: 14px/1.4 system-ui, Segoe UI, Roboto, sans-serif
}
.wrap {
display: grid;
grid-template-columns: 280px 1fr;
min-height: 100vh
}
.side {
border-right: 1px solid var(--brd);
padding: 14px;
background: rgba(255, 255, 255, .02)
}
.main {
padding: 16px;
display: grid;
grid-template-rows: 1fr auto;
gap: 10px
}
.card {
background: var(--card);
border: 1px solid var(--brd);
border-radius: 14px;
overflow: hidden
}
.conv {
display: grid;
gap: 8px;
}
.conv-item {
padding: 10px;
border-radius: 12px;
cursor: pointer;
border: 1px solid transparent
}
.conv-item:hover {
background: rgba(255, 255, 255, .05);
border-color: var(--brd)
}
.conv-item.active {
background: linear-gradient(135deg, rgba(255, 78, 205, .14), rgba(106, 140, 255, .12));
border-color: var(--brd)
}
.name {
font-weight: 700
}
.last {
color: var(--sub);
font-size: 12px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis
}
.thread {
padding: 12px;
display: grid;
gap: 8px;
max-height: 70vh;
overflow: auto
}
.bubble {
max-width: 72%;
padding: 10px 12px;
border-radius: 14px;
border: 1px solid var(--brd)
}
.bubble.user {
justify-self: end;
background: rgba(106, 140, 255, .16)
}
.bubble.agent {
justify-self: start;
background: rgba(255, 255, 255, .06)
}
.composer {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
padding: 12px
}
textarea {
resize: vertical;
min-height: 70px;
padding: 10px;
border-radius: 12px;
border: 1px solid var(--brd);
background: rgba(255, 255, 255, .06);
color: var(--txt)
}
button {
border: none;
border-radius: 12px;
padding: 10px 14px;
color: #fff;
cursor: pointer;
.wrap {
grid-template-columns: 220px 1fr;
}
.side {
padding: 10px;
}
.main {
padding: 12px;
gap: 8px;
}
.conv-item {
padding: 8px 10px;
border-radius: 10px;
}
.thread {
padding: 10px;
gap: 6px;
max-height: 68vh;
}
.composer {
grid-template-columns: 1fr auto;
gap: 8px;
padding: 10px;
}
textarea {
min-height: 54px;
font-size: 13px;
}
button {
padding: 8px 12px;
}
background:linear-gradient(135deg, var(--g1), var(--g2))
}
/* компактні скляні бульбашки */
.cs-msg {
max-width: 65%;
width: fit-content;
display: inline-block;
padding: 8px 10px;
font-size: 13px;
line-height: 1.35;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, .10);
background: rgba(255, 255, 255, .07);
backdrop-filter: blur(10px) saturate(160%);
-webkit-backdrop-filter: blur(10px) saturate(160%);
color: #e8e8f0;
white-space: pre-wrap;
word-break: break-word;
box-shadow: 0 3px 8px rgba(0, 0, 0, .18);
}
.cs-msg--user {
align-self: flex-start;
background: linear-gradient(135deg, rgba(170, 90, 255, .14), rgba(255, 80, 180, .12));
border-bottom-left-radius: 6px;
}
.cs-msg--agent {
align-self: flex-end;
background: linear-gradient(135deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .04));
border-bottom-right-radius: 6px;
}
/* нормальна колонка для повідомлень — без розтягування */
.thread{
display: flex !important; /* переважує будь-які глобальні стилі */
flex-direction: column;
justify-content: flex-start; /* НІЯКОГО space-between */
align-items: stretch;
align-content: flex-start;
gap: 8px;
padding: 10px;
max-height: 68vh;
overflow-y: auto;
}
/* підчищаємо випадкові маржини від глобальних стилів */
.thread > * { margin: 0 !important; }
/* бульбашки — залишаємо компактними */
.cs-msg{ max-width: 65%; width: fit-content; padding: 8px 10px; font-size: 13px; border-radius:12px; }
.cs-msg--user{ align-self:flex-start; }
.cs-msg--agent{ align-self:flex-end; }
</style>
</head>
<body>
<!-- важливо: шляхи до скриптів теж без / -->
<script type="module" src="agent.js?v=1"></script>
<div class="wrap">
<!-- Список користувачів -->
<aside class="side">
<h3>Conversations</h3>
<div id="conv-list" class="conv"></div>
</aside>
<!-- Поточний діалог -->
<section class="main">
<div class="card thread" id="thread"></div>
<div class="card composer">
<textarea id="msg" placeholder="Reply to user..."></textarea>
<button id="send">Send</button>
</div>
</section>
</div>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/12.5.0/firebase-app.js";
import { getFirestore, collection, doc, addDoc, setDoc,
onSnapshot, query, orderBy, serverTimestamp } from "https://www.gstatic.com/firebasejs/12.5.0/firebase-firestore.js";
const firebaseConfig = {
apiKey: "AIzaSyCfXt2YFfrTF0h0bxuh0uAL7VyC7waqTNOE",
authDomain: "cardsharp-chat.firebaseapp.com",
projectId: "cardsharp-chat",
storageBucket: "cardsharp-chat.firebasestorage.app",
messagingSenderId: "21085363631",
appId: "1:21085363631:web:f10be98af4dab37aefa75a",
measurementId: "G-FFNVQHSXHR"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const convList = document.getElementById('conv-list');
const thread = document.getElementById('thread');
const msgEl = document.getElementById('msg');
const sendBtn = document.getElementById('send');
let currentId = null;
let unsubThread = null;
// Conversations list
const convQ = query(collection(db,'conversations'), orderBy('lastAt','desc'));
onSnapshot(convQ, (snap) => {
convList.innerHTML = '';
snap.forEach(d => {
const c = d.data();
const el = document.createElement('div');
el.className = 'conv-item' + (d.id===currentId ? ' active':'');
el.innerHTML = `<div class="name">${c.name || 'Guest'}</div><div class="last">${c.lastMessage || ''}</div>`;
el.onclick = () => selectConversation(d.id, c.name || 'Guest');
convList.appendChild(el);
});
});
function selectConversation(id, name){
currentId = id;
if (unsubThread) { unsubThread(); unsubThread=null; }
thread.innerHTML = '';
const qMsgs = query(collection(doc(db,'conversations',id),'messages'), orderBy('createdAt','asc'));
unsubThread = onSnapshot(qMsgs, (snap) => {
thread.innerHTML = '';
snap.forEach(d => {
const m = d.data();
const b = document.createElement('div');
b.className = 'cs-msg ' + (m.role === 'agent' ? 'cs-msg--agent' : 'cs-msg--user');
b.textContent = m.text || '';
thread.appendChild(b);
});
thread.scrollTop = thread.scrollHeight;
});
[...convList.children].forEach(ch => ch.classList.remove('active'));
const match = [...convList.children].find(ch => ch.querySelector('.name')?.textContent===name);
if (match) match.classList.add('active');
}
// Send message
sendBtn.addEventListener('click', sendMessage);
msgEl.addEventListener('keydown', e => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
async function sendMessage() {
if(!currentId) return alert('Select a conversation first');
const text = msgEl.value.trim();
if(!text) return;
const convRef = doc(db,'conversations',currentId);
await addDoc(collection(convRef,'messages'), {
role:'agent', text, createdAt: serverTimestamp()
});
await setDoc(convRef, { lastMessage: text, lastAt: serverTimestamp() }, { merge:true });
msgEl.value = '';
}
</script>
</body>
</html>
</body>
</html>