Keep queued messages visible across task switches
This commit is contained in:
@@ -667,6 +667,9 @@ private struct PendingView: View {
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
if !pending.imageIds.isEmpty {
|
||||
MessageImages(ids: pending.imageIds)
|
||||
}
|
||||
if !pending.md.isEmpty {
|
||||
MarkdownView(blocks: pending.md)
|
||||
}
|
||||
|
||||
@@ -131,6 +131,8 @@ struct PendingSend: Identifiable {
|
||||
let id: Int
|
||||
let text: String
|
||||
let images: [PendingImage]
|
||||
let imageIds: [String]
|
||||
let local: Bool
|
||||
let queued: Bool
|
||||
let md: [MDBlock]
|
||||
}
|
||||
@@ -221,7 +223,7 @@ final class TranscriptBuilder {
|
||||
|
||||
func showPending(_ text: String, _ images: [PendingImage]) -> () -> Void {
|
||||
pendingIds += 1
|
||||
let entry = PendingSend(id: pendingIds, text: text, images: images, queued: running(), md: trimmed(text).isEmpty ? [] : parseMarkdown(text))
|
||||
let entry = PendingSend(id: pendingIds, text: text, images: images, imageIds: [], local: true, queued: running(), md: trimmed(text).isEmpty ? [] : parseMarkdown(text))
|
||||
pending.append(entry)
|
||||
ctx.run = nil
|
||||
return { [weak self] in
|
||||
@@ -229,8 +231,9 @@ final class TranscriptBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private func confirmPending(_ text: String) {
|
||||
if let i = pending.firstIndex(where: { $0.text == text }) {
|
||||
private func confirmPending(_ text: String, queued: Bool, local: Bool) {
|
||||
let i = queued ? pending.firstIndex { !$0.local && $0.text == text } : nil
|
||||
if let i = i ?? (local ? pending.firstIndex { $0.local && $0.text == text } : nil) {
|
||||
pending.remove(at: i)
|
||||
}
|
||||
}
|
||||
@@ -402,8 +405,21 @@ final class TranscriptBuilder {
|
||||
if sink == nil && ((ev.kind == "agent.message" && parent.isEmpty) || ev.kind == "turn.ended" || ev.kind == "user.message") {
|
||||
dropStream()
|
||||
}
|
||||
if sink == nil && ev.kind == "user.message" && ev.actor != "byre" {
|
||||
confirmPending(str(p, "text") ?? "")
|
||||
if sink == nil && ev.kind == "user.message" {
|
||||
confirmPending(str(p, "text") ?? "", queued: true, local: ev.actor != "byre")
|
||||
}
|
||||
if sink == nil && (ev.kind == "task.merged" || ev.kind == "task.discarded") {
|
||||
pending.removeAll { !$0.local }
|
||||
}
|
||||
if ev.kind == "user.queued" {
|
||||
if sink == nil {
|
||||
let text = str(p, "text") ?? ""
|
||||
confirmPending(text, queued: false, local: true)
|
||||
pendingIds += 1
|
||||
let images = (p["images"] as? [(any Sendable)?] ?? []).map { jsString($0) }
|
||||
pending.append(PendingSend(id: pendingIds, text: text, images: [], imageIds: images, local: false, queued: true, md: trimmed(text).isEmpty ? [] : parseMarkdown(text)))
|
||||
}
|
||||
continue
|
||||
}
|
||||
if ev.kind == "session.context" && sink != nil {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user