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 work against a server older than group chats

raullopez-sandboxd38ba2ece304
diff --git a/console/apps/switch-console-desktop/src/main/core/chats/gateway.test.ts b/console/apps/switch-console-desktop/src/main/core/chats/gateway.test.ts
index c7cac190d..4e46f2d82 100644
--- a/console/apps/switch-console-desktop/src/main/core/chats/gateway.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/chats/gateway.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it, vi } from 'vitest';
import { gatewayFetch } from '@main/core/switch-servers/gateway-client';
+import { chatMessageSchema } from '@shared/core/chats/chats';
import type { SwitchServer } from '@shared/core/switch-servers/switch-servers';
import {
addChatAgent,
@@ -52,6 +53,45 @@ describe('parseChatRows', () => {
expect.objectContaining({ roomId: 'room-bad' })
);
});
+
+ it('accepts a chat from a server older than group chats, with defaults', () => {
+ const agent = { id: 'a1', name: 'bot', displayName: null, iconUrl: null, provider: null };
+ const { memberUserIds: _ids, memberCount: _count, ...old } = row('room-old', 'direct');
+ const [chat] = parseChatRows([{ ...old, agents: [agent] }]);
+ expect(chat.memberUserIds).toEqual([]);
+ expect(chat.memberCount).toBe(0);
+ expect(chat.agents[0]).toEqual({
+ ...agent,
+ alias: null,
+ ownerName: null,
+ ownedByViewer: false,
+ });
+ });
+});
+
+describe('chatMessageSchema', () => {
+ it('accepts a message from a server older than group chats, with defaults', () => {
+ const message = chatMessageSchema.parse({
+ messageId: 'm1',
+ seq: 1,
+ roomId: 'room-old',
+ sentAt: '2026-01-01T00:00:00Z',
+ sender: { clientId: 'c1', name: 'Ann', kind: 'human', agentId: null, userId: 'u1' },
+ source: 'console',
+ body: 'hi',
+ format: null,
+ threadRootId: null,
+ attachments: [],
+ clientTxn: null,
+ });
+ expect(message).toMatchObject({
+ namedAgentIds: [],
+ namedUserIds: [],
+ mentions: [],
+ threadReplyCount: 0,
+ threadLastReplySeq: null,
+ });
+ });
});
describe('warmChatAgent', () => {
diff --git a/console/apps/switch-console-desktop/src/shared/core/chats/chats.ts b/console/apps/switch-console-desktop/src/shared/core/chats/chats.ts
index 012f6172f..9f1e5dc55 100644
--- a/console/apps/switch-console-desktop/src/shared/core/chats/chats.ts
+++ b/console/apps/switch-console-desktop/src/shared/core/chats/chats.ts
@@ -13,9 +13,10 @@ export const chatAgentSchema = z.object({
displayName: z.string().nullable(),
iconUrl: z.string().nullable(),
provider: z.string().nullable(),
- alias: z.string().nullable(),
- ownerName: z.string().nullable(),
- ownedByViewer: z.boolean(),
+ // The rest default for a server older than group chats, which does not send them.
+ alias: z.string().nullable().default(null),
+ ownerName: z.string().nullable().default(null),
+ ownedByViewer: z.boolean().default(false),
});
export type ChatAgent = z.infer<typeof chatAgentSchema>;
@@ -29,9 +30,10 @@ export const chatSummarySchema = z.object({
canManage: z.boolean(),
/** The viewer owns one of the agents, which keeps them in the room: they cannot leave it. */
ownsAgent: z.boolean().default(false),
- /** The people in the chat, by user id, sorted. */
- memberUserIds: z.array(z.string()),
- memberCount: z.number().int(),
+ /** The people in the chat, by user id, sorted; empty from a server older than group chats. */
+ memberUserIds: z.array(z.string()).default([]),
+ /** 0 from a server older than group chats. */
+ memberCount: z.number().int().default(0),
/** Messages since the viewer last read the chat; 0 from a server older than read positions. */
unreadCount: z.number().int().default(0),
lastMessage: z
@@ -84,13 +86,15 @@ export const chatMessageSchema = z.object({
threadRootId: z.string().nullable(),
attachments: z.array(chatAttachmentSchema),
clientTxn: z.string().nullable(),
- namedAgentIds: z.array(z.string()),
+ /** The agents the message names; empty from a server older than group chats. */
+ namedAgentIds: z.array(z.string()).default([]),
/** The people the message mentions; empty from a server older than people mentions. */
namedUserIds: z.array(z.string()).default([]),
/** Each mention's stretch of the body and whom it names; empty for older messages and servers. */
mentions: z.array(chatMentionSpanSchema).default([]),
- threadReplyCount: z.number().int(),
- threadLastReplySeq: z.number().int().nullable(),
+ /** 0 and null from a server older than group chats. */
+ threadReplyCount: z.number().int().default(0),
+ threadLastReplySeq: z.number().int().nullable().default(null),
});
export type ChatMessage = z.infer<typeof chatMessageSchema>;