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.

932 B
Raw Blame
import { isBotPrincipalId } from '@core/constant/macroAgent';
import type { IUser } from '@core/user';
import { idToDisplayName, idToEmail } from '@core/user/util';

/** Keep selected users available without adding other non-team people. */
export function scopedUserOptions(
  users: IUser[],
  otherUsers: IUser[],
  selectedIds: readonly string[]
): IUser[] {
  const options = [...users];

  for (const id of selectedIds) {
    const contact = otherUsers.find((user) => user.id === id);
    const member = users.find((user) => user.id === id);
    const user = contact ??
      member ?? {
        id,
        email: isBotPrincipalId(id) ? '' : idToEmail(id),
        name: isBotPrincipalId(id) ? 'Agent' : idToDisplayName(id),
      };
    const index = options.findIndex((option) => option.id === id);

    if (index === -1) {
      options.push(user);
    } else {
      options[index] = user;
    }
  }

  return options;
}