group_protocol.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. """Shared protocol limits and input normalization for YaoYao Group Chat."""
  2. from __future__ import annotations
  3. import base64
  4. import binascii
  5. import re
  6. import unicodedata
  7. from pathlib import Path
  8. from typing import Any, Literal
  9. from uuid import UUID
  10. from pydantic import (
  11. BaseModel,
  12. ConfigDict,
  13. Field,
  14. StrictBool,
  15. StrictInt,
  16. field_validator,
  17. model_validator,
  18. )
  19. PROTOCOL_VERSION = 12
  20. MAX_AGENTS_PER_ROOM = 8
  21. MAX_MESSAGE_BYTES = 64 * 1024
  22. MAX_TOOL_STATE_BYTES = 256 * 1024
  23. MAX_INTERACTION_PAYLOAD_BYTES = 64 * 1024
  24. MAX_MESSAGE_PAGE_SIZE = 100
  25. MAX_EVENT_BATCH_SIZE = 200
  26. MAX_EVENT_FRAME_BYTES = 2 * 1024 * 1024
  27. MAX_AGENT_DEPTH = 2
  28. DEFAULT_MAX_REPLY_ROUNDS = 3
  29. UNLIMITED_REPLY_ROUNDS = -1
  30. MAX_FINITE_REPLY_ROUNDS = 100
  31. MAX_AGENT_DISPLAY_NAME_LENGTH = 100
  32. MAX_ROOM_INSTRUCTIONS_LENGTH = 4_000
  33. MAX_ROOM_AVATAR_LENGTH = 512 * 1024
  34. MAX_ROOM_CONCURRENCY = 3
  35. MAX_PLUGIN_CONCURRENCY = 4
  36. INITIAL_CONTEXT_MESSAGE_LIMIT = 50
  37. CONTEXT_CHARACTER_BUDGET = 32_000
  38. REASONING_EFFORTS = frozenset({
  39. "none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"
  40. })
  41. ORCHESTRATION_MODES = frozenset({"free", "host"})
  42. _ROOM_AVATAR_PATTERN = re.compile(
  43. r"^data:image/(png|jpeg|webp);base64,([A-Za-z0-9+/]+={0,2})$",
  44. re.IGNORECASE,
  45. )
  46. # These literals address the room as a whole and must never become a member
  47. # display-name or alias target. Keep the stable wire spelling for existing
  48. # clients while accepting the localized spelling shown by the iOS UI.
  49. ALL_MENTION_ALIASES = ("所有人", "all")
  50. _ALL_MENTION_ALIAS_KEYS = frozenset(
  51. alias.casefold() for alias in ALL_MENTION_ALIASES
  52. )
  53. EVENT_TYPES = frozenset({
  54. "room.created",
  55. "room.updated",
  56. "room.deleted",
  57. "room.restored",
  58. "agent.created",
  59. "agent.updated",
  60. "agent.deleted",
  61. "agent.status",
  62. "message.upsert",
  63. "topic.updated",
  64. "topic.archived",
  65. "topic.restored",
  66. "room.activity",
  67. "interaction.requested",
  68. "interaction.resolved",
  69. "run.updated",
  70. })
  71. def limits_payload() -> dict[str, int]:
  72. """Return the public, lower-camel protocol limits advertised to clients."""
  73. return {
  74. "maxAgentsPerRoom": MAX_AGENTS_PER_ROOM,
  75. "maxMessageBytes": MAX_MESSAGE_BYTES,
  76. "maxToolStateBytes": MAX_TOOL_STATE_BYTES,
  77. "maxInteractionPayloadBytes": MAX_INTERACTION_PAYLOAD_BYTES,
  78. "maxMessagePageSize": MAX_MESSAGE_PAGE_SIZE,
  79. "maxEventBatchSize": MAX_EVENT_BATCH_SIZE,
  80. "maxEventFrameBytes": MAX_EVENT_FRAME_BYTES,
  81. "maxAgentDepth": MAX_AGENT_DEPTH,
  82. "defaultMaxReplyRounds": DEFAULT_MAX_REPLY_ROUNDS,
  83. "unlimitedReplyRoundsValue": UNLIMITED_REPLY_ROUNDS,
  84. "maxAgentDisplayNameLength": MAX_AGENT_DISPLAY_NAME_LENGTH,
  85. "maxRoomInstructionsLength": MAX_ROOM_INSTRUCTIONS_LENGTH,
  86. "maxRoomAvatarLength": MAX_ROOM_AVATAR_LENGTH,
  87. "maxRoomConcurrency": MAX_ROOM_CONCURRENCY,
  88. "maxPluginConcurrency": MAX_PLUGIN_CONCURRENCY,
  89. }
  90. def normalize_room_avatar(value: object) -> str:
  91. """Validate a persisted custom avatar; an empty string selects auto mode."""
  92. if not isinstance(value, str):
  93. raise ValueError("avatar must be a data image URL or an empty string")
  94. normalized = value.strip()
  95. if not normalized:
  96. return ""
  97. if len(normalized) > MAX_ROOM_AVATAR_LENGTH:
  98. raise ValueError("avatar is too large")
  99. match = _ROOM_AVATAR_PATTERN.fullmatch(normalized)
  100. if match is None:
  101. raise ValueError("avatar must be a PNG, JPEG, or WebP data image URL")
  102. try:
  103. decoded = base64.b64decode(match.group(2), validate=True)
  104. except (binascii.Error, ValueError) as error:
  105. raise ValueError("avatar contains invalid base64 data") from error
  106. if not decoded:
  107. raise ValueError("avatar image is empty")
  108. return normalized
  109. class GroupModel(BaseModel):
  110. """Public request base with lower-camel aliases and forbidden extras."""
  111. model_config = ConfigDict(populate_by_name=True, extra="forbid")
  112. class AgentSeed(GroupModel):
  113. profile: str = Field(min_length=1, max_length=100)
  114. node_id: str = Field(default="local", alias="nodeId", min_length=1, max_length=64)
  115. node_label: str = Field(default="", alias="nodeLabel", max_length=100)
  116. display_name: str | None = Field(
  117. default=None, alias="displayName", max_length=MAX_AGENT_DISPLAY_NAME_LENGTH
  118. )
  119. description: str = Field(default="", max_length=500)
  120. reply_without_mention: StrictBool = Field(
  121. default=False, alias="replyWithoutMention"
  122. )
  123. is_host: StrictBool = Field(default=False, alias="isHost")
  124. model: str | None = Field(default=None, max_length=4096)
  125. provider: str | None = Field(default=None, max_length=4096)
  126. reasoning_effort: str | None = Field(
  127. default=None, alias="reasoningEffort", max_length=32
  128. )
  129. fast_mode: StrictBool | None = Field(default=None, alias="fastMode")
  130. @field_validator("model", "provider", "reasoning_effort")
  131. @classmethod
  132. def normalize_optional_configuration(cls, value: str | None) -> str | None:
  133. return normalize_optional_agent_configuration(value)
  134. @field_validator("reasoning_effort")
  135. @classmethod
  136. def validate_reasoning_effort(cls, value: str | None) -> str | None:
  137. return validate_reasoning_override(value)
  138. @model_validator(mode="after")
  139. def validate_model_selection(self) -> "AgentSeed":
  140. validate_model_provider_pair(self.model, self.provider)
  141. return self
  142. @field_validator("display_name")
  143. @classmethod
  144. def reject_reserved_display_name(cls, value: str | None) -> str | None:
  145. return validate_optional_display_name(value)
  146. @field_validator("node_id")
  147. @classmethod
  148. def validate_node_id(cls, value: str) -> str:
  149. return normalize_node_id(value)
  150. @field_validator("node_label")
  151. @classmethod
  152. def normalize_node_label(cls, value: str) -> str:
  153. return " ".join(value.split())
  154. class CreateRoomRequest(GroupModel):
  155. request_id: UUID = Field(alias="requestId")
  156. name: str = Field(min_length=1, max_length=100)
  157. cwd: str = Field(default="", max_length=4096)
  158. instructions: str = Field(default="", max_length=MAX_ROOM_INSTRUCTIONS_LENGTH)
  159. avatar: str = Field(default="", max_length=MAX_ROOM_AVATAR_LENGTH)
  160. max_reply_rounds: StrictInt = Field(
  161. default=DEFAULT_MAX_REPLY_ROUNDS, alias="maxReplyRounds"
  162. )
  163. orchestration_mode: Literal["free", "host"] = Field(
  164. default="free", alias="orchestrationMode"
  165. )
  166. agents: list[AgentSeed] = Field(min_length=1, max_length=MAX_AGENTS_PER_ROOM)
  167. @field_validator("max_reply_rounds")
  168. @classmethod
  169. def validate_max_reply_rounds(cls, value: int) -> int:
  170. return normalize_max_reply_rounds(value)
  171. @field_validator("instructions")
  172. @classmethod
  173. def normalize_instructions(cls, value: str) -> str:
  174. return normalize_room_instructions(value)
  175. @field_validator("avatar")
  176. @classmethod
  177. def normalize_avatar(cls, value: str) -> str:
  178. return normalize_room_avatar(value)
  179. @model_validator(mode="after")
  180. def validate_unique_host(self) -> "CreateRoomRequest":
  181. if sum(agent.is_host for agent in self.agents) > 1:
  182. raise ValueError("Room may contain only one host Agent")
  183. return self
  184. class UpdateRoomRequest(GroupModel):
  185. request_id: UUID = Field(alias="requestId")
  186. name: str | None = Field(default=None, min_length=1, max_length=100)
  187. cwd: str | None = Field(default=None, max_length=4096)
  188. instructions: str | None = Field(
  189. default=None, max_length=MAX_ROOM_INSTRUCTIONS_LENGTH
  190. )
  191. avatar: str | None = Field(default=None, max_length=MAX_ROOM_AVATAR_LENGTH)
  192. max_reply_rounds: StrictInt | None = Field(default=None, alias="maxReplyRounds")
  193. orchestration_mode: Literal["free", "host"] | None = Field(
  194. default=None, alias="orchestrationMode"
  195. )
  196. @field_validator(
  197. "name", "cwd", "instructions", "avatar", "max_reply_rounds", "orchestration_mode",
  198. mode="before"
  199. )
  200. @classmethod
  201. def reject_explicit_null(cls, value: Any) -> Any:
  202. if value is None:
  203. raise ValueError("field must not be null")
  204. return value
  205. @model_validator(mode="after")
  206. def require_change(self) -> "UpdateRoomRequest":
  207. if not (
  208. {"name", "cwd", "instructions", "avatar", "max_reply_rounds", "orchestration_mode"}
  209. & self.model_fields_set
  210. ):
  211. raise ValueError(
  212. "Room update requires name, cwd, instructions, avatar, maxReplyRounds, or orchestrationMode"
  213. )
  214. return self
  215. @field_validator("instructions")
  216. @classmethod
  217. def normalize_instructions(cls, value: str | None) -> str | None:
  218. return None if value is None else normalize_room_instructions(value)
  219. @field_validator("avatar")
  220. @classmethod
  221. def normalize_avatar(cls, value: str | None) -> str | None:
  222. return None if value is None else normalize_room_avatar(value)
  223. @field_validator("max_reply_rounds")
  224. @classmethod
  225. def validate_max_reply_rounds(cls, value: int | None) -> int | None:
  226. return None if value is None else normalize_max_reply_rounds(value)
  227. class UpdateTopicRequest(GroupModel):
  228. request_id: UUID = Field(alias="requestId")
  229. title: str | None = Field(default=None, min_length=1, max_length=120)
  230. pinned: StrictBool | None = None
  231. @field_validator("title")
  232. @classmethod
  233. def normalize_title(cls, value: str | None) -> str | None:
  234. if value is None:
  235. return None
  236. normalized = " ".join(value.split()).strip()
  237. if not normalized:
  238. raise ValueError("title must not be blank")
  239. return normalized
  240. @model_validator(mode="after")
  241. def require_change(self) -> "UpdateTopicRequest":
  242. if not ({"title", "pinned"} & self.model_fields_set):
  243. raise ValueError("Topic update requires title or pinned")
  244. return self
  245. class MarkTopicReadRequest(GroupModel):
  246. request_id: UUID = Field(alias="requestId")
  247. through_seq: StrictInt = Field(alias="throughSeq", ge=0)
  248. class AddAgentRequest(GroupModel):
  249. request_id: UUID = Field(alias="requestId")
  250. profile: str = Field(min_length=1, max_length=100)
  251. node_id: str = Field(default="local", alias="nodeId", min_length=1, max_length=64)
  252. node_label: str = Field(default="", alias="nodeLabel", max_length=100)
  253. display_name: str | None = Field(
  254. default=None, alias="displayName", max_length=MAX_AGENT_DISPLAY_NAME_LENGTH
  255. )
  256. description: str = Field(default="", max_length=500)
  257. reply_without_mention: StrictBool = Field(
  258. default=False, alias="replyWithoutMention"
  259. )
  260. is_host: StrictBool = Field(default=False, alias="isHost")
  261. model: str | None = Field(default=None, max_length=4096)
  262. provider: str | None = Field(default=None, max_length=4096)
  263. reasoning_effort: str | None = Field(
  264. default=None, alias="reasoningEffort", max_length=32
  265. )
  266. fast_mode: StrictBool | None = Field(default=None, alias="fastMode")
  267. @field_validator("model", "provider", "reasoning_effort")
  268. @classmethod
  269. def normalize_optional_configuration(cls, value: str | None) -> str | None:
  270. return normalize_optional_agent_configuration(value)
  271. @field_validator("reasoning_effort")
  272. @classmethod
  273. def validate_reasoning_effort(cls, value: str | None) -> str | None:
  274. return validate_reasoning_override(value)
  275. @model_validator(mode="after")
  276. def validate_model_selection(self) -> "AddAgentRequest":
  277. validate_model_provider_pair(self.model, self.provider)
  278. return self
  279. @field_validator("display_name")
  280. @classmethod
  281. def reject_reserved_display_name(cls, value: str | None) -> str | None:
  282. return validate_optional_display_name(value)
  283. @field_validator("node_id")
  284. @classmethod
  285. def validate_node_id(cls, value: str) -> str:
  286. return normalize_node_id(value)
  287. @field_validator("node_label")
  288. @classmethod
  289. def normalize_node_label(cls, value: str) -> str:
  290. return " ".join(value.split())
  291. class UpdateAgentRequest(GroupModel):
  292. request_id: UUID = Field(alias="requestId")
  293. display_name: str | None = Field(
  294. default=None, alias="displayName", max_length=MAX_AGENT_DISPLAY_NAME_LENGTH
  295. )
  296. description: str | None = Field(default=None, max_length=500)
  297. enabled: StrictBool | None = None
  298. reply_without_mention: StrictBool | None = Field(
  299. default=None, alias="replyWithoutMention"
  300. )
  301. is_host: StrictBool | None = Field(default=None, alias="isHost")
  302. model: str | None = Field(default=None, max_length=4096)
  303. provider: str | None = Field(default=None, max_length=4096)
  304. reasoning_effort: str | None = Field(
  305. default=None, alias="reasoningEffort", max_length=32
  306. )
  307. fast_mode: StrictBool | None = Field(default=None, alias="fastMode")
  308. @field_validator(
  309. "display_name", "description", "enabled", "reply_without_mention", "is_host",
  310. mode="before"
  311. )
  312. @classmethod
  313. def reject_explicit_null(cls, value: Any) -> Any:
  314. if value is None:
  315. raise ValueError("field must not be null")
  316. return value
  317. @field_validator("display_name")
  318. @classmethod
  319. def reject_reserved_display_name(cls, value: str | None) -> str | None:
  320. return validate_optional_display_name(value)
  321. @field_validator("model", "provider", "reasoning_effort")
  322. @classmethod
  323. def normalize_optional_configuration(cls, value: str | None) -> str | None:
  324. return normalize_optional_agent_configuration(value)
  325. @field_validator("reasoning_effort")
  326. @classmethod
  327. def validate_reasoning_effort(cls, value: str | None) -> str | None:
  328. return validate_reasoning_override(value)
  329. @model_validator(mode="after")
  330. def require_change(self) -> "UpdateAgentRequest":
  331. if not (
  332. {
  333. "display_name", "description", "enabled", "reply_without_mention",
  334. "is_host",
  335. "model", "provider", "reasoning_effort", "fast_mode",
  336. }
  337. & self.model_fields_set
  338. ):
  339. raise ValueError(
  340. "Agent update requires a mutable agent field"
  341. )
  342. model_fields = {"model", "provider"} & self.model_fields_set
  343. if model_fields and model_fields != {"model", "provider"}:
  344. raise ValueError("model and provider must be updated together")
  345. if model_fields:
  346. validate_model_provider_pair(self.model, self.provider)
  347. return self
  348. def normalize_optional_agent_configuration(value: str | None) -> str | None:
  349. if value is None:
  350. return None
  351. normalized = value.strip()
  352. if not normalized:
  353. raise ValueError("configuration value must not be blank")
  354. return normalized
  355. def normalize_node_id(value: str) -> str:
  356. normalized = value.strip().lower()
  357. if normalized == "local":
  358. return normalized
  359. try:
  360. canonical = str(UUID(normalized))
  361. except ValueError as error:
  362. raise ValueError("nodeId must be local or a canonical UUID") from error
  363. if canonical != normalized:
  364. raise ValueError("nodeId must be local or a canonical UUID")
  365. return canonical
  366. def validate_reasoning_override(value: str | None) -> str | None:
  367. if value is not None and value not in REASONING_EFFORTS:
  368. raise ValueError("reasoningEffort is invalid")
  369. return value
  370. def validate_model_provider_pair(model: str | None, provider: str | None) -> None:
  371. if (model is None) != (provider is None):
  372. raise ValueError("model and provider must both be set or both be null")
  373. class RequestIDRequest(GroupModel):
  374. request_id: UUID = Field(alias="requestId")
  375. class SendMessageRequest(GroupModel):
  376. request_id: UUID = Field(alias="requestId")
  377. client_message_id: UUID = Field(alias="clientMessageId")
  378. topic_id: UUID | None = Field(default=None, alias="topicId")
  379. content: str
  380. mention_agent_ids: list[UUID] = Field(
  381. alias="mentionAgentIds", max_length=MAX_AGENTS_PER_ROOM
  382. )
  383. @field_validator("content")
  384. @classmethod
  385. def validate_content_bytes(cls, value: str) -> str:
  386. try:
  387. encoded = value.encode("utf-8")
  388. except UnicodeEncodeError as error:
  389. raise ValueError("content must be valid UTF-8") from error
  390. if len(encoded) > MAX_MESSAGE_BYTES:
  391. raise ValueError("content exceeds maximum size")
  392. if not value.strip():
  393. raise ValueError("content must not be blank")
  394. return value
  395. class ApprovalRequest(GroupModel):
  396. request_id: UUID = Field(alias="requestId")
  397. choice: Literal["once", "session", "always", "deny"]
  398. permanent: StrictBool = False
  399. @model_validator(mode="after")
  400. def validate_choice(self) -> "ApprovalRequest":
  401. if (self.choice == "always") != self.permanent:
  402. raise ValueError("permanent must be true exactly for choice=always")
  403. return self
  404. class ClarificationRequest(GroupModel):
  405. request_id: UUID = Field(alias="requestId")
  406. response: str
  407. @field_validator("response")
  408. @classmethod
  409. def validate_response_bytes(cls, value: str) -> str:
  410. try:
  411. encoded = value.encode("utf-8")
  412. except UnicodeEncodeError as error:
  413. raise ValueError("response must be valid UTF-8") from error
  414. if not value.strip():
  415. raise ValueError("response must not be blank")
  416. if len(encoded) > MAX_MESSAGE_BYTES:
  417. raise ValueError("response exceeds maximum size")
  418. return value
  419. def normalize_room_name(value: str) -> str:
  420. """Return a trimmed room name within the protocol's character limit."""
  421. normalized = value.strip()
  422. if not 1 <= len(normalized) <= 100:
  423. raise ValueError("Room name must contain 1 to 100 characters")
  424. return normalized
  425. def normalize_room_instructions(value: str) -> str:
  426. """Normalize optional multiline room rules without changing their structure."""
  427. if not isinstance(value, str):
  428. raise ValueError("Room instructions must be a string")
  429. normalized = value.replace("\r\n", "\n").replace("\r", "\n").strip()
  430. if len(normalized) > MAX_ROOM_INSTRUCTIONS_LENGTH:
  431. raise ValueError(
  432. f"Room instructions must contain at most {MAX_ROOM_INSTRUCTIONS_LENGTH} characters"
  433. )
  434. if any(
  435. unicodedata.category(character) == "Cc" and character not in {"\n", "\t"}
  436. for character in normalized
  437. ):
  438. raise ValueError("Room instructions contain unsupported control characters")
  439. return normalized
  440. def normalize_display_name(value: str) -> tuple[str, str]:
  441. """Return a trimmed display name and its case-insensitive uniqueness key."""
  442. normalized = value.strip()
  443. if not 1 <= len(normalized) <= MAX_AGENT_DISPLAY_NAME_LENGTH:
  444. raise ValueError(
  445. f"Display name must contain 1 to {MAX_AGENT_DISPLAY_NAME_LENGTH} characters"
  446. )
  447. uniqueness_key = normalized.casefold()
  448. if uniqueness_key in _ALL_MENTION_ALIAS_KEYS:
  449. raise ValueError("Display name is reserved")
  450. return normalized, uniqueness_key
  451. def is_reserved_mention_alias(value: str) -> bool:
  452. """Return whether a member-facing name would claim a room-wide Mention."""
  453. return value.strip().casefold() in _ALL_MENTION_ALIAS_KEYS
  454. def validate_optional_display_name(value: str | None) -> str | None:
  455. """Reject only non-empty reserved names; blank still means use the fallback."""
  456. if value is not None and value.strip() and is_reserved_mention_alias(value):
  457. raise ValueError("Display name is reserved")
  458. return value
  459. def normalize_max_reply_rounds(value: object) -> int:
  460. """Validate a finite reply-round ceiling or the explicit unlimited marker."""
  461. if isinstance(value, bool) or not isinstance(value, int):
  462. raise ValueError("maxReplyRounds must be an integer")
  463. if value == UNLIMITED_REPLY_ROUNDS:
  464. return value
  465. if not 1 <= value <= MAX_FINITE_REPLY_ROUNDS:
  466. raise ValueError(
  467. f"maxReplyRounds must be -1 or 1 to {MAX_FINITE_REPLY_ROUNDS}"
  468. )
  469. return value
  470. def normalize_interaction_id(value: object) -> str:
  471. """Canonicalize an opaque Gateway interaction identity for URL use."""
  472. if not isinstance(value, str):
  473. raise ValueError("interactionId must be a string")
  474. normalized = value.strip()
  475. if (
  476. not normalized
  477. or len(normalized) > 200
  478. or any(unicodedata.category(character) == "Cc" for character in normalized)
  479. ):
  480. raise ValueError("interactionId is invalid")
  481. return normalized
  482. def normalize_room_cwd(value: str) -> str:
  483. """Validate and canonicalize an optional room working directory."""
  484. if not isinstance(value, str):
  485. raise ValueError("Room cwd must be a string")
  486. if value and any(unicodedata.category(character) == "Cc" for character in value):
  487. raise ValueError("Room cwd must not contain control characters")
  488. normalized = value.strip()
  489. if not normalized:
  490. return ""
  491. path = Path(normalized)
  492. if not path.is_absolute():
  493. raise ValueError("Room cwd must be an absolute path")
  494. try:
  495. resolved = path.resolve()
  496. is_directory = resolved.is_dir()
  497. except (OSError, RuntimeError) as error:
  498. raise ValueError("Room cwd could not be resolved") from error
  499. if not is_directory:
  500. raise ValueError("Room cwd must exist and be a directory")
  501. return str(resolved)