Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion console/packages/plugins/src/switch-skill/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,9 @@ carrying a display name addresses no one.
`agent_names` that should receive `room_join` and `room_leave` events — off
by default). You
are not a member unless your own name is in `agent_names`. Returns
`{id, name, transport_room_id, caller_is_member, failed_attachments}`.
`{id, name, transport_room_id, caller_is_member, creation_visibility_notice, failed_attachments}`.
Relay any `creation_visibility_notice` to the requester: it explains why the
room was created on a public channel.
- **`update_room`** — change an existing room, including its `aliases` map.
- **`invite_agent_to_room`** — add an existing agent to an existing room by
name. Humans and agents can do the same from inside a room with the
Expand Down
6 changes: 5 additions & 1 deletion core/switch_core/bridges/agent/operations/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from switch_core.clients.agent_admin import DELETE_CONFIRM_SECONDS
from switch_core.db.models import CollaborationBridge, User, require_tenant_id
from switch_core.db.session_scope import shared_tenant_session
from switch_core.db.stores.room_store import creation_visibility_notice
from switch_core.db.stores.template_store import TemplateStore
from switch_core.feature_flags import SWITCH_BUDDY
from switch_core.names import refuse_hidden_characters
Expand Down Expand Up @@ -1067,7 +1068,9 @@ async def create_room(

Returns:
`{"id", "name", "matrix_room_id", "caller_is_member",
"failed_attachments": [...]}`.
"creation_visibility_notice", "failed_attachments": [...]}`.
Tell the requester any `creation_visibility_notice`: it explains
why their room was created on a public channel.
`failed_attachments` is empty on full success; otherwise it lists
`{kind, id, error}` for each attachment that could not be applied
after the room was created (race-time failures only; predictable
Expand Down Expand Up @@ -1112,6 +1115,7 @@ async def create_room(
# Deprecated alias, carried for the connector compatibility window.
"matrix_room_id": result.room.transport_room_id,
"caller_is_member": caller_is_member,
"creation_visibility_notice": creation_visibility_notice(result.room),
"failed_attachments": result.failed_attachments,
}

Expand Down
7 changes: 7 additions & 0 deletions core/switch_core/db/stores/room_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
NAME_SOURCE_KEY = "name_source"
# The linked platform channel's name as the bridge last saw it.
LINKED_CHANNEL_NAME_KEY = "linked_channel_name"
CREATION_VISIBILITY_NOTICE_KEY = "creation_visibility_notice"


def creation_visibility_notice(room: Room) -> str | None:
notice = (room.metadata_ or {}).get(CREATION_VISIBILITY_NOTICE_KEY)
return notice if isinstance(notice, str) else None


# Keys in a room's `metadata` for the follow-the-conversation settings. Both
# are absent by default (follow-ups on, no main agent), so rooms made before
Expand Down
7 changes: 6 additions & 1 deletion core/switch_core/gateway/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
from switch_core.db.stores.collaboration_bridge_store import CollaborationBridgeStore
from switch_core.db.stores.external_user_store import ExternalUserStore
from switch_core.db.stores.room_group_store import RoomGroupStore
from switch_core.db.stores.room_store import LINKED_CHANNEL_NAME_KEY, RoomStore
from switch_core.db.stores.room_store import (
LINKED_CHANNEL_NAME_KEY,
RoomStore,
creation_visibility_notice,
)
from switch_core.db.stores.template_store import TemplateStore
from switch_core.db.stores.user_store import UserStore
from switch_core.decision.room import (
Expand Down Expand Up @@ -353,6 +357,7 @@ async def _build_room_detail(
if room.external_channel_id
else None
),
creation_visibility_notice=creation_visibility_notice(room),
room_admin_candidates=candidates,
**flags,
auto_route=auto_route,
Expand Down
2 changes: 2 additions & 0 deletions core/switch_core/gateway/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ class RoomDetail(RoomSummary):
# when it has not seen one. A room not named after its channel can take
# it with `POST /rooms/{id}/sync-name`.
linked_channel_name: str | None = None
# Historical notice when a room defaulted to a public channel.
creation_visibility_notice: str | None = None
# Null on a server with the `decision_routing` flag off, where rooms have
# no auto-route to show.
auto_route: RoomAutoRoute | None
Expand Down
11 changes: 11 additions & 0 deletions core/switch_core/room_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from switch_core.db.stores.external_user_store import ExternalUserStore
from switch_core.db.stores.room_role_store import validate_role_name
from switch_core.db.stores.room_store import (
CREATION_VISIBILITY_NOTICE_KEY,
LINKED_CHANNEL_NAME_KEY,
NAME_SOURCE_KEY,
RoomStore,
Expand Down Expand Up @@ -995,6 +996,7 @@ async def create_room(self, config: RoomCreateConfig) -> RoomCreateResult:
# Never for a template's room: a template run shows no choice before it
# creates the room, so it is refused and the creator links an account.
fallback: dict[str, Any] | None = None
visibility_notice: str | None = None
if (
not chose
and not config.from_template
Expand All @@ -1012,6 +1014,10 @@ async def create_room(self, config: RoomCreateConfig) -> RoomCreateResult:
except PrivateChannelOwnerMissing:
platform = collaboration_core.adapter.platform_name
channel_type = "channel_public"
visibility_notice = (
f"This room was created on a public {platform} channel because "
"its creator did not have a linked account at the time."
)
fallback = {
"kind": "visibility",
"id": PUBLIC_NO_LINKED_ACCOUNT,
Expand Down Expand Up @@ -1132,6 +1138,11 @@ async def create_room(self, config: RoomCreateConfig) -> RoomCreateResult:
# Nothing else on the row can answer this afterwards.
metadata_={
"created_by_kind": config.created_by_kind,
**(
{CREATION_VISIBILITY_NOTICE_KEY: visibility_notice}
if visibility_notice is not None
else {}
),
**(
{"chat_operation_id": config.chat_operation_id}
if config.chat_operation_id is not None
Expand Down
25 changes: 25 additions & 0 deletions core/tests/switch_core/gateway/test_room_detail_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ async def test_detail_names_the_owner(
assert detail.owner_id == owner.id
assert detail.owner_name == "owner"

async def test_remembers_why_a_room_was_created_public(
self, session_factory: async_sessionmaker[AsyncSession]
) -> None:
async with session_factory() as session:
owner = await _add_user(session, name="owner")
room = await _add_room(
session, name="r1", owner_id=owner.id, read_visibility="public"
)
notice = "Made public: you have no messaging account linked."
room.metadata_ = {"creation_visibility_notice": notice}
await session.commit()

detail = await get_room(
room.id,
session,
_ROOM_STORE,
CollaborationBridgeStore(),
ExternalUserStore(),
_protocol(),
_NO_DECISIONS,
owner,
False,
)
assert detail.creation_visibility_notice == notice


class TestDetailMatchesList:
"""A room's detail carries every field of its list entry with the same
Expand Down
7 changes: 7 additions & 0 deletions core/tests/switch_core/test_room_service_channel_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,13 @@ async def test_no_choice_and_no_linked_account_makes_a_public_room_and_says_why(
(note,) = result.failed_attachments
assert note["id"] == PUBLIC_NO_LINKED_ACCOUNT
assert "Link your account to make it private" in note["error"]
async with session_factory() as session:
room = await session.get(Room, result.room.id)
assert room is not None
assert room.metadata_["creation_visibility_notice"] == (
f"This room was created on a public {adapter.platform_name} channel "
"because its creator did not have a linked account at the time."
)


@pytest.mark.parametrize(
Expand Down
Loading