@agimon-ai/po-native 0.0.1-alpha.72 → 0.0.1-alpha.73
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 +9 -1
- package/src/app/hostRuntimes.ts +7 -0
- package/src/app/liveRuntime.ts +95 -58
- package/src/screens/SessionScreen.stories.tsx +94 -3
- package/src/services/bundleUpdates/index.ts +16 -3
- package/src/services/deviceTrust/index.ts +7 -4
- package/src/services/hostActions/index.ts +5 -23
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.73",
|
|
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.193",
|
|
33
|
+
"@agimon-ai/po-expo-signing": "0.0.1-alpha.73",
|
|
34
|
+
"@agimon-ai/po-identity": "0.0.2-alpha.140",
|
|
35
|
+
"@agimon-ai/po-native-components": "0.0.0-alpha.193",
|
|
36
|
+
"@agimon-ai/po-native-dashboard": "0.0.0-alpha.65",
|
|
37
|
+
"@agimon-ai/po-template-advanced": "0.0.0-alpha.193",
|
|
38
|
+
"@agimon-ai/po-template-elegant": "0.0.0-alpha.193",
|
|
39
|
+
"@agimon-ai/po-voice": "0.0.0-alpha.193",
|
|
40
|
+
"@agimon-ai/po-web-components": "0.0.0-alpha.193",
|
|
41
|
+
"@agimon-ai/po-web-dashboard": "0.0.0-alpha.193",
|
|
42
|
+
"@agimon-ai/po-web-security": "0.0.0-alpha.193",
|
|
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
|
@@ -131,6 +131,7 @@ import {
|
|
|
131
131
|
} from '@react-navigation/native-stack';
|
|
132
132
|
import { shallow, useStore } from '@tanstack/react-store';
|
|
133
133
|
import { Store } from '@tanstack/store';
|
|
134
|
+
import { addNetworkStateListener } from 'expo-network';
|
|
134
135
|
import {
|
|
135
136
|
cloneElement,
|
|
136
137
|
memo,
|
|
@@ -3326,10 +3327,17 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
|
|
|
3326
3327
|
renew();
|
|
3327
3328
|
const subscription = AppState.addEventListener('change', (state) => {
|
|
3328
3329
|
if (state !== 'active') return;
|
|
3330
|
+
hosts.current?.retryDisconnectedComputers();
|
|
3329
3331
|
renew();
|
|
3330
3332
|
followAccountRemovals(hosts.current);
|
|
3331
3333
|
});
|
|
3332
|
-
|
|
3334
|
+
const network = addNetworkStateListener(({ isConnected }) => {
|
|
3335
|
+
if (isConnected && AppState.currentState === 'active') hosts.current?.retryDisconnectedComputers();
|
|
3336
|
+
});
|
|
3337
|
+
return () => {
|
|
3338
|
+
subscription.remove();
|
|
3339
|
+
network.remove();
|
|
3340
|
+
};
|
|
3333
3341
|
}, []);
|
|
3334
3342
|
|
|
3335
3343
|
useEffect(() => {
|
package/src/app/hostRuntimes.ts
CHANGED
|
@@ -579,6 +579,13 @@ export function createHostRuntimes(
|
|
|
579
579
|
return {
|
|
580
580
|
connect,
|
|
581
581
|
snapshot,
|
|
582
|
+
retryDisconnectedComputers() {
|
|
583
|
+
for (const { host, status } of entries.values()) {
|
|
584
|
+
if (!isCloudHost(host) && status === 'disconnected') {
|
|
585
|
+
void connect(host).catch(() => undefined);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
},
|
|
582
589
|
async rescan(scanned: string, signal?: AbortSignal): Promise<TrustedSession> {
|
|
583
590
|
if (closed) throw new Error('The host runtimes are closed.');
|
|
584
591
|
if (scan) throw new Error('A pairing scan is already running.');
|
package/src/app/liveRuntime.ts
CHANGED
|
@@ -83,6 +83,7 @@ import { createHomeReader, type HomeReader } from './homeState';
|
|
|
83
83
|
import { setNativeTemplateChoice } from './nativeTemplate';
|
|
84
84
|
/** `client=native` tells the host a phone needs its native build, which it otherwise defers. */
|
|
85
85
|
const COMPOSITIONS_ROUTE = '/api/compositions?client=native';
|
|
86
|
+
const BUNDLE_REQUEST_TIMEOUT_MS = 8_000;
|
|
86
87
|
const BUNDLED_IDS: ReadonlySet<string> = new Set(bundledPlugins.map((plugin) => plugin.id));
|
|
87
88
|
|
|
88
89
|
/**
|
|
@@ -102,6 +103,7 @@ let stopFileLinkModes: (() => void) | undefined;
|
|
|
102
103
|
/** What the current connection lends the host's plugins; absent between a drop and its replacement. */
|
|
103
104
|
interface HostPluginLink {
|
|
104
105
|
request: Connection['request'];
|
|
106
|
+
requestBundle: (target: string) => Promise<Response>;
|
|
105
107
|
onActivityLoad: (owner: string, state: ActivityLoadState) => void;
|
|
106
108
|
onCompatibility: (issues: readonly PluginCompatibility[]) => void;
|
|
107
109
|
onError: (error: unknown) => void;
|
|
@@ -147,15 +149,13 @@ function createHostPlugins(host: HostRecord): HostPlugins {
|
|
|
147
149
|
hostId: host.id,
|
|
148
150
|
signerPublicKey: host.signer.publicKey,
|
|
149
151
|
async fetchComposition(descriptor, entryPath) {
|
|
150
|
-
const {
|
|
151
|
-
const manifest = await
|
|
152
|
+
const { requestBundle } = linked(kept);
|
|
153
|
+
const manifest = await requestBundle(descriptor.manifestUrl);
|
|
152
154
|
if (!manifest.ok) throw new Error(`Composition ${descriptor.id} manifest is unavailable.`);
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
target: `${descriptor.rawAssetBaseUrl.replace(/\/+$/u, '')}${entryPath}`,
|
|
156
|
-
});
|
|
155
|
+
const signed: unknown = await manifest.json();
|
|
156
|
+
const asset = await requestBundle(`${descriptor.rawAssetBaseUrl.replace(/\/+$/u, '')}${entryPath}`);
|
|
157
157
|
if (!asset.ok) throw new Error(`Composition ${descriptor.id} module ${entryPath} is unavailable.`);
|
|
158
|
-
return { signed
|
|
158
|
+
return { signed, source: new Uint8Array(await asset.arrayBuffer()) };
|
|
159
159
|
},
|
|
160
160
|
onError(error) {
|
|
161
161
|
kept.link?.onActivityLoad('catalog', {
|
|
@@ -194,13 +194,14 @@ function createHostPlugins(host: HostRecord): HostPlugins {
|
|
|
194
194
|
async fetchComposition(descriptor, entryPath) {
|
|
195
195
|
const composition = compositions.get(descriptor.id);
|
|
196
196
|
if (!composition) throw new Error(`Composition ${descriptor.id} is not advertised by the host.`);
|
|
197
|
-
const {
|
|
198
|
-
const manifest = await
|
|
197
|
+
const { requestBundle } = linked(kept);
|
|
198
|
+
const manifest = await requestBundle(composition.manifestUrl);
|
|
199
199
|
if (!manifest.ok) throw new Error(`Composition ${descriptor.id} manifest is unavailable.`);
|
|
200
|
+
const signed: unknown = await manifest.json();
|
|
200
201
|
const base = composition.rawAssetBaseUrl.replace(/\/+$/u, '');
|
|
201
|
-
const asset = await
|
|
202
|
+
const asset = await requestBundle(`${base}${entryPath}`);
|
|
202
203
|
if (!asset.ok) throw new Error(`Composition ${descriptor.id} module ${entryPath} is unavailable.`);
|
|
203
|
-
return { signed
|
|
204
|
+
return { signed, source: new Uint8Array(await asset.arrayBuffer()) };
|
|
204
205
|
},
|
|
205
206
|
});
|
|
206
207
|
return Object.assign(kept, {
|
|
@@ -463,7 +464,7 @@ export function startLiveRuntime(
|
|
|
463
464
|
onChannel: (frame) => plugins.dispatch(frame),
|
|
464
465
|
// A republished global or workspace composition swaps in place; the app itself is not reloaded.
|
|
465
466
|
onCompositions() {
|
|
466
|
-
|
|
467
|
+
void loadCompositions('changed');
|
|
467
468
|
},
|
|
468
469
|
onReconnectNeeded() {
|
|
469
470
|
ready = false;
|
|
@@ -509,8 +510,16 @@ export function startLiveRuntime(
|
|
|
509
510
|
(target, body) => request({ method: 'POST', target, headers: [['content-type', 'application/json']], body }),
|
|
510
511
|
host.id,
|
|
511
512
|
);
|
|
513
|
+
const bundleLifetime = new AbortController();
|
|
514
|
+
const requestBundle = (target: string) =>
|
|
515
|
+
request({
|
|
516
|
+
method: 'GET',
|
|
517
|
+
target,
|
|
518
|
+
signal: AbortSignal.any([bundleLifetime.signal, AbortSignal.timeout(BUNDLE_REQUEST_TIMEOUT_MS)]),
|
|
519
|
+
});
|
|
512
520
|
kept.link = {
|
|
513
521
|
request,
|
|
522
|
+
requestBundle,
|
|
514
523
|
onActivityLoad,
|
|
515
524
|
onError: reportMountFailure,
|
|
516
525
|
onCompatibility(issues) {
|
|
@@ -533,50 +542,54 @@ export function startLiveRuntime(
|
|
|
533
542
|
: target.scope === 'workspace'
|
|
534
543
|
? `workspace:${target.workspaceId}`
|
|
535
544
|
: 'host';
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
545
|
+
const epoch = (loadEpochs.get(owner) ?? 0) + 1;
|
|
546
|
+
loadEpochs.set(owner, epoch);
|
|
547
|
+
const current = () =>
|
|
548
|
+
!closed &&
|
|
549
|
+
loadEpochs.get(owner) === epoch &&
|
|
550
|
+
(target.scope !== 'session' || sessionMounts.get(target.sessionId) === target);
|
|
551
|
+
try {
|
|
552
|
+
if (target.scope === 'session') {
|
|
553
|
+
const previous = selectedSessions.get(target.sessionId);
|
|
554
|
+
if (previous) composition = previous;
|
|
555
|
+
else {
|
|
556
|
+
onActivityLoad(owner, { loading: true });
|
|
557
|
+
const candidate = descriptorOf(composition);
|
|
558
|
+
if (!candidate) throw new Error('The session has an invalid Activity composition.');
|
|
559
|
+
const selected = await updates.selectSession(candidate);
|
|
560
|
+
if (!current()) return;
|
|
561
|
+
if (!selected) throw new Error('The installed Activity bundle does not cover this session.');
|
|
562
|
+
composition = { ...(composition as SessionNativeComposition), ...selected };
|
|
563
|
+
selectedSessions.set(target.sessionId, composition);
|
|
564
|
+
}
|
|
546
565
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
if (loadEpochs.has(owner)) {
|
|
552
|
-
loadEpochs.set(owner, loadEpochs.get(owner)! + 1);
|
|
553
|
-
if (target.scope !== 'session') {
|
|
566
|
+
const descriptor = descriptorOf(composition);
|
|
567
|
+
if (!descriptor) {
|
|
568
|
+
plugins.unmount(target);
|
|
569
|
+
if (epoch > 1) {
|
|
554
570
|
home.clear();
|
|
555
571
|
attentionHome.clear();
|
|
556
572
|
}
|
|
573
|
+
onActivityLoad(owner, { loading: false });
|
|
574
|
+
return;
|
|
557
575
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
home.clear();
|
|
567
|
-
attentionHome.clear();
|
|
576
|
+
compositions.set(descriptor.id, composition as SessionNativeComposition);
|
|
577
|
+
// An unchanged composition must not replace usable cards with a spinner.
|
|
578
|
+
if (!plugins.mounted(target, descriptor)) {
|
|
579
|
+
if (target.scope !== 'session') {
|
|
580
|
+
home.clear();
|
|
581
|
+
attentionHome.clear();
|
|
582
|
+
}
|
|
583
|
+
onActivityLoad(owner, { loading: true });
|
|
568
584
|
}
|
|
569
|
-
onActivityLoad(owner, { loading: true });
|
|
570
|
-
}
|
|
571
|
-
try {
|
|
572
585
|
await plugins.mount(target, descriptor);
|
|
573
|
-
if (
|
|
586
|
+
if (current()) onActivityLoad(owner, { loading: false });
|
|
574
587
|
} catch (error) {
|
|
575
|
-
if (!
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
588
|
+
if (!current()) return;
|
|
589
|
+
onActivityLoad(owner, {
|
|
590
|
+
loading: false,
|
|
591
|
+
error: error instanceof Error ? error.message : 'Activity failed to load.',
|
|
592
|
+
});
|
|
580
593
|
reportMountFailure(error);
|
|
581
594
|
}
|
|
582
595
|
};
|
|
@@ -623,10 +636,13 @@ export function startLiveRuntime(
|
|
|
623
636
|
await mount({ scope: 'workspace', workspaceId }, workspace.nativeComposition);
|
|
624
637
|
}
|
|
625
638
|
};
|
|
639
|
+
let installed = false;
|
|
626
640
|
const startup = updates
|
|
627
641
|
.startup()
|
|
628
642
|
.then(async (catalog) => {
|
|
629
643
|
if (catalog && !closed) {
|
|
644
|
+
installed = true;
|
|
645
|
+
onActivityLoad('catalog', { loading: false });
|
|
630
646
|
await applyCatalog(catalog);
|
|
631
647
|
if (!closed) applyFocus();
|
|
632
648
|
}
|
|
@@ -634,22 +650,21 @@ export function startLiveRuntime(
|
|
|
634
650
|
.catch((error: unknown) => {
|
|
635
651
|
if (!closed) reportMountFailure(error);
|
|
636
652
|
});
|
|
637
|
-
const
|
|
638
|
-
const
|
|
639
|
-
loadEpochs.set('catalog', epoch);
|
|
640
|
-
const current = () => !closed && loadEpochs.get('catalog') === epoch;
|
|
641
|
-
onActivityLoad('catalog', { loading: true });
|
|
653
|
+
const checkCompositions = async (reoffer: boolean) => {
|
|
654
|
+
const current = () => !closed;
|
|
642
655
|
try {
|
|
643
656
|
await startup;
|
|
644
657
|
if (!current()) return;
|
|
645
|
-
|
|
658
|
+
if (!installed) onActivityLoad('catalog', { loading: true });
|
|
659
|
+
const response = await requestBundle(COMPOSITIONS_ROUTE);
|
|
646
660
|
const body: unknown = await response.json();
|
|
647
661
|
if (!current()) return;
|
|
648
662
|
if (!response.ok || !isRecord(body)) throw new Error('Activity extensions are unavailable.');
|
|
649
663
|
options.observeCompositions?.(body, request);
|
|
650
|
-
const result = await updates.check(body);
|
|
664
|
+
const result = await updates.check(body, { signal: bundleLifetime.signal, reoffer });
|
|
651
665
|
if (!current()) return;
|
|
652
666
|
if (result.catalog) {
|
|
667
|
+
installed = true;
|
|
653
668
|
setNativeTemplateChoice(body.nativeTemplate, host.id);
|
|
654
669
|
await applyCatalog(result.catalog);
|
|
655
670
|
if (current()) applyFocus();
|
|
@@ -669,7 +684,7 @@ export function startLiveRuntime(
|
|
|
669
684
|
}
|
|
670
685
|
}
|
|
671
686
|
} catch (error) {
|
|
672
|
-
if (current())
|
|
687
|
+
if (current() && !installed)
|
|
673
688
|
onActivityLoad('catalog', {
|
|
674
689
|
loading: false,
|
|
675
690
|
error: error instanceof Error ? error.message : 'Activity update failed.',
|
|
@@ -691,7 +706,8 @@ export function startLiveRuntime(
|
|
|
691
706
|
}
|
|
692
707
|
if (current()) onActivityLoad('catalog', { loading: false });
|
|
693
708
|
} catch (error) {
|
|
694
|
-
if (current())
|
|
709
|
+
if (!current()) return;
|
|
710
|
+
if (!installed)
|
|
695
711
|
onActivityLoad('catalog', {
|
|
696
712
|
loading: false,
|
|
697
713
|
error: error instanceof Error ? error.message : 'Activity failed to load.',
|
|
@@ -699,6 +715,25 @@ export function startLiveRuntime(
|
|
|
699
715
|
reportMountFailure(error);
|
|
700
716
|
}
|
|
701
717
|
};
|
|
718
|
+
let checking: Promise<void> | undefined;
|
|
719
|
+
let trailing: 'changed' | 'retry' | undefined;
|
|
720
|
+
const loadCompositions = (reason?: 'changed' | 'retry'): Promise<void> | undefined => {
|
|
721
|
+
if (closed) return;
|
|
722
|
+
if (checking) {
|
|
723
|
+
if (reason === 'retry' || (reason === 'changed' && !trailing)) trailing = reason;
|
|
724
|
+
return checking;
|
|
725
|
+
}
|
|
726
|
+
checking = checkCompositions(reason === 'retry').finally(() => {
|
|
727
|
+
checking = undefined;
|
|
728
|
+
const next = trailing;
|
|
729
|
+
trailing = undefined;
|
|
730
|
+
if (next) void loadCompositions(next);
|
|
731
|
+
});
|
|
732
|
+
return checking;
|
|
733
|
+
};
|
|
734
|
+
const foreground = AppState.addEventListener('change', (state) => {
|
|
735
|
+
if (state === 'active') void loadCompositions();
|
|
736
|
+
});
|
|
702
737
|
void loadCompositions();
|
|
703
738
|
|
|
704
739
|
/** A stopped session has no runtime to attach to: its history is read from disk, as the cockpit does. */
|
|
@@ -811,7 +846,7 @@ export function startLiveRuntime(
|
|
|
811
846
|
open: openSession,
|
|
812
847
|
retryActivity(sessionId) {
|
|
813
848
|
if (closed || sessionId !== focused) return;
|
|
814
|
-
void loadCompositions();
|
|
849
|
+
void loadCompositions('retry');
|
|
815
850
|
applyFocus();
|
|
816
851
|
},
|
|
817
852
|
async wake(sessionId, options) {
|
|
@@ -849,6 +884,8 @@ export function startLiveRuntime(
|
|
|
849
884
|
close({ preserveHost = false } = {}) {
|
|
850
885
|
if (closed) return;
|
|
851
886
|
closed = true;
|
|
887
|
+
foreground.remove();
|
|
888
|
+
bundleLifetime.abort();
|
|
852
889
|
// A reconnect keeps the computer's plugins mounted for the next connection; anything else stops them.
|
|
853
890
|
const keep = preserveHost && host.id !== undefined && keptPlugins.get(host.id) === kept;
|
|
854
891
|
if (kept.link?.request === request) kept.link = undefined;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { PoNativeProvider } from '@agimon-ai/po-native-components';
|
|
1
|
+
import { ActivityIcon, Button, ChevronRightIcon, fontOf, PoNativeProvider } from '@agimon-ai/po-native-components';
|
|
2
2
|
import { type TimelineEntry, SessionScreen } from '@agimon-ai/po-native-dashboard';
|
|
3
|
-
import { View } from 'react-native';
|
|
4
|
-
import { UnistylesRuntime } from 'react-native-unistyles';
|
|
3
|
+
import { Text, View } from 'react-native';
|
|
4
|
+
import { StyleSheet, UnistylesRuntime } from 'react-native-unistyles';
|
|
5
|
+
|
|
6
|
+
import { type DesignScheme, PhoneFrame } from './designFrame';
|
|
5
7
|
|
|
6
8
|
const noop = () => {};
|
|
7
9
|
const ENTRIES: TimelineEntry[] = [
|
|
@@ -26,6 +28,95 @@ export const meta = {
|
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
export default meta;
|
|
31
|
+
|
|
32
|
+
function WorkspaceHeaderPreview({ scheme }: { scheme: DesignScheme }) {
|
|
33
|
+
return (
|
|
34
|
+
<PhoneFrame scheme={scheme} width={320} height={180}>
|
|
35
|
+
{['Design', 'Platform reliability and release operations', undefined].map((workspace) => (
|
|
36
|
+
<View key={workspace ?? 'standalone'} style={previewStyles.header}>
|
|
37
|
+
<Button variant="ghost" size="icon" accessibilityLabel="Back" onPress={noop}>
|
|
38
|
+
<View style={previewStyles.back}>
|
|
39
|
+
<ChevronRightIcon color="hi" />
|
|
40
|
+
</View>
|
|
41
|
+
</Button>
|
|
42
|
+
<View style={previewStyles.center}>
|
|
43
|
+
<View style={previewStyles.row}>
|
|
44
|
+
<View style={previewStyles.avatar}>
|
|
45
|
+
<Text style={previewStyles.initial}>P</Text>
|
|
46
|
+
</View>
|
|
47
|
+
<Text style={previewStyles.title} numberOfLines={1}>
|
|
48
|
+
Session
|
|
49
|
+
</Text>
|
|
50
|
+
{workspace ? (
|
|
51
|
+
<Text accessibilityLabel={`Workspace: ${workspace}`} style={previewStyles.workspace} numberOfLines={1}>
|
|
52
|
+
{`· ${workspace}`}
|
|
53
|
+
</Text>
|
|
54
|
+
) : null}
|
|
55
|
+
</View>
|
|
56
|
+
<View style={previewStyles.row}>
|
|
57
|
+
<Text style={previewStyles.agent} numberOfLines={1}>
|
|
58
|
+
Ponytail ·
|
|
59
|
+
</Text>
|
|
60
|
+
<Text style={previewStyles.meta} numberOfLines={1}>
|
|
61
|
+
ready when you are
|
|
62
|
+
</Text>
|
|
63
|
+
</View>
|
|
64
|
+
</View>
|
|
65
|
+
<Button variant="ghost" size="icon" accessibilityLabel="Activity" onPress={noop}>
|
|
66
|
+
<ActivityIcon color="hi" />
|
|
67
|
+
</Button>
|
|
68
|
+
</View>
|
|
69
|
+
))}
|
|
70
|
+
</PhoneFrame>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const WorkspaceHeaderDark = { render: () => <WorkspaceHeaderPreview scheme="dark" /> };
|
|
75
|
+
export const WorkspaceHeaderLight = { render: () => <WorkspaceHeaderPreview scheme="light" /> };
|
|
76
|
+
|
|
77
|
+
const previewStyles = StyleSheet.create((theme) => {
|
|
78
|
+
const meta = {
|
|
79
|
+
fontFamily: fontOf(theme.fontFamily.sans),
|
|
80
|
+
fontSize: theme.fontSize.sm,
|
|
81
|
+
lineHeight: theme.lineHeight.sm,
|
|
82
|
+
color: theme.colors.dim,
|
|
83
|
+
flexShrink: 1,
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
header: {
|
|
87
|
+
minHeight: 60,
|
|
88
|
+
flexDirection: 'row',
|
|
89
|
+
alignItems: 'center',
|
|
90
|
+
paddingHorizontal: theme.spacing(4),
|
|
91
|
+
gap: theme.spacing(2),
|
|
92
|
+
backgroundColor: theme.colors.rail,
|
|
93
|
+
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
94
|
+
borderBottomColor: theme.colors['border-soft'],
|
|
95
|
+
},
|
|
96
|
+
center: { flex: 1, minWidth: 0, alignItems: 'center' },
|
|
97
|
+
row: { flexDirection: 'row', alignItems: 'center', maxWidth: '100%', gap: theme.spacing(1.5) },
|
|
98
|
+
back: { transform: [{ rotate: '180deg' }] },
|
|
99
|
+
avatar: {
|
|
100
|
+
width: 20,
|
|
101
|
+
height: 20,
|
|
102
|
+
alignItems: 'center',
|
|
103
|
+
justifyContent: 'center',
|
|
104
|
+
borderRadius: theme.borderRadius.full,
|
|
105
|
+
backgroundColor: theme.colors['tint-green'],
|
|
106
|
+
},
|
|
107
|
+
initial: { ...meta, fontSize: theme.fontSize['2xs'], color: theme.colors.green },
|
|
108
|
+
title: {
|
|
109
|
+
...meta,
|
|
110
|
+
fontSize: theme.fontSize.lg,
|
|
111
|
+
lineHeight: theme.lineHeight.lg,
|
|
112
|
+
fontWeight: theme.fontWeight.semibold,
|
|
113
|
+
color: theme.colors.hi,
|
|
114
|
+
},
|
|
115
|
+
agent: { ...meta, color: theme.colors.hi },
|
|
116
|
+
workspace: { ...meta, maxWidth: '60%' },
|
|
117
|
+
meta,
|
|
118
|
+
};
|
|
119
|
+
});
|
|
29
120
|
export const Playground = {
|
|
30
121
|
render: () => (
|
|
31
122
|
<PoNativeProvider>
|
|
@@ -390,17 +390,28 @@ export function createNativeBundleUpdates(options: {
|
|
|
390
390
|
assertActive();
|
|
391
391
|
return state.generation?.catalog;
|
|
392
392
|
},
|
|
393
|
-
async check(
|
|
393
|
+
async check(
|
|
394
|
+
body: unknown,
|
|
395
|
+
{ signal, reoffer = false }: { signal?: AbortSignal; reoffer?: boolean } = {},
|
|
396
|
+
): Promise<{ catalog?: NativeBundleCatalog; update?: NativeBundleUpdateChoice }> {
|
|
394
397
|
const state = await selection;
|
|
398
|
+
signal?.throwIfAborted();
|
|
395
399
|
const localEpoch = ++epoch;
|
|
396
400
|
const admitted = (state.checkEpoch ?? 0) + 1;
|
|
397
401
|
state.checkEpoch = admitted;
|
|
398
402
|
const current = () => {
|
|
399
403
|
assertActive();
|
|
404
|
+
signal?.throwIfAborted();
|
|
400
405
|
if (epoch !== localEpoch || state.checkEpoch !== admitted)
|
|
401
406
|
throw new Error('Native catalog check was replaced.');
|
|
402
407
|
};
|
|
403
408
|
const candidate: Generation = { catalog: catalogOf(body), modules: [] };
|
|
409
|
+
// A matching catalog cannot change which verified bytes the current process is using.
|
|
410
|
+
if (state.generation && JSON.stringify(state.generation.catalog) === JSON.stringify(candidate.catalog)) {
|
|
411
|
+
current();
|
|
412
|
+
state.offeredIdentity = state.identity;
|
|
413
|
+
return {};
|
|
414
|
+
}
|
|
404
415
|
for (const descriptor of descriptors(candidate.catalog))
|
|
405
416
|
for (const path of paths(descriptor)) {
|
|
406
417
|
current();
|
|
@@ -459,7 +470,7 @@ export function createNativeBundleUpdates(options: {
|
|
|
459
470
|
state.generation = refreshed;
|
|
460
471
|
return { catalog: refreshed.catalog };
|
|
461
472
|
}
|
|
462
|
-
if (state.pendingIdentity === nextIdentity || alreadyOffered) return {};
|
|
473
|
+
if (!reoffer && (state.pendingIdentity === nextIdentity || alreadyOffered)) return {};
|
|
463
474
|
state.offeredBy = owner;
|
|
464
475
|
let decision: Promise<void> | undefined;
|
|
465
476
|
const commit = async (defer: boolean) => {
|
|
@@ -507,7 +518,9 @@ export function createNativeBundleUpdates(options: {
|
|
|
507
518
|
if (!state.generation) return undefined;
|
|
508
519
|
// A new scope may use only modules already selected by this generation. In particular,
|
|
509
520
|
// a pending UI entry must never be fetched or evaluated through the session path.
|
|
510
|
-
|
|
521
|
+
// The pinned hub session contract omits uiEntry. Only the host mount selects the UI in that case.
|
|
522
|
+
if (descriptor.uiEntry !== undefined && descriptor.uiEntry !== state.generation.catalog.nativeHost?.uiEntry)
|
|
523
|
+
return undefined;
|
|
511
524
|
const admitted = paths(descriptor);
|
|
512
525
|
for (const module of state.generation.modules) {
|
|
513
526
|
const loaded = await verify(module);
|
|
@@ -521,7 +521,8 @@ export async function reconnect(
|
|
|
521
521
|
);
|
|
522
522
|
options.signal?.addEventListener('abort', cancel, { once: true });
|
|
523
523
|
});
|
|
524
|
-
const
|
|
524
|
+
const deadline = AbortSignal.timeout(8_000);
|
|
525
|
+
const signal = AbortSignal.any([deadline, ...(options.signal ? [options.signal] : [])]);
|
|
525
526
|
let signingIn = true;
|
|
526
527
|
const boundedFetch: typeof fetch = (input, init) => fetcher(input, signingIn ? { ...init, signal } : init);
|
|
527
528
|
try {
|
|
@@ -534,11 +535,13 @@ export async function reconnect(
|
|
|
534
535
|
isLanTlsTrustError(error) ||
|
|
535
536
|
isRelayTrustError(error) ||
|
|
536
537
|
error instanceof DeviceSignInError ||
|
|
537
|
-
options.signal?.aborted
|
|
538
|
-
options.giveUp?.() === true ||
|
|
539
|
-
attempt === attemptsAt.length - 1
|
|
538
|
+
options.signal?.aborted
|
|
540
539
|
)
|
|
541
540
|
throw error;
|
|
541
|
+
if (options.giveUp?.() === true || attempt === attemptsAt.length - 1) {
|
|
542
|
+
if (deadline.aborted) throw new Error('Reconnecting to this computer timed out. Try again.', { cause: error });
|
|
543
|
+
throw error;
|
|
544
|
+
}
|
|
542
545
|
}
|
|
543
546
|
}
|
|
544
547
|
throw new Error('Could not reconnect.');
|
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
// Binds nativeApiTransport to the sealed, step-up aware shell transport.
|
|
27
27
|
import { apiTransportForHost } from '../apiTransport';
|
|
28
28
|
import '../byteCodec';
|
|
29
|
-
import { readSettingsConfig, writeSettingsValues } from '../settingsApi';
|
|
30
29
|
|
|
31
30
|
/**
|
|
32
31
|
* The cockpit rail's session and workspace requests, over the phone's sealed channel. The same
|
|
@@ -288,38 +287,21 @@ export async function addCoordinator(
|
|
|
288
287
|
return { sessionId: body.sessionId, created: body.created };
|
|
289
288
|
}
|
|
290
289
|
|
|
291
|
-
const PRESET_KEY = 'selection.preset';
|
|
292
|
-
|
|
293
290
|
/**
|
|
294
|
-
* First run on the chosen computer: the
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
* its own. Answers the qualified session id.
|
|
291
|
+
* First run on the chosen computer: the home coordinator as the chosen Po, or the one it already has.
|
|
292
|
+
* As the web's finishOnboarding, without its layout: the phone has its own. Answers the qualified
|
|
293
|
+
* session id.
|
|
298
294
|
*/
|
|
299
295
|
export async function openFirstSession(
|
|
300
296
|
hostId: string,
|
|
301
|
-
po: Pick<StarterPo, 'alias' | 'name'
|
|
297
|
+
po: Pick<StarterPo, 'alias' | 'name'>,
|
|
302
298
|
): Promise<{ sessionId: string } | { error: string }> {
|
|
303
|
-
const before = await readSettingsConfig([PRESET_KEY], undefined, hostId);
|
|
304
|
-
if ('error' in before) return before;
|
|
305
|
-
const previous = before.config.values[PRESET_KEY];
|
|
306
|
-
const write = (value: string | null, expectedHash: string) =>
|
|
307
|
-
writeSettingsValues(
|
|
308
|
-
{ repoRoot: '', scope: 'host', edits: [{ keyPath: PRESET_KEY.split('.'), value }], expectedHash },
|
|
309
|
-
undefined,
|
|
310
|
-
hostId,
|
|
311
|
-
);
|
|
312
|
-
const selected = await write(po.preset, before.config.hashes.host);
|
|
313
|
-
if ('error' in selected) return selected;
|
|
314
299
|
const { ok, body, status } = await rootRequest(
|
|
315
300
|
'/api/coordinators/home',
|
|
316
301
|
{ method: 'POST', headers: JSON_BODY, body: JSON.stringify({ profile: po.alias, name: po.name }) },
|
|
317
302
|
hostId,
|
|
318
303
|
);
|
|
319
|
-
if (!ok || !isRecord(body) || typeof body.sessionId !== 'string' || !body.sessionId)
|
|
320
|
-
await write(previous?.origin === 'host' ? (previous.value ?? null) : null, selected.config.hashes.host);
|
|
321
|
-
return errorOf(body, status);
|
|
322
|
-
}
|
|
304
|
+
if (!ok || !isRecord(body) || typeof body.sessionId !== 'string' || !body.sessionId) return errorOf(body, status);
|
|
323
305
|
return { sessionId: qualifyHostId(hostId, body.sessionId) };
|
|
324
306
|
}
|
|
325
307
|
|