fromRow static method

ToolEvent? fromRow(
  1. Map<String, Object?> r
)

Implementation

static ToolEvent? fromRow(Map<String, Object?> r) {
  final id = r['id'];
  final tool = r['tool'];
  if (id is! int || tool is! String) return null;
  final outcomeName = r['outcome'] as String?;
  final outcome = ToolOutcome.values.cast<ToolOutcome?>().firstWhere(
        (o) => o!.name == outcomeName,
        orElse: () => null,
      );
  final argKeysRaw = r['arg_keys'];
  return ToolEvent(
    id: id,
    tsMs: (r['ts_ms'] as int?) ?? 0,
    correlationId: (r['correlation_id'] as String?) ?? '',
    tool: tool,
    outcome: outcome ?? ToolOutcome.ok,
    argKeys: argKeysRaw is String && argKeysRaw.isNotEmpty ? argKeysRaw.split(',') : const [],
    durationMs: (r['duration_ms'] as int?) ?? 0,
    resultBytes: (r['result_bytes'] as int?) ?? 0,
    errorKind: r['error_kind'] as String?,
    diagnostics: {
      for (final e in r.entries)
        if (!baseKeys.contains(e.key)) e.key: e.value,
    },
  );
}