feat: command palette, PSA ticket context, session-to-flow converter #108

Merged
chihlasm merged 27 commits from feat/command-palette-session-flow-psa-context into main 2026-03-16 17:39:17 +00:00
Showing only changes of commit 2d602f687b - Show all commits

View File

@@ -1,4 +1,5 @@
import { useState, useEffect, useRef, useCallback } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { Sparkles, Send, Loader2, Flag } from 'lucide-react'
import { PageMeta } from '@/components/common/PageMeta'
import { assistantChatApi } from '@/api/assistantChat'
@@ -14,6 +15,8 @@ interface MessageWithMeta extends ChatMessageType {
}
export default function AssistantChatPage() {
const location = useLocation()
const navigate = useNavigate()
const [chats, setChats] = useState<ChatListItem[]>([])
const [activeChatId, setActiveChatId] = useState<string | null>(null)
const [messages, setMessages] = useState<MessageWithMeta[]>([])
@@ -22,12 +25,56 @@ export default function AssistantChatPage() {
const [showConclude, setShowConclude] = useState(false)
const messagesEndRef = useRef<HTMLDivElement>(null)
const inputRef = useRef<HTMLTextAreaElement>(null)
const prefillHandledRef = useRef(false)
// Load chat list
useEffect(() => {
loadChats()
}, [])
// Handle prefill from command palette handoff
useEffect(() => {
const prefill = (location.state as { prefill?: string } | null)?.prefill
if (!prefill || prefillHandledRef.current) return
prefillHandledRef.current = true
// Clear the location state so back-navigation doesn't retrigger
navigate(location.pathname, { replace: true, state: {} })
const sendPrefill = async () => {
try {
const chat = await assistantChatApi.createChat()
setChats(prev => [
{ id: chat.id, title: chat.title, message_count: 0, pinned: false, created_at: chat.created_at, updated_at: chat.updated_at },
...prev,
])
setActiveChatId(chat.id)
setMessages([{ role: 'user', content: prefill }])
setLoading(true)
const response = await assistantChatApi.sendMessage(chat.id, prefill)
setMessages(prev => [
...prev,
{ role: 'assistant', content: response.content, suggestedFlows: response.suggested_flows },
])
setChats(prev =>
prev.map(c =>
c.id === chat.id
? { ...c, message_count: 2, title: prefill.slice(0, 100), updated_at: new Date().toISOString() }
: c
)
)
} catch {
toast.error('Failed to start AI conversation')
} finally {
setLoading(false)
}
}
sendPrefill()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
// Auto-scroll
useEffect(() => {
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' })