add simple form and loading state#7
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR introduces guided and simple modes for the prompt-generation flow. The home page now offers two input paths: guided (structured multi-field form) or simple (single-textarea description). The API endpoint distinguishes mode during brief processing and Gemini prompt construction, while the build page refactors its layout to support loading states and displays responses in a new themed card structure. ChangesGuided & Simple Mode Support
Sequence DiagramsequenceDiagram
participant User
participant HomePage as Home Page
participant API as /api/generate-prompt
participant Gemini as Gemini API
participant BuildPage as Build Page
User->>HomePage: Select mode (guided or simple)
alt Guided Mode
User->>HomePage: Fill context, skills, format fields
else Simple Mode
User->>HomePage: Enter description
end
User->>HomePage: Submit
HomePage->>HomePage: Validate inputs per mode
HomePage->>HomePage: buildQueryParams (mode-aware)
HomePage->>BuildPage: Navigate /build?params
BuildPage->>BuildPage: Show Loading (Navbar + Forging skeleton)
BuildPage->>API: POST request with Brief (mode, description)
API->>API: Validate body → create Brief
API->>API: isSimple = (mode='simple' OR description present)
API->>API: buildBrief (simple early-return, include description)
API->>API: Construct Gemini prompt (conditional instruction text)
API->>Gemini: Send prompt request
Gemini->>API: Return response with content
API->>API: Parse first candidate text
API->>BuildPage: Return GeneratePromptResponse (prompt text)
BuildPage->>BuildPage: Parse response JSON
BuildPage->>BuildPage: Display prompt in themed layout
User->>BuildPage: Copy prompt
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/api/generate-prompt/route.ts`:
- Around line 164-174: The current code only uses the first Gemini content part
(parsed?.candidates?.[0]?.content?.parts?.[0]?.text) which can truncate outputs;
update the logic that constructs promptText (and uses cleanText) to concatenate
all parts' text for the first candidate by iterating
parsed?.candidates?.[0]?.content?.parts, extracting each part.text (ignoring
undefined), joining them into a single string, then pass that concatenated
string to cleanText so the full Gemini response is preserved; keep references to
parsed, promptText, cleanText and the content.parts array when making the
change.
In `@app/page.tsx`:
- Around line 91-97: Avoid putting long free-form textarea content into the URL:
in the branch that checks mode === "simple" (the code that trims description and
calls params.set("description", trimmed)), validate and enforce a maximum length
(e.g., <= 2000 chars) before adding description to params; if the trimmed
description exceeds the limit, instead persist it via client storage
(sessionStorage/localStorage) or a short server-side token and set a short
flag/query param (e.g., description_stored=true or description_token=<id>) so
/build can retrieve the full text, and apply the same guard/alternate-storage
approach to the other occurrence that sets description in params (the lines
around the second params.set("description")).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a67aa986-484c-4b4f-94be-f9cfd11376a9
📒 Files selected for processing (4)
app/api/generate-prompt/route.tsapp/build/loading.tsxapp/build/page.tsxapp/page.tsx
| const parsed = JSON.parse(rawText) as { | ||
| candidates?: Array<{ | ||
| content?: { parts?: Array<{ text?: string }> }; | ||
| content?: { | ||
| parts?: Array<{ text?: string }>; | ||
| }; | ||
| }>; | ||
| } | null = null; | ||
| }; | ||
|
|
||
| try { | ||
| data = JSON.parse(rawText); | ||
| } catch (parseError) { | ||
| console.error("Failed to parse Gemini response", { | ||
| error: parseError, | ||
| rawText, | ||
| }); | ||
| const promptText = cleanText( | ||
| parsed?.candidates?.[0]?.content?.parts?.[0]?.text || "", | ||
| ); |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In the Gemini generateContent API response schema, can candidates[0].content.parts contain multiple text parts for one candidate, and should clients concatenate them to reconstruct the full text response?
💡 Result:
Yes, the Gemini generateContent API response schema can contain multiple text parts within candidates.content.parts [1][2][3]. While many simple requests return a single text part, the API may return multiple parts in scenarios such as when the model includes "thinking" blocks, function calls, or other structured content alongside the generated text [2][3]. Clients should not rely solely on convenience accessors (like response.text) if they need to handle all response types robustly, as these accessors often only work for simple, single-part responses and may fail or return incomplete data when multiple parts are present [4][5][6]. To reconstruct the full text response correctly, clients should iterate through the parts array, check for the presence of text, and concatenate all text segments [4][2][3]. Example logic for reconstruction: const fullText = response.candidates.content.parts.filter(part => part.text).map(part => part.text).join(''); [4][2]
Citations:
- 1: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference
- 2: concatenate multple text parts for gemini models Portkey-AI/gateway#1466
- 3: Warning: there are non-text parts in the response googleapis/python-genai#850
- 4: Batch responses don’t populate response.text; need to read candidates[0].content.parts googleapis/js-genai#1433
- 5: Gemini-Pro response.text Error google-gemini/deprecated-generative-ai-python#196
- 6: https://stackoverflow.com/questions/79142007/google-genai-gemini-returning-package-code-instead-of-a-response-to-the-prompt
🏁 Script executed:
cat -n app/api/generate-prompt/route.ts | sed -n '160,180p'Repository: JasonDebnath001/PromptForge
Length of output: 686
🏁 Script executed:
cat -n app/api/generate-prompt/route.ts | sed -n '150,190p'Repository: JasonDebnath001/PromptForge
Length of output: 1295
Concatenate all returned Gemini text parts instead of reading only the first part.
At lines 172–174, the code uses only parts[0]?.text, which can truncate valid output when the Gemini API response splits content across multiple parts. The API may return multiple text parts in the content.parts array—for example, when the model includes thinking blocks or other structured content—and clients should concatenate all text segments to reconstruct the full response.
Proposed fix
- const promptText = cleanText(
- parsed?.candidates?.[0]?.content?.parts?.[0]?.text || "",
- );
+ const promptText = cleanText(
+ (parsed?.candidates?.[0]?.content?.parts ?? [])
+ .map((part) => part?.text ?? "")
+ .join(""),
+ );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@app/api/generate-prompt/route.ts` around lines 164 - 174, The current code
only uses the first Gemini content part
(parsed?.candidates?.[0]?.content?.parts?.[0]?.text) which can truncate outputs;
update the logic that constructs promptText (and uses cleanText) to concatenate
all parts' text for the first candidate by iterating
parsed?.candidates?.[0]?.content?.parts, extracting each part.text (ignoring
undefined), joining them into a single string, then pass that concatenated
string to cleanText so the full Gemini response is preserved; keep references to
parsed, promptText, cleanText and the content.parts array when making the
change.
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
UI Updates