mirror of
https://github.com/foss42/apidash.git
synced 2025-12-05 12:34:26 +08:00
INTEGRATED: SA_GEN, IR_GEN & STAC_GEN
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:apidash/consts.dart';
|
import 'package:apidash/consts.dart';
|
||||||
|
import 'package:apidash/services/agentic_services/agent_caller.dart';
|
||||||
import 'package:apidash/widgets/widget_sending.dart';
|
import 'package:apidash/widgets/widget_sending.dart';
|
||||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:stac/stac.dart' as stac;
|
||||||
|
|
||||||
void showCustomDialog(BuildContext context, String content) {
|
void showCustomDialog(BuildContext context, String content) {
|
||||||
showDialog(
|
showDialog(
|
||||||
@@ -20,7 +25,7 @@ void showCustomDialog(BuildContext context, String content) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DialogContents extends StatefulWidget {
|
class DialogContents extends ConsumerStatefulWidget {
|
||||||
final String content;
|
final String content;
|
||||||
const DialogContents({
|
const DialogContents({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -28,11 +33,49 @@ class DialogContents extends StatefulWidget {
|
|||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<DialogContents> createState() => _DialogContentsState();
|
ConsumerState<DialogContents> createState() => _DialogContentsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DialogContentsState extends State<DialogContents> {
|
class _DialogContentsState extends ConsumerState<DialogContents> {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
TextEditingController controller = TextEditingController();
|
||||||
|
|
||||||
|
String generatedSDUI = '{}';
|
||||||
|
|
||||||
|
Future<String> generateSDUICode(String apiResponse) async {
|
||||||
|
setState(() {
|
||||||
|
index = 1; //Induce Loading
|
||||||
|
});
|
||||||
|
//STEP 1: RESPONSE_ANALYSER (call the Semantic Analysis & IRGen Bots in parallel)
|
||||||
|
final step1Res = await Future.wait([
|
||||||
|
APIDashAgentCaller.instance.semanticAnalyser(
|
||||||
|
ref,
|
||||||
|
input: AgentInputs(query: apiResponse),
|
||||||
|
),
|
||||||
|
APIDashAgentCaller.instance.irGenerator(
|
||||||
|
ref,
|
||||||
|
input: AgentInputs(variables: {
|
||||||
|
'VAR_API_RESPONSE': apiResponse,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
final SA = step1Res[0]['SEMANTIC_ANALYSIS'];
|
||||||
|
final IR = step1Res[1]['INTERMEDIATE_REPRESENTATION'];
|
||||||
|
print("Semantic Analysis: $SA");
|
||||||
|
print("Intermediate Representation: $IR");
|
||||||
|
|
||||||
|
//STEP 2: STAC_GEN (Generate the SDUI Code)
|
||||||
|
final sduiCode = await APIDashAgentCaller.instance.stacGenerator(
|
||||||
|
ref,
|
||||||
|
input: AgentInputs(variables: {
|
||||||
|
'VAR_RAW_API_RESPONSE': apiResponse,
|
||||||
|
'VAR_INTERMEDIATE_REPR': IR,
|
||||||
|
'VAR_SEMANTIC_ANALYSIS': SA,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return sduiCode['STAC'].toString();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return IndexedStack(
|
return IndexedStack(
|
||||||
@@ -40,9 +83,12 @@ class _DialogContentsState extends State<DialogContents> {
|
|||||||
children: [
|
children: [
|
||||||
FrameWorkSelectorPage(
|
FrameWorkSelectorPage(
|
||||||
content: widget.content,
|
content: widget.content,
|
||||||
onNext: () {
|
onNext: (apiResponse, targetLanguage) async {
|
||||||
|
print("Generating SDUI Code");
|
||||||
|
final sdui = await generateSDUICode(apiResponse);
|
||||||
setState(() {
|
setState(() {
|
||||||
index = 1;
|
index = 2;
|
||||||
|
generatedSDUI = sdui;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -53,9 +99,9 @@ class _DialogContentsState extends State<DialogContents> {
|
|||||||
padding: const EdgeInsets.only(top: 40.0),
|
padding: const EdgeInsets.only(top: 40.0),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
// setState(() {
|
||||||
index = 2;
|
// index = 2;
|
||||||
});
|
// });
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 500,
|
height: 500,
|
||||||
@@ -67,8 +113,9 @@ class _DialogContentsState extends State<DialogContents> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
EditorPage(
|
SDUIPreviewPage(
|
||||||
onNext: () {},
|
onNext: () {},
|
||||||
|
sduiCode: generatedSDUI,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -77,7 +124,7 @@ class _DialogContentsState extends State<DialogContents> {
|
|||||||
|
|
||||||
class FrameWorkSelectorPage extends StatefulWidget {
|
class FrameWorkSelectorPage extends StatefulWidget {
|
||||||
final String content;
|
final String content;
|
||||||
final Function() onNext;
|
final Function(String, String) onNext;
|
||||||
const FrameWorkSelectorPage(
|
const FrameWorkSelectorPage(
|
||||||
{super.key, required this.content, required this.onNext});
|
{super.key, required this.content, required this.onNext});
|
||||||
|
|
||||||
@@ -173,7 +220,7 @@ class _FrameWorkSelectorPageState extends State<FrameWorkSelectorPage> {
|
|||||||
minimumSize: const Size(44, 44),
|
minimumSize: const Size(44, 44),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
widget.onNext();
|
widget.onNext(controller.value.text, "FLUTTER");
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.generating_tokens,
|
Icons.generating_tokens,
|
||||||
@@ -191,15 +238,17 @@ class _FrameWorkSelectorPageState extends State<FrameWorkSelectorPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EditorPage extends StatefulWidget {
|
class SDUIPreviewPage extends StatefulWidget {
|
||||||
|
final String sduiCode;
|
||||||
final Function() onNext;
|
final Function() onNext;
|
||||||
const EditorPage({super.key, required this.onNext});
|
const SDUIPreviewPage(
|
||||||
|
{super.key, required this.onNext, required this.sduiCode});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<EditorPage> createState() => _EditorPageState();
|
State<SDUIPreviewPage> createState() => _SDUIPreviewPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EditorPageState extends State<EditorPage> {
|
class _SDUIPreviewPageState extends State<SDUIPreviewPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@@ -223,9 +272,11 @@ class _EditorPageState extends State<EditorPage> {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: Colors.white),
|
border: Border.all(color: Colors.white),
|
||||||
),
|
),
|
||||||
child: Container(
|
child: widget.sduiCode == '{}'
|
||||||
color: Colors.grey,
|
? SizedBox()
|
||||||
),
|
: StacRenderer(
|
||||||
|
stacRepresentation: widget.sduiCode,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -303,3 +354,18 @@ class _EditorPageState extends State<EditorPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class StacRenderer extends StatelessWidget {
|
||||||
|
final String stacRepresentation;
|
||||||
|
const StacRenderer({super.key, required this.stacRepresentation});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return stac.StacApp(
|
||||||
|
title: 'Component Preview',
|
||||||
|
homeBuilder: (context) => Material(
|
||||||
|
child: stac.Stac.fromJson(jsonDecode(stacRepresentation), context),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user