gd-design-library 1.6.0 → 1.7.0
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/ai/PROMPT_USAGE_MANUAL.md +762 -0
- package/ai/README.md +287 -380
- package/ai/discovery.d.ts +48 -0
- package/ai/index.d.ts +3 -0
- package/ai/prompts.d.ts +30 -0
- package/ai/schemas/components/Select.d.ts +11 -0
- package/ai/schemas/index.d.ts +33 -0
- package/ai/validation.d.ts +35 -0
- package/components/core/Input/Input.types.d.ts +4 -4
- package/components/core/Input/InputHelper/InputHelper.js +14 -15
- package/components/core/Input/constants.js +9 -9
- package/components/core/Input/useInputHandlers.js +26 -18
- package/components/core/Select/Select.js +75 -74
- package/components/core/Select/Select.types.d.ts +3 -0
- package/components/core/Select/SelectStyled.js +17 -16
- package/components/core/Textarea/Textarea.js +35 -28
- package/components/core/Textarea/Textarea.types.d.ts +3 -4
- package/components/core/Textarea/TextareaStyled.js +11 -11
- package/hooks/useCarousel/useCarousel.js +1 -1
- package/hooks/useMediaQuery/useMediaQuery.js +17 -13
- package/hooks/useTheme/NoOpTheme.d.ts +53 -12
- package/llms.txt +169 -94
- package/package.json +1 -1
- package/tokens/defaultTheme.d.ts +53 -12
- package/tokens/index.d.ts +53 -12
- package/tokens/input.d.ts +7 -1
- package/tokens/input.js +17 -11
- package/tokens/select.d.ts +13 -0
- package/tokens/select.js +46 -21
- package/tokens/table.js +5 -5
- package/tokens/textarea.d.ts +34 -12
- package/tokens/textarea.js +51 -29
- package/types/input.d.ts +1 -6
- package/types/input.js +3 -4
|
@@ -0,0 +1,762 @@
|
|
|
1
|
+
# Prompt Usage Manual: GridKit Design System AI Integration
|
|
2
|
+
|
|
3
|
+
> **Comprehensive guide** for using prompt generation utilities with the GridKit Design System AI integration system.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
1. [Introduction](#introduction)
|
|
10
|
+
2. [Basic Prompt Usage](#basic-prompt-usage)
|
|
11
|
+
3. [Contextual Prompts](#contextual-prompts)
|
|
12
|
+
4. [Agent-Specific Prompts](#agent-specific-prompts)
|
|
13
|
+
5. [Discovery Utilities](#discovery-utilities)
|
|
14
|
+
6. [Validation](#validation)
|
|
15
|
+
7. [Best Practices](#best-practices)
|
|
16
|
+
8. [Examples](#examples)
|
|
17
|
+
9. [Troubleshooting](#troubleshooting)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Introduction
|
|
22
|
+
|
|
23
|
+
The GridKit Design System provides a comprehensive AI integration system that enables reliable code generation using only the design system's components. This manual covers how to use the prompt generation utilities effectively.
|
|
24
|
+
|
|
25
|
+
### Key Features
|
|
26
|
+
|
|
27
|
+
- **Automatic Guardrail Extraction**: Guardrails are automatically extracted from component schemas
|
|
28
|
+
- **Context-Aware Prompts**: Generate prompts with specific component details
|
|
29
|
+
- **Multi-Agent Support**: Optimized prompts for Claude, GPT-4, and Gemini
|
|
30
|
+
- **Discovery Utilities**: Find components by category, feature, or use case
|
|
31
|
+
- **Validation**: Validate schemas and generated code
|
|
32
|
+
|
|
33
|
+
### Installation
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import {
|
|
37
|
+
buildClaudeSystemPrompt,
|
|
38
|
+
buildContextualPrompt,
|
|
39
|
+
buildGPT4Prompt,
|
|
40
|
+
buildGeminiPrompt,
|
|
41
|
+
discovery,
|
|
42
|
+
validateSchema,
|
|
43
|
+
validateGeneratedCode,
|
|
44
|
+
componentIndex,
|
|
45
|
+
} from 'gd-design-library/ai';
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Basic Prompt Usage
|
|
51
|
+
|
|
52
|
+
### Standard Prompt Builder
|
|
53
|
+
|
|
54
|
+
The most common way to generate prompts is using `buildClaudeSystemPrompt`:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { buildClaudeSystemPrompt } from 'gd-design-library/ai';
|
|
58
|
+
|
|
59
|
+
const prompt = buildClaudeSystemPrompt('Create a sign-in form with email and password');
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**What it includes:**
|
|
63
|
+
|
|
64
|
+
- System instructions for the AI agent
|
|
65
|
+
- Hard requirements (TSX only, single-source imports)
|
|
66
|
+
- API constraints and guardrails (automatically extracted)
|
|
67
|
+
- Complete component catalog
|
|
68
|
+
- Composition tips
|
|
69
|
+
- General guidelines
|
|
70
|
+
|
|
71
|
+
**Output:**
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
You are Claude Code acting as a senior React UI engineer...
|
|
75
|
+
[System instructions]
|
|
76
|
+
[Guardrails]
|
|
77
|
+
[Component catalog]
|
|
78
|
+
[Composition tips]
|
|
79
|
+
|
|
80
|
+
Task: Create a sign-in form with email and password
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Direct System Prompt
|
|
84
|
+
|
|
85
|
+
For advanced use cases, you can access the system prompt directly:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { CLAUDE_GRIDKIT_SYSTEM_PROMPT } from 'gd-design-library/ai';
|
|
89
|
+
|
|
90
|
+
const customPrompt = `${CLAUDE_GRIDKIT_SYSTEM_PROMPT}\n\nTask: ${userRequest}`;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Legacy Builder
|
|
94
|
+
|
|
95
|
+
For backward compatibility:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { buildGDLibraryPrompt } from 'gd-design-library/ai';
|
|
99
|
+
|
|
100
|
+
const prompt = buildGDLibraryPrompt('Create a user profile card');
|
|
101
|
+
// Same as buildClaudeSystemPrompt
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Contextual Prompts
|
|
107
|
+
|
|
108
|
+
Contextual prompts include detailed documentation for specific components, reducing token usage and improving accuracy.
|
|
109
|
+
|
|
110
|
+
### Basic Contextual Prompt
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { buildContextualPrompt } from 'gd-design-library/ai';
|
|
114
|
+
|
|
115
|
+
const prompt = buildContextualPrompt('Create a form', {
|
|
116
|
+
components: ['Form', 'Input', 'Button'],
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**What it includes:**
|
|
121
|
+
|
|
122
|
+
- Standard system prompt
|
|
123
|
+
- Detailed documentation for specified components:
|
|
124
|
+
- Component description
|
|
125
|
+
- All props with types and descriptions
|
|
126
|
+
- Quick start examples
|
|
127
|
+
- Code examples
|
|
128
|
+
|
|
129
|
+
### Advanced Contextual Prompt
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const prompt = buildContextualPrompt('Create a complex form with validation', {
|
|
133
|
+
components: ['Form', 'Input', 'Textarea', 'Select', 'Button', 'InlineNotification'],
|
|
134
|
+
patterns: ['form-validation', 'error-handling'],
|
|
135
|
+
constraints: ['accessibility', 'responsive'],
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Benefits:**
|
|
140
|
+
|
|
141
|
+
- Reduced token usage (only relevant components included)
|
|
142
|
+
- Better accuracy (detailed component docs)
|
|
143
|
+
- Faster generation (less context to process)
|
|
144
|
+
|
|
145
|
+
### When to Use Contextual Prompts
|
|
146
|
+
|
|
147
|
+
✅ **Use contextual prompts when:**
|
|
148
|
+
|
|
149
|
+
- You know which components you need
|
|
150
|
+
- Working with complex components (Accordion, Table, etc.)
|
|
151
|
+
- Token limits are a concern
|
|
152
|
+
- You need detailed prop information
|
|
153
|
+
|
|
154
|
+
❌ **Use standard prompts when:**
|
|
155
|
+
|
|
156
|
+
- You want the AI to discover components
|
|
157
|
+
- Working with simple requests
|
|
158
|
+
- You need the full component catalog
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Agent-Specific Prompts
|
|
163
|
+
|
|
164
|
+
Different AI agents require different prompt formats. The library provides optimized formats for each.
|
|
165
|
+
|
|
166
|
+
### Claude (Anthropic)
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { buildClaudeSystemPrompt } from 'gd-design-library/ai';
|
|
170
|
+
|
|
171
|
+
const prompt = buildClaudeSystemPrompt('Create a form');
|
|
172
|
+
// Returns: string with system instructions
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Format:** Single string with system instructions and task
|
|
176
|
+
|
|
177
|
+
### GPT-4 (OpenAI)
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { buildGPT4Prompt } from 'gd-design-library/ai';
|
|
181
|
+
|
|
182
|
+
const messages = buildGPT4Prompt('Create a sign-in form');
|
|
183
|
+
// Returns: Array of message objects
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Format:**
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
[
|
|
190
|
+
{
|
|
191
|
+
role: 'system',
|
|
192
|
+
content: '...system instructions...',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
role: 'user',
|
|
196
|
+
content: 'Create a sign-in form',
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**Usage with OpenAI API:**
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
import { buildGPT4Prompt } from 'gd-design-library/ai';
|
|
205
|
+
import OpenAI from 'openai';
|
|
206
|
+
|
|
207
|
+
const openai = new OpenAI();
|
|
208
|
+
const messages = buildGPT4Prompt('Create a sign-in form');
|
|
209
|
+
|
|
210
|
+
const completion = await openai.chat.completions.create({
|
|
211
|
+
model: 'gpt-4',
|
|
212
|
+
messages,
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Gemini (Google)
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { buildGeminiPrompt } from 'gd-design-library/ai';
|
|
220
|
+
|
|
221
|
+
const request = buildGeminiPrompt('Create a form');
|
|
222
|
+
// Returns: Gemini API request object
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Format:**
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
{
|
|
229
|
+
contents: [
|
|
230
|
+
{
|
|
231
|
+
parts: [
|
|
232
|
+
{
|
|
233
|
+
text: '...system instructions...\n\nTask: Create a form',
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
generationConfig: {
|
|
239
|
+
temperature: 0.7,
|
|
240
|
+
topK: 40,
|
|
241
|
+
topP: 0.95,
|
|
242
|
+
},
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**Usage with Google Gemini API:**
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import { buildGeminiPrompt } from 'gd-design-library/ai';
|
|
250
|
+
import { GoogleGenerativeAI } from '@google/generative-ai';
|
|
251
|
+
|
|
252
|
+
const genAI = new GoogleGenerativeAI(apiKey);
|
|
253
|
+
const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
|
|
254
|
+
|
|
255
|
+
const request = buildGeminiPrompt('Create a form');
|
|
256
|
+
const result = await model.generateContent(request);
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Discovery Utilities
|
|
262
|
+
|
|
263
|
+
Before generating prompts, you may want to discover which components are available for your use case.
|
|
264
|
+
|
|
265
|
+
### Get Component by Name
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import { discovery } from 'gd-design-library/ai';
|
|
269
|
+
|
|
270
|
+
const button = discovery.getComponent('Button');
|
|
271
|
+
console.log(button?.description);
|
|
272
|
+
console.log(button?.props);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Search Components
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
const formComponents = discovery.searchComponents('form');
|
|
279
|
+
// Returns: [Input, Form, Select, Textarea, ...]
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Get Components by Category
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
import { getComponentsByCategory } from 'gd-design-library/ai';
|
|
286
|
+
|
|
287
|
+
const layoutComponents = getComponentsByCategory('Layout & Structure');
|
|
288
|
+
// Returns: [Box, FlexContainer, Column, Row, ...]
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**Available Categories:**
|
|
292
|
+
|
|
293
|
+
- `'Actions & Controls'`
|
|
294
|
+
- `'Layout & Structure'`
|
|
295
|
+
- `'Forms & Inputs'`
|
|
296
|
+
- `'Feedback & Overlays'`
|
|
297
|
+
- `'Navigation'`
|
|
298
|
+
- `'Display & Content'`
|
|
299
|
+
|
|
300
|
+
### Get Components by Feature
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
import { getComponentsByFeature } from 'gd-design-library/ai';
|
|
304
|
+
|
|
305
|
+
const validationComponents = getComponentsByFeature('validation');
|
|
306
|
+
// Returns components with validation features
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Get Components by Use Case
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
import { getComponentsByUseCase } from 'gd-design-library/ai';
|
|
313
|
+
|
|
314
|
+
const formComponents = getComponentsByUseCase('user registration');
|
|
315
|
+
// Returns components with patterns matching the use case
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Get Components by Complexity
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
const simpleComponents = discovery.getComponentsByComplexity('Low');
|
|
322
|
+
const complexComponents = discovery.getComponentsByComplexity('High');
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Find Related Components
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
const related = discovery.getRelatedComponents('Input');
|
|
329
|
+
// Returns components mentioned in Input's composition tips
|
|
330
|
+
// Example: [Form, Label, Button, ...]
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Find Patterns
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
import { findPatterns } from 'gd-design-library/ai';
|
|
337
|
+
|
|
338
|
+
const patterns = findPatterns(['Form', 'Input', 'Button'], 'validation');
|
|
339
|
+
// Returns patterns matching the use case
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Using Schema Index
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
import { componentIndex } from 'gd-design-library/ai';
|
|
346
|
+
|
|
347
|
+
// Get by category
|
|
348
|
+
const formControls = componentIndex.byCategory['Forms & Inputs'];
|
|
349
|
+
|
|
350
|
+
// Get by complexity
|
|
351
|
+
const simpleComponents = componentIndex.byComplexity.Low;
|
|
352
|
+
|
|
353
|
+
// Get by feature
|
|
354
|
+
const layoutComponents = componentIndex.byFeature['Layout'];
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## Validation
|
|
360
|
+
|
|
361
|
+
### Validate Component Schema
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
import { validateSchema } from 'gd-design-library/ai';
|
|
365
|
+
|
|
366
|
+
const result = validateSchema(componentSchema);
|
|
367
|
+
|
|
368
|
+
if (!result.valid) {
|
|
369
|
+
console.error('Schema errors:', result.errors);
|
|
370
|
+
}
|
|
371
|
+
console.warn('Warnings:', result.warnings);
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
**Checks:**
|
|
375
|
+
|
|
376
|
+
- Required fields (name, import, description)
|
|
377
|
+
- Props structure
|
|
378
|
+
- Examples count
|
|
379
|
+
- Best practices count
|
|
380
|
+
- Quick start examples
|
|
381
|
+
|
|
382
|
+
### Validate All Schemas
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
import { validateAllSchemas } from 'gd-design-library/ai';
|
|
386
|
+
|
|
387
|
+
const { results, summary } = validateAllSchemas();
|
|
388
|
+
|
|
389
|
+
console.log(`Valid: ${summary.valid}/${summary.total}`);
|
|
390
|
+
console.log(`Errors: ${summary.totalErrors}`);
|
|
391
|
+
console.log(`Warnings: ${summary.totalWarnings}`);
|
|
392
|
+
|
|
393
|
+
// Check specific component
|
|
394
|
+
const buttonResult = results.get('Button');
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Validate Generated Code
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
import { validateGeneratedCode } from 'gd-design-library/ai';
|
|
401
|
+
|
|
402
|
+
const generatedCode = `
|
|
403
|
+
import { Button } from 'gd-design-library';
|
|
404
|
+
|
|
405
|
+
export function MyButton() {
|
|
406
|
+
return <Button variant="primary">Click me</Button>;
|
|
407
|
+
}
|
|
408
|
+
`;
|
|
409
|
+
|
|
410
|
+
const result = validateGeneratedCode(generatedCode);
|
|
411
|
+
|
|
412
|
+
if (!result.valid) {
|
|
413
|
+
console.error('Code errors:', result.errors);
|
|
414
|
+
}
|
|
415
|
+
console.warn('Warnings:', result.warnings);
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
**Checks:**
|
|
419
|
+
|
|
420
|
+
- Imports are from `gd-design-library`
|
|
421
|
+
- Components exist in the library
|
|
422
|
+
- Warns about raw HTML elements
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
## Best Practices
|
|
427
|
+
|
|
428
|
+
### 1. Use Contextual Prompts for Complex Requests
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
// ✅ Good: Specific components
|
|
432
|
+
const prompt = buildContextualPrompt('Create a form', {
|
|
433
|
+
components: ['Form', 'Input', 'Button'],
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// ❌ Less efficient: Full catalog
|
|
437
|
+
const prompt = buildClaudeSystemPrompt('Create a form');
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### 2. Discover Components Before Prompting
|
|
441
|
+
|
|
442
|
+
```typescript
|
|
443
|
+
// ✅ Good: Discover first
|
|
444
|
+
const formComponents = discovery.searchComponents('form');
|
|
445
|
+
const prompt = buildContextualPrompt('Create a form', {
|
|
446
|
+
components: formComponents.map((c) => c.name),
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
// ❌ Less efficient: Guess components
|
|
450
|
+
const prompt = buildClaudeSystemPrompt('Create a form');
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### 3. Validate Generated Code
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
// ✅ Good: Validate after generation
|
|
457
|
+
const code = await generateCode(prompt);
|
|
458
|
+
const validation = validateGeneratedCode(code);
|
|
459
|
+
if (!validation.valid) {
|
|
460
|
+
// Handle errors
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// ❌ Risky: Use without validation
|
|
464
|
+
const code = await generateCode(prompt);
|
|
465
|
+
// Use code directly
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
### 4. Use Appropriate Agent Format
|
|
469
|
+
|
|
470
|
+
```typescript
|
|
471
|
+
// ✅ Good: Use correct format
|
|
472
|
+
const messages = buildGPT4Prompt('Create a form'); // For OpenAI
|
|
473
|
+
const request = buildGeminiPrompt('Create a form'); // For Gemini
|
|
474
|
+
|
|
475
|
+
// ❌ Wrong: Using wrong format
|
|
476
|
+
const prompt = buildClaudeSystemPrompt('Create a form'); // String format
|
|
477
|
+
// Won't work with OpenAI/Gemini APIs
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### 5. Leverage Schema Index
|
|
481
|
+
|
|
482
|
+
```typescript
|
|
483
|
+
// ✅ Good: Use index for quick lookups
|
|
484
|
+
const formControls = componentIndex.byCategory['Forms & Inputs'];
|
|
485
|
+
|
|
486
|
+
// ❌ Less efficient: Search every time
|
|
487
|
+
const formControls = discovery.searchComponents('form');
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### 6. Include Use Case Context
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
// ✅ Good: Specific use case
|
|
494
|
+
const prompt = buildClaudeSystemPrompt(
|
|
495
|
+
'Create a user registration form with email, password, and confirm password fields. Include validation and error messages.'
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
// ❌ Less clear: Vague request
|
|
499
|
+
const prompt = buildClaudeSystemPrompt('Create a form');
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
## Examples
|
|
505
|
+
|
|
506
|
+
### Example 1: Simple Form
|
|
507
|
+
|
|
508
|
+
```typescript
|
|
509
|
+
import { buildClaudeSystemPrompt } from 'gd-design-library/ai';
|
|
510
|
+
|
|
511
|
+
const prompt = buildClaudeSystemPrompt(
|
|
512
|
+
'Create a sign-in form with email and password fields, a submit button, and a link to sign up'
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
// Send to AI agent
|
|
516
|
+
const code = await generateCode(prompt);
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Example 2: Complex Component with Context
|
|
520
|
+
|
|
521
|
+
```typescript
|
|
522
|
+
import { buildContextualPrompt, discovery } from 'gd-design-library/ai';
|
|
523
|
+
|
|
524
|
+
// Discover Accordion components
|
|
525
|
+
const accordion = discovery.getComponent('Accordion');
|
|
526
|
+
const related = discovery.getRelatedComponents('Accordion');
|
|
527
|
+
|
|
528
|
+
// Build contextual prompt
|
|
529
|
+
const prompt = buildContextualPrompt('Create an FAQ section with accordion items', {
|
|
530
|
+
components: ['Accordion', ...related.map((c) => c.name)],
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
const code = await generateCode(prompt);
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
### Example 3: Multi-Agent Support
|
|
537
|
+
|
|
538
|
+
```typescript
|
|
539
|
+
import { buildGPT4Prompt, buildGeminiPrompt } from 'gd-design-library/ai';
|
|
540
|
+
|
|
541
|
+
// For OpenAI
|
|
542
|
+
const openaiMessages = buildGPT4Prompt('Create a dashboard layout');
|
|
543
|
+
const openaiResult = await openai.chat.completions.create({
|
|
544
|
+
model: 'gpt-4',
|
|
545
|
+
messages: openaiMessages,
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
// For Google Gemini
|
|
549
|
+
const geminiRequest = buildGeminiPrompt('Create a dashboard layout');
|
|
550
|
+
const geminiResult = await gemini.generateContent(geminiRequest);
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
### Example 4: Discovery-Driven Prompt
|
|
554
|
+
|
|
555
|
+
```typescript
|
|
556
|
+
import { discovery, getComponentsByCategory, buildContextualPrompt } from 'gd-design-library/ai';
|
|
557
|
+
|
|
558
|
+
// Find all form components
|
|
559
|
+
const formComponents = getComponentsByCategory('Forms & Inputs');
|
|
560
|
+
|
|
561
|
+
// Get related components
|
|
562
|
+
const relatedComponents = formComponents.flatMap((c) => discovery.getRelatedComponents(c.name));
|
|
563
|
+
|
|
564
|
+
// Build prompt with discovered components
|
|
565
|
+
const prompt = buildContextualPrompt('Create a comprehensive form', {
|
|
566
|
+
components: [...formComponents.map((c) => c.name), ...relatedComponents.map((c) => c.name)],
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
const code = await generateCode(prompt);
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
### Example 5: Validation Workflow
|
|
573
|
+
|
|
574
|
+
```typescript
|
|
575
|
+
import { buildClaudeSystemPrompt, validateGeneratedCode, validateAllSchemas } from 'gd-design-library/ai';
|
|
576
|
+
|
|
577
|
+
// Validate schemas first
|
|
578
|
+
const { summary } = validateAllSchemas();
|
|
579
|
+
if (summary.invalid > 0) {
|
|
580
|
+
console.error('Some schemas are invalid!');
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// Generate code
|
|
585
|
+
const prompt = buildClaudeSystemPrompt('Create a button');
|
|
586
|
+
const code = await generateCode(prompt);
|
|
587
|
+
|
|
588
|
+
// Validate generated code
|
|
589
|
+
const validation = validateGeneratedCode(code);
|
|
590
|
+
if (!validation.valid) {
|
|
591
|
+
console.error('Generated code has errors:', validation.errors);
|
|
592
|
+
// Retry or fix
|
|
593
|
+
} else if (validation.warnings.length > 0) {
|
|
594
|
+
console.warn('Warnings:', validation.warnings);
|
|
595
|
+
// Review warnings
|
|
596
|
+
} else {
|
|
597
|
+
// Use code
|
|
598
|
+
console.log('Code is valid!');
|
|
599
|
+
}
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
## Troubleshooting
|
|
605
|
+
|
|
606
|
+
### Issue: Prompt Too Long
|
|
607
|
+
|
|
608
|
+
**Problem:** Prompt exceeds token limits
|
|
609
|
+
|
|
610
|
+
**Solution:** Use contextual prompts with specific components
|
|
611
|
+
|
|
612
|
+
```typescript
|
|
613
|
+
// Instead of:
|
|
614
|
+
const prompt = buildClaudeSystemPrompt('Create a form');
|
|
615
|
+
|
|
616
|
+
// Use:
|
|
617
|
+
const prompt = buildContextualPrompt('Create a form', {
|
|
618
|
+
components: ['Form', 'Input', 'Button'],
|
|
619
|
+
});
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
### Issue: Wrong Component Names
|
|
623
|
+
|
|
624
|
+
**Problem:** AI uses components not in the library
|
|
625
|
+
|
|
626
|
+
**Solution:** Use discovery utilities to verify components
|
|
627
|
+
|
|
628
|
+
```typescript
|
|
629
|
+
const component = discovery.getComponent('Button');
|
|
630
|
+
if (!component) {
|
|
631
|
+
console.error('Component not found!');
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// Or validate generated code
|
|
635
|
+
const validation = validateGeneratedCode(code);
|
|
636
|
+
if (!validation.valid) {
|
|
637
|
+
// Check validation.errors
|
|
638
|
+
}
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
### Issue: Missing Guardrails
|
|
642
|
+
|
|
643
|
+
**Problem:** Generated code violates constraints
|
|
644
|
+
|
|
645
|
+
**Solution:** Guardrails are automatically included, but verify they're extracted
|
|
646
|
+
|
|
647
|
+
```typescript
|
|
648
|
+
// Guardrails are automatically extracted from schemas
|
|
649
|
+
// Check component schema has CRITICAL/IMPORTANT notes in bestPractices
|
|
650
|
+
const component = discovery.getComponent('Icon');
|
|
651
|
+
console.log(component?.bestPractices);
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
### Issue: Wrong Agent Format
|
|
655
|
+
|
|
656
|
+
**Problem:** Using Claude format with GPT-4/Gemini
|
|
657
|
+
|
|
658
|
+
**Solution:** Use agent-specific prompt builders
|
|
659
|
+
|
|
660
|
+
```typescript
|
|
661
|
+
// ❌ Wrong
|
|
662
|
+
const prompt = buildClaudeSystemPrompt('Create a form'); // String
|
|
663
|
+
const result = await openai.chat.completions.create({
|
|
664
|
+
messages: [{ role: 'user', content: prompt }], // Wrong format
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
// ✅ Correct
|
|
668
|
+
const messages = buildGPT4Prompt('Create a form'); // Array
|
|
669
|
+
const result = await openai.chat.completions.create({
|
|
670
|
+
messages, // Correct format
|
|
671
|
+
});
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
### Issue: Components Not Found
|
|
675
|
+
|
|
676
|
+
**Problem:** Discovery returns empty results
|
|
677
|
+
|
|
678
|
+
**Solution:** Check component names and categories
|
|
679
|
+
|
|
680
|
+
```typescript
|
|
681
|
+
// Verify component exists
|
|
682
|
+
const allComponents = componentIndex.byCategory;
|
|
683
|
+
console.log('Available categories:', Object.keys(allComponents));
|
|
684
|
+
|
|
685
|
+
// Search with different queries
|
|
686
|
+
const results1 = discovery.searchComponents('input');
|
|
687
|
+
const results2 = discovery.searchComponents('form');
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
### Issue: Validation Fails
|
|
691
|
+
|
|
692
|
+
**Problem:** Generated code fails validation
|
|
693
|
+
|
|
694
|
+
**Solution:** Check errors and retry with more specific prompt
|
|
695
|
+
|
|
696
|
+
```typescript
|
|
697
|
+
const validation = validateGeneratedCode(code);
|
|
698
|
+
if (!validation.valid) {
|
|
699
|
+
console.error('Errors:', validation.errors);
|
|
700
|
+
|
|
701
|
+
// Retry with more specific prompt
|
|
702
|
+
const betterPrompt = buildContextualPrompt(userRequest, {
|
|
703
|
+
components: ['Form', 'Input', 'Button'], // Be specific
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
---
|
|
709
|
+
|
|
710
|
+
## Quick Reference
|
|
711
|
+
|
|
712
|
+
### Prompt Builders
|
|
713
|
+
|
|
714
|
+
| Function | Use Case | Returns |
|
|
715
|
+
| ----------------------------------------- | -------------------------------- | ---------------- |
|
|
716
|
+
| `buildClaudeSystemPrompt(request)` | Standard prompts for Claude | `string` |
|
|
717
|
+
| `buildContextualPrompt(request, context)` | Prompts with specific components | `string` |
|
|
718
|
+
| `buildGPT4Prompt(request)` | Prompts for OpenAI GPT-4 | `Array<Message>` |
|
|
719
|
+
| `buildGeminiPrompt(request)` | Prompts for Google Gemini | `GeminiRequest` |
|
|
720
|
+
|
|
721
|
+
### Discovery Functions
|
|
722
|
+
|
|
723
|
+
| Function | Use Case | Returns |
|
|
724
|
+
| -------------------------------------- | ---------------------- | ------------------------------ |
|
|
725
|
+
| `discovery.getComponent(name)` | Get component by name | `ComponentSchema \| undefined` |
|
|
726
|
+
| `discovery.searchComponents(query)` | Search components | `ComponentSchema[]` |
|
|
727
|
+
| `getComponentsByCategory(category)` | Get by category | `ComponentSchema[]` |
|
|
728
|
+
| `getComponentsByFeature(feature)` | Get by feature | `ComponentSchema[]` |
|
|
729
|
+
| `getComponentsByUseCase(useCase)` | Get by use case | `ComponentSchema[]` |
|
|
730
|
+
| `discovery.getRelatedComponents(name)` | Get related components | `ComponentSchema[]` |
|
|
731
|
+
| `findPatterns(components, useCase?)` | Find patterns | `Pattern[]` |
|
|
732
|
+
|
|
733
|
+
### Validation Functions
|
|
734
|
+
|
|
735
|
+
| Function | Use Case | Returns |
|
|
736
|
+
| ----------------------------- | ------------------------- | ---------------------- |
|
|
737
|
+
| `validateSchema(schema)` | Validate component schema | `ValidationResult` |
|
|
738
|
+
| `validateAllSchemas()` | Validate all schemas | `{ results, summary }` |
|
|
739
|
+
| `validateGeneratedCode(code)` | Validate generated code | `ValidationResult` |
|
|
740
|
+
|
|
741
|
+
---
|
|
742
|
+
|
|
743
|
+
## Additional Resources
|
|
744
|
+
|
|
745
|
+
- [AI README](./README.md) - Detailed AI integration docs
|
|
746
|
+
- [llms.txt](../../llms.txt) - LLM-friendly documentation
|
|
747
|
+
|
|
748
|
+
---
|
|
749
|
+
|
|
750
|
+
## Summary
|
|
751
|
+
|
|
752
|
+
This manual covers:
|
|
753
|
+
|
|
754
|
+
1. ✅ Basic prompt usage with `buildClaudeSystemPrompt`
|
|
755
|
+
2. ✅ Contextual prompts for better accuracy
|
|
756
|
+
3. ✅ Agent-specific formats (Claude, GPT-4, Gemini)
|
|
757
|
+
4. ✅ Discovery utilities for finding components
|
|
758
|
+
5. ✅ Validation for schemas and generated code
|
|
759
|
+
6. ✅ Best practices and examples
|
|
760
|
+
7. ✅ Troubleshooting common issues
|
|
761
|
+
|
|
762
|
+
By following this manual, you'll be able to effectively use the GridKit Design System's AI integration to generate reliable, consistent React components.
|