For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
FrakmentFrakment

Sources

Collect and render agent source citations as a collapsible trace list.

How do I start an Astro project with pnpm?

Run pnpm create astro@latest and follow the prompts. It scaffolds the project and installs the dependencies.

sources-demo.tsx
"use client";

import { useChat } from "@ai-sdk/react";
import type { UIMessage } from "ai";
import { ArrowUpRightIcon, GlobeIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
  Bubble,
  BubbleContent,
  Message,
  MessageContent,
} from "@/components/ui/message";
import {
  Trace,
  TraceCollapsible,
  TraceCollapsibleContent,
  TraceCollapsibleTrigger,
  TraceIcon,
  TraceLine,
  TraceTitle,
} from "@/components/ui/trace";
import { createChat, getMessageText } from "@/lib/ai";

const chat = createChat()
  .user("How do I start an Astro project with pnpm?")
  .assistant(({ writer }) => {
    writer.text(
      "Run pnpm create astro@latest and follow the prompts. It scaffolds the project and installs the dependencies."
    );
    writer.sourceUrl({
      title: "Install Astro | docs.astro.build",
      url: "https://docs.astro.build/en/install-and-setup/",
    });
    writer.sourceUrl({
      title: "create-astro | npmjs.com",
      url: "https://www.npmjs.com/package/create-astro",
    });
    writer.sourceUrl({
      title: "Install Astro | docs.astro.build",
      url: "https://docs.astro.build/en/install-and-setup/",
    });
    writer.sourceUrl({
      title: "pnpm create | pnpm.io",
      url: "https://pnpm.io/cli/create",
    });
  });

const transcript = chat.get();
const [question] = chat.get(1);
const transport = chat.transport({ delayMs: 20 });

type SourcePart = Extract<UIMessage["parts"][number], { type: "source-url" }>;

function Sources({ sources }: { sources: SourcePart[] }) {
  return (
    <Trace>
      <TraceCollapsible defaultOpen>
        <TraceCollapsibleTrigger>
          <TraceLine>
            <TraceIcon>
              <GlobeIcon />
            </TraceIcon>
            <TraceTitle>{`Used ${sources.length} sources`}</TraceTitle>
          </TraceLine>
        </TraceCollapsibleTrigger>
        <TraceCollapsibleContent>
          <Trace>
            {sources.map((source) => (
              <a
                className="decoration-muted-foreground block rounded-md underline-offset-4 hover:underline"
                href={source.url}
                key={source.url}
                rel="noreferrer"
                target="_blank"
              >
                <TraceLine>
                  <TraceTitle>
                    {source.title ?? new URL(source.url).hostname}
                    <span className="sr-only"> (opens in a new tab)</span>
                  </TraceTitle>
                  <TraceIcon>
                    <ArrowUpRightIcon />
                  </TraceIcon>
                </TraceLine>
              </a>
            ))}
          </Trace>
        </TraceCollapsibleContent>
      </TraceCollapsible>
    </Trace>
  );
}

export function SourcesDemo() {
  const { messages, sendMessage, setMessages, status } = useChat({
    messages: transcript,
    transport,
  });
  const busy = status === "submitted" || status === "streaming";

  return (
    <div className="flex min-h-72 w-full max-w-sm flex-col gap-4 py-6 text-sm">
      {messages.map((message) => {
        if (message.role === "user") {
          return (
            <Message align="end" key={message.id}>
              <MessageContent>
                <Bubble align="end" variant="muted">
                  <BubbleContent>{getMessageText(message)}</BubbleContent>
                </Bubble>
              </MessageContent>
            </Message>
          );
        }

        const sources = message.parts
          .filter((part) => part.type === "source-url")
          .filter(
            (part, index, all) =>
              all.findIndex((other) => other.url === part.url) === index
          );
        const text = getMessageText(message);

        return (
          <Message key={message.id}>
            <MessageContent className="gap-4">
              {text && <p>{text}</p>}
              {sources.length > 0 && <Sources sources={sources} />}
            </MessageContent>
          </Message>
        );
      })}
      {!busy && question && (
        <Button
          className="mt-auto self-start"
          onClick={() => {
            if (!question) {
              return;
            }
            setMessages([]);
            sendMessage(question);
          }}
          size="sm"
          variant="outline"
        >
          Replay
        </Button>
      )}
    </div>
  );
}

Sources collects every source-url part from an assistant message and renders them as a collapsible trace list. The header shows the count, duplicates are removed, and each row links to the original page.

Sources is a composition, not a primitive. It composes Trace and streams sources through a chat transport.

Installation

Usage

sources.tsx
import {
  Trace,
  TraceCollapsible,
  TraceCollapsibleContent,
  TraceCollapsibleTrigger,
  TraceIcon,
  TraceLine,
  TraceTitle,
} from "@/components/ui/trace";
import { ArrowUpRightIcon, GlobeIcon } from "lucide-react";
sources.tsx
<Trace>
  <TraceCollapsible defaultOpen>
    <TraceCollapsibleTrigger>
      <TraceLine>
        <TraceIcon>
          <GlobeIcon />
        </TraceIcon>
        <TraceTitle>{`Used ${sources.length} sources`}</TraceTitle>
      </TraceLine>
    </TraceCollapsibleTrigger>
    <TraceCollapsibleContent>
      <Trace>
        {sources.map((source) => (
          <a key={source.url} href={source.url} target="_blank" rel="noreferrer" className="block">
            <TraceLine>
              <TraceTitle>{source.title ?? source.url}</TraceTitle>
              <TraceIcon>
                <ArrowUpRightIcon />
              </TraceIcon>
            </TraceLine>
          </a>
        ))}
      </Trace>
    </TraceCollapsibleContent>
  </TraceCollapsible>
</Trace>

Anatomy

sources.tsx
<Trace>
  <TraceCollapsible>
    <TraceCollapsibleTrigger>
      <TraceLine>
        <TraceIcon />
        <TraceTitle />
      </TraceLine>
    </TraceCollapsibleTrigger>
    <TraceCollapsibleContent>
      <Trace>
        <a>
          <TraceLine>
            <TraceTitle />
            <TraceIcon />
          </TraceLine>
        </a>
      </Trace>
    </TraceCollapsibleContent>
  </TraceCollapsible>
</Trace>
  • Trace — wrapper for the source list
  • TraceCollapsible — the header + body block
  • TraceCollapsibleTrigger — "Used N sources" row with a globe icon
  • TraceCollapsibleContent — the nested Trace with one anchor per source
  • TraceLine — a single source row, title on the left, external-link icon on the right

Deduplication

Assistants often cite the same URL twice. Filter duplicate URLs before rendering so the list stays short:

sources.tsx
const sources = message.parts
  .filter((part) => part.type === "source-url")
  .filter(
    (part, index, all) =>
      all.findIndex((other) => other.url === part.url) === index
  );

The demo streams four sources, one of which is a duplicate. The header shows the deduplicated count.

Static list

Render a fixed list without a chat transport for a read-only summary.

sources-static.tsx
import { ArrowUpRightIcon, GlobeIcon } from "lucide-react";

import {
  Trace,
  TraceCollapsible,
  TraceCollapsibleContent,
  TraceCollapsibleTrigger,
  TraceIcon,
  TraceLine,
  TraceTitle,
} from "@/components/ui/trace";

const sources = [
  {
    title: "Install Astro | docs.astro.build",
    url: "https://docs.astro.build/en/install-and-setup/",
  },
  {
    title: "create-astro | npmjs.com",
    url: "https://www.npmjs.com/package/create-astro",
  },
  {
    title: "pnpm create | pnpm.io",
    url: "https://pnpm.io/cli/create",
  },
];

export function SourcesStatic() {
  return (
    <Trace className="max-w-sm">
      <TraceCollapsible defaultOpen>
        <TraceCollapsibleTrigger>
          <TraceLine>
            <TraceIcon>
              <GlobeIcon />
            </TraceIcon>
            <TraceTitle>{`Used ${sources.length} sources`}</TraceTitle>
          </TraceLine>
        </TraceCollapsibleTrigger>
        <TraceCollapsibleContent>
          <Trace>
            {sources.map((source) => (
              <a
                className="decoration-muted-foreground block rounded-md underline-offset-4 hover:underline"
                href={source.url}
                key={source.url}
                rel="noreferrer"
                target="_blank"
              >
                <TraceLine>
                  <TraceTitle>
                    {source.title}
                    <span className="sr-only"> (opens in a new tab)</span>
                  </TraceTitle>
                  <TraceIcon>
                    <ArrowUpRightIcon />
                  </TraceIcon>
                </TraceLine>
              </a>
            ))}
          </Trace>
        </TraceCollapsibleContent>
      </TraceCollapsible>
    </Trace>
  );
}

Accessibility

  • Each source is an <a> with target="_blank" and rel="noreferrer". Add sr-only text to announce the new tab.
  • The external-link icon is decorative. The title carries the meaning.
  • The collapsible trigger is keyboard-focusable and toggles with Enter or Space.

Best Practices

  • Place sources after the answer. The text is the answer, the sources are the evidence.
  • Deduplicate by URL. Repeated citations waste space and confuse the count.
  • Fall back to the hostname. When the title is missing, show new URL(source.url).hostname.
  • Collapse on long lists. More than five sources crowds the transcript.