2026-02-04 23:36:23 +03:00
|
|
|
<!doctype html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
2026-02-26 15:05:18 +03:00
|
|
|
<title>RAG Multi-Window Demo</title>
|
2026-02-04 23:36:23 +03:00
|
|
|
<style>
|
2026-02-26 15:05:18 +03:00
|
|
|
:root {
|
|
|
|
|
--bg: #f1efe8;
|
|
|
|
|
--paper: #fffdf7;
|
|
|
|
|
--ink: #1f2937;
|
|
|
|
|
--muted: #6b7280;
|
|
|
|
|
--line: #dfd8c9;
|
|
|
|
|
--accent: #0f766e;
|
|
|
|
|
--accent-2: #d97706;
|
|
|
|
|
--bot: #ece8dc;
|
|
|
|
|
--user: #115e59;
|
|
|
|
|
--danger-bg: #fde8e8;
|
|
|
|
|
--danger-ink: #9b1c1c;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 23:36:23 +03:00
|
|
|
* {
|
2026-02-26 15:05:18 +03:00
|
|
|
box-sizing: border-box;
|
2026-02-04 23:36:23 +03:00
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body {
|
2026-02-26 15:05:18 +03:00
|
|
|
background:
|
|
|
|
|
radial-gradient(circle at 15% 15%, #f9d9a8 0%, transparent 35%),
|
|
|
|
|
radial-gradient(circle at 85% 20%, #b7e3d8 0%, transparent 40%),
|
|
|
|
|
linear-gradient(180deg, #f5f0e4 0%, #ede7d8 100%);
|
|
|
|
|
color: var(--ink);
|
|
|
|
|
font-family: "Trebuchet MS", "Segoe UI", sans-serif;
|
|
|
|
|
min-height: 100vh;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.app {
|
|
|
|
|
max-width: 1100px;
|
2026-02-04 23:36:23 +03:00
|
|
|
margin: 0 auto;
|
2026-02-26 15:05:18 +03:00
|
|
|
padding: 20px 14px 24px;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.shell {
|
|
|
|
|
border: 1px solid rgba(70, 62, 43, 0.15);
|
|
|
|
|
border-radius: 16px;
|
|
|
|
|
background: rgba(255, 253, 247, 0.92);
|
|
|
|
|
box-shadow: 0 18px 45px rgba(47, 41, 30, 0.12);
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
backdrop-filter: blur(6px);
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.shell-header {
|
|
|
|
|
padding: 14px 18px;
|
|
|
|
|
border-bottom: 1px solid var(--line);
|
|
|
|
|
background: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(244,239,228,0.85));
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.shell-header h1 {
|
|
|
|
|
font-size: 1.25rem;
|
|
|
|
|
letter-spacing: 0.02em;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.shell-header p {
|
|
|
|
|
margin-top: 4px;
|
|
|
|
|
color: var(--muted);
|
|
|
|
|
font-size: 0.92rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tabs-bar {
|
2026-02-04 23:36:23 +03:00
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
2026-02-26 15:05:18 +03:00
|
|
|
gap: 8px;
|
|
|
|
|
padding: 10px 12px;
|
|
|
|
|
border-bottom: 1px solid var(--line);
|
|
|
|
|
background: rgba(247, 243, 233, 0.9);
|
|
|
|
|
overflow-x: auto;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.tab-btn {
|
|
|
|
|
border: 1px solid var(--line);
|
|
|
|
|
background: #faf7ee;
|
|
|
|
|
color: var(--ink);
|
2026-02-04 23:36:23 +03:00
|
|
|
padding: 8px 12px;
|
2026-02-26 15:05:18 +03:00
|
|
|
border-radius: 999px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tab-btn:hover {
|
|
|
|
|
transform: translateY(-1px);
|
|
|
|
|
border-color: #c9bea6;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.tab-btn.active {
|
|
|
|
|
background: var(--accent);
|
|
|
|
|
border-color: var(--accent);
|
|
|
|
|
color: #fff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tab-btn.add-tab {
|
|
|
|
|
min-width: 38px;
|
|
|
|
|
padding-inline: 0;
|
|
|
|
|
text-align: center;
|
|
|
|
|
font-size: 1.1rem;
|
|
|
|
|
background: #fff;
|
|
|
|
|
color: var(--accent-2);
|
|
|
|
|
border-color: #e5c792;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.panel-host {
|
|
|
|
|
padding: 14px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-panel {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.panel-toolbar {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: auto 1fr auto;
|
|
|
|
|
gap: 10px;
|
|
|
|
|
align-items: center;
|
|
|
|
|
background: var(--paper);
|
|
|
|
|
border: 1px solid var(--line);
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.panel-toolbar label {
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
color: #4b5563;
|
|
|
|
|
font-size: 0.92rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.endpoint-input {
|
|
|
|
|
width: 100%;
|
|
|
|
|
border: 1px solid #d8cfbd;
|
|
|
|
|
border-radius: 10px;
|
|
|
|
|
padding: 10px 12px;
|
|
|
|
|
font-size: 0.94rem;
|
|
|
|
|
background: #fff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.endpoint-input:focus,
|
|
|
|
|
.message-input:focus {
|
|
|
|
|
outline: 2px solid rgba(15, 118, 110, 0.16);
|
|
|
|
|
border-color: var(--accent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.panel-toolbar button,
|
|
|
|
|
.send-btn {
|
2026-02-04 23:36:23 +03:00
|
|
|
border: none;
|
2026-02-26 15:05:18 +03:00
|
|
|
border-radius: 10px;
|
2026-02-04 23:36:23 +03:00
|
|
|
cursor: pointer;
|
2026-02-26 15:05:18 +03:00
|
|
|
font-weight: 700;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.set-endpoint-btn {
|
|
|
|
|
padding: 10px 12px;
|
|
|
|
|
background: #fff;
|
|
|
|
|
color: var(--accent);
|
|
|
|
|
border: 1px solid #b9d4cf;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.chat-card {
|
|
|
|
|
border: 1px solid var(--line);
|
|
|
|
|
border-radius: 14px;
|
2026-02-04 23:36:23 +03:00
|
|
|
overflow: hidden;
|
2026-02-26 15:05:18 +03:00
|
|
|
background: #fff;
|
|
|
|
|
min-height: 62vh;
|
2026-02-04 23:36:23 +03:00
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-header {
|
2026-02-26 15:05:18 +03:00
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
padding: 12px 14px;
|
|
|
|
|
border-bottom: 1px solid var(--line);
|
|
|
|
|
background: #fbf8ef;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-header-title {
|
|
|
|
|
font-weight: 800;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-header-endpoint {
|
|
|
|
|
color: var(--muted);
|
|
|
|
|
font-size: 0.85rem;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
text-align: right;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-messages {
|
|
|
|
|
flex: 1;
|
|
|
|
|
overflow-y: auto;
|
2026-02-26 15:05:18 +03:00
|
|
|
padding: 14px;
|
2026-02-04 23:36:23 +03:00
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
2026-02-26 15:05:18 +03:00
|
|
|
gap: 12px;
|
|
|
|
|
background:
|
|
|
|
|
linear-gradient(180deg, rgba(255,255,255,0.92), rgba(250,247,238,0.95)),
|
|
|
|
|
repeating-linear-gradient(
|
|
|
|
|
0deg,
|
|
|
|
|
rgba(218, 206, 181, 0.15),
|
|
|
|
|
rgba(218, 206, 181, 0.15) 1px,
|
|
|
|
|
transparent 1px,
|
|
|
|
|
transparent 28px
|
|
|
|
|
);
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.message {
|
2026-02-26 15:05:18 +03:00
|
|
|
max-width: 82%;
|
|
|
|
|
padding: 11px 13px;
|
|
|
|
|
border-radius: 14px;
|
|
|
|
|
line-height: 1.45;
|
|
|
|
|
animation: slideIn 0.2s ease;
|
|
|
|
|
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.message.user-message {
|
2026-02-04 23:36:23 +03:00
|
|
|
align-self: flex-end;
|
2026-02-26 15:05:18 +03:00
|
|
|
background: var(--user);
|
|
|
|
|
color: #fff;
|
|
|
|
|
border-bottom-right-radius: 5px;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.message.bot-message {
|
2026-02-04 23:36:23 +03:00
|
|
|
align-self: flex-start;
|
2026-02-26 15:05:18 +03:00
|
|
|
background: var(--bot);
|
|
|
|
|
color: #3c3f44;
|
|
|
|
|
border-bottom-left-radius: 5px;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.message.error-message {
|
2026-02-04 23:36:23 +03:00
|
|
|
align-self: flex-start;
|
2026-02-26 15:05:18 +03:00
|
|
|
background: var(--danger-bg);
|
|
|
|
|
color: var(--danger-ink);
|
|
|
|
|
border: 1px solid #f3bcbc;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.message.typing-indicator {
|
|
|
|
|
align-self: flex-start;
|
|
|
|
|
background: #eef2f7;
|
|
|
|
|
color: #475569;
|
|
|
|
|
font-style: italic;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.chat-input-row {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: 1fr auto;
|
|
|
|
|
gap: 10px;
|
|
|
|
|
padding: 12px;
|
|
|
|
|
border-top: 1px solid var(--line);
|
|
|
|
|
background: #fbf8ef;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.message-input {
|
|
|
|
|
border: 1px solid #d8cfbd;
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
padding: 11px 12px;
|
|
|
|
|
font-size: 0.95rem;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.send-btn {
|
|
|
|
|
background: var(--accent);
|
|
|
|
|
color: #fff;
|
|
|
|
|
padding: 0 16px;
|
|
|
|
|
min-width: 86px;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.send-btn:disabled,
|
|
|
|
|
.set-endpoint-btn:disabled {
|
|
|
|
|
opacity: 0.55;
|
2026-02-04 23:36:23 +03:00
|
|
|
cursor: not-allowed;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.footer-note {
|
|
|
|
|
padding: 8px 14px 14px;
|
|
|
|
|
color: var(--muted);
|
|
|
|
|
font-size: 0.85rem;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
@keyframes slideIn {
|
|
|
|
|
from {
|
|
|
|
|
opacity: 0;
|
|
|
|
|
transform: translateY(6px);
|
|
|
|
|
}
|
|
|
|
|
to {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
transform: translateY(0);
|
|
|
|
|
}
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
@media (max-width: 720px) {
|
|
|
|
|
.panel-toolbar {
|
|
|
|
|
grid-template-columns: 1fr;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.chat-header {
|
2026-02-04 23:36:23 +03:00
|
|
|
flex-direction: column;
|
2026-02-26 15:05:18 +03:00
|
|
|
align-items: flex-start;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
.chat-header-endpoint {
|
|
|
|
|
text-align: left;
|
|
|
|
|
white-space: normal;
|
|
|
|
|
word-break: break-all;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.message {
|
2026-02-26 15:05:18 +03:00
|
|
|
max-width: 92%;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
2026-02-26 15:05:18 +03:00
|
|
|
<div class="app">
|
|
|
|
|
<div class="shell">
|
|
|
|
|
<div class="shell-header">
|
|
|
|
|
<h1>RAG Demo Control Room</h1>
|
|
|
|
|
<p>Multiple chat windows with independent API endpoints.</p>
|
2026-02-04 23:36:23 +03:00
|
|
|
</div>
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
<div class="tabs-bar" id="tabsBar"></div>
|
|
|
|
|
<div class="panel-host" id="panelHost"></div>
|
|
|
|
|
<div class="footer-note">Phase 16 scalable demo UI: reusable chat panel + tabbed windows.</div>
|
|
|
|
|
</div>
|
2026-02-04 23:36:23 +03:00
|
|
|
</div>
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
<template id="chatPanelTemplate">
|
|
|
|
|
<div class="chat-panel">
|
|
|
|
|
<div class="panel-toolbar">
|
|
|
|
|
<label>API Endpoint</label>
|
|
|
|
|
<input class="endpoint-input" type="text" placeholder="Enter API endpoint URL" />
|
|
|
|
|
<button class="set-endpoint-btn" type="button">Set Endpoint</button>
|
|
|
|
|
</div>
|
2026-02-04 23:36:23 +03:00
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
<div class="chat-card">
|
|
|
|
|
<div class="chat-header">
|
|
|
|
|
<div class="chat-header-title">Chat with RAG Agent</div>
|
|
|
|
|
<div class="chat-header-endpoint">Endpoint: not set</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="chat-messages"></div>
|
|
|
|
|
<div class="chat-input-row">
|
|
|
|
|
<input class="message-input" type="text" placeholder="Type your message here..." />
|
|
|
|
|
<button class="send-btn" type="button">Send</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2026-02-04 23:36:23 +03:00
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
<script>
|
|
|
|
|
const DEFAULT_TAB_ENDPOINTS = [
|
|
|
|
|
"https://rag.langchain.overwatch.su/api/test-query",
|
|
|
|
|
"https://rag.llamaindex.overwatch.su/api/test-query",
|
|
|
|
|
"https://rag.haystack.overwatch.su/api/test-query",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
class ChatPanel {
|
|
|
|
|
constructor(rootElement, initialEndpoint = "") {
|
|
|
|
|
this.root = rootElement;
|
|
|
|
|
this.apiEndpoint = initialEndpoint;
|
|
|
|
|
|
|
|
|
|
this.endpointInput = this.root.querySelector(".endpoint-input");
|
|
|
|
|
this.setEndpointButton = this.root.querySelector(".set-endpoint-btn");
|
|
|
|
|
this.headerEndpoint = this.root.querySelector(".chat-header-endpoint");
|
|
|
|
|
this.messagesEl = this.root.querySelector(".chat-messages");
|
|
|
|
|
this.messageInput = this.root.querySelector(".message-input");
|
|
|
|
|
this.sendButton = this.root.querySelector(".send-btn");
|
|
|
|
|
|
|
|
|
|
this.endpointInput.value = initialEndpoint;
|
|
|
|
|
this._renderEndpointLabel();
|
|
|
|
|
this._bindEvents();
|
|
|
|
|
this.addMessage(
|
|
|
|
|
initialEndpoint
|
|
|
|
|
? `Ready. Endpoint preset to: ${initialEndpoint}`
|
|
|
|
|
: "Hello. Set an API endpoint and start chatting.",
|
|
|
|
|
"bot-message",
|
|
|
|
|
);
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
_bindEvents() {
|
|
|
|
|
this.setEndpointButton.addEventListener("click", () => this.setApiEndpoint());
|
|
|
|
|
this.sendButton.addEventListener("click", () => this.sendMessage());
|
|
|
|
|
this.messageInput.addEventListener("keydown", (event) => {
|
|
|
|
|
if (event.key === "Enter") {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
this.sendMessage();
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
focusInput() {
|
|
|
|
|
this.messageInput.focus();
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
_renderEndpointLabel() {
|
|
|
|
|
this.headerEndpoint.textContent = this.apiEndpoint
|
|
|
|
|
? `Endpoint: ${this.apiEndpoint}`
|
|
|
|
|
: "Endpoint: not set";
|
|
|
|
|
}
|
2026-02-04 23:36:23 +03:00
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
setApiEndpoint() {
|
|
|
|
|
const candidate = this.endpointInput.value.trim();
|
|
|
|
|
if (!candidate) {
|
|
|
|
|
alert("Please enter a valid API endpoint URL");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.apiEndpoint = candidate;
|
|
|
|
|
this._renderEndpointLabel();
|
|
|
|
|
this.addMessage(`API endpoint set to: ${candidate}`, "bot-message");
|
|
|
|
|
}
|
2026-02-04 23:36:23 +03:00
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
addMessage(text, className, extraClass = "") {
|
|
|
|
|
const messageDiv = document.createElement("div");
|
|
|
|
|
messageDiv.className = `message ${className} ${extraClass}`.trim();
|
|
|
|
|
messageDiv.innerHTML = String(text).replace(/\n/g, "<br>");
|
|
|
|
|
this.messagesEl.appendChild(messageDiv);
|
|
|
|
|
this.messagesEl.scrollTop = this.messagesEl.scrollHeight;
|
|
|
|
|
return messageDiv;
|
|
|
|
|
}
|
2026-02-04 23:36:23 +03:00
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
removeMessage(node) {
|
|
|
|
|
if (node && node.parentNode) {
|
|
|
|
|
node.parentNode.removeChild(node);
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
2026-02-26 15:05:18 +03:00
|
|
|
}
|
2026-02-04 23:36:23 +03:00
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
async sendMessage() {
|
|
|
|
|
const message = this.messageInput.value.trim();
|
|
|
|
|
if (!message) return;
|
|
|
|
|
if (!this.apiEndpoint) {
|
|
|
|
|
alert("Please set the API endpoint first");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-04 23:36:23 +03:00
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
this.sendButton.disabled = true;
|
|
|
|
|
this.messageInput.disabled = true;
|
|
|
|
|
|
|
|
|
|
let typingIndicator = null;
|
|
|
|
|
try {
|
|
|
|
|
this.addMessage(message, "user-message");
|
|
|
|
|
this.messageInput.value = "";
|
|
|
|
|
|
|
|
|
|
typingIndicator = this.addMessage("Thinking...", "typing-indicator", "typing");
|
|
|
|
|
|
|
|
|
|
const response = await fetch(this.apiEndpoint, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
body: JSON.stringify({ query: message }),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.removeMessage(typingIndicator);
|
|
|
|
|
typingIndicator = null;
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(`API request failed with status ${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
if (data.success) {
|
|
|
|
|
this.addMessage(data.response, "bot-message");
|
|
|
|
|
} else {
|
|
|
|
|
this.addMessage(
|
|
|
|
|
`Error: ${data.error || "Unknown error occurred"}`,
|
|
|
|
|
"error-message",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (typingIndicator) this.removeMessage(typingIndicator);
|
|
|
|
|
this.addMessage(
|
|
|
|
|
`Connection error: ${error.message}. Please check the API endpoint and try again. Reload page if needed to reinitialize endpoint state.`,
|
2026-02-04 23:36:23 +03:00
|
|
|
"error-message",
|
|
|
|
|
);
|
2026-02-26 15:05:18 +03:00
|
|
|
} finally {
|
|
|
|
|
this.sendButton.disabled = false;
|
|
|
|
|
this.messageInput.disabled = false;
|
|
|
|
|
this.messageInput.focus();
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
class MultiChatApp {
|
|
|
|
|
constructor() {
|
|
|
|
|
this.tabsBar = document.getElementById("tabsBar");
|
|
|
|
|
this.panelHost = document.getElementById("panelHost");
|
|
|
|
|
this.panelTemplate = document.getElementById("chatPanelTemplate");
|
|
|
|
|
this.tabs = [];
|
|
|
|
|
this.activeTabId = null;
|
|
|
|
|
this.nextTabNumber = 1;
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
init() {
|
|
|
|
|
DEFAULT_TAB_ENDPOINTS.forEach((endpoint) => this.createTab(endpoint));
|
|
|
|
|
if (this.tabs.length > 0) {
|
|
|
|
|
this.selectTab(this.tabs[0].id);
|
|
|
|
|
}
|
|
|
|
|
this.renderTabs();
|
|
|
|
|
}
|
2026-02-04 23:36:23 +03:00
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
createTab(initialEndpoint = "") {
|
|
|
|
|
const tab = {
|
|
|
|
|
id: `tab-${crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`}`,
|
|
|
|
|
title: String(this.nextTabNumber++),
|
|
|
|
|
endpoint: initialEndpoint,
|
|
|
|
|
panel: null,
|
|
|
|
|
panelNode: null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const fragment = this.panelTemplate.content.cloneNode(true);
|
|
|
|
|
const panelNode = fragment.firstElementChild;
|
|
|
|
|
const panel = new ChatPanel(panelNode, initialEndpoint);
|
|
|
|
|
tab.panel = panel;
|
|
|
|
|
tab.panelNode = panelNode;
|
|
|
|
|
this.tabs.push(tab);
|
|
|
|
|
this.renderTabs();
|
|
|
|
|
return tab;
|
|
|
|
|
}
|
2026-02-04 23:36:23 +03:00
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
selectTab(tabId) {
|
|
|
|
|
this.activeTabId = tabId;
|
|
|
|
|
const tab = this.tabs.find((item) => item.id === tabId);
|
|
|
|
|
if (!tab) return;
|
2026-02-04 23:36:23 +03:00
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
this.panelHost.innerHTML = "";
|
|
|
|
|
this.panelHost.appendChild(tab.panelNode);
|
|
|
|
|
tab.panel._renderEndpointLabel();
|
|
|
|
|
tab.panel.focusInput();
|
|
|
|
|
this.renderTabs();
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
renderTabs() {
|
|
|
|
|
this.tabsBar.innerHTML = "";
|
|
|
|
|
|
|
|
|
|
this.tabs.forEach((tab) => {
|
|
|
|
|
const btn = document.createElement("button");
|
|
|
|
|
btn.type = "button";
|
|
|
|
|
btn.className = `tab-btn ${tab.id === this.activeTabId ? "active" : ""}`.trim();
|
|
|
|
|
btn.textContent = tab.title;
|
|
|
|
|
btn.title = tab.endpoint || `Tab ${tab.title}`;
|
|
|
|
|
btn.addEventListener("click", () => this.selectTab(tab.id));
|
|
|
|
|
this.tabsBar.appendChild(btn);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const addBtn = document.createElement("button");
|
|
|
|
|
addBtn.type = "button";
|
|
|
|
|
addBtn.className = "tab-btn add-tab";
|
|
|
|
|
addBtn.textContent = "+";
|
|
|
|
|
addBtn.title = "Add new tab";
|
|
|
|
|
addBtn.addEventListener("click", () => {
|
|
|
|
|
const tab = this.createTab("");
|
|
|
|
|
this.selectTab(tab.id);
|
|
|
|
|
});
|
|
|
|
|
this.tabsBar.appendChild(addBtn);
|
2026-02-04 23:36:23 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:05:18 +03:00
|
|
|
window.addEventListener("DOMContentLoaded", () => {
|
|
|
|
|
const app = new MultiChatApp();
|
|
|
|
|
app.init();
|
|
|
|
|
});
|
2026-02-04 23:36:23 +03:00
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|