Allow AI to use Smart Categories and Webhook when creating rules#295
Allow AI to use Smart Categories and Webhook when creating rules#295
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis 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 Changes
Sequence DiagramsequenceDiagram
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
Possibly related PRs
Poem
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? 🪧 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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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
webhookUrlfield 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
CategoryFilterTypeand the inclusion ofRuleType.CATEGORYinallTypesSchemaproperly support the smart categories feature.
86-90: LGTM! Webhook URL field is properly typed.The
webhookUrlfield is correctly defined with proper nullish handling and transformation.
101-115: LGTM! Category filtering schema is well-structured.The
createRuleSchemaWithCategoriesextension 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-wrapimproves responsiveness by allowing buttons to wrap on smaller screens.
293-293: LGTM! Refined padding for better visual balance.The padding adjustment from
px-6topx-4provides 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
hasSmartCategoriesflag is properly derived from the user's categories array length.
615-615: LGTM! Consistent usage of smart categories flag.The
hasSmartCategoriesflag is consistently passed to allaiPromptToRulescalls, 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, |
There was a problem hiding this comment.
🛠️ 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:
- Converting prompts with category-specific rules
- Error handling with invalid category formats
- 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
Summary by CodeRabbit
Release Notes
New Features
Improvements
UI Changes
Technical Updates