Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(console): chats come back after signing out and in again in the same window

raullopez-sandboxbbbcb2cc4d11
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.ts
index 8e14af3ae..bc77fb053 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.ts
@@ -108,12 +108,29 @@ export class ChatsStore {
events.onReset(({ serverId }) => this.reset(serverId));
}
- /** Follow the server the window is scoped to; `key` changes with the workspace. */
+ /**
+ * Follow the server the window is scoped to; `key` changes with the workspace
+ * and the account signed in there. A new key on the same server starts over:
+ * the feed is opened again under the new sign-in, and nothing of the last
+ * account's chats is kept.
+ */
follow(read: () => { serverId: string | null; key: string | null }): () => void {
- return reaction(read, ({ serverId }) => void this.connect(serverId), {
- fireImmediately: true,
- equals: (a, b) => a.serverId === b.serverId && a.key === b.key,
- });
+ let following: string | null = null;
+ return reaction(
+ read,
+ ({ serverId }) => {
+ const again = serverId !== null && serverId === following;
+ following = serverId;
+ void (async () => {
+ if (again) await this.connect(null);
+ await this.connect(serverId);
+ })();
+ },
+ {
+ fireImmediately: true,
+ equals: (a, b) => a.serverId === b.serverId && a.key === b.key,
+ }
+ );
}
async connect(serverId: string | null): Promise<void> {
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats.ts
index 229050529..ac6c79f9b 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats.ts
@@ -52,7 +52,9 @@ chatsStore.follow(() => {
const serverId = workspacesStore.activeServerId;
const active = workspacesStore.active;
if (!serverId || agentChatsFlag(serverId) !== true) return { serverId: null, key: null };
- return { serverId, key: active ? `${active.id}:${active.tenantId}` : null };
+ // Signing out and in again, or as someone else, is a new key: the feed opens again for it.
+ const userId = switchServersStore.statusFor(serverId)?.user?.id ?? null;
+ return { serverId, key: active ? `${active.id}:${active.tenantId}:${userId}` : null };
});
// Server status is otherwise read again only on focus; until it is, the sidebar asks a server it thinks is down for no room names.
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.ts
index 0e41a2122..a3c7d400a 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.ts
@@ -1,3 +1,4 @@
+import { observable, runInAction } from 'mobx';
import { describe, expect, it, vi } from 'vitest';
import { readThroughSeq } from '@renderer/features/chats/read-progress';
import type { TimelineApi } from '@renderer/features/chats/stores/chat-timeline-store';
@@ -85,7 +86,7 @@ function setup(
onReset: () => () => {},
};
const api: ChatsApi = {
- connect: async () => ({ state: 'live', detail: null }),
+ connect: vi.fn(async () => ({ state: 'live' as const, detail: null })),
disconnect: vi.fn(async () => {}),
list: vi.fn(list),
identity,
@@ -105,6 +106,23 @@ function setup(
}
describe('ChatsStore', () => {
+ it('opens the feed again, keeping nothing of the last account, when the sign-in changes', async () => {
+ const { store, api } = setup(async () => [summary('r1', 1)]);
+ const scope = observable({ key: 'ws:t:user-a' as string | null });
+ const stop = store.follow(() => ({ serverId: 's1', key: scope.key }));
+ await vi.waitFor(() => expect(store.chats.size).toBe(1));
+ expect(api.connect).toHaveBeenCalledTimes(1);
+
+ runInAction(() => (scope.key = 'ws:t:null'));
+ await vi.waitFor(() => expect(api.connect).toHaveBeenCalledTimes(2));
+ expect(api.disconnect).toHaveBeenCalledWith('s1');
+ runInAction(() => (scope.key = 'ws:t:user-a'));
+ await vi.waitFor(() => expect(api.connect).toHaveBeenCalledTimes(3));
+ await vi.waitFor(() => expect(store.streamState).toBe('live'));
+ expect(store.chats.size).toBe(1);
+ stop();
+ });
+
it('reads every summary again, so a renamed agent shows its new name', async () => {
let name = 'ada';
const { store } = setup(async () => {