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.

1.3 KB
Raw Blame
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
export type ExtractedContactInfo = ContactInfo & {
  id: string;
  type: 'extracted';
};

export type CustomUserInput = {
  id: string;
  email: string;
  invalid: boolean;
};

type EntityMap = {
  user: IUser;
  channel: ChannelWithParticipants;
  contact: ExtractedContactInfo;
  custom: CustomUserInput;
  agent: Pick<Bot, 'id' | 'name' | 'handle' | 'description' | 'avatar_url'>;
};

type Entity<T extends keyof EntityMap> = {
  kind: T;
  id: EntityMap[T]['id'];
  data: EntityMap[T];
};

type PickEntity<K extends keyof EntityMap> = {
  [P in K]: Entity<P>;
}[K];

export type CombinedRecipientKind = keyof EntityMap;

export type WithCustomUserInput<
  K extends CombinedRecipientKind = CombinedRecipientKind,
> = CombinedRecipientItem<K> | CombinedRecipientItem<'custom'>;

export type CombinedRecipientItem<K extends keyof EntityMap = keyof EntityMap> =
  PickEntity<K>;

type EntityMapper<K extends keyof EntityMap> = (
  data: EntityMap[K]
) => PickEntity<K>;

export function recipientEntityMapper<K extends keyof EntityMap>(
  kind: K
): EntityMapper<K> {
  return (data: EntityMap[K]) => ({ kind, data, id: data.id });
}