# Web research

> Watch the agent search: the query types in, page icons stack up as it reads, then it folds into a trail of searches and the pages each one found.

A spinner during web search hides the most reassuring part: what the agent is actually reading. "Searching" carries a sweep of light next to the live query as it types in, then morphs to "Reading" as the page count rolls up. Each page drops its icon into an overlapping stack, pushing the oldest to fold away, and its title rises in underneath while the last one lifts off. When the work is done, the same line rearranges itself into "3 searches · 9 sources": counts roll, words morph, the title row folds shut and a chevron opens in. It opens into the queries and every page, each a link.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/web-research.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/web-research
- Registry item (source): https://hairlineui.com/r/web-research.json

## Usage

```tsx
import { WebResearch } from "@/components/web-research";

<WebResearch status="reading" queries={["annual plan discount benchmarks"]} sources={[{ url, title }]} />
```

## With the AI SDK

```tsx
// Server: a search tool (any provider: Exa, Tavily, your own index)
const searchWeb = tool({
  description: "Search the web",
  inputSchema: z.object({ query: z.string() }),
  execute: async ({ query }) => (await search(query)).map((r) => ({ url: r.url, title: r.title })),
});

// Client: read the run straight from the message parts
import type { UIMessage } from "ai";
import { WebResearch } from "@/components/web-research";

function Research({ message, streaming }: { message: UIMessage; streaming: boolean }) {
  const calls = message.parts.filter((p) => p.type === "tool-searchWeb");
  if (!calls.length) return null;
  const queries = calls.map((p) => p.input?.query).filter(Boolean);
  const sources = calls.flatMap((p) => (p.state === "output-available" ? p.output : []));
  const searching = calls.some((p) => p.state === "input-streaming" || p.state === "input-available");
  const failed = calls.some((p) => p.state === "output-error");
  const answering = message.parts.some((p) => p.type === "text" && p.text);
  const status = failed ? "error" : searching ? "searching" : streaming && !answering ? "reading" : "done";
  return <WebResearch status={status} queries={queries} sources={sources} />;
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `status` | `"searching" \| "reading" \| "done" \| "error" \| "cancelled"` | – | Where the run is. |
| `queries` | `(string \| ResearchQuery)[]` | – | Searches so far; the last one types in while searching. As { text, site?, siteIcon?, results?, resultLabel? } a search shows its site’s mark and its count on the trail. |
| `sources` | `{ url; title?; favicon?; query? }[]` | – | Pages read, in order. Without a favicon, a monogram tinted from the site name; query (the index of the search that found it) groups it on the trail. |
| `open / defaultOpen / onOpenChange` | `boolean / boolean / (open) => void` | – | Whether the finished run shows its list. |

## States

- **searching**: A 1.4s sweep of light crosses "Searching" and the newest query opens in after it, typing as it goes.
- **reading**: The label morphs to "Reading" and "7 sites" rolls. Each page’s icon drops into the stack (four shown; the oldest folds away over 420ms and +N rolls) and its title rises out of a 4px blur as the last one lifts off.
- **done**: The same line rearranges into "3 searches · 9 sources": pieces open and fold over 460ms, counts roll, "sites" morphs to "sources", the title row folds shut and a chevron opens in. It opens into the queries and the page list.
- **error**: The label morphs to "Search failed" in red, still counting and listing anything found before it failed.
- **cancelled**: "Stopped after 2 searches", with what was found.
- **trail**: Opened, each search is a row on a hairline trail with its count ("12 threads"). A search on one site wears that site’s mark and reads "Searched Threadly for …" with the query in mono. Pages that say which search found them sit under it as up to five overlapping marks on a branch; the chevron folds them open into links (380ms). Pages without a search are listed after the trail.

## What it handles

A spinner during web search hides the most reassuring part: what the agent is actually reading. This shows it as it happens, and keeps the trail afterwards.

- **The search types in**: “Searching” carries a sweep of light next to the live query as it types.
- **Pages stack up as they are read**: Each page drops its icon into an overlapping stack and its title rises in. The label becomes “Reading” and the site count rolls.
- **It folds into a summary**: The same line rearranges into “3 searches · 9 sources”, with a chevron that opens the full list.
- **A trail of searches**: Each search is a row with its result count, and pages that say which search found them sit under it.
- **Every source is a link**: Pages open in a new tab, so people can check what the agent read.
- **Failed and stopped runs**: It reads “Search failed” or “Stopped after 2 searches”, and still lists anything found before.

## Replaces

a search status line, a stack of favicons, a source list, a search trail, a count summary

## Where it fits

- **AI search and answer tools**: Show the pages being read while an answer is prepared.
- **Deep research agents**: The searches an agent ran and the sources it read, kept after it finishes.
- **Support and docs assistants**: Show which pages were searched before the assistant replied.
- **Market and competitor research**: A trail of searches per site, with each result a link.

## Notes

- A polite status region beside the row reads "Searching for …", "Read 6 sites", then the finished summary. The counts and words are real text for screen readers; the rolling digits are hidden from them.
- The row is one button from start to finish, disabled while the agent works, so nothing remounts and every piece can morph. Once done it has aria-expanded; the list is hidden from assistive tech and the tab order while folded.
- The sweep of light is a moving mask, so it also covers letters that are mid-morph. Installs Number roll and Text morph alongside it.
- Every source is a real link that opens in a new tab, so people can check the agent’s reading.
- With reduced motion the query appears whole, there is no sweep, nothing rolls or slides, and the list opens instantly.

License: MIT (https://hairlineui.com/license#components)
