The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep drafts editable while connecting
Ayush Nangia3a980a431b28
diff --git a/apps/desktop/src/app/chat/composer/composer-utils.test.ts b/apps/desktop/src/app/chat/composer/composer-utils.test.tsindex 746115002cf..5f523e844f2 100644--- a/apps/desktop/src/app/chat/composer/composer-utils.test.ts+++ b/apps/desktop/src/app/chat/composer/composer-utils.test.ts@@ -7,6 +7,7 @@ import {isPendingDraftPersistCurrent,type PendingDraftPersist,pickPlaceholder,+ shouldDisableComposerInput,slashArgStage,slashChipKindForItem,slashCommandToken,@@ -16,6 +17,26 @@ import {const item = (group: string): Unstable_TriggerItem =>({ id: 'x', type: 'slash', label: 'x', metadata: { group } }) as unknown as Unstable_TriggerItem+describe('shouldDisableComposerInput', () => {+ it.each(['idle', 'connecting', 'closed', 'error'] as const)(+ 'keeps the draft editable while the gateway is %s',+ gatewayState => {+ expect(shouldDisableComposerInput(true, gatewayState)).toBe(false)+ }+ )++ it('fails closed when connection atoms disagree about an open gateway', () => {+ expect(shouldDisableComposerInput(true, 'open')).toBe(true)+ })++ it.each(['idle', 'connecting', 'open', 'closed', 'error'] as const)(+ 'never disables an otherwise enabled composer while the gateway is %s',+ gatewayState => {+ expect(shouldDisableComposerInput(false, gatewayState)).toBe(false)+ }+ )+})+describe('slashArgStage', () => {it('is true only once the query is past the command name', () => {expect(slashArgStage('personality')).toBe(false)diff --git a/apps/desktop/src/app/chat/composer/composer-utils.ts b/apps/desktop/src/app/chat/composer/composer-utils.tsindex 65b141a0de7..97852c31336 100644--- a/apps/desktop/src/app/chat/composer/composer-utils.ts+++ b/apps/desktop/src/app/chat/composer/composer-utils.ts@@ -1,4 +1,5 @@import type { Unstable_TriggerItem } from '@assistant-ui/core'+import type { ConnectionState } from '@hermes/shared'import type { SlashChipKind } from '@/components/assistant-ui/directive-text'import type { ComposerAttachment } from '@/store/composer'@@ -52,6 +53,18 @@ export const COMPOSER_FADE_BACKGROUND =// unmount/pagehide flushes bypass it.export const DRAFT_PERSIST_DEBOUNCE_MS = 400+/**+ * Keep a reconnecting draft editable so transient gateway dials cannot blur+ * the editor and discard the user's caret. Submission still reads the+ * independent `disabled` prop, so non-open states cannot send.+ *+ * An `open` state paired with `disabled=true` is a transient disagreement+ * between the connection atoms; fail closed until they converge.+ */+export function shouldDisableComposerInput(disabled: boolean, gatewayState: ConnectionState): boolean {+ return disabled && gatewayState === 'open'+}+export const pickPlaceholder = (pool: readonly string[]) => pool[Math.floor(Math.random() * pool.length)]/** Completion items can carry an `action` (set in use-slash-completions) thatdiff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsxindex 3764633db6d..b01381e41d8 100644--- a/apps/desktop/src/app/chat/composer/index.tsx+++ b/apps/desktop/src/app/chat/composer/index.tsx@@ -35,6 +35,7 @@ import {COMPOSER_FADE_BACKGROUND,implicitSlashAcceptIndex,type QueueEditState,+ shouldDisableComposerInput,slashArgStage} from './composer-utils'import { ContextMenu } from './context-menu'@@ -220,8 +221,8 @@ export function ChatBar({const { t } = useI18n()const gatewayState = useStore($gatewayState)- const reconnecting = gatewayState === 'closed' || gatewayState === 'error'- const inputDisabled = disabled && !reconnecting+ const reconnecting = gatewayState !== 'open'+ const inputDisabled = shouldDisableComposerInput(disabled, gatewayState)// The draft engine — detached source of truth (DOM + draftRef + edge// selectors); typing never re-renders the chrome. ChatBar owns `queueEditRef`