Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
Tell a refused answerer in the card's thread when the card is itself a reply
Petr Bauch55e35aae7a29
diff --git a/core/switch_core/bridges/collaboration/session/refusal.py b/core/switch_core/bridges/collaboration/session/refusal.pyindex bdb613124..422dd2220 100644--- a/core/switch_core/bridges/collaboration/session/refusal.py+++ b/core/switch_core/bridges/collaboration/session/refusal.py@@ -19,8 +19,9 @@ class Refused:does, because most of these are one: the wording that explains a refusal towhoever reads the log is the wording that explains it to whoever typed.`handle` names the card when it is known, so the person can be told which- of several they were answering. `card_ref` is the card's own post — set- whenever a card was found, which is every refusal past the lookup — so a+ of several they were answering. `card_ref` is the thread the card is in —+ the root it was posted under, or the card's own post at the top level — set+ whenever a card was found, which is every refusal past the lookup, so anotice can be said in the card's thread rather than wherever the answerhappened to be typed, which may be nowhere at all."""diff --git a/core/switch_core/session_activity/bridge_answers.py b/core/switch_core/session_activity/bridge_answers.pyindex fbcafb8b8..59553d244 100644--- a/core/switch_core/session_activity/bridge_answers.py+++ b/core/switch_core/session_activity/bridge_answers.py@@ -113,7 +113,7 @@ class ApprovalAnswers:return Refused(reason="that control does not belong to this card",handle=post.handle,- card_ref=post.external_post_id,+ card_ref=_card_thread(post),)if row is None:return _gone(post)@@ -182,7 +182,7 @@ class ApprovalAnswers:) -> Answered | Refused:if isinstance(answer, Unanswerable):return Refused(- reason=answer.reason, handle=post.handle, card_ref=post.external_post_id+ reason=answer.reason, handle=post.handle, card_ref=_card_thread(post))mxid = await self._identify(actor)if mxid is None:@@ -193,7 +193,7 @@ class ApprovalAnswers:self._bridge_id,)return Refused(- reason=_NO_IDENTITY, handle=post.handle, card_ref=post.external_post_id+ reason=_NO_IDENTITY, handle=post.handle, card_ref=_card_thread(post))try:await self._service.answer_approval(@@ -214,16 +214,23 @@ class ApprovalAnswers:return Refused(reason=_as_reason(str(error)),handle=post.handle,- card_ref=post.external_post_id,+ card_ref=_card_thread(post),)return Answered(handle=post.handle)+def _card_thread(post: ApprovalRequestPost) -> str | None:+ """The thread a card is in: the root it was posted under, or the card itself+ when it was posted at the top level. A platform threads a reply under a+ root, not under another reply."""+ return post.thread_ref or post.external_post_id++def _gone(post: ApprovalRequestPost) -> Refused:return Refused(reason="its request no longer exists",handle=post.handle,- card_ref=post.external_post_id,+ card_ref=_card_thread(post),)diff --git a/core/tests/switch_core/session_activity/test_bridge_answers.py b/core/tests/switch_core/session_activity/test_bridge_answers.pyindex 6f3c8cb67..6f5ca9ffa 100644--- a/core/tests/switch_core/session_activity/test_bridge_answers.py+++ b/core/tests/switch_core/session_activity/test_bridge_answers.py@@ -148,6 +148,33 @@ async def test_someone_who_may_not_address_the_agent_is_refused(assert (await _state(session_factory))[0] == "open"+async def test_a_refusal_names_the_thread_a_threaded_card_is_in(+ service, session_factory, bridged, card, people+):+ async with session_factory() as db, db.begin():+ await db.execute(+ update(ApprovalRequestPost).values(thread_ref="1700000000.0001")+ )+ await db.execute(+ update(Agent)+ .where(Agent.id == AGENT)+ .values(addressing_policy=owner_only_policy([]).model_dump())+ )+ answers = _answers(service, session_factory, bridged, people.stranger)+ outcome = await answers.for_text(_typed(bridged, "A1 1"))+ assert isinstance(outcome, Refused)+ assert outcome.card_ref == "1700000000.0001"+++async def test_a_refusal_names_a_top_level_card_as_its_own_thread(+ service, session_factory, bridged, card, people+):+ answers = _answers(service, session_factory, bridged, None)+ outcome = await answers.for_text(_typed(bridged, "A1 1"))+ assert isinstance(outcome, Refused)+ assert outcome.card_ref == CARD_POST++async def test_a_press_on_another_message_is_refused(service, session_factory, bridged, card, people):