Files
orca/src/shared/structured-agent-session-draft-hand-off.ts
T
Brennan Benson b1c804b8d9 fix(native-chat): a message an older build saved behind its Retry no longer flashes "Sending…"
A message an older build left waiting on its Retry is never sent again; once the chat's journal
loads it either comes back to the composer or the host's row shows it. Until then it was drawn as
a message on its way and read "Sending…", so QA saw it flash for a moment before its text went back
to the composer. It is now never drawn as one of this client's sends: no bubble and no notice. The
host's row, when there is one, or the composer is where it shows.
2026-10-04 04:49:54 -07:00

45 lines
1.9 KiB
TypeScript

// A submission's `queuedMessageId` names the queued draft it hands off. The host sends every draft
// under a fresh submission id, so this link, never a draft id compared with a `clientMessageId`,
// is how a client knows the host has taken a message over.
import type { AgentJournalSubmission } from './agent-session-journal-types'
import {
reconcileStructuredAgentSessionOutbox,
type StructuredAgentSessionOutboxEntry
} from './structured-agent-session-outbox'
/** Ids of the queued drafts the journal shows handed off, in any dispatch state. An outbox entry
* under one of these ids belongs to the host: its card or bubble carries the text from here. */
export function handedOffQueuedMessageIds(
submissions: readonly AgentJournalSubmission[]
): Set<string> {
const ids = new Set<string>()
for (const submission of submissions) {
if (submission.queuedMessageId !== undefined) {
ids.add(submission.queuedMessageId)
}
}
return ids
}
/**
* The outbox entries a chat draws as its own sends, read against the journal: an entry the host
* handed off as a queued draft belongs to the host, whatever that hand-off's state, so it leaves
* with no restore. One an older build saved behind its Retry is never drawn either: it is not being
* sent, and the host's row or the composer it comes back to shows it. Every reading of the outbox
* against the journal goes through this.
*/
export function reconcileStructuredAgentSessionOutboxWithQueue(
entries: readonly StructuredAgentSessionOutboxEntry[],
submissions: readonly AgentJournalSubmission[]
): StructuredAgentSessionOutboxEntry[] {
const handedOff = handedOffQueuedMessageIds(submissions)
const drawn = entries.filter(
(entry) => entry.legacyUnsettled !== true && !handedOff.has(entry.clientMessageId)
)
return reconcileStructuredAgentSessionOutbox(
drawn.length === entries.length ? entries : drawn,
submissions
)
}