fix: Fix digest shadowed schema and guard for empty summary#597
fix: Fix digest shadowed schema and guard for empty summary#597elie222 merged 2 commits intoelie222:mainfrom
Conversation
|
@edulelis is attempting to deploy a commit to the Inbox Zero Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes update the AI email digest summarization and validation logic. They introduce stricter schema validation, allow for null summaries, refactor prompt construction, and improve handling of empty or invalid summaries to prevent further processing. Naming conventions for schemas are standardized, and unused imports are removed. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API_Route (/api/ai/digest/route.ts)
participant Summarizer (summarize-email-for-digest.ts)
participant UpsertLogic
Client->>API_Route: POST email to summarize
API_Route->>Summarizer: Call aiSummarizeEmailForDigest
Summarizer-->>API_Route: Return summary or null
alt Summary is falsy
API_Route->>API_Route: Log and return 200 (skip upsert)
else Summary is valid
API_Route->>UpsertLogic: Upsert digest with summary
UpsertLogic-->>API_Route: Upsert result
API_Route-->>Client: Return 200
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (4)
🧰 Additional context used📓 Path-based instructions (14)apps/web/**/*.{ts,tsx}📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)
Files:
apps/web/app/**📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)
Files:
apps/web/app/api/**/route.ts📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)
Files:
!{.cursor/rules/*.mdc}📄 CodeRabbit Inference Engine (.cursor/rules/cursor-rules.mdc)
Files:
**/*.ts📄 CodeRabbit Inference Engine (.cursor/rules/form-handling.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit Inference Engine (.cursor/rules/logging.mdc)
Files:
**/api/**/route.ts📄 CodeRabbit Inference Engine (.cursor/rules/security.mdc)
Files:
apps/web/app/api/**/*.{ts,js}📄 CodeRabbit Inference Engine (.cursor/rules/security-audit.mdc)
Files:
**/*.{js,jsx,ts,tsx}📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)
Files:
!pages/_document.{js,jsx,ts,tsx}📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)
Files:
apps/web/utils/{ai,llms}/**/*📄 CodeRabbit Inference Engine (.cursor/rules/llm.mdc)
Files:
apps/web/utils/{ai,llms}/**/*.ts📄 CodeRabbit Inference Engine (.cursor/rules/llm.mdc)
Files:
apps/web/utils/**📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)
Files:
apps/web/utils/**/*.ts📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)
Files:
🧠 Learnings (5)📓 Common learningsapps/web/app/api/ai/digest/route.ts (10)Learnt from: edulelis Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR apps/web/app/api/resend/digest/validation.ts (10)Learnt from: edulelis Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR apps/web/app/api/resend/digest/route.ts (14)Learnt from: edulelis Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR apps/web/utils/ai/digest/summarize-email-for-digest.ts (14)Learnt from: edulelis Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR Learnt from: CR ⏰ 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)
🔇 Additional comments (9)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
|
|
||
| export const DigestEmailSummarySchema = z | ||
| .object({ | ||
| export const digestEmailSummarySchema = z.union([ |
There was a problem hiding this comment.
This constant conflicted with the type below.
Not sure why this didn't give a compilation error.
I'm hoping the union here is a bit clearer to the AI.
| - If the email is spam, promotional content, or not worth summarizing, return null. | ||
| - Return ONLY valid JSON - no HTML, no tables, no explanatory text. | ||
|
|
||
| Return a valid JSON object with either "entries" array, "summary" string, or null.`; |
There was a problem hiding this comment.
Moved this to the system part.
| import type { EmailForLLM } from "@/utils/types"; | ||
| import { stringifyEmailSimple } from "@/utils/stringify-email"; | ||
| import { DigestEmailSummarySchema as schema } from "@/app/api/resend/digest/validation"; | ||
| import { digestEmailSummarySchema as schema } from "@/app/api/resend/digest/validation"; |
There was a problem hiding this comment.
i would move this schema in here like we do in every other place in the app
Summary by CodeRabbit
Bug Fixes
Refactor