Persist Atlas chat history; fix re-greeting on refresh
- GET /api/projects/[id]/atlas-chat returns stored user+assistant messages - POST handles __atlas_init__ trigger: runs once when no history exists, not stored as a user turn so Atlas intro appears cleanly - Rewrite AtlasChat.tsx: fully self-contained component with own message state; loads history from DB on mount, only greets on first open - Remove assistant-ui runtime dependency for message persistence - Add Vision & Success Metrics, Integrations & Dependencies, Open Questions to PRD section tracker (now 12 sections matching the PDF) Made-with: Cursor
This commit is contained in:
@@ -6,13 +6,16 @@ import { useParams } from "next/navigation";
|
||||
const PRD_SECTIONS = [
|
||||
{ id: "executive_summary", label: "Executive Summary" },
|
||||
{ id: "problem_statement", label: "Problem Statement" },
|
||||
{ id: "vision_metrics", label: "Vision & Success Metrics" },
|
||||
{ id: "users_personas", label: "Users & Personas" },
|
||||
{ id: "user_flows", label: "User Flows" },
|
||||
{ id: "feature_requirements", label: "Feature Requirements" },
|
||||
{ id: "screen_specs", label: "Screen Specs" },
|
||||
{ id: "business_model", label: "Business Model" },
|
||||
{ id: "integrations", label: "Integrations & Dependencies" },
|
||||
{ id: "non_functional", label: "Non-Functional Reqs" },
|
||||
{ id: "risks", label: "Risks" },
|
||||
{ id: "risks", label: "Risks & Mitigations" },
|
||||
{ id: "open_questions", label: "Open Questions" },
|
||||
];
|
||||
|
||||
interface PRDSection {
|
||||
|
||||
@@ -66,6 +66,30 @@ async function savePrd(projectId: string, prdContent: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GET — load stored conversation messages for display
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ projectId: string }> }
|
||||
) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.email) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { projectId } = await params;
|
||||
const history = await loadAtlasHistory(projectId);
|
||||
|
||||
// Filter to only user/assistant messages (no system prompts) for display
|
||||
const messages = history
|
||||
.filter((m: any) => m.role === "user" || m.role === "assistant")
|
||||
.map((m: any) => ({ role: m.role as "user" | "assistant", content: m.content as string }));
|
||||
|
||||
return NextResponse.json({ messages });
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// POST — send message to Atlas
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -90,14 +114,25 @@ export async function POST(
|
||||
// Load conversation history from DB to persist across agent runner restarts
|
||||
const history = await loadAtlasHistory(projectId);
|
||||
|
||||
// __init__ is a special internal trigger used only when there is no existing history.
|
||||
// If history already exists, ignore the init request (conversation already started).
|
||||
const isInit = message.trim() === "__atlas_init__";
|
||||
if (isInit && history.length > 0) {
|
||||
return NextResponse.json({ reply: null, alreadyStarted: true });
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`${AGENT_RUNNER_URL}/atlas/chat`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
message,
|
||||
// For init, send the greeting prompt but don't store it as a user message
|
||||
message: isInit
|
||||
? "Begin the conversation. Introduce yourself as Atlas and ask what the user is building. Do not acknowledge this as an internal trigger."
|
||||
: message,
|
||||
session_id: sessionId,
|
||||
history,
|
||||
is_init: isInit,
|
||||
}),
|
||||
signal: AbortSignal.timeout(120_000),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user