@gemies/sdk 1.1.0 → 2.0.1
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/CHANGELOG.md +20 -0
- package/README.md +0 -37
- package/package.json +1 -7
- package/src/components/GemieAccounts.tsx +64 -10
- package/src/components/canvas/ChartRenderer.tsx +3 -1
- package/src/components/thread/ToolResultCard.tsx +1 -1
- package/src/lib/copy-en.ts +1 -0
- package/src/lib/copy-es.ts +1 -0
- package/src/runtime/model.ts +1 -0
- package/src/metro/chart-importers.json +0 -18
- package/src/metro/granular-charts.js +0 -3
- package/src/metro/index.cjs +0 -227
- package/src/metro/index.d.cts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @gemies/sdk
|
|
2
2
|
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
- **`GemieAccounts` says when the API does not answer**, with a Retry (`gemie.accounts.retry`), and
|
|
6
|
+
offers nothing to link until it does. It used to show a line of text and no way to try again —
|
|
7
|
+
what a person saw while the API was rolling out a release that served the accounts routes.
|
|
8
|
+
- **A link that fails is said in the panel**, with the API's reason and a Retry, instead of a toast
|
|
9
|
+
that was gone before it could be read.
|
|
10
|
+
|
|
11
|
+
## 2.0.0
|
|
12
|
+
|
|
13
|
+
- **Lighter chat on web: the chart cards come from their own Bloom entries.** `ChartRenderer` and
|
|
14
|
+
`ToolResultCard` import `@oxy.so/bloom/chart-cards/bar-list` and `/line` instead of the
|
|
15
|
+
`chart-cards` root, which is every chart Bloom draws. Measured in the Gemies web export, the
|
|
16
|
+
first paint of `/` carries 50,210 B of chart code instead of 188,724 B. Both entries exist in
|
|
17
|
+
every Bloom the peer range admits (`>=17.41.0`), so nothing changes for a consumer.
|
|
18
|
+
- **Breaking: `@gemies/sdk/metro` is gone.** `withGemieGranularCharts` redirected those same two
|
|
19
|
+
imports at resolution time, for apps whose Bloom did not yet ship the chart entries; now the
|
|
20
|
+
SDK imports them itself, so a consumer that wrapped its Metro config with it removes the
|
|
21
|
+
wrapper and changes nothing else. No app used it.
|
|
22
|
+
|
|
3
23
|
## 1.1.0
|
|
4
24
|
|
|
5
25
|
- **New entry `@gemies/sdk/accounts`** (Gemies ADR 0035): `GemieAccounts`, the panel that links a
|
package/README.md
CHANGED
|
@@ -17,43 +17,6 @@ hooks are named `Gemie*` (`GemieChatContent`, `GemieChatSheet`, `GemieAvatar`, `
|
|
|
17
17
|
the default API is `https://api.gemies.ai` and the shared web origin is `https://gemies.ai`. The
|
|
18
18
|
mapping is in [`CHANGELOG.md`](./CHANGELOG.md) under 1.0.0.
|
|
19
19
|
|
|
20
|
-
## Optional granular chart imports for Metro
|
|
21
|
-
|
|
22
|
-
The standard SDK entries and Bloom peer range are unchanged. Apps that install a Bloom
|
|
23
|
-
version exposing `chart-cards/bar-list` and `chart-cards/line` can opt into a narrower
|
|
24
|
-
chart graph by wrapping their **finished** Metro configuration:
|
|
25
|
-
|
|
26
|
-
```js
|
|
27
|
-
const { withGemieGranularCharts } = require('@gemies/sdk/metro');
|
|
28
|
-
|
|
29
|
-
module.exports = withGemieGranularCharts(existingMetroConfig);
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
This Node-only entry wraps the previous resolver and redirects two verified chart imports
|
|
33
|
-
in this SDK copy. It delegates extra resolution probes to that resolver, so resolver
|
|
34
|
-
implementations with side effects will observe those calls. It checks that the original
|
|
35
|
-
barrel and both granular imports resolve to
|
|
36
|
-
the same physical Bloom copy for the original importer and the adapter. Both subpaths
|
|
37
|
-
must be explicit `exports` keys resolving under the active Metro conditions to files
|
|
38
|
-
inside that copy; arrays, patterns and redirects to other files are not supported.
|
|
39
|
-
The SDK importer hashes are rechecked on affected resolutions, including in watch mode.
|
|
40
|
-
Detection uses the registered paths and their real paths; new aliases introduced later
|
|
41
|
-
may be treated as unregistered, so restart Metro after changing SDK links.
|
|
42
|
-
Missing exports,
|
|
43
|
-
an altered SDK importer or incompatible metadata fail with an explicit build error; the
|
|
44
|
-
normal SDK does not require those exports when this option is not used. File hashes detect
|
|
45
|
-
changes requiring review; they do not authenticate packages.
|
|
46
|
-
|
|
47
|
-
Apply the wrapper once, after other Metro wrappers. Reapplying it directly throws;
|
|
48
|
-
register all copies together instead. Opaque wrappers or cloned configurations can
|
|
49
|
-
hide the marker; do not apply this helper again after composing them.
|
|
50
|
-
Multiple installed SDK copies are not discovered automatically. To opt in other copies,
|
|
51
|
-
pass `{ additionalSdkRoots: ['/absolute/path/to/sdk'] }`; each must ship matching opt-in
|
|
52
|
-
metadata. Unregistered copies retain their original imports and may still include the chart
|
|
53
|
-
barrel. This does not deduplicate React, Bloom or SDK providers, nor prove a bundle-size
|
|
54
|
-
reduction. Review importers, update the version and hashes in `chart-importers.json`, and
|
|
55
|
-
run the Metro tests when updating the SDK package or those files.
|
|
56
|
-
|
|
57
20
|
## Install
|
|
58
21
|
|
|
59
22
|
```sh
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gemies/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "The Gemies SDK: the conversation runtime, chat UI, voice calls and dictation for Oxy apps that talk to a gemie",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -18,10 +18,6 @@
|
|
|
18
18
|
"./csp": "./src/csp.ts",
|
|
19
19
|
"./dictation": "./src/dictation.ts",
|
|
20
20
|
"./model": "./src/runtime/model.ts",
|
|
21
|
-
"./metro": {
|
|
22
|
-
"types": "./src/metro/index.d.cts",
|
|
23
|
-
"default": "./src/metro/index.cjs"
|
|
24
|
-
},
|
|
25
21
|
"./runtime": "./src/runtime/index.ts",
|
|
26
22
|
"./text": "./src/text.ts",
|
|
27
23
|
"./tools": "./src/tools.ts",
|
|
@@ -49,7 +45,6 @@
|
|
|
49
45
|
"scripts": {
|
|
50
46
|
"typecheck": "tsc --noEmit",
|
|
51
47
|
"test": "vitest run",
|
|
52
|
-
"test:metro": "node --test scripts/metro/opt-in.node.cjs",
|
|
53
48
|
"check:entries": "node scripts/check-entry-isolation.mjs",
|
|
54
49
|
"check:entry-types": "node scripts/check-entry-types.mjs"
|
|
55
50
|
},
|
|
@@ -97,7 +92,6 @@
|
|
|
97
92
|
},
|
|
98
93
|
"devDependencies": {
|
|
99
94
|
"@types/react-test-renderer": "^19.1.0",
|
|
100
|
-
"metro-resolver": "0.87.1",
|
|
101
95
|
"react-native-audio-api": "0.13.6",
|
|
102
96
|
"react-native-qrcode-svg": "^6.3.21",
|
|
103
97
|
"react-test-renderer": "19.3.0",
|
|
@@ -330,12 +330,17 @@ export interface GemieAccountsProps {
|
|
|
330
330
|
* its own turns can read or send through them. Only what this deployment can link is offered.
|
|
331
331
|
*/
|
|
332
332
|
export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsProps) {
|
|
333
|
-
const { data, isPending, isError } = useGemieAccounts(gemieId);
|
|
333
|
+
const { data, isPending, isError, isFetching, refetch } = useGemieAccounts(gemieId);
|
|
334
334
|
const { link, remove } = useGemieAccountMutations(gemieId);
|
|
335
335
|
const [linking, setLinking] = useState<{
|
|
336
336
|
platform: GemieAccountPlatform;
|
|
337
337
|
link: GemieAccountLink;
|
|
338
338
|
} | null>(null);
|
|
339
|
+
/** The last link that failed, said in the panel with a way to try again. */
|
|
340
|
+
const [linkFailure, setLinkFailure] = useState<{
|
|
341
|
+
platform: GemieAccountPlatform;
|
|
342
|
+
reason: string;
|
|
343
|
+
} | null>(null);
|
|
339
344
|
const linked = useCallback(() => setLinking(null), []);
|
|
340
345
|
|
|
341
346
|
if (isPending) {
|
|
@@ -350,15 +355,11 @@ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsP
|
|
|
350
355
|
}
|
|
351
356
|
|
|
352
357
|
const handleLink = async (platform: GemieAccountPlatform) => {
|
|
358
|
+
setLinkFailure(null);
|
|
353
359
|
try {
|
|
354
360
|
setLinking({ platform, link: await link.mutateAsync(platform) });
|
|
355
361
|
} catch (error) {
|
|
356
|
-
|
|
357
|
-
t(`${K}.linkFailed`, {
|
|
358
|
-
platform: PLATFORM_LABELS[platform],
|
|
359
|
-
reason: errorMessage(error, t(`${K}.tryAgain`)),
|
|
360
|
-
}),
|
|
361
|
-
);
|
|
362
|
+
setLinkFailure({ platform, reason: errorMessage(error, t(`${K}.tryAgain`)) });
|
|
362
363
|
}
|
|
363
364
|
};
|
|
364
365
|
|
|
@@ -374,11 +375,39 @@ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsP
|
|
|
374
375
|
);
|
|
375
376
|
const platforms = data?.platforms ?? [];
|
|
376
377
|
|
|
378
|
+
/**
|
|
379
|
+
* Nothing could be read: the API did not answer (offline, or mid-rollout before it serves these
|
|
380
|
+
* routes). Said so, with a retry, and nothing else is offered until it answers. A later refresh
|
|
381
|
+
* that fails keeps what was already read.
|
|
382
|
+
*/
|
|
383
|
+
if (isError && data === undefined) {
|
|
384
|
+
return (
|
|
385
|
+
<View>
|
|
386
|
+
<Row first>
|
|
387
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
388
|
+
{t(`${K}.loadFailed`)}
|
|
389
|
+
</Text>
|
|
390
|
+
<View className="flex-row">
|
|
391
|
+
<Button
|
|
392
|
+
size="sm"
|
|
393
|
+
appearance="outline"
|
|
394
|
+
tone="neutral"
|
|
395
|
+
loading={isFetching}
|
|
396
|
+
onPress={() => void refetch()}
|
|
397
|
+
>
|
|
398
|
+
{t(`${K}.retry`)}
|
|
399
|
+
</Button>
|
|
400
|
+
</View>
|
|
401
|
+
</Row>
|
|
402
|
+
</View>
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
377
406
|
return (
|
|
378
407
|
<View>
|
|
379
408
|
<Row first>
|
|
380
409
|
<Text variant="body-2-regular" className="text-text-secondary">
|
|
381
|
-
{
|
|
410
|
+
{t(`${K}.description`, { name })}
|
|
382
411
|
</Text>
|
|
383
412
|
</Row>
|
|
384
413
|
{accounts.map((account) => (
|
|
@@ -401,7 +430,7 @@ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsP
|
|
|
401
430
|
onDone={linked}
|
|
402
431
|
onCancel={handleCancel}
|
|
403
432
|
/>
|
|
404
|
-
) :
|
|
433
|
+
) : (
|
|
405
434
|
<Row>
|
|
406
435
|
<Text variant="body-2-semibold">{t(`${K}.link`)}</Text>
|
|
407
436
|
{platforms.length === 0 ? (
|
|
@@ -409,7 +438,7 @@ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsP
|
|
|
409
438
|
{t(`${K}.unavailable`)}
|
|
410
439
|
</Text>
|
|
411
440
|
) : (
|
|
412
|
-
<View className="flex-row gap-2">
|
|
441
|
+
<View className="flex-row flex-wrap gap-2">
|
|
413
442
|
{platforms.map((platform) => (
|
|
414
443
|
<Button
|
|
415
444
|
key={platform}
|
|
@@ -426,6 +455,31 @@ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsP
|
|
|
426
455
|
))}
|
|
427
456
|
</View>
|
|
428
457
|
)}
|
|
458
|
+
{linkFailure ? (
|
|
459
|
+
<View className="gap-2">
|
|
460
|
+
<Text
|
|
461
|
+
variant="body-2-regular"
|
|
462
|
+
className="text-error-primary"
|
|
463
|
+
accessibilityRole="alert"
|
|
464
|
+
>
|
|
465
|
+
{t(`${K}.linkFailed`, {
|
|
466
|
+
platform: PLATFORM_LABELS[linkFailure.platform],
|
|
467
|
+
reason: linkFailure.reason,
|
|
468
|
+
})}
|
|
469
|
+
</Text>
|
|
470
|
+
<View className="flex-row">
|
|
471
|
+
<Button
|
|
472
|
+
size="sm"
|
|
473
|
+
appearance="outline"
|
|
474
|
+
tone="neutral"
|
|
475
|
+
disabled={link.isPending}
|
|
476
|
+
onPress={() => handleLink(linkFailure.platform)}
|
|
477
|
+
>
|
|
478
|
+
{t(`${K}.retry`)}
|
|
479
|
+
</Button>
|
|
480
|
+
</View>
|
|
481
|
+
</View>
|
|
482
|
+
) : null}
|
|
429
483
|
</Row>
|
|
430
484
|
)}
|
|
431
485
|
</View>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useLabels } from '../../lib/labels';
|
|
2
|
-
|
|
2
|
+
// The two cards by subpath: the `chart-cards` root is every chart Bloom draws (~190 KB on web).
|
|
3
|
+
import { BarListCard } from '@oxy.so/bloom/chart-cards/bar-list';
|
|
4
|
+
import { LineChartCard } from '@oxy.so/bloom/chart-cards/line';
|
|
3
5
|
import { formatNumber } from '@oxy.so/bloom/locale';
|
|
4
6
|
|
|
5
7
|
interface ChartData {
|
|
@@ -18,7 +18,7 @@ import { useGemieRuntime } from '../../runtime/config';
|
|
|
18
18
|
import { AiChatMessageLine } from '@oxy.so/bloom/ai-chat';
|
|
19
19
|
import { Badge } from '@oxy.so/bloom/badge';
|
|
20
20
|
import { Card, CardBody, CardHeader } from '@oxy.so/bloom/card';
|
|
21
|
-
import { LineChartCard } from '@oxy.so/bloom/chart-cards';
|
|
21
|
+
import { LineChartCard } from '@oxy.so/bloom/chart-cards/line';
|
|
22
22
|
import { IconCircle } from '@oxy.so/bloom/icon-circle';
|
|
23
23
|
import { RiArrowRightSLine } from '@oxy.so/bloom/icons/RiArrowRightSLine';
|
|
24
24
|
import { RiCalendarScheduleLine } from '@oxy.so/bloom/icons/RiCalendarScheduleLine';
|
package/src/lib/copy-en.ts
CHANGED
|
@@ -179,6 +179,7 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
|
|
|
179
179
|
'gemie.accounts.replies.everyone': 'Everyone who writes',
|
|
180
180
|
'gemie.accounts.replies.nobody': 'Nobody: {{name}} only reads and sends when you ask',
|
|
181
181
|
'gemie.accounts.repliesLabel': 'Who {{name}} answers',
|
|
182
|
+
'gemie.accounts.retry': 'Retry',
|
|
182
183
|
'gemie.accounts.saveFailed': 'Could not save. Try again.',
|
|
183
184
|
'gemie.accounts.scan.telegram':
|
|
184
185
|
'Open Telegram on your phone, go to Settings > Devices > Link Desktop Device, and scan this code.',
|
package/src/lib/copy-es.ts
CHANGED
|
@@ -175,6 +175,7 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
|
|
|
175
175
|
'gemie.accounts.replies.everyone': 'A todo el que escriba',
|
|
176
176
|
'gemie.accounts.replies.nobody': 'A nadie: {{name}} solo lee y envía cuando se lo pides',
|
|
177
177
|
'gemie.accounts.repliesLabel': 'A quién responde {{name}}',
|
|
178
|
+
'gemie.accounts.retry': 'Reintentar',
|
|
178
179
|
'gemie.accounts.saveFailed': 'No se ha podido guardar. Inténtalo de nuevo.',
|
|
179
180
|
'gemie.accounts.scan.telegram':
|
|
180
181
|
'Abre Telegram en tu teléfono, ve a Ajustes > Dispositivos > Vincular dispositivo de escritorio y escanea este código.',
|
package/src/runtime/model.ts
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"format": 1,
|
|
3
|
-
"sdkVersion": "1.1.0",
|
|
4
|
-
"adapter": {
|
|
5
|
-
"path": "src/metro/granular-charts.js",
|
|
6
|
-
"sha256": "252add5b6642f8637f9b044a76fd05aff52fc9751bcff3e3587a95444f9ec1c1"
|
|
7
|
-
},
|
|
8
|
-
"importers": [
|
|
9
|
-
{
|
|
10
|
-
"path": "src/components/thread/ToolResultCard.tsx",
|
|
11
|
-
"sha256": "887ee8e6e586248a172ab0234450498463f660a707c0a402c8ceba7b0cfc8932"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"path": "src/components/canvas/ChartRenderer.tsx",
|
|
15
|
-
"sha256": "14a6c3a6531a706f3b5c7b135034dfaaf6abe236acc53f98524bfcbb52d3d755"
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
}
|
package/src/metro/index.cjs
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Optional Metro-only resolver for Alia's chart imports. The regular SDK entries
|
|
5
|
-
* and their Bloom peer remain unchanged. Each opted-in SDK copy carries the
|
|
6
|
-
* exact importers and adapter it supports; an unknown copy fails explicitly.
|
|
7
|
-
*/
|
|
8
|
-
const fs = require('node:fs');
|
|
9
|
-
const path = require('node:path');
|
|
10
|
-
const crypto = require('node:crypto');
|
|
11
|
-
|
|
12
|
-
const SDK_ROOT = path.resolve(__dirname, '../..');
|
|
13
|
-
const LEGACY = '@oxy.so/bloom/chart-cards';
|
|
14
|
-
const GRANULAR = [`${LEGACY}/bar-list`, `${LEGACY}/line`];
|
|
15
|
-
const PREFIX = '[Gemies granular charts]';
|
|
16
|
-
const WRAPPED = Symbol.for('@gemies/sdk/metro/granular-charts-resolver/v1');
|
|
17
|
-
|
|
18
|
-
function checkedFile(root, entry) {
|
|
19
|
-
if (!entry || typeof entry.path !== 'string' || !/^[a-f0-9]{64}$/.test(entry.sha256 ?? '')) {
|
|
20
|
-
throw new Error(`${PREFIX} invalid SDK manifest entry`);
|
|
21
|
-
}
|
|
22
|
-
let actual;
|
|
23
|
-
try {
|
|
24
|
-
actual = fs.realpathSync(path.resolve(root, entry.path));
|
|
25
|
-
} catch (error) {
|
|
26
|
-
throw new Error(`${PREFIX} missing SDK file ${entry.path}`, { cause: error });
|
|
27
|
-
}
|
|
28
|
-
if (!actual.startsWith(`${root}${path.sep}`))
|
|
29
|
-
throw new Error(`${PREFIX} SDK file escapes its package`);
|
|
30
|
-
const digest = crypto.createHash('sha256').update(fs.readFileSync(actual)).digest('hex');
|
|
31
|
-
if (digest !== entry.sha256) throw new Error(`${PREFIX} changed SDK file ${entry.path}`);
|
|
32
|
-
return actual;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function collectTargets(roots) {
|
|
36
|
-
const targets = new Map();
|
|
37
|
-
for (const input of roots) {
|
|
38
|
-
let root, pkg, metadata;
|
|
39
|
-
try {
|
|
40
|
-
root = fs.realpathSync(input);
|
|
41
|
-
pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
42
|
-
metadata = JSON.parse(
|
|
43
|
-
fs.readFileSync(path.join(root, 'src/metro/chart-importers.json'), 'utf8'),
|
|
44
|
-
);
|
|
45
|
-
} catch (error) {
|
|
46
|
-
throw new Error(`${PREFIX} SDK copy lacks opt-in metadata`, { cause: error });
|
|
47
|
-
}
|
|
48
|
-
if (
|
|
49
|
-
pkg.name !== '@gemies/sdk' ||
|
|
50
|
-
metadata.format !== 1 ||
|
|
51
|
-
metadata.sdkVersion !== pkg.version ||
|
|
52
|
-
!Array.isArray(metadata.importers) ||
|
|
53
|
-
metadata.importers.length !== 2
|
|
54
|
-
) {
|
|
55
|
-
throw new Error(`${PREFIX} unsupported SDK copy or version`);
|
|
56
|
-
}
|
|
57
|
-
const adapter = checkedFile(root, metadata.adapter);
|
|
58
|
-
for (const importer of metadata.importers) {
|
|
59
|
-
const target = { root, adapter };
|
|
60
|
-
targets.set(checkedFile(root, importer), target);
|
|
61
|
-
targets.set(path.resolve(root, importer.path), target);
|
|
62
|
-
targets.set(path.resolve(input, importer.path), target);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return targets;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function sourceFile(resolution, name) {
|
|
69
|
-
if (resolution?.type !== 'sourceFile' || typeof resolution.filePath !== 'string') {
|
|
70
|
-
throw new Error(`${PREFIX} ${name} did not resolve to a source file`);
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
return fs.realpathSync(resolution.filePath);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
throw new Error(`${PREFIX} ${name} resolved to a missing file`, { cause: error });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function bloomRoot(file) {
|
|
80
|
-
let dir = path.dirname(file);
|
|
81
|
-
for (;;) {
|
|
82
|
-
const manifest = path.join(dir, 'package.json');
|
|
83
|
-
if (fs.existsSync(manifest)) {
|
|
84
|
-
let pkg;
|
|
85
|
-
try {
|
|
86
|
-
pkg = JSON.parse(fs.readFileSync(manifest, 'utf8'));
|
|
87
|
-
} catch (error) {
|
|
88
|
-
throw new Error(`${PREFIX} invalid package manifest`, { cause: error });
|
|
89
|
-
}
|
|
90
|
-
if (pkg.name === '@oxy.so/bloom') return fs.realpathSync(dir);
|
|
91
|
-
}
|
|
92
|
-
const parent = path.dirname(dir);
|
|
93
|
-
if (parent === dir) throw new Error(`${PREFIX} resolved file is not inside Bloom`);
|
|
94
|
-
dir = parent;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** Resolve only explicit, file-valued exports with Metro's active conditions. */
|
|
99
|
-
function exportedFile(root, entry, context, platform, subpath) {
|
|
100
|
-
const names = new Set([
|
|
101
|
-
'default',
|
|
102
|
-
context.isESMImport === true ? 'import' : 'require',
|
|
103
|
-
...(context.unstable_conditionNames ?? []),
|
|
104
|
-
...(context.unstable_conditionsByPlatform?.[platform] ?? []),
|
|
105
|
-
]);
|
|
106
|
-
let target = entry;
|
|
107
|
-
while (target && typeof target === 'object' && !Array.isArray(target)) {
|
|
108
|
-
const key = Object.keys(target).find((condition) => names.has(condition));
|
|
109
|
-
target = key === undefined ? null : target[key];
|
|
110
|
-
}
|
|
111
|
-
if (
|
|
112
|
-
typeof target !== 'string' ||
|
|
113
|
-
!target.startsWith('./') ||
|
|
114
|
-
target.includes('\\') ||
|
|
115
|
-
target.includes('*') ||
|
|
116
|
-
target.split('/').some((segment) => segment === '..' || segment === 'node_modules')
|
|
117
|
-
) {
|
|
118
|
-
throw new Error(`${PREFIX} ${subpath} has no supported export for ${platform}`);
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
const file = fs.realpathSync(path.resolve(root, target));
|
|
122
|
-
if (!file.startsWith(`${root}${path.sep}`) || !fs.statSync(file).isFile())
|
|
123
|
-
throw new Error('invalid target');
|
|
124
|
-
return file;
|
|
125
|
-
} catch (error) {
|
|
126
|
-
throw new Error(`${PREFIX} ${subpath} export target is unavailable for ${platform}`, {
|
|
127
|
-
cause: error,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Wrap a finished Metro config. Only the two verified importers in each
|
|
134
|
-
* explicitly opted-in SDK copy are redirected. Register other installed copies
|
|
135
|
-
* through `additionalSdkRoots`; unregistered copies use their original path.
|
|
136
|
-
* The app must install Bloom with both granular chart subpaths.
|
|
137
|
-
*
|
|
138
|
-
* @param {object} config Metro config, after the app's other resolver wrappers.
|
|
139
|
-
* @param {{additionalSdkRoots?: string[]}} [options]
|
|
140
|
-
* @returns {object} The same config, with its previous resolver preserved.
|
|
141
|
-
*/
|
|
142
|
-
function withGemieGranularCharts(config, options = {}) {
|
|
143
|
-
if (!Array.isArray(options.additionalSdkRoots ?? []))
|
|
144
|
-
throw new Error(`${PREFIX} additionalSdkRoots must be an array`);
|
|
145
|
-
const previous = config.resolver?.resolveRequest;
|
|
146
|
-
if (config[WRAPPED] || previous?.[WRAPPED]) {
|
|
147
|
-
throw new Error(
|
|
148
|
-
`${PREFIX} already configured; register all SDK copies with additionalSdkRoots in one call`,
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
const targets = collectTargets([SDK_ROOT, ...(options.additionalSdkRoots ?? [])]);
|
|
152
|
-
config.resolver ??= {};
|
|
153
|
-
const delegate = (context, name, platform) =>
|
|
154
|
-
previous ? previous(context, name, platform) : context.resolveRequest(context, name, platform);
|
|
155
|
-
const wrapped = (context, name, platform) => {
|
|
156
|
-
if (name !== LEGACY) return delegate(context, name, platform);
|
|
157
|
-
const lexicalOrigin = path.resolve(context.originModulePath);
|
|
158
|
-
const lexicalTarget = targets.get(lexicalOrigin);
|
|
159
|
-
let origin;
|
|
160
|
-
try {
|
|
161
|
-
origin = fs.realpathSync(lexicalOrigin);
|
|
162
|
-
} catch (error) {
|
|
163
|
-
if (lexicalTarget) throw new Error(`${PREFIX} SDK importer is missing`, { cause: error });
|
|
164
|
-
return delegate(context, name, platform);
|
|
165
|
-
}
|
|
166
|
-
const registered = lexicalTarget ?? targets.get(origin);
|
|
167
|
-
if (!registered) return delegate(context, name, platform);
|
|
168
|
-
const refreshed = collectTargets([registered.root]).get(origin);
|
|
169
|
-
if (!refreshed || refreshed.adapter !== registered.adapter) {
|
|
170
|
-
throw new Error(`${PREFIX} SDK targets changed; restart Metro`);
|
|
171
|
-
}
|
|
172
|
-
const adapter = refreshed.adapter;
|
|
173
|
-
|
|
174
|
-
let legacy;
|
|
175
|
-
try {
|
|
176
|
-
legacy = sourceFile(delegate(context, LEGACY, platform), LEGACY);
|
|
177
|
-
} catch (error) {
|
|
178
|
-
throw new Error(`${PREFIX} the original Bloom chart barrel is unavailable for ${platform}`, {
|
|
179
|
-
cause: error,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
const expectedBloom = bloomRoot(legacy);
|
|
183
|
-
const bloom = JSON.parse(fs.readFileSync(path.join(expectedBloom, 'package.json'), 'utf8'));
|
|
184
|
-
const adapterContext = { ...context, originModulePath: adapter };
|
|
185
|
-
for (const subpath of GRANULAR) {
|
|
186
|
-
const exported = `.${subpath.slice('@oxy.so/bloom'.length)}`;
|
|
187
|
-
if (!bloom.exports || !Object.hasOwn(bloom.exports, exported)) {
|
|
188
|
-
throw new Error(
|
|
189
|
-
`${PREFIX} ${subpath} is not exported by this Bloom; install a compatible Bloom`,
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
const publicTarget = exportedFile(
|
|
193
|
-
expectedBloom,
|
|
194
|
-
bloom.exports[exported],
|
|
195
|
-
context,
|
|
196
|
-
platform,
|
|
197
|
-
subpath,
|
|
198
|
-
);
|
|
199
|
-
let originalTarget, adapterTarget;
|
|
200
|
-
try {
|
|
201
|
-
originalTarget = sourceFile(delegate(context, subpath, platform), subpath);
|
|
202
|
-
adapterTarget = sourceFile(delegate(adapterContext, subpath, platform), subpath);
|
|
203
|
-
} catch (error) {
|
|
204
|
-
throw new Error(
|
|
205
|
-
`${PREFIX} ${subpath} is unavailable for ${platform}; install a compatible Bloom`,
|
|
206
|
-
{ cause: error },
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
if (originalTarget !== adapterTarget || bloomRoot(originalTarget) !== expectedBloom) {
|
|
210
|
-
throw new Error(`${PREFIX} ${subpath} selects a different Bloom copy for ${platform}`);
|
|
211
|
-
}
|
|
212
|
-
if (originalTarget !== publicTarget) {
|
|
213
|
-
throw new Error(
|
|
214
|
-
`${PREFIX} ${subpath} did not resolve to its declared public export for ${platform}`,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
const resolvedAdapter = sourceFile(delegate(context, adapter, platform), 'SDK chart adapter');
|
|
219
|
-
if (resolvedAdapter !== adapter) throw new Error(`${PREFIX} SDK chart adapter was redirected`);
|
|
220
|
-
return { type: 'sourceFile', filePath: adapter };
|
|
221
|
-
};
|
|
222
|
-
Object.defineProperty(wrapped, WRAPPED, { value: true });
|
|
223
|
-
Object.defineProperty(config, WRAPPED, { value: true, enumerable: true });
|
|
224
|
-
config.resolver.resolveRequest = wrapped;
|
|
225
|
-
return config;
|
|
226
|
-
}
|
|
227
|
-
module.exports = { withGemieGranularCharts };
|