Add Expo mobile client and wire up `dev:mobile` workflow #123
- @@ -0,0 +109,21 @@109+export function createBackendProfileId(): string {110+ return `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;111+}112+113+export function normalizeBackendInput(urlInput: string, authTokenInput: string): NormalizedBackendInput {114+ const parsed = toWsUrl(urlInput);115+ const tokenFromUrl = parsed.searchParams.get("token")?.trim() || "";116+ parsed.searchParams.delete("token");117+118+ const inputToken = authTokenInput.trim();119+ const authToken = inputToken.length > 0 ? inputToken : tokenFromUrl.length > 0 ? tokenFromUrl : null;120+121+ return {122+ name: buildBackendName(parsed),123+ url: parsed.toString(),124+ authToken,125+ };126+}127+128+export function buildSocketUrl(profile: Pick<BackendProfile, "url" | "authToken">): string {129+ const parsed = new URL(profile.url);@@ -0,0 +80,21 @@80+ if (status.state === "connected") return "bg-emerald-100 text-emerald-700";81+ if (status.state === "connecting") return "bg-amber-100 text-amber-700";82+ if (status.state === "error") return "bg-red-100 text-red-700";83+ return "bg-slate-200 text-slate-700";84+}85+86+function formatDate(iso: string | null | undefined): string {87+ if (!iso) return "-";88+89+ const value = new Date(iso);90+ if (Number.isNaN(value.getTime())) return "-";91+ return value.toLocaleString();92+}93+94+function formatEventType(event: OrchestrationEvent): string {95+ const eventRecord = event as Record<string, unknown>;96+ if (typeof eventRecord.type === "string") return eventRecord.type;97+ return "event";98+}99+100+function formatEventTimestamp(event: OrchestrationEvent): string {@@ -0,0 +84,21 @@84+ });85+86+ this.send(message);87+ });88+ }89+90+ subscribe(channel: string, listener: PushListener): () => void {91+ let channelListeners = this.listeners.get(channel);92+ if (!channelListeners) {93+ channelListeners = new Set();94+ this.listeners.set(channel, channelListeners);95+ }96+97+ channelListeners.add(listener);98+99+ return () => {100+ channelListeners?.delete(listener);101+ if (channelListeners && channelListeners.size === 0) {102+ this.listeners.delete(channel);103+ }104+ };@@ -0,0 +129,21 @@129+ const parsed = new URL(profile.url);130+ const token = profile.authToken?.trim();131+ if (token) {132+ parsed.searchParams.set("token", token);133+ } else {134+ parsed.searchParams.delete("token");135+ }136+ return parsed.toString();137+}138+139+export async function loadBackendState(): Promise<StoredBackendState> {140+ const [rawProfiles, rawActiveProfileId] = await Promise.all([141+ AsyncStorage.getItem(BACKEND_PROFILES_KEY),142+ AsyncStorage.getItem(ACTIVE_BACKEND_ID_KEY),143+ ]);144+145+ return {146+ profiles: parseStoredProfiles(rawProfiles),147+ activeProfileId: rawActiveProfileId && rawActiveProfileId.length > 0 ? rawActiveProfileId : null,148+ };149+}@@ -0,0 +207,21 @@207+ return;208+ }209+210+ pending.resolve(message.result);211+ }212+213+ private send(message: WsRequestEnvelope): void {214+ if (this.ws?.readyState === WebSocket.OPEN) {215+ this.ws.send(JSON.stringify(message));216+ return;217+ }218+219+ const check = setInterval(() => {220+ if (this.disposed) {221+ clearInterval(check);222+ return;223+ }224+225+ if (this.ws?.readyState === WebSocket.OPEN) {226+ clearInterval(check);227+ this.ws.send(JSON.stringify(message));
- @@ -0,0 +187,21 @@187+ void queryClient.invalidateQueries({ queryKey: ["orchestration.snapshot", profile.id] });188+ });189+190+ cleanupRef.current = () => {191+ unsubscribeWelcome();192+ unsubscribeDomainEvents();193+ nextClient.dispose();194+ };195+196+ setClient(nextClient);197+ setActiveProfileId(profile.id);198+ await setActiveBackendProfileId(profile.id);199+200+ const now = new Date().toISOString();201+ setProfiles((current) => {202+ const nextProfiles = current.map((candidate) =>203+ candidate.id === profile.id ? { ...candidate, lastConnectedAt: now } : candidate,204+ );205+ void saveBackendProfiles(nextProfiles);206+ return nextProfiles;207+ });@@ -0,0 +237,21 @@237+238+ const nextProfiles = existing239+ ? profiles.map((candidate) => (candidate.id === existing.id ? profile : candidate))240+ : [profile, ...profiles];241+242+ setProfiles(nextProfiles);243+ await saveBackendProfiles(nextProfiles);244+ await connectToProfile(profile);245+246+ setWsUrlInput("");247+ setAuthTokenInput("");248+ } catch (error) {249+ setUiError(error instanceof Error ? error.message : "Unable to save backend profile.");250+ }251+ }, [authTokenInput, connectToProfile, profiles, wsUrlInput]);252+253+ const removeProfile = useCallback(254+ async (profileId: string) => {255+ const nextProfiles = profiles.filter((profile) => profile.id !== profileId);256+ setProfiles(nextProfiles);257+ await saveBackendProfiles(nextProfiles);
- @@ -0,0 +25,21 @@25+26+const REQUEST_TIMEOUT_MS = 20_000;27+const RECONNECT_DELAYS_MS = [500, 1_000, 2_000, 4_000, 8_000];28+const decodeWsResponseFromJson = Schema.decodeUnknownExit(Schema.fromJsonString(WsResponse));29+const isWsPushEnvelope = Schema.is(WsPush);30+const isWebSocketResponseEnvelope = Schema.is(WebSocketResponse);31+32+function websocketRawToString(raw: unknown): string | null {33+ if (typeof raw === "string") {34+ return raw;35+ }36+37+ if (raw instanceof ArrayBuffer) {38+ return new TextDecoder().decode(raw);39+ }40+41+ if (ArrayBuffer.isView(raw)) {42+ return new TextDecoder().decode(raw);43+ }44+45+ return null;
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.