# RagStack Chat Component AI chat with source attribution for **any web framework**. Integrates with AWS Bedrock Knowledge Base. ## Quick Start - Web Component (Any Framework) Use the chat in Vue, Angular, Svelte, or vanilla JavaScript: ```html ``` **Get CDN URL:** Dashboard → Chat tab → Embed Chat Widget section ## Dashboard Chat Tab The Chat tab in the admin dashboard provides: ### System Prompt Editor Customize the AI assistant's behavior by editing the system prompt. Changes apply immediately to new conversations. **Location:** Chat tab → System Prompt (expandable section) ### Embed Code Generator Get ready-to-use embed code with your CDN URL pre-filled: - **Basic (Public):** For unauthenticated access - **Authenticated:** Includes user-id and user-token attributes with example JavaScript **Location:** Chat tab → Embed Chat Widget (expandable section) ## Quick Start - React Component For React applications: ```bash npm install @ragstack/ragstack-chat ``` ```tsx import { ChatWithSources } from '@ragstack/ragstack-chat'; export function App() { return ( ); } ``` ## Configuration ### Props | Prop | Type | Default | Description | |------|------|---------|-------------| | `conversationId` | string (UUID) | auto-generated | Unique conversation ID (must be a valid UUID v4; auto-generated if omitted or invalid) | | `headerText` | string | `"Document Q&A"` | Header title | | `headerSubtitle` | string | `"Ask questions about your documents"` | Header subtitle | | `inputPlaceholder` | string | `"Ask a question..."` | Input field placeholder | | `showSources` | boolean | `true` | Show/hide sources | | `maxWidth` | string | `"100%"` | Component width | | `userId` | string \| null | `null` | User ID for authenticated mode | | `userToken` | string \| null | `null` | Auth token for authenticated mode | | `className` | string | - | Additional CSS class | | `onSendMessage` | function | - | Callback when user sends message | | `onResponseReceived` | function | - | Callback when AI responds | ### Callbacks ```tsx // When user sends a message onSendMessage={(message: string, conversationId: string) => { console.log(`${conversationId}: ${message}`); }} // When AI responds onResponseReceived={(response: ChatMessage) => { console.log('Response:', response.content); console.log('Sources:', response.sources); }} ``` ## Source Citations ### Collapsible Sources Source citations appear below each AI response in a collapsible UI: - **Default state:** Collapsed (clean UI) - **Expand/collapse:** Click "Show/Hide" button - **Persistence:** State saved in sessionStorage (persists on page refresh) - **Accessibility:** Keyboard navigable (Tab + Enter), screen reader support ```tsx // Example document source { title: "financial-report-2024.pdf", location: "chunk-005", snippet: "Q4 revenue was $2.3M...", documentUrl: "https://s3.amazonaws.com/...", // Optional documentAccessAllowed: true // Configuration flag } // Example media source (video/audio) { title: "team-meeting.mp4", location: "1:30-2:00", // Timestamp range snippet: "We discussed the Q4 targets...", documentUrl: "https://s3.amazonaws.com/...#t=90,120", // URL with timestamp fragment isMedia: true, mediaType: "video", // "video" or "audio" timestampStart: 90, // seconds timestampEnd: 120, speaker: "speaker_0" // When diarization enabled } ``` ### Document Downloads When `chat_allow_document_access` is enabled (admin UI -> Configuration): - **"View Document" links** appear in source citations - **Presigned S3 URLs** for original uploaded files (not vector chunks) - **1-hour expiry** for security - **Read-only access** (no modification) **User experience:** 1. User sends query -> AI responds with sources 2. User expands sources -> sees snippets + "View Document" links 3. User clicks link -> original PDF/image/doc downloads 4. URL expires after 1 hour **Admin controls:** - Toggle on/off in real-time (no redeployment) - Changes take effect on the next Lambda invocation (request-scoped cache) ### Media Sources (Video/Audio) When sources come from video or audio files: - **Timestamp display:** Shows time range (e.g., "1:30-2:00") - **Click to play:** Opens inline player at that timestamp - **Speaker label:** Shows speaker ID when diarization is enabled - **Inline player:** HTML5 video/audio player embedded in source citation **URL format:** Presigned S3 URLs include `#t=start,end` media fragment for automatic seeking. **Player features:** - Play/pause controls - Seek bar - Volume control - Compact inline display (max 400px width for video) ### Accessibility Features - **Keyboard navigation:** Tab to navigate, Enter/Space to activate - **Screen reader support:** ARIA labels, state announcements - **Focus indicators:** Visible focus outlines on all interactive elements - **Semantic HTML:** `