agentboxd 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.
- agentboxd/__init__.py +376 -0
- agentboxd/_attachments.py +43 -0
- agentboxd/_client.py +3251 -0
- agentboxd/_consume.py +314 -0
- agentboxd/_errors.py +106 -0
- agentboxd/_pagination.py +37 -0
- agentboxd/_requests.py +1364 -0
- agentboxd/_signup.py +69 -0
- agentboxd/_stream.py +151 -0
- agentboxd/_types.py +1864 -0
- agentboxd/_version.py +1 -0
- agentboxd/_webhooks.py +68 -0
- agentboxd/identity.py +1199 -0
- agentboxd/py.typed +0 -0
- agentboxd-0.1.0.dist-info/METADATA +489 -0
- agentboxd-0.1.0.dist-info/RECORD +18 -0
- agentboxd-0.1.0.dist-info/WHEEL +4 -0
- agentboxd-0.1.0.dist-info/licenses/LICENSE +21 -0
agentboxd/_client.py
ADDED
|
@@ -0,0 +1,3251 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import builtins
|
|
3
|
+
import json as _json
|
|
4
|
+
import os
|
|
5
|
+
import threading
|
|
6
|
+
from collections.abc import Mapping, Sequence
|
|
7
|
+
from types import TracebackType
|
|
8
|
+
from typing import Any, Literal, Optional, TypeVar, Union, cast
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
|
|
12
|
+
from . import _consume
|
|
13
|
+
from . import _requests as r
|
|
14
|
+
from ._errors import APIConnectionError, error_for_status
|
|
15
|
+
from ._requests import (
|
|
16
|
+
NOT_GIVEN,
|
|
17
|
+
DraftStatuses,
|
|
18
|
+
InboxIds,
|
|
19
|
+
MetadataFilter,
|
|
20
|
+
MetadataPatch,
|
|
21
|
+
NotGiven,
|
|
22
|
+
Nullable,
|
|
23
|
+
NullableSendAt,
|
|
24
|
+
NullableText,
|
|
25
|
+
Recipients,
|
|
26
|
+
Request,
|
|
27
|
+
SendAt,
|
|
28
|
+
)
|
|
29
|
+
from ._signup import Signup, solve_signup_challenge
|
|
30
|
+
from ._stream import EventStream
|
|
31
|
+
from ._types import (
|
|
32
|
+
Account,
|
|
33
|
+
AckResult,
|
|
34
|
+
AddAgentResult,
|
|
35
|
+
AgentBundle,
|
|
36
|
+
AgentCard,
|
|
37
|
+
AgentCardInput,
|
|
38
|
+
AgentCardVisibility,
|
|
39
|
+
AgentKey,
|
|
40
|
+
AgentKeyList,
|
|
41
|
+
AttachmentInput,
|
|
42
|
+
AttachmentText,
|
|
43
|
+
BatchMessages,
|
|
44
|
+
BuiltinExtractionSchema,
|
|
45
|
+
ClaimRequestResult,
|
|
46
|
+
Contact,
|
|
47
|
+
ContactBulkDeleteResult,
|
|
48
|
+
ContactDomainList,
|
|
49
|
+
ContactKind,
|
|
50
|
+
ContactWithThreads,
|
|
51
|
+
DeletedThread,
|
|
52
|
+
DeliverabilitySummary,
|
|
53
|
+
Direction,
|
|
54
|
+
DirectoryReportReason,
|
|
55
|
+
DirectoryReportResult,
|
|
56
|
+
DirectoryVerifyResult,
|
|
57
|
+
Domain,
|
|
58
|
+
DomainZoneFile,
|
|
59
|
+
Draft,
|
|
60
|
+
DraftKeep,
|
|
61
|
+
DraftReply,
|
|
62
|
+
DraftSendResult,
|
|
63
|
+
EmergencyStopResult,
|
|
64
|
+
EscalationSettings,
|
|
65
|
+
ExtendResult,
|
|
66
|
+
IdentityClient,
|
|
67
|
+
IdentityClientType,
|
|
68
|
+
IdentityClientWithSecret,
|
|
69
|
+
IdentityScope,
|
|
70
|
+
IdentitySignIn,
|
|
71
|
+
IdentitySubjectType,
|
|
72
|
+
IdentityToken,
|
|
73
|
+
Inbox,
|
|
74
|
+
InboxEscalation,
|
|
75
|
+
InboxForward,
|
|
76
|
+
InboxIdentity,
|
|
77
|
+
KnowledgeDoc,
|
|
78
|
+
KnowledgeListItem,
|
|
79
|
+
KnowledgeSearchResults,
|
|
80
|
+
LeaseClaim,
|
|
81
|
+
ListDirection,
|
|
82
|
+
ListEntries,
|
|
83
|
+
ListEntry,
|
|
84
|
+
ListKind,
|
|
85
|
+
Message,
|
|
86
|
+
MessageChannel,
|
|
87
|
+
MessageStatus,
|
|
88
|
+
MessageType,
|
|
89
|
+
Metrics,
|
|
90
|
+
MetricsBucket,
|
|
91
|
+
NackResult,
|
|
92
|
+
Page,
|
|
93
|
+
PublicAgent,
|
|
94
|
+
PublicAgentCard,
|
|
95
|
+
PublicAgentKeys,
|
|
96
|
+
PublicHandle,
|
|
97
|
+
QuietHours,
|
|
98
|
+
ResolvedAgent,
|
|
99
|
+
ResumedInbox,
|
|
100
|
+
ScreeningState,
|
|
101
|
+
SearchResult,
|
|
102
|
+
SignupChallenge,
|
|
103
|
+
SignupResult,
|
|
104
|
+
StreamToken,
|
|
105
|
+
StructuredExtraction,
|
|
106
|
+
Thread,
|
|
107
|
+
ThreadWithMessages,
|
|
108
|
+
VerificationResult,
|
|
109
|
+
Webhook,
|
|
110
|
+
WebhookCatalogEntry,
|
|
111
|
+
WebhookEventType,
|
|
112
|
+
WebhookPayload,
|
|
113
|
+
WebhookTestResult,
|
|
114
|
+
WorkspaceHandle,
|
|
115
|
+
)
|
|
116
|
+
from ._types import (
|
|
117
|
+
Identity as IdentityRecord,
|
|
118
|
+
)
|
|
119
|
+
from ._version import __version__
|
|
120
|
+
|
|
121
|
+
__all__ = [
|
|
122
|
+
"DEFAULT_BASE_URL",
|
|
123
|
+
"DEFAULT_TIMEOUT",
|
|
124
|
+
"Agentboxd",
|
|
125
|
+
"AsyncAgentboxd",
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
DEFAULT_BASE_URL = "https://api.agentboxd.com"
|
|
129
|
+
DEFAULT_TIMEOUT = 30.0
|
|
130
|
+
DEFAULT_TEMPORARY_TTL = 900
|
|
131
|
+
"""Default lifetime (seconds) of a temporary inbox."""
|
|
132
|
+
WAIT_TIMEOUT_MARGIN = 10.0
|
|
133
|
+
"""Extra seconds added to the HTTP read timeout on long-poll (wait) requests."""
|
|
134
|
+
|
|
135
|
+
API_KEY_ENV_VARS = ("AGENTBOXD_API_KEY", "MAILROOM_API_KEY")
|
|
136
|
+
"""Environment variables read for the API key, in priority order (MAILROOM_* is the legacy name)."""
|
|
137
|
+
BASE_URL_ENV_VARS = ("AGENTBOXD_BASE_URL", "MAILROOM_URL")
|
|
138
|
+
"""Environment variables read for the base URL, in priority order (MAILROOM_* is the legacy name)."""
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _env(names: tuple[str, ...]) -> Optional[str]:
|
|
142
|
+
"""First non-blank value among the named environment variables."""
|
|
143
|
+
for name in names:
|
|
144
|
+
value = os.environ.get(name, "").strip()
|
|
145
|
+
if value:
|
|
146
|
+
return value
|
|
147
|
+
return None
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _retry_after(response: httpx.Response, details: Any) -> Optional[float]:
|
|
151
|
+
"""Seconds to wait: the ``Retry-After`` header, else ``details.retry_after_seconds``."""
|
|
152
|
+
header = response.headers.get("retry-after")
|
|
153
|
+
if header:
|
|
154
|
+
try:
|
|
155
|
+
return float(header)
|
|
156
|
+
except ValueError:
|
|
157
|
+
pass
|
|
158
|
+
value = details.get("retry_after_seconds") if isinstance(details, dict) else None
|
|
159
|
+
return float(value) if isinstance(value, (int, float)) and not isinstance(value, bool) else None
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _signup_base_url(base_url: Optional[str]) -> str:
|
|
163
|
+
return (base_url or _env(BASE_URL_ENV_VARS) or DEFAULT_BASE_URL).rstrip("/")
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _public_kwargs(base_url: str, req: Request) -> dict[str, Any]:
|
|
167
|
+
"""A request without an API key (the public signup routes)."""
|
|
168
|
+
headers = {"Accept": "application/json", "User-Agent": f"agentboxd-python/{__version__}"}
|
|
169
|
+
kwargs: dict[str, Any] = {"method": req.method, "url": base_url + req.path, "headers": headers}
|
|
170
|
+
if req.has_body:
|
|
171
|
+
headers["Content-Type"] = "application/json"
|
|
172
|
+
kwargs["content"] = _json.dumps(req.json).encode("utf-8")
|
|
173
|
+
return kwargs
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
_SelfT = TypeVar("_SelfT", bound="_BaseClient")
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class _BaseClient:
|
|
180
|
+
def __init__(self, api_key: Optional[str], base_url: Optional[str], timeout: float) -> None:
|
|
181
|
+
key = api_key if api_key is not None else _env(API_KEY_ENV_VARS)
|
|
182
|
+
if not key:
|
|
183
|
+
raise ValueError(
|
|
184
|
+
"No API key: pass api_key=... or set the AGENTBOXD_API_KEY environment variable."
|
|
185
|
+
)
|
|
186
|
+
self.api_key = key
|
|
187
|
+
self.base_url = (base_url or _env(BASE_URL_ENV_VARS) or DEFAULT_BASE_URL).rstrip("/")
|
|
188
|
+
self.timeout = timeout
|
|
189
|
+
|
|
190
|
+
def _build(self, req: Request) -> dict[str, Any]:
|
|
191
|
+
headers = {
|
|
192
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
193
|
+
"Accept": "application/json",
|
|
194
|
+
"User-Agent": f"agentboxd-python/{__version__}",
|
|
195
|
+
}
|
|
196
|
+
kwargs: dict[str, Any] = {"method": req.method, "url": self.base_url + req.path, "headers": headers}
|
|
197
|
+
if req.params:
|
|
198
|
+
kwargs["params"] = req.params
|
|
199
|
+
if req.has_body:
|
|
200
|
+
headers["Content-Type"] = "application/json"
|
|
201
|
+
kwargs["content"] = _json.dumps(req.json).encode("utf-8")
|
|
202
|
+
if req.idempotency_key:
|
|
203
|
+
headers["Idempotency-Key"] = req.idempotency_key
|
|
204
|
+
if req.wait_seconds is not None:
|
|
205
|
+
kwargs["timeout"] = httpx.Timeout(self.timeout, read=req.wait_seconds + WAIT_TIMEOUT_MARGIN)
|
|
206
|
+
return kwargs
|
|
207
|
+
|
|
208
|
+
@staticmethod
|
|
209
|
+
def _parse(response: httpx.Response) -> Any:
|
|
210
|
+
if response.status_code == 204:
|
|
211
|
+
return None
|
|
212
|
+
try:
|
|
213
|
+
payload: Any = response.json() if response.content else {}
|
|
214
|
+
except ValueError:
|
|
215
|
+
payload = {}
|
|
216
|
+
if not response.is_success:
|
|
217
|
+
err = payload.get("error") if isinstance(payload, dict) else None
|
|
218
|
+
err = err if isinstance(err, dict) else {}
|
|
219
|
+
code = err.get("code")
|
|
220
|
+
message = err.get("message")
|
|
221
|
+
details = err.get("details")
|
|
222
|
+
raise error_for_status(
|
|
223
|
+
response.status_code,
|
|
224
|
+
code if isinstance(code, str) else None,
|
|
225
|
+
message if isinstance(message, str) else (response.reason_phrase or None),
|
|
226
|
+
details,
|
|
227
|
+
_retry_after(response, details),
|
|
228
|
+
)
|
|
229
|
+
return payload
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
# =====================================================================
|
|
233
|
+
# sync
|
|
234
|
+
# =====================================================================
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class Inboxes:
|
|
238
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
239
|
+
self._c = client
|
|
240
|
+
|
|
241
|
+
def create(
|
|
242
|
+
self,
|
|
243
|
+
*,
|
|
244
|
+
username: Optional[str] = None,
|
|
245
|
+
display_name: Optional[str] = None,
|
|
246
|
+
client_id: Optional[str] = None,
|
|
247
|
+
metadata: Optional[MetadataPatch] = None,
|
|
248
|
+
domain: Optional[str] = None,
|
|
249
|
+
card: Optional[AgentCardInput] = None,
|
|
250
|
+
) -> Inbox:
|
|
251
|
+
"""Create an inbox. Idempotent on ``client_id`` (returns the existing inbox).
|
|
252
|
+
|
|
253
|
+
``domain``: a verified custom domain of the workspace (default: the server's agent domain).
|
|
254
|
+
``card``: also create its agent card (needs ``directory:write``); the response then has ``card``."""
|
|
255
|
+
req = r.inbox_create(username, display_name, client_id, metadata, domain, card=card)
|
|
256
|
+
return cast(Inbox, self._c._send(req))
|
|
257
|
+
|
|
258
|
+
def create_temporary(
|
|
259
|
+
self,
|
|
260
|
+
*,
|
|
261
|
+
ttl_seconds: int = DEFAULT_TEMPORARY_TTL,
|
|
262
|
+
display_name: Optional[str] = None,
|
|
263
|
+
metadata: Optional[MetadataPatch] = None,
|
|
264
|
+
) -> Inbox:
|
|
265
|
+
"""Create a temporary, receive-only inbox (random address on the temporary domain).
|
|
266
|
+
|
|
267
|
+
It and all its mail are wiped at ``expires_at``; ``ttl_seconds`` is 60 to 86400."""
|
|
268
|
+
req = r.inbox_create(None, display_name, None, metadata, None, ttl_seconds)
|
|
269
|
+
return cast(Inbox, self._c._send(req))
|
|
270
|
+
|
|
271
|
+
def list(
|
|
272
|
+
self,
|
|
273
|
+
*,
|
|
274
|
+
cursor: Optional[str] = None,
|
|
275
|
+
limit: Optional[int] = None,
|
|
276
|
+
metadata: Optional[MetadataFilter] = None,
|
|
277
|
+
include_temporary: Optional[bool] = None,
|
|
278
|
+
temporary: Optional[bool] = None,
|
|
279
|
+
) -> Page[Inbox]:
|
|
280
|
+
"""List inboxes, newest first. ``metadata`` filters by exact value, e.g. ``{"team": "billing"}``.
|
|
281
|
+
|
|
282
|
+
Temporary inboxes are excluded unless ``include_temporary=True``;
|
|
283
|
+
``temporary=True`` lists only them."""
|
|
284
|
+
req = r.inbox_list(cursor, limit, metadata, include_temporary, temporary)
|
|
285
|
+
return cast("Page[Inbox]", self._c._send(req))
|
|
286
|
+
|
|
287
|
+
def get(self, inbox_id: str) -> Inbox:
|
|
288
|
+
return cast(Inbox, self._c._send(r.inbox_get(inbox_id)))
|
|
289
|
+
|
|
290
|
+
def update(
|
|
291
|
+
self,
|
|
292
|
+
inbox_id: str,
|
|
293
|
+
*,
|
|
294
|
+
display_name: Nullable = NOT_GIVEN,
|
|
295
|
+
metadata: Optional[MetadataPatch] = None,
|
|
296
|
+
ttl_seconds: Optional[int] = None,
|
|
297
|
+
promotions_filter: Union[bool, NotGiven, None] = NOT_GIVEN,
|
|
298
|
+
) -> Inbox:
|
|
299
|
+
"""Change the display name (``None`` clears it) or metadata (merged; ``None`` deletes a key).
|
|
300
|
+
|
|
301
|
+
``ttl_seconds`` extends a temporary inbox from now (at most 24 h after its creation).
|
|
302
|
+
``promotions_filter`` turns the Promotions & spam view on or off (``None``: back to the default)."""
|
|
303
|
+
req = r.inbox_update(inbox_id, display_name, metadata, ttl_seconds, promotions_filter)
|
|
304
|
+
return cast(Inbox, self._c._send(req))
|
|
305
|
+
|
|
306
|
+
def delete(self, inbox_id: str) -> None:
|
|
307
|
+
"""Soft-delete an inbox (its address is never reused). A temporary inbox is wiped at once."""
|
|
308
|
+
self._c._send(r.inbox_delete(inbox_id))
|
|
309
|
+
|
|
310
|
+
def pause(self, inbox_id: str, *, reason: Optional[str] = None) -> Inbox:
|
|
311
|
+
"""Kill switch: every send from the inbox is refused (423 ``inbox_paused``) until ``resume``.
|
|
312
|
+
|
|
313
|
+
Inbound mail is still stored; its events and AI categorisation are held until then."""
|
|
314
|
+
return cast(Inbox, self._c._send(r.inbox_pause(inbox_id, reason)))
|
|
315
|
+
|
|
316
|
+
def resume(self, inbox_id: str) -> ResumedInbox:
|
|
317
|
+
"""Sending works again; held inbound events are emitted in arrival order (``released_events``)."""
|
|
318
|
+
return cast(ResumedInbox, self._c._send(r.inbox_resume(inbox_id)))
|
|
319
|
+
|
|
320
|
+
def consume(
|
|
321
|
+
self,
|
|
322
|
+
inbox_id: str,
|
|
323
|
+
handler: "_consume.SyncHandler",
|
|
324
|
+
*,
|
|
325
|
+
concurrency: int = 1,
|
|
326
|
+
lease_seconds: int = _consume.DEFAULT_LEASE_SECONDS,
|
|
327
|
+
wait: float = _consume.DEFAULT_WAIT,
|
|
328
|
+
consumer: Optional[str] = None,
|
|
329
|
+
enriched: Optional[bool] = None,
|
|
330
|
+
analysis: Optional[Literal["completed"]] = None,
|
|
331
|
+
include_unscreened: Optional[bool] = None,
|
|
332
|
+
include_held: Optional[bool] = None,
|
|
333
|
+
stop: "Optional[threading.Event]" = None,
|
|
334
|
+
retry_delay_seconds: float = 5,
|
|
335
|
+
max_retry_delay_seconds: float = 300,
|
|
336
|
+
paused_poll_seconds: float = 10,
|
|
337
|
+
on_error: "Optional[_consume.ErrorHandler]" = None,
|
|
338
|
+
) -> None:
|
|
339
|
+
"""Crash-safe consumer loop over the claim/ack queue.
|
|
340
|
+
|
|
341
|
+
Claims messages and calls ``handler(message)`` (or ``handler(message, ctx)``) for each, up to
|
|
342
|
+
``concurrency`` at once in threads. The lease is extended while the handler runs; the message
|
|
343
|
+
is acked when it returns and nacked with backoff (``retry_delay_seconds`` doubling per
|
|
344
|
+
delivery, capped) when it raises. Delivery is at-least-once: make the handler idempotent.
|
|
345
|
+
Runs until ``stop`` (a ``threading.Event``) is set; running handlers finish first."""
|
|
346
|
+
_consume.consume_sync(
|
|
347
|
+
self._c.messages,
|
|
348
|
+
inbox_id,
|
|
349
|
+
handler,
|
|
350
|
+
_consume.ConsumeOptions(
|
|
351
|
+
concurrency=concurrency,
|
|
352
|
+
lease_seconds=lease_seconds,
|
|
353
|
+
wait=wait,
|
|
354
|
+
consumer=consumer,
|
|
355
|
+
enriched=enriched,
|
|
356
|
+
analysis=analysis,
|
|
357
|
+
include_unscreened=include_unscreened,
|
|
358
|
+
include_held=include_held,
|
|
359
|
+
retry_delay_seconds=retry_delay_seconds,
|
|
360
|
+
max_retry_delay_seconds=max_retry_delay_seconds,
|
|
361
|
+
paused_poll_seconds=paused_poll_seconds,
|
|
362
|
+
on_error=on_error,
|
|
363
|
+
),
|
|
364
|
+
stop,
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
class Domains:
|
|
369
|
+
"""Custom domains: connect a domain you own, publish its ``records``, then ``verify``."""
|
|
370
|
+
|
|
371
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
372
|
+
self._c = client
|
|
373
|
+
|
|
374
|
+
def create(self, domain: str, *, receiving: Optional[bool] = None) -> Domain:
|
|
375
|
+
return cast(Domain, self._c._send(r.domain_create(domain, receiving)))
|
|
376
|
+
|
|
377
|
+
def list(self) -> Page[Domain]:
|
|
378
|
+
return cast("Page[Domain]", self._c._send(r.domain_list()))
|
|
379
|
+
|
|
380
|
+
def get(self, domain_id: str) -> Domain:
|
|
381
|
+
return cast(Domain, self._c._send(r.domain_get(domain_id)))
|
|
382
|
+
|
|
383
|
+
def zone_file(self, domain_id: str) -> DomainZoneFile:
|
|
384
|
+
"""The records to publish as a BIND zone file (``filename`` and ``content``).
|
|
385
|
+
|
|
386
|
+
Write ``content`` to a file and import it at a DNS provider that takes one."""
|
|
387
|
+
return cast(DomainZoneFile, self._c._send(r.domain_zone_file(domain_id)))
|
|
388
|
+
|
|
389
|
+
def verify(self, domain_id: str) -> Domain:
|
|
390
|
+
"""Check the DNS records now (at most once per 10 s per domain)."""
|
|
391
|
+
return cast(Domain, self._c._send(r.domain_verify(domain_id)))
|
|
392
|
+
|
|
393
|
+
def update(self, domain_id: str, *, receiving: Optional[bool] = None) -> Domain:
|
|
394
|
+
return cast(Domain, self._c._send(r.domain_update(domain_id, receiving)))
|
|
395
|
+
|
|
396
|
+
def delete(self, domain_id: str, *, force: bool = False) -> None:
|
|
397
|
+
"""409 ``domain_in_use`` while live inboxes use it, unless ``force`` (which deletes those inboxes)."""
|
|
398
|
+
self._c._send(r.domain_delete(domain_id, force))
|
|
399
|
+
|
|
400
|
+
def rotate_dkim(self, domain_id: str) -> Domain:
|
|
401
|
+
"""Start a DKIM key rotation: a new key on the other selector (``dkim_next`` in ``records``).
|
|
402
|
+
|
|
403
|
+
Publish it next to the current record; signing switches as soon as it is seen."""
|
|
404
|
+
return cast(Domain, self._c._send(r.domain_dkim_rotate(domain_id)))
|
|
405
|
+
|
|
406
|
+
def activate_dkim(self, domain_id: str) -> Domain:
|
|
407
|
+
"""Check DNS now and switch signing to the new key (409 ``dkim_record_not_found`` until published)."""
|
|
408
|
+
return cast(Domain, self._c._send(r.domain_dkim_activate(domain_id)))
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
class Messages:
|
|
412
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
413
|
+
self._c = client
|
|
414
|
+
|
|
415
|
+
def send(
|
|
416
|
+
self,
|
|
417
|
+
inbox_id: str,
|
|
418
|
+
to: Recipients,
|
|
419
|
+
subject: str,
|
|
420
|
+
text: Optional[str] = None,
|
|
421
|
+
html: Optional[str] = None,
|
|
422
|
+
cc: Optional[Recipients] = None,
|
|
423
|
+
bcc: Optional[Recipients] = None,
|
|
424
|
+
attachments: Optional[Sequence[AttachmentInput]] = None,
|
|
425
|
+
labels: Optional[Sequence[str]] = None,
|
|
426
|
+
idempotency_key: Optional[str] = None,
|
|
427
|
+
data: Any = None,
|
|
428
|
+
type: Optional[MessageType] = None,
|
|
429
|
+
agent_signature: Optional[str] = None,
|
|
430
|
+
) -> Message:
|
|
431
|
+
"""Send from ``inbox_id``. Returns the message with ``status: "queued"``.
|
|
432
|
+
|
|
433
|
+
``data`` (a JSON object or list, at most 64 KB) and ``type`` (``message``, ``task``, ``event``) make
|
|
434
|
+
it a structured agent message: Agentboxd recipients get it natively (``channel: "agent"``, see
|
|
435
|
+
``delivery``), everyone else by email with the data attached. ``text``, ``html`` or ``data`` is
|
|
436
|
+
required.
|
|
437
|
+
|
|
438
|
+
``agent_signature`` (aSIM phase 2): an author signature made with the agent's own registered key
|
|
439
|
+
(``agentboxd.identity.sign_agent_message``) over exactly what is sent; the message then goes out
|
|
440
|
+
exactly as signed."""
|
|
441
|
+
req = r.message_send(
|
|
442
|
+
inbox_id,
|
|
443
|
+
to,
|
|
444
|
+
subject,
|
|
445
|
+
text,
|
|
446
|
+
html,
|
|
447
|
+
cc,
|
|
448
|
+
bcc,
|
|
449
|
+
attachments,
|
|
450
|
+
labels,
|
|
451
|
+
idempotency_key,
|
|
452
|
+
data,
|
|
453
|
+
type,
|
|
454
|
+
agent_signature,
|
|
455
|
+
)
|
|
456
|
+
return cast(Message, self._c._send(req))
|
|
457
|
+
|
|
458
|
+
def forward(
|
|
459
|
+
self,
|
|
460
|
+
inbox_id: str,
|
|
461
|
+
message_id: str,
|
|
462
|
+
to: Recipients,
|
|
463
|
+
cc: Optional[Recipients] = None,
|
|
464
|
+
bcc: Optional[Recipients] = None,
|
|
465
|
+
text: Optional[str] = None,
|
|
466
|
+
html: Optional[str] = None,
|
|
467
|
+
include_attachments: Optional[bool] = None,
|
|
468
|
+
labels: Optional[Sequence[str]] = None,
|
|
469
|
+
idempotency_key: Optional[str] = None,
|
|
470
|
+
) -> Message:
|
|
471
|
+
"""Forward a message to new recipients, in a new thread: ``text`` (your note) above the original,
|
|
472
|
+
with its attachments unless ``include_attachments=False``."""
|
|
473
|
+
req = r.message_forward(
|
|
474
|
+
inbox_id, message_id, to, cc, bcc, text, html, include_attachments, labels, idempotency_key
|
|
475
|
+
)
|
|
476
|
+
return cast(Message, self._c._send(req))
|
|
477
|
+
|
|
478
|
+
def batch_get(
|
|
479
|
+
self,
|
|
480
|
+
ids: Sequence[str],
|
|
481
|
+
*,
|
|
482
|
+
include_unscreened: Optional[bool] = None,
|
|
483
|
+
include_held: Optional[bool] = None,
|
|
484
|
+
) -> BatchMessages:
|
|
485
|
+
"""Up to 100 messages by id; ids you can't see come back in ``missing``."""
|
|
486
|
+
req = r.messages_batch_get(ids, include_unscreened, include_held)
|
|
487
|
+
return cast(BatchMessages, self._c._send(req))
|
|
488
|
+
|
|
489
|
+
def batch_update(
|
|
490
|
+
self,
|
|
491
|
+
ids: Sequence[str],
|
|
492
|
+
add_labels: Optional[Sequence[str]] = None,
|
|
493
|
+
remove_labels: Optional[Sequence[str]] = None,
|
|
494
|
+
is_read: Optional[bool] = None,
|
|
495
|
+
) -> BatchMessages:
|
|
496
|
+
"""The same label and read changes on up to 100 messages."""
|
|
497
|
+
return cast(
|
|
498
|
+
BatchMessages, self._c._send(r.messages_batch_update(ids, add_labels, remove_labels, is_read))
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
def reply(
|
|
502
|
+
self,
|
|
503
|
+
inbox_id: str,
|
|
504
|
+
message_id: str,
|
|
505
|
+
text: Optional[str] = None,
|
|
506
|
+
html: Optional[str] = None,
|
|
507
|
+
attachments: Optional[Sequence[AttachmentInput]] = None,
|
|
508
|
+
reply_all: Optional[bool] = None,
|
|
509
|
+
labels: Optional[Sequence[str]] = None,
|
|
510
|
+
idempotency_key: Optional[str] = None,
|
|
511
|
+
data: Any = None,
|
|
512
|
+
type: Optional[MessageType] = None,
|
|
513
|
+
agent_signature: Optional[str] = None,
|
|
514
|
+
) -> Message:
|
|
515
|
+
"""Reply in-thread (sets In-Reply-To/References and a ``Re:`` subject), optionally with ``data`` and
|
|
516
|
+
``type`` like :meth:`send`."""
|
|
517
|
+
req = r.message_reply(
|
|
518
|
+
inbox_id,
|
|
519
|
+
message_id,
|
|
520
|
+
text,
|
|
521
|
+
html,
|
|
522
|
+
attachments,
|
|
523
|
+
reply_all,
|
|
524
|
+
labels,
|
|
525
|
+
idempotency_key,
|
|
526
|
+
data,
|
|
527
|
+
type,
|
|
528
|
+
agent_signature,
|
|
529
|
+
)
|
|
530
|
+
return cast(Message, self._c._send(req))
|
|
531
|
+
|
|
532
|
+
def list(
|
|
533
|
+
self,
|
|
534
|
+
inbox_id: str,
|
|
535
|
+
labels: Optional[Sequence[str]] = None,
|
|
536
|
+
is_read: Optional[bool] = None,
|
|
537
|
+
direction: Optional[Direction] = None,
|
|
538
|
+
cursor: Optional[str] = None,
|
|
539
|
+
limit: Optional[int] = None,
|
|
540
|
+
include_blocked: Optional[bool] = None,
|
|
541
|
+
channel: Optional[MessageChannel] = None,
|
|
542
|
+
type: Optional[MessageType] = None,
|
|
543
|
+
screening: Optional[ScreeningState] = None,
|
|
544
|
+
include_unscreened: Optional[bool] = None,
|
|
545
|
+
include_held: Optional[bool] = None,
|
|
546
|
+
promotions: Optional[Literal["include", "exclude", "only"]] = None,
|
|
547
|
+
status: Optional[MessageStatus] = None,
|
|
548
|
+
) -> Page[Message]:
|
|
549
|
+
"""List messages, newest first. ``labels`` filters to messages having all of them.
|
|
550
|
+
|
|
551
|
+
``include_blocked=True`` also returns mail stopped by the receive lists (label ``blocked``).
|
|
552
|
+
``screening="held"`` returns only received mail in that screening state.
|
|
553
|
+
``status="bounced"`` (with ``direction="outbound"``) returns sent mail that bounced.
|
|
554
|
+
``promotions="exclude"`` leaves out mail labelled ``ai:sales`` or ``local:spam``; ``"only"`` lists
|
|
555
|
+
just that.
|
|
556
|
+
"""
|
|
557
|
+
req = r.message_list(
|
|
558
|
+
inbox_id,
|
|
559
|
+
labels,
|
|
560
|
+
is_read,
|
|
561
|
+
direction,
|
|
562
|
+
cursor,
|
|
563
|
+
limit,
|
|
564
|
+
include_blocked,
|
|
565
|
+
channel,
|
|
566
|
+
type,
|
|
567
|
+
screening,
|
|
568
|
+
include_unscreened,
|
|
569
|
+
include_held,
|
|
570
|
+
promotions,
|
|
571
|
+
status,
|
|
572
|
+
)
|
|
573
|
+
return cast("Page[Message]", self._c._send(req))
|
|
574
|
+
|
|
575
|
+
def get(
|
|
576
|
+
self,
|
|
577
|
+
message_id: str,
|
|
578
|
+
*,
|
|
579
|
+
include_unscreened: Optional[bool] = None,
|
|
580
|
+
include_held: Optional[bool] = None,
|
|
581
|
+
) -> Message:
|
|
582
|
+
"""One message. Held or unscreened mail comes back with ``withheld`` (no content) unless you opt in;
|
|
583
|
+
``include_held`` needs the ``messages:release`` permission."""
|
|
584
|
+
return cast(Message, self._c._send(r.message_get(message_id, include_unscreened, include_held)))
|
|
585
|
+
|
|
586
|
+
def update(
|
|
587
|
+
self,
|
|
588
|
+
message_id: str,
|
|
589
|
+
add_labels: Optional[Sequence[str]] = None,
|
|
590
|
+
remove_labels: Optional[Sequence[str]] = None,
|
|
591
|
+
is_read: Optional[bool] = None,
|
|
592
|
+
) -> Message:
|
|
593
|
+
return cast(Message, self._c._send(r.message_update(message_id, add_labels, remove_labels, is_read)))
|
|
594
|
+
|
|
595
|
+
def release(self, message_id: str) -> Message:
|
|
596
|
+
"""Release a held message to agents: claim and ``wait`` return it from now on. Safe to repeat.
|
|
597
|
+
|
|
598
|
+
Emits ``message.released``. Needs the ``messages:release`` permission (Full access keys only).
|
|
599
|
+
409 ``not_held`` for mail that isn't held, ``message_blocked`` for mail stopped by the lists."""
|
|
600
|
+
return cast(Message, self._c._send(r.message_release(message_id)))
|
|
601
|
+
|
|
602
|
+
def draft_reply(
|
|
603
|
+
self, message_id: str, instructions: Optional[str] = None, *, save: Optional[bool] = None
|
|
604
|
+
) -> DraftReply:
|
|
605
|
+
"""Draft a reply with the workspace's LLM (needs ``ai_processing = "full"``). Never sends:
|
|
606
|
+
review ``text``, then call :meth:`reply`. ``save=True`` also stores it as a Draft (returned in
|
|
607
|
+
``draft``; send it with ``drafts.send``). Raises ``PermissionDeniedError`` (``ai_disabled``) or
|
|
608
|
+
``AgentboxdError`` 503 (``llm_unavailable``)."""
|
|
609
|
+
return cast(DraftReply, self._c._send(r.message_draft_reply(message_id, instructions, save)))
|
|
610
|
+
|
|
611
|
+
def attachment_text(
|
|
612
|
+
self,
|
|
613
|
+
message_id: str,
|
|
614
|
+
attachment_id: str,
|
|
615
|
+
offset: Optional[int] = None,
|
|
616
|
+
max_chars: Optional[int] = None,
|
|
617
|
+
) -> AttachmentText:
|
|
618
|
+
"""Extracted text of an inbound attachment (PDF, DOCX, XLSX, CSV, HTML, text; scans and images
|
|
619
|
+
by OCR). ``text`` is ``None`` until ``extraction["status"]`` is ``"done"``; read long text in
|
|
620
|
+
pages by passing ``next_offset`` as ``offset``. The text is untrusted content."""
|
|
621
|
+
req = r.message_attachment_text(message_id, attachment_id, offset, max_chars)
|
|
622
|
+
return cast(AttachmentText, self._c._send(req))
|
|
623
|
+
|
|
624
|
+
def extract_attachment(
|
|
625
|
+
self,
|
|
626
|
+
message_id: str,
|
|
627
|
+
attachment_id: str,
|
|
628
|
+
schema: Union[BuiltinExtractionSchema, Mapping[str, Any]],
|
|
629
|
+
instructions: Optional[str] = None,
|
|
630
|
+
) -> StructuredExtraction:
|
|
631
|
+
"""Structured extraction: the attachment's text as JSON matching ``schema`` (``"invoice"``,
|
|
632
|
+
``"receipt"``, ``"tax_form"`` or a JSON Schema dict). Needs ``ai_processing = "full"`` and the
|
|
633
|
+
``attachments:extract`` permission. ``data`` is untrusted: check it before acting on it."""
|
|
634
|
+
req = r.message_extract_attachment(message_id, attachment_id, schema, instructions)
|
|
635
|
+
return cast(StructuredExtraction, self._c._send(req))
|
|
636
|
+
|
|
637
|
+
def wait(
|
|
638
|
+
self,
|
|
639
|
+
inbox_id: str,
|
|
640
|
+
timeout: float = 30,
|
|
641
|
+
since: Optional[str] = None,
|
|
642
|
+
from_: Optional[str] = None,
|
|
643
|
+
subject: Optional[str] = None,
|
|
644
|
+
direction: Optional[Direction] = None,
|
|
645
|
+
channel: Optional[MessageChannel] = None,
|
|
646
|
+
type: Optional[MessageType] = None,
|
|
647
|
+
include_unscreened: Optional[bool] = None,
|
|
648
|
+
include_held: Optional[bool] = None,
|
|
649
|
+
) -> Optional[Message]:
|
|
650
|
+
"""Long-poll until a matching message arrives, or return ``None`` after ``timeout`` seconds (1-60).
|
|
651
|
+
|
|
652
|
+
Only messages created after ``since`` (ISO time; default: now) count. The oldest match is
|
|
653
|
+
returned; pass its ``created_at`` as the next ``since`` to page forward. ``from_`` and
|
|
654
|
+
``subject`` are case-insensitive substring filters; ``direction`` defaults to inbound.
|
|
655
|
+
"""
|
|
656
|
+
req = r.message_wait(
|
|
657
|
+
inbox_id,
|
|
658
|
+
timeout,
|
|
659
|
+
since,
|
|
660
|
+
from_,
|
|
661
|
+
subject,
|
|
662
|
+
direction,
|
|
663
|
+
channel,
|
|
664
|
+
type,
|
|
665
|
+
include_unscreened,
|
|
666
|
+
include_held,
|
|
667
|
+
)
|
|
668
|
+
return cast(Optional[Message], self._c._send(req)["data"])
|
|
669
|
+
|
|
670
|
+
def wait_for_verification(
|
|
671
|
+
self,
|
|
672
|
+
inbox_id: str,
|
|
673
|
+
timeout: float = 30,
|
|
674
|
+
since: Optional[str] = None,
|
|
675
|
+
from_: Optional[str] = None,
|
|
676
|
+
include_unauthenticated: Optional[bool] = None,
|
|
677
|
+
) -> Optional[VerificationResult]:
|
|
678
|
+
"""Return the newest verification code/link received after ``since``, waiting up to
|
|
679
|
+
``timeout`` seconds for one to arrive. ``None`` on timeout.
|
|
680
|
+
|
|
681
|
+
Codes from mail whose sender failed authentication (possible spoofs) are skipped unless
|
|
682
|
+
``include_unauthenticated=True``; then ``auth_failed`` says so."""
|
|
683
|
+
req = r.message_wait_for_verification(inbox_id, timeout, since, from_, include_unauthenticated)
|
|
684
|
+
return cast(Optional[VerificationResult], self._c._send(req)["data"])
|
|
685
|
+
|
|
686
|
+
def claim(
|
|
687
|
+
self,
|
|
688
|
+
inbox_id: str,
|
|
689
|
+
*,
|
|
690
|
+
limit: Optional[int] = None,
|
|
691
|
+
lease_seconds: Optional[int] = None,
|
|
692
|
+
consumer: Optional[str] = None,
|
|
693
|
+
wait: Optional[float] = None,
|
|
694
|
+
enriched: Optional[bool] = None,
|
|
695
|
+
since: Optional[str] = None,
|
|
696
|
+
type: Optional[MessageType] = None,
|
|
697
|
+
channel: Optional[MessageChannel] = None,
|
|
698
|
+
analysis: Optional[Literal["completed"]] = None,
|
|
699
|
+
include_unscreened: Optional[bool] = None,
|
|
700
|
+
include_held: Optional[bool] = None,
|
|
701
|
+
) -> LeaseClaim:
|
|
702
|
+
"""Claim/ack queue: lease up to ``limit`` (1-50, default 10) inbound messages, oldest first.
|
|
703
|
+
|
|
704
|
+
Each is hidden from other claims for ``lease_seconds`` (30-3600, default 300); ``ack`` it when
|
|
705
|
+
the work is done, or it comes back (at-least-once). ``wait`` long-polls up to 30 s. The first
|
|
706
|
+
claim starts the queue: older mail is not claimable unless you pass ``since``. A paused inbox
|
|
707
|
+
returns ``{"data": [], "paused": True}``. ``enriched=True`` waits for AI categorisation;
|
|
708
|
+
``analysis="completed"`` returns only messages whose injection and phishing check completed.
|
|
709
|
+
When the workspace screens agent mail (the default for new workspaces), only screened and
|
|
710
|
+
released mail is returned; ``include_unscreened=True`` / ``include_held=True`` opt in."""
|
|
711
|
+
req = r.message_claim(
|
|
712
|
+
inbox_id,
|
|
713
|
+
limit,
|
|
714
|
+
lease_seconds,
|
|
715
|
+
consumer,
|
|
716
|
+
wait,
|
|
717
|
+
enriched,
|
|
718
|
+
since,
|
|
719
|
+
type,
|
|
720
|
+
channel,
|
|
721
|
+
analysis,
|
|
722
|
+
include_unscreened,
|
|
723
|
+
include_held,
|
|
724
|
+
)
|
|
725
|
+
return cast(LeaseClaim, self._c._send(req))
|
|
726
|
+
|
|
727
|
+
def ack(self, message_id: str, lease_id: str, *, mark_read: Optional[bool] = None) -> AckResult:
|
|
728
|
+
"""Done: never claimed again. Idempotent. ``AgentboxdError`` 409 ``lease_expired`` if the lease is
|
|
729
|
+
no longer current; ``{"gone": True}`` if the message was deleted meanwhile."""
|
|
730
|
+
return cast(AckResult, self._c._send(r.message_ack(message_id, lease_id, mark_read)))
|
|
731
|
+
|
|
732
|
+
def nack(self, message_id: str, lease_id: str, *, delay_seconds: Optional[int] = None) -> NackResult:
|
|
733
|
+
"""Give the message back now, or after ``delay_seconds`` (0-3600). The 10th delivery nacked is
|
|
734
|
+
dead-lettered (label ``queue:dead-letter``)."""
|
|
735
|
+
return cast(NackResult, self._c._send(r.message_nack(message_id, lease_id, delay_seconds)))
|
|
736
|
+
|
|
737
|
+
def extend(self, message_id: str, lease_id: str, *, lease_seconds: Optional[int] = None) -> ExtendResult:
|
|
738
|
+
"""Heartbeat: the lease then runs until now + ``lease_seconds`` (30-3600, default 300)."""
|
|
739
|
+
return cast(ExtendResult, self._c._send(r.message_extend(message_id, lease_id, lease_seconds)))
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
class Drafts:
|
|
743
|
+
"""Drafts: store an email for review, edit it, then ``send`` it now or ``schedule`` it.
|
|
744
|
+
|
|
745
|
+
Sending goes through every check a normal send does (allow/block lists, suppressions, plan quota,
|
|
746
|
+
daily caps, the 5-minute burst limit). Permissions: ``drafts:read`` / ``drafts:write``; ``send`` and
|
|
747
|
+
``schedule`` also need ``messages:send``.
|
|
748
|
+
"""
|
|
749
|
+
|
|
750
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
751
|
+
self._c = client
|
|
752
|
+
|
|
753
|
+
def create(
|
|
754
|
+
self,
|
|
755
|
+
inbox_id: str,
|
|
756
|
+
*,
|
|
757
|
+
to: Optional[Recipients] = None,
|
|
758
|
+
subject: Optional[str] = None,
|
|
759
|
+
text: Optional[str] = None,
|
|
760
|
+
html: Optional[str] = None,
|
|
761
|
+
cc: Optional[Recipients] = None,
|
|
762
|
+
bcc: Optional[Recipients] = None,
|
|
763
|
+
attachments: Optional[Sequence[AttachmentInput]] = None,
|
|
764
|
+
labels: Optional[Sequence[str]] = None,
|
|
765
|
+
metadata: Optional[MetadataPatch] = None,
|
|
766
|
+
reply_to_message_id: Optional[str] = None,
|
|
767
|
+
thread_id: Optional[str] = None,
|
|
768
|
+
reply_all: Optional[bool] = None,
|
|
769
|
+
send_at: Optional[SendAt] = None,
|
|
770
|
+
idempotency_key: Optional[str] = None,
|
|
771
|
+
data: Any = None,
|
|
772
|
+
type: Optional[MessageType] = None,
|
|
773
|
+
) -> Draft:
|
|
774
|
+
"""Create a draft (nothing is sent). Everything is optional until it is sent.
|
|
775
|
+
|
|
776
|
+
``reply_to_message_id`` (or ``thread_id``) makes it a reply: recipients, ``Re:`` subject and
|
|
777
|
+
threading are filled in. ``send_at`` (1 minute to 30 days ahead) schedules it."""
|
|
778
|
+
req = r.draft_create(
|
|
779
|
+
inbox_id,
|
|
780
|
+
to,
|
|
781
|
+
subject,
|
|
782
|
+
text,
|
|
783
|
+
html,
|
|
784
|
+
cc,
|
|
785
|
+
bcc,
|
|
786
|
+
attachments,
|
|
787
|
+
labels,
|
|
788
|
+
metadata,
|
|
789
|
+
reply_to_message_id,
|
|
790
|
+
thread_id,
|
|
791
|
+
reply_all,
|
|
792
|
+
send_at,
|
|
793
|
+
idempotency_key,
|
|
794
|
+
data,
|
|
795
|
+
type,
|
|
796
|
+
)
|
|
797
|
+
return cast(Draft, self._c._send(req))
|
|
798
|
+
|
|
799
|
+
def list(
|
|
800
|
+
self,
|
|
801
|
+
inbox_id: str,
|
|
802
|
+
*,
|
|
803
|
+
status: Optional[DraftStatuses] = None,
|
|
804
|
+
thread_id: Optional[str] = None,
|
|
805
|
+
cursor: Optional[str] = None,
|
|
806
|
+
limit: Optional[int] = None,
|
|
807
|
+
) -> Page[Draft]:
|
|
808
|
+
"""Drafts of one inbox, newest first. ``status``: one or several (``["draft", "scheduled"]``)."""
|
|
809
|
+
return cast("Page[Draft]", self._c._send(r.draft_list(inbox_id, status, thread_id, cursor, limit)))
|
|
810
|
+
|
|
811
|
+
def list_all(
|
|
812
|
+
self,
|
|
813
|
+
*,
|
|
814
|
+
inbox_id: Optional[str] = None,
|
|
815
|
+
status: Optional[DraftStatuses] = None,
|
|
816
|
+
thread_id: Optional[str] = None,
|
|
817
|
+
cursor: Optional[str] = None,
|
|
818
|
+
limit: Optional[int] = None,
|
|
819
|
+
) -> Page[Draft]:
|
|
820
|
+
"""Drafts of every inbox of the workspace (``GET /v1/drafts``), optionally filtered."""
|
|
821
|
+
req = r.draft_list_all(inbox_id, status, thread_id, cursor, limit)
|
|
822
|
+
return cast("Page[Draft]", self._c._send(req))
|
|
823
|
+
|
|
824
|
+
def get(self, inbox_id: str, draft_id: str) -> Draft:
|
|
825
|
+
return cast(Draft, self._c._send(r.draft_get(inbox_id, draft_id)))
|
|
826
|
+
|
|
827
|
+
def update(
|
|
828
|
+
self,
|
|
829
|
+
inbox_id: str,
|
|
830
|
+
draft_id: str,
|
|
831
|
+
*,
|
|
832
|
+
to: Optional[Recipients] = None,
|
|
833
|
+
subject: NullableText = NOT_GIVEN,
|
|
834
|
+
text: NullableText = NOT_GIVEN,
|
|
835
|
+
html: NullableText = NOT_GIVEN,
|
|
836
|
+
cc: Optional[Recipients] = None,
|
|
837
|
+
bcc: Optional[Recipients] = None,
|
|
838
|
+
attachments: Optional[Sequence[Union[AttachmentInput, DraftKeep]]] = None,
|
|
839
|
+
labels: Optional[Sequence[str]] = None,
|
|
840
|
+
metadata: Optional[MetadataPatch] = None,
|
|
841
|
+
send_at: NullableSendAt = NOT_GIVEN,
|
|
842
|
+
data: Any = NOT_GIVEN,
|
|
843
|
+
type: Optional[MessageType] = None,
|
|
844
|
+
) -> Draft:
|
|
845
|
+
"""Edit a ``draft`` or ``scheduled`` draft (else ``409 draft_not_editable``).
|
|
846
|
+
|
|
847
|
+
``subject``/``text``/``html=None`` clear them; ``attachments`` replaces the list (``{"id": ...}``
|
|
848
|
+
keeps one already on the draft); ``send_at`` reschedules and ``send_at=None`` unschedules."""
|
|
849
|
+
req = r.draft_update(
|
|
850
|
+
inbox_id,
|
|
851
|
+
draft_id,
|
|
852
|
+
to,
|
|
853
|
+
subject,
|
|
854
|
+
text,
|
|
855
|
+
html,
|
|
856
|
+
cc,
|
|
857
|
+
bcc,
|
|
858
|
+
attachments,
|
|
859
|
+
labels,
|
|
860
|
+
metadata,
|
|
861
|
+
send_at,
|
|
862
|
+
data,
|
|
863
|
+
type,
|
|
864
|
+
)
|
|
865
|
+
return cast(Draft, self._c._send(req))
|
|
866
|
+
|
|
867
|
+
def delete(self, inbox_id: str, draft_id: str) -> None:
|
|
868
|
+
self._c._send(r.draft_delete(inbox_id, draft_id))
|
|
869
|
+
|
|
870
|
+
def send(self, inbox_id: str, draft_id: str, *, idempotency_key: Optional[str] = None) -> DraftSendResult:
|
|
871
|
+
"""Send now. A refused send raises the API error and leaves the draft as it was (``error`` set)."""
|
|
872
|
+
return cast(DraftSendResult, self._c._send(r.draft_send(inbox_id, draft_id, idempotency_key)))
|
|
873
|
+
|
|
874
|
+
def schedule(self, inbox_id: str, draft_id: str, send_at: SendAt) -> Draft:
|
|
875
|
+
"""Send automatically at ``send_at`` (1 minute to 30 days ahead; ``400 invalid_send_at``)."""
|
|
876
|
+
return cast(Draft, self._c._send(r.draft_schedule(inbox_id, draft_id, send_at)))
|
|
877
|
+
|
|
878
|
+
def cancel(self, inbox_id: str, draft_id: str) -> Draft:
|
|
879
|
+
"""Cancel a draft or its scheduled send (terminal)."""
|
|
880
|
+
return cast(Draft, self._c._send(r.draft_cancel(inbox_id, draft_id)))
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
class Threads:
|
|
884
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
885
|
+
self._c = client
|
|
886
|
+
|
|
887
|
+
def list(
|
|
888
|
+
self,
|
|
889
|
+
inbox_id: str,
|
|
890
|
+
cursor: Optional[str] = None,
|
|
891
|
+
limit: Optional[int] = None,
|
|
892
|
+
labels: Optional[Sequence[str]] = None,
|
|
893
|
+
before: Optional[str] = None,
|
|
894
|
+
after: Optional[str] = None,
|
|
895
|
+
participant: Optional[str] = None,
|
|
896
|
+
subject: Optional[str] = None,
|
|
897
|
+
ascending: Optional[bool] = None,
|
|
898
|
+
) -> Page[Thread]:
|
|
899
|
+
"""One inbox's threads, newest activity first.
|
|
900
|
+
|
|
901
|
+
Filters combine; ``participant`` and ``subject`` are substrings.
|
|
902
|
+
"""
|
|
903
|
+
return cast(
|
|
904
|
+
"Page[Thread]",
|
|
905
|
+
self._c._send(
|
|
906
|
+
r.thread_list(
|
|
907
|
+
inbox_id,
|
|
908
|
+
cursor,
|
|
909
|
+
limit,
|
|
910
|
+
labels=labels,
|
|
911
|
+
before=before,
|
|
912
|
+
after=after,
|
|
913
|
+
participant=participant,
|
|
914
|
+
subject=subject,
|
|
915
|
+
ascending=ascending,
|
|
916
|
+
)
|
|
917
|
+
),
|
|
918
|
+
)
|
|
919
|
+
|
|
920
|
+
def list_all(
|
|
921
|
+
self,
|
|
922
|
+
inbox_id: Optional[str] = None,
|
|
923
|
+
cursor: Optional[str] = None,
|
|
924
|
+
limit: Optional[int] = None,
|
|
925
|
+
labels: Optional[Sequence[str]] = None,
|
|
926
|
+
before: Optional[str] = None,
|
|
927
|
+
after: Optional[str] = None,
|
|
928
|
+
participant: Optional[str] = None,
|
|
929
|
+
subject: Optional[str] = None,
|
|
930
|
+
ascending: Optional[bool] = None,
|
|
931
|
+
) -> Page[Thread]:
|
|
932
|
+
"""Threads across every inbox the key can see, with the same filters as :meth:`list`."""
|
|
933
|
+
return cast(
|
|
934
|
+
"Page[Thread]",
|
|
935
|
+
self._c._send(
|
|
936
|
+
r.thread_list_all(
|
|
937
|
+
cursor,
|
|
938
|
+
limit,
|
|
939
|
+
inbox_id=inbox_id,
|
|
940
|
+
labels=labels,
|
|
941
|
+
before=before,
|
|
942
|
+
after=after,
|
|
943
|
+
participant=participant,
|
|
944
|
+
subject=subject,
|
|
945
|
+
ascending=ascending,
|
|
946
|
+
)
|
|
947
|
+
),
|
|
948
|
+
)
|
|
949
|
+
|
|
950
|
+
def delete(self, thread_id: str) -> DeletedThread:
|
|
951
|
+
"""Delete a thread with all its messages and attachments."""
|
|
952
|
+
return cast(DeletedThread, self._c._send(r.thread_delete(thread_id)))
|
|
953
|
+
|
|
954
|
+
def get(self, thread_id: str) -> ThreadWithMessages:
|
|
955
|
+
"""A thread plus its messages in order."""
|
|
956
|
+
return cast(ThreadWithMessages, self._c._send(r.thread_get(thread_id)))
|
|
957
|
+
|
|
958
|
+
def update(
|
|
959
|
+
self,
|
|
960
|
+
thread_id: str,
|
|
961
|
+
metadata: Optional[MetadataPatch] = None,
|
|
962
|
+
add_labels: Optional[Sequence[str]] = None,
|
|
963
|
+
remove_labels: Optional[Sequence[str]] = None,
|
|
964
|
+
) -> Thread:
|
|
965
|
+
"""Set thread labels and metadata (merged: a ``None`` value deletes a key). Returns the thread."""
|
|
966
|
+
return cast(Thread, self._c._send(r.thread_update(thread_id, metadata, add_labels, remove_labels)))
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
class Webhooks:
|
|
970
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
971
|
+
self._c = client
|
|
972
|
+
|
|
973
|
+
def create(
|
|
974
|
+
self,
|
|
975
|
+
url: str,
|
|
976
|
+
events: Optional[Sequence[WebhookEventType]] = None,
|
|
977
|
+
inbox_ids: InboxIds = NOT_GIVEN,
|
|
978
|
+
secret: Optional[str] = None,
|
|
979
|
+
payload: Optional[WebhookPayload] = None,
|
|
980
|
+
headers: Optional[Mapping[str, str]] = None,
|
|
981
|
+
) -> Webhook:
|
|
982
|
+
"""Create a webhook. The returned ``secret`` is only shown here: store it.
|
|
983
|
+
|
|
984
|
+
``payload="envelope"`` sends ids, addresses, subject and labels only (no bodies).
|
|
985
|
+
"""
|
|
986
|
+
return cast(
|
|
987
|
+
Webhook, self._c._send(r.webhook_create(url, events, inbox_ids, secret, payload, headers))
|
|
988
|
+
)
|
|
989
|
+
|
|
990
|
+
def list(self) -> Page[Webhook]:
|
|
991
|
+
return cast("Page[Webhook]", self._c._send(r.webhook_list()))
|
|
992
|
+
|
|
993
|
+
def get(self, webhook_id: str) -> Webhook:
|
|
994
|
+
return cast(Webhook, self._c._send(r.webhook_get(webhook_id)))
|
|
995
|
+
|
|
996
|
+
def update(
|
|
997
|
+
self,
|
|
998
|
+
webhook_id: str,
|
|
999
|
+
url: Optional[str] = None,
|
|
1000
|
+
events: Optional[Sequence[WebhookEventType]] = None,
|
|
1001
|
+
inbox_ids: InboxIds = NOT_GIVEN,
|
|
1002
|
+
enabled: Optional[bool] = None,
|
|
1003
|
+
payload: Optional[WebhookPayload] = None,
|
|
1004
|
+
headers: Optional[Mapping[str, str]] = None,
|
|
1005
|
+
) -> Webhook:
|
|
1006
|
+
"""Update a webhook. Pass ``inbox_ids=None`` explicitly to subscribe to all inboxes."""
|
|
1007
|
+
req = r.webhook_update(webhook_id, url, events, inbox_ids, enabled, payload, headers)
|
|
1008
|
+
return cast(Webhook, self._c._send(req))
|
|
1009
|
+
|
|
1010
|
+
def delete(self, webhook_id: str) -> None:
|
|
1011
|
+
self._c._send(r.webhook_delete(webhook_id))
|
|
1012
|
+
|
|
1013
|
+
def test(self, webhook_id: str) -> WebhookTestResult:
|
|
1014
|
+
"""Send a ``webhook.test`` event."""
|
|
1015
|
+
return cast(WebhookTestResult, self._c._send(r.webhook_test(webhook_id)))
|
|
1016
|
+
|
|
1017
|
+
def rotate_secret(self, webhook_id: str, secret: Optional[str] = None) -> Webhook:
|
|
1018
|
+
"""Replace the signing secret (yours, or a generated one); the new ``secret`` is returned once.
|
|
1019
|
+
|
|
1020
|
+
Deliveries are signed with it from then on: let your endpoint accept both secrets while you switch.
|
|
1021
|
+
"""
|
|
1022
|
+
return cast(Webhook, self._c._send(r.webhook_rotate_secret(webhook_id, secret)))
|
|
1023
|
+
|
|
1024
|
+
def events(self) -> builtins.list[WebhookCatalogEntry]:
|
|
1025
|
+
"""The event catalog: every event type with a description and example bodies."""
|
|
1026
|
+
return cast("builtins.list[WebhookCatalogEntry]", self._c._send(r.webhook_events())["data"])
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
class Lists:
|
|
1030
|
+
"""Allow/block lists for receiving, sending and replying (permission ``lists:manage``)."""
|
|
1031
|
+
|
|
1032
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1033
|
+
self._c = client
|
|
1034
|
+
|
|
1035
|
+
def list(
|
|
1036
|
+
self,
|
|
1037
|
+
inbox_id: Optional[str] = None,
|
|
1038
|
+
direction: Optional[ListDirection] = None,
|
|
1039
|
+
kind: Optional[ListKind] = None,
|
|
1040
|
+
) -> ListEntries:
|
|
1041
|
+
return cast(ListEntries, self._c._send(r.list_entries(inbox_id, direction, kind)))
|
|
1042
|
+
|
|
1043
|
+
def create(
|
|
1044
|
+
self, direction: ListDirection, kind: ListKind, pattern: str, inbox_id: Optional[str] = None
|
|
1045
|
+
) -> ListEntry:
|
|
1046
|
+
"""Add ``a@b.com`` or a domain (``b.com``, subdomains included). No ``inbox_id`` = workspace-wide."""
|
|
1047
|
+
return cast(ListEntry, self._c._send(r.list_create(direction, kind, pattern, inbox_id)))
|
|
1048
|
+
|
|
1049
|
+
def delete(self, entry_id: str) -> None:
|
|
1050
|
+
self._c._send(r.list_delete(entry_id))
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
class Contacts:
|
|
1054
|
+
"""Contacts: external addresses the workspace has exchanged mail with (created automatically)."""
|
|
1055
|
+
|
|
1056
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1057
|
+
self._c = client
|
|
1058
|
+
|
|
1059
|
+
def list(
|
|
1060
|
+
self,
|
|
1061
|
+
q: Optional[str] = None,
|
|
1062
|
+
label: Optional[str] = None,
|
|
1063
|
+
metadata: Optional[MetadataFilter] = None,
|
|
1064
|
+
cursor: Optional[str] = None,
|
|
1065
|
+
limit: Optional[int] = None,
|
|
1066
|
+
kind: Union[ContactKind, Sequence[ContactKind], None] = None,
|
|
1067
|
+
domain: Optional[str] = None,
|
|
1068
|
+
) -> Page[Contact]:
|
|
1069
|
+
"""Newest activity first. ``q`` matches address/name; ``metadata`` filters by exact value.
|
|
1070
|
+
|
|
1071
|
+
``kind`` is one kind or several (every kind when left out); ``domain`` is the part after the @.
|
|
1072
|
+
"""
|
|
1073
|
+
req = r.contact_list(q, label, metadata, cursor, limit, kind, domain)
|
|
1074
|
+
return cast("Page[Contact]", self._c._send(req))
|
|
1075
|
+
|
|
1076
|
+
def domains(
|
|
1077
|
+
self, kind: Union[ContactKind, Sequence[ContactKind], None] = None, limit: Optional[int] = None
|
|
1078
|
+
) -> ContactDomainList:
|
|
1079
|
+
"""Contacts counted per domain (most first), free-mail providers left out. ``kind`` as in ``list``."""
|
|
1080
|
+
return cast(ContactDomainList, self._c._send(r.contact_domains(kind, limit)))
|
|
1081
|
+
|
|
1082
|
+
def get(self, contact_id: str) -> ContactWithThreads:
|
|
1083
|
+
"""A contact plus its 10 most recent threads."""
|
|
1084
|
+
return cast(ContactWithThreads, self._c._send(r.contact_get(contact_id)))
|
|
1085
|
+
|
|
1086
|
+
def by_address(self, address: str) -> ContactWithThreads:
|
|
1087
|
+
"""Look a contact up by address. ``NotFoundError`` if the workspace never exchanged mail with it."""
|
|
1088
|
+
return cast(ContactWithThreads, self._c._send(r.contact_by_address(address)))
|
|
1089
|
+
|
|
1090
|
+
def update(
|
|
1091
|
+
self,
|
|
1092
|
+
contact_id: str,
|
|
1093
|
+
name: Nullable = NOT_GIVEN,
|
|
1094
|
+
notes: Nullable = NOT_GIVEN,
|
|
1095
|
+
metadata: Optional[MetadataPatch] = None,
|
|
1096
|
+
add_labels: Optional[Sequence[str]] = None,
|
|
1097
|
+
remove_labels: Optional[Sequence[str]] = None,
|
|
1098
|
+
kind: Optional[ContactKind] = None,
|
|
1099
|
+
) -> Contact:
|
|
1100
|
+
"""Update notes (up to 10,000 chars; ``None`` clears), name, labels, metadata or kind.
|
|
1101
|
+
|
|
1102
|
+
Metadata is merged: given keys are set, a ``None`` value deletes the key. A name or kind set here is
|
|
1103
|
+
never changed by later mail (``name_source`` / ``kind_source`` become ``manual``).
|
|
1104
|
+
"""
|
|
1105
|
+
req = r.contact_update(contact_id, name, notes, metadata, add_labels, remove_labels, kind)
|
|
1106
|
+
return cast(Contact, self._c._send(req))
|
|
1107
|
+
|
|
1108
|
+
def delete(self, contact_id: str, forget: bool = False) -> None:
|
|
1109
|
+
"""Delete the contact (name, notes, labels, metadata); its messages stay. Needs an org-wide key.
|
|
1110
|
+
|
|
1111
|
+
``forget=True``: mail from the address no longer creates the contact (only a hash of it is kept);
|
|
1112
|
+
sending to it does.
|
|
1113
|
+
"""
|
|
1114
|
+
self._c._send(r.contact_delete(contact_id, forget))
|
|
1115
|
+
|
|
1116
|
+
def delete_many(
|
|
1117
|
+
self,
|
|
1118
|
+
kind: Optional[Sequence[ContactKind]] = None,
|
|
1119
|
+
domain: Optional[str] = None,
|
|
1120
|
+
forget: bool = False,
|
|
1121
|
+
dry_run: bool = False,
|
|
1122
|
+
) -> ContactBulkDeleteResult:
|
|
1123
|
+
"""Delete every contact of these kinds and/or this domain, up to 1,000 per call (``has_more``: call
|
|
1124
|
+
again). ``dry_run`` only counts; ``forget`` as in ``delete``. Needs an org-wide key."""
|
|
1125
|
+
req = r.contact_delete_many(kind, domain, forget, dry_run)
|
|
1126
|
+
return cast(ContactBulkDeleteResult, self._c._send(req))
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
class Knowledge:
|
|
1130
|
+
"""Knowledge documents used as context for reply drafts (per inbox, or workspace-wide)."""
|
|
1131
|
+
|
|
1132
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1133
|
+
self._c = client
|
|
1134
|
+
|
|
1135
|
+
def list(
|
|
1136
|
+
self, inbox_id: Optional[str] = None, cursor: Optional[str] = None, limit: Optional[int] = None
|
|
1137
|
+
) -> Page[KnowledgeListItem]:
|
|
1138
|
+
"""Documents without bodies (each has an ``excerpt``). ``inbox_id``: one inbox's documents."""
|
|
1139
|
+
return cast("Page[KnowledgeListItem]", self._c._send(r.knowledge_list(inbox_id, cursor, limit)))
|
|
1140
|
+
|
|
1141
|
+
def create(self, title: str, body: str, inbox_id: Optional[str] = None) -> KnowledgeDoc:
|
|
1142
|
+
"""Create a document. Without ``inbox_id`` it applies to every inbox of the workspace."""
|
|
1143
|
+
return cast(KnowledgeDoc, self._c._send(r.knowledge_create(title, body, inbox_id)))
|
|
1144
|
+
|
|
1145
|
+
def get(self, doc_id: str) -> KnowledgeDoc:
|
|
1146
|
+
return cast(KnowledgeDoc, self._c._send(r.knowledge_get(doc_id)))
|
|
1147
|
+
|
|
1148
|
+
def update(
|
|
1149
|
+
self,
|
|
1150
|
+
doc_id: str,
|
|
1151
|
+
title: Optional[str] = None,
|
|
1152
|
+
body: Optional[str] = None,
|
|
1153
|
+
inbox_id: Nullable = NOT_GIVEN,
|
|
1154
|
+
) -> KnowledgeDoc:
|
|
1155
|
+
"""Update a document. Pass ``inbox_id=None`` explicitly to make it workspace-wide."""
|
|
1156
|
+
return cast(KnowledgeDoc, self._c._send(r.knowledge_update(doc_id, title, body, inbox_id)))
|
|
1157
|
+
|
|
1158
|
+
def delete(self, doc_id: str) -> None:
|
|
1159
|
+
self._c._send(r.knowledge_delete(doc_id))
|
|
1160
|
+
|
|
1161
|
+
def search(
|
|
1162
|
+
self, q: str, inbox_id: Optional[str] = None, limit: Optional[int] = None
|
|
1163
|
+
) -> KnowledgeSearchResults:
|
|
1164
|
+
"""Ranked full-text search. With ``inbox_id``, workspace-wide documents are included too."""
|
|
1165
|
+
return cast(KnowledgeSearchResults, self._c._send(r.knowledge_search(q, inbox_id, limit)))
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
class IdentityClients:
|
|
1169
|
+
"""Apps ("relying parties") the workspace registered for Sign in with Agentboxd (``identity:manage``)."""
|
|
1170
|
+
|
|
1171
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1172
|
+
self._c = client
|
|
1173
|
+
|
|
1174
|
+
def list(self) -> Page[IdentityClient]:
|
|
1175
|
+
return cast("Page[IdentityClient]", self._c._send(r.identity_client_list()))
|
|
1176
|
+
|
|
1177
|
+
def create(
|
|
1178
|
+
self,
|
|
1179
|
+
name: str,
|
|
1180
|
+
type: IdentityClientType,
|
|
1181
|
+
redirect_uris: Optional[Sequence[str]] = None,
|
|
1182
|
+
allowed_scopes: Optional[Sequence[IdentityScope]] = None,
|
|
1183
|
+
subject_type: Optional[IdentitySubjectType] = None,
|
|
1184
|
+
homepage_url: Optional[str] = None,
|
|
1185
|
+
) -> IdentityClientWithSecret:
|
|
1186
|
+
"""Register an app. ``client_secret`` (confidential clients) is only returned here: store it.
|
|
1187
|
+
|
|
1188
|
+
``redirect_uris`` is required for ``confidential``/``public`` clients, forbidden for ``verify_only``.
|
|
1189
|
+
"""
|
|
1190
|
+
req = r.identity_client_create(name, type, redirect_uris, allowed_scopes, subject_type, homepage_url)
|
|
1191
|
+
return cast(IdentityClientWithSecret, self._c._send(req))
|
|
1192
|
+
|
|
1193
|
+
def get(self, client_id: str) -> IdentityClient:
|
|
1194
|
+
"""``client_id`` is the client's ``id`` (UUID)."""
|
|
1195
|
+
return cast(IdentityClient, self._c._send(r.identity_client_get(client_id)))
|
|
1196
|
+
|
|
1197
|
+
def update(
|
|
1198
|
+
self,
|
|
1199
|
+
client_id: str,
|
|
1200
|
+
name: Optional[str] = None,
|
|
1201
|
+
redirect_uris: Optional[Sequence[str]] = None,
|
|
1202
|
+
allowed_scopes: Optional[Sequence[IdentityScope]] = None,
|
|
1203
|
+
homepage_url: Nullable = NOT_GIVEN,
|
|
1204
|
+
enabled: Optional[bool] = None,
|
|
1205
|
+
) -> IdentityClient:
|
|
1206
|
+
"""Pass ``homepage_url=None`` explicitly to clear it."""
|
|
1207
|
+
req = r.identity_client_update(client_id, name, redirect_uris, allowed_scopes, homepage_url, enabled)
|
|
1208
|
+
return cast(IdentityClient, self._c._send(req))
|
|
1209
|
+
|
|
1210
|
+
def delete(self, client_id: str) -> None:
|
|
1211
|
+
"""Permanent: the client's tokens stop being accepted at the token and userinfo endpoints."""
|
|
1212
|
+
self._c._send(r.identity_client_delete(client_id))
|
|
1213
|
+
|
|
1214
|
+
def rotate_secret(self, client_id: str) -> IdentityClientWithSecret:
|
|
1215
|
+
"""A new secret, shown once; the old one stops working."""
|
|
1216
|
+
return cast(IdentityClientWithSecret, self._c._send(r.identity_client_rotate_secret(client_id)))
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
class InboxIdentities:
|
|
1220
|
+
"""The per-inbox Sign in with Agentboxd switch and sign-in history."""
|
|
1221
|
+
|
|
1222
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1223
|
+
self._c = client
|
|
1224
|
+
|
|
1225
|
+
def get(self, inbox_id: str) -> InboxIdentity:
|
|
1226
|
+
return cast(InboxIdentity, self._c._send(r.inbox_identity_get(inbox_id)))
|
|
1227
|
+
|
|
1228
|
+
def update(self, inbox_id: str, enabled: bool) -> InboxIdentity:
|
|
1229
|
+
"""``enabled=False`` immediately refuses new tokens, sign-ins and userinfo (``identity:manage``)."""
|
|
1230
|
+
return cast(InboxIdentity, self._c._send(r.inbox_identity_update(inbox_id, enabled)))
|
|
1231
|
+
|
|
1232
|
+
def sign_ins(
|
|
1233
|
+
self, inbox_id: str, cursor: Optional[str] = None, limit: Optional[int] = None
|
|
1234
|
+
) -> Page[IdentitySignIn]:
|
|
1235
|
+
"""Newest first."""
|
|
1236
|
+
return cast("Page[IdentitySignIn]", self._c._send(r.inbox_identity_sign_ins(inbox_id, cursor, limit)))
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
class Identities:
|
|
1240
|
+
"""Identity-only agents: an Agentboxd identity without a mailbox (sign in to apps, no mail).
|
|
1241
|
+
|
|
1242
|
+
They count toward the plan's ``identities`` limit, not ``inboxes``. Mint tokens with
|
|
1243
|
+
``client.identity.token(identity_id=..., audience=...)``."""
|
|
1244
|
+
|
|
1245
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1246
|
+
self._c = client
|
|
1247
|
+
|
|
1248
|
+
def create(
|
|
1249
|
+
self,
|
|
1250
|
+
*,
|
|
1251
|
+
username: Optional[str] = None,
|
|
1252
|
+
display_name: Optional[str] = None,
|
|
1253
|
+
client_id: Optional[str] = None,
|
|
1254
|
+
metadata: Optional[MetadataPatch] = None,
|
|
1255
|
+
card: Optional[AgentCardInput] = None,
|
|
1256
|
+
) -> IdentityRecord:
|
|
1257
|
+
"""Create an identity-only agent. Idempotent on ``client_id`` (returns the existing one).
|
|
1258
|
+
``card``: also create its agent card (needs ``directory:write``)."""
|
|
1259
|
+
return cast(
|
|
1260
|
+
IdentityRecord,
|
|
1261
|
+
self._c._send(r.identity_create(username, display_name, client_id, metadata, card=card)),
|
|
1262
|
+
)
|
|
1263
|
+
|
|
1264
|
+
def list(
|
|
1265
|
+
self,
|
|
1266
|
+
*,
|
|
1267
|
+
cursor: Optional[str] = None,
|
|
1268
|
+
limit: Optional[int] = None,
|
|
1269
|
+
metadata: Optional[MetadataFilter] = None,
|
|
1270
|
+
) -> "Page[IdentityRecord]":
|
|
1271
|
+
"""Newest first. ``metadata`` filters by exact value, e.g. ``{"team": "research"}``."""
|
|
1272
|
+
return cast("Page[IdentityRecord]", self._c._send(r.identity_list(cursor, limit, metadata)))
|
|
1273
|
+
|
|
1274
|
+
def get(self, identity_id: str) -> IdentityRecord:
|
|
1275
|
+
return cast(IdentityRecord, self._c._send(r.identity_get(identity_id)))
|
|
1276
|
+
|
|
1277
|
+
def update(
|
|
1278
|
+
self,
|
|
1279
|
+
identity_id: str,
|
|
1280
|
+
*,
|
|
1281
|
+
display_name: Nullable = NOT_GIVEN,
|
|
1282
|
+
metadata: Optional[MetadataPatch] = None,
|
|
1283
|
+
) -> IdentityRecord:
|
|
1284
|
+
"""Change the display name (``None`` clears it) or metadata (merged; ``None`` deletes a key)."""
|
|
1285
|
+
return cast(IdentityRecord, self._c._send(r.identity_update(identity_id, display_name, metadata)))
|
|
1286
|
+
|
|
1287
|
+
def delete(self, identity_id: str) -> None:
|
|
1288
|
+
"""Soft delete: the handle is never reissued; tokens and sign-ins stop at once."""
|
|
1289
|
+
self._c._send(r.identity_delete(identity_id))
|
|
1290
|
+
|
|
1291
|
+
def pause(self, identity_id: str, *, reason: Optional[str] = None) -> Inbox:
|
|
1292
|
+
"""Kill switch: identity tokens, approvals and exchanges are refused until ``resume``."""
|
|
1293
|
+
return cast(Inbox, self._c._send(r.inbox_pause(identity_id, reason)))
|
|
1294
|
+
|
|
1295
|
+
def resume(self, identity_id: str) -> ResumedInbox:
|
|
1296
|
+
return cast(ResumedInbox, self._c._send(r.inbox_resume(identity_id)))
|
|
1297
|
+
|
|
1298
|
+
|
|
1299
|
+
class Identity:
|
|
1300
|
+
"""Sign in with Agentboxd: the agent's identity (an inbox or an identity-only agent), OpenID Connect."""
|
|
1301
|
+
|
|
1302
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1303
|
+
self._c = client
|
|
1304
|
+
self.clients = IdentityClients(client)
|
|
1305
|
+
self.inbox = InboxIdentities(client)
|
|
1306
|
+
|
|
1307
|
+
def token(
|
|
1308
|
+
self,
|
|
1309
|
+
inbox_id: Optional[str] = None,
|
|
1310
|
+
audience: Optional[str] = None,
|
|
1311
|
+
nonce: Optional[str] = None,
|
|
1312
|
+
scope: Optional[Union[str, Sequence[IdentityScope]]] = None,
|
|
1313
|
+
expires_in: Optional[int] = None,
|
|
1314
|
+
*,
|
|
1315
|
+
identity_id: Optional[str] = None,
|
|
1316
|
+
) -> IdentityToken:
|
|
1317
|
+
"""Mint a short-lived (at most 5 minutes), single-use ID token for the relying party ``audience``
|
|
1318
|
+
(its ``client_id``). Needs the ``identity:sign`` permission. ``scope`` defaults to ``openid email``.
|
|
1319
|
+
|
|
1320
|
+
Pass ``inbox_id`` for an inbox or ``identity_id`` for an identity-only agent (which never gets
|
|
1321
|
+
the ``email`` scope: it has no mailbox).
|
|
1322
|
+
"""
|
|
1323
|
+
req = r.identity_token(inbox_id, audience, nonce, scope, expires_in, identity_id)
|
|
1324
|
+
return cast(IdentityToken, self._c._send(req))
|
|
1325
|
+
|
|
1326
|
+
|
|
1327
|
+
def _card_body(
|
|
1328
|
+
name: Optional[str],
|
|
1329
|
+
description: Nullable,
|
|
1330
|
+
capabilities: Optional[Mapping[str, Any]],
|
|
1331
|
+
documentation_url: Nullable,
|
|
1332
|
+
visibility: Optional[str],
|
|
1333
|
+
routing: Optional[str],
|
|
1334
|
+
handle: Nullable = NOT_GIVEN,
|
|
1335
|
+
indexable: Optional[bool] = None,
|
|
1336
|
+
) -> dict[str, Any]:
|
|
1337
|
+
body: dict[str, Any] = {}
|
|
1338
|
+
if name is not None:
|
|
1339
|
+
body["name"] = name
|
|
1340
|
+
if not isinstance(description, NotGiven):
|
|
1341
|
+
body["description"] = description
|
|
1342
|
+
if capabilities is not None:
|
|
1343
|
+
body["capabilities"] = dict(capabilities)
|
|
1344
|
+
if not isinstance(documentation_url, NotGiven):
|
|
1345
|
+
body["documentation_url"] = documentation_url
|
|
1346
|
+
if visibility is not None:
|
|
1347
|
+
body["visibility"] = visibility
|
|
1348
|
+
if routing is not None:
|
|
1349
|
+
body["routing"] = routing
|
|
1350
|
+
if not isinstance(handle, NotGiven):
|
|
1351
|
+
body["handle"] = handle
|
|
1352
|
+
if indexable is not None:
|
|
1353
|
+
body["indexable"] = indexable
|
|
1354
|
+
return body
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
def _escalation_body(
|
|
1358
|
+
contacts: Union[Sequence[str], NotGiven],
|
|
1359
|
+
triggers: Union[Mapping[str, bool], NotGiven],
|
|
1360
|
+
delivery: Union[str, NotGiven],
|
|
1361
|
+
max_per_hour: Union[int, NotGiven],
|
|
1362
|
+
quiet_hours: Union[QuietHours, NotGiven, None],
|
|
1363
|
+
include_excerpt: Union[bool, NotGiven],
|
|
1364
|
+
) -> dict[str, Any]:
|
|
1365
|
+
return {
|
|
1366
|
+
"contacts": contacts if isinstance(contacts, NotGiven) else list(contacts),
|
|
1367
|
+
"triggers": triggers if isinstance(triggers, NotGiven) else dict(triggers),
|
|
1368
|
+
"delivery": delivery,
|
|
1369
|
+
"max_per_hour": max_per_hour,
|
|
1370
|
+
"quiet_hours": quiet_hours,
|
|
1371
|
+
"include_excerpt": include_excerpt,
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
def _inbox_escalation_body(
|
|
1376
|
+
override: Union[bool, NotGiven],
|
|
1377
|
+
contacts: Union[Sequence[str], NotGiven],
|
|
1378
|
+
triggers: Union[Mapping[str, bool], NotGiven, None],
|
|
1379
|
+
) -> dict[str, Any]:
|
|
1380
|
+
return {
|
|
1381
|
+
"override": override,
|
|
1382
|
+
"contacts": contacts if isinstance(contacts, NotGiven) else list(contacts),
|
|
1383
|
+
"triggers": triggers if triggers is None or isinstance(triggers, NotGiven) else dict(triggers),
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
|
|
1387
|
+
class Agents:
|
|
1388
|
+
"""aSIM bundle and agent card of an inbox or identity-only agent (``inbox_id`` is either id).
|
|
1389
|
+
|
|
1390
|
+
Reading needs ``inboxes:read``; changes need ``directory:write``. Inbox-scoped keys manage their own
|
|
1391
|
+
card."""
|
|
1392
|
+
|
|
1393
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1394
|
+
self._c = client
|
|
1395
|
+
self.keys = AgentKeys(client)
|
|
1396
|
+
|
|
1397
|
+
def get(self, inbox_id: str) -> AgentBundle:
|
|
1398
|
+
return cast(AgentBundle, self._c._send(r.agent_get(inbox_id)))
|
|
1399
|
+
|
|
1400
|
+
def update(
|
|
1401
|
+
self,
|
|
1402
|
+
inbox_id: str,
|
|
1403
|
+
*,
|
|
1404
|
+
name: Optional[str] = None,
|
|
1405
|
+
description: Nullable = NOT_GIVEN,
|
|
1406
|
+
capabilities: Optional[Mapping[str, Any]] = None,
|
|
1407
|
+
documentation_url: Nullable = NOT_GIVEN,
|
|
1408
|
+
visibility: Optional[AgentCardVisibility] = None,
|
|
1409
|
+
routing: Optional[Literal["relay", "direct_preferred"]] = None,
|
|
1410
|
+
handle: Nullable = NOT_GIVEN,
|
|
1411
|
+
indexable: Optional[bool] = None,
|
|
1412
|
+
) -> AgentBundle:
|
|
1413
|
+
"""Create the card (private by default) or update it.
|
|
1414
|
+
|
|
1415
|
+
``None`` for ``description`` / ``documentation_url`` / ``handle`` clears them. ``visibility="public"``
|
|
1416
|
+
lists the agent in the public directory (claimed workspace, org-scoped key, plan limit
|
|
1417
|
+
``public_listings``); ``indexable=True`` lets search engines index its public page; ``handle`` is the
|
|
1418
|
+
agent part of ``@workspace/agent``."""
|
|
1419
|
+
body = _card_body(
|
|
1420
|
+
name, description, capabilities, documentation_url, visibility, routing, handle, indexable
|
|
1421
|
+
)
|
|
1422
|
+
return cast(AgentBundle, self._c._send(r.agent_update(inbox_id, body)))
|
|
1423
|
+
|
|
1424
|
+
def delete(self, inbox_id: str) -> None:
|
|
1425
|
+
"""Delete the card: the agent leaves the directory at once. The inbox is unchanged."""
|
|
1426
|
+
self._c._send(r.agent_delete(inbox_id))
|
|
1427
|
+
|
|
1428
|
+
def revoke(self, inbox_id: str, *, reason: Optional[str] = None) -> AgentBundle:
|
|
1429
|
+
"""The agent stops signing; directory verify answers ``revoked``. Mail keeps flowing."""
|
|
1430
|
+
return cast(AgentBundle, self._c._send(r.agent_revoke(inbox_id, reason)))
|
|
1431
|
+
|
|
1432
|
+
def restore(self, inbox_id: str) -> AgentBundle:
|
|
1433
|
+
"""Undo a revoke (not an operator suspension: 403 ``agent_suspended``)."""
|
|
1434
|
+
return cast(AgentBundle, self._c._send(r.agent_restore(inbox_id)))
|
|
1435
|
+
|
|
1436
|
+
def oasf(self, inbox_id: str) -> dict[str, Any]:
|
|
1437
|
+
"""The card as an OASF record (``GET /v1/inboxes/:id/agent/oasf``)."""
|
|
1438
|
+
return cast(dict[str, Any], self._c._send(r.agent_oasf(inbox_id)))
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
class AgentKeys:
|
|
1442
|
+
"""Agent-held signing keys (aSIM phase 2): list needs ``inboxes:read``, changes ``identity:manage``.
|
|
1443
|
+
|
|
1444
|
+
The private key never leaves the agent: generate it with ``agentboxd.identity.generate_agent_key`` and
|
|
1445
|
+
register the public key with a proof (``agentboxd.identity.create_key_proof``)."""
|
|
1446
|
+
|
|
1447
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1448
|
+
self._c = client
|
|
1449
|
+
|
|
1450
|
+
def list(self, inbox_id: str) -> AgentKeyList:
|
|
1451
|
+
return cast(AgentKeyList, self._c._send(r.agent_keys_list(inbox_id)))
|
|
1452
|
+
|
|
1453
|
+
def register(self, inbox_id: str, *, public_jwk: Mapping[str, Any], proof: str) -> AgentKey:
|
|
1454
|
+
"""Register a public key (Ed25519 or P-256) with its proof of possession.
|
|
1455
|
+
|
|
1456
|
+
At most 3 active and 20 in all: retired and revoked keys count."""
|
|
1457
|
+
return cast(AgentKey, self._c._send(r.agent_keys_register(inbox_id, public_jwk, proof)))
|
|
1458
|
+
|
|
1459
|
+
def retire(self, inbox_id: str, kid: str) -> AgentKey:
|
|
1460
|
+
"""Rotation: no new signatures with it; old ones stay valid."""
|
|
1461
|
+
return cast(AgentKey, self._c._send(r.agent_keys_retire(inbox_id, kid)))
|
|
1462
|
+
|
|
1463
|
+
def revoke(
|
|
1464
|
+
self, inbox_id: str, kid: str, *, reason: Optional[str] = None, since: Optional[str] = None
|
|
1465
|
+
) -> AgentKey:
|
|
1466
|
+
"""Compromise: signatures made at or after ``since`` (ISO time, default now) no longer verify."""
|
|
1467
|
+
return cast(AgentKey, self._c._send(r.agent_keys_revoke(inbox_id, kid, reason, since)))
|
|
1468
|
+
|
|
1469
|
+
|
|
1470
|
+
class Directory:
|
|
1471
|
+
"""The agent directory (permission ``directory:read``): resolve, verify, search, report. Rate limited; 503
|
|
1472
|
+
``directory_disabled`` when the server hasn't enabled it."""
|
|
1473
|
+
|
|
1474
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1475
|
+
self._c = client
|
|
1476
|
+
|
|
1477
|
+
def resolve(self, address: Optional[str] = None, *, handle: Optional[str] = None) -> ResolvedAgent:
|
|
1478
|
+
"""Your workspace sees the full card, a publicly listed card is public for everyone, others see the
|
|
1479
|
+
minimal card. Pass an ``address`` or a ``handle`` (``@acme/billing``). 404 ``agent_not_found`` on a
|
|
1480
|
+
miss."""
|
|
1481
|
+
return cast(ResolvedAgent, self._c._send(r.directory_resolve(address, handle)))
|
|
1482
|
+
|
|
1483
|
+
def verify(
|
|
1484
|
+
self, *, signature: Optional[str] = None, address: Optional[str] = None
|
|
1485
|
+
) -> DirectoryVerifyResult:
|
|
1486
|
+
"""Pass a message's ``agent["signature"]`` (signature + sender's current status) or an ``address``."""
|
|
1487
|
+
return cast(DirectoryVerifyResult, self._c._send(r.directory_verify(signature, address)))
|
|
1488
|
+
|
|
1489
|
+
def search(
|
|
1490
|
+
self,
|
|
1491
|
+
*,
|
|
1492
|
+
q: Optional[str] = None,
|
|
1493
|
+
capability: Optional[str] = None,
|
|
1494
|
+
type: Optional[MessageType] = None,
|
|
1495
|
+
limit: Optional[int] = None,
|
|
1496
|
+
cursor: Optional[str] = None,
|
|
1497
|
+
scope: Optional[Literal["workspace", "public"]] = None,
|
|
1498
|
+
) -> "Page[AgentCard]":
|
|
1499
|
+
"""Active cards with ``workspace`` visibility in your workspace, or with ``scope="public"`` the public
|
|
1500
|
+
directory (publicly listed cards of every workspace)."""
|
|
1501
|
+
req = r.directory_search(q, capability, type, limit, cursor, scope)
|
|
1502
|
+
return cast("Page[AgentCard]", self._c._send(req))
|
|
1503
|
+
|
|
1504
|
+
def get_handle(self) -> WorkspaceHandle:
|
|
1505
|
+
"""The workspace handle (``@acme``) and previous ones that still redirect."""
|
|
1506
|
+
return cast(WorkspaceHandle, self._c._send(r.directory_handle_get()))
|
|
1507
|
+
|
|
1508
|
+
def set_handle(self, handle: str) -> WorkspaceHandle:
|
|
1509
|
+
"""Claim or rename the workspace handle (org-scoped key; the old one redirects for 90 days)."""
|
|
1510
|
+
return cast(WorkspaceHandle, self._c._send(r.directory_handle_set(handle)))
|
|
1511
|
+
|
|
1512
|
+
def release_handle(self) -> WorkspaceHandle:
|
|
1513
|
+
"""Release the workspace handle. It can never be claimed again."""
|
|
1514
|
+
return cast(WorkspaceHandle, self._c._send(r.directory_handle_release()))
|
|
1515
|
+
|
|
1516
|
+
def report(
|
|
1517
|
+
self,
|
|
1518
|
+
address: str,
|
|
1519
|
+
reason: DirectoryReportReason,
|
|
1520
|
+
*,
|
|
1521
|
+
details: Optional[str] = None,
|
|
1522
|
+
message_id: Optional[str] = None,
|
|
1523
|
+
) -> DirectoryReportResult:
|
|
1524
|
+
"""At most 10 per workspace per day; the agent's owner learns the reason, never who reported."""
|
|
1525
|
+
return cast(
|
|
1526
|
+
DirectoryReportResult, self._c._send(r.directory_report(address, reason, details, message_id))
|
|
1527
|
+
)
|
|
1528
|
+
|
|
1529
|
+
|
|
1530
|
+
class PublicDirectory:
|
|
1531
|
+
"""The public agent directory (``/v1/public/*``, aSIM phase 2): publicly listed agents, no permission
|
|
1532
|
+
needed. Rate limited per IP; 503 ``public_directory_disabled`` when the server hasn't enabled it."""
|
|
1533
|
+
|
|
1534
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1535
|
+
self._c = client
|
|
1536
|
+
|
|
1537
|
+
def search(
|
|
1538
|
+
self,
|
|
1539
|
+
*,
|
|
1540
|
+
q: Optional[str] = None,
|
|
1541
|
+
capability: Optional[str] = None,
|
|
1542
|
+
type: Optional[MessageType] = None,
|
|
1543
|
+
limit: Optional[int] = None,
|
|
1544
|
+
cursor: Optional[str] = None,
|
|
1545
|
+
) -> "Page[PublicAgentCard]":
|
|
1546
|
+
req = r.public_agents_search(q, capability, type, limit, cursor)
|
|
1547
|
+
return cast("Page[PublicAgentCard]", self._c._send(req))
|
|
1548
|
+
|
|
1549
|
+
def get(self, address: str) -> PublicAgent:
|
|
1550
|
+
return cast(PublicAgent, self._c._send(r.public_agent(address)))
|
|
1551
|
+
|
|
1552
|
+
def a2a_card(self, address: str) -> dict[str, Any]:
|
|
1553
|
+
"""The A2A agent card (signed by Agentboxd when agent messaging is on)."""
|
|
1554
|
+
return cast(dict[str, Any], self._c._send(r.public_agent(address, "agent-card.json")))
|
|
1555
|
+
|
|
1556
|
+
def oasf(self, address: str) -> dict[str, Any]:
|
|
1557
|
+
return cast(dict[str, Any], self._c._send(r.public_agent(address, "oasf.json")))
|
|
1558
|
+
|
|
1559
|
+
def keys(self, address: str) -> PublicAgentKeys:
|
|
1560
|
+
"""The agent's own public keys, for ``agentboxd.identity.verify_author_signature``."""
|
|
1561
|
+
return cast(PublicAgentKeys, self._c._send(r.public_agent(address, "keys.json")))
|
|
1562
|
+
|
|
1563
|
+
def handle(self, workspace: str, agent: str) -> PublicHandle:
|
|
1564
|
+
"""``@workspace/agent`` → the agent (follows renames within their 90-day redirect)."""
|
|
1565
|
+
return cast(PublicHandle, self._c._send(r.public_handle(workspace, agent)))
|
|
1566
|
+
|
|
1567
|
+
|
|
1568
|
+
class AccountApi:
|
|
1569
|
+
"""The workspace behind the key (``GET /v1/account``) and claim requests for agent-created workspaces."""
|
|
1570
|
+
|
|
1571
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1572
|
+
self._c = client
|
|
1573
|
+
|
|
1574
|
+
def get(self) -> Account:
|
|
1575
|
+
"""Claim status, effective limits and (unclaimed workspaces) today's recipient count."""
|
|
1576
|
+
return cast(Account, self._c._send(r.account_get()))
|
|
1577
|
+
|
|
1578
|
+
def request_claim(self, email: str) -> ClaimRequestResult:
|
|
1579
|
+
"""Email ``email`` a single-use link to claim this agent-created workspace (at most 3 a day)."""
|
|
1580
|
+
return cast(ClaimRequestResult, self._c._send(r.signup_claim(email)))
|
|
1581
|
+
|
|
1582
|
+
def add_agent(self, kind: Optional[str] = None) -> AddAgentResult:
|
|
1583
|
+
"""Another agent (``"mailbox"`` or ``"identity"``) in this unclaimed workspace, with its own key.
|
|
1584
|
+
|
|
1585
|
+
Use this instead of signing up again for the same owner: up to 3 agents until a human claims
|
|
1586
|
+
the workspace.
|
|
1587
|
+
"""
|
|
1588
|
+
return cast(AddAgentResult, self._c._send(r.signup_add_agent(kind)))
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
class Forwarding:
|
|
1592
|
+
"""Automatic forwarding: every inbound message of an inbox goes to up to 3 confirmed addresses.
|
|
1593
|
+
|
|
1594
|
+
Adding an address emails it a confirmation link; nothing is forwarded before it confirms. Needs
|
|
1595
|
+
``inboxes:write`` (and ``messages:send`` to add or resend); listing needs ``inboxes:read``.
|
|
1596
|
+
"""
|
|
1597
|
+
|
|
1598
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1599
|
+
self._c = client
|
|
1600
|
+
|
|
1601
|
+
def list(self, inbox_id: str) -> builtins.list[InboxForward]:
|
|
1602
|
+
return cast("builtins.list[InboxForward]", self._c._send(r.forwarding_list(inbox_id))["data"])
|
|
1603
|
+
|
|
1604
|
+
def add(self, inbox_id: str, address: str, *, skip_flagged: Optional[bool] = None) -> InboxForward:
|
|
1605
|
+
"""Adds a pending address and emails it the confirmation link."""
|
|
1606
|
+
return cast(InboxForward, self._c._send(r.forwarding_add(inbox_id, address, skip_flagged)))
|
|
1607
|
+
|
|
1608
|
+
def resend(self, inbox_id: str, forward_id: str) -> InboxForward:
|
|
1609
|
+
"""A new confirmation link for a pending address."""
|
|
1610
|
+
return cast(InboxForward, self._c._send(r.forwarding_resend(inbox_id, forward_id)))
|
|
1611
|
+
|
|
1612
|
+
def remove(self, inbox_id: str, forward_id: str) -> builtins.dict[str, Any]:
|
|
1613
|
+
return cast("builtins.dict[str, Any]", self._c._send(r.forwarding_remove(inbox_id, forward_id)))
|
|
1614
|
+
|
|
1615
|
+
|
|
1616
|
+
class EscalationApi:
|
|
1617
|
+
"""Human on call (permission ``escalation:manage``): who is emailed when an agent's mail needs a person.
|
|
1618
|
+
|
|
1619
|
+
New contacts get a confirmation email and receive nothing until they confirm.
|
|
1620
|
+
"""
|
|
1621
|
+
|
|
1622
|
+
def __init__(self, client: "Agentboxd") -> None:
|
|
1623
|
+
self._c = client
|
|
1624
|
+
|
|
1625
|
+
def get(self) -> EscalationSettings:
|
|
1626
|
+
"""Workspace contacts, triggers, delivery (immediate or digest), hourly limit, quiet hours."""
|
|
1627
|
+
return cast(EscalationSettings, self._c._send(r.escalation_get()))
|
|
1628
|
+
|
|
1629
|
+
def update(
|
|
1630
|
+
self,
|
|
1631
|
+
*,
|
|
1632
|
+
contacts: Union[Sequence[str], NotGiven] = NOT_GIVEN,
|
|
1633
|
+
triggers: Union[Mapping[str, bool], NotGiven] = NOT_GIVEN,
|
|
1634
|
+
delivery: Union[Literal["immediate", "digest"], NotGiven] = NOT_GIVEN,
|
|
1635
|
+
max_per_hour: Union[int, NotGiven] = NOT_GIVEN,
|
|
1636
|
+
quiet_hours: Union[QuietHours, NotGiven, None] = NOT_GIVEN,
|
|
1637
|
+
include_excerpt: Union[bool, NotGiven] = NOT_GIVEN,
|
|
1638
|
+
) -> EscalationSettings:
|
|
1639
|
+
"""Arguments left out keep their value; ``contacts`` (at most 5) replaces the list;
|
|
1640
|
+
``quiet_hours=None`` removes the quiet hours."""
|
|
1641
|
+
req = r.escalation_update(
|
|
1642
|
+
_escalation_body(contacts, triggers, delivery, max_per_hour, quiet_hours, include_excerpt)
|
|
1643
|
+
)
|
|
1644
|
+
return cast(EscalationSettings, self._c._send(req))
|
|
1645
|
+
|
|
1646
|
+
def get_inbox(self, inbox_id: str) -> InboxEscalation:
|
|
1647
|
+
"""The inbox's override: its own contacts (and triggers) instead of the workspace's."""
|
|
1648
|
+
return cast(InboxEscalation, self._c._send(r.inbox_escalation_get(inbox_id)))
|
|
1649
|
+
|
|
1650
|
+
def update_inbox(
|
|
1651
|
+
self,
|
|
1652
|
+
inbox_id: str,
|
|
1653
|
+
*,
|
|
1654
|
+
override: Union[bool, NotGiven] = NOT_GIVEN,
|
|
1655
|
+
contacts: Union[Sequence[str], NotGiven] = NOT_GIVEN,
|
|
1656
|
+
triggers: Union[Mapping[str, bool], NotGiven, None] = NOT_GIVEN,
|
|
1657
|
+
) -> InboxEscalation:
|
|
1658
|
+
"""``override=True`` sends this inbox's escalations to its own ``contacts``.
|
|
1659
|
+
|
|
1660
|
+
``triggers=None`` uses the workspace triggers."""
|
|
1661
|
+
req = r.inbox_escalation_update(inbox_id, _inbox_escalation_body(override, contacts, triggers))
|
|
1662
|
+
return cast(InboxEscalation, self._c._send(req))
|
|
1663
|
+
|
|
1664
|
+
|
|
1665
|
+
class Agentboxd(_BaseClient):
|
|
1666
|
+
"""Synchronous Agentboxd client.
|
|
1667
|
+
|
|
1668
|
+
>>> mr = Agentboxd() # reads AGENTBOXD_API_KEY / AGENTBOXD_BASE_URL
|
|
1669
|
+
>>> inbox = mr.inboxes.create(client_id="support-agent")
|
|
1670
|
+
>>> mr.messages.send(inbox["id"], to="someone@example.com", subject="Hi", text="Hello!")
|
|
1671
|
+
"""
|
|
1672
|
+
|
|
1673
|
+
def __init__(
|
|
1674
|
+
self,
|
|
1675
|
+
api_key: Optional[str] = None,
|
|
1676
|
+
base_url: Optional[str] = None,
|
|
1677
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
1678
|
+
*,
|
|
1679
|
+
http_client: Optional[httpx.Client] = None,
|
|
1680
|
+
) -> None:
|
|
1681
|
+
super().__init__(api_key, base_url, timeout)
|
|
1682
|
+
self._owns_http = http_client is None
|
|
1683
|
+
self._http = http_client if http_client is not None else httpx.Client(timeout=timeout)
|
|
1684
|
+
self.inboxes = Inboxes(self)
|
|
1685
|
+
self.domains = Domains(self)
|
|
1686
|
+
self.messages = Messages(self)
|
|
1687
|
+
self.drafts = Drafts(self)
|
|
1688
|
+
self.threads = Threads(self)
|
|
1689
|
+
self.webhooks = Webhooks(self)
|
|
1690
|
+
self.contacts = Contacts(self)
|
|
1691
|
+
self.knowledge = Knowledge(self)
|
|
1692
|
+
self.lists = Lists(self)
|
|
1693
|
+
self.identity = Identity(self)
|
|
1694
|
+
self.identities = Identities(self)
|
|
1695
|
+
self.account = AccountApi(self)
|
|
1696
|
+
self.escalation = EscalationApi(self)
|
|
1697
|
+
self.forwarding = Forwarding(self)
|
|
1698
|
+
self.agents = Agents(self)
|
|
1699
|
+
self.directory = Directory(self)
|
|
1700
|
+
self.public_directory = PublicDirectory(self)
|
|
1701
|
+
|
|
1702
|
+
@classmethod
|
|
1703
|
+
def signup(
|
|
1704
|
+
cls,
|
|
1705
|
+
*,
|
|
1706
|
+
agent_name: Optional[str] = None,
|
|
1707
|
+
owner_email: Optional[str] = None,
|
|
1708
|
+
base_url: Optional[str] = None,
|
|
1709
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
1710
|
+
http_client: Optional[httpx.Client] = None,
|
|
1711
|
+
max_iterations: int = 2**32,
|
|
1712
|
+
kind: Optional[str] = None,
|
|
1713
|
+
) -> "Signup[Agentboxd]":
|
|
1714
|
+
"""Agent self-signup, no API key needed.
|
|
1715
|
+
|
|
1716
|
+
Fetches a proof-of-work challenge, solves it (a few seconds of CPU) and creates an unclaimed
|
|
1717
|
+
workspace with one inbox. Returns a ready client plus the API's answer; ``api_key`` is shown only
|
|
1718
|
+
once, so store it. Until a human claims the workspace (``owner_email`` here, or
|
|
1719
|
+
``client.account.request_claim(email)`` later) sending is limited and webhooks are off.
|
|
1720
|
+
|
|
1721
|
+
>>> s = Agentboxd.signup(agent_name="research-agent", owner_email="me@example.com")
|
|
1722
|
+
>>> s.api_key, s.inbox["address"]
|
|
1723
|
+
|
|
1724
|
+
``kind="identity"`` creates an identity-only agent (sign in to apps, no mailbox) instead of an
|
|
1725
|
+
inbox: ``s.identity`` is set and ``s.inbox`` is ``None``. It can mint identity tokens once a human
|
|
1726
|
+
has claimed the workspace.
|
|
1727
|
+
"""
|
|
1728
|
+
url = _signup_base_url(base_url)
|
|
1729
|
+
http = http_client if http_client is not None else httpx.Client(timeout=timeout)
|
|
1730
|
+
try:
|
|
1731
|
+
try:
|
|
1732
|
+
ch = cast(
|
|
1733
|
+
SignupChallenge, cls._parse(http.request(**_public_kwargs(url, r.signup_challenge())))
|
|
1734
|
+
)
|
|
1735
|
+
solution = solve_signup_challenge(ch["challenge"], int(ch["difficulty"]), max_iterations)
|
|
1736
|
+
req = r.signup_create(ch["challenge"], solution, agent_name, owner_email, kind)
|
|
1737
|
+
result = cast(SignupResult, cls._parse(http.request(**_public_kwargs(url, req))))
|
|
1738
|
+
except httpx.TimeoutException as exc:
|
|
1739
|
+
raise APIConnectionError(f"Request timed out: {exc}", code="timeout") from exc
|
|
1740
|
+
except httpx.TransportError as exc:
|
|
1741
|
+
raise APIConnectionError(f"Connection error: {exc}") from exc
|
|
1742
|
+
finally:
|
|
1743
|
+
if http_client is None:
|
|
1744
|
+
http.close()
|
|
1745
|
+
client = cls(api_key=result["api_key"], base_url=url, timeout=timeout, http_client=http_client)
|
|
1746
|
+
return Signup(client=client, result=result)
|
|
1747
|
+
|
|
1748
|
+
def search(
|
|
1749
|
+
self,
|
|
1750
|
+
q: str,
|
|
1751
|
+
inbox_id: Optional[str] = None,
|
|
1752
|
+
cursor: Optional[str] = None,
|
|
1753
|
+
limit: Optional[int] = None,
|
|
1754
|
+
channel: Optional[MessageChannel] = None,
|
|
1755
|
+
type: Optional[MessageType] = None,
|
|
1756
|
+
) -> Page[SearchResult]:
|
|
1757
|
+
"""Full-text search (web-search syntax: ``"exact phrase"``, ``-exclude``, ``or``)."""
|
|
1758
|
+
return cast("Page[SearchResult]", self._send(r.search(q, inbox_id, cursor, limit, channel, type)))
|
|
1759
|
+
|
|
1760
|
+
def metrics(
|
|
1761
|
+
self,
|
|
1762
|
+
from_: Optional[str] = None,
|
|
1763
|
+
to: Optional[str] = None,
|
|
1764
|
+
tz: Optional[str] = None,
|
|
1765
|
+
inbox_id: Optional[str] = None,
|
|
1766
|
+
bucket: Optional[MetricsBucket] = None,
|
|
1767
|
+
) -> Metrics:
|
|
1768
|
+
"""Sent/received/delivery counts bucketed in ``tz`` (IANA), a 30-day heatmap and resources.
|
|
1769
|
+
|
|
1770
|
+
``from_``/``to``: ISO timestamps or dates (default: the last 30 days, at most 90).
|
|
1771
|
+
"""
|
|
1772
|
+
return cast(Metrics, self._send(r.metrics(from_, to, tz, inbox_id, bucket)))
|
|
1773
|
+
|
|
1774
|
+
def emergency_stop(self, reason: Optional[str] = None) -> EmergencyStopResult:
|
|
1775
|
+
"""Emergency stop (permission ``workspace:emergency``, workspace keys): every inbox and identity of
|
|
1776
|
+
the workspace stops sending (423 ``workspace_stopped``), minting identity tokens and sending
|
|
1777
|
+
scheduled drafts. Reads keep working. Only a workspace owner can resume, in the dashboard."""
|
|
1778
|
+
return cast(EmergencyStopResult, self._send(r.emergency_stop(reason)))
|
|
1779
|
+
|
|
1780
|
+
def deliverability(self) -> DeliverabilitySummary:
|
|
1781
|
+
"""Bounce and complaint rates (7 and 30 days), suppressed contacts, your domains' SPF/DKIM/DMARC
|
|
1782
|
+
and the shared IP's blocklist status (permission ``metrics:read``, workspace keys)."""
|
|
1783
|
+
return cast(DeliverabilitySummary, self._send(r.deliverability()))
|
|
1784
|
+
|
|
1785
|
+
def stream_token(self) -> StreamToken:
|
|
1786
|
+
"""A single-use, 60-second WebSocket URL for ``GET /v1/stream`` (any WebSocket client).
|
|
1787
|
+
|
|
1788
|
+
For a ready-made client with reconnect and resume, use :meth:`AsyncAgentboxd.stream`.
|
|
1789
|
+
"""
|
|
1790
|
+
return cast(StreamToken, self._send(r.stream_token()))
|
|
1791
|
+
|
|
1792
|
+
def _send(self, req: Request) -> Any:
|
|
1793
|
+
try:
|
|
1794
|
+
response = self._http.request(**self._build(req))
|
|
1795
|
+
except httpx.TimeoutException as exc:
|
|
1796
|
+
raise APIConnectionError(f"Request timed out: {exc}", code="timeout") from exc
|
|
1797
|
+
except httpx.TransportError as exc:
|
|
1798
|
+
raise APIConnectionError(f"Connection error: {exc}") from exc
|
|
1799
|
+
return self._parse(response)
|
|
1800
|
+
|
|
1801
|
+
def close(self) -> None:
|
|
1802
|
+
if self._owns_http:
|
|
1803
|
+
self._http.close()
|
|
1804
|
+
|
|
1805
|
+
def __enter__(self: _SelfT) -> _SelfT:
|
|
1806
|
+
return self
|
|
1807
|
+
|
|
1808
|
+
def __exit__(
|
|
1809
|
+
self,
|
|
1810
|
+
exc_type: Optional[type[BaseException]],
|
|
1811
|
+
exc: Optional[BaseException],
|
|
1812
|
+
tb: Optional[TracebackType],
|
|
1813
|
+
) -> None:
|
|
1814
|
+
self.close()
|
|
1815
|
+
|
|
1816
|
+
|
|
1817
|
+
# =====================================================================
|
|
1818
|
+
# async
|
|
1819
|
+
# =====================================================================
|
|
1820
|
+
|
|
1821
|
+
|
|
1822
|
+
class AsyncInboxes:
|
|
1823
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
1824
|
+
self._c = client
|
|
1825
|
+
|
|
1826
|
+
async def create(
|
|
1827
|
+
self,
|
|
1828
|
+
*,
|
|
1829
|
+
username: Optional[str] = None,
|
|
1830
|
+
display_name: Optional[str] = None,
|
|
1831
|
+
client_id: Optional[str] = None,
|
|
1832
|
+
metadata: Optional[MetadataPatch] = None,
|
|
1833
|
+
domain: Optional[str] = None,
|
|
1834
|
+
card: Optional[AgentCardInput] = None,
|
|
1835
|
+
) -> Inbox:
|
|
1836
|
+
"""Create an inbox. Idempotent on ``client_id`` (returns the existing inbox).
|
|
1837
|
+
|
|
1838
|
+
``domain``: a verified custom domain of the workspace (default: the server's agent domain).
|
|
1839
|
+
``card``: also create its agent card (needs ``directory:write``); the response then has ``card``."""
|
|
1840
|
+
req = r.inbox_create(username, display_name, client_id, metadata, domain, card=card)
|
|
1841
|
+
return cast(Inbox, await self._c._send(req))
|
|
1842
|
+
|
|
1843
|
+
async def create_temporary(
|
|
1844
|
+
self,
|
|
1845
|
+
*,
|
|
1846
|
+
ttl_seconds: int = DEFAULT_TEMPORARY_TTL,
|
|
1847
|
+
display_name: Optional[str] = None,
|
|
1848
|
+
metadata: Optional[MetadataPatch] = None,
|
|
1849
|
+
) -> Inbox:
|
|
1850
|
+
"""Create a temporary, receive-only inbox (random address on the temporary domain).
|
|
1851
|
+
|
|
1852
|
+
It and all its mail are wiped at ``expires_at``; ``ttl_seconds`` is 60 to 86400."""
|
|
1853
|
+
req = r.inbox_create(None, display_name, None, metadata, None, ttl_seconds)
|
|
1854
|
+
return cast(Inbox, await self._c._send(req))
|
|
1855
|
+
|
|
1856
|
+
async def list(
|
|
1857
|
+
self,
|
|
1858
|
+
*,
|
|
1859
|
+
cursor: Optional[str] = None,
|
|
1860
|
+
limit: Optional[int] = None,
|
|
1861
|
+
metadata: Optional[MetadataFilter] = None,
|
|
1862
|
+
include_temporary: Optional[bool] = None,
|
|
1863
|
+
temporary: Optional[bool] = None,
|
|
1864
|
+
) -> Page[Inbox]:
|
|
1865
|
+
"""List inboxes, newest first. ``metadata`` filters by exact value, e.g. ``{"team": "billing"}``.
|
|
1866
|
+
|
|
1867
|
+
Temporary inboxes are excluded unless ``include_temporary=True``;
|
|
1868
|
+
``temporary=True`` lists only them."""
|
|
1869
|
+
req = r.inbox_list(cursor, limit, metadata, include_temporary, temporary)
|
|
1870
|
+
return cast("Page[Inbox]", await self._c._send(req))
|
|
1871
|
+
|
|
1872
|
+
async def get(self, inbox_id: str) -> Inbox:
|
|
1873
|
+
return cast(Inbox, await self._c._send(r.inbox_get(inbox_id)))
|
|
1874
|
+
|
|
1875
|
+
async def update(
|
|
1876
|
+
self,
|
|
1877
|
+
inbox_id: str,
|
|
1878
|
+
*,
|
|
1879
|
+
display_name: Nullable = NOT_GIVEN,
|
|
1880
|
+
metadata: Optional[MetadataPatch] = None,
|
|
1881
|
+
ttl_seconds: Optional[int] = None,
|
|
1882
|
+
promotions_filter: Union[bool, NotGiven, None] = NOT_GIVEN,
|
|
1883
|
+
) -> Inbox:
|
|
1884
|
+
"""Change the display name (``None`` clears it) or metadata (merged; ``None`` deletes a key).
|
|
1885
|
+
|
|
1886
|
+
``ttl_seconds`` extends a temporary inbox from now (at most 24 h after its creation).
|
|
1887
|
+
``promotions_filter`` turns the Promotions & spam view on or off (``None``: back to the default)."""
|
|
1888
|
+
req = r.inbox_update(inbox_id, display_name, metadata, ttl_seconds, promotions_filter)
|
|
1889
|
+
return cast(Inbox, await self._c._send(req))
|
|
1890
|
+
|
|
1891
|
+
async def delete(self, inbox_id: str) -> None:
|
|
1892
|
+
"""Soft-delete an inbox (its address is never reused). A temporary inbox is wiped at once."""
|
|
1893
|
+
await self._c._send(r.inbox_delete(inbox_id))
|
|
1894
|
+
|
|
1895
|
+
async def pause(self, inbox_id: str, *, reason: Optional[str] = None) -> Inbox:
|
|
1896
|
+
"""Kill switch: every send from the inbox is refused (423 ``inbox_paused``) until ``resume``.
|
|
1897
|
+
|
|
1898
|
+
Inbound mail is still stored; its events and AI categorisation are held until then."""
|
|
1899
|
+
return cast(Inbox, await self._c._send(r.inbox_pause(inbox_id, reason)))
|
|
1900
|
+
|
|
1901
|
+
async def resume(self, inbox_id: str) -> ResumedInbox:
|
|
1902
|
+
"""Sending works again; held inbound events are emitted in arrival order (``released_events``)."""
|
|
1903
|
+
return cast(ResumedInbox, await self._c._send(r.inbox_resume(inbox_id)))
|
|
1904
|
+
|
|
1905
|
+
async def consume(
|
|
1906
|
+
self,
|
|
1907
|
+
inbox_id: str,
|
|
1908
|
+
handler: "_consume.AsyncHandler",
|
|
1909
|
+
*,
|
|
1910
|
+
concurrency: int = 1,
|
|
1911
|
+
lease_seconds: int = _consume.DEFAULT_LEASE_SECONDS,
|
|
1912
|
+
wait: float = _consume.DEFAULT_WAIT,
|
|
1913
|
+
consumer: Optional[str] = None,
|
|
1914
|
+
enriched: Optional[bool] = None,
|
|
1915
|
+
analysis: Optional[Literal["completed"]] = None,
|
|
1916
|
+
include_unscreened: Optional[bool] = None,
|
|
1917
|
+
include_held: Optional[bool] = None,
|
|
1918
|
+
stop: "Optional[asyncio.Event]" = None,
|
|
1919
|
+
retry_delay_seconds: float = 5,
|
|
1920
|
+
max_retry_delay_seconds: float = 300,
|
|
1921
|
+
paused_poll_seconds: float = 10,
|
|
1922
|
+
on_error: "Optional[_consume.ErrorHandler]" = None,
|
|
1923
|
+
) -> None:
|
|
1924
|
+
"""Crash-safe consumer loop over the claim/ack queue (async handler). See :meth:`Inboxes.consume`.
|
|
1925
|
+
|
|
1926
|
+
Runs until ``stop`` (an ``asyncio.Event``) is set; running handlers finish first."""
|
|
1927
|
+
await _consume.consume_async(
|
|
1928
|
+
self._c.messages,
|
|
1929
|
+
inbox_id,
|
|
1930
|
+
handler,
|
|
1931
|
+
_consume.ConsumeOptions(
|
|
1932
|
+
concurrency=concurrency,
|
|
1933
|
+
lease_seconds=lease_seconds,
|
|
1934
|
+
wait=wait,
|
|
1935
|
+
consumer=consumer,
|
|
1936
|
+
enriched=enriched,
|
|
1937
|
+
analysis=analysis,
|
|
1938
|
+
include_unscreened=include_unscreened,
|
|
1939
|
+
include_held=include_held,
|
|
1940
|
+
retry_delay_seconds=retry_delay_seconds,
|
|
1941
|
+
max_retry_delay_seconds=max_retry_delay_seconds,
|
|
1942
|
+
paused_poll_seconds=paused_poll_seconds,
|
|
1943
|
+
on_error=on_error,
|
|
1944
|
+
),
|
|
1945
|
+
stop,
|
|
1946
|
+
)
|
|
1947
|
+
|
|
1948
|
+
|
|
1949
|
+
class AsyncDomains:
|
|
1950
|
+
"""Custom domains: connect a domain you own, publish its ``records``, then ``verify``."""
|
|
1951
|
+
|
|
1952
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
1953
|
+
self._c = client
|
|
1954
|
+
|
|
1955
|
+
async def create(self, domain: str, *, receiving: Optional[bool] = None) -> Domain:
|
|
1956
|
+
return cast(Domain, await self._c._send(r.domain_create(domain, receiving)))
|
|
1957
|
+
|
|
1958
|
+
async def list(self) -> Page[Domain]:
|
|
1959
|
+
return cast("Page[Domain]", await self._c._send(r.domain_list()))
|
|
1960
|
+
|
|
1961
|
+
async def get(self, domain_id: str) -> Domain:
|
|
1962
|
+
return cast(Domain, await self._c._send(r.domain_get(domain_id)))
|
|
1963
|
+
|
|
1964
|
+
async def zone_file(self, domain_id: str) -> DomainZoneFile:
|
|
1965
|
+
"""The records to publish as a BIND zone file (``filename`` and ``content``).
|
|
1966
|
+
|
|
1967
|
+
Write ``content`` to a file and import it at a DNS provider that takes one."""
|
|
1968
|
+
return cast(DomainZoneFile, await self._c._send(r.domain_zone_file(domain_id)))
|
|
1969
|
+
|
|
1970
|
+
async def verify(self, domain_id: str) -> Domain:
|
|
1971
|
+
"""Check the DNS records now (at most once per 10 s per domain)."""
|
|
1972
|
+
return cast(Domain, await self._c._send(r.domain_verify(domain_id)))
|
|
1973
|
+
|
|
1974
|
+
async def update(self, domain_id: str, *, receiving: Optional[bool] = None) -> Domain:
|
|
1975
|
+
return cast(Domain, await self._c._send(r.domain_update(domain_id, receiving)))
|
|
1976
|
+
|
|
1977
|
+
async def delete(self, domain_id: str, *, force: bool = False) -> None:
|
|
1978
|
+
"""409 ``domain_in_use`` while live inboxes use it, unless ``force`` (which deletes those inboxes)."""
|
|
1979
|
+
await self._c._send(r.domain_delete(domain_id, force))
|
|
1980
|
+
|
|
1981
|
+
async def rotate_dkim(self, domain_id: str) -> Domain:
|
|
1982
|
+
"""Start a DKIM key rotation: a new key on the other selector (``dkim_next`` in ``records``).
|
|
1983
|
+
|
|
1984
|
+
Publish it next to the current record; signing switches as soon as it is seen."""
|
|
1985
|
+
return cast(Domain, await self._c._send(r.domain_dkim_rotate(domain_id)))
|
|
1986
|
+
|
|
1987
|
+
async def activate_dkim(self, domain_id: str) -> Domain:
|
|
1988
|
+
"""Check DNS now and switch signing to the new key (409 ``dkim_record_not_found`` until published)."""
|
|
1989
|
+
return cast(Domain, await self._c._send(r.domain_dkim_activate(domain_id)))
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
class AsyncMessages:
|
|
1993
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
1994
|
+
self._c = client
|
|
1995
|
+
|
|
1996
|
+
async def send(
|
|
1997
|
+
self,
|
|
1998
|
+
inbox_id: str,
|
|
1999
|
+
to: Recipients,
|
|
2000
|
+
subject: str,
|
|
2001
|
+
text: Optional[str] = None,
|
|
2002
|
+
html: Optional[str] = None,
|
|
2003
|
+
cc: Optional[Recipients] = None,
|
|
2004
|
+
bcc: Optional[Recipients] = None,
|
|
2005
|
+
attachments: Optional[Sequence[AttachmentInput]] = None,
|
|
2006
|
+
labels: Optional[Sequence[str]] = None,
|
|
2007
|
+
idempotency_key: Optional[str] = None,
|
|
2008
|
+
data: Any = None,
|
|
2009
|
+
type: Optional[MessageType] = None,
|
|
2010
|
+
agent_signature: Optional[str] = None,
|
|
2011
|
+
) -> Message:
|
|
2012
|
+
"""Send from ``inbox_id``. Returns the message with ``status: "queued"``.
|
|
2013
|
+
|
|
2014
|
+
``data`` (a JSON object or list, at most 64 KB) and ``type`` (``message``, ``task``, ``event``) make
|
|
2015
|
+
it a structured agent message: Agentboxd recipients get it natively (``channel: "agent"``, see
|
|
2016
|
+
``delivery``), everyone else by email with the data attached. ``text``, ``html`` or ``data`` is
|
|
2017
|
+
required."""
|
|
2018
|
+
req = r.message_send(
|
|
2019
|
+
inbox_id,
|
|
2020
|
+
to,
|
|
2021
|
+
subject,
|
|
2022
|
+
text,
|
|
2023
|
+
html,
|
|
2024
|
+
cc,
|
|
2025
|
+
bcc,
|
|
2026
|
+
attachments,
|
|
2027
|
+
labels,
|
|
2028
|
+
idempotency_key,
|
|
2029
|
+
data,
|
|
2030
|
+
type,
|
|
2031
|
+
agent_signature,
|
|
2032
|
+
)
|
|
2033
|
+
return cast(Message, await self._c._send(req))
|
|
2034
|
+
|
|
2035
|
+
async def forward(
|
|
2036
|
+
self,
|
|
2037
|
+
inbox_id: str,
|
|
2038
|
+
message_id: str,
|
|
2039
|
+
to: Recipients,
|
|
2040
|
+
cc: Optional[Recipients] = None,
|
|
2041
|
+
bcc: Optional[Recipients] = None,
|
|
2042
|
+
text: Optional[str] = None,
|
|
2043
|
+
html: Optional[str] = None,
|
|
2044
|
+
include_attachments: Optional[bool] = None,
|
|
2045
|
+
labels: Optional[Sequence[str]] = None,
|
|
2046
|
+
idempotency_key: Optional[str] = None,
|
|
2047
|
+
) -> Message:
|
|
2048
|
+
"""Forward a message to new recipients, in a new thread: ``text`` (your note) above the original,
|
|
2049
|
+
with its attachments unless ``include_attachments=False``."""
|
|
2050
|
+
req = r.message_forward(
|
|
2051
|
+
inbox_id, message_id, to, cc, bcc, text, html, include_attachments, labels, idempotency_key
|
|
2052
|
+
)
|
|
2053
|
+
return cast(Message, await self._c._send(req))
|
|
2054
|
+
|
|
2055
|
+
async def batch_get(
|
|
2056
|
+
self,
|
|
2057
|
+
ids: Sequence[str],
|
|
2058
|
+
*,
|
|
2059
|
+
include_unscreened: Optional[bool] = None,
|
|
2060
|
+
include_held: Optional[bool] = None,
|
|
2061
|
+
) -> BatchMessages:
|
|
2062
|
+
"""Up to 100 messages by id; ids you can't see come back in ``missing``."""
|
|
2063
|
+
req = r.messages_batch_get(ids, include_unscreened, include_held)
|
|
2064
|
+
return cast(BatchMessages, await self._c._send(req))
|
|
2065
|
+
|
|
2066
|
+
async def batch_update(
|
|
2067
|
+
self,
|
|
2068
|
+
ids: Sequence[str],
|
|
2069
|
+
add_labels: Optional[Sequence[str]] = None,
|
|
2070
|
+
remove_labels: Optional[Sequence[str]] = None,
|
|
2071
|
+
is_read: Optional[bool] = None,
|
|
2072
|
+
) -> BatchMessages:
|
|
2073
|
+
"""The same label and read changes on up to 100 messages."""
|
|
2074
|
+
return cast(
|
|
2075
|
+
BatchMessages,
|
|
2076
|
+
await self._c._send(r.messages_batch_update(ids, add_labels, remove_labels, is_read)),
|
|
2077
|
+
)
|
|
2078
|
+
|
|
2079
|
+
async def reply(
|
|
2080
|
+
self,
|
|
2081
|
+
inbox_id: str,
|
|
2082
|
+
message_id: str,
|
|
2083
|
+
text: Optional[str] = None,
|
|
2084
|
+
html: Optional[str] = None,
|
|
2085
|
+
attachments: Optional[Sequence[AttachmentInput]] = None,
|
|
2086
|
+
reply_all: Optional[bool] = None,
|
|
2087
|
+
labels: Optional[Sequence[str]] = None,
|
|
2088
|
+
idempotency_key: Optional[str] = None,
|
|
2089
|
+
data: Any = None,
|
|
2090
|
+
type: Optional[MessageType] = None,
|
|
2091
|
+
agent_signature: Optional[str] = None,
|
|
2092
|
+
) -> Message:
|
|
2093
|
+
"""Reply in-thread (sets In-Reply-To/References and a ``Re:`` subject), optionally with ``data`` and
|
|
2094
|
+
``type`` like :meth:`send`."""
|
|
2095
|
+
req = r.message_reply(
|
|
2096
|
+
inbox_id,
|
|
2097
|
+
message_id,
|
|
2098
|
+
text,
|
|
2099
|
+
html,
|
|
2100
|
+
attachments,
|
|
2101
|
+
reply_all,
|
|
2102
|
+
labels,
|
|
2103
|
+
idempotency_key,
|
|
2104
|
+
data,
|
|
2105
|
+
type,
|
|
2106
|
+
agent_signature,
|
|
2107
|
+
)
|
|
2108
|
+
return cast(Message, await self._c._send(req))
|
|
2109
|
+
|
|
2110
|
+
async def list(
|
|
2111
|
+
self,
|
|
2112
|
+
inbox_id: str,
|
|
2113
|
+
labels: Optional[Sequence[str]] = None,
|
|
2114
|
+
is_read: Optional[bool] = None,
|
|
2115
|
+
direction: Optional[Direction] = None,
|
|
2116
|
+
cursor: Optional[str] = None,
|
|
2117
|
+
limit: Optional[int] = None,
|
|
2118
|
+
include_blocked: Optional[bool] = None,
|
|
2119
|
+
channel: Optional[MessageChannel] = None,
|
|
2120
|
+
type: Optional[MessageType] = None,
|
|
2121
|
+
screening: Optional[ScreeningState] = None,
|
|
2122
|
+
include_unscreened: Optional[bool] = None,
|
|
2123
|
+
include_held: Optional[bool] = None,
|
|
2124
|
+
promotions: Optional[Literal["include", "exclude", "only"]] = None,
|
|
2125
|
+
status: Optional[MessageStatus] = None,
|
|
2126
|
+
) -> Page[Message]:
|
|
2127
|
+
"""List messages, newest first. ``labels`` filters to messages having all of them.
|
|
2128
|
+
|
|
2129
|
+
``include_blocked=True`` also returns mail stopped by the receive lists (label ``blocked``).
|
|
2130
|
+
``screening="held"`` returns only received mail in that screening state.
|
|
2131
|
+
``status="bounced"`` (with ``direction="outbound"``) returns sent mail that bounced.
|
|
2132
|
+
``promotions="exclude"`` leaves out mail labelled ``ai:sales`` or ``local:spam``; ``"only"`` lists
|
|
2133
|
+
just that.
|
|
2134
|
+
"""
|
|
2135
|
+
req = r.message_list(
|
|
2136
|
+
inbox_id,
|
|
2137
|
+
labels,
|
|
2138
|
+
is_read,
|
|
2139
|
+
direction,
|
|
2140
|
+
cursor,
|
|
2141
|
+
limit,
|
|
2142
|
+
include_blocked,
|
|
2143
|
+
channel,
|
|
2144
|
+
type,
|
|
2145
|
+
screening,
|
|
2146
|
+
include_unscreened,
|
|
2147
|
+
include_held,
|
|
2148
|
+
promotions,
|
|
2149
|
+
status,
|
|
2150
|
+
)
|
|
2151
|
+
return cast("Page[Message]", await self._c._send(req))
|
|
2152
|
+
|
|
2153
|
+
async def get(
|
|
2154
|
+
self,
|
|
2155
|
+
message_id: str,
|
|
2156
|
+
*,
|
|
2157
|
+
include_unscreened: Optional[bool] = None,
|
|
2158
|
+
include_held: Optional[bool] = None,
|
|
2159
|
+
) -> Message:
|
|
2160
|
+
"""One message. See :meth:`Messages.get`."""
|
|
2161
|
+
return cast(Message, await self._c._send(r.message_get(message_id, include_unscreened, include_held)))
|
|
2162
|
+
|
|
2163
|
+
async def update(
|
|
2164
|
+
self,
|
|
2165
|
+
message_id: str,
|
|
2166
|
+
add_labels: Optional[Sequence[str]] = None,
|
|
2167
|
+
remove_labels: Optional[Sequence[str]] = None,
|
|
2168
|
+
is_read: Optional[bool] = None,
|
|
2169
|
+
) -> Message:
|
|
2170
|
+
req = r.message_update(message_id, add_labels, remove_labels, is_read)
|
|
2171
|
+
return cast(Message, await self._c._send(req))
|
|
2172
|
+
|
|
2173
|
+
async def release(self, message_id: str) -> Message:
|
|
2174
|
+
"""Release a held message to agents. See :meth:`Messages.release`."""
|
|
2175
|
+
return cast(Message, await self._c._send(r.message_release(message_id)))
|
|
2176
|
+
|
|
2177
|
+
async def draft_reply(
|
|
2178
|
+
self, message_id: str, instructions: Optional[str] = None, *, save: Optional[bool] = None
|
|
2179
|
+
) -> DraftReply:
|
|
2180
|
+
"""Draft a reply (needs ``ai_processing = "full"``). Never sends. See :meth:`Messages.draft_reply`."""
|
|
2181
|
+
return cast(DraftReply, await self._c._send(r.message_draft_reply(message_id, instructions, save)))
|
|
2182
|
+
|
|
2183
|
+
async def attachment_text(
|
|
2184
|
+
self,
|
|
2185
|
+
message_id: str,
|
|
2186
|
+
attachment_id: str,
|
|
2187
|
+
offset: Optional[int] = None,
|
|
2188
|
+
max_chars: Optional[int] = None,
|
|
2189
|
+
) -> AttachmentText:
|
|
2190
|
+
"""Extracted text of an inbound attachment. See :meth:`Messages.attachment_text`."""
|
|
2191
|
+
req = r.message_attachment_text(message_id, attachment_id, offset, max_chars)
|
|
2192
|
+
return cast(AttachmentText, await self._c._send(req))
|
|
2193
|
+
|
|
2194
|
+
async def extract_attachment(
|
|
2195
|
+
self,
|
|
2196
|
+
message_id: str,
|
|
2197
|
+
attachment_id: str,
|
|
2198
|
+
schema: Union[BuiltinExtractionSchema, Mapping[str, Any]],
|
|
2199
|
+
instructions: Optional[str] = None,
|
|
2200
|
+
) -> StructuredExtraction:
|
|
2201
|
+
"""Structured extraction with a schema. See :meth:`Messages.extract_attachment`."""
|
|
2202
|
+
req = r.message_extract_attachment(message_id, attachment_id, schema, instructions)
|
|
2203
|
+
return cast(StructuredExtraction, await self._c._send(req))
|
|
2204
|
+
|
|
2205
|
+
async def wait(
|
|
2206
|
+
self,
|
|
2207
|
+
inbox_id: str,
|
|
2208
|
+
timeout: float = 30,
|
|
2209
|
+
since: Optional[str] = None,
|
|
2210
|
+
from_: Optional[str] = None,
|
|
2211
|
+
subject: Optional[str] = None,
|
|
2212
|
+
direction: Optional[Direction] = None,
|
|
2213
|
+
channel: Optional[MessageChannel] = None,
|
|
2214
|
+
type: Optional[MessageType] = None,
|
|
2215
|
+
include_unscreened: Optional[bool] = None,
|
|
2216
|
+
include_held: Optional[bool] = None,
|
|
2217
|
+
) -> Optional[Message]:
|
|
2218
|
+
"""Long-poll until a matching message arrives, or return ``None`` after ``timeout`` seconds.
|
|
2219
|
+
|
|
2220
|
+
See :meth:`Messages.wait`.
|
|
2221
|
+
"""
|
|
2222
|
+
req = r.message_wait(
|
|
2223
|
+
inbox_id,
|
|
2224
|
+
timeout,
|
|
2225
|
+
since,
|
|
2226
|
+
from_,
|
|
2227
|
+
subject,
|
|
2228
|
+
direction,
|
|
2229
|
+
channel,
|
|
2230
|
+
type,
|
|
2231
|
+
include_unscreened,
|
|
2232
|
+
include_held,
|
|
2233
|
+
)
|
|
2234
|
+
return cast(Optional[Message], (await self._c._send(req))["data"])
|
|
2235
|
+
|
|
2236
|
+
async def wait_for_verification(
|
|
2237
|
+
self,
|
|
2238
|
+
inbox_id: str,
|
|
2239
|
+
timeout: float = 30,
|
|
2240
|
+
since: Optional[str] = None,
|
|
2241
|
+
from_: Optional[str] = None,
|
|
2242
|
+
include_unauthenticated: Optional[bool] = None,
|
|
2243
|
+
) -> Optional[VerificationResult]:
|
|
2244
|
+
"""Newest verification code/link after ``since``, waiting up to ``timeout`` s. ``None`` on timeout.
|
|
2245
|
+
|
|
2246
|
+
Possible spoofs (sender failed authentication) are skipped unless ``include_unauthenticated=True``."""
|
|
2247
|
+
req = r.message_wait_for_verification(inbox_id, timeout, since, from_, include_unauthenticated)
|
|
2248
|
+
return cast(Optional[VerificationResult], (await self._c._send(req))["data"])
|
|
2249
|
+
|
|
2250
|
+
async def claim(
|
|
2251
|
+
self,
|
|
2252
|
+
inbox_id: str,
|
|
2253
|
+
*,
|
|
2254
|
+
limit: Optional[int] = None,
|
|
2255
|
+
lease_seconds: Optional[int] = None,
|
|
2256
|
+
consumer: Optional[str] = None,
|
|
2257
|
+
wait: Optional[float] = None,
|
|
2258
|
+
enriched: Optional[bool] = None,
|
|
2259
|
+
since: Optional[str] = None,
|
|
2260
|
+
type: Optional[MessageType] = None,
|
|
2261
|
+
channel: Optional[MessageChannel] = None,
|
|
2262
|
+
analysis: Optional[Literal["completed"]] = None,
|
|
2263
|
+
include_unscreened: Optional[bool] = None,
|
|
2264
|
+
include_held: Optional[bool] = None,
|
|
2265
|
+
) -> LeaseClaim:
|
|
2266
|
+
"""Claim/ack queue: lease inbound messages. See :meth:`Messages.claim`."""
|
|
2267
|
+
req = r.message_claim(
|
|
2268
|
+
inbox_id,
|
|
2269
|
+
limit,
|
|
2270
|
+
lease_seconds,
|
|
2271
|
+
consumer,
|
|
2272
|
+
wait,
|
|
2273
|
+
enriched,
|
|
2274
|
+
since,
|
|
2275
|
+
type,
|
|
2276
|
+
channel,
|
|
2277
|
+
analysis,
|
|
2278
|
+
include_unscreened,
|
|
2279
|
+
include_held,
|
|
2280
|
+
)
|
|
2281
|
+
return cast(LeaseClaim, await self._c._send(req))
|
|
2282
|
+
|
|
2283
|
+
async def ack(self, message_id: str, lease_id: str, *, mark_read: Optional[bool] = None) -> AckResult:
|
|
2284
|
+
"""Done: never claimed again. Idempotent. See :meth:`Messages.ack`."""
|
|
2285
|
+
return cast(AckResult, await self._c._send(r.message_ack(message_id, lease_id, mark_read)))
|
|
2286
|
+
|
|
2287
|
+
async def nack(
|
|
2288
|
+
self, message_id: str, lease_id: str, *, delay_seconds: Optional[int] = None
|
|
2289
|
+
) -> NackResult:
|
|
2290
|
+
"""Give the message back now or after ``delay_seconds``. See :meth:`Messages.nack`."""
|
|
2291
|
+
return cast(NackResult, await self._c._send(r.message_nack(message_id, lease_id, delay_seconds)))
|
|
2292
|
+
|
|
2293
|
+
async def extend(
|
|
2294
|
+
self, message_id: str, lease_id: str, *, lease_seconds: Optional[int] = None
|
|
2295
|
+
) -> ExtendResult:
|
|
2296
|
+
"""Heartbeat for long tasks. See :meth:`Messages.extend`."""
|
|
2297
|
+
return cast(ExtendResult, await self._c._send(r.message_extend(message_id, lease_id, lease_seconds)))
|
|
2298
|
+
|
|
2299
|
+
|
|
2300
|
+
class AsyncDrafts:
|
|
2301
|
+
"""Drafts: store an email for review, edit it, then ``send`` it now or ``schedule`` it.
|
|
2302
|
+
|
|
2303
|
+
Sending goes through every check a normal send does (allow/block lists, suppressions, plan quota,
|
|
2304
|
+
daily caps, the 5-minute burst limit). Permissions: ``drafts:read`` / ``drafts:write``; ``send`` and
|
|
2305
|
+
``schedule`` also need ``messages:send``.
|
|
2306
|
+
"""
|
|
2307
|
+
|
|
2308
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2309
|
+
self._c = client
|
|
2310
|
+
|
|
2311
|
+
async def create(
|
|
2312
|
+
self,
|
|
2313
|
+
inbox_id: str,
|
|
2314
|
+
*,
|
|
2315
|
+
to: Optional[Recipients] = None,
|
|
2316
|
+
subject: Optional[str] = None,
|
|
2317
|
+
text: Optional[str] = None,
|
|
2318
|
+
html: Optional[str] = None,
|
|
2319
|
+
cc: Optional[Recipients] = None,
|
|
2320
|
+
bcc: Optional[Recipients] = None,
|
|
2321
|
+
attachments: Optional[Sequence[AttachmentInput]] = None,
|
|
2322
|
+
labels: Optional[Sequence[str]] = None,
|
|
2323
|
+
metadata: Optional[MetadataPatch] = None,
|
|
2324
|
+
reply_to_message_id: Optional[str] = None,
|
|
2325
|
+
thread_id: Optional[str] = None,
|
|
2326
|
+
reply_all: Optional[bool] = None,
|
|
2327
|
+
send_at: Optional[SendAt] = None,
|
|
2328
|
+
idempotency_key: Optional[str] = None,
|
|
2329
|
+
data: Any = None,
|
|
2330
|
+
type: Optional[MessageType] = None,
|
|
2331
|
+
) -> Draft:
|
|
2332
|
+
"""Create a draft (nothing is sent). Everything is optional until it is sent.
|
|
2333
|
+
|
|
2334
|
+
``reply_to_message_id`` (or ``thread_id``) makes it a reply: recipients, ``Re:`` subject and
|
|
2335
|
+
threading are filled in. ``send_at`` (1 minute to 30 days ahead) schedules it."""
|
|
2336
|
+
req = r.draft_create(
|
|
2337
|
+
inbox_id,
|
|
2338
|
+
to,
|
|
2339
|
+
subject,
|
|
2340
|
+
text,
|
|
2341
|
+
html,
|
|
2342
|
+
cc,
|
|
2343
|
+
bcc,
|
|
2344
|
+
attachments,
|
|
2345
|
+
labels,
|
|
2346
|
+
metadata,
|
|
2347
|
+
reply_to_message_id,
|
|
2348
|
+
thread_id,
|
|
2349
|
+
reply_all,
|
|
2350
|
+
send_at,
|
|
2351
|
+
idempotency_key,
|
|
2352
|
+
data,
|
|
2353
|
+
type,
|
|
2354
|
+
)
|
|
2355
|
+
return cast(Draft, await self._c._send(req))
|
|
2356
|
+
|
|
2357
|
+
async def list(
|
|
2358
|
+
self,
|
|
2359
|
+
inbox_id: str,
|
|
2360
|
+
*,
|
|
2361
|
+
status: Optional[DraftStatuses] = None,
|
|
2362
|
+
thread_id: Optional[str] = None,
|
|
2363
|
+
cursor: Optional[str] = None,
|
|
2364
|
+
limit: Optional[int] = None,
|
|
2365
|
+
) -> Page[Draft]:
|
|
2366
|
+
"""Drafts of one inbox, newest first. ``status``: one or several (``["draft", "scheduled"]``)."""
|
|
2367
|
+
return cast(
|
|
2368
|
+
"Page[Draft]", await self._c._send(r.draft_list(inbox_id, status, thread_id, cursor, limit))
|
|
2369
|
+
)
|
|
2370
|
+
|
|
2371
|
+
async def list_all(
|
|
2372
|
+
self,
|
|
2373
|
+
*,
|
|
2374
|
+
inbox_id: Optional[str] = None,
|
|
2375
|
+
status: Optional[DraftStatuses] = None,
|
|
2376
|
+
thread_id: Optional[str] = None,
|
|
2377
|
+
cursor: Optional[str] = None,
|
|
2378
|
+
limit: Optional[int] = None,
|
|
2379
|
+
) -> Page[Draft]:
|
|
2380
|
+
"""Drafts of every inbox of the workspace (``GET /v1/drafts``), optionally filtered."""
|
|
2381
|
+
req = r.draft_list_all(inbox_id, status, thread_id, cursor, limit)
|
|
2382
|
+
return cast("Page[Draft]", await self._c._send(req))
|
|
2383
|
+
|
|
2384
|
+
async def get(self, inbox_id: str, draft_id: str) -> Draft:
|
|
2385
|
+
return cast(Draft, await self._c._send(r.draft_get(inbox_id, draft_id)))
|
|
2386
|
+
|
|
2387
|
+
async def update(
|
|
2388
|
+
self,
|
|
2389
|
+
inbox_id: str,
|
|
2390
|
+
draft_id: str,
|
|
2391
|
+
*,
|
|
2392
|
+
to: Optional[Recipients] = None,
|
|
2393
|
+
subject: NullableText = NOT_GIVEN,
|
|
2394
|
+
text: NullableText = NOT_GIVEN,
|
|
2395
|
+
html: NullableText = NOT_GIVEN,
|
|
2396
|
+
cc: Optional[Recipients] = None,
|
|
2397
|
+
bcc: Optional[Recipients] = None,
|
|
2398
|
+
attachments: Optional[Sequence[Union[AttachmentInput, DraftKeep]]] = None,
|
|
2399
|
+
labels: Optional[Sequence[str]] = None,
|
|
2400
|
+
metadata: Optional[MetadataPatch] = None,
|
|
2401
|
+
send_at: NullableSendAt = NOT_GIVEN,
|
|
2402
|
+
data: Any = NOT_GIVEN,
|
|
2403
|
+
type: Optional[MessageType] = None,
|
|
2404
|
+
) -> Draft:
|
|
2405
|
+
"""Edit a ``draft`` or ``scheduled`` draft (else ``409 draft_not_editable``).
|
|
2406
|
+
|
|
2407
|
+
``subject``/``text``/``html=None`` clear them; ``attachments`` replaces the list (``{"id": ...}``
|
|
2408
|
+
keeps one already on the draft); ``send_at`` reschedules and ``send_at=None`` unschedules."""
|
|
2409
|
+
req = r.draft_update(
|
|
2410
|
+
inbox_id,
|
|
2411
|
+
draft_id,
|
|
2412
|
+
to,
|
|
2413
|
+
subject,
|
|
2414
|
+
text,
|
|
2415
|
+
html,
|
|
2416
|
+
cc,
|
|
2417
|
+
bcc,
|
|
2418
|
+
attachments,
|
|
2419
|
+
labels,
|
|
2420
|
+
metadata,
|
|
2421
|
+
send_at,
|
|
2422
|
+
data,
|
|
2423
|
+
type,
|
|
2424
|
+
)
|
|
2425
|
+
return cast(Draft, await self._c._send(req))
|
|
2426
|
+
|
|
2427
|
+
async def delete(self, inbox_id: str, draft_id: str) -> None:
|
|
2428
|
+
await self._c._send(r.draft_delete(inbox_id, draft_id))
|
|
2429
|
+
|
|
2430
|
+
async def send(
|
|
2431
|
+
self, inbox_id: str, draft_id: str, *, idempotency_key: Optional[str] = None
|
|
2432
|
+
) -> DraftSendResult:
|
|
2433
|
+
"""Send now. A refused send raises the API error and leaves the draft as it was (``error`` set)."""
|
|
2434
|
+
return cast(DraftSendResult, await self._c._send(r.draft_send(inbox_id, draft_id, idempotency_key)))
|
|
2435
|
+
|
|
2436
|
+
async def schedule(self, inbox_id: str, draft_id: str, send_at: SendAt) -> Draft:
|
|
2437
|
+
"""Send automatically at ``send_at`` (1 minute to 30 days ahead; ``400 invalid_send_at``)."""
|
|
2438
|
+
return cast(Draft, await self._c._send(r.draft_schedule(inbox_id, draft_id, send_at)))
|
|
2439
|
+
|
|
2440
|
+
async def cancel(self, inbox_id: str, draft_id: str) -> Draft:
|
|
2441
|
+
"""Cancel a draft or its scheduled send (terminal)."""
|
|
2442
|
+
return cast(Draft, await self._c._send(r.draft_cancel(inbox_id, draft_id)))
|
|
2443
|
+
|
|
2444
|
+
|
|
2445
|
+
class AsyncThreads:
|
|
2446
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2447
|
+
self._c = client
|
|
2448
|
+
|
|
2449
|
+
async def list(
|
|
2450
|
+
self,
|
|
2451
|
+
inbox_id: str,
|
|
2452
|
+
cursor: Optional[str] = None,
|
|
2453
|
+
limit: Optional[int] = None,
|
|
2454
|
+
labels: Optional[Sequence[str]] = None,
|
|
2455
|
+
before: Optional[str] = None,
|
|
2456
|
+
after: Optional[str] = None,
|
|
2457
|
+
participant: Optional[str] = None,
|
|
2458
|
+
subject: Optional[str] = None,
|
|
2459
|
+
ascending: Optional[bool] = None,
|
|
2460
|
+
) -> Page[Thread]:
|
|
2461
|
+
"""One inbox's threads, newest activity first.
|
|
2462
|
+
|
|
2463
|
+
Filters combine; ``participant`` and ``subject`` are substrings.
|
|
2464
|
+
"""
|
|
2465
|
+
return cast(
|
|
2466
|
+
"Page[Thread]",
|
|
2467
|
+
await self._c._send(
|
|
2468
|
+
r.thread_list(
|
|
2469
|
+
inbox_id,
|
|
2470
|
+
cursor,
|
|
2471
|
+
limit,
|
|
2472
|
+
labels=labels,
|
|
2473
|
+
before=before,
|
|
2474
|
+
after=after,
|
|
2475
|
+
participant=participant,
|
|
2476
|
+
subject=subject,
|
|
2477
|
+
ascending=ascending,
|
|
2478
|
+
)
|
|
2479
|
+
),
|
|
2480
|
+
)
|
|
2481
|
+
|
|
2482
|
+
async def list_all(
|
|
2483
|
+
self,
|
|
2484
|
+
inbox_id: Optional[str] = None,
|
|
2485
|
+
cursor: Optional[str] = None,
|
|
2486
|
+
limit: Optional[int] = None,
|
|
2487
|
+
labels: Optional[Sequence[str]] = None,
|
|
2488
|
+
before: Optional[str] = None,
|
|
2489
|
+
after: Optional[str] = None,
|
|
2490
|
+
participant: Optional[str] = None,
|
|
2491
|
+
subject: Optional[str] = None,
|
|
2492
|
+
ascending: Optional[bool] = None,
|
|
2493
|
+
) -> Page[Thread]:
|
|
2494
|
+
"""Threads across every inbox the key can see, with the same filters as :meth:`list`."""
|
|
2495
|
+
return cast(
|
|
2496
|
+
"Page[Thread]",
|
|
2497
|
+
await self._c._send(
|
|
2498
|
+
r.thread_list_all(
|
|
2499
|
+
cursor,
|
|
2500
|
+
limit,
|
|
2501
|
+
inbox_id=inbox_id,
|
|
2502
|
+
labels=labels,
|
|
2503
|
+
before=before,
|
|
2504
|
+
after=after,
|
|
2505
|
+
participant=participant,
|
|
2506
|
+
subject=subject,
|
|
2507
|
+
ascending=ascending,
|
|
2508
|
+
)
|
|
2509
|
+
),
|
|
2510
|
+
)
|
|
2511
|
+
|
|
2512
|
+
async def delete(self, thread_id: str) -> DeletedThread:
|
|
2513
|
+
"""Delete a thread with all its messages and attachments."""
|
|
2514
|
+
return cast(DeletedThread, await self._c._send(r.thread_delete(thread_id)))
|
|
2515
|
+
|
|
2516
|
+
async def get(self, thread_id: str) -> ThreadWithMessages:
|
|
2517
|
+
"""A thread plus its messages in order."""
|
|
2518
|
+
return cast(ThreadWithMessages, await self._c._send(r.thread_get(thread_id)))
|
|
2519
|
+
|
|
2520
|
+
async def update(
|
|
2521
|
+
self,
|
|
2522
|
+
thread_id: str,
|
|
2523
|
+
metadata: Optional[MetadataPatch] = None,
|
|
2524
|
+
add_labels: Optional[Sequence[str]] = None,
|
|
2525
|
+
remove_labels: Optional[Sequence[str]] = None,
|
|
2526
|
+
) -> Thread:
|
|
2527
|
+
"""Set thread labels and metadata (merged: a ``None`` value deletes a key). Returns the thread."""
|
|
2528
|
+
return cast(
|
|
2529
|
+
Thread, await self._c._send(r.thread_update(thread_id, metadata, add_labels, remove_labels))
|
|
2530
|
+
)
|
|
2531
|
+
|
|
2532
|
+
|
|
2533
|
+
class AsyncWebhooks:
|
|
2534
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2535
|
+
self._c = client
|
|
2536
|
+
|
|
2537
|
+
async def create(
|
|
2538
|
+
self,
|
|
2539
|
+
url: str,
|
|
2540
|
+
events: Optional[Sequence[WebhookEventType]] = None,
|
|
2541
|
+
inbox_ids: InboxIds = NOT_GIVEN,
|
|
2542
|
+
secret: Optional[str] = None,
|
|
2543
|
+
payload: Optional[WebhookPayload] = None,
|
|
2544
|
+
headers: Optional[Mapping[str, str]] = None,
|
|
2545
|
+
) -> Webhook:
|
|
2546
|
+
"""Create a webhook. The returned ``secret`` is only shown here: store it.
|
|
2547
|
+
|
|
2548
|
+
``payload="envelope"`` sends ids, addresses, subject and labels only (no bodies).
|
|
2549
|
+
"""
|
|
2550
|
+
req = r.webhook_create(url, events, inbox_ids, secret, payload, headers)
|
|
2551
|
+
return cast(Webhook, await self._c._send(req))
|
|
2552
|
+
|
|
2553
|
+
async def list(self) -> Page[Webhook]:
|
|
2554
|
+
return cast("Page[Webhook]", await self._c._send(r.webhook_list()))
|
|
2555
|
+
|
|
2556
|
+
async def get(self, webhook_id: str) -> Webhook:
|
|
2557
|
+
return cast(Webhook, await self._c._send(r.webhook_get(webhook_id)))
|
|
2558
|
+
|
|
2559
|
+
async def update(
|
|
2560
|
+
self,
|
|
2561
|
+
webhook_id: str,
|
|
2562
|
+
url: Optional[str] = None,
|
|
2563
|
+
events: Optional[Sequence[WebhookEventType]] = None,
|
|
2564
|
+
inbox_ids: InboxIds = NOT_GIVEN,
|
|
2565
|
+
enabled: Optional[bool] = None,
|
|
2566
|
+
payload: Optional[WebhookPayload] = None,
|
|
2567
|
+
headers: Optional[Mapping[str, str]] = None,
|
|
2568
|
+
) -> Webhook:
|
|
2569
|
+
"""Update a webhook. Pass ``inbox_ids=None`` explicitly to subscribe to all inboxes."""
|
|
2570
|
+
req = r.webhook_update(webhook_id, url, events, inbox_ids, enabled, payload, headers)
|
|
2571
|
+
return cast(Webhook, await self._c._send(req))
|
|
2572
|
+
|
|
2573
|
+
async def delete(self, webhook_id: str) -> None:
|
|
2574
|
+
await self._c._send(r.webhook_delete(webhook_id))
|
|
2575
|
+
|
|
2576
|
+
async def test(self, webhook_id: str) -> WebhookTestResult:
|
|
2577
|
+
"""Send a ``webhook.test`` event."""
|
|
2578
|
+
return cast(WebhookTestResult, await self._c._send(r.webhook_test(webhook_id)))
|
|
2579
|
+
|
|
2580
|
+
async def rotate_secret(self, webhook_id: str, secret: Optional[str] = None) -> Webhook:
|
|
2581
|
+
"""Replace the signing secret (yours, or a generated one); the new ``secret`` is returned once.
|
|
2582
|
+
|
|
2583
|
+
Deliveries are signed with it from then on: let your endpoint accept both secrets while you switch.
|
|
2584
|
+
"""
|
|
2585
|
+
return cast(Webhook, await self._c._send(r.webhook_rotate_secret(webhook_id, secret)))
|
|
2586
|
+
|
|
2587
|
+
async def events(self) -> builtins.list[WebhookCatalogEntry]:
|
|
2588
|
+
"""The event catalog: every event type with a description and example bodies."""
|
|
2589
|
+
return cast("builtins.list[WebhookCatalogEntry]", (await self._c._send(r.webhook_events()))["data"])
|
|
2590
|
+
|
|
2591
|
+
|
|
2592
|
+
class AsyncLists:
|
|
2593
|
+
"""Allow/block lists for receiving, sending and replying (permission ``lists:manage``)."""
|
|
2594
|
+
|
|
2595
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2596
|
+
self._c = client
|
|
2597
|
+
|
|
2598
|
+
async def list(
|
|
2599
|
+
self,
|
|
2600
|
+
inbox_id: Optional[str] = None,
|
|
2601
|
+
direction: Optional[ListDirection] = None,
|
|
2602
|
+
kind: Optional[ListKind] = None,
|
|
2603
|
+
) -> ListEntries:
|
|
2604
|
+
return cast(ListEntries, await self._c._send(r.list_entries(inbox_id, direction, kind)))
|
|
2605
|
+
|
|
2606
|
+
async def create(
|
|
2607
|
+
self, direction: ListDirection, kind: ListKind, pattern: str, inbox_id: Optional[str] = None
|
|
2608
|
+
) -> ListEntry:
|
|
2609
|
+
"""Add ``a@b.com`` or a domain (``b.com``, subdomains included). No ``inbox_id`` = workspace-wide."""
|
|
2610
|
+
return cast(ListEntry, await self._c._send(r.list_create(direction, kind, pattern, inbox_id)))
|
|
2611
|
+
|
|
2612
|
+
async def delete(self, entry_id: str) -> None:
|
|
2613
|
+
await self._c._send(r.list_delete(entry_id))
|
|
2614
|
+
|
|
2615
|
+
|
|
2616
|
+
class AsyncContacts:
|
|
2617
|
+
"""Contacts: external addresses the workspace has exchanged mail with (created automatically)."""
|
|
2618
|
+
|
|
2619
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2620
|
+
self._c = client
|
|
2621
|
+
|
|
2622
|
+
async def list(
|
|
2623
|
+
self,
|
|
2624
|
+
q: Optional[str] = None,
|
|
2625
|
+
label: Optional[str] = None,
|
|
2626
|
+
metadata: Optional[MetadataFilter] = None,
|
|
2627
|
+
cursor: Optional[str] = None,
|
|
2628
|
+
limit: Optional[int] = None,
|
|
2629
|
+
kind: Union[ContactKind, Sequence[ContactKind], None] = None,
|
|
2630
|
+
domain: Optional[str] = None,
|
|
2631
|
+
) -> Page[Contact]:
|
|
2632
|
+
"""Newest activity first. ``q`` matches address/name; ``metadata`` filters by exact value.
|
|
2633
|
+
|
|
2634
|
+
``kind`` is one kind or several (every kind when left out); ``domain`` is the part after the @.
|
|
2635
|
+
"""
|
|
2636
|
+
req = r.contact_list(q, label, metadata, cursor, limit, kind, domain)
|
|
2637
|
+
return cast("Page[Contact]", await self._c._send(req))
|
|
2638
|
+
|
|
2639
|
+
async def domains(
|
|
2640
|
+
self, kind: Union[ContactKind, Sequence[ContactKind], None] = None, limit: Optional[int] = None
|
|
2641
|
+
) -> ContactDomainList:
|
|
2642
|
+
"""Contacts counted per domain (most first), free-mail providers left out. ``kind`` as in ``list``."""
|
|
2643
|
+
return cast(ContactDomainList, await self._c._send(r.contact_domains(kind, limit)))
|
|
2644
|
+
|
|
2645
|
+
async def get(self, contact_id: str) -> ContactWithThreads:
|
|
2646
|
+
"""A contact plus its 10 most recent threads."""
|
|
2647
|
+
return cast(ContactWithThreads, await self._c._send(r.contact_get(contact_id)))
|
|
2648
|
+
|
|
2649
|
+
async def by_address(self, address: str) -> ContactWithThreads:
|
|
2650
|
+
"""Look a contact up by address. ``NotFoundError`` if the workspace never exchanged mail with it."""
|
|
2651
|
+
return cast(ContactWithThreads, await self._c._send(r.contact_by_address(address)))
|
|
2652
|
+
|
|
2653
|
+
async def update(
|
|
2654
|
+
self,
|
|
2655
|
+
contact_id: str,
|
|
2656
|
+
name: Nullable = NOT_GIVEN,
|
|
2657
|
+
notes: Nullable = NOT_GIVEN,
|
|
2658
|
+
metadata: Optional[MetadataPatch] = None,
|
|
2659
|
+
add_labels: Optional[Sequence[str]] = None,
|
|
2660
|
+
remove_labels: Optional[Sequence[str]] = None,
|
|
2661
|
+
kind: Optional[ContactKind] = None,
|
|
2662
|
+
) -> Contact:
|
|
2663
|
+
"""Update notes (up to 10,000 chars; ``None`` clears), name, labels, metadata or kind.
|
|
2664
|
+
|
|
2665
|
+
Metadata is merged: given keys are set, a ``None`` value deletes the key. A name or kind set here is
|
|
2666
|
+
never changed by later mail (``name_source`` / ``kind_source`` become ``manual``).
|
|
2667
|
+
"""
|
|
2668
|
+
req = r.contact_update(contact_id, name, notes, metadata, add_labels, remove_labels, kind)
|
|
2669
|
+
return cast(Contact, await self._c._send(req))
|
|
2670
|
+
|
|
2671
|
+
async def delete(self, contact_id: str, forget: bool = False) -> None:
|
|
2672
|
+
"""Delete the contact (name, notes, labels, metadata); its messages stay. Needs an org-wide key.
|
|
2673
|
+
|
|
2674
|
+
``forget=True``: mail from the address no longer creates the contact (only a hash of it is kept);
|
|
2675
|
+
sending to it does.
|
|
2676
|
+
"""
|
|
2677
|
+
await self._c._send(r.contact_delete(contact_id, forget))
|
|
2678
|
+
|
|
2679
|
+
async def delete_many(
|
|
2680
|
+
self,
|
|
2681
|
+
kind: Optional[Sequence[ContactKind]] = None,
|
|
2682
|
+
domain: Optional[str] = None,
|
|
2683
|
+
forget: bool = False,
|
|
2684
|
+
dry_run: bool = False,
|
|
2685
|
+
) -> ContactBulkDeleteResult:
|
|
2686
|
+
"""Delete every contact of these kinds and/or this domain, up to 1,000 per call (``has_more``: call
|
|
2687
|
+
again). ``dry_run`` only counts; ``forget`` as in ``delete``. Needs an org-wide key."""
|
|
2688
|
+
req = r.contact_delete_many(kind, domain, forget, dry_run)
|
|
2689
|
+
return cast(ContactBulkDeleteResult, await self._c._send(req))
|
|
2690
|
+
|
|
2691
|
+
|
|
2692
|
+
class AsyncKnowledge:
|
|
2693
|
+
"""Knowledge documents used as context for reply drafts (per inbox, or workspace-wide)."""
|
|
2694
|
+
|
|
2695
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2696
|
+
self._c = client
|
|
2697
|
+
|
|
2698
|
+
async def list(
|
|
2699
|
+
self, inbox_id: Optional[str] = None, cursor: Optional[str] = None, limit: Optional[int] = None
|
|
2700
|
+
) -> Page[KnowledgeListItem]:
|
|
2701
|
+
"""Documents without bodies (each has an ``excerpt``). ``inbox_id``: one inbox's documents."""
|
|
2702
|
+
return cast("Page[KnowledgeListItem]", await self._c._send(r.knowledge_list(inbox_id, cursor, limit)))
|
|
2703
|
+
|
|
2704
|
+
async def create(self, title: str, body: str, inbox_id: Optional[str] = None) -> KnowledgeDoc:
|
|
2705
|
+
"""Create a document. Without ``inbox_id`` it applies to every inbox of the workspace."""
|
|
2706
|
+
return cast(KnowledgeDoc, await self._c._send(r.knowledge_create(title, body, inbox_id)))
|
|
2707
|
+
|
|
2708
|
+
async def get(self, doc_id: str) -> KnowledgeDoc:
|
|
2709
|
+
return cast(KnowledgeDoc, await self._c._send(r.knowledge_get(doc_id)))
|
|
2710
|
+
|
|
2711
|
+
async def update(
|
|
2712
|
+
self,
|
|
2713
|
+
doc_id: str,
|
|
2714
|
+
title: Optional[str] = None,
|
|
2715
|
+
body: Optional[str] = None,
|
|
2716
|
+
inbox_id: Nullable = NOT_GIVEN,
|
|
2717
|
+
) -> KnowledgeDoc:
|
|
2718
|
+
"""Update a document. Pass ``inbox_id=None`` explicitly to make it workspace-wide."""
|
|
2719
|
+
return cast(KnowledgeDoc, await self._c._send(r.knowledge_update(doc_id, title, body, inbox_id)))
|
|
2720
|
+
|
|
2721
|
+
async def delete(self, doc_id: str) -> None:
|
|
2722
|
+
await self._c._send(r.knowledge_delete(doc_id))
|
|
2723
|
+
|
|
2724
|
+
async def search(
|
|
2725
|
+
self, q: str, inbox_id: Optional[str] = None, limit: Optional[int] = None
|
|
2726
|
+
) -> KnowledgeSearchResults:
|
|
2727
|
+
"""Ranked full-text search. With ``inbox_id``, workspace-wide documents are included too."""
|
|
2728
|
+
return cast(KnowledgeSearchResults, await self._c._send(r.knowledge_search(q, inbox_id, limit)))
|
|
2729
|
+
|
|
2730
|
+
|
|
2731
|
+
class AsyncIdentityClients:
|
|
2732
|
+
"""Apps ("relying parties") the workspace registered for Sign in with Agentboxd (``identity:manage``)."""
|
|
2733
|
+
|
|
2734
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2735
|
+
self._c = client
|
|
2736
|
+
|
|
2737
|
+
async def list(self) -> Page[IdentityClient]:
|
|
2738
|
+
return cast("Page[IdentityClient]", await self._c._send(r.identity_client_list()))
|
|
2739
|
+
|
|
2740
|
+
async def create(
|
|
2741
|
+
self,
|
|
2742
|
+
name: str,
|
|
2743
|
+
type: IdentityClientType,
|
|
2744
|
+
redirect_uris: Optional[Sequence[str]] = None,
|
|
2745
|
+
allowed_scopes: Optional[Sequence[IdentityScope]] = None,
|
|
2746
|
+
subject_type: Optional[IdentitySubjectType] = None,
|
|
2747
|
+
homepage_url: Optional[str] = None,
|
|
2748
|
+
) -> IdentityClientWithSecret:
|
|
2749
|
+
"""Register an app. ``client_secret`` (confidential clients) is only returned here: store it."""
|
|
2750
|
+
req = r.identity_client_create(name, type, redirect_uris, allowed_scopes, subject_type, homepage_url)
|
|
2751
|
+
return cast(IdentityClientWithSecret, await self._c._send(req))
|
|
2752
|
+
|
|
2753
|
+
async def get(self, client_id: str) -> IdentityClient:
|
|
2754
|
+
return cast(IdentityClient, await self._c._send(r.identity_client_get(client_id)))
|
|
2755
|
+
|
|
2756
|
+
async def update(
|
|
2757
|
+
self,
|
|
2758
|
+
client_id: str,
|
|
2759
|
+
name: Optional[str] = None,
|
|
2760
|
+
redirect_uris: Optional[Sequence[str]] = None,
|
|
2761
|
+
allowed_scopes: Optional[Sequence[IdentityScope]] = None,
|
|
2762
|
+
homepage_url: Nullable = NOT_GIVEN,
|
|
2763
|
+
enabled: Optional[bool] = None,
|
|
2764
|
+
) -> IdentityClient:
|
|
2765
|
+
req = r.identity_client_update(client_id, name, redirect_uris, allowed_scopes, homepage_url, enabled)
|
|
2766
|
+
return cast(IdentityClient, await self._c._send(req))
|
|
2767
|
+
|
|
2768
|
+
async def delete(self, client_id: str) -> None:
|
|
2769
|
+
await self._c._send(r.identity_client_delete(client_id))
|
|
2770
|
+
|
|
2771
|
+
async def rotate_secret(self, client_id: str) -> IdentityClientWithSecret:
|
|
2772
|
+
return cast(IdentityClientWithSecret, await self._c._send(r.identity_client_rotate_secret(client_id)))
|
|
2773
|
+
|
|
2774
|
+
|
|
2775
|
+
class AsyncInboxIdentities:
|
|
2776
|
+
"""The per-inbox Sign in with Agentboxd switch and sign-in history."""
|
|
2777
|
+
|
|
2778
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2779
|
+
self._c = client
|
|
2780
|
+
|
|
2781
|
+
async def get(self, inbox_id: str) -> InboxIdentity:
|
|
2782
|
+
return cast(InboxIdentity, await self._c._send(r.inbox_identity_get(inbox_id)))
|
|
2783
|
+
|
|
2784
|
+
async def update(self, inbox_id: str, enabled: bool) -> InboxIdentity:
|
|
2785
|
+
return cast(InboxIdentity, await self._c._send(r.inbox_identity_update(inbox_id, enabled)))
|
|
2786
|
+
|
|
2787
|
+
async def sign_ins(
|
|
2788
|
+
self, inbox_id: str, cursor: Optional[str] = None, limit: Optional[int] = None
|
|
2789
|
+
) -> Page[IdentitySignIn]:
|
|
2790
|
+
return cast(
|
|
2791
|
+
"Page[IdentitySignIn]", await self._c._send(r.inbox_identity_sign_ins(inbox_id, cursor, limit))
|
|
2792
|
+
)
|
|
2793
|
+
|
|
2794
|
+
|
|
2795
|
+
class AsyncIdentities:
|
|
2796
|
+
"""Async :class:`Identities`."""
|
|
2797
|
+
|
|
2798
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2799
|
+
self._c = client
|
|
2800
|
+
|
|
2801
|
+
async def create(
|
|
2802
|
+
self,
|
|
2803
|
+
*,
|
|
2804
|
+
username: Optional[str] = None,
|
|
2805
|
+
display_name: Optional[str] = None,
|
|
2806
|
+
client_id: Optional[str] = None,
|
|
2807
|
+
metadata: Optional[MetadataPatch] = None,
|
|
2808
|
+
card: Optional[AgentCardInput] = None,
|
|
2809
|
+
) -> IdentityRecord:
|
|
2810
|
+
req = r.identity_create(username, display_name, client_id, metadata, card=card)
|
|
2811
|
+
return cast(IdentityRecord, await self._c._send(req))
|
|
2812
|
+
|
|
2813
|
+
async def list(
|
|
2814
|
+
self,
|
|
2815
|
+
*,
|
|
2816
|
+
cursor: Optional[str] = None,
|
|
2817
|
+
limit: Optional[int] = None,
|
|
2818
|
+
metadata: Optional[MetadataFilter] = None,
|
|
2819
|
+
) -> "Page[IdentityRecord]":
|
|
2820
|
+
return cast("Page[IdentityRecord]", await self._c._send(r.identity_list(cursor, limit, metadata)))
|
|
2821
|
+
|
|
2822
|
+
async def get(self, identity_id: str) -> IdentityRecord:
|
|
2823
|
+
return cast(IdentityRecord, await self._c._send(r.identity_get(identity_id)))
|
|
2824
|
+
|
|
2825
|
+
async def update(
|
|
2826
|
+
self,
|
|
2827
|
+
identity_id: str,
|
|
2828
|
+
*,
|
|
2829
|
+
display_name: Nullable = NOT_GIVEN,
|
|
2830
|
+
metadata: Optional[MetadataPatch] = None,
|
|
2831
|
+
) -> IdentityRecord:
|
|
2832
|
+
return cast(
|
|
2833
|
+
IdentityRecord, await self._c._send(r.identity_update(identity_id, display_name, metadata))
|
|
2834
|
+
)
|
|
2835
|
+
|
|
2836
|
+
async def delete(self, identity_id: str) -> None:
|
|
2837
|
+
await self._c._send(r.identity_delete(identity_id))
|
|
2838
|
+
|
|
2839
|
+
async def pause(self, identity_id: str, *, reason: Optional[str] = None) -> Inbox:
|
|
2840
|
+
return cast(Inbox, await self._c._send(r.inbox_pause(identity_id, reason)))
|
|
2841
|
+
|
|
2842
|
+
async def resume(self, identity_id: str) -> ResumedInbox:
|
|
2843
|
+
return cast(ResumedInbox, await self._c._send(r.inbox_resume(identity_id)))
|
|
2844
|
+
|
|
2845
|
+
|
|
2846
|
+
class AsyncIdentity:
|
|
2847
|
+
"""Sign in with Agentboxd: the agent's identity (an inbox or an identity-only agent), OpenID Connect."""
|
|
2848
|
+
|
|
2849
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2850
|
+
self._c = client
|
|
2851
|
+
self.clients = AsyncIdentityClients(client)
|
|
2852
|
+
self.inbox = AsyncInboxIdentities(client)
|
|
2853
|
+
|
|
2854
|
+
async def token(
|
|
2855
|
+
self,
|
|
2856
|
+
inbox_id: Optional[str] = None,
|
|
2857
|
+
audience: Optional[str] = None,
|
|
2858
|
+
nonce: Optional[str] = None,
|
|
2859
|
+
scope: Optional[Union[str, Sequence[IdentityScope]]] = None,
|
|
2860
|
+
expires_in: Optional[int] = None,
|
|
2861
|
+
*,
|
|
2862
|
+
identity_id: Optional[str] = None,
|
|
2863
|
+
) -> IdentityToken:
|
|
2864
|
+
"""Mint a short-lived, single-use ID token for the relying party ``audience`` (``identity:sign``).
|
|
2865
|
+
|
|
2866
|
+
Pass ``inbox_id`` for an inbox or ``identity_id`` for an identity-only agent."""
|
|
2867
|
+
req = r.identity_token(inbox_id, audience, nonce, scope, expires_in, identity_id)
|
|
2868
|
+
return cast(IdentityToken, await self._c._send(req))
|
|
2869
|
+
|
|
2870
|
+
|
|
2871
|
+
class AsyncAgents:
|
|
2872
|
+
"""Async :class:`Agents`."""
|
|
2873
|
+
|
|
2874
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2875
|
+
self._c = client
|
|
2876
|
+
self.keys = AsyncAgentKeys(client)
|
|
2877
|
+
|
|
2878
|
+
async def get(self, inbox_id: str) -> AgentBundle:
|
|
2879
|
+
return cast(AgentBundle, await self._c._send(r.agent_get(inbox_id)))
|
|
2880
|
+
|
|
2881
|
+
async def update(
|
|
2882
|
+
self,
|
|
2883
|
+
inbox_id: str,
|
|
2884
|
+
*,
|
|
2885
|
+
name: Optional[str] = None,
|
|
2886
|
+
description: Nullable = NOT_GIVEN,
|
|
2887
|
+
capabilities: Optional[Mapping[str, Any]] = None,
|
|
2888
|
+
documentation_url: Nullable = NOT_GIVEN,
|
|
2889
|
+
visibility: Optional[AgentCardVisibility] = None,
|
|
2890
|
+
routing: Optional[Literal["relay", "direct_preferred"]] = None,
|
|
2891
|
+
handle: Nullable = NOT_GIVEN,
|
|
2892
|
+
indexable: Optional[bool] = None,
|
|
2893
|
+
) -> AgentBundle:
|
|
2894
|
+
body = _card_body(
|
|
2895
|
+
name, description, capabilities, documentation_url, visibility, routing, handle, indexable
|
|
2896
|
+
)
|
|
2897
|
+
return cast(AgentBundle, await self._c._send(r.agent_update(inbox_id, body)))
|
|
2898
|
+
|
|
2899
|
+
async def delete(self, inbox_id: str) -> None:
|
|
2900
|
+
await self._c._send(r.agent_delete(inbox_id))
|
|
2901
|
+
|
|
2902
|
+
async def revoke(self, inbox_id: str, *, reason: Optional[str] = None) -> AgentBundle:
|
|
2903
|
+
return cast(AgentBundle, await self._c._send(r.agent_revoke(inbox_id, reason)))
|
|
2904
|
+
|
|
2905
|
+
async def restore(self, inbox_id: str) -> AgentBundle:
|
|
2906
|
+
return cast(AgentBundle, await self._c._send(r.agent_restore(inbox_id)))
|
|
2907
|
+
|
|
2908
|
+
async def oasf(self, inbox_id: str) -> dict[str, Any]:
|
|
2909
|
+
return cast(dict[str, Any], await self._c._send(r.agent_oasf(inbox_id)))
|
|
2910
|
+
|
|
2911
|
+
|
|
2912
|
+
class AsyncAgentKeys:
|
|
2913
|
+
"""Async :class:`AgentKeys`."""
|
|
2914
|
+
|
|
2915
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2916
|
+
self._c = client
|
|
2917
|
+
|
|
2918
|
+
async def list(self, inbox_id: str) -> AgentKeyList:
|
|
2919
|
+
return cast(AgentKeyList, await self._c._send(r.agent_keys_list(inbox_id)))
|
|
2920
|
+
|
|
2921
|
+
async def register(self, inbox_id: str, *, public_jwk: Mapping[str, Any], proof: str) -> AgentKey:
|
|
2922
|
+
return cast(AgentKey, await self._c._send(r.agent_keys_register(inbox_id, public_jwk, proof)))
|
|
2923
|
+
|
|
2924
|
+
async def retire(self, inbox_id: str, kid: str) -> AgentKey:
|
|
2925
|
+
return cast(AgentKey, await self._c._send(r.agent_keys_retire(inbox_id, kid)))
|
|
2926
|
+
|
|
2927
|
+
async def revoke(
|
|
2928
|
+
self, inbox_id: str, kid: str, *, reason: Optional[str] = None, since: Optional[str] = None
|
|
2929
|
+
) -> AgentKey:
|
|
2930
|
+
return cast(AgentKey, await self._c._send(r.agent_keys_revoke(inbox_id, kid, reason, since)))
|
|
2931
|
+
|
|
2932
|
+
|
|
2933
|
+
class AsyncDirectory:
|
|
2934
|
+
"""Async :class:`Directory`."""
|
|
2935
|
+
|
|
2936
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2937
|
+
self._c = client
|
|
2938
|
+
|
|
2939
|
+
async def resolve(self, address: Optional[str] = None, *, handle: Optional[str] = None) -> ResolvedAgent:
|
|
2940
|
+
return cast(ResolvedAgent, await self._c._send(r.directory_resolve(address, handle)))
|
|
2941
|
+
|
|
2942
|
+
async def verify(
|
|
2943
|
+
self, *, signature: Optional[str] = None, address: Optional[str] = None
|
|
2944
|
+
) -> DirectoryVerifyResult:
|
|
2945
|
+
return cast(DirectoryVerifyResult, await self._c._send(r.directory_verify(signature, address)))
|
|
2946
|
+
|
|
2947
|
+
async def search(
|
|
2948
|
+
self,
|
|
2949
|
+
*,
|
|
2950
|
+
q: Optional[str] = None,
|
|
2951
|
+
capability: Optional[str] = None,
|
|
2952
|
+
type: Optional[MessageType] = None,
|
|
2953
|
+
limit: Optional[int] = None,
|
|
2954
|
+
cursor: Optional[str] = None,
|
|
2955
|
+
scope: Optional[Literal["workspace", "public"]] = None,
|
|
2956
|
+
) -> "Page[AgentCard]":
|
|
2957
|
+
req = r.directory_search(q, capability, type, limit, cursor, scope)
|
|
2958
|
+
return cast("Page[AgentCard]", await self._c._send(req))
|
|
2959
|
+
|
|
2960
|
+
async def get_handle(self) -> WorkspaceHandle:
|
|
2961
|
+
return cast(WorkspaceHandle, await self._c._send(r.directory_handle_get()))
|
|
2962
|
+
|
|
2963
|
+
async def set_handle(self, handle: str) -> WorkspaceHandle:
|
|
2964
|
+
return cast(WorkspaceHandle, await self._c._send(r.directory_handle_set(handle)))
|
|
2965
|
+
|
|
2966
|
+
async def release_handle(self) -> WorkspaceHandle:
|
|
2967
|
+
return cast(WorkspaceHandle, await self._c._send(r.directory_handle_release()))
|
|
2968
|
+
|
|
2969
|
+
async def report(
|
|
2970
|
+
self,
|
|
2971
|
+
address: str,
|
|
2972
|
+
reason: DirectoryReportReason,
|
|
2973
|
+
*,
|
|
2974
|
+
details: Optional[str] = None,
|
|
2975
|
+
message_id: Optional[str] = None,
|
|
2976
|
+
) -> DirectoryReportResult:
|
|
2977
|
+
return cast(
|
|
2978
|
+
DirectoryReportResult,
|
|
2979
|
+
await self._c._send(r.directory_report(address, reason, details, message_id)),
|
|
2980
|
+
)
|
|
2981
|
+
|
|
2982
|
+
|
|
2983
|
+
class AsyncPublicDirectory:
|
|
2984
|
+
"""Async :class:`PublicDirectory`."""
|
|
2985
|
+
|
|
2986
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
2987
|
+
self._c = client
|
|
2988
|
+
|
|
2989
|
+
async def search(
|
|
2990
|
+
self,
|
|
2991
|
+
*,
|
|
2992
|
+
q: Optional[str] = None,
|
|
2993
|
+
capability: Optional[str] = None,
|
|
2994
|
+
type: Optional[MessageType] = None,
|
|
2995
|
+
limit: Optional[int] = None,
|
|
2996
|
+
cursor: Optional[str] = None,
|
|
2997
|
+
) -> "Page[PublicAgentCard]":
|
|
2998
|
+
req = r.public_agents_search(q, capability, type, limit, cursor)
|
|
2999
|
+
return cast("Page[PublicAgentCard]", await self._c._send(req))
|
|
3000
|
+
|
|
3001
|
+
async def get(self, address: str) -> PublicAgent:
|
|
3002
|
+
return cast(PublicAgent, await self._c._send(r.public_agent(address)))
|
|
3003
|
+
|
|
3004
|
+
async def a2a_card(self, address: str) -> dict[str, Any]:
|
|
3005
|
+
return cast(dict[str, Any], await self._c._send(r.public_agent(address, "agent-card.json")))
|
|
3006
|
+
|
|
3007
|
+
async def oasf(self, address: str) -> dict[str, Any]:
|
|
3008
|
+
return cast(dict[str, Any], await self._c._send(r.public_agent(address, "oasf.json")))
|
|
3009
|
+
|
|
3010
|
+
async def keys(self, address: str) -> PublicAgentKeys:
|
|
3011
|
+
return cast(PublicAgentKeys, await self._c._send(r.public_agent(address, "keys.json")))
|
|
3012
|
+
|
|
3013
|
+
async def handle(self, workspace: str, agent: str) -> PublicHandle:
|
|
3014
|
+
return cast(PublicHandle, await self._c._send(r.public_handle(workspace, agent)))
|
|
3015
|
+
|
|
3016
|
+
|
|
3017
|
+
class AsyncAccountApi:
|
|
3018
|
+
"""Async :class:`AccountApi`."""
|
|
3019
|
+
|
|
3020
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
3021
|
+
self._c = client
|
|
3022
|
+
|
|
3023
|
+
async def get(self) -> Account:
|
|
3024
|
+
return cast(Account, await self._c._send(r.account_get()))
|
|
3025
|
+
|
|
3026
|
+
async def request_claim(self, email: str) -> ClaimRequestResult:
|
|
3027
|
+
return cast(ClaimRequestResult, await self._c._send(r.signup_claim(email)))
|
|
3028
|
+
|
|
3029
|
+
async def add_agent(self, kind: Optional[str] = None) -> AddAgentResult:
|
|
3030
|
+
return cast(AddAgentResult, await self._c._send(r.signup_add_agent(kind)))
|
|
3031
|
+
|
|
3032
|
+
|
|
3033
|
+
class AsyncForwarding:
|
|
3034
|
+
"""Async :class:`Forwarding`."""
|
|
3035
|
+
|
|
3036
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
3037
|
+
self._c = client
|
|
3038
|
+
|
|
3039
|
+
async def list(self, inbox_id: str) -> builtins.list[InboxForward]:
|
|
3040
|
+
return cast("builtins.list[InboxForward]", (await self._c._send(r.forwarding_list(inbox_id)))["data"])
|
|
3041
|
+
|
|
3042
|
+
async def add(self, inbox_id: str, address: str, *, skip_flagged: Optional[bool] = None) -> InboxForward:
|
|
3043
|
+
return cast(InboxForward, await self._c._send(r.forwarding_add(inbox_id, address, skip_flagged)))
|
|
3044
|
+
|
|
3045
|
+
async def resend(self, inbox_id: str, forward_id: str) -> InboxForward:
|
|
3046
|
+
return cast(InboxForward, await self._c._send(r.forwarding_resend(inbox_id, forward_id)))
|
|
3047
|
+
|
|
3048
|
+
async def remove(self, inbox_id: str, forward_id: str) -> builtins.dict[str, Any]:
|
|
3049
|
+
return cast("builtins.dict[str, Any]", await self._c._send(r.forwarding_remove(inbox_id, forward_id)))
|
|
3050
|
+
|
|
3051
|
+
|
|
3052
|
+
class AsyncEscalationApi:
|
|
3053
|
+
"""Async :class:`EscalationApi`."""
|
|
3054
|
+
|
|
3055
|
+
def __init__(self, client: "AsyncAgentboxd") -> None:
|
|
3056
|
+
self._c = client
|
|
3057
|
+
|
|
3058
|
+
async def get(self) -> EscalationSettings:
|
|
3059
|
+
return cast(EscalationSettings, await self._c._send(r.escalation_get()))
|
|
3060
|
+
|
|
3061
|
+
async def update(
|
|
3062
|
+
self,
|
|
3063
|
+
*,
|
|
3064
|
+
contacts: Union[Sequence[str], NotGiven] = NOT_GIVEN,
|
|
3065
|
+
triggers: Union[Mapping[str, bool], NotGiven] = NOT_GIVEN,
|
|
3066
|
+
delivery: Union[Literal["immediate", "digest"], NotGiven] = NOT_GIVEN,
|
|
3067
|
+
max_per_hour: Union[int, NotGiven] = NOT_GIVEN,
|
|
3068
|
+
quiet_hours: Union[QuietHours, NotGiven, None] = NOT_GIVEN,
|
|
3069
|
+
include_excerpt: Union[bool, NotGiven] = NOT_GIVEN,
|
|
3070
|
+
) -> EscalationSettings:
|
|
3071
|
+
req = r.escalation_update(
|
|
3072
|
+
_escalation_body(contacts, triggers, delivery, max_per_hour, quiet_hours, include_excerpt)
|
|
3073
|
+
)
|
|
3074
|
+
return cast(EscalationSettings, await self._c._send(req))
|
|
3075
|
+
|
|
3076
|
+
async def get_inbox(self, inbox_id: str) -> InboxEscalation:
|
|
3077
|
+
return cast(InboxEscalation, await self._c._send(r.inbox_escalation_get(inbox_id)))
|
|
3078
|
+
|
|
3079
|
+
async def update_inbox(
|
|
3080
|
+
self,
|
|
3081
|
+
inbox_id: str,
|
|
3082
|
+
*,
|
|
3083
|
+
override: Union[bool, NotGiven] = NOT_GIVEN,
|
|
3084
|
+
contacts: Union[Sequence[str], NotGiven] = NOT_GIVEN,
|
|
3085
|
+
triggers: Union[Mapping[str, bool], NotGiven, None] = NOT_GIVEN,
|
|
3086
|
+
) -> InboxEscalation:
|
|
3087
|
+
req = r.inbox_escalation_update(inbox_id, _inbox_escalation_body(override, contacts, triggers))
|
|
3088
|
+
return cast(InboxEscalation, await self._c._send(req))
|
|
3089
|
+
|
|
3090
|
+
|
|
3091
|
+
class AsyncAgentboxd(_BaseClient):
|
|
3092
|
+
"""Asynchronous Agentboxd client with the same surface as :class:`Agentboxd`.
|
|
3093
|
+
|
|
3094
|
+
>>> async with AsyncAgentboxd() as mr:
|
|
3095
|
+
... inbox = await mr.inboxes.create()
|
|
3096
|
+
"""
|
|
3097
|
+
|
|
3098
|
+
def __init__(
|
|
3099
|
+
self,
|
|
3100
|
+
api_key: Optional[str] = None,
|
|
3101
|
+
base_url: Optional[str] = None,
|
|
3102
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
3103
|
+
*,
|
|
3104
|
+
http_client: Optional[httpx.AsyncClient] = None,
|
|
3105
|
+
) -> None:
|
|
3106
|
+
super().__init__(api_key, base_url, timeout)
|
|
3107
|
+
self._owns_http = http_client is None
|
|
3108
|
+
self._http = http_client if http_client is not None else httpx.AsyncClient(timeout=timeout)
|
|
3109
|
+
self.inboxes = AsyncInboxes(self)
|
|
3110
|
+
self.domains = AsyncDomains(self)
|
|
3111
|
+
self.messages = AsyncMessages(self)
|
|
3112
|
+
self.drafts = AsyncDrafts(self)
|
|
3113
|
+
self.threads = AsyncThreads(self)
|
|
3114
|
+
self.webhooks = AsyncWebhooks(self)
|
|
3115
|
+
self.contacts = AsyncContacts(self)
|
|
3116
|
+
self.knowledge = AsyncKnowledge(self)
|
|
3117
|
+
self.lists = AsyncLists(self)
|
|
3118
|
+
self.identity = AsyncIdentity(self)
|
|
3119
|
+
self.identities = AsyncIdentities(self)
|
|
3120
|
+
self.account = AsyncAccountApi(self)
|
|
3121
|
+
self.escalation = AsyncEscalationApi(self)
|
|
3122
|
+
self.forwarding = AsyncForwarding(self)
|
|
3123
|
+
self.agents = AsyncAgents(self)
|
|
3124
|
+
self.directory = AsyncDirectory(self)
|
|
3125
|
+
self.public_directory = AsyncPublicDirectory(self)
|
|
3126
|
+
|
|
3127
|
+
@classmethod
|
|
3128
|
+
async def signup(
|
|
3129
|
+
cls,
|
|
3130
|
+
*,
|
|
3131
|
+
agent_name: Optional[str] = None,
|
|
3132
|
+
owner_email: Optional[str] = None,
|
|
3133
|
+
base_url: Optional[str] = None,
|
|
3134
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
3135
|
+
http_client: Optional[httpx.AsyncClient] = None,
|
|
3136
|
+
max_iterations: int = 2**32,
|
|
3137
|
+
kind: Optional[str] = None,
|
|
3138
|
+
) -> "Signup[AsyncAgentboxd]":
|
|
3139
|
+
"""Async :meth:`Agentboxd.signup` (the proof of work runs in a worker thread)."""
|
|
3140
|
+
url = _signup_base_url(base_url)
|
|
3141
|
+
http = http_client if http_client is not None else httpx.AsyncClient(timeout=timeout)
|
|
3142
|
+
try:
|
|
3143
|
+
try:
|
|
3144
|
+
ch = cast(
|
|
3145
|
+
SignupChallenge,
|
|
3146
|
+
cls._parse(await http.request(**_public_kwargs(url, r.signup_challenge()))),
|
|
3147
|
+
)
|
|
3148
|
+
solution = await asyncio.to_thread(
|
|
3149
|
+
solve_signup_challenge, ch["challenge"], int(ch["difficulty"]), max_iterations
|
|
3150
|
+
)
|
|
3151
|
+
req = r.signup_create(ch["challenge"], solution, agent_name, owner_email, kind)
|
|
3152
|
+
result = cast(SignupResult, cls._parse(await http.request(**_public_kwargs(url, req))))
|
|
3153
|
+
except httpx.TimeoutException as exc:
|
|
3154
|
+
raise APIConnectionError(f"Request timed out: {exc}", code="timeout") from exc
|
|
3155
|
+
except httpx.TransportError as exc:
|
|
3156
|
+
raise APIConnectionError(f"Connection error: {exc}") from exc
|
|
3157
|
+
finally:
|
|
3158
|
+
if http_client is None:
|
|
3159
|
+
await http.aclose()
|
|
3160
|
+
client = cls(api_key=result["api_key"], base_url=url, timeout=timeout, http_client=http_client)
|
|
3161
|
+
return Signup(client=client, result=result)
|
|
3162
|
+
|
|
3163
|
+
async def search(
|
|
3164
|
+
self,
|
|
3165
|
+
q: str,
|
|
3166
|
+
inbox_id: Optional[str] = None,
|
|
3167
|
+
cursor: Optional[str] = None,
|
|
3168
|
+
limit: Optional[int] = None,
|
|
3169
|
+
channel: Optional[MessageChannel] = None,
|
|
3170
|
+
type: Optional[MessageType] = None,
|
|
3171
|
+
) -> Page[SearchResult]:
|
|
3172
|
+
"""Full-text search (web-search syntax: ``"exact phrase"``, ``-exclude``, ``or``)."""
|
|
3173
|
+
return cast(
|
|
3174
|
+
"Page[SearchResult]", await self._send(r.search(q, inbox_id, cursor, limit, channel, type))
|
|
3175
|
+
)
|
|
3176
|
+
|
|
3177
|
+
async def metrics(
|
|
3178
|
+
self,
|
|
3179
|
+
from_: Optional[str] = None,
|
|
3180
|
+
to: Optional[str] = None,
|
|
3181
|
+
tz: Optional[str] = None,
|
|
3182
|
+
inbox_id: Optional[str] = None,
|
|
3183
|
+
bucket: Optional[MetricsBucket] = None,
|
|
3184
|
+
) -> Metrics:
|
|
3185
|
+
"""Sent/received/delivery counts bucketed in ``tz`` (IANA), a 30-day heatmap and resources."""
|
|
3186
|
+
return cast(Metrics, await self._send(r.metrics(from_, to, tz, inbox_id, bucket)))
|
|
3187
|
+
|
|
3188
|
+
async def emergency_stop(self, reason: Optional[str] = None) -> EmergencyStopResult:
|
|
3189
|
+
return cast(EmergencyStopResult, await self._send(r.emergency_stop(reason)))
|
|
3190
|
+
|
|
3191
|
+
async def deliverability(self) -> DeliverabilitySummary:
|
|
3192
|
+
"""Bounce and complaint rates (7 and 30 days), suppressed contacts, your domains' SPF/DKIM/DMARC
|
|
3193
|
+
and the shared IP's blocklist status (permission ``metrics:read``, workspace keys)."""
|
|
3194
|
+
return cast(DeliverabilitySummary, await self._send(r.deliverability()))
|
|
3195
|
+
|
|
3196
|
+
async def stream_token(self) -> StreamToken:
|
|
3197
|
+
"""A single-use, 60-second WebSocket URL for ``GET /v1/stream``."""
|
|
3198
|
+
return cast(StreamToken, await self._send(r.stream_token()))
|
|
3199
|
+
|
|
3200
|
+
def stream(
|
|
3201
|
+
self,
|
|
3202
|
+
inbox_ids: Optional[Sequence[str]] = None,
|
|
3203
|
+
event_types: Optional[Sequence[WebhookEventType]] = None,
|
|
3204
|
+
payload: Optional[WebhookPayload] = None,
|
|
3205
|
+
since: Optional[str] = None,
|
|
3206
|
+
reconnect: bool = True,
|
|
3207
|
+
) -> EventStream:
|
|
3208
|
+
"""Realtime events over a WebSocket (permission ``messages:read``): the same bodies as webhooks.
|
|
3209
|
+
|
|
3210
|
+
Iterate with ``async for``; the stream reconnects and resumes after the last event on its own.
|
|
3211
|
+
Needs ``pip install 'agentboxd[stream]'``.
|
|
3212
|
+
|
|
3213
|
+
>>> async for event in mr.stream(event_types=["message.received"]):
|
|
3214
|
+
... print(event["data"]["message"]["subject"])
|
|
3215
|
+
"""
|
|
3216
|
+
|
|
3217
|
+
async def mint_url() -> str:
|
|
3218
|
+
return (await self.stream_token())["url"]
|
|
3219
|
+
|
|
3220
|
+
return EventStream(
|
|
3221
|
+
mint_url,
|
|
3222
|
+
inbox_ids=inbox_ids,
|
|
3223
|
+
event_types=event_types,
|
|
3224
|
+
payload=payload,
|
|
3225
|
+
since=since,
|
|
3226
|
+
reconnect=reconnect,
|
|
3227
|
+
)
|
|
3228
|
+
|
|
3229
|
+
async def _send(self, req: Request) -> Any:
|
|
3230
|
+
try:
|
|
3231
|
+
response = await self._http.request(**self._build(req))
|
|
3232
|
+
except httpx.TimeoutException as exc:
|
|
3233
|
+
raise APIConnectionError(f"Request timed out: {exc}", code="timeout") from exc
|
|
3234
|
+
except httpx.TransportError as exc:
|
|
3235
|
+
raise APIConnectionError(f"Connection error: {exc}") from exc
|
|
3236
|
+
return self._parse(response)
|
|
3237
|
+
|
|
3238
|
+
async def close(self) -> None:
|
|
3239
|
+
if self._owns_http:
|
|
3240
|
+
await self._http.aclose()
|
|
3241
|
+
|
|
3242
|
+
async def __aenter__(self: _SelfT) -> _SelfT:
|
|
3243
|
+
return self
|
|
3244
|
+
|
|
3245
|
+
async def __aexit__(
|
|
3246
|
+
self,
|
|
3247
|
+
exc_type: Optional[type[BaseException]],
|
|
3248
|
+
exc: Optional[BaseException],
|
|
3249
|
+
tb: Optional[TracebackType],
|
|
3250
|
+
) -> None:
|
|
3251
|
+
await self.close()
|