chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.3.1 Latest 5 packages
0
0
// A page as the server draws it: the tab its URL opens under, the calls of
// that tab's stack (its root's, and the screen the URL names over it, if
// it is not the root), and what they answered, for the browser to draw
// the same from as it hydrates. The screen on top is answered before the
// page is sent, so its HTML holds it, and the frame's aside with it; the
// root under it, which does not show, streams after (server.ts's `under`).
import { read, type Call, type Entry, type ToolResult } from '@hud/shared/result';
import type { Measure } from './app';
/** What a call answered: its result; that it needs an account; or why it could not be made. */
export type Answer = { result: ToolResult } | { signIn: true } | { failed: string };
export type Screen = {
tab: number;
/** The calls of the tab's stack, its root's first; none where its root needs an account. */
calls: Call[];
/** What the last of `calls` answered; under a story's URL, what the story viewer's page answered. */
top: Answer | null;
/** A story's URL: the story viewer over the stack, its one page the story's screen. */
pager?: { calls: Call[]; at: number };
/** What the frame's aside answered, where it has one. */
aside?: Answer | null;
/** The accounts' handles the server learnt from them, by DID (routes.ts's `Names`), so links are drawn the same in the browser. */
names: [string, string][];
/** No route has the URL's path: the page says so, over no tab. */
missing: boolean;
/** Each tab's root as the server chose it for the page (app.ts's `rootsOf`), so the browser's tabs open the same; none where the page draws no tab (not found, signing in). */
roots?: (Call | null)[];
/** How wide its root level is drawn where the screen is in a tab's root's place by that root's strip (`swappedTab`): the root's own measure, not the screen's. */
measure?: Measure;
/** The app's own sign-in screen, over no tab: where signing in comes back to (`back`), the handle typed, and why the last try did not sign in, if it did not. */
signIn?: SignInState;
};
/** What the sign-in screen is drawn with. */
export type SignInState = { back: string; handle: string; error: string | null };
/** A result as a page carries it: what its view is drawn from and its account (`_meta`), its words only where it failed; its answer's data, which the page does not draw, left out. */
export function carried(result: ToolResult): ToolResult {
return result.isError ? { isError: true, content: result.content } : { _meta: result._meta };
}
/** What a stack's level draws for an answer to its call. */
export function entryOf(call: Call, answer: Answer): { entry: Entry; signIn: boolean } {
if ('result' in answer) return { entry: { view: read(answer.result), call }, signIn: false };
const message = 'signIn' in answer ? 'Sign in to see this.' : answer.failed;
return { entry: { view: { renderer: 'error', message }, call }, signIn: 'signIn' in answer };
}