Skip to content

Commit b284c35

Browse files
committed
Fix chat multi-turn fallback + mobile UI tweaks
- Wrap plain-text assistant history in JSON before sending to Nova Lite (prevents model from dropping JSON output mode after 2-3 turns) - Reset fallbackMode flag when AI responds successfully - Chat container fills viewport, input bar closer to bottom nav - Bottom nav icon-label gap increased for better touch targets
1 parent 67bbe75 commit b284c35

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

app/api/chat/conversation/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,14 @@ export async function POST(req: NextRequest) {
268268

269269
for (const msg of messages) {
270270
if (msg.role === "assistant") {
271+
// Wrap plain-text assistant messages in JSON so Nova stays in JSON-output mode
272+
const isJson = msg.content.trimStart().startsWith("{");
273+
const wrapped = isJson
274+
? msg.content
275+
: JSON.stringify({ text: msg.content, turnType: "question", expectsResponse: true, responseRelevance: 0.5, shouldEnd: false, domain: "general", action: null });
271276
novaMessages.push({
272277
role: "assistant",
273-
content: [{ text: msg.content }],
278+
content: [{ text: wrapped }],
274279
});
275280
} else {
276281
novaMessages.push({

app/components/BottomNav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function BottomNav() {
5050
display: "flex",
5151
flexDirection: "column",
5252
alignItems: "center",
53-
gap: 2,
53+
gap: 4,
5454
textDecoration: "none",
5555
color: isActive ? "var(--sage-600)" : "var(--text-muted)",
5656
minWidth: 56,

app/kid-dashboard/chat/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export default function ChatPage() {
9292
});
9393
if (!res.ok) throw new Error("API error");
9494
const data = await res.json();
95-
if (data.fallback) setFallbackMode(true);
95+
setFallbackMode(!!data.fallback);
9696
return { text: data.text || "That was fun! Let's talk again soon!", shouldEnd: data.metadata?.shouldEnd === true };
9797
} catch {
9898
setFallbackMode(true);
@@ -230,7 +230,7 @@ export default function ChatPage() {
230230
</div>
231231
</nav>
232232

233-
<div className="main fade fade-1" style={{ maxWidth: 600, padding: "32px 24px 80px" }}>
233+
<div className="main fade fade-1" style={{ maxWidth: 600, padding: "32px 24px 80px", display: "flex", flexDirection: "column", flex: 1 }}>
234234

235235
{/* ---- AVATAR SELECTION SCREEN ---- */}
236236
{screen === "select" && (
@@ -286,7 +286,7 @@ export default function ChatPage() {
286286

287287
{/* ---- CHAT SCREEN ---- */}
288288
{screen === "chat" && animalInfo && animal && (
289-
<div className="fade fade-2" style={{ display: "flex", flexDirection: "column", minHeight: "60vh" }}>
289+
<div className="fade fade-2" style={{ display: "flex", flexDirection: "column", flex: 1, minHeight: 0 }}>
290290
{/* Avatar header */}
291291
<div style={{ display: "flex", flexDirection: "column", alignItems: "center", marginBottom: 16 }}>
292292
<AnimalAvatar animal={animal} gender="boy"state={avatarState} size={120} />
@@ -314,7 +314,7 @@ export default function ChatPage() {
314314
{/* Messages container */}
315315
<div style={{
316316
flex: 1, overflowY: "auto", display: "flex", flexDirection: "column",
317-
gap: 12, padding: "12px 0", marginBottom: 16, maxHeight: "40vh",
317+
gap: 12, padding: "12px 0", marginBottom: 8, minHeight: 0,
318318
}}>
319319
{messages.map((msg, i) => (
320320
<div key={i} style={{ display: "flex", justifyContent: msg.role === "assistant" ? "flex-start" : "flex-end" }}>

0 commit comments

Comments
 (0)