Skip to content
Merged
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
10 changes: 8 additions & 2 deletions apps/app/instrumentation-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { initBotId } from 'botid/client/core';
initBotId({
protect: [
{ path: '/api/chat', method: 'POST' },
{ path: '/api/tasks-automations/chat', method: 'POST' },
{ path: '/api/tasks-automations/errors', method: 'POST' },
{
path: `${process.env.NEXT_PUBLIC_ENTERPRISE_API_URL}/api/tasks-automations/chat`,
method: 'POST',
},
{
path: `${process.env.NEXT_PUBLIC_ENTERPRISE_API_URL}/api/tasks-automations/errors`,
method: 'POST',
},
],
});
2 changes: 2 additions & 0 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"@monaco-editor/react": "^4.7.0",
"@nangohq/frontend": "^0.53.2",
"@next/third-parties": "^15.3.1",
"@novu/api": "^1.6.0",
"@novu/nextjs": "^3.10.1",
"@number-flow/react": "^0.5.9",
"@prisma/client": "^6.13.0",
"@prisma/instrumentation": "6.6.0",
Expand Down
80 changes: 29 additions & 51 deletions apps/app/src/actions/policies/accept-requested-policy-changes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use server';

import { db, PolicyStatus } from '@db';
import { sendPolicyNotificationEmail } from '@trycompai/email';
import { revalidatePath, revalidateTag } from 'next/cache';
import { z } from 'zod';
import { authActionClient } from '../safe-action';
Expand Down Expand Up @@ -72,6 +71,7 @@ export const acceptRequestedPolicyChangesAction = authActionClient
approverId: null,
signedBy: [], // Clear the signedBy field
lastPublishedAt: new Date(), // Update last published date
reviewDate: new Date(), // Update reviewDate to current date
},
});

Expand All @@ -92,56 +92,34 @@ export const acceptRequestedPolicyChangesAction = authActionClient
return roles.includes('employee');
});

// Send notification emails to all employees
// Send emails in batches of 2 per second to respect rate limit
const BATCH_SIZE = 2;
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

const sendEmailsInBatches = async () => {
for (let i = 0; i < employeeMembers.length; i += BATCH_SIZE) {
const batch = employeeMembers.slice(i, i + BATCH_SIZE);

await Promise.all(
batch.map(async (employee) => {
if (!employee.user.email) return;

let notificationType: 'new' | 're-acceptance' | 'updated';
const wasAlreadySigned = policy.signedBy.includes(employee.id);
if (isNewPolicy) {
notificationType = 'new';
} else if (wasAlreadySigned) {
notificationType = 're-acceptance';
} else {
notificationType = 'updated';
}

try {
await sendPolicyNotificationEmail({
email: employee.user.email,
userName: employee.user.name || employee.user.email || 'Employee',
policyName: policy.name,
organizationName: policy.organization.name,
organizationId: session.activeOrganizationId,
notificationType,
});
} catch (emailError) {
console.error(`Failed to send email to ${employee.user.email}:`, emailError);
// Don't fail the whole operation if email fails
}
}),
);

// Only delay if there are more emails to send
if (i + BATCH_SIZE < employeeMembers.length) {
await delay(1000); // wait 1 second between batches
}
}
};

// Fire and forget, but log errors if any
sendEmailsInBatches().catch((error) => {
console.error('Some emails failed to send:', error);
});
// Call /api/send-policy-email to send emails to employees

// Prepare the events array for the API
const events = employeeMembers
.filter((employee) => employee.user.email)
.map((employee) => ({
subscriberId: `${employee.user.id}-${session.activeOrganizationId}`,
email: employee.user.email,
userName: employee.user.name || employee.user.email || 'Employee',
policyName: policy.name,
organizationName: policy.organization.name,
url: `${process.env.NEXT_PUBLIC_APP_URL ?? 'https://app.trycomp.ai'}/${session.activeOrganizationId}/policies/${policy.id}`,
description: `The "${policy.name}" policy has been ${isNewPolicy ? 'created' : 'updated'}.`,
}));

// Call the API route to send the emails
try {
await fetch(`${process.env.BETTER_AUTH_URL ?? ''}/api/send-policy-email`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(events),
});
} catch (error) {
console.error('Failed to call /api/send-policy-email:', error);
// Don't throw, just log
}

// If a comment was provided, create a comment
if (comment && comment.trim() !== '') {
Expand Down
25 changes: 0 additions & 25 deletions apps/app/src/ai/constants.ts

This file was deleted.

98 changes: 0 additions & 98 deletions apps/app/src/ai/secrets.ts

This file was deleted.

55 changes: 0 additions & 55 deletions apps/app/src/ai/tools/create-sandbox.md

This file was deleted.

75 changes: 0 additions & 75 deletions apps/app/src/ai/tools/create-sandbox.ts

This file was deleted.

Loading
Loading