fix: restore discord owner hint from allowlists

This commit is contained in:
Peter Steinberger
2026-02-04 23:34:08 -08:00
parent 8524666454
commit d84eb46467
8 changed files with 89 additions and 7 deletions

View File

@@ -154,6 +154,30 @@ export function resolveDiscordUserAllowed(params: {
});
}
export function resolveDiscordOwnerAllowFrom(params: {
channelConfig?: DiscordChannelConfigResolved | null;
guildInfo?: DiscordGuildEntryResolved | null;
sender: { id: string; name?: string; tag?: string };
}): string[] | undefined {
const rawAllowList = params.channelConfig?.users ?? params.guildInfo?.users;
if (!Array.isArray(rawAllowList) || rawAllowList.length === 0) {
return undefined;
}
const allowList = normalizeDiscordAllowList(rawAllowList, ["discord:", "user:", "pk:"]);
if (!allowList) {
return undefined;
}
const match = allowListMatches(allowList, {
id: params.sender.id,
name: params.sender.name,
tag: params.sender.tag,
});
if (!match.allowed || !match.matchKey || match.matchKey === "*") {
return undefined;
}
return [match.matchKey];
}
export function resolveDiscordCommandAuthorized(params: {
isDirectMessage: boolean;
allowFrom?: Array<string | number>;

View File

@@ -31,7 +31,7 @@ import { resolveThreadSessionKeys } from "../../routing/session-key.js";
import { buildUntrustedChannelMetadata } from "../../security/channel-metadata.js";
import { truncateUtf16Safe } from "../../utils.js";
import { reactMessageDiscord, removeReactionDiscord } from "../send.js";
import { normalizeDiscordSlug } from "./allow-list.js";
import { normalizeDiscordSlug, resolveDiscordOwnerAllowFrom } from "./allow-list.js";
import { resolveTimestampMs } from "./format.js";
import {
buildDiscordMediaPayload,
@@ -157,6 +157,11 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
);
const groupSystemPrompt =
systemPromptParts.length > 0 ? systemPromptParts.join("\n\n") : undefined;
const ownerAllowFrom = resolveDiscordOwnerAllowFrom({
channelConfig,
guildInfo,
sender: { id: sender.id, name: sender.name, tag: sender.tag },
});
const storePath = resolveStorePath(cfg.session?.store, {
agentId: route.agentId,
});
@@ -293,6 +298,7 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
UntrustedContext: untrustedChannelMetadata ? [untrustedChannelMetadata] : undefined,
GroupSystemPrompt: isGuildMessage ? groupSystemPrompt : undefined,
GroupSpace: isGuildMessage ? (guildInfo?.id ?? guildSlug) || undefined : undefined,
OwnerAllowFrom: ownerAllowFrom,
Provider: "discord" as const,
Surface: "discord" as const,
WasMentioned: effectiveWasMentioned,

View File

@@ -50,6 +50,7 @@ import {
normalizeDiscordSlug,
resolveDiscordChannelConfigWithFallback,
resolveDiscordGuildEntry,
resolveDiscordOwnerAllowFrom,
resolveDiscordUserAllowed,
} from "./allow-list.js";
import { resolveDiscordChannelInfo } from "./message-utils.js";
@@ -741,6 +742,11 @@ async function dispatchDiscordCommandInteraction(params: {
parentPeer: threadParentId ? { kind: "channel", id: threadParentId } : undefined,
});
const conversationLabel = isDirectMessage ? (user.globalName ?? user.username) : channelId;
const ownerAllowFrom = resolveDiscordOwnerAllowFrom({
channelConfig,
guildInfo,
sender: { id: sender.id, name: sender.name, tag: sender.tag },
});
const ctxPayload = finalizeInboundContext({
Body: prompt,
RawBody: prompt,
@@ -778,6 +784,7 @@ async function dispatchDiscordCommandInteraction(params: {
return untrustedChannelMetadata ? [untrustedChannelMetadata] : undefined;
})()
: undefined,
OwnerAllowFrom: ownerAllowFrom,
SenderName: user.globalName ?? user.username,
SenderId: user.id,
SenderUsername: user.username,