akvo-rag-js 1.2.3 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -9
- package/dist/akvo-rag.css +1 -1
- package/dist/akvo-rag.js +2 -1
- package/dist/akvo-rag.js.LICENSE.txt +1 -0
- package/dist/index.html +815 -13
- package/package.json +1 -2
package/dist/index.html
CHANGED
|
@@ -1,13 +1,815 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
<!doctype html><html class="h-full bg-[#FAFAFA] text-[#09090B]" lang="en"><head><meta charset="utf-8"/><meta content="width=device-width,initial-scale=1" name="viewport"/><title>akvo-rag-js / Workbench - Integration Playground</title><link href="https://fonts.googleapis.com" rel="preconnect"/><link crossorigin="" href="https://fonts.gstatic.com" rel="preconnect"/><link href="https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet"/><script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script><link rel="stylesheet" href="akvo-rag.css"/><script src="akvo-rag.js"></script><script>tailwind.config = {
|
|
2
|
+
darkMode: 'class',
|
|
3
|
+
theme: {
|
|
4
|
+
extend: {
|
|
5
|
+
fontFamily: {
|
|
6
|
+
sans: ['Geist', '-apple-system', 'BlinkMacSystemFont', 'Segoe UI', 'Roboto', 'sans-serif'],
|
|
7
|
+
mono: ['"JetBrains Mono"', 'monospace'],
|
|
8
|
+
},
|
|
9
|
+
colors: {
|
|
10
|
+
brand: {
|
|
11
|
+
teal: '#007A78',
|
|
12
|
+
'teal-dark': '#005D5B',
|
|
13
|
+
'teal-light': '#E6F3F2',
|
|
14
|
+
},
|
|
15
|
+
surface: {
|
|
16
|
+
DEFAULT: '#FFFFFF',
|
|
17
|
+
muted: '#F4F4F5',
|
|
18
|
+
subtle: '#FAFAFA',
|
|
19
|
+
dark: '#111113',
|
|
20
|
+
},
|
|
21
|
+
border: {
|
|
22
|
+
DEFAULT: '#E4E4E7',
|
|
23
|
+
strong: '#D4D4D8',
|
|
24
|
+
subtle: '#F0F0F2',
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
boxShadow: {
|
|
28
|
+
'subtle': '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
|
|
29
|
+
'card': '0 1px 3px 0 rgba(0, 0, 0, 0.03), 0 1px 2px -1px rgba(0, 0, 0, 0.03)',
|
|
30
|
+
'elevation': '0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04)',
|
|
31
|
+
'fab': '0 8px 24px -4px rgba(0, 122, 120, 0.35)',
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}</script><style data-purpose="custom-scrollbars">::-webkit-scrollbar {
|
|
36
|
+
width: 6px;
|
|
37
|
+
height: 6px;
|
|
38
|
+
}
|
|
39
|
+
::-webkit-scrollbar-track {
|
|
40
|
+
background: transparent;
|
|
41
|
+
}
|
|
42
|
+
::-webkit-scrollbar-thumb {
|
|
43
|
+
background: #D4D4D8;
|
|
44
|
+
border-radius: 9999px;
|
|
45
|
+
}
|
|
46
|
+
::-webkit-scrollbar-thumb:hover {
|
|
47
|
+
background: #A1A1AA;
|
|
48
|
+
}</style><style data-purpose="code-syntax-tokens">.tok-kw { color: #F43F5E; } /* pink-500 keywords */
|
|
49
|
+
.tok-fn { color: #38BDF8; } /* sky-400 function names */
|
|
50
|
+
.tok-str { color: #34D399; } /* emerald-400 strings */
|
|
51
|
+
.tok-prop { color: #E2E8F0; } /* slate-200 properties */
|
|
52
|
+
.tok-bool { color: #F59E0B; } /* amber-500 booleans */
|
|
53
|
+
.tok-num { color: #A78BFA; } /* violet-400 numbers */
|
|
54
|
+
.tok-com { color: #64748B; font-style: italic; } /* slate-500 comments */
|
|
55
|
+
.tok-punc { color: #94A3B8; } /* slate-400 punctuation */</style><script defer="defer" src="akvo-rag.js"></script><link href="akvo-rag.css" rel="stylesheet"></head><body class="min-h-screen bg-[#F8F9FA] text-[#09090B] font-sans antialiased selection:bg-[#007A78]/15 selection:text-[#005D5B]"><header class="sticky top-0 z-40 bg-white/95 backdrop-blur border-b border-border" data-purpose="top-navigation-bar"><div class="max-w-[1536px] mx-auto px-4 sm:px-6 lg:px-8 h-14 flex items-center justify-between gap-4"><div class="flex items-center gap-3"><div class="w-8 h-8 rounded-lg bg-neutral-900 text-white flex items-center justify-center font-mono font-bold text-xs tracking-wider border border-neutral-700 shadow-sm">AR</div><nav aria-label="Breadcrumb" class="flex items-center space-x-2 text-sm"><a class="font-semibold text-neutral-900 hover:text-black tracking-tight font-mono" href="#">akvo-rag-js</a> <span class="text-neutral-400">/</span> <span class="font-medium text-neutral-600">Workbench</span></nav><div class="hidden sm:flex items-center gap-1.5 ml-2"><span class="inline-flex items-center px-2 py-0.5 rounded-full text-[11px] font-mono font-medium bg-emerald-50 text-emerald-700 border border-emerald-200/60">v1.2.4 </span><span class="inline-flex items-center px-1.5 py-0.5 rounded text-[11px] font-mono text-neutral-500 bg-neutral-100 border border-neutral-200">UMD + ESM </span><span class="inline-flex items-center px-1.5 py-0.5 rounded text-[11px] font-mono text-neutral-500 bg-neutral-100 border border-neutral-200">Node 18+</span></div></div><div class="flex items-center gap-2"><a class="inline-flex items-center gap-1.5 px-2.5 py-1.5 text-xs font-medium text-neutral-600 hover:text-neutral-900 hover:bg-neutral-100 rounded-md transition-colors" href="https://github.com/akvo/akvo-rag-js#readme" target="_blank" rel="noopener noreferrer"><svg class="w-4 h-4 text-neutral-400" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewbox="0 0 24 24"><path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1-2.5-2.5Z"></path><path d="M6 6h10"></path><path d="M6 10h10"></path></svg> Docs </a><a class="inline-flex items-center gap-1.5 px-2.5 py-1.5 text-xs font-medium text-neutral-600 hover:text-neutral-900 hover:bg-neutral-100 rounded-md transition-colors" href="https://github.com/akvo/akvo-rag-js" target="_blank" rel="noopener noreferrer"><svg class="w-4 h-4 text-neutral-400" fill="currentColor" viewbox="0 0 24 24"><path clip-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.53 1.032 1.53 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" fill-rule="evenodd"></path></svg> Repository</a><div class="h-4 w-[1px] bg-neutral-200 mx-1"></div><button id="btnResetConfig" class="inline-flex items-center gap-1 px-3 py-1.5 text-xs font-semibold text-neutral-700 bg-neutral-100 hover:bg-neutral-200 border border-neutral-300 rounded-md transition-all shadow-xs" type="button"><svg class="w-3.5 h-3.5 text-neutral-500" fill="none" stroke="currentColor" stroke-width="2" viewbox="0 0 24 24"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"></path><path d="M3 3v5h5"></path></svg> Reset</button></div></div></header><main class="max-w-[1536px] mx-auto px-4 sm:px-6 lg:px-8 py-7" data-purpose="workbench-workspace"><div class="mb-6 flex flex-col md:flex-row md:items-center md:justify-between gap-3"><div><h1 class="text-xl font-bold tracking-tight text-neutral-900 flex items-center gap-2">RAG Integration Harness <span class="inline-flex items-center gap-1.5 text-xs font-medium px-2 py-0.5 rounded-full bg-emerald-50 text-emerald-700 border border-emerald-200"><span class="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"></span> Mounted & Active</span></h1><p class="text-xs text-neutral-500 mt-1 max-w-2xl leading-relaxed">Interactive client-side harness for testing launcher positioning, runtime CSS custom properties, reactive DOM lifecycle hooks, and tokenized chatbox embedding.</p></div><div class="flex items-center gap-2 self-start md:self-auto"><span class="text-xs font-mono text-neutral-400">Target: DOM-Window</span> <button class="text-xs font-medium px-2.5 py-1.5 bg-white border border-neutral-200 rounded-md text-neutral-700 hover:bg-neutral-50 shadow-xs flex items-center gap-1.5" id="togglePreviewViewBtn" type="button"><svg class="w-3.5 h-3.5 text-neutral-400" fill="none" stroke="currentColor" stroke-width="2" viewbox="0 0 24 24"><rect height="18" rx="2" width="18" x="3" y="3"></rect><path d="M9 3v18"></path></svg> Layout View</button></div></div><div id="workspaceGrid" class="grid grid-cols-1 lg:grid-cols-12 gap-6 items-start"><section class="lg:col-span-5 bg-white border border-border rounded-xl shadow-card flex flex-col overflow-hidden" data-purpose="configuration-inspector"><div class="px-5 py-3.5 border-b border-border bg-neutral-50/50 flex items-center justify-between"><div class="flex items-center gap-2"><svg class="w-4 h-4 text-neutral-500" fill="none" stroke="currentColor" stroke-width="2" viewbox="0 0 24 24"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"></path><circle cx="12" cy="12" r="3"></circle></svg><h2 class="text-xs font-semibold tracking-wider uppercase text-neutral-800 font-mono">Configuration Inspector</h2></div><span class="text-[11px] font-mono text-neutral-400">client_options</span></div><div class="p-5 space-y-6 divide-y divide-neutral-100 max-h-[calc(100vh-210px)] overflow-y-auto"><div class="space-y-3 pt-1"><div class="flex items-center justify-between"><label class="text-xs font-semibold uppercase tracking-wider text-neutral-700">Display Mode</label> <code class="text-[11px] font-mono text-neutral-400 bg-neutral-100 px-1.5 py-0.5 rounded">options.showLauncher</code></div><div class="grid grid-cols-2 p-1 bg-neutral-100/90 border border-neutral-200/80 rounded-lg gap-1" role="radiogroup"><button aria-checked="true" class="px-3 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 font-sans flex items-center justify-center gap-1.5" id="btnDisplayFab" type="button"><svg class="w-3.5 h-3.5 text-emerald-600" fill="none" stroke="currentColor" stroke-width="2.5" viewbox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg> Circular FAB <span class="text-[10px] text-neutral-400">(Modern)</span></button> <button aria-checked="false" class="px-3 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all font-sans flex items-center justify-center gap-1.5" id="btnDisplayEmbedded" type="button">Embedded Box <span class="text-[10px] text-neutral-400">(Legacy)</span></button></div><p class="text-[11px] text-neutral-500 leading-normal">Circular FAB renders a persistent 56×56px floating trigger at the viewport edge. Embedded mounts a direct 360×500px container inside host markup.</p></div><div id="startStateContainer" class="space-y-3 pt-5"><div class="flex items-center justify-between"><label class="text-xs font-semibold uppercase tracking-wider text-neutral-700">Initial Mount State</label> <code class="text-[11px] font-mono text-neutral-400 bg-neutral-100 px-1.5 py-0.5 rounded">options.startMinimized</code></div><div class="grid grid-cols-2 p-1 bg-neutral-100/90 border border-neutral-200/80 rounded-lg gap-1"><button class="px-3 py-1.5 text-xs font-mono font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5" id="btnMountMinTrue" type="button">startMinimized: true</button> <button class="px-3 py-1.5 text-xs font-mono font-medium rounded-md text-neutral-500 hover:text-neutral-900 transition-all" id="btnMountMinFalse" type="button">startMinimized: false</button></div><p class="text-[11px] text-neutral-500 leading-normal">When true, the chat engine mounts with the discreet launcher bubble; clicking expands the chat. When false, the full chatbox renders open immediately.</p></div><div class="space-y-3 pt-5" data-purpose="theme-token-selector"><div class="flex items-center justify-between"><label class="text-xs font-semibold uppercase tracking-wider text-neutral-700">Theme Token</label> <code class="text-[11px] font-mono text-teal-700 bg-teal-50 border border-teal-200/50 px-1.5 py-0.5 rounded">--akvo-primary</code></div><div class="flex items-center gap-2 flex-wrap"><button class="theme-swatch group relative w-8 h-8 rounded-lg bg-[#007A78] flex items-center justify-center ring-2 ring-neutral-900 ring-offset-2 transition-transform active:scale-95" data-color="#007A78" title="Default Teal (#007A78)" type="button"><svg class="w-4 h-4 text-white check-icon" fill="none" stroke="currentColor" stroke-width="3" viewbox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg></button> <button class="theme-swatch w-8 h-8 rounded-lg bg-[#0284C7] flex items-center justify-center ring-1 ring-black/10 hover:ring-2 hover:ring-neutral-400 ring-offset-1 transition-transform active:scale-95" data-color="#0284C7" title="Cyan 600 (#0284C7)" type="button"><svg class="w-4 h-4 text-white check-icon hidden" fill="none" stroke="currentColor" stroke-width="3" viewbox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg></button> <button class="theme-swatch w-8 h-8 rounded-lg bg-[#059669] flex items-center justify-center ring-1 ring-black/10 hover:ring-2 hover:ring-neutral-400 ring-offset-1 transition-transform active:scale-95" data-color="#059669" title="Emerald 600 (#059669)" type="button"><svg class="w-4 h-4 text-white check-icon hidden" fill="none" stroke="currentColor" stroke-width="3" viewbox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg></button> <button class="theme-swatch w-8 h-8 rounded-lg bg-[#D97706] flex items-center justify-center ring-1 ring-black/10 hover:ring-2 hover:ring-neutral-400 ring-offset-1 transition-transform active:scale-95" data-color="#D97706" title="Amber 600 (#D97706)" type="button"><svg class="w-4 h-4 text-white check-icon hidden" fill="none" stroke="currentColor" stroke-width="3" viewbox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg></button> <button class="theme-swatch w-8 h-8 rounded-lg bg-[#475569] flex items-center justify-center ring-1 ring-black/10 hover:ring-2 hover:ring-neutral-400 ring-offset-1 transition-transform active:scale-95" data-color="#475569" title="Slate 600 (#475569)" type="button"><svg class="w-4 h-4 text-white check-icon hidden" fill="none" stroke="currentColor" stroke-width="3" viewbox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg></button> <button class="theme-swatch w-8 h-8 rounded-lg bg-[#09090B] flex items-center justify-center ring-1 ring-black/10 hover:ring-2 hover:ring-neutral-400 ring-offset-1 transition-transform active:scale-95" data-color="#09090B" title="Zinc 950 (#09090B)" type="button"><svg class="w-4 h-4 text-white check-icon hidden" fill="none" stroke="currentColor" stroke-width="3" viewbox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg></button><div class="ml-auto flex items-center border border-neutral-300 rounded-lg overflow-hidden focus-within:border-neutral-800 transition-colors bg-white"><input class="w-7 h-7 p-0 border-0 cursor-pointer ml-1" id="nativeColorInput" type="color" value="#007A78"/> <span class="text-xs font-mono text-neutral-400 pl-1">#</span> <input class="w-20 border-0 text-xs font-mono py-1 px-1 text-neutral-800 uppercase focus:ring-0" id="hexTextInput" maxlength="6" value="007A78"/></div></div><p class="text-[11px] text-neutral-500 leading-normal">Dynamically cascades into FAB backdrop, active citations, inline copy-action highlights, and send button state.</p></div><div id="launcherIconContainer" class="space-y-3 pt-5"><div class="flex items-center justify-between"><label class="text-xs font-semibold uppercase tracking-wider text-neutral-700" for="selectLauncherIcon">Launcher Icon & Size</label> <code class="text-[11px] font-mono text-neutral-400 bg-neutral-100 px-1.5 py-0.5 rounded">options.launcherIcon</code></div><div class="relative"><select class="w-full text-xs font-medium rounded-lg border-neutral-300 py-2 pl-3 pr-8 text-neutral-800 bg-white hover:border-neutral-400 focus:border-neutral-900 focus:ring-1 focus:ring-neutral-900" id="selectLauncherIcon"><option selected="" value="bubble">Default Comment Bubble (FontAwesome)</option><option value="sparkle">Sparkle AI Intelligence (Inline SVG)</option><option value="robot">Assistant Bot Silhouette (Inline SVG)</option><option value="custom_url">External Asset URL (CDN image)</option></select></div><div><div class="flex items-center justify-between mb-1"><label class="text-[11px] font-medium text-neutral-600" for="selectLauncherSize">Button Size (FAB)</label> <code class="text-[10px] font-mono text-neutral-400">options.launcherSize</code></div><select class="w-full text-xs font-mono rounded-lg border-neutral-300 py-1.5 px-2 text-neutral-800 bg-white hover:border-neutral-400 focus:border-neutral-900" id="selectLauncherSize"><option value="48px">48×48px (Compact)</option><option selected="selected" value="56px">56×56px (Standard FAB)</option><option value="64px">64×64px (Large)</option></select></div><p class="text-[11px] text-neutral-400">Supports DOMPurified SVG markup, image URLs (.svg/.png), and custom button dimensions.</p></div><div class="space-y-4 pt-5"><div><div class="flex items-center justify-between mb-1.5"><label class="text-xs font-semibold uppercase tracking-wider text-neutral-700" for="inputHeaderTitle">Chat Header Title</label> <code class="text-[11px] font-mono text-neutral-400 bg-neutral-100 px-1.5 py-0.5 rounded">options.title</code></div><input class="w-full text-xs font-mono rounded-lg border-neutral-300 py-2 px-3 text-neutral-900 focus:border-neutral-900 focus:ring-1 focus:ring-neutral-900" id="inputHeaderTitle" value="Akvo Assistant"/></div><div><div class="flex items-center justify-between mb-1.5"><label class="text-xs font-semibold uppercase tracking-wider text-neutral-700" for="selectHeaderAvatar">Header Avatar Icon</label> <code class="text-[11px] font-mono text-neutral-400 bg-neutral-100 px-1.5 py-0.5 rounded">options.headerIcon</code></div><select class="w-full text-xs font-medium rounded-lg border-neutral-300 py-2 pl-3 pr-8 text-neutral-800 bg-white hover:border-neutral-400 focus:border-neutral-900" id="selectHeaderAvatar"><option selected="" value="none">None (Title Only)</option><option value="bot">Default Verified Bot Badge (SVG)</option><option value="custom_url">Custom Team Avatar (Image URL)</option></select></div></div><div class="space-y-4 pt-5"><div class="flex items-center justify-between"><label class="text-xs font-semibold uppercase tracking-wider text-neutral-700">Position & Dimensions</label> <code class="text-[11px] font-mono text-neutral-400 bg-neutral-100 px-1.5 py-0.5 rounded">position / size</code></div><div class="grid grid-cols-2 p-1 bg-neutral-100/90 border border-neutral-200/80 rounded-lg gap-1"><button class="px-3 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1" id="btnPosRight" type="button">Bottom Right</button> <button class="px-3 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1" id="btnPosLeft" type="button">Bottom Left</button></div><div class="grid grid-cols-2 gap-3"><div><label class="block text-[11px] font-medium text-neutral-600 mb-1" for="selectWidth">Width</label> <select class="w-full text-xs font-mono rounded-lg border-neutral-300 py-1.5 px-2 text-neutral-800 bg-white hover:border-neutral-400 focus:border-neutral-900" id="selectWidth"><option value="320px">320px (Compact)</option><option selected="selected" value="360px">360px (Standard)</option><option value="400px">400px (Medium)</option><option value="460px">460px (Wide)</option></select></div><div><label class="block text-[11px] font-medium text-neutral-600 mb-1" for="selectHeight">Height</label> <select class="w-full text-xs font-mono rounded-lg border-neutral-300 py-1.5 px-2 text-neutral-800 bg-white hover:border-neutral-400 focus:border-neutral-900" id="selectHeight"><option value="460px">460px (Short)</option><option selected="selected" value="500px">500px (Standard)</option><option value="580px">580px (Tall)</option><option value="660px">660px (Expanded)</option></select></div></div><div><div class="flex items-center justify-between mb-1"><label class="text-[11px] font-medium text-neutral-600" for="selectRadius">Corner Radius</label> <code class="text-[10px] font-mono text-neutral-400">options.borderRadius</code></div><select class="w-full text-xs font-mono rounded-lg border-neutral-300 py-1.5 px-2 text-neutral-800 bg-white hover:border-neutral-400 focus:border-neutral-900" id="selectRadius"><option value="4px">4px (Subtle)</option><option selected="selected" value="8px">8px (Default)</option><option value="12px">12px (Rounded)</option><option value="16px">16px (Pill / Soft)</option></select></div></div><div class="space-y-4 pt-5" data-purpose="kb-configuration-group"><div class="flex items-center justify-between"><label class="text-xs font-semibold uppercase tracking-wider text-neutral-700">RAG Backend Connection</label> <code class="text-[11px] font-mono text-neutral-400 bg-neutral-100 px-1.5 py-0.5 rounded">options.wsURL</code></div><div class="grid grid-cols-2 p-1 bg-neutral-100/90 border border-neutral-200/80 rounded-lg gap-1"><button class="px-2.5 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1.5 font-sans" id="btnWsOnline" type="button"><span class="w-2 h-2 rounded-full bg-emerald-500"></span> Online RAG</button> <button class="px-2.5 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1.5 font-sans" id="btnWsLocal" type="button"><span class="w-2 h-2 rounded-full bg-neutral-400"></span> Localhost:81</button></div><input class="w-full text-xs font-mono rounded-lg border-neutral-300 py-1.5 px-3 text-neutral-900 focus:border-neutral-900" id="inputWsUrl" value="wss://akvo-rag.akvotest.org/ws/chat"/><div class="flex items-center justify-between pt-2"><label class="text-xs font-semibold uppercase tracking-wider text-neutral-700">Knowledge Base Setup</label> <code class="text-[11px] font-mono text-neutral-400 bg-neutral-100 px-1.5 py-0.5 rounded">kb_id / kb_options</code></div><div class="grid grid-cols-2 p-1 bg-neutral-100/90 border border-neutral-200/80 rounded-lg gap-1" role="radiogroup"><button class="px-3 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1.5 font-sans" id="btnKbModeSingle" type="button">Single KB <span class="text-[10px] text-neutral-400">(Direct)</span></button> <button class="px-3 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1.5 font-sans" id="btnKbModeMulti" type="button">Multi-KB <span class="text-[10px] text-neutral-400">(Picker)</span></button></div><div id="singleKbContainer" class="hidden space-y-2 p-3 bg-neutral-50/80 rounded-lg border border-neutral-200/80"><div class="flex items-center justify-between"><label class="text-[11px] font-semibold text-neutral-700" for="inputSingleKbId">Single KB ID (Direct Session)</label> <code class="text-[10px] font-mono text-neutral-500 bg-neutral-200/60 px-1 rounded">options.kb_id</code></div><input class="w-full text-xs font-mono rounded-lg border-neutral-300 py-1.5 px-3 text-neutral-900 focus:border-neutral-900" id="inputSingleKbId" type="number" value="750"/><p class="text-[11px] text-neutral-500 leading-normal">Direct connection. Bypasses the knowledge base selection screen and connects immediately with the welcome message and input field ready.</p></div><div id="multiKbContainer" class="space-y-2 p-3 bg-neutral-50/80 rounded-lg border border-neutral-200/80"><div class="flex items-center justify-between"><label class="text-[11px] font-semibold text-neutral-700">Multi-KB Options List</label> <code class="text-[10px] font-mono text-neutral-500 bg-neutral-200/60 px-1 rounded">options.kb_options</code></div><div class="space-y-1.5 text-xs font-mono"><div class="flex items-center justify-between bg-white px-2.5 py-1.5 rounded border border-neutral-200 shadow-2xs"><span class="font-medium text-neutral-800">Critical Thinking</span> <span class="text-[11px] text-neutral-500 bg-neutral-100 px-1.5 py-0.5 rounded font-mono">ID: 750</span></div></div><p class="text-[11px] text-neutral-500 leading-normal">Presents the user with interactive radio buttons to choose their knowledge base first, then enables "Start Chat".</p></div></div></div><div class="p-4 bg-neutral-50/80 border-t border-border mt-auto flex flex-col gap-2.5"><button class="w-full py-2.5 px-4 rounded-lg bg-[#007A78] hover:bg-[#005D5B] text-white text-xs font-semibold tracking-wide transition-all shadow-subtle flex items-center justify-center gap-2 active:scale-[0.99]" id="btnApplyConfig" type="button"><svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2.5" viewbox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg> Apply Configuration to Session</button><div class="grid grid-cols-2 gap-2"><button class="py-2 px-3 text-xs font-medium text-neutral-700 bg-white hover:bg-neutral-100 border border-neutral-300 rounded-lg transition-colors flex items-center justify-center gap-1.5" id="btnTriggerOpen" type="button"><svg class="w-3.5 h-3.5 text-neutral-500" fill="none" stroke="currentColor" stroke-width="2" viewbox="0 0 24 24"><path d="M15 3h6v6"></path><path d="M10 14 21 3"></path><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path></svg> Trigger Open</button> <button class="py-2 px-3 text-xs font-medium text-neutral-700 bg-white hover:bg-neutral-100 border border-neutral-300 rounded-lg transition-colors flex items-center justify-center gap-1.5" id="btnTriggerMinimize" type="button"><svg class="w-3.5 h-3.5 text-neutral-500" fill="none" stroke="currentColor" stroke-width="2" viewbox="0 0 24 24"><path d="M4 14h6v6"></path><path d="M20 10h-6V4"></path><path d="M14 10l7-7"></path><path d="M3 21l7-7"></path></svg> Trigger Minimize</button></div></div></section><section class="lg:col-span-7 space-y-6 flex flex-col" data-purpose="output-telemetry-panel"><div class="bg-surface-dark rounded-xl border border-neutral-800 shadow-card overflow-hidden"><div class="px-4 py-3 bg-[#18181B] border-b border-neutral-800/80 flex items-center justify-between"><div class="flex items-center gap-2"><div class="flex items-center gap-1.5 mr-2"><span class="w-2.5 h-2.5 rounded-full bg-neutral-700"></span> <span class="w-2.5 h-2.5 rounded-full bg-neutral-700"></span> <span class="w-2.5 h-2.5 rounded-full bg-neutral-700"></span></div><div class="flex items-center space-x-1" role="tablist"><button id="tabMultiKb" class="px-2.5 py-1 text-xs font-mono rounded bg-neutral-800 text-white font-medium transition-colors" type="button">Multi-KB (kb_options)</button> <button id="tabSingleKb" class="px-2.5 py-1 text-xs font-mono rounded text-neutral-400 hover:text-neutral-200 hover:bg-neutral-800/50 transition-colors" type="button">Single KB (kb_id)</button> <button id="tabHtmlScript" class="px-2.5 py-1 text-xs font-mono rounded text-neutral-400 hover:text-neutral-200 hover:bg-neutral-800/50 transition-colors" type="button">HTML Script Tag</button></div></div><div class="flex items-center gap-3"><span class="hidden sm:inline-flex items-center gap-1 text-[11px] font-mono text-emerald-400"><span class="w-1.5 h-1.5 rounded-full bg-emerald-400"></span> Ready to deploy </span><button class="inline-flex items-center gap-1.5 px-2.5 py-1 text-xs font-mono text-neutral-300 hover:text-white bg-neutral-800 hover:bg-neutral-700 rounded border border-neutral-700 transition-colors" id="copyCodeBtn" type="button"><svg class="w-3.5 h-3.5 text-neutral-400" fill="none" stroke="currentColor" stroke-width="2" viewbox="0 0 24 24"><rect height="14" rx="2" ry="2" width="14" x="8" y="8"></rect><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"></path></svg> <span id="copyBtnLabel">Copy</span></button></div></div><div class="p-4 sm:p-5 overflow-x-auto text-[13px] font-mono leading-relaxed select-all"><pre class="text-neutral-300"><code id="codeSnippetPre"></code></pre></div><div class="px-4 py-2 bg-[#0E0E10] border-t border-neutral-800 text-[11px] font-mono text-neutral-500 flex justify-between"><span>Bundle cost: ~12.4 kB gzipped</span> <span>UTF-8 | LF</span></div></div><div class="bg-white rounded-xl border border-border shadow-card overflow-hidden" data-purpose="diagnostic-metrics"><div class="px-5 py-3 border-b border-border bg-neutral-50/50 flex items-center justify-between"><div class="flex items-center gap-2"><svg class="w-4 h-4 text-neutral-500" fill="none" stroke="currentColor" stroke-width="2" viewbox="0 0 24 24"><path d="M22 12h-4l-3 9L9 3l-3 9H2"></path></svg><h3 class="text-xs font-semibold tracking-wider uppercase text-neutral-800 font-mono">DOM State & Diagnostic Metrics</h3></div><span class="text-[11px] font-mono text-neutral-400">MutationObserver active</span></div><div class="p-5 grid grid-cols-1 sm:grid-cols-3 gap-4"><div class="p-3.5 rounded-lg border border-neutral-200/90 bg-neutral-50/40"><div class="text-[11px] font-mono uppercase text-neutral-500 font-medium">Launcher Element</div><div class="text-sm font-semibold font-mono text-neutral-900 mt-1 flex items-center gap-1.5" id="metricLauncher"><span class="w-2 h-2 rounded-full bg-emerald-500"></span> Visible (56px FAB)</div><span class="text-[10px] text-neutral-400 block mt-0.5">Fixed z-index: 99998</span></div><div class="p-3.5 rounded-lg border border-neutral-200/90 bg-neutral-50/40"><div class="text-[11px] font-mono uppercase text-neutral-500 font-medium">Chatbox Display</div><div class="text-sm font-semibold font-mono text-neutral-900 mt-1" id="metricChatbox">none (Collapsed)</div><span class="text-[10px] text-neutral-400 block mt-0.5">Hydrated & Collapsed</span></div><div class="p-3.5 rounded-lg border border-neutral-200/90 bg-neutral-50/40"><div class="text-[11px] font-mono uppercase text-neutral-500 font-medium">Token Inheritance</div><div class="text-sm font-semibold font-mono text-neutral-900 mt-1 flex items-center gap-1.5" id="metricToken"><span class="w-3 h-3 rounded bg-[#007A78]" id="metricColorDot"></span> <span id="metricTokenHex">#007A78</span></div><span class="text-[10px] text-neutral-400 block mt-0.5">Applied via --akvo-primary</span></div></div><div class="px-5 py-3 border-t border-neutral-100 bg-neutral-50/20 text-xs text-neutral-500 flex items-center justify-between"><span class="font-mono text-[11px] flex items-center gap-1.5"><span class="text-neutral-400">Recent Event:</span> <span id="recentEventText" class="text-neutral-700 bg-neutral-100 px-1.5 py-0.5 rounded font-mono">chat:ready (t+0ms)</span> </span><span class="text-[11px] font-mono text-teal-700">Live Client Connected</span></div></div></section></div></main><script data-purpose="workbench-interactivity">document.addEventListener('DOMContentLoaded', () => {
|
|
56
|
+
// Configuration State
|
|
57
|
+
const config = {
|
|
58
|
+
wsURL: "wss://akvo-rag.akvotest.org/ws/chat",
|
|
59
|
+
title: "Akvo Assistant",
|
|
60
|
+
primaryColor: "#007A78",
|
|
61
|
+
showLauncher: true,
|
|
62
|
+
startMinimized: true,
|
|
63
|
+
width: "360px",
|
|
64
|
+
height: "500px",
|
|
65
|
+
position: "bottom-right",
|
|
66
|
+
borderRadius: "8px",
|
|
67
|
+
launcherSize: "56px",
|
|
68
|
+
launcherIconType: "bubble",
|
|
69
|
+
headerIconType: "none",
|
|
70
|
+
kbMode: "multi", // "multi" or "single"
|
|
71
|
+
kb_id: 750,
|
|
72
|
+
kb_options: [
|
|
73
|
+
{ "kb_id": 750, "label": "Critical Thinking" }
|
|
74
|
+
],
|
|
75
|
+
activeTab: "multi" // "multi", "single", or "html"
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const ICONS = {
|
|
79
|
+
launcher: {
|
|
80
|
+
bubble: null,
|
|
81
|
+
sparkle: '<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"/></svg>',
|
|
82
|
+
robot: '<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="10" rx="2"/><circle cx="12" cy="5" r="2"/><path d="M12 7v4"/><line x1="8" y1="16" x2="8" y2="16"/><line x1="16" y1="16" x2="16" y2="16"/></svg>',
|
|
83
|
+
custom_url: 'https://api.iconify.design/lucide:bot.svg'
|
|
84
|
+
},
|
|
85
|
+
header: {
|
|
86
|
+
none: null,
|
|
87
|
+
bot: '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="10" rx="2"/><circle cx="12" cy="5" r="2"/><path d="M12 7v4"/></svg>',
|
|
88
|
+
custom_url: 'https://api.iconify.design/lucide:sparkles.svg'
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// UI References
|
|
93
|
+
const btnWsOnline = document.getElementById('btnWsOnline');
|
|
94
|
+
const btnWsLocal = document.getElementById('btnWsLocal');
|
|
95
|
+
const inputWsUrl = document.getElementById('inputWsUrl');
|
|
96
|
+
|
|
97
|
+
const nativeColorInput = document.getElementById('nativeColorInput');
|
|
98
|
+
const hexTextInput = document.getElementById('hexTextInput');
|
|
99
|
+
const swatches = document.querySelectorAll('.theme-swatch');
|
|
100
|
+
|
|
101
|
+
const tabMultiKb = document.getElementById('tabMultiKb');
|
|
102
|
+
const tabSingleKb = document.getElementById('tabSingleKb');
|
|
103
|
+
const tabHtmlScript = document.getElementById('tabHtmlScript');
|
|
104
|
+
const codeSnippetPre = document.getElementById('codeSnippetPre');
|
|
105
|
+
|
|
106
|
+
const metricTokenHex = document.getElementById('metricTokenHex');
|
|
107
|
+
const metricColorDot = document.getElementById('metricColorDot');
|
|
108
|
+
const metricChatbox = document.getElementById('metricChatbox');
|
|
109
|
+
const metricLauncher = document.getElementById('metricLauncher');
|
|
110
|
+
const recentEventText = document.getElementById('recentEventText');
|
|
111
|
+
|
|
112
|
+
const inputHeaderTitle = document.getElementById('inputHeaderTitle');
|
|
113
|
+
const selectLauncherIcon = document.getElementById('selectLauncherIcon');
|
|
114
|
+
const selectLauncherSize = document.getElementById('selectLauncherSize');
|
|
115
|
+
const selectHeaderAvatar = document.getElementById('selectHeaderAvatar');
|
|
116
|
+
const btnPosRight = document.getElementById('btnPosRight');
|
|
117
|
+
const btnPosLeft = document.getElementById('btnPosLeft');
|
|
118
|
+
const selectWidth = document.getElementById('selectWidth');
|
|
119
|
+
const selectHeight = document.getElementById('selectHeight');
|
|
120
|
+
const selectRadius = document.getElementById('selectRadius');
|
|
121
|
+
|
|
122
|
+
const btnKbModeSingle = document.getElementById('btnKbModeSingle');
|
|
123
|
+
const btnKbModeMulti = document.getElementById('btnKbModeMulti');
|
|
124
|
+
const singleKbContainer = document.getElementById('singleKbContainer');
|
|
125
|
+
const multiKbContainer = document.getElementById('multiKbContainer');
|
|
126
|
+
const inputSingleKbId = document.getElementById('inputSingleKbId');
|
|
127
|
+
|
|
128
|
+
const btnApplyConfig = document.getElementById('btnApplyConfig');
|
|
129
|
+
const btnTriggerOpen = document.getElementById('btnTriggerOpen');
|
|
130
|
+
const btnTriggerMinimize = document.getElementById('btnTriggerMinimize');
|
|
131
|
+
const btnResetConfig = document.getElementById('btnResetConfig');
|
|
132
|
+
const copyCodeBtn = document.getElementById('copyCodeBtn');
|
|
133
|
+
const copyBtnLabel = document.getElementById('copyBtnLabel');
|
|
134
|
+
|
|
135
|
+
const btnDisplayFab = document.getElementById('btnDisplayFab');
|
|
136
|
+
const btnDisplayEmbedded = document.getElementById('btnDisplayEmbedded');
|
|
137
|
+
const btnMountMinTrue = document.getElementById('btnMountMinTrue');
|
|
138
|
+
const btnMountMinFalse = document.getElementById('btnMountMinFalse');
|
|
139
|
+
const startStateContainer = document.getElementById('startStateContainer');
|
|
140
|
+
const launcherIconContainer = document.getElementById('launcherIconContainer');
|
|
141
|
+
|
|
142
|
+
function logEvent(name) {
|
|
143
|
+
if (recentEventText) {
|
|
144
|
+
const t = new Date().toLocaleTimeString();
|
|
145
|
+
recentEventText.textContent = `${name} (${t})`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function resolveOptions() {
|
|
150
|
+
const opts = {
|
|
151
|
+
wsURL: config.wsURL,
|
|
152
|
+
title: config.title,
|
|
153
|
+
primaryColor: config.primaryColor,
|
|
154
|
+
showLauncher: config.showLauncher,
|
|
155
|
+
startMinimized: config.startMinimized,
|
|
156
|
+
width: config.width,
|
|
157
|
+
height: config.height,
|
|
158
|
+
position: config.position,
|
|
159
|
+
borderRadius: config.borderRadius,
|
|
160
|
+
launcherSize: config.launcherSize,
|
|
161
|
+
launcherIcon: ICONS.launcher[config.launcherIconType] || null,
|
|
162
|
+
headerIcon: ICONS.header[config.headerIconType] || null
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
if (config.kbMode === "single") {
|
|
166
|
+
opts.kb_id = config.kb_id;
|
|
167
|
+
} else {
|
|
168
|
+
opts.kb_options = config.kb_options;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return opts;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function updateCodeSnippet(opts) {
|
|
175
|
+
if (!codeSnippetPre) return;
|
|
176
|
+
|
|
177
|
+
let codeHtml = "";
|
|
178
|
+
const iconStr = opts.launcherIcon
|
|
179
|
+
? (opts.launcherIcon.startsWith('<svg') ? '"<svg ... />"' : `"${opts.launcherIcon}"`)
|
|
180
|
+
: 'null';
|
|
181
|
+
const headerIconStr = opts.headerIcon
|
|
182
|
+
? (opts.headerIcon.startsWith('<svg') ? '"<svg ... />"' : `"${opts.headerIcon}"`)
|
|
183
|
+
: 'null';
|
|
184
|
+
|
|
185
|
+
if (config.activeTab === "single") {
|
|
186
|
+
codeHtml = `<span class="tok-com">// 1. Single Knowledge Base Direct Integration</span>
|
|
187
|
+
<span class="tok-kw">import</span> { <span class="tok-fn">initChat</span> } <span class="tok-kw">from</span> <span class="tok-str">"akvo-rag-js"</span>;
|
|
188
|
+
<span class="tok-kw">import</span> <span class="tok-str">"akvo-rag-js/dist/akvo-rag.css"</span>;
|
|
189
|
+
|
|
190
|
+
<span class="tok-kw">const</span> <span class="tok-prop">chat</span> = <span class="tok-fn">initChat</span>({
|
|
191
|
+
<span class="tok-prop">wsURL</span>: <span class="tok-str">"${opts.wsURL}"</span>,
|
|
192
|
+
<span class="tok-prop">kb_id</span>: <span class="tok-num">${config.kb_id}</span>, <span class="tok-com">// Direct session bypasses selection picker</span>
|
|
193
|
+
<span class="tok-prop">title</span>: <span class="tok-str">"${opts.title}"</span>,
|
|
194
|
+
<span class="tok-prop">primaryColor</span>: <span class="tok-str">"${opts.primaryColor}"</span>,
|
|
195
|
+
<span class="tok-prop">showLauncher</span>: <span class="tok-bool">${opts.showLauncher}</span>,
|
|
196
|
+
<span class="tok-prop">startMinimized</span>: <span class="tok-bool">${opts.startMinimized}</span>,
|
|
197
|
+
<span class="tok-prop">width</span>: <span class="tok-str">"${opts.width}"</span>,
|
|
198
|
+
<span class="tok-prop">height</span>: <span class="tok-str">"${opts.height}"</span>,
|
|
199
|
+
<span class="tok-prop">position</span>: <span class="tok-str">"${opts.position}"</span>,
|
|
200
|
+
<span class="tok-prop">borderRadius</span>: <span class="tok-str">"${opts.borderRadius}"</span>,
|
|
201
|
+
<span class="tok-prop">launcherSize</span>: <span class="tok-str">"${opts.launcherSize}"</span>,
|
|
202
|
+
<span class="tok-prop">launcherIcon</span>: <span class="tok-bool">${iconStr}</span>,
|
|
203
|
+
<span class="tok-prop">headerIcon</span>: <span class="tok-bool">${headerIconStr}</span>
|
|
204
|
+
});`;
|
|
205
|
+
} else if (config.activeTab === "multi") {
|
|
206
|
+
codeHtml = `<span class="tok-com">// 2. Multi-Knowledge Base Options Picker Integration</span>
|
|
207
|
+
<span class="tok-kw">import</span> { <span class="tok-fn">initChat</span> } <span class="tok-kw">from</span> <span class="tok-str">"akvo-rag-js"</span>;
|
|
208
|
+
<span class="tok-kw">import</span> <span class="tok-str">"akvo-rag-js/dist/akvo-rag.css"</span>;
|
|
209
|
+
|
|
210
|
+
<span class="tok-kw">const</span> <span class="tok-prop">chat</span> = <span class="tok-fn">initChat</span>({
|
|
211
|
+
<span class="tok-prop">wsURL</span>: <span class="tok-str">"${opts.wsURL}"</span>,
|
|
212
|
+
<span class="tok-prop">title</span>: <span class="tok-str">"${opts.title}"</span>,
|
|
213
|
+
<span class="tok-prop">primaryColor</span>: <span class="tok-str">"${opts.primaryColor}"</span>,
|
|
214
|
+
<span class="tok-prop">showLauncher</span>: <span class="tok-bool">${opts.showLauncher}</span>,
|
|
215
|
+
<span class="tok-prop">startMinimized</span>: <span class="tok-bool">${opts.startMinimized}</span>,
|
|
216
|
+
<span class="tok-prop">width</span>: <span class="tok-str">"${opts.width}"</span>,
|
|
217
|
+
<span class="tok-prop">height</span>: <span class="tok-str">"${opts.height}"</span>,
|
|
218
|
+
<span class="tok-prop">position</span>: <span class="tok-str">"${opts.position}"</span>,
|
|
219
|
+
<span class="tok-prop">borderRadius</span>: <span class="tok-str">"${opts.borderRadius}"</span>,
|
|
220
|
+
<span class="tok-prop">launcherSize</span>: <span class="tok-str">"${opts.launcherSize}"</span>,
|
|
221
|
+
<span class="tok-prop">launcherIcon</span>: <span class="tok-bool">${iconStr}</span>,
|
|
222
|
+
<span class="tok-prop">headerIcon</span>: <span class="tok-bool">${headerIconStr}</span>,
|
|
223
|
+
<span class="tok-prop">kb_options</span>: [
|
|
224
|
+
{
|
|
225
|
+
<span class="tok-prop">"kb_id"</span>: <span class="tok-num">750</span>,
|
|
226
|
+
<span class="tok-prop">"label"</span>: <span class="tok-str">"Critical Thinking"</span>
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
});`;
|
|
230
|
+
} else {
|
|
231
|
+
codeHtml = `<span class="tok-com"><!-- 3. Vanilla HTML / CDN Script Tag Integration --></span>
|
|
232
|
+
<span class="tok-tag"><link</span> <span class="tok-attr">rel</span>=<span class="tok-str">"stylesheet"</span> <span class="tok-attr">href</span>=<span class="tok-str">"https://unpkg.com/akvo-rag-js/dist/akvo-rag.css"</span><span class="tok-tag">></span>
|
|
233
|
+
<span class="tok-tag"><script</span> <span class="tok-attr">src</span>=<span class="tok-str">"https://unpkg.com/akvo-rag-js/dist/akvo-rag.js"</span><span class="tok-tag">></script></span>
|
|
234
|
+
|
|
235
|
+
<span class="tok-tag"><script></span>
|
|
236
|
+
<span class="tok-prop">document</span>.<span class="tok-fn">addEventListener</span>(<span class="tok-str">'DOMContentLoaded'</span>, <span class="tok-kw">function</span> () {
|
|
237
|
+
<span class="tok-fn">AkvoRagChatbox</span>.<span class="tok-fn">initChat</span>({
|
|
238
|
+
<span class="tok-prop">wsURL</span>: <span class="tok-str">"${opts.wsURL}"</span>,
|
|
239
|
+
${config.kbMode === 'single' ? `<span class="tok-prop">kb_id</span>: <span class="tok-num">${config.kb_id}</span>,` : `<span class="tok-prop">kb_options</span>: [
|
|
240
|
+
{ <span class="tok-prop">"kb_id"</span>: <span class="tok-num">750</span>, <span class="tok-prop">"label"</span>: <span class="tok-str">"Critical Thinking"</span> }
|
|
241
|
+
],`}
|
|
242
|
+
<span class="tok-prop">title</span>: <span class="tok-str">"${opts.title}"</span>,
|
|
243
|
+
<span class="tok-prop">primaryColor</span>: <span class="tok-str">"${opts.primaryColor}"</span>,
|
|
244
|
+
<span class="tok-prop">showLauncher</span>: <span class="tok-bool">${opts.showLauncher}</span>,
|
|
245
|
+
<span class="tok-prop">startMinimized</span>: <span class="tok-bool">${opts.startMinimized}</span>
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
<span class="tok-tag"></script></span>`;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
codeSnippetPre.innerHTML = codeHtml;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function updateTelemetry() {
|
|
255
|
+
const launcher = document.getElementById('akvo-rag-launcher');
|
|
256
|
+
const chatbox = document.getElementById('akvo-rag');
|
|
257
|
+
|
|
258
|
+
if (metricLauncher) {
|
|
259
|
+
if (!config.showLauncher) {
|
|
260
|
+
metricLauncher.innerHTML = `<span class="w-2 h-2 rounded-full bg-neutral-400"></span> Disabled (Inline Embed)`;
|
|
261
|
+
} else if (launcher) {
|
|
262
|
+
const isVisible = window.getComputedStyle(launcher).display !== 'none';
|
|
263
|
+
if (isVisible) {
|
|
264
|
+
metricLauncher.innerHTML = `<span class="w-2 h-2 rounded-full bg-emerald-500"></span> Visible (56px FAB)`;
|
|
265
|
+
} else {
|
|
266
|
+
metricLauncher.innerHTML = `<span class="w-2 h-2 rounded-full bg-amber-500"></span> Hidden (Chat Open)`;
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
metricLauncher.innerHTML = `<span class="w-2 h-2 rounded-full bg-neutral-400"></span> Pending Init...`;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (metricChatbox) {
|
|
274
|
+
if (chatbox) {
|
|
275
|
+
const isVisible = window.getComputedStyle(chatbox).display !== 'none';
|
|
276
|
+
if (isVisible) {
|
|
277
|
+
if (chatbox.classList.contains('minimized')) {
|
|
278
|
+
metricChatbox.innerHTML = `<span class="w-2 h-2 rounded-full bg-amber-500 inline-block mr-1"></span> minimized (Titlebar 40px)`;
|
|
279
|
+
metricChatbox.className = "text-sm font-semibold font-mono text-amber-700 mt-1";
|
|
280
|
+
} else {
|
|
281
|
+
metricChatbox.innerHTML = `<span class="w-2 h-2 rounded-full bg-emerald-500 inline-block mr-1"></span> flex (Active)`;
|
|
282
|
+
metricChatbox.className = "text-sm font-semibold font-mono text-emerald-700 mt-1";
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
metricChatbox.innerHTML = `<span class="w-2 h-2 rounded-full bg-neutral-400 inline-block mr-1"></span> none (Collapsed)`;
|
|
286
|
+
metricChatbox.className = "text-sm font-semibold font-mono text-neutral-600 mt-1";
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
metricChatbox.textContent = 'Unmounted';
|
|
290
|
+
metricChatbox.className = "text-sm font-semibold font-mono text-neutral-400 mt-1";
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (metricTokenHex) {
|
|
295
|
+
metricTokenHex.textContent = config.primaryColor;
|
|
296
|
+
}
|
|
297
|
+
if (metricColorDot) {
|
|
298
|
+
metricColorDot.style.backgroundColor = config.primaryColor;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function setTab(tab) {
|
|
303
|
+
config.activeTab = tab;
|
|
304
|
+
const activeClass = "px-2.5 py-1 text-xs font-mono rounded bg-neutral-800 text-white font-medium transition-colors";
|
|
305
|
+
const inactiveClass = "px-2.5 py-1 text-xs font-mono rounded text-neutral-400 hover:text-neutral-200 hover:bg-neutral-800/50 transition-colors";
|
|
306
|
+
|
|
307
|
+
if (tabMultiKb) tabMultiKb.className = tab === "multi" ? activeClass : inactiveClass;
|
|
308
|
+
if (tabSingleKb) tabSingleKb.className = tab === "single" ? activeClass : inactiveClass;
|
|
309
|
+
if (tabHtmlScript) tabHtmlScript.className = tab === "html" ? activeClass : inactiveClass;
|
|
310
|
+
|
|
311
|
+
updateCodeSnippet(resolveOptions());
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function setKbMode(mode, remount = true) {
|
|
315
|
+
config.kbMode = mode;
|
|
316
|
+
const activeBtnClass = "px-3 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1.5 font-sans";
|
|
317
|
+
const inactiveBtnClass = "px-3 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1.5 font-sans";
|
|
318
|
+
|
|
319
|
+
if (mode === "single") {
|
|
320
|
+
if (btnKbModeSingle) btnKbModeSingle.className = activeBtnClass;
|
|
321
|
+
if (btnKbModeMulti) btnKbModeMulti.className = inactiveBtnClass;
|
|
322
|
+
if (singleKbContainer) singleKbContainer.classList.remove('hidden');
|
|
323
|
+
if (multiKbContainer) multiKbContainer.classList.add('hidden');
|
|
324
|
+
} else {
|
|
325
|
+
if (btnKbModeMulti) btnKbModeMulti.className = activeBtnClass;
|
|
326
|
+
if (btnKbModeSingle) btnKbModeSingle.className = inactiveBtnClass;
|
|
327
|
+
if (multiKbContainer) multiKbContainer.classList.remove('hidden');
|
|
328
|
+
if (singleKbContainer) singleKbContainer.classList.add('hidden');
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (remount) {
|
|
332
|
+
mount();
|
|
333
|
+
}
|
|
334
|
+
logEvent(`kb_mode:${mode}`);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function mount() {
|
|
338
|
+
if (window.chatInstance) {
|
|
339
|
+
try {
|
|
340
|
+
window.chatInstance.destroy();
|
|
341
|
+
} catch (e) {
|
|
342
|
+
console.warn("Destroy instance:", e);
|
|
343
|
+
}
|
|
344
|
+
window.chatInstance = null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const opts = resolveOptions();
|
|
348
|
+
updateCodeSnippet(opts);
|
|
349
|
+
|
|
350
|
+
const Rag = window.AkvoRAG || (typeof AkvoRAG !== 'undefined' ? AkvoRAG : null);
|
|
351
|
+
if (Rag && typeof Rag.initChat === 'function') {
|
|
352
|
+
window.chatInstance = Rag.initChat(opts);
|
|
353
|
+
logEvent("widget:mounted");
|
|
354
|
+
} else {
|
|
355
|
+
console.warn("AkvoRAG is not available on window yet.");
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
setTimeout(updateTelemetry, 60);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Safe retry for initial script loading
|
|
362
|
+
function ensureMount(retries = 10) {
|
|
363
|
+
const Rag = window.AkvoRAG || (typeof AkvoRAG !== 'undefined' ? AkvoRAG : null);
|
|
364
|
+
if (Rag && typeof Rag.initChat === 'function') {
|
|
365
|
+
mount();
|
|
366
|
+
} else if (retries > 0) {
|
|
367
|
+
setTimeout(() => ensureMount(retries - 1), 100);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Update Theme Color
|
|
372
|
+
function applyThemeColor(color, remount = true) {
|
|
373
|
+
config.primaryColor = color;
|
|
374
|
+
nativeColorInput.value = color;
|
|
375
|
+
hexTextInput.value = color.replace('#', '').toUpperCase();
|
|
376
|
+
|
|
377
|
+
swatches.forEach(sw => {
|
|
378
|
+
const swColor = sw.getAttribute('data-color');
|
|
379
|
+
const checkIcon = sw.querySelector('.check-icon');
|
|
380
|
+
if (swColor && swColor.toLowerCase() === color.toLowerCase()) {
|
|
381
|
+
sw.classList.add('ring-2', 'ring-neutral-900', 'ring-offset-2');
|
|
382
|
+
sw.classList.remove('ring-1', 'ring-black/10');
|
|
383
|
+
if (checkIcon) checkIcon.classList.remove('hidden');
|
|
384
|
+
} else {
|
|
385
|
+
sw.classList.remove('ring-2', 'ring-neutral-900', 'ring-offset-2');
|
|
386
|
+
sw.classList.add('ring-1', 'ring-black/10');
|
|
387
|
+
if (checkIcon) checkIcon.classList.add('hidden');
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// Fast update runtime CSS variables without tearing down the DOM tree
|
|
392
|
+
const container = document.getElementById('akvo-rag');
|
|
393
|
+
const launcher = document.getElementById('akvo-rag-launcher');
|
|
394
|
+
if (container && container.style) container.style.setProperty('--akvo-primary', color);
|
|
395
|
+
if (launcher && launcher.style) launcher.style.setProperty('--akvo-primary', color);
|
|
396
|
+
|
|
397
|
+
updateCodeSnippet(resolveOptions());
|
|
398
|
+
updateTelemetry();
|
|
399
|
+
|
|
400
|
+
if (remount) {
|
|
401
|
+
mount();
|
|
402
|
+
}
|
|
403
|
+
logEvent(`theme:${color}`);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Swatch Click Listeners
|
|
407
|
+
swatches.forEach(swatch => {
|
|
408
|
+
swatch.addEventListener('click', () => {
|
|
409
|
+
const col = swatch.getAttribute('data-color');
|
|
410
|
+
if (col) applyThemeColor(col, true);
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// Custom Color Inputs (live 60fps CSS property preview on input, full sync on change)
|
|
415
|
+
nativeColorInput.addEventListener('input', (e) => {
|
|
416
|
+
applyThemeColor(e.target.value, false);
|
|
417
|
+
});
|
|
418
|
+
nativeColorInput.addEventListener('change', (e) => {
|
|
419
|
+
applyThemeColor(e.target.value, true);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
hexTextInput.addEventListener('change', (e) => {
|
|
423
|
+
let val = e.target.value.trim();
|
|
424
|
+
if (!val.startsWith('#')) val = '#' + val;
|
|
425
|
+
if (/^#[0-9A-Fa-f]{6}$/.test(val)) {
|
|
426
|
+
applyThemeColor(val, true);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// Header Title Change
|
|
431
|
+
inputHeaderTitle.addEventListener('change', (e) => {
|
|
432
|
+
const val = e.target.value.trim() || "Akvo Assistant";
|
|
433
|
+
config.title = val;
|
|
434
|
+
mount();
|
|
435
|
+
logEvent("title:updated");
|
|
436
|
+
});
|
|
437
|
+
inputHeaderTitle.addEventListener('keydown', (e) => {
|
|
438
|
+
if (e.key === 'Enter') {
|
|
439
|
+
const val = e.target.value.trim() || "Akvo Assistant";
|
|
440
|
+
config.title = val;
|
|
441
|
+
mount();
|
|
442
|
+
logEvent("title:updated");
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// Launcher Icon Dropdown
|
|
447
|
+
selectLauncherIcon.addEventListener('change', (e) => {
|
|
448
|
+
config.launcherIconType = e.target.value;
|
|
449
|
+
mount();
|
|
450
|
+
logEvent(`icon:launcher_${config.launcherIconType}`);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
// Launcher Size Dropdown
|
|
454
|
+
if (selectLauncherSize) {
|
|
455
|
+
selectLauncherSize.addEventListener('change', (e) => {
|
|
456
|
+
config.launcherSize = e.target.value;
|
|
457
|
+
mount();
|
|
458
|
+
logEvent(`launcher_size:${config.launcherSize}`);
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// Header Avatar Dropdown
|
|
463
|
+
selectHeaderAvatar.addEventListener('change', (e) => {
|
|
464
|
+
config.headerIconType = e.target.value;
|
|
465
|
+
mount();
|
|
466
|
+
logEvent(`icon:header_${config.headerIconType}`);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
// Programmatic Open & Minimize
|
|
470
|
+
btnTriggerOpen.addEventListener('click', () => {
|
|
471
|
+
if (window.chatInstance && typeof window.chatInstance.open === 'function') {
|
|
472
|
+
window.chatInstance.open();
|
|
473
|
+
logEvent("widget:opened");
|
|
474
|
+
updateTelemetry();
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
btnTriggerMinimize.addEventListener('click', () => {
|
|
479
|
+
if (window.chatInstance && typeof window.chatInstance.minimize === 'function') {
|
|
480
|
+
window.chatInstance.minimize();
|
|
481
|
+
logEvent("widget:minimized");
|
|
482
|
+
updateTelemetry();
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
// Position Switcher Listeners
|
|
487
|
+
if (btnPosRight && btnPosLeft) {
|
|
488
|
+
btnPosRight.addEventListener('click', () => {
|
|
489
|
+
config.position = 'bottom-right';
|
|
490
|
+
btnPosRight.className = 'px-3 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1';
|
|
491
|
+
btnPosLeft.className = 'px-3 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1';
|
|
492
|
+
mount();
|
|
493
|
+
logEvent("pos:bottom-right");
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
btnPosLeft.addEventListener('click', () => {
|
|
497
|
+
config.position = 'bottom-left';
|
|
498
|
+
btnPosLeft.className = 'px-3 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1';
|
|
499
|
+
btnPosRight.className = 'px-3 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1';
|
|
500
|
+
mount();
|
|
501
|
+
logEvent("pos:bottom-left");
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// Sizing Selectors
|
|
506
|
+
if (selectWidth) {
|
|
507
|
+
selectWidth.addEventListener('change', (e) => {
|
|
508
|
+
config.width = e.target.value;
|
|
509
|
+
mount();
|
|
510
|
+
logEvent(`width:${config.width}`);
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (selectHeight) {
|
|
515
|
+
selectHeight.addEventListener('change', (e) => {
|
|
516
|
+
config.height = e.target.value;
|
|
517
|
+
mount();
|
|
518
|
+
logEvent(`height:${config.height}`);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
if (selectRadius) {
|
|
523
|
+
selectRadius.addEventListener('change', (e) => {
|
|
524
|
+
config.borderRadius = e.target.value;
|
|
525
|
+
mount();
|
|
526
|
+
logEvent(`radius:${config.borderRadius}`);
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// Knowledge Base Mode Listeners
|
|
531
|
+
if (btnKbModeSingle && btnKbModeMulti) {
|
|
532
|
+
btnKbModeSingle.addEventListener('click', () => {
|
|
533
|
+
setKbMode("single");
|
|
534
|
+
setTab("single");
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
btnKbModeMulti.addEventListener('click', () => {
|
|
538
|
+
setKbMode("multi");
|
|
539
|
+
setTab("multi");
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (inputSingleKbId) {
|
|
544
|
+
inputSingleKbId.addEventListener('change', (e) => {
|
|
545
|
+
const val = parseInt(e.target.value, 10);
|
|
546
|
+
if (!isNaN(val) && val > 0) {
|
|
547
|
+
config.kb_id = val;
|
|
548
|
+
if (config.kbMode === "single") {
|
|
549
|
+
mount();
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// Code Tab Controls
|
|
556
|
+
if (tabMultiKb) {
|
|
557
|
+
tabMultiKb.addEventListener('click', () => {
|
|
558
|
+
setTab("multi");
|
|
559
|
+
setKbMode("multi");
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if (tabSingleKb) {
|
|
564
|
+
tabSingleKb.addEventListener('click', () => {
|
|
565
|
+
setTab("single");
|
|
566
|
+
setKbMode("single");
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
if (tabHtmlScript) {
|
|
571
|
+
tabHtmlScript.addEventListener('click', () => {
|
|
572
|
+
setTab("html");
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// WebSocket URL & Presets
|
|
577
|
+
if (btnWsOnline && btnWsLocal && inputWsUrl) {
|
|
578
|
+
const activeWsClass = "px-2.5 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1.5 font-sans";
|
|
579
|
+
const inactiveWsClass = "px-2.5 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1.5 font-sans";
|
|
580
|
+
|
|
581
|
+
btnWsOnline.addEventListener('click', () => {
|
|
582
|
+
config.wsURL = "wss://akvo-rag.akvotest.org/ws/chat";
|
|
583
|
+
inputWsUrl.value = config.wsURL;
|
|
584
|
+
btnWsOnline.className = activeWsClass;
|
|
585
|
+
btnWsLocal.className = inactiveWsClass;
|
|
586
|
+
mount();
|
|
587
|
+
logEvent("ws:online_akvotest");
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
btnWsLocal.addEventListener('click', () => {
|
|
591
|
+
config.wsURL = "ws://localhost:81/ws/chat";
|
|
592
|
+
inputWsUrl.value = config.wsURL;
|
|
593
|
+
btnWsLocal.className = activeWsClass;
|
|
594
|
+
btnWsOnline.className = inactiveWsClass;
|
|
595
|
+
mount();
|
|
596
|
+
logEvent("ws:localhost_81");
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
inputWsUrl.addEventListener('change', (e) => {
|
|
600
|
+
const val = e.target.value.trim();
|
|
601
|
+
if (val) {
|
|
602
|
+
config.wsURL = val;
|
|
603
|
+
if (val.includes("akvotest.org")) {
|
|
604
|
+
btnWsOnline.className = activeWsClass;
|
|
605
|
+
btnWsLocal.className = inactiveWsClass;
|
|
606
|
+
} else if (val.includes("localhost")) {
|
|
607
|
+
btnWsLocal.className = activeWsClass;
|
|
608
|
+
btnWsOnline.className = inactiveWsClass;
|
|
609
|
+
} else {
|
|
610
|
+
btnWsOnline.className = inactiveWsClass;
|
|
611
|
+
btnWsLocal.className = inactiveWsClass;
|
|
612
|
+
}
|
|
613
|
+
mount();
|
|
614
|
+
logEvent("ws:custom_url");
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// Display Mode Toggle
|
|
620
|
+
btnDisplayFab.addEventListener('click', () => {
|
|
621
|
+
config.showLauncher = true;
|
|
622
|
+
btnDisplayFab.className = 'px-3 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1.5';
|
|
623
|
+
btnDisplayEmbedded.className = 'px-3 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1.5';
|
|
624
|
+
if (startStateContainer) startStateContainer.style.display = 'block';
|
|
625
|
+
if (launcherIconContainer) launcherIconContainer.style.display = 'block';
|
|
626
|
+
mount();
|
|
627
|
+
logEvent("mode:circular_fab");
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
btnDisplayEmbedded.addEventListener('click', () => {
|
|
631
|
+
config.showLauncher = false;
|
|
632
|
+
btnDisplayEmbedded.className = 'px-3 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1.5';
|
|
633
|
+
btnDisplayFab.className = 'px-3 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1.5';
|
|
634
|
+
if (startStateContainer) startStateContainer.style.display = 'none';
|
|
635
|
+
if (launcherIconContainer) launcherIconContainer.style.display = 'none';
|
|
636
|
+
mount();
|
|
637
|
+
logEvent("mode:embedded_box");
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
// Mount State Toggle
|
|
641
|
+
btnMountMinTrue.addEventListener('click', () => {
|
|
642
|
+
config.startMinimized = true;
|
|
643
|
+
btnMountMinTrue.className = 'px-3 py-1.5 text-xs font-mono font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5';
|
|
644
|
+
btnMountMinFalse.className = 'px-3 py-1.5 text-xs font-mono font-medium rounded-md text-neutral-500 hover:text-neutral-900 transition-all';
|
|
645
|
+
mount();
|
|
646
|
+
logEvent("state:minimized_true");
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
btnMountMinFalse.addEventListener('click', () => {
|
|
650
|
+
config.startMinimized = false;
|
|
651
|
+
btnMountMinFalse.className = 'px-3 py-1.5 text-xs font-mono font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5';
|
|
652
|
+
btnMountMinTrue.className = 'px-3 py-1.5 text-xs font-mono font-medium rounded-md text-neutral-500 hover:text-neutral-900 transition-all';
|
|
653
|
+
mount();
|
|
654
|
+
logEvent("state:minimized_false");
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
// Apply Config Feedback
|
|
658
|
+
btnApplyConfig.addEventListener('click', () => {
|
|
659
|
+
config.title = inputHeaderTitle.value.trim() || "Akvo Assistant";
|
|
660
|
+
btnApplyConfig.innerHTML = `<svg class="w-4 h-4 animate-spin" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg> Reloading Engine...`;
|
|
661
|
+
setTimeout(() => {
|
|
662
|
+
mount();
|
|
663
|
+
btnApplyConfig.innerHTML = `<svg class="w-4 h-4 text-emerald-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="20 6 9 17 4 12"/></svg> Configuration Synced`;
|
|
664
|
+
setTimeout(() => {
|
|
665
|
+
btnApplyConfig.innerHTML = `<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="20 6 9 17 4 12"/></svg> Apply Configuration to Session`;
|
|
666
|
+
}, 1400);
|
|
667
|
+
}, 300);
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
// Reset Defaults
|
|
671
|
+
if (btnResetConfig) {
|
|
672
|
+
btnResetConfig.addEventListener('click', () => {
|
|
673
|
+
config.wsURL = "wss://akvo-rag.akvotest.org/ws/chat";
|
|
674
|
+
config.title = "Akvo Assistant";
|
|
675
|
+
config.primaryColor = "#007A78";
|
|
676
|
+
config.showLauncher = true;
|
|
677
|
+
config.startMinimized = true;
|
|
678
|
+
config.width = "360px";
|
|
679
|
+
config.height = "500px";
|
|
680
|
+
config.position = "bottom-right";
|
|
681
|
+
config.borderRadius = "8px";
|
|
682
|
+
config.launcherSize = "56px";
|
|
683
|
+
config.launcherIconType = "bubble";
|
|
684
|
+
config.headerIconType = "none";
|
|
685
|
+
config.kbMode = "multi";
|
|
686
|
+
config.kb_id = 750;
|
|
687
|
+
config.kb_options = [
|
|
688
|
+
{ "kb_id": 750, "label": "Critical Thinking" }
|
|
689
|
+
];
|
|
690
|
+
config.activeTab = "multi";
|
|
691
|
+
|
|
692
|
+
if (inputWsUrl) inputWsUrl.value = config.wsURL;
|
|
693
|
+
if (btnWsOnline) btnWsOnline.className = "px-2.5 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1.5 font-sans";
|
|
694
|
+
if (btnWsLocal) btnWsLocal.className = "px-2.5 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1.5 font-sans";
|
|
695
|
+
|
|
696
|
+
inputHeaderTitle.value = config.title;
|
|
697
|
+
selectLauncherIcon.value = "bubble";
|
|
698
|
+
selectHeaderAvatar.value = "none";
|
|
699
|
+
if (inputSingleKbId) inputSingleKbId.value = "750";
|
|
700
|
+
if (selectLauncherSize) selectLauncherSize.value = "56px";
|
|
701
|
+
if (selectWidth) selectWidth.value = "360px";
|
|
702
|
+
if (selectHeight) selectHeight.value = "500px";
|
|
703
|
+
if (selectRadius) selectRadius.value = "8px";
|
|
704
|
+
if (btnPosRight) btnPosRight.className = 'px-3 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1';
|
|
705
|
+
if (btnPosLeft) btnPosLeft.className = 'px-3 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1';
|
|
706
|
+
btnDisplayFab.className = 'px-3 py-1.5 text-xs font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5 flex items-center justify-center gap-1.5';
|
|
707
|
+
btnDisplayEmbedded.className = 'px-3 py-1.5 text-xs font-medium rounded-md text-neutral-600 hover:text-neutral-900 transition-all flex items-center justify-center gap-1.5';
|
|
708
|
+
btnMountMinTrue.className = 'px-3 py-1.5 text-xs font-mono font-medium rounded-md transition-all shadow-xs bg-white text-neutral-900 border border-black/5';
|
|
709
|
+
btnMountMinFalse.className = 'px-3 py-1.5 text-xs font-mono font-medium rounded-md text-neutral-500 hover:text-neutral-900 transition-all';
|
|
710
|
+
if (startStateContainer) startStateContainer.style.display = 'block';
|
|
711
|
+
if (launcherIconContainer) launcherIconContainer.style.display = 'block';
|
|
712
|
+
|
|
713
|
+
setKbMode("multi", false);
|
|
714
|
+
setTab("multi");
|
|
715
|
+
applyThemeColor("#007A78");
|
|
716
|
+
logEvent("config:reset_defaults");
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// Copy Code Snippet
|
|
721
|
+
copyCodeBtn.addEventListener('click', () => {
|
|
722
|
+
const opts = resolveOptions();
|
|
723
|
+
let codeText = "";
|
|
724
|
+
if (config.activeTab === "single") {
|
|
725
|
+
codeText = `// 1. Single Knowledge Base Direct Integration
|
|
726
|
+
import { initChat } from "akvo-rag-js";
|
|
727
|
+
import "akvo-rag-js/dist/akvo-rag.css";
|
|
728
|
+
|
|
729
|
+
const chat = initChat({
|
|
730
|
+
wsURL: "${opts.wsURL}",
|
|
731
|
+
kb_id: ${config.kb_id}, // Direct session bypasses selection picker
|
|
732
|
+
title: "${opts.title}",
|
|
733
|
+
primaryColor: "${opts.primaryColor}",
|
|
734
|
+
showLauncher: ${opts.showLauncher},
|
|
735
|
+
startMinimized: ${opts.startMinimized},
|
|
736
|
+
width: "${opts.width}",
|
|
737
|
+
height: "${opts.height}",
|
|
738
|
+
position: "${opts.position}",
|
|
739
|
+
borderRadius: "${opts.borderRadius}",
|
|
740
|
+
launcherSize: "${opts.launcherSize}"
|
|
741
|
+
});`;
|
|
742
|
+
} else if (config.activeTab === "multi") {
|
|
743
|
+
codeText = `// 2. Multi-Knowledge Base Options Picker Integration
|
|
744
|
+
import { initChat } from "akvo-rag-js";
|
|
745
|
+
import "akvo-rag-js/dist/akvo-rag.css";
|
|
746
|
+
|
|
747
|
+
const chat = initChat({
|
|
748
|
+
wsURL: "${opts.wsURL}",
|
|
749
|
+
title: "${opts.title}",
|
|
750
|
+
primaryColor: "${opts.primaryColor}",
|
|
751
|
+
showLauncher: ${opts.showLauncher},
|
|
752
|
+
startMinimized: ${opts.startMinimized},
|
|
753
|
+
width: "${opts.width}",
|
|
754
|
+
height: "${opts.height}",
|
|
755
|
+
position: "${opts.position}",
|
|
756
|
+
borderRadius: "${opts.borderRadius}",
|
|
757
|
+
launcherSize: "${opts.launcherSize}",
|
|
758
|
+
kb_options: [
|
|
759
|
+
{ "kb_id": 750, "label": "Critical Thinking" }
|
|
760
|
+
]
|
|
761
|
+
});`;
|
|
762
|
+
} else {
|
|
763
|
+
codeText = `<!-- 3. Vanilla HTML / CDN Script Tag Integration -->\n` +
|
|
764
|
+
`<link rel="stylesheet" href="https://unpkg.com/akvo-rag-js/dist/akvo-rag.css">\n` +
|
|
765
|
+
`<script src="https://unpkg.com/akvo-rag-js/dist/akvo-rag.js"><` + `/script>\n\n` +
|
|
766
|
+
`<script>\n` +
|
|
767
|
+
` document.addEventListener('DOMContentLoaded', function () {\n` +
|
|
768
|
+
` AkvoRagChatbox.initChat({\n` +
|
|
769
|
+
` wsURL: "${opts.wsURL}",\n` +
|
|
770
|
+
` ${config.kbMode === 'single' ? `kb_id: ${config.kb_id},` : `kb_options: [\n { "kb_id": 750, "label": "Critical Thinking" }\n ],`}\n` +
|
|
771
|
+
` title: "${opts.title}",\n` +
|
|
772
|
+
` primaryColor: "${opts.primaryColor}",\n` +
|
|
773
|
+
` showLauncher: ${opts.showLauncher},\n` +
|
|
774
|
+
` startMinimized: ${opts.startMinimized}\n` +
|
|
775
|
+
` });\n` +
|
|
776
|
+
` });\n` +
|
|
777
|
+
`<` + `/script>`;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
navigator.clipboard.writeText(codeText).then(() => {
|
|
781
|
+
copyBtnLabel.textContent = 'Copied!';
|
|
782
|
+
setTimeout(() => {
|
|
783
|
+
copyBtnLabel.textContent = 'Copy';
|
|
784
|
+
}, 1800);
|
|
785
|
+
});
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
// Layout View Toggle
|
|
789
|
+
const togglePreviewViewBtn = document.getElementById('togglePreviewViewBtn');
|
|
790
|
+
const workspaceGrid = document.getElementById('workspaceGrid');
|
|
791
|
+
if (togglePreviewViewBtn && workspaceGrid) {
|
|
792
|
+
let isStacked = false;
|
|
793
|
+
togglePreviewViewBtn.addEventListener('click', () => {
|
|
794
|
+
isStacked = !isStacked;
|
|
795
|
+
if (isStacked) {
|
|
796
|
+
workspaceGrid.classList.remove('lg:grid-cols-12');
|
|
797
|
+
workspaceGrid.classList.add('grid-cols-1');
|
|
798
|
+
} else {
|
|
799
|
+
workspaceGrid.classList.remove('grid-cols-1');
|
|
800
|
+
workspaceGrid.classList.add('lg:grid-cols-12');
|
|
801
|
+
}
|
|
802
|
+
logEvent(isStacked ? "layout:stacked" : "layout:split");
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// Reactively update telemetry when widget elements are clicked
|
|
807
|
+
document.addEventListener('click', (e) => {
|
|
808
|
+
if (e.target.closest('#akvo-rag-launcher') || e.target.closest('#akvo-rag-close-btn') || e.target.closest('#akvo-rag-header')) {
|
|
809
|
+
setTimeout(updateTelemetry, 50);
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
// Initial Mount
|
|
814
|
+
ensureMount();
|
|
815
|
+
});</script></body></html>
|