Skip to content

Conversation

@aidankmcalister
Copy link
Member

@aidankmcalister aidankmcalister commented Aug 12, 2025

Summary by CodeRabbit

  • Documentation
    • Added a comprehensive guide for building an AI-powered chat app with Next.js covering setup, persistent session/message storage, streaming AI responses to the client, API endpoints to load/save messages, a minimal client UI scaffold, and end-to-end flow.
    • Includes examples and dev/test tips.
    • Linked the new guide under Guides → Integration Solutions in the sidebar for easier discovery.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 12, 2025

Walkthrough

Adds a docs sidebar entry and a new guide that implements a Next.js + Prisma AI chat example: Prisma schema and client, API routes for streaming chat and retrieving messages, a persistence helper, and a Next.js page scaffold that loads, streams, and persists chat messages.

Changes

Cohort / File(s) Summary
Docs navigation
sidebars.ts
Inserts "guides/ai-sdk-nextjs" into Guides → Integration Solutions items array; preserves existing sorting.
Guide content
content/800-guides/340-ai-sdk-nextjs.mdx
Adds a full guide document describing setup, Prisma schema, API routes, client UI, and dev/testing steps.
Server API routes
app/api/chat/route.ts, app/api/messages/route.ts
Adds POST /api/chat handler that streams AI responses and calls onFinish to persist chat; adds GET /api/messages to return stored messages ordered by creation time.
Prisma schema & client
prisma/schema.prisma, lib/prisma.ts
Adds Session and Message models and MessageRole enum; adds a PrismaClient singleton export (with optional Postgres Accelerate extension).
Persistence helper
lib/save-chat.ts
Adds saveChat(messages: UIMessage[], id: string) to upsert Session and persist recent user/assistant messages.
Client scaffold
app/page.tsx
Adds Next.js client page component that loads messages from /api/messages, renders message list, and posts prompts to /api/chat to receive streamed responses.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant UI as Next.js Client (Page)
  participant MsgAPI as /api/messages
  participant ChatAPI as /api/chat
  participant AI as AI SDK
  participant DB as Prisma / DB

  User->>UI: Open page
  UI->>MsgAPI: GET /api/messages
  MsgAPI->>DB: Query messages ordered by createdAt
  DB-->>MsgAPI: Messages
  MsgAPI-->>UI: UI-formatted messages
  UI-->>User: Render messages

  User->>UI: Submit prompt
  UI->>ChatAPI: POST /api/chat { id, messages }
  ChatAPI->>AI: Stream completion request
  AI-->>ChatAPI: Streamed tokens/response
  ChatAPI-->>UI: Streamed response chunks
  ChatAPI->>DB: onFinish -> save session + recent messages
  DB-->>ChatAPI: Save confirmation
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

Possibly related PRs

  • Auth.js Guide Created #7064 — Adds a different guide entry into the same sidebars.ts Integration Solutions list (touches the same docs navigation area).

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4072a2 and b25b6bd.

📒 Files selected for processing (1)
  • sidebars.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • sidebars.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Check internal links
  • GitHub Check: runner / linkspector
  • GitHub Check: Lost Pixel
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch DC-4746-ai-sdk-guide

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

Dangerous URL check

No absolute URLs to prisma.io/docs found.
No local URLs found.

@github-actions
Copy link
Contributor

Redirect check

This PR probably requires the following redirects to be added to static/_redirects:

  • This PR does not change any pages in a way that would require a redirect.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 12, 2025

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 12, 2025

Deploying docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: b25b6bd
Status: ✅  Deploy successful!
Preview URL: https://762fca17.docs-51g.pages.dev
Branch Preview URL: https://dc-4746-ai-sdk-guide.docs-51g.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2dc2e5 and b352fbf.

📒 Files selected for processing (2)
  • content/800-guides/340-ai-adk-nextjs.mdx (1 hunks)
  • sidebars.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Check internal links
  • GitHub Check: runner / linkspector
  • GitHub Check: Lost Pixel
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
sidebars.ts (1)

449-449: LGTM - Sidebar integration looks correct.

The new AI SDK guide is properly added to the Integration Solutions category and maintains the existing sort pattern for consistency.

content/800-guides/340-ai-adk-nextjs.mdx (1)

148-161: Confirm Prisma client import path in the documentation.

The lib/prisma.ts snippet currently imports from

import { PrismaClient } from "../app/generated/prisma/client";

but most setups either use the default @prisma/client location or customize the output in your schema.prisma. Please verify and update this example to match your generator configuration:

• If you’re using the default client, change the import to:

import { PrismaClient } from "@prisma/client";

• If you’ve set a custom output in your schema.prisma, make sure it points to app/generated/prisma/client, e.g.:

generator client {
  provider = "prisma-client-js"
  output   = "../app/generated/prisma/client"
}

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 12, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (3)
content/800-guides/340-ai-sdk-nextjs.mdx (3)

309-319: Remove redundant session null check after upsert.

upsert always returns an object; the null/undefined check is dead code.

Apply this diff:

   const session = await prisma.session.upsert({
     where: { id },
     update: {},
     create: { id },
   });

-  if (!session) throw new Error("Session not found");

181-185: Clarify Accelerate usage note.

If readers use Accelerate primarily to support Edge runtimes, consider adding a short note that the route can be marked for edge runtime in Next.js if desired and that Accelerate requires the proper connection string set up.

I can draft a brief addendum showing export const runtime = 'edge' for the chat route and a one-liner about setting the Accelerate connection string. Want me to add it?


619-619: Grammar nit: “a AI SDK” → “an AI SDK”.

Apply this diff:

-You're done! You've just created a AI SDK chat application with Next.js and Prisma. Below are some next steps to explore, as well as some more resources to help you get started expanding your project.
+You're done! You've just created an AI SDK chat application with Next.js and Prisma. Below are some next steps to explore, as well as some more resources to help you get started expanding your project.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b352fbf and 10adeb5.

📒 Files selected for processing (2)
  • content/800-guides/340-ai-sdk-nextjs.mdx (1 hunks)
  • sidebars.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • sidebars.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Check internal links
  • GitHub Check: runner / linkspector
  • GitHub Check: Lost Pixel
🔇 Additional comments (1)
content/800-guides/340-ai-sdk-nextjs.mdx (1)

582-597: No changes needed: useChat v5 correctly exposes sendMessage
The latest @ai-sdk/react (v5) hook returns sendMessage (alongside regenerate and stop); the form-helper functions handleSubmit/handleInputChange are from earlier v4 patterns and aren’t part of the current API. Your existing snippet using sendMessage({ text: input }) is accurate—no migration to handleSubmit is required.

Likely an incorrect or invalid review comment.

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 13, 2025
@github-actions
Copy link
Contributor

Images automagically compressed by Calibre's image-actions

Compression reduced images by 4.2%, saving 31.18 KB.

Filename Before After Improvement Visual comparison
static/img/guides/prisma-ai-sdk-nextjs-cover.png 740.44 KB 709.26 KB -4.2% View diff

206 images did not require optimisation.

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 13, 2025
@aidankmcalister aidankmcalister merged commit c855d2e into main Aug 13, 2025
12 checks passed
@aidankmcalister aidankmcalister deleted the DC-4746-ai-sdk-guide branch August 13, 2025 17:08
jlecordier pushed a commit to jlecordier/docs-1 that referenced this pull request Sep 3, 2025
* AI SDK guide created

* Rename 340-ai-adk-nextjs.mdx to 340-ai-sdk-nextjs.mdx

* coderabbit changes

* name change in sidebar

* sidebar name change

* OG image added

* Optimised images with calibre/image-actions

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants