diff --git a/front/admin/db.ts b/front/admin/db.ts index 06baf37f1cb3..9141ddad148a 100644 --- a/front/admin/db.ts +++ b/front/admin/db.ts @@ -27,7 +27,7 @@ import { XP1User, } from "@app/lib/models"; import { - AgentDatasourceConfiguration, + AgentDataSourceConfiguration, AgentRetrievalConfiguration, } from "@app/lib/models/assistant/actions/retrieval"; import { @@ -65,7 +65,7 @@ async function main() { await AgentConfiguration.sync({ alter: true }); await AgentGenerationConfiguration.sync({ alter: true }); await AgentRetrievalConfiguration.sync({ alter: true }); - await AgentDatasourceConfiguration.sync({ alter: true }); + await AgentDataSourceConfiguration.sync({ alter: true }); await XP1User.sync({ alter: true }); await XP1Run.sync({ alter: true }); diff --git a/front/lib/models/assistant/actions/retrieval.ts b/front/lib/models/assistant/actions/retrieval.ts index fcf36501a2a8..33b5442587c7 100644 --- a/front/lib/models/assistant/actions/retrieval.ts +++ b/front/lib/models/assistant/actions/retrieval.ts @@ -71,20 +71,18 @@ AgentRetrievalConfiguration.init( beforeValidate: (retrieval: AgentRetrievalConfiguration) => { // Validation for templated Query if (retrieval.query == "templated") { - if (retrieval.queryTemplate === null) { + if (!retrieval.queryTemplate) { throw new Error("Must set a template for templated query"); } - } else { - if (retrieval.queryTemplate) { - throw new Error("Can't set a template without templated query"); - } + } else if (retrieval.queryTemplate) { + throw new Error("Can't set a template without templated query"); } // Validation for Timeframe if (retrieval.relativeTimeFrame == "custom") { if ( - retrieval.relativeTimeFrameDuration === null || - retrieval.relativeTimeFrameUnit === null + !retrieval.relativeTimeFrameDuration || + !retrieval.relativeTimeFrameUnit ) { throw new Error( "Custom relative time frame must have a duration and unit set" @@ -99,9 +97,9 @@ AgentRetrievalConfiguration.init( /** * Configuration of Datasources used for Retrieval Action. */ -export class AgentDatasourceConfiguration extends Model< - InferAttributes, - InferCreationAttributes +export class AgentDataSourceConfiguration extends Model< + InferAttributes, + InferCreationAttributes > { declare id: number; @@ -110,17 +108,17 @@ export class AgentDatasourceConfiguration extends Model< declare timeframeDuration: number | null; declare timeframeUnit: TimeframeUnit | null; - declare tagsIn: string[]; - declare tagsOut: string[]; - declare parentsIn: string[]; - declare parentsOut: string[]; + declare tagsIn: string[] | null; + declare tagsNotIn: string[] | null; + declare parentsIn: string[] | null; + declare parentsNotIn: string[] | null; - declare datasourceId: ForeignKey; + declare dataSourceId: ForeignKey; declare retrievalConfigurationId: ForeignKey< AgentRetrievalConfiguration["id"] >; } -AgentDatasourceConfiguration.init( +AgentDataSourceConfiguration.init( { id: { type: DataTypes.INTEGER, @@ -145,49 +143,40 @@ AgentDatasourceConfiguration.init( }, tagsIn: { type: DataTypes.ARRAY(DataTypes.STRING), - allowNull: false, - defaultValue: [], + allowNull: true, }, - tagsOut: { + tagsNotIn: { type: DataTypes.ARRAY(DataTypes.STRING), - allowNull: false, - defaultValue: [], + allowNull: true, }, parentsIn: { type: DataTypes.ARRAY(DataTypes.STRING), - allowNull: false, - defaultValue: [], + allowNull: true, }, - parentsOut: { + parentsNotIn: { type: DataTypes.ARRAY(DataTypes.STRING), - allowNull: false, - defaultValue: [], + allowNull: true, }, }, { - modelName: "agent_datasource_configuration", + modelName: "agent_data_source_configuration", sequelize: front_sequelize, hooks: { - beforeValidate: (datasourceConfig: AgentDatasourceConfiguration) => { - if ( - (datasourceConfig.minTimestamp === null) !== - (datasourceConfig.maxTimestamp === null) - ) { + beforeValidate: (dataSourceConfig: AgentDataSourceConfiguration) => { + if (!dataSourceConfig.minTimestamp !== !dataSourceConfig.maxTimestamp) { throw new Error("Timestamps must be both set or both null"); } if ( - (datasourceConfig.timeframeDuration === null) !== - (datasourceConfig.timeframeUnit === null) + !dataSourceConfig.timeframeDuration !== + !dataSourceConfig.timeframeUnit ) { throw new Error( "Timeframe duration/unit must be both set or both null" ); } if ( - (datasourceConfig.minTimestamp !== null || - datasourceConfig.maxTimestamp !== null) && - (datasourceConfig.timeframeDuration !== null || - datasourceConfig.timeframeUnit !== null) + (dataSourceConfig.minTimestamp || dataSourceConfig.maxTimestamp) && + (dataSourceConfig.timeframeDuration || dataSourceConfig.timeframeUnit) ) { throw new Error("Cannot use both timestamps and timeframe"); } @@ -196,8 +185,8 @@ AgentDatasourceConfiguration.init( } ); -// Retrieval config <> datasource config -AgentRetrievalConfiguration.hasMany(AgentDatasourceConfiguration, { +// Retrieval config <> data source config +AgentRetrievalConfiguration.hasMany(AgentDataSourceConfiguration, { foreignKey: { name: "retrievalId", allowNull: false }, onDelete: "CASCADE", }); diff --git a/front/lib/models/assistant/agent.ts b/front/lib/models/assistant/agent.ts index 4feb55a8f549..01b60728551f 100644 --- a/front/lib/models/assistant/agent.ts +++ b/front/lib/models/assistant/agent.ts @@ -9,7 +9,10 @@ import { import { front_sequelize } from "@app/lib/databases"; import { AgentRetrievalConfiguration } from "@app/lib/models/assistant/actions/retrieval"; import { Workspace } from "@app/lib/models/workspace"; -import { AgentConfigurationStatus } from "@app/types/assistant/agent"; +import { + AgentConfigurationScope, + AgentConfigurationStatus, +} from "@app/types/assistant/agent"; /** * Agent configuration @@ -25,7 +28,7 @@ export class AgentConfiguration extends Model< declare name: string; declare pictureUrl: string | null; - declare isGlobal: boolean; + declare scope: AgentConfigurationScope; declare workspaceId: ForeignKey | null; // null = it's a global agent declare model: ForeignKey | null; @@ -55,10 +58,10 @@ AgentConfiguration.init( type: DataTypes.TEXT, allowNull: true, }, - isGlobal: { - type: DataTypes.BOOLEAN, + scope: { + type: DataTypes.STRING, allowNull: false, - defaultValue: false, + defaultValue: "workspace", }, }, { @@ -75,10 +78,9 @@ AgentConfiguration.init( ], hooks: { beforeValidate: (agent: AgentConfiguration) => { - if (agent.isGlobal && agent.workspaceId) { + if (agent.scope !== "workspace" && agent.workspaceId) { throw new Error("Workspace id must be null for global agent"); - } - if (!agent.isGlobal && !agent.workspaceId) { + } else if (agent.scope === "workspace" && !agent.workspaceId) { throw new Error("Workspace id must be set for non-global agent"); } }, diff --git a/front/types/assistant/agent.ts b/front/types/assistant/agent.ts index fcbb2198813a..457320076e1a 100644 --- a/front/types/assistant/agent.ts +++ b/front/types/assistant/agent.ts @@ -56,6 +56,7 @@ export type AgentGenerationConfigurationType = { */ export type AgentConfigurationStatus = "active" | "archived"; +export type AgentConfigurationScope = "global" | "workspace"; export type AgentConfigurationType = { sId: string;