feat: chat agent knows current page context (order/product)
Frontend: Layout extracts order/product UUID from URL path and passes
to ChatPanel as contextType/contextId. When on /orders/{uuid}, the
chat knows which order you're viewing.
Backend: System prompt now loads actual entity data for the context:
- Order: order_number, status, line counts (completed/processing/failed)
- Product: name, PIM-ID, category, STEP file status
The AI understands "this order", "current product" etc. Example:
"What's the status of this order?" → agent knows you mean SA-2026-00164
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Outlet, NavLink, useNavigate, Link } from 'react-router-dom'
|
||||
import { Outlet, NavLink, useNavigate, Link, useLocation } from 'react-router-dom'
|
||||
import { LayoutDashboard, Package, Settings, LogOut, FlaskConical, Activity, Library, Plus, SlidersHorizontal, Building2, GitBranch, Image, BellRing, Receipt, Server, Upload, Menu, X, MessageSquare } from 'lucide-react'
|
||||
import { useAuthStore, isAdmin as checkIsAdmin, isPrivileged as checkIsPrivileged } from '../../store/auth'
|
||||
import { clsx } from 'clsx'
|
||||
@@ -36,9 +36,20 @@ const adminOnlyNav = [
|
||||
export default function Layout() {
|
||||
const { user, logout } = useAuthStore()
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false)
|
||||
const [chatOpen, setChatOpen] = useState(false)
|
||||
|
||||
// Extract page context from URL for the chat agent
|
||||
const chatContext = (() => {
|
||||
const path = location.pathname
|
||||
const orderMatch = path.match(/^\/orders\/([0-9a-f-]{36})/)
|
||||
if (orderMatch) return { type: 'order', id: orderMatch[1] }
|
||||
const productMatch = path.match(/^\/products\/([0-9a-f-]{36})/)
|
||||
if (productMatch) return { type: 'product', id: productMatch[1] }
|
||||
return { type: undefined, id: undefined }
|
||||
})()
|
||||
|
||||
const { data: activity } = useQuery({
|
||||
queryKey: ['worker-activity'],
|
||||
queryFn: getWorkerActivity,
|
||||
@@ -260,7 +271,7 @@ export default function Layout() {
|
||||
)}
|
||||
|
||||
{/* Chat panel */}
|
||||
{chatOpen && <ChatPanel open={chatOpen} onClose={() => setChatOpen(false)} />}
|
||||
{chatOpen && <ChatPanel open={chatOpen} onClose={() => setChatOpen(false)} contextType={chatContext.type} contextId={chatContext.id} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user