@open-workspace/email 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -22
- package/alchemy/index.ts +273 -0
- package/drizzle/mailbox/0000_puzzling_dracula.sql +149 -0
- package/drizzle/mailbox/0001_mute_jack_flag.sql +12 -0
- package/drizzle/mailbox/meta/0000_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/0001_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/_journal.json +20 -0
- package/drizzle/mailbox/migrations.js +12 -0
- package/index.ts +3 -1
- package/migrations/{0000_email.sql → 0000_dry_moon_knight.sql} +26 -20
- package/migrations/meta/0000_snapshot.json +125 -109
- package/migrations/meta/_journal.json +2 -2
- package/package.json +74 -68
- package/shared/attachment-preview.ts +37 -27
- package/shared/folder-order.ts +106 -0
- package/shared/mail-authentication.ts +8 -3
- package/shared/mail-feedback.ts +18 -25
- package/shared/mail-headers.ts +114 -39
- package/shared/mail-import.ts +38 -0
- package/shared/mail-path.ts +42 -0
- package/shared/mail-received.ts +174 -31
- package/shared/mail-remote.ts +59 -2
- package/shared/mail-sender-intel.ts +22 -4
- package/shared/mail.ts +77 -28
- package/shared/module.ts +33 -0
- package/shared/office-preview.ts +14 -2
- package/shared/pdfjs-assets.ts +35 -0
- package/shared/permissions.ts +73 -0
- package/shared/webhooks.ts +41 -0
- package/src/admin/blocked-senders.tsx +189 -0
- package/src/client.tsx +97 -0
- package/src/lib/mail-api.ts +9 -0
- package/src/mail/attachment-preview-dialog.tsx +161 -0
- package/src/mail/blocked-senders.tsx +138 -0
- package/src/mail/compose-window-chrome.tsx +194 -0
- package/src/mail/compose-window.tsx +486 -0
- package/src/mail/composer-asset-bookmarks.ts +409 -0
- package/src/mail/composer-asset.tsx +229 -0
- package/src/mail/composer-attachment-list.tsx +138 -0
- package/src/mail/composer-editor-document.ts +65 -0
- package/src/mail/composer-editor.tsx +284 -0
- package/src/mail/composer-linked-attachment-text.ts +12 -0
- package/src/mail/composer-recipient-fields.tsx +165 -0
- package/src/mail/composer-recipients.ts +208 -0
- package/src/mail/composer-session.ts +562 -0
- package/src/mail/composer-toolbar.tsx +303 -0
- package/src/mail/composer-upload-client.ts +105 -0
- package/src/mail/composer-upload-progress.ts +53 -0
- package/src/mail/conversation-list.tsx +550 -0
- package/src/mail/conversation-loading-skeleton.tsx +119 -0
- package/src/mail/conversation-message.tsx +346 -0
- package/src/mail/conversation-reply.tsx +470 -0
- package/src/mail/conversation-selection-toolbar.tsx +322 -0
- package/src/mail/conversation-view.tsx +437 -0
- package/src/mail/delivery-indicator.tsx +272 -0
- package/src/mail/email-html-body.tsx +203 -0
- package/src/mail/folder-glyph.tsx +46 -0
- package/src/mail/folder-manager.tsx +532 -0
- package/src/mail/format-bytes.ts +7 -0
- package/src/mail/mail-app-bar.tsx +253 -0
- package/src/mail/mail-background.tsx +12 -0
- package/src/mail/mail-dock.tsx +137 -0
- package/src/mail/mail-folders.ts +44 -0
- package/src/mail/mail-layout.css +236 -0
- package/src/mail/mail-location.ts +73 -0
- package/src/mail/mail-mailbox-sheet.tsx +275 -0
- package/src/mail/mail-nav-rail.tsx +129 -0
- package/src/mail/mail-nav.tsx +324 -0
- package/src/mail/mail-prefetch.ts +59 -0
- package/src/mail/mail-primitives.tsx +66 -0
- package/src/mail/mail-queries.ts +209 -0
- package/src/mail/mail-query-cache.ts +486 -0
- package/src/mail/mail-seed.ts +47 -0
- package/src/mail/mail-shell.tsx +126 -0
- package/src/mail/mailbox-ai-settings.tsx +185 -0
- package/src/mail/mailbox-realtime.tsx +251 -0
- package/src/mail/mailbox-route.tsx +15 -0
- package/src/mail/message-actions.tsx +353 -0
- package/src/mail/message-attachments.tsx +200 -0
- package/src/mail/message-format.ts +75 -0
- package/src/mail/message-header.tsx +260 -0
- package/src/mail/message-translation.tsx +225 -0
- package/src/mail/original-message-sheet.tsx +619 -0
- package/src/mail/original-message.ts +191 -0
- package/src/mail/outbound-notification.ts +53 -0
- package/src/mail/pane-splitter.tsx +117 -0
- package/src/mail/pdf-preview-toolbar.tsx +152 -0
- package/src/mail/pdf-preview.css +44 -0
- package/src/mail/pdf-preview.tsx +156 -0
- package/src/mail/pdf-translation-layout.ts +95 -0
- package/src/mail/print-message.ts +92 -0
- package/src/mail/reader-pane.tsx +535 -0
- package/src/mail/recipient-combobox.tsx +335 -0
- package/src/mail/recipient-field-row.tsx +34 -0
- package/src/mail/reply-to-warning.tsx +50 -0
- package/src/mail/sanitize-email-html.ts +430 -0
- package/src/mail/sender-actions.tsx +149 -0
- package/src/mail/sender-authentication.tsx +485 -0
- package/src/mail/sender-dialogs.tsx +384 -0
- package/src/mail/sender-security.tsx +545 -0
- package/src/mail/toolbar-tooltip.tsx +29 -0
- package/src/mail/translation-html.ts +49 -0
- package/src/mail/translation-language.ts +21 -0
- package/src/mail/types.ts +53 -0
- package/src/mail/unread-document-indicator.tsx +60 -0
- package/src/mail/use-compose-submission.ts +208 -0
- package/src/mail/use-composer-attachment-preflight.ts +184 -0
- package/src/mail/use-composer-submission.ts +117 -0
- package/src/mail/use-conversation-selection.ts +186 -0
- package/src/mail/use-mail-controller.ts +427 -0
- package/src/mail/use-mail-data.ts +279 -0
- package/src/mail/use-mail-safety.ts +155 -0
- package/src/mail/use-mail-send.ts +142 -0
- package/src/mail/use-pdf-translation-overlay.ts +156 -0
- package/src/mail/use-pdf-translation.ts +100 -0
- package/src/mail/use-pdf-viewer.ts +215 -0
- package/src/mail/use-reply-submission.ts +114 -0
- package/src/mail/use-sanitized-email-html.ts +20 -0
- package/src/mail/use-visible-message-read.ts +138 -0
- package/src/pwa/push-subscription.ts +151 -0
- package/src/settings/mail-apps-page.tsx +235 -0
- package/src/settings/notifications-page.tsx +291 -0
- package/worker/admin/blocked-sender-routes.ts +166 -0
- package/worker/admin/schemas.ts +11 -0
- package/worker/bindings.d.ts +14 -10
- package/worker/db/schema.ts +63 -40
- package/worker/jmap/eventsource.ts +84 -16
- package/worker/jmap/methods.ts +1630 -524
- package/worker/jmap/push-types.ts +27 -0
- package/worker/jmap/push.ts +140 -56
- package/worker/jmap/routes.ts +366 -105
- package/worker/mail/access.ts +258 -21
- package/worker/mail/ai-classification.ts +36 -20
- package/worker/mail/ai-translation.ts +13 -6
- package/worker/mail/auth-headers.ts +395 -137
- package/worker/mail/bimi.ts +200 -73
- package/worker/mail/bootstrap.ts +79 -0
- package/worker/mail/capped-body.ts +36 -0
- package/worker/mail/classification-signals.ts +35 -25
- package/worker/mail/conversation-cursor.ts +30 -19
- package/worker/mail/delivery-events.ts +88 -62
- package/worker/mail/delivery-facts.ts +46 -10
- package/worker/mail/demo-routes.ts +34 -10
- package/worker/mail/doh.ts +62 -23
- package/worker/mail/downloads.ts +75 -40
- package/worker/mail/edge-cache.ts +155 -0
- package/worker/mail/header-metadata.ts +88 -22
- package/worker/mail/impersonation.ts +160 -38
- package/worker/mail/import-routes.ts +313 -0
- package/worker/mail/inbound-delivery.ts +19 -9
- package/worker/mail/inbound-threading.ts +18 -8
- package/worker/mail/inbound.ts +82 -40
- package/worker/mail/ip-intel.ts +110 -27
- package/worker/mail/isolate-cache.ts +35 -0
- package/worker/mail/link-domains.ts +29 -7
- package/worker/mail/mailbox-deletion.ts +10 -4
- package/worker/mail/mailbox-directory.ts +16 -6
- package/worker/mail/mailing-list.ts +94 -39
- package/worker/mail/message-security.ts +90 -15
- package/worker/mail/message-view.ts +18 -6
- package/worker/mail/office-conversion.ts +31 -9
- package/worker/mail/office-preview-container.ts +40 -13
- package/worker/mail/office-preview-queue.ts +76 -32
- package/worker/mail/org-domain.ts +8 -1
- package/worker/mail/outbound-content.ts +71 -26
- package/worker/mail/outbound-delivery.ts +31 -17
- package/worker/mail/outbound-service.ts +48 -30
- package/worker/mail/outbound-threading.ts +30 -17
- package/worker/mail/outbound.ts +97 -70
- package/worker/mail/outgoing-context.ts +25 -15
- package/worker/mail/participants.ts +44 -29
- package/worker/mail/push-notifications.ts +271 -173
- package/worker/mail/quote-parser.ts +21 -10
- package/worker/mail/r2-presigned-urls.ts +31 -25
- package/worker/mail/receive.ts +23 -11
- package/worker/mail/recipients.ts +6 -1
- package/worker/mail/remote-proxy.ts +187 -31
- package/worker/mail/remote-routes.ts +87 -0
- package/worker/mail/remote-token.ts +104 -0
- package/worker/mail/repeat.ts +19 -0
- package/worker/mail/reply-plan.ts +62 -33
- package/worker/mail/rfc.ts +32 -7
- package/worker/mail/routes.ts +870 -541
- package/worker/mail/safety-routes.ts +328 -200
- package/worker/mail/schemas.ts +84 -105
- package/worker/mail/search.ts +1 -0
- package/worker/mail/security-settings.ts +41 -9
- package/worker/mail/sender-intel.ts +206 -51
- package/worker/mail/spamhaus.ts +92 -45
- package/worker/mail/unsubscribe.ts +76 -18
- package/worker/mail/uploads.ts +126 -93
- package/worker/mail/webhook-source.ts +35 -12
- package/worker/mail/workspace-safety.ts +97 -38
- package/worker/mailbox/demo-html.ts +7 -7
- package/worker/mailbox/demo-seed.ts +10 -44
- package/worker/mailbox/demo.ts +595 -225
- package/worker/mailbox/email-index.ts +53 -0
- package/worker/mailbox/folder-model.ts +53 -17
- package/worker/mailbox/import-placement.ts +88 -0
- package/worker/mailbox/inbox-counts.ts +106 -0
- package/worker/mailbox/index.ts +1734 -721
- package/worker/mailbox/jmap-store.ts +139 -35
- package/worker/mailbox/model.ts +8 -6
- package/worker/mailbox/office-preview-jobs.ts +56 -25
- package/worker/mailbox/schema.ts +87 -66
- package/worker/mailbox/senders.ts +176 -70
- package/worker/mcp/mail-action-tools.ts +128 -87
- package/worker/mcp/mail-compose-tools.ts +133 -82
- package/worker/mcp/mail-query-tools.ts +120 -71
- package/worker/mcp/mail-safety-tools.ts +321 -248
- package/worker/mcp/schemas.ts +43 -0
- package/worker/mcp/tools.ts +13 -10
- package/worker/module.ts +43 -18
- package/worker/sql.d.ts +8 -0
- package/alchemy.ts +0 -142
- package/containers/office-preview/Dockerfile +0 -10
- package/shared/mail-rules.ts +0 -156
- package/worker/admin/report-routes.ts +0 -164
- package/worker/mail/reported-messages.ts +0 -68
- package/worker/mailbox/migrations.ts +0 -10
- package/worker/mailbox/rules.ts +0 -110
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
ScopedToolRegistrar,
|
|
3
|
+
AccountApiClient,
|
|
4
|
+
} from "@open-workspace/core/module";
|
|
5
|
+
import { apiPath, runTool } from "@open-workspace/core/module";
|
|
2
6
|
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
import {
|
|
7
|
+
|
|
8
|
+
import { MAIL_ORGANIZE_SCOPE, MAIL_READ_SCOPE } from "../../shared/permissions";
|
|
5
9
|
import {
|
|
6
10
|
conversationIdsSchema,
|
|
7
11
|
entityIdSchema,
|
|
8
12
|
mailboxIdSchema,
|
|
9
13
|
mailboxStateSchema,
|
|
10
|
-
} from "
|
|
14
|
+
} from "./schemas";
|
|
11
15
|
|
|
12
16
|
const write = {
|
|
13
17
|
readOnlyHint: false,
|
|
@@ -16,12 +20,16 @@ const write = {
|
|
|
16
20
|
openWorldHint: false,
|
|
17
21
|
} as const;
|
|
18
22
|
|
|
19
|
-
export function registerMailActionTools(
|
|
20
|
-
|
|
23
|
+
export function registerMailActionTools(
|
|
24
|
+
tool: ScopedToolRegistrar,
|
|
25
|
+
api: AccountApiClient
|
|
26
|
+
) {
|
|
27
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
21
28
|
"set_message_read",
|
|
22
29
|
{
|
|
23
30
|
title: "Mark message read or unread",
|
|
24
|
-
description:
|
|
31
|
+
description:
|
|
32
|
+
"Set the current account's personal read state for one message.",
|
|
25
33
|
inputSchema: z.object({
|
|
26
34
|
mailboxId: mailboxIdSchema,
|
|
27
35
|
messageId: entityIdSchema,
|
|
@@ -29,17 +37,23 @@ export function registerMailActionTools(server: McpServer, api: AccountApiClient
|
|
|
29
37
|
}),
|
|
30
38
|
annotations: write,
|
|
31
39
|
},
|
|
32
|
-
({ mailboxId, messageId, isRead }) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
({ mailboxId, messageId, isRead }) =>
|
|
41
|
+
runTool(() =>
|
|
42
|
+
api.json(
|
|
43
|
+
apiPath(`/mail/messages/${encodeURIComponent(messageId)}/read`, {
|
|
44
|
+
mailboxId,
|
|
45
|
+
}),
|
|
46
|
+
{ method: "PATCH", json: { isRead } }
|
|
47
|
+
)
|
|
48
|
+
)
|
|
36
49
|
);
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
39
52
|
"set_conversations_read",
|
|
40
53
|
{
|
|
41
54
|
title: "Mark conversations read or unread",
|
|
42
|
-
description:
|
|
55
|
+
description:
|
|
56
|
+
"Set the current account's personal read state for all messages in up to 500 conversations.",
|
|
43
57
|
inputSchema: z.object({
|
|
44
58
|
mailboxId: mailboxIdSchema,
|
|
45
59
|
conversationIds: conversationIdsSchema,
|
|
@@ -47,50 +61,57 @@ export function registerMailActionTools(server: McpServer, api: AccountApiClient
|
|
|
47
61
|
}),
|
|
48
62
|
annotations: write,
|
|
49
63
|
},
|
|
50
|
-
({ mailboxId, conversationIds, isRead }) =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
({ mailboxId, conversationIds, isRead }) =>
|
|
65
|
+
runTool(() =>
|
|
66
|
+
api.json(apiPath("/mail/conversations/bulk", { mailboxId }), {
|
|
67
|
+
method: "PATCH",
|
|
68
|
+
json: { type: "read", conversationIds, isRead },
|
|
69
|
+
})
|
|
70
|
+
)
|
|
57
71
|
);
|
|
58
72
|
|
|
59
|
-
|
|
73
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
60
74
|
"move_conversations",
|
|
61
75
|
{
|
|
62
76
|
title: "Move conversations",
|
|
63
|
-
description:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
description:
|
|
78
|
+
"Move up to 500 conversations between Inbox, Archive, Trash, or a custom folder, or out of Spam. To put mail in Spam use report_conversations (or report_message), which also records the report for the spam classifier.",
|
|
79
|
+
inputSchema: z
|
|
80
|
+
.object({
|
|
81
|
+
mailboxId: mailboxIdSchema,
|
|
82
|
+
conversationIds: conversationIdsSchema,
|
|
83
|
+
sourceFolderId: entityIdSchema,
|
|
84
|
+
// Spam goes through reporting so the classifier learns from it.
|
|
85
|
+
mailboxState: mailboxStateSchema.exclude(["spam"]).optional(),
|
|
86
|
+
folderId: entityIdSchema.nullable().optional(),
|
|
87
|
+
})
|
|
88
|
+
.refine(
|
|
89
|
+
(value) =>
|
|
90
|
+
value.mailboxState !== undefined || value.folderId !== undefined,
|
|
91
|
+
"Provide mailboxState, folderId, or both"
|
|
92
|
+
),
|
|
75
93
|
annotations: write,
|
|
76
94
|
},
|
|
77
95
|
({ mailboxId, conversationIds, sourceFolderId, mailboxState, folderId }) =>
|
|
78
|
-
runTool(() =>
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
runTool(() =>
|
|
97
|
+
api.json(apiPath("/mail/conversations/bulk", { mailboxId }), {
|
|
98
|
+
method: "PATCH",
|
|
99
|
+
json: {
|
|
100
|
+
type: "update",
|
|
101
|
+
conversationIds,
|
|
102
|
+
sourceFolderId,
|
|
103
|
+
update: { mailboxState, folderId },
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
)
|
|
87
107
|
);
|
|
88
108
|
|
|
89
|
-
|
|
109
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
90
110
|
"delete_conversations_permanently",
|
|
91
111
|
{
|
|
92
112
|
title: "Permanently delete conversations",
|
|
93
|
-
description:
|
|
113
|
+
description:
|
|
114
|
+
"Permanently delete up to 500 conversations. Every conversation must already be in Trash.",
|
|
94
115
|
inputSchema: z.object({
|
|
95
116
|
mailboxId: mailboxIdSchema,
|
|
96
117
|
conversationIds: conversationIdsSchema,
|
|
@@ -100,33 +121,37 @@ export function registerMailActionTools(server: McpServer, api: AccountApiClient
|
|
|
100
121
|
destructiveHint: true,
|
|
101
122
|
},
|
|
102
123
|
},
|
|
103
|
-
({ mailboxId, conversationIds }) =>
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
124
|
+
({ mailboxId, conversationIds }) =>
|
|
125
|
+
runTool(() =>
|
|
126
|
+
api.json(apiPath("/mail/conversations/bulk", { mailboxId }), {
|
|
127
|
+
method: "PATCH",
|
|
128
|
+
json: { type: "delete_permanently", conversationIds },
|
|
129
|
+
})
|
|
130
|
+
)
|
|
110
131
|
);
|
|
111
132
|
|
|
112
|
-
|
|
133
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
113
134
|
"create_folder",
|
|
114
135
|
{
|
|
115
136
|
title: "Create custom folder",
|
|
116
|
-
description:
|
|
137
|
+
description:
|
|
138
|
+
"Create a custom folder shared by everyone with access to the mailbox.",
|
|
117
139
|
inputSchema: z.object({
|
|
118
140
|
mailboxId: mailboxIdSchema,
|
|
119
141
|
name: z.string().trim().min(1).max(80),
|
|
120
142
|
}),
|
|
121
143
|
annotations: { ...write, idempotentHint: false },
|
|
122
144
|
},
|
|
123
|
-
({ mailboxId, name }) =>
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
145
|
+
({ mailboxId, name }) =>
|
|
146
|
+
runTool(() =>
|
|
147
|
+
api.json(`/mail/mailboxes/${encodeURIComponent(mailboxId)}/folders`, {
|
|
148
|
+
method: "POST",
|
|
149
|
+
json: { name },
|
|
150
|
+
})
|
|
151
|
+
)
|
|
127
152
|
);
|
|
128
153
|
|
|
129
|
-
|
|
154
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
130
155
|
"rename_folder",
|
|
131
156
|
{
|
|
132
157
|
title: "Rename custom folder",
|
|
@@ -137,13 +162,16 @@ export function registerMailActionTools(server: McpServer, api: AccountApiClient
|
|
|
137
162
|
}),
|
|
138
163
|
annotations: write,
|
|
139
164
|
},
|
|
140
|
-
({ mailboxId, folderId, name }) =>
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
165
|
+
({ mailboxId, folderId, name }) =>
|
|
166
|
+
runTool(() =>
|
|
167
|
+
api.json(
|
|
168
|
+
`/mail/mailboxes/${encodeURIComponent(mailboxId)}/folders/${encodeURIComponent(folderId)}`,
|
|
169
|
+
{ method: "PATCH", json: { name } }
|
|
170
|
+
)
|
|
171
|
+
)
|
|
144
172
|
);
|
|
145
173
|
|
|
146
|
-
|
|
174
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
147
175
|
"delete_folder",
|
|
148
176
|
{
|
|
149
177
|
title: "Delete custom folder",
|
|
@@ -154,57 +182,70 @@ export function registerMailActionTools(server: McpServer, api: AccountApiClient
|
|
|
154
182
|
}),
|
|
155
183
|
annotations: { ...write, destructiveHint: true },
|
|
156
184
|
},
|
|
157
|
-
({ mailboxId, folderId }) =>
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
185
|
+
({ mailboxId, folderId }) =>
|
|
186
|
+
runTool(() =>
|
|
187
|
+
api.json(
|
|
188
|
+
`/mail/mailboxes/${encodeURIComponent(mailboxId)}/folders/${encodeURIComponent(folderId)}`,
|
|
189
|
+
{ method: "DELETE" }
|
|
190
|
+
)
|
|
191
|
+
)
|
|
161
192
|
);
|
|
162
193
|
|
|
163
|
-
|
|
194
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
164
195
|
"reorder_folders",
|
|
165
196
|
{
|
|
166
|
-
title: "Reorder
|
|
167
|
-
description:
|
|
197
|
+
title: "Reorder folders",
|
|
198
|
+
description:
|
|
199
|
+
"Set the complete order of a mailbox's folders: every custom folder and the system folders sent, archive, spam and trash, each once, in display order. Inbox always stays first and is not listed. System folders can be placed among custom ones.",
|
|
168
200
|
inputSchema: z.object({
|
|
169
201
|
mailboxId: mailboxIdSchema,
|
|
170
|
-
folderIds: z.array(entityIdSchema).max(
|
|
202
|
+
folderIds: z.array(entityIdSchema).max(104),
|
|
171
203
|
}),
|
|
172
204
|
annotations: write,
|
|
173
205
|
},
|
|
174
|
-
({ mailboxId, folderIds }) =>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
206
|
+
({ mailboxId, folderIds }) =>
|
|
207
|
+
runTool(() =>
|
|
208
|
+
api.json(
|
|
209
|
+
`/mail/mailboxes/${encodeURIComponent(mailboxId)}/folders/order`,
|
|
210
|
+
{ method: "PUT", json: { folderIds } }
|
|
211
|
+
)
|
|
212
|
+
)
|
|
178
213
|
);
|
|
179
214
|
|
|
180
|
-
|
|
215
|
+
tool(MAIL_READ_SCOPE)(
|
|
181
216
|
"get_mailbox_ai_settings",
|
|
182
217
|
{
|
|
183
218
|
title: "Get mailbox AI rules",
|
|
184
|
-
description:
|
|
219
|
+
description:
|
|
220
|
+
"Read mailbox-level classification instructions and confidence threshold.",
|
|
185
221
|
inputSchema: z.object({ mailboxId: mailboxIdSchema }),
|
|
186
222
|
annotations: { ...write, readOnlyHint: true },
|
|
187
223
|
},
|
|
188
|
-
({ mailboxId }) =>
|
|
189
|
-
|
|
190
|
-
|
|
224
|
+
({ mailboxId }) =>
|
|
225
|
+
runTool(() =>
|
|
226
|
+
api.json(`/mail/mailboxes/${encodeURIComponent(mailboxId)}/ai`)
|
|
227
|
+
)
|
|
191
228
|
);
|
|
192
229
|
|
|
193
|
-
|
|
230
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
194
231
|
"update_mailbox_ai_settings",
|
|
195
232
|
{
|
|
196
233
|
title: "Update mailbox AI rules",
|
|
197
|
-
description:
|
|
234
|
+
description:
|
|
235
|
+
"Update mailbox-level classification instructions and confidence threshold.",
|
|
198
236
|
inputSchema: z.object({
|
|
199
237
|
mailboxId: mailboxIdSchema,
|
|
200
|
-
instructions: z.string().trim().max(
|
|
238
|
+
instructions: z.string().trim().max(4000),
|
|
201
239
|
confidenceThreshold: z.number().int().min(50).max(100),
|
|
202
240
|
}),
|
|
203
241
|
annotations: write,
|
|
204
242
|
},
|
|
205
|
-
({ mailboxId, instructions, confidenceThreshold }) =>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
243
|
+
({ mailboxId, instructions, confidenceThreshold }) =>
|
|
244
|
+
runTool(() =>
|
|
245
|
+
api.json(`/mail/mailboxes/${encodeURIComponent(mailboxId)}/ai`, {
|
|
246
|
+
method: "PUT",
|
|
247
|
+
json: { instructions, confidenceThreshold },
|
|
248
|
+
})
|
|
249
|
+
)
|
|
209
250
|
);
|
|
210
251
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
ScopedToolRegistrar,
|
|
3
|
+
AccountApiClient,
|
|
4
|
+
} from "@open-workspace/core/module";
|
|
5
|
+
import { emailSchema, apiPath, runTool } from "@open-workspace/core/module";
|
|
2
6
|
import { z } from "zod";
|
|
7
|
+
|
|
3
8
|
import {
|
|
4
9
|
MAX_COMPOSER_ATTACHMENT_BYTES,
|
|
5
10
|
MAX_MAIL_RECIPIENTS,
|
|
6
11
|
} from "../../shared/mail";
|
|
7
|
-
import {
|
|
12
|
+
import { MAIL_SEND_SCOPE } from "../../shared/permissions";
|
|
8
13
|
import { dedupeRecipientFields, recipientCount } from "../mail/recipients";
|
|
9
|
-
import { AccountApiClient, apiPath } from "@open-workspace/core/worker/mcp/account-client.ts";
|
|
10
|
-
import { runTool } from "@open-workspace/core/worker/mcp/results.ts";
|
|
11
14
|
import {
|
|
12
15
|
entityIdSchema,
|
|
13
16
|
mailboxIdSchema,
|
|
@@ -15,7 +18,7 @@ import {
|
|
|
15
18
|
recipientFields,
|
|
16
19
|
replyModeSchema,
|
|
17
20
|
requestId,
|
|
18
|
-
} from "
|
|
21
|
+
} from "./schemas";
|
|
19
22
|
|
|
20
23
|
const sendAnnotations = {
|
|
21
24
|
readOnlyHint: false,
|
|
@@ -24,44 +27,61 @@ const sendAnnotations = {
|
|
|
24
27
|
openWorldHint: true,
|
|
25
28
|
} as const;
|
|
26
29
|
|
|
27
|
-
const composeInputSchema = z
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
const composeInputSchema = z
|
|
31
|
+
.object({
|
|
32
|
+
mailboxId: mailboxIdSchema,
|
|
33
|
+
...recipientFields,
|
|
34
|
+
replyTo: emailSchema.optional(),
|
|
35
|
+
subject: z.string().trim().max(998).default(""),
|
|
36
|
+
...messageContentFields,
|
|
37
|
+
})
|
|
38
|
+
.refine(
|
|
39
|
+
(value) => recipientCount(dedupeRecipientFields(value)) > 0,
|
|
40
|
+
"Add at least one recipient"
|
|
41
|
+
)
|
|
42
|
+
.refine(
|
|
43
|
+
(value) =>
|
|
44
|
+
recipientCount(dedupeRecipientFields(value)) <= MAX_MAIL_RECIPIENTS,
|
|
45
|
+
`An email can have at most ${MAX_MAIL_RECIPIENTS} recipients`
|
|
46
|
+
);
|
|
40
47
|
|
|
41
|
-
const forwardInputSchema = z
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
const forwardInputSchema = z
|
|
49
|
+
.object({
|
|
50
|
+
mailboxId: mailboxIdSchema,
|
|
51
|
+
sourceMessageId: entityIdSchema,
|
|
52
|
+
...recipientFields,
|
|
53
|
+
replyTo: emailSchema.optional(),
|
|
54
|
+
...messageContentFields,
|
|
55
|
+
})
|
|
56
|
+
.refine(
|
|
57
|
+
(value) => recipientCount(dedupeRecipientFields(value)) > 0,
|
|
58
|
+
"Add at least one recipient"
|
|
59
|
+
)
|
|
60
|
+
.refine(
|
|
61
|
+
(value) =>
|
|
62
|
+
recipientCount(dedupeRecipientFields(value)) <= MAX_MAIL_RECIPIENTS,
|
|
63
|
+
`An email can have at most ${MAX_MAIL_RECIPIENTS} recipients`
|
|
64
|
+
);
|
|
54
65
|
|
|
55
|
-
export function registerMailComposeTools(
|
|
56
|
-
|
|
66
|
+
export function registerMailComposeTools(
|
|
67
|
+
tool: ScopedToolRegistrar,
|
|
68
|
+
api: AccountApiClient
|
|
69
|
+
) {
|
|
70
|
+
tool(MAIL_SEND_SCOPE)(
|
|
57
71
|
"create_attachment_upload",
|
|
58
72
|
{
|
|
59
73
|
title: "Create attachment upload",
|
|
60
|
-
description:
|
|
74
|
+
description:
|
|
75
|
+
"Create a 15-minute presigned R2 PUT URL. Upload exactly the declared number of bytes to upload.uploadUrl using upload.headers, then call complete_attachment_upload with upload.id.",
|
|
61
76
|
inputSchema: z.object({
|
|
62
77
|
mailboxId: mailboxIdSchema,
|
|
63
78
|
filename: z.string().trim().min(1).max(255),
|
|
64
|
-
contentType: z
|
|
79
|
+
contentType: z
|
|
80
|
+
.string()
|
|
81
|
+
.trim()
|
|
82
|
+
.min(1)
|
|
83
|
+
.max(255)
|
|
84
|
+
.default("application/octet-stream"),
|
|
65
85
|
size: z.number().int().positive().max(MAX_COMPOSER_ATTACHMENT_BYTES),
|
|
66
86
|
}),
|
|
67
87
|
annotations: {
|
|
@@ -71,19 +91,21 @@ export function registerMailComposeTools(server: McpServer, api: AccountApiClien
|
|
|
71
91
|
openWorldHint: false,
|
|
72
92
|
},
|
|
73
93
|
},
|
|
74
|
-
({ mailboxId, filename, contentType, size }) =>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
({ mailboxId, filename, contentType, size }) =>
|
|
95
|
+
runTool(() =>
|
|
96
|
+
api.json(apiPath("/mail/uploads", { mailboxId }), {
|
|
97
|
+
method: "POST",
|
|
98
|
+
json: { filename, contentType, size },
|
|
99
|
+
})
|
|
100
|
+
)
|
|
80
101
|
);
|
|
81
102
|
|
|
82
|
-
|
|
103
|
+
tool(MAIL_SEND_SCOPE)(
|
|
83
104
|
"complete_attachment_upload",
|
|
84
105
|
{
|
|
85
106
|
title: "Complete attachment upload",
|
|
86
|
-
description:
|
|
107
|
+
description:
|
|
108
|
+
"Verify and seal a file uploaded with create_attachment_upload. Use the returned upload id in send_email, reply_to_email, or forward_email attachments.",
|
|
87
109
|
inputSchema: z.object({
|
|
88
110
|
mailboxId: mailboxIdSchema,
|
|
89
111
|
uploadId: entityIdSchema,
|
|
@@ -95,13 +117,18 @@ export function registerMailComposeTools(server: McpServer, api: AccountApiClien
|
|
|
95
117
|
openWorldHint: false,
|
|
96
118
|
},
|
|
97
119
|
},
|
|
98
|
-
({ mailboxId, uploadId }) =>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
120
|
+
({ mailboxId, uploadId }) =>
|
|
121
|
+
runTool(() =>
|
|
122
|
+
api.json(
|
|
123
|
+
apiPath(`/mail/uploads/${encodeURIComponent(uploadId)}/complete`, {
|
|
124
|
+
mailboxId,
|
|
125
|
+
}),
|
|
126
|
+
{ method: "POST" }
|
|
127
|
+
)
|
|
128
|
+
)
|
|
102
129
|
);
|
|
103
130
|
|
|
104
|
-
|
|
131
|
+
tool(MAIL_SEND_SCOPE)(
|
|
105
132
|
"discard_attachment_upload",
|
|
106
133
|
{
|
|
107
134
|
title: "Discard attachment upload",
|
|
@@ -116,31 +143,41 @@ export function registerMailComposeTools(server: McpServer, api: AccountApiClien
|
|
|
116
143
|
openWorldHint: false,
|
|
117
144
|
},
|
|
118
145
|
},
|
|
119
|
-
({ mailboxId, uploadId }) =>
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
146
|
+
({ mailboxId, uploadId }) =>
|
|
147
|
+
runTool(() =>
|
|
148
|
+
api.json(
|
|
149
|
+
apiPath(`/mail/uploads/${encodeURIComponent(uploadId)}`, {
|
|
150
|
+
mailboxId,
|
|
151
|
+
}),
|
|
152
|
+
{ method: "DELETE" }
|
|
153
|
+
)
|
|
154
|
+
)
|
|
123
155
|
);
|
|
124
156
|
|
|
125
|
-
|
|
157
|
+
tool(MAIL_SEND_SCOPE)(
|
|
126
158
|
"send_email",
|
|
127
159
|
{
|
|
128
160
|
title: "Send email",
|
|
129
|
-
description:
|
|
161
|
+
description:
|
|
162
|
+
"Compose and send a new email from a mailbox where the current account has send access.",
|
|
130
163
|
inputSchema: composeInputSchema,
|
|
131
164
|
annotations: sendAnnotations,
|
|
132
165
|
},
|
|
133
|
-
(input) =>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
166
|
+
(input) =>
|
|
167
|
+
runTool(() =>
|
|
168
|
+
api.json("/mail/messages", {
|
|
169
|
+
method: "POST",
|
|
170
|
+
json: { ...input, requestId: requestId(input.requestId) },
|
|
171
|
+
})
|
|
172
|
+
)
|
|
137
173
|
);
|
|
138
174
|
|
|
139
|
-
|
|
175
|
+
tool(MAIL_SEND_SCOPE)(
|
|
140
176
|
"reply_to_email",
|
|
141
177
|
{
|
|
142
178
|
title: "Reply to email",
|
|
143
|
-
description:
|
|
179
|
+
description:
|
|
180
|
+
"Reply, reply all, continue a draft-like outgoing thread, or reply to a mailing list.",
|
|
144
181
|
inputSchema: z.object({
|
|
145
182
|
mailboxId: mailboxIdSchema,
|
|
146
183
|
sourceMessageId: entityIdSchema,
|
|
@@ -151,46 +188,60 @@ export function registerMailComposeTools(server: McpServer, api: AccountApiClien
|
|
|
151
188
|
}),
|
|
152
189
|
annotations: sendAnnotations,
|
|
153
190
|
},
|
|
154
|
-
({ sourceMessageId, ...input }) =>
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
191
|
+
({ sourceMessageId, ...input }) =>
|
|
192
|
+
runTool(() =>
|
|
193
|
+
api.json(
|
|
194
|
+
`/mail/messages/${encodeURIComponent(sourceMessageId)}/replies`,
|
|
195
|
+
{
|
|
196
|
+
method: "POST",
|
|
197
|
+
json: { ...input, requestId: requestId(input.requestId) },
|
|
198
|
+
}
|
|
199
|
+
)
|
|
200
|
+
)
|
|
161
201
|
);
|
|
162
202
|
|
|
163
|
-
|
|
203
|
+
tool(MAIL_SEND_SCOPE)(
|
|
164
204
|
"forward_email",
|
|
165
205
|
{
|
|
166
206
|
title: "Forward email",
|
|
167
|
-
description:
|
|
207
|
+
description:
|
|
208
|
+
"Forward a message, including its original attachments, to new recipients.",
|
|
168
209
|
inputSchema: forwardInputSchema,
|
|
169
210
|
annotations: sendAnnotations,
|
|
170
211
|
},
|
|
171
|
-
({ sourceMessageId, ...input }) =>
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
212
|
+
({ sourceMessageId, ...input }) =>
|
|
213
|
+
runTool(() =>
|
|
214
|
+
api.json(
|
|
215
|
+
`/mail/messages/${encodeURIComponent(sourceMessageId)}/forward`,
|
|
216
|
+
{
|
|
217
|
+
method: "POST",
|
|
218
|
+
json: { ...input, requestId: requestId(input.requestId) },
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
)
|
|
178
222
|
);
|
|
179
223
|
|
|
180
|
-
|
|
224
|
+
tool(MAIL_SEND_SCOPE)(
|
|
181
225
|
"send_email_again",
|
|
182
226
|
{
|
|
183
227
|
title: "Retry failed email",
|
|
184
|
-
description:
|
|
228
|
+
description:
|
|
229
|
+
"Retry an outgoing message whose delivery is failed or unconfirmed.",
|
|
185
230
|
inputSchema: z.object({
|
|
186
231
|
mailboxId: mailboxIdSchema,
|
|
187
232
|
messageId: entityIdSchema,
|
|
188
233
|
}),
|
|
189
234
|
annotations: sendAnnotations,
|
|
190
235
|
},
|
|
191
|
-
({ mailboxId, messageId }) =>
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
236
|
+
({ mailboxId, messageId }) =>
|
|
237
|
+
runTool(() =>
|
|
238
|
+
api.json(
|
|
239
|
+
apiPath(
|
|
240
|
+
`/mail/messages/${encodeURIComponent(messageId)}/send-again`,
|
|
241
|
+
{ mailboxId }
|
|
242
|
+
),
|
|
243
|
+
{ method: "POST" }
|
|
244
|
+
)
|
|
245
|
+
)
|
|
195
246
|
);
|
|
196
247
|
}
|