@agimon-ai/po-native 0.0.1-alpha.71 → 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.
Files changed (36) hide show
  1. package/assets/onboarding/ink-day.webp +0 -0
  2. package/assets/onboarding/ink-night.webp +0 -0
  3. package/assets/onboarding/welcome-pos-night.png +0 -0
  4. package/assets/onboarding/welcome-pos.png +0 -0
  5. package/assets/po-avatars/dev.png +0 -0
  6. package/assets/po-avatars/marketing.png +0 -0
  7. package/assets/po-avatars/personal.png +0 -0
  8. package/assets/po-avatars/po.png +0 -0
  9. package/assets/po-avatars/sales.png +0 -0
  10. package/assets/po-cards/dev-night.webp +0 -0
  11. package/assets/po-cards/dev.webp +0 -0
  12. package/assets/po-cards/marketing-night.webp +0 -0
  13. package/assets/po-cards/marketing.webp +0 -0
  14. package/assets/po-cards/personal-night.webp +0 -0
  15. package/assets/po-cards/personal.webp +0 -0
  16. package/assets/po-cards/po-night.webp +0 -0
  17. package/assets/po-cards/po.webp +0 -0
  18. package/assets/po-cards/sales-night.webp +0 -0
  19. package/assets/po-cards/sales.webp +0 -0
  20. package/package.json +12 -12
  21. package/src/adapters/remoteHttp.ts +3 -2
  22. package/src/adapters/remoteSocket.ts +54 -54
  23. package/src/app/AccountRoute.tsx +2 -0
  24. package/src/app/App.tsx +87 -28
  25. package/src/app/OnboardingRoute.tsx +134 -0
  26. package/src/app/firstSteps.ts +41 -0
  27. package/src/app/hostRuntimes.ts +9 -3
  28. package/src/app/liveRuntime.ts +95 -58
  29. package/src/screens/AccountScreen.tsx +71 -0
  30. package/src/screens/HostedOnboarding.tsx +744 -0
  31. package/src/screens/HostedOnboardingDesign.stories.tsx +317 -0
  32. package/src/screens/SessionScreen.stories.tsx +94 -3
  33. package/src/services/bundleUpdates/index.ts +16 -3
  34. package/src/services/deviceTrust/index.ts +7 -4
  35. package/src/services/hostActions/index.ts +19 -1
  36. package/src/types/assets.d.ts +5 -0
@@ -535,9 +535,10 @@ export function createHostRuntimes(
535
535
  });
536
536
  },
537
537
  onSummariesLoaded() {
538
- if (!active()) return;
538
+ if (!active() || entry.status === 'connected') return;
539
539
  entry.status = 'connected';
540
540
  changed();
541
+ repairLinks();
541
542
  },
542
543
  onPluginCompatibility(issues) {
543
544
  if (!active()) return;
@@ -557,10 +558,8 @@ export function createHostRuntimes(
557
558
  changed();
558
559
  const trusted = await trustedSession;
559
560
  if (!active()) throw new Error('The host connection was replaced.');
560
- if (!saved) entry.status = 'connected';
561
561
  entry.push = startNativePush(trusted, requestPermission, host.id);
562
562
  changed();
563
- repairLinks();
564
563
  return runtime;
565
564
  } catch (error) {
566
565
  entry.lanTransport?.close();
@@ -580,6 +579,13 @@ export function createHostRuntimes(
580
579
  return {
581
580
  connect,
582
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
+ },
583
589
  async rescan(scanned: string, signal?: AbortSignal): Promise<TrustedSession> {
584
590
  if (closed) throw new Error('The host runtimes are closed.');
585
591
  if (scan) throw new Error('A pairing scan is already running.');
@@ -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 { request } = linked(kept);
151
- const manifest = await request({ method: 'GET', target: descriptor.manifestUrl });
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 asset = await request({
154
- method: 'GET',
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: await manifest.json(), source: new Uint8Array(await asset.arrayBuffer()) };
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 { request } = linked(kept);
198
- const manifest = await request({ method: 'GET', target: composition.manifestUrl });
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 request({ method: 'GET', target: `${base}${entryPath}` });
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: await manifest.json(), source: new Uint8Array(await asset.arrayBuffer()) };
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
- if (!closed) void loadCompositions();
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
- if (target.scope === 'session') {
537
- const previous = selectedSessions.get(target.sessionId);
538
- if (previous) composition = previous;
539
- else {
540
- const candidate = descriptorOf(composition);
541
- if (!candidate) return;
542
- const selected = await updates.selectSession(candidate);
543
- if (!selected || closed || sessionMounts.get(target.sessionId) !== target) return;
544
- composition = { ...(composition as SessionNativeComposition), ...selected };
545
- selectedSessions.set(target.sessionId, composition);
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
- const descriptor = descriptorOf(composition);
549
- if (!descriptor) {
550
- plugins.unmount(target);
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
- return;
559
- }
560
- compositions.set(descriptor.id, composition as SessionNativeComposition);
561
- const epoch = (loadEpochs.get(owner) ?? 0) + 1;
562
- loadEpochs.set(owner, epoch);
563
- // Session upserts re-run focus often; an unchanged composition must not blank the sheet with a spinner.
564
- if (!plugins.mounted(target, descriptor)) {
565
- if (target.scope !== 'session') {
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 (!closed && loadEpochs.get(owner) === epoch) onActivityLoad(owner, { loading: false });
586
+ if (current()) onActivityLoad(owner, { loading: false });
574
587
  } catch (error) {
575
- if (!closed && loadEpochs.get(owner) === epoch)
576
- onActivityLoad(owner, {
577
- loading: false,
578
- error: error instanceof Error ? error.message : 'Activity failed to load.',
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 loadCompositions = async () => {
638
- const epoch = (loadEpochs.get('catalog') ?? 0) + 1;
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
- const response = await request({ method: 'GET', target: COMPOSITIONS_ROUTE });
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;
@@ -21,6 +21,7 @@ import welcomeLogoDark from '../../assets/welcome-logo-dark.png';
21
21
  import welcomeLogoLight from '../../assets/welcome-logo-light.png';
22
22
  import { SocialSignInButton } from '../components/SocialSignInButton';
23
23
  import { TAB_BAR_CLEARANCE } from '../components/TabBar';
24
+ import { SignInFormStep, type SignInFormStepProps, SignInWelcomeStep } from './HostedOnboarding';
24
25
 
25
26
  export interface AccountViewProps {
26
27
  page: AccountPage;
@@ -110,10 +111,80 @@ export function accountTitle(page: AccountPage, teamMode?: 'create' | 'choose'):
110
111
  return TITLES[page];
111
112
  }
112
113
 
114
+ /**
115
+ * Hosted Po Cloud sign-in outside Settings, on the onboarding silk. Same pages and actions as below; the
116
+ * team list and every self-hosted page keep the plain look.
117
+ */
118
+ function hostedSignInForm(props: AccountViewProps): SignInFormStepProps | undefined {
119
+ const { onAction } = props;
120
+ const shared = { busy: props.busy, error: props.error, notice: props.notice };
121
+ if (props.page === 'email')
122
+ return {
123
+ ...shared,
124
+ title: 'Continue with email',
125
+ summary: 'We will send you a code. No password to remember.',
126
+ label: 'Email',
127
+ kind: 'email',
128
+ value: props.email ?? '',
129
+ onChangeText: (value) => props.onEmail?.(value),
130
+ primary: 'Send code',
131
+ onPrimary: () => onAction('send-email'),
132
+ secondary: 'Use your own server',
133
+ onSecondary: () => onAction('methods'),
134
+ onBack: () => onAction('welcome'),
135
+ };
136
+ if (props.page === 'email-code')
137
+ return {
138
+ ...shared,
139
+ title: 'Check your email',
140
+ summary: `Enter the 6-digit code we sent to ${props.email ?? 'your email'}.`,
141
+ label: 'Email code',
142
+ kind: 'code',
143
+ value: props.code ?? '',
144
+ onChangeText: (value) => props.onCode?.(value),
145
+ primary: 'Continue',
146
+ onPrimary: () => onAction('verify-email'),
147
+ secondary: 'Send a new code',
148
+ onSecondary: () => onAction('send-email'),
149
+ onBack: () => onAction('Email code'),
150
+ };
151
+ if (props.page === 'team' && props.teamMode !== 'choose')
152
+ return {
153
+ ...shared,
154
+ title: 'Name your team',
155
+ summary: 'Your sessions and settings live in a team. You can invite people later.',
156
+ label: 'Team name',
157
+ kind: 'text',
158
+ value: props.teamName ?? '',
159
+ onChangeText: (value) => props.onTeamName?.(value),
160
+ primary: 'Create team',
161
+ onPrimary: () => onAction('create-team'),
162
+ secondary: 'Use a different email',
163
+ onSecondary: () => onAction('sign-out'),
164
+ // The team is the first step after signing in, so stepping back means another email.
165
+ onBack: () => onAction('sign-out'),
166
+ };
167
+ return undefined;
168
+ }
169
+
113
170
  /** Shared composition for onboarding and Account. Mockup fidelity awaits human approval. */
114
171
  export function AccountView(props: AccountViewProps) {
115
172
  const { page, onAction, busy, error } = props;
116
173
  const { theme } = useUnistyles();
174
+ if (props.hosted && !props.inStack && !props.embedded) {
175
+ if (page === 'welcome' && props.firstRun && !props.signInUnavailable)
176
+ return (
177
+ <SignInWelcomeStep
178
+ busy={busy}
179
+ error={error}
180
+ notice={props.notice}
181
+ onEmail={() => onAction('cloud-sign-in')}
182
+ onOwnServer={() => onAction('methods')}
183
+ />
184
+ );
185
+ const form = hostedSignInForm(props);
186
+ if (form) return <SignInFormStep {...form} />;
187
+ }
117
188
  if (props.firstRun && page === 'welcome') {
118
189
  return (
119
190
  // In a stack the header already names the screen and sits below the status bar.