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
39 changes: 39 additions & 0 deletions apps/api/src/app/support/dtos/agents-early-access.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Type } from 'class-transformer';
import { IsArray, IsDefined, IsString, ValidateNested } from 'class-validator';

export class HowAgentRunsTodayDto {
@IsDefined()
@IsString()
value: string;

@IsDefined()
@IsString()
label: string;
}

export class PlannedProviderDto {
@IsDefined()
@IsString()
id: string;

@IsDefined()
@IsString()
label: string;
}

export class AgentsEarlyAccessDto {
@IsDefined()
@ValidateNested()
@Type(() => HowAgentRunsTodayDto)
howAgentRunsToday: HowAgentRunsTodayDto;

@IsDefined()
@IsArray()
@ValidateNested({ each: true })
@Type(() => PlannedProviderDto)
plannedProviders: PlannedProviderDto[];

@IsDefined()
@IsString()
whatAgentDoes: string;
}
53 changes: 51 additions & 2 deletions apps/api/src/app/support/support.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import { ApiExcludeController } from '@nestjs/swagger';
import { Novu } from '@novu/api';
import { UserSession } from '@novu/application-generic';
import { PinoLogger, UserSession } from '@novu/application-generic';
import { OrganizationRepository } from '@novu/dal';
import { UserSessionData } from '@novu/shared';
import { RequireAuthentication } from '../auth/framework/auth.decorator';
import { AgentsEarlyAccessDto } from './dtos/agents-early-access.dto';
import { CreateSupportThreadDto } from './dtos/create-thread.dto';
import { PlainCardRequestDto } from './dtos/plain-card.dto';
import { PlainCardsGuard } from './guards/plain-cards.guard';
Expand All @@ -16,15 +18,62 @@ import { PlainCardsCommand } from './usecases/plain-cards.command';
export class SupportController {
constructor(
private createSupportThreadUsecase: CreateSupportThreadUsecase,
private organizationRepository: OrganizationRepository,
private logger: PinoLogger,
private plainCardsUsecase: PlainCardsUsecase
) {}
) {
this.logger.setContext(SupportController.name);
}

@UseGuards(PlainCardsGuard)
@Post('customer-details')
async fetchUserOrganizations(@Body() body: PlainCardRequestDto) {
return this.plainCardsUsecase.fetchCustomerDetails(PlainCardsCommand.create({ ...body }));
}

@RequireAuthentication()
@Post('agents-early-access')
async submitAgentsEarlyAccess(@Body() body: AgentsEarlyAccessDto, @UserSession() user: UserSessionData) {
const organization = await this.organizationRepository.findById(user.organizationId);
const organizationName = organization?.name ?? '';

const secretKey = process.env.NOVU_SECRET_KEY;

if (!secretKey) {
this.logger.warn('NOVU_SECRET_KEY is not set; skipping early-access-request-agents-internal-email trigger');

return {
success: true,
};
}

const novu = new Novu({
security: {
secretKey,
},
});

await novu.trigger({
workflowId: 'early-access-request-agents-internal-email',
to: {
subscriberId: 'dima-internal',
email: 'dima@novu.co',
},
payload: {
howAgentRunsToday: body.howAgentRunsToday.label,
whatAgentDoes: body.whatAgentDoes,
plannedProviders: body.plannedProviders.map((p) => p.label),
organizationId: user.organizationId,
organizationName,
userEmail: user.email ?? '',
},
});
Comment on lines +56 to +70
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add error handling for the Novu workflow trigger.

If novu.trigger() fails (network issue, invalid workflow ID, etc.), the exception will propagate and return a 500 error to the client. Consider wrapping this in a try-catch to provide a graceful failure response or at minimum log the error.

🛡️ Proposed fix to add error handling
+    try {
       await novu.trigger({
         workflowId: 'early-access-request-agents-internal-email',
         to: {
           subscriberId: 'dima-internal',
           email: 'dima@novu.co',
         },
         payload: {
           howAgentRunsToday: body.howAgentRunsToday.label,
           whatAgentDoes: body.whatAgentDoes,
           plannedProviders: body.plannedProviders.map((p) => p.label),
           organizationId: user.organizationId,
           organizationName,
           userEmail: user.email ?? '',
         },
       });
+    } catch (error) {
+      this.logger.error('Failed to trigger early-access-request-agents-internal-email workflow', error);
+
+      return {
+        success: false,
+      };
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api/src/app/support/support.controller.ts` around lines 56 - 70, Wrap
the novu.trigger call inside the support controller method in a try-catch: catch
any error from novu.trigger, log the error with context (include the workflowId
and payload like
howAgentRunsToday/whatAgentDoes/plannedProviders/organizationId/userEmail) and
return a controlled failure to the client (e.g., throw a BadGatewayException or
respond with a 502 and a brief message) instead of letting the exception
propagate; ensure you reference the novu.trigger invocation and its payload when
adding the log and error handling.


return {
success: true,
};
}

@RequireAuthentication()
@Post('create-thread')
async createThread(@Body() body: CreateSupportThreadDto, @UserSession() user: UserSessionData) {
Expand Down
437 changes: 437 additions & 0 deletions apps/dashboard/public/images/agents-teaser.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions apps/dashboard/src/components/side-navigation/side-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
RiKey2Line,
RiLayout5Line,
RiLineChartLine,
RiRobot2Line,
RiRouteFill,
RiSettings4Line,
RiSignalTowerLine,
Expand Down Expand Up @@ -125,6 +126,19 @@ export const SideNavigation = () => {
</NavigationLink>
</Protect>

<NavigationLink
to={
currentEnvironment?.slug
? buildRoute(ROUTES.AGENTS, { environmentSlug: currentEnvironment?.slug ?? '' })
: undefined
}
>
<RiRobot2Line className="size-4" />
<span>Agents</span>
</NavigationLink>
</NavigationGroup>

<NavigationGroup label="Content">
<Protect permission={PermissionsEnum.WORKFLOW_READ}>
<NavigationLink
to={
Expand Down
5 changes: 5 additions & 0 deletions apps/dashboard/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { ResetPasswordPage } from './pages/reset-password';
import { TestWorkflowDrawerPage } from './pages/test-workflow-drawer-page';
import { TestWorkflowRouteHandler } from './pages/test-workflow-route-handler';
import { TopicsPage } from './pages/topics';
import { AgentsPage } from './pages/agents';
import { UpsertVariablePage } from './pages/upsert-variable';
import { VariablesPage } from './pages/variables';
import { VercelIntegrationPage } from './pages/vercel-integration-page';
Expand Down Expand Up @@ -349,6 +350,10 @@ const router = createBrowserRouter([
},
],
},
{
path: ROUTES.AGENTS,
element: <AgentsPage />,
},
{
path: ROUTES.API_KEYS,
element: (
Expand Down
Loading
Loading