Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(teams): unretardify teams (i) - improve channel creation (#6991)

Eric Hayes550cb64023a0
diff --git a/apps/web/src/features/channel/CreateChannelModal.tsx b/apps/web/src/features/channel/CreateChannelModal.tsx
index 04cbfd98cd..0088c153f1 100644
--- a/apps/web/src/features/channel/CreateChannelModal.tsx
+++ b/apps/web/src/features/channel/CreateChannelModal.tsx
@@ -1,59 +1,38 @@
import { useSplitLayout } from '@components/app/split-layout/layout';
-import { CustomScrollbar } from '@core/component/CustomScrollbar';
import { RecipientSelector } from '@core/component/RecipientSelector';
-import { TabsInset } from '@core/component/TabsInset';
import { toast } from '@core/component/Toast/Toast';
-import { UserIcon } from '@core/component/UserIcon';
import { useUserId } from '@core/context/user';
import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';
-import {
- getDisplayName,
- tryMacroId,
- type WithCustomUserInput,
-} from '@core/user';
+import { recipientEntityMapper, type WithCustomUserInput } from '@core/user';
import { useFocusLock } from '@core/util/createControlledOpenSignal';
import { getDestinationFromOptions } from '@core/util/destination';
import HashIcon from '@phosphor/hash.svg';
import InfoIcon from '@phosphor/info.svg';
+import LockIcon from '@phosphor/lock.svg';
import XIcon from '@phosphor/x.svg';
-import { useCreateChannelMutation } from '@queries/channel/channels';
+import { useAgentsQuery } from '@queries/agents/agents';
+import { useAddBotToChannelMutation } from '@queries/channel/channel-bots';
+import {
+ useCreateChannelMutation,
+ usePatchChannelMutation,
+} from '@queries/channel/channels';
+import { useAddParticipantsMutation } from '@queries/channel/participants';
import { useCurrentTeamQuery } from '@queries/team/teams';
-import type { TeamMember } from '@service-auth/generated/schemas/teamMember';
-import { Button, Dialog, Panel, ToggleSwitch, Tooltip } from '@ui';
-import { inputClasses } from '@ui/components/Input';
-import { createMemo, createSignal, For, Show } from 'solid-js';
+import {
+ Button,
+ Dialog,
+ InputGroup,
+ Panel,
+ RadioGroup,
+ ToggleSwitch,
+} from '@ui';
+import { createMemo, createSignal, Show } from 'solid-js';
const [newChannelModalOpen, setNewChannelModalOpen] = createSignal(false);
const newChannelModalFocusLock = useFocusLock('create-channel');
-const CHANNEL_TYPE_TABS = [
- { value: 'private', label: 'Private' },
- { value: 'team', label: 'Team' },
-];
-
-type CreatableChannelType = 'private' | 'team';
-
-function TeamMemberListItem(props: { member: TeamMember; isLast: boolean }) {
- const displayName = () => getDisplayName(tryMacroId(props.member.user_id));
-
- return (
- <div
- class="flex items-center gap-2 bg-surface px-3 py-1.5"
- classList={{ 'border-b border-edge-muted': !props.isLast }}
- >
- <UserIcon
- id={props.member.user_id}
- size="md"
- showTooltip={false}
- suppressClick
- />
- <div class="min-w-0 flex-1">
- <div class="truncate text-sm font-medium text-ink">{displayName()}</div>
- <div class="text-xs capitalize text-ink-muted">{props.member.role}</div>
- </div>
- </div>
- );
-}
+type ChannelVisibility = 'team' | 'private';
+type ChannelCreationStep = 'name' | 'visibility' | 'invite';
export function openNewChannelModal() {
newChannelModalFocusLock.acquire();
@@ -63,32 +42,48 @@ export function openNewChannelModal() {
export function CreateChannelModal() {
const { replaceOrInsertSplit } = useSplitLayout();
const userId = useUserId();
+ const [step, setStep] = createSignal<ChannelCreationStep>('name');
const { users: recipientOptions } = useCombinedRecipients();
+ const agentsQuery = useAgentsQuery(
+ () => newChannelModalOpen() && step() === 'invite'
+ );
const createChannelMutation = useCreateChannelMutation();
+ const patchChannelMutation = usePatchChannelMutation();
+ const addParticipantsMutation = useAddParticipantsMutation();
+ const addAgentMutation = useAddBotToChannelMutation();
const currentTeamQuery = useCurrentTeamQuery();
const [name, setName] = createSignal('');
- const [teamListScrollRef, setTeamListScrollRef] =
- createSignal<HTMLDivElement>();
- const [channelType, setChannelType] =
- createSignal<CreatableChannelType>('private');
- const [autoJoinTeam, setAutoJoinTeam] = createSignal(false);
+ const [visibility, setVisibility] = createSignal<ChannelVisibility>('team');
+ const [autoJoinTeam, setAutoJoinTeam] = createSignal(true);
const [selectedRecipients, setSelectedRecipients] = createSignal<
- WithCustomUserInput<'user' | 'contact'>[]
+ WithCustomUserInput<'user' | 'contact' | 'agent'>[]
>([]);
const [error, setError] = createSignal<string>();
+ const [createdChannelId, setCreatedChannelId] = createSignal<string>();
+ const [sentRecipientIds, setSentRecipientIds] = createSignal<string[]>([]);
+ const [addedAgentIds, setAddedAgentIds] = createSignal<string[]>([]);
const channelName = createMemo(() => name().trim());
- const team = createMemo(() => currentTeamQuery.data?.team);
- const teamMembers = createMemo(() => currentTeamQuery.data?.members ?? []);
- const canSubmit = createMemo(
- () => channelName().length > 0 && !createChannelMutation.isPending
- );
+ const inviteOptions = createMemo(() => [
+ ...recipientOptions(),
+ ...(agentsQuery.isSuccess ? agentsQuery.data : []).map((agent) =>
+ recipientEntityMapper('agent')(agent.bot)
+ ),
+ ]);
+ const team = () =>
+ currentTeamQuery.isSuccess ? currentTeamQuery.data?.team : undefined;
+ let nameInput: HTMLInputElement | undefined;
+ let visibilityOptions: HTMLDivElement | undefined;
function reset() {
+ setStep('name');
setName('');
- setChannelType('private');
- setAutoJoinTeam(false);
+ setVisibility('team');
+ setAutoJoinTeam(true);
setSelectedRecipients([]);
setError(undefined);
+ setCreatedChannelId(undefined);
+ setSentRecipientIds([]);
+ setAddedAgentIds([]);
}
function resetAndClose() {
@@ -98,44 +93,59 @@ export function CreateChannelModal() {
}
function close() {
- if (createChannelMutation.isPending) return;
+ if (
+ createChannelMutation.isPending ||
+ patchChannelMutation.isPending ||
+ addParticipantsMutation.isPending ||
+ addAgentMutation.isPending
+ )
+ return;
+ if (step() === 'invite' && visibility() === 'team') {
+ void finishInvites(false);
+ return;
+ }
resetAndClose();
}
- async function handleSubmit(event: SubmitEvent) {
- event.preventDefault();
- const trimmedName = channelName();
- if (!trimmedName) {
- setError('Enter a channel name');
+ function goBack() {
+ if (
+ createChannelMutation.isPending ||
+ patchChannelMutation.isPending ||
+ addParticipantsMutation.isPending ||
+ addAgentMutation.isPending
+ )
return;
- }
-
setError(undefined);
- const destination = getDestinationFromOptions(selectedRecipients());
- const selectedChannelType = channelType();
- const isTeamChannel = selectedChannelType === 'team';
+ setStep('name');
+ queueMicrotask(() => nameInput?.focus());
+ }
+
+ async function createChannel() {
+ if (createChannelMutation.isPending) return;
+ const selectedVisibility = visibility();
const selectedTeam = team();
- if (isTeamChannel && !selectedTeam) {
- setError('Select a team to create a team channel');
+ if (selectedVisibility === 'team' && !selectedTeam) {
+ setError('Your team is still loading. Try again in a moment.');
return;
}
- // Team channels currently require a non-empty participant list. The
- // repository filters out the owner after satisfying that validation.
+ // Team channels require a participant in the request; the API filters out
+ // the owner after validating the list.
const participants =
- isTeamChannel && destination.users.length === 0 && userId()
- ? [userId()!]
- : destination.users;
+ selectedVisibility === 'team' && userId() ? [userId()!] : [];
try {
const { id } = await createChannelMutation.mutateAsync({
- channel_type: selectedChannelType,
- name: trimmedName,
+ channel_type: selectedVisibility,
+ name: channelName(),
participants,
- team_id: isTeamChannel ? selectedTeam?.id : undefined,
- auto_join_team: isTeamChannel && autoJoinTeam(),
+ team_id: selectedVisibility === 'team' ? selectedTeam?.id : undefined,
+ // Apply the invite-page switch after creation so turning it off never
+ // leaves the current team pre-added to the channel.
+ auto_join_team: false,
});
- resetAndClose();
+ setCreatedChannelId(id);
+ setStep('invite');
replaceOrInsertSplit({ type: 'channel', id });
} catch (cause) {
console.error('Failed to create channel', cause);
@@ -144,165 +154,369 @@ export function CreateChannelModal() {
}
}
+ async function finishInvites(includeRecipients = true) {
+ const channelId = createdChannelId();
+ if (
+ !channelId ||
+ patchChannelMutation.isPending ||
+ addParticipantsMutation.isPending ||
+ addAgentMutation.isPending
+ )
+ return;
+ const sent = new Set(sentRecipientIds());
+ const addedAgents = new Set(addedAgentIds());
+ const participants = includeRecipients
+ ? getDestinationFromOptions(selectedRecipients()).users.filter(
+ (id) => !sent.has(id)
+ )
+ : [];
+ const agents = includeRecipients
+ ? selectedRecipients()
+ .filter((option) => option.kind === 'agent')
+ .filter((option) => !addedAgents.has(option.id))
+ : [];
+
+ try {
+ setError(undefined);
+ if (participants.length > 0) {
+ await addParticipantsMutation.mutateAsync({ channelId, participants });
+ setSentRecipientIds((previous) => [...previous, ...participants]);
+ }
+ for (const agent of agents) {
+ await addAgentMutation.mutateAsync({ channelId, botId: agent.id });
+ setAddedAgentIds((previous) => [...previous, agent.id]);
+ }
+ if (visibility() === 'team' && autoJoinTeam()) {
+ await patchChannelMutation.mutateAsync({
+ channelId,
+ auto_join_team: true,
+ });
+ }
+ resetAndClose();
+ } catch (cause) {
+ console.error('Failed to finish channel invitations', cause);
+ setError('Failed to finish setting up this channel. Try again.');
+ }
+ }
+
+ function handleSubmit(event: SubmitEvent) {
+ event.preventDefault();
+ if (
+ createChannelMutation.isPending ||
+ patchChannelMutation.isPending ||
+ addParticipantsMutation.isPending ||
+ addAgentMutation.isPending
+ )
+ return;
+ setError(undefined);
+
+ if (step() === 'name') {
+ if (!channelName()) {
+ setError('Enter a channel name');
+ return;
+ }
+ setStep('visibility');
+ queueMicrotask(() =>
+ visibilityOptions
+ ?.querySelector<HTMLInputElement>('input:checked')
+ ?.focus()
+ );
+ return;
+ }
+
+ if (step() === 'visibility') {
+ void createChannel();
+ return;
+ }
+
+ // The invite action is a button so Enter remains available to the combobox.
+ }
+
return (
<Dialog
open={newChannelModalOpen()}
onOpenChange={(open) => !open && close()}
+ position="center"
+ class="w-150"
>
- <Panel depth={2} class="rounded-xl *:max-h-[75vh]">
- <Panel.Body>
- <form class="flex flex-col gap-4 p-5" onSubmit={handleSubmit}>
- <div class="flex items-center gap-1">
- <Show when={team()}>
- <TabsInset
- depth={2}
- list={CHANNEL_TYPE_TABS}
- value={channelType()}
- onChange={(value) => {
- if (value !== 'private' && value !== 'team') return;
- setChannelType(value);
- setError(undefined);
- }}
- />
- </Show>
- <div class="flex-1" />
+ <Panel depth={2} class="rounded-xl *:max-h-[85vh]">
+ <Panel.Body scroll>
+ <form
+ class="flex min-h-80 flex-col gap-7 p-6 sm:p-8"
+ onSubmit={handleSubmit}
+ >
+ <div class="flex items-start justify-between gap-4">
+ <div class="min-w-0">
+ <Dialog.Title class="text-xl font-semibold text-ink">
+ {step() === 'invite' ? (
+ <>
+ Add people or agents to{' '}
+ <span class="inline-flex items-baseline gap-1">
+ <Show
+ when={visibility() === 'private'}
+ fallback={
+ <HashIcon
+ aria-hidden="true"
+ class="inline size-4"
+ />
+ }
+ >
+ <LockIcon aria-hidden="true" class="inline size-4" />
+ </Show>
+ {channelName()}
+ </span>
+ </>
+ ) : (
+ 'Create a channel'
+ )}
+ </Dialog.Title>
+ <Show when={step() === 'visibility'}>
+ <p class="mt-1 flex items-center gap-1 text-sm text-ink-muted">
+ <Show
+ when={visibility() === 'private'}
+ fallback={
+ <HashIcon aria-hidden="true" class="size-3.5" />
+ }
+ >
+ <LockIcon aria-hidden="true" class="size-3.5" />
+ </Show>
+ {channelName()}
+ </p>
+ </Show>
+ </div>
<Dialog.CloseButton
as={Button}
+ variant="ghost"
size="icon-sm"
label="Close"
tabIndex={-1}
- disabled={createChannelMutation.isPending}
+ disabled={
+ createChannelMutation.isPending ||
+ patchChannelMutation.isPending ||
+ addParticipantsMutation.isPending ||
+ addAgentMutation.isPending
+ }
>
<XIcon />
</Dialog.CloseButton>
</div>
- <div class="flex flex-col gap-4">
- <div class="flex items-center gap-2 px-2">
- <Dialog.Title class="sr-only">Create a channel</Dialog.Title>
- <label for="new-channel-name" class="sr-only">
+ <Show when={step() === 'name'}>
+ <div class="flex flex-col gap-2">
+ <label
+ for="new-channel-name"
+ class="text-sm font-medium text-ink"
+ >
Name
</label>
- <HashIcon
- aria-hidden="true"
- class="size-5 shrink-0 text-ink-placeholder"
- />
- <input
- id="new-channel-name"
- type="text"
- value={name()}
- onInput={(event) => {
- setName(event.currentTarget.value);
+ <InputGroup
+ size="xl"
+ class="focus-within:ring-2 focus-within:ring-edge-muted"
+ >
+ <InputGroup.Addon>
+ <HashIcon aria-hidden="true" class="size-4" />
+ </InputGroup.Addon>
+ <InputGroup.Input
+ ref={nameInput}
+ id="new-channel-name"
+ type="text"
+ value={name()}
+ onInput={(event) => {
+ setName(event.currentTarget.value);
+ setError(undefined);
+ }}
+ placeholder="e.g. Feature Requests"
+ maxLength={80}
+ autocomplete="off"
+ data-1p-ignore
+ aria-invalid={error() === 'Enter a channel name'}
+ aria-describedby="new-channel-name-description"
+ />
+ <InputGroup.Addon align="inline-end">
+ <span class="text-xs tabular-nums text-ink-extra-muted">
+ {80 - name().length}
+ </span>
+ </InputGroup.Addon>
+ </InputGroup>
+ <p
+ id="new-channel-name-description"
+ class="text-sm text-ink-muted"
+ >
+ Channels are where conversations happen around a topic. Use a
+ name that is easy to find and understand.
+ </p>
+ </div>
+ </Show>
+
+ <Show when={step() === 'visibility'}>
+ <div ref={visibilityOptions} class="flex flex-col gap-3">
+ <span class="text-sm font-medium text-ink">Visibility</span>
+ <RadioGroup
+ value={visibility()}
+ onChange={(value) => {
+ if (value !== 'team' && value !== 'private') return;
+ setVisibility(value);
setError(undefined);
}}
- placeholder="Channel name"
- autocomplete="off"
- data-1p-ignore
- aria-invalid={error() === 'Enter a channel name'}
- class={inputClasses({ size: 'lg', class: 'text-sm' })}
- />
+ aria-label="Visibility"
+ class="gap-4"
+ >
+ <RadioGroup.Item value="team" class="items-start">
+ <RadioGroup.ItemControl class="mt-0.5" />
+ <div class="flex flex-col gap-1">
+ <RadioGroup.ItemLabel class="text-base text-ink">
+ Team — anyone on your team
+ </RadioGroup.ItemLabel>
+ <RadioGroup.ItemDescription class="text-sm text-ink-muted">
+ Always discoverable to teammates
+ </RadioGroup.ItemDescription>
+ </div>
+ </RadioGroup.Item>
+ <RadioGroup.Item value="private" class="items-start">
+ <RadioGroup.ItemControl class="mt-0.5" />
+ <div class="flex flex-col gap-1">
+ <RadioGroup.ItemLabel class="text-base text-ink">
+ Private — only specific people
+ </RadioGroup.ItemLabel>
+ <RadioGroup.ItemDescription class="text-sm text-ink-muted">
+ Can only be viewed or joined by invitation
+ </RadioGroup.ItemDescription>
+ </div>
+ </RadioGroup.Item>
+ </RadioGroup>
</div>
+ </Show>
- <div class="flex flex-col gap-2 px-2">
- <div class="flex items-center gap-2">
- <span class="text-xs font-medium text-ink-muted">
- Invite people
- </span>
- <span class="rounded-full bg-ink/5 px-1.5 py-0.5 text-xxs font-medium text-ink-extra-muted">
- Optional
- </span>
- </div>
- <RecipientSelector<'user' | 'contact'>
- options={recipientOptions}
+ <Show when={step() === 'invite'}>
+ <div class="flex flex-col gap-3">
+ <RecipientSelector<'user' | 'contact' | 'agent'>
+ options={inviteOptions}
selectedOptions={selectedRecipients()}
setSelectedOptions={setSelectedRecipients}
- placeholder="To: Macro users or email addresses"
+ placeholder="Search people, agents, or email addresses"
+ focusOnMount
+ inviteExternalEmails
+ class="min-h-12 rounded-full border-edge-frame bg-control px-3 py-2 focus-within:ring-2 focus-within:ring-edge-muted"
/>
- <Show when={channelType() === 'team' && autoJoinTeam()}>
- <div class="mt-2 flex flex-col gap-2">
- <div class="flex items-center gap-1">
- <span class="text-xs font-medium text-ink-muted">
- Included team members
- </span>
- <span class="text-xs text-ink-extra-muted">
- ({teamMembers().length})
+ <Show when={visibility() === 'team'}>
+ <ToggleSwitch
+ size="md"
+ class="w-full gap-3 py-2"
+ controlClass="shrink-0"
+ checked={autoJoinTeam()}
+ disabled={
+ patchChannelMutation.isPending ||
+ addParticipantsMutation.isPending ||
+ addAgentMutation.isPending
+ }
+ onChange={setAutoJoinTeam}
+ label={
+ <span class="flex min-w-0 flex-col gap-0.5">
+ <span class="text-sm font-medium text-ink">
+ Automatically add teammates
+ </span>
+ <span class="text-xs text-ink-muted">
+ Add current and future teammates to this channel.
+ </span>
</span>
- </div>
- <div class="relative max-h-56 rounded-lg border border-edge-muted">
- <div
- ref={setTeamListScrollRef}
- class="scrollbar-hidden max-h-56 overflow-y-auto"
- >
- <For each={teamMembers()}>
- {(member, index) => (
- <TeamMemberListItem
- member={member}
- isLast={index() === teamMembers().length - 1}
- />
- )}
- </For>
- </div>
- <CustomScrollbar
- scrollContainer={teamListScrollRef}
- watchContent
- />
- </div>
- </div>
+ }
+ />
</Show>
</div>
- </div>
+ </Show>
<Show when={error()}>
{(message) => (
- <div class="border-y border-edge-muted p-2">
- <div class="px-3 py-2 text-sm text-failure-ink" role="alert">
- {message()}
- </div>
- </div>
+ <p class="text-sm text-failure-ink" role="alert">
+ {message()}
+ </p>
)}
</Show>
- <div class="flex shrink-0 items-center justify-end gap-3 px-2">
- <Show when={channelType() === 'private'}>
- <p class="mr-auto text-xs text-ink-extra-muted">
- Only people you invite can see this channel.
- </p>
- </Show>
- <Show when={channelType() === 'team' && team()}>
- <div class="mr-auto flex items-center gap-1.5">
- <ToggleSwitch
- labelClass="text-xs text-ink-muted font-normal whitespace-nowrap"
- onChange={setAutoJoinTeam}
- checked={autoJoinTeam()}
- label="Team Auto-Join"
- />
- <Tooltip
- as="span"
- placement="bottom"
- label={
- autoJoinTeam()
- ? 'Current and new team members will join automatically.'
- : 'Team members can choose whether to join this channel.'
- }
+ <div class="mt-auto flex items-center justify-between gap-3 pt-4">
+ <span class="text-sm text-ink-muted">
+ Step{' '}
+ {step() === 'name' ? '1' : step() === 'visibility' ? '2' : '3'}{' '}
+ of 3
+ </span>
+ <div class="flex items-center gap-2">
+ <Show when={step() === 'visibility'}>
+ <Button
+ type="button"
+ variant="ghost"
+ disabled={createChannelMutation.isPending}
+ onClick={goBack}
>
- <InfoIcon class="size-3.5 text-ink-extra-muted" />
- </Tooltip>
- </div>
- </Show>
- <Button
- type="submit"
- variant={canSubmit() ? 'accent' : 'ghost'}
- depth={3}
- class="rounded-lg border-0"
- disabled={!canSubmit()}
- >
- {createChannelMutation.isPending
- ? 'Creating…'
- : 'Create Channel'}
- </Button>
+ Back
+ </Button>
+ </Show>
+ <Button
+ type={step() === 'invite' ? 'button' : 'submit'}
+ onClick={() => {
+ if (step() === 'invite') void finishInvites();
+ }}
+ variant={
+ step() === 'invite' && selectedRecipients().length === 0
+ ? 'ghost'
+ : 'accent'
+ }
+ disabled={
+ (step() !== 'invite' && !channelName()) ||
+ createChannelMutation.isPending ||
+ patchChannelMutation.isPending ||
+ addParticipantsMutation.isPending ||
+ addAgentMutation.isPending ||
+ (step() === 'visibility' &&
+ visibility() === 'team' &&
+ !team())
+ }
+ >
+ {step() === 'name'
+ ? 'Next'
+ : step() === 'visibility'
+ ? createChannelMutation.isPending
+ ? 'Creating…'
+ : 'Create'
+ : patchChannelMutation.isPending ||
+ addParticipantsMutation.isPending ||
+ addAgentMutation.isPending
+ ? 'Saving…'
+ : selectedRecipients().length > 0
+ ? 'Add'
+ : 'Skip for now'}
+ </Button>
+ </div>
</div>
</form>
</Panel.Body>
+ <Show when={step() === 'invite'}>
+ <Panel.Footer class="items-start gap-3 px-6 py-4 sm:px-8">
+ <InfoIcon
+ aria-hidden="true"
+ class="mt-0.5 size-5 shrink-0 text-accent"
+ />
+ <p class="text-sm text-ink-muted">
+ <Show
+ when={visibility() === 'team'}
+ fallback={
+ <>
+ <strong class="font-semibold text-ink">
+ Working with people outside your team?
+ </strong>{' '}
+ Type their email above and press Enter. If they don’t have a
+ Macro account, clicking Add emails them an invite.
+ </>
+ }
+ >
+ <strong class="font-semibold text-ink">
+ Team channels are always discoverable.
+ </strong>{' '}
+ Anyone on your team can find and join this channel, even when
+ automatic adding is off.
+ </Show>
+ </p>
+ </Panel.Footer>
+ </Show>
</Panel>
</Dialog>
);
diff --git a/apps/web/src/lib/core/component/RecipientSelector.tsx b/apps/web/src/lib/core/component/RecipientSelector.tsx
index 629915ded1..28f7b5a6ad 100644
--- a/apps/web/src/lib/core/component/RecipientSelector.tsx
+++ b/apps/web/src/lib/core/component/RecipientSelector.tsx
@@ -26,9 +26,12 @@ import {
} from '@kobalte/core/combobox';
import CheckIcon from '@phosphor/check.svg';
import HashIcon from '@phosphor/hash.svg';
+import PaperPlaneTiltIcon from '@phosphor/paper-plane-tilt.svg';
+import RobotIcon from '@phosphor/robot.svg';
import XIcon from '@phosphor/x.svg';
+import type { Bot } from '@service-storage/generated/schemas/bot';
import { debounce } from '@solid-primitives/scheduled';
-import { cn, Layer } from '@ui';
+import { Avatar, cn, Layer } from '@ui';
import * as EmailValidator from 'email-validator';
import {
type Accessor,
@@ -91,6 +94,25 @@ function RecipientChip(props: {
);
}
+function AgentAvatar(props: { agent: Bot }) {
+ return (
+ <Avatar size="sm">
+ <Show
+ when={props.agent.avatar_url}
+ fallback={
+ <Avatar.Fallback>
+ <RobotIcon aria-hidden="true" class="size-3.5" />
+ </Avatar.Fallback>
+ }
+ >
+ {(avatarUrl) => (
+ <Avatar.Image src={avatarUrl()} alt={props.agent.name} />
+ )}
+ </Show>
+ </Avatar>
+ );
+}
+
function getRecipientOptionEmail(
option: CombinedRecipientItem
): string | undefined {
@@ -98,6 +120,7 @@ function getRecipientOptionEmail(
case 'user':
return option.data.email;
case 'channel':
+ case 'agent':
return undefined;
case 'contact':
return option.data.email;
@@ -114,6 +137,8 @@ function getRecipientOptionName(option: CombinedRecipientItem) {
return undefined;
case 'channel':
return option.data.name;
+ case 'agent':
+ return option.data.name;
case 'contact':
return option.data.name;
case 'custom':
@@ -127,6 +152,8 @@ function getRecipientOptionValue(option: CombinedRecipientItem) {
return `user-${option.data.id}`;
case 'channel':
return `channel-${option.data.id}`;
+ case 'agent':
+ return `agent-${option.data.id}`;
case 'contact':
return `contact-${option.data.email}`;
case 'custom':
@@ -140,6 +167,8 @@ function getRecipientOptionLabel(option: CombinedRecipientItem) {
return option.data.email;
case 'channel':
return option.data.id;
+ case 'agent':
+ return option.data.name;
case 'contact':
return option.data.email;
case 'custom':
@@ -156,12 +185,18 @@ function getRecipientOptionTextValue(option: CombinedRecipientItem) {
return name ? `${name} ${email}` : (email ?? '');
case 'channel':
return option.data.name ?? '';
+ case 'agent':
+ return [option.data.name, option.data.handle, option.data.description]
+ .filter(Boolean)
+ .join(' ');
case 'custom':
return option.data.email;
}
}
-type RecipientComboboxItemProps = CollectionNode<CombinedRecipientItem>;
+type RecipientComboboxItemProps = CollectionNode<CombinedRecipientItem> & {
+ inviteExternalEmails?: boolean;
+};
const RECIPIENT_OPTION_HEIGHT_PX = 36;
const RECIPIENT_OPTION_MAX_VISIBLE_COUNT = 6;
@@ -215,16 +250,35 @@ function RecipientComboboxItem(props: RecipientComboboxItemProps): JSX.Element {
return (
<Combobox.ItemLabel class="flex flex-row w-full items-center gap-1.5 text-ink select-none text-sm">
- <UserIcon id={iconId ?? ''} size="sm" isDeleted={false} />
+ <Show
+ when={props.inviteExternalEmails && option.kind === 'custom'}
+ fallback={
+ <UserIcon id={iconId ?? ''} size="sm" isDeleted={false} />
+ }
+ >
+ <PaperPlaneTiltIcon
+ aria-hidden="true"
+ class="size-4 shrink-0"
+ />
+ </Show>
<p
class={cn(
'ph-no-capture truncate my-auto',
props.disabled && 'italic'
)}
>
- <Show when={showEmail} fallback={name || email}>
- {name}
- <span class="ml-[0.5em] opacity-50">{email}</span>
+ <Show
+ when={
+ props.inviteExternalEmails && option.kind === 'custom'
+ }
+ fallback={
+ <Show when={showEmail} fallback={name || email}>
+ {name}
+ <span class="ml-[0.5em] opacity-50">{email}</span>
+ </Show>
+ }
+ >
+ <strong class="font-semibold">Invite</strong> {email}
</Show>
</p>
</Combobox.ItemLabel>
@@ -247,6 +301,19 @@ function RecipientComboboxItem(props: RecipientComboboxItemProps): JSX.Element {
);
}}
</Match>
+ <Match when={matches(props.rawValue, (i) => i.kind === 'agent')}>
+ {(item) => (
+ <Combobox.ItemLabel class="flex min-w-0 w-full items-center gap-2 text-sm text-ink select-none">
+ <AgentAvatar agent={item().data} />
+ <span class="min-w-0 truncate font-medium">
+ {item().data.name}
+ </span>
+ <span class="min-w-0 truncate text-xs text-ink-muted">
+ @{item().data.handle}
+ </span>
+ </Combobox.ItemLabel>
+ )}
+ </Match>
</Switch>
<Combobox.ItemIndicator>
@@ -281,6 +348,8 @@ type RecipientSelectorProps<K extends CombinedRecipientKind> = {
class?: string;
depth?: 0 | 1 | 2 | 3 | 4;
portalScope?: 'local';
+ /** Show an invite action for a complete email outside the known recipients. */
+ inviteExternalEmails?: boolean;
};
export function RecipientSelector<K extends CombinedRecipientKind>(
@@ -395,7 +464,8 @@ export function RecipientSelector<K extends CombinedRecipientKind>(
if (
newestSelection.kind === 'user' ||
newestSelection.kind === 'contact' ||
- newestSelection.kind === 'custom'
+ newestSelection.kind === 'custom' ||
+ newestSelection.kind === 'agent'
) {
setCustomUsers(
value.filter((o) => {
@@ -720,6 +790,19 @@ export function RecipientSelector<K extends CombinedRecipientKind>(
);
}}
</Match>
+ <Match
+ when={matches(option, (o) => o.kind === 'agent')}
+ >
+ {(agentOption) => (
+ <RecipientChip
+ icon={
+ <AgentAvatar agent={agentOption().data} />
+ }
+ label={agentOption().data.name}
+ onRemove={() => state.remove(option)}
+ />
+ )}
+ </Match>
<Match
when={matches(option, (o) => o.kind === 'custom')}
>
@@ -731,12 +814,19 @@ export function RecipientSelector<K extends CombinedRecipientKind>(
chip={
<RecipientChip
icon={
- <UserIcon
- id={email}
- size="sm"
- isDeleted={false}
- showTooltip={false}
- />
+ props.inviteExternalEmails ? (
+ <PaperPlaneTiltIcon
+ aria-hidden="true"
+ class="size-4"
+ />
+ ) : (
+ <UserIcon
+ id={email}
+ size="sm"
+ isDeleted={false}
+ showTooltip={false}
+ />
+ )
}
label={email}
onRemove={() => state.remove(option)}
@@ -931,7 +1021,12 @@ export function RecipientSelector<K extends CombinedRecipientKind>(
ref={setHandle}
>
{(item) => {
- return <RecipientComboboxItem {...item} />;
+ return (
+ <RecipientComboboxItem
+ {...item}
+ inviteExternalEmails={props.inviteExternalEmails}
+ />
+ );
}}
</VList>
);
diff --git a/apps/web/src/lib/core/user/combinedRecipient.ts b/apps/web/src/lib/core/user/combinedRecipient.ts
index 02d4dab588..323c598d9f 100644
--- a/apps/web/src/lib/core/user/combinedRecipient.ts
+++ b/apps/web/src/lib/core/user/combinedRecipient.ts
@@ -1,3 +1,4 @@
+import type { Bot } from '@service-storage/generated/schemas/bot';
import type { ChannelWithParticipants, ContactInfo, IUser } from './types';
// this type is extracted from the user's message info
@@ -17,6 +18,7 @@ type EntityMap = {
channel: ChannelWithParticipants;
contact: ExtractedContactInfo;
custom: CustomUserInput;
+ agent: Bot;
};
type Entity<T extends keyof EntityMap> = {
diff --git a/apps/web/src/lib/core/util/destination.ts b/apps/web/src/lib/core/util/destination.ts
index 2ecc5c2c4b..ef81c62202 100644
--- a/apps/web/src/lib/core/util/destination.ts
+++ b/apps/web/src/lib/core/util/destination.ts
@@ -32,13 +32,14 @@ export function getDestinationFromOptions<T extends CombinedRecipientItem>(
const userIds = options
.filter((o) => {
+ if (o.kind === 'agent') return false;
if (o.kind === 'custom') {
return !o.data.invalid;
}
return true;
})
.map((o) => {
- if (o.kind === 'channel') return;
+ if (o.kind === 'channel' || o.kind === 'agent') return;
return o.id;
})
.filter((id) => id != null);
diff --git a/apps/web/src/lib/queries/agents/agents.ts b/apps/web/src/lib/queries/agents/agents.ts
index 6725420b24..da0ed6dead 100644
--- a/apps/web/src/lib/queries/agents/agents.ts
+++ b/apps/web/src/lib/queries/agents/agents.ts
@@ -7,6 +7,7 @@ import type { Agent } from '@service-storage/generated/schemas/agent';
import type { AgentChannelScope } from '@service-storage/generated/schemas/agentChannelScope';
import type { AgentMcpServers } from '@service-storage/generated/schemas/agentMcpServers';
import { useMutation, useQuery } from '@tanstack/solid-query';
+import type { Accessor } from 'solid-js';
import { agentKeys } from './keys';
/**
@@ -53,9 +54,10 @@ export type DeleteAgentParams = {
channelIds: string[];
};
-export function useAgentsQuery() {
+export function useAgentsQuery(enabled: Accessor<boolean> = () => true) {
return useQuery(() => ({
queryKey: agentKeys.list.queryKey,
+ enabled: enabled(),
queryFn: async (): Promise<AgentWithHarnessId[]> =>
await throwOnErr(() => storageServiceClient.getAgents()),
}));
diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.md
index b877f12edf..70a6701226 100644
--- a/docs/AGENT_GUIDE/channels.md
+++ b/docs/AGENT_GUIDE/channels.md
@@ -2,17 +2,13 @@
## Create a channel
-1. `Create` → `Channel G`. Dialog `Create a channel` opens with the `Name` textbox focused.
-2. `fill` the name.
-3. Invite (optional): click the combobox `To: Macro users or email addresses`, `type_text`
- the email, wait for the live-region text `one option available` (or `N options`), press
- **Enter** to tokenize — the email becomes a chip above the combobox. Skipping the Enter
- leaves raw text that is not submitted.
-4. Click `Create Channel`. Navigates to the channel (as a split pane:
- `.../channel/<uuid>`); a system row `Channel <name> created` appears.
-
-Channels are invite-only ("Only people you invite can see this channel"). A DM is just a
-channel between two users.
+1. `Create` → `Channel G`. Dialog `Create a channel` opens on step 1 of 3 with the `Name` textbox focused.
+2. Fill the name and click `Next`. Step 2 of 3 shows `Visibility`, with `Team — anyone on your team` selected by default. Team channels are always discoverable to teammates.
+3. For a team channel, click `Create`. For a private channel, select `Private — only specific people` and click `Create`. Creation navigates to the channel (as a split pane: `.../channel/<uuid>`); a system row `Channel <name> created` appears.
+4. Step 3 of 3 is an optional invite dialog for either channel type. The recipient combobox searches people and saved agents by name; it also accepts complete email addresses. Select a suggestion or press **Enter** to tokenize it. An unknown complete email appears as **Invite** with a paper airplane icon. Raw text left in the input is not submitted. Click `Add` when recipients are selected, or `Skip for now` to finish without invitees. Selected agents are added through the channel's agent membership endpoint. For team channels, `Automatically add teammates` defaults on; turning it off leaves the channel discoverable without automatically adding current or future teammates. The switch choice is applied when the invite dialog is finished or closed.
+
+Team channels are always discoverable to the team. Private channels can only be viewed or joined by invitation. A DM is a channel between two users.
+An external email can be selected as a channel participant. For an unregistered recipient, clicking `Add` sends an email invite.
## Agent session entities