Skip to content

Update route.ts#102

Open
Ashusf90 wants to merge 2 commits intoBeyteFlow:mainfrom
Ashusf90:patch-1
Open

Update route.ts#102
Ashusf90 wants to merge 2 commits intoBeyteFlow:mainfrom
Ashusf90:patch-1

Conversation

@Ashusf90
Copy link
Copy Markdown

🚀 BΞYTΞFLʘW | Pull Request Protocol

PR Type: (Choose one: feat | fix | refactor | docs | perf)
Issue Link: Fixes #


📝 System Summary

Provide a concise brief of the changes introduced to the stream.

🛠️ Technical Changes

  • Logic change in ...
  • New UI component added: ...
  • Database schema updated: ...

🧪 Quality Assurance (QA)

  • Linting: Code style matches the BeyteFlow grid.
  • Build: npm run build executed without errors.
  • Testing: New logic has been verified and tested.
  • Dark Mode: UI is high-contrast and neon-optimized.

🖼️ Visual Evidence

If this PR affects the UI, drop a screenshot or GIF below:


📡 Developer Authorization

  • I have performed a self-review of my code.
  • My changes generate no new warnings in the console.
  • I have updated the documentation (if applicable).

Authorized by: @Yourusername
Timestamp: {{ date }}


@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 24, 2026

@Ashusf90 is attempting to deploy a commit to the naheel0's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c9fdaafe-dca9-49c0-8c1a-c5da5343ca49

📥 Commits

Reviewing files that changed from the base of the PR and between 20abd7f and 1b8b1c2.

📒 Files selected for processing (1)
  • src/app/api/generate/route.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/api/generate/route.ts

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • README generation now produces structured, named sections and combines them into a single Markdown document for clearer, sectioned output.
  • Chores

    • Internal generation flow refactored to support multi-step creation and improved modularity.

Walkthrough

Added a multi-step README generation pipeline: generateStructure(repoData) to request a JSON array of section names, generateSection(section, repoData) to request content for a named section, and exported generateReadme(repoData) which sequentially builds a Markdown README from those pieces. The existing POST handler remains unchanged.

Changes

Cohort / File(s) Summary
Multi-step README generation pipeline
src/app/api/generate/route.ts
Introduced generateStructure() (requests AI for JSON section list), generateSection(section, repoData) (requests AI for a single section's content), and exported generateReadme(repoData) (orchestrates calls, assembles Markdown with ## ${section} headers). POST endpoint logic unchanged.

Sequence Diagram

sequenceDiagram
    participant Client
    participant generateReadme
    participant generateStructure
    participant generateSection
    participant GeminiAPI

    Client->>generateReadme: generateReadme(repoData)
    generateReadme->>generateStructure: generateStructure(repoData)
    generateStructure->>GeminiAPI: Prompt for section names
    GeminiAPI-->>generateStructure: JSON array of section names
    generateStructure-->>generateReadme: Section array

    loop For each section
        generateReadme->>generateSection: generateSection(section, repoData)
        generateSection->>GeminiAPI: Prompt for section content
        GeminiAPI-->>generateSection: Section content
        generateSection-->>generateReadme: Section content
    end

    generateReadme->>generateReadme: Assemble Markdown with ## headers
    generateReadme-->>Client: Final README Markdown
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #14: Modifies the same API route module and likely integrates the new generateReadme() flow into the POST handler.

Suggested labels

area: ai-logic, area: backend

Suggested reviewers

  • adithyanmkd

Poem

🐰 I nibble prompts in moonlit code,
I hop through sections, light and bold.
From structure first to content fine,
I stitch a README, line by line. ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Update route.ts' is vague and generic, failing to convey the specific nature of the changes made to the file. Use a more descriptive title that explains the primary change, such as 'Add generateReadme function with section-based README generation' or 'Refactor README generation into modular functions'.
Description check ❓ Inconclusive The description uses a template with placeholder values and uncompleted checklists, lacking concrete information about the actual code changes in the pull request. Complete the template with specific details: specify the PR type, link the relevant issue, describe the actual changes made to route.ts, and mark completed QA items.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown

@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: 3

🧹 Nitpick comments (1)
src/app/api/generate/route.ts (1)

8-8: Consider adding proper types instead of any.

All three functions use repoData: any, losing type safety. If a type or interface for repository data exists (or can be created), using it would improve maintainability and catch errors at compile time.

Also applies to: 23-23, 36-36

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/api/generate/route.ts` at line 8, Define a proper typed interface
(e.g., RepositoryData) that lists the actual properties accessed on repoData and
replace the repoData: any annotations with this interface in generateStructure
and the other functions that accept repoData; to implement, inspect the bodies
of generateStructure and the two other repoData-using functions to collect every
property and nested shape they read/write, declare those fields in
RepositoryData (or split into smaller interfaces for nested objects), export it
if reused, and update the function signatures to use RepositoryData instead of
any to restore type safety.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/app/api/generate/route.ts`:
- Around line 22-32: The generateSection function calls a non-existent helper
callAI; replace that call with the project's established Gemini invocation or
implement a callAI wrapper that delegates to the existing Gemini-based request
flow. Locate the generateSection function and either (a) refactor the return
from "return await callAI(prompt);" to use the same Gemini call used elsewhere
(e.g., the function/method that sends prompts to the Gemini model), passing the
prompt and any required options, or (b) add a callAI helper that accepts a
prompt and internally invokes the Gemini request function/class used in the
codebase, then return its result; ensure you reference the exact symbol
generateSection when making the change so all callers keep working.
- Around line 7-19: The function generateStructure calls an undefined callAI and
blindly JSON.parse's the response; fix by replacing callAI with the existing
getGeminiModel()/appropriate AI call used elsewhere (or import/define callAI)
and wrap the JSON.parse in a try/catch that sanitizes/preprocesses the model
output before parsing (e.g., strip non-JSON preamble), validate the parsed value
is an array of strings, and return a safe fallback or throw a clear error;
reference generateStructure and callAI (or use getGeminiModel) when making the
change.
- Around line 35-47: The exported generateReadme function is unused and unsafe:
either remove/export it if unnecessary, or integrate it into the POST handler by
calling generateReadme from the request flow (replace the single-prompt path).
If you keep it, harden it by validating the result of generateStructure before
iterating (use Array.isArray on the value returned from
generateStructure/JSON.parse and handle non-array cases by throwing or returning
a safe default), and update the function signature/return type expectations
accordingly; ensure generateSection is only called for confirmed array entries.

---

Nitpick comments:
In `@src/app/api/generate/route.ts`:
- Line 8: Define a proper typed interface (e.g., RepositoryData) that lists the
actual properties accessed on repoData and replace the repoData: any annotations
with this interface in generateStructure and the other functions that accept
repoData; to implement, inspect the bodies of generateStructure and the two
other repoData-using functions to collect every property and nested shape they
read/write, declare those fields in RepositoryData (or split into smaller
interfaces for nested objects), export it if reused, and update the function
signatures to use RepositoryData instead of any to restore type safety.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3bf78f75-08cb-4469-b395-f6119f3d3e95

📥 Commits

Reviewing files that changed from the base of the PR and between a9effc4 and 20abd7f.

📒 Files selected for processing (1)
  • src/app/api/generate/route.ts

Comment on lines +7 to +19
// STEP 1: Generate structure
async function generateStructure(repoData: any) {
const prompt = `
Create a list of README sections for this repository.
Return ONLY array of section names.

Repo:
${JSON.stringify(repoData)}
`;

const res = await callAI(prompt);
return JSON.parse(res); // ["Introduction", "Features", ...]
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

callAI is undefined — code will fail at runtime.

The function callAI is called on line 17 but is never defined or imported in this file. This will throw a ReferenceError when executed.

Additionally, JSON.parse(res) on line 18 lacks error handling. If the AI returns malformed JSON or includes preamble text, this will throw an unhandled exception.

🐛 Proposed fix

Either define callAI or use the existing getGeminiModel() pattern:

+async function callAI(prompt: string): Promise<string> {
+  const model = getGeminiModel();
+  const result = await model.generateContent(prompt);
+  const response = await result.response;
+  return response.text();
+}
+
 // STEP 1: Generate structure
 async function generateStructure(repoData: any) {
   const prompt = `
   Create a list of README sections for this repository.
   Return ONLY array of section names.
 
   Repo:
   ${JSON.stringify(repoData)}
   `;
 
   const res = await callAI(prompt);
-  return JSON.parse(res); // ["Introduction", "Features", ...]
+  try {
+    return JSON.parse(res);
+  } catch {
+    throw new Error("Failed to parse section structure from AI response");
+  }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/api/generate/route.ts` around lines 7 - 19, The function
generateStructure calls an undefined callAI and blindly JSON.parse's the
response; fix by replacing callAI with the existing getGeminiModel()/appropriate
AI call used elsewhere (or import/define callAI) and wrap the JSON.parse in a
try/catch that sanitizes/preprocesses the model output before parsing (e.g.,
strip non-JSON preamble), validate the parsed value is an array of strings, and
return a safe fallback or throw a clear error; reference generateStructure and
callAI (or use getGeminiModel) when making the change.

Comment on lines +22 to +32
// STEP 2: Generate each section
async function generateSection(section: string, repoData: any) {
const prompt = `
Generate ONLY the "${section}" section of a README.

Repo:
${JSON.stringify(repoData)}
`;

return await callAI(prompt);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Same undefined callAI issue.

This function also calls callAI which doesn't exist. Same fix applies — either define the helper or refactor to use the existing Gemini model pattern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/api/generate/route.ts` around lines 22 - 32, The generateSection
function calls a non-existent helper callAI; replace that call with the
project's established Gemini invocation or implement a callAI wrapper that
delegates to the existing Gemini-based request flow. Locate the generateSection
function and either (a) refactor the return from "return await callAI(prompt);"
to use the same Gemini call used elsewhere (e.g., the function/method that sends
prompts to the Gemini model), passing the prompt and any required options, or
(b) add a callAI helper that accepts a prompt and internally invokes the Gemini
request function/class used in the codebase, then return its result; ensure you
reference the exact symbol generateSection when making the change so all callers
keep working.

@naheel0
Copy link
Copy Markdown
Member

naheel0 commented Mar 24, 2026

Hi @Ashusf90,

Could you provide a brief description of the changes in this PR and how they address the linked issue #<issue_number>? Specifically, a short summary of what this update to route.ts does and the purpose of the new functions would help reviewers understand the context.

Thanks!

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