mirror of https://github.com/openclaw/openclaw.git
refactor(slack): share room context hints
This commit is contained in:
parent
ca4c2b33d7
commit
da2fde7b6f
|
|
@ -35,7 +35,6 @@ import { buildPairingReply } from "../../../pairing/pairing-messages.js";
|
|||
import { upsertChannelPairingRequest } from "../../../pairing/pairing-store.js";
|
||||
import { resolveAgentRoute } from "../../../routing/resolve-route.js";
|
||||
import { resolveThreadSessionKeys } from "../../../routing/session-key.js";
|
||||
import { buildUntrustedChannelMetadata } from "../../../security/channel-metadata.js";
|
||||
import { reactSlackMessage } from "../../actions.js";
|
||||
import { sendMessageSlack } from "../../send.js";
|
||||
import { resolveSlackThreadContext } from "../../threading.js";
|
||||
|
|
@ -49,6 +48,7 @@ import {
|
|||
resolveSlackThreadHistory,
|
||||
resolveSlackThreadStarter,
|
||||
} from "../media.js";
|
||||
import { resolveSlackRoomContextHints } from "../room-context.js";
|
||||
|
||||
export async function prepareSlackMessage(params: {
|
||||
ctx: SlackMonitorContext;
|
||||
|
|
@ -452,18 +452,11 @@ export async function prepareSlackMessage(params: {
|
|||
|
||||
const slackTo = isDirectMessage ? `user:${message.user}` : `channel:${message.channel}`;
|
||||
|
||||
const untrustedChannelMetadata = isRoomish
|
||||
? buildUntrustedChannelMetadata({
|
||||
source: "slack",
|
||||
label: "Slack channel description",
|
||||
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 { untrustedChannelMetadata, groupSystemPrompt } = resolveSlackRoomContextHints({
|
||||
isRoomish,
|
||||
channelInfo,
|
||||
channelConfig,
|
||||
});
|
||||
|
||||
let threadStarterBody: string | undefined;
|
||||
let threadHistoryBody: string | undefined;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
@ -26,7 +26,6 @@ import {
|
|||
upsertChannelPairingRequest,
|
||||
} from "../../pairing/pairing-store.js";
|
||||
import { resolveAgentRoute } from "../../routing/resolve-route.js";
|
||||
import { buildUntrustedChannelMetadata } from "../../security/channel-metadata.js";
|
||||
import {
|
||||
normalizeAllowList,
|
||||
normalizeAllowListLower,
|
||||
|
|
@ -38,6 +37,7 @@ import { buildSlackSlashCommandMatcher, resolveSlackSlashCommandConfig } from ".
|
|||
import { normalizeSlackChannelType } from "./context.js";
|
||||
import { isSlackChannelAllowedByPolicy } from "./policy.js";
|
||||
import { deliverSlackSlashReplies } from "./replies.js";
|
||||
import { resolveSlackRoomContextHints } from "./room-context.js";
|
||||
|
||||
type SlackBlock = { type: string; [key: string]: unknown };
|
||||
|
||||
|
|
@ -387,18 +387,11 @@ export function registerSlackMonitorSlashCommands(params: {
|
|||
},
|
||||
});
|
||||
|
||||
const untrustedChannelMetadata = isRoomish
|
||||
? buildUntrustedChannelMetadata({
|
||||
source: "slack",
|
||||
label: "Slack channel description",
|
||||
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 { untrustedChannelMetadata, groupSystemPrompt } = resolveSlackRoomContextHints({
|
||||
isRoomish,
|
||||
channelInfo,
|
||||
channelConfig,
|
||||
});
|
||||
|
||||
const ctxPayload = finalizeInboundContext({
|
||||
Body: prompt,
|
||||
|
|
|
|||
Loading…
Reference in New Issue