Skip to content

Migrate to better auth#662

Merged
edulelis merged 102 commits intoelie222:stagingfrom
edulelis:migrate-to-better-auth
Aug 7, 2025
Merged

Migrate to better auth#662
edulelis merged 102 commits intoelie222:stagingfrom
edulelis:migrate-to-better-auth

Conversation

@edulelis
Copy link
Collaborator

@edulelis edulelis commented Aug 7, 2025

Summary by CodeRabbit

  • New Features

    • Introduced support for multiple, independently controlled sidebars, including a new right-hand chat sidebar and associated UI controls.
    • Added an "AI Chat" button for quick access to the chat sidebar.
    • Enhanced chat experience with improved context management and streamlined chat state handling.
  • Improvements

    • Upgraded AI SDK and dependencies for better performance and compatibility.
    • Refined type safety and consistency across chat and assistant features.
    • Enhanced prompt formatting and output readability for AI-generated rules and snippets.
    • Improved error handling and fallback for AI model interactions, including backup model support.
    • Updated authentication, session handling, and account linking logic for improved reliability.
    • Expanded usage tracking to include more detailed token metrics.
  • Bug Fixes

    • Fixed chat input and message handling for a more reliable chat experience.
    • Addressed UI inconsistencies in sidebar and menu button behavior.
  • Chores

    • Updated environment variables and build configurations.
    • Updated documentation comments and code formatting.
    • Bumped version to v2.2.2.

@vercel
Copy link

vercel bot commented Aug 7, 2025

@edulelis is attempting to deploy a commit to the Inbox Zero OSS Program Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update is a comprehensive refactor and modernization of the AI assistant chat, LLM utility abstractions, and related backend and frontend components. It replaces legacy AI invocation methods with new factory-based abstractions for text/object generation, modularizes tool definitions, streamlines schema handling, and updates type definitions throughout. The sidebar system is reworked to support multiple sidebars, and chat state is centralized in a new context provider. Numerous function signatures are updated to support model selection, and logging is reduced or removed in favor of clearer error handling. Supporting files, tests, and configuration are updated accordingly.

Changes

Cohort / File(s) Change Summary
AI LLM Utility Refactor
apps/web/utils/llms/index.ts, apps/web/utils/llms/model.ts, apps/web/utils/llms/model.test.ts, apps/web/env.ts, turbo.json, apps/web/package.json
Replaces legacy LLM functions with factory-based abstractions for text/object generation, updates to LanguageModelV2, adds backup model fallback, disables Ollama, updates environment/config, and aligns tests.
Assistant Chat Tool Modularization
apps/web/utils/ai/assistant/chat.ts, apps/web/components/assistant-chat/tools.tsx, apps/web/components/assistant-chat/types.ts
Refactors assistant chat tools into modular factory functions, updates type definitions, removes generic tool handler, and strengthens per-tool typing.
Chat State Management Overhaul
apps/web/components/assistant-chat/chat.tsx, apps/web/components/assistant-chat/ChatContext.tsx, apps/web/components/assistant-chat/data-stream-handler.tsx, apps/web/components/assistant-chat/examples-dialog.tsx, apps/web/components/assistant-chat/message-editor.tsx, apps/web/components/assistant-chat/message.tsx, apps/web/components/assistant-chat/messages.tsx, apps/web/components/assistant-chat/multimodal-input.tsx, apps/web/components/assistant-chat/overview.tsx, apps/web/components/assistant-chat/suggested-actions.tsx, apps/web/providers/ChatProvider.tsx, apps/web/providers/AppProviders.tsx
Removes SWR and old context, introduces a new ChatProvider context, updates all chat UI and helper components to use new types and context, and removes unused/legacy files.
Sidebar System Refactor
apps/web/components/ui/sidebar.tsx, apps/web/components/SideNavWithTopNav.tsx, apps/web/components/SidebarRight.tsx, apps/web/components/SideNav.tsx, apps/web/components/SideNavMenu.tsx, apps/web/components/ReferralDialog.tsx, apps/web/components/AccountSwitcher.tsx, apps/web/app/(app)/layout.tsx, apps/web/app/(app)/[emailAccountId]/automation/page.tsx, apps/web/app/(app)/[emailAccountId]/assistant/AIChatButton.tsx
Refactors sidebar logic to support multiple named sidebars, updates all sidebar-related components, adds right sidebar for chat, and introduces new chat sidebar button.
AI Utility Refactor: ModelType Propagation
apps/web/utils/ai/choose-rule/ai-choose-args.ts, apps/web/utils/ai/choose-rule/choose-args.ts, apps/web/utils/ai/choose-rule/match-rules.ts, apps/web/utils/ai/choose-rule/run-rules.ts, apps/web/utils/actions/ai-rule.ts, apps/web/utils/cold-email/is-cold-email.ts, apps/web/app/api/google/webhook/process-history-item.ts, apps/web/app/api/outlook/webhook/process-history-item.ts
Adds/propagates modelType parameter to AI rule and cold email functions, updating signatures and internal calls for model-specific logic.
AI Utility Refactor: New Generation Abstractions
apps/web/utils/ai/choose-rule/ai-choose-rule.ts, apps/web/utils/ai/choose-rule/ai-detect-recurring-pattern.ts, apps/web/utils/ai/categorize-sender/ai-categorize-single-sender.ts, apps/web/utils/ai/categorize-sender/ai-categorize-senders.ts, apps/web/utils/ai/clean/ai-clean-select-labels.ts, apps/web/utils/ai/clean/ai-clean.ts, apps/web/utils/ai/digest/summarize-email-for-digest.ts, apps/web/utils/ai/example-matches/find-example-matches.ts, apps/web/utils/ai/group/create-group.ts, apps/web/utils/ai/knowledge/extract-from-email-history.ts, apps/web/utils/ai/knowledge/extract.ts, apps/web/utils/ai/knowledge/writing-style.ts, apps/web/utils/ai/reply/check-if-needs-reply.ts, apps/web/utils/ai/reply/draft-with-knowledge.ts, apps/web/utils/ai/reply/generate-nudge.ts, apps/web/utils/ai/rule/create-rule.ts, apps/web/utils/ai/rule/diff-rules.ts, apps/web/utils/ai/rule/find-existing-rules.ts, apps/web/utils/ai/rule/generate-prompt-on-delete-rule.ts, apps/web/utils/ai/rule/generate-prompt-on-update-rule.ts, apps/web/utils/ai/rule/generate-rules-prompt.ts, apps/web/utils/ai/rule/prompt-to-rules.ts, apps/web/utils/ai/snippets/find-snippets.ts
Replaces direct AI calls with new createGenerateText/createGenerateObject abstractions, moves schemas inline, removes logging, and updates prompt instructions for JSON output.
API and Backend Updates
apps/web/app/api/chat/route.ts, apps/web/utils/ai/assistant/process-user-request.ts, apps/web/utils/ai/actions.ts, apps/web/utils/assistant/process-assistant-email.ts, apps/web/utils/outlook/filter.ts, apps/web/utils/outlook/mail.ts, apps/web/utils/redis/usage.ts, apps/web/utils/usage.ts, apps/web/utils/user.ts, apps/web/utils/auth-client.ts, apps/web/utils/auth.ts, apps/web/prisma/migrations/20250804163003_better_auth/migration.sql
Refactors chat API for bulk message saves, updates function signatures, improves error handling/logging, updates usage tracking types, and modifies auth/session/account hooks and schema.
Frontend and UI Adjustments
apps/web/app/(app)/[emailAccountId]/assistant/ExecutedRulesTable.tsx, apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx, apps/web/app/(app)/[emailAccountId]/assistant/History.tsx, apps/web/app/(app)/[emailAccountId]/assistant/Pending.tsx, apps/web/app/(app)/[emailAccountId]/assistant/ProcessRules.tsx, apps/web/app/(app)/[emailAccountId]/assistant/RulesPrompt.tsx, apps/web/app/(app)/[emailAccountId]/assistant/page.tsx, apps/web/app/(app)/[emailAccountId]/usage/usage.tsx, apps/web/app/(app)/accounts/AddAccount.tsx, apps/web/app/(landing)/login/LoginForm.tsx, apps/web/app/(landing)/login/page.tsx, apps/web/app/(marketing), apps/web/components/Combobox.tsx, apps/web/components/PlanBadge.tsx, apps/web/components/email-list/EmailMessage.tsx, apps/web/components/ui/calendar.ts, apps/web/providers/PostHogProvider.tsx, apps/web/providers/SessionProvider.tsx, apps/web/app/(app)/[emailAccountId]/simple/Summary.tsx
Updates type annotations, imports, and UI logic to match new chat, sidebar, and usage tracking systems; minor bugfixes and code cleanups.
Testing and Miscellaneous
apps/web/__tests__/ai-diff-rules.test.ts, biome.json, version.txt, .cursor/rules/llm.mdc, apps/web/utils/account.ts, apps/web/utils/redis/subscriber.ts
Updates tests for new output format, linter config, version bump, code cleanups, and removes obsolete code/comments.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatUI
    participant ChatProvider
    participant LLMUtils
    participant AIModel

    User->>ChatUI: Enters message / triggers action
    ChatUI->>ChatProvider: handleSubmit(input)
    ChatProvider->>LLMUtils: generateText/generateObject(input, modelOptions)
    LLMUtils->>AIModel: Send prompt, system, schema
    AIModel-->>LLMUtils: AI response (stream/object)
    LLMUtils-->>ChatProvider: Parsed and validated result
    ChatProvider-->>ChatUI: Update chat state/messages
    ChatUI-->>User: Render AI response
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~90+ minutes

  • Complexity: High. This PR spans many files, deeply refactors core abstractions, updates types and interfaces, and touches both backend and frontend logic. Careful review is needed to ensure correctness, type safety, and backward compatibility.

Possibly related PRs

  • Switch to fast model for user actions #631: Adds or propagates a modelType parameter for AI model selection in user actions and rule matching, directly relating to similar changes in this PR.
  • Migrate to ai sdk v5 #592: Refactors assistant chat and AI integration, removing old context and SWR, and migrating to new AI SDK abstractions—overlapping with this PR's chat and AI refactor.
  • Fallback to Haiku if service unavailable #279: Introduces backup model fallback and related environment variables for LLMs, which aligns with this PR's backup model and model selection enhancements.

Poem

A bunny hopped through fields of code,
Refactoring tools with a lighter load.
Sidebars now swing both left and right,
Chat flows with context, clear and bright.
Models chosen with a thoughtful mind—
AI and rabbit, now well-aligned!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Support

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

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 generate unit tests to generate unit tests for 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.

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.

@edulelis edulelis merged commit b5468fe into elie222:staging Aug 7, 2025
8 of 12 checks passed
@socket-security
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​ai-sdk/​provider@​2.0.01001007197100
Added@​ai-sdk/​react@​2.0.0991007197100
Updated@​ai-sdk/​groq@​1.2.9 ⏵ 2.0.0100 +110081 +197 +1100
Added@​ai-sdk/​google@​2.0.01001008297100
Added@​ai-sdk/​anthropic@​2.0.01001008397100
Added@​ai-sdk/​openai@​2.0.01001008497100
Added@​ai-sdk/​amazon-bedrock@​3.0.010010010097100
Addedai@​5.0.0100100100100100

View full report

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.

3 participants

Comments