Download index.html from KirkAis/KirkAI: direct link, hf CLI and curl.
- Browser
- Download file 118 kB
-
https://huggingface.co/spaces/KirkAis/KirkAI/resolve/main/index.html
- Command line
-
hf download hf://spaces/KirkAis/KirkAI/index.html
-
curl -L -o index.html https://huggingface.co/spaces/KirkAis/KirkAI/resolve/main/index.html
118 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>KirkAI β Free AI for Everyone</title>
<meta name="description" content="KirkAI is a completely free AI chat β no login required. Access every model instantly."/>
<link rel="icon" href="https://iili.io/CxhPxMG.jpg" type="image/jpeg"/>
<!-- Fonts -->
<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=Figtree:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,400&family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet"/>
<!-- Highlight.js -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<!-- JSZip -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<style>
/* ββ Reset & Base ββ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0a0a0b;
--bg2: #111114;
--bg3: #18181c;
--glass: rgba(255,255,255,0.04);
--glass-border: rgba(255,255,255,0.08);
--glass-hover: rgba(255,255,255,0.07);
--accent: #DC143C;
--accent-dim: rgba(220,20,60,0.15);
--accent-glow: rgba(220,20,60,0.3);
--text: #f0f0f2;
--text-sub: #8b8b9a;
--text-dim: #5a5a6a;
--radius: 12px;
--sidebar-w: 280px;
--topbar-h: 60px;
--composer-h: auto;
--font: 'Figtree', system-ui, sans-serif;
--mono: 'JetBrains Mono', 'Fira Code', monospace;
--transition: 0.18s ease;
}
html, body { height: 100%; overflow: hidden; }
body {
font-family: var(--font);
background: var(--bg);
color: var(--text);
line-height: 1.6;
-webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
textarea { font-family: var(--font); resize: none; }
input, textarea, select { outline: none; }
::selection { background: var(--accent-dim); }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
/* ββ Canvas BG ββ */
#bgCanvas {
position: fixed; inset: 0; z-index: 0;
pointer-events: none; opacity: 0.35;
}
/* ββ App Shell ββ */
#app {
position: relative; z-index: 1;
display: flex; height: 100vh; overflow: hidden;
}
/* ββ Sidebar ββ */
#sidebar {
width: var(--sidebar-w);
background: rgba(10,10,11,0.95);
border-right: 1px solid var(--glass-border);
display: flex; flex-direction: column;
transition: transform var(--transition);
z-index: 100; flex-shrink: 0;
backdrop-filter: blur(20px);
}
#sidebar.collapsed {
transform: translateX(calc(-1 * var(--sidebar-w)));
position: absolute; top: 0; left: 0; bottom: 0;
}
.sidebar-head {
padding: 16px;
border-bottom: 1px solid var(--glass-border);
display: flex; align-items: center; gap: 10px;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; flex: 1; }
.sidebar-logo img { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; }
.sidebar-logo-text { font-weight: 700; font-size: 16px; letter-spacing: -0.3px; }
.sidebar-logo-text span { color: var(--accent); }
#newChatBtn {
display: flex; align-items: center; gap: 8px;
margin: 12px; padding: 10px 14px;
background: var(--accent-dim); border: 1px solid var(--accent-glow);
border-radius: 10px; color: var(--accent);
font-weight: 600; font-size: 14px;
transition: background var(--transition), transform 0.1s;
}
#newChatBtn:hover { background: rgba(220,20,60,0.22); transform: translateY(-1px); }
#newChatBtn:active { transform: translateY(0); }
.chat-history-label {
padding: 6px 16px; font-size: 11px; font-weight: 600;
color: var(--text-dim); letter-spacing: 0.08em; text-transform: uppercase;
}
#historyList {
flex: 1; overflow-y: auto; padding: 4px 8px;
}
.hist-item {
display: flex; align-items: center; gap: 8px;
padding: 9px 10px; border-radius: 9px;
cursor: pointer; transition: background var(--transition);
font-size: 13.5px; color: var(--text-sub);
white-space: nowrap; overflow: hidden;
}
.hist-item:hover { background: var(--glass-hover); color: var(--text); }
.hist-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.hist-item-icon { font-size: 14px; flex-shrink: 0; opacity: 0.6; }
.hist-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.hist-item-del {
opacity: 0; font-size: 13px; padding: 2px 4px; border-radius: 5px;
color: var(--text-dim); transition: opacity var(--transition);
}
.hist-item:hover .hist-item-del { opacity: 1; }
.hist-item-del:hover { color: var(--accent); background: var(--accent-dim); }
.sidebar-footer {
padding: 12px 16px;
border-top: 1px solid var(--glass-border);
display: flex; flex-direction: column; gap: 4px;
}
.sidebar-link {
display: flex; align-items: center; gap: 9px;
padding: 9px 10px; border-radius: 9px;
font-size: 13.5px; color: var(--text-sub);
cursor: pointer; transition: background var(--transition), color var(--transition);
}
.sidebar-link:hover { background: var(--glass-hover); color: var(--text); }
.free-badge {
display: inline-flex; align-items: center; gap: 5px;
padding: 5px 10px; border-radius: 20px;
background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.25);
color: #22c55e; font-size: 11.5px; font-weight: 600;
margin: 8px 16px 4px;
}
/* ββ Main ββ */
#main {
flex: 1; display: flex; flex-direction: column;
min-width: 0; overflow: hidden;
transition: margin-left var(--transition);
}
/* ββ Topbar ββ */
#topbar {
height: var(--topbar-h);
display: flex; align-items: center; gap: 12px;
padding: 0 16px;
border-bottom: 1px solid var(--glass-border);
background: rgba(10,10,11,0.8);
backdrop-filter: blur(16px);
flex-shrink: 0; z-index: 10;
}
#sidebarToggle {
width: 36px; height: 36px; border-radius: 9px;
display: flex; align-items: center; justify-content: center;
color: var(--text-sub); font-size: 18px;
transition: background var(--transition), color var(--transition);
flex-shrink: 0;
}
#sidebarToggle:hover { background: var(--glass-hover); color: var(--text); }
#topbarTitle {
font-size: 15px; font-weight: 700; letter-spacing: -0.3px;
flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
color: var(--text-sub);
}
#topbarTitle span { color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
#friendliesToggleBtn {
display: flex; align-items: center; gap: 7px;
padding: 7px 14px; border-radius: 10px;
font-size: 13px; font-weight: 600;
background: var(--glass); border: 1px solid var(--glass-border);
color: var(--text-sub);
transition: all var(--transition);
}
#friendliesToggleBtn:hover { background: var(--glass-hover); color: var(--text); }
#friendliesToggleBtn.active {
background: rgba(123,94,167,0.2); border-color: rgba(123,94,167,0.4);
color: #a78bcc;
}
.icon-btn {
width: 36px; height: 36px; border-radius: 9px;
display: flex; align-items: center; justify-content: center;
color: var(--text-sub); font-size: 17px;
transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--glass-hover); color: var(--text); }
/* ββ Messages Area ββ */
#messages {
flex: 1; overflow-y: auto; padding: 24px 0;
display: flex; flex-direction: column; gap: 4px;
}
.msg-row {
display: flex; padding: 4px 24px; gap: 12px;
animation: fadeUp 0.22s ease both;
}
@keyframes fadeUp {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: translateY(0); }
}
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }
/* Avatar */
.msg-avatar {
width: 32px; height: 32px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
font-size: 13px; font-weight: 700; flex-shrink: 0;
margin-top: 4px;
}
.msg-avatar.ai {
background: var(--accent-dim); border: 1px solid var(--accent-glow);
color: var(--accent);
}
.msg-avatar.user-av {
background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
color: var(--text-sub);
}
.msg-content-wrap { max-width: 780px; display: flex; flex-direction: column; gap: 4px; }
.msg-row.user .msg-content-wrap { align-items: flex-end; }
.msg-bubble {
padding: 12px 16px;
border-radius: 16px;
font-size: 15px; line-height: 1.65;
max-width: 100%;
}
.msg-row.user .msg-bubble {
background: rgba(220,20,60,0.15);
border: 1px solid rgba(220,20,60,0.25);
border-bottom-right-radius: 4px;
color: var(--text);
}
.msg-row.assistant .msg-bubble {
background: var(--glass);
border: 1px solid var(--glass-border);
border-bottom-left-radius: 4px;
color: var(--text);
}
/* Attachment previews in user bubble */
.attach-preview-row {
display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px;
}
.attach-thumb {
width: 80px; height: 80px; border-radius: 8px;
object-fit: cover; border: 1px solid var(--glass-border);
}
.attach-file-chip {
display: flex; align-items: center; gap: 6px;
padding: 6px 10px; border-radius: 8px;
background: rgba(255,255,255,0.06); border: 1px solid var(--glass-border);
font-size: 12.5px; color: var(--text-sub);
}
/* Markdown rendered content */
.md-body { min-width: 0; }
.md-body p { margin-bottom: 0.75em; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
margin: 1em 0 0.4em; font-weight: 700; line-height: 1.3;
}
.md-body h1 { font-size: 1.4em; }
.md-body h2 { font-size: 1.2em; }
.md-body h3 { font-size: 1.05em; }
.md-body ul, .md-body ol { padding-left: 1.4em; margin-bottom: 0.75em; }
.md-body li { margin-bottom: 0.25em; }
.md-body blockquote {
border-left: 3px solid var(--accent); padding: 8px 14px;
margin: 0.75em 0; background: var(--accent-dim); border-radius: 0 8px 8px 0;
color: var(--text-sub); font-style: italic;
}
.md-body code:not(pre code) {
background: rgba(255,255,255,0.08); padding: 2px 6px;
border-radius: 5px; font-family: var(--mono); font-size: 0.88em;
color: #e2b96b;
}
.md-body pre {
background: #0d0d10 !important; border-radius: 10px;
overflow: hidden; margin: 0.75em 0;
border: 1px solid rgba(255,255,255,0.06);
}
.md-body pre code { font-family: var(--mono); font-size: 13.5px; line-height: 1.6; }
.code-block-wrap { position: relative; }
.code-header {
display: flex; align-items: center; justify-content: space-between;
padding: 8px 14px; background: rgba(255,255,255,0.04);
border-bottom: 1px solid rgba(255,255,255,0.06);
}
.code-lang { font-size: 12px; color: var(--text-dim); font-family: var(--mono); }
.copy-btn {
font-size: 12px; color: var(--text-dim); padding: 3px 8px;
border-radius: 5px; background: rgba(255,255,255,0.05);
border: 1px solid rgba(255,255,255,0.08);
transition: all var(--transition);
}
.copy-btn:hover { background: rgba(255,255,255,0.1); color: var(--text); }
.copy-btn.copied { color: #22c55e; border-color: rgba(34,197,94,0.3); }
.md-body table {
width: 100%; border-collapse: collapse; margin: 0.75em 0; font-size: 14px;
}
.md-body th {
background: rgba(255,255,255,0.06);
padding: 8px 12px; text-align: left; font-weight: 600;
border-bottom: 1px solid var(--glass-border);
}
.md-body td {
padding: 7px 12px; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.md-body tr:hover td { background: rgba(255,255,255,0.02); }
.md-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md-body hr { border: none; border-top: 1px solid var(--glass-border); margin: 1em 0; }
/* Thinking block */
.thinking-block {
background: rgba(255,255,255,0.025);
border: 1px solid rgba(255,255,255,0.07);
border-radius: 10px; margin-bottom: 12px; overflow: hidden;
}
.thinking-toggle {
display: flex; align-items: center; gap: 8px;
padding: 10px 14px; cursor: pointer;
font-size: 13px; color: var(--text-dim); font-weight: 500;
user-select: none; list-style: none;
transition: color var(--transition);
}
.thinking-toggle::-webkit-details-marker,
details.thinking-block summary::-webkit-details-marker { display: none; }
details.thinking-block summary { list-style: none; }
.thinking-toggle:hover { color: var(--text-sub); }
.th-arrow { transition: transform 0.2s ease; margin-left: auto; display: inline-block; font-size: 11px; }
details[open] > .thinking-toggle .th-arrow { transform: rotate(180deg); }
.thinking-content { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,0.05); }
.thinking-content pre {
white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px;
color: var(--text-dim); line-height: 1.6;
}
/* Msg actions */
.msg-actions {
display: flex; gap: 4px; opacity: 0; transition: opacity var(--transition);
}
.msg-row:hover .msg-actions { opacity: 1; }
.msg-action-btn {
font-size: 12px; color: var(--text-dim); padding: 3px 7px;
border-radius: 5px; background: var(--glass); border: 1px solid var(--glass-border);
transition: all var(--transition);
}
.msg-action-btn:hover { color: var(--text); background: var(--glass-hover); }
.msg-action-btn.copied { color: #22c55e; }
/* Loading / streaming */
.msg-loading { display: flex; gap: 5px; align-items: center; padding: 4px 0; }
.msg-loading span {
width: 6px; height: 6px; border-radius: 50%;
background: var(--accent); display: inline-block;
animation: bounce 1.2s infinite ease-in-out;
}
.msg-loading span:nth-child(2) { animation-delay: 0.2s; }
.msg-loading span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
40% { transform: translateY(-6px); opacity: 1; }
}
/* ββ Empty State ββ */
#emptyState {
display: flex; flex-direction: column; align-items: center; justify-content: center;
flex: 1; padding: 32px; text-align: center;
gap: 20px;
}
#emptyState img {
width: 72px; height: 72px; border-radius: 18px; object-fit: cover;
box-shadow: 0 0 40px var(--accent-glow);
}
#emptyState h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
#emptyState h1 span { color: var(--accent); }
#emptyState p { font-size: 15px; color: var(--text-sub); max-width: 420px; }
.starter-chips {
display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 540px;
}
.starter-chip {
padding: 8px 16px; border-radius: 20px;
background: var(--glass); border: 1px solid var(--glass-border);
font-size: 13.5px; color: var(--text-sub);
cursor: pointer; transition: all var(--transition);
}
.starter-chip:hover {
background: var(--glass-hover); color: var(--text);
border-color: rgba(255,255,255,0.14);
}
/* ββ Composer Area ββ */
#composerArea {
padding: 12px 16px 16px;
border-top: 1px solid var(--glass-border);
background: rgba(10,10,11,0.9);
backdrop-filter: blur(16px);
flex-shrink: 0;
}
#attachStrip {
display: flex; flex-wrap: wrap; gap: 8px;
margin-bottom: 8px; empty-cells: show;
}
#attachStrip:empty { display: none; }
.attach-chip {
display: flex; align-items: center; gap: 6px;
padding: 5px 10px; border-radius: 8px;
background: var(--glass); border: 1px solid var(--glass-border);
font-size: 12.5px; color: var(--text-sub); max-width: 180px;
}
.attach-chip-img {
width: 28px; height: 28px; border-radius: 5px;
object-fit: cover; flex-shrink: 0;
}
.attach-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip-del {
font-size: 14px; color: var(--text-dim); flex-shrink: 0;
cursor: pointer; line-height: 1;
}
.attach-chip-del:hover { color: var(--accent); }
#composer {
display: flex; align-items: flex-end; gap: 8px;
background: var(--glass); border: 1px solid var(--glass-border);
border-radius: 14px; padding: 10px 12px;
transition: border-color var(--transition);
}
#composer:focus-within { border-color: rgba(220,20,60,0.35); }
#promptInput {
flex: 1; background: none; border: none; color: var(--text);
font-size: 15px; line-height: 1.55; max-height: 200px;
padding: 2px 0; resize: none;
}
#promptInput::placeholder { color: var(--text-dim); }
.composer-actions { display: flex; align-items: center; gap: 5px; }
.composer-btn {
width: 34px; height: 34px; border-radius: 9px;
display: flex; align-items: center; justify-content: center;
color: var(--text-dim); font-size: 16px;
transition: all var(--transition);
}
.composer-btn:hover { background: var(--glass-hover); color: var(--text); }
#sendBtn {
width: 36px; height: 36px; border-radius: 10px;
display: flex; align-items: center; justify-content: center;
background: var(--accent); color: #fff; font-size: 16px;
transition: all var(--transition); flex-shrink: 0;
}
#sendBtn:hover { background: #ff1a42; transform: scale(1.05); }
#sendBtn:disabled { background: var(--glass); color: var(--text-dim); transform: none; cursor: not-allowed; }
#sendBtn.stop { background: rgba(255,100,100,0.2); color: #ff6464; border: 1px solid rgba(255,100,100,0.3); }
.composer-footer {
display: flex; align-items: center; gap: 8px;
margin-top: 8px; flex-wrap: wrap;
}
.picker-btn {
display: flex; align-items: center; gap: 6px;
padding: 5px 11px; border-radius: 8px;
background: var(--glass); border: 1px solid var(--glass-border);
font-size: 12.5px; color: var(--text-sub);
cursor: pointer; transition: all var(--transition); white-space: nowrap;
}
.picker-btn:hover { background: var(--glass-hover); color: var(--text); }
.picker-btn .dot {
width: 7px; height: 7px; border-radius: 50%;
background: var(--accent); flex-shrink: 0;
}
.composer-spacer { flex: 1; }
.friendlies-mode-indicator {
display: flex; align-items: center; gap: 8px;
padding: 5px 11px; border-radius: 8px;
background: rgba(123,94,167,0.15); border: 1px solid rgba(123,94,167,0.3);
font-size: 12.5px; color: #a78bcc; font-weight: 600;
}
/* ββ Picker Popups ββ */
.picker-popup {
position: fixed; z-index: 200;
background: #16161a; border: 1px solid rgba(255,255,255,0.1);
border-radius: 14px; padding: 8px;
box-shadow: 0 20px 60px rgba(0,0,0,0.6);
min-width: 280px; max-width: 340px;
backdrop-filter: blur(20px);
display: none;
}
.picker-popup.open { display: block; animation: popIn 0.15s ease; }
@keyframes popIn {
from { opacity: 0; transform: scale(0.96) translateY(6px); }
to { opacity: 1; transform: scale(1) translateY(0); }
}
.picker-section-label {
font-size: 10.5px; font-weight: 700; letter-spacing: 0.09em;
color: var(--text-dim); padding: 6px 10px 3px; text-transform: uppercase;
}
.picker-family {
border-radius: 10px; overflow: hidden; margin-bottom: 4px;
}
.picker-family-head {
display: flex; align-items: center; justify-content: space-between;
padding: 9px 12px; cursor: pointer;
transition: background var(--transition); border-radius: 9px;
}
.picker-family-head:hover { background: var(--glass-hover); }
.picker-family-name { font-weight: 700; font-size: 14px; }
.picker-family-tag {
font-size: 10px; font-weight: 700; padding: 2px 7px;
border-radius: 5px; background: var(--accent-dim); color: var(--accent);
letter-spacing: 0.05em;
}
.picker-family-desc { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.picker-family-versions { display: none; padding: 0 4px 4px; }
.picker-family.open .picker-family-versions { display: block; }
.picker-version {
display: flex; align-items: center; justify-content: space-between;
padding: 8px 10px; border-radius: 8px; cursor: pointer;
transition: background var(--transition);
}
.picker-version:hover { background: var(--glass-hover); }
.picker-version.selected { background: var(--accent-dim); }
.picker-version-label { font-size: 13.5px; font-weight: 500; }
.picker-version-ver { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }
.picker-scroll { max-height: 340px; overflow-y: auto; }
.mode-picker-item {
padding: 9px 12px; border-radius: 9px; cursor: pointer;
transition: background var(--transition);
}
.mode-picker-item:hover { background: var(--glass-hover); }
.mode-picker-item.selected { background: var(--accent-dim); }
.mode-picker-item-name { font-weight: 600; font-size: 14px; }
.mode-picker-item-meta { font-size: 12px; color: var(--text-dim); }
/* ββ Modals ββ */
.modal-backdrop {
position: fixed; inset: 0; z-index: 300;
background: rgba(0,0,0,0.7); backdrop-filter: blur(8px);
display: flex; align-items: center; justify-content: center;
padding: 20px;
animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
background: #13131a; border: 1px solid rgba(255,255,255,0.1);
border-radius: 18px; padding: 28px;
max-width: 640px; width: 100%; max-height: 90vh;
overflow-y: auto;
box-shadow: 0 30px 80px rgba(0,0,0,0.7);
animation: modalUp 0.2s ease;
}
@keyframes modalUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.modal-head h2 { flex: 1; font-size: 20px; font-weight: 800; letter-spacing: -0.3px; }
.modal-close {
width: 32px; height: 32px; border-radius: 8px;
display: flex; align-items: center; justify-content: center;
color: var(--text-dim); font-size: 18px;
transition: all var(--transition);
}
.modal-close:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.form-group { margin-bottom: 16px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text-sub); margin-bottom: 6px; display: block; }
.form-input {
width: 100%; padding: 10px 13px;
background: var(--glass); border: 1px solid var(--glass-border);
border-radius: 9px; color: var(--text); font-size: 14px;
transition: border-color var(--transition);
}
.form-input:focus { border-color: rgba(220,20,60,0.4); }
.form-textarea { min-height: 100px; }
.form-color-row { display: flex; align-items: center; gap: 12px; }
.color-preview { width: 36px; height: 36px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.15); }
.btn { padding: 10px 18px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; transition: all var(--transition); }
.btn-primary { background: var(--accent); color: #fff; border: none; }
.btn-primary:hover { background: #ff1a42; transform: translateY(-1px); }
.btn-secondary {
background: var(--glass); border: 1px solid var(--glass-border); color: var(--text-sub);
}
.btn-secondary:hover { background: var(--glass-hover); color: var(--text); }
.btn-danger { background: rgba(220,20,60,0.15); border: 1px solid rgba(220,20,60,0.3); color: var(--accent); }
.btn-danger:hover { background: rgba(220,20,60,0.25); }
.btn-purple { background: rgba(123,94,167,0.2); border: 1px solid rgba(123,94,167,0.4); color: #a78bcc; }
.btn-purple:hover { background: rgba(123,94,167,0.3); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }
/* Agent Cards in Manage Modal */
.agent-card {
background: var(--glass); border: 1px solid var(--glass-border);
border-radius: 12px; padding: 14px 16px; margin-bottom: 10px;
display: flex; align-items: center; gap: 12px;
}
.agent-card-avatar {
width: 40px; height: 40px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
font-size: 16px; font-weight: 700; flex-shrink: 0;
color: #fff;
}
.agent-card-info { flex: 1; min-width: 0; }
.agent-card-name { font-weight: 700; font-size: 15px; }
.agent-card-role { font-size: 12.5px; color: var(--text-dim); }
.agent-card-actions { display: flex; gap: 6px; }
.drag-handle { color: var(--text-dim); cursor: grab; font-size: 16px; flex-shrink: 0; }
.drag-handle:active { cursor: grabbing; }
/* ββ Friendlies Results ββ */
#friendliesResults {
padding: 24px;
animation: fadeUp 0.3s ease;
}
.friendlies-results-header {
text-align: center; margin-bottom: 24px;
}
.friendlies-results-header h2 {
font-size: 22px; font-weight: 800; letter-spacing: -0.4px; margin-bottom: 6px;
}
.friendlies-results-header p { font-size: 14px; color: var(--text-sub); }
.friendlies-cards-grid {
display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
}
@media (max-width: 900px) { .friendlies-cards-grid { grid-template-columns: 1fr; } }
@media (max-width: 1100px) { .friendlies-cards-grid { grid-template-columns: repeat(2, 1fr); } }
.friendlies-result-card {
background: var(--glass); border: 1px solid var(--glass-border);
border-radius: 16px; overflow: hidden;
transition: transform var(--transition), box-shadow var(--transition);
}
.friendlies-result-card:hover { transform: translateY(-2px); box-shadow: 0 12px 40px rgba(0,0,0,0.4); }
.fr-card-head {
display: flex; align-items: center; gap: 12px;
padding: 16px; border-bottom: 1px solid var(--glass-border);
}
.fr-card-avatar {
width: 42px; height: 42px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
font-size: 17px; font-weight: 800; flex-shrink: 0; color: #fff;
}
.fr-card-name { font-size: 16px; font-weight: 800; }
.fr-card-role { font-size: 12px; color: var(--text-dim); }
.fr-card-body { padding: 16px; }
.fr-card-output { font-size: 14px; line-height: 1.65; color: var(--text); }
.fr-card-thought {
margin-top: 14px; border-top: 1px solid var(--glass-border); padding-top: 12px;
}
.fr-card-thought summary {
font-size: 12.5px; color: var(--text-dim); cursor: pointer;
font-weight: 600; user-select: none; list-style: none;
display: flex; align-items: center; gap: 6px;
}
.fr-card-thought summary::-webkit-details-marker { display: none; }
.fr-card-thought summary::before {
content: 'βΊ'; font-size: 16px; transition: transform 0.15s;
}
.fr-card-thought[open] summary::before { transform: rotate(90deg); }
.fr-cycle-entry { margin-top: 12px; }
.fr-cycle-label {
font-size: 11px; font-weight: 700; letter-spacing: 0.07em;
color: var(--text-dim); text-transform: uppercase; margin-bottom: 6px;
}
.fr-cycle-text {
font-size: 13px; line-height: 1.6; color: var(--text-sub);
background: rgba(255,255,255,0.02); border-radius: 8px; padding: 10px;
border: 1px solid rgba(255,255,255,0.04);
}
/* Progress indicator */
#friendliesProgress {
display: flex; flex-direction: column; align-items: center;
padding: 40px 24px; gap: 20px;
}
.fp-cycle-ring {
width: 64px; height: 64px; border-radius: 50%;
border: 3px solid rgba(123,94,167,0.2);
border-top-color: #7B5EA7;
animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.fp-status { font-size: 15px; font-weight: 600; color: var(--text-sub); }
.fp-subtext { font-size: 13px; color: var(--text-dim); }
.fp-progress-bar-wrap {
width: 280px; height: 4px; background: rgba(255,255,255,0.06); border-radius: 4px; overflow: hidden;
}
.fp-progress-bar {
height: 100%; background: linear-gradient(90deg, #7B5EA7, #DC143C);
border-radius: 4px; transition: width 0.4s ease;
}
.fp-agents { display: flex; gap: 10px; }
.fp-agent-dot {
display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.fp-agent-bubble {
width: 36px; height: 36px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
font-weight: 700; font-size: 14px; color: #fff;
opacity: 0.3; transition: opacity 0.3s, box-shadow 0.3s;
}
.fp-agent-bubble.thinking {
opacity: 1; box-shadow: 0 0 16px currentColor;
animation: pulse 1.2s ease-in-out infinite;
}
.fp-agent-bubble.done { opacity: 0.7; }
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.12); }
}
.fp-agent-name { font-size: 10px; color: var(--text-dim); }
/* ββ KirkNovel ββ */
.novel-badge {
display: inline-flex; align-items: center; gap: 5px;
padding: 3px 9px; border-radius: 6px;
background: rgba(155,89,182,0.15); border: 1px solid rgba(155,89,182,0.3);
color: #c39de8; font-size: 12px; font-weight: 600; margin-bottom: 8px;
}
/* Overflow menu */
.overflow-menu {
position: fixed; z-index: 250;
background: #16161a; border: 1px solid rgba(255,255,255,0.1);
border-radius: 11px; padding: 6px;
box-shadow: 0 16px 50px rgba(0,0,0,0.6);
min-width: 170px; display: none;
}
.overflow-menu.open { display: block; animation: popIn 0.14s ease; }
.overflow-item {
display: flex; align-items: center; gap: 9px;
padding: 8px 12px; border-radius: 8px;
font-size: 13.5px; color: var(--text-sub); cursor: pointer;
transition: background var(--transition);
}
.overflow-item:hover { background: var(--glass-hover); color: var(--text); }
.overflow-item.danger { color: #ff6464; }
.overflow-item.danger:hover { background: rgba(255,100,100,0.1); }
/* Settings Modal */
.settings-section { margin-bottom: 24px; }
.settings-section h3 { font-size: 13px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 12px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.04); }
.settings-row:last-child { border-bottom: none; }
.settings-row-label { font-size: 14px; color: var(--text-sub); }
/* Toggle switch */
.toggle { width: 40px; height: 22px; background: rgba(255,255,255,0.1); border-radius: 11px; position: relative; cursor: pointer; transition: background 0.2s; }
.toggle.on { background: var(--accent); }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.toggle.on::after { transform: translateX(18px); }
/* Web Sources Card */
.web-sources-card {
margin-bottom: 12px;
background: rgba(34, 197, 94, 0.05);
border: 1px solid rgba(34, 197, 94, 0.2);
border-radius: 9px;
overflow: hidden;
font-size: 13px;
}
.web-sources-card summary {
padding: 7px 12px;
cursor: pointer;
color: #4ade80;
font-weight: 600;
display: flex;
align-items: center;
gap: 6px;
user-select: none;
}
.web-sources-card summary:hover {
background: rgba(34, 197, 94, 0.08);
}
.web-sources-list {
padding: 8px 12px 10px;
border-top: 1px solid rgba(34, 197, 94, 0.15);
display: flex;
flex-direction: column;
gap: 6px;
}
.web-source-item {
display: flex;
flex-direction: column;
padding: 5px 8px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.03);
text-decoration: none;
transition: background 0.15s;
}
.web-source-item:hover {
background: rgba(255, 255, 255, 0.07);
}
.ws-title {
font-size: 12.5px;
font-weight: 600;
color: var(--text);
}
.ws-url {
font-size: 11px;
color: var(--text-dim);
font-family: 'JetBrains Mono', monospace;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.web-searching-banner {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 6px 12px;
border-radius: 7px;
font-size: 12.5px;
color: #4ade80;
background: rgba(34, 197, 94, 0.1);
border: 1px solid rgba(34, 197, 94, 0.25);
margin-bottom: 10px;
animation: pulse 1.5s infinite;
}
.topbar-btn {
display: flex; align-items: center; gap: 6px;
padding: 6px 13px; border-radius: 8px;
font-size: 12.5px; font-weight: 600;
background: rgba(255,255,255,0.05);
border: 1px solid rgba(255,255,255,0.1);
color: var(--text-sub);
cursor: pointer;
transition: all var(--transition);
}
.topbar-btn:hover {
background: rgba(255,255,255,0.1);
color: var(--text);
}
.topbar-btn.active {
background: rgba(96, 165, 250, 0.15);
border-color: rgba(96, 165, 250, 0.4);
color: #93c5fd;
}
/* Toast */
#toastContainer {
position: fixed; bottom: 20px; right: 20px; z-index: 9999;
display: flex; flex-direction: column; gap: 8px;
}
.toast {
padding: 11px 18px; border-radius: 10px;
background: #1e1e28; border: 1px solid rgba(255,255,255,0.1);
color: var(--text); font-size: 14px;
box-shadow: 0 8px 30px rgba(0,0,0,0.5);
animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity:0; transform: translateY(10px); } to { opacity:1; transform: translateY(0); } }
.toast.success { border-color: rgba(34,197,94,0.3); }
.toast.error { border-color: rgba(220,20,60,0.3); }
/* Responsive */
@media (max-width: 700px) {
#sidebar { position: absolute; top: 0; left: 0; bottom: 0; z-index: 100; }
#sidebar:not(.collapsed) + #main { margin-left: 0; }
.msg-row { padding: 4px 12px; }
#composerArea { padding: 8px 12px 12px; }
#friendliesResults { padding: 16px; }
}
</style>
</head>
<body>
<canvas id="bgCanvas"></canvas>
<div id="app">
<!-- Sidebar -->
<nav id="sidebar">
<div class="sidebar-head">
<div class="sidebar-logo">
<img src="https://iili.io/CxhPxMG.jpg" alt="Kirk"/>
<div class="sidebar-logo-text"><span>Kirk</span>AI</div>
</div>
<button class="icon-btn" id="sidebarCloseBtn" title="Close sidebar">β</button>
</div>
<button id="newChatBtn">
<svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><path d="M12 5v14M5 12h14"/></svg>
New Chat
</button>
<div class="chat-history-label">Recent Chats</div>
<div id="historyList"></div>
<div class="sidebar-footer">
<div class="free-badge">
<svg width="11" height="11" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"/></svg>
KirkAI is free for everyone
</div>
<div class="sidebar-link" onclick="openSettingsModal()">
<svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-2 2 2 2 0 01-2-2v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83 0 2 2 0 010-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 01-2-2 2 2 0 012-2h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 010-2.83 2 2 0 012.83 0l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 012-2 2 2 0 012 2v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 0 2 2 0 010 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 012 2 2 2 0 01-2 2h-.09a1.65 1.65 0 00-1.51 1z"/></svg>
Settings
</div>
<div class="sidebar-link" onclick="exportAllChats()">
<svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
Export All Chats
</div>
<div class="sidebar-link" onclick="window.open('https://ai.kirkclient.com/api','_blank')">
<svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
API
</div>
</div>
</nav>
<!-- Main -->
<div id="main">
<!-- Topbar -->
<header id="topbar">
<button class="icon-btn" id="sidebarToggle" title="Toggle sidebar">
<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
</button>
<div id="topbarTitle">New Chat</div>
<div class="topbar-actions">
<a href="/api" target="_blank" class="icon-btn" title="KirkAI API System & Documentation" style="display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700;color:var(--text-sub);padding:0 8px;width:auto;gap:4px;text-decoration:none;">
<svg width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
<span>API</span>
</a>
<button id="friendliesToggleBtn" title="Friendlies Mode">
<svg width="15" height="15" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 00-3-3.87"/><path d="M16 3.13a4 4 0 010 7.75"/></svg>
Friendlies
</button>
<button class="icon-btn" title="Chat menu" id="chatMenuBtn">
<svg width="17" height="17" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><circle cx="12" cy="5" r="1"/><circle cx="12" cy="12" r="1"/><circle cx="12" cy="19" r="1"/></svg>
</button>
<button class="icon-btn" title="Settings" onclick="openSettingsModal()">
<svg width="17" height="17" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-2 2 2 2 0 01-2-2v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83 0 2 2 0 010-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 01-2-2 2 2 0 012-2h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 010-2.83 2 2 0 012.83 0l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 012-2 2 2 0 012 2v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 0 2 2 0 010 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 012 2 2 2 0 01-2 2h-.09a1.65 1.65 0 00-1.51 1z"/></svg>
</button>
</div>
</header>
<!-- Empty State -->
<div id="emptyState">
<img src="https://iili.io/CxhPxMG.jpg" alt="KirkAI"/>
<div>
<h1>Hello, I'm <span>KirkAI</span>.</h1>
<p style="margin-top:8px; color:var(--text-sub);">Completely free. No login required. All models unlocked.</p>
</div>
<p>What can I help you with today?</p>
<div class="starter-chips">
<div class="starter-chip" onclick="starterPrompt('Explain quantum computing in simple terms')">Explain quantum computing</div>
<div class="starter-chip" onclick="starterPrompt('Write a short story about a robot finding art')">Write a short story</div>
<div class="starter-chip" onclick="starterPrompt('Debug this code and suggest improvements')">Debug my code</div>
<div class="starter-chip" onclick="starterPrompt('Help me plan a productive morning routine')">Morning routine planner</div>
<div class="starter-chip" onclick="starterPrompt('What are the best practices for React performance?')">React performance tips</div>
<div class="starter-chip" onclick="starterPrompt('Summarize the history of the internet')">History of the internet</div>
</div>
</div>
<!-- Messages -->
<div id="messages" style="display:none;"></div>
<!-- Composer Area -->
<div id="composerArea">
<div id="attachStrip"></div>
<div id="composer">
<textarea id="promptInput" placeholder="Message KirkAIβ¦" rows="1"></textarea>
<div class="composer-actions">
<input type="file" id="fileInput" multiple accept="image/*,text/*,.pdf,.doc,.docx,.json,.csv" style="display:none"/>
<button class="composer-btn" title="Attach files" onclick="document.getElementById('fileInput').click()">
<svg width="17" height="17" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><path d="M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"/></svg>
</button>
<button id="sendBtn" title="Send" onclick="handleSend()">
<svg id="sendIcon" width="17" height="17" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
</button>
</div>
</div>
<div class="composer-footer" id="composerFooter">
<button class="picker-btn" id="modelBtn">
<span class="dot"></span>
<span id="modelBtnLabel">KirkWild Auto</span>
<svg width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><polyline points="6 9 12 15 18 9"/></svg>
</button>
<button class="picker-btn" id="modeBtn">
<svg width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"/></svg>
<span id="modeBtnLabel">Default</span>
<svg width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><polyline points="6 9 12 15 18 9"/></svg>
</button>
<button class="picker-btn" id="webSearchToggleBtn" onclick="toggleWebSearch()" title="Toggle Real-Time Web Search & Browsing">
<span class="dot" id="webSearchDot" style="background:#22c55e;box-shadow:0 0 6px #22c55e;"></span>
<span id="webSearchLabel">Web: ON</span>
</button>
<div class="composer-spacer"></div>
<span style="font-size:11.5px;color:var(--text-dim);">Press <kbd style="background:rgba(255,255,255,0.07);padding:1px 5px;border-radius:4px;font-size:11px;">Enter</kbd> to send Β· <kbd style="background:rgba(255,255,255,0.07);padding:1px 5px;border-radius:4px;font-size:11px;">Shift+Enter</kbd> for newline</span>
</div>
</div>
</div>
</div>
<!-- ββ Model Picker Popup ββ -->
<div class="picker-popup" id="modelPickerPopup">
<div class="picker-section-label">Choose Model</div>
<div class="picker-scroll" id="modelPickerList"></div>
</div>
<!-- ββ Mode Picker Popup ββ -->
<div class="picker-popup" id="modePickerPopup">
<div class="picker-section-label">Response Mode</div>
<div id="modePickerList"></div>
</div>
<!-- ββ Chat Menu Overflow ββ -->
<div class="overflow-menu" id="chatMenu">
<div class="overflow-item" onclick="exportCurrentChat(); closeChatMenu()">
<svg width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
Export Chat
</div>
<div class="overflow-item" onclick="copyCurrentChat(); closeChatMenu()">
<svg width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
Copy Transcript
</div>
<div class="overflow-item danger" onclick="clearCurrentChat(); closeChatMenu()">
<svg width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a1 1 0 011-1h4a1 1 0 011 1v2"/></svg>
Clear Chat
</div>
</div>
<!-- ββ Settings Modal ββ -->
<div class="modal-backdrop" id="settingsModal" style="display:none;" onclick="closeModalOnBackdrop(event,'settingsModal')">
<div class="modal">
<div class="modal-head">
<h2>βοΈ Settings</h2>
<button class="modal-close" onclick="closeModal('settingsModal')">β</button>
</div>
<div class="settings-section">
<h3>Appearance</h3>
<div class="settings-row">
<div class="settings-row-label">Show canvas background animation</div>
<div class="toggle on" id="toggleBg" onclick="toggleBgAnim(this)"></div>
</div>
<div class="settings-row">
<div class="settings-row-label">Compact message density</div>
<div class="toggle" id="toggleCompact" onclick="toggleCompact(this)"></div>
</div>
</div>
<div class="settings-section">
<h3>Chat</h3>
<div class="settings-row">
<div class="settings-row-label">Send on Enter (disable for Shift+Enter only)</div>
<div class="toggle on" id="toggleEnterSend" onclick="toggleEnterSend(this)"></div>
</div>
</div>
<div class="settings-section">
<h3>Data</h3>
<div style="display:flex;gap:10px;flex-wrap:wrap;">
<button class="btn btn-secondary" onclick="exportAllChats()">Export All Chats</button>
<button class="btn btn-danger" onclick="clearAllChats()">Clear All History</button>
</div>
</div>
<div class="modal-actions">
<button class="btn btn-primary" onclick="closeModal('settingsModal')">Done</button>
</div>
</div>
</div>
<!-- ββ Friendlies Manage Modal ββ -->
<div class="modal-backdrop" id="friendliesModal" style="display:none;" onclick="closeModalOnBackdrop(event,'friendliesModal')">
<div class="modal modal-wide">
<div class="modal-head">
<h2>π€ Manage Friendlies</h2>
<button class="modal-close" onclick="closeModal('friendliesModal')">β</button>
</div>
<p style="font-size:14px;color:var(--text-sub);margin-bottom:20px;">Friendlies are AI agents that collaborate in cycles to tackle your prompts from multiple angles. Drag to reorder.</p>
<div id="agentsList"></div>
<div style="margin-top:16px;">
<button class="btn btn-purple" onclick="openAddAgentForm()">
<svg width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24" style="display:inline;vertical-align:middle;margin-right:5px;"><path d="M12 5v14M5 12h14"/></svg>
Add Custom Agent
</button>
</div>
<div id="agentEditForm" style="display:none; margin-top:20px; background:var(--glass); border:1px solid var(--glass-border); border-radius:14px; padding:20px;">
<h3 style="margin-bottom:16px; font-size:16px;">
<span id="agentFormTitle">Edit Agent</span>
</h3>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:14px;">
<div class="form-group">
<label class="form-label">Name</label>
<input class="form-input" id="agentName" placeholder="e.g. Alex"/>
</div>
<div class="form-group">
<label class="form-label">Role / Title</label>
<input class="form-input" id="agentRole" placeholder="e.g. The Strategist"/>
</div>
</div>
<div class="form-group">
<label class="form-label">Avatar Color</label>
<div class="form-color-row">
<div class="color-preview" id="colorPreview"></div>
<input type="color" class="form-input" id="agentColor" style="width:60px;height:38px;padding:2px;cursor:pointer;" oninput="updateColorPreview()"/>
<span style="font-size:13px;color:var(--text-dim);">Pick a color for this agent's avatar</span>
</div>
</div>
<div class="form-group">
<label class="form-label">System Prompt</label>
<textarea class="form-input form-textarea" id="agentSystemPrompt" placeholder="Describe this agent's personality, role, and behaviorβ¦" style="min-height:130px;"></textarea>
</div>
<div style="display:flex;gap:10px;justify-content:flex-end;margin-top:8px;">
<button class="btn btn-secondary" onclick="cancelAgentEdit()">Cancel</button>
<button class="btn btn-primary" onclick="saveAgent()">Save Agent</button>
</div>
</div>
</div>
</div>
<!-- Toast container -->
<div id="toastContainer"></div>
<script>
/* βββββββββββββββββββββββββββββββββββββββββββββββ
CONFIGURATION
βββββββββββββββββββββββββββββββββββββββββββββββ */
const API_URL = (location.hostname.endsWith('kirkclient.com') || location.hostname.endsWith('pages.dev'))
? '/api/chat'
: 'https://ai.kirkclient.com/api/chat';
const KIRK_LOGO = 'https://iili.io/CxhPxMG.jpg';
const MODELS = [
{
id: 'Lucent 5.0',
name: 'Lucent 5.0',
tag: 'Flagship (Fine-Tuned)',
version: '5.0',
desc: 'Official fine-tuned Minecraft client engineering & modding intelligence, housed on Hugging Face (KirkAis/Lucent)'
},
{
id: 'Aether 4.0',
name: 'Aether 4.0',
tag: 'General IDE',
version: '4.0',
desc: 'Most efficient kirk model, best for large scale database changes, project changes, or pretty much any useful need within an IDE'
},
{
id: 'Axiom 3.5',
name: 'Axiom 3.5',
tag: 'Refactor & Development',
version: '3.5',
desc: 'Great for major project changes, refactoring, major patch fixes, and overall development'
},
{
id: 'Arco 3.0',
name: 'Arco 3.0',
tag: 'Detail & Small Apps',
version: '3.0',
desc: 'Quick eye for small details, efficient for small scale projects and applications'
},
{
id: 'Nova 2.3',
name: 'Nova 2.3',
tag: 'Codebase & Quick Fixes',
version: '2.3',
desc: 'Efficient for small tasks, quick error fixes, general codebase analyzing'
},
{
id: 'Epoch 1.1',
name: 'Epoch 1.1',
tag: 'Fast Thinker & Search',
version: '1.1',
desc: 'Fast thinker, methodical and analytical, perfect for quick web searches or questions'
}
];
const MODES = [
{ id: 'default', name: 'Default', meta: 'Balanced KirkAI', prompt: '' },
{ id: 'instant', name: 'KirkInstant', meta: 'Snappy one-shot answers', prompt: 'Respond as concisely as possible. One or two short paragraphs maximum. No preamble.' },
{ id: 'agent', name: 'KirkAgent', meta: 'Plans, then acts', prompt: 'Operate as an autonomous agent. Before answering, briefly outline a numbered plan, then execute each step in your reply. End with a Result section.' },
{ id: 'thinkmaxx', name: 'Kirk ThinkMaxxing', meta: 'Maximum reasoning depth', prompt: 'Reason exhaustively. Begin with a hidden-style <thinking> block where you reason step-by-step through every angle, edge case, and counter-argument, then deliver a confident final answer in a Final section.' },
{ id: 'creative', name: 'Kirk Muse', meta: 'Vivid, creative writing', prompt: 'Adopt a vivid, imaginative, expressive voice. Prefer evocative imagery and rhythm over dryness.' },
{ id: 'coder', name: 'Kirk Forge', meta: 'Engineering mode', prompt: 'Act as a senior engineer. Prefer working code, exact APIs, and concise rationale. Always show code in fenced blocks.' }
];
const DEFAULT_FRIENDLIES = [
{
id: 'erika', name: 'Erika', role: 'The Organizer',
color: '#7B5EA7', isDefault: true,
systemPrompt: 'You are Erika, an AI agent specializing in organization and ideation. You are part of a collaborative Friendlies team. Your role is to take the user\'s idea and figure out exactly what they want, then create a clear outline or rough draft. You are warm, encouraging, and think in big-picture terms. Focus on structure, clarity of intent, and a solid foundation for the project. Be concise but thorough.'
},
{
id: 'tyler', name: 'Tyler', role: 'The Detail Man',
color: '#2E86AB', isDefault: true,
systemPrompt: 'You are Tyler, an AI agent specializing in detail analysis and review. You are part of a collaborative Friendlies team. Your role is to examine every detail of a project β look at the rough draft carefully, identify what works, what doesn\'t, flag inconsistencies, gaps, or improvements, and produce a precise breakdown of exactly what everything is. You are analytical, meticulous, and direct. Give concrete, actionable feedback.'
},
{
id: 'kirk', name: 'Kirk', role: 'The Decider',
color: '#DC143C', isDefault: true,
systemPrompt: 'You are Kirk, the lead AI agent and the final authority in the Friendlies team. Your role is to look at the outline from Erika and the detailed analysis from Tyler, then make definitive decisions about what is right, what needs to change, and what the final product should be. You are confident, authoritative, and decisive. You synthesize all prior thinking into clear, correct conclusions.'
}
];
/* βββββββββββββββββββββββββββββββββββββββββββββββ
AGENTS.MD PRESETS & SPEC
βββββββββββββββββββββββββββββββββββββββββββββββ */
const AGENTS_MD_PRESETS = {
kirk: `# AGENTS.md for Kirk Client & Kirk AI
## 1. Project Overview & Architecture
- Standalone zero-barrier AI intelligence platform at ai.kirkclient.com.
- Cloudflare Pages Functions serverless endpoints (/api/chat, /api/search).
- Multi-agent Friendlies collaborative engine (Erika, Tyler, Kirk).
## 2. Development Guidelines
- Always use modern vanilla JS, responsive CSS, and semantic HTML5.
- Keep deployments self-contained for Cloudflare Pages.
- Test serverless endpoints locally before publishing.
## 3. Operational Rules
- Zero-barrier access: No paywalls, tokens, or mandatory logins.
- All models accessible to everyone for free.`,
nextjs: `# AGENTS.md Guidelines
## 1. Use the Development Server, not npm run build
- Always use npm run dev (or pnpm dev) while iterating on the application.
- Do NOT run production build inside interactive agent sessions.
- Keep dependencies in sync (package-lock.json, pnpm-lock.yaml).
## 2. Coding Conventions
- Prefer TypeScript (.tsx/.ts) for new components and utilities.
- Co-locate component-specific styles with components when practical.
- Keep README for humans, AGENTS.md for coding agents.`,
python: `# AGENTS.md for Python / Backend Projects
## 1. Environment & Setup
- Use virtual environments (venv / poetry).
- Follow PEP 8 style guides and type hints (mypy).
- Format code using Black and Ruff.
## 2. Testing
- Run pytest for all unit and integration tests.
- Maintain test coverage above 80%.
## 3. Architecture
- Separation of concerns between API routers, services, and repositories.
- Keep environment configurations in .env files.`,
clean: `# AGENTS.md General Software Guidelines
## 1. Code Standards
- Write modular, DRY, and well-commented code.
- Prefer explicit over implicit logic.
- Gracefully handle all network and API exceptions.
## 2. Testing & Quality Assurance
- Test edge cases and validate inputs before processing.
- Keep user interfaces responsive, accessible, and fast.`
};
/* βββββββββββββββββββββββββββββββββββββββββββββββ
STATE
βββββββββββββββββββββββββββββββββββββββββββββββ */
let state = {
conversations: [], // [{id, title, messages, model, mode, created}]
currentId: null,
selectedModel: 'Lucent 5.0',
selectedMode: 'default',
attachments: [], // [{name, type, dataUrl, content}]
streaming: false,
abortController: null,
friendliesMode: false,
webSearch: true,
agentsMd: {
enabled: true,
content: AGENTS_MD_PRESETS.kirk
},
settings: { bgAnim: true, compact: false, enterSend: true, apiKey: '' }
};
function loadState() {
try {
const convs = JSON.parse(localStorage.getItem('kirk_conversations_v2') || '[]');
state.conversations = convs;
} catch(e) { state.conversations = []; }
try {
const s = JSON.parse(localStorage.getItem('kirk_settings_v1') || '{}');
Object.assign(state.settings, s);
} catch(e) {}
const lastModel = localStorage.getItem('kirk_last_model');
if (lastModel && MODELS.some(m => m.id === lastModel)) {
state.selectedModel = lastModel;
} else {
state.selectedModel = 'Lucent 5.0';
}
const lastMode = localStorage.getItem('kirk_last_mode');
if (lastMode) state.selectedMode = lastMode;
const ws = localStorage.getItem('kirk_web_search');
if (ws !== null) state.webSearch = ws === 'true';
const amdEnabled = localStorage.getItem('kirk_agents_md_enabled');
if (amdEnabled !== null) state.agentsMd.enabled = amdEnabled === 'true';
const amdContent = localStorage.getItem('kirk_agents_md_content');
if (amdContent) state.agentsMd.content = amdContent;
}
function saveConversations() {
localStorage.setItem('kirk_conversations_v2', JSON.stringify(state.conversations));
}
function saveSettings() {
localStorage.setItem('kirk_settings_v1', JSON.stringify(state.settings));
}
function getFriendlies() {
try {
const stored = localStorage.getItem('kirk_friendlies_v1');
if (!stored) return JSON.parse(JSON.stringify(DEFAULT_FRIENDLIES));
const parsed = JSON.parse(stored);
// Ensure defaults are always present at start
const ids = parsed.map(f => f.id);
const merged = [];
for (const d of DEFAULT_FRIENDLIES) {
const existing = parsed.find(f => f.id === d.id);
merged.push(existing ? { ...d, ...existing } : d);
}
for (const f of parsed) {
if (!DEFAULT_FRIENDLIES.find(d => d.id === f.id)) merged.push(f);
}
return merged;
} catch(e) { return JSON.parse(JSON.stringify(DEFAULT_FRIENDLIES)); }
}
function saveFriendlies(arr) {
localStorage.setItem('kirk_friendlies_v1', JSON.stringify(arr));
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
WEBGL BACKGROUND SHADER
βββββββββββββββββββββββββββββββββββββββββββββββ */
(function() {
const canvas = document.getElementById('bgCanvas');
const gl = canvas.getContext('webgl');
if (!gl) return;
const vert = `
attribute vec2 a_pos;
void main() { gl_Position = vec4(a_pos, 0.0, 1.0); }
`;
const frag = `
precision mediump float;
uniform vec2 u_res;
uniform float u_time;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float noise(vec2 p) {
vec2 i = floor(p); vec2 f = fract(p);
f = f*f*(3.0-2.0*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),mix(hash(i+vec2(0,1)),hash(i+vec2(1,1)),f.x),f.y);
}
void main() {
vec2 uv = gl_FragCoord.xy / u_res;
uv.y = 1.0 - uv.y;
float t = u_time * 0.12;
float n = noise(uv * 3.0 + vec2(t * 0.5, t * 0.3));
n += noise(uv * 6.0 - vec2(t * 0.3, t * 0.2)) * 0.5;
n /= 1.5;
vec3 crimson = vec3(0.863, 0.078, 0.235);
vec3 dark = vec3(0.02, 0.01, 0.02);
float d = length(uv - vec2(0.5));
float glow = smoothstep(0.8, 0.0, d) * 0.15;
vec3 col = mix(dark, crimson, n * glow + n * 0.04);
gl_FragColor = vec4(col, 1.0);
}
`;
function compile(type, src) {
const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return s;
}
const prog = gl.createProgram();
gl.attachShader(prog, compile(gl.VERTEX_SHADER, vert));
gl.attachShader(prog, compile(gl.FRAGMENT_SHADER, frag));
gl.linkProgram(prog); gl.useProgram(prog);
const buf = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]), gl.STATIC_DRAW);
const loc = gl.getAttribLocation(prog, 'a_pos');
gl.enableVertexAttribArray(loc); gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);
const uRes = gl.getUniformLocation(prog, 'u_res');
const uTime = gl.getUniformLocation(prog, 'u_time');
let animId;
function resize() {
canvas.width = window.innerWidth; canvas.height = window.innerHeight;
gl.viewport(0, 0, canvas.width, canvas.height);
gl.uniform2f(uRes, canvas.width, canvas.height);
}
window.addEventListener('resize', resize); resize();
let running = true;
function loop(t) {
if (!running) return;
gl.uniform1f(uTime, t * 0.001);
gl.drawArrays(gl.TRIANGLES, 0, 6);
animId = requestAnimationFrame(loop);
}
animId = requestAnimationFrame(loop);
window._bgAnim = {
stop() { running = false; cancelAnimationFrame(animId); },
start() { if (!running) { running = true; animId = requestAnimationFrame(loop); } }
};
})();
/* βββββββββββββββββββββββββββββββββββββββββββββββ
UI HELPERS
βββββββββββββββββββββββββββββββββββββββββββββββ */
function showToast(msg, type = '') {
const el = document.createElement('div');
el.className = 'toast ' + type;
el.textContent = msg;
document.getElementById('toastContainer').appendChild(el);
setTimeout(() => { el.style.opacity = '0'; el.style.transition = 'opacity 0.3s'; setTimeout(() => el.remove(), 300); }, 3000);
}
function closeModal(id) { document.getElementById(id).style.display = 'none'; }
function closeModalOnBackdrop(e, id) { if (e.target.classList.contains('modal-backdrop')) closeModal(id); }
function openModal(id) { document.getElementById(id).style.display = 'flex'; }
function openSettingsModal() { closeAllPickersMenus(); applySettingsUI(); openModal('settingsModal'); }
function applySettingsUI() {
setToggle('toggleBg', state.settings.bgAnim);
setToggle('toggleCompact', state.settings.compact);
setToggle('toggleEnterSend', state.settings.enterSend);
}
function setToggle(id, val) {
const el = document.getElementById(id);
if (val) el.classList.add('on'); else el.classList.remove('on');
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
WEB SEARCH & AGENTS.MD HELPERS
βββββββββββββββββββββββββββββββββββββββββββββββ */
function renderWebSourcesCard(sources) {
if (!sources || !sources.length) return '';
return `
<details class="web-sources-card">
<summary>
<svg width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>
<span>Consulted <strong>${sources.length}</strong> live web sources</span>
</summary>
<div class="web-sources-list">
${sources.map(s => `
<a href="${escAttr(s.url)}" target="_blank" rel="noopener" class="web-source-item">
<span class="ws-title">${escHtml(s.title || s.url)}</span>
<span class="ws-url">${escHtml(s.url)}</span>
</a>
`).join('')}
</div>
</details>
`;
}
function toggleWebSearch() {
state.webSearch = !state.webSearch;
localStorage.setItem('kirk_web_search', state.webSearch ? 'true' : 'false');
updateWebSearchUI();
showToast(state.webSearch ? 'Live Web Access enabled' : 'Live Web Access disabled');
}
function updateWebSearchUI() {
const btn = document.getElementById('webSearchToggleBtn');
const dot = document.getElementById('webSearchDot');
const lbl = document.getElementById('webSearchLabel');
if (!btn || !dot || !lbl) return;
if (state.webSearch) {
dot.style.background = '#22c55e';
dot.style.boxShadow = '0 0 6px #22c55e';
lbl.textContent = 'Web: ON';
btn.style.color = '#fff';
btn.style.borderColor = 'rgba(34, 197, 94, 0.4)';
btn.style.background = 'rgba(34, 197, 94, 0.12)';
} else {
dot.style.background = '#6b7280';
dot.style.boxShadow = 'none';
lbl.textContent = 'Web: OFF';
btn.style.color = 'var(--text-sub)';
btn.style.borderColor = 'rgba(255, 255, 255, 0.1)';
btn.style.background = 'var(--glass)';
}
}
function exportFriendliesToAgentsMd() {
const conv = state.conversations.find(c => c.id === state.currentId);
const title = (conv && conv.title) ? conv.title : 'Project Plan';
let md = `# AGENTS.md for ${title}\n\n`;
md += `Generated by KirkAI Friendlies Collaborative Engine.\n\n`;
md += `## 1. Project Guidelines & Overview\n`;
md += `- Task: ${title}\n`;
md += `- Date: ${new Date().toISOString().split('T')[0]}\n\n`;
md += `## 2. Collaborative Decisions\n`;
const friendliesEl = document.getElementById('friendliesResults');
if (friendliesEl) {
const cards = friendliesEl.querySelectorAll('.friendly-card');
cards.forEach(card => {
const name = card.querySelector('.fc-name')?.textContent || 'Agent';
const role = card.querySelector('.fc-role')?.textContent || '';
const text = card.querySelector('.fc-output')?.innerText || '';
md += `### ${name} (${role})\n${text}\n\n`;
});
}
downloadFile('AGENTS.md', md);
showToast('Exported Friendlies plan as AGENTS.md');
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
SIDEBAR
βββββββββββββββββββββββββββββββββββββββββββββββ */
const sidebar = document.getElementById('sidebar');
document.getElementById('sidebarToggle').onclick = () => { sidebar.classList.toggle('collapsed'); };
document.getElementById('sidebarCloseBtn').onclick = () => { sidebar.classList.add('collapsed'); };
function renderHistory() {
const list = document.getElementById('historyList');
list.innerHTML = '';
if (!state.conversations.length) {
list.innerHTML = '<div style="padding:16px;font-size:13px;color:var(--text-dim);text-align:center;">No conversations yet</div>';
return;
}
const sorted = [...state.conversations].sort((a,b) => (b.created||0) - (a.created||0));
for (const conv of sorted) {
const el = document.createElement('div');
el.className = 'hist-item' + (conv.id === state.currentId ? ' active' : '');
el.innerHTML = `
<span class="hist-item-icon">π¬</span>
<span class="hist-item-title">${escHtml(conv.title || 'New Chat')}</span>
<button class="hist-item-del" title="Delete" onclick="deleteConversation('${conv.id}',event)">β</button>
`;
el.addEventListener('click', () => loadConversation(conv.id));
list.appendChild(el);
}
}
function deleteConversation(id, e) {
if (e) e.stopPropagation();
state.conversations = state.conversations.filter(c => c.id !== id);
if (state.currentId === id) {
state.currentId = null;
const msgContainer = document.getElementById('messages');
if (msgContainer) msgContainer.innerHTML = '';
newChat();
}
saveConversations();
renderHistory();
showToast('Chat deleted', 'success');
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
CONVERSATION MANAGEMENT
βββββββββββββββββββββββββββββββββββββββββββββββ */
function genId() { return Date.now().toString(36) + Math.random().toString(36).slice(2, 6); }
function getCurrentConv() {
return state.conversations.find(c => c.id === state.currentId) || null;
}
function newChat() {
closeAllPickersMenus();
if (state.streaming) {
stopStreaming();
}
state.currentId = null;
state.attachments = [];
renderAttachStrip();
// Fully purge messages DOM container so old chats never linger
const msgContainer = document.getElementById('messages');
if (msgContainer) msgContainer.innerHTML = '';
showEmptyState();
const input = document.getElementById('promptInput');
if (input) {
input.value = '';
autoResizeTextarea();
}
document.getElementById('topbarTitle').textContent = 'New Chat';
renderHistory();
}
function loadConversation(id) {
state.currentId = id;
const conv = getCurrentConv();
if (!conv) {
newChat();
return;
}
state.selectedModel = conv.model || state.selectedModel;
state.selectedMode = conv.mode || state.selectedMode;
updatePickerLabels();
document.getElementById('topbarTitle').textContent = conv.title || 'Chat';
renderMessages(conv.messages || []);
renderHistory();
if (window.innerWidth <= 700) sidebar.classList.add('collapsed');
}
function ensureCurrentConv(firstUserMsg) {
if (!state.currentId) {
const id = genId();
const title = firstUserMsg.slice(0, 48) + (firstUserMsg.length > 48 ? 'β¦' : '');
state.conversations.unshift({
id,
title,
messages: [],
model: state.selectedModel,
mode: state.selectedMode,
created: Date.now()
});
state.currentId = id;
document.getElementById('topbarTitle').textContent = title;
saveConversations();
renderHistory();
}
return getCurrentConv();
}
function pushMessage(role, content, attachments, webSources) {
const conv = getCurrentConv();
if (!conv) return;
if (!Array.isArray(conv.messages)) conv.messages = [];
conv.messages.push({ role, content, attachments, webSources, ts: Date.now() });
saveConversations();
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
EMPTY STATE / MESSAGES TOGGLE
βββββββββββββββββββββββββββββββββββββββββββββββ */
function showEmptyState() {
document.getElementById('emptyState').style.display = 'flex';
const msgContainer = document.getElementById('messages');
if (msgContainer) {
msgContainer.style.display = 'none';
if (!state.currentId) {
msgContainer.innerHTML = '';
}
}
}
function showMessages() {
document.getElementById('emptyState').style.display = 'none';
const msgContainer = document.getElementById('messages');
if (msgContainer) {
msgContainer.style.display = 'flex';
}
}
function starterPrompt(text) {
document.getElementById('promptInput').value = text;
handleSend();
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
MARKDOWN RENDERING
βββββββββββββββββββββββββββββββββββββββββββββββ */
function renderMarkdown(raw) {
// Parse thinking blocks first (<think>, <thinking>, <thought>)
let thinkingHTML = '';
let text = raw.replace(/<(?:thinking|think|thought)>([\s\S]*?)<\/(?:thinking|think|thought)>/gi, (_, inner) => {
thinkingHTML += `
<details class="thinking-block">
<summary class="thinking-toggle">
<span>π§ </span> <span>Thinking Process</span> <span class="th-arrow">βΎ</span>
</summary>
<div class="thinking-content"><pre>${escHtml(inner.trim())}</pre></div>
</details>`;
return '';
});
// Handle active streaming unclosed thinking block
const unclosedThink = text.match(/<(?:thinking|think|thought)>([\s\S]*)$/i);
if (unclosedThink) {
thinkingHTML += `
<details class="thinking-block" open>
<summary class="thinking-toggle">
<span>π§ </span> <span>Thinking Process (Streaming...)</span> <span class="th-arrow">βΎ</span>
</summary>
<div class="thinking-content"><pre>${escHtml(unclosedThink[1].trim())}</pre></div>
</details>`;
text = text.slice(0, unclosedThink.index);
}
text = text.trim();
// Simple markdown β HTML
let html = text
.replace(/```(\w*)\n?([\s\S]*?)```/g, (_, lang, code) => {
const highlighted = lang && hljs.getLanguage(lang)
? hljs.highlight(code.trim(), { language: lang }).value
: hljs.highlightAuto(code.trim()).value;
const id = 'cb_' + Math.random().toString(36).slice(2);
return `<div class="code-block-wrap">
<div class="code-header">
<span class="code-lang">${escHtml(lang || 'code')}</span>
<button class="copy-btn" id="${id}" onclick="copyCode(this,'${id}',\`${escAttr(code.trim())}\`)">Copy</button>
</div>
<pre><code class="hljs language-${escHtml(lang)}">${highlighted}</code></pre>
</div>`;
})
.replace(/`([^`]+)`/g, '<code>$1</code>')
.replace(/\*\*\*(.+?)\*\*\*/g, '<strong><em>$1</em></strong>')
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.+?)\*/g, '<em>$1</em>')
.replace(/~~(.+?)~~/g, '<del>$1</del>')
.replace(/^#{4}\s+(.+)$/gm, '<h4>$1</h4>')
.replace(/^#{3}\s+(.+)$/gm, '<h3>$1</h3>')
.replace(/^#{2}\s+(.+)$/gm, '<h2>$1</h2>')
.replace(/^#{1}\s+(.+)$/gm, '<h1>$1</h1>')
.replace(/^---+$/gm, '<hr/>')
.replace(/^\|\s*(.+?)\s*\|/gm, (line) => {
if (/^[\s|:-]+$/.test(line)) return '';
const cells = line.split('|').filter((_,i,a) => i > 0 && i < a.length-1).map(c => c.trim());
return '<tr>' + cells.map(c => `<td>${c}</td>`).join('') + '</tr>';
})
.replace(/(<tr>.*<\/tr>)/gs, m => `<table>${m}</table>`)
.replace(/^>\s+(.+)$/gm, '<blockquote>$1</blockquote>')
.replace(/^\s*[-*+]\s+(.+)$/gm, '<li>$1</li>')
.replace(/(<li>[\s\S]*?<\/li>)/g, m => `<ul>${m}</ul>`)
.replace(/^\s*\d+\.\s+(.+)$/gm, '<li>$1</li>')
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>')
.replace(/\n{2,}/g, '</p><p>')
.replace(/\n/g, '<br/>');
// Wrap in paragraphs
if (!html.startsWith('<')) html = '<p>' + html + '</p>';
return thinkingHTML + '<div class="md-body">' + html + '</div>';
}
function escHtml(str) {
return String(str).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
}
function escAttr(str) {
return String(str).replace(/`/g,'\\`').replace(/\$/g,'\\$').replace(/\\/g,'\\\\');
}
function copyCode(btn, id, code) {
navigator.clipboard.writeText(code).then(() => {
btn.textContent = 'β Copied'; btn.classList.add('copied');
setTimeout(() => { btn.textContent = 'Copy'; btn.classList.remove('copied'); }, 2000);
});
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
MESSAGE RENDERING
βββββββββββββββββββββββββββββββββββββββββββββββ */
function renderMessages(messages) {
showMessages();
const container = document.getElementById('messages');
container.innerHTML = '';
for (const msg of messages) appendMessageDOM(msg.role, msg.content, msg.attachments, msg.webSources);
container.scrollTop = container.scrollHeight;
}
function appendMessageDOM(role, content, attachments, webSources) {
const container = document.getElementById('messages');
const row = document.createElement('div');
row.className = 'msg-row ' + (role === 'user' ? 'user' : 'assistant');
// Avatar
const av = document.createElement('div');
av.className = 'msg-avatar ' + (role === 'user' ? 'user-av' : 'ai');
av.textContent = role === 'user' ? 'π€' : 'β¦';
if (role === 'assistant') {
av.style.background = 'var(--accent-dim)';
av.style.color = 'var(--accent)';
}
// Content wrap
const wrap = document.createElement('div');
wrap.className = 'msg-content-wrap';
// Bubble
const bubble = document.createElement('div');
bubble.className = 'msg-bubble';
// Attach previews (user only)
if (attachments && attachments.length) {
const pr = document.createElement('div');
pr.className = 'attach-preview-row';
for (const a of attachments) {
if (a.type && a.type.startsWith('image/')) {
const img = document.createElement('img');
img.className = 'attach-thumb'; img.src = a.dataUrl; img.alt = a.name;
pr.appendChild(img);
} else {
const chip = document.createElement('div');
chip.className = 'attach-file-chip';
chip.innerHTML = `π <span>${escHtml(a.name)}</span>`;
pr.appendChild(chip);
}
}
bubble.appendChild(pr);
}
// Content
const contentDiv = document.createElement('div');
if (role === 'user') {
contentDiv.className = 'md-body';
contentDiv.innerHTML = '<p>' + escHtml(content).replace(/\n/g,'<br/>') + '</p>';
} else {
const sourcesHtml = (webSources && webSources.length) ? renderWebSourcesCard(webSources) : '';
contentDiv.innerHTML = sourcesHtml + renderMarkdown(content);
}
bubble.appendChild(contentDiv);
// Actions
const actions = document.createElement('div');
actions.className = 'msg-actions';
actions.innerHTML = `
<button class="msg-action-btn" onclick="copyMsg(this,'${escAttr(content)}')">Copy</button>
`;
wrap.appendChild(bubble);
wrap.appendChild(actions);
if (role === 'user') {
row.appendChild(wrap); row.appendChild(av);
} else {
row.appendChild(av); row.appendChild(wrap);
}
container.appendChild(row);
row.scrollIntoView({ behavior: 'smooth', block: 'end' });
return row;
}
function copyMsg(btn, text) {
navigator.clipboard.writeText(text).then(() => {
btn.textContent = 'β Copied'; btn.classList.add('copied');
setTimeout(() => { btn.textContent = 'Copy'; btn.classList.remove('copied'); }, 2000);
});
}
function appendStreamingBubble() {
const container = document.getElementById('messages');
const row = document.createElement('div');
row.className = 'msg-row assistant';
row.id = 'streamingRow';
const av = document.createElement('div');
av.className = 'msg-avatar ai';
av.textContent = 'β¦';
const wrap = document.createElement('div');
wrap.className = 'msg-content-wrap';
const bubble = document.createElement('div');
bubble.className = 'msg-bubble';
bubble.id = 'streamingBubble';
if (state.webSearch) {
bubble.innerHTML = `
<div class="web-searching-banner">
<svg width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.3" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>
<span>Searching live web data & citationsβ¦</span>
</div>
<div class="msg-loading"><span></span><span></span><span></span></div>
`;
} else {
bubble.innerHTML = '<div class="msg-loading"><span></span><span></span><span></span></div>';
}
wrap.appendChild(bubble);
row.appendChild(av); row.appendChild(wrap);
container.appendChild(row);
row.scrollIntoView({ behavior: 'smooth', block: 'end' });
return bubble;
}
function finalizeStreamingBubble(bubble, fullText, webSources) {
const row = document.getElementById('streamingRow');
if (row) row.id = '';
if (bubble) {
bubble.id = '';
const sourcesHtml = (webSources && webSources.length) ? renderWebSourcesCard(webSources) : '';
bubble.innerHTML = sourcesHtml + renderMarkdown(fullText);
const actions = document.createElement('div');
actions.className = 'msg-actions';
const txt = fullText;
actions.innerHTML = `<button class="msg-action-btn" onclick="copyMsg(this,\`${escAttr(txt)}\`)">Copy</button>`;
const wrap = bubble.closest('.msg-content-wrap');
if (wrap) wrap.appendChild(actions);
bubble.scrollIntoView({ behavior: 'smooth', block: 'end' });
}
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
ATTACHMENTS
βββββββββββββββββββββββββββββββββββββββββββββββ */
document.getElementById('fileInput').onchange = async function() {
for (const file of this.files) {
if (file.type.startsWith('image/')) {
const dataUrl = await readAsDataURL(file);
state.attachments.push({ name: file.name, type: file.type, dataUrl, content: null });
} else {
const text = await readAsText(file);
state.attachments.push({ name: file.name, type: file.type, dataUrl: null, content: text });
}
}
renderAttachStrip();
this.value = '';
};
function readAsDataURL(file) {
return new Promise(res => { const r = new FileReader(); r.onload = e => res(e.target.result); r.readAsDataURL(file); });
}
function readAsText(file) {
return new Promise(res => { const r = new FileReader(); r.onload = e => res(e.target.result); r.readAsText(file); });
}
function renderAttachStrip() {
const strip = document.getElementById('attachStrip');
strip.innerHTML = '';
for (let i = 0; i < state.attachments.length; i++) {
const a = state.attachments[i];
const chip = document.createElement('div');
chip.className = 'attach-chip';
if (a.dataUrl && a.type.startsWith('image/')) {
const img = document.createElement('img');
img.className = 'attach-chip-img'; img.src = a.dataUrl;
chip.appendChild(img);
} else {
chip.innerHTML += 'π ';
}
chip.innerHTML += `<span class="attach-chip-name">${escHtml(a.name)}</span>`;
const del = document.createElement('span');
del.className = 'attach-chip-del'; del.textContent = 'β';
del.onclick = () => { state.attachments.splice(i, 1); renderAttachStrip(); };
chip.appendChild(del);
strip.appendChild(chip);
}
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
SEND LOGIC
βββββββββββββββββββββββββββββββββββββββββββββββ */
async function handleSend() {
if (state.streaming) { stopStreaming(); return; }
const input = document.getElementById('promptInput');
const text = input.value.trim();
if (!text && !state.attachments.length) return;
if (state.friendliesMode) {
await runFriendliesCycle(text);
return;
}
const attachSnap = [...state.attachments];
state.attachments = []; renderAttachStrip();
input.value = ''; autoResizeTextarea();
const isNewChat = !state.currentId;
const conv = ensureCurrentConv(text);
const msgContainer = document.getElementById('messages');
if (isNewChat && msgContainer) {
msgContainer.innerHTML = '';
}
showMessages();
pushMessage('user', text, attachSnap);
appendMessageDOM('user', text, attachSnap);
const bubble = appendStreamingBubble();
setSendStop(true);
// Build messages array
const sysPrompt = MODES.find(m => m.id === state.selectedMode)?.prompt || '';
const apiMessages = [];
if (sysPrompt) apiMessages.push({ role: 'system', content: sysPrompt });
for (const m of conv.messages) {
if (m.role === 'user') {
const parts = [];
if (m.attachments) {
for (const a of m.attachments) {
if (a.dataUrl && a.type.startsWith('image/')) {
parts.push({ type: 'image_url', image_url: { url: a.dataUrl } });
} else if (a.content) {
parts.push({ type: 'text', text: `[File: ${a.name}]\n${a.content}` });
}
}
}
parts.push({ type: 'text', text: m.content });
apiMessages.push({ role: 'user', content: parts.length === 1 ? parts[0].text : parts });
} else {
apiMessages.push({ role: 'assistant', content: m.content });
}
}
let fullText = '';
let webSources = [];
try {
state.abortController = new AbortController();
const payload = {
model: state.selectedModel,
messages: apiMessages,
stream: true,
web_search: state.webSearch,
agents_md: state.agentsMd.enabled ? state.agentsMd.content : undefined
};
if (state.settings.apiKey) payload.custom_api_key = state.settings.apiKey;
const resp = await fetch(API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
signal: state.abortController.signal
});
if (!resp.ok) {
const errJson = await resp.json().catch(() => ({}));
throw new Error(errJson.error || `API error ${resp.status}`);
}
const sourcesHeader = resp.headers.get('x-web-sources');
if (sourcesHeader) {
try { webSources = JSON.parse(decodeURIComponent(sourcesHeader)); } catch(e){}
}
const reader = resp.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split('\n');
buffer = lines.pop();
for (const line of lines) {
if (!line.startsWith('data: ')) continue;
const raw = line.slice(6);
if (raw === '[DONE]') break;
try {
const json = JSON.parse(raw);
const delta = json.choices?.[0]?.delta?.content || '';
fullText += delta;
const sourcesHtml = webSources.length ? renderWebSourcesCard(webSources) : '';
bubble.innerHTML = sourcesHtml + renderMarkdown(fullText + 'β');
bubble.scrollIntoView({ behavior: 'smooth', block: 'end' });
} catch {}
}
}
} catch(e) {
if (e.name !== 'AbortError') {
fullText = fullText || `β οΈ Error: ${e.message}`;
showToast('Request failed: ' + e.message, 'error');
}
}
finalizeStreamingBubble(bubble, fullText, webSources);
pushMessage('assistant', fullText, [], webSources);
setSendStop(false);
}
function stopStreaming() {
if (state.abortController) state.abortController.abort();
state.streaming = false;
setSendStop(false);
}
function setSendStop(isStreaming) {
state.streaming = isStreaming;
const btn = document.getElementById('sendBtn');
const icon = document.getElementById('sendIcon');
if (isStreaming) {
btn.classList.add('stop'); btn.title = 'Stop';
icon.innerHTML = '<rect x="6" y="6" width="12" height="12" rx="2" fill="currentColor"/>';
} else {
btn.classList.remove('stop'); btn.title = 'Send';
icon.innerHTML = '<line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/>';
}
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
FRIENDLIES MODE
βββββββββββββββββββββββββββββββββββββββββββββββ */
let friendliesModeActive = false;
document.getElementById('friendliesToggleBtn').onclick = toggleFriendliesMode;
function toggleFriendliesMode() {
friendliesModeActive = !friendliesModeActive;
const btn = document.getElementById('friendliesToggleBtn');
btn.classList.toggle('active', friendliesModeActive);
const footer = document.getElementById('composerFooter');
if (friendliesModeActive) {
footer.innerHTML = `
<div class="friendlies-mode-indicator">
<svg width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 00-3-3.87"/><path d="M16 3.13a4 4 0 010 7.75"/></svg>
Friendlies Mode Active
</div>
<div class="composer-spacer"></div>
<button class="picker-btn btn-purple" onclick="openFriendliesModal()" style="background:rgba(123,94,167,0.15);border-color:rgba(123,94,167,0.3);color:#a78bcc;">
<svg width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-2 2 2 2 0 01-2-2v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83 0 2 2 0 010-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 01-2-2 2 2 0 012-2h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 010-2.83 2 2 0 012.83 0l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 012-2 2 2 0 012 2v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 0 2 2 0 010 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 012 2 2 2 0 01-2 2h-.09a1.65 1.65 0 00-1.51 1z"/></svg>
Manage Agents
</button>
`;
document.getElementById('promptInput').placeholder = 'Describe your project, problem, or goal for the Friendlies teamβ¦';
} else {
buildComposerFooter();
document.getElementById('promptInput').placeholder = 'Message KirkAIβ¦';
}
}
function buildComposerFooter() {
const footer = document.getElementById('composerFooter');
footer.innerHTML = `
<button class="picker-btn" id="modelBtn" onclick="openModelPicker(event)">
<span class="dot"></span>
<span id="modelBtnLabel">${escHtml(getModelLabel(state.selectedModel))}</span>
<svg width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><polyline points="6 9 12 15 18 9"/></svg>
</button>
<button class="picker-btn" id="modeBtn" onclick="openModePicker(event)">
<svg width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"/></svg>
<span id="modeBtnLabel">${escHtml(MODES.find(m => m.id === state.selectedMode)?.name || 'Default')}</span>
<svg width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><polyline points="6 9 12 15 18 9"/></svg>
</button>
<div class="composer-spacer"></div>
<span style="font-size:11.5px;color:var(--text-dim);">Press <kbd style="background:rgba(255,255,255,0.07);padding:1px 5px;border-radius:4px;font-size:11px;">Enter</kbd> to send Β· <kbd style="background:rgba(255,255,255,0.07);padding:1px 5px;border-radius:4px;font-size:11px;">Shift+Enter</kbd> for newline</span>
`;
}
function getModelLabel(id) {
const m = MODELS.find(m => m.id === id);
return m ? m.name : id;
}
/* ββ Friendlies Cycle ββ */
async function runFriendliesCycle(userPrompt) {
const input = document.getElementById('promptInput');
input.value = ''; autoResizeTextarea();
const isNewChat = !state.currentId;
ensureCurrentConv(userPrompt);
const messages = document.getElementById('messages');
if (isNewChat && messages) {
messages.innerHTML = '';
}
showMessages();
// User message bubble
pushMessage('user', userPrompt, []);
appendMessageDOM('user', userPrompt, []);
// Progress container
const progressRow = document.createElement('div');
progressRow.style.cssText = 'padding: 0 24px;';
progressRow.id = 'friendliesProgressRow';
messages.appendChild(progressRow);
messages.scrollTop = messages.scrollHeight;
const agents = getFriendlies();
const CYCLES = 3;
const totalCalls = agents.length * CYCLES;
const allOutputs = {}; // agentId β [cycle1, cycle2, cycle3]
for (const a of agents) allOutputs[a.id] = [];
function renderProgress(cycleNum, agentIdx, agentName, done) {
const pct = done ? 100 : Math.round(((cycleNum * agents.length + agentIdx) / totalCalls) * 100);
progressRow.innerHTML = `
<div id="friendliesProgress">
<div class="fp-agents">
${agents.map((a,i) => `
<div class="fp-agent-dot">
<div class="fp-agent-bubble ${!done && i === agentIdx ? 'thinking' : (done ? 'done' : '')}"
style="background:${a.color};color:#fff;">
${a.name[0]}
</div>
<span class="fp-agent-name">${escHtml(a.name)}</span>
</div>`).join('')}
</div>
<div class="fp-cycle-ring"></div>
<div class="fp-status">Cycle ${cycleNum + 1}/${CYCLES} β ${escHtml(agentName)} thinkingβ¦</div>
<div class="fp-subtext">${pct}% complete Β· ${totalCalls - (cycleNum * agents.length + agentIdx)} calls remaining</div>
<div class="fp-progress-bar-wrap"><div class="fp-progress-bar" style="width:${pct}%"></div></div>
</div>
`;
messages.scrollTop = messages.scrollHeight;
}
// Run 3 full cycles
for (let cycle = 0; cycle < CYCLES; cycle++) {
for (let ai = 0; ai < agents.length; ai++) {
const agent = agents[ai];
renderProgress(cycle, ai, agent.name, false);
// Build context messages for this agent
const contextParts = [];
// System prompt
contextParts.push({ role: 'system', content: agent.systemPrompt });
// User's original prompt
contextParts.push({ role: 'user', content: `Here is the project/task:\n\n${userPrompt}` });
// Previous cycle outputs from all agents
if (cycle > 0 || ai > 0) {
let priorContext = '\n\n--- Prior collaborative work so far ---\n';
for (const a of agents) {
const outputs = allOutputs[a.id];
for (let c = 0; c < outputs.length; c++) {
if (c < cycle || (c === cycle && agents.indexOf(a) < ai)) {
priorContext += `\n[${a.name} β ${a.role}, Cycle ${c+1}]:\n${outputs[c]}\n`;
}
}
}
contextParts.push({ role: 'assistant', content: 'I understand the context. Let me continue.' });
contextParts.push({ role: 'user', content: priorContext + '\n\nNow provide your Cycle ' + (cycle + 1) + ' contribution as ' + agent.name + ':' });
}
try {
const payload = {
model: state.selectedModel,
messages: contextParts,
stream: false,
web_search: state.webSearch,
agents_md: state.agentsMd.enabled ? state.agentsMd.content : undefined
};
if (state.settings.apiKey) payload.custom_api_key = state.settings.apiKey;
const resp = await fetch(API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const data = await resp.json();
if (!resp.ok) throw new Error(data.error || `HTTP ${resp.status}`);
const output = data.choices?.[0]?.message?.content || '(no response)';
allOutputs[agent.id].push(output);
} catch(e) {
allOutputs[agent.id].push(`Error: ${e.message}`);
}
}
}
// Now get final product from each agent (streaming would be complex here, using non-stream)
renderProgress(CYCLES - 1, agents.length - 1, 'Synthesizingβ¦', false);
progressRow.innerHTML = `<div id="friendliesProgress"><div class="fp-cycle-ring" style="border-top-color:#DC143C;"></div><div class="fp-status">Generating final outputsβ¦</div></div>`;
const finalOutputs = {};
for (const agent of agents) {
const contextParts = [
{ role: 'system', content: agent.systemPrompt + '\n\nYou are now producing your FINAL output β the definitive best version of your work, synthesizing everything discussed.' },
{ role: 'user', content: `Original task:\n\n${userPrompt}` },
{ role: 'assistant', content: 'Here is all our collaborative work:' },
{ role: 'user', content: agents.map(a => allOutputs[a.id].map((o,ci) => `[${a.name} β Cycle ${ci+1}]:\n${o}`).join('\n\n')).join('\n\n---\n\n') + '\n\nNow produce your best final output as ' + agent.name + ':' }
];
try {
const payload = {
model: state.selectedModel,
messages: contextParts,
stream: false,
web_search: state.webSearch,
agents_md: state.agentsMd.enabled ? state.agentsMd.content : undefined
};
if (state.settings.apiKey) payload.custom_api_key = state.settings.apiKey;
const resp = await fetch(API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const data = await resp.json();
if (!resp.ok) throw new Error(data.error || `HTTP ${resp.status}`);
finalOutputs[agent.id] = data.choices?.[0]?.message?.content || '(no response)';
} catch(e) {
finalOutputs[agent.id] = `Error: ${e.message}`;
}
}
// Replace progress with results
progressRow.remove();
const resultsEl = document.createElement('div');
resultsEl.id = 'friendliesResults';
resultsEl.innerHTML = `
<div class="friendlies-results-header">
<h2>β¨ Friendlies Final Output</h2>
<p>3 cycles Γ ${agents.length} agents = ${totalCalls} collaborative exchanges</p>
<div style="margin-top:10px;display:flex;gap:8px;justify-content:center;">
<button class="btn btn-secondary" onclick="exportFriendliesToAgentsMd()" style="font-size:12px;padding:5px 12px;background:rgba(255,255,255,0.08);border-color:rgba(255,255,255,0.15);color:#fff;">
π Export Plan as AGENTS.md
</button>
</div>
</div>
<div class="friendlies-cards-grid">
${agents.map(agent => `
<div class="friendlies-result-card">
<div class="fr-card-head" style="border-bottom-color:${agent.color}22;">
<div class="fr-card-avatar" style="background:${agent.color};">${agent.name[0]}</div>
<div>
<div class="fr-card-name">${escHtml(agent.name)}</div>
<div class="fr-card-role">${escHtml(agent.role)}</div>
</div>
</div>
<div class="fr-card-body">
<div class="fr-card-output md-body">${renderMarkdown(finalOutputs[agent.id] || '')}</div>
<details class="fr-card-thought">
<summary>Thought Process (${CYCLES} cycles)</summary>
${allOutputs[agent.id].map((out, ci) => `
<div class="fr-cycle-entry">
<div class="fr-cycle-label">Cycle ${ci+1}</div>
<div class="fr-cycle-text">${escHtml(out)}</div>
</div>
`).join('')}
</details>
</div>
</div>
`).join('')}
</div>
`;
messages.appendChild(resultsEl);
messages.scrollTop = messages.scrollHeight;
// Save to conversation
const resultSummary = agents.map(a => `**${a.name} (${a.role}):**\n${finalOutputs[a.id]}`).join('\n\n---\n\n');
pushMessage('assistant', `[Friendlies Result β ${agents.length} agents, 3 cycles]\n\n${resultSummary}`, []);
}
/* ββ Friendlies Modal ββ */
function openFriendliesModal() {
renderAgentsList();
openModal('friendliesModal');
}
function renderAgentsList() {
const list = document.getElementById('agentsList');
const agents = getFriendlies();
list.innerHTML = '';
agents.forEach((agent, idx) => {
const card = document.createElement('div');
card.className = 'agent-card';
card.draggable = true;
card.dataset.idx = idx;
card.innerHTML = `
<span class="drag-handle" title="Drag to reorder">β Ώ</span>
<div class="agent-card-avatar" style="background:${agent.color};">${agent.name[0]}</div>
<div class="agent-card-info">
<div class="agent-card-name">${escHtml(agent.name)}</div>
<div class="agent-card-role">${escHtml(agent.role)}${agent.isDefault ? ' Β· <em style="color:var(--text-dim);font-size:11px;font-style:normal;">Default</em>' : ''}</div>
</div>
<div class="agent-card-actions">
<button class="btn btn-secondary" style="padding:6px 12px;font-size:12px;" onclick="openEditAgent(${idx})">Edit</button>
${!agent.isDefault ? `<button class="btn btn-danger" style="padding:6px 12px;font-size:12px;" onclick="deleteAgent(${idx})">Delete</button>` : ''}
</div>
`;
setupDragHandles(card, idx);
list.appendChild(card);
});
}
let dragSrcIdx = null;
function setupDragHandles(card, idx) {
card.addEventListener('dragstart', () => { dragSrcIdx = idx; card.style.opacity = '0.5'; });
card.addEventListener('dragend', () => { card.style.opacity = '1'; });
card.addEventListener('dragover', e => { e.preventDefault(); card.style.background = 'rgba(123,94,167,0.1)'; });
card.addEventListener('dragleave', () => { card.style.background = ''; });
card.addEventListener('drop', e => {
e.preventDefault(); card.style.background = '';
if (dragSrcIdx === null || dragSrcIdx === idx) return;
const agents = getFriendlies();
const [moved] = agents.splice(dragSrcIdx, 1);
agents.splice(idx, 0, moved);
saveFriendlies(agents);
renderAgentsList();
dragSrcIdx = null;
});
}
let editingAgentIdx = null;
let isAddingAgent = false;
function openEditAgent(idx) {
editingAgentIdx = idx;
isAddingAgent = false;
const agents = getFriendlies();
const agent = agents[idx];
document.getElementById('agentFormTitle').textContent = 'Edit Agent';
document.getElementById('agentName').value = agent.name;
document.getElementById('agentRole').value = agent.role;
document.getElementById('agentColor').value = agent.color;
document.getElementById('agentSystemPrompt').value = agent.systemPrompt;
updateColorPreview();
document.getElementById('agentEditForm').style.display = 'block';
}
function openAddAgentForm() {
editingAgentIdx = null;
isAddingAgent = true;
document.getElementById('agentFormTitle').textContent = 'Add New Agent';
document.getElementById('agentName').value = '';
document.getElementById('agentRole').value = '';
document.getElementById('agentColor').value = '#4CAF50';
document.getElementById('agentSystemPrompt').value = '';
updateColorPreview();
document.getElementById('agentEditForm').style.display = 'block';
}
function updateColorPreview() {
const color = document.getElementById('agentColor').value;
document.getElementById('colorPreview').style.background = color;
}
function cancelAgentEdit() {
document.getElementById('agentEditForm').style.display = 'none';
}
function saveAgent() {
const name = document.getElementById('agentName').value.trim();
const role = document.getElementById('agentRole').value.trim();
const color = document.getElementById('agentColor').value;
const systemPrompt = document.getElementById('agentSystemPrompt').value.trim();
if (!name || !role || !systemPrompt) { showToast('Please fill in all fields', 'error'); return; }
const agents = getFriendlies();
if (isAddingAgent) {
agents.push({ id: 'custom_' + genId(), name, role, color, systemPrompt, isDefault: false });
showToast('Agent added!', 'success');
} else if (editingAgentIdx !== null) {
const agent = agents[editingAgentIdx];
agent.name = name; agent.role = role; agent.color = color; agent.systemPrompt = systemPrompt;
showToast('Agent updated!', 'success');
}
saveFriendlies(agents);
renderAgentsList();
document.getElementById('agentEditForm').style.display = 'none';
}
function deleteAgent(idx) {
const agents = getFriendlies();
agents.splice(idx, 1);
saveFriendlies(agents);
renderAgentsList();
showToast('Agent deleted');
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
MODEL PICKER
βββββββββββββββββββββββββββββββββββββββββββββββ */
function buildModelPicker() {
const list = document.getElementById('modelPickerList');
list.innerHTML = '';
for (const m of MODELS) {
const isSelected = m.id === state.selectedModel;
const item = document.createElement('div');
item.className = 'picker-version' + (isSelected ? ' selected' : '');
item.style.padding = '10px 14px';
item.style.borderRadius = '8px';
item.style.cursor = 'pointer';
item.style.marginBottom = '6px';
item.style.transition = 'all 0.15s ease';
item.style.display = 'flex';
item.style.flexDirection = 'column';
item.style.gap = '3px';
item.style.background = isSelected ? 'rgba(220,20,60,0.18)' : 'rgba(255,255,255,0.03)';
item.style.border = isSelected ? '1px solid rgba(220,20,60,0.45)' : '1px solid rgba(255,255,255,0.06)';
item.onclick = () => selectModel(m.id, m.name);
item.innerHTML = `
<div>
<span class="picker-version-label" style="font-weight:600;font-size:13.5px;color:#fff;">${escHtml(m.name)}</span>
</div>
<div class="picker-family-desc" style="font-size:12px;color:var(--text-sub);line-height:1.4;">${escHtml(m.desc)}</div>
`;
list.appendChild(item);
}
}
function openModelPicker(e) {
e.stopPropagation();
closeAllPickersMenus();
buildModelPicker();
const popup = document.getElementById('modelPickerPopup');
popup.classList.add('open');
positionPopup(popup, e.currentTarget);
}
function selectModel(id, label) {
state.selectedModel = id;
localStorage.setItem('kirk_last_model', id);
const lbl = document.getElementById('modelBtnLabel');
if (lbl) lbl.textContent = label;
updatePickerLabels();
closeAllPickersMenus();
const conv = getCurrentConv();
if (conv) { conv.model = id; saveConversations(); }
}
function buildModePicker() {
const list = document.getElementById('modePickerList');
list.innerHTML = '';
for (const mode of MODES) {
const item = document.createElement('div');
item.className = 'mode-picker-item' + (mode.id === state.selectedMode ? ' selected' : '');
item.innerHTML = `<div class="mode-picker-item-name">${escHtml(mode.name)}</div><div class="mode-picker-item-meta">${escHtml(mode.meta)}</div>`;
item.onclick = () => selectMode(mode.id, mode.name);
list.appendChild(item);
}
}
function openModePicker(e) {
e.stopPropagation();
closeAllPickersMenus();
buildModePicker();
const popup = document.getElementById('modePickerPopup');
popup.classList.add('open');
positionPopup(popup, e.currentTarget);
}
function selectMode(id, name) {
state.selectedMode = id;
localStorage.setItem('kirk_last_mode', id);
const lbl = document.getElementById('modeBtnLabel');
if (lbl) lbl.textContent = name;
updatePickerLabels();
closeAllPickersMenus();
const conv = getCurrentConv();
if (conv) { conv.mode = id; saveConversations(); }
}
function updatePickerLabels() {
const modelLbl = document.getElementById('modelBtnLabel');
if (modelLbl) modelLbl.textContent = getModelLabel(state.selectedModel);
const modeLbl = document.getElementById('modeBtnLabel');
const modeObj = MODES.find(m => m.id === state.selectedMode);
if (modeLbl && modeObj) modeLbl.textContent = modeObj.name;
}
function positionPopup(popup, anchor) {
const rect = anchor.getBoundingClientRect();
const pW = popup.offsetWidth || 300;
let left = rect.left;
let top = rect.bottom + 6;
if (left + pW > window.innerWidth - 10) left = window.innerWidth - pW - 10;
if (top + 400 > window.innerHeight) top = rect.top - Math.min(400, top + 400 - window.innerHeight) - 6;
popup.style.left = left + 'px';
popup.style.top = top + 'px';
}
document.addEventListener('click', () => closeAllPickersMenus());
function closeAllPickersMenus() {
document.getElementById('modelPickerPopup').classList.remove('open');
document.getElementById('modePickerPopup').classList.remove('open');
document.getElementById('chatMenu').classList.remove('open');
}
/* Model / Mode buttons click */
document.getElementById('modelBtn').onclick = openModelPicker;
document.getElementById('modeBtn').onclick = openModePicker;
document.getElementById('modelPickerPopup').onclick = e => e.stopPropagation();
document.getElementById('modePickerPopup').onclick = e => e.stopPropagation();
/* βββββββββββββββββββββββββββββββββββββββββββββββ
CHAT MENU
βββββββββββββββββββββββββββββββββββββββββββββββ */
document.getElementById('chatMenuBtn').onclick = function(e) {
e.stopPropagation();
closeAllPickersMenus();
const menu = document.getElementById('chatMenu');
menu.classList.add('open');
const rect = this.getBoundingClientRect();
menu.style.right = (window.innerWidth - rect.right) + 'px';
menu.style.top = (rect.bottom + 6) + 'px';
menu.style.left = 'auto';
};
document.getElementById('chatMenu').onclick = e => e.stopPropagation();
function closeChatMenu() { document.getElementById('chatMenu').classList.remove('open'); }
/* βββββββββββββββββββββββββββββββββββββββββββββββ
EXPORT / CLEAR
βββββββββββββββββββββββββββββββββββββββββββββββ */
function exportCurrentChat() {
const conv = getCurrentConv();
if (!conv || !conv.messages.length) { showToast('No messages to export', 'error'); return; }
const text = conv.messages.map(m => `[${m.role.toUpperCase()}]\n${m.content}`).join('\n\n---\n\n');
downloadText(text, (conv.title || 'chat') + '.txt');
showToast('Chat exported!', 'success');
}
function copyCurrentChat() {
const conv = getCurrentConv();
if (!conv || !conv.messages.length) { showToast('No messages', 'error'); return; }
const text = conv.messages.map(m => `${m.role.toUpperCase()}: ${m.content}`).join('\n\n');
navigator.clipboard.writeText(text).then(() => showToast('Copied!', 'success'));
}
function clearCurrentChat() {
if (!state.currentId) {
newChat();
return;
}
const idToDelete = state.currentId;
state.conversations = state.conversations.filter(c => c.id !== idToDelete);
state.currentId = null;
saveConversations();
const msgContainer = document.getElementById('messages');
if (msgContainer) msgContainer.innerHTML = '';
newChat();
renderHistory();
showToast('Chat fully cleared from browser', 'success');
}
function exportAllChats() {
if (!state.conversations.length) { showToast('No chats to export', 'error'); return; }
const zip = new JSZip();
for (const conv of state.conversations) {
const text = conv.messages.map(m => `[${m.role.toUpperCase()}]\n${m.content}`).join('\n\n---\n\n');
zip.file((conv.title || conv.id) + '.txt', text);
}
zip.generateAsync({ type: 'blob' }).then(blob => {
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'kirkai_chats.zip';
a.click();
showToast('All chats exported!', 'success');
});
}
function clearAllChats() {
if (!confirm('Clear ALL chat history? This will permanently wipe all conversation data from your browser.')) return;
state.conversations = [];
state.currentId = null;
try {
localStorage.removeItem('kirk_conversations_v2');
localStorage.removeItem('kirk_conversations');
localStorage.removeItem('kirk_last_conversation');
} catch(e) {}
saveConversations();
const msgContainer = document.getElementById('messages');
if (msgContainer) msgContainer.innerHTML = '';
newChat();
renderHistory();
showToast('All chats permanently wiped from browser', 'success');
}
function downloadText(text, filename) {
const a = document.createElement('a');
a.href = URL.createObjectURL(new Blob([text], { type: 'text/plain' }));
a.download = filename; a.click();
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
SETTINGS TOGGLES
βββββββββββββββββββββββββββββββββββββββββββββββ */
function toggleBgAnim(el) {
el.classList.toggle('on');
state.settings.bgAnim = el.classList.contains('on');
saveSettings();
if (state.settings.bgAnim) { window._bgAnim?.start(); document.getElementById('bgCanvas').style.opacity = '0.35'; }
else { window._bgAnim?.stop(); document.getElementById('bgCanvas').style.opacity = '0'; }
}
function toggleCompact(el) {
el.classList.toggle('on');
state.settings.compact = el.classList.contains('on');
saveSettings();
document.body.style.setProperty('--msg-pad', state.settings.compact ? '2px' : '4px');
}
function toggleEnterSend(el) {
el.classList.toggle('on');
state.settings.enterSend = el.classList.contains('on');
saveSettings();
}
/* βββββββββββββββββββββββββββββββββββββββββββββββ
TEXTAREA AUTO-RESIZE
βββββββββββββββββββββββββββββββββββββββββββββββ */
const promptInput = document.getElementById('promptInput');
function autoResizeTextarea() {
promptInput.style.height = 'auto';
promptInput.style.height = Math.min(promptInput.scrollHeight, 200) + 'px';
}
promptInput.addEventListener('input', autoResizeTextarea);
promptInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
const enterSend = state.settings.enterSend;
if (enterSend && !e.shiftKey) { e.preventDefault(); handleSend(); }
else if (!enterSend && e.shiftKey) { e.preventDefault(); handleSend(); }
}
});
let lastWindowEsc = 0;
window.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
if (state.generating) {
e.preventDefault();
if (state.abortController) state.abortController.abort();
setGenerating(false);
return;
}
const now = Date.now();
if (now - lastWindowEsc < 500) {
e.preventDefault();
newChat();
lastWindowEsc = 0;
} else {
lastWindowEsc = now;
if (document.activeElement === promptInput && promptInput.value) {
promptInput.value = '';
autoResizeTextarea();
}
}
}
});
/* βββββββββββββββββββββββββββββββββββββββββββββββ
NEW CHAT
βββββββββββββββββββββββββββββββββββββββββββββββ */
document.getElementById('newChatBtn').onclick = newChat;
/* βββββββββββββββββββββββββββββββββββββββββββββββ
INIT
βββββββββββββββββββββββββββββββββββββββββββββββ */
loadState();
renderHistory();
updatePickerLabels();
updateWebSearchUI();
applySettingsUI();
if (!state.settings.bgAnim) {
window._bgAnim?.stop();
document.getElementById('bgCanvas').style.opacity = '0';
}
// Always start in a fresh, clean conversation session
newChat();
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>KirkAI β Free AI for Everyone</title>
<meta name="description" content="KirkAI is a completely free AI chat β no login required. Access every model instantly."/>
<link rel="icon" href="https://iili.io/CxhPxMG.jpg" type="image/jpeg"/>
<!-- Fonts -->
<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=Figtree:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,400&family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet"/>
<!-- Highlight.js -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<!-- JSZip -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<style>
/* ββ Reset & Base ββ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0a0a0b;
--bg2: #111114;
--bg3: #18181c;
--glass: rgba(255,255,255,0.04);
--glass-border: rgba(255,255,255,0.08);
--glass-hover: rgba(255,255,255,0.07);
--accent: #DC143C;
--accent-dim: rgba(220,20,60,0.15);
--accent-glow: rgba(220,20,60,0.3);
--text: #f0f0f2;
--text-sub: #8b8b9a;
--text-dim: #5a5a6a;
--radius: 12px;
--sidebar-w: 280px;
--topbar-h: 60px;
--composer-h: auto;
--font: 'Figtree', system-ui, sans-serif;
--mono: 'JetBrains Mono', 'Fira Code', monospace;
--transition: 0.18s ease;
}
html, body { height: 100%; overflow: hidden; }
body {
font-family: var(--font);
background: var(--bg);
color: var(--text);
line-height: 1.6;
-webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
textarea { font-family: var(--font); resize: none; }
input, textarea, select { outline: none; }
::selection { background: var(--accent-dim); }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
/* ββ Canvas BG ββ */
#bgCanvas {
position: fixed; inset: 0; z-index: 0;
pointer-events: none; opacity: 0.35;
}
/* ββ App Shell ββ */
#app {
position: relative; z-index: 1;
display: flex; height: 100vh; overflow: hidden;
}
/* ββ Sidebar ββ */
#sidebar {
width: var(--sidebar-w);
background: rgba(10,10,11,0.95);
border-right: 1px solid var(--glass-border);
display: flex; flex-direction: column;
transition: transform var(--transition);
z-index: 100; flex-shrink: 0;
backdrop-filter: blur(20px);
}
#sidebar.collapsed {
transform: translateX(calc(-1 * var(--sidebar-w)));
position: absolute; top: 0; left: 0; bottom: 0;
}
.sidebar-head {
padding: 16px;
border-bottom: 1px solid var(--glass-border);
display: flex; align-items: center; gap: 10px;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; flex: 1; }
.sidebar-logo img { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; }
.sidebar-logo-text { font-weight: 700; font-size: 16px; letter-spacing: -0.3px; }
.sidebar-logo-text span { color: var(--accent); }
#newChatBtn {
display: flex; align-items: center; gap: 8px;