From 42e3d086e70c62a3f1099e95a7292844ae2b61a7 Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:14:25 +0800 Subject: [PATCH] Import apps/android/src/screens/chat/composer-gate.ts --- .../android/src/screens/chat/composer-gate.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 apps/android/src/screens/chat/composer-gate.ts diff --git a/apps/android/src/screens/chat/composer-gate.ts b/apps/android/src/screens/chat/composer-gate.ts new file mode 100644 index 0000000..7802d6f --- /dev/null +++ b/apps/android/src/screens/chat/composer-gate.ts @@ -0,0 +1,48 @@ +/** + * Composer availability rules for the chat input. + * + * Editing is a local operation: a dropped carrier must never lock the + * `TextInput`, otherwise the draft cannot be continued while the Host is + * unreachable. Sending still requires the authenticated channel, so an offline + * tap must leave the draft untouched instead of entering the submit path that + * clears it before `sendMessage` runs. + */ + +/** Reason a send attempt must not start. */ +export type SubmitIntent = 'submit' | 'offline' | 'ignore' + +export type SubmitGateInput = { + /** Authenticated Host channel (Harness/ACP/CodeX ready). */ + connected: boolean + /** Connection plus per-backend readiness and no blocking session action. */ + sendReady: boolean + permissionSelecting: boolean + /** A prompt upload is already in flight. */ + uploading: boolean + /** Live draft/quotes/images/files produced by the caller, not the render closure. */ + hasContent: boolean +} + +export type ComposerEditGateInput = { + permissionSelecting: boolean + uploading: boolean +} + +/** + * Editing stays available while the Host is unreachable; only composer-local + * blocking states (permission switch, in-flight upload) lock the input. + */ +export function composerEditable(input: ComposerEditGateInput): boolean { + return !input.permissionSelecting && !input.uploading +} + +/** + * `offline` means the tap was deliberate but cannot be delivered: the caller + * must return before clearing the draft or creating an optimistic row. + */ +export function submitIntent(input: SubmitGateInput): SubmitIntent { + if (input.uploading || !input.hasContent) return 'ignore' + if (!input.connected) return 'offline' + if (!input.sendReady || input.permissionSelecting) return 'ignore' + return 'submit' +}