forked from zyntromedia/pure-agent-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
575 lines (516 loc) · 22.6 KB
/
Copy pathindex.html
File metadata and controls
575 lines (516 loc) · 22.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
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
<!DOCTYPE html>
<html lang="th">
<head>
<script>// Playables SDK v1.0.0
// Game lifecycle bridge: rAF-based game-ready detection + event communication
(function() {
'use strict';
if (window.playablesSDK) return;
var HANDLER_NAME = 'playablesGameEventHandler';
var ANDROID_BRIDGE_NAME = '_MetaPlayablesBridge';
var RAF_FRAME_THRESHOLD = 3;
var gameReadySent = false;
var firstInteractionSent = false;
var errorSent = false;
var frameCount = 0;
var originalRAF = window.requestAnimationFrame;
function hasIOSBridge() {
return !!(window.webkit &&
window.webkit.messageHandlers &&
window.webkit.messageHandlers[HANDLER_NAME]);
}
function hasAndroidBridge() {
return !!(window[ANDROID_BRIDGE_NAME] &&
typeof window[ANDROID_BRIDGE_NAME].postEvent === 'function');
}
function isInIframe() {
return !!(window.parent && window.parent !== window);
}
function sendEvent(eventName, payload) {
var message = {
type: eventName,
payload: payload || {},
timestamp: Date.now()
};
if (hasIOSBridge()) {
try {
window.webkit.messageHandlers[HANDLER_NAME].postMessage(message);
} catch (e) { /* ignore */ }
return;
}
if (hasAndroidBridge()) {
try {
var p = payload || {};
p.__secureToken = window.__fbAndroidBridgeAuthToken || '';
p.timestamp = message.timestamp;
window[ANDROID_BRIDGE_NAME].postEvent(
eventName,
JSON.stringify(p)
);
} catch (e) { /* ignore */ }
return;
}
if (isInIframe()) {
try {
window.parent.postMessage(message, '');
} catch (e) { /* ignore */ }
return;
}
}
function onFrame() {
if (gameReadySent) return;
frameCount++;
if (frameCount >= RAF_FRAME_THRESHOLD) {
gameReadySent = true;
sendEvent('game_ready', {
frame_count: frameCount,
detected_at: Date.now()
});
return;
}
originalRAF.call(window, onFrame);
}
if (originalRAF) {
window.requestAnimationFrame = function(callback) {
if (!gameReadySent) {
return originalRAF.call(window, function(timestamp) {
frameCount++;
if (frameCount >= RAF_FRAME_THRESHOLD && !gameReadySent) {
gameReadySent = true;
sendEvent('game_ready', {
frame_count: frameCount,
detected_at: Date.now()
});
}
callback(timestamp);
});
}
return originalRAF.call(window, callback);
};
}
function setupFirstInteractionDetection() {
var events = ['touchstart', 'mousedown', 'keydown'];
function onFirstInteraction() {
if (firstInteractionSent) return;
firstInteractionSent = true;
sendEvent('user_interaction_start', null);
for (var i = 0; i < events.length; i++) {
document.removeEventListener(events[i], onFirstInteraction, true);
}
}
for (var i = 0; i < events.length; i++) {
document.addEventListener(events[i], onFirstInteraction, true);
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', setupFirstInteractionDetection);
} else {
setupFirstInteractionDetection();
}
window.addEventListener('error', function(event) {
if (errorSent) return;
errorSent = true;
sendEvent('error', {
message: event.message || 'Unknown error',
source: event.filename || '',
lineno: event.lineno || 0,
colno: event.colno || 0,
auto_captured: true
});
});
window.addEventListener('unhandledrejection', function(event) {
if (errorSent) return;
errorSent = true;
var reason = event.reason;
sendEvent('error', {
message: (reason instanceof Error) ? reason.message : String(reason),
type: 'unhandled_promise_rejection',
auto_captured: true
});
});
window.playablesSDK = {
complete: function(score) {
sendEvent('game_ended', {
score: score,
completed: true
});
},
error: function(message) {
if (errorSent) return;
errorSent = true;
sendEvent('error', {
message: message || 'Unknown error',
auto_captured: false
});
},
sendEvent: function(eventName, payload) {
if (!eventName || typeof eventName !== 'string') return;
sendEvent(eventName, payload);
}
};
if (originalRAF) {
originalRAF.call(window, onFrame);
}
})();</script>
<script>window.Intl=window.Intl||{};Intl.t=function(s){return(Intl._locale&&Intl._locale[s])||s;};</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CrystalCastle Azure API — Preview</title>
<meta name="color-scheme" content="dark">
<script src="https://cdn.tailwindcss.com"></script>
<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=Noto+Sans+Thai:wght@300;400;500;600&family=JetBrains+Mono:wght@400&display=swap" rel="stylesheet">
<style>
* {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
font-family: 'Noto Sans Thai', ui-sans-serif, system-ui, -apple-system, sans-serif;
background: #050810;
overscroll-behavior: none;
}
.glass {
background: rgba(17, 25, 40, 0.7);
backdrop-filter: blur(24px) saturate(180%);
-webkit-backdrop-filter: blur(24px) saturate(180%);
border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow:
0 8px 32px rgba(0, 0, 0, 0.4),
inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.glass-strong {
background: rgba(10, 15, 25, 0.85);
backdrop-filter: blur(32px) saturate(200%);
-webkit-backdrop-filter: blur(32px) saturate(200%);
}
.mono {
font-family: 'JetBrains Mono', monospace;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }
textarea {
field-sizing: content;
}
.shimmer {
position: relative;
overflow: hidden;
}
.shimmer::after {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
transform: translateX(-100%);
animation: shimmer 2s infinite;
}
@keyframes shimmer {
100% { transform: translateX(200%); }
}
.fade-in {
animation: fadeIn 0.4s ease-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body class="min-h-screen text-zinc-100 selection:bg-violet-500/30 selection:text-violet-200">
<div class="fixed inset-0 -z-10">
<div class="absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-slate-900 via-[#050810] to-black"></div>
<div class="absolute top-[-20%] -left-[10%] w-[600px] h-[600px] bg-violet-600/20 rounded-full blur-[140px] animate-pulse"></div>
<div class="absolute bottom-[-20%] -right-[10%] w-[600px] h-[600px] bg-cyan-500/15 rounded-full blur-[140px] animate-pulse [animation-duration:7s]"></div>
<div class="absolute top-[30%] left-[50%] -translate-x-1/2 w-[800px] h-[800px] bg-indigo-600/10 rounded-full blur-[160px]"></div>
</div>
<div class="relative z-10 min-h-screen flex flex-col">
<header class="sticky top-0 z-20 border-b border-white/[0.05] glass-strong">
<div class="max-w-[920px] mx-auto px-4 sm:px-6 h-[68px] flex items-center justify-between">
<div class="flex items-center gap-3">
<div class="w-9 h-9 rounded-2xl bg-gradient-to-br from-violet-600 to-cyan-400 flex items-center justify-center shadow-lg shadow-violet-600/20 ring-1 ring-white/10">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" class="text-white">
<path d="M12 2L20 8.5V15.5L12 22L4 15.5V8.5L12 2Z" stroke="currentColor" stroke-width="1.5" fill="currentColor" fill-opacity="0.2"/>
</svg>
</div>
<div>
<h1 class="text-[17px] font-semibold tracking-tight leading-none">CrystalCastle</h1>
<p class="text-[11px] text-zinc-500 font-medium mt-[2px]">Azure API Preview</p>
</div>
</div>
<div class="flex items-center gap-2">
<span class="hidden sm:inline text-[11px] px-2.5 py-1 rounded-full bg-white/5 border border-white/10 text-zinc-400">/api/chat</span>
<span class="text-[11px] px-2.5 py-1 rounded-full bg-emerald-500/10 border border-emerald-500/20 text-emerald-300">Preview</span>
</div>
</div>
</header>
<main class="flex-1 w-full max-w-[920px] mx-auto px-4 sm:px-6 py-8 sm:py-12">
<div class="glass rounded-[28px] p-5 sm:p-6 mb-6 fade-in">
<div class="flex items-center justify-between mb-4">
<div class="flex items-center gap-2.5">
<div class="relative">
<span id="status-dot" class="w-2.5 h-2.5 rounded-full bg-zinc-600 block"></span>
<span id="status-pulse" class="absolute inset-0 w-2.5 h-2.5 rounded-full bg-zinc-600/50 animate-ping hidden"></span>
</div>
<h2 class="text-[15px] font-medium text-zinc-200">สถานะระบบ</h2>
</div>
<button id="refresh-status" class="group flex items-center gap-1.5 text-[12px] text-zinc-500 hover:text-zinc-300 transition">
<svg class="w-3.5 h-3.5 group-active:rotate-180 transition-transform duration-500" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 2v6h-6M3 12a9 9 0 0 1 15-6.7L21 8M3 22v-6h6M21 12a9 9 0 0 1-15 6.7L3 16"/>
</svg>
รีเฟรช
</button>
</div>
<div class="grid grid-cols-3 gap-3 sm:gap-6">
<div class="group">
<p class="text-[11px] text-zinc-500 mb-1.5 uppercase tracking-wide font-medium">สถานะ</p>
<p id="status-text" class="text-[14px] font-medium text-zinc-300">กำลังตรวจสอบ...</p>
</div>
<div>
<p class="text-[11px] text-zinc-500 mb-1.5 uppercase tracking-wide font-medium">Latency</p>
<p id="status-latency" class="text-[14px] font-medium mono text-zinc-300">—</p>
</div>
<div>
<p class="text-[11px] text-zinc-500 mb-1.5 uppercase tracking-wide font-medium">เวอร์ชัน</p>
<p id="status-version" class="text-[14px] font-medium mono text-zinc-300">—</p>
</div>
</div>
<div class="mt-4 pt-4 border-t border-white/[0.06] flex items-center justify-between">
<p class="text-[11px] text-zinc-600 mono truncate">https://crystalcastle-api.azurewebsites.net</p>
<p id="status-updated" class="text-[11px] text-zinc-600 whitespace-nowrap ml-3">—</p>
</div>
</div>
<div class="glass rounded-[28px] p-5 sm:p-7 fade-in [animation-delay:100ms]">
<div class="flex items-start justify-between mb-5">
<div>
<h2 class="text-[18px] sm:text-[20px] font-semibold tracking-tight">ทดสอบ API</h2>
<p class="text-[13px] text-zinc-500 mt-1">ส่งข้อความไปยัง <span class="text-zinc-400 mono">/api/chat</span></p>
</div>
</div>
<form id="chat-form" class="relative">
<div class="relative group">
<textarea
id="message-input"
rows="3"
placeholder="พิมพ์ข้อความของคุณที่นี่..."
class="w-full min-h-[120px] max-h-[320px] resize-none rounded-2xl bg-black/40 border border-white/10 px-4 py-3.5 text-[15px] leading-relaxed placeholder-zinc-600 focus:outline-none focus:ring-2 focus:ring-violet-500/50 focus:border-violet-500/50 transition-all"
autofocus
></textarea>
<div class="absolute bottom-3 right-3 flex items-center gap-1.5 opacity-0 group-focus-within:opacity-100 transition-opacity">
<kbd class="px-1.5 py-0.5 text-[10px] bg-white/10 border border-white/10 rounded text-zinc-500">⌘</kbd>
<kbd class="px-1.5 py-0.5 text-[10px] bg-white/10 border border-white/10 rounded text-zinc-500">↵</kbd>
</div>
</div>
<div class="flex flex-wrap gap-2 mt-3">
<button type="button" data-example="สวัสดีครับ CrystalCastle" class="example-chip text-[12px] px-3 py-1.5 rounded-full bg-white/[0.04] hover:bg-white/[0.08] border border-white/10 text-zinc-400 hover:text-zinc-200 transition">สวัสดีครับ</button>
<button type="button" data-example="แนะนำความสามารถของ API นี้หน่อย" class="example-chip text-[12px] px-3 py-1.5 rounded-full bg-white/[0.04] hover:bg-white/[0.08] border border-white/10 text-zinc-400 hover:text-zinc-200 transition">แนะนำ API</button>
<button type="button" data-example="ทดสอบการเชื่อมต่อ" class="example-chip text-[12px] px-3 py-1.5 rounded-full bg-white/[0.04] hover:bg-white/[0.08] border border-white/10 text-zinc-400 hover:text-zinc-200 transition">ทดสอบระบบ</button>
</div>
<div class="flex items-center justify-between mt-5">
<p class="text-[12px] text-zinc-600 hidden sm:block">กด Enter เพื่อขึ้นบรรทัดใหม่ • Ctrl+Enter เพื่อส่ง</p>
<div class="flex items-center gap-2 ml-auto">
<button
type="button"
id="clear-btn"
class="h-[38px] px-4 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-[13px] text-zinc-400 hover:text-zinc-200 transition"
>
ล้าง
</button>
<button
type="submit"
id="send-btn"
class="group relative h-[38px] px-5 rounded-xl bg-white text-black font-medium text-[14px] hover:bg-zinc-200 active:bg-zinc-300 transition disabled:opacity-40 disabled:cursor-not-allowed overflow-hidden"
>
<span class="relative z-10 flex items-center gap-1.5">
<span>ส่ง</span>
<svg class="w-3.5 h-3.5 transition-transform group-hover:translate-x-0.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
<path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"/>
</svg>
</span>
</button>
</div>
</div>
</form>
<div id="response-container" class="hidden mt-6">
<div class="flex items-center gap-2 mb-3">
<div class="w-5 h-5 rounded-lg bg-violet-500/20 border border-violet-500/30 flex items-center justify-center">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" class="text-violet-300">
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
</svg>
</div>
<h3 class="text-[13px] font-medium text-zinc-400 uppercase tracking-wide">การตอบกลับ</h3>
<div id="response-status" class="ml-auto"></div>
</div>
<div class="relative rounded-2xl overflow-hidden border border-white/10 bg-black/50">
<div class="absolute inset-0 bg-gradient-to-b from-violet-500/[0.03] to-transparent pointer-events-none"></div>
<div class="relative p-4 sm:p-5">
<div id="response-content" class="text-[14px] leading-[1.7] text-zinc-200 whitespace-pre-wrap break-words"></div>
</div>
<div class="relative flex items-center justify-between px-4 py-2.5 bg-white/[0.02] border-t border-white/5">
<div class="flex items-center gap-3">
<span id="response-time" class="text-[11px] mono text-zinc-500"></span>
<span id="response-size" class="text-[11px] mono text-zinc-600"></span>
</div>
<div class="flex items-center gap-1.5">
<button id="copy-btn" class="h-6 px-2.5 rounded-lg bg-white/5 hover:bg-white/10 text-[11px] text-zinc-400 hover:text-zinc-200 transition flex items-center gap-1">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg>
คัดลอก
</button>
</div>
</div>
</div>
</div>
</main>
<footer class="max-w-[920px] w-full mx-auto px-4 sm:px-6 py-6 border-t border-white/[0.05] text-center text-zinc-600 text-[12px]">
© 2026 CrystalCastle. All rights reserved. Powered by Azure OpenAI.
</footer>
</div>
<script>
const BASE_URL = 'https://crystalcastle-api.azurewebsites.net';
// Elements
const statusDot = document.getElementById('status-dot');
const statusPulse = document.getElementById('status-pulse');
const statusText = document.getElementById('status-text');
const statusLatency = document.getElementById('status-latency');
const statusVersion = document.getElementById('status-version');
const statusUpdated = document.getElementById('status-updated');
const refreshStatusBtn = document.getElementById('refresh-status');
const chatForm = document.getElementById('chat-form');
const messageInput = document.getElementById('message-input');
const sendBtn = document.getElementById('send-btn');
const clearBtn = document.getElementById('clear-btn');
const exampleChips = document.querySelectorAll('.example-chip');
const responseContainer = document.getElementById('response-container');
const responseContent = document.getElementById('response-content');
const responseStatus = document.getElementById('response-status');
const responseTime = document.getElementById('response-time');
const responseSize = document.getElementById('response-size');
const copyBtn = document.getElementById('copy-btn');
// 1. ตรวจสอบสถานะระบบ (Health Check)
async function checkSystemStatus() {
const startTime = Date.now();
statusText.innerText = 'กำลังตรวจสอบ...';
statusText.className = 'text-[14px] font-medium text-zinc-400';
try {
// แนะนำให้ยิงไปที่ Endpoint ของคุณ (เช่น /api/health หรือ / ตามความเหมาะสม)
const response = await fetch(`${BASE_URL}/`, { method: 'GET' });
const latency = Date.now() - startTime;
statusDot.className = 'w-2.5 h-2.5 rounded-full bg-emerald-500 block';
statusPulse.className = 'absolute inset-0 w-2.5 h-2.5 rounded-full bg-emerald-500/50 animate-ping block';
statusText.innerText = 'ออนไลน์';
statusText.className = 'text-[14px] font-medium text-emerald-400';
statusLatency.innerText = `${latency} ms`;
statusVersion.innerText = 'v1.0.0-preview';
} catch (error) {
statusDot.className = 'w-2.5 h-2.5 rounded-full bg-rose-500 block';
statusPulse.className = 'absolute inset-0 w-2.5 h-2.5 rounded-full bg-rose-500/50 animate-ping block';
statusText.innerText = 'ออฟไลน์';
statusText.className = 'text-[14px] font-medium text-rose-400';
statusLatency.innerText = '—';
statusVersion.innerText = '—';
} finally {
const now = new Date();
statusUpdated.innerText = `อัปเดตล่าสุด: ${now.toLocaleTimeString('th-TH')}`;
}
}
// 2. การส่งข้อความแชทไปยัง API
chatForm.addEventListener('submit', async (e) => {
e.preventDefault();
const prompt = messageInput.value.trim();
if (!prompt) return;
// UI States: Loading
sendBtn.disabled = true;
sendBtn.innerHTML = '<span>กำลังส่ง...</span>';
responseContainer.classList.remove('hidden');
responseContent.innerText = 'กำลังประมวลผลคำสั่งซื้อและวิเคราะห์ข้อมูล...';
responseStatus.innerHTML = `<span class="text-[11px] px-2 py-0.5 rounded bg-amber-500/10 border border-amber-500/20 text-amber-300">PENDING</span>`;
responseTime.innerText = 'Latency: —';
responseSize.innerText = 'Size: —';
const startTime = Date.now();
try {
const response = await fetch(`${BASE_URL}/api/chat`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: prompt }) // ปรับแก้ Key ตามที่ Backend ของคุณใช้ (เช่น prompt, message, text)
});
const latency = Date.now() - startTime;
const dataText = await response.text();
// คำนวณขนาดข้อมูล
const byteSize = new Blob([dataText]).size;
const displaySize = byteSize > 1024 ? `${(byteSize/1024).toFixed(2)} KB` : `${byteSize} Bytes`;
if (response.ok) {
// สำเร็จ
try {
const json = JSON.parse(dataText);
// แสดงผลลัพธ์ถ้าได้เป็น JSON (ปรับจุดนี้ตาม Response โครงสร้างของคุณ เช่น json.reply หรือ json.response)
responseContent.innerText = json.reply || json.response || JSON.stringify(json, null, 2);
} catch {
responseContent.innerText = dataText; // แสดง Text ดิบถ้าไม่ใช่ JSON
}
responseStatus.innerHTML = `<span class="text-[11px] px-2 py-0.5 rounded bg-emerald-500/10 border border-emerald-500/20 text-emerald-300">200 OK</span>`;
} else {
// เกิดข้อผิดพลาดจากฝั่ง Server
responseContent.innerText = `Error: ${response.status} ${response.statusText}\n${dataText}`;
responseStatus.innerHTML = `<span class="text-[11px] px-2 py-0.5 rounded bg-rose-500/10 border border-rose-500/20 text-rose-300">ERROR</span>`;
}
responseTime.innerText = `Latency: ${latency}ms`;
responseSize.innerText = `Size: ${displaySize}`;
} catch (error) {
// ข้อผิดพลาดจากการเชื่อมต่อ (Network Error)
responseContent.innerText = `ไม่สามารถเชื่อมต่อกับ API ได้: ${error.message}`;
responseStatus.innerHTML = `<span class="text-[11px] px-2 py-0.5 rounded bg-rose-500/10 border border-rose-500/20 text-rose-300">FAILED</span>`;
} finally {
sendBtn.disabled = false;
sendBtn.innerHTML = `<span class="relative z-10 flex items-center gap-1.5">
<span>ส่ง</span>
<svg class="w-3.5 h-3.5 transition-transform group-hover:translate-x-0.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
<path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"/>
</svg>
</span>`;
}
});
// 3. ปุ่มกดตัวอย่างข้อความ (Example Chips)
exampleChips.forEach(chip => {
chip.addEventListener('click', () => {
messageInput.value = chip.getAttribute('data-example');
messageInput.focus();
});
});
// 4. ปุ่มล้างข้อความ (Clear Button)
clearBtn.addEventListener('click', () => {
messageInput.value = '';
responseContainer.classList.add('hidden');
messageInput.focus();
});
// 5. ปุ่มคัดลอกข้อความตอบกลับ (Copy to Clipboard)
copyBtn.addEventListener('click', () => {
const textToCopy = responseContent.innerText;
navigator.clipboard.writeText(textToCopy).then(() => {
const originalText = copyBtn.innerHTML;
copyBtn.innerHTML = 'คัดลอกแล้ว!';
copyBtn.classList.add('text-emerald-400');
setTimeout(() => {
copyBtn.innerHTML = originalText;
copyBtn.classList.remove('text-emerald-400');
}, 2000);
});
});
// 6. ทางลัดปุ่มกด (Ctrl + Enter หรือ Cmd + Enter เพื่อส่งข้อความ)
messageInput.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault();
chatForm.dispatchEvent(new Event('submit'));
}
});
// 7. จัดการเหตุการณ์เมื่อกดปุ่มรีเฟรชสถานะระบบ
refreshStatusBtn.addEventListener('click', checkSystemStatus);
// เริ่มต้นเช็คสถานะทันทีที่โหลดหน้าจอเสร็จ
document.addEventListener('DOMContentLoaded', checkSystemStatus);
</script>
</body>
</html>