list method

Future<List<AgentRunRecord>> list({
  1. DateTime? since,
  2. String? agentId,
  3. int? limit,
})

Loads runs, newest first.

Implementation

Future<List<AgentRunRecord>> list({
  DateTime? since,
  String? agentId,
  int? limit,
}) async {
  final records = await _records.query(
    AgentRunRecords.collection,
    query: RecordQuery(
      equals: {AgentRunRecords.agentIdField: ?agentId},
      orderBy: AgentRunRecords.startedAtField,
      descending: true,
    ),
  );
  final runs = [
    for (final record in records)
      AgentRunRecord.fromJson(record.id, record.value),
  ];
  final filtered = since == null
      ? runs
      : [
          for (final run in runs)
            if (run.startedAt.isAfter(since)) run,
        ];
  return limit == null || filtered.length <= limit
      ? filtered
      : filtered.sublist(0, limit);
}