Files
orca/src/shared/native-chat-transcript-retention.ts
T
NeilandOrca b3965f3205 perf(native-chat): suspend hidden transcript streams (#13622)
* perf(native-chat): suspend hidden transcript streams

* fix(native-chat): keep assembly renders pure

* fix(native-chat): keep a transient error from stranding a revealed chat

- An error snapshot frame no longer latches frameArrived, so the in-flight
  read can still seed the pane instead of leaving it on the error surface.
- Retained history is shown over a full-pane read error for the same source.
- The paged read window survives a hide/reveal; only a source change resets it.

Co-authored-by: Orca <help@stably.ai>

* fix(mobile): match the trimmed native-chat retention signature

The shared retention type no longer takes `loading`, so mobile's call was an
excess-property error that broke the mobile typecheck job. Dropping it also
lets mobile inherit the desktop behavior: a stream error or dropped client
keeps the last transcript instead of swapping it for the error empty state.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-08-11 01:27:25 -07:00

35 lines
1.2 KiB
TypeScript

import type { NativeChatMessage } from './native-chat-types'
export const EMPTY_NATIVE_CHAT_TRANSCRIPT: NativeChatMessage[] = []
export function encodeNativeChatTranscriptIdentity(parts: readonly (string | null)[]): string {
return JSON.stringify(parts)
}
export type NativeChatTranscriptRetention = {
capture: (identity: string, messages: NativeChatMessage[]) => void
visible: (args: {
identity: string
messages: NativeChatMessage[]
settled: boolean
}) => NativeChatMessage[]
}
/** Retains one settled transcript so a same-source rebind does not blank the conversation. */
export function createNativeChatTranscriptRetention(): NativeChatTranscriptRetention {
let captured: { identity: string; messages: NativeChatMessage[] } | null = null
return {
capture(identity, messages) {
captured = { identity, messages }
},
visible({ identity, messages, settled }) {
if (settled) {
return messages
}
// An unsettled read includes a failed one: retained history beats blanking the pane for a transient error.
return captured?.identity === identity ? captured.messages : EMPTY_NATIVE_CHAT_TRANSCRIPT
}
}
}