diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx index 45d2aad72e428..3e7eec1449e26 100644 --- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx +++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx @@ -249,7 +249,8 @@ export interface ThreadDetailScreenProps { /** Set while the next send compacts the thread first. */ readonly compactBeforeSend?: { readonly tokens: number; - readonly keepFullHistory: () => void; + readonly keepFullHistory: boolean; + readonly toggleKeepFullHistory: () => void; } | null; readonly creationState: | { @@ -1691,11 +1692,19 @@ function ThreadDetailBody( {props.compactBeforeSend ? ( ) : null} diff --git a/apps/mobile/src/state/thread-task-permissions.test.ts b/apps/mobile/src/state/thread-task-permissions.test.ts index 3b43a1451eb41..d037ac106a025 100644 --- a/apps/mobile/src/state/thread-task-permissions.test.ts +++ b/apps/mobile/src/state/thread-task-permissions.test.ts @@ -346,15 +346,23 @@ describe("mobile task permissions", () => { expect.not.objectContaining({ compactBeforeSend: true }), ); state.draft = { ...state.draft, modelSelection: undefined }; - composer.compactBeforeSend?.keepFullHistory(); + composer.compactBeforeSend?.toggleKeepFullHistory(); const kept = useThreadComposerState(NO_SIDE_CHATS); - expect(kept.compactBeforeSend).toBeNull(); - await kept.onSendMessage(); + expect(kept.compactBeforeSend?.keepFullHistory).toBe(true); + kept.compactBeforeSend?.toggleKeepFullHistory(); + const compactAgain = useThreadComposerState(NO_SIDE_CHATS); + expect(compactAgain.compactBeforeSend?.keepFullHistory).toBe(false); + await compactAgain.onSendMessage(); + expect(state.enqueue).toHaveBeenLastCalledWith( + expect.objectContaining({ compactBeforeSend: true }), + ); + compactAgain.compactBeforeSend?.toggleKeepFullHistory(); + await useThreadComposerState(NO_SIDE_CHATS).onSendMessage(); expect(state.enqueue).toHaveBeenLastCalledWith( expect.not.objectContaining({ compactBeforeSend: true }), ); // Keeping covers one send, as on web. - expect(useThreadComposerState(NO_SIDE_CHATS).compactBeforeSend?.tokens).toBe(248_000); + expect(useThreadComposerState(NO_SIDE_CHATS).compactBeforeSend?.keepFullHistory).toBe(false); state.freshPending = true; await composer.onSendMessage(); expect(state.enqueue).toHaveBeenLastCalledWith( diff --git a/apps/mobile/src/state/use-thread-composer-state.ts b/apps/mobile/src/state/use-thread-composer-state.ts index 896adc53f5203..8a762e88c97c6 100644 --- a/apps/mobile/src/state/use-thread-composer-state.ts +++ b/apps/mobile/src/state/use-thread-composer-state.ts @@ -892,11 +892,12 @@ export function useThreadComposerState(input: { providerSubagentStatus, isCompacting, compactBeforeSend: - compactTokens === null || selectedThreadKey === null || keepFullHistory + compactTokens === null || selectedThreadKey === null ? null : { tokens: compactTokens, - keepFullHistory: () => setKeepFullHistory(selectedThreadKey, true), + keepFullHistory, + toggleKeepFullHistory: () => setKeepFullHistory(selectedThreadKey, !keepFullHistory), }, composerDraftKey, followUpBehavior,