Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class ChatHistoryApiService {
'nodeName',
'traceId',
'source',
'inputGrammarFix',
];

void dispose() {
Expand Down Expand Up @@ -206,6 +207,9 @@ class ChatHistoryApiService {
router: chatRouterFromApi(item['router'] as String?),
nodeId: item['nodeId'] as String?,
instructions: item['instructions'] as String?,
outputTone: chatOutputToneFromApi(item['outputTone']),
inputGrammarFixerEnabled:
item['inputGrammarFixerEnabled'] as bool? ?? false,
resolvedTargetNodeId: item['resolvedTargetNodeId'] as String?,
resolvedTargetNodeName: item['resolvedTargetNodeName'] as String?,
resolvedTargetPluginId: item['resolvedTargetPluginId'] as String?,
Expand Down Expand Up @@ -438,6 +442,8 @@ class ChatHistoryApiService {
required ChatRouter? router,
String? nodeId,
String? instructions,
ChatOutputToneSetting? outputTone,
bool? inputGrammarFixerEnabled,
}) async {
final response = await _apiClient.put(
_scopeSettingsUri,
Expand All @@ -451,6 +457,9 @@ class ChatHistoryApiService {
'router': router?.apiValue,
if (nodeId != null) 'nodeId': nodeId,
'instructions': instructions,
if (outputTone != null) 'outputTone': outputTone.toApiMap(),
if (inputGrammarFixerEnabled != null)
'inputGrammarFixerEnabled': inputGrammarFixerEnabled,
}),
);
if (response.statusCode != 200) {
Expand Down
37 changes: 37 additions & 0 deletions apps/mobile_chat_app/lib/features/chat/chat_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,37 @@ class ChatInvalidation {
}
}

class InputGrammarFixResult {
const InputGrammarFixResult({
required this.status,
this.suggestion,
});

final String status;
final String? suggestion;

bool get isAccepted => status == 'accepted';
bool get hasSuggestion =>
status == 'suggested' && suggestion != null && suggestion!.isNotEmpty;

Map<String, Object?> toMap() => {
'status': status,
'suggestion': suggestion,
};

static InputGrammarFixResult? fromMap(Object? value) {
if (value is! Map) return null;
final map = Map<Object?, Object?>.from(value);
final status = map['status'];
if (status != 'accepted' && status != 'suggested') return null;
final suggestion = map['suggestion'];
return InputGrammarFixResult(
status: status as String,
suggestion: suggestion is String ? suggestion : null,
);
}
}

/// A chat message displayed in the [MessageList].
///
/// This is a thin view-model for the chat UI, distinct from
Expand Down Expand Up @@ -124,6 +155,7 @@ class ChatMessage {
this.isRecovered = false,
this.agentLoopPhase,
this.agentLoopTool,
this.inputGrammarFix,
this.invalidations = const [],
}) : timestamp = timestamp ?? DateTime.now();

Expand Down Expand Up @@ -173,6 +205,7 @@ class ChatMessage {
/// The tool name associated with a `tool_call_start` phase message.
/// Extracted from `agentLoop.toolName` in server metadata.
final String? agentLoopTool;
final InputGrammarFixResult? inputGrammarFix;
final List<ChatInvalidation> invalidations;

ChatMessage copyWith({
Expand Down Expand Up @@ -210,6 +243,7 @@ class ChatMessage {
bool? isRecovered,
String? agentLoopPhase,
String? agentLoopTool,
InputGrammarFixResult? inputGrammarFix,
List<ChatInvalidation>? invalidations,
}) {
return ChatMessage(
Expand Down Expand Up @@ -248,6 +282,7 @@ class ChatMessage {
isRecovered: isRecovered ?? this.isRecovered,
agentLoopPhase: agentLoopPhase ?? this.agentLoopPhase,
agentLoopTool: agentLoopTool ?? this.agentLoopTool,
inputGrammarFix: inputGrammarFix ?? this.inputGrammarFix,
invalidations: invalidations ?? this.invalidations,
);
}
Expand Down Expand Up @@ -288,6 +323,7 @@ class ChatMessage {
'isRecovered': isRecovered,
'agentLoopPhase': agentLoopPhase,
'agentLoopTool': agentLoopTool,
if (inputGrammarFix != null) 'inputGrammarFix': inputGrammarFix!.toMap(),
if (invalidations.isNotEmpty)
'invalidations': invalidations.map((item) => item.toMap()).toList(),
};
Expand Down Expand Up @@ -359,6 +395,7 @@ class ChatMessage {
isRecovered: map['isRecovered'] as bool? ?? false,
agentLoopPhase: map['agentLoopPhase'] as String?,
agentLoopTool: map['agentLoopTool'] as String?,
inputGrammarFix: InputGrammarFixResult.fromMap(map['inputGrammarFix']),
invalidations: parseInvalidations(map['invalidations']),
);
}
Expand Down
Loading
Loading