@agimon-ai/po-native 0.0.1-alpha.57 → 0.0.1-alpha.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/po-native",
3
- "version": "0.0.1-alpha.57",
3
+ "version": "0.0.1-alpha.59",
4
4
  "description": "Po for iOS and Android",
5
5
  "homepage": "https://agimon.ai",
6
6
  "bugs": {
@@ -29,17 +29,17 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@agimon-ai/po-core": "0.0.0-alpha.177",
33
- "@agimon-ai/po-expo-signing": "0.0.1-alpha.57",
34
- "@agimon-ai/po-identity": "0.0.2-alpha.124",
35
- "@agimon-ai/po-native-components": "0.0.0-alpha.177",
36
- "@agimon-ai/po-native-dashboard": "0.0.0-alpha.49",
37
- "@agimon-ai/po-template-advanced": "0.0.0-alpha.177",
38
- "@agimon-ai/po-template-elegant": "0.0.0-alpha.177",
39
- "@agimon-ai/po-voice": "0.0.0-alpha.177",
40
- "@agimon-ai/po-web-components": "0.0.0-alpha.177",
41
- "@agimon-ai/po-web-dashboard": "0.0.0-alpha.177",
42
- "@agimon-ai/po-web-security": "0.0.0-alpha.177",
32
+ "@agimon-ai/po-core": "0.0.0-alpha.179",
33
+ "@agimon-ai/po-expo-signing": "0.0.1-alpha.59",
34
+ "@agimon-ai/po-identity": "0.0.2-alpha.126",
35
+ "@agimon-ai/po-native-components": "0.0.0-alpha.179",
36
+ "@agimon-ai/po-native-dashboard": "0.0.0-alpha.51",
37
+ "@agimon-ai/po-template-advanced": "0.0.0-alpha.179",
38
+ "@agimon-ai/po-template-elegant": "0.0.0-alpha.179",
39
+ "@agimon-ai/po-voice": "0.0.0-alpha.179",
40
+ "@agimon-ai/po-web-components": "0.0.0-alpha.179",
41
+ "@agimon-ai/po-web-dashboard": "0.0.0-alpha.179",
42
+ "@agimon-ai/po-web-security": "0.0.0-alpha.179",
43
43
  "@better-auth/expo": "1.7.12",
44
44
  "@config-plugins/react-native-webrtc": "15.0.2",
45
45
  "@earendil-works/chord": "1.5.2",
package/src/app/App.tsx CHANGED
@@ -552,7 +552,7 @@ function useSessionList(hosts: readonly HostRuntimeState[]): SessionSummary[] {
552
552
  workspaces.find((workspace) => workspace.id === summary.workspaceId)?.kind === 'session'
553
553
  ? undefined
554
554
  : summary.cwd,
555
- hostLabel: host ? (host.host.displayName ?? new URL(host.host.origin).hostname) : undefined,
555
+ hostLabel: host ? hostDisplayName(host.host) : undefined,
556
556
  status: card?.status,
557
557
  ...(card?.clock ? { clock: card.clock } : {}),
558
558
  stale: host !== undefined && host.status !== 'connected',
@@ -1964,7 +1964,7 @@ function SessionsRoute({
1964
1964
  ),
1965
1965
  hosts: hostStates.map(({ host, status }) => ({
1966
1966
  id: host.id,
1967
- label: host.displayName ?? new URL(host.origin).hostname,
1967
+ label: hostDisplayName(host),
1968
1968
  status,
1969
1969
  onRetry: connections?.find(({ id }) => id === host.id)?.onRetry ?? (() => undefined),
1970
1970
  createGeneralSession: () => {
@@ -2351,7 +2351,7 @@ function SessionsRoute({
2351
2351
  {hostStates.map(({ host, status }) => (
2352
2352
  <ComputerRow
2353
2353
  key={host.id}
2354
- name={host.displayName ?? new URL(host.origin).hostname}
2354
+ name={hostDisplayName(host)}
2355
2355
  status={status}
2356
2356
  onPress={() => {
2357
2357
  setChoosingGeneralHost(false);
@@ -27,6 +27,7 @@ import {
27
27
  type HostViewRecord,
28
28
  } from '../screens/HostsView';
29
29
  import { createAccountClient, loadLocalAccount, selectedIdentityIssuer } from '../services/accountClient';
30
+ import { hostDisplayName } from '../services/deviceTrust';
30
31
  import { createHostLinkBroker, HostLinkConfirmationNeeded, type HostLinks } from '../services/hostLinkBroker';
31
32
  import { hostSnapshots } from '../services/hostSnapshots';
32
33
  import type { HostRuntimes, HostRuntimeState } from './hostRuntimes';
@@ -37,7 +38,7 @@ const message = (error: unknown) => (error instanceof Error ? error.message : 'T
37
38
  export const hostViewRecords = (states: readonly HostRuntimeState[]): HostViewRecord[] =>
38
39
  states.map(({ host, status }) => ({
39
40
  id: host.id,
40
- label: host.displayName ?? new URL(host.origin).host,
41
+ label: hostDisplayName(host),
41
42
  origin: new URL(host.origin).host,
42
43
  status: status === 'connected' ? 'Connected' : status === 'connecting' ? 'Connecting' : 'Disconnected',
43
44
  }));
@@ -89,7 +89,7 @@ export function cloudFetch(host: CloudHostRecord, options: Pick<CloudRuntimeOpti
89
89
  const fetcher = options.fetch ?? nativeFetch;
90
90
  return async (
91
91
  url: string,
92
- init: { method?: string; headers?: Record<string, string>; body?: string; signal?: AbortSignal } = {},
92
+ init: { method?: string; headers?: Record<string, string>; body?: string | Uint8Array; signal?: AbortSignal } = {},
93
93
  ): Promise<Response> => {
94
94
  const target = new URL(url);
95
95
  // Cloud API calls, plus hosted Po Cloud's own `/api/owner` routes such as push enrollment.
@@ -105,8 +105,11 @@ export function cloudFetch(host: CloudHostRecord, options: Pick<CloudRuntimeOpti
105
105
  if (!cookie) throw new Error(SIGNED_OUT);
106
106
  // Hosted Po Cloud admits a cookie write only from the app scheme with its CSRF header.
107
107
  const write = host.hosted !== undefined && init.method !== undefined && !['GET', 'HEAD'].includes(init.method);
108
+ const { body, ...rest } = init;
108
109
  return fetcher(url, {
109
- ...init,
110
+ ...rest,
111
+ // Bytes, such as an attachment upload, go as their own copy of the buffer.
112
+ ...(body === undefined ? {} : { body: typeof body === 'string' ? body : body.slice().buffer }),
110
113
  headers: {
111
114
  ...(write ? HOSTED_WRITE_HEADERS : {}),
112
115
  ...init.headers,
@@ -148,18 +151,62 @@ export function cloudApiSend(host: CloudHostRecord, options: Pick<CloudRuntimeOp
148
151
  target: string;
149
152
  headers?: readonly (readonly [string, string])[];
150
153
  body?: string | Uint8Array;
154
+ signal?: AbortSignal;
151
155
  },
152
- signal?: AbortSignal,
153
- ): Promise<Response> => {
154
- // ponytail: text bodies only. A route that uploads bytes to Po Cloud needs a byte path here.
155
- if (request.body !== undefined && typeof request.body !== 'string')
156
- throw new Error('Po Cloud takes text requests only.');
157
- return send(`${cloudBase(host)}${request.target}`, {
156
+ signal = request.signal,
157
+ ): Promise<Response> =>
158
+ send(`${cloudBase(host)}${request.target}`, {
158
159
  method: request.method,
159
160
  headers: Object.fromEntries(request.headers ?? []),
160
161
  ...(request.body === undefined ? {} : { body: request.body }),
161
162
  ...(signal === undefined ? {} : { signal }),
162
163
  });
164
+ }
165
+
166
+ /** Opens one cookie-admitted socket at `path` under this host's API and resolves once it is open. */
167
+ async function openCloudSocket(
168
+ host: CloudHostRecord,
169
+ path: string,
170
+ cookie: string,
171
+ Socket: CloudSocketConstructor,
172
+ ): Promise<CloudSocket> {
173
+ const url = new URL(`${cloudBase(host).replace(/^https:/u, 'wss:')}${path}`);
174
+ url.searchParams.set('poClient', encodePoClientMetadata(currentClientMetadata()));
175
+ const socket = new Socket(url.toString(), null, {
176
+ headers: { ...cloudHeaders(host, cookie), ...(host.computer ? { origin: HOSTED_WRITE_HEADERS.origin } : {}) },
177
+ });
178
+ socket.binaryType = 'arraybuffer';
179
+ // Chord's link must start on an open socket; anything before that is a failed attempt.
180
+ await new Promise<void>((resolve, reject) => {
181
+ let settled = false;
182
+ const settle = (error?: Error) => {
183
+ if (settled) return;
184
+ settled = true;
185
+ clearTimeout(timer);
186
+ if (error) {
187
+ socket.close();
188
+ reject(error);
189
+ } else resolve();
190
+ };
191
+ const timer = setTimeout(() => settle(new Error('Po Cloud did not answer in time.')), SOCKET_OPEN_TIMEOUT_MS);
192
+ socket.addEventListener('open', () => settle());
193
+ socket.addEventListener('error', (event) => settle(new Error(event?.message ?? 'Po Cloud socket failed.')));
194
+ socket.addEventListener('close', () => settle(new Error('Po Cloud closed the socket before it opened.')));
195
+ });
196
+ return socket;
197
+ }
198
+
199
+ /** A linked computer's host protocol through Po Cloud: the socket a paired device opens, with the person's sign-in. */
200
+ export function cloudComputerLink(
201
+ host: CloudHostRecord,
202
+ options: Pick<CloudRuntimeOptions, 'cookie' | 'Socket'> = {},
203
+ ): () => Promise<Link> {
204
+ const readCookie = options.cookie ?? (() => cloudCookie(host));
205
+ const Socket = options.Socket ?? (WebSocket as unknown as CloudSocketConstructor);
206
+ return async () => {
207
+ const cookie = await readCookie();
208
+ if (!cookie) throw new Error(SIGNED_OUT);
209
+ return webSocketLink((await openCloudSocket(host, '/api/ws', cookie, Socket)) as unknown as WebSocketLike);
163
210
  };
164
211
  }
165
212
 
@@ -354,31 +401,12 @@ export function startCloudRuntime(host: CloudHostRecord, options: CloudRuntimeOp
354
401
  if (closed || !online || binding?.sockets !== sockets) throw new Error('The session connection was replaced.');
355
402
  if (!cookie) throw new Error(SIGNED_OUT);
356
403
  const path = `/api/workspaces/${encodeURIComponent(localHostId(host.id, workspaceId))}/sessions/${encodeURIComponent(localHostId(host.id, sessionId))}/ws`;
357
- const url = new URL(`${cloudBase(host).replace(/^https:/u, 'wss:')}${path}`);
358
- url.searchParams.set('poClient', encodePoClientMetadata(currentClientMetadata()));
359
- const socket = new Socket(url.toString(), null, {
360
- headers: { ...cloudHeaders(host, cookie), ...(host.computer ? { origin: HOSTED_WRITE_HEADERS.origin } : {}) },
361
- });
362
- socket.binaryType = 'arraybuffer';
404
+ const socket = await openCloudSocket(host, path, cookie, Socket);
405
+ if (closed || binding?.sockets !== sockets) {
406
+ socket.close();
407
+ throw new Error('The session connection was replaced.');
408
+ }
363
409
  sockets.add(socket);
364
- // Chord's link must start on an open socket; anything before that is a failed attempt.
365
- await new Promise<void>((resolve, reject) => {
366
- let settled = false;
367
- const settle = (error?: Error) => {
368
- if (settled) return;
369
- settled = true;
370
- clearTimeout(timer);
371
- if (error) {
372
- sockets.delete(socket);
373
- socket.close();
374
- reject(error);
375
- } else resolve();
376
- };
377
- const timer = setTimeout(() => settle(new Error('Po Cloud did not answer in time.')), SOCKET_OPEN_TIMEOUT_MS);
378
- socket.addEventListener('open', () => settle());
379
- socket.addEventListener('error', (event) => settle(new Error(event?.message ?? 'Po Cloud socket failed.')));
380
- socket.addEventListener('close', () => settle(new Error('Po Cloud closed the socket before it opened.')));
381
- });
382
410
  socket.addEventListener('close', (event) => {
383
411
  sockets.delete(socket);
384
412
  if (event?.code === CLOUD_REAUTHENTICATE_CLOSE) reauthenticate();
@@ -33,12 +33,22 @@ import { startNativePush, startPushEnrollment, unregisterNativePush } from '../s
33
33
  import { parsePairingUrl } from '../services/pairing';
34
34
  import type { PluginCompatibility } from '../services/pluginRuntime';
35
35
  import { createRelayTransport } from '../services/relayTransport';
36
- import { cloudApiSend, cloudPushEnrollment, refreshCloudComputers, startCloudRuntime } from './cloudRuntime';
36
+ import {
37
+ cloudApiSend,
38
+ cloudComputerLink,
39
+ cloudPushEnrollment,
40
+ refreshCloudComputers,
41
+ startCloudRuntime,
42
+ } from './cloudRuntime';
37
43
  import { type ActivityLoadState, type LiveRuntime, startLiveRuntime } from './liveRuntime';
38
44
  import { activateNativeTemplateHost, resetNativeTemplateChoice } from './nativeTemplate';
39
45
 
40
46
  /** Forget tells a reachable computer or Po Cloud to stop pushing to this phone, but never waits on an offline one. */
41
47
  const PUSH_DEREGISTER_DEADLINE_MS = 2_000;
48
+ /** A Cloud-linked computer's protocol socket dropped: try again after this, so an offline computer is not hammered. */
49
+ const CLOUD_COMPUTER_RECONNECT_MS = 3_000;
50
+ /** A paired computer running through Po Cloud tries its own connection again this often. */
51
+ const PAIRED_RETRY_MS = 30_000;
42
52
 
43
53
  async function withinDeadline(operation: Promise<unknown>, deferred: string): Promise<void> {
44
54
  let timer: ReturnType<typeof setTimeout> | undefined;
@@ -63,12 +73,16 @@ export interface HostRuntimeState {
63
73
  linkError?: string;
64
74
  /** Incompatible plugins do not change this host's connection status. */
65
75
  pluginCompatibility?: readonly PluginCompatibility[];
76
+ /** A paired computer its own connection cannot reach, running through Po Cloud for now. */
77
+ via?: 'cloud';
66
78
  }
67
79
 
68
80
  interface HostRuntimeEntry extends HostRuntimeState {
69
81
  controller: AbortController;
70
82
  push?: ReturnType<typeof startNativePush>;
71
83
  lanTransport?: TrustedSession['lanTransport'];
84
+ /** A Cloud computer that is also paired here: hidden, with no connection of its own. */
85
+ standby?: true;
72
86
  }
73
87
 
74
88
  function sameHostState(left: HostRuntimeState, right: HostRuntimeState): boolean {
@@ -78,7 +92,8 @@ function sameHostState(left: HostRuntimeState, right: HostRuntimeState): boolean
78
92
  left.runtime === right.runtime &&
79
93
  left.error === right.error &&
80
94
  left.linkError === right.linkError &&
81
- left.pluginCompatibility === right.pluginCompatibility
95
+ left.pluginCompatibility === right.pluginCompatibility &&
96
+ left.via === right.via
82
97
  );
83
98
  }
84
99
 
@@ -96,7 +111,9 @@ export function createHostRuntimes(
96
111
  const repairs = new Map<string, { left: HostRuntimeEntry; right: HostRuntimeEntry; controller: AbortController }>();
97
112
  const repairLinks = () => {
98
113
  // Host links join paired computers; a cloud host has no pairing keys to offer hints with.
99
- const connected = [...entries.values()].filter((entry) => entry.status === 'connected' && !isCloudHost(entry.host));
114
+ const connected = [...entries.values()].filter(
115
+ (entry) => entry.status === 'connected' && !isCloudHost(entry.host) && entry.via === undefined,
116
+ );
100
117
  for (let i = 0; i < connected.length; i++)
101
118
  for (const right of connected.slice(i + 1)) {
102
119
  const left = connected[i]!;
@@ -127,11 +144,13 @@ export function createHostRuntimes(
127
144
  // or a repeated status would otherwise re-render every screen of the app.
128
145
  let reported: readonly HostRuntimeState[] = [];
129
146
  const snapshot = (): readonly HostRuntimeState[] => {
130
- const next = [...entries.values()].map(({ host, status, runtime, error, linkError, pluginCompatibility }) => {
131
- const state = { host, status, runtime, error, linkError, pluginCompatibility };
132
- const previous = reported.find((candidate) => candidate.host.id === host.id);
133
- return previous && sameHostState(previous, state) ? previous : state;
134
- });
147
+ const next = [...entries.values()]
148
+ .filter((entry) => !entry.standby)
149
+ .map(({ host, status, runtime, error, linkError, pluginCompatibility, via }) => {
150
+ const state = { host, status, runtime, error, linkError, pluginCompatibility, ...(via ? { via } : {}) };
151
+ const previous = reported.find((candidate) => candidate.host.id === host.id);
152
+ return previous && sameHostState(previous, state) ? previous : state;
153
+ });
135
154
  return next.length === reported.length && next.every((state, index) => state === reported[index]) ? reported : next;
136
155
  };
137
156
  const changed = () => {
@@ -156,6 +175,29 @@ export function createHostRuntimes(
156
175
  entry.lanTransport = undefined;
157
176
  };
158
177
 
178
+ // One computer, two entries: a Cloud listing and a pairing that carry the same bundle signer.
179
+ const pairedTwin = (publicKey: string | undefined) =>
180
+ publicKey === undefined
181
+ ? undefined
182
+ : [...entries.values()].find(
183
+ (entry): entry is HostRuntimeEntry & { host: HostRecord } =>
184
+ !isCloudHost(entry.host) && entry.host.signer.publicKey === publicKey && !forgetting.has(entry.host.id),
185
+ );
186
+ const cloudTwin = (publicKey: string) =>
187
+ [...entries.values()].find(
188
+ (entry): entry is HostRuntimeEntry & { host: CloudHostRecord } =>
189
+ isCloudHost(entry.host) && entry.host.computer?.publicKey === publicKey,
190
+ );
191
+ /** The paired entry shows the computer; its Cloud listing keeps only the record for a fallback. */
192
+ const standDown = (entry: HostRuntimeEntry) => {
193
+ stopEntry(entry);
194
+ entry.runtime = undefined;
195
+ entry.push = undefined;
196
+ entry.standby = true;
197
+ applySessionsSnapshot({ sessions: [] }, entry.host.id);
198
+ applyWorkspacesSnapshot({ workspaces: [] }, entry.host.id);
199
+ };
200
+
159
201
  const dropCloudEntry = (entry: HostRuntimeEntry) => {
160
202
  const { id } = entry.host;
161
203
  stopEntry(entry);
@@ -163,15 +205,110 @@ export function createHostRuntimes(
163
205
  applySessionsSnapshot({ sessions: [] }, id);
164
206
  applyWorkspacesSnapshot({ workspaces: [] }, id);
165
207
  if (focused !== null && splitHostId(focused)?.hostId === id) focused = null;
208
+ // A paired computer running through this listing goes back to its own connection.
209
+ const key = isCloudHost(entry.host) ? entry.host.computer?.publicKey : undefined;
210
+ const twin = pairedTwin(key);
211
+ if (twin?.via === 'cloud') void connect(twin.host).catch(() => undefined);
166
212
  changed();
167
213
  };
168
214
 
215
+ /** How a paired computer is reached: its relay route, its pinned private network, or plain HTTPS. */
216
+ const pairedTransport = async (host: HostRecord) =>
217
+ !host.tlsCertificateSha256 && !host.relayRoute
218
+ ? undefined
219
+ : host.relayRoute
220
+ ? createRelayTransport({
221
+ origin: host.origin,
222
+ route: host.relayRoute,
223
+ capability: await loadRelayCapability(host.id),
224
+ signer: host.signer.publicKey,
225
+ })
226
+ : createPinnedLanTransport(host.origin, host.tlsCertificateSha256!);
227
+
228
+ /**
229
+ * Runs a paired computer through its Cloud listing, under the paired id so its sessions keep their ids, and
230
+ * keeps trying its own connection, which takes over once it answers.
231
+ */
232
+ const fallBackToCloud = (host: HostRecord, cloud: CloudHostRecord): LiveRuntime => {
233
+ const previous = entries.get(host.id);
234
+ if (previous) stopEntry(previous, true);
235
+ const entry: HostRuntimeEntry = { host, status: 'connecting', controller: new AbortController(), via: 'cloud' };
236
+ entries.set(host.id, entry);
237
+ const active = () =>
238
+ !closed && entries.get(host.id) === entry && !entry.controller.signal.aborted && !forgetting.has(host.id);
239
+ const send = cloudApiSend(cloud);
240
+ const runtime = startLiveRuntime(
241
+ { hostId: host.id, origin: cloud.origin, sealed: send, openLink: cloudComputerLink(cloud) },
242
+ host,
243
+ () => {
244
+ if (active())
245
+ setTimeout(() => {
246
+ if (active()) fallBackToCloud(host, cloud);
247
+ }, CLOUD_COMPUTER_RECONNECT_MS);
248
+ },
249
+ (owner, state) => {
250
+ if (active()) options.activity?.(host.id, owner, state);
251
+ },
252
+ {
253
+ onSummariesLoaded() {
254
+ if (!active() || entry.status === 'connected') return;
255
+ entry.status = 'connected';
256
+ changed();
257
+ },
258
+ onPluginCompatibility(issues) {
259
+ if (!active()) return;
260
+ entry.pluginCompatibility = issues;
261
+ changed();
262
+ },
263
+ onUpdateRequired() {
264
+ if (!active()) return;
265
+ entry.status = 'update_required';
266
+ changed();
267
+ },
268
+ },
269
+ );
270
+ entry.runtime = runtime;
271
+ // Plugin and Settings calls for this computer go through Cloud too, until its own connection returns.
272
+ entry.controller.signal.addEventListener('abort', bindCloudApi(host.id, send), { once: true });
273
+ const retry = setInterval(() => {
274
+ if (!active()) return clearInterval(retry);
275
+ void (async () => {
276
+ const transport = await pairedTransport(host);
277
+ try {
278
+ const trusted = await reconnect(host.origin, transport?.fetch ?? nativeFetch, {
279
+ hostId: host.id,
280
+ signal: entry.controller.signal,
281
+ });
282
+ if (!active()) throw new Error('The host connection was replaced.');
283
+ if (transport) trusted.lanTransport = transport;
284
+ clearInterval(retry);
285
+ await connect(host, trusted);
286
+ } catch {
287
+ // Still unreachable on its own; Cloud keeps carrying it until the next try.
288
+ transport?.close();
289
+ }
290
+ })();
291
+ }, PAIRED_RETRY_MS);
292
+ entry.controller.signal.addEventListener('abort', () => clearInterval(retry), { once: true });
293
+ runtime.open(focused !== null && splitHostId(focused)?.hostId === host.id ? focused : null);
294
+ changed();
295
+ return runtime;
296
+ };
297
+
169
298
  /** Cloud hosts poll and focus over cookie admission. Only the Cloud service enrolls push. */
170
- const connectCloud = (host: CloudHostRecord, requestPermission: boolean): LiveRuntime => {
299
+ const connectCloud = (host: CloudHostRecord, requestPermission: boolean): LiveRuntime | undefined => {
171
300
  const previous = entries.get(host.id);
172
301
  if (previous) stopEntry(previous);
173
302
  const entry: HostRuntimeEntry = { host, status: 'connecting', controller: new AbortController() };
174
303
  entries.set(host.id, entry);
304
+ // Paired here too: the paired entry shows it, and runs through this listing only while it cannot connect.
305
+ const twin = pairedTwin(host.computer?.publicKey);
306
+ if (twin) {
307
+ standDown(entry);
308
+ const runtime = twin.status === 'disconnected' ? fallBackToCloud(twin.host, host) : twin.runtime;
309
+ changed();
310
+ return runtime;
311
+ }
175
312
  const active = () => !closed && entries.get(host.id) === entry && !forgetting.has(host.id);
176
313
  let discovering = false;
177
314
  const discoverComputers = async () => {
@@ -191,9 +328,13 @@ export function createHostRuntimes(
191
328
  continue;
192
329
  const latest = computers.find(({ id }) => id === existing.id);
193
330
  if (!latest || latest.computer?.generation !== existing.computer.generation) dropCloudEntry(candidate);
194
- else if (latest.label !== existing.label) {
195
- candidate.host = latest;
196
- changed();
331
+ else if (latest.label !== existing.label || latest.computer?.publicKey !== existing.computer.publicKey) {
332
+ // A newly listed bundle signer moves the computer onto the full runtime.
333
+ if (latest.computer?.publicKey !== existing.computer.publicKey) connectCloud(latest, false);
334
+ else {
335
+ candidate.host = latest;
336
+ changed();
337
+ }
197
338
  }
198
339
  }
199
340
  for (const computer of computers) {
@@ -206,22 +347,64 @@ export function createHostRuntimes(
206
347
  discovering = false;
207
348
  }
208
349
  };
209
- const runtime = startCloudRuntime(host, {
210
- onSummariesLoaded() {
211
- if (!active()) return;
212
- if (entry.status !== 'connected') {
213
- entry.status = 'connected';
214
- changed();
215
- }
216
- if (!host.computer && host.hosted && !discovering) void discoverComputers();
217
- },
218
- onError(message) {
219
- if (!active() || entry.error === message) return;
220
- entry.error = message;
221
- if (message !== undefined && (entry.status === 'connecting' || host.computer)) entry.status = 'disconnected';
222
- changed();
223
- },
224
- });
350
+ const publicKey = host.computer?.publicKey;
351
+ // A computer whose bundle signer Cloud lists runs as a paired computer does: activity, plugins and its own UI.
352
+ const runtime = publicKey
353
+ ? startLiveRuntime(
354
+ { hostId: host.id, origin: host.origin, sealed: cloudApiSend(host), openLink: cloudComputerLink(host) },
355
+ {
356
+ id: host.id,
357
+ origin: host.origin,
358
+ trustedDeviceId: `cloud:${host.person.subject}`,
359
+ signer: { publicKey, revision: 0 },
360
+ label: host.label,
361
+ ...(host.displayName === undefined ? {} : { displayName: host.displayName }),
362
+ },
363
+ () => {
364
+ if (active())
365
+ setTimeout(() => {
366
+ if (active()) connectCloud(host, false);
367
+ }, CLOUD_COMPUTER_RECONNECT_MS);
368
+ },
369
+ (owner, state) => {
370
+ if (active()) options.activity?.(host.id, owner, state);
371
+ },
372
+ {
373
+ onSummariesLoaded() {
374
+ if (!active() || entry.status === 'connected') return;
375
+ entry.status = 'connected';
376
+ entry.error = undefined;
377
+ changed();
378
+ },
379
+ onPluginCompatibility(issues) {
380
+ if (!active()) return;
381
+ entry.pluginCompatibility = issues;
382
+ changed();
383
+ },
384
+ onUpdateRequired() {
385
+ if (!active()) return;
386
+ entry.status = 'update_required';
387
+ changed();
388
+ },
389
+ },
390
+ )
391
+ : startCloudRuntime(host, {
392
+ onSummariesLoaded() {
393
+ if (!active()) return;
394
+ if (entry.status !== 'connected') {
395
+ entry.status = 'connected';
396
+ changed();
397
+ }
398
+ if (!host.computer && host.hosted && !discovering) void discoverComputers();
399
+ },
400
+ onError(message) {
401
+ if (!active() || entry.error === message) return;
402
+ entry.error = message;
403
+ if (message !== undefined && (entry.status === 'connecting' || host.computer))
404
+ entry.status = 'disconnected';
405
+ changed();
406
+ },
407
+ });
225
408
  entry.runtime = runtime;
226
409
  // Settings and other host calls reach this Po Cloud host with the person's sign-in until it stops.
227
410
  entry.controller.signal.addEventListener('abort', bindCloudApi(host.id, cloudApiSend(host)), { once: true });
@@ -231,11 +414,18 @@ export function createHostRuntimes(
231
414
  return runtime;
232
415
  };
233
416
 
234
- const connect = async (
417
+ // A paired computer always gets a runtime; a Cloud listing hidden behind its pairing has none of its own.
418
+ async function connect(host: HostRecord, session?: TrustedSession, requestPermission?: boolean): Promise<LiveRuntime>;
419
+ async function connect(
420
+ host: HostRecord | CloudHostRecord,
421
+ session?: TrustedSession,
422
+ requestPermission?: boolean,
423
+ ): Promise<LiveRuntime | undefined>;
424
+ async function connect(
235
425
  host: HostRecord | CloudHostRecord,
236
426
  session?: TrustedSession,
237
427
  requestPermission = false,
238
- ): Promise<LiveRuntime> => {
428
+ ): Promise<LiveRuntime | undefined> {
239
429
  if (closed) throw new Error('The host runtimes are closed.');
240
430
  if (forgetting.has(host.id)) throw new Error('This host is being forgotten.');
241
431
  if (isCloudHost(host)) return connectCloud(host, requestPermission);
@@ -253,6 +443,8 @@ export function createHostRuntimes(
253
443
  stopEntry(previous, !isCloudHost(previous.host) && previous.host.signer.publicKey === host.signer.publicKey);
254
444
  const entry: HostRuntimeEntry = { host, status: 'connecting', controller: new AbortController() };
255
445
  entries.set(host.id, entry);
446
+ const twin = cloudTwin(host.signer.publicKey);
447
+ if (twin && !twin.standby) standDown(twin);
256
448
  const saved = hostSnapshots.open(host).read();
257
449
  if (saved) {
258
450
  applySessionsSnapshot({ sessions: saved.sessions }, host.id);
@@ -267,17 +459,9 @@ export function createHostRuntimes(
267
459
  scan?.hostId !== host.id;
268
460
  try {
269
461
  // A relay host never touches its Cloud origin directly, so its transport is chosen before any request.
462
+ // Plain HTTPS starts without waiting, so cached plugins start before authentication.
270
463
  const transport =
271
- session || (!host.tlsCertificateSha256 && !host.relayRoute)
272
- ? undefined
273
- : host.relayRoute
274
- ? createRelayTransport({
275
- origin: host.origin,
276
- route: host.relayRoute,
277
- capability: await loadRelayCapability(host.id),
278
- signer: host.signer.publicKey,
279
- })
280
- : createPinnedLanTransport(host.origin, host.tlsCertificateSha256!);
464
+ session || (!host.tlsCertificateSha256 && !host.relayRoute) ? undefined : await pairedTransport(host);
281
465
  entry.lanTransport = session?.lanTransport ?? transport;
282
466
  const trustedSession =
283
467
  session ??
@@ -347,13 +531,16 @@ export function createHostRuntimes(
347
531
  entry.lanTransport?.close();
348
532
  entry.lanTransport = undefined;
349
533
  if (active()) {
534
+ // Its own connection is down; the same computer's Cloud listing carries it meanwhile.
535
+ const listed = cloudTwin(host.signer.publicKey);
536
+ if (listed) return fallBackToCloud(host, listed.host);
350
537
  entry.status = 'disconnected';
351
538
  entry.error = error instanceof Error ? error.message : 'Could not connect to this host.';
352
539
  changed();
353
540
  }
354
541
  throw error;
355
542
  }
356
- };
543
+ }
357
544
 
358
545
  return {
359
546
  connect,
@@ -497,6 +684,10 @@ export function createHostRuntimes(
497
684
  if (focused !== null && splitHostId(focused)?.hostId === hostId) focused = null;
498
685
  changed();
499
686
  forgetHostModules(hostId);
687
+ // Forgetting the pairing leaves the computer reachable through its Cloud listing.
688
+ const listed =
689
+ forgotten && !isCloudHost(forgotten.host) ? cloudTwin(forgotten.host.signer.publicKey) : undefined;
690
+ if (listed?.standby && !closed) connectCloud(listed.host, false);
500
691
  purgeNativeBundleUpdates(hostId);
501
692
  await bundleCacheStorage(hostId).clear();
502
693
  } finally {
@@ -1,4 +1,5 @@
1
1
  import type { FederationWorkPaused } from '@agimon-ai/po-core/packageApi';
2
+ import type { ProtocolLink } from '@agimon-ai/po-core/protocolTransport';
2
3
  import {
3
4
  transcriptPageQuery,
4
5
  type TranscriptPage,
@@ -82,6 +83,17 @@ import { setNativeTemplateChoice } from './nativeTemplate';
82
83
  /** `client=native` tells the host a phone needs its native build, which it otherwise defers. */
83
84
  const COMPOSITIONS_ROUTE = '/api/compositions?client=native';
84
85
  const BUNDLED_IDS: ReadonlySet<string> = new Set(bundledPlugins.map((plugin) => plugin.id));
86
+
87
+ /**
88
+ * A computer linked to the person's Po Cloud account: HTTP and the host protocol go through Po Cloud with their
89
+ * sign-in. There are no pairing keys, so nothing here can show a Face ID step-up.
90
+ */
91
+ export interface CloudComputerSession {
92
+ hostId: string;
93
+ origin: string;
94
+ sealed: TrustedSession['sealed'];
95
+ openLink: () => Promise<ProtocolLink>;
96
+ }
85
97
  // All host runtimes share one mode source. A disconnected host must not unbind the others.
86
98
  let liveHosts = 0;
87
99
  let stopFileLinkModes: (() => void) | undefined;
@@ -239,9 +251,9 @@ function isRecord(value: unknown): value is Record<string, unknown> {
239
251
  return typeof value === 'object' && value !== null && !Array.isArray(value);
240
252
  }
241
253
 
242
- /** Wires connection, hub frames, session runtime and native compositions for one trusted session. */
254
+ /** Wires connection, hub frames, session runtime and native compositions for one trusted or Cloud-linked session. */
243
255
  export function startLiveRuntime(
244
- session: TrustedSession | Promise<TrustedSession>,
256
+ session: TrustedSession | CloudComputerSession | Promise<TrustedSession>,
245
257
  host: HostRecord,
246
258
  onReconnectNeeded: () => void,
247
259
  receiveActivityLoad: (owner: string, state: ActivityLoadState) => void = () => {},
@@ -255,6 +267,7 @@ export function startLiveRuntime(
255
267
  federationHostId?: string;
256
268
  } = {},
257
269
  ): LiveRuntime {
270
+ const cloudComputer = !(session instanceof Promise) && 'openLink' in session;
258
271
  const snapshotLease = hostSnapshots.open(host);
259
272
  const lastKnown: HostSnapshot = { sessions: [], workspaces: [] };
260
273
  const persist = () => {
@@ -368,8 +381,9 @@ export function startLiveRuntime(
368
381
  const kept = hostPluginsFor(host);
369
382
  const { updates, plugins, compositions, selectedSessions, sessionMounts, mountedWorkspaces } = kept;
370
383
 
371
- const connect = (session: TrustedSession): Connection => {
372
- if ((host.tlsCertificateSha256 || host.relayRoute) && !session.lanTransport)
384
+ const connect = (session: TrustedSession | CloudComputerSession): Connection => {
385
+ const cloud = 'openLink' in session;
386
+ if (!cloud && (host.tlsCertificateSha256 || host.relayRoute) && !session.lanTransport)
373
387
  throw new Error(
374
388
  host.relayRoute
375
389
  ? 'The relay session has no relay transport.'
@@ -377,11 +391,15 @@ export function startLiveRuntime(
377
391
  );
378
392
  return createConnection({
379
393
  hostId: host.id,
380
- http: session.http,
381
- channels: session.channels,
394
+ ...(cloud
395
+ ? { openLink: session.openLink }
396
+ : {
397
+ http: session.http,
398
+ channels: session.channels,
399
+ // React Native's WebSocket takes (url, protocols, { headers }); the DOM lib typing omits the third argument.
400
+ Socket: session.lanTransport?.Socket ?? (WebSocket as unknown as NativeSocketConstructor),
401
+ }),
382
402
  sealed: session.sealed,
383
- // React Native's WebSocket takes (url, protocols, { headers }); the DOM lib typing omits the third argument.
384
- Socket: session.lanTransport?.Socket ?? (WebSocket as unknown as NativeSocketConstructor),
385
403
  onAccess: (rights) => applySessionInteractions(rights, host.id),
386
404
  onSessions(sessions) {
387
405
  if (closed) return;
@@ -795,15 +813,11 @@ export function startLiveRuntime(
795
813
  applyFocus();
796
814
  },
797
815
  async wake(sessionId) {
798
- const response = await fetchWithStepUp(
799
- {
800
- method: 'POST',
801
- target: hostPath(sessionId, '/revive'),
802
- },
803
- undefined,
804
- undefined,
805
- host.id,
806
- );
816
+ const target = hostPath(sessionId, '/revive');
817
+ // A Cloud-linked computer has no Face ID key to confirm with; its sign-in is what admits the wake.
818
+ const response = cloudComputer
819
+ ? await request({ method: 'POST', target })
820
+ : await fetchWithStepUp({ method: 'POST', target }, undefined, undefined, host.id);
807
821
  if (response.ok) return;
808
822
  const body: unknown = await response.json().catch(() => undefined);
809
823
  throw new Error(
@@ -4,7 +4,7 @@ import { useCallback, useEffect, useState } from 'react';
4
4
  import { Alert, ScrollView, Text } from 'react-native';
5
5
  import { StyleSheet } from 'react-native-unistyles';
6
6
 
7
- import { disableRemote, readRemote, revokeTrustedDevice } from '../services/settingsApi';
7
+ import { disableRemote, NO_REMOTE_ACCESS, readRemote, revokeTrustedDevice } from '../services/settingsApi';
8
8
  import { ErrorLine, Group, OnComputer, remoteSummary, Row } from './SettingsScreen';
9
9
 
10
10
  /*
@@ -88,7 +88,11 @@ export function RemoteControlScreen({ remote, error, busy, turnOff, revokeDevice
88
88
  <Text style={styles.lede}>
89
89
  Reach this Po from your phone or another computer. Turning access on and pairing happen on your computer.
90
90
  </Text>
91
- <ErrorLine>{error}</ErrorLine>
91
+ {error === NO_REMOTE_ACCESS ? (
92
+ <OnComputer>Remote access and trusted devices change on that computer only.</OnComputer>
93
+ ) : (
94
+ <ErrorLine>{error}</ErrorLine>
95
+ )}
92
96
  {remote && summary ? (
93
97
  <>
94
98
  <Group label="Remote access">
@@ -106,15 +106,18 @@ export function bindCloudApi(hostId: string, send: Send): () => void {
106
106
  }
107
107
 
108
108
  /**
109
- * One host's exchange: its paired sealed channel, or Po Cloud when the host is one. With no host named
110
- * and no computer paired, the only signed-in Po Cloud host answers.
109
+ * One host's exchange: its paired sealed channel, or Po Cloud when the host is one or a paired computer runs
110
+ * through it for now. With no host named and no computer paired, the only signed-in Po Cloud host answers.
111
111
  */
112
112
  function sendTo(hostId?: string): Send {
113
113
  return (request, signal) => {
114
- const candidate =
115
- hostId === undefined ? (cloudApis.size === 1 ? [...cloudApis.values()][0] : undefined) : cloudApis.get(hostId);
116
- // A paired computer keeps its own sealed channel.
117
- const cloud = candidate !== undefined && !currentSession(hostId) ? candidate : undefined;
114
+ // A named host bound to Cloud is reached through Cloud, even with a paired channel left from before.
115
+ const cloud =
116
+ hostId !== undefined
117
+ ? cloudApis.get(hostId)
118
+ : cloudApis.size === 1 && !currentSession()
119
+ ? [...cloudApis.values()][0]
120
+ : undefined;
118
121
  if (cloud) return cloud(request, signal);
119
122
  if (hostId !== undefined) return fetchWithStepUp(request, undefined, signal, hostId);
120
123
  return signal === undefined ? fetchWithStepUp(request) : fetchWithStepUp(request, undefined, signal);
@@ -144,10 +147,10 @@ export function settingsTransportForHost(hostId: string): ApiTransport {
144
147
  input === '/api/remote' || input.startsWith('/api/remote/') ? shell(input, init) : scoped(input, init);
145
148
  }
146
149
 
147
- /** Native plugins may name a connected host. Unknown hosts never fall back to another session. */
150
+ /** Native plugins may name a connected host: paired, or reached through Po Cloud. Unknown hosts never fall back to another session. */
148
151
  export function transportForHost(hostId: string): ApiTransport {
149
152
  return async (input, init) => {
150
- if (!currentSession(hostId)) throw new Error('This host is unavailable.');
153
+ if (!currentSession(hostId) && !cloudApis.has(hostId)) throw new Error('This host is unavailable.');
151
154
  const request = apiTransportForHost(hostId);
152
155
  const workspace = /^\/api\/network\/workspaces\/([^/?]+)\/calendar\//u.exec(input)?.[1];
153
156
  if (!workspace) return request(input, init);
@@ -9,6 +9,7 @@ const UUID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/u;
9
9
  const ORG_ID = /^[a-zA-Z0-9_-]{1,128}$/u;
10
10
  const API_PREFIX = /^\/[a-z0-9-]+(?:\/[a-z0-9-]+)*$/u;
11
11
  const RELAY_HOST_ID = /^relay-[a-zA-Z0-9_-]{43}$/u;
12
+ const PUBLIC_KEY = /^[A-Za-z0-9_-]{1,512}$/u;
12
13
 
13
14
  /** A Po Cloud org reached with the person's identity session cookie, not a QR pairing. */
14
15
  export interface CloudHostRecord {
@@ -25,8 +26,11 @@ export interface CloudHostRecord {
25
26
  workspaceId?: string;
26
27
  /** Hosted Po Cloud: signed in with its own email-code session, its cloud API under this path of `origin`. */
27
28
  hosted?: { apiPrefix: string };
28
- /** A distinct computer discovered through the hosted account, never a paired host. */
29
- computer?: { hostId: string; generation: number };
29
+ /**
30
+ * A distinct computer discovered through the hosted account, never a paired host. Its bundle signer, when Cloud
31
+ * lists one, lets the phone check that computer's plugins and run it as it runs a paired computer.
32
+ */
33
+ computer?: { hostId: string; generation: number; publicKey?: string };
30
34
  }
31
35
 
32
36
  export function isCloudHost(host: object): host is CloudHostRecord {
@@ -55,7 +59,11 @@ function computerOf(value: unknown): CloudHostRecord['computer'] {
55
59
  if (!isRecord(value) || typeof value.hostId !== 'string' || !RELAY_HOST_ID.test(value.hostId)) return undefined;
56
60
  const generation = value.generation;
57
61
  if (typeof generation !== 'number' || !Number.isSafeInteger(generation) || generation < 1) return undefined;
58
- return { hostId: value.hostId, generation };
62
+ return {
63
+ hostId: value.hostId,
64
+ generation,
65
+ ...(typeof value.publicKey === 'string' && PUBLIC_KEY.test(value.publicKey) ? { publicKey: value.publicKey } : {}),
66
+ };
59
67
  }
60
68
 
61
69
  function cloudHostOf(value: unknown): CloudHostRecord | undefined {
@@ -1,4 +1,4 @@
1
- import { createProtocolClient, type ProtocolClient } from '@agimon-ai/po-core/protocolTransport';
1
+ import { createProtocolClient, type ProtocolClient, type ProtocolLink } from '@agimon-ai/po-core/protocolTransport';
2
2
  import {
3
3
  bindTransport,
4
4
  bindHostTransport,
@@ -20,19 +20,22 @@ const TELEMETRY_ROUTE = '/api/telemetry/browser';
20
20
  /** One sealed channel per transport, established by pairing or device authentication. */
21
21
  export type ConnectionChannels = Record<'session' | 'protocol' | 'http', SealedTransport>;
22
22
 
23
- export interface ConnectionOptions extends Omit<SessionSocketHandlers, 'onOpen' | 'onClose'> {
24
- hostId?: string;
25
- http: RemoteHttp;
26
- channels: ConnectionChannels;
27
- /** The trusted session owns the single exchange queue for its HTTP channel. */
28
- sealed: ReturnType<typeof createSealedHttp>;
29
- Socket: NativeSocketConstructor;
30
- /**
31
- * Called when an open hub connection drops, so the shell can re-authenticate and rebuild channels.
32
- * Not called once the server needs a newer app: reconnecting cannot help, `onUpdateRequired` is heard instead.
33
- */
34
- onReconnectNeeded(): void;
35
- }
23
+ /** A paired computer's sealed channels, or a link a Po Cloud sign-in already opened to a linked computer. */
24
+ type ProtocolSource =
25
+ | { http: RemoteHttp; channels: ConnectionChannels; Socket: NativeSocketConstructor; openLink?: undefined }
26
+ | { openLink: () => Promise<ProtocolLink>; http?: undefined; channels?: undefined; Socket?: undefined };
27
+
28
+ export type ConnectionOptions = Omit<SessionSocketHandlers, 'onOpen' | 'onClose'> &
29
+ ProtocolSource & {
30
+ hostId?: string;
31
+ /** The trusted session owns the single exchange queue for its HTTP channel. */
32
+ sealed: ReturnType<typeof createSealedHttp>;
33
+ /**
34
+ * Called when an open hub connection drops, so the shell can re-authenticate and rebuild channels.
35
+ * Not called once the server needs a newer app: reconnecting cannot help, `onUpdateRequired` is heard instead.
36
+ */
37
+ onReconnectNeeded(): void;
38
+ };
36
39
 
37
40
  export interface Connection {
38
41
  readonly client: ProtocolClient;
@@ -44,10 +47,13 @@ export interface Connection {
44
47
 
45
48
  /** Wires the protocol client, hub socket and dashboard transport over already-established channels. */
46
49
  export function createConnection(options: ConnectionOptions): Connection {
47
- const { http, channels, sealed: request } = options;
50
+ const { sealed: request } = options;
48
51
  const client = createProtocolClient({
49
52
  name: 'native',
50
- openLink: createNativeProtocolLink(http, channels.protocol, options.Socket, undefined, request),
53
+ openLink:
54
+ options.openLink !== undefined
55
+ ? options.openLink
56
+ : createNativeProtocolLink(options.http, options.channels.protocol, options.Socket, undefined, request),
51
57
  });
52
58
  let opened = false;
53
59
  let closed = false;
@@ -9,6 +9,7 @@ import {
9
9
  type PinnedLanTransport,
10
10
  } from '../../../modules/po-lan-tls';
11
11
  import { createRemoteHttp, createSealedHttp, type RemoteHttp, type SealedHttpRequest } from '../../adapters/remoteHttp';
12
+ import { isCloudHost } from '../cloudHosts';
12
13
  import { hostSnapshots } from '../hostSnapshots';
13
14
  import { type Channels, establishChannels, pairDevice, parsePairingUrl } from '../pairing';
14
15
  import { isRelayTrustError, PRIVATE_RELAY_CAPABILITY, PRIVATE_RELAY_ROUTE } from '../relayTransport/route';
@@ -305,9 +306,9 @@ export function validHostDisplayName(value: string): boolean {
305
306
  return value === value.trim() && value.length >= 1 && value.length <= 64 && !/[\p{Cc}\p{Cf}]/u.test(value);
306
307
  }
307
308
 
308
- /** Also names Po Cloud hosts, which carry the same origin and optional name. */
309
+ /** Also names Po Cloud hosts: they share the Cloud origin, so each falls back to its own label instead. */
309
310
  export function hostDisplayName(host: Pick<HostRecord, 'displayName' | 'origin'>): string {
310
- return host.displayName ?? new URL(host.origin).hostname;
311
+ return host.displayName ?? (isCloudHost(host) ? host.label : new URL(host.origin).hostname);
311
312
  }
312
313
 
313
314
  /** Renames the computer, never the phone label sent during registration. */
@@ -81,6 +81,8 @@ async function request<T>(
81
81
  if (picked !== undefined) return picked;
82
82
  }
83
83
  if (missing !== undefined && (response.status === 404 || (response.ok && !isRecord(body)))) return { error: missing };
84
+ // A computer reached through Po Cloud keeps its remote access to itself: the same quiet answer, not a failure.
85
+ if (missing === NO_REMOTE_ACCESS && response.status === 403) return { error: missing };
84
86
  if (response.status === 0) return { error: UNANSWERED };
85
87
  return {
86
88
  error: isRecord(body) && typeof body.error === 'string' ? body.error : `Po answered ${String(response.status)}.`,
@@ -158,7 +160,7 @@ export function logoutProvider(providerId: string, hostId?: string): Promise<Res
158
160
  return request(`${AUTH_PROVIDERS_API_ROUTE}/${encodeURIComponent(providerId)}`, { method: 'DELETE' }, ok, hostId);
159
161
  }
160
162
 
161
- /** What `readRemote` answers for a host with no remote access of its own, such as Po Cloud. Not a failure. */
163
+ /** What `readRemote` answers for a host with no remote access this phone may read, such as Po Cloud or a computer reached through it. Not a failure. */
162
164
  export const NO_REMOTE_ACCESS = 'This host has no remote access settings.';
163
165
 
164
166
  export function readRemote(hostId?: string): Promise<Result<{ state: RemoteAccessStateView }>> {