This skill helps you deploy a production-ready ChatGPT-style chatbot widget with SSE streaming, RAG backend, and performance monitoring.
npx playbooks add skill mrowaisabdullah/ai-humanoid-robotics --skill chatbot-widget-creator
Creates a production-ready ChatGPT-style chatbot widget with advanced features:
var(--ifm-color-primary) to match host site brandingMessageBubblePOST /api/chat returning Server-Sent Events{ "question": string, "stream": boolean }{ "type": "chunk", "content": string } npm install react framer-motion react-markdown react-syntax-highlighter remark-gfm lucide-react clsx tailwind-merge
# Note: No ChatKit dependency - this is a custom implementation
# Create main directory structure
mkdir -p src/components/ChatWidget/{components,hooks,contexts,utils,styles}
# Copy all template files
cp -r .claude/skills/chatbot-widget-creator/templates/* src/components/ChatWidget/
Your backend must implement:
@app.post("/api/chat")
async def chat_endpoint(request: ChatRequest):
"""Chat endpoint with Server-Sent Events streaming."""
# Request format
{
"question": "What is physical AI?",
"stream": true,
"context": { # Optional
"selectedText": "...",
"source": "User selection"
}
}
# Response format (SSE)
data: {"type": "start", "session_id": "..."}
data: {"type": "chunk", "content": "Physical AI refers to..."}
data: {"type": "chunk", "content": "embodied AI systems..."}
data: {"type": "done", "session_id": "..."}
Add to your site root (e.g., src/theme/Root.tsx):
import React from 'react';
import AnimatedChatWidget from '../components/ChatWidget/components/AnimatedChatWidget';
export default function Root({ children }) {
const getChatEndpoint = () => {
const hostname = window.location.hostname;
if (hostname === 'localhost') {
return 'http://localhost:7860/api/chat';
}
return 'https://your-domain.com/api/chat';
};
return (
<>
{children}
<AnimatedChatWidget
apiUrl={getChatEndpoint()}
maxTextSelectionLength={2000}
fallbackTextLength={5000}
/>
</>
);
}
// Consolidated state to prevent fragmentation
interface ChatState {
messages: ChatMessage[];
isOpen: boolean;
isThinking: boolean;
currentStreamingId?: string;
error: Error | null;
renderCount: number;
}
// Split context pattern
const ChatStateContext = createContext<{ state: ChatState }>();
const ChatActionsContext = createContext<{ actions: ChatActions }>();
// Components only subscribe to what they need
const messages = useChatSelector(s => s.messages); // Re-renders on messages change
const actions = useChatActions(); // Never re-renders
// Bad - causes context fragmentation
const [messages, setMessages] = useState([]);
const [isOpen, setIsOpen] = useState(false);
// Good - single state source
const [state, dispatch] = useReducer(chatReducer, initialState);
// Bad - callback depends on state that changes
const handleChunk = useCallback((chunk) => {
if (session.currentStreamingId) { // Dependency on state
updateMessage(session.currentStreamingId, chunk);
}
}, [session.currentStreamingId]); // Infinite re-render!
// Good - no circular dependencies
const streamingIdRef = useRef<string>();
const handleChunk = useCallback((chunk) => {
if (streamingIdRef.current) {
dispatch(updateStreamingAction(streamingIdRef.current, chunk));
}
}, [dispatch]); // Stable dependency array
// Proper SSE parsing
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = line.slice(6);
if (data !== '[DONE]') {
const parsed = JSON.parse(data);
if (parsed.type === 'chunk' && parsed.content) {
handleChunk(parsed.content);
} else if (parsed.type === 'done') {
handleComplete();
}
}
}
}
Edit src/components/ChatWidget/styles/ChatWidget.module.css:
/* Primary colors */
.widget {
background: #171717; /* Dark mode background */
width: 380px;
height: 700px;
}
/* Message bubbles */
.userMessageBubble {
background: var(--ifm-color-primary); /* Theme integration */
color: white;
}
.aiMessageBubble {
background: #21262d;
border: 1px solid #30363d;
}
window.performance.memorytext/event-streamdata: {} formatCache-Control: no-cache is setstream: true in the bodyhandleChunk(JSON.parse(data).content) not the raw stringuseTextSelection is enableduser-select: none conflictslist-style-position: inside on ul/olp margins in lists: li > p { margin: 0; display: inline; }.messageRenderer, headings, and lists in light mode media queries or classes.aiMessageBubble background is transparent or correctly coloredp, ul, ol (e.g., 0.25rem).messageRenderer > *:first-child { margin-top: 0; }!important if global site styles (like Docusaurus) override your chat styles.aiMessage { display: grid; align-items: end; }A production-ready chat widget that:
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.