toJson method
Implementation
Map<String, Object?> toJson() {
switch (role) {
case AiRole.assistant when toolCalls.isNotEmpty:
return {
'role': 'assistant',
'content': content.isEmpty ? null : content,
'tool_calls': [for (final t in toolCalls) t.toJson()],
};
case AiRole.tool:
return {'role': 'tool', 'tool_call_id': toolCallId, 'content': content};
default:
return {'role': role.name, 'content': content};
}
}