refactor: move inbound config

This commit is contained in:
Peter Steinberger
2025-12-24 00:22:52 +00:00
parent 5e07400cd1
commit 93af424ce5
34 changed files with 283 additions and 243 deletions

View File

@@ -66,7 +66,7 @@ struct ConfigSettings: View {
private var header: some View {
Text("Clawdis CLI config")
.font(.title3.weight(.semibold))
Text("Edit ~/.clawdis/clawdis.json (agent / inbound.session).")
Text("Edit ~/.clawdis/clawdis.json (agent / session / routing / messages).")
.font(.callout)
.foregroundStyle(.secondary)
}

View File

@@ -163,8 +163,7 @@ enum DebugActions {
guard
let data = try? Data(contentsOf: configURL),
let parsed = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
let inbound = parsed["inbound"] as? [String: Any],
let session = inbound["session"] as? [String: Any],
let session = parsed["session"] as? [String: Any],
let path = session["store"] as? String,
!path.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
else {

View File

@@ -681,8 +681,7 @@ struct DebugSettings: View {
guard
let data = try? Data(contentsOf: url),
let parsed = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
let inbound = parsed["inbound"] as? [String: Any],
let session = inbound["session"] as? [String: Any],
let session = parsed["session"] as? [String: Any],
let path = session["store"] as? String
else {
self.sessionStorePath = SessionLoader.defaultStorePath
@@ -701,11 +700,9 @@ struct DebugSettings: View {
root = parsed
}
var inbound = root["inbound"] as? [String: Any] ?? [:]
var session = inbound["session"] as? [String: Any] ?? [:]
var session = root["session"] as? [String: Any] ?? [:]
session["store"] = trimmed.isEmpty ? SessionLoader.defaultStorePath : trimmed
inbound["session"] = session
root["inbound"] = inbound
root["session"] = session
do {
let data = try JSONSerialization.data(withJSONObject: root, options: [.prettyPrinted, .sortedKeys])

View File

@@ -287,15 +287,11 @@ actor GatewayConnection {
extension GatewayConnection {
struct ConfigGetSnapshot: Decodable, Sendable {
struct SnapshotConfig: Decodable, Sendable {
struct Inbound: Decodable, Sendable {
struct Session: Decodable, Sendable {
let mainKey: String?
}
let session: Session?
struct Session: Decodable, Sendable {
let mainKey: String?
}
let inbound: Inbound?
let session: Session?
}
let config: SnapshotConfig?
@@ -303,7 +299,7 @@ extension GatewayConnection {
static func mainSessionKey(fromConfigGetData data: Data) throws -> String {
let snapshot = try JSONDecoder().decode(ConfigGetSnapshot.self, from: data)
let raw = snapshot.config?.inbound?.session?.mainKey
let raw = snapshot.config?.session?.mainKey
let trimmed = (raw ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
return trimmed.isEmpty ? "main" : trimmed
}

View File

@@ -27,7 +27,7 @@ import Testing
"raw": null,
"parsed": {},
"valid": true,
"config": { "inbound": { "session": { "mainKey": " primary " } } },
"config": { "session": { "mainKey": " primary " } },
"issues": []
}
"""
@@ -38,7 +38,7 @@ import Testing
@Test func configGetSnapshotMainKeyFallsBackWhenEmptyOrWhitespace() throws {
let json = """
{
"config": { "inbound": { "session": { "mainKey": " " } } }
"config": { "session": { "mainKey": " " } }
}
"""
let key = try GatewayConnection.mainSessionKey(fromConfigGetData: Data(json.utf8))