~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

Notifications tiles for Bluesky and Grain

Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:views/notifications
crates/hud-core/src/apps.rs+8−2
@@ -223,7 +223,13 @@ mod tests {
let me = Some(("did:plc:me", Some("me.test")));
assert_eq!(
titles("bsky.app", me),
["Posts", "Discover", "Saved feeds", "Following"]
[
"Posts",
"Discover",
"Saved feeds",
"Notifications",
"Following"
]
);
// Feeds by name are the account's: a call the query tool resolves for it.
let yours = &entries("bsky.app", me, None)[2].call;
@@ -237,7 +243,7 @@ mod tests {
"params": { "actor": "did:plc:me", "filter": "posts_no_replies" } } })
);
assert_eq!(
mine[3].call,
mine[4].call,
json!({ "name": "query", "args": { "method": "app.bsky.feed.getTimeline", "params": {} } })
);
}
crates/hud-core/src/join.rs+79−10
@@ -350,7 +350,8 @@ impl<'a, F: Fetch> Engine<'a, F> {
pub const QUERY_WAIT: Duration = Duration::from_secs(3);
/// A query join's params, read from the main scope: none when a binding
/// does not resolve, or an `$each` finds nothing.
/// does not resolve, or an `$each` finds nothing. An `$each` holds each
/// value once, in order.
fn params_of(j: &QueryJoin, scope: &Value) -> Option<Map<String, Value>> {
j.params
.iter()
@@ -359,17 +360,22 @@ fn params_of(j: &QueryJoin, scope: &Value) -> Option<Map<String, Value>> {
Param::Literal(v) => v.clone(),
Param::Bound(b) => b.get(scope)?.clone(),
Param::Each { each, at } => {
let found: Vec<Value> = each
let mut found: Vec<Value> = Vec::new();
let values = each
.get(scope)?
.as_array()?
.iter()
.filter_map(|e| at.get(e))
.filter(|v| {
matches!(v, Value::String(_) | Value::Number(_) | Value::Bool(_))
})
.take(crate::view::MAX_PARAM_ARRAY)
.cloned()
.collect();
.filter_map(|e| at.get(e));
for v in values {
let scalar =
matches!(v, Value::String(_) | Value::Number(_) | Value::Bool(_));
if scalar && !found.contains(v) {
found.push(v.clone());
if found.len() == crate::view::MAX_PARAM_ARRAY {
break;
}
}
}
if found.is_empty() {
return None;
}
@@ -381,6 +387,24 @@ fn params_of(j: &QueryJoin, scope: &Value) -> Option<Map<String, Value>> {
.collect()
}
/// Each `$each` param cut to the most its method takes, its lexicon's
/// `maxLength` (`app.bsky.feed.getPosts` takes 25 uris): the first of its
/// values asked, not the call refused.
fn cut_to_lexicon(j: &QueryJoin, def: &Value, params: &mut Map<String, Value>) {
for (name, _) in j
.params
.iter()
.filter(|(_, p)| matches!(p, Param::Each { .. }))
{
let max = def["parameters"]["properties"][name]["maxLength"]
.as_u64()
.and_then(|m| usize::try_from(m).ok());
if let (Some(max), Some(Value::Array(values))) = (max, params.get_mut(name)) {
values.truncate(max);
}
}
}
/// Run a mode's query joins on its main `scope`, all at once, each within
/// `wait`, each through `asker` (the person asking): each one's answer by
/// its name, or null. A join with no service of its own calls `own` (a
@@ -423,7 +447,15 @@ async fn query<A: Asker>(
tracing::warn!(join = j.name, method, "a query join has no service");
return Value::Null;
};
match tokio::time::timeout(wait, xrpc::ask(asker, &service, method, &mut params)).await {
let asked = async {
let docs = asker.docs(method).await;
let def = docs.iter().find(|d| d["id"] == method);
if let Some(def) = def.and_then(|d| xrpc::query_def(method, d).ok()) {
cut_to_lexicon(j, def, &mut params);
}
xrpc::ask_with(asker, &docs, &service, method, &mut params).await
};
match tokio::time::timeout(wait, asked).await {
Ok(Ok(asked)) => asked.response,
Ok(Err(Refusal::Error(why))) => {
tracing::warn!(join = j.name, method, why, "a query join failed");
@@ -995,4 +1027,41 @@ mod tests {
]
);
}
/// `$each` asks each value once, and no more of them than its param's
/// `maxLength` (3 here), the first; a query view's join reading the
/// answer runs on every page, one reading its params on the first.
#[tokio::test]
async fn each_asks_each_value_once_and_no_more_than_its_method_takes() {
let svc = Svc::new(&[("posts", 0, json!({ "items": ["p"] }))]);
let joins = query_joins(&[
(
"posts",
json!({ "actor": { "$": "response.did" }, "uris": { "$each": ["response.items", "subject"] } }),
),
("first", json!({ "actor": { "$root": "params.actor" } })),
]);
let per_page: Vec<bool> = joins.iter().map(QueryJoin::per_page).collect();
assert_eq!(per_page, [true, false]);
let post = |n: u8| json!({ "subject": format!("at://did:plc:a/app.bsky.feed.post/{n}") });
let scope = json!({ "response": { "did": "did:plc:alice", "items": [
post(1), post(1), post(2), {}, post(1), post(3), post(4),
] } });
queries(&svc, joins[..1].iter(), OWN, &scope, WAIT).await;
let asked = svc.asked.lock().unwrap();
let uris: Vec<&str> = asked[0]
.1
.iter()
.filter(|(k, _)| k == "uris")
.map(|(_, v)| v.as_str())
.collect();
assert_eq!(
uris,
[
"at://did:plc:a/app.bsky.feed.post/1",
"at://did:plc:a/app.bsky.feed.post/2",
"at://did:plc:a/app.bsky.feed.post/3",
]
);
}
}
crates/hud-core/src/tools.rs+149−13
@@ -1845,19 +1845,16 @@ impl Hud {
// The answer, as the scope a view without items summarizes in.
let mut structured = json!({ "method": method, "service": service.name(), "params": params,
"response": response });
// Its query joins, on its first page alone (a page more keeps the
// first's).
// Its query joins: all of them on its first page, on a page more
// those that read the answer (a page more keeps the first's others).
let first = paging.is_none();
let runs = move |j: &&view::QueryJoin| first || j.per_page();
let queries = mode
.map(|(_, q)| &q.queries[..])
.filter(|q| paging.is_none() && !q.is_empty());
.map(|(_, q)| q.queries.iter().filter(runs))
.filter(|q| q.clone().next().is_some());
let own = service.name();
let joined = self
.query_joins(
queries.map(<[_]>::iter),
Some(&own),
Some(&structured),
account,
)
.query_joins(queries, Some(&own), Some(&structured), account)
.await;
let mut text = match mode {
Some((_, q)) => match (&q.summary, &q.items) {
@@ -1883,8 +1880,8 @@ impl Hud {
},
None => summary::generic_query(method, &host, &response),
};
if let (Some(q), Some(joined)) = (queries, joined) {
text = summary::with_said(text, q, &joined);
if let (Some((_, q)), Some(joined)) = (mode, joined) {
text = summary::with_said(text, &q.queries, &joined);
structured["joins"] = Value::Object(joined);
}
let none = (&Value::Null, &Value::Null);
@@ -2916,7 +2913,13 @@ mod tests {
assert_eq!(ui::check(&page), Ok(()));
assert_eq!(
words(&page)[4..],
["Posts", "Discover", "Saved feeds", "Following"]
[
"Posts",
"Discover",
"Saved feeds",
"Notifications",
"Following"
]
);
// An account's part: its sections of this app alone, never its
// collections.
@@ -3379,6 +3382,139 @@ mod tests {
);
}
/// An answer of `method`, as its lexicon allows one, drawn by its
/// bundled view as the signed-in `did:plc:me`: the list's items.
fn notifications_drawn(method: &str, response: Value, joins: Value) -> Vec<Value> {
let docs: Vec<Arc<Value>> = crate::lexicon::all_bundled().cloned().collect();
let doc = docs.iter().find(|d| d["id"] == method).unwrap();
let def = crate::xrpc::query_def(method, doc).unwrap();
let lexicons = crate::xrpc::lexicons_for(method, &docs);
assert_eq!(
crate::xrpc::output_problem(&lexicons, method, def, &response),
None
);
let v = view::for_method(method).unwrap();
let structured = json!({ "method": method, "service": v.service, "params": {},
"response": response, "joins": joins });
let args = json!({ "method": method });
let none = (None, None);
let drawn = view_ui(
v,
true,
"query",
&structured,
Some(&args),
Some("did:plc:me"),
none,
);
let drawn = drawn.unwrap();
assert_eq!(ui::check(&drawn), Ok(()));
drawn["root"]["items"].as_array().unwrap().clone()
}
/// The query each item opens (its `{ method, params }`), the item's own
/// first, then those of the lists within it, but no account's.
fn queries_opened(item: &Value) -> Vec<Value> {
fn walk(v: &Value, out: &mut Vec<Value>) {
match v {
Value::Object(o) => {
if let Some(args) = o.get("open").map(|open| &open["call"]["args"])
&& args.get("method").is_some()
{
out.push(json!({ "method": args["method"], "params": args["params"] }));
}
o.values().for_each(|v| walk(v, out));
}
Value::Array(a) => a.iter().for_each(|v| walk(v, out)),
_ => {}
}
}
let mut out = Vec::new();
walk(item, &mut out);
out
}
/// Bluesky's notifications: a like shows the post it likes, from the
/// join, and opens it; a reply its own words, opening its thread; a
/// follow opens nothing but its follower.
#[test]
fn bluesky_notifications_show_and_open_what_they_are_about() {
let cid = "bafyreie5737gdxlw5i64vzichcalba3z2v5n6icifvx5xytvske7mr3hpm";
let mine = "at://did:plc:me/app.bsky.feed.post/3mine";
let reply = "at://did:plc:bob/app.bsky.feed.post/3reply";
let at = "2026-11-16T12:00:00.000Z";
let author = |did: &str, handle: &str| json!({ "did": did, "handle": handle });
let notification = |uri: &str, who: Value, reason: &str, record: Value| {
json!({ "uri": uri, "cid": cid, "author": who, "reason": reason, "record": record,
"isRead": false, "indexedAt": at })
};
let response = json!({ "notifications": [
notification("at://did:plc:alice/app.bsky.feed.like/3like", author("did:plc:alice", "alice.test"), "like",
json!({ "$type": "app.bsky.feed.like", "subject": { "uri": mine, "cid": cid }, "createdAt": at })),
notification(reply, author("did:plc:bob", "bob.test"), "reply",
json!({ "$type": "app.bsky.feed.post", "text": "Nice one", "createdAt": at,
"reply": { "root": { "uri": mine, "cid": cid }, "parent": { "uri": mine, "cid": cid } } })),
notification("at://did:plc:carol/app.bsky.graph.follow/3follow", author("did:plc:carol", "carol.test"), "follow",
json!({ "$type": "app.bsky.graph.follow", "subject": "did:plc:me", "createdAt": at })),
] });
let joins = json!({ "subjects": { "posts": [{ "uri": mine, "cid": cid, "author": author("did:plc:me", "me.test"),
"record": { "$type": "app.bsky.feed.post", "text": "My post", "createdAt": at }, "indexedAt": at }] } });
let items = notifications_drawn("app.bsky.notification.listNotifications", response, joins);
let thread = |uri: &str| json!({ "method": "app.bsky.feed.getPostThread", "params": { "uri": uri } });
assert_eq!(queries_opened(&items[0])[0], thread(mine));
let liked = words(&items[0]);
assert!(liked.contains(&"liked your post".into()) && liked.contains(&"My post".into()));
assert!(items[1].get("open").is_none());
assert_eq!(queries_opened(&items[1]), [thread(reply)]);
assert!(words(&items[1]).contains(&"replied to you".into()));
assert!(!words(&items[1]).contains(&"My post".into()));
assert!(queries_opened(&items[2]).is_empty());
assert!(words(&items[2]).contains(&"followed you".into()));
}
/// Grain's notifications open their gallery; a follow opens nothing
/// but its follower.
#[test]
fn grain_notifications_open_their_gallery() {
let gallery = "at://did:plc:me/social.grain.gallery/3coast";
let at = "2026-11-16T12:00:00.000Z";
let notification = |uri: &str, did: &str, reason: &str, extra: Value| {
let mut n = json!({ "uri": uri, "reason": reason, "createdAt": at, "indexedAt": at, "isRead": true,
"author": { "did": did, "handle": "someone.test" } });
n.as_object_mut()
.unwrap()
.extend(extra.as_object().unwrap().clone());
n
};
let on = json!({ "galleryUri": gallery, "galleryTitle": "Coast" });
let mut reply = on.clone();
reply["commentText"] = json!("Lovely light");
reply["replyToText"] = json!("Shot at dawn");
let response = json!({ "notifications": [
notification("at://did:plc:alice/social.grain.favorite/3fav", "did:plc:alice", "gallery-favorite", on),
notification("at://did:plc:bob/social.grain.comment/3c", "did:plc:bob", "reply", reply),
notification("at://did:plc:carol/social.grain.graph.follow/3f", "did:plc:carol", "follow", json!({})),
] });
let items = notifications_drawn(
"social.grain.notification.listNotifications",
response,
Value::Null,
);
let opens = json!({ "method": "social.grain.gallery.getGallery", "params": { "gallery": gallery } });
assert_eq!(queries_opened(&items[0]), std::slice::from_ref(&opens));
assert_eq!(queries_opened(&items[1]), [opens]);
let replied = words(&items[1]);
for w in [
"replied to your comment",
"Shot at dawn",
"Lovely light",
"Coast",
] {
assert!(replied.contains(&w.into()), "{w}");
}
assert!(queries_opened(&items[2]).is_empty());
}
#[test]
fn descriptions_stripped() {
let mut defs = json!({ "main": { "type": "record", "description": "a record",
crates/hud-core/src/view.rs+13−7
@@ -213,21 +213,26 @@ impl QueryJoin {
.or_else(|| bundled_service(&self.method).map(str::to_string))
}
/// Whether it reads a page's records, so runs on every page of them,
/// not on the first alone.
/// Whether it reads the page: a page of records' `records`, or a
/// query's answer (`response`), so runs on every page of them, not on
/// the first alone.
pub fn per_page(&self) -> bool {
let records = |p: &Path| p.0.first().is_some_and(|k| k == "records");
let page = |p: &Path| {
p.0.first()
.is_some_and(|k| k == "records" || k == "response")
};
self.params.iter().any(|(_, p)| match p {
Param::Literal(_) => false,
Param::Bound(b) => b.0.iter().any(records),
Param::Each { each, .. } => records(each),
Param::Bound(b) => b.0.iter().any(page),
Param::Each { each, .. } => page(each),
})
}
}
/// A query join's param: a literal, a value from the main scope, or the
/// values at `at` in each element of the array at `each` there (each
/// record's uri), at most `MAX_PARAM_ARRAY`.
/// record's uri), each once, at most `MAX_PARAM_ARRAY` and the method's
/// `maxLength` for it.
#[derive(Clone, Debug, PartialEq)]
pub enum Param {
Literal(Value),
@@ -4275,7 +4280,7 @@ mod tests {
seen += 1;
}
}
assert_eq!(seen, 13);
assert_eq!(seen, 15);
// Those naming the person need one signed in.
let names_me: Vec<bool> = for_method("dev.knotless.getFeed")
.unwrap()
@@ -5171,6 +5176,7 @@ mod tests {
"bsky-app posts",
"bsky-app feeds",
"bsky-chat-with messages",
"bsky-notifications subjects",
"bsky-profile posts",
"bsky-profile feeds",
"grain-app profile",
crates/hud-core/src/xrpc.rs+12−1
@@ -541,13 +541,24 @@ pub async fn ask<A: Asker + ?Sized>(
params: &mut Map<String, Value>,
) -> Result<Asked, Refusal> {
let docs = asker.docs(method).await;
ask_with(asker, &docs, service, method, params).await
}
/// `ask`, with the lexicon documents `asker.docs` gave for `method`.
pub async fn ask_with<A: Asker + ?Sized>(
asker: &A,
docs: &[Arc<Value>],
service: &Service,
method: &str,
params: &mut Map<String, Value>,
) -> Result<Asked, Refusal> {
let doc = docs
.iter()
.find(|d| d["id"] == method)
.ok_or_else(|| format!("No lexicon for {method}"))?;
let def = query_def(method, doc)?;
handles_to_dids(def, params, |h| asker.handle_did(h)).await?;
let lexicons = lexicons_for(method, &docs);
let lexicons = lexicons_for(method, docs);
let problems = params_problems(&lexicons, method, def, params);
if !problems.is_empty() {
return Err(format!("Invalid params for {method}: {}", problems.join("; ")).into());
docs/app-pages.md+2−2
@@ -48,7 +48,7 @@ More on knotless's views is in [knotless](knotless.md).
### Grain
Grain's page (`grain-app`) is its profile. It shows the account's avatar large beside its galleries, followers and following, its name, handle and bio, and on one's own page its feeds (For you, Following, Recent, Galleries). It shows its 18 latest galleries as 3:4 tiles, each opening the gallery. The data comes from Grain's AppView (`getProfile` and the `actor` feed of `getFeed`).
Grain's page (`grain-app`) is its profile. It shows the account's avatar large beside its galleries, followers and following, its name, handle and bio, and on one's own page where to go (For you, Following, Recent, Galleries, Notifications). It shows its 18 latest galleries as 3:4 tiles, each opening the gallery. The data comes from Grain's AppView (`getProfile` and the `actor` feed of `getFeed`).
### Bluesky
@@ -56,7 +56,7 @@ Bluesky's page (`bsky-app`) is a profile as Bluesky's app draws one:
- banner, avatar, name, handle and bio
- followers, following and posts
- where to go, on one's own page (Following, Discover, Saved feeds)
- where to go, on one's own page (Following, Discover, Saved feeds, Notifications)
- their posts and their threads (`posts_and_author_threads`), with links to all of them, their replies, media and videos (the filters of `getAuthorFeed`)
- the feeds they made
docs/views.md+12−8
@@ -155,8 +155,10 @@ never read a join's result. The main scope is a query view's `params` and `respo
`did`, `handle` and `records`, and also a record's `value`.
A param can also be `{"$each": [array, path]}`. That's an array of the value at `path` in each
element of `array` there, in order, at most 50 (`{"$each": ["records", "uri"]}` is every record's
uri). A binding that doesn't resolve, or an `$each` that finds nothing, skips the call.
element of `array` there, in order, each once, at most 50 (`{"$each": ["records", "uri"]}` is every
record's uri). HUD asks with no more of them than the method's lexicon takes for that param (its
`maxLength`), the first. A binding that doesn't resolve, or an `$each` that finds nothing, skips the
call.
HUD checks the literal params against the method's lexicon as the view loads (a problem is the
view's error), and checks all of them before each call.
@@ -172,10 +174,10 @@ first line of `label` (`… README: knotless keeps a git…; latest release: 0.1
### Pages
A page more (a cursor) keeps the first page's joins. The exception is a records page's joins that
read its `records`, which run on every page. A List of their answer (`{"$root": "joins.<as>…"}`)
is the page's. Such a view's pages are no longer than its `pageSize`, so one call takes a page
whole.
A page more (a cursor) keeps the first page's joins. The exception is a join that reads the page,
which runs on every page: a records page's that reads its `records`, or a query view's that reads
its `response`. A List of a records page's such join (`{"$root": "joins.<as>…"}`) is the page's.
Such a view's pages are no longer than its `pageSize`, so one call takes a page whole.
### Bundled query joins
@@ -184,6 +186,7 @@ The bundled views use query joins for these:
- a knotless repository's README (collapsed past about 20 lines) and latest release
- a Bluesky profile's latest 5 posts, and its feeds
- a standard.site post's replies on Bluesky, where it links a post (`bskyPostRef`)
- the posts Bluesky notifications of likes and reposts are about
- a Grain gallery's comments
- the [app pages](app-pages.md)
@@ -200,6 +203,7 @@ one for the collection or method, and otherwise they draw generically.
| `views/bsky-profile.json` | An account's profile, with its latest posts and feeds |
| `views/grain-feed.json` | The feeds of galleries from Grain's AppView |
| `views/grain-gallery-view.json` | One gallery's photos with its comments |
| `views/bsky-notifications.json`, `views/grain-notifications.json` | Your Bluesky and Grain notifications: who did what, the post, comment or gallery it's about |
| `views/plyr-list.json` | plyr.fm albums and playlists |
| `views/plyr-likes.json` | plyr.fm likes, as a playlist |
| `views/standard-document.json` | Blog posts (standard.site documents) |
@@ -314,6 +318,6 @@ needs an account (its `signIn`). Each title says what it shows, and the tile's h
| App | Entries |
| --- | --- |
| Bluesky | Posts and Saved feeds (`bsky-author-feed`, `bsky-feed-generators`) · Discover (`bsky-feed`, Bluesky's whats-hot feed) · Following (`bsky-timeline`) |
| Grain | For you, Following, Recent and Galleries (`grain-feed`) |
| Bluesky | Posts and Saved feeds (`bsky-author-feed`, `bsky-feed-generators`) · Discover (`bsky-feed`, Bluesky's whats-hot feed) · Notifications (`bsky-notifications`) · Following (`bsky-timeline`) |
| Grain | For you, Following, Recent and Galleries (`grain-feed`) · Notifications (`grain-notifications`) |
| knotless | Repositories, Activity, Everyone's activity and Notifications |
harness/gallery/answers.json+676−0
676 lines changed: not loaded until asked for.
harness/gallery/entries.mjs+2−0
@@ -42,6 +42,7 @@ export const entries = [
{ id: 'bsky-thread', group: 'Bluesky', view: 'bsky-thread', title: 'Thread', call: q('app.bsky.feed.getPostThread', { uri: '$picked.bsky-thread', depth: 2 }), note: 'query app.bsky.feed.getPostThread (views/bsky-thread.json)', pick: { from: 'bsky-author-feed', post: 'replies' } },
{ id: 'bsky-post', group: 'Bluesky', view: 'bsky-thread', title: 'Post', call: record('bsky-post'), note: 'get_record app.bsky.feed.post: a post opens as its thread (views/bsky-thread.json, records)', pick: { from: 'bsky-author-feed', post: 'replies' } },
{ id: 'bsky-profile', group: 'Bluesky', view: 'bsky-profile', title: 'Profile', call: q('app.bsky.actor.getProfile', { actor: 'danabra.mov' }), note: 'query app.bsky.actor.getProfile (views/bsky-profile.json)' },
{ id: 'bsky-notifications', group: 'Bluesky', view: 'bsky-notifications', made: true, title: 'Notifications', call: q('app.bsky.notification.listNotifications', { limit: 25 }), note: 'query app.bsky.notification.listNotifications (views/bsky-notifications.json): each with the post it is about; made up, signed in only' },
{ id: 'bsky-app', group: 'Bluesky', view: 'bsky-app', title: 'Bluesky', call: { name: 'describe_app', args: { domain: 'bsky.app', actor: 'danabra.mov' } }, note: 'describe_app bsky.app for an account (views/bsky-app.json, its page)' },
{
id: 'bsky-feed-generators',
@@ -68,6 +69,7 @@ export const entries = [
{ id: 'grain-feed', group: 'Grain', view: 'grain-feed', title: 'Recent galleries', call: q('social.grain.feed.getFeed', { feed: 'at://did:web:grain.social/social.grain.feed.generator/recent', limit: 4 }), note: 'query social.grain.feed.getFeed (views/grain-feed.json)' },
{ id: 'grain-gallery-view', group: 'Grain', view: 'grain-gallery-view', title: 'nyc', call: q('social.grain.gallery.getGallery', { gallery }), note: 'query social.grain.gallery.getGallery (views/grain-gallery-view.json)' },
{ id: 'grain-app', group: 'Grain', view: 'grain-app', title: 'Grain', call: { name: 'describe_app', args: { domain: 'grain.social', actor: 'tx3.grapevyne.social' } }, note: 'describe_app grain.social for an account (views/grain-app.json, its page)' },
{ id: 'grain-notifications', group: 'Grain', view: 'grain-notifications', made: true, title: 'Notifications', call: q('social.grain.notification.listNotifications', {}), note: 'query social.grain.notification.listNotifications (views/grain-notifications.json); made up, signed in only' },
// knotless
{ id: 'knotless-app', group: 'knotless', view: 'knotless-app', title: 'knotless', call: { name: 'describe_app', args: { domain: 'knotless.dev', actor: 'chadtmiller.com' } }, note: 'describe_app knotless.dev for an account (views/knotless-app.json, its page)' },
harness/gallery/made.mjs+40−3
@@ -1,5 +1,5 @@
// The gallery's made-up answers: what the views only a signed-in account
// sees (its timeline, its chats, its knotless notifications) would answer
// sees (its timeline, its chats, its notifications) would answer
// `me`, as the query tool answers one, `_meta.viewer` naming `me` so that
// `hud resolve` draws them as theirs (their own messages theirs, a chat's
// box to send). Made of the real people and posts record.mjs recorded, so
@@ -17,6 +17,7 @@ const answer = (me, method, service, params, response, summary, joins) => ({
const BSKY = 'did:web:api.bsky.app#bsky_appview';
const CHAT = 'did:web:api.bsky.chat#bsky_chat';
const KNOTLESS = 'did:web:knotless.dev#knotless_appview';
const GRAIN = 'did:web:grain.social#grain_appview';
/** Minutes before the gallery's moment, as a datetime. */
const ago = (minutes) => new Date(Date.parse('2026-11-16T23:30:00.000Z') - minutes * 60_000).toISOString();
@@ -129,6 +130,37 @@ export function made({ me, people, recorded, args }) {
notification(actor(jay), 'follow', 60 * 30, { uri: `at://${jay.did}/dev.knotless.follow/3n2follow0001` })
];
// Bluesky notifications about a post of `me`'s, the post as the join fetches it.
const post = recorded['bsky-author-feed'].structuredContent.response.feed[0].post;
const mine = { uri: `at://${me.did}/app.bsky.feed.post/3n2mypost0001`, cid: post.cid };
const myPost = { $type: 'app.bsky.feed.post', text: 'HUD draws any atproto app as tiles on a canvas. Next up: notifications, Bluesky’s and Grain’s, each in its own tile.', createdAt: ago(60 * 2) };
const bsky = (author, reason, minutes, record, extra = {}) => ({ uri: `at://${author.did}/${record.$type}/3n2bsky${String(minutes).padStart(6, '0')}`, cid: post.cid, author, reason, record, isRead: minutes > 60, indexedAt: ago(minutes), ...extra });
const reply = { root: mine, parent: mine };
const zz = basic('zzstoatzz.io');
const bskyNotifications = [
bsky(dan, 'like', 3, { $type: 'app.bsky.feed.like', subject: mine, createdAt: ago(3) }, { reasonSubject: mine.uri }),
bsky(paul, 'reply', 12, { $type: 'app.bsky.feed.post', text: 'Nice. Does a page more fetch the older posts too?', reply, createdAt: ago(12) }, { reasonSubject: mine.uri }),
bsky(bryan, 'repost', 40, { $type: 'app.bsky.feed.repost', subject: mine, createdAt: ago(40) }, { reasonSubject: mine.uri }),
bsky(jay, 'quote', 60 * 3, { $type: 'app.bsky.feed.post', text: 'This one is worth watching.', embed: { $type: 'app.bsky.embed.record', record: mine }, createdAt: ago(60 * 3) }, { reasonSubject: mine.uri }),
bsky(zz, 'follow', 60 * 20, { $type: 'app.bsky.graph.follow', subject: me.did, createdAt: ago(60 * 20) })
];
const subjects = { posts: [{ uri: mine.uri, cid: mine.cid, author: self, record: myPost, likeCount: 1, repostCount: 1, replyCount: 1, quoteCount: 1, indexedAt: myPost.createdAt }] };
// Grain notifications, on the recorded galleries, by their photographers.
const galleries = recorded['grain-feed'].structuredContent.response.items;
const creator = (i) => {
const c = galleries[i].creator;
return { did: c.did, handle: c.handle, ...(c.displayName ? { displayName: c.displayName } : {}), ...(c.avatar ? { avatar: c.avatar } : {}) };
};
const on = (i) => ({ galleryUri: galleries[i].uri, galleryTitle: galleries[i].title, galleryThumb: galleries[i].items[0].thumb });
const grain = (author, reason, minutes, collection, extra = {}) => ({ uri: `at://${author.did}/${collection}/3n2grain${String(minutes).padStart(5, '0')}`, reason, createdAt: ago(minutes), indexedAt: ago(minutes), isRead: minutes > 60, author, ...extra });
const grainNotifications = [
grain(creator(2), 'gallery-favorite', 4, 'social.grain.favorite', on(0)),
grain(creator(1), 'gallery-comment', 18, 'social.grain.comment', { ...on(3), commentText: 'That light through the fog is unreal.' }),
grain(creator(0), 'reply', 60 * 2, 'social.grain.comment', { ...on(0), replyToText: 'Which lens was this?', commentText: 'The 35mm, wide open.' }),
grain(creator(2), 'follow', 60 * 9, 'social.grain.graph.follow')
];
const a = (id, method, service, response, summary, joins) => [id, answer(me, method, service, args[id].params, response, summary, joins)];
return Object.fromEntries([
a('bsky-timeline', 'app.bsky.feed.getTimeline', BSKY, { feed, cursor: feed.at(-1).post.indexedAt }, `${feed.length} posts from app.bsky.feed.getTimeline on api.bsky.app`),
@@ -136,12 +168,17 @@ export function made({ me, people, recorded, args }) {
a('bsky-chat', 'chat.bsky.convo.getMessages', CHAT, { messages: group, relatedProfiles: [self, dan, paul, bryan] }, `${group.length} messages from chat.bsky.convo.getMessages on api.bsky.chat`),
a('bsky-chat-with', 'chat.bsky.convo.getConvoForMembers', CHAT, { convo: danConvo }, `Chat with ${dan.handle}: ${withDan.length} messages.`, { messages: { messages: withDan } }),
a('bsky-chat-availability', 'chat.bsky.convo.getConvoAvailability', CHAT, { canChat: true, convo: danConvo }, `You can message ${dan.handle}.`),
a('knotless-notifications', 'dev.knotless.listNotifications', KNOTLESS, { notifications, seenAt: ago(60) }, `${notifications.length} notifications from dev.knotless.listNotifications on knotless.dev`)
a('knotless-notifications', 'dev.knotless.listNotifications', KNOTLESS, { notifications, seenAt: ago(60) }, `${notifications.length} notifications from dev.knotless.listNotifications on knotless.dev`),
a('bsky-notifications', 'app.bsky.notification.listNotifications', BSKY, { notifications: bskyNotifications, seenAt: ago(60) }, `${bskyNotifications.length} notifications from app.bsky.notification.listNotifications on api.bsky.app`, { subjects }),
a('grain-notifications', 'social.grain.notification.listNotifications', GRAIN, { notifications: grainNotifications, seenAt: ago(60) }, `${grainNotifications.length} notifications from social.grain.notification.listNotifications on grain.social`)
]);
}
/** The joins a made-up answer holds, by its method: the method each join's answer is of. */
const JOINS = { 'chat.bsky.convo.getConvoForMembers': { messages: 'chat.bsky.convo.getMessages' } };
const JOINS = {
'chat.bsky.convo.getConvoForMembers': { messages: 'chat.bsky.convo.getMessages' },
'app.bsky.notification.listNotifications': { subjects: 'app.bsky.feed.getPosts' }
};
/** Every made-up answer held to its method's lexicon, and each join to its own: the problems, none when all are valid. */
export function check(lexicons, answers) {
views/bsky-app.json+9−0
@@ -219,6 +219,15 @@
"feeds": "saved"
}
}
},
{
"label": "Notifications",
"open": {
"query": "app.bsky.notification.listNotifications",
"params": {
"limit": 25
}
}
}
]
},
views/bsky-notifications.jsonnew+108−0
views/grain-app.json+4−0
views/grain-notifications.jsonnew+72−0