fix(it0_app): stop using systemPrompt as conversation title
Voice sessions set systemPrompt to the voice-mode instruction string, causing every voice conversation to display '你正在通过语音与用户实时对话。请…' as its title in the chat history list. Title derivation priority (highest to lowest): 1. metadata.title — explicit title saved by backend on first task 2. metadata.voiceMode == true → '语音对话 M/D HH:mm' 3. Fallback → '对话 M/D HH:mm' based on session createdAt
This commit is contained in:
parent
f0634c2e49
commit
9546dab93d
|
|
@ -22,7 +22,11 @@ class SessionSummary {
|
|||
factory SessionSummary.fromJson(Map<String, dynamic> json) {
|
||||
return SessionSummary(
|
||||
id: json['id'] as String,
|
||||
title: json['systemPrompt'] as String? ?? _generateTitle(json),
|
||||
// NOTE: Never use systemPrompt as title — it's an internal engine instruction
|
||||
// (voice sessions set systemPrompt to the voice-mode rules string, which caused
|
||||
// every voice conversation to appear as "你正在通过语音与用户实时对话。请…").
|
||||
// Always derive the display title from metadata or the session creation time.
|
||||
title: _generateTitle(json),
|
||||
status: json['status'] as String? ?? 'active',
|
||||
createdAt: DateTime.tryParse(json['createdAt'] as String? ?? '') ?? DateTime.now(),
|
||||
updatedAt: DateTime.tryParse(json['updatedAt'] as String? ?? '') ?? DateTime.now(),
|
||||
|
|
@ -30,12 +34,21 @@ class SessionSummary {
|
|||
}
|
||||
|
||||
static String _generateTitle(Map<String, dynamic> json) {
|
||||
// Use metadata or fallback to date-based title
|
||||
final meta = json['metadata'] as Map<String, dynamic>?;
|
||||
if (meta != null && meta['title'] != null) {
|
||||
return meta['title'] as String;
|
||||
}
|
||||
|
||||
// 1. Use the explicit title stored by the backend on first task (text sessions)
|
||||
final storedTitle = meta?['title'] as String?;
|
||||
if (storedTitle != null && storedTitle.isNotEmpty) return storedTitle;
|
||||
|
||||
final createdAt = DateTime.tryParse(json['createdAt'] as String? ?? '');
|
||||
|
||||
// 2. Voice sessions: prefix with 🎙 and show time
|
||||
final isVoice = meta?['voiceMode'] as bool? ?? false;
|
||||
if (isVoice && createdAt != null) {
|
||||
return '语音对话 ${createdAt.month}/${createdAt.day} ${createdAt.hour}:${createdAt.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
// 3. Fallback: date-based title
|
||||
if (createdAt != null) {
|
||||
return '对话 ${createdAt.month}/${createdAt.day} ${createdAt.hour}:${createdAt.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue