@assistant-ui/metro 0.0.7 → 0.0.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"transformer.d.cts","names":[],"sources":["../src/transformer.ts"],"mappings":";;KAeK;EACH,YAAY;IACV;IACA;IACA;MACM;QAA2B;;;KAEhC;;EAEH;GACC;;iBA2Ca,UACd,OAAO,WAAW;iBA0CJ"}
1
+ {"version":3,"file":"transformer.d.cts","names":[],"sources":["../src/transformer.ts"],"mappings":";;KAeK;EACH,YAAY;IACV;IACA;IACA;MACM;QAA2B;;;KAEhC;;EAEH;GACC;;iBA2Ca,UACd,OAAO,WAAW;iBA2CJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/metro",
3
- "version": "0.0.7",
3
+ "version": "0.0.10",
4
4
  "description": "Metro / Expo integration for assistant-ui: the \"use generative\" directive compiler that colocates a tool's schema, server execute, and client render in one file. Works with Expo and bare React Native.",
5
5
  "keywords": [
6
6
  "assistant-ui",
@@ -37,13 +37,13 @@
37
37
  "@babel/types": "^8.0.4"
38
38
  },
39
39
  "devDependencies": {
40
- "@types/node": "^26.1.1",
40
+ "@types/node": "^26.2.0",
41
41
  "tsdown": "^0.22.14",
42
42
  "typescript": "npm:@typescript/typescript6@^6.0.2",
43
43
  "typescript-7": "npm:typescript@^7.0.2",
44
44
  "vitest": "^4.1.10",
45
- "@assistant-ui/x-buildutils": "0.0.21",
46
- "@assistant-ui/x-generative-compiler": "^0.0.11"
45
+ "@assistant-ui/x-buildutils": "0.0.23",
46
+ "@assistant-ui/x-generative-compiler": "^0.0.14"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public",
package/src/index.ts CHANGED
@@ -8,6 +8,8 @@ const require = createRequire(import.meta.url);
8
8
  * preserved and only `transformer.babelTransformerPath` is augmented.
9
9
  */
10
10
  export type MetroConfigLike = {
11
+ /** assistant-ui options, stripped from the config handed back to Metro. */
12
+ aui?: WithAuiOptions | undefined;
11
13
  transformer?:
12
14
  | {
13
15
  babelTransformerPath?: string | undefined;
@@ -24,6 +26,21 @@ export type MetroConfigLike = {
24
26
  */
25
27
  export const UPSTREAM_TRANSFORMER_ENV = "AUI_METRO_UPSTREAM_TRANSFORMER";
26
28
 
29
+ /**
30
+ * Env var carrying the `backendless` option to the transformer. Metro forks its
31
+ * transform workers after `metro.config` is evaluated, so they inherit it.
32
+ */
33
+ export const BACKENDLESS_ENV = "AUI_METRO_BACKENDLESS";
34
+
35
+ export interface WithAuiOptions {
36
+ /**
37
+ * The app has no backend importing the server builds of its `"use generative"`
38
+ * modules (e.g. cloud-hosted runs). Frontend/human tool schemas then stay
39
+ * uploadable from the client instead of being assumed backend-known.
40
+ */
41
+ backendless?: boolean;
42
+ }
43
+
27
44
  /**
28
45
  * Wraps a Metro (or Expo) config so assistant-ui `"use generative"` modules are
29
46
  * compiled. Such a file colocates a tool's schema, its `execute`, and its
@@ -40,7 +57,10 @@ export const UPSTREAM_TRANSFORMER_ENV = "AUI_METRO_UPSTREAM_TRANSFORMER";
40
57
  * const { getDefaultConfig } = require("expo/metro-config");
41
58
  * const { withAui } = require("@assistant-ui/metro");
42
59
  *
43
- * module.exports = withAui(getDefaultConfig(__dirname));
60
+ * module.exports = withAui({
61
+ * ...getDefaultConfig(__dirname),
62
+ * aui: { backendless: true },
63
+ * });
44
64
  * ```
45
65
  *
46
66
  * Authoring is identical to the web: a `"use generative"` file whose default
@@ -48,8 +68,13 @@ export const UPSTREAM_TRANSFORMER_ENV = "AUI_METRO_UPSTREAM_TRANSFORMER";
48
68
  */
49
69
  export function withAui<T extends MetroConfigLike>(config: T): T {
50
70
  const self = require.resolve("@assistant-ui/metro/transformer");
71
+ // Metro validates config keys it does not recognize, so `aui` must not
72
+ // survive into the returned config.
73
+ const { aui, ...baseConfig } = config;
51
74
  const upstream = config.transformer?.babelTransformerPath;
52
75
 
76
+ if (aui?.backendless) process.env[BACKENDLESS_ENV] = "1";
77
+
53
78
  // Guard against a double-wrap (`withAui(withAui(config))`, or a shared config
54
79
  // already wrapped): if it already points at our transformer, keep the real
55
80
  // upstream captured earlier rather than overwriting it with our own path,
@@ -59,10 +84,10 @@ export function withAui<T extends MetroConfigLike>(config: T): T {
59
84
  }
60
85
 
61
86
  return {
62
- ...config,
87
+ ...baseConfig,
63
88
  transformer: {
64
89
  ...config.transformer,
65
90
  babelTransformerPath: self,
66
91
  },
67
- };
92
+ } as T;
68
93
  }
@@ -5,7 +5,7 @@ import {
5
5
  compileGenerative,
6
6
  isGenerativeModule,
7
7
  } from "@assistant-ui/x-generative-compiler";
8
- import { UPSTREAM_TRANSFORMER_ENV } from "./index";
8
+ import { BACKENDLESS_ENV, UPSTREAM_TRANSFORMER_ENV } from "./index";
9
9
 
10
10
  const require = createRequire(import.meta.url);
11
11
 
@@ -86,6 +86,7 @@ export function transform(
86
86
  // resolve; the environment split already keeps a server `execute` out of
87
87
  // the client bundle.
88
88
  injectServerOnly: false,
89
+ backendless: process.env[BACKENDLESS_ENV] === "1",
89
90
  });
90
91
 
91
92
  return upstream.transform({ ...props, src: code });
@@ -112,5 +113,7 @@ function selfCacheToken(): string {
112
113
  export function getCacheKey(): string {
113
114
  const upstream = upstreamTransformer();
114
115
  const base = upstream.getCacheKey ? upstream.getCacheKey() : "";
115
- return `${base}$aui-metro:${selfCacheToken()}`;
116
+ const backendless =
117
+ process.env[BACKENDLESS_ENV] === "1" ? ":backendless" : "";
118
+ return `${base}$aui-metro:${selfCacheToken()}${backendless}`;
116
119
  }