@feardread/fear 1.0.4 → 1.0.6

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.
@@ -0,0 +1,30 @@
1
+
2
+
3
+ async function webSearch(query) {
4
+ // Implement web search functionality
5
+ console.log('Searching for:', query);
6
+ return { results: [] };
7
+ }
8
+
9
+ const fs = require('fs').promises;
10
+
11
+ async function readFile(path) {
12
+ try {
13
+ const content = await fs.readFile(path, 'utf8');
14
+ return { success: true, content };
15
+ } catch (error) {
16
+ return { success: false, error: error.message };
17
+ }
18
+ }
19
+
20
+ async function queryDatabase(query) {
21
+ // Implement database query functionality
22
+ console.log('Querying database:', query);
23
+ return { rows: [] };
24
+ }
25
+
26
+ module.exports = function () {
27
+ return {
28
+
29
+ }
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feardread/fear",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,341 @@
1
+
2
+ module.exports = (fear) => {
3
+ const router = fear.createRouter();
4
+ const logger = fear.getLogger();
5
+ const handler = fear.getHandler();
6
+
7
+ router.post('/generate', handler.async((req, res) => {
8
+ const { formData } = req.body;
9
+
10
+ const toolImplementations = {
11
+ web_search: `
12
+ async function webSearch(query) {
13
+ // Implement web search functionality
14
+ console.log('Searching for:', query);
15
+ return { results: [] };
16
+ }`,
17
+ file_read: `
18
+ const fs = require('fs').promises;
19
+
20
+ async function readFile(path) {
21
+ try {
22
+ const content = await fs.readFile(path, 'utf8');
23
+ return { success: true, content };
24
+ } catch (error) {
25
+ return { success: false, error: error.message };
26
+ }
27
+ }`,
28
+ calculator: `
29
+ function calculate(expression) {
30
+ try {
31
+ return { result: eval(expression) };
32
+ } catch (error) {
33
+ return { error: 'Invalid expression' };
34
+ }
35
+ }`,
36
+ database: `
37
+ async function queryDatabase(query) {
38
+ // Implement database query functionality
39
+ console.log('Querying database:', query);
40
+ return { rows: [] };
41
+ }`
42
+ };
43
+
44
+ const selectedTools = (formData.tools || []).map(t => toolImplementations[t] || '').join('\n');
45
+ const chatRoute = `
46
+ router.post('/chat', handler.async((req, res) => {
47
+ const { message, conversationHistory = [] } = req.body;
48
+ const messages = [
49
+ ...conversationHistory,
50
+ { role: 'user', content: message }
51
+ ];
52
+
53
+ return anthropic.messages.create({
54
+ model: AGENT_CONFIG.model,
55
+ max_tokens: 1024,
56
+ system: SYSTEM_PROMPT,
57
+ messages: messages
58
+ })
59
+ .then((response) => {
60
+ const assistantMessage = response.content[0].text;
61
+ return handler.success(res, {
62
+ success: true,
63
+ output: assistantMessage,
64
+ conversationHistory: [
65
+ ...messages,
66
+ { role: 'assistant', content: assistantMessage }
67
+ ]
68
+ })
69
+ })
70
+ .catch((error) => {
71
+ logger.error('Error:', error);
72
+ return handler.error(res, {
73
+ success: false,
74
+ error: error.message
75
+ })
76
+ });
77
+ }));`;
78
+ const serverCode = `// ${formData.agentName || 'Custom AI Agent'}
79
+ // Generated by AI Agent Builder
80
+ // ${formData.agentDescription || 'No description provided'}
81
+
82
+ require('dotenv').config();
83
+ const Fear = require('@feardread/fear');
84
+ const Anthropic = require('@anthropic-ai/sdk');
85
+
86
+ const app = express();
87
+ app.use(express.json());
88
+ app.use(express.static('public'));
89
+
90
+ const anthropic = new Anthropic({
91
+ apiKey: process.env.ANTHROPIC_API_KEY || '${formData.apiKey || ''}'
92
+ });
93
+
94
+ const AGENT_CONFIG = {
95
+ name: '${formData.agentName || 'Custom Agent'}',
96
+ description: '${formData.agentDescription || 'AI Assistant'}',
97
+ personality: '${formData.personality || 'professional'}',
98
+ model: '${formData.model || 'claude-sonnet-4-20250514'}'
99
+ };
100
+
101
+ const SYSTEM_PROMPT = \`You are \${AGENT_CONFIG.name}, \${AGENT_CONFIG.description}.
102
+ Your primary function is: ${formData.primaryFunction || 'assist users with their requests'}.
103
+ Personality: \${AGENT_CONFIG.personality}.
104
+ ${(formData.tools || []).length > 0 ? `Available tools: ${formData.tools.join(', ')}` : ''}
105
+ \`;
106
+ ${selectedTools}
107
+ ${chatRoute}
108
+ // Serve the frontend
109
+ app.get('/', (req, res) => {
110
+ res.send(\`
111
+ <!DOCTYPE html>
112
+ <html>
113
+ <head>
114
+ <title>\${AGENT_CONFIG.name}</title>
115
+ <style>
116
+ * { margin: 0; padding: 0; box-sizing: border-box; }
117
+ body {
118
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
119
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
120
+ min-height: 100vh;
121
+ display: flex;
122
+ justify-content: center;
123
+ align-items: center;
124
+ padding: 20px;
125
+ }
126
+ .container {
127
+ background: white;
128
+ border-radius: 20px;
129
+ box-shadow: 0 20px 60px rgba(0,0,0,0.3);
130
+ width: 100%;
131
+ max-width: 800px;
132
+ height: 600px;
133
+ display: flex;
134
+ flex-direction: column;
135
+ }
136
+ .header {
137
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
138
+ color: white;
139
+ padding: 20px;
140
+ border-radius: 20px 20px 0 0;
141
+ text-align: center;
142
+ }
143
+ .chat-container {
144
+ flex: 1;
145
+ overflow-y: auto;
146
+ padding: 20px;
147
+ display: flex;
148
+ flex-direction: column;
149
+ gap: 15px;
150
+ }
151
+ .message {
152
+ padding: 12px 16px;
153
+ border-radius: 12px;
154
+ max-width: 70%;
155
+ word-wrap: break-word;
156
+ }
157
+ .user-message {
158
+ background: #667eea;
159
+ color: white;
160
+ align-self: flex-end;
161
+ }
162
+ .assistant-message {
163
+ background: #f0f0f0;
164
+ color: #333;
165
+ align-self: flex-start;
166
+ }
167
+ .input-container {
168
+ padding: 20px;
169
+ border-top: 1px solid #eee;
170
+ display: flex;
171
+ gap: 10px;
172
+ }
173
+ input {
174
+ flex: 1;
175
+ padding: 12px;
176
+ border: 2px solid #ddd;
177
+ border-radius: 10px;
178
+ font-size: 16px;
179
+ }
180
+ button {
181
+ padding: 12px 24px;
182
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
183
+ color: white;
184
+ border: none;
185
+ border-radius: 10px;
186
+ cursor: pointer;
187
+ font-size: 16px;
188
+ font-weight: 600;
189
+ }
190
+ button:hover { opacity: 0.9; }
191
+ button:disabled {
192
+ opacity: 0.5;
193
+ cursor: not-allowed;
194
+ }
195
+ </style>
196
+ </head>
197
+ <body>
198
+ <div class="container">
199
+ <div class="header">
200
+ <h1>\${AGENT_CONFIG.name}</h1>
201
+ <p>\${AGENT_CONFIG.description}</p>
202
+ </div>
203
+ <div class="chat-container" id="chatContainer"></div>
204
+ <div class="input-container">
205
+ <input type="text" id="messageInput" placeholder="Type your message..." />
206
+ <button onclick="sendMessage()" id="sendBtn">Send</button>
207
+ </div>
208
+ </div>
209
+
210
+ <script>
211
+ let conversationHistory = [];
212
+
213
+ async function sendMessage() {
214
+ const input = document.getElementById('messageInput');
215
+ const message = input.value.trim();
216
+ if (!message) return;
217
+
218
+ const sendBtn = document.getElementById('sendBtn');
219
+ sendBtn.disabled = true;
220
+
221
+ addMessage(message, 'user');
222
+ input.value = '';
223
+
224
+ try {
225
+ const response = await fetch('/chat', {
226
+ method: 'POST',
227
+ headers: { 'Content-Type': 'application/json' },
228
+ body: JSON.stringify({ message, conversationHistory })
229
+ });
230
+
231
+ const data = await response.json();
232
+
233
+ if (data.success) {
234
+ addMessage(data.response, 'assistant');
235
+ conversationHistory = data.conversationHistory;
236
+ } else {
237
+ addMessage('Error: ' + data.error, 'assistant');
238
+ }
239
+ } catch (error) {
240
+ addMessage('Error: ' + error.message, 'assistant');
241
+ }
242
+
243
+ sendBtn.disabled = false;
244
+ }
245
+
246
+ function addMessage(text, type) {
247
+ const container = document.getElementById('chatContainer');
248
+ const div = document.createElement('div');
249
+ div.className = \`message \${type}-message\`;
250
+ div.textContent = text;
251
+ container.appendChild(div);
252
+ container.scrollTop = container.scrollHeight;
253
+ }
254
+
255
+ document.getElementById('messageInput').addEventListener('keypress', (e) => {
256
+ if (e.key === 'Enter') sendMessage();
257
+ });
258
+ </script>
259
+ </body>
260
+ </html>
261
+ \`);
262
+ });
263
+
264
+ const PORT = process.env.PORT || ${formData.port || '3000'};
265
+ app.listen(PORT, () => {
266
+ console.log(\`🤖 \${AGENT_CONFIG.name} running on http://localhost:\${PORT}\`);
267
+ console.log(\`📝 Description: \${AGENT_CONFIG.description}\`);
268
+ console.log(\`🎭 Personality: \${AGENT_CONFIG.personality}\`);
269
+ });
270
+ `;
271
+
272
+ const packageJson = {
273
+ name: (formData.agentName || 'custom-ai-agent').toLowerCase().replace(/\s+/g, '-'),
274
+ version: '1.0.0',
275
+ description: formData.agentDescription || 'Custom AI Agent',
276
+ main: 'server.js',
277
+ scripts: {
278
+ start: 'node server.js',
279
+ dev: 'nodemon server.js'
280
+ },
281
+ dependencies: {
282
+ '@feardread/fear': '^*',
283
+ '@anthropic-ai/sdk': '^0.32.0',
284
+ 'express': '^4.18.2',
285
+ 'dotenv': '^16.3.1'
286
+ },
287
+ devDependencies: {
288
+ 'nodemon': '^3.0.1'
289
+ }
290
+ };
291
+
292
+ const readme = `# ${formData.agentName || 'Custom AI Agent'}
293
+
294
+ ${formData.agentDescription || 'AI Agent generated by AI Agent Builder'}
295
+
296
+ ## Setup
297
+
298
+ 1. Install dependencies:
299
+ \`\`\`bash
300
+ npm install
301
+ \`\`\`
302
+
303
+ 2. Create a \`.env\` file:
304
+ \`\`\`
305
+ ANTHROPIC_API_KEY=your_api_key_here
306
+ PORT=${formData.port || '3000'}
307
+ \`\`\`
308
+
309
+ 3. Run the agent:
310
+ \`\`\`bash
311
+ npm start
312
+ \`\`\`
313
+
314
+ 4. Open http://localhost:${formData.port || '3000'} in your browser
315
+
316
+ ## Features
317
+
318
+ - **Primary Function**: ${formData.primaryFunction || 'General assistance'}
319
+ - **Personality**: ${formData.personality || 'professional'}
320
+ - **Model**: ${formData.model || 'claude-sonnet-4-20250514'}
321
+ ${(formData.tools || []).length > 0 ? `- **Tools**: ${formData.tools.join(', ')}` : ''}
322
+
323
+ ## Configuration
324
+
325
+ Edit the \`AGENT_CONFIG\` object in \`server.js\` to customize the agent's behavior.
326
+ `;
327
+ const envExample = `ANTHROPIC_API_KEY=your_api_key_here\nPORT=${formData.port || '3000'}`;
328
+
329
+ return handler.success(res, {
330
+ success: true,
331
+ files: {
332
+ 'server.js': serverCode,
333
+ 'package.json': JSON.stringify(packageJson, null, 2),
334
+ 'README.md': readme,
335
+ '.env.example': envExample
336
+ }
337
+ })
338
+ }));
339
+
340
+ return router;
341
+ }