Skip to content

Commit 09e32b4

Browse files
committed
update system prompt and modal
1 parent 01f77d9 commit 09e32b4

File tree

2 files changed

+98
-81
lines changed

2 files changed

+98
-81
lines changed

app/src/components/ConversationalGenerator.tsx

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { useState, useRef, useEffect } from 'react';
44
import { Send, Loader2, Save, Cpu, X, AlertTriangle, Clipboard } from 'lucide-react';
55
import { sendPrompt } from '@utils/sendApi';
6-
import { CompleteAgent } from '@utils/agent_database';
6+
import { CompleteAgent, updateAgentImageMemory } from '@utils/agent_database';
77
import { extractAgentConfig, parseAgentResponse, extractImageRequest } from '@utils/agentParser';
88
import MediaUploadMessage from './MediaUploadMessage';
99
import getConversationalSystemPrompt from '@utils/conversational_system_prompt';
@@ -203,6 +203,11 @@ What would you like to create today?`
203203
const [isLoading, setIsLoading] = useState(false);
204204
const chatEndRef = useRef<HTMLDivElement>(null);
205205

206+
// Auto-scroll to bottom when new messages are added
207+
useEffect(() => {
208+
chatEndRef.current?.scrollIntoView({ behavior: 'smooth' });
209+
}, [messages]);
210+
206211
// --- STATE FOR MODAL AND LOCAL MODEL SELECTION ---
207212
const [isLocalModalOpen, setIsLocalModalOpen] = useState(false);
208213
const [selectedLocalModel, setSelectedLocalModel] = useState('');
@@ -236,22 +241,54 @@ What would you like to create today?`
236241
// Check for agent config first (priority)
237242
const agentConfig = extractAgentConfig(responseText);
238243
if (agentConfig) {
239-
const responseMessage: Message = {
240-
id: Date.now() + 1,
244+
// Extract text outside $$$ blocks
245+
const textOutsideBlocks = responseText.replace(/\$\$\$\s*\n?[\s\S]*?\n?\$\$\$/g, '').trim();
246+
247+
const newMessages: Message[] = [];
248+
249+
// Add regular AI message if there's text outside the $$$ blocks
250+
if (textOutsideBlocks) {
251+
newMessages.push({
252+
id: Date.now() + 1,
253+
text: textOutsideBlocks,
254+
sender: 'ai',
255+
});
256+
}
257+
258+
// Add system message
259+
newMessages.push({
260+
id: Date.now() + 2,
241261
text: agentConfig,
242262
sender: 'system',
243-
};
244-
setMessages(prev => [...prev, responseMessage]);
263+
});
264+
265+
setMessages(prev => [...prev, ...newMessages]);
245266
} else {
246267
// Check for image request
247268
const imageRequest = extractImageRequest(responseText);
248269
if (imageRequest) {
249-
const responseMessage: Message = {
250-
id: Date.now() + 1,
270+
// Extract text outside %%% blocks
271+
const textOutsideBlocks = responseText.replace(/%%%\s*\n?[\s\S]*?\n?%%%/g, '').trim();
272+
273+
const newMessages: Message[] = [];
274+
275+
// Add regular AI message if there's text outside the %%% blocks
276+
if (textOutsideBlocks) {
277+
newMessages.push({
278+
id: Date.now() + 1,
279+
text: textOutsideBlocks,
280+
sender: 'ai',
281+
});
282+
}
283+
284+
// Add image request message
285+
newMessages.push({
286+
id: Date.now() + 2,
251287
text: imageRequest,
252288
sender: 'image-request',
253-
};
254-
setMessages(prev => [...prev, responseMessage]);
289+
});
290+
291+
setMessages(prev => [...prev, ...newMessages]);
255292
} else {
256293
// Regular AI response
257294
const responseMessage: Message = {
@@ -289,9 +326,18 @@ What would you like to create today?`
289326
await sendConversation(allMessages);
290327
};
291328

292-
const handleConfigureAndSave = (configText: string) => {
329+
const handleConfigureAndSave = async (configText: string) => {
293330
const parsed = parseAgentResponse(configText);
294331
if (parsed) {
332+
// Collect all images from the conversation and store them for the agent
333+
const images = messages
334+
.filter(msg => msg.imageData)
335+
.map(msg => msg.imageData!);
336+
337+
if (images.length > 0) {
338+
await updateAgentImageMemory(parsed.agent.id, images);
339+
}
340+
295341
onAgentGenerated(parsed.agent, parsed.code);
296342
} else {
297343
setMessages(prev => [...prev, { id: Date.now(), sender: 'ai', text: "I'm sorry, there was an error parsing that. Could you try describing your agent again?" }]);

0 commit comments

Comments
 (0)