sessionyard 0.7.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.
- agent_chat/001_core.sql +172 -0
- agent_chat/002_coordination.sql +63 -0
- agent_chat/003_harness_admission.sql +10 -0
- agent_chat/004_session_titles.sql +3 -0
- agent_chat/005_viewer.sql +9 -0
- agent_chat/006_quotas.sql +6 -0
- agent_chat/007_sender_receipts.sql +20 -0
- agent_chat/008_direct_threads.sql +49 -0
- agent_chat/009_pm_mark.sql +23 -0
- agent_chat/010_quota_backfill.sql +12 -0
- agent_chat/011_roles_and_work.sql +31 -0
- agent_chat/__init__.py +1 -0
- agent_chat/adapter.py +414 -0
- agent_chat/admin.py +524 -0
- agent_chat/api.py +641 -0
- agent_chat/auth.py +226 -0
- agent_chat/browser.py +118 -0
- agent_chat/browser_verify.py +487 -0
- agent_chat/browser_verify_artifacts.py +280 -0
- agent_chat/browser_verify_checks.py +236 -0
- agent_chat/browser_verify_run.py +523 -0
- agent_chat/cli.py +532 -0
- agent_chat/client.py +272 -0
- agent_chat/deliveries.py +555 -0
- agent_chat/events.py +48 -0
- agent_chat/feed.py +193 -0
- agent_chat/http_boundary.py +154 -0
- agent_chat/instance_client.py +349 -0
- agent_chat/instance_file.py +207 -0
- agent_chat/instance_worker.py +326 -0
- agent_chat/mcp/__init__.py +5 -0
- agent_chat/mcp/__main__.py +39 -0
- agent_chat/mcp/app.py +183 -0
- agent_chat/mcp/auth.py +67 -0
- agent_chat/mcp/config.py +55 -0
- agent_chat/mcp/tools.py +295 -0
- agent_chat/metrics.py +60 -0
- agent_chat/models.py +430 -0
- agent_chat/openapi.py +322 -0
- agent_chat/producer.py +208 -0
- agent_chat/protocol.py +71 -0
- agent_chat/publication.py +252 -0
- agent_chat/receipts.py +225 -0
- agent_chat/retention.py +154 -0
- agent_chat/roles.py +153 -0
- agent_chat/rooms.py +179 -0
- agent_chat/sessions.py +340 -0
- agent_chat/skills/agent-chat/SKILL.md +64 -0
- agent_chat/state.py +144 -0
- agent_chat/storage.py +110 -0
- agent_chat/threads.py +50 -0
- agent_chat/web/Manrope-OFL.txt +93 -0
- agent_chat/web/Manrope-Variable.ttf +0 -0
- agent_chat/web/chat.css +936 -0
- agent_chat/web/chat.js +1922 -0
- agent_chat/web/i18n.js +340 -0
- agent_chat/web/index.html +264 -0
- sessionyard-0.7.0.dist-info/METADATA +314 -0
- sessionyard-0.7.0.dist-info/RECORD +62 -0
- sessionyard-0.7.0.dist-info/WHEEL +4 -0
- sessionyard-0.7.0.dist-info/entry_points.txt +3 -0
- sessionyard-0.7.0.dist-info/licenses/LICENSE +661 -0
agent_chat/models.py
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
"""Request models, limits and error codes shared by the server, the CLI and the storage boundary."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Any, Literal
|
|
7
|
+
from uuid import UUID
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
|
10
|
+
|
|
11
|
+
BIDI_CONTROLS = frozenset(map(chr, (*range(0x202A, 0x202F), *range(0x2066, 0x206A))))
|
|
12
|
+
|
|
13
|
+
# An instance is online while its last heartbeat is younger than this.
|
|
14
|
+
LEASE_SECONDS = 90
|
|
15
|
+
# The adapter core rejoins a lapsed instance only for these worker codes.
|
|
16
|
+
REJOIN_CODES = frozenset({"STALE_INSTANCE", "SERVICE_UNAVAILABLE", "TRANSPORT_UNAVAILABLE", "REQUEST_UNCERTAIN"})
|
|
17
|
+
REJOIN_BACKOFF_BASE_S = 5.0
|
|
18
|
+
REJOIN_BACKOFF_CAP_S = 120.0
|
|
19
|
+
REJOIN_JITTER_MIN = 0.5
|
|
20
|
+
# One episode may run this long, and a session may complete this many rejoins in the budget window.
|
|
21
|
+
REJOIN_EPISODE_S = 7200.0
|
|
22
|
+
REJOIN_PER_HOUR = 3
|
|
23
|
+
REJOIN_BUDGET_WINDOW_S = 3600.0
|
|
24
|
+
# Agent replies a thread accepts before an operator reply resets the count.
|
|
25
|
+
REPLY_LIMIT = 6
|
|
26
|
+
# Wake admissions per session in a rolling window; admissions are never refunded.
|
|
27
|
+
WAKE_LIMIT = 20
|
|
28
|
+
WAKE_WINDOW_SECONDS = 3600
|
|
29
|
+
# A direct 1:1 thread (exactly two sessions, created after 008_direct_threads.sql) has its own reply limit and its
|
|
30
|
+
# own wake allowance per session in the same window.
|
|
31
|
+
DIRECT_REPLY_LIMIT = 20
|
|
32
|
+
DIRECT_WAKE_LIMIT = 60
|
|
33
|
+
# Loop detector of a direct thread: this many consecutive agent replies within this many seconds refuse further
|
|
34
|
+
# replies and wakes in it until an operator reset.
|
|
35
|
+
LOOP_REPLIES = 10
|
|
36
|
+
LOOP_WINDOW_SECONDS = 120
|
|
37
|
+
# Wait after a failed or deferred attempt before attempt 2, then before attempt 3.
|
|
38
|
+
BACKOFF_SECONDS = (1, 5)
|
|
39
|
+
# An addressed item not handed within this time after it was stored is never offered again.
|
|
40
|
+
DELIVERY_MAX_AGE_SECONDS = 86400
|
|
41
|
+
# Volume caps that bound what one credential can create; hard refusals, never queued. The hourly windows roll.
|
|
42
|
+
QUOTA_WINDOW_SECONDS = 3600
|
|
43
|
+
MAX_LIVE_INSTANCES_PER_PRINCIPAL = 32
|
|
44
|
+
MAX_REGISTRATIONS_PER_PRINCIPAL_HOUR = 120
|
|
45
|
+
MAX_MESSAGES_PER_SESSION_HOUR = 120
|
|
46
|
+
# A room role mark lapses after this many hours without its holder's own publication or acknowledgement.
|
|
47
|
+
# roles.py applies it; no SQL file holds a copy.
|
|
48
|
+
ROLE_EXPIRY_HOURS = 48
|
|
49
|
+
# The closed role set. `pm` is the Forgejo PM mark and wire value, so existing messages, `--from pm` and
|
|
50
|
+
# the skills keep their meaning; the other two stamps are their own names.
|
|
51
|
+
ROLE_NAMES = ("pm", "github_pm", "delivery_manager")
|
|
52
|
+
# The names the CLI and the browser accept. `forgejo-pm`/`forgejo_pm` and `dm` are aliases.
|
|
53
|
+
# The history filter accepts this same table: every name resolves to its canonical role, which is
|
|
54
|
+
# also the wire stamp. One definition, so the parser and the filter cannot drift apart.
|
|
55
|
+
ROLE_SELECTORS = {
|
|
56
|
+
"pm": "pm",
|
|
57
|
+
"forgejo-pm": "pm",
|
|
58
|
+
"forgejo_pm": "pm",
|
|
59
|
+
"github-pm": "github_pm",
|
|
60
|
+
"github_pm": "github_pm",
|
|
61
|
+
"delivery-manager": "delivery_manager",
|
|
62
|
+
"delivery_manager": "delivery_manager",
|
|
63
|
+
"dm": "delivery_manager",
|
|
64
|
+
}
|
|
65
|
+
ROLE_FILTER_STAMPS = ROLE_SELECTORS
|
|
66
|
+
|
|
67
|
+
# Kinds that record coordination material. Delivery lists its kinds explicitly, so none of these is ever
|
|
68
|
+
# pending, claimed or woken; like `status`, they never count toward the reply cap.
|
|
69
|
+
COORDINATION_KINDS = ("heads_up", "blocked_on", "decision_needed", "intent")
|
|
70
|
+
# Kinds that never count toward, reset or are refused at a thread's reply limit.
|
|
71
|
+
UNCOUNTED_KINDS = ("status", *COORDINATION_KINDS)
|
|
72
|
+
# The only exact grammar of a thread key; the database checks a coarser shape (002_coordination.sql).
|
|
73
|
+
REF_KEY_PATTERN = (
|
|
74
|
+
r"^(pr:[A-Za-z0-9_.-]{1,40}/[A-Za-z0-9_.-]{1,80}#[1-9][0-9]{0,9}"
|
|
75
|
+
r"|lane:[A-Za-z0-9_./-]{1,80}::[A-Za-z0-9-]{1,40}"
|
|
76
|
+
r"|resource:[a-z0-9][a-z0-9-]{0,62}:[a-z0-9][a-z0-9-]{0,62})$"
|
|
77
|
+
)
|
|
78
|
+
# Deliberately looser than the gate's lane reference; the gate stays the only exact owner of that grammar.
|
|
79
|
+
LANE_PATTERN = r"^[A-Za-z0-9_./-]{1,80}::[A-Za-z0-9-]{1,40}$"
|
|
80
|
+
LANE_MAX_LENGTH = 120
|
|
81
|
+
# A work declaration names at most these many `owner/name` repositories, bounded by the stored JSON text too.
|
|
82
|
+
REPOSITORY_PATTERN = r"^[A-Za-z0-9_.-]{1,40}/[A-Za-z0-9_.-]{1,80}$"
|
|
83
|
+
MAX_REPOSITORIES_PER_FORGE = 16
|
|
84
|
+
MAX_REPOSITORIES = 32
|
|
85
|
+
WORK_BYTES = 4096
|
|
86
|
+
PR_REF = re.compile(r"^pr:(?P<repository>[A-Za-z0-9_.-]{1,40}/[A-Za-z0-9_.-]{1,80})#(?P<number>[1-9][0-9]{0,9})$")
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def pr_ref_parts(ref: str) -> tuple[str, int] | None:
|
|
90
|
+
"""The repository and number of a `pr:` ref, or None when the stored text does not parse."""
|
|
91
|
+
match = PR_REF.fullmatch(ref)
|
|
92
|
+
return None if match is None else (match["repository"], int(match["number"]))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
STATE_KEY_PATTERN = r"^[a-z0-9][a-z0-9-]{0,62}:[a-z0-9][a-z0-9-]{0,62}:[a-z0-9][a-z0-9.-]{0,62}$"
|
|
96
|
+
STATE_REF_KEY_PATTERN = r"^resource:[a-z0-9][a-z0-9-]{0,62}:[a-z0-9][a-z0-9-]{0,62}$"
|
|
97
|
+
STATE_VALUE_BYTES = 4096
|
|
98
|
+
STATE_BATCH = 8
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@dataclass(frozen=True)
|
|
102
|
+
class Actor:
|
|
103
|
+
# Internal authentication result, never constructed from publication JSON.
|
|
104
|
+
principal_id: UUID
|
|
105
|
+
session_id: UUID | None
|
|
106
|
+
instance_id: UUID | None
|
|
107
|
+
browser_session_hash: str | None = field(default=None, repr=False)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@dataclass(frozen=True)
|
|
111
|
+
class ProducerActor:
|
|
112
|
+
# A machine writer of room state. Deliberately not an Actor: it has no session, instance or browser binding,
|
|
113
|
+
# and no route that takes an Actor can be handed one.
|
|
114
|
+
principal_id: UUID
|
|
115
|
+
host: str
|
|
116
|
+
producer: str
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class Publication(BaseModel):
|
|
120
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
121
|
+
|
|
122
|
+
kind: Literal[
|
|
123
|
+
"message", "status", "question", "consultation", "reply", "heads_up", "blocked_on", "decision_needed", "intent"
|
|
124
|
+
]
|
|
125
|
+
body: str = Field(strict=True, min_length=1)
|
|
126
|
+
recipients: tuple[UUID, ...] = Field(default=(), max_length=16)
|
|
127
|
+
thread_id: UUID | None = None
|
|
128
|
+
reply_to: UUID | None = None
|
|
129
|
+
ref_key: str | None = Field(default=None, strict=True, pattern=REF_KEY_PATTERN)
|
|
130
|
+
# The sender's opt-in to receipts on an addressed message or reply; `receipts.eligible` decides what it means.
|
|
131
|
+
receipts: bool = Field(default=False, strict=True)
|
|
132
|
+
|
|
133
|
+
@field_validator("body")
|
|
134
|
+
@classmethod
|
|
135
|
+
def bounded_body(cls, body: str) -> str:
|
|
136
|
+
if "\x00" in body or len(body.encode("utf-8")) > 16384:
|
|
137
|
+
raise ValueError("body must be valid PostgreSQL text of at most 16 KiB")
|
|
138
|
+
return body
|
|
139
|
+
|
|
140
|
+
@field_validator("recipients")
|
|
141
|
+
@classmethod
|
|
142
|
+
def unique_recipients(cls, recipients: tuple[UUID, ...]) -> tuple[UUID, ...]:
|
|
143
|
+
return tuple(sorted(set(recipients)))
|
|
144
|
+
|
|
145
|
+
@model_validator(mode="after")
|
|
146
|
+
def reply_shape(self) -> "Publication":
|
|
147
|
+
if (self.kind == "reply") != (self.reply_to is not None):
|
|
148
|
+
raise ValueError("reply kind and reply_to must occur together")
|
|
149
|
+
if self.ref_key is not None:
|
|
150
|
+
# A keyed thread is long-lived: it opens only through a new post, and a question or consultation
|
|
151
|
+
# (wake-eligible, reply-capped) cannot open or join one.
|
|
152
|
+
if self.thread_id is not None or self.reply_to is not None:
|
|
153
|
+
raise ValueError("ref_key names a new or existing thread by itself")
|
|
154
|
+
if self.kind in ("question", "consultation"):
|
|
155
|
+
raise ValueError("a question or consultation cannot name a ref_key")
|
|
156
|
+
return self
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class Registration(BaseModel):
|
|
160
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
161
|
+
|
|
162
|
+
native_session_id: str = Field(strict=True, min_length=1, max_length=256, pattern=r"^[^\x00-\x1f\x7f]+$")
|
|
163
|
+
boot_id: UUID
|
|
164
|
+
instance_token_hash: str = Field(strict=True, pattern=r"^[0-9a-f]{64}$")
|
|
165
|
+
lane: str | None = Field(default=None, strict=True, pattern=LANE_PATTERN, max_length=LANE_MAX_LENGTH)
|
|
166
|
+
|
|
167
|
+
@field_validator("native_session_id")
|
|
168
|
+
@classmethod
|
|
169
|
+
def native_utf8(cls, value: str) -> str:
|
|
170
|
+
value.encode("utf-8")
|
|
171
|
+
# Bidirectional controls would let a stored label visually reorder the flags rendered beside it.
|
|
172
|
+
if BIDI_CONTROLS.intersection(value):
|
|
173
|
+
raise ValueError("native_session_id must not contain bidirectional controls")
|
|
174
|
+
return value
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class Heartbeat(BaseModel):
|
|
178
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
179
|
+
|
|
180
|
+
native_state: Literal["idle", "busy", "unknown"]
|
|
181
|
+
stopped: bool = Field(strict=True)
|
|
182
|
+
plan_mode: bool = Field(strict=True)
|
|
183
|
+
# Omission preserves the stored title: the normal path for harnesses without a native title owner (Claude,
|
|
184
|
+
# Codex). JSON null clears it.
|
|
185
|
+
title: str | None = Field(default=None, strict=True, min_length=1, max_length=128)
|
|
186
|
+
|
|
187
|
+
@field_validator("title")
|
|
188
|
+
@classmethod
|
|
189
|
+
def safe_title(cls, value: str | None) -> str | None:
|
|
190
|
+
if value is not None:
|
|
191
|
+
if (not value.strip() or value != value.strip() or len(value.encode("utf-8")) > 512
|
|
192
|
+
or any(ord(char) < 32 or 127 <= ord(char) < 160 for char in value)
|
|
193
|
+
or (BIDI_CONTROLS | frozenset("\u061c\u200e\u200f\u2028\u2029")).intersection(value)):
|
|
194
|
+
raise ValueError("invalid session title")
|
|
195
|
+
return value
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class LaneDeclaration(BaseModel):
|
|
199
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
200
|
+
|
|
201
|
+
# Required: null clears the lane, so an omitted field is not a silent clear.
|
|
202
|
+
lane: str | None = Field(strict=True, pattern=LANE_PATTERN, max_length=LANE_MAX_LENGTH)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class WorkDeclaration(BaseModel):
|
|
206
|
+
"""The live instance's advisory map from forge to repositories; `{}` clears it."""
|
|
207
|
+
|
|
208
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
209
|
+
|
|
210
|
+
# Required: an omitted map is not a silent clear.
|
|
211
|
+
repositories: dict[Literal["forgejo", "github"], tuple[str, ...]]
|
|
212
|
+
|
|
213
|
+
@field_validator("repositories")
|
|
214
|
+
@classmethod
|
|
215
|
+
def bounded(cls, value: dict[str, tuple[str, ...]]) -> dict[str, tuple[str, ...]]:
|
|
216
|
+
total = 0
|
|
217
|
+
bounded: dict[str, tuple[str, ...]] = {}
|
|
218
|
+
for forge, repositories in value.items():
|
|
219
|
+
if len(repositories) > MAX_REPOSITORIES_PER_FORGE:
|
|
220
|
+
raise ValueError(f"at most {MAX_REPOSITORIES_PER_FORGE} repositories per forge")
|
|
221
|
+
for repository in repositories:
|
|
222
|
+
if not re.fullmatch(REPOSITORY_PATTERN, repository):
|
|
223
|
+
raise ValueError("a repository must be owner/name")
|
|
224
|
+
total += len(repositories)
|
|
225
|
+
bounded[forge] = tuple(sorted(set(repositories)))
|
|
226
|
+
if total > MAX_REPOSITORIES:
|
|
227
|
+
raise ValueError(f"at most {MAX_REPOSITORIES} repositories")
|
|
228
|
+
rendered = json.dumps(bounded, ensure_ascii=True, separators=(",", ":"))
|
|
229
|
+
if len(rendered.encode("utf-8")) > WORK_BYTES:
|
|
230
|
+
raise ValueError("the declaration is larger than 4 KiB")
|
|
231
|
+
return bounded
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
class Resolution(BaseModel):
|
|
235
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
236
|
+
resolved: bool = Field(strict=True)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def _bounded_state_value(value: dict[str, Any]) -> dict[str, Any]:
|
|
240
|
+
def walk(item: Any) -> None:
|
|
241
|
+
if isinstance(item, dict):
|
|
242
|
+
for key, child in item.items():
|
|
243
|
+
walk(key)
|
|
244
|
+
walk(child)
|
|
245
|
+
elif isinstance(item, list):
|
|
246
|
+
for child in item:
|
|
247
|
+
walk(child)
|
|
248
|
+
elif isinstance(item, str) and "\x00" in item:
|
|
249
|
+
raise ValueError("state values must be valid PostgreSQL text")
|
|
250
|
+
|
|
251
|
+
walk(value)
|
|
252
|
+
# PostgreSQL measures the jsonb text form, which separates with ", " and ": ".
|
|
253
|
+
rendered = json.dumps(value, ensure_ascii=False, separators=(", ", ": "), allow_nan=False)
|
|
254
|
+
if len(rendered.encode("utf-8")) > STATE_VALUE_BYTES:
|
|
255
|
+
raise ValueError("state value is larger than 4 KiB")
|
|
256
|
+
return value
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class StateEntry(BaseModel):
|
|
260
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
261
|
+
|
|
262
|
+
state_key: str = Field(strict=True, pattern=STATE_KEY_PATTERN)
|
|
263
|
+
value: dict[str, Any]
|
|
264
|
+
ttl_seconds: int = Field(strict=True, ge=30, le=3600)
|
|
265
|
+
ref_key: str | None = Field(default=None, strict=True, pattern=STATE_REF_KEY_PATTERN)
|
|
266
|
+
|
|
267
|
+
@field_validator("value")
|
|
268
|
+
@classmethod
|
|
269
|
+
def bounded_value(cls, value: dict[str, Any]) -> dict[str, Any]:
|
|
270
|
+
return _bounded_state_value(value)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
class StateUpsert(BaseModel):
|
|
274
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
275
|
+
|
|
276
|
+
entries: tuple[StateEntry, ...] = Field(min_length=1, max_length=STATE_BATCH)
|
|
277
|
+
|
|
278
|
+
@field_validator("entries")
|
|
279
|
+
@classmethod
|
|
280
|
+
def unique_keys(cls, entries: tuple[StateEntry, ...]) -> tuple[StateEntry, ...]:
|
|
281
|
+
if len({entry.state_key for entry in entries}) != len(entries):
|
|
282
|
+
raise ValueError("a batch names each state_key once")
|
|
283
|
+
return entries
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
class Login(BaseModel):
|
|
287
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
288
|
+
|
|
289
|
+
token: str = Field(strict=True, pattern=r"^[0-9a-f]{64}$", repr=False)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
class RoomCreation(BaseModel):
|
|
293
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
294
|
+
|
|
295
|
+
slug: str = Field(strict=True, pattern=r"^[a-z0-9][a-z0-9-]{0,62}$")
|
|
296
|
+
label: str = Field(strict=True, min_length=1, max_length=128, pattern=r"^[^\x00-\x1f\x7f]+$")
|
|
297
|
+
|
|
298
|
+
@field_validator("label")
|
|
299
|
+
@classmethod
|
|
300
|
+
def label_utf8(cls, value: str) -> str:
|
|
301
|
+
value.encode("utf-8")
|
|
302
|
+
return value
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
class Membership(BaseModel):
|
|
306
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
307
|
+
session_id: UUID
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
class Mute(BaseModel):
|
|
311
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
312
|
+
muted: bool = Field(strict=True)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
class PmMark(BaseModel):
|
|
316
|
+
"""The operator's set (`pm: true`) or clear (`pm: false`) of the room's PM mark for one session."""
|
|
317
|
+
|
|
318
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
319
|
+
session_id: UUID
|
|
320
|
+
pm: bool = Field(strict=True)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
class RoleMark(BaseModel):
|
|
324
|
+
"""The operator's set or clear of one of the three role marks for one session."""
|
|
325
|
+
|
|
326
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
327
|
+
role: Literal["pm", "github_pm", "delivery_manager"]
|
|
328
|
+
session_id: UUID
|
|
329
|
+
assigned: bool = Field(strict=True)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
class Reply(BaseModel):
|
|
333
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
334
|
+
body: str = Field(strict=True, min_length=1)
|
|
335
|
+
recipients: tuple[UUID, ...] = Field(default=(), max_length=16)
|
|
336
|
+
receipts: bool = Field(default=False, strict=True)
|
|
337
|
+
|
|
338
|
+
@field_validator("body")
|
|
339
|
+
@classmethod
|
|
340
|
+
def bounded_body(cls, value: str) -> str:
|
|
341
|
+
return Publication.bounded_body(value)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
class DeliveryClaim(BaseModel):
|
|
345
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
346
|
+
messages: tuple[UUID, ...] = Field(min_length=1, max_length=16)
|
|
347
|
+
|
|
348
|
+
@field_validator("messages")
|
|
349
|
+
@classmethod
|
|
350
|
+
def unique_messages(cls, value: tuple[UUID, ...]) -> tuple[UUID, ...]:
|
|
351
|
+
return tuple(sorted(set(value)))
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
# Undelivered sender receipts one feed read returns, and the most one delivered mark names.
|
|
355
|
+
RECEIPT_FEED_LIMIT = 50
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
class ReceiptDelivery(BaseModel):
|
|
359
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
360
|
+
receipts: tuple[UUID, ...] = Field(min_length=1, max_length=RECEIPT_FEED_LIMIT)
|
|
361
|
+
|
|
362
|
+
@field_validator("receipts")
|
|
363
|
+
@classmethod
|
|
364
|
+
def unique_receipts(cls, value: tuple[UUID, ...]) -> tuple[UUID, ...]:
|
|
365
|
+
return tuple(sorted(set(value)))
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
# Every outcome and the reasons it may carry; the only vocabulary DeliveryResult validates against.
|
|
369
|
+
DELIVERY_REASONS: dict[str, frozenset[str | None]] = {
|
|
370
|
+
"handed": frozenset({None}),
|
|
371
|
+
"failed": frozenset({"native_unavailable"}),
|
|
372
|
+
"deferred": frozenset({"busy", "muted", "stopped", "plan", "unknown", "offline", "stale_binding"}),
|
|
373
|
+
"uncertain": frozenset({"transport_ambiguous"}),
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
class DeliveryResult(BaseModel):
|
|
378
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
379
|
+
outcome: str = Field(strict=True)
|
|
380
|
+
reason: str | None = Field(default=None, strict=True)
|
|
381
|
+
|
|
382
|
+
@model_validator(mode="after")
|
|
383
|
+
def reason_matches_outcome(self) -> "DeliveryResult":
|
|
384
|
+
if self.reason not in DELIVERY_REASONS.get(self.outcome, frozenset()):
|
|
385
|
+
raise ValueError("delivery outcome and reason must be a known pair")
|
|
386
|
+
return self
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
class EmptyRequest(BaseModel):
|
|
390
|
+
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
HTTP_ERROR_STATUS = {
|
|
394
|
+
"UNAUTHENTICATED": 401,
|
|
395
|
+
"SESSION_FORBIDDEN": 403,
|
|
396
|
+
"CSRF_FORBIDDEN": 403,
|
|
397
|
+
"LOGIN_RATE_LIMITED": 429,
|
|
398
|
+
"ROOM_FORBIDDEN": 403,
|
|
399
|
+
"STATE_KEY_FORBIDDEN": 403,
|
|
400
|
+
"NOT_FOUND": 404,
|
|
401
|
+
"BINDING_CONFLICT": 409,
|
|
402
|
+
"ROOM_CONFLICT": 409,
|
|
403
|
+
"ROLE_CONFLICT": 409,
|
|
404
|
+
"STALE_INSTANCE": 409,
|
|
405
|
+
"IDEMPOTENCY_CONFLICT": 409,
|
|
406
|
+
"CONSULTATION_LIMIT": 409,
|
|
407
|
+
"DELIVERY_DISABLED": 403,
|
|
408
|
+
"DELIVERY_BLOCKED": 409,
|
|
409
|
+
"DELIVERY_INELIGIBLE": 409,
|
|
410
|
+
"DELIVERY_IN_FLIGHT": 409,
|
|
411
|
+
"DELIVERY_BATCH_CONFLICT": 409,
|
|
412
|
+
"DELIVERY_CLOSED": 409,
|
|
413
|
+
"DELIVERY_EXHAUSTED": 409,
|
|
414
|
+
"DELIVERY_BACKOFF": 409,
|
|
415
|
+
"WAKE_LIMIT": 429,
|
|
416
|
+
"INSTANCE_LIMIT": 429,
|
|
417
|
+
"REGISTRATION_LIMIT": 429,
|
|
418
|
+
"PUBLICATION_LIMIT": 429,
|
|
419
|
+
"MESSAGE_EXPIRED": 410,
|
|
420
|
+
"CURSOR_EXPIRED": 410,
|
|
421
|
+
"INVALID_REQUEST": 422,
|
|
422
|
+
"INVALID_RECIPIENT": 422,
|
|
423
|
+
"INVALID_CURSOR": 422,
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
class ChatError(Exception):
|
|
428
|
+
def __init__(self, code: str):
|
|
429
|
+
super().__init__(code)
|
|
430
|
+
self.code = code
|