Skip to content

Increase context for choosing rule#373

Merged
elie222 merged 7 commits intomainfrom
increased-rule-context
Mar 20, 2025
Merged

Increase context for choosing rule#373
elie222 merged 7 commits intomainfrom
increased-rule-context

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Mar 20, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced processing of message threads to leverage multiple messages for richer context, leading to more accurate AI responses.
    • Improved formatting of previous messages for clearer and concise conversation history.
  • Refactor

    • Unified the message input structure across various functionalities for consistent behavior.
    • Refined inbound reply tracking and cleanup logic to better manage conversation data.

@vercel
Copy link

vercel bot commented Mar 20, 2025

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

Name Status Preview Updated (UTC)
inbox-zero ✅ Ready (Inspect) Visit Preview Mar 20, 2025 1:28pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request refactors how emails are handled by updating the aiChooseRule function and its related calls. The single email parameter has been replaced with a messages array across tests and utility files. In addition, type definitions and helper functions have been adjusted to support multiple message objects, including changes in prompt construction and dataset insertion logic with Braintrust.

Changes

Files Change Summary
apps/web/__tests__/ai-choose-rule.test.ts, apps/web/utils/ai/choose-rule/ai-choose-rule.ts, apps/web/utils/ai/choose-rule/match-rules.ts, apps/web/utils/reply-tracker/inbound.ts, apps/web/utils/actions/ai-rule.ts, apps/web/utils/ai/choose-rule/run-rules.ts Updated function signatures and call-sites to replace the single email parameter with a messages array. Type definitions, error checks, and prompt creation logic were modified to extract and process the last message.
apps/web/utils/ai/clean/ai-clean.ts, apps/web/utils/stringify-email.ts Introduced the stringifyPreviousEmails helper function to format email threads and integrated the Braintrust dataset insertion by uncommenting and updating the relevant logic.
apps/web/utils/gmail/thread.ts Added a new function getThreadMessages to retrieve messages from a Gmail thread, replacing the previous implementation.
apps/web/utils/reply-tracker/check-previous-emails.ts Updated the argument passed to handleInboundReply to use an array of messages instead of a single message.
apps/web/utils/ai/choose-rule/match-rules.test.ts Modified test cases to pass an array of messages to the findMatchingRule function instead of a single message.

Possibly related PRs

  • Adjust group matches #285: The changes in the main PR, which involve modifying the aiChooseRule function to accept an array of messages instead of a single email object, are related to the changes in the retrieved PR, which also involves updates to the handling of message inputs in the findMatchingRule function to accommodate multiple messages.
  • Allow AI to use Smart Categories and Webhook when creating rules #295: The changes in the main PR, which involve modifying the aiChooseRule function to accept an array of messages instead of a single email object, are related to the retrieved PR, as both involve adjustments to function signatures and handling of message inputs, specifically in the context of processing multiple messages.
  • Persona onboarding for AI assistant #292: The changes in the main PR, which involve modifying the aiChooseRule function to accept an array of messages instead of a single email object, are related to the changes in the retrieved PR, as both involve updates to function signatures and handling of message inputs in a similar context.

Poem

In the code garden where emails once grew,
I've hopped to a rhythm refreshingly new.
From one lonely email to a vibrant array,
Each message now dances in a structured ballet.
I, the merry rabbit, skip with delight,
Celebrating tidy changes from morning to night!
🐰💻🌼

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/utils/ai/choose-rule/match-rules.test.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser '@typescript-eslint/parser' declared in 'apps/web/.eslintrc.json': Cannot find module '@typescript-eslint/parser'
Require stack:

  • /apps/web/.eslintrc.json
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)
apps/web/utils/ai/choose-rule/match-rules.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser '@typescript-eslint/parser' declared in 'apps/web/.eslintrc.json': Cannot find module '@typescript-eslint/parser'
Require stack:

  • /apps/web/.eslintrc.json
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)
apps/web/utils/actions/ai-rule.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser '@typescript-eslint/parser' declared in 'apps/web/.eslintrc.json': Cannot find module '@typescript-eslint/parser'
Require stack:

  • /apps/web/.eslintrc.json
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)
  • 7 others

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e89370f and e1a36c3.

📒 Files selected for processing (10)
  • apps/web/app/api/google/webhook/process-history-item.ts (5 hunks)
  • apps/web/utils/actions/ai-rule.ts (4 hunks)
  • apps/web/utils/ai/choose-rule/match-rules.test.ts (14 hunks)
  • apps/web/utils/ai/choose-rule/match-rules.ts (2 hunks)
  • apps/web/utils/ai/choose-rule/run-rules.ts (2 hunks)
  • apps/web/utils/ai/clean/ai-clean.ts (4 hunks)
  • apps/web/utils/gmail/thread.ts (1 hunks)
  • apps/web/utils/reply-tracker/check-previous-emails.ts (1 hunks)
  • apps/web/utils/reply-tracker/inbound.ts (3 hunks)
  • apps/web/utils/stringify-email.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings 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.

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.

@elie222 elie222 merged commit 301f3d2 into main Mar 20, 2025
1 of 3 checks passed
@elie222 elie222 deleted the increased-rule-context branch March 20, 2025 13:14
@elie222 elie222 restored the increased-rule-context branch March 20, 2025 15:59
@coderabbitai coderabbitai bot mentioned this pull request Jul 3, 2025
@elie222 elie222 deleted the increased-rule-context branch December 18, 2025 23:07
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

Comments