mirror of
https://github.com/wu736139669/hapi.git
synced 2026-12-04 06:57:55 +00:00
Three H5 parity pieces for the chat surface: - Conversation outline: a sheet lists the user prompts loaded in the transcript, filters them by text, and scrolls/flashes the chosen prompt through the same tokenized transcript target as pending requests. - Plan quotas: a compact 5h/7d used-percent readout in the composer strip, fed by the runner's agent-quotas RPC through a new machine endpoint client. Hidden unless the machine advertises the capability and the active agent reports an OK account; refreshes every two minutes. - PR awareness: session metadata now decodes external refs (tolerantly for unknown kinds), the list row shows the primary GitHub PR number with a forge-state tint, and the row context menu opens the PR in Safari. Adds pure tests for outline filtering/truncation, quota selection and countdown formatting, and PR badge precedence plus wire decoding. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> Co-Authored-By: Claude Code <noreply@anthropic.com>
82 lines
2.5 KiB
Swift
82 lines
2.5 KiB
Swift
import Foundation
|
|
|
|
/// One rate-limit window reported by a runner's quota RPC
|
|
/// (`AgentQuotaBucketSchema`, `shared/src/apiTypes.ts`).
|
|
public struct AgentQuotaBucket: Codable, Equatable, Sendable, Identifiable {
|
|
public var id: String
|
|
public var label: String
|
|
public var group: String?
|
|
/// Wire window key: `5h`, `weekly`, … (`nil` for account-wide buckets).
|
|
public var window: String?
|
|
public var usedPercent: Double
|
|
public var remainingPercent: Double
|
|
/// Epoch ms; nil when the provider does not expose a reset.
|
|
public var resetsAt: Int?
|
|
|
|
public init(
|
|
id: String,
|
|
label: String,
|
|
group: String? = nil,
|
|
window: String? = nil,
|
|
usedPercent: Double,
|
|
remainingPercent: Double,
|
|
resetsAt: Int? = nil
|
|
) {
|
|
self.id = id
|
|
self.label = label
|
|
self.group = group
|
|
self.window = window
|
|
self.usedPercent = usedPercent
|
|
self.remainingPercent = remainingPercent
|
|
self.resetsAt = resetsAt
|
|
}
|
|
}
|
|
|
|
/// One agent account's quota snapshot (`AgentQuotaAccountSchema`).
|
|
public struct AgentQuotaAccount: Codable, Equatable, Sendable {
|
|
/// Agent flavor id (`claude`, `codex`, …).
|
|
public var agent: String
|
|
public var available: Bool
|
|
/// `ok`, `custom_provider`, `unauthenticated`, `unavailable`, `error`.
|
|
public var status: String
|
|
public var accountLabel: String?
|
|
public var planLabel: String?
|
|
public var creditsLabel: String?
|
|
public var buckets: [AgentQuotaBucket]
|
|
public var note: String?
|
|
public var updatedAt: Int
|
|
|
|
public init(
|
|
agent: String,
|
|
available: Bool,
|
|
status: String,
|
|
accountLabel: String? = nil,
|
|
planLabel: String? = nil,
|
|
creditsLabel: String? = nil,
|
|
buckets: [AgentQuotaBucket],
|
|
note: String? = nil,
|
|
updatedAt: Int
|
|
) {
|
|
self.agent = agent
|
|
self.available = available
|
|
self.status = status
|
|
self.accountLabel = accountLabel
|
|
self.planLabel = planLabel
|
|
self.creditsLabel = creditsLabel
|
|
self.buckets = buckets
|
|
self.note = note
|
|
self.updatedAt = updatedAt
|
|
}
|
|
}
|
|
|
|
/// `GET /api/machines/:id/agent-quotas` (`AgentQuotasResponseSchema`).
|
|
public struct AgentQuotasResponse: Codable, Equatable, Sendable {
|
|
public var accounts: [AgentQuotaAccount]
|
|
public var fetchedAt: Int
|
|
|
|
public init(accounts: [AgentQuotaAccount], fetchedAt: Int) {
|
|
self.accounts = accounts
|
|
self.fetchedAt = fetchedAt
|
|
}
|
|
}
|