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): show people's emails and a way to invite in a group chat's Add person

raullopez-sandbox766419b50111
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 ee626f888..47fe5865f 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
@@ -29,7 +29,9 @@ function row(roomId: string, channelType: string) {
channelName: null,
agents: [],
canManage: true,
- ownsAgent: false, memberUserIds: [], memberCount: 0,
+ ownsAgent: false,
+ memberUserIds: [],
+ memberCount: 0,
lastMessage: null,
};
}
@@ -159,7 +161,9 @@ describe('chat members', () => {
status: 200,
})
);
- expect(await listWorkspaceMembers(server, 't-1')).toEqual([{ userId: 'u2', name: 'Bob' }]);
+ expect(await listWorkspaceMembers(server, 't-1')).toEqual([
+ { userId: 'u2', name: 'Bob', email: null },
+ ]);
expect(gatewayFetch).toHaveBeenCalledWith(server, '/tenants/t-1/members', {
authenticated: true,
});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx
index 1c95cd631..09319c22c 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx
@@ -8,6 +8,7 @@ import { chatsStore } from '@renderer/features/chats/stores/chats';
import { agentsStore } from '@renderer/features/locations/stores/agents-store';
import { isConsoleGroupChatSummary } from '@renderer/features/switch-servers/room-filters';
import { switchRoomsStore } from '@renderer/features/switch-servers/switch-rooms-store';
+import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';
import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';
import { AgentAvatar } from '@renderer/lib/components/agent-avatar';
import { bridgePlatformLabel } from '@renderer/lib/components/bridge-platform';
@@ -29,10 +30,12 @@ import { cn } from '@renderer/utils/utils';
import { agentInitials } from '@shared/core/agents/agent-avatar';
import { type ChatSummary, chatAgentLabel } from '@shared/core/chats/chats';
import { providerDisplayName } from '@shared/core/providers/agent-provider-registry';
+import { runsOnThisComputer } from '@shared/core/switch-servers/switch-servers';
import type {
RemoteAgentSummary,
RemoteRoomDetail,
} from '@shared/core/switch-servers/switch-servers';
+import { administersWorkspace } from '@shared/core/workspaces/workspaces';
import { channelOnDeleteSummary } from './room-delete-wording';
import { membershipSummary, roomTitle } from './room-labels';
import { openRoomChannel } from './room-links';
@@ -201,7 +204,7 @@ const ChatParticipantsSection = observer(function ChatParticipantsSection({
people={people.map((person) => ({
id: person.userId,
name: person.name,
- detail: person.isOwner ? 'owner' : 'person',
+ detail: person.isOwner ? 'owner' : 'member',
}))}
manage={manage}
/>
@@ -212,6 +215,7 @@ const ChatParticipantsSection = observer(function ChatParticipantsSection({
{adding === 'person' && (
<ChatAddPersonPanel
serverId={serverId}
+ workspaceId={workspaceId}
tenantId={chatsStore.tenantId}
roomId={roomId}
memberIds={new Set(people.map((person) => person.userId))}
@@ -237,6 +241,7 @@ const ChatAddAgentPanel = observer(function ChatAddAgentPanel({
return (
<AddParticipantPanel
noun="agent"
+ footer={null}
searchPlaceholder="Search agents in this workspace…"
allInText="Every agent in this workspace is already in this chat."
loading={agents.isPending}
@@ -268,12 +273,14 @@ const ChatAddAgentPanel = observer(function ChatAddAgentPanel({
/** The workspace's people not yet in the chat. */
function ChatAddPersonPanel({
serverId,
+ workspaceId,
tenantId,
roomId,
memberIds,
onAdded,
}: {
serverId: string;
+ workspaceId: string | null;
/** The workspace the chats follow; its roster is the one offered. */
tenantId: string | null;
roomId: string;
@@ -304,8 +311,9 @@ function ChatAddPersonPanel({
id: person.userId,
name: person.name,
mark: <PersonMark name={person.name} size="sm" />,
- detail: 'person',
+ detail: person.email ?? '',
}))}
+ footer={<InviteHint workspaceId={workspaceId} canInvite={canInvite(serverId, workspaceId)} />}
onAdd={async (userId) => {
try {
onAdded(await rpc.chats.addMember({ serverId, roomId, userId }));
@@ -317,6 +325,45 @@ function ChatAddPersonPanel({
);
}
+/** Whether the viewer may invite people to the workspace, as the workspace menu decides it. */
+function canInvite(serverId: string, workspaceId: string | null): boolean {
+ const workspace = workspacesStore.workspaces.find((each) => each.id === workspaceId) ?? null;
+ const server = switchServersStore.servers.find((each) => each.id === serverId) ?? null;
+ return (
+ workspace !== null &&
+ server !== null &&
+ administersWorkspace(workspace) &&
+ !runsOnThisComputer(server)
+ );
+}
+
+/** Where to go for someone the roster does not have yet. */
+export function InviteHint({
+ workspaceId,
+ canInvite,
+}: {
+ workspaceId: string | null;
+ canInvite: boolean;
+}) {
+ const showInvitePeopleModal = useShowModal('invitePeopleModal');
+ return (
+ <p className="px-1 text-xs text-foreground-muted">
+ Don&apos;t see someone?{' '}
+ {canInvite && workspaceId !== null ? (
+ <button
+ type="button"
+ className="cursor-pointer underline hover:text-foreground"
+ onClick={() => showInvitePeopleModal({ workspaceId })}
+ >
+ Invite them to the workspace
+ </button>
+ ) : (
+ 'Ask a workspace admin to invite them.'
+ )}
+ </p>
+ );
+}
+
/**
* A room's settings: what it is for, what it tells agents on arrival, and who is
* in it.
@@ -792,6 +839,7 @@ function AddParticipantPanel({
loading,
loadError,
candidates,
+ footer,
onAdd,
}: {
noun: string;
@@ -800,6 +848,8 @@ function AddParticipantPanel({
loading: boolean;
loadError: string | null;
candidates: Candidate[];
+ /** Under the list, such as where to go for someone who is not in it. */
+ footer: React.ReactNode;
onAdd: (id: string) => Promise<void>;
}) {
const [filter, setFilter] = useState('');
@@ -807,7 +857,8 @@ function AddParticipantPanel({
const [error, setError] = useState<string | null>(null);
const query = filter.trim().toLowerCase();
const shown = candidates.filter(
- (candidate) => query === '' || candidate.name.toLowerCase().includes(query)
+ (candidate) =>
+ query === '' || `${candidate.name}\n${candidate.detail}`.toLowerCase().includes(query)
);
async function add(id: string) {
@@ -884,6 +935,7 @@ function AddParticipantPanel({
))}
</div>
)}
+ {footer}
</div>
);
}
@@ -910,6 +962,7 @@ const AddAgentPanel = observer(function AddAgentPanel({
return (
<AddParticipantPanel
noun="agent"
+ footer={null}
searchPlaceholder="Search agents on this computer…"
allInText="Every agent on this computer is already in this room."
loading={false}
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chat-configuration.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chat-configuration.test.ts
index ffd7f043f..9160e0b09 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/chat-configuration.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/tests/chat-configuration.test.ts
@@ -4,6 +4,7 @@ import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it, vi } from 'vitest';
import {
chatMembersQueryKey,
+ InviteHint,
RoomConfigurationPanel,
} from '@renderer/features/switch-rooms/room-configuration-panel';
import type { ChatSummary } from '@shared/core/chats/chats';
@@ -19,6 +20,9 @@ vi.mock('@renderer/features/chats/stores/chats', () => ({
},
}));
+const showModal = vi.hoisted(() => vi.fn());
+vi.mock('@renderer/lib/modal/modal-provider', () => ({ useShowModal: () => showModal }));
+
const agent = {
id: 'agent-1',
name: 'helper',
@@ -101,3 +105,25 @@ describe('chatMembersQueryKey', () => {
).toEqual(now);
});
});
+
+describe('group chat people', () => {
+ it('labels the owner and everyone else as a member', () => {
+ const html = render(false);
+ expect(html).toMatch(/Alice<\/span><span[^>]*>owner</);
+ expect(html).toMatch(/Bob<\/span><span[^>]*>member</);
+ expect(html).not.toContain('>person<');
+ });
+
+ it('offers the invite to someone who may invite, and says who to ask otherwise', () => {
+ const can = renderToStaticMarkup(
+ createElement(InviteHint, { workspaceId: 'w', canInvite: true })
+ );
+ expect(can).toContain('Invite them to the workspace');
+ expect(can).toContain('<button');
+ const cannot = renderToStaticMarkup(
+ createElement(InviteHint, { workspaceId: 'w', canInvite: false })
+ );
+ expect(cannot).toContain('Ask a workspace admin to invite them.');
+ expect(cannot).not.toContain('<button');
+ });
+});
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 a84fcc09a..f5f75af74 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
@@ -104,8 +104,8 @@ export type ChatMember = z.infer<typeof chatMemberSchema>;
export const chatMemberListSchema = z.object({ members: z.array(chatMemberSchema) });
/** A person in the workspace, from its roster, who could be added to a chat. */
export const workspaceMemberSchema = z
- .object({ user_id: z.string(), name: z.string() })
- .transform(({ user_id, name }) => ({ userId: user_id, name }));
+ .object({ user_id: z.string(), name: z.string(), email: z.string().nullish() })
+ .transform(({ user_id, name, email }) => ({ userId: user_id, name, email: email || null }));
export type WorkspaceMember = z.infer<typeof workspaceMemberSchema>;
export const chatUploadSchema = z.object({
uploadId: z.string(),