@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,392 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Google Slides Helper Functions
|
|
3
|
+
|
|
4
|
+
Shared utilities for Google Slides operations.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import asyncio
|
|
8
|
+
import difflib
|
|
9
|
+
import json
|
|
10
|
+
from typing import Any, Dict, List, Optional, Set, Tuple
|
|
11
|
+
|
|
12
|
+
from core.utils import UserInputError
|
|
13
|
+
from gslides.slides_digest import format_deck, format_layouts, format_page
|
|
14
|
+
from gslides.slides_markup import iter_elements, project_page
|
|
15
|
+
|
|
16
|
+
_PRESENTATION_PAGE_ID_FIELDS = (
|
|
17
|
+
"slides(objectId,slideProperties(notesPage(objectId,"
|
|
18
|
+
"notesProperties(speakerNotesObjectId)))),"
|
|
19
|
+
"masters(objectId),layouts(objectId),notesMaster(objectId)"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
_SLIDES_BATCH_REQUEST_TYPES = frozenset(
|
|
23
|
+
{
|
|
24
|
+
"createSlide",
|
|
25
|
+
"createShape",
|
|
26
|
+
"createTable",
|
|
27
|
+
"insertText",
|
|
28
|
+
"insertTableRows",
|
|
29
|
+
"insertTableColumns",
|
|
30
|
+
"deleteTableRow",
|
|
31
|
+
"deleteTableColumn",
|
|
32
|
+
"replaceAllText",
|
|
33
|
+
"deleteObject",
|
|
34
|
+
"updatePageElementTransform",
|
|
35
|
+
"updateSlidesPosition",
|
|
36
|
+
"deleteText",
|
|
37
|
+
"createImage",
|
|
38
|
+
"createVideo",
|
|
39
|
+
"createSheetsChart",
|
|
40
|
+
"createLine",
|
|
41
|
+
"refreshSheetsChart",
|
|
42
|
+
"updateShapeProperties",
|
|
43
|
+
"updateImageProperties",
|
|
44
|
+
"updateVideoProperties",
|
|
45
|
+
"updatePageProperties",
|
|
46
|
+
"updateTableCellProperties",
|
|
47
|
+
"updateLineProperties",
|
|
48
|
+
"createParagraphBullets",
|
|
49
|
+
"replaceAllShapesWithImage",
|
|
50
|
+
"duplicateObject",
|
|
51
|
+
"updateTextStyle",
|
|
52
|
+
"replaceAllShapesWithSheetsChart",
|
|
53
|
+
"deleteParagraphBullets",
|
|
54
|
+
"updateParagraphStyle",
|
|
55
|
+
"updateTableBorderProperties",
|
|
56
|
+
"updateTableColumnProperties",
|
|
57
|
+
"updateTableRowProperties",
|
|
58
|
+
"mergeTableCells",
|
|
59
|
+
"unmergeTableCells",
|
|
60
|
+
"groupObjects",
|
|
61
|
+
"ungroupObjects",
|
|
62
|
+
"updatePageElementAltText",
|
|
63
|
+
"replaceImage",
|
|
64
|
+
"updateSlideProperties",
|
|
65
|
+
"updatePageElementsZOrder",
|
|
66
|
+
"updateLineCategory",
|
|
67
|
+
"rerouteLine",
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
_SLIDES_BATCH_REQUEST_EXAMPLES = (
|
|
72
|
+
"createSlide",
|
|
73
|
+
"createShape",
|
|
74
|
+
"insertText",
|
|
75
|
+
"updateTextStyle",
|
|
76
|
+
"createImage",
|
|
77
|
+
"deleteObject",
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# getThumbnail thumbnailSize values and the pixel width each renders at.
|
|
82
|
+
PAGE_IMAGE_WIDTHS = {
|
|
83
|
+
"SMALL": 200,
|
|
84
|
+
"MEDIUM": 800,
|
|
85
|
+
"LARGE": 1600,
|
|
86
|
+
"WIDTH2000_PX": 2000,
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def validate_page_image_size(size: str) -> int:
|
|
91
|
+
"""Check a render size against the API's values and return its pixel width."""
|
|
92
|
+
width = PAGE_IMAGE_WIDTHS.get(size)
|
|
93
|
+
if width is None:
|
|
94
|
+
valid = ", ".join(
|
|
95
|
+
f"{name} ({px}px wide)" for name, px in PAGE_IMAGE_WIDTHS.items()
|
|
96
|
+
)
|
|
97
|
+
raise UserInputError(f"Invalid size '{size}'. Use one of: {valid}.")
|
|
98
|
+
return width
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _slides_batch_request_guidance() -> str:
|
|
102
|
+
examples = ", ".join(_SLIDES_BATCH_REQUEST_EXAMPLES)
|
|
103
|
+
return f"exactly one Slides request type such as {examples}"
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def validate_batch_update_requests(requests: List[Dict[str, Any]]) -> None:
|
|
107
|
+
guidance = _slides_batch_request_guidance()
|
|
108
|
+
if not requests:
|
|
109
|
+
raise UserInputError(
|
|
110
|
+
"Invalid Slides batch update request: requests must contain at least "
|
|
111
|
+
f"one request object with {guidance}."
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
for index, request in enumerate(requests):
|
|
115
|
+
if not isinstance(request, dict):
|
|
116
|
+
raise UserInputError(
|
|
117
|
+
"Invalid Slides batch update request: "
|
|
118
|
+
f"requests[{index}] must be an object containing {guidance}."
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
request_types = list(request)
|
|
122
|
+
if len(request_types) != 1:
|
|
123
|
+
if not request_types:
|
|
124
|
+
problem = "is empty"
|
|
125
|
+
else:
|
|
126
|
+
problem = f"contains multiple fields ({', '.join(request_types)})"
|
|
127
|
+
raise UserInputError(
|
|
128
|
+
"Invalid Slides batch update request: "
|
|
129
|
+
f"requests[{index}] {problem}; it must contain {guidance}."
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
request_type = request_types[0]
|
|
133
|
+
if request_type not in _SLIDES_BATCH_REQUEST_TYPES:
|
|
134
|
+
raise UserInputError(
|
|
135
|
+
"Invalid Slides batch update request: "
|
|
136
|
+
f"requests[{index}] has unsupported request type '{request_type}'. "
|
|
137
|
+
f"It must contain {guidance}."
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
if not isinstance(request[request_type], dict):
|
|
141
|
+
raise UserInputError(
|
|
142
|
+
"Invalid Slides batch update request: "
|
|
143
|
+
f"requests[{index}].{request_type} must be an object for {guidance}."
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _get_request_payload(request: Dict[str, Any], request_type: str) -> Dict[str, Any]:
|
|
148
|
+
payload = request.get(request_type)
|
|
149
|
+
return payload if isinstance(payload, dict) else {}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _find_insert_text_targets(
|
|
153
|
+
requests: List[Dict[str, Any]],
|
|
154
|
+
) -> List[Tuple[int, str]]:
|
|
155
|
+
targets = []
|
|
156
|
+
for index, request in enumerate(requests):
|
|
157
|
+
if not isinstance(request, dict):
|
|
158
|
+
continue
|
|
159
|
+
object_id = _get_request_payload(request, "insertText").get("objectId")
|
|
160
|
+
if isinstance(object_id, str) and object_id:
|
|
161
|
+
targets.append((index, object_id))
|
|
162
|
+
return targets
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _find_created_slide_ids(requests: List[Dict[str, Any]]) -> Set[str]:
|
|
166
|
+
slide_ids = set()
|
|
167
|
+
for request in requests:
|
|
168
|
+
if not isinstance(request, dict):
|
|
169
|
+
continue
|
|
170
|
+
object_id = _get_request_payload(request, "createSlide").get("objectId")
|
|
171
|
+
if isinstance(object_id, str) and object_id:
|
|
172
|
+
slide_ids.add(object_id)
|
|
173
|
+
return slide_ids
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
async def _get_presentation_page_ids(
|
|
177
|
+
service, presentation_id: str
|
|
178
|
+
) -> Tuple[Set[str], Dict[str, str]]:
|
|
179
|
+
"""Return every page object ID plus a notes page ID -> speaker notes shape ID map.
|
|
180
|
+
|
|
181
|
+
The speaker notes shape is the only writable part of a notes page, so the map
|
|
182
|
+
lets an insertText aimed at a notes page be redirected to the shape that can
|
|
183
|
+
actually hold the text. See https://developers.google.com/slides/api/guides/notes
|
|
184
|
+
"""
|
|
185
|
+
result = await asyncio.to_thread(
|
|
186
|
+
service.presentations()
|
|
187
|
+
.get(
|
|
188
|
+
presentationId=presentation_id,
|
|
189
|
+
fields=_PRESENTATION_PAGE_ID_FIELDS,
|
|
190
|
+
)
|
|
191
|
+
.execute
|
|
192
|
+
)
|
|
193
|
+
page_ids = {
|
|
194
|
+
page["objectId"]
|
|
195
|
+
for page_type in ("slides", "masters", "layouts")
|
|
196
|
+
for page in result.get(page_type, [])
|
|
197
|
+
if isinstance(page.get("objectId"), str)
|
|
198
|
+
}
|
|
199
|
+
speaker_notes_shapes: Dict[str, str] = {}
|
|
200
|
+
for slide in result.get("slides", []):
|
|
201
|
+
notes_page = slide.get("slideProperties", {}).get("notesPage", {})
|
|
202
|
+
notes_id = notes_page.get("objectId")
|
|
203
|
+
if not isinstance(notes_id, str):
|
|
204
|
+
continue
|
|
205
|
+
page_ids.add(notes_id)
|
|
206
|
+
shape_id = notes_page.get("notesProperties", {}).get("speakerNotesObjectId")
|
|
207
|
+
if isinstance(shape_id, str) and shape_id:
|
|
208
|
+
speaker_notes_shapes[notes_id] = shape_id
|
|
209
|
+
notes_master = result.get("notesMaster")
|
|
210
|
+
if isinstance(notes_master, dict) and isinstance(notes_master.get("objectId"), str):
|
|
211
|
+
page_ids.add(notes_master["objectId"])
|
|
212
|
+
return page_ids, speaker_notes_shapes
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
async def validate_insert_text_targets(
|
|
216
|
+
service, presentation_id: str, requests: List[Dict[str, Any]]
|
|
217
|
+
) -> None:
|
|
218
|
+
insert_text_targets = _find_insert_text_targets(requests)
|
|
219
|
+
if not insert_text_targets:
|
|
220
|
+
return
|
|
221
|
+
|
|
222
|
+
page_ids = _find_created_slide_ids(requests)
|
|
223
|
+
presentation_page_ids, speaker_notes_shapes = await _get_presentation_page_ids(
|
|
224
|
+
service, presentation_id
|
|
225
|
+
)
|
|
226
|
+
page_ids.update(presentation_page_ids)
|
|
227
|
+
|
|
228
|
+
invalid_targets = [
|
|
229
|
+
(index, object_id)
|
|
230
|
+
for index, object_id in insert_text_targets
|
|
231
|
+
if object_id in page_ids
|
|
232
|
+
]
|
|
233
|
+
if not invalid_targets:
|
|
234
|
+
return
|
|
235
|
+
|
|
236
|
+
problems = []
|
|
237
|
+
has_non_notes_target = False
|
|
238
|
+
for index, object_id in invalid_targets:
|
|
239
|
+
ref = f"requests[{index}].insertText.objectId='{object_id}'"
|
|
240
|
+
shape_id = speaker_notes_shapes.get(object_id)
|
|
241
|
+
if shape_id:
|
|
242
|
+
problems.append(
|
|
243
|
+
f"{ref} targets a notes page. Speaker notes text lives in the notes "
|
|
244
|
+
f"shape on that page, so use objectId '{shape_id}' instead."
|
|
245
|
+
)
|
|
246
|
+
else:
|
|
247
|
+
has_non_notes_target = True
|
|
248
|
+
problems.append(f"{ref} targets a slide/page object.")
|
|
249
|
+
|
|
250
|
+
message = "Invalid Slides batch update request: " + " ".join(problems)
|
|
251
|
+
if has_non_notes_target:
|
|
252
|
+
message += (
|
|
253
|
+
" The Slides API only allows insertText on text-capable shapes or table "
|
|
254
|
+
"cells. Create a text box or shape first with createShape, set "
|
|
255
|
+
"elementProperties.pageObjectId to the slide ID, then insertText into "
|
|
256
|
+
'the new shape objectId. For existing content, call get_presentation with action="page" and use a '
|
|
257
|
+
"Shape or Table element ID, not the Page ID."
|
|
258
|
+
)
|
|
259
|
+
raise UserInputError(message)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
# --- get_presentation actions --------------------------------------------------
|
|
263
|
+
|
|
264
|
+
GET_PRESENTATION_ACTIONS = ("deck", "layouts", "page", "markup")
|
|
265
|
+
|
|
266
|
+
# What the page digest needs from the deck to say what the layout and master
|
|
267
|
+
# draw: their non-placeholder elements.
|
|
268
|
+
_PAGE_CONTEXT_FIELDS = (
|
|
269
|
+
"layouts(objectId,pageElements(objectId,shape(placeholder))),"
|
|
270
|
+
"masters(objectId,pageElements(objectId,shape(placeholder)))"
|
|
271
|
+
)
|
|
272
|
+
_LAYOUTS_FIELDS = (
|
|
273
|
+
"slides(objectId,slideProperties(layoutObjectId,masterObjectId)),"
|
|
274
|
+
"layouts(objectId,layoutProperties,pageElements(objectId,shape(placeholder))),"
|
|
275
|
+
"masters(objectId,masterProperties)"
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _check_targets(page: Dict[str, Any], targets: List[str]) -> None:
|
|
280
|
+
"""Refuse a target that is not on the page, naming the closest IDs."""
|
|
281
|
+
present = {
|
|
282
|
+
el.get("objectId") for el, _ in iter_elements(page.get("pageElements", []))
|
|
283
|
+
}
|
|
284
|
+
missing = [t for t in targets if t != "notes" and t not in present]
|
|
285
|
+
if not missing:
|
|
286
|
+
return
|
|
287
|
+
hints = []
|
|
288
|
+
for target in missing:
|
|
289
|
+
close = difflib.get_close_matches(target, sorted(present), n=3, cutoff=0.6)
|
|
290
|
+
hints.append(
|
|
291
|
+
f"'{target}'" + (f" (did you mean {', '.join(close)}?)" if close else "")
|
|
292
|
+
)
|
|
293
|
+
raise UserInputError(
|
|
294
|
+
f"Not on page {page.get('objectId')}: {'; '.join(hints)}. "
|
|
295
|
+
'get_presentation(action="page") lists every element ID on the page.'
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def _prune_page(page: Dict[str, Any], targets: List[str]) -> Dict[str, Any]:
|
|
300
|
+
"""The raw Page resource with pageElements limited to ``targets``.
|
|
301
|
+
|
|
302
|
+
A target inside a group is returned on its own, with its transform still
|
|
303
|
+
relative to the group; a target that is a group keeps its descendants.
|
|
304
|
+
Speaker notes are kept only when "notes" is a target.
|
|
305
|
+
"""
|
|
306
|
+
wanted = set(targets)
|
|
307
|
+
pruned = {k: v for k, v in page.items() if k != "pageElements"}
|
|
308
|
+
pruned["pageElements"] = [
|
|
309
|
+
el
|
|
310
|
+
for el, ancestors in iter_elements(page.get("pageElements", []))
|
|
311
|
+
if el.get("objectId") in wanted
|
|
312
|
+
and not any(group.get("objectId") in wanted for group in ancestors)
|
|
313
|
+
]
|
|
314
|
+
if "notes" not in wanted and "slideProperties" in pruned:
|
|
315
|
+
pruned["slideProperties"] = {
|
|
316
|
+
k: v for k, v in pruned["slideProperties"].items() if k != "notesPage"
|
|
317
|
+
}
|
|
318
|
+
return pruned
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
async def read_presentation(
|
|
322
|
+
service: Any,
|
|
323
|
+
presentation_id: str,
|
|
324
|
+
action: str = "deck",
|
|
325
|
+
page_id: Optional[str] = None,
|
|
326
|
+
targets: Optional[List[str]] = None,
|
|
327
|
+
raw: bool = False,
|
|
328
|
+
offset: int = 0,
|
|
329
|
+
after: Optional[str] = None,
|
|
330
|
+
) -> str:
|
|
331
|
+
"""Run one get_presentation action and return its text."""
|
|
332
|
+
action = (action or "deck").lower().strip()
|
|
333
|
+
if action not in GET_PRESENTATION_ACTIONS:
|
|
334
|
+
raise UserInputError(
|
|
335
|
+
f"Invalid action '{action}'. Must be one of: "
|
|
336
|
+
+ ", ".join(f'"{a}"' for a in GET_PRESENTATION_ACTIONS)
|
|
337
|
+
+ "."
|
|
338
|
+
)
|
|
339
|
+
presentations = service.presentations()
|
|
340
|
+
|
|
341
|
+
if action == "deck":
|
|
342
|
+
if offset < 0:
|
|
343
|
+
raise UserInputError(f"offset must be >= 0, got {offset}.")
|
|
344
|
+
pres = await asyncio.to_thread(
|
|
345
|
+
presentations.get(presentationId=presentation_id).execute
|
|
346
|
+
)
|
|
347
|
+
return format_deck(pres, offset=offset)
|
|
348
|
+
|
|
349
|
+
if action == "layouts":
|
|
350
|
+
pres = await asyncio.to_thread(
|
|
351
|
+
presentations.get(
|
|
352
|
+
presentationId=presentation_id, fields=_LAYOUTS_FIELDS
|
|
353
|
+
).execute
|
|
354
|
+
)
|
|
355
|
+
if after not in (None, "start") and after not in {
|
|
356
|
+
s.get("objectId") for s in pres.get("slides", [])
|
|
357
|
+
}:
|
|
358
|
+
raise UserInputError(
|
|
359
|
+
f"after='{after}' is not a slide in this presentation. Pass a "
|
|
360
|
+
'slide ID from get_presentation(action="deck"), or "start".'
|
|
361
|
+
)
|
|
362
|
+
lines = format_layouts(pres, after=after)
|
|
363
|
+
return "\n".join(lines) if lines else "No layouts found."
|
|
364
|
+
|
|
365
|
+
if not page_id:
|
|
366
|
+
raise UserInputError(f"page_id is required for the '{action}' action.")
|
|
367
|
+
|
|
368
|
+
# One request at a time: a service's httplib2 connection is not
|
|
369
|
+
# thread-safe, so concurrent to_thread calls on it fail with SSL errors.
|
|
370
|
+
page = await asyncio.to_thread(
|
|
371
|
+
presentations.pages()
|
|
372
|
+
.get(presentationId=presentation_id, pageObjectId=page_id)
|
|
373
|
+
.execute
|
|
374
|
+
)
|
|
375
|
+
if action == "page":
|
|
376
|
+
context = await asyncio.to_thread(
|
|
377
|
+
presentations.get(
|
|
378
|
+
presentationId=presentation_id, fields=_PAGE_CONTEXT_FIELDS
|
|
379
|
+
).execute
|
|
380
|
+
)
|
|
381
|
+
return format_page(page, pres=context)
|
|
382
|
+
|
|
383
|
+
if targets:
|
|
384
|
+
_check_targets(page, targets)
|
|
385
|
+
if raw:
|
|
386
|
+
body = _prune_page(page, targets) if targets else page
|
|
387
|
+
return json.dumps(body, ensure_ascii=False, separators=(",", ":"))
|
|
388
|
+
meta = await asyncio.to_thread(
|
|
389
|
+
presentations.get(presentationId=presentation_id, fields="pageSize").execute
|
|
390
|
+
)
|
|
391
|
+
projection = project_page(page, meta.get("pageSize"), targets=targets or None)
|
|
392
|
+
return json.dumps(projection, ensure_ascii=False, separators=(",", ":"))
|