Skip to content

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

feat(console): search finds your 1:1 chats, and leaves legacy rows out reliably

raullopez-sandbox091a011d76cd
diff --git a/console/apps/switch-console-desktop/src/renderer/features/command-palette/command-palette-modal.tsx b/console/apps/switch-console-desktop/src/renderer/features/command-palette/command-palette-modal.tsx
index 4b314b71b..17e1ffb1d 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/command-palette/command-palette-modal.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/command-palette/command-palette-modal.tsx
@@ -4,6 +4,7 @@ import { Activity, DoorOpen, Globe, type LucideIcon, MessageSquare, Server } fro
import { observer, useObserver } from 'mobx-react-lite';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { agentChatsFlag } from '@renderer/features/chats/stores/agent-chats-flag';
+import { chatsStore } from '@renderer/features/chats/stores/chats';
import { managedAgentLabel } from '@renderer/features/managed-agents/managed-agent-state';
import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';
import { REMOTE_HOSTS_QUERY_KEY } from '@renderer/features/remote-hosts/views/remote-hosts-view';
@@ -19,6 +20,7 @@ import { commandRegistry } from '@renderer/lib/commands/registry';
import { BridgeIcon, hasBridgeIcon } from '@renderer/lib/components/bridge-icon';
import { failureText } from '@renderer/lib/errors/describe-failure';
import { useDebounce } from '@renderer/lib/hooks/useDebounce';
+import { useFeatureFlagsKnown } from '@renderer/lib/hooks/useFeatureFlags';
import { getEffectiveHotkey } from '@renderer/lib/hooks/useKeyboardShortcuts';
import { rpc } from '@renderer/lib/ipc';
import { useNavigate } from '@renderer/lib/layout/navigation-provider';
@@ -41,12 +43,14 @@ import {
applyContextAffinity,
indexedSearchLabel,
instantMatchLabel,
+ matchDirectChats,
matchHosts,
matchManagedAgents,
matchRooms,
matchServers,
paletteSearchPlaceholder,
sectionResults,
+ withoutLegacy,
} from './search-utils';
interface CommandPaletteProps {
@@ -197,7 +201,8 @@ export function CommandPaletteModal({
// sessions under Legacy; the palette leaves them out entirely and offers the
// server's managed agents instead.
const managementMode = useAgentManagementMode();
- const includeLegacy = !managementMode;
+ // Until the flags are read, management mode is not known: legacy rows wait rather than flash.
+ const includeLegacy = useFeatureFlagsKnown(switchServersStore.activeServerId) && !managementMode;
const managedAgents = useManagedAgents(managementMode ? switchServersStore.activeServerId : null);
const handleClose = onClose;
@@ -240,7 +245,9 @@ export function CommandPaletteModal({
// Keep results fresh for 5 s — re-opening the palette with the same query
// returns cached data instantly rather than waiting for a round-trip.
staleTime: 5_000,
- placeholderData: (prev) => prev,
+ // Kept only while the same kinds are searched for, so legacy rows never linger once left out.
+ placeholderData: (prev, prevQuery) =>
+ prevQuery?.queryKey[2] === includeLegacy ? prev : undefined,
});
const registryActions = useObserver((): PaletteAction[] =>
@@ -287,7 +294,9 @@ export function CommandPaletteModal({
.slice(0, 7);
}, [registryActions, resourceMonitorAction, sessionId]);
- const rankedDb = applyContextAffinity(searchResult.items, { locationId });
+ const rankedDb = applyContextAffinity(withoutLegacy(searchResult.items, includeLegacy), {
+ locationId,
+ });
const actionResults = actions;
// Rooms and servers come from MobX stores rather than the FTS index, read
@@ -304,6 +313,9 @@ export function CommandPaletteModal({
)
);
const serverResults = useObserver(() => matchServers(switchServersStore.servers, debouncedQuery));
+ const chatResults = useObserver(() =>
+ matchDirectChats([...chatsStore.chats.values()], debouncedQuery)
+ );
const { data: hosts = [] } = useQuery({
queryKey: REMOTE_HOSTS_QUERY_KEY,
@@ -315,7 +327,11 @@ export function CommandPaletteModal({
? matchManagedAgents(managedAgents.data ?? [], debouncedQuery)
: [];
const rendererMatchCount =
- managedAgentResults.length + roomResults.length + serverResults.length + hostResults.length;
+ managedAgentResults.length +
+ chatResults.length +
+ roomResults.length +
+ serverResults.length +
+ hostResults.length;
const q = debouncedQuery.toLowerCase();
const matchedResourceMonitor =
@@ -390,6 +406,14 @@ export function CommandPaletteModal({
});
};
+ const handleOpenChat = (item: SearchItem) => {
+ const serverId = chatsStore.serverId;
+ const chat = chatsStore.chat(item.id);
+ if (!serverId || !chat) return;
+ handleClose();
+ navigate('chat', { serverId, roomId: chat.roomId, agentId: chat.agents[0]?.id ?? null });
+ };
+
const handleNavigateToRoom = (item: SearchItem) => {
handleClose();
void openRoom(item.id);
@@ -531,6 +555,18 @@ export function CommandPaletteModal({
{indexed.session.map(renderSessionResult)}
</Command.Group>
)}
+ {chatResults.length > 0 && (
+ <Command.Group heading="Chats" className={GROUP_CLASS}>
+ {chatResults.map((item) => (
+ <PaletteItem
+ key={`chat:${item.id}`}
+ value={`chat:${item.id}`}
+ item={item}
+ onSelect={() => handleOpenChat(item)}
+ />
+ ))}
+ </Command.Group>
+ )}
<PaletteResultGroup
heading="Rooms"
items={[...roomResults, ...indexed.room]}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/command-palette/search-utils.ts b/console/apps/switch-console-desktop/src/renderer/features/command-palette/search-utils.ts
index 7b7035218..6dee1c341 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/command-palette/search-utils.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/command-palette/search-utils.ts
@@ -1,4 +1,6 @@
import { managedAgentLabel } from '@renderer/features/managed-agents/managed-agent-state';
+import { isConsoleDirectChatSummary } from '@renderer/features/switch-servers/room-filters';
+import { type ChatSummary, chatAgentLabel } from '@shared/core/chats/chats';
import type { ManagedAgentView } from '@shared/core/managed-agents/managed-agents';
import { matchQuality, type SearchItem, type SearchItemKind } from '@shared/core/search';
import type { RemoteRoomSummary, SwitchServer } from '@shared/core/switch-servers/switch-servers';
@@ -89,6 +91,31 @@ function item(
return { kind, id, locationId: null, sessionId: null, title, subtitle, score };
}
+/**
+ * Matches the user's 1:1 chats with agents, by the chat's name and the agent's.
+ * Drawn as chats (the item's `id` is the room); a chat the user no longer has
+ * is not in the list, so it is not found.
+ */
+export function matchDirectChats(chats: ChatSummary[], query: string): SearchItem[] {
+ const q = query.trim().toLowerCase();
+ if (!q) return [];
+ return finalise(
+ chats.flatMap((chat) => {
+ if (!isConsoleDirectChatSummary(chat)) return [];
+ const agent = chat.agents[0] ? chatAgentLabel(chat.agents[0]) : '';
+ const score = rank(chat.name, q) ?? rank(agent, q);
+ return score === null ? [] : [item('session', chat.roomId, chat.name, agent, score)];
+ })
+ );
+}
+
+/** What an indexed search may show: no legacy agents or sessions when they are left out. */
+export function withoutLegacy(items: SearchItem[], includeLegacy: boolean): SearchItem[] {
+ return includeLegacy
+ ? items
+ : items.filter((each) => each.kind !== 'session' && each.kind !== 'agent');
+}
+
/**
* Matches Switch rooms, across every server rather than the active one — you
* search because you do not know where a thing is. Selecting one switches the
diff --git a/console/apps/switch-console-desktop/src/renderer/lib/hooks/feature-flags-settled.test.ts b/console/apps/switch-console-desktop/src/renderer/lib/hooks/feature-flags-settled.test.ts
new file mode 100644
index 000000000..a1edd896a
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/lib/hooks/feature-flags-settled.test.ts
@@ -0,0 +1,13 @@
+import { describe, expect, it, vi } from 'vitest';
+import { FLAGS_NOT_READ_YET } from '@shared/core/feature-flags/feature-flags';
+import { flagsSettled } from './useFeatureFlags';
+
+vi.mock('@renderer/lib/ipc', () => ({ events: { on: vi.fn() }, rpc: {} }));
+
+describe('flagsSettled', () => {
+ it('is unknown until the flags are read or a read fails', () => {
+ expect(flagsSettled({ fetchedAt: null, error: FLAGS_NOT_READ_YET })).toBe(false);
+ expect(flagsSettled({ fetchedAt: 1, error: null })).toBe(true);
+ expect(flagsSettled({ fetchedAt: null, error: 'unreachable' })).toBe(true);
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/lib/hooks/useFeatureFlags.ts b/console/apps/switch-console-desktop/src/renderer/lib/hooks/useFeatureFlags.ts
index 071300978..0c4de4c99 100644
--- a/console/apps/switch-console-desktop/src/renderer/lib/hooks/useFeatureFlags.ts
+++ b/console/apps/switch-console-desktop/src/renderer/lib/hooks/useFeatureFlags.ts
@@ -4,6 +4,8 @@ import {
allFeatureFlagsOff,
type FeatureFlagKey,
type FeatureFlags,
+ FLAGS_NOT_READ_YET,
+ type ServerFeatureFlags,
} from '@shared/core/feature-flags/feature-flags';
import { featureFlagsChangedChannel } from '@shared/events/featureFlagEvents';
@@ -68,6 +70,39 @@ export function useFeatureFlags(serverId: string | null | undefined): FeatureFla
return flags;
}
+/** Whether a server's flags say anything yet: read once, or tried and failed (then they stay off). */
+export function flagsSettled(state: Pick<ServerFeatureFlags, 'fetchedAt' | 'error'>): boolean {
+ return state.fetchedAt !== null || (state.error !== null && state.error !== FLAGS_NOT_READ_YET);
+}
+
+/**
+ * Whether a server's flags are known yet, kept current. Before they are, what
+ * they decide is unknown, and a view that would show the wrong thing either
+ * way can wait for them.
+ */
+export function useFeatureFlagsKnown(serverId: string | null | undefined): boolean {
+ const [settled, setSettled] = useState(() => (serverId ? known.has(serverId) : true));
+ useEffect(() => {
+ if (!serverId) {
+ setSettled(true);
+ return;
+ }
+ setSettled(known.has(serverId));
+ let current = true;
+ const off = events.on(featureFlagsChangedChannel, (state) => {
+ if (state.serverId === serverId && flagsSettled(state)) setSettled(true);
+ });
+ void rpc.featureFlags.get(serverId).then((res) => {
+ if (current && res?.success && flagsSettled(res.data)) setSettled(true);
+ });
+ return () => {
+ current = false;
+ off();
+ };
+ }, [serverId]);
+ return settled;
+}
+
/**
* Whether any connected server turns `key` on, kept current. For what Console
* shows outside any one server — a settings page about every server's agents —
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/palette-search-utils.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/palette-search-utils.test.ts
index 4a2c8fe8f..dc5a32924 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/palette-search-utils.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/tests/palette-search-utils.test.ts
@@ -3,13 +3,16 @@ import {
applyContextAffinity,
indexedSearchLabel,
instantMatchLabel,
+ matchDirectChats,
matchHosts,
matchManagedAgents,
matchRooms,
matchServers,
paletteSearchPlaceholder,
sectionResults,
+ withoutLegacy,
} from '@renderer/features/command-palette/search-utils';
+import type { ChatSummary } from '@shared/core/chats/chats';
import type { ManagedAgentView } from '@shared/core/managed-agents/managed-agents';
import type { SearchItem } from '@shared/core/search';
import type { RemoteRoomSummary, SwitchServer } from '@shared/core/switch-servers/switch-servers';
@@ -328,3 +331,61 @@ describe('matchManagedAgents', () => {
expect(matchManagedAgents(agents, 'sw').map((agent) => agent.agentId)).toEqual(['a-2']);
});
});
+
+describe('matchDirectChats', () => {
+ const agent = {
+ id: 'a1',
+ name: 'smiley',
+ displayName: 'Smiley',
+ iconUrl: null,
+ provider: null,
+ alias: null,
+ ownerName: null,
+ ownedByViewer: true,
+ };
+ const chat = (roomId: string, extra: Partial<ChatSummary> = {}): ChatSummary => ({
+ roomId,
+ name: 'Release notes',
+ channelType: 'direct',
+ bridgeType: null,
+ channelName: null,
+ agents: [agent],
+ canManage: true,
+ ownsAgent: true,
+ memberUserIds: [],
+ memberCount: 1,
+ unreadCount: 0,
+ lastMessage: null,
+ ...extra,
+ });
+
+ it('finds 1:1 chats by their name or their agent’s, and no groups or bridged rooms', () => {
+ const chats = [
+ chat('d1'),
+ chat('g1', { channelType: 'channel_private' }),
+ chat('b1', { bridgeType: 'slack' }),
+ ];
+ expect(matchDirectChats(chats, 'release').map((each) => each.id)).toEqual(['d1']);
+ expect(matchDirectChats(chats, 'smil').map((each) => each.id)).toEqual(['d1']);
+ expect(matchDirectChats(chats, '')).toEqual([]);
+ });
+});
+
+describe('withoutLegacy', () => {
+ const of = (kind: SearchItem['kind']) =>
+ ({
+ kind,
+ id: kind,
+ locationId: null,
+ sessionId: null,
+ title: kind,
+ subtitle: '',
+ score: 0,
+ }) as SearchItem;
+
+ it('drops legacy agents and sessions when they are left out, and keeps them otherwise', () => {
+ const items = [of('session'), of('agent'), of('command')];
+ expect(withoutLegacy(items, false).map((each) => each.kind)).toEqual(['command']);
+ expect(withoutLegacy(items, true)).toEqual(items);
+ });
+});