The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import {
Column,
CreateDateColumn,
Entity,
Index,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { ADD_IS_SYSTEM_TO_AGENT_AND_WORKFLOW_UPGRADE_COMMAND_NAME } from 'src/database/commands/upgrade-version-command/2-46/add-is-system-to-agent-and-workflow-upgrade-command-name.constant';
import { ADD_TRIGGERS_TO_AGENT_UPGRADE_COMMAND_NAME } from 'src/database/commands/upgrade-version-command/2-46/add-triggers-to-agent-upgrade-command-name.constant';
import { DROP_AGENT_EVALUATION_INPUTS_UPGRADE_COMMAND_NAME } from 'src/database/commands/upgrade-version-command/2-47/drop-agent-evaluation-inputs-upgrade-command-name.constant';
import { AGENT_AND_SKILL_OVERRIDABLE_ENTITY_UPGRADE_COMMAND_NAME } from 'src/database/commands/upgrade-version-command/2-53/agent-and-skill-overridable-entity-upgrade-command-name.constant';
import { DROP_IS_CUSTOM_FROM_AGENT_SKILL_VIEW_INDEX_AND_AGENT_CHAT_CHANNEL_UPGRADE_COMMAND_NAME } from 'src/database/commands/upgrade-version-command/2-54/drop-is-custom-from-agent-skill-view-index-and-agent-chat-channel-upgrade-command-name.constant';
import { WasIntroducedInUpgrade } from 'src/engine/core-modules/upgrade/decorators/was-introduced-in-upgrade.decorator';
import { WasRemovedInUpgrade } from 'src/engine/core-modules/upgrade/decorators/was-removed-in-upgrade.decorator';
import { AgentResponseFormat } from 'src/engine/metadata-modules/ai/ai-agent/types/agent-response-format.type';
import { ModelConfiguration } from 'src/engine/metadata-modules/ai/ai-agent/types/model-configuration.type';
import { AUTO_SELECT_WORKSPACE_DEFAULT_MODEL_ID } from 'twenty-shared/ai';
import { type AgentTrigger } from 'twenty-shared/application';
import { type ModelId } from 'src/engine/metadata-modules/ai/ai-models/types/model-id.type';
import { OverridableEntity } from 'src/engine/workspace-manager/types/overridable-entity.type';
import { JsonbProperty } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/jsonb-property.type';
export type AgentOverrides = {
label?: string;
icon?: string | null;
description?: string | null;
prompt?: string;
modelId?: ModelId;
responseFormat?: AgentResponseFormat;
modelConfiguration?: ModelConfiguration | null;
isActive?: boolean;
};
@Entity('agent')
// Both indexes go with the deletedAt column in 2.55
@Index('IDX_AGENT_ID_DELETED_AT', ['id', 'deletedAt'])
@Index('IDX_AGENT_NAME_WORKSPACE_ID_UNIQUE', ['name', 'workspaceId'], {
unique: true,
where: '"deletedAt" IS NULL',
})
export class AgentEntity
extends OverridableEntity<AgentOverrides>
implements Required<AgentEntity>
{
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ nullable: false })
name: string;
@Column({ nullable: false })
label: string;
@Column({ nullable: true, type: 'varchar' })
icon: string | null;
@Column({ nullable: true, type: 'text' })
description: string | null;
@Column({ nullable: false, type: 'text' })
prompt: string;
@Column({
nullable: false,
type: 'varchar',
default: AUTO_SELECT_WORKSPACE_DEFAULT_MODEL_ID,
})
modelId: ModelId;
// TODO: make non-nullable
@Column({ nullable: true, type: 'jsonb', default: { type: 'text' } })
responseFormat: JsonbProperty<AgentResponseFormat>;
@WasRemovedInUpgrade({
upgradeCommandName:
DROP_IS_CUSTOM_FROM_AGENT_SKILL_VIEW_INDEX_AND_AGENT_CHAT_CHANNEL_UPGRADE_COMMAND_NAME,
})
@Column({ type: 'boolean', default: false })
isCustom: WasRemovedInUpgrade<boolean>;
@WasIntroducedInUpgrade({
upgradeCommandName:
ADD_IS_SYSTEM_TO_AGENT_AND_WORKFLOW_UPGRADE_COMMAND_NAME,
})
@Column({ default: false })
isSystem: boolean;
@CreateDateColumn({ type: 'timestamptz' })
createdAt: Date;
@UpdateDateColumn({ type: 'timestamptz' })
updatedAt: Date;
@Column({ nullable: true, type: 'timestamptz' })
deletedAt: Date | null;
@Column({ nullable: true, type: 'jsonb' })
modelConfiguration: JsonbProperty<ModelConfiguration> | null;
@WasIntroducedInUpgrade({
upgradeCommandName: ADD_TRIGGERS_TO_AGENT_UPGRADE_COMMAND_NAME,
})
@Column({ nullable: false, type: 'jsonb', default: [] })
triggers: JsonbProperty<AgentTrigger[]>;
@WasRemovedInUpgrade({
upgradeCommandName: DROP_AGENT_EVALUATION_INPUTS_UPGRADE_COMMAND_NAME,
})
@Column({ type: 'text', array: true, default: '{}' })
evaluationInputs: WasRemovedInUpgrade<string[]>;
}
WasIntroducedInUpgrade({
upgradeCommandName: AGENT_AND_SKILL_OVERRIDABLE_ENTITY_UPGRADE_COMMAND_NAME,
})(AgentEntity.prototype, 'overrides');
WasIntroducedInUpgrade({
upgradeCommandName: AGENT_AND_SKILL_OVERRIDABLE_ENTITY_UPGRADE_COMMAND_NAME,
})(AgentEntity.prototype, 'isActive');