@assistant-ui/metro 0.0.6 → 0.0.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/README.md +19 -3
- package/dist/index.cjs.map +1 -1
- package/dist/transformer.cjs +76 -50
- package/dist/transformer.cjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -67,10 +67,26 @@ export default defineToolkit({
|
|
|
67
67
|
Register it with `Tools({ toolkit })`, the same as on the web:
|
|
68
68
|
|
|
69
69
|
```tsx
|
|
70
|
-
import {
|
|
70
|
+
import type { ReactNode } from "react";
|
|
71
|
+
import {
|
|
72
|
+
AssistantRuntimeProvider,
|
|
73
|
+
AuiConfig,
|
|
74
|
+
Tools,
|
|
75
|
+
useLocalRuntime,
|
|
76
|
+
} from "@assistant-ui/react-native";
|
|
71
77
|
import toolkit from "./toolkit";
|
|
72
|
-
|
|
73
|
-
|
|
78
|
+
import { modelAdapter } from "./modelAdapter";
|
|
79
|
+
|
|
80
|
+
const config = AuiConfig({ tools: Tools({ toolkit }) });
|
|
81
|
+
|
|
82
|
+
const App = ({ children }: { children: ReactNode }) => {
|
|
83
|
+
const runtime = useLocalRuntime(modelAdapter);
|
|
84
|
+
return (
|
|
85
|
+
<AssistantRuntimeProvider runtime={runtime} config={config}>
|
|
86
|
+
{children}
|
|
87
|
+
</AssistantRuntimeProvider>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
74
90
|
```
|
|
75
91
|
|
|
76
92
|
## How it works
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["require"],"sources":["../src/index.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nconst require = createRequire(import.meta.url);\n\n/**\n * The shape of a Metro / Expo config `withAui` accepts. Typed loosely so this\n * package needs no hard dependency on `metro` or `expo`; the input shape is\n * preserved and only `transformer.babelTransformerPath` is augmented.\n */\nexport type MetroConfigLike = {\n transformer?:\n | {\n babelTransformerPath?: string | undefined;\n [key: string]: unknown;\n }\n | undefined;\n [key: string]: unknown;\n};\n\n/**\n * Env var the transformer reads to delegate to the project's existing\n * (Expo / React Native) babel transformer. Metro forks its transform workers\n * after `metro.config` is evaluated, so they inherit this value.\n */\nexport const UPSTREAM_TRANSFORMER_ENV = \"AUI_METRO_UPSTREAM_TRANSFORMER\";\n\n/**\n * Wraps a Metro (or Expo) config so assistant-ui `\"use generative\"` modules are\n * compiled. Such a file colocates a tool's schema, its `execute`, and its\n * `render` via {@link https://www.assistant-ui.com/docs/tools/defining-tools | defineToolkit}.\n *\n * It points Metro's `babelTransformerPath` at this package's transformer, which\n * runs the `\"use generative\"` compiler and then delegates to your project's\n * existing transformer. The device (client) build keeps each tool's `render`\n * and any frontend `execute`; a server build (an Expo Router `+api` route)\n * keeps a server `execute` instead.\n *\n * ```js\n * // metro.config.js\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { withAui } = require(\"@assistant-ui/metro\");\n *\n * module.exports = withAui(getDefaultConfig(__dirname));\n * ```\n *\n * Authoring is identical to the web: a `\"use generative\"` file whose default\n * export is `defineToolkit({ ... })`, registered with `Tools({ toolkit })`.\n */\nexport function withAui<T extends MetroConfigLike>(config: T): T {\n const self = require.resolve(\"@assistant-ui/metro/transformer\");\n const upstream = config.transformer?.babelTransformerPath;\n\n // Guard against a double-wrap (`withAui(withAui(config))`, or a shared config\n // already wrapped): if it already points at our transformer, keep the real\n // upstream captured earlier rather than overwriting it with our own path,\n // which would make `resolveUpstream()` return this transformer and recurse.\n if (upstream && upstream !== self) {\n process.env[UPSTREAM_TRANSFORMER_ENV] = upstream;\n }\n\n return {\n ...config,\n transformer: {\n ...config.transformer,\n babelTransformerPath: self,\n },\n };\n}\n"],"mappings":";;AAEA,MAAMA,aAAAA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["require","createRequire"],"sources":["../src/index.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nconst require = createRequire(import.meta.url);\n\n/**\n * The shape of a Metro / Expo config `withAui` accepts. Typed loosely so this\n * package needs no hard dependency on `metro` or `expo`; the input shape is\n * preserved and only `transformer.babelTransformerPath` is augmented.\n */\nexport type MetroConfigLike = {\n transformer?:\n | {\n babelTransformerPath?: string | undefined;\n [key: string]: unknown;\n }\n | undefined;\n [key: string]: unknown;\n};\n\n/**\n * Env var the transformer reads to delegate to the project's existing\n * (Expo / React Native) babel transformer. Metro forks its transform workers\n * after `metro.config` is evaluated, so they inherit this value.\n */\nexport const UPSTREAM_TRANSFORMER_ENV = \"AUI_METRO_UPSTREAM_TRANSFORMER\";\n\n/**\n * Wraps a Metro (or Expo) config so assistant-ui `\"use generative\"` modules are\n * compiled. Such a file colocates a tool's schema, its `execute`, and its\n * `render` via {@link https://www.assistant-ui.com/docs/tools/defining-tools | defineToolkit}.\n *\n * It points Metro's `babelTransformerPath` at this package's transformer, which\n * runs the `\"use generative\"` compiler and then delegates to your project's\n * existing transformer. The device (client) build keeps each tool's `render`\n * and any frontend `execute`; a server build (an Expo Router `+api` route)\n * keeps a server `execute` instead.\n *\n * ```js\n * // metro.config.js\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { withAui } = require(\"@assistant-ui/metro\");\n *\n * module.exports = withAui(getDefaultConfig(__dirname));\n * ```\n *\n * Authoring is identical to the web: a `\"use generative\"` file whose default\n * export is `defineToolkit({ ... })`, registered with `Tools({ toolkit })`.\n */\nexport function withAui<T extends MetroConfigLike>(config: T): T {\n const self = require.resolve(\"@assistant-ui/metro/transformer\");\n const upstream = config.transformer?.babelTransformerPath;\n\n // Guard against a double-wrap (`withAui(withAui(config))`, or a shared config\n // already wrapped): if it already points at our transformer, keep the real\n // upstream captured earlier rather than overwriting it with our own path,\n // which would make `resolveUpstream()` return this transformer and recurse.\n if (upstream && upstream !== self) {\n process.env[UPSTREAM_TRANSFORMER_ENV] = upstream;\n }\n\n return {\n ...config,\n transformer: {\n ...config.transformer,\n babelTransformerPath: self,\n },\n };\n}\n"],"mappings":";;AAEA,MAAMA,aAAAA,wBAAUC,CAAAA,CAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B;;;;;;AAsB7C,MAAa,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;AAwBxC,SAAgB,QAAmC,QAAc;CAC/D,MAAM,OAAOD,UAAQ,QAAQ,iCAAiC;CAC9D,MAAM,WAAW,OAAO,aAAa;CAMrC,IAAI,YAAY,aAAa,MAC3B,QAAQ,IAAI,4BAA4B;CAG1C,OAAO;EACL,GAAG;EACH,aAAa;GACX,GAAG,OAAO;GACV,sBAAsB;EACxB;CACF;AACF"}
|
package/dist/transformer.cjs
CHANGED
|
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
21
21
|
value: mod,
|
|
22
22
|
enumerable: true
|
|
23
23
|
}) : target, mod));
|
|
@@ -40,18 +40,16 @@ _babel_types = __toESM(_babel_types, 1);
|
|
|
40
40
|
const DIRECTIVE = "use generative";
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region ../x-generative-compiler/dist/package.js
|
|
43
|
-
var version = "0.0.
|
|
43
|
+
var version = "0.0.12";
|
|
44
44
|
//#endregion
|
|
45
45
|
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/constants.js
|
|
46
46
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
47
|
-
const SEMVER_SPEC_VERSION = "2.0.0";
|
|
48
|
-
const MAX_LENGTH = 256;
|
|
49
|
-
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
|
|
50
47
|
module.exports = {
|
|
51
|
-
MAX_LENGTH,
|
|
48
|
+
MAX_LENGTH: 256,
|
|
52
49
|
MAX_SAFE_COMPONENT_LENGTH: 16,
|
|
53
|
-
MAX_SAFE_BUILD_LENGTH:
|
|
54
|
-
MAX_SAFE_INTEGER
|
|
50
|
+
MAX_SAFE_BUILD_LENGTH: 250,
|
|
51
|
+
MAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER ||
|
|
52
|
+
/* istanbul ignore next */ 9007199254740991,
|
|
55
53
|
RELEASE_TYPES: [
|
|
56
54
|
"major",
|
|
57
55
|
"premajor",
|
|
@@ -61,7 +59,7 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
61
59
|
"prepatch",
|
|
62
60
|
"prerelease"
|
|
63
61
|
],
|
|
64
|
-
SEMVER_SPEC_VERSION,
|
|
62
|
+
SEMVER_SPEC_VERSION: "2.0.0",
|
|
65
63
|
FLAG_INCLUDE_PRERELEASE: 1,
|
|
66
64
|
FLAG_LOOSE: 2
|
|
67
65
|
};
|
|
@@ -199,9 +197,10 @@ var require_semver$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
199
197
|
module.exports = class SemVer {
|
|
200
198
|
constructor(version, options) {
|
|
201
199
|
options = parseOptions(options);
|
|
202
|
-
if (version instanceof SemVer)
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
if (version instanceof SemVer) {
|
|
201
|
+
if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) return version;
|
|
202
|
+
else version = version.version;
|
|
203
|
+
} else if (typeof version !== "string") throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`);
|
|
205
204
|
if (version.length > MAX_LENGTH) throw new TypeError(`version is longer than ${MAX_LENGTH} characters`);
|
|
206
205
|
debug("SemVer", version, options);
|
|
207
206
|
this.options = options;
|
|
@@ -654,9 +653,7 @@ var require_truncate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
654
653
|
version.minor = 0;
|
|
655
654
|
version.patch = 0;
|
|
656
655
|
break;
|
|
657
|
-
case "minor":
|
|
658
|
-
version.patch = 0;
|
|
659
|
-
break;
|
|
656
|
+
case "minor": version.patch = 0;
|
|
660
657
|
}
|
|
661
658
|
return version.format();
|
|
662
659
|
};
|
|
@@ -705,8 +702,10 @@ var require_range = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
705
702
|
module.exports = class Range {
|
|
706
703
|
constructor(range, options) {
|
|
707
704
|
options = parseOptions(options);
|
|
708
|
-
if (range instanceof Range)
|
|
709
|
-
|
|
705
|
+
if (range instanceof Range) {
|
|
706
|
+
if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) return range;
|
|
707
|
+
else return new Range(range.raw, options);
|
|
708
|
+
}
|
|
710
709
|
if (range instanceof Comparator) {
|
|
711
710
|
this.raw = range.value;
|
|
712
711
|
this.set = [[range]];
|
|
@@ -876,18 +875,21 @@ var require_range = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
876
875
|
let ret;
|
|
877
876
|
if (isX(M)) ret = "";
|
|
878
877
|
else if (isX(m)) ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
879
|
-
else if (isX(p))
|
|
880
|
-
|
|
881
|
-
|
|
878
|
+
else if (isX(p)) {
|
|
879
|
+
if (M === "0") ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
880
|
+
else ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
|
|
881
|
+
} else if (pr) {
|
|
882
882
|
debug("replaceCaret pr", pr);
|
|
883
|
-
if (M === "0")
|
|
884
|
-
|
|
885
|
-
|
|
883
|
+
if (M === "0") {
|
|
884
|
+
if (m === "0") ret = `>=${M}.${m}.${p}-${pr} <${M}.${m}.${+p + 1}-0`;
|
|
885
|
+
else ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
886
|
+
} else ret = `>=${M}.${m}.${p}-${pr} <${+M + 1}.0.0-0`;
|
|
886
887
|
} else {
|
|
887
888
|
debug("no pr");
|
|
888
|
-
if (M === "0")
|
|
889
|
-
|
|
890
|
-
|
|
889
|
+
if (M === "0") {
|
|
890
|
+
if (m === "0") ret = `>=${M}.${m}.${p} <${M}.${m}.${+p + 1}-0`;
|
|
891
|
+
else ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
|
|
892
|
+
} else ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
|
|
891
893
|
}
|
|
892
894
|
debug("caret return", ret);
|
|
893
895
|
return ret;
|
|
@@ -909,9 +911,10 @@ var require_range = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
909
911
|
const anyX = xp;
|
|
910
912
|
if (gtlt === "=" && anyX) gtlt = "";
|
|
911
913
|
pr = options.includePrerelease ? "-0" : "";
|
|
912
|
-
if (xM)
|
|
913
|
-
|
|
914
|
-
|
|
914
|
+
if (xM) {
|
|
915
|
+
if (gtlt === ">" || gtlt === "<") ret = "<0.0.0-0";
|
|
916
|
+
else ret = "*";
|
|
917
|
+
} else if (gtlt && anyX) {
|
|
915
918
|
if (xm) m = 0;
|
|
916
919
|
p = 0;
|
|
917
920
|
if (gtlt === ">") {
|
|
@@ -985,8 +988,10 @@ var require_comparator = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
985
988
|
}
|
|
986
989
|
constructor(comp, options) {
|
|
987
990
|
options = parseOptions(options);
|
|
988
|
-
if (comp instanceof Comparator)
|
|
989
|
-
|
|
991
|
+
if (comp instanceof Comparator) {
|
|
992
|
+
if (comp.loose === !!options.loose) return comp;
|
|
993
|
+
else comp = comp.value;
|
|
994
|
+
}
|
|
990
995
|
comp = comp.trim().split(/\s+/).join(" ");
|
|
991
996
|
debug("comparator", comp, options);
|
|
992
997
|
this.options = options;
|
|
@@ -1306,11 +1311,15 @@ var require_subset = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1306
1311
|
const minimumVersion = [new Comparator(">=0.0.0")];
|
|
1307
1312
|
const simpleSubset = (sub, dom, options) => {
|
|
1308
1313
|
if (sub === dom) return true;
|
|
1309
|
-
if (sub.length === 1 && sub[0].semver === ANY)
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
+
if (sub.length === 1 && sub[0].semver === ANY) {
|
|
1315
|
+
if (dom.length === 1 && dom[0].semver === ANY) return true;
|
|
1316
|
+
else if (options.includePrerelease) sub = minimumVersionWithPreRelease;
|
|
1317
|
+
else sub = minimumVersion;
|
|
1318
|
+
}
|
|
1319
|
+
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
1320
|
+
if (options.includePrerelease) return true;
|
|
1321
|
+
else dom = minimumVersion;
|
|
1322
|
+
}
|
|
1314
1323
|
const eqSet = /* @__PURE__ */ new Set();
|
|
1315
1324
|
let gt, lt;
|
|
1316
1325
|
for (const c of sub) if (c.operator === ">" || c.operator === ">=") gt = higherGT(gt, c, options);
|
|
@@ -2095,20 +2104,35 @@ function toolkitEntryNames(entry, toolkitSpreadNames) {
|
|
|
2095
2104
|
}
|
|
2096
2105
|
return [];
|
|
2097
2106
|
}
|
|
2107
|
+
function toolkitEntrySourceLabel(entry) {
|
|
2108
|
+
if (_babel_types.isSpreadElement(entry)) {
|
|
2109
|
+
if (_babel_types.isIdentifier(entry.argument)) return `...${entry.argument.name}`;
|
|
2110
|
+
if (unwrapToCall(entry.argument, MCP_TOOLKIT_WRAPPER)) return `...${MCP_TOOLKIT_WRAPPER}(...)`;
|
|
2111
|
+
return "...";
|
|
2112
|
+
}
|
|
2113
|
+
if (_babel_types.isObjectProperty(entry) || _babel_types.isObjectMethod(entry)) {
|
|
2114
|
+
const line = entry.loc?.start.line;
|
|
2115
|
+
return line === void 0 ? "inline property" : `inline property (line ${line})`;
|
|
2116
|
+
}
|
|
2117
|
+
return "inline property";
|
|
2118
|
+
}
|
|
2098
2119
|
function warnDuplicateToolkitNames(object, toolkitSpreadNames, filename) {
|
|
2099
|
-
const
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
}
|
|
2109
|
-
continue;
|
|
2120
|
+
const sourcesByToolName = /* @__PURE__ */ new Map();
|
|
2121
|
+
for (const entry of object.properties) {
|
|
2122
|
+
const entryNames = toolkitEntryNames(entry, toolkitSpreadNames);
|
|
2123
|
+
if (!entryNames) continue;
|
|
2124
|
+
const source = toolkitEntrySourceLabel(entry);
|
|
2125
|
+
for (const name of entryNames) {
|
|
2126
|
+
const sources = sourcesByToolName.get(name);
|
|
2127
|
+
if (sources) sources.push(source);
|
|
2128
|
+
else sourcesByToolName.set(name, [source]);
|
|
2110
2129
|
}
|
|
2111
|
-
|
|
2130
|
+
}
|
|
2131
|
+
for (const [name, sources] of sourcesByToolName) {
|
|
2132
|
+
const winner = sources.at(-1);
|
|
2133
|
+
const overridden = sources.slice(0, -1);
|
|
2134
|
+
if (winner === void 0 || overridden.length === 0) continue;
|
|
2135
|
+
console.warn(new GenerativeCompileError(`Duplicate tool name "${name}": ${winner} overrides ${overridden.join(", ")}. JavaScript object spread keeps the last definition.`, filename).message);
|
|
2112
2136
|
}
|
|
2113
2137
|
}
|
|
2114
2138
|
function isSafeToolkitSpread(entry, toolkitSpreadNames) {
|
|
@@ -2217,8 +2241,10 @@ function compileToolkit(object, target, instances, interactableToolImports, tool
|
|
|
2217
2241
|
} else {
|
|
2218
2242
|
if (hasRender) removeMember(value, "render");
|
|
2219
2243
|
if (hasRenderText) removeMember(value, "renderText");
|
|
2220
|
-
if (execute)
|
|
2221
|
-
|
|
2244
|
+
if (execute) {
|
|
2245
|
+
if (type === "backend" && !isExternal) flags.keptBackendExecute = true;
|
|
2246
|
+
else removeMember(value, "execute");
|
|
2247
|
+
}
|
|
2222
2248
|
}
|
|
2223
2249
|
setToolType(value, type);
|
|
2224
2250
|
setBackendDefault(value, target, type);
|