Skip to content

Commit b318e95

Browse files
committed
Fix: clarifying responses now update pending brief
1 parent 5698c51 commit b318e95

1 file changed

Lines changed: 37 additions & 11 deletions

File tree

  • content-gen/src/app/frontend/src

content-gen/src/app/frontend/src/App.tsx

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function App() {
4747
// Brief confirmation flow
4848
const [pendingBrief, setPendingBrief] = useState<CreativeBrief | null>(null);
4949
const [confirmedBrief, setConfirmedBrief] = useState<CreativeBrief | null>(null);
50+
const [awaitingClarification, setAwaitingClarification] = useState<boolean>(false);
5051

5152
// Product selection
5253
const [selectedProducts, setSelectedProducts] = useState<Product[]>([]);
@@ -113,6 +114,7 @@ function App() {
113114
}));
114115
setMessages(loadedMessages);
115116
setPendingBrief(null);
117+
setAwaitingClarification(false);
116118
setConfirmedBrief(data.brief || null);
117119

118120
if (data.generated_content) {
@@ -176,6 +178,7 @@ function App() {
176178
setConversationId(uuidv4());
177179
setMessages([]);
178180
setPendingBrief(null);
181+
setAwaitingClarification(false);
179182
setConfirmedBrief(null);
180183
setGeneratedContent(null);
181184
setSelectedProducts([]);
@@ -202,11 +205,12 @@ function App() {
202205

203206
// If we have a pending brief and user is providing feedback, update the brief
204207
if (pendingBrief && !confirmedBrief) {
205-
// User is refining the brief conversationally
208+
// User is refining the brief or providing clarification
206209
const refinementKeywords = ['change', 'update', 'modify', 'add', 'remove', 'delete', 'set', 'make', 'should be'];
207210
const isRefinement = refinementKeywords.some(kw => content.toLowerCase().includes(kw));
208211

209-
if (isRefinement) {
212+
// If awaiting clarification, treat ANY response as a brief update
213+
if (isRefinement || awaitingClarification) {
210214
// Send the refinement request to update the brief
211215
// Combine original brief context with the refinement request
212216
const refinementPrompt = `Current creative brief:\n${JSON.stringify(pendingBrief, null, 2)}\n\nUser requested change: ${content}\n\nPlease update the brief accordingly and return the complete updated brief.`;
@@ -216,16 +220,34 @@ function App() {
216220
if (parsed.brief) {
217221
setPendingBrief(parsed.brief);
218222
}
219-
setGenerationStatus('');
220223

221-
const assistantMessage: ChatMessage = {
222-
id: uuidv4(),
223-
role: 'assistant',
224-
content: "I've updated the brief based on your feedback. Please review the changes above. Let me know if you'd like any other modifications, or click **Confirm Brief** when you're satisfied.",
225-
agent: 'PlanningAgent',
226-
timestamp: new Date().toISOString(),
227-
};
228-
setMessages(prev => [...prev, assistantMessage]);
224+
// Check if we still need more clarification
225+
if (parsed.requires_clarification && parsed.clarifying_questions) {
226+
setAwaitingClarification(true);
227+
setGenerationStatus('');
228+
229+
const assistantMessage: ChatMessage = {
230+
id: uuidv4(),
231+
role: 'assistant',
232+
content: parsed.clarifying_questions,
233+
agent: 'PlanningAgent',
234+
timestamp: new Date().toISOString(),
235+
};
236+
setMessages(prev => [...prev, assistantMessage]);
237+
} else {
238+
// Brief is now complete
239+
setAwaitingClarification(false);
240+
setGenerationStatus('');
241+
242+
const assistantMessage: ChatMessage = {
243+
id: uuidv4(),
244+
role: 'assistant',
245+
content: "I've updated the brief based on your feedback. Please review the changes above. Let me know if you'd like any other modifications, or click **Confirm Brief** when you're satisfied.",
246+
agent: 'PlanningAgent',
247+
timestamp: new Date().toISOString(),
248+
};
249+
setMessages(prev => [...prev, assistantMessage]);
250+
}
229251
} else {
230252
// General question or comment while brief is pending
231253
let fullContent = '';
@@ -307,6 +329,7 @@ function App() {
307329
if (parsed.brief) {
308330
setPendingBrief(parsed.brief);
309331
}
332+
setAwaitingClarification(true);
310333
setGenerationStatus('');
311334

312335
const assistantMessage: ChatMessage = {
@@ -322,6 +345,7 @@ function App() {
322345
if (parsed.brief) {
323346
setPendingBrief(parsed.brief);
324347
}
348+
setAwaitingClarification(false);
325349
setGenerationStatus('');
326350

327351
const assistantMessage: ChatMessage = {
@@ -410,6 +434,7 @@ function App() {
410434
await confirmBrief(pendingBrief, conversationId, userId);
411435
setConfirmedBrief(pendingBrief);
412436
setPendingBrief(null);
437+
setAwaitingClarification(false);
413438

414439
const productsResponse = await fetch('/api/products');
415440
if (productsResponse.ok) {
@@ -432,6 +457,7 @@ function App() {
432457

433458
const handleBriefCancel = useCallback(() => {
434459
setPendingBrief(null);
460+
setAwaitingClarification(false);
435461
const assistantMessage: ChatMessage = {
436462
id: uuidv4(),
437463
role: 'assistant',

0 commit comments

Comments
 (0)