({
thread,
message,
platformIntegration,
user,
}: {
thread: Thread;
message: Message;
platformIntegration: PlatformIntegration;
user: User;
})
| 7 | import { captureException } from '@sentry/nextjs'; |
| 8 | |
| 9 | export async function processLinkedMessage({ |
| 10 | thread, |
| 11 | message, |
| 12 | platformIntegration, |
| 13 | user, |
| 14 | }: { |
| 15 | thread: Thread; |
| 16 | message: Message; |
| 17 | platformIntegration: PlatformIntegration; |
| 18 | user: User; |
| 19 | }) { |
| 20 | const botPlatform = botPlatforms.requireByAdapter(thread.adapter); |
| 21 | const stopProcessingIndicator = await botPlatform.startProcessingIndicator({ |
| 22 | thread, |
| 23 | messageId: message.id, |
| 24 | status: 'Thinking...', |
| 25 | platformIntegration, |
| 26 | }); |
| 27 | |
| 28 | let handedOff = false; |
| 29 | try { |
| 30 | let botRequestId: string; |
| 31 | try { |
| 32 | botRequestId = await createBotRequest({ |
| 33 | createdBy: user.id, |
| 34 | organizationId: platformIntegration.owned_by_organization_id ?? null, |
| 35 | platformIntegrationId: platformIntegration.id, |
| 36 | platform: thread.adapter.name, |
| 37 | platformThreadId: thread.id, |
| 38 | platformMessageId: message.id, |
| 39 | userMessage: message.text, |
| 40 | modelUsed: undefined, |
| 41 | }); |
| 42 | } catch (error) { |
| 43 | captureException(error, { |
| 44 | tags: { component: 'kilo-bot', op: 'create-bot-request' }, |
| 45 | extra: { |
| 46 | platform: thread.adapter.name, |
| 47 | platformIntegrationId: platformIntegration.id, |
| 48 | userId: user.id, |
| 49 | threadId: thread.id, |
| 50 | messageId: message.id, |
| 51 | }, |
| 52 | }); |
| 53 | await botPlatform.withAuthContext({ |
| 54 | platformIntegration, |
| 55 | fn: () => |
| 56 | thread.post({ |
| 57 | markdown: |
| 58 | 'Sorry, I could not start processing your message because of an internal error. Please try again in a moment.', |
| 59 | }), |
| 60 | }); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | handedOff = await processMessage({ |
| 65 | thread, |
| 66 | message, |
no test coverage detected