list method
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);
}