Replace callDriver with direct mail manager methods#1466
Conversation
WalkthroughThis change removes the generic Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant TRPC_Router
participant ZeroAgent
participant MailManager
Client->>TRPC_Router: API call (e.g., createDraft)
TRPC_Router->>ZeroAgent: createDraft(input)
ZeroAgent->>MailManager: createDraft(input)
MailManager-->>ZeroAgent: result
ZeroAgent-->>TRPC_Router: result
TRPC_Router-->>Client: result
Possibly related PRs
Poem
✨ Finishing Touches
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
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/server/src/routes/chat.ts (1)
359-583: Excellent refactoring that improves type safety and code clarity.The replacement of the generic
callDrivermethod with explicit, strongly-typed methods is a significant improvement. Each method follows a consistent pattern of driver validation and delegation.However, there are a few areas for improvement:
Redundant methods: Some methods appear to have overlapping functionality:
listThreads(line 360) vslist(line 509)markThreadsRead(line 380) vsmarkAsRead(line 522)markThreadsUnread(line 390) vsmarkAsUnread(line 529)Type safety: Many parameters use
anytype, which could be improved with proper interfaces.Consider consolidating redundant methods and improving type definitions:
- async markThreadsRead(threadIds: string[]) { - if (!this.driver) { - throw new Error('No driver available'); - } - return await this.driver.modifyLabels(threadIds, { - addLabels: [], - removeLabels: ['UNREAD'], - }); - } - async markThreadsUnread(threadIds: string[]) { - if (!this.driver) { - throw new Error('No driver available'); - } - return await this.driver.modifyLabels(threadIds, { - addLabels: ['UNREAD'], - removeLabels: [], - }); - }And improve type definitions for better type safety:
- async createDraft(draftData: any) { + async createDraft(draftData: DraftData) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/server/src/routes/chat.ts(1 hunks)apps/server/src/trpc/routes/drafts.ts(2 hunks)apps/server/src/trpc/routes/label.ts(4 hunks)apps/server/src/trpc/routes/mail.ts(19 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (12)
apps/server/src/trpc/routes/drafts.ts (3)
10-10: LGTM - Clean refactoring to explicit method call.The change from
callDriver('createDraft', input)tocreateDraft(input)improves type safety and code clarity.
16-16: LGTM - Consistent with the refactoring pattern.Direct method call is clearer than string-based dispatch.
30-30: LGTM - Explicit method call improves readability.The parameter transformation maintains the same structure while removing the generic
callDriverinvocation.apps/server/src/trpc/routes/label.ts (4)
17-17: LGTM - Direct method call with proper async handling.The addition of
awaitensures proper asynchronous execution.
73-73: LGTM - Clean parameter destructuring and method call.The destructuring of
idfrom input and passing the remaining properties is handled correctly.
86-86: LGTM - Straightforward method call replacement.Direct access to
input.idmaintains the same functionality with better type safety.
47-47: ```shell
#!/bin/bashShow the full createLabel signature in ZeroAgent class to verify accepted fields
rg -n -A15 -B5 "async createLabel" apps/server/src/routes/chat.ts
</details> <details> <summary>apps/server/src/trpc/routes/mail.ts (5)</summary> `25-25`: **LGTM - Clean method call replacement.** The `getThread` method call properly passes the thread ID parameter. --- `47-52`: **LGTM - Proper handling of different draft vs thread listing.** The conditional logic correctly uses `listDrafts` for draft folders and `list` for regular thread listing, maintaining the same parameter structures. Also applies to: 54-60 --- `71-71`: **LGTM - Consistent read/unread operations.** Both `markAsRead` and `markAsUnread` method calls maintain the same parameter passing pattern. Also applies to: 82-82 --- `112-112`: **LGTM - Proper ID normalization and label modification.** The sequence of `normalizeIds` followed by `modifyLabels` maintains the same operational flow with explicit method calls. Also applies to: 116-116 --- `302-304`: **LGTM - Clean conditional logic for draft sending vs creating.** The branching logic properly handles both `sendDraft` and `create` operations based on the presence of `draftId`. </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->

Refactor Mail Manager Methods in ZeroAgent
This PR refactors the
ZeroAgentclass by replacing the genericcallDrivermethod with explicit, type-safe methods for each mail operation. Instead of dynamically calling driver methods throughcallDriver, the code now provides dedicated methods that directly access the driver functionality.Type of Change
Areas Affected
Testing Done
Checklist
Additional Notes
This refactoring improves code readability and type safety by providing explicit methods for each mail operation rather than using a generic
callDrivermethod. The implementation maintains the same functionality while making the code more maintainable and easier to understand.By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit