@mindstone/mcp-server-microsoft-mail 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/CHANGELOG.md +29 -0
- package/README.md +10 -2
- package/dist/resources/compose-email-template.d.ts +1 -1
- package/dist/resources/compose-email-template.js +245 -25
- package/package.json +1 -1
- package/server.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,35 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.4.0] - 2026-11-03
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Cards keep their send state in every copy and after a restart; a blocked send says why without a Retry that can't work.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Compose cards hide Retry when sending is blocked by your settings, your organization or security policy. Cancel stays available; a stopped server still offers Retry.
|
|
18
|
+
- Send requests declare the host-neutral `_meta: { 'mcp-app/cardOutcome': 'sent' }` outcome.
|
|
19
|
+
- Cancel after a draft-save timeout says "Nothing sent" unless an earlier send remains uncertain.
|
|
20
|
+
- Compose cards keep their sent status across copies and reloads in supporting hosts. Reloaded cards show the send time without the sent contents. The sender keeps its posted contents even if confirmation arrives after a lost reply; malformed host timestamps omit the date.
|
|
21
|
+
- After an unconfirmed send, the check-before-resending notice stays visible while editing and returns on Reopen. Cancel keeps the same reminder. Calls blocked before sending, including `not-dispatched` failures, still say "Nothing sent" unless an earlier attempt may have gone through.
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- The inline compose form (`compose_email`) gains a "Save draft" button
|
|
26
|
+
(between Cancel and Send) that saves the edited email to Outlook Drafts via
|
|
27
|
+
the existing `create_draft` tool instead of sending it. The saved-draft
|
|
28
|
+
confirmation is terminal (no Reopen) so the form can't silently diverge from
|
|
29
|
+
or duplicate the mailbox draft.
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- The compose form's wording no longer names a particular host app: the
|
|
34
|
+
lost-reply notices now start "No confirmation came back in time…" and the
|
|
35
|
+
unconfirmed-sender notice reads "Couldn't confirm which email account to
|
|
36
|
+
send from. Cancel, then ask your assistant to recreate this draft."
|
|
37
|
+
|
|
9
38
|
## [0.3.0] - 2026-08-06
|
|
10
39
|
|
|
11
40
|
### Changed
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Microsoft 365 Outlook Mail MCP server — list, search, read, send, reply, forwa
|
|
|
9
9
|
|
|
10
10
|
## Status
|
|
11
11
|
|
|
12
|
-
- **Version:** [0.
|
|
12
|
+
- **Version:** [0.4.0](./CHANGELOG.md) · [npm](https://www.npmjs.com/package/@mindstone/mcp-server-microsoft-mail)
|
|
13
13
|
- **Auth:** OAuth (host-orchestrated) ([`MS_CLIENT_ID`](./server.json))
|
|
14
14
|
- **Tools:** [22](./src/tools.ts) (messages, folders, drafts, attachments, threads, settings)
|
|
15
15
|
- **Surface:** cloud-api
|
|
@@ -179,7 +179,7 @@ Until the host has written `${MS_CONFIG_DIR}/credentials/<account>.token.json` a
|
|
|
179
179
|
| `list_attachments` | List attachment metadata (ID, name, type, size) for a message. |
|
|
180
180
|
| `download_attachment` | Save a file attachment into the workspace (or OS temp directory). |
|
|
181
181
|
| `send_email` | Send a new email message (supports CC and BCC). |
|
|
182
|
-
| `compose_email` | Open an editable draft in an interactive compose view; nothing is sent until the user clicks Send. |
|
|
182
|
+
| `compose_email` | Open an editable draft in an interactive compose view; nothing is sent until the user clicks Send, and Save draft stores it in Drafts instead. |
|
|
183
183
|
| `search_emails` | Search emails using Microsoft Search syntax. |
|
|
184
184
|
| `get_conversation` | List messages in a thread, oldest first (see ordering note below). |
|
|
185
185
|
| `reply_to_email` | Reply (or reply-all) to an existing email. |
|
|
@@ -196,6 +196,14 @@ Until the host has written `${MS_CONFIG_DIR}/credentials/<account>.token.json` a
|
|
|
196
196
|
| `get_automatic_replies` | Read the out-of-office configuration (requires `MailboxSettings.Read`). |
|
|
197
197
|
| `set_automatic_replies` | Turn out-of-office replies on/off or schedule them (requires `MailboxSettings.ReadWrite`). |
|
|
198
198
|
|
|
199
|
+
### Compose send status
|
|
200
|
+
|
|
201
|
+
In hosts that remember send status, sending an email closes its other compose copies. Reloaded cards show "Email sent" with the send time and hide Reopen because they do not have the sent contents. The copy used to send keeps its posted contents in a read-only sent view, including when confirmation follows a lost reply. After an error or block reply, a later sent status from another copy shows only the sent bar, without this copy's contents. While a send is in progress, other copies show “Sending…” with Send, Retry, Cancel and Save draft (where available) disabled. Replies to this copy’s own requests keep those controls locked until the other send ends. If the send ends without a confirmed outcome, those copies return to editing and keep any earlier uncertainty. A copy waiting for its own Send reply keeps its sending view. Sent views stay read-only, and uncertainty remains until a send is confirmed. After an error or missing confirmation, check whether the email was sent before using Retry; the notice stays visible while editing and returns on Reopen. Collapsing the card does not resolve that uncertainty. Policy-block explanations stay visible while editing with Send disabled. Cancel says "Nothing sent" only when no send may have gone through, including a `not-dispatched` failure before the request left the device.
|
|
202
|
+
|
|
203
|
+
When sending is blocked by your settings, your organization or security policy, the card hides Retry and keeps Cancel. If the server is stopped, Retry remains available.
|
|
204
|
+
|
|
205
|
+
Send requests declare `_meta: { 'mcp-app/cardOutcome': 'sent' }` to supporting hosts. Draft saves do not declare a send outcome; Cancel after a draft-save timeout says "Nothing sent" unless an earlier send remains uncertain.
|
|
206
|
+
|
|
199
207
|
### Graph permissions
|
|
200
208
|
|
|
201
209
|
Mail tools run on the `Mail.ReadWrite` + `Mail.Send` delegated grants. The automatic-replies tools additionally need `MailboxSettings.Read` / `MailboxSettings.ReadWrite`; in many organizations an administrator must approve that permission, and the tools return a guidance envelope (rather than a raw Graph 403) when the connected account lacks it.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const COMPOSE_EMAIL_HTML = "\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>Compose Email</title>\n <style>\n :root {\n --bg: #ffffff;\n --panel: #ffffff;\n --border: #d9dde5;\n --text: #1f2937;\n --muted: #6b7280;\n --input-bg: #ffffff;\n --button-bg: #1f6feb;\n --button-text: #ffffff;\n --button-bg-hover: #1b63d3;\n --secondary-bg: #f3f4f6;\n --secondary-text: #1f2937;\n --secondary-border: #d1d5db;\n --error-bg: #fef2f2;\n --error-border: #fecaca;\n --error-text: #991b1b;\n --success-bg: #ecfdf5;\n --success-border: #bbf7d0;\n --success-text: #166534;\n --warning-bg: #fffbeb;\n --warning-border: #fde68a;\n --warning-text: #92400e;\n }\n\n @media (prefers-color-scheme: dark) {\n :root {\n --bg: #0f172a;\n --panel: #111827;\n --border: #334155;\n --text: #e5e7eb;\n --muted: #9ca3af;\n --input-bg: #0b1220;\n --button-bg: #3b82f6;\n --button-text: #eff6ff;\n --button-bg-hover: #2563eb;\n --secondary-bg: #1f2937;\n --secondary-text: #e5e7eb;\n --secondary-border: #374151;\n --error-bg: #2b1011;\n --error-border: #7f1d1d;\n --error-text: #fca5a5;\n --success-bg: #052e1b;\n --success-border: #166534;\n --success-text: #86efac;\n --warning-bg: #2a2106;\n --warning-border: #854d0e;\n --warning-text: #fcd34d;\n }\n }\n\n html[data-theme=\"light\"] {\n color-scheme: light;\n }\n\n html[data-theme=\"dark\"] {\n color-scheme: dark;\n --bg: #0f172a;\n --panel: #111827;\n --border: #334155;\n --text: #e5e7eb;\n --muted: #9ca3af;\n --input-bg: #0b1220;\n --button-bg: #3b82f6;\n --button-text: #eff6ff;\n --button-bg-hover: #2563eb;\n --secondary-bg: #1f2937;\n --secondary-text: #e5e7eb;\n --secondary-border: #374151;\n --error-bg: #2b1011;\n --error-border: #7f1d1d;\n --error-text: #fca5a5;\n --success-bg: #052e1b;\n --success-border: #166534;\n --success-text: #86efac;\n --warning-bg: #2a2106;\n --warning-border: #854d0e;\n --warning-text: #fcd34d;\n }\n\n * {\n box-sizing: border-box;\n }\n\n body {\n margin: 0;\n padding: 16px;\n background: var(--bg);\n color: var(--text);\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n line-height: 1.4;\n }\n\n .wrapper {\n width: 100%;\n max-width: 720px;\n margin: 0 auto;\n }\n\n .card {\n background: var(--panel);\n border: 1px solid var(--border);\n border-radius: 12px;\n padding: 14px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n\n .field {\n display: flex;\n flex-direction: column;\n gap: 6px;\n }\n\n .field label {\n font-size: 12px;\n font-weight: 600;\n color: var(--muted);\n text-transform: uppercase;\n letter-spacing: 0.04em;\n }\n\n .from-value {\n color: var(--text);\n font-size: 14px;\n padding: 2px 0;\n word-break: break-word;\n }\n\n .from-helper {\n font-size: 12px;\n color: var(--muted);\n margin-top: 2px;\n }\n\n .input,\n .textarea {\n width: 100%;\n background: var(--input-bg);\n color: var(--text);\n border: 1px solid var(--border);\n border-radius: 8px;\n padding: 10px 12px;\n font-size: 14px;\n font-family: inherit;\n }\n\n .input:focus,\n .textarea:focus {\n outline: 2px solid rgba(59, 130, 246, 0.35);\n outline-offset: 1px;\n }\n\n .textarea {\n min-height: 180px;\n resize: vertical;\n white-space: pre-wrap;\n }\n\n .toggles {\n display: flex;\n gap: 12px;\n align-items: center;\n flex-wrap: wrap;\n }\n\n .link-button {\n border: none;\n padding: 0;\n background: none;\n color: var(--muted);\n text-decoration: underline;\n font-size: 12px;\n cursor: pointer;\n }\n\n .link-button:hover {\n color: var(--text);\n }\n\n .actions {\n display: flex;\n justify-content: flex-end;\n gap: 10px;\n margin-top: 2px;\n }\n\n .button {\n border-radius: 8px;\n border: 1px solid transparent;\n min-height: 36px;\n padding: 0 14px;\n font-size: 13px;\n font-weight: 600;\n font-family: inherit;\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n transition: background 120ms ease, opacity 120ms ease, border-color 120ms ease;\n }\n\n .button:disabled {\n cursor: not-allowed;\n opacity: 0.75;\n }\n\n .button-primary {\n background: var(--button-bg);\n color: var(--button-text);\n }\n\n .button-primary:hover:enabled {\n background: var(--button-bg-hover);\n }\n\n .button-secondary {\n background: var(--secondary-bg);\n color: var(--secondary-text);\n border-color: var(--secondary-border);\n }\n\n .spinner {\n width: 14px;\n height: 14px;\n border: 2px solid currentColor;\n border-right-color: transparent;\n border-radius: 50%;\n display: inline-block;\n animation: spin 700ms linear infinite;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n .status {\n border-radius: 8px;\n border: 1px solid transparent;\n padding: 8px 10px;\n font-size: 13px;\n }\n\n .error {\n background: var(--error-bg);\n border-color: var(--error-border);\n color: var(--error-text);\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: 8px;\n flex-wrap: wrap;\n }\n\n .success {\n background: var(--success-bg);\n border-color: var(--success-border);\n color: var(--success-text);\n }\n\n .warning {\n background: var(--warning-bg);\n border-color: var(--warning-border);\n color: var(--warning-text);\n display: block;\n }\n\n .warning strong {\n display: block;\n margin-bottom: 2px;\n }\n\n .warning .warning-detail {\n opacity: 0.85;\n }\n\n .collapsed {\n border: 1px solid var(--border);\n border-radius: 10px;\n background: var(--panel);\n padding: 10px 12px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: 8px;\n font-size: 13px;\n }\n\n .hidden {\n display: none !important;\n }\n\n .sent-header {\n display: flex;\n align-items: center;\n gap: 8px;\n flex-wrap: wrap;\n }\n\n .sent-badge {\n display: inline-flex;\n align-items: center;\n background: var(--success-bg);\n color: var(--success-text);\n border: 1px solid var(--success-border);\n border-radius: 999px;\n padding: 2px 10px;\n font-size: 12px;\n font-weight: 600;\n }\n\n .sent-timestamp {\n color: var(--muted);\n font-size: 12px;\n }\n\n .sent-value {\n color: var(--text);\n font-size: 14px;\n word-break: break-word;\n }\n\n .sent-body {\n color: var(--text);\n font-size: 14px;\n white-space: pre-wrap;\n word-break: break-word;\n max-height: 260px;\n overflow: auto;\n border: 1px solid var(--border);\n border-radius: 8px;\n padding: 10px 12px;\n background: var(--input-bg);\n }\n </style>\n</head>\n<body>\n <div class=\"wrapper\">\n <div id=\"collapsedState\" class=\"collapsed hidden\">\n <span id=\"collapsedMessage\">Draft collapsed.</span>\n <button id=\"reopenButton\" type=\"button\" class=\"button button-secondary\">Reopen</button>\n </div>\n\n <form id=\"composeForm\" class=\"card\" novalidate aria-label=\"Compose email\">\n <div class=\"field from-field\">\n <label>From</label>\n <span id=\"fromValue\" class=\"from-value\"></span>\n <span id=\"fromHelper\" class=\"from-helper hidden\"></span>\n </div>\n\n <div class=\"field\">\n <label for=\"toInput\">To</label>\n <input id=\"toInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"name@example.com, team@example.com\">\n </div>\n\n <div class=\"toggles\">\n <button id=\"toggleCcButton\" type=\"button\" class=\"link-button\" aria-expanded=\"false\" aria-controls=\"ccRow\">Add CC</button>\n <button id=\"toggleBccButton\" type=\"button\" class=\"link-button\" aria-expanded=\"false\" aria-controls=\"bccRow\">Add BCC</button>\n </div>\n\n <div id=\"ccRow\" class=\"field hidden\">\n <label for=\"ccInput\">CC</label>\n <input id=\"ccInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"cc@example.com\">\n </div>\n\n <div id=\"bccRow\" class=\"field hidden\">\n <label for=\"bccInput\">BCC</label>\n <input id=\"bccInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"bcc@example.com\">\n </div>\n\n <div class=\"field\">\n <label for=\"subjectInput\">Subject</label>\n <input id=\"subjectInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"Email subject\">\n </div>\n\n <div class=\"field\">\n <label for=\"bodyInput\">Body</label>\n <textarea id=\"bodyInput\" class=\"textarea\" placeholder=\"Write your email\"></textarea>\n </div>\n\n <div id=\"errorBox\" class=\"status error hidden\" role=\"alert\">\n <span id=\"errorText\"></span>\n <button id=\"retryButton\" type=\"button\" class=\"link-button\">Retry</button>\n </div>\n\n <div id=\"successBox\" class=\"status success hidden\" role=\"status\" aria-live=\"polite\"></div>\n\n <div id=\"unknownBox\" class=\"status warning hidden\" role=\"status\" aria-live=\"polite\">\n <strong id=\"unknownTitle\"></strong>\n <span id=\"unknownText\" class=\"warning-detail\"></span>\n </div>\n\n <div class=\"actions\">\n <button id=\"cancelButton\" type=\"button\" class=\"button button-secondary\">Cancel</button>\n <button id=\"sendButton\" type=\"button\" class=\"button button-primary\">\n <span id=\"sendSpinner\" class=\"spinner hidden\" aria-hidden=\"true\"></span>\n <span id=\"sendLabel\">Send email</span>\n </button>\n </div>\n </form>\n\n <div id=\"sentView\" class=\"card hidden\" role=\"status\" aria-live=\"polite\">\n <div class=\"sent-header\">\n <span class=\"sent-badge\">Sent</span>\n <span id=\"sentTimestamp\" class=\"sent-timestamp\"></span>\n </div>\n\n <div class=\"field\">\n <label>From</label>\n <span id=\"sentFrom\" class=\"sent-value\"></span>\n </div>\n\n <div class=\"field\">\n <label>To</label>\n <span id=\"sentTo\" class=\"sent-value\"></span>\n </div>\n\n <div id=\"sentCcField\" class=\"field hidden\">\n <label>CC</label>\n <span id=\"sentCc\" class=\"sent-value\"></span>\n </div>\n\n <div id=\"sentBccField\" class=\"field hidden\">\n <label>BCC</label>\n <span id=\"sentBcc\" class=\"sent-value\"></span>\n </div>\n\n <div class=\"field\">\n <label>Subject</label>\n <span id=\"sentSubject\" class=\"sent-value\"></span>\n </div>\n\n <div class=\"field\">\n <label>Message</label>\n <div id=\"sentBody\" class=\"sent-body\"></div>\n </div>\n\n <div class=\"actions\">\n <button id=\"sentCollapseButton\" type=\"button\" class=\"button button-secondary\">Collapse</button>\n </div>\n </div>\n </div>\n\n <script>\n (function () {\n 'use strict';\n\n var RESOURCE_URI = 'ui://microsoft-mail/compose-email';\n var currentEmail = '';\n // The host prefills the draft exactly once via ui/notifications/tool-result\n // on ready. We apply only the FIRST prefill and ignore any later ones, so a\n // stray or hostile re-post can't silently rewrite a draft the user has\n // already reviewed before clicking Send.\n var draftApplied = false;\n var pendingRequestId = null;\n var pendingPayload = null;\n var sending = false;\n var collapsed = false;\n var outcomeUnknown = false;\n var sent = false;\n var sendTimeoutId = null;\n // Just beyond the host-side tool-call timeout (60s) so a legitimately slow\n // send resolves to its real result first; this only fires when the reply\n // is genuinely lost, so the button can never stay stuck-silent.\n var SEND_TIMEOUT_MS = 75000;\n\n var composeForm = document.getElementById('composeForm');\n var collapsedState = document.getElementById('collapsedState');\n var collapsedMessage = document.getElementById('collapsedMessage');\n var reopenButton = document.getElementById('reopenButton');\n\n var sentView = document.getElementById('sentView');\n var sentTimestamp = document.getElementById('sentTimestamp');\n var sentFrom = document.getElementById('sentFrom');\n var sentTo = document.getElementById('sentTo');\n var sentCcField = document.getElementById('sentCcField');\n var sentCc = document.getElementById('sentCc');\n var sentBccField = document.getElementById('sentBccField');\n var sentBcc = document.getElementById('sentBcc');\n var sentSubject = document.getElementById('sentSubject');\n var sentBody = document.getElementById('sentBody');\n var sentCollapseButton = document.getElementById('sentCollapseButton');\n\n var toInput = document.getElementById('toInput');\n var ccInput = document.getElementById('ccInput');\n var bccInput = document.getElementById('bccInput');\n var subjectInput = document.getElementById('subjectInput');\n var bodyInput = document.getElementById('bodyInput');\n var fromValue = document.getElementById('fromValue');\n var fromHelper = document.getElementById('fromHelper');\n var ccRow = document.getElementById('ccRow');\n var bccRow = document.getElementById('bccRow');\n var toggleCcButton = document.getElementById('toggleCcButton');\n var toggleBccButton = document.getElementById('toggleBccButton');\n\n var sendButton = document.getElementById('sendButton');\n var sendLabel = document.getElementById('sendLabel');\n var sendSpinner = document.getElementById('sendSpinner');\n var cancelButton = document.getElementById('cancelButton');\n var retryButton = document.getElementById('retryButton');\n\n var errorBox = document.getElementById('errorBox');\n var errorText = document.getElementById('errorText');\n var successBox = document.getElementById('successBox');\n var unknownBox = document.getElementById('unknownBox');\n var unknownTitle = document.getElementById('unknownTitle');\n var unknownText = document.getElementById('unknownText');\n\n function applyThemeFromHostContext() {\n try {\n var context = window.__MCP_HOST_CONTEXT__;\n if (!context || (context.theme !== 'light' && context.theme !== 'dark')) {\n return;\n }\n document.documentElement.setAttribute('data-theme', context.theme);\n } catch (_) {\n // Ignore theme extraction errors\n }\n }\n\n function trimString(value) {\n return String(value || '').trim();\n }\n\n function applyFromValue(email) {\n var trimmed = trimString(email);\n if (trimmed) {\n fromValue.textContent = trimmed;\n fromValue.style.color = '';\n fromHelper.textContent = '';\n fromHelper.classList.add('hidden');\n } else {\n fromValue.textContent = 'Account not shown';\n fromValue.style.color = 'var(--muted)';\n fromHelper.textContent = 'Rebel could not confirm the sending account. Cancel and ask Rebel to recreate the draft before sending.';\n fromHelper.classList.remove('hidden');\n }\n }\n\n function formatAddressItem(item) {\n if (item && typeof item === 'object') {\n var email = trimString(item.email || item.address || item.value);\n var name = trimString(item.name || item.displayName);\n if (email && name) {\n return name + ' <' + email + '>';\n }\n return email;\n }\n return trimString(item);\n }\n\n function normalizeAddressList(value) {\n if (Array.isArray(value)) {\n return value.map(formatAddressItem).filter(Boolean);\n }\n if (typeof value === 'string') {\n return value\n .split(',')\n .map(function (item) { return trimString(item); })\n .filter(Boolean);\n }\n return [];\n }\n\n function listToInputValue(list) {\n return normalizeAddressList(list).join(', ');\n }\n\n var resizeQueued = false;\n function postResize() {\n if (resizeQueued) return;\n resizeQueued = true;\n requestAnimationFrame(function () {\n resizeQueued = false;\n var height = Math.max(\n document.documentElement.scrollHeight,\n document.body ? document.body.scrollHeight : 0\n );\n window.parent.postMessage(\n { jsonrpc: '2.0', method: 'ui/resize', params: { height: height } },\n '*'\n );\n });\n }\n\n function postReady() {\n window.parent.postMessage(\n {\n method: 'mcp-app:ready',\n params: { resourceUri: RESOURCE_URI }\n },\n '*'\n );\n }\n\n // Exactly one of the three panels is visible at a time: the editable form,\n // the read-only sent view, or the collapsed summary bar.\n function showView(view) {\n composeForm.classList.toggle('hidden', view !== 'form');\n sentView.classList.toggle('hidden', view !== 'sent');\n collapsedState.classList.toggle('hidden', view !== 'collapsed');\n postResize();\n }\n\n function setCollapsed(nextCollapsed, message) {\n collapsed = nextCollapsed;\n if (nextCollapsed) {\n collapsedMessage.textContent = message || 'Draft collapsed.';\n showView('collapsed');\n } else {\n // Expanding after a send restores the read-only sent view (never the\n // editable form) so the user can re-read what went out without any risk\n // of a duplicate send; before sending, it restores the editable form.\n showView(sent ? 'sent' : 'form');\n }\n }\n\n function setSending(nextSending) {\n sending = nextSending;\n sendButton.disabled = nextSending;\n cancelButton.disabled = nextSending;\n toInput.disabled = nextSending;\n ccInput.disabled = nextSending;\n bccInput.disabled = nextSending;\n subjectInput.disabled = nextSending;\n bodyInput.disabled = nextSending;\n sendSpinner.classList.toggle('hidden', !nextSending);\n sendLabel.textContent = nextSending ? 'Sending\u2026' : 'Send email';\n sendButton.setAttribute('aria-busy', nextSending ? 'true' : 'false');\n postResize();\n }\n\n function clearError() {\n errorText.textContent = '';\n errorBox.classList.add('hidden');\n }\n\n function showError(message) {\n errorText.textContent = message || 'Failed to send email.';\n errorBox.classList.remove('hidden');\n postResize();\n }\n\n function clearSuccess() {\n successBox.textContent = '';\n successBox.classList.add('hidden');\n }\n\n function showSuccess(message) {\n successBox.textContent = message;\n successBox.classList.remove('hidden');\n postResize();\n }\n\n function clearSendTimeout() {\n if (sendTimeoutId !== null) {\n clearTimeout(sendTimeoutId);\n sendTimeoutId = null;\n }\n }\n\n function clearUnknown() {\n outcomeUnknown = false;\n unknownTitle.textContent = '';\n unknownText.textContent = '';\n unknownBox.classList.add('hidden');\n }\n\n // No reply ever came back for the send (e.g. the host's response was lost\n // before reaching this iframe). We genuinely don't know whether the email\n // went out, so we must NOT claim success or failure: re-enable the form and\n // tell the user to verify before resending (the send is not idempotent, so\n // a blind retry could send a duplicate).\n function showSendUnknown() {\n outcomeUnknown = true;\n clearError();\n clearSuccess();\n unknownTitle.textContent = 'Not sure if this sent.';\n unknownText.textContent = \"Rebel didn't hear back in time. Check your Sent folder before sending again, so it doesn't go out twice.\";\n unknownBox.classList.remove('hidden');\n postResize();\n }\n\n function handleSendTimeout() {\n sendTimeoutId = null;\n if (!pendingRequestId) {\n return;\n }\n pendingRequestId = null;\n setSending(false);\n showSendUnknown();\n }\n\n function setCcVisible(visible) {\n ccRow.classList.toggle('hidden', !visible);\n toggleCcButton.textContent = visible ? 'Hide CC' : 'Add CC';\n toggleCcButton.setAttribute('aria-expanded', visible ? 'true' : 'false');\n }\n\n function setBccVisible(visible) {\n bccRow.classList.toggle('hidden', !visible);\n toggleBccButton.textContent = visible ? 'Hide BCC' : 'Add BCC';\n toggleBccButton.setAttribute('aria-expanded', visible ? 'true' : 'false');\n }\n\n function readFormPayload() {\n var payload = {\n to: normalizeAddressList(toInput.value),\n cc: normalizeAddressList(ccInput.value),\n bcc: normalizeAddressList(bccInput.value),\n subject: String(subjectInput.value || ''),\n body: String(bodyInput.value || '')\n };\n if (currentEmail) {\n payload.email = currentEmail;\n }\n return payload;\n }\n\n function validatePayload(payload) {\n if (!payload.to || payload.to.length === 0) {\n return 'Add at least one recipient in To.';\n }\n if (!trimString(payload.subject)) {\n return 'Add a subject before sending.';\n }\n if (!trimString(payload.body)) {\n return 'Add an email body before sending.';\n }\n return null;\n }\n\n function sendPayload(payload) {\n pendingPayload = payload;\n pendingRequestId = 'send-' + Date.now() + '-' + Math.random().toString(16).slice(2);\n setSending(true);\n clearError();\n clearSuccess();\n clearUnknown();\n clearSendTimeout();\n sendTimeoutId = setTimeout(handleSendTimeout, SEND_TIMEOUT_MS);\n\n window.parent.postMessage(\n {\n jsonrpc: '2.0',\n method: 'tools/call',\n params: {\n name: 'send_email',\n arguments: payload\n },\n id: pendingRequestId\n },\n '*'\n );\n }\n\n function applyDraftData(rawDraft) {\n var draft = rawDraft && typeof rawDraft === 'object' ? rawDraft : {};\n toInput.value = listToInputValue(draft.to);\n ccInput.value = listToInputValue(draft.cc);\n bccInput.value = listToInputValue(draft.bcc);\n subjectInput.value = typeof draft.subject === 'string' ? draft.subject : '';\n bodyInput.value = typeof draft.body === 'string' ? draft.body : '';\n currentEmail = typeof draft.email === 'string' ? draft.email : '';\n applyFromValue(currentEmail);\n setCcVisible(normalizeAddressList(draft.cc).length > 0);\n setBccVisible(normalizeAddressList(draft.bcc).length > 0);\n clearError();\n clearSuccess();\n postResize();\n }\n\n function getDraftFromToolResult(payload) {\n if (!payload || typeof payload !== 'object') {\n return null;\n }\n // CANONICAL: post-A0 super-mcp hoists structuredContent onto the\n // outer block; the host posts it through `params.structuredContent`.\n if (payload.structuredContent && typeof payload.structuredContent === 'object') {\n return payload.structuredContent;\n }\n // MIGRATION SHIM: pre-A0 stored sessions replayed through the\n // current iframe lack `params.structuredContent` because the outer\n // block had no hoist at capture time. Read inner envelope text \u2192\n // JSON.parse \u2192 result.structuredContent. NOT regex-based.\n //\n // Lifetime: PERMANENT defensive read-side helper. Pre-A0 sessions\n // are persisted on disk and may be replayed indefinitely; there is\n // no time-based sunset. Removing this fallback would silently break\n // pre-A0 conversation replay.\n var text = typeof payload.text === 'string' ? payload.text :\n (Array.isArray(payload.content)\n ? (payload.content.find(function (c) { return c && c.type === 'text' && typeof c.text === 'string'; }) || {}).text\n : null);\n if (typeof text !== 'string') return null;\n try {\n var parsed = JSON.parse(text);\n if (parsed && typeof parsed === 'object' && parsed.result && typeof parsed.result === 'object') {\n var inner = parsed.result;\n if (inner.structuredContent && typeof inner.structuredContent === 'object') {\n return inner.structuredContent;\n }\n }\n } catch (_) {\n // Likely-envelope heuristic: text starts with `{` and contains\n // `\"package_id\"` in the first 64 chars. If JSON.parse failed on a\n // likely-envelope, surface a warning so the developer chasing\n // \"compose form is empty on replay\" sees a signal. For non-envelope\n // text (the dominant case), no log fires.\n var prefix = text.length > 64 ? text.slice(0, 64) : text;\n var likelyEnvelope = prefix.charAt(0) === '{' && prefix.indexOf('\"package_id\"') !== -1;\n if (likelyEnvelope && typeof console !== 'undefined' && typeof console.warn === 'function') {\n console.warn('[compose-email] Migration shim: JSON.parse failed on likely super-mcp envelope; pre-fill skipped');\n }\n }\n return null;\n }\n\n function findTextBlock(blocks) {\n if (!Array.isArray(blocks)) return null;\n var block = blocks.find(function (c) {\n return c && c.type === 'text' && typeof c.text === 'string';\n });\n return block ? block.text : null;\n }\n\n // Extract the send result identifiers ({ messageId, threadId, labelIds })\n // from the tool-call reply. The connector attaches structuredContent, which\n // super-mcp hoists onto the outer block, so the fast path is a single read.\n // The envelope-unwrapping fallback keeps this robust for hosts (or replayed\n // sessions) that forward only the serialized super-mcp text envelope.\n function getSendMetaFromResult(result) {\n if (!result || typeof result !== 'object') return null;\n if (result.structuredContent && typeof result.structuredContent === 'object') {\n return result.structuredContent;\n }\n try {\n var outerText = findTextBlock(result.content);\n if (typeof outerText !== 'string' && typeof result.text === 'string') {\n outerText = result.text;\n }\n if (typeof outerText !== 'string') return null;\n var envelope = JSON.parse(outerText);\n if (!envelope || typeof envelope !== 'object') return null;\n // outerText was the connector payload directly (no super-mcp envelope).\n if (envelope.messageId || envelope.threadId) return envelope;\n var inner = envelope.result;\n if (!inner || typeof inner !== 'object') return null;\n if (inner.structuredContent && typeof inner.structuredContent === 'object') {\n return inner.structuredContent;\n }\n var innerText = findTextBlock(inner.content);\n if (typeof innerText !== 'string') return null;\n var payload = JSON.parse(innerText);\n return (payload && typeof payload === 'object') ? payload : null;\n } catch (_) {\n return null;\n }\n }\n\n function formatSentTime() {\n try {\n return new Date().toLocaleString(undefined, {\n month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit'\n });\n } catch (_) {\n return '';\n }\n }\n\n function renderSentView(payload, meta, stamp) {\n payload = payload && typeof payload === 'object' ? payload : {};\n sentTimestamp.textContent = stamp ? 'Sent ' + stamp : 'Sent';\n sentFrom.textContent = trimString(payload.email) || 'Account not shown';\n sentTo.textContent = normalizeAddressList(payload.to).join(', ');\n var ccList = normalizeAddressList(payload.cc);\n sentCc.textContent = ccList.join(', ');\n sentCcField.classList.toggle('hidden', ccList.length === 0);\n var bccList = normalizeAddressList(payload.bcc);\n sentBcc.textContent = bccList.join(', ');\n sentBccField.classList.toggle('hidden', bccList.length === 0);\n sentSubject.textContent = String(payload.subject || '');\n sentBody.textContent = String(payload.body || '');\n }\n\n function handleSendRequest() {\n if (sending) return;\n\n var payload = readFormPayload();\n var validationError = validatePayload(payload);\n if (validationError) {\n showError(validationError);\n return;\n }\n\n sendPayload(payload);\n }\n\n // The Send button is type=\"button\" with an explicit click handler rather\n // than a form submit button. The Rebel host renders this iframe with a\n // sandbox of \"allow-scripts\" only \u2014 no \"allow-forms\" \u2014 so native form\n // submission is blocked by the browser BEFORE the submit event fires\n // (\"Blocked form submission ... the form's frame is sandboxed and the\n // allow-forms permission is not set\"). A submit-driven Send therefore\n // silently did nothing: no postMessage, no spinner, no telemetry.\n // A click handler needs no sandbox permission and is the same path\n // Cancel/Retry already use. The submit listener below stays only as a\n // defensive fallback for hosts that DO grant allow-forms; in this sandbox\n // it never fires (neither the button click nor Enter routes through it).\n // The sending guard keeps any double-fire (in an allow-forms host) a no-op.\n sendButton.addEventListener('click', function () {\n handleSendRequest();\n });\n\n composeForm.addEventListener('submit', function (event) {\n event.preventDefault();\n handleSendRequest();\n });\n\n retryButton.addEventListener('click', function () {\n if (sending) return;\n var payload = readFormPayload();\n var validationError = validatePayload(payload);\n if (validationError) {\n showError(validationError);\n return;\n }\n sendPayload(payload);\n });\n\n cancelButton.addEventListener('click', function () {\n if (sending) return;\n // After a lost-reply timeout we don't know if the email sent, so don't\n // claim \"Nothing sent.\" on collapse \u2014 point the user to verify instead.\n var collapseMessage = outcomeUnknown\n ? 'Collapsed. Check your Sent folder if you are not sure.'\n : 'Draft collapsed. Nothing sent.';\n clearError();\n clearSuccess();\n clearUnknown();\n setCollapsed(true, collapseMessage);\n });\n\n reopenButton.addEventListener('click', function () {\n setCollapsed(false);\n });\n\n sentCollapseButton.addEventListener('click', function () {\n setCollapsed(true, collapsedMessage.textContent || 'Email sent.');\n });\n\n toggleCcButton.addEventListener('click', function () {\n setCcVisible(ccRow.classList.contains('hidden'));\n postResize();\n });\n\n toggleBccButton.addEventListener('click', function () {\n setBccVisible(bccRow.classList.contains('hidden'));\n postResize();\n });\n\n [toInput, ccInput, bccInput, subjectInput, bodyInput].forEach(function (element) {\n element.addEventListener('input', function () {\n clearError();\n clearSuccess();\n clearUnknown();\n postResize();\n });\n });\n\n window.addEventListener('message', function (event) {\n // Honest scope (origin-independent): the iframe sandbox origin is 'null',\n // so validating event.origin is unreliable across dev/prod/custom-scheme\n // hosts. Instead reject any *identified* sender that isn't our host frame\n // (window.parent). A real cross-frame postMessage always stamps\n // event.source with the sending window, so a hostile sibling frame is\n // rejected here; a null source only occurs for same-context synthetic\n // dispatch (our own code) and cannot be forged from outside, so we\n // tolerate it. This does not authenticate the host's identity \u2014 the host\n // separately authenticates this iframe by origin+source.\n if (event.source && event.source !== window.parent) {\n return;\n }\n\n var data = event.data;\n if (!data || typeof data !== 'object') {\n return;\n }\n\n if (data.method === 'ui/notifications/tool-result') {\n // Always parse (so the migration-shim's malformed-envelope warning\n // still fires), but apply only the first successful prefill: a stray\n // or hostile re-post can't silently rewrite a draft the user has\n // already reviewed.\n var draft = getDraftFromToolResult(data.params);\n if (draft && !draftApplied) {\n draftApplied = true;\n applyDraftData(draft);\n }\n return;\n }\n\n if (data.jsonrpc !== '2.0' || !pendingRequestId || data.id !== pendingRequestId) {\n return;\n }\n\n pendingRequestId = null;\n clearSendTimeout();\n clearUnknown();\n setSending(false);\n\n if (data.error) {\n var errorMessage = data.error && typeof data.error.message === 'string'\n ? data.error.message\n : 'Failed to send email.';\n showError(errorMessage);\n return;\n }\n\n clearError();\n clearSuccess();\n // Preserve what was sent instead of discarding the draft. pendingPayload\n // is the exact payload we posted. We default to the collapsed summary, but\n // Reopen now restores a read-only view of the sent message.\n var sentPayload = pendingPayload || readFormPayload();\n var stamp = formatSentTime();\n renderSentView(sentPayload, getSendMetaFromResult(data.result), stamp);\n sent = true;\n setCollapsed(true, stamp ? 'Email sent \u00B7 ' + stamp : 'Email sent.');\n });\n\n if (typeof ResizeObserver === 'function' && document.body) {\n var observer = new ResizeObserver(postResize);\n observer.observe(document.body);\n }\n\n applyThemeFromHostContext();\n setCcVisible(false);\n setBccVisible(false);\n setCollapsed(false);\n postResize();\n postReady();\n\n window.parent.postMessage(\n {\n jsonrpc: '2.0',\n method: 'ui/initialize',\n params: { resourceUri: RESOURCE_URI },\n id: 'compose-email-init'\n },\n '*'\n );\n })();\n </script>\n</body>\n</html>\n";
|
|
1
|
+
export declare const COMPOSE_EMAIL_HTML = "\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>Compose Email</title>\n <style>\n :root {\n --bg: #ffffff;\n --panel: #ffffff;\n --border: #d9dde5;\n --text: #1f2937;\n --muted: #6b7280;\n --input-bg: #ffffff;\n --button-bg: #1f6feb;\n --button-text: #ffffff;\n --button-bg-hover: #1b63d3;\n --secondary-bg: #f3f4f6;\n --secondary-text: #1f2937;\n --secondary-border: #d1d5db;\n --error-bg: #fef2f2;\n --error-border: #fecaca;\n --error-text: #991b1b;\n --success-bg: #ecfdf5;\n --success-border: #bbf7d0;\n --success-text: #166534;\n --warning-bg: #fffbeb;\n --warning-border: #fde68a;\n --warning-text: #92400e;\n }\n\n @media (prefers-color-scheme: dark) {\n :root {\n --bg: #0f172a;\n --panel: #111827;\n --border: #334155;\n --text: #e5e7eb;\n --muted: #9ca3af;\n --input-bg: #0b1220;\n --button-bg: #3b82f6;\n --button-text: #eff6ff;\n --button-bg-hover: #2563eb;\n --secondary-bg: #1f2937;\n --secondary-text: #e5e7eb;\n --secondary-border: #374151;\n --error-bg: #2b1011;\n --error-border: #7f1d1d;\n --error-text: #fca5a5;\n --success-bg: #052e1b;\n --success-border: #166534;\n --success-text: #86efac;\n --warning-bg: #2a2106;\n --warning-border: #854d0e;\n --warning-text: #fcd34d;\n }\n }\n\n html[data-theme=\"light\"] {\n color-scheme: light;\n }\n\n html[data-theme=\"dark\"] {\n color-scheme: dark;\n --bg: #0f172a;\n --panel: #111827;\n --border: #334155;\n --text: #e5e7eb;\n --muted: #9ca3af;\n --input-bg: #0b1220;\n --button-bg: #3b82f6;\n --button-text: #eff6ff;\n --button-bg-hover: #2563eb;\n --secondary-bg: #1f2937;\n --secondary-text: #e5e7eb;\n --secondary-border: #374151;\n --error-bg: #2b1011;\n --error-border: #7f1d1d;\n --error-text: #fca5a5;\n --success-bg: #052e1b;\n --success-border: #166534;\n --success-text: #86efac;\n --warning-bg: #2a2106;\n --warning-border: #854d0e;\n --warning-text: #fcd34d;\n }\n\n * {\n box-sizing: border-box;\n }\n\n body {\n margin: 0;\n padding: 16px;\n background: var(--bg);\n color: var(--text);\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n line-height: 1.4;\n }\n\n .wrapper {\n width: 100%;\n max-width: 720px;\n margin: 0 auto;\n }\n\n .card {\n background: var(--panel);\n border: 1px solid var(--border);\n border-radius: 12px;\n padding: 14px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n\n .field {\n display: flex;\n flex-direction: column;\n gap: 6px;\n }\n\n .field label {\n font-size: 12px;\n font-weight: 600;\n color: var(--muted);\n text-transform: uppercase;\n letter-spacing: 0.04em;\n }\n\n .from-value {\n color: var(--text);\n font-size: 14px;\n padding: 2px 0;\n word-break: break-word;\n }\n\n .from-helper {\n font-size: 12px;\n color: var(--muted);\n margin-top: 2px;\n }\n\n .input,\n .textarea {\n width: 100%;\n background: var(--input-bg);\n color: var(--text);\n border: 1px solid var(--border);\n border-radius: 8px;\n padding: 10px 12px;\n font-size: 14px;\n font-family: inherit;\n }\n\n .input:focus,\n .textarea:focus {\n outline: 2px solid rgba(59, 130, 246, 0.35);\n outline-offset: 1px;\n }\n\n .textarea {\n min-height: 180px;\n resize: vertical;\n white-space: pre-wrap;\n }\n\n .toggles {\n display: flex;\n gap: 12px;\n align-items: center;\n flex-wrap: wrap;\n }\n\n .link-button {\n border: none;\n padding: 0;\n background: none;\n color: var(--muted);\n text-decoration: underline;\n font-size: 12px;\n cursor: pointer;\n }\n\n .link-button:hover {\n color: var(--text);\n }\n\n .actions {\n display: flex;\n justify-content: flex-end;\n gap: 10px;\n margin-top: 2px;\n flex-wrap: wrap;\n }\n\n .button {\n border-radius: 8px;\n border: 1px solid transparent;\n min-height: 36px;\n padding: 0 14px;\n font-size: 13px;\n font-weight: 600;\n font-family: inherit;\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n transition: background 120ms ease, opacity 120ms ease, border-color 120ms ease;\n }\n\n .button:disabled {\n cursor: not-allowed;\n opacity: 0.75;\n }\n\n .button-primary {\n background: var(--button-bg);\n color: var(--button-text);\n }\n\n .button-primary:hover:enabled {\n background: var(--button-bg-hover);\n }\n\n .button-secondary {\n background: var(--secondary-bg);\n color: var(--secondary-text);\n border-color: var(--secondary-border);\n }\n\n .spinner {\n width: 14px;\n height: 14px;\n border: 2px solid currentColor;\n border-right-color: transparent;\n border-radius: 50%;\n display: inline-block;\n animation: spin 700ms linear infinite;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n .status {\n border-radius: 8px;\n border: 1px solid transparent;\n padding: 8px 10px;\n font-size: 13px;\n }\n\n .error {\n background: var(--error-bg);\n border-color: var(--error-border);\n color: var(--error-text);\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: 8px;\n flex-wrap: wrap;\n }\n\n .success {\n background: var(--success-bg);\n border-color: var(--success-border);\n color: var(--success-text);\n }\n\n .warning {\n background: var(--warning-bg);\n border-color: var(--warning-border);\n color: var(--warning-text);\n display: block;\n }\n\n .warning strong {\n display: block;\n margin-bottom: 2px;\n }\n\n .warning .warning-detail {\n opacity: 0.85;\n }\n\n .collapsed {\n border: 1px solid var(--border);\n border-radius: 10px;\n background: var(--panel);\n padding: 10px 12px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: 8px;\n font-size: 13px;\n }\n\n .hidden {\n display: none !important;\n }\n\n .sent-header {\n display: flex;\n align-items: center;\n gap: 8px;\n flex-wrap: wrap;\n }\n\n .sent-badge {\n display: inline-flex;\n align-items: center;\n background: var(--success-bg);\n color: var(--success-text);\n border: 1px solid var(--success-border);\n border-radius: 999px;\n padding: 2px 10px;\n font-size: 12px;\n font-weight: 600;\n }\n\n .sent-timestamp {\n color: var(--muted);\n font-size: 12px;\n }\n\n .sent-value {\n color: var(--text);\n font-size: 14px;\n word-break: break-word;\n }\n\n .sent-body {\n color: var(--text);\n font-size: 14px;\n white-space: pre-wrap;\n word-break: break-word;\n max-height: 260px;\n overflow: auto;\n border: 1px solid var(--border);\n border-radius: 8px;\n padding: 10px 12px;\n background: var(--input-bg);\n }\n </style>\n</head>\n<body>\n <div class=\"wrapper\">\n <div id=\"collapsedState\" class=\"collapsed hidden\">\n <span id=\"collapsedMessage\">Draft collapsed.</span>\n <button id=\"reopenButton\" type=\"button\" class=\"button button-secondary\">Reopen</button>\n </div>\n\n <form id=\"composeForm\" class=\"card\" novalidate aria-label=\"Compose email\">\n <div class=\"field from-field\">\n <label>From</label>\n <span id=\"fromValue\" class=\"from-value\"></span>\n <span id=\"fromHelper\" class=\"from-helper hidden\"></span>\n </div>\n\n <div class=\"field\">\n <label for=\"toInput\">To</label>\n <input id=\"toInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"name@example.com, team@example.com\">\n </div>\n\n <div class=\"toggles\">\n <button id=\"toggleCcButton\" type=\"button\" class=\"link-button\" aria-expanded=\"false\" aria-controls=\"ccRow\">Add CC</button>\n <button id=\"toggleBccButton\" type=\"button\" class=\"link-button\" aria-expanded=\"false\" aria-controls=\"bccRow\">Add BCC</button>\n </div>\n\n <div id=\"ccRow\" class=\"field hidden\">\n <label for=\"ccInput\">CC</label>\n <input id=\"ccInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"cc@example.com\">\n </div>\n\n <div id=\"bccRow\" class=\"field hidden\">\n <label for=\"bccInput\">BCC</label>\n <input id=\"bccInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"bcc@example.com\">\n </div>\n\n <div class=\"field\">\n <label for=\"subjectInput\">Subject</label>\n <input id=\"subjectInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"Email subject\">\n </div>\n\n <div class=\"field\">\n <label for=\"bodyInput\">Body</label>\n <textarea id=\"bodyInput\" class=\"textarea\" placeholder=\"Write your email\"></textarea>\n </div>\n\n <div id=\"errorBox\" class=\"status error hidden\" role=\"alert\">\n <span id=\"errorText\"></span>\n <button id=\"retryButton\" type=\"button\" class=\"link-button\">Retry</button>\n </div>\n\n <div id=\"successBox\" class=\"status success hidden\" role=\"status\" aria-live=\"polite\"></div>\n\n <div id=\"unknownBox\" class=\"status warning hidden\" role=\"status\" aria-live=\"polite\">\n <strong id=\"unknownTitle\"></strong>\n <span id=\"unknownText\" class=\"warning-detail\"></span>\n </div>\n\n <div class=\"actions\">\n <button id=\"cancelButton\" type=\"button\" class=\"button button-secondary\">Cancel</button>\n <button id=\"draftButton\" type=\"button\" class=\"button button-secondary\">\n <span id=\"draftSpinner\" class=\"spinner hidden\" aria-hidden=\"true\"></span>\n <span id=\"draftLabel\">Save draft</span>\n </button>\n <button id=\"sendButton\" type=\"button\" class=\"button button-primary\">\n <span id=\"sendSpinner\" class=\"spinner hidden\" aria-hidden=\"true\"></span>\n <span id=\"sendLabel\">Send email</span>\n </button>\n </div>\n </form>\n\n <div id=\"sentView\" class=\"card hidden\" role=\"status\" aria-live=\"polite\">\n <div class=\"sent-header\">\n <span class=\"sent-badge\">Sent</span>\n <span id=\"sentTimestamp\" class=\"sent-timestamp\"></span>\n </div>\n\n <div class=\"field\">\n <label>From</label>\n <span id=\"sentFrom\" class=\"sent-value\"></span>\n </div>\n\n <div class=\"field\">\n <label>To</label>\n <span id=\"sentTo\" class=\"sent-value\"></span>\n </div>\n\n <div id=\"sentCcField\" class=\"field hidden\">\n <label>CC</label>\n <span id=\"sentCc\" class=\"sent-value\"></span>\n </div>\n\n <div id=\"sentBccField\" class=\"field hidden\">\n <label>BCC</label>\n <span id=\"sentBcc\" class=\"sent-value\"></span>\n </div>\n\n <div class=\"field\">\n <label>Subject</label>\n <span id=\"sentSubject\" class=\"sent-value\"></span>\n </div>\n\n <div class=\"field\">\n <label>Message</label>\n <div id=\"sentBody\" class=\"sent-body\"></div>\n </div>\n\n <div class=\"actions\">\n <button id=\"sentCollapseButton\" type=\"button\" class=\"button button-secondary\">Collapse</button>\n </div>\n </div>\n </div>\n\n <script>\n (function () {\n 'use strict';\n\n var RESOURCE_URI = 'ui://microsoft-mail/compose-email';\n var currentEmail = '';\n // The host prefills the draft exactly once via ui/notifications/tool-result\n // on ready. We apply only the FIRST prefill and ignore any later ones, so a\n // stray or hostile re-post can't silently rewrite a draft the user has\n // already reviewed before clicking Send.\n var draftApplied = false;\n var pendingRequestId = null;\n var pendingSendPayload = null;\n // Retain across the local timeout so even a late reply clears its payload.\n var pendingSendRequestId = null;\n var sending = false;\n var hostSending = false;\n var collapsed = false;\n var sendMayHaveGone = false;\n var sent = false;\n // Which action the in-flight request belongs to ('send' | 'draft').\n // Captured before clearing on reply/timeout so the response handler can\n // route error/success correctly. retryAction survives the reply so a\n // later Retry click still knows which tool to re-invoke.\n var pendingAction = null;\n var retryAction = null;\n var sendBlocked = false;\n var sendTimeoutId = null;\n // Just beyond the host-side tool-call timeout (60s) so a legitimately slow\n // send resolves to its real result first; this only fires when the reply\n // is genuinely lost, so the button can never stay stuck-silent.\n var SEND_TIMEOUT_MS = 75000;\n\n var composeForm = document.getElementById('composeForm');\n var collapsedState = document.getElementById('collapsedState');\n var collapsedMessage = document.getElementById('collapsedMessage');\n var reopenButton = document.getElementById('reopenButton');\n\n var sentView = document.getElementById('sentView');\n var sentTimestamp = document.getElementById('sentTimestamp');\n var sentFrom = document.getElementById('sentFrom');\n var sentTo = document.getElementById('sentTo');\n var sentCcField = document.getElementById('sentCcField');\n var sentCc = document.getElementById('sentCc');\n var sentBccField = document.getElementById('sentBccField');\n var sentBcc = document.getElementById('sentBcc');\n var sentSubject = document.getElementById('sentSubject');\n var sentBody = document.getElementById('sentBody');\n var sentCollapseButton = document.getElementById('sentCollapseButton');\n\n var toInput = document.getElementById('toInput');\n var ccInput = document.getElementById('ccInput');\n var bccInput = document.getElementById('bccInput');\n var subjectInput = document.getElementById('subjectInput');\n var bodyInput = document.getElementById('bodyInput');\n var fromValue = document.getElementById('fromValue');\n var fromHelper = document.getElementById('fromHelper');\n var ccRow = document.getElementById('ccRow');\n var bccRow = document.getElementById('bccRow');\n var toggleCcButton = document.getElementById('toggleCcButton');\n var toggleBccButton = document.getElementById('toggleBccButton');\n\n var sendButton = document.getElementById('sendButton');\n var sendLabel = document.getElementById('sendLabel');\n var sendSpinner = document.getElementById('sendSpinner');\n var draftButton = document.getElementById('draftButton');\n var draftLabel = document.getElementById('draftLabel');\n var draftSpinner = document.getElementById('draftSpinner');\n var cancelButton = document.getElementById('cancelButton');\n var retryButton = document.getElementById('retryButton');\n\n var errorBox = document.getElementById('errorBox');\n var errorText = document.getElementById('errorText');\n var successBox = document.getElementById('successBox');\n var unknownBox = document.getElementById('unknownBox');\n var unknownTitle = document.getElementById('unknownTitle');\n var unknownText = document.getElementById('unknownText');\n\n function applyThemeFromHostContext() {\n try {\n var context = window.__MCP_HOST_CONTEXT__;\n if (!context || (context.theme !== 'light' && context.theme !== 'dark')) {\n return;\n }\n document.documentElement.setAttribute('data-theme', context.theme);\n } catch (_) {\n // Ignore theme extraction errors\n }\n }\n\n function trimString(value) {\n return String(value || '').trim();\n }\n\n function applyFromValue(email) {\n var trimmed = trimString(email);\n if (trimmed) {\n fromValue.textContent = trimmed;\n fromValue.style.color = '';\n fromHelper.textContent = '';\n fromHelper.classList.add('hidden');\n } else {\n fromValue.textContent = 'Account not shown';\n fromValue.style.color = 'var(--muted)';\n fromHelper.textContent = 'Couldn\\'t confirm which email account to send from. Cancel, then ask your assistant to recreate this draft.';\n fromHelper.classList.remove('hidden');\n }\n }\n\n function formatAddressItem(item) {\n if (item && typeof item === 'object') {\n var email = trimString(item.email || item.address || item.value);\n var name = trimString(item.name || item.displayName);\n if (email && name) {\n return name + ' <' + email + '>';\n }\n return email;\n }\n return trimString(item);\n }\n\n function normalizeAddressList(value) {\n if (Array.isArray(value)) {\n return value.map(formatAddressItem).filter(Boolean);\n }\n if (typeof value === 'string') {\n return value\n .split(',')\n .map(function (item) { return trimString(item); })\n .filter(Boolean);\n }\n return [];\n }\n\n function listToInputValue(list) {\n return normalizeAddressList(list).join(', ');\n }\n\n var resizeQueued = false;\n function postResize() {\n if (resizeQueued) return;\n resizeQueued = true;\n requestAnimationFrame(function () {\n resizeQueued = false;\n var height = Math.max(\n document.documentElement.scrollHeight,\n document.body ? document.body.scrollHeight : 0\n );\n window.parent.postMessage(\n { jsonrpc: '2.0', method: 'ui/resize', params: { height: height } },\n '*'\n );\n });\n }\n\n function postReady() {\n window.parent.postMessage(\n {\n method: 'mcp-app:ready',\n params: { resourceUri: RESOURCE_URI }\n },\n '*'\n );\n }\n\n // Exactly one of the three panels is visible at a time: the editable form,\n // the read-only sent view, or the collapsed summary bar.\n function showView(view) {\n composeForm.classList.toggle('hidden', view !== 'form');\n sentView.classList.toggle('hidden', view !== 'sent');\n collapsedState.classList.toggle('hidden', view !== 'collapsed');\n postResize();\n }\n\n function setCollapsed(nextCollapsed, message) {\n collapsed = nextCollapsed;\n if (nextCollapsed) {\n collapsedMessage.textContent = message || 'Draft collapsed.';\n showView('collapsed');\n } else {\n // Expanding after a send restores the read-only sent view (never the\n // editable form) so the user can re-read what went out without any risk\n // of a duplicate send; before sending, it restores the editable form.\n showView(sent ? 'sent' : 'form');\n }\n }\n\n function setSending(nextSending) {\n // Only a host outcome can release another copy's in-flight send.\n nextSending = nextSending || hostSending;\n sending = nextSending;\n sendButton.disabled = nextSending || sendBlocked;\n retryButton.disabled = nextSending;\n draftButton.disabled = nextSending;\n cancelButton.disabled = nextSending;\n toInput.disabled = nextSending;\n ccInput.disabled = nextSending;\n bccInput.disabled = nextSending;\n subjectInput.disabled = nextSending;\n bodyInput.disabled = nextSending;\n sendSpinner.classList.toggle('hidden', !nextSending);\n sendLabel.textContent = nextSending ? 'Sending\u2026' : 'Send email';\n sendButton.setAttribute('aria-busy', nextSending ? 'true' : 'false');\n postResize();\n }\n\n // One local request is in flight at a time, but a send in another\n // copy can overlap this draft save and must keep the controls locked.\n function setSavingDraft(nextSaving) {\n sending = nextSaving;\n sendButton.disabled = nextSaving || sendBlocked;\n draftButton.disabled = nextSaving;\n cancelButton.disabled = nextSaving;\n toInput.disabled = nextSaving;\n ccInput.disabled = nextSaving;\n bccInput.disabled = nextSaving;\n subjectInput.disabled = nextSaving;\n bodyInput.disabled = nextSaving;\n sendSpinner.classList.add('hidden');\n sendLabel.textContent = 'Send email';\n sendButton.setAttribute('aria-busy', 'false');\n draftSpinner.classList.toggle('hidden', !nextSaving);\n draftLabel.textContent = nextSaving ? 'Saving\u2026' : 'Save draft';\n draftButton.setAttribute('aria-busy', nextSaving ? 'true' : 'false');\n if (hostSending) setSending(true);\n postResize();\n }\n\n function clearError() {\n errorText.textContent = '';\n errorBox.classList.add('hidden');\n }\n\n function showError(message) {\n retryButton.classList.toggle('hidden', sendBlocked && retryAction !== 'draft');\n errorText.textContent = message || 'Failed to send email.';\n errorBox.classList.remove('hidden');\n postResize();\n }\n\n function clearSuccess() {\n successBox.textContent = '';\n successBox.classList.add('hidden');\n }\n\n function showSuccess(message) {\n successBox.textContent = message;\n successBox.classList.remove('hidden');\n postResize();\n }\n\n function clearSendTimeout() {\n if (sendTimeoutId !== null) {\n clearTimeout(sendTimeoutId);\n sendTimeoutId = null;\n }\n }\n\n function clearUnknown() {\n unknownTitle.textContent = '';\n unknownText.textContent = '';\n unknownBox.classList.add('hidden');\n errorBox.appendChild(retryButton);\n }\n\n // No reply ever came back for the send (e.g. the host's response was lost\n // before reaching this iframe). We genuinely don't know whether the email\n // went out, so we must NOT claim success or failure: re-enable the form and\n // tell the user to verify before resending (the send is not idempotent, so\n // a blind retry could send a duplicate).\n function showSendUnknown() {\n sendMayHaveGone = true;\n clearError();\n clearSuccess();\n unknownTitle.textContent = 'Not sure if this sent.';\n unknownText.textContent = \"No confirmation came back in time. Check your Sent folder before sending again, so it doesn't go out twice.\";\n unknownBox.classList.remove('hidden');\n if (!sendBlocked) unknownBox.appendChild(retryButton);\n postResize();\n }\n\n function handleSendTimeout() {\n sendTimeoutId = null;\n if (!pendingRequestId || sent) {\n return;\n }\n pendingRequestId = null;\n if (pendingAction === 'draft') {\n pendingAction = null;\n setSavingDraft(false);\n showDraftSaveUnknown();\n return;\n }\n pendingAction = null;\n setSending(false);\n showSendUnknown();\n }\n\n // Same lost-reply honesty as a send, lower stakes: a blind retry here\n // could create a duplicate draft, so we say we're not sure and point at\n // the Drafts folder instead of offering Retry.\n function showDraftSaveUnknown() {\n clearError();\n clearSuccess();\n unknownTitle.textContent = 'Not sure if the draft was saved.';\n unknownText.textContent =\n \"No confirmation came back in time. Check your Drafts folder before trying again, so you don't create a duplicate.\";\n unknownBox.classList.remove('hidden');\n postResize();\n }\n\n function setCcVisible(visible) {\n ccRow.classList.toggle('hidden', !visible);\n toggleCcButton.textContent = visible ? 'Hide CC' : 'Add CC';\n toggleCcButton.setAttribute('aria-expanded', visible ? 'true' : 'false');\n }\n\n function setBccVisible(visible) {\n bccRow.classList.toggle('hidden', !visible);\n toggleBccButton.textContent = visible ? 'Hide BCC' : 'Add BCC';\n toggleBccButton.setAttribute('aria-expanded', visible ? 'true' : 'false');\n }\n\n function readFormPayload() {\n var payload = {\n to: normalizeAddressList(toInput.value),\n cc: normalizeAddressList(ccInput.value),\n bcc: normalizeAddressList(bccInput.value),\n subject: String(subjectInput.value || ''),\n body: String(bodyInput.value || '')\n };\n if (currentEmail) {\n payload.email = currentEmail;\n }\n return payload;\n }\n\n function validatePayload(payload) {\n if (!payload.to || payload.to.length === 0) {\n return 'Add at least one recipient in To.';\n }\n if (!trimString(payload.subject)) {\n return 'Add a subject before sending.';\n }\n if (!trimString(payload.body)) {\n return 'Add an email body before sending.';\n }\n return null;\n }\n\n // Same provider-compatible minimum as sending (the draft tools require\n // To, Subject, and Body too) with save-specific copy. Draft is\n // email-mode only, so this body is the email shape unconditionally.\n function validateDraftPayload(payload) {\n if (!payload.to || payload.to.length === 0) {\n return 'Add at least one recipient in To.';\n }\n if (!trimString(payload.subject)) {\n return 'Add a subject before saving.';\n }\n if (!trimString(payload.body)) {\n return 'Add an email body before saving.';\n }\n return null;\n }\n\n function sendPayload(payload) {\n pendingSendPayload = payload;\n pendingRequestId = 'send-' + Date.now() + '-' + Math.random().toString(16).slice(2);\n pendingSendRequestId = pendingRequestId;\n pendingAction = 'send';\n retryAction = null;\n setSending(true);\n clearError();\n clearSuccess();\n clearUnknown();\n clearSendTimeout();\n sendTimeoutId = setTimeout(handleSendTimeout, SEND_TIMEOUT_MS);\n\n window.parent.postMessage(\n {\n jsonrpc: '2.0',\n method: 'tools/call',\n params: {\n name: 'send_email',\n _meta: { 'mcp-app/cardOutcome': 'sent' },\n arguments: payload\n },\n id: pendingRequestId\n },\n '*'\n );\n }\n\n function saveDraftPayload(payload) {\n pendingRequestId = 'draft-' + Date.now() + '-' + Math.random().toString(16).slice(2);\n pendingAction = 'draft';\n retryAction = null;\n setSavingDraft(true);\n clearError();\n clearSuccess();\n clearUnknown();\n clearSendTimeout();\n sendTimeoutId = setTimeout(handleSendTimeout, SEND_TIMEOUT_MS);\n\n window.parent.postMessage(\n {\n jsonrpc: '2.0',\n method: 'tools/call',\n params: {\n name: 'create_draft',\n arguments: payload\n },\n id: pendingRequestId\n },\n '*'\n );\n }\n\n function applyDraftData(rawDraft) {\n var draft = rawDraft && typeof rawDraft === 'object' ? rawDraft : {};\n toInput.value = listToInputValue(draft.to);\n ccInput.value = listToInputValue(draft.cc);\n bccInput.value = listToInputValue(draft.bcc);\n subjectInput.value = typeof draft.subject === 'string' ? draft.subject : '';\n bodyInput.value = typeof draft.body === 'string' ? draft.body : '';\n currentEmail = typeof draft.email === 'string' ? draft.email : '';\n applyFromValue(currentEmail);\n setCcVisible(normalizeAddressList(draft.cc).length > 0);\n setBccVisible(normalizeAddressList(draft.bcc).length > 0);\n clearError();\n clearSuccess();\n postResize();\n }\n\n function getDraftFromToolResult(payload) {\n if (!payload || typeof payload !== 'object') {\n return null;\n }\n // CANONICAL: post-A0 super-mcp hoists structuredContent onto the\n // outer block; the host posts it through `params.structuredContent`.\n if (payload.structuredContent && typeof payload.structuredContent === 'object') {\n return payload.structuredContent;\n }\n // MIGRATION SHIM: pre-A0 stored sessions replayed through the\n // current iframe lack `params.structuredContent` because the outer\n // block had no hoist at capture time. Read inner envelope text \u2192\n // JSON.parse \u2192 result.structuredContent. NOT regex-based.\n //\n // Lifetime: PERMANENT defensive read-side helper. Pre-A0 sessions\n // are persisted on disk and may be replayed indefinitely; there is\n // no time-based sunset. Removing this fallback would silently break\n // pre-A0 conversation replay.\n var text = typeof payload.text === 'string' ? payload.text :\n (Array.isArray(payload.content)\n ? (payload.content.find(function (c) { return c && c.type === 'text' && typeof c.text === 'string'; }) || {}).text\n : null);\n if (typeof text !== 'string') return null;\n try {\n var parsed = JSON.parse(text);\n if (parsed && typeof parsed === 'object' && parsed.result && typeof parsed.result === 'object') {\n var inner = parsed.result;\n if (inner.structuredContent && typeof inner.structuredContent === 'object') {\n return inner.structuredContent;\n }\n }\n } catch (_) {\n // Likely-envelope heuristic: text starts with `{` and contains\n // `\"package_id\"` in the first 64 chars. If JSON.parse failed on a\n // likely-envelope, surface a warning so the developer chasing\n // \"compose form is empty on replay\" sees a signal. For non-envelope\n // text (the dominant case), no log fires.\n var prefix = text.length > 64 ? text.slice(0, 64) : text;\n var likelyEnvelope = prefix.charAt(0) === '{' && prefix.indexOf('\"package_id\"') !== -1;\n if (likelyEnvelope && typeof console !== 'undefined' && typeof console.warn === 'function') {\n console.warn('[compose-email] Migration shim: JSON.parse failed on likely super-mcp envelope; pre-fill skipped');\n }\n }\n return null;\n }\n\n function findTextBlock(blocks) {\n if (!Array.isArray(blocks)) return null;\n var block = blocks.find(function (c) {\n return c && c.type === 'text' && typeof c.text === 'string';\n });\n return block ? block.text : null;\n }\n\n // Extract the send result identifiers ({ messageId, threadId, labelIds })\n // from the tool-call reply. The connector attaches structuredContent, which\n // super-mcp hoists onto the outer block, so the fast path is a single read.\n // The envelope-unwrapping fallback keeps this robust for hosts (or replayed\n // sessions) that forward only the serialized super-mcp text envelope.\n function getSendMetaFromResult(result) {\n if (!result || typeof result !== 'object') return null;\n if (result.structuredContent && typeof result.structuredContent === 'object') {\n return result.structuredContent;\n }\n try {\n var outerText = findTextBlock(result.content);\n if (typeof outerText !== 'string' && typeof result.text === 'string') {\n outerText = result.text;\n }\n if (typeof outerText !== 'string') return null;\n var envelope = JSON.parse(outerText);\n if (!envelope || typeof envelope !== 'object') return null;\n // outerText was the connector payload directly (no super-mcp envelope).\n if (envelope.messageId || envelope.threadId) return envelope;\n var inner = envelope.result;\n if (!inner || typeof inner !== 'object') return null;\n if (inner.structuredContent && typeof inner.structuredContent === 'object') {\n return inner.structuredContent;\n }\n var innerText = findTextBlock(inner.content);\n if (typeof innerText !== 'string') return null;\n var payload = JSON.parse(innerText);\n return (payload && typeof payload === 'object') ? payload : null;\n } catch (_) {\n return null;\n }\n }\n\n function formatSentTime(at) {\n if (typeof at !== 'number' || !Number.isFinite(at)) return '';\n var date = new Date(at);\n if (!Number.isFinite(date.getTime())) return '';\n try {\n return date.toLocaleString(undefined, {\n month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit'\n });\n } catch (_) {\n return '';\n }\n }\n\n function applyCardOutcome(o) {\n if (sent) return;\n if (pendingRequestId && pendingRequestId === pendingSendRequestId &&\n (!o || o.outcome === 'sending' || o.outcome === 'maybe-sent')) return;\n if (hostSending) {\n hostSending = false;\n setSending(false);\n if (sendMayHaveGone) showSendUnknown();\n }\n if (!o || typeof o !== 'object') return;\n if (o.outcome === 'sending') {\n hostSending = true;\n setCollapsed(false);\n setSending(true);\n clearUnknown();\n return;\n }\n if (o.outcome === 'maybe-sent') {\n showSendUnknown();\n setCollapsed(false);\n return;\n }\n if (o.outcome !== 'sent' && o.outcome !== 'submitted') return;\n sent = true;\n sendMayHaveGone = false;\n clearSendTimeout();\n clearError();\n clearSuccess();\n clearUnknown();\n var stamp = formatSentTime(o.at);\n setCollapsed(true, stamp ? 'Email sent \u00B7 ' + stamp : 'Email sent.');\n if (pendingSendPayload) renderSentView(pendingSendPayload, null, stamp);\n reopenButton.classList.toggle('hidden', !pendingSendPayload);\n }\n\n function renderSentView(payload, meta, stamp) {\n payload = payload && typeof payload === 'object' ? payload : {};\n sentTimestamp.textContent = stamp ? 'Sent ' + stamp : 'Sent';\n sentFrom.textContent = trimString(payload.email) || 'Account not shown';\n sentTo.textContent = normalizeAddressList(payload.to).join(', ');\n var ccList = normalizeAddressList(payload.cc);\n sentCc.textContent = ccList.join(', ');\n sentCcField.classList.toggle('hidden', ccList.length === 0);\n var bccList = normalizeAddressList(payload.bcc);\n sentBcc.textContent = bccList.join(', ');\n sentBccField.classList.toggle('hidden', bccList.length === 0);\n sentSubject.textContent = String(payload.subject || '');\n sentBody.textContent = String(payload.body || '');\n }\n\n function handleSendRequest() {\n if (sent) return;\n if (sending) return;\n if (sendBlocked) return;\n var payload = readFormPayload();\n var validationError = validatePayload(payload);\n if (validationError) {\n showError(validationError);\n return;\n }\n\n sendPayload(payload);\n }\n\n // The Send button is type=\"button\" with an explicit click handler rather\n // than a form submit button. The host renders this iframe with a\n // sandbox of \"allow-scripts\" only \u2014 no \"allow-forms\" \u2014 so native form\n // submission is blocked by the browser BEFORE the submit event fires\n // (\"Blocked form submission ... the form's frame is sandboxed and the\n // allow-forms permission is not set\"). A submit-driven Send therefore\n // silently did nothing: no postMessage, no spinner, no telemetry.\n // A click handler needs no sandbox permission and is the same path\n // Cancel/Retry already use. The submit listener below stays only as a\n // defensive fallback for hosts that DO grant allow-forms; in this sandbox\n // it never fires (neither the button click nor Enter routes through it).\n // The sending guard keeps any double-fire (in an allow-forms host) a no-op.\n sendButton.addEventListener('click', function () {\n handleSendRequest();\n });\n\n draftButton.addEventListener('click', function () {\n if (sending) return;\n var payload = readFormPayload();\n var validationError = validateDraftPayload(payload);\n if (validationError) {\n showError(validationError);\n return;\n }\n saveDraftPayload(payload);\n });\n\n composeForm.addEventListener('submit', function (event) {\n event.preventDefault();\n handleSendRequest();\n });\n\n retryButton.addEventListener('click', function () {\n if (sent) return;\n if (sending) return;\n if (sendBlocked && retryAction !== 'draft') return;\n var payload = readFormPayload();\n if (retryAction === 'draft') {\n var draftValidationError = validateDraftPayload(payload);\n if (draftValidationError) {\n showError(draftValidationError);\n return;\n }\n retryAction = null;\n saveDraftPayload(payload);\n return;\n }\n var validationError = validatePayload(payload);\n if (validationError) {\n showError(validationError);\n return;\n }\n sendPayload(payload);\n });\n\n cancelButton.addEventListener('click', function () {\n if (sending) return;\n // Hiding the notice does not resolve whether an earlier send went out.\n var collapseMessage = sendMayHaveGone\n ? 'Collapsed. Check your Sent folder if you are not sure.'\n : 'Draft collapsed. Nothing sent.';\n clearError();\n clearSuccess();\n clearUnknown();\n setCollapsed(true, collapseMessage);\n });\n\n reopenButton.addEventListener('click', function () {\n setCollapsed(false);\n if (!sent && sendMayHaveGone) showSendUnknown();\n });\n\n sentCollapseButton.addEventListener('click', function () {\n setCollapsed(true, collapsedMessage.textContent || 'Email sent.');\n });\n\n toggleCcButton.addEventListener('click', function () {\n setCcVisible(ccRow.classList.contains('hidden'));\n postResize();\n });\n\n toggleBccButton.addEventListener('click', function () {\n setBccVisible(bccRow.classList.contains('hidden'));\n postResize();\n });\n\n [toInput, ccInput, bccInput, subjectInput, bodyInput].forEach(function (element) {\n element.addEventListener('input', function () {\n if (!sendBlocked) clearError();\n clearSuccess();\n if (!sendMayHaveGone) clearUnknown();\n postResize();\n });\n });\n\n window.addEventListener('message', function (event) {\n // Honest scope (origin-independent): the iframe sandbox origin is 'null',\n // so validating event.origin is unreliable across dev/prod/custom-scheme\n // hosts. Instead reject any *identified* sender that isn't our host frame\n // (window.parent). A real cross-frame postMessage always stamps\n // event.source with the sending window, so a hostile sibling frame is\n // rejected here; a null source only occurs for same-context synthetic\n // dispatch (our own code) and cannot be forged from outside, so we\n // tolerate it. This does not authenticate the host's identity \u2014 the host\n // separately authenticates this iframe by origin+source.\n if (event.source && event.source !== window.parent) {\n return;\n }\n\n var data = event.data;\n if (!data || typeof data !== 'object') {\n return;\n }\n\n if (data.method === 'mcp-app:card-outcome') {\n if (event.source === window.parent) applyCardOutcome(data.params);\n return;\n }\n\n if (data.method === 'ui/notifications/tool-result') {\n // Always parse (so the migration-shim's malformed-envelope warning\n // still fires), but apply only the first successful prefill: a stray\n // or hostile re-post can't silently rewrite a draft the user has\n // already reviewed.\n var draft = getDraftFromToolResult(data.params);\n if (draft && !draftApplied) {\n draftApplied = true;\n applyDraftData(draft);\n }\n return;\n }\n\n if (data.jsonrpc !== '2.0') return;\n var completedSendPayload = null;\n if (pendingSendRequestId && data.id === pendingSendRequestId) {\n completedSendPayload = pendingSendPayload;\n pendingSendPayload = null;\n pendingSendRequestId = null;\n }\n if (!pendingRequestId || data.id !== pendingRequestId) {\n return;\n }\n\n pendingRequestId = null;\n clearSendTimeout();\n clearUnknown();\n var completedAction = pendingAction;\n pendingAction = null;\n if (completedAction === 'draft') {\n setSavingDraft(false);\n } else {\n setSending(false);\n }\n\n if (data.error) {\n var errorMessage = data.error && typeof data.error.message === 'string'\n ? data.error.message\n : (completedAction === 'draft' ? 'Failed to save draft.' : 'Failed to send email.');\n if (completedAction === 'draft') {\n // Retry re-invokes the draft tool, not the send tool \u2014 pendingAction\n // is already cleared, so this is what the Retry handler routes on.\n retryAction = 'draft';\n }\n var blockedReason = data.error.data && data.error.data.reason;\n var retryCannotChangeBlock = blockedReason === 'user-disabled' || blockedReason === 'admin-disabled' || blockedReason === 'security-policy';\n var blockedBeforeSend = retryCannotChangeBlock || blockedReason === 'not-dispatched';\n if (completedAction !== 'draft' && retryCannotChangeBlock) {\n sendBlocked = true;\n sendButton.disabled = true;\n }\n if (completedAction !== 'draft' && (!blockedBeforeSend || sendMayHaveGone)) {\n showSendUnknown();\n }\n showError(errorMessage);\n return;\n }\n\n clearError();\n clearSuccess();\n if (completedAction === 'draft') {\n // Terminal: the draft now lives in the mailbox's Drafts folder.\n // Collapse to a stamped confirmation and retire the form \u2014 Reopen\n // would resurrect an editable copy whose next Save/Send silently\n // diverges from (or duplicates) the saved draft.\n var draftStamp = formatSentTime(Date.now());\n setCollapsed(true, draftStamp ? 'Draft saved \u00B7 ' + draftStamp : 'Draft saved.');\n reopenButton.classList.add('hidden');\n return;\n }\n // Preserve what was sent instead of discarding the draft. completedSendPayload\n // is the exact payload we posted. We default to the collapsed summary, but\n // Reopen now restores a read-only view of the sent message.\n var sentPayload = completedSendPayload || readFormPayload();\n var stamp = formatSentTime(Date.now());\n renderSentView(sentPayload, getSendMetaFromResult(data.result), stamp);\n sent = true;\n sendMayHaveGone = false;\n reopenButton.classList.remove('hidden');\n setCollapsed(true, stamp ? 'Email sent \u00B7 ' + stamp : 'Email sent.');\n });\n\n if (typeof ResizeObserver === 'function' && document.body) {\n var observer = new ResizeObserver(postResize);\n observer.observe(document.body);\n }\n\n applyThemeFromHostContext();\n setCcVisible(false);\n setBccVisible(false);\n var hostOutcome = (window.__MCP_HOST_CONTEXT__ || {}).cardOutcome;\n if (hostOutcome) applyCardOutcome(hostOutcome);\n else setCollapsed(false);\n postResize();\n postReady();\n\n window.parent.postMessage(\n {\n jsonrpc: '2.0',\n method: 'ui/initialize',\n params: { resourceUri: RESOURCE_URI },\n id: 'compose-email-init'\n },\n '*'\n );\n })();\n </script>\n</body>\n</html>\n";
|
|
2
2
|
//# sourceMappingURL=compose-email-template.d.ts.map
|
|
@@ -194,6 +194,7 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
194
194
|
justify-content: flex-end;
|
|
195
195
|
gap: 10px;
|
|
196
196
|
margin-top: 2px;
|
|
197
|
+
flex-wrap: wrap;
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
.button {
|
|
@@ -404,6 +405,10 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
404
405
|
|
|
405
406
|
<div class="actions">
|
|
406
407
|
<button id="cancelButton" type="button" class="button button-secondary">Cancel</button>
|
|
408
|
+
<button id="draftButton" type="button" class="button button-secondary">
|
|
409
|
+
<span id="draftSpinner" class="spinner hidden" aria-hidden="true"></span>
|
|
410
|
+
<span id="draftLabel">Save draft</span>
|
|
411
|
+
</button>
|
|
407
412
|
<button id="sendButton" type="button" class="button button-primary">
|
|
408
413
|
<span id="sendSpinner" class="spinner hidden" aria-hidden="true"></span>
|
|
409
414
|
<span id="sendLabel">Send email</span>
|
|
@@ -465,11 +470,21 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
465
470
|
// already reviewed before clicking Send.
|
|
466
471
|
var draftApplied = false;
|
|
467
472
|
var pendingRequestId = null;
|
|
468
|
-
var
|
|
473
|
+
var pendingSendPayload = null;
|
|
474
|
+
// Retain across the local timeout so even a late reply clears its payload.
|
|
475
|
+
var pendingSendRequestId = null;
|
|
469
476
|
var sending = false;
|
|
477
|
+
var hostSending = false;
|
|
470
478
|
var collapsed = false;
|
|
471
|
-
var
|
|
479
|
+
var sendMayHaveGone = false;
|
|
472
480
|
var sent = false;
|
|
481
|
+
// Which action the in-flight request belongs to ('send' | 'draft').
|
|
482
|
+
// Captured before clearing on reply/timeout so the response handler can
|
|
483
|
+
// route error/success correctly. retryAction survives the reply so a
|
|
484
|
+
// later Retry click still knows which tool to re-invoke.
|
|
485
|
+
var pendingAction = null;
|
|
486
|
+
var retryAction = null;
|
|
487
|
+
var sendBlocked = false;
|
|
473
488
|
var sendTimeoutId = null;
|
|
474
489
|
// Just beyond the host-side tool-call timeout (60s) so a legitimately slow
|
|
475
490
|
// send resolves to its real result first; this only fires when the reply
|
|
@@ -508,6 +523,9 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
508
523
|
var sendButton = document.getElementById('sendButton');
|
|
509
524
|
var sendLabel = document.getElementById('sendLabel');
|
|
510
525
|
var sendSpinner = document.getElementById('sendSpinner');
|
|
526
|
+
var draftButton = document.getElementById('draftButton');
|
|
527
|
+
var draftLabel = document.getElementById('draftLabel');
|
|
528
|
+
var draftSpinner = document.getElementById('draftSpinner');
|
|
511
529
|
var cancelButton = document.getElementById('cancelButton');
|
|
512
530
|
var retryButton = document.getElementById('retryButton');
|
|
513
531
|
|
|
@@ -544,7 +562,7 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
544
562
|
} else {
|
|
545
563
|
fromValue.textContent = 'Account not shown';
|
|
546
564
|
fromValue.style.color = 'var(--muted)';
|
|
547
|
-
fromHelper.textContent = '
|
|
565
|
+
fromHelper.textContent = 'Couldn\\'t confirm which email account to send from. Cancel, then ask your assistant to recreate this draft.';
|
|
548
566
|
fromHelper.classList.remove('hidden');
|
|
549
567
|
}
|
|
550
568
|
}
|
|
@@ -628,8 +646,12 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
628
646
|
}
|
|
629
647
|
|
|
630
648
|
function setSending(nextSending) {
|
|
649
|
+
// Only a host outcome can release another copy's in-flight send.
|
|
650
|
+
nextSending = nextSending || hostSending;
|
|
631
651
|
sending = nextSending;
|
|
632
|
-
sendButton.disabled = nextSending;
|
|
652
|
+
sendButton.disabled = nextSending || sendBlocked;
|
|
653
|
+
retryButton.disabled = nextSending;
|
|
654
|
+
draftButton.disabled = nextSending;
|
|
633
655
|
cancelButton.disabled = nextSending;
|
|
634
656
|
toInput.disabled = nextSending;
|
|
635
657
|
ccInput.disabled = nextSending;
|
|
@@ -642,12 +664,35 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
642
664
|
postResize();
|
|
643
665
|
}
|
|
644
666
|
|
|
667
|
+
// One local request is in flight at a time, but a send in another
|
|
668
|
+
// copy can overlap this draft save and must keep the controls locked.
|
|
669
|
+
function setSavingDraft(nextSaving) {
|
|
670
|
+
sending = nextSaving;
|
|
671
|
+
sendButton.disabled = nextSaving || sendBlocked;
|
|
672
|
+
draftButton.disabled = nextSaving;
|
|
673
|
+
cancelButton.disabled = nextSaving;
|
|
674
|
+
toInput.disabled = nextSaving;
|
|
675
|
+
ccInput.disabled = nextSaving;
|
|
676
|
+
bccInput.disabled = nextSaving;
|
|
677
|
+
subjectInput.disabled = nextSaving;
|
|
678
|
+
bodyInput.disabled = nextSaving;
|
|
679
|
+
sendSpinner.classList.add('hidden');
|
|
680
|
+
sendLabel.textContent = 'Send email';
|
|
681
|
+
sendButton.setAttribute('aria-busy', 'false');
|
|
682
|
+
draftSpinner.classList.toggle('hidden', !nextSaving);
|
|
683
|
+
draftLabel.textContent = nextSaving ? 'Saving…' : 'Save draft';
|
|
684
|
+
draftButton.setAttribute('aria-busy', nextSaving ? 'true' : 'false');
|
|
685
|
+
if (hostSending) setSending(true);
|
|
686
|
+
postResize();
|
|
687
|
+
}
|
|
688
|
+
|
|
645
689
|
function clearError() {
|
|
646
690
|
errorText.textContent = '';
|
|
647
691
|
errorBox.classList.add('hidden');
|
|
648
692
|
}
|
|
649
693
|
|
|
650
694
|
function showError(message) {
|
|
695
|
+
retryButton.classList.toggle('hidden', sendBlocked && retryAction !== 'draft');
|
|
651
696
|
errorText.textContent = message || 'Failed to send email.';
|
|
652
697
|
errorBox.classList.remove('hidden');
|
|
653
698
|
postResize();
|
|
@@ -672,10 +717,10 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
672
717
|
}
|
|
673
718
|
|
|
674
719
|
function clearUnknown() {
|
|
675
|
-
outcomeUnknown = false;
|
|
676
720
|
unknownTitle.textContent = '';
|
|
677
721
|
unknownText.textContent = '';
|
|
678
722
|
unknownBox.classList.add('hidden');
|
|
723
|
+
errorBox.appendChild(retryButton);
|
|
679
724
|
}
|
|
680
725
|
|
|
681
726
|
// No reply ever came back for the send (e.g. the host's response was lost
|
|
@@ -684,25 +729,46 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
684
729
|
// tell the user to verify before resending (the send is not idempotent, so
|
|
685
730
|
// a blind retry could send a duplicate).
|
|
686
731
|
function showSendUnknown() {
|
|
687
|
-
|
|
732
|
+
sendMayHaveGone = true;
|
|
688
733
|
clearError();
|
|
689
734
|
clearSuccess();
|
|
690
735
|
unknownTitle.textContent = 'Not sure if this sent.';
|
|
691
|
-
unknownText.textContent = "
|
|
736
|
+
unknownText.textContent = "No confirmation came back in time. Check your Sent folder before sending again, so it doesn't go out twice.";
|
|
692
737
|
unknownBox.classList.remove('hidden');
|
|
738
|
+
if (!sendBlocked) unknownBox.appendChild(retryButton);
|
|
693
739
|
postResize();
|
|
694
740
|
}
|
|
695
741
|
|
|
696
742
|
function handleSendTimeout() {
|
|
697
743
|
sendTimeoutId = null;
|
|
698
|
-
if (!pendingRequestId) {
|
|
744
|
+
if (!pendingRequestId || sent) {
|
|
699
745
|
return;
|
|
700
746
|
}
|
|
701
747
|
pendingRequestId = null;
|
|
748
|
+
if (pendingAction === 'draft') {
|
|
749
|
+
pendingAction = null;
|
|
750
|
+
setSavingDraft(false);
|
|
751
|
+
showDraftSaveUnknown();
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
pendingAction = null;
|
|
702
755
|
setSending(false);
|
|
703
756
|
showSendUnknown();
|
|
704
757
|
}
|
|
705
758
|
|
|
759
|
+
// Same lost-reply honesty as a send, lower stakes: a blind retry here
|
|
760
|
+
// could create a duplicate draft, so we say we're not sure and point at
|
|
761
|
+
// the Drafts folder instead of offering Retry.
|
|
762
|
+
function showDraftSaveUnknown() {
|
|
763
|
+
clearError();
|
|
764
|
+
clearSuccess();
|
|
765
|
+
unknownTitle.textContent = 'Not sure if the draft was saved.';
|
|
766
|
+
unknownText.textContent =
|
|
767
|
+
"No confirmation came back in time. Check your Drafts folder before trying again, so you don't create a duplicate.";
|
|
768
|
+
unknownBox.classList.remove('hidden');
|
|
769
|
+
postResize();
|
|
770
|
+
}
|
|
771
|
+
|
|
706
772
|
function setCcVisible(visible) {
|
|
707
773
|
ccRow.classList.toggle('hidden', !visible);
|
|
708
774
|
toggleCcButton.textContent = visible ? 'Hide CC' : 'Add CC';
|
|
@@ -742,9 +808,28 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
742
808
|
return null;
|
|
743
809
|
}
|
|
744
810
|
|
|
811
|
+
// Same provider-compatible minimum as sending (the draft tools require
|
|
812
|
+
// To, Subject, and Body too) with save-specific copy. Draft is
|
|
813
|
+
// email-mode only, so this body is the email shape unconditionally.
|
|
814
|
+
function validateDraftPayload(payload) {
|
|
815
|
+
if (!payload.to || payload.to.length === 0) {
|
|
816
|
+
return 'Add at least one recipient in To.';
|
|
817
|
+
}
|
|
818
|
+
if (!trimString(payload.subject)) {
|
|
819
|
+
return 'Add a subject before saving.';
|
|
820
|
+
}
|
|
821
|
+
if (!trimString(payload.body)) {
|
|
822
|
+
return 'Add an email body before saving.';
|
|
823
|
+
}
|
|
824
|
+
return null;
|
|
825
|
+
}
|
|
826
|
+
|
|
745
827
|
function sendPayload(payload) {
|
|
746
|
-
|
|
828
|
+
pendingSendPayload = payload;
|
|
747
829
|
pendingRequestId = 'send-' + Date.now() + '-' + Math.random().toString(16).slice(2);
|
|
830
|
+
pendingSendRequestId = pendingRequestId;
|
|
831
|
+
pendingAction = 'send';
|
|
832
|
+
retryAction = null;
|
|
748
833
|
setSending(true);
|
|
749
834
|
clearError();
|
|
750
835
|
clearSuccess();
|
|
@@ -758,6 +843,32 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
758
843
|
method: 'tools/call',
|
|
759
844
|
params: {
|
|
760
845
|
name: 'send_email',
|
|
846
|
+
_meta: { 'mcp-app/cardOutcome': 'sent' },
|
|
847
|
+
arguments: payload
|
|
848
|
+
},
|
|
849
|
+
id: pendingRequestId
|
|
850
|
+
},
|
|
851
|
+
'*'
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function saveDraftPayload(payload) {
|
|
856
|
+
pendingRequestId = 'draft-' + Date.now() + '-' + Math.random().toString(16).slice(2);
|
|
857
|
+
pendingAction = 'draft';
|
|
858
|
+
retryAction = null;
|
|
859
|
+
setSavingDraft(true);
|
|
860
|
+
clearError();
|
|
861
|
+
clearSuccess();
|
|
862
|
+
clearUnknown();
|
|
863
|
+
clearSendTimeout();
|
|
864
|
+
sendTimeoutId = setTimeout(handleSendTimeout, SEND_TIMEOUT_MS);
|
|
865
|
+
|
|
866
|
+
window.parent.postMessage(
|
|
867
|
+
{
|
|
868
|
+
jsonrpc: '2.0',
|
|
869
|
+
method: 'tools/call',
|
|
870
|
+
params: {
|
|
871
|
+
name: 'create_draft',
|
|
761
872
|
arguments: payload
|
|
762
873
|
},
|
|
763
874
|
id: pendingRequestId
|
|
@@ -870,9 +981,12 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
870
981
|
}
|
|
871
982
|
}
|
|
872
983
|
|
|
873
|
-
function formatSentTime() {
|
|
984
|
+
function formatSentTime(at) {
|
|
985
|
+
if (typeof at !== 'number' || !Number.isFinite(at)) return '';
|
|
986
|
+
var date = new Date(at);
|
|
987
|
+
if (!Number.isFinite(date.getTime())) return '';
|
|
874
988
|
try {
|
|
875
|
-
return
|
|
989
|
+
return date.toLocaleString(undefined, {
|
|
876
990
|
month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit'
|
|
877
991
|
});
|
|
878
992
|
} catch (_) {
|
|
@@ -880,6 +994,41 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
880
994
|
}
|
|
881
995
|
}
|
|
882
996
|
|
|
997
|
+
function applyCardOutcome(o) {
|
|
998
|
+
if (sent) return;
|
|
999
|
+
if (pendingRequestId && pendingRequestId === pendingSendRequestId &&
|
|
1000
|
+
(!o || o.outcome === 'sending' || o.outcome === 'maybe-sent')) return;
|
|
1001
|
+
if (hostSending) {
|
|
1002
|
+
hostSending = false;
|
|
1003
|
+
setSending(false);
|
|
1004
|
+
if (sendMayHaveGone) showSendUnknown();
|
|
1005
|
+
}
|
|
1006
|
+
if (!o || typeof o !== 'object') return;
|
|
1007
|
+
if (o.outcome === 'sending') {
|
|
1008
|
+
hostSending = true;
|
|
1009
|
+
setCollapsed(false);
|
|
1010
|
+
setSending(true);
|
|
1011
|
+
clearUnknown();
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (o.outcome === 'maybe-sent') {
|
|
1015
|
+
showSendUnknown();
|
|
1016
|
+
setCollapsed(false);
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
if (o.outcome !== 'sent' && o.outcome !== 'submitted') return;
|
|
1020
|
+
sent = true;
|
|
1021
|
+
sendMayHaveGone = false;
|
|
1022
|
+
clearSendTimeout();
|
|
1023
|
+
clearError();
|
|
1024
|
+
clearSuccess();
|
|
1025
|
+
clearUnknown();
|
|
1026
|
+
var stamp = formatSentTime(o.at);
|
|
1027
|
+
setCollapsed(true, stamp ? 'Email sent · ' + stamp : 'Email sent.');
|
|
1028
|
+
if (pendingSendPayload) renderSentView(pendingSendPayload, null, stamp);
|
|
1029
|
+
reopenButton.classList.toggle('hidden', !pendingSendPayload);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
883
1032
|
function renderSentView(payload, meta, stamp) {
|
|
884
1033
|
payload = payload && typeof payload === 'object' ? payload : {};
|
|
885
1034
|
sentTimestamp.textContent = stamp ? 'Sent ' + stamp : 'Sent';
|
|
@@ -896,8 +1045,9 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
896
1045
|
}
|
|
897
1046
|
|
|
898
1047
|
function handleSendRequest() {
|
|
1048
|
+
if (sent) return;
|
|
899
1049
|
if (sending) return;
|
|
900
|
-
|
|
1050
|
+
if (sendBlocked) return;
|
|
901
1051
|
var payload = readFormPayload();
|
|
902
1052
|
var validationError = validatePayload(payload);
|
|
903
1053
|
if (validationError) {
|
|
@@ -909,7 +1059,7 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
909
1059
|
}
|
|
910
1060
|
|
|
911
1061
|
// The Send button is type="button" with an explicit click handler rather
|
|
912
|
-
// than a form submit button. The
|
|
1062
|
+
// than a form submit button. The host renders this iframe with a
|
|
913
1063
|
// sandbox of "allow-scripts" only — no "allow-forms" — so native form
|
|
914
1064
|
// submission is blocked by the browser BEFORE the submit event fires
|
|
915
1065
|
// ("Blocked form submission ... the form's frame is sandboxed and the
|
|
@@ -924,14 +1074,37 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
924
1074
|
handleSendRequest();
|
|
925
1075
|
});
|
|
926
1076
|
|
|
1077
|
+
draftButton.addEventListener('click', function () {
|
|
1078
|
+
if (sending) return;
|
|
1079
|
+
var payload = readFormPayload();
|
|
1080
|
+
var validationError = validateDraftPayload(payload);
|
|
1081
|
+
if (validationError) {
|
|
1082
|
+
showError(validationError);
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
saveDraftPayload(payload);
|
|
1086
|
+
});
|
|
1087
|
+
|
|
927
1088
|
composeForm.addEventListener('submit', function (event) {
|
|
928
1089
|
event.preventDefault();
|
|
929
1090
|
handleSendRequest();
|
|
930
1091
|
});
|
|
931
1092
|
|
|
932
1093
|
retryButton.addEventListener('click', function () {
|
|
1094
|
+
if (sent) return;
|
|
933
1095
|
if (sending) return;
|
|
1096
|
+
if (sendBlocked && retryAction !== 'draft') return;
|
|
934
1097
|
var payload = readFormPayload();
|
|
1098
|
+
if (retryAction === 'draft') {
|
|
1099
|
+
var draftValidationError = validateDraftPayload(payload);
|
|
1100
|
+
if (draftValidationError) {
|
|
1101
|
+
showError(draftValidationError);
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
retryAction = null;
|
|
1105
|
+
saveDraftPayload(payload);
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
935
1108
|
var validationError = validatePayload(payload);
|
|
936
1109
|
if (validationError) {
|
|
937
1110
|
showError(validationError);
|
|
@@ -942,9 +1115,8 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
942
1115
|
|
|
943
1116
|
cancelButton.addEventListener('click', function () {
|
|
944
1117
|
if (sending) return;
|
|
945
|
-
//
|
|
946
|
-
|
|
947
|
-
var collapseMessage = outcomeUnknown
|
|
1118
|
+
// Hiding the notice does not resolve whether an earlier send went out.
|
|
1119
|
+
var collapseMessage = sendMayHaveGone
|
|
948
1120
|
? 'Collapsed. Check your Sent folder if you are not sure.'
|
|
949
1121
|
: 'Draft collapsed. Nothing sent.';
|
|
950
1122
|
clearError();
|
|
@@ -955,6 +1127,7 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
955
1127
|
|
|
956
1128
|
reopenButton.addEventListener('click', function () {
|
|
957
1129
|
setCollapsed(false);
|
|
1130
|
+
if (!sent && sendMayHaveGone) showSendUnknown();
|
|
958
1131
|
});
|
|
959
1132
|
|
|
960
1133
|
sentCollapseButton.addEventListener('click', function () {
|
|
@@ -973,9 +1146,9 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
973
1146
|
|
|
974
1147
|
[toInput, ccInput, bccInput, subjectInput, bodyInput].forEach(function (element) {
|
|
975
1148
|
element.addEventListener('input', function () {
|
|
976
|
-
clearError();
|
|
1149
|
+
if (!sendBlocked) clearError();
|
|
977
1150
|
clearSuccess();
|
|
978
|
-
clearUnknown();
|
|
1151
|
+
if (!sendMayHaveGone) clearUnknown();
|
|
979
1152
|
postResize();
|
|
980
1153
|
});
|
|
981
1154
|
});
|
|
@@ -999,6 +1172,11 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
999
1172
|
return;
|
|
1000
1173
|
}
|
|
1001
1174
|
|
|
1175
|
+
if (data.method === 'mcp-app:card-outcome') {
|
|
1176
|
+
if (event.source === window.parent) applyCardOutcome(data.params);
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1002
1180
|
if (data.method === 'ui/notifications/tool-result') {
|
|
1003
1181
|
// Always parse (so the migration-shim's malformed-envelope warning
|
|
1004
1182
|
// still fires), but apply only the first successful prefill: a stray
|
|
@@ -1012,32 +1190,72 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
1012
1190
|
return;
|
|
1013
1191
|
}
|
|
1014
1192
|
|
|
1015
|
-
if (data.jsonrpc !== '2.0'
|
|
1193
|
+
if (data.jsonrpc !== '2.0') return;
|
|
1194
|
+
var completedSendPayload = null;
|
|
1195
|
+
if (pendingSendRequestId && data.id === pendingSendRequestId) {
|
|
1196
|
+
completedSendPayload = pendingSendPayload;
|
|
1197
|
+
pendingSendPayload = null;
|
|
1198
|
+
pendingSendRequestId = null;
|
|
1199
|
+
}
|
|
1200
|
+
if (!pendingRequestId || data.id !== pendingRequestId) {
|
|
1016
1201
|
return;
|
|
1017
1202
|
}
|
|
1018
1203
|
|
|
1019
1204
|
pendingRequestId = null;
|
|
1020
1205
|
clearSendTimeout();
|
|
1021
1206
|
clearUnknown();
|
|
1022
|
-
|
|
1207
|
+
var completedAction = pendingAction;
|
|
1208
|
+
pendingAction = null;
|
|
1209
|
+
if (completedAction === 'draft') {
|
|
1210
|
+
setSavingDraft(false);
|
|
1211
|
+
} else {
|
|
1212
|
+
setSending(false);
|
|
1213
|
+
}
|
|
1023
1214
|
|
|
1024
1215
|
if (data.error) {
|
|
1025
1216
|
var errorMessage = data.error && typeof data.error.message === 'string'
|
|
1026
1217
|
? data.error.message
|
|
1027
|
-
: 'Failed to send email.';
|
|
1218
|
+
: (completedAction === 'draft' ? 'Failed to save draft.' : 'Failed to send email.');
|
|
1219
|
+
if (completedAction === 'draft') {
|
|
1220
|
+
// Retry re-invokes the draft tool, not the send tool — pendingAction
|
|
1221
|
+
// is already cleared, so this is what the Retry handler routes on.
|
|
1222
|
+
retryAction = 'draft';
|
|
1223
|
+
}
|
|
1224
|
+
var blockedReason = data.error.data && data.error.data.reason;
|
|
1225
|
+
var retryCannotChangeBlock = blockedReason === 'user-disabled' || blockedReason === 'admin-disabled' || blockedReason === 'security-policy';
|
|
1226
|
+
var blockedBeforeSend = retryCannotChangeBlock || blockedReason === 'not-dispatched';
|
|
1227
|
+
if (completedAction !== 'draft' && retryCannotChangeBlock) {
|
|
1228
|
+
sendBlocked = true;
|
|
1229
|
+
sendButton.disabled = true;
|
|
1230
|
+
}
|
|
1231
|
+
if (completedAction !== 'draft' && (!blockedBeforeSend || sendMayHaveGone)) {
|
|
1232
|
+
showSendUnknown();
|
|
1233
|
+
}
|
|
1028
1234
|
showError(errorMessage);
|
|
1029
1235
|
return;
|
|
1030
1236
|
}
|
|
1031
1237
|
|
|
1032
1238
|
clearError();
|
|
1033
1239
|
clearSuccess();
|
|
1034
|
-
|
|
1240
|
+
if (completedAction === 'draft') {
|
|
1241
|
+
// Terminal: the draft now lives in the mailbox's Drafts folder.
|
|
1242
|
+
// Collapse to a stamped confirmation and retire the form — Reopen
|
|
1243
|
+
// would resurrect an editable copy whose next Save/Send silently
|
|
1244
|
+
// diverges from (or duplicates) the saved draft.
|
|
1245
|
+
var draftStamp = formatSentTime(Date.now());
|
|
1246
|
+
setCollapsed(true, draftStamp ? 'Draft saved · ' + draftStamp : 'Draft saved.');
|
|
1247
|
+
reopenButton.classList.add('hidden');
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
// Preserve what was sent instead of discarding the draft. completedSendPayload
|
|
1035
1251
|
// is the exact payload we posted. We default to the collapsed summary, but
|
|
1036
1252
|
// Reopen now restores a read-only view of the sent message.
|
|
1037
|
-
var sentPayload =
|
|
1038
|
-
var stamp = formatSentTime();
|
|
1253
|
+
var sentPayload = completedSendPayload || readFormPayload();
|
|
1254
|
+
var stamp = formatSentTime(Date.now());
|
|
1039
1255
|
renderSentView(sentPayload, getSendMetaFromResult(data.result), stamp);
|
|
1040
1256
|
sent = true;
|
|
1257
|
+
sendMayHaveGone = false;
|
|
1258
|
+
reopenButton.classList.remove('hidden');
|
|
1041
1259
|
setCollapsed(true, stamp ? 'Email sent · ' + stamp : 'Email sent.');
|
|
1042
1260
|
});
|
|
1043
1261
|
|
|
@@ -1049,7 +1267,9 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
1049
1267
|
applyThemeFromHostContext();
|
|
1050
1268
|
setCcVisible(false);
|
|
1051
1269
|
setBccVisible(false);
|
|
1052
|
-
|
|
1270
|
+
var hostOutcome = (window.__MCP_HOST_CONTEXT__ || {}).cardOutcome;
|
|
1271
|
+
if (hostOutcome) applyCardOutcome(hostOutcome);
|
|
1272
|
+
else setCollapsed(false);
|
|
1053
1273
|
postResize();
|
|
1054
1274
|
postReady();
|
|
1055
1275
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindstone/mcp-server-microsoft-mail",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"mcpName": "io.github.mindstone/mcp-server-microsoft-mail",
|
|
5
5
|
"description": "Microsoft 365 Outlook mail via Graph: read, search, send, reply, forward, draft, move, delete.",
|
|
6
6
|
"license": "FSL-1.1-MIT",
|
package/server.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "io.github.mindstone/mcp-server-microsoft-mail",
|
|
4
4
|
"title": "Microsoft 365 Mail",
|
|
5
5
|
"description": "Microsoft 365 Outlook mail via Graph: read, search, send, reply, forward, draft, move, delete.",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.4.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"url": "https://github.com/mindstone/mcp-servers",
|
|
9
9
|
"source": "github",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"registryType": "npm",
|
|
15
15
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
16
16
|
"identifier": "@mindstone/mcp-server-microsoft-mail",
|
|
17
|
-
"version": "0.
|
|
17
|
+
"version": "0.4.0",
|
|
18
18
|
"runtimeHint": "npx",
|
|
19
19
|
"transport": {
|
|
20
20
|
"type": "stdio"
|