Files
hapi/ios/Packages/HapiKit/Sources/HapiProtocol/Models/SessionSteering.swift
T
wushenghuaandHAPI 19b2435ea8 feat(ios): H5-style session rows and fix stuck queued actions
Session rows now match the web sidebar: the second line shows the last
two path components, active shares get a "Shared" pill, relative ages
read like the H5 list (now, 5 min ago, 10 hours ago, 2 days ago, then a
date), and the list font scale reaches 60%.

The running spinner is drawn from a timeline instead of ProgressView:
UIKit-backed spinners stop animating when a List cell is reconfigured,
which read as a spinner that often failed. Working rows also keep their
spinner while a pending approval is shown, as on web.

Queued-message actions no longer look dead. Cancelling a row the hub
reports as `busy` because it is already indeterminate used to restore
the row unchanged; it now keeps a `queueDismissed` hold (web #1839), so
Cancel and Retry take effect while the durable record stays available
for a late consume. Steer is hidden for flavors that cannot take it
(agy needs acp, cursor needs acp) via a port of the web steering gate.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
2026-12-05 12:11:13 +08:00

68 lines
2.6 KiB
Swift

import Foundation
/// Which flavors accept a "Steer" (soft mid-turn delivery) — port of
/// `shared/src/modes.ts` `isSteeringSupportedForSession`.
///
/// Native gating only: whether a turn is currently steerable is a separate
/// check (`Session.agentState.steeringActive` / `thinking`). The web hides the
/// Steer affordance entirely for unsupported flavors; showing it there only
/// produces a guaranteed hub error.
public enum SessionSteering {
/// Flavors with any steering capability.
private static let supportedFlavors: Set<String> = [
"agy", "claude", "codex", "cursor", "opencode", "pi", "dsh",
]
/// Session-aware gate. Cursor's legacy stream-json sessions advertise the
/// flavor but cannot steer; Antigravity only steers on `agy acp`.
public static func isSupported(_ metadata: SessionMetadata?) -> Bool {
isSupported(
flavor: metadata?.flavor,
agyProtocol: metadata?.agyProtocol,
cursorSessionProtocol: metadata?.cursorSessionProtocol,
cursorSessionId: metadata?.cursorSessionId
)
}
/// List-row gate: summaries carry only the flavor, so protocol markers
/// fall back to "unknown ⇒ supported", matching the web's compat fallback.
public static func isSupported(_ metadata: SessionSummaryMetadata?) -> Bool {
isSupported(
flavor: metadata?.flavor,
agyProtocol: nil,
cursorSessionProtocol: nil,
cursorSessionId: nil
)
}
static func isSupported(
flavor rawFlavor: String?,
agyProtocol: String?,
cursorSessionProtocol: String?,
cursorSessionId: String?
) -> Bool {
guard let flavor = rawFlavor.map({ $0.lowercased() }) else { return false }
guard supportedFlavors.contains(flavor) else { return false }
switch flavor {
case "agy":
return agyProtocol == "acp"
case "cursor":
if cursorSessionProtocol == "stream-json" { return false }
return cursorSessionProtocol == "acp" || cursorSessionId == nil
default:
return true
}
}
/// Whether the provider reports an active steerable turn. Follows the
/// per-flavor signal the web uses: `thinking` for pi, `steeringActive`
/// for everyone else.
public static func hasActiveTurn(_ session: Session?) -> Bool {
guard let session, isSupported(session.metadata) else { return false }
if session.metadata?.flavor?.lowercased() == "pi" {
return session.thinking
}
return session.agentState?.steeringActive == true
}
}