feat: background tasks panel (Phase 7)

This commit is contained in:
snowspeeder committed 2026-08-30 08:48:33 -04:00
1 parent 5c35fa9c65
commit af296da6b8
7 files changed
+339 -5

No files matched your search

+14 -4
View File
@@ -26,6 +26,7 @@ final class ControlChannel: NSObject, RoomDelegate {
let content: String?
let result: String?
let error: String?
let createdAt: Double?
}
var onEvent: ((InboundEvent) -> Void)?
@@ -63,19 +64,23 @@ final class ControlChannel: NSObject, RoomDelegate {
}
}
/// Inbound task_event handling (topic-agnostic per web UI). Returns true when consumed.
/// Inbound task_event handling (topic-agnostic per web UI). The agent publishes
/// {type:"task_event", task_id, event, ...} — the discriminator is `event`, not `type`.
func handleTaskEvent(_ data: Data) -> Bool {
guard let json = try? decoder.decode([String: JSONValue].self, from: data),
let type = json["type"]?.stringValue,
json["type"]?.stringValue == "task_event",
let type = json["event"]?.stringValue,
["created", "step", "completed", "failed"].contains(type) else { return false }
let taskObj = json["task"]?.objectValue ?? [:]
let payload = TaskEventPayload(
type: type,
taskId: json["task_id"]?.stringValue,
description: json["description"]?.stringValue,
description: json["description"]?.stringValue ?? taskObj["description"]?.stringValue,
role: json["role"]?.stringValue,
content: json["content"]?.stringValue,
result: json["result"]?.stringValue,
error: json["error"]?.stringValue
error: json["error"]?.stringValue,
createdAt: json["created_at"]?.doubleValue ?? taskObj["created_at"]?.doubleValue
)
onEvent?(.taskEvent(payload))
return true
@@ -137,6 +142,11 @@ indirect enum JSONValue: Decodable {
return nil
}
var doubleValue: Double? {
if case .number(let value) = self { return value }
return nil
}
var objectValue: [String: JSONValue]? {
if case .object(let value) = self { return value }
return nil