render-lab-tasks-gcal 0.1.0__py3-none-any.whl
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.
- render_lab_tasks_gcal/__init__.py +1 -0
- render_lab_tasks_gcal/_app.py +3 -0
- render_lab_tasks_gcal/client.py +199 -0
- render_lab_tasks_gcal/create_event.py +18 -0
- render_lab_tasks_gcal/delete_event.py +18 -0
- render_lab_tasks_gcal/find_free_busy.py +18 -0
- render_lab_tasks_gcal/get_event.py +18 -0
- render_lab_tasks_gcal/list_events.py +18 -0
- render_lab_tasks_gcal/py.typed +0 -0
- render_lab_tasks_gcal/quick_add.py +18 -0
- render_lab_tasks_gcal/respond.py +18 -0
- render_lab_tasks_gcal/retry.py +3 -0
- render_lab_tasks_gcal/suggest_time.py +18 -0
- render_lab_tasks_gcal/tasks.py +32 -0
- render_lab_tasks_gcal/types.py +106 -0
- render_lab_tasks_gcal/update_event.py +18 -0
- render_lab_tasks_gcal-0.1.0.dist-info/METADATA +75 -0
- render_lab_tasks_gcal-0.1.0.dist-info/RECORD +20 -0
- render_lab_tasks_gcal-0.1.0.dist-info/WHEEL +4 -0
- render_lab_tasks_gcal-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Import .tasks explicitly to register durable tasks."""
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""Injected vendor interface and one-attempt async HTTP adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from collections.abc import AsyncIterator, Callable, Mapping
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from datetime import UTC, datetime, timedelta
|
|
10
|
+
from typing import Any, Protocol, cast
|
|
11
|
+
|
|
12
|
+
import httpx
|
|
13
|
+
from render_lab_tasks_core.google_auth import GoogleAccessToken
|
|
14
|
+
from render_lab_tasks_core.http import HttpClient, enc, nullish, pick, query
|
|
15
|
+
|
|
16
|
+
from . import types as t
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def iso(value: datetime) -> str:
|
|
20
|
+
return value.isoformat(timespec="milliseconds").replace("+00:00", "Z")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def parse_date(value: str) -> datetime:
|
|
24
|
+
parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
25
|
+
return parsed if parsed.tzinfo else parsed.replace(tzinfo=UTC)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def event(row: Any) -> t.CalEvent:
|
|
29
|
+
return {
|
|
30
|
+
"id": row.get("id", ""),
|
|
31
|
+
"summary": nullish(row.get("summary"), ""),
|
|
32
|
+
"start": row.get("start", {}).get("dateTime", row.get("start", {}).get("date", "")),
|
|
33
|
+
"end": row.get("end", {}).get("dateTime", row.get("end", {}).get("date", "")),
|
|
34
|
+
"htmlLink": nullish(row.get("htmlLink"), ""),
|
|
35
|
+
"attendees": [a["email"] for a in row.get("attendees", []) if a.get("email")],
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def event_body(input: Mapping[str, Any]) -> dict[str, Any]:
|
|
40
|
+
body = pick(input, "summary", "description")
|
|
41
|
+
for key in ("start", "end"):
|
|
42
|
+
if key in input:
|
|
43
|
+
body[key] = {"dateTime": input[key]}
|
|
44
|
+
if "attendees" in input:
|
|
45
|
+
body["attendees"] = [{"email": address} for address in input["attendees"]]
|
|
46
|
+
return body
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Port(Protocol):
|
|
50
|
+
async def create_event(self, input: t.CreateEventInput) -> t.CalEvent: ...
|
|
51
|
+
async def delete_event(self, input: t.DeleteEventInput) -> t.DeleteEventResult: ...
|
|
52
|
+
async def find_free_busy(self, input: t.FindFreeBusyInput) -> list[t.FreeBusyCalendar]: ...
|
|
53
|
+
async def get_event(self, input: t.GetEventInput) -> t.CalEvent: ...
|
|
54
|
+
async def list_events(self, input: t.ListEventsInput) -> list[t.CalEvent]: ...
|
|
55
|
+
async def quick_add(self, input: t.QuickAddInput) -> t.CalEvent: ...
|
|
56
|
+
async def respond(self, input: t.RespondInput) -> t.RespondResult: ...
|
|
57
|
+
async def suggest_time(self, input: t.SuggestTimeInput) -> t.SuggestTimeResult: ...
|
|
58
|
+
async def update_event(self, input: t.UpdateEventInput) -> t.CalEvent: ...
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(frozen=True)
|
|
62
|
+
class Deps:
|
|
63
|
+
gcal: Port
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class Client:
|
|
67
|
+
def __init__(self, http: httpx.AsyncClient, env: Mapping[str, str] | None = None) -> None:
|
|
68
|
+
self.env = os.environ if env is None else env
|
|
69
|
+
self.auth = GoogleAccessToken(http, self.env)
|
|
70
|
+
self.api = HttpClient(
|
|
71
|
+
http,
|
|
72
|
+
"https://www.googleapis.com/calendar/v3",
|
|
73
|
+
auth=self.auth.headers,
|
|
74
|
+
label="Google Calendar",
|
|
75
|
+
)
|
|
76
|
+
self.now: Callable[[], datetime] = lambda: datetime.now(UTC)
|
|
77
|
+
|
|
78
|
+
def _calendar(self, input: Mapping[str, Any]) -> str:
|
|
79
|
+
return "/calendars/" + enc(
|
|
80
|
+
input.get("calendarId", self.env.get("GCAL_CALENDAR_ID", "primary"))
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
async def list_events(self, input: t.ListEventsInput) -> list[t.CalEvent]:
|
|
84
|
+
params: dict[str, Any] = {"singleEvents": "true", "orderBy": "startTime"}
|
|
85
|
+
params.update(pick(input, "timeMin", "timeMax"))
|
|
86
|
+
if "limit" in input:
|
|
87
|
+
params["maxResults"] = input["limit"]
|
|
88
|
+
data = await self.api.call(self._calendar(input) + "/events?" + query(params))
|
|
89
|
+
return [event(row) for row in data.get("items", [])]
|
|
90
|
+
|
|
91
|
+
async def get_event(self, input: t.GetEventInput) -> t.CalEvent:
|
|
92
|
+
return event(
|
|
93
|
+
await self.api.call(self._calendar(input) + "/events/" + enc(input["eventId"]))
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
async def create_event(self, input: t.CreateEventInput) -> t.CalEvent:
|
|
97
|
+
body = event_body(input)
|
|
98
|
+
body.setdefault("attendees", [])
|
|
99
|
+
return event(
|
|
100
|
+
await self.api.call(self._calendar(input) + "/events", method="POST", body=body)
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
async def update_event(self, input: t.UpdateEventInput) -> t.CalEvent:
|
|
104
|
+
return event(
|
|
105
|
+
await self.api.call(
|
|
106
|
+
self._calendar(input) + "/events/" + enc(input["eventId"]),
|
|
107
|
+
method="PATCH",
|
|
108
|
+
body=event_body(input),
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
async def delete_event(self, input: t.DeleteEventInput) -> t.DeleteEventResult:
|
|
113
|
+
await self.api.call(
|
|
114
|
+
self._calendar(input) + "/events/" + enc(input["eventId"]),
|
|
115
|
+
method="DELETE",
|
|
116
|
+
response_type="text",
|
|
117
|
+
)
|
|
118
|
+
return {"eventId": input["eventId"], "deleted": True}
|
|
119
|
+
|
|
120
|
+
async def respond(self, input: t.RespondInput) -> t.RespondResult:
|
|
121
|
+
await self.api.call(
|
|
122
|
+
self._calendar(input) + "/events/" + enc(input["eventId"]) + "?sendUpdates=all",
|
|
123
|
+
method="PATCH",
|
|
124
|
+
body={"attendees": [{"self": True, "responseStatus": input["response"]}]},
|
|
125
|
+
)
|
|
126
|
+
return {"eventId": input["eventId"], "response": input["response"]}
|
|
127
|
+
|
|
128
|
+
async def quick_add(self, input: t.QuickAddInput) -> t.CalEvent:
|
|
129
|
+
return event(
|
|
130
|
+
await self.api.call(
|
|
131
|
+
self._calendar(input) + "/events/quickAdd?" + query({"text": input["text"]}),
|
|
132
|
+
method="POST",
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
async def find_free_busy(self, input: t.FindFreeBusyInput) -> list[t.FreeBusyCalendar]:
|
|
137
|
+
ids = input.get("calendarIds") or [self.env.get("GCAL_CALENDAR_ID", "primary")]
|
|
138
|
+
data = await self.api.call(
|
|
139
|
+
"/freeBusy",
|
|
140
|
+
method="POST",
|
|
141
|
+
body={
|
|
142
|
+
"timeMin": input["timeMin"],
|
|
143
|
+
"timeMax": input["timeMax"],
|
|
144
|
+
"items": [{"id": id} for id in ids],
|
|
145
|
+
},
|
|
146
|
+
)
|
|
147
|
+
return [
|
|
148
|
+
{
|
|
149
|
+
"calendarId": id,
|
|
150
|
+
"busy": [
|
|
151
|
+
{"start": nullish(b.get("start"), ""), "end": nullish(b.get("end"), "")}
|
|
152
|
+
for b in cal.get("busy", [])
|
|
153
|
+
],
|
|
154
|
+
}
|
|
155
|
+
for id, cal in data.get("calendars", {}).items()
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
async def suggest_time(self, input: t.SuggestTimeInput) -> t.SuggestTimeResult:
|
|
159
|
+
start = self.now()
|
|
160
|
+
until = start + timedelta(days=input.get("withinDays", 7))
|
|
161
|
+
events = await self.list_events(
|
|
162
|
+
cast(
|
|
163
|
+
t.ListEventsInput,
|
|
164
|
+
{
|
|
165
|
+
**pick(input, "calendarId"),
|
|
166
|
+
"timeMin": iso(start),
|
|
167
|
+
"timeMax": iso(until),
|
|
168
|
+
"limit": 250,
|
|
169
|
+
},
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
duration = timedelta(minutes=input["durationMinutes"])
|
|
173
|
+
cursor = start
|
|
174
|
+
for row in sorted(events, key=lambda e: parse_date(e["start"])):
|
|
175
|
+
left, right = parse_date(row["start"]), parse_date(row["end"])
|
|
176
|
+
if right <= cursor or left >= until:
|
|
177
|
+
continue
|
|
178
|
+
if left - cursor >= duration:
|
|
179
|
+
return {"start": iso(cursor), "end": iso(cursor + duration)}
|
|
180
|
+
cursor = max(cursor, right)
|
|
181
|
+
if cursor + duration <= until:
|
|
182
|
+
return {"start": iso(cursor), "end": iso(cursor + duration)}
|
|
183
|
+
raise RuntimeError("No free slot found in the requested window")
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
@asynccontextmanager
|
|
187
|
+
async def dependencies(deps: Deps | None) -> AsyncIterator[Deps]:
|
|
188
|
+
if deps is not None:
|
|
189
|
+
yield deps
|
|
190
|
+
else:
|
|
191
|
+
async with httpx.AsyncClient(
|
|
192
|
+
timeout=30, transport=httpx.AsyncHTTPTransport(retries=0)
|
|
193
|
+
) as http:
|
|
194
|
+
yield Deps(gcal=Client(http))
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
GcalPort = Port
|
|
198
|
+
GcalClient = Client
|
|
199
|
+
GcalDeps = Deps
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GCAL_RETRY
|
|
6
|
+
from .types import CalEvent, CreateEventInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def create_event_impl(
|
|
10
|
+
ctx: TaskContext, input: CreateEventInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CalEvent:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gcal.create_event(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gcal.createEvent", retry=GCAL_RETRY)
|
|
17
|
+
async def create_event(ctx: TaskContext, input: CreateEventInput) -> CalEvent:
|
|
18
|
+
return await create_event_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GCAL_RETRY
|
|
6
|
+
from .types import DeleteEventInput, DeleteEventResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def delete_event_impl(
|
|
10
|
+
ctx: TaskContext, input: DeleteEventInput, *, deps: Deps | None = None
|
|
11
|
+
) -> DeleteEventResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gcal.delete_event(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gcal.deleteEvent", retry=GCAL_RETRY)
|
|
17
|
+
async def delete_event(ctx: TaskContext, input: DeleteEventInput) -> DeleteEventResult:
|
|
18
|
+
return await delete_event_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GCAL_RETRY
|
|
6
|
+
from .types import FindFreeBusyInput, FreeBusyCalendar
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def find_free_busy_impl(
|
|
10
|
+
ctx: TaskContext, input: FindFreeBusyInput, *, deps: Deps | None = None
|
|
11
|
+
) -> list[FreeBusyCalendar]:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gcal.find_free_busy(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gcal.findFreeBusy", retry=GCAL_RETRY)
|
|
17
|
+
async def find_free_busy(ctx: TaskContext, input: FindFreeBusyInput) -> list[FreeBusyCalendar]:
|
|
18
|
+
return await find_free_busy_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GCAL_RETRY
|
|
6
|
+
from .types import CalEvent, GetEventInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_event_impl(
|
|
10
|
+
ctx: TaskContext, input: GetEventInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CalEvent:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gcal.get_event(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gcal.getEvent", retry=GCAL_RETRY)
|
|
17
|
+
async def get_event(ctx: TaskContext, input: GetEventInput) -> CalEvent:
|
|
18
|
+
return await get_event_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GCAL_RETRY
|
|
6
|
+
from .types import CalEvent, ListEventsInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def list_events_impl(
|
|
10
|
+
ctx: TaskContext, input: ListEventsInput, *, deps: Deps | None = None
|
|
11
|
+
) -> list[CalEvent]:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gcal.list_events(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gcal.listEvents", retry=GCAL_RETRY)
|
|
17
|
+
async def list_events(ctx: TaskContext, input: ListEventsInput) -> list[CalEvent]:
|
|
18
|
+
return await list_events_impl(ctx, input)
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GCAL_RETRY
|
|
6
|
+
from .types import CalEvent, QuickAddInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def quick_add_impl(
|
|
10
|
+
ctx: TaskContext, input: QuickAddInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CalEvent:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gcal.quick_add(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gcal.quickAdd", retry=GCAL_RETRY)
|
|
17
|
+
async def quick_add(ctx: TaskContext, input: QuickAddInput) -> CalEvent:
|
|
18
|
+
return await quick_add_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GCAL_RETRY
|
|
6
|
+
from .types import RespondInput, RespondResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def respond_impl(
|
|
10
|
+
ctx: TaskContext, input: RespondInput, *, deps: Deps | None = None
|
|
11
|
+
) -> RespondResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gcal.respond(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gcal.respond", retry=GCAL_RETRY)
|
|
17
|
+
async def respond(ctx: TaskContext, input: RespondInput) -> RespondResult:
|
|
18
|
+
return await respond_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GCAL_RETRY
|
|
6
|
+
from .types import SuggestTimeInput, SuggestTimeResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def suggest_time_impl(
|
|
10
|
+
ctx: TaskContext, input: SuggestTimeInput, *, deps: Deps | None = None
|
|
11
|
+
) -> SuggestTimeResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gcal.suggest_time(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gcal.suggestTime", retry=GCAL_RETRY)
|
|
17
|
+
async def suggest_time(ctx: TaskContext, input: SuggestTimeInput) -> SuggestTimeResult:
|
|
18
|
+
return await suggest_time_impl(ctx, input)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from ._app import app
|
|
2
|
+
from .create_event import create_event, create_event_impl
|
|
3
|
+
from .delete_event import delete_event, delete_event_impl
|
|
4
|
+
from .find_free_busy import find_free_busy, find_free_busy_impl
|
|
5
|
+
from .get_event import get_event, get_event_impl
|
|
6
|
+
from .list_events import list_events, list_events_impl
|
|
7
|
+
from .quick_add import quick_add, quick_add_impl
|
|
8
|
+
from .respond import respond, respond_impl
|
|
9
|
+
from .suggest_time import suggest_time, suggest_time_impl
|
|
10
|
+
from .update_event import update_event, update_event_impl
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"app",
|
|
14
|
+
"create_event",
|
|
15
|
+
"create_event_impl",
|
|
16
|
+
"delete_event",
|
|
17
|
+
"delete_event_impl",
|
|
18
|
+
"find_free_busy",
|
|
19
|
+
"find_free_busy_impl",
|
|
20
|
+
"get_event",
|
|
21
|
+
"get_event_impl",
|
|
22
|
+
"list_events",
|
|
23
|
+
"list_events_impl",
|
|
24
|
+
"quick_add",
|
|
25
|
+
"quick_add_impl",
|
|
26
|
+
"respond",
|
|
27
|
+
"respond_impl",
|
|
28
|
+
"suggest_time",
|
|
29
|
+
"suggest_time_impl",
|
|
30
|
+
"update_event",
|
|
31
|
+
"update_event_impl",
|
|
32
|
+
]
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""JSON contracts ported from the pinned TypeScript pack."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Literal, NotRequired, TypedDict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class CalEvent(TypedDict):
|
|
9
|
+
id: str
|
|
10
|
+
summary: str
|
|
11
|
+
start: str
|
|
12
|
+
end: str
|
|
13
|
+
htmlLink: str
|
|
14
|
+
attendees: list[str]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ListEventsInput(TypedDict):
|
|
18
|
+
calendarId: NotRequired[str]
|
|
19
|
+
timeMin: NotRequired[str]
|
|
20
|
+
timeMax: NotRequired[str]
|
|
21
|
+
limit: NotRequired[float]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CreateEventInput(TypedDict):
|
|
25
|
+
calendarId: NotRequired[str]
|
|
26
|
+
summary: str
|
|
27
|
+
start: str
|
|
28
|
+
end: str
|
|
29
|
+
description: NotRequired[str]
|
|
30
|
+
attendees: NotRequired[list[str]]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class SuggestTimeInput(TypedDict):
|
|
34
|
+
calendarId: NotRequired[str]
|
|
35
|
+
durationMinutes: float
|
|
36
|
+
withinDays: NotRequired[float]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class SuggestTimeResult(TypedDict):
|
|
40
|
+
start: str
|
|
41
|
+
end: str
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class RespondInput(TypedDict):
|
|
45
|
+
calendarId: NotRequired[str]
|
|
46
|
+
eventId: str
|
|
47
|
+
response: Literal["accepted"] | Literal["declined"] | Literal["tentative"]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class RespondResult(TypedDict):
|
|
51
|
+
eventId: str
|
|
52
|
+
response: str
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class GetEventInput(TypedDict):
|
|
56
|
+
calendarId: NotRequired[str]
|
|
57
|
+
eventId: str
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class UpdateEventInput(TypedDict):
|
|
61
|
+
calendarId: NotRequired[str]
|
|
62
|
+
eventId: str
|
|
63
|
+
summary: NotRequired[str]
|
|
64
|
+
start: NotRequired[str]
|
|
65
|
+
end: NotRequired[str]
|
|
66
|
+
description: NotRequired[str]
|
|
67
|
+
attendees: NotRequired[list[str]]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class EventPatch(TypedDict):
|
|
71
|
+
summary: NotRequired[str]
|
|
72
|
+
start: NotRequired[str]
|
|
73
|
+
end: NotRequired[str]
|
|
74
|
+
description: NotRequired[str]
|
|
75
|
+
attendees: NotRequired[list[str]]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class DeleteEventInput(TypedDict):
|
|
79
|
+
calendarId: NotRequired[str]
|
|
80
|
+
eventId: str
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class DeleteEventResult(TypedDict):
|
|
84
|
+
eventId: str
|
|
85
|
+
deleted: Literal[True]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class TimeInterval(TypedDict):
|
|
89
|
+
start: str
|
|
90
|
+
end: str
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class FindFreeBusyInput(TypedDict):
|
|
94
|
+
timeMin: str
|
|
95
|
+
timeMax: str
|
|
96
|
+
calendarIds: NotRequired[list[str]]
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class FreeBusyCalendar(TypedDict):
|
|
100
|
+
calendarId: str
|
|
101
|
+
busy: list[TimeInterval]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class QuickAddInput(TypedDict):
|
|
105
|
+
calendarId: NotRequired[str]
|
|
106
|
+
text: str
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GCAL_RETRY
|
|
6
|
+
from .types import CalEvent, UpdateEventInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def update_event_impl(
|
|
10
|
+
ctx: TaskContext, input: UpdateEventInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CalEvent:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gcal.update_event(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gcal.updateEvent", retry=GCAL_RETRY)
|
|
17
|
+
async def update_event(ctx: TaskContext, input: UpdateEventInput) -> CalEvent:
|
|
18
|
+
return await update_event_impl(ctx, input)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: render-lab-tasks-gcal
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: gcal tasks for Render Workflows
|
|
5
|
+
Project-URL: Repository, https://github.com/render-lab/render-tasks-python
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: httpx<0.29,>=0.28
|
|
10
|
+
Requires-Dist: render-lab-tasks-core<0.2,>=0.1.1
|
|
11
|
+
Requires-Dist: render==1.0.1
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# render-lab-tasks-gcal
|
|
15
|
+
|
|
16
|
+
Python port of all 9 registered tasks in the pinned TypeScript pack at
|
|
17
|
+
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.
|
|
18
|
+
|
|
19
|
+
Install this distribution and its dependencies:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install render-lab-tasks-gcal==0.1.0
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Import definitions from `render_lab_tasks_gcal.tasks`; combine `app` objects
|
|
26
|
+
with `Workflows.from_workflows(...)`. JSON fields retain TS spelling; functions
|
|
27
|
+
use snake_case. Package root imports are inert.
|
|
28
|
+
|
|
29
|
+
## Tasks
|
|
30
|
+
|
|
31
|
+
| Registered name | Python export (also exposes `_impl`) |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| `gcal.createEvent` | `create_event` |
|
|
34
|
+
| `gcal.deleteEvent` | `delete_event` |
|
|
35
|
+
| `gcal.findFreeBusy` | `find_free_busy` |
|
|
36
|
+
| `gcal.getEvent` | `get_event` |
|
|
37
|
+
| `gcal.listEvents` | `list_events` |
|
|
38
|
+
| `gcal.quickAdd` | `quick_add` |
|
|
39
|
+
| `gcal.respond` | `respond` |
|
|
40
|
+
| `gcal.suggestTime` | `suggest_time` |
|
|
41
|
+
| `gcal.updateEvent` | `update_event` |
|
|
42
|
+
|
|
43
|
+
## Dependencies and retries
|
|
44
|
+
|
|
45
|
+
Raw implementations accept context first and keyword-only `deps`. The `.client`
|
|
46
|
+
module exports typed `Port`, `Deps`, and `Client` classes. Inject a fake port, or
|
|
47
|
+
pass a caller-owned `httpx.AsyncClient` to `Client`. Default dependencies close
|
|
48
|
+
their client after one operation. Credentials resolve at first use. Transport
|
|
49
|
+
retries are disabled; `retry.py` owns durable policies. DTO types are in `.types`.
|
|
50
|
+
Requires core >=0.1.1.
|
|
51
|
+
|
|
52
|
+
## Environment
|
|
53
|
+
|
|
54
|
+
| Variable | Contract |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `GOOGLE_ACCESS_TOKEN` | Optional pre-issued token; takes precedence. |
|
|
57
|
+
| `GOOGLE_CLIENT_ID` | Required with secret and refresh token when no access token is supplied. |
|
|
58
|
+
| `GOOGLE_CLIENT_SECRET` | OAuth client secret for refresh. |
|
|
59
|
+
| `GOOGLE_REFRESH_TOKEN` | Refresh token granted the scopes for the operations you use. |
|
|
60
|
+
| `GCAL_CALENDAR_ID` | Optional default calendar; otherwise `primary`. |
|
|
61
|
+
|
|
62
|
+
## Verification and limitations
|
|
63
|
+
|
|
64
|
+
Calendar operations use the Google Calendar v3 API. listEvents returns one page.
|
|
65
|
+
suggestTime starts at the current instant, defaults to seven days, and reads at
|
|
66
|
+
most 250 events; it does not model business hours or exhaust pagination. It must
|
|
67
|
+
not be treated as an authoritative availability guarantee. freeBusy is a separate
|
|
68
|
+
operation. Writes use the inherited three-retry policy and may duplicate creates.
|
|
69
|
+
OAuth scopes and account permissions require live verification.
|
|
70
|
+
|
|
71
|
+
Shared fixtures execute the actual pinned TS implementations and compare Python
|
|
72
|
+
outputs and requests. Sanity's SDK calls are translated into separately asserted
|
|
73
|
+
REST requests. These are hermetic checks, not real account or hosted verification.
|
|
74
|
+
See [the testing backlog](https://github.com/render-lab/render-tasks-python/issues/1)
|
|
75
|
+
and the root verification tracker. Licensed under MIT.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
render_lab_tasks_gcal/__init__.py,sha256=fGcyw3Sxjue9wB_1RdFbEFKm5DXSlw_6vD2ud03a6og,58
|
|
2
|
+
render_lab_tasks_gcal/_app.py,sha256=nkWSD_6eq3xzdPJ_G7z6d5mv8tSB-Rq21yp07usJihA,48
|
|
3
|
+
render_lab_tasks_gcal/client.py,sha256=eYDPX22sQwFPGqnqtMK0d9ImqBxUxcUp4yqyKfRsMjI,7605
|
|
4
|
+
render_lab_tasks_gcal/create_event.py,sha256=KsMBgWo_Vg8kD3gXyYOTppBkl-KPGX_SUnTQ1L_Xd8Y,573
|
|
5
|
+
render_lab_tasks_gcal/delete_event.py,sha256=66QJuZG9jVS551Nn6CFTnF_VYd2pt_DxKyA5oq4L-jo,600
|
|
6
|
+
render_lab_tasks_gcal/find_free_busy.py,sha256=BSNwx-elge3jMH_kOTL7Rz5cvf_V-EJ5tcaccn1o1bo,621
|
|
7
|
+
render_lab_tasks_gcal/get_event.py,sha256=mLS7LuFvL8meHOyUUk9PSRLKKdPHCrFHdVMP2kOFOwg,549
|
|
8
|
+
render_lab_tasks_gcal/list_events.py,sha256=JjwSoPzSynHo3-N2JkbSesnxme3NN5R0elepk17hUfU,577
|
|
9
|
+
render_lab_tasks_gcal/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
render_lab_tasks_gcal/quick_add.py,sha256=cfllTb1QUXC3qiO-KF_Ix6eldf5LUbXMSpB0hU1P_vQ,549
|
|
11
|
+
render_lab_tasks_gcal/respond.py,sha256=tzhN05cgArUQjLNgrw9qqhYVAxGisiZV423DAliOx9w,552
|
|
12
|
+
render_lab_tasks_gcal/retry.py,sha256=_JgFTG8zTDDEmHRV0VmIHFecVg1qEJG6X0G-nlgrGzo,103
|
|
13
|
+
render_lab_tasks_gcal/suggest_time.py,sha256=EiVACYnY_NFDocDZCev6bUDDofZObp9IXK8WdqEE2To,600
|
|
14
|
+
render_lab_tasks_gcal/tasks.py,sha256=7MELHVjJgiYxBXdXznKG_GTBq3cXi-8uNU5Dfj5APd0,925
|
|
15
|
+
render_lab_tasks_gcal/types.py,sha256=2Inlj4w4oI18yUedVpcKACzrzGrHQysnaf2gF8gAku0,2076
|
|
16
|
+
render_lab_tasks_gcal/update_event.py,sha256=GYTcDp00ca_bVL4MTO5jdvjYeT5W5iVmq9TFLB7THGw,573
|
|
17
|
+
render_lab_tasks_gcal-0.1.0.dist-info/METADATA,sha256=RsjIOmqPrmgyA1YnaSHN_x8gs9vqP3Jf5Gdfxhdo9fU,3085
|
|
18
|
+
render_lab_tasks_gcal-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
19
|
+
render_lab_tasks_gcal-0.1.0.dist-info/licenses/LICENSE,sha256=LvmsuKGkhvlSISJRqvBIPUQ_BqVDFRe0RghPSmDebzU,1067
|
|
20
|
+
render_lab_tasks_gcal-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Render Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|