refactor(macos): dedupe UI, pairing, and runtime helpers

This commit is contained in:
Peter Steinberger
2026-03-02 11:32:04 +00:00
parent cd011897d0
commit cf67e374c0
92 changed files with 1769 additions and 1802 deletions

View File

@@ -12,13 +12,92 @@ struct GatewayCostUsageTotals: Codable {
struct GatewayCostUsageDay: Codable {
let date: String
let input: Int
let output: Int
let cacheRead: Int
let cacheWrite: Int
let totalTokens: Int
let totalCost: Double
let missingCostEntries: Int
private let totals: GatewayCostUsageTotals
var input: Int {
self.totals.input
}
var output: Int {
self.totals.output
}
var cacheRead: Int {
self.totals.cacheRead
}
var cacheWrite: Int {
self.totals.cacheWrite
}
var totalTokens: Int {
self.totals.totalTokens
}
var totalCost: Double {
self.totals.totalCost
}
var missingCostEntries: Int {
self.totals.missingCostEntries
}
init(
date: String,
input: Int,
output: Int,
cacheRead: Int,
cacheWrite: Int,
totalTokens: Int,
totalCost: Double,
missingCostEntries: Int)
{
self.date = date
self.totals = GatewayCostUsageTotals(
input: input,
output: output,
cacheRead: cacheRead,
cacheWrite: cacheWrite,
totalTokens: totalTokens,
totalCost: totalCost,
missingCostEntries: missingCostEntries)
}
private enum CodingKeys: String, CodingKey {
case date
case input
case output
case cacheRead
case cacheWrite
case totalTokens
case totalCost
case missingCostEntries
}
init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
self.date = try c.decode(String.self, forKey: .date)
self.totals = GatewayCostUsageTotals(
input: try c.decode(Int.self, forKey: .input),
output: try c.decode(Int.self, forKey: .output),
cacheRead: try c.decode(Int.self, forKey: .cacheRead),
cacheWrite: try c.decode(Int.self, forKey: .cacheWrite),
totalTokens: try c.decode(Int.self, forKey: .totalTokens),
totalCost: try c.decode(Double.self, forKey: .totalCost),
missingCostEntries: try c.decode(Int.self, forKey: .missingCostEntries))
}
func encode(to encoder: Encoder) throws {
var c = encoder.container(keyedBy: CodingKeys.self)
try c.encode(self.date, forKey: .date)
try c.encode(self.input, forKey: .input)
try c.encode(self.output, forKey: .output)
try c.encode(self.cacheRead, forKey: .cacheRead)
try c.encode(self.cacheWrite, forKey: .cacheWrite)
try c.encode(self.totalTokens, forKey: .totalTokens)
try c.encode(self.totalCost, forKey: .totalCost)
try c.encode(self.missingCostEntries, forKey: .missingCostEntries)
}
}
struct GatewayCostUsageSummary: Codable {