~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

iOS: log failed and stopped feed interactions

Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:ios/interaction-logs
ios/HUDKit/Sources/HUDKit/Data/Interactions.swift+19−6
@@ -1,4 +1,5 @@
import Foundation
import os
/// What HUD's apps tell a feed generator of what is done with its feed, as
/// web/shared/interactions.ts: the posts seen, the post opened, "more like
@@ -7,7 +8,8 @@ import Foundation
/// `send_interactions`, at most one send every 10 s, and at once when the
/// app moves on; a "more/less like this" goes at once. A failure drops the
/// batch; a feed that takes no interactions (`sent: 0` with a reason) is not
/// told any more.
/// told any more. Both are logged (subsystem place.hud.app, category
/// interactions) with the feed, how many and why, never the posts.
@MainActor
public final class Interactions {
public static let seen = "app.bsky.feed.defs#interactionSeen"
@@ -17,6 +19,7 @@ public final class Interactions {
public typealias Send = @MainActor (_ feed: String, _ interactions: [JSON]) async throws -> (sent: Int, reason: String?)
private static let batch = 100
private static let log = Logger(subsystem: "place.hud.app", category: "interactions")
private static let every: Duration = .seconds(10)
private var queue: [String: [JSON]] = [:]
@@ -62,21 +65,31 @@ public final class Interactions {
/// or a feed that takes none, throws, for the button to say.
public func now(_ feed: String, _ interaction: JSON) async throws {
if stopped.contains(feed) { throw HUDError.tool("This feed doesn't take feedback.") }
let (sent, reason) = try await send(feed, [interaction])
let sent: Int, reason: String?
do {
(sent, reason) = try await send(feed, [interaction])
} catch {
Self.log.error("send_interactions for \(feed, privacy: .public) failed: \(error.localizedDescription, privacy: .public)")
throw error
}
if sent == 0, let reason {
stop(feed)
stop(feed, reason)
throw HUDError.tool(reason)
}
}
private func deliver(_ feed: String, _ interactions: [JSON]) async {
guard !stopped.contains(feed) else { return }
if let (sent, reason) = try? await send(feed, interactions), sent == 0, reason != nil {
stop(feed)
do {
let (sent, reason) = try await send(feed, interactions)
if sent == 0, let reason { stop(feed, reason) }
} catch {
Self.log.error("send_interactions for \(feed, privacy: .public) failed; \(interactions.count) dropped: \(error.localizedDescription, privacy: .public)")
}
}
private func stop(_ feed: String) {
private func stop(_ feed: String, _ reason: String) {
Self.log.notice("send_interactions for \(feed, privacy: .public) stopped: \(reason, privacy: .public)")
stopped.insert(feed)
queue[feed] = nil
}