@@ -30,16 +30,16 @@ import { convertMarkdownTables } from "../../markdown/tables.js";
3030import { getAgentScopedMediaLocalRoots } from "../../media/local-roots.js" ;
3131import { buildAgentSessionKey } from "../../routing/resolve-route.js" ;
3232import { resolveThreadSessionKeys } from "../../routing/session-key.js" ;
33- import { buildUntrustedChannelMetadata } from "../../security/channel-metadata.js" ;
3433import { stripReasoningTagsFromText } from "../../shared/text/reasoning-tags.js" ;
3534import { truncateUtf16Safe } from "../../utils.js" ;
3635import { chunkDiscordTextWithMode } from "../chunk.js" ;
3736import { resolveDiscordDraftStreamingChunking } from "../draft-chunking.js" ;
3837import { createDiscordDraftStream } from "../draft-stream.js" ;
3938import { reactMessageDiscord , removeReactionDiscord } from "../send.js" ;
4039import { editMessageDiscord } from "../send.messages.js" ;
41- import { normalizeDiscordSlug , resolveDiscordOwnerAllowFrom } from "./allow-list.js" ;
40+ import { normalizeDiscordSlug } from "./allow-list.js" ;
4241import { resolveTimestampMs } from "./format.js" ;
42+ import { buildDiscordInboundAccessContext } from "./inbound-context.js" ;
4343import type { DiscordMessagePreflightContext } from "./message-handler.preflight.js" ;
4444import {
4545 buildDiscordMediaPayload ,
@@ -212,30 +212,20 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
212212 const forumContextLine = isForumStarter ? `[Forum parent: #${ forumParentSlug } ]` : null ;
213213 const groupChannel = isGuildMessage && displayChannelSlug ? `#${ displayChannelSlug } ` : undefined ;
214214 const groupSubject = isDirectMessage ? undefined : groupChannel ;
215- const untrustedChannelMetadata = isGuildMessage
216- ? buildUntrustedChannelMetadata ( {
217- source : "discord" ,
218- label : "Discord channel topic" ,
219- entries : [ channelInfo ?. topic ] ,
220- } )
221- : undefined ;
222215 const senderName = sender . isPluralKit
223216 ? ( sender . name ?? author . username )
224217 : ( data . member ?. nickname ?? author . globalName ?? author . username ) ;
225218 const senderUsername = sender . isPluralKit
226219 ? ( sender . tag ?? sender . name ?? author . username )
227220 : author . username ;
228221 const senderTag = sender . tag ;
229- const systemPromptParts = [ channelConfig ?. systemPrompt ?. trim ( ) || null ] . filter (
230- ( entry ) : entry is string => Boolean ( entry ) ,
231- ) ;
232- const groupSystemPrompt =
233- systemPromptParts . length > 0 ? systemPromptParts . join ( "\n\n" ) : undefined ;
234- const ownerAllowFrom = resolveDiscordOwnerAllowFrom ( {
222+ const { groupSystemPrompt, ownerAllowFrom, untrustedContext } = buildDiscordInboundAccessContext ( {
235223 channelConfig,
236224 guildInfo,
237225 sender : { id : sender . id , name : sender . name , tag : sender . tag } ,
238226 allowNameMatching : isDangerousNameMatchingEnabled ( discordConfig ) ,
227+ isGuild : isGuildMessage ,
228+ channelTopic : channelInfo ?. topic ,
239229 } ) ;
240230 const storePath = resolveStorePath ( cfg . session ?. store , {
241231 agentId : route . agentId ,
@@ -374,7 +364,7 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
374364 SenderTag : senderTag ,
375365 GroupSubject : groupSubject ,
376366 GroupChannel : groupChannel ,
377- UntrustedContext : untrustedChannelMetadata ? [ untrustedChannelMetadata ] : undefined ,
367+ UntrustedContext : untrustedContext ,
378368 GroupSystemPrompt : isGuildMessage ? groupSystemPrompt : undefined ,
379369 GroupSpace : isGuildMessage ? ( guildInfo ?. id ?? guildSlug ) || undefined : undefined ,
380370 OwnerAllowFrom : ownerAllowFrom ,
0 commit comments