Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions apps/api/src/handlers/slack/events/fast-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,6 @@ export async function processFastAgentMessage(params: {
ts: message.ts,
bot_id: message.bot_id,
}));
const hasOtherHumanParticipant = threadContext.some(
(message) =>
message.ts !== event.ts &&
!message.bot_id &&
Boolean(message.user) &&
message.user !== event.user,
);

const needsCanonicalAdmission =
!releaseFastAgentLock ||
Expand All @@ -219,12 +212,16 @@ export async function processFastAgentMessage(params: {
currentMessageId: event.ts,
userId,
question,
threadContext: serializedThreadContext,
...(attachments.images.length ? { images: attachments.images } : {}),
...(currentMessage?.username
? { senderDisplayName: currentMessage.username }
: {}),
...(event.user ? { senderExternalId: event.user } : {}),
directedAtRoomote,
directedAtRoomote:
directedAtRoomote ||
event.channel_type === 'im' ||
event.channel_type === 'mpim',
};
let durableTurn: FastAgentDurableTurn | null = null;
if (needsCanonicalAdmission) {
Expand Down Expand Up @@ -299,7 +296,6 @@ export async function processFastAgentMessage(params: {
allowSilentAmbientReply:
event.channel_type !== 'im' &&
event.channel_type !== 'mpim' &&
hasOtherHumanParticipant &&
!directedAtRoomote,
...(roomoteSlackUserId ? { slackRoomoteUserId: roomoteSlackUserId } : {}),
adapter: {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 33 additions & 19 deletions apps/api/src/handlers/slack/events/message-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type UnmentionedSlackThreadReplyRoutingDecision =
| { shouldRoute: false }
| {
shouldRoute: true;
threadMessages: SlackThreadMessage[];
threadMessages?: SlackThreadMessage[];
taskId?: string;
};

Expand Down Expand Up @@ -281,11 +281,23 @@ async function markHumanMentionedSlackThread(params: {
event: SlackEvent;
slack: SlackNotifier;
botUserId: string | null | undefined;
teamId: string;
}): Promise<void> {
if (!mentionsSlackUserOtherThanBot(params.event, params.botUserId)) {
return;
}

if (
params.event.thread_ts &&
(await hasBoundSlackFastAgentSession({
teamId: params.teamId,
channelId: params.event.channel,
threadId: params.event.thread_ts,
}))
) {
return;
}

await markExplicitMentionRequiredSlackThread(params);
}

Expand Down Expand Up @@ -321,6 +333,19 @@ export async function shouldRouteUnmentionedSlackThreadReplyToAgent(params: {
return { shouldRoute: false };
}

// Established Fast conversations observe human discussion too. Fast decides
// whether to engage under its quiet-participation rules; legacy task threads
// retain their explicit-mention/interjection gate below.
if (
await hasBoundSlackFastAgentSession({
teamId,
channelId: event.channel,
threadId: event.thread_ts,
})
) {
return { shouldRoute: true };
}

if (
mentionsSlackUserOtherThanBotWithoutMentioningBot(
event,
Expand All @@ -333,36 +358,25 @@ export async function shouldRouteUnmentionedSlackThreadReplyToAgent(params: {
let roomoteThreadMatch: Awaited<
ReturnType<typeof findRoomoteOwnedSlackThread>
> | null = null;
let isFastAgentThread = false;

let eligibilityReason: 'roomote-owned-thread' | null = null;

{
isFastAgentThread = await hasBoundSlackFastAgentSession({
roomoteThreadMatch = await findRoomoteOwnedSlackThread({
teamId,
channelId: event.channel,
threadId: event.thread_ts,
threadTs: event.thread_ts,
});

roomoteThreadMatch = isFastAgentThread
const taskThreadRoute = roomoteThreadMatch
? null
: await findRoomoteOwnedSlackThread({
teamId,
: await resolveSlackThreadFollowUpRoute({
threadId: event.thread_ts,
channelId: event.channel,
threadTs: event.thread_ts,
slackTeamId: teamId,
});

const taskThreadRoute =
isFastAgentThread || roomoteThreadMatch
? null
: await resolveSlackThreadFollowUpRoute({
threadId: event.thread_ts,
channelId: event.channel,
slackTeamId: teamId,
});

if (
isFastAgentThread ||
roomoteThreadMatch ||
(taskThreadRoute && taskThreadRoute.kind !== 'fresh')
) {
Expand Down Expand Up @@ -431,7 +445,6 @@ export async function shouldRouteUnmentionedSlackThreadReplyToAgent(params: {
isAutomationReportThread: Boolean(
roomoteThreadMatch?.isAutomationReportThread,
),
isOpenConversationThread: isFastAgentThread,
threadMessages: sharedHistory,
compareMessageIds: compareNumericMessageIds,
});
Expand Down Expand Up @@ -1377,6 +1390,7 @@ export async function handleMessageOrAppMentionEvent(params: {
event,
slack: context.slack,
botUserId: context.slackInstallation.botUserId,
teamId: context.teamId,
});

const mentionedThreadAliasTaskId =
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading