diff --git a/lib/services/agentic/agent_caller.dart b/lib/services/agentic_services/agent_caller.dart similarity index 100% rename from lib/services/agentic/agent_caller.dart rename to lib/services/agentic_services/agent_caller.dart diff --git a/lib/services/agentic_services/agents/intermediate_rep_gen.dart b/lib/services/agentic_services/agents/intermediate_rep_gen.dart new file mode 100644 index 00000000..cb35209d --- /dev/null +++ b/lib/services/agentic_services/agents/intermediate_rep_gen.dart @@ -0,0 +1,67 @@ +import 'package:genai/agentic_engine/blueprint.dart'; + +const String kIntermediateRepGenSystemPrompt = """ +You are an expert at converting API Responses into a YAML schema tree. +When you get a given JSON API Response, I want you to break it down and recombine it in the form of a YAMK UI schema. + +Sample Schema: +```yaml +- type: column + elements: + - type: row + elements: + - type: image + src: "https://reqres.in/img/faces/7-image.jpg" + shape: circle + width: 60 + height: 60 + - type: column + elements: + - type: text + data: "Michael Lawson" + font: "segoe-ui" + color: blue + - type: text + data: "michael.lawson@reqres.in" + font: "segoe-ui" + color: gray +``` + +API_RESPONSE: ```json +:VAR_API_RESPONSE: +``` + +USE the API_RESPONSE to generate this YAML representation. +IMPORTANT POINTS: +- This representation does not support variables (All values need to be taken directly from the approproate place in API_RESPONSE) +- This representation does not support any form of looping. Hence if there are 5 repeated elements with different data, repeat the representation and use actual data from API_RESPONSE + +DO NOT START OR END THE RESPONSE WITH ANYTHING ELSE. I WANT PURE YAML OUTPUT + """; + +class IntermediateRepresentationGen extends APIDashAIAgent { + @override + String get agentName => 'INTERMEDIATE_REP_GEN'; + + @override + String getSystemPrompt() { + return kIntermediateRepGenSystemPrompt; + } + + @override + Future validator(String aiResponse) async { + //Add any specific validations here as needed + return true; + } + + @override + Future outputFormatter(String validatedResponse) async { + validatedResponse = validatedResponse + .replaceAll('```yaml', '') + .replaceAll('```yaml\n', '') + .replaceAll('```', ''); + return { + 'INTERMEDIATE_REPRESENTATION': validatedResponse, + }; + } +} diff --git a/lib/services/agentic_services/agents/semantic_analyser.dart b/lib/services/agentic_services/agents/semantic_analyser.dart new file mode 100644 index 00000000..c21f4873 --- /dev/null +++ b/lib/services/agentic_services/agents/semantic_analyser.dart @@ -0,0 +1,38 @@ +import 'package:genai/agentic_engine/blueprint.dart'; + +const String kSemanticAnalyserSystemPrompt = """ +You are an expert at understanding API response structures. +When i provide a sample JSON response, Please give me a semantic analysis about it. + +AVOID USAGE OF MARKDOWN. I WANT SIMPLE PLAIN_TEXT OUTPUT. +Keep in mind that the content you generate will be used as input to another AI Bot so please be crisp and to the point. + +KEEP only fields that make sense to the UI and instruct to omit other things + +THe next bot will be a UI Generator bot that will take your semantic analysis and use it to generate UI, so tailor the details accordingly. +I do not want any format, Just a large paragraph of plaintext explaining what the response is and what type of UI will be best suited + DO NOT START OR END THE RESPONSE WITH ANYTHING ELSE. I WANT PURE OUTPUT + """; + +class ResponseSemanticAnalyser extends APIDashAIAgent { + @override + String get agentName => 'RESP_SEMANTIC_ANALYSER'; + + @override + String getSystemPrompt() { + return kSemanticAnalyserSystemPrompt; + } + + @override + Future validator(String aiResponse) async { + //Add any specific validations here as needed + return true; + } + + @override + Future outputFormatter(String validatedResponse) async { + return { + 'SEMANTIC_ANALYSIS': validatedResponse, + }; + } +} diff --git a/lib/services/agentic_services/agents/stac2flutter.dart b/lib/services/agentic_services/agents/stac2flutter.dart new file mode 100644 index 00000000..c0bf6d4d --- /dev/null +++ b/lib/services/agentic_services/agents/stac2flutter.dart @@ -0,0 +1,45 @@ +import 'package:genai/agentic_engine/blueprint.dart'; + +const String kIntermediateRepGenSystemPrompt = """ +You are an expert agent whose sole JOB is to accept FLutter-SDUI (json-like) representation +and convert it into actual working FLutter component. + +This is fairly easy to do as FLutter-SDUI is literally a one-one representation of Flutter Code + +SDUI_CODE: ```:VAR_CODE:``` + +use the Above SDUI_CODE and convert it into Flutter Code that is effectively same as what the SDUI_CODE represents + +DO NOT CHANGE CONTENT, just convert everything one-by-one +Output ONLY Code Representation NOTHING ELSE. DO NOT START OR END WITH TEXT, ONLY Code + +DO NOT WRITE CODE TO PARSE SDUI, ACTUALLY CONVERT IT TO REAL DART CODE +"""; + +class StacToFlutterBot extends APIDashAIAgent { + @override + String get agentName => 'STAC_2_FLUTTER'; + + @override + String getSystemPrompt() { + return kIntermediateRepGenSystemPrompt; + } + + @override + Future validator(String aiResponse) async { + //Add any specific validations here as needed + return true; + } + + @override + Future outputFormatter(String validatedResponse) async { + validatedResponse = validatedResponse + .replaceAll('```dart', '') + .replaceAll('```dart\n', '') + .replaceAll('```', ''); + + return { + 'CODE': validatedResponse, + }; + } +} diff --git a/lib/services/agentic_services/agents/stacgen.dart b/lib/services/agentic_services/agents/stacgen.dart new file mode 100644 index 00000000..7599298d --- /dev/null +++ b/lib/services/agentic_services/agents/stacgen.dart @@ -0,0 +1,258 @@ +import 'package:genai/agentic_engine/blueprint.dart'; + +const String kIntermediateRepGenSystemPrompt = """ +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 + + +An example of FLutter-SDUI code would be something like this: +``` +{ + "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": { + + }, + "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": { + + }, + "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" + } + } + ] + } + } + ] + } + } + } +} +``` + + +SCHEMA: ```:VAR_INTERMEDIATE_REPR:``` + +DESCRIPTION: ```:VAR_SEMANTIC_ANALYSIS:``` + +now, use the SCHEMA and SEMANTIC_DETAILS to make the FLutter-SDUI Representation + + +Consider using only thee types: +``` +container +text +row +column +elevatedButton +textButtton +icon +image +singleChildScrollView +listView +padding +sizedBox +card +expanded +center +circleAvatar +``` + +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 + +"""; + +class StacGenBot extends APIDashAIAgent { + @override + String get agentName => 'STAC_GEN'; + + @override + String getSystemPrompt() { + return kIntermediateRepGenSystemPrompt; + } + + @override + Future validator(String aiResponse) async { + //Add any specific validations here as needed + return true; + } + + @override + Future outputFormatter(String validatedResponse) async { + validatedResponse = validatedResponse + .replaceAll('```json', '') + .replaceAll('```json\n', '') + .replaceAll('```', ''); + + //Stac Specific Changes + validatedResponse = validatedResponse.replaceAll('bold', 'w700'); + + return { + 'STAC': validatedResponse, + }; + } +} diff --git a/lib/services/agentic_services/agents/stacmodifier.dart b/lib/services/agentic_services/agents/stacmodifier.dart new file mode 100644 index 00000000..0ad35c45 --- /dev/null +++ b/lib/services/agentic_services/agents/stacmodifier.dart @@ -0,0 +1,47 @@ +import 'package:genai/agentic_engine/blueprint.dart'; + +const String kIntermediateRepGenSystemPrompt = """ +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:``` + +CLIENT_REQUEST: ```:VAR_CLIENT_REQUEST:``` + +use the CLIENT_REQUEST to modify the PREVIOUS_CODE while following the existing FLutter-SDUI (json-like) representation + + +DO NOT CHANGE ANYTHING UNLESS SPECIFICALLY ASKED TO +ONLY FLutter-SDUI Representation NOTHING ELSE. DO NOT START OR END WITH TEXT, ONLY FLutter-SDUI Representatiin. +"""; + +class SlacModifierBot extends APIDashAIAgent { + @override + String get agentName => 'STAC_MODIFIER'; + + @override + String getSystemPrompt() { + return kIntermediateRepGenSystemPrompt; + } + + @override + Future validator(String aiResponse) async { + //Add any specific validations here as needed + return true; + } + + @override + Future outputFormatter(String validatedResponse) async { + validatedResponse = validatedResponse + .replaceAll('```json', '') + .replaceAll('```json\n', '') + .replaceAll('```', ''); + + //Stac Specific Changes + validatedResponse = validatedResponse.replaceAll('bold', 'w700'); + + return { + 'STAC': validatedResponse, + }; + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 0ef4fae7..3a735b83 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -75,6 +75,8 @@ dependencies: url: https://github.com/google/flutter-desktop-embedding.git path: plugins/window_size + stac: ^0.11.0 + dependency_overrides: extended_text_field: ^16.0.0 pdf_widget_wrapper: ^1.0.4