AI settings tab (#13496)

https://github.com/user-attachments/assets/87f5a556-ff12-4ce0-aaa7-9120c0432151

---------

Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
Abdul Rahman
2025-08-01 20:29:28 +05:30
committed by GitHub
parent 75214c3e61
commit c3a9843fcb
60 changed files with 2453 additions and 482 deletions
@@ -4,9 +4,9 @@ import { InjectRepository } from '@nestjs/typeorm';
import { t } from '@lingui/core/macro';
import { FieldMetadataType } from 'twenty-shared/types';
import { isDefined, isValidUuid } from 'twenty-shared/utils';
import { StepStatus } from 'twenty-shared/workflow';
import { Repository } from 'typeorm';
import { v4 } from 'uuid';
import { StepStatus } from 'twenty-shared/workflow';
import { BASE_TYPESCRIPT_PROJECT_INPUT_SCHEMA } from 'src/engine/core-modules/serverless/drivers/constants/base-typescript-project-input-schema';
import { CreateWorkflowVersionStepInput } from 'src/engine/core-modules/workflow/dtos/create-workflow-version-step-input.dto';
@@ -403,12 +403,16 @@ export class WorkflowVersionStepWorkspaceService {
break;
}
case WorkflowActionType.AI_AGENT: {
if (!isDefined(step.settings.input.agentId)) {
break;
}
const agent = await this.agentService.findOneAgent(
step.settings.input.agentId,
workspaceId,
);
if (agent) {
if (isDefined(agent)) {
await this.agentService.deleteOneAgent(agent.id, workspaceId);
}
break;
@@ -611,25 +615,6 @@ export class WorkflowVersionStepWorkspaceService {
};
}
case WorkflowActionType.AI_AGENT: {
const newAgent = await this.agentService.createOneAgentAndFirstThread(
{
label: 'AI Agent Workflow Step',
name: `ai-agent-workflow-${newStepId}`,
description: 'Created automatically for workflow step',
prompt: '',
modelId: 'auto',
},
workspaceId,
this.scopedWorkspaceContextFactory.create().userWorkspaceId,
);
if (!isDefined(newAgent)) {
throw new WorkflowVersionStepException(
'Failed to create AI Agent Step',
WorkflowVersionStepExceptionCode.FAILURE,
);
}
return {
id: newStepId,
name: 'AI Agent',
@@ -638,7 +623,8 @@ export class WorkflowVersionStepWorkspaceService {
settings: {
...BASE_STEP_DEFINITION,
input: {
agentId: newAgent.id,
agentId: '',
prompt: '',
},
},
};
@@ -18,6 +18,7 @@ import {
} from 'src/modules/workflow/workflow-executor/exceptions/workflow-step-executor.exception';
import { WorkflowActionInput } from 'src/modules/workflow/workflow-executor/types/workflow-action-input';
import { WorkflowActionOutput } from 'src/modules/workflow/workflow-executor/types/workflow-action-output.type';
import { resolveInput } from 'src/modules/workflow/workflow-executor/utils/variable-resolver.util';
import { isWorkflowAiAgentAction } from './guards/is-workflow-ai-agent-action.guard';
@@ -51,18 +52,22 @@ export class AiAgentWorkflowAction implements WorkflowAction {
);
}
const { agentId } = step.settings.input;
const { agentId, prompt } = step.settings.input;
const workspaceId = context.workspaceId as string;
try {
const agent = await this.agentRepository.findOne({
where: {
id: agentId,
workspaceId,
},
});
let agent: AgentEntity | null = null;
if (!agent) {
if (agentId) {
agent = await this.agentRepository.findOne({
where: {
id: agentId,
workspaceId,
},
});
}
if (agentId && !agent) {
throw new AgentException(
`Agent with id ${agentId} not found`,
AgentExceptionCode.AGENT_NOT_FOUND,
@@ -73,10 +78,11 @@ export class AiAgentWorkflowAction implements WorkflowAction {
agent,
context,
schema: step.settings.outputSchema,
userPrompt: resolveInput(prompt, context) as string,
});
await this.aiBillingService.calculateAndBillUsage(
agent.modelId,
agent?.modelId ?? 'auto',
usage,
workspaceId,
);
@@ -1,3 +1,4 @@
export type WorkflowAiAgentActionInput = {
agentId: string;
agentId?: string;
prompt?: string;
};