Files
hapi/ios/Packages/HapiKit/Sources/HapiProtocol/Models/SessionShare.swift
T
30f775cb84 feat(ios): preview HTML files and share sessions
HTML preview:
- HTML/HTM files get a Source/Preview toggle in the file viewer. Preview
  uses a WKWebView with JavaScript disabled and a non-persistent data
  store, matching the web's inline "preview sandbox · scripts disabled".
- The mobile viewport meta is inserted only when the document lacks one
  (web prepareHtmlDocument), and tapped links leave for Safari instead of
  navigating the preview.

Session sharing:
- New share endpoints client (create/read/revoke) and wire models. The
  share link points at the hub's web /shared-session/<token> guest page;
  the six-digit access code is kept from the create response because the
  hub never returns it again.
- A Share Session sheet creates/regenerates/revokes the link, copies the
  link or code, and offers the native share sheet. Reopening the sheet
  keeps a code created earlier in the same chat.

Adds endpoint, URL-building, model, and HTML-document tests.

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

Co-Authored-By: HAPI <noreply@hapi.run>
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-12-01 09:29:55 +08:00

64 lines
2.1 KiB
Swift

import Foundation
/// An active public share for one session (`SessionShare`,
/// `shared/src/apiTypes.ts`). The access code is never returned by list/get
/// endpoints — only when the share is created or regenerated.
public struct SessionShare: Codable, Equatable, Sendable, Identifiable {
public var id: String
public var sessionId: String
public var shareToken: String
public var createdAt: Int
public var updatedAt: Int
public init(
id: String,
sessionId: String,
shareToken: String,
createdAt: Int,
updatedAt: Int
) {
self.id = id
self.sessionId = sessionId
self.shareToken = shareToken
self.createdAt = createdAt
self.updatedAt = updatedAt
}
}
/// `POST /api/session-shares` — the raw access code is shown exactly once.
public struct SessionShareCreateResponse: Codable, Equatable, Sendable {
public var share: SessionShare
public var accessCode: String
public init(share: SessionShare, accessCode: String) {
self.share = share
self.accessCode = accessCode
}
}
/// `GET /api/session-shares/session/:id` (null when no share is active).
public struct SessionShareEnvelope: Codable, Equatable, Sendable {
public var share: SessionShare?
public init(share: SessionShare?) {
self.share = share
}
}
/// The browser-facing share URL: the hub origin plus the web app's
/// `/shared-session/<token>` route (web `buildSessionShareUrl`). A native
/// client has no PWA origin of its own, so the hub origin is the share host.
public enum SessionShareLink {
public static func url(baseURL: URL, shareToken: String) -> URL? {
guard let scheme = baseURL.scheme, let host = baseURL.host else { return nil }
let token = shareToken.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)
?? shareToken
var components = URLComponents()
components.scheme = scheme
components.host = host
components.port = baseURL.port
components.path = "/shared-session/\(token)"
return components.url
}
}