Spaces:
Sleeping
Sleeping
delete: toggle mode chat
Browse filesFiles changed (4)
23 unmodified lines242526272829303127282930313233115 unmodified lines14915015115315415515615715815916016116216316416516616716816917015215315415519 unmodified lines1751761771961781791801818 unmodified lines190191192211193194195196132 unmodified lines32933033135033233333433523 unmodified lines2. [Authentication](#2-authentication)3. [URL Parameters Reference](#3-url-parameters-reference)4. [Theming & Customization](#4-theming--customization)5. [Chat Mode](#5-chat-mode)6. [postMessage Events](#6-postmessage-events)7. [Session Persistence](#7-session-persistence)8. [Full Integration Examples](#8-full-integration-examples)9. [Troubleshooting](#9-troubleshooting)5. [postMessage Events](#5-postmessage-events)6. [Session Persistence](#6-session-persistence)7. [Full Integration Examples](#7-full-integration-examples)8. [Troubleshooting](#8-troubleshooting)
---
115 unmodified lines
---
### 5. Chat Mode
Chat mode dikonfigurasi di sisi **server** (bukan via URL), melalui environment variable `RAG_CHAT_MODE`.
| Mode | Keterangan ||------------|------------|| `standard` | *(default)* Chat berbasis sesi. Riwayat percakapan tersimpan dan bisa diakses kembali via tab Riwayat. || `direct` | Setiap pesan dikirim langsung ke endpoint `/ai/query` tanpa membuat sesi. Cocok untuk one-shot Q&A tanpa history. |
Atur di file `.env`:
```envRAG_CHAT_MODE=direct```
---
### 6. postMessage Events### 5. postMessage Events
Widget berkomunikasi dengan halaman induk melalui `window.postMessage`. Dengarkan event ini di halaman yang meng-embed iframe untuk mendapat notifikasi dari widget.
19 unmodified lines
---
### 7. Session Persistence### 6. Session Persistence
Widget menyimpan data sesi di `sessionStorage` browser (bukan `localStorage`), sehingga **otomatis terhapus saat tab ditutup**.
8 unmodified lines
---
### 8. Full Integration Examples### 7. Full Integration Examples
#### 8.1 Embed Sederhana (API Key)
132 unmodified lines
---
### 9. Troubleshooting### 8. Troubleshooting
#### Widget menampilkan "Token iframe tidak tersedia"
36 unmodified lines3738394040414236 unmodified lines
'rag' => [ 'base_url' => env('RAG_API_BASE_URL'), 'chat_mode' => env('RAG_CHAT_API_MODE', 'stream'), ],
];28 unmodified lines2930313232333413 unmodified lines484950525354515253405 unmodified lines459460461466462463464465161 unmodified lines62762862963463563663763863964063063163263363463563663728 unmodified lines listChatSessionsEmbed, listCoursesEmbed, loginWithEmbedApiKey, queryAiDirect, sendRestChatMessage,} from '@/lib/rag-client';
13 unmodified lines userName: string;};
type EmbedPageProps = { isDirectChatMode?: boolean;};
const COLOR_DEFAULTS = { background: '#ffffff',405 unmodified lines );}
export default function Embed({ isDirectChatMode = false }: EmbedPageProps) {export default function Embed() { const [config, setConfig] = useState<EmbedConfig>(() => parseEmbedConfig( typeof window !== 'undefined'161 unmodified lines setChatSessions((prev) => [session, ...prev]); }
const assistantMessage = isDirectChatMode ? await queryAiDirect(selectedCourseId, trimmedQuestion, token) : await sendRestChatMessage( currentSessionId, trimmedQuestion, token, ); const assistantMessage = await sendRestChatMessage( currentSessionId, trimmedQuestion, token, );
setAnimatedAssistantMessageId(assistantMessage.uuid_id); setMessages((prev) => [...prev, userMessage, assistantMessage]);13 unmodified lines1415161718191718192013 unmodified lines
Route::inertia('register/dosen', 'auth/register-dosen')->name('register.dosen');
Route::get('embed', fn () => Inertia::render('embed', [ 'isDirectChatMode' => config('services.rag.chat_mode') === 'direct',]))->name('embed');Route::inertia('embed', 'embed')->name('embed');
Route::inertia('admin/login', 'auth/admin-login')->name('admin.login');
README.md+8-26
config/services.php-1
resources/js/pages/embed.tsx+6-12
routes/web.php+1-3