@mutallip/google-workspace-mcp 0.0.0-stage → 2.8.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/LICENSE +21 -0
- package/README.md +353 -2
- package/README.npm.md +28 -0
- package/auth/__init__.py +1 -0
- package/auth/auth_info_middleware.py +419 -0
- package/auth/client_secrets.py +76 -0
- package/auth/credential_store.py +598 -0
- package/auth/external_oauth_provider.py +369 -0
- package/auth/gateway_identity.py +164 -0
- package/auth/google_auth.py +1550 -0
- package/auth/google_oauth_provider.py +20 -0
- package/auth/mcp_session_middleware.py +95 -0
- package/auth/oauth21_session_store.py +1332 -0
- package/auth/oauth_callback_server.py +466 -0
- package/auth/oauth_config.py +693 -0
- package/auth/oauth_proxy_config.py +122 -0
- package/auth/oauth_responses.py +230 -0
- package/auth/oauth_types.py +92 -0
- package/auth/permissions.py +330 -0
- package/auth/port_resolver.py +153 -0
- package/auth/request_identity.py +89 -0
- package/auth/scopes.py +369 -0
- package/auth/service_decorator.py +1109 -0
- package/bin/google-workspace-mcp.cjs +123 -0
- package/core/__init__.py +1 -0
- package/core/api_enablement.py +108 -0
- package/core/attachment_storage.py +496 -0
- package/core/camel_case_middleware.py +98 -0
- package/core/cli.py +161 -0
- package/core/comments.py +609 -0
- package/core/config.py +57 -0
- package/core/context.py +43 -0
- package/core/file_limits.py +632 -0
- package/core/gcs_attachment_storage.py +253 -0
- package/core/http_utils.py +339 -0
- package/core/log_formatter.py +270 -0
- package/core/portable_schema_middleware.py +67 -0
- package/core/server.py +1192 -0
- package/core/startup_ui.py +239 -0
- package/core/storage.py +23 -0
- package/core/telemetry.py +194 -0
- package/core/tool_descriptions.py +19 -0
- package/core/tool_registry.py +311 -0
- package/core/tool_tier_loader.py +197 -0
- package/core/tool_tiers.yaml +179 -0
- package/core/toolset_header_middleware.py +67 -0
- package/core/utils.py +1537 -0
- package/core/valkey_storage.py +271 -0
- package/core/warning_filters.py +19 -0
- package/fastmcp_server.py +198 -0
- package/gappsscript/README.md +512 -0
- package/gappsscript/TESTING.md +254 -0
- package/gappsscript/__init__.py +0 -0
- package/gappsscript/apps_script_tools.py +1940 -0
- package/gcalendar/__init__.py +1 -0
- package/gcalendar/calendar_helpers.py +1323 -0
- package/gcalendar/calendar_tools.py +2252 -0
- package/gchat/__init__.py +7 -0
- package/gchat/chat_helpers.py +410 -0
- package/gchat/chat_tools.py +798 -0
- package/gcontacts/__init__.py +1 -0
- package/gcontacts/contacts_helpers.py +765 -0
- package/gcontacts/contacts_tools.py +1685 -0
- package/gdocs/__init__.py +0 -0
- package/gdocs/docs_anchors.py +163 -0
- package/gdocs/docs_comments.py +89 -0
- package/gdocs/docs_helpers.py +2201 -0
- package/gdocs/docs_links.py +87 -0
- package/gdocs/docs_markdown.py +828 -0
- package/gdocs/docs_markdown_writer.py +592 -0
- package/gdocs/docs_plain_text.py +463 -0
- package/gdocs/docs_structure.py +621 -0
- package/gdocs/docs_tables.py +425 -0
- package/gdocs/docs_tools.py +3300 -0
- package/gdocs/managers/__init__.py +18 -0
- package/gdocs/managers/batch_operation_manager.py +1694 -0
- package/gdocs/managers/header_footer_manager.py +526 -0
- package/gdocs/managers/table_operation_manager.py +488 -0
- package/gdocs/managers/validation_manager.py +1504 -0
- package/gdocs/operation_schemas.py +594 -0
- package/gdrive/__init__.py +0 -0
- package/gdrive/drive_helpers.py +1738 -0
- package/gdrive/drive_tools.py +3085 -0
- package/gforms/__init__.py +3 -0
- package/gforms/forms_tools.py +575 -0
- package/gmail/__init__.py +1 -0
- package/gmail/gmail_helpers.py +2107 -0
- package/gmail/gmail_tools.py +4895 -0
- package/gmail/gmail_web_mime.py +441 -0
- package/gsearch/__init__.py +0 -0
- package/gsearch/search_tools.py +253 -0
- package/gsheets/__init__.py +31 -0
- package/gsheets/sheets_helpers.py +2236 -0
- package/gsheets/sheets_tools.py +3280 -0
- package/gslides/__init__.py +0 -0
- package/gslides/slides_digest.py +390 -0
- package/gslides/slides_helpers.py +392 -0
- package/gslides/slides_markup.py +770 -0
- package/gslides/slides_tools.py +376 -0
- package/gtasks/__init__.py +5 -0
- package/gtasks/tasks_tools.py +936 -0
- package/main.py +1170 -0
- package/package.json +43 -4
- package/pyproject.toml +173 -0
- package/uv.lock +2504 -0
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Typed Pydantic schemas for Google Docs batch operations.
|
|
3
|
+
|
|
4
|
+
These models are used to generate a richer MCP schema for batch_update_doc so
|
|
5
|
+
LLMs receive a machine-readable contract instead of a free-form object array.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
from typing import Annotated, Any, Literal, Optional, Union
|
|
13
|
+
from zoneinfo import available_timezones
|
|
14
|
+
|
|
15
|
+
from pydantic import (
|
|
16
|
+
BaseModel,
|
|
17
|
+
ConfigDict,
|
|
18
|
+
Field,
|
|
19
|
+
BeforeValidator,
|
|
20
|
+
field_validator,
|
|
21
|
+
model_validator,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
ParagraphBorderEdge = Literal["top", "bottom", "left", "right", "between"]
|
|
26
|
+
TableBorderEdge = Literal["top", "bottom", "left", "right"]
|
|
27
|
+
_IANA_TIME_ZONES = frozenset(available_timezones())
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _coerce_json_str_to_list(v: Any) -> Any:
|
|
31
|
+
"""Accept JSON-encoded lists for MCP clients that serialize arrays as strings."""
|
|
32
|
+
if not isinstance(v, str):
|
|
33
|
+
return v
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
parsed = json.loads(v)
|
|
37
|
+
except (json.JSONDecodeError, TypeError):
|
|
38
|
+
return v
|
|
39
|
+
|
|
40
|
+
return parsed if isinstance(parsed, list) else v
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class StrictDocOperation(BaseModel):
|
|
44
|
+
"""Base model for strictly typed high-impact operations."""
|
|
45
|
+
|
|
46
|
+
model_config = ConfigDict(extra="forbid")
|
|
47
|
+
|
|
48
|
+
tab_id: Optional[str] = Field(
|
|
49
|
+
default=None,
|
|
50
|
+
description="Optional document tab ID to target.",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class SegmentTargetDocOperation(StrictDocOperation):
|
|
55
|
+
"""Base model for operations that can target document segments."""
|
|
56
|
+
|
|
57
|
+
segment_id: Optional[str] = Field(
|
|
58
|
+
default=None,
|
|
59
|
+
description=(
|
|
60
|
+
"Optional header/footer/footnote segment ID. Use a real ID returned by "
|
|
61
|
+
"inspect_doc_structure; do not guess values like 'kix.header'."
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class InsertionLocationOperation(StrictDocOperation):
|
|
67
|
+
"""One explicit location or semantic anchor for an insertion."""
|
|
68
|
+
|
|
69
|
+
index: Optional[int] = Field(
|
|
70
|
+
default=None,
|
|
71
|
+
description="Insertion index. Omit when end_of_segment=true.",
|
|
72
|
+
)
|
|
73
|
+
end_of_segment: bool = Field(
|
|
74
|
+
default=False,
|
|
75
|
+
description="Append to the end of the targeted body/segment instead of using index.",
|
|
76
|
+
)
|
|
77
|
+
after_heading: Optional[str] = Field(
|
|
78
|
+
default=None,
|
|
79
|
+
description=(
|
|
80
|
+
"Insert immediately after the heading paragraph with this exact text, "
|
|
81
|
+
"resolved to an index at execution time. Errors when it matches zero or "
|
|
82
|
+
"more than one heading."
|
|
83
|
+
),
|
|
84
|
+
)
|
|
85
|
+
before_heading: Optional[str] = Field(
|
|
86
|
+
default=None,
|
|
87
|
+
description=(
|
|
88
|
+
"Insert immediately before the heading paragraph with this exact text. "
|
|
89
|
+
"Errors when it matches zero or more than one heading."
|
|
90
|
+
),
|
|
91
|
+
)
|
|
92
|
+
anchor_text: Optional[str] = Field(
|
|
93
|
+
default=None,
|
|
94
|
+
description=(
|
|
95
|
+
"Insert relative to this literal text, which must occur exactly once "
|
|
96
|
+
"within a single paragraph. Use anchor_position to pick which side."
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
anchor_position: Literal["before", "after"] = Field(
|
|
100
|
+
default="after",
|
|
101
|
+
description="Which side of anchor_text to insert on. Defaults to 'after'.",
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
@model_validator(mode="after")
|
|
105
|
+
def validate_location(self) -> "InsertionLocationOperation":
|
|
106
|
+
anchors = [self.after_heading, self.before_heading, self.anchor_text]
|
|
107
|
+
provided = sum(
|
|
108
|
+
[self.index is not None, self.end_of_segment]
|
|
109
|
+
+ [anchor is not None for anchor in anchors]
|
|
110
|
+
)
|
|
111
|
+
if provided != 1:
|
|
112
|
+
raise ValueError(
|
|
113
|
+
"Provide exactly one of 'index', 'end_of_segment=true', "
|
|
114
|
+
"'after_heading', 'before_heading' or 'anchor_text'."
|
|
115
|
+
)
|
|
116
|
+
return self
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class InsertTextOperation(InsertionLocationOperation, SegmentTargetDocOperation):
|
|
120
|
+
type: Literal["insert_text"]
|
|
121
|
+
text: str = Field(description="Text to insert.")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class ReplaceTextOperation(SegmentTargetDocOperation):
|
|
125
|
+
type: Literal["replace_text"]
|
|
126
|
+
start_index: int
|
|
127
|
+
end_index: int
|
|
128
|
+
text: str = Field(description="Replacement text.")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class DeleteTextOperation(SegmentTargetDocOperation):
|
|
132
|
+
type: Literal["delete_text"]
|
|
133
|
+
start_index: int
|
|
134
|
+
end_index: int
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class FormatTextOperation(SegmentTargetDocOperation):
|
|
138
|
+
type: Literal["format_text"]
|
|
139
|
+
start_index: int
|
|
140
|
+
end_index: int
|
|
141
|
+
bold: Optional[bool] = None
|
|
142
|
+
italic: Optional[bool] = None
|
|
143
|
+
underline: Optional[bool] = None
|
|
144
|
+
strikethrough: Optional[bool] = None
|
|
145
|
+
font_size: Optional[float] = None
|
|
146
|
+
font_family: Optional[str] = None
|
|
147
|
+
font_weight: Optional[int] = None
|
|
148
|
+
text_color: Optional[str] = None
|
|
149
|
+
background_color: Optional[str] = None
|
|
150
|
+
link_url: Optional[str] = None
|
|
151
|
+
clear_link: Optional[bool] = None
|
|
152
|
+
baseline_offset: Optional[str] = None
|
|
153
|
+
small_caps: Optional[bool] = None
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class UpdateParagraphStyleOperation(SegmentTargetDocOperation):
|
|
157
|
+
type: Literal["update_paragraph_style"]
|
|
158
|
+
start_index: int
|
|
159
|
+
end_index: int
|
|
160
|
+
heading_level: Optional[int] = None
|
|
161
|
+
alignment: Optional[str] = None
|
|
162
|
+
line_spacing: Optional[float] = None
|
|
163
|
+
indent_first_line: Optional[float] = None
|
|
164
|
+
indent_start: Optional[float] = None
|
|
165
|
+
indent_end: Optional[float] = None
|
|
166
|
+
space_above: Optional[float] = None
|
|
167
|
+
space_below: Optional[float] = None
|
|
168
|
+
named_style_type: Optional[str] = None
|
|
169
|
+
direction: Optional[str] = None
|
|
170
|
+
keep_lines_together: Optional[bool] = None
|
|
171
|
+
keep_with_next: Optional[bool] = None
|
|
172
|
+
avoid_widow_and_orphan: Optional[bool] = None
|
|
173
|
+
page_break_before: Optional[bool] = None
|
|
174
|
+
spacing_mode: Optional[str] = None
|
|
175
|
+
shading_color: Optional[str] = None
|
|
176
|
+
border_edges: Optional[list[ParagraphBorderEdge]] = Field(
|
|
177
|
+
default=None,
|
|
178
|
+
min_length=1,
|
|
179
|
+
description="Paragraph border edges to update; omit to update top, bottom, left, and right.",
|
|
180
|
+
)
|
|
181
|
+
border_color: Optional[str] = None
|
|
182
|
+
border_width: Optional[float] = None
|
|
183
|
+
border_padding: Optional[float] = None
|
|
184
|
+
border_dash: Optional[str] = None
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
class UpdateTableCellStyleOperation(StrictDocOperation):
|
|
188
|
+
type: Literal["update_table_cell_style"]
|
|
189
|
+
table_start_index: int
|
|
190
|
+
background_color: Optional[str] = None
|
|
191
|
+
border_color: Optional[str] = None
|
|
192
|
+
border_width: Optional[float] = None
|
|
193
|
+
padding_top: Optional[float] = None
|
|
194
|
+
padding_bottom: Optional[float] = None
|
|
195
|
+
padding_left: Optional[float] = None
|
|
196
|
+
padding_right: Optional[float] = None
|
|
197
|
+
content_alignment: Optional[str] = None
|
|
198
|
+
row_index: Optional[int] = None
|
|
199
|
+
column_index: Optional[int] = None
|
|
200
|
+
row_span: Optional[int] = None
|
|
201
|
+
column_span: Optional[int] = None
|
|
202
|
+
border_edges: Optional[list[TableBorderEdge]] = Field(
|
|
203
|
+
default=None,
|
|
204
|
+
min_length=1,
|
|
205
|
+
description="Table-cell border edges to update; omit to update all four edges.",
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
class InsertTableOperation(InsertionLocationOperation, SegmentTargetDocOperation):
|
|
210
|
+
type: Literal["insert_table"]
|
|
211
|
+
rows: int
|
|
212
|
+
columns: int
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
class InsertTableRowOperation(StrictDocOperation):
|
|
216
|
+
type: Literal["insert_table_row"]
|
|
217
|
+
table_start_index: int
|
|
218
|
+
row_index: int
|
|
219
|
+
insert_below: bool = True
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
class DeleteTableRowOperation(StrictDocOperation):
|
|
223
|
+
type: Literal["delete_table_row"]
|
|
224
|
+
table_start_index: int
|
|
225
|
+
row_index: int
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class InsertTableColumnOperation(StrictDocOperation):
|
|
229
|
+
type: Literal["insert_table_column"]
|
|
230
|
+
table_start_index: int
|
|
231
|
+
column_index: int
|
|
232
|
+
insert_right: bool = True
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class DeleteTableColumnOperation(StrictDocOperation):
|
|
236
|
+
type: Literal["delete_table_column"]
|
|
237
|
+
table_start_index: int
|
|
238
|
+
column_index: int
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class MergeTableCellsOperation(StrictDocOperation):
|
|
242
|
+
type: Literal["merge_table_cells"]
|
|
243
|
+
table_start_index: int
|
|
244
|
+
row_index: int
|
|
245
|
+
column_index: int
|
|
246
|
+
row_span: int
|
|
247
|
+
column_span: int
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
class UnmergeTableCellsOperation(StrictDocOperation):
|
|
251
|
+
type: Literal["unmerge_table_cells"]
|
|
252
|
+
table_start_index: int
|
|
253
|
+
row_index: int
|
|
254
|
+
column_index: int
|
|
255
|
+
row_span: int
|
|
256
|
+
column_span: int
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class UpdateTableColumnPropertiesOperation(StrictDocOperation):
|
|
260
|
+
type: Literal["update_table_column_properties"]
|
|
261
|
+
table_start_index: int
|
|
262
|
+
column_indices: list[int]
|
|
263
|
+
width: Optional[float] = None
|
|
264
|
+
width_type: Optional[str] = None
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class UpdateTableRowStyleOperation(StrictDocOperation):
|
|
268
|
+
type: Literal["update_table_row_style"]
|
|
269
|
+
table_start_index: int
|
|
270
|
+
row_indices: list[int] = Field(
|
|
271
|
+
description="Zero-based row indices to style, e.g. [0] for the header row."
|
|
272
|
+
)
|
|
273
|
+
min_row_height: Optional[float] = Field(
|
|
274
|
+
default=None,
|
|
275
|
+
description="Minimum row height in points.",
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class PinTableHeaderRowsOperation(StrictDocOperation):
|
|
280
|
+
type: Literal["pin_table_header_rows"]
|
|
281
|
+
table_start_index: int
|
|
282
|
+
pinned_header_rows_count: int = Field(
|
|
283
|
+
ge=0,
|
|
284
|
+
description="Number of leading rows to pin as a repeating header on each "
|
|
285
|
+
"page. 0 unpins all rows. Use this dedicated request because the "
|
|
286
|
+
"'tableHeader' value reported in TableRowStyle cannot be set through "
|
|
287
|
+
"UpdateTableRowStyleRequest.",
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
class InsertPageBreakOperation(InsertionLocationOperation):
|
|
292
|
+
type: Literal["insert_page_break"]
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
class InsertSectionBreakOperation(InsertionLocationOperation):
|
|
296
|
+
type: Literal["insert_section_break"]
|
|
297
|
+
section_type: Literal["CONTINUOUS", "NEXT_PAGE"] = "NEXT_PAGE"
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
class FindReplaceOperation(StrictDocOperation):
|
|
301
|
+
type: Literal["find_replace"]
|
|
302
|
+
find_text: str
|
|
303
|
+
replace_text: str
|
|
304
|
+
match_case: bool = False
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
class CreateBulletListOperation(SegmentTargetDocOperation):
|
|
308
|
+
type: Literal["create_bullet_list"]
|
|
309
|
+
start_index: int
|
|
310
|
+
end_index: int
|
|
311
|
+
list_type: Literal["UNORDERED", "ORDERED", "CHECKBOX", "NONE"] = "UNORDERED"
|
|
312
|
+
nesting_level: Optional[int] = None
|
|
313
|
+
paragraph_start_indices: Optional[list[int]] = None
|
|
314
|
+
bullet_preset: Optional[str] = None
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
class CreateNamedRangeOperation(SegmentTargetDocOperation):
|
|
318
|
+
type: Literal["create_named_range"]
|
|
319
|
+
name: str
|
|
320
|
+
start_index: int
|
|
321
|
+
end_index: int
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
class ReplaceNamedRangeContentOperation(StrictDocOperation):
|
|
325
|
+
type: Literal["replace_named_range_content"]
|
|
326
|
+
text: str
|
|
327
|
+
named_range_id: Optional[str] = None
|
|
328
|
+
named_range_name: Optional[str] = None
|
|
329
|
+
|
|
330
|
+
@model_validator(mode="after")
|
|
331
|
+
def validate_named_range_target(self) -> "ReplaceNamedRangeContentOperation":
|
|
332
|
+
if bool(self.named_range_id) == bool(self.named_range_name):
|
|
333
|
+
raise ValueError(
|
|
334
|
+
"Provide exactly one of 'named_range_id' or 'named_range_name'."
|
|
335
|
+
)
|
|
336
|
+
return self
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
class DeleteNamedRangeOperation(StrictDocOperation):
|
|
340
|
+
type: Literal["delete_named_range"]
|
|
341
|
+
named_range_id: Optional[str] = None
|
|
342
|
+
named_range_name: Optional[str] = None
|
|
343
|
+
|
|
344
|
+
@model_validator(mode="after")
|
|
345
|
+
def validate_named_range_target(self) -> "DeleteNamedRangeOperation":
|
|
346
|
+
if bool(self.named_range_id) == bool(self.named_range_name):
|
|
347
|
+
raise ValueError(
|
|
348
|
+
"Provide exactly one of 'named_range_id' or 'named_range_name'."
|
|
349
|
+
)
|
|
350
|
+
return self
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
class UpdateDocumentStyleOperation(StrictDocOperation):
|
|
354
|
+
type: Literal["update_document_style"]
|
|
355
|
+
background_color: Optional[str] = None
|
|
356
|
+
margin_top: Optional[float] = None
|
|
357
|
+
margin_bottom: Optional[float] = None
|
|
358
|
+
margin_left: Optional[float] = None
|
|
359
|
+
margin_right: Optional[float] = None
|
|
360
|
+
margin_header: Optional[float] = None
|
|
361
|
+
margin_footer: Optional[float] = None
|
|
362
|
+
page_width: Optional[float] = None
|
|
363
|
+
page_height: Optional[float] = None
|
|
364
|
+
page_number_start: Optional[int] = None
|
|
365
|
+
use_even_page_header_footer: Optional[bool] = None
|
|
366
|
+
use_first_page_header_footer: Optional[bool] = None
|
|
367
|
+
flip_page_orientation: Optional[bool] = None
|
|
368
|
+
document_mode: Optional[Literal["PAGES", "PAGELESS"]] = None
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
class UpdateSectionStyleOperation(StrictDocOperation):
|
|
372
|
+
type: Literal["update_section_style"]
|
|
373
|
+
start_index: int
|
|
374
|
+
end_index: int
|
|
375
|
+
margin_top: Optional[float] = None
|
|
376
|
+
margin_bottom: Optional[float] = None
|
|
377
|
+
margin_left: Optional[float] = None
|
|
378
|
+
margin_right: Optional[float] = None
|
|
379
|
+
margin_header: Optional[float] = None
|
|
380
|
+
margin_footer: Optional[float] = None
|
|
381
|
+
page_number_start: Optional[int] = None
|
|
382
|
+
use_first_page_header_footer: Optional[bool] = None
|
|
383
|
+
flip_page_orientation: Optional[bool] = None
|
|
384
|
+
content_direction: Optional[Literal["LEFT_TO_RIGHT", "RIGHT_TO_LEFT"]] = None
|
|
385
|
+
column_count: Optional[int] = None
|
|
386
|
+
column_spacing: Optional[float] = None
|
|
387
|
+
column_separator_style: Optional[Literal["NONE", "BETWEEN_EACH_COLUMN"]] = None
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
class CreateHeaderFooterOperation(StrictDocOperation):
|
|
391
|
+
type: Literal["create_header_footer"]
|
|
392
|
+
section_type: Literal["header", "footer"] = Field(
|
|
393
|
+
description="Which section to create."
|
|
394
|
+
)
|
|
395
|
+
header_footer_type: Literal["DEFAULT", "FIRST_PAGE_ONLY", "EVEN_PAGE"] = Field(
|
|
396
|
+
default="DEFAULT",
|
|
397
|
+
description="Header/footer type to create.",
|
|
398
|
+
)
|
|
399
|
+
section_break_index: Optional[int] = Field(
|
|
400
|
+
default=None,
|
|
401
|
+
description="Optional section break index for section-scoped layouts.",
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
class InsertImageOperation(InsertionLocationOperation, SegmentTargetDocOperation):
|
|
406
|
+
type: Literal["insert_image"]
|
|
407
|
+
image_uri: str = Field(description="Image URL or resolvable image URI.")
|
|
408
|
+
width: Optional[int] = None
|
|
409
|
+
height: Optional[int] = None
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
class InsertPersonOperation(InsertionLocationOperation, SegmentTargetDocOperation):
|
|
413
|
+
type: Literal["insert_person"]
|
|
414
|
+
email: str = Field(
|
|
415
|
+
min_length=1,
|
|
416
|
+
description="Email of the person to @mention as a smart chip.",
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
DropdownDefinitionId = Annotated[str, Field(pattern=r"^kix\.[a-zA-Z0-9_-]{2,14}$")]
|
|
421
|
+
DropdownOptionId = Annotated[str, Field(pattern=r"^dropdownItem\.[a-zA-Z0-9_-]{2,14}$")]
|
|
422
|
+
DropdownColor = Annotated[str, Field(pattern=r"^#[0-9a-fA-F]{6}$")]
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
class DropdownOption(BaseModel):
|
|
426
|
+
"""A native dropdown choice; only foreground/background colours are supported."""
|
|
427
|
+
|
|
428
|
+
model_config = ConfigDict(extra="forbid")
|
|
429
|
+
|
|
430
|
+
display_value: str = Field(min_length=1, max_length=200)
|
|
431
|
+
option_id: Optional[DropdownOptionId] = None
|
|
432
|
+
text_color: Optional[DropdownColor] = None
|
|
433
|
+
background_color: Optional[DropdownColor] = None
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
class CreateDropdownDefinitionOperation(StrictDocOperation):
|
|
437
|
+
type: Literal["create_dropdown_definition"]
|
|
438
|
+
title: str = Field(min_length=1, max_length=200)
|
|
439
|
+
options: list[DropdownOption] = Field(min_length=2, max_length=50)
|
|
440
|
+
dropdown_definition_id: Optional[DropdownDefinitionId] = Field(
|
|
441
|
+
default=None,
|
|
442
|
+
description="Unique within the tab. Omit for a server-generated ID returned in the result.",
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
@model_validator(mode="after")
|
|
446
|
+
def validate_option_ids(self) -> "CreateDropdownDefinitionOperation":
|
|
447
|
+
ids = [
|
|
448
|
+
option.option_id for option in self.options if option.option_id is not None
|
|
449
|
+
]
|
|
450
|
+
if len(ids) != len(set(ids)):
|
|
451
|
+
raise ValueError("option_id must be unique within a dropdown definition.")
|
|
452
|
+
return self
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
class InsertDropdownOperation(InsertionLocationOperation, SegmentTargetDocOperation):
|
|
456
|
+
type: Literal["insert_dropdown"]
|
|
457
|
+
dropdown_definition_id: DropdownDefinitionId
|
|
458
|
+
selected_option_id: Optional[DropdownOptionId] = Field(
|
|
459
|
+
default=None, description="Omit to select the first option in the definition."
|
|
460
|
+
)
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
class InsertDateOperation(InsertionLocationOperation, SegmentTargetDocOperation):
|
|
464
|
+
type: Literal["insert_date"]
|
|
465
|
+
date: str = Field(
|
|
466
|
+
min_length=1,
|
|
467
|
+
description="YYYY-MM-DD, or an ISO 8601 timestamp with an offset (displayed in UTC unless timezone is set).",
|
|
468
|
+
)
|
|
469
|
+
date_format: Optional[
|
|
470
|
+
Literal[
|
|
471
|
+
"DATE_FORMAT_MONTH_DAY_ABBREVIATED",
|
|
472
|
+
"DATE_FORMAT_MONTH_DAY_FULL",
|
|
473
|
+
"DATE_FORMAT_MONTH_DAY_YEAR_ABBREVIATED",
|
|
474
|
+
"DATE_FORMAT_ISO8601",
|
|
475
|
+
]
|
|
476
|
+
] = Field(
|
|
477
|
+
default=None,
|
|
478
|
+
description="Defaults to DATE_FORMAT_MONTH_DAY_YEAR_ABBREVIATED.",
|
|
479
|
+
)
|
|
480
|
+
time_format: Optional[
|
|
481
|
+
Literal[
|
|
482
|
+
"TIME_FORMAT_DISABLED",
|
|
483
|
+
"TIME_FORMAT_HOUR_MINUTE",
|
|
484
|
+
"TIME_FORMAT_HOUR_MINUTE_TIMEZONE",
|
|
485
|
+
]
|
|
486
|
+
] = Field(default=None, description="Omit to show no time.")
|
|
487
|
+
timezone: Optional[str] = Field(
|
|
488
|
+
default=None,
|
|
489
|
+
description="IANA time zone ID shown on the chip. Requires time_format TIME_FORMAT_HOUR_MINUTE_TIMEZONE.",
|
|
490
|
+
)
|
|
491
|
+
|
|
492
|
+
@field_validator("date")
|
|
493
|
+
@classmethod
|
|
494
|
+
def _validate_date(cls, value: str) -> str:
|
|
495
|
+
"""Accept YYYY-MM-DD or an ISO 8601 timestamp that carries a time zone."""
|
|
496
|
+
try:
|
|
497
|
+
if len(value) == 10:
|
|
498
|
+
datetime.strptime(value, "%Y-%m-%d")
|
|
499
|
+
else:
|
|
500
|
+
parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
501
|
+
if "T" not in value or parsed.tzinfo is None:
|
|
502
|
+
raise ValueError(value)
|
|
503
|
+
except ValueError as exc:
|
|
504
|
+
raise ValueError(
|
|
505
|
+
"date must be YYYY-MM-DD or an ISO 8601 timestamp with a time zone, "
|
|
506
|
+
"e.g. 2026-11-03T09:30:00Z"
|
|
507
|
+
) from exc
|
|
508
|
+
return value
|
|
509
|
+
|
|
510
|
+
@field_validator("timezone")
|
|
511
|
+
@classmethod
|
|
512
|
+
def _validate_timezone(cls, value: Optional[str]) -> Optional[str]:
|
|
513
|
+
"""Reject names the IANA time zone database does not know."""
|
|
514
|
+
if value is not None and value not in _IANA_TIME_ZONES:
|
|
515
|
+
raise ValueError(f"unknown IANA time zone: {value}")
|
|
516
|
+
return value
|
|
517
|
+
|
|
518
|
+
@model_validator(mode="after")
|
|
519
|
+
def validate_timezone_format(self) -> "InsertDateOperation":
|
|
520
|
+
if self.timezone and self.time_format != "TIME_FORMAT_HOUR_MINUTE_TIMEZONE":
|
|
521
|
+
raise ValueError(
|
|
522
|
+
"timezone requires time_format TIME_FORMAT_HOUR_MINUTE_TIMEZONE."
|
|
523
|
+
)
|
|
524
|
+
return self
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
class InsertDocTabOperation(BaseModel):
|
|
528
|
+
model_config = ConfigDict(extra="forbid")
|
|
529
|
+
|
|
530
|
+
type: Literal["insert_doc_tab"]
|
|
531
|
+
title: str
|
|
532
|
+
index: int
|
|
533
|
+
parent_tab_id: Optional[str] = None
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
class DeleteDocTabOperation(BaseModel):
|
|
537
|
+
model_config = ConfigDict(extra="forbid")
|
|
538
|
+
|
|
539
|
+
type: Literal["delete_doc_tab"]
|
|
540
|
+
tab_id: str
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
class UpdateDocTabOperation(BaseModel):
|
|
544
|
+
model_config = ConfigDict(extra="forbid")
|
|
545
|
+
|
|
546
|
+
type: Literal["update_doc_tab"]
|
|
547
|
+
tab_id: str
|
|
548
|
+
title: str
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
BatchDocOperation = Annotated[
|
|
552
|
+
Union[
|
|
553
|
+
InsertTextOperation,
|
|
554
|
+
DeleteTextOperation,
|
|
555
|
+
ReplaceTextOperation,
|
|
556
|
+
FormatTextOperation,
|
|
557
|
+
UpdateParagraphStyleOperation,
|
|
558
|
+
UpdateTableCellStyleOperation,
|
|
559
|
+
InsertTableOperation,
|
|
560
|
+
InsertTableRowOperation,
|
|
561
|
+
DeleteTableRowOperation,
|
|
562
|
+
InsertTableColumnOperation,
|
|
563
|
+
DeleteTableColumnOperation,
|
|
564
|
+
MergeTableCellsOperation,
|
|
565
|
+
UnmergeTableCellsOperation,
|
|
566
|
+
UpdateTableColumnPropertiesOperation,
|
|
567
|
+
UpdateTableRowStyleOperation,
|
|
568
|
+
PinTableHeaderRowsOperation,
|
|
569
|
+
InsertPageBreakOperation,
|
|
570
|
+
InsertSectionBreakOperation,
|
|
571
|
+
FindReplaceOperation,
|
|
572
|
+
CreateBulletListOperation,
|
|
573
|
+
CreateNamedRangeOperation,
|
|
574
|
+
ReplaceNamedRangeContentOperation,
|
|
575
|
+
DeleteNamedRangeOperation,
|
|
576
|
+
UpdateDocumentStyleOperation,
|
|
577
|
+
UpdateSectionStyleOperation,
|
|
578
|
+
CreateHeaderFooterOperation,
|
|
579
|
+
InsertImageOperation,
|
|
580
|
+
InsertPersonOperation,
|
|
581
|
+
InsertDateOperation,
|
|
582
|
+
CreateDropdownDefinitionOperation,
|
|
583
|
+
InsertDropdownOperation,
|
|
584
|
+
InsertDocTabOperation,
|
|
585
|
+
DeleteDocTabOperation,
|
|
586
|
+
UpdateDocTabOperation,
|
|
587
|
+
],
|
|
588
|
+
Field(discriminator="type"),
|
|
589
|
+
]
|
|
590
|
+
|
|
591
|
+
BatchDocOperations = Annotated[
|
|
592
|
+
list[BatchDocOperation],
|
|
593
|
+
BeforeValidator(_coerce_json_str_to_list),
|
|
594
|
+
]
|
|
File without changes
|