| 1 | import '../data/models/persona.dart'; |
| 2 | |
| 3 | class PersonaPromptUtils { |
| 4 | PersonaPromptUtils._(); |
| 5 | |
| 6 | static List<String> parsePersonaIds(String? raw) { |
| 7 | if (raw == null || raw.trim().isEmpty) return const []; |
| 8 | return raw |
| 9 | .split(',') |
| 10 | .map((id) => id.trim()) |
| 11 | .where((id) => id.isNotEmpty) |
| 12 | .toList(); |
| 13 | } |
| 14 | |
| 15 | static String joinPersonaIds(List<String> ids) => ids.join(','); |
| 16 | |
| 17 | static String combineSystemPrompts(List<Persona> personas) { |
| 18 | if (personas.isEmpty) return ''; |
| 19 | if (personas.length == 1) return personas.first.systemPrompt; |
| 20 | return personas |
| 21 | .map((p) => '## ${p.name}\n\n${p.systemPrompt.trim()}') |
| 22 | .join('\n\n---\n\n'); |
| 23 | } |
| 24 | |
| 25 | static List<Persona> resolvePersonas( |
| 26 | String? rawIds, |
| 27 | List<Persona> allPersonas, |
| 28 | ) { |
| 29 | final ids = parsePersonaIds(rawIds); |
| 30 | if (ids.isEmpty) return const []; |
| 31 | final byId = {for (final p in allPersonas) p.id: p}; |
| 32 | return ids.map((id) => byId[id]).whereType<Persona>().toList(); |
| 33 | } |
| 34 | } |