feat(chat): Add usage statistics support for message persistence

This commit is contained in:
cogwheel0
2025-12-15 18:42:06 +05:30
parent c21e70396d
commit 55cedc3ab8
7 changed files with 505 additions and 41 deletions

View File

@@ -305,6 +305,10 @@ Map<String, dynamic> _parseOpenWebUIMessageToJson(
? historyMsg['sources'] ?? historyMsg['citations']
: msgData['sources'] ?? msgData['citations'];
// Parse usage data - Open WebUI stores this in 'usage' field on messages
final rawUsage = _coerceJsonMap(historyMsg?['usage'] ?? msgData['usage']);
final Map<String, dynamic>? usage = rawUsage.isEmpty ? null : rawUsage;
return <String, dynamic>{
'id': (msgData['id'] ?? _uuid.v4()).toString(),
'role': role,
@@ -319,7 +323,7 @@ Map<String, dynamic> _parseOpenWebUIMessageToJson(
'followUps': _coerceStringList(followUpsRaw),
'codeExecutions': _parseCodeExecutionsField(codeExecRaw),
'sources': _parseSourcesField(sourcesRaw),
'usage': _coerceJsonMap(msgData['usage']),
'usage': usage,
'versions': const <Map<String, dynamic>>[],
};
}