Gateway: discriminated protocol schema + CLI updates
This commit is contained in:
@@ -23,9 +23,9 @@ actor AgentRPC {
|
||||
}
|
||||
|
||||
func start() async throws {
|
||||
if configured { return }
|
||||
await gateway.configure(url: gatewayURL, token: gatewayToken)
|
||||
configured = true
|
||||
if self.configured { return }
|
||||
await self.gateway.configure(url: self.gatewayURL, token: self.gatewayToken)
|
||||
self.configured = true
|
||||
}
|
||||
|
||||
func shutdown() async {
|
||||
@@ -34,10 +34,12 @@ actor AgentRPC {
|
||||
|
||||
func setHeartbeatsEnabled(_ enabled: Bool) async -> Bool {
|
||||
do {
|
||||
_ = try await controlRequest(method: "set-heartbeats", params: ControlRequestParams(raw: ["enabled": AnyHashable(enabled)]))
|
||||
_ = try await self.controlRequest(
|
||||
method: "set-heartbeats",
|
||||
params: ControlRequestParams(raw: ["enabled": AnyHashable(enabled)]))
|
||||
return true
|
||||
} catch {
|
||||
logger.error("setHeartbeatsEnabled failed \(error.localizedDescription, privacy: .public)")
|
||||
self.logger.error("setHeartbeatsEnabled failed \(error.localizedDescription, privacy: .public)")
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -46,7 +48,8 @@ actor AgentRPC {
|
||||
do {
|
||||
let data = try await controlRequest(method: "status")
|
||||
if let obj = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
|
||||
(obj["ok"] as? Bool) ?? true {
|
||||
(obj["ok"] as? Bool) ?? true
|
||||
{
|
||||
return (true, nil)
|
||||
}
|
||||
return (false, "status error")
|
||||
@@ -71,7 +74,7 @@ actor AgentRPC {
|
||||
"to": AnyHashable(to ?? ""),
|
||||
"idempotencyKey": AnyHashable(UUID().uuidString),
|
||||
]
|
||||
_ = try await controlRequest(method: "agent", params: ControlRequestParams(raw: params))
|
||||
_ = try await self.controlRequest(method: "agent", params: ControlRequestParams(raw: params))
|
||||
return (true, nil, nil)
|
||||
} catch {
|
||||
return (false, nil, error.localizedDescription)
|
||||
@@ -79,8 +82,8 @@ actor AgentRPC {
|
||||
}
|
||||
|
||||
func controlRequest(method: String, params: ControlRequestParams? = nil) async throws -> Data {
|
||||
try await start()
|
||||
let rawParams = params?.raw.reduce(into: [String: Any]()) { $0[$1.key] = $1.value }
|
||||
return try await gateway.request(method: method, params: rawParams)
|
||||
try await self.start()
|
||||
let rawParams = params?.raw.reduce(into: [String: AnyCodable]()) { $0[$1.key] = AnyCodable($1.value) }
|
||||
return try await self.gateway.request(method: method, params: rawParams)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user