AI UI-Designer & ToolGenerator: Added ErrorHandling

This commit is contained in:
Manas Hejmadi
2025-05-04 04:03:03 +05:30
parent 1057e07241
commit c6c0391b66
3 changed files with 102 additions and 31 deletions

View File

@@ -224,7 +224,7 @@ circleAvatar has a field backgroundImage which takes the image url directly. no
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
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
""";

View File

@@ -37,7 +37,7 @@ class _GenerateToolDialogState extends ConsumerState<GenerateToolDialog> {
setState(() {
generatedToolCode = null;
});
final x = await APIDashAgentCaller.instance.call(
final toolfuncRes = await APIDashAgentCaller.instance.call(
APIToolFunctionGenerator(),
ref: ref,
input: AgentInputs(variables: {
@@ -45,19 +45,22 @@ class _GenerateToolDialogState extends ConsumerState<GenerateToolDialog> {
'TARGET_LANGUAGE': selectedLanguage,
}),
);
if (x == null) {
if (toolfuncRes == null) {
setState(() {
generatedToolCode = '';
});
print("ToolGeneration Failed"); //TODO: Make Alert
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"API Tool generation failed!",
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.redAccent,
));
return;
}
String toolCode = x!['FUNC'];
String toolCode = toolfuncRes!['FUNC'];
print(toolCode);
//TODO: Integrate into tool
final toolres = await APIDashAgentCaller.instance.call(
ApiToolBodyGen(),
ref: ref,
@@ -71,7 +74,13 @@ class _GenerateToolDialogState extends ConsumerState<GenerateToolDialog> {
setState(() {
generatedToolCode = '';
});
print("ToolGeneration Failed"); //TODO: Make Alert
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"API Tool generation failed!",
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.redAccent,
));
return;
}
String toolDefinition = toolres!['TOOL'];

View File

@@ -42,7 +42,7 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
String generatedSDUI = '{}';
Future<String> generateSDUICode(String apiResponse) async {
Future<String?> generateSDUICode(String apiResponse) async {
setState(() {
index = 1; //Induce Loading
});
@@ -61,9 +61,23 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
}),
),
]);
final SA = step1Res[0]?['SEMANTIC_ANALYSIS'];
final IR = step1Res[1]?['INTERMEDIATE_REPRESENTATION'];
if (SA == null || IR == null) {
setState(() {
index = 0;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"Preview Generation Failed!",
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.redAccent,
));
return null;
}
print("Semantic Analysis: $SA");
print("Intermediate Representation: $IR");
@@ -78,7 +92,21 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
'VAR_SEMANTIC_ANALYSIS': SA,
}),
);
return sduiCode?['STAC']?.toString() ?? "<NONE>";
final stacCode = sduiCode?['STAC']?.toString();
if (stacCode == null) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"Preview Generation Failed!",
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.redAccent,
));
setState(() {
index = 0;
});
return null;
}
return sduiCode['STAC'].toString();
}
Future<void> modifySDUICode(String modificationRequest) async {
@@ -95,7 +123,21 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
}),
);
final SDUI = res['STAC'];
final SDUI = res?['STAC'];
if (SDUI == null) {
setState(() {
index = 2;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"Modification Request Failed!",
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.redAccent,
));
return;
}
setState(() {
generatedSDUI = SDUI;
index = 2;
@@ -112,6 +154,7 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
onNext: (apiResponse, targetLanguage) async {
print("Generating SDUI Code");
final sdui = await generateSDUICode(apiResponse);
if (sdui == null) return;
setState(() {
index = 2;
generatedSDUI = sdui;
@@ -276,6 +319,42 @@ class _SDUIPreviewPageState extends ConsumerState<SDUIPreviewPage> {
bool exportingCode = false;
String modificationRequest = "";
exportCode() async {
setState(() {
exportingCode = true;
});
final ans = await APIDashAgentCaller.instance.call(
StacToFlutterBot(),
ref: ref,
input: AgentInputs(
variables: {'VAR_CODE': widget.sduiCode},
),
);
final exportedCode = ans?['CODE'];
if (exportedCode == null) {
setState(() {
exportingCode = false;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"Export Failed",
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.redAccent,
));
print("exportCode: Failed; ABORTING");
return;
}
Clipboard.setData(ClipboardData(text: ans['CODE']));
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text("Copied to clipboard!")));
setState(() {
exportingCode = false;
});
}
@override
Widget build(BuildContext context) {
return Container(
@@ -354,24 +433,7 @@ class _SDUIPreviewPageState extends ConsumerState<SDUIPreviewPage> {
padding: kPh12,
minimumSize: const Size(44, 44),
),
onPressed: () async {
setState(() {
exportingCode = true;
});
final ans = await APIDashAgentCaller.instance.call(
StacToFlutterBot(),
ref: ref,
input: AgentInputs(
variables: {'VAR_CODE': widget.sduiCode}),
);
final exportedCode = ans['CODE'];
Clipboard.setData(ClipboardData(text: ans['CODE']));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Copied to clipboard!")));
setState(() {
exportingCode = false;
});
},
onPressed: exportCode,
icon: Icon(
Icons.download,
),