chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.6.0 Latest 5 packages
0
0
A feed tile says when newer posts came, and goes to them
crates/hud-core/src/tools.rs+92−6
| @@ -1816,7 +1816,7 @@ impl Hud { | ||
}; | ||
let method = method.as_str(); | ||
let doc = self.query_lexicon(method).await?; | ||
xrpc::query_def(method, &doc)?; | ||
let def = xrpc::query_def(method, &doc)?; | ||
let chosen = args.method_view(method)?; | ||
if let Some(c) = &chosen { | ||
self.check_query_joins(c).await?; | ||
| @@ -1885,7 +1885,7 @@ impl Hud { | ||
structured["joins"] = Value::Object(joined); | ||
} | ||
let none = (&Value::Null, &Value::Null); | ||
let ui = self | ||
let mut ui = self | ||
.call_ui( | ||
chosen.as_ref(), | ||
"query", | ||
| @@ -1896,6 +1896,14 @@ impl Hud { | ||
) | ||
.await | ||
.unwrap_or_else(|| json_ui(&structured)); | ||
// What tells something newer came asks for the newest item alone, | ||
// where the method takes a limit (as small as its lexicon allows). | ||
let limit = &def["parameters"]["properties"]["limit"]; | ||
if let Some(args) = ui.pointer_mut("/latest/call/args") | ||
&& limit["type"] == "integer" | ||
{ | ||
args["params"]["limit"] = limit["minimum"].as_u64().unwrap_or(1).max(1).into(); | ||
} | ||
Ok(Output { | ||
text, | ||
structured, | ||
| @@ -2006,8 +2014,9 @@ fn view_ui( | ||
| ||
/// A query view's layout resolved over its answer. Its scope is the | ||
/// answer, its items and cursor where the view says, its query joins; | ||
/// `next` the call for the page after; a feed view's `report`, its feed | ||
/// bound in the answer. | ||
/// `next` the call for the page after; `latest` how to tell something | ||
/// newer came (`latest_ui`); a feed view's `report`, its feed bound in | ||
/// the answer. | ||
fn query_ui( | ||
v: &View, | ||
trusted: bool, | ||
| @@ -2048,7 +2057,7 @@ fn query_ui( | ||
let feed = i.feed.get(structured).and_then(Value::as_str)?; | ||
Some((i, feed)) | ||
}); | ||
resolved_ui( | ||
let mut ui = resolved_ui( | ||
v, | ||
trusted, | ||
&v.doc["query"]["layout"], | ||
| @@ -2057,9 +2066,44 @@ fn query_ui( | ||
next, | ||
me, | ||
(None, None), | ||
) | ||
); | ||
if let Some(latest) = latest_ui(q, &scope["items"], arguments) { | ||
ui["latest"] = latest; | ||
} | ||
ui | ||
} | ||
| ||
/// How to tell something newer came than a page of a query's items, where | ||
/// its view names each one's key: the call again with no cursor (its | ||
/// `limit` made 1 by `query`, where the method takes one), the items drawn | ||
/// by their keys, and what they are (the summary's plural noun). Something | ||
/// newer came when that call's tree has a key these lack. | ||
fn latest_ui(q: &view::QueryMode, items: &Value, arguments: Option<&Value>) -> Option<Value> { | ||
let key = q.latest.as_ref()?; | ||
let items: Vec<Value> = items | ||
.as_array()? | ||
.iter() | ||
.filter_map(|item| key.get(item).and_then(Value::as_str)) | ||
.take(MAX_LATEST_ITEMS) | ||
.map(|key| json!({ "key": key })) | ||
.collect(); | ||
let mut args = arguments.cloned().unwrap_or_else(|| json!({})); | ||
let o = args.as_object_mut()?; | ||
o.remove("cursor"); | ||
if let Some(Value::Object(params)) = o.get_mut("params") { | ||
params.remove("cursor"); | ||
} | ||
let mut latest = json!({ "call": { "name": "query", "args": args }, "items": items }); | ||
if let Some(s) = &q.summary { | ||
latest["noun"] = s.noun[1].as_str().into(); | ||
} | ||
Some(latest) | ||
} | ||
| ||
/// The most items a tree's `latest` holds: a page's, as a method's `limit` | ||
/// allows at most (100 for the AppView's feeds). | ||
const MAX_LATEST_ITEMS: usize = 100; | ||
| ||
/// The call for the page after a page of records, when it has a cursor. | ||
fn next_page(structured: &Value, arguments: Option<&Value>) -> Option<Value> { | ||
structured["cursor"] | ||
| @@ -3515,6 +3559,48 @@ mod tests { | ||
assert!(queries_opened(&items[2]).is_empty()); | ||
} | ||
| ||
#[test] | ||
fn a_feed_tree_says_how_to_tell_something_newer_came() { | ||
let bundled = |method| { | ||
let Ok(Some(Chosen::Bundled(v))) = Args::of(Some(&json!({})), &["view"]) | ||
.unwrap() | ||
.method_view(method) | ||
else { | ||
panic!("{method} has a bundled view"); | ||
}; | ||
v | ||
}; | ||
let post = |rkey: &str| { | ||
json!({ "post": { "uri": format!("at://did:plc:alice/app.bsky.feed.post/{rkey}"), "cid": "bafyrei", | ||
"author": { "did": "did:plc:alice", "handle": "alice.test" }, | ||
"record": { "text": rkey, "createdAt": "2026-11-17T09:00:00.000Z" }, | ||
"indexedAt": "2026-11-17T09:00:00.000Z" } }) | ||
}; | ||
// A page after the first: its keys, and the call again from the top. | ||
let arguments = json!({ "method": "app.bsky.feed.getAuthorFeed", "cursor": "c1", | ||
"params": { "actor": "alice.test", "cursor": "c0", "includePins": true } }); | ||
let structured = json!({ "method": "app.bsky.feed.getAuthorFeed", "service": "did:web:api.bsky.app#bsky_appview", | ||
"params": arguments["params"], "response": { "feed": [post("pinned"), post("b"), post("a")], "cursor": "c2" } }); | ||
let read = (None, None); | ||
let v = bundled("app.bsky.feed.getAuthorFeed"); | ||
let ui = view_ui(v, true, "query", &structured, Some(&arguments), None, read).unwrap(); | ||
assert_eq!(ui::check(&ui), Ok(())); | ||
assert_eq!( | ||
ui["latest"], | ||
json!({ "call": { "name": "query", "args": { "method": "app.bsky.feed.getAuthorFeed", | ||
"params": { "actor": "alice.test", "includePins": true } } }, | ||
"items": [{ "key": "at://did:plc:alice/app.bsky.feed.post/pinned" }, | ||
{ "key": "at://did:plc:alice/app.bsky.feed.post/b" }, | ||
{ "key": "at://did:plc:alice/app.bsky.feed.post/a" }], | ||
"noun": "posts" }) | ||
); | ||
// A view naming no key says nothing of it (a feed's posts are | ||
// chosen afresh, not newest first). | ||
let v = bundled("app.bsky.feed.getFeed"); | ||
let ui = view_ui(v, true, "query", &structured, Some(&arguments), None, read).unwrap(); | ||
assert!(ui.get("latest").is_none()); | ||
} | ||
| ||
#[test] | ||
fn descriptions_stripped() { | ||
let mut defs = json!({ "main": { "type": "record", "description": "a record", | ||
crates/hud-core/src/view.rs+16−1
| @@ -280,6 +280,9 @@ pub struct QueryMode { | ||
pub items: Option<Path>, | ||
/// The answer's cursor for the next page, from the answer. | ||
pub cursor: Option<Path>, | ||
/// Each item's key, within it (`post.uri`): with it, a tree says how | ||
/// to tell something newer came (`_meta.ui.latest`). | ||
pub latest: Option<Path>, | ||
pub summary: Option<Summary>, | ||
/// The queries it joins, once an answer. | ||
pub queries: Vec<QueryJoin>, | ||
| @@ -1381,7 +1384,11 @@ fn parse_interactions(p: &mut Problems, v: &Value) -> Option<Interactions> { | ||
/// if it has them, the queries it joins, its summary, its layout. | ||
fn parse_query_mode(p: &mut Problems, v: &Value) -> Option<QueryMode> { | ||
let at = "query"; | ||
let o = p.object(v, at, &["items", "cursor", "join", "summary", "layout"])?; | ||
let o = p.object( | ||
v, | ||
at, | ||
&["items", "cursor", "latest", "join", "summary", "layout"], | ||
)?; | ||
let items = o.get("items").and_then(|i| p.path(i, "query.items")); | ||
let cursor = o.get("cursor").and_then(|c| p.path(c, "query.cursor")); | ||
if o.contains_key("cursor") && !o.contains_key("items") { | ||
| @@ -1390,6 +1397,13 @@ fn parse_query_mode(p: &mut Problems, v: &Value) -> Option<QueryMode> { | ||
"a cursor pages items: name query.items too, or no cursor", | ||
); | ||
} | ||
let latest = o.get("latest").and_then(|l| p.path(l, "query.latest")); | ||
if o.contains_key("latest") && !o.contains_key("items") { | ||
p.add( | ||
"query.latest", | ||
"the path to each item's key: name query.items too, or no latest", | ||
); | ||
} | ||
let queries = match o.get("join") { | ||
Some(j) => joins(p, j, "query.join", 1, Some((QUERY_SCOPE, false))).1, | ||
None => Vec::new(), | ||
| @@ -1401,6 +1415,7 @@ fn parse_query_mode(p: &mut Problems, v: &Value) -> Option<QueryMode> { | ||
Some(QueryMode { | ||
items, | ||
cursor, | ||
latest, | ||
summary, | ||
queries, | ||
}) | ||
docs/views.md+14−0
| @@ -129,6 +129,20 @@ An answer that's one thing (a thread) has no items. Its summary reads the scope | ||
summary's `by` names the author, and its count is bound to an array. The count counts that array | ||
and, with `children`, the arrays nested in it (`Thread: "…" by alice.example: 12 replies.`). | ||
| ||
### Newer items | ||
| ||
A list that runs newest first can name each item's key in `latest`, a path within each item | ||
(`"latest": "post.uri"`). HUD then puts `_meta.ui.latest` in the tree. It holds the same call with | ||
no cursor (`call`), the items drawn by their keys (`items`, each `{ key }`), and the summary's | ||
plural noun (`noun`, "posts"). Where the method | ||
takes a `limit`, that call asks for the fewest its lexicon allows (1 for the AppView's feeds). | ||
| ||
Something newer came when that call's tree has a key the drawn ones lack. So a pinned post at the | ||
top of an author feed doesn't count, since it was drawn too. The bundled timeline, author feed, and | ||
knotless's feed and notifications name a key. A custom feed (`app.bsky.feed.getFeed`) doesn't, | ||
because it picks its posts afresh on every call and nearly every check would find something. What | ||
the clients do with it is on [the workspace page](workspace.md#newer-items). | ||
| ||
## Query joins | ||
| ||
Any mode may also join a few related queries, so one tile draws the answer with what goes with it. | ||
docs/workspace.md+8−0
| @@ -81,6 +81,14 @@ Each takes `canvas`, an id or a name. By default it's the person's current canva | ||
| ||
A tile opened from another keeps that tile's id (`from`). Taking a tile off leaves the tiles opened from it as they are. | ||
| ||
## Newer items | ||
| ||
A tile drawing a list newest first (a tree with `latest`, see [query views](views.md#newer-items)) checks for newer items while it's drawn and the page is in view. It checks once a minute, and again as it comes back into view if its last read or check was 30 s or more ago. It stops once it finds some. | ||
| ||
Then its refresh button shows without a hover, with a dot. Scrolled down, a "New posts" button also sits over the top of its body, and it goes to the top and reads the tile again. HUD never puts newer items in above what a person is reading. Ten such tiles on screen make about ten small calls a minute. | ||
| ||
The iOS app checks the same way while a column is on screen and the app is active. It shows the button over the column's top, and pulling down still reads the column again. The MCP App view doesn't check. | ||
| ||
## Music | ||
| ||
Music a tile plays keeps going as a person moves about. The page plays it in one `<audio>` of its own, through scrolling, switching tabs, putting a canvas away, and refreshing or closing the tile. | ||
harness/look.mjs+28−5
| @@ -26,6 +26,12 @@ | ||
// t, Shift+ArrowLeft, Meta+k (a step) | ||
// --eval <js> print what the expression gives in | ||
// the page, to see why it looks so (a step) | ||
// --later <ms> the clock moved on so far, and the page | ||
// shown again, as its browser tab coming | ||
// back (a step) | ||
// --newer a list newest first, read the first | ||
// time, says its newest item was not | ||
// drawn, so the next ask finds it newer | ||
// --desktop --phone --light --dark only those; desktop light and | ||
// phone dark if none is given | ||
// --all all four | ||
| @@ -59,6 +65,7 @@ const sets = []; | ||
const steps = []; | ||
const sides = new Set(); | ||
let events = null; | ||
let newer = false; | ||
const argv = process.argv.slice(2); | ||
for (let i = 0; i < argv.length; i++) { | ||
const a = argv[i]; | ||
| @@ -84,6 +91,8 @@ for (let i = 0; i < argv.length; i++) { | ||
steps.push({ sel, text }); | ||
} else if (a === '--press') steps.push({ key: next() }); | ||
else if (a === '--eval') steps.push({ js: next() }); | ||
else if (a === '--later') steps.push({ later: Number(next()) }); | ||
else if (a === '--newer') newer = true; | ||
else if (a === '--all') for (const s of ['desktop', 'phone', 'light', 'dark']) sides.add(s); | ||
else if (/^--(desktop|phone|light|dark)$/.test(a)) sides.add(a.slice(2)); | ||
else if (a.startsWith('--')) fail(`${a}: no such option`); | ||
| @@ -110,12 +119,13 @@ const used = new Set(); | ||
// The world as the stand-in keeps it, changed by what the page asks; as | ||
// the world has it again for each picture, so what one picture's steps | ||
// changed (a canvas opened from the + menu) is not there for the next. | ||
let views, tiles, open, current; | ||
let views, tiles, open, current, held; | ||
const reset = () => { | ||
views = new Map(w.canvases.map((c) => [c.view.key, structuredClone(c.view)])); | ||
tiles = new Map(w.canvases.map((c) => [c.view.key, structuredClone(c.tiles)])); | ||
open = [...w.open]; | ||
current = w.current; | ||
held = new Set(); | ||
}; | ||
let made = 0; | ||
| ||
| @@ -174,7 +184,8 @@ function tool(name, args) { | ||
.map((k) => `${JSON.stringify(k)}:${canonical(v[k])}`) | ||
.join(',')}}` | ||
: JSON.stringify(v); | ||
const found = recorded.calls[`${name} ${canonical(args ?? {})}`]; | ||
const key = `${name} ${canonical(args ?? {})}`; | ||
const found = recorded.calls[key]; | ||
// An app's page needs no recording: its head and entry points come from the bundled views (no account's part, offline). | ||
if (!found && name === 'describe_app' && typeof args?.domain === 'string') { | ||
const domain = args.domain.toLowerCase(); | ||
| @@ -184,7 +195,14 @@ function tool(name, args) { | ||
if (!found) return { isError: true, content: [{ type: 'text', text: `Not recorded: ${name}.` }] }; | ||
const doc = found._meta?.view?.doc; | ||
const now = doc && bundled.get(doc.method ?? doc.collection); | ||
return resolved(name, args, now ? { ...found, _meta: { ...found._meta, view: { ...found._meta.view, doc: now } } } : found); | ||
const answer = resolved(name, args, now ? { ...found, _meta: { ...found._meta, view: { ...found._meta.view, doc: now } } } : found); | ||
// --newer: its newest item held back the first time, as if it came after. | ||
const latest = answer._meta?.ui?.latest; | ||
if (newer && latest?.items.length && !held.has(key)) { | ||
held.add(key); | ||
latest.items = latest.items.slice(1); | ||
} | ||
return answer; | ||
} | ||
| ||
const tileView = (canvas, input, extra) => ({ | ||
| @@ -405,7 +423,8 @@ try { | ||
const [device, scheme] = project.split('-'); | ||
const context = await browser.newContext({ ...devices[device], colorScheme: scheme, locale: 'en-US', timezoneId: 'America/Los_Angeles', reducedMotion: 'reduce' }); | ||
const page = await context.newPage(); | ||
await page.clock.setFixedTime(new Date('2026-11-14T19:00:00.000Z')); | ||
let now = new Date('2026-11-14T19:00:00.000Z').getTime(); | ||
await page.clock.setFixedTime(now); | ||
await page.goto(`${base}/workspace`, { waitUntil: 'load' }); | ||
await page.locator('.strip.shown').waitFor(); | ||
const settle = async () => { | ||
| @@ -420,7 +439,11 @@ try { | ||
} | ||
for (const s of steps) { | ||
if (s.js) console.log(JSON.stringify(await page.evaluate(s.js))); | ||
else if (s.key) await page.keyboard.press(s.key); | ||
else if (s.later) { | ||
now += s.later; | ||
await page.clock.setFixedTime(now); | ||
await page.evaluate(() => document.dispatchEvent(new Event('visibilitychange'))); | ||
} else if (s.key) await page.keyboard.press(s.key); | ||
else if (s.sel) { | ||
const it = page.locator(s.sel).first(); | ||
await it.fill(''); | ||
ios/App/Browser.swift+20−0
| @@ -295,8 +295,13 @@ final class Step: Hashable { | ||
var viewer: Viewer? | ||
/// Whether the latest call needed an account it was not made as. | ||
var needsSignIn = false | ||
/// Whether something newer came than the items drawn (`peek`). | ||
var fresh = false | ||
/// The posts this screen has told its feed were seen. | ||
@ObservationIgnored var told: Set<String> = [] | ||
/// When it was last read, or asked whether something newer came. | ||
@ObservationIgnored var checked = Date.distantPast | ||
@ObservationIgnored private var peeking = false | ||
| ||
init(call: Call) { | ||
self.call = call | ||
| @@ -339,6 +344,8 @@ final class Step: Hashable { | ||
if !result.isError { viewer = result.viewer } | ||
needsSignIn = false | ||
drawn = Drawn(result) | ||
fresh = false | ||
checked = .now | ||
} catch is CancellationError { | ||
} catch let error as URLError where error.code == .cancelled { | ||
} catch { | ||
| @@ -348,6 +355,19 @@ final class Step: Hashable { | ||
} | ||
} | ||
| ||
/// Ask whether something newer came than what it drew: its newest item | ||
/// alone, as its tree's `latest` calls it. A failure says nothing, and | ||
/// the next ask asks again. | ||
func peek(_ client: HUDClient) async { | ||
guard !fresh, !peeking, let latest = drawn?.latest else { return } | ||
peeking = true | ||
checked = .now | ||
defer { peeking = false } | ||
guard let result = try? await client.call(latest.call), !Task.isCancelled else { return } | ||
// What it drew is what was asked of: not read again meanwhile. | ||
if drawn?.latest?.keys == latest.keys, latest.isNewer(Drawn(result)) { fresh = true } | ||
} | ||
| ||
/// A page more, its tree's `next`. | ||
func loadMore(_ client: HUDClient) async { | ||
guard !loadingMore, let drawn, let next = drawn.nextPage else { return } | ||
ios/App/StepScreen.swift+82−20
| @@ -24,6 +24,10 @@ struct StepScreen: View { | ||
/// sent. What opens from it goes to `open`, a tab's call | ||
/// to `replace`; links in Safari. A call that needs an account offers | ||
/// sign-in in place of its error, and is made again once signed in. | ||
/// A list newest first (a tree with `latest`) is asked now and then, while | ||
/// on screen with the app active, whether something newer came: then a | ||
/// button over its top says so, and goes to its top and reads it again. | ||
/// Nothing newer is put in under the reader. | ||
struct StepView: View { | ||
let step: Step | ||
let browser: Browser | ||
| @@ -36,46 +40,104 @@ struct StepView: View { | ||
/// comes back on screen) would leave its links opening nothing. | ||
@State private var wired: ObjectIdentifier? | ||
@Environment(\.webAuthenticationSession) private var web | ||
@Environment(\.scenePhase) private var phase | ||
| ||
/// How often a list newest first asks whether something newer came, and | ||
/// how long after it was read or asked it asks again as it comes back. | ||
private static let peekEvery: Duration = .seconds(60) | ||
private static let peekAfter: TimeInterval = 30 | ||
| ||
var body: some View { | ||
Group { | ||
if !step.needsSignIn, let drawn = step.drawn, drawn.pagesItself, wired == ObjectIdentifier(step) { | ||
ResultView(drawn: drawn, context: context, onRetry: { Task { await step.load(browser.client) } }) | ||
} else { | ||
ScrollView { | ||
VStack(alignment: .leading, spacing: Space.s3) { | ||
if step.needsSignIn { | ||
signIn | ||
} else if let drawn = step.drawn, wired == ObjectIdentifier(step) { | ||
ResultView(drawn: drawn, context: context, onRetry: { Task { await step.load(browser.client) } }) | ||
foot(drawn) | ||
} else { | ||
ProgressView() | ||
.frame(maxWidth: .infinity) | ||
.padding(.top, 80) | ||
ScrollViewReader { proxy in | ||
ScrollView { | ||
VStack(alignment: .leading, spacing: Space.s3) { | ||
if step.needsSignIn { | ||
signIn | ||
} else if let drawn = step.drawn, wired == ObjectIdentifier(step) { | ||
ResultView(drawn: drawn, context: context, onRetry: { Task { await step.load(browser.client) } }) | ||
foot(drawn) | ||
} else { | ||
ProgressView() | ||
.frame(maxWidth: .infinity) | ||
.padding(.top, 80) | ||
} | ||
} | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.padding(.horizontal, Space.s3) | ||
.environment(\.listBleed, Space.s3) | ||
.padding(.vertical, Space.s2) | ||
.id(Self.top) | ||
} | ||
.overlay(alignment: .top) { | ||
if step.fresh, let noun = step.drawn?.latest?.noun { | ||
newer(noun) { | ||
withAnimation { proxy.scrollTo(Self.top, anchor: .top) } | ||
Task { await refresh() } | ||
} | ||
} | ||
} | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.padding(.horizontal, Space.s3) | ||
.environment(\.listBleed, Space.s3) | ||
.padding(.vertical, Space.s2) | ||
} | ||
} | ||
} | ||
.background(.tileSurface) | ||
.refreshable { | ||
step.told = [] | ||
await step.load(browser.client) | ||
configure() | ||
} | ||
.refreshable { await refresh() } | ||
// Another step in its place (a tab chosen in a tile): read and drawn afresh. | ||
.task(id: ObjectIdentifier(step)) { | ||
if step.drawn == nil { await step.load(browser.client) } | ||
configure() | ||
} | ||
// On screen with the app active: asked whether something newer came, | ||
// at once where it was read or asked long enough ago, then every | ||
// minute, until something did. | ||
.task(id: Peeking(step: ObjectIdentifier(step), active: phase == .active, listed: step.drawn?.latest != nil, fresh: step.fresh)) { | ||
guard phase == .active, !step.fresh, step.drawn?.latest != nil else { return } | ||
if Date.now.timeIntervalSince(step.checked) >= Self.peekAfter { await step.peek(browser.client) } | ||
while !Task.isCancelled, !step.fresh { | ||
try? await Task.sleep(for: Self.peekEvery) | ||
if Task.isCancelled { return } | ||
await step.peek(browser.client) | ||
} | ||
} | ||
.onDisappear { Task { await browser.feedback.flush() } } | ||
} | ||
| ||
/// The top of its scroll, which the button saying something newer came goes to. | ||
private static let top = "top" | ||
| ||
/// What the polling task restarts on. | ||
private struct Peeking: Hashable { | ||
let step: ObjectIdentifier | ||
let active: Bool | ||
let listed: Bool | ||
let fresh: Bool | ||
} | ||
| ||
/// Read afresh, its feed told anew of what is seen. | ||
private func refresh() async { | ||
step.told = [] | ||
await step.load(browser.client) | ||
configure() | ||
} | ||
| ||
/// The button over its top saying something newer came ("New posts"): | ||
/// a piece of glass, as what floats over content is. | ||
private func newer(_ noun: String, action: @escaping () -> Void) -> some View { | ||
Button(action: action) { | ||
Label("New \(noun)", systemImage: "arrow.up") | ||
.font(.subheadline.weight(.semibold)) | ||
.padding(.horizontal, Space.s3) | ||
.padding(.vertical, Space.s2) | ||
.hudGlass(in: Capsule(), interactive: true) { $0.background(.bar, in: Capsule()) } | ||
} | ||
.buttonStyle(.plain) | ||
.padding(.top, Space.s2) | ||
.transition(.move(edge: .top).combined(with: .opacity)) | ||
} | ||
| ||
private var signIn: some View { | ||
ContentUnavailableView { | ||
Label("Sign in to see this", systemImage: "person.crop.circle.badge.questionmark") | ||
ios/HUDKit/Sources/HUDKit/Data/Result.swift+29−0
| @@ -95,6 +95,19 @@ public enum Drawn: Sendable { | ||
return Call(name, next["args"]?.object ?? [:]) | ||
} | ||
| ||
/// How to tell something newer came than its items: a tree's `latest`, | ||
/// where its view names each item's key. | ||
public var latest: Latest? { | ||
guard case .tree(let ui) = self, let latest = ui["latest"], let call = latest["call"], | ||
let name = call["name"]?.string, let items = latest["items"]?.array | ||
else { return nil } | ||
return Latest( | ||
call: Call(name, call["args"]?.object ?? [:]), | ||
keys: Set(items.compactMap { $0["key"]?.string }), | ||
noun: latest["noun"]?.string ?? "items" | ||
) | ||
} | ||
| ||
/// Whether its tree scrolls and pages itself: a conversation | ||
/// (`Messages`), held to its foot with its box under it, its earlier | ||
/// messages asked for at its top (`ViewContext.onMore`). The app draws | ||
| @@ -150,3 +163,19 @@ public enum Drawn: Sendable { | ||
return nil | ||
} | ||
} | ||
| ||
/// How to tell something newer came than a query's items, as | ||
/// web/shared/result.ts reads it: make `call`, and something did when its | ||
/// tree's `latest` has a key `keys` lacks; `noun` what the items are, | ||
/// plural (posts). | ||
public struct Latest: Sendable { | ||
public let call: Call | ||
public let keys: Set<String> | ||
public let noun: String | ||
| ||
/// Whether `peeked`, what `call` answered, has an item these keys lack: | ||
/// one newer than those drawn (not a pinned post, which was drawn too). | ||
public func isNewer(_ peeked: Drawn) -> Bool { | ||
peeked.latest?.keys.contains { !keys.contains($0) } ?? false | ||
} | ||
} | ||
schemas/place.hud.ui.json+19−0
| @@ -14,6 +14,7 @@ | ||
"people": { "type": "string", "maxLength": 253, "description": "The domain of the app the tree is of, where it has a page: an account a mention names opens as describe_app { domain, actor }, its page there; absent: as describe_repo." }, | ||
"root": { "type": "ref", "ref": "#node" }, | ||
"next": { "type": "ref", "ref": "#call", "description": "The call for the page after: its tree's page list's items go after these (a node with page and items, whatever its component)." }, | ||
"latest": { "type": "ref", "ref": "#latest" }, | ||
"report": { "type": "ref", "ref": "#report" } | ||
} | ||
}, | ||
| @@ -50,6 +51,24 @@ | ||
"args": { "type": "unknown", "description": "Its arguments." } | ||
} | ||
}, | ||
"latest": { | ||
"type": "object", | ||
"description": "How to tell something newer came than the items a query's tree drew: make call, and something did when its tree's latest has an item whose key none of these items has.", | ||
"required": ["call", "items"], | ||
"properties": { | ||
"call": { "type": "ref", "ref": "#call", "description": "The tree's own call with no cursor, asking for as few items as its method allows." }, | ||
"items": { "type": "array", "maxLength": 100, "items": { "type": "ref", "ref": "#latestItem" }, "description": "The items drawn, in order." }, | ||
"noun": { "type": "string", "maxLength": 32, "description": "What the items are, plural (posts), as its view's summary names them." } | ||
} | ||
}, | ||
"latestItem": { | ||
"type": "object", | ||
"description": "An item drawn, as a tree's latest knows it.", | ||
"required": ["key"], | ||
"properties": { | ||
"key": { "type": "string", "maxLength": 8192, "description": "The item's key, as its view names it (a post's at-uri)." } | ||
} | ||
}, | ||
"run": { | ||
"type": "object", | ||
"description": "A run of text: plain, or a link, an account or a tag; each formatting flag present only when true.", | ||
views/bsky-author-feed.json+1−0
| @@ -11,6 +11,7 @@ | ||
"query": { | ||
"items": "feed", | ||
"cursor": "cursor", | ||
"latest": "post.uri", | ||
"summary": { "noun": ["post", "posts"], "label": { "$": "post.record.text" } }, | ||
"layout": { | ||
"component": "List", | ||