Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(console): a composer moved to another account, workspace or room never carries its draft over
raullopez-sandboxaabf3c24a19c
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsxindex 909d4cdc3..a06c423ad 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsx@@ -192,22 +192,28 @@ export const ChatComposer = observer(function ChatComposer({const [picked, setPicked] = useState<MentionToken[]>(() => readChatDraft(draftKey)?.mentions ?? []);- // The account or workspace became known: what was kept for it wins over what is on screen.- const [readFrom, setReadFrom] = useState(draftKey);- if (readFrom !== draftKey) {- setReadFrom(draftKey);- const kept = readChatDraft(draftKey);- if (kept) {- setDraft(kept.text);- setPicked(kept.mentions);- }- }/** The send that emptied the composer: its text stays kept until the server has taken it. */const [sending, setSending] = useState<string | null>(null);const sendState =sending === null? null: (timeline.pending.find((send) => send.requestId === sending)?.state ?? 'sent');+ // Another account, workspace or room shows its own draft, or none: the one on+ // screen is never carried over. Only typing done before this room's account and+ // workspace were known is kept for them, when they have nothing of their own.+ const [readFrom, setReadFrom] = useState(draftKey);+ if (readFrom !== draftKey) {+ const startup =+ readFrom ===+ chatDraftKey({ serverId, userId: null, workspaceId: null, roomId: timeline.roomId });+ const kept = readChatDraft(draftKey);+ setReadFrom(draftKey);+ if (kept || !startup) {+ setDraft(kept?.text ?? '');+ setPicked(kept?.mentions ?? []);+ setSending(null);+ }+ }useEffect(() => {if (readFrom !== draftKey) return;if (draft === '' && sendState !== null && sendState !== 'sent') return;diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-drafts.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-drafts.test.tsxindex b6dc6cb45..51b0dd801 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-drafts.test.tsx+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-drafts.test.tsx@@ -8,7 +8,7 @@ import { act } from 'react';import { createRoot, type Root } from 'react-dom/client';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-const scope = vi.hoisted(() => ({ userId: 'user-a', workspaceId: 'ws-1' }));+const scope = vi.hoisted(() => ({ userId: 'user-a' as string | null, workspaceId: 'ws-1' }));vi.mock('@renderer/lib/hooks/useFeatureFlags', () => ({useFeatureFlags: () => ({ group_chats: true }),}));@@ -59,10 +59,13 @@ function api(send: TimelineApi['send']): TimelineApi {return { newId: () => `id-${++n}`, send } as unknown as TimelineApi;}+/** Renders the composer for `timeline`; a second call re-renders the same mounted composer. */async function mount(timeline: ChatTimeline): Promise<HTMLTextAreaElement> {- container = document.createElement('div');- document.body.appendChild(container);- root = createRoot(container);+ if (!root) {+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ }await act(async () =>root!.render(<QueryClientProvider client={new QueryClient()}>@@ -80,7 +83,7 @@ async function mount(timeline: ChatTimeline): Promise<HTMLTextAreaElement> {</QueryClientProvider>));- return container.querySelector('textarea')!;+ return container!.querySelector('textarea')!;}async function type(textarea: HTMLTextAreaElement, value: string): Promise<void> {@@ -174,4 +177,36 @@ describe('chat drafts', () => {textarea = await mount(new ChatTimeline('room-1', api(vi.fn())));expect(textarea.value).toBe('do not lose me');});+ it('shows the other room’s draft, or none, in the same composer, and never carries one over', async () => {+ localStorage.setItem(+ key('user-a', 'ws-1', 'room-a'),+ JSON.stringify({ text: '@agent-two only for A', mentions: [keptMention] })+ );+ let textarea = await mount(new ChatTimeline('room-a', api(vi.fn())));+ expect(textarea.value).toBe('@agent-two only for A');++ textarea = await mount(new ChatTimeline('room-b', api(vi.fn())));+ expect(textarea.value).toBe('');+ expect(container!.querySelector('mark')).toBeNull();+ expect(localStorage.getItem(key('user-a', 'ws-1', 'room-b'))).toBeNull();++ // Another account in the same room: its own draft, or none.+ textarea = await mount(new ChatTimeline('room-a', api(vi.fn())));+ expect(textarea.value).toBe('@agent-two only for A');+ scope.userId = 'user-b';+ textarea = await mount(new ChatTimeline('room-a', api(vi.fn())));+ expect(textarea.value).toBe('');+ expect(localStorage.getItem(key('user-b', 'ws-1', 'room-a'))).toBeNull();+ expect(readChatDraft(key('user-a', 'ws-1', 'room-a'))?.text).toBe('@agent-two only for A');+ });++ it('keeps what was typed before the account was known, for that account', async () => {+ scope.userId = null;+ let textarea = await mount(new ChatTimeline('room-1', api(vi.fn())));+ await type(textarea, 'typed while starting');+ scope.userId = 'user-a';+ textarea = await mount(new ChatTimeline('room-1', api(vi.fn())));+ expect(textarea.value).toBe('typed while starting');+ expect(readChatDraft(key('user-a', 'ws-1', 'room-1'))?.text).toBe('typed while starting');+ });});