json-ui-lite-rn 0.12.0
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 +230 -0
- package/lib/commonjs/GenUINode.js +113 -0
- package/lib/commonjs/GenUINode.js.map +1 -0
- package/lib/commonjs/GenerativeUIView.js +116 -0
- package/lib/commonjs/GenerativeUIView.js.map +1 -0
- package/lib/commonjs/index.js +78 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/parseGenUIProps.js +53 -0
- package/lib/commonjs/parseGenUIProps.js.map +1 -0
- package/lib/commonjs/prompt.js +27 -0
- package/lib/commonjs/prompt.js.map +1 -0
- package/lib/commonjs/registry.js +70 -0
- package/lib/commonjs/registry.js.map +1 -0
- package/lib/commonjs/tools.js +386 -0
- package/lib/commonjs/tools.js.map +1 -0
- package/lib/module/GenUINode.js +108 -0
- package/lib/module/GenUINode.js.map +1 -0
- package/lib/module/GenerativeUIView.js +111 -0
- package/lib/module/GenerativeUIView.js.map +1 -0
- package/lib/module/index.js +9 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/parseGenUIProps.js +49 -0
- package/lib/module/parseGenUIProps.js.map +1 -0
- package/lib/module/prompt.js +23 -0
- package/lib/module/prompt.js.map +1 -0
- package/lib/module/registry.js +66 -0
- package/lib/module/registry.js.map +1 -0
- package/lib/module/tools.js +383 -0
- package/lib/module/tools.js.map +1 -0
- package/lib/typescript/GenUINode.d.ts +12 -0
- package/lib/typescript/GenUINode.d.ts.map +1 -0
- package/lib/typescript/GenerativeUIView.d.ts +23 -0
- package/lib/typescript/GenerativeUIView.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/parseGenUIProps.d.ts +20 -0
- package/lib/typescript/parseGenUIProps.d.ts.map +1 -0
- package/lib/typescript/prompt.d.ts +12 -0
- package/lib/typescript/prompt.d.ts.map +1 -0
- package/lib/typescript/registry.d.ts +36 -0
- package/lib/typescript/registry.d.ts.map +1 -0
- package/lib/typescript/tools.d.ts +119 -0
- package/lib/typescript/tools.d.ts.map +1 -0
- package/package.json +56 -0
- package/src/GenUINode.tsx +115 -0
- package/src/GenerativeUIView.tsx +137 -0
- package/src/index.ts +25 -0
- package/src/parseGenUIProps.ts +59 -0
- package/src/prompt.ts +49 -0
- package/src/registry.ts +73 -0
- package/src/tools.ts +392 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GEN_UI_STYLE_HINTS = exports.GEN_UI_STYLES = exports.GEN_UI_NODE_NAMES_THAT_SUPPORT_CHILDREN = exports.GEN_UI_NODE_NAMES = exports.GEN_UI_NODE_HINTS = exports.DEFAULT_GEN_UI_ROOT_ID = void 0;
|
|
7
|
+
var _zod = require("zod");
|
|
8
|
+
const DEFAULT_GEN_UI_ROOT_ID = exports.DEFAULT_GEN_UI_ROOT_ID = 'root';
|
|
9
|
+
const GEN_UI_NODE_NAMES = exports.GEN_UI_NODE_NAMES = {
|
|
10
|
+
Text: 'Text',
|
|
11
|
+
Paragraph: 'Paragraph',
|
|
12
|
+
Label: 'Label',
|
|
13
|
+
Heading: 'Heading',
|
|
14
|
+
Button: 'Button',
|
|
15
|
+
TextInput: 'TextInput'
|
|
16
|
+
};
|
|
17
|
+
const GEN_UI_NODE_NAMES_THAT_SUPPORT_CHILDREN = exports.GEN_UI_NODE_NAMES_THAT_SUPPORT_CHILDREN = [];
|
|
18
|
+
const GEN_UI_NODE_HINTS = exports.GEN_UI_NODE_HINTS = {
|
|
19
|
+
Text: 'Single line text. Props: text [string], style [object].',
|
|
20
|
+
Paragraph: 'Long text. Props: text [string], style [object].',
|
|
21
|
+
Label: 'Small label. Props: text [string], style [object].',
|
|
22
|
+
Heading: 'Title text. Props: text [string], style [object].',
|
|
23
|
+
Button: 'Tap button. Props: text [string], style [object].',
|
|
24
|
+
TextInput: 'Single line text input. Props: placeholder [string], style [object].'
|
|
25
|
+
};
|
|
26
|
+
const GEN_UI_STYLES = exports.GEN_UI_STYLES = {
|
|
27
|
+
flex: _zod.z.number(),
|
|
28
|
+
padding: _zod.z.number(),
|
|
29
|
+
gap: _zod.z.number(),
|
|
30
|
+
backgroundColor: _zod.z.string(),
|
|
31
|
+
color: _zod.z.string(),
|
|
32
|
+
fontSize: _zod.z.number(),
|
|
33
|
+
fontWeight: _zod.z.string(),
|
|
34
|
+
textAlign: _zod.z.string()
|
|
35
|
+
};
|
|
36
|
+
const GEN_UI_STYLE_HINTS = exports.GEN_UI_STYLE_HINTS = {
|
|
37
|
+
flex: {
|
|
38
|
+
type: 'number',
|
|
39
|
+
description: 'Flex grow/shrink basis value.'
|
|
40
|
+
},
|
|
41
|
+
padding: {
|
|
42
|
+
type: 'number',
|
|
43
|
+
description: 'Padding in density-independent px.'
|
|
44
|
+
},
|
|
45
|
+
gap: {
|
|
46
|
+
type: 'number',
|
|
47
|
+
description: 'Spacing between children in density-independent px.'
|
|
48
|
+
},
|
|
49
|
+
backgroundColor: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'React Native color value.'
|
|
52
|
+
},
|
|
53
|
+
color: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'Text color value.'
|
|
56
|
+
},
|
|
57
|
+
fontSize: {
|
|
58
|
+
type: 'number',
|
|
59
|
+
description: 'Font size in points.'
|
|
60
|
+
},
|
|
61
|
+
fontWeight: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
description: 'Font weight string like "400", "600", "bold".'
|
|
64
|
+
},
|
|
65
|
+
textAlign: {
|
|
66
|
+
type: 'string',
|
|
67
|
+
description: 'Text alignment, for example "left", "center", "right".'
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_zod","require","DEFAULT_GEN_UI_ROOT_ID","exports","GEN_UI_NODE_NAMES","Text","Paragraph","Label","Heading","Button","TextInput","GEN_UI_NODE_NAMES_THAT_SUPPORT_CHILDREN","GEN_UI_NODE_HINTS","GEN_UI_STYLES","flex","z","number","padding","gap","backgroundColor","string","color","fontSize","fontWeight","textAlign","GEN_UI_STYLE_HINTS","type","description"],"sourceRoot":"../../src","sources":["registry.ts"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAaO,MAAMC,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG,MAAM;AAErC,MAAME,iBAAiB,GAAAD,OAAA,CAAAC,iBAAA,GAAG;EAC/BC,IAAI,EAAE,MAAM;EACZC,SAAS,EAAE,WAAW;EACtBC,KAAK,EAAE,OAAO;EACdC,OAAO,EAAE,SAAS;EAClBC,MAAM,EAAE,QAAQ;EAChBC,SAAS,EAAE;AACb,CAAU;AAEH,MAAMC,uCAAiD,GAAAR,OAAA,CAAAQ,uCAAA,GAAG,EAAE;AAE5D,MAAMC,iBAAiE,GAAAT,OAAA,CAAAS,iBAAA,GAC5E;EACEP,IAAI,EAAE,yDAAyD;EAC/DC,SAAS,EAAE,kDAAkD;EAC7DC,KAAK,EAAE,oDAAoD;EAC3DC,OAAO,EAAE,mDAAmD;EAC5DC,MAAM,EAAE,mDAAmD;EAC3DC,SAAS,EACP;AACJ,CAAC;AAEI,MAAMG,aAAa,GAAAV,OAAA,CAAAU,aAAA,GAAG;EAC3BC,IAAI,EAAEC,MAAC,CAACC,MAAM,CAAC,CAAC;EAChBC,OAAO,EAAEF,MAAC,CAACC,MAAM,CAAC,CAAC;EACnBE,GAAG,EAAEH,MAAC,CAACC,MAAM,CAAC,CAAC;EACfG,eAAe,EAAEJ,MAAC,CAACK,MAAM,CAAC,CAAC;EAC3BC,KAAK,EAAEN,MAAC,CAACK,MAAM,CAAC,CAAC;EACjBE,QAAQ,EAAEP,MAAC,CAACC,MAAM,CAAC,CAAC;EACpBO,UAAU,EAAER,MAAC,CAACK,MAAM,CAAC,CAAC;EACtBI,SAAS,EAAET,MAAC,CAACK,MAAM,CAAC;AACtB,CAAC;AAEM,MAAMK,kBAGZ,GAAAtB,OAAA,CAAAsB,kBAAA,GAAG;EACFX,IAAI,EAAE;IAAEY,IAAI,EAAE,QAAQ;IAAEC,WAAW,EAAE;EAAgC,CAAC;EACtEV,OAAO,EAAE;IACPS,IAAI,EAAE,QAAQ;IACdC,WAAW,EAAE;EACf,CAAC;EACDT,GAAG,EAAE;IACHQ,IAAI,EAAE,QAAQ;IACdC,WAAW,EAAE;EACf,CAAC;EACDR,eAAe,EAAE;IAAEO,IAAI,EAAE,QAAQ;IAAEC,WAAW,EAAE;EAA4B,CAAC;EAC7EN,KAAK,EAAE;IAAEK,IAAI,EAAE,QAAQ;IAAEC,WAAW,EAAE;EAAoB,CAAC;EAC3DL,QAAQ,EAAE;IAAEI,IAAI,EAAE,QAAQ;IAAEC,WAAW,EAAE;EAAuB,CAAC;EACjEJ,UAAU,EAAE;IACVG,IAAI,EAAE,QAAQ;IACdC,WAAW,EAAE;EACf,CAAC;EACDH,SAAS,EAAE;IACTE,IAAI,EAAE,QAAQ;IACdC,WAAW,EAAE;EACf;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createGenUITools = createGenUITools;
|
|
7
|
+
var _ai = require("ai");
|
|
8
|
+
var _zod = require("zod");
|
|
9
|
+
var _registry = require("./registry");
|
|
10
|
+
/**
|
|
11
|
+
* Sometimes LLMs call tools with a string instead of an object.
|
|
12
|
+
*/
|
|
13
|
+
function smartParse(props) {
|
|
14
|
+
return typeof props === 'string' ? JSON.parse(props) : props;
|
|
15
|
+
}
|
|
16
|
+
const defaultCreateId = () => `UI-${Date.now().toString(36)}-${Math.random().toString(16).slice(2)}`;
|
|
17
|
+
const cloneSpec = spec => ({
|
|
18
|
+
...spec,
|
|
19
|
+
elements: Object.fromEntries(Object.entries(spec.elements).map(([id, element]) => [id, {
|
|
20
|
+
...element,
|
|
21
|
+
props: {
|
|
22
|
+
...(element.props ?? {})
|
|
23
|
+
},
|
|
24
|
+
children: [...(element.children ?? [])]
|
|
25
|
+
}]))
|
|
26
|
+
});
|
|
27
|
+
let mutationQueue = Promise.resolve();
|
|
28
|
+
const withMutationLock = async run => {
|
|
29
|
+
let release = () => {};
|
|
30
|
+
const pending = new Promise(resolve => {
|
|
31
|
+
release = resolve;
|
|
32
|
+
});
|
|
33
|
+
const previous = mutationQueue;
|
|
34
|
+
mutationQueue = mutationQueue.then(() => pending);
|
|
35
|
+
await previous;
|
|
36
|
+
try {
|
|
37
|
+
return await run();
|
|
38
|
+
} finally {
|
|
39
|
+
release();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Creates generative UI tools that read/update a JSON UI spec.
|
|
45
|
+
*/
|
|
46
|
+
function createGenUITools({
|
|
47
|
+
contextId,
|
|
48
|
+
getSpec,
|
|
49
|
+
updateSpec,
|
|
50
|
+
createId = defaultCreateId,
|
|
51
|
+
rootId = _registry.DEFAULT_GEN_UI_ROOT_ID,
|
|
52
|
+
nodeHints = _registry.GEN_UI_NODE_HINTS,
|
|
53
|
+
nodeNamesThatSupportChildren = _registry.GEN_UI_NODE_NAMES_THAT_SUPPORT_CHILDREN,
|
|
54
|
+
toolWrapper = (_, execute) => execute
|
|
55
|
+
}) {
|
|
56
|
+
// Serialize mutating tool calls to avoid interleaving writes.
|
|
57
|
+
let cachedSpec = null;
|
|
58
|
+
const readSpec = () => {
|
|
59
|
+
if (cachedSpec) return cloneSpec(cachedSpec);
|
|
60
|
+
const spec = getSpec(contextId);
|
|
61
|
+
if (!spec) return null;
|
|
62
|
+
cachedSpec = cloneSpec(spec);
|
|
63
|
+
return cloneSpec(cachedSpec);
|
|
64
|
+
};
|
|
65
|
+
const commitSpec = spec => {
|
|
66
|
+
cachedSpec = spec ? cloneSpec(spec) : null;
|
|
67
|
+
updateSpec(contextId, spec ? cloneSpec(spec) : null);
|
|
68
|
+
};
|
|
69
|
+
const getUIRootNode = (0, _ai.tool)({
|
|
70
|
+
description: 'Get the root node of the generative UI tree. Returns id, type, props, and children (array of { id, type }). Root always exists with id "root".',
|
|
71
|
+
inputSchema: _zod.z.object({}),
|
|
72
|
+
execute: toolWrapper('getUIRootNode', async () => {
|
|
73
|
+
const spec = readSpec();
|
|
74
|
+
if (!spec?.root || !spec.elements[spec.root]) return {
|
|
75
|
+
root: null
|
|
76
|
+
};
|
|
77
|
+
const element = spec.elements[spec.root];
|
|
78
|
+
const children = (element.children ?? []).map(id => ({
|
|
79
|
+
id,
|
|
80
|
+
type: spec.elements[id]?.type ?? 'unknown'
|
|
81
|
+
}));
|
|
82
|
+
return {
|
|
83
|
+
root: {
|
|
84
|
+
id: spec.root,
|
|
85
|
+
type: element.type,
|
|
86
|
+
props: element.props,
|
|
87
|
+
children
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
const getUINode = (0, _ai.tool)({
|
|
93
|
+
description: 'Get a node by id. Returns id, type, props, and children (array of { id, type }). If id is omitted, returns root node.',
|
|
94
|
+
inputSchema: _zod.z.object({
|
|
95
|
+
id: _zod.z.string().optional().describe('Node id; omit for root')
|
|
96
|
+
}),
|
|
97
|
+
execute: toolWrapper('getUINode', async ({
|
|
98
|
+
id
|
|
99
|
+
}) => {
|
|
100
|
+
const spec = readSpec();
|
|
101
|
+
if (!spec) return {
|
|
102
|
+
node: null
|
|
103
|
+
};
|
|
104
|
+
const nodeId = id ?? spec.root;
|
|
105
|
+
const element = spec.elements[nodeId];
|
|
106
|
+
if (!element) return {
|
|
107
|
+
node: null
|
|
108
|
+
};
|
|
109
|
+
const children = (element.children ?? []).map(childId => ({
|
|
110
|
+
id: childId,
|
|
111
|
+
type: spec.elements[childId]?.type ?? 'unknown'
|
|
112
|
+
}));
|
|
113
|
+
return {
|
|
114
|
+
node: {
|
|
115
|
+
id: nodeId,
|
|
116
|
+
type: element.type,
|
|
117
|
+
props: element.props,
|
|
118
|
+
children
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
const getUILayout = (0, _ai.tool)({
|
|
124
|
+
description: 'Get compact UI layout.',
|
|
125
|
+
inputSchema: _zod.z.object({}),
|
|
126
|
+
execute: toolWrapper('getUILayout', async () => {
|
|
127
|
+
const spec = readSpec();
|
|
128
|
+
if (!spec) return {
|
|
129
|
+
root: null,
|
|
130
|
+
nodes: []
|
|
131
|
+
};
|
|
132
|
+
const parentByChild = {};
|
|
133
|
+
for (const [id, element] of Object.entries(spec.elements)) {
|
|
134
|
+
for (const childId of element.children ?? []) {
|
|
135
|
+
parentByChild[childId] = id;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const nodes = Object.entries(spec.elements).map(([id, element]) => ({
|
|
139
|
+
id,
|
|
140
|
+
type: element.type,
|
|
141
|
+
parentId: parentByChild[id] ?? null,
|
|
142
|
+
children: element.children ?? [],
|
|
143
|
+
props: Object.keys(element.props ?? {})
|
|
144
|
+
}));
|
|
145
|
+
return {
|
|
146
|
+
root: spec.root,
|
|
147
|
+
nodes
|
|
148
|
+
};
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
const getAvailableUINodes = (0, _ai.tool)({
|
|
152
|
+
description: 'List nodes + props.',
|
|
153
|
+
inputSchema: _zod.z.object({}),
|
|
154
|
+
execute: toolWrapper('getAvailableUINodes', async () => ({
|
|
155
|
+
nodes: Object.entries(nodeHints).map(([name, props]) => ({
|
|
156
|
+
name,
|
|
157
|
+
props
|
|
158
|
+
}))
|
|
159
|
+
}))
|
|
160
|
+
});
|
|
161
|
+
const setUINodeProps = (0, _ai.tool)({
|
|
162
|
+
description: 'Set or add props for a node by id.',
|
|
163
|
+
inputSchema: _zod.z.object({
|
|
164
|
+
id: _zod.z.string().describe('Node id'),
|
|
165
|
+
props: _zod.z.string().describe('Props object for the node'),
|
|
166
|
+
replace: _zod.z.boolean().optional().describe('Replace existing props')
|
|
167
|
+
}),
|
|
168
|
+
execute: toolWrapper('setUINodeProps', async ({
|
|
169
|
+
id,
|
|
170
|
+
props: propsArg,
|
|
171
|
+
replace = false
|
|
172
|
+
}) => withMutationLock(async () => {
|
|
173
|
+
const parsedProps = smartParse(propsArg);
|
|
174
|
+
const spec = readSpec();
|
|
175
|
+
if (!spec) return {
|
|
176
|
+
success: false,
|
|
177
|
+
message: 'No UI spec'
|
|
178
|
+
};
|
|
179
|
+
if (!spec.elements[id]) {
|
|
180
|
+
return {
|
|
181
|
+
success: false,
|
|
182
|
+
message: 'Node not found'
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const elements = {
|
|
186
|
+
...spec.elements
|
|
187
|
+
};
|
|
188
|
+
const current = elements[id];
|
|
189
|
+
const nextProps = replace ? parsedProps : {
|
|
190
|
+
...current.props,
|
|
191
|
+
...parsedProps
|
|
192
|
+
};
|
|
193
|
+
elements[id] = {
|
|
194
|
+
...current,
|
|
195
|
+
props: nextProps
|
|
196
|
+
};
|
|
197
|
+
commitSpec({
|
|
198
|
+
root: spec.root,
|
|
199
|
+
elements
|
|
200
|
+
});
|
|
201
|
+
return {
|
|
202
|
+
success: true
|
|
203
|
+
};
|
|
204
|
+
}))
|
|
205
|
+
});
|
|
206
|
+
const deleteUINode = (0, _ai.tool)({
|
|
207
|
+
description: 'Delete a node by id. Cannot delete the root node (id "root"). Removes the node and its reference from the parent\'s children.',
|
|
208
|
+
inputSchema: _zod.z.object({
|
|
209
|
+
id: _zod.z.string().describe('Node id to delete')
|
|
210
|
+
}),
|
|
211
|
+
execute: toolWrapper('deleteUINode', async ({
|
|
212
|
+
id
|
|
213
|
+
}) => withMutationLock(async () => {
|
|
214
|
+
if (id === rootId) {
|
|
215
|
+
return {
|
|
216
|
+
success: false,
|
|
217
|
+
message: 'Cannot delete root node'
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const spec = readSpec();
|
|
221
|
+
if (!spec) return {
|
|
222
|
+
success: false,
|
|
223
|
+
message: 'No UI spec'
|
|
224
|
+
};
|
|
225
|
+
const elements = {
|
|
226
|
+
...spec.elements
|
|
227
|
+
};
|
|
228
|
+
delete elements[id];
|
|
229
|
+
for (const key of Object.keys(elements)) {
|
|
230
|
+
const element = elements[key];
|
|
231
|
+
if (element.children?.includes(id)) {
|
|
232
|
+
elements[key] = {
|
|
233
|
+
...element,
|
|
234
|
+
children: element.children.filter(childId => childId !== id)
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
commitSpec({
|
|
239
|
+
root: spec.root,
|
|
240
|
+
elements
|
|
241
|
+
});
|
|
242
|
+
return {
|
|
243
|
+
success: true
|
|
244
|
+
};
|
|
245
|
+
}))
|
|
246
|
+
});
|
|
247
|
+
const addUINode = (0, _ai.tool)({
|
|
248
|
+
description: 'Add a new node as a child of parentId. Creates element with type and props. Returns new node id. Props must be a valid JSON object.',
|
|
249
|
+
inputSchema: _zod.z.object({
|
|
250
|
+
parentId: _zod.z.string().optional().describe('Parent node id; omit for root'),
|
|
251
|
+
type: _zod.z.string().describe('Component type (e.g. Container, Column, Text, Button)'),
|
|
252
|
+
props: _zod.z.string().optional().describe('Props object for the node')
|
|
253
|
+
}),
|
|
254
|
+
execute: toolWrapper('addUINode', async ({
|
|
255
|
+
parentId,
|
|
256
|
+
type,
|
|
257
|
+
props: propsArg
|
|
258
|
+
}) => withMutationLock(async () => {
|
|
259
|
+
const parsedProps = smartParse(propsArg ?? '{}');
|
|
260
|
+
const spec = readSpec();
|
|
261
|
+
if (!spec) {
|
|
262
|
+
console.warn('[json-ui-lite-rn tool addNode] No UI spec, aborting');
|
|
263
|
+
return {
|
|
264
|
+
success: false,
|
|
265
|
+
message: 'No UI spec'
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
parentId ??= spec.root;
|
|
269
|
+
if (!spec.elements[parentId]) {
|
|
270
|
+
console.warn('[json-ui-lite-rn tool addNode] Parent not found, aborting');
|
|
271
|
+
return {
|
|
272
|
+
success: false,
|
|
273
|
+
message: 'Parent not found'
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const newId = createId();
|
|
277
|
+
spec.elements[newId] = {
|
|
278
|
+
type,
|
|
279
|
+
props: parsedProps ?? {},
|
|
280
|
+
children: []
|
|
281
|
+
};
|
|
282
|
+
let parent = spec.elements[parentId];
|
|
283
|
+
if (!nodeNamesThatSupportChildren.includes(parent.type)) {
|
|
284
|
+
parent = spec.elements[spec.root];
|
|
285
|
+
parentId = spec.root;
|
|
286
|
+
}
|
|
287
|
+
spec.elements[parentId].children ??= [];
|
|
288
|
+
spec.elements[parentId].children.push(newId);
|
|
289
|
+
commitSpec({
|
|
290
|
+
root: spec.root,
|
|
291
|
+
elements: spec.elements
|
|
292
|
+
});
|
|
293
|
+
return {
|
|
294
|
+
success: true,
|
|
295
|
+
id: newId
|
|
296
|
+
};
|
|
297
|
+
}))
|
|
298
|
+
});
|
|
299
|
+
const reorderUINodes = (0, _ai.tool)({
|
|
300
|
+
description: 'Move one node among siblings by offset (negative = up, positive = down).',
|
|
301
|
+
inputSchema: _zod.z.object({
|
|
302
|
+
nodeId: _zod.z.string().describe('Node id to move'),
|
|
303
|
+
offset: _zod.z.number().describe('Relative index shift among siblings; negative moves earlier, positive moves later')
|
|
304
|
+
}),
|
|
305
|
+
execute: toolWrapper('reorderUINodes', async ({
|
|
306
|
+
nodeId,
|
|
307
|
+
offset
|
|
308
|
+
}) => withMutationLock(async () => {
|
|
309
|
+
const spec = readSpec();
|
|
310
|
+
if (!spec) return {
|
|
311
|
+
success: false,
|
|
312
|
+
message: 'No UI spec'
|
|
313
|
+
};
|
|
314
|
+
const findParentId = childId => {
|
|
315
|
+
for (const [id, element] of Object.entries(spec.elements)) {
|
|
316
|
+
if (element.children?.includes(childId)) return id;
|
|
317
|
+
}
|
|
318
|
+
return null;
|
|
319
|
+
};
|
|
320
|
+
const nodeParentId = findParentId(nodeId);
|
|
321
|
+
if (!nodeParentId) {
|
|
322
|
+
return {
|
|
323
|
+
success: false,
|
|
324
|
+
message: 'nodeId must exist and have a parent'
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
const parentId = nodeParentId;
|
|
328
|
+
const parent = spec.elements[parentId];
|
|
329
|
+
if (!parent) return {
|
|
330
|
+
success: false,
|
|
331
|
+
message: 'Parent not found'
|
|
332
|
+
};
|
|
333
|
+
const currentChildren = [...(parent.children ?? [])];
|
|
334
|
+
const nodeIndex = currentChildren.indexOf(nodeId);
|
|
335
|
+
if (nodeIndex === -1) {
|
|
336
|
+
return {
|
|
337
|
+
success: false,
|
|
338
|
+
message: 'nodeId must be a direct child'
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
if (offset === 0) {
|
|
342
|
+
return {
|
|
343
|
+
success: true,
|
|
344
|
+
parentId,
|
|
345
|
+
nodeId,
|
|
346
|
+
fromIndex: nodeIndex,
|
|
347
|
+
toIndex: nodeIndex,
|
|
348
|
+
appliedOffset: 0,
|
|
349
|
+
childIds: currentChildren
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
const maxIndex = currentChildren.length - 1;
|
|
353
|
+
const toIndex = Math.min(Math.max(nodeIndex + offset, 0), maxIndex);
|
|
354
|
+
currentChildren.splice(nodeIndex, 1);
|
|
355
|
+
currentChildren.splice(toIndex, 0, nodeId);
|
|
356
|
+
const elements = {
|
|
357
|
+
...spec.elements
|
|
358
|
+
};
|
|
359
|
+
elements[parentId].children = currentChildren;
|
|
360
|
+
commitSpec({
|
|
361
|
+
root: spec.root,
|
|
362
|
+
elements
|
|
363
|
+
});
|
|
364
|
+
return {
|
|
365
|
+
success: true,
|
|
366
|
+
parentId,
|
|
367
|
+
nodeId,
|
|
368
|
+
fromIndex: nodeIndex,
|
|
369
|
+
toIndex,
|
|
370
|
+
appliedOffset: toIndex - nodeIndex,
|
|
371
|
+
childIds: currentChildren
|
|
372
|
+
};
|
|
373
|
+
}))
|
|
374
|
+
});
|
|
375
|
+
return {
|
|
376
|
+
getUIRootNode,
|
|
377
|
+
getUINode,
|
|
378
|
+
getUILayout,
|
|
379
|
+
getAvailableUINodes,
|
|
380
|
+
setUINodeProps,
|
|
381
|
+
deleteUINode,
|
|
382
|
+
addUINode,
|
|
383
|
+
reorderUINodes
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_ai","require","_zod","_registry","smartParse","props","JSON","parse","defaultCreateId","Date","now","toString","Math","random","slice","cloneSpec","spec","elements","Object","fromEntries","entries","map","id","element","children","mutationQueue","Promise","resolve","withMutationLock","run","release","pending","previous","then","createGenUITools","contextId","getSpec","updateSpec","createId","rootId","DEFAULT_GEN_UI_ROOT_ID","nodeHints","GEN_UI_NODE_HINTS","nodeNamesThatSupportChildren","GEN_UI_NODE_NAMES_THAT_SUPPORT_CHILDREN","toolWrapper","_","execute","cachedSpec","readSpec","commitSpec","getUIRootNode","tool","description","inputSchema","z","object","root","type","getUINode","string","optional","describe","node","nodeId","childId","getUILayout","nodes","parentByChild","parentId","keys","getAvailableUINodes","name","setUINodeProps","replace","boolean","propsArg","parsedProps","success","message","current","nextProps","deleteUINode","key","includes","filter","addUINode","console","warn","newId","parent","push","reorderUINodes","offset","number","findParentId","nodeParentId","currentChildren","nodeIndex","indexOf","fromIndex","toIndex","appliedOffset","childIds","maxIndex","length","min","max","splice"],"sourceRoot":"../../src","sources":["tools.ts"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAF,OAAA;AAOA;AACA;AACA;AACA,SAASG,UAAUA,CACjBC,KA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CAAC;MAElD,OAAO;QACL6D,OAAO,EAAE,IAAI;QACbT,QAAQ;QACRL,MAAM;QACNoC,SAAS,EAAEF,SAAS;QACpBG,OAAO;QACPC,aAAa,EAAED,OAAO,GAAGH,SAAS;QAClCK,QAAQ,EAAEN;MACZ,CAAC;IACH,CAAC,CACH;EACF,CAAC,CAAC;EAEF,OAAO;IACL9C,aAAa;IACbQ,SAAS;IACTO,WAAW;IACXK,mBAAmB;IACnBE,cAAc;IACdS,YAAY;IACZI,SAAS;IACTM;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
|
|
5
|
+
import { parseGenUIElementProps } from './parseGenUIProps';
|
|
6
|
+
import { GEN_UI_NODE_NAMES } from './registry';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export function GenUINode({
|
|
9
|
+
nodeId,
|
|
10
|
+
elements,
|
|
11
|
+
styles: styleValidators,
|
|
12
|
+
GenUINodeComponent
|
|
13
|
+
}) {
|
|
14
|
+
const element = elements[nodeId];
|
|
15
|
+
if (!element) return null;
|
|
16
|
+
const {
|
|
17
|
+
type,
|
|
18
|
+
props,
|
|
19
|
+
children = []
|
|
20
|
+
} = element;
|
|
21
|
+
const {
|
|
22
|
+
baseStyle,
|
|
23
|
+
text,
|
|
24
|
+
label
|
|
25
|
+
} = parseGenUIElementProps(element, styleValidators, {
|
|
26
|
+
nodeId,
|
|
27
|
+
type
|
|
28
|
+
});
|
|
29
|
+
const ChildRenderer = GenUINodeComponent ?? GenUINode;
|
|
30
|
+
const childProps = {
|
|
31
|
+
elements,
|
|
32
|
+
styles: styleValidators,
|
|
33
|
+
GenUINodeComponent
|
|
34
|
+
};
|
|
35
|
+
switch (type) {
|
|
36
|
+
case 'Container':
|
|
37
|
+
return /*#__PURE__*/_jsx(View, {
|
|
38
|
+
style: [styles.container, baseStyle],
|
|
39
|
+
children: children.map(id => /*#__PURE__*/_jsx(ChildRenderer, {
|
|
40
|
+
...childProps,
|
|
41
|
+
nodeId: id
|
|
42
|
+
}, id))
|
|
43
|
+
});
|
|
44
|
+
case GEN_UI_NODE_NAMES.Text:
|
|
45
|
+
case GEN_UI_NODE_NAMES.Paragraph:
|
|
46
|
+
case GEN_UI_NODE_NAMES.Label:
|
|
47
|
+
case GEN_UI_NODE_NAMES.Heading:
|
|
48
|
+
return /*#__PURE__*/_jsx(Text, {
|
|
49
|
+
style: [styles.text, baseStyle],
|
|
50
|
+
children: text ?? label ?? ''
|
|
51
|
+
});
|
|
52
|
+
case GEN_UI_NODE_NAMES.Button:
|
|
53
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
54
|
+
style: [styles.button, baseStyle],
|
|
55
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
56
|
+
style: [styles.buttonText, baseStyle],
|
|
57
|
+
children: label ?? text ?? ''
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
case GEN_UI_NODE_NAMES.TextInput:
|
|
61
|
+
return /*#__PURE__*/_jsx(TextInput, {
|
|
62
|
+
placeholder: props?.placeholder,
|
|
63
|
+
style: [styles.textInput, baseStyle],
|
|
64
|
+
onChangeText: () => {}
|
|
65
|
+
});
|
|
66
|
+
default:
|
|
67
|
+
return /*#__PURE__*/_jsx(View, {
|
|
68
|
+
style: [styles.container, baseStyle],
|
|
69
|
+
children: children.map(id => /*#__PURE__*/_jsx(ChildRenderer, {
|
|
70
|
+
...childProps,
|
|
71
|
+
nodeId: id
|
|
72
|
+
}, id))
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const styles = StyleSheet.create({
|
|
77
|
+
container: {
|
|
78
|
+
gap: 8,
|
|
79
|
+
flex: 1
|
|
80
|
+
},
|
|
81
|
+
text: {
|
|
82
|
+
fontSize: 16,
|
|
83
|
+
color: '#111827',
|
|
84
|
+
flex: 1
|
|
85
|
+
},
|
|
86
|
+
button: {
|
|
87
|
+
paddingHorizontal: 16,
|
|
88
|
+
paddingVertical: 10,
|
|
89
|
+
backgroundColor: '#3b82f6',
|
|
90
|
+
borderRadius: 8,
|
|
91
|
+
alignSelf: 'flex-start',
|
|
92
|
+
flex: 1
|
|
93
|
+
},
|
|
94
|
+
buttonText: {
|
|
95
|
+
flex: 1,
|
|
96
|
+
color: 'white'
|
|
97
|
+
},
|
|
98
|
+
textInput: {
|
|
99
|
+
borderWidth: 1,
|
|
100
|
+
borderColor: '#e0e0e0',
|
|
101
|
+
borderRadius: 8,
|
|
102
|
+
padding: 8,
|
|
103
|
+
fontSize: 16,
|
|
104
|
+
color: '#111827',
|
|
105
|
+
flex: 1
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
//# sourceMappingURL=GenUINode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","Pressable","StyleSheet","Text","TextInput","View","parseGenUIElementProps","GEN_UI_NODE_NAMES","jsx","_jsx","GenUINode","nodeId","elements","styles","styleValidators","GenUINodeComponent","element","type","props","children","baseStyle","text","label","ChildRenderer","childProps","style","container","map","id","Paragraph","Label","Heading","Button","button","buttonText","placeholder","textInput","onChangeText","create","gap","flex","fontSize","color","paddingHorizontal","paddingVertical","backgroundColor","borderRadius","alignSelf","borderWidth","borderColor","padding"],"sourceRoot":"../../src","sources":["GenUINode.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS,EAAEC,UAAU,EAAEC,IAAI,EAAEC,SAAS,EAAEC,IAAI,QAAQ,cAAc;AAG3E,SAASC,sBAAsB,QAAQ,mBAAmB;AAC1D,SAASC,iBAAiB,QAAyB,YAAY;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAU/D,OAAO,SAASC,SAASA,CAAC;EACxBC,MAAM;EACNC,QAAQ;EACRC,MAAM,EAAEC,eAAe;EACvBC;AACc,C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