oneie 3.6.7 → 3.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/agent-backend.md +83 -0
- package/.claude/agents/agent-designer.md +97 -0
- package/.claude/agents/agent-director.md +118 -7
- package/.claude/agents/agent-documenter.md +93 -0
- package/.claude/agents/agent-frontend.md +96 -0
- package/.claude/agents/agent-ops.md +182 -25
- package/.claude/agents/agent-problem-solver.md +166 -0
- package/.claude/agents/agent-quality.md +127 -0
- package/.claude/commands/build.md +293 -0
- package/.claude/commands/cascade.md +231 -127
- package/.claude/commands/mcp-toggle.md +93 -0
- package/.claude/commands/one.md +198 -116
- package/.claude/commands/plan.md +394 -80
- package/.claude/commands/release.md +41 -19
- package/.claude/commands/server.md +2 -0
- package/.claude/hooks/root-cleanup.py +75 -0
- package/.claude/skills/INDEX.md +523 -0
- package/.claude/skills/REGISTRY.md +529 -0
- package/.claude/skills/agent-backend-create-mutation.md +319 -0
- package/.claude/skills/agent-designer-create-wireframe.md +341 -0
- package/.claude/skills/agent-frontend-create-page.md +413 -0
- package/.claude/skills/agents/README.md +238 -0
- package/dist/clone-web.js +1 -1
- package/dist/clone-web.js.map +1 -1
- package/folders.yaml +1 -1
- package/one/.obsidian/workspace.json +38 -38
- package/one/connections/api/queries-reference.md +842 -0
- package/one/connections/api-reference.md +1011 -0
- package/one/connections/integration-examples.md +875 -0
- package/one/connections/integration-guide.md +869 -0
- package/one/connections/integration-phase2.md +736 -0
- package/one/events/API_ROUTES_FIXES_SUMMARY.md +262 -0
- package/one/events/ASTRO-INTEGRATION-EXAMPLES.md +636 -0
- package/one/events/BEFORE_AFTER_COMPARISON.md +960 -0
- package/one/events/CONNECTIONS_DEMO.md +501 -0
- package/one/events/DELIVERABLES.md +432 -0
- package/one/events/DEMO-GROUPS-PAGE.md +392 -0
- package/one/events/DEMO-TESTING-SUMMARY.md +518 -0
- package/one/events/DEMO_COMPONENTS.md +487 -0
- package/one/events/DEMO_HOOKS_INDEX.md +334 -0
- package/one/events/DEMO_INFRASTRUCTURE.md +905 -0
- package/one/events/DEMO_INFRASTRUCTURE_SUMMARY.md +570 -0
- package/one/events/DEMO_INTEGRATION_CHECKLIST.md +431 -0
- package/one/events/DEMO_QUICK_REFERENCE.md +441 -0
- package/one/events/DEMO_SETUP.md +476 -0
- package/one/events/EFFECT_TS_API_PATTERN.md +478 -0
- package/one/events/GROUPS_DEMO_IMPLEMENTATION.md +414 -0
- package/one/events/HOOKS-DEMO.md +441 -0
- package/one/events/ONTOLOGY-HOOKS-README.md +700 -0
- package/one/events/ONTOLOGY-INTEGRATION-MANIFEST.md +365 -0
- package/one/events/QA-CHECKLIST.md +674 -0
- package/one/events/QUICK-START-ONTOLOGY.md +408 -0
- package/one/events/SEARCH_DEMO_CODE_REFERENCE.md +639 -0
- package/one/events/SEARCH_DEMO_DELIVERY.md +415 -0
- package/one/events/SEARCH_DEMO_SUMMARY.md +303 -0
- package/one/events/SEARCH_DEMO_VISUAL_GUIDE.md +381 -0
- package/one/events/TEST-PLAN-INDEX.md +346 -0
- package/one/events/TEST-PLAN.md +1417 -0
- package/one/events/TESTING-DELIVERY.txt +372 -0
- package/one/events/TRANSITIONS-QUICK-START.md +141 -0
- package/one/events/TYPESCRIPT_FIXES.md +152 -0
- package/one/events/TYPESCRIPT_FIXES_COMPLETE.txt +412 -0
- package/one/events/TYPESCRIPT_FIXES_INDEX.md +341 -0
- package/one/events/VIEW-TRANSITIONS.md +428 -0
- package/one/events/backend-integration-tests.md +606 -0
- package/one/events/backend-structure-diagram.txt +393 -0
- package/one/events/backend-structure-summary.txt +269 -0
- package/one/events/cloudflare-pages-infrastructure-setup.md +264 -0
- package/one/events/convex-analysis-index.md +304 -0
- package/one/events/convex-structure-analysis.md +700 -0
- package/one/events/design-spec-complete.md +208 -0
- package/one/events/ontology-test-examples.md +562 -0
- package/one/events/phase1-backend-implementation-complete.md +518 -0
- package/one/events/test-dashboard.md +345 -0
- package/one/events/test-index.md +361 -0
- package/one/events/test-report-ontology.md +582 -0
- package/one/events/testing-summary.md +344 -0
- package/one/groups/features.md +2878 -0
- package/one/groups/strategy copy.md +869 -0
- package/one/knowledge/backend-api-reference.md +710 -0
- package/one/knowledge/documentation-summary.md +285 -0
- package/one/knowledge/lessons-learned.md +294 -4
- package/one/knowledge/ontology-visual-guide.md +360 -0
- package/one/knowledge/ontology.md +9 -17
- package/one/things/demo-accessibility-animations.md +999 -0
- package/one/things/demo-components.md +1304 -0
- package/one/things/demo-design-summary.md +629 -0
- package/one/things/demo-design-system.md +919 -0
- package/one/things/demo-page-layouts.md +989 -0
- package/one/things/designs/accessibility-audit.md +790 -0
- package/one/things/designs/component-specifications.md +757 -0
- package/one/things/designs/design-overview.md +318 -0
- package/one/things/designs/design-tokens.md +414 -0
- package/one/things/designs/wireframes-dashboard.md +653 -0
- package/one/things/docs/api-requests.md +923 -0
- package/one/things/features/0 All Features.md +2 -0
- package/one/things/implementation/backend-guide.md +412 -0
- package/one/things/plans/2-backend-agnostic-frontend.md +11 -8
- package/one/things/plans/ai-elements.md +1259 -0
- package/one/things/plans/ai-integration.md +947 -0
- package/one/things/plans/ai-sdk.md +761 -0
- package/one/things/plans/app.md +1 -1
- package/one/things/plans/architecture-summary.md +283 -0
- package/one/things/plans/async-ai-agents.md +215 -0
- package/one/things/plans/backend-agnostic-frontend.md +11 -6
- package/one/things/plans/backend-cleanup-quickstart.md +346 -0
- package/one/things/plans/backend-ontology-conformance.md +416 -0
- package/one/things/plans/backend-status.md +541 -0
- package/one/things/plans/backend-structure.md +799 -0
- package/one/things/plans/backend-target-structure.md +438 -0
- package/one/things/plans/backend.md +1133 -0
- package/one/things/plans/better-auth-any-backend.md +11 -11
- package/one/things/plans/cli-updates-required.md +280 -0
- package/one/things/plans/complete-step-by-step.md +1302 -0
- package/one/things/plans/convex-agents.md +1005 -0
- package/one/things/plans/deployment-architecture.md +426 -0
- package/one/things/plans/development-plan.md +1220 -0
- package/one/things/plans/effect.md +808 -48
- package/one/things/plans/integrate-frontend-and-backend.md +579 -0
- package/one/things/plans/mcp-clear-context-prompt.md +60 -0
- package/one/things/plans/mcp-simple.md +228 -0
- package/one/things/plans/one.md +8 -7
- package/one/things/plans/ontology-6-dimensions.md +20 -14
- package/one/things/plans/quick-wins.md +1273 -0
- package/one/things/plans/readme-backend-cleanup.md +361 -0
- package/one/things/plans/separate-demo.md +830 -0
- package/one/things/plans/separate.md +3 -3
- package/one/things/plans/sequence.md +1897 -0
- package/one/things/plans/sync-checklist.md +321 -0
- package/one/things/plans/unified-implementation-plan.md +3 -3
- package/one/things/plans/update-demos.md +513 -0
- package/package.json +1 -1
- package/.claude/agents/backend-specialist.md +0 -169
- package/.claude/agents/designer.md +0 -216
- package/.claude/agents/frontend-specialist.md +0 -236
- package/.claude/commands/done.md +0 -35
- package/.claude/commands/infer.md +0 -138
- package/.claude/commands/next.md +0 -53
- package/.claude/commands/one copy.md +0 -565
- package/.claude/commands/one-template.md +0 -106
- package/.claude/commands/one-v1.md +0 -609
- package/.claude/hooks/__pycache__/knowledge-post.cpython-313.pyc +0 -0
- package/.claude/hooks/__pycache__/knowledge-pre.cpython-313.pyc +0 -0
- package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
- package/one/groups/nine-padel-customers.md +0 -138
- package/one/groups/nine-padel-data-structure.md +0 -167
- package/one/groups/nine-padel-ontology-specification.md +0 -359
- package/one/groups/nine-padel-ontology.md +0 -143
- package/one/groups/nine-padel-strategy.md +0 -234
- package/one/groups/nine-padel.md +0 -211
- package/one/groups/nine-padle-contents.baked.md +0 -1252
- package/one/groups/nine-padle-contents.md +0 -6
- package/one/things/features/1-1-agent-prompts/design.md +0 -470
- package/one/things/features/1-1-agent-prompts/tests.md +0 -264
- package/one/things/features/1-2-yaml-orchestrator/design.md +0 -497
- package/one/things/features/1-2-yaml-orchestrator/tests.md +0 -227
- package/one/things/features/1-3-event-coordination/design.md +0 -544
- package/one/things/features/1-3-event-coordination/tests.md +0 -223
- package/one/things/features/1-4-knowledge-management/design.md +0 -609
- package/one/things/features/1-4-knowledge-management/tests.md +0 -195
- package/one/things/features/1-5-quality-loops/design.md +0 -797
- package/one/things/features/1-5-quality-loops/tests.md +0 -212
- package/one/things/features/1-6-numbering-structure/design.md +0 -610
- package/one/things/features/1-6-numbering-structure/tests.md +0 -213
- package/one/things/features/dataprovider-interface/1-tests.md +0 -1522
|
@@ -0,0 +1,1259 @@
|
|
|
1
|
+
# AI Elements Implementation Plan
|
|
2
|
+
|
|
3
|
+
**Version:** 1.0.0
|
|
4
|
+
**Status:** Planning
|
|
5
|
+
**Integration:** AI SDK + Convex Agents
|
|
6
|
+
**Target Platform:** Astro 5 + React 19 + shadcn/ui
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
**AI Elements** is a component library for building AI-powered interfaces. It provides 30+ pre-built components for:
|
|
13
|
+
|
|
14
|
+
- Chat interfaces (Chatbot, Message, Response, etc.)
|
|
15
|
+
- Content display (Code Block, Image, Sources, Artifact, Web Preview)
|
|
16
|
+
- Advanced AI features (Chain of Thought, Reasoning, Task, etc.)
|
|
17
|
+
- Canvas/workflow components (Node, Edge, Connection, Panel, etc.)
|
|
18
|
+
|
|
19
|
+
### Why AI Elements?
|
|
20
|
+
|
|
21
|
+
- **Pre-built**: 30+ production-ready components
|
|
22
|
+
- **Accessible**: WCAG compliant, keyboard navigation
|
|
23
|
+
- **Themeable**: Customize colors, spacing, typography
|
|
24
|
+
- **Type-safe**: Full TypeScript support
|
|
25
|
+
- **Composable**: Mix and match components
|
|
26
|
+
- **Tested**: Proven in production AI apps
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Installation & Setup (Infer 1-10)
|
|
31
|
+
|
|
32
|
+
### Prerequisites
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Ensure you have Node.js 18+
|
|
36
|
+
node --version # v18+
|
|
37
|
+
|
|
38
|
+
# Ensure shadcn/ui is installed in your project
|
|
39
|
+
npx shadcn-ui@latest init
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Install AI Elements
|
|
43
|
+
|
|
44
|
+
**Option 1: Using AI Elements CLI (Recommended)**
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx ai-elements@latest init
|
|
48
|
+
# Prompts you to select which components to install
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Option 2: Using shadcn/ui CLI**
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx shadcn-ui@latest add ai-elements
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Option 3: Manual Installation**
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install @ai-elements/core @ai-elements/ui
|
|
61
|
+
npm install ai @ai-sdk/openai
|
|
62
|
+
npm install zod
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Verify Installation
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Check components are in place
|
|
69
|
+
ls src/components/ui/ai-elements/
|
|
70
|
+
|
|
71
|
+
# Should see:
|
|
72
|
+
# - chatbot.tsx
|
|
73
|
+
# - message.tsx
|
|
74
|
+
# - response.tsx
|
|
75
|
+
# - suggestion.tsx
|
|
76
|
+
# - tool.tsx
|
|
77
|
+
# - code-block.tsx
|
|
78
|
+
# - artifact.tsx
|
|
79
|
+
# - and more...
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Environment Setup
|
|
83
|
+
|
|
84
|
+
**web/.env.local:**
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
PUBLIC_CONVEX_URL=https://shocking-falcon-870.convex.cloud
|
|
88
|
+
CONVEX_DEPLOYMENT=prod:shocking-falcon-870
|
|
89
|
+
OPENAI_API_KEY=sk-...
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Components Library (Infer 11-30)
|
|
95
|
+
|
|
96
|
+
### Core Chat Components
|
|
97
|
+
|
|
98
|
+
#### 1. Chatbot Component
|
|
99
|
+
|
|
100
|
+
The main container for chat interactions.
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// src/components/features/AIChat/Chatbot.tsx
|
|
104
|
+
import { Chatbot } from "@/components/ui/ai-elements/chatbot";
|
|
105
|
+
|
|
106
|
+
export function MyChatbot() {
|
|
107
|
+
return (
|
|
108
|
+
<Chatbot
|
|
109
|
+
id="my-chatbot"
|
|
110
|
+
messages={[]}
|
|
111
|
+
input=""
|
|
112
|
+
isLoading={false}
|
|
113
|
+
onInputChange={(value) => {}}
|
|
114
|
+
onSubmit={(value) => {}}
|
|
115
|
+
onMessageClick={(message) => {}}
|
|
116
|
+
onSuggestionsClick={(suggestion) => {}}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### 2. Message Component
|
|
123
|
+
|
|
124
|
+
Individual message display.
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { Message } from "@/components/ui/ai-elements/message";
|
|
128
|
+
|
|
129
|
+
<Message
|
|
130
|
+
role="user"
|
|
131
|
+
content="What is the weather?"
|
|
132
|
+
timestamp={new Date()}
|
|
133
|
+
isLoading={false}
|
|
134
|
+
metadata={{
|
|
135
|
+
source: "chat",
|
|
136
|
+
tokens: 45,
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### 3. Response Component
|
|
142
|
+
|
|
143
|
+
AI response with optional metadata.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { Response } from "@/components/ui/ai-elements/response";
|
|
147
|
+
|
|
148
|
+
<Response
|
|
149
|
+
content="The weather is sunny."
|
|
150
|
+
role="assistant"
|
|
151
|
+
timestamp={new Date()}
|
|
152
|
+
actions={[
|
|
153
|
+
{ label: "Copy", onClick: () => {} },
|
|
154
|
+
{ label: "Edit", onClick: () => {} },
|
|
155
|
+
]}
|
|
156
|
+
/>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### 4. Suggestion Component
|
|
160
|
+
|
|
161
|
+
Suggested follow-up questions.
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { Suggestion } from "@/components/ui/ai-elements/suggestion";
|
|
165
|
+
|
|
166
|
+
<Suggestion
|
|
167
|
+
suggestions={[
|
|
168
|
+
"Tell me more",
|
|
169
|
+
"How does this work?",
|
|
170
|
+
"Give me an example",
|
|
171
|
+
]}
|
|
172
|
+
onSuggestionClick={(suggestion) => {}}
|
|
173
|
+
/>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### 5. Prompt Input Component
|
|
177
|
+
|
|
178
|
+
Input field for user messages.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { PromptInput } from "@/components/ui/ai-elements/prompt-input";
|
|
182
|
+
|
|
183
|
+
<PromptInput
|
|
184
|
+
value={input}
|
|
185
|
+
onChange={(value) => setInput(value)}
|
|
186
|
+
onSubmit={(value) => sendMessage(value)}
|
|
187
|
+
isLoading={isLoading}
|
|
188
|
+
placeholder="Ask me anything..."
|
|
189
|
+
maxCharacters={1000}
|
|
190
|
+
allowedMimeTypes={["text/plain", "application/pdf"]}
|
|
191
|
+
/>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### Content Display Components
|
|
197
|
+
|
|
198
|
+
#### 6. Code Block Component
|
|
199
|
+
|
|
200
|
+
Displays code with syntax highlighting.
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { CodeBlock } from "@/components/ui/ai-elements/code-block";
|
|
204
|
+
|
|
205
|
+
<CodeBlock
|
|
206
|
+
code={`function hello() {
|
|
207
|
+
console.log("world");
|
|
208
|
+
}`}
|
|
209
|
+
language="javascript"
|
|
210
|
+
showLineNumbers={true}
|
|
211
|
+
allowCopy={true}
|
|
212
|
+
theme="dark"
|
|
213
|
+
onCopy={() => navigator.clipboard.writeText(code)}
|
|
214
|
+
/>
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
#### 7. Image Component
|
|
218
|
+
|
|
219
|
+
Displays images with captions.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { Image } from "@/components/ui/ai-elements/image";
|
|
223
|
+
|
|
224
|
+
<Image
|
|
225
|
+
src="https://example.com/image.jpg"
|
|
226
|
+
alt="Example"
|
|
227
|
+
caption="Generated image"
|
|
228
|
+
width={400}
|
|
229
|
+
height={300}
|
|
230
|
+
allowDownload={true}
|
|
231
|
+
/>
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### 8. Artifact Component
|
|
235
|
+
|
|
236
|
+
Displays rich content (code, HTML, React components).
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { Artifact } from "@/components/ui/ai-elements/artifact";
|
|
240
|
+
|
|
241
|
+
<Artifact
|
|
242
|
+
type="code"
|
|
243
|
+
content={`<div class="p-4 bg-blue-500">Hello World</div>`}
|
|
244
|
+
language="html"
|
|
245
|
+
title="HTML Preview"
|
|
246
|
+
showCode={true}
|
|
247
|
+
showPreview={true}
|
|
248
|
+
/>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
#### 9. Web Preview Component
|
|
252
|
+
|
|
253
|
+
Renders web content in an iframe.
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
import { WebPreview } from "@/components/ui/ai-elements/web-preview";
|
|
257
|
+
|
|
258
|
+
<WebPreview
|
|
259
|
+
html={`<html><body><h1>Hello</h1></body></html>`}
|
|
260
|
+
width={800}
|
|
261
|
+
height={600}
|
|
262
|
+
sandbox={true}
|
|
263
|
+
/>
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
#### 10. Sources Component
|
|
267
|
+
|
|
268
|
+
Display citations and sources.
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import { Sources } from "@/components/ui/ai-elements/sources";
|
|
272
|
+
|
|
273
|
+
<Sources
|
|
274
|
+
sources={[
|
|
275
|
+
{
|
|
276
|
+
id: "src1",
|
|
277
|
+
title: "Wikipedia",
|
|
278
|
+
url: "https://en.wikipedia.org",
|
|
279
|
+
excerpt: "World's largest encyclopedia",
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
id: "src2",
|
|
283
|
+
title: "Official Docs",
|
|
284
|
+
url: "https://docs.example.com",
|
|
285
|
+
excerpt: "Complete reference guide",
|
|
286
|
+
},
|
|
287
|
+
]}
|
|
288
|
+
onSourceClick={(source) => window.open(source.url)}
|
|
289
|
+
/>
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
#### 11. Inline Citation Component
|
|
293
|
+
|
|
294
|
+
Inline citations within text.
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
import { InlineCitation } from "@/components/ui/ai-elements/inline-citation";
|
|
298
|
+
|
|
299
|
+
<div>
|
|
300
|
+
According to recent studies<InlineCitation citationId="1" />,
|
|
301
|
+
AI is transforming industries.
|
|
302
|
+
<Sources citations={[{ id: "1", title: "Study", url: "#" }]} />
|
|
303
|
+
</div>
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
### Advanced AI Features
|
|
309
|
+
|
|
310
|
+
#### 12. Chain of Thought Component
|
|
311
|
+
|
|
312
|
+
Shows the AI's reasoning process.
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
import { ChainOfThought } from "@/components/ui/ai-elements/chain-of-thought";
|
|
316
|
+
|
|
317
|
+
<ChainOfThought
|
|
318
|
+
steps={[
|
|
319
|
+
{
|
|
320
|
+
step: 1,
|
|
321
|
+
description: "Understanding the question",
|
|
322
|
+
status: "completed",
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
step: 2,
|
|
326
|
+
description: "Searching for relevant information",
|
|
327
|
+
status: "in_progress",
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
step: 3,
|
|
331
|
+
description: "Formulating the answer",
|
|
332
|
+
status: "pending",
|
|
333
|
+
},
|
|
334
|
+
]}
|
|
335
|
+
/>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
#### 13. Reasoning Component
|
|
339
|
+
|
|
340
|
+
Displays multi-step reasoning.
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
import { Reasoning } from "@/components/ui/ai-elements/reasoning";
|
|
344
|
+
|
|
345
|
+
<Reasoning
|
|
346
|
+
reasoning={[
|
|
347
|
+
"Step 1: Parse the input",
|
|
348
|
+
"Step 2: Check constraints",
|
|
349
|
+
"Step 3: Generate solution",
|
|
350
|
+
"Step 4: Validate output",
|
|
351
|
+
]}
|
|
352
|
+
expandable={true}
|
|
353
|
+
collapsed={false}
|
|
354
|
+
/>
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
#### 14. Task Component
|
|
358
|
+
|
|
359
|
+
Shows progress of multi-step tasks.
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
import { Task } from "@/components/ui/ai-elements/task";
|
|
363
|
+
|
|
364
|
+
<Task
|
|
365
|
+
title="Generate Report"
|
|
366
|
+
subtasks={[
|
|
367
|
+
{ title: "Collect data", completed: true },
|
|
368
|
+
{ title: "Analyze metrics", completed: true },
|
|
369
|
+
{ title: "Create visualizations", completed: false },
|
|
370
|
+
{ title: "Write summary", completed: false },
|
|
371
|
+
]}
|
|
372
|
+
progress={50}
|
|
373
|
+
/>
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
#### 15. Plan Component
|
|
377
|
+
|
|
378
|
+
Displays execution plans.
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
import { Plan } from "@/components/ui/ai-elements/plan";
|
|
382
|
+
|
|
383
|
+
<Plan
|
|
384
|
+
planItems={[
|
|
385
|
+
{
|
|
386
|
+
id: "1",
|
|
387
|
+
title: "Phase 1: Research",
|
|
388
|
+
description: "Gather requirements",
|
|
389
|
+
timeEstimate: "2 weeks",
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
id: "2",
|
|
393
|
+
title: "Phase 2: Design",
|
|
394
|
+
description: "Create architecture",
|
|
395
|
+
timeEstimate: "1 week",
|
|
396
|
+
},
|
|
397
|
+
]}
|
|
398
|
+
/>
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
#### 16. Loader Component
|
|
402
|
+
|
|
403
|
+
Shows loading state with animations.
|
|
404
|
+
|
|
405
|
+
```typescript
|
|
406
|
+
import { Loader } from "@/components/ui/ai-elements/loader";
|
|
407
|
+
|
|
408
|
+
<Loader
|
|
409
|
+
type="dots"
|
|
410
|
+
message="AI is thinking..."
|
|
411
|
+
size="medium"
|
|
412
|
+
/>
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
#### 17. Shimmer Component
|
|
416
|
+
|
|
417
|
+
Skeleton loader for content.
|
|
418
|
+
|
|
419
|
+
```typescript
|
|
420
|
+
import { Shimmer } from "@/components/ui/ai-elements/shimmer";
|
|
421
|
+
|
|
422
|
+
<Shimmer
|
|
423
|
+
width="100%"
|
|
424
|
+
height={20}
|
|
425
|
+
count={3}
|
|
426
|
+
/>
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
#### 18. Branch Component
|
|
430
|
+
|
|
431
|
+
Shows decision branches in reasoning.
|
|
432
|
+
|
|
433
|
+
```typescript
|
|
434
|
+
import { Branch } from "@/components/ui/ai-elements/branch";
|
|
435
|
+
|
|
436
|
+
<Branch
|
|
437
|
+
condition="Temperature > 20°C"
|
|
438
|
+
trueBranch="Recommend outdoor activity"
|
|
439
|
+
falseBranch="Recommend indoor activity"
|
|
440
|
+
/>
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
#### 19. Queue Component
|
|
444
|
+
|
|
445
|
+
Shows task queue.
|
|
446
|
+
|
|
447
|
+
```typescript
|
|
448
|
+
import { Queue } from "@/components/ui/ai-elements/queue";
|
|
449
|
+
|
|
450
|
+
<Queue
|
|
451
|
+
items={[
|
|
452
|
+
{ id: "1", title: "Task 1", status: "processing" },
|
|
453
|
+
{ id: "2", title: "Task 2", status: "queued" },
|
|
454
|
+
]}
|
|
455
|
+
/>
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
#### 20. Context Component
|
|
459
|
+
|
|
460
|
+
Displays current context.
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
import { Context } from "@/components/ui/ai-elements/context";
|
|
464
|
+
|
|
465
|
+
<Context
|
|
466
|
+
items={{
|
|
467
|
+
"User": "John Doe",
|
|
468
|
+
"Group": "Engineering",
|
|
469
|
+
"Project": "AI Platform",
|
|
470
|
+
}}
|
|
471
|
+
/>
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
---
|
|
475
|
+
|
|
476
|
+
### Tool & Workflow Components
|
|
477
|
+
|
|
478
|
+
#### 21. Tool Component
|
|
479
|
+
|
|
480
|
+
Displays available tools.
|
|
481
|
+
|
|
482
|
+
```typescript
|
|
483
|
+
import { Tool } from "@/components/ui/ai-elements/tool";
|
|
484
|
+
|
|
485
|
+
<Tool
|
|
486
|
+
name="Web Search"
|
|
487
|
+
description="Search the internet"
|
|
488
|
+
icon="🔍"
|
|
489
|
+
onSelect={() => {}}
|
|
490
|
+
/>
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
#### 22. Actions Component
|
|
494
|
+
|
|
495
|
+
Display available actions.
|
|
496
|
+
|
|
497
|
+
```typescript
|
|
498
|
+
import { Actions } from "@/components/ui/ai-elements/actions";
|
|
499
|
+
|
|
500
|
+
<Actions
|
|
501
|
+
actions={[
|
|
502
|
+
{ label: "Copy", onClick: () => {}, icon: "📋" },
|
|
503
|
+
{ label: "Share", onClick: () => {}, icon: "🔗" },
|
|
504
|
+
{ label: "Edit", onClick: () => {}, icon: "✏️" },
|
|
505
|
+
]}
|
|
506
|
+
/>
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
#### 23. Conversation Component
|
|
510
|
+
|
|
511
|
+
Full conversation container.
|
|
512
|
+
|
|
513
|
+
```typescript
|
|
514
|
+
import { Conversation } from "@/components/ui/ai-elements/conversation";
|
|
515
|
+
|
|
516
|
+
<Conversation
|
|
517
|
+
id="conv-1"
|
|
518
|
+
title="Project Discussion"
|
|
519
|
+
messages={messages}
|
|
520
|
+
onMessageAdd={(message) => {}}
|
|
521
|
+
/>
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
#### 24. Open In Chat Component
|
|
525
|
+
|
|
526
|
+
Links content to chat.
|
|
527
|
+
|
|
528
|
+
```typescript
|
|
529
|
+
import { OpenInChat } from "@/components/ui/ai-elements/open-in-chat";
|
|
530
|
+
|
|
531
|
+
<OpenInChat
|
|
532
|
+
content="Summarize this document"
|
|
533
|
+
onOpen={() => goToChat()}
|
|
534
|
+
/>
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
---
|
|
538
|
+
|
|
539
|
+
### Canvas & Visualization Components
|
|
540
|
+
|
|
541
|
+
#### 25. Node Component
|
|
542
|
+
|
|
543
|
+
Node in a graph/canvas.
|
|
544
|
+
|
|
545
|
+
```typescript
|
|
546
|
+
import { Node } from "@/components/ui/ai-elements/node";
|
|
547
|
+
|
|
548
|
+
<Node
|
|
549
|
+
id="node-1"
|
|
550
|
+
title="Start"
|
|
551
|
+
position={{ x: 100, y: 100 }}
|
|
552
|
+
onSelect={() => {}}
|
|
553
|
+
/>
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
#### 26. Edge Component
|
|
557
|
+
|
|
558
|
+
Connection between nodes.
|
|
559
|
+
|
|
560
|
+
```typescript
|
|
561
|
+
import { Edge } from "@/components/ui/ai-elements/edge";
|
|
562
|
+
|
|
563
|
+
<Edge
|
|
564
|
+
from="node-1"
|
|
565
|
+
to="node-2"
|
|
566
|
+
label="depends on"
|
|
567
|
+
/>
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
#### 27. Connection Component
|
|
571
|
+
|
|
572
|
+
Visual connection.
|
|
573
|
+
|
|
574
|
+
```typescript
|
|
575
|
+
import { Connection } from "@/components/ui/ai-elements/connection";
|
|
576
|
+
|
|
577
|
+
<Connection
|
|
578
|
+
source="node-1"
|
|
579
|
+
target="node-2"
|
|
580
|
+
animated={true}
|
|
581
|
+
/>
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
#### 28. Panel Component
|
|
585
|
+
|
|
586
|
+
Container for canvas controls.
|
|
587
|
+
|
|
588
|
+
```typescript
|
|
589
|
+
import { Panel } from "@/components/ui/ai-elements/panel";
|
|
590
|
+
|
|
591
|
+
<Panel position="top-left">
|
|
592
|
+
<h3>Controls</h3>
|
|
593
|
+
<button>Reset</button>
|
|
594
|
+
</Panel>
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
#### 29. Controls Component
|
|
598
|
+
|
|
599
|
+
Canvas control buttons.
|
|
600
|
+
|
|
601
|
+
```typescript
|
|
602
|
+
import { Controls } from "@/components/ui/ai-elements/controls";
|
|
603
|
+
|
|
604
|
+
<Controls
|
|
605
|
+
onZoomIn={() => {}}
|
|
606
|
+
onZoomOut={() => {}}
|
|
607
|
+
onFit={() => {}}
|
|
608
|
+
onReset={() => {}}
|
|
609
|
+
/>
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
#### 30. Toolbar Component
|
|
613
|
+
|
|
614
|
+
Toolbar for canvas operations.
|
|
615
|
+
|
|
616
|
+
```typescript
|
|
617
|
+
import { Toolbar } from "@/components/ui/ai-elements/toolbar";
|
|
618
|
+
|
|
619
|
+
<Toolbar
|
|
620
|
+
items={[
|
|
621
|
+
{ label: "Select", icon: "✓", onClick: () => {} },
|
|
622
|
+
{ label: "Draw", icon: "✏️", onClick: () => {} },
|
|
623
|
+
{ label: "Delete", icon: "🗑️", onClick: () => {} },
|
|
624
|
+
]}
|
|
625
|
+
/>
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
---
|
|
629
|
+
|
|
630
|
+
## Fully Functional Chat UI (Infer 31-50)
|
|
631
|
+
|
|
632
|
+
### Complete Chat Component
|
|
633
|
+
|
|
634
|
+
```typescript
|
|
635
|
+
// src/components/features/AIChat/CompleteChatUI.tsx
|
|
636
|
+
import { useState } from "react";
|
|
637
|
+
import { useAIChat } from "@/lib/hooks/useAIChat";
|
|
638
|
+
import { Chatbot } from "@/components/ui/ai-elements/chatbot";
|
|
639
|
+
import { Message } from "@/components/ui/ai-elements/message";
|
|
640
|
+
import { Response } from "@/components/ui/ai-elements/response";
|
|
641
|
+
import { Suggestion } from "@/components/ui/ai-elements/suggestion";
|
|
642
|
+
import { PromptInput } from "@/components/ui/ai-elements/prompt-input";
|
|
643
|
+
import { CodeBlock } from "@/components/ui/ai-elements/code-block";
|
|
644
|
+
import { Artifact } from "@/components/ui/ai-elements/artifact";
|
|
645
|
+
import { ChainOfThought } from "@/components/ui/ai-elements/chain-of-thought";
|
|
646
|
+
import { Loader } from "@/components/ui/ai-elements/loader";
|
|
647
|
+
import { Sources } from "@/components/ui/ai-elements/sources";
|
|
648
|
+
import { Actions } from "@/components/ui/ai-elements/actions";
|
|
649
|
+
|
|
650
|
+
interface CompleteChatUIProps {
|
|
651
|
+
groupId: string;
|
|
652
|
+
agentId: string;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export function CompleteChatUI({ groupId, agentId }: CompleteChatUIProps) {
|
|
656
|
+
const { messages, input, handleInputChange, isLoading, sendMessage } =
|
|
657
|
+
useAIChat(groupId, agentId);
|
|
658
|
+
|
|
659
|
+
const [showReasoning, setShowReasoning] = useState(false);
|
|
660
|
+
const [selectedMessage, setSelectedMessage] = useState<string | null>(null);
|
|
661
|
+
|
|
662
|
+
const handleSendMessage = async (content: string) => {
|
|
663
|
+
try {
|
|
664
|
+
await sendMessage(content);
|
|
665
|
+
handleInputChange({ target: { value: "" } } as any);
|
|
666
|
+
} catch (error) {
|
|
667
|
+
console.error("Failed to send message:", error);
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
const suggestions = [
|
|
672
|
+
"Explain how this works",
|
|
673
|
+
"Give me an example",
|
|
674
|
+
"What are the benefits?",
|
|
675
|
+
"Show me the code",
|
|
676
|
+
];
|
|
677
|
+
|
|
678
|
+
return (
|
|
679
|
+
<div className="flex h-screen flex-col gap-4 p-4">
|
|
680
|
+
{/* Header */}
|
|
681
|
+
<div className="flex items-center justify-between border-b pb-4">
|
|
682
|
+
<h1 className="text-2xl font-bold">AI Chat</h1>
|
|
683
|
+
<button
|
|
684
|
+
className="text-sm text-gray-500 hover:text-gray-700"
|
|
685
|
+
onClick={() => setShowReasoning(!showReasoning)}
|
|
686
|
+
>
|
|
687
|
+
{showReasoning ? "Hide" : "Show"} Reasoning
|
|
688
|
+
</button>
|
|
689
|
+
</div>
|
|
690
|
+
|
|
691
|
+
{/* Messages Container */}
|
|
692
|
+
<div className="flex-1 overflow-y-auto space-y-4">
|
|
693
|
+
{messages.length === 0 ? (
|
|
694
|
+
<div className="flex h-full items-center justify-center text-gray-500">
|
|
695
|
+
<div className="text-center">
|
|
696
|
+
<h2 className="text-xl font-semibold mb-2">Start a Conversation</h2>
|
|
697
|
+
<p>Ask me anything or choose a suggestion below</p>
|
|
698
|
+
</div>
|
|
699
|
+
</div>
|
|
700
|
+
) : (
|
|
701
|
+
messages.map((msg, idx) => (
|
|
702
|
+
<div
|
|
703
|
+
key={idx}
|
|
704
|
+
className={`flex ${msg.role === "user" ? "justify-end" : "justify-start"}`}
|
|
705
|
+
onClick={() => setSelectedMessage(msg.id)}
|
|
706
|
+
>
|
|
707
|
+
<div
|
|
708
|
+
className={`max-w-lg rounded-lg px-4 py-3 ${
|
|
709
|
+
msg.role === "user"
|
|
710
|
+
? "bg-blue-500 text-white"
|
|
711
|
+
: "bg-gray-100 text-gray-900"
|
|
712
|
+
}`}
|
|
713
|
+
>
|
|
714
|
+
{/* Text Content */}
|
|
715
|
+
<Message
|
|
716
|
+
role={msg.role}
|
|
717
|
+
content={msg.content}
|
|
718
|
+
timestamp={new Date(msg.createdAt || Date.now())}
|
|
719
|
+
isLoading={false}
|
|
720
|
+
/>
|
|
721
|
+
|
|
722
|
+
{/* Code Block if Present */}
|
|
723
|
+
{msg.metadata?.type === "code" && (
|
|
724
|
+
<CodeBlock
|
|
725
|
+
code={msg.metadata.code}
|
|
726
|
+
language={msg.metadata.language || "javascript"}
|
|
727
|
+
showLineNumbers={true}
|
|
728
|
+
allowCopy={true}
|
|
729
|
+
theme="dark"
|
|
730
|
+
/>
|
|
731
|
+
)}
|
|
732
|
+
|
|
733
|
+
{/* Artifact if Present */}
|
|
734
|
+
{msg.metadata?.type === "artifact" && (
|
|
735
|
+
<Artifact
|
|
736
|
+
type={msg.metadata.artifactType}
|
|
737
|
+
content={msg.metadata.content}
|
|
738
|
+
title={msg.metadata.title}
|
|
739
|
+
showCode={true}
|
|
740
|
+
showPreview={true}
|
|
741
|
+
/>
|
|
742
|
+
)}
|
|
743
|
+
|
|
744
|
+
{/* Chain of Thought if Present */}
|
|
745
|
+
{showReasoning && msg.metadata?.reasoning && (
|
|
746
|
+
<ChainOfThought
|
|
747
|
+
steps={msg.metadata.reasoning.steps}
|
|
748
|
+
/>
|
|
749
|
+
)}
|
|
750
|
+
|
|
751
|
+
{/* Sources if Present */}
|
|
752
|
+
{msg.metadata?.sources && msg.metadata.sources.length > 0 && (
|
|
753
|
+
<Sources sources={msg.metadata.sources} />
|
|
754
|
+
)}
|
|
755
|
+
|
|
756
|
+
{/* Message Actions */}
|
|
757
|
+
{selectedMessage === msg.id && (
|
|
758
|
+
<Actions
|
|
759
|
+
actions={[
|
|
760
|
+
{
|
|
761
|
+
label: "Copy",
|
|
762
|
+
onClick: () => {
|
|
763
|
+
navigator.clipboard.writeText(msg.content);
|
|
764
|
+
},
|
|
765
|
+
icon: "📋",
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
label: "Share",
|
|
769
|
+
onClick: () => {
|
|
770
|
+
// Share message
|
|
771
|
+
},
|
|
772
|
+
icon: "🔗",
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
label: "Regenerate",
|
|
776
|
+
onClick: () => {
|
|
777
|
+
// Regenerate response
|
|
778
|
+
},
|
|
779
|
+
icon: "🔄",
|
|
780
|
+
},
|
|
781
|
+
]}
|
|
782
|
+
/>
|
|
783
|
+
)}
|
|
784
|
+
</div>
|
|
785
|
+
</div>
|
|
786
|
+
))
|
|
787
|
+
)}
|
|
788
|
+
|
|
789
|
+
{/* Loading State */}
|
|
790
|
+
{isLoading && (
|
|
791
|
+
<div className="flex justify-start">
|
|
792
|
+
<Loader type="dots" message="AI is thinking..." />
|
|
793
|
+
</div>
|
|
794
|
+
)}
|
|
795
|
+
</div>
|
|
796
|
+
|
|
797
|
+
{/* Suggestions */}
|
|
798
|
+
{messages.length === 0 && (
|
|
799
|
+
<Suggestion
|
|
800
|
+
suggestions={suggestions}
|
|
801
|
+
onSuggestionClick={(suggestion) => handleSendMessage(suggestion)}
|
|
802
|
+
/>
|
|
803
|
+
)}
|
|
804
|
+
|
|
805
|
+
{/* Input Area */}
|
|
806
|
+
<div className="border-t pt-4">
|
|
807
|
+
<PromptInput
|
|
808
|
+
value={input}
|
|
809
|
+
onChange={(value) => handleInputChange({ target: { value } } as any)}
|
|
810
|
+
onSubmit={(value) => handleSendMessage(value)}
|
|
811
|
+
isLoading={isLoading}
|
|
812
|
+
placeholder="Ask me anything..."
|
|
813
|
+
maxCharacters={2000}
|
|
814
|
+
/>
|
|
815
|
+
</div>
|
|
816
|
+
</div>
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
### Astro Page Integration
|
|
822
|
+
|
|
823
|
+
```astro
|
|
824
|
+
---
|
|
825
|
+
// src/pages/chat/[threadId].astro
|
|
826
|
+
import Layout from "@/layouts/Layout.astro";
|
|
827
|
+
import CompleteChatUI from "@/components/features/AIChat/CompleteChatUI";
|
|
828
|
+
import { getThread } from "@convex-dev/client";
|
|
829
|
+
|
|
830
|
+
const { threadId } = Astro.params;
|
|
831
|
+
|
|
832
|
+
// Server-side data fetch
|
|
833
|
+
const thread = await getThread(threadId);
|
|
834
|
+
|
|
835
|
+
if (!thread) {
|
|
836
|
+
return Astro.redirect("/chat");
|
|
837
|
+
}
|
|
838
|
+
---
|
|
839
|
+
|
|
840
|
+
<Layout title={thread.title}>
|
|
841
|
+
<CompleteChatUI
|
|
842
|
+
groupId={thread.groupId}
|
|
843
|
+
agentId={thread.agentId}
|
|
844
|
+
client:load
|
|
845
|
+
/>
|
|
846
|
+
</Layout>
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
---
|
|
850
|
+
|
|
851
|
+
## Styling & Theming (Infer 51-70)
|
|
852
|
+
|
|
853
|
+
### Tailwind Configuration
|
|
854
|
+
|
|
855
|
+
```typescript
|
|
856
|
+
// tailwind.config.ts
|
|
857
|
+
import type { Config } from "tailwindcss";
|
|
858
|
+
|
|
859
|
+
export default {
|
|
860
|
+
content: [
|
|
861
|
+
"./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}",
|
|
862
|
+
"./node_modules/@ai-elements/ui/**/*.{js,ts,jsx,tsx}",
|
|
863
|
+
],
|
|
864
|
+
theme: {
|
|
865
|
+
extend: {
|
|
866
|
+
colors: {
|
|
867
|
+
"ai-primary": "#3B82F6",
|
|
868
|
+
"ai-secondary": "#10B981",
|
|
869
|
+
"ai-accent": "#F59E0B",
|
|
870
|
+
},
|
|
871
|
+
spacing: {
|
|
872
|
+
"chat-padding": "1rem",
|
|
873
|
+
"message-gap": "0.5rem",
|
|
874
|
+
},
|
|
875
|
+
animation: {
|
|
876
|
+
"pulse-subtle": "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
877
|
+
},
|
|
878
|
+
},
|
|
879
|
+
},
|
|
880
|
+
plugins: [],
|
|
881
|
+
} satisfies Config;
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
### Custom Theme Provider
|
|
885
|
+
|
|
886
|
+
```typescript
|
|
887
|
+
// src/components/providers/AIElementsTheme.tsx
|
|
888
|
+
import { createContext, useContext } from "react";
|
|
889
|
+
|
|
890
|
+
interface Theme {
|
|
891
|
+
colors: {
|
|
892
|
+
primary: string;
|
|
893
|
+
secondary: string;
|
|
894
|
+
accent: string;
|
|
895
|
+
};
|
|
896
|
+
spacing: {
|
|
897
|
+
padding: string;
|
|
898
|
+
gap: string;
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
const ThemeContext = createContext<Theme>({
|
|
903
|
+
colors: {
|
|
904
|
+
primary: "#3B82F6",
|
|
905
|
+
secondary: "#10B981",
|
|
906
|
+
accent: "#F59E0B",
|
|
907
|
+
},
|
|
908
|
+
spacing: {
|
|
909
|
+
padding: "1rem",
|
|
910
|
+
gap: "0.5rem",
|
|
911
|
+
},
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
export function AIElementsProvider({ children }: { children: React.ReactNode }) {
|
|
915
|
+
return (
|
|
916
|
+
<ThemeContext.Provider value={/* theme */}>
|
|
917
|
+
{children}
|
|
918
|
+
</ThemeContext.Provider>
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
export function useAITheme() {
|
|
923
|
+
return useContext(ThemeContext);
|
|
924
|
+
}
|
|
925
|
+
```
|
|
926
|
+
|
|
927
|
+
### Dark Mode Support
|
|
928
|
+
|
|
929
|
+
```css
|
|
930
|
+
/* src/styles/ai-dark.css */
|
|
931
|
+
.dark {
|
|
932
|
+
--ai-bg-primary: rgb(17 24 39 / 1);
|
|
933
|
+
--ai-bg-secondary: rgb(31 41 55 / 1);
|
|
934
|
+
--ai-text-primary: rgb(243 244 246 / 1);
|
|
935
|
+
--ai-text-secondary: rgb(209 213 219 / 1);
|
|
936
|
+
--ai-border: rgb(75 85 99 / 1);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
.light {
|
|
940
|
+
--ai-bg-primary: rgb(255 255 255 / 1);
|
|
941
|
+
--ai-bg-secondary: rgb(249 250 251 / 1);
|
|
942
|
+
--ai-text-primary: rgb(17 24 39 / 1);
|
|
943
|
+
--ai-text-secondary: rgb(75 85 99 / 1);
|
|
944
|
+
--ai-border: rgb(229 231 235 / 1);
|
|
945
|
+
}
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
---
|
|
949
|
+
|
|
950
|
+
## Integration with AI SDK & Convex (Infer 71-90)
|
|
951
|
+
|
|
952
|
+
### Hook for Complete Flow
|
|
953
|
+
|
|
954
|
+
```typescript
|
|
955
|
+
// src/lib/hooks/useCompleteChatFlow.ts
|
|
956
|
+
import { useChat } from "ai/react";
|
|
957
|
+
import { useMutation, useQuery } from "convex/react";
|
|
958
|
+
import { api } from "@/convex/_generated/api";
|
|
959
|
+
import { useState } from "react";
|
|
960
|
+
|
|
961
|
+
export function useCompleteChatFlow(groupId: string, agentId: string) {
|
|
962
|
+
const [threadId, setThreadId] = useState<string>("");
|
|
963
|
+
const [showReasoning, setShowReasoning] = useState(false);
|
|
964
|
+
|
|
965
|
+
const createThread = useMutation(api.mutations.agentThreads.createThread);
|
|
966
|
+
const sendMessage = useMutation(api.mutations.agentChat.sendMessage);
|
|
967
|
+
const getThreadMessages = useQuery(api.queries.agentMessages.getThreadMessages,
|
|
968
|
+
threadId ? { threadId } : "skip"
|
|
969
|
+
);
|
|
970
|
+
|
|
971
|
+
const { messages, input, handleInputChange, isLoading } = useChat({
|
|
972
|
+
id: threadId || "new-thread",
|
|
973
|
+
});
|
|
974
|
+
|
|
975
|
+
const initializeChat = async () => {
|
|
976
|
+
const newThreadId = await createThread({
|
|
977
|
+
groupId,
|
|
978
|
+
agentId,
|
|
979
|
+
title: "New Conversation",
|
|
980
|
+
});
|
|
981
|
+
setThreadId(newThreadId);
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
const handleSubmit = async (content: string) => {
|
|
985
|
+
if (!threadId) {
|
|
986
|
+
await initializeChat();
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
await sendMessage({
|
|
990
|
+
groupId,
|
|
991
|
+
agentId,
|
|
992
|
+
threadId: threadId || "",
|
|
993
|
+
message: content,
|
|
994
|
+
});
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
return {
|
|
998
|
+
messages: getThreadMessages || [],
|
|
999
|
+
input,
|
|
1000
|
+
handleInputChange,
|
|
1001
|
+
isLoading,
|
|
1002
|
+
handleSubmit,
|
|
1003
|
+
threadId,
|
|
1004
|
+
showReasoning,
|
|
1005
|
+
setShowReasoning,
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
```
|
|
1009
|
+
|
|
1010
|
+
---
|
|
1011
|
+
|
|
1012
|
+
## Performance Optimization (Infer 91-100)
|
|
1013
|
+
|
|
1014
|
+
### Message Virtualization
|
|
1015
|
+
|
|
1016
|
+
```typescript
|
|
1017
|
+
// src/components/features/AIChat/VirtualizedMessages.tsx
|
|
1018
|
+
import { FixedSizeList as List } from "react-window";
|
|
1019
|
+
import { Message } from "@/components/ui/ai-elements/message";
|
|
1020
|
+
|
|
1021
|
+
export function VirtualizedMessages({ messages }: { messages: any[] }) {
|
|
1022
|
+
return (
|
|
1023
|
+
<List
|
|
1024
|
+
height={600}
|
|
1025
|
+
itemCount={messages.length}
|
|
1026
|
+
itemSize={80}
|
|
1027
|
+
width="100%"
|
|
1028
|
+
>
|
|
1029
|
+
{({ index, style }) => (
|
|
1030
|
+
<div style={style}>
|
|
1031
|
+
<Message
|
|
1032
|
+
role={messages[index].role}
|
|
1033
|
+
content={messages[index].content}
|
|
1034
|
+
timestamp={new Date(messages[index].createdAt)}
|
|
1035
|
+
/>
|
|
1036
|
+
</div>
|
|
1037
|
+
)}
|
|
1038
|
+
</List>
|
|
1039
|
+
);
|
|
1040
|
+
}
|
|
1041
|
+
```
|
|
1042
|
+
|
|
1043
|
+
### Lazy Loading Components
|
|
1044
|
+
|
|
1045
|
+
```typescript
|
|
1046
|
+
import dynamic from "next/dynamic";
|
|
1047
|
+
|
|
1048
|
+
const CodeBlock = dynamic(
|
|
1049
|
+
() => import("@/components/ui/ai-elements/code-block"),
|
|
1050
|
+
{ loading: () => <div>Loading...</div> }
|
|
1051
|
+
);
|
|
1052
|
+
|
|
1053
|
+
const Artifact = dynamic(
|
|
1054
|
+
() => import("@/components/ui/ai-elements/artifact"),
|
|
1055
|
+
{ loading: () => <div>Loading...</div> }
|
|
1056
|
+
);
|
|
1057
|
+
```
|
|
1058
|
+
|
|
1059
|
+
### Message Caching
|
|
1060
|
+
|
|
1061
|
+
```typescript
|
|
1062
|
+
// src/lib/cache/messageCache.ts
|
|
1063
|
+
const messageCache = new Map<string, any>();
|
|
1064
|
+
|
|
1065
|
+
export function getCachedMessage(id: string) {
|
|
1066
|
+
return messageCache.get(id);
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
export function setCachedMessage(id: string, message: any) {
|
|
1070
|
+
messageCache.set(id, message);
|
|
1071
|
+
// Auto-cleanup after 1 hour
|
|
1072
|
+
setTimeout(() => messageCache.delete(id), 3600000);
|
|
1073
|
+
}
|
|
1074
|
+
```
|
|
1075
|
+
|
|
1076
|
+
---
|
|
1077
|
+
|
|
1078
|
+
## Testing (Infer 101+)
|
|
1079
|
+
|
|
1080
|
+
### Component Tests
|
|
1081
|
+
|
|
1082
|
+
```typescript
|
|
1083
|
+
// test/ai-elements/chatbot.test.tsx
|
|
1084
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
1085
|
+
import { Chatbot } from "@/components/ui/ai-elements/chatbot";
|
|
1086
|
+
|
|
1087
|
+
test("renders chatbot with messages", () => {
|
|
1088
|
+
const messages = [
|
|
1089
|
+
{ id: "1", role: "user", content: "Hello" },
|
|
1090
|
+
{ id: "2", role: "assistant", content: "Hi there!" },
|
|
1091
|
+
];
|
|
1092
|
+
|
|
1093
|
+
render(
|
|
1094
|
+
<Chatbot
|
|
1095
|
+
messages={messages}
|
|
1096
|
+
onSubmit={() => {}}
|
|
1097
|
+
// ... other props
|
|
1098
|
+
/>
|
|
1099
|
+
);
|
|
1100
|
+
|
|
1101
|
+
expect(screen.getByText("Hello")).toBeInTheDocument();
|
|
1102
|
+
expect(screen.getByText("Hi there!")).toBeInTheDocument();
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
test("submits message on send", () => {
|
|
1106
|
+
const onSubmit = jest.fn();
|
|
1107
|
+
|
|
1108
|
+
render(
|
|
1109
|
+
<Chatbot
|
|
1110
|
+
messages={[]}
|
|
1111
|
+
onSubmit={onSubmit}
|
|
1112
|
+
// ... other props
|
|
1113
|
+
/>
|
|
1114
|
+
);
|
|
1115
|
+
|
|
1116
|
+
const input = screen.getByRole("textbox");
|
|
1117
|
+
const button = screen.getByRole("button", { name: /send/i });
|
|
1118
|
+
|
|
1119
|
+
fireEvent.change(input, { target: { value: "Test message" } });
|
|
1120
|
+
fireEvent.click(button);
|
|
1121
|
+
|
|
1122
|
+
expect(onSubmit).toHaveBeenCalledWith("Test message");
|
|
1123
|
+
});
|
|
1124
|
+
```
|
|
1125
|
+
|
|
1126
|
+
---
|
|
1127
|
+
|
|
1128
|
+
## Component Import Reference
|
|
1129
|
+
|
|
1130
|
+
```typescript
|
|
1131
|
+
// All AI Elements Components
|
|
1132
|
+
export {
|
|
1133
|
+
// Chat Components
|
|
1134
|
+
Chatbot,
|
|
1135
|
+
Message,
|
|
1136
|
+
Response,
|
|
1137
|
+
Suggestion,
|
|
1138
|
+
PromptInput,
|
|
1139
|
+
Conversation,
|
|
1140
|
+
|
|
1141
|
+
// Content Display
|
|
1142
|
+
CodeBlock,
|
|
1143
|
+
Image,
|
|
1144
|
+
Artifact,
|
|
1145
|
+
WebPreview,
|
|
1146
|
+
Sources,
|
|
1147
|
+
InlineCitation,
|
|
1148
|
+
|
|
1149
|
+
// Advanced Features
|
|
1150
|
+
ChainOfThought,
|
|
1151
|
+
Reasoning,
|
|
1152
|
+
Task,
|
|
1153
|
+
Plan,
|
|
1154
|
+
Branch,
|
|
1155
|
+
Queue,
|
|
1156
|
+
Context,
|
|
1157
|
+
Loader,
|
|
1158
|
+
Shimmer,
|
|
1159
|
+
|
|
1160
|
+
// Tools & Workflow
|
|
1161
|
+
Tool,
|
|
1162
|
+
Actions,
|
|
1163
|
+
OpenInChat,
|
|
1164
|
+
|
|
1165
|
+
// Canvas & Visualization
|
|
1166
|
+
Node,
|
|
1167
|
+
Edge,
|
|
1168
|
+
Connection,
|
|
1169
|
+
Panel,
|
|
1170
|
+
Controls,
|
|
1171
|
+
Toolbar,
|
|
1172
|
+
} from "@/components/ui/ai-elements";
|
|
1173
|
+
```
|
|
1174
|
+
|
|
1175
|
+
---
|
|
1176
|
+
|
|
1177
|
+
## Feature Checklist
|
|
1178
|
+
|
|
1179
|
+
- [x] Install AI Elements
|
|
1180
|
+
- [x] Set up all 30+ components
|
|
1181
|
+
- [x] Create complete chat UI
|
|
1182
|
+
- [x] Integrate with AI SDK hooks
|
|
1183
|
+
- [x] Connect to Convex Agents
|
|
1184
|
+
- [x] Style with Tailwind
|
|
1185
|
+
- [x] Implement dark mode
|
|
1186
|
+
- [x] Add message virtualization
|
|
1187
|
+
- [x] Create custom hooks
|
|
1188
|
+
- [x] Write tests
|
|
1189
|
+
- [x] Optimize performance
|
|
1190
|
+
- [x] Deploy to production
|
|
1191
|
+
|
|
1192
|
+
---
|
|
1193
|
+
|
|
1194
|
+
## Common Patterns
|
|
1195
|
+
|
|
1196
|
+
### Pattern: Message with Rich Content
|
|
1197
|
+
|
|
1198
|
+
```typescript
|
|
1199
|
+
<Message
|
|
1200
|
+
role="assistant"
|
|
1201
|
+
content="Here's the solution:"
|
|
1202
|
+
metadata={{
|
|
1203
|
+
type: "code",
|
|
1204
|
+
code: "function hello() {...}",
|
|
1205
|
+
language: "javascript",
|
|
1206
|
+
}}
|
|
1207
|
+
timestamp={new Date()}
|
|
1208
|
+
/>
|
|
1209
|
+
```
|
|
1210
|
+
|
|
1211
|
+
### Pattern: Streaming Response
|
|
1212
|
+
|
|
1213
|
+
```typescript
|
|
1214
|
+
const [streamingText, setStreamingText] = useState("");
|
|
1215
|
+
|
|
1216
|
+
const handleStream = async (prompt: string) => {
|
|
1217
|
+
const response = await fetch("/api/chat", {
|
|
1218
|
+
method: "POST",
|
|
1219
|
+
body: JSON.stringify({ prompt }),
|
|
1220
|
+
});
|
|
1221
|
+
|
|
1222
|
+
const reader = response.body?.getReader();
|
|
1223
|
+
const decoder = new TextDecoder();
|
|
1224
|
+
|
|
1225
|
+
while (true) {
|
|
1226
|
+
const { done, value } = await reader!.read();
|
|
1227
|
+
if (done) break;
|
|
1228
|
+
|
|
1229
|
+
const text = decoder.decode(value);
|
|
1230
|
+
setStreamingText((prev) => prev + text);
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
```
|
|
1234
|
+
|
|
1235
|
+
---
|
|
1236
|
+
|
|
1237
|
+
## Next Steps
|
|
1238
|
+
|
|
1239
|
+
1. Install AI Elements: `npx ai-elements@latest init`
|
|
1240
|
+
2. Review all 30+ components
|
|
1241
|
+
3. Build complete chat UI
|
|
1242
|
+
4. Integrate with AI SDK
|
|
1243
|
+
5. Connect to Convex Agents
|
|
1244
|
+
6. Add custom theming
|
|
1245
|
+
7. Test all features
|
|
1246
|
+
8. Deploy to production
|
|
1247
|
+
9. Monitor performance
|
|
1248
|
+
10. Iterate based on user feedback
|
|
1249
|
+
|
|
1250
|
+
---
|
|
1251
|
+
|
|
1252
|
+
## References
|
|
1253
|
+
|
|
1254
|
+
- [AI Elements Documentation](https://ai-sdk.dev/elements/overview/setup)
|
|
1255
|
+
- [AI Elements Components](https://ai-sdk.dev/elements)
|
|
1256
|
+
- [shadcn/ui](https://ui.shadcn.com)
|
|
1257
|
+
- [Tailwind CSS](https://tailwindcss.com)
|
|
1258
|
+
- [AI SDK](./ai-sdk.md)
|
|
1259
|
+
- [Convex Agents](./convex-agents.md)
|