Skip to content

Comments

Update digest prompt and summary schema. Update digest mail template and props#605

Merged
elie222 merged 3 commits intoelie222:mainfrom
edulelis:digest-emails-v12
Jul 29, 2025
Merged

Update digest prompt and summary schema. Update digest mail template and props#605
elie222 merged 3 commits intoelie222:mainfrom
edulelis:digest-emails-v12

Conversation

@edulelis
Copy link
Collaborator

@edulelis edulelis commented Jul 29, 2025

Summary by CodeRabbit

  • New Features

    • Digest emails now include a mapping of rule category keys to their original display names, improving clarity in email content.
  • Improvements

    • Digest email summaries are now clearly classified as "structured" or "unstructured," enhancing consistency and readability.
    • Summarization prompts and output formats have been refined for better AI classification and summary generation.
    • Digest email rendering updated to support the new summary structure with explicit type and content fields.
  • Bug Fixes

    • Improved handling of empty or unstructured email content in digest summaries.
  • Tests

    • Updated tests to reflect the new summary output format and classification logic.

@vercel
Copy link

vercel bot commented Jul 29, 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 Jul 29, 2025

Walkthrough

This change updates the handling and display of AI-generated email digests. The summarization schema now uses a discriminated union with explicit type and content fields, affecting both the summarizer and its tests. Digest email rendering is updated to use this new schema and can now display original rule names via a passed mapping.

Changes

Cohort / File(s) Change Summary
Digest Email Rule Name Mapping
apps/web/app/api/resend/digest/route.ts
Adds mapping from camelCase rule keys to original rule names, included as ruleNames in email props.
Summarization Schema & Logic
apps/web/utils/ai/digest/summarize-email-for-digest.ts
Changes summarization schema to discriminated union with type and content; updates prompt, logic, and error handling.
Summarization Tests
apps/web/utils/ai/digest/summarize-email-for-digest.test.ts
Updates tests to expect new schema (type and content), adjusts imports, and modifies empty content handling.
Digest Email Rendering
packages/resend/emails/digest.tsx
Updates types and rendering logic to use new summarization schema; supports ruleNames mapping for category display.

Sequence Diagram(s)

sequenceDiagram
    participant API as API Route
    participant Summarizer as AI Summarizer
    participant Email as Digest Email Renderer

    API->>Summarizer: Summarize email content
    Summarizer-->>API: { type, content }
    API->>Email: Send digest props (includes ruleNames, summaries)
    Email-->>User: Render digest with correct rule names and summary format
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇
A schema reborn, with type and with flair,
Now summaries know just how to declare—
Structured or not, the content’s precise,
With rule names restored, the email looks nice.
The tests all align, the logic is neat,
This bunny approves—digest change is complete!
✉️✨

Note

⚡️ Unit Test Generation is now available in beta!

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


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b787ef and dc5622d.

📒 Files selected for processing (1)
  • packages/resend/emails/digest.tsx (14 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
!{.cursor/rules/*.mdc}

📄 CodeRabbit Inference Engine (.cursor/rules/cursor-rules.mdc)

Never place rule files in the project root, in subdirectories outside .cursor/rules, or in any other location

Files:

  • packages/resend/emails/digest.tsx
**/*.tsx

📄 CodeRabbit Inference Engine (.cursor/rules/form-handling.mdc)

**/*.tsx: Use React Hook Form with Zod for validation
Validate form inputs before submission
Show validation errors inline next to form fields

Files:

  • packages/resend/emails/digest.tsx
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/logging.mdc)

**/*.{ts,tsx}: Use createScopedLogger for logging in backend TypeScript files
Typically add the logger initialization at the top of the file when using createScopedLogger
Only use .with() on a logger instance within a specific function, not for a global logger

Import Prisma in the project using import prisma from "@/utils/prisma";

**/*.{ts,tsx}: Don't use TypeScript enums.
Don't use TypeScript const enum.
Don't use the TypeScript directive @ts-ignore.
Don't use primitive type aliases or misleading types.
Don't use empty type parameters in type aliases and interfaces.
Don't use any or unknown as type constraints.
Don't use implicit any type on variable declarations.
Don't let variables evolve into any type through reassignments.
Don't use non-null assertions with the ! postfix operator.
Don't misuse the non-null assertion operator (!) in TypeScript files.
Don't use user-defined types.
Use as const instead of literal types and type annotations.
Use export type for types.
Use import type for types.
Don't declare empty interfaces.
Don't merge interfaces and classes unsafely.
Don't use overload signatures that aren't next to each other.
Use the namespace keyword instead of the module keyword to declare TypeScript namespaces.
Don't use TypeScript namespaces.
Don't export imported variables.
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions.
Don't use parameter properties in class constructors.
Use either T[] or Array consistently.
Initialize each enum member value explicitly.
Make sure all enum members are literal values.

Files:

  • packages/resend/emails/digest.tsx
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)

**/*.{js,jsx,ts,tsx}: Don't use elements in Next.js projects.
Don't use elements in Next.js projects.
Don't use namespace imports.
Don't access namespace imports dynamically.
Don't use global eval().
Don't use console.
Don't use debugger.
Don't use var.
Don't use with statements in non-strict contexts.
Don't use the arguments object.
Don't use consecutive spaces in regular expression literals.
Don't use the comma operator.
Don't use unnecessary boolean casts.
Don't use unnecessary callbacks with flatMap.
Use for...of statements instead of Array.forEach.
Don't create classes that only have static members (like a static namespace).
Don't use this and super in static contexts.
Don't use unnecessary catch clauses.
Don't use unnecessary constructors.
Don't use unnecessary continue statements.
Don't export empty modules that don't change anything.
Don't use unnecessary escape sequences in regular expression literals.
Don't use unnecessary labels.
Don't use unnecessary nested block statements.
Don't rename imports, exports, and destructured assignments to the same name.
Don't use unnecessary string or template literal concatenation.
Don't use String.raw in template literals when there are no escape sequences.
Don't use useless case statements in switch statements.
Don't use ternary operators when simpler alternatives exist.
Don't use useless this aliasing.
Don't initialize variables to undefined.
Don't use the void operators (they're not familiar).
Use arrow functions instead of function expressions.
Use Date.now() to get milliseconds since the Unix Epoch.
Use .flatMap() instead of map().flat() when possible.
Use literal property access instead of computed property access.
Don't use parseInt() or Number.parseInt() when binary, octal, or hexadecimal literals work.
Use concise optional chaining instead of chained logical expressions.
Use regular expression literals instead of the RegExp constructor when possible.
Don't use number literal object member names th...

Files:

  • packages/resend/emails/digest.tsx
!pages/_document.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)

!pages/_document.{js,jsx,ts,tsx}: Don't import next/document outside of pages/_document.jsx in Next.js projects.
Don't import next/document outside of pages/_document.jsx in Next.js projects.

Files:

  • packages/resend/emails/digest.tsx
**/*.{jsx,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)

**/*.{jsx,tsx}: Don't destructure props inside JSX components in Solid projects.
Don't use both children and dangerouslySetInnerHTML props on the same element.
Don't use Array index in keys.
Don't assign to React component props.
Don't define React components inside other components.
Don't use event handlers on non-interactive elements.
Don't assign JSX properties multiple times.
Don't add extra closing tags for components without children.
Use <>...</> instead of ....
Don't insert comments as text nodes.
Don't use the return value of React.render.
Make sure all dependencies are correctly specified in React hooks.
Make sure all React hooks are called from the top level of component functions.
Don't use unnecessary fragments.
Don't pass children as props.
Use semantic elements instead of role attributes in JSX.

Files:

  • packages/resend/emails/digest.tsx
**/*.{html,jsx,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)

**/*.{html,jsx,tsx}: Don't use or elements.
Don't use accessKey attribute on any HTML element.
Don't set aria-hidden="true" on focusable elements.
Don't add ARIA roles, states, and properties to elements that don't support them.
Only use the scope prop on elements.
Don't assign non-interactive ARIA roles to interactive HTML elements.
Make sure label elements have text content and are associated with an input.
Don't assign interactive ARIA roles to non-interactive HTML elements.
Don't assign tabIndex to non-interactive HTML elements.
Don't use positive integers for tabIndex property.
Don't include "image", "picture", or "photo" in img alt prop.
Don't use explicit role property that's the same as the implicit/default role.
Make static elements with click handlers use a valid role attribute.
Always include a title element for SVG elements.
Give all elements requiring alt text meaningful information for screen readers.
Make sure anchors have content that's accessible to screen readers.
Assign tabIndex to non-interactive HTML elements with aria-activedescendant.
Include all required ARIA attributes for elements with ARIA roles.
Make sure ARIA properties are valid for the element's supported roles.
Always include a type attribute for button elements.
Make elements with interactive roles and handlers focusable.
Give heading elements content that's accessible to screen readers (not hidden with aria-hidden).
Always include a lang attribute on the html element.
Always include a title attribute for iframe elements.
Accompany onClick with at least one of: onKeyUp, onKeyDown, or onKeyPress.
Accompany onMouseOver/onMouseOut with onFocus/onBlur.
Include caption tracks for audio and video elements.
Make sure all anchors are valid and navigable.
Ensure all ARIA properties (aria-*) are valid.
Use valid, non-abstract ARIA roles for elements with ARIA roles.
Use valid ARIA state and property values.
Use valid values for the autocomplete attribute on input eleme...

Files:

  • packages/resend/emails/digest.tsx
🧠 Learnings (2)
📓 Common learnings
Learnt from: edulelis
PR: elie222/inbox-zero#576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses `[key: string]: DigestItem[] | undefined | string | Date | undefined` instead of intersection types like `& Record<string, DigestItem[] | undefined>` due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Make Zod schemas as specific as possible to guide the LLM output.
packages/resend/emails/digest.tsx (2)

Learnt from: edulelis
PR: #576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses [key: string]: DigestItem[] | undefined | string | Date | undefined instead of intersection types like & Record<string, DigestItem[] | undefined> due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{html,jsx,tsx} : Give heading elements content that's accessible to screen readers (not hidden with aria-hidden).

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Static Code Analysis Js
  • GitHub Check: Jit Security
🔇 Additional comments (10)
packages/resend/emails/digest.tsx (10)

22-25: Well-structured discriminated union implementation

The DigestContent type properly uses a discriminated union with a type field to distinguish between structured and unstructured content. This provides better type safety than the previous optional fields approach.


97-97: Clean destructuring of the new ruleNames prop

The destructuring properly extracts the ruleNames prop for use in the component.


147-164: Good implementation of custom rule name display

The getCategoryInfo function properly uses the ruleNames mapping to override display names while maintaining fallback behavior. The logic correctly preserves other category properties while updating the display name.


192-198: Minor optimization: cache the items array

Good practice to cache the items array before accessing its length, avoiding repeated type assertions.


309-335: Robust content rendering with proper type guards

The content rendering logic correctly handles the discriminated union:

  • Properly checks for content.type === "structured" and validates the array type
  • Safely renders structured content with proper TypeScript typing
  • Falls back to unstructured content rendering with appropriate type casting

The implementation is type-safe and handles edge cases well.


399-410: Comprehensive ruleNames mapping in preview props

The preview props include a good variety of rule name mappings, including both predefined categories and custom ones like "travel", "funnyStuff", and "orders". This demonstrates the flexibility of the new system.


416-419: Consistent use of new discriminated union structure

All preview content items properly use the new discriminated union structure with explicit type and content fields. The unstructured content examples are well-formed.


445-451: Well-structured preview data for structured content

The structured content examples properly demonstrate the key-value pair format with meaningful labels and values. The receipt data structure is realistic and useful for testing.


691-731: Excellent addition of new category for testing

The new "orders" category provides comprehensive test data with various structured content examples from different merchants. This enhances the preview's usefulness for development and testing.


82-90: Ignore: Flexible index signature is intentional

The permissive index signature on DigestEmailProps (including Record<string, string>) is by design to support dynamic keys and implementation constraints in packages/resend/emails/digest.tsx. There are no more specific “ruleNames” constraints elsewhere in the codebase, and tightening this would break existing usage.

Likely an incorrect or invalid review comment.

✨ 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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

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 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 changed the title WIP: Update digest prompt. Update digest mail template and props WIP: Update digest prompt and summary schema. Update digest mail template and props Jul 29, 2025
@edulelis edulelis changed the title WIP: Update digest prompt and summary schema. Update digest mail template and props Update digest prompt and summary schema. Update digest mail template and props Jul 29, 2025
@elie222 elie222 merged commit 91f2a34 into elie222:main Jul 29, 2025
9 of 10 checks passed
@edulelis edulelis deleted the digest-emails-v12 branch August 29, 2025 14:37
@coderabbitai coderabbitai bot mentioned this pull request Sep 30, 2025
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.

2 participants