# Admin Extension The admin chat UI is a React page extension registered under `src/admin/routes//page.tsx`. ## Page Registration ```tsx import { defineRouteConfig } from "@medusajs/admin-sdk" import { ChatBubbleLeftRight } from "@medusajs/icons" export const config = defineRouteConfig({ label: "My Agent", icon: ChatBubbleLeftRight, }) ``` ## Admin UI Component Libraries Only use these — they are bundled with Medusa admin: ```tsx import { useState, useRef, useEffect, useCallback } from "react" import { defineRouteConfig } from "@medusajs/admin-sdk" import { ChatBubbleLeftRight, PlusMini, Wrench, AcademicCap } from "@medusajs/icons" import { Button, Textarea, clx } from "@medusajs/ui" ``` > Do NOT import from `@headlessui`, `shadcn`, or other UI libraries — they are not bundled in the admin. ## Types ```tsx type Message = { id: string role: "user" | "assistant" content: string toolCalls: ToolCall[] } type ToolCall = { tool: string; status: "running" | "done" } type Session = { id: string; title: string | null; created_at: string } ``` ## Full Layout The UI uses a two-column layout: a fixed-width session sidebar on the left and the chat area filling the rest. ```tsx export default function AgentPage() { const [messages, setMessages] = useState([]) const [sessions, setSessions] = useState([]) const [sessionId, setSessionId] = useState(null) const [isStreaming, setIsStreaming] = useState(false) const [input, setInput] = useState("") const bottomRef = useRef(null) useEffect(() => { loadSessions() }, []) useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: "smooth" }) }, [messages]) return (
{/* ── Sidebar ── */}
{sessions.map((s) => ( ))}
{/* ── Main chat area ── */}
{/* Header */}

Store Agent

Ask questions or give commands about your store

{/* Messages */}
{messages.map((msg, i) => ( ))}
{/* Input */}