Files
orca/mobile/src/session/MobileNativeChatOverlay.tsx
T
Brennan Benson a4aef5bd18 fix(mobile): surface load-earlier failures and stop scroll-retry storms
A failed older-history page silently did nothing: the near-top scroll
trigger kept re-firing the same doomed request, and a rejected transport
request escaped as an unhandled rejection.

Failures (RPC not-ok, error results, rejections) now set an inline
"Couldn't load earlier messages / Tap to retry" header row, and the
scroll trigger stands down until the user retries explicitly or an
authoritative window supersedes the failed page.

Refs STA-3333.
2026-08-04 15:19:38 -07:00

105 lines
4.0 KiB
TypeScript

import { useMemo } from 'react'
import { StyleSheet, View } from 'react-native'
import { MobileNativeChatView, type MobileNativeChatInputLockReason } from './MobileNativeChatView'
import { foldMobileNativeChatMessages } from './mobile-native-chat-render-data'
import type { MobileNativeChatImageAttachments } from './use-mobile-native-chat-image-attachments'
import type { MobileNativeChatController } from './use-mobile-native-chat-controller'
import { useMobileNativeChatStreamingBubble } from './use-mobile-native-chat-streaming-bubble'
type Props = {
controller: MobileNativeChatController
/** Native-chat image attachments: picking adds a composer chip, and sending
* rides the pending images along with the message text (desktop parity). */
images: MobileNativeChatImageAttachments
onMicPress: () => void
micActive: boolean
dictationMode: 'toggle' | 'hold'
onMicPressIn: () => void
onMicPressOut: () => void
inputLockReason: MobileNativeChatInputLockReason | null
/** Latest send failure, rendered inline above the composer. */
sendErrorMessage: string | null
/** Drops that failure once a later send succeeds. */
onClearSendError: () => void
keyboardInset: number
}
/** Keeps the terminal mounted underneath chat so its PTY subscription survives
* view toggles while the native surface owns the visible composer. Also owns
* the streaming gate: this component stays mounted across those toggles, while
* the chat list below it does not. */
export function MobileNativeChatOverlay({
controller,
images,
onMicPress,
micActive,
dictationMode,
onMicPressIn,
onMicPressOut,
inputLockReason,
sendErrorMessage,
onClearSendError,
keyboardInset
}: Props): React.JSX.Element | null {
const session = controller.nativeChatSession
const folded = useMemo(() => foldMobileNativeChatMessages(session.messages), [session.messages])
const streaming = useMobileNativeChatStreamingBubble(
folded,
controller.nativeChatStreamingText,
controller.nativeChatStreamScopeKey,
controller.nativeChatStreamLive
)
if (!controller.showNativeChat) {
return null
}
return (
<View style={styles.overlay}>
<MobileNativeChatView
messages={session.messages}
folded={folded}
status={session.status}
error={session.error}
agent={controller.nativeChatAgent}
agentWorking={controller.nativeChatAgentWorking}
streaming={streaming}
onStop={controller.handleNativeChatStop}
ask={controller.nativeChatAsk}
onAnswerAsk={controller.handleNativeChatAnswerAsk}
onCancelAsk={controller.handleNativeChatCancelAsk}
question={controller.nativeChatQuestion}
onAnswerQuestion={controller.handleNativeChatQuestionAnswer}
permission={controller.nativeChatPermission}
onRespondPermission={controller.handleNativeChatRespondPermission}
onOpenFile={controller.handleNativeChatOpenFile}
hasMore={session.hasMore}
loadingEarlier={session.loadingEarlier}
loadEarlierError={session.loadEarlierError}
onLoadEarlier={session.loadEarlier}
onSend={images.sendNativeChat}
pending={controller.chatPending}
composerText={controller.chatComposerText}
onComposerTextChange={controller.setChatComposerText}
onAttachImage={() => void images.attachImage('library')}
attachments={images.attachments}
onRemoveAttachment={images.removeAttachment}
isAttaching={images.isAttaching}
onMicPress={onMicPress}
micActive={micActive}
dictationMode={dictationMode}
onMicPressIn={onMicPressIn}
onMicPressOut={onMicPressOut}
inputLockReason={inputLockReason}
sendErrorMessage={sendErrorMessage}
onClearSendError={onClearSendError}
filePaths={controller.nativeChatFilePaths}
onNeedFiles={controller.loadNativeChatFiles}
keyboardInset={keyboardInset}
/>
</View>
)
}
const styles = StyleSheet.create({
overlay: StyleSheet.absoluteFillObject
})