Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
Add GitHub PR entity type filter support (#4107)
Peter Chinmanc1d4a69e5b47
diff --git a/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts b/js/app/packages/app/component/app-sidebar/soup-filter-presets.tsindex 480153de43..1e43e4a63c 100644--- a/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts+++ b/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts@@ -93,6 +93,7 @@ const getInboxSignalFilters = () => {// Referencing `fef` also opts them into the signal query (otherwise// defineQueryFilters excludes unreferenced entity types). Rendering is// still gated on the supported-foreign-entities flag client-side.+ foreignEntitySource: ['github_pull_request'],foreignEntityDone: false,foreignEntityIncludesMe: true,emailShared: 'exclude',@@ -135,6 +136,9 @@ export const VIEW_TAB_PRESETS: Record<ListView, ViewTabConfig> = {// crm companies aren't surfaced outside the Companies view.include: {crmCompanyId: [NIL_UUID],+ ...(ENABLE_SUPPORTED_SOUP_FOREIGN_ENTITIES_OVERRIDE+ ? { foreignEntitySource: ['github_pull_request'] }+ : {}),foreignEntityIncludesMe: true,},exclude: {diff --git a/js/app/packages/app/component/next-soup/filters/configs/base.ts b/js/app/packages/app/component/next-soup/filters/configs/base.tsindex 2913f02f22..7203cabea1 100644--- a/js/app/packages/app/component/next-soup/filters/configs/base.ts+++ b/js/app/packages/app/component/next-soup/filters/configs/base.ts@@ -33,6 +33,7 @@ export const VIDEO_EXTENSIONS = [export const isEmail = { exclude: { threadId: [NIL_UUID] } };export const isAgent = { exclude: { chatId: [NIL_UUID] } };+export const isForeign = { exclude: { foreignEntityRecordId: [NIL_UUID] } };export const isTask = { include: { subType: ['task'] } };export const isNotTask = { exclude: { subType: ['task'] } };export const isEmailAttachment = { include: { isEmailAttachment: true } };diff --git a/js/app/packages/app/component/next-soup/filters/configs/entity-type.ts b/js/app/packages/app/component/next-soup/filters/configs/entity-type.tsindex cd6353a374..3c18c4d239 100644--- a/js/app/packages/app/component/next-soup/filters/configs/entity-type.ts+++ b/js/app/packages/app/component/next-soup/filters/configs/entity-type.ts@@ -4,11 +4,12 @@ import {documentFilter as documentPredicate,emailFilter as emailPredicate,fileFilter as filePredicate,+ githubPrFilter as githubPrPredicate,peopleFilter as peoplePredicate,taskFilter as taskPredicate,teamsFilter as teamsPredicate,} from '../predicates';-import { config, isAgent, isEmail, isTask } from './base';+import { config, isAgent, isEmail, isForeign, isTask } from './base';const documentFilter = config({id: 'document',@@ -71,6 +72,18 @@ const fileFilter = config({},});+const githubPrFilter = config({+ id: 'github-pr',+ group: 'entity-type',+ predicate: githubPrPredicate,+ query: {+ ...isForeign,+ include: {+ foreignEntitySource: ['github_pull_request'],+ },+ },+});+export const ENTITY_TYPE_FILTERS = [documentFilter,agentFilter,@@ -80,4 +93,5 @@ export const ENTITY_TYPE_FILTERS = [taskFilter,emailFilter,fileFilter,+ githubPrFilter,] as const;diff --git a/js/app/packages/app/component/next-soup/filters/configs/general.ts b/js/app/packages/app/component/next-soup/filters/configs/general.tsindex 6b784ff8ca..7fc1bdb7ee 100644--- a/js/app/packages/app/component/next-soup/filters/configs/general.ts+++ b/js/app/packages/app/component/next-soup/filters/configs/general.ts@@ -26,6 +26,7 @@ export const inboxFilter = config({channelDone: false,chatDone: false,folderDone: false,+ foreignEntitySource: ['github_pull_request'],foreignEntityDone: false,},emailView: 'inbox',diff --git a/js/app/packages/app/component/next-soup/filters/filter-store/compile.test.ts b/js/app/packages/app/component/next-soup/filters/filter-store/compile.test.tsnew file mode 100644index 0000000000..16d6bd124e--- /dev/null+++ b/js/app/packages/app/component/next-soup/filters/filter-store/compile.test.ts@@ -0,0 +1,19 @@+import { describe, expect, it } from 'vitest';+import { compileToAst, queryStateFrom } from './compile';++describe('compileToAst', () => {+ it('compiles foreign entity source filters to the backend AST source literal', () => {+ const ast = compileToAst(+ queryStateFrom({+ include: {+ foreignEntitySource: ['github_pull_request'],+ foreignEntityDone: false,+ },+ })+ );++ expect(ast.fef).toEqual({+ '&': [{ l: { fes: 'github_pull_request' } }, { l: { nd: false } }],+ });+ });+});diff --git a/js/app/packages/app/component/next-soup/filters/filter-store/compile.ts b/js/app/packages/app/component/next-soup/filters/filter-store/compile.tsindex 583a1d7369..43e1e008b2 100644--- a/js/app/packages/app/component/next-soup/filters/filter-store/compile.ts+++ b/js/app/packages/app/component/next-soup/filters/filter-store/compile.ts@@ -116,6 +116,7 @@ const FIELD_CONFIG: Record<callStatus: { target: 'callf', field: 'Status' },callAttended: { target: 'callf', field: 'Attended' },foreignEntityRecordId: { target: 'fef', field: 'id' },+ foreignEntitySource: { target: 'fef', field: 'fes' },foreignEntitySeen: { target: 'fef', field: 'ns' },foreignEntityDone: { target: 'fef', field: 'nd' },foreignEntityIncludesMe: { target: 'fef', field: 'me', unit: true },diff --git a/js/app/packages/app/component/next-soup/filters/filter-store/types.ts b/js/app/packages/app/component/next-soup/filters/filter-store/types.tsindex 561e5a1624..5fa739bde2 100644--- a/js/app/packages/app/component/next-soup/filters/filter-store/types.ts+++ b/js/app/packages/app/component/next-soup/filters/filter-store/types.ts@@ -46,6 +46,7 @@ export type ArrayFieldFilters = {callChannelId?: string[];callSpeakerId?: string[];foreignEntityRecordId?: string[];+ foreignEntitySource?: string[];crmCompanyId?: string[];properties?: PropertyFilter[];};diff --git a/js/app/packages/app/component/next-soup/filters/predicates.ts b/js/app/packages/app/component/next-soup/filters/predicates.tsindex 8474da1faa..6a0c4fb3ee 100644--- a/js/app/packages/app/component/next-soup/filters/predicates.ts+++ b/js/app/packages/app/component/next-soup/filters/predicates.ts@@ -2,6 +2,7 @@ import {type EntityData,getTaskAssigneeIds,getTaskStatusOptionId,+ isGithubPrEntity,isTaskEntity,type TaskEntityWithProperties,toNotificationEntity,@@ -101,6 +102,10 @@ export function fileFilter(entity: EntityData): boolean {return !['md', 'canvas'].includes(fileType);}+export function githubPrFilter(entity: EntityData): boolean {+ return isGithubPrEntity(entity);+}+export function channelsFilter(entity: EntityData): boolean {return entity.type === 'channel' || entity.type === 'channel_message';}diff --git a/js/app/packages/app/component/next-soup/soup-view/create-search-state.ts b/js/app/packages/app/component/next-soup/soup-view/create-search-state.tsindex 5099ed82f9..ba37a14356 100644--- a/js/app/packages/app/component/next-soup/soup-view/create-search-state.ts+++ b/js/app/packages/app/component/next-soup/soup-view/create-search-state.ts@@ -116,9 +116,13 @@ function filterDataToQueryFilters(data: QueryState): EntityFilters {}// Foreign entity filters- if (include.foreignEntityRecordId?.length) {+ if (+ include.foreignEntityRecordId?.length ||+ include.foreignEntitySource?.length+ ) {filters.foreign_entity_filters = {ids: include.foreignEntityRecordId,+ foreign_entity_sources: include.foreignEntitySource,};}diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/filter-categories.ts b/js/app/packages/app/component/next-soup/soup-view/filters-bar/filter-categories.tsnew file mode 100644index 0000000000..a06d839624--- /dev/null+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/filter-categories.ts@@ -0,0 +1,35 @@+import type { FilterID } from '@app/component/next-soup/filters';+import type { JSX } from 'solid-js';++export type FilterOption = {+ id: FilterID;+ label: string;+ icon?: () => JSX.Element;+};++export type FilterCategory = {+ id: string;+ label: string;+ /** Plural form for multi-value chip display (e.g., 'Types', 'Statuses') */+ labelPlural?: string;+ options: FilterOption[];+ multiple?: boolean;+};++export function filterInboxGithubPrOption(+ categories: FilterCategory[],+ hasGithub: boolean+): FilterCategory[] {+ if (hasGithub) return categories;++ return categories.map((category) =>+ category.id === 'type'+ ? {+ ...category,+ options: category.options.filter(+ (option) => option.id !== 'github-pr'+ ),+ }+ : category+ );+}diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.test.ts b/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.test.tsnew file mode 100644index 0000000000..cc7d278f6c--- /dev/null+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.test.ts@@ -0,0 +1,41 @@+import { describe, expect, it } from 'vitest';+import {+ type FilterCategory,+ filterInboxGithubPrOption,+} from './filter-categories';++const categories: FilterCategory[] = [+ {+ id: 'type',+ label: 'Type',+ options: [+ { id: 'document', label: 'Docs' },+ { id: 'github-pr', label: 'GitHub PRs' },+ ],+ multiple: true,+ },+ {+ id: 'status',+ label: 'Status',+ options: [{ id: 'unread', label: 'Unread' }],+ },+];++describe('filterInboxGithubPrOption', () => {+ it('keeps the GitHub PR option for linked users', () => {+ expect(filterInboxGithubPrOption(categories, true)[0]?.options).toEqual([+ { id: 'document', label: 'Docs' },+ { id: 'github-pr', label: 'GitHub PRs' },+ ]);+ });++ it('removes the GitHub PR option for users without a linked GitHub account', () => {+ expect(filterInboxGithubPrOption(categories, false)[0]?.options).toEqual([+ { id: 'document', label: 'Docs' },+ ]);+ });++ it('leaves other filter categories unchanged', () => {+ expect(filterInboxGithubPrOption(categories, false)[1]).toBe(categories[1]);+ });+});diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsxindex e66e7ca70a..8271bcfa9c 100644--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx@@ -1,5 +1,4 @@import { getViewPreset } from '@app/component/app-sidebar/soup-filter-presets';-import type { FilterID } from '@app/component/next-soup/filters';import {type FilterContext,NO_ASSIGNEE,@@ -25,6 +24,7 @@ import CircleDashedIcon from '@phosphor/circle-dashed.svg';import FilterIcon from '@phosphor/funnel-simple.svg';import { PropertyValueIcon } from '@property/component/propertyValue/PropertyValueIcon';import { PROPERTY_OPTION_IDS, SYSTEM_PROPERTY_IDS } from '@property/constants';+import { useGithubLinkStatusQuery } from '@queries/auth';import { useContacts } from '@queries/contacts/contacts';import { cn, Dropdown, Tooltip } from '@ui';import {@@ -40,11 +40,17 @@ import {Show,Switch,} from 'solid-js';+import {+ type FilterCategory,+ filterInboxGithubPrOption,+} from './filter-categories';import {SearchableMultiSelectInline,type SearchableOption,} from './searchable-multi-select';+export type { FilterCategory, FilterOption } from './filter-categories';+export const TypeIndicator = (props: { active: boolean }) => (<spanclass={cn(@@ -64,21 +70,6 @@ export const TypeIndicator = (props: { active: boolean }) => (// distributing label + caret to the row ends.// const FILTER_MENU_SUBTRIGGER_CLASS = 'justify-between gap-2';-export type FilterOption = {- id: FilterID;- label: string;- icon?: () => JSX.Element;-};--type FilterCategory = {- id: string;- label: string;- /** Plural form for multi-value chip display (e.g., 'Types', 'Statuses') */- labelPlural?: string;- options: FilterOption[];- multiple?: boolean;-};-// Filter categories by viewconst INBOX_FILTER_CATEGORIES: FilterCategory[] = [{@@ -121,6 +112,11 @@ const INBOX_FILTER_CATEGORIES: FilterCategory[] = [label: 'Files',icon: () => <EntityIcon targetType="files" size="xs" />,},+ {+ id: 'github-pr',+ label: 'GitHub PRs',+ icon: () => <EntityIcon targetType="githubPullRequest" size="xs" />,+ },],multiple: true,},@@ -486,11 +482,21 @@ export const UnifiedFilterDropdown = (return undefined;return content.id;});+ const githubLinkStatus = useGithubLinkStatusQuery({+ enabled: () => currentView() === 'inbox',+ });const categories = createMemo(() => {const view = currentView();if (!view) return [];- return VIEW_FILTER_CATEGORIES[view] ?? [];+ const viewCategories = VIEW_FILTER_CATEGORIES[view] ?? [];++ if (view !== 'inbox') return viewCategories;++ return filterInboxGithubPrOption(+ viewCategories,+ githubLinkStatus.data?.status === 'linked'+ );});const isOptionActive = (optionId: string) => {diff --git a/js/app/packages/app/component/settings/GitHub.tsx b/js/app/packages/app/component/settings/GitHub.tsxindex c69ffb8f86..fb0b319076 100644--- a/js/app/packages/app/component/settings/GitHub.tsx+++ b/js/app/packages/app/component/settings/GitHub.tsx@@ -1,7 +1,12 @@import { toast } from '@core/component/Toast/Toast';import GithubIcon from '@icon/mcp-github.svg';-import { authServiceClient } from '@service-auth/client';-import { createResource, Show } from 'solid-js';+import {+ useDeleteGithubLinkMutation,+ useGithubLinkStatusQuery,+ useInitGithubLinkMutation,+ useReauthenticateGithubMutation,+} from '@queries/auth';+import { Show } from 'solid-js';import { match } from 'ts-pattern';import { Button } from '@ui';import {@@ -11,68 +16,38 @@ import {StatusPill,} from './integration-ui';-type GithubLinkStatus = 'linked' | 'unlinked' | 'reauthentication_required';--type GithubLink = {- status: GithubLinkStatus;- // Populated once the auth service starts returning the linked account's- // handle on /link/github/status. Until then it stays undefined and the- // username line below simply doesn't render.- username?: string;-};-export function GitHub() {- const [githubLink, { refetch: refetchGithubLink }] = createResource(- async (): Promise<GithubLink> => {- const response = await authServiceClient.checkGithubLinkStatus();+ const githubLink = useGithubLinkStatusQuery();+ const initGithubLink = useInitGithubLinkMutation();+ const deleteGithubLink = useDeleteGithubLinkMutation();+ const reauthenticateGithub = useReauthenticateGithubMutation();- if (response.isOk()) {- // `github_username` is not yet part of the generated response schema;- // read it defensively so the UI lights up automatically once the- // backend includes it.- const username =- (response.value as { github_username?: string | null })- .github_username ?? undefined;- return {- status: response.value.reauthentication_required- ? 'reauthentication_required'- : 'linked',- username,- };- }-- const needsReauthentication = response.error.some(- (error) => error.code === 'REAUTHENTICATION_REQUIRED'- );- return {- status: needsReauthentication- ? 'reauthentication_required'- : 'unlinked',- };- }- );-- const status = () => githubLink()?.status;+ const status = () => githubLink.data?.status;const handleGithubEnable = async () => {- const url = await authServiceClient.initGithubLink(window.location.href);- if (url.isOk()) {- window.location.href = url.value;+ try {+ window.location.href = await initGithubLink.mutateAsync(+ window.location.href+ );+ } catch {+ toast.failure('Failed to start GitHub connect flow');}};const handleGithubDisable = async () => {- await authServiceClient.deleteGithubLink();- refetchGithubLink();+ try {+ await deleteGithubLink.mutateAsync();+ } catch {+ toast.failure('Failed to disconnect GitHub');+ }};const handleGithubReconnect = async () => {- const url = await authServiceClient.reauthenticateGithub(- window.location.href- );- if (url.isOk()) {- window.location.href = url.value;- } else {+ try {+ window.location.href = await reauthenticateGithub.mutateAsync(+ window.location.href+ );+ } catch {toast.failure('Failed to start GitHub reconnect flow');}};@@ -91,7 +66,7 @@ export function GitHub() {return (<IntegrationPanelShell title="GitHub"><Show- when={!githubLink.loading}+ when={!githubLink.isLoading}fallback={<div class="flex items-center justify-center pt-24 text-sm text-ink-muted">Loading…@@ -105,7 +80,7 @@ export function GitHub() {status={<div class="flex flex-col items-center gap-2"><StatusPill state={pill().state} label={pill().label} />- <Show when={status() === 'linked' && githubLink()?.username}>+ <Show when={status() === 'linked' && githubLink.data?.username}>{(username) => (<span class="ph-no-capture text-sm text-ink">@{username()}@@ -121,6 +96,7 @@ export function GitHub() {size="md"depth={3}onClick={handleGithubReconnect}+ disabled={reauthenticateGithub.isPending}>Reconnect</Button>@@ -131,6 +107,7 @@ export function GitHub() {size="md"depth={3}onClick={handleGithubDisable}+ disabled={deleteGithubLink.isPending}>Disconnect</Button>@@ -145,6 +122,7 @@ export function GitHub() {size="md"depth={3}onClick={handleGithubEnable}+ disabled={initGithubLink.isPending}>Connect GitHub</Button>diff --git a/js/app/packages/queries/auth/github-link.ts b/js/app/packages/queries/auth/github-link.tsnew file mode 100644index 0000000000..76c00e6000--- /dev/null+++ b/js/app/packages/queries/auth/github-link.ts@@ -0,0 +1,111 @@+import { throwOnErr } from '@core/util/result';+import { queryClient } from '@queries/client';+import { invalidateAllSoup } from '@queries/soup/normalized-cache';+import { authServiceClient } from '@service-auth/client';+import { useMutation, useQuery } from '@tanstack/solid-query';+import { authKeys } from './keys';++const GITHUB_LINK_STATUS_STALE_TIME = 5 * 60 * 1000;++export type GithubLinkStatus =+ | 'linked'+ | 'unlinked'+ | 'reauthentication_required';++export type GithubLink = {+ status: GithubLinkStatus;+ // Populated once auth-service includes the linked account handle on+ // /link/github/status.+ username?: string;+};++type UseGithubLinkStatusQueryOptions = {+ enabled?: boolean | (() => boolean);+};++function hasReauthenticationError(+ errors: Array<{ code: string; message?: string }>+): boolean {+ return errors.some((error) => error.code === 'REAUTHENTICATION_REQUIRED');+}++export async function fetchGithubLinkStatus(): Promise<GithubLink> {+ const response = await authServiceClient.checkGithubLinkStatus();++ if (response.isOk()) {+ const username =+ (response.value as { github_username?: string | null }).github_username ??+ undefined;++ return {+ status: response.value.reauthentication_required+ ? 'reauthentication_required'+ : 'linked',+ username,+ };+ }++ return {+ status: hasReauthenticationError(response.error)+ ? 'reauthentication_required'+ : 'unlinked',+ };+}++export function githubLinkStatusQueryOptions() {+ return {+ queryKey: authKeys.githubLinkStatus.queryKey,+ queryFn: fetchGithubLinkStatus,+ staleTime: GITHUB_LINK_STATUS_STALE_TIME,+ refetchOnWindowFocus: 'always' as const,+ };+}++export function useGithubLinkStatusQuery(+ options?: UseGithubLinkStatusQueryOptions+) {+ return useQuery(() => {+ const enabled =+ typeof options?.enabled === 'function'+ ? options.enabled()+ : (options?.enabled ?? true);++ return {+ ...githubLinkStatusQueryOptions(),+ enabled,+ };+ });+}++export function invalidateGithubLinkStatus() {+ return queryClient.invalidateQueries({+ queryKey: authKeys.githubLinkStatus.queryKey,+ });+}++export function useInitGithubLinkMutation() {+ return useMutation(() => ({+ mutationFn: async (originalUrl?: string) =>+ await throwOnErr(() => authServiceClient.initGithubLink(originalUrl)),+ }));+}++export function useReauthenticateGithubMutation() {+ return useMutation(() => ({+ mutationFn: async (originalUrl?: string) =>+ await throwOnErr(() =>+ authServiceClient.reauthenticateGithub(originalUrl)+ ),+ }));+}++export function useDeleteGithubLinkMutation() {+ return useMutation(() => ({+ mutationFn: async () =>+ await throwOnErr(() => authServiceClient.deleteGithubLink()),+ onSuccess: () => {+ invalidateGithubLinkStatus();+ invalidateAllSoup();+ },+ }));+}diff --git a/js/app/packages/queries/auth/index.ts b/js/app/packages/queries/auth/index.tsindex 69aa772879..2b3ba1bc6a 100644--- a/js/app/packages/queries/auth/index.ts+++ b/js/app/packages/queries/auth/index.ts@@ -4,6 +4,15 @@ export {useUserId,useUserInfo,} from '@core/context/user';+export {+ type GithubLink,+ type GithubLinkStatus,+ invalidateGithubLinkStatus,+ useDeleteGithubLinkMutation,+ useGithubLinkStatusQuery,+ useInitGithubLinkMutation,+ useReauthenticateGithubMutation,+} from './github-link';export { useInitGmailLink } from './gmail-link';export { authKeys } from './keys';export { useSendMobileWelcomeEmail } from './mobile-welcome-email';diff --git a/js/app/packages/queries/auth/keys.ts b/js/app/packages/queries/auth/keys.tsindex f2dabd3b3d..c29cf1e5ab 100644--- a/js/app/packages/queries/auth/keys.ts+++ b/js/app/packages/queries/auth/keys.ts@@ -1,6 +1,7 @@import { createQueryKeys } from '@lukemorales/query-key-factory';export const authKeys = createQueryKeys('auth', {+ githubLinkStatus: null,userInfo: null,userName: (userId: string) => ({queryKey: [userId],