@agimon-ai/po-native 0.0.1-alpha.6 → 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.6",
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.126",
33
- "@agimon-ai/po-expo-signing": "0.0.1-alpha.6",
34
- "@agimon-ai/po-identity": "0.0.2-alpha.73",
35
- "@agimon-ai/po-native-components": "0.0.0-alpha.126",
36
- "@agimon-ai/po-template-advanced": "0.0.0-alpha.126",
37
- "@agimon-ai/po-voice": "0.0.0-alpha.126",
38
- "@agimon-ai/po-web-components": "0.0.0-alpha.126",
39
- "@agimon-ai/po-web-dashboard": "0.0.0-alpha.126",
40
- "@agimon-ai/po-web-security": "0.0.0-alpha.126",
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
@@ -44,6 +44,7 @@ import {
44
44
  pluginSettingsPanels,
45
45
  applySessionRemoved,
46
46
  applySessionUpsert,
47
+ sessionMoveTarget,
47
48
  applyWorkspaceRemoved,
48
49
  applyWorkspaceUpsert,
49
50
  renameSession,
@@ -74,6 +75,7 @@ import {
74
75
  HOST_SLOTS,
75
76
  globalSlotFills,
76
77
  webPluginRegistryRevision,
78
+ globalPluginProviders,
77
79
  setUiTraceSink,
78
80
  traceStore,
79
81
  useRenderTrace,
@@ -205,6 +207,7 @@ import {
205
207
  renameSessionGroup,
206
208
  requestWithStepUp,
207
209
  restartSession,
210
+ moveSession,
208
211
  type ResumeSource,
209
212
  searchDirectories,
210
213
  setSessionGroups,
@@ -543,7 +546,13 @@ function SessionRoute({
543
546
  nativeAudio,
544
547
  nativeRealtime,
545
548
  runNativeVoice,
549
+ composer,
546
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
+ };
547
556
  allowGlobalActions: boolean;
548
557
  nativeAudio: ReturnType<typeof createNativeAudioSession>;
549
558
  nativeRealtime: NativeRealtimeHost;
@@ -573,25 +582,23 @@ function SessionRoute({
573
582
  const openSession = useOpenSession();
574
583
  const openWorkspace = useOpenWorkspace(splitHostId(sessionId)?.hostId);
575
584
  const inner = useRef<NativeStackNavigationProp<SessionRoutes> | null>(null);
576
- const [drafts] = useState(() => traceStore('composerDrafts', new Store<Record<string, string>>({})));
585
+ const drafts = composer.text;
577
586
  const setDrafts = (update: (current: Record<string, string>) => Record<string, string>) => drafts.setState(update);
578
- const [captureDrafts, setCaptureDrafts] = useState<Record<string, ComposerCapture[]>>({});
579
- const captureRefs = useRef<Record<string, ComposerCapture[]>>({});
587
+ const captureDrafts = useStore(composer.captures);
580
588
  const captures = captureDrafts[sessionId] ?? [];
581
589
  const capturesRef = useMemo(
582
590
  () => ({
583
591
  get current() {
584
- return captureRefs.current[sessionId] ?? [];
592
+ return composer.captures.state[sessionId] ?? [];
585
593
  },
586
594
  set current(value: ComposerCapture[]) {
587
- captureRefs.current[sessionId] = value;
595
+ composer.captures.setState((current) => ({ ...current, [sessionId]: value }));
588
596
  },
589
597
  }),
590
- [sessionId],
598
+ [sessionId, composer],
591
599
  );
592
- const setCaptures = (value: ComposerCapture[]) => setCaptureDrafts((current) => ({ ...current, [sessionId]: value }));
593
600
  const richRenderers = useMemo(createRichActivityRenderers, []);
594
- const [contexts, setContexts] = useState<Record<string, WebPluginContextItem[]>>({});
601
+ const contexts = useStore(composer.contexts);
595
602
  const [, registryChanged] = useState(0);
596
603
  useEffect(() => subscribeWebPluginRegistry(() => registryChanged((value) => value + 1)), []);
597
604
  useEffect(() => () => dropTransientTabs(ownerSessionId), [ownerSessionId]);
@@ -788,7 +795,6 @@ function SessionRoute({
788
795
  attachComposerCapture: (capture) => {
789
796
  const staged = stageNativeCapture(capturesRef.current, contexts[sessionId] ?? [], capture);
790
797
  capturesRef.current = staged;
791
- setCaptures(staged);
792
798
  },
793
799
  openSession,
794
800
  openWorkspace,
@@ -818,7 +824,7 @@ function SessionRoute({
818
824
  />
819
825
  ),
820
826
  attachComposerContext: (item) =>
821
- setContexts((current) => ({
827
+ composer.contexts.setState((current) => ({
822
828
  ...current,
823
829
  [sessionId]: [
824
830
  ...(current[sessionId] ?? []).filter((entry) => entry.source !== item.source || entry.id !== item.id),
@@ -831,8 +837,7 @@ function SessionRoute({
831
837
  capturesRef.current = capturesRef.current.filter(
832
838
  (capture) => capture.context.source !== source || capture.context.id !== id,
833
839
  );
834
- setCaptures(capturesRef.current);
835
- setContexts((current) => ({
840
+ composer.contexts.setState((current) => ({
836
841
  ...current,
837
842
  [sessionId]: (current[sessionId] ?? []).filter((item) => item.source !== source || item.id !== id),
838
843
  }));
@@ -881,8 +886,7 @@ function SessionRoute({
881
886
  )
882
887
  return false;
883
888
  capturesRef.current = [];
884
- setCaptures([]);
885
- setContexts((current) => ({ ...current, [sessionId]: [] }));
889
+ composer.contexts.setState((current) => ({ ...current, [sessionId]: [] }));
886
890
  markSentFromPhone();
887
891
  return true;
888
892
  }}
@@ -1613,6 +1617,20 @@ function SessionsRoute({
1613
1617
  // the cockpit. Renaming another session needs a hub route; until then it is a no-op there.
1614
1618
  whenConnected(sessionId, () => renameSession(trimmed, sessionId));
1615
1619
  },
1620
+ async moveSession(sessionId, workspaceId) {
1621
+ if (!canMutate(sessionId) || !canMutate(workspaceId)) return unavailable;
1622
+ const summary = sessionsStore.state.byId[sessionId]?.summary;
1623
+ const target = summary
1624
+ ? sessionMoveTarget(summary, workspacesStore.state.byId, workspacesStore.state.order)
1625
+ : undefined;
1626
+ if (!target || target.blocked || !target.destinations.some((workspace) => workspace.id === workspaceId))
1627
+ return { error: 'This session cannot move to that workspace now.' };
1628
+ const result = await moveSession(sessionId, workspaceId);
1629
+ if ('error' in result) return result;
1630
+ if (result.session) applySessionUpsert({ session: result.session }, splitHostId(sessionId)?.hostId);
1631
+ // SessionRuntime rebinds the restarted reference; the hub upsert retains the qualified ID.
1632
+ return undefined;
1633
+ },
1616
1634
  restartSession(sessionId) {
1617
1635
  if (!canMutate(sessionId)) return;
1618
1636
  void restartSession(sessionId);
@@ -2428,7 +2446,20 @@ function ConnectFirst({ restore }: { restore?: { onRestore: () => void; busy: bo
2428
2446
  );
2429
2447
  }
2430
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
+
2431
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
+ }));
2432
2463
  const [nativeAudio] = useState(createNativeAudioSession);
2433
2464
  const [nativeRealtime] = useState(
2434
2465
  () =>
@@ -2487,6 +2518,19 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
2487
2518
  const [trustLoaded, setTrustLoaded] = useState(false);
2488
2519
  const [navigationReady, setNavigationReady] = useState(false);
2489
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
+
2490
2534
  useEffect(loadSentFromPhone, []);
2491
2535
  useEffect(loadAppearance, []);
2492
2536
  useEffect(loadOtherWorkspacesOpen, []);
@@ -2519,7 +2563,7 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
2519
2563
  const errors = states.flatMap((state) => (state.error ? [state.error] : []));
2520
2564
  setRestoreReason(errors.join('\n') || undefined);
2521
2565
  setSettingsError(errors.join('\n') || undefined);
2522
- if (!loaded && states.length > 1 && states.some((state) => state.runtime)) setPhase('ready');
2566
+ if (!loaded && states.some((state) => state.runtime)) setPhase('ready');
2523
2567
  if (loaded) setPhase(states.length === 1 && !states[0].runtime ? 'pairing' : states.length ? 'ready' : 'pairing');
2524
2568
  };
2525
2569
  const manager = createHostRuntimes({
@@ -2527,6 +2571,19 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
2527
2571
  activity: (hostId, owner, state) => {
2528
2572
  if (mounted) setActivityLoads((current) => ({ ...current, [`${hostId}:${owner}`]: state }));
2529
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
+ },
2530
2587
  });
2531
2588
  hosts.current = manager;
2532
2589
  void (async () => {
@@ -2720,7 +2777,7 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
2720
2777
  ) : undefined;
2721
2778
  return (
2722
2779
  <SafeAreaProvider>
2723
- <PoNativeProvider>
2780
+ <GlobalPluginProviders>
2724
2781
  <KeyboardProvider>
2725
2782
  <NavigationContainer
2726
2783
  ref={navigation}
@@ -2949,6 +3006,7 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
2949
3006
  {...props}
2950
3007
  nativeHost={nativeHost}
2951
3008
  nativeAudio={nativeAudio}
3009
+ composer={composer}
2952
3010
  nativeRealtime={nativeRealtime}
2953
3011
  runNativeVoice={runNativeVoice}
2954
3012
  allowGlobalActions={allowGlobalActions}
@@ -3088,7 +3146,7 @@ export function App({ nativeHost }: { nativeHost?: (sessionId: string) => Native
3088
3146
  />
3089
3147
  </NavigationContainer>
3090
3148
  </KeyboardProvider>
3091
- </PoNativeProvider>
3149
+ </GlobalPluginProviders>
3092
3150
  </SafeAreaProvider>
3093
3151
  );
3094
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);