fix: Prevent permission cards from being lost on PromptBar open
- Connect WebSocket BEFORE loading history to catch real-time permissions - loadHistory() now preserves unresolved intervention cards - loadPendingPermissions() runs AFTER loadHistory() to avoid race condition
This commit is contained in:
@@ -561,6 +561,9 @@ async function loadHistory(sessionId?: string) {
|
||||
const data = await res.json()
|
||||
activeSessionId.value = data.sessionId || null
|
||||
|
||||
// Preserve unresolved intervention cards (permissions, questions, plans)
|
||||
const pendingInterventions = messages.filter(m => m.intervention && !m.intervention.resolved)
|
||||
|
||||
messages.length = 0
|
||||
idCounter = 0
|
||||
|
||||
@@ -575,6 +578,14 @@ async function loadHistory(sessionId?: string) {
|
||||
})
|
||||
}
|
||||
|
||||
// Re-add preserved intervention cards at the end
|
||||
for (const intv of pendingInterventions) {
|
||||
const rid = intv.intervention?.requestId
|
||||
if (rid && messages.some(m => m.intervention?.requestId === rid)) continue
|
||||
intv.id = ++idCounter
|
||||
messages.push(intv)
|
||||
}
|
||||
|
||||
// Extract session stats
|
||||
if (data.model || data.stats) {
|
||||
sessionStats.value = {
|
||||
@@ -680,18 +691,19 @@ watch(() => props.visible, async (v) => {
|
||||
|
||||
console.log('[PromptBar] Opening for agent:', props.agent.id)
|
||||
|
||||
// Load real conversation history + sessions list + global stats + usage
|
||||
await Promise.all([loadHistory(), fetchSessions(), fetchClaudeStats(), fetchClaudeUsage(), loadPendingPermissions()])
|
||||
|
||||
console.log('[PromptBar] Loaded', messages.length, 'messages, sessions:', sessions.value.length)
|
||||
|
||||
// Connect WebSocket for real-time updates
|
||||
// Connect WebSocket FIRST so real-time permission messages aren't missed
|
||||
connectWs()
|
||||
|
||||
// Connect agent terminal (lazy)
|
||||
agentTerminal.connect()
|
||||
agentTerminal.checkStatus()
|
||||
|
||||
// Load history + stats (loadHistory preserves any intervention cards added by WS)
|
||||
await Promise.all([loadHistory(), fetchSessions(), fetchClaudeStats(), fetchClaudeUsage()])
|
||||
|
||||
// Load pending permissions AFTER history so they aren't wiped
|
||||
await loadPendingPermissions()
|
||||
|
||||
console.log('[PromptBar] Loaded', messages.length, 'messages, sessions:', sessions.value.length)
|
||||
|
||||
await voice.init()
|
||||
await nextTick()
|
||||
if (props.startRecording) {
|
||||
|
||||
Reference in New Issue
Block a user