| 42 | }; |
| 43 | |
| 44 | async function saveAnalyticsToDB( |
| 45 | instructionMessage: string, |
| 46 | llmResponse: string, |
| 47 | orgId: number, |
| 48 | dbData: { conversationId: number; index: number }, |
| 49 | bertie?: boolean, |
| 50 | chosenActions?: string[], |
| 51 | ): Promise<void> { |
| 52 | const insertRes = await supabase.from("analytics_code_snippets").insert({ |
| 53 | instruction_message: instructionMessage, // The user message contents |
| 54 | output: llmResponse, |
| 55 | org_id: orgId, |
| 56 | conversation_id: dbData.conversationId, |
| 57 | conversation_index: dbData.index, |
| 58 | is_bertie: bertie ?? false, |
| 59 | chosen_actions: chosenActions ?? [], |
| 60 | }); |
| 61 | if (insertRes.error) { |
| 62 | console.error( |
| 63 | "Failed to insert analytics code snippet to DB:", |
| 64 | insertRes.error, |
| 65 | ); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | const madeAMistake = { |
| 70 | role: "loading", |