Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis pull request introduces a custom prompt feature that integrates deeply into AI-driven email responses. The changes update the AI reply function to include a dynamic system prompt and user-specific custom prompt retrieved from settings. Additionally, modifications are made to the settings page, database schema, and localization strings to support this feature. UI enhancements include improved Tab key handling in the editor, loading state management in the mail list and reply composer, and layout adjustments for better feedback during email sending. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant E as Editor
participant R as ReplyCompose
participant A as AI Response Service
participant O as OpenAI API
U->>E: Compose email
E->>R: Trigger send (Enter/Tab key event)
R->>R: Set isSubmitting to true
R->>A: Call generateAIResponse (with customPrompt)
A->>A: Retrieve user settings (customPrompt)
A->>O: Send API request with formatted prompt
O-->>A: Return AI-generated reply
A-->>R: Provide reply response
R->>U: Display response and update UI
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/mail/components/create/editor.tsx (2)
474-480: Consider using optional chaining for the onTab callback.The current implementation checks if
onTabexists before calling it. Using optional chaining would make the code more concise.-if (onTab && onTab()) { +if (onTab?.()) { e.preventDefault(); e.stopPropagation(); return; }🧰 Tools
🪛 Biome (1.9.4)
[error] 475-475: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
505-510: Consider using optional chaining for the onTab callback in the EditorContent keydown handler.Similar to the previous suggestion, optional chaining would simplify this code.
-if (onTab && onTab()) { +if (onTab?.()) { event.preventDefault(); return true; }🧰 Tools
🪛 Biome (1.9.4)
[error] 506-506: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
apps/mail/actions/ai-reply.ts(5 hunks)apps/mail/app/(routes)/settings/general/page.tsx(3 hunks)apps/mail/components/create/editor.tsx(4 hunks)apps/mail/components/mail/mail-list.tsx(2 hunks)apps/mail/components/mail/reply-composer.tsx(10 hunks)apps/mail/locales/en.json(1 hunks)packages/db/src/schema.ts(1 hunks)packages/db/src/user_settings_default.ts(1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
apps/mail/actions/ai-reply.ts (1)
packages/db/src/schema.ts (2)
session(18-29)userSettings(108-117)
apps/mail/app/(routes)/settings/general/page.tsx (3)
apps/mail/i18n/config.ts (1)
locales(24-24)apps/mail/components/ui/form.tsx (5)
FormField(169-169)FormItem(164-164)FormLabel(165-165)FormControl(166-166)FormDescription(167-167)apps/mail/components/ui/textarea.tsx (1)
Textarea(21-21)
🪛 Biome (1.9.4)
apps/mail/components/create/editor.tsx
[error] 475-475: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 506-506: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🔇 Additional comments (29)
packages/db/src/schema.ts (1)
15-15: Addition of customPrompt field to user table schema.The implementation looks good. Adding this field will allow storing user-specific custom prompts in the database.
packages/db/src/user_settings_default.ts (2)
8-8: Default value for customPrompt is properly initialized.The empty string is an appropriate default value for the custom prompt field.
16-16: Validation schema for customPrompt is properly defined.The schema correctly uses
z.string()for validation, which aligns with the default value's type.apps/mail/components/create/editor.tsx (1)
77-77: New onTab callback property added to EditorProps interface.This addition allows parent components to handle tab key events, which is useful for implementing custom tab navigation.
apps/mail/app/(routes)/settings/general/page.tsx (4)
33-33: Import of Textarea component for the custom prompt field.The Textarea component is appropriately imported for handling multi-line input for the custom prompt.
40-40: Addition of customPrompt to form schema.The form schema correctly defines customPrompt as a string using Zod validation.
56-56: Default value for customPrompt in the form.An empty string is set as the default value, which aligns with the schema in user_settings_default.ts.
195-213: UI implementation for the custom prompt input.The implementation looks good with proper form structure and localization support. The min-height property on the Textarea ensures sufficient space for users to input potentially lengthy custom prompts.
apps/mail/locales/en.json (2)
267-267: Update placeholder variable for localization consistency.The placeholder has been changed from
{language}to{locale}for better consistency with naming conventions in internationalization libraries.
268-270: LGTM: New localization strings for custom AI prompt feature.These new localization strings support the custom AI prompt feature, making it accessible to users through proper UI labels and descriptions.
apps/mail/components/mail/mail-list.tsx (2)
496-496: Improvement in scroll area styling.Removing the
pb-4class eliminates extra padding at the bottom of the scroll area, providing more space for content display.
513-528: Enhanced loading state feedback for better UX.The button now provides visual feedback during loading states with a spinner and text, and is properly disabled when loading. The
rounded-noneclass makes the button styling consistent with the surrounding UI.apps/mail/actions/ai-reply.ts (7)
3-3: Added import for user settings to support custom prompts.The new import enables retrieving user-defined custom prompts from the database.
32-35: Code formatting improvement in function signature.The function signature has been reformatted for better readability.
47-49: Implemented custom prompt retrieval from user settings.This key addition retrieves the user's custom prompt from settings, with a fallback to an empty string if not defined. This is a central feature of the PR that enables personalized AI responses.
56-58: Enhanced AI system prompt with environment variable.Using an environment variable for the system prompt allows for easier configuration changes without code modifications.
67-67: Improved prompt instructions for better AI context awareness.The updated instruction allows the AI to adapt its tone based on the email context, creating more natural-sounding responses.
76-77: Added user's custom prompt to the AI instruction set.This is the core functionality that integrates the user's custom prompt into the AI generation process, allowing for personalized email replies.
87-87: Formatting improvement in API authorization header.The formatting change makes the code more readable while maintaining the same functionality.
apps/mail/components/mail/reply-composer.tsx (10)
219-219: Added loading state for improved UX during email submission.This state variable tracks when an email is being sent, enabling visual feedback to users.
223-223: Implemented proper loading state management.The loading state is now properly set before sending an email and reset in a finally block, ensuring it's always reset even if an error occurs.
Also applies to: 272-273
347-352: Added auto-focus after AI content generation.This UX improvement automatically focuses the editor after AI content is generated, allowing users to immediately start editing the suggested text.
392-398: Added keyboard shortcut for sending emails.The send button ref and Command+Enter handler improve accessibility by allowing users to send emails using keyboard shortcuts.
401-407: Implemented Tab key handling for accepting AI suggestions.This smart addition allows users to quickly accept AI suggestions by pressing Tab, improving workflow efficiency.
483-485: Enhanced editor with keyboard shortcuts and loading state.The editor now supports Command+Enter to send emails, Tab key to accept AI suggestions, and properly disables during submission.
488-489: Added visual feedback for AI suggestions and loading states.The styling changes provide clear visual cues when AI suggestions are available and when the form is submitting.
502-506: Added helpful keyboard shortcut hint.This UI improvement informs users they can press Tab to accept AI suggestions, enhancing discoverability of this feature.
621-626: Added loading state to Save Draft button.The button is now properly disabled during submission to prevent double submissions.
629-641: Enhanced send button with loading state and accessibility.The send button now has a reference for keyboard shortcuts and is properly disabled during submission, with appropriate styling.
* adjustable height * h1 h2 h3 working in reply composer * select dropdown for categories * feat(navbar): update item label based on auth status * feature/persist user settings (#513) * feat: persist setting (codycodes95) * feat: update settings to jsonb * feat: run migration * feat: save changes to db * fix: naming * feat: validate settings schema * feat: add i18n * fix: set i18n variables * fix: coderabbit comment * feat: improve function readability * feat: use hook * fix:update settings --------- Co-authored-by: Cody Partington <codythatsme@gmail.com> * remove unique status from email in schema * early access check added to schema * updated readme * add contributors * remove text-decoration * text-decoration * remove auto focus on search * ahuh * gg * i18n * check email for early access (#519) * check email for early access * one check * saving... * disable buttons * disable * fix * saving... * saving... * minor * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (Catalan) * New translations en.json (Czech) * New translations en.json (German) * New translations en.json (Japanese) * New translations en.json (Korean) * New translations en.json (Polish) * New translations en.json (Portuguese) * New translations en.json (Russian) * New translations en.json (Turkish) * New translations en.json (Latvian) * New translations en.json (Hindi) * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (Catalan) * New translations en.json (German) * New translations en.json (Japanese) * New translations en.json (Korean) * New translations en.json (Polish) * New translations en.json (Portuguese) * New translations en.json (Hindi) * reply and searchbar display * reply ai (#526) * reply ai * ai functionality * line height * adam fixes --------- Co-authored-by: user12224 <122770437+user12224@users.noreply.github.com> Co-authored-by: Nizzy <nizabizaher@gmail.com> * Autocompletions for reply and create * email avatars (#528) * added email avatars * fix small issue * small ui fix * color fix * reply ui * New translations en.json (Japanese) * New translations en.json (Korean) * no drop down * ui fix * wip performance * saving... * saving... * saving... * saving... * - updated phrases - added delay of 2 matching characters * Improved ai with custom prompt (#534) * ai * improved ai * improved-ai-with-custom-prompt * empty commit * removed new lines * empty commit * search * forwarding * search filter removed. all in ai now * saving... * fix double submit on command enter create email * saving... * saving... * turn search ai into a server action * fuix * show most recent email in thread * saving... * saving... * forward and reply in one compose button * saving... * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (Catalan) * New translations en.json (Czech) * New translations en.json (German) * New translations en.json (Japanese) * New translations en.json (Korean) * New translations en.json (Polish) * New translations en.json (Portuguese) * New translations en.json (Russian) * New translations en.json (Turkish) * New translations en.json (Latvian) * New translations en.json (Hindi) * fix to height reply composer * posthog * remove github login for now * refresh * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (Catalan) * New translations en.json (Czech) * New translations en.json (German) * New translations en.json (Japanese) * New translations en.json (Korean) * New translations en.json (Polish) * New translations en.json (Portuguese) * New translations en.json (Russian) * New translations en.json (Turkish) * New translations en.json (Latvian) * New translations en.json (Hindi) * revert * a * fix load more * fix load more * remove use memo from thread to not load when opening an email * fix switching accounts --------- Co-authored-by: Nizzy <nizabizaher@gmail.com> Co-authored-by: pietrodev07 <pietro.dev.07@gmail.com> Co-authored-by: Sergio JVA <60497216+sergio-jva@users.noreply.github.com> Co-authored-by: Cody Partington <codythatsme@gmail.com> Co-authored-by: Ahmet Kilinc <akx9@icloud.com> Co-authored-by: user12224 <122770437+user12224@users.noreply.github.com> Co-authored-by: nizzy <140507264+nizzyabi@users.noreply.github.com> Co-authored-by: [bot] <zero@ibra.rip> Co-authored-by: needle <122770437+needleXO@users.noreply.github.com>
* adjustable height * h1 h2 h3 working in reply composer * select dropdown for categories * feat(navbar): update item label based on auth status * feature/persist user settings (#513) * feat: persist setting (codycodes95) * feat: update settings to jsonb * feat: run migration * feat: save changes to db * fix: naming * feat: validate settings schema * feat: add i18n * fix: set i18n variables * fix: coderabbit comment * feat: improve function readability * feat: use hook * fix:update settings --------- Co-authored-by: Cody Partington <codythatsme@gmail.com> * remove unique status from email in schema * early access check added to schema * updated readme * add contributors * remove text-decoration * text-decoration * remove auto focus on search * ahuh * gg * i18n * check email for early access (#519) * check email for early access * one check * saving... * disable buttons * disable * fix * saving... * saving... * minor * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (Catalan) * New translations en.json (Czech) * New translations en.json (German) * New translations en.json (Japanese) * New translations en.json (Korean) * New translations en.json (Polish) * New translations en.json (Portuguese) * New translations en.json (Russian) * New translations en.json (Turkish) * New translations en.json (Latvian) * New translations en.json (Hindi) * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (Catalan) * New translations en.json (German) * New translations en.json (Japanese) * New translations en.json (Korean) * New translations en.json (Polish) * New translations en.json (Portuguese) * New translations en.json (Hindi) * reply and searchbar display * reply ai (#526) * reply ai * ai functionality * line height * adam fixes --------- Co-authored-by: user12224 <122770437+user12224@users.noreply.github.com> Co-authored-by: Nizzy <nizabizaher@gmail.com> * Autocompletions for reply and create * email avatars (#528) * added email avatars * fix small issue * small ui fix * color fix * reply ui * New translations en.json (Japanese) * New translations en.json (Korean) * no drop down * ui fix * wip performance * saving... * saving... * saving... * saving... * - updated phrases - added delay of 2 matching characters * Improved ai with custom prompt (#534) * ai * improved ai * improved-ai-with-custom-prompt * empty commit * removed new lines * empty commit * search * forwarding * search filter removed. all in ai now * saving... * fix double submit on command enter create email * saving... * saving... * turn search ai into a server action * fuix * show most recent email in thread * saving... * saving... * forward and reply in one compose button * saving... * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (Catalan) * New translations en.json (Czech) * New translations en.json (German) * New translations en.json (Japanese) * New translations en.json (Korean) * New translations en.json (Polish) * New translations en.json (Portuguese) * New translations en.json (Russian) * New translations en.json (Turkish) * New translations en.json (Latvian) * New translations en.json (Hindi) * fix to height reply composer * posthog * remove github login for now * refresh * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (Catalan) * New translations en.json (Czech) * New translations en.json (German) * New translations en.json (Japanese) * New translations en.json (Korean) * New translations en.json (Polish) * New translations en.json (Portuguese) * New translations en.json (Russian) * New translations en.json (Turkish) * New translations en.json (Latvian) * New translations en.json (Hindi) * revert * a * fix load more * fix load more * remove use memo from thread to not load when opening an email * fix switching accounts * navbar changed to login --------- Co-authored-by: Nizzy <nizabizaher@gmail.com> Co-authored-by: pietrodev07 <pietro.dev.07@gmail.com> Co-authored-by: Sergio JVA <60497216+sergio-jva@users.noreply.github.com> Co-authored-by: Cody Partington <codythatsme@gmail.com> Co-authored-by: Adam <x_1337@outlook.com> Co-authored-by: Ahmet Kilinc <akx9@icloud.com> Co-authored-by: user12224 <122770437+user12224@users.noreply.github.com> Co-authored-by: nizzy <140507264+nizzyabi@users.noreply.github.com> Co-authored-by: [bot] <zero@ibra.rip>
Uh oh!
There was an error while loading. Please reload this page.