Skip to content
TypeScript

feat(web): set up EAS Simulator hosts in Settings (#21846)

Julius Marminged18352e378c5
diff --git a/apps/server/src/auth/RpcAuthorization.ts b/apps/server/src/auth/RpcAuthorization.ts
index 24ccc3beae1..dca29f707a1 100644
--- a/apps/server/src/auth/RpcAuthorization.ts
+++ b/apps/server/src/auth/RpcAuthorization.ts
@@ -195,6 +195,7 @@ export const RPC_REQUIRED_SCOPES = {
[WS_METHODS.subscribeDiscoveredLocalServers]: AuthOrchestrationReadScope,
[WS_METHODS.deviceConfigure]: AuthSettingsWriteScope,
[WS_METHODS.deviceTestHost]: AuthSettingsWriteScope,
+ [WS_METHODS.deviceEasAccount]: AuthSettingsWriteScope,
[WS_METHODS.deviceList]: AuthOrchestrationReadScope,
[WS_METHODS.deviceOpen]: AuthOrchestrationOperateScope,
[WS_METHODS.deviceClose]: AuthOrchestrationOperateScope,
diff --git a/apps/server/src/device/DeviceService.ts b/apps/server/src/device/DeviceService.ts
index d9963033b38..1ad95d17559 100644
--- a/apps/server/src/device/DeviceService.ts
+++ b/apps/server/src/device/DeviceService.ts
@@ -17,6 +17,9 @@ import {
type DeviceSession,
type DeviceShutdownInput,
type DeviceSummary,
+ type DeviceEasAccount,
+ DeviceEasAccountError,
+ type DeviceEasAccountInput,
type DeviceHostConfig,
type EasDeviceHostConfig,
type SshDeviceHostConfig,
@@ -46,6 +49,7 @@ import * as Scope from "effect/Scope";
import * as Semaphore from "effect/Semaphore";
import * as Stream from "effect/Stream";
import * as SynchronizedRef from "effect/SynchronizedRef";
+import * as HttpClient from "effect/http/HttpClient";
import * as ServerSettings from "../serverSettings.ts";
import { isLocalSshDeviceHost, remoteSshDeviceHosts } from "./localSshDeviceHost.ts";
@@ -55,6 +59,7 @@ import * as ProcessRunner from "../processRunner.ts";
import * as DeviceHost from "./DeviceHost.ts";
import * as SshDeviceHost from "./SshDeviceHost.ts";
import * as EasDeviceHost from "./EasDeviceHost.ts";
+import { makeExpoApi, resolveExpoCredential } from "./ExpoApi.ts";
import * as Exit from "effect/Exit";
import * as LocalDeviceHost from "./LocalDeviceHost.ts";
@@ -103,6 +108,10 @@ export class DeviceService extends Context.Service<
readonly testHost: (
config: SshDeviceHostConfig,
) => Effect.Effect<DeviceHostSummary, DeviceError>;
+ /** Who an Expo credential signs in as and which EAS projects it can run sessions under. */
+ readonly easAccount: (
+ input: DeviceEasAccountInput,
+ ) => Effect.Effect<DeviceEasAccount, DeviceEasAccountError>;
/**
* The agent-device flags that reach the device: its config and session,
* 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*
supportsHostRetry: true,
supportsToolUpdate: installTool !== undefined,
supportsToolInspection: true,
+ supportsEasHosts: true,
hosts: initialHosts,
hostStatus: initialSettings.enabled ? "idle" : "disabled",
hostStatuses: {},
@@ -810,6 +820,12 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
),
retryHost,
inspect,
+ easAccount: () =>
+ Effect.fail(
+ new DeviceEasAccountError({
+ reason: "EAS accounts are unavailable in this device service.",
+ }),
+ ),
agentCli: Effect.fail(
new DeviceHostUnavailableError({
hostId: LOCAL_DEVICE_HOST_ID,
@@ -1083,8 +1099,38 @@ export const make = Effect.gen(function* () {
concurrency: 4,
}),
);
+ const easAccount: DeviceService["Service"]["easAccount"] = Effect.fn("DeviceService.easAccount")(
+ function* (input) {
+ const saved =
+ input.hostId === undefined
+ ? ""
+ : ((yield* settings.getSettings).easDeviceHosts.find((host) => host.id === input.hostId)
+ ?.accessToken ?? "");
+ const credential = yield* resolveExpoCredential(input.accessToken ?? saved);
+ const viewer = yield* makeExpoApi(yield* HttpClient.HttpClient, credential).viewer;
+ return { signedInAs: viewer.name, credentialSource: credential.source, apps: viewer.apps };
+ },
+ Effect.provide(easContext),
+ // Only bounded text reaches the browser: the credential errors' own
+ // guidance, or a category for what Expo answered, never Expo's text.
+ Effect.mapError(
+ (cause) =>
+ new DeviceEasAccountError({
+ reason:
+ cause._tag === "ExpoApiError"
+ ? cause.status === 401 || cause.status === 403
+ ? `Expo rejected the credential (HTTP ${cause.status}).`
+ : cause.rejected
+ ? "Expo refused the account check."
+ : "Could not complete the Expo account check."
+ : cause.message,
+ }),
+ ),
+ );
+
return {
...service,
+ easAccount,
agentCli: resolveNodeExecutable("Device automation").pipe(
Effect.andThen(ensureAgentDevice(config.baseDir)),
Effect.provideService(FileSystem.FileSystem, fs),
diff --git a/apps/server/src/observability/RpcInstrumentation.ts b/apps/server/src/observability/RpcInstrumentation.ts
index 6cc3bdb18b3..4b3ea1f7410 100644
--- a/apps/server/src/observability/RpcInstrumentation.ts
+++ b/apps/server/src/observability/RpcInstrumentation.ts
@@ -199,6 +199,7 @@ const RPC_AGGREGATES = {
[WS_METHODS.subscribeDiscoveredLocalServers]: "preview",
[WS_METHODS.deviceConfigure]: "device",
[WS_METHODS.deviceTestHost]: "device",
+ [WS_METHODS.deviceEasAccount]: "device",
[WS_METHODS.deviceList]: "device",
[WS_METHODS.deviceOpen]: "device",
[WS_METHODS.deviceClose]: "device",
diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts
index 5667a3b3730..7d63d72d861 100644
--- a/apps/server/src/ws.ts
+++ b/apps/server/src/ws.ts
@@ -2904,6 +2904,7 @@ export const layerWsRpc = (
[WS_METHODS.subscribePreviewEvents]: (_input) => previewManager.events,
[WS_METHODS.deviceConfigure]: (input) => deviceService.configure(input),
[WS_METHODS.deviceTestHost]: (input) => deviceService.testHost(input),
+ [WS_METHODS.deviceEasAccount]: (input) => deviceService.easAccount(input),
[WS_METHODS.deviceList]: (input) =>
input.inspectOnly && !input.updateTool
? deviceService.inspect
diff --git a/apps/web/src/components/device/DeviceSetup.test.ts b/apps/web/src/components/device/DeviceSetup.test.ts
index fead75af9e0..711d513e24a 100644
--- a/apps/web/src/components/device/DeviceSetup.test.ts
+++ b/apps/web/src/components/device/DeviceSetup.test.ts
@@ -63,6 +63,48 @@ describe("device setup guidance", () => {
expect(platformSetupStatus(state, "android").message).toBe("Android Emulator is missing.");
});
+ it("names an EAS host instead of local tooling when only the cloud can run iOS", () => {
+ const state = deviceState({
+ hostStatus: "idle",
+ hostStatuses: { eas: { status: "ready" } },
+ hosts: [
+ {
+ ...deviceState().hosts[0]!,
+ platforms: [
+ { platform: "ios", available: false, reason: "Xcode was not found." },
+ { platform: "android", available: false, reason: "No SDK." },
+ ],
+ },
+ {
+ id: "eas",
+ kind: "eas",
+ label: "EAS Simulator",
+ hubInstalled: true,
+ agentDeviceInstalled: true,
+ platforms: [
+ { platform: "ios", available: true },
+ { platform: "android", available: false, reason: "Not supported yet." },
+ ],
+ },
+ ],
+ devices: [
+ {
+ hostId: "eas",
+ id: "eas-ios",
+ platform: "ios",
+ name: "iPhone (EAS Simulator)",
+ version: "Cloud",
+ booted: false,
+ physical: false,
+ },
+ ],
+ });
+ expect(platformSetupStatus(state, "ios")).toEqual({
+ ready: true,
+ message: "EAS Simulator starts iOS Simulators in the cloud with EAS Simulator.",
+ });
+ });
+
it("counts a remote device host when this machine has no simulator tooling", () => {
const state = deviceState({
hostStatus: "idle",
diff --git a/apps/web/src/components/device/DeviceSetup.tsx b/apps/web/src/components/device/DeviceSetup.tsx
index 5b641b94b00..dd9bd6b4526 100644
--- a/apps/web/src/components/device/DeviceSetup.tsx
+++ b/apps/web/src/components/device/DeviceSetup.tsx
@@ -117,9 +117,11 @@ export function platformSetupStatus(state: DeviceServiceState, platform: DeviceP
return {
ready: true,
message:
- platform === "ios"
- ? `Xcode and iOS Simulator are available${location}.`
- : `The Android SDK and Emulator are available${location}.`,
+ remoteHost?.kind === "eas"
+ ? `${remoteHost.label} starts iOS Simulators in the cloud with EAS Simulator.`
+ : platform === "ios"
+ ? `Xcode and iOS Simulator are available${location}.`
+ : `The Android SDK and Emulator are available${location}.`,
};
}
diff --git a/apps/web/src/components/settings/EasDeviceHostsSettings.tsx b/apps/web/src/components/settings/EasDeviceHostsSettings.tsx
new file mode 100644
index 00000000000..f067848ad96
--- /dev/null
+++ b/apps/web/src/components/settings/EasDeviceHostsSettings.tsx
@@ -0,0 +1,422 @@
+import { useEffect, useEffectEvent, useId, useRef, useState } from "react";
+import * as Cause from "effect/Cause";
+import * as Option from "effect/Option";
+import {
+ AuthSettingsWriteScope,
+ type DeviceEasAccount,
+ type EasDeviceHostConfig,
+ type EnvironmentId,
+} from "@t3tools/contracts";
+import { CloudIcon, PlusIcon, XIcon } from "lucide-react";
+
+import { randomUUID } from "../../lib/utils";
+import { deviceEnvironment } from "../../state/device";
+import { serverEnvironment } from "../../state/server";
+import { readEnvironmentScope, useEnvironmentScope } from "../../state/session";
+import { useAtomCommand } from "../../state/use-atom-command";
+import { Button } from "../ui/button";
+import {
+ Dialog,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogPanel,
+ DialogPopup,
+ DialogTitle,
+} from "../ui/dialog";
+import { Input } from "../ui/input";
+import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
+import { Spinner } from "../ui/spinner";
+import { toastManager } from "../ui/toast";
+import {
+ easSessionLimits,
+ newEasDeviceHost,
+ parseEasDeviceHostDraft,
+ updateEasDeviceHosts,
+} from "./easDeviceHostsSettings.logic";
+import { SecretInput } from "./SecretInput";
+import { useSettingsScope } from "./SettingsScopeContext";
+import { SettingsRow } from "./settingsLayout";
+
+const FROM_THREAD_PROJECT = "thread-project";
+
+const CREDENTIAL_SOURCES: Record<DeviceEasAccount["credentialSource"], string> = {
+ settings: "the access token saved here",
+ env: "EXPO_TOKEN on the server",
+ "eas-login": "the server's eas login",
+};
+
+const failureMessage = (cause: Cause.Cause<unknown>) => {
+ const error = Cause.squash(cause);
+ return error instanceof Error ? error.message : String(error);
+};
+
+/** EAS hosts belong to one environment: its server holds the Expo credential and runs the sessions. */
+export function EasDeviceHostsSettings(props: { environmentId: EnvironmentId | null }) {
+ const { scope, connectedEnvironments } = useSettingsScope();
+ const canConfigure = useEnvironmentScope(props.environmentId, AuthSettingsWriteScope);
+ const projectScope = scope.kind === "project" || scope.kind === "checkout";
+ const update = useAtomCommand(serverEnvironment.updateSettings, { reportFailure: false });
+ const environment = connectedEnvironments.find(
+ (candidate) => candidate.environmentId === props.environmentId,
+ );
+ const hosts = environment?.serverConfig?.settings.easDeviceHosts ?? [];
+ const [editing, setEditing] = useState<{ host: EasDeviceHostConfig; isNew: boolean } | null>(
+ null,
+ );
+ const [busy, setBusy] = useState(false);
+ const disabled = !canConfigure || projectScope || busy || !props.environmentId;
+
+ const save = async (host: EasDeviceHostConfig, remove: boolean) => {
+ if (!props.environmentId || !readEnvironmentScope(props.environmentId, AuthSettingsWriteScope))
+ return;
+ setBusy(true);
+ const result = await update({
+ environmentId: props.environmentId,
+ input: { patch: { easDeviceHosts: updateEasDeviceHosts(hosts, host, remove) } },
+ });
+ setBusy(false);
+ if (result._tag === "Success") setEditing(null);
+ else
+ toastManager.add({
+ type: "error",
+ title: remove ? "EAS host not removed" : "EAS host not saved",
+ description: failureMessage(result.cause),
+ });
+ };
+
+ return (
+ <SettingsRow
+ id="eas-device-hosts"
+ title="EAS Simulator"
+ serverScoped
+ settingKeys={["easDeviceHosts"]}
+ description="Run iOS Simulators in Expo's cloud from this environment. Sessions bill the Expo account until they stop, so each host limits how many run and for how long. Editing or removing a host stops its running sessions."
+ control={
+ <Button
+ size="sm"
+ variant="outline"
+ disabled={disabled || editing !== null}
+ onClick={() => setEditing({ host: newEasDeviceHost(randomUUID()), isNew: true })}
+ >
+ <PlusIcon className="size-3.5" /> Add EAS host
+ </Button>
+ }
+ >
+ <div className="pt-3 pb-2">
+ {hosts.length === 0 ? (
+ <p className="text-sm text-muted-foreground">No EAS hosts.</p>
+ ) : (
+ <ul className="divide-y divide-border/40">
+ {hosts.map((host) => (
+ <li key={host.id} className="flex items-center justify-between gap-3 py-2.5 text-sm">
+ <div className="min-w-0">
+ <p className="flex items-center gap-1.5 truncate font-medium">
+ <CloudIcon className="size-3.5 shrink-0" /> {host.label}
+ </p>
+ <p className="truncate text-xs text-muted-foreground">{easSessionLimits(host)}</p>
+ </div>
+ <div className="flex shrink-0 gap-1">
+ <Button
+ size="sm"
+ variant="ghost"
+ disabled={disabled}
+ onClick={() => setEditing({ host, isNew: false })}
+ >
+ Edit
+ </Button>
+ <Button
+ size="sm"
+ variant="ghost-destructive"
+ disabled={disabled}
+ onClick={() => void save(host, true)}
+ >
+ Remove
+ </Button>
+ </div>
+ </li>
+ ))}
+ </ul>
+ )}
+ {editing && props.environmentId ? (
+ <EasDeviceHostEditor
+ key={editing.host.id}
+ environmentId={props.environmentId}
+ host={editing.host}
+ isNew={editing.isNew}
+ busy={busy}
+ onSave={(host) => void save(host, false)}
+ onClose={() => setEditing(null)}
+ />
+ ) : null}
+ </div>
+ </SettingsRow>
+ );
+}
+
+function EasDeviceHostEditor(props: {
+ environmentId: EnvironmentId;
+ host: EasDeviceHostConfig;
+ isNew: boolean;
+ busy: boolean;
+ onSave: (host: EasDeviceHostConfig) => void;
+ onClose: () => void;
+}) {
+ const check = useAtomCommand(deviceEnvironment.easAccount, { reportFailure: false });
+ const [draft, setDraft] = useState(props.host);
+ const tokenId = useId();
+ // A saved token arrives redacted; only a replacement or a clear changes it.
+ const [token, setToken] = useState<
+ { kind: "saved" } | { kind: "new"; value: string } | { kind: "cleared" }
+ >(props.host.accessToken ? { kind: "saved" } : { kind: "cleared" });
+ const [account, setAccount] = useState<
+ | { status: "idle" }
+ | { status: "checking" }
+ | { status: "signed-in"; account: DeviceEasAccount }
+ | { status: "failed"; error: string }
+ // The editor checks the account as it opens.
+ >({ status: "checking" });
+ const next: EasDeviceHostConfig = {
+ ...draft,
+ label: draft.label.trim(),
+ accessToken:
+ token.kind === "saved" ? props.host.accessToken : token.kind === "new" ? token.value : "",
+ };
+ const valid = Option.isSome(parseEasDeviceHostDraft(next));
+ // Why Save is off, for the limits the fields' ranges do not show.
+ const problem = valid
+ ? null
+ : draft.maxSessionMinutes > 0 && draft.idleMinutes >= draft.maxSessionMinutes
+ ? "Idle minutes must be smaller than session minutes."
+ : "Give the host a label and limits within the ranges shown.";
+ const apps = account.status === "signed-in" ? account.account.apps : [];
+
+ // A check answers for the credential it was asked about: a later check or a
+ // token edit makes an earlier answer stale.
+ const latestCheck = useRef(0);
+ const resetAccount = () => {
+ latestCheck.current++;
+ setAccount({ status: "idle" });
+ };
+ const requestCheck = async () => {
+ const run = ++latestCheck.current;
+ const result = await check({
+ environmentId: props.environmentId,
+ input: {
+ ...(token.kind === "saved" && !props.isNew ? { hostId: props.host.id } : {}),
+ // A cleared token is sent as empty, so the check does not fall back to
+ // the saved one that Save is about to drop.
+ ...(token.kind === "new"
+ ? { accessToken: token.value }
+ : token.kind === "cleared"
+ ? { accessToken: "" }
+ : {}),
+ },
+ });
+ if (run !== latestCheck.current) return;
+ setAccount(
+ result._tag === "Success"
+ ? { status: "signed-in", account: result.value }
+ : { status: "failed", error: failureMessage(result.cause) },
+ );
+ };
+ const checkAccount = () => {
+ setAccount({ status: "checking" });
+ void requestCheck();
+ };
+
+ // Checking on open names the saved project and shows a rejected credential
+ // before anything is changed.
+ const checkOnOpen = useEffectEvent(() => void requestCheck());
+ useEffect(() => {
+ checkOnOpen();
+ }, []);
+
+ const limit = (
+ field: "maxSessionMinutes" | "idleMinutes" | "maxConcurrentSessions",
+ label: string,
+ max: number,
+ ) => (
+ <label className="block space-y-1.5">
+ <span>{label}</span>
+ <Input
+ type="number"
+ min={1}
+ max={max}
+ value={draft[field]}
+ disabled={props.busy}
+ onChange={(event) => {
+ const value = Number(event.target.value);
+ setDraft((current) => ({ ...current, [field]: value }));
+ }}
+ />
+ </label>
+ );
+
+ return (
+ <Dialog
+ open
+ onOpenChange={(open) => {
+ if (!open && !props.busy) props.onClose();
+ }}
+ >
+ <DialogPopup showCloseButton={!props.busy}>
+ <form
+ className="flex min-h-0 flex-col"
+ onSubmit={(event) => {
+ event.preventDefault();
+ if (valid && !props.busy) props.onSave(next);
+ }}
+ >
+ <DialogHeader>
+ <DialogTitle>{props.isNew ? "Add EAS host" : "Edit EAS host"}</DialogTitle>
+ <DialogDescription>
+ The environment's server signs in to Expo and starts the sessions. Without a token
+ here it uses EXPO_TOKEN, then its eas login.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogPanel>
+ <label className="block space-y-1.5 text-sm">
+ <span>Name</span>
+ <Input
+ autoFocus
+ required
+ value={draft.label}
+ disabled={props.busy}
+ onChange={(event) => {
+ const label = event.target.value;
+ setDraft((current) => ({ ...current, label }));
+ }}
+ />
+ </label>
+ <div className="space-y-1.5 text-sm">
+ <label htmlFor={tokenId} className="block">
+ Expo access token
+ </label>
+ <div className="flex items-center gap-2">
+ <SecretInput
+ id={tokenId}
+ className="min-w-0 flex-1"
+ configured={token.kind === "saved"}
+ value={token.kind === "new" ? token.value : ""}
+ disabled={props.busy}
+ placeholder="Optional"
+ onChange={(event) => {
+ const value = event.target.value;
+ // Emptying the field is not clearing the saved token; the
+ // Clear button is, so a saved token comes back here.
+ setToken(
+ value
+ ? { kind: "new", value }
+ : props.host.accessToken
+ ? { kind: "saved" }
+ : { kind: "cleared" },
+ );
+ resetAccount();
+ }}
+ />
+ {token.kind !== "cleared" ? (
+ <Button
+ type="button"
+ size="icon-sm"
+ variant="ghost-destructive"
+ aria-label="Clear access token"
+ onClick={() => {
+ setToken({ kind: "cleared" });
+ resetAccount();
+ }}
+ >
+ <XIcon className="size-3.5" />
+ </Button>
+ ) : null}
+ </div>
+ </div>
+ <div className="flex items-center justify-between gap-3 rounded-lg border border-border/60 px-3 py-2.5">
+ <p role="status" className="min-w-0 text-xs text-muted-foreground">
+ {account.status === "signed-in"
+ ? `Signed in as ${account.account.signedInAs} with ${CREDENTIAL_SOURCES[account.account.credentialSource]}.`
+ : account.status === "failed"
+ ? account.error
+ : account.status === "checking"
+ ? "Checking the Expo account…"
+ : "Check the Expo account before choosing a project."}
+ </p>
+ <Button
+ type="button"
+ size="sm"
+ variant="outline"
+ disabled={props.busy || account.status === "checking"}
+ onClick={() => void checkAccount()}
+ >
+ {account.status === "checking" ? <Spinner size="xs" /> : null} Check account
+ </Button>
+ </div>
+ <div className="space-y-1.5 text-sm">
+ <span>EAS project</span>
+ <Select
+ value={draft.appId ?? FROM_THREAD_PROJECT}
+ disabled={props.busy}
+ onValueChange={(value) => {
+ if (typeof value !== "string") return;
+ setDraft((current) => {
+ const { appId: _, ...rest } = current;
+ return value === FROM_THREAD_PROJECT ? rest : { ...rest, appId: value };
+ });
+ }}
+ >
+ <SelectTrigger size="sm" aria-label="EAS project">
+ <SelectValue>
+ {(value: string) =>
+ value === FROM_THREAD_PROJECT
+ ? "From the thread's project"
+ : (apps.find((app) => app.id === value)?.fullName ?? value)
+ }
+ </SelectValue>
+ </SelectTrigger>
+ <SelectPopup>
+ <SelectItem value={FROM_THREAD_PROJECT}>From the thread's project</SelectItem>
+ {draft.appId && !apps.some((app) => app.id === draft.appId) ? (
+ <SelectItem value={draft.appId}>{draft.appId}</SelectItem>
+ ) : null}
+ {apps.map((app) => (
+ <SelectItem key={app.id} value={app.id}>
+ {app.fullName}
+ </SelectItem>
+ ))}
+ </SelectPopup>
+ </Select>
+ <p className="text-xs text-muted-foreground">
+ Sessions bill the project's Expo account. "From the thread's project" reads
+ extra.eas.projectId from the project's app config.
+ </p>
+ </div>
+ <div className="grid grid-cols-3 gap-3 text-sm">
+ {limit("maxConcurrentSessions", "Sessions at once", 20)}
+ {limit("maxSessionMinutes", "Session minutes", 115)}
+ {limit("idleMinutes", "Idle minutes", 60)}
+ </div>
+ <p className="text-xs text-muted-foreground">
+ Expo allows sessions of up to 40 minutes on free accounts and 115 on paid ones, and
+ ends one after the idle minutes without activity, so idle minutes must be smaller than
+ session minutes.
+ {props.isNew ? null : " Saving restarts this host, which stops its running sessions."}
+ </p>
+ {problem === null ? null : (
+ <p className="text-xs text-destructive" role="alert">
+ {problem}
+ </p>
+ )}
+ </DialogPanel>
+ <DialogFooter>
+ <Button type="button" variant="ghost" disabled={props.busy} onClick={props.onClose}>
+ Cancel
+ </Button>
+ <Button type="submit" disabled={props.busy || !valid}>
+ {props.busy ? <Spinner size="xs" /> : null} Save host
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogPopup>
+ </Dialog>
+ );
+}
diff --git a/apps/web/src/components/settings/IntegrationsSettings.tsx b/apps/web/src/components/settings/IntegrationsSettings.tsx
index 02b24e0b97f..388c513c8cf 100644
--- a/apps/web/src/components/settings/IntegrationsSettings.tsx
+++ b/apps/web/src/components/settings/IntegrationsSettings.tsx
@@ -3,6 +3,7 @@ import { DeviceToolVersions } from "../device/DeviceToolVersions";
import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings";
import { ScopedSwitch } from "./ScopedSwitch";
import { DeviceHostsSettings } from "./DeviceHostsSettings";
+import { EasDeviceHostsSettings } from "./EasDeviceHostsSettings";
import {
AuthSettingsWriteScope,
BrowserImportFailureReason,
@@ -1068,6 +1069,7 @@ export function DeviceIntegrationControls({
/>
) : null}
<DeviceHostsSettings environmentId={environmentId} />
+ {state.supportsEasHosts ? <EasDeviceHostsSettings environmentId={environmentId} /> : null}
</>
);
}
diff --git a/apps/web/src/components/settings/easDeviceHostsSettings.logic.test.ts b/apps/web/src/components/settings/easDeviceHostsSettings.logic.test.ts
new file mode 100644
index 00000000000..ed13e95f678
--- /dev/null
+++ b/apps/web/src/components/settings/easDeviceHostsSettings.logic.test.ts
@@ -0,0 +1,42 @@
+import { describe, expect, it } from "vite-plus/test";
+import * as Option from "effect/Option";
+
+import {
+ easSessionLimits,
+ newEasDeviceHost,
+ parseEasDeviceHostDraft,
+ updateEasDeviceHosts,
+} from "./easDeviceHostsSettings.logic";
+
+describe("EAS device host settings", () => {
+ it("adds, edits, and removes one EAS host without touching the others", () => {
+ const other = newEasDeviceHost("eas-0");
+ const eas = newEasDeviceHost("eas-1");
+ const added = updateEasDeviceHosts([other], eas, false);
+ expect(added).toEqual([other, eas]);
+ const edited = { ...eas, label: "Cloud iPhone", maxConcurrentSessions: 1 };
+ expect(updateEasDeviceHosts(added, edited, false)).toEqual([other, edited]);
+ expect(updateEasDeviceHosts(added, eas, true)).toEqual([other]);
+ });
+
+ it("rejects limits EAS does not allow", () => {
+ expect(Option.isSome(parseEasDeviceHostDraft(newEasDeviceHost("eas")))).toBe(true);
+ expect(
+ Option.isNone(parseEasDeviceHostDraft({ ...newEasDeviceHost("eas"), maxSessionMinutes: 10 })),
+ ).toBe(true);
+ expect(
+ Option.isNone(
+ parseEasDeviceHostDraft({ ...newEasDeviceHost("eas"), maxSessionMinutes: 600 }),
+ ),
+ ).toBe(true);
+ expect(Option.isNone(parseEasDeviceHostDraft({ ...newEasDeviceHost("eas"), label: " " }))).toBe(
+ true,
+ );
+ });
+
+ it("describes a host's bounds in one line", () => {
+ expect(easSessionLimits({ ...newEasDeviceHost("eas"), maxConcurrentSessions: 1 })).toBe(
+ "Up to 1 session at once, each stopped after 30 min or 10 idle min",
+ );
+ });
+});
diff --git a/apps/web/src/components/settings/easDeviceHostsSettings.logic.ts b/apps/web/src/components/settings/easDeviceHostsSettings.logic.ts
new file mode 100644
index 00000000000..418a15d0064
--- /dev/null
+++ b/apps/web/src/components/settings/easDeviceHostsSettings.logic.ts
@@ -0,0 +1,35 @@
+import {
+ EasDeviceHostConfig,
+ type EasDeviceHostConfig as EasDeviceHostConfigType,
+} from "@t3tools/contracts";
+import * as Schema from "effect/Schema";
+
+export const parseEasDeviceHostDraft = Schema.decodeUnknownOption(EasDeviceHostConfig);
+
+export const newEasDeviceHost = (id: string): EasDeviceHostConfigType => ({
+ kind: "eas",
+ id,
+ label: "EAS Simulator",
+ accessToken: "",
+ maxSessionMinutes: 30,
+ idleMinutes: 10,
+ maxConcurrentSessions: 2,
+});
+
+/** Adds, replaces, or removes one EAS host. */
+export function updateEasDeviceHosts(
+ hosts: ReadonlyArray<EasDeviceHostConfigType>,
+ host: EasDeviceHostConfigType,
+ remove: boolean,
+): ReadonlyArray<EasDeviceHostConfigType> {
+ if (remove) return hosts.filter((candidate) => candidate.id !== host.id);
+ return hosts.some((candidate) => candidate.id === host.id)
+ ? hosts.map((candidate) => (candidate.id === host.id ? host : candidate))
+ : [...hosts, host];
+}
+
+export function easSessionLimits(host: EasDeviceHostConfigType) {
+ const sessions =
+ host.maxConcurrentSessions === 1 ? "1 session" : `${host.maxConcurrentSessions} sessions`;
+ return `Up to ${sessions} at once, each stopped after ${host.maxSessionMinutes} min or ${host.idleMinutes} idle min`;
+}
diff --git a/packages/client-runtime/src/state/device.ts b/packages/client-runtime/src/state/device.ts
index 7af65307859..2be3d213abc 100644
--- a/packages/client-runtime/src/state/device.ts
+++ b/packages/client-runtime/src/state/device.ts
@@ -50,6 +50,10 @@ export function createDeviceEnvironmentAtoms<R, E>(
label: "environment-data:device:test-host",
tag: WS_METHODS.deviceTestHost,
}),
+ easAccount: createEnvironmentRpcCommand(runtime, {
+ label: "environment-data:device:eas-account",
+ tag: WS_METHODS.deviceEasAccount,
+ }),
list: createEnvironmentRpcCommand(runtime, {
label: "environment-data:device:list",
tag: WS_METHODS.deviceList,
diff --git a/packages/contracts/src/device.ts b/packages/contracts/src/device.ts
index ecc99e46f52..0fdfb304944 100644
--- a/packages/contracts/src/device.ts
+++ b/packages/contracts/src/device.ts
@@ -85,6 +85,31 @@ export const SshDeviceHostConfigs = Schema.Array(SshDeviceHostConfig).check(uniq
*/
export const EasDeviceHostConfigs = Schema.Array(EasDeviceHostConfig).check(uniqueHostIds);
+export const DeviceEasAccountInput = Schema.Struct({
+ /** A saved EAS host whose stored token is checked when no new token is given. */
+ hostId: Schema.optional(DeviceHostId),
+ accessToken: Schema.optional(TrimmedString),
+});
+export type DeviceEasAccountInput = typeof DeviceEasAccountInput.Type;
+
+export const DeviceEasAccount = Schema.Struct({
+ signedInAs: Schema.String,
+ credentialSource: Schema.Literals(["settings", "env", "eas-login"]),
+ apps: Schema.Array(Schema.Struct({ id: Schema.String, fullName: Schema.String })),
+});
+export type DeviceEasAccount = typeof DeviceEasAccount.Type;
+
+/** Checking an Expo credential failed; no device host is involved yet. */
+export class DeviceEasAccountError extends Schema.TaggedError<DeviceEasAccountError>()(
+ "DeviceEasAccountError",
+ // No cause: this error reaches the browser, and the reason already says what Expo answered.
+ { reason: Schema.String },
+) {
+ override get message(): string {
+ return this.reason;
+ }
+}
+
export const DeviceId = TrimmedNonEmptyString.check(Schema.isMaxLength(256));
export type DeviceId = typeof DeviceId.Type;
@@ -171,6 +196,8 @@ const deviceServiceStateFields = {
supportsHostRetry: Schema.optional(Schema.Boolean),
supportsToolUpdate: Schema.optional(Schema.Boolean),
supportsToolInspection: Schema.optional(Schema.Boolean),
+ /** Servers from before EAS hosts ignore `easDeviceHosts`, so clients offer them only when set. */
+ supportsEasHosts: Schema.optional(Schema.Boolean),
hostStatus: DeviceHostStatus,
hostStatusDetail: Schema.optional(Schema.String),
hostStatuses: DeviceHostStatuses,
diff --git a/packages/contracts/src/rpc.ts b/packages/contracts/src/rpc.ts
index 796e7af7164..ea834d15caa 100644
--- a/packages/contracts/src/rpc.ts
+++ b/packages/contracts/src/rpc.ts
@@ -282,6 +282,9 @@ import {
DeviceError,
DeviceListInput,
SshDeviceHostConfig,
+ DeviceEasAccount,
+ DeviceEasAccountError,
+ DeviceEasAccountInput,
DeviceHostSummary,
DeviceOpenInput,
DeviceServiceState,
@@ -459,6 +462,7 @@ export const WS_METHODS = {
deviceConfigure: "device.configure",
deviceList: "device.list",
deviceTestHost: "device.testHost",
+ deviceEasAccount: "device.easAccount",
deviceOpen: "device.open",
deviceClose: "device.close",
deviceShutdown: "device.shutdown",
@@ -1555,6 +1559,12 @@ const WsDeviceTestHostRpc = Rpc.make(WS_METHODS.deviceTestHost, {
error: Schema.Union([DeviceError, EnvironmentAuthorizationError]),
});
+const WsDeviceEasAccountRpc = Rpc.make(WS_METHODS.deviceEasAccount, {
+ payload: DeviceEasAccountInput,
+ success: DeviceEasAccount,
+ error: Schema.Union([DeviceEasAccountError, EnvironmentAuthorizationError]),
+});
+
const WsDeviceListRpc = Rpc.make(WS_METHODS.deviceList, {
payload: DeviceListInput,
success: DeviceServiceState,
@@ -2031,6 +2041,7 @@ export const WsRpcGroup = RpcGroup.make(
WsDeviceConfigureRpc,
WsDeviceListRpc,
WsDeviceTestHostRpc,
+ WsDeviceEasAccountRpc,
WsDeviceOpenRpc,
WsDeviceCloseRpc,
WsDeviceShutdownRpc,