refactor(slack): share room context hints

This commit is contained in:
Peter Steinberger
2026-02-15 17:06:17 +00:00
parent ca4c2b33d7
commit da2fde7b6f
3 changed files with 43 additions and 26 deletions

View File

@@ -35,7 +35,6 @@ import { buildPairingReply } from "../../../pairing/pairing-messages.js";
import { upsertChannelPairingRequest } from "../../../pairing/pairing-store.js"; import { upsertChannelPairingRequest } from "../../../pairing/pairing-store.js";
import { resolveAgentRoute } from "../../../routing/resolve-route.js"; import { resolveAgentRoute } from "../../../routing/resolve-route.js";
import { resolveThreadSessionKeys } from "../../../routing/session-key.js"; import { resolveThreadSessionKeys } from "../../../routing/session-key.js";
import { buildUntrustedChannelMetadata } from "../../../security/channel-metadata.js";
import { reactSlackMessage } from "../../actions.js"; import { reactSlackMessage } from "../../actions.js";
import { sendMessageSlack } from "../../send.js"; import { sendMessageSlack } from "../../send.js";
import { resolveSlackThreadContext } from "../../threading.js"; import { resolveSlackThreadContext } from "../../threading.js";
@@ -49,6 +48,7 @@ import {
resolveSlackThreadHistory, resolveSlackThreadHistory,
resolveSlackThreadStarter, resolveSlackThreadStarter,
} from "../media.js"; } from "../media.js";
import { resolveSlackRoomContextHints } from "../room-context.js";
export async function prepareSlackMessage(params: { export async function prepareSlackMessage(params: {
ctx: SlackMonitorContext; ctx: SlackMonitorContext;
@@ -452,18 +452,11 @@ export async function prepareSlackMessage(params: {
const slackTo = isDirectMessage ? `user:${message.user}` : `channel:${message.channel}`; const slackTo = isDirectMessage ? `user:${message.user}` : `channel:${message.channel}`;
const untrustedChannelMetadata = isRoomish const { untrustedChannelMetadata, groupSystemPrompt } = resolveSlackRoomContextHints({
? buildUntrustedChannelMetadata({ isRoomish,
source: "slack", channelInfo,
label: "Slack channel description", channelConfig,
entries: [channelInfo?.topic, channelInfo?.purpose], });
})
: undefined;
const systemPromptParts = [channelConfig?.systemPrompt?.trim() || null].filter(
(entry): entry is string => Boolean(entry),
);
const groupSystemPrompt =
systemPromptParts.length > 0 ? systemPromptParts.join("\n\n") : undefined;
let threadStarterBody: string | undefined; let threadStarterBody: string | undefined;
let threadHistoryBody: string | undefined; let threadHistoryBody: string | undefined;

View File

@@ -0,0 +1,31 @@
import { buildUntrustedChannelMetadata } from "../../security/channel-metadata.js";
export function resolveSlackRoomContextHints(params: {
isRoomish: boolean;
channelInfo?: { topic?: string; purpose?: string };
channelConfig?: { systemPrompt?: string | null } | null;
}): {
untrustedChannelMetadata?: ReturnType<typeof buildUntrustedChannelMetadata>;
groupSystemPrompt?: string;
} {
if (!params.isRoomish) {
return {};
}
const untrustedChannelMetadata = buildUntrustedChannelMetadata({
source: "slack",
label: "Slack channel description",
entries: [params.channelInfo?.topic, params.channelInfo?.purpose],
});
const systemPromptParts = [params.channelConfig?.systemPrompt?.trim() || null].filter(
(entry): entry is string => Boolean(entry),
);
const groupSystemPrompt =
systemPromptParts.length > 0 ? systemPromptParts.join("\n\n") : undefined;
return {
untrustedChannelMetadata,
groupSystemPrompt,
};
}

View File

@@ -26,7 +26,6 @@ import {
upsertChannelPairingRequest, upsertChannelPairingRequest,
} from "../../pairing/pairing-store.js"; } from "../../pairing/pairing-store.js";
import { resolveAgentRoute } from "../../routing/resolve-route.js"; import { resolveAgentRoute } from "../../routing/resolve-route.js";
import { buildUntrustedChannelMetadata } from "../../security/channel-metadata.js";
import { import {
normalizeAllowList, normalizeAllowList,
normalizeAllowListLower, normalizeAllowListLower,
@@ -38,6 +37,7 @@ import { buildSlackSlashCommandMatcher, resolveSlackSlashCommandConfig } from ".
import { normalizeSlackChannelType } from "./context.js"; import { normalizeSlackChannelType } from "./context.js";
import { isSlackChannelAllowedByPolicy } from "./policy.js"; import { isSlackChannelAllowedByPolicy } from "./policy.js";
import { deliverSlackSlashReplies } from "./replies.js"; import { deliverSlackSlashReplies } from "./replies.js";
import { resolveSlackRoomContextHints } from "./room-context.js";
type SlackBlock = { type: string; [key: string]: unknown }; type SlackBlock = { type: string; [key: string]: unknown };
@@ -387,18 +387,11 @@ export function registerSlackMonitorSlashCommands(params: {
}, },
}); });
const untrustedChannelMetadata = isRoomish const { untrustedChannelMetadata, groupSystemPrompt } = resolveSlackRoomContextHints({
? buildUntrustedChannelMetadata({ isRoomish,
source: "slack", channelInfo,
label: "Slack channel description", channelConfig,
entries: [channelInfo?.topic, channelInfo?.purpose], });
})
: undefined;
const systemPromptParts = [channelConfig?.systemPrompt?.trim() || null].filter(
(entry): entry is string => Boolean(entry),
);
const groupSystemPrompt =
systemPromptParts.length > 0 ? systemPromptParts.join("\n\n") : undefined;
const ctxPayload = finalizeInboundContext({ const ctxPayload = finalizeInboundContext({
Body: prompt, Body: prompt,