Sources

The Sources component allows a user to view the sources or citations used to generate a response.

Installation

pnpm dlx shadcn-svelte@latest add https://svelte-ai-elements.vercel.app/r/sources.json

If you prefer using jsrepo, please install via the command below:

pnpm dlx jsrepo add @ai/elements/ai-elements/sources

Usage

Usage with AI SDK

Build a simple web search agent with Perplexity Sonar and display the sources used to generate the response.

Add the following component to your frontend:

+page.svelte

Add the following route to your backend:

api/chat/+server.ts

Features

  • Collapsible component that allows a user to view the sources or citations used to generate a response
  • Customizable trigger and content components
  • Support for custom sources or citations
  • Responsive design with mobile-friendly controls
  • Clean, modern styling with customizable themes

Props

Sources

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the sources container
childrenSnippet-Child components (typically SourcesTrigger and SourcesContent)
...restPropsCollapsibleProps-All other Collapsible component props are supported

SourcesTrigger

PropTypeDefaultDescription
countnumber-Number of sources to display in the trigger text
classstring-Additional CSS classes to apply to the trigger button
childrenSnippet-Custom content to render instead of the default trigger text
...restPropsCollapsibleTriggerProps-All other CollapsibleTrigger component props are supported

SourcesContent

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the content container
childrenSnippet-Source components to display when expanded
...restPropsCollapsibleContentProps-All other CollapsibleContent component props are supported

Source

PropTypeDefaultDescription
hrefstring-URL of the source (opens in new tab)
titlestring-Title/name of the source to display
classstring-Additional CSS classes to apply to the source link
childrenSnippet-Custom content to render instead of the default icon and title
...restPropsHTMLAnchorAttributes-All other anchor element props are supported