mirror of https://github.com/openclaw/openclaw.git
feat(openclawkit): support pairing reset and request id errors
This commit is contained in:
parent
65b9c0a064
commit
9ab339e897
|
|
@ -64,6 +64,11 @@ public enum DeviceAuthStore {
|
|||
writeStore(store)
|
||||
}
|
||||
|
||||
public static func reset() {
|
||||
// Best-effort: forget stored per-device tokens so a fresh pairing/approval is required.
|
||||
try? FileManager.default.removeItem(at: fileURL())
|
||||
}
|
||||
|
||||
private static func normalizeRole(_ role: String) -> String {
|
||||
role.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@ public enum DeviceIdentityStore {
|
|||
return identity
|
||||
}
|
||||
|
||||
public static func reset() {
|
||||
// Best-effort: forget local device identity so the gateway sees a new device and requires pairing again.
|
||||
let url = self.fileURL()
|
||||
try? FileManager.default.removeItem(at: url)
|
||||
}
|
||||
|
||||
public static func signPayload(_ payload: String, identity: DeviceIdentity) -> String? {
|
||||
guard let privateKeyData = Data(base64Encoded: identity.privateKey) else { return nil }
|
||||
do {
|
||||
|
|
|
|||
|
|
@ -384,7 +384,31 @@ public actor GatewayChannelActor {
|
|||
) async throws {
|
||||
if res.ok == false {
|
||||
let msg = (res.error?["message"]?.value as? String) ?? "gateway connect failed"
|
||||
throw NSError(domain: "Gateway", code: 1008, userInfo: [NSLocalizedDescriptionKey: msg])
|
||||
let code = (res.error?["code"]?.value as? String) ?? ""
|
||||
let requestId: String? = {
|
||||
guard let detailsAny = res.error?["details"]?.value else { return nil }
|
||||
if let dict = detailsAny as? [String: ProtoAnyCodable],
|
||||
let id = dict["requestId"]?.value as? String
|
||||
{
|
||||
return id
|
||||
}
|
||||
if let dict = detailsAny as? [String: Any],
|
||||
let id = dict["requestId"] as? String
|
||||
{
|
||||
return id
|
||||
}
|
||||
if let dict = detailsAny as? [AnyHashable: Any],
|
||||
let id = dict["requestId"] as? String
|
||||
{
|
||||
return id
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
|
||||
let decorated = (code == "NOT_PAIRED" && requestId?.isEmpty == false)
|
||||
? "\(msg) (requestId: \(requestId ?? ""))"
|
||||
: msg
|
||||
throw NSError(domain: "Gateway", code: 1008, userInfo: [NSLocalizedDescriptionKey: decorated])
|
||||
}
|
||||
guard let payload = res.payload else {
|
||||
throw NSError(
|
||||
|
|
|
|||
Loading…
Reference in New Issue