Discord: isolate autoThread thread context (#856)
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
- Telegram: honor `channels.telegram.timeoutSeconds` for grammY API requests. (#863) — thanks @Snaver.
|
- Telegram: honor `channels.telegram.timeoutSeconds` for grammY API requests. (#863) — thanks @Snaver.
|
||||||
- Telegram: split long captions into media + follow-up text messages. (#907) - thanks @jalehman.
|
- Telegram: split long captions into media + follow-up text messages. (#907) - thanks @jalehman.
|
||||||
- Slack: drop Socket Mode events with mismatched `api_app_id`/`team_id`. (#889) — thanks @roshanasingh4.
|
- Slack: drop Socket Mode events with mismatched `api_app_id`/`team_id`. (#889) — thanks @roshanasingh4.
|
||||||
|
- Discord: isolate autoThread thread context. (#856) — thanks @davidguttman.
|
||||||
|
|
||||||
## 2026.1.13
|
## 2026.1.13
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,10 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
|
|||||||
body: text,
|
body: text,
|
||||||
});
|
});
|
||||||
let shouldClearHistory = false;
|
let shouldClearHistory = false;
|
||||||
if (!isDirectMessage) {
|
const shouldIncludeChannelHistory =
|
||||||
|
!isDirectMessage &&
|
||||||
|
!(isGuildMessage && channelConfig?.autoThread && !threadChannel);
|
||||||
|
if (shouldIncludeChannelHistory) {
|
||||||
combinedBody = buildHistoryContextFromMap({
|
combinedBody = buildHistoryContextFromMap({
|
||||||
historyMap: guildHistories,
|
historyMap: guildHistories,
|
||||||
historyKey: message.channelId,
|
historyKey: message.channelId,
|
||||||
@@ -147,10 +150,12 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
|
|||||||
body: `${entry.sender}: ${entry.body} [id:${entry.messageId ?? "unknown"} channel:${message.channelId}]`,
|
body: `${entry.sender}: ${entry.body} [id:${entry.messageId ?? "unknown"} channel:${message.channelId}]`,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
shouldClearHistory = true;
|
||||||
|
}
|
||||||
|
if (!isDirectMessage) {
|
||||||
const name = formatDiscordUserTag(author);
|
const name = formatDiscordUserTag(author);
|
||||||
const id = author.id;
|
const id = author.id;
|
||||||
combinedBody = `${combinedBody}\n[from: ${name} user id:${id}]`;
|
combinedBody = `${combinedBody}\n[from: ${name} user id:${id}]`;
|
||||||
shouldClearHistory = true;
|
|
||||||
}
|
}
|
||||||
const replyContext = resolveReplyContext(message, resolveDiscordMessageText);
|
const replyContext = resolveReplyContext(message, resolveDiscordMessageText);
|
||||||
if (replyContext) {
|
if (replyContext) {
|
||||||
@@ -197,7 +202,7 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
|
|||||||
parentSessionKey,
|
parentSessionKey,
|
||||||
useSuffix: false,
|
useSuffix: false,
|
||||||
});
|
});
|
||||||
const ctxPayload = {
|
let ctxPayload = {
|
||||||
Body: combinedBody,
|
Body: combinedBody,
|
||||||
RawBody: baseText,
|
RawBody: baseText,
|
||||||
CommandBody: baseText,
|
CommandBody: baseText,
|
||||||
@@ -254,6 +259,35 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
|
|||||||
replyTarget = replyPlan.replyTarget;
|
replyTarget = replyPlan.replyTarget;
|
||||||
const replyReference = replyPlan.replyReference;
|
const replyReference = replyPlan.replyReference;
|
||||||
|
|
||||||
|
// If autoThread created a new thread, ensure we also isolate session context to that thread.
|
||||||
|
if (createdThreadId && replyTarget === `channel:${createdThreadId}`) {
|
||||||
|
const threadSessionKey = buildAgentSessionKey({
|
||||||
|
agentId: route.agentId,
|
||||||
|
channel: route.channel,
|
||||||
|
peer: { kind: "channel", id: createdThreadId },
|
||||||
|
});
|
||||||
|
const autoParentSessionKey = buildAgentSessionKey({
|
||||||
|
agentId: route.agentId,
|
||||||
|
channel: route.channel,
|
||||||
|
peer: { kind: "channel", id: message.channelId },
|
||||||
|
});
|
||||||
|
const autoThreadKeys = resolveThreadSessionKeys({
|
||||||
|
baseSessionKey: threadSessionKey,
|
||||||
|
threadId: createdThreadId,
|
||||||
|
parentSessionKey: autoParentSessionKey,
|
||||||
|
useSuffix: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
ctxPayload = {
|
||||||
|
...ctxPayload,
|
||||||
|
From: `group:${createdThreadId}`,
|
||||||
|
To: `channel:${createdThreadId}`,
|
||||||
|
OriginatingTo: `channel:${createdThreadId}`,
|
||||||
|
SessionKey: autoThreadKeys.sessionKey,
|
||||||
|
ParentSessionKey: autoThreadKeys.parentSessionKey,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (isDirectMessage) {
|
if (isDirectMessage) {
|
||||||
const sessionCfg = cfg.session;
|
const sessionCfg = cfg.session;
|
||||||
const storePath = resolveStorePath(sessionCfg?.store, {
|
const storePath = resolveStorePath(sessionCfg?.store, {
|
||||||
|
|||||||
Reference in New Issue
Block a user