Files
hapi/ios/Hapi/HapiApp.swift
T
14f2dd763e feat(ios): session citations, custom Claude models and chat status polish
- Copy a session citation from the list (native parity with the web
  reference text) and open the paired session list via
  hapicompanion://sessions.
- Load hub-wide custom Claude models in New Session with machine-catalog
  fallback, and show the transcript-resolved model in chat chrome.
- Render synthetic Claude API failures as error events instead of leaking
  the <synthetic> model or zero usage into the context meter.
- Refresh the session list returning from chat, request the list from Home,
  and update the home widget surfaces.

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

Co-Authored-By: HAPI <noreply@hapi.run>
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-08 20:24:30 +08:00

57 lines
1.9 KiB
Swift

import HapiProtocol
import OSLog
import SwiftUI
@main
struct HapiApp: App {
/// APNs registration callbacks + notification-center delegate install
/// (P3) — SwiftUI lifecycle apps get them only through the adaptor.
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
@State private var model = AppModel()
@Environment(\.scenePhase) private var scenePhase
private let log = Logger(subsystem: "run.hapi.companion", category: "app")
var body: some Scene {
WindowGroup {
RootView()
.environment(model)
.onOpenURL { url in
handleIncomingURL(url)
}
}
.onChange(of: scenePhase, initial: true) { _, phase in
model.handleScenePhase(phase)
}
.commands {
HapiCommands()
}
}
/// `hapicompanion://bind?hub=<url>&code=<accessToken>` — parse and route
/// through `AppModel`: unpaired → pairing confirm; already paired to that
/// hub → switch with a notice; a different hub → add-hub confirm.
///
/// Live Activities open `hapicompanion://sessions/<id>[?hub=<url>]`;
/// that form is routed through the same notification-target path.
///
/// Never log the URL itself: the bind query carries the access token.
private func handleIncomingURL(_ url: URL) {
if let link = BindLink.parse(url.absoluteString) {
if !model.handleBindLink(link) {
log.warning("Bind link carried an unusable hub URL")
}
return
}
if SessionListLink.matches(url.absoluteString) {
model.openSessionList()
return
}
if let link = SessionLink.parse(url.absoluteString) {
model.handleSessionLink(link)
return
}
log.warning("Ignoring malformed URL (scheme: \(url.scheme ?? "none", privacy: .public))")
}
}