Skip to content

Comments

New chat#444

Merged
elie222 merged 2 commits intomainfrom
feat/new-chat
May 23, 2025
Merged

New chat#444
elie222 merged 2 commits intomainfrom
feat/new-chat

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented May 23, 2025

Summary by CodeRabbit

  • New Features

    • Improved chat initialization to ensure every chat has a valid and consistent ID before displaying the chat interface.
  • Refactor

    • Streamlined chat component logic for clearer handling of chat IDs and message fetching.
    • Enhanced handling of chat retrieval and creation for more predictable chat management.
  • Bug Fixes

    • Fixed potential issues where chats without valid IDs could cause errors or inconsistent behavior.
  • Chores

    • Updated application version to v1.1.11.

@vercel
Copy link

vercel bot commented May 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
inbox-zero ✅ Ready (Inspect) Visit Preview May 23, 2025 5:17pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 23, 2025

Walkthrough

The changes update chat handling across the API and UI. The chat schema now requires a non-optional id, and chat creation ensures the specified ID is used. The chat retrieval endpoint no longer returns a 404 on missing chats. The chat component refactors how chatId is managed and passed, ensuring it is always present before rendering.

Changes

File(s) Change Summary
apps/web/app/api/chat/route.ts Updated assistantInputSchema to require non-optional id. Changed chat creation to use provided id. Modified createNewChat signature to accept an object with emailAccountId and chatId.
apps/web/app/api/chats/[chatId]/route.ts Removed explicit 404 error handling for missing chats; now returns chat object directly (possibly null/undefined).
apps/web/components/assistant-chat/chat.tsx Refactored Chat to manage chatId state internally, ensuring a valid chatId before rendering. Added ChatWithEmptySWR internal component. Made chatId required in ChatInner. Updated imports.
apps/web/hooks/useChatMessages.ts Changed useChatMessages parameter from optional string to `string
version.txt Updated version from v1.1.10 to v1.1.11.

Poem

In the warren, chats hop with glee,
Each has an ID, as clear as can be.
No more guessing, no more doubt,
Every bunny knows what their chat’s about!
With a version bump and code made neat,
The carrots of progress taste extra sweet.
🥕✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/web/app/api/chat/route.ts

Oops! Something went wrong! :(

ESLint: 9.24.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

apps/web/hooks/useChatMessages.ts

Oops! Something went wrong! :(

ESLint: 9.24.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

apps/web/components/assistant-chat/chat.tsx

Oops! Something went wrong! :(

ESLint: 9.24.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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

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

🧹 Nitpick comments (2)
apps/web/components/assistant-chat/chat.tsx (2)

47-58: Consider improving the chatId initialization approach.

While the logic correctly ensures a chatId exists before rendering, returning null during initialization could cause a flash of empty content. Consider showing a loading state instead.

- if (!chatId) return null;
+ if (!chatId) return <div>Initializing chat...</div>;

Additionally, consider using a proper UUID library instead of the custom implementation for better reliability and standards compliance.


283-289: Consider using a standard UUID library.

While the custom UUID implementation works, consider using a standard library like uuid or crypto.randomUUID() for better reliability and standards compliance.

- // NOTE: not sure why we don't just use the default from AI SDK
- function generateUUID(): string {
-   return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
-     const r = (Math.random() * 16) | 0;
-     const v = c === "x" ? r : (r & 0x3) | 0x8;
-     return v.toString(16);
-   });
- }
+ function generateUUID(): string {
+   return crypto.randomUUID();
+ }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7fe0fde and aa9ca3c.

📒 Files selected for processing (5)
  • apps/web/app/api/chat/route.ts (3 hunks)
  • apps/web/app/api/chats/[chatId]/route.ts (0 hunks)
  • apps/web/components/assistant-chat/chat.tsx (4 hunks)
  • apps/web/hooks/useChatMessages.ts (1 hunks)
  • version.txt (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/app/api/chats/[chatId]/route.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/components/assistant-chat/chat.tsx (1)
apps/web/hooks/useChatMessages.ts (1)
  • useChatMessages (4-6)
🔇 Additional comments (7)
version.txt (1)

1-1: Version bump looks good.

The version increment appropriately reflects the coordinated changes to chat handling across the codebase.

apps/web/hooks/useChatMessages.ts (1)

4-4: Good type clarification.

Changing from optional parameter to explicit string | null improves type clarity and aligns well with the component refactor that ensures chatId is always explicitly handled.

apps/web/app/api/chat/route.ts (3)

57-60: Chat creation logic looks correct.

The new approach of attempting to retrieve an existing chat before creating ensures consistency with frontend-generated chat IDs.


135-144: Function signature update correctly implements explicit chat ID.

The updated createNewChat function properly accepts and uses the explicit chatId, ensuring the database record matches the frontend-generated ID.


26-26:

Details

✅ Verification successful

Breaking change: ID field now required.

Making the id field required is a significant behavioral change. Ensure all existing clients are updated to provide explicit chat IDs.

Let me verify if there are any existing API calls that might be affected by this change:


🏁 Script executed:

#!/bin/bash
# Search for API calls to /api/chat that might not include an id field
rg -A 10 -B 5 "api/chat" --type typescript --type javascript

Length of output: 95


Let’s broaden the search to pick up all client-side calls, regardless of language type aliases:


🏁 Script executed:

#!/bin/bash
# Search for any usage of '/api/chat' in TS/JS/TSX/JSX files
rg "/api/chat" -A5 -B5 -g '*.ts' -g '*.tsx' -g '*.js' -g '*.jsx'

Length of output: 2658


ID requirement integrated in client

All internal usages of the /api/chat endpoint now include the required id field.

• apps/web/components/assistant-chat/chat.tsx
– In the useChat hook call, experimental_prepareRequestBody injects id: chatId.
• No other /api/chat calls were found in TS/JS/TSX/JSX code.

Internal clients have been updated to comply with the new schema; this breaking change is contained.

apps/web/components/assistant-chat/chat.tsx (2)

60-80: Well-structured component architecture.

The separation of concerns with ChatWithEmptySWR handling SWR configuration and data fetching is clean. The workaround for AI SDK's SWR usage is properly documented.


88-88: Good type safety improvement.

Making chatId required in ChatInner ensures type safety and aligns with the guarantee that a valid chatId exists at this point in the component hierarchy.

@elie222 elie222 merged commit 4db1e07 into main May 23, 2025
4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 4, 2025
@elie222 elie222 deleted the feat/new-chat branch December 18, 2025 23:03
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.

1 participant