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.
89 lines
2.6 KiB
Dart
89 lines
2.6 KiB
Dart
import '../../../core/api_gateway.dart';
|
|
|
|
/// The server's search narrowing vocabulary (`internal/protocol/search.go`),
|
|
/// in the control's display order. The empty [wire] value means every kind.
|
|
enum SearchKind {
|
|
all('', 'All kinds'),
|
|
pipeline('pipeline', 'Pipelines'),
|
|
run('run', 'Runs'),
|
|
step('step', 'Steps'),
|
|
field('field', 'Fields'),
|
|
artifact('artifact', 'Artifacts'),
|
|
chat('chat', 'Chats'),
|
|
version('version', 'Versions');
|
|
|
|
const SearchKind(this.wire, this.label);
|
|
|
|
final String wire;
|
|
final String label;
|
|
|
|
/// A stale or unknown value falls back to [SearchKind.all] rather than
|
|
/// inventing an option the server does not accept.
|
|
static SearchKind fromWire(String? wire) {
|
|
for (final kind in values) {
|
|
if (kind.wire == wire) return kind;
|
|
}
|
|
return SearchKind.all;
|
|
}
|
|
}
|
|
|
|
/// A query after `t:`/`type:` tokens have been recognised. [query] is the text
|
|
/// the server should match; [kind] is the effective narrowing.
|
|
class ParsedSearchQuery {
|
|
const ParsedSearchQuery(this.query, this.kind, this.hasType);
|
|
|
|
final String query;
|
|
final SearchKind kind;
|
|
final bool hasType;
|
|
}
|
|
|
|
/// The bounded `search_results` body from the server. Every bound the server
|
|
/// reports is kept, so the screen can show a truncation/scan indicator instead
|
|
/// of pretending a capped reply was complete.
|
|
class SearchResponse {
|
|
const SearchResponse({
|
|
this.query = '',
|
|
this.kind = SearchKind.all,
|
|
this.results = const [],
|
|
this.truncated = false,
|
|
this.scannedSteps = 0,
|
|
this.scannedBytes = 0,
|
|
this.cap = 0,
|
|
this.scanBoundBytes = 0,
|
|
});
|
|
|
|
factory SearchResponse.fromJson(JsonMap json) {
|
|
final rows = json['results'];
|
|
return SearchResponse(
|
|
query: '${json['query'] ?? ''}',
|
|
kind: SearchKind.fromWire('${json['kind'] ?? ''}'),
|
|
results: rows is List
|
|
? rows
|
|
.whereType<Map>()
|
|
.map((row) => Map<String, dynamic>.from(row))
|
|
.toList(growable: false)
|
|
: const [],
|
|
truncated: json['truncated'] == true,
|
|
scannedSteps: _integer(json['scanned_steps']),
|
|
scannedBytes: _integer(json['scanned_bytes']),
|
|
cap: _integer(json['cap']),
|
|
scanBoundBytes: _integer(json['scan_bound_bytes']),
|
|
);
|
|
}
|
|
|
|
final String query;
|
|
final SearchKind kind;
|
|
final List<JsonMap> results;
|
|
final bool truncated;
|
|
final int scannedSteps;
|
|
final int scannedBytes;
|
|
final int cap;
|
|
final int scanBoundBytes;
|
|
}
|
|
|
|
int _integer(Object? value) {
|
|
if (value is int) return value;
|
|
if (value is num) return value.toInt();
|
|
return int.tryParse('$value') ?? 0;
|
|
}
|