@mcp-z/mcp-sheets 2.4.2 → 2.5.1

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.
Files changed (119) hide show
  1. package/README.md +45 -29
  2. package/dist/cjs/constants.d.cts +26 -0
  3. package/dist/cjs/constants.d.ts +26 -0
  4. package/dist/cjs/constants.js +83 -3
  5. package/dist/cjs/constants.js.map +1 -1
  6. package/dist/cjs/mcp/tools/cells-copy.d.cts +165 -0
  7. package/dist/cjs/mcp/tools/cells-copy.d.ts +165 -0
  8. package/dist/cjs/mcp/tools/cells-copy.js +388 -0
  9. package/dist/cjs/mcp/tools/cells-copy.js.map +1 -0
  10. package/dist/cjs/mcp/tools/cells-format.d.cts +3 -3
  11. package/dist/cjs/mcp/tools/cells-format.d.ts +3 -3
  12. package/dist/cjs/mcp/tools/cells-format.js +3 -2
  13. package/dist/cjs/mcp/tools/cells-format.js.map +1 -1
  14. package/dist/cjs/mcp/tools/columns-get.d.cts +2 -2
  15. package/dist/cjs/mcp/tools/columns-get.d.ts +2 -2
  16. package/dist/cjs/mcp/tools/columns-get.js +2 -1
  17. package/dist/cjs/mcp/tools/columns-get.js.map +1 -1
  18. package/dist/cjs/mcp/tools/columns-update.d.cts +1 -1
  19. package/dist/cjs/mcp/tools/columns-update.d.ts +1 -1
  20. package/dist/cjs/mcp/tools/columns-update.js +3 -2
  21. package/dist/cjs/mcp/tools/columns-update.js.map +1 -1
  22. package/dist/cjs/mcp/tools/index.d.cts +1 -0
  23. package/dist/cjs/mcp/tools/index.d.ts +1 -0
  24. package/dist/cjs/mcp/tools/index.js +4 -0
  25. package/dist/cjs/mcp/tools/index.js.map +1 -1
  26. package/dist/cjs/mcp/tools/rows-append.d.cts +1 -1
  27. package/dist/cjs/mcp/tools/rows-append.d.ts +1 -1
  28. package/dist/cjs/mcp/tools/rows-append.js +2 -1
  29. package/dist/cjs/mcp/tools/rows-append.js.map +1 -1
  30. package/dist/cjs/mcp/tools/rows-csv-append.d.cts +1 -1
  31. package/dist/cjs/mcp/tools/rows-csv-append.d.ts +1 -1
  32. package/dist/cjs/mcp/tools/rows-csv-append.js +2 -1
  33. package/dist/cjs/mcp/tools/rows-csv-append.js.map +1 -1
  34. package/dist/cjs/mcp/tools/rows-get.d.cts +2 -2
  35. package/dist/cjs/mcp/tools/rows-get.d.ts +2 -2
  36. package/dist/cjs/mcp/tools/rows-get.js +2 -1
  37. package/dist/cjs/mcp/tools/rows-get.js.map +1 -1
  38. package/dist/cjs/mcp/tools/values-batch-update.d.cts +1 -1
  39. package/dist/cjs/mcp/tools/values-batch-update.d.ts +1 -1
  40. package/dist/cjs/mcp/tools/values-batch-update.js +3 -2
  41. package/dist/cjs/mcp/tools/values-batch-update.js.map +1 -1
  42. package/dist/cjs/mcp/tools/values-csv-update.d.cts +1 -1
  43. package/dist/cjs/mcp/tools/values-csv-update.d.ts +1 -1
  44. package/dist/cjs/mcp/tools/values-csv-update.js +3 -2
  45. package/dist/cjs/mcp/tools/values-csv-update.js.map +1 -1
  46. package/dist/cjs/mcp/tools/values-search.d.cts +2 -2
  47. package/dist/cjs/mcp/tools/values-search.d.ts +2 -2
  48. package/dist/cjs/mcp/tools/values-search.js +2 -1
  49. package/dist/cjs/mcp/tools/values-search.js.map +1 -1
  50. package/dist/cjs/schemas/index.d.cts +1 -0
  51. package/dist/cjs/schemas/index.d.ts +1 -0
  52. package/dist/cjs/schemas/index.js +16 -0
  53. package/dist/cjs/schemas/index.js.map +1 -1
  54. package/dist/cjs/setup/config.js +26 -14
  55. package/dist/cjs/setup/config.js.map +1 -1
  56. package/dist/cjs/setup/version-help.js +1 -1
  57. package/dist/cjs/setup/version-help.js.map +1 -1
  58. package/dist/cjs/spreadsheet/data-operations.js +60 -181
  59. package/dist/cjs/spreadsheet/data-operations.js.map +1 -1
  60. package/dist/cjs/spreadsheet/range-operations.d.cts +27 -5
  61. package/dist/cjs/spreadsheet/range-operations.d.ts +27 -5
  62. package/dist/cjs/spreadsheet/range-operations.js +48 -28
  63. package/dist/cjs/spreadsheet/range-operations.js.map +1 -1
  64. package/dist/cjs/spreadsheet/sheet-operations.d.cts +6 -0
  65. package/dist/cjs/spreadsheet/sheet-operations.d.ts +6 -0
  66. package/dist/cjs/spreadsheet/sheet-operations.js +114 -124
  67. package/dist/cjs/spreadsheet/sheet-operations.js.map +1 -1
  68. package/dist/esm/constants.d.ts +26 -0
  69. package/dist/esm/constants.js +55 -0
  70. package/dist/esm/constants.js.map +1 -1
  71. package/dist/esm/mcp/tools/cells-copy.d.ts +165 -0
  72. package/dist/esm/mcp/tools/cells-copy.js +190 -0
  73. package/dist/esm/mcp/tools/cells-copy.js.map +1 -0
  74. package/dist/esm/mcp/tools/cells-format.d.ts +3 -3
  75. package/dist/esm/mcp/tools/cells-format.js +3 -2
  76. package/dist/esm/mcp/tools/cells-format.js.map +1 -1
  77. package/dist/esm/mcp/tools/columns-get.d.ts +2 -2
  78. package/dist/esm/mcp/tools/columns-get.js +2 -1
  79. package/dist/esm/mcp/tools/columns-get.js.map +1 -1
  80. package/dist/esm/mcp/tools/columns-update.d.ts +1 -1
  81. package/dist/esm/mcp/tools/columns-update.js +3 -2
  82. package/dist/esm/mcp/tools/columns-update.js.map +1 -1
  83. package/dist/esm/mcp/tools/index.d.ts +1 -0
  84. package/dist/esm/mcp/tools/index.js +1 -0
  85. package/dist/esm/mcp/tools/index.js.map +1 -1
  86. package/dist/esm/mcp/tools/rows-append.d.ts +1 -1
  87. package/dist/esm/mcp/tools/rows-append.js +2 -1
  88. package/dist/esm/mcp/tools/rows-append.js.map +1 -1
  89. package/dist/esm/mcp/tools/rows-csv-append.d.ts +1 -1
  90. package/dist/esm/mcp/tools/rows-csv-append.js +2 -1
  91. package/dist/esm/mcp/tools/rows-csv-append.js.map +1 -1
  92. package/dist/esm/mcp/tools/rows-get.d.ts +2 -2
  93. package/dist/esm/mcp/tools/rows-get.js +2 -1
  94. package/dist/esm/mcp/tools/rows-get.js.map +1 -1
  95. package/dist/esm/mcp/tools/values-batch-update.d.ts +1 -1
  96. package/dist/esm/mcp/tools/values-batch-update.js +3 -2
  97. package/dist/esm/mcp/tools/values-batch-update.js.map +1 -1
  98. package/dist/esm/mcp/tools/values-csv-update.d.ts +1 -1
  99. package/dist/esm/mcp/tools/values-csv-update.js +3 -2
  100. package/dist/esm/mcp/tools/values-csv-update.js.map +1 -1
  101. package/dist/esm/mcp/tools/values-search.d.ts +2 -2
  102. package/dist/esm/mcp/tools/values-search.js +2 -1
  103. package/dist/esm/mcp/tools/values-search.js.map +1 -1
  104. package/dist/esm/schemas/index.d.ts +1 -0
  105. package/dist/esm/schemas/index.js +9 -0
  106. package/dist/esm/schemas/index.js.map +1 -1
  107. package/dist/esm/setup/config.js +26 -14
  108. package/dist/esm/setup/config.js.map +1 -1
  109. package/dist/esm/setup/version-help.js +7 -0
  110. package/dist/esm/setup/version-help.js.map +1 -1
  111. package/dist/esm/spreadsheet/data-operations.js +47 -95
  112. package/dist/esm/spreadsheet/data-operations.js.map +1 -1
  113. package/dist/esm/spreadsheet/range-operations.d.ts +27 -5
  114. package/dist/esm/spreadsheet/range-operations.js +50 -27
  115. package/dist/esm/spreadsheet/range-operations.js.map +1 -1
  116. package/dist/esm/spreadsheet/sheet-operations.d.ts +6 -0
  117. package/dist/esm/spreadsheet/sheet-operations.js +88 -79
  118. package/dist/esm/spreadsheet/sheet-operations.js.map +1 -1
  119. package/package.json +3 -3
@@ -0,0 +1,388 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get copyCells () {
13
+ return copyCells;
14
+ },
15
+ get default () {
16
+ return createTool;
17
+ }
18
+ });
19
+ var _sheets = require("@googleapis/sheets");
20
+ var _oauthgoogle = require("@mcp-z/oauth-google");
21
+ var _server = require("@mcp-z/server");
22
+ var _zod = require("zod");
23
+ var _constantsts = require("../../constants.js");
24
+ var _googleauthts = require("../../lib/google-auth.js");
25
+ var _indexts = require("../../schemas/index.js");
26
+ var _rangeoperationsts = require("../../spreadsheet/range-operations.js");
27
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
28
+ try {
29
+ var info = gen[key](arg);
30
+ var value = info.value;
31
+ } catch (error) {
32
+ reject(error);
33
+ return;
34
+ }
35
+ if (info.done) resolve(value);
36
+ else Promise.resolve(value).then(_next, _throw);
37
+ }
38
+ function _async_to_generator(fn) {
39
+ return function() {
40
+ var self = this, args = arguments;
41
+ return new Promise(function(resolve, reject) {
42
+ var gen = fn.apply(self, args);
43
+ function _next(value) {
44
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
45
+ }
46
+ function _throw(err) {
47
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
48
+ }
49
+ _next(undefined);
50
+ });
51
+ };
52
+ }
53
+ function _instanceof(left, right) {
54
+ "@swc/helpers - instanceof";
55
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
56
+ return !!right[Symbol.hasInstance](left);
57
+ } else return left instanceof right;
58
+ }
59
+ function _ts_generator(thisArg, body) {
60
+ var f, y, t, _ = {
61
+ label: 0,
62
+ sent: function() {
63
+ if (t[0] & 1) throw t[1];
64
+ return t[1];
65
+ },
66
+ trys: [],
67
+ ops: []
68
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
69
+ return d(g, "next", {
70
+ value: verb(0)
71
+ }), d(g, "throw", {
72
+ value: verb(1)
73
+ }), d(g, "return", {
74
+ value: verb(2)
75
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
76
+ value: function() {
77
+ return this;
78
+ }
79
+ }), g;
80
+ function verb(n) {
81
+ return function(v) {
82
+ return step([
83
+ n,
84
+ v
85
+ ]);
86
+ };
87
+ }
88
+ function step(op) {
89
+ if (f) throw new TypeError("Generator is already executing.");
90
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
91
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
92
+ if (y = 0, t) op = [
93
+ op[0] & 2,
94
+ t.value
95
+ ];
96
+ switch(op[0]){
97
+ case 0:
98
+ case 1:
99
+ t = op;
100
+ break;
101
+ case 4:
102
+ _.label++;
103
+ return {
104
+ value: op[1],
105
+ done: false
106
+ };
107
+ case 5:
108
+ _.label++;
109
+ y = op[1];
110
+ op = [
111
+ 0
112
+ ];
113
+ continue;
114
+ case 7:
115
+ op = _.ops.pop();
116
+ _.trys.pop();
117
+ continue;
118
+ default:
119
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
120
+ _ = 0;
121
+ continue;
122
+ }
123
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
124
+ _.label = op[1];
125
+ break;
126
+ }
127
+ if (op[0] === 6 && _.label < t[1]) {
128
+ _.label = t[1];
129
+ t = op;
130
+ break;
131
+ }
132
+ if (t && _.label < t[2]) {
133
+ _.label = t[2];
134
+ _.ops.push(op);
135
+ break;
136
+ }
137
+ if (t[2]) _.ops.pop();
138
+ _.trys.pop();
139
+ continue;
140
+ }
141
+ op = body.call(thisArg, _);
142
+ } catch (e) {
143
+ op = [
144
+ 6,
145
+ e
146
+ ];
147
+ y = 0;
148
+ } finally{
149
+ f = t = 0;
150
+ }
151
+ if (op[0] & 5) throw op[1];
152
+ return {
153
+ value: op[0] ? op[1] : void 0,
154
+ done: true
155
+ };
156
+ }
157
+ }
158
+ var AuthRequiredBranchSchema = _oauthgoogle.schemas.AuthRequiredBranchSchema;
159
+ var inputSchema = _zod.z.object({
160
+ id: _indexts.SpreadsheetIdSchema,
161
+ sourceGid: _indexts.StrictSheetGidSchema.describe('Source sheet ID (from URL gid={gid})'),
162
+ sourceRange: _indexts.A1NotationSchema.describe('Finite sheet-local A1 range to copy (e.g., "A1:C10"; no sheet prefix, no whole rows/columns)'),
163
+ destinationGid: _indexts.StrictSheetGidSchema.describe('Destination sheet ID in the same spreadsheet; may equal sourceGid'),
164
+ destinationRange: _indexts.A1NotationSchema.describe('Top-left cell (e.g., "E1") or a finite range whose height and width are whole multiples of the (oriented) source; a larger range repeats the source to fill it'),
165
+ pasteType: _zod.z.enum(_constantsts.PASTE_TYPES).default('PASTE_NORMAL').describe('What to paste. PASTE_NORMAL (default) = values, formulas, formats and merges; PASTE_VALUES = values only, no formats/formulas/merges; PASTE_FORMAT = format only, excluding data validation; PASTE_NO_BORDERS = like PASTE_NORMAL without borders; PASTE_FORMULA = formulas only; PASTE_DATA_VALIDATION = data validation only; PASTE_CONDITIONAL_FORMATTING = conditional formatting rules only'),
166
+ pasteOrientation: _zod.z.enum(_constantsts.PASTE_ORIENTATIONS).default('NORMAL').describe('NORMAL, or TRANSPOSE (rows become columns and vice versa)')
167
+ });
168
+ var successBranchSchema = _zod.z.object({
169
+ type: _zod.z.literal('success'),
170
+ id: _indexts.SpreadsheetIdOutput,
171
+ spreadsheetTitle: _zod.z.string().describe('Title of the spreadsheet'),
172
+ spreadsheetUrl: _zod.z.string().describe('URL of the spreadsheet'),
173
+ sourceGid: _indexts.SheetGidOutput,
174
+ sourceSheetTitle: _zod.z.string().describe('Title of the source sheet'),
175
+ sourceRange: _zod.z.string().describe('A1 range that was copied'),
176
+ destinationGid: _indexts.SheetGidOutput,
177
+ destinationSheetTitle: _zod.z.string().describe('Title of the destination sheet'),
178
+ destinationRange: _zod.z.string().describe('Destination range as requested'),
179
+ pastedRange: _zod.z.string().describe('A1 range of cells written in the destination sheet'),
180
+ pasteType: _zod.z.enum(_constantsts.PASTE_TYPES).describe('Paste type applied'),
181
+ pasteOrientation: _zod.z.enum(_constantsts.PASTE_ORIENTATIONS).describe('Orientation applied'),
182
+ sheetUrl: _zod.z.string().describe('URL of the destination sheet')
183
+ });
184
+ var outputSchema = _zod.z.discriminatedUnion('type', [
185
+ successBranchSchema,
186
+ AuthRequiredBranchSchema
187
+ ]);
188
+ var config = {
189
+ description: 'Copy a cell range to another range in the same spreadsheet (same or different tab), like Google Sheets copy and paste-special. Default PASTE_NORMAL copies values, formulas (relative references adjust), formats and merges; pasteType selects one native paste-special mode. Cannot copy between spreadsheets: use sheet-copy-to first. To duplicate a whole tab or workbook use sheet-copy, sheet-copy-to or spreadsheet-copy. Use a1-notation prompt for range syntax.',
190
+ inputSchema: inputSchema,
191
+ outputSchema: _zod.z.object({
192
+ result: outputSchema
193
+ })
194
+ };
195
+ function invalid(message) {
196
+ return new _server.ProtocolError(_server.ProtocolErrorCode.InvalidParams, message);
197
+ }
198
+ /** Validates a finite sheet-local A1 range, converting any failure to InvalidParams. */ function checkRange(label, notation) {
199
+ try {
200
+ (0, _rangeoperationsts.validateA1Notation)(notation);
201
+ return (0, _rangeoperationsts.parseFiniteCellBlock)(notation);
202
+ } catch (error) {
203
+ throw invalid("Invalid ".concat(label, ": ").concat(_instanceof(error, Error) ? error.message : String(error)));
204
+ }
205
+ }
206
+ function copyCells(_0, _1) {
207
+ return _async_to_generator(function(sheets, param) {
208
+ var id, sourceGid, sourceRange, destinationGid, destinationRange, pasteType, pasteOrientation, _destinationSheet_sheetId, _ref, _spreadsheetData_spreadsheetUrl, _sourceSheet_title, _destinationSheet_title, _spreadsheetData_properties, source, pasted, spreadsheetResponse, spreadsheetData, findSheet, sourceSheet, destinationSheet, gridSize, sourceGrid, destinationGrid, fits, destinationSheetId;
209
+ return _ts_generator(this, function(_state) {
210
+ switch(_state.label){
211
+ case 0:
212
+ id = param.id, sourceGid = param.sourceGid, sourceRange = param.sourceRange, destinationGid = param.destinationGid, destinationRange = param.destinationRange, pasteType = param.pasteType, pasteOrientation = param.pasteOrientation;
213
+ // All range checks happen before any network call
214
+ source = checkRange('sourceRange', sourceRange);
215
+ checkRange('destinationRange', destinationRange);
216
+ try {
217
+ pasted = (0, _rangeoperationsts.calculatePasteRange)(sourceRange, destinationRange, pasteOrientation);
218
+ } catch (error) {
219
+ throw invalid(_instanceof(error, Error) ? error.message : String(error));
220
+ }
221
+ return [
222
+ 4,
223
+ sheets.spreadsheets.get({
224
+ spreadsheetId: id,
225
+ fields: 'properties.title,spreadsheetUrl,sheets.properties.sheetId,sheets.properties.title,sheets.properties.gridProperties'
226
+ })
227
+ ];
228
+ case 1:
229
+ spreadsheetResponse = _state.sent();
230
+ spreadsheetData = spreadsheetResponse.data;
231
+ findSheet = function findSheet(gid) {
232
+ var _spreadsheetData_sheets_find, _spreadsheetData_sheets;
233
+ return (_spreadsheetData_sheets = spreadsheetData.sheets) === null || _spreadsheetData_sheets === void 0 ? void 0 : (_spreadsheetData_sheets_find = _spreadsheetData_sheets.find(function(s) {
234
+ var _s_properties;
235
+ return String((_s_properties = s.properties) === null || _s_properties === void 0 ? void 0 : _s_properties.sheetId) === gid;
236
+ })) === null || _spreadsheetData_sheets_find === void 0 ? void 0 : _spreadsheetData_sheets_find.properties;
237
+ };
238
+ sourceSheet = findSheet(sourceGid);
239
+ if (!sourceSheet) throw invalid("Sheet not found: ".concat(sourceGid));
240
+ destinationSheet = findSheet(destinationGid);
241
+ if (!destinationSheet) throw invalid("Sheet not found: ".concat(destinationGid));
242
+ gridSize = function gridSize(sheet) {
243
+ var _sheet_title;
244
+ var _sheet_gridProperties, _sheet_gridProperties1;
245
+ var rows = (_sheet_gridProperties = sheet.gridProperties) === null || _sheet_gridProperties === void 0 ? void 0 : _sheet_gridProperties.rowCount;
246
+ var columns = (_sheet_gridProperties1 = sheet.gridProperties) === null || _sheet_gridProperties1 === void 0 ? void 0 : _sheet_gridProperties1.columnCount;
247
+ if (typeof rows !== 'number' || typeof columns !== 'number') throw new Error('Could not read the grid size of sheet "'.concat((_sheet_title = sheet.title) !== null && _sheet_title !== void 0 ? _sheet_title : sheet.sheetId, '"'));
248
+ return {
249
+ rows: rows,
250
+ columns: columns
251
+ };
252
+ };
253
+ sourceGrid = gridSize(sourceSheet);
254
+ destinationGrid = gridSize(destinationSheet);
255
+ fits = function fits(grid, endRow, endColumn) {
256
+ return endRow <= grid.rows && endColumn <= grid.columns;
257
+ };
258
+ if (!fits(sourceGrid, source.endRow, source.endColumn)) {
259
+ throw invalid("Source range ".concat(sourceRange, ' is outside the grid of "').concat(sourceSheet.title, '" (').concat(sourceGrid.rows, " rows x ").concat(sourceGrid.columns, " columns)"));
260
+ }
261
+ if (!fits(destinationGrid, pasted.endRow, pasted.endColumn)) {
262
+ throw invalid("Pasting ".concat(sourceRange, " at ").concat(destinationRange, " would write ").concat((0, _rangeoperationsts.cellBlockToA1)(pasted), ', outside the grid of "').concat(destinationSheet.title, '" (').concat(destinationGrid.rows, " rows x ").concat(destinationGrid.columns, " columns)"));
263
+ }
264
+ // pasteType is always sent explicitly; there is no fallback path
265
+ return [
266
+ 4,
267
+ sheets.spreadsheets.batchUpdate({
268
+ spreadsheetId: id,
269
+ requestBody: {
270
+ requests: [
271
+ {
272
+ copyPaste: {
273
+ source: (0, _rangeoperationsts.rangeReferenceToGridRange)((0, _rangeoperationsts.parseA1Notation)(sourceRange), Number(sourceGid)),
274
+ destination: (0, _rangeoperationsts.rangeReferenceToGridRange)((0, _rangeoperationsts.parseA1Notation)(destinationRange), Number(destinationGid)),
275
+ pasteType: pasteType,
276
+ pasteOrientation: pasteOrientation
277
+ }
278
+ }
279
+ ]
280
+ }
281
+ })
282
+ ];
283
+ case 2:
284
+ _state.sent();
285
+ destinationSheetId = (_destinationSheet_sheetId = destinationSheet.sheetId) !== null && _destinationSheet_sheetId !== void 0 ? _destinationSheet_sheetId : Number(destinationGid);
286
+ return [
287
+ 2,
288
+ {
289
+ type: 'success',
290
+ id: id,
291
+ spreadsheetTitle: (_ref = (_spreadsheetData_properties = spreadsheetData.properties) === null || _spreadsheetData_properties === void 0 ? void 0 : _spreadsheetData_properties.title) !== null && _ref !== void 0 ? _ref : '',
292
+ spreadsheetUrl: (_spreadsheetData_spreadsheetUrl = spreadsheetData.spreadsheetUrl) !== null && _spreadsheetData_spreadsheetUrl !== void 0 ? _spreadsheetData_spreadsheetUrl : '',
293
+ sourceGid: sourceGid,
294
+ sourceSheetTitle: (_sourceSheet_title = sourceSheet.title) !== null && _sourceSheet_title !== void 0 ? _sourceSheet_title : sourceGid,
295
+ sourceRange: sourceRange,
296
+ destinationGid: destinationGid,
297
+ destinationSheetTitle: (_destinationSheet_title = destinationSheet.title) !== null && _destinationSheet_title !== void 0 ? _destinationSheet_title : destinationGid,
298
+ destinationRange: destinationRange,
299
+ pastedRange: (0, _rangeoperationsts.cellBlockToA1)(pasted),
300
+ pasteType: pasteType,
301
+ pasteOrientation: pasteOrientation,
302
+ sheetUrl: "https://docs.google.com/spreadsheets/d/".concat(id, "/edit#gid=").concat(destinationSheetId)
303
+ }
304
+ ];
305
+ }
306
+ });
307
+ }).apply(this, arguments);
308
+ }
309
+ function handler(input, extra) {
310
+ return _async_to_generator(function() {
311
+ var logger, id, sourceGid, destinationGid, pasteType, pasteOrientation, sheets, result, error, message;
312
+ return _ts_generator(this, function(_state) {
313
+ switch(_state.label){
314
+ case 0:
315
+ logger = extra.logger;
316
+ id = input.id, sourceGid = input.sourceGid, destinationGid = input.destinationGid, pasteType = input.pasteType, pasteOrientation = input.pasteOrientation;
317
+ logger.info('sheets.cells.copy called', {
318
+ id: id,
319
+ sourceGid: sourceGid,
320
+ destinationGid: destinationGid,
321
+ pasteType: pasteType,
322
+ pasteOrientation: pasteOrientation
323
+ });
324
+ _state.label = 1;
325
+ case 1:
326
+ _state.trys.push([
327
+ 1,
328
+ 3,
329
+ ,
330
+ 4
331
+ ]);
332
+ sheets = (0, _sheets.sheets)({
333
+ version: 'v4',
334
+ auth: (0, _googleauthts.googleAuth)(extra.authContext.auth)
335
+ });
336
+ return [
337
+ 4,
338
+ copyCells(sheets, input)
339
+ ];
340
+ case 2:
341
+ result = _state.sent();
342
+ logger.info('sheets.cells.copy completed successfully', {
343
+ id: id,
344
+ pastedRange: result.type === 'success' ? result.pastedRange : undefined
345
+ });
346
+ return [
347
+ 2,
348
+ {
349
+ content: [
350
+ {
351
+ type: 'text',
352
+ text: JSON.stringify(result)
353
+ }
354
+ ],
355
+ structuredContent: {
356
+ result: result
357
+ }
358
+ }
359
+ ];
360
+ case 3:
361
+ error = _state.sent();
362
+ if (_instanceof(error, _server.ProtocolError)) throw error;
363
+ message = _instanceof(error, Error) ? error.message : String(error);
364
+ logger.error('Copy cells failed', {
365
+ id: id,
366
+ sourceGid: sourceGid,
367
+ destinationGid: destinationGid,
368
+ error: message
369
+ });
370
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error copying cells: ".concat(message), {
371
+ stack: _instanceof(error, Error) ? error.stack : undefined
372
+ });
373
+ case 4:
374
+ return [
375
+ 2
376
+ ];
377
+ }
378
+ });
379
+ })();
380
+ }
381
+ function createTool() {
382
+ return {
383
+ name: 'cells-copy',
384
+ config: config,
385
+ handler: handler
386
+ };
387
+ }
388
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/cells-copy.ts"],"sourcesContent":["import type { sheets_v4 } from '@googleapis/sheets';\nimport { sheets as sheetsApi } from '@googleapis/sheets';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { z } from 'zod';\nimport { PASTE_ORIENTATIONS, PASTE_TYPES } from '../../constants.ts';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { A1NotationSchema, SheetGidOutput, SpreadsheetIdOutput, SpreadsheetIdSchema, StrictSheetGidSchema } from '../../schemas/index.ts';\nimport { calculatePasteRange, cellBlockToA1, parseA1Notation, parseFiniteCellBlock, rangeReferenceToGridRange, validateA1Notation } from '../../spreadsheet/range-operations.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n sourceGid: StrictSheetGidSchema.describe('Source sheet ID (from URL gid={gid})'),\n sourceRange: A1NotationSchema.describe('Finite sheet-local A1 range to copy (e.g., \"A1:C10\"; no sheet prefix, no whole rows/columns)'),\n destinationGid: StrictSheetGidSchema.describe('Destination sheet ID in the same spreadsheet; may equal sourceGid'),\n destinationRange: A1NotationSchema.describe('Top-left cell (e.g., \"E1\") or a finite range whose height and width are whole multiples of the (oriented) source; a larger range repeats the source to fill it'),\n pasteType: z\n .enum(PASTE_TYPES)\n .default('PASTE_NORMAL')\n .describe(\n 'What to paste. PASTE_NORMAL (default) = values, formulas, formats and merges; PASTE_VALUES = values only, no formats/formulas/merges; PASTE_FORMAT = format only, excluding data validation; PASTE_NO_BORDERS = like PASTE_NORMAL without borders; PASTE_FORMULA = formulas only; PASTE_DATA_VALIDATION = data validation only; PASTE_CONDITIONAL_FORMATTING = conditional formatting rules only'\n ),\n pasteOrientation: z.enum(PASTE_ORIENTATIONS).default('NORMAL').describe('NORMAL, or TRANSPOSE (rows become columns and vice versa)'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n spreadsheetTitle: z.string().describe('Title of the spreadsheet'),\n spreadsheetUrl: z.string().describe('URL of the spreadsheet'),\n sourceGid: SheetGidOutput,\n sourceSheetTitle: z.string().describe('Title of the source sheet'),\n sourceRange: z.string().describe('A1 range that was copied'),\n destinationGid: SheetGidOutput,\n destinationSheetTitle: z.string().describe('Title of the destination sheet'),\n destinationRange: z.string().describe('Destination range as requested'),\n pastedRange: z.string().describe('A1 range of cells written in the destination sheet'),\n pasteType: z.enum(PASTE_TYPES).describe('Paste type applied'),\n pasteOrientation: z.enum(PASTE_ORIENTATIONS).describe('Orientation applied'),\n sheetUrl: z.string().describe('URL of the destination sheet'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description:\n 'Copy a cell range to another range in the same spreadsheet (same or different tab), like Google Sheets copy and paste-special. Default PASTE_NORMAL copies values, formulas (relative references adjust), formats and merges; pasteType selects one native paste-special mode. Cannot copy between spreadsheets: use sheet-copy-to first. To duplicate a whole tab or workbook use sheet-copy, sheet-copy-to or spreadsheet-copy. Use a1-notation prompt for range syntax.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\ntype SuccessOutput = z.infer<typeof successBranchSchema>;\n\n/** The slice of the Sheets client this tool uses; tests pass a plain fake. */\nexport interface CellsCopySheets {\n spreadsheets: {\n get(params: { spreadsheetId: string; fields: string }): Promise<{ data: sheets_v4.Schema$Spreadsheet }>;\n batchUpdate(params: { spreadsheetId: string; requestBody: sheets_v4.Schema$BatchUpdateSpreadsheetRequest }): Promise<unknown>;\n };\n}\n\nfunction invalid(message: string): ProtocolError {\n return new ProtocolError(ProtocolErrorCode.InvalidParams, message);\n}\n\n/** Validates a finite sheet-local A1 range, converting any failure to InvalidParams. */\nfunction checkRange(label: string, notation: string) {\n try {\n validateA1Notation(notation);\n return parseFiniteCellBlock(notation);\n } catch (error) {\n throw invalid(`Invalid ${label}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\nexport async function copyCells(sheets: CellsCopySheets, { id, sourceGid, sourceRange, destinationGid, destinationRange, pasteType, pasteOrientation }: Input): Promise<SuccessOutput> {\n // All range checks happen before any network call\n const source = checkRange('sourceRange', sourceRange);\n checkRange('destinationRange', destinationRange);\n let pasted: ReturnType<typeof calculatePasteRange>;\n try {\n pasted = calculatePasteRange(sourceRange, destinationRange, pasteOrientation);\n } catch (error) {\n throw invalid(error instanceof Error ? error.message : String(error));\n }\n\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'properties.title,spreadsheetUrl,sheets.properties.sheetId,sheets.properties.title,sheets.properties.gridProperties',\n });\n const spreadsheetData = spreadsheetResponse.data;\n const findSheet = (gid: string) => spreadsheetData.sheets?.find((s) => String(s.properties?.sheetId) === gid)?.properties;\n const sourceSheet = findSheet(sourceGid);\n if (!sourceSheet) throw invalid(`Sheet not found: ${sourceGid}`);\n const destinationSheet = findSheet(destinationGid);\n if (!destinationSheet) throw invalid(`Sheet not found: ${destinationGid}`);\n\n const gridSize = (sheet: sheets_v4.Schema$SheetProperties) => {\n const rows = sheet.gridProperties?.rowCount;\n const columns = sheet.gridProperties?.columnCount;\n if (typeof rows !== 'number' || typeof columns !== 'number') throw new Error(`Could not read the grid size of sheet \"${sheet.title ?? sheet.sheetId}\"`);\n return { rows, columns };\n };\n const sourceGrid = gridSize(sourceSheet);\n const destinationGrid = gridSize(destinationSheet);\n const fits = (grid: { rows: number; columns: number }, endRow: number, endColumn: number) => endRow <= grid.rows && endColumn <= grid.columns;\n if (!fits(sourceGrid, source.endRow, source.endColumn)) {\n throw invalid(`Source range ${sourceRange} is outside the grid of \"${sourceSheet.title}\" (${sourceGrid.rows} rows x ${sourceGrid.columns} columns)`);\n }\n if (!fits(destinationGrid, pasted.endRow, pasted.endColumn)) {\n throw invalid(`Pasting ${sourceRange} at ${destinationRange} would write ${cellBlockToA1(pasted)}, outside the grid of \"${destinationSheet.title}\" (${destinationGrid.rows} rows x ${destinationGrid.columns} columns)`);\n }\n\n // pasteType is always sent explicitly; there is no fallback path\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [\n {\n copyPaste: {\n source: rangeReferenceToGridRange(parseA1Notation(sourceRange), Number(sourceGid)),\n destination: rangeReferenceToGridRange(parseA1Notation(destinationRange), Number(destinationGid)),\n pasteType,\n pasteOrientation,\n },\n },\n ],\n },\n });\n\n const destinationSheetId = destinationSheet.sheetId ?? Number(destinationGid);\n return {\n type: 'success' as const,\n id,\n spreadsheetTitle: spreadsheetData.properties?.title ?? '',\n spreadsheetUrl: spreadsheetData.spreadsheetUrl ?? '',\n sourceGid,\n sourceSheetTitle: sourceSheet.title ?? sourceGid,\n sourceRange,\n destinationGid,\n destinationSheetTitle: destinationSheet.title ?? destinationGid,\n destinationRange,\n pastedRange: cellBlockToA1(pasted),\n pasteType,\n pasteOrientation,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${destinationSheetId}`,\n };\n}\n\nasync function handler(input: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n const { id, sourceGid, destinationGid, pasteType, pasteOrientation } = input;\n logger.info('sheets.cells.copy called', { id, sourceGid, destinationGid, pasteType, pasteOrientation });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n const result: Output = await copyCells(sheets as unknown as CellsCopySheets, input);\n logger.info('sheets.cells.copy completed successfully', { id, pastedRange: result.type === 'success' ? result.pastedRange : undefined });\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n if (error instanceof ProtocolError) throw error;\n const message = error instanceof Error ? error.message : String(error);\n logger.error('Copy cells failed', { id, sourceGid, destinationGid, error: message });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error copying cells: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'cells-copy',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["copyCells","createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","sourceGid","StrictSheetGidSchema","describe","sourceRange","A1NotationSchema","destinationGid","destinationRange","pasteType","enum","PASTE_TYPES","default","pasteOrientation","PASTE_ORIENTATIONS","successBranchSchema","type","literal","SpreadsheetIdOutput","spreadsheetTitle","string","spreadsheetUrl","SheetGidOutput","sourceSheetTitle","destinationSheetTitle","pastedRange","sheetUrl","outputSchema","discriminatedUnion","config","description","result","invalid","message","ProtocolError","ProtocolErrorCode","InvalidParams","checkRange","label","notation","validateA1Notation","parseFiniteCellBlock","error","Error","String","sheets","destinationSheet","spreadsheetData","sourceSheet","source","pasted","spreadsheetResponse","findSheet","gridSize","sourceGrid","destinationGrid","fits","destinationSheetId","calculatePasteRange","spreadsheets","get","spreadsheetId","fields","data","gid","find","s","properties","sheetId","sheet","rows","gridProperties","rowCount","columns","columnCount","title","grid","endRow","endColumn","cellBlockToA1","batchUpdate","requestBody","requests","copyPaste","rangeReferenceToGridRange","parseA1Notation","Number","destination","handler","input","extra","logger","info","sheetsApi","version","auth","googleAuth","authContext","undefined","content","text","JSON","stringify","structuredContent","InternalError","stack","name"],"mappings":";;;;;;;;;;;QAoFsBA;eAAAA;;QAiGtB;eAAwBC;;;sBApLY;2BAEZ;sBAKyB;mBAC/B;2BAC8B;4BACrB;uBACsF;iCACwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AARzI,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAUR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,WAAWC,6BAAoB,CAACC,QAAQ,CAAC;IACzCC,aAAaC,yBAAgB,CAACF,QAAQ,CAAC;IACvCG,gBAAgBJ,6BAAoB,CAACC,QAAQ,CAAC;IAC9CI,kBAAkBF,yBAAgB,CAACF,QAAQ,CAAC;IAC5CK,WAAWX,MAAC,CACTY,IAAI,CAACC,wBAAW,EAChBC,OAAO,CAAC,gBACRR,QAAQ,CACP;IAEJS,kBAAkBf,MAAC,CAACY,IAAI,CAACI,+BAAkB,EAAEF,OAAO,CA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MAAM;QACN7E,QAAAA;QACA2D,SAAAA;IACF;AACF"}
@@ -25,11 +25,11 @@ declare const inputSchema: z.ZodObject<{
25
25
  }>>;
26
26
  numberFormat: z.ZodOptional<z.ZodObject<{
27
27
  type: z.ZodEnum<{
28
+ DATE: "DATE";
28
29
  TEXT: "TEXT";
29
30
  NUMBER: "NUMBER";
30
31
  PERCENT: "PERCENT";
31
32
  CURRENCY: "CURRENCY";
32
- DATE: "DATE";
33
33
  TIME: "TIME";
34
34
  }>;
35
35
  pattern: z.ZodOptional<z.ZodString>;
@@ -71,7 +71,7 @@ declare function handler({ id, gid, requests }: Input, extra: EnrichedExtra): Pr
71
71
  export default function createTool(): {
72
72
  name: string;
73
73
  config: {
74
- readonly description: "Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets.";
74
+ readonly description: "Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets. Date/time cells: numberFormat {type:\"DATE\", pattern:\"yyyy-mm-dd hh:mm\"} only displays a numeric serial as a date; it does not convert text. Dates: a date-looking string is not necessarily a native date. See values-batch-update for the native-date write, format and read-back steps.";
75
75
  readonly inputSchema: z.ZodObject<{
76
76
  id: z.ZodString;
77
77
  gid: z.ZodCoercedString<unknown>;
@@ -96,11 +96,11 @@ export default function createTool(): {
96
96
  }>>;
97
97
  numberFormat: z.ZodOptional<z.ZodObject<{
98
98
  type: z.ZodEnum<{
99
+ DATE: "DATE";
99
100
  TEXT: "TEXT";
100
101
  NUMBER: "NUMBER";
101
102
  PERCENT: "PERCENT";
102
103
  CURRENCY: "CURRENCY";
103
- DATE: "DATE";
104
104
  TIME: "TIME";
105
105
  }>;
106
106
  pattern: z.ZodOptional<z.ZodString>;
@@ -25,11 +25,11 @@ declare const inputSchema: z.ZodObject<{
25
25
  }>>;
26
26
  numberFormat: z.ZodOptional<z.ZodObject<{
27
27
  type: z.ZodEnum<{
28
+ DATE: "DATE";
28
29
  TEXT: "TEXT";
29
30
  NUMBER: "NUMBER";
30
31
  PERCENT: "PERCENT";
31
32
  CURRENCY: "CURRENCY";
32
- DATE: "DATE";
33
33
  TIME: "TIME";
34
34
  }>;
35
35
  pattern: z.ZodOptional<z.ZodString>;
@@ -71,7 +71,7 @@ declare function handler({ id, gid, requests }: Input, extra: EnrichedExtra): Pr
71
71
  export default function createTool(): {
72
72
  name: string;
73
73
  config: {
74
- readonly description: "Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets.";
74
+ readonly description: "Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets. Date/time cells: numberFormat {type:\"DATE\", pattern:\"yyyy-mm-dd hh:mm\"} only displays a numeric serial as a date; it does not convert text. Dates: a date-looking string is not necessarily a native date. See values-batch-update for the native-date write, format and read-back steps.";
75
75
  readonly inputSchema: z.ZodObject<{
76
76
  id: z.ZodString;
77
77
  gid: z.ZodCoercedString<unknown>;
@@ -96,11 +96,11 @@ export default function createTool(): {
96
96
  }>>;
97
97
  numberFormat: z.ZodOptional<z.ZodObject<{
98
98
  type: z.ZodEnum<{
99
+ DATE: "DATE";
99
100
  TEXT: "TEXT";
100
101
  NUMBER: "NUMBER";
101
102
  PERCENT: "PERCENT";
102
103
  CURRENCY: "CURRENCY";
103
- DATE: "DATE";
104
104
  TIME: "TIME";
105
105
  }>;
106
106
  pattern: z.ZodOptional<z.ZodString>;
@@ -12,6 +12,7 @@ var _sheets = require("@googleapis/sheets");
12
12
  var _oauthgoogle = require("@mcp-z/oauth-google");
13
13
  var _server = require("@mcp-z/server");
14
14
  var _zod = require("zod");
15
+ var _constantsts = require("../../constants.js");
15
16
  var _googleauthts = require("../../lib/google-auth.js");
16
17
  var _indexts = require("../../schemas/index.js");
17
18
  var _rangeoperationsts = require("../../spreadsheet/range-operations.js");
@@ -163,7 +164,7 @@ var NumberFormatSchema = _zod.z.object({
163
164
  'DATE',
164
165
  'TIME'
165
166
  ]).describe('Number format type'),
166
- pattern: _zod.z.string().optional().describe('Custom format pattern (e.g., "$#,##0.00" for currency)')
167
+ pattern: _zod.z.string().optional().describe('Custom format pattern (e.g., "$#,##0.00" for currency, "yyyy-mm-dd hh:mm" for a date/time serial)')
167
168
  });
168
169
  // Border schema
169
170
  var BorderSchema = _zod.z.object({
@@ -211,7 +212,7 @@ var outputSchema = _zod.z.discriminatedUnion('type', [
211
212
  AuthRequiredBranchSchema
212
213
  ]);
213
214
  var config = {
214
- description: 'Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets.',
215
+ description: 'Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets. Date/time cells: numberFormat {type:"DATE", pattern:"yyyy-mm-dd hh:mm"} only displays a numeric serial as a date; it does not convert text. '.concat(_constantsts.NATIVE_DATE_POINTER),
215
216
  inputSchema: inputSchema,
216
217
  outputSchema: _zod.z.object({
217
218
  result: outputSchema
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/cells-format.ts"],"sourcesContent":["import { type sheets_v4, sheets as sheetsApi } from '@googleapis/sheets';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { z } from 'zod';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { parseA1Notation, rangeReferenceToGridRange } from '../../spreadsheet/range-operations.ts';\n\n// RGB color schema (0-1 range for Google Sheets API)\nconst ColorSchema = z.object({\n red: z.number().min(0).max(1).describe('Red component (0-1)'),\n green: z.number().min(0).max(1).describe('Green component (0-1)'),\n blue: z.number().min(0).max(1).describe('Blue component (0-1)'),\n});\n\n// Number format schema\nconst NumberFormatSchema = z.object({\n type: z.enum(['TEXT', 'NUMBER', 'PERCENT', 'CURRENCY', 'DATE', 'TIME']).describe('Number format type'),\n pattern: z.string().optional().describe('Custom format pattern (e.g., \"$#,##0.00\" for currency)'),\n});\n\n// Border schema\nconst BorderSchema = z.object({\n style: z.enum(['SOLID', 'DASHED', 'DOTTED']).describe('Border line style'),\n color: ColorSchema.describe('Border color'),\n});\n\n// Input schema for format requests\nconst FormatRequestSchema = z.object({\n range: z.string().min(1).describe('A1 notation range to format (e.g., \"A1:D10\", \"B:B\", \"5:5\")'),\n backgroundColor: ColorSchema.optional().describe('Cell background color'),\n textColor: ColorSchema.optional().describe('Text color'),\n bold: z.boolean().optional().describe('Bold text'),\n fontSize: z.number().int().min(6).max(36).optional().describe('Font size in points'),\n horizontalAlignment: z.enum(['LEFT', 'CENTER', 'RIGHT']).optional().describe('Horizontal text alignment'),\n numberFormat: NumberFormatSchema.optional().describe('Number format pattern'),\n borders: BorderSchema.optional().describe('Cell borders'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n requests: z.array(FormatRequestSchema).min(1).max(50).describe('Array of formatting requests. Batch multiple ranges for efficiency.'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetTitle: z.string().describe('Title of the formatted sheet'),\n sheetUrl: z.string().describe('URL of the formatted sheet'),\n successCount: z.number().int().nonnegative().describe('Number of format requests successfully applied'),\n failedRanges: z\n .array(\n z.object({\n range: z.string().describe('A1 notation of range that failed'),\n error: z.string().describe('Why formatting failed for this range'),\n })\n )\n .optional()\n .describe('Only populated if some ranges failed to format'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, requests }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.cells.format called', {\n id,\n gid,\n requestCount: requests.length,\n });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n // Find sheet by gid\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n logger.info('Sheet not found for format cells', { id, gid, requestCount: requests.length });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? gid;\n // googleapis types sheetId as `number | null | undefined`; coerce for rangeReferenceToGridRange below (same pattern as values-batch-update.ts's sheetGid).\n const sheetId = sheet.properties.sheetId ?? 0;\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`;\n\n // Build batch update requests\n const batchRequests: sheets_v4.Schema$Request[] = [];\n const failedRanges: Array<{ range: string; error: string }> = [];\n\n for (const request of requests) {\n try {\n // Parse A1 notation to range reference\n const rangeRef = parseA1Notation(request.range);\n\n // Build grid range from range reference using helper function\n const gridRange = rangeReferenceToGridRange(rangeRef, sheetId);\n\n // Build cell format object\n const cellFormat: {\n backgroundColor?: sheets_v4.Schema$Color;\n textFormat?: sheets_v4.Schema$TextFormat;\n horizontalAlignment?: string;\n numberFormat?: sheets_v4.Schema$NumberFormat;\n } = {};\n const fields: string[] = [];\n\n // Background color\n if (request.backgroundColor) {\n cellFormat.backgroundColor = request.backgroundColor;\n fields.push('backgroundColor');\n }\n\n // Text format\n if (request.textColor || request.bold !== undefined || request.fontSize !== undefined) {\n cellFormat.textFormat = {};\n if (request.textColor) {\n cellFormat.textFormat.foregroundColor = request.textColor;\n fields.push('textFormat.foregroundColor');\n }\n if (request.bold !== undefined) {\n cellFormat.textFormat.bold = request.bold;\n fields.push('textFormat.bold');\n }\n if (request.fontSize !== undefined) {\n cellFormat.textFormat.fontSize = request.fontSize;\n fields.push('textFormat.fontSize');\n }\n }\n\n // Horizontal alignment\n if (request.horizontalAlignment) {\n cellFormat.horizontalAlignment = request.horizontalAlignment;\n fields.push('horizontalAlignment');\n }\n\n // Number format\n if (request.numberFormat) {\n const numberFormat: sheets_v4.Schema$NumberFormat = {\n type: request.numberFormat.type,\n };\n if (request.numberFormat.pattern !== undefined) {\n numberFormat.pattern = request.numberFormat.pattern;\n }\n cellFormat.numberFormat = numberFormat;\n fields.push('numberFormat');\n }\n\n // Add repeatCell request for this range\n if (fields.length > 0) {\n batchRequests.push({\n repeatCell: {\n range: gridRange,\n cell: {\n userEnteredFormat: cellFormat,\n },\n fields: `userEnteredFormat(${fields.join(',')})`,\n },\n });\n }\n\n // Add border formatting if specified\n if (request.borders) {\n batchRequests.push({\n updateBorders: {\n range: gridRange,\n top: {\n style: request.borders.style,\n color: request.borders.color,\n },\n bottom: {\n style: request.borders.style,\n color: request.borders.color,\n },\n left: {\n style: request.borders.style,\n color: request.borders.color,\n },\n right: {\n style: request.borders.style,\n color: request.borders.color,\n },\n },\n });\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.info('Failed to parse range for formatting', {\n range: request.range,\n error: message,\n });\n failedRanges.push({\n range: request.range,\n error: `Failed to parse range: ${message}`,\n });\n }\n }\n\n // Early return if all ranges failed\n if (batchRequests.length === 0) {\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: 0,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n }\n\n logger.info('sheets.cells.format executing batch request', {\n spreadsheetId: id,\n sheetTitle,\n batchRequestsCount: batchRequests.length,\n });\n\n // Execute the batch update\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: batchRequests,\n },\n });\n\n logger.info('sheets.cells.format completed successfully', {\n successCount: requests.length - failedRanges.length,\n failedCount: failedRanges.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: requests.length - failedRanges.length,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('Format cells operation failed', {\n id,\n gid,\n requestCount: requests.length,\n error: message,\n });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error formatting cells: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'cells-format',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","ColorSchema","z","object","red","number","min","max","describe","green","blue","NumberFormatSchema","type","enum","pattern","string","optional","BorderSchema","style","color","FormatRequestSchema","range","backgroundColor","textColor","bold","boolean","fontSize","int","horizontalAlignment","numberFormat","borders","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","requests","array","successBranchSchema","literal","SpreadsheetIdOutput","SheetGidOutput","sheetTitle","sheetUrl","successCount","nonnegative","failedRanges","error","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sheet","spreadsheetResponse","sheets","sheetId","batchRequests","request","rangeRef","gridRange","cellFormat","fields","message","info","requestCount","length","sheetsApi","version","auth","googleAuth","authContext","spreadsheets","get","spreadsheetId","data","find","s","String","properties","ProtocolError","ProtocolErrorCode","InvalidParams","title","parseA1Notation","rangeReferenceToGridRange","push","undefined","textFormat","foregroundColor","repeatCell","cell","userEnteredFormat","join","updateBorders","top","bottom","left","right","Error","content","text","JSON","stringify","structuredContent","batchRequestsCount","batchUpdate","requestBody","failedCount","InternalError","stack","name"],"mappings":";;;;+BAgSA;;;eAAwBA;;;sBAhS4B;2BAE5B;sBAKyB;mBAC/B;4BACS;uBAC8D;iCAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAP3D,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,qDAAqD;AACrD,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,KAAKF,MAAC,CAACG,MAAM,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACvCC,OAAOP,MAAC,CAACG,MAAM,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACzCE,MAAMR,MAAC,CAACG,MAAM,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AAC1C;AAEA,uBAAuB;AACvB,IAAMG,qBAAqBT,MAAC,CAACC,MAAM,CAAC;IAClCS,MAAMV,MAAC,CAACW,IAAI,CAAC;QAAC;QAAQ;QAAU;QAAW;QAAY;QAAQ;KAAO,EAAEL,QAAQ,CAAC;IACjFM,SAASZ,MA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AAK,YAALA,OAAiBuD,SAAQvD,MAAMkE,KAAK,GAAGvB;oBAChD;;;;;;;IAEJ;;AAEe,SAAS5F;IACtB,OAAO;QACLoH,MAAM;QACNhE,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/cells-format.ts"],"sourcesContent":["import { type sheets_v4, sheets as sheetsApi } from '@googleapis/sheets';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { z } from 'zod';\nimport { NATIVE_DATE_POINTER } from '../../constants.ts';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { parseA1Notation, rangeReferenceToGridRange } from '../../spreadsheet/range-operations.ts';\n\n// RGB color schema (0-1 range for Google Sheets API)\nconst ColorSchema = z.object({\n red: z.number().min(0).max(1).describe('Red component (0-1)'),\n green: z.number().min(0).max(1).describe('Green component (0-1)'),\n blue: z.number().min(0).max(1).describe('Blue component (0-1)'),\n});\n\n// Number format schema\nconst NumberFormatSchema = z.object({\n type: z.enum(['TEXT', 'NUMBER', 'PERCENT', 'CURRENCY', 'DATE', 'TIME']).describe('Number format type'),\n pattern: z.string().optional().describe('Custom format pattern (e.g., \"$#,##0.00\" for currency, \"yyyy-mm-dd hh:mm\" for a date/time serial)'),\n});\n\n// Border schema\nconst BorderSchema = z.object({\n style: z.enum(['SOLID', 'DASHED', 'DOTTED']).describe('Border line style'),\n color: ColorSchema.describe('Border color'),\n});\n\n// Input schema for format requests\nconst FormatRequestSchema = z.object({\n range: z.string().min(1).describe('A1 notation range to format (e.g., \"A1:D10\", \"B:B\", \"5:5\")'),\n backgroundColor: ColorSchema.optional().describe('Cell background color'),\n textColor: ColorSchema.optional().describe('Text color'),\n bold: z.boolean().optional().describe('Bold text'),\n fontSize: z.number().int().min(6).max(36).optional().describe('Font size in points'),\n horizontalAlignment: z.enum(['LEFT', 'CENTER', 'RIGHT']).optional().describe('Horizontal text alignment'),\n numberFormat: NumberFormatSchema.optional().describe('Number format pattern'),\n borders: BorderSchema.optional().describe('Cell borders'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n requests: z.array(FormatRequestSchema).min(1).max(50).describe('Array of formatting requests. Batch multiple ranges for efficiency.'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetTitle: z.string().describe('Title of the formatted sheet'),\n sheetUrl: z.string().describe('URL of the formatted sheet'),\n successCount: z.number().int().nonnegative().describe('Number of format requests successfully applied'),\n failedRanges: z\n .array(\n z.object({\n range: z.string().describe('A1 notation of range that failed'),\n error: z.string().describe('Why formatting failed for this range'),\n })\n )\n .optional()\n .describe('Only populated if some ranges failed to format'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: `Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets. Date/time cells: numberFormat {type:\"DATE\", pattern:\"yyyy-mm-dd hh:mm\"} only displays a numeric serial as a date; it does not convert text. ${NATIVE_DATE_POINTER}`,\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, requests }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.cells.format called', {\n id,\n gid,\n requestCount: requests.length,\n });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n // Find sheet by gid\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n logger.info('Sheet not found for format cells', { id, gid, requestCount: requests.length });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? gid;\n // googleapis types sheetId as `number | null | undefined`; coerce for rangeReferenceToGridRange below (same pattern as values-batch-update.ts's sheetGid).\n const sheetId = sheet.properties.sheetId ?? 0;\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`;\n\n // Build batch update requests\n const batchRequests: sheets_v4.Schema$Request[] = [];\n const failedRanges: Array<{ range: string; error: string }> = [];\n\n for (const request of requests) {\n try {\n // Parse A1 notation to range reference\n const rangeRef = parseA1Notation(request.range);\n\n // Build grid range from range reference using helper function\n const gridRange = rangeReferenceToGridRange(rangeRef, sheetId);\n\n // Build cell format object\n const cellFormat: {\n backgroundColor?: sheets_v4.Schema$Color;\n textFormat?: sheets_v4.Schema$TextFormat;\n horizontalAlignment?: string;\n numberFormat?: sheets_v4.Schema$NumberFormat;\n } = {};\n const fields: string[] = [];\n\n // Background color\n if (request.backgroundColor) {\n cellFormat.backgroundColor = request.backgroundColor;\n fields.push('backgroundColor');\n }\n\n // Text format\n if (request.textColor || request.bold !== undefined || request.fontSize !== undefined) {\n cellFormat.textFormat = {};\n if (request.textColor) {\n cellFormat.textFormat.foregroundColor = request.textColor;\n fields.push('textFormat.foregroundColor');\n }\n if (request.bold !== undefined) {\n cellFormat.textFormat.bold = request.bold;\n fields.push('textFormat.bold');\n }\n if (request.fontSize !== undefined) {\n cellFormat.textFormat.fontSize = request.fontSize;\n fields.push('textFormat.fontSize');\n }\n }\n\n // Horizontal alignment\n if (request.horizontalAlignment) {\n cellFormat.horizontalAlignment = request.horizontalAlignment;\n fields.push('horizontalAlignment');\n }\n\n // Number format\n if (request.numberFormat) {\n const numberFormat: sheets_v4.Schema$NumberFormat = {\n type: request.numberFormat.type,\n };\n if (request.numberFormat.pattern !== undefined) {\n numberFormat.pattern = request.numberFormat.pattern;\n }\n cellFormat.numberFormat = numberFormat;\n fields.push('numberFormat');\n }\n\n // Add repeatCell request for this range\n if (fields.length > 0) {\n batchRequests.push({\n repeatCell: {\n range: gridRange,\n cell: {\n userEnteredFormat: cellFormat,\n },\n fields: `userEnteredFormat(${fields.join(',')})`,\n },\n });\n }\n\n // Add border formatting if specified\n if (request.borders) {\n batchRequests.push({\n updateBorders: {\n range: gridRange,\n top: {\n style: request.borders.style,\n color: request.borders.color,\n },\n bottom: {\n style: request.borders.style,\n color: request.borders.color,\n },\n left: {\n style: request.borders.style,\n color: request.borders.color,\n },\n right: {\n style: request.borders.style,\n color: request.borders.color,\n },\n },\n });\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.info('Failed to parse range for formatting', {\n range: request.range,\n error: message,\n });\n failedRanges.push({\n range: request.range,\n error: `Failed to parse range: ${message}`,\n });\n }\n }\n\n // Early return if all ranges failed\n if (batchRequests.length === 0) {\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: 0,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n }\n\n logger.info('sheets.cells.format executing batch request', {\n spreadsheetId: id,\n sheetTitle,\n batchRequestsCount: batchRequests.length,\n });\n\n // Execute the batch update\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: batchRequests,\n },\n });\n\n logger.info('sheets.cells.format completed successfully', {\n successCount: requests.length - failedRanges.length,\n failedCount: failedRanges.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: requests.length - failedRanges.length,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('Format cells operation failed', {\n id,\n gid,\n requestCount: requests.length,\n error: message,\n });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error formatting cells: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'cells-format',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","ColorSchema","z","object","red","number","min","max","describe","green","blue","NumberFormatSchema","type","enum","pattern","string","optional","BorderSchema","style","color","FormatRequestSchema","range","backgroundColor","textColor","bold","boolean","fontSize","int","horizontalAlignment","numberFormat","borders","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","requests","array","successBranchSchema","literal","SpreadsheetIdOutput","SheetGidOutput","sheetTitle","sheetUrl","successCount","nonnegative","failedRanges","error","outputSchema","discriminatedUnion","config","description","NATIVE_DATE_POINTER","result","handler","extra","logger","sheet","spreadsheetResponse","sheets","sheetId","batchRequests","request","rangeRef","gridRange","cellFormat","fields","message","info","requestCount","length","sheetsApi","version","auth","googleAuth","authContext","spreadsheets","get","spreadsheetId","data","find","s","String","properties","ProtocolError","ProtocolErrorCode","InvalidParams","title","parseA1Notation","rangeReferenceToGridRange","push","undefined","textFormat","foregroundColor","repeatCell","cell","userEnteredFormat","join","updateBorders","top","bottom","left","right","Error","content","text","JSON","stringify","structuredContent","batchRequestsCount","batchUpdate","requestBody","failedCount","InternalError","stack","name"],"mappings":";;;;+BAiSA;;;eAAwBA;;;sBAjS4B;2BAE5B;sBAKyB;mBAC/B;2BACkB;4BACT;uBAC8D;iCAC9B;;;;;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