mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 09:21:23 +00:00
refactor(slack): share room context hints
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
31
src/slack/monitor/room-context.ts
Normal file
31
src/slack/monitor/room-context.ts
Normal 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,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user