Files
openclaw/apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatCompactTokenCountFormatter.swift
T
Peter Steinberger cb51cf7d3e feat(apps): Apple chat adopts the system-notice family (#122255)
* feat(apps): adopt the system-notice family in Apple chat (OpenClawChatUI)

Decode internal_system provenance and __openclaw history markers, classify
once into message/notice/divider rows (web-parity kinds), render minimal
hairline notice/divider SwiftUI rows, preserve metadata through history
reconciliation, live transport, and the transcript cache, and align the
transcript exporter with visible classification instead of leaking raw
[System] prompts.

* fix(apps): satisfy OpenClawKit periphery gate

Remove the dead visibleMessages projection (rows path replaced its
consumers) and annotate the provenance test-fixture initializer with the
repo-standard periphery:ignore rationale.

* fix(apps): refresh native i18n inventory after periphery cleanup
2026-08-11 14:47:19 -07:00

24 lines
845 B
Swift

import Foundation
enum ChatCompactTokenCountFormatter {
static func string(_ tokens: Double) -> String {
if tokens >= 1_000_000 {
return "\(self.oneDecimal(tokens / 1_000_000))M"
}
if tokens >= 1000 {
let thousands = self.oneDecimal(tokens / 1000)
if Double(thousands) ?? 0 >= 1000 {
return "\(self.oneDecimal(tokens / 1_000_000))M"
}
return "\(thousands)k"
}
return String(Int(tokens))
}
private static func oneDecimal(_ value: Double) -> String {
let rounded = (value * 10).rounded(.toNearestOrAwayFromZero) / 10
let formatted = String(format: "%.1f", locale: Locale(identifier: "en_US_POSIX"), rounded)
return formatted.hasSuffix(".0") ? String(formatted.dropLast(2)) : formatted
}
}