0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 08:06:54 +08:00
discourse/plugins/discourse-ai/lib/ai_bot.rb
Mark VanLandingham c2a47a6675
FIX: Authorize Retried AI Bot Replies Against Topic Creator (#42325)
## Summary

Previously, AI bot replies checked agent access against the author of
the latest post, which meant a more privileged participant could
unintentionally unlock a restricted agent for a conversation; retries
could also lose the original authorization context, especially after a
failed response.

This change keeps topic-selected agents tied to the topic creator’s
permissions, records the exact authorizing user before response
generation begins, and reuses that information for retries. Explicit
agent mentions still use the mentioning user’s permissions, while legacy
conversations and missing users fail closed rather than guessing or
inheriting access from another participant.
## Source

- Patch Triage: https://patch.discourse.org/patch-triage/1180
2026-08-05 14:28:53 -05:00

15 lines
556 B
Ruby
Vendored

# frozen_string_literal: true
module DiscourseAi
module AiBot
USER_AGENT = "Discourse AI Bot 1.0 (https://www.discourse.org)"
TOPIC_AI_BOT_PM_FIELD = "is_ai_bot_pm"
POST_AI_LLM_NAME_FIELD = "ai_llm_name"
POST_AI_LLM_MODEL_ID_FIELD = "ai_llm_model_id"
POST_AI_AGENT_ID_FIELD = "ai_agent_id"
POST_AI_AGENT_AUTHORIZATION_USER_ID_FIELD = "ai_agent_authorization_user_id"
TOPIC_AI_AGENT_ID_FIELD = "ai_agent_id"
TOPIC_AI_AGENT_ID_MAX_LENGTH = 20
PERSONAL_MESSAGE_CONTEXT = "discourse_ai.ai_bot_personal_message"
end
end