@@ -17,6 +17,9 @@ import {
1717 type DeviceSession ,
1818 type DeviceShutdownInput ,
1919 type DeviceSummary ,
20+ type DeviceEasAccount ,
21+ DeviceEasAccountError ,
22+ type DeviceEasAccountInput ,
2023 type DeviceHostConfig ,
2124 type EasDeviceHostConfig ,
2225 type SshDeviceHostConfig ,
@@ -46,6 +49,7 @@ import * as Scope from "effect/Scope";
4649import * as Semaphore from "effect/Semaphore" ;
4750import * as Stream from "effect/Stream" ;
4851import * as SynchronizedRef from "effect/SynchronizedRef" ;
52+ import * as HttpClient from "effect/http/HttpClient" ;
4953
5054import * as ServerSettings from "../serverSettings.ts" ;
5155import { isLocalSshDeviceHost , remoteSshDeviceHosts } from "./localSshDeviceHost.ts" ;
@@ -55,6 +59,7 @@ import * as ProcessRunner from "../processRunner.ts";
5559import * as DeviceHost from "./DeviceHost.ts" ;
5660import * as SshDeviceHost from "./SshDeviceHost.ts" ;
5761import * as EasDeviceHost from "./EasDeviceHost.ts" ;
62+ import { makeExpoApi , resolveExpoCredential } from "./ExpoApi.ts" ;
5863import * as Exit from "effect/Exit" ;
5964import * as LocalDeviceHost from "./LocalDeviceHost.ts" ;
6065
@@ -103,6 +108,10 @@ export class DeviceService extends Context.Service<
103108 readonly testHost : (
104109 config : SshDeviceHostConfig ,
105110 ) => Effect . Effect < DeviceHostSummary , DeviceError > ;
111+ /** Who an Expo credential signs in as and which EAS projects it can run sessions under. */
112+ readonly easAccount : (
113+ input : DeviceEasAccountInput ,
114+ ) => Effect . Effect < DeviceEasAccount , DeviceEasAccountError > ;
106115 /**
107116 * The agent-device flags that reach the device: its config and session,
108117 * and the id agent-device selects it by, which can differ from its id here.
@@ -199,6 +208,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
199208 supportsHostRetry : true ,
200209 supportsToolUpdate : installTool !== undefined ,
201210 supportsToolInspection : true ,
211+ supportsEasHosts : true ,
202212 hosts : initialHosts ,
203213 hostStatus : initialSettings . enabled ? "idle" : "disabled" ,
204214 hostStatuses : { } ,
@@ -810,6 +820,12 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
810820 ) ,
811821 retryHost,
812822 inspect,
823+ easAccount : ( ) =>
824+ Effect . fail (
825+ new DeviceEasAccountError ( {
826+ reason : "EAS accounts are unavailable in this device service." ,
827+ } ) ,
828+ ) ,
813829 agentCli : Effect . fail (
814830 new DeviceHostUnavailableError ( {
815831 hostId : LOCAL_DEVICE_HOST_ID ,
@@ -1083,8 +1099,38 @@ export const make = Effect.gen(function* () {
10831099 concurrency : 4 ,
10841100 } ) ,
10851101 ) ;
1102+ const easAccount : DeviceService [ "Service" ] [ "easAccount" ] = Effect . fn ( "DeviceService.easAccount" ) (
1103+ function * ( input ) {
1104+ const saved =
1105+ input . hostId === undefined
1106+ ? ""
1107+ : ( ( yield * settings . getSettings ) . easDeviceHosts . find ( ( host ) => host . id === input . hostId )
1108+ ?. accessToken ?? "" ) ;
1109+ const credential = yield * resolveExpoCredential ( input . accessToken ?? saved ) ;
1110+ const viewer = yield * makeExpoApi ( yield * HttpClient . HttpClient , credential ) . viewer ;
1111+ return { signedInAs : viewer . name , credentialSource : credential . source , apps : viewer . apps } ;
1112+ } ,
1113+ Effect . provide ( easContext ) ,
1114+ // Only bounded text reaches the browser: the credential errors' own
1115+ // guidance, or a category for what Expo answered, never Expo's text.
1116+ Effect . mapError (
1117+ ( cause ) =>
1118+ new DeviceEasAccountError ( {
1119+ reason :
1120+ cause . _tag === "ExpoApiError"
1121+ ? cause . status === 401 || cause . status === 403
1122+ ? `Expo rejected the credential (HTTP ${ cause . status } ).`
1123+ : cause . rejected
1124+ ? "Expo refused the account check."
1125+ : "Could not complete the Expo account check."
1126+ : cause . message ,
1127+ } ) ,
1128+ ) ,
1129+ ) ;
1130+
10861131 return {
10871132 ...service ,
1133+ easAccount,
10881134 agentCli : resolveNodeExecutable ( "Device automation" ) . pipe (
10891135 Effect . andThen ( ensureAgentDevice ( config . baseDir ) ) ,
10901136 Effect . provideService ( FileSystem . FileSystem , fs ) ,
0 commit comments