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

chadtmiller.com/hud

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

0
0
67 lines · 2.7 KB Raw History
<script lang="ts">
	import { ErrorMessage, Tree, type ActionHandler, type PlayerHost, type UiInteractionHandler, type UiPaging, type UiReport, type UiShown, type UiToolHandler, type UiUploadHandler } from '@hud/renderer';
	import type { Call, Entry } from './result';

	// One tool result, drawn as HUD's apps draw it: the view the server
	// resolved (`_meta.ui`) by `Tree`, a failure by
	// `ErrorMessage`. What opens from it, and what writes, is the app's to
	// do: the MCP App view pushes it on its back stack, the workspace puts
	// it in a tile of its own. A tree's calls go to `oncall`, with the feed
	// item each was opened from; a tab's to `onreplace`, which draws it in
	// place of this result; its `oninteraction` and `onseen` hear of
	// its items as their reports (`UiReport`). A tree that asks for its
	// page more in its own place (`ownsPaging`) is given `paging`, and
	// `onreload` makes its call again in its place. A tree's forms call
	// tools through `ontool` and upload pictures through `onupload`, where
	// the app can.
	let {
		entry,
		oncall,
		onreplace,
		onaction,
		onopenlink,
		oninteraction,
		onseen,
		onpopout,
		onretry,
		player,
		playerOrigin,
		paging,
		onreload,
		ontool,
		onupload,
		shown
	}: {
		entry: Entry;
		/** A tree's call opened, with the feed item it was opened from when its feed is told. */
		oncall: (call: Call, report: UiReport | null) => void;
		/** A tab chosen: its call drawn in place of this result, never beside it. */
		onreplace?: (call: Call) => void;
		onaction: ActionHandler;
		onopenlink: (url: string) => void;
		oninteraction?: UiInteractionHandler;
		onseen?: (report: UiReport) => void;
		onpopout?: () => void;
		onretry?: (call: Call) => void;
		/** The app's player host, and where this result's music comes from (see Tree). */
		player?: PlayerHost;
		playerOrigin?: unknown;
		/** A page more, for a tree that draws its own (`ownsPaging`). */
		paging?: UiPaging | null;
		/** Make the entry's call again and draw what it answers in its place. */
		onreload?: () => Promise<void>;
		/** One of HUD's tools, called as the account, for a tree's form. */
		ontool?: UiToolHandler;
		/** A picture uploaded as the account, for a tree's form; none where the app cannot. */
		onupload?: UiUploadHandler;
		/** What the app shows above it (a tile's header), not said again. */
		shown?: UiShown | null;
	} = $props();
</script>

{#if entry.view.renderer === 'tree'}
	<Tree ui={entry.view.ui} {oncall} {onreplace} {onopenlink} {onaction} {oninteraction} {onseen} {player} {playerOrigin} {onpopout} {paging} {onreload} {ontool} {onupload} {shown} />
{:else}
	{@const call = entry.call}
	<ErrorMessage message={entry.view.message} onretry={call && onretry ? () => onretry(call) : undefined} />
{/if}