mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-17 15:47:28 +00:00
24 lines
1002 B
Swift
24 lines
1002 B
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 isCanonicalMainSessionKey(_ value: String?) -> Bool {
|
|
let trimmed = (value ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
|
|
if trimmed.isEmpty { return false }
|
|
if trimmed == "global" { return true }
|
|
return trimmed.hasPrefix("agent:")
|
|
}
|
|
}
|