@@ -3,13 +3,17 @@ import {
33 type EnvironmentConnectionPresentation ,
44 RelayConnectionRegistration ,
55 RelayConnectionTarget ,
6+ orchestrationProtocolCompatibilityError ,
67} from "@t3tools/client-runtime/connection" ;
78import {
89 isAtomCommandInterrupted ,
910 squashAtomCommandFailure ,
1011} from "@t3tools/client-runtime/state/runtime" ;
1112import type { EnvironmentId } from "@t3tools/contracts" ;
12- import type { RelayClientEnvironmentRecord } from "@t3tools/contracts/relay" ;
13+ import type {
14+ RelayClientEnvironmentRecord ,
15+ RelayEnvironmentStatusResponse ,
16+ } from "@t3tools/contracts/relay" ;
1317import * as Option from "effect/Option" ;
1418import { type ReactNode , useCallback , useEffect , useEffectEvent , useState } from "react" ;
1519
@@ -29,6 +33,13 @@ import { presentSavedCloudEnvironmentConnection } from "./cloudEnvironmentConnec
2933
3034const EMPTY_DISCOVERY_REFRESH_INTERVAL_MS = 5_000 ;
3135
36+ function discoveredCompatibilityError (
37+ status : Option . Option < RelayEnvironmentStatusResponse > | undefined ,
38+ ) {
39+ const descriptor = status === undefined ? undefined : Option . getOrNull ( status ) ?. descriptor ;
40+ return descriptor === undefined ? null : orchestrationProtocolCompatibilityError ( descriptor ) ;
41+ }
42+
3243export interface SavedCloudEnvironmentConnection {
3344 readonly environmentId : EnvironmentId ;
3445 readonly connection : EnvironmentConnectionPresentation ;
@@ -119,6 +130,12 @@ export function CloudEnvironmentConnectRows({
119130 } , [ refreshRelayEnvironments , refreshWhileEmpty , onDiscoveryReady ] ) ;
120131
121132 const connectEnvironment = async ( environment : RelayClientEnvironmentRecord ) => {
133+ if (
134+ discoveredCompatibilityError (
135+ environmentsState . environments . get ( environment . environmentId ) ?. status ,
136+ ) !== null
137+ )
138+ return false ;
122139 setConnectingEnvironmentIds ( ( current ) => new Set ( [ ...current , environment . environmentId ] ) ) ;
123140 const result = await connectRelayEnvironment ( environment ) ;
124141 setConnectingEnvironmentIds ( ( current ) => {
@@ -166,8 +183,17 @@ export function CloudEnvironmentConnectRows({
166183 const selectNewComputers = useEffectEvent ( ( ) => {
167184 const seen = selection ?. autoSelectedComputers ;
168185 if ( ! selection || ! seen ) return ;
169- for ( const { environment } of visibleEnvironments ) {
186+ for ( const { environment, status , availability } of visibleEnvironments ) {
170187 const id = environment . environmentId ;
188+ if ( availability === "checking" ) continue ;
189+ if (
190+ discoveredCompatibilityError ( status ) !== null ||
191+ savedById . get ( id ) ?. connection . phase === "unsupported"
192+ ) {
193+ seen . add ( id ) ;
194+ if ( selection . selectedIds . has ( id ) ) selection . onChange ( id , false ) ;
195+ continue ;
196+ }
171197 if ( seen . has ( id ) ) continue ;
172198 seen . add ( id ) ;
173199 selection . onChange ( id , true ) ;
@@ -265,11 +291,20 @@ export function CloudEnvironmentConnectRows({
265291 return empty ;
266292 }
267293
268- return visibleEnvironments . map ( ( { environment, availability, error } ) => {
294+ return visibleEnvironments . map ( ( { environment, availability, error, status } ) => {
269295 const savedEnvironment = savedById . get ( environment . environmentId ) ;
270- const savedConnection = savedEnvironment
271- ? presentSavedCloudEnvironmentConnection ( savedEnvironment . connection )
272- : null ;
296+ const compatibilityError = discoveredCompatibilityError ( status ) ;
297+ const unsupported =
298+ compatibilityError !== null || savedEnvironment ?. connection . phase === "unsupported" ;
299+ const savedConnection = unsupported
300+ ? presentSavedCloudEnvironmentConnection ( {
301+ phase : "unsupported" ,
302+ error : compatibilityError ?. message ?? savedEnvironment ?. connection . error ?? null ,
303+ traceId : null ,
304+ } )
305+ : savedEnvironment
306+ ? presentSavedCloudEnvironmentConnection ( savedEnvironment . connection )
307+ : null ;
273308 const dotClassName = savedConnection
274309 ? savedConnection . tone === "connected"
275310 ? "bg-success"
@@ -302,9 +337,10 @@ export function CloudEnvironmentConnectRows({
302337 className = "flex cursor-pointer items-center gap-3 rounded-lg border border-border bg-background px-3 py-2.5 has-disabled:cursor-default"
303338 >
304339 < Checkbox
305- checked = { selection . selectedIds . has ( environment . environmentId ) }
306- disabled = { connectingEnvironmentIds . has ( environment . environmentId ) }
340+ checked = { ! unsupported && selection . selectedIds . has ( environment . environmentId ) }
341+ disabled = { unsupported || connectingEnvironmentIds . has ( environment . environmentId ) }
307342 onCheckedChange = { async ( checked ) => {
343+ if ( unsupported ) return ;
308344 selection . onChange ( environment . environmentId , checked ) ;
309345 if ( checked && ! savedEnvironment ) {
310346 const connected = await connectEnvironment ( environment ) ;
0 commit comments