Files
openclaw/apps/macos/Sources/OpenClaw/TextSummarySupport.swift
2026-03-02 11:32:20 +00:00

17 lines
624 B
Swift

import Foundation
enum TextSummarySupport {
static func summarizeLastLine(_ text: String, maxLength: Int = 200) -> String? {
let lines = text
.split(whereSeparator: \.isNewline)
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
.filter { !$0.isEmpty }
guard let last = lines.last else { return nil }
let normalized = last.replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression)
if normalized.count > maxLength {
return String(normalized.prefix(maxLength - 1)) + ""
}
return normalized
}
}