From 13d7e91e0d529a72f8b79baa7b157a869d45d79b Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sun, 2 Mar 2025 16:08:51 +0100 Subject: [PATCH] Remove agent-related configurations and dependencies. This commit removes the "Agents" configuration section, related API keys, services, and persistence logic across the codebase. Unused agent-related NuGet packages and code references were also eliminated to simplify the project and focus on core functionality. --- Directory.Packages.props | 1 - src/apps/Elsa.Server.Web/Program.cs | 34 ++++----- src/apps/Elsa.Server.Web/appsettings.json | 76 ------------------- src/apps/Elsa.ServerAndStudio.Web/Program.cs | 23 +----- .../Helpers/Fixtures/WorkflowServer.cs | 10 +-- 5 files changed, 20 insertions(+), 124 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index c1faed54a..7fe38d5fd 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -64,7 +64,6 @@ - diff --git a/src/apps/Elsa.Server.Web/Program.cs b/src/apps/Elsa.Server.Web/Program.cs index 0ede4e723..2e802dcc0 100644 --- a/src/apps/Elsa.Server.Web/Program.cs +++ b/src/apps/Elsa.Server.Web/Program.cs @@ -1,5 +1,4 @@ using System.Text.Encodings.Web; -using Elsa.Agents; using Elsa.Alterations.Extensions; using Elsa.Alterations.MassTransit.Extensions; using Elsa.Caching.Options; @@ -94,7 +93,6 @@ const DistributedCachingTransport distributedCachingTransport = DistributedCachi const MassTransitBroker massTransitBroker = MassTransitBroker.Memory; const bool useMultitenancy = false; const bool useTenantsFromConfiguration = true; -const bool useAgents = false; const bool useSecrets = false; const bool disableVariableWrappers = false; const bool disableVariableCopying = false; @@ -213,7 +211,8 @@ services else if (sqlDatabaseProvider == SqlDatabaseProvider.CockroachDb) ef.UsePostgreSql(cockroachDbConnectionString!); else if (sqlDatabaseProvider == SqlDatabaseProvider.Oracle) - ef.UseOracle(oracleConnectionString, new ElsaDbContextOptions{ SchemaName = "ELSA"}); + ef.UseOracle(oracleConnectionString, new() + { SchemaName = "ELSA"}); else ef.UseSqlite(sp => sp.GetSqliteConnectionString()); @@ -256,7 +255,8 @@ services else if (sqlDatabaseProvider == SqlDatabaseProvider.CockroachDb) ef.UsePostgreSql(cockroachDbConnectionString!); else if (sqlDatabaseProvider == SqlDatabaseProvider.Oracle) - ef.UseOracle(oracleConnectionString, new ElsaDbContextOptions{ SchemaName = "ELSA"}); + ef.UseOracle(oracleConnectionString, new() + { SchemaName = "ELSA"}); else ef.UseSqlite(sp => sp.GetSqliteConnectionString()); @@ -304,7 +304,8 @@ services else if (sqlDatabaseProvider == SqlDatabaseProvider.CockroachDb) ef.UsePostgreSql(cockroachDbConnectionString); else if (sqlDatabaseProvider == SqlDatabaseProvider.Oracle) - ef.UseOracle(oracleConnectionString, new ElsaDbContextOptions{ SchemaName = "ELSA"}); + ef.UseOracle(oracleConnectionString, new() + { SchemaName = "ELSA"}); else ef.UseSqlite(sp => sp.GetSqliteConnectionString()); @@ -354,7 +355,7 @@ services return new RedisDistributedSynchronizationProvider(database); } case "File": - return new FileDistributedSynchronizationProvider(new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "App_Data", "locks"))); + return new FileDistributedSynchronizationProvider(new(Path.Combine(Directory.GetCurrentDirectory(), "App_Data", "locks"))); case "Noop": default: return new NoopDistributedSynchronizationProvider(); @@ -451,7 +452,8 @@ services else if (sqlDatabaseProvider == SqlDatabaseProvider.CockroachDb) ef.UsePostgreSql(cockroachDbConnectionString); else if (sqlDatabaseProvider == SqlDatabaseProvider.Oracle) - ef.UseOracle(oracleConnectionString, new ElsaDbContextOptions{ SchemaName = "ELSA"}); + ef.UseOracle(oracleConnectionString, new() + { SchemaName = "ELSA"}); else ef.UseSqlite(sp => sp.GetSqliteConnectionString()); @@ -536,7 +538,7 @@ services { if (sqlDatabaseProvider == SqlDatabaseProvider.SqlServer) return new SqlServerProvider(sqlServerConnectionString!, true, "", "proto_actor"); - return new SqliteProvider(new SqliteConnectionStringBuilder(sqliteConnectionString)); + return new SqliteProvider(new(sqliteConnectionString)); }; if (configuration["KUBERNETES_SERVICE_HOST"] != null) @@ -562,18 +564,7 @@ services kafka.ConfigureOptions(options => configuration.GetSection("Kafka").Bind(options)); }); } - - if (useAgents) - { - elsa - .UseAgentActivities() - .UseAgentPersistence(persistence => persistence.UseEntityFrameworkCore(ef => ef.UseSqlite(sp => sp.GetSqliteConnectionString()))) - .UseAgentsApi() - ; - - services.Configure(options => builder.Configuration.GetSection("Agents").Bind(options)); - } - + if (useSecrets) { elsa @@ -647,7 +638,8 @@ services if (sqlDatabaseProvider == SqlDatabaseProvider.Sqlite) ef.UseSqlite(sqliteConnectionString); if (sqlDatabaseProvider == SqlDatabaseProvider.SqlServer) ef.UseSqlServer(sqlServerConnectionString); if (sqlDatabaseProvider == SqlDatabaseProvider.PostgreSql) ef.UsePostgreSql(postgresConnectionString); - if (sqlDatabaseProvider == SqlDatabaseProvider.Oracle) ef.UseOracle(oracleConnectionString, new ElsaDbContextOptions{ SchemaName = "ELSA"}); + if (sqlDatabaseProvider == SqlDatabaseProvider.Oracle) ef.UseOracle(oracleConnectionString, new() + { SchemaName = "ELSA"}); #if !NET9_0 if (sqlDatabaseProvider == SqlDatabaseProvider.MySql) ef.UseMySql(mySqlConnectionString); diff --git a/src/apps/Elsa.Server.Web/appsettings.json b/src/apps/Elsa.Server.Web/appsettings.json index 786f2d033..e361f3077 100644 --- a/src/apps/Elsa.Server.Web/appsettings.json +++ b/src/apps/Elsa.Server.Web/appsettings.json @@ -254,82 +254,6 @@ "SweepInterval": "04:00:00" } }, - "Agents": { - "ApiKeys": [ - { - "Name": "MyApiKey", - "Value": "my-api-key" - } - ], - "Services": [ - { - "Name": "ChatCompletion", - "Type": "OpenAIChatCompletion", - "Settings": { - "ModelId": "gpt-4o", - "ApiKeyRef": "MyApiKey" - } - }, - { - "Name": "TextToImage", - "Type": "OpenAITextToImage", - "Settings": { - "ModelId": "dall-e-3", - "ApiKeyRef": "MyApiKey" - } - } - ], - "Agents": [ - { - "Name": "Copywriter", - "Description": "A persona that writes articles on any topic.", - "Services": [ - "ChatCompletion" - ], - "FunctionName": "WriteArticle", - "PromptTemplate": "You are a writer of articles about any topic and any additional instructions given to you. The syntax of the article content will be markdown, and your response will be in JSON format containing a \"title\" field and a \"markdown\" field using the following JSON structure: { \"title\": \"The title of the Article\", \"markdown\": \"The article content in markdown syntax.\" }. This is the topic: {{$Topic}}. The article consists of around {{$ParagraphCount}} paragraphs. The article must be written in the language {{$Language}} using the following style: {{$WritingStyle}}. Additional instructions (if any): {{$AdditionalInstructions}}.", - "InputVariables": [ - { - "Name": "Topic", - "Description": "The topic to write an article about.", - "Type": "string" - }, - { - "Name": "ParagraphCount", - "Description": "The number of paragraphs to write.", - "Type": "int" - }, - { - "Name": "Language", - "Description": "The language to write the text in.", - "Type": "string" - }, - { - "Name": "WritingStyle", - "Description": "The style to write the text in.", - "Type": "string" - }, - { - "Name": "AdditionalInstructions", - "Description": "Any additional instructions.", - "Type": "string" - } - ], - "OutputVariable": { - "Name": "Article", - "Description": "The article consisting of a title and markdown text." - }, - "ExecutionSettings": { - "MaxTokens": null, - "Temperature": 0.5, - "TopP": 0.9, - "PresencePenalty": 0.5, - "FrequencyPenalty": 0.5, - "ResponseFormat": "json_object" - } - } - ] - }, "Webhooks": { "Sinks": [ { diff --git a/src/apps/Elsa.ServerAndStudio.Web/Program.cs b/src/apps/Elsa.ServerAndStudio.Web/Program.cs index 807f711a0..01b787cad 100644 --- a/src/apps/Elsa.ServerAndStudio.Web/Program.cs +++ b/src/apps/Elsa.ServerAndStudio.Web/Program.cs @@ -11,9 +11,9 @@ using Elsa.ServerAndStudio.Web.Enums; using Medallion.Threading.FileSystem; using Microsoft.AspNetCore.Mvc; using Microsoft.Data.Sqlite; -using Proto.Persistence.Sqlite; using WebhooksCore.Options; using Elsa.Connections.Middleware; +using Proto.Persistence.Sqlite; const bool useMassTransit = true; const bool useProtoActor = true; @@ -140,21 +140,6 @@ services .UseEmail(email => email.ConfigureOptions = options => configuration.GetSection("Smtp").Bind(options)) .UseWebhooks(webhooks => webhooks.ConfigureSinks = options => builder.Configuration.GetSection("Webhooks:Sinks").Bind(options)) .UseWorkflowsApi() - .UseAgentsApi() - .UseAgentPersistence(persistence => persistence.UseEntityFrameworkCore(ef => - { - if (sqlDatabaseProvider == SqlDatabaseProvider.SqlServer) - ef.UseSqlServer(sqlServerConnectionString); - else if (sqlDatabaseProvider == SqlDatabaseProvider.PostgreSql) - ef.UsePostgreSql(postgreSqlConnectionString); - else if (sqlDatabaseProvider == SqlDatabaseProvider.Sqlite) - ef.UseSqlite(sqliteConnectionString); -#if !NET9_0 - else if (sqlDatabaseProvider == SqlDatabaseProvider.MySql) - ef.UseMySql(mySqlConnectionString); -#endif - })) - .UseAgentActivities() .AddActivitiesFrom() .AddWorkflowsFrom(); @@ -195,9 +180,9 @@ services }); } - elsa.UseConnections( - configure=> configure.AddConnectionsFrom()); - elsa.UseConnectionPersistence(ef=> ef.UseEntityFrameworkCore(f=>f.UseSqlite())); + elsa.UseConnections( + configure=> configure.AddConnectionsFrom()); + elsa.UseConnectionPersistence(ef=> ef.UseEntityFrameworkCore(f=>f.UseSqlite())); elsa.UseConnectionsApi(); }); diff --git a/test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/WorkflowServer.cs b/test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/WorkflowServer.cs index efeea9663..67f5b73d8 100644 --- a/test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/WorkflowServer.cs +++ b/test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/WorkflowServer.cs @@ -1,6 +1,4 @@ -using System.Net.Http.Headers; using System.Reflection; -using Elsa.Agents; using Elsa.Alterations.Extensions; using Elsa.Caching; using Elsa.EntityFrameworkCore.Extensions; @@ -36,7 +34,7 @@ public class WorkflowServer(Infrastructure infrastructure, string url) : WebAppl public TClient CreateApiClient() { var client = CreateClient(); - client.BaseAddress = new Uri(client.BaseAddress!, "/elsa/api"); + client.BaseAddress = new(client.BaseAddress!, "/elsa/api"); client.Timeout = TimeSpan.FromMinutes(1); return RestService.For(client, CreateRefitSettings(Services)); } @@ -44,7 +42,7 @@ public class WorkflowServer(Infrastructure infrastructure, string url) : WebAppl public HttpClient CreateHttpWorkflowClient() { var client = CreateClient(); - client.BaseAddress = new Uri(client.BaseAddress!, "/workflows/"); + client.BaseAddress = new(client.BaseAddress!, "/workflows/"); client.Timeout = TimeSpan.FromMinutes(1); return client; } @@ -114,8 +112,6 @@ public class WorkflowServer(Infrastructure infrastructure, string url) : WebAppl { http.UseCache(); }); - elsa.UseAgents(); - elsa.UseAgentPersistence(feature => feature.UseEntityFrameworkCore(ef => ef.UsePostgreSql(typeof(AgentsPostgreSqlProvidersExtensions).Assembly, dbConnectionString))); }; } @@ -137,6 +133,6 @@ public class WorkflowServer(Infrastructure infrastructure, string url) : WebAppl protected override void ConfigureClient(HttpClient client) { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("ApiKey", AdminApiKeyProvider.DefaultApiKey); + client.DefaultRequestHeaders.Authorization = new("ApiKey", AdminApiKeyProvider.DefaultApiKey); } } \ No newline at end of file