Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(gmail): add edit draft and update label tools#4374

Merged
waleedlatif1 merged 6 commits intostagingsimstudioai/sim:stagingfrom
waleedlatif1/gmail-edit-draft-v2simstudioai/sim:waleedlatif1/gmail-edit-draft-v2Copy head branch name to clipboard
May 1, 2026
Merged

feat(gmail): add edit draft and update label tools#4374
waleedlatif1 merged 6 commits intostagingsimstudioai/sim:stagingfrom
waleedlatif1/gmail-edit-draft-v2simstudioai/sim:waleedlatif1/gmail-edit-draft-v2Copy head branch name to clipboard

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Add gmail_edit_draft_v2 — updates a Gmail draft in place via PUT /drafts/{id} so Mothership no longer has to delete and recreate (which churns the draft ID)
  • Add gmail_update_label_v2 — partial label updates via PATCH /labels/{id} (rename, change visibility) without losing the label ID
  • Wire Edit Draft operation into the Gmail block (V2) reusing existing send/draft fields plus a draftId input
  • Uses existing gmail.modify / gmail.labels scopes — no re-auth needed

Type of Change

  • New feature

Testing

Tested manually. Validated both tools against the official Gmail API docs (drafts.update and labels.patch) and confirmed wiring across tool registry, barrel exports, and block definition.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment May 1, 2026 2:53am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 1, 2026

PR Summary

Medium Risk
Adds a new Gmail draft-update API endpoint and wires it into the Gmail block, including attachment handling and threading headers, which could impact email composition behavior if misused. Changes are mostly additive but touch external Gmail API calls and auth-gated routes.

Overview
Adds a new Gmail capability to edit an existing draft in place via gmail_edit_draft_v2, including a new /api/tools/gmail/edit-draft route that builds raw MIME messages (with optional attachments) and updates drafts using Gmail’s PUT /drafts/{id}.

Wires Edit Draft into the Gmail block UI/operation selector (adds required draftId, reuses send/draft fields, and exposes draft outputs for both draft+edit), and updates the integration catalog operation count.

Introduces a tool-only gmail_update_label_v2 for patch-updating Gmail labels (rename/visibility) via PATCH /labels/{id}, registers both new tools in the tool barrel/registry, and updates docs (Gmail tool docs, Linear trigger doc trimming, and a knowledge tool doc/model description fix).

Reviewed by Cursor Bugbot for commit 44b97ad. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 1, 2026

Greptile Summary

This PR adds two new Gmail tools — gmail_edit_draft_v2 (in-place draft update via PUT /drafts/{id}, with a server-side proxy route and block UI integration) and gmail_update_label_v2 (partial label update via PATCH /labels/{id}, tool-only/agent-facing) — and makes a collateral hardening change to the knowledge search tool description.

  • knowledge.mdx docs regression: The rerankerModel description row now literally renders ${SUPPORTED_RERANKER_MODELS.join(', ')} as user-visible text instead of the actual model names (rerank-v4.0-pro, rerank-v4.0-fast, rerank-v3.5). This appears to have been introduced when the docs were regenerated after the search.ts description changed from a template literal to a static string.

Confidence Score: 4/5

Safe to merge after fixing the knowledge.mdx docs regression; all Gmail wiring is correct

One P1 finding (knowledge.mdx shows raw JS expression in public docs) caps the score at 4. The Gmail tool implementations, contract schemas, block wiring, and registry entries are all correct. The P2 error-detail finding in edit-draft/route.ts is non-blocking.

apps/docs/content/docs/en/tools/knowledge.mdx — rerankerModel description renders raw JS instead of model names

Important Files Changed

Filename Overview
apps/docs/content/docs/en/tools/knowledge.mdx Regression: rerankerModel description now shows raw JS template literal ${SUPPORTED_RERANKER_MODELS.join(', ')} instead of actual model names
apps/sim/app/api/tools/gmail/edit-draft/route.ts New server-side proxy route for edit-draft; auth and contract validation are correct; error details from Gmail API are swallowed (only statusText returned, not body)
apps/sim/blocks/blocks/gmail.ts Edit Draft wired into both GmailBlock and GmailV2Block (inherited via spread); access lists, input subblock for draftId, and output conditions all updated correctly
apps/sim/tools/gmail/edit_draft.ts New tool definition for gmail_edit_draft_v2; params, visibility, and request body match the contract schema correctly
apps/sim/tools/gmail/update_label.ts New tool-only tool for gmail_update_label_v2; direct PATCH to Gmail API with proper encodeURIComponent; TSDoc notes intentional omission from block UI
apps/sim/lib/api/contracts/google-tools.ts gmailEditDraftBodySchema correctly extends gmailMailBodySchema with draftId; contract and type exports are complete
apps/sim/tools/knowledge/search.ts SUPPORTED_RERANKER_MODELS import removed; description hardcoded to static string — correct in code, but the generated docs (knowledge.mdx) did not pick up the new static value
apps/sim/tools/registry.ts Both new tools registered correctly under their v2 IDs

Sequence Diagram

sequenceDiagram
    participant UI as Gmail Block (V1/V2)
    participant Tool as gmail_edit_draft_v2
    participant Route as /api/tools/gmail/edit-draft
    participant Gmail as Gmail API

    UI->>Tool: params (draftId, to, body, ...)
    Tool->>Route: POST /api/tools/gmail/edit-draft
    Route->>Route: checkInternalAuth()
    Route->>Route: parseRequest(gmailEditDraftContract)
    alt has attachments
        Route->>Route: processFilesToUserFiles()
        Route->>Route: downloadFileFromStorage()
        Route->>Route: buildMimeMessage()
    else no attachments
        Route->>Route: buildSimpleEmailMessage()
    end
    Route->>Gmail: PUT /drafts/{draftId}
    Gmail-->>Route: { id, message: { id, threadId, labelIds } }
    Route-->>Tool: { success, output: { draftId, messageId, threadId, labelIds } }
    Tool-->>UI: output

    Note over UI,Gmail: gmail_update_label_v2 (tool-only / agent-facing)
    participant Agent as Agent/MCP
    participant LabelTool as gmail_update_label_v2
    Agent->>LabelTool: params (labelId, name, visibility)
    LabelTool->>Gmail: PATCH /labels/{labelId}
    Gmail-->>LabelTool: { id, name, messageListVisibility, labelListVisibility, type }
    LabelTool-->>Agent: output
Loading

Reviews (2): Last reviewed commit: "fix(knowledge): inline reranker model li..." | Re-trigger Greptile

Comment thread apps/sim/blocks/blocks/gmail.ts Outdated
Comment thread apps/docs/content/docs/en/tools/gmail.mdx
Comment thread apps/sim/tools/gmail/update_label.ts
Comment thread apps/sim/blocks/blocks/gmail.ts Outdated
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/docs/content/docs/en/tools/knowledge.mdx Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 44b97ad. Configure here.

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.