Files
bot/apps/macos/Sources/Bot/GatewayPushSubscription.swift
zooqueen fd1d312208 feat: merge upstream improvements via rebrand bridge
Squash merge of 1,462 upstream commits with openclaw→hanzo-bot
naming transforms applied. Conflicts resolved favoring our main
branch to preserve existing customizations.

Key upstream additions:
- iOS Security Stack (concurrency locks, runtime guards, TTS fallback)
- Discord CDN hostname allowlisting for SSRF protection
- Discord mention handling improvements
- Various bug fixes and stability improvements
2026-03-03 09:38:30 -08:00

35 lines
940 B
Swift

import BotKit
enum GatewayPushSubscription {
@MainActor
static func consume(
bufferingNewest: Int? = nil,
onPush: @escaping @MainActor (GatewayPush) -> Void) async
{
let stream: AsyncStream<GatewayPush> = if let bufferingNewest {
await GatewayConnection.shared.subscribe(bufferingNewest: bufferingNewest)
} else {
await GatewayConnection.shared.subscribe()
}
for await push in stream {
if Task.isCancelled { return }
await MainActor.run {
onPush(push)
}
}
}
@MainActor
static func restartTask(
task: inout Task<Void, Never>?,
bufferingNewest: Int? = nil,
onPush: @escaping @MainActor (GatewayPush) -> Void)
{
task?.cancel()
task = Task {
await self.consume(bufferingNewest: bufferingNewest, onPush: onPush)
}
}
}