Add TanStack Start server code example for chat API #141
main fromrefs/pull/141/head·merged by AlemTuzlak View on GitHubThe Next.js-only code was confusing for a beginner unfamiliar with Tanstack syntax.
🎯 Changes#
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm run test:pr.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
- Documentation
- Added a TanStack Start Quick Start example demonstrating a complete chat API endpoint with streaming responses and error handling.
- Replaced the previous Next.js header with the new TanStack Start block and simplified the Next.js snippet to retain only essential imports.
- Improved guidance for implementing streaming chat endpoints in the Quick Start.
- 1
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 049eb8acd83e6d566c6040c0c4cb53dbe222d46a and f07605b289d376c3c1a77868b1058e34fade2b72.
📒 Files selected for processing (1)
docs/getting-started/quick-start.md(1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
docs/getting-started/quick-start.md
30-30: Hard tabs Column: 1
(MD010, no-hard-tabs)
31-31: Hard tabs Column: 1
(MD010, no-hard-tabs)
32-32: Hard tabs Column: 1
(MD010, no-hard-tabs)
33-33: Hard tabs Column: 1
(MD010, no-hard-tabs)
34-34: Hard tabs Column: 1
(MD010, no-hard-tabs)
35-35: Hard tabs Column: 1
(MD010, no-hard-tabs)
36-36: Hard tabs Column: 1
(MD010, no-hard-tabs)
37-37: Hard tabs Column: 1
(MD010, no-hard-tabs)
38-38: Hard tabs Column: 1
(MD010, no-hard-tabs)
39-39: Hard tabs Column: 1
(MD010, no-hard-tabs)
40-40: Hard tabs Column: 1
(MD010, no-hard-tabs)
41-41: Hard tabs Column: 1
(MD010, no-hard-tabs)
42-42: Hard tabs Column: 1
(MD010, no-hard-tabs)
43-43: Hard tabs Column: 1
(MD010, no-hard-tabs)
44-44: Hard tabs Column: 1
(MD010, no-hard-tabs)
46-46: Hard tabs Column: 1
(MD010, no-hard-tabs)
48-48: Hard tabs Column: 1
(MD010, no-hard-tabs)
49-49: Hard tabs Column: 1
(MD010, no-hard-tabs)
50-50: Hard tabs Column: 1
(MD010, no-hard-tabs)
51-51: Hard tabs Column: 1
(MD010, no-hard-tabs)
52-52: Hard tabs Column: 1
(MD010, no-hard-tabs)
53-53: Hard tabs Column: 1
(MD010, no-hard-tabs)
54-54: Hard tabs Column: 1
(MD010, no-hard-tabs)
55-55: Hard tabs Column: 1
(MD010, no-hard-tabs)
57-57: Hard tabs Column: 1
(MD010, no-hard-tabs)
58-58: Hard tabs Column: 1
(MD010, no-hard-tabs)
59-59: Hard tabs Column: 1
(MD010, no-hard-tabs)
60-60: Hard tabs Column: 1
(MD010, no-hard-tabs)
61-61: Hard tabs Column: 1
(MD010, no-hard-tabs)
62-62: Hard tabs Column: 1
(MD010, no-hard-tabs)
63-63: Hard tabs Column: 1
(MD010, no-hard-tabs)
64-64: Hard tabs Column: 1
(MD010, no-hard-tabs)
65-65: Hard tabs Column: 1
(MD010, no-hard-tabs)
66-66: Hard tabs Column: 1
(MD010, no-hard-tabs)
67-67: Hard tabs Column: 1
(MD010, no-hard-tabs)
68-68: Hard tabs Column: 1
(MD010, no-hard-tabs)
69-69: Hard tabs Column: 1
(MD010, no-hard-tabs)
70-70: Hard tabs Column: 1
(MD010, no-hard-tabs)
71-71: Hard tabs Column: 1
(MD010, no-hard-tabs)
72-72: Hard tabs Column: 1
(MD010, no-hard-tabs)
73-73: Hard tabs Column: 1
(MD010, no-hard-tabs)
🔇 Additional comments (1)
docs/getting-started/quick-start.md (1)
22-122: Well-structured examples demonstrating equivalent functionality across frameworks.The addition of the TanStack Start example alongside the Next.js implementation is excellent for documentation clarity. Both examples properly demonstrate:
- Environment variable validation
- Request parsing with
conversationIdandmessages - Streaming chat response creation via the
chat()API - Proper error handling with JSON error responses
The parallel structure makes it easy for developers familiar with either framework to understand how to implement the same functionality.
@@ -21,0 +53,21 @@53+ model: "gpt-4o",54+ conversationId,55+ });56+57+ // Convert stream to HTTP response58+ return toStreamResponse(stream);59+ } catch (error) {60+ return new Response(61+ JSON.stringify({62+ error:63+ error instanceof Error ? error.message : "An error occurred",64+ }),65+ {66+ status: 500,67+ headers: { "Content-Type": "application/json" },68+ },69+ );70+ }71+ },72+ },73+ },⚠️ Potential issue | 🟡 Minor
Replace hard tabs with spaces in the TanStack Start code block.
The TanStack Start example uses hard tabs for indentation, which violates markdown linting rules. Please convert all hard tabs to spaces (typically 2 or 4 spaces per indentation level to match the Next.js example below).
Apply this diff to replace hard tabs with spaces in the code block:
export const Route = createFileRoute("/api/chat")({ - server: { - handlers: { - POST: async ({ request }) => { - // Check for API key - if (!process.env.OPENAI_API_KEY) { - return new Response( + server: { + handlers: { + POST: async ({ request }) => { + // Check for API key + if (!process.env.OPENAI_API_KEY) { + return new Response( JSON.stringify({ - error: "OPENAI_API_KEY not configured", - }), - { - status: 500, - headers: { "Content-Type": "application/json" }, - }, - ); - } + error: "OPENAI_API_KEY not configured", + }), + { + status: 500, + headers: { "Content-Type": "application/json" }, + }, + ); + } - const { messages, conversationId } = await request.json(); + const { messages, conversationId } = await request.json(); - try { - // Create a streaming chat response - const stream = chat({ - adapter: openai(), - messages, - model: "gpt-4o", - conversationId, - }); + try { + // Create a streaming chat response + const stream = chat({ + adapter: openai(), + messages, + model: "gpt-4o", + conversationId, + }); - // Convert stream to HTTP response - return toStreamResponse(stream); - } catch (error) { - return new Response( + // Convert stream to HTTP response + return toStreamResponse(stream); + } catch (error) { + return new Response( JSON.stringify({ - error: - error instanceof Error ? error.message : "An error occurred", - }), - { - status: 500, - headers: { "Content-Type": "application/json" }, - }, - ); - } - }, - }, - }, + error: + error instanceof Error ? error.message : "An error occurred", + }), + { + status: 500, + headers: { "Content-Type": "application/json" }, + }, + ); + } + }, + }, + }, });Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)
30-30: Hard tabs Column: 1
(MD010, no-hard-tabs)
31-31: Hard tabs Column: 1
(MD010, no-hard-tabs)
32-32: Hard tabs Column: 1
(MD010, no-hard-tabs)
33-33: Hard tabs Column: 1
(MD010, no-hard-tabs)
34-34: Hard tabs Column: 1
(MD010, no-hard-tabs)
35-35: Hard tabs Column: 1
(MD010, no-hard-tabs)
36-36: Hard tabs Column: 1
(MD010, no-hard-tabs)
37-37: Hard tabs Column: 1
(MD010, no-hard-tabs)
38-38: Hard tabs Column: 1
(MD010, no-hard-tabs)
39-39: Hard tabs Column: 1
(MD010, no-hard-tabs)
40-40: Hard tabs Column: 1
(MD010, no-hard-tabs)
41-41: Hard tabs Column: 1
(MD010, no-hard-tabs)
42-42: Hard tabs Column: 1
(MD010, no-hard-tabs)
43-43: Hard tabs Column: 1
(MD010, no-hard-tabs)
44-44: Hard tabs Column: 1
(MD010, no-hard-tabs)
46-46: Hard tabs Column: 1
(MD010, no-hard-tabs)
48-48: Hard tabs Column: 1
(MD010, no-hard-tabs)
49-49: Hard tabs Column: 1
(MD010, no-hard-tabs)
50-50: Hard tabs Column: 1
(MD010, no-hard-tabs)
51-51: Hard tabs Column: 1
(MD010, no-hard-tabs)
52-52: Hard tabs Column: 1
(MD010, no-hard-tabs)
53-53: Hard tabs Column: 1
(MD010, no-hard-tabs)
54-54: Hard tabs Column: 1
(MD010, no-hard-tabs)
55-55: Hard tabs Column: 1
(MD010, no-hard-tabs)
57-57: Hard tabs Column: 1
(MD010, no-hard-tabs)
58-58: Hard tabs Column: 1
(MD010, no-hard-tabs)
59-59: Hard tabs Column: 1
(MD010, no-hard-tabs)
60-60: Hard tabs Column: 1
(MD010, no-hard-tabs)
61-61: Hard tabs Column: 1
(MD010, no-hard-tabs)
62-62: Hard tabs Column: 1
(MD010, no-hard-tabs)
63-63: Hard tabs Column: 1
(MD010, no-hard-tabs)
64-64: Hard tabs Column: 1
(MD010, no-hard-tabs)
65-65: Hard tabs Column: 1
(MD010, no-hard-tabs)
66-66: Hard tabs Column: 1
(MD010, no-hard-tabs)
67-67: Hard tabs Column: 1
(MD010, no-hard-tabs)
68-68: Hard tabs Column: 1
(MD010, no-hard-tabs)
69-69: Hard tabs Column: 1
(MD010, no-hard-tabs)
70-70: Hard tabs Column: 1
(MD010, no-hard-tabs)
71-71: Hard tabs Column: 1
(MD010, no-hard-tabs)
72-72: Hard tabs Column: 1
(MD010, no-hard-tabs)
73-73: Hard tabs Column: 1
(MD010, no-hard-tabs)
🤖 Prompt for AI Agents
In docs/getting-started/quick-start.md around lines 30 to 73, the TanStack Start code block uses hard tab characters for indentation; replace every hard tab with spaces (use the same indentation width as the Next.js example—preferably 2 spaces per level or 4 if the repo standard is 4) so the block uses consistent space-based indentation; ensure all lines in the snippet are updated, preserve original line breaks and code content, and verify there are no remaining tab characters before committing.✅ Addressed in commit 5a90539
fixed in 5a90539
@harlley, thank you for fixing the indentation! The code block should now be consistent with markdown linting rules. 🎉
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
AlemTuzlak approved these changes
AlemTuzlak merged this254b248
AlemTuzlak closed this
Sign in to join this conversation.
Walkthrough#
Added a TanStack Start server POST
/api/chatexample to the quick-start docs demonstrating OPENAI_API_KEY validation, request parsing (messages, conversationId), streaming chat viachat({ adapter: openai(), ... })converted to an HTTP stream withtoStreamResponse, and JSON 500 error handling; adjusted the Next.js snippet imports.Changes#
docs/getting-started/quick-start.md/api/chatAPI route example (OPENAI_API_KEY validation, parsingmessagesandconversationId, streaming chat viachat({ adapter: openai(), ... }), converting to HTTP stream withtoStreamResponse, and JSON 500 error handling). Replaced Next.js placeholder header with remaining import statements.Estimated code review effort#
🎯 1 (Trivial) | ⏱️ ~5 minutes
chat,openai,toStreamResponse) match library API.Poem#
Pre-merge checks and finishing touches#
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 5a905396141e99e83eb79d6554da7dadeea2f55c and 2b3543e673b4d75b29cb2c26f8eaf43dd0794234.
📒 Files selected for processing (1)
docs/getting-started/quick-start.md(1 hunks)🚧 Files skipped from review as they are similar to previous changes (1)
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