Add AI request model support and improve type handling

Refactored collection state management to handle API type changes and AI request models. Updated widgets and tests to support nullable HTTP methods and AI request models, and improved response body rendering for AI responses.
This commit is contained in:
Ankit Mahato
2025-08-28 23:34:28 +05:30
parent 6e1f2b4773
commit 7b7daa7dac
11 changed files with 92 additions and 40 deletions

View File

@@ -11,7 +11,7 @@ class SidebarRequestCard extends StatelessWidget {
super.key,
required this.id,
required this.apiType,
required this.method,
this.method,
this.name,
this.url,
this.selectedId,
@@ -30,7 +30,7 @@ class SidebarRequestCard extends StatelessWidget {
final APIType apiType;
final String? name;
final String? url;
final HTTPVerb method;
final HTTPVerb? method;
final String? selectedId;
final String? editRequestId;
final void Function()? onTap;

View File

@@ -49,8 +49,7 @@ class ResponseBody extends StatelessWidget {
// '$kMsgUnknowContentType - ${responseModel.contentType}. $kUnexpectedRaiseIssue');
// }
var responseBodyView = (selectedRequestModel?.apiType == APIType.ai &&
(responseModel.sseOutput?.isNotEmpty ?? false))
var responseBodyView = selectedRequestModel?.apiType == APIType.ai
? (kAnswerRawBodyViewOptions, kSubTypePlain)
: getResponseBodyViewOptions(mediaType);
var options = responseBodyView.$1;
@@ -70,6 +69,7 @@ class ResponseBody extends StatelessWidget {
formattedBody: formattedBody,
highlightLanguage: highlightLanguage,
sseOutput: responseModel.sseOutput,
isAIResponse: selectedRequestModel?.apiType == APIType.ai,
aiRequestModel: selectedRequestModel?.aiRequestModel,
);
}

View File

@@ -17,6 +17,7 @@ class ResponseBodySuccess extends StatefulWidget {
this.formattedBody,
this.highlightLanguage,
this.sseOutput,
this.isAIResponse = false,
this.aiRequestModel,
});
final MediaType mediaType;
@@ -26,6 +27,7 @@ class ResponseBodySuccess extends StatefulWidget {
final String? formattedBody;
final List<String>? sseOutput;
final String? highlightLanguage;
final bool isAIResponse;
final AIRequestModel? aiRequestModel;
@override
@@ -137,7 +139,7 @@ class _ResponseBodySuccessState extends State<ResponseBodySuccess> {
),
),
),
ResponseBodyView.raw || ResponseBodyView.answer => Expanded(
ResponseBodyView.answer => Expanded(
child: Container(
width: double.maxFinite,
padding: kP8,
@@ -150,6 +152,21 @@ class _ResponseBodySuccessState extends State<ResponseBodySuccess> {
),
),
),
ResponseBodyView.raw => Expanded(
child: Container(
width: double.maxFinite,
padding: kP8,
decoration: textContainerdecoration,
child: SingleChildScrollView(
child: SelectableText(
widget.isAIResponse
? widget.body
: (widget.formattedBody ?? widget.body),
style: kCodeStyle,
),
),
),
),
ResponseBodyView.sse => Expanded(
child: Container(
width: double.maxFinite,

View File

@@ -7,10 +7,10 @@ class SidebarRequestCardTextBox extends StatelessWidget {
const SidebarRequestCardTextBox({
super.key,
required this.apiType,
required this.method,
this.method,
});
final APIType apiType;
final HTTPVerb method;
final HTTPVerb? method;
@override
Widget build(BuildContext context) {
@@ -18,7 +18,7 @@ class SidebarRequestCardTextBox extends StatelessWidget {
width: 24,
child: Text(
switch (apiType) {
APIType.rest => method.abbr,
APIType.rest => method!.abbr,
APIType.graphql => apiType.abbr,
APIType.ai => apiType.abbr,
},