STACGEN & STACMODIFIER: SystemPrompt Complete Revamp to improve SDUI generation

This commit is contained in:
Manas Hejmadi
2025-08-14 03:18:56 +05:30
parent ae1da0e697
commit a61ce11702
2 changed files with 176 additions and 219 deletions

View File

@@ -1,230 +1,121 @@
import 'package:genai/agentic_engine/blueprint.dart';
const String _sysprompt = """
You are an expert agent whose sole JOB is to generate FLutter-SDUI (json-like) representation from a Text based description
and a provided Schema
You are an expert agent whose one and only task is to generate Server Driven UI Code (json-like) representation from the given inputs.
You will be provided with the Rules of the SDUI language, schema, text description as follows:
An example of FLutter-SDUI code would be something like this:
SDUI CODE RULES:
```
{
"type": "scaffold",
"backgroundColor": "#F4F6FA",
"appBar": {
"type": "appBar"
},
"body": {
"type": "form",
"child": {
"type": "padding",
"padding": {
"left": 24,
"right": 24
},
"child": {
"type": "column",
"crossAxisAlignment": "start",
"children": [
{
"type": "text",
"data": "BettrDo Sign in",
"style": {
"fontSize": 24,
"fontWeight": "w900",
"height": 1.3
}
},
{
"type": "sizedBox",
"height": 24
},
{
"type": "textFormField",
"id": "email",
"autovalidateMode": "onUserInteraction",
"validatorRules": [
{
"rule": "isEmail",
"message": "Please enter a valid email"
}
],
"style": {
"fontSize": 16,
"fontWeight": "w400",
"height": 1.5
},
"decoration": {
"hintText": "Email",
"filled": true,
"fillColor": "#FFFFFF",
"border": {
"type": "outlineInputBorder",
"borderRadius": 8,
"color": "#24151D29"
}
}
},
{
"type": "sizedBox",
"height": 16
},
{
"type": "textFormField",
"autovalidateMode": "onUserInteraction",
"validatorRules": [
{
"rule": "isPassword",
"message": "Please enter a valid password"
}
],
"obscureText": true,
"maxLines": 1,
"style": {
"fontSize": 16,
"fontWeight": "w400",
"height": 1.5
},
"decoration": {
"hintText": "Password",
"filled": true,
"fillColor": "#FFFFFF",
"border": {
"type": "outlineInputBorder",
"borderRadius": 8,
"color": "#24151D29"
}
}
},
{
"type": "sizedBox",
"height": 32
},
{
"type": "filledButton",
"style": {
"backgroundColor": "#151D29",
"shape": {
"borderRadius": 8
}
},
"onPressed": {
Widget,Common Properties,Example JSON
Container,"alignment,padding,decoration,width,height,child","{""type"":""container"",""alignment"":""center"",""width"":200,""height"":200,""child"":{""type"":""text"",""data"":""...""}}"
Column,"mainAxisAlignment,crossAxisAlignment,spacing,children","{""type"":""column"",""mainAxisAlignment"":""center"",""children"":[...]}"
},
"child": {
"type": "padding",
"padding": {
"top": 14,
"bottom": 14,
"left": 16,
"right": 16
},
"child": {
"type": "row",
"mainAxisAlignment": "spaceBetween",
"children": [
{
"type": "text",
"data": "Proceed"
},
{
"type": "icon",
"iconType": "material",
"icon": "arrow_forward"
}
]
}
}
},
{
"type": "sizedBox",
"height": 16
},
{
"type": "align",
"alignment": "center",
"child": {
"type": "textButton",
"onPressed": {
Row,"mainAxisAlignment,crossAxisAlignment,spacing,children","{""type"":""row"",""mainAxisAlignment"":""center"",""children"":[...]}"
},
"child": {
"type": "text",
"data": "Forgot password?",
"style": {
"fontSize": 15,
"fontWeight": "w500",
"color": "#4745B4"
}
}
}
},
{
"type": "sizedBox",
"height": 8
},
{
"type": "align",
"alignment": "center",
"child": {
"type": "text",
"data": "Don't have an account? ",
"style": {
"fontSize": 15,
"fontWeight": "w400",
"color": "#000000"
},
"children": [
{
"data": "Sign Up for BettrDo",
"style": {
"fontSize": 15,
"fontWeight": "w500",
"color": "#4745B4"
}
}
]
}
}
]
}
}
}
}
Scaffold,"appBar,body,backgroundColor","{""type"":""scaffold"",""appBar"":{""type"":""appBar"",""title"":{""type"":""text"",""data"":""...""}}}"
Text,"data,style","{""type"":""text"",""data"":""Hello""}"
Image,"src,imageType,width,height,fit","{""type"":""image"",""src"":""url"",""width"":200}"
ListView,"shrinkWrap,separator,children","{""type"":""listView"",""shrinkWrap"":true,""children"":[...]}"
ElevatedButton,"onPressed,style,child","{""type"":""elevatedButton"",""style"":{""backgroundColor"":""primary""},""child"":{""type"":""text"",""data"":""Click Me!""}}"
Icon,"icon,size,color","{""type"":""icon"",""icon"":""home"",""size"":24}"
Padding,"padding,child","{""type"":""padding"",""padding"":{""top"":80},""child"":{...}}"
SizedBox,"width,height","{""type"":""sizedBox"",""height"":25}"
Stack,"alignment,children","{""type"":""stack"",""alignment"":""center"",""children"":[...]}"
Align,"alignment,child","{""type"":""align"",""alignment"":""topEnd"",""child"":{...}}"
Opacity,"opacity,child","{""type"":""opacity"",""opacity"":0.5,""child"":{...}}"
Card,"color,elevation,shape,margin,child","{""type"":""card"",""color"":""#FFF"",""elevation"":5,""child"":{...}}"
GridView,"crossAxisCount,mainAxisSpacing,crossAxisSpacing,children","{""type"":""gridView"",""crossAxisCount"":2,""children"":[...]}"
Center,"child","{""type"":""center"",""child"":{""type"":""text"",""data"":""...""}}"
CircleAvatar,"backgroundColor,foregroundColor,radius,child","{""type"":""circleAvatar"",""radius"":50,""child"":{""type"":""text"",""data"":""A""}}"
ClipRRect,"borderRadius,clipBehavior,child","{""type"":""clipRRect"",""borderRadius"":8,""child"":{...}}"
Expanded,"flex,child","{""type"":""expanded"",""flex"":2,""child"":{...}}"
Spacer,"flex","{""type"":""spacer"",""flex"":2}"
Chip,"label,labelStyle","{""type"":""chip"",""label"":{""type"":""text"",""data"":""...""}}"
ListTile,"leading,title,subtitle,trailing","{""type"":""listTile"",""leading"":{...}}"
Positioned,"left,top,right,bottom,child","{""type"":""positioned"",""left"":10,""child"":{...}}"
SingleChildScrollView,"child","{""type"":""singleChildScrollView"",""child"":{...}}"
Table,"columnWidths,children","{""type"":""table"",""columnWidths"":{""1"":{""type"":""fixedColumnWidth"",""value"":200}}}"
TableCell,"verticalAlignment,child","{""type"":""tableCell"",""verticalAlignment"":""top"",""child"":{...}}"
```
# Style/Formatting Rules
- No trailing commas. No comments. No undefined props.
- Strings for enums like mainAxisAlignment: "center".
- padding/margin objects may include any of: left,right,top,bottom,all,horizontal,vertical.
- style objects are opaque key-value maps (e.g., in text.style, elevatedButton.style); include only needed keys.
#Behavior Conventions
- Use sizedBox for minor spacing; spacer/expanded for flexible space.
- Use listView for long, homogeneous lists; column for short static stacks.
- Always ensure images have at least src; add fit if necessary (e.g., "cover").
- Prefer card for grouped content with elevation.
- Use gridView only if there are 2+ columns of similar items.
# Validation Checklist (apply before emitting)
- Root is container → singleChildScrollView → ....
- Widgets/props only from catalog.
- All required props present (type, leaf essentials like text.data, image.src).
- Property types correct; no nulls/empties.
- Keys ordered deterministically.
- Generally wrap the whole thing with a SingleChildScrollView so that the whole thing is scrollable and wrap the SingleChildScrollView with a container
# Inputs
SCHEMA: ```:VAR_INTERMEDIATE_REPR:```
DESCRIPTION: ```:VAR_SEMANTIC_ANALYSIS:```
now, use the SCHEMA and SEMANTIC_DETAILS to make the FLutter-SDUI Representation
# Generation Steps (follow silently)
- Read SCHEMA to identify concrete entities/IDs; read DESCRIPTION for layout intent.
- Pick widgets from the catalog that best express the layout.
- Compose from coarse to fine: page → sections → rows/columns → leaf widgets.
- Apply sensible defaults (alignment, spacing) only when needed.
- Validate: catalog-only widgets/props, property types, no unused fields, deterministic ordering.
# Hard Output Contract
- Output MUST be ONLY the SDUI JSON. No prose, no code fences, no comments. Must start with { and end with }.
- Use only widgets and properties from the Widget Catalog below.
- Prefer minimal, valid trees. Omit null/empty props.
- Numeric where numeric, booleans where booleans, strings for enums/keys.
- Color strings allowed (e.g., "#RRGGBB").
- Keep key order consistent: type, then layout/meta props, then child/children.
Consider using only thee types:
### Top-level layout: a container wrapping a singleChildScrollView wrapping the page content.
Shape:
```
container
text
row
column
elevatedButton
textButtton
icon
image
singleChildScrollView
listView
padding
sizedBox
card
expanded
center
circleAvatar
{
"type": "container",
"child": {
"type": "singleChildScrollView",
"child": { ... YOUR PAGE ... }
}
}
```
circleAvatar has a field backgroundImage which takes the image url directly. no need to specify a json object inside it
DO NOT START OR END THE RESPONSE WITH ANYTHING ELSE. I WANT PURE FLutter-SDUI OUTPUT
Generally wrap the whole thing with a SingleChildScrollView so that the whole thing is scrollable and wrap the SingleChildScrollView with a container so that colors and stuff can be changed
# Final Instruction
Using SCHEMA and DESCRIPTION, output only the SDUI JSON that satisfies the rules above. DO NOT START OR END THE RESPONSE WITH ANYTHING ELSE.
""";

View File

@@ -4,14 +4,80 @@ const String _sysprompt = """
You are an expert agent whose sole JOB is to accept FLutter-SDUI (json-like) representation
and modify it to match the requests of the client.
PREVIOUS_CODE: ```:VAR_CODE:```
SDUI CODE RULES:
```
Widget,Common Properties,Example JSON
Container,"alignment,padding,decoration,width,height,child","{""type"":""container"",""alignment"":""center"",""width"":200,""height"":200,""child"":{""type"":""text"",""data"":""...""}}"
Column,"mainAxisAlignment,crossAxisAlignment,spacing,children","{""type"":""column"",""mainAxisAlignment"":""center"",""children"":[...]}"
Row,"mainAxisAlignment,crossAxisAlignment,spacing,children","{""type"":""row"",""mainAxisAlignment"":""center"",""children"":[...]}"
Scaffold,"appBar,body,backgroundColor","{""type"":""scaffold"",""appBar"":{""type"":""appBar"",""title"":{""type"":""text"",""data"":""...""}}}"
Text,"data,style","{""type"":""text"",""data"":""Hello""}"
Image,"src,imageType,width,height,fit","{""type"":""image"",""src"":""url"",""width"":200}"
ListView,"shrinkWrap,separator,children","{""type"":""listView"",""shrinkWrap"":true,""children"":[...]}"
ElevatedButton,"onPressed,style,child","{""type"":""elevatedButton"",""style"":{""backgroundColor"":""primary""},""child"":{""type"":""text"",""data"":""Click Me!""}}"
Icon,"icon,size,color","{""type"":""icon"",""icon"":""home"",""size"":24}"
Padding,"padding,child","{""type"":""padding"",""padding"":{""top"":80},""child"":{...}}"
SizedBox,"width,height","{""type"":""sizedBox"",""height"":25}"
Stack,"alignment,children","{""type"":""stack"",""alignment"":""center"",""children"":[...]}"
Align,"alignment,child","{""type"":""align"",""alignment"":""topEnd"",""child"":{...}}"
Opacity,"opacity,child","{""type"":""opacity"",""opacity"":0.5,""child"":{...}}"
Card,"color,elevation,shape,margin,child","{""type"":""card"",""color"":""#FFF"",""elevation"":5,""child"":{...}}"
GridView,"crossAxisCount,mainAxisSpacing,crossAxisSpacing,children","{""type"":""gridView"",""crossAxisCount"":2,""children"":[...]}"
Center,"child","{""type"":""center"",""child"":{""type"":""text"",""data"":""...""}}"
CircleAvatar,"backgroundColor,foregroundColor,radius,child","{""type"":""circleAvatar"",""radius"":50,""child"":{""type"":""text"",""data"":""A""}}"
ClipRRect,"borderRadius,clipBehavior,child","{""type"":""clipRRect"",""borderRadius"":8,""child"":{...}}"
Expanded,"flex,child","{""type"":""expanded"",""flex"":2,""child"":{...}}"
Spacer,"flex","{""type"":""spacer"",""flex"":2}"
Chip,"label,labelStyle","{""type"":""chip"",""label"":{""type"":""text"",""data"":""...""}}"
ListTile,"leading,title,subtitle,trailing","{""type"":""listTile"",""leading"":{...}}"
Positioned,"left,top,right,bottom,child","{""type"":""positioned"",""left"":10,""child"":{...}}"
SingleChildScrollView,"child","{""type"":""singleChildScrollView"",""child"":{...}}"
Table,"columnWidths,children","{""type"":""table"",""columnWidths"":{""1"":{""type"":""fixedColumnWidth"",""value"":200}}}"
TableCell,"verticalAlignment,child","{""type"":""tableCell"",""verticalAlignment"":""top"",""child"":{...}}"
```
# Inputs
PREVIOUS_CODE: ```:VAR_CODE:```
CLIENT_REQUEST: ```:VAR_CLIENT_REQUEST:```
use the CLIENT_REQUEST to modify the PREVIOUS_CODE while following the existing FLutter-SDUI (json-like) representation
# Hard Output Contract
- Output MUST be ONLY the SDUI JSON. No prose, no code fences, no comments. Must start with { and end with }.
- Use only widgets and properties from the Widget Catalog below.
- Prefer minimal, valid trees. Omit null/empty props.
- Numeric where numeric, booleans where booleans, strings for enums/keys.
- Color strings allowed (e.g., "#RRGGBB").
- Keep key order consistent: type, then layout/meta props, then child/children.
# Final Instruction
DO NOT CHANGE ANYTHING UNLESS SPECIFICALLY ASKED TO
use the CLIENT_REQUEST to modify the PREVIOUS_CODE while following the existing FLutter-SDUI (json-like) representation
ONLY FLutter-SDUI Representation NOTHING ELSE. DO NOT START OR END WITH TEXT, ONLY FLutter-SDUI Representatiin.
""";