mirror of
https://github.com/wu736139669/hapi.git
synced 2026-12-05 07:07:04 +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>
105 lines
3.9 KiB
Swift
105 lines
3.9 KiB
Swift
import HapiClient
|
|
import HapiProtocol
|
|
import HapiUI
|
|
import SwiftUI
|
|
|
|
/// One jump target in the conversation outline. Only user prompts currently
|
|
/// loaded in the transcript are listed (web `buildConversationOutline`).
|
|
struct ChatOutlineItem: Identifiable, Equatable {
|
|
/// The transcript row id (the user block's message id).
|
|
let id: String
|
|
let label: String
|
|
let createdAt: Int
|
|
}
|
|
|
|
enum ConversationOutlineBuilder {
|
|
static let maxLabelLength = 96
|
|
|
|
/// Web parity: a user block with no invocation time is a local echo and
|
|
/// not a stable destination; a failed send is still a real prompt.
|
|
static func items(from blocks: [VisibleChatBlock]) -> [ChatOutlineItem] {
|
|
blocks.compactMap { visible in
|
|
guard case .block(.userText(let block)) = visible else { return nil }
|
|
guard !(block.invokedAt == nil && block.status != "failed") else { return nil }
|
|
let label = truncateLabel(block.text)
|
|
return ChatOutlineItem(
|
|
id: block.id,
|
|
label: label.isEmpty ? String(localized: "Empty message") : label,
|
|
createdAt: block.createdAt
|
|
)
|
|
}
|
|
}
|
|
|
|
static func truncateLabel(_ value: String) -> String {
|
|
let collapsed = value
|
|
.split(whereSeparator: \.isWhitespace)
|
|
.joined(separator: " ")
|
|
guard collapsed.count > maxLabelLength else { return collapsed }
|
|
let head = String(collapsed.prefix(maxLabelLength - 3))
|
|
return head.trimmingCharacters(in: .whitespaces) + "..."
|
|
}
|
|
}
|
|
|
|
/// Sheet listing the user prompts in the loaded transcript. Selecting one
|
|
/// closes the sheet and scrolls the transcript to that prompt.
|
|
struct ConversationOutlineSheet: View {
|
|
let items: [ChatOutlineItem]
|
|
let onSelect: (String) -> Void
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
@State private var search = ""
|
|
|
|
private var filtered: [ChatOutlineItem] {
|
|
let query = search.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
guard !query.isEmpty else { return items }
|
|
return items.filter { $0.label.localizedCaseInsensitiveContains(query) }
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
List(filtered) { item in
|
|
Button {
|
|
onSelect(item.id)
|
|
dismiss()
|
|
} label: {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text(verbatim: item.label)
|
|
.foregroundStyle(.primary)
|
|
.lineLimit(3)
|
|
Text(verbatim: ChatTimeLabel.text(for: item.createdAt))
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.contentShape(Rectangle())
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
.overlay {
|
|
if items.isEmpty {
|
|
ContentUnavailableView(
|
|
"No Outline Yet",
|
|
systemImage: "list.bullet.rectangle",
|
|
description: Text("User prompts appear here once the conversation has messages.")
|
|
)
|
|
} else if filtered.isEmpty {
|
|
ContentUnavailableView.search(text: search)
|
|
}
|
|
}
|
|
.searchable(
|
|
text: $search,
|
|
placement: .navigationBarDrawer(displayMode: .always),
|
|
prompt: Text("Search prompts")
|
|
)
|
|
.navigationTitle("Conversation Outline")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .confirmationAction) {
|
|
Button("Done") { dismiss() }
|
|
}
|
|
}
|
|
}
|
|
.presentationDetents([.medium, .large])
|
|
}
|
|
}
|