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/_types.py ADDED
@@ -0,0 +1,1864 @@
1
+ """Response and input types. All are TypedDicts: API JSON is returned as plain dicts."""
2
+
3
+ import sys
4
+ from typing import TYPE_CHECKING, Any, Generic, Literal, Optional, TypedDict, TypeVar, Union
5
+
6
+ __all__ = [
7
+ "Account",
8
+ "AccountClaim",
9
+ "AckResult",
10
+ "AddAgentResult",
11
+ "AgentAssurance",
12
+ "AgentBundle",
13
+ "AgentCard",
14
+ "AgentCardInput",
15
+ "AgentCardListing",
16
+ "AgentCardSkill",
17
+ "AgentCardStatus",
18
+ "AgentCardVisibility",
19
+ "AgentKey",
20
+ "AgentKeyJwk",
21
+ "AgentKeyList",
22
+ "AgentMessaging",
23
+ "AgentStatus",
24
+ "AiDisclosure",
25
+ "AiProcessing",
26
+ "Attachment",
27
+ "AttachmentExtraction",
28
+ "AttachmentInput",
29
+ "AttachmentText",
30
+ "BounceReason",
31
+ "BuiltinExtractionSchema",
32
+ "BusiestDay",
33
+ "ClaimRequestResult",
34
+ "Contact",
35
+ "ContactWithThreads",
36
+ "Deliverability",
37
+ "Direction",
38
+ "DirectoryReportReason",
39
+ "DirectoryReportResult",
40
+ "DirectoryVerifyResult",
41
+ "Domain",
42
+ "DomainRecord",
43
+ "DomainRecordKey",
44
+ "DomainStatus",
45
+ "DomainZoneFile",
46
+ "Draft",
47
+ "DraftApprover",
48
+ "DraftAttachment",
49
+ "DraftCitation",
50
+ "DraftError",
51
+ "DraftKeep",
52
+ "DraftReply",
53
+ "DraftSendResult",
54
+ "DraftStatus",
55
+ "EmergencyStopResult",
56
+ "EnvelopeEventData",
57
+ "EscalationContact",
58
+ "EscalationSettings",
59
+ "EscalationTrigger",
60
+ "ExtendResult",
61
+ "ExtractionError",
62
+ "ExtractionMethod",
63
+ "ExtractionStatus",
64
+ "HeatmapDay",
65
+ "IdentityClient",
66
+ "IdentityClientType",
67
+ "IdentityClientWithSecret",
68
+ "IdentityFlow",
69
+ "IdentityScope",
70
+ "IdentitySignIn",
71
+ "IdentitySubjectType",
72
+ "IdentityToken",
73
+ "InboundQuality",
74
+ "Inbox",
75
+ "InboxEscalation",
76
+ "InboxIdentity",
77
+ "InboxIdentityApp",
78
+ "KnowledgeDoc",
79
+ "KnowledgeListItem",
80
+ "KnowledgeSearchResult",
81
+ "KnowledgeSearchResults",
82
+ "Lease",
83
+ "LeaseClaim",
84
+ "ListDirection",
85
+ "ListEntries",
86
+ "ListEntry",
87
+ "ListKind",
88
+ "Message",
89
+ "MessageAgent",
90
+ "MessageAi",
91
+ "MessageAnalysis",
92
+ "MessageApproval",
93
+ "MessageAuthor",
94
+ "MessageCategory",
95
+ "MessageCategoryInfo",
96
+ "MessageChannel",
97
+ "MessageDelivery",
98
+ "MessageEventData",
99
+ "MessageRisk",
100
+ "MessageScreening",
101
+ "MessageStatus",
102
+ "MessageType",
103
+ "MessageUrgency",
104
+ "MessageWithheld",
105
+ "Metadata",
106
+ "MetadataValue",
107
+ "MetricCounts",
108
+ "Metrics",
109
+ "MetricsBucket",
110
+ "MetricsPoint",
111
+ "MinimalAgentCard",
112
+ "NackResult",
113
+ "Page",
114
+ "PublicAgent",
115
+ "PublicAgentCard",
116
+ "PublicAgentKeys",
117
+ "PublicCardUrls",
118
+ "PublicHandle",
119
+ "QueueMetrics",
120
+ "QuietHours",
121
+ "ResolvedAgent",
122
+ "Resources",
123
+ "ScreeningReason",
124
+ "ScreeningState",
125
+ "SearchResult",
126
+ "SignupChallenge",
127
+ "SignupClaim",
128
+ "SignupResult",
129
+ "SignupWorkspace",
130
+ "Streak",
131
+ "StreamEvent",
132
+ "StreamToken",
133
+ "StructuredExtraction",
134
+ "Thread",
135
+ "ThreadWithMessages",
136
+ "UnclaimedRestrictions",
137
+ "UrgencyLevel",
138
+ "VerificationInfo",
139
+ "VerificationResult",
140
+ "Webhook",
141
+ "WebhookCatalogEntry",
142
+ "WebhookEvent",
143
+ "WebhookEventType",
144
+ "WebhookPayload",
145
+ "WebhookStats",
146
+ "WebhookTestResult",
147
+ "WorkspaceHandle",
148
+ ]
149
+
150
+ _T = TypeVar("_T")
151
+
152
+ Direction = Literal["inbound", "outbound"]
153
+
154
+ MessageStatus = Literal["queued", "sent", "delivered", "bounced", "complained", "failed", "received"]
155
+ MessageChannel = Literal["agent", "email", "mixed"]
156
+ """``agent``: an inbound copy from another Agentboxd inbox, sender verified and signed. ``mixed``: an
157
+ outbound message with agent and email recipients. Everything else is ``email``."""
158
+ MessageType = Literal["message", "task", "event"]
159
+ """Advisory message kind set by the sender."""
160
+ AgentAssurance = Literal["unclaimed", "workspace", "domain_verified", "org_verified"]
161
+ """How strongly Agentboxd vouches for an agent sender (``unclaimed``: an agent-created workspace no person
162
+ claimed yet)."""
163
+
164
+ WebhookEventType = Literal[
165
+ "message.received",
166
+ "message.sent",
167
+ "message.delivered",
168
+ "message.bounced",
169
+ "message.complained",
170
+ "message.enriched",
171
+ "message.released",
172
+ "inbox.expired",
173
+ "message.received.blocked",
174
+ "draft.created",
175
+ "draft.updated",
176
+ "draft.sent",
177
+ "draft.failed",
178
+ "draft.cancelled",
179
+ "identity.token_issued",
180
+ "identity.signed_in",
181
+ "signup.created",
182
+ "signup.claimed",
183
+ "attachment.extracted",
184
+ "attachment.extraction_failed",
185
+ "inbox.paused",
186
+ "inbox.resumed",
187
+ "domain.dkim_rotated",
188
+ "domain.dkim_rotation_due",
189
+ "domain.verified",
190
+ "domain.failed",
191
+ "connector.authorized",
192
+ "connector.revoked",
193
+ "workspace.stopped",
194
+ "workspace.resumed",
195
+ "escalation.sent",
196
+ "agent.updated",
197
+ "agent.revoked",
198
+ "agent.deleted",
199
+ "agent.reported",
200
+ ]
201
+
202
+ WebhookPayload = Literal["full", "envelope"]
203
+ """``full`` = the whole message (default) · ``envelope`` = ids, addresses, subject and labels only."""
204
+
205
+ ListDirection = Literal["receive", "send", "reply"]
206
+ ListKind = Literal["allow", "block"]
207
+ MetricsBucket = Literal["hour", "day"]
208
+
209
+ MessageCategory = Literal[
210
+ "support", "sales", "billing", "verification", "notification", "newsletter", "personal", "other"
211
+ ]
212
+
213
+ UrgencyLevel = Literal["low", "normal", "high", "critical"]
214
+
215
+ AiProcessing = Literal["off", "categorize", "full"]
216
+ """Workspace AI switch: ``off`` (nothing leaves the server), ``categorize`` (JEV), ``full`` (+ drafts)."""
217
+
218
+ MetadataValue = Union[str, int, float, bool, None]
219
+ Metadata = dict[str, MetadataValue]
220
+ """Custom key/value data: at most 50 keys (``^[a-zA-Z0-9_.-]{1,64}$``), string values up to 1,000 chars.
221
+
222
+ In updates the object is merged: given keys are set and a ``None`` value deletes the key."""
223
+
224
+
225
+ class _InboxBase(TypedDict):
226
+ id: str
227
+ address: str
228
+ username: str
229
+ display_name: Optional[str]
230
+ client_id: Optional[str]
231
+ daily_send_limit: int
232
+ created_at: str
233
+
234
+
235
+ class Inbox(_InboxBase, total=False):
236
+ kind: Literal["mailbox", "identity"]
237
+ """``identity``: an identity-only agent (no mail, see ``client.identities``). Identity ids only reach you
238
+ through per-id inbox routes (``get``, ``pause``), never through ``inboxes.list``."""
239
+ metadata: Metadata
240
+ """Custom metadata (always present on servers with Phase 2b)."""
241
+ temporary: bool
242
+ """Temporary (receive-only, self-deleting) inbox."""
243
+ expires_at: Optional[str]
244
+ """When a temporary inbox is wiped (ISO 8601); ``None`` for permanent inboxes."""
245
+ status: Literal["active", "paused"]
246
+ """``paused``: sends are refused (423 ``inbox_paused``) and inbound events are held until resume."""
247
+ paused_at: Optional[str]
248
+ paused_reason: Optional[str]
249
+ promotions_filter: bool
250
+ """Promotions & spam view: the dashboard shows mail labelled ``ai:sales`` or ``local:spam`` apart. On by
251
+ default for role addresses (hello@, support@, security@, ...)."""
252
+ held_count: int
253
+ """Screening: held mail nobody has opened yet."""
254
+ pending_draft_count: int
255
+ """Drafts waiting for a person: to approve (``draft``) or refused at their send time (``failed``)."""
256
+ needs_human_count: int
257
+ """Unread received mail labelled ``ai:needs-human``."""
258
+ recent_bounce_count: int
259
+ """Sent messages that bounced in the last 7 days."""
260
+
261
+
262
+ class ResumedInbox(Inbox, total=False):
263
+ """``inboxes.resume()``: the inbox plus how many held events were released."""
264
+
265
+ released_events: int
266
+
267
+
268
+ DomainStatus = Literal["pending", "verified", "failed", "disabled"]
269
+
270
+ DomainRecordKey = Literal["verification", "mx", "spf", "dkim", "dmarc", "dkim_next", "dkim_previous"]
271
+ """``dkim_next`` / ``dkim_previous`` only appear during a DKIM key rotation (never required)."""
272
+
273
+
274
+ class _DomainRecordBase(TypedDict):
275
+ key: DomainRecordKey
276
+ type: Literal["TXT", "MX"]
277
+ name: str
278
+ value: str
279
+ required: bool
280
+ status: Literal["ok", "missing", "mismatch"]
281
+
282
+
283
+ class DomainRecord(_DomainRecordBase, total=False):
284
+ """One DNS record to publish for a custom domain, with the result of the last check."""
285
+
286
+ found: list[str]
287
+ """What was found in DNS for this name."""
288
+ host: str
289
+ """The part of ``name`` to type at DNS providers that add the zone themselves (``@`` = the zone)."""
290
+ hint: Literal["full_name_in_host"]
291
+ """Missing, but published at ``<name>.<zone>``: the full name went into a host field.
292
+ Rename it to ``host``."""
293
+
294
+
295
+ class InboxForward(TypedDict):
296
+ """An automatic forwarding address of an inbox. Nothing is forwarded until it confirms by email."""
297
+
298
+ id: str
299
+ inbox_id: str
300
+ address: str
301
+ status: Literal["pending", "confirmed"]
302
+ skip_flagged: bool
303
+ """Skip mail flagged as phishing, prompt injection or failing DMARC (default True)."""
304
+ confirmed_at: Optional[str]
305
+ confirmation_sent_at: Optional[str]
306
+ last_forwarded_at: Optional[str]
307
+ forwarded_count: int
308
+ created_at: str
309
+
310
+
311
+ class DomainDnsProvider(TypedDict):
312
+ id: str
313
+ name: str
314
+
315
+
316
+ class DomainDns(TypedDict):
317
+ """Where a custom domain's DNS is hosted, from its NS records."""
318
+
319
+ zone: str
320
+ nameservers: list[str]
321
+ provider: Optional[DomainDnsProvider]
322
+ """A known DNS provider (``cloudflare``, ``godaddy``, ``route53``, ...), or None."""
323
+ checked_at: str
324
+
325
+
326
+ class DkimNext(TypedDict):
327
+ selector: str
328
+ status: Literal["ok", "missing", "mismatch"]
329
+ started_at: Optional[str]
330
+
331
+
332
+ class DkimPrevious(TypedDict):
333
+ selector: str
334
+ retire_at: Optional[str]
335
+
336
+
337
+ class DomainDkim(TypedDict):
338
+ """DKIM key rotation state of a custom domain."""
339
+
340
+ selector: str
341
+ active_since: str
342
+ rotation_due: bool
343
+ """The active key has signed for a year: rotate it."""
344
+ next: Optional[DkimNext]
345
+ """A rotation waiting for its new record (``dkim_next`` in ``records``)."""
346
+ previous: Optional[DkimPrevious]
347
+ """The replaced key: keep its record (``dkim_previous``) until ``retire_at``."""
348
+
349
+
350
+ class _DomainBase(TypedDict):
351
+ id: str
352
+ domain: str
353
+ status: DomainStatus
354
+ receiving: bool
355
+ records: list[DomainRecord]
356
+ verified_at: Optional[str]
357
+ last_checked_at: Optional[str]
358
+ created_at: str
359
+
360
+
361
+ class Domain(_DomainBase, total=False):
362
+ """A workspace's own domain: inboxes on it send DKIM-signed with its own key."""
363
+
364
+ dkim: DomainDkim
365
+ """DKIM key rotation state (optional for older servers)."""
366
+ dns: Optional[DomainDns]
367
+ """Where the domain's DNS is hosted; None until found (optional for older servers)."""
368
+
369
+
370
+ class DomainZoneFile(TypedDict):
371
+ """A domain's DNS records as a BIND zone file, for DNS providers that import one."""
372
+
373
+ filename: str
374
+ """Suggested file name, e.g. ``mail.acme.com.zone.txt``."""
375
+ content: str
376
+ """The zone-file text: one line per record to publish, with fully qualified names."""
377
+
378
+
379
+ ExtractionStatus = Literal["pending", "done", "failed", "skipped"]
380
+ ExtractionMethod = Literal["text", "ocr"]
381
+ BuiltinExtractionSchema = Literal["invoice", "receipt", "tax_form"]
382
+
383
+
384
+ class ExtractionError(TypedDict):
385
+ code: str
386
+ """unsupported_type, quota, ocr_unavailable, ocr_error, timeout, parse_error, ..."""
387
+ message: str
388
+
389
+
390
+ class AttachmentExtraction(TypedDict):
391
+ """Text extraction of an inbound attachment. Read the text with ``messages.attachment_text``."""
392
+
393
+ status: ExtractionStatus
394
+ method: Optional[ExtractionMethod]
395
+ pages: Optional[int]
396
+ chars: Optional[int]
397
+ language: Optional[str]
398
+ truncated: bool
399
+ error: Optional[ExtractionError]
400
+ updated_at: Optional[str]
401
+
402
+
403
+ class _AttachmentBase(TypedDict):
404
+ id: str
405
+ filename: Optional[str]
406
+ content_type: str
407
+ size_bytes: int
408
+ sha256: str
409
+ content_id: Optional[str]
410
+ inline: bool
411
+ available: bool
412
+
413
+
414
+ class Attachment(_AttachmentBase, total=False):
415
+ extraction: Optional[AttachmentExtraction]
416
+ """``None`` for outbound mail and attachments stored before extraction existed."""
417
+
418
+
419
+ class AttachmentText(TypedDict):
420
+ """``messages.attachment_text``: ``text`` is ``None`` until ``extraction.status`` is ``done``.
421
+
422
+ The text is untrusted: it comes from a document someone emailed."""
423
+
424
+ attachment_id: str
425
+ message_id: str
426
+ filename: Optional[str]
427
+ content_type: str
428
+ extraction: Optional[AttachmentExtraction]
429
+ text: Optional[str]
430
+ offset: int
431
+ total_chars: Optional[int]
432
+ next_offset: Optional[int]
433
+ """Pass as ``offset`` to read the next page; ``None`` at the end."""
434
+ untrusted: bool
435
+
436
+
437
+ class StructuredExtraction(TypedDict):
438
+ """``messages.extract_attachment``: ``data`` validates against the schema but is untrusted."""
439
+
440
+ attachment_id: str
441
+ message_id: str
442
+ schema: str
443
+ data: dict[str, Any]
444
+ model: str
445
+ repaired: bool
446
+ truncated: bool
447
+ untrusted: bool
448
+
449
+
450
+ class AttachmentInput(TypedDict):
451
+ """An attachment to send. Build one with ``attachment_from_path`` / ``attachment_from_bytes``."""
452
+
453
+ filename: str
454
+ content_type: str
455
+ content_base64: str
456
+
457
+
458
+ class _VerificationInfoBase(TypedDict):
459
+ code: Optional[str]
460
+ """One-time code (4-10 chars, digits or alphanumeric), if found."""
461
+ link: Optional[str]
462
+ """Verification / magic / confirm link, if found."""
463
+ confidence: float
464
+ """0-1. Regex-only detection is capped at 0.7; JEV confirmation raises or lowers it."""
465
+ jev_probability: Optional[float]
466
+ """JEV's probability that this is a verification/login email, once enrichment has run."""
467
+
468
+
469
+ class VerificationInfo(_VerificationInfoBase, total=False):
470
+ """Login/verification code or magic link found in a message."""
471
+
472
+ auth_failed: bool
473
+ """The sender failed authentication (DMARC, or SPF without aligned DKIM): the code may come from a
474
+ spoofer. Don't use it unless you just asked for one. Absent on older servers."""
475
+
476
+
477
+ class MessageCategoryInfo(TypedDict):
478
+ """JEV's category for a message."""
479
+
480
+ label: MessageCategory
481
+ confidence: float
482
+ """0-1. ``label`` becomes an ``ai:<label>`` label only at 0.6 or more (else ``ai:uncertain``)."""
483
+ probabilities: dict[MessageCategory, float]
484
+ """Probability of each category JEV returned (not necessarily all eight)."""
485
+
486
+
487
+ class MessageRisk(TypedDict):
488
+ """Yes-probabilities (0-1). ``ai:injection-risk`` / ``ai:phishing`` are added at 0.8 or more."""
489
+
490
+ injection: float
491
+ """The message tries to instruct an AI (ignore rules, reveal data, act for the sender)."""
492
+ phishing: float
493
+ """Credential harvesting, scam or impersonation."""
494
+
495
+
496
+ class MessageUrgency(TypedDict):
497
+ level: UrgencyLevel
498
+ """Most likely level. ``high`` and ``critical`` add the ``ai:urgent`` label."""
499
+ score: float
500
+ """Expected score from 0 (low) to 3 (critical); may fall between levels."""
501
+ confidence: float
502
+
503
+
504
+ class _MessageAiBase(TypedDict):
505
+ verification: Optional[VerificationInfo]
506
+
507
+
508
+ class MessageAi(_MessageAiBase, total=False):
509
+ """AI/derived data attached to a message.
510
+
511
+ ``verification`` is always present. The other keys appear only once JEV enrichment has run
512
+ (the server needs ``TYPESAFE_API_KEY``), so read them with ``.get()``. A ``message.enriched``
513
+ webhook fires when they are added.
514
+ """
515
+
516
+ category: MessageCategoryInfo
517
+ risk: MessageRisk
518
+ needs_human: float
519
+ """Yes-probability (0-1) that a person should handle it. ``ai:needs-human`` at 0.7 or more."""
520
+ urgency: MessageUrgency
521
+ auto_reply: float
522
+ """Yes-probability (0-1) of an out-of-office / auto-responder / bulk mail. ``ai:auto-reply`` at 0.8."""
523
+ model: str
524
+ """Engine that produced the fields above (``"jev"``)."""
525
+ enriched_at: str
526
+ """When enrichment finished (ISO 8601)."""
527
+ analysis_coverage: Literal["full", "partial"]
528
+ """Whether enrichment read the whole message. Prefer ``message["analysis"]``."""
529
+ enrichment_error: str
530
+ """Set when enrichment gave up after retries; the message is otherwise unaffected."""
531
+ enrichment_skipped: Literal["quota", "ai_off", "not_available"]
532
+ """Why enrichment didn't run. Prefer ``message["analysis"]``."""
533
+ local_screen: "LocalScreen"
534
+ """The local injection check (no AI, every received message since Screening v2)."""
535
+ local_spam: "LocalSpam"
536
+ """Why the message got ``local:spam``."""
537
+ released_at: str
538
+ """A held message released to agents: when. Prefer ``message["screening"]``."""
539
+ released_by: str
540
+ """Who released it: ``user:<id>`` or ``key:<id>``."""
541
+
542
+
543
+ ScreeningState = Literal["screened", "pending", "held", "released"]
544
+ ScreeningReason = Literal[
545
+ "ai_off",
546
+ "not_applicable",
547
+ "not_available",
548
+ "injection_risk",
549
+ "phishing",
550
+ "check_failed",
551
+ "quota",
552
+ "check_timed_out",
553
+ "blocked",
554
+ ]
555
+
556
+
557
+ class MessageScreening(TypedDict):
558
+ """Whether agents get a received message.
559
+
560
+ When the workspace screens agent mail (the default for new workspaces), claim and ``wait`` return
561
+ only ``screened`` and ``released`` mail unless you pass ``include_unscreened`` / ``include_held``.
562
+ """
563
+
564
+ state: ScreeningState
565
+ reason: Optional[ScreeningReason]
566
+ """Why it is held, or why it counts as screened without a check (``ai_off``, ``not_available``,
567
+ ``not_applicable``)."""
568
+ released_at: Optional[str]
569
+
570
+
571
+ class MessageWithheld(TypedDict):
572
+ """What was left out of a withheld message."""
573
+
574
+ state: ScreeningState
575
+ reason: Optional[ScreeningReason]
576
+ attachments: int
577
+
578
+
579
+ class LocalScreenReason(TypedDict, total=False):
580
+ code: str
581
+ weight: float
582
+ where: Literal["visible", "hidden", "beyond_window", "attachment"]
583
+ detail: str
584
+
585
+
586
+ class LocalScreen(TypedDict):
587
+ """The local injection check: no AI, run on every received message. It reads the whole message,
588
+ including HTML text hidden from a human reader. At ``score`` 0.6 or more the message gets
589
+ ``local:injection-risk``."""
590
+
591
+ score: float
592
+ flagged: bool
593
+ reasons: list[LocalScreenReason]
594
+ hidden_chars: int
595
+ """Characters of HTML text hidden from a sighted reader."""
596
+ complete: bool
597
+ """False when some text was too long to scan in full."""
598
+ version: int
599
+
600
+
601
+ class LocalSpam(TypedDict):
602
+ reasons: list[str]
603
+
604
+
605
+ class MessageAnalysis(TypedDict):
606
+ """Whether a received message was checked for prompt injection and phishing, and how much of it.
607
+
608
+ A message without an ``ai:injection-risk`` or ``ai:phishing`` label is only known to be clean when
609
+ ``state`` is ``"completed"`` and ``coverage`` is ``"full"``.
610
+ """
611
+
612
+ state: Literal["pending", "completed", "skipped", "failed"]
613
+ coverage: Optional[Literal["full", "partial"]]
614
+ """Completed only. ``partial``: some of the message wasn't read (a long body or data, attachment text
615
+ cut or not extracted)."""
616
+ reason: Optional[Literal["quota", "ai_off", "not_available", "blocked", "not_applicable"]]
617
+ """Skipped only."""
618
+
619
+
620
+ # ``from`` is a Python keyword, so these use the functional TypedDict syntax.
621
+ _VerificationResultBase = TypedDict(
622
+ "_VerificationResultBase",
623
+ {
624
+ "code": Optional[str],
625
+ "link": Optional[str],
626
+ "confidence": float,
627
+ "jev_probability": Optional[float],
628
+ "message_id": str,
629
+ "from": str,
630
+ "subject": Optional[str],
631
+ "received_at": Optional[str],
632
+ },
633
+ )
634
+
635
+
636
+ class VerificationResult(_VerificationResultBase, total=False):
637
+ """``GET /v1/inboxes/{id}/verification``: the newest code or link and the message it came from."""
638
+
639
+ auth_failed: bool
640
+ """Only ``True`` with ``include_unauthenticated=True``: the sender failed authentication."""
641
+
642
+
643
+ _MessageBase = TypedDict(
644
+ "_MessageBase",
645
+ {
646
+ "id": str,
647
+ "inbox_id": str,
648
+ "thread_id": str,
649
+ "direction": Direction,
650
+ "status": MessageStatus,
651
+ "rfc_message_id": str,
652
+ "in_reply_to": Optional[str],
653
+ "references": list[str],
654
+ "from": str,
655
+ "to": list[str],
656
+ "cc": list[str],
657
+ "bcc": list[str],
658
+ "reply_to": Optional[str],
659
+ "subject": Optional[str],
660
+ "text": Optional[str],
661
+ "html": Optional[str],
662
+ # The new content of the message only: quoted history and signatures removed.
663
+ "extracted_text": Optional[str],
664
+ "headers": dict[str, Union[str, list[str]]],
665
+ "labels": list[str],
666
+ "is_read": bool,
667
+ "provider_message_id": Optional[str],
668
+ "size_bytes": int,
669
+ "sent_at": Optional[str],
670
+ "received_at": Optional[str],
671
+ "created_at": str,
672
+ "attachments": list[Attachment],
673
+ # Derived data: verification codes, plus JEV categories and risk scores once enriched. Never null.
674
+ "ai": MessageAi,
675
+ },
676
+ )
677
+
678
+
679
+ class MessageDelivery(TypedDict):
680
+ """Outbound messages: where one recipient's copy went."""
681
+
682
+ address: str
683
+ channel: Literal["agent", "email"]
684
+ status: Literal["queued", "delivered", "sent", "bounced"]
685
+
686
+
687
+ _MessageAgentBase = TypedDict(
688
+ "_MessageAgentBase",
689
+ {
690
+ "verified": bool,
691
+ # The sender's address, as verified by Agentboxd at delivery.
692
+ "from": str,
693
+ "assurance": AgentAssurance,
694
+ "signed_at": Optional[str],
695
+ "kid": Optional[str],
696
+ # Compact JWS (ES256, typ agentboxd-msg+jwt), bound to this copy's recipient.
697
+ "signature": Optional[str],
698
+ },
699
+ )
700
+
701
+
702
+ class MessageAgent(_MessageAgentBase, total=False):
703
+ """Inbound agent-channel copies: the sender verified at delivery and the per-copy signature
704
+ (``agentboxd.identity.verify_agent_message`` checks it outside Agentboxd). A verified sender is not
705
+ trustworthy content."""
706
+
707
+ reason: str
708
+ """Why ``verified`` is false: ``revoked`` (the owner revoked its agent card) or ``suspended`` (the
709
+ operator suspended it); such senders are no longer signed."""
710
+
711
+
712
+ class _MessageAuthorBase(TypedDict):
713
+ verified: bool
714
+ kid: str
715
+ """The RFC 7638 thumbprint of the agent's own key."""
716
+ alg: Literal["EdDSA", "ES256"]
717
+ signature: str
718
+ """Compact JWS (typ ``agentboxd-author+jwt``) made by the sending agent with its own key."""
719
+
720
+
721
+ class MessageAuthor(_MessageAuthorBase, total=False):
722
+ """aSIM phase 2: the sending agent's own author signature, checked by Agentboxd at send and re-checked at
723
+ delivery. ``agentboxd.identity.verify_author_signature`` checks it outside Agentboxd."""
724
+
725
+ reason: str
726
+ """Why ``verified`` is false: ``key_revoked`` or ``key_unknown``."""
727
+
728
+
729
+ class AiDisclosure(TypedDict):
730
+ """The ``Agent-Disclosure`` header of a message, parsed. Inbound: untrusted unless ``verified``."""
731
+
732
+ agent: bool
733
+ on_behalf_of: Optional[str]
734
+ operator: Optional[str]
735
+ verified: bool
736
+ """True only for mail from an Agentboxd sender (internal delivery, or a DKIM pass for its domain)."""
737
+ header: str
738
+
739
+
740
+ class Message(_MessageBase, total=False):
741
+ contact_id: Optional[str]
742
+ """Inbound: the sender's contact. Outbound: the first recipient that is a contact."""
743
+ channel: MessageChannel
744
+ """Agent messaging (absent on servers before it)."""
745
+ type: MessageType
746
+ data: Any
747
+ """The sender's structured data (a JSON object or array), or None. Untrusted input, like the text."""
748
+ delivery: Optional[list[MessageDelivery]]
749
+ """Outbound only: per-recipient channel and outcome."""
750
+ agent: Optional[MessageAgent]
751
+ """Inbound agent-channel copies only."""
752
+ author: Optional[MessageAuthor]
753
+ """The agent's own author signature (outbound rows and inbound agent copies), or None."""
754
+ approval: Optional["MessageApproval"]
755
+ """Sent from a draft: who approved it, when, and the content hash it covered.
756
+ Kept after the draft is deleted."""
757
+ ai_disclosure: Optional[AiDisclosure]
758
+ """AI disclosure: what was disclosed (outbound) or the sender's header (inbound). None when absent."""
759
+ analysis: Optional[MessageAnalysis]
760
+ """Received mail: whether it was checked for prompt injection and phishing. None for sent mail."""
761
+ screening: Optional["MessageScreening"]
762
+ """Received mail: whether agents get it (screened, pending, held, released). None for sent mail."""
763
+ withheld: "MessageWithheld"
764
+ """Set when the content was withheld from this key (held or not screened yet): subject, text, html,
765
+ headers, attachments, data and the detected code are left out unless you opt in."""
766
+ auto_reply: bool
767
+ """Received mail: an automatic reply (out of office and the like), from its headers or the
768
+ ``ai:auto-reply`` label. Don't answer it. False for sent mail."""
769
+
770
+
771
+ class Lease(TypedDict):
772
+ """One claimed message (claim/ack queue). Present ``lease_id`` to ack, nack or extend."""
773
+
774
+ lease_id: str
775
+ lease_until: str
776
+ delivery_count: int
777
+ """1 on the first delivery; higher means a redelivery (a lease ran out or was nacked)."""
778
+ message: Message
779
+
780
+
781
+ class LeaseClaim(TypedDict):
782
+ """``messages.claim()``. ``paused`` is true while the inbox is paused (nothing is claimable)."""
783
+
784
+ data: list[Lease]
785
+ paused: bool
786
+
787
+
788
+ class AckResult(TypedDict, total=False):
789
+ """``messages.ack()``: ``acked_at``, or ``gone: True`` when the message was deleted meanwhile."""
790
+
791
+ id: str
792
+ acked_at: str
793
+ gone: bool
794
+
795
+
796
+ class NackResult(TypedDict, total=False):
797
+ """``messages.nack()``. ``dead_letter`` is true when this was the last allowed delivery."""
798
+
799
+ id: str
800
+ delivery_count: int
801
+ available_at: str
802
+ dead_letter: bool
803
+ gone: bool
804
+
805
+
806
+ class ExtendResult(TypedDict, total=False):
807
+ id: str
808
+ lease_id: str
809
+ lease_until: str
810
+ gone: bool
811
+
812
+
813
+ class SearchResult(Message):
814
+ rank: float
815
+ snippet: str
816
+
817
+
818
+ class _ThreadBase(TypedDict):
819
+ id: str
820
+ inbox_id: str
821
+ subject: Optional[str]
822
+ participants: list[str]
823
+ message_count: int
824
+ last_message_at: str
825
+ created_at: str
826
+
827
+
828
+ class Thread(_ThreadBase, total=False):
829
+ labels: list[str]
830
+ metadata: Metadata
831
+
832
+
833
+ class ThreadWithMessages(Thread):
834
+ messages: list[Message]
835
+
836
+
837
+ class DeletedThread(TypedDict):
838
+ """``threads.delete``: what was removed."""
839
+
840
+ deleted: bool
841
+ messages: int
842
+ attachments: int
843
+
844
+
845
+ class BatchMessages(TypedDict):
846
+ """``messages.batch_get`` / ``batch_update``: the messages, and ids you can't see."""
847
+
848
+ data: list[Message]
849
+ missing: list[str]
850
+
851
+
852
+ ContactKind = Literal["person", "automated", "sales", "unknown"]
853
+ """Who is behind a contact. ``unknown`` until the AI category of their mail sorts it (sales and
854
+ newsletters -> ``sales``, notifications and verification codes -> ``automated``, the rest -> ``person``);
855
+ writing to an address makes it a ``person``."""
856
+
857
+
858
+ class _ContactBase(TypedDict):
859
+ id: str
860
+ address: str
861
+ name: Optional[str]
862
+ notes: Optional[str]
863
+ metadata: Metadata
864
+ labels: list[str]
865
+ message_count: int
866
+ """Messages involving the address (from it, or to/cc/bcc it)."""
867
+ first_seen_at: str
868
+ last_seen_at: str
869
+ created_at: str
870
+
871
+
872
+ class Contact(_ContactBase, total=False):
873
+ """An external address the workspace has exchanged mail with (created automatically; automated
874
+ senders never are). The keys below are always present on current servers."""
875
+
876
+ kind: ContactKind
877
+ kind_source: Literal["auto", "manual"]
878
+ """``manual`` once set with ``update(kind=...)``: later mail never changes it."""
879
+ name_source: Literal["auto", "manual"]
880
+ """``manual`` once set with ``update(name=...)``: mail never replaces it."""
881
+ domain: str
882
+ """The part of the address after the @."""
883
+ last_subject: Optional[str]
884
+ """Subject of the newest message with this contact, without Re:/Fwd:."""
885
+
886
+
887
+ class ContactDomain(TypedDict):
888
+ """``contacts.domains``: contacts per domain (free-mail providers left out)."""
889
+
890
+ domain: str
891
+ contacts: int
892
+ last_seen_at: Optional[str]
893
+
894
+
895
+ class ContactDomainList(TypedDict):
896
+ data: list[ContactDomain]
897
+
898
+
899
+ class ContactBulkDeleteResult(TypedDict):
900
+ """``contacts.delete_many``: ``matched`` (dry run: would be deleted), ``deleted``, ``forgotten``, and
901
+ ``has_more`` when more than 1,000 matched (call again)."""
902
+
903
+ matched: int
904
+ deleted: int
905
+ forgotten: int
906
+ has_more: bool
907
+ dry_run: bool
908
+
909
+
910
+ class ContactWithThreads(Contact):
911
+ recent_threads: list[Thread]
912
+ """Up to 10 newest threads (all inboxes) with this address."""
913
+
914
+
915
+ class KnowledgeDoc(TypedDict):
916
+ """Reference text for reply drafts. ``inbox_id`` None = every inbox of the workspace."""
917
+
918
+ id: str
919
+ inbox_id: Optional[str]
920
+ title: str
921
+ body: str
922
+ created_at: str
923
+ updated_at: str
924
+
925
+
926
+ class KnowledgeListItem(TypedDict):
927
+ id: str
928
+ inbox_id: Optional[str]
929
+ title: str
930
+ excerpt: str
931
+ """First 200 characters of the body (lists never include the body)."""
932
+ created_at: str
933
+ updated_at: str
934
+
935
+
936
+ class KnowledgeSearchResult(TypedDict):
937
+ id: str
938
+ title: str
939
+ inbox_id: Optional[str]
940
+ rank: float
941
+ snippet: str
942
+
943
+
944
+ class KnowledgeSearchResults(TypedDict):
945
+ data: list[KnowledgeSearchResult]
946
+
947
+
948
+ class DraftCitation(TypedDict):
949
+ knowledge_id: str
950
+ title: str
951
+
952
+
953
+ DraftStatus = Literal["draft", "scheduled", "sending", "sent", "failed", "cancelled"]
954
+ """``draft`` → ``scheduled`` → ``sending`` → ``sent`` | ``failed`` | ``cancelled``."""
955
+
956
+
957
+ class DraftAttachment(TypedDict):
958
+ id: str
959
+ filename: str
960
+ content_type: str
961
+ size_bytes: int
962
+ sha256: str
963
+
964
+
965
+ class DraftError(TypedDict):
966
+ """Why the last send attempt was refused (API error code and message)."""
967
+
968
+ code: str
969
+ message: str
970
+
971
+
972
+ class DraftApprover(TypedDict):
973
+ """Who approved a draft's send: a person (``label`` = email), an API key (its name) or a connector."""
974
+
975
+ type: Literal["user", "api_key", "connector"]
976
+ id: str
977
+ label: str
978
+
979
+
980
+ class MessageApproval(TypedDict):
981
+ """An outbound message's approval, copied from its draft at send time."""
982
+
983
+ draft_id: str
984
+ by: DraftApprover
985
+ at: str
986
+ content_sha256: str
987
+
988
+
989
+ class _DraftExtras(TypedDict, total=False):
990
+ type: MessageType
991
+ """Agent messaging: sent as the message's type and data."""
992
+ data: Any
993
+
994
+
995
+ class Draft(_DraftExtras):
996
+ """A message waiting for review, approval or its ``send_at``.
997
+
998
+ Once sent, ``text``/``html``/``attachments`` are cleared: read the message ``sent_message_id``.
999
+ """
1000
+
1001
+ id: str
1002
+ inbox_id: str
1003
+ status: DraftStatus
1004
+ reply_to_message_id: Optional[str]
1005
+ thread_id: Optional[str]
1006
+ reply_all: bool
1007
+ to: list[str]
1008
+ cc: list[str]
1009
+ bcc: list[str]
1010
+ subject: Optional[str]
1011
+ text: Optional[str]
1012
+ html: Optional[str]
1013
+ attachments: list[DraftAttachment]
1014
+ metadata: Metadata
1015
+ labels: list[str]
1016
+ source: Literal["api", "ai"]
1017
+ """``ai`` when saved by ``messages.draft_reply(..., save=True)``."""
1018
+ send_at: Optional[str]
1019
+ sent_at: Optional[str]
1020
+ sent_message_id: Optional[str]
1021
+ approved_by: Optional[DraftApprover]
1022
+ """Who sent it, scheduled it, or last changed what it sends while scheduled; ``None`` until then."""
1023
+ approved_at: Optional[str]
1024
+ approved_content_sha256: Optional[str]
1025
+ """SHA-256 of the content the approval covers; a change to what a scheduled draft sends unschedules it."""
1026
+ error: Optional[DraftError]
1027
+ created_at: str
1028
+ updated_at: str
1029
+
1030
+
1031
+ class DraftSendResult(TypedDict):
1032
+ """``drafts.send``: the draft (now ``sent``) and the queued message."""
1033
+
1034
+ draft: Draft
1035
+ message: "Message"
1036
+
1037
+
1038
+ class DraftKeep(TypedDict):
1039
+ """In ``drafts.update(attachments=...)``: keep an attachment already on the draft."""
1040
+
1041
+ id: str
1042
+
1043
+
1044
+ class _DraftReplyBase(TypedDict):
1045
+ text: str
1046
+ citations: list[DraftCitation]
1047
+ model: str
1048
+
1049
+
1050
+ class DraftReply(_DraftReplyBase, total=False):
1051
+ """A reply draft. Nothing is sent: review it, then call ``messages.reply``.
1052
+
1053
+ With ``save=True`` it also carries ``draft``: the stored Draft, to send with ``drafts.send``."""
1054
+
1055
+ draft: Draft
1056
+
1057
+
1058
+ # Generic TypedDicts are only supported at runtime from Python 3.11; type checkers always see
1059
+ # the generic form, older interpreters get an equivalent plain-dict class.
1060
+ if TYPE_CHECKING or sys.version_info >= (3, 11):
1061
+
1062
+ class Page(TypedDict, Generic[_T]):
1063
+ """One page of a cursor-paginated list. Pass ``next_cursor`` as ``cursor`` to continue."""
1064
+
1065
+ data: list[_T]
1066
+ next_cursor: Optional[str]
1067
+
1068
+ else: # pragma: no cover - exercised on Python < 3.11 only
1069
+
1070
+ class Page(dict[str, Any], Generic[_T]):
1071
+ """One page of a cursor-paginated list. Pass ``next_cursor`` as ``cursor`` to continue."""
1072
+
1073
+
1074
+ class _WebhookRequired(TypedDict):
1075
+ id: str
1076
+ url: str
1077
+ events: list[WebhookEventType]
1078
+ inbox_ids: Optional[list[str]]
1079
+ enabled: bool
1080
+ created_at: str
1081
+
1082
+
1083
+ class WebhookStats(TypedDict):
1084
+ """Delivery stats over the last 24 hours."""
1085
+
1086
+ deliveries_24h: int
1087
+ failed_24h: int
1088
+ error_rate_24h: float
1089
+ last_success_at: Optional[str]
1090
+ last_failure_at: Optional[str]
1091
+
1092
+
1093
+ class Webhook(_WebhookRequired, total=False):
1094
+ secret: str
1095
+ """Only returned by ``webhooks.create``."""
1096
+ secret_hint: str
1097
+ payload: WebhookPayload
1098
+ stats: WebhookStats
1099
+
1100
+
1101
+ _EnvelopeEventDataBase = TypedDict(
1102
+ "_EnvelopeEventDataBase",
1103
+ {
1104
+ "inbox_id": Optional[str],
1105
+ "thread_id": Optional[str],
1106
+ "message_id": Optional[str],
1107
+ "from": Optional[str],
1108
+ "to": list[str],
1109
+ "subject": Optional[str],
1110
+ "labels": list[str],
1111
+ "received_at": Optional[str],
1112
+ },
1113
+ )
1114
+
1115
+
1116
+ class EnvelopeEventData(_EnvelopeEventDataBase, total=False):
1117
+ """``data`` of an event sent to a webhook with ``payload="envelope"`` (no bodies, no AI content)."""
1118
+
1119
+ channel: MessageChannel
1120
+ """Agent messaging (never the data itself)."""
1121
+ type: MessageType
1122
+
1123
+
1124
+ class WebhookCatalogEntry(TypedDict):
1125
+ """One entry of ``GET /v1/webhooks/events``."""
1126
+
1127
+ type: Union[WebhookEventType, Literal["webhook.test"]]
1128
+ description: str
1129
+ example: dict[str, Any]
1130
+ envelope_example: dict[str, Any]
1131
+
1132
+
1133
+ class ListEntry(TypedDict):
1134
+ """An allow/block list entry. ``inbox_id`` None = the whole workspace."""
1135
+
1136
+ id: str
1137
+ inbox_id: Optional[str]
1138
+ direction: ListDirection
1139
+ kind: ListKind
1140
+ pattern: str
1141
+ """``a@b.com`` (exact address) or ``b.com`` (the domain and its subdomains)."""
1142
+ type: Literal["address", "domain", "token"]
1143
+ """``token``: a receive-list token (``agents:any``, ``agents:verified``, ``workspace:self``)."""
1144
+ created_at: str
1145
+
1146
+
1147
+ class ListEntries(TypedDict):
1148
+ data: list[ListEntry]
1149
+
1150
+
1151
+ class MetricCounts(TypedDict):
1152
+ sent: int
1153
+ received: int
1154
+ delivered: int
1155
+ bounced: int
1156
+ complained: int
1157
+ blocked: int
1158
+
1159
+
1160
+ class MetricsPoint(MetricCounts):
1161
+ t: str
1162
+ """Start of the bucket (ISO 8601, UTC)."""
1163
+
1164
+
1165
+ class BounceReason(TypedDict):
1166
+ status: str
1167
+ count: int
1168
+
1169
+
1170
+ class Deliverability(TypedDict):
1171
+ delivered_rate: float
1172
+ bounce_rate: float
1173
+ complaint_rate: float
1174
+ bounce_reasons: list[BounceReason]
1175
+
1176
+
1177
+ class InboundQuality(TypedDict):
1178
+ spam: int
1179
+ blocked: int
1180
+ unauthenticated: int
1181
+
1182
+
1183
+ class HeatmapDay(TypedDict):
1184
+ date: str
1185
+ sent: int
1186
+ received: int
1187
+
1188
+
1189
+ class BusiestDay(TypedDict):
1190
+ date: str
1191
+ count: int
1192
+
1193
+
1194
+ class Streak(TypedDict):
1195
+ longest_days: int
1196
+ busiest_day: Optional[BusiestDay]
1197
+
1198
+
1199
+ class DeliverabilityWindow(TypedDict):
1200
+ sent: int
1201
+ bounced: int
1202
+ complained: int
1203
+ bounce_rate: float
1204
+ complaint_rate: float
1205
+
1206
+
1207
+ class DeliverabilityRates(TypedDict):
1208
+ last_7_days: DeliverabilityWindow
1209
+ last_30_days: DeliverabilityWindow
1210
+
1211
+
1212
+ class DeliverabilityThresholds(TypedDict):
1213
+ bounce_rate: float
1214
+ complaint_rate: float
1215
+ min_sent: int
1216
+
1217
+
1218
+ class DomainAuth(TypedDict):
1219
+ id: str
1220
+ domain: str
1221
+ status: DomainStatus
1222
+ spf: Literal["ok", "missing", "mismatch"]
1223
+ dkim: Literal["ok", "missing", "mismatch"]
1224
+ dmarc: Literal["ok", "missing", "mismatch"]
1225
+ dkim_rotation_due: bool
1226
+
1227
+
1228
+ class _BlocklistEntryBase(TypedDict):
1229
+ name: str
1230
+ status: Literal["clean", "listed", "unknown", "skipped"]
1231
+
1232
+
1233
+ class BlocklistEntry(_BlocklistEntryBase, total=False):
1234
+ codes: list[str]
1235
+ """Return codes when listed (e.g. ``127.0.0.2``)."""
1236
+
1237
+
1238
+ class IpReputation(TypedDict):
1239
+ status: Literal["clean", "listed", "partial", "unknown", "stale", "not_checked"]
1240
+ checked_at: Optional[str]
1241
+ lists: list[BlocklistEntry]
1242
+
1243
+
1244
+ class SharedSending(TypedDict):
1245
+ sending_domain: str
1246
+ ip_reputation: IpReputation
1247
+
1248
+
1249
+ class DeliverabilitySummary(TypedDict):
1250
+ """``deliverability()``: what affects whether your mail reaches the inbox."""
1251
+
1252
+ rates: DeliverabilityRates
1253
+ thresholds: DeliverabilityThresholds
1254
+ """Sending is suspended above these rates over 7 days (with at least ``min_sent`` sends)."""
1255
+ suppressed_contacts: int
1256
+ """Your contacts whose address is suppressed (hard bounce or complaint)."""
1257
+ domains: list[DomainAuth]
1258
+ shared: SharedSending
1259
+
1260
+
1261
+ class Resources(TypedDict):
1262
+ inboxes: int
1263
+ domains: int
1264
+ threads: int
1265
+ messages: int
1266
+ storage_bytes: int
1267
+
1268
+
1269
+ class QueueMetrics(TypedDict):
1270
+ """Claim/ack queue state of one inbox that has used it (``Metrics["queue"]``)."""
1271
+
1272
+ inbox_id: str
1273
+ address: str
1274
+ started_at: str
1275
+ depth: int
1276
+ in_flight: int
1277
+ dead_letters: int
1278
+ oldest_waiting_at: Optional[str]
1279
+
1280
+
1281
+ Metrics = TypedDict(
1282
+ "Metrics",
1283
+ {
1284
+ "from": str,
1285
+ "to": str,
1286
+ "tz": str,
1287
+ "bucket": MetricsBucket,
1288
+ "inbox_id": Optional[str],
1289
+ "series": list[MetricsPoint],
1290
+ "totals": MetricCounts,
1291
+ "deliverability": Deliverability,
1292
+ "inbound": InboundQuality,
1293
+ "heatmap": list[HeatmapDay],
1294
+ "streak": Streak,
1295
+ "resources": Resources,
1296
+ "queue": list[QueueMetrics],
1297
+ },
1298
+ )
1299
+ """``GET /v1/metrics``: counts bucketed in ``tz``, a 30-day heatmap and resource totals."""
1300
+
1301
+
1302
+ class WebhookTestResult(TypedDict):
1303
+ event_id: str
1304
+ delivery_id: str
1305
+
1306
+
1307
+ class _MessageEventDataRequired(TypedDict):
1308
+ inbox: Inbox
1309
+ thread_id: str
1310
+ message: Message
1311
+
1312
+
1313
+ class MessageEventData(_MessageEventDataRequired, total=False):
1314
+ bounce: Any
1315
+ complaint: Any
1316
+
1317
+
1318
+ class StreamEvent(TypedDict):
1319
+ """One event from :meth:`AsyncAgentboxd.stream`: exactly a webhook body. ``data`` is a
1320
+ :class:`MessageEventData` (``payload="full"``), an :class:`EnvelopeEventData` (``payload="envelope"``)
1321
+ or ``{"inbox": ...}`` for ``inbox.expired``."""
1322
+
1323
+ id: str
1324
+ type: str
1325
+ created_at: str
1326
+ data: Any
1327
+
1328
+
1329
+ class StreamToken(TypedDict):
1330
+ """``POST /v1/stream/token``: a single-use, 60-second URL for ``GET /v1/stream``."""
1331
+
1332
+ token: str
1333
+ expires_at: str
1334
+ url: str
1335
+
1336
+
1337
+ class WebhookEvent(TypedDict):
1338
+ """Body of every webhook POST."""
1339
+
1340
+ id: str
1341
+ type: Union[WebhookEventType, Literal["webhook.test"]]
1342
+ created_at: str
1343
+ data: MessageEventData
1344
+
1345
+
1346
+ # ---------- agent identity (Sign in with Agentboxd) ----------
1347
+
1348
+ IdentityScope = Literal["openid", "email", "profile", "workspace"]
1349
+ IdentityClientType = Literal["confidential", "public", "verify_only"]
1350
+ """``confidential``: has a client secret · ``public``: no secret, PKCE · ``verify_only``: only receives
1351
+ headless identity tokens and verifies them against the JWKS."""
1352
+ IdentitySubjectType = Literal["pairwise", "public"]
1353
+ IdentityFlow = Literal["headless", "authorization_code", "jwt_bearer"]
1354
+
1355
+
1356
+ class IdentityClient(TypedDict):
1357
+ """An app ("relying party") registered by the workspace. ``client_id`` is public (the tokens' ``aud``)."""
1358
+
1359
+ id: str
1360
+ client_id: str
1361
+ name: str
1362
+ type: IdentityClientType
1363
+ redirect_uris: list[str]
1364
+ allowed_scopes: list[IdentityScope]
1365
+ subject_type: IdentitySubjectType
1366
+ homepage_url: Optional[str]
1367
+ secret_prefix: Optional[str]
1368
+ enabled: bool
1369
+ last_used_at: Optional[str]
1370
+ created_at: str
1371
+ updated_at: str
1372
+
1373
+
1374
+ class _IdentityClientWithSecretBase(TypedDict):
1375
+ client: IdentityClient
1376
+
1377
+
1378
+ class IdentityClientWithSecret(_IdentityClientWithSecretBase, total=False):
1379
+ """Create and secret rotation. ``client_secret`` is only returned here, once (confidential clients)."""
1380
+
1381
+ client_secret: Optional[str]
1382
+
1383
+
1384
+ class IdentityToken(TypedDict):
1385
+ """A short-lived (at most 5 minutes), single-use OpenID Connect ID token for one relying party."""
1386
+
1387
+ id_token: str
1388
+ token_type: Literal["id_token"]
1389
+ issuer: str
1390
+ audience: str
1391
+ sub: str
1392
+ jti: str
1393
+ scope: str
1394
+ expires_in: int
1395
+ expires_at: str
1396
+
1397
+
1398
+ class InboxIdentityApp(TypedDict):
1399
+ client_id: str
1400
+ name: str
1401
+ homepage_url: Optional[str]
1402
+ last_signed_in_at: str
1403
+ sign_ins: int
1404
+
1405
+
1406
+ class _InboxIdentityBase(TypedDict):
1407
+ inbox_id: str
1408
+ enabled: bool
1409
+ apps: list[InboxIdentityApp]
1410
+
1411
+
1412
+ class InboxIdentity(_InboxIdentityBase, total=False):
1413
+ """The inbox's "Sign in with Agentboxd" switch and the apps it signed into."""
1414
+
1415
+ kind: Literal["mailbox", "identity"]
1416
+ """``identity`` for an identity-only agent."""
1417
+
1418
+
1419
+ class Identity(TypedDict):
1420
+ """An identity-only agent: an Agentboxd identity (sign in to apps) without a mailbox.
1421
+
1422
+ ``address`` is a stable handle on the agent domain; nothing is delivered to it and tokens never carry
1423
+ it as ``email``."""
1424
+
1425
+ id: str
1426
+ kind: Literal["identity"]
1427
+ address: str
1428
+ username: str
1429
+ display_name: Optional[str]
1430
+ client_id: Optional[str]
1431
+ metadata: Metadata
1432
+ identity_enabled: bool
1433
+ status: Literal["active", "paused"]
1434
+ paused_at: Optional[str]
1435
+ paused_reason: Optional[str]
1436
+ created_at: str
1437
+
1438
+
1439
+ class IdentitySignIn(TypedDict):
1440
+ id: str
1441
+ inbox_id: str
1442
+ client_id: str
1443
+ client_name: str
1444
+ event: Literal["token_issued", "signed_in"]
1445
+ flow: IdentityFlow
1446
+ jti: str
1447
+ ip: Optional[str]
1448
+ created_at: str
1449
+
1450
+
1451
+ # ---------- agent self-signup ----------
1452
+
1453
+
1454
+ class SignupChallenge(TypedDict):
1455
+ """``GET /v1/signup/challenge``.
1456
+
1457
+ Find a decimal ``solution`` such that SHA-256(challenge + ":" + solution) starts with ``difficulty``
1458
+ zero bits (:func:`agentboxd.solve_signup_challenge`)."""
1459
+
1460
+ challenge: str
1461
+ algorithm: Literal["sha256"]
1462
+ difficulty: int
1463
+ expires_at: str
1464
+ instructions: str
1465
+ terms: str
1466
+ terms_url: str
1467
+
1468
+
1469
+ class SignupWorkspace(TypedDict):
1470
+ """An agent-created workspace: ``unclaimed`` until a human claims it."""
1471
+
1472
+ id: str
1473
+ name: str
1474
+ status: Literal["unclaimed", "claimed"]
1475
+ created_at: str
1476
+ claimed_at: Optional[str]
1477
+
1478
+
1479
+ class UnclaimedRestrictions(TypedDict, total=False):
1480
+ """What an unclaimed workspace may do."""
1481
+
1482
+ recipients_per_day: int
1483
+ """Distinct recipients per UTC day (429 ``unclaimed_recipient_limit`` past it)."""
1484
+ replies_to_inbound_threads: Literal["unlimited"]
1485
+ inboxes: int
1486
+ identities: int
1487
+ identity_tokens: bool
1488
+ """``False`` until a human claims the workspace (identity tokens are refused)."""
1489
+ webhooks: bool
1490
+ custom_domains: bool
1491
+ event_stream: bool
1492
+ expires_after_inactive_days: int
1493
+ recipients_today: int
1494
+ """``GET /v1/account`` only."""
1495
+
1496
+
1497
+ class SignupClaim(TypedDict):
1498
+ status: Literal["email_sent", "not_requested", "email_failed"]
1499
+ email: Optional[str]
1500
+ """Masked, e.g. ``o***@example.com``."""
1501
+
1502
+
1503
+ class _SignupResultBase(TypedDict):
1504
+ api_key: str
1505
+ workspace: SignupWorkspace
1506
+ inbox: Inbox
1507
+ """``None`` for ``kind="identity"`` signups (see ``identity``)."""
1508
+ claim: SignupClaim
1509
+ restrictions: UnclaimedRestrictions
1510
+ docs_url: str
1511
+ next_steps: list[str]
1512
+
1513
+
1514
+ class SignupResult(_SignupResultBase, total=False):
1515
+ """``POST /v1/signup`` (201). ``api_key`` is shown only here."""
1516
+
1517
+ kind: Literal["mailbox", "identity"]
1518
+ identity: Optional[Identity]
1519
+ """The identity-only agent of a ``kind="identity"`` signup, else ``None``."""
1520
+
1521
+
1522
+ class AccountClaim(TypedDict):
1523
+ status: Literal["unclaimed", "claimed", "not_applicable"]
1524
+ """``not_applicable``: the workspace was created by a person, not by an agent."""
1525
+ claimed_at: Optional[str]
1526
+ pending_email: Optional[str]
1527
+ expires_at: Optional[str]
1528
+ """Unclaimed only: when the workspace is deleted if nothing happens before."""
1529
+
1530
+
1531
+ class _AgentMessagingBase(TypedDict):
1532
+ enabled: bool
1533
+ directory_enabled: bool
1534
+
1535
+
1536
+ class AgentMessaging(_AgentMessagingBase, total=False):
1537
+ """Launch switches of agent messaging and the directory."""
1538
+
1539
+ agent_keys_enabled: bool
1540
+ """aSIM phase 2: agents may register their own signing keys and send author-signed messages."""
1541
+ public_directory_enabled: bool
1542
+ """aSIM phase 2: public cards, handles and the public directory."""
1543
+
1544
+
1545
+ class _AccountExtras(TypedDict, total=False):
1546
+ agent_messaging: AgentMessaging
1547
+ """Absent on servers before agent messaging."""
1548
+
1549
+
1550
+ class Account(_AccountExtras):
1551
+ """``GET /v1/account``: the workspace behind the key, its claim status and effective limits."""
1552
+
1553
+ workspace: dict[str, Any]
1554
+ claim: AccountClaim
1555
+ limits: dict[str, Optional[int]]
1556
+ restrictions: Optional[UnclaimedRestrictions]
1557
+
1558
+
1559
+ # ``draft_created``: a draft is waiting for a person to approve it (off by default).
1560
+ EscalationTrigger = Literal[
1561
+ "needs_human", "phishing", "blocked", "draft_failed", "emergency_stop", "held", "draft_created"
1562
+ ]
1563
+
1564
+
1565
+ class EscalationContact(TypedDict):
1566
+ """An on-call contact: ``pending`` until the confirmation link is clicked (only confirmed get alerts)."""
1567
+
1568
+ email: str
1569
+ status: Literal["pending", "confirmed"]
1570
+ confirmed_at: Optional[str]
1571
+
1572
+
1573
+ class QuietHours(TypedDict):
1574
+ """``HH:MM`` start and end (24-hour, may wrap midnight) in an IANA ``timezone``."""
1575
+
1576
+ start: str
1577
+ end: str
1578
+ timezone: str
1579
+
1580
+
1581
+ class EscalationSettings(TypedDict):
1582
+ """``GET/PUT /v1/escalation``: who is alerted, for what, and how (human on call)."""
1583
+
1584
+ contacts: list[EscalationContact]
1585
+ triggers: dict[str, bool]
1586
+ delivery: Literal["immediate", "digest"]
1587
+ max_per_hour: int
1588
+ quiet_hours: Optional[QuietHours]
1589
+ include_excerpt: bool
1590
+
1591
+
1592
+ class InboxEscalation(TypedDict):
1593
+ """``GET/PUT /v1/inboxes/{id}/escalation``: the inbox's own contacts (and triggers) when ``override``."""
1594
+
1595
+ override: bool
1596
+ contacts: list[EscalationContact]
1597
+ triggers: Optional[dict[str, bool]]
1598
+
1599
+
1600
+ # ---------- agent cards and the directory (aSIM) ----------
1601
+
1602
+ AgentCardVisibility = Literal["private", "workspace", "public"]
1603
+ AgentCardStatus = Literal["active", "revoked", "suspended"]
1604
+ AgentStatus = Literal["active", "revoked", "suspended", "deleted"]
1605
+ DirectoryReportReason = Literal["spam", "impersonation", "malicious", "illegal", "other"]
1606
+
1607
+
1608
+ class AgentCardSkill(TypedDict):
1609
+ id: str
1610
+ name: str
1611
+ description: str
1612
+ tags: list[str]
1613
+ oasf: Optional[str]
1614
+
1615
+
1616
+ class _AgentCardBase(TypedDict):
1617
+ format_version: str
1618
+ address: str
1619
+ name: str
1620
+ description: str
1621
+ status: AgentCardStatus
1622
+ assurance: AgentAssurance
1623
+ badges: list[str]
1624
+ visibility: AgentCardVisibility
1625
+ channels: dict[str, Any]
1626
+ routing: Literal["relay", "direct_preferred"]
1627
+ accepts: dict[str, list[str]]
1628
+ skills: list[AgentCardSkill]
1629
+ documentation_url: Optional[str]
1630
+ keys: dict[str, Any]
1631
+ minimal: Literal[False]
1632
+ updated_at: str
1633
+
1634
+
1635
+ class AgentCardListing(TypedDict):
1636
+ """The public listing of a card (owner view): ``pending`` (listing check) → ``listed`` or ``hidden``."""
1637
+
1638
+ state: Literal["pending", "listed", "hidden"]
1639
+ reason: Optional[str]
1640
+ """Why it is hidden: ``listing_check``, ``reports`` or ``operator…``."""
1641
+ listed_at: Optional[str]
1642
+
1643
+
1644
+ class AgentKeyJwk(TypedDict, total=False):
1645
+ """An agent-held public key as cards publish it (a JWK with its lifecycle)."""
1646
+
1647
+ kty: str
1648
+ crv: str
1649
+ x: str
1650
+ y: str
1651
+ kid: str
1652
+ alg: str
1653
+ use: str
1654
+ status: Literal["active", "retired", "revoked"]
1655
+ created_at: str
1656
+ retired_at: Optional[str]
1657
+ revoked_at: Optional[str]
1658
+
1659
+
1660
+ class PublicCardUrls(TypedDict):
1661
+ page: str
1662
+ a2a: str
1663
+ oasf: str
1664
+ keys: str
1665
+
1666
+
1667
+ class AgentCard(_AgentCardBase, total=False):
1668
+ """A card as the agent's own workspace sees it (bundle, search, events)."""
1669
+
1670
+ revoked_at: Optional[str]
1671
+ handle: Optional[str]
1672
+ """aSIM phase 2: ``@workspace/agent``, or None."""
1673
+ domain: Optional[str]
1674
+ """The verified custom domain behind the ``domain_verified`` badge, or None."""
1675
+ listing: Optional[AgentCardListing]
1676
+ """Public cards only (owner view)."""
1677
+ indexable: bool
1678
+ """The public page may be indexed by search engines and is in the sitemap."""
1679
+
1680
+
1681
+ class PublicAgentCard(_AgentCardBase, total=False):
1682
+ """A publicly listed card (everyone sees it): no listing state, plus the public URLs."""
1683
+
1684
+ revoked_at: Optional[str]
1685
+ handle: Optional[str]
1686
+ domain: Optional[str]
1687
+ indexable: bool
1688
+ """The owner allows search engines to index the card's public page."""
1689
+ urls: PublicCardUrls
1690
+
1691
+
1692
+ class _MinimalAgentCardBase(TypedDict):
1693
+ format_version: str
1694
+ address: str
1695
+ name: str
1696
+ status: AgentCardStatus
1697
+ assurance: AgentAssurance
1698
+ accepts: dict[str, list[str]]
1699
+ keys: dict[str, Any]
1700
+ minimal: Literal[True]
1701
+
1702
+
1703
+ class MinimalAgentCard(_MinimalAgentCardBase, total=False):
1704
+ """What another workspace sees on resolve: what a signed message already reveals, plus the name."""
1705
+
1706
+ revoked_at: Optional[str]
1707
+ badges: list[str]
1708
+
1709
+
1710
+ class _AgentKeyBase(TypedDict):
1711
+ kid: str
1712
+ alg: Literal["EdDSA", "ES256"]
1713
+ status: Literal["active", "retired", "revoked"]
1714
+ public_jwk: dict[str, str]
1715
+ created_at: str
1716
+ retired_at: Optional[str]
1717
+ revoked_at: Optional[str]
1718
+ revocation_reason: Optional[str]
1719
+ last_used_at: Optional[str]
1720
+
1721
+
1722
+ class AgentKey(_AgentKeyBase):
1723
+ """An agent-held signing key (``/v1/inboxes/:id/agent/keys``): public key only."""
1724
+
1725
+
1726
+ class AgentKeyList(TypedDict):
1727
+ data: list[AgentKey]
1728
+
1729
+
1730
+ class WorkspaceHandle(TypedDict):
1731
+ """``/v1/directory/handle``: the workspace handle and the previous ones that still redirect."""
1732
+
1733
+ handle: Optional[str]
1734
+ previous: list[dict[str, str]]
1735
+
1736
+
1737
+ class PublicAgent(TypedDict):
1738
+ """``GET /v1/public/agents/{address}``."""
1739
+
1740
+ card: PublicAgentCard
1741
+
1742
+
1743
+ class _PublicHandleBase(TypedDict):
1744
+ handle: str
1745
+ address: str
1746
+ card: PublicAgentCard
1747
+
1748
+
1749
+ class PublicHandle(_PublicHandleBase, total=False):
1750
+ """``GET /v1/public/handles/{workspace}/{agent}``."""
1751
+
1752
+ redirected_from: str
1753
+
1754
+
1755
+ class PublicAgentKeys(TypedDict):
1756
+ keys: list[AgentKeyJwk]
1757
+
1758
+
1759
+ class AgentCardInput(TypedDict, total=False):
1760
+ """Create or edit a card (``agents.update``, or ``card=`` on ``inboxes.create`` / ``identities.create``).
1761
+
1762
+ New cards are ``private`` (resolvable by exact address, never listed); ``workspace`` lists it in your
1763
+ workspace. Card text can't contain HTML, links (use ``documentation_url``) or email addresses."""
1764
+
1765
+ name: str
1766
+ description: Optional[str]
1767
+ capabilities: dict[str, Any]
1768
+ """``skills`` (``id``, ``name``, optional ``description``, ``tags``, ``oasf``), ``accepts_types``,
1769
+ ``languages`` and ``input_modes``; replaces all capabilities when given."""
1770
+ documentation_url: Optional[str]
1771
+ visibility: AgentCardVisibility
1772
+ """``public`` needs the public directory, a claimed workspace and an org-scoped key (plan limit
1773
+ ``public_listings``)."""
1774
+ routing: Literal["relay", "direct_preferred"]
1775
+ handle: Optional[str]
1776
+ """The agent part of the handle (``billing`` in ``@acme/billing``); None clears it."""
1777
+ indexable: bool
1778
+
1779
+
1780
+ class _ResolvedAgentBase(TypedDict):
1781
+ card: Union[AgentCard, MinimalAgentCard, PublicAgentCard]
1782
+
1783
+
1784
+ class ResolvedAgent(_ResolvedAgentBase, total=False):
1785
+ """``GET /v1/directory/resolve``."""
1786
+
1787
+ redirected_from: str
1788
+ """Resolving a renamed handle: the handle asked for."""
1789
+
1790
+
1791
+ class _AgentBundleExtras(TypedDict, total=False):
1792
+ domain: Optional[str]
1793
+ handle: Optional[str]
1794
+
1795
+
1796
+ class AgentBundle(_AgentBundleExtras):
1797
+ """``GET /v1/inboxes/:id/agent``: everything that makes the inbox an agent."""
1798
+
1799
+ inbox: Inbox
1800
+ identity: dict[str, bool]
1801
+ card: Optional[AgentCard]
1802
+ keys: dict[str, Any]
1803
+ routing: Literal["relay", "direct_preferred"]
1804
+ visibility: AgentCardVisibility
1805
+ status: Literal["no_card", "active", "revoked", "suspended"]
1806
+ assurance: AgentAssurance
1807
+ badges: list[str]
1808
+
1809
+
1810
+ _DirectoryVerifyBase = TypedDict(
1811
+ "_DirectoryVerifyBase",
1812
+ {
1813
+ # The signature is ours and the sender is active now (for an address: the agent is active).
1814
+ "valid": bool,
1815
+ "status": Optional[AgentStatus],
1816
+ "from": Optional[str],
1817
+ "assurance": Optional[str],
1818
+ "kid": Optional[str],
1819
+ "signed_at": Optional[str],
1820
+ "card": bool,
1821
+ # e.g. bad_signature, unknown_key, key_revoked, agent_revoked, agent_suspended, agent_deleted
1822
+ "reasons": list[str],
1823
+ },
1824
+ )
1825
+
1826
+
1827
+ class DirectoryVerifyResult(_DirectoryVerifyBase, total=False):
1828
+ """``POST /v1/directory/verify``."""
1829
+
1830
+ signer: Optional[Literal["server", "agent"]]
1831
+ """``server`` (Agentboxd's delivery signature) or ``agent`` (an author signature); None for an address."""
1832
+ key_revoked_at: Optional[str]
1833
+ """Author signatures: when the agent key was revoked, or None. A signature whose own ``iat`` is
1834
+ earlier still verifies, but ``iat`` is the signer's claim. Recommended: refuse the signature when
1835
+ this isn't None, unless you have your own proof of when it was signed."""
1836
+
1837
+
1838
+ class DirectoryReportResult(TypedDict):
1839
+ received: Literal[True]
1840
+
1841
+
1842
+ class EmergencyStopResult(TypedDict):
1843
+ """``POST /v1/emergency-stop``: the workspace, now stopped."""
1844
+
1845
+ org: dict[str, Any]
1846
+
1847
+
1848
+ class AddAgentResult(TypedDict):
1849
+ """``POST /v1/signup/agents``: another agent in the same unclaimed workspace, with its own key."""
1850
+
1851
+ api_key: str
1852
+ kind: Literal["mailbox", "identity"]
1853
+ workspace: dict[str, Any]
1854
+ inbox: Optional[dict[str, Any]]
1855
+ identity: Optional[dict[str, Any]]
1856
+ next_steps: list[str]
1857
+
1858
+
1859
+ class ClaimRequestResult(TypedDict):
1860
+ """``POST /v1/signup/claim``."""
1861
+
1862
+ status: Literal["email_sent"]
1863
+ email: str
1864
+ expires_at: str