Skip to content

feat: Generate NEXT_PUBLIC_CHAT_API for NextJS backend to specify alt… #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

marcusschiesser
Copy link
Collaborator

@marcusschiesser marcusschiesser commented Nov 22, 2024

…ernative backend

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new environment variable NEXT_PUBLIC_CHAT_API for enhanced backend configuration in Next.js applications.
    • Added new command-line options for bootstrapping applications: --db-source <connection-string>, --web-source <url>, and --example-file.
  • Bug Fixes

    • Improved error handling for launching VSCode and running applications with clearer error messages.
  • Refactor

    • Simplified the structure of various functions by removing the customApiPath parameter and updating related interfaces.

Copy link

changeset-bot bot commented Nov 22, 2024

🦋 Changeset detected

Latest commit: 29d92d9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-llama Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Nov 22, 2024

Walkthrough

A new patch named "create-llama" has been introduced, which adds the environment variable NEXT_PUBLIC_CHAT_API for a Next.js backend, allowing for alternative backend configurations. Additionally, several modifications were made to types and function signatures, including the removal of the customApiPath property and the introduction of a port property in the InstallAppArgs type. The command-line interface options have also been enhanced with new parameters for improved flexibility in application bootstrapping.

Changes

File Change Summary
.changeset/perfect-days-smoke.md Added new environment variable NEXT_PUBLIC_CHAT_API for Next.js backend configuration.
create-app.ts Updated InstallAppArgs type by removing customApiPath and adding port. Modified createApp function accordingly.
helpers/env-variables.ts Added NEXT_PUBLIC_CHAT_API in getFrameworkEnvs for Next.js. Removed previous declaration in createFrontendEnvFile.
helpers/index.ts Modified installTemplate function to remove customApiPath parameter in createFrontendEnvFile call.
helpers/types.ts Removed customApiPath property from InstallTemplateArgs interface.
index.ts Enhanced CLI options by adding --db-source <connection-string>, --web-source <url>, and --example-file. Improved error handling and validation.

Possibly related PRs

🐰 In the garden where ideas bloom,
A new variable brings chat to zoom.
With paths now clear and options bright,
We hop along, our code takes flight!
A port to guide, a source to share,
In this patch, we find our flair! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

Documentation and Community

  • 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.

Copy link

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

🧹 Outside diff range and nitpick comments (2)
create-app.ts (1)

Line range hint 1-150: Document the breaking changes and migration path.

The changes to the type system and environment variable handling represent breaking changes. Consider:

  1. Adding migration documentation for existing users
  2. Updating the README to reflect the new port parameter requirement
  3. Documenting the new NEXT_PUBLIC_CHAT_API environment variable

Would you like me to help draft the migration documentation or update the README?

helpers/env-variables.ts (1)

410-416: Enhance documentation and add URL validation

The implementation looks good, but consider the following improvements:

  1. Expand the description to clarify all valid use cases beyond Express
  2. Add validation for the URL format when the env var is consumed

Update the description to be more comprehensive:

-      description:
-        "The API for the chat endpoint. Set when using a custom backend (e.g. Express). Use full URL like http://localhost:8000/api/chat",
+      description:
+        "The API for the chat endpoint. Set this when using any custom backend implementation (e.g. Express, FastAPI, etc.). Must be a full URL including protocol and path (e.g. http://localhost:8000/api/chat). This value will be exposed to the client-side.",
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6e70e32 and 29d92d9.

📒 Files selected for processing (6)
  • .changeset/perfect-days-smoke.md (1 hunks)
  • create-app.ts (1 hunks)
  • helpers/env-variables.ts (1 hunks)
  • helpers/index.ts (0 hunks)
  • helpers/types.ts (0 hunks)
  • index.ts (0 hunks)
💤 Files with no reviewable changes (3)
  • helpers/index.ts
  • helpers/types.ts
  • index.ts
🧰 Additional context used
🪛 LanguageTool
.changeset/perfect-days-smoke.md

[uncategorized] ~5-~5: The official spelling of this programming framework is “Next.js”.
Context: ... --- Generate NEXT_PUBLIC_CHAT_API for NextJS backend to specify alternative backend ...

(NODE_JS)

🔇 Additional comments (2)
create-app.ts (1)

19-19: Verify the impact of the InstallAppArgs type change.

The addition of port to the omitted properties list indicates that it's now a required property in InstallTemplateArgs. This change, combined with the removal of customApiPath, represents a breaking change that could affect existing consumers.

Let's verify the related changes and their impact:

✅ Verification successful

Port configuration has been simplified and standardized across templates

The changes to InstallAppArgs type are part of a broader improvement in port handling:

  1. The removal of customApiPath and addition of port to omitted properties is a positive change that:

    • Standardizes port configuration through environment variables (PORT=8000 by default in Express)
    • Removes the need for manual API path construction
    • Maintains backward compatibility as the port configuration is handled at the template level
  2. The git diff shows that the port parameter was also removed from the createApp function, confirming that port handling has been moved to the template level where it belongs.

This is not a breaking change as it actually simplifies the API and moves configuration to a more appropriate location in the templates.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the changes to InstallTemplateArgs and environment variable handling

# Check for InstallTemplateArgs interface definition
echo "Checking InstallTemplateArgs interface..."
rg -A 10 "interface InstallTemplateArgs"

# Check for port parameter usage
echo "Checking port parameter usage..."
rg "port.*:" --type ts

# Check for NEXT_PUBLIC_CHAT_API environment variable
echo "Checking NEXT_PUBLIC_CHAT_API usage..."
rg "NEXT_PUBLIC_CHAT_API"

# Check for customApiPath usage to ensure complete removal
echo "Checking for remaining customApiPath references..."
rg "customApiPath"

Length of output: 15278


Script:

#!/bin/bash
# Let's verify the changes in create-app.ts and related files

# Check the full content of create-app.ts to understand the context
echo "Checking create-app.ts content..."
cat create-app.ts

# Check the git diff for create-app.ts to see the exact changes
echo "Checking git diff for create-app.ts..."
git diff origin/main create-app.ts

# Check for port-related environment variable setup
echo "Checking port-related environment variables..."
rg -A 5 "port.*=.*process\.env" --type ts

# Check for port usage in template generation
echo "Checking port usage in template generation..."
rg -A 5 "port.*=.*\d+" --type ts

Length of output: 10440

helpers/env-variables.ts (1)

410-416: Verify impact of environment variable consolidation

The PR moves NEXT_PUBLIC_CHAT_API from frontend env file to framework envs. While this consolidation makes sense, we should verify that existing implementations aren't affected.

Let's check for any existing usage of this variable:

✅ Verification successful

Environment variable consolidation is safe to proceed

The variable NEXT_PUBLIC_CHAT_API is used consistently across templates as an optional configuration with a fallback to window.ENV.BASE_URL. Moving it to framework envs is a safe consolidation since:

  • No .env files currently define this variable
  • Usage in code properly handles the case when the variable is undefined
  • The implementation in both templates is identical and follows the same pattern
  • The variable is now properly documented in the framework-specific section where it belongs
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing usage of NEXT_PUBLIC_CHAT_API
echo "Searching for NEXT_PUBLIC_CHAT_API usage in code..."
rg "NEXT_PUBLIC_CHAT_API" -g '!{.env}*'

# Search for any .env files that might be using this variable
echo -e "\nSearching for .env files containing NEXT_PUBLIC_CHAT_API..."
fd -g '.env*' --exec grep -l "NEXT_PUBLIC_CHAT_API" {} \;

Length of output: 851


Script:

#!/bin/bash
# Search for .env files including hidden ones
echo "Searching for .env files (including hidden)..."
fd -H -g '.env*' --exec grep -l "NEXT_PUBLIC_CHAT_API" {} \;

# Check the content of the use-config files to understand the usage context
echo -e "\nChecking usage in NextJS template:"
cat "templates/components/ui/html/chat/hooks/use-config.ts"

echo -e "\nChecking usage in streaming template:"
cat "templates/types/streaming/nextjs/app/components/ui/chat/hooks/use-config.ts"

Length of output: 1440

@leehuwuj leehuwuj merged commit 0a7dfcf into main Nov 22, 2024
46 checks passed
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