mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-16 18:01:41 +00:00
* style: apply SwiftFormat 0.62.1 rules Refs #103202 * ci: enforce deterministic Swift lint Refs #103202 * refactor: keep gateway connect lint-clean Refs #103202 * style: keep iOS typography checks warning-free * ci: route MLX Swift changes through pre-push * fix: preserve native i18n extraction after Swift cleanup * refactor: keep rebased Swift surfaces lint-clean * style: format latest Swift additions * chore: refresh native i18n inventory * style: keep generated Swift formatter-clean * fix: preserve node route invalidation callbacks * fix: keep native translation IDs stable * fix: retain native translation identifiers * fix: preserve translations across Swift source moves
28 lines
1.1 KiB
Swift
28 lines
1.1 KiB
Swift
import Foundation
|
|
|
|
enum SessionKey {
|
|
static func normalizeMainKey(_ raw: String?) -> String {
|
|
let trimmed = (raw ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
|
|
return trimmed.isEmpty ? "main" : trimmed
|
|
}
|
|
|
|
static func makeAgentSessionKey(agentId: String, baseKey: String) -> String {
|
|
let trimmedAgent = agentId.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
let trimmedBase = baseKey.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
if trimmedAgent.isEmpty {
|
|
return trimmedBase.isEmpty ? "main" : trimmedBase
|
|
}
|
|
let normalizedBase = trimmedBase.isEmpty ? "main" : trimmedBase
|
|
return "agent:\(trimmedAgent):\(normalizedBase)"
|
|
}
|
|
|
|
static func agentId(from value: String?) -> String? {
|
|
let parts = (value ?? "")
|
|
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
.split(separator: ":", omittingEmptySubsequences: false)
|
|
guard parts.count >= 3, parts[0].lowercased() == "agent" else { return nil }
|
|
let agentId = String(parts[1]).trimmingCharacters(in: .whitespacesAndNewlines)
|
|
return agentId.isEmpty ? nil : agentId
|
|
}
|
|
}
|