refactor: reasoning parser

This commit is contained in:
cogwheel0
2025-09-05 22:44:04 +05:30
parent 2580bf961e
commit f8650cf809
3 changed files with 454 additions and 173 deletions

View File

@@ -0,0 +1,24 @@
import 'tool_calls_parser.dart';
import 'reasoning_parser.dart';
/// Unified segment representing ordered pieces of a message:
/// - `text`: plain text/markdown to render
/// - `toolCall`: a parsed tool call entry to render as a tile
/// - `reasoning`: a parsed reasoning entry to render as a tile
class MessageSegment {
final String? text;
final ToolCallEntry? toolCall;
final ReasoningEntry? reasoning;
const MessageSegment._({this.text, this.toolCall, this.reasoning});
factory MessageSegment.text(String text) => MessageSegment._(text: text);
factory MessageSegment.tool(ToolCallEntry tool) =>
MessageSegment._(toolCall: tool);
factory MessageSegment.reason(ReasoningEntry entry) =>
MessageSegment._(reasoning: entry);
bool get isText => text != null;
bool get isTool => toolCall != null;
bool get isReasoning => reasoning != null;
}