Skip to content

Feat/ai design turn engine - #29

Merged
Suharshit merged 3 commits into
mainfrom
feat/ai-design-turn-engine
Sep 15, 2026
Merged

Suharshit merged 3 commits into
mainfrom
feat/ai-design-turn-engine

Conversation

@Suharshit

Copy link
Copy Markdown
Owner

No description provided.

Suharshit and others added 2 commits September 16, 2026 00:13
Each turn is still one design-agent run, but the agent now keeps a
requirements brief, asks up to 3 rounds of clarifying questions when
an unknown would change the architecture, proposes a plan (components,
flows, decisions with rationale and alternatives, assumptions), and
only draws the diagram once the plan is approved.

- lib/ai/agent-schema.ts: brief, question, plan, turn-analysis and
  run-result schemas; list limits trimmed in code rather than enforced
  as maxItems, which models don't reliably honour
- lib/ai/prompts.ts, lib/ai/design-agent-engine.ts: analyze/plan/
  generate on generateText + Output.object; code-enforced decision
  rules; per-step thinking level (Gemini 3) or budget (Gemini 2.x);
  one retry on schema mismatch; per-call timeouts
- design-agent task: single attempt, maxDuration 300s
- Turns route accepts message, answers, generate and skip; stored
  replies are validated run output (QUESTIONS / PLAN / RESULT) and run
  failures are shown as friendly messages

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* feat(ai-sessions): add persistent storage for AI design sessions

The AI sidebar kept its chat in React state only, so a reload lost the
transcript and any in-flight run. This adds the storage layer the
multi-turn design agent will build on (not wired to the UI yet).

- AiSession / AiMessage Prisma models + additive migration; sessions
  cascade with their project, messages cascade with their session
- lib/ai/session-store.ts: 7-day sliding expiry, 10 sessions per user
  per project, 60 messages per session; reads ignore expired rows
- GET/POST /api/projects/[projectId]/ai-sessions and
  GET/DELETE /api/projects/[projectId]/ai-sessions/[sessionId],
  private to the session's creator
- Daily Vercel Cron cleanup at /api/cron/ai-sessions/cleanup,
  gated by CRON_SECRET (public in proxy.ts)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* feat(ai-sessions): run the AI Architect chat on stored sessions

A reload no longer loses the chat or an in-flight run. Generation is
still one-shot; this changes persistence and resume only.

- POST /api/projects/[projectId]/ai-sessions/[sessionId]/turns stores
  the prompt and a PENDING reply carrying the run id (replaces
  POST /api/ai/design, which is removed)
- Replies are settled from runs.retrieve whenever a session is read, so
  a turn is saved even if the tab closed mid-run; concurrent reads
  settle once
- useAiSession replaces useDesignAgent: reopens the last chat, resumes
  pending runs via Realtime with a 4s polling fallback, stores new chats
  lazily on the first message
- Sidebar session bar with saved-chat history (delete, expiry) and
  New chat
- Limits moved to lib/ai/session-limits.ts for client use;
  formatRelativeTime extracted to lib/relative-time.ts

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* feat(ai-agent): multi-turn design agent - clarify, plan, then generate

Each turn is still one design-agent run, but the agent now keeps a
requirements brief, asks up to 3 rounds of clarifying questions when
an unknown would change the architecture, proposes a plan (components,
flows, decisions with rationale and alternatives, assumptions), and
only draws the diagram once the plan is approved.

- lib/ai/agent-schema.ts: brief, question, plan, turn-analysis and
  run-result schemas; list limits trimmed in code rather than enforced
  as maxItems, which models don't reliably honour
- lib/ai/prompts.ts, lib/ai/design-agent-engine.ts: analyze/plan/
  generate on generateText + Output.object; code-enforced decision
  rules; per-step thinking level (Gemini 3) or budget (Gemini 2.x);
  one retry on schema mismatch; per-call timeouts
- design-agent task: single attempt, maxDuration 300s
- Turns route accepts message, answers, generate and skip; stored
  replies are validated run output (QUESTIONS / PLAN / RESULT) and run
  failures are shown as friendly messages

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* feat(ai-agent): question, plan and result cards in the AI sidebar

The AI Architect chat now renders the design agent's turns as cards
instead of plain text, so users answer, skip and approve with buttons.

- QuestionsCard: option chips and a free-text answer per question,
  Send answers and Skip; read-only with the chosen answers once sent
- PlanCard: summary, highlighted key decisions with rationale and
  alternatives, components (folded after 6), flows, assumptions, and
  Draw this plan
- ResultCard: canvas summary with collapsible decisions
- Only the newest non-failed reply is interactive, and only while no
  turn is pending, mirroring the server's rules
- useAiSession.sendTurn sends message, answers, generate and skip,
  with optimistic user text matching what the server stores
- TurnInput, the generate/skip texts and payload readers now live in
  the client-safe agent-schema and are shared with the server; question
  and plan payloads also store the agent's reply

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
draftly Ready Ready Preview Sep 15, 2026 8:15pm UTC

@coderabbitai

coderabbitai Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 5c3db828-4544-4f7e-bf0f-60f41d239164


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Resolves the conflicts with the squash-merged history on main. main's content equals step 3, which this branch already contains, so the branch's content is kept unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Suharshit
Suharshit merged commit a977284 into main Sep 15, 2026
4 checks passed
@Suharshit
Suharshit deleted the feat/ai-design-turn-engine branch September 16, 2026 18:25

This branch was successfully deployed

1 active deployment
Preview — a7121220 Deployed Sep 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant