Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
34 changes: 33 additions & 1 deletion apps/api/src/handlers/fast-agent-entry.test.ts

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

7 changes: 7 additions & 0 deletions apps/api/src/handlers/fast-agent-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { Env } from '@roomote/env';

type FastAgentEntryMode = 'explicit' | 'default';

export function shouldShowFastAgentProcessingReaction(params: {
entryMode: FastAgentEntryMode;
hasExistingSession: boolean;
}): boolean {
return params.entryMode === 'explicit' || !params.hasExistingSession;
}

export function resolveFastAgentEntryMode(params: {
explicitInvocation: boolean;
deploymentSettingEnabled: boolean;
Expand Down

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

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

14 changes: 9 additions & 5 deletions apps/api/src/handlers/slack/events/fast-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export async function processFastAgentMessage(params: {
activeTasks?: FastAgentActiveTask[];
launchTask: LaunchFastAgentTask;
processingReactionName?: string;
showProcessingReaction?: boolean;
}): Promise<void> {
const {
event,
Expand All @@ -67,6 +68,7 @@ export async function processFastAgentMessage(params: {
activeTasks = [],
launchTask,
processingReactionName = 'eyes',
showProcessingReaction = true,
} = params;
const threadId = event.thread_ts || event.ts;
const conversation = {
Expand Down Expand Up @@ -99,11 +101,13 @@ export async function processFastAgentMessage(params: {
let didAddProcessingReaction = false;

try {
didAddProcessingReaction = await slack.addReaction({
channel: event.channel,
timestamp: event.ts,
name: processingReactionName,
});
if (showProcessingReaction) {
didAddProcessingReaction = await slack.addReaction({
channel: event.channel,
timestamp: event.ts,
name: processingReactionName,
});
}

if (!question) {
await postSlackThreadMarkdownMessage({
Expand Down
38 changes: 37 additions & 1 deletion apps/api/src/handlers/slack/events/message-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ import {
isFastCommandInvocation,
processFastAgentMessage,
} from './fast-agent.js';
import { resolveFastAgentEntryMode } from '../../fast-agent-entry.js';
import {
resolveFastAgentEntryMode,
shouldShowFastAgentProcessingReaction,
} from '../../fast-agent-entry.js';
import { processSnapshotResume } from './snapshot-resume.js';
import {
dispatchSlackThreadFollowUp,
Expand Down Expand Up @@ -1258,6 +1261,22 @@ async function maybeHandleChannelAutoStart(params: {
: null;

if (fastAgentEntryMode && userMapping) {
const hasExistingSession =
fastAgentEntryMode === 'default' &&
(await hasFastAgentSession({
surface: 'slack',
workspaceId: context.teamId,
conversationId: channelAutoStartEvent.ts,
replyTarget: {
channelId: channelAutoStartEvent.channel,
threadId: channelAutoStartEvent.ts,
},
}));
const showProcessingReaction = shouldShowFastAgentProcessingReaction({
entryMode: fastAgentEntryMode,
hasExistingSession,
});

startFastAgentResponse({
event: { ...channelAutoStartEvent, user: channelAutoStartEvent.user },
slackInstallation: context.slackInstallation,
Expand All @@ -1268,6 +1287,7 @@ async function maybeHandleChannelAutoStart(params: {
usageText: 'Use `/fast <question>` in this channel.',
continuation: fastAgentEntryMode === 'default',
processingReactionName: ackEmoji,
showProcessingReaction,
errorLogPrefix: `❌ Background fast-agent response failed for auto-start thread ${channelAutoStartEvent.ts}:`,
});

Expand Down Expand Up @@ -1602,6 +1622,7 @@ function startFastAgentResponse(params: {
continuation?: boolean;
activeTasks?: { taskId: string }[];
processingReactionName: string;
showProcessingReaction?: boolean;
errorLogPrefix: string;
}): void {
const { errorLogPrefix, ...fastAgentParams } = params;
Expand Down Expand Up @@ -1741,6 +1762,19 @@ async function handleSlackEntryEvent(params: {
});

if (fastAgentEntryMode) {
const hasExistingSession =
fastAgentEntryMode === 'default' &&
(await hasFastAgentSession({
Comment thread
roomote-roomote[bot] marked this conversation as resolved.
Outdated
surface: 'slack',
workspaceId: teamId,
conversationId: threadId,
replyTarget: { channelId: event.channel, threadId },
}));
const showProcessingReaction = shouldShowFastAgentProcessingReaction({
entryMode: fastAgentEntryMode,
hasExistingSession,
});

startFastAgentResponse({
event,
slackInstallation,
Expand All @@ -1751,6 +1785,7 @@ async function handleSlackEntryEvent(params: {
activeTasks: activeRun ? [{ taskId: activeRun.taskId }] : [],
continuation: fastAgentEntryMode === 'default',
processingReactionName: ackEmoji,
showProcessingReaction,
errorLogPrefix: `❌ Background fast-agent response failed for thread ${threadId}:`,
});

Expand Down Expand Up @@ -1779,6 +1814,7 @@ async function handleSlackEntryEvent(params: {
continuation: true,
activeTasks: activeRun ? [{ taskId: activeRun.taskId }] : [],
processingReactionName: ackEmoji,
showProcessingReaction: false,
errorLogPrefix: `❌ Background fast-agent continuation failed for thread ${threadId}:`,
});

Expand Down
Loading