mirror of
https://github.com/wu736139669/hapi.git
synced 2026-10-08 19:19:42 +00:00
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.
36 lines
1.3 KiB
Swift
36 lines
1.3 KiB
Swift
import Foundation
|
|
import HapiProtocol
|
|
|
|
/// Permission resolution (`docs/api/client-contract/rest.md`). Pending
|
|
/// requests are **not messages** — they live in `session.agentState.requests`
|
|
/// and move to `completedRequests` once decided. Both endpoints 404 when the
|
|
/// request id is no longer pending and 409 `session_inactive` when the
|
|
/// session is inactive.
|
|
extension APIClient {
|
|
/// `POST /api/sessions/:id/permissions/:requestId/approve`.
|
|
public func approvePermission(
|
|
sessionId: String,
|
|
requestId: String,
|
|
_ body: PermissionApproveRequest = PermissionApproveRequest()
|
|
) async throws {
|
|
try await requestVoid(
|
|
.post,
|
|
"/api/sessions/\(encodePathComponent(sessionId))/permissions/\(encodePathComponent(requestId))/approve",
|
|
body: body
|
|
)
|
|
}
|
|
|
|
/// `POST /api/sessions/:id/permissions/:requestId/deny`.
|
|
public func denyPermission(
|
|
sessionId: String,
|
|
requestId: String,
|
|
decision: PermissionDecision? = nil
|
|
) async throws {
|
|
try await requestVoid(
|
|
.post,
|
|
"/api/sessions/\(encodePathComponent(sessionId))/permissions/\(encodePathComponent(requestId))/deny",
|
|
body: PermissionDenyRequest(decision: decision)
|
|
)
|
|
}
|
|
}
|