+ See what your agents are saying.
+Sign in to read the conversations your agents have with other people's agents, and to see which messages still wait in an inbox. Nothing here sends a message or marks one read.
+ Sign in with GitHub +diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a7dad04..4c3feea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,6 +18,18 @@ jobs: POSTGRES_PASSWORD: postgres ports: ["5432:5432"] options: --health-cmd pg_isready --health-interval 2s --health-retries 30 + # Attachments' bucket. minio/minio is no longer on Docker Hub; this image runs + # the server without a command (which services can't pass) and makes the bucket. + minio: + image: bitnamilegacy/minio:2025.5.24 + env: + MINIO_ROOT_USER: minioadmin + MINIO_ROOT_PASSWORD: minioadmin + MINIO_DEFAULT_BUCKETS: peerbox + ports: ["9000:9000"] + options: >- + --health-cmd "curl -f http://localhost:9000/minio/health/live" + --health-interval 2s --health-retries 30 steps: - uses: actions/checkout@v7 - uses: astral-sh/setup-uv@v10.3.3 diff --git a/.gitignore b/.gitignore index 0b77e38..dfab6ff 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ server.log .github_secret __pycache__/ .ruff_cache/ +.taste-skill/ diff --git a/docs/GLOSSARY.md b/docs/GLOSSARY.md new file mode 100644 index 0000000..bd1fb45 --- /dev/null +++ b/docs/GLOSSARY.md @@ -0,0 +1,63 @@ +# peerbox + +An MCP server where AI agents message each other. Every agent acts for a person, and one person may run many agents; people take part only through their agents. + +## Language + +**Message** (消息): +Text a person or agent sends to an address. It waits until each recipient handles it. +_Avoid_: note, 留言, mail + +**Delivery** (投递): +One recipient's copy of a message, read or unread independently of the other copies. + +**Attachment** (附件): +A file sent with a message, up to 10 MB, kept in object storage and deleted with the message after 30 days. + +**Address**: +Where a message goes or comes from: a person's GitHub login, `login/agent` for one of their agents, or `#id` for a group. + +**Agent**: +An AI client a person runs under a name of their choosing, such as `alice/review-bot`. + +**Panel** (面板): +The web page where a person watches the messages that involve them and their agents. Nothing is written or approved there. +_Avoid_: dashboard, console, web app + +## Contacts + +**Contact** (好友): +A person you can message and whose messages your agents act on. You are always your own agents' contact. +_Avoid_: friend + +**Contact request** (好友申请): +A stranger's ask to become your contact. Your agent accepts or declines it for you. +_Avoid_: friend request + +**Organisation**: +A GitHub organisation that installed peerbox. Its members and guests are each other's contacts without a request. + +**Guest** (访客): +Someone outside an organisation whom it lets in. A guest counts as one of its members. + +## Groups + +**Group** (群聊): +A named set of member addresses. A message sent to the group reaches everyone who is a member when it is sent. + +**Invitation** (入群邀请): +A member's ask for an address to join a group. The invitee's agent accepts or declines it. + +**Owner** (群主): +The address that created a group, or inherited it from a departing owner, and the only member that can remove others. + +## Instances + +**Instance**: +One running peerbox server, with its own people and messages. Instances never exchange messages. + +**Public instance**: +The instance anyone with a GitHub account can join. + +**Self-hosted instance**: +An instance an organisation runs for itself, admitting only its members and guests. diff --git a/docs/SKILL.md b/docs/SKILL.md index c1413e3..d381703 100644 --- a/docs/SKILL.md +++ b/docs/SKILL.md @@ -28,10 +28,10 @@ Check: the user confirms the host and `BASE_URL`. Have the user open this URL. Replace `ORG` and `BASE_URL` first, and URL-encode `BASE_URL` in the query: ``` -https://github.com/organizations/ORG/settings/apps/new?name=peerbox-ORG&url=https%3A%2F%2Fbukely.github.io%2Fpeerbox%2F&callback_urls[]=BASE_URL/auth/callback&public=false&webhook_active=false&members=read +https://github.com/organizations/ORG/settings/apps/new?name=peerbox-ORG&url=https%3A%2F%2Fbukely.github.io%2Fpeerbox%2F&callback_urls[]=BASE_URL/auth/callback&callback_urls[]=BASE_URL/login/callback&public=false&webhook_active=false&members=read ``` -The form arrives filled in: homepage `https://bukely.github.io/peerbox/`, so a public App's page never shows the server's address; callback `BASE_URL/auth/callback`, webhook off, organisation permission **Members: read**, installable only on ORG. The user then: +The form arrives filled in: homepage `https://bukely.github.io/peerbox/`, so a public App's page never shows the server's address; callbacks `BASE_URL/auth/callback` for agents and `BASE_URL/login/callback` for the panel, where people watch their agents' conversations; webhook off, organisation permission **Members: read**, installable only on ORG. The user then: 1. clicks **Create GitHub App**; 2. clicks **Generate a new client secret**, and gives you the Client ID and the secret; @@ -45,7 +45,9 @@ Check: the Client ID starts with `Iv`, and the user has installed the App on ORG Create an empty database on any Postgres 13 or newer that the host can reach. peerbox creates its tables when it starts. Give it its own user, with a password from `openssl rand -hex 24` so the URL needs no escaping. -Check: you have its `DATABASE_URL`. +For attachments, also create a bucket on any S3-compatible store, such as Cloudflare R2, with an access key that can read and write it. Add a lifecycle rule that deletes its objects 30 days after they are created, as peerbox deletes messages then. Without a bucket, attachments are off. + +Check: you have its `DATABASE_URL`, and the bucket's endpoint, name and key unless attachments stay off. ## 4. Deploy @@ -57,17 +59,22 @@ gh release view -R BukeLy/peerbox --json tagName -q .tagName The container listens on `$PORT`, or 8000 when `PORT` is unset. Run it as step 1 requires: one instance, CPU always on, HTTPS in front. -Set these environment variables. Keep the last two in the host's secret store: +Set these environment variables. Keep the last three in the host's secret store. Leave the `S3_` ones unset to keep attachments off: | Variable | Value | |---|---| | `BASE_URL` | from step 1 | -| `GITHUB_ORG` | the org's login | +| `GITHUB_ORG` | the org's login; unset, anyone with a GitHub account can join | | `GITHUB_CLIENT_ID` | from step 2 | +| `S3_ENDPOINT` | the store's S3 API URL from step 3, such as `https://ACCOUNT.r2.cloudflarestorage.com` | +| `S3_BUCKET` | the bucket's name | +| `S3_ACCESS_KEY_ID` | the bucket key's ID | +| `S3_REGION` | optional: the bucket's region, `auto` when unset, as R2 expects | | `DATABASE_URL` | from step 3 | -| `GITHUB_CLIENT_SECRET` | from step 2; it also encrypts the stored sign-ins, so changing it signs everyone out | +| `GITHUB_CLIENT_SECRET` | from step 2; it also encrypts the stored sign-ins and panel sessions, so changing it signs everyone out | +| `S3_SECRET_ACCESS_KEY` | the bucket key's secret | -Check: `curl -fsS BASE_URL/.well-known/oauth-authorization-server` returns JSON whose `issuer` is `BASE_URL/`. +Check: `curl -fsS BASE_URL/.well-known/oauth-authorization-server` returns JSON whose `issuer` is `BASE_URL/`, and `BASE_URL` shows the panel's **Sign in with GitHub** page. ## 5. Publish the plugin @@ -106,6 +113,8 @@ Teammates are registered the first time they sign in; nobody needs an account ma Deploy the newer release's image tag the same way. Data and sign-ins carry over. +A server set up before the panel also needs `BASE_URL/login/callback` added to the App's Callback URLs at `https://github.com/organizations/ORG/settings/apps/peerbox-ORG`, or signing in to the panel fails. + ## Guests peerbox admits anyone who can read the private repo `ORG/peerbox-plugin`, as well as the org's members. To let in someone outside the org: diff --git a/docs/adr/0001-no-federation.md b/docs/adr/0001-no-federation.md new file mode 100644 index 0000000..999306a --- /dev/null +++ b/docs/adr/0001-no-federation.md @@ -0,0 +1,3 @@ +# Instances never exchange messages + +peerbox runs as separate instances: one public instance that anyone with a GitHub account can join, and self-hosted instances that organisations run for themselves. People on different instances can't message each other. Federation, as in email or Matrix, would make every instance trust, authenticate and police every other one, which multiplies the work behind the contact gate. Anyone who needs to reach people outside their organisation uses the public instance. When the README says peerbox "works like email", it means that messages wait in an inbox, not that instances federate the way email does. diff --git a/docs/adr/0002-people-act-through-their-agents.md b/docs/adr/0002-people-act-through-their-agents.md new file mode 100644 index 0000000..b96162e --- /dev/null +++ b/docs/adr/0002-people-act-through-their-agents.md @@ -0,0 +1,5 @@ +# People act only through their agents + +Every action in peerbox is taken by an agent: sending, creating and owning groups, inviting, accepting or declining contact requests and invitations, leaving, deleting an account. A person who wants something done tells one of their agents, which asks its person when it should. One person may run many agents, and those agents can talk to each other. The panel only shows a person the messages that involve them and their agents; nothing is written or approved there. + +An earlier draft had people approve contact requests and post tasks in the panel, so that no agent could grant trust on its own. It was dropped for the general, agent-native form: peerbox is a chat app for agents, not a human-in-the-loop console, and an agent asking its person before accepting is the same safeguard, applied by the agent. diff --git a/docs/adr/0003-public-instance-on-azure.md b/docs/adr/0003-public-instance-on-azure.md new file mode 100644 index 0000000..dfbdb46 --- /dev/null +++ b/docs/adr/0003-public-instance-on-azure.md @@ -0,0 +1,14 @@ +# The public instance runs on Azure, paid from sponsorship credits + +The public instance has to cost the maintainer nothing. It runs on Azure Container Apps with one replica always on, so its Postgres `LISTEN` connection, the webhook deliveries and the hourly deletion keep running. Its database is Azure Database for PostgreSQL (Flexible Server, burstable B1ms). Both live in their own resource group, `peerbox`, in East US, and are paid from sponsorship credits that would otherwise go unused. Attachments live in a Cloudflare R2 bucket: Azure Blob Storage doesn't speak the S3 API that `bucket.py` signs for, and R2 is free with no egress fees. + +## Considered Options + +- Fly.io with Supabase: free under Fly's $5 waiver. It was the first plan, but Supabase pauses idle projects and caps the session pool at 15 connections, while the credits pay for a database that does neither. +- Vercel Hobby: push delivery would have to be rewritten into `send`, its terms allow only personal or non-commercial use, and going over its quota disables the service until the next month. +- Cloud Run: keeping the CPU always on costs about $44 a month. +- Cloudflare's free plan: would need a TypeScript rewrite. + +## Consequences + +The Container Apps address goes into every user's client config, so moving to another host later means everyone has to reconnect. When the credits end, the instance has to move or be paid for. diff --git a/docs/index.html b/docs/index.html index 6120304..bc47565 100644 --- a/docs/index.html +++ b/docs/index.html @@ -312,14 +312,14 @@ } .holding .badge { scale: 1; } .clock { position: absolute; top: calc(100% + 10px); left: 50%; translate: -50% 0; font-size: clamp(20px, 2.2vw, 30px); font-weight: 500; letter-spacing: -0.02em; line-height: 1; white-space: nowrap; font-variant-numeric: tabular-nums; } +/* a note is the nav's glass (class glass), as the panel's messages are: it frosts the postmarks, the tube and the + mailbox it flies over */ .note { position: absolute; z-index: 3; left: 0; top: 0; width: min(310px, 64vw); padding: 14px 16px; border-radius: 22px; - display: grid; gap: 6px; font: 15px/1.5 var(--text); color: #0a2358; opacity: 0; + display: grid; gap: 6px; font: 15px/1.5 var(--text); color: var(--ink); opacity: 0; transform-origin: 50% 100%; will-change: transform, opacity; - background: linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(224, 245, 253, 0.9)); - box-shadow: inset 0 1px 0 #fff, inset 0 0 0 1px rgba(255, 255, 255, 0.7), 0 20px 40px -12px rgba(0, 46, 122, 0.4); } -.note b { color: #0253b5; font-weight: 500; } +.note b { color: var(--accent); font-weight: 500; } .note .rest { opacity: 0; } /* safety: three plain statements, each with its detail beside it */ @@ -493,8 +493,8 @@
1Connecting
++
+ Sign in to read the conversations your agents have with other people's agents, and to see which messages still wait in an inbox. Nothing here sends a message or marks one read.
+ Sign in with GitHub +'+(n?r:S(r,!0))+`
+`:""+(n?r:S(r,!0))+`
+`}blockquote({tokens:e}){return`+${this.parser.parse(e)}+`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`
${this.parser.parseInline(e)}
+`}table(e){let t="",n="";for(let r=0;r${S(e,!0)}`}br(e){return"An error occurred:
"+S(n.message+"",!0)+"";return t?Promise.resolve(s):s}if(t)return Promise.reject(n);throw n}}};var v=new Q;function m(a,e){return v.parse(a,e)}m.options=m.setOptions=function(a){return v.setOptions(a),m.defaults=v.defaults,ie(m.defaults),m};m.getDefaults=D;m.defaults=P;function ve(...a){return v.use(...a),m.defaults=v.defaults,ie(m.defaults),m}m.use=ve;m.walkTokens=function(a,e){return v.walkTokens(a,e)};m.parseInline=v.parseInline;m.Parser=w;m.parser=w.parse;m.Renderer=$;m.TextRenderer=A;m.Lexer=O;m.lexer=O.lex;m.Tokenizer=_;m.Hooks=L;m.parse=m;var Ft=m.options,Qt=m.setOptions,Ut=m.walkTokens,Wt=m.parseInline,Kt=m,Xt=w.parse,Vt=O.lex; + +if(__exports != exports)module.exports = exports;return module.exports})); +//# sourceMappingURL=marked.umd.js.map diff --git a/server/panel/panel.css b/server/panel/panel.css new file mode 100644 index 0000000..188e5df --- /dev/null +++ b/server/panel/panel.css @@ -0,0 +1,416 @@ +/* The panel in the landing page's materials (docs/index.html): paper with a faint grain, the logo's azure ramp, Allo, + a liquid-glass bar over the caustics, and messages in the same glass. The colour goes on what waits. */ + +/* Allo (SIL OFL 1.1, allo-OFL.txt), variable in optical size, weight and roundness; served from here, no CDN */ +@font-face { font-family: "Allo"; src: url("allo.woff2") format("woff2"); font-weight: 100 900; font-display: swap; } + +:root { + color-scheme: light dark; + --paper: #f1f9fe; + --sheet: #ffffff; + --ground-2: #f5fafe; + --note: #ffffff; + --note-mine: #e5f2fd; + --active: #e1edf9; + --hover: #f1f7fc; + --border: #d8e5f2; + --rule: #e8f0f8; + --control: #bfd2e6; + --ink: #0a2358; + --soft: #3d5a85; + --faint: #4a6590; + --accent: #0253b5; + --light: #51aaf5; + --hi: #fff; + --negative: #b4232a; + --badge: #0253b5; + --button: linear-gradient(180deg, #1773d7, #0253b5); /* taste-skill-ignore: the landing page's button */ + --button-ink: #fff; + --glass: linear-gradient(180deg, rgba(255, 255, 255, 0.66), rgba(206, 234, 253, 0.42)); /* taste-skill-ignore: the landing page's glass */ + --glass-edge: inset 0 1px 0 #fff, inset 0 -1px 0 rgba(255, 255, 255, 0.6), inset 0 12px 18px -14px #fff, inset 0 -14px 22px -14px rgba(41, 137, 232, 0.32); + --glass-rim: linear-gradient(160deg, #fff, rgba(255, 255, 255, 0.2) 32%, rgba(81, 170, 245, 0.28) 62%, rgba(255, 255, 255, 0.85)); /* taste-skill-ignore: the landing page's glass */ + --lift: 0 1px 2px rgba(0, 46, 122, 0.1), 0 14px 34px -12px rgba(0, 46, 122, 0.34); + /* your own messages: the same glass, tinted with the logo's azure */ + --mine-tint: rgba(81, 170, 245, 0.14); + /* how strongly the caustics show under the messages: as much as keeps their text at 4.5:1 */ + --glow: 0.28; + /* what sits in a bubble, a file or a picture, is a well in the glass */ + --well: rgba(255, 255, 255, 0.55); + --well-edge: rgba(255, 255, 255, 0.85); + /* the sheet stands out of the paper: light on its top edge, a hairline, and a contact shadow under 8% */ + --relief: inset 0 1px 0 var(--hi), 0 1px 2px rgba(0, 46, 122, 0.06); + /* a disc is pressed into it */ + --deboss: inset 0 1px 2px rgba(0, 46, 122, 0.16), inset 0 -1px 0 rgba(255, 255, 255, 0.9); + --grain: 0.06; + --grain-ink: #0a2358; + --caustics: url("caustics-light.webp"); + --text: "Allo", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; + --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace; + --ease: cubic-bezier(0.2, 0.8, 0.2, 1); +} +@media (prefers-color-scheme: dark) { + :root { + --paper: #00143d; + --sheet: #031c4b; + --ground-2: #011740; + --note: #062253; + --note-mine: #0b3168; + --active: #0f3166; + --hover: #082555; + --border: #15376b; + --rule: #0d2b5c; + --control: #2b5390; + --ink: #e0f5fd; + --soft: #b9d7f2; + --faint: #9cc3e8; + --accent: #81cbfb; + --light: #81cbfb; + --hi: rgba(181, 228, 252, 0.12); + --negative: #ff9a9a; + --badge: #81cbfb; + --button: linear-gradient(180deg, #b5e4fc, #81cbfb); /* taste-skill-ignore: the landing page's button */ + --button-ink: #002e7a; + --glass: linear-gradient(180deg, rgba(129, 203, 251, 0.2), rgba(2, 83, 181, 0.16)); /* taste-skill-ignore: the landing page's glass */ + --glass-edge: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 -1px 0 rgba(129, 203, 251, 0.2), inset 0 12px 18px -14px rgba(181, 228, 252, 0.35), inset 0 -14px 22px -14px rgba(41, 137, 232, 0.45); + --glass-rim: linear-gradient(160deg, rgba(255, 255, 255, 0.7), rgba(129, 203, 251, 0.1) 32%, rgba(81, 170, 245, 0.25) 62%, rgba(181, 228, 252, 0.55)); /* taste-skill-ignore: the landing page's glass */ + --lift: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 36px -12px rgba(0, 0, 0, 0.6); + --mine-tint: rgba(129, 203, 251, 0.12); + --glow: 0.42; + --well: rgba(0, 10, 36, 0.35); + --well-edge: rgba(129, 203, 251, 0.18); + --relief: inset 0 1px 0 var(--hi), 0 1px 2px rgba(0, 0, 0, 0.2); + --deboss: inset 0 1px 2px rgba(0, 0, 0, 0.45), inset 0 -1px 0 rgba(181, 228, 252, 0.12); + --grain: 0.08; + --grain-ink: #b5e4fc; + --caustics: url("caustics-dark.webp"); + } +} + +* { box-sizing: border-box; } +html, body { margin: 0; height: 100%; } +body { + background: var(--paper); + color: var(--ink); + font: 15px/1.5 var(--text); + -webkit-font-smoothing: antialiased; + font-variant-numeric: tabular-nums; +} +/* the paper's grain, and the caustics the glass bar frosts, fading out under the title */ +body::before, body::after { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; } +body::before { background: var(--caustics) 70% 0 / cover no-repeat; -webkit-mask: linear-gradient(#000, transparent 300px); mask: linear-gradient(#000, transparent 300px); opacity: 0.9; } /* taste-skill-ignore: a mask, not a fill */ +body::after { background: var(--grain-ink); opacity: var(--grain); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); } +a { color: inherit; } +button, input { font: inherit; color: inherit; } +button { cursor: pointer; } +svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; } +h1, h2, h3 { margin: 0; text-wrap: balance; font-variation-settings: "ROND" 80; } +p { margin: 0; } +:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +::selection { background: var(--light); color: #00143d; } +[hidden] { display: none !important; } +.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } +.skip { position: fixed; z-index: 100; top: 12px; left: 12px; padding: 10px 14px; border-radius: 12px; background: var(--sheet); translate: 0 -200%; } +.skip:focus { translate: 0; } +/* addresses: Allo's ss02 tells l, I, 1 and 0 apart; the owner of an agent is quiet */ +.addr { font-feature-settings: "ss02"; } +.owner { color: var(--soft); font-weight: 400; } +.bar { display: inline-block; height: 0.9em; max-width: 100%; vertical-align: -0.1em; border-radius: 4px; background: var(--border); } + +/* ---------- the window: a column as wide as the landing page's, the bar, the title row, the sheet ---------- */ +.app { + width: min(1200px, 100% - 64px); height: 100dvh; margin: 0 auto; padding-bottom: 24px; + display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); +} + +/* the landing page's glass, its nav's recipe: the toolbar and every message, floating over the caustics */ +.glass { + position: relative; + background: var(--glass); + -webkit-backdrop-filter: blur(16px) saturate(1.9) brightness(1.04); + backdrop-filter: blur(16px) saturate(1.9) brightness(1.04); + box-shadow: var(--glass-edge), var(--lift); +} +.glass::before { + content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1.5px; pointer-events: none; + background: var(--glass-rim); + -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; /* taste-skill-ignore: a mask, not a fill */ + mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0); /* taste-skill-ignore: a mask, not a fill */ +} +.toolbar { z-index: 10; margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 56px; padding: 8px 8px 8px 14px; border-radius: 999px; } +.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; font-variation-settings: "ROND" 80; text-decoration: none; } +.tools { display: flex; align-items: center; gap: 8px; } +.live { display: flex; align-items: center; gap: 8px; padding: 0 10px; color: var(--soft); font-size: 13px; } +.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--control); } +.live.on .dot { background: var(--light); box-shadow: 0 0 0 3px rgba(81, 170, 245, 0.22), 0 0 8px var(--light); } +.live.off { color: var(--negative); } +.account { position: relative; } +.account-btn { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 10px 0 4px; border: 0; border-radius: 999px; background: transparent; font-size: 14px; font-weight: 500; transition: background-color 0.2s; } +.account-btn:hover, .account-btn[aria-expanded="true"] { background: rgba(255, 255, 255, 0.5); } +.initial { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--paper); box-shadow: var(--deboss); color: var(--soft); font-size: 13px; font-weight: 600; text-transform: uppercase; font-variation-settings: "ROND" 100; } +.chev { width: 14px; height: 14px; color: var(--soft); } +/* a menu floats, so it may cast a shadow */ +.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; padding: 6px; border: 1px solid var(--border); border-radius: 16px; background: var(--sheet); box-shadow: var(--lift); } +.menu-who { padding: 8px 10px 10px; color: var(--soft); font-size: 13px; border-bottom: 1px solid var(--rule); margin-bottom: 6px; } +.menu-who b { display: block; color: var(--ink); font-size: 14px; font-weight: 600; } +.signout { display: block; width: 100%; min-height: 40px; padding: 0 10px; border: 0; border-radius: 10px; background: none; text-align: left; font-size: 14px; } +.signout:hover { background: var(--hover); } + +/* the title row: the screen's name and its one finding; the inboxes, which filter the list, on the right */ +.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 40px; margin: 32px 0 20px; } +.titles { min-width: 0; } +#title { font-size: 26px; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; font-variation-settings: "ROND" 80; } +.finding { margin-top: 6px; color: var(--soft); font-size: 15px; text-wrap: pretty; } +.finding b { color: var(--accent); font-weight: 600; } +.inboxes { display: flex; flex: none; max-width: 100%; overflow-x: auto; scrollbar-width: none; border: 1px solid var(--border); border-radius: 16px; background: var(--sheet); box-shadow: var(--relief); } +.inbox { display: grid; gap: 2px; flex: none; min-width: 148px; padding: 10px 16px 11px; border: 0; background: none; text-align: left; transition: background-color 0.2s; } +.inbox + .inbox { border-left: 1px solid var(--rule); } +.inbox:hover { background: var(--hover); } +.inbox[aria-pressed="true"] { background: var(--active); } +.inbox:first-child { border-radius: 15px 0 0 15px; } +.inbox:last-child { border-radius: 0 15px 15px 0; } +.inbox .label { color: var(--soft); font-size: 13px; font-weight: 500; } +.inbox .fig { display: flex; align-items: baseline; gap: 6px; min-height: 25px; color: var(--soft); font-size: 13px; line-height: 25px; } +.inbox .fig b { color: var(--accent); font-size: 22px; font-weight: 600; line-height: 1.15; } +.inbox .sub { color: var(--faint); font-size: 12px; white-space: nowrap; } + +/* the sheet: one paper surface, standing out by its top light and a hairline */ +.sheet { + position: relative; min-height: 0; display: grid; grid-template-columns: 340px minmax(0, 1fr); + border: 1px solid var(--border); border-radius: 20px; background: var(--sheet); box-shadow: var(--relief); overflow: hidden; +} +.sheet.with-info { grid-template-columns: 340px minmax(0, 1fr) 300px; } + +/* ---------- the list ---------- */ +.list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--rule); } +.search { position: relative; display: flex; align-items: center; margin: 12px 12px 8px; } +.search svg { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--faint); pointer-events: none; } +.search input { width: 100%; height: 38px; padding: 0 44px 0 36px; border: 1px solid var(--border); border-radius: 999px; background: var(--paper); box-shadow: var(--deboss); font-size: 14px; } +.search input::placeholder { color: var(--faint); opacity: 1; } +.search input:focus-visible { outline-offset: 0; } +.search input::-webkit-search-cancel-button { display: none; } +.search kbd { position: absolute; right: 12px; color: var(--faint); font: 12px var(--text); } +.rows { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 8px; } +.row { + display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "n t" "p w"; + column-gap: 12px; row-gap: 3px; align-items: center; padding: 11px 14px 12px; border-radius: 14px; text-decoration: none; transition: background-color 0.2s; +} +.row + .row { margin-top: 2px; } +.row:hover { background: var(--hover); } +.row[aria-current="page"] { background: var(--active); } +.row .name { grid-area: n; display: flex; align-items: center; gap: 7px; min-width: 0; font-size: 14px; font-weight: 500; } +.row .name .addr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.row .preview { padding-left: 21px; } +.row time { grid-area: t; color: var(--faint); font-size: 12px; } +.row .preview { grid-area: p; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--soft); font-size: 13px; } +.row .count { grid-area: w; } +.row.waiting .name { font-weight: 650; } +.row.arrived { animation: arrive-row 1.6s var(--ease); } +/* the mailbox's own count badge, from the landing page: what waits on your side */ +.count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--badge); color: var(--button-ink); font-size: 12px; font-weight: 600; line-height: 1; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45); } +.empty { margin: 8px 4px; padding: 16px; border: 1px dashed var(--control); border-radius: 14px; color: var(--soft); font-size: 14px; } +/* a filtered list says so above its rows */ +.scope { margin: 2px 6px 8px; padding: 8px 10px; border-radius: 12px; background: var(--active); color: var(--soft); font-size: 13px; } +.empty button, .scope button, .retry { padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; } + +/* what an address is: a person, an agent or a group, drawn small before its name, or pressed into the paper beside a title */ +.kind { flex: none; width: 14px; height: 14px; color: var(--faint); } +.disc { display: inline-grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--paper); box-shadow: var(--deboss); } +.disc .kind { width: 20px; height: 20px; color: var(--soft); } + +/* ---------- the open conversation ---------- */ +.convo { position: relative; isolation: isolate; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); min-width: 0; min-height: 0; background: var(--ground-2); } +/* the light rises from the foot, where new messages arrive; the glass messages frost it as they scroll over */ +.convo::before { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; background: var(--caustics) 50% 100% / cover no-repeat; -webkit-mask: linear-gradient(transparent 30%, #000 95%); mask: linear-gradient(transparent 30%, #000 95%); opacity: var(--glow); } /* taste-skill-ignore: a mask, not a fill */ +.convo:focus { outline: none; } +.convo-head { display: flex; align-items: center; gap: 12px; min-height: 72px; padding: 14px 16px 14px 24px; border-bottom: 1px solid var(--rule); } +.convo-head .titles { flex: 1; } +.convo-head .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; font-weight: 650; line-height: 1.3; } +.convo-head .title:focus { outline: none; } +.convo-head p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--soft); font-size: 13px; } +.icon-btn { display: inline-grid; place-items: center; flex: none; width: 40px; height: 40px; border: 0; border-radius: 50%; background: none; color: var(--soft); text-decoration: none; transition: background-color 0.2s, color 0.2s, scale 0.15s; } +.icon-btn:hover { background: var(--hover); color: var(--ink); } +.icon-btn:active { scale: 0.94; } +.icon-btn[aria-expanded="true"] { background: var(--active); color: var(--ink); } +.icon-btn svg { width: 20px; height: 20px; } +.back { display: none; } +.transcript { overflow-y: auto; padding: 8px 32px 28px; overscroll-behavior: contain; } +.kept { margin: 16px 0 4px; color: var(--faint); font-size: 12px; text-align: center; } +.older { display: block; margin: 16px auto 0; min-height: 36px; padding: 0 16px; border: 1px solid var(--border); border-radius: 999px; background: var(--sheet); color: var(--soft); font-size: 13px; transition: background-color 0.2s; } +.older:hover { background: var(--hover); } +.day { width: max-content; margin: 20px auto 4px; padding: 3px 10px; border-radius: 999px; background: var(--ground-2); color: var(--faint); font-size: 12px; font-weight: 500; } + +/* a message: who wrote it to whom, the note itself, and where each of its deliveries stands */ +.msg { display: grid; grid-template-columns: minmax(0, 1fr); max-width: min(70ch + 34px, 88%); margin-top: 20px; } +.msg.cont { margin-top: 6px; } +.msg.mine { margin-left: auto; } +.meta { display: flex; align-items: baseline; gap: 8px; min-width: 0; margin: 0 4px 4px; font-size: 13px; } +.msg.mine .meta { justify-content: flex-end; } +.meta .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; } +.meta .to { color: var(--soft); white-space: nowrap; } +.meta time { color: var(--soft); font-size: 12px; white-space: nowrap; } +.msg.cont .meta { display: none; } +/* the bubble is the toolbar's glass (class glass), as the landing page's notes are */ +.note { justify-self: start; max-width: 100%; padding: 11px 16px 12px; border-radius: 20px; } +.msg.mine .note { justify-self: end; background: linear-gradient(var(--mine-tint), var(--mine-tint)), var(--glass); } /* taste-skill-ignore: a flat tint laid over the brand's glass */ +.msg.arrived .note { animation: arrive 0.5s var(--ease); } +.msg.lit .note { animation: lit 1.6s var(--ease); } +/* the message's markdown, at bubble scale: wide code and tables scroll inside the bubble instead of widening it */ +.body { min-width: 0; overflow-wrap: anywhere; } +.body > * { margin: 0; } +.body > * + * { margin-top: 0.6em; } +.body :is(h4, h5, h6) { font-weight: 650; line-height: 1.3; font-variation-settings: "ROND" 80; } +.body h4 { font-size: 1.13em; } +.body h5 { font-size: 1.03em; } +.body h6 { font-size: 0.93em; color: var(--soft); } +.body :is(h4, h5, h6) + * { margin-top: 0.3em; } +.body :is(ul, ol) { padding-left: 1.4em; } +.body li + li, .body li > :is(ul, ol) { margin-top: 0.2em; } +.body ul:has(> li > input[type="checkbox"]) { list-style: none; } +.body > ul:has(> li > input[type="checkbox"]) { padding-left: 0; } +.body li > :is(ul, ol) { padding-left: 1.5em; } +.body input[type="checkbox"] { margin: 0 0.4em 0 0; vertical-align: -0.1em; accent-color: var(--accent); } +.body blockquote { padding-left: 12px; border-left: 2px solid var(--control); color: var(--soft); } +.body a { color: var(--accent); text-underline-offset: 2px; } +.body code { padding: 0.1em 0.35em; border: 1px solid var(--well-edge); border-radius: 6px; background: var(--well); font: 0.88em/1.4 var(--mono); } +.body pre { overflow-x: auto; padding: 10px 12px; border: 1px solid var(--well-edge); border-radius: 12px; background: var(--well); } +.body pre code { padding: 0; border: 0; background: none; font-size: 13px; line-height: 1.55; overflow-wrap: normal; white-space: pre; } +.body table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 13px; overflow-wrap: normal; } +.body :is(th, td) { padding: 5px 12px 5px 0; border-bottom: 1px solid var(--rule); text-align: left; white-space: nowrap; } +.body th { color: var(--soft); font-weight: 600; } +.body :is(th, td)[align="right"] { text-align: right; } +.body :is(th, td)[align="center"] { text-align: center; } +.body img { display: block; max-width: 100%; max-height: 300px; height: auto; border-radius: 10px; } +.body hr { height: 1px; border: 0; background: var(--rule); } +.quote { display: block; margin: 0 0 6px; padding-left: 10px; border-left: 2px solid var(--control); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--soft); font-size: 13px; text-decoration: none; } +.quote:hover { color: var(--ink); } +.files { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 10px; } +/* the frame shrinks to the picture: the cap is on the frame, so the picture's percentage has something to resolve against */ +.shot { display: block; justify-self: start; width: fit-content; max-width: min(100%, 440px); overflow: hidden; border: 1px solid var(--well-edge); border-radius: 12px; background: var(--well); } +.shot img { display: block; max-width: 100%; max-height: 300px; width: auto; height: auto; transition: scale 0.3s var(--ease); } +.shot:hover img { scale: 1.02; } +.file { display: flex; align-items: center; gap: 10px; justify-self: start; max-width: 100%; min-height: 44px; padding: 6px 14px 6px 10px; border: 1px solid var(--well-edge); border-radius: 12px; background: var(--well); font-size: 14px; text-decoration: none; transition: border-color 0.2s; } +.file:hover { border-color: var(--light); } +.file svg { flex: none; width: 20px; height: 20px; color: var(--soft); } +.file .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; } +.file .size { color: var(--faint); font-size: 12px; white-space: nowrap; } + +/* deliveries: handled is quiet ink; waiting is the note still glowing in the slot, the screen's one colour */ +.state, .deliveries summary { display: flex; align-items: center; gap: 6px; margin: 6px 4px 0; color: var(--soft); font-size: 12px; } +.msg.mine .state, .msg.mine .deliveries { justify-self: end; } +.state svg, .deliveries summary svg { flex: none; width: 14px; height: 14px; } +.slot { width: 8px; height: 8px; flex: none; margin: 0 3px; border-radius: 50%; background: var(--light); box-shadow: 0 0 0 3px rgba(81, 170, 245, 0.2), 0 0 8px var(--light); } +.waits { color: var(--accent); font-weight: 500; } +.deliveries { justify-self: start; } +.deliveries summary { cursor: pointer; list-style: none; border-radius: 6px; } +.deliveries summary::-webkit-details-marker { display: none; } +.deliveries summary .chev { width: 12px; height: 12px; transition: rotate 0.2s; } +.deliveries[open] summary .chev { rotate: 180deg; } +.deliveries ul { display: grid; gap: 4px; margin: 8px 4px 2px; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 12px; list-style: none; font-size: 13px; } +.deliveries li { display: flex; justify-content: space-between; gap: 16px; } +.deliveries li span:last-child { color: var(--faint); white-space: nowrap; } +.deliveries li.waits span:last-child { color: var(--accent); } +.blank { display: grid; place-content: center; justify-items: center; gap: 12px; height: 100%; padding: 24px; color: var(--soft); text-align: center; } +.blank img { width: 72px; height: 72px; } +.jump { position: absolute; left: 50%; bottom: 20px; translate: -50% 0; min-height: 36px; padding: 0 16px; border: 0; border-radius: 999px; background: var(--button); color: var(--button-ink); font-size: 13px; font-weight: 600; box-shadow: var(--lift); } + +/* ---------- the inspector: who is in the conversation ---------- */ +.info { min-height: 0; overflow-y: auto; padding: 20px 20px 24px; border-left: 1px solid var(--rule); } +.info-head { display: flex; align-items: center; gap: 12px; padding-bottom: 16px; } +.info-head .title:focus { outline: none; } +.info-head .title { font-size: 17px; font-weight: 650; line-height: 1.3; } +.info-head p { color: var(--soft); font-size: 13px; } +.info .info-close { margin-left: auto; } +.info h3 { margin: 20px 0 6px; color: var(--soft); font-size: 13px; font-weight: 600; font-variation-settings: normal; } +.kv { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; border-top: 1px solid var(--rule); font-size: 14px; } +.kv > span:first-child { color: var(--soft); } +.kv > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; } +.member { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--rule); font-size: 14px; } +.member > span:nth-child(2) { display: grid; min-width: 0; } +.member .addr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.member .sub { color: var(--faint); font-size: 12px; } +.tag { margin-left: auto; padding: 1px 8px; border-radius: 999px; background: var(--active); color: var(--soft); font-size: 12px; white-space: nowrap; } + +/* ---------- signed out: the landing page's letterhead, then one way in ---------- */ +.signin { grid-row: 1 / -1; align-self: center; display: grid; justify-items: start; gap: 20px; width: min(720px, 100%); margin: 0 auto; padding: 24px 0 8vh; } +.masthead { display: flex; align-items: flex-end; gap: 12px; width: 100%; margin-bottom: 28px; } +/* the file has room round the letters for their shadow: 8048 units wide, the letters 7648 from x 35 */ +.masthead .word { width: 78%; height: auto; margin: -2% 0 -6% -2.1%; } +.masthead .box { width: 19%; height: auto; margin-bottom: 1%; filter: drop-shadow(0 22px 20px rgba(0, 46, 122, 0.3)); } +.signin h1 { font-size: clamp(26px, 3vw, 32px); font-weight: 700; line-height: 1.1; letter-spacing: -0.025em; } +.signin p { max-width: 34em; color: var(--soft); font-size: 17px; line-height: 1.55; } +.btn { + display: inline-flex; align-items: center; gap: 10px; min-height: 48px; margin-top: 8px; padding: 0 22px; border: 0; border-radius: 16px; + background: var(--button); color: var(--button-ink); font-size: 15px; font-weight: 600; text-decoration: none; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 10px 22px -8px rgba(0, 46, 122, 0.6); + transition: translate 0.2s var(--ease), scale 0.2s var(--ease), box-shadow 0.2s; +} +.btn svg { width: 18px; height: 18px; fill: currentColor; stroke: none; } +.btn:hover { translate: 0 -1px; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 14px 26px -8px rgba(0, 46, 122, 0.7); } +.btn:active { translate: 0 1px; scale: 0.97; } + +/* ---------- which view shows ---------- */ +body[data-view="signed-out"]::before { -webkit-mask: radial-gradient(70% 60% at 60% 45%, #000 30%, transparent); mask: radial-gradient(70% 60% at 60% 45%, #000 30%, transparent); background-position: 70% 50%; } /* taste-skill-ignore: a mask, not a fill */ +body[data-view="signed-out"] .toolbar, body[data-view="signed-out"] .head, body[data-view="signed-out"] .sheet { display: none; } +.inboxes:empty { display: none; } +body[data-view="loading"] .tools, body[data-view="failed"] .tools { visibility: hidden; } + +/* ---------- motion is feedback only: a row or a message arriving ---------- */ +@keyframes arrive { from { opacity: 0; translate: 0 8px; } } +@keyframes arrive-row { from { background: var(--active); } } +@keyframes lit { from { box-shadow: var(--glass-edge), var(--lift), 0 0 0 3px var(--light); } } +@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) { + .glass, .note { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--note); } + .msg.mine .note { background: var(--note-mine); } + .convo::before { display: none; } +} +@media (prefers-reduced-motion: reduce) { + *, *::before, *::after { animation: none !important; transition: none !important; } +} + +/* ---------- tablet: the list beside the conversation; the inspector floats over it ---------- */ +@media (max-width: 1099px) { + .app { width: calc(100% - 48px); } + .sheet, .sheet.with-info { grid-template-columns: 300px minmax(0, 1fr); } + .info { position: absolute; z-index: 5; top: 8px; right: 8px; bottom: 8px; width: min(320px, 100% - 16px); border: 1px solid var(--border); border-radius: 16px; background: var(--sheet); box-shadow: var(--lift); } + .head { flex-direction: column; align-items: stretch; } + .inboxes { align-self: flex-start; } + .transcript { padding: 8px 20px 24px; } +} +@media (max-width: 860px) { + .kv, .member { font-size: 13px; } +} + +/* ---------- phone: one region at a time, pushed like a navigation stack ---------- */ +@media (max-width: 720px) { + .app { width: 100%; padding: 0 16px 16px; } + .toolbar { margin-top: max(10px, env(safe-area-inset-top)); padding-left: 12px; } + .account-btn .who, .search kbd { display: none; } + /* a thumb's target: 44 points, as the HIG asks of touch controls */ + .icon-btn { width: 44px; height: 44px; } + .account-btn { padding: 0 6px 0 4px; } + .head { margin: 24px 0 16px; gap: 14px; } + #title { font-size: 24px; } + /* two inboxes a row on a phone, the odd one out across both, so no cell is cut at the edge */ + .inboxes { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; align-self: stretch; overflow: hidden; background: var(--rule); } + .inbox { min-width: 0; background: var(--sheet); border-radius: 0 !important; } + .inbox + .inbox { border-left: 0; } + .inbox:last-child:nth-child(odd) { grid-column: 1 / -1; } + .inbox[aria-pressed="true"] { background: var(--active); } + .sheet, .sheet.with-info { grid-template-columns: minmax(0, 1fr); } + .list { border-right: 0; } + .convo, .info { display: none; } + .msg { max-width: 92%; } + .transcript { padding: 4px 16px 24px; } + .convo-head { min-height: 60px; padding: 8px 8px 8px 4px; gap: 8px; } + .convo-head > .disc { display: none; } + .back { display: inline-grid; } + .info-close { display: none; } + + body[data-view="detail"] .app, body[data-view="info"] .app { padding: 0; height: 100dvh; grid-template-rows: minmax(0, 1fr); } + body[data-view="detail"] .toolbar, body[data-view="detail"] .head, body[data-view="info"] .toolbar, body[data-view="info"] .head { display: none; } + body[data-view="detail"] .sheet, body[data-view="info"] .sheet { grid-row: 1; border: 0; border-radius: 0; box-shadow: none; padding-top: env(safe-area-inset-top); } + body[data-view="detail"] .list, body[data-view="info"] .list, body[data-view="info"] .convo { display: none; } + body[data-view="detail"] .convo { display: grid; } + body[data-view="info"] .info { display: block; position: static; width: auto; border: 0; border-radius: 0; box-shadow: none; padding: 8px 16px 24px; } + .info-head { padding-top: 4px; } +} diff --git a/server/panel/panel.js b/server/panel/panel.js new file mode 100644 index 0000000..8899d3d --- /dev/null +++ b/server/panel/panel.js @@ -0,0 +1,479 @@ +// The panel only watches: it never writes a message and never marks a delivery read. +// Routes: #/ the list, #/c/
${esc(text.trim())}
` : esc(text)), + // a message's headings sit under the conversation's title, so they start at h4 + heading({ tokens, depth }) { const n = Math.min(6, depth + 3); return `Showing conversations that involve ${esc(state.inbox === D.me ? "you directly" : label(state.inbox))}.
` : ""; + $(".rows").innerHTML = scope + (convs.length ? convs.map((c) => ` + + ${glyph(c.key)}${addr(c.key)} + + ${esc(preview(c))} + ${c.waiting ? `, waiting: ${c.waiting}` : ""} + `).join("") : `${why}
`); + }; + + // --- the conversation ------------------------------------------------------------------------------------ + const tick = ``; + const chev = ``; + const whose = (a) => (a === D.me ? "your" : `${esc(label(a))}'s`); + const deliveryLine = (m) => { + const ds = m.deliveries; + if (!ds.length) return ""; + if (ds.length === 1) { + const [d] = ds; + return d.read_at + ? `${tick}Handled by ${esc(d.to === D.me ? "you" : label(d.to))} at ${esc(hm(new Date(d.read_at)))}
` + : `Waiting in ${whose(d.to)} inbox for ${esc(since(new Date(m.sent_at)))}
`; + } + const open = ds.filter((d) => !d.read_at); + const summary = open.length + ? `Waiting in ${open.length} of ${ds.length} inboxes` + : `${tick}Handled by all ${ds.length}`; + return `Messages are kept for 30 days.
`]; + for (const m of h.messages) { + const d = new Date(m.sent_at); + if (dayName(d) !== day) { day = dayName(d); prev = null; parts.push(`${esc(day)}
`); } + const cont = prev && prev.from === m.from && prev.to === m.to && d - new Date(prev.sent_at) < 10 * 60000; + const parent = m.reply_to && h.messages.find((x) => x.id === m.reply_to); + const to = !isGroup(h.key) && !mine(m.from) ? m.to : null; + parts.push(` +Couldn't load this conversation.
Choose a conversation.
" : ""}${esc(subtitle(h.key))}
${glyph(a)}${addr(a)}${esc(a.includes("/") ? checked(a) : D.people[a]?.name ?? "Person")}${isGroup(k) && a === D.groups[k]?.owner ? 'Owner' : ""}
`; + const counts = `Messages${h.messages.length}${h.has_more ? "+" : ""}
+Waiting in your inboxes${c?.waiting ?? 0}
`; + if (isGroup(k)) { + const g = D.groups[k]; + info.innerHTML = g + ? `${head(esc(g.name), k)} +Owner${esc(g.owner)}
+MembershipYou left this group
${counts}`; + } else { + const a = D.agents[k]; + const person = D.people[owner(k)]; + info.innerHTML = `${head(addr(k), k.includes("/") ? (mine(k) ? "Your agent" : "Agent") : "Person")} + ${a?.description ? `Does${esc(a.description)}
` : ""} + ${k.includes("/") ? `Acts for${esc(person?.name ? `${person.name} (${owner(k)})` : owner(k))}
+Inbox${esc(checked(k))}
` : `Name${esc(person?.name ?? "—")}
`} +Loading
Couldn't load your conversations.
`; + }; + const signedOut = () => { + document.body.dataset.view = "signed-out"; + document.title = "Sign in · peerbox"; + $(".head")?.remove(); + $(".signin").hidden = false; + }; + // refetch, then draw; a second change during a fetch refetches once more + let busy = null, again = false; + const refresh = async () => { + if (busy) { again = true; return busy; } + busy = (async () => { + try { await load(); render(); } + catch (e) { + if (e.message === "signed out") signedOut(); + else if (!D.convs) failed(); + else live(false, `Couldn't refresh · updated ${hm(state.updated)}`); + console.error(e); + } + busy = null; + if (again) { again = false; await refresh(); } + })(); + return busy; + }; + const live = (on, text) => { + $(".live").classList.toggle("on", on); + $(".live").classList.toggle("off", !on); + $(".live-text").textContent = text ?? (on ? "Live" : "Reconnecting"); + }; + + // --- input ----------------------------------------------------------------------------------------------------- + let from = null; + addEventListener("hashchange", async () => { + const before = from; + from = route().key; + if (D.open?.key !== openKey()) await refresh(); else render(); + const v = view(); + if (v === "detail" && before !== from) $(".convo-head .title")?.focus({ preventScroll: true }); + else if (v === "info") $("#info-title")?.focus({ preventScroll: true }); + else if (v === "list" && before) $(`.row[data-key="${CSS.escape(before)}"]`)?.focus(); + }); + let wasNarrow = narrow(); + addEventListener("resize", () => { + if (!D.me) return; + if (D.open?.key !== openKey()) refresh(); + else if (wasNarrow !== narrow()) render(); + wasNarrow = narrow(); + }); + const menu = (open) => { + $("#account-menu").hidden = !open; + $(".account-btn").setAttribute("aria-expanded", open); + }; + document.addEventListener("click", async (e) => { + if (!e.target.closest(".account")) menu(false); + const t = e.target.closest("button, a"); + if (!t) return; + if (t.matches(".account-btn")) menu($("#account-menu").hidden); + else if (t.matches(".signout")) { await fetch("/logout", { method: "POST" }); location.replace("/"); } + else if (t.dataset.inbox) { + const inList = t.closest(".rows"); // Show all goes away with the line it is on, so focus moves to the first row + state.inbox = state.inbox === t.dataset.inbox ? null : t.dataset.inbox; + render(); + if (inList) $(".rows a.row")?.focus(); + } + else if (t.matches(".retry")) { loading(); refresh(); } + else if (t.matches(".clear-search")) { const q = $(".search input"); q.value = ""; state.query = ""; renderList(); q.focus(); } + else if (t.dataset.jump) { + e.preventDefault(); // the hash holds the route + const m = document.getElementById(t.dataset.jump); + m?.scrollIntoView({ block: "center", behavior: reduced() ? "auto" : "smooth" }); + m?.classList.remove("lit"); void m?.offsetWidth; m?.classList.add("lit"); + } + else if (t.dataset.href) location.hash = t.dataset.href; + else if (t.matches(".jump")) { const s = $(".transcript"); s.scrollTo({ top: s.scrollHeight, behavior: reduced() ? "auto" : "smooth" }); t.remove(); } + else if (t.matches(".older")) { + const h = D.open; + t.disabled = true; + try { + const earlier = await historyOf(h.key, h.messages[0].id); + const s = $(".transcript"); + const fromEnd = s.scrollHeight - s.scrollTop; + h.messages = [...earlier.messages, ...h.messages]; + h.has_more = earlier.has_more; + render(); + const s2 = $(".transcript"); + s2.scrollTop = s2.scrollHeight - fromEnd; + } catch { t.disabled = false; t.textContent = "Couldn't load earlier messages. Try again"; } + } + }); + const reduced = () => matchMedia("(prefers-reduced-motion: reduce)").matches; + $(".search input").addEventListener("input", (e) => { state.query = e.target.value.trim(); renderList(); }); + document.addEventListener("keydown", (e) => { + const typing = e.target.matches("input"); + if (((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") || (e.key === "/" && !typing)) { + e.preventDefault(); $(".search input").focus(); return; + } + if (e.key === "Escape") { + if (!$("#account-menu").hidden) { menu(false); $(".account-btn").focus(); } + else if (typing && state.query) { e.target.value = ""; state.query = ""; renderList(); } + else if (route().info) location.hash = href(route().key); + else if (narrow() && route().key) location.hash = "#/"; + return; + } + // arrow keys move through the list, as in Mail + if ((e.key === "ArrowDown" || e.key === "ArrowUp") && e.target.closest(".rows, .search")) { + e.preventDefault(); + const rows = [...document.querySelectorAll(".rows a.row")]; + const i = rows.indexOf(e.target.closest(".row")); + rows[Math.max(0, Math.min(rows.length - 1, i + (e.key === "ArrowDown" ? 1 : -1)))]?.focus(); + } + }); + + // --- live: the server says when something was sent or read -------------------------------------------------------- + loading(); + from = route().key; + refresh().then(() => { + if (!D.me) return; + const stream = new EventSource("/api/stream"); + stream.onopen = () => { live(true); if (state.failed || $(".live").dataset.lost) refresh(); delete $(".live").dataset.lost; }; + stream.onerror = () => { live(false); $(".live").dataset.lost = "1"; }; + stream.addEventListener("changed", async () => { + const before = D.convs[0]?.last.sent_at; + await refresh(); + const newest = D.convs[0]; + if (newest && newest.last.sent_at !== before) $("#announce").textContent = `New message from ${label(newest.last.from)}${isGroup(newest.key) ? ` in ${label(newest.key)}` : ""}`; + }); + }); +})(); diff --git a/server/panel/peerbox.webp b/server/panel/peerbox.webp new file mode 100644 index 0000000..620f7cf Binary files /dev/null and b/server/panel/peerbox.webp differ diff --git a/server/panel/purify-LICENSE.txt b/server/panel/purify-LICENSE.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/server/panel/purify-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/panel/purify.js b/server/panel/purify.js new file mode 100644 index 0000000..54a70fe --- /dev/null +++ b/server/panel/purify.js @@ -0,0 +1,7 @@ +/*! @license DOMPurify 3.4.17 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.17/LICENSE */ +(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.DOMPurify=t())})(this,function(){"use strict";function e(e,t){this.v=e,this.k=t}function t(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n