@agimon-ai/po-native 0.0.1-alpha.57 → 0.0.1-alpha.58
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 +12 -12
- package/src/app/App.tsx +3 -3
- package/src/app/HostsRoutes.tsx +2 -1
- package/src/app/cloudRuntime.ts +60 -32
- package/src/app/hostRuntimes.ts +74 -20
- package/src/app/liveRuntime.ts +31 -17
- package/src/screens/RemoteControlScreen.tsx +6 -2
- package/src/services/apiTransport/index.ts +2 -2
- package/src/services/cloudHosts/index.ts +11 -3
- package/src/services/connection/index.ts +22 -16
- package/src/services/deviceTrust/index.ts +3 -2
- package/src/services/settingsApi/index.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/po-native",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.58",
|
|
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.
|
|
33
|
-
"@agimon-ai/po-expo-signing": "0.0.1-alpha.
|
|
34
|
-
"@agimon-ai/po-identity": "0.0.2-alpha.
|
|
35
|
-
"@agimon-ai/po-native-components": "0.0.0-alpha.
|
|
36
|
-
"@agimon-ai/po-native-dashboard": "0.0.0-alpha.
|
|
37
|
-
"@agimon-ai/po-template-advanced": "0.0.0-alpha.
|
|
38
|
-
"@agimon-ai/po-template-elegant": "0.0.0-alpha.
|
|
39
|
-
"@agimon-ai/po-voice": "0.0.0-alpha.
|
|
40
|
-
"@agimon-ai/po-web-components": "0.0.0-alpha.
|
|
41
|
-
"@agimon-ai/po-web-dashboard": "0.0.0-alpha.
|
|
42
|
-
"@agimon-ai/po-web-security": "0.0.0-alpha.
|
|
32
|
+
"@agimon-ai/po-core": "0.0.0-alpha.178",
|
|
33
|
+
"@agimon-ai/po-expo-signing": "0.0.1-alpha.58",
|
|
34
|
+
"@agimon-ai/po-identity": "0.0.2-alpha.125",
|
|
35
|
+
"@agimon-ai/po-native-components": "0.0.0-alpha.178",
|
|
36
|
+
"@agimon-ai/po-native-dashboard": "0.0.0-alpha.50",
|
|
37
|
+
"@agimon-ai/po-template-advanced": "0.0.0-alpha.178",
|
|
38
|
+
"@agimon-ai/po-template-elegant": "0.0.0-alpha.178",
|
|
39
|
+
"@agimon-ai/po-voice": "0.0.0-alpha.178",
|
|
40
|
+
"@agimon-ai/po-web-components": "0.0.0-alpha.178",
|
|
41
|
+
"@agimon-ai/po-web-dashboard": "0.0.0-alpha.178",
|
|
42
|
+
"@agimon-ai/po-web-security": "0.0.0-alpha.178",
|
|
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
|
|
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:
|
|
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={
|
|
2354
|
+
name={hostDisplayName(host)}
|
|
2355
2355
|
status={status}
|
|
2356
2356
|
onPress={() => {
|
|
2357
2357
|
setChoosingGeneralHost(false);
|
package/src/app/HostsRoutes.tsx
CHANGED
|
@@ -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:
|
|
41
|
+
label: hostDisplayName(host),
|
|
41
42
|
origin: new URL(host.origin).host,
|
|
42
43
|
status: status === 'connected' ? 'Connected' : status === 'connecting' ? 'Connecting' : 'Disconnected',
|
|
43
44
|
}));
|
package/src/app/cloudRuntime.ts
CHANGED
|
@@ -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
|
-
...
|
|
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
|
|
153
|
-
): Promise<Response> =>
|
|
154
|
-
|
|
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
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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();
|
package/src/app/hostRuntimes.ts
CHANGED
|
@@ -33,12 +33,20 @@ 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 {
|
|
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;
|
|
42
50
|
|
|
43
51
|
async function withinDeadline(operation: Promise<unknown>, deferred: string): Promise<void> {
|
|
44
52
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -191,9 +199,13 @@ export function createHostRuntimes(
|
|
|
191
199
|
continue;
|
|
192
200
|
const latest = computers.find(({ id }) => id === existing.id);
|
|
193
201
|
if (!latest || latest.computer?.generation !== existing.computer.generation) dropCloudEntry(candidate);
|
|
194
|
-
else if (latest.label !== existing.label) {
|
|
195
|
-
|
|
196
|
-
|
|
202
|
+
else if (latest.label !== existing.label || latest.computer?.publicKey !== existing.computer.publicKey) {
|
|
203
|
+
// A newly listed bundle signer moves the computer onto the full runtime.
|
|
204
|
+
if (latest.computer?.publicKey !== existing.computer.publicKey) connectCloud(latest, false);
|
|
205
|
+
else {
|
|
206
|
+
candidate.host = latest;
|
|
207
|
+
changed();
|
|
208
|
+
}
|
|
197
209
|
}
|
|
198
210
|
}
|
|
199
211
|
for (const computer of computers) {
|
|
@@ -206,22 +218,64 @@ export function createHostRuntimes(
|
|
|
206
218
|
discovering = false;
|
|
207
219
|
}
|
|
208
220
|
};
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
const publicKey = host.computer?.publicKey;
|
|
222
|
+
// A computer whose bundle signer Cloud lists runs as a paired computer does: activity, plugins and its own UI.
|
|
223
|
+
const runtime = publicKey
|
|
224
|
+
? startLiveRuntime(
|
|
225
|
+
{ hostId: host.id, origin: host.origin, sealed: cloudApiSend(host), openLink: cloudComputerLink(host) },
|
|
226
|
+
{
|
|
227
|
+
id: host.id,
|
|
228
|
+
origin: host.origin,
|
|
229
|
+
trustedDeviceId: `cloud:${host.person.subject}`,
|
|
230
|
+
signer: { publicKey, revision: 0 },
|
|
231
|
+
label: host.label,
|
|
232
|
+
...(host.displayName === undefined ? {} : { displayName: host.displayName }),
|
|
233
|
+
},
|
|
234
|
+
() => {
|
|
235
|
+
if (active())
|
|
236
|
+
setTimeout(() => {
|
|
237
|
+
if (active()) connectCloud(host, false);
|
|
238
|
+
}, CLOUD_COMPUTER_RECONNECT_MS);
|
|
239
|
+
},
|
|
240
|
+
(owner, state) => {
|
|
241
|
+
if (active()) options.activity?.(host.id, owner, state);
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
onSummariesLoaded() {
|
|
245
|
+
if (!active() || entry.status === 'connected') return;
|
|
246
|
+
entry.status = 'connected';
|
|
247
|
+
entry.error = undefined;
|
|
248
|
+
changed();
|
|
249
|
+
},
|
|
250
|
+
onPluginCompatibility(issues) {
|
|
251
|
+
if (!active()) return;
|
|
252
|
+
entry.pluginCompatibility = issues;
|
|
253
|
+
changed();
|
|
254
|
+
},
|
|
255
|
+
onUpdateRequired() {
|
|
256
|
+
if (!active()) return;
|
|
257
|
+
entry.status = 'update_required';
|
|
258
|
+
changed();
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
)
|
|
262
|
+
: startCloudRuntime(host, {
|
|
263
|
+
onSummariesLoaded() {
|
|
264
|
+
if (!active()) return;
|
|
265
|
+
if (entry.status !== 'connected') {
|
|
266
|
+
entry.status = 'connected';
|
|
267
|
+
changed();
|
|
268
|
+
}
|
|
269
|
+
if (!host.computer && host.hosted && !discovering) void discoverComputers();
|
|
270
|
+
},
|
|
271
|
+
onError(message) {
|
|
272
|
+
if (!active() || entry.error === message) return;
|
|
273
|
+
entry.error = message;
|
|
274
|
+
if (message !== undefined && (entry.status === 'connecting' || host.computer))
|
|
275
|
+
entry.status = 'disconnected';
|
|
276
|
+
changed();
|
|
277
|
+
},
|
|
278
|
+
});
|
|
225
279
|
entry.runtime = runtime;
|
|
226
280
|
// Settings and other host calls reach this Po Cloud host with the person's sign-in until it stops.
|
|
227
281
|
entry.controller.signal.addEventListener('abort', bindCloudApi(host.id, cloudApiSend(host)), { once: true });
|
package/src/app/liveRuntime.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
381
|
-
|
|
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
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
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
|
-
|
|
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">
|
|
@@ -144,10 +144,10 @@ export function settingsTransportForHost(hostId: string): ApiTransport {
|
|
|
144
144
|
input === '/api/remote' || input.startsWith('/api/remote/') ? shell(input, init) : scoped(input, init);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
/** Native plugins may name a connected host. Unknown hosts never fall back to another session. */
|
|
147
|
+
/** Native plugins may name a connected host: paired, or reached through Po Cloud. Unknown hosts never fall back to another session. */
|
|
148
148
|
export function transportForHost(hostId: string): ApiTransport {
|
|
149
149
|
return async (input, init) => {
|
|
150
|
-
if (!currentSession(hostId)) throw new Error('This host is unavailable.');
|
|
150
|
+
if (!currentSession(hostId) && !cloudApis.has(hostId)) throw new Error('This host is unavailable.');
|
|
151
151
|
const request = apiTransportForHost(hostId);
|
|
152
152
|
const workspace = /^\/api\/network\/workspaces\/([^/?]+)\/calendar\//u.exec(input)?.[1];
|
|
153
153
|
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
|
-
/**
|
|
29
|
-
|
|
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 {
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
http: RemoteHttp;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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 {
|
|
50
|
+
const { sealed: request } = options;
|
|
48
51
|
const client = createProtocolClient({
|
|
49
52
|
name: 'native',
|
|
50
|
-
openLink:
|
|
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
|
|
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
|
|
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 }>> {
|