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

Apps and sites make a person's invite inbox when they sign in

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:sdk/invite-inbox
crates/group-host/src/sites.rs+17−4
@@ -159,13 +159,19 @@ fn skey(key: Option<&str>) -> String {
key.map(|key| format!("&skey={key}")).unwrap_or_default()
}
/// Whether a site makes each visitor's invite inbox when they sign in.
fn inbox_of(site: &Value) -> bool {
site["inbox"] == true
}
/// Whether a site asks for its visitor's session: to read, act, read
/// spaces or write.
/// spaces, write, or make their inbox.
fn is_live(site: &Value) -> bool {
!reads_of(site).is_empty()
|| !acts_of(site).is_empty()
|| !spaces_of(site).is_empty()
|| !writes_of(site).is_empty()
|| inbox_of(site)
}
/// Refuses a site whose `spaces` name no type, or one space twice.
@@ -617,9 +623,10 @@ fn script(bytes: Vec<u8>) -> Response {
/// The site's OAuth client document, at its address `origin`: `atproto`;
/// leave to ask each of its `reads` and `acts`, and `getViewer`, of the
/// host; to read each of its `spaces` whole, in the group `did`'s spaces
/// of that type; and to make each of its `writes` in the visitor's own repo, in the group
/// of that type; to make each of its `writes` in the visitor's own repo, in the group
/// `did`'s spaces of that type alone, with pictures they upload for those
/// records to point to.
/// records to point to; and with `inbox`, to make the visitor's own invite
/// inbox and see its policy.
fn client_metadata(host: &Host, did: &str, handle: &str, origin: &str, site: &Value) -> Response {
let aud = format!("{}#opensocial", host.config.service_did);
let aud = reqwest::Url::parse_with_params("https://x/", &[("aud", aud)])
@@ -648,6 +655,9 @@ fn client_metadata(host: &Host, did: &str, handle: &str, origin: &str, site: &Va
if !written.is_empty() {
scope.push("blob:image/*".to_string());
}
if inbox_of(site) {
scope.push("space:fyi.opensocial.invites?action=read_self&manage=create".to_string());
}
let doc = json!({
"client_id": format!("{origin}/client-metadata.json"),
"client_name": handle,
@@ -702,6 +712,7 @@ fn shell(host: &Host, did: &str, handle: &str, site: &Value, path: &str) -> Resp
"acts": acts,
"spaces": spaces,
"writes": writes,
"inbox": inbox_of(site),
"aud": format!("{}#opensocial", host.config.service_did),
"handleResolver": host.config.site_handle_resolver,
"plc": host.config.site_plc_url,
@@ -792,7 +803,9 @@ pub async fn put_site(
let group = configuring(&host, &headers, &body, "putSite").await?;
host.active(&group)?;
let mut site = json!({"$type": SITE, "files": [], "createdAt": iso(now_millis())});
for key in ["fallback", "notFound", "reads", "acts", "spaces", "writes"] {
for key in [
"fallback", "notFound", "reads", "acts", "spaces", "writes", "inbox",
] {
if let Some(given) = body.get(key) {
site[key] = given.clone();
}
crates/group-host/tests/sites.rs+39−0
@@ -806,6 +806,45 @@ async fn a_site_reads_the_groups_spaces_whole_as_its_visitor() {
assert_eq!(site["spaces"], spaces);
}
#[tokio::test]
async fn a_site_with_an_inbox_asks_to_make_its_visitors_invite_inbox() {
let h = start(&[], false).await;
let (did, [alice, ..]) = group(&h).await;
let files = json!([{"path": "index.html", "text": "<p>the club</p>"}]);
let said = call(
&h,
&alice,
"putSite",
json!({"group": did, "files": files, "inbox": true}),
)
.await;
assert_eq!(said.0, 200, "{}", said.1);
// Though it reads and writes nothing of the group's, its pages are
// served in the page that holds a session, which is told to make the
// visitor's inbox when they sign in.
let shell = page(&h, "/").await;
let (_, config) = shell_of(&shell);
assert_eq!(config["inbox"], json!(true));
// Its OAuth client asks the visitor's PDS to make their own inbox, and
// to see its policy, and nothing in it.
let client = page(&h, "/client-metadata.json").await;
let doc: Json = serde_json::from_str(&client.body).unwrap();
let scope: Vec<&str> = doc["scope"].as_str().unwrap().split(' ').collect();
let wanted = [
"atproto".to_string(),
format!("rpc:{NS}.getViewer?aud=did%3Aweb%3Ahost.test%23opensocial"),
format!("space:{NS}.invites?action=read_self&manage=create"),
];
assert_eq!(scope, wanted);
// The record says so, for any app that reads it.
let kept = h.host.store.record(&did, SITE, "self").unwrap().unwrap();
let site = atproto::drisl::decode(&kept.value).unwrap().to_json();
assert_eq!(site["inbox"], json!(true));
}
#[tokio::test]
async fn a_site_that_writes_asks_its_visitor_for_those_writes_alone() {
let h = start(&[], false).await;
crates/group-host-mcp/src/lib.rs+2−1
@@ -400,7 +400,8 @@ const TOOLS: &[(&str, &[&str], &str, Made)] = &[
host's that signs its visitor in: its pages ask those reads as whoever is looking, \
with `os.call` from `/_os/kit.js`, those acts with `os.act`, and open those spaces \
with `os.space`, to sync and read them whole and make those writes in that person's \
own repo.",
own repo. With `inbox`, it is served so too, and makes each visitor's invite inbox \
(fyi.opensocial.invites) at their own PDS as they sign in, if they have none.",
Made::Method("putSite", None),
),
(
crates/opensocial/src/lib.rs+10−3
@@ -62,7 +62,7 @@ role
site
site publish <group> <dir> [--fallback <path>] [--not-found <path>] [--reads <methods>]
[--acts <methods>] [--spaces <type[/key],…>]
[--writes <type[/key]:collection,…>]
[--writes <type[/key]:collection,…>] [--inbox]
publish the files under <dir> as the group's website, at its
address, in place of the one there; with --reads, the host's
methods its pages may ask as whoever signs in on it; with
@@ -71,7 +71,8 @@ site
they may read whole as that person, each by its NSID; with
--writes, the records they may write in that person's own repo,
each a type of the group's spaces and a collection there; a type
with /<key> after it names just the one space of it by that key
with /<key> after it names just the one space of it by that key;
with --inbox, making that person's invite inbox as they sign in
site delete <group> take the group's website down
site domain <group> [--undo]
serve the website at the group's own domain, its handle, once
@@ -687,7 +688,10 @@ pub async fn run(args: &[String], env: &Env) -> Result<String> {
}
["site", "publish", rest @ ..] => {
let flags = ["fallback", "not-found", "reads", "acts", "spaces", "writes"];
let a = parse(rest, &flags)?;
// `--inbox` alone, with no value after it.
let inbox = rest.contains(&"--inbox");
let rest: Vec<&str> = rest.iter().copied().filter(|w| *w != "--inbox").collect();
let a = parse(&rest, &flags)?;
let [group, dir] = a.take()?;
let mut given = json!({"files": site_files(std::path::Path::new(dir))?});
for (flag, name) in [("fallback", "fallback"), ("not-found", "not_found")] {
@@ -744,6 +748,9 @@ pub async fn run(args: &[String], env: &Env) -> Result<String> {
let writes: Vec<Value> = each.map(write).collect::<Result<_>>()?;
given["writes"] = writes.into();
}
if inbox {
given["inbox"] = true.into();
}
let tools = group_host_mcp::tools();
let tool = tools.iter().find(|t| t.name == "site_publish");
let tool = tool.expect("site_publish is a tool");
crates/opensocial/tests/commands.rs+6−0
@@ -1068,6 +1068,12 @@ async fn publishes_a_folder_as_the_groups_site_and_takes_it_down() {
"{keyless}"
);
// Each visitor's invite inbox, made when they sign in.
ok(&alice, &["site", "publish", group, folder, "--inbox"]).await;
let record = h.host.store.record(&did, "fyi.opensocial.site", "self");
let site = atproto::drisl::decode(&record.unwrap().unwrap().value).unwrap();
assert_eq!(&site.to_json()["inbox"], &json!(true));
let missing = fails(&alice, &["site", "publish", group, "/no/such/folder"]).await;
assert!(missing.contains("reading /no/such/folder"), "{missing}");
docs/design/membership.md+9−0
@@ -208,6 +208,15 @@ members. So any group may write an invite there and only the invitee
reads the space. The invitee's PDS keeps each group that writes there
among the inbox's writers.
An app makes it with the SDK's `InviteInbox.open`, asking the person for
`space:fyi.opensocial.invites?action=read_self&manage=create`: to make
their own inbox, and to see the policy of one already there, which it
leaves as it is ([the SDK](../reference/sdk.md#the-invite-inbox)). A
group's site that sets `inbox` makes it for each visitor who signs in
there ([sites](sites.md#the-page-around-a-site)). The console doesn't
make one: someone whose app never made their inbox still sees their
invites in the console, from the host's own list (below).
An app invites someone by writing that record as the group, through
`com.atproto.space.createRecord` (or `putRecord`, or `applyWrites` with
one write) with a session for the group. It takes the invite back by
docs/design/sites.md+17−6
@@ -8,7 +8,8 @@ names `reads` may also show the group as each visitor may see it. One
that names `spaces` may read the group's spaces whole as each visitor
may, and one that names `acts` may act for each visitor, such as
reporting what they see. One that names `writes` may write in the
group's spaces as each visitor may. Each works once the visitor signs in
group's spaces as each visitor may, and one that sets `inbox` makes
each visitor's invite inbox. Each works once the visitor signs in
on the site, through a page the host serves around its own
([live data](#live-data)).
@@ -49,6 +50,10 @@ pages may write in that person's own repo. Each is a type of the group's
spaces, a key if it's for one space of them, and a collection there,
such as `com.example.note` in `fyi.opensocial.siteSpace` under `board`.
It may set `inbox`, and then the host's page makes the invite inbox of
each visitor who signs in, if they have none
([invites](membership.md#invites)).
A site has 1 to 2000 files. Each publish replaces the record whole, and
deleting the record takes the site down. A blob only the old record held
is deleted with it, just as any blob is once no record holds it.
@@ -71,13 +76,13 @@ page says where the site is, how many files it has and when it was
published. It publishes a folder you choose in the browser, or deletes
the site after asking you to confirm. Publishing takes a `404.html` at
the folder's top as `notFound`. It keeps `fallback`, `reads`, `spaces`,
`acts` and `writes` under Advanced, filled in as the site has them.
`acts`, `writes` and `inbox` under Advanced, filled in as the site has them.
The `opensocial site publish` command reads a folder and sends its
files. `--reads` and `--acts` name methods by NSID or by their last
part, `--spaces` names each space as `<type>` or `<type>/<key>`, and
`--writes` names each write as `<type>:<collection>` or
`<type>/<key>:<collection>`. `site delete` takes the site down. Both
`<type>/<key>:<collection>`; `--inbox` sets `inbox`. `site delete` takes the site down. Both
leave out files whose names start with a dot. They send each file as
text if it's UTF-8 and as bytes otherwise, and they take the folder's
own name off each path. An AI app
@@ -250,7 +255,7 @@ them.
### The page around a site
A site that names `reads`, `spaces`, `acts` or `writes` is served
A site that names `reads`, `spaces`, `acts` or `writes`, or sets `inbox`, is served
differently. Each of its pages is the host's own page, which holds the
visitor's session. It shows the
site's page in a sandboxed frame beneath it, filling the window. The
@@ -283,17 +288,23 @@ Its scope is `atproto`, plus these:
- for each of its `writes`,
`space:<type>?authority=<the group>&skey=<key>&collection=<collection>&action=create&action=update&action=delete`.
- `blob:image/*`, if it has any `writes`.
- `space:fyi.opensocial.invites?action=read_self&manage=create`, if it
sets `inbox`.
An entry without a key leaves out `&skey=<key>`, and its scope covers
every space of the type. So the site can call those methods on the
host, read those of this group's spaces, and write those records in the
visitor's own repo in them.
visitor's own repo in them. With `inbox`, it can make the visitor's own
`fyi.opensocial.invites` space and read its policy, but nothing written
in it. Coming back from signing in, the host's page makes the inbox with
the SDK's `InviteInbox.open`: one already there is left as it is,
whatever its policy, and a failure only logs to the console.
It can't do anything else. The session is kept in the browser at the
address's origin and goes only to the visitor's PDS. The site's frame
never holds it.
The visitor's PDS must support spaces for them to sign in to a site
that names `spaces` or `writes`, since it must grant the `space:`
that names `spaces` or `writes`, or sets `inbox`, since it must grant the `space:`
scopes. bsky.social doesn't yet.
As the visitor moves through the site, the host's page puts the frame's
docs/reference/api.md+6−6
@@ -128,16 +128,16 @@ A group's website ([sites](../design/sites.md)).
| Method | What it does |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `POST fyi.opensocial.putSite` | publishes a group's whole site from the files given, each as text or bytes, and replaces the one there. `reads` lists the host's methods its pages may read, `acts` the procedures they may ask, and `spaces` the group's spaces they may read whole, each a type and, for one space of it, a `key`. `writes` lists the records they may write in the signed-in person's own repo in the group's spaces, each a type, an optional `key` and a collection. Pages do all of it as that person. It takes a body up to `BLOB_UPLOAD_LIMIT` |
| `POST fyi.opensocial.putSite` | publishes a group's whole site from the files given, each as text or bytes, and replaces the one there. `reads` lists the host's methods its pages may read, `acts` the procedures they may ask, and `spaces` the group's spaces they may read whole, each a type and, for one space of it, a `key`. `writes` lists the records they may write in the signed-in person's own repo in the group's spaces, each a type, an optional `key` and a collection. Pages do all of it as that person. `inbox` makes that person's invite inbox as they sign in, if they have none. It takes a body up to `BLOB_UPLOAD_LIMIT` |
| `POST fyi.opensocial.deleteSite` | takes a group's site down |
| `POST fyi.opensocial.putSiteDomain` | serves a group's site at its handle's own domain once that domain answers as this host. The site's address and `www.` under the domain redirect there |
| `POST fyi.opensocial.deleteSiteDomain` | serves a group's site at its address alone again |
| `GET /tls/ask?domain=<domain>` | answers 200 if the proxy in front may get a certificate for `domain`, and 404 otherwise. A domain qualifies if it's a group's own domain, or `www.` under it, while the group is on |
| `GET`, `HEAD` `https://<address>/<path>` | serves a file, sandboxed, from the site of the group whose address the request's `Host` names. The host keeps `/.well-known/` and `/xrpc/` there for itself. For a site that names `reads`, `spaces`, `acts` or `writes`, a page is the host's page wrapped around the site's. It holds the visitor's session and carries the site page's title, preview tags and the status it would have |
| `GET https://<address>/_site/<path>` | for a site that names `reads`, `spaces`, `acts` or `writes`, serves the file the frame shows, sandboxed, as above |
| `GET https://<address>/client-metadata.json` | for a site that names `reads`, `spaces`, `acts` or `writes`, serves its OAuth client's metadata. It's a public client asking for `atproto`, an `rpc:` scope for each read, each act and `getViewer`, and a `space:` scope to read each of its `spaces`, with `authority` the group and `skey` its key if it has one. For each write it asks a `space:` scope of its type, with `authority` the group, `skey` its key if it has one, its collection and every action, and with any write it asks `blob:image/*` ([live data](../design/sites.md#live-data)). It's named for the request's `X-Forwarded-Host` if a proxy sends one, and otherwise its `Host` |
| `GET https://<address>/_os/kit.js` | for a site that names `reads`, `spaces`, `acts` or `writes`, serves the script its pages load for `os` ([the site kit](site-kit.md)) |
| `GET https://<address>/_os/shell.js` | for a site that names `reads`, `spaces`, `acts` or `writes`, serves the host's page script from `SITE_SHELL_DIR`, or 404 without it |
| `GET`, `HEAD` `https://<address>/<path>` | serves a file, sandboxed, from the site of the group whose address the request's `Host` names. The host keeps `/.well-known/` and `/xrpc/` there for itself. For a site that names `reads`, `spaces`, `acts` or `writes`, or sets `inbox`, a page is the host's page wrapped around the site's. It holds the visitor's session and carries the site page's title, preview tags and the status it would have |
| `GET https://<address>/_site/<path>` | for a site that names `reads`, `spaces`, `acts` or `writes`, or sets `inbox`, serves the file the frame shows, sandboxed, as above |
| `GET https://<address>/client-metadata.json` | for a site that names `reads`, `spaces`, `acts` or `writes`, or sets `inbox`, serves its OAuth client's metadata. It's a public client asking for `atproto`, an `rpc:` scope for each read, each act and `getViewer`, and a `space:` scope to read each of its `spaces`, with `authority` the group and `skey` its key if it has one. For each write it asks a `space:` scope of its type, with `authority` the group, `skey` its key if it has one, its collection and every action, and with any write it asks `blob:image/*`. With `inbox` it asks `space:fyi.opensocial.invites?action=read_self&manage=create` ([live data](../design/sites.md#live-data)). It's named for the request's `X-Forwarded-Host` if a proxy sends one, and otherwise its `Host` |
| `GET https://<address>/_os/kit.js` | for a site that names `reads`, `spaces`, `acts` or `writes`, or sets `inbox`, serves the script its pages load for `os` ([the site kit](site-kit.md)) |
| `GET https://<address>/_os/shell.js` | for a site that names `reads`, `spaces`, `acts` or `writes`, or sets `inbox`, serves the host's page script from `SITE_SHELL_DIR`, or 404 without it |
The host is the spaces' authority and the PDS of the group's own repo in
each, so it answers the space alpha's methods:
docs/reference/cli.md+1−1
@@ -91,7 +91,7 @@ group's requests in it, while an MCP client acts in one group.
| Command | What it does |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `site publish <group> <dir> [--fallback <path>] [--not-found <path>] [--reads <methods>] [--acts <methods>] [--spaces <type[/key],…>] [--writes <type[/key]:collection,…>]` | publishes the files under `<dir>`, except those whose names start with a dot, as the group's website at its address. It replaces the site that's there, sending each file as text if it's UTF-8 and as bytes otherwise. `--reads` is a comma-separated list of the host's methods the site's pages may ask as whoever signs in on it, each by NSID or by its last part (`getGroup,listMembers`). `--acts` lists the procedures they may ask as that person the same way (`createReport`). `--spaces` is a comma-separated list of the group's spaces they may read whole as that person, each a type by NSID, or a type and one space's key (`fyi.opensocial.siteSpace/board,fyi.opensocial.siteSpace/calendar`). `--writes` is a comma-separated list of the records they may write in that person's own repo, each a space named the same way and a collection there (`fyi.opensocial.siteSpace/board:com.example.note`) ([live data](../design/sites.md#live-data)) |
| `site publish <group> <dir> [--fallback <path>] [--not-found <path>] [--reads <methods>] [--acts <methods>] [--spaces <type[/key],…>] [--writes <type[/key]:collection,…>] [--inbox]` | publishes the files under `<dir>`, except those whose names start with a dot, as the group's website at its address. It replaces the site that's there, sending each file as text if it's UTF-8 and as bytes otherwise. `--reads` is a comma-separated list of the host's methods the site's pages may ask as whoever signs in on it, each by NSID or by its last part (`getGroup,listMembers`). `--acts` lists the procedures they may ask as that person the same way (`createReport`). `--spaces` is a comma-separated list of the group's spaces they may read whole as that person, each a type by NSID, or a type and one space's key (`fyi.opensocial.siteSpace/board,fyi.opensocial.siteSpace/calendar`). `--writes` is a comma-separated list of the records they may write in that person's own repo, each a space named the same way and a collection there (`fyi.opensocial.siteSpace/board:com.example.note`). `--inbox` makes that person's invite inbox at their PDS as they sign in, if they have none ([live data](../design/sites.md#live-data)) |
| `site delete <group>` | takes the group's website down |
| `site domain <group> [--undo]` | serves the group's website at its handle's own domain once that domain reaches this host, and redirects its address and `www.` there. With `--undo`, it serves the site at its address alone again ([on its own domain](../design/sites.md#on-its-own-domain)) |
docs/reference/mcp.md+1−1
@@ -110,7 +110,7 @@ profile already had keeps its icon.
| Tool | Command | Lexicon | What it does |
| -------------- | -------------- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `site_publish` | `site publish` | `fyi.opensocial.putSite` | publishes the group's whole website from `files`, each `{path, text}` or `{path, bytes}`. `fallback` and `not_found` name files among them, and `reads` names the host's methods its pages may ask as whoever signs in. `acts` names the procedures they may ask as that person, and `spaces` the group's spaces they may read whole, each `{space, key}`, where `key` names one space of the type and without it it's every one (`{"space": "fyi.opensocial.siteSpace", "key": "board"}`). `writes` names the records they may write in that person's own repo, each `{space, key, collection}`, with `key` the same way. The command reads the files from a folder |
| `site_publish` | `site publish` | `fyi.opensocial.putSite` | publishes the group's whole website from `files`, each `{path, text}` or `{path, bytes}`. `fallback` and `not_found` name files among them, and `reads` names the host's methods its pages may ask as whoever signs in. `acts` names the procedures they may ask as that person, and `spaces` the group's spaces they may read whole, each `{space, key}`, where `key` names one space of the type and without it it's every one (`{"space": "fyi.opensocial.siteSpace", "key": "board"}`). `writes` names the records they may write in that person's own repo, each `{space, key, collection}`, with `key` the same way. `inbox` makes that person's invite inbox as they sign in, if they have none. The command reads the files from a folder |
| `site_delete` | `site delete` | `fyi.opensocial.deleteSite` | takes the group's website down |
| `site_domain` | `site domain` | `fyi.opensocial.putSiteDomain` | serves the group's website at its handle's own domain once that domain reaches this host. With `undo`, `fyi.opensocial.deleteSiteDomain` serves it at its address alone again |
docs/reference/sdk.md+18−2
examples/kicker/harness/e2e/flows.spec.mjs+21−0
examples/kicker/harness/seed.mjs+4−3
examples/kicker/README.md+4−1
lexicons/fyi/opensocial/putSite.json+4−0
lexicons/fyi/opensocial/site.json+4−0
packages/sdk/src/index.ts+1−0
packages/sdk/src/invite-inbox.test.tsnew+159−0
packages/sdk/src/invite-inbox.tsnew+126−0
packages/sdk/README.md+28−0
web/messages/en.json+3−0
web/shell/shell.ts+18−2
web/src/lib/organisms/GroupSite.svelte+9−0
web/src/lib/server/settings.ts+2−1
web/src/lib/server/site.ts+4−1