-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockAI.ts
More file actions
135 lines (111 loc) · 3.79 KB
/
mockAI.ts
File metadata and controls
135 lines (111 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
export const mockAIResponses: Record<string, string> = {
'html boilerplate': `Here's a modern HTML5 boilerplate:
\`\`\`html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your App</title>
</head>
<body>
<div id="app"></div>
</body>
</html>
\`\`\``,
'readme': `# Project Name
## Overview
Brief description of your project and its purpose.
## Features
- Feature 1
- Feature 2
- Feature 3
## Tech Stack
- Frontend: React, TypeScript, Tailwind CSS
- Backend: Node.js
- Database: PostgreSQL
## Getting Started
\`\`\`bash
npm install
npm run dev
\`\`\`
## Team
List your team members and their roles.`,
'api': `Here's a sample REST API structure:
\`\`\`javascript
// GET /api/users
app.get('/api/users', async (req, res) => {
const users = await db.query('SELECT * FROM users');
res.json(users);
});
// POST /api/users
app.post('/api/users', async (req, res) => {
const { name, email } = req.body;
const result = await db.query(
'INSERT INTO users (name, email) VALUES ($1, $2) RETURNING *',
[name, email]
);
res.json(result.rows[0]);
});
\`\`\``,
'name': `Based on your project concept, here are some suggested names:
- TaskFlow Pro
- DevSync Hub
- BuildMate
- CodeCraft Studio
- TeamForge AI`,
'component': `Here's a reusable React component template:
\`\`\`typescript
interface Props {
title: string;
onAction: () => void;
}
export const Card = ({ title, onAction }: Props) => {
return (
<div className="bg-white rounded-lg shadow p-6">
<h3 className="text-xl font-bold mb-4">{title}</h3>
<button
onClick={onAction}
className="bg-blue-600 text-white px-4 py-2 rounded"
>
Action
</button>
</div>
);
};
\`\`\``,
'test': `Here's a sample test structure:
\`\`\`typescript
import { describe, it, expect } from 'vitest';
describe('Component', () => {
it('renders correctly', () => {
const result = render(<Component />);
expect(result).toBeTruthy();
});
it('handles user interaction', () => {
const mockFn = vi.fn();
const { getByText } = render(<Component onClick={mockFn} />);
fireEvent.click(getByText('Click me'));
expect(mockFn).toHaveBeenCalled();
});
});
\`\`\``
};
export const getAIResponse = (query: string): string => {
const lowerQuery = query.toLowerCase();
for (const [key, response] of Object.entries(mockAIResponses)) {
if (lowerQuery.includes(key)) {
return response;
}
}
if (lowerQuery.includes('help') || lowerQuery.includes('how')) {
return "I can help you with:\n- Generating code snippets (HTML, React, API)\n- Creating README documentation\n- Suggesting project names\n- Writing test cases\n- Best practices and architecture advice\n\nWhat would you like assistance with?";
}
if (lowerQuery.includes('bug') || lowerQuery.includes('error')) {
return "To debug effectively:\n1. Check console for error messages\n2. Verify data flow and state management\n3. Use browser DevTools for inspection\n4. Add console.log statements to trace execution\n5. Check network requests in Network tab\n\nWhat specific error are you encountering?";
}
if (lowerQuery.includes('optimize') || lowerQuery.includes('performance')) {
return "Performance optimization tips:\n- Use React.memo() for expensive components\n- Implement lazy loading for routes\n- Optimize images and assets\n- Minimize bundle size with code splitting\n- Use efficient data structures and algorithms\n- Cache API responses when appropriate";
}
return `I understand you're asking about: "${query}"\n\nI can assist with code generation, debugging, architecture decisions, and best practices. Try asking me to:\n- Generate specific code snippets\n- Review your approach\n- Suggest improvements\n- Create documentation`;
};