@mindstone/mcp-server-google-workspace 0.1.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -9
- package/dist/modules/accounts/manager.js +20 -2
- package/dist/modules/accounts/token.d.ts +13 -0
- package/dist/modules/accounts/token.js +73 -58
- package/dist/modules/accounts/types.d.ts +1 -0
- package/dist/modules/calendar/service.js +9 -0
- package/dist/modules/chat/index.d.ts +12 -0
- package/dist/modules/chat/index.js +18 -0
- package/dist/modules/chat/scopes.d.ts +14 -0
- package/dist/modules/chat/scopes.js +32 -0
- package/dist/modules/chat/types.d.ts +88 -0
- package/dist/modules/chat/types.js +14 -0
- package/dist/modules/comments/service.js +26 -5
- package/dist/modules/contacts/scopes.d.ts +1 -0
- package/dist/modules/contacts/scopes.js +2 -2
- package/dist/modules/contacts/types.d.ts +34 -0
- package/dist/modules/docs/index.js +2 -1
- package/dist/modules/docs/service.js +36 -7
- package/dist/modules/drive/activity-service.d.ts +45 -0
- package/dist/modules/drive/activity-service.js +114 -0
- package/dist/modules/drive/index.d.ts +4 -0
- package/dist/modules/drive/index.js +12 -0
- package/dist/modules/drive/scopes.d.ts +1 -0
- package/dist/modules/drive/scopes.js +3 -0
- package/dist/modules/drive/service.d.ts +2 -1
- package/dist/modules/drive/service.js +29 -0
- package/dist/modules/drive/types.d.ts +8 -0
- package/dist/modules/forms/service.js +16 -3
- package/dist/modules/gmail/services/attachment.js +2 -1
- package/dist/modules/gmail/services/base.d.ts +5 -1
- package/dist/modules/gmail/services/base.js +10 -1
- package/dist/modules/gmail/services/draft.js +13 -7
- package/dist/modules/gmail/services/email.js +4 -3
- package/dist/modules/gmail/services/label.js +10 -9
- package/dist/modules/gmail/services/settings.d.ts +14 -1
- package/dist/modules/gmail/services/settings.js +96 -1
- package/dist/modules/gmail/types.d.ts +36 -0
- package/dist/modules/meet/index.d.ts +12 -0
- package/dist/modules/meet/index.js +18 -0
- package/dist/modules/meet/scopes.d.ts +9 -0
- package/dist/modules/meet/scopes.js +25 -0
- package/dist/modules/meet/types.d.ts +97 -0
- package/dist/modules/meet/types.js +14 -0
- package/dist/modules/sheets/service.js +49 -0
- package/dist/modules/slides/service.js +31 -6
- package/dist/modules/tasks/service.js +31 -6
- package/dist/resources/compose-email-template.d.ts +1 -1
- package/dist/resources/compose-email-template.js +388 -19
- package/dist/services/base/BaseGoogleService.d.ts +9 -1
- package/dist/services/base/BaseGoogleService.js +33 -1
- package/dist/services/chat/index.d.ts +34 -0
- package/dist/services/chat/index.js +120 -0
- package/dist/services/contacts/index.d.ts +19 -1
- package/dist/services/contacts/index.js +124 -0
- package/dist/services/meet/index.d.ts +35 -0
- package/dist/services/meet/index.js +116 -0
- package/dist/tools/calendar-handlers.js +28 -23
- package/dist/tools/chat-handlers.d.ts +14 -0
- package/dist/tools/chat-handlers.js +126 -0
- package/dist/tools/contacts-handlers.d.ts +31 -0
- package/dist/tools/contacts-handlers.js +96 -23
- package/dist/tools/definitions/account.js +8 -1
- package/dist/tools/definitions/chat.d.ts +3 -0
- package/dist/tools/definitions/chat.js +137 -0
- package/dist/tools/definitions/contacts.js +82 -0
- package/dist/tools/definitions/destructive-overrides.json +12 -0
- package/dist/tools/definitions/drive.js +132 -6
- package/dist/tools/definitions/gmail.js +94 -0
- package/dist/tools/definitions/index.d.ts +2 -0
- package/dist/tools/definitions/index.js +6 -0
- package/dist/tools/definitions/meet.d.ts +3 -0
- package/dist/tools/definitions/meet.js +149 -0
- package/dist/tools/definitions/open-world-overrides.json +12 -0
- package/dist/tools/drive-handlers.d.ts +27 -0
- package/dist/tools/drive-handlers.js +93 -2
- package/dist/tools/forms-handlers.js +5 -12
- package/dist/tools/gmail-handlers.d.ts +31 -1
- package/dist/tools/gmail-handlers.js +167 -35
- package/dist/tools/meet-handlers.d.ts +42 -0
- package/dist/tools/meet-handlers.js +144 -0
- package/dist/tools/server.js +67 -5
- package/dist/tools/tasks-handlers.js +7 -18
- package/dist/tools/type-guards.d.ts +3 -1
- package/dist/tools/type-guards.js +22 -2
- package/dist/tools/types.d.ts +13 -0
- package/dist/utils/apiError.d.ts +49 -0
- package/dist/utils/apiError.js +96 -0
- package/dist/utils/scope-hierarchy.js +10 -0
- package/dist/utils/service-initializer.js +9 -0
- package/dist/utils/untrusted-content.d.ts +37 -1
- package/dist/utils/untrusted-content.js +61 -6
- package/package.json +5 -1
- package/dist/services/calendar/index.d.ts +0 -27
- package/dist/services/calendar/index.js +0 -146
- package/dist/services/gmail/index.d.ts +0 -39
- package/dist/services/gmail/index.js +0 -337
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
|
|
3
|
+
import { isAuthHandoffError } from '../../utils/apiError.js';
|
|
3
4
|
import { SHEETS_SCOPES } from './scopes.js';
|
|
4
5
|
import { buildAnchorEnvelope, buildShapedReadResponse, ContinuationTokenError, mergeFormulaAndValue, parseContinuationToken, } from './cellShape.js';
|
|
5
6
|
import { rewriteSheetsApiError } from './errorRewriter.js';
|
|
@@ -495,6 +496,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
495
496
|
};
|
|
496
497
|
}
|
|
497
498
|
catch (error) {
|
|
499
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
500
|
+
if (isAuthHandoffError(error))
|
|
501
|
+
throw error;
|
|
498
502
|
return {
|
|
499
503
|
success: false,
|
|
500
504
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -551,6 +555,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
551
555
|
};
|
|
552
556
|
}
|
|
553
557
|
catch (error) {
|
|
558
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
559
|
+
if (isAuthHandoffError(error))
|
|
560
|
+
throw error;
|
|
554
561
|
if (error instanceof ContinuationTokenError) {
|
|
555
562
|
return {
|
|
556
563
|
success: false,
|
|
@@ -617,6 +624,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
617
624
|
};
|
|
618
625
|
}
|
|
619
626
|
catch (error) {
|
|
627
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
628
|
+
if (isAuthHandoffError(error))
|
|
629
|
+
throw error;
|
|
620
630
|
if (error instanceof ContinuationTokenError) {
|
|
621
631
|
return {
|
|
622
632
|
success: false,
|
|
@@ -722,6 +732,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
722
732
|
return { formulaCells };
|
|
723
733
|
}
|
|
724
734
|
catch (error) {
|
|
735
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
736
|
+
if (isAuthHandoffError(error))
|
|
737
|
+
throw error;
|
|
725
738
|
const kind = this.classifyFormulaPreReadError(error);
|
|
726
739
|
const rewrittenError = rewriteSheetsApiError(error, {
|
|
727
740
|
tool,
|
|
@@ -920,6 +933,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
920
933
|
};
|
|
921
934
|
}
|
|
922
935
|
catch (error) {
|
|
936
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
937
|
+
if (isAuthHandoffError(error))
|
|
938
|
+
throw error;
|
|
923
939
|
return {
|
|
924
940
|
success: false,
|
|
925
941
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -976,6 +992,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
976
992
|
};
|
|
977
993
|
}
|
|
978
994
|
catch (error) {
|
|
995
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
996
|
+
if (isAuthHandoffError(error))
|
|
997
|
+
throw error;
|
|
979
998
|
return {
|
|
980
999
|
success: false,
|
|
981
1000
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -1037,6 +1056,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1037
1056
|
};
|
|
1038
1057
|
}
|
|
1039
1058
|
catch (error) {
|
|
1059
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
1060
|
+
if (isAuthHandoffError(error))
|
|
1061
|
+
throw error;
|
|
1040
1062
|
return {
|
|
1041
1063
|
success: false,
|
|
1042
1064
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -1067,6 +1089,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1067
1089
|
};
|
|
1068
1090
|
}
|
|
1069
1091
|
catch (error) {
|
|
1092
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
1093
|
+
if (isAuthHandoffError(error))
|
|
1094
|
+
throw error;
|
|
1070
1095
|
return {
|
|
1071
1096
|
success: false,
|
|
1072
1097
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -1120,6 +1145,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1120
1145
|
};
|
|
1121
1146
|
}
|
|
1122
1147
|
catch (error) {
|
|
1148
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
1149
|
+
if (isAuthHandoffError(error))
|
|
1150
|
+
throw error;
|
|
1123
1151
|
return {
|
|
1124
1152
|
success: false,
|
|
1125
1153
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -1157,6 +1185,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1157
1185
|
};
|
|
1158
1186
|
}
|
|
1159
1187
|
catch (error) {
|
|
1188
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
1189
|
+
if (isAuthHandoffError(error))
|
|
1190
|
+
throw error;
|
|
1160
1191
|
return {
|
|
1161
1192
|
success: false,
|
|
1162
1193
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -1190,6 +1221,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1190
1221
|
};
|
|
1191
1222
|
}
|
|
1192
1223
|
catch (error) {
|
|
1224
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
1225
|
+
if (isAuthHandoffError(error))
|
|
1226
|
+
throw error;
|
|
1193
1227
|
return {
|
|
1194
1228
|
success: false,
|
|
1195
1229
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -1285,6 +1319,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1285
1319
|
};
|
|
1286
1320
|
}
|
|
1287
1321
|
catch (error) {
|
|
1322
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
1323
|
+
if (isAuthHandoffError(error))
|
|
1324
|
+
throw error;
|
|
1288
1325
|
if (error instanceof ContinuationTokenError) {
|
|
1289
1326
|
return {
|
|
1290
1327
|
success: false,
|
|
@@ -1391,6 +1428,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1391
1428
|
};
|
|
1392
1429
|
}
|
|
1393
1430
|
catch (error) {
|
|
1431
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
1432
|
+
if (isAuthHandoffError(error))
|
|
1433
|
+
throw error;
|
|
1394
1434
|
if (error instanceof ContinuationTokenError) {
|
|
1395
1435
|
return {
|
|
1396
1436
|
success: false,
|
|
@@ -1472,6 +1512,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1472
1512
|
};
|
|
1473
1513
|
}
|
|
1474
1514
|
catch (error) {
|
|
1515
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
1516
|
+
if (isAuthHandoffError(error))
|
|
1517
|
+
throw error;
|
|
1475
1518
|
return {
|
|
1476
1519
|
success: false,
|
|
1477
1520
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -1520,6 +1563,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1520
1563
|
};
|
|
1521
1564
|
}
|
|
1522
1565
|
catch (error) {
|
|
1566
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
1567
|
+
if (isAuthHandoffError(error))
|
|
1568
|
+
throw error;
|
|
1523
1569
|
return {
|
|
1524
1570
|
success: false,
|
|
1525
1571
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -1640,6 +1686,9 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1640
1686
|
};
|
|
1641
1687
|
}
|
|
1642
1688
|
catch (error) {
|
|
1689
|
+
// Keep the reconnect signal: an expired/revoked grant must not collapse to a plain string.
|
|
1690
|
+
if (isAuthHandoffError(error))
|
|
1691
|
+
throw error;
|
|
1643
1692
|
return {
|
|
1644
1693
|
success: false,
|
|
1645
1694
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
|
|
3
3
|
import { SLIDES_SCOPES } from './scopes.js';
|
|
4
|
+
import { describeApiError, isAuthHandoffError } from '../../utils/apiError.js';
|
|
4
5
|
const DEFAULT_MAX_CHARS = 50000;
|
|
5
6
|
const TRUNCATION_MARKER = '\n\n[TRUNCATED - presentation exceeds character limit]';
|
|
6
7
|
export class SlidesService extends BaseGoogleService {
|
|
@@ -199,9 +200,13 @@ export class SlidesService extends BaseGoogleService {
|
|
|
199
200
|
};
|
|
200
201
|
}
|
|
201
202
|
catch (error) {
|
|
203
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
204
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
205
|
+
if (isAuthHandoffError(error))
|
|
206
|
+
throw error;
|
|
202
207
|
return {
|
|
203
208
|
success: false,
|
|
204
|
-
error: error
|
|
209
|
+
error: describeApiError(error),
|
|
205
210
|
};
|
|
206
211
|
}
|
|
207
212
|
}
|
|
@@ -238,9 +243,13 @@ export class SlidesService extends BaseGoogleService {
|
|
|
238
243
|
};
|
|
239
244
|
}
|
|
240
245
|
catch (error) {
|
|
246
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
247
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
248
|
+
if (isAuthHandoffError(error))
|
|
249
|
+
throw error;
|
|
241
250
|
return {
|
|
242
251
|
success: false,
|
|
243
|
-
error: error
|
|
252
|
+
error: describeApiError(error),
|
|
244
253
|
};
|
|
245
254
|
}
|
|
246
255
|
}
|
|
@@ -264,9 +273,13 @@ export class SlidesService extends BaseGoogleService {
|
|
|
264
273
|
};
|
|
265
274
|
}
|
|
266
275
|
catch (error) {
|
|
276
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
277
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
278
|
+
if (isAuthHandoffError(error))
|
|
279
|
+
throw error;
|
|
267
280
|
return {
|
|
268
281
|
success: false,
|
|
269
|
-
error: error
|
|
282
|
+
error: describeApiError(error),
|
|
270
283
|
};
|
|
271
284
|
}
|
|
272
285
|
}
|
|
@@ -315,9 +328,13 @@ export class SlidesService extends BaseGoogleService {
|
|
|
315
328
|
};
|
|
316
329
|
}
|
|
317
330
|
catch (error) {
|
|
331
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
332
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
333
|
+
if (isAuthHandoffError(error))
|
|
334
|
+
throw error;
|
|
318
335
|
return {
|
|
319
336
|
success: false,
|
|
320
|
-
error: error
|
|
337
|
+
error: describeApiError(error),
|
|
321
338
|
};
|
|
322
339
|
}
|
|
323
340
|
}
|
|
@@ -349,9 +366,13 @@ export class SlidesService extends BaseGoogleService {
|
|
|
349
366
|
};
|
|
350
367
|
}
|
|
351
368
|
catch (error) {
|
|
369
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
370
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
371
|
+
if (isAuthHandoffError(error))
|
|
372
|
+
throw error;
|
|
352
373
|
return {
|
|
353
374
|
success: false,
|
|
354
|
-
error: error
|
|
375
|
+
error: describeApiError(error),
|
|
355
376
|
};
|
|
356
377
|
}
|
|
357
378
|
}
|
|
@@ -384,9 +405,13 @@ export class SlidesService extends BaseGoogleService {
|
|
|
384
405
|
};
|
|
385
406
|
}
|
|
386
407
|
catch (error) {
|
|
408
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
409
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
410
|
+
if (isAuthHandoffError(error))
|
|
411
|
+
throw error;
|
|
387
412
|
return {
|
|
388
413
|
success: false,
|
|
389
|
-
error: error
|
|
414
|
+
error: describeApiError(error),
|
|
390
415
|
};
|
|
391
416
|
}
|
|
392
417
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
|
|
3
|
+
import { describeApiError, isAuthHandoffError } from '../../utils/apiError.js';
|
|
3
4
|
import { TASKS_SCOPES } from './scopes.js';
|
|
4
5
|
/**
|
|
5
6
|
* Service for interacting with Google Tasks API.
|
|
@@ -78,9 +79,13 @@ export class TasksService extends BaseGoogleService {
|
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
catch (error) {
|
|
82
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
83
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
84
|
+
if (isAuthHandoffError(error))
|
|
85
|
+
throw error;
|
|
81
86
|
return {
|
|
82
87
|
success: false,
|
|
83
|
-
error: error
|
|
88
|
+
error: describeApiError(error)
|
|
84
89
|
};
|
|
85
90
|
}
|
|
86
91
|
}
|
|
@@ -138,9 +143,13 @@ export class TasksService extends BaseGoogleService {
|
|
|
138
143
|
};
|
|
139
144
|
}
|
|
140
145
|
catch (error) {
|
|
146
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
147
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
148
|
+
if (isAuthHandoffError(error))
|
|
149
|
+
throw error;
|
|
141
150
|
return {
|
|
142
151
|
success: false,
|
|
143
|
-
error: error
|
|
152
|
+
error: describeApiError(error)
|
|
144
153
|
};
|
|
145
154
|
}
|
|
146
155
|
}
|
|
@@ -186,9 +195,13 @@ export class TasksService extends BaseGoogleService {
|
|
|
186
195
|
};
|
|
187
196
|
}
|
|
188
197
|
catch (error) {
|
|
198
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
199
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
200
|
+
if (isAuthHandoffError(error))
|
|
201
|
+
throw error;
|
|
189
202
|
return {
|
|
190
203
|
success: false,
|
|
191
|
-
error: error
|
|
204
|
+
error: describeApiError(error)
|
|
192
205
|
};
|
|
193
206
|
}
|
|
194
207
|
}
|
|
@@ -227,9 +240,13 @@ export class TasksService extends BaseGoogleService {
|
|
|
227
240
|
};
|
|
228
241
|
}
|
|
229
242
|
catch (error) {
|
|
243
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
244
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
245
|
+
if (isAuthHandoffError(error))
|
|
246
|
+
throw error;
|
|
230
247
|
return {
|
|
231
248
|
success: false,
|
|
232
|
-
error: error
|
|
249
|
+
error: describeApiError(error)
|
|
233
250
|
};
|
|
234
251
|
}
|
|
235
252
|
}
|
|
@@ -282,9 +299,13 @@ export class TasksService extends BaseGoogleService {
|
|
|
282
299
|
};
|
|
283
300
|
}
|
|
284
301
|
catch (error) {
|
|
302
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
303
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
304
|
+
if (isAuthHandoffError(error))
|
|
305
|
+
throw error;
|
|
285
306
|
return {
|
|
286
307
|
success: false,
|
|
287
|
-
error: error
|
|
308
|
+
error: describeApiError(error)
|
|
288
309
|
};
|
|
289
310
|
}
|
|
290
311
|
}
|
|
@@ -309,9 +330,13 @@ export class TasksService extends BaseGoogleService {
|
|
|
309
330
|
};
|
|
310
331
|
}
|
|
311
332
|
catch (error) {
|
|
333
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
334
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
335
|
+
if (isAuthHandoffError(error))
|
|
336
|
+
throw error;
|
|
312
337
|
return {
|
|
313
338
|
success: false,
|
|
314
|
-
error: error
|
|
339
|
+
error: describeApiError(error)
|
|
315
340
|
};
|
|
316
341
|
}
|
|
317
342
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const COMPOSE_EMAIL_HTML = "\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>Compose Email</title>\n <style>\n :root {\n --bg: #ffffff;\n --panel: #ffffff;\n --border: #d9dde5;\n --text: #1f2937;\n --muted: #6b7280;\n --input-bg: #ffffff;\n --button-bg: #1f6feb;\n --button-text: #ffffff;\n --button-bg-hover: #1b63d3;\n --secondary-bg: #f3f4f6;\n --secondary-text: #1f2937;\n --secondary-border: #d1d5db;\n --error-bg: #fef2f2;\n --error-border: #fecaca;\n --error-text: #991b1b;\n --success-bg: #ecfdf5;\n --success-border: #bbf7d0;\n --success-text: #166534;\n --warning-bg: #fffbeb;\n --warning-border: #fde68a;\n --warning-text: #92400e;\n }\n\n @media (prefers-color-scheme: dark) {\n :root {\n --bg: #0f172a;\n --panel: #111827;\n --border: #334155;\n --text: #e5e7eb;\n --muted: #9ca3af;\n --input-bg: #0b1220;\n --button-bg: #3b82f6;\n --button-text: #eff6ff;\n --button-bg-hover: #2563eb;\n --secondary-bg: #1f2937;\n --secondary-text: #e5e7eb;\n --secondary-border: #374151;\n --error-bg: #2b1011;\n --error-border: #7f1d1d;\n --error-text: #fca5a5;\n --success-bg: #052e1b;\n --success-border: #166534;\n --success-text: #86efac;\n --warning-bg: #2a2106;\n --warning-border: #854d0e;\n --warning-text: #fcd34d;\n }\n }\n\n html[data-theme=\"light\"] {\n color-scheme: light;\n }\n\n html[data-theme=\"dark\"] {\n color-scheme: dark;\n --bg: #0f172a;\n --panel: #111827;\n --border: #334155;\n --text: #e5e7eb;\n --muted: #9ca3af;\n --input-bg: #0b1220;\n --button-bg: #3b82f6;\n --button-text: #eff6ff;\n --button-bg-hover: #2563eb;\n --secondary-bg: #1f2937;\n --secondary-text: #e5e7eb;\n --secondary-border: #374151;\n --error-bg: #2b1011;\n --error-border: #7f1d1d;\n --error-text: #fca5a5;\n --success-bg: #052e1b;\n --success-border: #166534;\n --success-text: #86efac;\n --warning-bg: #2a2106;\n --warning-border: #854d0e;\n --warning-text: #fcd34d;\n }\n\n * {\n box-sizing: border-box;\n }\n\n body {\n margin: 0;\n padding: 16px;\n background: var(--bg);\n color: var(--text);\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n line-height: 1.4;\n }\n\n .wrapper {\n width: 100%;\n max-width: 720px;\n margin: 0 auto;\n }\n\n .card {\n background: var(--panel);\n border: 1px solid var(--border);\n border-radius: 12px;\n padding: 14px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n\n .field {\n display: flex;\n flex-direction: column;\n gap: 6px;\n }\n\n .field label {\n font-size: 12px;\n font-weight: 600;\n color: var(--muted);\n text-transform: uppercase;\n letter-spacing: 0.04em;\n }\n\n .from-value {\n color: var(--text);\n font-size: 14px;\n padding: 2px 0;\n word-break: break-word;\n }\n\n .from-helper {\n font-size: 12px;\n color: var(--muted);\n margin-top: 2px;\n }\n\n .input,\n .textarea {\n width: 100%;\n background: var(--input-bg);\n color: var(--text);\n border: 1px solid var(--border);\n border-radius: 8px;\n padding: 10px 12px;\n font-size: 14px;\n font-family: inherit;\n }\n\n .input:focus,\n .textarea:focus {\n outline: 2px solid rgba(59, 130, 246, 0.35);\n outline-offset: 1px;\n }\n\n .textarea {\n min-height: 180px;\n resize: vertical;\n white-space: pre-wrap;\n }\n\n .toggles {\n display: flex;\n gap: 12px;\n align-items: center;\n flex-wrap: wrap;\n }\n\n .link-button {\n border: none;\n padding: 0;\n background: none;\n color: var(--muted);\n text-decoration: underline;\n font-size: 12px;\n cursor: pointer;\n }\n\n .link-button:hover {\n color: var(--text);\n }\n\n .actions {\n display: flex;\n justify-content: flex-end;\n gap: 10px;\n margin-top: 2px;\n }\n\n .button {\n border-radius: 8px;\n border: 1px solid transparent;\n min-height: 36px;\n padding: 0 14px;\n font-size: 13px;\n font-weight: 600;\n font-family: inherit;\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n transition: background 120ms ease, opacity 120ms ease, border-color 120ms ease;\n }\n\n .button:disabled {\n cursor: not-allowed;\n opacity: 0.75;\n }\n\n .button-primary {\n background: var(--button-bg);\n color: var(--button-text);\n }\n\n .button-primary:hover:enabled {\n background: var(--button-bg-hover);\n }\n\n .button-secondary {\n background: var(--secondary-bg);\n color: var(--secondary-text);\n border-color: var(--secondary-border);\n }\n\n .spinner {\n width: 14px;\n height: 14px;\n border: 2px solid currentColor;\n border-right-color: transparent;\n border-radius: 50%;\n display: inline-block;\n animation: spin 700ms linear infinite;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n .status {\n border-radius: 8px;\n border: 1px solid transparent;\n padding: 8px 10px;\n font-size: 13px;\n }\n\n .error {\n background: var(--error-bg);\n border-color: var(--error-border);\n color: var(--error-text);\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: 8px;\n flex-wrap: wrap;\n }\n\n .success {\n background: var(--success-bg);\n border-color: var(--success-border);\n color: var(--success-text);\n }\n\n .warning {\n background: var(--warning-bg);\n border-color: var(--warning-border);\n color: var(--warning-text);\n display: block;\n }\n\n .warning strong {\n display: block;\n margin-bottom: 2px;\n }\n\n .warning .warning-detail {\n opacity: 0.85;\n }\n\n .collapsed {\n border: 1px solid var(--border);\n border-radius: 10px;\n background: var(--panel);\n padding: 10px 12px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: 8px;\n font-size: 13px;\n }\n\n .hidden {\n display: none !important;\n }\n </style>\n</head>\n<body>\n <div class=\"wrapper\">\n <div id=\"collapsedState\" class=\"collapsed hidden\">\n <span id=\"collapsedMessage\">Draft collapsed.</span>\n <button id=\"reopenButton\" type=\"button\" class=\"button button-secondary\">Reopen</button>\n </div>\n\n <form id=\"composeForm\" class=\"card\" novalidate>\n <div class=\"field from-field\">\n <label>From</label>\n <span id=\"fromValue\" class=\"from-value\"></span>\n <span id=\"fromHelper\" class=\"from-helper hidden\"></span>\n </div>\n\n <div class=\"field\">\n <label for=\"toInput\">To</label>\n <input id=\"toInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"name@example.com, team@example.com\">\n </div>\n\n <div class=\"toggles\">\n <button id=\"toggleCcButton\" type=\"button\" class=\"link-button\">Add CC</button>\n <button id=\"toggleBccButton\" type=\"button\" class=\"link-button\">Add BCC</button>\n </div>\n\n <div id=\"ccRow\" class=\"field hidden\">\n <label for=\"ccInput\">CC</label>\n <input id=\"ccInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"cc@example.com\">\n </div>\n\n <div id=\"bccRow\" class=\"field hidden\">\n <label for=\"bccInput\">BCC</label>\n <input id=\"bccInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"bcc@example.com\">\n </div>\n\n <div class=\"field\">\n <label for=\"subjectInput\">Subject</label>\n <input id=\"subjectInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"Email subject\">\n </div>\n\n <div class=\"field\">\n <label for=\"bodyInput\">Body</label>\n <textarea id=\"bodyInput\" class=\"textarea\" placeholder=\"Write your email\"></textarea>\n </div>\n\n <div id=\"errorBox\" class=\"status error hidden\">\n <span id=\"errorText\"></span>\n <button id=\"retryButton\" type=\"button\" class=\"link-button\">Retry</button>\n </div>\n\n <div id=\"successBox\" class=\"status success hidden\"></div>\n\n <div id=\"unknownBox\" class=\"status warning hidden\" role=\"status\" aria-live=\"polite\">\n <strong id=\"unknownTitle\"></strong>\n <span id=\"unknownText\" class=\"warning-detail\"></span>\n </div>\n\n <div class=\"actions\">\n <button id=\"cancelButton\" type=\"button\" class=\"button button-secondary\">Cancel</button>\n <button id=\"sendButton\" type=\"button\" class=\"button button-primary\">\n <span id=\"sendSpinner\" class=\"spinner hidden\" aria-hidden=\"true\"></span>\n <span id=\"sendLabel\">Send email</span>\n </button>\n </div>\n </form>\n </div>\n\n <script>\n (function () {\n 'use strict';\n\n var RESOURCE_URI = 'ui://google-workspace/compose-email';\n var currentEmail = '';\n var pendingRequestId = null;\n var pendingPayload = null;\n var sending = false;\n var collapsed = false;\n var outcomeUnknown = false;\n var sendTimeoutId = null;\n // Just beyond the host-side tool-call timeout (60s) so a legitimately slow\n // send resolves to its real result first; this only fires when the reply\n // is genuinely lost (REBEL-677), so the button can never stay stuck-silent.\n var SEND_TIMEOUT_MS = 75000;\n\n var composeForm = document.getElementById('composeForm');\n var collapsedState = document.getElementById('collapsedState');\n var collapsedMessage = document.getElementById('collapsedMessage');\n var reopenButton = document.getElementById('reopenButton');\n\n var toInput = document.getElementById('toInput');\n var ccInput = document.getElementById('ccInput');\n var bccInput = document.getElementById('bccInput');\n var subjectInput = document.getElementById('subjectInput');\n var bodyInput = document.getElementById('bodyInput');\n var fromValue = document.getElementById('fromValue');\n var fromHelper = document.getElementById('fromHelper');\n var ccRow = document.getElementById('ccRow');\n var bccRow = document.getElementById('bccRow');\n var toggleCcButton = document.getElementById('toggleCcButton');\n var toggleBccButton = document.getElementById('toggleBccButton');\n\n var sendButton = document.getElementById('sendButton');\n var sendLabel = document.getElementById('sendLabel');\n var sendSpinner = document.getElementById('sendSpinner');\n var cancelButton = document.getElementById('cancelButton');\n var retryButton = document.getElementById('retryButton');\n\n var errorBox = document.getElementById('errorBox');\n var errorText = document.getElementById('errorText');\n var successBox = document.getElementById('successBox');\n var unknownBox = document.getElementById('unknownBox');\n var unknownTitle = document.getElementById('unknownTitle');\n var unknownText = document.getElementById('unknownText');\n\n function applyThemeFromHostContext() {\n try {\n var context = window.__MCP_HOST_CONTEXT__;\n if (!context || (context.theme !== 'light' && context.theme !== 'dark')) {\n return;\n }\n document.documentElement.setAttribute('data-theme', context.theme);\n } catch (_) {\n // Ignore theme extraction errors\n }\n }\n\n function trimString(value) {\n return String(value || '').trim();\n }\n\n function applyFromValue(email) {\n var trimmed = trimString(email);\n if (trimmed) {\n fromValue.textContent = trimmed;\n fromValue.style.color = '';\n fromHelper.textContent = '';\n fromHelper.classList.add('hidden');\n } else {\n fromValue.textContent = 'Account not shown';\n fromValue.style.color = 'var(--muted)';\n fromHelper.textContent = 'Rebel could not confirm the sending account. Cancel and ask Rebel to recreate the draft before sending.';\n fromHelper.classList.remove('hidden');\n }\n }\n\n function formatAddressItem(item) {\n if (item && typeof item === 'object') {\n var email = trimString(item.email || item.address || item.value);\n var name = trimString(item.name || item.displayName);\n if (email && name) {\n return name + ' <' + email + '>';\n }\n return email;\n }\n return trimString(item);\n }\n\n function normalizeAddressList(value) {\n if (Array.isArray(value)) {\n return value.map(formatAddressItem).filter(Boolean);\n }\n if (typeof value === 'string') {\n return value\n .split(',')\n .map(function (item) { return trimString(item); })\n .filter(Boolean);\n }\n return [];\n }\n\n function listToInputValue(list) {\n return normalizeAddressList(list).join(', ');\n }\n\n var resizeQueued = false;\n function postResize() {\n if (resizeQueued) return;\n resizeQueued = true;\n requestAnimationFrame(function () {\n resizeQueued = false;\n var height = Math.max(\n document.documentElement.scrollHeight,\n document.body ? document.body.scrollHeight : 0\n );\n window.parent.postMessage(\n { jsonrpc: '2.0', method: 'ui/resize', params: { height: height } },\n '*'\n );\n });\n }\n\n function postReady() {\n window.parent.postMessage(\n {\n method: 'mcp-app:ready',\n params: { resourceUri: RESOURCE_URI }\n },\n '*'\n );\n }\n\n function setCollapsed(nextCollapsed, message) {\n collapsed = nextCollapsed;\n composeForm.classList.toggle('hidden', collapsed);\n collapsedState.classList.toggle('hidden', !collapsed);\n if (message) {\n collapsedMessage.textContent = message;\n } else {\n collapsedMessage.textContent = collapsed ? 'Draft collapsed.' : '';\n }\n postResize();\n }\n\n function setSending(nextSending) {\n sending = nextSending;\n sendButton.disabled = nextSending;\n cancelButton.disabled = nextSending;\n toInput.disabled = nextSending;\n ccInput.disabled = nextSending;\n bccInput.disabled = nextSending;\n subjectInput.disabled = nextSending;\n bodyInput.disabled = nextSending;\n sendSpinner.classList.toggle('hidden', !nextSending);\n sendLabel.textContent = nextSending ? 'Sending\u2026' : 'Send email';\n postResize();\n }\n\n function clearError() {\n errorText.textContent = '';\n errorBox.classList.add('hidden');\n }\n\n function showError(message) {\n errorText.textContent = message || 'Failed to send email.';\n errorBox.classList.remove('hidden');\n postResize();\n }\n\n function clearSuccess() {\n successBox.textContent = '';\n successBox.classList.add('hidden');\n }\n\n function showSuccess(message) {\n successBox.textContent = message;\n successBox.classList.remove('hidden');\n postResize();\n }\n\n function clearSendTimeout() {\n if (sendTimeoutId !== null) {\n clearTimeout(sendTimeoutId);\n sendTimeoutId = null;\n }\n }\n\n function clearUnknown() {\n outcomeUnknown = false;\n unknownTitle.textContent = '';\n unknownText.textContent = '';\n unknownBox.classList.add('hidden');\n }\n\n // No reply ever came back for the send (e.g. the host's response was lost\n // before reaching this iframe). We genuinely don't know whether the email\n // went out, so we must NOT claim success or failure: re-enable the form and\n // tell the user to verify before resending (the send is not idempotent, so\n // a blind retry could send a duplicate). REBEL-677 / FOX-3484.\n function showSendUnknown() {\n outcomeUnknown = true;\n clearError();\n clearSuccess();\n unknownTitle.textContent = 'Not sure if this sent.';\n unknownText.textContent = \"Rebel didn't hear back in time. Check your Sent folder before sending again, so it doesn't go out twice.\";\n unknownBox.classList.remove('hidden');\n postResize();\n }\n\n function handleSendTimeout() {\n sendTimeoutId = null;\n if (!pendingRequestId) {\n return;\n }\n pendingRequestId = null;\n setSending(false);\n showSendUnknown();\n }\n\n function setCcVisible(visible) {\n ccRow.classList.toggle('hidden', !visible);\n toggleCcButton.textContent = visible ? 'Hide CC' : 'Add CC';\n }\n\n function setBccVisible(visible) {\n bccRow.classList.toggle('hidden', !visible);\n toggleBccButton.textContent = visible ? 'Hide BCC' : 'Add BCC';\n }\n\n function readFormPayload() {\n var payload = {\n to: normalizeAddressList(toInput.value),\n cc: normalizeAddressList(ccInput.value),\n bcc: normalizeAddressList(bccInput.value),\n subject: String(subjectInput.value || ''),\n body: String(bodyInput.value || '')\n };\n if (currentEmail) {\n payload.email = currentEmail;\n }\n return payload;\n }\n\n function validatePayload(payload) {\n if (!payload.to || payload.to.length === 0) {\n return 'Add at least one recipient in To.';\n }\n if (!trimString(payload.subject)) {\n return 'Add a subject before sending.';\n }\n if (!trimString(payload.body)) {\n return 'Add an email body before sending.';\n }\n return null;\n }\n\n function sendPayload(payload) {\n pendingPayload = payload;\n pendingRequestId = 'send-' + Date.now() + '-' + Math.random().toString(16).slice(2);\n setSending(true);\n clearError();\n clearSuccess();\n clearUnknown();\n clearSendTimeout();\n sendTimeoutId = setTimeout(handleSendTimeout, SEND_TIMEOUT_MS);\n\n window.parent.postMessage(\n {\n jsonrpc: '2.0',\n method: 'tools/call',\n params: {\n name: 'send_workspace_email',\n arguments: payload\n },\n id: pendingRequestId\n },\n '*'\n );\n }\n\n function applyDraftData(rawDraft) {\n var draft = rawDraft && typeof rawDraft === 'object' ? rawDraft : {};\n toInput.value = listToInputValue(draft.to);\n ccInput.value = listToInputValue(draft.cc);\n bccInput.value = listToInputValue(draft.bcc);\n subjectInput.value = typeof draft.subject === 'string' ? draft.subject : '';\n bodyInput.value = typeof draft.body === 'string' ? draft.body : '';\n currentEmail = typeof draft.email === 'string' ? draft.email : '';\n applyFromValue(currentEmail);\n setCcVisible(normalizeAddressList(draft.cc).length > 0);\n setBccVisible(normalizeAddressList(draft.bcc).length > 0);\n clearError();\n clearSuccess();\n postResize();\n }\n\n function getDraftFromToolResult(payload) {\n if (!payload || typeof payload !== 'object') {\n return null;\n }\n // CANONICAL: post-A0 super-mcp hoists structuredContent onto the\n // outer block; the host posts it through `params.structuredContent`.\n if (payload.structuredContent && typeof payload.structuredContent === 'object') {\n return payload.structuredContent;\n }\n // MIGRATION SHIM: pre-A0 stored sessions replayed through the\n // current iframe lack `params.structuredContent` because the outer\n // block had no hoist at capture time. Read inner envelope text \u2192\n // JSON.parse \u2192 result.structuredContent. NOT regex-based.\n //\n // Lifetime: PERMANENT defensive read-side helper. Pre-A0 sessions\n // are persisted on disk and may be replayed indefinitely; there is\n // no time-based sunset. Removing this fallback would silently break\n // pre-A0 conversation replay.\n var text = typeof payload.text === 'string' ? payload.text :\n (Array.isArray(payload.content)\n ? (payload.content.find(function (c) { return c && c.type === 'text' && typeof c.text === 'string'; }) || {}).text\n : null);\n if (typeof text !== 'string') return null;\n try {\n var parsed = JSON.parse(text);\n if (parsed && typeof parsed === 'object' && parsed.result && typeof parsed.result === 'object') {\n var inner = parsed.result;\n if (inner.structuredContent && typeof inner.structuredContent === 'object') {\n return inner.structuredContent;\n }\n }\n } catch (_) {\n // Likely-envelope heuristic: text starts with `{` and contains\n // `\"package_id\"` in the first 64 chars. If JSON.parse failed on a\n // likely-envelope, surface a warning so the developer chasing\n // \"compose form is empty on replay\" sees a signal. For non-envelope\n // text (the dominant case), no log fires.\n var prefix = text.length > 64 ? text.slice(0, 64) : text;\n var likelyEnvelope = prefix.charAt(0) === '{' && prefix.indexOf('\"package_id\"') !== -1;\n if (likelyEnvelope && typeof console !== 'undefined' && typeof console.warn === 'function') {\n console.warn('[compose-email] Migration shim: JSON.parse failed on likely super-mcp envelope; pre-fill skipped');\n }\n }\n return null;\n }\n\n function handleSendRequest() {\n if (sending) return;\n\n var payload = readFormPayload();\n var validationError = validatePayload(payload);\n if (validationError) {\n showError(validationError);\n return;\n }\n\n sendPayload(payload);\n }\n\n // The Send button is type=\"button\" with an explicit click handler rather\n // than a form submit button. The Rebel host renders this iframe with a\n // sandbox of \"allow-scripts\" only \u2014 no \"allow-forms\" \u2014 so native form\n // submission is blocked by the browser BEFORE the submit event fires\n // (\"Blocked form submission ... the form's frame is sandboxed and the\n // allow-forms permission is not set\"). A submit-driven Send therefore\n // silently did nothing: no postMessage, no spinner, no telemetry.\n // A click handler needs no sandbox permission and is the same path\n // Cancel/Retry already use. The submit listener below stays only as a\n // defensive fallback for hosts that DO grant allow-forms; in this sandbox\n // it never fires (neither the button click nor Enter routes through it).\n // The sending guard keeps any double-fire (in an allow-forms host) a no-op.\n sendButton.addEventListener('click', function () {\n handleSendRequest();\n });\n\n composeForm.addEventListener('submit', function (event) {\n event.preventDefault();\n handleSendRequest();\n });\n\n retryButton.addEventListener('click', function () {\n if (sending) return;\n var payload = readFormPayload();\n var validationError = validatePayload(payload);\n if (validationError) {\n showError(validationError);\n return;\n }\n sendPayload(payload);\n });\n\n cancelButton.addEventListener('click', function () {\n if (sending) return;\n // After a lost-reply timeout we don't know if the email sent, so don't\n // claim \"Nothing sent.\" on collapse \u2014 point the user to verify instead.\n var collapseMessage = outcomeUnknown\n ? 'Collapsed. Check your Sent folder if you are not sure.'\n : 'Draft collapsed. Nothing sent.';\n clearError();\n clearSuccess();\n clearUnknown();\n setCollapsed(true, collapseMessage);\n });\n\n reopenButton.addEventListener('click', function () {\n setCollapsed(false);\n });\n\n toggleCcButton.addEventListener('click', function () {\n setCcVisible(ccRow.classList.contains('hidden'));\n postResize();\n });\n\n toggleBccButton.addEventListener('click', function () {\n setBccVisible(bccRow.classList.contains('hidden'));\n postResize();\n });\n\n [toInput, ccInput, bccInput, subjectInput, bodyInput].forEach(function (element) {\n element.addEventListener('input', function () {\n clearError();\n clearSuccess();\n clearUnknown();\n postResize();\n });\n });\n\n window.addEventListener('message', function (event) {\n var data = event.data;\n if (!data || typeof data !== 'object') {\n return;\n }\n\n if (data.method === 'ui/notifications/tool-result') {\n var draft = getDraftFromToolResult(data.params);\n if (draft) {\n applyDraftData(draft);\n }\n return;\n }\n\n if (data.jsonrpc !== '2.0' || !pendingRequestId || data.id !== pendingRequestId) {\n return;\n }\n\n pendingRequestId = null;\n clearSendTimeout();\n clearUnknown();\n setSending(false);\n\n if (data.error) {\n var errorMessage = data.error && typeof data.error.message === 'string'\n ? data.error.message\n : 'Failed to send email.';\n showError(errorMessage);\n return;\n }\n\n clearError();\n showSuccess('Email sent successfully.');\n setCollapsed(true, 'Email sent.');\n reopenButton.classList.add('hidden');\n });\n\n if (typeof ResizeObserver === 'function' && document.body) {\n var observer = new ResizeObserver(postResize);\n observer.observe(document.body);\n }\n\n applyThemeFromHostContext();\n setCcVisible(false);\n setBccVisible(false);\n setCollapsed(false);\n postResize();\n postReady();\n\n window.parent.postMessage(\n {\n jsonrpc: '2.0',\n method: 'ui/initialize',\n params: { resourceUri: RESOURCE_URI },\n id: 'compose-email-init'\n },\n '*'\n );\n })();\n </script>\n</body>\n</html>\n";
|
|
1
|
+
export declare const COMPOSE_EMAIL_HTML = "\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>Compose Email</title>\n <style>\n :root {\n --bg: #ffffff;\n --panel: #ffffff;\n --border: #d9dde5;\n --text: #1f2937;\n --muted: #6b7280;\n --input-bg: #ffffff;\n --button-bg: #1f6feb;\n --button-text: #ffffff;\n --button-bg-hover: #1b63d3;\n --secondary-bg: #f3f4f6;\n --secondary-text: #1f2937;\n --secondary-border: #d1d5db;\n --error-bg: #fef2f2;\n --error-border: #fecaca;\n --error-text: #991b1b;\n --success-bg: #ecfdf5;\n --success-border: #bbf7d0;\n --success-text: #166534;\n --warning-bg: #fffbeb;\n --warning-border: #fde68a;\n --warning-text: #92400e;\n }\n\n @media (prefers-color-scheme: dark) {\n :root {\n --bg: #0f172a;\n --panel: #111827;\n --border: #334155;\n --text: #e5e7eb;\n --muted: #9ca3af;\n --input-bg: #0b1220;\n --button-bg: #3b82f6;\n --button-text: #eff6ff;\n --button-bg-hover: #2563eb;\n --secondary-bg: #1f2937;\n --secondary-text: #e5e7eb;\n --secondary-border: #374151;\n --error-bg: #2b1011;\n --error-border: #7f1d1d;\n --error-text: #fca5a5;\n --success-bg: #052e1b;\n --success-border: #166534;\n --success-text: #86efac;\n --warning-bg: #2a2106;\n --warning-border: #854d0e;\n --warning-text: #fcd34d;\n }\n }\n\n html[data-theme=\"light\"] {\n color-scheme: light;\n }\n\n html[data-theme=\"dark\"] {\n color-scheme: dark;\n --bg: #0f172a;\n --panel: #111827;\n --border: #334155;\n --text: #e5e7eb;\n --muted: #9ca3af;\n --input-bg: #0b1220;\n --button-bg: #3b82f6;\n --button-text: #eff6ff;\n --button-bg-hover: #2563eb;\n --secondary-bg: #1f2937;\n --secondary-text: #e5e7eb;\n --secondary-border: #374151;\n --error-bg: #2b1011;\n --error-border: #7f1d1d;\n --error-text: #fca5a5;\n --success-bg: #052e1b;\n --success-border: #166534;\n --success-text: #86efac;\n --warning-bg: #2a2106;\n --warning-border: #854d0e;\n --warning-text: #fcd34d;\n }\n\n * {\n box-sizing: border-box;\n }\n\n body {\n margin: 0;\n padding: 16px;\n background: var(--bg);\n color: var(--text);\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n line-height: 1.4;\n }\n\n .wrapper {\n width: 100%;\n max-width: 720px;\n margin: 0 auto;\n }\n\n .card {\n background: var(--panel);\n border: 1px solid var(--border);\n border-radius: 12px;\n padding: 14px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n\n .field {\n display: flex;\n flex-direction: column;\n gap: 6px;\n }\n\n .field label {\n font-size: 12px;\n font-weight: 600;\n color: var(--muted);\n text-transform: uppercase;\n letter-spacing: 0.04em;\n }\n\n .from-value {\n color: var(--text);\n font-size: 14px;\n padding: 2px 0;\n word-break: break-word;\n }\n\n .from-helper {\n font-size: 12px;\n color: var(--muted);\n margin-top: 2px;\n }\n\n .input,\n .textarea {\n width: 100%;\n background: var(--input-bg);\n color: var(--text);\n border: 1px solid var(--border);\n border-radius: 8px;\n padding: 10px 12px;\n font-size: 14px;\n font-family: inherit;\n }\n\n .input:focus,\n .textarea:focus {\n outline: 2px solid rgba(59, 130, 246, 0.35);\n outline-offset: 1px;\n }\n\n .textarea {\n min-height: 180px;\n resize: vertical;\n white-space: pre-wrap;\n }\n\n .toggles {\n display: flex;\n gap: 12px;\n align-items: center;\n flex-wrap: wrap;\n }\n\n .link-button {\n border: none;\n padding: 0;\n background: none;\n color: var(--muted);\n text-decoration: underline;\n font-size: 12px;\n cursor: pointer;\n }\n\n .link-button:hover {\n color: var(--text);\n }\n\n .actions {\n display: flex;\n justify-content: flex-end;\n gap: 10px;\n margin-top: 2px;\n }\n\n .button {\n border-radius: 8px;\n border: 1px solid transparent;\n min-height: 36px;\n padding: 0 14px;\n font-size: 13px;\n font-weight: 600;\n font-family: inherit;\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n transition: background 120ms ease, opacity 120ms ease, border-color 120ms ease;\n }\n\n .button:disabled {\n cursor: not-allowed;\n opacity: 0.75;\n }\n\n .button-primary {\n background: var(--button-bg);\n color: var(--button-text);\n }\n\n .button-primary:hover:enabled {\n background: var(--button-bg-hover);\n }\n\n .button-secondary {\n background: var(--secondary-bg);\n color: var(--secondary-text);\n border-color: var(--secondary-border);\n }\n\n .spinner {\n width: 14px;\n height: 14px;\n border: 2px solid currentColor;\n border-right-color: transparent;\n border-radius: 50%;\n display: inline-block;\n animation: spin 700ms linear infinite;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n .status {\n border-radius: 8px;\n border: 1px solid transparent;\n padding: 8px 10px;\n font-size: 13px;\n }\n\n .error {\n background: var(--error-bg);\n border-color: var(--error-border);\n color: var(--error-text);\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: 8px;\n flex-wrap: wrap;\n }\n\n .success {\n background: var(--success-bg);\n border-color: var(--success-border);\n color: var(--success-text);\n }\n\n .warning {\n background: var(--warning-bg);\n border-color: var(--warning-border);\n color: var(--warning-text);\n display: block;\n }\n\n .warning strong {\n display: block;\n margin-bottom: 2px;\n }\n\n .warning .warning-detail {\n opacity: 0.85;\n }\n\n .blocked-actions {\n margin-top: 8px;\n }\n\n .collapsed {\n border: 1px solid var(--border);\n border-radius: 10px;\n background: var(--panel);\n padding: 10px 12px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: 8px;\n font-size: 13px;\n }\n\n .hidden {\n display: none !important;\n }\n\n .sent-header {\n display: flex;\n align-items: center;\n gap: 8px;\n flex-wrap: wrap;\n }\n\n .sent-badge {\n display: inline-flex;\n align-items: center;\n background: var(--success-bg);\n color: var(--success-text);\n border: 1px solid var(--success-border);\n border-radius: 999px;\n padding: 2px 10px;\n font-size: 12px;\n font-weight: 600;\n }\n\n .sent-timestamp {\n color: var(--muted);\n font-size: 12px;\n }\n\n .sent-value {\n color: var(--text);\n font-size: 14px;\n word-break: break-word;\n }\n\n .sent-body {\n color: var(--text);\n font-size: 14px;\n white-space: pre-wrap;\n word-break: break-word;\n max-height: 260px;\n overflow: auto;\n border: 1px solid var(--border);\n border-radius: 8px;\n padding: 10px 12px;\n background: var(--input-bg);\n }\n </style>\n</head>\n<body>\n <div class=\"wrapper\">\n <div id=\"collapsedState\" class=\"collapsed hidden\">\n <span id=\"collapsedMessage\">Draft collapsed.</span>\n <button id=\"reopenButton\" type=\"button\" class=\"button button-secondary\">Reopen</button>\n </div>\n\n <form id=\"composeForm\" class=\"card\" novalidate aria-label=\"Compose email\">\n <div class=\"field from-field\">\n <label>From</label>\n <span id=\"fromValue\" class=\"from-value\"></span>\n <span id=\"fromHelper\" class=\"from-helper hidden\"></span>\n </div>\n\n <div class=\"field\">\n <label for=\"toInput\">To</label>\n <input id=\"toInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"name@example.com, team@example.com\">\n </div>\n\n <div class=\"toggles\">\n <button id=\"toggleCcButton\" type=\"button\" class=\"link-button\" aria-expanded=\"false\" aria-controls=\"ccRow\">Add CC</button>\n <button id=\"toggleBccButton\" type=\"button\" class=\"link-button\" aria-expanded=\"false\" aria-controls=\"bccRow\">Add BCC</button>\n </div>\n\n <div id=\"ccRow\" class=\"field hidden\">\n <label for=\"ccInput\">CC</label>\n <input id=\"ccInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"cc@example.com\">\n </div>\n\n <div id=\"bccRow\" class=\"field hidden\">\n <label for=\"bccInput\">BCC</label>\n <input id=\"bccInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"bcc@example.com\">\n </div>\n\n <div class=\"field\">\n <label for=\"subjectInput\">Subject</label>\n <input id=\"subjectInput\" class=\"input\" type=\"text\" autocomplete=\"off\" placeholder=\"Email subject\">\n </div>\n\n <div class=\"field\">\n <label for=\"bodyInput\">Body</label>\n <textarea id=\"bodyInput\" class=\"textarea\" placeholder=\"Write your email\"></textarea>\n </div>\n\n <div id=\"errorBox\" class=\"status error hidden\" role=\"alert\">\n <span id=\"errorText\"></span>\n <button id=\"retryButton\" type=\"button\" class=\"link-button\">Retry</button>\n </div>\n\n <div id=\"blockedBox\" class=\"status warning hidden\" role=\"status\" aria-live=\"polite\">\n <span id=\"blockedText\"></span>\n <div class=\"blocked-actions\">\n <button id=\"openComposeButton\" type=\"button\" class=\"button button-secondary\">Open in Gmail</button>\n </div>\n </div>\n\n <div id=\"successBox\" class=\"status success hidden\" role=\"status\" aria-live=\"polite\"></div>\n\n <div id=\"unknownBox\" class=\"status warning hidden\" role=\"status\" aria-live=\"polite\">\n <strong id=\"unknownTitle\"></strong>\n <span id=\"unknownText\" class=\"warning-detail\"></span>\n </div>\n\n <div class=\"actions\">\n <button id=\"cancelButton\" type=\"button\" class=\"button button-secondary\">Cancel</button>\n <button id=\"sendButton\" type=\"button\" class=\"button button-primary\">\n <span id=\"sendSpinner\" class=\"spinner hidden\" aria-hidden=\"true\"></span>\n <span id=\"sendLabel\">Send email</span>\n </button>\n </div>\n </form>\n\n <div id=\"sentView\" class=\"card hidden\" role=\"status\" aria-live=\"polite\">\n <div class=\"sent-header\">\n <span class=\"sent-badge\">Sent</span>\n <span id=\"sentTimestamp\" class=\"sent-timestamp\"></span>\n </div>\n\n <div class=\"field\">\n <label>From</label>\n <span id=\"sentFrom\" class=\"sent-value\"></span>\n </div>\n\n <div class=\"field\">\n <label>To</label>\n <span id=\"sentTo\" class=\"sent-value\"></span>\n </div>\n\n <div id=\"sentCcField\" class=\"field hidden\">\n <label>CC</label>\n <span id=\"sentCc\" class=\"sent-value\"></span>\n </div>\n\n <div id=\"sentBccField\" class=\"field hidden\">\n <label>BCC</label>\n <span id=\"sentBcc\" class=\"sent-value\"></span>\n </div>\n\n <div class=\"field\">\n <label>Subject</label>\n <span id=\"sentSubject\" class=\"sent-value\"></span>\n </div>\n\n <div class=\"field\">\n <label>Message</label>\n <div id=\"sentBody\" class=\"sent-body\"></div>\n </div>\n\n <div class=\"actions\">\n <button id=\"openGmailButton\" type=\"button\" class=\"button button-secondary hidden\">Open in Gmail</button>\n <button id=\"sentCollapseButton\" type=\"button\" class=\"button button-secondary\">Collapse</button>\n </div>\n </div>\n </div>\n\n <script>\n (function () {\n 'use strict';\n\n var RESOURCE_URI = 'ui://google-workspace/compose-email';\n var currentEmail = '';\n // The host prefills the draft exactly once via ui/notifications/tool-result\n // on ready. We apply only the FIRST prefill and ignore any later ones, so a\n // stray or hostile re-post can't silently rewrite a draft the user has\n // already reviewed before clicking Send.\n var draftApplied = false;\n var pendingRequestId = null;\n var pendingPayload = null;\n var sending = false;\n var collapsed = false;\n var outcomeUnknown = false;\n var sent = false;\n var sendBlocked = false;\n var gmailUrl = null;\n var sendTimeoutId = null;\n // Just beyond the host-side tool-call timeout (60s) so a legitimately slow\n // send resolves to its real result first; this only fires when the reply\n // is genuinely lost, so the button can never stay stuck-silent.\n var SEND_TIMEOUT_MS = 75000;\n\n var composeForm = document.getElementById('composeForm');\n var collapsedState = document.getElementById('collapsedState');\n var collapsedMessage = document.getElementById('collapsedMessage');\n var reopenButton = document.getElementById('reopenButton');\n\n var sentView = document.getElementById('sentView');\n var sentTimestamp = document.getElementById('sentTimestamp');\n var sentFrom = document.getElementById('sentFrom');\n var sentTo = document.getElementById('sentTo');\n var sentCcField = document.getElementById('sentCcField');\n var sentCc = document.getElementById('sentCc');\n var sentBccField = document.getElementById('sentBccField');\n var sentBcc = document.getElementById('sentBcc');\n var sentSubject = document.getElementById('sentSubject');\n var sentBody = document.getElementById('sentBody');\n var openGmailButton = document.getElementById('openGmailButton');\n var sentCollapseButton = document.getElementById('sentCollapseButton');\n\n var toInput = document.getElementById('toInput');\n var ccInput = document.getElementById('ccInput');\n var bccInput = document.getElementById('bccInput');\n var subjectInput = document.getElementById('subjectInput');\n var bodyInput = document.getElementById('bodyInput');\n var fromValue = document.getElementById('fromValue');\n var fromHelper = document.getElementById('fromHelper');\n var ccRow = document.getElementById('ccRow');\n var bccRow = document.getElementById('bccRow');\n var toggleCcButton = document.getElementById('toggleCcButton');\n var toggleBccButton = document.getElementById('toggleBccButton');\n\n var sendButton = document.getElementById('sendButton');\n var sendLabel = document.getElementById('sendLabel');\n var sendSpinner = document.getElementById('sendSpinner');\n var cancelButton = document.getElementById('cancelButton');\n var retryButton = document.getElementById('retryButton');\n\n var errorBox = document.getElementById('errorBox');\n var errorText = document.getElementById('errorText');\n var successBox = document.getElementById('successBox');\n var unknownBox = document.getElementById('unknownBox');\n var unknownTitle = document.getElementById('unknownTitle');\n var unknownText = document.getElementById('unknownText');\n var blockedBox = document.getElementById('blockedBox');\n var blockedText = document.getElementById('blockedText');\n var openComposeButton = document.getElementById('openComposeButton');\n\n function applyThemeFromHostContext() {\n try {\n var context = window.__MCP_HOST_CONTEXT__;\n if (!context || (context.theme !== 'light' && context.theme !== 'dark')) {\n return;\n }\n document.documentElement.setAttribute('data-theme', context.theme);\n } catch (_) {\n // Ignore theme extraction errors\n }\n }\n\n function trimString(value) {\n return String(value || '').trim();\n }\n\n function applyFromValue(email) {\n var trimmed = trimString(email);\n if (trimmed) {\n fromValue.textContent = trimmed;\n fromValue.style.color = '';\n fromHelper.textContent = '';\n fromHelper.classList.add('hidden');\n } else {\n fromValue.textContent = 'Account not shown';\n fromValue.style.color = 'var(--muted)';\n fromHelper.textContent = 'Rebel could not confirm the sending account. Cancel and ask Rebel to recreate the draft before sending.';\n fromHelper.classList.remove('hidden');\n }\n }\n\n function formatAddressItem(item) {\n if (item && typeof item === 'object') {\n var email = trimString(item.email || item.address || item.value);\n var name = trimString(item.name || item.displayName);\n if (email && name) {\n return name + ' <' + email + '>';\n }\n return email;\n }\n return trimString(item);\n }\n\n function normalizeAddressList(value) {\n if (Array.isArray(value)) {\n return value.map(formatAddressItem).filter(Boolean);\n }\n if (typeof value === 'string') {\n return value\n .split(',')\n .map(function (item) { return trimString(item); })\n .filter(Boolean);\n }\n return [];\n }\n\n function listToInputValue(list) {\n return normalizeAddressList(list).join(', ');\n }\n\n var resizeQueued = false;\n function postResize() {\n if (resizeQueued) return;\n resizeQueued = true;\n requestAnimationFrame(function () {\n resizeQueued = false;\n var height = Math.max(\n document.documentElement.scrollHeight,\n document.body ? document.body.scrollHeight : 0\n );\n window.parent.postMessage(\n { jsonrpc: '2.0', method: 'ui/resize', params: { height: height } },\n '*'\n );\n });\n }\n\n function postReady() {\n window.parent.postMessage(\n {\n method: 'mcp-app:ready',\n params: { resourceUri: RESOURCE_URI }\n },\n '*'\n );\n }\n\n // Exactly one of the three panels is visible at a time: the editable form,\n // the read-only sent view, or the collapsed summary bar.\n function showView(view) {\n composeForm.classList.toggle('hidden', view !== 'form');\n sentView.classList.toggle('hidden', view !== 'sent');\n collapsedState.classList.toggle('hidden', view !== 'collapsed');\n postResize();\n }\n\n function setCollapsed(nextCollapsed, message) {\n collapsed = nextCollapsed;\n if (nextCollapsed) {\n collapsedMessage.textContent = message || 'Draft collapsed.';\n showView('collapsed');\n } else {\n // Expanding after a send restores the read-only sent view (never the\n // editable form) so the user can re-read what went out without any risk\n // of a duplicate send; before sending, it restores the editable form.\n showView(sent ? 'sent' : 'form');\n }\n }\n\n function setSending(nextSending) {\n sending = nextSending;\n sendButton.disabled = nextSending || sendBlocked;\n cancelButton.disabled = nextSending;\n toInput.disabled = nextSending;\n ccInput.disabled = nextSending;\n bccInput.disabled = nextSending;\n subjectInput.disabled = nextSending;\n bodyInput.disabled = nextSending;\n sendSpinner.classList.toggle('hidden', !nextSending);\n sendLabel.textContent = nextSending ? 'Sending\u2026' : 'Send email';\n sendButton.setAttribute('aria-busy', nextSending ? 'true' : 'false');\n postResize();\n }\n\n function clearError() {\n errorText.textContent = '';\n errorBox.classList.add('hidden');\n }\n\n function showError(message) {\n errorText.textContent = message || 'Failed to send email.';\n errorBox.classList.remove('hidden');\n postResize();\n }\n\n function clearSuccess() {\n successBox.textContent = '';\n successBox.classList.add('hidden');\n }\n\n function showSuccess(message) {\n successBox.textContent = message;\n successBox.classList.remove('hidden');\n postResize();\n }\n\n function clearSendTimeout() {\n if (sendTimeoutId !== null) {\n clearTimeout(sendTimeoutId);\n sendTimeoutId = null;\n }\n }\n\n function clearUnknown() {\n outcomeUnknown = false;\n unknownTitle.textContent = '';\n unknownText.textContent = '';\n unknownBox.classList.add('hidden');\n }\n\n // No reply ever came back for the send (e.g. the host's response was lost\n // before reaching this iframe). We genuinely don't know whether the email\n // went out, so we must NOT claim success or failure: re-enable the form and\n // tell the user to verify before resending (the send is not idempotent, so\n // a blind retry could send a duplicate).\n function showSendUnknown() {\n outcomeUnknown = true;\n clearError();\n clearSuccess();\n unknownTitle.textContent = 'Not sure if this sent.';\n unknownText.textContent = \"Rebel didn't hear back in time. Check your Sent folder before sending again, so it doesn't go out twice.\";\n unknownBox.classList.remove('hidden');\n postResize();\n }\n\n function handleSendTimeout() {\n sendTimeoutId = null;\n if (!pendingRequestId) {\n return;\n }\n pendingRequestId = null;\n setSending(false);\n showSendUnknown();\n }\n\n function setCcVisible(visible) {\n ccRow.classList.toggle('hidden', !visible);\n toggleCcButton.textContent = visible ? 'Hide CC' : 'Add CC';\n toggleCcButton.setAttribute('aria-expanded', visible ? 'true' : 'false');\n }\n\n function setBccVisible(visible) {\n bccRow.classList.toggle('hidden', !visible);\n toggleBccButton.textContent = visible ? 'Hide BCC' : 'Add BCC';\n toggleBccButton.setAttribute('aria-expanded', visible ? 'true' : 'false');\n }\n\n function readFormPayload() {\n var payload = {\n to: normalizeAddressList(toInput.value),\n cc: normalizeAddressList(ccInput.value),\n bcc: normalizeAddressList(bccInput.value),\n subject: String(subjectInput.value || ''),\n body: String(bodyInput.value || '')\n };\n if (currentEmail) {\n payload.email = currentEmail;\n }\n return payload;\n }\n\n function validatePayload(payload) {\n if (!payload.to || payload.to.length === 0) {\n return 'Add at least one recipient in To.';\n }\n if (!trimString(payload.subject)) {\n return 'Add a subject before sending.';\n }\n if (!trimString(payload.body)) {\n return 'Add an email body before sending.';\n }\n return null;\n }\n\n function sendPayload(payload) {\n pendingPayload = payload;\n pendingRequestId = 'send-' + Date.now() + '-' + Math.random().toString(16).slice(2);\n setSending(true);\n clearError();\n clearSuccess();\n clearUnknown();\n clearSendTimeout();\n sendTimeoutId = setTimeout(handleSendTimeout, SEND_TIMEOUT_MS);\n\n window.parent.postMessage(\n {\n jsonrpc: '2.0',\n method: 'tools/call',\n params: {\n name: 'send_workspace_email',\n arguments: payload\n },\n id: pendingRequestId\n },\n '*'\n );\n }\n\n function applyDraftData(rawDraft) {\n var draft = rawDraft && typeof rawDraft === 'object' ? rawDraft : {};\n toInput.value = listToInputValue(draft.to);\n ccInput.value = listToInputValue(draft.cc);\n bccInput.value = listToInputValue(draft.bcc);\n subjectInput.value = typeof draft.subject === 'string' ? draft.subject : '';\n bodyInput.value = typeof draft.body === 'string' ? draft.body : '';\n currentEmail = typeof draft.email === 'string' ? draft.email : '';\n applyFromValue(currentEmail);\n setCcVisible(normalizeAddressList(draft.cc).length > 0);\n setBccVisible(normalizeAddressList(draft.bcc).length > 0);\n clearError();\n clearSuccess();\n postResize();\n }\n\n function getDraftFromToolResult(payload) {\n if (!payload || typeof payload !== 'object') {\n return null;\n }\n // CANONICAL: post-A0 super-mcp hoists structuredContent onto the\n // outer block; the host posts it through `params.structuredContent`.\n if (payload.structuredContent && typeof payload.structuredContent === 'object') {\n return payload.structuredContent;\n }\n // MIGRATION SHIM: pre-A0 stored sessions replayed through the\n // current iframe lack `params.structuredContent` because the outer\n // block had no hoist at capture time. Read inner envelope text \u2192\n // JSON.parse \u2192 result.structuredContent. NOT regex-based.\n //\n // Lifetime: PERMANENT defensive read-side helper. Pre-A0 sessions\n // are persisted on disk and may be replayed indefinitely; there is\n // no time-based sunset. Removing this fallback would silently break\n // pre-A0 conversation replay.\n var text = typeof payload.text === 'string' ? payload.text :\n (Array.isArray(payload.content)\n ? (payload.content.find(function (c) { return c && c.type === 'text' && typeof c.text === 'string'; }) || {}).text\n : null);\n if (typeof text !== 'string') return null;\n try {\n var parsed = JSON.parse(text);\n if (parsed && typeof parsed === 'object' && parsed.result && typeof parsed.result === 'object') {\n var inner = parsed.result;\n if (inner.structuredContent && typeof inner.structuredContent === 'object') {\n return inner.structuredContent;\n }\n }\n } catch (_) {\n // Likely-envelope heuristic: text starts with `{` and contains\n // `\"package_id\"` in the first 64 chars. If JSON.parse failed on a\n // likely-envelope, surface a warning so the developer chasing\n // \"compose form is empty on replay\" sees a signal. For non-envelope\n // text (the dominant case), no log fires.\n var prefix = text.length > 64 ? text.slice(0, 64) : text;\n var likelyEnvelope = prefix.charAt(0) === '{' && prefix.indexOf('\"package_id\"') !== -1;\n if (likelyEnvelope && typeof console !== 'undefined' && typeof console.warn === 'function') {\n console.warn('[compose-email] Migration shim: JSON.parse failed on likely super-mcp envelope; pre-fill skipped');\n }\n }\n return null;\n }\n\n function findTextBlock(blocks) {\n if (!Array.isArray(blocks)) return null;\n var block = blocks.find(function (c) {\n return c && c.type === 'text' && typeof c.text === 'string';\n });\n return block ? block.text : null;\n }\n\n // Extract the send result identifiers ({ messageId, threadId, labelIds })\n // from the tool-call reply. The connector attaches structuredContent, which\n // super-mcp hoists onto the outer block, so the fast path is a single read.\n // The envelope-unwrapping fallback keeps this robust for hosts (or replayed\n // sessions) that forward only the serialized super-mcp text envelope.\n function getSendMetaFromResult(result) {\n if (!result || typeof result !== 'object') return null;\n if (result.structuredContent && typeof result.structuredContent === 'object') {\n return result.structuredContent;\n }\n try {\n var outerText = findTextBlock(result.content);\n if (typeof outerText !== 'string' && typeof result.text === 'string') {\n outerText = result.text;\n }\n if (typeof outerText !== 'string') return null;\n var envelope = JSON.parse(outerText);\n if (!envelope || typeof envelope !== 'object') return null;\n // outerText was the connector payload directly (no super-mcp envelope).\n if (envelope.messageId || envelope.threadId) return envelope;\n var inner = envelope.result;\n if (!inner || typeof inner !== 'object') return null;\n if (inner.structuredContent && typeof inner.structuredContent === 'object') {\n return inner.structuredContent;\n }\n var innerText = findTextBlock(inner.content);\n if (typeof innerText !== 'string') return null;\n var payload = JSON.parse(innerText);\n return (payload && typeof payload === 'object') ? payload : null;\n } catch (_) {\n return null;\n }\n }\n\n // ---- Blocked-send Gmail escape hatch ----\n // Shown ONLY when the user's own send preference blocks the tool\n // (super-mcp TOOL_BLOCKED / -33008 + \"disabled by user preference\"). We\n // never call the disabled tool; instead we open a prefilled Gmail compose\n // window so the user finishes the send in Gmail (no copy-paste). This is\n // deliberately narrow: admin-disabled (\"disabled by your organization\u2026\")\n // and generic security-policy blocks fall through to the normal retryable\n // error, because offering a Gmail bypass there would route around a control\n // the user did not set.\n //\n // Gmail compose URLs that get too long can silently fail to open, so we cap\n // the length and degrade visibly (recipients + subject only, paste the body)\n // rather than truncating without telling the user.\n var GMAIL_COMPOSE_MAX_URL = 8000;\n var BLOCKED_SEND_MESSAGE =\n 'Sending from here is turned off in your settings. You can finish and send this email in Gmail, or turn sending back on in Settings.';\n\n function isUserDisabledSendError(message) {\n var m = String(message || '').toLowerCase();\n // Anchor the code so it can't match inside a longer number (-330080),\n // and require the user-preference phrase so admin-disabled / generic\n // security blocks fall through to the ordinary retryable error.\n return /-33008\\b/.test(m) && m.indexOf('disabled by user preference') !== -1;\n }\n\n // Base URL + path are constant (code-reviewed here, never config-provided);\n // only the field VALUES vary and go through URLSearchParams, so query\n // delimiters, newlines, and reserved characters become encoded data \u2014 no\n // query injection or header splitting. The host ui/open-external-link\n // bridge re-validates the mail.google.com host before opening.\n function buildGmailComposeUrl(payload, includeBody) {\n var url = new URL('https://mail.google.com/mail/');\n var params = new URLSearchParams();\n params.set('view', 'cm');\n params.set('fs', '1');\n var to = normalizeAddressList(payload.to).join(',');\n if (to) params.set('to', to);\n var cc = normalizeAddressList(payload.cc).join(',');\n if (cc) params.set('cc', cc);\n var bcc = normalizeAddressList(payload.bcc).join(',');\n if (bcc) params.set('bcc', bcc);\n var subject = trimString(payload.subject);\n if (subject) params.set('su', subject);\n if (includeBody) {\n var body = String(payload.body || '');\n if (body) params.set('body', body);\n }\n url.search = params.toString();\n return url.toString();\n }\n\n function showBlockedSend() {\n sendBlocked = true;\n clearError();\n clearSuccess();\n clearUnknown();\n sendButton.disabled = true;\n sendButton.title =\n 'Sending from here is turned off in your settings. Turn it back on in Settings, or open this draft in Gmail to send.';\n blockedText.textContent = BLOCKED_SEND_MESSAGE;\n blockedBox.classList.remove('hidden');\n postResize();\n }\n\n openComposeButton.addEventListener('click', function () {\n // Reset any prior \"too long\" note, then rebuild from the live form so\n // edits made after the block are reflected.\n blockedText.textContent = BLOCKED_SEND_MESSAGE;\n var payload = readFormPayload();\n var composeUrl = buildGmailComposeUrl(payload, true);\n if (composeUrl.length > GMAIL_COMPOSE_MAX_URL) {\n composeUrl = buildGmailComposeUrl(payload, false);\n if (composeUrl.length > GMAIL_COMPOSE_MAX_URL) {\n // Even without the body the link is too long (many recipients, or a\n // very long subject). Gmail would silently refuse to open it, so\n // don't pretend \u2014 tell the user and post nothing.\n blockedText.textContent =\n 'This draft is too large to open in Gmail. Shorten the recipients or subject, or turn sending back on in Settings.';\n postResize();\n return;\n }\n blockedText.textContent =\n 'This email is long, so Gmail will open with just the recipients and subject. Copy the message text above into Gmail before sending.';\n postResize();\n }\n window.parent.postMessage(\n { jsonrpc: '2.0', method: 'ui/open-external-link', params: { url: composeUrl } },\n '*'\n );\n });\n\n function looksLikeEmail(value) {\n var at = value.indexOf('@');\n return at > 0 && at === value.lastIndexOf('@') && value.indexOf(' ') === -1;\n }\n\n // Build a Gmail deep link to the just-sent message. The /u/<account> segment\n // targets the right inbox when the user is signed into several Google\n // accounts; #all/<id> opens the thread (falling back to the message id).\n function buildGmailUrl(meta, email) {\n if (!meta || typeof meta !== 'object') return null;\n var id = trimString(meta.threadId) || trimString(meta.messageId);\n if (!id || !/^[A-Za-z0-9_-]+$/.test(id)) return null;\n var account = trimString(email);\n var userPart = looksLikeEmail(account) ? encodeURIComponent(account) : '0';\n return 'https://mail.google.com/mail/u/' + userPart + '/#all/' + encodeURIComponent(id);\n }\n\n function formatSentTime() {\n try {\n return new Date().toLocaleString(undefined, {\n month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit'\n });\n } catch (_) {\n return '';\n }\n }\n\n function renderSentView(payload, meta, stamp) {\n payload = payload && typeof payload === 'object' ? payload : {};\n sentTimestamp.textContent = stamp ? 'Sent ' + stamp : 'Sent';\n sentFrom.textContent = trimString(payload.email) || 'Account not shown';\n sentTo.textContent = normalizeAddressList(payload.to).join(', ');\n var ccList = normalizeAddressList(payload.cc);\n sentCc.textContent = ccList.join(', ');\n sentCcField.classList.toggle('hidden', ccList.length === 0);\n var bccList = normalizeAddressList(payload.bcc);\n sentBcc.textContent = bccList.join(', ');\n sentBccField.classList.toggle('hidden', bccList.length === 0);\n sentSubject.textContent = String(payload.subject || '');\n sentBody.textContent = String(payload.body || '');\n gmailUrl = buildGmailUrl(meta, payload.email);\n openGmailButton.classList.toggle('hidden', !gmailUrl);\n }\n\n function handleSendRequest() {\n if (sending) return;\n // Once the user's own send preference has blocked this tool, never\n // re-invoke it \u2014 the escape hatch is the only path out. The Send button\n // is already disabled, but this also fends off a future host that grants\n // allow-forms (a submit could otherwise re-fire the disabled tool).\n if (sendBlocked) return;\n\n var payload = readFormPayload();\n var validationError = validatePayload(payload);\n if (validationError) {\n showError(validationError);\n return;\n }\n\n sendPayload(payload);\n }\n\n // The Send button is type=\"button\" with an explicit click handler rather\n // than a form submit button. The Rebel host renders this iframe with a\n // sandbox of \"allow-scripts\" only \u2014 no \"allow-forms\" \u2014 so native form\n // submission is blocked by the browser BEFORE the submit event fires\n // (\"Blocked form submission ... the form's frame is sandboxed and the\n // allow-forms permission is not set\"). A submit-driven Send therefore\n // silently did nothing: no postMessage, no spinner, no telemetry.\n // A click handler needs no sandbox permission and is the same path\n // Cancel/Retry already use. The submit listener below stays only as a\n // defensive fallback for hosts that DO grant allow-forms; in this sandbox\n // it never fires (neither the button click nor Enter routes through it).\n // The sending guard keeps any double-fire (in an allow-forms host) a no-op.\n sendButton.addEventListener('click', function () {\n handleSendRequest();\n });\n\n composeForm.addEventListener('submit', function (event) {\n event.preventDefault();\n handleSendRequest();\n });\n\n retryButton.addEventListener('click', function () {\n if (sending) return;\n var payload = readFormPayload();\n var validationError = validatePayload(payload);\n if (validationError) {\n showError(validationError);\n return;\n }\n sendPayload(payload);\n });\n\n cancelButton.addEventListener('click', function () {\n if (sending) return;\n // After a lost-reply timeout we don't know if the email sent, so don't\n // claim \"Nothing sent.\" on collapse \u2014 point the user to verify instead.\n var collapseMessage = outcomeUnknown\n ? 'Collapsed. Check your Sent folder if you are not sure.'\n : 'Draft collapsed. Nothing sent.';\n clearError();\n clearSuccess();\n clearUnknown();\n setCollapsed(true, collapseMessage);\n });\n\n reopenButton.addEventListener('click', function () {\n setCollapsed(false);\n });\n\n sentCollapseButton.addEventListener('click', function () {\n setCollapsed(true, collapsedMessage.textContent || 'Email sent.');\n });\n\n // The iframe sandbox is \"allow-scripts\" only (no allow-popups / allow-forms),\n // so it cannot open a URL itself. Ask the host to open the Gmail link in the\n // user's browser via the ui/open-external-link bridge, which re-validates the\n // URL against its own allowlist before handing it to the OS.\n openGmailButton.addEventListener('click', function () {\n if (!gmailUrl) return;\n window.parent.postMessage(\n { jsonrpc: '2.0', method: 'ui/open-external-link', params: { url: gmailUrl } },\n '*'\n );\n });\n\n toggleCcButton.addEventListener('click', function () {\n setCcVisible(ccRow.classList.contains('hidden'));\n postResize();\n });\n\n toggleBccButton.addEventListener('click', function () {\n setBccVisible(bccRow.classList.contains('hidden'));\n postResize();\n });\n\n [toInput, ccInput, bccInput, subjectInput, bodyInput].forEach(function (element) {\n element.addEventListener('input', function () {\n clearError();\n clearSuccess();\n clearUnknown();\n postResize();\n });\n });\n\n window.addEventListener('message', function (event) {\n // Honest scope (origin-independent): the iframe sandbox origin is 'null',\n // so validating event.origin is unreliable across dev/prod/custom-scheme\n // hosts. Instead reject any *identified* sender that isn't our host frame\n // (window.parent). A real cross-frame postMessage always stamps\n // event.source with the sending window, so a hostile sibling frame is\n // rejected here; a null source only occurs for same-context synthetic\n // dispatch (our own code) and cannot be forged from outside, so we\n // tolerate it. This does not authenticate the host's identity \u2014 the host\n // separately authenticates this iframe by origin+source.\n if (event.source && event.source !== window.parent) {\n return;\n }\n\n var data = event.data;\n if (!data || typeof data !== 'object') {\n return;\n }\n\n if (data.method === 'ui/notifications/tool-result') {\n // Always parse (so the migration-shim's malformed-envelope warning\n // still fires), but apply only the first successful prefill: a stray\n // or hostile re-post can't silently rewrite a draft the user has\n // already reviewed.\n var draft = getDraftFromToolResult(data.params);\n if (draft && !draftApplied) {\n draftApplied = true;\n applyDraftData(draft);\n }\n return;\n }\n\n if (data.jsonrpc !== '2.0' || !pendingRequestId || data.id !== pendingRequestId) {\n return;\n }\n\n pendingRequestId = null;\n clearSendTimeout();\n clearUnknown();\n setSending(false);\n\n if (data.error) {\n var errorMessage = data.error && typeof data.error.message === 'string'\n ? data.error.message\n : 'Failed to send email.';\n // Prefer the host-vetted structured reason (a closed enum the host\n // derives from the tool-block error data) and fall back to\n // text-matching the flattened message for hosts that don't forward it\n // yet. Only 'user-disabled' opens the Gmail escape hatch \u2014\n // admin-disabled and security-policy blocks stay ordinary errors (see\n // the detector comment above for why).\n var blockedReason = data.error.data && data.error.data.reason;\n if (blockedReason === 'user-disabled' || isUserDisabledSendError(errorMessage)) {\n showBlockedSend();\n return;\n }\n showError(errorMessage);\n return;\n }\n\n clearError();\n clearSuccess();\n // Preserve what was sent (and how to reach it) instead of discarding the\n // draft. pendingPayload is the exact payload we posted; the reply carries\n // the Gmail message/thread ids. We default to the collapsed summary, but\n // Reopen now restores a read-only view of the sent message.\n var sentPayload = pendingPayload || readFormPayload();\n var stamp = formatSentTime();\n renderSentView(sentPayload, getSendMetaFromResult(data.result), stamp);\n sent = true;\n setCollapsed(true, stamp ? 'Email sent \u00B7 ' + stamp : 'Email sent.');\n });\n\n if (typeof ResizeObserver === 'function' && document.body) {\n var observer = new ResizeObserver(postResize);\n observer.observe(document.body);\n }\n\n applyThemeFromHostContext();\n setCcVisible(false);\n setBccVisible(false);\n setCollapsed(false);\n postResize();\n postReady();\n\n window.parent.postMessage(\n {\n jsonrpc: '2.0',\n method: 'ui/initialize',\n params: { resourceUri: RESOURCE_URI },\n id: 'compose-email-init'\n },\n '*'\n );\n })();\n </script>\n</body>\n</html>\n";
|
|
2
2
|
//# sourceMappingURL=compose-email-template.d.ts.map
|