|
@@ -147,7 +147,9 @@ export const useChatStore = defineStore('chat', () => {
|
|
|
})
|
|
})
|
|
|
const ids=new Set(canonical.flatMap(m=>[m.id,m.clientMessageId].filter(Boolean)))
|
|
const ids=new Set(canonical.flatMap(m=>[m.id,m.clientMessageId].filter(Boolean)))
|
|
|
const pending=initial.messages.filter(m=>m.role==='user'&&m.stage!=='settled'&&!ids.has(m.id)&&!ids.has(m.clientMessageId))
|
|
const pending=initial.messages.filter(m=>m.role==='user'&&m.stage!=='settled'&&!ids.has(m.id)&&!ids.has(m.clientMessageId))
|
|
|
- const messages=[...canonical,...pending]
|
|
|
|
|
|
|
+ // Unsent local inputs keep their original time among server messages;
|
|
|
|
|
+ // appending the outbox would move old failures below every new reply.
|
|
|
|
|
+ const messages=mergeChatMessages(canonical,pending)
|
|
|
const {messages:_,...checkpoint}=value
|
|
const {messages:_,...checkpoint}=value
|
|
|
await historyCache.set(scope,id,{messages,total:value.total,savedAt:Date.now(),transcript:checkpoint},true)
|
|
await historyCache.set(scope,id,{messages,total:value.total,savedAt:Date.now(),transcript:checkpoint},true)
|
|
|
const beforeOutbox=current();if(!beforeOutbox)return
|
|
const beforeOutbox=current();if(!beforeOutbox)return
|
|
@@ -157,7 +159,7 @@ export const useChatStore = defineStore('chat', () => {
|
|
|
// the current route after both writes, preserving any newer local send.
|
|
// the current route after both writes, preserving any newer local send.
|
|
|
const latest=current();if(!latest)return
|
|
const latest=current();if(!latest)return
|
|
|
const latestPending=latest.messages.filter(m=>m.role==='user'&&m.stage!=='settled'&&!ids.has(m.id)&&!ids.has(m.clientMessageId))
|
|
const latestPending=latest.messages.filter(m=>m.role==='user'&&m.stage!=='settled'&&!ids.has(m.id)&&!ids.has(m.clientMessageId))
|
|
|
- latest.messages=[...canonical,...latestPending];latest.messageTotal=value.total;latest.loadedMessageCount=canonical.length
|
|
|
|
|
|
|
+ latest.messages=mergeChatMessages(canonical,latestPending);latest.messageTotal=value.total;latest.loadedMessageCount=canonical.length
|
|
|
const approval=value.pendingApproval,clarification=value.pendingClarification
|
|
const approval=value.pendingApproval,clarification=value.pendingClarification
|
|
|
latest.pendingApproval=approval?{id:string(approval.request_id??approval.id),sessionId:id,message:string(approval.message??approval.prompt),toolName:string(approval.tool_name),choices:values(approval.choices).map(String),payload:approval as Record<string,JsonValue>}:undefined
|
|
latest.pendingApproval=approval?{id:string(approval.request_id??approval.id),sessionId:id,message:string(approval.message??approval.prompt),toolName:string(approval.tool_name),choices:values(approval.choices).map(String),payload:approval as Record<string,JsonValue>}:undefined
|
|
|
latest.pendingClarification=clarification?{id:string(clarification.request_id??clarification.id),sessionId:id,question:string(clarification.question??clarification.prompt),payload:clarification as Record<string,JsonValue>}:undefined
|
|
latest.pendingClarification=clarification?{id:string(clarification.request_id??clarification.id),sessionId:id,question:string(clarification.question??clarification.prompt),payload:clarification as Record<string,JsonValue>}:undefined
|