Files
ReadViewSDK/Sources/RDAIReaderView/Core/RDAIDiagnostics.swift
T
2026-07-27 21:43:13 +08:00

24 lines
1.2 KiB
Swift

import Foundation
public enum RDAIDiagnosticStage: String, Codable, Sendable { case indexing, retrieval, generation, storage }
public struct RDAIDiagnosticEvent: Codable, Sendable {
public let documentHash: String
public let stage: RDAIDiagnosticStage
public let durationMilliseconds: Int
public let errorCode: String?
public let count: Int
public let createdAt: Date
public init(documentHash: String, stage: RDAIDiagnosticStage, durationMilliseconds: Int, errorCode: String? = nil, count: Int = 0, createdAt: Date = .init()) { self.documentHash = documentHash; self.stage = stage; self.durationMilliseconds = durationMilliseconds; self.errorCode = errorCode; self.count = count; self.createdAt = createdAt }
}
public protocol RDAIDiagnosticsRecording: Sendable { func record(_ event: RDAIDiagnosticEvent) async }
public actor RDAIInMemoryDiagnosticsRecorder: RDAIDiagnosticsRecording {
private var values: [RDAIDiagnosticEvent] = []
public init() {}
public func record(_ event: RDAIDiagnosticEvent) { values.append(event) }
public func events() -> [RDAIDiagnosticEvent] { values }
public func removeAll() { values.removeAll() }
}