@mindstone/mcp-server-google-workspace 0.4.2 → 0.5.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.
Files changed (39) hide show
  1. package/README.md +43 -5
  2. package/dist/modules/docs/service.d.ts +76 -6
  3. package/dist/modules/docs/service.js +791 -103
  4. package/dist/modules/docs/tabCopy.d.ts +266 -0
  5. package/dist/modules/docs/tabCopy.js +794 -0
  6. package/dist/modules/docs/tabs.d.ts +161 -0
  7. package/dist/modules/docs/tabs.js +416 -0
  8. package/dist/modules/docs/types.d.ts +141 -1
  9. package/dist/modules/drive/service.d.ts +15 -0
  10. package/dist/modules/drive/service.js +77 -2
  11. package/dist/modules/drive/types.d.ts +1 -1
  12. package/dist/modules/sheets/a1Utils.d.ts +13 -0
  13. package/dist/modules/sheets/a1Utils.js +33 -7
  14. package/dist/modules/sheets/formatters.d.ts +33 -2
  15. package/dist/modules/sheets/formatters.js +84 -5
  16. package/dist/modules/sheets/service.d.ts +26 -1
  17. package/dist/modules/sheets/service.js +264 -8
  18. package/dist/modules/sheets/types.d.ts +71 -0
  19. package/dist/modules/sheets/types.js +12 -1
  20. package/dist/modules/sheets/writeGuards.js +2 -2
  21. package/dist/tools/definitions/destructive-overrides.json +8 -0
  22. package/dist/tools/definitions/docs.js +395 -9
  23. package/dist/tools/definitions/drive.js +9 -4
  24. package/dist/tools/definitions/open-world-overrides.json +8 -0
  25. package/dist/tools/definitions/sheets.js +177 -1
  26. package/dist/tools/docs-handlers.d.ts +125 -0
  27. package/dist/tools/docs-handlers.js +397 -15
  28. package/dist/tools/param-normalizer.js +16 -0
  29. package/dist/tools/server.js +35 -3
  30. package/dist/tools/sheets-handlers.d.ts +54 -1
  31. package/dist/tools/sheets-handlers.js +107 -13
  32. package/dist/tools/type-guards.d.ts +89 -0
  33. package/dist/tools/type-guards.js +190 -6
  34. package/dist/tools/types.d.ts +1 -1
  35. package/dist/utils/apiError.d.ts +6 -0
  36. package/dist/utils/apiError.js +12 -0
  37. package/dist/utils/tabPosition.d.ts +20 -0
  38. package/dist/utils/tabPosition.js +19 -0
  39. package/package.json +1 -1
@@ -0,0 +1,266 @@
1
+ /**
2
+ * Copy one Docs tab's content into another tab of the same document.
3
+ *
4
+ * The Docs API has no "copy tab" request, so the copy is rebuilt from a
5
+ * `documents.get` read of the source in dependent rounds of `batchUpdate`
6
+ * (indices only exist after the previous round has been applied):
7
+ *
8
+ * Phase 0 clear the target, copy page setup and named styles
9
+ * Phase 1 skeleton: text, smart chips, page breaks and empty tables, in order
10
+ * Phase 2 table cell text, filled in reverse order
11
+ * Phase 3 paragraph styles, run styles and bullets, per unit, last unit first
12
+ * Phase 3b re-apply bullet paragraphs' paragraph styles (bullets reset them)
13
+ * Phase 4 table column widths and cell styles
14
+ * then a verification read compares the result with the source.
15
+ *
16
+ * The planners below are pure (documents.get JSON in, batchUpdate requests out)
17
+ * and the orchestrator `copyTabContent` takes its I/O as injected dependencies,
18
+ * so the whole algorithm is testable without the API. Ordering rules that the
19
+ * API depends on (learned against the live API, do not reorder):
20
+ * - Within a paragraph: paragraph style (incl. namedStyleType) first, then the
21
+ * text-style clear, then run styles, then bullets. Re-applying namedStyleType
22
+ * wipes run styles.
23
+ * - createParagraphBullets removes the leading tabs that set nesting and resets
24
+ * indents/spacing, so units are sent last-first and bullet paragraphs get
25
+ * their paragraph style re-applied (without namedStyleType) afterwards.
26
+ * - insertTable adds its own newline before the table; insertPageBreak adds a
27
+ * newline after the break; empty insertText is rejected.
28
+ * - insertRichLink fails the whole batch when the caller can't open the linked
29
+ * file, so every chip is checked first and falls back to a titled link.
30
+ */
31
+ import { docs_v1 } from 'googleapis';
32
+ import { ParagraphContainer } from './tabs.js';
33
+ type Tab = docs_v1.Schema$Tab;
34
+ type Paragraph = docs_v1.Schema$Paragraph;
35
+ type TextStyle = docs_v1.Schema$TextStyle;
36
+ /** Requests per batchUpdate call. */
37
+ export declare const CHUNK = 150;
38
+ /** Paragraph-style fields never copied (a heading id belongs to the source paragraph). */
39
+ export declare const PSTYLE_DROP: readonly string[];
40
+ /**
41
+ * Document-style (page setup) fields copied in Phase 0. Never
42
+ * `useCustomHeaderFooterMargins`: the API rejects it in updateDocumentStyle.
43
+ */
44
+ export declare const DOCUMENT_STYLE_KEYS: readonly ["marginTop", "marginBottom", "marginLeft", "marginRight", "pageSize", "marginHeader", "marginFooter", "pageNumberStart"];
45
+ /**
46
+ * A Docs request, plus the two request types the googleapis 171.4.0 typings
47
+ * lack (both are documented by Google; insertRichLink is proven live).
48
+ */
49
+ export type TabCopyRequest = docs_v1.Schema$Request & {
50
+ insertRichLink?: {
51
+ location?: docs_v1.Schema$Location;
52
+ endOfSegmentLocation?: docs_v1.Schema$EndOfSegmentLocation;
53
+ richLinkProperties: {
54
+ uri: string;
55
+ };
56
+ };
57
+ updateNamedStyle?: {
58
+ tabId?: string;
59
+ namedStyle: docs_v1.Schema$NamedStyle;
60
+ fields: string;
61
+ };
62
+ };
63
+ /** One piece of a source paragraph, with its length in the target (UTF-16 units). */
64
+ export type Piece = {
65
+ kind: 'text';
66
+ text: string;
67
+ length: number;
68
+ style?: TextStyle;
69
+ /** Leading tabs that set a bullet's nesting level (createParagraphBullets removes them). */
70
+ nesting?: true;
71
+ /** A visible "[kind]" stand-in for an element that can't be copied. */
72
+ placeholder?: true;
73
+ } | {
74
+ kind: 'chip';
75
+ uri: string;
76
+ length: 1;
77
+ style: TextStyle;
78
+ } | {
79
+ kind: 'pagebreak';
80
+ length: 1;
81
+ style: TextStyle;
82
+ };
83
+ export type Token = {
84
+ kind: 'text';
85
+ text: string;
86
+ } | {
87
+ kind: 'chip';
88
+ uri: string;
89
+ } | {
90
+ kind: 'pagebreak';
91
+ } | {
92
+ kind: 'table';
93
+ rows: number;
94
+ columns: number;
95
+ };
96
+ export type SourceParagraph = {
97
+ container: ParagraphContainer;
98
+ paragraph: Paragraph;
99
+ pieces: Piece[];
100
+ };
101
+ export type ChipFallback = {
102
+ uri: string;
103
+ title: string;
104
+ };
105
+ export interface SourcePlan {
106
+ /** Body and table-cell paragraphs in document order (the order flatParagraphs gives the target). */
107
+ paragraphs: SourceParagraph[];
108
+ /** Phase 1 tokens, appended at the end of the target in order. */
109
+ bodyTokens: Token[];
110
+ tables: docs_v1.Schema$Table[];
111
+ /** Phase 2 tokens per cell: cellTokens[table][row][col], trailing newline stripped. */
112
+ cellTokens: Token[][][][];
113
+ lists: Record<string, docs_v1.Schema$List>;
114
+ chipsCopied: number;
115
+ /** One entry per distinct URI. */
116
+ chipFallbacks: ChipFallback[];
117
+ convertedToText: {
118
+ people: number;
119
+ dates: number;
120
+ };
121
+ placeholders: number;
122
+ /** Element kinds (or "merged table cells") that were not copied, with counts. */
123
+ notCopied: Record<string, number>;
124
+ notes: string[];
125
+ }
126
+ export interface CopyMismatch {
127
+ /** 0-based paragraph (body and table-cell paragraphs, in document order). */
128
+ paragraphIndex?: number;
129
+ /** 0-based table in the tab body. */
130
+ tableIndex?: number;
131
+ kind: string;
132
+ }
133
+ export interface CopyVerification {
134
+ passed: boolean;
135
+ checkedParagraphs: number;
136
+ tables: number;
137
+ lists: number;
138
+ placeholders: number;
139
+ mismatchCount: number;
140
+ /** The first few mismatches (indices and kinds only, never text). */
141
+ mismatches: CopyMismatch[];
142
+ }
143
+ export interface TabCopyResult {
144
+ targetTabId: string;
145
+ requests: number;
146
+ rounds: number;
147
+ chipsCopied: number;
148
+ chipFallbacks: ChipFallback[];
149
+ convertedToText: {
150
+ people: number;
151
+ dates: number;
152
+ };
153
+ namedStylesCopied: number;
154
+ notCopied: Record<string, number>;
155
+ notes: string[];
156
+ verification: CopyVerification;
157
+ }
158
+ export interface TabCopyDeps {
159
+ /** Committed content only: pending suggestions are left out (PREVIEW_WITHOUT_SUGGESTIONS). */
160
+ getSourceTab(): Promise<Tab>;
161
+ /** A fresh read of a tab (default view, so indices are valid for writes). */
162
+ getTab(tabId: string): Promise<Tab>;
163
+ batchUpdate(requests: TabCopyRequest[]): Promise<void>;
164
+ /** Whether the caller can open the file a smart chip links to. */
165
+ checkChip(uri: string): Promise<boolean>;
166
+ /**
167
+ * Called once, after the source is read and every chip checked and before
168
+ * the first content write. Returns the target tab id (new-tab mode creates
169
+ * the tab here).
170
+ */
171
+ prepareTarget(): Promise<string>;
172
+ }
173
+ /**
174
+ * A failure inside the copy, naming the phase, whether a content write was
175
+ * confirmed (`wroteContent`) and whether one had been sent at all
176
+ * (`attemptedWrite`: a write whose reply was lost may still have applied).
177
+ */
178
+ export declare class TabCopyError extends Error {
179
+ readonly phase: string;
180
+ readonly wroteContent: boolean;
181
+ readonly attemptedWrite: boolean;
182
+ readonly cause: unknown;
183
+ constructor(phase: string, wroteContent: boolean, attemptedWrite: boolean, cause: unknown);
184
+ }
185
+ /** Drive file id of a Docs/Sheets/Slides/Drive link (`/d/<id>`), or null. */
186
+ export declare function idFromUri(uri: string): string | null;
187
+ /**
188
+ * Every smart-chip URI in the tab (body and table cells), in document order,
189
+ * without duplicates. Collected before any write so each one is checked once.
190
+ */
191
+ export declare function collectChipUris(tab: Tab): string[];
192
+ /**
193
+ * Docs bullet preset for a source list. Only preset styles can be created, so
194
+ * the first nesting level's glyph decides: decimal numbering, letter
195
+ * numbering, or discs (●/○/■ or no symbol; an unknown symbol also becomes
196
+ * discs, with a note).
197
+ */
198
+ export declare function presetFor(list: docs_v1.Schema$List | undefined, notes: string[]): string;
199
+ /**
200
+ * Plan the source tab: every paragraph's pieces (computed exactly once and
201
+ * reused by Phases 1-3 and verification), the Phase 1 and Phase 2 tokens, and
202
+ * the report counts. `chipAccess` holds the result of the per-URI access check;
203
+ * a URI that is missing or false falls back to a titled link.
204
+ */
205
+ export declare function buildSourcePlan(sourceTab: Tab, chipAccess: ReadonlyMap<string, boolean>): SourcePlan;
206
+ /**
207
+ * Phase 0: clear the target body, reset its remaining paragraph (no bullet,
208
+ * NORMAL_TEXT, no character style), copy page setup and any named style that
209
+ * differs from the target's.
210
+ */
211
+ export declare function planClear(sourceTab: Tab, targetTab: Tab, targetTabId: string): {
212
+ requests: TabCopyRequest[];
213
+ namedStylesCopied: number;
214
+ };
215
+ /** Phase 1: the skeleton, appended at the end of the target in document order. */
216
+ export declare function planSkeleton(plan: SourcePlan, targetTabId: string): TabCopyRequest[];
217
+ /**
218
+ * Phase 2: fill table cells, last table / row / column first and each cell's
219
+ * tokens in reverse, all at the cell's first index, so no insert shifts an
220
+ * index still to be used.
221
+ */
222
+ export declare function planTableCells(plan: SourcePlan, targetTab: Tab, targetTabId: string): TabCopyRequest[];
223
+ /**
224
+ * Phase 3: per unit (one paragraph, or a run of consecutive bullet paragraphs
225
+ * of one list in one container), in this order: paragraph style (incl.
226
+ * namedStyleType) → bullet removal → text-style clear → run styles, per
227
+ * paragraph; then createParagraphBullets over the unit. Units are emitted last
228
+ * first, because createParagraphBullets removes the nesting tabs and shifts
229
+ * every later index. Throws when the target's paragraph count differs.
230
+ */
231
+ export declare function planStyles(plan: SourcePlan, targetTab: Tab, targetTabId: string): TabCopyRequest[];
232
+ /**
233
+ * Phase 3b: createParagraphBullets resets indents and spacing, so re-apply each
234
+ * bullet paragraph's source style, without namedStyleType (re-applying it
235
+ * would wipe the run styles) and without headingId.
236
+ */
237
+ export declare function planBulletParagraphStyles(plan: SourcePlan, targetTab: Tab, targetTabId: string): TabCopyRequest[];
238
+ /**
239
+ * Phase 4: table column properties and cell styles (merges are not
240
+ * reproduced, so rowSpan/columnSpan are dropped).
241
+ */
242
+ export declare function planTableStyles(plan: SourcePlan, targetTab: Tab, targetTabId: string): TabCopyRequest[];
243
+ /**
244
+ * Paragraph-format fields compared by verification, when set on the source
245
+ * paragraph. headingId is never compared. If the live API normalises one of
246
+ * these on every paragraph (a difference that is not a copy defect), remove
247
+ * that field here with a comment saying why.
248
+ */
249
+ export declare const VERIFIED_PARAGRAPH_FIELDS: readonly ["alignment", "direction", "indentStart", "indentEnd", "indentFirstLine", "spaceAbove", "spaceBelow", "lineSpacing", "spacingMode"];
250
+ /**
251
+ * Compare the copied tab with the source: per paragraph the text (with chip
252
+ * fallbacks, people and dates as the text that was inserted), named style,
253
+ * paragraph formatting, bullet and nesting; list grouping (one-to-one list
254
+ * mapping); table count and shapes. Run styles and table cell styles are not
255
+ * compared. Reports indices and kinds only, never document text.
256
+ */
257
+ export declare function verifyCopy(plan: SourcePlan, sourceTab: Tab, targetTab: Tab): CopyVerification;
258
+ /**
259
+ * Run the copy: read and plan the source, check every chip, prepare the
260
+ * target, then Phases 0-4 and a verification read. Requests are sent in
261
+ * chunks of CHUNK per batchUpdate. Any failure is rethrown as a TabCopyError
262
+ * naming the phase and whether content had already been written.
263
+ */
264
+ export declare function copyTabContent(deps: TabCopyDeps): Promise<TabCopyResult>;
265
+ export {};
266
+ //# sourceMappingURL=tabCopy.d.ts.map