google-mcp-suite 1.19.0 → 1.20.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/dist/gmail/entities/AttachmentFile.d.ts +17 -0
- package/dist/gmail/entities/AttachmentFile.d.ts.map +1 -0
- package/dist/gmail/entities/AttachmentFile.js +33 -0
- package/dist/gmail/entities/AttachmentFile.js.map +1 -0
- package/dist/gmail/instructions.d.ts.map +1 -1
- package/dist/gmail/instructions.js +4 -1
- package/dist/gmail/instructions.js.map +1 -1
- package/dist/gmail/lib/attachment.d.ts +36 -0
- package/dist/gmail/lib/attachment.d.ts.map +1 -0
- package/dist/gmail/lib/attachment.js +112 -0
- package/dist/gmail/lib/attachment.js.map +1 -0
- package/dist/gmail/lib/headers.d.ts +7 -0
- package/dist/gmail/lib/headers.d.ts.map +1 -1
- package/dist/gmail/lib/headers.js +9 -0
- package/dist/gmail/lib/headers.js.map +1 -1
- package/dist/gmail/lib/message.d.ts +2 -0
- package/dist/gmail/lib/message.d.ts.map +1 -1
- package/dist/gmail/lib/message.js +13 -1
- package/dist/gmail/lib/message.js.map +1 -1
- package/dist/gmail/methods/registry.d.ts +10 -0
- package/dist/gmail/methods/registry.d.ts.map +1 -1
- package/dist/gmail/methods/send_message/handler.d.ts.map +1 -1
- package/dist/gmail/methods/send_message/handler.js +2 -0
- package/dist/gmail/methods/send_message/handler.js.map +1 -1
- package/dist/gmail/methods/send_message/index.d.ts +7 -1
- package/dist/gmail/methods/send_message/index.d.ts.map +1 -1
- package/dist/gmail/methods/send_message/index.js +3 -2
- package/dist/gmail/methods/send_message/index.js.map +1 -1
- package/dist/gmail/methods/send_message/schema.d.ts +5 -0
- package/dist/gmail/methods/send_message/schema.d.ts.map +1 -1
- package/dist/gmail/methods/send_message/schema.js +3 -0
- package/dist/gmail/methods/send_message/schema.js.map +1 -1
- package/dist/gmail/methods/update_draft/handler.d.ts.map +1 -1
- package/dist/gmail/methods/update_draft/handler.js +2 -0
- package/dist/gmail/methods/update_draft/handler.js.map +1 -1
- package/dist/gmail/methods/update_draft/index.d.ts +7 -1
- package/dist/gmail/methods/update_draft/index.d.ts.map +1 -1
- package/dist/gmail/methods/update_draft/index.js +3 -2
- package/dist/gmail/methods/update_draft/index.js.map +1 -1
- package/dist/gmail/methods/update_draft/schema.d.ts +5 -0
- package/dist/gmail/methods/update_draft/schema.d.ts.map +1 -1
- package/dist/gmail/methods/update_draft/schema.js +3 -0
- package/dist/gmail/methods/update_draft/schema.js.map +1 -1
- package/dist/gmail/tools/create_draft/handler.d.ts.map +1 -1
- package/dist/gmail/tools/create_draft/handler.js +2 -0
- package/dist/gmail/tools/create_draft/handler.js.map +1 -1
- package/dist/gmail/tools/create_draft/index.d.ts +8 -1
- package/dist/gmail/tools/create_draft/index.d.ts.map +1 -1
- package/dist/gmail/tools/create_draft/index.js +4 -2
- package/dist/gmail/tools/create_draft/index.js.map +1 -1
- package/dist/gmail/tools/create_draft/schema.d.ts +5 -0
- package/dist/gmail/tools/create_draft/schema.d.ts.map +1 -1
- package/dist/gmail/tools/create_draft/schema.js +3 -0
- package/dist/gmail/tools/create_draft/schema.js.map +1 -1
- package/dist/gmail/tools/registry.d.ts +5 -0
- package/dist/gmail/tools/registry.d.ts.map +1 -1
- package/dist/lib/limits.d.ts +7 -4
- package/dist/lib/limits.d.ts.map +1 -1
- package/dist/lib/limits.js +7 -5
- package/dist/lib/limits.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* A local file to attach to an outgoing message. A suite extension, not a
|
|
4
|
+
* Google noun: the Gmail API's compose surface takes attachments only inside
|
|
5
|
+
* the documented `raw` RFC 822 field (a documented API field, not a
|
|
6
|
+
* workaround), so the compose operations (`create_draft`, `update_draft`,
|
|
7
|
+
* `send_message`) accept this shape and the server assembles the MIME message
|
|
8
|
+
* itself (issue #101 is the provenance).
|
|
9
|
+
* @see https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages#Message
|
|
10
|
+
*/
|
|
11
|
+
export declare const AttachmentFile: z.ZodObject<{
|
|
12
|
+
path: z.ZodString;
|
|
13
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
14
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
export type AttachmentFile = z.infer<typeof AttachmentFile>;
|
|
17
|
+
//# sourceMappingURL=AttachmentFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttachmentFile.d.ts","sourceRoot":"","sources":["../../../src/gmail/entities/AttachmentFile.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc;;;;kBAyBzB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isAbsolute } from 'node:path';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { headerSafe } from '../lib/headers.js';
|
|
4
|
+
/**
|
|
5
|
+
* A local file to attach to an outgoing message. A suite extension, not a
|
|
6
|
+
* Google noun: the Gmail API's compose surface takes attachments only inside
|
|
7
|
+
* the documented `raw` RFC 822 field (a documented API field, not a
|
|
8
|
+
* workaround), so the compose operations (`create_draft`, `update_draft`,
|
|
9
|
+
* `send_message`) accept this shape and the server assembles the MIME message
|
|
10
|
+
* itself (issue #101 is the provenance).
|
|
11
|
+
* @see https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages#Message
|
|
12
|
+
*/
|
|
13
|
+
export const AttachmentFile = z.strictObject({
|
|
14
|
+
path: z
|
|
15
|
+
.string()
|
|
16
|
+
.min(1)
|
|
17
|
+
.refine(isAbsolute, 'must be an absolute path')
|
|
18
|
+
.describe('Absolute filesystem path, as this server process sees it, of the file to attach. ' +
|
|
19
|
+
'The server reads the bytes when the message is assembled.'),
|
|
20
|
+
filename: headerSafe
|
|
21
|
+
.min(1)
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('Filename shown to the recipient. Defaults to the basename of `path`. ' +
|
|
24
|
+
'Double quotes and backslashes are stripped for header safety.'),
|
|
25
|
+
mimeType: headerSafe
|
|
26
|
+
.min(1)
|
|
27
|
+
.regex(/^[\w.+-]+\/[\w.+-]+$/, 'must be a type/subtype MIME type, without parameters')
|
|
28
|
+
.optional()
|
|
29
|
+
.describe('MIME type of the file, as a bare type/subtype token. Defaults to a type inferred ' +
|
|
30
|
+
"from the path's file extension, or application/octet-stream when the extension " +
|
|
31
|
+
'is unrecognized.'),
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=AttachmentFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttachmentFile.js","sourceRoot":"","sources":["../../../src/gmail/entities/AttachmentFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,YAAY,CAAC;IAC3C,IAAI,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,MAAM,CAAC,UAAU,EAAE,0BAA0B,CAAC;SAC9C,QAAQ,CACP,mFAAmF;QACjF,2DAA2D,CAC9D;IACH,QAAQ,EAAE,UAAU;SACjB,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,EAAE;SACV,QAAQ,CACP,uEAAuE;QACrE,+DAA+D,CAClE;IACH,QAAQ,EAAE,UAAU;SACjB,GAAG,CAAC,CAAC,CAAC;SACN,KAAK,CAAC,sBAAsB,EAAE,sDAAsD,CAAC;SACrF,QAAQ,EAAE;SACV,QAAQ,CACP,mFAAmF;QACjF,iFAAiF;QACjF,kBAAkB,CACrB;CACJ,CAAC,CAAC","sourcesContent":["import { isAbsolute } from 'node:path';\nimport { z } from 'zod';\nimport { headerSafe } from '../lib/headers.js';\n\n/**\n * A local file to attach to an outgoing message. A suite extension, not a\n * Google noun: the Gmail API's compose surface takes attachments only inside\n * the documented `raw` RFC 822 field (a documented API field, not a\n * workaround), so the compose operations (`create_draft`, `update_draft`,\n * `send_message`) accept this shape and the server assembles the MIME message\n * itself (issue #101 is the provenance).\n * @see https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages#Message\n */\nexport const AttachmentFile = z.strictObject({\n path: z\n .string()\n .min(1)\n .refine(isAbsolute, 'must be an absolute path')\n .describe(\n 'Absolute filesystem path, as this server process sees it, of the file to attach. ' +\n 'The server reads the bytes when the message is assembled.',\n ),\n filename: headerSafe\n .min(1)\n .optional()\n .describe(\n 'Filename shown to the recipient. Defaults to the basename of `path`. ' +\n 'Double quotes and backslashes are stripped for header safety.',\n ),\n mimeType: headerSafe\n .min(1)\n .regex(/^[\\w.+-]+\\/[\\w.+-]+$/, 'must be a type/subtype MIME type, without parameters')\n .optional()\n .describe(\n 'MIME type of the file, as a bare type/subtype token. Defaults to a type inferred ' +\n \"from the path's file extension, or application/octet-stream when the extension \" +\n 'is unrecognized.',\n ),\n});\nexport type AttachmentFile = z.infer<typeof AttachmentFile>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/gmail/instructions.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/gmail/instructions.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,YAAY,QAWuC,CAAC"}
|
|
@@ -11,5 +11,8 @@ export const instructions = identityInstructions('Gmail account') +
|
|
|
11
11
|
'permanent deletes bypass the trash entirely (trash_* and untrash_* are ' +
|
|
12
12
|
'the reversible pair, and Gmail purges trashed mail after about 30 days); ' +
|
|
13
13
|
'create_filter installs a standing rule that keeps acting on future mail. ' +
|
|
14
|
-
'Attachment bytes are returned base64url-encoded in JSON.'
|
|
14
|
+
'Attachment bytes are returned base64url-encoded in JSON. ' +
|
|
15
|
+
'To attach files, pass the attachments parameter of create_draft, ' +
|
|
16
|
+
'update_draft, or send_message: each entry names a local file path this ' +
|
|
17
|
+
'server process reads when it assembles the outgoing message.';
|
|
15
18
|
//# sourceMappingURL=instructions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/gmail/instructions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,CAAC,MAAM,YAAY,GACvB,oBAAoB,CAAC,eAAe,CAAC;IACrC,sBAAsB,EAAE;IACxB,4BAA4B,EAAE;IAC9B,wEAAwE;IACxE,yEAAyE;IACzE,2EAA2E;IAC3E,2EAA2E;IAC3E,
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/gmail/instructions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,CAAC,MAAM,YAAY,GACvB,oBAAoB,CAAC,eAAe,CAAC;IACrC,sBAAsB,EAAE;IACxB,4BAA4B,EAAE;IAC9B,wEAAwE;IACxE,yEAAyE;IACzE,2EAA2E;IAC3E,2EAA2E;IAC3E,2DAA2D;IAC3D,mEAAmE;IACnE,yEAAyE;IACzE,8DAA8D,CAAC","sourcesContent":["/**\n * Served in the MCP initialize result; see `ServerOptions.instructions` in\n * src/lib/server.ts. A standalone module so tests can pin the content without\n * booting the server (index.ts's import side effect is `await server()`).\n */\nimport {\n identityInstructions,\n untrustedContentInstructions,\n vocabularyInstructions,\n} from '../lib/instructions.js';\n\nexport const instructions =\n identityInstructions('Gmail account') +\n vocabularyInstructions() +\n untrustedContentInstructions() +\n 'Heed the hints: sends are irreversible and reach external recipients; ' +\n 'permanent deletes bypass the trash entirely (trash_* and untrash_* are ' +\n 'the reversible pair, and Gmail purges trashed mail after about 30 days); ' +\n 'create_filter installs a standing rule that keeps acting on future mail. ' +\n 'Attachment bytes are returned base64url-encoded in JSON. ' +\n 'To attach files, pass the attachments parameter of create_draft, ' +\n 'update_draft, or send_message: each entry names a local file path this ' +\n 'server process reads when it assembles the outgoing message.';\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AttachmentFile } from '../entities/AttachmentFile.js';
|
|
2
|
+
/**
|
|
3
|
+
* The `attachments` parameter description, shared by the three compose
|
|
4
|
+
* schemas (create_draft, update_draft, send_message) so the wording and the
|
|
5
|
+
* interpolated cap cannot drift between them or from the constant.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ATTACHMENTS_PARAM_DESCRIPTION: string;
|
|
8
|
+
/** MIME type for a filename, by extension; octet-stream when unrecognized. */
|
|
9
|
+
export declare function mimeTypeForExtension(filename: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* An attachment loaded and encoded for MIME assembly: `data` is standard
|
|
12
|
+
* base64 (the RFC 2045 content-transfer-encoding, not the base64url the API's
|
|
13
|
+
* outer `raw` field uses), folded to 76-character lines because the builder
|
|
14
|
+
* emits the string verbatim and an unfolded multi-megabyte line breaks the
|
|
15
|
+
* RFC 5322 line-length limit.
|
|
16
|
+
*/
|
|
17
|
+
export type MimeAttachment = {
|
|
18
|
+
filename: string;
|
|
19
|
+
contentType: string;
|
|
20
|
+
data: string;
|
|
21
|
+
};
|
|
22
|
+
/** Fold a base64 string to 76-character CRLF-separated lines (RFC 2045 §6.8). */
|
|
23
|
+
export declare function foldBase64(base64: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Read attachment specs from disk into MIME-ready parts. The combined decoded
|
|
26
|
+
* size is capped at the suite's shared JSON-transfer ceiling; that bounds
|
|
27
|
+
* what this process buffers, not what Gmail accepts (base64 inflates the
|
|
28
|
+
* encoded message ~4/3, so sends near the cap can still be refused by
|
|
29
|
+
* Google; the band past the cap is deferred to issue #103). Each path is
|
|
30
|
+
* stat-checked first: only regular files are read (a FIFO or device file
|
|
31
|
+
* would block or grow unbounded), and an oversize total refuses before the
|
|
32
|
+
* offending file is buffered. Returns undefined when there is nothing to
|
|
33
|
+
* attach.
|
|
34
|
+
*/
|
|
35
|
+
export declare function loadAttachments(specs: AttachmentFile[] | undefined): Promise<MimeAttachment[] | undefined>;
|
|
36
|
+
//# sourceMappingURL=attachment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment.d.ts","sourceRoot":"","sources":["../../../src/gmail/lib/attachment.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAsCpE;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,QAGE,CAAC;AAE7C,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAErF,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD;AAQD;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,cAAc,EAAE,GAAG,SAAS,GAClC,OAAO,CAAC,cAAc,EAAE,GAAG,SAAS,CAAC,CAuCvC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { open } from 'node:fs/promises';
|
|
2
|
+
import { basename, extname } from 'node:path';
|
|
3
|
+
import { assertWithinDownloadCap, MIB_LABEL } from '../../lib/limits.js';
|
|
4
|
+
import { ownLookup } from '../../lib/utils/lookup.js';
|
|
5
|
+
import { headerParamSafe } from './headers.js';
|
|
6
|
+
/**
|
|
7
|
+
* Extension -> MIME type for the attachment types agents actually send.
|
|
8
|
+
* Deliberately small: an unlisted extension degrades to
|
|
9
|
+
* application/octet-stream, which every mail client treats as "download me",
|
|
10
|
+
* never a wrong rendering. Keyed lowercase, without the dot.
|
|
11
|
+
*/
|
|
12
|
+
const MIME_TYPES = {
|
|
13
|
+
csv: 'text/csv',
|
|
14
|
+
doc: 'application/msword',
|
|
15
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
16
|
+
gif: 'image/gif',
|
|
17
|
+
html: 'text/html',
|
|
18
|
+
ics: 'text/calendar',
|
|
19
|
+
jpeg: 'image/jpeg',
|
|
20
|
+
jpg: 'image/jpeg',
|
|
21
|
+
json: 'application/json',
|
|
22
|
+
md: 'text/markdown',
|
|
23
|
+
mp3: 'audio/mpeg',
|
|
24
|
+
mp4: 'video/mp4',
|
|
25
|
+
pdf: 'application/pdf',
|
|
26
|
+
png: 'image/png',
|
|
27
|
+
ppt: 'application/vnd.ms-powerpoint',
|
|
28
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
29
|
+
svg: 'image/svg+xml',
|
|
30
|
+
txt: 'text/plain',
|
|
31
|
+
wav: 'audio/wav',
|
|
32
|
+
webp: 'image/webp',
|
|
33
|
+
xls: 'application/vnd.ms-excel',
|
|
34
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
35
|
+
xml: 'application/xml',
|
|
36
|
+
zip: 'application/zip',
|
|
37
|
+
};
|
|
38
|
+
const FALLBACK_MIME_TYPE = 'application/octet-stream';
|
|
39
|
+
/**
|
|
40
|
+
* The `attachments` parameter description, shared by the three compose
|
|
41
|
+
* schemas (create_draft, update_draft, send_message) so the wording and the
|
|
42
|
+
* interpolated cap cannot drift between them or from the constant.
|
|
43
|
+
*/
|
|
44
|
+
export const ATTACHMENTS_PARAM_DESCRIPTION = 'Local files to attach; the server reads each path and assembles the MIME message. ' +
|
|
45
|
+
'Attachments are delivered as downloads, not inline images (no cid: references). ' +
|
|
46
|
+
`Combined size is capped at ${MIB_LABEL}.`;
|
|
47
|
+
/** MIME type for a filename, by extension; octet-stream when unrecognized. */
|
|
48
|
+
export function mimeTypeForExtension(filename) {
|
|
49
|
+
const extension = extname(filename).slice(1).toLowerCase();
|
|
50
|
+
return ownLookup(MIME_TYPES, extension) ?? FALLBACK_MIME_TYPE;
|
|
51
|
+
}
|
|
52
|
+
/** Fold a base64 string to 76-character CRLF-separated lines (RFC 2045 §6.8). */
|
|
53
|
+
export function foldBase64(base64) {
|
|
54
|
+
return base64.match(/.{1,76}/g)?.join('\r\n') ?? '';
|
|
55
|
+
}
|
|
56
|
+
const CAP_OPTIONS = {
|
|
57
|
+
subject: 'The combined attachment payload',
|
|
58
|
+
action: 'compose attachments',
|
|
59
|
+
deferral: 'https://github.com/simiancraft/google-mcp-suite/issues/103',
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Read attachment specs from disk into MIME-ready parts. The combined decoded
|
|
63
|
+
* size is capped at the suite's shared JSON-transfer ceiling; that bounds
|
|
64
|
+
* what this process buffers, not what Gmail accepts (base64 inflates the
|
|
65
|
+
* encoded message ~4/3, so sends near the cap can still be refused by
|
|
66
|
+
* Google; the band past the cap is deferred to issue #103). Each path is
|
|
67
|
+
* stat-checked first: only regular files are read (a FIFO or device file
|
|
68
|
+
* would block or grow unbounded), and an oversize total refuses before the
|
|
69
|
+
* offending file is buffered. Returns undefined when there is nothing to
|
|
70
|
+
* attach.
|
|
71
|
+
*/
|
|
72
|
+
export async function loadAttachments(specs) {
|
|
73
|
+
if (!specs?.length) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
let total = 0;
|
|
77
|
+
const out = [];
|
|
78
|
+
for (const spec of specs) {
|
|
79
|
+
const file = await open(spec.path, 'r');
|
|
80
|
+
let bytes;
|
|
81
|
+
try {
|
|
82
|
+
const stats = await file.stat();
|
|
83
|
+
if (!stats.isFile()) {
|
|
84
|
+
throw new Error(`Attachment path ${spec.path} is not a regular file.`);
|
|
85
|
+
}
|
|
86
|
+
total += stats.size;
|
|
87
|
+
assertWithinDownloadCap(total, CAP_OPTIONS);
|
|
88
|
+
bytes = await file.readFile();
|
|
89
|
+
// Re-check what actually arrived: a file that grew between stat and
|
|
90
|
+
// read must not slip past the ceiling the stat check enforced.
|
|
91
|
+
total += bytes.byteLength - stats.size;
|
|
92
|
+
assertWithinDownloadCap(total, CAP_OPTIONS);
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
await file.close();
|
|
96
|
+
}
|
|
97
|
+
// A name that sanitizes to nothing still needs a header value; 'attachment'
|
|
98
|
+
// keeps the part well-formed and the recipient's client offers a download.
|
|
99
|
+
const filename = headerParamSafe(spec.filename ?? basename(spec.path)) || 'attachment';
|
|
100
|
+
out.push({
|
|
101
|
+
filename,
|
|
102
|
+
// The type is inferred from the path's extension (the recipient-facing
|
|
103
|
+
// filename may legitimately carry none), falling back after sanitization
|
|
104
|
+
// so the builder never sees an empty content type.
|
|
105
|
+
contentType: headerParamSafe(spec.mimeType ?? mimeTypeForExtension(basename(spec.path))) ||
|
|
106
|
+
FALLBACK_MIME_TYPE,
|
|
107
|
+
data: foldBase64(bytes.toString('base64')),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=attachment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment.js","sourceRoot":"","sources":["../../../src/gmail/lib/attachment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,E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AAC;YACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;QACD,4EAA4E;QAC5E,2EAA2E;QAC3E,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,YAAY,CAAC;QACvF,GAAG,CAAC,IAAI,CAAC;YACP,QAAQ;YACR,uEAAuE;YACvE,yEAAyE;YACzE,mDAAmD;YACnD,WAAW,EACT,eAAe,CAAC,IAAI,CAAC,QAAQ,IAAI,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC3E,kBAAkB;YACpB,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;SAC3C,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { open } from 'node:fs/promises';\nimport { basename, extname } from 'node:path';\nimport { assertWithinDownloadCap, MIB_LABEL } from '../../lib/limits.js';\nimport { ownLookup } from '../../lib/utils/lookup.js';\nimport type { AttachmentFile } from '../entities/AttachmentFile.js';\nimport { headerParamSafe } from './headers.js';\n\n/**\n * Extension -> MIME type for the attachment types agents actually send.\n * Deliberately small: an unlisted extension degrades to\n * application/octet-stream, which every mail client treats as \"download me\",\n * never a wrong rendering. Keyed lowercase, without the dot.\n */\nconst MIME_TYPES: Record<string, string> = {\n csv: 'text/csv',\n doc: 'application/msword',\n docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n gif: 'image/gif',\n html: 'text/html',\n ics: 'text/calendar',\n jpeg: 'image/jpeg',\n jpg: 'image/jpeg',\n json: 'application/json',\n md: 'text/markdown',\n mp3: 'audio/mpeg',\n mp4: 'video/mp4',\n pdf: 'application/pdf',\n png: 'image/png',\n ppt: 'application/vnd.ms-powerpoint',\n pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n svg: 'image/svg+xml',\n txt: 'text/plain',\n wav: 'audio/wav',\n webp: 'image/webp',\n xls: 'application/vnd.ms-excel',\n xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n xml: 'application/xml',\n zip: 'application/zip',\n};\n\nconst FALLBACK_MIME_TYPE = 'application/octet-stream';\n\n/**\n * The `attachments` parameter description, shared by the three compose\n * schemas (create_draft, update_draft, send_message) so the wording and the\n * interpolated cap cannot drift between them or from the constant.\n */\nexport const ATTACHMENTS_PARAM_DESCRIPTION =\n 'Local files to attach; the server reads each path and assembles the MIME message. ' +\n 'Attachments are delivered as downloads, not inline images (no cid: references). ' +\n `Combined size is capped at ${MIB_LABEL}.`;\n\n/** MIME type for a filename, by extension; octet-stream when unrecognized. */\nexport function mimeTypeForExtension(filename: string): string {\n const extension = extname(filename).slice(1).toLowerCase();\n return ownLookup(MIME_TYPES, extension) ?? FALLBACK_MIME_TYPE;\n}\n\n/**\n * An attachment loaded and encoded for MIME assembly: `data` is standard\n * base64 (the RFC 2045 content-transfer-encoding, not the base64url the API's\n * outer `raw` field uses), folded to 76-character lines because the builder\n * emits the string verbatim and an unfolded multi-megabyte line breaks the\n * RFC 5322 line-length limit.\n */\nexport type MimeAttachment = { filename: string; contentType: string; data: string };\n\n/** Fold a base64 string to 76-character CRLF-separated lines (RFC 2045 §6.8). */\nexport function foldBase64(base64: string): string {\n return base64.match(/.{1,76}/g)?.join('\\r\\n') ?? '';\n}\n\nconst CAP_OPTIONS = {\n subject: 'The combined attachment payload',\n action: 'compose attachments',\n deferral: 'https://github.com/simiancraft/google-mcp-suite/issues/103',\n} as const;\n\n/**\n * Read attachment specs from disk into MIME-ready parts. The combined decoded\n * size is capped at the suite's shared JSON-transfer ceiling; that bounds\n * what this process buffers, not what Gmail accepts (base64 inflates the\n * encoded message ~4/3, so sends near the cap can still be refused by\n * Google; the band past the cap is deferred to issue #103). Each path is\n * stat-checked first: only regular files are read (a FIFO or device file\n * would block or grow unbounded), and an oversize total refuses before the\n * offending file is buffered. Returns undefined when there is nothing to\n * attach.\n */\nexport async function loadAttachments(\n specs: AttachmentFile[] | undefined,\n): Promise<MimeAttachment[] | undefined> {\n if (!specs?.length) {\n return undefined;\n }\n let total = 0;\n const out: MimeAttachment[] = [];\n for (const spec of specs) {\n const file = await open(spec.path, 'r');\n let bytes: Buffer;\n try {\n const stats = await file.stat();\n if (!stats.isFile()) {\n throw new Error(`Attachment path ${spec.path} is not a regular file.`);\n }\n total += stats.size;\n assertWithinDownloadCap(total, CAP_OPTIONS);\n bytes = await file.readFile();\n // Re-check what actually arrived: a file that grew between stat and\n // read must not slip past the ceiling the stat check enforced.\n total += bytes.byteLength - stats.size;\n assertWithinDownloadCap(total, CAP_OPTIONS);\n } finally {\n await file.close();\n }\n // A name that sanitizes to nothing still needs a header value; 'attachment'\n // keeps the part well-formed and the recipient's client offers a download.\n const filename = headerParamSafe(spec.filename ?? basename(spec.path)) || 'attachment';\n out.push({\n filename,\n // The type is inferred from the path's extension (the recipient-facing\n // filename may legitimately carry none), falling back after sanitization\n // so the builder never sees an empty content type.\n contentType:\n headerParamSafe(spec.mimeType ?? mimeTypeForExtension(basename(spec.path))) ||\n FALLBACK_MIME_TYPE,\n data: foldBase64(bytes.toString('base64')),\n });\n }\n return out;\n}\n"]}
|
|
@@ -3,4 +3,11 @@ import { z } from 'zod';
|
|
|
3
3
|
export declare const headerSafe: z.ZodString;
|
|
4
4
|
/** Strip control characters and line breaks, defending header assembly from injection. */
|
|
5
5
|
export declare function stripBreaks(value: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Make a value safe for a quoted MIME header parameter (`name="..."`,
|
|
8
|
+
* `filename="..."`): strip control characters (header injection) plus double
|
|
9
|
+
* quotes and backslashes, which the MIME builder interpolates unescaped into
|
|
10
|
+
* the quoted string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function headerParamSafe(value: string): string;
|
|
6
13
|
//# sourceMappingURL=headers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../../src/gmail/lib/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,yFAAyF;AACzF,eAAO,MAAM,UAAU,aAKpB,CAAC;AAEJ,0FAA0F;AAC1F,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
|
1
|
+
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../../src/gmail/lib/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,yFAAyF;AACzF,eAAO,MAAM,UAAU,aAKpB,CAAC;AAEJ,0FAA0F;AAC1F,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
@@ -16,4 +16,13 @@ export const headerSafe = z
|
|
|
16
16
|
export function stripBreaks(value) {
|
|
17
17
|
return [...value].filter((ch) => !isControl(ch)).join('');
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Make a value safe for a quoted MIME header parameter (`name="..."`,
|
|
21
|
+
* `filename="..."`): strip control characters (header injection) plus double
|
|
22
|
+
* quotes and backslashes, which the MIME builder interpolates unescaped into
|
|
23
|
+
* the quoted string.
|
|
24
|
+
*/
|
|
25
|
+
export function headerParamSafe(value) {
|
|
26
|
+
return stripBreaks(value).replaceAll('"', '').replaceAll('\\', '');
|
|
27
|
+
}
|
|
19
28
|
//# sourceMappingURL=headers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../src/gmail/lib/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,8EAA8E;AAC9E,iFAAiF;AACjF,mEAAmE;AAEnE,+FAA+F;AAC/F,SAAS,SAAS,CAAC,EAAU;IAC3B,MAAM,IAAI,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9B,OAAO,IAAI,GAAG,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC;AACtC,CAAC;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC;KACxB,MAAM,EAAE;KACR,MAAM,CACL,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EACtC,oDAAoD,CACrD,CAAC;AAEJ,0FAA0F;AAC1F,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import { z } from 'zod';\n\n// Header-bound inputs (addresses, subject, message ids) must not carry control\n// characters or line breaks: a CRLF in an address string injects a new header\n// line (e.g. a silent `Bcc:`) when the message is assembled. Inputs are rejected\n// at the schema, and stripped defensively where headers are built.\n\n/** True for C0 control characters (incl. CR/LF) and DEL, which are never valid in a header. */\nfunction isControl(ch: string): boolean {\n const code = ch.charCodeAt(0);\n return code < 0x20 || code === 0x7f;\n}\n\n/** A string safe to place in an RFC 822 header: no control characters or line breaks. */\nexport const headerSafe = z\n .string()\n .refine(\n (value) => ![...value].some(isControl),\n 'must not contain control characters or line breaks',\n );\n\n/** Strip control characters and line breaks, defending header assembly from injection. */\nexport function stripBreaks(value: string): string {\n return [...value].filter((ch) => !isControl(ch)).join('');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../src/gmail/lib/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,8EAA8E;AAC9E,iFAAiF;AACjF,mEAAmE;AAEnE,+FAA+F;AAC/F,SAAS,SAAS,CAAC,EAAU;IAC3B,MAAM,IAAI,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9B,OAAO,IAAI,GAAG,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC;AACtC,CAAC;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC;KACxB,MAAM,EAAE;KACR,MAAM,CACL,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EACtC,oDAAoD,CACrD,CAAC;AAEJ,0FAA0F;AAC1F,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { z } from 'zod';\n\n// Header-bound inputs (addresses, subject, message ids) must not carry control\n// characters or line breaks: a CRLF in an address string injects a new header\n// line (e.g. a silent `Bcc:`) when the message is assembled. Inputs are rejected\n// at the schema, and stripped defensively where headers are built.\n\n/** True for C0 control characters (incl. CR/LF) and DEL, which are never valid in a header. */\nfunction isControl(ch: string): boolean {\n const code = ch.charCodeAt(0);\n return code < 0x20 || code === 0x7f;\n}\n\n/** A string safe to place in an RFC 822 header: no control characters or line breaks. */\nexport const headerSafe = z\n .string()\n .refine(\n (value) => ![...value].some(isControl),\n 'must not contain control characters or line breaks',\n );\n\n/** Strip control characters and line breaks, defending header assembly from injection. */\nexport function stripBreaks(value: string): string {\n return [...value].filter((ch) => !isControl(ch)).join('');\n}\n\n/**\n * Make a value safe for a quoted MIME header parameter (`name=\"...\"`,\n * `filename=\"...\"`): strip control characters (header injection) plus double\n * quotes and backslashes, which the MIME builder interpolates unescaped into\n * the quoted string.\n */\nexport function headerParamSafe(value: string): string {\n return stripBreaks(value).replaceAll('\"', '').replaceAll('\\\\', '');\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import type { gmail_v1 } from '@googleapis/gmail';
|
|
|
2
2
|
import type { Optional } from '../../lib/optionality.js';
|
|
3
3
|
import type { Draft } from '../entities/Draft.js';
|
|
4
4
|
import type { Message } from '../entities/Message.js';
|
|
5
|
+
import type { MimeAttachment } from './attachment.js';
|
|
5
6
|
/** Project a raw Gmail message onto the documented Message shape. */
|
|
6
7
|
export declare function projectMessage(message: gmail_v1.Schema$Message): Message;
|
|
7
8
|
/** Project a raw Gmail draft onto the documented Draft shape. */
|
|
@@ -21,6 +22,7 @@ export declare function buildRawMessage(args: {
|
|
|
21
22
|
body?: Optional<string>;
|
|
22
23
|
htmlBody?: Optional<string>;
|
|
23
24
|
inReplyTo?: Optional<string>;
|
|
25
|
+
attachments?: Optional<MimeAttachment[]>;
|
|
24
26
|
}): string;
|
|
25
27
|
/**
|
|
26
28
|
* Resolve a reply's threading context: fetch the original message for its thread
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/gmail/lib/message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,C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,wBAAgB,eAAe,CAAC,IAAI,EAAE;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,EAAE,CAAC,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACxB,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACzB,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3B,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxB,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7B,WAAW,CAAC,EAAE,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC;CAC1C,GAAG,MAAM,CA4CT;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,QAAQ,CAAC,KAAK,EACrB,gBAAgB,EAAE,MAAM,GAAG,SAAS,GACnC,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC,CAgB1E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import addressparser from 'addressparser';
|
|
2
2
|
import { createMimeMessage } from 'mail-mime-builder';
|
|
3
|
-
import { stripBreaks } from './headers.js';
|
|
3
|
+
import { headerParamSafe, stripBreaks } from './headers.js';
|
|
4
4
|
/**
|
|
5
5
|
* Lowercased header name -> value, from a message payload. Null-prototype: a
|
|
6
6
|
* sender controls header names, and `__proto__` must land as plain data, not a
|
|
@@ -168,6 +168,18 @@ export function buildRawMessage(args) {
|
|
|
168
168
|
if (args.body === undefined && args.htmlBody === undefined) {
|
|
169
169
|
msg.addMessage({ contentType: 'text/plain', data: '' });
|
|
170
170
|
}
|
|
171
|
+
// Attachments arrive pre-encoded (lib/attachment.ts owns reading, sizing,
|
|
172
|
+
// and folding) and pre-sanitized, but filename and contentType are
|
|
173
|
+
// header-bound, so the choke-point guarantee applies to them too: sanitize
|
|
174
|
+
// here regardless of what the producer did. Their presence switches the
|
|
175
|
+
// builder to a multipart/mixed structure.
|
|
176
|
+
for (const attachment of args.attachments ?? []) {
|
|
177
|
+
msg.addAttachment({
|
|
178
|
+
filename: headerParamSafe(attachment.filename) || 'attachment',
|
|
179
|
+
contentType: headerParamSafe(attachment.contentType) || 'application/octet-stream',
|
|
180
|
+
data: attachment.data,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
171
183
|
// Base64url the RFC 822 text ourselves (the format the Gmail API expects),
|
|
172
184
|
// rather than the library's asEncoded(), whose output is not URL-safe base64.
|
|
173
185
|
return Buffer.from(msg.asRaw()).toString('base64url');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/gmail/lib/message.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAKtD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;GAIG;AACH,SAAS,SAAS,CAAC,OAAqC;IACtD,MAAM,GAAG,GAA2B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,CAAC;QAC5C,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YAChC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;QAChD,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAOD,8EAA8E;AAC9E,+EAA+E;AAC/E,iFAAiF;AACjF,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;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E,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;IACvD,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAC9C,MAAM,EAAE,IAAI;QACZ,EAAE,EAAE,gBAAgB;QACpB,MAAM,EAAE,UAAU;QAClB,eAAe,EAAE,CAAC,YAAY,CAAC;KAChC,CAAC,CAAC;IACH,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,SAAS;QACpC,SAAS,EACP,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,YAAY,CAAC,EAAE,KAAK;YAC3F,SAAS;KACZ,CAAC;AACJ,CAAC","sourcesContent":["import type { gmail_v1 } from '@googleapis/gmail';\nimport addressparser from 'addressparser';\nimport { createMimeMessage } from 'mail-mime-builder';\nimport type { Optional } from '../../lib/optionality.js';\nimport type { Draft } from '../entities/Draft.js';\nimport type { EmailAddress } from '../entities/EmailAddress.js';\nimport type { Message } from '../entities/Message.js';\nimport { stripBreaks } from './headers.js';\n\n/**\n * Lowercased header name -> value, from a message payload. Null-prototype: a\n * sender controls header names, and `__proto__` must land as plain data, not a\n * prototype write.\n */\nfunction headerMap(payload?: gmail_v1.Schema$MessagePart): Record<string, string> {\n const map: Record<string, string> = Object.create(null);\n for (const header of payload?.headers ?? []) {\n if (header.name && header.value) {\n map[header.name.toLowerCase()] = header.value;\n }\n }\n return map;\n}\n\n// addressparser's address node: `name` is always a string ('' when absent), and\n// a node may instead be a `group` of members. Distinct from our entity\n// EmailAddress (../entities/EmailAddress), whose `name` is optional.\ntype ParsedAddress = ReturnType<typeof addressparser>[number];\n\n// Bounds against hostile inbound mail; a sender controls header text and MIME\n// structure. Best-effort: cap the work and project what fits rather than block\n// the server (addressparser is O(n^2) in entry count) or overflow the stack on a\n// deeply nested tree. A header longer than this, or nesting deeper, is not\n// legitimate mail to act on. (A deep RFC 5322 group can still overflow inside\n// addressparser before we see it; that surfaces as a server-caught per-call\n// error, not a crash.)\nconst MAX_HEADER_LENGTH = 100_000;\nconst MAX_DEPTH = 100;\n\n/**\n * Parse an address-list header into structured addresses (display name + bare\n * address). RFC 5322 tokenization (quoted display names, escaped commas, group\n * syntax) is deferred to addressparser; a naive `.split(',')` mis-parses\n * `\"Doe, John\" <j@x.com>` into two broken tokens. Group syntax is flattened to\n * its member addresses; a name is included only when the header carried one.\n */\nfunction addresses(value?: string): EmailAddress[] {\n if (!value) {\n return [];\n }\n const bounded = value.length > MAX_HEADER_LENGTH ? value.slice(0, MAX_HEADER_LENGTH) : value;\n const out: EmailAddress[] = [];\n const collect = (entries: ParsedAddress[], depth: number): void => {\n if (depth > MAX_DEPTH) {\n return;\n }\n for (const entry of entries) {\n if (entry.group) {\n collect(entry.group, depth + 1);\n } else if (entry.address) {\n // addressparser yields name:'' (not undefined) for nameless addresses; ''\n // is falsy, so we omit the key and keep the projected object clean.\n out.push(\n entry.name ? { name: entry.name, address: entry.address } : { address: entry.address },\n );\n }\n }\n };\n collect(addressparser(bounded), 0);\n return out;\n}\n\n/** The first address parsed from a header (e.g. the sender from `From`), or undefined. */\nfunction firstAddress(value?: string): EmailAddress | undefined {\n return addresses(value)[0];\n}\n\nfunction decodeBody(data?: string | null): string {\n return data ? Buffer.from(data, 'base64url').toString('utf8') : '';\n}\n\ntype Bodies = { plain?: string; html?: string };\n\n/**\n * Walk the MIME tree collecting the first text/plain and first text/html parts.\n * Both are surfaced (an intentional extension beyond Google's plaintext-only\n * projection): callers need plain and HTML bodies extracted reliably.\n */\nfunction collectBodies(\n part: gmail_v1.Schema$MessagePart | undefined,\n acc: Bodies,\n depth = 0,\n): void {\n if (!part || depth > MAX_DEPTH) {\n return;\n }\n if (part.body?.data) {\n if (part.mimeType === 'text/plain' && acc.plain === undefined) {\n acc.plain = decodeBody(part.body.data);\n } else if (part.mimeType === 'text/html' && acc.html === undefined) {\n acc.html = decodeBody(part.body.data);\n }\n }\n for (const child of part.parts ?? []) {\n collectBodies(child, acc, depth + 1);\n }\n}\n\n/** Walk the MIME tree collecting attachment ids. */\nfunction collectAttachmentIds(\n part: gmail_v1.Schema$MessagePart | undefined,\n ids: string[],\n depth = 0,\n): void {\n if (!part || depth > MAX_DEPTH) {\n return;\n }\n if (part.body?.attachmentId) {\n ids.push(part.body.attachmentId);\n }\n for (const child of part.parts ?? []) {\n collectAttachmentIds(child, ids, depth + 1);\n }\n}\n\n/** Project a raw Gmail message onto the documented Message shape. */\nexport function projectMessage(message: gmail_v1.Schema$Message): Message {\n const headers = headerMap(message.payload);\n const attachmentIds: string[] = [];\n collectAttachmentIds(message.payload, attachmentIds);\n const bodies: Bodies = {};\n collectBodies(message.payload, bodies);\n return {\n id: message.id ?? '',\n snippet: message.snippet ?? undefined,\n subject: headers['subject'],\n sender: firstAddress(headers['from']),\n toRecipients: addresses(headers['to']),\n ccRecipients: addresses(headers['cc']),\n date: headers['date'],\n plaintextBody: bodies.plain || undefined,\n htmlBody: bodies.html || undefined,\n attachmentIds: attachmentIds.length ? attachmentIds : undefined,\n };\n}\n\n/** Project a raw Gmail draft onto the documented Draft shape. */\nexport function projectDraft(draft: gmail_v1.Schema$Draft): Draft {\n const message = draft.message;\n const headers = headerMap(message?.payload);\n const bodies: Bodies = {};\n collectBodies(message?.payload, bodies);\n return {\n id: draft.id ?? '',\n threadId: message?.threadId ?? undefined,\n subject: headers['subject'],\n toRecipients: addresses(headers['to']),\n ccRecipients: addresses(headers['cc']),\n bccRecipients: addresses(headers['bcc']),\n plaintextBody: bodies.plain || undefined,\n htmlBody: bodies.html || undefined,\n date: headers['date'],\n };\n}\n\n/**\n * Build an RFC 822 message and base64url-encode it for the Gmail API, via\n * mail-mime-builder (RFC 2822/2045/2049 compliant: encoded-word headers,\n * multipart, transfer encoding). `from` is required by the builder; pass the\n * authenticated account's address.\n */\nexport function buildRawMessage(args: {\n from: string;\n to: string[];\n cc?: Optional<string[]>;\n bcc?: Optional<string[]>;\n subject?: Optional<string>;\n body?: Optional<string>;\n htmlBody?: Optional<string>;\n inReplyTo?: Optional<string>;\n}): string {\n // Strip CR/LF and control characters from every header-bound field: a line\n // break in an address or subject would otherwise inject a new header (e.g. a\n // silent Bcc). Schemas reject these too; this is the choke-point guarantee.\n const msg = createMimeMessage();\n msg.setSender(stripBreaks(args.from));\n msg.setTo(args.to.map(stripBreaks));\n if (args.cc?.length) {\n msg.setCc(args.cc.map(stripBreaks));\n }\n if (args.bcc?.length) {\n msg.setBcc(args.bcc.map(stripBreaks));\n }\n // Subject is a required header for the builder; default to empty when omitted.\n msg.setSubject(stripBreaks(args.subject ?? ''));\n if (args.inReplyTo) {\n const inReplyTo = stripBreaks(args.inReplyTo);\n msg.setHeader('In-Reply-To', inReplyTo);\n msg.setHeader('References', inReplyTo);\n }\n if (args.body !== undefined) {\n msg.addMessage({ contentType: 'text/plain', data: args.body });\n }\n if (args.htmlBody !== undefined) {\n msg.addMessage({ contentType: 'text/html', data: args.htmlBody });\n }\n if (args.body === undefined && args.htmlBody === undefined) {\n msg.addMessage({ contentType: 'text/plain', data: '' });\n }\n // Base64url the RFC 822 text ourselves (the format the Gmail API expects),\n // rather than the library's asEncoded(), whose output is not URL-safe base64.\n return Buffer.from(msg.asRaw()).toString('base64url');\n}\n\n/**\n * Resolve a reply's threading context: fetch the original message for its thread\n * id and `Message-ID` so the new draft/message lands in the same thread with a\n * correct `In-Reply-To`. Returns empty fields when not replying. Shared by the\n * compose handlers (create_draft, send_message) so the threading fetch lives once.\n */\nexport async function resolveReplyContext(\n gmail: gmail_v1.Gmail,\n replyToMessageId: string | undefined,\n): Promise<{ threadId: string | undefined; inReplyTo: string | undefined }> {\n if (!replyToMessageId) {\n return { threadId: undefined, inReplyTo: undefined };\n }\n const { data } = await gmail.users.messages.get({\n userId: 'me',\n id: replyToMessageId,\n format: 'metadata',\n metadataHeaders: ['Message-ID'],\n });\n return {\n threadId: data.threadId ?? undefined,\n inReplyTo:\n data.payload?.headers?.find((header) => header.name?.toLowerCase() === 'message-id')?.value ??\n undefined,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/gmail/lib/message.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAMtD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE5D;;;;GAIG;AACH,SAAS,SAAS,CAAC,OAAqC;IACtD,MAAM,GAAG,GAA2B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,CAAC;QAC5C,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YAChC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;QAChD,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAOD,8EAA8E;AAC9E,+EAA+E;AAC/E,iFAAiF;AACjF,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;AAC5E,uBAAuB;AACvB,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAClC,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB;;;;;;GAMG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7F,MAAM,GAAG,GAAmB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AAE,SAAS,EAAE,SAAS,EAAE,CAAC;IACvD,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAC9C,MAAM,EAAE,IAAI;QACZ,EAAE,EAAE,gBAAgB;QACpB,MAAM,EAAE,UAAU;QAClB,eAAe,EAAE,CAAC,YAAY,CAAC;KAChC,CAAC,CAAC;IACH,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,SAAS;QACpC,SAAS,EACP,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,YAAY,CAAC,EAAE,KAAK;YAC3F,SAAS;KACZ,CAAC;AACJ,CAAC","sourcesContent":["import type { gmail_v1 } from '@googleapis/gmail';\nimport addressparser from 'addressparser';\nimport { createMimeMessage } from 'mail-mime-builder';\nimport type { Optional } from '../../lib/optionality.js';\nimport type { Draft } from '../entities/Draft.js';\nimport type { EmailAddress } from '../entities/EmailAddress.js';\nimport type { Message } from '../entities/Message.js';\nimport type { MimeAttachment } from './attachment.js';\nimport { headerParamSafe, stripBreaks } from './headers.js';\n\n/**\n * Lowercased header name -> value, from a message payload. Null-prototype: a\n * sender controls header names, and `__proto__` must land as plain data, not a\n * prototype write.\n */\nfunction headerMap(payload?: gmail_v1.Schema$MessagePart): Record<string, string> {\n const map: Record<string, string> = Object.create(null);\n for (const header of payload?.headers ?? []) {\n if (header.name && header.value) {\n map[header.name.toLowerCase()] = header.value;\n }\n }\n return map;\n}\n\n// addressparser's address node: `name` is always a string ('' when absent), and\n// a node may instead be a `group` of members. Distinct from our entity\n// EmailAddress (../entities/EmailAddress), whose `name` is optional.\ntype ParsedAddress = ReturnType<typeof addressparser>[number];\n\n// Bounds against hostile inbound mail; a sender controls header text and MIME\n// structure. Best-effort: cap the work and project what fits rather than block\n// the server (addressparser is O(n^2) in entry count) or overflow the stack on a\n// deeply nested tree. A header longer than this, or nesting deeper, is not\n// legitimate mail to act on. (A deep RFC 5322 group can still overflow inside\n// addressparser before we see it; that surfaces as a server-caught per-call\n// error, not a crash.)\nconst MAX_HEADER_LENGTH = 100_000;\nconst MAX_DEPTH = 100;\n\n/**\n * Parse an address-list header into structured addresses (display name + bare\n * address). RFC 5322 tokenization (quoted display names, escaped commas, group\n * syntax) is deferred to addressparser; a naive `.split(',')` mis-parses\n * `\"Doe, John\" <j@x.com>` into two broken tokens. Group syntax is flattened to\n * its member addresses; a name is included only when the header carried one.\n */\nfunction addresses(value?: string): EmailAddress[] {\n if (!value) {\n return [];\n }\n const bounded = value.length > MAX_HEADER_LENGTH ? value.slice(0, MAX_HEADER_LENGTH) : value;\n const out: EmailAddress[] = [];\n const collect = (entries: ParsedAddress[], depth: number): void => {\n if (depth > MAX_DEPTH) {\n return;\n }\n for (const entry of entries) {\n if (entry.group) {\n collect(entry.group, depth + 1);\n } else if (entry.address) {\n // addressparser yields name:'' (not undefined) for nameless addresses; ''\n // is falsy, so we omit the key and keep the projected object clean.\n out.push(\n entry.name ? { name: entry.name, address: entry.address } : { address: entry.address },\n );\n }\n }\n };\n collect(addressparser(bounded), 0);\n return out;\n}\n\n/** The first address parsed from a header (e.g. the sender from `From`), or undefined. */\nfunction firstAddress(value?: string): EmailAddress | undefined {\n return addresses(value)[0];\n}\n\nfunction decodeBody(data?: string | null): string {\n return data ? Buffer.from(data, 'base64url').toString('utf8') : '';\n}\n\ntype Bodies = { plain?: string; html?: string };\n\n/**\n * Walk the MIME tree collecting the first text/plain and first text/html parts.\n * Both are surfaced (an intentional extension beyond Google's plaintext-only\n * projection): callers need plain and HTML bodies extracted reliably.\n */\nfunction collectBodies(\n part: gmail_v1.Schema$MessagePart | undefined,\n acc: Bodies,\n depth = 0,\n): void {\n if (!part || depth > MAX_DEPTH) {\n return;\n }\n if (part.body?.data) {\n if (part.mimeType === 'text/plain' && acc.plain === undefined) {\n acc.plain = decodeBody(part.body.data);\n } else if (part.mimeType === 'text/html' && acc.html === undefined) {\n acc.html = decodeBody(part.body.data);\n }\n }\n for (const child of part.parts ?? []) {\n collectBodies(child, acc, depth + 1);\n }\n}\n\n/** Walk the MIME tree collecting attachment ids. */\nfunction collectAttachmentIds(\n part: gmail_v1.Schema$MessagePart | undefined,\n ids: string[],\n depth = 0,\n): void {\n if (!part || depth > MAX_DEPTH) {\n return;\n }\n if (part.body?.attachmentId) {\n ids.push(part.body.attachmentId);\n }\n for (const child of part.parts ?? []) {\n collectAttachmentIds(child, ids, depth + 1);\n }\n}\n\n/** Project a raw Gmail message onto the documented Message shape. */\nexport function projectMessage(message: gmail_v1.Schema$Message): Message {\n const headers = headerMap(message.payload);\n const attachmentIds: string[] = [];\n collectAttachmentIds(message.payload, attachmentIds);\n const bodies: Bodies = {};\n collectBodies(message.payload, bodies);\n return {\n id: message.id ?? '',\n snippet: message.snippet ?? undefined,\n subject: headers['subject'],\n sender: firstAddress(headers['from']),\n toRecipients: addresses(headers['to']),\n ccRecipients: addresses(headers['cc']),\n date: headers['date'],\n plaintextBody: bodies.plain || undefined,\n htmlBody: bodies.html || undefined,\n attachmentIds: attachmentIds.length ? attachmentIds : undefined,\n };\n}\n\n/** Project a raw Gmail draft onto the documented Draft shape. */\nexport function projectDraft(draft: gmail_v1.Schema$Draft): Draft {\n const message = draft.message;\n const headers = headerMap(message?.payload);\n const bodies: Bodies = {};\n collectBodies(message?.payload, bodies);\n return {\n id: draft.id ?? '',\n threadId: message?.threadId ?? undefined,\n subject: headers['subject'],\n toRecipients: addresses(headers['to']),\n ccRecipients: addresses(headers['cc']),\n bccRecipients: addresses(headers['bcc']),\n plaintextBody: bodies.plain || undefined,\n htmlBody: bodies.html || undefined,\n date: headers['date'],\n };\n}\n\n/**\n * Build an RFC 822 message and base64url-encode it for the Gmail API, via\n * mail-mime-builder (RFC 2822/2045/2049 compliant: encoded-word headers,\n * multipart, transfer encoding). `from` is required by the builder; pass the\n * authenticated account's address.\n */\nexport function buildRawMessage(args: {\n from: string;\n to: string[];\n cc?: Optional<string[]>;\n bcc?: Optional<string[]>;\n subject?: Optional<string>;\n body?: Optional<string>;\n htmlBody?: Optional<string>;\n inReplyTo?: Optional<string>;\n attachments?: Optional<MimeAttachment[]>;\n}): string {\n // Strip CR/LF and control characters from every header-bound field: a line\n // break in an address or subject would otherwise inject a new header (e.g. a\n // silent Bcc). Schemas reject these too; this is the choke-point guarantee.\n const msg = createMimeMessage();\n msg.setSender(stripBreaks(args.from));\n msg.setTo(args.to.map(stripBreaks));\n if (args.cc?.length) {\n msg.setCc(args.cc.map(stripBreaks));\n }\n if (args.bcc?.length) {\n msg.setBcc(args.bcc.map(stripBreaks));\n }\n // Subject is a required header for the builder; default to empty when omitted.\n msg.setSubject(stripBreaks(args.subject ?? ''));\n if (args.inReplyTo) {\n const inReplyTo = stripBreaks(args.inReplyTo);\n msg.setHeader('In-Reply-To', inReplyTo);\n msg.setHeader('References', inReplyTo);\n }\n if (args.body !== undefined) {\n msg.addMessage({ contentType: 'text/plain', data: args.body });\n }\n if (args.htmlBody !== undefined) {\n msg.addMessage({ contentType: 'text/html', data: args.htmlBody });\n }\n if (args.body === undefined && args.htmlBody === undefined) {\n msg.addMessage({ contentType: 'text/plain', data: '' });\n }\n // Attachments arrive pre-encoded (lib/attachment.ts owns reading, sizing,\n // and folding) and pre-sanitized, but filename and contentType are\n // header-bound, so the choke-point guarantee applies to them too: sanitize\n // here regardless of what the producer did. Their presence switches the\n // builder to a multipart/mixed structure.\n for (const attachment of args.attachments ?? []) {\n msg.addAttachment({\n filename: headerParamSafe(attachment.filename) || 'attachment',\n contentType: headerParamSafe(attachment.contentType) || 'application/octet-stream',\n data: attachment.data,\n });\n }\n // Base64url the RFC 822 text ourselves (the format the Gmail API expects),\n // rather than the library's asEncoded(), whose output is not URL-safe base64.\n return Buffer.from(msg.asRaw()).toString('base64url');\n}\n\n/**\n * Resolve a reply's threading context: fetch the original message for its thread\n * id and `Message-ID` so the new draft/message lands in the same thread with a\n * correct `In-Reply-To`. Returns empty fields when not replying. Shared by the\n * compose handlers (create_draft, send_message) so the threading fetch lives once.\n */\nexport async function resolveReplyContext(\n gmail: gmail_v1.Gmail,\n replyToMessageId: string | undefined,\n): Promise<{ threadId: string | undefined; inReplyTo: string | undefined }> {\n if (!replyToMessageId) {\n return { threadId: undefined, inReplyTo: undefined };\n }\n const { data } = await gmail.users.messages.get({\n userId: 'me',\n id: replyToMessageId,\n format: 'metadata',\n metadataHeaders: ['Message-ID'],\n });\n return {\n threadId: data.threadId ?? undefined,\n inReplyTo:\n data.payload?.headers?.find((header) => header.name?.toLowerCase() === 'message-id')?.value ??\n undefined,\n };\n}\n"]}
|
|
@@ -72,6 +72,11 @@ export declare const methods: {
|
|
|
72
72
|
body: import("zod").ZodOptional<import("zod").ZodString>;
|
|
73
73
|
htmlBody: import("zod").ZodOptional<import("zod").ZodString>;
|
|
74
74
|
replyToMessageId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
75
|
+
attachments: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
|
|
76
|
+
path: import("zod").ZodString;
|
|
77
|
+
filename: import("zod").ZodOptional<import("zod").ZodString>;
|
|
78
|
+
mimeType: import("zod").ZodOptional<import("zod").ZodString>;
|
|
79
|
+
}, import("zod/v4/core").$strict>>>;
|
|
75
80
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
76
81
|
id: import("zod").ZodString;
|
|
77
82
|
snippet: import("zod").ZodOptional<import("zod").ZodString>;
|
|
@@ -198,6 +203,11 @@ export declare const methods: {
|
|
|
198
203
|
subject: import("zod").ZodOptional<import("zod").ZodString>;
|
|
199
204
|
body: import("zod").ZodOptional<import("zod").ZodString>;
|
|
200
205
|
htmlBody: import("zod").ZodOptional<import("zod").ZodString>;
|
|
206
|
+
attachments: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
|
|
207
|
+
path: import("zod").ZodString;
|
|
208
|
+
filename: import("zod").ZodOptional<import("zod").ZodString>;
|
|
209
|
+
mimeType: import("zod").ZodOptional<import("zod").ZodString>;
|
|
210
|
+
}, import("zod/v4/core").$strict>>>;
|
|
201
211
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
202
212
|
id: import("zod").ZodString;
|
|
203
213
|
subject: import("zod").ZodOptional<import("zod").ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/gmail/methods/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AA0BlD;;;;;;GAMG;AACH,eAAO,MAAM,OAAO
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/gmail/methods/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AA0BlD;;;;;;GAMG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BoC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAK7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,wBAAsB,OAAO,CAC3B,KAAK,EAAE,QAAQ,CAAC,KAAK,EACrB,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,GACjC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAmBxC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { forGoogle } from '../../../lib/optionality.js';
|
|
2
|
+
import { loadAttachments } from '../../lib/attachment.js';
|
|
2
3
|
import { buildRawMessage, projectMessage, resolveReplyContext } from '../../lib/message.js';
|
|
3
4
|
import { senderAddress } from '../../lib/profile.js';
|
|
4
5
|
export async function handler(gmail, args) {
|
|
@@ -12,6 +13,7 @@ export async function handler(gmail, args) {
|
|
|
12
13
|
body: args.body,
|
|
13
14
|
htmlBody: args.htmlBody,
|
|
14
15
|
inReplyTo,
|
|
16
|
+
attachments: await loadAttachments(args.attachments),
|
|
15
17
|
});
|
|
16
18
|
const { data } = await gmail.users.messages.send(forGoogle({ userId: 'me', requestBody: forGoogle({ raw, threadId }) }));
|
|
17
19
|
return projectMessage(data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,KAAqB,EACrB,IAAkC;IAElC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAExF,MAAM,GAAG,GAAG,eAAe,CAAC;QAC1B,IAAI,EAAE,MAAM,aAAa,CAAC,KAAK,CAAC;QAChC,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,SAAS;
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,KAAqB,EACrB,IAAkC;IAElC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAExF,MAAM,GAAG,GAAG,eAAe,CAAC;QAC1B,IAAI,EAAE,MAAM,aAAa,CAAC,KAAK,CAAC;QAChC,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,SAAS;QACT,WAAW,EAAE,MAAM,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC;KACrD,CAAC,CAAC;IAEH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAC9C,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CACvE,CAAC;IACF,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import type { gmail_v1 } from '@googleapis/gmail';\nimport type { z } from 'zod';\nimport { forGoogle } from '../../../lib/optionality.js';\nimport { loadAttachments } from '../../lib/attachment.js';\nimport { buildRawMessage, projectMessage, resolveReplyContext } from '../../lib/message.js';\nimport { senderAddress } from '../../lib/profile.js';\nimport type { schema } from './schema.js';\n\nexport async function handler(\n gmail: gmail_v1.Gmail,\n args: z.infer<typeof schema.input>,\n): Promise<z.infer<typeof schema.output>> {\n const { threadId, inReplyTo } = await resolveReplyContext(gmail, args.replyToMessageId);\n\n const raw = buildRawMessage({\n from: await senderAddress(gmail),\n to: args.to,\n cc: args.cc,\n bcc: args.bcc,\n subject: args.subject,\n body: args.body,\n htmlBody: args.htmlBody,\n inReplyTo,\n attachments: await loadAttachments(args.attachments),\n });\n\n const { data } = await gmail.users.messages.send(\n forGoogle({ userId: 'me', requestBody: forGoogle({ raw, threadId }) }),\n );\n return projectMessage(data);\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Irreversible: assembles an RFC 822 message and sends it immediately. When
|
|
3
3
|
* `replyToMessageId` is given, the original is fetched for its thread and
|
|
4
|
-
* Message-ID so the reply threads correctly.
|
|
4
|
+
* Message-ID so the reply threads correctly. When `attachments` is given, the
|
|
5
|
+
* named local files are read and assembled into the raw message (issue #101).
|
|
5
6
|
*/
|
|
6
7
|
export declare const send_message: import("../../../lib/operation.js").Operation<import("@googleapis/gmail").gmail_v1.Gmail, import("zod").ZodObject<{
|
|
7
8
|
to: import("zod").ZodArray<import("zod").ZodString>;
|
|
@@ -11,6 +12,11 @@ export declare const send_message: import("../../../lib/operation.js").Operation
|
|
|
11
12
|
body: import("zod").ZodOptional<import("zod").ZodString>;
|
|
12
13
|
htmlBody: import("zod").ZodOptional<import("zod").ZodString>;
|
|
13
14
|
replyToMessageId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
15
|
+
attachments: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
|
|
16
|
+
path: import("zod").ZodString;
|
|
17
|
+
filename: import("zod").ZodOptional<import("zod").ZodString>;
|
|
18
|
+
mimeType: import("zod").ZodOptional<import("zod").ZodString>;
|
|
19
|
+
}, import("zod/v4/core").$strict>>>;
|
|
14
20
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
15
21
|
id: import("zod").ZodString;
|
|
16
22
|
snippet: import("zod").ZodOptional<import("zod").ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/index.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/index.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAWvB,CAAC"}
|
|
@@ -4,10 +4,11 @@ import { schema } from './schema.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Irreversible: assembles an RFC 822 message and sends it immediately. When
|
|
6
6
|
* `replyToMessageId` is given, the original is fetched for its thread and
|
|
7
|
-
* Message-ID so the reply threads correctly.
|
|
7
|
+
* Message-ID so the reply threads correctly. When `attachments` is given, the
|
|
8
|
+
* named local files are read and assembled into the raw message (issue #101).
|
|
8
9
|
*/
|
|
9
10
|
export const send_message = gmailOperation({
|
|
10
|
-
description: 'Send an email immediately.',
|
|
11
|
+
description: 'Send an email immediately, optionally attaching local files.',
|
|
11
12
|
annotations: {
|
|
12
13
|
readOnlyHint: false,
|
|
13
14
|
destructiveHint: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;IACzC,WAAW,EAAE,8DAA8D;IAC3E,WAAW,EAAE;QACX,YAAY,EAAE,KAAK;QACnB,eAAe,EAAE,IAAI;QACrB,cAAc,EAAE,KAAK;QACrB,aAAa,EAAE,IAAI;KACpB;IACD,MAAM,EAAE,yFAAyF;IACjG,MAAM;IACN,OAAO;CACR,CAAC,CAAC","sourcesContent":["import { gmailOperation } from '../../operation.js';\nimport { handler } from './handler.js';\nimport { schema } from './schema.js';\n\n/**\n * Irreversible: assembles an RFC 822 message and sends it immediately. When\n * `replyToMessageId` is given, the original is fetched for its thread and\n * Message-ID so the reply threads correctly. When `attachments` is given, the\n * named local files are read and assembled into the raw message (issue #101).\n */\nexport const send_message = gmailOperation({\n description: 'Send an email immediately, optionally attaching local files.',\n annotations: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: true,\n },\n source: 'https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages/send',\n schema,\n handler,\n});\n"]}
|
|
@@ -8,6 +8,11 @@ export declare const schema: {
|
|
|
8
8
|
body: z.ZodOptional<z.ZodString>;
|
|
9
9
|
htmlBody: z.ZodOptional<z.ZodString>;
|
|
10
10
|
replyToMessageId: z.ZodOptional<z.ZodString>;
|
|
11
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
12
|
+
path: z.ZodString;
|
|
13
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
14
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strict>>>;
|
|
11
16
|
}, z.core.$strict>;
|
|
12
17
|
output: z.ZodObject<{
|
|
13
18
|
id: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,MAAM;IACjB,KAAK;;;;;;;;;;;;;;IAUL,MAAM;;;;;;;;;;;;;;;;;;;;;CACP,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { AttachmentFile } from '../../entities/AttachmentFile.js';
|
|
2
3
|
import { Message } from '../../entities/Message.js';
|
|
4
|
+
import { ATTACHMENTS_PARAM_DESCRIPTION } from '../../lib/attachment.js';
|
|
3
5
|
import { headerSafe } from '../../lib/headers.js';
|
|
4
6
|
export const schema = {
|
|
5
7
|
input: z.strictObject({
|
|
@@ -10,6 +12,7 @@ export const schema = {
|
|
|
10
12
|
body: z.string().optional().describe('Plain-text content.'),
|
|
11
13
|
htmlBody: z.string().optional().describe('HTML content.'),
|
|
12
14
|
replyToMessageId: headerSafe.optional().describe('Id of the message being replied to.'),
|
|
15
|
+
attachments: z.array(AttachmentFile).optional().describe(ATTACHMENTS_PARAM_DESCRIPTION),
|
|
13
16
|
}),
|
|
14
17
|
output: Message,
|
|
15
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC;QACpB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC9D,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC7D,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC/D,OAAO,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC5D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC3D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;QACzD,gBAAgB,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;KACxF,CAAC;IACF,MAAM,EAAE,OAAO;CAChB,CAAC","sourcesContent":["import { z } from 'zod';\nimport { Message } from '../../entities/Message.js';\nimport { headerSafe } from '../../lib/headers.js';\n\nexport const schema = {\n input: z.strictObject({\n to: z.array(headerSafe).min(1).describe('Primary recipients.'),\n cc: z.array(headerSafe).optional().describe('Cc recipients.'),\n bcc: z.array(headerSafe).optional().describe('Bcc recipients.'),\n subject: headerSafe.optional().describe('The subject line.'),\n body: z.string().optional().describe('Plain-text content.'),\n htmlBody: z.string().optional().describe('HTML content.'),\n replyToMessageId: headerSafe.optional().describe('Id of the message being replied to.'),\n }),\n output: Message,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/gmail/methods/send_message/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC;QACpB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC9D,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC7D,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC/D,OAAO,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC5D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC3D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;QACzD,gBAAgB,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;QACvF,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;KACxF,CAAC;IACF,MAAM,EAAE,OAAO;CAChB,CAAC","sourcesContent":["import { z } from 'zod';\nimport { AttachmentFile } from '../../entities/AttachmentFile.js';\nimport { Message } from '../../entities/Message.js';\nimport { ATTACHMENTS_PARAM_DESCRIPTION } from '../../lib/attachment.js';\nimport { headerSafe } from '../../lib/headers.js';\n\nexport const schema = {\n input: z.strictObject({\n to: z.array(headerSafe).min(1).describe('Primary recipients.'),\n cc: z.array(headerSafe).optional().describe('Cc recipients.'),\n bcc: z.array(headerSafe).optional().describe('Bcc recipients.'),\n subject: headerSafe.optional().describe('The subject line.'),\n body: z.string().optional().describe('Plain-text content.'),\n htmlBody: z.string().optional().describe('HTML content.'),\n replyToMessageId: headerSafe.optional().describe('Id of the message being replied to.'),\n attachments: z.array(AttachmentFile).optional().describe(ATTACHMENTS_PARAM_DESCRIPTION),\n }),\n output: Message,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAI7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,wBAAsB,OAAO,CAC3B,KAAK,EAAE,QAAQ,CAAC,KAAK,EACrB,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,GACjC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAsBxC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { loadAttachments } from '../../lib/attachment.js';
|
|
1
2
|
import { buildRawMessage, projectDraft } from '../../lib/message.js';
|
|
2
3
|
import { senderAddress } from '../../lib/profile.js';
|
|
3
4
|
export async function handler(gmail, args) {
|
|
@@ -9,6 +10,7 @@ export async function handler(gmail, args) {
|
|
|
9
10
|
subject: args.subject,
|
|
10
11
|
body: args.body,
|
|
11
12
|
htmlBody: args.htmlBody,
|
|
13
|
+
attachments: await loadAttachments(args.attachments),
|
|
12
14
|
});
|
|
13
15
|
await gmail.users.drafts.update({
|
|
14
16
|
userId: 'me',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EA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;QACZ,EAAE,EAAE,IAAI,CAAC,OAAO;QAChB,WAAW,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE;KAClC,CAAC,CAAC;IACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;QAC5C,MAAM,EAAE,IAAI;QACZ,EAAE,EAAE,IAAI,CAAC,OAAO;QAChB,MAAM,EAAE,MAAM;KACf,CAAC,CAAC;IACH,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import type { gmail_v1 } from '@googleapis/gmail';\nimport type { z } from 'zod';\nimport { loadAttachments } from '../../lib/attachment.js';\nimport { buildRawMessage, projectDraft } from '../../lib/message.js';\nimport { senderAddress } from '../../lib/profile.js';\nimport type { schema } from './schema.js';\n\nexport async function handler(\n gmail: gmail_v1.Gmail,\n args: z.infer<typeof schema.input>,\n): Promise<z.infer<typeof schema.output>> {\n const raw = buildRawMessage({\n from: await senderAddress(gmail),\n to: args.to,\n cc: args.cc,\n bcc: args.bcc,\n subject: args.subject,\n body: args.body,\n htmlBody: args.htmlBody,\n attachments: await loadAttachments(args.attachments),\n });\n await gmail.users.drafts.update({\n userId: 'me',\n id: args.draftId,\n requestBody: { message: { raw } },\n });\n const { data } = await gmail.users.drafts.get({\n userId: 'me',\n id: args.draftId,\n format: 'full',\n });\n return projectDraft(data);\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Replaces the draft's content with a freshly assembled message, then re-fetches
|
|
3
|
-
* it `full` for projection.
|
|
3
|
+
* it `full` for projection. When `attachments` is given, the named local files
|
|
4
|
+
* are read and assembled into the raw message (issue #101).
|
|
4
5
|
*/
|
|
5
6
|
export declare const update_draft: import("../../../lib/operation.js").Operation<import("@googleapis/gmail").gmail_v1.Gmail, import("zod").ZodObject<{
|
|
6
7
|
draftId: import("zod").ZodString;
|
|
@@ -10,6 +11,11 @@ export declare const update_draft: import("../../../lib/operation.js").Operation
|
|
|
10
11
|
subject: import("zod").ZodOptional<import("zod").ZodString>;
|
|
11
12
|
body: import("zod").ZodOptional<import("zod").ZodString>;
|
|
12
13
|
htmlBody: import("zod").ZodOptional<import("zod").ZodString>;
|
|
14
|
+
attachments: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
|
|
15
|
+
path: import("zod").ZodString;
|
|
16
|
+
filename: import("zod").ZodOptional<import("zod").ZodString>;
|
|
17
|
+
mimeType: import("zod").ZodOptional<import("zod").ZodString>;
|
|
18
|
+
}, import("zod/v4/core").$strict>>>;
|
|
13
19
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
14
20
|
id: import("zod").ZodString;
|
|
15
21
|
subject: import("zod").ZodOptional<import("zod").ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/index.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/index.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAWvB,CAAC"}
|
|
@@ -3,10 +3,11 @@ import { handler } from './handler.js';
|
|
|
3
3
|
import { schema } from './schema.js';
|
|
4
4
|
/**
|
|
5
5
|
* Replaces the draft's content with a freshly assembled message, then re-fetches
|
|
6
|
-
* it `full` for projection.
|
|
6
|
+
* it `full` for projection. When `attachments` is given, the named local files
|
|
7
|
+
* are read and assembled into the raw message (issue #101).
|
|
7
8
|
*/
|
|
8
9
|
export const update_draft = gmailOperation({
|
|
9
|
-
description: 'Replace the content of an existing draft.',
|
|
10
|
+
description: 'Replace the content of an existing draft, optionally attaching local files.',
|
|
10
11
|
annotations: {
|
|
11
12
|
readOnlyHint: false,
|
|
12
13
|
destructiveHint: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;IACzC,WAAW,EAAE,6EAA6E;IAC1F,WAAW,EAAE;QACX,YAAY,EAAE,KAAK;QACnB,eAAe,EAAE,KAAK;QACtB,cAAc,EAAE,IAAI;QACpB,aAAa,EAAE,KAAK;KACrB;IACD,MAAM,EAAE,yFAAyF;IACjG,MAAM;IACN,OAAO;CACR,CAAC,CAAC","sourcesContent":["import { gmailOperation } from '../../operation.js';\nimport { handler } from './handler.js';\nimport { schema } from './schema.js';\n\n/**\n * Replaces the draft's content with a freshly assembled message, then re-fetches\n * it `full` for projection. When `attachments` is given, the named local files\n * are read and assembled into the raw message (issue #101).\n */\nexport const update_draft = gmailOperation({\n description: 'Replace the content of an existing draft, optionally attaching local files.',\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n source: 'https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.drafts/update',\n schema,\n handler,\n});\n"]}
|
|
@@ -8,6 +8,11 @@ export declare const schema: {
|
|
|
8
8
|
subject: z.ZodOptional<z.ZodString>;
|
|
9
9
|
body: z.ZodOptional<z.ZodString>;
|
|
10
10
|
htmlBody: z.ZodOptional<z.ZodString>;
|
|
11
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
12
|
+
path: z.ZodString;
|
|
13
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
14
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strict>>>;
|
|
11
16
|
}, z.core.$strict>;
|
|
12
17
|
output: z.ZodObject<{
|
|
13
18
|
id: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,MAAM;IACjB,KAAK;;;;;;;;;;;;;;IAaL,MAAM;;;;;;;;;;;;;;;;;;;;CACP,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { AttachmentFile } from '../../entities/AttachmentFile.js';
|
|
2
3
|
import { Draft } from '../../entities/Draft.js';
|
|
4
|
+
import { ATTACHMENTS_PARAM_DESCRIPTION } from '../../lib/attachment.js';
|
|
3
5
|
import { headerSafe } from '../../lib/headers.js';
|
|
4
6
|
export const schema = {
|
|
5
7
|
input: z.strictObject({
|
|
@@ -13,6 +15,7 @@ export const schema = {
|
|
|
13
15
|
subject: headerSafe.optional().describe('The subject line.'),
|
|
14
16
|
body: z.string().optional().describe('Plain-text content.'),
|
|
15
17
|
htmlBody: z.string().optional().describe('HTML content.'),
|
|
18
|
+
attachments: z.array(AttachmentFile).optional().describe(ATTACHMENTS_PARAM_DESCRIPTION),
|
|
16
19
|
}),
|
|
17
20
|
output: Draft,
|
|
18
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC;QACpB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;QAC/D,EAAE,EAAE,CAAC;aACF,KAAK,CAAC,UAAU,CAAC;aACjB,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CAAC,0DAA0D,CAAC;QACvE,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC7D,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC/D,OAAO,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC5D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC3D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/gmail/methods/update_draft/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC;QACpB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;QAC/D,EAAE,EAAE,CAAC;aACF,KAAK,CAAC,UAAU,CAAC;aACjB,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CAAC,0DAA0D,CAAC;QACvE,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC7D,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC/D,OAAO,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC5D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC3D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;QACzD,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;KACxF,CAAC;IACF,MAAM,EAAE,KAAK;CACd,CAAC","sourcesContent":["import { z } from 'zod';\nimport { AttachmentFile } from '../../entities/AttachmentFile.js';\nimport { Draft } from '../../entities/Draft.js';\nimport { ATTACHMENTS_PARAM_DESCRIPTION } from '../../lib/attachment.js';\nimport { headerSafe } from '../../lib/headers.js';\n\nexport const schema = {\n input: z.strictObject({\n draftId: z.string().describe('The id of the draft to replace.'),\n to: z\n .array(headerSafe)\n .min(1)\n .describe('Primary recipients (the draft is replaced, not patched).'),\n cc: z.array(headerSafe).optional().describe('Cc recipients.'),\n bcc: z.array(headerSafe).optional().describe('Bcc recipients.'),\n subject: headerSafe.optional().describe('The subject line.'),\n body: z.string().optional().describe('Plain-text content.'),\n htmlBody: z.string().optional().describe('HTML content.'),\n attachments: z.array(AttachmentFile).optional().describe(ATTACHMENTS_PARAM_DESCRIPTION),\n }),\n output: Draft,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAK7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,wBAAsB,OAAO,CAC3B,KAAK,EAAE,QAAQ,CAAC,KAAK,EACrB,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,GACjC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAwBxC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { forGoogle } from '../../../lib/optionality.js';
|
|
2
|
+
import { loadAttachments } from '../../lib/attachment.js';
|
|
2
3
|
import { buildRawMessage, projectDraft, resolveReplyContext } from '../../lib/message.js';
|
|
3
4
|
import { senderAddress } from '../../lib/profile.js';
|
|
4
5
|
export async function handler(gmail, args) {
|
|
@@ -12,6 +13,7 @@ export async function handler(gmail, args) {
|
|
|
12
13
|
body: args.body,
|
|
13
14
|
htmlBody: args.htmlBody,
|
|
14
15
|
inReplyTo,
|
|
16
|
+
attachments: await loadAttachments(args.attachments),
|
|
15
17
|
});
|
|
16
18
|
const created = await gmail.users.drafts.create({
|
|
17
19
|
userId: 'me',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,KAAqB,EACrB,IAAkC;IAElC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAExF,MAAM,GAAG,GAAG,eAAe,CAAC;QAC1B,IAAI,EAAE,MAAM,aAAa,CAAC,KAAK,CAAC;QAChC,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,SAAS;
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,M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type { gmail_v1 } from '@googleapis/gmail';\nimport type { z } from 'zod';\nimport { forGoogle } from '../../../lib/optionality.js';\nimport { loadAttachments } from '../../lib/attachment.js';\nimport { buildRawMessage, projectDraft, resolveReplyContext } from '../../lib/message.js';\nimport { senderAddress } from '../../lib/profile.js';\nimport type { schema } from './schema.js';\n\nexport async function handler(\n gmail: gmail_v1.Gmail,\n args: z.infer<typeof schema.input>,\n): Promise<z.infer<typeof schema.output>> {\n const { threadId, inReplyTo } = await resolveReplyContext(gmail, args.replyToMessageId);\n\n const raw = buildRawMessage({\n from: await senderAddress(gmail),\n to: args.to,\n cc: args.cc,\n bcc: args.bcc,\n subject: args.subject,\n body: args.body,\n htmlBody: args.htmlBody,\n inReplyTo,\n attachments: await loadAttachments(args.attachments),\n });\n\n const created = await gmail.users.drafts.create({\n userId: 'me',\n requestBody: { message: forGoogle({ raw, threadId }) },\n });\n\n const { data } = await gmail.users.drafts.get(\n forGoogle({ userId: 'me', id: created.data.id ?? undefined, format: 'full' }),\n );\n return projectDraft(data);\n}\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Assembles an RFC 822 message and creates a draft. When `replyToMessageId` is
|
|
3
3
|
* given, the original is fetched for its thread and Message-ID so the draft
|
|
4
|
-
* threads correctly.
|
|
4
|
+
* threads correctly. When `attachments` is given, the named local files are
|
|
5
|
+
* read and assembled into the raw message (issue #101). The created draft is
|
|
6
|
+
* re-fetched `full` for projection.
|
|
5
7
|
*/
|
|
6
8
|
export declare const create_draft: import("../../../lib/operation.js").Operation<import("@googleapis/gmail").gmail_v1.Gmail, import("zod").ZodObject<{
|
|
7
9
|
to: import("zod").ZodArray<import("zod").ZodString>;
|
|
@@ -11,6 +13,11 @@ export declare const create_draft: import("../../../lib/operation.js").Operation
|
|
|
11
13
|
body: import("zod").ZodOptional<import("zod").ZodString>;
|
|
12
14
|
htmlBody: import("zod").ZodOptional<import("zod").ZodString>;
|
|
13
15
|
replyToMessageId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
16
|
+
attachments: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
|
|
17
|
+
path: import("zod").ZodString;
|
|
18
|
+
filename: import("zod").ZodOptional<import("zod").ZodString>;
|
|
19
|
+
mimeType: import("zod").ZodOptional<import("zod").ZodString>;
|
|
20
|
+
}, import("zod/v4/core").$strict>>>;
|
|
14
21
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
15
22
|
id: import("zod").ZodString;
|
|
16
23
|
subject: import("zod").ZodOptional<import("zod").ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/index.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/index.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAWvB,CAAC"}
|
|
@@ -4,10 +4,12 @@ import { schema } from './schema.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Assembles an RFC 822 message and creates a draft. When `replyToMessageId` is
|
|
6
6
|
* given, the original is fetched for its thread and Message-ID so the draft
|
|
7
|
-
* threads correctly.
|
|
7
|
+
* threads correctly. When `attachments` is given, the named local files are
|
|
8
|
+
* read and assembled into the raw message (issue #101). The created draft is
|
|
9
|
+
* re-fetched `full` for projection.
|
|
8
10
|
*/
|
|
9
11
|
export const create_draft = gmailOperation({
|
|
10
|
-
description: 'Create a draft email.',
|
|
12
|
+
description: 'Create a draft email, optionally attaching local files.',
|
|
11
13
|
annotations: {
|
|
12
14
|
readOnlyHint: false,
|
|
13
15
|
destructiveHint: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;IACzC,WAAW,EAAE,yDAAyD;IACtE,WAAW,EAAE;QACX,YAAY,EAAE,KAAK;QACnB,eAAe,EAAE,KAAK;QACtB,cAAc,EAAE,KAAK;QACrB,aAAa,EAAE,KAAK;KACrB;IACD,MAAM,EAAE,yFAAyF;IACjG,MAAM;IACN,OAAO;CACR,CAAC,CAAC","sourcesContent":["import { gmailOperation } from '../../operation.js';\nimport { handler } from './handler.js';\nimport { schema } from './schema.js';\n\n/**\n * Assembles an RFC 822 message and creates a draft. When `replyToMessageId` is\n * given, the original is fetched for its thread and Message-ID so the draft\n * threads correctly. When `attachments` is given, the named local files are\n * read and assembled into the raw message (issue #101). The created draft is\n * re-fetched `full` for projection.\n */\nexport const create_draft = gmailOperation({\n description: 'Create a draft email, optionally attaching local files.',\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n },\n source: 'https://developers.google.com/workspace/gmail/api/reference/mcp/tools_list/create_draft',\n schema,\n handler,\n});\n"]}
|
|
@@ -8,6 +8,11 @@ export declare const schema: {
|
|
|
8
8
|
body: z.ZodOptional<z.ZodString>;
|
|
9
9
|
htmlBody: z.ZodOptional<z.ZodString>;
|
|
10
10
|
replyToMessageId: z.ZodOptional<z.ZodString>;
|
|
11
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
12
|
+
path: z.ZodString;
|
|
13
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
14
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strict>>>;
|
|
11
16
|
}, z.core.$strict>;
|
|
12
17
|
output: z.ZodObject<{
|
|
13
18
|
id: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,MAAM;IACjB,KAAK;;;;;;;;;;;;;;IAUL,MAAM;;;;;;;;;;;;;;;;;;;;CACP,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { AttachmentFile } from '../../entities/AttachmentFile.js';
|
|
2
3
|
import { Draft } from '../../entities/Draft.js';
|
|
4
|
+
import { ATTACHMENTS_PARAM_DESCRIPTION } from '../../lib/attachment.js';
|
|
3
5
|
import { headerSafe } from '../../lib/headers.js';
|
|
4
6
|
export const schema = {
|
|
5
7
|
input: z.strictObject({
|
|
@@ -10,6 +12,7 @@ export const schema = {
|
|
|
10
12
|
body: z.string().optional().describe('Plain-text content.'),
|
|
11
13
|
htmlBody: z.string().optional().describe('HTML content.'),
|
|
12
14
|
replyToMessageId: headerSafe.optional().describe('Id of the message being replied to.'),
|
|
15
|
+
attachments: z.array(AttachmentFile).optional().describe(ATTACHMENTS_PARAM_DESCRIPTION),
|
|
13
16
|
}),
|
|
14
17
|
output: Draft,
|
|
15
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC;QACpB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC9D,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC7D,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC/D,OAAO,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC5D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC3D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;QACzD,gBAAgB,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;KACxF,CAAC;IACF,MAAM,EAAE,KAAK;CACd,CAAC","sourcesContent":["import { z } from 'zod';\nimport { Draft } from '../../entities/Draft.js';\nimport { headerSafe } from '../../lib/headers.js';\n\nexport const schema = {\n input: z.strictObject({\n to: z.array(headerSafe).min(1).describe('Primary recipients.'),\n cc: z.array(headerSafe).optional().describe('Cc recipients.'),\n bcc: z.array(headerSafe).optional().describe('Bcc recipients.'),\n subject: headerSafe.optional().describe('The subject line.'),\n body: z.string().optional().describe('Plain-text content.'),\n htmlBody: z.string().optional().describe('HTML content.'),\n replyToMessageId: headerSafe.optional().describe('Id of the message being replied to.'),\n }),\n output: Draft,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/gmail/tools/create_draft/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC;QACpB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC9D,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC7D,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC/D,OAAO,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC5D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC3D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;QACzD,gBAAgB,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;QACvF,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;KACxF,CAAC;IACF,MAAM,EAAE,KAAK;CACd,CAAC","sourcesContent":["import { z } from 'zod';\nimport { AttachmentFile } from '../../entities/AttachmentFile.js';\nimport { Draft } from '../../entities/Draft.js';\nimport { ATTACHMENTS_PARAM_DESCRIPTION } from '../../lib/attachment.js';\nimport { headerSafe } from '../../lib/headers.js';\n\nexport const schema = {\n input: z.strictObject({\n to: z.array(headerSafe).min(1).describe('Primary recipients.'),\n cc: z.array(headerSafe).optional().describe('Cc recipients.'),\n bcc: z.array(headerSafe).optional().describe('Bcc recipients.'),\n subject: headerSafe.optional().describe('The subject line.'),\n body: z.string().optional().describe('Plain-text content.'),\n htmlBody: z.string().optional().describe('HTML content.'),\n replyToMessageId: headerSafe.optional().describe('Id of the message being replied to.'),\n attachments: z.array(AttachmentFile).optional().describe(ATTACHMENTS_PARAM_DESCRIPTION),\n }),\n output: Draft,\n};\n"]}
|
|
@@ -104,6 +104,11 @@ export declare const tools: {
|
|
|
104
104
|
body: import("zod").ZodOptional<import("zod").ZodString>;
|
|
105
105
|
htmlBody: import("zod").ZodOptional<import("zod").ZodString>;
|
|
106
106
|
replyToMessageId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
107
|
+
attachments: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
|
|
108
|
+
path: import("zod").ZodString;
|
|
109
|
+
filename: import("zod").ZodOptional<import("zod").ZodString>;
|
|
110
|
+
mimeType: import("zod").ZodOptional<import("zod").ZodString>;
|
|
111
|
+
}, import("zod/v4/core").$strict>>>;
|
|
107
112
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
108
113
|
id: import("zod").ZodString;
|
|
109
114
|
subject: import("zod").ZodOptional<import("zod").ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/gmail/tools/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAalD;;;GAGG;AACH,eAAO,MAAM,KAAK
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/gmail/tools/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAalD;;;GAGG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWsC,CAAC"}
|
package/dist/lib/limits.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The decoded-size ceiling for base64-in-JSON content transfers: 25 MiB,
|
|
3
3
|
* Gmail's attachment maximum and the suite's de facto boundary for bytes that
|
|
4
|
-
* must buffer whole into a JSON string. Drive's blob paths
|
|
5
|
-
* attachment download
|
|
6
|
-
*
|
|
7
|
-
* export
|
|
4
|
+
* must buffer whole into a JSON string. Drive's blob paths, Gmail's
|
|
5
|
+
* attachment download, and Gmail's compose attachments (outbound bytes buffer
|
|
6
|
+
* whole into the raw message the same way) enforce it via
|
|
7
|
+
* `assertWithinDownloadCap`; Drive's Google-native export paths are exempt,
|
|
8
|
+
* bounded instead by Google's own export cap (about 10 MB).
|
|
8
9
|
*/
|
|
9
10
|
export declare const MAX_DOWNLOAD_BYTES: number;
|
|
11
|
+
/** The ceiling rendered as prose, one spelling for error and schema text alike. */
|
|
12
|
+
export declare const MIB_LABEL = "25 MiB";
|
|
10
13
|
/**
|
|
11
14
|
* Refuse a transfer over the suite ceiling. One construction site for every
|
|
12
15
|
* cap error, so the prose cannot drift from the constant; the options object
|
package/dist/lib/limits.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/lib/limits.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/lib/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,QAAmB,CAAC;AAEnD,mFAAmF;AACnF,eAAO,MAAM,SAAS,WAA8C,CAAC;AAErE;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACxC,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,WAAW,MAAM,EAAE,CAAA;CAAE,GAC3E,IAAI,CASN"}
|
package/dist/lib/limits.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The decoded-size ceiling for base64-in-JSON content transfers: 25 MiB,
|
|
3
3
|
* Gmail's attachment maximum and the suite's de facto boundary for bytes that
|
|
4
|
-
* must buffer whole into a JSON string. Drive's blob paths
|
|
5
|
-
* attachment download
|
|
6
|
-
*
|
|
7
|
-
* export
|
|
4
|
+
* must buffer whole into a JSON string. Drive's blob paths, Gmail's
|
|
5
|
+
* attachment download, and Gmail's compose attachments (outbound bytes buffer
|
|
6
|
+
* whole into the raw message the same way) enforce it via
|
|
7
|
+
* `assertWithinDownloadCap`; Drive's Google-native export paths are exempt,
|
|
8
|
+
* bounded instead by Google's own export cap (about 10 MB).
|
|
8
9
|
*/
|
|
9
10
|
export const MAX_DOWNLOAD_BYTES = 25 * 1024 * 1024;
|
|
10
|
-
|
|
11
|
+
/** The ceiling rendered as prose, one spelling for error and schema text alike. */
|
|
12
|
+
export const MIB_LABEL = `${MAX_DOWNLOAD_BYTES / (1024 * 1024)} MiB`;
|
|
11
13
|
/**
|
|
12
14
|
* Refuse a transfer over the suite ceiling. One construction site for every
|
|
13
15
|
* cap error, so the prose cannot drift from the constant; the options object
|
package/dist/lib/limits.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../../src/lib/limits.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../../src/lib/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEnD,mFAAmF;AACnF,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,kBAAkB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;AAErE;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAAwC,EACxC,OAA4E;IAE5E,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IACrC,IAAI,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,kBAAkB,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CACb,GAAG,OAAO,CAAC,OAAO,OAAO,UAAU,4BAA4B,OAAO,CAAC,MAAM,MAAM;YACjF,GAAG,kBAAkB,WAAW,SAAS,IAAI;YAC7C,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,qCAAqC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CACrF,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/**\n * The decoded-size ceiling for base64-in-JSON content transfers: 25 MiB,\n * Gmail's attachment maximum and the suite's de facto boundary for bytes that\n * must buffer whole into a JSON string. Drive's blob paths, Gmail's\n * attachment download, and Gmail's compose attachments (outbound bytes buffer\n * whole into the raw message the same way) enforce it via\n * `assertWithinDownloadCap`; Drive's Google-native export paths are exempt,\n * bounded instead by Google's own export cap (about 10 MB).\n */\nexport const MAX_DOWNLOAD_BYTES = 25 * 1024 * 1024;\n\n/** The ceiling rendered as prose, one spelling for error and schema text alike. */\nexport const MIB_LABEL = `${MAX_DOWNLOAD_BYTES / (1024 * 1024)} MiB`;\n\n/**\n * Refuse a transfer over the suite ceiling. One construction site for every\n * cap error, so the prose cannot drift from the constant; the options object\n * keeps a swapped subject/action unrepresentable. `size` may be Google's\n * string-typed metadata size; a non-finite value passes (the caller re-checks\n * the bytes that actually arrive, which contains a malformed size to a wasted\n * transfer, never an oversize output). `deferral` cites a wing's tracking\n * issue where larger transfers are deferred.\n */\nexport function assertWithinDownloadCap(\n size: number | string | null | undefined,\n options: { subject: string; action: string; deferral?: `https://${string}` },\n): void {\n const byteLength = Number(size ?? 0);\n if (Number.isFinite(byteLength) && byteLength > MAX_DOWNLOAD_BYTES) {\n throw new Error(\n `${options.subject} is ${byteLength} bytes; this server caps ${options.action} at ` +\n `${MAX_DOWNLOAD_BYTES} bytes (${MIB_LABEL}).` +\n (options.deferral ? ` Larger transfers are deferred to ${options.deferral}.` : ''),\n );\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "google-mcp-suite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Google Workspace MCP servers for AI agents, one per service per account: Gmail, Google Calendar, Google Drive, Google Docs, and Google Sheets. Identity is bound to the running instance, so an agent (Claude, Cursor, or any MCP client) can never act on the wrong account; each server exposes Google's curated MCP toolset (where one exists) plus the broader REST surface.",
|
|
6
6
|
"keywords": [
|