feat(ios): HapiClient API transport + auth (A-M1b)

APIClient (final class, Sendable) with typed endpoints for the M2/M3 REST
surface behind an HTTPPerforming seam; actor AuthManager with single-flight
JWT refresh (POST /api/auth), proactive refresh 10 min before exp, terminal
authFailed state, and 401 -> refresh -> retry-once wiring per
docs/api/client-contract/auth.md; Keychain credential store (per-hub records
under run.hapi.companion) with CredentialStoring seam + in-memory double;
HubRegistry (ordered hubs + active hub in injectable UserDefaults, origin
normalization); payload-only JWT decoding; APIError {status, code, body}
parsing per errors.md; minimal multipart builder for M4c dictation; 256 MB
URLCache session for generated images.

Request/response wire models (SendMessageRequest, PermissionApproveRequest,
SpawnRequest/SpawnResponse, MessagesQuery, envelopes, RPC-wrapped shapes)
join HapiProtocol/Models mirroring shared/src/apiTypes.ts.

swift-testing coverage: JWT decode (padding/garbage/hostile exp), auth
single-flight (8 concurrent callers -> one exchange), 401 retry-once and
terminal paths, APIError body parsing, endpoint request construction
byte-checks (cursor queries, deliveryMode body, answers formats, explicit
null model reset) via a recording performer, hub URL normalization,
multipart bytes.
This commit is contained in:
weishu
2026-08-17 15:20:03 +08:00
parent 1e80327d76
commit 1f0ec6184d
27 changed files with 3153 additions and 6 deletions
@@ -1,11 +1,11 @@
import Foundation
import HapiProtocol
/// Scaffold marker for the transport layer.
/// Version anchor for the transport layer.
///
/// APIClient, AuthManager (single-flight refresh), and SSEClient arrive in
/// M1b/M1c. Until then this constant proves the target graph and the
/// HapiClient -> HapiProtocol dependency compile and link.
/// As of M1b the target carries `APIClient` + typed endpoints, `AuthManager`
/// (single-flight JWT refresh), the Keychain credential store, `HubRegistry`,
/// and the multipart builder; SSEClient and the stores arrive in M1c+.
public enum HapiClientVersion {
/// Version of the HapiKit client scaffold.
public static let current = "0.1.0"