MCPcopy
hub / github.com/simstudioai/sim / executeInboxTask

Function executeInboxTask

apps/sim/lib/mothership/inbox/executor.ts:44–323  ·  view source on GitHub ↗
(taskId: string)

Source from the content-addressed store, hash-verified

42 * 7. Update task status
43 */
44export async function executeInboxTask(taskId: string): Promise<void> {
45 const [inboxTask] = await db
46 .select()
47 .from(mothershipInboxTask)
48 .where(eq(mothershipInboxTask.id, taskId))
49 .limit(1)
50
51 if (!inboxTask) {
52 logger.error('Inbox task not found', { taskId })
53 return
54 }
55
56 if (inboxTask.status === 'completed' || inboxTask.status === 'failed') {
57 logger.info('Inbox task already terminal, skipping', { taskId, status: inboxTask.status })
58 return
59 }
60
61 const [ws] = await db
62 .select({
63 id: workspace.id,
64 ownerId: workspace.ownerId,
65 inboxProviderId: workspace.inboxProviderId,
66 })
67 .from(workspace)
68 .where(eq(workspace.id, inboxTask.workspaceId))
69 .limit(1)
70
71 if (!ws) {
72 logger.error('Workspace not found for inbox task', {
73 taskId,
74 workspaceId: inboxTask.workspaceId,
75 })
76 await markTaskFailed(taskId, 'Workspace not found')
77 return
78 }
79
80 let chatId = inboxTask.chatId
81 let responseSent = false
82
83 try {
84 const [[claimed], userId] = await Promise.all([
85 db
86 .update(mothershipInboxTask)
87 .set({ status: 'processing', processingStartedAt: new Date() })
88 .where(and(eq(mothershipInboxTask.id, taskId), eq(mothershipInboxTask.status, 'received')))
89 .returning({ id: mothershipInboxTask.id }),
90 resolveUserId(inboxTask.fromEmail, ws),
91 ])
92
93 if (!claimed) {
94 logger.info('Task already claimed by another execution, skipping', { taskId })
95 return
96 }
97
98 // Blocked senders and banned accounts must not drive the agent; the sender
99 // email is checked directly (domain list + the sender's own account ban)
100 // because non-members resolve to the workspace owner, and the workspace
101 // billed account is checked to match preprocessExecution's gate. Fails

Callers 2

route.tsFile · 0.90

Calls 15

isEmailBlockedFunction · 0.90
getActivelyBannedUserIdsFunction · 0.90
getErrorMessageFunction · 0.90
resolveOrCreateChatFunction · 0.90
requestChatTitleFunction · 0.90
generateIdFunction · 0.90
generateWorkspaceContextFunction · 0.90
buildUserSkillToolFunction · 0.90
getUserEntityPermissionsFunction · 0.90
formatEmailAsMessageFunction · 0.90

Tested by

no test coverage detected