~ 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
97 lines · 4.4 KB Raw History
// The launcher's apps: the queries bundled views offer (their `launch`),
// which a search finds, listed under their app (unsearched, it shows the
// person's apps and feeds). Picking one turns the launcher into that
// query's tile, its params the person's. The world's
// accounts are on no knotless appview, so this holds the tile to its call
// (getCanvas), not its drawing; and it takes the tile off again, leaving
// carol's canvas as the flows after it find it. Your own profile across
// your apps opens from the launcher's account, and from a tile's "You".

import { expect, signIn, test, who } from './pages.mjs';

test('a launcher row of an app opens its query as a tile, as the person', async ({ browser }) => {
	const context = await browser.newContext();
	const page = await context.newPage();
	await signIn(page, 'carol');
	const launcher = page.getByRole('main', { name: 'Columns' }).getByRole('region', { name: 'Open' });
	await expect(launcher.getByRole('heading', { name: 'Your apps' })).toBeVisible();
	// Search finds it, under its app.
	await launcher.getByRole('searchbox').fill('repositories');
	await expect(launcher.getByRole('heading', { name: 'knotless' })).toBeVisible();
	await launcher.getByRole('option', { name: /Repositories/ }).click();
	await expect(launcher).toHaveCount(0);
	const xrpc = (method, params) =>
		page.evaluate(
			async ([method, params]) => (await fetch(`/xrpc/place.hud.${method}?${new URLSearchParams(params)}`)).json(),
			[method, params]
		);
	const ws = await xrpc('getWorkspace', {});
	const canvas = await xrpc('getCanvas', { canvas: ws.current });
	const tiles = canvas.tiles.map((t) => ({
		key: t.key,
		tool: t.record.tool,
		arguments: t.record.arguments ?? (t.record.argumentsJson ? JSON.parse(t.record.argumentsJson) : undefined)
	}));
	const made = tiles.find((t) => t.arguments?.method === 'dev.knotless.getActorRepos');
	expect(made?.tool).toBe('query');
	expect(made.arguments).toEqual({
		method: 'dev.knotless.getActorRepos',
		params: { actor: who.carol.did },
		service: 'did:web:knotless.dev#knotless_appview'
	});
	await page.evaluate(
		async ([canvas, tile]) =>
			fetch('/xrpc/place.hud.removeTile', {
				method: 'POST',
				headers: { 'Content-Type': 'application/json', 'X-HUD': '1' },
				body: JSON.stringify({ canvas, tile })
			}),
		[ws.current, made.key]
	);
	await context.close();
});

test('your own profile opens from the launcher’s account and from a tile’s You', async ({ browser }) => {
	const context = await browser.newContext();
	const page = await context.newPage();
	await signIn(page, 'carol');
	const xrpc = (method, params) =>
		page.evaluate(
			async ([method, params]) => (await fetch(`/xrpc/place.hud.${method}?${new URLSearchParams(params)}`)).json(),
			[method, params]
		);
	const post = (method, body) =>
		page.evaluate(
			async ([method, body]) =>
				(
					await fetch(`/xrpc/place.hud.${method}`, {
						method: 'POST',
						headers: { 'Content-Type': 'application/json', 'X-HUD': '1' },
						body: JSON.stringify(body)
					})
				).json(),
			[method, body]
		);
	const { current } = await xrpc('getWorkspace', {});
	/** The canvas's profiles of carol: their keys. */
	const profiles = async () =>
		(await xrpc('getCanvas', { canvas: current })).tiles
			.filter((t) => t.record.tool === 'describe_repo' && (t.record.arguments ?? JSON.parse(t.record.argumentsJson ?? '{}')).actor === who.carol.did)
			.map((t) => t.key);

	const launcher = page.getByRole('main', { name: 'Columns' }).getByRole('region', { name: 'Open' });
	await launcher.getByTitle('Your profile across your apps').click();
	await expect(launcher).toHaveCount(0);
	await expect.poll(profiles).toHaveLength(1);
	await post('removeTile', { canvas: current, tile: (await profiles())[0] });

	// A tile of carol's own says "You", which opens her profile beside it.
	const added = await post('addTile', { canvas: current, tool: 'list_records', arguments: { actor: who.carol.did, collection: 'app.bsky.actor.profile' }, title: 'Her profile record' });
	const records = page.locator(`[data-tile="${added.tile.key}"]`);
	await records.getByRole('button', { name: 'You', exact: true }).click();
	await expect.poll(profiles).toHaveLength(1);
	await expect(page.locator(`[data-tile="${(await profiles())[0]}"]`)).toBeVisible();

	for (const tile of [added.tile.key, ...(await profiles())]) await post('removeTile', { canvas: current, tile });
	await context.close();
});