Files
orca/src/renderer/src/components/native-chat/native-chat-draft-cache.ts
T
Brennan Benson 02ff7c7465 Preserve agent chats and drafts through reconnects (#9242)
* fix(chat): preserve drafts through reconnects

* fix(terminal): bound stale handle reconnect polling

* refactor(chat): extract native view props

* fix(chat): harden reconnect lifecycle

* fix(terminal): replace stale reconnect identities atomically

* fix(terminal): recover mirrors after reconnect polling

* docs(reliability): record merged reconnect coverage

* fix(terminal): preserve reconnect lifecycle state

* fix(terminal): keep reconnect polling truly bounded
2026-07-18 20:31:14 -07:00

29 lines
1.1 KiB
TypeScript

// Module-level cache for the composer's in-progress draft text, keyed by the
// same stable pane scope as image attachments. The composer unmounts when the
// pane toggles back to the hosted terminal, so without this the typed-but-unsent
// draft would be lost on every TUI/GUI round-trip. Mirrors the attachment cache
// so both halves of an unsent message survive toggles and reconnects.
import { setBoundedScopeCacheEntry } from './native-chat-composer-scope-cache'
const draftCache = new Map<string, string>()
export function readNativeChatDraftCache(scopeKey: string): string {
return draftCache.get(scopeKey) ?? ''
}
export function writeNativeChatDraftCache(scopeKey: string, draft: string): void {
// An empty draft carries no state worth retaining; drop the entry so a stale
// scope key never resurrects cleared text.
if (draft === '') {
draftCache.delete(scopeKey)
return
}
// LRU-bounded so unsent drafts for permanently-removed panes can't accumulate.
setBoundedScopeCacheEntry(draftCache, scopeKey, draft)
}
export function clearNativeChatDraftCacheForTests(): void {
draftCache.clear()
}