Skip to content

Commit ed8603c

Browse files
committed
feat: add new AI tool components and functionalities
- create tool-input-available.tsx for image generation tool input UI - create tool-input-streaming.tsx for web search tool input UI - create tool-output-available.tsx to display available output from database queries - create tool-output-error.tsx to handle and display errors from API requests - implement tool.tsx to manage various tool states including approval and output handling - add transcription.tsx for audio transcription functionality with segment display - introduce voice-selector.tsx for selecting and previewing different voice options - implement web-preview.tsx for displaying web content with navigation and console logging
1 parent e363d81 commit ed8603c

263 files changed

Lines changed: 29564 additions & 43 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.agent/README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,35 @@ For the division of responsibilities and usage patterns between rule files and w
5454
The following files are available for both Windsurf (`.windsurf/rules/`) and Antigravity (`.agent/rules/`).
5555

5656
- `commit-message-format.md`
57-
- **Role**: Defines the commit message format (prefix, summary, bullet-list body) and prohibited patterns.
58-
- **Characteristics**: Based on Conventional Commits, with additional guidelines such as `language`-based language selection and diff-based message generation.
57+
- **Role**: Defines the commit message format (prefix, summary, bullet-list body) and prohibited patterns.
58+
- **Characteristics**: Based on Conventional Commits, with additional guidelines such as `language`-based language selection and diff-based message generation.
5959

6060
- `pr-message-format.md`
61-
- **Role**: Defines the format for PR titles and bodies (prefix-style titles and structured sections such as Overview, Changes, Tests) and prohibited patterns.
62-
- **Characteristics**: Aligns PR messages with the commit message conventions and encourages structured descriptions that facilitate review and understanding of change intent.
61+
- **Role**: Defines the format for PR titles and bodies (prefix-style titles and structured sections such as Overview, Changes, Tests) and prohibited patterns.
62+
- **Characteristics**: Aligns PR messages with the commit message conventions and encourages structured descriptions that facilitate review and understanding of change intent.
6363

6464
- `test-strategy.md`
65-
- **Role**: Defines test strategy rules for test implementation and maintenance, including equivalence partitioning, boundary value analysis, and coverage requirements.
66-
- **Purpose**: Serves as a quality guardrail by requiring corresponding automated tests whenever meaningful changes are made to production code, where reasonably feasible.
65+
- **Role**: Defines test strategy rules for test implementation and maintenance, including equivalence partitioning, boundary value analysis, and coverage requirements.
66+
- **Purpose**: Serves as a quality guardrail by requiring corresponding automated tests whenever meaningful changes are made to production code, where reasonably feasible.
6767

6868
- `prompt-injection-guard.md`
69-
- **Role**: Defines defense rules against **context injection attacks from external sources (RAG, web, files, API responses, etc.)**.
70-
- **Contents**: Describes guardrails such as restrictions on executing commands originating from external data, the Instruction Quarantine mechanism, the `SECURITY_ALERT` format, and detection of user impersonation attempts.
71-
- **Characteristics**: Does not restrict the user's own direct instructions; only malicious commands injected via external sources are neutralized.
72-
- **Note**: This file has `trigger: always_on` set in its metadata, but users can still control when these rules are applied via the editor's UI settings. See the [operational guide](doc/prompt-injection-guard.md) for details on handling false positives.
69+
- **Role**: Defines defense rules against **context injection attacks from external sources (RAG, web, files, API responses, etc.)**.
70+
- **Contents**: Describes guardrails such as restrictions on executing commands originating from external data, the Instruction Quarantine mechanism, the `SECURITY_ALERT` format, and detection of user impersonation attempts.
71+
- **Characteristics**: Does not restrict the user's own direct instructions; only malicious commands injected via external sources are neutralized.
72+
- **Note**: This file has `trigger: always_on` set in its metadata, but users can still control when these rules are applied via the editor's UI settings. See the [operational guide](doc/prompt-injection-guard.md) for details on handling false positives.
7373

7474
- `planning-mode-guard.md` **(Antigravity only)**
75-
- **Role**: A guardrail to prevent problematic behaviors in Antigravity's Planning Mode.
76-
- **Issues addressed**:
77-
- Transitioning to the implementation phase without user instruction
78-
- Responding in English even when instructed in another language (e.g., Japanese)
79-
- **Contents**: In Planning Mode, only analysis and planning are performed; file modifications and command execution are prevented without explicit user approval. Also encourages responses in the user's preferred language.
80-
- **Characteristics**: Placed only in `.agent/rules/`; not used in Windsurf.
75+
- **Role**: A guardrail to prevent problematic behaviors in Antigravity's Planning Mode.
76+
- **Issues addressed**:
77+
- Transitioning to the implementation phase without user instruction
78+
- Responding in English even when instructed in another language (e.g., Japanese)
79+
- **Contents**: In Planning Mode, only analysis and planning are performed; file modifications and command execution are prevented without explicit user approval. Also encourages responses in the user's preferred language.
80+
- **Characteristics**: Placed only in `.agent/rules/`; not used in Windsurf.
8181

8282
- `doc/custom_instruction_plan_prompt_injection.md`
83-
- **Role**: Design and threat analysis document for external context injection defense.
84-
- **Contents**: Organizes attack categories (A-01–A-09) via external sources, corresponding defense requirements (R-01–R-08), design principles for the external data control layer, and validation/operations planning.
85-
- **Update**: Fully revised in November 2024 to focus on external-source attacks.
83+
- **Role**: Design and threat analysis document for external context injection defense.
84+
- **Contents**: Organizes attack categories (A-01–A-09) via external sources, corresponding defense requirements (R-01–R-08), design principles for the external data control layer, and validation/operations planning.
85+
- **Update**: Fully revised in November 2024 to focus on external-source attacks.
8686

8787
## Translation Guide
8888

.agent/skills/ai-elements/SKILL.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
---
2+
name: ai-elements
3+
description: Create new AI chat interface components for the ai-elements library following established composable patterns, shadcn/ui integration, and Vercel AI SDK conventions. Use when creating new components in packages/elements/src or when the user asks to add a new component to ai-elements.
4+
---
5+
6+
# AI Elements
7+
8+
[AI Elements](https://www.npmjs.com/package/ai-elements) is a component library and custom registry built on top of [shadcn/ui](https://ui.shadcn.com/) to help you build AI-native applications faster. It provides pre-built components like conversations, messages and more.
9+
10+
Installing AI Elements is straightforward and can be done in a couple of ways. You can use the dedicated CLI command for the fastest setup, or integrate via the standard shadcn/ui CLI if you've already adopted shadcn's workflow.
11+
12+
13+
14+
## Quick Start
15+
16+
Here are some basic examples of what you can achieve using components from AI Elements.
17+
18+
19+
20+
## Prerequisites
21+
22+
Before installing AI Elements, make sure your environment meets the following requirements:
23+
24+
- [Node.js](https://nodejs.org/en/download/), version 18 or later
25+
- A [Next.js](https://nextjs.org/) project with the [AI SDK](https://ai-sdk.dev/) installed.
26+
- [shadcn/ui](https://ui.shadcn.com/) installed in your project. If you don't have it installed, running any install command will automatically install it for you.
27+
- We also highly recommend using the [AI Gateway](https://vercel.com/docs/ai-gateway) and adding `AI_GATEWAY_API_KEY` to your `env.local` so you don't have to use an API key from every provider. AI Gateway also gives $5 in usage per month so you can experiment with models. You can obtain an API key [here](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys&title=Get%20your%20AI%20Gateway%20key).
28+
29+
30+
31+
## Installing Components
32+
33+
You can install AI Elements components using either the AI Elements CLI or the shadcn/ui CLI. Both achieve the same result: adding the selected component’s code and any needed dependencies to your project.
34+
35+
The CLI will download the component’s code and integrate it into your project’s directory (usually under your components folder). By default, AI Elements components are added to the `@/components/ai-elements/` directory (or whatever folder you’ve configured in your shadcn components settings).
36+
37+
After running the command, you should see a confirmation in your terminal that the files were added. You can then proceed to use the component in your code.
38+
39+
## Usage
40+
41+
Once an AI Elements component is installed, you can import it and use it in your application like any other React component. The components are added as part of your codebase (not hidden in a library), so the usage feels very natural.
42+
43+
## Example
44+
45+
After installing AI Elements components, you can use them in your application like any other React component. For example:
46+
47+
```tsx title="conversation.tsx"
48+
"use client";
49+
50+
import {
51+
Message,
52+
MessageContent,
53+
MessageResponse,
54+
} from "@/components/ai-elements/message";
55+
import { useChat } from "@ai-sdk/react";
56+
57+
const Example = () => {
58+
const { messages } = useChat();
59+
60+
return (
61+
<>
62+
{messages.map(({ role, parts }, index) => (
63+
<Message from={role} key={index}>
64+
<MessageContent>
65+
{parts.map((part, i) => {
66+
switch (part.type) {
67+
case "text":
68+
return (
69+
<MessageResponse key={`${role}-${i}`}>
70+
{part.text}
71+
</MessageResponse>
72+
);
73+
}
74+
})}
75+
</MessageContent>
76+
</Message>
77+
))}
78+
</>
79+
);
80+
};
81+
82+
export default Example;
83+
```
84+
85+
In the example above, we import the `Message` component from our AI Elements directory and include it in our JSX. Then, we compose the component with the `MessageContent` and `MessageResponse` subcomponents. You can style or configure the component just as you would if you wrote it yourself – since the code lives in your project, you can even open the component file to see how it works or make custom modifications.
86+
87+
## Extensibility
88+
89+
All AI Elements components take as many primitive attributes as possible. For example, the `Message` component extends `HTMLAttributes<HTMLDivElement>`, so you can pass any props that a `div` supports. This makes it easy to extend the component with your own styles or functionality.
90+
91+
## Customization
92+
93+
94+
95+
After installation, no additional setup is needed. The component’s styles (Tailwind CSS classes) and scripts are already integrated. You can start interacting with the component in your app immediately.
96+
97+
For example, if you'd like to remove the rounding on `Message`, you can go to `components/ai-elements/message.tsx` and remove `rounded-lg` as follows:
98+
99+
```tsx title="components/ai-elements/message.tsx" highlight="8"
100+
export const MessageContent = ({
101+
children,
102+
className,
103+
...props
104+
}: MessageContentProps) => (
105+
<div
106+
className={cn(
107+
"flex flex-col gap-2 text-sm text-foreground",
108+
"group-[.is-user]:bg-primary group-[.is-user]:text-primary-foreground group-[.is-user]:px-4 group-[.is-user]:py-3",
109+
className
110+
)}
111+
{...props}
112+
>
113+
<div className="is-user:dark">{children}</div>
114+
</div>
115+
);
116+
```
117+
118+
## Troubleshooting
119+
120+
## Why are my components not styled?
121+
122+
Make sure your project is configured correctly for shadcn/ui in Tailwind 4 - this means having a `globals.css` file that imports Tailwind and includes the shadcn/ui base styles.
123+
124+
## I ran the AI Elements CLI but nothing was added to my project
125+
126+
Double-check that:
127+
128+
- Your current working directory is the root of your project (where `package.json` lives).
129+
- Your components.json file (if using shadcn-style config) is set up correctly.
130+
- You’re using the latest version of the AI Elements CLI:
131+
132+
```bash title="Terminal"
133+
npx ai-elements@latest
134+
```
135+
136+
If all else fails, feel free to open an [issue on GitHub](https://github.com/vercel/ai-elements/issues).
137+
138+
## Theme switching doesn’t work — my app stays in light mode
139+
140+
Ensure your app is using the same data-theme system that shadcn/ui and AI Elements expect. The default implementation toggles a data-theme attribute on the `<html>` element. Make sure your tailwind.config.js is using class or data- selectors accordingly:
141+
142+
## The component imports fail with “module not found”
143+
144+
Check the file exists. If it does, make sure your `tsconfig.json` has a proper paths alias for `@/` i.e.
145+
146+
```json title="tsconfig.json"
147+
{
148+
"compilerOptions": {
149+
"baseUrl": ".",
150+
"paths": {
151+
"@/*": ["./*"]
152+
}
153+
}
154+
}
155+
```
156+
157+
## My AI coding assistant can't access AI Elements components
158+
159+
1. Verify your config file syntax is valid JSON.
160+
2. Check that the file path is correct for your AI tool.
161+
3. Restart your coding assistant after making changes.
162+
4. Ensure you have a stable internet connection.
163+
164+
## Still stuck?
165+
166+
If none of these answers help, open an [issue on GitHub](https://github.com/vercel/ai-elements/issues) and someone will be happy to assist.
167+
168+
## Available Components
169+
170+
See the `references/` folder for detailed documentation on each component.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Agent
2+
3+
A composable component for displaying AI agent configuration with model, instructions, tools, and output schema.
4+
5+
The `Agent` component displays an interface for showing AI agent configuration details. It's designed to represent a configured agent from the AI SDK, showing the agent's model, system instructions, available tools (with expandable input schemas), and output schema.
6+
7+
See `scripts/agent.tsx` for this example.
8+
9+
## Installation
10+
11+
```bash
12+
npx ai-elements@latest add agent
13+
```
14+
15+
## Usage with AI SDK
16+
17+
Display an agent's configuration alongside your chat interface. Tools are displayed in an accordion where clicking the description expands to show the input schema.
18+
19+
```tsx title="app/page.tsx"
20+
"use client";
21+
22+
import { tool } from "ai";
23+
import { z } from "zod";
24+
import {
25+
Agent,
26+
AgentContent,
27+
AgentHeader,
28+
AgentInstructions,
29+
AgentOutput,
30+
AgentTool,
31+
AgentTools,
32+
} from "@/components/ai-elements/agent";
33+
34+
const webSearch = tool({
35+
description: "Search the web for information",
36+
inputSchema: z.object({
37+
query: z.string().describe("The search query"),
38+
}),
39+
});
40+
41+
const readUrl = tool({
42+
description: "Read and parse content from a URL",
43+
inputSchema: z.object({
44+
url: z.string().url().describe("The URL to read"),
45+
}),
46+
});
47+
48+
const outputSchema = `z.object({
49+
sentiment: z.enum(['positive', 'negative', 'neutral']),
50+
score: z.number(),
51+
summary: z.string(),
52+
})`;
53+
54+
export default function Page() {
55+
return (
56+
<Agent>
57+
<AgentHeader
58+
name="Sentiment Analyzer"
59+
model="anthropic/claude-sonnet-4-5"
60+
/>
61+
<AgentContent>
62+
<AgentInstructions>
63+
Analyze the sentiment of the provided text and return a structured
64+
analysis with sentiment classification, confidence score, and summary.
65+
</AgentInstructions>
66+
<AgentTools>
67+
<AgentTool tool={webSearch} value="web_search" />
68+
<AgentTool tool={readUrl} value="read_url" />
69+
</AgentTools>
70+
<AgentOutput schema={outputSchema} />
71+
</AgentContent>
72+
</Agent>
73+
);
74+
}
75+
```
76+
77+
## Features
78+
79+
- Model badge in header
80+
- Instructions rendered as markdown
81+
- Tools displayed as accordion items with expandable input schemas
82+
- Output schema display with syntax highlighting
83+
- Composable structure for flexible layouts
84+
- Works with AI SDK `Tool` type
85+
86+
## Props
87+
88+
### `<Agent />`
89+
90+
| Prop | Type | Default | Description |
91+
|------|------|---------|-------------|
92+
| `...props` | `React.ComponentProps<` | - | Any props are spread to the root div. |
93+
94+
### `<AgentHeader />`
95+
96+
| Prop | Type | Default | Description |
97+
|------|------|---------|-------------|
98+
| `name` | `string` | Required | The name of the agent. |
99+
| `model` | `string` | - | The model identifier (e.g. |
100+
| `...props` | `React.ComponentProps<` | - | Any other props are spread to the container div. |
101+
102+
### `<AgentContent />`
103+
104+
| Prop | Type | Default | Description |
105+
|------|------|---------|-------------|
106+
| `...props` | `React.ComponentProps<` | - | Any other props are spread to the container div. |
107+
108+
### `<AgentInstructions />`
109+
110+
| Prop | Type | Default | Description |
111+
|------|------|---------|-------------|
112+
| `children` | `string` | Required | The instruction text. |
113+
| `...props` | `React.ComponentProps<` | - | Any other props are spread to the container div. |
114+
115+
### `<AgentTools />`
116+
117+
| Prop | Type | Default | Description |
118+
|------|------|---------|-------------|
119+
| `...props` | `React.ComponentProps<typeof Accordion>` | - | Any other props are spread to the Accordion component. |
120+
121+
### `<AgentTool />`
122+
123+
| Prop | Type | Default | Description |
124+
|------|------|---------|-------------|
125+
| `tool` | `Tool` | Required | The tool object from the AI SDK containing description and inputSchema. |
126+
| `value` | `string` | Required | Unique identifier for the accordion item. |
127+
| `...props` | `React.ComponentProps<typeof AccordionItem>` | - | Any other props are spread to the AccordionItem component. |
128+
129+
### `<AgentOutput />`
130+
131+
| Prop | Type | Default | Description |
132+
|------|------|---------|-------------|
133+
| `schema` | `string` | Required | The output schema as a string (displayed with syntax highlighting). |
134+
| `...props` | `React.ComponentProps<` | - | Any other props are spread to the container div. |

0 commit comments

Comments
 (0)