@@ -7,9 +7,14 @@ import Link from 'next/link'
77import { HomeSection } from '@/components/home/home-section'
88import { OAUTH_SEARCH_READ_SCOPE , oauthScopeSatisfies } from '@/lib/auth/oauth-provider'
99import { organizationRoutes } from '@/lib/navigation/paths'
10+ import {
11+ liveSearchProviderForCredential ,
12+ supportsLiveSearchMode ,
13+ } from '@/lib/sim-search/live/provider-catalog'
1014import { useOrganizationContext } from '@/app/o/[organizationId]/providers/organization-provider'
1115import { useAuthorizedApps } from '@/hooks/queries/oauth-provider'
1216import { useOrganizationAccounts } from '@/hooks/queries/organization-accounts'
17+ import { useSearchIntegrations } from '@/hooks/queries/search-integrations'
1318
1419type StepId = 'connect-integration' | 'connect-sim-search'
1520
@@ -69,9 +74,15 @@ function StepMark({ complete }: { complete: boolean }) {
6974 * and reads as done from the organization's real state: a connected account and an OAuth app authorized to use Search.
7075 */
7176export function GetStarted ( ) {
72- const { organization, viewer } = useOrganizationContext ( )
77+ const { organization, viewer, connectedAccountsAvailable } = useOrganizationContext ( )
7378 const routes = organizationRoutes ( organization . id )
74- const { data : accounts } = useOrganizationAccounts ( organization . id )
79+ const canConnectIntegrations = viewer . canConnectSearchIntegrations && connectedAccountsAvailable
80+ const { data : accounts } = useOrganizationAccounts (
81+ canConnectIntegrations ? organization . id : undefined
82+ )
83+ const { data : integrations } = useSearchIntegrations ( organization . id , {
84+ enabled : canConnectIntegrations ,
85+ } )
7586 const {
7687 data : authorizedApps ,
7788 fetchNextPage,
@@ -83,6 +94,46 @@ export function GetStarted() {
8394 authorizedApps ?. pages . some ( ( page ) =>
8495 page . apps . some ( ( app ) => oauthScopeSatisfies ( app . scopes , OAUTH_SEARCH_READ_SCOPE ) )
8596 ) ?? false
97+ const approvedProviders = new Set (
98+ integrations
99+ ?. filter ( ( integration ) => integration . approved && integration . available !== false )
100+ . map ( ( integration ) => integration . connectorType )
101+ )
102+ const readyOptions = new Set (
103+ accounts ?. credentialGroup ?. options
104+ . filter ( ( option ) => {
105+ const provider = liveSearchProviderForCredential ( option . provider )
106+ return (
107+ option . status === 'active' &&
108+ option . configurationStatus === 'ready' &&
109+ provider &&
110+ supportsLiveSearchMode ( provider , 'member' ) &&
111+ approvedProviders . has ( provider )
112+ )
113+ } )
114+ . map ( ( option ) => option . id )
115+ )
116+ const readyMcpServers = new Set (
117+ accounts ?. credentialGroup ?. mcpServers
118+ . filter ( ( server ) => {
119+ const provider = liveSearchProviderForCredential ( `mcp:${ server . managedConnectorId } ` )
120+ return (
121+ server . enabled &&
122+ provider &&
123+ approvedProviders . has ( provider ) &&
124+ accounts . availableMcpConnectors . some ( ( id ) => id === server . managedConnectorId )
125+ )
126+ } )
127+ . map ( ( server ) => server . id )
128+ )
129+ const hasSearchConnection =
130+ accounts ?. credentialGroup ?. status === 'active' &&
131+ ( accounts . viewerAccounts ?. some (
132+ ( account ) => account . status === 'active' && readyOptions . has ( account . optionId )
133+ ) ||
134+ accounts . viewerMcpAccounts ?. some (
135+ ( account ) => account . status === 'active' && readyMcpServers . has ( account . mcpServerId )
136+ ) )
86137
87138 const hrefs : Record < StepId , string > = {
88139 'connect-integration' : viewer . isAdmin
@@ -91,13 +142,12 @@ export function GetStarted() {
91142 'connect-sim-search' : routes . settingsSection ( 'search-mcp' ) ,
92143 }
93144 const completed : Record < StepId , boolean > = {
94- 'connect-integration' : Boolean (
95- accounts ?. viewerAccounts ?. some ( ( account ) => account . status === 'active' ) ||
96- accounts ?. viewerMcpAccounts ?. some ( ( account ) => account . status === 'active' )
97- ) ,
145+ 'connect-integration' : Boolean ( hasSearchConnection ) ,
98146 'connect-sim-search' : hasSearchAuthorization ,
99147 }
100- const steps = STEPS . filter ( ( step ) => step . id !== 'connect-sim-search' || viewer . canUseSearchMcp )
148+ const steps = STEPS . filter ( ( step ) =>
149+ step . id === 'connect-sim-search' ? viewer . canUseSearchMcp : canConnectIntegrations
150+ )
101151
102152 const [ expanded , setExpanded ] = useState ( true )
103153 /**
@@ -132,6 +182,8 @@ export function GetStarted() {
132182 setExpanded ( ( prev ) => ! prev )
133183 }
134184
185+ if ( steps . length === 0 ) return null
186+
135187 return (
136188 < HomeSection
137189 title = 'Get started'
0 commit comments