Skip to content

Allow AI to use Smart Categories and Webhook when creating rules#295

Merged
elie222 merged 3 commits intomainfrom
smart-category-webhook-prompt
Jan 6, 2025
Merged

Allow AI to use Smart Categories and Webhook when creating rules#295
elie222 merged 3 commits intomainfrom
smart-category-webhook-prompt

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Jan 6, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for smart categories in rule creation
    • Enhanced AI rule generation with new category filtering options
  • Improvements

    • Refined navigation bottom bar layout
    • Updated AI assistant labeling
    • Improved rule schema flexibility
  • UI Changes

    • Simplified navigation menu labels
    • Adjusted navigation layout to use grid system
  • Technical Updates

    • Added webhook URL support in rule actions
    • Introduced more granular category-based rule filtering

@vercel
Copy link

vercel bot commented Jan 6, 2025

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

Name Status Preview Updated (UTC)
inbox-zero ✅ Ready (Inspect) Visit Preview Jan 6, 2025 8:03pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

Walkthrough

This pull request introduces enhancements to the AI rule generation and processing system across multiple files. The changes primarily focus on adding support for smart categories, modifying rule schema definitions, and improving the flexibility of AI-driven rule creation. The modifications span test files, utility functions, and component layouts, with a particular emphasis on extending the aiPromptToRules function to handle category-based filtering and webhook URLs.

Changes

File Change Summary
apps/web/__tests__/ai-prompt-to-rules.test.ts Added hasSmartCategories: false parameter to aiPromptToRules function calls
apps/web/app/(app)/automation/RulesPrompt.tsx Modified onboarding completion logic and minor layout adjustments
apps/web/components/NavBottom.tsx Changed navigation layout to grid and simplified "AI Personal Assistant" label to "Assistant"
apps/web/utils/actions/ai-rule.ts Added categories to user selection and introduced hasSmartCategories variable
apps/web/utils/ai/rule/create-rule-schema.ts Added new schemas for rule types, introduced createRuleSchemaWithCategories
apps/web/utils/ai/rule/create-rule.ts Added webhookUrl to action mapping
apps/web/utils/ai/rule/prompt-to-rules.ts Updated aiPromptToRules function with hasSmartCategories parameter and schema selection logic

Sequence Diagram

sequenceDiagram
    participant User
    participant RulesPrompt
    participant AIPromptToRules
    participant RuleSchema

    User->>RulesPrompt: Submits AI Prompt
    RulesPrompt->>AIPromptToRules: Call with hasSmartCategories
    AIPromptToRules->>RuleSchema: Select Appropriate Schema
    RuleSchema-->>AIPromptToRules: Return Validated Schema
    AIPromptToRules->>AIPromptToRules: Process Rules with Categories
    AIPromptToRules-->>RulesPrompt: Return Processed Rules
Loading

Possibly related PRs

Poem

🐰 Hop into the world of smart rules,
Where categories dance and AI unfurls,
Webhooks whisper, schemas align,
A rabbit's code, both clever and fine!
Automation's magic, now more refined! 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5f5ab55 and c0a6738.

📒 Files selected for processing (7)
  • apps/web/__tests__/ai-prompt-to-rules.test.ts (2 hunks)
  • apps/web/app/(app)/automation/RulesPrompt.tsx (3 hunks)
  • apps/web/components/NavBottom.tsx (2 hunks)
  • apps/web/utils/actions/ai-rule.ts (5 hunks)
  • apps/web/utils/ai/rule/create-rule-schema.ts (3 hunks)
  • apps/web/utils/ai/rule/create-rule.ts (1 hunks)
  • apps/web/utils/ai/rule/prompt-to-rules.ts (2 hunks)
🔇 Additional comments (17)
apps/web/utils/ai/rule/create-rule.ts (1)

43-43: LGTM! Verify webhook URL handling.

The addition of webhookUrl field is properly implemented with null-safe access.

Let's verify the webhook URL field is consistently handled across the codebase:

✅ Verification successful

Webhook URL handling verified and consistent

The webhook URL field is properly implemented across the codebase:

  • Validated as a nullable string in the schema
  • Consistently handled in both rule creation paths
  • Properly implements null-safety checks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for webhook URL related fields and validations
rg -g '*.ts' -g '*.tsx' 'webhookUrl'

Length of output: 303


Script:

#!/bin/bash
# Check schema definition and surrounding context
rg -g '*.ts' -g '*.tsx' -B 2 -A 2 'webhookUrl: z'

Length of output: 447

apps/web/components/NavBottom.tsx (2)

29-29: LGTM! Grid layout improves spacing.

The change from flex to grid with explicit column count ensures consistent spacing.


53-53: LGTM! Shorter label improves mobile display.

Simplifying "AI Personal Assistant" to "Assistant" makes the navigation more concise on mobile devices.

apps/web/utils/ai/rule/prompt-to-rules.ts (5)

4-7: LGTM! Clean import organization.

The imports are properly organized to support the new category functionality.


15-17: LGTM! Schema extension maintains type safety.

The category schema properly extends the base schema while preserving optional ruleId.


23-23: LGTM! Clear parameter addition.

The hasSmartCategories parameter is properly typed and documented.

Also applies to: 28-28


30-36: LGTM! Well-encapsulated schema selection.

The getSchema function cleanly encapsulates the logic for selecting the appropriate schema based on both editing state and smart categories support.


88-88: LGTM! Consistent webhook support.

The webhookUrl field is handled consistently with other action fields.

apps/web/utils/ai/rule/create-rule-schema.ts (3)

3-11: LGTM! Schema types are well-defined.

The addition of CategoryFilterType and the inclusion of RuleType.CATEGORY in allTypesSchema properly support the smart categories feature.


86-90: LGTM! Webhook URL field is properly typed.

The webhookUrl field is correctly defined with proper nullish handling and transformation.


101-115: LGTM! Category filtering schema is well-structured.

The createRuleSchemaWithCategories extension properly implements category filtering with:

  • Correct type inheritance from base schema
  • Clear distinction between include/exclude filtering
  • Optional array of category filters
apps/web/app/(app)/automation/RulesPrompt.tsx (3)

66-70: LGTM! Improved onboarding flow.

The condition if (!data?.rulesPrompt) ensures the persona dialog only opens for new users without existing rules.


227-227: LGTM! Enhanced button container layout.

The addition of flex-wrap improves responsiveness by allowing buttons to wrap on smaller screens.


293-293: LGTM! Refined padding for better visual balance.

The padding adjustment from px-6 to px-4 provides better spacing in the examples section.

apps/web/utils/actions/ai-rule.ts (3)

546-546: LGTM! Proper category data fetching.

The categories selection is correctly added to the user query with minimal data retrieval (only IDs).


576-577: LGTM! Clear smart categories detection.

The hasSmartCategories flag is properly derived from the user's categories array length.


615-615: LGTM! Consistent usage of smart categories flag.

The hasSmartCategories flag is consistently passed to all aiPromptToRules calls, ensuring uniform handling across different rule operations (adding, editing, and creating new rules).

Also applies to: 698-698, 744-744

user,
promptFile,
isEditing: false,
hasSmartCategories: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add test coverage for smart categories.

While the hasSmartCategories parameter is properly added to existing tests, we should add test cases with hasSmartCategories=true to ensure the category functionality works correctly.

Consider adding these test cases:

  1. Converting prompts with category-specific rules
  2. Error handling with invalid category formats
  3. Mixed rules with and without categories

Example test structure:

it("should handle smart categories in rules", async () => {
  const user = {
    email: "user@test.com",
    aiModel: null,
    aiProvider: null,
    aiApiKey: null,
  };

  const prompts = [
    `* Add to category "Important" when from boss@company.com`,
    `* Move to category "Archive" all newsletters`,
  ];

  const result = await aiPromptToRules({
    user,
    promptFile: prompts.join("\n"),
    isEditing: false,
    hasSmartCategories: true,
  });

  // Add appropriate assertions
});

Also applies to: 126-131

@elie222 elie222 merged commit 48c0673 into main Jan 6, 2025
4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 19, 2025
This was referenced Mar 16, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 25, 2025
@coderabbitai coderabbitai bot mentioned this pull request Nov 5, 2025
@coderabbitai coderabbitai bot mentioned this pull request Nov 13, 2025
@elie222 elie222 deleted the smart-category-webhook-prompt branch December 18, 2025 23:09
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