Skip to content

ui: list the attachments of every chat in the Library, each leading back to its message - #140

Draft
allozaur wants to merge 1 commit into
allozaur/feat/ui-library-promptsfrom
allozaur/feat/ui-library-attachments
Draft

allozaur wants to merge 1 commit into
allozaur/feat/ui-library-promptsfrom
allozaur/feat/ui-library-attachments

Conversation

@allozaur

@allozaur allozaur commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Overview

The Library gets an Attachments tab: the files of every chat in one grid. A click opens a file in the slideshow over all of them, and a right click leads back to the chat, at the message the file was sent in.

Additional information

Stacked on the Library and prompts PR (#139). Second of three Library PRs: a Skills tab (#141) follows on top. It takes the place of the Media mock-up in the old Library draft (#29).

Choices made here that are still open:

  • A file is an image, an audio clip, a video, a PDF or a text file. Prompts and MCP resources attached to a message are not listed.
  • Tool results count too: an image a tool returned is listed, and leads to the turn that called the tool.
  • Images and PDFs sent as images show as pictures, text files by their first lines, audio, video and other PDFs as an icon tile. There are no video frames or waveforms in the grid.
  • The search looks at file names only.
  • Besides "Go to conversation" the menu has "Download", and "Copy text" for a text file. Download is new: the app had none for a stored attachment.

Known gaps:

  • A jump to a file on a branch that is not the open one switches the chat to that branch, as the branch arrows do, and the chat stays on it.
  • Reading a page of files scans the messages from the newest down, since the messages table has no index on attachments. Fine for thousands of messages, not measured beyond.
  • A chat with system messages hidden still lists nothing for them: system messages hold no files.
  • The demo script below was run locally. No video is uploaded yet.
How it works
  • Reading lazily. Nothing is read until the tab opens. Then the messages that hold files are read 24 at a time, the newest first, and the next page loads as the end of the grid comes near. A search starts over from the newest message with the name filter applied in the database read. Leaving the tab drops what was read.
  • Grid. Files are dealt into columns in turn, as many as fit at 220px each and at least two. A page that loads later lands under the files already shown and moves none of them. Each tile names its file and its chat.
  • Slideshow. The existing attachment preview, given the files of the grid in the grid's order: arrows, the thumbnail strip and the keys work as they do in a chat.
  • Go to conversation. The tile names the conversation and the message to land on, and opens the chat's route. The chat screen then lands on that message in place of the bottom: it stops following the bottom and brings the message's row to the top of the view. The rows around it are placeholders until they come near, so the row is put back whenever the list changes size, before the frame is painted, until the sizes rest for a second. Any scroll, press or key from the reader ends the hold. A target meant for another conversation, or a message that is gone, lands at the bottom as usual.
What changed
  • DatabaseService.getMessagesHolding: messages a filter accepts, newest first, a page at a time, going on from a timestamp.
  • libraryAttachmentsStore: pages, search, no message listed twice (two messages can share a millisecond), a stale page dropped.
  • utils/library-attachments.ts: which extras are files, the files of a message, and what a file gives to draw, copy and save.
  • utils/message-jump.ts: the row that shows a message (its own, or its turn's for a tool result) and the scroll that holds it in view. chatStore.scrollTarget, StickToBottom.release(), and the landing in ChatScreen.
  • LibraryAttachments, LibraryAttachmentTile, and the Library page in tabs (Llama UI Tabs).
Testing

In ui/apps/chat, on the tip of this branch:

  • npm run check and npm run lint clean.
  • Unit tests pass, 20 of them new: the files of a message and what they give, the store (paging, messages of the same millisecond, search, a page that arrives after the tab closed, a failed read), and the row a jump lands on.
  • Client and Storybook tests pass, the client ones in batches of ten.
  • In the browser, with two chats written to the database (30 and 4 exchanges, seven files): the grid in five columns on a desktop and two on a phone, the slideshow opening at the clicked file and stepping through the others, the search, and "Go to conversation" for files in the 3rd, 10th and 25th of 30 exchanges, each landing on its message at the top of the view and staying there. Nothing is read before the tab opens. A file on the branch that was not open switched the chat to its branch and landed on its message.

Not run: the E2E suite, a production build, a download.

Demo script

Needs no model. It writes two chats with files to the app's database through the app's own service, which works against the dev server the demo harness records.

// A demo sends nothing to a model, so the two chats and their files are written straight to
// the app's database, through the app's own service on the dev server.
async function seedChats() {
	const { DatabaseService } = await import(
		/* @vite-ignore */ `${location.origin}/src/lib/services/database.service.ts`
	);

	function picture(width: number, height: number, hue: number, label: string): string {
		const canvas = document.createElement('canvas');

		canvas.width = width;
		canvas.height = height;

		const context = canvas.getContext('2d')!;
		const gradient = context.createLinearGradient(0, 0, width, height);

		gradient.addColorStop(0, `hsl(${hue} 70% 55%)`);
		gradient.addColorStop(1, `hsl(${(hue + 60) % 360} 70% 35%)`);
		context.fillStyle = gradient;
		context.fillRect(0, 0, width, height);
		context.fillStyle = 'white';
		context.font = 'bold 28px sans-serif';
		context.fillText(label, 20, 48);

		return canvas.toDataURL('image/png');
	}

	async function chat(name: string, turns: number, files: Record<number, object[]>) {
		const conversation = await DatabaseService.createConversation(name);

		let parent = await DatabaseService.createRootMessage(conversation.id);
		let timestamp = Date.now() - turns * 60000;

		for (let turn = 0; turn < turns; turn++) {
			const question = await DatabaseService.createMessageBranch(
				{
					children: [],
					content: `Question ${turn + 1} about ${name.toLowerCase()}`,
					convId: conversation.id,
					extra: files[turn],
					parent,
					role: 'user',
					timestamp: timestamp++,
					type: 'text'
				},
				parent
			);
			const answer = await DatabaseService.createMessageBranch(
				{
					children: [],
					content: `Answer ${turn + 1}.\n\n${'A few lines of explanation, so the chat is long. '.repeat(8)}`,
					convId: conversation.id,
					model: 'demo',
					parent: question.id,
					role: 'assistant',
					timestamp: timestamp++,
					type: 'text'
				},
				question.id
			);

			parent = answer.id;
		}
	}

	await chat('The trip to the Alps', 30, {
		2: [{ base64Url: picture(640, 420, 200, 'Alps map'), name: 'alps-map.png', type: 'IMAGE' }],
		9: [
			{
				content: 'Packing list\n- boots\n- rope\n- headlamp\n- stove\n- first aid kit',
				name: 'packing-list.txt',
				type: 'TEXT'
			},
			{ base64Url: picture(420, 640, 20, 'Route'), name: 'route-profile.png', type: 'IMAGE' }
		],
		24: [{ base64Url: picture(600, 600, 120, 'Summit'), name: 'summit.png', type: 'IMAGE' }]
	});
	await chat('The kitchen plan', 4, {
		0: [
			{ base64Url: picture(800, 360, 280, 'Floor plan'), name: 'floor-plan.png', type: 'IMAGE' },
			{
				content: '# Measurements\n\n| wall | cm |\n| --- | --- |\n| north | 412 |\n| east | 286 |',
				name: 'measurements.md',
				type: 'TEXT'
			}
		],
		3: [{ base64Url: picture(360, 480, 40, 'Tiles'), name: 'tiles.png', type: 'IMAGE' }]
	});
}

test('demo', async ({ demo, page }) => {
	await page.evaluate(seedChats);
	await page.reload();
	await page.getByRole('textbox', { name: 'Type a message...' }).waitFor();

	await demo.click(page.getByRole('button', { name: 'Expand navigation' }).first());
	await demo.click(page.getByRole('button', { name: 'Library' }));
	await demo.click(page.getByRole('tab', { name: 'Attachments' }));
	await expect(page.getByRole('button', { name: 'Open alps-map.png' })).toBeVisible();
	await demo.caption('The files of every chat, the newest first');

	await demo.click(page.getByRole('button', { name: 'Open floor-plan.png' }));
	await demo.caption('A click opens the slideshow over all of them');
	await demo.press('ArrowRight');
	await demo.press('ArrowRight');
	await demo.press('Escape');

	const map = page.getByRole('button', { name: 'Open alps-map.png' });

	await demo.hover(map);
	await map.click({ button: 'right' });
	await demo.caption('A right click leads back to where a file was sent');
	await demo.click(page.getByRole('menuitem', { name: 'Go to conversation' }));

	await expect(page.getByText('Question 3 about the trip to the alps')).toBeInViewport();
	await demo.caption('The chat opens at the message that holds the file');
	await demo.pause(1500);
});

Requirements

@allozaur
allozaur added this pull request to stack #138 November 26, 2026 15:13
@allozaur
allozaur force-pushed the allozaur/feat/ui-library-attachments branch 2 times, most recently from cafe2be to 67467b9 Compare November 26, 2026 15:23
@allozaur
allozaur force-pushed the allozaur/feat/ui-library-attachments branch 2 times, most recently from d9d0136 to 2c2e3fb Compare November 26, 2026 16:12
@allozaur
allozaur force-pushed the allozaur/feat/ui-library-attachments branch from 2c2e3fb to 40f4ba5 Compare November 26, 2026 16:19
@allozaur
allozaur force-pushed the allozaur/feat/ui-library-attachments branch from 40f4ba5 to 01ee0b5 Compare November 26, 2026 20:05
@allozaur
allozaur force-pushed the allozaur/feat/ui-library-attachments branch from 01ee0b5 to 2c83385 Compare November 27, 2026 08:51
@allozaur
allozaur force-pushed the allozaur/feat/ui-library-attachments branch from 2c83385 to 2a50b24 Compare November 27, 2026 09:04
…ack to its message

An Attachments tab reads the messages that hold files a page at a time and shows the files in a grid. A click opens the attachment preview as a slideshow over them. Go to conversation opens the chat and lands on the message that holds the file, in place of the bottom.

Assisted-by: Claude (Opus 5.5 Medium)
@allozaur
allozaur removed this pull request from stack #138 November 27, 2026 09:26
@allozaur
allozaur force-pushed the allozaur/feat/ui-library-attachments branch from 2a50b24 to e930a4e Compare November 27, 2026 09:26
@allozaur
allozaur added this pull request to stack #151 November 27, 2026 09:27

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant