diff --git a/lib/services/agentic_services/agents/stacgen.dart b/lib/services/agentic_services/agents/stacgen.dart index c6281d0b..704fed6a 100644 --- a/lib/services/agentic_services/agents/stacgen.dart +++ b/lib/services/agentic_services/agents/stacgen.dart @@ -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 """; diff --git a/lib/widgets/ai_toolgen_widgets.dart b/lib/widgets/ai_toolgen_widgets.dart index a815febc..cd4e94a0 100644 --- a/lib/widgets/ai_toolgen_widgets.dart +++ b/lib/widgets/ai_toolgen_widgets.dart @@ -37,7 +37,7 @@ class _GenerateToolDialogState extends ConsumerState { 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 { '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 { 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']; diff --git a/lib/widgets/ai_ui_desginer_widgets.dart b/lib/widgets/ai_ui_desginer_widgets.dart index 177e4e50..0b46c345 100644 --- a/lib/widgets/ai_ui_desginer_widgets.dart +++ b/lib/widgets/ai_ui_desginer_widgets.dart @@ -42,7 +42,7 @@ class _GenerateUIDialogState extends ConsumerState { String generatedSDUI = '{}'; - Future generateSDUICode(String apiResponse) async { + Future generateSDUICode(String apiResponse) async { setState(() { index = 1; //Induce Loading }); @@ -61,9 +61,23 @@ class _GenerateUIDialogState extends ConsumerState { }), ), ]); - 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 { 'VAR_SEMANTIC_ANALYSIS': SA, }), ); - return sduiCode?['STAC']?.toString() ?? ""; + 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 modifySDUICode(String modificationRequest) async { @@ -95,7 +123,21 @@ class _GenerateUIDialogState extends ConsumerState { }), ); - 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 { 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 { 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 { 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, ),