import '../../../core/api_gateway.dart'; import 'search_row.dart'; /// The chat payload of a `chat` search hit, or null for any other hit. JsonMap? searchChatOf(JsonMap hit) { final chat = hit['chat']; return hit['kind'] == 'chat' && chat is Map ? Map.from(chat) : null; } /// A chat hit's row: the chat's title, its harness and directory as the /// muted facts, and the matching message's snippet when message text matched. /// It opens only with the server's own `chat:` target. SearchRowView searchChatRowView( JsonMap chat, { required String query, required String? target, required String? recency, }) { final title = '${chat['title'] ?? ''}'.trim(); final directory = '${chat['directory'] ?? ''}'.trim(); final snippet = '${chat['snippet'] ?? ''}'; final facts = [ searchHarnessLabel('${chat['backend'] ?? ''}'), if (directory.isNotEmpty) directory, if (chat['closed'] == true) 'closed', ].join(' ยท '); return SearchRowView( title: title.isEmpty ? 'Untitled chat' : title, secondary: facts, kindLabel: 'Chat', snippet: snippet.isEmpty ? null : snippet, snippetSpans: snippetSpans(snippet, query), recency: recency, target: target, ); } /// The harness's display name, matching the server's own names; an unknown /// harness shows as sent. String searchHarnessLabel(String backend) => switch (backend) { 'claude' => 'Claude Code', 'codex' => 'Codex', '' || 'opencode' => 'OpenCode', _ => backend, };