@ghostpaw/email 0.5.4 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,8 +32,59 @@ var init_surface_types = __esm({
32
32
  }
33
33
  });
34
34
 
35
+ // src/surfaces/schema_example.ts
36
+ function schemaExample(schema, seed = {}) {
37
+ if (schema.oneOf) {
38
+ const branch = schema.oneOf.find(
39
+ (candidate) => Object.entries(seed).every(([key, value]) => {
40
+ const values = candidate.properties?.[key]?.enum;
41
+ return !values || values.includes(value);
42
+ })
43
+ );
44
+ return schemaExample({ ...schema, ...branch, oneOf: void 0 }, seed);
45
+ }
46
+ if (schema.enum) return schema.enum[0];
47
+ if (schema.type === "object") {
48
+ const result = { ...seed };
49
+ for (const key of schema.required ?? [])
50
+ if (!(key in result)) {
51
+ const property = schema.properties?.[key] ?? {};
52
+ const placeholders = {
53
+ folder: "INBOX",
54
+ destination: "Archive",
55
+ query: "invoice",
56
+ subject: "Hello",
57
+ path: "Projects",
58
+ oldPath: "Projects",
59
+ newPath: "Archive/Projects"
60
+ };
61
+ result[key] = property.type === "string" && !property.enum && placeholders[key] ? placeholders[key] : schemaExample(property);
62
+ }
63
+ return result;
64
+ }
65
+ if (schema.type === "array") return [schemaExample(schema.items ?? {})];
66
+ if (schema.type === "integer" || schema.type === "number") return 1;
67
+ if (schema.type === "boolean") return false;
68
+ return schema.description?.includes("address") ? "reader@example.com" : "example";
69
+ }
70
+ var init_schema_example = __esm({
71
+ "src/surfaces/schema_example.ts"() {
72
+ }
73
+ });
74
+
35
75
  // src/surfaces/validate_input.ts
36
76
  function validateInput(schema, input, path = "$") {
77
+ const errors = validate(schema, input, path);
78
+ if (path !== "$" || !errors.length) return errors;
79
+ const seed = {};
80
+ if (input && typeof input === "object") {
81
+ for (const key of ["action", "view"])
82
+ if (schema.properties?.[key]?.enum?.includes(input[key]))
83
+ seed[key] = input[key];
84
+ }
85
+ return errors.map((error) => `${error}; pass ${JSON.stringify(schemaExample(schema, seed))}`);
86
+ }
87
+ function validate(schema, input, path) {
37
88
  const errors = [];
38
89
  const matchesType = (type) => {
39
90
  switch (type) {
@@ -56,24 +107,33 @@ function validateInput(schema, input, path = "$") {
56
107
  }
57
108
  if (schema.enum && !schema.enum.some((value) => JSON.stringify(value) === JSON.stringify(input)))
58
109
  errors.push(`${path}: expected one of ${JSON.stringify(schema.enum)}`);
59
- if (schema.oneOf && !schema.oneOf.some((branch) => validateInput(branch, input, path).length === 0))
60
- errors.push(`${path}: must match at least one schema branch`);
110
+ if (schema.oneOf) {
111
+ const branches = schema.oneOf.map((branch) => validate(branch, input, path));
112
+ if (!branches.some((errors2) => errors2.length === 0)) {
113
+ const record = input && typeof input === "object" ? input : {};
114
+ const selected = schema.oneOf.findIndex(
115
+ (branch) => ["action", "view"].some((key) => branch.properties?.[key]?.enum?.includes(record[key]))
116
+ );
117
+ errors.push(...branches[selected >= 0 ? selected : 0] ?? []);
118
+ }
119
+ }
61
120
  if (typeof input === "object" && input !== null && !Array.isArray(input)) {
62
121
  const record = input;
63
122
  for (const name of schema.required ?? [])
64
123
  if (!Object.hasOwn(record, name)) errors.push(`${path}.${name}: required`);
65
124
  for (const [name, property] of Object.entries(schema.properties ?? {}))
66
125
  if (Object.hasOwn(record, name))
67
- errors.push(...validateInput(property, record[name], `${path}.${name}`));
126
+ errors.push(...validate(property, record[name], `${path}.${name}`));
68
127
  }
69
128
  if (Array.isArray(input) && schema.items)
70
129
  input.forEach((value, index) => {
71
- errors.push(...validateInput(schema.items, value, `${path}[${index}]`));
130
+ errors.push(...validate(schema.items, value, `${path}[${index}]`));
72
131
  });
73
132
  return errors;
74
133
  }
75
134
  var init_validate_input = __esm({
76
135
  "src/surfaces/validate_input.ts"() {
136
+ init_schema_example();
77
137
  }
78
138
  });
79
139
 
@@ -256,7 +316,7 @@ var init_mcp_stdio = __esm({
256
316
  var emailVersion;
257
317
  var init_version = __esm({
258
318
  "src/version.ts"() {
259
- emailVersion = "0.5.4";
319
+ emailVersion = "0.5.5";
260
320
  }
261
321
  });
262
322
 
@@ -1108,10 +1168,107 @@ var init_read = __esm({
1108
1168
  }
1109
1169
  });
1110
1170
 
1171
+ // src/tools/input_schema.ts
1172
+ function emailInputSchema(name, schema) {
1173
+ const discriminator = name === "mail_read" ? "view" : "action";
1174
+ const actions = schema.properties?.[discriminator]?.enum;
1175
+ if (!actions || name === "mail_sync") return schema;
1176
+ return {
1177
+ ...schema,
1178
+ oneOf: actions.map((value) => {
1179
+ const action = String(value);
1180
+ let required = [];
1181
+ let input;
1182
+ if (name === "mail_read") {
1183
+ if (action === "thread") required = ["threadId"];
1184
+ if (["message", "attachment", "eml"].includes(action)) required = ["folder", "uid"];
1185
+ } else if (name === "mail_compose") {
1186
+ if (action !== "send_draft") {
1187
+ required.push("input");
1188
+ input = {
1189
+ ...payload,
1190
+ required: ["send", "save_draft", "update_draft"].includes(action) ? ["to", "subject"] : action === "forward" ? ["to"] : []
1191
+ };
1192
+ }
1193
+ if (["reply", "forward"].includes(action)) required.push("folder", "uid");
1194
+ if (["update_draft", "send_draft"].includes(action)) required.push("uid");
1195
+ } else if (name === "mail_organize") {
1196
+ required = action === "rename_folder" ? ["oldPath", "newPath"] : action.endsWith("_folder") ? ["path"] : ["folder", "uids"];
1197
+ if (["copy", "move"].includes(action)) required.push("destination");
1198
+ if (action.endsWith("_labels")) required.push("labels");
1199
+ }
1200
+ return {
1201
+ type: "object",
1202
+ required: [...schema.required ?? [], ...required],
1203
+ properties: {
1204
+ ...schema.properties,
1205
+ [discriminator]: { ...schema.properties?.[discriminator], enum: [value] },
1206
+ ...input ? { input } : {}
1207
+ }
1208
+ };
1209
+ })
1210
+ };
1211
+ }
1212
+ var address, recipients, payload;
1213
+ var init_input_schema = __esm({
1214
+ "src/tools/input_schema.ts"() {
1215
+ address = {
1216
+ type: "object",
1217
+ required: ["address"],
1218
+ properties: {
1219
+ address: { type: "string", description: "Email address." },
1220
+ name: { type: "string", description: "Display name." }
1221
+ }
1222
+ };
1223
+ recipients = {
1224
+ type: "array",
1225
+ items: address,
1226
+ description: "Recipient addresses."
1227
+ };
1228
+ payload = {
1229
+ type: "object",
1230
+ properties: {
1231
+ from: address,
1232
+ sender: address,
1233
+ envelopeFrom: address,
1234
+ replyTo: address,
1235
+ to: recipients,
1236
+ cc: recipients,
1237
+ bcc: recipients,
1238
+ subject: { type: "string", description: "Message subject." },
1239
+ text: { type: "string", description: "Plain text body." },
1240
+ html: { type: "string", description: "HTML body." },
1241
+ replyAll: { type: "boolean", description: "Reply to all original recipients." },
1242
+ mode: { type: "string", enum: ["inline", "attachment"] },
1243
+ attachments: {
1244
+ type: "array",
1245
+ description: "Message attachments.",
1246
+ items: {
1247
+ type: "object",
1248
+ required: ["filename", "content"],
1249
+ properties: {
1250
+ filename: { type: "string" },
1251
+ content: { description: "Attachment bytes (Buffer in library calls)." },
1252
+ mimeType: { type: "string" },
1253
+ inline: { type: "boolean" },
1254
+ contentId: { type: "string" }
1255
+ }
1256
+ }
1257
+ },
1258
+ inReplyTo: { type: "string" },
1259
+ references: { type: "array", items: { type: "string" } },
1260
+ headers: { type: "object" }
1261
+ }
1262
+ };
1263
+ }
1264
+ });
1265
+
1111
1266
  // src/tools/email_tools.ts
1112
1267
  var emailTools;
1113
1268
  var init_email_tools = __esm({
1114
1269
  "src/tools/email_tools.ts"() {
1270
+ init_validate_input();
1271
+ init_input_schema();
1115
1272
  emailTools = [
1116
1273
  {
1117
1274
  name: "mail_read",
@@ -1831,6 +1988,21 @@ var init_email_tools = __esm({
1831
1988
  }
1832
1989
  }
1833
1990
  ];
1991
+ for (const tool of emailTools) {
1992
+ Object.assign(tool.inputSchema, emailInputSchema(tool.name, tool.inputSchema));
1993
+ const handler = tool.handler;
1994
+ tool.handler = async (ctx, input) => {
1995
+ const errors = validateInput(tool.inputSchema, input);
1996
+ if (errors.length)
1997
+ return {
1998
+ outcome: "error",
1999
+ summary: errors.join("; "),
2000
+ entities: [],
2001
+ nextSteps: errors
2002
+ };
2003
+ return handler(ctx, input);
2004
+ };
2005
+ }
1834
2006
  }
1835
2007
  });
1836
2008
 
@@ -2373,8 +2545,8 @@ async function authenticate(dispatcher, capabilities, config) {
2373
2545
  }
2374
2546
  if ("mechanism" in config) {
2375
2547
  const { mechanism, credentials } = config;
2376
- const payload = encodeBase64(Buffer.from(JSON.stringify(credentials), "utf8"));
2377
- const res = await dispatcher.execute("AUTHENTICATE", [mechanism, payload]);
2548
+ const payload2 = encodeBase64(Buffer.from(JSON.stringify(credentials), "utf8"));
2549
+ const res = await dispatcher.execute("AUTHENTICATE", [mechanism, payload2]);
2378
2550
  if (res.tagged.status !== "OK") {
2379
2551
  throw new EmailAuthError(`${mechanism} authentication failed`, mechanism);
2380
2552
  }
@@ -3332,23 +3504,23 @@ var init_decode_bodystructure = __esm({
3332
3504
  });
3333
3505
 
3334
3506
  // src/mime/decode_encoded_words.ts
3335
- function decodeQPayload(payload) {
3507
+ function decodeQPayload(payload2) {
3336
3508
  const bytes = [];
3337
- for (let i = 0; i < payload.length; i++) {
3338
- const c = payload[i];
3509
+ for (let i = 0; i < payload2.length; i++) {
3510
+ const c = payload2[i];
3339
3511
  if (c === "_") {
3340
3512
  bytes.push(32);
3341
3513
  continue;
3342
3514
  }
3343
- if (c === "=" && i + 2 < payload.length) {
3344
- const h = payload.slice(i + 1, i + 3);
3515
+ if (c === "=" && i + 2 < payload2.length) {
3516
+ const h = payload2.slice(i + 1, i + 3);
3345
3517
  if (/^[0-9A-Fa-f]{2}$/.test(h)) {
3346
3518
  bytes.push(Number.parseInt(h, 16));
3347
3519
  i += 2;
3348
3520
  continue;
3349
3521
  }
3350
3522
  }
3351
- bytes.push(payload.charCodeAt(i) & 255);
3523
+ bytes.push(payload2.charCodeAt(i) & 255);
3352
3524
  }
3353
3525
  return Buffer.from(bytes);
3354
3526
  }
@@ -3419,9 +3591,9 @@ function parseAddressList(items) {
3419
3591
  const mailbox = s2(addrArr[2]);
3420
3592
  const host = s2(addrArr[3]);
3421
3593
  if (!mailbox || !host) continue;
3422
- const address = `${mailbox}@${host}`;
3594
+ const address2 = `${mailbox}@${host}`;
3423
3595
  const name = nameRaw ? decodeEncodedWords(nameRaw) : void 0;
3424
- out.push(name ? { name, address } : { address });
3596
+ out.push(name ? { name, address: address2 } : { address: address2 });
3425
3597
  }
3426
3598
  return out;
3427
3599
  }
@@ -5588,11 +5760,11 @@ function populateFts(db, messageId, textPlain, textHtml) {
5588
5760
  if (!row) return;
5589
5761
  const subject = row.subject != null ? String(row.subject) : "";
5590
5762
  const sender = row.from != null ? String(row.from) : "";
5591
- const recipients = row.to != null ? String(row.to) : "";
5763
+ const recipients2 = row.to != null ? String(row.to) : "";
5592
5764
  db.exec(`DELETE FROM messages_fts WHERE rowid = ${messageId}`);
5593
5765
  db.prepare(
5594
5766
  "INSERT INTO messages_fts(rowid, subject, body_text, sender, recipients) VALUES (?, ?, ?, ?, ?)"
5595
- ).run(messageId, subject, bodyText, sender, recipients);
5767
+ ).run(messageId, subject, bodyText, sender, recipients2);
5596
5768
  }
5597
5769
  var init_fts_populate = __esm({
5598
5770
  "src/sync/fts_populate.ts"() {
package/dist/mcp.cjs CHANGED
@@ -1298,8 +1298,8 @@ async function authenticate(dispatcher, capabilities, config) {
1298
1298
  }
1299
1299
  if ("mechanism" in config) {
1300
1300
  const { mechanism, credentials } = config;
1301
- const payload = encodeBase64(Buffer.from(JSON.stringify(credentials), "utf8"));
1302
- const res = await dispatcher.execute("AUTHENTICATE", [mechanism, payload]);
1301
+ const payload2 = encodeBase64(Buffer.from(JSON.stringify(credentials), "utf8"));
1302
+ const res = await dispatcher.execute("AUTHENTICATE", [mechanism, payload2]);
1303
1303
  if (res.tagged.status !== "OK") {
1304
1304
  throw new EmailAuthError(`${mechanism} authentication failed`, mechanism);
1305
1305
  }
@@ -2257,23 +2257,23 @@ var init_decode_bodystructure = __esm({
2257
2257
  });
2258
2258
 
2259
2259
  // src/mime/decode_encoded_words.ts
2260
- function decodeQPayload(payload) {
2260
+ function decodeQPayload(payload2) {
2261
2261
  const bytes = [];
2262
- for (let i = 0; i < payload.length; i++) {
2263
- const c = payload[i];
2262
+ for (let i = 0; i < payload2.length; i++) {
2263
+ const c = payload2[i];
2264
2264
  if (c === "_") {
2265
2265
  bytes.push(32);
2266
2266
  continue;
2267
2267
  }
2268
- if (c === "=" && i + 2 < payload.length) {
2269
- const h = payload.slice(i + 1, i + 3);
2268
+ if (c === "=" && i + 2 < payload2.length) {
2269
+ const h = payload2.slice(i + 1, i + 3);
2270
2270
  if (/^[0-9A-Fa-f]{2}$/.test(h)) {
2271
2271
  bytes.push(Number.parseInt(h, 16));
2272
2272
  i += 2;
2273
2273
  continue;
2274
2274
  }
2275
2275
  }
2276
- bytes.push(payload.charCodeAt(i) & 255);
2276
+ bytes.push(payload2.charCodeAt(i) & 255);
2277
2277
  }
2278
2278
  return Buffer.from(bytes);
2279
2279
  }
@@ -2344,9 +2344,9 @@ function parseAddressList(items) {
2344
2344
  const mailbox = s2(addrArr[2]);
2345
2345
  const host = s2(addrArr[3]);
2346
2346
  if (!mailbox || !host) continue;
2347
- const address = `${mailbox}@${host}`;
2347
+ const address2 = `${mailbox}@${host}`;
2348
2348
  const name = nameRaw ? decodeEncodedWords(nameRaw) : void 0;
2349
- out.push(name ? { name, address } : { address });
2349
+ out.push(name ? { name, address: address2 } : { address: address2 });
2350
2350
  }
2351
2351
  return out;
2352
2352
  }
@@ -4513,11 +4513,11 @@ function populateFts(db, messageId, textPlain, textHtml) {
4513
4513
  if (!row) return;
4514
4514
  const subject = row.subject != null ? String(row.subject) : "";
4515
4515
  const sender = row.from != null ? String(row.from) : "";
4516
- const recipients = row.to != null ? String(row.to) : "";
4516
+ const recipients2 = row.to != null ? String(row.to) : "";
4517
4517
  db.exec(`DELETE FROM messages_fts WHERE rowid = ${messageId}`);
4518
4518
  db.prepare(
4519
4519
  "INSERT INTO messages_fts(rowid, subject, body_text, sender, recipients) VALUES (?, ?, ?, ?, ?)"
4520
- ).run(messageId, subject, bodyText, sender, recipients);
4520
+ ).run(messageId, subject, bodyText, sender, recipients2);
4521
4521
  }
4522
4522
  var init_fts_populate = __esm({
4523
4523
  "src/sync/fts_populate.ts"() {
@@ -5007,7 +5007,7 @@ var init_network = __esm({
5007
5007
  });
5008
5008
 
5009
5009
  // src/version.ts
5010
- var emailVersion = "0.5.4";
5010
+ var emailVersion = "0.5.5";
5011
5011
 
5012
5012
  // src/surface/email_mcp_instructions.ts
5013
5013
  var emailMcpInstructions = "Read and search cached email offline. Configure live accounts with email account add before network operations. Inspect messages before replying or changing folders. Confirm recipients and content before sending; trash and folder deletion can remove mail. Credentials use the existing email CLI account configuration or EMAIL_* environment variables.";
@@ -5088,6 +5088,192 @@ function createReadSurface(db, accountId, _options) {
5088
5088
  // src/surface/email_surface_tools.ts
5089
5089
  init_store();
5090
5090
 
5091
+ // src/surfaces/schema_example.ts
5092
+ function schemaExample(schema, seed = {}) {
5093
+ if (schema.oneOf) {
5094
+ const branch = schema.oneOf.find(
5095
+ (candidate) => Object.entries(seed).every(([key, value]) => {
5096
+ const values = candidate.properties?.[key]?.enum;
5097
+ return !values || values.includes(value);
5098
+ })
5099
+ );
5100
+ return schemaExample({ ...schema, ...branch, oneOf: void 0 }, seed);
5101
+ }
5102
+ if (schema.enum) return schema.enum[0];
5103
+ if (schema.type === "object") {
5104
+ const result = { ...seed };
5105
+ for (const key of schema.required ?? [])
5106
+ if (!(key in result)) {
5107
+ const property = schema.properties?.[key] ?? {};
5108
+ const placeholders = {
5109
+ folder: "INBOX",
5110
+ destination: "Archive",
5111
+ query: "invoice",
5112
+ subject: "Hello",
5113
+ path: "Projects",
5114
+ oldPath: "Projects",
5115
+ newPath: "Archive/Projects"
5116
+ };
5117
+ result[key] = property.type === "string" && !property.enum && placeholders[key] ? placeholders[key] : schemaExample(property);
5118
+ }
5119
+ return result;
5120
+ }
5121
+ if (schema.type === "array") return [schemaExample(schema.items ?? {})];
5122
+ if (schema.type === "integer" || schema.type === "number") return 1;
5123
+ if (schema.type === "boolean") return false;
5124
+ return schema.description?.includes("address") ? "reader@example.com" : "example";
5125
+ }
5126
+
5127
+ // src/surfaces/validate_input.ts
5128
+ function validateInput(schema, input, path = "$") {
5129
+ const errors = validate(schema, input, path);
5130
+ if (path !== "$" || !errors.length) return errors;
5131
+ const seed = {};
5132
+ if (input && typeof input === "object") {
5133
+ for (const key of ["action", "view"])
5134
+ if (schema.properties?.[key]?.enum?.includes(input[key]))
5135
+ seed[key] = input[key];
5136
+ }
5137
+ return errors.map((error) => `${error}; pass ${JSON.stringify(schemaExample(schema, seed))}`);
5138
+ }
5139
+ function validate(schema, input, path) {
5140
+ const errors = [];
5141
+ const matchesType = (type) => {
5142
+ switch (type) {
5143
+ case "object":
5144
+ return typeof input === "object" && input !== null && !Array.isArray(input);
5145
+ case "array":
5146
+ return Array.isArray(input);
5147
+ case "integer":
5148
+ return typeof input === "number" && Number.isInteger(input);
5149
+ case "number":
5150
+ return typeof input === "number" && Number.isFinite(input);
5151
+ case "null":
5152
+ return input === null;
5153
+ default:
5154
+ return typeof input === type;
5155
+ }
5156
+ };
5157
+ if (schema.type && !(Array.isArray(schema.type) ? schema.type : [schema.type]).some(matchesType)) {
5158
+ return [`${path}: expected ${String(schema.type)}`];
5159
+ }
5160
+ if (schema.enum && !schema.enum.some((value) => JSON.stringify(value) === JSON.stringify(input)))
5161
+ errors.push(`${path}: expected one of ${JSON.stringify(schema.enum)}`);
5162
+ if (schema.oneOf) {
5163
+ const branches = schema.oneOf.map((branch) => validate(branch, input, path));
5164
+ if (!branches.some((errors2) => errors2.length === 0)) {
5165
+ const record = input && typeof input === "object" ? input : {};
5166
+ const selected = schema.oneOf.findIndex(
5167
+ (branch) => ["action", "view"].some((key) => branch.properties?.[key]?.enum?.includes(record[key]))
5168
+ );
5169
+ errors.push(...branches[selected >= 0 ? selected : 0] ?? []);
5170
+ }
5171
+ }
5172
+ if (typeof input === "object" && input !== null && !Array.isArray(input)) {
5173
+ const record = input;
5174
+ for (const name of schema.required ?? [])
5175
+ if (!Object.hasOwn(record, name)) errors.push(`${path}.${name}: required`);
5176
+ for (const [name, property] of Object.entries(schema.properties ?? {}))
5177
+ if (Object.hasOwn(record, name))
5178
+ errors.push(...validate(property, record[name], `${path}.${name}`));
5179
+ }
5180
+ if (Array.isArray(input) && schema.items)
5181
+ input.forEach((value, index) => {
5182
+ errors.push(...validate(schema.items, value, `${path}[${index}]`));
5183
+ });
5184
+ return errors;
5185
+ }
5186
+
5187
+ // src/tools/input_schema.ts
5188
+ var address = {
5189
+ type: "object",
5190
+ required: ["address"],
5191
+ properties: {
5192
+ address: { type: "string", description: "Email address." },
5193
+ name: { type: "string", description: "Display name." }
5194
+ }
5195
+ };
5196
+ var recipients = {
5197
+ type: "array",
5198
+ items: address,
5199
+ description: "Recipient addresses."
5200
+ };
5201
+ var payload = {
5202
+ type: "object",
5203
+ properties: {
5204
+ from: address,
5205
+ sender: address,
5206
+ envelopeFrom: address,
5207
+ replyTo: address,
5208
+ to: recipients,
5209
+ cc: recipients,
5210
+ bcc: recipients,
5211
+ subject: { type: "string", description: "Message subject." },
5212
+ text: { type: "string", description: "Plain text body." },
5213
+ html: { type: "string", description: "HTML body." },
5214
+ replyAll: { type: "boolean", description: "Reply to all original recipients." },
5215
+ mode: { type: "string", enum: ["inline", "attachment"] },
5216
+ attachments: {
5217
+ type: "array",
5218
+ description: "Message attachments.",
5219
+ items: {
5220
+ type: "object",
5221
+ required: ["filename", "content"],
5222
+ properties: {
5223
+ filename: { type: "string" },
5224
+ content: { description: "Attachment bytes (Buffer in library calls)." },
5225
+ mimeType: { type: "string" },
5226
+ inline: { type: "boolean" },
5227
+ contentId: { type: "string" }
5228
+ }
5229
+ }
5230
+ },
5231
+ inReplyTo: { type: "string" },
5232
+ references: { type: "array", items: { type: "string" } },
5233
+ headers: { type: "object" }
5234
+ }
5235
+ };
5236
+ function emailInputSchema(name, schema) {
5237
+ const discriminator = name === "mail_read" ? "view" : "action";
5238
+ const actions = schema.properties?.[discriminator]?.enum;
5239
+ if (!actions || name === "mail_sync") return schema;
5240
+ return {
5241
+ ...schema,
5242
+ oneOf: actions.map((value) => {
5243
+ const action = String(value);
5244
+ let required = [];
5245
+ let input;
5246
+ if (name === "mail_read") {
5247
+ if (action === "thread") required = ["threadId"];
5248
+ if (["message", "attachment", "eml"].includes(action)) required = ["folder", "uid"];
5249
+ } else if (name === "mail_compose") {
5250
+ if (action !== "send_draft") {
5251
+ required.push("input");
5252
+ input = {
5253
+ ...payload,
5254
+ required: ["send", "save_draft", "update_draft"].includes(action) ? ["to", "subject"] : action === "forward" ? ["to"] : []
5255
+ };
5256
+ }
5257
+ if (["reply", "forward"].includes(action)) required.push("folder", "uid");
5258
+ if (["update_draft", "send_draft"].includes(action)) required.push("uid");
5259
+ } else if (name === "mail_organize") {
5260
+ required = action === "rename_folder" ? ["oldPath", "newPath"] : action.endsWith("_folder") ? ["path"] : ["folder", "uids"];
5261
+ if (["copy", "move"].includes(action)) required.push("destination");
5262
+ if (action.endsWith("_labels")) required.push("labels");
5263
+ }
5264
+ return {
5265
+ type: "object",
5266
+ required: [...schema.required ?? [], ...required],
5267
+ properties: {
5268
+ ...schema.properties,
5269
+ [discriminator]: { ...schema.properties?.[discriminator], enum: [value] },
5270
+ ...input ? { input } : {}
5271
+ }
5272
+ };
5273
+ })
5274
+ };
5275
+ }
5276
+
5091
5277
  // src/tools/email_tools.ts
5092
5278
  var emailTools = [
5093
5279
  {
@@ -5808,6 +5994,21 @@ var emailTools = [
5808
5994
  }
5809
5995
  }
5810
5996
  ];
5997
+ for (const tool of emailTools) {
5998
+ Object.assign(tool.inputSchema, emailInputSchema(tool.name, tool.inputSchema));
5999
+ const handler = tool.handler;
6000
+ tool.handler = async (ctx, input) => {
6001
+ const errors = validateInput(tool.inputSchema, input);
6002
+ if (errors.length)
6003
+ return {
6004
+ outcome: "error",
6005
+ summary: errors.join("; "),
6006
+ entities: [],
6007
+ nextSteps: errors
6008
+ };
6009
+ return handler(ctx, input);
6010
+ };
6011
+ }
5811
6012
 
5812
6013
  // src/tools/aligned.ts
5813
6014
  var usage = {
@@ -6102,47 +6303,6 @@ function isErrorResult(result) {
6102
6303
  return typeof result === "object" && result !== null && "ok" in result && result.ok === false;
6103
6304
  }
6104
6305
 
6105
- // src/surfaces/validate_input.ts
6106
- function validateInput(schema, input, path = "$") {
6107
- const errors = [];
6108
- const matchesType = (type) => {
6109
- switch (type) {
6110
- case "object":
6111
- return typeof input === "object" && input !== null && !Array.isArray(input);
6112
- case "array":
6113
- return Array.isArray(input);
6114
- case "integer":
6115
- return typeof input === "number" && Number.isInteger(input);
6116
- case "number":
6117
- return typeof input === "number" && Number.isFinite(input);
6118
- case "null":
6119
- return input === null;
6120
- default:
6121
- return typeof input === type;
6122
- }
6123
- };
6124
- if (schema.type && !(Array.isArray(schema.type) ? schema.type : [schema.type]).some(matchesType)) {
6125
- return [`${path}: expected ${String(schema.type)}`];
6126
- }
6127
- if (schema.enum && !schema.enum.some((value) => JSON.stringify(value) === JSON.stringify(input)))
6128
- errors.push(`${path}: expected one of ${JSON.stringify(schema.enum)}`);
6129
- if (schema.oneOf && !schema.oneOf.some((branch) => validateInput(branch, input, path).length === 0))
6130
- errors.push(`${path}: must match at least one schema branch`);
6131
- if (typeof input === "object" && input !== null && !Array.isArray(input)) {
6132
- const record = input;
6133
- for (const name of schema.required ?? [])
6134
- if (!Object.hasOwn(record, name)) errors.push(`${path}.${name}: required`);
6135
- for (const [name, property] of Object.entries(schema.properties ?? {}))
6136
- if (Object.hasOwn(record, name))
6137
- errors.push(...validateInput(property, record[name], `${path}.${name}`));
6138
- }
6139
- if (Array.isArray(input) && schema.items)
6140
- input.forEach((value, index) => {
6141
- errors.push(...validateInput(schema.items, value, `${path}[${index}]`));
6142
- });
6143
- return errors;
6144
- }
6145
-
6146
6306
  // src/surfaces/mcp_server.ts
6147
6307
  var MCP_LATEST_PROTOCOL_VERSION = "2026-07-28";
6148
6308
  var MCP_SUPPORTED_PROTOCOL_VERSIONS = [