Skip to content
WebJs
Menu

A short prompt you can send to the agent in one click.

import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { buttonClass } from '#components/ui/button.ts';
import {
  inputGroupClass, inputGroupAddonClass, inputGroupButtonClass, inputGroupTextareaClass,
} from '#components/ui/input-group.ts';
import { ArrowUpIcon, PlusIcon } from '#lib/ui/lucide.ts';

const suggestions = [
  'Add a dark mode toggle',
  'Fix the failing build',
  'Write tests for the form',
  'Upgrade to Next.js 16',
  'Add a loading state',
  'Find unused dependencies',
];

// Before anything is sent: the row of suggestions above an empty prompt
// field. Sending a suggestion is the app's to wire, as the AI SDK section
// below shows.
export default function SuggestionDemo() {
  return html`
    <div class="mx-auto flex w-full max-w-lg flex-col gap-6 py-6 text-sm">
      <div class="flex flex-col gap-2">
        <div class="flex scroll-fade-x scrollbar-none gap-2 overflow-x-auto overscroll-x-contain">
          ${suggestions.map((suggestion) => html`
            <button type="button" data-slot="button" data-variant="outline" data-size="sm" class=${cn(buttonClass({ variant: 'outline', size: 'sm' }), 'shrink-0')}>
              ${suggestion}
            </button>
          `)}
        </div>
        <form>
          <div data-slot="input-group" role="group" class=${inputGroupClass()}>
            <textarea data-slot="input-group-control" name="prompt" aria-label="Prompt" placeholder="Ask the agent to change your code..." class=${cn(inputGroupTextareaClass(), 'p-3')}></textarea>
            <div role="group" data-slot="input-group-addon" data-align="block-end" class=${inputGroupAddonClass({ align: 'block-end' })}>
              <button type="button" data-slot="input-group-button" data-variant="outline" data-size="icon-sm" aria-label="Attach files" class=${cn(inputGroupButtonClass({ size: 'icon-sm', variant: 'outline' }), 'rounded-full')}>
                ${PlusIcon()}
              </button>
              <button type="submit" data-slot="input-group-button" data-variant="default" data-size="icon-sm" aria-label="Send" disabled class=${cn(inputGroupButtonClass({ size: 'icon-sm', variant: 'default' }), 'ml-auto rounded-full')}>
                ${ArrowUpIcon()}
              </button>
            </div>
          </div>
        </form>
      </div>
    </div>
  `;
}
View Code

Suggestion is a prompt you send without typing. Each one is a Button with the prompt as its label. Put a row of them above the Prompt Input.

Installation

Suggestion is built with the Button component.

pnpm dlx @webjsdev/ui add button

Usage

import { buttonClass } from '#components/ui/button.ts';
<div class="scrollbar-none flex scroll-fade-x gap-2 overflow-x-auto overscroll-x-contain">
  ${suggestions.map((suggestion) => html`
    <button type="button" data-slot="button" data-variant="outline" data-size="sm"
      class=${cn(buttonClass({ variant: 'outline', size: 'sm' }), 'shrink-0')}
      @click=${() => this.send(suggestion)}>
      ${suggestion}
    </button>
  `)}
</div>

Scrolling

The row scrolls sideways when the suggestions do not fit. scroll-fade-x fades the edge that has more to show, and shrink-0 keeps each label on one line.

AI SDK

The label is the message. Send it as is, through the same method your chat component calls with the text the person typed.

@click=${() => this.sendMessage({ text: suggestion })}

sendMessage is your component's own method. See AI SDK for streaming the reply from a 'use server' action.

Migrating from AI SDK Elements

If you used Suggestion from AI SDK Elements, its wrapper lives in components/ai-elements/suggestion.tsx. In a WebJs app it becomes this pattern, built from WebJs UI components. Each export of the wrapper maps onto a part:

AI SDK ElementsWebJs UI
SuggestionsA <div> with class="flex scroll-fade-x scrollbar-none gap-2 overflow-x-auto overscroll-x-contain", instead of a ScrollArea.
SuggestionA button with buttonClass({ variant: 'outline', size: 'sm' }) and shrink-0, whose click handler sends the suggestion.