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 chat's composer waits while a new chat is being made
raullopez-sandbox05d3422507fd
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsxindex a91a1b88f..ef0eeb138 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsx@@ -6,6 +6,7 @@ import { SERVER_TOO_OLD_FOR_ACTIVITY } from '@shared/core/chats/activity';import type { ChatMessage, ChatSummary } from '@shared/core/chats/chats';import { useChatPeople } from '../chat-people';import { readThroughSeq } from '../read-progress';+import { directChats } from '../start-direct-chat';import { agentActivities } from '../stores/activities';import type { AgentActivity } from '../stores/chat-activity-store';import type { ChatTimeline } from '../stores/chat-timeline-store';@@ -194,11 +195,10 @@ export const ChatPanel = observer(function ChatPanel({activity={activities[0] ?? null}replyTo={replyTo}onClearReply={() => setReplyTo(null)}- disabled={- chatsStore.streamState === 'offline' && !timeline.loaded- ? 'Switch cannot be reached right now.'- : null- }+ disabled={composerBlocked({+ offline: chatsStore.streamState === 'offline' && !timeline.loaded,+ startingNewChat: directChats.starting,+ })}/></div>);@@ -263,6 +263,20 @@ const ReadWhileFollowing = observer(function ReadWhileFollowing({return null;});+/**+ * Why the composer takes nothing now, or null. While a new chat is being+ * made, this one's composer waits: a quick send would land here, in the chat+ * being left, just before the new one opens.+ */+export function composerBlocked(state: {+ offline: boolean;+ startingNewChat: boolean;+}): string | null {+ if (state.startingNewChat) return 'Starting a new chat…';+ if (state.offline) return 'Switch cannot be reached right now.';+ return null;+}+/*** Sending from here jumps to the end and resumes following, wherever the* reader had scrolled to: what they just sent is what they want to see.diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/direct-chat-starter.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/direct-chat-starter.tsindex 4b9670c88..94d1b80f0 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/direct-chat-starter.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/direct-chat-starter.ts@@ -1,3 +1,4 @@+import { observable } from 'mobx';import type { ChatSummary } from '@shared/core/chats/chats';import { chatFailure } from './chat-errors';@@ -27,11 +28,16 @@ export type DirectChatStarterDeps = {* rather than making another.*/export class DirectChatStarter {- private readonly inFlight = new Set<string>();+ private readonly inFlight = observable.set<string>();private readonly retryIds = new Map<string, string>();constructor(private readonly deps: DirectChatStarterDeps) {}+ /** A new chat is being made: until it opens, a message typed now has no right room to go to. */+ get starting(): boolean {+ return this.inFlight.size > 0;+ }+async start(serverId: string, agentId: string): Promise<ChatSummary | null> {const existing = this.deps.findEmpty(agentId);if (existing) {diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsxindex bd8406159..35a603129 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsx+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsx@@ -10,6 +10,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';// Geometry is the subject, so the real utility classes must be present.import '@renderer/index.css';import { ChatComposer } from '@renderer/features/chats/components/chat-composer';+import { composerBlocked } from '@renderer/features/chats/components/chat-panel';import {ChatTimeline,type TimelineApi,@@ -196,3 +197,44 @@ describe('ChatComposer on a server without group chats', () => {}});});++describe('ChatComposer while a new chat is being made', () => {+ it('sends nothing to the chat being left, and keeps the draft', async () => {+ const send = vi.fn();+ const timeline = new ChatTimeline('room-old', {} as TimelineApi);+ timeline.send = send;+ const composer = (disabled: string | null) => (+ <QueryClientProvider client={new QueryClient()}>+ <ChatComposer+ serverId="s"+ timeline={timeline}+ agents={[agent]}+ people={[]}+ groupName={null}+ activity={null}+ replyTo={null}+ onClearReply={() => {}}+ disabled={disabled}+ />+ </QueryClientProvider>+ );+ const textarea = await render(composer(null));+ await act(async () => {+ textarea.focus();+ document.execCommand('insertText', false, 'for the old chat?');+ });+ // The new chat is being made: the composer waits.+ await act(async () =>+ root!.render(composer(composerBlocked({ offline: false, startingNewChat: true })))+ );+ const waiting = container!.querySelector('textarea')!;+ expect(waiting.disabled).toBe(true);+ expect(waiting.placeholder).toBe('Starting a new chat…');+ await act(async () => {+ waiting.form?.requestSubmit();+ });+ expect(send).not.toHaveBeenCalled();+ // The draft is the old chat's still, not sent anywhere.+ expect(waiting.value).toBe('for the old chat?');+ });+});diff --git a/console/apps/switch-console-desktop/src/renderer/tests/direct-chat-starter.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/direct-chat-starter.test.tsindex 3ed82ce3f..d083e1fbb 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/direct-chat-starter.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/direct-chat-starter.test.ts@@ -82,3 +82,16 @@ describe('DirectChatStarter', () => {expect(deps.opened).not.toHaveBeenCalled();});});++describe('DirectChatStarter while a chat is being made', () => {+ it('says it is starting until the create answers, so other composers wait', async () => {+ let finish: (value: ChatSummary) => void = () => {};+ const { starter } = setup(() => new Promise((resolve) => (finish = resolve)));+ expect(starter.starting).toBe(false);+ const started = starter.start('s1', 'a1');+ expect(starter.starting).toBe(true);+ finish(chat);+ await started;+ expect(starter.starting).toBe(false);+ });+});