mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 11:55:47 -06:00
7a5de93228
Amp-Thread-ID: https://ampcode.com/threads/T-01a037b7-9244-7298-b368-3faab8a11cbf Co-authored-by: Amp <amp@ampcode.com>
15 lines
493 B
Swift
15 lines
493 B
Swift
import Foundation
|
|
import OpenClawKit
|
|
|
|
enum ChatPayloadDecoding {
|
|
static func decode<T: Decodable>(_ payload: AnyCodable, as _: T.Type = T.self) throws -> T {
|
|
let data = try JSONEncoder().encode(payload)
|
|
return try JSONDecoder().decode(T.self, from: data)
|
|
}
|
|
|
|
static func trimmedNonEmptyString(_ value: String?) -> String? {
|
|
let trimmed = value?.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
return trimmed?.isEmpty == false ? trimmed : nil
|
|
}
|
|
}
|