Files
hapi/ios/Packages/HapiKit/Sources/HapiProtocol/Models/SessionContentSearch.swift
4387dc7f4a feat(ios): search message content and jump to the matched message
Port the H5 content-search scope to the native session list:

- The search field gains a Sessions/Content scope menu. Content mode
  debounces the hub's POST /sessions/content-search over the sessions
  visible under the current machine/status/unread filters, discards stale
  responses by generation, and surfaces loading, failure, and
  potentially-incomplete result states.
- Result rows keep the two-line contract: the matched snippet (plus a
  truncation mark) replaces the project line, while server relevance
  order is preserved.
- Tapping a hit passes its message id to the chat. A row already in the
  loaded transcript scrolls directly; otherwise the window controller
  loads the hub's bounded message-context page, enters history mode, and
  the chat scrolls/flashes the target. "Back to latest" still resets to
  the live tail because a context window is explicitly not the tail.

Adds content-search wire models, endpoint coverage, context-window
transition tests, and session-list model tests for scoping and rendering.

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

Co-Authored-By: HAPI <noreply@hapi.run>
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-12-01 07:22:36 +08:00

58 lines
1.8 KiB
Swift

import Foundation
/// One message hit from the hub's opt-in content search
/// (`SessionContentMatch`, `shared/src/apiTypes.ts`).
public struct SessionContentMatch: Codable, Equatable, Sendable {
public var messageId: String
/// `user` or `assistant`.
public var role: String
public var seq: Int
public var createdAt: Int
/// Hub-composed surrounding text (markup stripped, bounded).
public var snippet: String
/// The indexed message exceeded the search index budget.
public var truncated: Bool
public init(
messageId: String,
role: String,
seq: Int,
createdAt: Int,
snippet: String,
truncated: Bool
) {
self.messageId = messageId
self.role = role
self.seq = seq
self.createdAt = createdAt
self.snippet = snippet
self.truncated = truncated
}
}
public struct SessionContentSearchResult: Codable, Equatable, Sendable {
public var session: SessionSummary
public var match: SessionContentMatch
public init(session: SessionSummary, match: SessionContentMatch) {
self.session = session
self.match = match
}
}
/// `POST /api/sessions/content-search` (`SessionContentSearchResponse`).
public struct SessionContentSearchResponse: Codable, Equatable, Sendable {
public var results: [SessionContentSearchResult]
/// True when the query may miss content omitted by an indexing
/// optimization (the list surfaces a hint rather than hiding results).
public var hasPotentiallyIncompleteResults: Bool
public init(
results: [SessionContentSearchResult],
hasPotentiallyIncompleteResults: Bool
) {
self.results = results
self.hasPotentiallyIncompleteResults = hasPotentiallyIncompleteResults
}
}