dash: as iterate/private's template has it at 3de3de7d
Misha Kaletsky, 2026-11-25 15:18 UTC · 2907dfdce2d50ce4c6324ae9975aab0a966721f9 · parent cce6153
6 files changed
- A agent-catalog.ts
- A framed-sign-in.ts
- M index.html
- M public/app.css
- M public/app.js
- M public/mcp-page.js
A agent-catalog.ts
@@ -0,0 +1,36 @@ +// agent-catalog.ts — WHICH CONTEXT IS AN AGENT: the catalog on /agents, read in one call, and the +// test of one path against it. api.ts `taskDeps` uses both, since a follower's row writes +// to the path it names. +// @ts-expect-error -- a plain browser module of the Dash, with no types; this file uses `agentPathOf` alone +import { agentPathOf } from "./public/share-links.js"; + +/** Whether `path` is an agent in the catalog on /agents (its live state `{ agents: { [path]: row } }`): + * a row that said what runs it or what it is called. A row with neither is a folder + * (@iterate-com/ui lib/agent-summary.ts `folderTest`), and the root and any path outside /agents/ + * are refused before (`agentPathOf`). */ +export function isAgentOf(catalog: unknown, path: string): boolean { + if (!agentPathOf(path)) return false; + // the catalog's live state is `unknown` to its reader: iterate/agents writes `agents` as a map + // from a path to its row, and a state of any other shape has no row for the path + const agents = ( + catalog as { agents?: Record<string, { kind?: string; title?: string } | null> } | null + )?.agents; + const row = agents && Object.hasOwn(agents, path) ? agents[path] : null; + return Boolean(row && (row.kind || row.title)); +} + +/** What `agentCatalogOf` reaches of the mind: the catalog's facet on /agents. */ +export type CatalogItx = { + cd(path: string): { + facets: { get(name: string): { liveSnapshot(): Promise<{ state: unknown }> } }; + }; +}; + +/** The catalog on /agents (its live state), or null. It touches /agents alone. */ +export async function agentCatalogOf(itx: CatalogItx): Promise<unknown> { + try { + return (await itx.cd("/agents").facets.get("agents").liveSnapshot()).state; + } catch { + return null; + } +}
A framed-sign-in.ts
@@ -0,0 +1,39 @@ +// framed-sign-in.ts — what the Dash's host answers a signed-out request that comes from a frame. +// worker.ts wraps the member guard's answer with it, on the Dash's host alone. + +/** A SIGNED-OUT REQUEST FOR THE DASH IN A FRAME (another app of the mind shows an agent's chat in + * one: the Tasks app's "Chat with …", `?embed=1`). Each host of the mind has a session of its + * own, and the platform signs a person in on a host only for a page load of the whole tab + * (`sec-fetch-dest: document`): a frame gets the guard's plain 401, the words "Sign in" with no + * link, and a person cannot go on from there. `refused` is the guard's answer, or null for a + * member. For a frame's GET this answers the SAME refusal, the same status and challenge, with + * words that say what to do: open the Dash once in a tab of its own, where the platform signs + * the person in, and come back; the frame then loads again by itself. Nobody is signed in here, + * and nothing of the mind is shown: the page names this host alone. Any other request gets the + * guard's answer as it is. */ +export function framedSignIn(request: Request, refused: Response | null): Response | null { + if ( + !refused || + refused.status !== 401 || + request.method !== "GET" || + request.headers.get("sec-fetch-dest") !== "iframe" + ) + return refused; + const headers = new Headers(refused.headers); + headers.set("content-type", "text/html; charset=utf-8"); + headers.set("cache-control", "no-store"); + const dash = `${new URL(request.url).origin}/`; + return new Response( + `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Sign in to the Dash</title> +<style>body{margin:0;padding:1.5rem;font:14px/1.5 system-ui,sans-serif;color:#18181b;background:#fff}@media (prefers-color-scheme:dark){body{color:#fafafa;background:#09090b}a{color:#fafafa}}p{margin:0 0 .75rem;max-width:34rem}</style> +<p><strong>This browser is not signed in to the Dash yet.</strong></p> +<p><a href="${dash}" target="_blank" rel="noopener">Open the Dash</a> once in a tab of its own. Then come back: this chat loads by itself.</p> +<script> + // back from the Dash's own tab: the session is there now, so load the frame again + addEventListener("visibilitychange", () => { if (document.visibilityState === "visible") location.reload(); }); + addEventListener("focus", () => location.reload()); +</script> +`, + { status: 401, headers }, + ); +}
M index.html
@@ -12,11 +12,11 @@ <script type="importmap"> { "imports": { - "@iterate-com/ui/": "https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T154040Z-83b4390/", - "react": "https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T154040Z-83b4390/react", - "react/": "https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T154040Z-83b4390/react/", - "react-dom": "https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T154040Z-83b4390/react-dom", - "react-dom/": "https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T154040Z-83b4390/react-dom/", + "@iterate-com/ui/": "https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T221123Z-9ecb4a7/", + "react": "https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T221123Z-9ecb4a7/react", + "react/": "https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T221123Z-9ecb4a7/react/", + "react-dom": "https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T221123Z-9ecb4a7/react-dom", + "react-dom/": "https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T221123Z-9ecb4a7/react-dom/", "lucide-react": "https://esm.iterate.com/lucide-react@1.48.0?external=react,react-dom" } } @@ -39,23 +39,29 @@ <!-- THE FRAME'S SHAPE, said before the first paint. The body draws the app's frame from HTML and app.css alone, in the places the shell will draw it, so nothing moves when the app takes over. These lines decide what the shell decides: the sidebar as the person left it - (the cookie `sidebar_state`, which the shell writes at each toggle), and whether the - page is an agent's, which has a header row. A first arrival at the onboarding agent, with - no choice stored, starts with the sidebar as a rail of icons, so the chat has the room: - app.js hands the Dash the same choice. `data-frame` on the root element tells the - components that the person's wait began with this frame. --> + (the cookie `sidebar_state`, which the shell writes at each toggle), or an explicit + `#sidebar=collapsed` / `?sidebar=collapsed` (or `open`) in the URL when no choice is + stored, and whether the page is an agent's, which has a header row. app.js hands the Dash + the same default. `data-frame` on the root element tells the components that the person's + wait began with this frame. --> <script> { const query = new URLSearchParams(location.search); + const hash = new URLSearchParams(location.hash.replace(/^#/, "")); + const sidebarParam = hash.get("sidebar") || query.get("sidebar"); const agent = location.pathname.startsWith("/agents/") ? location.pathname.slice("/agents".length) : location.pathname === "/agents" ? query.get("contextPath") : null; const left = /(?:^|; )sidebar_state=(true|false)/.exec(document.cookie)?.[1]; - const open = left ? left === "true" : agent !== "/agents/onboarding"; + const open = left ? left === "true" : sidebarParam !== "collapsed"; document.documentElement.dataset.sidebar = open ? "open" : "collapsed"; if (agent) document.documentElement.dataset.page = "agent"; + // `?embed=1`: the page is shown in a frame of another app of the mind (the Tasks app shows + // an agent's chat in a sheet). The frame is narrow, so the shell draws no sidebar; its + // button is hidden too (public/app.css). The page is the same Dash, for the same member. + if (query.get("embed") === "1") document.documentElement.dataset.embed = ""; } </script> <!-- The stylesheet at the address the build serves it from: the shorter one answers with a @@ -63,7 +69,7 @@ <link rel="stylesheet" crossorigin - href="https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T154040Z-83b4390/dist/styles.css" + href="https://esm.iterate.com/@iterate-com/ui@0.1.0-main.20261124T221123Z-9ecb4a7/dist/styles.css" /> <!-- The look of this mind's apps: apps/theme.css, one file for every app. One line there makes them all dark. shadcn's components also ask for the class `dark`, so the script
M public/app.css
@@ -321,3 +321,11 @@ padding: 1rem 1rem 0; } } + +/* An embedded view (index.html, `?embed=1`): no button for a sidebar that the frame has no room for. */ +[data-embed] [data-slot="sidebar-trigger"], +[data-embed] [data-slot="sidebar"], +[data-embed] [data-slot="sidebar-gap"], +[data-embed] .frame-sidebar { + display: none; +}
M public/app.js
@@ -227,8 +227,9 @@ // Personal items inside the account popover above Sign out. const accountLinks = [{ name: "Your sessions", href: `${stack}/sessions`, icon: HistoryIcon }]; -// The sidebar for a person who has not toggled it yet: as index.html drew it in its frame (open, -// or the rail of icons for a first arrival at the onboarding agent). A choice they made wins. +// The sidebar for a person who has not toggled it yet: as index.html drew it in its frame (open +// by default, or collapsed when `#sidebar=collapsed` / `?sidebar=collapsed` is in the URL). A +// choice they made wins. const sidebarDefaultOpen = document.documentElement.dataset.sidebar !== "collapsed"; // The mind's name and icon, as its owner wrote them (profile.ts, the folder profile/ of the
M public/mcp-page.js
@@ -1,7 +1,6 @@ // mcp-page.js — THE DASH'S MCP PAGE: how to connect coding agents (Claude Code, Codex, Claude) -// to this mind over MCP. Shows both the platform endpoint (`https://<mind>/mcp`, which stays up -// even if userspace code breaks the web UI) and the customizable userspace endpoint -// (`https://mcp.<zone>/mcp`, served by apps/mcp/ in /repos/config). +// to this mind over MCP. Shows the platform endpoint (`https://<mind>/mcp`), which stays up +// even if userspace code breaks the web UI. import { html } from "@iterate-com/ui/page"; import { CopyText } from "@iterate-com/ui/components/copy-text"; import { @@ -60,12 +59,8 @@ } export function DashMcp({ mind }) { - const zone = location.hostname.split(".").slice(1).join("."); const platformServer = `https://${mind}/mcp`; const platformName = mind.replaceAll(".", "-"); - const userspaceHost = `mcp.${zone}`; - const userspaceServer = `https://${userspaceHost}/mcp`; - const userspaceName = userspaceHost.replaceAll(".", "-"); return html` <div className="min-h-0 flex-1 overflow-y-auto"> @@ -90,12 +85,6 @@ description="Served directly by the platform — keeps working even if userspace code breaks the Dash or another web app." server=${platformServer} name=${platformName} - /> - <${EndpointSection} - title="Userspace MCP (customizable)" - description="Served by apps/mcp/ in /repos/config, so you can customize the instructions and run tool description your coding agents see." - server=${userspaceServer} - name=${userspaceName} /> </div> </div>