← All proposals

Chat with an agent

A recipe, not a component: one interactive story that composes the existing proposals into a chat with an agent, from the empty state to a conversation.

Extends a PDS componentOpen in Storybook

proposals/ChatWithAgent/ChatWithAgent.mdx44 lines · View on GitHub
import { Canvas, Meta, Title } from '@storybook/addon-docs/blocks';

import * as ChatWithAgentStories from './ChatWithAgent.stories';

<Meta of={ChatWithAgentStories} name='Usage' />

<Title />

## Purpose

Shows a chat with an agent working end to end, from the empty state to a conversation, using the existing proposals.

## Usage

This is a recipe, not a component. It composes Chat Panel, Composer (with a primary Icon Button as Send and the bare Select as the model picker), Chat Message, Chain of Thought (Thinking State, Event Log and Event Log Item), Suggestion Card, Code Diff and Feedback Bar, plus the PDS Segmented Button, Status Indicator, Tag and Empty State.

- Start on the empty state with the default-size Composer in the same group as the heading. There is no footer yet.
- When the first message is sent, move the input to the footer as the compact bar and keep focus in it.
- Show the agent's work as a Chain of Thought: open while working, collapsed with "Thought for N seconds" when done, then the reply.
- End a reply that proposes changes with a Suggestion Card; show the changes as a Code Diff. After Accept, show the Feedback Bar in the card.
- Put the Feedback Bar under plain replies. Its thanks text replaces the thumbs for a few seconds, then the thumbs come back with the choice pressed; that timing belongs to the screen.
- Use the Composer's `aboveField` slot for context the next message applies to. In the sample, Refine on the Suggestion Card shows "Refining: 2 changes (composer.json, pantheon.yml)" above the input, with a dismiss button, and moves focus to the input. Send a note and the bar goes away; the agent replies with a narrowed Suggestion Card. Announce the bar to screen readers when it appears.
- Pass `onFilesDrop` to the Chat Panel to accept files dropped anywhere on it, and give the same handler to the Composer.
- Turn on `hasScrollToLatest` (with `scrollToLatestLabel`) and `hasContentFade` on the Chat Panel. The view stays at the end while the agent works, including while the chain of thought grows; scroll up to read earlier messages and it stops following, and a button at the bottom center jumps back to the latest.

Do not use this for a chat that needs a full-screen layout or a conversation history; the recipe covers the drawer only. For a single suggestion or a diff on its own, use the Suggestion Card or the Code diff recipe directly.

## Accessibility

- Keyboard: Enter sends and Shift+Enter adds a line. Every control is a native button, `details` or input from its component, so Tab reaches them in order.
- Focus: on the first send the input moves to the footer and keeps focus. Refine moves focus to the input. After Dismiss on a Suggestion Card, focus moves to Undo; after Undo, back to Dismiss.
- Labels: give the Chat Panel's close button a label (`closeButtonLabel`) or turn it off (`hasCloseButton={false}`); the Feedback Bar needs `groupLabel`, `upLabel` and `downLabel`; each attached file chip needs a `removeLabel`; the Scroll to latest button needs `scrollToLatestLabel`; the Composer's drop area needs `dropLabel`. Send, voice and Stop refining are icon-only, so each has an `ariaLabel`.
- Announced: the Refine context bar is announced through a visually hidden `role='status'` region ("Refining" followed by the suggestion title) that sits next to the Composer. The Feedback Bar's thanks text is its `statusLabel`, and a Suggestion Card announces its result line when it is accepted or dismissed.
- Chain of Thought is native `details`/`summary`; its label changes from "Working..." to "Thought for N seconds" when done.
- Not checked: the a11y panel has not been run, and light and dark have not been checked by eye.

## Implementation

The story is interactive. Type a message and press Enter, then accept the suggestion and rate a reply.

<hr />

<Canvas of={ChatWithAgentStories.Interactive} />