@agimon-ai/po-native 0.0.1-alpha.7 → 0.0.1-alpha.8

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.7",
3
+ "version": "0.0.1-alpha.8",
4
4
  "description": "Po for iOS and Android",
5
5
  "homepage": "https://agimon.ai",
6
6
  "bugs": {
@@ -29,15 +29,15 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@agimon-ai/po-core": "0.0.0-alpha.127",
33
- "@agimon-ai/po-expo-signing": "0.0.1-alpha.7",
34
- "@agimon-ai/po-identity": "0.0.2-alpha.74",
35
- "@agimon-ai/po-native-components": "0.0.0-alpha.127",
36
- "@agimon-ai/po-template-advanced": "0.0.0-alpha.127",
37
- "@agimon-ai/po-voice": "0.0.0-alpha.127",
38
- "@agimon-ai/po-web-components": "0.0.0-alpha.127",
39
- "@agimon-ai/po-web-dashboard": "0.0.0-alpha.127",
40
- "@agimon-ai/po-web-security": "0.0.0-alpha.127",
32
+ "@agimon-ai/po-core": "0.0.0-alpha.128",
33
+ "@agimon-ai/po-expo-signing": "0.0.1-alpha.8",
34
+ "@agimon-ai/po-identity": "0.0.2-alpha.75",
35
+ "@agimon-ai/po-native-components": "0.0.0-alpha.128",
36
+ "@agimon-ai/po-template-advanced": "0.0.0-alpha.128",
37
+ "@agimon-ai/po-voice": "0.0.0-alpha.128",
38
+ "@agimon-ai/po-web-components": "0.0.0-alpha.128",
39
+ "@agimon-ai/po-web-dashboard": "0.0.0-alpha.128",
40
+ "@agimon-ai/po-web-security": "0.0.0-alpha.128",
41
41
  "@better-auth/expo": "1.7.12",
42
42
  "@config-plugins/react-native-webrtc": "15.0.2",
43
43
  "@earendil-works/chord": "1.5.0",
package/src/app/App.tsx CHANGED
@@ -75,6 +75,7 @@ import {
75
75
  HOST_SLOTS,
76
76
  globalSlotFills,
77
77
  webPluginRegistryRevision,
78
+ globalPluginProviders,
78
79
  setUiTraceSink,
79
80
  traceStore,
80
81
  useRenderTrace,
@@ -545,7 +546,13 @@ function SessionRoute({
545
546
  nativeAudio,
546
547
  nativeRealtime,
547
548
  runNativeVoice,
549
+ composer,
548
550
  }: NativeStackScreenProps<Routes, 'Session'> & {
551
+ composer: {
552
+ text: Store<Record<string, string>>;
553
+ captures: Store<Record<string, ComposerCapture[]>>;
554
+ contexts: Store<Record<string, WebPluginContextItem[]>>;
555
+ };
549
556
  allowGlobalActions: boolean;
550
557
  nativeAudio: ReturnType<typeof createNativeAudioSession>;
551
558
  nativeRealtime: NativeRealtimeHost;
@@ -575,25 +582,23 @@ function SessionRoute({
575
582
  const openSession = useOpenSession();
576
583
  const openWorkspace = useOpenWorkspace(splitHostId(sessionId)?.hostId);
577
584
  const inner = useRef<NativeStackNavigationProp<SessionRoutes> | null>(null);
578
- const [drafts] = useState(() => traceStore('composerDrafts', new Store<Record<string, string>>({})));
585
+ const drafts = composer.text;
579
586
  const setDrafts = (update: (current: Record<string, string>) => Record<string, string>) => drafts.setState(update);
580
- const [captureDrafts, setCaptureDrafts] = useState<Record<string, ComposerCapture[]>>({});
581
- const captureRefs = useRef<Record<string, ComposerCapture[]>>({});
587
+ const captureDrafts = useStore(composer.captures);
582
588
  const captures = captureDrafts[sessionId] ?? [];
583
589
  const capturesRef = useMemo(
584
590
  () => ({
585
591
  get current() {
586
- return captureRefs.current[sessionId] ?? [];
592
+ return composer.captures.state[sessionId] ?? [];
587
593
  },
588
594
  set current(value: ComposerCapture[]) {
589
- captureRefs.current[sessionId] = value;
595
+ composer.captures.setState((current) => ({ ...current, [sessionId]: value }));
590
596
  },
591
597
  }),
592
- [sessionId],
598
+ [sessionId, composer],
593
599
  );
594
- const setCaptures = (value: ComposerCapture[]) => setCaptureDrafts((current) => ({ ...current, [sessionId]: value }));
595
600
  const richRenderers = useMemo(createRichActivityRenderers, []);
596
- const [contexts, setContexts] = useState<Record<string, WebPluginContextItem[]>>({});
601
+ const contexts = useStore(composer.contexts);
597
602
  const [, registryChanged] = useState(0);
598
603
  useEffect(() => subscribeWebPluginRegistry(() => registryChanged((value) => value + 1)), []);
599
604
  useEffect(() => () => dropTransientTabs(ownerSessionId), [ownerSessionId]);
@@ -790,7 +795,6 @@ function SessionRoute({
790
795
  attachComposerCapture: (capture) => {
791
796
  const staged = stageNativeCapture(capturesRef.current, contexts[sessionId] ?? [], capture);
792
797
  capturesRef.current = staged;
793
- setCaptures(staged);
794
798
  },
795
799
  openSession,
796
800
  openWorkspace,
@@ -820,7 +824,7 @@ function SessionRoute({
820
824
  />
821
825
  ),
822
826
  attachComposerContext: (item) =>
823
- setContexts((current) => ({
827
+ composer.contexts.setState((current) => ({
824
828
  ...current,
825
829
  [sessionId]: [
826
830
  ...(current[sessionId] ?? []).filter((entry) => entry.source !== item.source || entry.id !== item.id),
@@ -833,8 +837,7 @@ function SessionRoute({
833
837
  capturesRef.current = capturesRef.current.filter(
834
838
  (capture) => capture.context.source !== source || capture.context.id !== id,
835
839
  );
836
- setCaptures(capturesRef.current);
837
- setContexts((current) => ({
840
+ composer.contexts.setState((current) => ({
838
841
  ...current,
839
842
  [sessionId]: (current[sessionId] ?? []).filter((item) => item.source !== source || item.id !== id),
840
843
  }));
@@ -883,8 +886,7 @@ function SessionRoute({
883
886
  )
884
887
  return false;
885
888
  capturesRef.current = [];
886
- setCaptures([]);
887
- setContexts((current) => ({ ...current, [sessionId]: [] }));
889
+ composer.contexts.setState((current) => ({ ...current, [sessionId]: [] }));
888
890
  markSentFromPhone();
889
891
  return true;
890
892
  }}
@@ -2444,7 +2446,20 @@ function ConnectFirst({ restore }: { restore?: { onRestore: () => void; busy: bo
2444
2446
  );
2445
2447
  }
2446
2448
 
2449
+ function GlobalPluginProviders({ children }: { children: ReactNode }) {
2450
+ useSyncExternalStore(subscribeWebPluginRegistry, webPluginRegistryRevision);
2451
+ return globalPluginProviders().reduceRight<ReactNode>(
2452
+ (content, { pluginId, provider: Provider }) => <Provider key={pluginId}>{content}</Provider>,
2453
+ <PoNativeProvider>{children}</PoNativeProvider>,
2454
+ );
2455
+ }
2456
+
2447
2457
  export function App({ nativeHost }: { nativeHost?: (sessionId: string) => NativeSlotHost } = {}) {
2458
+ const [composer] = useState(() => ({
2459
+ text: traceStore('composerDrafts', new Store<Record<string, string>>({})),
2460
+ captures: new Store<Record<string, ComposerCapture[]>>({}),
2461
+ contexts: new Store<Record<string, WebPluginContextItem[]>>({}),
2462
+ }));
2448
2463
  const [nativeAudio] = useState(createNativeAudioSession);
2449
2464
  const [nativeRealtime] = useState(
2450
2465
  () =>
@@ -2503,6 +2518,19 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
2503
2518
  const [trustLoaded, setTrustLoaded] = useState(false);
2504
2519
  const [navigationReady, setNavigationReady] = useState(false);
2505
2520
 
2521
+ useEffect(() => {
2522
+ if (!trustLoaded) return;
2523
+ const hostIds = new Set(hostStates.map(({ host }) => host.id));
2524
+ const retain = <T,>(drafts: Record<string, T>): Record<string, T> => {
2525
+ const entries = Object.entries(drafts).filter(([sessionId]) => {
2526
+ const hostId = splitHostId(sessionId)?.hostId;
2527
+ return hostId === undefined || hostIds.has(hostId);
2528
+ });
2529
+ return entries.length === Object.keys(drafts).length ? drafts : Object.fromEntries(entries);
2530
+ };
2531
+ for (const store of Object.values(composer)) store.setState(retain);
2532
+ }, [hostStates, trustLoaded, composer]);
2533
+
2506
2534
  useEffect(loadSentFromPhone, []);
2507
2535
  useEffect(loadAppearance, []);
2508
2536
  useEffect(loadOtherWorkspacesOpen, []);
@@ -2535,7 +2563,7 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
2535
2563
  const errors = states.flatMap((state) => (state.error ? [state.error] : []));
2536
2564
  setRestoreReason(errors.join('\n') || undefined);
2537
2565
  setSettingsError(errors.join('\n') || undefined);
2538
- if (!loaded && states.length > 1 && states.some((state) => state.runtime)) setPhase('ready');
2566
+ if (!loaded && states.some((state) => state.runtime)) setPhase('ready');
2539
2567
  if (loaded) setPhase(states.length === 1 && !states[0].runtime ? 'pairing' : states.length ? 'ready' : 'pairing');
2540
2568
  };
2541
2569
  const manager = createHostRuntimes({
@@ -2543,6 +2571,19 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
2543
2571
  activity: (hostId, owner, state) => {
2544
2572
  if (mounted) setActivityLoads((current) => ({ ...current, [`${hostId}:${owner}`]: state }));
2545
2573
  },
2574
+ onBundleUpdate(host, choice) {
2575
+ if (!mounted) return;
2576
+ const apply = (action: () => Promise<void>) => {
2577
+ void action().catch((error: unknown) => {
2578
+ if (mounted)
2579
+ Alert.alert('Update unavailable', messageOf(error, 'Your current version is still installed.'));
2580
+ });
2581
+ };
2582
+ Alert.alert('Po update available', `An update from ${host.displayName || host.label} is ready.`, [
2583
+ { text: 'Next app start', onPress: () => apply(choice.installOnNextStart) },
2584
+ { text: 'Install now', onPress: () => apply(choice.installNow) },
2585
+ ]);
2586
+ },
2546
2587
  });
2547
2588
  hosts.current = manager;
2548
2589
  void (async () => {
@@ -2736,7 +2777,7 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
2736
2777
  ) : undefined;
2737
2778
  return (
2738
2779
  <SafeAreaProvider>
2739
- <PoNativeProvider>
2780
+ <GlobalPluginProviders>
2740
2781
  <KeyboardProvider>
2741
2782
  <NavigationContainer
2742
2783
  ref={navigation}
@@ -2965,6 +3006,7 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
2965
3006
  {...props}
2966
3007
  nativeHost={nativeHost}
2967
3008
  nativeAudio={nativeAudio}
3009
+ composer={composer}
2968
3010
  nativeRealtime={nativeRealtime}
2969
3011
  runNativeVoice={runNativeVoice}
2970
3012
  allowGlobalActions={allowGlobalActions}
@@ -3104,7 +3146,7 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
3104
3146
  />
3105
3147
  </NavigationContainer>
3106
3148
  </KeyboardProvider>
3107
- </PoNativeProvider>
3149
+ </GlobalPluginProviders>
3108
3150
  </SafeAreaProvider>
3109
3151
  );
3110
3152
  }
@@ -10,6 +10,7 @@ import {
10
10
  } from '@agimon-ai/po-web-dashboard/core';
11
11
 
12
12
  import { expoBundleCacheStorage } from '../services/bundleCache';
13
+ import { purgeNativeBundleUpdates, type NativeBundleUpdateChoice } from '../services/bundleUpdates';
13
14
  import { type CloudHostRecord, isCloudHost, removeCloudHost, renameCloudHost } from '../services/cloudHosts';
14
15
  import {
15
16
  currentSession,
@@ -22,6 +23,7 @@ import {
22
23
  type TrustedSession,
23
24
  } from '../services/deviceTrust';
24
25
  import { createHostLinkBroker, HostLinkApiUnavailable } from '../services/hostLinkBroker';
26
+ import { forgetHostModules } from '../services/hostModules';
25
27
  import { hostSnapshots } from '../services/hostSnapshots';
26
28
  import { startNativePush, startPushEnrollment, unregisterNativePush } from '../services/nativePush';
27
29
  import { parsePairingUrl } from '../services/pairing';
@@ -68,6 +70,7 @@ export function createHostRuntimes(
68
70
  options: {
69
71
  changed?: (states: readonly HostRuntimeState[]) => void;
70
72
  activity?: (hostId: string, owner: string, state: ActivityLoadState) => void;
73
+ onBundleUpdate?: (host: HostRecord, choice: NativeBundleUpdateChoice) => void;
71
74
  } = {},
72
75
  ) {
73
76
  const entries = new Map<string, HostRuntimeEntry>();
@@ -118,7 +121,7 @@ export function createHostRuntimes(
118
121
  );
119
122
  options.changed?.(snapshot());
120
123
  };
121
- const stopEntry = (entry: HostRuntimeEntry) => {
124
+ const stopEntry = (entry: HostRuntimeEntry, preserveGlobal = false) => {
122
125
  entry.controller.abort();
123
126
  for (const [key, operation] of repairs)
124
127
  if (operation.left === entry || operation.right === entry) {
@@ -126,7 +129,7 @@ export function createHostRuntimes(
126
129
  repairs.delete(key);
127
130
  }
128
131
  entry.push?.stop();
129
- entry.runtime?.close();
132
+ entry.runtime?.close({ preserveGlobal });
130
133
  };
131
134
 
132
135
  /** Cloud hosts poll and focus over cookie admission, and enroll push with the person's account. */
@@ -168,7 +171,8 @@ export function createHostRuntimes(
168
171
  if (session && (session.hostId !== host.id || session.origin !== host.origin))
169
172
  throw new Error('The trusted session belongs to another host.');
170
173
  const previous = entries.get(host.id);
171
- if (previous) stopEntry(previous);
174
+ if (previous)
175
+ stopEntry(previous, !isCloudHost(previous.host) && previous.host.signer.publicKey === host.signer.publicKey);
172
176
  const entry: HostRuntimeEntry = { host, status: 'connecting', controller: new AbortController() };
173
177
  entries.set(host.id, entry);
174
178
  const saved = hostSnapshots.open(host).read();
@@ -184,11 +188,14 @@ export function createHostRuntimes(
184
188
  !forgetting.has(host.id) &&
185
189
  scan?.hostId !== host.id;
186
190
  try {
187
- const trusted =
188
- session ?? (await reconnect(host.origin, fetch, { hostId: host.id, signal: entry.controller.signal }));
189
- if (!active()) throw new Error('The host connection was replaced.');
191
+ const trustedSession =
192
+ session ??
193
+ reconnect(host.origin, fetch, { hostId: host.id, signal: entry.controller.signal }).then((trusted) => {
194
+ if (!active()) throw new Error('The host connection was replaced.');
195
+ return trusted;
196
+ });
190
197
  const runtime = startLiveRuntime(
191
- trusted,
198
+ trustedSession,
192
199
  host,
193
200
  () => {
194
201
  if (!active()) return;
@@ -221,6 +228,9 @@ export function createHostRuntimes(
221
228
  entry.pluginCompatibility = issues;
222
229
  changed();
223
230
  },
231
+ onBundleUpdate(choice) {
232
+ if (active()) options.onBundleUpdate?.(host, choice);
233
+ },
224
234
  onUpdateRequired() {
225
235
  if (!active()) return;
226
236
  entry.status = 'update_required';
@@ -229,9 +239,12 @@ export function createHostRuntimes(
229
239
  },
230
240
  );
231
241
  entry.runtime = runtime;
242
+ runtime.open(focused !== null && splitHostId(focused)?.hostId === host.id ? focused : null);
243
+ changed();
244
+ const trusted = await trustedSession;
245
+ if (!active()) throw new Error('The host connection was replaced.');
232
246
  if (!saved) entry.status = 'connected';
233
247
  entry.push = startNativePush(trusted, requestPermission, host.id);
234
- runtime.open(focused !== null && splitHostId(focused)?.hostId === host.id ? focused : null);
235
248
  changed();
236
249
  repairLinks();
237
250
  return runtime;
@@ -339,8 +352,9 @@ export function createHostRuntimes(
339
352
  return;
340
353
  }
341
354
  const pending = entries.get(hostId);
342
- if (pending && !pending.runtime) {
355
+ if (pending && !pending.push) {
343
356
  pending.controller.abort();
357
+ pending.runtime?.close();
344
358
  pending.status = 'disconnected';
345
359
  changed();
346
360
  }
@@ -365,6 +379,8 @@ export function createHostRuntimes(
365
379
  resetNativeTemplateChoice(hostId);
366
380
  if (focused !== null && splitHostId(focused)?.hostId === hostId) focused = null;
367
381
  changed();
382
+ forgetHostModules(hostId);
383
+ purgeNativeBundleUpdates(hostId);
368
384
  await expoBundleCacheStorage(hostId).clear();
369
385
  } finally {
370
386
  forgetting.delete(hostId);