@agimon-ai/po-native 0.0.1-alpha.76 → 0.0.1-alpha.78

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.
@@ -25,7 +25,10 @@ export async function establishChannels(_http: RemoteHttp, hostPublicKey: string
25
25
  const keys = {} as Record<ChannelScope, string>;
26
26
  for (const scope of ['session', 'protocol', 'http'] as const) {
27
27
  const clientPublicKey = await channels[scope].connect(hostPublicKey);
28
- if (!clientPublicKey) throw new Error(`The ${scope} sealed channel could not be established.`);
28
+ if (!clientPublicKey)
29
+ throw new Error(
30
+ t('native.pairing.channelFailed', 'The {scope} sealed channel could not be established.', { scope }),
31
+ );
29
32
  keys[scope] = clientPublicKey;
30
33
  }
31
34
  return { channels, keys };
@@ -48,7 +51,8 @@ export function parsePairingUrl(scanned: string) {
48
51
  }
49
52
  const params = new URLSearchParams(url.hash.slice(1));
50
53
  for (const key of ['c', 'k', 's', 'r']) {
51
- if (params.getAll(key).length !== 1) throw new Error(`Pairing QR must contain exactly one ${key}.`);
54
+ if (params.getAll(key).length !== 1)
55
+ throw new Error(t('native.pairing.qrFieldCount', 'Pairing QR must contain exactly one {key}.', { key }));
52
56
  }
53
57
  const code = params.get('c') ?? '';
54
58
  const hostPublicKey = params.get('k') ?? '';
@@ -63,21 +67,24 @@ export function parsePairingUrl(scanned: string) {
63
67
  !Number.isSafeInteger(revision) ||
64
68
  revision < 1
65
69
  ) {
66
- throw new Error('Pairing QR has invalid code, channel key or signing trust.');
70
+ throw new Error(t('native.pairing.invalidQr', 'Pairing QR has invalid code, channel key or signing trust.'));
67
71
  }
68
72
  const pins = params.getAll('p');
69
73
  if (pins.length > 1 || (pins.length === 1 && !/^[A-Za-z0-9_-]{43}$/u.test(pins[0]!))) {
70
- throw new Error('Pairing QR has an invalid TLS certificate pin.');
74
+ throw new Error(t('native.pairing.invalidTlsPin', 'Pairing QR has an invalid TLS certificate pin.'));
71
75
  }
72
76
  const relays = params.getAll('relay');
73
77
  const capabilities = params.getAll('cap');
74
78
  if (relays.length > 1 || capabilities.length > 1 || relays.length !== capabilities.length) {
75
- throw new Error('Pairing QR has an invalid private relay address.');
79
+ throw new Error(t('native.pairing.invalidRelay', 'Pairing QR has an invalid private relay address.'));
76
80
  }
77
81
  if (relays.length === 1) {
78
- if (pins.length > 0) throw new Error('Pairing QR cannot name both a LAN pin and a private relay.');
82
+ if (pins.length > 0)
83
+ throw new Error(
84
+ t('native.pairing.conflictingRoutes', 'Pairing QR cannot name both a LAN pin and a private relay.'),
85
+ );
79
86
  if (!PRIVATE_RELAY_ROUTE.test(relays[0]!) || !PRIVATE_RELAY_CAPABILITY.test(capabilities[0]!)) {
80
- throw new Error('Pairing QR has an invalid private relay address.');
87
+ throw new Error(t('native.pairing.invalidRelay', 'Pairing QR has an invalid private relay address.'));
81
88
  }
82
89
  }
83
90
  return {
@@ -121,7 +128,7 @@ export async function pairDevice(scanned: string, fetcher: typeof fetch, signal?
121
128
  const response = await http.direct(`/api/remote/pair/status?request=${encodeURIComponent(claim.requestId)}`);
122
129
  const status: unknown = await response.json();
123
130
  if (!response.ok || typeof status !== 'object' || status === null || !('status' in status)) {
124
- throw new Error('Invalid host approval response.');
131
+ throw new Error(t('native.pairing.invalidApproval', 'Invalid host approval response.'));
125
132
  }
126
133
  if (status.status === 'pending') {
127
134
  await new Promise<void>((resolve, reject) => {
@@ -137,9 +144,10 @@ export async function pairDevice(scanned: string, fetcher: typeof fetch, signal?
137
144
  });
138
145
  continue;
139
146
  }
140
- if (status.status !== 'approved') throw new Error(`Pairing ${String(status.status)}.`);
147
+ if (status.status !== 'approved')
148
+ throw new Error(t('native.pairing.status', 'Pairing {status}.', { status: String(status.status) }));
141
149
  if (!('hostPublicKey' in status) || status.hostPublicKey !== invitation.hostPublicKey) {
142
- throw new Error('Approved host key does not match the QR.');
150
+ throw new Error(t('native.pairing.hostKeyMismatch', 'Approved host key does not match the QR.'));
143
151
  }
144
152
  if (
145
153
  !('bundleTrust' in status) ||
@@ -148,15 +156,20 @@ export async function pairDevice(scanned: string, fetcher: typeof fetch, signal?
148
156
  !('publicKey' in status.bundleTrust) ||
149
157
  status.bundleTrust.publicKey !== invitation.trust.publicKey
150
158
  ) {
151
- throw new Error('Approved signer does not match the QR.');
159
+ throw new Error(t('native.pairing.signerMismatch', 'Approved signer does not match the QR.'));
152
160
  }
153
- if (!http.cookie()) throw new Error('The native fetch implementation did not expose the device cookie.');
161
+ if (!http.cookie())
162
+ throw new Error(
163
+ t('native.pairing.cookieUnavailable', 'The native fetch implementation did not expose the device cookie.'),
164
+ );
154
165
  const established = await establishChannels(http, invitation.hostPublicKey);
155
166
  channels = established.channels;
156
167
  for (const [scope, clientPublicKey] of Object.entries(established.keys)) {
157
168
  if (signal?.aborted) throw new Error(t('native.pairing.cancelled', 'Pairing cancelled.'));
158
169
  if (!(await http.direct('/api/remote/channel', { scope, clientPublicKey })).ok) {
159
- throw new Error(`The ${scope} sealed channel could not be established.`);
170
+ throw new Error(
171
+ t('native.pairing.channelFailed', 'The {scope} sealed channel could not be established.', { scope }),
172
+ );
160
173
  }
161
174
  }
162
175
  // Pairing is useful without an account. A linking failure must never discard it.
@@ -1,3 +1,4 @@
1
+ import { t } from '@agimon-ai/po-core/native';
1
2
  import { pluginApiUrl, sessionApiAddress } from '@agimon-ai/po-core/web';
2
3
  import { parseProfileCatalog } from '@agimon-ai/po-web-components/text';
3
4
 
@@ -87,7 +88,7 @@ export async function selectSessionProfile(
87
88
  /** Labels are presentation; row values and checkmarks always use the profile name. */
88
89
  export function profileChoices(catalog: ProfileCatalog, current: string | null | undefined): ProfileChoiceRow[] {
89
90
  return [
90
- { key: '', label: 'None', on: current !== undefined && !current },
91
+ { key: '', label: t('native.profile.none', 'None'), on: current !== undefined && !current },
91
92
  ...catalog.profiles.map(({ name, identity }) => ({
92
93
  key: name,
93
94
  label: identity?.name ?? name,