@mindstone/mcp-server-google-workspace 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/resources/compose-email-template.d.ts +1 -1
- package/dist/resources/compose-email-template.js +151 -4
- package/dist/tools/definitions/gmail.js +4 -2
- package/dist/utils/atomicCredentialWrite.d.ts +1 -1
- package/dist/utils/atomicCredentialWrite.js +17 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Google Workspace MCP server — Gmail, Calendar, Drive, Docs, Sheets, Slides, Co
|
|
|
8
8
|
|
|
9
9
|
## Status
|
|
10
10
|
|
|
11
|
-
- **Version:** [0.1.
|
|
11
|
+
- **Version:** [0.1.5](./CHANGELOG.md) · npm: not yet published
|
|
12
12
|
- **Auth:** OAuth (host-orchestrated) ([`GOOGLE_CLIENT_SECRET`](./server.json))
|
|
13
13
|
- **Tools:** [94](./src/tools/definitions/) (Gmail, Calendar, Drive, Docs, Sheets, Slides, Contacts, Comments, Account; +10 gated Tasks/Forms behind `ENABLE_GOOGLE_TASKS_FORMS=true`)
|
|
14
14
|
- **Surface:** cloud-api
|
|
@@ -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 }\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 }\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 }\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 .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 .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 </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>\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\">Add CC</button>\n <button id=\"toggleBccButton\" type=\"button\" class=\"link-button\">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\">\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\"></div>\n\n <div class=\"actions\">\n <button id=\"cancelButton\" type=\"button\" class=\"button button-secondary\">Cancel</button>\n <button id=\"sendButton\" type=\"submit\" 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 </div>\n\n <script>\n (function () {\n 'use strict';\n\n var RESOURCE_URI = 'ui://google-workspace/compose-email';\n var currentEmail = '';\n var pendingRequestId = null;\n var pendingPayload = null;\n var sending = false;\n var collapsed = false;\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 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 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\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 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 function setCollapsed(nextCollapsed, message) {\n collapsed = nextCollapsed;\n composeForm.classList.toggle('hidden', collapsed);\n collapsedState.classList.toggle('hidden', !collapsed);\n if (message) {\n collapsedMessage.textContent = message;\n } else {\n collapsedMessage.textContent = collapsed ? 'Draft collapsed.' : '';\n }\n postResize();\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 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 setCcVisible(visible) {\n ccRow.classList.toggle('hidden', !visible);\n toggleCcButton.textContent = visible ? 'Hide CC' : 'Add CC';\n }\n\n function setBccVisible(visible) {\n bccRow.classList.toggle('hidden', !visible);\n toggleBccButton.textContent = visible ? 'Hide BCC' : 'Add BCC';\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\n window.parent.postMessage(\n {\n jsonrpc: '2.0',\n method: 'tools/call',\n params: {\n name: 'send_workspace_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 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 composeForm.addEventListener('submit', function (event) {\n event.preventDefault();\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 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 clearError();\n clearSuccess();\n setCollapsed(true, 'Draft collapsed. Nothing sent.');\n });\n\n reopenButton.addEventListener('click', function () {\n setCollapsed(false);\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 postResize();\n });\n });\n\n window.addEventListener('message', function (event) {\n var data = event.data;\n if (!data || typeof data !== 'object') {\n return;\n }\n\n if (data.method === 'ui/notifications/tool-result') {\n var draft = getDraftFromToolResult(data.params);\n if (draft) {\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 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 showSuccess('Email sent successfully.');\n setCollapsed(true, 'Email sent.');\n reopenButton.classList.add('hidden');\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 }\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 </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>\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\">Add CC</button>\n <button id=\"toggleBccButton\" type=\"button\" class=\"link-button\">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\">\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\"></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 </div>\n\n <script>\n (function () {\n 'use strict';\n\n var RESOURCE_URI = 'ui://google-workspace/compose-email';\n var currentEmail = '';\n var pendingRequestId = null;\n var pendingPayload = null;\n var sending = false;\n var collapsed = false;\n var outcomeUnknown = 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 (REBEL-677), 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 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 function setCollapsed(nextCollapsed, message) {\n collapsed = nextCollapsed;\n composeForm.classList.toggle('hidden', collapsed);\n collapsedState.classList.toggle('hidden', !collapsed);\n if (message) {\n collapsedMessage.textContent = message;\n } else {\n collapsedMessage.textContent = collapsed ? 'Draft collapsed.' : '';\n }\n postResize();\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 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). REBEL-677 / FOX-3484.\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 }\n\n function setBccVisible(visible) {\n bccRow.classList.toggle('hidden', !visible);\n toggleBccButton.textContent = visible ? 'Hide BCC' : 'Add BCC';\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_workspace_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 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 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 var data = event.data;\n if (!data || typeof data !== 'object') {\n return;\n }\n\n if (data.method === 'ui/notifications/tool-result') {\n var draft = getDraftFromToolResult(data.params);\n if (draft) {\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 showSuccess('Email sent successfully.');\n setCollapsed(true, 'Email sent.');\n reopenButton.classList.add('hidden');\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";
|
|
2
2
|
//# sourceMappingURL=compose-email-template.d.ts.map
|
|
@@ -26,6 +26,9 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
26
26
|
--success-bg: #ecfdf5;
|
|
27
27
|
--success-border: #bbf7d0;
|
|
28
28
|
--success-text: #166534;
|
|
29
|
+
--warning-bg: #fffbeb;
|
|
30
|
+
--warning-border: #fde68a;
|
|
31
|
+
--warning-text: #92400e;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
@media (prefers-color-scheme: dark) {
|
|
@@ -48,6 +51,9 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
48
51
|
--success-bg: #052e1b;
|
|
49
52
|
--success-border: #166534;
|
|
50
53
|
--success-text: #86efac;
|
|
54
|
+
--warning-bg: #2a2106;
|
|
55
|
+
--warning-border: #854d0e;
|
|
56
|
+
--warning-text: #fcd34d;
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
|
|
@@ -75,6 +81,9 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
75
81
|
--success-bg: #052e1b;
|
|
76
82
|
--success-border: #166534;
|
|
77
83
|
--success-text: #86efac;
|
|
84
|
+
--warning-bg: #2a2106;
|
|
85
|
+
--warning-border: #854d0e;
|
|
86
|
+
--warning-text: #fcd34d;
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
* {
|
|
@@ -120,6 +129,19 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
120
129
|
letter-spacing: 0.04em;
|
|
121
130
|
}
|
|
122
131
|
|
|
132
|
+
.from-value {
|
|
133
|
+
color: var(--text);
|
|
134
|
+
font-size: 14px;
|
|
135
|
+
padding: 2px 0;
|
|
136
|
+
word-break: break-word;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.from-helper {
|
|
140
|
+
font-size: 12px;
|
|
141
|
+
color: var(--muted);
|
|
142
|
+
margin-top: 2px;
|
|
143
|
+
}
|
|
144
|
+
|
|
123
145
|
.input,
|
|
124
146
|
.textarea {
|
|
125
147
|
width: 100%;
|
|
@@ -246,6 +268,22 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
246
268
|
color: var(--success-text);
|
|
247
269
|
}
|
|
248
270
|
|
|
271
|
+
.warning {
|
|
272
|
+
background: var(--warning-bg);
|
|
273
|
+
border-color: var(--warning-border);
|
|
274
|
+
color: var(--warning-text);
|
|
275
|
+
display: block;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.warning strong {
|
|
279
|
+
display: block;
|
|
280
|
+
margin-bottom: 2px;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.warning .warning-detail {
|
|
284
|
+
opacity: 0.85;
|
|
285
|
+
}
|
|
286
|
+
|
|
249
287
|
.collapsed {
|
|
250
288
|
border: 1px solid var(--border);
|
|
251
289
|
border-radius: 10px;
|
|
@@ -271,6 +309,12 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
271
309
|
</div>
|
|
272
310
|
|
|
273
311
|
<form id="composeForm" class="card" novalidate>
|
|
312
|
+
<div class="field from-field">
|
|
313
|
+
<label>From</label>
|
|
314
|
+
<span id="fromValue" class="from-value"></span>
|
|
315
|
+
<span id="fromHelper" class="from-helper hidden"></span>
|
|
316
|
+
</div>
|
|
317
|
+
|
|
274
318
|
<div class="field">
|
|
275
319
|
<label for="toInput">To</label>
|
|
276
320
|
<input id="toInput" class="input" type="text" autocomplete="off" placeholder="name@example.com, team@example.com">
|
|
@@ -308,9 +352,14 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
308
352
|
|
|
309
353
|
<div id="successBox" class="status success hidden"></div>
|
|
310
354
|
|
|
355
|
+
<div id="unknownBox" class="status warning hidden" role="status" aria-live="polite">
|
|
356
|
+
<strong id="unknownTitle"></strong>
|
|
357
|
+
<span id="unknownText" class="warning-detail"></span>
|
|
358
|
+
</div>
|
|
359
|
+
|
|
311
360
|
<div class="actions">
|
|
312
361
|
<button id="cancelButton" type="button" class="button button-secondary">Cancel</button>
|
|
313
|
-
<button id="sendButton" type="
|
|
362
|
+
<button id="sendButton" type="button" class="button button-primary">
|
|
314
363
|
<span id="sendSpinner" class="spinner hidden" aria-hidden="true"></span>
|
|
315
364
|
<span id="sendLabel">Send email</span>
|
|
316
365
|
</button>
|
|
@@ -328,6 +377,12 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
328
377
|
var pendingPayload = null;
|
|
329
378
|
var sending = false;
|
|
330
379
|
var collapsed = false;
|
|
380
|
+
var outcomeUnknown = false;
|
|
381
|
+
var sendTimeoutId = null;
|
|
382
|
+
// Just beyond the host-side tool-call timeout (60s) so a legitimately slow
|
|
383
|
+
// send resolves to its real result first; this only fires when the reply
|
|
384
|
+
// is genuinely lost (REBEL-677), so the button can never stay stuck-silent.
|
|
385
|
+
var SEND_TIMEOUT_MS = 75000;
|
|
331
386
|
|
|
332
387
|
var composeForm = document.getElementById('composeForm');
|
|
333
388
|
var collapsedState = document.getElementById('collapsedState');
|
|
@@ -339,6 +394,8 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
339
394
|
var bccInput = document.getElementById('bccInput');
|
|
340
395
|
var subjectInput = document.getElementById('subjectInput');
|
|
341
396
|
var bodyInput = document.getElementById('bodyInput');
|
|
397
|
+
var fromValue = document.getElementById('fromValue');
|
|
398
|
+
var fromHelper = document.getElementById('fromHelper');
|
|
342
399
|
var ccRow = document.getElementById('ccRow');
|
|
343
400
|
var bccRow = document.getElementById('bccRow');
|
|
344
401
|
var toggleCcButton = document.getElementById('toggleCcButton');
|
|
@@ -353,6 +410,9 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
353
410
|
var errorBox = document.getElementById('errorBox');
|
|
354
411
|
var errorText = document.getElementById('errorText');
|
|
355
412
|
var successBox = document.getElementById('successBox');
|
|
413
|
+
var unknownBox = document.getElementById('unknownBox');
|
|
414
|
+
var unknownTitle = document.getElementById('unknownTitle');
|
|
415
|
+
var unknownText = document.getElementById('unknownText');
|
|
356
416
|
|
|
357
417
|
function applyThemeFromHostContext() {
|
|
358
418
|
try {
|
|
@@ -370,6 +430,21 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
370
430
|
return String(value || '').trim();
|
|
371
431
|
}
|
|
372
432
|
|
|
433
|
+
function applyFromValue(email) {
|
|
434
|
+
var trimmed = trimString(email);
|
|
435
|
+
if (trimmed) {
|
|
436
|
+
fromValue.textContent = trimmed;
|
|
437
|
+
fromValue.style.color = '';
|
|
438
|
+
fromHelper.textContent = '';
|
|
439
|
+
fromHelper.classList.add('hidden');
|
|
440
|
+
} else {
|
|
441
|
+
fromValue.textContent = 'Account not shown';
|
|
442
|
+
fromValue.style.color = 'var(--muted)';
|
|
443
|
+
fromHelper.textContent = 'Rebel could not confirm the sending account. Cancel and ask Rebel to recreate the draft before sending.';
|
|
444
|
+
fromHelper.classList.remove('hidden');
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
373
448
|
function formatAddressItem(item) {
|
|
374
449
|
if (item && typeof item === 'object') {
|
|
375
450
|
var email = trimString(item.email || item.address || item.value);
|
|
@@ -474,6 +549,45 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
474
549
|
postResize();
|
|
475
550
|
}
|
|
476
551
|
|
|
552
|
+
function clearSendTimeout() {
|
|
553
|
+
if (sendTimeoutId !== null) {
|
|
554
|
+
clearTimeout(sendTimeoutId);
|
|
555
|
+
sendTimeoutId = null;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function clearUnknown() {
|
|
560
|
+
outcomeUnknown = false;
|
|
561
|
+
unknownTitle.textContent = '';
|
|
562
|
+
unknownText.textContent = '';
|
|
563
|
+
unknownBox.classList.add('hidden');
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// No reply ever came back for the send (e.g. the host's response was lost
|
|
567
|
+
// before reaching this iframe). We genuinely don't know whether the email
|
|
568
|
+
// went out, so we must NOT claim success or failure: re-enable the form and
|
|
569
|
+
// tell the user to verify before resending (the send is not idempotent, so
|
|
570
|
+
// a blind retry could send a duplicate). REBEL-677 / FOX-3484.
|
|
571
|
+
function showSendUnknown() {
|
|
572
|
+
outcomeUnknown = true;
|
|
573
|
+
clearError();
|
|
574
|
+
clearSuccess();
|
|
575
|
+
unknownTitle.textContent = 'Not sure if this sent.';
|
|
576
|
+
unknownText.textContent = "Rebel didn't hear back in time. Check your Sent folder before sending again, so it doesn't go out twice.";
|
|
577
|
+
unknownBox.classList.remove('hidden');
|
|
578
|
+
postResize();
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function handleSendTimeout() {
|
|
582
|
+
sendTimeoutId = null;
|
|
583
|
+
if (!pendingRequestId) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
pendingRequestId = null;
|
|
587
|
+
setSending(false);
|
|
588
|
+
showSendUnknown();
|
|
589
|
+
}
|
|
590
|
+
|
|
477
591
|
function setCcVisible(visible) {
|
|
478
592
|
ccRow.classList.toggle('hidden', !visible);
|
|
479
593
|
toggleCcButton.textContent = visible ? 'Hide CC' : 'Add CC';
|
|
@@ -517,6 +631,9 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
517
631
|
setSending(true);
|
|
518
632
|
clearError();
|
|
519
633
|
clearSuccess();
|
|
634
|
+
clearUnknown();
|
|
635
|
+
clearSendTimeout();
|
|
636
|
+
sendTimeoutId = setTimeout(handleSendTimeout, SEND_TIMEOUT_MS);
|
|
520
637
|
|
|
521
638
|
window.parent.postMessage(
|
|
522
639
|
{
|
|
@@ -540,6 +657,7 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
540
657
|
subjectInput.value = typeof draft.subject === 'string' ? draft.subject : '';
|
|
541
658
|
bodyInput.value = typeof draft.body === 'string' ? draft.body : '';
|
|
542
659
|
currentEmail = typeof draft.email === 'string' ? draft.email : '';
|
|
660
|
+
applyFromValue(currentEmail);
|
|
543
661
|
setCcVisible(normalizeAddressList(draft.cc).length > 0);
|
|
544
662
|
setBccVisible(normalizeAddressList(draft.bcc).length > 0);
|
|
545
663
|
clearError();
|
|
@@ -593,8 +711,7 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
593
711
|
return null;
|
|
594
712
|
}
|
|
595
713
|
|
|
596
|
-
|
|
597
|
-
event.preventDefault();
|
|
714
|
+
function handleSendRequest() {
|
|
598
715
|
if (sending) return;
|
|
599
716
|
|
|
600
717
|
var payload = readFormPayload();
|
|
@@ -605,6 +722,27 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
605
722
|
}
|
|
606
723
|
|
|
607
724
|
sendPayload(payload);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// The Send button is type="button" with an explicit click handler rather
|
|
728
|
+
// than a form submit button. The Rebel host renders this iframe with a
|
|
729
|
+
// sandbox of "allow-scripts" only — no "allow-forms" — so native form
|
|
730
|
+
// submission is blocked by the browser BEFORE the submit event fires
|
|
731
|
+
// ("Blocked form submission ... the form's frame is sandboxed and the
|
|
732
|
+
// allow-forms permission is not set"). A submit-driven Send therefore
|
|
733
|
+
// silently did nothing: no postMessage, no spinner, no telemetry.
|
|
734
|
+
// A click handler needs no sandbox permission and is the same path
|
|
735
|
+
// Cancel/Retry already use. The submit listener below stays only as a
|
|
736
|
+
// defensive fallback for hosts that DO grant allow-forms; in this sandbox
|
|
737
|
+
// it never fires (neither the button click nor Enter routes through it).
|
|
738
|
+
// The sending guard keeps any double-fire (in an allow-forms host) a no-op.
|
|
739
|
+
sendButton.addEventListener('click', function () {
|
|
740
|
+
handleSendRequest();
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
composeForm.addEventListener('submit', function (event) {
|
|
744
|
+
event.preventDefault();
|
|
745
|
+
handleSendRequest();
|
|
608
746
|
});
|
|
609
747
|
|
|
610
748
|
retryButton.addEventListener('click', function () {
|
|
@@ -620,9 +758,15 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
620
758
|
|
|
621
759
|
cancelButton.addEventListener('click', function () {
|
|
622
760
|
if (sending) return;
|
|
761
|
+
// After a lost-reply timeout we don't know if the email sent, so don't
|
|
762
|
+
// claim "Nothing sent." on collapse — point the user to verify instead.
|
|
763
|
+
var collapseMessage = outcomeUnknown
|
|
764
|
+
? 'Collapsed. Check your Sent folder if you are not sure.'
|
|
765
|
+
: 'Draft collapsed. Nothing sent.';
|
|
623
766
|
clearError();
|
|
624
767
|
clearSuccess();
|
|
625
|
-
|
|
768
|
+
clearUnknown();
|
|
769
|
+
setCollapsed(true, collapseMessage);
|
|
626
770
|
});
|
|
627
771
|
|
|
628
772
|
reopenButton.addEventListener('click', function () {
|
|
@@ -643,6 +787,7 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
643
787
|
element.addEventListener('input', function () {
|
|
644
788
|
clearError();
|
|
645
789
|
clearSuccess();
|
|
790
|
+
clearUnknown();
|
|
646
791
|
postResize();
|
|
647
792
|
});
|
|
648
793
|
});
|
|
@@ -666,6 +811,8 @@ export const COMPOSE_EMAIL_HTML = `
|
|
|
666
811
|
}
|
|
667
812
|
|
|
668
813
|
pendingRequestId = null;
|
|
814
|
+
clearSendTimeout();
|
|
815
|
+
clearUnknown();
|
|
669
816
|
setSending(false);
|
|
670
817
|
|
|
671
818
|
if (data.error) {
|
|
@@ -364,7 +364,9 @@ Use get_workspace_email_thread with a thread_id from results to get full convers
|
|
|
364
364
|
category: 'Gmail/Messages',
|
|
365
365
|
description: `Open an inline editable email compose form before sending.
|
|
366
366
|
|
|
367
|
-
Use this when
|
|
367
|
+
Use this when the user wants an editable review form in Rebel before sending. The form lets the user edit To, CC, BCC, Subject, and Body, then explicitly click Send.
|
|
368
|
+
|
|
369
|
+
Do NOT use this when the user asks to save/create a Gmail draft, save to drafts, or save the already-drafted email without opening another review UI. Use create_workspace_draft for that.
|
|
368
370
|
|
|
369
371
|
This tool does not send the email directly. It prepares the draft and launches the inline form.`,
|
|
370
372
|
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
@@ -746,7 +748,7 @@ Attachments are NOT automatically carried over — you must explicitly download
|
|
|
746
748
|
{
|
|
747
749
|
name: 'create_workspace_draft',
|
|
748
750
|
category: 'Gmail/Drafts',
|
|
749
|
-
description: `Create a new Gmail draft. Supports plain text and HTML bodies, CC/BCC, reply threading, and attachments.`,
|
|
751
|
+
description: `Create a new Gmail draft. Use this when the user asks to save to drafts, save/create a Gmail draft, or save an already-drafted email without sending or opening another review UI. Supports plain text and HTML bodies, CC/BCC, reply threading, and attachments.`,
|
|
750
752
|
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
751
753
|
inputSchema: {
|
|
752
754
|
type: 'object',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function atomicCredentialWrite(filePath: string, data: string, opts?: {
|
|
1
|
+
export declare function atomicCredentialWrite(filePath: string, data: string | Buffer, opts?: {
|
|
2
2
|
mode?: number;
|
|
3
3
|
}): Promise<void>;
|
|
4
4
|
export declare function sweepStaleTemps(dir: string): Promise<void>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// vendored from upstream commit 4fcf6bcf2cc8170e656dc4e9a7f362116b9025c9
|
|
2
|
+
// keep byte-equivalent (modulo import path); see check-atomic-helper-equivalence.ts
|
|
1
3
|
import crypto from 'node:crypto';
|
|
2
4
|
import fs from 'node:fs';
|
|
3
5
|
import path from 'node:path';
|
|
@@ -6,12 +8,22 @@ const CREDENTIAL_FILE_MODE = 0o600;
|
|
|
6
8
|
const CREDENTIAL_DIR_MODE = 0o700;
|
|
7
9
|
const STALE_TEMP_MAX_AGE_MS = 5 * 60 * 1000;
|
|
8
10
|
function getSafeTempOpenFlags() {
|
|
11
|
+
// Use exclusive create (`wx`) so pre-existing temp paths fail closed.
|
|
12
|
+
// When available, add O_NOFOLLOW to refuse symlink traversal outright.
|
|
9
13
|
if (process.platform !== 'win32' && typeof fs.constants.O_NOFOLLOW === 'number') {
|
|
10
14
|
return fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_NOFOLLOW;
|
|
11
15
|
}
|
|
12
16
|
return 'wx';
|
|
13
17
|
}
|
|
14
18
|
function assertTargetIsNotSymlink(filePath) {
|
|
19
|
+
// Policy guard, NOT a race-free primitive: this lstat is TOCTOU-racy by design
|
|
20
|
+
// (an attacker who controls the parent directory can swap the entry between this
|
|
21
|
+
// check and the later rename). It exists to fail loud — and give a clear error —
|
|
22
|
+
// when a pre-existing credential path is already a symlink. The real write-through
|
|
23
|
+
// protection is the exclusive-create temp open (wx/O_EXCL + O_NOFOLLOW where
|
|
24
|
+
// available) plus rename(), which replaces the destination entry rather than
|
|
25
|
+
// following a symlink. See check-atomic-helper-equivalence.ts: this guard is part
|
|
26
|
+
// of the byte-equivalent contract across host + OSS copies.
|
|
15
27
|
try {
|
|
16
28
|
const stats = withSingleSyncRetryOnEmfile(() => fs.lstatSync(filePath));
|
|
17
29
|
if (stats.isSymbolicLink()) {
|
|
@@ -29,6 +41,7 @@ function assertTargetIsNotSymlink(filePath) {
|
|
|
29
41
|
}
|
|
30
42
|
function fsyncParentDirectory(dirPath) {
|
|
31
43
|
if (process.platform === 'win32') {
|
|
44
|
+
// Windows does not support fsync on directory file descriptors in a portable way.
|
|
32
45
|
return;
|
|
33
46
|
}
|
|
34
47
|
let dirFd;
|
|
@@ -64,10 +77,13 @@ export async function atomicCredentialWrite(filePath, data, opts) {
|
|
|
64
77
|
assertTargetIsNotSymlink(filePath);
|
|
65
78
|
const openedFileDescriptor = withSingleSyncRetryOnEmfile(() => fs.openSync(tempPath, getSafeTempOpenFlags(), fileMode));
|
|
66
79
|
fileDescriptor = openedFileDescriptor;
|
|
67
|
-
withSingleSyncRetryOnEmfile(() =>
|
|
80
|
+
withSingleSyncRetryOnEmfile(() => typeof data === 'string'
|
|
81
|
+
? fs.writeFileSync(openedFileDescriptor, data, { encoding: 'utf8' })
|
|
82
|
+
: fs.writeFileSync(openedFileDescriptor, data));
|
|
68
83
|
withSingleSyncRetryOnEmfile(() => fs.fsyncSync(openedFileDescriptor));
|
|
69
84
|
withSingleSyncRetryOnEmfile(() => fs.closeSync(openedFileDescriptor));
|
|
70
85
|
fileDescriptor = undefined;
|
|
86
|
+
withSingleSyncRetryOnEmfile(() => fs.chmodSync(tempPath, CREDENTIAL_FILE_MODE));
|
|
71
87
|
withSingleSyncRetryOnEmfile(() => fs.renameSync(tempPath, filePath));
|
|
72
88
|
withSingleSyncRetryOnEmfile(() => fs.chmodSync(filePath, CREDENTIAL_FILE_MODE));
|
|
73
89
|
fsyncParentDirectory(parentDir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindstone/mcp-server-google-workspace",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"mcpName": "io.github.mindstone/mcp-server-google-workspace",
|
|
5
5
|
"description": "Google Workspace MCP server for Gmail, Calendar, Drive, Docs, Sheets, Slides, Contacts, Tasks, and Forms",
|
|
6
6
|
"license": "FSL-1.1-MIT",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"@types/node": "^22",
|
|
50
50
|
"@types/uuid": "^10.0.0",
|
|
51
51
|
"@vitest/coverage-v8": "^4.1.3",
|
|
52
|
+
"happy-dom": "^20.8.9",
|
|
52
53
|
"msw": "^2.13.2",
|
|
53
54
|
"shx": "^0.3.4",
|
|
54
55
|
"typescript": "^5.8.2",
|