bff7115e4e
A search with kind chat matches the operator-session registry's titles and directories and the newest messages of recent transcripts through the chat broker (bounded count, concurrency and one-second budget), answered off the connection's read loop. The all-kind search is unchanged for older clients. The app sends the chat search after its run search and shows a Chats group with title, harness, directory and snippet; a chat hit opens that chat in the Chat tab. The probe fixture answers chat searches over ?chats=N.
84 lines
2.5 KiB
Dart
84 lines
2.5 KiB
Dart
import '../../../core/api_gateway.dart';
|
|
import '../data/search_repository.dart';
|
|
import 'search_models.dart';
|
|
import 'search_query.dart';
|
|
|
|
/// Wording for a server whose search does not know the `chat` kind (it
|
|
/// predates chat search and rejects the kind by name).
|
|
const unsupportedChatSearchCopy =
|
|
'This server does not search chats. Update the Pipelines server to '
|
|
'include them.';
|
|
|
|
final _unknownKind = RegExp(r'unknown search kind', caseSensitive: false);
|
|
|
|
/// The Chats section's state: one `kind: chat` request per sent query, run
|
|
/// beside (never instead of, nor ahead of) the run/artifact search, so the
|
|
/// server's transcript readback cannot delay the other results.
|
|
class SearchChatSlice {
|
|
List<JsonMap> results = const [];
|
|
bool loading = false;
|
|
bool loaded = false;
|
|
bool truncated = false;
|
|
String? error;
|
|
|
|
void clear() {
|
|
results = const [];
|
|
loading = false;
|
|
loaded = false;
|
|
truncated = false;
|
|
error = null;
|
|
}
|
|
|
|
/// Requests chats for [query]. [current] reports whether this request is
|
|
/// still the newest edit; a stale reply is dropped without a change.
|
|
Future<void> load(
|
|
SearchRepository repository,
|
|
String query, {
|
|
required bool Function() current,
|
|
required void Function() changed,
|
|
}) async {
|
|
loading = true;
|
|
error = null;
|
|
changed();
|
|
try {
|
|
final response = await repository.search(
|
|
query: query,
|
|
kind: SearchKind.chat,
|
|
);
|
|
if (!current()) return;
|
|
if (response == null) {
|
|
results = const [];
|
|
truncated = false;
|
|
error = unsupportedChatSearchCopy;
|
|
} else {
|
|
results = response.results
|
|
.where((hit) => hit['kind'] == SearchKind.chat.wire)
|
|
.toList(growable: false);
|
|
truncated = response.truncated;
|
|
}
|
|
} catch (failure) {
|
|
if (!current()) return;
|
|
results = const [];
|
|
truncated = false;
|
|
final text = searchFailureText(failure);
|
|
error = _unknownKind.hasMatch(text) || text == unsupportedSearchCopy
|
|
? unsupportedChatSearchCopy
|
|
: text;
|
|
}
|
|
loading = false;
|
|
loaded = true;
|
|
changed();
|
|
}
|
|
|
|
/// A short honest note under the Chats section: why chats are missing, or
|
|
/// that the server's bounds left some transcripts unsearched.
|
|
String? get note {
|
|
if (error != null) return error;
|
|
if (truncated) {
|
|
return "Some chats were not searched within the server's time or "
|
|
'result limit.';
|
|
}
|
|
return null;
|
|
}
|
|
}
|