The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | EasDeviceHostConfig, |
| 3 | type EasDeviceHostConfig as EasDeviceHostConfigType, |
| 4 | } from "@t3tools/contracts"; |
| 5 | import * as Schema from "effect/Schema"; |
| 6 | import { msg } from "gt-react"; |
| 7 | |
| 8 | import { m, type MessageResolver } from "../../i18n/messages"; |
| 9 | |
| 10 | export const parseEasDeviceHostDraft = Schema.decodeUnknownOption(EasDeviceHostConfig); |
| 11 | |
| 12 | export const newEasDeviceHost = ( |
| 13 | id: string, |
| 14 | resolve: MessageResolver = m, |
| 15 | ): EasDeviceHostConfigType => ({ |
| 16 | kind: "eas", |
| 17 | id, |
| 18 | label: resolve(msg("Expo Simulators")), |
| 19 | accessToken: "", |
| 20 | maxSessionMinutes: 30, |
| 21 | idleMinutes: 10, |
| 22 | maxConcurrentSessions: 2, |
| 23 | }); |
| 24 | |
| 25 | /** Adds, replaces, or removes one Expo host. */ |
| 26 | /** |
| 27 | * With `keepToken`, the environment keeps the token it holds: a saved token arrives redacted, and |
| 28 | * one environment's token says nothing about another's. One new to the host uses its own Expo login. |
| 29 | */ |
| 30 | export function updateEasDeviceHosts( |
| 31 | hosts: ReadonlyArray<EasDeviceHostConfigType>, |
| 32 | host: EasDeviceHostConfigType, |
| 33 | remove: boolean, |
| 34 | keepToken = false, |
| 35 | ): ReadonlyArray<EasDeviceHostConfigType> { |
| 36 | if (remove) return hosts.filter((candidate) => candidate.id !== host.id); |
| 37 | const existing = hosts.find((candidate) => candidate.id === host.id); |
| 38 | const next = keepToken ? { ...host, accessToken: existing?.accessToken ?? "" } : host; |
| 39 | return existing |
| 40 | ? hosts.map((candidate) => (candidate.id === host.id ? next : candidate)) |
| 41 | : [...hosts, next]; |
| 42 | } |
| 43 | |
| 44 | export function easSessionLimits(host: EasDeviceHostConfigType, resolve: MessageResolver = m) { |
| 45 | return resolve( |
| 46 | msg( |
| 47 | "Up to {sessions, plural, one {{sessions} session} other {{sessions} sessions}} at once, each stopped after {maxMinutes} min or {idleMinutes} idle min", |
| 48 | { |
| 49 | sessions: host.maxConcurrentSessions, |
| 50 | maxMinutes: host.maxSessionMinutes, |
| 51 | idleMinutes: host.idleMinutes, |
| 52 | }, |
| 53 | ), |
| 54 | ); |
| 55 | } |